Commit 85b7798c authored by thejoelinux's avatar thejoelinux

Renommage des tables

parent 8ac35e56
......@@ -3,7 +3,7 @@
class Esar_Category extends Record {
public $id, $name, $label;
public $table = "esar_categories";
public static $table = "lud_esar_categories";
public function __construct($id = 0) {
if (!$this->id) {
......@@ -15,7 +15,7 @@ class Esar_Category extends Record {
$esar_categories = array();
// SQL SELECT esar_categories
$sql = "SELECT id, name, label
FROM esar_categories
FROM ".Esar_Category::$table."
ORDER BY label";
$GLOBALS["data"]->select($sql, $esar_categories, "Esar_Category");
return sizeof($esar_categories);
......@@ -24,7 +24,7 @@ class Esar_Category extends Record {
public static function fetch($id) {
// SQL SELECT esar_categories
$sql = "SELECT id, name, label
FROM esar_categories
FROM ".Esar_Category::$table."
WHERE id = ".$id;
$GLOBALS["data"]->select($sql, $esar_category, "Esar_Category");
return $esar_category;
......@@ -33,7 +33,8 @@ class Esar_Category extends Record {
public function validate_input(&$errors) {
$v = new Valitron\Validator($_REQUEST);
$v->rule('required', ['name', 'label']);
$v->rule('alphaNum', ['name', 'label']);
$v->rule('lengthBetween', 'name', 10, 128);
$v->rule('lengthBetween', 'label', 3, 16);
$v->labels(array(
'name' => 'Le nom',
'label' => 'L\'etiquette'
......
......@@ -3,6 +3,8 @@
class Family_Member extends Record {
public $id, $member_id, $firstname, $lastname, $birth_date, $link_id, $link_name;
public static $table = "lud_family_members";
public function __construct($id = 0)
{
if (!$this->id) {
......@@ -13,9 +15,9 @@ class Family_Member extends Record {
public static function fetch_all(&$family_members, $member_id) {
$family_members = array();
// SQL SELECT family_members
// SQL SELECT lud_family_members
$sql = " SELECT id, firstname, lastname, DATE_FORMAT(birth_date, '%d/%m/%Y') AS birth_date, link_id
FROM family_members
FROM ".Family_Member::$table."
WHERE member_id = ".$member_id."
ORDER BY DATE_FORMAT(birth_date, '%Y/%m/%d') ASC";
$GLOBALS["data"]->select($sql, $family_members, "Family_Member", true);
......@@ -25,8 +27,8 @@ class Family_Member extends Record {
public function create($firstname, $lastname, $birth_date, $link_id) {
// date transformation from displayable to database
$birth_date = date_format(date_create_from_format('d-m-Y', $birth_date),'Y-m-d');
// SQL INSERT family_members
$sql = " INSERT INTO family_members (firstname, lastname, birth_date,
// SQL INSERT lud_family_members
$sql = " INSERT INTO ".Family_Member::$table." (firstname, lastname, birth_date,
link_id, member_id)
VALUES ('".$firstname."', '".$lastname."', '".$birth_date."',
'".$link_id."', ".$_REQUEST["i"].")";
......
......@@ -11,7 +11,7 @@ class Game extends Record {
// loan history
public $loans;
public $table = "games";
public static $table = "lud_games";
public function __construct($id = 0) {
if (!$this->id) {
......@@ -20,7 +20,7 @@ class Game extends Record {
}
public static function fetch($id) {
// SQL SELECT games prets
// SQL SELECT lud_games lud_loans lud_reservations lud_members
$sql = "SELECT g.id, g.name, g.reference, g.maker, g.category, g.esar_category_id,
g.comments, g.maker_info, g.content_inventory,
DATE_FORMAT(g.aquisition_date, '%m/%d/%Y') as aquisition_date,
......@@ -29,10 +29,10 @@ class Game extends Record {
l.id as loan_id, l.end_date AS loan_end_date,
r.id AS reservation_id, r.member_id AS reservation_member_id, r.reservation_date,
CONCAT(m.firstname, ' ', m.lastname) AS reservation_member_name
FROM games g
LEFT OUTER JOIN loans l ON (g.id = l.game_id AND l.is_back = 0)
LEFT OUTER JOIN reservations r ON (g.id = r.game_id)
LEFT OUTER JOIN members m ON (r.member_id = m.id)
FROM ".Game::$table." g
LEFT OUTER JOIN ".Loan::$table." l ON (g.id = l.game_id AND l.is_back = 0)
LEFT OUTER JOIN ".Reservation::$table." r ON (g.id = r.game_id)
LEFT OUTER JOIN ".Member::$table." m ON (r.member_id = m.id)
WHERE g.id = ".$id;
$GLOBALS["data"]->select($sql, $game, "Game");
return $game;
......@@ -71,12 +71,13 @@ class Game extends Record {
if(array_key_exists("filter", $_REQUEST) && $_REQUEST["filter"] == "available") {
$where_clause = "WHERE l.id IS NULL";
}
// SQL SELECT lud_games lud_esar_categories lud_loans
$sql = "SELECT g.id, g.name, g.age_min, g.age_max,
CONCAT (ec.label, ' - ', ec.name) AS label,
l.id as loan_status
FROM games g
LEFT OUTER JOIN esar_categories ec ON g.esar_category_id = ec.id
LEFT OUTER JOIN loans l ON (g.id = l.game_id AND l.is_back = 0)
FROM ".Game::$table." g
LEFT OUTER JOIN ".Esar_Category::$table." ec ON g.esar_category_id = ec.id
LEFT OUTER JOIN ".Loan::$table." l ON (g.id = l.game_id AND l.is_back = 0)
$where_clause
ORDER BY g.name";
$GLOBALS["data"]->select($sql, $games, "Game");
......
<?php
class Loan extends Record {
public $id, $game_id, $member_id;
public $start_date, $end_date, $is_back;
public $created_at, $updated_at;
public $id, $game_id, $member_id;
public $start_date, $end_date, $is_back;
public $created_at, $updated_at;
public $member_name, $is_late;
public $member_name, $is_late;
public $table = "loans";
public static $table = "lud_loans";
public function __construct($id = 0)
{
if (!$this->id) {
$this->id = $id;
public function __construct($id = 0)
{
if (!$this->id) {
$this->id = $id;
}
}
}
public static function fetch_all(&$loans, $member_id, $limit = 0) {
public static function fetch_all(&$loans, $member_id, $limit = 0) {
$loans = array();
// SQL SELECT loans games members
// SQL SELECT lud_loans lud_games lud_members
$sql = " SELECT l.id, start_date, end_date, is_back, l.created_at, l.updated_at,
g.id AS game_id, g.name as game_name,
CASE WHEN (end_date < curdate() AND is_back = 0) THEN 1 ELSE 0 END AS is_late,
CONCAT(m.firstname, ' ', m.lastname) AS member_name, m.id AS member_id
FROM loans l, games g, members m
FROM ".Loan::$table." l, ".Game::$table." g, ".Member::$table." m
WHERE
g.id = l.game_id
g.id = l.game_id
".($member_id == 0 ? "" : "AND l.member_id = ".$member_id)."
AND l.member_id = m.id
ORDER BY l.is_back ASC, start_date DESC
".($limit != 0 ? "LIMIT 0,$limit" : "");
ORDER BY l.is_back ASC, start_date DESC
".($limit != 0 ? "LIMIT 0,$limit" : "");
$GLOBALS["data"]->select($sql, $loans, "Loan", true);
return sizeof($loans);
}
public static function fetch_current_loans(&$loans) {
$loans = array();
// SQL SELECT loans games members
// SQL SELECT lud_loans lud_games lud_members
$sql = " SELECT l.id, start_date, end_date, is_back, l.created_at, l.updated_at,
g.id AS game_id, g.name as game_name,
CASE WHEN (end_date < curdate() AND is_back = 0) THEN 1 ELSE 0 END AS is_late,
CONCAT(m.firstname, ' ', m.lastname) AS member_name, m.id AS member_id
FROM loans l, games g, members m
FROM ".Loan::$table." l, ".Game::$table." g, ".Member::$table." m
WHERE
g.id = l.game_id
g.id = l.game_id
AND l.member_id = m.id
AND l.is_back = 0
ORDER BY start_date ASC";
ORDER BY start_date ASC";
$GLOBALS["data"]->select($sql, $loans, "Loan", true);
return sizeof($loans);
}
public static function fetch_loans(&$loans, $id) {
// SQL SELECT loans members
// SQL SELECT lud_loans lud_members
$sql = " SELECT l.id, start_date, end_date, is_back, l.created_at, l.updated_at,
CASE WHEN (end_date < curdate() AND is_back = 0) THEN 1 ELSE 0 END AS is_late,
l.member_id, CONCAT(m.firstname, ' ', m.lastname) AS member_name
FROM loans l, members m
FROM ".Loan::$table." l, ".Member::$table." m
WHERE l.game_id = $id
AND l.member_id = m.id
ORDER BY start_date DESC ";
......@@ -65,28 +65,40 @@ class Loan extends Record {
}
public static function fetch($id) {
// SQL SELECT loans
$sql = " SELECT l.id, start_date, end_date, is_back, l.created_at, l.updated_at, member_id,
g.name as game_name
FROM loans l, games g
public static function fetch($id) {
// SQL SELECT lud_loans lud_games
$sql = " SELECT l.id, start_date, end_date, is_back, l.created_at, l.updated_at, member_id,
l.game_id, g.name as game_name
FROM ".Loan::$table." l, ".Game::$table." g
WHERE l.id = $id
AND g.id = l.game_id";
$GLOBALS["data"]->select($sql, $loan, "Loan");
return $loan;
}
AND g.id = l.game_id";
$GLOBALS["data"]->select($sql, $loan, "Loan");
return $loan;
}
public function change_state($new_state) {
public function change_state($new_state) {
// update loans but also any reservation on the same game
// that's a multi-table update ! returns 1 or 2 depending
// on how many table have been updated
// SQL UPDATE loans
$sql = " UPDATE loans l, reservations r
SET l.is_back = ".$new_state.", l.updated_at = now(),
r.available = ".$new_state.", r.updated_at = now()
WHERE l.id = ".$this->id."
AND l.game_id = r.game_id";
// SQL SELECT lud_reservations
$sql = " SELECT count(id) AS num_res
FROM ".Reservation::$table."
WHERE game_id = ".$this->game_id;
$GLOBALS["data"]->select($sql, $rset);
if($rset->value("num_res") == 0) {
// SQL UPDATE lud_loans
$sql = " UPDATE ".Loan::$table."
SET is_back = ".$new_state.", updated_at = now()
WHERE id = ".$this->id;
} else {
// SQL UPDATE lud_loans lud_reservations
$sql = " UPDATE ".Loan::$table." l, ".Reservation::$table." r
SET l.is_back = ".$new_state.", l.updated_at = now(),
r.available = ".$new_state.", r.updated_at = now()
WHERE l.id = ".$this->id."
AND l.game_id = r.game_id";
}
$this->is_back = $new_state;
return $GLOBALS["data"]->update($sql);
}
return $GLOBALS["data"]->update($sql);
}
}
......@@ -3,6 +3,8 @@
class Media {
public $id, $description, $media_type_id, $file, $mime_type;
public static $table = "lud_medias";
public function __construct($id = 0)
{
if (!$this->id) {
......@@ -11,10 +13,10 @@ class Media {
}
public static function fetch($id) {
// SQL SELECT medias
// SQL SELECT lud_medias lud_media_types
$sql = "SELECT m.id, m.description, m.media_type_id, m.game_id, m.file,
mt.mime_type
FROM medias m, media_types mt
FROM ".Media::$table." m, ".Media_Type::$table." mt
WHERE m.id = ".$id."
AND m.media_type_id = mt.id ";
$GLOBALS["data"]->select($sql, $media, "Media");
......@@ -23,10 +25,10 @@ class Media {
public static function fetch_all(&$medias, $game_id) {
$medias = array();
// SQL SELECT medias media_types
// SQL SELECT lud_medias lud_media_types
$sql = " SELECT m.id, m.description, m.media_type_id, m.file, mt.mime_type
FROM medias m
LEFT OUTER JOIN media_types mt ON (m.media_type_id = mt.id)
FROM ".Media::$table." m
LEFT OUTER JOIN ".Media_Type::$table." mt ON (m.media_type_id = mt.id)
WHERE game_id = ".$game_id;
$GLOBALS["data"]->select($sql, $medias, "Media", true);
return sizeof($medias);
......@@ -34,16 +36,16 @@ class Media {
public function delete() {
unlink("uploads/".$this->file);
// SQL DELETE media
$sql = " DELETE FROM medias
// SQL DELETE lud_media
$sql = " DELETE FROM ".Media::$table."
WHERE id = ".$this->id;
$GLOBALS["data"]->delete($sql);
return $this->id;
}
public function create() {
// SQL INSERT medias
$sql = " INSERT INTO medias (description, game_id, media_type_id)
// SQL INSERT lud_medias
$sql = " INSERT INTO ".Media::$table." (description, game_id, media_type_id)
VALUES ('".$this->description."', ".$_REQUEST["i"].", ".
$this->media_type_id.")";
return $this->id = $GLOBALS["data"]->insert($sql);
......@@ -51,17 +53,17 @@ class Media {
public function update($filename, $filetype) {
$this->file = $filename."-".$this->id.".".$filetype;
// SQL UPDATE medias
$sql = " UPDATE medias
// SQL UPDATE lud_medias
$sql = " UPDATE ".Media::$table."
SET file = '".$this->file."'
WHERE id = ".$this->id;
return $GLOBALS["data"]->update($sql);
}
public function set_mime_type($type) {
// SQL SELECT media_types
// SQL SELECT lud_media_types
$sql = " SELECT id
FROM media_types
FROM ".Media_Type::$table."
WHERE mime_type = '".$type."'";
$GLOBALS["data"]->select($sql, $rset);
$this->media_type_id = ($rset->numrows ? $rset->value("id") : 0);
......
<?php
class Media_Type extends Record {
public $id;
public static $table = "lud_media_types";
public function __construct($id = 0)
{
if (!$this->id) {
$this->id = $id;
}
}
}
......@@ -13,7 +13,7 @@ class Member extends Record {
public $subscriptions, $loans, $reservations;
public $account;
public $table = "members";
public static $table = "lud_members";
public function __construct($id = 0) {
if (!$this->id) {
......@@ -45,13 +45,13 @@ class Member extends Record {
return false;
}
// SQL SELECT members
// SQL SELECT lud_members
$sql = "SELECT id, firstname, lastname, birth_date, address, po_town,
home_phone, work_phone, mobile_phone, fax_phone, comments, member_ref,
email, newsletter, other_members, deposit, deposit_expiration_date,
DATEDIFF(deposit_expiration_date, curdate()) as remaining_deposit_days,
CONCAT(lastname, ' ', firstname) AS full_name, account_id
FROM members
FROM ".Member::$table."
WHERE id = ".$id;
$GLOBALS["data"]->select($sql, $member, "Member");
return $member;
......@@ -59,14 +59,14 @@ class Member extends Record {
public static function fetch_birthdays() {
// from http://stackoverflow.com/a/28000048/1191256 - give credit where credit is due
// SQL SELECT members family_members
// SQL SELECT lud_members lud_family_members
$sql = "SELECT CONCAT ( firstname, ' ', lastname, '(', YEAR(CURDATE())-YEAR(birth_date), ') ') AS title,
DATE_ADD(
birth_date,
INTERVAL YEAR(CURDATE())-YEAR(birth_date) YEAR
) AS `date`,
'true' AS `badge`
FROM members
FROM ".Member::$table."
WHERE
`birth_date` IS NOT NULL
HAVING
......@@ -78,7 +78,7 @@ class Member extends Record {
INTERVAL YEAR(CURDATE())-YEAR(birth_date) YEAR
) AS `date`,
'true' AS `badge`
FROM family_members
FROM ".Family_Member::$table."
WHERE
`birth_date` IS NOT NULL
HAVING
......@@ -196,7 +196,7 @@ class Member extends Record {
public static function fetch_all(&$members) {
$members = array();
// SQL SELECT members subscriptions
// SQL SELECT lud_members subscriptions
$sql = "SELECT m.id, m.lastname, m.firstname, m.po_town,
CONCAT(m.firstname, ' ', m.lastname) AS full_name,
s.id AS subscription_id, MAX(s.end_date) AS subscription_end_date,
......@@ -208,8 +208,8 @@ class Member extends Record {
ELSE 'Valide'
END
END AS subscription_status
FROM members m
LEFT OUTER JOIN subscriptions s ON (s.member_id = m.id)
FROM ".Member::$table." m
LEFT OUTER JOIN ".Subscription::$table." s ON (s.member_id = m.id)
GROUP BY m.id
ORDER BY m.lastname";
$GLOBALS["data"]->select($sql, $members, "Member");
......@@ -218,9 +218,9 @@ class Member extends Record {
public static function fetch_last(&$members) {
$members = array();
// SQL SELECT members
// SQL SELECT lud_members
$sql = "SELECT id, po_town, CONCAT(firstname, ' ', lastname) AS full_name
FROM members
FROM ".Member::$table."
ORDER BY created_at DESC
LIMIT 0,10";
$GLOBALS["data"]->select($sql, $members, "Member");
......@@ -228,8 +228,8 @@ class Member extends Record {
}
public function save_account() {
// SQL UPDATE members
$sql = " UPDATE members SET account_id = ".$this->account_id.
// SQL UPDATE lud_members
$sql = " UPDATE ".Member::$table." SET account_id = ".$this->account_id.
" WHERE id = ".$this->id;
return $GLOBALS["data"]->update($sql);
}
......
......@@ -3,7 +3,7 @@
class Membership_Type extends Record {
public $id, $name, $description, $price;
public $table = "membership_types";
public static $table = "lud_membership_types";
public function __construct($id = 0) {
if (!$this->id) {
......@@ -17,7 +17,7 @@ class Membership_Type extends Record {
// every type. It could be an indication of wether you could delete it or not.
// SQL SELECT membership_types
$sql = "SELECT id, name, description, price
FROM membership_types
FROM ".Membership_Type::$table."
ORDER BY name";
$GLOBALS["data"]->select($sql, $membership_types, "Membership_Type", 1);
return sizeof($membership_types);
......@@ -26,7 +26,7 @@ class Membership_Type extends Record {
public static function fetch($id) {
// SQL SELECT membership_types
$sql = "SELECT id, name, description, price
FROM membership_types
FROM ".Membership_Type::$table."
WHERE id = ".$id;
$GLOBALS["data"]->select($sql, $membership_type, "Membership_Type");
return $membership_type;
......
......@@ -3,7 +3,7 @@
class Payment_Method extends Record {
public $id, $name, $description;
public $table = "payment_methods";
public static $table = "lud_payment_methods";
public function __construct($id = 0) {
if (!$this->id) {
......@@ -13,18 +13,18 @@ class Payment_Method extends Record {
public static function fetch_all(&$payment_methods) {
$payment_methods = array();
// SQL SELECT payment_methods
// SQL SELECT lud_payment_methods
$sql = "SELECT id, name, description
FROM payment_methods
FROM ".Payment_Method::$table."
ORDER BY name";
$GLOBALS["data"]->select($sql, $payment_methods, "Payment_Method", 1);
return sizeof($payment_methods);
}
public static function fetch($id) {
// SQL SELECT payment_methods
// SQL SELECT lud_payment_methods
$sql = "SELECT id, name, description
FROM payment_methods
FROM ".Payment_Method::$table."
WHERE id = ".$id;
$GLOBALS["data"]->select($sql, $payment_method, "Payment_Method");
return $payment_method;
......
......@@ -6,7 +6,7 @@ class Reservation extends Record {
public $member_name;
public $table = "reservations";
public static $table = "lud_reservations";
public function __construct($id = 0)
{
......@@ -17,11 +17,11 @@ class Reservation extends Record {
public static function fetch_all(&$reservations, $member_id = 0, $limit = 0) {
$reservations = array();
// SQL SELECT reservations games members
// SQL SELECT lud_reservations lud_games lud_members
$sql = " SELECT r.id, r.created_at, r.updated_at, r.available,
g.id AS game_id, g.name as game_name,
CONCAT(m.firstname, ' ', m.lastname) AS member_name, m.id AS member_id
FROM reservations r, games g, members m
FROM ".Reservation::$table." r, ".Game::$table." g, ".Member::$table." m
WHERE
g.id = r.game_id
".($member_id == 0 ? "" : "AND r.member_id = ".$member_id)."
......@@ -33,10 +33,10 @@ class Reservation extends Record {
}
public static function fetch($id) {
// SQL SELECT reservations
// SQL SELECT lud_reservations lud_game
$sql = " SELECT r.id, r.created_at, r.updated_at, r.member_id, r.available,
g.name as game_name
FROM reservations r, games g
FROM ".Reservation::$table." r, ".Game::$table." g
WHERE r.id = $id
AND g.id = r.game_id";
$GLOBALS["data"]->select($sql, $reservation, "Reservation");
......@@ -44,8 +44,8 @@ class Reservation extends Record {
}
public static function delete_game_reservation($game_id) {
// SQL DELETE reservations
$sql = " DELETE FROM reservations
// SQL DELETE lud_reservations
$sql = " DELETE FROM ".Reservation::$table."
WHERE game_id = $game_id ";
return $GLOBALS["data"]->delete($sql);
}
......
......@@ -4,7 +4,7 @@ class Subscription extends Record {
public $id, $start_date, $end_date, $member_id, $member_name, $membership_type_id, $payment_method_id;
public $price, $credit, $comments, $created_at, $updated_at;
public $table = "subscriptions";
public static $table = "lud_subscriptions";
public function __construct($id = 0)
{
......@@ -21,13 +21,13 @@ class Subscription extends Record {
}
public static function fetch($id) {
// SQL SELECT subscriptions membership_types payment_methods members
// SQL SELECT lud_subscriptions lud_membership_types lud_payment_methods lud_members
$sql = " SELECT ms.id, start_date, end_date, ms.member_id, CONCAT(m.lastname, ' ', m.firstname) as member_name,
ms.membership_type_id, mt.name as membership_type_name,
ms.payment_method_id, pm.name as payment_method_name,
ms.price, credit, ms.comments, ms.created_at, ms.updated_at,
DATEDIFF(end_date, curdate()) as remaining_days
FROM subscriptions ms, members m, membership_types mt, payment_methods pm
FROM ".Subscription::$table." ms, ".Member::$table." m, ".Membership_Type::$table." mt, ".Payment_Method::$table." pm
WHERE ms.id = ".$id."
AND ms.member_id = m.id
AND ms.membership_type_id = mt.id
......@@ -39,13 +39,13 @@ class Subscription extends Record {
public static function fetch_all(&$subscriptions, $member_id) {
$subscriptions = array();
// SQL SELECT subscriptions members membership_types payment_methods
// SQL SELECT lud_subscriptions lud_members lud_membership_types lud_payment_methods
$sql = " SELECT ms.id, start_date, end_date, ms.member_id, CONCAT(m.lastname, ' ', m.firstname) as member_name,
ms.membership_type_id, mt.name as membership_type_name,
ms.payment_method_id, pm.name as payment_method_name,
ms.price, credit, ms.comments, ms.created_at, ms.updated_at,
DATEDIFF(end_date, curdate()) as remaining_days
FROM subscriptions ms, members m, membership_types mt, payment_methods pm
FROM ".Subscription::$table." ms, ".Member::$table." m, ".Membership_Type::$table." mt, ".Payment_Method::$table." pm
WHERE member_id = ".$member_id."
AND ms.member_id = m.id
AND ms.membership_type_id = mt.id
......@@ -57,14 +57,14 @@ class Subscription extends Record {
}
public function delete() {
// SQL SELECT subscriptions
// SQL SELECT lud_subscriptions
$sql = " SELECT id
FROM subscriptions
FROM ".Subscription::$table."
WHERE id = ".$this->id;
$GLOBALS["data"]->select($sql, $rset);
if($rset->numrows) {
// SQL DELETE subscription
$sql = " DELETE FROM subscriptions
// SQL DELETE lud_subscription
$sql = " DELETE FROM ".Subscription::$table."
WHERE id = ".$this->id;
$GLOBALS["data"]->delete($sql);
return $rset->value("id");
......
......@@ -57,13 +57,27 @@ class User extends Record {
$context = stream_context_create($opts);
$json_user_info = file_get_contents($GLOBALS["saas_api_url"], false, $context);
if($json_user_info == "") {
return false;
return new User(0);
}
$user = json_decode($json_user_info);
$_SESSION["logged_user"] = $user;
$user = new User(0);
$user->set_properties(json_decode($json_user_info));
return $user;
}
public function set_properties($json) {
$this->id = $json->id;
$this->name = $json->name;
$this->email = $json->email;
$this->active = $json->active;
$this->alert_msg = $json->alert_msg;
$this->roles = array();
foreach(get_object_vars($json->roles) as $var => $value) {
foreach(get_object_vars($value) as $role => $active) {
$this->roles[$var][$role] = $active;
}
}
}
public static function fetch_by_name($user) {
// SQL SELECT users
$sql = "SELECT id, name, password_digest, email, active
......
......@@ -34,13 +34,10 @@ class AppController {
} else {
if(array_key_exists("a", $_REQUEST) && $_REQUEST["a"] == "logout") {
// logout
// unset($_SESSION["user"]);
session_destroy();
header("Location: index.php?o=users", true, 302);
} else {
// stay authenticated - do what your roles decides
// give me a break - user is in the session after all
// $logged_user = User::fetch($_SESSION["user_id"]);
}
}
......@@ -73,8 +70,7 @@ class AppController {
// extract the local roles from the session
// application_instance id and key should be in the config file
if(!array_key_exists($GLOBALS["application_instance_id"],
$_SESSION["user"]->roles)) {
if(!array_key_exists($GLOBALS["application_instance_id"], $_SESSION["user"]->roles)) {
$this->render("no_access");
exit();
}
......
......@@ -9,6 +9,10 @@ class GamesController extends AppController {
$this->render($this->$function_name());
}
function _index() {
return $this->_list();
}
function _new() {
$game = new Game(0);
$_REQUEST["i"] = $game->id;
......
......@@ -11,6 +11,10 @@ class MembersController extends AppController {
$this->render($this->$function_name());
}
function _index() {
return $this->_list();
}
function _create() {
// TODO : posted datas should be validated
// who is responsible for that ? i think
......
......@@ -7,7 +7,7 @@ class UsersController extends AppController {
function UsersController () {
$this->AppController();
if(!array_key_exists("logged_user", $GLOBALS) || $GLOBALS["logged_user"]->id == 0) {
if(!array_key_exists("user", $GLOBALS) || $GLOBALS["user"]->id == 0) {
$render = "users/loginform";
} else {
$function_name = "_".$_REQUEST["a"];
......
......@@ -22,5 +22,4 @@ $_REQUEST["o"] = (array_key_exists("o", $_REQUEST)) ? $_REQUEST["o"] : "home";
// call of the controller
$controller = str_replace(' ','',ucwords(str_replace('_',' ',$_REQUEST["o"])))."Controller";
$ctrl = new $controller();
// DEBUG
echo "<pre>"; print_r($_SESSION); echo "</pre>";
// DEBUG echo "<pre>"; print_r($_SESSION); echo "</pre>";
......@@ -17,89 +17,45 @@
<title>{% block title %}{% endblock %} - Ludothèque</title>
</head>
<body>
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
data-target="#navbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.php">
<img id="logo" src="images/ludo-associative.jpg" alt="associative - ludotheque"></a>
</div>