userportal.lib.php 64 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use \ChamiloSession as Session;
  4. class IndexManager
  5. {
  6. //An instance of the template engine
  7. public $tpl = false;
  8. public $name = '';
  9. public $home = '';
  10. public $default_home = 'home/';
  11. public function __construct($title)
  12. {
  13. $this->tpl = new Template($title);
  14. $this->home = api_get_home_path();
  15. $this->user_id = api_get_user_id();
  16. $this->load_directories_preview = false;
  17. if (api_get_setting('show_documents_preview') == 'true') {
  18. $this->load_directories_preview = true;
  19. }
  20. }
  21. /**
  22. * @param bool $setLoginForm
  23. */
  24. function set_login_form($setLoginForm = true)
  25. {
  26. global $loginFailed;
  27. $login_form = '';
  28. if (!($this->user_id) || api_is_anonymous($this->user_id)) {
  29. // Only display if the user isn't logged in.
  30. $this->tpl->assign('login_language_form', api_display_language_form(true));
  31. if ($setLoginForm) {
  32. $this->tpl->assign('login_form', self::display_login_form());
  33. if ($loginFailed) {
  34. $this->tpl->assign('login_failed', self::handle_login_failed());
  35. }
  36. if (api_get_setting('allow_lostpassword') == 'true' || api_get_setting('allow_registration') == 'true') {
  37. $login_form .= '<ul class="nav nav-list">';
  38. if (api_get_setting('allow_registration') != 'false') {
  39. $login_form .= '<li><a href="main/auth/inscription.php">'.get_lang('Reg').'</a></li>';
  40. }
  41. if (api_get_setting('allow_lostpassword') == 'true') {
  42. $login_form .= '<li><a href="main/auth/lostPassword.php">'.get_lang('LostPassword').'</a></li>';
  43. }
  44. $login_form .= '</ul>';
  45. }
  46. $this->tpl->assign('login_options', $login_form);
  47. }
  48. }
  49. }
  50. function return_exercise_block($personal_course_list)
  51. {
  52. require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.lib.php';
  53. $exercise_list = array();
  54. if (!empty($personal_course_list)) {
  55. foreach($personal_course_list as $course_item) {
  56. $course_code = $course_item['c'];
  57. $session_id = $course_item['id_session'];
  58. $exercises = get_exercises_to_be_taken($course_code, $session_id);
  59. foreach($exercises as $exercise_item) {
  60. $exercise_item['course_code'] = $course_code;
  61. $exercise_item['session_id'] = $session_id;
  62. $exercise_item['tms'] = api_strtotime($exercise_item['end_time'], 'UTC');
  63. $exercise_list[] = $exercise_item;
  64. }
  65. }
  66. if (!empty($exercise_list)) {
  67. $exercise_list = msort($exercise_list, 'tms');
  68. $my_exercise = $exercise_list[0];
  69. $url = Display::url($my_exercise['title'], api_get_path(WEB_CODE_PATH).'exercice/overview.php?exerciseId='.$my_exercise['id'].'&cidReq='.$my_exercise['course_code'].'&id_session='.$my_exercise['session_id']);
  70. $this->tpl->assign('exercise_url', $url);
  71. $this->tpl->assign('exercise_end_date', api_convert_and_format_date($my_exercise['end_time'], DATE_FORMAT_SHORT));
  72. }
  73. }
  74. }
  75. function return_announcements($show_slide = true) {
  76. // Display System announcements
  77. $announcement = isset($_GET['announcement']) ? $_GET['announcement'] : null;
  78. $announcement = intval($announcement);
  79. if (!api_is_anonymous() && $this->user_id) {
  80. $visibility = api_is_allowed_to_create_course() ? SystemAnnouncementManager::VISIBLE_TEACHER : SystemAnnouncementManager::VISIBLE_STUDENT;
  81. if ($show_slide) {
  82. $announcements = SystemAnnouncementManager :: display_announcements_slider($visibility, $announcement);
  83. } else {
  84. $announcements = SystemAnnouncementManager :: display_all_announcements($visibility, $announcement);
  85. }
  86. } else {
  87. if ($show_slide) {
  88. $announcements = SystemAnnouncementManager :: display_announcements_slider(SystemAnnouncementManager::VISIBLE_GUEST, $announcement);
  89. } else {
  90. $announcements = SystemAnnouncementManager :: display_all_announcements(SystemAnnouncementManager::VISIBLE_GUEST, $announcement);
  91. }
  92. }
  93. return $announcements;
  94. }
  95. /**
  96. * Alias for the online_logout() function
  97. */
  98. function logout() {
  99. online_logout($this->user_id, true);
  100. }
  101. /**
  102. * This function checks if there are courses that are open to the world in the platform course categories (=faculties)
  103. *
  104. * @param string $category
  105. * @return boolean
  106. */
  107. function category_has_open_courses($category) {
  108. $setting_show_also_closed_courses = api_get_setting('show_closed_courses') == 'true';
  109. $main_course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
  110. $category = Database::escape_string($category);
  111. $sql_query = "SELECT * FROM $main_course_table WHERE category_code='$category'";
  112. $sql_result = Database::query($sql_query);
  113. while ($course = Database::fetch_array($sql_result)) {
  114. if (!$setting_show_also_closed_courses) {
  115. if ((api_get_user_id() > 0 && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM) || ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD)) {
  116. return true; //at least one open course
  117. }
  118. } else {
  119. if (isset($course['visibility'])) {
  120. return true; // At least one course (it does not matter weither it's open or not because $setting_show_also_closed_courses = true).
  121. }
  122. }
  123. }
  124. return false;
  125. }
  126. /**
  127. * Displays the right-hand menu for anonymous users:
  128. * login form, useful links, help section
  129. * Warning: function defines globals
  130. * @version 1.0.1
  131. * @todo does $_plugins need to be global?
  132. */
  133. function display_anonymous_right_menu() {
  134. global $loginFailed, $_user;
  135. $display_add_course_link = api_is_allowed_to_create_course() && ($_SESSION['studentview'] != 'studentenview');
  136. $current_user_id = api_get_user_id();
  137. echo self::set_login_form(false);
  138. echo self::return_teacher_link();
  139. echo self::return_notice();
  140. }
  141. function return_teacher_link() {
  142. $html = '';
  143. if (!empty($this->user_id)) {
  144. // tabs that are deactivated are added here
  145. $show_menu = false;
  146. $show_create_link = false;
  147. $show_course_link = false;
  148. if (api_is_platform_admin() || api_is_course_admin() || api_is_allowed_to_create_course()) {
  149. $show_menu = true;
  150. $show_course_link = true;
  151. $show_create_link = true;
  152. } else {
  153. if (api_get_setting('allow_students_to_browse_courses') == 'true') {
  154. $show_menu = true;
  155. $show_course_link = true;
  156. }
  157. }
  158. if ($show_menu && ($show_create_link || $show_course_link )) {
  159. $show_menu = true;
  160. } else {
  161. $show_menu = false;
  162. }
  163. }
  164. // My Account section
  165. if ($show_menu) {
  166. $html .= '<ul class="nav nav-list">';
  167. if ($show_create_link) {
  168. $html .= '<li class="add-course"><a href="' . api_get_path(WEB_CODE_PATH) . 'create_course/add_course.php">'.(api_get_setting('course_validation') == 'true' ? get_lang('CreateCourseRequest') : get_lang('CourseCreate')).'</a></li>';
  169. }
  170. if ($show_course_link) {
  171. if (!api_is_drh() && !api_is_session_admin()) {
  172. $html .= '<li class="list-course"><a href="' . api_get_path(WEB_CODE_PATH) . 'auth/courses.php">'.get_lang('CourseCatalog').'</a></li>';
  173. } else {
  174. $html .= '<li><a href="' . api_get_path(WEB_CODE_PATH) . 'dashboard/index.php">'.get_lang('Dashboard').'</a></li>';
  175. }
  176. }
  177. $html .= '</ul>';
  178. }
  179. if (!empty($html)) {
  180. $html = self::show_right_block(get_lang('Courses'), $html, 'teacher_block');
  181. }
  182. return $html;
  183. }
  184. /* Includes a created page */
  185. function return_home_page()
  186. {
  187. $userId = api_get_user_id();
  188. global $_configuration;
  189. // Including the page for the news
  190. $html = '';
  191. if (!empty($_GET['include']) && preg_match('/^[a-zA-Z0-9_-]*\.html$/', $_GET['include'])) {
  192. $open = @(string)file_get_contents(api_get_path(SYS_PATH).$this->home.$_GET['include']);
  193. $html = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
  194. } else {
  195. // Hiding home top when user not connected.
  196. if (isset($_configuration['hide_home_top_when_connected']) && $_configuration['hide_home_top_when_connected'] && !empty($userId)) {
  197. return $html;
  198. }
  199. if (!empty($_SESSION['user_language_choice'])) {
  200. $user_selected_language = $_SESSION['user_language_choice'];
  201. } elseif (!empty($_SESSION['_user']['language'])) {
  202. $user_selected_language = $_SESSION['_user']['language'];
  203. } else {
  204. $user_selected_language = api_get_setting('platformLanguage');
  205. }
  206. if (!file_exists($this->home.'home_news_'.$user_selected_language.'.html')) {
  207. if (file_exists($this->home.'home_top.html')) {
  208. $home_top_temp = file($this->home.'home_top.html');
  209. } else {
  210. $home_top_temp = file($this->default_home.'home_top.html');
  211. }
  212. $home_top_temp = implode('', $home_top_temp);
  213. } else {
  214. if (file_exists($this->home.'home_top_'.$user_selected_language.'.html')) {
  215. $home_top_temp = file_get_contents($this->home.'home_top_'.$user_selected_language.'.html');
  216. } else {
  217. $home_top_temp = file_get_contents($this->home.'home_top.html');
  218. }
  219. }
  220. if (trim($home_top_temp) == '' && api_is_platform_admin()) {
  221. $home_top_temp = '<div class="welcome-mascot">' . get_lang('PortalHomepageDefaultIntroduction') . '</div>';
  222. } else {
  223. $home_top_temp = '<div class="welcome-home-top-temp">' . $home_top_temp . '</div>';
  224. }
  225. $open = str_replace('{rel_path}', api_get_path(REL_PATH), $home_top_temp);
  226. $html = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
  227. }
  228. return $html;
  229. }
  230. function return_notice() {
  231. $sys_path = api_get_path(SYS_PATH);
  232. $user_selected_language = api_get_interface_language();
  233. $html = '';
  234. // Notice
  235. $home_notice = @(string)file_get_contents($sys_path.$this->home.'home_notice_'.$user_selected_language.'.html');
  236. if (empty($home_notice)) {
  237. $home_notice = @(string)file_get_contents($sys_path.$this->home.'home_notice.html');
  238. }
  239. if (!empty($home_notice)) {
  240. $home_notice = api_to_system_encoding($home_notice, api_detect_encoding(strip_tags($home_notice)));
  241. $home_notice = Display::div($home_notice, array('class' => 'homepage_notice'));
  242. $html = self::show_right_block(get_lang('Notice'), $home_notice, 'notice_block');
  243. }
  244. return $html;
  245. }
  246. function return_help() {
  247. $user_selected_language = api_get_interface_language();
  248. $sys_path = api_get_path(SYS_PATH);
  249. $platformLanguage = api_get_setting('platformLanguage');
  250. // Help section.
  251. /* Hide right menu "general" and other parts on anonymous right menu. */
  252. if (!isset($user_selected_language)) {
  253. $user_selected_language = $platformLanguage;
  254. }
  255. $html = null;
  256. $home_menu = @(string)file_get_contents($sys_path.$this->home.'home_menu_'.$user_selected_language.'.html');
  257. if (!empty($home_menu)) {
  258. $home_menu_content = '<ul class="nav nav-list">';
  259. $home_menu_content .= api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
  260. $home_menu_content .= '</ul>';
  261. $html .= self::show_right_block(get_lang('MenuGeneral'), $home_menu_content, 'help_block');
  262. }
  263. return $html;
  264. }
  265. function return_skills_links() {
  266. $html = '';
  267. if (api_get_setting('allow_skills_tool') == 'true') {
  268. $content = '<ul class="nav nav-list">';
  269. $content .= Display::tag('li', Display::url(get_lang('MySkills'), api_get_path(WEB_CODE_PATH).'social/skills_wheel.php'));
  270. $allowSkillsManagement = api_get_setting('allow_hr_skills_management') == 'true';
  271. if (($allowSkillsManagement && api_is_drh()) || api_is_platform_admin()) {
  272. $content .= Display::tag('li', Display::url(get_lang('ManageSkills'), api_get_path(WEB_CODE_PATH).'admin/skills_wheel.php'));
  273. }
  274. $content .= '</ul>';
  275. $html = self::show_right_block(get_lang("Skills"), $content, 'skill_block');
  276. }
  277. return $html;
  278. }
  279. /**
  280. * Reacts on a failed login:
  281. * Displays an explanation with a link to the registration form.
  282. *
  283. * @version 1.0.1
  284. */
  285. function handle_login_failed() {
  286. $message = get_lang('InvalidId');
  287. if (!isset($_GET['error'])) {
  288. if (api_is_self_registration_allowed()) {
  289. $message = get_lang('InvalidForSelfRegistration');
  290. }
  291. } else {
  292. switch ($_GET['error']) {
  293. case '':
  294. if (api_is_self_registration_allowed()) {
  295. $message = get_lang('InvalidForSelfRegistration');
  296. }
  297. break;
  298. case 'account_expired':
  299. $message = get_lang('AccountExpired');
  300. break;
  301. case 'account_inactive':
  302. $message = get_lang('AccountInactive');
  303. break;
  304. case 'user_password_incorrect':
  305. $message = get_lang('InvalidId');
  306. break;
  307. case 'access_url_inactive':
  308. $message = get_lang('AccountURLInactive');
  309. break;
  310. case 'wrong_captcha':
  311. $message = get_lang('TheTextYouEnteredDoesNotMatchThePicture');
  312. break;
  313. case 'blocked_by_captcha':
  314. $message = get_lang('AccountBlockedByCaptcha');
  315. break;
  316. case 'multiple_connection_not_allowed':
  317. $message = get_lang('MultipleConnectionsAreNotAllow');
  318. break;
  319. case 'unrecognize_sso_origin':
  320. //$message = get_lang('SSOError');
  321. break;
  322. }
  323. }
  324. return Display::return_message($message, 'error');
  325. }
  326. /**
  327. * Display list of courses in a category.
  328. * (for anonymous users)
  329. *
  330. * @version 1.1
  331. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University - refactoring and code cleaning
  332. * @author Julio Montoya <gugli100@gmail.com>, Beeznest template modifs
  333. */
  334. function return_courses_in_categories() {
  335. $result = '';
  336. $stok = Security::get_token();
  337. // Initialization.
  338. $user_identified = (api_get_user_id() > 0 && !api_is_anonymous());
  339. $web_course_path = api_get_path(WEB_COURSE_PATH);
  340. $category = Database::escape_string($_GET['category']);
  341. $setting_show_also_closed_courses = api_get_setting('show_closed_courses') == 'true';
  342. // Database table definitions.
  343. $main_course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
  344. $main_category_table = Database :: get_main_table(TABLE_MAIN_CATEGORY);
  345. // Get list of courses in category $category.
  346. $sql_get_course_list = "SELECT * FROM $main_course_table cours
  347. WHERE category_code = '".Database::escape_string($_GET['category'])."'
  348. ORDER BY title, UPPER(visual_code)";
  349. // Showing only the courses of the current access_url_id.
  350. global $_configuration;
  351. if ($_configuration['multiple_access_urls']) {
  352. $url_access_id = api_get_current_access_url_id();
  353. if ($url_access_id != -1) {
  354. $tbl_url_rel_course = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
  355. $sql_get_course_list = "SELECT * FROM $main_course_table as course INNER JOIN $tbl_url_rel_course as url_rel_course
  356. ON (url_rel_course.course_code=course.code)
  357. WHERE access_url_id = $url_access_id AND category_code = '".Database::escape_string($_GET['category'])."' ORDER BY title, UPPER(visual_code)";
  358. }
  359. }
  360. // Removed: AND cours.visibility='".COURSE_VISIBILITY_OPEN_WORLD."'
  361. $sql_result_courses = Database::query($sql_get_course_list);
  362. while ($course_result = Database::fetch_array($sql_result_courses)) {
  363. $course_list[] = $course_result;
  364. }
  365. // $setting_show_also_closed_courses
  366. if ($user_identified) {
  367. if ($setting_show_also_closed_courses) {
  368. $platform_visible_courses = '';
  369. } else {
  370. $platform_visible_courses = " AND (t3.visibility='".COURSE_VISIBILITY_OPEN_WORLD."' OR t3.visibility='".COURSE_VISIBILITY_OPEN_PLATFORM."' )";
  371. }
  372. } else {
  373. if ($setting_show_also_closed_courses) {
  374. $platform_visible_courses = '';
  375. } else {
  376. $platform_visible_courses = " AND (t3.visibility='".COURSE_VISIBILITY_OPEN_WORLD."' )";
  377. }
  378. }
  379. $sqlGetSubCatList = "
  380. SELECT t1.name,
  381. t1.code,
  382. t1.parent_id,
  383. t1.children_count,COUNT(DISTINCT t3.code) AS nbCourse
  384. FROM $main_category_table t1
  385. LEFT JOIN $main_category_table t2 ON t1.code=t2.parent_id
  386. LEFT JOIN $main_course_table t3 ON (t3.category_code = t1.code $platform_visible_courses)
  387. WHERE t1.parent_id ". (empty ($category) ? "IS NULL" : "='$category'")."
  388. GROUP BY t1.name,t1.code,t1.parent_id,t1.children_count ORDER BY t1.tree_pos, t1.name";
  389. // Showing only the category of courses of the current access_url_id
  390. if (api_is_multiple_url_enabled()) {
  391. require_once api_get_path(LIBRARY_PATH).'course_category.lib.php';
  392. $courseCategoryCondition = null;
  393. if (isMultipleUrlSupport()) {
  394. $table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE_CATEGORY);
  395. $courseCategoryCondition = " INNER JOIN $table a ON (t1.id = a.course_category_id)";
  396. }
  397. $url_access_id = api_get_current_access_url_id();
  398. if ($url_access_id != -1) {
  399. $tbl_url_rel_course = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
  400. $sqlGetSubCatList = "
  401. SELECT t1.name,
  402. t1.code,
  403. t1.parent_id,
  404. t1.children_count,
  405. COUNT(DISTINCT t3.code) AS nbCourse
  406. FROM $main_category_table t1
  407. $courseCategoryCondition
  408. LEFT JOIN $main_category_table t2 ON t1.code = t2.parent_id
  409. LEFT JOIN $main_course_table t3 ON (t3.category_code=t1.code $platform_visible_courses)
  410. INNER JOIN $tbl_url_rel_course as url_rel_course
  411. ON (url_rel_course.course_code=t3.code)
  412. WHERE url_rel_course.access_url_id = $url_access_id AND t1.parent_id ".(empty($category) ? "IS NULL" : "='$category'")."
  413. GROUP BY t1.name,t1.code,t1.parent_id,t1.children_count ORDER BY t1.tree_pos, t1.name";
  414. }
  415. }
  416. $resCats = Database::query($sqlGetSubCatList);
  417. $thereIsSubCat = false;
  418. if (Database::num_rows($resCats) > 0) {
  419. $htmlListCat = Display::page_header(get_lang('CatList'));
  420. $htmlListCat .= '<ul>';
  421. $htmlTitre = '';
  422. while ($catLine = Database::fetch_array($resCats)) {
  423. $category_has_open_courses = self::category_has_open_courses($catLine['code']);
  424. if ($category_has_open_courses) {
  425. // The category contains courses accessible to anonymous visitors.
  426. $htmlListCat .= '<li>';
  427. $htmlListCat .= '<a href="'.api_get_self().'?category='.$catLine['code'].'">'.$catLine['name'].'</a>';
  428. if (api_get_setting('show_number_of_courses') == 'true') {
  429. $htmlListCat .= ' ('.$catLine['nbCourse'].' '.get_lang('Courses').')';
  430. }
  431. $htmlListCat .= "</li>";
  432. $thereIsSubCat = true;
  433. } elseif ($catLine['children_count'] > 0) {
  434. // The category has children, subcategories.
  435. $htmlListCat .= '<li>';
  436. $htmlListCat .= '<a href="'.api_get_self().'?category='.$catLine['code'].'">'.$catLine['name'].'</a>';
  437. $htmlListCat .= "</li>";
  438. $thereIsSubCat = true;
  439. } elseif (api_get_setting('show_empty_course_categories') == 'true') {
  440. /* End changed code to eliminate the (0 courses) after empty categories. */
  441. $htmlListCat .= '<li>';
  442. $htmlListCat .= $catLine['name'];
  443. $htmlListCat .= "</li>";
  444. $thereIsSubCat = true;
  445. } // Else don't set thereIsSubCat to true to avoid printing things if not requested.
  446. // TODO: deprecate this useless feature - this includes removing system variable
  447. if (empty($htmlTitre)) {
  448. $htmlTitre = '<p>';
  449. if (api_get_setting('show_back_link_on_top_of_tree') == 'true') {
  450. $htmlTitre .= '<a href="'.api_get_self().'">&lt;&lt; '.get_lang('BackToHomePage').'</a>';
  451. }
  452. $htmlTitre .= "</p>";
  453. }
  454. }
  455. $htmlListCat .= "</ul>";
  456. }
  457. $result .= $htmlTitre;
  458. if ($thereIsSubCat) {
  459. $result .= $htmlListCat;
  460. }
  461. while ($categoryName = Database::fetch_array($resCats)) {
  462. $result .= '<h3>' . $categoryName['name'] . "</h3>\n";
  463. }
  464. $numrows = Database::num_rows($sql_result_courses);
  465. $courses_list_string = '';
  466. $courses_shown = 0;
  467. if ($numrows > 0) {
  468. $courses_list_string .= Display::page_header(get_lang('CourseList'));
  469. $courses_list_string .= "<ul>";
  470. if (api_get_user_id()) {
  471. $courses_of_user = self::get_courses_of_user(api_get_user_id());
  472. }
  473. foreach ($course_list as $course) {
  474. // $setting_show_also_closed_courses
  475. if ($course['visibility'] == COURSE_VISIBILITY_HIDDEN) { continue; }
  476. if (!$setting_show_also_closed_courses) {
  477. // If we do not show the closed courses
  478. // we only show the courses that are open to the world (to everybody)
  479. // and the courses that are open to the platform (if the current user is a registered user.
  480. if (($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM) || ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD)) {
  481. $courses_shown++;
  482. $courses_list_string .= "<li>";
  483. $courses_list_string .= '<a href="'.$web_course_path.$course['directory'].'/">'.$course['title'].'</a><br />';
  484. $course_details = array();
  485. if (api_get_setting('display_coursecode_in_courselist') == 'true') {
  486. $course_details[] = $course['visual_code'];
  487. }
  488. if (api_get_setting('display_teacher_in_courselist') == 'true') {
  489. $course_details[] = CourseManager::get_teacher_list_from_course_code_to_string($course['code']);
  490. }
  491. if (api_get_setting('show_different_course_language') == 'true' && $course['course_language'] != api_get_setting('platformLanguage')) {
  492. $course_details[] = $course['course_language'];
  493. }
  494. $courses_list_string .= implode(' - ', $course_details);
  495. $courses_list_string .= "</li>";
  496. }
  497. } else {
  498. // We DO show the closed courses.
  499. // The course is accessible if (link to the course homepage):
  500. // 1. the course is open to the world (doesn't matter if the user is logged in or not): $course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD);
  501. // 2. the user is logged in and the course is open to the world or open to the platform: ($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM);
  502. // 3. the user is logged in and the user is subscribed to the course and the course visibility is not COURSE_VISIBILITY_CLOSED;
  503. // 4. the user is logged in and the user is course admin of te course (regardless of the course visibility setting);
  504. // 5. the user is the platform admin api_is_platform_admin().
  505. //
  506. $courses_shown++;
  507. $courses_list_string .= "<li>";
  508. if ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD
  509. || ($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM)
  510. || ($user_identified && array_key_exists($course['code'], $courses_of_user)
  511. && $course['visibility'] != COURSE_VISIBILITY_CLOSED)
  512. || $courses_of_user[$course['code']]['status'] == '1'
  513. || api_is_platform_admin()) {
  514. $courses_list_string .= '<a href="'.$web_course_path.$course['directory'].'/">';
  515. }
  516. $courses_list_string .= $course['title'];
  517. if ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD
  518. || ($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM)
  519. || ($user_identified && array_key_exists($course['code'], $courses_of_user)
  520. && $course['visibility'] != COURSE_VISIBILITY_CLOSED)
  521. || $courses_of_user[$course['code']]['status'] == '1'
  522. || api_is_platform_admin()) {
  523. $courses_list_string .= '</a><br />';
  524. }
  525. $course_details = array();
  526. if (api_get_setting('display_coursecode_in_courselist') == 'true') {
  527. $course_details[] = $course['visual_code'];
  528. }
  529. // if (api_get_setting('display_coursecode_in_courselist') == 'true' && api_get_setting('display_teacher_in_courselist') == 'true') {
  530. // $courses_list_string .= ' - ';
  531. // }
  532. if (api_get_setting('display_teacher_in_courselist') == 'true') {
  533. if (!empty($course['tutor_name'])) {
  534. $course_details[] = $course['tutor_name'];
  535. }
  536. }
  537. if (api_get_setting('show_different_course_language') == 'true' && $course['course_language'] != api_get_setting('platformLanguage')) {
  538. $course_details[] = $course['course_language'];
  539. }
  540. $courses_list_string .= implode(' - ', $course_details);
  541. // We display a subscription link if:
  542. // 1. it is allowed to register for the course and if the course is not already in the courselist of the user and if the user is identiefied
  543. // 2.
  544. if ($user_identified && !array_key_exists($course['code'], $courses_of_user)) {
  545. if ($course['subscribe'] == '1') {
  546. /*$courses_list_string .= '<form action="main/auth/courses.php?action=subscribe&category='.Security::remove_XSS($_GET['category']).'" method="post">';
  547. $courses_list_string .= '<input type="hidden" name="sec_token" value="'.$stok.'">';
  548. $courses_list_string .= '<input type="hidden" name="subscribe" value="'.$course['code'].'" />';
  549. $courses_list_string .= '<input type="image" name="unsub" src="main/img/enroll.gif" alt="'.get_lang('Subscribe').'" />'.get_lang('Subscribe').'</form>';
  550. */
  551. $courses_list_string .= '&nbsp;<a class="btn btn-primary" href="main/auth/courses.php?action=subscribe_course&amp;sec_token='.$stok.'&amp;subscribe_course='.$course['code'].'&amp;category_code='.Security::remove_XSS($_GET['category']).'">'.get_lang('Subscribe').'</a><br />';
  552. } else {
  553. $courses_list_string .= '<br />'.get_lang('SubscribingNotAllowed');
  554. }
  555. }
  556. $courses_list_string .= "</li>";
  557. } //end else
  558. } // end foreach
  559. $courses_list_string .= "</ul>";
  560. }
  561. if ($courses_shown > 0) {
  562. // Only display the list of courses and categories if there was more than
  563. // 0 courses visible to the world (we're in the anonymous list here).
  564. $result .= $courses_list_string;
  565. }
  566. if ($category != '') {
  567. $result .= '<p><a href="'.api_get_self().'"> ' . Display :: return_icon('back.png', get_lang('BackToHomePage')) . get_lang('BackToHomePage') . '</a></p>';
  568. }
  569. return $result;
  570. }
  571. /**
  572. * retrieves all the courses that the user has already subscribed to
  573. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  574. * @param int $user_id: the id of the user
  575. * @return array an array containing all the information of the courses of the given user
  576. */
  577. function get_courses_of_user($user_id) {
  578. $table_course = Database::get_main_table(TABLE_MAIN_COURSE);
  579. $table_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  580. // Secondly we select the courses that are in a category (user_course_cat <> 0) and sort these according to the sort of the category
  581. $user_id = intval($user_id);
  582. $sql_select_courses = "SELECT course.code k, course.visual_code vc, course.subscribe subscr, course.unsubscribe unsubscr,
  583. course.title i, course.tutor_name t, course.db_name db, course.directory dir, course_rel_user.status status,
  584. course_rel_user.sort sort, course_rel_user.user_course_cat user_course_cat
  585. FROM $table_course course,
  586. $table_course_user course_rel_user
  587. WHERE course.code = course_rel_user.course_code
  588. AND course_rel_user.user_id = '".$user_id."'
  589. AND course_rel_user.relation_type<>".COURSE_RELATION_TYPE_RRHH."
  590. ORDER BY course_rel_user.sort ASC";
  591. $result = Database::query($sql_select_courses);
  592. $courses = array();
  593. while ($row = Database::fetch_array($result)) {
  594. // We only need the database name of the course.
  595. $courses[$row['k']] = array('db' => $row['db'], 'code' => $row['k'], 'visual_code' => $row['vc'], 'title' => $row['i'], 'directory' => $row['dir'], 'status' => $row['status'], 'tutor' => $row['t'], 'subscribe' => $row['subscr'], 'unsubscribe' => $row['unsubscr'], 'sort' => $row['sort'], 'user_course_category' => $row['user_course_cat']);
  596. }
  597. return $courses;
  598. }
  599. /**
  600. * @todo use the template system
  601. */
  602. function show_right_block($title, $content, $id = null, $params = null) {
  603. if (!empty($id)) {
  604. $params['id'] = $id;
  605. }
  606. $params['class'] = 'well sidebar-nav';
  607. $html = null;
  608. if (!empty($title)) {
  609. $html.= '<h4>'.$title.'</h4>';
  610. }
  611. $html.= $content;
  612. $html = Display::div($html, $params);
  613. return $html;
  614. }
  615. /**
  616. * Adds a form to let users login
  617. * @version 1.1
  618. */
  619. function display_login_form()
  620. {
  621. $form = new FormValidator('formLogin', 'POST', null, null, array('class'=>'form-vertical'));
  622. $form->addElement('text', 'login', get_lang('UserName'), array('id' => 'login', 'class' => 'span2 user_login_icon autocapitalize_off', 'autofocus' => 'autofocus'));
  623. $form->addElement('password', 'password', get_lang('Pass'), array('id' => 'password', 'class' => 'span2 user_password_icon'));
  624. global $_configuration;
  625. // Captcha
  626. $allowCaptcha = isset($_configuration['allow_captcha']) ? $_configuration['allow_captcha'] : false;
  627. if ($allowCaptcha) {
  628. $useCaptcha = isset($_SESSION['loginFailed']) ? $_SESSION['loginFailed'] : null;
  629. if ($useCaptcha) {
  630. $ajax = api_get_path(WEB_AJAX_PATH).'form.ajax.php?a=get_captcha';
  631. $options = array(
  632. 'width' => 250,
  633. 'height' => 90,
  634. 'callback' => $ajax.'&var='.basename(__FILE__, '.php'),
  635. 'sessionVar' => basename(__FILE__, '.php'),
  636. 'imageOptions' => array(
  637. 'font_size' => 20,
  638. 'font_path' => api_get_path(LIBRARY_PATH).'pchart/fonts/',
  639. 'font_file' => 'tahoma.ttf',
  640. //'output' => 'gif'
  641. )
  642. );
  643. // Minimum options using all defaults (including defaults for Image_Text):
  644. //$options = array('callback' => 'qfcaptcha_image.php');
  645. $captcha_question = $form->addElement('CAPTCHA_Image', 'captcha_question', '', $options);
  646. $form->addElement('static', null, null, get_lang('ClickOnTheImageForANewOne'));
  647. $form->addElement('text', 'captcha', get_lang('EnterTheLettersYouSee'));
  648. $form->addRule('captcha', get_lang('EnterTheCharactersYouReadInTheImage'), 'required', null, 'client');
  649. $form->addRule('captcha', get_lang('TheTextYouEnteredDoesNotMatchThePicture'), 'CAPTCHA', $captcha_question);
  650. }
  651. }
  652. $form->addElement('style_submit_button','submitAuth', get_lang('LoginEnter'), array('class' => 'btn'));
  653. $html = $form->return_form();
  654. // The validation is located in the local.inc
  655. /*if ($form->validate()) {
  656. // Prevent re-use of the same CAPTCHA phrase
  657. $captcha_question->destroy();
  658. }*/
  659. if (api_get_setting('openid_authentication') == 'true') {
  660. include_once 'main/auth/openid/login.php';
  661. $html .= '<div>'.openid_form().'</div>';
  662. }
  663. return $html;
  664. }
  665. function return_search_block() {
  666. $html = '';
  667. if (api_get_setting('search_enabled') == 'true') {
  668. $html .= '<div class="searchbox">';
  669. $search_btn = get_lang('Search');
  670. $search_content = '<br />
  671. <form action="main/search/" method="post">
  672. <input type="text" id="query" class="span2" name="query" value="" />
  673. <button class="save" type="submit" name="submit" value="'.$search_btn.'" />'.$search_btn.' </button>
  674. </form></div>';
  675. $html .= self::show_right_block(get_lang('Search'), $search_content, 'search_block');
  676. }
  677. return $html;
  678. }
  679. function return_classes_block() {
  680. $html = '';
  681. if (api_get_setting('show_groups_to_users') == 'true') {
  682. require_once api_get_path(LIBRARY_PATH).'usergroup.lib.php';
  683. $usergroup = new Usergroup();
  684. $usergroup_list = $usergroup->get_usergroup_by_user(api_get_user_id());
  685. $classes = '';
  686. if (!empty($usergroup_list)) {
  687. foreach($usergroup_list as $group_id) {
  688. $data = $usergroup->get($group_id);
  689. $data['name'] = Display::url($data['name'], api_get_path(WEB_CODE_PATH).'user/classes.php?id='.$data['id']);
  690. $classes .= Display::tag('li', $data['name']);
  691. }
  692. }
  693. if (api_is_platform_admin()) {
  694. $classes .= Display::tag('li', Display::url(get_lang('AddClasses') ,api_get_path(WEB_CODE_PATH).'admin/usergroups.php?action=add'));
  695. }
  696. if (!empty($classes)) {
  697. $classes = Display::tag('ul', $classes, array('class'=>'nav nav-list'));
  698. $html .= self::show_right_block(get_lang('Classes'), $classes, 'classes_block');
  699. }
  700. }
  701. return $html;
  702. }
  703. function return_reservation_block() {
  704. $html = '';
  705. $booking_content = null;
  706. if (api_get_setting('allow_reservation') == 'true' && api_is_allowed_to_create_course()) {
  707. $booking_content .='<ul class="nav nav-list">';
  708. $booking_content .='<a href="main/reservation/reservation.php">'.get_lang('ManageReservations').'</a><br />';
  709. $booking_content .='</ul>';
  710. $html .= self::show_right_block(get_lang('Booking'), $booking_content, 'reservation_block');
  711. }
  712. return $html;
  713. }
  714. function return_user_image_block() {
  715. $img_array = UserManager::get_user_picture_path_by_id(api_get_user_id(), 'web', true, true);
  716. $img_array = UserManager::get_picture_user(api_get_user_id(), $img_array['file'], 50, USER_IMAGE_SIZE_MEDIUM, ' width="90" height="90" ');
  717. $profile_content = null;
  718. if (api_get_setting('allow_social_tool') == 'true') {
  719. $profile_content .='<a style="text-align:center" href="'.api_get_path(WEB_PATH).'main/social/home.php"><img src="'.$img_array['file'].'" '.$img_array['style'].' ></a>';
  720. } else {
  721. $profile_content .='<a style="text-align:center" href="'.api_get_path(WEB_PATH).'main/auth/profile.php"><img title="'.get_lang('EditProfile').'" src="'.$img_array['file'].'" '.$img_array['style'].'></a>';
  722. }
  723. $html = self::show_right_block(null, $profile_content, 'user_image_block', array('style' => 'text-align:center;'));
  724. return $html;
  725. }
  726. function return_profile_block()
  727. {
  728. global $_configuration;
  729. $user_id = api_get_user_id();
  730. if (empty($user_id)) {
  731. return;
  732. }
  733. $profile_content = '<ul class="nav nav-list">';
  734. // @todo Add a platform setting to add the user image.
  735. if (api_get_setting('allow_message_tool') == 'true') {
  736. require_once api_get_path(LIBRARY_PATH).'group_portal_manager.lib.php';
  737. // New messages.
  738. $number_of_new_messages = MessageManager::get_new_messages();
  739. // New contact invitations.
  740. $number_of_new_messages_of_friend = SocialManager::get_message_number_invitation_by_user_id(api_get_user_id());
  741. // New group invitations sent by a moderator.
  742. $group_pending_invitations = GroupPortalManager::get_groups_by_user(api_get_user_id(), GROUP_USER_PERMISSION_PENDING_INVITATION, false);
  743. $group_pending_invitations = count($group_pending_invitations);
  744. $total_invitations = $number_of_new_messages_of_friend + $group_pending_invitations;
  745. $cant_msg = Display::badge($number_of_new_messages);
  746. $link = '';
  747. if (api_get_setting('allow_social_tool') == 'true') {
  748. $link = '?f=social';
  749. }
  750. $profile_content .= '<li class="inbox-social"><a href="'.api_get_path(WEB_PATH).'main/messages/inbox.php'.$link.'">'.get_lang('Inbox').$cant_msg.' </a></li>';
  751. $profile_content .= '<li class="new-message-social"><a href="'.api_get_path(WEB_PATH).'main/messages/new_message.php'.$link.'">'.get_lang('Compose').' </a></li>';
  752. if (api_get_setting('allow_social_tool') == 'true') {
  753. $total_invitations = Display::badge($total_invitations);
  754. $profile_content .= '<li class="invitations-social"><a href="'.api_get_path(WEB_PATH).'main/social/invitations.php">'.get_lang('PendingInvitations').$total_invitations.'</a></li>';
  755. }
  756. if (isset($_configuration['allow_my_files_link_in_homepage']) && $_configuration['allow_my_files_link_in_homepage']) {
  757. $profile_content .= '<li class="myfiles-social"><a href="'.api_get_path(WEB_PATH).'main/social/myfiles.php">'.get_lang('MyFiles').'</a></li>';
  758. }
  759. }
  760. $editProfileUrl = api_get_path(WEB_CODE_PATH) . 'auth/profile.php';
  761. if (api_get_setting('sso_authentication') === 'true') {
  762. $subSSOClass = api_get_setting('sso_authentication_subclass');
  763. $objSSO = null;
  764. if (!empty($subSSOClass)) {
  765. require_once api_get_path(SYS_CODE_PATH) . 'auth/sso/sso.' . $subSSOClass . '.class.php';
  766. $subSSOClass = 'sso' . $subSSOClass;
  767. $objSSO = new $subSSOClass();
  768. } else {
  769. $objSSO = new sso();
  770. }
  771. $editProfileUrl = $objSSO->generateProfileEditingURL();
  772. }
  773. $profile_content .= '<li class="profile-social"><a href="' . $editProfileUrl . '">'.get_lang('EditProfile').'</a></li>';
  774. $profile_content .= '</ul>';
  775. $html = self::show_right_block(get_lang('Profile'), $profile_content, 'profile_block');
  776. return $html;
  777. }
  778. function return_navigation_links() {
  779. $html = '';
  780. // Deleting the myprofile link.
  781. if (api_get_setting('allow_social_tool') == 'true') {
  782. unset($this->tpl->menu_navigation['myprofile']);
  783. }
  784. // Main navigation section.
  785. // Tabs that are deactivated are added here.
  786. if (!empty($this->tpl->menu_navigation)) {
  787. $content = '<ul class="nav nav-list">';
  788. foreach ($this->tpl->menu_navigation as $section => $navigation_info) {
  789. $current = $section == $GLOBALS['this_section'] ? ' id="current"' : '';
  790. $content .= '<li'.$current.'>';
  791. $content .= '<a href="'.$navigation_info['url'].'" target="_self">'.$navigation_info['title'].'</a>';
  792. $content .= '</li>';
  793. }
  794. $content .= '</ul>';
  795. $html = self::show_right_block(get_lang('MainNavigation'), $content, 'navigation_link_block');
  796. }
  797. return $html;
  798. }
  799. function return_course_block() {
  800. $html = '';
  801. $show_create_link = false;
  802. $show_course_link = false;
  803. if ((api_get_setting('allow_users_to_create_courses') == 'false' && !api_is_platform_admin()) || api_is_student()) {
  804. $display_add_course_link = false;
  805. } else {
  806. $display_add_course_link = true;
  807. }
  808. //$display_add_course_link = api_is_allowed_to_create_course() && ($_SESSION['studentview'] != 'studentenview');
  809. if ($display_add_course_link) {
  810. $show_create_link = true;
  811. }
  812. if (api_is_platform_admin() || api_is_course_admin() || api_is_allowed_to_create_course()) {
  813. $show_course_link = true;
  814. } else {
  815. if (api_get_setting('allow_students_to_browse_courses') == 'true') {
  816. $show_course_link = true;
  817. }
  818. }
  819. // My account section
  820. $my_account_content = '<ul class="nav nav-list">';
  821. if ($show_create_link) {
  822. $my_account_content .= '<li class="add-course"><a href="main/create_course/add_course.php">';
  823. if (api_get_setting('course_validation') == 'true' && !api_is_platform_admin()) {
  824. $my_account_content .= get_lang('CreateCourseRequest');
  825. } else {
  826. $my_account_content .= get_lang('CourseCreate');
  827. }
  828. $my_account_content .= '</a></li>';
  829. }
  830. //Sort courses
  831. $url = api_get_path(WEB_CODE_PATH).'auth/courses.php?action=sortmycourses';
  832. $my_account_content .= '<li class="order-course">'.Display::url(get_lang('SortMyCourses'), $url, array('class' => 'sort course')).'</li>';
  833. // Session history
  834. if (isset($_GET['history']) && intval($_GET['history']) == 1) {
  835. $my_account_content .= '<li class="history-course"><a href="user_portal.php">'.get_lang('DisplayTrainingList').'</a></li>';
  836. } else {
  837. $my_account_content .= '<li class="history-course"><a href="user_portal.php?history=1" >'.get_lang('HistoryTrainingSessions').'</a></li>';
  838. }
  839. // Course catalog
  840. if ($show_course_link) {
  841. if (!api_is_drh()) {
  842. $my_account_content .= '<li class="list-course"><a href="main/auth/courses.php" >'.get_lang('CourseCatalog').'</a></li>';
  843. } else {
  844. $my_account_content .= '<li><a href="main/dashboard/index.php">'.get_lang('Dashboard').'</a></li>';
  845. }
  846. }
  847. $my_account_content .= '</ul>';
  848. if (!empty($my_account_content)) {
  849. $html = self::show_right_block(get_lang('Courses'), $my_account_content, 'course_block');
  850. }
  851. return $html;
  852. }
  853. /**
  854. * Prints the session and course list (user_portal.php)
  855. * @param int $user_id
  856. * @return string
  857. */
  858. public function return_courses_and_sessions($user_id)
  859. {
  860. global $_configuration;
  861. $load_history = (isset($_GET['history']) && intval($_GET['history']) == 1) ? true : false;
  862. if ($load_history) {
  863. // Load sessions in category in *history*
  864. $session_categories = UserManager::get_sessions_by_category(
  865. $user_id,
  866. true
  867. );
  868. } else {
  869. // Load sessions in category
  870. $session_categories = UserManager::get_sessions_by_category(
  871. $user_id,
  872. false
  873. );
  874. }
  875. $html = '';
  876. // Showing history title
  877. if ($load_history) {
  878. $html .= Display::page_subheader(get_lang('HistoryTrainingSession'));
  879. if (empty($session_categories)) {
  880. $html .= get_lang('YouDoNotHaveAnySessionInItsHistory');
  881. }
  882. }
  883. $courses_html = '';
  884. $special_courses = '';
  885. // If we're not in the history view...
  886. if (!isset($_GET['history'])) {
  887. // Display special courses.
  888. $special_courses = CourseManager::display_special_courses($user_id, $this->load_directories_preview);
  889. // Display courses.
  890. $courses_html .= CourseManager::display_courses($user_id, $this->load_directories_preview);
  891. }
  892. $sessions_with_category = '';
  893. $sessions_with_no_category = '';
  894. if (is_array($session_categories)) {
  895. foreach ($session_categories as $session_category) {
  896. $session_category_id = $session_category['session_category']['id'];
  897. // Sessions and courses that are not in a session category
  898. if ($session_category_id == 0 &&
  899. isset($session_category['sessions'])
  900. ) {
  901. // Independent sessions
  902. foreach ($session_category['sessions'] as $session) {
  903. $session_id = $session['session_id'];
  904. // Don't show empty sessions.
  905. if (count($session['courses']) < 1) {
  906. continue;
  907. }
  908. // Courses inside the current session.
  909. $date_session_start = $session['date_start'];
  910. $date_session_end = $session['date_end'];
  911. $days_access_before_beginning = $session['nb_days_access_before_beginning'];
  912. $days_access_after_end = $session['nb_days_access_after_end'];
  913. $session_now = time();
  914. $count_courses_session = 0;
  915. // Loop course content
  916. $html_courses_session = '';
  917. $atLeastOneCourseIsVisible = false;
  918. foreach ($session['courses'] as $course) {
  919. $is_coach_course = api_is_coach($session_id, $course['code']);
  920. $allowed_time = 0;
  921. $dif_time_after = 0;
  922. if ($date_session_start != '0000-00-00') {
  923. if ($is_coach_course) {
  924. $allowed_time = api_strtotime($date_session_start.' 00:00:00') - ($days_access_before_beginning * 86400);
  925. } else {
  926. $allowed_time = api_strtotime($date_session_start.' 00:00:00');
  927. }
  928. if (!isset($_GET['history'])) {
  929. if ($date_session_end != '0000-00-00') {
  930. $endSessionToTms = api_strtotime($date_session_end.' 23:59:59');
  931. if ($session_now > $endSessionToTms) {
  932. $dif_time_after = $session_now - $endSessionToTms;
  933. $dif_time_after = round($dif_time_after/86400);
  934. }
  935. }
  936. }
  937. }
  938. if ($session_now > $allowed_time && $days_access_after_end > $dif_time_after - 1) {
  939. // Read only and accessible.
  940. $atLeastOneCourseIsVisible = true;
  941. if (api_get_setting('hide_courses_in_sessions') == 'false') {
  942. $c = CourseManager::get_logged_user_course_html(
  943. $course,
  944. $session_id,
  945. 'session_course_item',
  946. true,
  947. $this->load_directories_preview
  948. );
  949. $html_courses_session .= $c[1];
  950. }
  951. $count_courses_session++;
  952. }
  953. }
  954. // No courses to show.
  955. if ($atLeastOneCourseIsVisible == false) {
  956. if (empty($html_courses_session)) {
  957. continue;
  958. }
  959. }
  960. if ($count_courses_session > 0) {
  961. $params = array();
  962. $session_box = Display::get_session_title_box($session_id);
  963. $params['icon'] = Display::return_icon('window_list.png', $session_box['title'], array('id' => 'session_img_'.$session_id), ICON_SIZE_LARGE);
  964. $extra_info = !empty($session_box['coach']) ? $session_box['coach'] : null;
  965. $extra_info .= !empty($session_box['coach']) ? ' - '.$session_box['dates'] : $session_box['dates'];
  966. $extra_info .= isset($session_box['duration']) ? ' '.$session_box['duration'] : null;
  967. if (api_is_drh()) {
  968. $session_link = $session_box['title'];
  969. $params['link'] = null;
  970. } else {
  971. $session_link = Display::tag('a', $session_box['title'], array('href'=>api_get_path(WEB_CODE_PATH).'session/index.php?session_id='.$session_id));
  972. $params['link'] = api_get_path(WEB_CODE_PATH).'session/index.php?session_id='.$session_id;
  973. }
  974. $params['title'] = $session_link;
  975. $params['subtitle'] = $extra_info;
  976. $params['right_actions'] = '';
  977. if (api_is_platform_admin()) {
  978. $params['right_actions'] .= '<a href="'.api_get_path(WEB_CODE_PATH).'admin/resume_session.php?id_session='.$session_id.'">';
  979. $params['right_actions'] .= Display::return_icon('edit.png', get_lang('Edit'), array('align' => 'absmiddle'), ICON_SIZE_SMALL).'</a>';
  980. }
  981. if (api_get_setting('hide_courses_in_sessions') == 'false') {
  982. // $params['extra'] .= $html_courses_session;
  983. }
  984. $params['description'] = isset($session_box['description']) ? $session_box['description'] : null;
  985. $parentInfo = CourseManager::course_item_html($params, true);
  986. if (isset($_configuration['show_simple_session_info']) && $_configuration['show_simple_session_info']) {
  987. $params['title'] = $session_box['title'];
  988. $parentInfo = CourseManager::course_item_html_no_icon($params);
  989. }
  990. $sessions_with_no_category .= CourseManager::course_item_parent($parentInfo, $html_courses_session);
  991. }
  992. }
  993. } else {
  994. // All sessions included in
  995. $count_courses_session = 0;
  996. $html_sessions = '';
  997. if (isset($session_category['sessions'])) {
  998. foreach ($session_category['sessions'] as $session) {
  999. $session_id = $session['session_id'];
  1000. // Don't show empty sessions.
  1001. if (count($session['courses']) < 1) {
  1002. continue;
  1003. }
  1004. $date_session_start = $session['date_start'];
  1005. $date_session_end = $session['date_end'];
  1006. $days_access_before_beginning = $session['nb_days_access_before_beginning'];
  1007. $days_access_after_end = $session['nb_days_access_after_end'];
  1008. $session_now = time();
  1009. $html_courses_session = '';
  1010. $count = 0;
  1011. foreach ($session['courses'] as $course) {
  1012. $is_coach_course = api_is_coach(
  1013. $session_id,
  1014. $course['code']
  1015. );
  1016. $dif_time_after = 0;
  1017. $allowed_time = 0;
  1018. if ($is_coach_course) {
  1019. // 24 hours = 86400
  1020. if ($date_session_start != '0000-00-00') {
  1021. $allowed_time = api_strtotime($date_session_start . ' 00:00:00') - ($days_access_before_beginning * 86400);
  1022. }
  1023. if ($date_session_end != '0000-00-00') {
  1024. $endSessionToTms = api_strtotime($date_session_end . ' 23:59:59');
  1025. if ($session_now > $endSessionToTms) {
  1026. $dif_time_after = $session_now - $endSessionToTms;
  1027. $dif_time_after = round(
  1028. $dif_time_after / 86400
  1029. );
  1030. }
  1031. }
  1032. } else {
  1033. $allowed_time = api_strtotime(
  1034. $date_session_start . ' 00:00:00'
  1035. );
  1036. }
  1037. if ($session_now > $allowed_time && $days_access_after_end > $dif_time_after - 1) {
  1038. if (api_get_setting('hide_courses_in_sessions') == 'false') {
  1039. $c = CourseManager:: get_logged_user_course_html(
  1040. $course,
  1041. $session_id,
  1042. 'session_course_item'
  1043. );
  1044. $html_courses_session .= $c[1];
  1045. }
  1046. $count_courses_session++;
  1047. $count++;
  1048. }
  1049. }
  1050. $params = array();
  1051. if ($count > 0) {
  1052. $session_box = Display:: get_session_title_box(
  1053. $session_id
  1054. );
  1055. $params['icon'] = Display::return_icon(
  1056. 'window_list.png',
  1057. $session_box['title'],
  1058. array(
  1059. 'width' => '48px',
  1060. 'align' => 'absmiddle',
  1061. 'id' => 'session_img_' . $session_id
  1062. )
  1063. ) . ' ';
  1064. if (api_is_drh()) {
  1065. $session_link = $session_box['title'];
  1066. $params['link'] = null;
  1067. } else {
  1068. $session_link = Display::tag(
  1069. 'a',
  1070. $session_box['title'],
  1071. array(
  1072. 'href' => api_get_path(WEB_CODE_PATH) . 'session/index.php?session_id=' . $session_id
  1073. )
  1074. );
  1075. $params['link'] = api_get_path(WEB_CODE_PATH) . 'session/index.php?session_id=' . $session_id;
  1076. }
  1077. $params['title'] = $session_link;
  1078. $params['subtitle'] = (!empty($session_box['coach']) ? $session_box['coach'] . ' | ' : '') . $session_box['dates'];
  1079. if (api_is_platform_admin()) {
  1080. $params['right_actions'] = '<a href="' . api_get_path(WEB_CODE_PATH) . 'admin/resume_session.php?id_session=' . $session_id . '">' .
  1081. Display::return_icon(
  1082. 'edit.png',
  1083. get_lang('Edit'),
  1084. array('align' => 'absmiddle'),
  1085. ICON_SIZE_SMALL
  1086. ) . '</a>';
  1087. }
  1088. $parentInfo = CourseManager::course_item_html(
  1089. $params,
  1090. true
  1091. );
  1092. if (isset($_configuration['show_simple_session_info']) && $_configuration['show_simple_session_info']) {
  1093. $params['title'] = $session_box['title'];
  1094. $parentInfo = CourseManager::course_item_html_no_icon(
  1095. $params
  1096. );
  1097. }
  1098. $html_sessions .= $parentInfo . $html_courses_session;
  1099. }
  1100. }
  1101. }
  1102. if ($count_courses_session > 0) {
  1103. $params = array();
  1104. $params['icon'] = Display::return_icon('folder_blue.png', $session_category['session_category']['name'], array(), ICON_SIZE_LARGE);
  1105. if (api_is_platform_admin()) {
  1106. $params['right_actions'] = '<a href="'.api_get_path(WEB_CODE_PATH).'admin/session_category_edit.php?&id='.$session_category['session_category']['id'].'">'.Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL).'</a>';
  1107. }
  1108. $params['title'] = $session_category['session_category']['name'];
  1109. if (api_is_platform_admin()) {
  1110. $params['link'] = api_get_path(WEB_CODE_PATH).'admin/session_category_edit.php?&id='.$session_category['session_category']['id'];
  1111. }
  1112. $session_category_start_date = $session_category['session_category']['date_start'];
  1113. $session_category_end_date = $session_category['session_category']['date_end'];
  1114. if (!empty($session_category_start_date) && $session_category_start_date != '0000-00-00' && !empty($session_category_end_date) && $session_category_end_date != '0000-00-00' ) {
  1115. $params['subtitle'] = sprintf(get_lang('FromDateXToDateY'), $session_category['session_category']['date_start'], $session_category['session_category']['date_end']);
  1116. } else {
  1117. if (!empty($session_category_start_date) && $session_category_start_date != '0000-00-00') {
  1118. $params['subtitle'] = get_lang('From').' '.$session_category_start_date;
  1119. }
  1120. if (!empty($session_category_end_date) && $session_category_end_date != '0000-00-00') {
  1121. $params['subtitle'] = get_lang('Until').' '.$session_category_end_date;
  1122. }
  1123. }
  1124. $sessions_with_category .= CourseManager::course_item_parent(
  1125. CourseManager::course_item_html($params, true),
  1126. $html_sessions
  1127. );
  1128. }
  1129. }
  1130. }
  1131. }
  1132. return $sessions_with_category.
  1133. $sessions_with_no_category.
  1134. $courses_html.$special_courses;
  1135. }
  1136. /**
  1137. * Shows a welcome message when the user doesn't have any content in the course list
  1138. */
  1139. public function return_welcome_to_course_block()
  1140. {
  1141. $count_courses = CourseManager::count_courses();
  1142. $tpl = $this->tpl->get_template('layout/welcome_to_course.tpl');
  1143. $course_catalog_url = api_get_path(WEB_CODE_PATH).'auth/courses.php';
  1144. $course_list_url = api_get_path(WEB_PATH).'user_portal.php';
  1145. $this->tpl->assign('course_catalog_url', $course_catalog_url);
  1146. $this->tpl->assign('course_list_url', $course_list_url);
  1147. $this->tpl->assign('course_catalog_link', Display::url(get_lang('here'), $course_catalog_url));
  1148. $this->tpl->assign('course_list_link', Display::url(get_lang('here'), $course_list_url));
  1149. $this->tpl->assign('count_courses', $count_courses);
  1150. return $this->tpl->fetch($tpl);
  1151. }
  1152. /**
  1153. * @return array
  1154. */
  1155. public function return_hot_courses()
  1156. {
  1157. return CourseManager::return_hot_courses();
  1158. }
  1159. }