userportal.lib.php 83 KB

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