0) {
$cid = md5_decrypt($_POST['cid']);
if ($cid == strtoupper($_POST['spam_check'])) {
$passed = true;
} else {
$passed = false;
echo "
";
exit;
}
} else {
$passed = false;
echo "
";
exit;
}
require_once W2P_BASE_DIR . '/includes/config.php';
if (!isset($GLOBALS['OS_WIN'])) {
$GLOBALS['OS_WIN'] = (stristr(PHP_OS, 'WIN') !== false);
}
// tweak for pathname consistence on windows machines
require_once W2P_BASE_DIR . '/includes/main_functions.php';
require_once W2P_BASE_DIR . '/includes/db_adodb.php';
require_once W2P_BASE_DIR . '/classes/query.class.php';
require_once W2P_BASE_DIR . '/classes/ui.class.php';
$AppUI = new CAppUI();
include_once W2P_BASE_DIR . '/classes/w2p.class.php';
require_once W2P_BASE_DIR . '/classes/date.class.php';
require_once W2P_BASE_DIR . '/modules/admin/admin.class.php';
// Create the roles class container
require_once W2P_BASE_DIR . '/modules/system/roles/roles.class.php';
if (w2PgetConfig('activate_external_user_creation') != 'true') {
die('You should not access this file directly');
}
require_once ($AppUI->getSystemClass('libmail'));
include $AppUI->getModuleClass('contacts');
$obj = new CUser();
$contact = new CContact();
$q = new DBQuery;
$q->addTable('users', 'u');
$q->addQuery('COUNT(u.user_id)');
$q->addWhere('u.user_username = \'' . $_POST['user_username'] . '\'');
$usr_count = $q->loadResult();
if ($usr_count) {
error_reporting(0);
echo "
";
die;
}
$q->clear();
$q = new DBQuery;
$q->addTable('contacts', 'c');
$q->addQuery('COUNT(c.contact_id)');
$q->addWhere('c.contact_email = \'' . $_POST['contact_email'] . '\'');
$ct_count = $q->loadResult();
if ($ct_count) {
error_reporting(0);
echo "
";
die;
}
$q->clear();
if (!$obj->bind($_POST)) {
$AppUI->setMsg($obj->getError(), UI_MSG_ERROR);
$AppUI->redirect();
}
if (!$contact->bind($_POST)) {
$AppUI->setMsg($contact->getError(), UI_MSG_ERROR);
$AppUI->redirect();
}
// prepare (and translate) the module name ready for the suffix
$AppUI->setMsg('User');
$isNewUser = !(w2PgetParam($_REQUEST, 'user_id', 0));
if ($isNewUser) {
// check if a user with the param Username already exists
$userEx = false;
function userExistence($userName) {
global $obj, $userEx;
if ($userName == $obj->user_username) {
$userEx = true;
}
}
//pull a list of existing usernames
$q = new DBQuery;
$q->addTable('users', 'u');
$q->addQuery('user_username');
$users = $q->loadList();
// Iterate the above userNameExistenceCheck for each user
foreach ($users as $usrs) {
$usrLst = array_map('userExistence', $usrs);
}
// If userName already exists quit with error and do nothing
if ($userEx == true) {
$AppUI->setMsg('already exists. Try another username.', UI_MSG_ERROR, true);
$AppUI->redirect();
}
$contact->contact_owner = $AppUI->user_id;
}
if (($msg = $contact->store())) {
$AppUI->setMsg($msg, UI_MSG_ERROR);
} else {
$obj->user_contact = $contact->contact_id;
if (($msg = $obj->store())) {
$AppUI->setMsg($msg, UI_MSG_ERROR);
} else {
if ($isNewUser) {
notifyNewExternalUser($contact->contact_email, $contact->contact_first_name, $obj->user_username, $_POST['user_password']);
}
notifyHR('hr@yourdomain.com', 'w2P System Human Resources', $contact->contact_email, $contact->contact_first_name, $obj->user_username, $_POST['user_password'], $obj->user_id);
$q = new DBQuery;
$q->addTable('users', 'u');
$q->addQuery('ct.contact_email');
$q->addJoin('contacts', 'ct', 'ct.contact_id = u.user_contact', 'inner');
$q->addWhere('u.user_username = \'admin\'');
$admin_user = $q->loadList();
//notifyAdmin($admin_user[0]['contact_email'], 'web2Project Administrator', $contact->contact_email, $contact->contact_first_name, $obj->user_username, $_POST['user_password'], $obj->user_id);
}
}
echo "
";
function notifyNewExternalUser($address, $username, $logname, $logpwd) {
global $AppUI;
$mail = new Mail;
if ($mail->ValidEmail($address)) {
if ($mail->ValidEmail($AppUI->user_email)) {
$email = $AppUI->user_email;
} else {
$email = 'web2project@web2project.net';
}
$mail->To($address);
$mail->Subject('New Account Created');
$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****');
$mail->Send();
}
}
function notifyHR($address, $username, $uaddress, $uusername, $logname, $logpwd, $userid) {
global $AppUI;
$mail = new Mail;
if ($mail->ValidEmail($address)) {
if ($mail->ValidEmail($AppUI->user_email)) {
$email = $AppUI->user_email;
} else {
$email = 'web2project@web2project.net';
}
$mail->To($address);
$mail->Subject('New External User Created');
$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****');
$mail->Send();
}
}
?>