userportal.lib.php 100 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300
  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(
  81. 'exercise_end_date',
  82. api_convert_and_format_date($my_exercise['end_time'], DATE_FORMAT_SHORT)
  83. );
  84. }
  85. }
  86. }
  87. /**
  88. * @param bool $show_slide
  89. * @return null|string
  90. */
  91. public function return_announcements($show_slide = true)
  92. {
  93. $hideAnnouncements = api_get_setting('hide_global_announcements_when_not_connected');
  94. $currentUserId = api_get_user_id();
  95. if ($hideAnnouncements == 'true' && empty($currentUserId)) {
  96. return null;
  97. }
  98. $announcement = isset($_GET['announcement']) ? $_GET['announcement'] : null;
  99. $announcement = intval($announcement);
  100. if (!api_is_anonymous() && $this->user_id) {
  101. $visibility = SystemAnnouncementManager::getCurrentUserVisibility();
  102. if ($show_slide) {
  103. $announcements = SystemAnnouncementManager::displayAnnouncementsSlider(
  104. $visibility,
  105. $announcement
  106. );
  107. } else {
  108. $announcements = SystemAnnouncementManager::displayAllAnnouncements(
  109. $visibility,
  110. $announcement
  111. );
  112. }
  113. } else {
  114. if ($show_slide) {
  115. $announcements = SystemAnnouncementManager::displayAnnouncementsSlider(
  116. SystemAnnouncementManager::VISIBLE_GUEST,
  117. $announcement
  118. );
  119. } else {
  120. $announcements = SystemAnnouncementManager::displayAllAnnouncements(
  121. SystemAnnouncementManager::VISIBLE_GUEST,
  122. $announcement
  123. );
  124. }
  125. }
  126. return $announcements;
  127. }
  128. /**
  129. * Alias for the online_logout() function
  130. * @param bool $redirect Whether to ask online_logout to redirect to index.php or not
  131. * @param array $logoutInfo Information stored by local.inc.php before new context ['uid'=> x, 'cid'=>y, 'sid'=>z]
  132. */
  133. public function logout($redirect = true, $logoutInfo = [])
  134. {
  135. online_logout($this->user_id, true);
  136. courseLogout($logoutInfo);
  137. }
  138. /**
  139. * This function checks if there are courses that are open to the world in the platform course categories (=faculties)
  140. *
  141. * @param string $category
  142. * @return boolean
  143. */
  144. public function category_has_open_courses($category)
  145. {
  146. $setting_show_also_closed_courses = api_get_setting('show_closed_courses') == 'true';
  147. $main_course_table = Database::get_main_table(TABLE_MAIN_COURSE);
  148. $category = Database::escape_string($category);
  149. $sql_query = "SELECT * FROM $main_course_table WHERE category_code='$category'";
  150. $sql_result = Database::query($sql_query);
  151. while ($course = Database::fetch_array($sql_result)) {
  152. if (!$setting_show_also_closed_courses) {
  153. if ((api_get_user_id() > 0 && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM) || ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD)) {
  154. return true; //at least one open course
  155. }
  156. } else {
  157. if (isset($course['visibility'])) {
  158. return true; // At least one course (it does not matter weither it's open or not because $setting_show_also_closed_courses = true).
  159. }
  160. }
  161. }
  162. return false;
  163. }
  164. /**
  165. * @return null|string
  166. */
  167. public function return_teacher_link()
  168. {
  169. $html = '';
  170. $show_menu = false;
  171. if (!empty($this->user_id)) {
  172. // tabs that are deactivated are added here
  173. $show_menu = false;
  174. $show_create_link = false;
  175. $show_course_link = false;
  176. if (api_is_allowed_to_create_course()) {
  177. $show_menu = true;
  178. $show_course_link = true;
  179. $show_create_link = true;
  180. } else {
  181. if (api_get_setting('allow_students_to_browse_courses') === 'true') {
  182. $show_menu = true;
  183. $show_course_link = true;
  184. }
  185. if (api_is_allowed_to_create_course()) {
  186. $show_create_link = true;
  187. }
  188. }
  189. if ($show_menu && ($show_create_link || $show_course_link)) {
  190. $show_menu = true;
  191. } else {
  192. $show_menu = false;
  193. }
  194. }
  195. // My Account section
  196. if ($show_menu) {
  197. $html .= '<ul class="nav nav-pills nav-stacked">';
  198. if ($show_create_link) {
  199. $html .= '<li class="add-course"><a href="'.api_get_path(WEB_CODE_PATH).'create_course/add_course.php">'
  200. .Display::return_icon('new-course.png', get_lang('CourseCreate'))
  201. .(api_get_setting('course_validation') == 'true' ? get_lang('CreateCourseRequest') : get_lang('CourseCreate'))
  202. .'</a></li>';
  203. }
  204. if ($show_course_link) {
  205. if (!api_is_drh() && !api_is_session_admin()) {
  206. $html .= '<li class="list-course"><a href="'.api_get_path(WEB_CODE_PATH).'auth/courses.php">'
  207. .Display::return_icon('catalog-course.png', get_lang('CourseCatalog'))
  208. .get_lang('CourseCatalog')
  209. .'</a></li>';
  210. } else {
  211. $html .= '<li><a href="'.api_get_path(WEB_CODE_PATH).'dashboard/index.php">'.get_lang('Dashboard').'</a></li>';
  212. }
  213. }
  214. $html .= '</ul>';
  215. }
  216. if (!empty($html)) {
  217. $html = self::show_right_block(
  218. get_lang('Courses'),
  219. $html,
  220. 'teacher_block',
  221. null,
  222. 'teachers',
  223. 'teachersCollapse'
  224. );
  225. }
  226. return $html;
  227. }
  228. /**
  229. * Includes a created page
  230. * @return string
  231. */
  232. public function return_home_page()
  233. {
  234. $userId = api_get_user_id();
  235. // Including the page for the news
  236. $html = '';
  237. if (!empty($_GET['include']) && preg_match('/^[a-zA-Z0-9_-]*\.html$/', $_GET['include'])) {
  238. $open = @(string) file_get_contents($this->home.$_GET['include']);
  239. $html = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
  240. } else {
  241. // Hiding home top when user not connected.
  242. $hideTop = api_get_setting('hide_home_top_when_connected');
  243. if ($hideTop == 'true' && !empty($userId)) {
  244. return $html;
  245. }
  246. if (!empty($_SESSION['user_language_choice'])) {
  247. $user_selected_language = $_SESSION['user_language_choice'];
  248. } elseif (!empty($_SESSION['_user']['language'])) {
  249. $user_selected_language = $_SESSION['_user']['language'];
  250. } else {
  251. $user_selected_language = api_get_setting('platformLanguage');
  252. }
  253. $home_top_temp = '';
  254. // Try language specific home
  255. if (file_exists($this->home.'home_top_'.$user_selected_language.'.html')) {
  256. $home_top_temp = file_get_contents($this->home.'home_top_'.$user_selected_language.'.html');
  257. }
  258. // Try default language home
  259. if (empty($home_top_temp)) {
  260. if (file_exists($this->home.'home_top.html')) {
  261. $home_top_temp = file_get_contents($this->home.'home_top.html');
  262. } else {
  263. if (file_exists($this->default_home.'home_top.html')) {
  264. $home_top_temp = file_get_contents($this->default_home.'home_top.html');
  265. }
  266. }
  267. }
  268. if (trim($home_top_temp) == '' && api_is_platform_admin()) {
  269. $home_top_temp = '<div class="welcome-mascot">'.get_lang('PortalHomepageDefaultIntroduction').'</div>';
  270. } else {
  271. $home_top_temp = '<div class="welcome-home-top-temp">'.$home_top_temp.'</div>';
  272. }
  273. $open = str_replace('{rel_path}', api_get_path(REL_PATH), $home_top_temp);
  274. $html = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
  275. }
  276. return $html;
  277. }
  278. /**
  279. * @return string
  280. */
  281. public function return_notice()
  282. {
  283. $user_selected_language = api_get_interface_language();
  284. $html = '';
  285. // Notice
  286. $home_notice = @(string) file_get_contents($this->home.'home_notice_'.$user_selected_language.'.html');
  287. if (empty($home_notice)) {
  288. $home_notice = @(string) file_get_contents($this->home.'home_notice.html');
  289. }
  290. if (!empty($home_notice)) {
  291. $home_notice = api_to_system_encoding($home_notice, api_detect_encoding(strip_tags($home_notice)));
  292. $html = self::show_right_block(
  293. get_lang('Notice'),
  294. $home_notice,
  295. 'notice_block',
  296. null,
  297. 'notices',
  298. 'noticesCollapse'
  299. );
  300. }
  301. return $html;
  302. }
  303. /**
  304. * @return string
  305. */
  306. public function return_help()
  307. {
  308. $user_selected_language = api_get_interface_language();
  309. $platformLanguage = api_get_setting('platformLanguage');
  310. // Help section.
  311. /* Hide right menu "general" and other parts on anonymous right menu. */
  312. if (!isset($user_selected_language)) {
  313. $user_selected_language = $platformLanguage;
  314. }
  315. $html = '';
  316. $home_menu = @(string) file_get_contents($this->home.'home_menu_'.$user_selected_language.'.html');
  317. if (!empty($home_menu)) {
  318. $home_menu_content = '<ul class="nav nav-pills nav-stacked">';
  319. $home_menu_content .= api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
  320. $home_menu_content .= '</ul>';
  321. $html .= self::show_right_block(
  322. get_lang('MenuGeneral'),
  323. $home_menu_content,
  324. 'help_block',
  325. null,
  326. 'helps',
  327. 'helpsCollapse'
  328. );
  329. }
  330. return $html;
  331. }
  332. /**
  333. * Generate the block for show a panel with links to My Certificates and Certificates Search pages
  334. * @return array The HTML code for the panel
  335. */
  336. public function returnSkillLinks()
  337. {
  338. $items = [];
  339. if (!api_is_anonymous() &&
  340. api_get_configuration_value('hide_my_certificate_link') === false
  341. ) {
  342. $items[] = [
  343. 'icon' => Display::return_icon('graduation.png', get_lang('MyCertificates')),
  344. 'link' => api_get_path(WEB_CODE_PATH).'gradebook/my_certificates.php',
  345. 'title' => get_lang('MyCertificates')
  346. ];
  347. }
  348. if (api_get_setting('allow_public_certificates') == 'true') {
  349. $items[] = [
  350. 'icon' => Display::return_icon('search_graduation.png', get_lang('Search')),
  351. 'link' => api_get_path(WEB_CODE_PATH).'gradebook/search.php',
  352. 'title' => get_lang('Search')
  353. ];
  354. }
  355. if (Skill::isAllow(0, false)) {
  356. $items[] = [
  357. 'icon' => Display::return_icon('skill-badges.png', get_lang('MySkills')),
  358. 'link' => api_get_path(WEB_CODE_PATH).'social/my_skills_report.php',
  359. 'title' => get_lang('MySkills')
  360. ];
  361. $allowSkillsManagement = api_get_setting('allow_hr_skills_management') == 'true';
  362. if (($allowSkillsManagement && api_is_drh()) || api_is_platform_admin()) {
  363. $items[] = [
  364. 'icon' => Display::return_icon('edit-skill.png', get_lang('MySkills')),
  365. 'link' => api_get_path(WEB_CODE_PATH).'admin/skills_wheel.php',
  366. 'title' => get_lang('ManageSkills')
  367. ];
  368. }
  369. }
  370. return $items;
  371. }
  372. /**
  373. * Reacts on a failed login:
  374. * Displays an explanation with a link to the registration form.
  375. *
  376. * @version 1.0.1
  377. */
  378. public function handle_login_failed()
  379. {
  380. return $this->tpl->handleLoginFailed();
  381. }
  382. /**
  383. * Display list of courses in a category.
  384. * (for anonymous users)
  385. *
  386. * @version 1.1
  387. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University - refactoring and code cleaning
  388. * @author Julio Montoya <gugli100@gmail.com>, Beeznest template modifs
  389. */
  390. public function return_courses_in_categories()
  391. {
  392. $result = '';
  393. $stok = Security::get_token();
  394. // Initialization.
  395. $user_identified = (api_get_user_id() > 0 && !api_is_anonymous());
  396. $web_course_path = api_get_path(WEB_COURSE_PATH);
  397. $category = isset($_GET['category']) ? Database::escape_string($_GET['category']) : '';
  398. $setting_show_also_closed_courses = api_get_setting('show_closed_courses') == 'true';
  399. // Database table definitions.
  400. $main_course_table = Database::get_main_table(TABLE_MAIN_COURSE);
  401. $main_category_table = Database::get_main_table(TABLE_MAIN_CATEGORY);
  402. // Get list of courses in category $category.
  403. $sql = "SELECT * FROM $main_course_table cours
  404. WHERE category_code = '".$category."'
  405. ORDER BY title, UPPER(visual_code)";
  406. // Showing only the courses of the current access_url_id.
  407. if (api_is_multiple_url_enabled()) {
  408. $url_access_id = api_get_current_access_url_id();
  409. if ($url_access_id != -1) {
  410. $tbl_url_rel_course = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
  411. $sql = "SELECT * FROM $main_course_table as course
  412. INNER JOIN $tbl_url_rel_course as url_rel_course
  413. ON (url_rel_course.c_id = course.id)
  414. WHERE
  415. access_url_id = $url_access_id AND
  416. category_code = '".$category."'
  417. ORDER BY title, UPPER(visual_code)";
  418. }
  419. }
  420. // Removed: AND cours.visibility='".COURSE_VISIBILITY_OPEN_WORLD."'
  421. $queryResult = Database::query($sql);
  422. while ($course_result = Database::fetch_array($queryResult)) {
  423. $course_list[] = $course_result;
  424. }
  425. $numRows = Database::num_rows($queryResult);
  426. // $setting_show_also_closed_courses
  427. if ($user_identified) {
  428. if ($setting_show_also_closed_courses) {
  429. $platform_visible_courses = '';
  430. } else {
  431. $platform_visible_courses = " AND (t3.visibility='".COURSE_VISIBILITY_OPEN_WORLD."' OR t3.visibility='".COURSE_VISIBILITY_OPEN_PLATFORM."' )";
  432. }
  433. } else {
  434. if ($setting_show_also_closed_courses) {
  435. $platform_visible_courses = '';
  436. } else {
  437. $platform_visible_courses = " AND (t3.visibility='".COURSE_VISIBILITY_OPEN_WORLD."' )";
  438. }
  439. }
  440. $sqlGetSubCatList = "
  441. SELECT t1.name,
  442. t1.code,
  443. t1.parent_id,
  444. t1.children_count,COUNT(DISTINCT t3.code) AS nbCourse
  445. FROM $main_category_table t1
  446. LEFT JOIN $main_category_table t2
  447. ON t1.code=t2.parent_id
  448. LEFT JOIN $main_course_table t3
  449. ON (t3.category_code = t1.code $platform_visible_courses)
  450. WHERE t1.parent_id ".(empty($category) ? "IS NULL" : "='$category'")."
  451. GROUP BY t1.name,t1.code,t1.parent_id,t1.children_count
  452. ORDER BY t1.tree_pos, t1.name";
  453. // Showing only the category of courses of the current access_url_id
  454. if (api_is_multiple_url_enabled()) {
  455. $table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE_CATEGORY);
  456. $courseCategoryCondition = " INNER JOIN $table a ON (t1.id = a.course_category_id)";
  457. $url_access_id = api_get_current_access_url_id();
  458. if ($url_access_id != -1) {
  459. $tbl_url_rel_course = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
  460. $sqlGetSubCatList = "
  461. SELECT t1.name,
  462. t1.code,
  463. t1.parent_id,
  464. t1.children_count,
  465. COUNT(DISTINCT t3.code) AS nbCourse
  466. FROM $main_category_table t1
  467. $courseCategoryCondition
  468. LEFT JOIN $main_category_table t2 ON t1.code = t2.parent_id
  469. LEFT JOIN $main_course_table t3 ON (t3.category_code = t1.code $platform_visible_courses)
  470. INNER JOIN $tbl_url_rel_course as url_rel_course
  471. ON (url_rel_course.c_id = t3.id)
  472. WHERE
  473. url_rel_course.access_url_id = $url_access_id AND
  474. t1.parent_id ".(empty($category) ? "IS NULL" : "='$category'")."
  475. GROUP BY t1.name,t1.code,t1.parent_id,t1.children_count
  476. ORDER BY t1.tree_pos, t1.name";
  477. }
  478. }
  479. $resCats = Database::query($sqlGetSubCatList);
  480. $thereIsSubCat = false;
  481. if (Database::num_rows($resCats) > 0) {
  482. $htmlListCat = Display::page_header(get_lang('CatList'));
  483. $htmlListCat .= '<ul>';
  484. $htmlTitre = '';
  485. while ($catLine = Database::fetch_array($resCats)) {
  486. $category_has_open_courses = self::category_has_open_courses($catLine['code']);
  487. if ($category_has_open_courses) {
  488. // The category contains courses accessible to anonymous visitors.
  489. $htmlListCat .= '<li>';
  490. $htmlListCat .= '<a href="'.api_get_self().'?category='.$catLine['code'].'">'.$catLine['name'].'</a>';
  491. if (api_get_setting('show_number_of_courses') == 'true') {
  492. $htmlListCat .= ' ('.$catLine['nbCourse'].' '.get_lang('Courses').')';
  493. }
  494. $htmlListCat .= "</li>";
  495. $thereIsSubCat = true;
  496. } elseif ($catLine['children_count'] > 0) {
  497. // The category has children, subcategories.
  498. $htmlListCat .= '<li>';
  499. $htmlListCat .= '<a href="'.api_get_self().'?category='.$catLine['code'].'">'.$catLine['name'].'</a>';
  500. $htmlListCat .= "</li>";
  501. $thereIsSubCat = true;
  502. } elseif (api_get_setting('show_empty_course_categories') == 'true') {
  503. /* End changed code to eliminate the (0 courses) after empty categories. */
  504. $htmlListCat .= '<li>';
  505. $htmlListCat .= $catLine['name'];
  506. $htmlListCat .= "</li>";
  507. $thereIsSubCat = true;
  508. } // Else don't set thereIsSubCat to true to avoid printing things if not requested.
  509. // TODO: deprecate this useless feature - this includes removing system variable
  510. if (empty($htmlTitre)) {
  511. $htmlTitre = '<p>';
  512. if (api_get_setting('show_back_link_on_top_of_tree') == 'true') {
  513. $htmlTitre .= '<a href="'.api_get_self().'">&lt;&lt; '.get_lang('BackToHomePage').'</a>';
  514. }
  515. $htmlTitre .= "</p>";
  516. }
  517. }
  518. $htmlListCat .= "</ul>";
  519. }
  520. $result .= $htmlTitre;
  521. if ($thereIsSubCat) {
  522. $result .= $htmlListCat;
  523. }
  524. while ($categoryName = Database::fetch_array($resCats)) {
  525. $result .= '<h3>'.$categoryName['name']."</h3>\n";
  526. }
  527. $courses_list_string = '';
  528. $courses_shown = 0;
  529. if ($numRows > 0) {
  530. $courses_list_string .= Display::page_header(get_lang('CourseList'));
  531. $courses_list_string .= "<ul>";
  532. if (api_get_user_id()) {
  533. $courses_of_user = self::get_courses_of_user(api_get_user_id());
  534. }
  535. foreach ($course_list as $course) {
  536. // $setting_show_also_closed_courses
  537. if ($course['visibility'] == COURSE_VISIBILITY_HIDDEN) {
  538. continue;
  539. }
  540. if (!$setting_show_also_closed_courses) {
  541. // If we do not show the closed courses
  542. // we only show the courses that are open to the world (to everybody)
  543. // and the courses that are open to the platform (if the current user is a registered user.
  544. if (($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM) || ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD)) {
  545. $courses_shown++;
  546. $courses_list_string .= "<li>";
  547. $courses_list_string .= '<a href="'.$web_course_path.$course['directory'].'/">'.$course['title'].'</a><br />';
  548. $course_details = array();
  549. if (api_get_setting('display_coursecode_in_courselist') === 'true') {
  550. $course_details[] = $course['visual_code'];
  551. }
  552. if (api_get_setting('display_teacher_in_courselist') === 'true') {
  553. $course_details[] = CourseManager::get_teacher_list_from_course_code_to_string($course['code']);
  554. }
  555. if (api_get_setting('show_different_course_language') === 'true' && $course['course_language'] != api_get_setting('platformLanguage')) {
  556. $course_details[] = $course['course_language'];
  557. }
  558. $courses_list_string .= implode(' - ', $course_details);
  559. $courses_list_string .= "</li>";
  560. }
  561. } else {
  562. // We DO show the closed courses.
  563. // The course is accessible if (link to the course homepage):
  564. // 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);
  565. // 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);
  566. // 3. the user is logged in and the user is subscribed to the course and the course visibility is not COURSE_VISIBILITY_CLOSED;
  567. // 4. the user is logged in and the user is course admin of te course (regardless of the course visibility setting);
  568. // 5. the user is the platform admin api_is_platform_admin().
  569. $courses_shown++;
  570. $courses_list_string .= "<li>";
  571. if ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD
  572. || ($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM)
  573. || ($user_identified && array_key_exists($course['code'], $courses_of_user)
  574. && $course['visibility'] != COURSE_VISIBILITY_CLOSED)
  575. || $courses_of_user[$course['code']]['status'] == '1'
  576. || api_is_platform_admin()
  577. ) {
  578. $courses_list_string .= '<a href="'.$web_course_path.$course['directory'].'/">';
  579. }
  580. $courses_list_string .= $course['title'];
  581. if ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD
  582. || ($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM)
  583. || ($user_identified && array_key_exists($course['code'], $courses_of_user)
  584. && $course['visibility'] != COURSE_VISIBILITY_CLOSED)
  585. || $courses_of_user[$course['code']]['status'] == '1'
  586. || api_is_platform_admin()
  587. ) {
  588. $courses_list_string .= '</a><br />';
  589. }
  590. $course_details = array();
  591. if (api_get_setting('display_coursecode_in_courselist') == 'true') {
  592. $course_details[] = $course['visual_code'];
  593. }
  594. if (api_get_setting('display_teacher_in_courselist') === 'true') {
  595. if (!empty($course['tutor_name'])) {
  596. $course_details[] = $course['tutor_name'];
  597. }
  598. }
  599. if (api_get_setting('show_different_course_language') == 'true' && $course['course_language'] != api_get_setting('platformLanguage')) {
  600. $course_details[] = $course['course_language'];
  601. }
  602. $courses_list_string .= implode(' - ', $course_details);
  603. // We display a subscription link if:
  604. // 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
  605. // 2.
  606. if ($user_identified && !array_key_exists($course['code'], $courses_of_user)) {
  607. if ($course['subscribe'] == '1') {
  608. $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 />';
  609. } else {
  610. $courses_list_string .= '<br />'.get_lang('SubscribingNotAllowed');
  611. }
  612. }
  613. $courses_list_string .= "</li>";
  614. } //end else
  615. } // end foreach
  616. $courses_list_string .= "</ul>";
  617. }
  618. if ($courses_shown > 0) {
  619. // Only display the list of courses and categories if there was more than
  620. // 0 courses visible to the world (we're in the anonymous list here).
  621. $result .= $courses_list_string;
  622. }
  623. if ($category != '') {
  624. $result .= '<p><a href="'.api_get_self().'">'
  625. .Display:: return_icon('back.png', get_lang('BackToHomePage'))
  626. .get_lang('BackToHomePage').'</a></p>';
  627. }
  628. return $result;
  629. }
  630. /**
  631. * retrieves all the courses that the user has already subscribed to
  632. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  633. * @param int $user_id : the id of the user
  634. * @return array an array containing all the information of the courses of the given user
  635. */
  636. public function get_courses_of_user($user_id)
  637. {
  638. $table_course = Database::get_main_table(TABLE_MAIN_COURSE);
  639. $table_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  640. // Secondly we select the courses that are in a category (user_course_cat <> 0)
  641. // and sort these according to the sort of the category
  642. $user_id = intval($user_id);
  643. $sql = "SELECT
  644. course.code k,
  645. course.visual_code vc,
  646. course.subscribe subscr,
  647. course.unsubscribe unsubscr,
  648. course.title i,
  649. course.tutor_name t,
  650. course.directory dir,
  651. course_rel_user.status status,
  652. course_rel_user.sort sort,
  653. course_rel_user.user_course_cat user_course_cat
  654. FROM
  655. $table_course course,
  656. $table_course_user course_rel_user
  657. WHERE
  658. course.id = course_rel_user.c_id AND
  659. course_rel_user.user_id = '".$user_id."' AND
  660. course_rel_user.relation_type <> ".COURSE_RELATION_TYPE_RRHH."
  661. ORDER BY course_rel_user.sort ASC";
  662. $result = Database::query($sql);
  663. $courses = array();
  664. while ($row = Database::fetch_array($result)) {
  665. // We only need the database name of the course.
  666. $courses[$row['k']] = array(
  667. 'code' => $row['k'],
  668. 'visual_code' => $row['vc'],
  669. 'title' => $row['i'],
  670. 'directory' => $row['dir'],
  671. 'status' => $row['status'],
  672. 'tutor' => $row['t'],
  673. 'subscribe' => $row['subscr'],
  674. 'unsubscribe' => $row['unsubscr'],
  675. 'sort' => $row['sort'],
  676. 'user_course_category' => $row['user_course_cat']
  677. );
  678. }
  679. return $courses;
  680. }
  681. /**
  682. * @todo use the template system
  683. * @param $title
  684. * @param $content
  685. * @param string $id
  686. * @param array $params
  687. * @param string $idAccordion
  688. * @param string $idCollapse
  689. * @return string
  690. */
  691. public function show_right_block(
  692. $title,
  693. $content,
  694. $id = '',
  695. $params = [],
  696. $idAccordion = '',
  697. $idCollapse = ''
  698. ) {
  699. $html = '';
  700. if (!empty($idAccordion)) {
  701. $html .= '<div class="panel-group" id="'.$idAccordion.'" role="tablist" aria-multiselectable="true">';
  702. $html .= '<div class="panel panel-default" id="'.$id.'">';
  703. $html .= '<div class="panel-heading" role="tab"><h4 class="panel-title">';
  704. $html .= '<a role="button" data-toggle="collapse" data-parent="#'.$idAccordion.'" href="#'.$idCollapse.'" aria-expanded="true" aria-controls="'.$idCollapse.'">'.$title.'</a>';
  705. $html .= '</h4></div>';
  706. $html .= '<div id="'.$idCollapse.'" class="panel-collapse collapse in" role="tabpanel">';
  707. $html .= '<div class="panel-body">'.$content.'</div>';
  708. $html .= '</div></div></div>';
  709. } else {
  710. if (!empty($id)) {
  711. $params['id'] = $id;
  712. }
  713. $params['class'] = 'panel panel-default';
  714. $html = null;
  715. if (!empty($title)) {
  716. $html .= '<div class="panel-heading">'.$title.'</div>';
  717. }
  718. $html .= '<div class="panel-body">'.$content.'</div>';
  719. $html = Display::div($html, $params);
  720. }
  721. return $html;
  722. }
  723. /**
  724. * Adds a form to let users login
  725. * @version 1.1
  726. */
  727. public function display_login_form()
  728. {
  729. return $this->tpl->displayLoginForm();
  730. }
  731. /**
  732. * @todo use FormValidator
  733. * @return string
  734. */
  735. public function return_search_block()
  736. {
  737. $html = '';
  738. if (api_get_setting('search_enabled') == 'true') {
  739. $search_btn = get_lang('Search');
  740. $search_content = '<form action="main/search/" method="post">
  741. <div class="form-group">
  742. <input type="text" id="query" class="form-control" name="query" value="" />
  743. <button class="btn btn-default" type="submit" name="submit" value="'.$search_btn.'" />'.$search_btn.' </button>
  744. </div></form>';
  745. $html .= self::show_right_block(get_lang('Search'), $search_content, 'search_block');
  746. }
  747. return $html;
  748. }
  749. /**
  750. * @return string
  751. */
  752. public function return_classes_block()
  753. {
  754. if (api_get_setting('show_groups_to_users') !== 'true') {
  755. return '';
  756. }
  757. $usergroup = new UserGroup();
  758. $usergroup_list = $usergroup->get_usergroup_by_user(api_get_user_id());
  759. $items = [];
  760. if (!empty($usergroup_list)) {
  761. foreach ($usergroup_list as $group_id) {
  762. $data = $usergroup->get($group_id);
  763. $items[] = [
  764. 'link' => api_get_path(WEB_CODE_PATH).'user/classes.php?id='.$data['id'],
  765. 'title' => $data['name']
  766. ];
  767. }
  768. }
  769. if (api_is_platform_admin()) {
  770. $items[] = [
  771. 'link' => api_get_path(WEB_CODE_PATH).'admin/usergroups.php?action=add',
  772. 'title' => get_lang('AddClasses')
  773. ];
  774. }
  775. $html = self::show_right_block(
  776. get_lang('Classes'),
  777. self::returnRightBlockItems($items),
  778. 'classes_block'
  779. );
  780. return $html;
  781. }
  782. /**
  783. * @return string
  784. */
  785. public function return_user_image_block()
  786. {
  787. $html = '';
  788. if (!api_is_anonymous()) {
  789. $userPicture = UserManager::getUserPicture(api_get_user_id(), USER_IMAGE_SIZE_ORIGINAL);
  790. $content = null;
  791. if (api_get_setting('allow_social_tool') == 'true') {
  792. $content .= '<a style="text-align:center" href="'.api_get_path(WEB_PATH).'main/social/home.php">
  793. <img class="img-circle" src="'.$userPicture.'"></a>';
  794. } else {
  795. $content .= '<a style="text-align:center" href="'.api_get_path(WEB_PATH).'main/auth/profile.php">
  796. <img class="img-circle" title="'.get_lang('EditProfile').'" src="'.$userPicture.'"></a>';
  797. }
  798. $html = self::show_right_block(
  799. null,
  800. $content,
  801. 'user_image_block',
  802. array('style' => 'text-align:center;')
  803. );
  804. }
  805. return $html;
  806. }
  807. /**
  808. * @return array
  809. */
  810. public function return_profile_block()
  811. {
  812. $userInfo = api_get_user_info();
  813. $userId = api_get_user_id();
  814. if (empty($userId)) {
  815. return;
  816. }
  817. $items = [];
  818. $userGroup = new UserGroup();
  819. // @todo Add a platform setting to add the user image.
  820. if (api_get_setting('allow_message_tool') == 'true') {
  821. // New messages.
  822. $number_of_new_messages = MessageManager::getCountNewMessages();
  823. // New contact invitations.
  824. $number_of_new_messages_of_friend = SocialManager::get_message_number_invitation_by_user_id(
  825. $userId
  826. );
  827. // New group invitations sent by a moderator.
  828. $group_pending_invitations = $userGroup->get_groups_by_user(
  829. $userId,
  830. GROUP_USER_PERMISSION_PENDING_INVITATION,
  831. false
  832. );
  833. $group_pending_invitations = count($group_pending_invitations);
  834. $total_invitations = $number_of_new_messages_of_friend + $group_pending_invitations;
  835. $cant_msg = Display::badge($number_of_new_messages);
  836. $link = '';
  837. if (api_get_setting('allow_social_tool') == 'true') {
  838. $link = '?f=social';
  839. }
  840. $items[] = [
  841. 'class' => 'inbox-message-social',
  842. 'icon' => Display::return_icon('inbox.png', get_lang('Inbox')),
  843. 'link' => api_get_path(WEB_PATH).'main/messages/inbox.php'.$link,
  844. 'title' => get_lang('Inbox').$cant_msg
  845. ];
  846. $items[] = [
  847. 'class' => 'new-message-social',
  848. 'icon' => Display::return_icon('new-message.png', get_lang('Compose')),
  849. 'link' => api_get_path(WEB_PATH).'main/messages/new_message.php'.$link,
  850. 'title' => get_lang('Compose')
  851. ];
  852. if (api_get_setting('allow_social_tool') == 'true') {
  853. $total_invitations = Display::badge($total_invitations);
  854. $items[] = [
  855. 'class' => 'invitations-social',
  856. 'icon' => Display::return_icon('invitations.png', get_lang('PendingInvitations')),
  857. 'link' => api_get_path(WEB_PATH).'main/social/invitations.php',
  858. 'title' => get_lang('PendingInvitations').$total_invitations
  859. ];
  860. }
  861. if (api_get_configuration_value('allow_my_files_link_in_homepage')) {
  862. if (api_get_setting('allow_my_files') !== 'false') {
  863. $items[] = [
  864. 'class' => 'myfiles-social',
  865. 'icon' => Display::return_icon('sn-files.png', get_lang('Files')),
  866. 'link' => api_get_path(WEB_PATH).'main/social/myfiles.php',
  867. 'title' => get_lang('MyFiles')
  868. ];
  869. }
  870. }
  871. }
  872. $items[] = [
  873. 'class' => 'profile-social',
  874. 'icon' => Display::return_icon('edit-profile.png', get_lang('EditProfile')),
  875. 'link' => Display::getProfileEditionLink($userId),
  876. 'title' => get_lang('EditProfile')
  877. ];
  878. if (api_get_configuration_value('show_link_request_hrm_user') &&
  879. api_is_drh()
  880. ) {
  881. $label = get_lang('RequestLinkingToUser');
  882. $items[] = [
  883. 'icon' => Display::return_icon('new_group.png', $label),
  884. 'link' => api_get_path(WEB_CODE_PATH).'social/require_user_linking.php',
  885. 'title' => $label
  886. ];
  887. }
  888. if (bbb::showGlobalConferenceLink($userInfo)) {
  889. $url = api_get_path(WEB_PLUGIN_PATH).'bbb/start.php?global=1';
  890. $items[] = [
  891. 'class' => 'video-conference',
  892. 'icon' => Display::return_icon(
  893. 'bbb.png',
  894. get_lang('VideoConference')
  895. ),
  896. 'link' => $url,
  897. 'title' => get_lang('VideoConference')
  898. ];
  899. }
  900. return $items;
  901. }
  902. /**
  903. * @return array
  904. */
  905. public function return_navigation_links()
  906. {
  907. $items = [];
  908. // Deleting the myprofile link.
  909. if (api_get_setting('allow_social_tool') == 'true') {
  910. unset($this->tpl->menu_navigation['myprofile']);
  911. }
  912. $hideMenu = api_get_configuration_value('hide_main_navigation_menu');
  913. if ($hideMenu === true) {
  914. return '';
  915. }
  916. // Main navigation section.
  917. // Tabs that are deactivated are added here.
  918. if (!empty($this->tpl->menu_navigation)) {
  919. //$content = '<ul class="nav nav-pills nav-stacked">';
  920. foreach ($this->tpl->menu_navigation as $section => $navigation_info) {
  921. $items [] = [
  922. 'icon' => null,
  923. 'link' => $navigation_info['url'],
  924. 'title' => $navigation_info['title']
  925. ];
  926. }
  927. }
  928. return $items;
  929. }
  930. /**
  931. * @return null|string
  932. */
  933. public function return_course_block()
  934. {
  935. $isHrm = api_is_drh();
  936. $show_create_link = false;
  937. $show_course_link = false;
  938. if (api_is_allowed_to_create_course()) {
  939. $show_create_link = true;
  940. }
  941. if (api_get_setting('allow_students_to_browse_courses') === 'true') {
  942. $show_course_link = true;
  943. }
  944. $items = [];
  945. // My account section
  946. if ($show_create_link) {
  947. if (api_get_setting('course_validation') == 'true' && !api_is_platform_admin()) {
  948. $items[] = [
  949. 'class' => 'add-course',
  950. 'icon' => Display::return_icon('new-course.png', get_lang('CreateCourseRequest')),
  951. 'link' => 'main/create_course/add_course.php',
  952. 'title' => get_lang('CreateCourseRequest')
  953. ];
  954. } else {
  955. $items[] = [
  956. 'class' => 'add-course',
  957. 'icon' => Display::return_icon('new-course.png', get_lang('CourseCreate')),
  958. 'link' => 'main/create_course/add_course.php',
  959. 'title' => get_lang('CourseCreate')
  960. ];
  961. }
  962. if (SessionManager::allowToManageSessions()) {
  963. $items[] = [
  964. 'class' => 'add-course',
  965. 'icon' => Display::return_icon('session.png', get_lang('AddSession')),
  966. 'link' => 'main/session/session_add.php',
  967. 'title' => get_lang('AddSession')
  968. ];
  969. }
  970. }
  971. // Sort courses
  972. // ofaj
  973. /*$items[] = [
  974. 'class' => 'order-course',
  975. 'icon' => Display::return_icon('order-course.png', get_lang('SortMyCourses')),
  976. 'link' => api_get_path(WEB_CODE_PATH).'auth/courses.php?action=sortmycourses',
  977. 'title' => get_lang('SortMyCourses')
  978. ];*/
  979. // Session history
  980. if (isset($_GET['history']) && intval($_GET['history']) == 1) {
  981. $items[] = [
  982. 'class' => 'history-course',
  983. 'icon' => Display::return_icon('history-course.png', get_lang('DisplayTrainingList')),
  984. 'link' => 'user_portal.php',
  985. 'title' => get_lang('DisplayTrainingList')
  986. ];
  987. } else {
  988. $items[] = [
  989. 'class' => 'history-course',
  990. 'icon' => Display::return_icon('history-course.png', get_lang('HistoryTrainingSessions')),
  991. 'link' => 'user_portal.php?history=1',
  992. 'title' => get_lang('HistoryTrainingSessions')
  993. ];
  994. }
  995. if ($isHrm) {
  996. $items[] = [
  997. 'link' => api_get_path(WEB_CODE_PATH).'auth/hrm_courses.php',
  998. 'title' => get_lang('HrmAssignedUsersCourseList')
  999. ];
  1000. }
  1001. // Course catalog
  1002. if ($show_course_link) {
  1003. if (!api_is_drh()) {
  1004. $items[] = [
  1005. 'class' => 'list-course',
  1006. 'icon' => Display::return_icon('catalog-course.png', get_lang('CourseCatalog')),
  1007. 'link' => 'main/auth/courses.php',
  1008. 'title' => get_lang('CourseCatalog')
  1009. ];
  1010. } else {
  1011. $items[] = [
  1012. 'link' => 'main/dashboard/index.php',
  1013. 'title' => get_lang('Dashboard')
  1014. ];
  1015. }
  1016. }
  1017. return $items;
  1018. }
  1019. /**
  1020. * Generate the HTML code for items when displaying the right-side blocks
  1021. * @param array $items
  1022. * @return string
  1023. */
  1024. private static function returnRightBlockItems(array $items)
  1025. {
  1026. $my_account_content = '';
  1027. foreach ($items as $item) {
  1028. if (empty($item['link']) && empty($item['title'])) {
  1029. continue;
  1030. }
  1031. $my_account_content .= '<li class="list-group-item '.(empty($item['class']) ? '' : $item['class']).'">'
  1032. .(empty($item['icon']) ? '' : '<span class="item-icon">'.$item['icon'].'</span>')
  1033. .'<a href="'.$item['link'].'">'.$item['title'].'</a>'
  1034. .'</li>';
  1035. }
  1036. return '<ul class="list-group">'.$my_account_content.'</ul>';
  1037. }
  1038. /**
  1039. * Prints the session and course list (user_portal.php)
  1040. * @param int $user_id
  1041. * @param bool $showSessions
  1042. * @param string $categoryCodeFilter
  1043. * @param bool $useUserLanguageFilterIfAvailable
  1044. * @return string
  1045. */
  1046. public function returnCoursesAndSessions(
  1047. $user_id,
  1048. $showSessions = true,
  1049. $categoryCodeFilter = '',
  1050. $useUserLanguageFilterIfAvailable = true
  1051. ) {
  1052. $gameModeIsActive = api_get_setting('gamification_mode');
  1053. $listCourse = '';
  1054. $specialCourseList = '';
  1055. $load_history = isset($_GET['history']) && intval($_GET['history']) == 1 ? true : false;
  1056. $viewGridCourses = api_get_configuration_value('view_grid_courses') === true;
  1057. $showSimpleSessionInfo = api_get_configuration_value('show_simple_session_info');
  1058. $coursesWithoutCategoryTemplate = '/user_portal/classic_courses_without_category.tpl';
  1059. $coursesWithCategoryTemplate = '/user_portal/classic_courses_with_category.tpl';
  1060. if ($load_history) {
  1061. // Load sessions in category in *history*
  1062. $session_categories = UserManager::get_sessions_by_category($user_id, true);
  1063. } else {
  1064. // Load sessions in category
  1065. $session_categories = UserManager::get_sessions_by_category($user_id, false);
  1066. }
  1067. $sessionCount = 0;
  1068. $courseCount = 0;
  1069. // Student info code check (shows student progress information on
  1070. // courses list
  1071. $studentInfo = api_get_configuration_value('course_student_info');
  1072. $viewGrid = api_get_configuration_value('view_grid_courses');
  1073. $studentInfoProgress = !empty($studentInfo['progress']) && $studentInfo['progress'] === true;
  1074. $studentInfoScore = !empty($studentInfo['score']) && $studentInfo['score'] === true;
  1075. $studentInfoCertificate = !empty($studentInfo['certificate']) && $studentInfo['certificate'] === true;
  1076. $courseCompleteList = [];
  1077. $coursesInCategoryCount = 0;
  1078. $coursesNotInCategoryCount = 0;
  1079. // If we're not in the history view...
  1080. if (!isset($_GET['history'])) {
  1081. // Display special courses.
  1082. $specialCourses = CourseManager::returnSpecialCourses(
  1083. $user_id,
  1084. $this->load_directories_preview,
  1085. $useUserLanguageFilterIfAvailable
  1086. );
  1087. // Display courses.
  1088. $courses = CourseManager::returnCourses(
  1089. $user_id,
  1090. $this->load_directories_preview,
  1091. $useUserLanguageFilterIfAvailable
  1092. );
  1093. // Course option (show student progress)
  1094. // This code will add new variables (Progress, Score, Certificate)
  1095. if ($studentInfoProgress || $studentInfoScore || $studentInfoCertificate) {
  1096. if (!empty($specialCourses)) {
  1097. foreach ($specialCourses as $key => $specialCourseInfo) {
  1098. if ($studentInfoProgress) {
  1099. $progress = Tracking::get_avg_student_progress(
  1100. $user_id,
  1101. $specialCourseInfo['course_code']
  1102. );
  1103. $specialCourses[$key]['student_info']['progress'] = $progress === false ? null : $progress;
  1104. }
  1105. if ($studentInfoScore) {
  1106. $percentage_score = Tracking::get_avg_student_score(
  1107. $user_id,
  1108. $specialCourseInfo['course_code'],
  1109. array()
  1110. );
  1111. $specialCourses[$key]['student_info']['score'] = $percentage_score;
  1112. }
  1113. if ($studentInfoCertificate) {
  1114. $category = Category::load(
  1115. null,
  1116. null,
  1117. $specialCourseInfo['course_code'],
  1118. null,
  1119. null,
  1120. null
  1121. );
  1122. $specialCourses[$key]['student_info']['certificate'] = null;
  1123. if (isset($category[0])) {
  1124. if ($category[0]->is_certificate_available($user_id)) {
  1125. $specialCourses[$key]['student_info']['certificate'] = Display::label(
  1126. get_lang('Yes'),
  1127. 'success'
  1128. );
  1129. } else {
  1130. $specialCourses[$key]['student_info']['certificate'] = Display::label(
  1131. get_lang('No'),
  1132. 'danger'
  1133. );
  1134. }
  1135. }
  1136. }
  1137. }
  1138. }
  1139. if (isset($courses['in_category'])) {
  1140. foreach ($courses['in_category'] as $key1 => $value) {
  1141. if (isset($courses['in_category'][$key1]['courses'])) {
  1142. foreach ($courses['in_category'][$key1]['courses'] as $key2 => $courseInCatInfo) {
  1143. if ($studentInfoProgress) {
  1144. $progress = Tracking::get_avg_student_progress(
  1145. $user_id,
  1146. $courseInCatInfo['course_code']
  1147. );
  1148. $courses['in_category'][$key1]['courses'][$key2]['student_info']['progress'] = $progress === false ? null : $progress;
  1149. }
  1150. if ($studentInfoScore) {
  1151. $percentage_score = Tracking::get_avg_student_score(
  1152. $user_id,
  1153. $specialCourseInfo['course_code'],
  1154. array()
  1155. );
  1156. $courses['in_category'][$key1]['courses'][$key2]['student_info']['score'] = $percentage_score;
  1157. }
  1158. if ($studentInfoCertificate) {
  1159. $category = Category::load(
  1160. null,
  1161. null,
  1162. $courseInCatInfo['course_code'],
  1163. null,
  1164. null,
  1165. null
  1166. );
  1167. $courses['in_category'][$key1]['student_info']['certificate'] = null;
  1168. $isCertificateAvailable = $category[0]->is_certificate_available($user_id);
  1169. if (isset($category[0])) {
  1170. if ($viewGrid == 'true') {
  1171. if ($isCertificateAvailable) {
  1172. $courses['in_category'][$key1]['student_info']['certificate'] = get_lang('Yes');
  1173. } else {
  1174. $courses['in_category'][$key1]['student_info']['certificate'] = get_lang('No');
  1175. }
  1176. } else {
  1177. if ($isCertificateAvailable) {
  1178. $courses['in_category'][$key1]['student_info']['certificate'] = Display::label(
  1179. get_lang('Yes'),
  1180. 'success'
  1181. );
  1182. } else {
  1183. $courses['in_category'][$key1]['student_info']['certificate'] = Display::label(
  1184. get_lang('No'),
  1185. 'danger'
  1186. );
  1187. }
  1188. }
  1189. }
  1190. }
  1191. }
  1192. }
  1193. }
  1194. }
  1195. if (isset($courses['not_category'])) {
  1196. foreach ($courses['not_category'] as $key => $courseNotInCatInfo) {
  1197. if ($studentInfoProgress) {
  1198. $progress = Tracking::get_avg_student_progress(
  1199. $user_id,
  1200. $courseNotInCatInfo['course_code']
  1201. );
  1202. $courses['not_category'][$key]['student_info']['progress'] = $progress === false ? null : $progress;
  1203. }
  1204. if ($studentInfoScore) {
  1205. $percentage_score = Tracking::get_avg_student_score(
  1206. $user_id,
  1207. $courseNotInCatInfo['course_code'],
  1208. array()
  1209. );
  1210. $courses['not_category'][$key]['student_info']['score'] = $percentage_score;
  1211. }
  1212. if ($studentInfoCertificate) {
  1213. $category = Category::load(
  1214. null,
  1215. null,
  1216. $courseNotInCatInfo['course_code'],
  1217. null,
  1218. null,
  1219. null
  1220. );
  1221. $courses['not_category'][$key]['student_info']['certificate'] = null;
  1222. if (isset($category[0])) {
  1223. $certificateAvailable = $category[0]->is_certificate_available($user_id);
  1224. if ($viewGrid == 'true') {
  1225. if ($certificateAvailable) {
  1226. $courses['not_category'][$key]['student_info']['certificate'] = get_lang('Yes');
  1227. } else {
  1228. $courses['not_category'][$key]['student_info']['certificate'] = get_lang('No');
  1229. }
  1230. } else {
  1231. if ($certificateAvailable) {
  1232. $courses['not_category'][$key]['student_info']['certificate'] = Display::label(
  1233. get_lang('Yes'),
  1234. 'success'
  1235. );
  1236. } else {
  1237. $courses['not_category'][$key]['student_info']['certificate'] = Display::label(
  1238. get_lang('No'),
  1239. 'danger'
  1240. );
  1241. }
  1242. }
  1243. }
  1244. }
  1245. }
  1246. }
  1247. }
  1248. if ($viewGridCourses) {
  1249. $coursesWithoutCategoryTemplate = '/user_portal/grid_courses_without_category.tpl';
  1250. $coursesWithCategoryTemplate = '/user_portal/grid_courses_with_category.tpl';
  1251. }
  1252. if ($specialCourses) {
  1253. if ($categoryCodeFilter) {
  1254. $specialCourses = self::filterByCategory(
  1255. $specialCourses,
  1256. $categoryCodeFilter
  1257. );
  1258. }
  1259. $this->tpl->assign('courses', $specialCourses);
  1260. $specialCourseList = $this->tpl->fetch(
  1261. $this->tpl->get_template($coursesWithoutCategoryTemplate)
  1262. );
  1263. $courseCompleteList = array_merge($courseCompleteList, $specialCourses);
  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. // ofaj 4 courses
  1668. return CourseManager::return_hot_courses(30, 4);
  1669. }
  1670. /**
  1671. * UserPortal view for session, return the HTML of the course list
  1672. * @param $user_id
  1673. * @return string
  1674. */
  1675. public function returnCoursesAndSessionsViewBySession($user_id)
  1676. {
  1677. $sessionCount = 0;
  1678. $courseCount = 0;
  1679. $load_history = (isset($_GET['history']) && intval($_GET['history']) == 1) ? true : false;
  1680. if ($load_history) {
  1681. // Load sessions in category in *history*
  1682. $session_categories = UserManager::get_sessions_by_category($user_id, true);
  1683. } else {
  1684. // Load sessions in category
  1685. $session_categories = UserManager::get_sessions_by_category($user_id, false);
  1686. }
  1687. $html = '';
  1688. $loadDirs = $this->load_directories_preview;
  1689. // If we're not in the history view...
  1690. $listCoursesInfo = array();
  1691. if (!isset($_GET['history'])) {
  1692. // Display special courses
  1693. $specialCoursesResult = CourseManager::returnSpecialCourses(
  1694. $user_id,
  1695. $loadDirs
  1696. );
  1697. $specialCourses = $specialCoursesResult;
  1698. if ($specialCourses) {
  1699. $this->tpl->assign('courses', $specialCourses);
  1700. $html = $this->tpl->fetch(
  1701. $this->tpl->get_template('/user_portal/classic_courses_without_category.tpl')
  1702. );
  1703. }
  1704. // Display courses
  1705. // [code=>xxx, real_id=>000]
  1706. $listCourses = CourseManager::get_courses_list_by_user_id(
  1707. $user_id,
  1708. false
  1709. );
  1710. foreach ($listCourses as $i => $listCourseCodeId) {
  1711. if (isset($listCourseCodeId['special_course'])) {
  1712. continue;
  1713. }
  1714. $courseCategory = CourseManager::getUserCourseCategoryForCourse(
  1715. $user_id,
  1716. $listCourseCodeId['real_id']
  1717. );
  1718. $userCatTitle = '';
  1719. $userCategoryId = 0;
  1720. if ($courseCategory) {
  1721. $userCategoryId = $courseCategory['user_course_cat'];
  1722. $userCatTitle = $courseCategory['title'];
  1723. }
  1724. $listCourse = api_get_course_info_by_id($listCourseCodeId['real_id']);
  1725. $listCoursesInfo[] = array(
  1726. 'course' => $listCourse,
  1727. 'code' => $listCourseCodeId['code'],
  1728. 'id' => $listCourseCodeId['real_id'],
  1729. 'title' => $listCourse['title'],
  1730. 'userCatId' => $userCategoryId,
  1731. 'userCatTitle' => $userCatTitle
  1732. );
  1733. $courseCount++;
  1734. }
  1735. usort($listCoursesInfo, 'self::compareByCourse');
  1736. }
  1737. if (is_array($session_categories)) {
  1738. // all courses that are in a session
  1739. $listCoursesInSession = SessionManager::getNamedSessionCourseForCoach($user_id);
  1740. }
  1741. // we got all courses
  1742. // for each user category, sorted alphabetically, display courses
  1743. $listUserCategories = CourseManager::get_user_course_categories($user_id);
  1744. $listCoursesAlreadyDisplayed = array();
  1745. uasort($listUserCategories, "self::compareListUserCategory");
  1746. $listUserCategories[0] = '';
  1747. $html .= '<div class="session-view-block">';
  1748. foreach ($listUserCategories as $userCategoryId => $userCat) {
  1749. // add user category
  1750. $userCategoryHtml = '';
  1751. if ($userCategoryId != 0) {
  1752. $userCategoryHtml = '<div class="session-view-well ">';
  1753. $userCategoryHtml .= self::getHtmlForUserCategory($userCategoryId, $userCat['title']);
  1754. }
  1755. // look for course in this userCat in session courses : $listCoursesInSession
  1756. $htmlCategory = '';
  1757. if (isset($listCoursesInSession[$userCategoryId])) {
  1758. // list of courses in this user cat
  1759. foreach ($listCoursesInSession[$userCategoryId]['courseInUserCatList'] as $i => $listCourse) {
  1760. // add course
  1761. $listCoursesAlreadyDisplayed[$listCourse['courseId']] = 1;
  1762. if ($userCategoryId == 0) {
  1763. $htmlCategory .= '<div class="panel panel-default">';
  1764. } else {
  1765. $htmlCategory .= '<div class="panel panel-default">';
  1766. }
  1767. $htmlCategory .= '<div class="panel-body">';
  1768. $coursesInfo = $listCourse['course'];
  1769. $htmlCategory .= self::getHtmlForCourse(
  1770. $coursesInfo,
  1771. $userCategoryId,
  1772. 1,
  1773. $loadDirs
  1774. );
  1775. // list of session category
  1776. $htmlSessionCategory = '<div class="session-view-row" style="display:none;" id="courseblock-'.$coursesInfo['real_id'].'">';
  1777. foreach ($listCourse['sessionCatList'] as $j => $listCategorySession) {
  1778. // add session category
  1779. $htmlSessionCategory .= self::getHtmlSessionCategory(
  1780. $listCategorySession['catSessionId'],
  1781. $listCategorySession['catSessionName']
  1782. );
  1783. // list of session
  1784. $htmlSession = ''; // start
  1785. foreach ($listCategorySession['sessionList'] as $k => $listSession) {
  1786. // add session
  1787. $htmlSession .= '<div class="session-view-row">';
  1788. $htmlSession .= self::getHtmlForSession(
  1789. $listSession['sessionId'],
  1790. $listSession['sessionName'],
  1791. $listCategorySession['catSessionId'],
  1792. $coursesInfo
  1793. );
  1794. $htmlSession .= '</div>';
  1795. $sessionCount++;
  1796. }
  1797. $htmlSession .= ''; // end session block
  1798. $htmlSessionCategory .= $htmlSession;
  1799. }
  1800. $htmlSessionCategory .= '</div>'; // end session cat block
  1801. $htmlCategory .= $htmlSessionCategory.'</div></div>';
  1802. $htmlCategory .= ''; // end course block
  1803. }
  1804. $userCategoryHtml .= $htmlCategory;
  1805. }
  1806. // look for courses in this userCat in not in session courses : $listCoursesInfo
  1807. // if course not already added
  1808. $htmlCategory = '';
  1809. foreach ($listCoursesInfo as $i => $listCourse) {
  1810. if ($listCourse['userCatId'] == $userCategoryId && !isset($listCoursesAlreadyDisplayed[$listCourse['id']])) {
  1811. if ($userCategoryId != 0) {
  1812. $htmlCategory .= '<div class="panel panel-default">';
  1813. } else {
  1814. $htmlCategory .= '<div class="panel panel-default">';
  1815. }
  1816. $htmlCategory .= '<div class="panel-body">';
  1817. $htmlCategory .= self::getHtmlForCourse(
  1818. $listCourse['course'],
  1819. $userCategoryId,
  1820. 0,
  1821. $loadDirs
  1822. );
  1823. $htmlCategory .= '</div></div>';
  1824. }
  1825. }
  1826. $htmlCategory .= '';
  1827. $userCategoryHtml .= $htmlCategory; // end user cat block
  1828. if ($userCategoryId != 0) {
  1829. $userCategoryHtml .= '</div>';
  1830. }
  1831. $html .= $userCategoryHtml; //
  1832. }
  1833. $html .= '</div>';
  1834. return [
  1835. 'html' => $html,
  1836. 'sessions' => $session_categories,
  1837. 'courses' => $listCoursesInfo,
  1838. 'session_count' => $sessionCount,
  1839. 'course_count' => $courseCount
  1840. ];
  1841. }
  1842. /**
  1843. * Return HTML code for personal user course category
  1844. * @param $id
  1845. * @param $title
  1846. * @return string
  1847. */
  1848. private static function getHtmlForUserCategory($id, $title)
  1849. {
  1850. if ($id == 0) {
  1851. return '';
  1852. }
  1853. $icon = Display::return_icon(
  1854. 'folder_yellow.png',
  1855. $title,
  1856. array('class' => 'sessionView'),
  1857. ICON_SIZE_LARGE
  1858. );
  1859. return "<div class='session-view-user-category'>$icon<span>$title</span></div>";
  1860. }
  1861. /**
  1862. * return HTML code for course display in session view
  1863. * @param array $courseInfo
  1864. * @param $userCategoryId
  1865. * @param bool $displayButton
  1866. * @param $loadDirs
  1867. * @return string
  1868. */
  1869. private static function getHtmlForCourse(
  1870. $courseInfo,
  1871. $userCategoryId,
  1872. $displayButton = false,
  1873. $loadDirs
  1874. ) {
  1875. if (empty($courseInfo)) {
  1876. return '';
  1877. }
  1878. $id = $courseInfo['real_id'];
  1879. $title = $courseInfo['title'];
  1880. $code = $courseInfo['code'];
  1881. $class = 'session-view-lvl-6';
  1882. if ($userCategoryId != 0 && !$displayButton) {
  1883. $class = 'session-view-lvl-7';
  1884. }
  1885. $class2 = 'session-view-lvl-6';
  1886. if ($displayButton || $userCategoryId != 0) {
  1887. $class2 = 'session-view-lvl-7';
  1888. }
  1889. $button = '';
  1890. if ($displayButton) {
  1891. $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="+" />';
  1892. }
  1893. $icon = Display::return_icon(
  1894. 'blackboard.png',
  1895. $title,
  1896. array('class' => 'sessionView'),
  1897. ICON_SIZE_LARGE
  1898. );
  1899. $courseLink = $courseInfo['course_public_url'].'?id_session=0';
  1900. // get html course params
  1901. $courseParams = CourseManager::getCourseParamsForDisplay($id, $loadDirs);
  1902. $teachers = '';
  1903. $rightActions = '';
  1904. // teacher list
  1905. if (!empty($courseParams['teachers'])) {
  1906. $teachers = '<p class="'.$class2.' view-by-session-teachers">'.$courseParams['teachers'].'</p>';
  1907. }
  1908. // notification
  1909. if (!empty($courseParams['right_actions'])) {
  1910. $rightActions = '<div class="pull-right">'.$courseParams['right_actions'].'</div>';
  1911. }
  1912. $notifications = isset($courseParams['notifications']) ? $courseParams['notifications'] : '';
  1913. return "<div>
  1914. $button
  1915. <span class='$class'>$icon
  1916. <a class='sessionView' href='$courseLink'>$title</a>
  1917. </span>
  1918. $notifications
  1919. $rightActions
  1920. </div>
  1921. $teachers";
  1922. }
  1923. /**
  1924. * return HTML code for session category
  1925. * @param $id
  1926. * @param $title
  1927. * @return string
  1928. */
  1929. private static function getHtmlSessionCategory($id, $title)
  1930. {
  1931. if ($id == 0) {
  1932. return '';
  1933. }
  1934. $icon = Display::return_icon(
  1935. 'folder_blue.png',
  1936. $title,
  1937. array('class' => 'sessionView'),
  1938. ICON_SIZE_LARGE
  1939. );
  1940. return "<div class='session-view-session-category'>
  1941. <span class='session-view-lvl-2'>
  1942. $icon
  1943. <span>$title</span>
  1944. </span>
  1945. </div>";
  1946. }
  1947. /**
  1948. * return HTML code for session
  1949. * @param int $id session id
  1950. * @param string $title session title
  1951. * @param int $categorySessionId
  1952. * @param array $courseInfo
  1953. *
  1954. * @return string
  1955. */
  1956. private static function getHtmlForSession($id, $title, $categorySessionId, $courseInfo)
  1957. {
  1958. $html = '';
  1959. if ($categorySessionId == 0) {
  1960. $class1 = 'session-view-lvl-2'; // session
  1961. $class2 = 'session-view-lvl-4'; // got to course in session link
  1962. } else {
  1963. $class1 = 'session-view-lvl-3'; // session
  1964. $class2 = 'session-view-lvl-5'; // got to course in session link
  1965. }
  1966. $icon = Display::return_icon(
  1967. 'blackboard_blue.png',
  1968. $title,
  1969. array('class' => 'sessionView'),
  1970. ICON_SIZE_LARGE
  1971. );
  1972. $courseLink = $courseInfo['course_public_url'].'?id_session='.intval($id);
  1973. $html .= "<span class='$class1 session-view-session'>$icon$title</span>";
  1974. $html .= '<div class="'.$class2.' session-view-session-go-to-course-in-session">
  1975. <a class="" href="'.$courseLink.'">'.get_lang('GoToCourseInsideSession').'</a></div>';
  1976. return '<div>'.$html.'</div>';
  1977. }
  1978. /**
  1979. * @param $listA
  1980. * @param $listB
  1981. * @return int
  1982. */
  1983. private static function compareByCourse($listA, $listB)
  1984. {
  1985. if ($listA['userCatTitle'] == $listB['userCatTitle']) {
  1986. if ($listA['title'] == $listB['title']) {
  1987. return 0;
  1988. }
  1989. if ($listA['title'] > $listB['title']) {
  1990. return 1;
  1991. }
  1992. return -1;
  1993. }
  1994. if ($listA['userCatTitle'] > $listB['userCatTitle']) {
  1995. return 1;
  1996. }
  1997. return -1;
  1998. }
  1999. /**
  2000. * @param $listA
  2001. * @param $listB
  2002. * @return int
  2003. */
  2004. public static function compareListUserCategory($listA, $listB)
  2005. {
  2006. if ($listA['title'] == $listB['title']) {
  2007. return 0;
  2008. }
  2009. if ($listA['title'] > $listB['title']) {
  2010. return 1;
  2011. }
  2012. return -1;
  2013. }
  2014. /**
  2015. * @param $view
  2016. * @param $userId
  2017. */
  2018. public static function setDefaultMyCourseView($view, $userId)
  2019. {
  2020. setcookie('defaultMyCourseView'.$userId, $view);
  2021. }
  2022. /**
  2023. * Get the session coach name, duration or dates
  2024. * when $_configuration['show_simple_session_info'] is enabled
  2025. * @param string $coachName
  2026. * @param string $dates
  2027. * @param string|null $duration Optional
  2028. * @return string
  2029. */
  2030. private static function getSimpleSessionDetails($coachName, $dates, $duration = null)
  2031. {
  2032. $strDetails = [];
  2033. if (!empty($coachName)) {
  2034. $strDetails[] = $coachName;
  2035. }
  2036. $strDetails[] = !empty($duration) ? $duration : $dates;
  2037. return implode(' | ', $strDetails);
  2038. }
  2039. /**
  2040. * @param int $userId
  2041. * @return array
  2042. */
  2043. public function returnCourseCategoryListFromUser($userId)
  2044. {
  2045. $sessionCount = 0;
  2046. $courseList = CourseManager::get_courses_list_by_user_id($userId);
  2047. $categoryCodes = CourseManager::getCourseCategoriesFromCourseList($courseList);
  2048. $categories = [];
  2049. foreach ($categoryCodes as $categoryCode) {
  2050. $categories[] = CourseCategory::getCategory($categoryCode);
  2051. }
  2052. $template = new Template('', false, false, false, true, false, false);
  2053. $layout = $template->get_template('user_portal/course_categories.tpl');
  2054. $template->assign('course_categories', $categories);
  2055. return [
  2056. 'courses' => $courseList,
  2057. 'html' => $template->fetch($layout),
  2058. 'course_count' => count($courseList),
  2059. 'session_count' => $sessionCount
  2060. ];
  2061. }
  2062. /**
  2063. * Filter the course list by category code
  2064. * @param array $courseList course list
  2065. * @param string $categoryCode
  2066. * @return array
  2067. */
  2068. private static function filterByCategory($courseList, $categoryCode)
  2069. {
  2070. return array_filter($courseList, function ($courseInfo) use ($categoryCode) {
  2071. if (isset($courseInfo['category_code']) &&
  2072. $courseInfo['category_code'] === $categoryCode
  2073. ) {
  2074. return true;
  2075. }
  2076. return false;
  2077. });
  2078. }
  2079. }