4 This belongs to the ATutor Mahara module page. It is called within an iframe or
\r
5 a new window from index.php and allows a user to access
\r
6 his/her ePortfolio account on Mahara through their account on ATutor.
\r
8 Login information for Mahara is passed using cookies (password encrypted in SHA1).
\r
9 This is to avoid conflicting sessions between ATutor and Mahara from within
\r
15 $_user_location = 'public';
\r
17 define('AT_INCLUDE_PATH', '../../include/');
\r
20 /*~~~~~~~~~~~~~few essentials copied from ATutor's vitals.inc.php~~~~~~~~~~~~*/
\r
22 /**** 0. start system configuration options block ****/
\r
24 if (!defined(AT_REDIRECT_LOADED)){
\r
25 include_once(AT_INCLUDE_PATH.'config.inc.php');
\r
27 error_reporting(AT_ERROR_REPORTING);
\r
29 if (!defined('AT_INSTALL') || !AT_INSTALL) {
\r
30 header('Cache-Control: no-store, no-cache, must-revalidate');
\r
31 header('Pragma: no-cache');
\r
33 $relative_path = substr(AT_INCLUDE_PATH, 0, -strlen('include/'));
\r
34 header('Location: ' . $relative_path . 'install/not_installed.php');
\r
38 /*** 1. constants ***/
\r
39 if (!defined(AT_REDIRECT_LOADED)){
\r
40 require_once(AT_INCLUDE_PATH.'lib/constants.inc.php');
\r
43 $db = @mysql_connect(DB_HOST . ':' . DB_PORT, DB_USER, DB_PASSWORD);
\r
45 /* AT_ERROR_NO_DB_CONNECT */
\r
46 require_once(AT_INCLUDE_PATH . 'classes/ErrorHandler/ErrorHandler.class.php');
\r
47 $err =& new ErrorHandler();
\r
48 trigger_error('VITAL#Unable to connect to db.', E_USER_ERROR);
\r
51 if (!@mysql_select_db(DB_NAME, $db)) {
\r
52 require_once(AT_INCLUDE_PATH . 'classes/ErrorHandler/ErrorHandler.class.php');
\r
53 $err =& new ErrorHandler();
\r
54 trigger_error('VITAL#DB connection established, but database "'.DB_NAME.'" cannot be selected.',
\r
59 /* get config variables. if they're not in the db then it uses the installation default value in constants.inc.php */
\r
60 $sql = "SELECT * FROM ".TABLE_PREFIX."config";
\r
61 $result = mysql_query($sql, $db);
\r
62 while ($row = mysql_fetch_assoc($result)) {
\r
63 $_config[$row['name']] = $row['value'];
\r
66 /***** 7. start language block *****/
\r
67 // set current language
\r
68 require(AT_INCLUDE_PATH . 'classes/Language/LanguageManager.class.php');
\r
69 $languageManager =& new LanguageManager();
\r
71 $myLang =& $languageManager->getMyLanguage();
\r
73 if ($myLang === FALSE) {
\r
74 echo 'There are no languages installed!';
\r
77 $myLang->saveToSession();
\r
78 if (isset($_GET['lang']) && $_SESSION['valid_user']) {
\r
79 if ($_SESSION['course_id'] == -1) {
\r
80 $myLang->saveToPreferences($_SESSION['login'], 1); //1 for admin
\r
82 $myLang->saveToPreferences($_SESSION['member_id'], 0); //0 for non-admin
\r
85 $myLang->sendContentTypeHeader();
\r
87 /* set right-to-left language */
\r
89 if ($myLang->isRTL()) {
\r
90 $rtl = 'rtl_'; /* basically the prefix to a rtl variant directory/filename. eg. rtl_tree */
\r
92 /***** end language block ****/
\r
94 /*~~~~~~~~~~~~~~~~~~~~~~~end of vitals.inc.php~~~~~~~~~~~~~~~~~~~~~~*/
\r
100 // Read Mahara login information from cookies passed by ATutor
\r
102 if (isset($_COOKIE['ATutor_Mahara'])) {
\r
103 foreach ($_COOKIE['ATutor_Mahara'] as $name => $value) {
\r
104 $usr[$name] = $value;
\r
106 // expire the cookie
\r
107 ATutor.setcookie ("ATutor_Mahara[".$name."]", "", time() - 3600);
\r
109 //expire the cookie array
\r
110 ATutor.setcookie ("ATutor_Mahara", "", time() - 3600);
\r
112 echo 'Unable to detect cookies or the session has timed out. Please check that cookies are enabled on your browser and try again.';
\r
116 // Get password from ATutor's database
\r
117 $sql = "SELECT password FROM ".TABLE_PREFIX."mahara WHERE at_login='".$usr["at_login"]."' AND username='".$usr["username"]."' AND SHA1(password)='".$usr["password"]."'";
\r
118 $result = mysql_query($sql, $db);
\r
119 if (!($row = @mysql_fetch_array($result))) {
\r
120 echo 'Incorrect login information. Please check with course instructor or administrator.';
\r
125 if (isset($_config['mahara'])) {
\r
127 /****** Taken from index.php of /mahara *****/
\r
128 define('INTERNAL', 1);
\r
129 define('PUBLIC', 1);
\r
130 define('MENUITEM', '');
\r
131 define (MAHARA_PATH, $_config['mahara']);
\r
132 require (MAHARA_PATH.'init.php');
\r
133 define('TITLE', get_string('home'));
\r
135 // Check if user exists in Mahara
\r
136 if (!(record_exists('usr', 'username', $usr["username"]))) {
\r
137 // Reconnect to ATutor Database and remove the record from the mahara table
\r
138 $db_atutor = @mysql_connect(DB_HOST . ':' . DB_PORT, DB_USER, DB_PASSWORD);
\r
140 /* AT_ERROR_NO_DB_CONNECT */
\r
141 require_once(AT_INCLUDE_PATH . 'classes/ErrorHandler/ErrorHandler.class.php');
\r
142 $err =& new ErrorHandler();
\r
143 trigger_error('VITAL#Unable to connect to db.', E_USER_ERROR);
\r
146 if (!@mysql_select_db(DB_NAME, $db_atutor)) {
\r
147 require_once(AT_INCLUDE_PATH . 'classes/ErrorHandler/ErrorHandler.class.php');
\r
148 $err =& new ErrorHandler();
\r
149 trigger_error('VITAL#DB connection established, but database "'.DB_NAME.'" cannot be selected.',
\r
154 // Delete record from ATutor database since it should not be there
\r
155 $sql = "DELETE FROM ".TABLE_PREFIX."mahara WHERE at_login='".$usr["at_login"]."'";
\r
157 $result = mysql_query($sql, $db_atutor);
\r
159 echo "Successfully synchronized user login with Mahara database. Please refresh the page from ATutor.";
\r
165 /*~~~~~~~~~~~copied from index.php of Mahara~~~~~~~~~~~~~~~*/
\r
166 // Check for whether the user is logged in, before processing the page. After
\r
167 // this, we can guarantee whether the user is logged in or not for this page.
\r
168 if (!$USER->is_logged_in()) {
\r
169 $lang = param_alphanumext('lang', null);
\r
170 if (!empty($lang)) {
\r
171 $SESSION->set('lang', $lang);
\r
174 // Read login information
\r
175 $values['login_username'] = $usr["username"];
\r
176 $values['login_password'] = $pwd;
\r
177 $values['submit'] = "Login";
\r
178 $values['sesskey'] = "";
\r
179 $values['pieform_login'] = "";
\r
182 login_submit(null, $values);
\r
184 $adminpage = ($USER->get('admin')) ? 'admin/' : '';
\r
187 /* Logged in session should be created. Now redirect to the Mahara page
\r
188 and it should read from this session
\r
190 header('Location: '.get_config('wwwroot').$adminpage);
\r
191 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
\r
193 echo 'You have incorrect config settings for the Mahara module.';
\r