Commit 848e0fd6 authored by Denis S. Valdenaire's avatar Denis S. Valdenaire

corrections/evolutions/etc...

parent b106dbe5
<?php
session_start();
function myautoload($class_name) {
if(strpos($class_name, "Controller")) {
include "controllers/". //strtolower(substr($class_name, 0, -10)).".php";
......@@ -14,6 +13,7 @@ spl_autoload_register("myautoload");
include("config/config.php");
global $data;
$data = new data();
$session_db = new session_db();
global $logged_user;
$logged_user = new User(0);
if(!array_key_exists("user_id", $_SESSION)) {
......@@ -33,4 +33,3 @@ if(array_key_exists("o", $_REQUEST) && $_REQUEST["o"] != ""
} else {
header($_SERVER['SERVER_PROTOCOL'] . ' 400 Bad Request', true, 400);
}
?>
......@@ -87,5 +87,3 @@ class Loan extends Record {
return $GLOBALS["data"]->update($sql);
}
}
?>
......@@ -145,7 +145,7 @@ class Member extends Record {
}
public function update_loan() {
$loan = Loan::fetch($GLOBALS["data"]->db_escape_string($_REQUEST["i"]));
$loan = Loan::fetch($GLOBALS["data"]->db_escape_string($_REQUEST["loan_id"]));
$loan->update();
}
......
......@@ -73,5 +73,3 @@ class Subscription extends Record {
}
}
?>
......@@ -86,15 +86,16 @@ class MembersController extends AppController {
}
function _create_loan() {
$_REQUEST["a"] = "loans";
$this->context["request"] = $_REQUEST;
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) {
$member->fetch_subscriptions();
if($member->has_valid_subscription()) {
$member->create_loan();
$member->fetch_loans();
} // no error message - normally you can't do this
$_REQUEST["i"] = $member->id;
$this->set("member", $member);
return "members/loans";
} else {
......@@ -106,13 +107,14 @@ class MembersController extends AppController {
}
function _update_loan() {
$_REQUEST["a"] = "loans";
$this->context["request"] = $_REQUEST;
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) {
$member->fetch_subscriptions();
$member->update_loan();
$member->fetch_loans();
$_REQUEST["i"] = $member->id;
$this->set("member", $member);
return "members/loans";
} else {
......@@ -139,10 +141,11 @@ class MembersController extends AppController {
}
function _create_subscription() {
$_REQUEST["a"] = "subscriptions";
$this->context["request"] = $_REQUEST;
try {
$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();
$this->set("member", $member);
......@@ -156,10 +159,11 @@ class MembersController extends AppController {
}
function _update_subscription() {
$_REQUEST["a"] = "subscriptions";
$this->context["request"] = $_REQUEST;
try {
$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();
$this->set("member", $member);
......@@ -173,6 +177,8 @@ class MembersController extends AppController {
}
function _delete_subscription() {
$_REQUEST["a"] = "subscriptions";
$this->context["request"] = $_REQUEST;
try {
$member = Member::fetch($GLOBALS["data"]->db_escape_string($_REQUEST["member_id"]));
if($member->id != 0) {
......
<div>
<p style="font-size:120%; text-align: center">Erreur de la base données</p>
<p>Une requête a échouée.</p>
{% extends "base.html" %}
{% block title %}Erreur{% endblock %}
{% block content %}
<div class="panel panel-danger">
<div class="panel-heading">
<span class="glyphicon glyphicon-remove-sign" style="font-size:150%" ></span>
<span style="font-size: 150%; font-weight: bold">
Erreur de base de données
</span>
</div>
<div class="panel-body">
{% if global['debug'] %}
<p style="background-color: white;">
<table style="border: 1px solid black;">
<tr style="background-color: gray">
<th>Le Fameux Code d'Erreur</th>
<td>{{ global['sql_error_code'] }}</td>
</tr>
<tr>
<th>La Requête Problématique</th>
<td><pre style="width: 650px; border: 1px solid black; overflow: auto;">{{ global['sql_error_query'] }}</pre></td>
</tr>
<tr style="background-color: gray">
<th>Le Message d'Erreur Enigmatique</th>
<td>{{ global['sql_error_message'] }}</td>
</tr>
<tr>
<th>La Trace Complète Pour l'Autopsie</th>
<td><pre style="width: 650px; border: 1px solid black; overflow: auto;">{{ global['exception_trace'] }}</pre></td>
</tr>
</table>
</p>
<table class="table table-striped">
<tr>
<th>Le Fameux Code d'Erreur</th>
<td>{{ global['sql_error_code'] }}</td>
</tr>
<tr>
<th>La Requête Problématique</th>
<td><pre style="overflow: auto;">{{ global['sql_error_query'] }}</pre></td>
</tr>
<tr>
<th>Le Message d'Erreur Enigmatique</th>
<td>{{ global['sql_error_message'] }}</td>
</tr>
<tr>
<th>La Trace Complète Pour l'Autopsie</th>
<td><pre style="overflow: auto;">{{ global['exception_trace'] }}</pre></td>
</tr>
</table>
{% else %}
Si vous voulez (et pouvez), vous pouvez activer le mode debug dans le fichier de configuration pour voir ce qui n'a pas marché.
{% endif %}
</div>
</div>
{% endblock %}
This diff is collapsed.
{% 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">
<i class="glyphicon glyphicon-user"></i>
Retour à la fiche adhérent
</span>
<span class="btn btn-primary" id="back_button">
<i class="glyphicon glyphicon-user"></i>
Retour à la fiche adhérent
</span>
<span style="font-size: 150%; font-weight: bold">&nbsp;{{ member.lastname }} {{ member.firstname }} - Emprunts&nbsp;</span>
{% if member.valid_subscription %}
<span class="btn btn-success btn-md" style="float: right" id="new_button">
<i class="glyphicon glyphicon-plus"></i>
<span>Nouvel emprunt...</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>Nouvel emprunt...</span>
</button>
{% else %}
<span class="btn btn-danger btn-md" style="float: right">
<i class="glyphicon glyphicon-warning-sign"></i>
<span>Impossible de faire un nouvel emprunt.</span>
</span>
<span class="btn btn-danger btn-md" style="float: right">
<i class="glyphicon glyphicon-warning-sign"></i>
<span>Impossible de faire un nouvel emprunt.</span>
</span>
{% endif %}
</div>
<div class="panel-body">
<table id="loans_list" class="col-sm-12" width="100%">
<thead>
<tr>
<th>Nom</th>
<th>Date emprunt</th>
<th>Date retour</th>
<th>Rendu</th>
<th>Actions</th>
</tr>
</thead>
<table id="object_list" class="col-sm-12" width="100%">
<thead>
<tr>
<th>Nom</th>
<th>Date emprunt</th>
<th>Date retour</th>
<th>Rendu</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for key, val in member.loans %}
<tr>
<tr>
<td>{{ val.game_name }}
{% if val.is_late %} <span class="label label-warning">En retard</span> {% endif %}
</td>
<td>{{ val.start_date }}</td>
<td>{{ val.end_date }}</td>
</td>
<td>{{ val.start_date | date("d/m/Y") }}</td>
<td>{{ val.end_date | date("d/m/Y") }}</td>
<td><input type="checkbox" id="is_back_{{ val.id }}" name="is_back_{{ val.id }}" class="form-control is_back_cbx"
data-switch-with-ajax {{ val.is_back ? ' checked ' }}></td>
<td>
<a href="index.php?o=loans&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>
<a onClick="if(confirm('Êtes vous sur ?')) { $('a').val('delete_loan'); $('#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>
</a>
</td>
<td>
<button type="button" class="btn btn-success btn-sm"
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_loan'); $('#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>
</a>
</td>
{% else %}
<tr>
<th colspan="5">
<div class="alert alert-warning" role="alert">Aucun emprunt</div>
</th>
</tr>
<tr>
<th colspan="5">
<div class="alert alert-warning" role="alert">Aucun emprunt</div>
</th>
</tr>
{% endfor %}
</tbody>
</table>
......@@ -64,41 +66,55 @@
<!-- 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 () {
$('#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.
$('#back_button').click(function(){
window.location.href='index.php?o=members&a=edit&i={{ member.id }}';
});
$('#new_button').click(function(){
$('#a').val('new');
$('#o').val('loans');
defaultform.submit();
});
$('.is_back_cbx').bootstrapSwitch({
onText: "Oui",
offText: "Non",
}).on('switchChange.bootstrapSwitch', function(event, state) {
$.ajax({
url: 'api.php?o=loans&a=switch_state&i=' + this.name.substr(8)
+ "&state=" + (state ? 1 : 0), // post on the API
type: 'POST',
xhr: function() { // Custom XMLHttpRequest
var myXhr = $.ajaxSettings.xhr();
return myXhr;
},
success: function(){
alert('Le jeu est noté comme restitué aujourd\'hui.');
},
error: function(){
alert('Une erreur a eu lieu lors de la restitution de ce jeu.');
},
cache: false,
contentType: false,
processData: false
});
});
});
$("#editModal").on("show.bs.modal", function(e) {
var button = $(e.relatedTarget);
if(button.data('id') == 0) {
$(this).find(".modal-content").load("index.php?o=" + $('#a').val() + "&a=new&i={{ member.id }}");
} else {
$(this).find(".modal-content").load("index.php?o=" + $('#a').val() + "&a=edit&i=" + button.data('id'));
}
}).on("hidden.bs.modal", function(e) {
$(this).find(".modal-content").empty();
});
// the switch code to give a game back
$('.is_back_cbx').bootstrapSwitch({
onText: "Oui",
offText: "Non",
}).on('switchChange.bootstrapSwitch', function(event, state) {
$.ajax({
url: 'api.php?o=loans&a=switch_state&i=' + this.name.substr(8)
+ "&state=" + (state ? 1 : 0), // post on the API
type: 'POST',
xhr: function() { // Custom XMLHttpRequest
var myXhr = $.ajaxSettings.xhr();
return myXhr;
},
success: function(){
alert('Le jeu est noté comme restitué aujourd\'hui.');
},
error: function(){
alert('Une erreur a eu lieu lors de la restitution de ce jeu.');
},
cache: false,
contentType: false,
processData: false
});
});
});
</script>
{% endblock %}
......@@ -3,65 +3,63 @@
{% block content %}
<div class="panel panel-default">
<div class="panel-heading">
<span class="btn btn-primary" id="back_button">
<i class="glyphicon glyphicon-user"></i>
Retour à la fiche adhérent
</span>
<span class="btn btn-primary" id="back_button">
<i class="glyphicon glyphicon-user"></i>
Retour à la fiche adhérent
</span>
<span style="font-size: 150%; font-weight: bold">&nbsp;{{ member.lastname }} {{ member.firstname }} - Adhésions&nbsp;</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 adhésion...</span>
</button>
<i class="glyphicon glyphicon-plus"></i>
<span>Nouvelle adhésion...</span>
</button>
</div>
<div class="panel-body">
<table id="subscriptions_list" class="col-sm-12" width="100%">
<thead>
<tr>
<th>Début</th>
<th>Fin</th>
<th>Type</th>
<th>Paiement</th>
<th>Crédit</th>
<th>Prix</th>
<th>Notes</th>
<th>Actions</th>
</tr>
</thead>
<table id="object_list" class="col-sm-12" width="100%">
<thead>
<tr>
<th>Début</th>
<th>Fin</th>
<th>Type</th>
<th>Paiement</th>
<th>Crédit</th>
<th>Prix</th>
<th>Notes</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for key, val in member.subscriptions %}
<tr>
<td>{{ val.start_date }}</td>
<td>{{ val.end_date }}</td>
<td>{{ val.membership_type_name }}</td>
<td>{{ val.payment_method_name }}</td>
<td>{{ val.credit ? "Oui" : "Non" }}</td>
<td>{{ val.price }}</td>
<td>{{ val.comments }}</td>
<td>
<tr>
<td>{{ val.start_date | date("d/m/Y") }}</td>
<td>{{ val.end_date | date("d/m/Y") }}</td>
<td>{{ val.membership_type_name }}</td>
<td>{{ val.payment_method_name }}</td>
<td>{{ val.credit ? "Oui" : "Non" }}</td>
<td>{{ val.price }}</td>
<td>{{ val.comments }}</td>
<td>
<button type="button" class="btn btn-success btn-sm"
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>
</a>
</td>
<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>
</a>
</td>
{% else %}
<tr>
<th colspan="8">
<div class="alert alert-warning" role="alert">Aucune adhésion</div>
</th>
</tr>
<tr>
<th colspan="8">
<div class="alert alert-warning" role="alert">Aucune adhésion</div>
</th>
</tr>
{% endfor %}
</tbody>
</table>
<!-- end of panel -->
</div>
</div>
......@@ -76,29 +74,20 @@
<script>
$(document).ready(function () {
$('#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.
$('#back_button').click(function(){
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 }}");
$(this).find(".modal-content").load("index.php?o=" + $('#a').val() + "&a=new&i={{ member.id }}");
} else {
$(this).find(".modal-content").load("index.php?o=subscriptions&a=edit&i=" + button.data('id'));
$(this).find(".modal-content").load("index.php?o=" + $('#a').val() + "&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 %}
......@@ -22,10 +22,6 @@
</div>
</div>
<!-- end of panel -->
</div>
</div>
<script>
// buttons events
$('#save_button').click(function(){
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment