userportal.lib.php 78 KB

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