PageRenderTime 42ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 1ms

/admin/controls/profils.php

https://gitlab.com/pancard/nuXt
PHP | 227 lines | 174 code | 45 blank | 8 comment | 17 complexity | 132293a7983cc3cb8582c80bbfd2392b MD5 | raw file
  1. <?php
  2. function xAfficherProfils() {
  3. $reponse = new xajaxResponse();
  4. $reponse->clear('tableProfil','innerHTML');
  5. $tableau = "";
  6. $tableau .= "<tr>
  7. <th>ID</th>
  8. <th>Libellé</th>
  9. <th>Modifier</th>
  10. <th>Archiver</th>
  11. </tr>";
  12. // Récupérer en base de données les infos du membre
  13. connexion();
  14. $sql = sql('SELECT * FROM nuxt_profils WHERE profils_valide = 1 AND profils_id > 0 ORDER BY profils_libelle;');
  15. deconnexion();
  16. while($value = mysql_fetch_array($sql)) {
  17. if($value['profils_valide']=='1') {
  18. $image_del = '<img src="'.$GLOBALS['IMG_valide'].'" alt="Actif" class="icone" onClick="jsArchiverProfil('.$value['profils_id'].',0);" />';
  19. }
  20. else {
  21. $image_del = '<img src="'.$GLOBALS['IMG_invalide'].'" alt="Inactif" class="icone" onClick="jsArchiverProfil('.$value['profils_id'].',1);" />';
  22. }
  23. $image_up = '<img src="'.$GLOBALS['IMG_modifier'].'" alt="Modifier" class="icone" />';
  24. $tableau .= '<tr>';
  25. $tableau .= '<td>'.$value['profils_id'].'</td>';
  26. $tableau .= '<td>'.$value['profils_libelle'].'</td>';
  27. $tableau .= '<td><img src="'.$GLOBALS['IMG_modifier'].'" alt="Modifier" class="icone" onClick="jsAfficherProfilById('.$value['profils_id'].');" /></td>';
  28. $tableau .= '<td>'.$image_del.'</td>';
  29. $tableau .= '</tr>';
  30. }
  31. if(mysql_num_rows($sql)<=0) {
  32. $reponse->assign('lbl_resultat','innerHTML','Aucun résultat');
  33. }
  34. else {
  35. $reponse->assign('tableProfil','innerHTML',$tableau);
  36. }
  37. return $reponse;
  38. }
  39. function xAfficherProfilById($id) {
  40. $reponse = new xajaxResponse();
  41. connexion();
  42. $repSql = sql('SELECT * FROM nuxt_profils WHERE profils_id = '.$id.' AND profils_id > 0 ;');
  43. deconnexion();
  44. while($ligne = mysql_fetch_array($repSql)) {
  45. $reponse->assign('upid', 'value', $ligne['profils_id']);
  46. $reponse->assign('uplibelle', 'value', $ligne['profils_libelle']);
  47. $reponse->assign('upListeDroits','innerHTML', getInputDroits($id));
  48. }
  49. return $reponse;
  50. }
  51. function xCreerProfil($libelle,$d) {
  52. $reponse = new xajaxResponse();
  53. $reponse->clear('tableProfil','innerHTML');
  54. $reponse->clear('addListeDroits','innerHTML');
  55. $reponse->assign('addListeDroits', 'innerHTML', getInputDroits(""));
  56. $nextId = getNextID('profils');
  57. connexion();
  58. $libelle = securite_bdd($libelle);
  59. // Je retravaille les droits et leurs valeurs ex: 1-1;2-0 = id1-actif;id2-non actif
  60. $droits = explode(";",$d);
  61. for($i = 0; $i < count($droits); $i++) {
  62. //$people[$i]['salt'] = mt_rand(000000, 999999);
  63. $droit = explode("-",$droits[$i]);
  64. sql('INSERT INTO nuxt_lien_droits_profils (l_profils_id,l_droits_id,l_actif)
  65. VALUES ("'.$nextId.'","'.$droit[0].'","'.$droit[1].'");');
  66. }
  67. sql('INSERT INTO nuxt_profils (profils_id,profils_libelle,profils_valide)
  68. VALUES ("'.$nextId.'","'.$libelle.'","1");');
  69. deconnexion();
  70. $reponse->assign('lbl_resultat', 'innerHTML', 'Profil '.$libelle.' crée avec succès !');
  71. $reponse->call('xajax_xAfficherProfils');
  72. return $reponse;
  73. }
  74. function xModifierProfil($id,$libelle,$d) {
  75. $reponse = new xajaxResponse();
  76. $reponse->clear('tableProfil','innerHTML');
  77. $reponse->clear('upListeDroits','innerHTML');
  78. $reponse->assign('upListeDroits', 'innerHTML', getInputDroits($id));
  79. connexion();
  80. $libelle = securite_bdd($libelle);
  81. // Je retravaille les droits et leurs valeurs ex: 1-1;2-0 = id1-actif;id2-non actif
  82. $droits = explode(";",$d);
  83. for($i = 0; $i < count($droits); $i++) {
  84. //$people[$i]['salt'] = mt_rand(000000, 999999);
  85. $droit = explode("-",$droits[$i]);
  86. sql('UPDATE nuxt_lien_droits_profils SET l_actif = "'.$droit[1].'" WHERE l_droits_id = "'.$droit[0].'" AND l_profils_id = "'.$id.'";');
  87. }
  88. sql('UPDATE nuxt_profils SET profils_libelle = "'.$libelle.'" WHERE profils_id = "'.$id.'";');
  89. deconnexion();
  90. $reponse->assign('lbl_resultat', 'innerHTML', 'Profil '.$libelle.' modifié avec succès !');
  91. $reponse->call('xajax_xAfficherProfils');
  92. return $reponse;
  93. }
  94. function xArchiverProfil($id,$value) {
  95. $reponse = new xajaxResponse();
  96. $reponse->clear('tableProfil','innerHTML');
  97. connexion();
  98. sql('UPDATE nuxt_profils SET profils_valide = '.$value.' WHERE profils_id = '.$id.';');
  99. deconnexion();
  100. if($value=="0") {
  101. $msg = "Désactivation ";
  102. }
  103. else {
  104. $msg = "Activation ";
  105. }
  106. $res = $msg.' du profil effectuée avec succès';
  107. $reponse->assign('lbl_resultat','innerHTML',$res);
  108. $reponse->call('xajax_xAfficherProfils');
  109. return $reponse;
  110. }
  111. function xAfficherProfilsWCritere($crit)
  112. {
  113. $reponse = new xajaxResponse();
  114. $reponse->clear('tableProfil','innerHTML');
  115. // Variable pour le WHERE
  116. $where = " WHERE ";
  117. // Découpage des critères
  118. if(($crit!="") OR (isset($crit))) {
  119. $where .= " (profils_libelle like '%".$crit."%') ";
  120. $where .= " AND profils_id > 0 ";
  121. }
  122. $tableau = "";
  123. $tableau .= "<tr>
  124. <th>ID</th>
  125. <th>Libellé</th>
  126. <th>Modifier</th>
  127. <th>Archiver</th>
  128. </tr>";
  129. // Récupérer en base de données les infos du membre
  130. connexion();
  131. $sql = sql("SELECT * FROM nuxt_profils ".$where." ORDER BY profils_libelle;");
  132. deconnexion();
  133. while($value = mysql_fetch_array($sql)) {
  134. if($value['profils_valide']=='1') {
  135. $image_del = '<img src="'.$GLOBALS['IMG_valide'].'" alt="Actif" class="icone" onClick="jsArchiverProfil('.$value['profils_id'].',0);" />';
  136. }
  137. else {
  138. $image_del = '<img src="'.$GLOBALS['IMG_invalide'].'" alt="Inactif" class="icone" onClick="jsArchiverProfil('.$value['profils_id'].',1);" />';
  139. }
  140. $image_up = '<img src="'.$GLOBALS['IMG_modifier'].'" alt="Modifier" class="icone" />';
  141. $tableau .= '<tr>';
  142. $tableau .= '<td>'.$value['profils_id'].'</td>';
  143. $tableau .= '<td>'.$value['profils_libelle'].'</td>';
  144. $tableau .= '<td><img src="'.$GLOBALS['IMG_modifier'].'" alt="Modifier" class="icone" onClick="jsAfficherProfilById('.$value['profils_id'].');" /></td>';
  145. $tableau .= '<td>'.$image_del.'</td>';
  146. $tableau .= '</tr>';
  147. }
  148. if(mysql_num_rows($sql)<=0) {
  149. $reponse->assign('lbl_resultat','innerHTML','Aucun résultat');
  150. }
  151. else {
  152. $reponse->assign('tableProfil','innerHTML',$tableau);
  153. }
  154. return $reponse;
  155. }
  156. function getInputDroits($id) {
  157. $res = "<br>";
  158. if($id!="") {
  159. connexion();
  160. $sql = sql("SELECT *
  161. FROM nuxt_lien_droits_profils
  162. INNER JOIN nuxt_droits ON droits_id = l_droits_id
  163. WHERE droits_valide = 1
  164. AND l_profils_id = ".$id."
  165. ORDER BY droits_libelle;");
  166. deconnexion();
  167. while($value = mysql_fetch_array($sql)) {
  168. if($value['l_actif']==1) { $ch = "checked";} else { $ch = "";}
  169. $res .= "<input type='checkbox' name='droits[]' id='d".$value['droits_id']."' value='".$value['droits_id']."' ".$ch." />&nbsp;".lireBdd($value['droits_libelle'],false)."<br>";
  170. }
  171. }
  172. else {
  173. connexion();
  174. $sql = sql("SELECT * FROM nuxt_droits WHERE droits_valide = 1 ORDER BY droits_libelle; ");
  175. deconnexion();
  176. while($value = mysql_fetch_array($sql)) {
  177. $res .= "<input type='checkbox' name='droits[]' id='d".$value['droits_id']."' value='".$value['droits_id']."' />&nbsp;".lireBdd($value['droits_libelle'],false)."<br>";
  178. }
  179. }
  180. return $res;
  181. }
  182. ?>