[ Index ]

Source Code Reference for V1.00

title

Body

[close]

/modules/admin/ -> addedituser.php (source)

   1  <?php /* $Id: addedituser.php 56 2008-02-19 18:39:18Z pedroix $ $URL: https://web2project.svn.sourceforge.net/svnroot/web2project/trunk/modules/admin/addedituser.php $ */
   2  //add or edit a system user

   3  
   4  if (!defined('W2P_BASE_DIR')) {
   5      die('You should not access this file directly.');
   6  }
   7  
   8  $user_id = isset($_GET['user_id']) ? w2PgetParam($_GET, 'user_id', 0) : 0;
   9  $contact_id = isset($_GET['contact_id']) ? w2PgetParam($_GET, 'contact_id', 0) : 0;
  10  
  11  if ($user_id == 0) {
  12      $canEdit = $canAuthor;
  13  }
  14  
  15  if ($canEdit) {
  16      $canEdit = $perms->checkModuleItem('users', ($user_id ? 'edit' : 'add'), $user_id);
  17  }
  18  
  19  // check permissions

  20  if (!$canEdit && $user_id != $AppUI->user_id) {
  21      $AppUI->redirect('m=public&a=access_denied');
  22  }
  23  
  24  //$roles

  25  // Create the roles class container

  26  require_once  W2P_BASE_DIR . '/modules/system/roles/roles.class.php';
  27  $perms = &$AppUI->acl();
  28  $crole = &new CRole;
  29  $roles = $crole->getRoles();
  30  // Format the roles for use in arraySelect

  31  $roles_arr = array();
  32  foreach ($roles as $role) {
  33      $roles_arr[$role['id']] = $role['name'];
  34  }
  35  $roles_arr = arrayMerge(array(0 => ''), $roles_arr);
  36  
  37  if ($contact_id) {
  38      $q = new DBQuery;
  39      $q->addTable('contacts', 'con');
  40      $q->addQuery('con.*, company_id, company_name, dept_name');
  41      $q->addJoin('companies', 'com', 'contact_company = company_id');
  42      $q->addJoin('departments', 'dep', 'dept_id = contact_department');
  43      $q->addWhere('con.contact_id = ' . (int)$contact_id);
  44  } else {
  45      $q = new DBQuery;
  46      $q->addTable('users', 'u');
  47      $q->addQuery('u.*');
  48      $q->addQuery('con.*, company_id, company_name, dept_name');
  49      $q->addJoin('contacts', 'con', 'user_contact = contact_id', 'inner');
  50      $q->addJoin('companies', 'com', 'contact_company = company_id');
  51      $q->addJoin('departments', 'dep', 'dept_id = contact_department');
  52      $q->addWhere('u.user_id = ' . (int)$user_id);
  53  }
  54  $user = $q->loadHash();
  55  $q->clear();
  56  
  57  if (!$user && $user_id > 0) {
  58      $titleBlock = new CTitleBlock('Invalid User ID', 'helix-setup-user.png', $m, $m . '.' . $a);
  59      $titleBlock->addCrumb('?m=admin', 'users list');
  60      $titleBlock->show();
  61  } else {
  62      if ($user_id == 0 && !$contact_id) {
  63          $user['contact_id'] = 0;
  64      }
  65      // pull companies

  66      $q = new DBQuery;
  67      $q->addTable('companies');
  68      $q->addQuery('company_id, company_name');
  69      $q->addOrder('company_name');
  70      $companies = arrayMerge(array(0 => ''), $q->loadHashList());
  71  
  72      // setup the title block

  73      $ttl = $user_id > 0 ? 'Edit User' : 'Add User';
  74      $titleBlock = new CTitleBlock($ttl, 'helix-setup-user.png', $m, $m . '.' . $a);
  75      if ($perms->checkModule('admin', 'view') && $perms->checkModule('users', 'view')) {
  76          $titleBlock->addCrumb('?m=admin', 'users list');
  77      }
  78      if ($user_id > 0) {
  79          $titleBlock->addCrumb('?m=admin&a=viewuser&user_id=' . $user_id, 'view this user');
  80          if ($canEdit || $user_id == $AppUI->user_id) {
  81              $titleBlock->addCrumb('?m=system&a=addeditpref&user_id=' . $user_id, 'edit preferences');
  82          }
  83      }
  84      $titleBlock->show();
  85  ?>
  86  <script language="javascript">
  87  function submitIt(){
  88      var form = document.editFrm;
  89     if (form.user_username.value.length < <?php echo w2PgetConfig('username_min_len'); ?> && form.user_username.value != '<?php echo w2PgetConfig('admin_username'); ?>') {
  90          alert("<?php echo $AppUI->_('adminValidUserName', UI_OUTPUT_JS); ?>"  + <?php echo w2PgetConfig('username_min_len'); ?>);
  91          form.user_username.focus();
  92  <?php if ($canEdit && !$user_id) { ?>
  93      } else if (form.user_role.value <=0 ) {
  94          alert("<?php echo $AppUI->_('adminValidRole', UI_OUTPUT_JS); ?>");
  95          form.user_role.focus();     
  96      } else if (form.user_password.value.length < <?php echo w2PgetConfig('password_min_len'); ?>) {
  97          alert("<?php echo $AppUI->_('adminValidPassword', UI_OUTPUT_JS); ?>" + <?php echo w2PgetConfig('password_min_len'); ?>);
  98          form.user_password.focus();
  99      } else if (form.user_password.value !=  form.password_check.value) {
 100          alert("<?php echo $AppUI->_('adminPasswordsDiffer', UI_OUTPUT_JS); ?>");
 101          form.user_password.focus();
 102  <?php } ?>
 103      } else if (form.contact_first_name.value.length < 1) {
 104          alert("<?php echo $AppUI->_('adminValidFirstName', UI_OUTPUT_JS); ?>");
 105          form.contact_first_name.focus();
 106      } else if (form.contact_last_name.value.length < 1) {
 107          alert("<?php echo $AppUI->_('adminValidLastName', UI_OUTPUT_JS); ?>");
 108          form.contact_last_name.focus();
 109      } else if (form.contact_email.value.length < 4) {
 110          alert("<?php echo $AppUI->_('adminInvalidEmail', UI_OUTPUT_JS); ?>");
 111          form.contact_email.focus();
 112      } else if (form.contact_birthday && form.contact_birthday.value.length > 0) {
 113          dar = form.contact_birthday.value.split("-");
 114          if (dar.length < 3) {
 115              alert("<?php echo $AppUI->_('adminInvalidBirthday', UI_OUTPUT_JS); ?>");
 116              form.contact_birthday.focus();
 117          } else if (isNaN(parseInt(dar[0],10)) || isNaN(parseInt(dar[1],10)) || isNaN(parseInt(dar[2],10))) {
 118              alert("<?php echo $AppUI->_('adminInvalidBirthday', UI_OUTPUT_JS); ?>");
 119              form.contact_birthday.focus();
 120          } else if (parseInt(dar[1],10) < 1 || parseInt(dar[1],10) > 12) {
 121              alert("<?php echo $AppUI->_('adminInvalidMonth', UI_OUTPUT_JS) . ' ' . $AppUI->_('adminInvalidBirthday', UI_OUTPUT_JS); ?>");
 122              form.contact_birthday.focus();
 123          } else if (parseInt(dar[2],10) < 1 || parseInt(dar[2],10) > 31) {
 124              alert("<?php echo $AppUI->_('adminInvalidDay', UI_OUTPUT_JS) . ' ' . $AppUI->_('adminInvalidBirthday', UI_OUTPUT_JS); ?>");
 125              form.contact_birthday.focus();
 126          } else if(parseInt(dar[0],10) < 1900 || parseInt(dar[0],10) > 2020) {
 127              alert("<?php echo $AppUI->_('adminInvalidYear', UI_OUTPUT_JS) . ' ' . $AppUI->_('adminInvalidBirthday', UI_OUTPUT_JS); ?>");
 128              form.contact_birthday.focus();
 129          } else {
 130              form.submit();
 131          }
 132      } else {
 133          form.submit();
 134      }
 135  }
 136  
 137  function popDept() {
 138      var f = document.editFrm;
 139      if (f.selectedIndex == 0) {
 140          alert('<?php echo $AppUI->_('Please select a company first!', UI_OUTPUT_JS); ?>');
 141      } else {
 142          window.open('./index.php?m=public&a=selector&dialog=1&callback=setDept&table=departments&company_id='
 143              + f.contact_company.options[f.contact_company.selectedIndex].value
 144              + '&dept_id='+f.contact_department.value,'dept','left=50,top=50,height=250,width=400,resizable')
 145      }
 146  }
 147  
 148  // Callback function for the generic selector

 149  function setDept( key, val ) {
 150      var f = document.editFrm;
 151      if (val != '') {
 152          f.contact_department.value = key;
 153          f.dept_name.value = val;
 154      } else {
 155          f.contact_department.value = '0';
 156          f.dept_name.value = '';
 157      }
 158  }
 159  </script>
 160  
 161  <table width="100%" border="0" cellpadding="0" cellspacing="1" class="std">
 162  <form name="editFrm" action="./index.php?m=admin" method="post">
 163      <input type="hidden" name="user_id" value="<?php echo intval($user['user_id']); ?>" />
 164      <input type="hidden" name="contact_id" value="<?php echo intval($user['contact_id']); ?>" />
 165      <input type="hidden" name="dosql" value="do_user_aed" />
 166      <input type="hidden" name="username_min_len" value="<?php echo w2PgetConfig('username_min_len'); ?>)" />
 167      <input type="hidden" name="password_min_len" value="<?php echo w2PgetConfig('password_min_len'); ?>)" />
 168      
 169  
 170  <tr>
 171      <td align="right" width="35%" nowrap="nowrap">* <?php echo $AppUI->_('Login Name'); ?>:</td>
 172      <td>
 173  <?php
 174      if ($user["user_username"]) {
 175          echo '<input type="hidden" class="text" name="user_username" value="' . $user['user_username'] . '" />';
 176          echo '<strong>' . $user["user_username"] . '</strong>';
 177      } else {
 178          echo '<input type="text" class="text" name="user_username" value="' . $user['user_username'] . '" maxlength="255" size="40" />';
 179      }
 180  ?>
 181      </td></tr>
 182  <?php if ($canEdit) { // prevent users without read-write permissions from seeing and editing user type
 183  
 184  ?>
 185  <tr>
 186      <td align="right" nowrap="nowrap"> <?php echo $AppUI->_('User Type'); ?>:</td>
 187      <td>
 188  <?php
 189          echo arraySelect($utypes, 'user_type', 'class=text size=1', $user['user_type'], true);
 190  ?>
 191      </td>
 192  </tr>
 193  <?php } // End of security

 194  
 195  ?>
 196  <?php if ($canEdit && !$user_id) { ?>
 197  <tr>
 198      <td align="right" nowrap="nowrap">* <?php echo $AppUI->_('User Role'); ?>:</td>
 199      <td><?php echo arraySelect($roles_arr, 'user_role', 'size="1" class="text"', '', true); ?></td>
 200  </tr>
 201  <?php }
 202  
 203      if (!$user["user_id"]) {
 204  ?>
 205  <tr>
 206      <td align="right" nowrap="nowrap">* <?php echo $AppUI->_('Password'); ?>:</td>
 207      <td><input type="password" class="text" name="user_password" value="<?php echo $user['user_password']; ?>" maxlength="32" size="32" /> </td>
 208  </tr>
 209  <tr>
 210      <td align="right" nowrap="nowrap">* <?php echo $AppUI->_('Confirm Password'); ?>:</td>
 211      <td><input type="password" class="text" name="password_check" value="<?php echo $user['user_password']; ?>" maxlength="32" size="32" /> </td>
 212  </tr>
 213  <?php }
 214  ?>
 215  <tr>
 216      <td align="right" nowrap="nowrap">* <?php echo $AppUI->_('Name'); ?>:</td>
 217      <td><input type="text" class="text" name="contact_first_name" value="<?php echo $user['contact_first_name']; ?>" maxlength="50" /> <input type="text" class="text" name="contact_last_name" value="<?php echo $user['contact_last_name']; ?>" maxlength="50" /></td>
 218  </tr>
 219  <?php if ($canEdit) { ?>
 220  <tr>
 221      <td align="right" nowrap="nowrap"> <?php echo $AppUI->_('Company'); ?>:</td>
 222      <td>
 223  <?php
 224          echo arraySelect($companies, 'contact_company', 'class=text size=1', $user['contact_company']);
 225  ?>
 226      </td>
 227  </tr>
 228  <?php } ?>
 229  <tr>
 230      <td align="right" nowrap="nowrap"><?php echo $AppUI->_('Department'); ?>:</td>
 231      <td>
 232          <input type="hidden" name="contact_department" value="<?php echo $user['contact_department']; ?>" />
 233          <input type="text" class="text" name="dept_name" value="<?php echo $user['dept_name']; ?>" size="40" disabled="disabled" />
 234          <input type="button" class="button" value="<?php echo $AppUI->_('select dept'); ?>..." onclick="popDept()" />
 235      </td>
 236  </tr>
 237  <tr>
 238      <td align="right" nowrap="nowrap">* <?php echo $AppUI->_('Email'); ?>:</td>
 239      <td><input type="text" class="text" name="contact_email" value="<?php echo $user['contact_email']; ?>" maxlength="255" size="40" /> </td>
 240  </tr>
 241  <tr>
 242      <td align="right" valign="top" nowrap="nowrap"><?php echo $AppUI->_('Email') . ' ' . $AppUI->_('Signature'); ?>:</td>
 243      <td><textarea class="text" cols="50" name="user_signature" style="height: 50px"><?php echo $user["user_signature"]; ?></textarea></td>
 244  </tr>
 245  <?php if ($user_id) { ?>
 246      <tr>
 247          <td align="right" nowrap="nowrap"><a href="?m=contacts&a=addedit&contact_id=<?php echo $user['contact_id']; ?>"><?php echo $AppUI->_(array('edit', 'contact info')); ?></a></td>
 248          <td>&nbsp;</td>
 249      </tr>
 250  <?php } ?>
 251  <tr>
 252      <td align="right" nowrap="nowrap">* <?php echo $AppUI->_('Required Fields'); ?></td>
 253      <td></td>
 254  <tr>
 255      <td align="left">
 256          <input type="button" value="<?php echo $AppUI->_('back'); ?>" onclick="javascript:history.back(-1);" class="button" />
 257      </td>
 258      <?php if ($canEdit && !$user_id) { ?>
 259          <td width="100%">
 260              &nbsp;
 261          </td>
 262          <td nowrap="nowrap" align="right">
 263              <label for="send_user_mail"><?php echo $AppUI->_('Inform new user of their account details?'); ?></label>
 264          </td>
 265      <?php } ?>
 266      <td nowrap="nowrap" align="right">
 267          <?php if ($canEdit && !$user_id) { ?>
 268              <input type="checkbox" value="1" name="send_user_mail" id="send_user_mail" />&nbsp;&nbsp;&nbsp;
 269          <?php } ?>
 270          <input type="button" value="<?php echo $AppUI->_('submit'); ?>" onclick="submitIt()" class="button" />
 271      </td>
 272  </tr>
 273  </table>
 274  <?php } ?>


Generated: Wed Jan 7 03:00:01 2009 Cross-referenced by PHPXref 0.7