|
Invité de passage
Inscription : octobre 2006 Messages : 22 Détails du profil  Informations forums : Inscription : octobre 2006 Messages : 22 Points : 2 Points : 2
|
Fopen via un Formulaire.
Bonjour,
Je viens vous demander conseils et aides sur un problème que je cherche à corriger depuis quelques jours, mais sans sucés.
Description du problème :
- J'ai un formulaire permettant la gestion d'une partie de ma BDD. Le dialogue et l'implantation dans la BDD se réalise sans soucis.
- Lors de la validation j'ai certaines information que j'écris via un Fopen dans un fichier texte. Ces valeurs sont ensuite afficher dans un textarea en temps réel.
- La gestion des transfert entre les deux fonctionnent.
=> Le problème : Lorsque j'arrive sur la page en question mon textarea se remplis alors que je ne souhaite le remplir uniquement lors de la validation du formulaire. Même soucis si j'actualise la page.
Se problème est récurant car j'ai voulu mettre des alertes pour les zone non remplis et même constat lors du load ou du refresh.
Si quelqu'un à une idée ou une correction.
Je reste dispo pour répondre aux questions
-> Code:
"SS page."
Code :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286
| <?php
$CTRL = 0;
$Type = "Modifier.txt";
$Destination = "0";
$Designation = "0";
//Récupération des informations du formulaire
If (isset($_POST['Catégorie']))
{
$Categorie_Form = $_POST['Catégorie'];
$CTRL = $CTRL + 1;
}
If (isset($_POST['Numero']))
{
$Nom_Form = $_POST['Numero'];
$CTRL = $CTRL + 1;
}
If (isset($_POST['Prix']))
{
$Prix_Form = $_POST['Prix'];
$CTRL = $CTRL + 1;
}
If (isset($_POST['Commentaire']))
{
$Commentaire_Form = $_POST['Commentaire'];
$CTRL = $CTRL + 1;
}
If (isset($_POST['Reference']))
{
$Reference_Form = $_POST['Reference'];
$CTRL = $CTRL + 1;
}
If (isset($_POST['Collection']))
{
$Collection_Form = $_POST['Collection'];
$CTRL = $CTRL + 1;
}
If (isset($_POST['Destination']))
{
$Destination_Form = $_POST['Destination'];
}
If (isset($_POST['Designation']))
{
$Designation_Form = $_POST['Designation'];
}
// Connection à la base .
Include("Connect.php");
print("<center>");
include("Module_search.php");
print("</center>");
If ($CTRL == 6){
// Comparaison et implantation.
Include("Compar_implan.php");
}
//$ID=1;
//récupération des informations dans la BDD
$sql = "SELECT Id, Nom, Collection, Reference, Details, Prix, Vendu, Date_modification, Date_vente FROM Photo WHERE ".$Designation." ='".$Destination."' ";
$req = mysql_query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());
$data = mysql_fetch_array($req);
mysql_free_result ($req);
$Id = $data['Id'];
$Nom = $data['Nom'];
$Collection = $data['Collection'];
$Prix= $data['Prix'];
$Details= $data['Details'];
$Details=str_replace("\r\n", "\n", $Details);
$Vendu= $data['Vendu'];
$Reference= $data['Reference'];
$Date_modification=$data['Date_modification'];
If ($Date_modification==""){$Date_modification="Aucunes modifications!";}
$Date_vente =$data['Date_vente'];
If ($Date_vente==""){$Date_vente="Non vendu ";}
// Création de référence.
$Date = Date("d/m/Y");
$Dateref = Date("dmY");
If (strlen($Id)<2)
{
$ID = "0".$Id;
}
$Categorie = substr($Reference,0, 4);
$Date_cate_Bdd = substr($Reference,4, 6);
Switch($Categorie)
{
Case "Crac":
$Check = "checked";
$Check1 = "";
Break;
Case "Bisc":
$Check1 = "checked";
$Check = "";
Break;
}
// Définition de la taille de l'image
list($width, $height, $type) = getimagesize("../Photos/$Nom");
$Width_Aff = 650;
$Height_Aff = 600;
$Width = (Floor(($width/10)/(Round(($width/$Width_Aff),2)))*3)+($width/10);
$Height = (Floor(($height/10)/(Round(($height/$Height_Aff),2)))*3)+($height/10);
$type = str_replace('.','',strstr($Nom, '.'));
print("<form action=\"Form.php?add=$VAR\" method=\"POST\" >");
If ($Date_cate_Bdd<>$Dateref)
{
$Dateref = $Date_cate_Bdd;
}
If (isset($_POST['Catégorie']))
{
$Reference = "$Categorie"."$Dateref"."_$ID";
}
//Affichage des informations de la base
print("<div id=\"Centrage\">
<table border=1 >
<tr><td><i>Matricule Réseau : </i></td><td width=50 align=center>$Id</td><td width=50><i>Date : </i></td><td align=center>$Date</td>
<td ><center><i>Visualisation :</i></center></td>
</tr>
<tr><td colspan = 2><i>Catégorie :</i> </td><td colspan = 2>
<input type=\"checkbox\" name=\"Catégorie\" $Check value=\"Crac\"/>Cracotine
<input type=\"checkbox\" name=\"Catégorie\" $Check1 value=\"Bisc\"/>Biscotine </td>
<td rowspan=9 bgcolor=white width = 180><center>
<Table Border =\"0\" id=\"Tab\" >
<tr><td Class=\"Tab_back\">
<a href=\"javascript:visibilite('1');\" ><img src=\"../Photos/$Nom\" border=\"0\" align=\"center\" id=\"Photo_Dim_minia\"></a>
<div id=\"zone\"><div id=\"1\" style=\"display:none\"><div class= \"SuperContener\">
<img id = \"Photo\" onclick= \"visibilite('1')\" src=\"../Photos/$Nom\" width=$Width height=$Height >
<div id=\"Info\">
<table border=\"0\" id=\"Police1\">
<tr >
<td >Collection</td>
<td >:</td>
<td > $Collection</td><td width=5> </td>
<td >Référence</td>
<td >:</td>
<td > $Reference </td>
<td width=5> </td><td >Prix</td>
<td >:</td>
<td > $Prix </td>
<td ><center>");
// Controle de l'état du produit Vendu / Pas vendu
// Article Vendu
If ($Vendu == 1)
{
Print("<img id=\"Dispo\" src=\"../Pictures/Voy_Rouge.gif\" width=25 height=25 title=\"Article indisponible\" >");
}
// Article Non Vendu
Else
{
Print("<img id=\"Dispo\" src=\"../Pictures/Voy_Vert.gif\" width=25 height=25 title=\"Article disponible\" >");
}
// Controle des informations détails de l'article.
Print("
</center></td>
</tr>
<tr >
<td rowspan=2 >Détails</td>
<td rowspan=2>:</td>
<td colspan=9 rowspan=2 align=\"Top\" Valign=\"Top\"> $Details</td>
<td><img src=\"../Pictures/panier.gif\" width=70 height=45 ></td>
</table>
</div>
<div id=\"Back\" >
</div><div class=\"Conterner\" ></div></div>
</td></tr>
<tr><td>
<table border =\"0\"id=\"Police2\"><tr><td >Prix </td><td>:</td><td>$Prix</td></tr></table>
</td></tr>
</table></center>
</td></tr>
<tr><td colspan = 2 Title=\"Nom de la photo + extension\"><i>Nom :</i> </td><td colspan = 2><input STYLE=\"Text-ALIGN:right\" type=\"Text\" valign=\"right\"size=\"30\" name=\"Numero\" value=\"$Nom\" ></td></tr>
<tr><td colspan = 2 colspan = 2><i>Collection :</i> </td><td colspan = 2><input STYLE=\"Text-ALIGN:right\" type=\"Text\" size=\"30\" name=\"Collection\" value=\"$Collection\" ></td></tr>
<tr><td colspan = 2 height = 62><i>Commentaire:</i> </td><td colspan = 2><center>");include("Zone.php");print("</center></td></tr>
<tr><td colspan = 2><i>Référence:</i> </td><td colspan = 2><input STYLE=\"Text-ALIGN:right\" type=\"Text\" size=\"30\" name=\"Reference\" value=\"$Reference\" ></td></tr>
<tr><td colspan = 2 ><i>Prix :</i> </td><td colspan = 2><input STYLE=\"Text-ALIGN:right\" type=\"Text\" size=\"30\" name=\"Prix\" value=\"$Prix\" ></td></tr>
<tr><td colspan = 2 ><i>Vendu :</i> </td><td colspan = 2><P STYLE=\"Text-ALIGN:right\">");
If ($Vendu == 1)
{
Print("Article Vendu <img id=\"Dispo\" src=\"../Pictures/Voy_Rouge.gif\" width=15 height=15 title=\"Article indisponible\" >");
}
// Article Non Vendu
Else
{
Print("Article non vendu <img id=\"Dispo\" src=\"../Pictures/Voy_Vert.gif\" width=15 height=15 title=\"Article disponible\" >");
}
Print("</p></td></tr>
<tr><td colspan = 2 >Date de modification :</td><td colspan = 2 STYLE=\"Text-ALIGN:right\" >$Date_modification</td></tr>
<tr><td colspan = 2 >Date de vente : </td><td colspan = 2 STYLE=\"Text-ALIGN:right\">$Date_vente</td> </tr>
<input name=\"Destination\" type=\"hidden\" value=\"$Destination\">
<input name=\"Designation\" type=\"hidden\" value=\"$Designation\">
<div id=\"Button\"><input type=\"submit\" value=\"Valider\"></div>
</form>
</table>
</div>");
// ---------------------------------------------------------------------------------------------------------- //
// Lecture et affichage.
// Memorisation des informations de la base :
$Id_Save = $Id;
$Nom_Save = $Nom;
$Collection_Save = $Collection;
$Prix_Save = $Prix;
$Details_Save = str_replace("\r\n", "\n", $Details);
$Vendu_Save = $Vendu;
$Reference_Save = $Reference;
$Date_modification_Save = $Date_modification;
$Date_vente_Save = $Date_vente;
Print("
<table border=1 id=\"Centrage1\">
<tr><td colspan = 4><center><i>Zone Mémoire</i></center></td></tr>
<tr><td Width = 124 ><i>Matricule Réseau : </i></td><td width=50 align=center>$Id</td><td width=50 ><i>Date : </i></td><td align=center >$Date</td>
</tr>
<tr><td colspan = 2 Width = 180><i>Catégorie :</i> </td><td colspan = 2>
<input type=\"checkbox\" name=\"Catégorie\" disabled=\"disabled\" $Check value=\"Crac\"/>Cracotine
<input type=\"checkbox\" name=\"Catégorie\" disabled=\"disabled\" $Check1 value=\"Bisc\"/>Biscotine </td>
</td></tr>
<tr><td colspan = 2 Width = 180 Title=\"Nom de la photo + extension\"><i>Nom :</i> </td><td colspan = 2><p STYLE=\"Text-ALIGN:right\" valign=\"right\">$Nom_Save </p></td></tr>
<tr><td colspan = 2 Width = 180 colspan = 2><i>Collection :</i> </td><td colspan = 2><p STYLE=\"Text-ALIGN:right\" >$Collection_Save </p></td></tr>
<tr><td colspan = 2 height = 44 Width = 180 ><i>Commentaire:</i> </td><td colspan = 2 width=350 ><p ALIGN=right >$Details_Save</p></td></tr>
<tr><td colspan = 2 Width = 180 ><i>Référence:</i> </td><td colspan = 2><p STYLE=\"Text-ALIGN:right\" >$Reference_Save </p></td></tr>
<tr><td colspan = 2 Width = 180 colspan = 2><i>Prix :</i> </td><td colspan = 2><p STYLE=\"Text-ALIGN:right\">$Prix_Save </p></td></tr>
<tr><td colspan = 2 Width = 180 colspan = 2><i>Vendu :</i> </td><td colspan = 2><P STYLE=\"Text-ALIGN:right\">");
If ($Vendu_Save == 1)
{
Print("Article Vendu <img id=\"Dispo\" src=\"../Pictures/Voy_Rouge.gif\" width=15 height=15 title=\"Article indisponible\" >");
}
// Article Non Vendu
Else
{
Print("Article non vendu <img id=\"Dispo\" src=\"../Pictures/Voy_Vert.gif\" width=15 height=15 title=\"Article disponible\" >");
}
Print("</p></td></tr>
<tr><td Width = 180 colspan = 2 >Date de modification :</td><td colspan = 2 STYLE=\"Text-ALIGN:right\" >$Date_modification_Save </td></tr>
<tr><td Width = 180 colspan = 2 >Date de vente : </td><td colspan = 2 STYLE=\"Text-ALIGN:right\">$Date_vente_Save </td> </tr>
</table>
");
// Génération des historiques .TXT
print("<div id=\"fopen\">");
include("Fopen.php");
print("</div>");
/*
//Controle de la validation du checkbox
If (!isset($_POST['Catégorie']))
{
$Message_Box = ("Vous devez Selectionner la catégorie!!!" );
include("MessageBox.php");
}*/
?> |
page Fopen
Code :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| <?PHP
//$contents = str_replace("<br>","",$contents);
$content = "Data/his/".$Type."";
if(!file_exists($content)){$f = fopen("Data/his/".$Type."","a+"); }
if(file_exists($content))
{
$tab = file($content);
$nb = count($tab);
$Nbcar = strlen($nb);
if ($Nbcar == 1){$Space = " ";}
if ($Nbcar == 2){$Space = " ";}
if ($Nbcar == 3){$Space = "";}
$Date = Date("d-m-Y");
$Text = "L". $nb .$Space."| $Date | $Id | $Reference | $Prix | $Categorie | $Date_vente |";
// Lecture et ecriture dans un fichier à la derniére position.
//$Text = "Le lundi au soleil";
$f = fopen("Data/his/".$Type."","a+");
if(fwrite($f, $Text) === FALSE)
{
Echo " Impossible write dans :$f";
exit;
}
//Echo"Ecriture ok";
fputs($f, "\n");
fclose($f);
//Affichage dans la zone de text.
$contents = file_get_contents("Data/his/".$Type."");
print("<br><br><br><br>");
print("<form><textarea disabled=\"disabled\" cols=\"71\" rows=\"6\" >$contents</textarea></form>");
}
?> |
Page de comparation / Implantation
Code :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
| <?php
$Mod = "";
//récupération des informations dans la BDD
$sql = "SELECT Id, Nom, Collection, Reference, Details, Prix, Vendu, Date_modification, Date_vente FROM Photo WHERE ".$Designation_Form." ='".$Destination_Form."' ";
$req = mysql_query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());
$data = mysql_fetch_array($req);
mysql_free_result ($req);
$Id = $data['Id'];
$Nom_Bdd = $data['Nom'];
$Collection_Bdd = $data['Collection'];
$Prix_Bdd= $data['Prix'];
$Details_Bdd= $data['Details'];
$Details=str_replace("\r\n", "\n", $Details_Bdd);
$Vendu_Bdd= $data['Vendu'];
$Reference_Bdd= $data['Reference'];
$Date_modification=$data['Date_modification'];
// 1. Mise en forme textuelle.
// 2. Comparaison entre les valeurs de la BDD et du formulaire.
// 3. Insertion dans la BDD des modifications.
//-----------------------------------------------------------
// 1. Mise en forme textuelle.
include("Mise_en_forme.php");
// 2. Comparaison entre les valeurs de la BDD et du formulaire.
// Catégorie et Référence.
$NBcar = strlen($Reference_Bdd);
$Categorie_Bdd = substr($Reference_Bdd,0, 4);
$Reste_Cat = substr($Reference_Bdd,4, $NBcar);
If ($Categorie_Bdd <> $Categorie_Form)
{
$Categorie_Bdd = $Categorie_Form;
$Reference_Bdd = $Categorie_Bdd.''.$Reste_Cat;
$Mod = $Mod + 1;
}
// Prix
If ($Prix_Bdd <> $Prix_Form)
{
$Unit = chr(128);
$Prix_Bdd = $Prix_Form.''.$Unit;
$Mod = $Mod + 1;
}
//Nom
If ($Nom_Bdd <> $Nom_Form)
{
$Nom_Bdd = $Nom_Form;
$Mod = $Mod + 1;
}
//Collection
If ($Collection_Bdd <> $Collection_Form)
{
$Collection_Bdd = $Collection_Form;
$Mod = $Mod + 1;
}
// Commentaires
If ($Details_Bdd <> $Commentaire_Form)
{
$Details_Bdd = $Commentaire_Form;
$Details_Bdd = wordwrap($Details_Bdd,41, "<br/>", true);
}
If($Commentaire_Form == "")
{
$Details_Bdd = $Details_Bdd;
$Mod = $Mod + 1;
}
// Controle des modifications pour datatation
If ($Mod <> "")
{
$Date_modification = Date("d/m/Y");
}
// 3. Insertion dans la BDD des modifications.
// Implantation des valeurs.
$query="SELECT Id, Prix FROM Photo WHERE ".$Designation_Form." ='".$Destination_Form."' ";
$result=mysql_query($query);
if(mysql_num_rows($result)<> 1)
{
$Id = $data['Id'];
$Prix = $data['Prix'];
}
$req = "UPDATE photo SET Prix = '$Prix_Bdd', Nom ='$Nom_Bdd', Collection='$Collection_Bdd', Reference='$Reference_Bdd', Date_modification='$Date_modification', Details='$Details_Bdd' WHERE ".$Designation_Form." ='".$Destination_Form."' ";
$resultat = mysql_query($req) or die ('ERREUR '.$req.' '.mysql_error());
//Raz des paramétres formulaires
unset($_POST['Catégorie']);
unset($_POST['Numero']);
unset($_POST['Prix']);
unset($_POST['Commentaire']);
unset($_POST['Reference']);
unset($_POST['Collection']);
unset($_POST['Destination']);
unset($_POST['Designation']);
?> |
|