home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / dotproject / modules / admin / addedituser.php < prev    next >
Encoding:
PHP Script  |  2004-01-18  |  9.9 KB  |  225 lines

  1. <?php /* ADMIN $Id: addedituser.php,v 1.30 2004/01/18 05:07:49 mkozusnik Exp $ */
  2. //add or edit a system user
  3.  
  4. $user_id = isset($_GET['user_id']) ? $_GET['user_id'] : 0;
  5.  
  6. // check permissions
  7. if (!$canEdit && $user_id != $AppUI->user_id) {
  8.     $AppUI->redirect( "m=public&a=access_denied" );
  9. }
  10.  
  11. $sql = "
  12. SELECT users.*, 
  13.     company_id, company_name, 
  14.     dept_name
  15. FROM users
  16. LEFT JOIN companies ON user_company = companies.company_id
  17. LEFT JOIN departments ON dept_id = user_department
  18. WHERE user_id = $user_id
  19. ";
  20. if (!db_loadHash( $sql, $user ) && $user_id > 0) {
  21.     $titleBlock = new CTitleBlock( 'Invalid User ID', 'helix-setup-user.png', $m, "$m.$a" );
  22.     $titleBlock->addCrumb( "?m=admin", "users list" );
  23.     $titleBlock->show();
  24. } else {
  25. // pull companies
  26.     $sql = "SELECT company_id, company_name FROM companies ORDER BY company_name";
  27.     $companies = arrayMerge( array( 0 => '' ), db_loadHashList( $sql ) );
  28.  
  29. // setup the title block
  30.     $ttl = $user_id > 0 ? "Edit User" : "Add User";
  31.     $titleBlock = new CTitleBlock( $ttl, 'helix-setup-user.png', $m, "$m.$a" );
  32.     if ($canEdit) {
  33.       $titleBlock->addCrumb( "?m=admin", "users list" );
  34.     }
  35.     $titleBlock->addCrumb( "?m=admin&a=viewuser&user_id=$user_id", "view this user" );
  36.     $titleBlock->addCrumb( "?m=system&a=addeditpref&user_id=$user_id", "edit preferences" );
  37.     $titleBlock->show();
  38. ?>
  39. <SCRIPT language="javascript">
  40. function submitIt(){
  41.     var form = document.editFrm;
  42.     if (form.user_username.value.length < 3) {
  43.         alert("<?php echo $AppUI->_('adminValidUserName');?>");
  44.         form.user_username.focus();
  45.     } else if (form.user_password.value.length < 4) {
  46.         alert("<?php echo $AppUI->_('adminValidPassword');?>");
  47.         form.user_password.focus();
  48.     } else if (form.user_password.value !=  form.password_check.value) {
  49.         alert("<?php echo $AppUI->_('adminPasswordsDiffer');?>");
  50.         form.user_password.focus();
  51.     } else if (form.user_first_name.value.length < 1) {
  52.         alert("<?php echo $AppUI->_('adminValidFirstName');?>");
  53.         form.user_first_name.focus();
  54.     } else if (form.user_last_name.value.length < 1) {
  55.         alert("<?php echo $AppUI->_('adminValidLastName');?>");
  56.         form.user_last_name.focus();
  57.     } else if (form.user_email.value.length < 4) {
  58.         alert("<?php echo $AppUI->_('adminInvalidEmail');?>");
  59.         form.user_email.focus();
  60.     } else if (form.user_birthday.value.length > 0) {
  61.         dar = form.user_birthday.value.split("-");
  62.         if (dar.length < 3) {
  63.             alert("<?php echo $AppUI->_('adminInvalidBirthday');?>");
  64.             form.user_birthday.focus();
  65.         } else if (isNaN(parseInt(dar[0],10)) || isNaN(parseInt(dar[1],10)) || isNaN(parseInt(dar[2],10))) {
  66.             alert("<?php echo $AppUI->_('adminInvalidBirthday');?>");
  67.             form.user_birthday.focus();
  68.         } else if (parseInt(dar[1],10) < 1 || parseInt(dar[1],10) > 12) {
  69.             alert("<?php echo $AppUI->_('adminInvalidMonth').' '.$AppUI->_('adminInvalidBirthday');?>");
  70.             form.user_birthday.focus();
  71.         } else if (parseInt(dar[2],10) < 1 || parseInt(dar[2],10) > 31) {
  72.             alert("<?php echo $AppUI->_('adminInvalidDay').' '.$AppUI->_('adminInvalidBirthday');?>");
  73.             form.user_birthday.focus();
  74.         } else if(parseInt(dar[0],10) < 1900 || parseInt(dar[0],10) > 2020) {
  75.             alert("<?php echo $AppUI->_('adminInvalidYear').' '.$AppUI->_('adminInvalidBirthday');?>");
  76.             form.user_birthday.focus();
  77.         } else {
  78.             form.submit();
  79.         }
  80.     } else {
  81.         form.submit();
  82.     }
  83. }
  84.  
  85. function popDept() {
  86.     var f = document.editFrm;
  87.     if (f.selectedIndex == 0) {
  88.         alert( 'Please select a company first!' );
  89.     } else {
  90.         window.open('./index.php?m=public&a=selector&dialog=1&callback=setDept&table=departments&company_id='
  91.             + f.user_company.options[f.user_company.selectedIndex].value
  92.             + '&dept_id='+f.user_department.value,'dept','left=50,top=50,height=250,width=400,resizable')
  93.     }
  94. }
  95.  
  96. // Callback function for the generic selector
  97. function setDept( key, val ) {
  98.     var f = document.editFrm;
  99.     if (val != '') {
  100.         f.user_department.value = key;
  101.         f.dept_name.value = val;
  102.     } else {
  103.         f.user_department.value = '0';
  104.         f.dept_name.value = '';
  105.     }
  106. }
  107. </script>
  108.  
  109. <table width="100%" border="0" cellpadding="0" cellspacing="1" height="400" class="std">
  110. <form name="editFrm" action="./index.php?m=admin" method="post">
  111.     <input type="hidden" name="user_id" value="<?php echo intval($user["user_id"]);?>" />
  112.     <input type="hidden" name="dosql" value="do_user_aed" />
  113.  
  114. <tr>
  115.     <td align="right" width="230"><?php echo $AppUI->_('Login Name');?>:</td>
  116.     <td>
  117. <?php
  118.     if (@$user["user_username"]){
  119.         echo '<input type="hidden" class="text" name="user_username" value="' . $user["user_username"] . '" />';
  120.         echo '<strong>' . $user["user_username"] . '</strong>';
  121.     } else {
  122.         echo '<input type="text" class="text" name="user_username" value="' . $user["user_username"] . '" maxlength="20" size="20" />';
  123.         echo ' <span class="smallNorm">(' . $AppUI->_('required') . ')</span>';
  124.     }
  125. ?>
  126.     </td></tr>
  127. <?php if ($canEdit) { // prevent users without read-write permissions from seeing and editing user type
  128. ?>
  129. <tr>
  130.     <td align="right"><?php echo $AppUI->_('User Type');?>:</td>
  131.     <td>
  132. <?php
  133.     echo arraySelect( $utypes, 'user_type', 'class=text size=1', $user["user_type"], true );
  134. ?>
  135.     </td>
  136. </tr>
  137. <?php } // End of security
  138. ?>
  139. <tr>
  140.     <td align="right"><?php echo $AppUI->_('Password');?>:</td>
  141.     <td><input type="password" class="text" name="user_password" value="<?php echo $user["user_password"];?>" maxlength="32" size="32" /> </td>
  142. </tr>
  143. <tr>
  144.     <td align="right"><?php echo $AppUI->_('Password');?>2:</td>
  145.     <td><input type="password" class="text" name="password_check" value="<?php echo $user["user_password"];?>" maxlength="32" size="32" /> </td>
  146. </tr>
  147. <tr>
  148.     <td align="right"><?php echo $AppUI->_('First Name');?>:</td>
  149.     <td><input type="text" class="text" name="user_first_name" value="<?php echo $user["user_first_name"];?>" maxlength="50" /> <input type="text" class="text" name="user_last_name" value="<?php echo $user["user_last_name"];?>" maxlength="50" /></td>
  150. </tr>
  151. <?php if ($canEdit) { ?>
  152. <tr>
  153.     <td align="right"><?php echo $AppUI->_('Company');?>:</td>
  154.     <td>
  155. <?php
  156.     echo arraySelect( $companies, 'user_company', 'class=text size=1', $user["user_company"] );
  157. ?>
  158.     </td>
  159. </tr>
  160. <?php } ?>
  161. <tr>
  162.     <td align="right"><?php echo $AppUI->_('Department');?>:</td>
  163.     <td>
  164.         <input type="hidden" name="user_department" value="<?php echo @$user["user_department"];?>" />
  165.         <input type="text" class="text" name="dept_name" value="<?php echo @$user["dept_name"];?>" size="40" disabled />
  166.         <input type="button" class="button" value="<?php echo $AppUI->_('select dept');?>..." onclick="popDept()" />
  167.     </td>
  168. </tr>
  169. <tr>
  170.     <td align="right"><?php echo $AppUI->_('Email');?>:</td>
  171.     <td><input type="text" class="text" name="user_email" value="<?php echo $user["user_email"];?>" maxlength="255" size="40" /> </td>
  172. </tr>
  173. <tr>
  174.     <td align="right"><?php echo $AppUI->_('Phone');?>:</td>
  175.     <td><input type="text" class="text" name="user_phone" value="<?php echo $user["user_phone"];?>" maxlength="50" size="40" /> </td>
  176.     </tr>
  177. <tr>
  178.     <td align="right"><?php echo $AppUI->_('Home Phone');?>:</td>
  179.     <td><input type="text" class="text" name="user_home_phone" value="<?php echo $user["user_home_phone"];?>" maxlength="50" size="40" /> </td></tr>
  180. <tr>
  181.     <td align="right"><?php echo $AppUI->_('Mobile');?>:</td>
  182.     <td><input type="text" class="text" name="user_mobile" value="<?php echo $user["user_mobile"];?>" maxlength="50" size="40" /> </td></tr>
  183. <tr>
  184.     <td align="right"><?php echo $AppUI->_('Address');?>1:</td>
  185.     <td><input type="text" class="text" name="user_address1" value="<?php echo $user["user_address1"];?>" maxlength="50" size="40" /> </td></tr>
  186. <tr>
  187.     <td align="right"><?php echo $AppUI->_('Address');?>2:</td>
  188.     <td><input type="text" class="text" name="user_address2" value="<?php echo $user["user_address2"];?>" maxlength="50" size="40" /> </td></tr>
  189. <tr>
  190.     <td align="right"><?php echo $AppUI->_('City');?>:</td>
  191.     <td><input type="text" class="text" name="user_city" value="<?php echo $user["user_city"];?>" maxlength="50" size="40" /> </td></tr>
  192. <tr>
  193.     <td align="right"><?php echo $AppUI->_('State');?>:</td>
  194.     <td><input type="text" class="text" name="user_state" value="<?php echo $user["user_state"];?>" maxlength="50" size="40" /> </td></tr>
  195. <tr>
  196.     <td align="right"><?php echo $AppUI->_('Zip');?>:</td>
  197.     <td><input type="text" class="text" name="user_zip" value="<?php echo $user["user_zip"];?>" maxlength="50" size="40" /> </td></tr>
  198. <tr>
  199.     <td align="right"><?php echo $AppUI->_('Country');?>:</td>
  200.     <td><input type="text" class="text" name="user_country" value="<?php echo $user["user_country"];?>" maxlength="50" size="40" /> </td>
  201. </tr>
  202. <tr>
  203.     <td align="right">ICQ#:</td>
  204.     <td><input type="text" class="text" name="user_icq" value="<?php echo $user["user_icq"];?>" maxlength="50"> AOL Nick: <input type="text" class="text" name="user_aol" value="<?php echo $user["user_aol"];?>" maxlength="50"> </td>
  205. </tr>
  206. <tr>
  207.     <td align="right"><?php echo $AppUI->_('Birthday');?>:</td>
  208.     <td><input type="text" class="text" name="user_birthday" value="<?php if(intval($user["user_birthday"])!=0) { echo substr($user["user_birthday"],0,10);}?>" maxlength="50" size="40" /> format(YYYY-MM-DD)</td>
  209. </tr>
  210. <tr>
  211.     <td align="right" valign=top><?php echo $AppUI->_('Email').' '.$AppUI->_('Signature');?>:</td>
  212.     <td><textarea class="text" cols=50 name="user_signature" style="height: 50px"><?php echo @$user["user_signature"];?></textarea></td>
  213. </tr>
  214.  
  215. <tr>
  216.     <td align="left">
  217.         <input type="button" value="<?php echo $AppUI->_('back');?>" onClick="javascript:history.back(-1);" class="button" />
  218.     </td>
  219.     <td align="right">
  220.         <input type="button" value="<?php echo $AppUI->_('submit');?>" onClick="submitIt()" class="button" />
  221.     </td>
  222. </tr>
  223. </table>
  224. <?php } ?>
  225.