userportal.lib.php 95 KB

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