userportal.lib.php 65 KB

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