Commit cb4f9e06 authored by Denis S. Valdenaire's avatar Denis S. Valdenaire

fixes #32, fixes #42

parent cd7f97cd
<?php
class Esar_Category {
class Esar_Category extends Record {
public $id, $name, $label;
public $table = "esar_categories";
public function __construct($id = 0) {
if (!$this->id) {
$this->id = $id;
......@@ -18,4 +20,29 @@ class Esar_Category {
$GLOBALS["data"]->select($sql, $esar_categories, "Esar_Category");
return sizeof($esar_categories);
}
public static function fetch($id) {
// SQL SELECT esar_categories
$sql = "SELECT id, name, label
FROM esar_categories
WHERE id = ".$id;
$GLOBALS["data"]->select($sql, $esar_category, "Esar_Category");
return $esar_category;
}
public static function delete($id) {
// SQL SELECT esar_categories
$sql = " SELECT id
FROM esar_categories
WHERE id = $id ";
$GLOBALS["data"]->select($sql, $rset);
if($rset->numrows) {
// SQL DELETE esar_categories
$sql = " DELETE FROM esar_categories
WHERE id = $id ";
$GLOBALS["data"]->delete($sql);
return $rset->value("id");
}
return false;
}
}
<?php
/*
This file is part of phpLudoreve.
// controller
$render = "list";
// format
$format = (preg_match("/api.php/", $_SERVER["REQUEST_URI"])) ? "json" : "html";
phpLudoreve is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
switch($_REQUEST["a"]) {
phpLudoreve is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
case "create":
try {
$esar_category = new Esar_Category(0);
$esar_category->create();
Esar_Category::fetch_all($esar_categories);
$render = "esar_categories/list";
} catch(data_exception $e) {
$render = "data_exception";
}
break;
You should have received a copy of the GNU General Public License
along with phpLudoreve. If not, see <http://www.gnu.org/licenses/>.
*/
case "new":
$esar_category = new Esar_Category(0);
$_REQUEST["i"] = 0;
$render = "esar_categories/edit";
break;
case "delete":
try {
if($_REQUEST["i"] = Esar_Category::delete($_REQUEST["i"])) {
Esar_Category::fetch_all($esar_categories);
$render = "esar_categories/list";
} else {
$render = "unprocessable";
}
} catch(data_exception $e) {
$render = "data_exception";
}
break;
case "update":
try {
$esar_category = Esar_Category::fetch($data->db_escape_string($_REQUEST["i"]));
if($esar_category->id != 0) {
$esar_category->update();
Esar_Category::fetch_all($esar_categories);
$render = "esar_categories/list";
} else {
$render = "esar_categories/not_found"; // TODO
}
} catch(data_exception $e) {
$render = "data_exception";
}
break;
case "edit":
try {
$esar_category = Esar_Category::fetch($data->db_escape_string($_REQUEST["i"]));
if($esar_category->id != 0) {
$render = "esar_categories/edit";
} else {
$render = "esar_categories/not_found"; // TODO
}
} catch(data_exception $e) {
$render = "data_exception";
}
break;
// controller
$render = "list";
switch($_REQUEST["a"]) {
case "list": // for API
try {
Esar_Category::fetch_all($esar_categories);
echo json_encode($esar_categories);
exit(); // no further rendering needed
if($format == "json") {
echo json_encode($esar_categories);
exit(); // no further rendering needed
} else {
$render = "esar_categories/list";
}
} catch(data_exception $e) {
$render = "views/data_exception";
}
break;
}
include("views/".$render.".php");
<?php
/*
This file is part of phpLudoreve.
phpLudoreve is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
phpLudoreve is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with phpLudoreve. If not, see <http://www.gnu.org/licenses/>.
*/
// controller
$render = "list";
// format
......
<div class="panel panel-default">
<div class="panel-heading">
<h4>
<span class="glyphicon glyphicon-list-alt" style="margin-right: 10px" ></span>
<?=($esar_category->id != 0) ? "Catégorie ESAR : ".$esar_category->name : "Nouvelle catégorie ESAR"?>
</h4>
</div>
<div class="panel-body">
<div class="form-group">
<label class="control-label col-sm-2" for="name">Nom</label>
<div class="col-sm-4">
<input type="text" id="name" name="name" class="form-control" value="<?=$esar_category->name?>"/>
</div>
<label class="control-label col-sm-2" for="label">label</label>
<div class="col-sm-4">
<input type="text" id="label" name="label" class="form-control" value="<?=$esar_category->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">
<?php if ($esar_category->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">
<?php } else { ?>
<input type="button" class="btn btn-success" id="save_button" value="Créer">
<?php } ?>
</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>
<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">
Catégories ESAR
</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>
</div>
</div>
<div class="panel-body">
<div class="col-sm-12" align="center">
<table id="list_esar">
<thead>
<tr>
<th>Label</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<?php
while(list($key, $val) = each($esar_categories)) { ?>
<tr>
<td>
<a href="index.php?o=esar_categories&a=edit&i=<?=$val->id?>"><?=$val->label?></a>
</td>
<td>
<?=$val->name?>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
<!-- end of panel -->
</div>
</div>
<script>
$(document).ready(function() {
$('#list_esar').DataTable({"autoWidth": false})
});
/* FIXME : translation of the table
see https://datatables.net/plug-ins/i18n/French
*/
</script>
<div class="col-sm-8" align="center">
<h2>Liste des jeux</h2>
</div>
<div class="col-sm-4" align="center">
<span class="btn btn-success" onClick="$('#a').val('new'); defaultform.submit()">
<div class="panel panel-default">
<div class="panel-heading">
<span style="font-size: 150%;" class="glyphicon glyphicon-knight"></span>
<span style="font-size: 150%; font-weight: bold">
Jeux
</span>
<span class="btn btn-success btn-md" style="float: right" id="new_button">
<i class="glyphicon glyphicon-plus"></i>
<span>Nouveau jeu ...</span>
<span>Nouvel jeu...</span>
</span>
</div>
</div>
<div class="panel-body">
<div class="col-sm-12" align="center">
<table id="list_jeu">
<thead>
......@@ -33,6 +41,10 @@ while(list($key, $val) = each($games)) { ?>
<?php } ?>
</tbody>
</table>
</div>
<!-- end of panel -->
</div>
</div>
<script>
$(document).ready(function() {
......@@ -41,6 +53,10 @@ $(document).ready(function() {
)
/* .removeClass( 'display' )
.addClass('table table-striped table-bordered');*/
$('#new_button').click(function(){
$('#a').val('new');
defaultform.submit();
});
});
/* FIXME : translation of the table
see https://datatables.net/plug-ins/i18n/French
......
<div class="col-sm-8" align="center">
<h2>Liste des adhérents</h2>
</div>
<div class="col-sm-4" align="center">
<span class="btn btn-success" onClick="$('#a').val('new'); defaultform.submit()">
<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">
Adhérents
<span class="btn btn-success btn-md" style="float: right" id="new_button">
<i class="glyphicon glyphicon-plus"></i>
<span>Nouvelle adhésion...</span>
<span>Nouvel adhérent...</span>
</span>
</div>
</div>
<div class="panel-body">
<div class="col-sm-12" align="center">
<table id="list_member">
<thead>
......@@ -33,9 +38,18 @@ while(list($key, $val) = each($members)) { ?>
<?php } ?>
</tbody>
</table>
</div>
<!-- end of panel -->
</div>
</div>
<script>
$(document).ready(function() {$('#list_member').DataTable({"autoWidth": false})});
$(document).ready(function() {
$('#list_member').DataTable({"autoWidth": false})
$('#new_button').click(function(){
$('#a').val('new');
defaultform.submit();
});
});
/* FIXME : translation of the table
see https://datatables.net/plug-ins/i18n/French
*/
......
......@@ -42,8 +42,6 @@
<?php } ?>
</table>
<!-- end of panel -->
</div>
</div>
......
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