Advertisement
Guest User

tmp004

a guest
Sep 18th, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 17.45 KB | None | 0 0
  1. <?php
  2. //error_reporting(0);
  3. class editUser {
  4.     function getGroupname($id)
  5.     {
  6. include("bdd.php");
  7. $sql = "SELECT * FROM users WHERE ID='$id'";
  8. $req = $bdd->prepare($sql);
  9. if($req == false)
  10. {
  11.     print_r($req->errorInfo());
  12.     die("error");
  13. }
  14. $req->execute();
  15. if($req == false)
  16. {
  17.     print_r($req->errorInfo());
  18.     die("error");
  19. }
  20. $results = $req->fetchAll();
  21. foreach($results as $row)
  22. {
  23.     return $row['user_group'];
  24. }
  25.  
  26.     }
  27.    
  28.     function chkPerm($array, $group){
  29.             if (in_array($group, $array)) {
  30.                     return true;
  31.             }else{
  32.                 return false;
  33.             }
  34.         }
  35.         function getColor($group){
  36.             include("bdd.php");
  37.             $sql = "SELECT * FROM groups WHERE name='$group'";
  38. $query = $bdd->prepare( $sql );
  39.     if ($query == false) {
  40.      
  41.      echo ("<center>
  42.     <img src='http://www.clipartbest.com/cliparts/yck/M6X/yckM6Xygi.png' width=20% height=20%>
  43.     <p>
  44.     <h2>ERROR:</h2>
  45.     <h3>We had a fatal error. Please contact the developer and supply this information:</h3>
  46.     <h4>SQL ERROR: \"$sql\"</h4>
  47.     <h4>Details:</h4>
  48.     </p>
  49.     </center>");
  50. print_r($bdd->errorInfo());
  51. die();
  52.     }
  53.     $sth = $query->execute();
  54.     if ($sth == false) {
  55.       echo ("<center>
  56.     <img src='http://www.clipartbest.com/cliparts/yck/M6X/yckM6Xygi.png' width=20% height=20%>
  57.     <p>
  58.     <h2>ERROR:</h2>
  59.     <h3>We had a fatal error. Please contact the developer and supply this information:</h3>
  60.     <h4>SQL ERROR: \"$sql\"</h4>
  61.     <h4>Details:</h4>
  62.     </p>
  63.     </center>");
  64.     print_r($query->errorInfo());
  65.     die();
  66.     }
  67.    
  68.    
  69.     $results = $query->fetchAll();
  70.     foreach ($results as $row) {
  71.         return $row['color'];
  72.     }
  73.            
  74.         }
  75. function showUserList($filter, $name){
  76.     session_start();
  77.     $username = $_SESSION['name'];
  78.     include ("bdd.php");
  79. if($filter == true){
  80.     $sql = "SELECT * FROM users WHERE name LIKE '%".$name."%' AND name <> '$username'";
  81. }else{
  82.     $sql = "SELECT * FROM users WHERE name <> '$username'";
  83. }
  84.    
  85.    
  86.     $query = $bdd->prepare( $sql );
  87.     if ($query == false) {
  88.      
  89.      echo ("<center>
  90.     <img src='http://www.clipartbest.com/cliparts/yck/M6X/yckM6Xygi.png' width=20% height=20%>
  91.     <p>
  92.     <h2>ERROR:</h2>
  93.     <h3>We had a fatal error. Please contact the developer and supply this information:</h3>
  94.     <h4>SQL ERROR: \"$sql\"</h4>
  95.     <h4>Details:</h4>
  96.     </p>
  97.     </center>");
  98. print_r($bdd->errorInfo());
  99. die();
  100.     }
  101.     $sth = $query->execute();
  102.     if ($sth == false) {
  103.       echo ("<center>
  104.     <img src='http://www.clipartbest.com/cliparts/yck/M6X/yckM6Xygi.png' width=20% height=20%>
  105.     <p>
  106.     <h2>ERROR:</h2>
  107.     <h3>We had a fatal error. Please contact the developer and supply this information:</h3>
  108.     <h4>SQL ERROR: \"$sql\"</h4>
  109.     <h4>Details:</h4>
  110.     </p>
  111.     </center>");
  112.     print_r($query->errorInfo());
  113.     die();
  114.     }
  115.    
  116.    
  117.     $results = $query->fetchAll();
  118.     foreach ($results as $row) {
  119.     $name = $row['name'];
  120.     $id = $row['ID'];
  121.     $group = $row['user_group'];
  122.     $new = new editUser();
  123. $color = $new->getColor($group);
  124.     echo("
  125.    
  126.     <tr>
  127.         <td>$id</td>
  128.         <td>$name</td>
  129.         <td><font color='$color'>$group</font></td>
  130.     <td><a href='/admin/pages/includes/ajaxDel.php?id=$id' class='btn btn-danger' onClick='return confirm(`Are you sure?`)'><i class='fa fa-trash-o' aria-hidden='true'></i> Delete</a> <a href='?userEdit=$id&group=$group&edit=modal#tbl' class='btn btn-warning'><i class='fa fa-pencil' aria-hidden='true'></i> Edit user</a> <a href='?userEdit=$id&edit=pwd' class='btn btn-info'><i class='fa fa-key' aria-hidden='true'></i> Change password</a></td>
  131.     </tr>
  132.     ");
  133.    
  134.    
  135. }
  136. $count = $query->rowCount();
  137. if($count == 0){
  138.     echo("
  139.     <a href='#addModal' type='button' class='btn btn-primary btn-lg btn-block' data-toggle='modal'><i class='fa fa-plus-square' aria-hidden='true'></i> Add user</a>
  140.     <br />
  141.       <a href='/admin/edit-users/' type='button' class='btn btn-default btn-lg btn-block'><i class='fa fa-retweet' aria-hidden='true'></i> Refresh Results</a>
  142.       <br />
  143.     <div class='alert alert-danger'>
  144.  <strong><i class='fa fa-times' aria-hidden='true'></i></strong> No results found.
  145. </div>
  146.  
  147.    
  148.    
  149.     ");
  150. }else{
  151.         echo("
  152.     <a href='#addModal' type='button' class='btn btn-primary btn-lg btn-block' data-toggle='modal'><i class='fa fa-plus-square' aria-hidden='true'></i> Add user</a>
  153.     <br />
  154.       <a href='/admin/edit-users/' type='button' class='btn btn-default btn-lg btn-block'><i class='fa fa-retweet' aria-hidden='true'></i> Refresh Results</a>
  155.       <br />
  156.     <div class='alert alert-info'>
  157.  <strong><i class='fa fa-info-circle fa-1x' aria-hidden='true'></i></strong> Showing <strong>$count</strong> results.
  158. </div>
  159.  
  160.    
  161.    
  162.     ");
  163. }
  164. }
  165.     function delUser($id){
  166.         include ("bdd.php");
  167.         $sql =  "DELETE FROM users WHERE id='$id'";
  168.         $query = $bdd->prepare( $sql );
  169.     if ($query == false) {
  170.      
  171.      echo ("<center>
  172.     <img src='http://www.clipartbest.com/cliparts/yck/M6X/yckM6Xygi.png' width=20% height=20%>
  173.     <p>
  174.     <h2>ERROR:</h2>
  175.     <h3>We had a fatal error. Please contact the developer and supply this information:</h3>
  176.     <h4>SQL ERROR: \"$sql\"</h4>
  177.     <h4>Details:</h4>
  178.     </p>
  179.     </center>");
  180. print_r($bdd->errorInfo());
  181. die();
  182.     }
  183.     $sth = $query->execute();
  184.     if ($sth == false) {
  185.      
  186.      echo ("<center>
  187.     <img src='http://www.clipartbest.com/cliparts/yck/M6X/yckM6Xygi.png' width=20% height=20%>
  188.     <p>
  189.     <h2>ERROR:</h2>
  190.     <h3>We had a fatal error. Please contact the developer and supply this information:</h3>
  191.     <h4>SQL ERROR: \"$sql\"</h4>
  192.     <h4>Details:</h4>
  193.     </p>
  194.     </center>");
  195.     print_r($query->errorInfo());
  196.     die();
  197.     }
  198.     }
  199.     function updateUser($id, $name, $group){
  200.         include ("bdd.php");
  201.         $sql =  "UPDATE users SET name = '$name', user_group = '$group' WHERE ID='$id'";
  202.         $query = $bdd->prepare( $sql );
  203.     if ($query == false) {
  204.      
  205.      echo ("<center>
  206.     <img src='http://www.clipartbest.com/cliparts/yck/M6X/yckM6Xygi.png' width=20% height=20%>
  207.     <p>
  208.     <h2>ERROR:</h2>
  209.     <h3>We had a fatal error. Please contact the developer and supply this information:</h3>
  210.     <h4>SQL ERROR: \"$sql\"</h4>
  211.     <h4>Details:</h4>
  212.     </p>
  213.     </center>");
  214. print_r($bdd->errorInfo());
  215. die();
  216.     }
  217.     $sth = $query->execute();
  218.     if ($sth == false) {
  219.      
  220.      echo ("<center>
  221.     <img src='http://www.clipartbest.com/cliparts/yck/M6X/yckM6Xygi.png' width=20% height=20%>
  222.     <p>
  223.     <h2>ERROR:</h2>
  224.     <h3>We had a fatal error. Please contact the developer and supply this information:</h3>
  225.     <h4>SQL ERROR: \"$sql\"</h4>
  226.     <h4>Details:</h4>
  227.     </p>
  228.     </center>");
  229.     print_r($query->errorInfo());
  230.     die();
  231.     }
  232.     }
  233.     function getUserVals($id){
  234.         include ("bdd.php");
  235.         $sql =  "SELECT * FROM users WHERE ID='$id'";
  236.         $query = $bdd->prepare($sql);
  237.     if ($query == false) {
  238.      
  239.      echo ("<center>
  240.     <img src='http://www.clipartbest.com/cliparts/yck/M6X/yckM6Xygi.png' width=20% height=20%>
  241.     <p>
  242.     <h2>ERROR:</h2>
  243.     <h3>We had a fatal error. Please contact the developer and supply this information:</h3>
  244.     <h4>SQL ERROR: \"$sql\"</h4>
  245.     <h4>Details:</h4>
  246.     </p>
  247.     </center>");
  248. print_r($bdd->errorInfo());
  249. die();
  250.     }
  251.     $sth = $query->execute();
  252.     if ($sth == false) {
  253.    
  254.      echo ("<center>
  255.     <img src='http://www.clipartbest.com/cliparts/yck/M6X/yckM6Xygi.png' width=20% height=20%>
  256.     <p>
  257.     <h2>ERROR:</h2>
  258.     <h3>We had a fatal error. Please contact the developer and supply this information:</h3>
  259.     <h4>SQL ERROR: \"$sql\"</h4>
  260.     <h4>Details:</h4>
  261.     </p>
  262.     </center>");
  263.     print_r($query->errorInfo());
  264.     die();
  265.     }
  266.     $results = $query->fetchAll();
  267.     foreach ($results as $row) {
  268.         $name = $row['name'];
  269.         $group = $row['group'];
  270.     }
  271.    
  272.     return $name;
  273.     }
  274.     function addUser($name, $unSaltPass, $group, $salt){
  275.         include ("bdd.php");
  276.         $sql = "SELECT * FROM users WHERE name='$name'";
  277.     //$req = $bdd->prepare($sql);
  278.     //$req->execute();
  279.    
  280.        
  281.     $query = $bdd->prepare( $sql );
  282.     if ($query == false) {
  283.      
  284.      echo ("<center>
  285.     <img src='http://www.clipartbest.com/cliparts/yck/M6X/yckM6Xygi.png' width=20% height=20%>
  286.     <p>
  287.     <h2>ERROR:</h2>
  288.     <h3>We had a fatal error. Please contact the developer and supply this information:</h3>
  289.     <h4>SQL ERROR: \"$sql\"</h4>
  290.     <h4>Details:</h4>
  291.     </p>
  292.     </center>");
  293. print_r($bdd->errorInfo());
  294. die();
  295.     }
  296.     $sth = $query->execute();
  297.     if ($sth == false) {
  298.    
  299.      echo ("<center>
  300.     <img src='http://www.clipartbest.com/cliparts/yck/M6X/yckM6Xygi.png' width=20% height=20%>
  301.     <p>
  302.     <h2>ERROR:</h2>
  303.     <h3>We had a fatal error. Please contact the developer and supply this information:</h3>
  304.     <h4>SQL ERROR: \"$sql\"</h4>
  305.     <h4>Details:</h4>
  306.     </p>
  307.     </center>");
  308.     print_r($query->errorInfo());
  309.     die();
  310.     }
  311. $results = $query->fetchAll();
  312.     foreach($results as $row){
  313.         $name1 = $row['name'];
  314.     }
  315.    
  316.    
  317. $password = sha1($unSaltPass.$salt);
  318.  
  319.  
  320. $sql = "INSERT INTO users(name, password, user_group) values ('$name', '$password', '$group')";
  321.     //$req = $bdd->prepare($sql);
  322.     //$req->execute();
  323.    
  324.        
  325.     $query = $bdd->prepare( $sql );
  326.     if ($query == false) {
  327.      
  328.      echo ("<center>
  329.     <img src='http://www.clipartbest.com/cliparts/yck/M6X/yckM6Xygi.png' width=20% height=20%>
  330.     <p>
  331.     <h2>ERROR:</h2>
  332.     <h3>We had a fatal error. Please contact the developer and supply this information:</h3>
  333.     <h4>SQL ERROR: \"$sql\"</h4>
  334.     <h4>Details:</h4>
  335.     </p>
  336.     </center>");
  337. print_r($bdd->errorInfo());
  338. die();
  339.     }
  340.     $sth = $query->execute();
  341.     if ($sth == false) {
  342.    
  343.      echo ("<center>
  344.     <img src='http://www.clipartbest.com/cliparts/yck/M6X/yckM6Xygi.png' width=20% height=20%>
  345.     <p>
  346.     <h2>ERROR:</h2>
  347.     <h3>We had a fatal error. Please contact the developer and supply this information:</h3>
  348.     <h4>SQL ERROR: \"$sql\"</h4>
  349.     <h4>Details:</h4>
  350.     </p>
  351.     </center>");
  352.     print_r($query->errorInfo());
  353.     die();
  354.     }
  355.     }
  356.     function changePwd($id, $unSaltPass, $salt){
  357.         include ("bdd.php");
  358.         include ("gatherPermissions.php");
  359.         $user = new editUser();
  360.        
  361.        
  362. $password = sha1($unSaltPass.$salt);
  363.  
  364.  
  365. $sql = "UPDATE users SET password = '$password' WHERE ID='$id'";
  366.     $query = $bdd->prepare( $sql );
  367.     if ($query == false) {
  368.      
  369.      echo ("<center>
  370.     <img src='http://www.clipartbest.com/cliparts/yck/M6X/yckM6Xygi.png' width=20% height=20%>
  371.     <p>
  372.     <h2>ERROR:</h2>
  373.     <h3>We had a fatal error. Please contact the developer and supply this information:</h3>
  374.     <h4>SQL ERROR: \"$sql\"</h4>
  375.     <h4>Details:</h4>
  376.     </p>
  377.     </center>");
  378. print_r($bdd->errorInfo());
  379. die();
  380.     }
  381.     $sth = $query->execute();
  382.     if ($sth == false) {
  383.    
  384.      echo ("<center>
  385.     <img src='http://www.clipartbest.com/cliparts/yck/M6X/yckM6Xygi.png' width=20% height=20%>
  386.     <p>
  387.     <h2>ERROR:</h2>
  388.     <h3>We had a fatal error. Please contact the developer and supply this information:</h3>
  389.     <h4>SQL ERROR: \"$sql\"</h4>
  390.     <h4>Details:</h4>
  391.     </p>
  392.     </center>");
  393.     print_r($query->errorInfo());
  394.     die();
  395.     }
  396.     }
  397.    
  398.    
  399.     function checkLevel($currentUsername,$requested_group){
  400.         include ("bdd.php");
  401.         //Get user info
  402. $sql = "SELECT * FROM users WHERE name='$currentUsername'";
  403. $req = $bdd->prepare($sql);
  404. if($req == false)
  405. {
  406.     print_r($req->errorInfo());
  407.     die("error");
  408. }
  409. $req->execute();
  410. if($req == false)
  411. {
  412.     print_r($req->errorInfo());
  413.     die("error");
  414. }
  415. $results = $req->fetchAll();
  416. foreach($results as $row)
  417. {
  418.     $userGroupCurrent = $row['user_group'];
  419. }
  420.  
  421. //Get Requested group Level
  422. $sql = "SELECT * FROM groups WHERE name='$requested_group'";
  423. $req = $bdd->prepare($sql);
  424. if($req == false)
  425. {
  426.     print_r($req->errorInfo());
  427.     die("error");
  428. }
  429. $req->execute();
  430. if($req == false)
  431. {
  432.     print_r($req->errorInfo());
  433.     die("error");
  434. }
  435. $results = $req->fetchAll();
  436. foreach($results as $row)
  437. {
  438.     $reqGroupLevel = $row['level'];
  439. }
  440. //Get current user group level
  441. $sql = "SELECT * FROM groups WHERE name='$userGroupCurrent'";
  442. $req = $bdd->prepare($sql);
  443. if($req == false)
  444. {
  445.     print_r($req->errorInfo());
  446.     die("error");
  447. }
  448. $req->execute();
  449. if($req == false)
  450. {
  451.     print_r($req->errorInfo());
  452.     die("error");
  453. }
  454. $results = $req->fetchAll();
  455. foreach($results as $row)
  456. {
  457.     $currentGroupLevel = $row['level'];
  458. }
  459.     if($currentGroupLevel > $reqGroupLevel)
  460.     {
  461.         return false;
  462.     }else{
  463.         return true;
  464.     }
  465.    
  466.     }
  467.    
  468.    
  469.    
  470. }
  471. class editGroup{
  472.    
  473.     function listGroups($filter, $name){
  474.        
  475.         include ("bdd.php");
  476.         include ("gatherPermissions.php");
  477.         if($filter == true){
  478.     $sql = "SELECT * FROM groups WHERE name LIKE '%".$name."%' AND name <> 'not_assigned' ORDER BY level ASC";
  479. }else{
  480.     $sql = "SELECT * FROM groups WHERE name <> 'not_assigned' ORDER BY level ASC";
  481. }
  482.    
  483.    
  484.     $query = $bdd->prepare( $sql );
  485.     if ($query == false) {
  486.      
  487.      echo ("<center>
  488.     <img src='http://www.clipartbest.com/cliparts/yck/M6X/yckM6Xygi.png' width=20% height=20%>
  489.     <p>
  490.     <h2>ERROR:</h2>
  491.     <h3>We had a fatal error. Please contact the developer and supply this information:</h3>
  492.     <h4>SQL ERROR: \"$sql\"</h4>
  493.     <h4>Details:</h4>
  494.     </p>
  495.     </center>");
  496. print_r($bdd->errorInfo());
  497. die();
  498.     }
  499.     $sth = $query->execute();
  500.     if ($sth == false) {
  501.       echo ("<center>
  502.     <img src='http://www.clipartbest.com/cliparts/yck/M6X/yckM6Xygi.png' width=20% height=20%>
  503.     <p>
  504.     <h2>ERROR:</h2>
  505.     <h3>We had a fatal error. Please contact the developer and supply this information:</h3>
  506.     <h4>SQL ERROR: \"$sql\"</h4>
  507.     <h4>Details:</h4>
  508.     </p>
  509.     </center>");
  510.     print_r($query->errorInfo());
  511.     die();
  512.     }
  513.    
  514.    
  515.     $results = $query->fetchAll();
  516.     $count= $query->rowCount();
  517.     if($count < 1){
  518.         echo("
  519.         <div class='alert alert-danger'>
  520.  <strong><i class='fa fa-times' aria-hidden='true'></i></strong> No results found.
  521. </div>
  522.        
  523.         ");
  524.     }else{
  525.         echo("<div class='alert alert-info'>
  526.  <strong><i class='fa fa-info-circle fa-1x' aria-hidden='true'></i></strong> Showing <strong>$count</strong> results.
  527. </div>");
  528.        
  529.     }
  530.     foreach ($results as $row) {
  531.     $name = $row['name'];
  532.     $id = $row['ID'];
  533.     $color = $row['color'];
  534.     $level = $row['level'];
  535.     $desc = $row['description'];
  536.     $currentGroupLevel = $userPerm['level'];
  537.     $reqGroupLevel = $row['level'];
  538.     if($currentGroupLevel > $reqGroupLevel)
  539.     {
  540.     echo("
  541.    
  542.     <tr>
  543.         <td>$id</td>
  544.         <td><font color='$color'>$name</font></td>
  545.         <td><span class='label label-danger'>$level</span></td>
  546.         <td>$desc</td>
  547.         <td><a href='#' data-toggle='modal' data-target='#delModal' class='btn btn-danger' onClick='confirmDel($id)'><i class='fa fa-trash-o' aria-hidden='true'></i> Delete</a>
  548.         <a href='edit-group-perms/$id/' class='btn btn-default'>
  549.         <i class='fa fa-shield' aria-hidden='true'></i> View/Edit Permissions</a>
  550.         <a href='#' data-toggle='modal' data-target='#lvModal' class='btn btn-info'><i class='fa fa-bars' aria-hidden='true'></i> Edit Group order...</a>
  551.             <a href='#' data-toggle='modal' onClick='setId(`$id`,`$name`,`$color`)' data-target='#editModal' class='btn btn-info'><i class='fa fa-pencil' aria-hidden='true'></i> Edit Other Properties</a>
  552.         </td>
  553.     </tr>
  554.     ");
  555.     }else if($userPerm['level'] <= $level){
  556.         echo("
  557.    
  558.     <tr>
  559.         <td>$id</td>
  560.         <td><font color='$color'>$name</font></td>
  561.         <td><span class='label label-success'>$level</span></td>
  562.         <td>$desc</td>
  563.         <td><a href='#' data-toggle='modal' data-target='#delModal' onClick='confirmDel($id)' class='btn btn-danger' ><i class='fa fa-trash-o' aria-hidden='true' ></i> Delete</a>
  564.         <a href='edit-group-perms/$id/' class='btn btn-default'>
  565.         <i class='fa fa-shield' aria-hidden='true'></i> View/Edit Permissions</a>
  566.         <a href='#' data-toggle='modal'  data-target='#lvModal' class='btn btn-info'><i class='fa fa-bars' aria-hidden='true'></i> Edit Group order...</a>
  567.             <a href='#' data-toggle='modal' onClick='setId(`$id`,`$name`,`$color`)' data-target='#editModal' class='btn btn-info'><i class='fa fa-pencil' aria-hidden='true'></i> Edit Other Properties</a>
  568.         </td>
  569.     </tr>
  570.     ");
  571.        
  572.     }
  573.    
  574.     }
  575.     ?>
  576.     <script>
  577. function setId(id,name,color){
  578. $("#Editname").val(name);
  579. $("#Editcolor").val(color);
  580. $("#Editid").val(id);
  581. }
  582. </script>
  583.     <?php
  584.    
  585.        
  586.     }
  587.     function delGroup($id,$old)
  588.     {
  589.         include("bdd.php");
  590.     $sql =  "DELETE FROM groups WHERE id='$id'";
  591.     $req = $bdd->prepare($sql);
  592.     if($req == false)
  593.     {
  594.         die("ERR");
  595.     }
  596.     $sth = $req->execute();
  597.     if($sth == false)
  598.     {
  599.         die("ERR");
  600.     }
  601.     $sql =  "UPDATE users SET user_group = 'not_assigned' WHERE user_group='$old'";
  602.     $req = $bdd->prepare($sql);
  603.     if($req == false)
  604.     {
  605.         die("ERR");
  606.     }
  607.     $sth = $req->execute();
  608.     if($sth == false)
  609.     {
  610.         die("ERR");
  611.     }
  612.     return true;
  613.     }
  614.     function chkPerm($array, $group){
  615.             if (in_array($group, $array)) {
  616.                     return true;
  617.             }else{
  618.                 return false;
  619.             }
  620.         }
  621.     function updateGroup($name,$color,$id){
  622.        
  623.         include("bdd.php");
  624.         $sql = "SELECT * FROM groups WHERE ID='$id'";
  625.         $req = $bdd->prepare($sql);
  626.         if($req == false)
  627.         {
  628.             print_r($req->errorInfo());
  629.             die("Error");
  630.         }
  631.        
  632.         $req->execute();
  633.        
  634.         if($req == false)
  635.         {
  636.             print_r($req->errorInfo());
  637.             die("Error");
  638.         }
  639.         $result =  $req->fetchAll();
  640.         foreach($result as $row)
  641.         {
  642.             $old_group = $row['name'];
  643.         }
  644.         $name = htmlspecialchars($name);
  645.         $sql = "UPDATE groups SET name='$name', color='$color' WHERE ID='$id'";
  646.         $req = $bdd->prepare($sql);
  647.         if($req == false)
  648.         {
  649.             print_r($req->errorInfo());
  650.             die("Error");
  651.         }
  652.        
  653.         $req->execute();
  654.         if($req == false)
  655.         {
  656.             print_r($req->errorInfo());
  657.             die("Error");
  658.         }
  659.        
  660.        
  661.         $sql = "UPDATE users SET user_group = '$name' WHERE user_group='$old_group'";
  662.         $req = $bdd->prepare($sql);
  663.        
  664.         if($req == false)
  665.         {
  666.             print_r($req->errorInfo());
  667.             die("Error");
  668.         }
  669.        
  670.         $req->execute();
  671.         if($req == false)
  672.         {
  673.             print_r($req->errorInfo());
  674.             die("Error");
  675.         }
  676.         $_SESSION['msg_success'] = "Updated group";
  677.         return true;
  678.     }
  679.     function getGroupname($id)
  680.     {
  681. include("bdd.php");
  682. $sql = "SELECT * FROM groups WHERE ID='$id'";
  683. $req = $bdd->prepare($sql);
  684. if($req == false)
  685. {
  686.     print_r($req->errorInfo());
  687.     die("error");
  688. }
  689. $req->execute();
  690. if($req == false)
  691. {
  692.     print_r($req->errorInfo());
  693.     die("error");
  694. }
  695. $results = $req->fetchAll();
  696. foreach($results as $row)
  697. {
  698.     return $row['name'];
  699. }
  700.  
  701.     }
  702.    
  703. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement