public static function createAccount($accountInfo, $isCurrentUser = false)
{
$accountInfo = Utils::sanitize($accountInfo);
$encryptionSalt = Core::getEncryptionSalt();
$accountType = $accountInfo["accountType"];
$firstName = isset($accountInfo["firstName"]) && !empty($accountInfo["firstName"]) ? $accountInfo["firstName"] : "";
$lastName = isset($accountInfo["lastName"]) && !empty($accountInfo["lastName"]) ? $accountInfo["lastName"] : "";
$email = isset($accountInfo["email"]) && !empty($accountInfo["email"]) ? $accountInfo["email"] : "";
$password = "";
if (isset($accountInfo["password"]) && !empty($accountInfo["password"])) {
$password = crypt($accountInfo["password"], $encryptionSalt);
}
// TODO - this is weird!
$autoEmail = isset($accountInfo["accountType"]) ? $accountInfo["accountType"] : false;
$L = Core::$language->getCurrentLanguageStrings();
$now = Utils::getCurrentDatetime();
$prefix = Core::getDbTablePrefix();
$selectedDataTypes = Settings::getSetting("installedDataTypes");
$selectedExportTypes = Settings::getSetting("installedExportTypes");
$selectedCountries = Settings::getSetting("installedCountries");
$result = Core::$db->query("\n\t\t\tINSERT INTO {$prefix}user_accounts (date_created, last_updated, date_expires, last_logged_in, account_type, \n\t\t\t\tfirst_name, last_name, email, password, selected_data_types, selected_export_types, selected_countries)\n\t\t\tVALUES ('{$now}', '{$now}', '{$now}', NULL, '{$accountType}', '{$firstName}', '{$lastName}', '{$email}', '{$password}',\n\t\t\t\t'{$selectedDataTypes}', '\${$selectedExportTypes}', '{$selectedCountries}')\n\t\t");
$emailSent = false;
// not used yet, but we should notify the user via the interface
if ($autoEmail) {
try {
$content = $L["account_created_msg"] . "\n\n";
if (isset($_SERVER["HTTP_REFERER"]) && !empty($_SERVER["HTTP_REFERER"])) {
$content .= "{$L["login_url_c"]} {$_SERVER["HTTP_REFERER"]}\n";
}
$content .= "{$L["email_c"]} {$email}\n{$L["password_c"]} {$accountInfo["password"]}\n";
Emails::sendEmail(array("recipient" => $email, "subject" => $L["account_created"], "content" => $content));
$emailSent = true;
} catch (Exception $e) {
$emailSent = false;
}
}
$returnInfo = array("success" => $result["success"]);
if ($result["success"]) {
$accountID = mysqli_insert_id(Core::$db->getDBLink());
if ($isCurrentUser) {
Core::initSessions();
$_SESSION["account_id"] = $accountID;
Core::initUser(true);
}
$returnInfo["accountID"] = $accountID;
}
return $returnInfo;
}