function createuser($user = null) { global $pref, $atmail, $settings, $domains; // If we are using LDAP, grab the user details via the LDAP server if ($pref['ldap_auth']) { $ldapuser = $this->ldap_auth_populate($this->username); // LDAP mod --- changed user[FirstName], & user[LastName] to user[Industry], & user[Occupation] $user['Industry'] = $ldapuser['FirstName']; $user['Occupation'] = $ldapuser['LastName']; $user['RealName'] = $ldapuser['RealName']; //echo $user['FirstName'] . ":" . $user['LastName'] . "\n"; } if (!$pref['crypt'] || !$atmail->isset_chk($domains[$this->pop3host])) { // Plaintext password $pass = $this->password; } else { // Encrypt the password $pass = crypt($this->password); } $this->SessionID = session_id(); // Load our table names $atmail->db->table_names($this->Account); // Log the time we created the account $time = time(); // Specify the 'default' user group if none exists if (!$user['UGroup']) { $user['UGroup'] = 'Default'; } // Purge any invalid entries in the DB $atmail->db->sqldo("delete from UserSession where Account=?", $this->Account); // Create a new SessionID for the user $query = "INSERT INTO UserSession (Account, Password, SessionID, LastLogin, PasswordMD5, SessionData) VALUES(?, ?, ?, ?, ?, ?)"; $data = array($this->Account, $pass, $this->SessionID, $time, md5($pass), ''); $res = $atmail->db->sqldo($query, $data); if ($res != 1) { return -1; } $settings['UseSSL'] = 0; // Select the MailType - SQL or Flatfile // All functions are based on what type of account the user has if (!$domains[$this->pop3host]) { $settings['MailType'] = $_REQUEST['MailType']; if (strpos($settings['MailType'], 's')) { $settings['UseSSL'] = 1; $settings['MailType'] = str_replace('s', '', $settings['MailType']); } } elseif ($pref['sql_type'] && $domains[$this->pop3host]) { $settings['MailType'] = 'sql'; } elseif (!$pref['sql_type'] && $domains[$this->pop3host]) { $settings['MailType'] = 'file'; } if ($pref['sql_type']) { $settings['Mode'] = 'sql'; } else { $settings['Mode'] = 'file'; } if (!$user['UserQuota']) { $user['UserQuota'] = $settings['UserQuota']; } // Build an SQL query for the new User $query = "INSERT INTO Users (UGroup, Address, BirthDay, BirthMonth, BirthYear, City, Country, TelHome,\r\n\t\t\t\t FaxHome, TelWork, FaxWork, TelMobile, TelPager, FirstName, Gender, Industry, LastName,\r\n\t\t\t\t Occupation, OtherEmail, PasswordQuestion, PostCode, State, DateCreate, UserStatus,\r\n\t\t\t\t Account, MailDir, UserQuota) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, {$atmail->db->NOW},\r\n\t\t\t\t ?, ?, ?, ?)"; if (empty($user['BirthYear'])) { $user['BirthYear'] = 0; } $data = array($user['UGroup'], $user['Address'], $user['BirthDay'], $user['BirthMonth'], $user['BirthYear'], $user['City'], $user['Country'], $user['TelHome'], $user['FaxHome'], $user['TelWork'], $user['FaxWork'], $user['TelMobile'], $user['TelPager'], $user['FirstName'], $user['Gender'], $user['Industry'], $user['LastName'], $user['Occupation'], $user['OtherEmail'], $user['PasswordQuestion'], $user['PostCode'], $user['State'], $pref['UserStatus'], $this->Account, $user['MailDir'], $user['UserQuota']); if ($atmail->db->sqldo($query, $data) != 1) { return -1; } // Build the query $insert = ''; $values = ''; $data = array(); // Insert the users settings foreach ($settings as $key => $value) { if ($key == 'UserQuota') { continue; } $insert .= Filter::cleanSqlFieldNames($key) . ','; $values .= '?,'; // Insert custom preferences for account, depending on the // new user form if ($key == "RealName") { $data[] = $user['FirstName'] . ' ' . $user['LastName']; } elseif ($key == "LoginType") { $data[] = $user['LoginType']; } elseif ($key == "Service") { $data[] = $user['Service']; } elseif ($key == "ReplyTo" && $atmail->isset_chk($_REQUEST['email'])) { $data[] = $_REQUEST['email']; } elseif ($key == "ReplyTo" && !$atmail->isset_chk($_REQUEST['email'])) { $data[] = $this->Account; } elseif ($key == "Language" && $atmail->isset_chk($_REQUEST['Language'])) { $data[] = $_REQUEST['Language']; } else { $data[] = $value; } } $user_settings = $atmail->db->get('UserSettings'); $query = "INSERT INTO {$user_settings} ({$insert} Account) values ({$values} ?)"; $data[] = $this->Account; if ($atmail->db->sqldo($query, $data) != 1) { return -1; } list($this->username, $this->pop3host) = explode('@', $this->Account); require_once 'GetMail.php'; //'Username' 'Pop3host' 'Type' 'Mode' $mail = new GetMail(array('Username' => $this->username, 'Pop3host' => $this->pop3host, 'Type' => $settings['MailType'], 'Mode' => 'sql', 'UseSSL' => $settings['UseSSL'])); $mail->login(); // Create the users default folders $folders = array('Inbox', 'Sent', 'Trash', 'Drafts', 'Spam'); foreach ($folders as $folder) { $mail->newfolder($folder); } return 1; }