userportal.lib.php 96 KB

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