3 This is the main page for the ATutor+Mahara module accessed by ATutor admins.
\r
4 It checks if the current admin is registered with Mahara by checking
\r
5 ATutor's 'mahara' table. If registered, an iframe is created to display
\r
6 the Mahara page ('mahara_login.php', a login script to the page also gets called).
\r
7 If not registered, 'new_account_admin.php' is called which automatically sets up an
\r
8 admin account with Mahara and saves the user information in ATutor's mahara table.
\r
9 The page then automatically gets refreshed.
\r
15 define('AT_INCLUDE_PATH', '../../include/');
\r
16 require (AT_INCLUDE_PATH.'vitals.inc.php');
\r
18 ob_start(); // we need this to be able to set cookies
\r
20 admin_authenticate(AT_ADMIN_PRIV_MAHARA);
\r
24 * Adds an ending slash to the given path, and differentiates
\r
25 * between windows and unix paths (keeps orginal slashes)
\r
27 * @param $string The path to some directory.
\r
28 * @return Returns the path in proper format with a trailing slash.
\r
29 * @author Boon-Hau Teh
\r
31 function add_ending_slash($path){
\r
32 // Check if last character is a slash
\r
33 //$last_char = substr($path, strlen($path)-1, 1);
\r
34 $last_char = $path[strlen($path)-1];
\r
35 if ($last_char != '/' && $last_char != '\\') {
\r
36 // determine if windows or unix
\r
37 $path .= (substr_count($path, '\\') > 0) ? '\\\\' : '/';
\r
45 if (isset($_POST['uri'])) {
\r
46 $mahara_path = add_ending_slash(trim($_POST['uri']));
\r
48 $msg->addError('MAHARA_MINURL_ADD_EMPTY');
\r
51 if (!$msg->containsErrors()) {
\r
52 // If Magic Quotes are not on, then add necessary slashes
\r
53 if (!get_magic_quotes_gpc())
\r
54 $mahara_path = addslashes($mahara_path);
\r
56 $sql = "REPLACE INTO ".TABLE_PREFIX."config VALUES ('mahara', '$mahara_path')";
\r
57 mysql_query($sql, $db);
\r
58 $msg->addFeedback('MAHARA_MINURL_ADD_SAVED');
\r
60 header('Location: '.$_SERVER['PHP_SELF']);
\r
65 if (isset($_config['mahara'])) {
\r
66 if (!file_exists($_config['mahara'].'config.php'))
\r
67 $msg->addError ("MAHARA_ERROR_PATH");
\r
70 require (AT_INCLUDE_PATH.'header.inc.php');
\r
74 <form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
\r
75 <div class="input-form">
\r
77 <p><label for="uri"><?php echo _AT('mahara_location'); ?></label></p>
\r
79 <input type="text" name="uri" value="<?php echo $_config['mahara']; ?>" id="uri" size="80" style="min-width: 95%;" />
\r
82 <div class="row buttons">
\r
83 <input type="submit" name="submit" value="<?php echo _AT('save'); ?>" />
\r
91 // Show iframe to Mahara if path is correct and user has access to admin site in Mahara
\r
93 // First check if path is correct
\r
94 if (isset($_config['mahara'])) {
\r
95 @include ($_config['mahara'].'config.php');
\r
98 // Now check for existing account on Mahara and if it's admin
\r
100 // Read login info for Mahara
\r
101 $sql = "SELECT username, SHA1(password) FROM ".TABLE_PREFIX."mahara WHERE at_login='".$_SESSION['login']."'";
\r
102 $result = mysql_query($sql, $db);
\r
104 if (!($row = @mysql_fetch_array($result))) {
\r
105 define('new_admin_account', 1);
\r
107 // if not configured with ATutor, automatically register for account now
\r
108 require('new_account_admin.php');
\r
110 // refresh the page
\r
111 header('Location: index_admin.php');
\r
114 $username = $row[0];
\r
115 $password = $row[1];
\r
121 ATutor.setcookie("ATutor_Mahara[at_login]", $_SESSION['login'], time()+1200);
\r
122 ATutor.setcookie("ATutor_Mahara[username]", $username, time()+1200);
\r
123 ATutor.setcookie("ATutor_Mahara[password]", $password, time()+1200);
\r
126 if (function_exists('url_rewrite')) { // if "pretty url" feature supported (from ATutor 1.6.1)
\r
127 $url = url_rewrite('mods/mahara/mahara_login.php', AT_PRETTY_URL_IS_HEADER); // to be directly called in an iframe
\r
128 $url_cookie_forward = url_rewrite('mods/mahara/cookie.php', AT_PRETTY_URL_IS_HEADER); // to be used in a new window and redirect to mahara_login.php
\r
130 $url = AT_BASE_HREF.'mods/mahara/mahara_login.php';
\r
131 $url_cookie_forward = AT_BASE_HREF.'mods/mahara/cookie.php';
\r
135 <script language='javascript' type='text/javascript'>
\r
136 function iFrameHeight() {
\r
138 if ( !document.all ) {
\r
139 h = document.getElementById('ATutorMahara').contentDocument.height;
\r
140 document.getElementById('ATutorMahara').style.height = h + 60 + 'px';
\r
141 } else if( document.all ) {
\r
142 h = document.frames('ATutorMahara').document.body.scrollHeight;
\r
143 document.all.ATutorMahara.style.height = h + 20 + 'px';
\r
147 <iframe onload='iFrameHeight()' id='ATutorMahara' name='ATutorMahara'
\r
148 src='<?=$url?>' width='100%' height='500' scrolling='auto' align='top' frameborder='0'>
\r
158 require (AT_INCLUDE_PATH.'footer.inc.php');
\r