PageRenderTime 50ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/includes/index/searchFriend.php

http://projetwebdubail.googlecode.com/
PHP | 255 lines | 226 code | 19 blank | 10 comment | 27 complexity | 24ab78cdb2199f9253f74d09188d9b01 MD5 | raw file
  1. <!---
  2. Formulaire de recherche
  3. --->
  4. <?php
  5. if(isset($_SESSION['isConnected']) && $_SESSION['isConnected'])
  6. {
  7. ?>
  8. <table style='border:2px solid rgb(198, 155, 224); border-collapse:collapse; margin-left:20px;' width='660px;' class='simpleFormat'>
  9. <tr style='background-color:rgb(198, 155, 224)'>
  10. <td class='simpleFormat' colspan='5'>
  11. <h3 class='h3SimpleFormat' style='color:rgb(132, 65, 170); '><center>Rechercher un ami</center></h3>
  12. </td>
  13. </tr>
  14. <tr height='10px'/>
  15. <tr>
  16. <form method="post" action="index.php?cat=searchFriend" name="submitSearch">
  17. <td/>
  18. <td class="simpleFormat" width='35%'>
  19. Nom :
  20. </td>
  21. <td width='50%'>
  22. <input type="text" name="name" onMouseOver="this.focus();">
  23. </td>
  24. </tr>
  25. <tr>
  26. <td/>
  27. <td class="simpleFormat">
  28. Prénom :
  29. </td>
  30. <td>
  31. <input type="text" name="forname" onMouseOver="this.focus();">
  32. </td>
  33. </tr>
  34. <tr>
  35. <td/>
  36. <td class="simpleFormat">
  37. Pseudonyme :
  38. </td>
  39. <td>
  40. <input type="text" name="pseudo" onMouseOver="this.focus();">
  41. </td>
  42. </tr>
  43. <tr>
  44. <td colspan="3" align="center">
  45. <input type="submit" value="Rechercher" class="simpleFormat">
  46. <input type="submit" value="TOUS" class="simpleFormat" onClick="all.value='yes';submit();">
  47. <input type="hidden" value="no" name="all" class="simpleFormat">
  48. </td>
  49. </form>
  50. </tr>
  51. <tr height='10px'/>
  52. </table>
  53. <br>
  54. <!---
  55. Résultat de la recherche
  56. --->
  57. <?php
  58. //Récupération des données
  59. $isPseudoEmpty=false;
  60. $isNameEmpty=false;
  61. $isFornameEmpty=false;
  62. if(isset($_POST['pseudo']) && !empty($_POST['pseudo'])) $tmpPseudo=$_POST['pseudo'];
  63. else
  64. {
  65. $isPseudoEmpty=true;
  66. $tmpPseudo="";
  67. }
  68. if(isset($_POST['forname']) && !empty($_POST['forname'])) $tmpForname=$_POST['forname'];
  69. else
  70. {
  71. $isFornameEmpty=true;
  72. $tmpForname="";
  73. }
  74. if(isset($_POST['name']) && !empty($_POST['name'])) $tmpName=$_POST['name'];
  75. else
  76. {
  77. $isNameEmpty=true;
  78. $tmpName="";
  79. }
  80. if(isset($_POST['all']) && !empty($_POST['all']))
  81. $All=$_POST['all']=='no'?false:true;
  82. else
  83. $All=false;
  84. $tmpPseudo=strtolower($tmpPseudo);
  85. $tmpName=strtolower($tmpName);
  86. $tmpForname=strtolower($tmpForname);
  87. //Interrogation de la base de données
  88. global $host, $user, $password, $base;
  89. $link=connexion();
  90. $sql="SELECT pseudo, nom, prenom, idUtilisateur, nbvote, reputation
  91. FROM utilisateur
  92. WHERE pseudo LIKE '%".$tmpPseudo."%'
  93. AND nom LIKE '%".$tmpName."%'
  94. AND prenom LIKE '%".$tmpForname."%'
  95. AND idUtilisateur<>".$_SESSION['userID']."
  96. ORDER BY nom ;";
  97. $data=mysql_query($sql, $link);
  98. if((!$isPseudoEmpty or !$isNameEmpty or !$isFornameEmpty or $All) and mysql_num_rows($data)>0)
  99. {
  100. ?>
  101. <table style='border:2px solid rgb(198, 155, 224); border-collapse:collapse; margin-left:20px;' width='660px;' class='tableSearchFriend'>
  102. <tr style='background-color:rgb(198, 155, 224);'>
  103. <td class='simpleFormat' colspan='7'>
  104. <h3 class='h3SimpleFormat' style='color:rgb(132, 65, 170); '><center>Résultat de la recherche</center></h3>
  105. </td>
  106. </tr>
  107. <tr>
  108. <td class="simpleFormat" width="20%" height="30px">
  109. <center><b>Nom</b></center>
  110. </td>
  111. <td class="simpleFormat" width="20%">
  112. <center><b>Prénom</b></center>
  113. </td>
  114. <td class="simpleFormat" width="20%">
  115. <center><b>Pseudonyme</b></center>
  116. </td>
  117. <td class="simpleFormat">
  118. <center><b>Reputation</b></center>
  119. </td>
  120. <td class="simpleFormat">
  121. <center><b>NB vote</b></center>
  122. </td>
  123. <td class="simpleFormat">
  124. <center><b>Voter</b></center>
  125. </td>
  126. <td class="simpleFormat">
  127. <center><b>Inviter</b></center>
  128. </td>
  129. </tr>
  130. <?php
  131. while($row=mysql_fetch_array($data))
  132. {
  133. $pseudo=$row['pseudo'];
  134. $name=$row['nom'];
  135. $forname=$row['prenom'];
  136. $id=$row['idUtilisateur'];
  137. $nbvote=$row['nbvote'];
  138. $reputation=$row['reputation'];
  139. /* gestion des amis : est son ami ? */
  140. $sontami=sontami($id, $link);
  141. if($sontami){
  142. /* si oui : affiche le bouton pour le retirer */
  143. $codeami=' <td>
  144. <Center><a href="index.php?cat=enleverami&amp;id='.$id.'"><img style="border:none;" src="templates/images/delete.JPG" alt="Supprimer ami" title="Supprimer un ami"></a></center>
  145. </td>';
  146. //partie de gestion du vote
  147. $reqvote="SELECT COUNT(*) FROM voteutilisateur WHERE idVotant=".$_SESSION['userID']." AND idUtilisateur=".$id.";";
  148. $SQLVote=mysql_query($reqvote, $link);
  149. $resultVote=mysql_result($SQLVote, 0);
  150. if($resultVote!=0) $codevote='<td/>';
  151. if($resultVote==0)
  152. $codevote=' <td>
  153. <form name="AddVote" method="post" action="index.php?cat=addNewVoteUser">
  154. <SELECT name="choix" onChange="if(this.value!=-1)submit();">
  155. <option value="-1"> </option>
  156. <option value="0"> 0 </option>
  157. <option value="1"> 1 </option>
  158. <option value="2"> 2 </option>
  159. <option value="3"> 3 </option>
  160. <option value="4"> 4 </option>
  161. <option value="5"> 5 </option>
  162. <option value="6"> 6 </option>
  163. <option value="7"> 7 </option>
  164. <option value="8"> 8 </option>
  165. <option value="9"> 9 </option>
  166. <option value="10"> 10 </option>
  167. </SELECT>
  168. <input type="hidden" value="'.$id.'" name="utilisateur">
  169. </form>
  170. </td>';
  171. }
  172. else {
  173. /* sinon on affiche le bouton pour l'ajouter */
  174. $codeami='<td align="center">
  175. <a href="index.php?cat=ajouterami&id='.$id.'"><img style="border:none;" src="templates/images/valide2.PNG" alt="Ajouter ami" title="Ajouter"></a>
  176. </td>';
  177. $codevote='<td/>';
  178. }
  179. $concat=analyze($pseudo, $name, $forname);
  180. $result=0;
  181. if(!$isPseudoEmpty && strpos($concat, $tmpPseudo)!==false) $result=1;
  182. if(!$isNameEmpty && strpos($concat, $tmpName)!==false) $result=1;
  183. if(!$isFornameEmpty && strpos($concat, $tmpForname)!==false) $result=1;
  184. if($All) $result=1;
  185. if($result==1)
  186. {
  187. echo '<tr>
  188. <td align="center" class="simpleFormat">'.$name.'</td>
  189. <td align="center" class="simpleFormat">'.$forname.'</td>
  190. <td align="center" class="simpleFormat">'.$pseudo.'</td>
  191. <td align="center" class="simpleFormat">'.$reputation.'</td>
  192. <td align="center" class="simpleFormat">'.$nbvote.'</td>
  193. '.$codevote.'
  194. '.$codeami.'
  195. </tr>';
  196. }
  197. }
  198. ?>
  199. </table>
  200. <?php
  201. }
  202. if(!(mysql_num_rows($data)>0))
  203. echo "<table style='border:2px solid rgb(198, 155, 224); border-collapse:collapse; margin-left:20px;' width='660px;'>
  204. <tr align='center'><td class='tdWarning'></td>
  205. <td>Aucun utilisateur ne correspond ? vos crit?res de recherche!</td></tr></table>";
  206. }
  207. //Retourne une chaine de caract?re pour effectuer la recherche
  208. function analyze($pseudo, $name, $forname)
  209. {
  210. //concaténation et mise en minuscule des caract?res
  211. $tmpConcat=strtolower($pseudo.$name.$forname);
  212. //Supression des espaces blanc
  213. $concat=strtolower($pseudo.$name.$forname);
  214. $j=0;
  215. for($i=0; $i<strlen($tmpConcat); ++$i)
  216. {
  217. if($tmpConcat[$i]!=' ')
  218. {
  219. $concat[$j]=$tmpConcat[$i];
  220. $j++;
  221. }
  222. }
  223. $concat=substr($concat, 0, $j);
  224. return $concat;
  225. }
  226. function sontami($id, $link) {
  227. //recherche si c'est son ami
  228. $req="SELECT COUNT(utilisateur.idUtilisateur) FROM utilisateur, estAmi WHERE estAmi.idUtilisateur=".$_SESSION['userID']." AND estAmi.idAmi=".$id." ; ";
  229. $sql=mysql_query($req, $link);
  230. $resultVote=mysql_result($sql, 0);
  231. if($resultVote!=0)
  232. return true;
  233. else
  234. return false;
  235. }
  236. ?>