Commit 908f323d authored by Denis S. Valdenaire's avatar Denis S. Valdenaire

avance dans le templating total + modif des subscriptions en modal

parent 43a4dcc8
......@@ -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();
}
......
......@@ -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) {
......
......@@ -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>
......
{% 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>
......@@ -65,3 +68,4 @@ $(document).ready(function() {
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 %}
{% 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 %}Catalogue des jeux{% 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>
<span class="btn btn-success btm-md" style="float: right" id="new_button">
<button type="button" class="btn btn-success btm-md" style="float: right"
data-toggle="modal" data-target="#editModal" data-id="0">
<i class="glyphicon glyphicon-plus"></i>
<span>Nouvelle adhésion...</span>
</span>
</button>
</div>
<div class="panel-body">
......@@ -37,10 +41,11 @@
<td>{{ val.price }}</td>
<td>{{ val.comments }}</td>
<td>
<a href="index.php?o=subscriptions&a=edit&i={{ val.id }}">
<button type="button" class="btn btn-default btn-sm">
<span class="glyphicon glyphicon-edit" aria-hidden="true"></span></button>
</a>
<button type="button" class="btn btn-success btm-md"
data-toggle="modal" data-target="#editModal" data-id="{{ val.id }}">
<i class="glyphicon glyphicon-edit"></i>
</button>
<a onClick="if(confirm('Êtes vous sur ?')) { $('#a').val('delete_subscription'); $('i').val('{{ val.id }}'); defaultform.submit()}" href="#">
<button type="button" class="btn btn-danger btn-sm">
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span></button>
......@@ -60,6 +65,14 @@
<!-- 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 () {
......@@ -68,10 +81,24 @@ $(document).ready(function () {
// and if yes, ask for confirmation from the user.
window.location.href='index.php?o=members&a=edit&i={{ member.id }}';
});
$("#editModal").on("show.bs.modal", function(e) {
var button = $(e.relatedTarget);
if(button.data('id') == 0) {
$(this).find(".modal-content").load("index.php?o=subscriptions&a=new&i={{ member.id }}");
} else {
$(this).find(".modal-content").load("index.php?o=subscriptions&a=edit&i=" + button.data('id'));
}
}).on("hidden.bs.modal", function(e) {
$(this).find(".modal-content").empty();
});
/*
$('#new_button').click(function(){
$('#a').val('new');
$('#o').val('subscriptions');
defaultform.submit();
});
*/
});
</script>
{% endblock %}
<div class="panel panel-default">
<div class="panel-heading">
<h4><!-- class="panel-title" -->
<span class="glyphicon glyphicon-th-list" style="margin-right: 10px" ></span>
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="myModalLabel">
<span class="glyphicon glyphicon-th-list" style="margin-right: 10px" ></span>
{% if object.id %} Adhésion du {{ object.start_date }} {% else %} Nouvelle adhésion {% endif %}
</h4>
</h4>
</div>
<div class="panel-body">
<div class="modal-body">
<div class="form-group">
<div class="form-group">
<label class="control-label col-sm-2" for="start_date">Début</label>
<div class="col-sm-4">
<div class='input-group date' id='start_datetimepicker'>
<input type="text" id="start_date" name="start_date" class="form-control"/>
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
<script type="text/javascript">
<div class='input-group date' id='start_datetimepicker'>
<input type="text" id="start_date" name="start_date" class="form-control"/>
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
<script type="text/javascript">
$(function () {
$('#start_datetimepicker').datetimepicker({
locale: 'fr',
format: 'DD-MM-YYYY',
locale: 'fr',
format: 'DD-MM-YYYY',
defaultDate: new Date({% if object.start_date %} '{{ object.start_date }}' {% endif %})
})
.on('changeDate', function(ev){
$('#start_date') = ev.format();
});
})
.on('changeDate', function(ev){
$('#start_date') = ev.format();
});
});
</script>
</div>
<!-- TODO : these are dependant fields -->
<label class="control-label col-sm-2" for="end_date">Fin</label>
<!-- TODO : these are dependant fields -->
<label class="control-label col-sm-2" for="end_date">Fin</label>
<div class="col-sm-4">
<div class='input-group date' id='end_datetimepicker'>
<input type="text" id="end_date" name="end_date" class="form-control"/>
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
<script type="text/javascript">
<div class='input-group date' id='end_datetimepicker'>
<input type="text" id="end_date" name="end_date" class="form-control"/>
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
<script type="text/javascript">
$(function () {
$('#end_datetimepicker').datetimepicker({
locale: 'fr',
format: 'DD-MM-YYYY',
locale: 'fr',
format: 'DD-MM-YYYY',
defaultDate: new Date({% if object.end_date %} '{{ object.end_date }}' {% endif %})
})
.on('changeDate', function(ev){
$('#end_date') = ev.format();
});
})
.on('changeDate', function(ev){
$('#end_date') = ev.format();
});
});
</script>
</div>
</div>
<div class="form-group">
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="membership_type_id">Type d'adhésion</label>
<div class="col-sm-4">
<select id="membership_type_id" name="membership_type_id" class="form-control">
</select>
<script>
$('#membership_type_id').html('<option value="">Loading...</option>');
$.ajax({url: 'api.php?o=membership_types&a=list',
</select>
<script>
$('#membership_type_id').html('<option value="">Loading...</option>');
$.ajax({url: 'api.php?o=membership_types&a=list',
success: function(output) {
var html = '';
$.each(output, function(key, val){
html = html + '<option value="' + val.id + '"'
var html = '';
$.each(output, function(key, val){
html = html + '<option value="' + val.id + '"'
+ (val.id == {{ object.membership_type_id ?: 0 }} ? ' selected ' : '' ) + '>'
+ val.name + '</option>';
});
+ val.name + '</option>';
});
$('#membership_type_id').html(html);
},
error: function (xhr, ajaxOptions, thrownError) {
// well, that's weird, ok :)
$('#membership_type_id').html('<option value="">' + xhr.status + ' ' + thrownError + '</option>');
// well, that's weird, ok :)
$('#membership_type_id').html('<option value="">' + xhr.status + ' ' + thrownError + '</option>');
// alert(xhr.status + " " + thrownError);
}});
</script>
</script>
</div>
<label class="control-label col-sm-2" for="payment_method_id">Méthode de paiement</label>
<label class="control-label col-sm-2" for="payment_method_id">Méthode de paiement</label>
<div class="col-sm-4">
<select id="payment_method_id" name="payment_method_id" class="form-control">
</select>
<script>
$('#payment_method_id').html('<option value="">Loading...</option>');
$.ajax({url: 'api.php?o=payment_methods&a=list',
</select>
<script>
$('#payment_method_id').html('<option value="">Loading...</option>');
$.ajax({url: 'api.php?o=payment_methods&a=list',
success: function(output) {
var html = '';
$.each(output, function(key, val){
html = html + '<option value="' + val.id + '"'
var html = '';
$.each(output, function(key, val){
html = html + '<option value="' + val.id + '"'
+ (val.id == {{ object.payment_method_id ?: 0 }} ? ' selected ' : '' ) + '>'
+ val.name + '</option>';
});
+ val.name + '</option>';
});
$('#payment_method_id').html(html);
},
error: function (xhr, ajaxOptions, thrownError) {
// well, that's weird, ok :)
$('#payment_method_id').html('<option value="">' + xhr.status + ' ' + thrownError + '</option>');
// well, that's weird, ok :)
$('#payment_method_id').html('<option value="">' + xhr.status + ' ' + thrownError + '</option>');
// alert(xhr.status + " " + thrownError);
}});
</script>
</script>
</div>
</div>
<div class="form-group">
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="price">Prix</label>
<div class="col-sm-4">
<input type="text" id="price" name="price" class="form-control" value="{{ object.price }}"/>
......@@ -109,27 +111,26 @@
<div class="col-sm-1">
<input type="checkbox" id="credit" name="credit" class="form-control" {{ object.credit ? "checked" }}/>
</div>