public function getLdapName($username) { if ($this->app['debug'] && !function_exists('ICFS\\Model\\ldap_get_names') && !function_exists('ldap_get_names')) { function ldap_get_names($username) { return array("First {$username}", "Last"); } } return ldap_get_names($username); }
function createuser($username, $mobile, $regmethod) { //These guys are here if we are running locally and want to do member ops which integrate with LDAP. if ($this->app['debug'] && !function_exists('ldap_get_names')) { function ldap_get_names($user) { return array('Dario', 'is sexy'); } } if ($this->app['debug'] && !function_exists('ldap_get_mail')) { function ldap_get_mail($user) { return '*****@*****.**'; } } if ($this->app['debug'] && !function_exists('ldap_get_info')) { function ldap_get_info($user) { return array("Exact Course Title", "Undergraduate", "Department", "Faculty", "Imperial College"); } } $names = ldap_get_names($username); if ($names) { if ($app['db']->executeQuery("SELECT * FROM members WHERE username = ?", array($username)) == 0) { $email = ldap_get_mail($username); $info = ldap_get_info($username); $time = time(); mysql_query("INSERT INTO 2011_Members (Username, Mobile, Forename, Surname, Department, Email, Reg_time, Reg_method)\n VALUES('{$username}', '{$mobile}', '{$names['0']}', '{$names['1']}', '{$info['2']}', '{$email}', NOW(), '{$regmethod}')"); return array("status" => true, "msg" => "Thank you, {$names['0']}! You are now on the Finance Society mailing list.", "already_mem" => false); } else { return array("status" => false, "msg" => "You appear be a member registered with us already.", "already_mem" => true, "first_name" => $names[0]); } } else { return array("status" => false, "msg" => "Sorry, that username does not exist.", "first_name" => $names[0], "already_mem" => false); } }
$DB_USER = '******'; $DB_PASS = ''; $mysqli = new mysqli($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME); if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit; } $result = $mysqli->query("SELECT DISTINCT(Username), Mobile, Reg_time, Reg_method FROM 2011_Members GROUP BY Username"); echo "We currently have {$result->num_rows} unique members\n"; $unique = $result->num_rows; $non_exist = 0; $added = 0; $values = NULL; $departmentless = array(); while ($row = $result->fetch_assoc()) { $names = ldap_get_names($row['Username']); if ($names) { $email = ldap_get_mail($row['Username']); $info = ldap_get_info($row['Username']); if (!$info['2']) { echo "Warning! {$row['Username']} appears to not be in any department.\n"; $departmentless[] = $row['Username']; } $values = $values . " ('{$row['Username']}', '{$row['Mobile']}', '{$info[2]}', '{$names[0]}', '{$names[1]}', '{$email}', '{$row['Reg_time']}', '{$row['Reg_method']}'),"; echo $names[0] . ' ' . $names[1] . " moved to new table\n"; $added++; } else { echo "Username {$row['Username']} appears to no longer exist.\n"; $non_exist++; } }