Location: PHPKode > projects > PhpMyDVDs > phpmydvds/modifClients.php
<?php

    /***************************************************************************
                                 modifProprietaires.php  -  description
                                -------------------

        copyright          : (C) 2002 by Cédric Rochat
        email                : hide@address.com
    ***************************************************************************/
    /***************************************************************************
    *
    *   This program 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.
    *
    ***************************************************************************/

    require ("util.php");

	if (ControleAcces($password, $Internaute, session_id()))
	{
		require ("config.php");

		if ($ajout!='TRUE' or ($creationClient and $valider!='Annuler'))
		{
			if (!$creationClient) echo "<center><h1>Modifications de clients</h1></center><hr>";
			else echo "<center><h1>Création d'un client</h1></center><hr>";

			if ($submit=='Annuler' or $valider=='Annuler')
			{
				$IDClientSauv=$IDClient;
				unset($IDClient);
			}

			if (($Choice=='true' and $submit!='Annuler' and $valider!='Annuler') or $confirm=='Oui')
			{
				if ($RecordChoice==0)
				{
					if ($submit=='OK' or $confirm=='Oui')
					{
						if ($confirm=='Oui')
						{
							RecordDelete($IDClient, 7);
							echo "<center><b><H2>Client supprimé !!</H2><br><br><a href='index.php?sousPage="; if ($FormulairePrets!='TRUE') echo "modifClients.php"; else echo "prets.php&MenuChoix=4"; echo "&AdminState=1'>Retour</a></b></center>";
						}
						else
						{
							echo "<center><b><font face='Arial, Helvetica, sans-serif' size='3'>Cette action entraînera la suppression de plusieurs références à ce client<br><br>Etes-vous sûr de vouloir continuer ?</font></b></center>";
							echo "
							<form name='ConfirmSuppressionClient' method='POST' action='index.php?sousPage=modifClients.php&AdminState=1'>
								<table border='0' cellspacing='5' cellpadding='5' align='center' width='60%'>
									<tr>
										<td align='center' colspan='2'>
											<input type='submit' value='Oui' name='confirm'>&nbsp;&nbsp;<input type='submit' value='Non' name='confirm'>
											<input type='hidden' value=$IDClient name='IDClient'>
											<input type='hidden' value=$FormulairePrets name='FormulairePrets'>
										</td>
									</tr>
								</table>
							</form>";
						}
					}
				}
				if ($RecordChoice==1)
				{
					if ($ModifEnd==1)
					{
						if ($PrenomClient_new!="" and $NomClient_new!="")
						{
							$ExistenceClient=ChercheClient ($NomClient_new, $PrenomClient_new);
							$RessemblanceClient=ChercheRessemblance(7, "$PrenomClient_new $NomClient_new");
							if ($ajout=='TRUE' and $ExistenceClient->IDClient=="")
							{
								if (mysql_num_rows($RessemblanceClient)==0 or $verif=='TRUE')
								{
									$requete="INSERT INTO $pTable_Prefixe"."Clients (NomClient, PrenomClient, AdresseClient, TelephoneClient, TelephonePortableClient, EmailClient)
						 				VALUES ('$NomClient_new', '$PrenomClient_new', '$AdresseClient_new', '$TelephoneClient_new', '$TelephonePortableClient_new', '$EmailClient_new')";
									$verif='TRUE';
								}
								else
								{
									echo "<center>Il existe une ressemblance entre le nom que vous avez saisi (<b>$PrenomClient_new $NomClient_new</b>), et au moins un nom de client existant !!<br>Vous devriez vérifier que le nom que vous avez entré n'existe pas déjà sous une autre orthographe.<br>Vous n'aurez plus ensuite qu'à confirmer votre saisie, ou à l'annuler.</center>";
									$form=new Formulaire("POST", "index.php?sousPage=modifClients.php&AdminState=1");
									$form->debutTable(HORIZONTAL,1);
									$form->champCache("Choice", "true");
									$form->champCache("RecordChoice", 1);
									$form->champCache("ModifEnd", 1);
									$form->champCache("ajout", $ajout);
									$form->champCache("creationClient", "TRUE");
									$form->champCache("PrenomClient_new", $PrenomClient_new);
									$form->champCache("NomClient_new", $NomClient_new);
									$form->champCache("AdresseClient_new", $AdresseClient_new);
									$form->champCache("TelephoneClient_new", $TelephoneClient_new);
									$form->champCache("TelephonePortableClient_new", $TelephonePortableClient_new);
									$form->champCache("EmailClient_new", $EmailClient_new);
									$form->champCache("verif", "TRUE");
									$form->champCache("FormulairePrets", $FormulairePrets);
									$form->champValider ("Confirmer création", "valider");
									$form->champValider ("Annuler", "valider");
									$form->finTable();
									$form->fin();

									$Record_count=mysql_num_rows($RessemblanceClient);
									switch ($Record_count)
									{
										case 1 :
 											$Record_count_text = "<I>$Record_count </I> enregistrement  a été trouvé";
											break;
										default :
 											$Record_count_text = "<I>$Record_count </I> enregistrements  ont étés trouvés";
									}
									echo "
											<table width='100%' border=0 cellspacing=1 cellpadding=1>
												<tr>
													<td>
													<br>
														<b>$Record_count_text</b>
													</td
												</tr>
											</table>";
									echo "
											<table width='100%' border=0 cellspacing=1 cellpadding=1>
												<tr>
													<td bgcolor='$color_frame' width='10%'><b><font face='Arial, Helvetica, sans-serif' size='2' color='$color_menu'>&nbsp;ID&nbsp;Client</b></font></td>
													<td bgcolor='$color_frame' width='10%'><b><font face='Arial, Helvetica, sans-serif' size='2' color='$color_menu'>&nbsp;Numérotation</b></font></td>
													<td bgcolor='$color_frame' width='10%'><b><font face='Arial, Helvetica, sans-serif' size='2' color='$color_menu'>&nbsp;Prénom</b></font></td>
													<td bgcolor='$color_frame' width='10%'><b><font face='Arial, Helvetica, sans-serif' size='2' color='$color_menu'>&nbsp;Nom</b></font></td>
													<td bgcolor='$color_frame' width='60%'><b><font face='Arial, Helvetica, sans-serif' size='2' color='$color_menu'>&nbsp;E-mail</b></font></td>
												</tr>
												<tr><td colspan=5><hr></td></tr>";

				        			$font_begin="<font color='#FF0A3B' face='Arial, Helvetica, sans-serif' size='2'>";
        							$font_end="</font>";
        							$Client_count=0;
            						while ($rowList = mysql_fetch_array ($RessemblanceClient))
            						{
                    					$href_begin ="";
                    					$href_end ="";
                    					$Client_count++;

                    					echo "		<tr>
                                        					<td width='10%'><font color='#000000' face='Arial, Helvetica, sans-serif' size='2'>$rowList[0] $font_end</td>
                                        					<td width='10%'>$font_begin <B>$Client_count</B> $font_end</td>
                                        					<td width='10%'>$font_begin <a href='index.php?IDClient=$rowList[0]&sousPage=modifClients.php&AdminState=1'>"; $rowList[1]=nbsp($rowList[1]); echo "$rowList[1]</a>$font_end</td>
                                        					<td width='10%'>$font_begin <a href='index.php?IDClient=$rowList[0]&sousPage=modifClients.php&AdminState=1'>"; $rowList[2]=nbsp($rowList[2]); echo "$rowList[2]</a>$font_end</td>
                                        					<td width='60%'>$font_begin <a href=mailto:$rowList[3]>$rowList[3]</a>$font_end</td>";
                        				echo "</tr>";
            						}
									echo "</table>";
            						echo "<hr>";

									$verif='FALSE';
								}
							}
							elseif ($ajout=='TRUE')
							{
								echo "<center><b><H2>Désolé, ce client existe déjà dans la base de données !!</H2><br><br><a href='index.php?sousPage="; if ($FormulairePrets!='TRUE') "modifClients.php"; else echo "prets.php&MenuChoix=4&IDClient=$IDClient"; echo "&AdminState=1&ajout=TRUE'>Retour</a></b></center>";
							}

							if ($ajout=='FALSE')
								$requete="UPDATE $pTable_Prefixe"."Clients SET NomClient='$NomClient_new', PrenomClient='$PrenomClient_new', AdresseClient='$AdresseClient_new', TelephoneClient='$TelephoneClient_new', TelephonePortableClient='$TelephonePortableClient_new', EmailClient='$EmailClient_new'
						 			WHERE IDClient=$IDClient";
						}
						else
						{
							if ($ajout=='TRUE') echo "<center><b><H2>Au moins un des champs importants (prénom ou nom) était vide !!</H2><br><br><a href='index.php?sousPage=modifClients.php&AdminState=1&ajout=TRUE'>Retour</a></b></center>";
							elseif ($ajout=='FALSE') echo "<center><b><H2>Au moins un des champs importants (prénom ou nom) était vide !!</H2><br><br><a href='index.php?sousPage=modifClients.php&AdminState=1&Choice=true&RecordChoice=1&IDClient=$IDClient'>Retour</a></b></center>";
						}

						if (($ajout=='FALSE' and $NomClient_new!="" and $PrenomClient_new!="") or ($ajout=='TRUE' and $NomClient_new!="" and $PrenomClient_new!="" and $ExistenceClient->IDClient==""))
						{
							if (($creationClient and $verif=='TRUE') or $ajout!='TRUE') $requeteClient=ExecRequete ($requete, BASE);
							if ($creationClient and $verif=='TRUE')
							{
								echo "<center><b><H2>Client créé !!</H2><br><br><a href='index.php?sousPage=modifClients.php&AdminState=1&ajout=TRUE"; if ($FormulairePrets=='TRUE') echo "&FormulairePrets=TRUE"; echo "'>Nouveau client</a><br><br><a href='index.php?sousPage="; if ($FormulairePrets!='TRUE') echo "modifClients.php"; else {$IDClient=mysql_insert_id(); echo "prets.php&MenuChoix=4&IDClient=$IDClient";} echo "&AdminState=1'>Retour</a></b></center>";
							}
							elseif (!$creationClient)
							{
								echo "<center><b><H2>Client modifié !!</H2><br><br><a href='index.php?sousPage="; if ($FormulairePrets!='TRUE') echo "modifClients.php"; else echo "prets.php&MenuChoix=4&IDClient=$IDClient"; echo "&AdminState=1'>Retour</a></b></center>";
							}
						}
					}
					else
					{
						if ($FormulairePrets=='TRUE') FormModifs ($IDClient, 71);
						else FormModifs ($IDClient, 7);
					}
				}
			}
			else
			{
				if (isset($IDClient))
				{
					echo "
					<form name='modificationsClients' method='POST' action='index.php?sousPage=modifClients.php&AdminState=1'>
						<table border='0' cellspacing='5' cellpadding='5' align='center'>
							<tr>
								<td>
									<b>
										<i>
											<font face='Arial, Helvetica, sans-serif' size='2'>Que voulez-vous faire ?</font>
										</i>
									</b>
								</td>
								<td>
									<input type='radio' name='RecordChoice' value='1' checked>
										<font face='Arial, Helvetica, sans-serif' size='2'>Modifier ce client</font>
										<br>
										<br>
									<input type='radio' name='RecordChoice' value='0'>
										<font face='Arial, Helvetica, sans-serif' size='2'>Supprimer ce client</font>
										<br>
										<br>
									<input type='hidden' name='Choice' value='true'>
									<input type='hidden' name='IDClient' value=$IDClient>
									<input type='hidden' value=$FormulairePrets name='FormulairePrets'>
								</td>
							</tr>
							<tr>
								<td align='center' colspan='2'>
									<input type='submit' value='OK' name='submit'>&nbsp;&nbsp;<input type='submit' value='Annuler' name='submit'>
								</td>
							</tr>
						</table>
					</form>";
				}
				elseif ($FormulairePrets!='TRUE')
				{
 	       			$connexion = Connexion (NOM, PASSE, BASE,SERVEUR);
					if ($client) $client=urldecode($client);

					$nombre_limite=$NombreEnregistrementsLimiteAdmin;
					if (!$debut)
					{
						$debut=0;
						$DonneesClient=ExecRequete ("SELECT * FROM $pTable_Prefixe"."Clients WHERE NomClient LIKE '%$client%' OR PrenomClient LIKE '%$client%' ORDER BY PrenomClient ASC, NomClient ASC" ,BASE);

						$Record_count=mysql_num_rows($DonneesClient);
					}

					if ($debut >= $nombre_limite)
					{
						$valideprev=1;
						$debutprecedent=$debut-$nombre_limite;
					}
					else $valideprev=0;

					if (($debut+$nombre_limite) > $Record_count) $validenext=0;
					else
					{
						$validenext=1;
						$debutsuivant=$debut+$nombre_limite;
					}

					$DonneesClient=ExecRequete ("SELECT * FROM $pTable_Prefixe"."Clients WHERE NomClient LIKE '%$client%' OR PrenomClient LIKE '%$client%' ORDER BY PrenomClient ASC, NomClient ASC LIMIT $debut, $nombre_limite" ,BASE);

					switch ($Record_count)
					{
						case 0 :
 							$Record_count_text = "Aucun enregistrement n'a été trouvé";
							break;
						case 1 :
 							$Record_count_text = "<I>$Record_count </I> enregistrement  a été trouvé";
							break;
						default :
 							$Record_count_text = "<I>$Record_count </I> enregistrements  ont étés trouvés";
					}

					$pages_tot=$Record_count/$nombre_limite;
					if ($pages_tot > floor($pages_tot)) $pages_tot=floor($pages_tot)+1;
					$page_actuelle=floor($debut/$nombre_limite)+1;

					echo "  <table width='100%' border=0 cellspacing=1 cellpadding=1 align='center'>
									<tr><center><td>";
					$form = new Formulaire ("POST", "index.php?sousPage=modifClients.php&AdminState=1");
					$form->debutTable ("HORIZONTAL");
					$form->champTexte ("", "client", "", 30, 40);
					$form->champValider ("Recherche client", "valider");
					$form->finTable();
					$form->fin();
					echo "</td></center></tr>
					</table>
					<table width='100%' border=0 cellspacing=1 cellpadding=1>
					<tr>
						<td>
							<br>
							<b>$Record_count_text</b>
						</td>
						<td align='right'>
							<table border='0' cellspacing='0' cellpadding='0'>
								<tr>
									<td align='right'><b>"; if ($pages_tot > 1) echo "$page_actuelle/$pages_tot"; echo "</b></td>
									<td align='right'>";
										if ($client and ($valideprev==1 or $validenext==1)) $client=urlencode($client);
										if ($valideprev == 1)
										{
											echo "<a href='index.php?sousPage=modifClients.php&AdminState=1&debut=$debutprecedent&Record_count=$Record_count&client=$client'><img border='0' src='images/prev.gif'></a>";
										}
										else
										{
											if ($pages_tot > 1) echo "<img border='0' src='images/prevdis.gif'>";
										}

										if ($validenext == 1)
										{
											echo "<a href='index.php?sousPage=modifClients.php&AdminState=1&debut=$debutsuivant&Record_count=$Record_count&client=$client'><img border='0' src='images/next.gif'></a>";
										}
										else
										{
											if ($pages_tot > 1) echo "<img border='0' src='images/nextdis.gif'>";
										}
									echo "</td>
								</tr>
							</table>
						</td>
					</tr>
					</table>";
					if ($Record_count!=0)
					{
						echo "
							<table width='100%' border=0 cellspacing=1 cellpadding=1>
								<tr>
									<td bgcolor='$color_frame' width='10%'><b><font face='Arial, Helvetica, sans-serif' size='2' color='$color_menu'>&nbsp;ID&nbsp;Client</b></font></td>
									<td bgcolor='$color_frame' width='10%'><b><font face='Arial, Helvetica, sans-serif' size='2' color='$color_menu'>&nbsp;Numérotation</b></font></td>
									<td bgcolor='$color_frame' width='10%'><b><font face='Arial, Helvetica, sans-serif' size='2' color='$color_menu'>&nbsp;Prénom</b></font></td>
									<td bgcolor='$color_frame' width='10%'><b><font face='Arial, Helvetica, sans-serif' size='2' color='$color_menu'>&nbsp;Nom</b></font></td>
									<td bgcolor='$color_frame' width='60%'><b><font face='Arial, Helvetica, sans-serif' size='2' color='$color_menu'>&nbsp;E-mail</b></font></td>
								</tr>
								<tr><td colspan=5><hr></td></tr>";


				        $font_begin="<font color='#FF0A3B' face='Arial, Helvetica, sans-serif' size='2'>";
        				$font_end="</font>";
        				$Client_count=$debut;
            			while ($rowList = mysql_fetch_array ($DonneesClient))
            			{
                    		$href_begin ="";
                    		$href_end ="";
                    		$Client_count++;

                    		echo "		<tr>
                                        		<td width='10%'><font color='#000000' face='Arial, Helvetica, sans-serif' size='2'>$rowList[0] $font_end</td>
                                        		<td width='10%'>$font_begin <B>$Client_count</B> $font_end</td>
                                        		<td width='10%'>$font_begin <a href='index.php?IDClient=$rowList[0]&sousPage=modifClients.php&AdminState=1'>"; $rowList[2]=nbsp($rowList[2]); echo "$rowList[2]</a>$font_end</td>
                                        		<td width='10%'>$font_begin <a href='index.php?IDClient=$rowList[0]&sousPage=modifClients.php&AdminState=1'>"; $rowList[1]=nbsp($rowList[1]); echo "$rowList[1]</a>$font_end</td>
                                        		<td width='60%'>$font_begin <a href=mailto:$rowList[6]>$rowList[6]</a>$font_end</td>";
                        	echo "</tr>";
            			}
						if ($Record_count!=0) echo "</table>";
            			echo "<hr>";
    				}
				}
				elseif ($FormulairePrets=='TRUE') echo "<br><br><center><h2>Action annulée !!</H2><BR><center><br><br><a href='index.php?sousPage=prets.php&MenuChoix=4&IDClient=$IDClientSauv&AdminState=1'>Retour</a><BR></center>";
			}
		}
		else
		{
			if ($valider!='Annuler')
			{
				echo "<center><h1>Ajouts de clients</h1></center><hr>";
				if ($FormulairePrets=='TRUE') FormModifs ($IDClient, 71, 'TRUE');
				else FormModifs ($IDClient, 7, 'TRUE');
			}
			else
			{
				echo "<br><br><center><h2>Action annulée !!</H2><BR><center><br><br><a href='index.php?sousPage="; if ($FormulairePrets!='TRUE') echo "modifClients.php"; else echo "prets.php&MenuChoix=4&IDClient=$IDClientSauv"; echo "&AdminState=1'>Retour</a><BR></center>";
			}
		}
	}
	else
	{
		echo "<table width='100%' border='0' valign='top'><br><br><tr><td><center><h2>Mot&nbsp;de&nbsp;passe&nbsp;incorrect<BR>ou<BR>session&nbsp;terminée</h2><br><a href='index.php?sousPage=admin-request.php'>Autentifiez-vous&nbsp;ici</a></center></td></tr></table>";
	}

?>
Return current item: PhpMyDVDs