Source for file new_user.php

Documentation is available at new_user.php

  1. <?php
  2. /**
  3. * Adding new user
  4. * <br/><br/>
  5. * Access resctricted to administrators and members of group "Management"
  6. * @author Gabriele Droege, DNA Bank Network <contact@dnabank-network.org>
  7. * @version 2.0
  8. * @package Configuration
  9. * @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
  10. * @filesource
  11. * @license http://www.mozilla.org/MPL/ MPL
  12. * @see start.inc.php|RandPass
  13. */
  14.  
  15.     /********************************************************************************************
  16.     * login as administrator or manager is required                                             *
  17.     * password will be generated automatically (line 35)                                        *
  18.     * @see start.inc.php|RandPass                                                               *
  19.     *********************************************************************************************/
  20.  
  21.  
  22. if (!isset($_SESSION['admin']) & !$_SESSION['admin'] & !isset($_SESSION['management']) & !$_SESSION['management']) {
  23.  
  24. $sql= "SELECT ID_User FROM user";
  25. $result = mysql_query($sql);
  26. if(mysql_num_rows($result) > 10) {                        
  27. $TestAdmin = false;
  28. echo "<tr><td colspan='3'><span class='error'>Sorry, you have no permission for editing connection parameters! Please login as administrator or contact an admin.</span></td></tr>"; }
  29.  
  30. else
  31. { $Test = true; }
  32. }
  33.  
  34. if($Test == "true" or (isset($_SESSION['admin']) || $_SESSION['admin'] || isset($_SESSION['management']) || $_SESSION['management'])) {
  35.  
  36. if($formSubmitSaveUser) {
  37.  
  38. $Signature = $_POST['signature'];
  39. $Username = $_POST['username'];
  40. $Password = md5($randomstring);
  41. $Email = $_POST['email'];
  42. $Group = $_POST['group'];
  43.  
  44. $sqltest = "SELECT * FROM user WHERE Signature = '$Signature' OR Login = '$Username'";
  45. $resulttest = mysql_query($sqltest);
  46.  
  47. if(mysql_num_rows($resulttest) > 0) {
  48.  
  49. echo  "<tr><td colspan='3'><span class='error'>User name '".$Username."' or real name '".$Signature."' already exist in database!</span></td></tr>"; 
  50. $Exist = true; }
  51.  
  52. else {
  53.  
  54. $sql = "INSERT INTO user (Signature, Login, Password, Email, ID_Group, Created_Who) VALUES ('$Signature','$Username','$Password','$Email','$Group','$log')";
  55. $result = mysql_query($sql);   
  56.  
  57. $msg = "<font size='2' face='Arial'><table width='80%'><tr><td align='justify'>Dear ".utf8_decode($Signature)."<br/><br/>Welcome to the DNA Module! Please keep this email. It contains your current password. You can change your password at any time.<br/><br/><b>Login name: ".utf8_decode($Username)."<br>Password: ".$randomstring."</b></td></tr>";
  58. $msg .= "<tr><td><hr></td></tr>";
  59. $msg .= "<tr><td>Sincerely,</td></tr>";
  60. $msg .= "<tr><td>Administrator DNA Module</td></tr>";
  61. echo "</table></font>";
  62.  
  63.     /********************************************************************************************
  64.     * sending email to new user with generated password                                         *
  65.     *********************************************************************************************/
  66.  
  67. $from = "From: contact@dnabank-network.org\n";
  68. $from .= "Content-Type: text/html\n";
  69.  
  70. if(mail($Email, "Welcome to the DNA Module", htmlspecialchars_decode($msg), $from)) {
  71. $$NewUser = true;
  72.  
  73. echo  "<tr><td colspan='3'><span class='fine'>An email with current password has been sent to ".$Email."</td></tr>"; 
  74.    }}
  75.    }
  76. else {
  77. echo "<tr>
  78.         <td colspan='3' valign='top'>
  79.         <table border='0' id='table2'>";
  80. echo "<tr><td colspan='4'><h3>Add new user:</h3> Password will be generated automatically and can be changed after first login.</td></tr>"; 
  81.   echo "<tr><td id='DescriptionGreen'>Signature</td><td><input type='text' name='signature' id='InputLong' ";
  82.   if($Exist == "true") { echo "value='".$Signature."'"; }
  83.   echo "/></td><td colspan='2'>Real Name/Signature.</td></tr>";
  84.   echo "<tr><td id='DescriptionGreen'>User name</td><td><input type='text' name='username' id='InputLong' ";
  85.   if($Exist == "true") { echo "value='".$Username."'"; }
  86.   echo "/></td><td colspan='2'>Login Name.</td></tr>";  
  87.   echo "<tr><td id='DescriptionGreen'>Email</td><td><input type='text' name='email' id='InputLong' ";
  88.   if($Exist == "true") { echo "value='".$Email."'"; }
  89.   echo "/></td><td colspan='2'>Enter user's email address. The user will receive an email with his or her password.</td></tr>"; 
  90.   echo "<tr><td id='DescriptionGreen'>Group</td><td> <select name='group' id='InputLong'><option value=''>-------</option>
  91.      <option value='1'";
  92.      if($Test == "true") { echo " selected"; }
  93.      echo ">Administrator</option>
  94.      <option value='2'>DNA Bank Team</option>
  95.      <option value='3'>Project</option>
  96.      <option value='4'>Guest</option>
  97.      </select></td><td colspan='2'>Group for this user.</td></tr>"; 
  98.   echo '<tr><td id="DescriptionBlack"></td><td><input type="submit" name="formSubmitSaveUser" value="Save new user" id="InputLong" onClick="return CheckGroup();"/></td><td colspan="2"></td></tr>';   
  99. echo "</table></td></tr>";}
  100.  
  101.  
  102. }
  103.  
  104. ?>

Documentation generated on Tue, 29 Nov 2011 10:44:58 +0100 by phpDocumentor 1.4.3