Source for file usermanagement.php

Documentation is available at usermanagement.php

  1. <?php
  2. /**
  3. * User management
  4. * <br/><br/>
  5. * Frame script for user management
  6. * <br/><br/>
  7. * Access restricted to administrators and members of group "Management"
  8. @author Gabriele Droege, DNA Bank Network <contact@dnabank-network.org>
  9. @version 2.0
  10. @package Configuration
  11. @copyright Copyright © 2011 DNA Bank Network http://www.dnabank-network.org<br>The contents of this file are subject to the Mozilla Public License Version 1.1
  12. @filesource
  13. @license http://www.mozilla.org/MPL/ MPL
  14. */
  15.  
  16.      /**
  17.     * calling connection to database
  18.     */
  19.     include ("../config/head.php");
  20.  
  21.     /**
  22.     * calling authorisation script
  23.     */
  24.     include ("../auth.php");
  25. ?>
  26. <html>
  27.  
  28. <head>
  29. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  30. <title>DNA Module - User management</title>
  31. <link rel="stylesheet" type="text/css" href="../format.css">
  32. <link rel="stylesheet" type="text/css" href="../input/XSLT/Styles.css">
  33. <SCRIPT LANGUAGE="JavaScript1.1" src="../Functions.js"></SCRIPT>
  34. <NOSCRIPT>Please enable Javascript!</NOSCRIPT>
  35.  
  36. </head>
  37.  
  38. <body>
  39. <div align="center">
  40. <?php
  41.    
  42.     /**
  43.     * including navigation menu
  44.     */
  45.     include("../tablenavi.php")?>
  46.     
  47. <form name="formular" method="POST" action="usermanagement.php">
  48. <table id="tablemain" class="main">
  49.     <tr>
  50.   <td id="tdLogo"><img border="0" href="<?php echo $Path_Wiki?>" src="../images/Logo-DNA-Bank-Network-ocker.jpg" width="123" height="78"></td>
  51.         <td id="tdtitle">
  52.         <h1>Configuration Tool<br />User Management</h1></td>
  53.     <td id="tdLogo2"><?php echo $Path_Logo?></td>
  54.     </tr>
  55.   <tr>
  56.   <td colspan="4"><?php
  57.     echo "Logged in as: ";
  58.     $log $_SESSION["log"];
  59.     echo $log;
  60.     ?></td></tr>
  61.     <tr>
  62.         <td colspan="3" valign="top">
  63.         <table border="0" id="table2">
  64.     <?php
  65.     
  66.     /********************************************************************************************
  67.     * login as Administrator or memeber of Management group required                            *
  68.     * feature: "Add new user"                                                                   *
  69.     *  START                                                                                    *
  70.     *********************************************************************************************/
  71.     
  72.     if (isset($_SESSION['admin']|| $_SESSION['admin'|| isset($_SESSION['management']|| $_SESSION['management']{
  73.     
  74.     if($formSubmitChange and $formAction == "add"{
  75.  
  76. if($formAction == "add" or $formSubmitSaveUser)
  77.     /**
  78.     * including script for adding new user
  79.     */
  80.     include("new_user.php");}
  81.  
  82.     }
  83.     /********************************************************************************************
  84.     * feature: "Add new user"                                                                   *
  85.     *  END                                                                                      *
  86.     *********************************************************************************************/
  87.     
  88.     
  89.     if($formSubmitSave{
  90.  
  91.  
  92.      $ID_User $_POST['formPeople'];
  93.      $Group $_POST['group'];
  94.      $Login $_POST['formLogin'];
  95.      $Email $_POST['formEmail'];
  96.      $sql "UPDATE user SET ID_Group = '$Group', Login = '$Login', Email = '$Email' WHERE ID_User = '$ID_User'";
  97.      $result mysql_query($sql);
  98.     
  99.      if($result{
  100.      
  101.      echo "<tr><td colspan='4'><span class='fine'>Changes accepted!</span></td></tr>";      }
  102.      else echo "<tr><td colspan='4'><span class='error'>Changes not accepted!</span></td></tr>"}
  103.     
  104.     
  105.     // if($formSubmitSave)
  106.     
  107.     
  108.  
  109.     ?>
  110.     
  111.     <?php
  112.     
  113.     /********************************************************************************************
  114.     * login as Administrator or memeber of Management group required                            *
  115.     * feature: "Change user settings"                                                           *
  116.     *  START                                                                                    *
  117.     *********************************************************************************************/
  118.     
  119.    if($formSubmitChange and $formAction == "change"{
  120.  
  121.     if($_POST['user']=="")
  122.      unset($_POST['user'])
  123.      echo "<tr><td colspan='3'><span class='error'>Please select an user.</span></td></tr>"
  124.      $UserCheck "true";}
  125.   
  126.   else 
  127.     
  128.     echo "<tr><td colspan='3'><h3>Please change group, login name or email for selected user.</h3></td></tr>"
  129.     echo "<tr><td colspan='3'><table id='table1'><th></th><th>Signature</th><th>Login Name</th><th>Email</th><th>Group</th>";
  130.  
  131.     foreach ($_POST['user'as $index)
  132.       
  133.       $ID_User $_POST['formPeople'][$index];
  134.       $sql "SELECT user.ID_User, user.Signature, user.Login, user.Email, usergroups.Group FROM user LEFT JOIN usergroups ON 
  135.       user.ID_Group = usergroups.ID_Group WHERE user.ID_User = '$ID_User'";
  136.  
  137.       $result mysql_query($sql);
  138.     
  139.       while($row mysql_fetch_object($result))
  140.       
  141.       echo "<tr><td><input type='hidden' name='formPeople' value='".$row->ID_User."'></td><td>".$row->Signature."</td><td><input type='text' name='formLogin' value='".$row->Login."'></td><td><input type='text' name='formEmail' value='".$row->Email."'></td><td>"
  142.     echo "<select name='group'><option value=''>-------</option>
  143.      <option value='1'";
  144.      if($row->Group == "Administrator"echo " selected"}
  145.      echo ">Administrators</option>
  146.      <option value='2'";
  147.       if($row->Group == "DNA Bank Team"echo " selected"}
  148.      echo ">DNA Bank Team</option>
  149.      <option value='3'";
  150.       if($row->Group == "Project"echo " selected"}
  151.      echo ">Project Members</option>
  152.      <option value='4'";
  153.       if($row->Group == "Guest"echo " selected"}
  154.      echo ">Guests</option>
  155.      </select>";
  156.          echo "</td></tr>";     }}
  157.        echo "<tr><td></td><td colspan='2' align='right'><input type='submit' name='formSubmitSave' value='Save Edits' class='button'/></td></tr></table></td></tr>"}
  158.     }
  159.     
  160.     /********************************************************************************************
  161.     * feature: "Change user settings"                                                           *
  162.     * END                                                                                       *
  163.     *********************************************************************************************/
  164.     
  165.     /********************************************************************************************
  166.     * login as Administrator or memeber of Management group required                            *
  167.     * feature: "Delete user"                                                                    *
  168.     * START                                                                                     *
  169.     *********************************************************************************************/
  170.         
  171.  if($formSubmitChange and $formAction == "delete"{
  172.  
  173.     if($_POST['user']=="")
  174.      unset($_POST['user'])
  175.      echo "<tr><td colspan='3'><span class='error'>Please select an user.</span></td></tr>"
  176.      $UserCheck "true";}
  177.   
  178.   else 
  179.     
  180.      foreach ($_POST['user'as $index)
  181.       
  182.       $ID_User $_POST['formPeople'][$index];
  183.       $Signature $_POST['formSignaturehidden'][$index];
  184.       
  185.       $sqldna "SELECT ID_DNA FROM dnabanknumbers WHERE Created_Who = '$Signature'";
  186.       $resultdna mysql_query($sqldna);
  187.       $countdna mysql_num_rows($resultdna);
  188.       $sqlspecimen "SELECT ID_Collection FROM sptoolcollection WHERE Created_Who = '$Signature'";
  189.       $resultspecimen mysql_query($sqlspecimen);
  190.       $countspecimen mysql_num_rows($resultspecimen);
  191.       
  192.       /********************************************************************************************
  193.       * check if user is creator of DNA or specimen records                                       *
  194.       * user can only be deleted when he/she doesn't have created records                         *
  195.       *********************************************************************************************/
  196.       
  197.       if($countdna == "0" and $countspecimen == "0"{
  198.       
  199.       $sql "DELETE FROM user WHERE ID_User = '$ID_User'";
  200.       $result mysql_query($sql);        
  201.       if($sqlecho "<tr><td colspan='3'><span class='fine'>User successfully deleted.</span></td></tr>";  
  202.                  $UserCheck "true"}
  203.       if(!$sqlecho "<tr><td colspan='3'><span class='error'>User can't be deleted.</span></td></tr>";
  204.                   $UserCheck "true";   }
  205.                   }
  206.       else echo "<tr><td colspan='3'><span class='error'>User ".$Signature." can't be deleted, since he/her has created records. You can change his/her group membership instead.</span></td></tr>"
  207. $UserCheck "true"}}
  208.     }} 
  209.       /********************************************************************************************
  210.       * feature: "Delete user"                                                                    *
  211.       * END                                                                                       *
  212.       *********************************************************************************************/
  213.     
  214.        
  215.       /********************************************************************************************
  216.       * login as Administrator or memeber of Management group required                            *
  217.       * Start page, listing all registered user and number of created records                     *
  218.       *  START                                                                                    *
  219.       *********************************************************************************************/
  220.     
  221.     
  222.     if(!$formSubmitChange or $formSubmitSave or $UserCheck == "true"{
  223.    
  224.     
  225.     $sqlcheck "SELECT * from user where ID_Group = '1'";
  226.     $resultcheck mysql_query($sqlcheck);
  227.     $count mysql_num_rows($resultcheck);
  228.     
  229.           if($count == 1while($rowcheck =  mysql_fetch_object($resultcheck)) {
  230.           $UserCheck $rowcheck->ID_User}}
  231.     
  232.     $sql "SELECT user.ID_User, user.Signature, user.Login, user.Email, usergroups.Group FROM user LEFT JOIN usergroups ON 
  233.     user.ID_Group = usergroups.ID_Group ORDER BY usergroups.Group";
  234.     $result mysql_query($sql);
  235.     
  236.     if($result{
  237.     echo "<tr><td colspan='3'><h3>The following users are registered to the DNA Module:</h3></td></tr>";
  238.     echo "<tr><td colspan='3'><table id='table1'><th></th><th>Signature</th><th>Login Name</th><th>Email</th><th>Group</th><th>DNA entries</th><th>Specimen entries</th>";
  239.  
  240.     $gesamt mysql_num_rows($result);
  241.       
  242.     for ($i=1$i<=$gesamt$i++{
  243.     $row=mysql_fetch_array($result);
  244.     {
  245.     
  246.     $Signature $row['Signature'];
  247.     $sqldna "SELECT ID_DNA FROM dnabanknumbers WHERE Created_Who = '$Signature'";
  248.     $resultdna mysql_query($sqldna);
  249.     $countdna mysql_num_rows($resultdna);
  250.     $sqlspecimen "SELECT ID_Collection FROM sptoolcollection WHERE Created_Who = '$Signature'";
  251.     $resultspecimen mysql_query($sqlspecimen);
  252.     $countspecimen mysql_num_rows($resultspecimen);
  253.     
  254.     if($row['Signature'== $log or $row['ID_User'== $UserCheck)
  255.     {echo "<tr><td></td><td>".$row['Signature']."</td><td>".$row['Login']."</td><td>".$row['Email']."</td><td>".$row['Group']."</td><td>".$countdna."</td><td>".$countspecimen."</td></tr>";  }
  256.     else {
  257.     echo "<tr><td><input type='radio' name='user[]' value='".$i."'><input type='hidden' name='formPeople[".$i."]' value='".$row['ID_User']."'></td><td><input type='hidden' name='formSignaturehidden[".$i."]' value='".$row['Signature']."'>".$row['Signature']."</td><td>".$row['Login']."</td><td>".$row['Email']."</td><td>".$row['Group']."</td><td><input type='hidden' name='countdna[".$i."]' value='".$countdna."'>".$countdna."</td><td><input type='hidden' name='countspecimen[".$i."]' value='".$countspecimen."'>".$countspecimen."</td></tr>"}
  258. }}
  259.     
  260.      echo "<tr><td>Choose action:</td><td>
  261.      <select name='formAction'><option value=''>-------</option>
  262.      <option value='change'>Edit User</option>
  263.      <option value='delete'>Delete User</option>
  264.      <option value='add'>Add User</option>
  265.      </select></td>
  266.      <td colspan='2' align='right'>
  267.      <input type='submit' value='Action' name='formSubmitChange' class='button' onclick='return checkAction();'></td></tr>";
  268.      
  269.      echo "</table></td></tr>"
  270.  
  271.     }
  272.     // if(!$formSubmitChange)
  273.     
  274.       /********************************************************************************************
  275.       * Start page                                                                                *
  276.       * END                                                                                       *
  277.       *********************************************************************************************/
  278.     
  279.     }
  280.     
  281.       /**
  282.       * message permission denied for non administrators or managers
  283.       */
  284.           
  285.     if (!isset($_SESSION['admin']&& !$_SESSION['admin'&& !isset($_SESSION['management']&& !$_SESSION['management']echo '<tr>
  286.       <td id="DescriptionBlack" colspan="2"></td>';
  287.       include("../No_permission.php");
  288.       echo '</td></tr>'}
  289.     
  290.     ?>
  291.       <tr>
  292.       <td id="DescriptionBlack" colspan="2"></td>
  293.       <td align="right"><input type="button" 
  294.       <?php  if($formSubmitChange and ($formAction == "change" or $formAction == "add"))
  295.       echo 'value="Cancel" name="formSubmitMenu" id="SelectLong" onClick="self.location.href = \'usermanagement.php\';">'}      
  296.       else echo 'value="Return to Configuration Tool" name="formSubmitMenu" id="SelectLong" onClick="self.location.href = \'configuration.php\';">'?></td>
  297.     </tr>
  298.             </table>
  299.         </td>
  300.     </tr>
  301. </table>
  302. <?php
  303.     /**
  304.     * including footer
  305.     */
  306.     include ("../footer.php")?>
  307.     
  308. </div>
  309. </form>
  310. </body>
  311.  
  312. </html>

Documentation generated on Tue, 29 Nov 2011 10:45:20 +0100 by phpDocumentor 1.4.3