userportal.lib.php 81 KB

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