index.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  1. <?php
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004-2005 Dokeos S.A.
  6. Copyright (c) 2003 Ghent University (UGent)
  7. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  8. Copyright (c) various contributors
  9. For a full list of contributors, see "credits.txt".
  10. The full license can be read in "license.txt".
  11. This program is free software; you can redistribute it and/or
  12. modify it under the terms of the GNU General Public License
  13. as published by the Free Software Foundation; either version 2
  14. of the License, or (at your option) any later version.
  15. See the GNU General Public License for more details.
  16. Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium
  17. Mail: info@dokeos.com
  18. ==============================================================================
  19. */
  20. /**
  21. ==============================================================================
  22. * This is the index file displayed when a user arrives at Dokeos.
  23. *
  24. * It dispalys:
  25. * - tree of courses and categories
  26. * - login form
  27. * - public menu
  28. *
  29. * Search for
  30. * CONFIGURATION parameters
  31. * to modify settings
  32. *
  33. * @todo rewrite code to separate display, logic, database code
  34. * @package dokeos.main
  35. ==============================================================================
  36. */
  37. /*
  38. ==============================================================================
  39. INIT SECTION
  40. ==============================================================================
  41. */
  42. // only this script should have this constant defined
  43. define('DOKEOS_HOMEPAGE', true);
  44. // Don't change these settings
  45. define("SCRIPTVAL_No", 0);
  46. define("SCRIPTVAL_InCourseList", 1);
  47. define("SCRIPTVAL_UnderCourseList", 2);
  48. define("SCRIPTVAL_Both", 3);
  49. define("SCRIPTVAL_NewEntriesOfTheDay", 4);
  50. define("SCRIPTVAL_NewEntriesOfTheDayOfLastLogin", 5);
  51. define("SCRIPTVAL_NoTimeLimit", 6);
  52. // End 'don't change' section
  53. $langFile = array ('courses', 'index');
  54. $cidReset = true; /* Flag forcing the 'current course' reset,
  55. as we're not inside a course anymore */
  56. /*
  57. -----------------------------------------------------------
  58. Included libraries
  59. -----------------------------------------------------------
  60. */
  61. //this includes main_api too:
  62. include_once ('./main/inc/global.inc.php');
  63. $this_section = SECTION_CAMPUS;
  64. include_once (api_get_path(LIBRARY_PATH).'course.lib.php');
  65. include_once (api_get_path(LIBRARY_PATH).'debug.lib.inc.php');
  66. include_once (api_get_path(LIBRARY_PATH).'events.lib.inc.php');
  67. include_once (api_get_path(LIBRARY_PATH).'system_announcements.lib.php');
  68. include_once (api_get_path(LIBRARY_PATH).'groupmanager.lib.php');
  69. include_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  70. if ($_GET['logout'])
  71. {
  72. $query_string='';
  73. if(!empty($_SESSION['user_language_choice']))
  74. {
  75. $query_string='?language='.$_SESSION['user_language_choice'];
  76. }
  77. //LoginDelete($_uid, $statsDbName);
  78. LoginDelete($_GET["uid"], $statsDbName);
  79. api_session_destroy();
  80. header("Location: index.php$query_string");
  81. exit();
  82. }
  83. /*
  84. -----------------------------------------------------------
  85. Table definitions
  86. -----------------------------------------------------------
  87. */
  88. //new table definitions, using database library
  89. //these already have backticks around them!
  90. $main_course_table = Database :: get_main_table(MAIN_COURSE_TABLE);
  91. $main_category_table = Database :: get_main_table(MAIN_CATEGORY_TABLE);
  92. $track_login_table = Database :: get_statistic_table(STATISTIC_TRACK_E_LOGIN_TABLE);
  93. /*
  94. -----------------------------------------------------------
  95. Constants and CONFIGURATION parameters
  96. -----------------------------------------------------------
  97. */
  98. // ---- Category list options ----
  99. /** defines wether or not anonymous visitors can see a list of the courses on
  100. the Dokeos homepage that are open to the world */
  101. define('DISPLAY_COURSES_TO_ANONYMOUS_USERS', true);
  102. define('CONFVAL_showNodeEmpty', true);
  103. define('CONFVAL_showNumberOfChild', false); // actually count are only for direct children
  104. define('CONFVAL_ShowLinkBackToTopOfTree', false);
  105. // ---- Course list options ----
  106. define("CONFVAL_showCourseLangIfNotSameThatPlatform", TRUE);
  107. // Preview of course content
  108. // to disable all: set CONFVAL_maxTotalByCourse = 0
  109. // to enable all: set e.g. CONFVAL_maxTotalByCourse = 5
  110. // by default disabled since what's new icons are better (see function display_digest() )
  111. define("CONFVAL_maxValvasByCourse", 2); // Maximum number of entries
  112. define("CONFVAL_maxAgendaByCourse", 2); // collected from each course
  113. define("CONFVAL_maxTotalByCourse", 0); // and displayed in summary.
  114. define("CONFVAL_NB_CHAR_FROM_CONTENT", 80);
  115. // Order to sort data
  116. $orderKey = array('keyTools', 'keyTime', 'keyCourse'); // default "best" Choice
  117. //$orderKey = array('keyTools', 'keyCourse', 'keyTime');
  118. //$orderKey = array('keyCourse', 'keyTime', 'keyTools');
  119. //$orderKey = array('keyCourse', 'keyTools', 'keyTime');
  120. define('CONFVAL_showExtractInfo', SCRIPTVAL_UnderCourseList);
  121. // SCRIPTVAL_InCourseList // best choice if $orderKey[0] == 'keyCourse'
  122. // SCRIPTVAL_UnderCourseList // best choice
  123. // SCRIPTVAL_Both // probably only for debug
  124. //$dateFormatForInfosFromCourses = $dateFormatShort;
  125. $dateFormatForInfosFromCourses = $dateFormatLong;
  126. //define("CONFVAL_limitPreviewTo",SCRIPTVAL_NewEntriesOfTheDay);
  127. //define("CONFVAL_limitPreviewTo",SCRIPTVAL_NoTimeLimit);
  128. define("CONFVAL_limitPreviewTo", SCRIPTVAL_NewEntriesOfTheDayOfLastLogin);
  129. if (isset ($_uid))
  130. {
  131. $nameTools = api_get_setting('siteName');
  132. }
  133. /*
  134. -----------------------------------------------------------
  135. Check configuration parameters integrity
  136. -----------------------------------------------------------
  137. */
  138. if (CONFVAL_showExtractInfo != SCRIPTVAL_UnderCourseList and $orderKey[0] != "keyCourse")
  139. {
  140. // CONFVAL_showExtractInfo must be SCRIPTVAL_UnderCourseList to accept $orderKey[0] !="keyCourse"
  141. if (DEBUG || api_is_platform_admin()) // Show bug if admin. Else force a new order
  142. die("
  143. <strong>
  144. config error:".__FILE__."</strong>
  145. <br/>
  146. set
  147. <ul>
  148. <li>
  149. CONFVAL_showExtractInfo=SCRIPTVAL_UnderCourseList
  150. (actually : ".CONFVAL_showExtractInfo.")
  151. </li>
  152. </ul>
  153. or
  154. <ul>
  155. <li>
  156. \$orderKey[0] !=\"keyCourse\"
  157. (actually : ".$orderKey[0].")
  158. </li>
  159. </ul>");
  160. else
  161. {
  162. $orderKey = array ("keyCourse", "keyTools", "keyTime");
  163. }
  164. }
  165. /*
  166. ==============================================================================
  167. LOGIN
  168. ==============================================================================
  169. */
  170. if ($_GET["submitAuth"] == 1)
  171. {
  172. echo "Attempted breakin - sysadmins notified.";
  173. session_destroy();
  174. die();
  175. }
  176. if ($_POST["submitAuth"])
  177. {
  178. // To ensure legacy compatibility, we set the following variables.
  179. // But they should be removed at last.
  180. $uid = $_uid;
  181. $lastname = $_user['lastName'];
  182. $firstname = $_user['firstName'];
  183. $email = $_user['mail'];
  184. $status = $uData['status'];
  185. if (isset ($_uid))
  186. {
  187. $sqlLastLogin = "SELECT UNIX_TIMESTAMP(login_date)
  188. FROM $track_login_table
  189. WHERE login_user_id = '$_uid'
  190. ORDER BY login_date DESC LIMIT 1";
  191. $resLastLogin = api_sql_query($sqlLastLogin, __FILE__, __LINE__);
  192. if (!$resLastLogin)
  193. if (mysql_num_rows($resLastLogin) > 0)
  194. {
  195. $user_last_login_datetime = mysql_fetch_array($resLastLogin);
  196. $user_last_login_datetime = $user_last_login_datetime[0];
  197. api_session_register('user_last_login_datetime');
  198. }
  199. mysql_free_result($resLastLogin);
  200. event_login();
  201. if (api_is_platform_admin())
  202. {
  203. // decode all open event informations and fill the track_c_* tables
  204. include (api_get_path(LIBRARY_PATH)."stats.lib.inc.php");
  205. decodeOpenInfos();
  206. }
  207. }
  208. } // end login -- if($submit)
  209. else
  210. {
  211. // only if login form was not sent because if the form is sent the user was
  212. // already on the page.
  213. event_open();
  214. }
  215. /*
  216. -----------------------------------------------------------
  217. Header
  218. include the HTTP, HTML headers plus the top banner
  219. -----------------------------------------------------------
  220. */
  221. $help = "Clar";
  222. Display :: display_header('', $help);
  223. /*
  224. ==============================================================================
  225. FUNCTIONS
  226. display_anonymous_right_menu()
  227. display_anonymous_course_list()
  228. display_login_form()
  229. handle_login_failed()
  230. display_lost_password_info()
  231. ==============================================================================
  232. */
  233. /*
  234. -----------------------------------------------------------
  235. Display functions
  236. -----------------------------------------------------------
  237. */
  238. /**
  239. * Displays the right-hand menu for anonymous users:
  240. * login form, useful links, help section
  241. * Warning: function defines globals
  242. * @version 1.0.1
  243. */
  244. function display_anonymous_right_menu()
  245. {
  246. global $loginFailed, $_plugins;
  247. $platformLanguage = api_get_setting('platformLanguage');
  248. $_uid = api_get_user_id();
  249. if ( !(isset($_uid) && $_uid) ) // only display if the user isn't logged in
  250. {
  251. api_display_language_form();
  252. echo '<br />';
  253. display_login_form();
  254. if ($loginFailed)
  255. handle_login_failed();
  256. if (api_get_setting('allow_lostpassword') == 'true' OR api_get_setting('allow_registration') == 'true')
  257. {
  258. echo '<div class="menusection"><span class="menusectioncaption">'.get_lang('MenuUser').'</span><ul class="menulist">';
  259. if (get_setting('allow_registration') <> 'false')
  260. {
  261. echo '<li><a href="main/auth/inscription.php">'.get_lang('Reg').'</a></li>';
  262. }
  263. if (get_setting('allow_lostpassword') == 'true')
  264. {
  265. display_lost_password_info();
  266. }
  267. echo '</ul></div>';
  268. }
  269. api_plugin('loginpage_menu');
  270. }
  271. /*** hide right menu "general" and other parts on anonymous right menu *****/
  272. echo "<div class=\"menusection\">", "<span class=\"menusectioncaption\">".get_lang("MenuGeneral")."</span>";
  273. echo "<ul class=\"menulist\">";
  274. $user_selected_language = $_SESSION["user_language_choice"];
  275. if (!isset ($user_selected_language))
  276. $user_selected_language = $platformLanguage;
  277. if(!file_exists('home/home_menu_'.$user_selected_language.'.html'))
  278. {
  279. include ('home/home_menu.html');
  280. }
  281. else
  282. {
  283. include('home/home_menu_'.$user_selected_language.'.html');
  284. }
  285. echo '</ul>';
  286. echo '</div>';
  287. if ($_uid)
  288. {
  289. api_plugin('campushomepage_menu');
  290. }
  291. /**** use this comment to hide notice file section from right menu ****
  292. echo '<div class="note">';
  293. // includes for any files to be displayed below anonymous right menu
  294. if(!file_exists('home/home_notice_'.$user_selected_language.'.html'))
  295. {
  296. include ('home/home_notice.html');
  297. }
  298. else
  299. {
  300. include('home/home_notice_'.$user_selected_language.'.html');
  301. }
  302. echo '</div>';
  303. **** end of hide various right menu items on anonymous right menu ****/
  304. }
  305. /**
  306. * Reacts on a failed login:
  307. * displays an explanation with
  308. * a link to the registration form.
  309. *
  310. * @version 1.0.1
  311. */
  312. function handle_login_failed()
  313. {
  314. switch ($_GET['error'])
  315. {
  316. case '':
  317. $message = get_lang("InvalidId");
  318. if (api_is_self_registration_allowed())
  319. {
  320. $message = get_lang("InvalidForSelfRegistration");
  321. }
  322. break;
  323. case 'account_expired':
  324. $message=get_lang('AccountExpired');
  325. break;
  326. case 'account_inactive':
  327. $message=get_lang('AccountInactive');
  328. break;
  329. case 'user_password_incorrect':
  330. $message=get_lang('InvalidId');
  331. break;
  332. }
  333. echo "<div id=\"login_fail\">".$message."</div>";
  334. }
  335. /**
  336. * Adds a form to let users login
  337. * @version 1.1
  338. */
  339. function display_login_form()
  340. {
  341. $form = new FormValidator('formLogin');
  342. $form->addElement('text','login',get_lang('UserName'),array('size'=>15));
  343. $form->addElement('password','password',get_lang('Pass'),array('size'=>15));
  344. $form->addElement('submit','submitAuth',get_lang('Ok'));
  345. $renderer =& $form->defaultRenderer();
  346. $element_template = '<!-- BEGIN required --><span class="form_required">*</span> <!-- END required -->{label}<br />
  347. <!-- BEGIN error --><span class="form_error">{error}</span><br /><!-- END error --> {element}<br />';
  348. $renderer->setElementTemplate($element_template);
  349. $form->display();
  350. }
  351. /**
  352. * Displays a link to the lost password section
  353. */
  354. function display_lost_password_info()
  355. {
  356. echo "<li><a href=\"main/auth/lostPassword.php\">".get_lang("LostPassword")."</a></li>";
  357. }
  358. /**
  359. * Display list of courses in a category.
  360. * (for anonymous users)
  361. *
  362. * Warning: this function defines globals.
  363. * @version 1.0
  364. */
  365. function display_anonymous_course_list()
  366. {
  367. //init
  368. global $coursesRepositoryWeb;
  369. $web_course_path = api_get_path(WEB_COURSE_PATH);
  370. $category = $_GET["category"];
  371. $main_course_table = Database :: get_main_table(MAIN_COURSE_TABLE);
  372. $main_category_table = Database :: get_main_table(MAIN_CATEGORY_TABLE);
  373. $platformLanguage = api_get_setting('platformLanguage');
  374. //get list of courses in category $category
  375. $sql_get_course_list = "SELECT * FROM $main_course_table cours
  376. WHERE category_code = '".$category."'
  377. ORDER BY UPPER(visual_code)";
  378. //removed: AND cours.visibility='".COURSE_VISIBILITY_OPEN_WORLD."'
  379. $sql_result_courses = api_sql_query($sql_get_course_list, __FILE__, __LINE__);
  380. while ($course_result = mysql_fetch_array($sql_result_courses))
  381. {
  382. $course_list[] = $course_result;
  383. }
  384. $sqlGetSubCatList = "
  385. SELECT t1.name,t1.code,t1.parent_id,t1.children_count,COUNT(DISTINCT t3.code) AS nbCourse
  386. FROM $main_category_table t1
  387. LEFT JOIN $main_category_table t2 ON t1.code=t2.parent_id
  388. LEFT JOIN $main_course_table t3 ON (t3.category_code=t1.code AND t3.visibility='".COURSE_VISIBILITY_OPEN_WORLD."')
  389. WHERE t1.parent_id ". (empty ($category) ? "IS NULL" : "='$category'")."
  390. GROUP BY t1.name,t1.code,t1.parent_id,t1.children_count ORDER BY t1.tree_pos";
  391. $resCats = api_sql_query($sqlGetSubCatList, __FILE__, __LINE__);
  392. $thereIsSubCat = FALSE;
  393. if (mysql_num_rows($resCats) > 0)
  394. {
  395. $htmlListCat = "<h4 style=\"margin-top: 0px;\">".get_lang("CatList")."</h4>"."<ul>";
  396. while ($catLine = mysql_fetch_array($resCats))
  397. {
  398. if ($catLine['code'] != $category)
  399. {
  400. $htmlListCat .= "<li>";
  401. $category_has_open_courses = category_has_open_courses($catLine['code']);
  402. if ($category_has_open_courses)
  403. {
  404. //the category contains courses accessible to anonymous visitors
  405. $htmlListCat .= "<a href=\"".$_SERVER['PHP_SELF']."?category=".$catLine['code']."\">".$catLine['name']."</a>";
  406. if (CONFVAL_showNumberOfChild)
  407. {
  408. $htmlListCat .= " (".$catLine['nbCourse']." ".get_lang("Courses").")";
  409. }
  410. }
  411. elseif ($catLine['children_count'] > 0)
  412. {
  413. //the category has children, subcategories
  414. $htmlListCat .= "<a href=\"".$_SERVER['PHP_SELF']."?category=".$catLine['code']."\">".$catLine['name']."</a>";
  415. }
  416. /************************************************************************
  417. end changed code to eliminate the (0 courses) after empty categories
  418. ************************************************************************/
  419. elseif (CONFVAL_showNodeEmpty)
  420. {
  421. $htmlListCat .= $catLine['name'];
  422. }
  423. $htmlListCat .= "</li>\n";
  424. $thereIsSubCat = true;
  425. }
  426. else
  427. {
  428. $htmlTitre = "<p>";
  429. if (CONFVAL_ShowLinkBackToTopOfTree)
  430. {
  431. $htmlTitre .= "<a href=\"".$_SERVER['PHP_SELF']."\">"."&lt;&lt; ".get_lang("BackToHomePage")."</a>";
  432. }
  433. if (!is_null($catLine['parent_id']) || (!CONFVAL_ShowLinkBackToTopOfTree && !is_null($catLine['code'])))
  434. {
  435. $htmlTitre .= "<a href=\"".$_SERVER['PHP_SELF']."?category=".$catLine['parent_id']."\">"."&lt;&lt; ".get_lang("Up")."</a>";
  436. }
  437. $htmlTitre .= "</p>\n";
  438. if ($category != "" && !is_null($catLine['code']))
  439. {
  440. $htmlTitre .= "<h3>".$catLine['name']."</h3>\n";
  441. }
  442. else
  443. {
  444. $htmlTitre .= "<h3>".get_lang("Categories")."</h3>\n";
  445. }
  446. }
  447. }
  448. $htmlListCat .= "</ul>\n";
  449. }
  450. echo $htmlTitre;
  451. if ($thereIsSubCat)
  452. echo $htmlListCat;
  453. while ($categoryName = mysql_fetch_array($resCats))
  454. {
  455. echo "<h3>", $categoryName['name'], "</h3>\n";
  456. }
  457. $numrows = mysql_num_rows($sql_result_courses);
  458. if ($numrows > 0)
  459. {
  460. if ($thereIsSubCat)
  461. echo "<hr size=\"1\" noshade=\"noshade\">\n";
  462. echo "<h4 style=\"margin-top: 0px;\">", get_lang("CourseList"), "</h4>\n", "<ul>\n";
  463. while ($course = mysql_fetch_array($sql_result_courses))
  464. {
  465. echo "<li>\n", "<a href=\"".$web_course_path.$course['directory'], "/\">", $course['title'], "</a>", "<br/>", $course['visual_code'], " - ", $course['tutor_name'], ((CONFVAL_showCourseLangIfNotSameThatPlatform && $course['course_language'] != $platformLanguage) ? " - ".$course['course_language'] : ""), "\n", "</li>\n";
  466. }
  467. echo "</ul>\n";
  468. }
  469. else
  470. {
  471. // echo "<blockquote>",get_lang('_No_course_publicly_available'),"</blockquote>\n";
  472. }
  473. if ($category != "")
  474. {
  475. echo "<p>", "<a href=\"".$_SERVER['PHP_SELF']."\"><b>&lt;&lt;</b> ", get_lang("BackToHomePage"), "</a>", "</p>\n";
  476. }
  477. }
  478. function category_has_open_courses($category)
  479. {
  480. $main_course_table = Database :: get_main_table(MAIN_COURSE_TABLE);
  481. $sql_query = "SELECT * FROM $main_course_table WHERE category_code='$category'";
  482. $sql_result = api_sql_query($sql_query, __FILE__, __LINE__);
  483. while ($course = mysql_fetch_array($sql_result))
  484. {
  485. if ($is_allowed_anonymous_access)
  486. return true; //at least one open course
  487. }
  488. return false;
  489. }
  490. /*
  491. ==============================================================================
  492. MAIN CODE
  493. ==============================================================================
  494. */
  495. echo '<div class="maincontent">';
  496. /*
  497. -----------------------------------------------------------------------------
  498. Plugins for loginpage_main AND campushomepage_main
  499. -----------------------------------------------------------------------------
  500. */
  501. if (!$_uid)
  502. {
  503. api_plugin('loginpage_main');
  504. }
  505. else
  506. {
  507. api_plugin('campushomepage_main');
  508. }
  509. if (!empty ($_GET['include']) && !strstr($_GET['include'], '/') && strstr($_GET['include'], '.html'))
  510. {
  511. include ('./home/'.$_GET['include']);
  512. $pageIncluded = true;
  513. }
  514. else
  515. {
  516. if(!file_exists('home/home_news_'.$user_selected_language.'.html'))
  517. {
  518. include ('home/home_top.html');
  519. }
  520. else
  521. {
  522. include('home/home_top_'.$user_selected_language.'.html');
  523. }
  524. }
  525. // Display System announcements
  526. $announcement = $_GET['announcement'] ? $_GET['announcement'] : -1;
  527. SystemAnnouncementManager :: display_announcements(VISIBLE_GUEST, $announcement);
  528. // Display courses and category list
  529. if (!$pageIncluded)
  530. {
  531. // echo '<div class="clear">&nbsp;</div>';
  532. echo '<div class="home_cats">';
  533. if (DISPLAY_COURSES_TO_ANONYMOUS_USERS)
  534. {
  535. display_anonymous_course_list();
  536. }
  537. echo '</div>';
  538. /*
  539. echo '<div class="home_news">';
  540. if(!file_exists('home/home_news_'.$user_selected_language.'.html'))
  541. {
  542. include ('home/home_news.html');
  543. }
  544. else
  545. {
  546. include('home/home_news_'.$user_selected_language.'.html');
  547. }
  548. echo '</div>';
  549. */
  550. }
  551. echo '</div>';
  552. // Right Menu
  553. // language form, login section + useful weblinks
  554. echo '<div class="menu">';
  555. display_anonymous_right_menu();
  556. echo '</div>';
  557. /*
  558. ==============================================================================
  559. FOOTER
  560. ==============================================================================
  561. */
  562. Display :: display_footer();
  563. ?>