userportal.lib.php 100 KB

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