HRDIODB
[ class tree: HRDIODB ] [ index: HRDIODB ] [ all elements ]

Source for file user.php

Documentation is available at user.php

  1. <?php
  2. /**
  3.  * User registration and account maintenance page.
  4.  * This file displays the registration form as well as the user edit form.
  5.  * @package HRDIODB
  6.  */
  7.  
  8. /**
  9.  * This file is part of HRDIODB.
  10.  *
  11.  * HRDIODB is free software; you can redistribute it and/or modify
  12.  * it under the terms of the GNU General Public License as published by
  13.  * the Free Software Foundation; either version 2 of the License, or
  14.  * (at your option) any later version.
  15.  *
  16.  * HRDIODB is distributed in the hope that it will be useful,
  17.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19.  * GNU General Public License for more details.
  20.  *
  21.  * You should have received a copy of the GNU General Public License
  22.  * along with HRDIODB; if not, write to the Free Software
  23.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  24.  */
  25.  
  26. /** Configuration file */
  27. require_once("conf.php");
  28. /** HRDI database class */
  29. require_once("hrdi_db_class.php");
  30. /** PHP session class */
  31. require_once("session_class.php");
  32. /** User class */
  33. require_once("user_class.php");
  34. /** Common class */
  35. require_once("common_class.php");
  36. /** Debugging functions */
  37. require_once("debugging.php");
  38.  
  39. // Create class instances
  40. $session new session();
  41. $hdb new hrdi_db ($dsn);
  42. $user new user ($hdb$session);
  43.  
  44. // Get the mode from the $_GET or the $_POST variable
  45. $mode = isset($_POST['mode']$_POST['mode'@$_GET['mode'];
  46.  
  47. // If we're not in a valid mode, stop execution
  48. if (($mode != "register"&& ($mode != "update")) {
  49.   require_once("header.php");
  50.   error("$mode is not a valid mode");
  51.   require_once("footer.php");
  52.   exit(0);
  53. }
  54.  
  55. /* If we're not authenticated but want to do an update, or if we're
  56.  * authenticated but want to register, lets go back to our previous page.
  57.  */
  58. if ((!$user->authenticated(&& ($mode == "update")) ||
  59.     ($user->authenticated(&& ($mode == "register"))) {
  60.   $session->go_to_last_page();
  61. }
  62.  
  63. if (isset($_POST['register'])) {
  64.   // Process user registration
  65.     unset($_POST['register']);
  66.   unset($_POST['mode']);
  67.  
  68.   // Perform the registration
  69.     if ($user->register($_POST)) {
  70.     require_once("header.php");
  71.     print "<br/><center><div id=\"message\">Thank you for registering! You may
  72.           now <a href=\"login.php\">login</a>.</div></center>";
  73.     require_once("footer.php");
  74.     exit(1);
  75.   }
  76. else if (isset($_POST['update'])) {
  77.   // Process the update
  78.     unset($_POST['update']);
  79.   unset($_POST['mode']);
  80.  
  81.   // Perform the update
  82.     if ($user->update($_POST)) {
  83.     $session->go_to_last_page();
  84.   }
  85. }
  86.  
  87. // Page title
  88. $page_title "";
  89.  
  90. // Include the page header
  91. require_once("header.php");
  92.  
  93. // Print out any errors
  94. if ($user->error{
  95.   error($user->error);
  96.   print "<br>";
  97. }
  98.  
  99. // Display registration or update form
  100. ?>
  101. <center>
  102. <div id="message_block">Please note that your e-mail will be your login
  103. username, and it will also be used to send you an e-mail if you need to reset
  104. your password.</div>
  105. <br/>
  106. <form name="user_form" method="post" action="<?php print $_SERVER['PHP_SELF']?>">
  107. <input type="hidden" name="mode" value="<?php print $mode ?>">
  108. <?php if ($mode == "update"?>
  109. <input type="hidden" name="ID" value="<?php print $user->get_user_id(?>">
  110. <?php ?>
  111. <table class="user">
  112.   <tr>
  113.     <?php if ($mode == "register"?>
  114.     <td colspan="2" align="center"><b>HRDI User Registration</b></td>
  115.     <?php else if ($mode == "update"?>
  116.     <td colspan="2" align="center"><b>HRDI User Update</b></td>
  117.     <?php ?>
  118.   </tr>
  119.   <tr>
  120.     <td align="right">E-mail:</td>
  121.     <td>
  122.       <?php if ($mode == "register"?>
  123.       <input type="text" name="Email" size="20" maxlength="255" value="<?php print common::get_value('Email'$_POST$user->data)?>">
  124.       <?php else if ($mode == "update"{
  125.         print $user->data['Email'];
  126.       ?>
  127.     </td>
  128.   </tr>
  129.   <tr>
  130.     <td align="right">First Name:</td>
  131.     <td><input type="text" name="Firstname" size="20" maxlength="255" value="<?php print common::get_value('Firstname'$_POST$user->data)?>"></td>
  132.   </tr>
  133.   <tr>
  134.     <td align="right">Last Name:</td>
  135.     <td><input type="text" name="Lastname" size="20" maxlength="255" value="<?php print common::get_value('Lastname'$_POST$user->data)?>"></td>
  136.   </tr>
  137.   <tr>
  138.     <?php if ($mode == "register"?>
  139.     <td align="right">Password:</td>
  140.     <?php else if ($mode == "update"?>
  141.     <td align="right">New Password:</td>
  142.     <?php ?>
  143.     <td><input type="password" name="Password" size="20"></td>
  144.   </tr>
  145.   <tr>
  146.     <td align="right">Retype Password:</td>
  147.     <td><input type="password" name="Password2" size="20"></td>
  148.   </tr>
  149.   <tr>
  150.     <?php if ($mode == "register"?>
  151.     <td colspan="2" align="right"><input type="submit" name="register" value="Register"></td>
  152.     <?php else if ($mode == "update"?>
  153.     <td colspan="2" align="right"><input type="submit" name="update" value="Update"></td>
  154.     <?php ?>
  155.   </tr>
  156. </table>
  157. </form>
  158. <?php if ($mode == "register"?>
  159. <script type="text/javascript">
  160. <?php // Grab the focus and smack it in the e-mail field ?>
  161. document.user_form.Email.focus();
  162. </script>
  163. <?php else if ($mode == "update"?>
  164. <script type="text/javascript">
  165. <?php // Grab the focus and smack it in the first name field ?>
  166. document.user_form.Firstname.focus();
  167. </script>
  168. <?php ?>
  169. </center>
  170. <?php
  171. // Include the page footer
  172. require_once("footer.php");
  173. ?>

Documentation generated on Tue, 23 Jan 2007 22:57:53 -0500 by phpDocumentor 1.3.0RC6