[ Index ]

Source Code Reference for V1.00

title

Body

[close]

/ -> do_user_aed.php (source)

   1  <?php /* $Id: do_user_aed.php 144 2008-04-06 19:54:09Z pedroix $ $URL: https://web2project.svn.sourceforge.net/svnroot/web2project/trunk/do_user_aed.php $ */
   2  require_once  'base.php';
   3  if (!defined('W2P_BASE_DIR')) {
   4      die('You should not access this file directly');
   5  }
   6  
   7  require_once  W2P_BASE_DIR . '/lib/captcha/Functions.php';
   8  /*
   9  CAPTCHA control condition...
  10  */
  11  if (strlen($_POST['spam_check']) > 0) {
  12      $cid = md5_decrypt($_POST['cid']);
  13      if ($cid == strtoupper($_POST['spam_check'])) {
  14          $passed = true;
  15      } else {
  16          $passed = false;
  17          echo "
  18                <script language='javascript'>
  19                      alert('Error: You didn\'t provide the correct Anti Spam Security ID or all required data. Please try again.');
  20                      history.go(-1);
  21                </script>
  22               ";
  23          exit;
  24      }
  25  } else {
  26      $passed = false;
  27      echo "
  28            <script language='javascript'>
  29                  alert('Error: You didn\'t provide the Anti Spam Security ID. Please try again.');
  30                  history.go(-1);
  31            </script>
  32           ";
  33      exit;
  34  }
  35  
  36  require_once W2P_BASE_DIR . '/includes/config.php';
  37  
  38  if (!isset($GLOBALS['OS_WIN'])) {
  39      $GLOBALS['OS_WIN'] = (stristr(PHP_OS, 'WIN') !== false);
  40  }
  41  
  42  // tweak for pathname consistence on windows machines
  43  require_once  W2P_BASE_DIR . '/includes/main_functions.php';
  44  require_once  W2P_BASE_DIR . '/includes/db_adodb.php';
  45  require_once  W2P_BASE_DIR . '/classes/query.class.php';
  46  require_once  W2P_BASE_DIR . '/classes/ui.class.php';
  47  $AppUI = new CAppUI();
  48  include_once  W2P_BASE_DIR . '/classes/w2p.class.php';
  49  require_once  W2P_BASE_DIR . '/classes/date.class.php';
  50  require_once  W2P_BASE_DIR . '/modules/admin/admin.class.php';
  51  // Create the roles class container
  52  require_once  W2P_BASE_DIR . '/modules/system/roles/roles.class.php';
  53  if (w2PgetConfig('activate_external_user_creation') != 'true') {
  54      die('You should not access this file directly');
  55  }
  56  
  57  require_once ($AppUI->getSystemClass('libmail'));
  58  include $AppUI->getModuleClass('contacts');
  59  
  60  $obj = new CUser();
  61  $contact = new CContact();
  62  
  63  $q = new DBQuery;
  64  $q->addTable('users', 'u');
  65  $q->addQuery('COUNT(u.user_id)');
  66  $q->addWhere('u.user_username = \'' . $_POST['user_username'] . '\'');
  67  $usr_count = $q->loadResult();
  68  if ($usr_count) {
  69      error_reporting(0);
  70      echo "
  71              <script language='javascript'>
  72                    alert('The user name you selected already exists, please select another or if that user name is yours request the password recovery through the dedicated link.');
  73                    history.go(-2);
  74              </script>
  75             ";
  76      die;
  77  }
  78  $q->clear();
  79  
  80  $q = new DBQuery;
  81  $q->addTable('contacts', 'c');
  82  $q->addQuery('COUNT(c.contact_id)');
  83  $q->addWhere('c.contact_email = \'' . $_POST['contact_email'] . '\'');
  84  $ct_count = $q->loadResult();
  85  if ($ct_count) {
  86      error_reporting(0);
  87      echo "
  88              <script language='javascript'>
  89                    alert('The email you selected already exists, please select another or if that email is yours request the password recovery through the dedicated link.');
  90                    history.go(-2);
  91              </script>
  92             ";
  93      die;
  94  }
  95  $q->clear();
  96  
  97  if (!$obj->bind($_POST)) {
  98      $AppUI->setMsg($obj->getError(), UI_MSG_ERROR);
  99      $AppUI->redirect();
 100  }
 101  if (!$contact->bind($_POST)) {
 102      $AppUI->setMsg($contact->getError(), UI_MSG_ERROR);
 103      $AppUI->redirect();
 104  }
 105  
 106  // prepare (and translate) the module name ready for the suffix
 107  $AppUI->setMsg('User');
 108  
 109  $isNewUser = !(w2PgetParam($_REQUEST, 'user_id', 0));
 110  if ($isNewUser) {
 111      // check if a user with the param Username already exists
 112      $userEx = false;
 113  
 114  	function userExistence($userName) {
 115          global $obj, $userEx;
 116          if ($userName == $obj->user_username) {
 117              $userEx = true;
 118          }
 119      }
 120  
 121      //pull a list of existing usernames
 122      $q = new DBQuery;
 123      $q->addTable('users', 'u');
 124      $q->addQuery('user_username');
 125      $users = $q->loadList();
 126  
 127      // Iterate the above userNameExistenceCheck for each user
 128      foreach ($users as $usrs) {
 129          $usrLst = array_map('userExistence', $usrs);
 130      }
 131      // If userName already exists quit with error and do nothing
 132      if ($userEx == true) {
 133          $AppUI->setMsg('already exists. Try another username.', UI_MSG_ERROR, true);
 134          $AppUI->redirect();
 135      }
 136  
 137      $contact->contact_owner = $AppUI->user_id;
 138  }
 139  
 140  if (($msg = $contact->store())) {
 141      $AppUI->setMsg($msg, UI_MSG_ERROR);
 142  } else {
 143  
 144      $obj->user_contact = $contact->contact_id;
 145      if (($msg = $obj->store())) {
 146          $AppUI->setMsg($msg, UI_MSG_ERROR);
 147      } else {
 148          if ($isNewUser) {
 149              notifyNewExternalUser($contact->contact_email, $contact->contact_first_name, $obj->user_username, $_POST['user_password']);
 150          }
 151          notifyHR('hr@yourdomain.com', 'w2P System Human Resources', $contact->contact_email, $contact->contact_first_name, $obj->user_username, $_POST['user_password'], $obj->user_id);
 152  
 153          $q = new DBQuery;
 154          $q->addTable('users', 'u');
 155          $q->addQuery('ct.contact_email');
 156          $q->addJoin('contacts', 'ct', 'ct.contact_id = u.user_contact', 'inner');
 157          $q->addWhere('u.user_username = \'admin\'');
 158          $admin_user = $q->loadList();
 159          //notifyAdmin($admin_user[0]['contact_email'], 'web2Project Administrator', $contact->contact_email, $contact->contact_first_name, $obj->user_username, $_POST['user_password'], $obj->user_id);
 160  
 161      }
 162  }
 163  
 164  echo "
 165        <script language='javascript'>
 166              alert('The User Administrator has been notified to grant you access to the system and an email message was sent to you with your login info. Thank you very much.');
 167              history.go(-2);
 168        </script>
 169  ";
 170  
 171  function notifyNewExternalUser($address, $username, $logname, $logpwd) {
 172      global $AppUI;
 173      $mail = new Mail;
 174      if ($mail->ValidEmail($address)) {
 175          if ($mail->ValidEmail($AppUI->user_email)) {
 176              $email = $AppUI->user_email;
 177          } else {
 178              $email = 'web2project@web2project.net';
 179          }
 180  
 181          $mail->To($address);
 182          $mail->Subject('New Account Created');
 183          $mail->Body('You have signed up for a new account on ' . w2PgetConfig('company_name') . ".\n\n" . "Once the administrator approves your request, you will receive an email with confirmation.\n" . "Your login information are below for your own record:\n\n" . 'Username:    ' . $logname . "\n" . 'Password:    ' . $logpwd . "\n\n" . "You may login at the following URL: " . W2P_BASE_URL . "\n\n" . "Thank you very much.\n\n" . 'The ' . w2PgetConfig('company_name') . " Support Staff.\n\n" . '****PLEASE KEEP THIS EMAIL FOR YOUR RECORDS****');
 184          $mail->Send();
 185      }
 186  }
 187  
 188  function notifyHR($address, $username, $uaddress, $uusername, $logname, $logpwd, $userid) {
 189      global $AppUI;
 190      $mail = new Mail;
 191      if ($mail->ValidEmail($address)) {
 192          if ($mail->ValidEmail($AppUI->user_email)) {
 193              $email = $AppUI->user_email;
 194          } else {
 195              $email = 'web2project@web2project.net';
 196          }
 197  
 198          $mail->To($address);
 199          $mail->Subject('New External User Created');
 200          $mail->Body('A new user has signed up on ' . w2PgetConfig('company_name') . ". Please go through the user details below:\n" . 'Name:    ' . $uusername . "\n" . 'Username:    ' . $logname . "\n" . 'Email:    ' . $uaddress . "\n\n" . 'You may check this account at the following URL: ' . W2P_BASE_URL . '/index.php?m=admin&a=viewuser&user_id=' . $userid . "\n\n" . "Thank you very much.\n\n" . 'The ' . w2PgetConfig('company_name') . " Taskforce.\n\n" . '****PLEASE KEEP THIS EMAIL FOR YOUR RECORDS****');
 201          $mail->Send();
 202      }
 203  }
 204  ?>


Generated: Tue Mar 9 03:00:03 2010 Cross-referenced by PHPXref 0.7