removed mods directory from the ATutor codebase
[atutor.git] / mods / mahara / new_account_admin.php
diff --git a/mods/mahara/new_account_admin.php b/mods/mahara/new_account_admin.php
deleted file mode 100644 (file)
index 920576e..0000000
+++ /dev/null
@@ -1,281 +0,0 @@
-<?php\r
-\r
-/*\r
-    This belongs to the ATutor+Mahara module. It is called from index_admin.php when\r
-    the admin user does not have a Mahara account associated with ATutor.  This script\r
-    automatically creates a new Mahara admin account for the user and saves the login\r
-    information with ATutor.  If the user already has an admin Mahara account, the script\r
-    simply adds the login information to ATutor and reassigns an automatically\r
-    generated password for Mahara.\r
-\r
-    Most of the necessary code is copied and modified from init.php and\r
-    register.php of Mahara.\r
-\r
-    This script very similar to new_account.php except it deals with admin only\r
-    (ie. authenticates session for admin, reads from 'admins' table, and sets\r
-         'admin' value to 1 in the 'usr' table of Mahara)\r
-\r
-    by: Boon-Hau Teh\r
-*/\r
-\r
-$_user_location        = 'public';\r
-\r
-if (!defined('new_admin_account')) { exit; }\r
-if (!defined('AT_INCLUDE_PATH')) { exit; }\r
-if (!function_exists('admin_authenticate')) { exit; }\r
-\r
-admin_authenticate(AT_ADMIN_PRIV_MAHARA);\r
-\r
-$sql = 'SELECT * FROM '.TABLE_PREFIX.'admins WHERE login="'.$_SESSION['login'].'"';\r
-$result = mysql_query($sql, $db);\r
-$row = mysql_fetch_assoc($result);\r
-\r
-$registration->username     = $row['login'];\r
-if (isset($row['real_name']) && $row['real_name'] != '')\r
-    $registration->firstname    = $row['real_name'];\r
-else\r
-    $registration->firstname    = $row['login'];\r
-$registration->lastname     = ' ';           // mahara also requires lastname so enter a space char.\r
-$registration->password     = $row['password'];\r
-$registration->email        = $row['email'];\r
-\r
-define (MAHARA_PATH, $_config['mahara']);\r
-\r
-/******************from init.php*************************/\r
-define('INTERNAL', 1);\r
-define('PUBLIC', 1);\r
-define('SECTION_PLUGINTYPE', 'core');\r
-define('SECTION_PLUGINNAME', 'site');\r
-define('SECTION_PAGE', 'register');\r
-\r
-$CFG = new StdClass;\r
-$CFG->docroot = MAHARA_PATH;\r
-\r
-// Figure out our include path\r
-if (!empty($_SERVER['MAHARA_LIBDIR'])) {\r
-    $CFG->libroot = $_SERVER['MAHARA_LIBDIR'];\r
-} else {\r
-    $CFG->libroot = MAHARA_PATH. 'lib/';\r
-}\r
-set_include_path($CFG->libroot . PATH_SEPARATOR . $CFG->libroot . 'pear/' . PATH_SEPARATOR . get_include_path());\r
-\r
-// Set up error handling\r
-require(MAHARA_PATH.'lib/errors.php');\r
-\r
-if (!is_readable($CFG->docroot . 'config.php')) {\r
-    // @todo Later, this will redirect to the installer script. For now, we\r
-    // just log and exit.\r
-    log_environ(_AT('MAHARA_ERROR_INSTALL'));\r
-    header('Location: '.AT_BASE_HREF);\r
-}\r
-\r
-require(MAHARA_PATH.'config.php');\r
-$CFG = (object)array_merge((array)$cfg, (array)$CFG);\r
-\r
-// Fix up paths in $CFG\r
-foreach (array('docroot', 'dataroot') as $path) {\r
-    $CFG->{$path} = (substr($CFG->{$path}, -1) != DIRECTORY_SEPARATOR) ? $CFG->{$path} . DIRECTORY_SEPARATOR : $CFG->{$path};\r
-}\r
-\r
-// xmldb stuff\r
-$CFG->xmldbdisablenextprevchecking = true;\r
-$CFG->xmldbdisablecommentchecking = true;\r
-\r
-// ensure directorypermissions is set\r
-if (empty($CFG->directorypermissions)) {\r
-    $CFG->directorypermissions = 0700;\r
-}\r
-\r
-// core libraries\r
-require(MAHARA_PATH.'lib/mahara.php');\r
-ensure_sanity();\r
-require(MAHARA_PATH.'auth/internal/lib.php');\r
-require(MAHARA_PATH.'lib/dml.php');\r
-require(MAHARA_PATH.'lib/ddl.php');\r
-require(MAHARA_PATH.'lib/activity.php');\r
-require(MAHARA_PATH.'lib/user.php');\r
-require(MAHARA_PATH.'lib/web.php');\r
-\r
-// Database access functions\r
-require(MAHARA_PATH.'lib/adodb/adodb-exceptions.inc.php');\r
-require(MAHARA_PATH.'lib/adodb/adodb.inc.php');\r
-\r
-try {\r
-    // ADODB does not provide the raw driver error message if the connection\r
-    // fails for some reason, so we use output buffering to catch whatever\r
-    // the error is instead.\r
-    ob_start();\r
-    \r
-    $db = &ADONewConnection($CFG->dbtype);\r
-    $dbgenerator = null;\r
-    if (empty($CFG->dbhost)) {\r
-        $CFG->dbhost = '';\r
-    }\r
-    else if (!empty($CFG->dbport)) {\r
-        $CFG->dbhost .= ':'.$CFG->dbport;\r
-    }\r
-    if (!empty($CFG->dbpersist)) {    // Use persistent connection (default)\r
-        $dbconnected = $db->PConnect($CFG->dbhost,$CFG->dbuser,$CFG->dbpass,$CFG->dbname);\r
-    } \r
-    else {                                                     // Use single connection\r
-        $dbconnected = $db->Connect($CFG->dbhost,$CFG->dbuser,$CFG->dbpass,$CFG->dbname);\r
-    }\r
-\r
-    $db->SetFetchMode(ADODB_FETCH_ASSOC);\r
-    configure_dbconnection();\r
-    ensure_internal_plugins_exist();\r
-\r
-    ob_end_clean();\r
-}\r
-catch (Exception $e) {\r
-    $errormessage = ob_get_contents();\r
-    if (!$errormessage) {\r
-        $errormessage = $e->getMessage();\r
-    }\r
-    ob_end_clean();\r
-    $errormessage = get_string('dbconnfailed', 'error') . $errormessage;\r
-    throw new ConfigSanityException($errormessage);\r
-}\r
-try {\r
-    db_ignore_sql_exceptions(true);\r
-    load_config();\r
-    db_ignore_sql_exceptions(false);\r
-} \r
-catch (SQLException $e) {\r
-    db_ignore_sql_exceptions(false);\r
-}\r
-\r
-\r
-// Only do authentication once we know the page theme, so that the login form\r
-// can have the correct theming.\r
-require_once(MAHARA_PATH.'auth/lib.php');\r
-$USER    = new LiveUser();\r
-/***************end from init.php*************************/\r
-\r
-\r
-/*~~~~~~~~~modified from register.php~~~~~~~~~~*/\r
-$random_password = substr(md5($registration->password.rand(100000, 999999)), 2, 8);\r
-\r
-/*-- from register_submit function --*/\r
-$registration->salt         = substr(md5(rand(1000000, 9999999)), 2, 8);\r
-$registration->password     = AuthInternal::encrypt_password($random_password, $registration->salt);\r
-$registration->expiry       = NULL;\r
-/*-----------------------------------*/\r
-\r
-\r
-check_create_admin();\r
-\r
-\r
- /**\r
- * Uses global variable $registration and checks if the user\r
- * is registered in Mahara as an admin.  If so, the record is\r
- * updated.  If not, a new Mahara is created using the login name\r
- * or the login name appended by random characters (if the username\r
- * exists in Mahara but not as an admin).  This function recursively\r
- * calls itself until a Mahara account is created/updated.\r
- * @param   void\r
- * @access  private\r
- * @return  void\r
- * @author  Boon-Hau Teh\r
- */\r
-function check_create_admin() {\r
-    global $registration;\r
-\r
-    // Check if user already exists in Mahara\r
-    if ($data_record = get_record('usr', 'username', $registration->username)) {\r
-        // Check if user is an admin on Mahara as well\r
-        if ($data_record -> admin == 1) {\r
-            $registration -> id = $data_record -> id;\r
-            update_record('usr', $registration, 'username');\r
-        } else {\r
-            // create a new admin account with a different name\r
-            $registration->username = $_SESSION['login'].substr(md5(rand(100, 999)), 2, 5);\r
-            check_create_admin();   // Send register info to create a new account\r
-        }\r
-    } else {\r
-        create_admin_user();   // Send register info to create a new account\r
-    }\r
-}\r
-\r
-// Reconnect to ATutor Database\r
-$db_atutor = @mysql_connect(DB_HOST . ':' . DB_PORT, DB_USER, DB_PASSWORD);\r
-if (!$db_atutor) {\r
-    /* AT_ERROR_NO_DB_CONNECT */\r
-    require_once(AT_INCLUDE_PATH . 'classes/ErrorHandler/ErrorHandler.class.php');\r
-    $err =& new ErrorHandler();\r
-    trigger_error('VITAL#Unable to connect to db.', E_USER_ERROR);\r
-    exit;\r
-}\r
-if (!@mysql_select_db(DB_NAME, $db_atutor)) {\r
-    require_once(AT_INCLUDE_PATH . 'classes/ErrorHandler/ErrorHandler.class.php');\r
-    $err =& new ErrorHandler();\r
-    trigger_error('VITAL#DB connection established, but database "'.DB_NAME.'" cannot be selected.',\r
-                    E_USER_ERROR);\r
-    exit;\r
-}\r
-\r
-// Store data into ATutor Databse\r
-$sql = "INSERT INTO ".TABLE_PREFIX."mahara SET at_login='".$_SESSION['login']."', username='".$registration->username."', password='".$random_password."'";\r
-if (!mysql_query($sql, $db_atutor))\r
-    exit;                    // in case there's some external error; prevent being caught in an infinite loop\r
-\r
-\r
-/**\r
- * This function is copied and modified from register.php of Mahara to create an admin account\r
- *\r
- * @param array profilefields    Array of values from registration form. In this module, we're not using a form so we don't pass anything\r
- * @return boolean               Returns true if function exits without any problems\r
- */\r
-function create_admin_user($profilefields=array()) {\r
-    global $registration, $USER;\r
-\r
-    db_begin();\r
-\r
-    // Move the user record to the usr table from the registration table\r
-    $registrationid = $registration->id;\r
-    unset($registration->id);\r
-    unset($registration->expiry);\r
-    if ($expirytime = get_config('defaultaccountlifetime')) {\r
-        $registration->expiry = db_format_timestamp(time() + $expirytime);\r
-    }\r
-    $registration->lastlogin = db_format_timestamp(time());\r
-\r
-    $user = new User();\r
-    $user->username         = $registration->username;\r
-    $user->password         = $registration->password;\r
-    $user->salt             = $registration->salt;\r
-    $user->passwordchange   = 0;\r
-    $user->active           = 1;\r
-    $user->authinstance     = $authinstance->id;\r
-    $user->firstname        = $registration->firstname;\r
-    $user->lastname         = $registration->lastname;\r
-    $user->email            = $registration->email;\r
-    $user->admin            = 1;\r
-    $user->commit();\r
-\r
-    $registration->id = $user->id;\r
-\r
-    // Insert standard stuff as artefacts\r
-    set_profile_field($user->id, 'email', $registration->email);\r
-    set_profile_field($user->id, 'firstname', $registration->firstname);\r
-    set_profile_field($user->id, 'lastname', $registration->lastname);\r
-    if (!empty($registration->lang) && $registration->lang != 'default') {\r
-        set_account_preference($user->id, 'lang', $registration->lang);\r
-    }\r
-\r
-    // Set mandatory profile fields \r
-    foreach(ArtefactTypeProfile::get_mandatory_fields() as $field => $type) {\r
-        // @todo here and above, use the method for getting "always mandatory" fields\r
-        if (in_array($field, array('firstname', 'lastname', 'email'))) {\r
-            continue;\r
-        }\r
-        set_profile_field($user->id, $field, $profilefields[$field]);\r
-    }\r
-\r
-    db_commit();\r
-    handle_event('createuser', $registration);\r
-\r
-    return true;\r
-}\r
-\r
-?>
\ No newline at end of file