/includes/index/searchFriend.php
PHP | 255 lines | 226 code | 19 blank | 10 comment | 27 complexity | 24ab78cdb2199f9253f74d09188d9b01 MD5 | raw file
- <!---
- Formulaire de recherche
- --->
- <?php
- if(isset($_SESSION['isConnected']) && $_SESSION['isConnected'])
- {
- ?>
- <table style='border:2px solid rgb(198, 155, 224); border-collapse:collapse; margin-left:20px;' width='660px;' class='simpleFormat'>
- <tr style='background-color:rgb(198, 155, 224)'>
- <td class='simpleFormat' colspan='5'>
- <h3 class='h3SimpleFormat' style='color:rgb(132, 65, 170); '><center>Rechercher un ami</center></h3>
- </td>
- </tr>
- <tr height='10px'/>
- <tr>
- <form method="post" action="index.php?cat=searchFriend" name="submitSearch">
- <td/>
- <td class="simpleFormat" width='35%'>
- Nom :
- </td>
- <td width='50%'>
- <input type="text" name="name" onMouseOver="this.focus();">
- </td>
- </tr>
- <tr>
- <td/>
- <td class="simpleFormat">
- Prénom :
- </td>
- <td>
- <input type="text" name="forname" onMouseOver="this.focus();">
- </td>
- </tr>
- <tr>
- <td/>
- <td class="simpleFormat">
- Pseudonyme :
- </td>
- <td>
- <input type="text" name="pseudo" onMouseOver="this.focus();">
- </td>
- </tr>
- <tr>
- <td colspan="3" align="center">
- <input type="submit" value="Rechercher" class="simpleFormat">
- <input type="submit" value="TOUS" class="simpleFormat" onClick="all.value='yes';submit();">
- <input type="hidden" value="no" name="all" class="simpleFormat">
- </td>
- </form>
- </tr>
- <tr height='10px'/>
- </table>
- <br>
- <!---
- Résultat de la recherche
- --->
- <?php
-
- //Récupération des données
- $isPseudoEmpty=false;
- $isNameEmpty=false;
- $isFornameEmpty=false;
-
- if(isset($_POST['pseudo']) && !empty($_POST['pseudo'])) $tmpPseudo=$_POST['pseudo'];
- else
- {
- $isPseudoEmpty=true;
- $tmpPseudo="";
- }
-
- if(isset($_POST['forname']) && !empty($_POST['forname'])) $tmpForname=$_POST['forname'];
- else
- {
- $isFornameEmpty=true;
- $tmpForname="";
- }
-
- if(isset($_POST['name']) && !empty($_POST['name'])) $tmpName=$_POST['name'];
- else
- {
- $isNameEmpty=true;
- $tmpName="";
- }
-
- if(isset($_POST['all']) && !empty($_POST['all']))
- $All=$_POST['all']=='no'?false:true;
- else
- $All=false;
-
- $tmpPseudo=strtolower($tmpPseudo);
- $tmpName=strtolower($tmpName);
- $tmpForname=strtolower($tmpForname);
-
- //Interrogation de la base de données
- global $host, $user, $password, $base;
- $link=connexion();
- $sql="SELECT pseudo, nom, prenom, idUtilisateur, nbvote, reputation
- FROM utilisateur
- WHERE pseudo LIKE '%".$tmpPseudo."%'
- AND nom LIKE '%".$tmpName."%'
- AND prenom LIKE '%".$tmpForname."%'
- AND idUtilisateur<>".$_SESSION['userID']."
- ORDER BY nom ;";
-
- $data=mysql_query($sql, $link);
-
- if((!$isPseudoEmpty or !$isNameEmpty or !$isFornameEmpty or $All) and mysql_num_rows($data)>0)
- {
- ?>
- <table style='border:2px solid rgb(198, 155, 224); border-collapse:collapse; margin-left:20px;' width='660px;' class='tableSearchFriend'>
- <tr style='background-color:rgb(198, 155, 224);'>
- <td class='simpleFormat' colspan='7'>
- <h3 class='h3SimpleFormat' style='color:rgb(132, 65, 170); '><center>Résultat de la recherche</center></h3>
- </td>
- </tr>
- <tr>
- <td class="simpleFormat" width="20%" height="30px">
- <center><b>Nom</b></center>
- </td>
- <td class="simpleFormat" width="20%">
- <center><b>Prénom</b></center>
- </td>
- <td class="simpleFormat" width="20%">
- <center><b>Pseudonyme</b></center>
- </td>
- <td class="simpleFormat">
- <center><b>Reputation</b></center>
- </td>
- <td class="simpleFormat">
- <center><b>NB vote</b></center>
- </td>
- <td class="simpleFormat">
- <center><b>Voter</b></center>
- </td>
- <td class="simpleFormat">
- <center><b>Inviter</b></center>
- </td>
- </tr>
- <?php
- while($row=mysql_fetch_array($data))
- {
- $pseudo=$row['pseudo'];
- $name=$row['nom'];
- $forname=$row['prenom'];
- $id=$row['idUtilisateur'];
- $nbvote=$row['nbvote'];
- $reputation=$row['reputation'];
-
- /* gestion des amis : est son ami ? */
- $sontami=sontami($id, $link);
- if($sontami){
- /* si oui : affiche le bouton pour le retirer */
- $codeami=' <td>
- <Center><a href="index.php?cat=enleverami&id='.$id.'"><img style="border:none;" src="templates/images/delete.JPG" alt="Supprimer ami" title="Supprimer un ami"></a></center>
- </td>';
-
- //partie de gestion du vote
- $reqvote="SELECT COUNT(*) FROM voteutilisateur WHERE idVotant=".$_SESSION['userID']." AND idUtilisateur=".$id.";";
- $SQLVote=mysql_query($reqvote, $link);
- $resultVote=mysql_result($SQLVote, 0);
-
- if($resultVote!=0) $codevote='<td/>';
- if($resultVote==0)
- $codevote=' <td>
- <form name="AddVote" method="post" action="index.php?cat=addNewVoteUser">
- <SELECT name="choix" onChange="if(this.value!=-1)submit();">
- <option value="-1"> </option>
- <option value="0"> 0 </option>
- <option value="1"> 1 </option>
- <option value="2"> 2 </option>
- <option value="3"> 3 </option>
- <option value="4"> 4 </option>
- <option value="5"> 5 </option>
- <option value="6"> 6 </option>
- <option value="7"> 7 </option>
- <option value="8"> 8 </option>
- <option value="9"> 9 </option>
- <option value="10"> 10 </option>
- </SELECT>
- <input type="hidden" value="'.$id.'" name="utilisateur">
- </form>
- </td>';
- }
- else {
- /* sinon on affiche le bouton pour l'ajouter */
- $codeami='<td align="center">
- <a href="index.php?cat=ajouterami&id='.$id.'"><img style="border:none;" src="templates/images/valide2.PNG" alt="Ajouter ami" title="Ajouter"></a>
- </td>';
- $codevote='<td/>';
- }
-
- $concat=analyze($pseudo, $name, $forname);
- $result=0;
-
- if(!$isPseudoEmpty && strpos($concat, $tmpPseudo)!==false) $result=1;
- if(!$isNameEmpty && strpos($concat, $tmpName)!==false) $result=1;
- if(!$isFornameEmpty && strpos($concat, $tmpForname)!==false) $result=1;
- if($All) $result=1;
-
- if($result==1)
- {
- echo '<tr>
- <td align="center" class="simpleFormat">'.$name.'</td>
- <td align="center" class="simpleFormat">'.$forname.'</td>
- <td align="center" class="simpleFormat">'.$pseudo.'</td>
- <td align="center" class="simpleFormat">'.$reputation.'</td>
- <td align="center" class="simpleFormat">'.$nbvote.'</td>
- '.$codevote.'
- '.$codeami.'
- </tr>';
- }
- }
- ?>
- </table>
- <?php
- }
- if(!(mysql_num_rows($data)>0))
- echo "<table style='border:2px solid rgb(198, 155, 224); border-collapse:collapse; margin-left:20px;' width='660px;'>
- <tr align='center'><td class='tdWarning'></td>
- <td>Aucun utilisateur ne correspond ? vos crit?res de recherche!</td></tr></table>";
- }
-
- //Retourne une chaine de caract?re pour effectuer la recherche
- function analyze($pseudo, $name, $forname)
- {
- //concaténation et mise en minuscule des caract?res
- $tmpConcat=strtolower($pseudo.$name.$forname);
-
- //Supression des espaces blanc
- $concat=strtolower($pseudo.$name.$forname);
- $j=0;
- for($i=0; $i<strlen($tmpConcat); ++$i)
- {
- if($tmpConcat[$i]!=' ')
- {
- $concat[$j]=$tmpConcat[$i];
- $j++;
- }
- }
- $concat=substr($concat, 0, $j);
- return $concat;
- }
-
- function sontami($id, $link) {
- //recherche si c'est son ami
- $req="SELECT COUNT(utilisateur.idUtilisateur) FROM utilisateur, estAmi WHERE estAmi.idUtilisateur=".$_SESSION['userID']." AND estAmi.idAmi=".$id." ; ";
- $sql=mysql_query($req, $link);
- $resultVote=mysql_result($sql, 0);
-
- if($resultVote!=0)
- return true;
- else
- return false;
- }
- ?>