userportal.lib.php 79 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725
  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. }