userportal.lib.php 98 KB

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