userportal.lib.php 79 KB

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