userportal.lib.php 79 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Class IndexManager
  5. */
  6. class IndexManager
  7. {
  8. const VIEW_BY_DEFAULT = 0;
  9. const VIEW_BY_SESSION = 1;
  10. // An instance of the template engine
  11. public $tpl = false;
  12. public $name = '';
  13. public $home = '';
  14. public $default_home = 'home/';
  15. /**
  16. * Construct
  17. * @param string $title
  18. */
  19. public function __construct($title)
  20. {
  21. $this->tpl = new Template($title);
  22. $this->home = api_get_home_path();
  23. $this->user_id = api_get_user_id();
  24. $this->load_directories_preview = false;
  25. // Load footer plugins systematically
  26. /*$config = api_get_settings_params(array('subkey = ? ' => 'customfooter', ' AND category = ? ' => 'Plugins'));
  27. if (!empty($config)) {
  28. foreach ($config as $fooid => $configrecord) {
  29. $canonic = preg_replace('/^customfooter_/', '', $configrecord['variable']);
  30. $footerconfig->$canonic = $configrecord['selected_value'];
  31. }
  32. if (!empty($footerconfig->footer_left)) {
  33. $this->tpl->assign('plugin_footer_left', $footerconfig->footer_left);
  34. }
  35. if (!empty($footerconfig->footer_right)) {
  36. $this->tpl->assign('plugin_footer_right', $footerconfig->footer_right);
  37. }
  38. }*/
  39. if (api_get_setting('show_documents_preview') === 'true') {
  40. $this->load_directories_preview = true;
  41. }
  42. }
  43. /**
  44. * @param bool $setLoginForm
  45. */
  46. public function set_login_form($setLoginForm = true)
  47. {
  48. global $loginFailed;
  49. $this->tpl->setLoginForm($setLoginForm);
  50. }
  51. /**
  52. * @param array $personal_course_list
  53. */
  54. public function return_exercise_block($personal_course_list)
  55. {
  56. $exercise_list = array();
  57. if (!empty($personal_course_list)) {
  58. foreach ($personal_course_list as $course_item) {
  59. $course_code = $course_item['c'];
  60. $session_id = $course_item['id_session'];
  61. $exercises = ExerciseLib::get_exercises_to_be_taken(
  62. $course_code,
  63. $session_id
  64. );
  65. foreach ($exercises as $exercise_item) {
  66. $exercise_item['course_code'] = $course_code;
  67. $exercise_item['session_id'] = $session_id;
  68. $exercise_item['tms'] = api_strtotime($exercise_item['end_time'], 'UTC');
  69. $exercise_list[] = $exercise_item;
  70. }
  71. }
  72. if (!empty($exercise_list)) {
  73. $exercise_list = msort($exercise_list, 'tms');
  74. $my_exercise = $exercise_list[0];
  75. $url = Display::url(
  76. $my_exercise['title'],
  77. api_get_path(WEB_CODE_PATH).'exercise/overview.php?exerciseId='.$my_exercise['id'].'&cidReq='.$my_exercise['course_code'].'&id_session='.$my_exercise['session_id']
  78. );
  79. $this->tpl->assign('exercise_url', $url);
  80. $this->tpl->assign('exercise_end_date', api_convert_and_format_date($my_exercise['end_time'], DATE_FORMAT_SHORT));
  81. }
  82. }
  83. }
  84. /**
  85. * @param bool $show_slide
  86. * @return null|string
  87. */
  88. public function return_announcements($show_slide = true)
  89. {
  90. // Display System announcements
  91. $hideAnnouncements = api_get_setting('hide_global_announcements_when_not_connected');
  92. $currentUserId = api_get_user_id();
  93. if ($hideAnnouncements == 'true' && empty($currentUserId)) {
  94. return null;
  95. }
  96. $announcement = isset($_GET['announcement']) ? $_GET['announcement'] : null;
  97. $announcement = intval($announcement);
  98. if (!api_is_anonymous() && $this->user_id) {
  99. $visibility = api_is_allowed_to_create_course() ? SystemAnnouncementManager::VISIBLE_TEACHER : SystemAnnouncementManager::VISIBLE_STUDENT;
  100. if ($show_slide) {
  101. $announcements = SystemAnnouncementManager:: display_announcements_slider(
  102. $visibility,
  103. $announcement
  104. );
  105. } else {
  106. $announcements = SystemAnnouncementManager:: display_all_announcements(
  107. $visibility,
  108. $announcement
  109. );
  110. }
  111. } else {
  112. if ($show_slide) {
  113. $announcements = SystemAnnouncementManager:: display_announcements_slider(
  114. SystemAnnouncementManager::VISIBLE_GUEST,
  115. $announcement
  116. );
  117. } else {
  118. $announcements = SystemAnnouncementManager:: display_all_announcements(
  119. SystemAnnouncementManager::VISIBLE_GUEST,
  120. $announcement
  121. );
  122. }
  123. }
  124. return $announcements;
  125. }
  126. /**
  127. * Alias for the online_logout() function
  128. * @param bool $redirect Whether to ask online_logout to redirect to index.php or not
  129. */
  130. public function logout($redirect = true)
  131. {
  132. online_logout($this->user_id, true);
  133. }
  134. /**
  135. * This function checks if there are courses that are open to the world in the platform course categories (=faculties)
  136. *
  137. * @param string $category
  138. * @return boolean
  139. */
  140. public function category_has_open_courses($category)
  141. {
  142. $setting_show_also_closed_courses = api_get_setting('show_closed_courses') == 'true';
  143. $main_course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
  144. $category = Database::escape_string($category);
  145. $sql_query = "SELECT * FROM $main_course_table WHERE category_code='$category'";
  146. $sql_result = Database::query($sql_query);
  147. while ($course = Database::fetch_array($sql_result)) {
  148. if (!$setting_show_also_closed_courses) {
  149. if ((api_get_user_id() > 0 && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM) || ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD)) {
  150. return true; //at least one open course
  151. }
  152. } else {
  153. if (isset($course['visibility'])) {
  154. return true; // At least one course (it does not matter weither it's open or not because $setting_show_also_closed_courses = true).
  155. }
  156. }
  157. }
  158. return false;
  159. }
  160. /**
  161. * @return null|string
  162. */
  163. public function return_teacher_link()
  164. {
  165. $html = '';
  166. $show_menu = false;
  167. if (!empty($this->user_id)) {
  168. // tabs that are deactivated are added here
  169. $show_menu = false;
  170. $show_create_link = false;
  171. $show_course_link = false;
  172. if (api_is_allowed_to_create_course()) {
  173. $show_menu = true;
  174. $show_course_link = true;
  175. $show_create_link = true;
  176. } else {
  177. if (api_get_setting('allow_students_to_browse_courses') === 'true') {
  178. $show_menu = true;
  179. $show_course_link = true;
  180. }
  181. if (api_is_allowed_to_create_course()) {
  182. $show_create_link = true;
  183. }
  184. }
  185. if ($show_menu && ($show_create_link || $show_course_link)) {
  186. $show_menu = true;
  187. } else {
  188. $show_menu = false;
  189. }
  190. }
  191. // My Account section
  192. if ($show_menu) {
  193. $html .= '<ul class="nav nav-pills nav-stacked">';
  194. if ($show_create_link) {
  195. $html .= '<li class="add-course"><a href="' . api_get_path(WEB_CODE_PATH) . 'create_course/add_course.php">'.
  196. Display::return_icon('new-course.png', get_lang('CourseCreate')).(api_get_setting('course_validation') == 'true' ? get_lang('CreateCourseRequest') : get_lang('CourseCreate')).'</a></li>';
  197. }
  198. if ($show_course_link) {
  199. if (!api_is_drh() && !api_is_session_admin()) {
  200. $html .= '<li class="list-course"><a href="'. api_get_path(WEB_CODE_PATH) . 'auth/courses.php">'.
  201. Display::return_icon('catalog-course.png', get_lang('CourseCatalog')) .get_lang('CourseCatalog').'</a></li>';
  202. } else {
  203. $html .= '<li><a href="' . api_get_path(WEB_CODE_PATH) . 'dashboard/index.php">'.get_lang('Dashboard').'</a></li>';
  204. }
  205. }
  206. $html .= '</ul>';
  207. }
  208. if (!empty($html)) {
  209. $html = self::show_right_block(
  210. get_lang('Courses'),
  211. $html,
  212. 'teacher_block',
  213. null,
  214. 'teachers',
  215. 'teachersCollapse'
  216. );
  217. }
  218. return $html;
  219. }
  220. /**
  221. * Includes a created page
  222. * @return string
  223. */
  224. public function return_home_page()
  225. {
  226. $userId = api_get_user_id();
  227. // Including the page for the news
  228. $html = '';
  229. if (!empty($_GET['include']) && preg_match('/^[a-zA-Z0-9_-]*\.html$/', $_GET['include'])) {
  230. $open = @(string)file_get_contents($this->home.$_GET['include']);
  231. $html = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
  232. } else {
  233. // Hiding home top when user not connected.
  234. $hideTop = api_get_setting('hide_home_top_when_connected');
  235. if ($hideTop == 'true' && !empty($userId)) {
  236. return $html;
  237. }
  238. if (!empty($_SESSION['user_language_choice'])) {
  239. $user_selected_language = $_SESSION['user_language_choice'];
  240. } elseif (!empty($_SESSION['_user']['language'])) {
  241. $user_selected_language = $_SESSION['_user']['language'];
  242. } else {
  243. $user_selected_language = api_get_setting('platformLanguage');
  244. }
  245. $home_top_temp = '';
  246. // Try language specific home
  247. if (file_exists($this->home.'home_top_'.$user_selected_language.'.html')) {
  248. $home_top_temp = file_get_contents($this->home.'home_top_'.$user_selected_language.'.html');
  249. }
  250. // Try default language home
  251. if (empty($home_top_temp)) {
  252. if (file_exists($this->home.'home_top.html')) {
  253. $home_top_temp = file_get_contents($this->home.'home_top.html');
  254. } else {
  255. if (file_exists($this->default_home.'home_top.html')) {
  256. $home_top_temp = file_get_contents($this->default_home . 'home_top.html');
  257. }
  258. }
  259. }
  260. if (trim($home_top_temp) == '' && api_is_platform_admin()) {
  261. $home_top_temp = '<div class="welcome-mascot">' . get_lang('PortalHomepageDefaultIntroduction') . '</div>';
  262. } else {
  263. $home_top_temp = '<div class="welcome-home-top-temp">' . $home_top_temp . '</div>';
  264. }
  265. $open = str_replace('{rel_path}', api_get_path(REL_PATH), $home_top_temp);
  266. $html = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
  267. }
  268. return $html;
  269. }
  270. /**
  271. * @return string
  272. */
  273. public function return_notice()
  274. {
  275. $user_selected_language = api_get_interface_language();
  276. $html = '';
  277. // Notice
  278. $home_notice = @(string)file_get_contents($this->home.'home_notice_'.$user_selected_language.'.html');
  279. if (empty($home_notice)) {
  280. $home_notice = @(string)file_get_contents($this->home.'home_notice.html');
  281. }
  282. if (!empty($home_notice)) {
  283. $home_notice = api_to_system_encoding($home_notice, api_detect_encoding(strip_tags($home_notice)));
  284. $html = self::show_right_block(
  285. get_lang('Notice'),
  286. $home_notice,
  287. 'notice_block',
  288. null,
  289. 'notices',
  290. 'noticesCollapse'
  291. );
  292. }
  293. return $html;
  294. }
  295. /**
  296. * @return string
  297. */
  298. public function return_help()
  299. {
  300. $user_selected_language = api_get_interface_language();
  301. $platformLanguage = api_get_setting('platformLanguage');
  302. // Help section.
  303. /* Hide right menu "general" and other parts on anonymous right menu. */
  304. if (!isset($user_selected_language)) {
  305. $user_selected_language = $platformLanguage;
  306. }
  307. $html = '';
  308. $home_menu = @(string)file_get_contents($this->home.'home_menu_'.$user_selected_language.'.html');
  309. if (!empty($home_menu)) {
  310. $home_menu_content = '<ul class="nav nav-pills nav-stacked">';
  311. $home_menu_content .= api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
  312. $home_menu_content .= '</ul>';
  313. $html .= self::show_right_block(
  314. get_lang('MenuGeneral'),
  315. $home_menu_content,
  316. 'help_block',
  317. null,
  318. 'helps',
  319. 'helpsCollapse'
  320. );
  321. }
  322. return $html;
  323. }
  324. /**
  325. * @return null|string
  326. */
  327. public function return_skills_links()
  328. {
  329. $content = '<ul class="nav nav-pills nav-stacked">';
  330. /**
  331. * Generate the block for show a panel with links to My Certificates and Certificates Search pages
  332. * @return string The HTML code for the panel
  333. */
  334. $certificatesItem = '';
  335. if (!api_is_anonymous()) {
  336. $allow = api_get_configuration_value('hide_my_certificate_link');
  337. if ($allow === false) {
  338. $certificatesItem = Display::tag(
  339. 'li',
  340. Display::url(
  341. Display::return_icon(
  342. 'graduation.png',
  343. get_lang('MyCertificates'),
  344. null,
  345. ICON_SIZE_SMALL
  346. ).
  347. get_lang('MyCertificates'),
  348. api_get_path(WEB_CODE_PATH)."gradebook/my_certificates.php"
  349. )
  350. );
  351. }
  352. }
  353. $searchItem = '';
  354. if (api_get_setting('allow_public_certificates') == 'true') {
  355. $searchItem = Display::tag(
  356. 'li',
  357. Display::url(Display::return_icon('search_graduation.png',get_lang('Search'),null,ICON_SIZE_SMALL).
  358. get_lang('Search'),
  359. api_get_path(WEB_CODE_PATH) . "gradebook/search.php"
  360. )
  361. );
  362. }
  363. if (empty($certificatesItem) && empty($searchItem)) {
  364. return '';
  365. } else {
  366. $content .= $certificatesItem;
  367. $content .= $searchItem;
  368. }
  369. if (api_get_setting('allow_skills_tool') == 'true') {
  370. $content .= Display::tag(
  371. 'li',
  372. Display::url(
  373. Display::return_icon('skill-badges.png',get_lang('MySkills'),null,ICON_SIZE_SMALL).get_lang('MySkills'),
  374. api_get_path(WEB_CODE_PATH).'social/my_skills_report.php'
  375. )
  376. );
  377. $allowSkillsManagement = api_get_setting('allow_hr_skills_management') == 'true';
  378. if (($allowSkillsManagement && api_is_drh()) || api_is_platform_admin()) {
  379. $content .= Display::tag('li',
  380. Display::url(Display::return_icon('edit-skill.png', get_lang('MySkills'), null,
  381. ICON_SIZE_SMALL) . get_lang('ManageSkills'),
  382. api_get_path(WEB_CODE_PATH) . 'admin/skills_wheel.php'));
  383. }
  384. }
  385. $content .= '</ul>';
  386. $html = self::show_right_block(
  387. get_lang("Skills"),
  388. $content,
  389. 'skill_block',
  390. null,
  391. 'skills',
  392. 'skillsCollapse'
  393. );
  394. return $html;
  395. }
  396. /**
  397. * Reacts on a failed login:
  398. * Displays an explanation with a link to the registration form.
  399. *
  400. * @version 1.0.1
  401. */
  402. public function handle_login_failed()
  403. {
  404. return $this->tpl->handleLoginFailed();
  405. }
  406. /**
  407. * Display list of courses in a category.
  408. * (for anonymous users)
  409. *
  410. * @version 1.1
  411. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University - refactoring and code cleaning
  412. * @author Julio Montoya <gugli100@gmail.com>, Beeznest template modifs
  413. */
  414. public function return_courses_in_categories()
  415. {
  416. $result = '';
  417. $stok = Security::get_token();
  418. // Initialization.
  419. $user_identified = (api_get_user_id() > 0 && !api_is_anonymous());
  420. $web_course_path = api_get_path(WEB_COURSE_PATH);
  421. $category = isset($_GET['category']) ? Database::escape_string($_GET['category']) : '';
  422. $setting_show_also_closed_courses = api_get_setting('show_closed_courses') == 'true';
  423. // Database table definitions.
  424. $main_course_table = Database:: get_main_table(TABLE_MAIN_COURSE);
  425. $main_category_table = Database:: get_main_table(TABLE_MAIN_CATEGORY);
  426. // Get list of courses in category $category.
  427. $sql = "SELECT * FROM $main_course_table cours
  428. WHERE category_code = '" . $category . "'
  429. ORDER BY title, UPPER(visual_code)";
  430. // Showing only the courses of the current access_url_id.
  431. if (api_is_multiple_url_enabled()) {
  432. $url_access_id = api_get_current_access_url_id();
  433. if ($url_access_id != -1) {
  434. $tbl_url_rel_course = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
  435. $sql = "SELECT * FROM $main_course_table as course
  436. INNER JOIN $tbl_url_rel_course as url_rel_course
  437. ON (url_rel_course.c_id = course.id)
  438. WHERE
  439. access_url_id = $url_access_id AND
  440. category_code = '".Database::escape_string($_GET['category'])."'
  441. ORDER BY title, UPPER(visual_code)";
  442. }
  443. }
  444. // Removed: AND cours.visibility='".COURSE_VISIBILITY_OPEN_WORLD."'
  445. $sql_result_courses = Database::query($sql);
  446. while ($course_result = Database::fetch_array($sql_result_courses)) {
  447. $course_list[] = $course_result;
  448. }
  449. // $setting_show_also_closed_courses
  450. if ($user_identified) {
  451. if ($setting_show_also_closed_courses) {
  452. $platform_visible_courses = '';
  453. } else {
  454. $platform_visible_courses = " AND (t3.visibility='".COURSE_VISIBILITY_OPEN_WORLD."' OR t3.visibility='".COURSE_VISIBILITY_OPEN_PLATFORM."' )";
  455. }
  456. } else {
  457. if ($setting_show_also_closed_courses) {
  458. $platform_visible_courses = '';
  459. } else {
  460. $platform_visible_courses = " AND (t3.visibility='".COURSE_VISIBILITY_OPEN_WORLD."' )";
  461. }
  462. }
  463. $sqlGetSubCatList = "
  464. SELECT t1.name,
  465. t1.code,
  466. t1.parent_id,
  467. t1.children_count,COUNT(DISTINCT t3.code) AS nbCourse
  468. FROM $main_category_table t1
  469. LEFT JOIN $main_category_table t2 ON t1.code=t2.parent_id
  470. LEFT JOIN $main_course_table t3 ON (t3.category_code = t1.code $platform_visible_courses)
  471. WHERE t1.parent_id ". (empty($category) ? "IS NULL" : "='$category'")."
  472. GROUP BY t1.name,t1.code,t1.parent_id,t1.children_count
  473. ORDER BY t1.tree_pos, t1.name";
  474. // Showing only the category of courses of the current access_url_id
  475. if (api_is_multiple_url_enabled()) {
  476. $table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE_CATEGORY);
  477. $courseCategoryCondition = " INNER JOIN $table a ON (t1.id = a.course_category_id)";
  478. $url_access_id = api_get_current_access_url_id();
  479. if ($url_access_id != -1) {
  480. $tbl_url_rel_course = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
  481. $sqlGetSubCatList = "
  482. SELECT t1.name,
  483. t1.code,
  484. t1.parent_id,
  485. t1.children_count,
  486. COUNT(DISTINCT t3.code) AS nbCourse
  487. FROM $main_category_table t1
  488. $courseCategoryCondition
  489. LEFT JOIN $main_category_table t2 ON t1.code = t2.parent_id
  490. LEFT JOIN $main_course_table t3 ON (t3.category_code = t1.code $platform_visible_courses)
  491. INNER JOIN $tbl_url_rel_course as url_rel_course
  492. ON (url_rel_course.c_id = t3.id)
  493. WHERE
  494. url_rel_course.access_url_id = $url_access_id AND
  495. t1.parent_id ".(empty($category) ? "IS NULL" : "='$category'")."
  496. GROUP BY t1.name,t1.code,t1.parent_id,t1.children_count
  497. ORDER BY t1.tree_pos, t1.name";
  498. }
  499. }
  500. $resCats = Database::query($sqlGetSubCatList);
  501. $thereIsSubCat = false;
  502. if (Database::num_rows($resCats) > 0) {
  503. $htmlListCat = Display::page_header(get_lang('CatList'));
  504. $htmlListCat .= '<ul>';
  505. $htmlTitre = '';
  506. while ($catLine = Database::fetch_array($resCats)) {
  507. $category_has_open_courses = self::category_has_open_courses($catLine['code']);
  508. if ($category_has_open_courses) {
  509. // The category contains courses accessible to anonymous visitors.
  510. $htmlListCat .= '<li>';
  511. $htmlListCat .= '<a href="'.api_get_self().'?category='.$catLine['code'].'">'.$catLine['name'].'</a>';
  512. if (api_get_setting('show_number_of_courses') == 'true') {
  513. $htmlListCat .= ' ('.$catLine['nbCourse'].' '.get_lang('Courses').')';
  514. }
  515. $htmlListCat .= "</li>";
  516. $thereIsSubCat = true;
  517. } elseif ($catLine['children_count'] > 0) {
  518. // The category has children, subcategories.
  519. $htmlListCat .= '<li>';
  520. $htmlListCat .= '<a href="'.api_get_self().'?category='.$catLine['code'].'">'.$catLine['name'].'</a>';
  521. $htmlListCat .= "</li>";
  522. $thereIsSubCat = true;
  523. } elseif (api_get_setting('show_empty_course_categories') == 'true') {
  524. /* End changed code to eliminate the (0 courses) after empty categories. */
  525. $htmlListCat .= '<li>';
  526. $htmlListCat .= $catLine['name'];
  527. $htmlListCat .= "</li>";
  528. $thereIsSubCat = true;
  529. } // Else don't set thereIsSubCat to true to avoid printing things if not requested.
  530. // TODO: deprecate this useless feature - this includes removing system variable
  531. if (empty($htmlTitre)) {
  532. $htmlTitre = '<p>';
  533. if (api_get_setting('show_back_link_on_top_of_tree') == 'true') {
  534. $htmlTitre .= '<a href="'.api_get_self().'">&lt;&lt; '.get_lang('BackToHomePage').'</a>';
  535. }
  536. $htmlTitre .= "</p>";
  537. }
  538. }
  539. $htmlListCat .= "</ul>";
  540. }
  541. $result .= $htmlTitre;
  542. if ($thereIsSubCat) {
  543. $result .= $htmlListCat;
  544. }
  545. while ($categoryName = Database::fetch_array($resCats)) {
  546. $result .= '<h3>' . $categoryName['name'] . "</h3>\n";
  547. }
  548. $numrows = Database::num_rows($sql_result_courses);
  549. $courses_list_string = '';
  550. $courses_shown = 0;
  551. if ($numrows > 0) {
  552. $courses_list_string .= Display::page_header(get_lang('CourseList'));
  553. $courses_list_string .= "<ul>";
  554. if (api_get_user_id()) {
  555. $courses_of_user = self::get_courses_of_user(api_get_user_id());
  556. }
  557. foreach ($course_list as $course) {
  558. // $setting_show_also_closed_courses
  559. if ($course['visibility'] == COURSE_VISIBILITY_HIDDEN) { continue; }
  560. if (!$setting_show_also_closed_courses) {
  561. // If we do not show the closed courses
  562. // we only show the courses that are open to the world (to everybody)
  563. // and the courses that are open to the platform (if the current user is a registered user.
  564. if (($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM) || ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD)) {
  565. $courses_shown++;
  566. $courses_list_string .= "<li>";
  567. $courses_list_string .= '<a href="'.$web_course_path.$course['directory'].'/">'.$course['title'].'</a><br />';
  568. $course_details = array();
  569. if (api_get_setting('display_coursecode_in_courselist') === 'true') {
  570. $course_details[] = $course['visual_code'];
  571. }
  572. if (api_get_setting('display_teacher_in_courselist') === 'true') {
  573. $course_details[] = CourseManager::get_teacher_list_from_course_code_to_string($course['code']);
  574. }
  575. if (api_get_setting('show_different_course_language') === 'true' && $course['course_language'] != api_get_setting('platformLanguage')) {
  576. $course_details[] = $course['course_language'];
  577. }
  578. $courses_list_string .= implode(' - ', $course_details);
  579. $courses_list_string .= "</li>";
  580. }
  581. } else {
  582. // We DO show the closed courses.
  583. // The course is accessible if (link to the course homepage):
  584. // 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);
  585. // 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);
  586. // 3. the user is logged in and the user is subscribed to the course and the course visibility is not COURSE_VISIBILITY_CLOSED;
  587. // 4. the user is logged in and the user is course admin of te course (regardless of the course visibility setting);
  588. // 5. the user is the platform admin api_is_platform_admin().
  589. $courses_shown++;
  590. $courses_list_string .= "<li>";
  591. if ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD
  592. || ($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM)
  593. || ($user_identified && array_key_exists($course['code'], $courses_of_user)
  594. && $course['visibility'] != COURSE_VISIBILITY_CLOSED)
  595. || $courses_of_user[$course['code']]['status'] == '1'
  596. || api_is_platform_admin()) {
  597. $courses_list_string .= '<a href="'.$web_course_path.$course['directory'].'/">';
  598. }
  599. $courses_list_string .= $course['title'];
  600. if ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD
  601. || ($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM)
  602. || ($user_identified && array_key_exists($course['code'], $courses_of_user)
  603. && $course['visibility'] != COURSE_VISIBILITY_CLOSED)
  604. || $courses_of_user[$course['code']]['status'] == '1'
  605. || api_is_platform_admin()) {
  606. $courses_list_string .= '</a><br />';
  607. }
  608. $course_details = array();
  609. if (api_get_setting('display_coursecode_in_courselist') == 'true') {
  610. $course_details[] = $course['visual_code'];
  611. }
  612. // if (api_get_setting('display_coursecode_in_courselist') == 'true' && api_get_setting('display_teacher_in_courselist') == 'true') {
  613. // $courses_list_string .= ' - ';
  614. // }
  615. if (api_get_setting('display_teacher_in_courselist') === 'true') {
  616. if (!empty($course['tutor_name'])) {
  617. $course_details[] = $course['tutor_name'];
  618. }
  619. }
  620. if (api_get_setting('show_different_course_language') == 'true' && $course['course_language'] != api_get_setting('platformLanguage')) {
  621. $course_details[] = $course['course_language'];
  622. }
  623. $courses_list_string .= implode(' - ', $course_details);
  624. // We display a subscription link if:
  625. // 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
  626. // 2.
  627. if ($user_identified && !array_key_exists($course['code'], $courses_of_user)) {
  628. if ($course['subscribe'] == '1') {
  629. $courses_list_string .= '&nbsp;<a class="btn btn-primary" href="main/auth/courses.php?action=subscribe_course&sec_token='.$stok.'&subscribe_course='.$course['code'].'&category_code='.Security::remove_XSS($_GET['category']).'">'.get_lang('Subscribe').'</a><br />';
  630. } else {
  631. $courses_list_string .= '<br />'.get_lang('SubscribingNotAllowed');
  632. }
  633. }
  634. $courses_list_string .= "</li>";
  635. } //end else
  636. } // end foreach
  637. $courses_list_string .= "</ul>";
  638. }
  639. if ($courses_shown > 0) {
  640. // Only display the list of courses and categories if there was more than
  641. // 0 courses visible to the world (we're in the anonymous list here).
  642. $result .= $courses_list_string;
  643. }
  644. if ($category != '') {
  645. $result .= '<p><a href="'.api_get_self().'"> ' .
  646. Display :: return_icon('back.png', get_lang('BackToHomePage')).
  647. get_lang('BackToHomePage') . '</a></p>';
  648. }
  649. return $result;
  650. }
  651. /**
  652. * retrieves all the courses that the user has already subscribed to
  653. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  654. * @param int $user_id: the id of the user
  655. * @return array an array containing all the information of the courses of the given user
  656. */
  657. public function get_courses_of_user($user_id)
  658. {
  659. $table_course = Database::get_main_table(TABLE_MAIN_COURSE);
  660. $table_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  661. // Secondly we select the courses that are in a category (user_course_cat <> 0)
  662. // and sort these according to the sort of the category
  663. $user_id = intval($user_id);
  664. $sql = "SELECT
  665. course.code k,
  666. course.visual_code vc,
  667. course.subscribe subscr,
  668. course.unsubscribe unsubscr,
  669. course.title i,
  670. course.tutor_name t,
  671. course.directory dir,
  672. course_rel_user.status status,
  673. course_rel_user.sort sort,
  674. course_rel_user.user_course_cat user_course_cat
  675. FROM
  676. $table_course course,
  677. $table_course_user course_rel_user
  678. WHERE
  679. course.id = course_rel_user.c_id AND
  680. course_rel_user.user_id = '".$user_id."' AND
  681. course_rel_user.relation_type <> ".COURSE_RELATION_TYPE_RRHH."
  682. ORDER BY course_rel_user.sort ASC";
  683. $result = Database::query($sql);
  684. $courses = array();
  685. while ($row = Database::fetch_array($result)) {
  686. // We only need the database name of the course.
  687. $courses[$row['k']] = array(
  688. 'code' => $row['k'],
  689. 'visual_code' => $row['vc'],
  690. 'title' => $row['i'],
  691. 'directory' => $row['dir'],
  692. 'status' => $row['status'],
  693. 'tutor' => $row['t'],
  694. 'subscribe' => $row['subscr'],
  695. 'unsubscribe' => $row['unsubscr'],
  696. 'sort' => $row['sort'],
  697. 'user_course_category' => $row['user_course_cat']
  698. );
  699. }
  700. return $courses;
  701. }
  702. /**
  703. * @todo use the template system
  704. * @param $title
  705. * @param $content
  706. * @param string $id
  707. * @param array $params
  708. * @param string $idAccordion
  709. * @param string $idCollapse
  710. * @return string
  711. */
  712. public function show_right_block(
  713. $title,
  714. $content,
  715. $id = '',
  716. $params = [],
  717. $idAccordion = '',
  718. $idCollapse = ''
  719. ) {
  720. $html = '';
  721. if (!empty($idAccordion)) {
  722. $html .= '<div class="panel-group" id="'.$idAccordion.'" role="tablist" aria-multiselectable="true">';
  723. $html .= '<div class="panel panel-default" id="'.$id.'">';
  724. $html .= '<div class="panel-heading" role="tab"><h4 class="panel-title">';
  725. $html .= '<a role="button" data-toggle="collapse" data-parent="#'.$idAccordion.'" href="#'.$idCollapse.'" aria-expanded="true" aria-controls="'.$idCollapse.'">'.$title.'</a>';
  726. $html .= '</h4></div>';
  727. $html .= '<div id="'.$idCollapse.'" class="panel-collapse collapse in" role="tabpanel">';
  728. $html .= '<div class="panel-body">'.$content.'</div>';
  729. $html .= '</div></div></div>';
  730. } else {
  731. if (!empty($id)) {
  732. $params['id'] = $id;
  733. }
  734. $params['class'] = 'panel panel-default';
  735. $html = null;
  736. if (!empty($title)) {
  737. $html .= '<div class="panel-heading">'.$title.'</div>';
  738. }
  739. $html.= '<div class="panel-body">'.$content.'</div>';
  740. $html = Display::div($html, $params);
  741. }
  742. return $html;
  743. }
  744. /**
  745. * Adds a form to let users login
  746. * @version 1.1
  747. */
  748. public function display_login_form()
  749. {
  750. return $this->tpl->displayLoginForm();
  751. }
  752. /**
  753. * @todo use FormValidator
  754. * @return string
  755. */
  756. public function return_search_block()
  757. {
  758. $html = '';
  759. if (api_get_setting('search_enabled') == 'true') {
  760. $search_btn = get_lang('Search');
  761. $search_content = '<form action="main/search/" method="post">
  762. <div class="form-group">
  763. <input type="text" id="query" class="form-control" name="query" value="" />
  764. <button class="btn btn-default" type="submit" name="submit" value="'.$search_btn.'" />'.$search_btn.' </button>
  765. </div></form>';
  766. $html .= self::show_right_block(get_lang('Search'), $search_content, 'search_block');
  767. }
  768. return $html;
  769. }
  770. /**
  771. * @return string
  772. */
  773. public function return_classes_block()
  774. {
  775. $html = '';
  776. if (api_get_setting('show_groups_to_users') === 'true') {
  777. $usergroup = new UserGroup();
  778. $usergroup_list = $usergroup->get_usergroup_by_user(api_get_user_id());
  779. $classes = '';
  780. if (!empty($usergroup_list)) {
  781. foreach($usergroup_list as $group_id) {
  782. $data = $usergroup->get($group_id);
  783. $data['name'] = Display::url($data['name'], api_get_path(WEB_CODE_PATH).'user/classes.php?id='.$data['id']);
  784. $classes .= Display::tag('li', $data['name']);
  785. }
  786. }
  787. if (api_is_platform_admin()) {
  788. $classes .= Display::tag(
  789. 'li',
  790. Display::url(get_lang('AddClasses') ,api_get_path(WEB_CODE_PATH).'admin/usergroups.php?action=add')
  791. );
  792. }
  793. if (!empty($classes)) {
  794. $classes = Display::tag('ul', $classes, array('class'=>'nav nav-pills nav-stacked'));
  795. $html .= self::show_right_block(get_lang('Classes'), $classes, 'classes_block');
  796. }
  797. }
  798. return $html;
  799. }
  800. /**
  801. * @return string
  802. */
  803. public function return_user_image_block()
  804. {
  805. $html = '';
  806. if (!api_is_anonymous()) {
  807. $userPicture = UserManager::getUserPicture(api_get_user_id(), USER_IMAGE_SIZE_ORIGINAL);
  808. $content = null;
  809. if (api_get_setting('allow_social_tool') == 'true') {
  810. $content .= '<a style="text-align:center" href="' . api_get_path(WEB_PATH) . 'main/social/home.php">
  811. <img class="img-circle" src="' . $userPicture . '" ></a>';
  812. } else {
  813. $content .= '<a style="text-align:center" href="' . api_get_path(WEB_PATH) . 'main/auth/profile.php">
  814. <img class="img-circle" title="' . get_lang('EditProfile') . '" src="' . $userPicture. '" ></a>';
  815. }
  816. $html = self::show_right_block(
  817. null,
  818. $content,
  819. 'user_image_block',
  820. array('style' => 'text-align:center;')
  821. );
  822. }
  823. return $html;
  824. }
  825. /**
  826. * @return null|string|void
  827. */
  828. public function return_profile_block()
  829. {
  830. global $_configuration;
  831. $user_id = api_get_user_id();
  832. if (empty($user_id)) {
  833. return;
  834. }
  835. $userGroup = new UserGroup();
  836. $profile_content = '<ul class="nav nav-pills nav-stacked">';
  837. // @todo Add a platform setting to add the user image.
  838. if (api_get_setting('allow_message_tool') == 'true') {
  839. // New messages.
  840. $number_of_new_messages = MessageManager::getCountNewMessages();
  841. // New contact invitations.
  842. $number_of_new_messages_of_friend = SocialManager::get_message_number_invitation_by_user_id(api_get_user_id());
  843. // New group invitations sent by a moderator.
  844. $group_pending_invitations = $userGroup->get_groups_by_user(
  845. api_get_user_id(),
  846. GROUP_USER_PERMISSION_PENDING_INVITATION,
  847. false
  848. );
  849. $group_pending_invitations = count($group_pending_invitations);
  850. $total_invitations = $number_of_new_messages_of_friend + $group_pending_invitations;
  851. $cant_msg = Display::badge($number_of_new_messages);
  852. $link = '';
  853. if (api_get_setting('allow_social_tool') == 'true') {
  854. $link = '?f=social';
  855. }
  856. $profile_content .= '<li class="inbox-message-social"><a href="'.api_get_path(WEB_PATH).'main/messages/inbox.php'.$link.'">'.
  857. Display::return_icon('inbox.png',get_lang('Inbox'),null,ICON_SIZE_SMALL).get_lang('Inbox').$cant_msg.' </a></li>';
  858. $profile_content .= '<li class="new-message-social"><a href="'.api_get_path(WEB_PATH).'main/messages/new_message.php'.$link.'">'.
  859. Display::return_icon('new-message.png',get_lang('Compose'),null,ICON_SIZE_SMALL).get_lang('Compose').' </a></li>';
  860. if (api_get_setting('allow_social_tool') == 'true') {
  861. $total_invitations = Display::badge($total_invitations);
  862. $profile_content .= '<li class="invitations-social"><a href="'.api_get_path(WEB_PATH).'main/social/invitations.php">'.Display::return_icon('invitations.png',get_lang('PendingInvitations'),null,ICON_SIZE_SMALL).get_lang('PendingInvitations').$total_invitations.'</a></li>';
  863. }
  864. if (isset($_configuration['allow_my_files_link_in_homepage']) && $_configuration['allow_my_files_link_in_homepage']) {
  865. $myFiles = '<li class="myfiles-social"><a href="'.api_get_path(WEB_PATH).'main/social/myfiles.php">'.
  866. Display::return_icon('sn-files.png',get_lang('Files'),null,ICON_SIZE_SMALL).get_lang('MyFiles').'</a></li>';
  867. if (api_get_setting('allow_my_files') === 'false') {
  868. $myFiles = '';
  869. }
  870. $profile_content .= $myFiles;
  871. }
  872. }
  873. $editProfileUrl = Display::getProfileEditionLink($user_id);
  874. $profile_content .= '<li class="profile-social"><a href="' . $editProfileUrl . '">'.
  875. Display::return_icon(
  876. 'edit-profile.png',
  877. get_lang('EditProfile'),
  878. null,
  879. ICON_SIZE_SMALL
  880. ).
  881. get_lang('EditProfile').'</a></li>';
  882. $profile_content .= '</ul>';
  883. $html = self::show_right_block(
  884. get_lang('Profile'),
  885. $profile_content,
  886. 'profile_block',
  887. null,
  888. 'profile',
  889. 'profileCollapse'
  890. );
  891. $setting = api_get_plugin_setting('bbb', 'enable_global_conference');
  892. $settingLink = api_get_plugin_setting('bbb', 'enable_global_conference_link');
  893. if ($setting === 'true' && $settingLink === 'true') {
  894. $url = api_get_path(WEB_PLUGIN_PATH).'bbb/start.php?global=1';
  895. $content = Display::url(get_lang('LaunchVideoConferenceRoom'), $url);
  896. $html .= self::show_right_block(
  897. get_lang('VideoConference'),
  898. $content,
  899. 'videoconference_block',
  900. null,
  901. 'videoconference',
  902. 'videoconferenceCollapse'
  903. );
  904. }
  905. return $html;
  906. }
  907. /**
  908. * @return null|string
  909. */
  910. public function return_navigation_links()
  911. {
  912. $html = '';
  913. // Deleting the myprofile link.
  914. if (api_get_setting('allow_social_tool') == 'true') {
  915. unset($this->tpl->menu_navigation['myprofile']);
  916. }
  917. // Main navigation section.
  918. // Tabs that are deactivated are added here.
  919. if (!empty($this->tpl->menu_navigation)) {
  920. $content = '<ul class="nav nav-pills nav-stacked">';
  921. foreach ($this->tpl->menu_navigation as $section => $navigation_info) {
  922. $current = $section == $GLOBALS['this_section'] ? ' id="current"' : '';
  923. $content .= '<li'.$current.'>';
  924. $content .= '<a href="'.$navigation_info['url'].'" target="_self">'.$navigation_info['title'].'</a>';
  925. $content .= '</li>';
  926. }
  927. $content .= '</ul>';
  928. $html = self::show_right_block(get_lang('MainNavigation'), $content, 'navigation_link_block');
  929. }
  930. return $html;
  931. }
  932. /**
  933. * @return null|string
  934. */
  935. public function return_course_block()
  936. {
  937. $html = '';
  938. $show_create_link = false;
  939. $show_course_link = false;
  940. if (api_is_allowed_to_create_course()) {
  941. $show_create_link = true;
  942. }
  943. if (api_get_setting('allow_students_to_browse_courses') === 'true') {
  944. $show_course_link = true;
  945. }
  946. // My account section
  947. $my_account_content = '<ul class="nav nav-pills nav-stacked">';
  948. if ($show_create_link) {
  949. $my_account_content .= '<li class="add-course"><a href="main/create_course/add_course.php">';
  950. if (api_get_setting('course_validation') == 'true' && !api_is_platform_admin()) {
  951. $my_account_content .= Display::return_icon('new-course.png',get_lang('CreateCourseRequest'),null,ICON_SIZE_SMALL);
  952. $my_account_content .= get_lang('CreateCourseRequest');
  953. } else {
  954. $my_account_content .= Display::return_icon('new-course.png',get_lang('CourseCreate'),null,ICON_SIZE_SMALL);
  955. $my_account_content .= get_lang('CourseCreate');
  956. }
  957. $my_account_content .= '</a></li>';
  958. if (SessionManager::allowToManageSessions()) {
  959. $my_account_content .= '<li class="add-course"><a href="main/session/session_add.php">';
  960. $my_account_content .= Display::return_icon('session.png',get_lang('AddSession'),null,ICON_SIZE_SMALL);
  961. $my_account_content .= get_lang('AddSession');
  962. $my_account_content .= '</a></li>';
  963. }
  964. }
  965. //Sort courses
  966. $url = api_get_path(WEB_CODE_PATH).'auth/courses.php?action=sortmycourses';
  967. $img_order= Display::return_icon('order-course.png',get_lang('SortMyCourses'),null,ICON_SIZE_SMALL);
  968. $my_account_content .= '<li class="order-course">'.Display::url($img_order.get_lang('SortMyCourses'), $url, array('class' => 'sort course')).'</li>';
  969. // Session history
  970. if (isset($_GET['history']) && intval($_GET['history']) == 1) {
  971. $my_account_content .= '<li class="history-course"><a href="user_portal.php">'.Display::return_icon('history-course.png',get_lang('DisplayTrainingList'),null,ICON_SIZE_SMALL).get_lang('DisplayTrainingList').'</a></li>';
  972. } else {
  973. $my_account_content .= '<li class="history-course"><a href="user_portal.php?history=1" >'.Display::return_icon('history-course.png',get_lang('HistoryTrainingSessions'),null,ICON_SIZE_SMALL).get_lang('HistoryTrainingSessions').'</a></li>';
  974. }
  975. // Course catalog
  976. if ($show_course_link) {
  977. if (!api_is_drh()) {
  978. $my_account_content .= '<li class="list-course"><a href="main/auth/courses.php" >'.Display::return_icon('catalog-course.png',get_lang('CourseCatalog'),null,ICON_SIZE_SMALL).get_lang('CourseCatalog').'</a></li>';
  979. } else {
  980. $my_account_content .= '<li><a href="main/dashboard/index.php">'.get_lang('Dashboard').'</a></li>';
  981. }
  982. }
  983. $my_account_content .= '</ul>';
  984. if (!empty($my_account_content)) {
  985. $html = self::show_right_block(
  986. get_lang('Courses'),
  987. $my_account_content,
  988. 'course_block',
  989. null,
  990. 'course',
  991. 'courseCollapse'
  992. );
  993. }
  994. return $html;
  995. }
  996. /**
  997. * Prints the session and course list (user_portal.php)
  998. * @param int $user_id
  999. * @return string
  1000. */
  1001. public function returnCoursesAndSessions($user_id)
  1002. {
  1003. $gamificationModeIsActive = api_get_setting('gamification_mode');
  1004. $listCourse = '';
  1005. $specialCourseList = '';
  1006. $load_history = isset($_GET['history']) && intval($_GET['history']) == 1 ? true : false;
  1007. $viewGridCourses = api_get_configuration_value('view_grid_courses');
  1008. $showSimpleSessionInfo = api_get_configuration_value('show_simple_session_info');
  1009. $coursesWithoutCategoryTemplate = '/user_portal/classic_courses_without_category.tpl';
  1010. $coursesWithCategoryTemplate = '/user_portal/classic_courses_with_category.tpl';
  1011. if ($load_history) {
  1012. // Load sessions in category in *history*
  1013. $session_categories = UserManager::get_sessions_by_category($user_id, true);
  1014. } else {
  1015. // Load sessions in category
  1016. $session_categories = UserManager::get_sessions_by_category($user_id, false);
  1017. }
  1018. $sessionCount = 0;
  1019. $courseCount = 0;
  1020. //$template = new Template(null, false, false, false, false, false, false);
  1021. // If we're not in the history view...
  1022. if (!isset($_GET['history'])) {
  1023. // Display special courses.
  1024. $specialCourses = CourseManager::returnSpecialCourses(
  1025. $user_id,
  1026. $this->load_directories_preview
  1027. );
  1028. // Display courses.
  1029. $courses = CourseManager::returnCourses(
  1030. $user_id,
  1031. $this->load_directories_preview
  1032. );
  1033. if ($viewGridCourses) {
  1034. $coursesWithoutCategoryTemplate = '/user_portal/grid_courses_without_category.tpl';
  1035. $coursesWithCategoryTemplate = '/user_portal/grid_courses_with_category.tpl';
  1036. }
  1037. if ($specialCourses) {
  1038. $this->tpl->assign('courses', $specialCourses);
  1039. $specialCourseList = $this->tpl->fetch(
  1040. $this->tpl->get_template($coursesWithoutCategoryTemplate)
  1041. );
  1042. }
  1043. if ($courses['in_category'] || $courses['not_category']) {
  1044. $this->tpl->assign('courses', $courses['not_category']);
  1045. $this->tpl->assign('categories', $courses['in_category']);
  1046. $listCourse = $this->tpl->fetch(
  1047. $this->tpl->get_template($coursesWithCategoryTemplate)
  1048. );
  1049. $listCourse .= $this->tpl->fetch(
  1050. $this->tpl->get_template($coursesWithoutCategoryTemplate)
  1051. );
  1052. }
  1053. $courseCount = count($specialCourses) + count($courses['in_category']) + count($courses['not_category']);
  1054. }
  1055. $sessions_with_category = '';
  1056. $coursesListSessionStyle = api_get_configuration_value('courses_list_session_title_link');
  1057. $coursesListSessionStyle = $coursesListSessionStyle === false ? 1 : $coursesListSessionStyle;
  1058. if (api_is_drh()) {
  1059. $coursesListSessionStyle = 1;
  1060. }
  1061. // Declared listSession variable
  1062. $listSession = [];
  1063. if (is_array($session_categories)) {
  1064. foreach ($session_categories as $session_category) {
  1065. $session_category_id = $session_category['session_category']['id'];
  1066. // Sessions and courses that are not in a session category
  1067. if (
  1068. empty($session_category_id) &&
  1069. isset($session_category['sessions'])
  1070. ) {
  1071. // Independent sessions
  1072. foreach ($session_category['sessions'] as $session) {
  1073. $session_id = $session['session_id'];
  1074. // Don't show empty sessions.
  1075. if (count($session['courses']) < 1) {
  1076. continue;
  1077. }
  1078. // Courses inside the current session.
  1079. $date_session_start = api_get_local_time($session['access_start_date']);
  1080. $date_session_end = api_get_local_time($session['access_end_date']);
  1081. $coachAccessStartDate = api_get_local_time($session['coach_access_start_date']);
  1082. $coachAccessEndDate = api_get_local_time($session['coach_access_end_date']);
  1083. $session_now = time();
  1084. $count_courses_session = 0;
  1085. // Loop course content
  1086. $html_courses_session = [];
  1087. $atLeastOneCourseIsVisible = false;
  1088. foreach ($session['courses'] as $course) {
  1089. $is_coach_course = api_is_coach($session_id, $course['real_id']);
  1090. $allowed_time = 0;
  1091. $allowedEndTime = true;
  1092. if (!empty($date_session_start)) {
  1093. if ($is_coach_course) {
  1094. $allowed_time = api_strtotime($coachAccessStartDate);
  1095. } else {
  1096. $allowed_time = api_strtotime($date_session_start);
  1097. }
  1098. if (!isset($_GET['history'])) {
  1099. if (!empty($date_session_end)) {
  1100. $endSessionToTms = api_strtotime($date_session_end);
  1101. if ($session_now > $endSessionToTms) {
  1102. $allowedEndTime = false;
  1103. }
  1104. }
  1105. }
  1106. }
  1107. if ($session_now >= $allowed_time && $allowedEndTime) {
  1108. // Read only and accessible.
  1109. $atLeastOneCourseIsVisible = true;
  1110. if (api_get_setting('hide_courses_in_sessions') == 'false') {
  1111. $courseUserHtml = CourseManager::get_logged_user_course_html(
  1112. $course,
  1113. $session_id,
  1114. 'session_course_item',
  1115. true,
  1116. $this->load_directories_preview
  1117. );
  1118. if (isset($courseUserHtml[1])) {
  1119. $course_session = $courseUserHtml[1];
  1120. $course_session['skill'] = isset($courseUserHtml['skill']) ? $courseUserHtml['skill'] : '';
  1121. $html_courses_session[] = $course_session;
  1122. }
  1123. }
  1124. $count_courses_session++;
  1125. }
  1126. }
  1127. // No courses to show.
  1128. if ($atLeastOneCourseIsVisible == false) {
  1129. if (empty($html_courses_session)) {
  1130. continue;
  1131. }
  1132. }
  1133. if ($count_courses_session > 0) {
  1134. $params = array(
  1135. 'id' => $session_id
  1136. );
  1137. $session_box = Display::get_session_title_box($session_id);
  1138. $actions = null;
  1139. if (api_is_platform_admin()) {
  1140. $actions = api_get_path(WEB_CODE_PATH) .'session/resume_session.php?id_session='.$session_id;
  1141. }
  1142. $coachId = $session_box['id_coach'];
  1143. $extraFieldValue = new ExtraFieldValue('session');
  1144. $imageField = $extraFieldValue->get_values_by_handler_and_field_variable($session_id, 'image');
  1145. $params['category_id'] = $session_box['category_id'];
  1146. $params['title'] = $session_box['title'];
  1147. $params['id_coach'] = $coachId;
  1148. $params['coach_url'] = api_get_path(WEB_AJAX_PATH) . 'user_manager.ajax.php?a=get_user_popup&user_id=' . $coachId;
  1149. $params['coach_name'] = !empty($session_box['coach']) ? $session_box['coach'] : null;
  1150. $params['coach_avatar'] = UserManager::getUserPicture($coachId, USER_IMAGE_SIZE_SMALL);
  1151. $params['date'] = $session_box['dates'];
  1152. $params['image'] = isset($imageField['value']) ? $imageField['value'] : null;
  1153. $params['duration'] = isset($session_box['duration']) ? ' ' . $session_box['duration'] : null;
  1154. $params['edit_actions'] = $actions;
  1155. $params['show_description'] = $session_box['show_description'];
  1156. $params['description'] = $session_box['description'];
  1157. $params['visibility'] = $session_box['visibility'];
  1158. $params['show_simple_session_info'] = false;
  1159. $params['course_list_session_style'] = $coursesListSessionStyle;
  1160. $params['num_users'] = $session_box['num_users'];
  1161. $params['num_courses'] = $session_box['num_courses'];
  1162. $params['courses'] = $html_courses_session;
  1163. if ($showSimpleSessionInfo) {
  1164. $params['show_simple_session_info'] = true;
  1165. }
  1166. if ($gamificationModeIsActive) {
  1167. $params['stars'] = GamificationUtils::getSessionStars($params['id'], $this->user_id);
  1168. $params['progress'] = GamificationUtils::getSessionProgress($params['id'], $this->user_id);
  1169. $params['points'] = GamificationUtils::getSessionPoints($params['id'], $this->user_id);
  1170. }
  1171. $listSession[] = $params;
  1172. $sessionCount++;
  1173. }
  1174. }
  1175. } else {
  1176. // All sessions included in
  1177. $count_courses_session = 0;
  1178. $html_sessions = '';
  1179. if (isset($session_category['sessions'])) {
  1180. foreach ($session_category['sessions'] as $session) {
  1181. $session_id = $session['session_id'];
  1182. // Don't show empty sessions.
  1183. if (count($session['courses']) < 1) {
  1184. continue;
  1185. }
  1186. $date_session_start = $session['access_start_date'];
  1187. $date_session_end = $session['access_end_date'];
  1188. $coachAccessStartDate = $session['coach_access_start_date'];
  1189. $coachAccessEndDate = $session['coach_access_end_date'];
  1190. $session_now = time();
  1191. $html_courses_session = [];
  1192. $count = 0;
  1193. foreach ($session['courses'] as $course) {
  1194. $is_coach_course = api_is_coach(
  1195. $session_id,
  1196. $course['real_id']
  1197. );
  1198. $allowed_time = 0;
  1199. $allowedEndTime = true;
  1200. if ($is_coach_course) {
  1201. if (!empty($date_session_start)) {
  1202. $allowed_time = api_strtotime($coachAccessStartDate);
  1203. }
  1204. if (!isset($_GET['history'])) {
  1205. if (!empty($date_session_end)) {
  1206. $endSessionToTms = api_strtotime($date_session_end);
  1207. if ($session_now > $endSessionToTms) {
  1208. $allowedEndTime = false;
  1209. }
  1210. }
  1211. }
  1212. } else {
  1213. $allowed_time = api_strtotime(
  1214. $date_session_start
  1215. );
  1216. }
  1217. if ($session_now >= $allowed_time && $allowedEndTime) {
  1218. if (api_get_setting('hide_courses_in_sessions') === 'false') {
  1219. $c = CourseManager::get_logged_user_course_html(
  1220. $course,
  1221. $session_id,
  1222. 'session_course_item'
  1223. );
  1224. $html_courses_session[] = $c[1];
  1225. }
  1226. $count_courses_session++;
  1227. $count++;
  1228. }
  1229. }
  1230. $sessionParams = [];
  1231. // Category
  1232. if ($count > 0) {
  1233. $session_box = Display::get_session_title_box($session_id);
  1234. $sessionParams[0]['id'] = $session_id;
  1235. $sessionParams[0]['date'] = $session_box['dates'];
  1236. $sessionParams[0]['course_list_session_style'] = $coursesListSessionStyle;
  1237. $sessionParams[0]['title'] = $session_box['title'];
  1238. $sessionParams[0]['subtitle'] = (!empty($session_box['coach']) ? $session_box['coach'] . ' | ': '') . $session_box['dates'];
  1239. $sessionParams[0]['show_actions'] = api_is_platform_admin();
  1240. $sessionParams[0]['courses'] = $html_courses_session;
  1241. $sessionParams[0]['show_simple_session_info'] = false;
  1242. if ($showSimpleSessionInfo) {
  1243. $sessionParams[0]['show_simple_session_info'] = true;
  1244. }
  1245. $this->tpl->assign('session', $sessionParams);
  1246. $html_sessions .= $this->tpl->fetch(
  1247. $this->tpl->get_template('user_portal/classic_session.tpl')
  1248. );
  1249. $sessionCount++;
  1250. }
  1251. }
  1252. }
  1253. if ($count_courses_session > 0) {
  1254. $categoryParams = array(
  1255. 'id' => $session_category['session_category']['id'],
  1256. 'title' => $session_category['session_category']['name'],
  1257. 'show_actions' => api_is_platform_admin(),
  1258. 'subtitle' => '',
  1259. 'sessions' => $html_sessions
  1260. );
  1261. $session_category_start_date = $session_category['session_category']['date_start'];
  1262. $session_category_end_date = $session_category['session_category']['date_end'];
  1263. if ($session_category_start_date == '0000-00-00') {
  1264. $session_category_start_date = '';
  1265. }
  1266. if ($session_category_end_date == '0000-00-00') {
  1267. $session_category_end_date = '';
  1268. }
  1269. if (
  1270. !empty($session_category_start_date) &&
  1271. !empty($session_category_end_date)
  1272. ) {
  1273. $categoryParams['subtitle'] = sprintf(
  1274. get_lang('FromDateXToDateY'),
  1275. $session_category_start_date,
  1276. $session_category_end_date
  1277. );
  1278. } else {
  1279. if (
  1280. !empty($session_category_start_date)
  1281. ) {
  1282. $categoryParams['subtitle'] = get_lang('From') . ' ' . $session_category_start_date;
  1283. }
  1284. if (
  1285. !empty($session_category_end_date)
  1286. ) {
  1287. $categoryParams['subtitle'] = get_lang('Until') . ' ' . $session_category_end_date;
  1288. }
  1289. }
  1290. $this->tpl->assign('session_category', $categoryParams);
  1291. $sessions_with_category .= $this->tpl->fetch(
  1292. "{$this->tpl->templateFolder}/user_portal/session_category.tpl"
  1293. );
  1294. }
  1295. }
  1296. }
  1297. $allCoursesInSessions = [];
  1298. foreach ($listSession as $currentSession) {
  1299. $coursesInSessions = $currentSession['courses'];
  1300. unset($currentSession['courses']);
  1301. foreach ($coursesInSessions as $coursesInSession) {
  1302. $coursesInSession['session'] = $currentSession;
  1303. $allCoursesInSessions[] = $coursesInSession;
  1304. }
  1305. }
  1306. $this->tpl->assign('all_courses', $allCoursesInSessions);
  1307. $this->tpl->assign('session', $listSession);
  1308. $this->tpl->assign('show_tutor', (api_get_setting('show_session_coach')==='true' ? true : false));
  1309. $this->tpl->assign('gamification_mode', $gamificationModeIsActive);
  1310. if (api_get_configuration_value('view_grid_courses')) {
  1311. $sessions_with_no_category = $this->tpl->fetch(
  1312. $this->tpl->get_template('/user_portal/grid_session.tpl')
  1313. );
  1314. } else {
  1315. $sessions_with_no_category = $this->tpl->fetch(
  1316. $this->tpl->get_template('user_portal/classic_session.tpl')
  1317. );
  1318. }
  1319. }
  1320. return [
  1321. 'html' => $specialCourseList . $sessions_with_category.$sessions_with_no_category.$listCourse,
  1322. 'session_count' => $sessionCount,
  1323. 'course_count' => $courseCount
  1324. ];
  1325. }
  1326. /**
  1327. * Shows a welcome message when the user doesn't have any content in the course list
  1328. */
  1329. public function return_welcome_to_course_block()
  1330. {
  1331. $count_courses = CourseManager::count_courses();
  1332. $tpl = $this->tpl->get_template('layout/welcome_to_course.tpl');
  1333. $course_catalog_url = api_get_path(WEB_CODE_PATH).'auth/courses.php';
  1334. $course_list_url = api_get_path(WEB_PATH).'user_portal.php';
  1335. $this->tpl->assign('course_catalog_url', $course_catalog_url);
  1336. $this->tpl->assign('course_list_url', $course_list_url);
  1337. $this->tpl->assign('course_catalog_link', Display::url(get_lang('Here'), $course_catalog_url));
  1338. $this->tpl->assign('course_list_link', Display::url(get_lang('Here'), $course_list_url));
  1339. $this->tpl->assign('count_courses', $count_courses);
  1340. return $this->tpl->fetch($tpl);
  1341. }
  1342. /**
  1343. * @return array
  1344. */
  1345. public function return_hot_courses()
  1346. {
  1347. return CourseManager::return_hot_courses(30, 6);
  1348. }
  1349. /**
  1350. * UserPortal view for session, return the HTML of the course list
  1351. * @param $user_id
  1352. * @return string
  1353. */
  1354. public function returnCoursesAndSessionsViewBySession($user_id)
  1355. {
  1356. $sessionCount = 0;
  1357. $courseCount = 0;
  1358. $load_history = (isset($_GET['history']) && intval($_GET['history']) == 1) ? true : false;
  1359. if ($load_history) {
  1360. //Load sessions in category in *history*
  1361. $session_categories = UserManager::get_sessions_by_category($user_id, true);
  1362. } else {
  1363. //Load sessions in category
  1364. $session_categories = UserManager::get_sessions_by_category($user_id, false);
  1365. }
  1366. $html = '';
  1367. $loadDirs = $this->load_directories_preview;
  1368. // If we're not in the history view...
  1369. $listCoursesInfo = array();
  1370. if (!isset($_GET['history'])) {
  1371. // Display special courses
  1372. $specialCoursesResult = CourseManager::returnSpecialCourses(
  1373. $user_id,
  1374. $loadDirs
  1375. );
  1376. $specialCourses = $specialCoursesResult;
  1377. if ($specialCourses) {
  1378. $this->tpl->assign('courses', $specialCourses);
  1379. $html = $this->tpl->fetch(
  1380. $this->tpl->get_template('/user_portal/classic_courses_without_category.tpl')
  1381. );
  1382. }
  1383. // Display courses
  1384. // [code=>xxx, real_id=>000]
  1385. $listCourses = CourseManager::get_courses_list_by_user_id($user_id, false);
  1386. foreach ($listCourses as $i => $listCourseCodeId) {
  1387. if (isset($listCourseCodeId['special_course'])) {
  1388. continue;
  1389. }
  1390. list($userCategoryId, $userCatTitle) = CourseManager::getUserCourseCategoryForCourse(
  1391. $user_id,
  1392. $listCourseCodeId['real_id']
  1393. );
  1394. $listCourse = api_get_course_info_by_id($listCourseCodeId['real_id']);
  1395. $listCoursesInfo[] = array(
  1396. 'course' => $listCourse,
  1397. 'code' => $listCourseCodeId['code'],
  1398. 'id' => $listCourseCodeId['real_id'],
  1399. 'title' => $listCourse['title'],
  1400. 'userCatId' => $userCategoryId,
  1401. 'userCatTitle' => $userCatTitle
  1402. );
  1403. $courseCount++;
  1404. }
  1405. usort($listCoursesInfo, 'self::compareByCourse');
  1406. }
  1407. if (is_array($session_categories)) {
  1408. // all courses that are in a session
  1409. $listCoursesInSession = SessionManager::getNamedSessionCourseForCoach($user_id);
  1410. }
  1411. // we got all courses
  1412. // for each user category, sorted alphabetically, display courses
  1413. $listUserCategories = CourseManager::get_user_course_categories($user_id);
  1414. $listCoursesAlreadyDisplayed = array();
  1415. uasort($listUserCategories, "self::compareListUserCategory");
  1416. $listUserCategories[0] = '';
  1417. $html .= '<div class="session-view-block">';
  1418. foreach ($listUserCategories as $userCategoryId => $userCatTitle) {
  1419. // add user category
  1420. $userCategoryHtml = '';
  1421. if ($userCategoryId != 0) {
  1422. $userCategoryHtml = '<div class="session-view-well ">';
  1423. }
  1424. $userCategoryHtml .= self::getHtmlForUserCategory($userCategoryId, $userCatTitle);
  1425. // look for course in this userCat in session courses : $listCoursesInSession
  1426. $htmlCategory = '';
  1427. if (isset($listCoursesInSession[$userCategoryId])) {
  1428. // list of courses in this user cat
  1429. foreach ($listCoursesInSession[$userCategoryId]['courseInUserCatList'] as $i => $listCourse) {
  1430. // add course
  1431. $listCoursesAlreadyDisplayed[$listCourse['courseId']] = 1;
  1432. if ($userCategoryId == 0) {
  1433. $htmlCategory .= '<div class="panel panel-default">';
  1434. } else {
  1435. $htmlCategory .= '<div class="panel panel-default">';
  1436. }
  1437. $htmlCategory .= '<div class="panel-body">';
  1438. $coursesInfo = $listCourse['course'];
  1439. $htmlCategory .= self::getHtmlForCourse(
  1440. $coursesInfo,
  1441. $userCategoryId,
  1442. 1,
  1443. $loadDirs
  1444. );
  1445. // list of session category
  1446. $htmlSessionCategory = '<div class="session-view-row" style="display:none;" id="courseblock-'.$coursesInfo['real_id'].'">';
  1447. foreach ($listCourse['sessionCatList'] as $j => $listCategorySession) {
  1448. // add session category
  1449. $htmlSessionCategory .= self::getHtmlSessionCategory(
  1450. $listCategorySession['catSessionId'],
  1451. $listCategorySession['catSessionName']
  1452. );
  1453. // list of session
  1454. $htmlSession = ''; // start
  1455. foreach ($listCategorySession['sessionList'] as $k => $listSession) {
  1456. // add session
  1457. $htmlSession .= '<div class="session-view-row">';
  1458. $htmlSession .= self::getHtmlForSession(
  1459. $listSession['sessionId'],
  1460. $listSession['sessionName'],
  1461. $listCategorySession['catSessionId'],
  1462. $coursesInfo
  1463. );
  1464. $htmlSession .= '</div>';
  1465. $sessionCount++;
  1466. }
  1467. $htmlSession .= ''; // end session block
  1468. $htmlSessionCategory .= $htmlSession;
  1469. }
  1470. $htmlSessionCategory .= '</div>'; // end session cat block
  1471. $htmlCategory .= $htmlSessionCategory .'</div></div>' ;
  1472. $htmlCategory .= ''; // end course block
  1473. }
  1474. $userCategoryHtml .= $htmlCategory;
  1475. }
  1476. // look for courses in this userCat in not in session courses : $listCoursesInfo
  1477. // if course not already added
  1478. $htmlCategory = '';
  1479. foreach ($listCoursesInfo as $i => $listCourse) {
  1480. if ($listCourse['userCatId'] == $userCategoryId && !isset($listCoursesAlreadyDisplayed[$listCourse['id']])) {
  1481. if ($userCategoryId != 0) {
  1482. $htmlCategory .= '<div class="panel panel-default">';
  1483. } else {
  1484. $htmlCategory .= '<div class="panel panel-default">';
  1485. }
  1486. $htmlCategory .= '<div class="panel-body">';
  1487. $htmlCategory .= self::getHtmlForCourse(
  1488. $listCourse['course'],
  1489. $userCategoryId,
  1490. 0,
  1491. $loadDirs
  1492. );
  1493. $htmlCategory .= '</div></div>';
  1494. }
  1495. }
  1496. $htmlCategory .= '';
  1497. $userCategoryHtml .= $htmlCategory; // end user cat block
  1498. if ($userCategoryId != 0) {
  1499. $userCategoryHtml .= '</div>';
  1500. }
  1501. $html .= $userCategoryHtml; //
  1502. }
  1503. $html .= '</div>';
  1504. return [
  1505. 'html' => $html,
  1506. 'session_count' => $sessionCount,
  1507. 'course_count' => $courseCount
  1508. ];
  1509. }
  1510. /**
  1511. * Return HTML code for personal user course category
  1512. * @param $id
  1513. * @param $title
  1514. * @return string
  1515. */
  1516. private static function getHtmlForUserCategory($id, $title)
  1517. {
  1518. if ($id == 0) {
  1519. return '';
  1520. }
  1521. $icon = Display::return_icon(
  1522. 'folder_yellow.png',
  1523. $title,
  1524. array('class' => 'sessionView'),
  1525. ICON_SIZE_LARGE
  1526. );
  1527. return "<div class='session-view-user-category'>$icon<span>$title</span></div>";
  1528. }
  1529. /**
  1530. * return HTML code for course display in session view
  1531. * @param array $courseInfo
  1532. * @param $userCategoryId
  1533. * @param bool $displayButton
  1534. * @param $loadDirs
  1535. * @return string
  1536. */
  1537. private static function getHtmlForCourse(
  1538. $courseInfo,
  1539. $userCategoryId,
  1540. $displayButton = false,
  1541. $loadDirs
  1542. ) {
  1543. if (empty($courseInfo)) {
  1544. return '';
  1545. }
  1546. $id = $courseInfo['real_id'];
  1547. $title = $courseInfo['title'];
  1548. $code = $courseInfo['code'];
  1549. $class = 'session-view-lvl-6';
  1550. if ($userCategoryId != 0 && !$displayButton) {
  1551. $class = 'session-view-lvl-7';
  1552. }
  1553. $class2 = 'session-view-lvl-6';
  1554. if ($displayButton || $userCategoryId != 0) {
  1555. $class2 = 'session-view-lvl-7';
  1556. }
  1557. $button = '';
  1558. if ($displayButton) {
  1559. $button = '<input id="session-view-button-'.intval($id).'" class="btn btn-default btn-sm" type="button" onclick="hideUnhide(\'courseblock-'.intval($id).'\', \'session-view-button-'.intval($id).'\', \'+\', \'-\')" value="+" />';
  1560. }
  1561. $icon = Display::return_icon(
  1562. 'blackboard.png',
  1563. $title,
  1564. array('class' => 'sessionView'),
  1565. ICON_SIZE_LARGE
  1566. );
  1567. $courseLink = $courseInfo['course_public_url'].'?id_session=0';
  1568. // get html course params
  1569. // ['right_actions'] ['teachers'] ['notifications']
  1570. $tabParams = CourseManager::getCourseParamsForDisplay($id, $loadDirs);
  1571. // teacher list
  1572. if (!empty($tabParams['teachers'])) {
  1573. $teachers = '<p class="'.$class2.' view-by-session-teachers">'.$tabParams['teachers'].'</p>';
  1574. }
  1575. // notification
  1576. if (!empty($tabParams['right_actions'])) {
  1577. $rightActions = '<div class="pull-right">'.$tabParams['right_actions'].'</div>';
  1578. }
  1579. return "<div>
  1580. $button
  1581. <span class='$class'>$icon
  1582. <a class='sessionView' href='$courseLink'>$title</a>
  1583. </span>".$tabParams['notifications']."$rightActions
  1584. </div>
  1585. $teachers";
  1586. }
  1587. /**
  1588. * return HTML code for session category
  1589. * @param $id
  1590. * @param $title
  1591. * @return string
  1592. */
  1593. private static function getHtmlSessionCategory($id, $title)
  1594. {
  1595. if ($id == 0) {
  1596. return '';
  1597. }
  1598. $icon = Display::return_icon(
  1599. 'folder_blue.png',
  1600. $title,
  1601. array('class' => 'sessionView'),
  1602. ICON_SIZE_LARGE
  1603. );
  1604. return "<div class='session-view-session-category'>
  1605. <span class='session-view-lvl-2'>
  1606. $icon
  1607. <span>$title</span>
  1608. </span>
  1609. </div>";
  1610. }
  1611. /**
  1612. * return HTML code for session
  1613. * @param int $id session id
  1614. * @param string $title session title
  1615. * @param int $categorySessionId
  1616. * @param array $courseInfo
  1617. *
  1618. * @return string
  1619. */
  1620. private static function getHtmlForSession($id, $title, $categorySessionId, $courseInfo)
  1621. {
  1622. $html = '';
  1623. if ($categorySessionId == 0) {
  1624. $class1 = 'session-view-lvl-2'; // session
  1625. $class2 = 'session-view-lvl-4'; // got to course in session link
  1626. } else {
  1627. $class1 = 'session-view-lvl-3'; // session
  1628. $class2 = 'session-view-lvl-5'; // got to course in session link
  1629. }
  1630. $icon = Display::return_icon(
  1631. 'blackboard_blue.png',
  1632. $title,
  1633. array('class' => 'sessionView'),
  1634. ICON_SIZE_LARGE
  1635. );
  1636. $courseLink = $courseInfo['course_public_url'].'?id_session='.intval($id);
  1637. $html .= "<span class='$class1 session-view-session'>$icon$title</span>";
  1638. $html .= '<div class="'.$class2.' session-view-session-go-to-course-in-session">
  1639. <a class="" href="'.$courseLink.'">'.get_lang('GoToCourseInsideSession').'</a></div>';
  1640. return '<div>'.$html.'</div>';
  1641. }
  1642. /**
  1643. * @param $listA
  1644. * @param $listB
  1645. * @return int
  1646. */
  1647. private static function compareByCourse($listA, $listB)
  1648. {
  1649. if ($listA['userCatTitle'] == $listB['userCatTitle']) {
  1650. if ($listA['title'] == $listB['title']) {
  1651. return 0;
  1652. } else if($listA['title'] > $listB['title']) {
  1653. return 1;
  1654. } else {
  1655. return -1;
  1656. }
  1657. } else if ($listA['userCatTitle'] > $listB['userCatTitle']) {
  1658. return 1;
  1659. } else {
  1660. return -1;
  1661. }
  1662. }
  1663. /**
  1664. * @param $listA
  1665. * @param $listB
  1666. * @return int
  1667. */
  1668. public static function compareListUserCategory($listA, $listB)
  1669. {
  1670. if ($listA['title'] == $listB['title']) {
  1671. return 0;
  1672. } else if($listA['title'] > $listB['title']) {
  1673. return 1;
  1674. } else {
  1675. return -1;
  1676. }
  1677. }
  1678. /**
  1679. * @param $view
  1680. * @param $userId
  1681. */
  1682. public static function setDefaultMyCourseView($view, $userId)
  1683. {
  1684. setcookie('defaultMyCourseView'.$userId, $view);
  1685. }
  1686. }