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

    /***************************************************************************
                                 prets.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 (($ValiderClient=='Modifier le client' and ($Client or $IDClientModif)) or $ValiderClient=='Ajouter un client')
		{
			if ($ValiderClient=='Modifier le client')
			{
				if ($Client)
				{
					$Client_separe = explode(" ", $Client);
					$Client_temp = ChercheClient($Client_separe[1], $Client_separe[0]);
					$IDClient = $Client_temp->IDClient;
        		}
				elseif (!$Client) // Dans le cas d'un appel par JavaScript
				{
					$IDClient=$IDClientModif;
					$connexion = Connexion (NOM, PASSE, BASE, SERVEUR);

					$resultat=ExecRequete("SELECT * FROM $pTable_Prefixe"."Clients WHERE IDClient=$IDClient", BASE);
					$Client_result=mysql_fetch_object($resultat);

					$Client=$Client_result->PrenomClient." ".$Client_result->NomClient;
				}
			}
			elseif ($ValiderClient=='Ajouter un client')
			{
				$ajout='TRUE';
				unset($IDClient);
			}
			$FormulairePrets='TRUE';
			include ("modifClients.php");
		}
		else
		{
			if ($sousPage=='prets.php') echo "<br><br>";
			echo "<center><h1>Gestion des prêts</h1></center><hr>";

        	$connexion = Connexion (NOM, PASSE, BASE,SERVEUR);

			if ($DVDValider=='>> Emprunt')
			{
				if (!$IDDVD_Emprunt)
				{
					$DVD_Emprunt=stripSlashes($DVD_Emprunt);

					$IDDVDTemp=ChercheDVD($DVD_Emprunt);
					$IDDVD=$IDDVDTemp->IDDVD;
				}
				else $IDDVD=$IDDVD_Emprunt;
				$request = ExecRequete ("SELECT IDDVD FROM $pTable_Prefixe"."DVD WHERE IDDVD=$IDDVD", BASE);
				$TestExistence=mysql_num_rows($request);
				if ($TestExistence==0) echo "<table width='100%' border='0' valign='top'><tr><td><center><b><font color='#FF0000'>Le&nbsp;DVD&nbsp;No&nbsp;$IDDVD&nbsp;n'existe&nbsp;pas&nbsp;!!</font></b></center></td></tr></table>";
				else
				{
					$requete_test = "SELECT IDDVD FROM $pTable_Prefixe"."Prets WHERE IDDVD=$IDDVD";
					$resultat_test = ExecRequete($requete_test, BASE);
					$TestEmprunt = mysql_num_rows($resultat_test);
					if ($TestEmprunt==0)
					{
						$requete="INSERT INTO $pTable_Prefixe"."Prets (IDClient, IDDVD) VALUES ('$IDClient', '$IDDVD')";
						$resultat=ExecRequete($requete, BASE);

						$requete="UPDATE $pTable_Prefixe"."DVD SET Emprunt=1 WHERE IDDVD=$IDDVD";
						$resultat=ExecRequete($requete, BASE);
					}
					else echo "<table width='100%' border='0' valign='top'><tr><td><center><b><font color='#FF0000'>Le&nbsp;DVD&nbsp;No&nbsp;$IDDVD&nbsp;est&nbsp;déjà&nbsp;<a href=index.php?sousPage=prets.php&AdminState=1&IDDVD=$IDDVD>emprunté</a>&nbsp;!!</font></b></center></td></tr></table>";
				}
			}
			elseif ($DVDValider=='<< Restitution')
			{
				if ($NombreDVDEmpruntesClient!=0)
				{
					for ($i==1;$i<=$NombreDVDEmpruntesClient;$i++)
					{
						if ($ChoixDVD[$i])
						{
							$requete="DELETE FROM $pTable_Prefixe"."Prets WHERE IDDVD=$IDDVD_Check[$i]";
							$resultat=ExecRequete($requete, BASE);

							$requete="UPDATE $pTable_Prefixe"."DVD SET Emprunt=0 WHERE IDDVD=$IDDVD_Check[$i]";
							$resultat=ExecRequete($requete, BASE);
						}
					}
				}
			}

			// Recherche des DVDs existants dans la base de données
			$DVDdisponiblesBase=ExecRequete("SELECT IDDVD FROM $pTable_Prefixe"."DVD", BASE);

			$nombreDVDdisponiblesBase=mysql_num_rows($DVDdisponiblesBase);

			// Recherche des DVDs disponibles
			$DVDdisponibles=ExecRequete("SELECT Titre, $pTable_Prefixe"."DVD.IDDVD
			FROM $pTable_Prefixe"."DVD LEFT OUTER JOIN $pTable_Prefixe"."Prets ON $pTable_Prefixe"."DVD.IDDVD = $pTable_Prefixe"."Prets.IDDVD
			WHERE $pTable_Prefixe"."DVD.IDDVD NOT IN ($pTable_Prefixe"."Prets.IDDVD)
			ORDER BY Titre ASC;", BASE);

			$nombreDVDdisponibles=mysql_num_rows($DVDdisponibles);

			if ($nombreDVDdisponibles>1) mysql_data_seek($DVDdisponibles, 1);
			if ($nombreDVDdisponibles>1)
			{
				for ($i=1; $i<$nombreDVDdisponibles; $i++)
				{
					$temp=mysql_fetch_object($DVDdisponibles);
					$ListeDVDdisponibles[$i]=$temp->Titre;
				}
			}
			else $ListeDVDdisponibles[0]="";

			if ($nombreDVDdisponibles!=0)
			{
				mysql_data_seek($DVDdisponibles, 0);
				$premierTemp=mysql_fetch_object($DVDdisponibles);
				$ListeDVDdisponibles_premier=$premierTemp->Titre;
			}

			if ($IDDVD and !$DVDValider)
			{
				$resultat=ExecRequete("SELECT IDClient FROM $pTable_Prefixe"."Prets WHERE IDDVD=$IDDVD", BASE);
				$ClientTemp=mysql_fetch_object($resultat);
				$IDClient=$ClientTemp->IDClient;
			}

			// Liste de tous les clients
			$resultat=ExecRequete("SELECT IDClient, PrenomClient, NomClient FROM $pTable_Prefixe"."Clients ORDER BY PrenomClient ASC, NomClient ASC", BASE);
			$nbLignes=mysql_num_rows($resultat);
			if ($nbLignes!=0)
			{
				for ($i=0; $i<$nbLignes; $i++)
				{
					$temp=mysql_fetch_object($resultat);
					$ListeClients[$i][0]=$temp->PrenomClient." ".$temp->NomClient;
					$ListeClients[$i][1]=$temp->IDClient;
				}
			}
			else $ListeClients[0][0]="";

			// Informations sur le client séléctionné
			if ($ListeDeroulante and !$IDClient)
			{
				$IDClientTemp=explode("=", $ListeDeroulante);
				$IDClient=$IDClientTemp[3];
			}
			if ($IDClient or $Client)
			{
				if ($Client and !$IDClient)
				{
					$Client_separe = explode(" ", $Client);
					$Client_temp = ChercheClient($Client_separe[1], $Client_separe[0]);
					$IDClient = $Client_temp->IDClient;
				}
				$resultat=ExecRequete("SELECT * FROM $pTable_Prefixe"."Clients WHERE IDClient=$IDClient", BASE);
				$DonneesClient = mysql_fetch_array($resultat);

				if ($IDClient and !$Client) $Client = $DonneesClient[2]." ".$DonneesClient[1];

				$requeteDVDEmpruntes="SELECT $pTable_Prefixe"."Prets.IDDVD, Titre, PrenomProprietaire, NomProprietaire, DatePret
				FROM $pTable_Prefixe"."DVD LEFT JOIN $pTable_Prefixe"."Proprietaires ON $pTable_Prefixe"."DVD.IDProprietaire=$pTable_Prefixe"."Proprietaires.IDProprietaire, $pTable_Prefixe"."Prets WHERE
				$pTable_Prefixe"."Prets.IDDVD=$pTable_Prefixe"."DVD.IDDVD
				AND IDClient=$IDClient
				ORDER BY Titre ASC";
				$ListeDVDEmpruntesClient=ExecRequete($requeteDVDEmpruntes, BASE);

				$NombreDVDEmpruntesClient=mysql_num_rows($ListeDVDEmpruntesClient);

				// Chargement des variables client
				$PrenomClient = nbsp($DonneesClient[2]);
				$NomClient = nbsp($DonneesClient[1]);
				$AdresseClient = Explode("
", $DonneesClient[3]);
				$i=0;
				while ($AdresseClient[$i]!="")
				{
					$AdresseClient[$i]=nbsp($AdresseClient[$i]);
					$i++;
				}
				$TelephoneClient = nbsp($DonneesClient[4]);
				$TelephonePortableClient = nbsp($DonneesClient[5]);
				$EmailClient = $DonneesClient[6];
			}

			echo "<TABLE WIDTH='100%' CELLSPACING='0' CELLPADDING='0' BORDER='0'>
						<TR>
							<TD>
								<BR>
							</TD>
						</TR>
						<TR>
							<TD>
							<TABLE CELLSPACING='0' CELLPADDING='0' BORDER='0'>
								<TR>
									<TD VALIGN='top'>";
										$formClient = new Formulaire ("POST", "index.php?sousPage=prets.php&AdminState=1");
										echo "<TABLE ALIGN='left' CELLSPACING='0' CELLPADDING='0' BORDER='0'><TR><TD>";
										if ($ListeClients[0][0]!="")
										{
											echo "Client <SELECT NAME='ListeDeroulante' SIZE=1 onChange='ChangeUrl(this.form)'>";
											echo "<OPTION VALUE='index.php?sousPage=prets.php&AdminState=1&IDClient=$IDClient'>$PrenomClient $NomClient";
											$i=0;
											while ($ListeClients[$i][0]!="")
											{
												$nomprenomclient=$ListeClients[$i][0];
												$IDClientListe=$ListeClients[$i][1];
  												if ($IDClientListe != $IDClient) echo "<OPTION VALUE='index.php?sousPage=prets.php&AdminState=1&IDClient=$IDClientListe'>$nomprenomclient";
												$i++;
											}
											echo "</SELECT>";
											$formClient->champValider ("Sélectionner", "ValiderClient");
										}
										echo "</TD></TR><TR><TD><BR>";
										if ($DonneesClient)
										{
											$formClient->champValider ("Modifier le client", "ValiderClient");
											echo "</TD></TR><TR><TD>";
										}
										$formClient->champValider ("Ajouter un client", "ValiderClient");
									echo "</TD></TR></TABLE></TD>
									<TD WIDTH='50'></TD>
									<TD ALIGN='left'>";
										if ($DonneesClient)
										{
											echo "<TABLE ALIGN='left' BORDER='0'>
															<TR>
																<TD>
																	<B>Client</B>
																</TD>
																<TD>
																	<B>:</B>&nbsp;$PrenomClient&nbsp;$NomClient
																</TD>
															</TR>";
														if ($AdresseClient[0])
														{
															echo "
															<TR>
																<TD VALIGN='top'>
																	<B>Adresse</B>
																</TD>
																<TD>";
																$i=0;
																while($AdresseClient[$i]!="")
																{
																	if ($i>0) echo "<BR>&nbsp;&nbsp;";
																	elseif ($i==0) echo "<B>:</B>&nbsp;";
																	echo $AdresseClient[$i];
																	$i++;
																}
																echo "
																</TD>
															</TR>";
														}
														if ($TelephoneClient)
														{
															echo "
															<TR>
																<TD>
																	<B>Téléphone</B>
																</TD>
																<TD>
																	<B>:</B>&nbsp;$TelephoneClient
																</TD>
															</TR>";
														}
														if ($TelephonePortableClient)
														{
															echo "
															<TR>
																<TD>
																	<B>Téléphone&nbsp;portable</B>
																</TD>
																<TD>
																	<B>:</B>&nbsp;$TelephonePortableClient
																</TD>
															</TR>";
														}
														if ($EmailClient)
														{
															echo "
															<TR>
																<TD>
																	<B>E-Mail</B>
																</TD>
																<TD>
																	<B>:</B>&nbsp;<A HREF=mailto:$EmailClient?subject=Emprunt_DVD>$EmailClient</A>
																</TD>
															</TR>";
														}
														echo "
														</TABLE>";
										}
									$formClient->champCache("MenuChoix", 4);
									$formClient->champCache("IDClientModif",$IDClient);
									$formClient->fin();
									echo "</TD>
								</TR>
							</TABLE>
							</TD>
						</TR>";
						if ($IDClient)
						{
							echo "
							<TR>
							</TR>
							<TR>
								<TD>
									<BR>
								</TD>
							</TR>
							<TR>
								<TD>
									<HR>
								</TD>
							</TR>
							<TR>
								<TD>
									<BR>
								</TD>
							</TR>
							<TR>
								<TD>";
									if ($nombreDVDdisponiblesBase!=0)
									{
									$formDVD=new Formulaire("POST", "index.php?sousPage=prets.php&AdminState=1");
									if ($nombreDVDdisponibles!=0)
									{
										echo "
										<TABLE ALIGN='left' CELLSPACING='0' CELLPADDING='0' BORDER='0'>
											<TR>
												<TD VALIGN='top'>";
													$formDVD->champListe("<center><b><font size='3'>DVDs&nbsp;disponibles&nbsp;&nbsp;</font></b></center>", "DVD_Emprunt", $ListeDVDdisponibles_premier, 10, $ListeDVDdisponibles);
												echo "</TD>
												<TD VALIGN='top'>";
													$formDVD->champTexte("<center><b><font size='3'>IDDVD</font></b><br></center>", "IDDVD_Emprunt", "", 4, 10);
												echo "</TD>
												<TD WIDTH='10' ALIGN='left' VALIGN='top'><BR>";
													$formDVD->champValider(">> Emprunt", "DVDValider");
									}
									else
									{
										echo "
										<TABLE ALIGN='left' CELLSPACING='0' CELLPADDING='0' BORDER='0'>
											<TR>
												<TD VALIGN='top'>
													<FONT SIZE='4' COLOR='#FF0000'>Aucun&nbsp;DVD&nbsp;n'est&nbsp;actuellement&nbsp;disponible&nbsp;!!</FONT>
												</TD>
												<TD VALIGN='top'>
												</TD>
												<TD WIDTH='10' ALIGN='left' VALIGN='top'><BR>";
									}
												if ($NombreDVDEmpruntesClient!=0)
												{
													echo "<BR>";
													$formDVD->champValider("<< Restitution", "DVDValider");
												}
											echo "</TD>
											<TD VALIGN='top'>";
													if ($NombreDVDEmpruntesClient!=0)
													{
														echo "
														<TABLE  CELLSPACING='0' CELLPADDING='0' BORDER='0'>
															<TR><TD COLSPAN=5 ALIGN='center'><B><FONT SIZE='3'>DVDs&nbsp;empruntés&nbsp;par&nbsp;$PrenomClient&nbsp;$NomClient</FONT></B></TD></TR>
                    										<TR>
                    											<TD VALIGN='top' BGCOLOR='$color_frame'><B><FONT FACE='Arial, Helvetica, sans-serif' SIZE='2' COLOR='$color_menu'></FONT>&nbsp;</B></TD>
                    											<TD VALIGN='top' BGCOLOR='$color_frame'><B><FONT FACE='Arial, Helvetica, sans-serif' SIZE='2' COLOR='$color_menu'>&nbsp;ID&nbsp;DVD</FONT></B></TD>
                    											<TD VALIGN='top' BGCOLOR='$color_frame'><B><FONT FACE='Arial, Helvetica, sans-serif' SIZE='2' COLOR='$color_menu'>&nbsp;Titre&nbsp;du&nbsp;film</FONT></B></TD>
                    											<TD VALIGN='top' BGCOLOR='$color_frame'><B><FONT FACE='Arial, Helvetica, sans-serif' SIZE='2' COLOR='$color_menu'>&nbsp;Date&nbsp;d'emprunt</FONT></B></TD>
                    											<TD VALIGN='top' BGCOLOR='$color_frame'><B><FONT FACE='Arial, Helvetica, sans-serif' SIZE='2' COLOR='$color_menu'>&nbsp;Propriétaire</FONT></B></TD>
															</TR>
                    										<TR><TD COLSPAN=5><HR></TD></TR>";
															$font_begin="<FONT COLOR='#FF0A3B' FACE='Arial, Helvetica, sans-serif' SIZE='2'>";
															$font_end="</FONT>";
															$i=1;
															$ListeCheckBox=array("");
															while ($rowList = mysql_fetch_array ($ListeDVDEmpruntesClient))
															{
																$href_begin ="";
																$href_end ="";

																// Propriétaire du DVD
																$resultat = ExecRequete ("SELECT $pTable_Prefixe"."DVD.IDProprietaire, NomProprietaire, PrenomProprietaire
       	 														FROM $pTable_Prefixe"."DVD LEFT JOIN $pTable_Prefixe"."Proprietaires ON $pTable_Prefixe"."DVD.IDProprietaire=$pTable_Prefixe"."Proprietaires.IDProprietaire
        														WHERE $pTable_Prefixe"."DVD.IDDVD=$rowList[0]
        														ORDER BY PrenomProprietaire ASC, NomProprietaire ASC;", BASE);
																$ProprietaireDVD_temp=mysql_fetch_object($resultat);
																$Proprietaire_DVD=$ProprietaireDVD_temp->PrenomProprietaire."&nbsp;".$ProprietaireDVD_temp->NomProprietaire;
																$IDProprietaire=$ProprietaireDVD_temp->IDProprietaire;
																$DateEmprunt=FormatageDate($rowList[4]);
																$DateEmprunt=nbsp($DateEmprunt);

                    											echo "		<TR>
																					<TD ALIGN='center' VALIGN='center'>";
																					echo "<INPUT TYPE='CHECKBOX' NAME='ChoixDVD[$i]'>";
																					$formDVD->champCache("IDDVD_Check[$i]", $rowList[0]);
																					echo "</TD>
                                        											<TD VALIGN='center'><FONT COLOR='#FF0000' FACE='Arial, Helvetica, sans-serif' SIZE='2'>&nbsp;$rowList[0] $font_end</TD>
																					<TD VALIGN='center'>$font_begin &nbsp;<A HREF='index.php?IDDVD=$rowList[0]&sousPage=ficheDVD.php'>"; if ($IDDVD==$rowList[0] and !$DVDValider) echo "<B>"; echo "<FONT COLOR="; if ($IDDVD==$rowList[0] and !$DVDValider) echo $color_menu_actif; else echo "'#000000'"; echo " FACE='Arial, Helvetica, sans-serif' SIZE='2'>"; $rowList[1]=nbsp($rowList[1]); echo "$rowList[1]</FONT>"; if ($IDDVD==$rowList[0] and !$DVDValider) echo "</B>"; echo "</A>$font_end</TD>
                                        											<TD VALIGN='center'><FONT COLOR='#FF0000' FACE='Arial, Helvetica, sans-serif' SIZE='2'>&nbsp;$DateEmprunt $font_end</TD>";
																					if ($IDProprietaire) echo "<TD VALIGN='center'>$font_begin &nbsp;<A HREF='index.php?IDProprietaire=$IDProprietaire&sousPage=proprietaires.php'>$Proprietaire_DVD</A>$font_end &nbsp;</TD>";
                    															echo "</TR>";
																$i++;
            												}
														echo "
														</TABLE>";
													}
											$formDVD->champCache("NombreDVDEmpruntesClient", $NombreDVDEmpruntesClient);
											$formDVD->champCache("MenuChoix", 4);
											$formDVD->champCache("IDClient", $IDClient);
											$formDVD->fin();
											echo "
											</TD>
										</TR>
									</TABLE>";
									}
									else echo "<CENTER><FONT COLOR='#FF0000' SIZE='4'>Aucun&nbsp;DVD&nbsp;n'existe&nbsp;dans&nbsp;la&nbsp;base&nbsp;de&nbsp;données&nbsp;!!</FONT></CENTER><BR><BR>";
								echo "</TD>
							</TR>
							";
						}
					echo "
					</TABLE>";
		}
	}
	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