/** * Method used to add a new project to the system. * * @access public * @return integer 1 if the update worked, -1 or -2 otherwise */ function insert() { global $HTTP_POST_VARS; if (Validation::isWhitespace($HTTP_POST_VARS["title"])) { return -2; } $stmt = "INSERT INTO\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project\n (\n prj_created_date,\n prj_title,\n prj_status,\n prj_lead_usr_id,\n prj_initial_sta_id,\n prj_outgoing_sender_name,\n prj_outgoing_sender_email,\n prj_remote_invocation,\n prj_customer_backend,\n prj_workflow_backend\n ) VALUES (\n '" . Date_API::getCurrentDateGMT() . "',\n '" . Misc::escapeString($HTTP_POST_VARS["title"]) . "',\n '" . Misc::escapeString($HTTP_POST_VARS["status"]) . "',\n " . Misc::escapeInteger($HTTP_POST_VARS["lead_usr_id"]) . ",\n " . Misc::escapeInteger($HTTP_POST_VARS["initial_status"]) . ",\n '" . Misc::escapeString($HTTP_POST_VARS["outgoing_sender_name"]) . "',\n '" . Misc::escapeString($HTTP_POST_VARS["outgoing_sender_email"]) . "',\n '" . Misc::escapeString($HTTP_POST_VARS["remote_invocation"]) . "',\n '" . Misc::escapeString($HTTP_POST_VARS["customer_backend"]) . "',\n '" . Misc::escapeString($HTTP_POST_VARS["workflow_backend"]) . "'\n )"; $res = $GLOBALS["db_api"]->dbh->query($stmt); if (PEAR::isError($res)) { Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); return -1; } else { $new_prj_id = $GLOBALS["db_api"]->get_last_insert_id(); for ($i = 0; $i < count($HTTP_POST_VARS["users"]); $i++) { if ($HTTP_POST_VARS["users"][$i] == $HTTP_POST_VARS["lead_usr_id"]) { $role_id = User::getRoleID("Manager"); } else { $role_id = User::getRoleID("Standard User"); } Project::associateUser($new_prj_id, $HTTP_POST_VARS["users"][$i], $role_id); } foreach ($HTTP_POST_VARS['statuses'] as $sta_id) { Status::addProjectAssociation($sta_id, $new_prj_id); } Display_Column::setupNewProject($new_prj_id); return 1; } }
/** * Method used to add a new user to the system. * * @param array $user The array of user information * @return integer 1 if the update worked, -1 otherwise */ public static function insert($user) { $projects = array(); foreach ($user['role'] as $prj_id => $role) { if ($role < 1) { continue; } $projects[] = $prj_id; } $params = array(isset($user['customer_id']) ? $user['customer_id'] : null, isset($user['contact_id']) ? $user['contact_id'] : null, Date_Helper::getCurrentDateGMT(), Auth::hashPassword($user['password']), $user['full_name'], $user['email'], !empty($user['grp_id']) ? $user['grp_id'] : null, $user['external_id'], isset($user['par_code']) ? $user['par_code'] : null); $stmt = 'INSERT INTO {{%user}} ( usr_customer_id, usr_customer_contact_id, usr_created_date, usr_password, usr_full_name, usr_email, usr_grp_id, usr_external_id, usr_par_code ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ? )'; try { DB_Helper::getInstance()->query($stmt, $params); } catch (DbException $e) { return -1; } $new_usr_id = DB_Helper::get_last_insert_id(); // add the project associations! $projects = array(); foreach ($user['role'] as $prj_id => $role) { if ($role < 1) { continue; } Project::associateUser($prj_id, $new_usr_id, $role); $projects[] = $prj_id; } Prefs::set($new_usr_id, Prefs::getDefaults($projects)); // send email to user Notification::notifyNewUser($new_usr_id, $user['password']); return $new_usr_id; }
// | Authors: Bryan Alsdorf <*****@*****.**> | // +----------------------------------------------------------------------+ // // include_once "../../config.inc.php"; include_once APP_INC_PATH . "db_access.php"; include_once APP_INC_PATH . "class.customer.php"; include_once APP_INC_PATH . "class.user.php"; // creates user accounts for all the customers $prj_id = 1; $customers = Customer::getAssocList($prj_id); foreach ($customers as $customer_id => $customer_name) { echo "Customer: {$customer_name}<br />\n"; $details = Customer::getDetails($prj_id, $customer_id); foreach ($details['contacts'] as $contact) { echo "Contact: " . $contact['first_name'] . " " . $contact['last_name'] . " (" . $contact['email'] . ")<br />\n"; $contact_id = User::getUserIDByContactID($contact['contact_id']); if (empty($contact_id)) { $sql = "INSERT INTO\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "user\n SET\n usr_created_date = '" . Date_API::getCurrentDateGMT() . "',\n usr_full_name = '" . Misc::escapeString($contact['first_name'] . " " . $contact['last_name']) . "',\n usr_email = '" . $contact['email'] . "',\n usr_customer_id = " . $customer_id . ",\n usr_customer_contact_id = " . $contact['contact_id'] . ",\n usr_preferences = '" . Misc::escapeString(Prefs::getDefaults(array($prj_id))) . "'"; $res = $GLOBALS["db_api"]->dbh->query($sql); if (PEAR::isError($res)) { echo "Error inserting user<br /><pre>"; print_r($res); echo "</pre>"; } $new_usr_id = $GLOBALS['db_api']->get_last_insert_id(); Project::associateUser($prj_id, $new_usr_id, User::getRoleID("Customer")); } } echo "<hr />"; }
$prj_id = 1; // FIXME: Customer::getAssocList does not exist $customers = Customer::getAssocList($prj_id); foreach ($customers as $customer_id => $customer_name) { echo "Customer: {$customer_name}<br />\n"; $details = Customer::getDetails($prj_id, $customer_id); foreach ($details['contacts'] as $contact) { echo 'Contact: ' . $contact['first_name'] . ' ' . $contact['last_name'] . ' (' . $contact['email'] . ")<br />\n"; $contact_id = User::getUserIDByContactID($contact['contact_id']); if (empty($contact_id)) { $sql = 'INSERT INTO {{%user}} SET usr_created_date = ?, usr_full_name = ?, usr_email = ?, usr_customer_id = ?, usr_customer_contact_id = ?, usr_preferences = ?'; $params = array(Date_Helper::getCurrentDateGMT(), $contact['first_name'] . ' ' . $contact['last_name'], $contact['email'], $customer_id, $contact['contact_id'], Prefs::getDefaults(array($prj_id))); try { DB_Helper::getInstance()->query($sql, $params); } catch (DbException $e) { echo 'Error inserting user<br />'; } $new_usr_id = DB_Helper::get_last_insert_id(); Project::associateUser($prj_id, $new_usr_id, User::ROLE_CUSTOMER); } } echo '<hr />'; }
/** * Method used to add a new user to the system. * * @access public * @return integer 1 if the update worked, -1 otherwise */ function insert() { global $HTTP_POST_VARS; $projects = array(); foreach ($HTTP_POST_VARS["role"] as $prj_id => $role) { if ($role < 1) { continue; } $projects[] = $prj_id; } $fn = preg_split('/\\s+/', $HTTP_POST_VARS["full_name"], 2); $username = preg_split('/@/', $HTTP_POST_VARS["email"], 2); $prefs = Prefs::getDefaults($projects); $stmt = "INSERT INTO\n " . ETEL_USER_TABLE_NOSUB . "\n\t\t\t\tSET\n en_ev_customer_id = NULL,\n en_ev_contact_id = NULL,\n en_signup = '" . Date_API::getCurrentDateGMT() . "',\n en_username = '******',\n en_password = '******',\n en_firstname = '" . Misc::escapeString($fn[0]) . "',\n en_lastname = '" . Misc::escapeString($fn[1]) . "',\n en_email = '" . Misc::escapeString($HTTP_POST_VARS["email"]) . "',\n en_ev_pref = '" . Misc::escapeString($prefs) . "'\n "; $res = $GLOBALS["db_api"]->dbh->query($stmt); if (PEAR::isError($res)) { Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); return -1; } else { $new_usr_id = $GLOBALS["db_api"]->get_last_insert_id(); // add the project associations! foreach ($HTTP_POST_VARS["role"] as $prj_id => $role) { if ($role < 1) { continue; } Project::associateUser($prj_id, $new_usr_id, $role); } // send email to user Notification::notifyNewUser($new_usr_id, $HTTP_POST_VARS["password"]); return 1; } }