Commit 1e87c9b1 authored by Denis S. Valdenaire's avatar Denis S. Valdenaire

work on forms

parent 4ca3e0ec
......@@ -50,7 +50,7 @@ class data {
* @param $query the select sql statement to execute
* @param $rset
*/
public function select ($query, &$rset) {
public function select ($query, &$rset, $object = false) {
$conn = "db_handle";
if (! ($this->db_handle && ($result = $this->$conn->query($query)))) {
......@@ -60,17 +60,33 @@ class data {
mysqli_error($this->$conn),
$query);
}
$rset = new rset(
mysqli_field_count($this->$conn),
$result->num_rows
);
$rset->raw_content = $result;
$rset->content[0] = mysqli_fetch_array($rset->raw_content, MYSQLI_ASSOC);
$finfo = $result->fetch_fields();
foreach ($finfo as $val) {
$rset->table[] = $val->name;
}
if($object) {
if(!class_exists($object)) {
throw new data_exception(
0,
"Calling select to object w/ a class <b>$object</b> that doesn't even exists",
"select (\$query, &\$rset, $object)");
}
$rset = array();
if($result->num_rows <= 1) {
$rset = $result->fetch_object($object);
} else {
while ($obj = $result->fetch_object($object)) {
$rset[] = $obj;
}
}
} else {
$rset = new rset(
mysqli_field_count($this->$conn),
$result->num_rows
);
$rset->raw_content = $result;
$rset->content[0] = mysqli_fetch_array($rset->raw_content, MYSQLI_ASSOC);
$finfo = $result->fetch_fields();
foreach ($finfo as $val) {
$rset->table[] = $val->name;
}
}
return true;
}
......
<?php
class Game {
public $id_jeu;
public $nom, $reference, $fabricant, $categorie, $categorie_esar_id;
public $commentaire, $infos_fabricant, $inventaire, $date_achat, $prix;
public $nombre_mini, $nombre_maxi, $age_mini, $age_maxi, $type;
public function __construct($id = 0)
{
if (!$this->id_jeu) {
$this->id_jeu = $id;
}
}
}
?>
<?php
class Media {
public $id, $description, $media_type_id, $file;
public function __construct($id = 0)
{
if (!$this->id) {
$this->id = $id;
}
}
}
?>
......@@ -165,37 +165,3 @@ img#logo {
.main .page-header {
margin-top: 0;
}
/* calendar stuff */
#calendar table {
border: 1px solid #fff;
padding: 0;
margin: 0px;
font-size: 80%;
z-index: 0;
}
#calendar th {
background: #565;
color: #fff;
margin: 0px;
padding: 1px 1px;
font-size: 85%
}
#calendar td {
background: #eee;
color: #000;
padding: 1px;
margin: 0;
height: 8px;
text-align: center;
vertical-align: top;
border: 1px solid #fff;
font-size: 75%
}
#calendar td.current {
background: #CCC;
border: red 1px solid;
}
......@@ -15,12 +15,9 @@ This file is part of phpLudoreve.
You should have received a copy of the GNU General Public License
along with phpLudoreve. If not, see <http://www.gnu.org/licenses/>.
*/
include "entt.php";
?>
<script src="../js/jquery-1.11.3.min.js"></script>
<SCRIPT LANGUAGE="JavaScript">
<script>
/* FIXME view form validation later
function validate_and_submit ()
{
if(document.forms["saisie"].nom.value == 0)
......@@ -31,81 +28,66 @@ function validate_and_submit ()
document.forms["saisie"].submit();
return true;
}
</SCRIPT>
</script>
<?php
echo "<center>";
if (isset($_GET['id_jeu'])) {
$jeu = get_jeu($_GET['id_jeu']);
echo "<h3>JEU n°".$_GET['id_jeu'];
if (est_prete($_GET['id_jeu'])) {
echo "(INDISPONIBLE)</h3>";
} else {
echo "(DISPONIBLE)</h3>";
}
echo "<a href='../pret/recherche.php?jeu=".$jeu['nom']."'>
Historique des prêts</a>";
}
else
#Création à vide
{
$jeu = array('nom'=>'','reference'=>'','fabricant'=>'','infos_fabricant'=>'','categorie'=>'',
'categorie_esar_id' => 0,
'prix'=>'','date_achat'=>date("Y-m-d"),'inventaire'=>'','commentaire'=>'');
echo "<h3>NOUVEAU JEU</h3>";
}
// since we are in the edit form, we have an existing $game
?>
<center>
<h3>JEU n°<?=$game->id_jeu?>
<?php if($game->id_pret) { ?>
(INDISPONIBLE) FIXME : lien vers pret en cours
<?php } else { ?>
(DISPONIBLE)
<?php } ?>
</h3>
<a href="index.php?o=prets&id_jeu=<?$game->id_pret?>">Historique des prêts</a>
<div class="form-group">
<label class="control-label col-sm-2" for="nom">Nom</label>
<div class="col-sm-4">
<input type="text" id="nom" class="form-control" value="<?=$game->nom?>"/>
</div>
<label class="control-label col-sm-2" for="reference">Référence</label>
<div class="col-sm-4">
<input type="text" id="reference" class="form-control" value="<?=$game->reference?>"/>
</div>
</div>
<table>
<form name="saisie" action="valide.php" enctype="multipart/form-data" method="post">
<tr>
<td align=right>Nom</td>
<td align=left><input type=text name=nom SIZE=50 MAXLENGTH=50
value="<?php echo $jeu['nom'];?>"></td>
</tr>
<tr>
<td align=right>Référence</td>
<td align=left><input type=text name=reference SIZE=20 MAXLENGTH=20
value="<?php echo $jeu['reference'];?>"></td>
</tr>
<tr>
<td align=right>Fabricant</td>
<td align=left><input type=text name=fabricant SIZE=20 MAXLENGTH=20
value="<?php echo $jeu['fabricant'];?>"></td>
value="<?=$game->fabricant?>"></td>
</tr>
<tr>
<td align=right>Informations du Fabricant</td>
<td align=left><input type=text name=infos_fabricant SIZE=60 MAXLENGTH=60
value="<?php echo $jeu['infos_fabricant'];?>"></td>
value="<?=$game->infos_fabricant?>"></td>
</tr>
<tr>
<td align=right>Catégorie</td>
<td align=left><input type=text name=categorie SIZE=40 MAXLENGTH=40
value="<?php echo $jeu['categorie'];?>">
value="<?=$game->categorie?>">
(ex sy as rè)
</td>
</tr>
<tr>
<td align=right>Catégorie ESAR</td>
<td align="left">
<?php select_categorie_esar($jeu['categorie_esar_id']);?>
<td align="left">FIXME - wait a minute
<?php //select_categorie_esar($game->categorie_esar_id);?>
</td>
</tr>
<tr>
<td align=right>Prix</td>
<td align=left><input type=text name=prix SIZE=3 MAXLENGTH=3
value="<?php echo $jeu['prix'];?>">
value="<?=$game->prix?>">
</td>
</tr>
<tr>
<td align="right">Medias</td>
<td style="background-color: white">
<?php
if(!array_key_exists("id_jeu", $jeu)) {
?>
Il faut enregistrer le jeu avant d'ajouter des médias.
<?php
} else {
if(is_array($jeu['medias'])) {
?><div id="media_list"><?php
// DEBUG echo "<pre>"; print_r($jeu["medias"]); echo "</pre>";
......@@ -175,9 +157,7 @@ function completeHandler (response) {
}
</script>
<?php
}
?>
</td>
</tr>
<tr>
......
......@@ -16,36 +16,40 @@ This file is part of phpLudoreve.
along with phpLudoreve. If not, see <http://www.gnu.org/licenses/>.
*/
// controller part
include("classes/game.php");
include("classes/media.php");
// controller + model part
$render = "list";
switch($_REQUEST["a"]) {
case "edit":
// SQL SELECT jeu
$sql = "SELECT id_jeu, nom, reference, fabricant, categorie, categorie_esar_id,
commentaire, infos_fabricant, inventaire, date_achat, prix, nombre_mini, nombre_maxi,
age_mini, age_maxi, type
FROM jeu WHERE id_jeu = ".mysql_real_escape_string($_REQUEST["i"]);
$data->select($sql, $rset);
if($rset->numrows) {
// get medias associated with it
// SQL SELECT media
$sql = " SELECT id, description, media_type_id, file
FROM medias
WHERE id_jeu = ".mysql_real_escape_string($_REQUEST["i"]);
$data->select($sql, $media_rset);
} else {
$media_rset = "";
try {
// FIXME this should be in the model
// 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,
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 = ".mysql_real_escape_string($_REQUEST["i"]);
$data->select($sql, $game, "Game");
if(sizeof($game)) {
// get medias associated with it
// SQL SELECT medias
$sql = " SELECT id, description, media_type_id, file
FROM medias
WHERE id_jeu = ".mysql_real_escape_string($_REQUEST["i"]);
$data->select($sql, $medias, "Media");
$render = "games/edit";
} else {
$render = "games/not_found"; // TODO
}
} catch(data_exception $e) {
$render = "views/data_exception";
}
break;
}
// view part
switch($_REQUEST["a"]) {
case "edit":
include("games/edit.php");
break;
default: // list
include("games/list.php");
break;
}
include($render.".php");
?>
......@@ -20,8 +20,6 @@ $data->select($sql, $rset);
</thead>
<tbody>
<?php
$ligne=FALSE;
# affichage des résultats de la requête dans le menu déroulant
do { ?>
<tr>
<td>
......
......@@ -74,7 +74,7 @@ if(!array_key_exists("o", $_REQUEST) || !array_key_exists($_REQUEST["o"], $conte
// compute date
include("helpers/date.php");
?>
<form action="index.php" method="post" id="defaultform" name="defaultform">
<form action="index.php" method="post" id="defaultform" name="defaultform" enctype="multipart/form-data">
<div class="container-fluid">
<div class="row">
<div class="col-sm-9 col-md-10 main">
......
<div>
<p style="font-size:120%; text-align: center">Serious Database Error</p>
<p>Some SQL query has failed.</p>
<?php
if($debug) {
?>
<p style="background-color: white;">
<table style="border: 1px solid black;">
<tr style="background-color: gray">
<th>The Famous Error Code</th>
<td><?=$e->sql_error_code?></td>
</tr>
<tr>
<th>The Problematic Query</th>
<td><pre style="width: 650px; border: 1px solid black; overflow: auto;"><?=$e->sql_error_query?></pre></td>
</tr>
<tr style="background-color: gray">
<th>The Enigmatic Error Message</th>
<td><?=$e->sql_error_message?></td>
</tr>
<tr>
<th>The Complete Trace</th>
<td><pre style="width: 650px; border: 1px solid black; overflow: auto;"><?=$e->getTraceAsString()?></pre></td>
</tr>
</table>
</p>
<?php
} else {
echo "If you want (and can) you could enable the 'debug' parameter in the config file to know what failed.";
}
?>
</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