changed git call from https to git readonly
[atutor.git] / mods / mahara / index.php
1 <?php\r
2 /*\r
3     This is the main page for the ATutor+Mahara module page.\r
4     It checks if the current user 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.php' is called which automatically sets up an\r
8     account with Mahara and saves the user information in ATutor's mahara table.\r
9     The page then automatically gets refreshed.\r
10 \r
11     by: Boon-Hau Teh\r
12 */\r
13 \r
14 \r
15 $_user_location = 'public';\r
16 \r
17 ob_start();  // we need this to be able to set cookies\r
18 \r
19 define('AT_INCLUDE_PATH', '../../include/');\r
20 require (AT_INCLUDE_PATH.'vitals.inc.php');\r
21 \r
22 \r
23 if ($_SESSION['is_guest'])\r
24     $msg->addFeedback ("MAHARA_LOGIN");\r
25 \r
26 require (AT_INCLUDE_PATH.'header.inc.php');\r
27 \r
28 \r
29 // Check if user is logged in as a guest\r
30 if (!($_SESSION['is_guest'])) {\r
31     // Read login info for Mahara\r
32     $sql    = "SELECT username, SHA1(password) FROM ".TABLE_PREFIX."mahara WHERE at_login='".$_SESSION['login']."'";\r
33     $result = mysql_query($sql, $db);\r
34 \r
35 \r
36     if (!($row = @mysql_fetch_array($result))) {\r
37         define('new_account', 1);\r
38 \r
39         // if not configured with ATutor, automatically register for account now\r
40         require('new_account.php');\r
41 \r
42         // refresh the page\r
43         header('Location: index.php');\r
44 \r
45     } else {\r
46         $username = $row[0];\r
47         $password = $row[1];\r
48 \r
49         // Login\r
50         ?>\r
51 \r
52         <?php\r
53         ATutor.setcookie("ATutor_Mahara[at_login]", $_SESSION['login'], time()+1200); \r
54         ATutor.setcookie("ATutor_Mahara[username]", $username, time()+1200); \r
55         ATutor.setcookie("ATutor_Mahara[password]", $password, time()+1200); \r
56 \r
57 \r
58         if (function_exists('url_rewrite')) {   // if "pretty url" feature supported (from ATutor 1.6.1)\r
59             $url = url_rewrite('mods/mahara/mahara_login.php', AT_PRETTY_URL_IS_HEADER);  // to be directly called in an iframe\r
60             $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
61         } else {\r
62             $url = AT_BASE_HREF.'mods/mahara/mahara_login.php';\r
63             $url_cookie_forward = AT_BASE_HREF.'mods/mahara/cookie.php';\r
64         }\r
65 \r
66         ?>\r
67             <script language='javascript' type='text/javascript'>\r
68             function iFrameHeight() {\r
69               var h = 0;\r
70                 if ( !document.all ) {\r
71                     h = document.getElementById('ATutorMahara').contentDocument.height;\r
72                     document.getElementById('ATutorMahara').style.height = h + 60 + 'px';\r
73                 } else if( document.all ) {\r
74                     h = document.frames('ATutorMahara').document.body.scrollHeight;\r
75                     document.all.ATutorMahara.style.height = h + 20 + 'px';\r
76                 }\r
77             }\r
78             function stopFrame(url, name, button) {\r
79                 // close iframe\r
80                 var ifr = document.getElementById(name);\r
81                 if (ifr)\r
82                     ifr.parentNode.removeChild(ifr);\r
83 \r
84                 // disable button\r
85                 var btn = document.getElementById(button);\r
86                 if (btn) {\r
87                     btn.value = '<?=_AT('mahara_opened')?>';\r
88                     btn.disabled = true;\r
89                 }\r
90 \r
91                 // open in new window\r
92                 window.open(url);\r
93             }\r
94             </script>\r
95             <div align="center">\r
96                 <input type="button" name="new_win" id="new_win" value= "<?=_AT('mahara_new_win')?>" onClick="stopFrame('<?php echo $url_cookie_forward;?>', 'ATutorMahara', 'new_win')" class="button" /><br /><br />\r
97             </div>\r
98             <iframe onload='iFrameHeight()' id='ATutorMahara' name='ATutorMahara'\r
99               src='<?=$url?>' width='100%' height='500' scrolling='auto' align='top' frameborder='0'>\r
100             </iframe>\r
101     <?php\r
102     }\r
103 }\r
104 \r
105 ob_end_flush();\r
106 \r
107 ?>\r
108 \r
109 <?php require (AT_INCLUDE_PATH.'footer.inc.php'); ?>\r