userportal.lib.php 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use \ChamiloSession as Session;
  4. class IndexManager {
  5. var $tpl = false; //An instance of the template engine
  6. var $name = '';
  7. var $home = '';
  8. var $default_home = 'home/';
  9. function __construct($title) {
  10. $this->tpl = new Template($title);
  11. $this->home = api_get_home_path();
  12. $this->user_id = api_get_user_id();
  13. $this->load_directories_preview = false;
  14. if (api_get_setting('show_documents_preview') == 'true') {
  15. $this->load_directories_preview = true;
  16. }
  17. }
  18. function set_login_form() {
  19. global $loginFailed;
  20. $login_form = '';
  21. if (!($this->user_id) || api_is_anonymous($this->user_id)) {
  22. // Only display if the user isn't logged in.
  23. $this->tpl->assign('login_language_form', api_display_language_form(true));
  24. $this->tpl->assign('login_form', self::display_login_form());
  25. if ($loginFailed) {
  26. $this->tpl->assign('login_failed', self::handle_login_failed());
  27. }
  28. if (api_get_setting('allow_lostpassword') == 'true' || api_get_setting('allow_registration') == 'true') {
  29. $login_form .= '<ul class="nav nav-list">';
  30. if (api_get_setting('allow_registration') != 'false') {
  31. $login_form .= '<li><a href="main/auth/inscription.php">'.get_lang('Reg').'</a></li>';
  32. }
  33. if (api_get_setting('allow_lostpassword') == 'true') {
  34. $login_form .= '<li><a href="main/auth/lostPassword.php">'.get_lang('LostPassword').'</a></li>';
  35. }
  36. $login_form .= '</ul>';
  37. }
  38. $this->tpl->assign('login_options', $login_form);
  39. }
  40. }
  41. function return_exercise_block($personal_course_list) {
  42. require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.lib.php';
  43. $exercise_list = array();
  44. if (!empty($personal_course_list)) {
  45. foreach($personal_course_list as $course_item) {
  46. $course_code = $course_item['c'];
  47. $session_id = $course_item['id_session'];
  48. $exercises = get_exercises_to_be_taken($course_code, $session_id);
  49. foreach($exercises as $exercise_item) {
  50. $exercise_item['course_code'] = $course_code;
  51. $exercise_item['session_id'] = $session_id;
  52. $exercise_item['tms'] = api_strtotime($exercise_item['end_time'], 'UTC');
  53. $exercise_list[] = $exercise_item;
  54. }
  55. }
  56. if (!empty($exercise_list)) {
  57. $exercise_list = msort($exercise_list, 'tms');
  58. $my_exercise = $exercise_list[0];
  59. $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']);
  60. $this->tpl->assign('exercise_url', $url);
  61. $this->tpl->assign('exercise_end_date', api_convert_and_format_date($my_exercise['end_time'], DATE_FORMAT_SHORT));
  62. }
  63. }
  64. }
  65. function return_announcements($show_slide = true) {
  66. // Display System announcements
  67. $announcement = isset($_GET['announcement']) ? $_GET['announcement'] : null;
  68. $announcement = intval($announcement);
  69. if (!api_is_anonymous() && $this->user_id) {
  70. $visibility = api_is_allowed_to_create_course() ? SystemAnnouncementManager::VISIBLE_TEACHER : SystemAnnouncementManager::VISIBLE_STUDENT;
  71. if ($show_slide) {
  72. $announcements = SystemAnnouncementManager :: display_announcements_slider($visibility, $announcement);
  73. } else {
  74. $announcements = SystemAnnouncementManager :: display_all_announcements($visibility, $announcement);
  75. }
  76. } else {
  77. if ($show_slide) {
  78. $announcements = SystemAnnouncementManager :: display_announcements_slider(SystemAnnouncementManager::VISIBLE_GUEST, $announcement);
  79. } else {
  80. $announcements = SystemAnnouncementManager :: display_all_announcements(SystemAnnouncementManager::VISIBLE_GUEST, $announcement);
  81. }
  82. }
  83. return $announcements;
  84. }
  85. /**
  86. * Alias for the online_logout() function
  87. */
  88. function logout() {
  89. online_logout($this->user_id, true);
  90. }
  91. /**
  92. * This function checks if there are courses that are open to the world in the platform course categories (=faculties)
  93. *
  94. * @param string $category
  95. * @return boolean
  96. */
  97. function category_has_open_courses($category) {
  98. $setting_show_also_closed_courses = api_get_setting('show_closed_courses') == 'true';
  99. $main_course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
  100. $category = Database::escape_string($category);
  101. $sql_query = "SELECT * FROM $main_course_table WHERE category_code='$category'";
  102. $sql_result = Database::query($sql_query);
  103. while ($course = Database::fetch_array($sql_result)) {
  104. if (!$setting_show_also_closed_courses) {
  105. if ((api_get_user_id() > 0 && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM) || ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD)) {
  106. return true; //at least one open course
  107. }
  108. } else {
  109. if (isset($course['visibility'])) {
  110. return true; // At least one course (it does not matter weither it's open or not because $setting_show_also_closed_courses = true).
  111. }
  112. }
  113. }
  114. return false;
  115. }
  116. /**
  117. * Displays the right-hand menu for anonymous users:
  118. * login form, useful links, help section
  119. * Warning: function defines globals
  120. * @version 1.0.1
  121. * @todo does $_plugins need to be global?
  122. */
  123. function display_anonymous_right_menu() {
  124. global $loginFailed, $_user;
  125. $display_add_course_link = api_is_allowed_to_create_course() && ($_SESSION['studentview'] != 'studentenview');
  126. $current_user_id = api_get_user_id();
  127. echo self::set_login_form(false);
  128. echo self::return_teacher_link();
  129. echo self::return_notice();
  130. }
  131. function return_teacher_link() {
  132. $html = '';
  133. if (!empty($this->user_id)) {
  134. // tabs that are deactivated are added here
  135. $show_menu = false;
  136. $show_create_link = false;
  137. $show_course_link = false;
  138. if (api_is_platform_admin() || api_is_course_admin() || api_is_allowed_to_create_course()) {
  139. $show_menu = true;
  140. $show_course_link = true;
  141. } else {
  142. if (api_get_setting('allow_students_to_browse_courses') == 'true') {
  143. $show_menu = true;
  144. $show_course_link = true;
  145. }
  146. }
  147. if ($show_menu && ($show_create_link || $show_course_link )) {
  148. $show_menu = true;
  149. } else {
  150. $show_menu = false;
  151. }
  152. }
  153. // My Account section
  154. if ($show_menu) {
  155. $html .= '<ul class="nav nav-list">';
  156. if ($show_create_link) {
  157. $html .= '<li><a href="main/create_course/add_course.php" class="add course">'.(api_get_setting('course_validation') == 'true' ? get_lang('CreateCourseRequest') : get_lang('CourseCreate')).'</a></li>';
  158. }
  159. if ($show_course_link) {
  160. if (!api_is_drh() && !api_is_session_admin()) {
  161. $html .= '<li><a href="main/auth/courses.php" class="list course">'.get_lang('CourseCatalog').'</a></li>';
  162. } else {
  163. $html .= '<li><a href="main/dashboard/index.php">'.get_lang('Dashboard').'</a></li>';
  164. }
  165. }
  166. $html .= '</ul>';
  167. }
  168. if (!empty($html)) {
  169. $html = self::show_right_block(get_lang('Courses'), $html, 'teacher_block');
  170. }
  171. return $html;
  172. }
  173. /* Includes a created page */
  174. function return_home_page() {
  175. // Including the page for the news
  176. $html = '';
  177. if (!empty($_GET['include']) && preg_match('/^[a-zA-Z0-9_-]*\.html$/', $_GET['include'])) {
  178. $open = @(string)file_get_contents(api_get_path(SYS_PATH).$this->home.$_GET['include']);
  179. $html = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
  180. } else {
  181. if (!empty($_SESSION['user_language_choice'])) {
  182. $user_selected_language = $_SESSION['user_language_choice'];
  183. } elseif (!empty($_SESSION['_user']['language'])) {
  184. $user_selected_language = $_SESSION['_user']['language'];
  185. } else {
  186. $user_selected_language = api_get_setting('platformLanguage');
  187. }
  188. if (!file_exists($this->home.'home_news_'.$user_selected_language.'.html')) {
  189. if (file_exists($this->home.'home_top.html')) {
  190. $home_top_temp = file($this->home.'home_top.html');
  191. } else {
  192. $home_top_temp = file($this->default_home.'home_top.html');
  193. }
  194. $home_top_temp = implode('', $home_top_temp);
  195. } else {
  196. if (file_exists($this->home.'home_top_'.$user_selected_language.'.html')) {
  197. $home_top_temp = file_get_contents($this->home.'home_top_'.$user_selected_language.'.html');
  198. } else {
  199. $home_top_temp = file_get_contents($this->home.'home_top.html');
  200. }
  201. }
  202. if (trim($home_top_temp) == '' && api_is_platform_admin()) {
  203. $home_top_temp = get_lang('PortalHomepageDefaultIntroduction');
  204. }
  205. $open = str_replace('{rel_path}', api_get_path(REL_PATH), $home_top_temp);
  206. $html = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
  207. }
  208. return $html;
  209. }
  210. function return_notice() {
  211. $sys_path = api_get_path(SYS_PATH);
  212. $user_selected_language = api_get_interface_language();
  213. $html = '';
  214. // Notice
  215. $home_notice = @(string)file_get_contents($sys_path.$this->home.'home_notice_'.$user_selected_language.'.html');
  216. if (empty($home_notice)) {
  217. $home_notice = @(string)file_get_contents($sys_path.$this->home.'home_notice.html');
  218. }
  219. if (!empty($home_notice)) {
  220. $home_notice = api_to_system_encoding($home_notice, api_detect_encoding(strip_tags($home_notice)));
  221. $home_notice = Display::div($home_notice, array('class' => 'homepage_notice'));
  222. $html = self::show_right_block(get_lang('Notice'), $home_notice, 'notice_block');
  223. }
  224. return $html;
  225. }
  226. function return_help() {
  227. $user_selected_language = api_get_interface_language();
  228. $sys_path = api_get_path(SYS_PATH);
  229. $platformLanguage = api_get_setting('platformLanguage');
  230. // Help section.
  231. /* Hide right menu "general" and other parts on anonymous right menu. */
  232. if (!isset($user_selected_language)) {
  233. $user_selected_language = $platformLanguage;
  234. }
  235. $html = null;
  236. $home_menu = @(string)file_get_contents($sys_path.$this->home.'home_menu_'.$user_selected_language.'.html');
  237. if (!empty($home_menu)) {
  238. $home_menu_content .= '<ul class="nav nav-list">';
  239. $home_menu_content .= api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
  240. $home_menu_content .= '</ul>';
  241. $html .= self::show_right_block(get_lang('MenuGeneral'), $home_menu_content, 'help_block');
  242. }
  243. return $html;
  244. }
  245. function return_skills_links() {
  246. $html = '';
  247. if (api_get_setting('allow_skills_tool') == 'true') {
  248. $content = '<ul class="nav nav-list">';
  249. $content .= Display::tag('li', Display::url(get_lang('MySkills'), api_get_path(WEB_CODE_PATH).'social/skills_wheel.php'));
  250. if (api_get_setting('allow_hr_skills_management') == 'true' || api_is_platform_admin()) {
  251. $content .= Display::tag('li', Display::url(get_lang('ManageSkills'), api_get_path(WEB_CODE_PATH).'admin/skills_wheel.php'));
  252. }
  253. $content .= '</ul>';
  254. $html = self::show_right_block(get_lang("Skills"), $content, 'skill_block');
  255. }
  256. return $html;
  257. }
  258. /**
  259. * Reacts on a failed login:
  260. * Displays an explanation with a link to the registration form.
  261. *
  262. * @version 1.0.1
  263. */
  264. function handle_login_failed() {
  265. $message = get_lang('InvalidId');
  266. if (!isset($_GET['error'])) {
  267. if (api_is_self_registration_allowed()) {
  268. $message = get_lang('InvalidForSelfRegistration');
  269. }
  270. } else {
  271. switch ($_GET['error']) {
  272. case '':
  273. if (api_is_self_registration_allowed()) {
  274. $message = get_lang('InvalidForSelfRegistration');
  275. }
  276. break;
  277. case 'account_expired':
  278. $message = get_lang('AccountExpired');
  279. break;
  280. case 'account_inactive':
  281. $message = get_lang('AccountInactive');
  282. break;
  283. case 'user_password_incorrect':
  284. $message = get_lang('InvalidId');
  285. break;
  286. case 'access_url_inactive':
  287. $message = get_lang('AccountURLInactive');
  288. break;
  289. case 'unrecognize_sso_origin':
  290. //$message = get_lang('SSOError');
  291. break;
  292. }
  293. }
  294. return Display::return_message($message, 'error');
  295. }
  296. /**
  297. * Display list of courses in a category.
  298. * (for anonymous users)
  299. *
  300. * @version 1.1
  301. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University - refactoring and code cleaning
  302. * @author Julio Montoya <gugli100@gmail.com>, Beeznest template modifs
  303. */
  304. function return_courses_in_categories() {
  305. $result = '';
  306. $ctok = $_SESSION['sec_token'];
  307. $stok = Security::get_token();
  308. // Initialization.
  309. $user_identified = (api_get_user_id() > 0 && !api_is_anonymous());
  310. $web_course_path = api_get_path(WEB_COURSE_PATH);
  311. $category = Database::escape_string($_GET['category']);
  312. $setting_show_also_closed_courses = api_get_setting('show_closed_courses') == 'true';
  313. // Database table definitions.
  314. $main_course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
  315. $main_category_table = Database :: get_main_table(TABLE_MAIN_CATEGORY);
  316. // Get list of courses in category $category.
  317. $sql_get_course_list = "SELECT * FROM $main_course_table cours
  318. WHERE category_code = '".Database::escape_string($_GET['category'])."'
  319. ORDER BY title, UPPER(visual_code)";
  320. // Showing only the courses of the current access_url_id.
  321. global $_configuration;
  322. if ($_configuration['multiple_access_urls']) {
  323. $url_access_id = api_get_current_access_url_id();
  324. if ($url_access_id != -1) {
  325. $tbl_url_rel_course = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
  326. $sql_get_course_list = "SELECT * FROM $main_course_table as course INNER JOIN $tbl_url_rel_course as url_rel_course
  327. ON (url_rel_course.course_code=course.code)
  328. WHERE access_url_id = $url_access_id AND category_code = '".Database::escape_string($_GET['category'])."' ORDER BY title, UPPER(visual_code)";
  329. }
  330. }
  331. // Removed: AND cours.visibility='".COURSE_VISIBILITY_OPEN_WORLD."'
  332. $sql_result_courses = Database::query($sql_get_course_list);
  333. while ($course_result = Database::fetch_array($sql_result_courses)) {
  334. $course_list[] = $course_result;
  335. }
  336. $platform_visible_courses = '';
  337. // $setting_show_also_closed_courses
  338. if ($user_identified) {
  339. if ($setting_show_also_closed_courses) {
  340. $platform_visible_courses = '';
  341. } else {
  342. $platform_visible_courses = " AND (t3.visibility='".COURSE_VISIBILITY_OPEN_WORLD."' OR t3.visibility='".COURSE_VISIBILITY_OPEN_PLATFORM."' )";
  343. }
  344. } else {
  345. if ($setting_show_also_closed_courses) {
  346. $platform_visible_courses = '';
  347. } else {
  348. $platform_visible_courses = " AND (t3.visibility='".COURSE_VISIBILITY_OPEN_WORLD."' )";
  349. }
  350. }
  351. $sqlGetSubCatList = "
  352. SELECT t1.name,t1.code,t1.parent_id,t1.children_count,COUNT(DISTINCT t3.code) AS nbCourse
  353. FROM $main_category_table t1
  354. LEFT JOIN $main_category_table t2 ON t1.code=t2.parent_id
  355. LEFT JOIN $main_course_table t3 ON (t3.category_code=t1.code $platform_visible_courses)
  356. WHERE t1.parent_id ". (empty ($category) ? "IS NULL" : "='$category'")."
  357. GROUP BY t1.name,t1.code,t1.parent_id,t1.children_count ORDER BY t1.tree_pos, t1.name";
  358. // Showing only the category of courses of the current access_url_id
  359. if ($_configuration['multiple_access_urls']) {
  360. $url_access_id = api_get_current_access_url_id();
  361. if ($url_access_id != -1) {
  362. $tbl_url_rel_course = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
  363. $sqlGetSubCatList = "
  364. SELECT t1.name,t1.code,t1.parent_id,t1.children_count,COUNT(DISTINCT t3.code) AS nbCourse
  365. FROM $main_category_table t1
  366. LEFT JOIN $main_category_table t2 ON t1.code=t2.parent_id
  367. LEFT JOIN $main_course_table t3 ON (t3.category_code=t1.code $platform_visible_courses)
  368. INNER JOIN $tbl_url_rel_course as url_rel_course
  369. ON (url_rel_course.course_code=t3.code)
  370. WHERE access_url_id = $url_access_id AND t1.parent_id ".(empty($category) ? "IS NULL" : "='$category'")."
  371. GROUP BY t1.name,t1.code,t1.parent_id,t1.children_count ORDER BY t1.tree_pos, t1.name";
  372. }
  373. }
  374. $resCats = Database::query($sqlGetSubCatList);
  375. $thereIsSubCat = false;
  376. if (Database::num_rows($resCats) > 0) {
  377. $htmlListCat = Display::page_header(get_lang('CatList'));
  378. $htmlListCat .= '<ul>';
  379. while ($catLine = Database::fetch_array($resCats)) {
  380. if ($catLine['code'] != $category) {
  381. $category_has_open_courses = self::category_has_open_courses($catLine['code']);
  382. if ($category_has_open_courses) {
  383. // The category contains courses accessible to anonymous visitors.
  384. $htmlListCat .= '<li>';
  385. $htmlListCat .= '<a href="'.api_get_self().'?category='.$catLine['code'].'">'.$catLine['name'].'</a>';
  386. if (api_get_setting('show_number_of_courses') == 'true') {
  387. $htmlListCat .= ' ('.$catLine['nbCourse'].' '.get_lang('Courses').')';
  388. }
  389. $htmlListCat .= "</li>";
  390. $thereIsSubCat = true;
  391. } elseif ($catLine['children_count'] > 0) {
  392. // The category has children, subcategories.
  393. $htmlListCat .= '<li>';
  394. $htmlListCat .= '<a href="'.api_get_self().'?category='.$catLine['code'].'">'.$catLine['name'].'</a>';
  395. $htmlListCat .= "</li>";
  396. $thereIsSubCat = true;
  397. }
  398. /* End changed code to eliminate the (0 courses) after empty categories. */
  399. elseif (api_get_setting('show_empty_course_categories') == 'true') {
  400. $htmlListCat .= '<li>';
  401. $htmlListCat .= $catLine['name'];
  402. $htmlListCat .= "</li>";
  403. $thereIsSubCat = true;
  404. } // Else don't set thereIsSubCat to true to avoid printing things if not requested.
  405. } else {
  406. $htmlTitre = '<p>';
  407. if (api_get_setting('show_back_link_on_top_of_tree') == 'true') {
  408. $htmlTitre .= '<a href="'.api_get_self().'">&lt;&lt; '.get_lang('BackToHomePage').'</a>';
  409. }
  410. if (!is_null($catLine['parent_id']) || (api_get_setting('show_back_link_on_top_of_tree') != 'true' && !is_null($catLine['code']))) {
  411. $htmlTitre .= '<a href="'.api_get_self().'?category='.$catLine['parent_id'].'">&lt;&lt; '.get_lang('Up').'</a>';
  412. }
  413. $htmlTitre .= "</p>";
  414. if ($category != "" && !is_null($catLine['code'])) {
  415. $htmlTitre .= '<h3>'.$catLine['name']."</h3>";
  416. } else {
  417. $htmlTitre .= '<h3>'.get_lang('Categories')."</h3>";
  418. }
  419. }
  420. }
  421. $htmlListCat .= "</ul>";
  422. }
  423. $result .= $htmlTitre;
  424. if ($thereIsSubCat) {
  425. $result .= $htmlListCat;
  426. }
  427. while ($categoryName = Database::fetch_array($resCats)) {
  428. $result .= '<h3>' . $categoryName['name'] . "</h3>\n";
  429. }
  430. $numrows = Database::num_rows($sql_result_courses);
  431. $courses_list_string = '';
  432. $courses_shown = 0;
  433. if ($numrows > 0) {
  434. $courses_list_string .= Display::page_header(get_lang('CourseList'));
  435. $courses_list_string .= "<ul>";
  436. if (api_get_user_id()) {
  437. $courses_of_user = self::get_courses_of_user(api_get_user_id());
  438. }
  439. foreach ($course_list as $course) {
  440. // $setting_show_also_closed_courses
  441. if (!$setting_show_also_closed_courses) {
  442. // If we do not show the closed courses
  443. // we only show the courses that are open to the world (to everybody)
  444. // and the courses that are open to the platform (if the current user is a registered user.
  445. if( ($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM) || ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD)) {
  446. $courses_shown++;
  447. $courses_list_string .= "<li>\n";
  448. $courses_list_string .= '<a href="'.$web_course_path.$course['directory'].'/">'.$course['title'].'</a><br />';
  449. $course_details = array();
  450. if (api_get_setting('display_coursecode_in_courselist') == 'true') {
  451. $course_details[] = $course['visual_code'];
  452. }
  453. if (api_get_setting('display_teacher_in_courselist') == 'true') {
  454. $course_details[] = $course['tutor_name'];
  455. }
  456. if (api_get_setting('show_different_course_language') == 'true' && $course['course_language'] != api_get_setting('platformLanguage')) {
  457. $course_details[] = $course['course_language'];
  458. }
  459. $courses_list_string .= implode(' - ', $course_details);
  460. $courses_list_string .= "</li>\n";
  461. }
  462. } else {
  463. // We DO show the closed courses.
  464. // The course is accessible if (link to the course homepage):
  465. // 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);
  466. // 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);
  467. // 3. the user is logged in and the user is subscribed to the course and the course visibility is not COURSE_VISIBILITY_CLOSED;
  468. // 4. the user is logged in and the user is course admin of te course (regardless of the course visibility setting);
  469. // 5. the user is the platform admin api_is_platform_admin().
  470. //
  471. $courses_shown++;
  472. $courses_list_string .= "<li>\n";
  473. if ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD
  474. || ($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM)
  475. || ($user_identified && key_exists($course['code'], $courses_of_user) && $course['visibility'] != COURSE_VISIBILITY_CLOSED)
  476. || $courses_of_user[$course['code']]['status'] == '1'
  477. || api_is_platform_admin()) {
  478. $courses_list_string .= '<a href="'.$web_course_path.$course['directory'].'/">';
  479. }
  480. $courses_list_string .= $course['title'];
  481. if ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD
  482. || ($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM)
  483. || ($user_identified && key_exists($course['code'], $courses_of_user) && $course['visibility'] != COURSE_VISIBILITY_CLOSED)
  484. || $courses_of_user[$course['code']]['status'] == '1'
  485. || api_is_platform_admin()) {
  486. $courses_list_string .= '</a><br />';
  487. }
  488. $course_details = array();
  489. if (api_get_setting('display_coursecode_in_courselist') == 'true') {
  490. $course_details[] = $course['visual_code'];
  491. }
  492. // if (api_get_setting('display_coursecode_in_courselist') == 'true' && api_get_setting('display_teacher_in_courselist') == 'true') {
  493. // $courses_list_string .= ' - ';
  494. // }
  495. if (api_get_setting('display_teacher_in_courselist') == 'true') {
  496. $course_details[] = $course['tutor_name'];
  497. }
  498. if (api_get_setting('show_different_course_language') == 'true' && $course['course_language'] != api_get_setting('platformLanguage')) {
  499. $course_details[] = $course['course_language'];
  500. }
  501. if (api_get_setting('show_different_course_language') == 'true' && $course['course_language'] != api_get_setting('platformLanguage')) {
  502. $course_details[] = $course['course_language'];
  503. }
  504. $courses_list_string .= implode(' - ', $course_details);
  505. // We display a subscription link if:
  506. // 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
  507. // 2.
  508. if ($user_identified && !key_exists($course['code'], $courses_of_user)) {
  509. if ($course['subscribe'] == '1') {
  510. $courses_list_string .= '<form action="main/auth/courses.php?action=subscribe&category='.Security::remove_XSS($_GET['category']).'" method="post">';
  511. $courses_list_string .= '<input type="hidden" name="sec_token" value="'.$stok.'">';
  512. $courses_list_string .= '<input type="hidden" name="subscribe" value="'.$course['code'].'" />';
  513. $courses_list_string .= '<input type="image" name="unsub" src="main/img/enroll.gif" alt="'.get_lang('Subscribe').'" />'.get_lang('Subscribe').'</form>';
  514. } else {
  515. $courses_list_string .= '<br />'.get_lang('SubscribingNotAllowed');
  516. }
  517. }
  518. $courses_list_string .= "</li>";
  519. } //end else
  520. } // end foreach
  521. $courses_list_string .= "</ul>";
  522. }
  523. if ($courses_shown > 0) {
  524. // Only display the list of courses and categories if there was more than
  525. // 0 courses visible to the world (we're in the anonymous list here).
  526. $result .= $courses_list_string;
  527. }
  528. if ($category != '') {
  529. $result .= '<p><a href="'.api_get_self().'"> ' . Display :: return_icon('back.png', get_lang('BackToHomePage')) . get_lang('BackToHomePage') . '</a></p>';
  530. }
  531. return $result;
  532. }
  533. /**
  534. * retrieves all the courses that the user has already subscribed to
  535. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  536. * @param int $user_id: the id of the user
  537. * @return array an array containing all the information of the courses of the given user
  538. */
  539. function get_courses_of_user($user_id) {
  540. $table_course = Database::get_main_table(TABLE_MAIN_COURSE);
  541. $table_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  542. // Secondly we select the courses that are in a category (user_course_cat <> 0) and sort these according to the sort of the category
  543. $user_id = intval($user_id);
  544. $sql_select_courses = "SELECT course.code k, course.visual_code vc, course.subscribe subscr, course.unsubscribe unsubscr,
  545. course.title i, course.tutor_name t, course.db_name db, course.directory dir, course_rel_user.status status,
  546. course_rel_user.sort sort, course_rel_user.user_course_cat user_course_cat
  547. FROM $table_course course,
  548. $table_course_user course_rel_user
  549. WHERE course.code = course_rel_user.course_code
  550. AND course_rel_user.user_id = '".$user_id."'
  551. AND course_rel_user.relation_type<>".COURSE_RELATION_TYPE_RRHH."
  552. ORDER BY course_rel_user.sort ASC";
  553. $result = Database::query($sql_select_courses);
  554. $courses = array();
  555. while ($row = Database::fetch_array($result)) {
  556. // We only need the database name of the course.
  557. $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']);
  558. }
  559. return $courses;
  560. }
  561. /**
  562. * @todo use the template system
  563. */
  564. function show_right_block($title, $content, $id = null, $params = null) {
  565. if (!empty($id)) {
  566. $params['id'] = $id;
  567. }
  568. $params['class'] = 'well sidebar-nav';
  569. $html = null;
  570. if (!empty($title)) {
  571. $html.= '<h4>'.$title.'</h4>';
  572. }
  573. $html.= $content;
  574. $html = Display::div($html, $params);
  575. return $html;
  576. }
  577. /**
  578. * Adds a form to let users login
  579. * @version 1.1
  580. */
  581. function display_login_form() {
  582. $form = new FormValidator('formLogin', 'POST', null, null, array('class'=>'form-vertical'));
  583. // 'placeholder'=>get_lang('UserName')
  584. //'autocomplete'=>"off",
  585. $form->addElement('text', 'login', get_lang('UserName'), array('class' => 'span2 autocapitalize_off', 'autofocus' => 'autofocus'));
  586. $form->addElement('password', 'password', get_lang('Pass'), array('class' => 'span2'));
  587. $form->addElement('style_submit_button','submitAuth', get_lang('LoginEnter'), array('class' => 'btn'));
  588. $html = $form->return_form();
  589. if (api_get_setting('openid_authentication') == 'true') {
  590. include_once 'main/auth/openid/login.php';
  591. $html .= '<div>'.openid_form().'</div>';
  592. }
  593. return $html;
  594. }
  595. function return_search_block() {
  596. $html = '';
  597. if (api_get_setting('search_enabled') == 'true') {
  598. $html .= '<div class="searchbox">';
  599. $search_btn = get_lang('Search');
  600. $search_content = '<br />
  601. <form action="main/search/" method="post">
  602. <input type="text" id="query" class="span2" name="query" value="" />
  603. <button class="save" type="submit" name="submit" value="'.$search_btn.'" />'.$search_btn.' </button>
  604. </form></div>';
  605. $html .= self::show_right_block(get_lang('Search'), $search_content, 'search_block');
  606. }
  607. return $html;
  608. }
  609. function return_classes_block() {
  610. $html = '';
  611. if (api_get_setting('show_groups_to_users') == 'true') {
  612. require_once api_get_path(LIBRARY_PATH).'usergroup.lib.php';
  613. $usergroup = new Usergroup();
  614. $usergroup_list = $usergroup->get_usergroup_by_user(api_get_user_id());
  615. $classes = '';
  616. if (!empty($usergroup_list)) {
  617. foreach($usergroup_list as $group_id) {
  618. $data = $usergroup->get($group_id);
  619. $data['name'] = Display::url($data['name'], api_get_path(WEB_CODE_PATH).'user/classes.php?id='.$data['id']);
  620. $classes .= Display::tag('li', $data['name']);
  621. }
  622. }
  623. if (api_is_platform_admin()) {
  624. $classes .= Display::tag('li', Display::url(get_lang('AddClasses') ,api_get_path(WEB_CODE_PATH).'admin/usergroups.php?action=add'));
  625. }
  626. if (!empty($classes)) {
  627. $classes = Display::tag('ul', $classes, array('class'=>'nav nav-list'));
  628. $html .= self::show_right_block(get_lang('Classes'), $classes, 'classes_block');
  629. }
  630. }
  631. return $html;
  632. }
  633. function return_reservation_block() {
  634. $html = '';
  635. if (api_get_setting('allow_reservation') == 'true' && api_is_allowed_to_create_course()) {
  636. $booking_content .='<ul class="nav nav-list">';
  637. $booking_content .='<a href="main/reservation/reservation.php">'.get_lang('ManageReservations').'</a><br />';
  638. $booking_content .='</ul>';
  639. $html .= self::show_right_block(get_lang('Booking'), $booking_content, 'reservation_block');
  640. }
  641. return $html;
  642. }
  643. function return_user_image_block() {
  644. //Always show the user image
  645. $img_array = UserManager::get_user_picture_path_by_id(api_get_user_id(), 'web', true, true);
  646. $no_image = false;
  647. if ($img_array['file'] == 'unknown.jpg') {
  648. $no_image = true;
  649. }
  650. $img_array = UserManager::get_picture_user(api_get_user_id(), $img_array['file'], 50, USER_IMAGE_SIZE_MEDIUM, ' width="90" height="90" ');
  651. if (api_get_setting('allow_social_tool') == 'true') {
  652. if (!$no_image) {
  653. $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>';
  654. } else {
  655. $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>';
  656. }
  657. }
  658. $html = self::show_right_block(null, $profile_content, 'user_image_block', array('style' => 'text-align:center;'));
  659. return $html;
  660. }
  661. function return_profile_block() {
  662. $html = '';
  663. $user_id = api_get_user_id();
  664. if (empty($user_id)) {
  665. return;
  666. }
  667. $profile_content .= '<ul class="nav nav-list">';
  668. // @todo Add a platform setting to add the user image.
  669. if (api_get_setting('allow_message_tool') == 'true') {
  670. require_once api_get_path(LIBRARY_PATH).'group_portal_manager.lib.php';
  671. // New messages.
  672. $number_of_new_messages = MessageManager::get_new_messages();
  673. // New contact invitations.
  674. $number_of_new_messages_of_friend = SocialManager::get_message_number_invitation_by_user_id(api_get_user_id());
  675. // New group invitations sent by a moderator.
  676. $group_pending_invitations = GroupPortalManager::get_groups_by_user(api_get_user_id(), GROUP_USER_PERMISSION_PENDING_INVITATION, false);
  677. $group_pending_invitations = count($group_pending_invitations);
  678. $total_invitations = $number_of_new_messages_of_friend + $group_pending_invitations;
  679. $cant_msg = Display::badge($number_of_new_messages);
  680. $link = '';
  681. if (api_get_setting('allow_social_tool') == 'true') {
  682. $link = '?f=social';
  683. }
  684. $profile_content .= '<li><a href="'.api_get_path(WEB_PATH).'main/messages/inbox.php'.$link.'">'.get_lang('Inbox').$cant_msg.' </a></li>';
  685. $profile_content .= '<li><a href="'.api_get_path(WEB_PATH).'main/messages/new_message.php'.$link.'">'.get_lang('Compose').' </a></li>';
  686. if (api_get_setting('allow_social_tool') == 'true') {
  687. $total_invitations = Display::badge($total_invitations);
  688. $profile_content .= '<li><a href="'.api_get_path(WEB_PATH).'main/social/invitations.php">'.get_lang('PendingInvitations').$total_invitations.'</a></li>';
  689. }
  690. $profile_content .= '<li><a href="'.api_get_path(WEB_PATH).'main/auth/profile.php">'.get_lang('EditProfile').'</a></li>';
  691. }
  692. $profile_content .= '</ul>';
  693. $html = self::show_right_block(get_lang('Profile'), $profile_content, 'profile_block');
  694. return $html;
  695. }
  696. function return_navigation_links() {
  697. $html = '';
  698. // Deleting the myprofile link.
  699. if (api_get_setting('allow_social_tool') == 'true') {
  700. unset($this->tpl->menu_navigation['myprofile']);
  701. }
  702. // Main navigation section.
  703. // Tabs that are deactivated are added here.
  704. if (!empty($this->tpl->menu_navigation)) {
  705. $content = '<ul class="nav nav-list">';
  706. foreach ($this->tpl->menu_navigation as $section => $navigation_info) {
  707. $current = $section == $GLOBALS['this_section'] ? ' id="current"' : '';
  708. $content .= '<li'.$current.'>';
  709. $content .= '<a href="'.$navigation_info['url'].'" target="_self">'.$navigation_info['title'].'</a>';
  710. $content .= '</li>';
  711. }
  712. $content .= '</ul>';
  713. $html = self::show_right_block(get_lang('MainNavigation'), $content, 'navigation_link_block');
  714. }
  715. return $html;
  716. }
  717. function return_course_block() {
  718. $html = '';
  719. $show_create_link = false;
  720. $show_course_link = false;
  721. $display_add_course_link = api_is_allowed_to_create_course() && ($_SESSION['studentview'] != 'studentenview');
  722. if ($display_add_course_link) {
  723. $show_create_link = true;
  724. }
  725. if (api_is_platform_admin() || api_is_course_admin() || api_is_allowed_to_create_course()) {
  726. $show_course_link = true;
  727. } else {
  728. if (api_get_setting('allow_students_to_browse_courses') == 'true') {
  729. $show_course_link = true;
  730. }
  731. }
  732. // My account section
  733. $my_account_content = '<ul class="nav nav-list">';
  734. if ($show_create_link) {
  735. $my_account_content .= '<li><a href="main/create_course/add_course.php" class="add course">'.(api_get_setting('course_validation') == 'true' ? get_lang('CreateCourseRequest') : get_lang('CourseCreate')).'</a></li>';
  736. }
  737. //Sort courses
  738. $url = api_get_path(WEB_CODE_PATH).'auth/courses.php?action=sortmycourses';
  739. $my_account_content .= '<li>'.Display::url(get_lang('SortMyCourses'), $url, array('class' => 'sort course')).'</li>';
  740. //Course management
  741. if ($show_course_link) {
  742. if (!api_is_drh()) {
  743. $my_account_content .= '<li><a href="main/auth/courses.php" class="list course">'.get_lang('CourseCatalog').'</a></li>';
  744. if (isset($_GET['history']) && intval($_GET['history']) == 1) {
  745. $my_account_content .= '<li><a href="user_portal.php">'.get_lang('DisplayTrainingList').'</a></li>';
  746. } else {
  747. $my_account_content .= '<li><a href="user_portal.php?history=1" class="history course">'.get_lang('HistoryTrainingSessions').'</a></li>';
  748. }
  749. } else {
  750. $my_account_content .= '<li><a href="main/dashboard/index.php">'.get_lang('Dashboard').'</a></li>';
  751. }
  752. }
  753. $my_account_content .= '</ul>';
  754. if (!empty($my_account_content)) {
  755. $html = self::show_right_block(get_lang('Courses'), $my_account_content, 'course_block');
  756. }
  757. return $html;
  758. }
  759. /**
  760. * The most important function here, prints the session and course list (user_portal.php)
  761. *
  762. * */
  763. function return_courses_and_sessions($user_id) {
  764. $session_categories = array();
  765. $load_history = (isset($_GET['history']) && intval($_GET['history']) == 1) ? true : false;
  766. if ($load_history) {
  767. //Load sessions in category in *history*
  768. $session_categories = UserManager::get_sessions_by_category($user_id, true);
  769. } else {
  770. //Load sessions in category
  771. $session_categories = UserManager::get_sessions_by_category($user_id, false);
  772. }
  773. $html = '';
  774. //Showing history title
  775. if ($load_history) {
  776. $html .= Display::page_subheader(get_lang('HistoryTrainingSession'));
  777. if (empty($session_categories)) {
  778. $html .= get_lang('YouDoNotHaveAnySessionInItsHistory');
  779. }
  780. }
  781. $courses_html = '';
  782. $special_courses = '';
  783. // If we're not in the history view...
  784. if (!isset($_GET['history'])) {
  785. //Display special courses
  786. $special_courses = CourseManager::display_special_courses($user_id, $this->load_directories_preview);
  787. //Display courses
  788. $courses_html .= CourseManager::display_courses($user_id, $this->load_directories_preview);
  789. }
  790. $sessions_with_category = '';
  791. $sessions_with_no_category = '';
  792. if (is_array($session_categories)) {
  793. foreach ($session_categories as $session_category) {
  794. $session_category_id = $session_category['session_category']['id'];
  795. // Sessions and courses that are not in a session category
  796. if ($session_category_id == 0) {
  797. // Independent sessions
  798. foreach ($session_category['sessions'] as $session) {
  799. $session_id = $session['session_id'];
  800. // Don't show empty sessions.
  801. if (count($session['courses']) < 1) {
  802. continue;
  803. }
  804. // Courses inside the current session.
  805. $date_session_start = $session['date_start'];
  806. $days_access_before_beginning = $session['nb_days_access_before_beginning'] * 24 * 3600;
  807. $session_now = time();
  808. $html_courses_session = '';
  809. $count_courses_session = 0;
  810. foreach ($session['courses'] as $course) {
  811. $is_coach_course = api_is_coach($session_id, $course['code']);
  812. $allowed_time = 0;
  813. if ($date_session_start != '0000-00-00') {
  814. if ($is_coach_course) {
  815. $allowed_time = api_strtotime($date_session_start) - $days_access_before_beginning;
  816. } else {
  817. $allowed_time = api_strtotime($date_session_start);
  818. }
  819. }
  820. if ($session_now > $allowed_time) {
  821. //read only and accesible
  822. if (api_get_setting('hide_courses_in_sessions') == 'false') {
  823. $c = CourseManager :: get_logged_user_course_html($course, $session_id, 'session_course_item', true, $this->load_directories_preview);
  824. $html_courses_session .= $c[1];
  825. }
  826. $count_courses_session++;
  827. }
  828. }
  829. if ($count_courses_session > 0) {
  830. $params = array();
  831. $session_box = Display :: get_session_title_box($session_id);
  832. $params['icon'] = Display::return_icon('window_list.png', $session_box['title'], array('id' => 'session_img_'.$session_id), ICON_SIZE_LARGE);
  833. $extra_info = !empty($session_box['coach']) ? $session_box['coach'] : null;
  834. $extra_info .= !empty($session_box['coach']) ? ' - '.$session_box['dates'] : $session_box['dates'];
  835. if (api_is_drh()) {
  836. $session_link = $session_box['title'];
  837. $params['link'] = null;
  838. } else {
  839. $session_link = Display::tag('a', $session_box['title'], array('href'=>api_get_path(WEB_CODE_PATH).'session/index.php?session_id='.$session_id));
  840. $params['link'] = api_get_path(WEB_CODE_PATH).'session/index.php?session_id='.$session_id;
  841. }
  842. $params['title'] = $session_link;
  843. $params['subtitle'] = $extra_info;
  844. $params['right_actions'] = '';
  845. if (api_is_platform_admin()) {
  846. $params['right_actions'] .= '<a href="'.api_get_path(WEB_CODE_PATH).'admin/resume_session.php?id_session='.$session_id.'">';
  847. $params['right_actions'] .= Display::return_icon('edit.png', get_lang('Edit'), array('align' => 'absmiddle'), ICON_SIZE_SMALL).'</a>';
  848. }
  849. if (api_get_setting('hide_courses_in_sessions') == 'false') {
  850. // $params['extra'] .= $html_courses_session;
  851. }
  852. $sessions_with_no_category .= CourseManager::course_item_parent(CourseManager::course_item_html($params, true), $html_courses_session);
  853. }
  854. }
  855. } else {
  856. // All sessions included in
  857. $count_courses_session = 0;
  858. $html_sessions = '';
  859. foreach ($session_category['sessions'] as $session) {
  860. $session_id = $session['session_id'];
  861. //var_dump($session);var_dump($session_category);
  862. // Don't show empty sessions.
  863. if (count($session['courses']) < 1) {
  864. continue;
  865. }
  866. $date_session_start = $session['date_start'];
  867. //api_get_session_visibility($session_id);
  868. $days_access_before_beginning = $session['nb_days_access_before_beginning'] * 24 * 3600;
  869. $session_now = time();
  870. $html_courses_session = '';
  871. $count = 0;
  872. foreach ($session['courses'] as $course) {
  873. $is_coach_course = api_is_coach($session_id, $course['code']);
  874. if ($is_coach_course) {
  875. $allowed_time = api_strtotime($date_session_start) - $days_access_before_beginning;
  876. } else {
  877. $allowed_time = api_strtotime($date_session_start);
  878. }
  879. if ($session_now > $allowed_time) {
  880. $c = CourseManager :: get_logged_user_course_html($course, $session_id, 'session_course_item');
  881. $html_courses_session .= $c[1];
  882. $count_courses_session++;
  883. $count++;
  884. }
  885. }
  886. $params = array();
  887. if ($count > 0) {
  888. $session_box = Display :: get_session_title_box($session_id);
  889. $params['icon'] = Display::return_icon('window_list.png', $session_box['title'], array('width' => '48px', 'align' => 'absmiddle', 'id' => 'session_img_'.$session_id)) . ' ';
  890. if (api_is_drh()) {
  891. $session_link = $session_box['title'];
  892. $params['link'] = null;
  893. } else {
  894. $session_link = Display::tag('a', $session_box['title'], array('href'=>api_get_path(WEB_CODE_PATH).'session/index.php?session_id='.$session_id));
  895. $params['link'] = api_get_path(WEB_CODE_PATH).'session/index.php?session_id='.$session_id;
  896. }
  897. $params['title'] .= $session_link;
  898. $params['subtitle'] = (!empty($session_box['coach']) ? $session_box['coach'].' | ' : '').$session_box['dates'];
  899. if (api_is_platform_admin()) {
  900. $params['right_actions'] .= '<a href="'.api_get_path(WEB_CODE_PATH).'admin/resume_session.php?id_session='.$session_id.'">'.Display::return_icon('edit.png', get_lang('Edit'), array('align' => 'absmiddle'), ICON_SIZE_SMALL).'</a>';
  901. }
  902. $html_sessions .= CourseManager::course_item_html($params, true).$html_courses_session;
  903. }
  904. }
  905. if ($count_courses_session > 0) {
  906. $params = array();
  907. $params['icon'] = Display::return_icon('folder_blue.png', $session_category['session_category']['name'], array(), ICON_SIZE_LARGE);
  908. if (api_is_platform_admin()) {
  909. $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>';
  910. }
  911. $params['title'] .= $session_category['session_category']['name'];
  912. if (api_is_platform_admin()) {
  913. $params['link'] = api_get_path(WEB_CODE_PATH).'admin/session_category_edit.php?&id='.$session_category['session_category']['id'];
  914. }
  915. $session_category_start_date = $session_category['session_category']['date_start'];
  916. $session_category_end_date = $session_category['session_category']['date_end'];
  917. 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' ) {
  918. $params['subtitle'] = sprintf(get_lang('FromDateXToDateY'), $session_category['session_category']['date_start'], $session_category['session_category']['date_end']);
  919. } else {
  920. if (!empty($session_category_start_date) && $session_category_start_date != '0000-00-00') {
  921. $params['subtitle'] = get_lang('From').' '.$session_category_start_date;
  922. }
  923. if (!empty($session_category_end_date) && $session_category_end_date != '0000-00-00') {
  924. $params['subtitle'] = get_lang('Until').' '.$session_category_end_date;
  925. }
  926. }
  927. $sessions_with_category .= CourseManager::course_item_parent(CourseManager::course_item_html($params, true), $html_sessions);
  928. }
  929. }
  930. }
  931. }
  932. return $sessions_with_category.$sessions_with_no_category.$courses_html.$special_courses;
  933. }
  934. /**
  935. * Shows a welcome message when the user doesn't have any content in the course list
  936. */
  937. function return_welcome_to_course_block() {
  938. $tpl = $this->tpl->get_template('layout/welcome_to_course.tpl');
  939. $course_catalog_url = api_get_path(WEB_CODE_PATH).'auth/courses.php';
  940. $course_list_url = api_get_path(WEB_PATH).'user_portal.php';
  941. $this->tpl->assign('course_catalog_url', $course_catalog_url);
  942. $this->tpl->assign('course_list_url', $course_list_url);
  943. $this->tpl->assign('course_catalog_link', Display::url(get_lang('here'), $course_catalog_url));
  944. $this->tpl->assign('course_list_link', Display::url(get_lang('here'), $course_list_url));
  945. return $this->tpl->fetch($tpl);
  946. }
  947. function return_hot_courses() {
  948. return CourseManager::return_hot_courses();
  949. }
  950. }