index.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  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. display_login_form();
  253. if ($loginFailed)
  254. handle_login_failed();
  255. if (api_get_setting('allow_lostpassword') == 'true' OR api_get_setting('allow_registration') == 'true')
  256. {
  257. echo '<div class="menusection"><span class="menusectioncaption">'.get_lang('MenuUser').'</span><ul class="menulist">';
  258. if (get_setting('allow_registration') <> 'false')
  259. {
  260. echo '<li><a href="main/auth/inscription.php">'.get_lang('Reg').'</a></li>';
  261. }
  262. if (get_setting('allow_lostpassword') == 'true')
  263. {
  264. display_lost_password_info();
  265. }
  266. echo '</ul></div>';
  267. }
  268. api_plugin('loginpage_menu');
  269. }
  270. /*** hide right menu "general" and other parts on anonymous right menu *****/
  271. echo "<div class=\"menusection\">", "<span class=\"menusectioncaption\">".get_lang("MenuGeneral")."</span>";
  272. echo "<ul class=\"menulist\">";
  273. $user_selected_language = $_SESSION["user_language_choice"];
  274. if (!isset ($user_selected_language))
  275. $user_selected_language = $platformLanguage;
  276. if(!file_exists('home/home_menu_'.$user_selected_language.'.html'))
  277. {
  278. include ('home/home_menu.html');
  279. }
  280. else
  281. {
  282. include('home/home_menu_'.$user_selected_language.'.html');
  283. }
  284. echo '</ul>';
  285. echo '</div>';
  286. if ($_uid)
  287. {
  288. api_plugin('campushomepage_menu');
  289. }
  290. /**** use this comment to hide notice file section from right menu ****
  291. echo '<div class="note">';
  292. // includes for any files to be displayed below anonymous right menu
  293. if(!file_exists('home/home_notice_'.$user_selected_language.'.html'))
  294. {
  295. include ('home/home_notice.html');
  296. }
  297. else
  298. {
  299. include('home/home_notice_'.$user_selected_language.'.html');
  300. }
  301. echo '</div>';
  302. **** end of hide various right menu items on anonymous right menu ****/
  303. }
  304. /**
  305. * Reacts on a failed login:
  306. * displays an explanation with
  307. * a link to the registration form.
  308. *
  309. * @version 1.0.1
  310. */
  311. function handle_login_failed()
  312. {
  313. switch ($_GET['error'])
  314. {
  315. case '':
  316. $message = get_lang("InvalidId");
  317. if (api_is_self_registration_allowed())
  318. {
  319. $message = get_lang("InvalidForSelfRegistration");
  320. }
  321. break;
  322. case 'account_expired':
  323. $message=get_lang('AccountExpired');
  324. break;
  325. case 'account_inactive':
  326. $message=get_lang('AccountInactive');
  327. break;
  328. case 'user_password_incorrect':
  329. $message=get_lang('InvalidId');
  330. break;
  331. }
  332. echo "<div id=\"login_fail\">".$message."</div>";
  333. }
  334. /**
  335. * Adds a form to let users login
  336. * @version 1.1
  337. */
  338. function display_login_form()
  339. {
  340. $form = new FormValidator('formLogin');
  341. $form->addElement('static',null,null,get_lang('UserName'));
  342. $form->addElement('text','login','',array('size'=>15));
  343. $form->addElement('static',null,null,get_lang('Pass'));
  344. $form->addElement('password','password','',array('size'=>15));
  345. $form->addElement('submit','submitAuth',get_lang('Ok'));
  346. $form->display();
  347. }
  348. /**
  349. * Displays a link to the lost password section
  350. */
  351. function display_lost_password_info()
  352. {
  353. echo "<li><a href=\"main/auth/lostPassword.php\">".get_lang("LostPassword")."</a></li>";
  354. }
  355. /**
  356. * Display list of courses in a category.
  357. * (for anonymous users)
  358. *
  359. * Warning: this function defines globals.
  360. * @version 1.0
  361. */
  362. function display_anonymous_course_list()
  363. {
  364. //init
  365. global $coursesRepositoryWeb;
  366. $web_course_path = api_get_path(WEB_COURSE_PATH);
  367. $category = $_GET["category"];
  368. $main_course_table = Database :: get_main_table(MAIN_COURSE_TABLE);
  369. $main_category_table = Database :: get_main_table(MAIN_CATEGORY_TABLE);
  370. $platformLanguage = api_get_setting('platformLanguage');
  371. //get list of courses in category $category
  372. $sql_get_course_list = "SELECT * FROM $main_course_table cours
  373. WHERE category_code = '".$category."'
  374. ORDER BY UPPER(visual_code)";
  375. //removed: AND cours.visibility='".COURSE_VISIBILITY_OPEN_WORLD."'
  376. $sql_result_courses = api_sql_query($sql_get_course_list, __FILE__, __LINE__);
  377. while ($course_result = mysql_fetch_array($sql_result_courses))
  378. {
  379. $course_list[] = $course_result;
  380. }
  381. $sqlGetSubCatList = "
  382. SELECT t1.name,t1.code,t1.parent_id,t1.children_count,COUNT(DISTINCT t3.code) AS nbCourse
  383. FROM $main_category_table t1
  384. LEFT JOIN $main_category_table t2 ON t1.code=t2.parent_id
  385. LEFT JOIN $main_course_table t3 ON (t3.category_code=t1.code AND t3.visibility='".COURSE_VISIBILITY_OPEN_WORLD."')
  386. WHERE t1.parent_id ". (empty ($category) ? "IS NULL" : "='$category'")."
  387. GROUP BY t1.name,t1.code,t1.parent_id,t1.children_count ORDER BY t1.tree_pos";
  388. $resCats = api_sql_query($sqlGetSubCatList, __FILE__, __LINE__);
  389. $thereIsSubCat = FALSE;
  390. if (mysql_num_rows($resCats) > 0)
  391. {
  392. $htmlListCat = "<h4 style=\"margin-top: 0px;\">".get_lang("CatList")."</h4>"."<ul>";
  393. while ($catLine = mysql_fetch_array($resCats))
  394. {
  395. if ($catLine['code'] != $category)
  396. {
  397. $htmlListCat .= "<li>";
  398. $category_has_open_courses = category_has_open_courses($catLine['code']);
  399. if ($category_has_open_courses)
  400. {
  401. //the category contains courses accessible to anonymous visitors
  402. $htmlListCat .= "<a href=\"".$_SERVER['PHP_SELF']."?category=".$catLine['code']."\">".$catLine['name']."</a>";
  403. if (CONFVAL_showNumberOfChild)
  404. {
  405. $htmlListCat .= " (".$catLine['nbCourse']." ".get_lang("Courses").")";
  406. }
  407. }
  408. elseif ($catLine['children_count'] > 0)
  409. {
  410. //the category has children, subcategories
  411. $htmlListCat .= "<a href=\"".$_SERVER['PHP_SELF']."?category=".$catLine['code']."\">".$catLine['name']."</a>";
  412. }
  413. /************************************************************************
  414. end changed code to eliminate the (0 courses) after empty categories
  415. ************************************************************************/
  416. elseif (CONFVAL_showNodeEmpty)
  417. {
  418. $htmlListCat .= $catLine['name'];
  419. }
  420. $htmlListCat .= "</li>\n";
  421. $thereIsSubCat = true;
  422. }
  423. else
  424. {
  425. $htmlTitre = "<p>";
  426. if (CONFVAL_ShowLinkBackToTopOfTree)
  427. {
  428. $htmlTitre .= "<a href=\"".$_SERVER['PHP_SELF']."\">"."&lt;&lt; ".get_lang("BackToHomePage")."</a>";
  429. }
  430. if (!is_null($catLine['parent_id']) || (!CONFVAL_ShowLinkBackToTopOfTree && !is_null($catLine['code'])))
  431. {
  432. $htmlTitre .= "<a href=\"".$_SERVER['PHP_SELF']."?category=".$catLine['parent_id']."\">"."&lt;&lt; ".get_lang("Up")."</a>";
  433. }
  434. $htmlTitre .= "</p>\n";
  435. if ($category != "" && !is_null($catLine['code']))
  436. {
  437. $htmlTitre .= "<h3>".$catLine['name']."</h3>\n";
  438. }
  439. else
  440. {
  441. $htmlTitre .= "<h3>".get_lang("Categories")."</h3>\n";
  442. }
  443. }
  444. }
  445. $htmlListCat .= "</ul>\n";
  446. }
  447. echo $htmlTitre;
  448. if ($thereIsSubCat)
  449. echo $htmlListCat;
  450. while ($categoryName = mysql_fetch_array($resCats))
  451. {
  452. echo "<h3>", $categoryName['name'], "</h3>\n";
  453. }
  454. $numrows = mysql_num_rows($sql_result_courses);
  455. if ($numrows > 0)
  456. {
  457. if ($thereIsSubCat)
  458. echo "<hr size=\"1\" noshade=\"noshade\">\n";
  459. echo "<h4 style=\"margin-top: 0px;\">", get_lang("CourseList"), "</h4>\n", "<ul>\n";
  460. while ($course = mysql_fetch_array($sql_result_courses))
  461. {
  462. 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";
  463. }
  464. echo "</ul>\n";
  465. }
  466. else
  467. {
  468. // echo "<blockquote>",get_lang('_No_course_publicly_available'),"</blockquote>\n";
  469. }
  470. if ($category != "")
  471. {
  472. echo "<p>", "<a href=\"".$_SERVER['PHP_SELF']."\"><b>&lt;&lt;</b> ", get_lang("BackToHomePage"), "</a>", "</p>\n";
  473. }
  474. }
  475. function category_has_open_courses($category)
  476. {
  477. $main_course_table = Database :: get_main_table(MAIN_COURSE_TABLE);
  478. $sql_query = "SELECT * FROM $main_course_table WHERE category_code='$category'";
  479. $sql_result = api_sql_query($sql_query, __FILE__, __LINE__);
  480. while ($course = mysql_fetch_array($sql_result))
  481. {
  482. if ($is_allowed_anonymous_access)
  483. return true; //at least one open course
  484. }
  485. return false;
  486. }
  487. /*
  488. ==============================================================================
  489. MAIN CODE
  490. ==============================================================================
  491. */
  492. echo '<div class="maincontent">';
  493. /*
  494. -----------------------------------------------------------------------------
  495. Plugins for loginpage_main AND campushomepage_main
  496. -----------------------------------------------------------------------------
  497. */
  498. if (!$_uid)
  499. {
  500. api_plugin('loginpage_main');
  501. }
  502. else
  503. {
  504. api_plugin('campushomepage_main');
  505. }
  506. if (!empty ($_GET['include']) && !strstr($_GET['include'], '/') && strstr($_GET['include'], '.html'))
  507. {
  508. include ('./home/'.$_GET['include']);
  509. $pageIncluded = true;
  510. }
  511. else
  512. {
  513. if(!file_exists('home/home_news_'.$user_selected_language.'.html'))
  514. {
  515. include ('home/home_top.html');
  516. }
  517. else
  518. {
  519. include('home/home_top_'.$user_selected_language.'.html');
  520. }
  521. }
  522. // Display System announcements
  523. $announcement = $_GET['announcement'] ? $_GET['announcement'] : -1;
  524. SystemAnnouncementManager :: display_announcements(VISIBLE_GUEST, $announcement);
  525. // Display courses and category list
  526. if (!$pageIncluded)
  527. {
  528. // echo '<div class="clear">&nbsp;</div>';
  529. echo '<div class="home_cats">';
  530. if (DISPLAY_COURSES_TO_ANONYMOUS_USERS)
  531. {
  532. display_anonymous_course_list();
  533. }
  534. echo '</div>';
  535. /*
  536. echo '<div class="home_news">';
  537. if(!file_exists('home/home_news_'.$user_selected_language.'.html'))
  538. {
  539. include ('home/home_news.html');
  540. }
  541. else
  542. {
  543. include('home/home_news_'.$user_selected_language.'.html');
  544. }
  545. echo '</div>';
  546. */
  547. }
  548. echo '</div>';
  549. // Right Menu
  550. // language form, login section + useful weblinks
  551. echo '<div class="menu">';
  552. display_anonymous_right_menu();
  553. echo '</div>';
  554. /*
  555. ==============================================================================
  556. FOOTER
  557. ==============================================================================
  558. */
  559. Display :: display_footer();
  560. ?>