par
zepretender » 30 juil. 2006, 10:22
l s'agit donc d'une base de données historique des rapports avec des organisations (pour mon boulot)
Voici le formulaire :
<?php
/* FCK EDITOR */
include("../../administration/FCKeditor/fckeditor.php") ;
/* Récupération des données POST */
import_request_variables("GP", "var_");
$query1 = "SELECT orgaId, orgaDate,orgaLib FROM orga WHERE orgaId='".$var_id."'";
$query2 = "SELECT * FROM mcTypes";
$query3 = "SELECT * FROM mainCourante WHERE mcId = '".$var_mcId."'";
$query4 = "SELECT * FROM mcFichiers WHERE mcId = '".$var_mcId."' ORDER BY mcDate DESC";
// CONNEXION A LA BASE
connectBDD("base");
// EXECUTION DES REQUETES
$req1= queryBDD($query1);
$req2= queryBDD($query2);
$req3= queryBDD($query3);
$req4= queryBDD($query4);
// FERMETURE DE LA CONNEXON
mysql_close();
// DONNES - c pour organitions et m pour main courante
$c = mysql_fetch_assoc($req1);
$m = mysql_fetch_assoc($req3);
// Transformation de la date
$date = substr ($m[mcDate], 8, 2)."/".substr ($m[mcDate], 5, 2)."/".substr ($m[mcDate], 0, 4);
?>
<h2>Modifier un élément</h2>
<form id="form1" name="form1" method="post" action="mcModif.php">
<table width="100%" border="1" cellspacing="0" cellpadding="5">
<tr>
<td><strong>Nom</strong></td>
<td><input name="nom" type="text" id="nom" value="<?php echo $m[mcLogin]; ?>" maxlength="50" /></td>
</tr>
<tr>
<td><strong>Titre</strong></td>
<td><input name="titre" type="text" id="titre" value="<?php echo $m[mcTitre]; ?>" /></td>
</tr>
<tr>
<td><strong>Catégorie</strong></td>
<td><label>
<select name="mcType" id="mcType">
<option value="0">Aucune</option>
<?php
WHILE ($t=mysql_fetch_assoc($req2)){
echo "<option value=\"".$t[mcTypeId]."\"";
if ($t[mcTypeId] == $m[mcType]){
echo " checked=\"checked\"";
}
echo ">".$t[mcTypeLib]."</option>";
}
?>
</select>
</label></td>
</tr>
<tr>
<td><strong>Date</strong></td>
<td><input name="date" type="text" id="date" value="<?php echo $date; ?>" size="10" maxlength="10" /></td>
</tr>
<tr>
<td width="30%"><strong>Commentaire</strong></td>
<td>
<?php
$oFCKeditor = new FCKeditor('texte') ;
$oFCKeditor->Config['CustomConfigurationsPath'] = '/administration/fckconfig.js';
$oFCKeditor->BasePath = '/administration/FCKeditor2/';
$oFCKeditor->ToolbarSet = 'Prot';
$oFCKeditor->Width = 500 ;
$oFCKeditor->Height = 250 ;
$oFCKeditor->Value = //write to db
$content = unhtmlentities ($m[mcTexte]);
$oFCKeditor->Create() ;
?> </td>
</tr>
</table>
<p align="center">
<label>
<input name="mcId" type="hidden" id="mcId" value="<?php echo $_GET[mcId]; ?>" />
<input name="orgaId" type="hidden" id="orgaId" value="<?php echo $_GET[id]; ?>" />
<input type="submit" name="Submit" value="Modifier" />
</label>
<a href="#ajout"><img src="../../images/icones/mail_compose.gif" width="16" height="16" border="0" /></a></p>
</form>
J'ouvre une connexion à la base de données et exécute trois requetes :
req1 : récupération des infos sur l'organisation choisie (variable transmise en get)
req2 : récupération des catégories d'historique possible (pour le formulaire)
req3 : récupération de l'élément historique à modifier
J'affiche donc l'élément de l'historique séléctionné page précédente pour qu'il soit modifié en fonction de id (id de l'orga) et mcId (id de l'élément historique)
je transfère le tout ici :
<?php
include("paramsSecu.inc.php");
/* Récupération des données POST */
import_request_variables("P", "var_");
/* Tests */
if (empty ($var_nom) OR empty($var_titre) OR empty ($var_texte) OR empty ($var_date)){
echo "Le titre, le texte ou la date sont des éléments obligatoires $var_nom $var_titre $var_texte $var_date";
exit;
} else {
/* Formatage des données */
$titre = texteToTexte($var_titre);
$mcLogin = texteToTexte($var_nom);
$mcDate = makeTime(substr ("$var_date", 0, 2),substr ("$var_date", 3, 2),substr ("$var_date", -4, 4),23,59,59);
//read from db
$texte = htmlspecialchars ($var_texte);
/* Connexion à la base de données */
connectBDD("base");
/* Ajout dans la base */
queryBDD("UPDATE mainCourante SET mcDate='".$date."', mcDateModif='".date("Y-m-d H:i:s")."', mcTitre='" .$titre .
"', mcType='" .$var_mcType ."', mcLogin='".$mcLogin."', mcTexte='" .$texte ."' WHERE mcId = '".$var_mcId."'");
// Modification de l'historique sur la première page et autres
include ($siteRoot."ressources/php/makeHistory.inc.php");
mysql_close();
header("Location: mcModif.php?id=$var_orgaId&mcId=$var_mcId");
}
?>
Note : connectBDD() et queryBDD sont deux fonctions affichant les erreurs précises en cas d'échec.
D'avance merci !
Note d'importance
Le header final renvoie sur la page du formulaire. Etrangement, si celui ci renvoie vers une autre page, tout va bien...
l s'agit donc d'une base de données historique des rapports avec des organisations (pour mon boulot)
Voici le formulaire :
[php]<?php
/* FCK EDITOR */
include("../../administration/FCKeditor/fckeditor.php") ;
/* Récupération des données POST */
import_request_variables("GP", "var_");
$query1 = "SELECT orgaId, orgaDate,orgaLib FROM orga WHERE orgaId='".$var_id."'";
$query2 = "SELECT * FROM mcTypes";
$query3 = "SELECT * FROM mainCourante WHERE mcId = '".$var_mcId."'";
$query4 = "SELECT * FROM mcFichiers WHERE mcId = '".$var_mcId."' ORDER BY mcDate DESC";
// CONNEXION A LA BASE
connectBDD("base");
// EXECUTION DES REQUETES
$req1= queryBDD($query1);
$req2= queryBDD($query2);
$req3= queryBDD($query3);
$req4= queryBDD($query4);
// FERMETURE DE LA CONNEXON
mysql_close();
// DONNES - c pour organitions et m pour main courante
$c = mysql_fetch_assoc($req1);
$m = mysql_fetch_assoc($req3);
// Transformation de la date
$date = substr ($m[mcDate], 8, 2)."/".substr ($m[mcDate], 5, 2)."/".substr ($m[mcDate], 0, 4);
?>
<h2>Modifier un élément</h2>
<form id="form1" name="form1" method="post" action="mcModif.php">
<table width="100%" border="1" cellspacing="0" cellpadding="5">
<tr>
<td><strong>Nom</strong></td>
<td><input name="nom" type="text" id="nom" value="<?php echo $m[mcLogin]; ?>" maxlength="50" /></td>
</tr>
<tr>
<td><strong>Titre</strong></td>
<td><input name="titre" type="text" id="titre" value="<?php echo $m[mcTitre]; ?>" /></td>
</tr>
<tr>
<td><strong>Catégorie</strong></td>
<td><label>
<select name="mcType" id="mcType">
<option value="0">Aucune</option>
<?php
WHILE ($t=mysql_fetch_assoc($req2)){
echo "<option value=\"".$t[mcTypeId]."\"";
if ($t[mcTypeId] == $m[mcType]){
echo " checked=\"checked\"";
}
echo ">".$t[mcTypeLib]."</option>";
}
?>
</select>
</label></td>
</tr>
<tr>
<td><strong>Date</strong></td>
<td><input name="date" type="text" id="date" value="<?php echo $date; ?>" size="10" maxlength="10" /></td>
</tr>
<tr>
<td width="30%"><strong>Commentaire</strong></td>
<td>
<?php
$oFCKeditor = new FCKeditor('texte') ;
$oFCKeditor->Config['CustomConfigurationsPath'] = '/administration/fckconfig.js';
$oFCKeditor->BasePath = '/administration/FCKeditor2/';
$oFCKeditor->ToolbarSet = 'Prot';
$oFCKeditor->Width = 500 ;
$oFCKeditor->Height = 250 ;
$oFCKeditor->Value = //write to db
$content = unhtmlentities ($m[mcTexte]);
$oFCKeditor->Create() ;
?> </td>
</tr>
</table>
<p align="center">
<label>
<input name="mcId" type="hidden" id="mcId" value="<?php echo $_GET[mcId]; ?>" />
<input name="orgaId" type="hidden" id="orgaId" value="<?php echo $_GET[id]; ?>" />
<input type="submit" name="Submit" value="Modifier" />
</label>
<a href="#ajout"><img src="../../images/icones/mail_compose.gif" width="16" height="16" border="0" /></a></p>
</form>
[/php]
J'ouvre une connexion à la base de données et exécute trois requetes :
req1 : récupération des infos sur l'organisation choisie (variable transmise en get)
req2 : récupération des catégories d'historique possible (pour le formulaire)
req3 : récupération de l'élément historique à modifier
J'affiche donc l'élément de l'historique séléctionné page précédente pour qu'il soit modifié en fonction de id (id de l'orga) et mcId (id de l'élément historique)
je transfère le tout ici :
[php]
<?php
include("paramsSecu.inc.php");
/* Récupération des données POST */
import_request_variables("P", "var_");
/* Tests */
if (empty ($var_nom) OR empty($var_titre) OR empty ($var_texte) OR empty ($var_date)){
echo "Le titre, le texte ou la date sont des éléments obligatoires $var_nom $var_titre $var_texte $var_date";
exit;
} else {
/* Formatage des données */
$titre = texteToTexte($var_titre);
$mcLogin = texteToTexte($var_nom);
$mcDate = makeTime(substr ("$var_date", 0, 2),substr ("$var_date", 3, 2),substr ("$var_date", -4, 4),23,59,59);
//read from db
$texte = htmlspecialchars ($var_texte);
/* Connexion à la base de données */
connectBDD("base");
/* Ajout dans la base */
queryBDD("UPDATE mainCourante SET mcDate='".$date."', mcDateModif='".date("Y-m-d H:i:s")."', mcTitre='" .$titre .
"', mcType='" .$var_mcType ."', mcLogin='".$mcLogin."', mcTexte='" .$texte ."' WHERE mcId = '".$var_mcId."'");
// Modification de l'historique sur la première page et autres
include ($siteRoot."ressources/php/makeHistory.inc.php");
mysql_close();
header("Location: mcModif.php?id=$var_orgaId&mcId=$var_mcId");
}
?>
[/php]
Note : connectBDD() et queryBDD sont deux fonctions affichant les erreurs précises en cas d'échec.
D'avance merci !
[b]Note d'importance[/b]
Le header final renvoie sur la page du formulaire. Etrangement, si celui ci renvoie vers une autre page, tout va bien...