userportal.lib.php 80 KB

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