Commit 0ad01526 authored by Denis S. Valdenaire's avatar Denis S. Valdenaire

Merge branch 'complete_templating' into 'master'

Complete templating

Merge intermédiaire pour prendre en compte le templating total.

See merge request !2
parents 43a4dcc8 1eb8934b
......@@ -99,7 +99,7 @@ class Member extends Record {
}
public function update_subscription() {
$subscription = Subscription::fetch($GLOBALS["data"]->db_escape_string($_REQUEST["i"]));
$subscription = Subscription::fetch($GLOBALS["data"]->db_escape_string($_REQUEST["subscription_id"]));
$subscription->update();
}
......
......@@ -30,6 +30,9 @@ class Payment_Method extends Record {
return $payment_method;
}
// FIXME : hey you can't just delete like that
// if the payment method is used somewhere, that
// can't be done
public static function delete($id) {
// SQL SELECT payment_methods
$sql = " SELECT id
......
......@@ -48,7 +48,7 @@ class Record {
$sql = " UPDATE ".$this->table." SET ".$update_sql." updated_at = now()
WHERE id = ".$this->id;
return $GLOBALS["data"]->update($sql);
}
}
}
}
......@@ -15,15 +15,21 @@ class Role extends Record {
/* fetch ALL the roles, with the selected field = user_id if the
user has the role, NULL otherwise.
Be sure to use user->has_role to check if a user has a role.
FIXME : i can't see the point of doing that
Back to a better solution but we'll see that next
*/
public static function fetch_user_roles($user_id) {
$roles = array();
// SQL SELECT roles user_roles
$sql = "SELECT r.id, r.name, r.description, ur.user_id AS selected
FROM roles r
LEFT OUTER JOIN user_roles ur
ON (r.id = ur.role_id AND ur.user_id = ".$user_id.")";
$GLOBALS["data"]->select($sql, $roles, "Role");
$sql = "SELECT r.name
FROM roles r, user_roles ur
WHERE r.id = ur.role_id AND ur.user_id = ".$user_id;
$GLOBALS["data"]->select($sql, $rset);
if($rset->numrows) {
do {
$roles[$rset->value("name")] = 1;
} while($rset->nextrow());
}
return $roles;
}
......
......@@ -66,14 +66,7 @@ class User extends Record {
}
public function has_role($role_name) {
while(list($key, $val) = each($this->roles)) {
if($val->name == $role_name) {
reset($this->roles);
return $val->selected == $this->id;
}
}
reset($this->roles);
return false;
return (array_key_exists($role_name, $this->roles));
}
public function update_roles() {
......
......@@ -19,6 +19,7 @@ class AppController {
'cache' => false
));
$this->context["global"] = $GLOBALS;
$this->context["request"] = $_REQUEST;
}
function set($var, &$val) {
......@@ -58,7 +59,11 @@ class AppController {
try {
$classname = $this->model;
$object = new $classname(0);
$object->create();
if($object->create()) {
$this->set_message("Création effectuée");
} else {
$this->set_message("Aucun nouvel objet n'a été créé");
}
// FIXME : may be this fail !!!
if($render == "list") {
$classname::fetch_all($objects);
......@@ -96,8 +101,10 @@ class AppController {
try {
$classname = $this->model;
$object = $classname::fetch($GLOBALS["data"]->db_escape_string($_REQUEST["i"]));
if($object->id != 0) {
$object->update();
if($object->id != 0) {
if($object->update()) {
$this->set_message("Modification enregistrée");
}
$objects = array();
$classname::fetch_all($objects);
$this->set("objects", $objects);
......@@ -114,6 +121,7 @@ class AppController {
try {
$classname = $this->model;
if($_REQUEST["i"] = $classname::delete($_REQUEST["i"])) {
$this->set_message("Suppression effectuée");
$classname::fetch_all($objects);
$this->set("objects", $objects);
return $_REQUEST["o"]."/list";
......
......@@ -140,11 +140,11 @@ class MembersController extends AppController {
function _create_subscription() {
try {
$member = Member::fetch($GLOBALS["data"]->db_escape_string($_REQUEST["member_id"]));
$member = Member::fetch($GLOBALS["data"]->db_escape_string($_REQUEST["i"]));
if($member->id != 0) {
$_REQUEST["member_id"] = $member->id;
$member->create_subscription();
$member->fetch_subscriptions();
$_REQUEST["i"] = $member->id;
$this->set("member", $member);
return "members/subscriptions";
} else {
......@@ -157,11 +157,11 @@ class MembersController extends AppController {
function _update_subscription() {
try {
$member = Member::fetch($GLOBALS["data"]->db_escape_string($_REQUEST["member_id"]));
$member = Member::fetch($GLOBALS["data"]->db_escape_string($_REQUEST["i"]));
if($member->id != 0) {
$_REQUEST["member_id"] = $member->id;
$member->update_subscription();
$member->fetch_subscriptions();
$_REQUEST["i"] = $member->id;
$this->set("member", $member);
return "members/subscriptions";
} else {
......
......@@ -35,142 +35,17 @@ if(!array_key_exists("user_id", $_SESSION)) {
$logged_user = User::fetch($_SESSION["user_id"]);
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" href="images/favicon.png">
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/bootstrap-theme.min.css">
<link rel="stylesheet" href="css/zabuto_calendar.min.css">
<link rel="stylesheet" href="css/jquery.dataTables.min.css">
<link rel="stylesheet" href="css/bootstrap-datetimepicker.css">
<link rel="stylesheet" href="css/bootstrap-switch.min.css">
<link rel="stylesheet" href="css/bootstrap-multiselect.css">
<!-- link rel="stylesheet" href="css/datatables.min.css" -->
<link rel="stylesheet" href="css/styles.css">
<script src="js/jquery-2.1.4.min.js"></script>
</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>
<?php if($logged_user->id != 0) {
$menu_entries = array();
?>
<div id="navbar" class="collapse navbar-collapse navbar-right">
<ul class="nav navbar-nav">
<?php if($logged_user->has_role("games")) {
$menu_entries["esar_categories"] = "Catégories Esar";
?>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true"
aria-expanded="false">Jeux...<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="index.php?o=games">Catalogue des jeux</a></li>
<li><a href="index.php?o=loans">Emprunts</a></li>
</ul>
</li>
<?php } ?>
<?php if($logged_user->has_role("members")) {
$menu_entries["membership_types"] = "Types d'adhésion";
$menu_entries["payment_methods"] = "Méthodes de paiement";
?>
<li><a href="index.php?o=members">Adhérents</a></li>
<?php } ?>
<?php if($logged_user->has_role("admin")) { ?>
<li><a href="index.php?o=users&a=list">Utilisateurs</a></li>
<?php } ?>
<?php if(sizeof($menu_entries)) { ?>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true"
aria-expanded="false">Options <span class="caret"></span></a>
<ul class="dropdown-menu">
<?php while(list($key, $val) = each($menu_entries)) { ?>
<li><a href="index.php?o=<?=$key?>&a=list"><?=$val?></a></li>
<?php } ?>
</ul>
</li>
<?php } ?>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="index.php?o=users&a=edit&i=<?=$logged_user->id?>"><span class="glyphicon glyphicon-user"></span></a></li>
<li><a href="index.php?a=logout"><span class="glyphicon glyphicon-log-out"></span></a></li>
</ul>
<form class="navbar-form navbar-right">
<div id="search-all" >
<input class="typeahead" type="text" placeholder="Recherche...">
</div>
</form>
</div>
<?php } ?>
</div>
</nav>
<form action="index.php" method="POST" id="defaultform" name="defaultform"
class="form-horizontal" enctype="multipart/form-data">
<!-- div class="col-sm-9 col-md-10 main" -->
<div class="container">
<?php
$_REQUEST["a"] = (array_key_exists("a", $_REQUEST)) ? $_REQUEST["a"] : "";
$_REQUEST["i"] = (array_key_exists("i", $_REQUEST)) ? $_REQUEST["i"] : "";
if($logged_user->id == 0) {
// not authenticated
$_REQUEST["o"] = "users";
// include("controllers/users.php");
} else {
if(array_key_exists("o", $_REQUEST) && $_REQUEST["o"] != ""
&& file_exists("controllers/".$_REQUEST["o"].".php")) {
// include("controllers/".$_REQUEST["o"].".php");
} else {
if(!array_key_exists("o", $_REQUEST) || $_REQUEST["o"] == ""
|| !file_exists("controllers/".$_REQUEST["o"].".php")) {
$_REQUEST["o"] = "home";
// include("controllers/home.php");
}
}
$_REQUEST["a"] = (array_key_exists("a", $_REQUEST)) ? $_REQUEST["a"] : "";
$_REQUEST["i"] = (array_key_exists("i", $_REQUEST)) ? $_REQUEST["i"] : "";
// call of the controller
$controller = str_replace(' ','',ucwords(str_replace('_',' ',$_REQUEST["o"])))."Controller";
// ucfirst($_REQUEST["o"])."Controller";
$ctrl = new $controller();
?>
</div>
<input type="hidden" name="o" id="o" value="<?=$_REQUEST["o"]?>">
<input type="hidden" name="a" id="a" value="<?=$_REQUEST["a"]?>">
<input type="hidden" name="i" id="i" value="<?=$_REQUEST["i"]?>">
</form>
<footer>
<?php if($debug) { ?>
<pre>
REQUEST :
<?php print_r($_REQUEST) ?>
SESSION :
<?php print_r($_SESSION) ?>
</pre>
<?php } ?>
</footer>
<!-- Placed at the end of the document so the pages load faster -->
<script src="js/bootstrap.min.js"></script>
<script src="js/jquery.dataTables.min.js"></script>
<!-- script src="js/datatables.js"></script -->
<script src="js/zabuto_calendar.min.js"></script>
<script src="js/typeahead.bundle.min.js"></script>
<script src="js/moment-with-locales.min.js"></script>
<script src="js/bootstrap-datetimepicker.js"></script>
<script src="js/bootstrap-switch.min.js"></script>
<script src="js/bootstrap-multiselect.js"></script>
<?php if($logged_user->id != 0) { ?>
<script src="js/functions.js"></script>
<?php } ?>
</body>
</html>
......@@ -14,6 +14,7 @@
<!-- link rel="stylesheet" href="css/datatables.min.css" -->
<link rel="stylesheet" href="css/styles.css">
<script src="js/jquery-2.1.4.min.js"></script>
<title>{% block title %}{% endblock %} - Ludothèque</title>
</head>
<body>
<nav class="navbar navbar-default">
......@@ -28,22 +29,40 @@
<a class="navbar-brand" href="index.php">
<img id="logo" src="images/ludo-associative.jpg" alt="associative - ludotheque"></a>
</div>
{% if global['logged_user'].id %}
<div id="navbar" class="collapse navbar-collapse navbar-right">
<ul class="nav navbar-nav">
<li><a href="index.php?o=games">Jeux</a></li>
{% if global['logged_user'].roles['games'] %}
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true"
aria-expanded="false">Jeux...<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="index.php?o=games">Catalogue des jeux</a></li>
<li><a href="index.php?o=loans">Emprunts</a></li>
</ul>
</li>
{% endif %}
{% if global['logged_user'].roles['members'] %}
<li><a href="index.php?o=members">Adhérents</a></li>
{% endif %}
{% if global['logged_user'].roles['admin'] %}
<li><a href="index.php?o=users&a=list">Comptes</a></li>
{% endif %}
{% if global['logged_user'].roles['games'] or user.roles['members'] %}
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true"
aria-expanded="false">Options <span class="caret"></span></a>
<ul class="dropdown-menu">
{% if global['logged_user'].roles['games'] %}
<li><a href="index.php?o=esar_categories&a=list">Catégories Esar</a></li>
{% endif %}
{% if global['logged_user'].roles['members'] %}
<li><a href="index.php?o=membership_types&a=list">Types d'adhésion</a></li>
<li><a href="index.php?o=payment_methods&a=list">Méthodes de paiement</a></li>
{% endif %}
</ul>
</li>
{% endif %}
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="index.php?o=users&a=edit&i=<?=$logged_user->id?>"><span class="glyphicon glyphicon-user"></span> Mon compte</a></li>
......@@ -64,19 +83,19 @@
<div class="container">
{% block content %}{% endblock %}
</div>
<input type="hidden" name="o" id="o" value="<?=$_REQUEST["o"]?>">
<input type="hidden" name="a" id="a" value="<?=$_REQUEST["a"]?>">
<input type="hidden" name="i" id="i" value="<?=$_REQUEST["i"]?>">
<input type="hidden" name="o" id="o" value="{{ request['o'] }}">
<input type="hidden" name="a" id="a" value="{{ request['a'] }}">
<input type="hidden" name="i" id="i" value="{{ request['i'] }}">
</form>
<footer>
<?php if($debug) { ?>
{% if global['debug'] %}
<pre>
REQUEST :
<?php print_r($_REQUEST) ?>
SESSION :
<?php print_r($_SESSION) ?>
o : {{ request['o'] }}
a : {{ request['a'] }}
i : {{ request['i'] }}
</pre>
<?php } ?>
{% endif %}
</footer>
<!-- Placed at the end of the document so the pages load faster -->
<script src="js/bootstrap.min.js"></script>
......
<div class="panel panel-default">
<div class="panel-heading">
<h4>
<span class="glyphicon glyphicon-list-alt" style="margin-right: 10px;" ></span>
{% if object.id %} Catégorie ESAR : {{ object.name }} {% else %} Nouvelle catégorie ESAR {% endif %}
</h4>
</div>
<div class="panel-body">
{% extends 'modal.html' %}
{% block modal_title %}
{% if object.id %} Catégorie ESAR : {{ object.name }} {% else %} Nouvelle catégorie ESAR {% endif %}
{% endblock %}
{% block modal_body %}
<div class="form-group">
<label class="control-label col-sm-2" for="name">Nom</label>
<div class="col-sm-4">
......@@ -17,49 +13,9 @@
<input type="text" id="label" name="label" class="form-control" value="{{ object.label }}"/>
</div>
</div>
<div class="form-group">
<div class="col-sm-12" align="center">
<input type="button" class="btn btn-primary" id="back_button" value="&lt;&lt; Retour à la liste">
{% if object.id != 0 %}
<input type="submit" class="btn btn-success" id="save_button" value="Enregistrer les changements">
<input type="button" class="btn btn-danger" id="delete_button" value="Supprimer">
{% else %}
<input type="button" class="btn btn-success" id="save_button" value="Créer">
{% endif %}
</div>
</div>
<!-- end of panel -->
</div>
</div>
<script>
// buttons events
$('#save_button').click(function(){
if(document.defaultform.name.value == 0) {
alert ("Vous n'avez pas saisi de nom !");
return false;
}
if($('#i').val() == 0) {
$('#a').val('create');
} else {
$('#a').val('update');
}
document.defaultform.submit();
return true;
});
$('#delete_button').click(function(){
var msg = 'Voulez-vous réellement supprimer cette catégorie ?\n' +
'Cette action n\'est possible que si celle-ci n\'a pas été\n' +
'utilisée pour la classification d\'un jeu.';
if(confirm(msg)) {
$('#a').val('delete');
document.defaultform.submit();
}
});
$('#back_button').click(function(){
// TODO this function should verify that the object has not been modified
// and if yes, ask for confirmation from the user.
window.location.href='index.php?o=esar_categories&a=list';
});
</script>
{% endblock %}
{% block javascript_msg %}
var msg = 'Voulez-vous réellement supprimer cette catégorie ?\n' +
'Cette action n\'est possible que si celle-ci n\'a pas été\n' +
'utilisée pour la classification d\'un jeu.';
{% endblock %}
{% extends "base.html" %}
{% block title %}Catégories ESAR{% endblock %}
{% block content %}
<div class="panel panel-default">
<div class="panel-heading">
<span style="font-size: 150%;" class="glyphicon glyphicon-user"></span>
<span style="font-size: 150%; font-weight: bold">
<span style="font-size: 150%;" class="glyphicon glyphicon-user"></span>
<span style="font-size: 150%; font-weight: bold">
Catégories ESAR
</span>
</span>
<span class="btn btn-success btn-md" style="float: right" id="new_button">
<i class="glyphicon glyphicon-plus"></i>
<span>Nouvelle catégorie...</span>
</span>
<button type="button" class="btn btn-success btn-md" style="float: right"
data-toggle="modal" data-target="#editModal" data-id="0">
<i class="glyphicon glyphicon-plus"></i>
<span>Nouvelle catégorie...</span>
</button>
</div>
</div>
<div class="panel-body">
{% include 'ihm_messages.html' %}
<div class="col-sm-12" align="center">
<table id="list_esar" style="display:none">
<thead>
<tr>
<th>Label</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<table id="object_list" style="display:none">
<thead>
<tr>
<th>Label</th>
<th>Description</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for key, val in objects %}
<tr>
<td>
<a href="index.php?o=esar_categories&a=edit&i={{ val.id }}">{{ val.label }}</a>
</td>
<td>
{{ val.name }}
</td>
</tr>
<tr>
<td>{{ val.label }}</td>
<td>{{ val.name }}</td>
<td align="center">
<button type="button" class="btn btn-success btn-xs"
data-toggle="modal" data-target="#editModal" data-id="{{ val.id }}">
<i class="glyphicon glyphicon-edit"></i>
</button>
<a href="#" onClick="if(confirm('Êtes vous sur ?')) { $('#a').val('delete'); $('#i').val('{{ val.id }}'); defaultform.submit()}" href="#">
<button type="button" class="btn btn-danger btn-xs">
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span></button>
</a>
</td>
</tr>
{% else %}
<tr>
<td colspan="2">
......@@ -39,29 +52,44 @@
</td>
</tr>
{% endfor %}
</tbody>
</tbody>
</table>
</div>
<!-- end of panel -->
</div>
</div>
<!-- edit modal skel -->
<div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="editModalLabel">
<div class="modal-dialog">
<div class="modal-content">
</div>
</div>
</div>
<!-- end edit modal -->
<script>
$(document).ready(function() {
$('#list_esar').DataTable({
$('#object_list').DataTable({
"autoWidth": false,
"fnDrawCallback": function() {
$(this).show();
}
});
$('#new_button').click(function(){
$('#a').val('new');
defaultform.submit();
});
$("#editModal").on("show.bs.modal", function(e) {
var button = $(e.relatedTarget);
if(button.data('id') == 0) {
$(this).find(".modal-content").load("index.php?o=" + $('#o').val() + "&a=new");
} else {
$(this).find(".modal-content").load("index.php?o=" + $('#o').val() + "&a=edit&i=" + button.data('id'));
}
}).on("hidden.bs.modal", function(e) {
$(this).find(".modal-content").empty();
});
});
/* FIXME : translation of the table
see https://datatables.net/plug-ins/i18n/French
*/
</script>
{% endblock %}
{% extends "base.html" %}
{% block title %}Catalogue des jeux{% endblock %}
{% block content %}
<div class="panel panel-default">
<div class="panel-heading">
<h4><!-- class="panel-title" -->
......@@ -211,3 +214,4 @@ $('#reservation_button').click(function(){
document.defaultform.submit();
});
</script>
{% endblock %}
{% extends "base.html" %}
{% block title %}Catalogue des jeux{% endblock %}
{% block content %}
<div class="panel panel-default">
<div class="panel-heading">
<span style="font-size: 150%;" class="glyphicon glyphicon-knight"></span>
......@@ -66,3 +69,4 @@ $(document).ready(function() {
see https://datatables.net/plug-ins/i18n/French
*/
</script>
{% endblock %}
{% extends "base.html" %}
{% block title %}Home{% endblock %}
{% block content %}
<div class="row">
<div class="col-sm-4">
<!-- right hand side of the screen, w/ loans status & new buttons -->
......@@ -47,3 +50,4 @@ $(document).ready(function () {
});
});
</script>
{% endblock %}
{% for key, val in global['ihm_message'] %}
<div class="alert alert-{{ val.level }} alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
{{ val.msg }}
</div>
{% endfor %}
{% extends "base.html" %}
{% block title %}Catalogue des jeux{% endblock %}
{% block content %}
<div class="panel panel-default">
<div class="panel-heading">
<h4><span class="glyphicon glyphicon-user" style="margin-right: 10px" ></span>
......@@ -298,3 +301,4 @@ $(document).ready(function () {
});
});
</script>
{% endblock %}
{% extends "base.html" %}
{% block title %}Catalogue des jeux{% endblock %}
{% block content %}
<div class="panel panel-default">
<div class="panel-heading">
<span style="font-size: 150%;" class="glyphicon glyphicon-user"></span>
......@@ -64,3 +67,4 @@ $(document).ready(function() {
see https://datatables.net/plug-ins/i18n/French
*/
</script>
{% endblock %}
{% extends "base.html" %}
{% block title %}{{ member.lastname }} {{ member.firstname }} - Adhésions{% endblock %}
{% block content %}
<div class="panel panel-default">
<div class="panel-heading">
<span class="btn btn-primary" id="back_button">
......@@ -6,10 +9,11 @@
</span>
<span style="font-size: 150%; font-weight: bold">&nbsp;{{ member.lastname }} {{ member.firstname }} - Adhésions&nbsp;</span>