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.     /**
  79.     * including script for adding new user
  80.     */
  81.     include("new_user.php");}
  82.  
  83.     }
  84.     /********************************************************************************************
  85.     * feature: "Add new user"                                                                   *
  86.     *  END                                                                                      *
  87.     *********************************************************************************************/
  88.     
  89.     
  90.     if($formSubmitSave) {
  91.  
  92.  
  93.      $ID_User = $_POST['formPeople'];
  94.      $Group = $_POST['group'];
  95.      $Login = $_POST['formLogin'];
  96.      $Email = $_POST['formEmail'];
  97.      $sql = "UPDATE user SET ID_Group = '$Group', Login = '$Login', Email = '$Email' WHERE ID_User = '$ID_User'";
  98.      $result = mysql_query($sql);
  99.     
  100.      if($result) {
  101.      
  102.      echo "<tr><td colspan='4'><span class='fine'>Changes accepted!</span></td></tr>";      }
  103.      else { echo "<tr><td colspan='4'><span class='error'>Changes not accepted!</span></td></tr>"; }
  104.     
  105.     
  106.     } // if($formSubmitSave)
  107.     
  108.     
  109.  
  110.     ?>
  111.     
  112.     <?php
  113.     
  114.     /********************************************************************************************
  115.     * login as Administrator or memeber of Management group required                            *
  116.     * feature: "Change user settings"                                                           *
  117.     *  START                                                                                    *
  118.     *********************************************************************************************/
  119.     
  120.    if($formSubmitChange and $formAction == "change") {
  121.  
  122.     if($_POST['user']=="")
  123.      { unset($_POST['user']); 
  124.      echo "<tr><td colspan='3'><span class='error'>Please select an user.</span></td></tr>"; 
  125.      $UserCheck = "true";}
  126.   
  127.   else 
  128.     { 
  129.     echo "<tr><td colspan='3'><h3>Please change group, login name or email for selected user.</h3></td></tr>"; 
  130.     echo "<tr><td colspan='3'><table id='table1'><th></th><th>Signature</th><th>Login Name</th><th>Email</th><th>Group</th>";
  131.  
  132.     foreach ($_POST['user'] as $index)
  133.       { 
  134.       $ID_User = $_POST['formPeople'][$index];
  135.       $sql = "SELECT user.ID_User, user.Signature, user.Login, user.Email, usergroups.Group FROM user LEFT JOIN usergroups ON 
  136.       user.ID_Group = usergroups.ID_Group WHERE user.ID_User = '$ID_User'";
  137.  
  138.       $result = mysql_query($sql);
  139.     
  140.       while($row = mysql_fetch_object($result))
  141.       { 
  142.       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>"; 
  143.     echo "<select name='group'><option value=''>-------</option>
  144.      <option value='1'";
  145.      if($row->Group == "Administrator") { echo " selected"; }
  146.      echo ">Administrators</option>
  147.      <option value='2'";
  148.       if($row->Group == "DNA Bank Team") { echo " selected"; }
  149.      echo ">DNA Bank Team</option>
  150.      <option value='3'";
  151.       if($row->Group == "Project") { echo " selected"; }
  152.      echo ">Project Members</option>
  153.      <option value='4'";
  154.       if($row->Group == "Guest") { echo " selected"; }
  155.      echo ">Guests</option>
  156.      </select>";
  157.          echo "</td></tr>";     }}
  158.        echo "<tr><td></td><td colspan='2' align='right'><input type='submit' name='formSubmitSave' value='Save Edits' class='button'/></td></tr></table></td></tr>"; }
  159.     }
  160.     
  161.     /********************************************************************************************
  162.     * feature: "Change user settings"                                                           *
  163.     * END                                                                                       *
  164.     *********************************************************************************************/
  165.     
  166.     /********************************************************************************************
  167.     * login as Administrator or memeber of Management group required                            *
  168.     * feature: "Delete user"                                                                    *
  169.     * START                                                                                     *
  170.     *********************************************************************************************/
  171.         
  172.  if($formSubmitChange and $formAction == "delete") {
  173.  
  174.     if($_POST['user']=="")
  175.      { unset($_POST['user']); 
  176.      echo "<tr><td colspan='3'><span class='error'>Please select an user.</span></td></tr>"; 
  177.      $UserCheck = "true";}
  178.   
  179.   else 
  180.     { 
  181.      foreach ($_POST['user'] as $index)
  182.       { 
  183.       $ID_User = $_POST['formPeople'][$index];
  184.       $Signature = $_POST['formSignaturehidden'][$index];
  185.       
  186.       $sqldna = "SELECT ID_DNA FROM dnabanknumbers WHERE Created_Who = '$Signature'";
  187.       $resultdna = mysql_query($sqldna);
  188.       $countdna = mysql_num_rows($resultdna);
  189.       $sqlspecimen = "SELECT ID_Collection FROM sptoolcollection WHERE Created_Who = '$Signature'";
  190.       $resultspecimen = mysql_query($sqlspecimen);
  191.       $countspecimen = mysql_num_rows($resultspecimen);
  192.       
  193.       /********************************************************************************************
  194.       * check if user is creator of DNA or specimen records                                       *
  195.       * user can only be deleted when he/she doesn't have created records                         *
  196.       *********************************************************************************************/
  197.       
  198.       if($countdna == "0" and $countspecimen == "0") {
  199.       
  200.       $sql = "DELETE FROM user WHERE ID_User = '$ID_User'";
  201.       $result = mysql_query($sql);        
  202.       if($sql) { echo "<tr><td colspan='3'><span class='fine'>User successfully deleted.</span></td></tr>";  
  203.                  $UserCheck = "true"; }
  204.       if(!$sql) { echo "<tr><td colspan='3'><span class='error'>User can't be deleted.</span></td></tr>";
  205.                   $UserCheck = "true";   }
  206.                   }
  207.       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>"; 
  208. $UserCheck = "true"; }}
  209.     }} 
  210.       /********************************************************************************************
  211.       * feature: "Delete user"                                                                    *
  212.       * END                                                                                       *
  213.       *********************************************************************************************/
  214.     
  215.        
  216.       /********************************************************************************************
  217.       * login as Administrator or memeber of Management group required                            *
  218.       * Start page, listing all registered user and number of created records                     *
  219.       *  START                                                                                    *
  220.       *********************************************************************************************/
  221.     
  222.     
  223.     if(!$formSubmitChange or $formSubmitSave or $UserCheck == "true") {
  224.    
  225.     
  226.     $sqlcheck = "SELECT * from user where ID_Group = '1'";
  227.     $resultcheck = mysql_query($sqlcheck);
  228.     $count = mysql_num_rows($resultcheck);
  229.     
  230.           if($count == 1) { while($rowcheck =  mysql_fetch_object($resultcheck)) {
  231.           $UserCheck = $rowcheck->ID_User; }}
  232.     
  233.     $sql = "SELECT user.ID_User, user.Signature, user.Login, user.Email, usergroups.Group FROM user LEFT JOIN usergroups ON 
  234.     user.ID_Group = usergroups.ID_Group ORDER BY usergroups.Group";
  235.     $result = mysql_query($sql);
  236.     
  237.     if($result) {
  238.     echo "<tr><td colspan='3'><h3>The following users are registered to the DNA Module:</h3></td></tr>";
  239.     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>";
  240.  
  241.     $gesamt = mysql_num_rows($result);
  242.       
  243.     for ($i=1; $i<=$gesamt; $i++) {
  244.     $row=mysql_fetch_array($result);
  245.     {
  246.     
  247.     $Signature = $row['Signature'];
  248.     $sqldna = "SELECT ID_DNA FROM dnabanknumbers WHERE Created_Who = '$Signature'";
  249.     $resultdna = mysql_query($sqldna);
  250.     $countdna = mysql_num_rows($resultdna);
  251.     $sqlspecimen = "SELECT ID_Collection FROM sptoolcollection WHERE Created_Who = '$Signature'";
  252.     $resultspecimen = mysql_query($sqlspecimen);
  253.     $countspecimen = mysql_num_rows($resultspecimen);
  254.     
  255.     if($row['Signature'] == $log or $row['ID_User'] == $UserCheck)
  256.     {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>";  }
  257.     else {
  258.     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>"; }
  259. }}
  260.     
  261.      echo "<tr><td>Choose action:</td><td>
  262.      <select name='formAction'><option value=''>-------</option>
  263.      <option value='change'>Edit User</option>
  264.      <option value='delete'>Delete User</option>
  265.      <option value='add'>Add User</option>
  266.      </select></td>
  267.      <td colspan='2' align='right'>
  268.      <input type='submit' value='Action' name='formSubmitChange' class='button' onclick='return checkAction();'></td></tr>";
  269.      
  270.      echo "</table></td></tr>"; 
  271.  
  272.     }
  273.     } // if(!$formSubmitChange)
  274.     
  275.       /********************************************************************************************
  276.       * Start page                                                                                *
  277.       * END                                                                                       *
  278.       *********************************************************************************************/
  279.     
  280.     }
  281.     
  282.       /**
  283.       * message permission denied for non administrators or managers
  284.       */
  285.           
  286.     if (!isset($_SESSION['admin']) && !$_SESSION['admin'] && !isset($_SESSION['management']) && !$_SESSION['management']) { echo '<tr>
  287.       <td id="DescriptionBlack" colspan="2"></td>';
  288.       include("../No_permission.php");
  289.       echo '</td></tr>'; }
  290.     
  291.     ?>
  292.       <tr>
  293.       <td id="DescriptionBlack" colspan="2"></td>
  294.       <td align="right"><input type="button" 
  295.       <?php  if($formSubmitChange and ($formAction == "change" or $formAction == "add"))
  296.       { echo 'value="Cancel" name="formSubmitMenu" id="SelectLong" onClick="self.location.href = \'usermanagement.php\';">'; }      
  297.       else { echo 'value="Return to Configuration Tool" name="formSubmitMenu" id="SelectLong" onClick="self.location.href = \'configuration.php\';">'; } ?></td>
  298.     </tr>
  299.             </table>
  300.         </td>
  301.     </tr>
  302. </table>
  303. <?php
  304.     /**
  305.     * including footer
  306.     */
  307.     include ("../footer.php"); ?>
  308.     
  309. </div>
  310. </form>
  311. </body>
  312.  
  313. </html>

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