index.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  1. <?php
  2. /*
  3. DOKEOS - elearning and course management software
  4. For a full list of contributors, see documentation/credits.html
  5. This program is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public License
  7. as published by the Free Software Foundation; either version 2
  8. of the License, or (at your option) any later version.
  9. See "documentation/licence.html" more details.
  10. Contact:
  11. Dokeos
  12. Rue des Palais 44 Paleizenstraat
  13. B-1030 Brussels - Belgium
  14. Tel. +32 (2) 211 34 56
  15. */
  16. /**
  17. * @package dokeos.main
  18. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Refactoring
  19. * @version $Id: index.php 10580 2006-12-31 17:13:48Z pcool $
  20. * @todo check the different @todos in this page and really do them
  21. * @todo check if the news management works as expected
  22. */
  23. // only this script should have this constant defined. This is used to activate the javascript that
  24. // gives the login name automatic focus in header.inc.html.
  25. /** @todo Couldn't this be done using the $HtmlHeadXtra array? */
  26. define('DOKEOS_HOMEPAGE', true);
  27. // the language file
  28. $langFile = array ('courses', 'index');
  29. /* Flag forcing the 'current course' reset, as we're not inside a course anymore */
  30. // maybe we should change this into an api function? an example: Coursemanager::unset();
  31. $cidReset = true;
  32. // the section (for the tabs)
  33. $this_section = SECTION_CAMPUS;
  34. /*
  35. -----------------------------------------------------------
  36. Included libraries
  37. -----------------------------------------------------------
  38. */
  39. /** @todo make all the library files consistent use filename.lib.php and not filename.lib.inc.php */
  40. include_once ('./main/inc/global.inc.php');
  41. include_once (api_get_path(LIBRARY_PATH).'course.lib.php');
  42. include_once (api_get_path(LIBRARY_PATH).'debug.lib.inc.php');
  43. include_once (api_get_path(LIBRARY_PATH).'events.lib.inc.php');
  44. include_once (api_get_path(LIBRARY_PATH).'system_announcements.lib.php');
  45. include_once (api_get_path(LIBRARY_PATH).'groupmanager.lib.php');
  46. include_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  47. /*
  48. -----------------------------------------------------------
  49. Action Handling
  50. -----------------------------------------------------------
  51. */
  52. /** @todo wouldn't it make more sense if this would be done in local.inc.php so that local.inc.php become the only place where authentication is done?
  53. * by doing this you could logout from any page instead of only from index.php. From the moment there is a logout=true in the url you will be logged out
  54. * this can be usefull when you are on an open course and you need to log in to edit something and you immediately want to check how anonymous users
  55. * will see it.
  56. */
  57. if ($_GET['logout'])
  58. {
  59. logout();
  60. }
  61. /*
  62. -----------------------------------------------------------
  63. Table definitions
  64. -----------------------------------------------------------
  65. */
  66. $main_course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
  67. $main_category_table = Database :: get_main_table(TABLE_MAIN_CATEGORY);
  68. $track_login_table = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN);
  69. /*
  70. -----------------------------------------------------------
  71. Constants and CONFIGURATION parameters
  72. -----------------------------------------------------------
  73. */
  74. /** @todo these configuration settings should move to the dokeos config settings */
  75. /** defines wether or not anonymous visitors can see a list of the courses on the Dokeos homepage that are open to the world */
  76. $_setting['display_courses_to_anonymous_users'] = 'true';
  77. /** defines weither empty course categories should appear in the list with the course categories */
  78. $_setting['show_empty_course_categories'] = 'true';
  79. /** defines weither the number of open courses has to appear after the course category (faculty) */
  80. /** remark: actually count are only for direct children */
  81. $_setting['show_number_of_courses'] = 'false';
  82. /** Show the back link on top of the tree */
  83. $_setting['show_back_link_on_top_of_tree'] = 'false';
  84. /** Show the course language if it is not the same as the platform lanugage */
  85. $_setting['show_different_course_language'] = 'true';
  86. /** @todo remove this piece of code because this is not used */
  87. if (isset ($_user['user_id']))
  88. {
  89. $nameTools = api_get_setting('siteName');
  90. }
  91. /*
  92. ==============================================================================
  93. LOGIN
  94. ==============================================================================
  95. */
  96. /**
  97. * @todo This piece of code should probably move to local.inc.php where the actual login / logout procedure is handled.
  98. * @todo consider removing this piece of code because does nothing.
  99. */
  100. if ($_GET["submitAuth"] == 1)
  101. {
  102. // nice lie!!!
  103. echo "Attempted breakin - sysadmins notified.";
  104. session_destroy();
  105. die();
  106. }
  107. /**
  108. * @todo This piece of code should probably move to local.inc.php where the actual login procedure is handled.
  109. * @todo check if this code is used. I think this code is never executed because after clicking the submit button
  110. * the code does the stuff in local.inc.php and then redirects to index.php or user_portal.php depending
  111. * on api_get_setting('page_after_login')
  112. */
  113. if ($_POST["submitAuth"])
  114. {
  115. // the user is already authenticated, we now find the last login of the user.
  116. if (isset ($_user['user_id']))
  117. {
  118. $sql_last_login = "SELECT UNIX_TIMESTAMP(login_date)
  119. FROM $track_login_table
  120. WHERE login_user_id = '".$_user['user_id']."'
  121. ORDER BY login_date DESC LIMIT 1";
  122. $result_last_login = api_sql_query($sql_last_login, __FILE__, __LINE__);
  123. if (!$result_last_login)
  124. if (mysql_num_rows($result_last_login) > 0)
  125. {
  126. $user_last_login_datetime = mysql_fetch_array($result_last_login);
  127. $user_last_login_datetime = $user_last_login_datetime[0];
  128. api_session_register('user_last_login_datetime');
  129. }
  130. mysql_free_result($result_last_login);
  131. //event_login();
  132. if (api_is_platform_admin())
  133. {
  134. // decode all open event informations and fill the track_c_* tables
  135. include (api_get_path(LIBRARY_PATH)."stats.lib.inc.php");
  136. decodeOpenInfos();
  137. }
  138. }
  139. } // end login -- if($_POST["submitAuth"])
  140. else
  141. {
  142. // only if login form was not sent because if the form is sent the user was already on the page.
  143. event_open();
  144. }
  145. // the header
  146. Display :: display_header('', 'dokeos');
  147. /*
  148. ==============================================================================
  149. MAIN CODE
  150. ==============================================================================
  151. */
  152. echo '<div class="maincontent">';
  153. // Plugins for loginpage_main AND campushomepage_main
  154. if (!api_get_user_id())
  155. {
  156. api_plugin('loginpage_main');
  157. }
  158. else
  159. {
  160. api_plugin('campushomepage_main');
  161. }
  162. // Including the page for the news
  163. if (!empty ($_GET['include']) && !strstr($_GET['include'], '/') && strstr($_GET['include'], '.html'))
  164. {
  165. include ('./home/'.$_GET['include']);
  166. $page_included = true;
  167. }
  168. else
  169. {
  170. if(!file_exists('home/home_news_'.$user_selected_language.'.html'))
  171. {
  172. include ('home/home_top.html');
  173. }
  174. else
  175. {
  176. include('home/home_top_'.$user_selected_language.'.html');
  177. }
  178. }
  179. // Display System announcements
  180. $announcement = $_GET['announcement'] ? $_GET['announcement'] : -1;
  181. SystemAnnouncementManager :: display_announcements(VISIBLE_GUEST, $announcement);
  182. // Display courses and category list
  183. if (!$page_included)
  184. {
  185. if (api_get_setting('display_courses_to_anonymous_users') == 'true')
  186. {
  187. echo '<div class="home_cats">';
  188. display_anonymous_course_list();
  189. echo '</div>';
  190. }
  191. }
  192. echo '</div>';
  193. // display right menu: language form, login section + useful weblinks
  194. echo '<div class="menu">';
  195. display_anonymous_right_menu();
  196. echo '</div>';
  197. /*
  198. ==============================================================================
  199. FOOTER
  200. ==============================================================================
  201. */
  202. Display :: display_footer();
  203. /**
  204. * This function handles the logout and is called whenever there is a $_GET['logout']
  205. *
  206. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  207. */
  208. function logout()
  209. {
  210. // variable initialisation
  211. $query_string='';
  212. if(!empty($_SESSION['user_language_choice']))
  213. {
  214. $query_string='?language='.$_SESSION['user_language_choice'];
  215. }
  216. // Database table definition
  217. $tbl_track_login = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN);
  218. // selecting the last login of the user
  219. $sql_last_connection="SELECT login_id, login_date FROM $tbl_track_login WHERE login_user_id='".$_GET["uid"]."' ORDER BY login_date DESC LIMIT 0,1";
  220. $q_last_connection=mysql_query($sql_last_connection);
  221. $i_id_last_connection=mysql_result($q_last_connection,0,"login_id");
  222. $s_sql_update_logout_date="UPDATE $tbl_track_login SET logout_date=NOW() WHERE login_id='$i_id_last_connection'";
  223. api_sql_query($s_sql_update_logout_date);
  224. //LoginDelete(".$_user['user_id'].", $_configuration['statistics_database']);
  225. LoginDelete($_GET["uid"], $_configuration['statistics_database']);
  226. api_session_destroy();
  227. header("Location: index.php$query_string");
  228. exit();
  229. }
  230. /**
  231. * This function checks if there are courses that are open to the world in the platform course categories (=faculties)
  232. *
  233. * @param unknown_type $category
  234. * @return boolean
  235. */
  236. function category_has_open_courses($category)
  237. {
  238. $main_course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
  239. $sql_query = "SELECT * FROM $main_course_table WHERE category_code='$category'";
  240. $sql_result = api_sql_query($sql_query, __FILE__, __LINE__);
  241. while ($course = mysql_fetch_array($sql_result))
  242. {
  243. if ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD)
  244. {
  245. return true; //at least one open course
  246. }
  247. }
  248. return false;
  249. }
  250. /**
  251. * Displays the right-hand menu for anonymous users:
  252. * login form, useful links, help section
  253. * Warning: function defines globals
  254. * @version 1.0.1
  255. * @todo does $_plugins need to be global?
  256. */
  257. function display_anonymous_right_menu()
  258. {
  259. global $loginFailed, $_plugins, $_user;
  260. $platformLanguage = api_get_setting('platformLanguage');
  261. if ( !($_user['user_id']) ) // only display if the user isn't logged in
  262. {
  263. api_display_language_form();
  264. echo '<br />';
  265. display_login_form();
  266. if ($loginFailed)
  267. {
  268. handle_login_failed();
  269. }
  270. if (api_get_setting('allow_lostpassword') == 'true' OR api_get_setting('allow_registration') == 'true')
  271. {
  272. echo '<div class="menusection"><span class="menusectioncaption">'.get_lang('MenuUser').'</span><ul class="menulist">';
  273. if (get_setting('allow_registration') <> 'false')
  274. {
  275. echo '<li><a href="main/auth/inscription.php">'.get_lang('Reg').'</a></li>';
  276. }
  277. if (get_setting('allow_lostpassword') == 'true')
  278. {
  279. display_lost_password_info();
  280. }
  281. echo '</ul></div>';
  282. }
  283. echo '<div class="note" style="background: none">';
  284. api_plugin('loginpage_menu');
  285. echo '</div>';
  286. }
  287. /*** hide right menu "general" and other parts on anonymous right menu *****/
  288. echo "<div class=\"menusection\">", "<span class=\"menusectioncaption\">".get_lang("MenuGeneral")."</span>";
  289. echo "<ul class=\"menulist\">";
  290. $user_selected_language = $_SESSION["user_language_choice"];
  291. if (!isset ($user_selected_language))
  292. $user_selected_language = $platformLanguage;
  293. if(!file_exists('home/home_menu_'.$user_selected_language.'.html'))
  294. {
  295. include ('home/home_menu.html');
  296. }
  297. else
  298. {
  299. include('home/home_menu_'.$user_selected_language.'.html');
  300. }
  301. echo '</ul>';
  302. echo '</div>';
  303. if ($_user['user_id'])
  304. {
  305. echo '<div class="note" style="background: none">';
  306. api_plugin('campushomepage_menu');
  307. echo '</div>';
  308. }
  309. /**** use this comment to hide notice file section from right menu ****
  310. echo '<div class="note">';
  311. // includes for any files to be displayed below anonymous right menu
  312. if(!file_exists('home/home_notice_'.$user_selected_language.'.html'))
  313. {
  314. include ('home/home_notice.html');
  315. }
  316. else
  317. {
  318. include('home/home_notice_'.$user_selected_language.'.html');
  319. }
  320. echo '</div>';
  321. **** end of hide various right menu items on anonymous right menu ****/
  322. }
  323. /**
  324. * Reacts on a failed login:
  325. * displays an explanation with
  326. * a link to the registration form.
  327. *
  328. * @version 1.0.1
  329. */
  330. function handle_login_failed()
  331. {
  332. switch ($_GET['error'])
  333. {
  334. case '':
  335. $message = get_lang("InvalidId");
  336. if (api_is_self_registration_allowed())
  337. {
  338. $message = get_lang("InvalidForSelfRegistration");
  339. }
  340. break;
  341. case 'account_expired':
  342. $message=get_lang('AccountExpired');
  343. break;
  344. case 'account_inactive':
  345. $message=get_lang('AccountInactive');
  346. break;
  347. case 'user_password_incorrect':
  348. $message=get_lang('InvalidId');
  349. break;
  350. }
  351. echo "<div id=\"login_fail\">".$message."</div>";
  352. }
  353. /**
  354. * Adds a form to let users login
  355. * @version 1.1
  356. */
  357. function display_login_form()
  358. {
  359. $form = new FormValidator('formLogin');
  360. $form->addElement('text','login',get_lang('UserName'),array('size'=>15));
  361. $form->addElement('password','password',get_lang('Pass'),array('size'=>15));
  362. $form->addElement('submit','submitAuth',get_lang('Ok'));
  363. $renderer =& $form->defaultRenderer();
  364. $element_template = '<!-- BEGIN required --><span class="form_required">*</span> <!-- END required -->{label}<br />
  365. <!-- BEGIN error --><span class="form_error">{error}</span><br /><!-- END error --> {element}<br />';
  366. $renderer->setElementTemplate($element_template);
  367. $form->display();
  368. }
  369. /**
  370. * Displays a link to the lost password section
  371. */
  372. function display_lost_password_info()
  373. {
  374. echo "<li><a href=\"main/auth/lostPassword.php\">".get_lang("LostPassword")."</a></li>";
  375. }
  376. /**
  377. * Display list of courses in a category.
  378. * (for anonymous users)
  379. *
  380. * @version 1.1
  381. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University - refactoring and code cleaning
  382. */
  383. function display_anonymous_course_list()
  384. {
  385. //init
  386. $web_course_path = api_get_path(WEB_COURSE_PATH);
  387. $category = $_GET["category"];
  388. // Database table definitions
  389. $main_course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
  390. $main_category_table = Database :: get_main_table(TABLE_MAIN_CATEGORY);
  391. $platformLanguage = api_get_setting('platformLanguage');
  392. //get list of courses in category $category
  393. $sql_get_course_list = "SELECT * FROM $main_course_table cours
  394. WHERE category_code = '".mysql_real_escape_string($_GET["category"])."'
  395. ORDER BY UPPER(visual_code)";
  396. //removed: AND cours.visibility='".COURSE_VISIBILITY_OPEN_WORLD."'
  397. $sql_result_courses = api_sql_query($sql_get_course_list, __FILE__, __LINE__);
  398. while ($course_result = mysql_fetch_array($sql_result_courses))
  399. {
  400. $course_list[] = $course_result;
  401. }
  402. $sqlGetSubCatList = "
  403. SELECT t1.name,t1.code,t1.parent_id,t1.children_count,COUNT(DISTINCT t3.code) AS nbCourse
  404. FROM $main_category_table t1
  405. LEFT JOIN $main_category_table t2 ON t1.code=t2.parent_id
  406. LEFT JOIN $main_course_table t3 ON (t3.category_code=t1.code AND t3.visibility='".COURSE_VISIBILITY_OPEN_WORLD."')
  407. WHERE t1.parent_id ". (empty ($category) ? "IS NULL" : "='$category'")."
  408. GROUP BY t1.name,t1.code,t1.parent_id,t1.children_count ORDER BY t1.tree_pos";
  409. $resCats = api_sql_query($sqlGetSubCatList, __FILE__, __LINE__);
  410. $thereIsSubCat = FALSE;
  411. if (mysql_num_rows($resCats) > 0)
  412. {
  413. $htmlListCat = "<h4 style=\"margin-top: 0px;\">".get_lang("CatList")."</h4>"."<ul>";
  414. while ($catLine = mysql_fetch_array($resCats))
  415. {
  416. if ($catLine['code'] != $category)
  417. {
  418. $htmlListCat .= "<li>";
  419. $category_has_open_courses = category_has_open_courses($catLine['code']);
  420. if ($category_has_open_courses)
  421. {
  422. //the category contains courses accessible to anonymous visitors
  423. $htmlListCat .= "<a href=\"".$_SERVER['PHP_SELF']."?category=".$catLine['code']."\">".$catLine['name']."</a>";
  424. if (get_setting('show_number_of_courses') == 'true')
  425. {
  426. $htmlListCat .= " (".$catLine['nbCourse']." ".get_lang("Courses").")";
  427. }
  428. }
  429. elseif ($catLine['children_count'] > 0)
  430. {
  431. //the category has children, subcategories
  432. $htmlListCat .= "<a href=\"".$_SERVER['PHP_SELF']."?category=".$catLine['code']."\">".$catLine['name']."</a>";
  433. }
  434. /************************************************************************
  435. end changed code to eliminate the (0 courses) after empty categories
  436. ************************************************************************/
  437. elseif (get_setting('show_empty_course_categories') == 'true')
  438. {
  439. $htmlListCat .= $catLine['name'];
  440. }
  441. $htmlListCat .= "</li>\n";
  442. $thereIsSubCat = true;
  443. }
  444. else
  445. {
  446. $htmlTitre = "<p>";
  447. if ($_setting['show_back_link_on_top_of_tree'] == 'true')
  448. {
  449. $htmlTitre .= "<a href=\"".$_SERVER['PHP_SELF']."\">"."&lt;&lt; ".get_lang("BackToHomePage")."</a>";
  450. }
  451. if (!is_null($catLine['parent_id']) || ($_setting['show_back_link_on_top_of_tree'] <> 'true' && !is_null($catLine['code'])))
  452. {
  453. $htmlTitre .= "<a href=\"".$_SERVER['PHP_SELF']."?category=".$catLine['parent_id']."\">"."&lt;&lt; ".get_lang("Up")."</a>";
  454. }
  455. $htmlTitre .= "</p>\n";
  456. if ($category != "" && !is_null($catLine['code']))
  457. {
  458. $htmlTitre .= "<h3>".$catLine['name']."</h3>\n";
  459. }
  460. else
  461. {
  462. $htmlTitre .= "<h3>".get_lang("Categories")."</h3>\n";
  463. }
  464. }
  465. }
  466. $htmlListCat .= "</ul>\n";
  467. }
  468. echo $htmlTitre;
  469. if ($thereIsSubCat)
  470. {
  471. echo $htmlListCat;
  472. }
  473. while ($categoryName = mysql_fetch_array($resCats))
  474. {
  475. echo "<h3>", $categoryName['name'], "</h3>\n";
  476. }
  477. $numrows = mysql_num_rows($sql_result_courses);
  478. if ($numrows > 0)
  479. {
  480. if ($thereIsSubCat)
  481. {
  482. echo "<hr size=\"1\" noshade=\"noshade\">\n";
  483. }
  484. echo "<h4 style=\"margin-top: 0px;\">", get_lang("CourseList"), "</h4>\n", "<ul>\n";
  485. while ($course = mysql_fetch_array($sql_result_courses))
  486. {
  487. echo "<li>\n";
  488. echo "<a href=\"".$web_course_path.$course['directory'], "/\">", $course['title'], "</a>";
  489. echo "<br/>", $course['visual_code'], " - ", $course['tutor_name'];
  490. if ($_setting['show_different_course_language'] == 'true' && $course['course_language'] <> api_get_setting('platformLanguage'))
  491. {
  492. echo ' - '.$course['course_language'];
  493. }
  494. echo "</li>\n";
  495. }
  496. echo "</ul>\n";
  497. }
  498. else
  499. {
  500. // echo "<blockquote>",get_lang('_No_course_publicly_available'),"</blockquote>\n";
  501. }
  502. if ($category != "")
  503. {
  504. echo "<p>", "<a href=\"".$_SERVER['PHP_SELF']."\"><b>&lt;&lt;</b> ", get_lang("BackToHomePage"), "</a>", "</p>\n";
  505. }
  506. }
  507. ?>