Commit 91ee9214 authored by Denis S. Valdenaire's avatar Denis S. Valdenaire

lot of work with the game form

parent a3b38ffb
......@@ -23,20 +23,28 @@ function __autoload($class_name) {
include("config/config.php");
global $data;
$data = new data();
$contexts = array("members" => "Adhérents", "games" => "Jeux");
// this is a json-only zone
header("Content-Type: application/json");
$contexts = array("members" => "Adhérents",
"games" => "Jeux",
"esar_categories" => "Catégories ESAR");
if(!array_key_exists("o", $_REQUEST) || !array_key_exists($_REQUEST["o"], $contexts)) {
// FIXME send correct HTTP code
exit();
}
switch($_REQUEST["o"]) {
case "games";
include("games/games.php");
include("controllers/games.php");
break;
case "members";
include("members/members.php");
include("controllers/members.php");
break;
case "esar_categories":
include("controllers/esar_categories.php");
break;
default:
//header("Location: ./accueil/index.php");
?>
......
<?php
class Esar_Category {
public $id, $name, $label;
public function __construct($id = 0) {
if (!$this->id) {
$this->id = $id;
}
}
public static function fetch_all(&$esar_categories, $fields = false) {
$esar_categories = array();
$sql = "SELECT id, name, label
FROM categorie_esar
ORDER BY label";
$GLOBALS["data"]->select($sql, $esar_categories, "Esar_Category");
return sizeof($esar_categories);
}
}
......@@ -18,31 +18,55 @@ class Game {
public static function fetch($id) {
// SQL SELECT jeu prets
$sql = "SELECT jeu.id_jeu, nom, reference, fabricant, categorie, categorie_esar_id,
commentaire, infos_fabricant, inventaire, date_achat, prix, nombre_mini, nombre_maxi,
commentaire, infos_fabricant, inventaire, DATE_FORMAT(date_achat, '%m/%d/%Y') as date_achat,
prix, nombre_mini, nombre_maxi,
age_mini, age_maxi, type, id_pret
FROM jeu
LEFT OUTER JOIN prets ON (jeu.id_jeu = prets.id_jeu AND prets.rendu = 0)
WHERE jeu.id_jeu = ".$id;
$GLOBALS["data"]->select($sql, $game, "Game");
// foreach(get_object_vars($my) as $var => $value) $this->$var = $value;
return $game;
}
public function update() {
$update_sql = "";
foreach(get_object_vars($this) as $var => $value) {
// check if there is a corresponding value in _REQUEST
// and the value has really changed
//echo "check for $var... ";
if(array_key_exists($var, $_REQUEST)) {
if($var == "date_achat") {
$_REQUEST["date_achat"] = date_format(date_create_from_format('d-m-Y', $_REQUEST["date_achat"]),'m/d/Y');
}
if($_REQUEST[$var] != $value) {
$this->$var = $_REQUEST[$var];
if($var == "date_achat") {
$_REQUEST["date_achat"] = date_format(date_create_from_format('m/d/Y', $_REQUEST["date_achat"]),'Y-m-d');
}
$update_sql .= " $var = '".$GLOBALS["data"]->db_escape_string($_REQUEST[$var])."',";
// DEBUG echo "REQ : ".$_REQUEST[$var]." != OBJ : ".$value."<br>";
}
}
}
if($update_sql != "") {
// SQL UPDATE jeu
$sql = " UPDATE jeu SET ".substr($update_sql, 0, -1)."
WHERE id_jeu = ".$this->id_jeu;
return $GLOBALS["data"]->update($sql);
}
}
public function render_json() {
echo json_encode($this);
}
public function fetch_medias() {
$this->medias = array();
// SQL SELECT medias
$sql = " SELECT id, description, media_type_id, file
FROM medias
WHERE id_jeu = ".$this->id_jeu;
$GLOBALS["data"]->select($sql, $this->medias, "Media");
Media::fetch_all($this->medias, $this->id_jeu);
return sizeof($this->medias);
}
public static function fetch_all(&$games, $fields = false) {
public static function fetch_all(&$games) {
$games = array();
$sql = "SELECT jeu.id_jeu, nom,
CONCAT (categorie_esar.label, ' - ', categorie_esar.name) AS label,
......
......@@ -9,6 +9,16 @@ class Media {
$this->id = $id;
}
}
public static function fetch_all(&$medias, $game_id) {
$medias = array();
// SQL SELECT medias
$sql = " SELECT id, description, media_type_id, file
FROM medias
WHERE id_jeu = ".$game_id;
$GLOBALS["data"]->select($sql, $medias, "Media");
return sizeof($medias);
}
}
?>
<?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";
switch($_REQUEST["a"]) {
case "list": // for API
try {
Esar_Category::fetch_all($esar_categories);
echo json_encode($esar_categories);
exit(); // no further rendering needed
} catch(data_exception $e) {
$render = "views/data_exception";
}
break;
}
......@@ -19,17 +19,23 @@ This file is part of phpLudoreve.
// controller
$render = "list";
switch($_REQUEST["a"]) {
case "edit_medias":
case "update":
case "edit":
try {
$game = Game::fetch($data->db_escape_string($_REQUEST["i"]));
if($game->id_jeu != 0) {
$game->fetch_medias();
$render = "games/edit";
if($_REQUEST["a"] == "update") {
$game->update();
$_REQUEST["a"] = "edit";
}
$render = "games/".$_REQUEST["a"];
} else {
$render = "games/not_found"; // TODO
}
} catch(data_exception $e) {
$render = "views/data_exception";
$render = "data_exception";
}
break;
......@@ -39,20 +45,32 @@ switch($_REQUEST["a"]) {
echo json_encode($games);
exit(); // no further rendering needed
} catch(data_exception $e) {
$render = "views/data_exception";
$render = "data_exception";
}
break;
case "delete":
// FIXME : make a screen to confirm the deletion of the game
// and all the things w/it, like : medias, comments, lends...
$render = "games/confirm_delete";
break;
case "confirm_delete":
// FIXME : call the model, delete depedants items
// and the game itself
$render = "games/list";
break;
default:
try {
Game::fetch_all($games);
$render = "games/list";
} catch(data_exception $e) {
$render = "views/data_exception";
$render = "data_exception";
}
break;
}
// view part
include($render.".php");
include("views/".$render.".php");
?>
......@@ -28,7 +28,7 @@ switch($_REQUEST["a"]) {
$render = "members/not_found"; // TODO
}
} catch(data_exception $e) {
$render = "views/data_exception";
$render = "data_exception";
}
break;
......@@ -38,7 +38,7 @@ switch($_REQUEST["a"]) {
echo json_encode($members);
exit(); // no further rendering needed
} catch(data_exception $e) {
$render = "views/data_exception";
$render = "data_exception";
}
break;
......@@ -47,11 +47,11 @@ switch($_REQUEST["a"]) {
Member::fetch_all($members);
$render = "members/list";
} catch(data_exception $e) {
$render = "views/data_exception";
$render = "data_exception";
}
break;
}
// view part
include($render.".php");
include("views/".$render.".php");
?>
/*!
* Datetimepicker for Bootstrap 3
* version : 4.15.35
* https://github.com/Eonasdan/bootstrap-datetimepicker/
*/
.bootstrap-datetimepicker-widget {
list-style: none;
}
.bootstrap-datetimepicker-widget.dropdown-menu {
margin: 2px 0;
padding: 4px;
width: 19em;
}
@media (min-width: 768px) {
.bootstrap-datetimepicker-widget.dropdown-menu.timepicker-sbs {
width: 38em;
}
}
@media (min-width: 992px) {
.bootstrap-datetimepicker-widget.dropdown-menu.timepicker-sbs {
width: 38em;
}
}
@media (min-width: 1200px) {
.bootstrap-datetimepicker-widget.dropdown-menu.timepicker-sbs {
width: 38em;
}
}
.bootstrap-datetimepicker-widget.dropdown-menu:before,
.bootstrap-datetimepicker-widget.dropdown-menu:after {
content: '';
display: inline-block;
position: absolute;
}
.bootstrap-datetimepicker-widget.dropdown-menu.bottom:before {
border-left: 7px solid transparent;
border-right: 7px solid transparent;
border-bottom: 7px solid #cccccc;
border-bottom-color: rgba(0, 0, 0, 0.2);
top: -7px;
left: 7px;
}
.bootstrap-datetimepicker-widget.dropdown-menu.bottom:after {
border-left: 6px solid transparent;
border-right: 6px solid transparent;
border-bottom: 6px solid white;
top: -6px;
left: 8px;
}
.bootstrap-datetimepicker-widget.dropdown-menu.top:before {
border-left: 7px solid transparent;
border-right: 7px solid transparent;
border-top: 7px solid #cccccc;
border-top-color: rgba(0, 0, 0, 0.2);
bottom: -7px;
left: 6px;
}
.bootstrap-datetimepicker-widget.dropdown-menu.top:after {
border-left: 6px solid transparent;
border-right: 6px solid transparent;
border-top: 6px solid white;
bottom: -6px;
left: 7px;
}
.bootstrap-datetimepicker-widget.dropdown-menu.pull-right:before {
left: auto;
right: 6px;
}
.bootstrap-datetimepicker-widget.dropdown-menu.pull-right:after {
left: auto;
right: 7px;
}
.bootstrap-datetimepicker-widget .list-unstyled {
margin: 0;
}
.bootstrap-datetimepicker-widget a[data-action] {
padding: 6px 0;
}
.bootstrap-datetimepicker-widget a[data-action]:active {
box-shadow: none;
}
.bootstrap-datetimepicker-widget .timepicker-hour,
.bootstrap-datetimepicker-widget .timepicker-minute,
.bootstrap-datetimepicker-widget .timepicker-second {
width: 54px;
font-weight: bold;
font-size: 1.2em;
margin: 0;
}
.bootstrap-datetimepicker-widget button[data-action] {
padding: 6px;
}
.bootstrap-datetimepicker-widget .btn[data-action="incrementHours"]::after {
position: absolute;
width: 1px;
height: 1px;
margin: -1px;
padding: 0;
overflow: hidden;
clip: rect(0, 0, 0, 0);
border: 0;
content: "Increment Hours";
}
.bootstrap-datetimepicker-widget .btn[data-action="incrementMinutes"]::after {
position: absolute;
width: 1px;
height: 1px;
margin: -1px;
padding: 0;
overflow: hidden;
clip: rect(0, 0, 0, 0);
border: 0;
content: "Increment Minutes";
}
.bootstrap-datetimepicker-widget .btn[data-action="decrementHours"]::after {
position: absolute;
width: 1px;
height: 1px;
margin: -1px;
padding: 0;
overflow: hidden;
clip: rect(0, 0, 0, 0);
border: 0;
content: "Decrement Hours";
}
.bootstrap-datetimepicker-widget .btn[data-action="decrementMinutes"]::after {
position: absolute;
width: 1px;
height: 1px;
margin: -1px;
padding: 0;
overflow: hidden;
clip: rect(0, 0, 0, 0);
border: 0;
content: "Decrement Minutes";
}
.bootstrap-datetimepicker-widget .btn[data-action="showHours"]::after {
position: absolute;
width: 1px;
height: 1px;
margin: -1px;
padding: 0;
overflow: hidden;
clip: rect(0, 0, 0, 0);
border: 0;
content: "Show Hours";
}
.bootstrap-datetimepicker-widget .btn[data-action="showMinutes"]::after {
position: absolute;
width: 1px;
height: 1px;
margin: -1px;
padding: 0;
overflow: hidden;
clip: rect(0, 0, 0, 0);
border: 0;
content: "Show Minutes";
}
.bootstrap-datetimepicker-widget .btn[data-action="togglePeriod"]::after {
position: absolute;
width: 1px;
height: 1px;
margin: -1px;
padding: 0;
overflow: hidden;
clip: rect(0, 0, 0, 0);
border: 0;
content: "Toggle AM/PM";
}
.bootstrap-datetimepicker-widget .btn[data-action="clear"]::after {
position: absolute;
width: 1px;
height: 1px;
margin: -1px;
padding: 0;
overflow: hidden;
clip: rect(0, 0, 0, 0);
border: 0;
content: "Clear the picker";
}
.bootstrap-datetimepicker-widget .btn[data-action="today"]::after {
position: absolute;
width: 1px;
height: 1px;
margin: -1px;
padding: 0;
overflow: hidden;
clip: rect(0, 0, 0, 0);
border: 0;
content: "Set the date to today";
}
.bootstrap-datetimepicker-widget .picker-switch {
text-align: center;
}
.bootstrap-datetimepicker-widget .picker-switch::after {
position: absolute;
width: 1px;
height: 1px;
margin: -1px;
padding: 0;
overflow: hidden;
clip: rect(0, 0, 0, 0);
border: 0;
content: "Toggle Date and Time Screens";
}
.bootstrap-datetimepicker-widget .picker-switch td {
padding: 0;
margin: 0;
height: auto;
width: auto;
line-height: inherit;
}
.bootstrap-datetimepicker-widget .picker-switch td span {
line-height: 2.5;
height: 2.5em;
width: 100%;
}
.bootstrap-datetimepicker-widget table {
width: 100%;
margin: 0;
}
.bootstrap-datetimepicker-widget table td,
.bootstrap-datetimepicker-widget table th {
text-align: center;
border-radius: 4px;
}
.bootstrap-datetimepicker-widget table th {
height: 20px;
line-height: 20px;
width: 20px;
}
.bootstrap-datetimepicker-widget table th.picker-switch {
width: 145px;
}
.bootstrap-datetimepicker-widget table th.disabled,
.bootstrap-datetimepicker-widget table th.disabled:hover {
background: none;
color: #777777;
cursor: not-allowed;
}
.bootstrap-datetimepicker-widget table th.prev::after {
position: absolute;
width: 1px;
height: 1px;
margin: -1px;
padding: 0;
overflow: hidden;
clip: rect(0, 0, 0, 0);
border: 0;
content: "Previous Month";
}
.bootstrap-datetimepicker-widget table th.next::after {
position: absolute;
width: 1px;
height: 1px;
margin: -1px;
padding: 0;
overflow: hidden;
clip: rect(0, 0, 0, 0);
border: 0;
content: "Next Month";
}
.bootstrap-datetimepicker-widget table thead tr:first-child th {
cursor: pointer;
}
.bootstrap-datetimepicker-widget table thead tr:first-child th:hover {
background: #eeeeee;
}
.bootstrap-datetimepicker-widget table td {
height: 54px;
line-height: 54px;
width: 54px;
}
.bootstrap-datetimepicker-widget table td.cw {
font-size: .8em;
height: 20px;
line-height: 20px;
color: #777777;
}
.bootstrap-datetimepicker-widget table td.day {
height: 20px;
line-height: 20px;
width: 20px;
}
.bootstrap-datetimepicker-widget table td.day:hover,
.bootstrap-datetimepicker-widget table td.hour:hover,
.bootstrap-datetimepicker-widget table td.minute:hover,
.bootstrap-datetimepicker-widget table td.second:hover {
background: #eeeeee;
cursor: pointer;
}
.bootstrap-datetimepicker-widget table td.old,
.bootstrap-datetimepicker-widget table td.new {
color: #777777;
}
.bootstrap-datetimepicker-widget table td.today {
position: relative;
}
.bootstrap-datetimepicker-widget table td.today:before {
content: '';
display: inline-block;
border: solid transparent;
border-width: 0 0 7px 7px;
border-bottom-color: #337ab7;
border-top-color: rgba(0, 0, 0, 0.2);
position: absolute;
bottom: 4px;
right: 4px;
}
.bootstrap-datetimepicker-widget table td.active,
.bootstrap-datetimepicker-widget table td.active:hover {
background-color: #337ab7;
color: #ffffff;
text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25);
}
.bootstrap-datetimepicker-widget table td.active.today:before {
border-bottom-color: #fff;
}
.bootstrap-datetimepicker-widget table td.disabled,
.bootstrap-datetimepicker-widget table td.disabled:hover {
background: none;
color: #777777;
cursor: not-allowed;
}
.bootstrap-datetimepicker-widget table td span {
display: inline-block;
width: 54px;
height: 54px;
line-height: 54px;
margin: 2px 1.5px;
cursor: pointer;
border-radius: 4px;
}
.bootstrap-datetimepicker-widget table td span:hover {
background: #eeeeee;
}
.bootstrap-datetimepicker-widget table td span.active {
background-color: #337ab7;
color: #ffffff;
text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25);
}
.bootstrap-datetimepicker-widget table td span.old {
color: #777777;
}
.bootstrap-datetimepicker-widget table td span.disabled,
.bootstrap-datetimepicker-widget table td span.disabled:hover {
background: none;
color: #777777;
cursor: not-allowed;
}
.bootstrap-datetimepicker-widget.usetwentyfour td.hour {
height: 27px;
line-height: 27px;
}
.bootstrap-datetimepicker-widget.wider {
width: 21em;
}
.bootstrap-datetimepicker-widget .datepicker-decades .decade {
line-height: 1.8em !important;
}
.input-group.date .input-group-addon {
cursor: pointer;
}
.sr-only {
position: absolute;
width: 1px;
height: 1px;
margin: -1px;
padding: 0;
overflow: hidden;
clip: rect(0, 0, 0, 0);
border: 0;
}
......@@ -4,7 +4,7 @@
/* Move down content because we have a fixed navbar that is 50px tall */
body {
padding-top: 50px;
/*padding-top: 50px;*/
background-color : #bbbbff;
}
......@@ -171,14 +171,81 @@ img#logo {
margin: