userportal.lib.php 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081
  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_tree.php'));
  250. $content .= '</ul>';
  251. $html = self::show_right_block(get_lang("Skills"), $content, 'skill_block');
  252. }
  253. return $html;
  254. }
  255. /**
  256. * Reacts on a failed login:
  257. * Displays an explanation with a link to the registration form.
  258. *
  259. * @version 1.0.1
  260. */
  261. function handle_login_failed() {
  262. $message = get_lang('InvalidId');
  263. if (!isset($_GET['error'])) {
  264. if (api_is_self_registration_allowed()) {
  265. $message = get_lang('InvalidForSelfRegistration');
  266. }
  267. } else {
  268. switch ($_GET['error']) {
  269. case '':
  270. if (api_is_self_registration_allowed()) {
  271. $message = get_lang('InvalidForSelfRegistration');
  272. }
  273. break;
  274. case 'account_expired':
  275. $message = get_lang('AccountExpired');
  276. break;
  277. case 'account_inactive':
  278. $message = get_lang('AccountInactive');
  279. break;
  280. case 'user_password_incorrect':
  281. $message = get_lang('InvalidId');
  282. break;
  283. case 'access_url_inactive':
  284. $message = get_lang('AccountURLInactive');
  285. break;
  286. case 'unrecognize_sso_origin':
  287. //$message = get_lang('SSOError');
  288. break;
  289. }
  290. }
  291. return Display::return_message($message, 'error');
  292. }
  293. /**
  294. * Display list of courses in a category.
  295. * (for anonymous users)
  296. *
  297. * @version 1.1
  298. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University - refactoring and code cleaning
  299. * @author Julio Montoya <gugli100@gmail.com>, Beeznest template modifs
  300. */
  301. function return_courses_in_categories() {
  302. $result = '';
  303. $ctok = $_SESSION['sec_token'];
  304. $stok = Security::get_token();
  305. // Initialization.
  306. $user_identified = (api_get_user_id() > 0 && !api_is_anonymous());
  307. $web_course_path = api_get_path(WEB_COURSE_PATH);
  308. $category = Database::escape_string($_GET['category']);
  309. $setting_show_also_closed_courses = api_get_setting('show_closed_courses') == 'true';
  310. // Database table definitions.
  311. $main_course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
  312. $main_category_table = Database :: get_main_table(TABLE_MAIN_CATEGORY);
  313. // Get list of courses in category $category.
  314. $sql_get_course_list = "SELECT * FROM $main_course_table cours
  315. WHERE category_code = '".Database::escape_string($_GET['category'])."'
  316. ORDER BY title, UPPER(visual_code)";
  317. // Showing only the courses of the current access_url_id.
  318. global $_configuration;
  319. if ($_configuration['multiple_access_urls']) {
  320. $url_access_id = api_get_current_access_url_id();
  321. if ($url_access_id != -1) {
  322. $tbl_url_rel_course = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
  323. $sql_get_course_list = "SELECT * FROM $main_course_table as course INNER JOIN $tbl_url_rel_course as url_rel_course
  324. ON (url_rel_course.course_code=course.code)
  325. WHERE access_url_id = $url_access_id AND category_code = '".Database::escape_string($_GET['category'])."' ORDER BY title, UPPER(visual_code)";
  326. }
  327. }
  328. // Removed: AND cours.visibility='".COURSE_VISIBILITY_OPEN_WORLD."'
  329. $sql_result_courses = Database::query($sql_get_course_list);
  330. while ($course_result = Database::fetch_array($sql_result_courses)) {
  331. $course_list[] = $course_result;
  332. }
  333. $platform_visible_courses = '';
  334. // $setting_show_also_closed_courses
  335. if ($user_identified) {
  336. if ($setting_show_also_closed_courses) {
  337. $platform_visible_courses = '';
  338. } else {
  339. $platform_visible_courses = " AND (t3.visibility='".COURSE_VISIBILITY_OPEN_WORLD."' OR t3.visibility='".COURSE_VISIBILITY_OPEN_PLATFORM."' )";
  340. }
  341. } else {
  342. if ($setting_show_also_closed_courses) {
  343. $platform_visible_courses = '';
  344. } else {
  345. $platform_visible_courses = " AND (t3.visibility='".COURSE_VISIBILITY_OPEN_WORLD."' )";
  346. }
  347. }
  348. $sqlGetSubCatList = "
  349. SELECT t1.name,t1.code,t1.parent_id,t1.children_count,COUNT(DISTINCT t3.code) AS nbCourse
  350. FROM $main_category_table t1
  351. LEFT JOIN $main_category_table t2 ON t1.code=t2.parent_id
  352. LEFT JOIN $main_course_table t3 ON (t3.category_code=t1.code $platform_visible_courses)
  353. WHERE t1.parent_id ". (empty ($category) ? "IS NULL" : "='$category'")."
  354. GROUP BY t1.name,t1.code,t1.parent_id,t1.children_count ORDER BY t1.tree_pos, t1.name";
  355. // Showing only the category of courses of the current access_url_id
  356. if ($_configuration['multiple_access_urls']) {
  357. $url_access_id = api_get_current_access_url_id();
  358. if ($url_access_id != -1) {
  359. $tbl_url_rel_course = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
  360. $sqlGetSubCatList = "
  361. SELECT t1.name,t1.code,t1.parent_id,t1.children_count,COUNT(DISTINCT t3.code) AS nbCourse
  362. FROM $main_category_table t1
  363. LEFT JOIN $main_category_table t2 ON t1.code=t2.parent_id
  364. LEFT JOIN $main_course_table t3 ON (t3.category_code=t1.code $platform_visible_courses)
  365. INNER JOIN $tbl_url_rel_course as url_rel_course
  366. ON (url_rel_course.course_code=t3.code)
  367. WHERE access_url_id = $url_access_id AND t1.parent_id ".(empty($category) ? "IS NULL" : "='$category'")."
  368. GROUP BY t1.name,t1.code,t1.parent_id,t1.children_count ORDER BY t1.tree_pos, t1.name";
  369. }
  370. }
  371. $resCats = Database::query($sqlGetSubCatList);
  372. $thereIsSubCat = false;
  373. if (Database::num_rows($resCats) > 0) {
  374. $htmlListCat = Display::page_header(get_lang('CatList'));
  375. $htmlListCat .= '<ul>';
  376. while ($catLine = Database::fetch_array($resCats)) {
  377. if ($catLine['code'] != $category) {
  378. $category_has_open_courses = self::category_has_open_courses($catLine['code']);
  379. if ($category_has_open_courses) {
  380. // The category contains courses accessible to anonymous visitors.
  381. $htmlListCat .= '<li>';
  382. $htmlListCat .= '<a href="'.api_get_self().'?category='.$catLine['code'].'">'.$catLine['name'].'</a>';
  383. if (api_get_setting('show_number_of_courses') == 'true') {
  384. $htmlListCat .= ' ('.$catLine['nbCourse'].' '.get_lang('Courses').')';
  385. }
  386. $htmlListCat .= "</li>";
  387. $thereIsSubCat = true;
  388. } elseif ($catLine['children_count'] > 0) {
  389. // The category has children, subcategories.
  390. $htmlListCat .= '<li>';
  391. $htmlListCat .= '<a href="'.api_get_self().'?category='.$catLine['code'].'">'.$catLine['name'].'</a>';
  392. $htmlListCat .= "</li>";
  393. $thereIsSubCat = true;
  394. }
  395. /* End changed code to eliminate the (0 courses) after empty categories. */
  396. elseif (api_get_setting('show_empty_course_categories') == 'true') {
  397. $htmlListCat .= '<li>';
  398. $htmlListCat .= $catLine['name'];
  399. $htmlListCat .= "</li>";
  400. $thereIsSubCat = true;
  401. } // Else don't set thereIsSubCat to true to avoid printing things if not requested.
  402. } else {
  403. $htmlTitre = '<p>';
  404. if (api_get_setting('show_back_link_on_top_of_tree') == 'true') {
  405. $htmlTitre .= '<a href="'.api_get_self().'">&lt;&lt; '.get_lang('BackToHomePage').'</a>';
  406. }
  407. if (!is_null($catLine['parent_id']) || (api_get_setting('show_back_link_on_top_of_tree') != 'true' && !is_null($catLine['code']))) {
  408. $htmlTitre .= '<a href="'.api_get_self().'?category='.$catLine['parent_id'].'">&lt;&lt; '.get_lang('Up').'</a>';
  409. }
  410. $htmlTitre .= "</p>";
  411. if ($category != "" && !is_null($catLine['code'])) {
  412. $htmlTitre .= '<h3>'.$catLine['name']."</h3>";
  413. } else {
  414. $htmlTitre .= '<h3>'.get_lang('Categories')."</h3>";
  415. }
  416. }
  417. }
  418. $htmlListCat .= "</ul>";
  419. }
  420. $result .= $htmlTitre;
  421. if ($thereIsSubCat) {
  422. $result .= $htmlListCat;
  423. }
  424. while ($categoryName = Database::fetch_array($resCats)) {
  425. $result .= '<h3>' . $categoryName['name'] . "</h3>\n";
  426. }
  427. $numrows = Database::num_rows($sql_result_courses);
  428. $courses_list_string = '';
  429. $courses_shown = 0;
  430. if ($numrows > 0) {
  431. $courses_list_string .= Display::page_header(get_lang('CourseList'));
  432. $courses_list_string .= "<ul>";
  433. if (api_get_user_id()) {
  434. $courses_of_user = self::get_courses_of_user(api_get_user_id());
  435. }
  436. foreach ($course_list as $course) {
  437. // $setting_show_also_closed_courses
  438. if (!$setting_show_also_closed_courses) {
  439. // If we do not show the closed courses
  440. // we only show the courses that are open to the world (to everybody)
  441. // and the courses that are open to the platform (if the current user is a registered user.
  442. if( ($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM) || ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD)) {
  443. $courses_shown++;
  444. $courses_list_string .= "<li>\n";
  445. $courses_list_string .= '<a href="'.$web_course_path.$course['directory'].'/">'.$course['title'].'</a><br />';
  446. $course_details = array();
  447. if (api_get_setting('display_coursecode_in_courselist') == 'true') {
  448. $course_details[] = $course['visual_code'];
  449. }
  450. if (api_get_setting('display_teacher_in_courselist') == 'true') {
  451. $course_details[] = $course['tutor_name'];
  452. }
  453. if (api_get_setting('show_different_course_language') == 'true' && $course['course_language'] != api_get_setting('platformLanguage')) {
  454. $course_details[] = $course['course_language'];
  455. }
  456. $courses_list_string .= implode(' - ', $course_details);
  457. $courses_list_string .= "</li>\n";
  458. }
  459. } else {
  460. // We DO show the closed courses.
  461. // The course is accessible if (link to the course homepage):
  462. // 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);
  463. // 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);
  464. // 3. the user is logged in and the user is subscribed to the course and the course visibility is not COURSE_VISIBILITY_CLOSED;
  465. // 4. the user is logged in and the user is course admin of te course (regardless of the course visibility setting);
  466. // 5. the user is the platform admin api_is_platform_admin().
  467. //
  468. $courses_shown++;
  469. $courses_list_string .= "<li>\n";
  470. if ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD
  471. || ($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM)
  472. || ($user_identified && key_exists($course['code'], $courses_of_user) && $course['visibility'] != COURSE_VISIBILITY_CLOSED)
  473. || $courses_of_user[$course['code']]['status'] == '1'
  474. || api_is_platform_admin()) {
  475. $courses_list_string .= '<a href="'.$web_course_path.$course['directory'].'/">';
  476. }
  477. $courses_list_string .= $course['title'];
  478. if ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD
  479. || ($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM)
  480. || ($user_identified && key_exists($course['code'], $courses_of_user) && $course['visibility'] != COURSE_VISIBILITY_CLOSED)
  481. || $courses_of_user[$course['code']]['status'] == '1'
  482. || api_is_platform_admin()) {
  483. $courses_list_string .= '</a><br />';
  484. }
  485. $course_details = array();
  486. if (api_get_setting('display_coursecode_in_courselist') == 'true') {
  487. $course_details[] = $course['visual_code'];
  488. }
  489. // if (api_get_setting('display_coursecode_in_courselist') == 'true' && api_get_setting('display_teacher_in_courselist') == 'true') {
  490. // $courses_list_string .= ' - ';
  491. // }
  492. if (api_get_setting('display_teacher_in_courselist') == 'true') {
  493. $course_details[] = $course['tutor_name'];
  494. }
  495. if (api_get_setting('show_different_course_language') == 'true' && $course['course_language'] != api_get_setting('platformLanguage')) {
  496. $course_details[] = $course['course_language'];
  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. $courses_list_string .= implode(' - ', $course_details);
  502. // We display a subscription link if:
  503. // 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
  504. // 2.
  505. if ($user_identified && !key_exists($course['code'], $courses_of_user)) {
  506. if ($course['subscribe'] == '1') {
  507. $courses_list_string .= '<form action="main/auth/courses.php?action=subscribe&category='.Security::remove_XSS($_GET['category']).'" method="post">';
  508. $courses_list_string .= '<input type="hidden" name="sec_token" value="'.$stok.'">';
  509. $courses_list_string .= '<input type="hidden" name="subscribe" value="'.$course['code'].'" />';
  510. $courses_list_string .= '<input type="image" name="unsub" src="main/img/enroll.gif" alt="'.get_lang('Subscribe').'" />'.get_lang('Subscribe').'</form>';
  511. } else {
  512. $courses_list_string .= '<br />'.get_lang('SubscribingNotAllowed');
  513. }
  514. }
  515. $courses_list_string .= "</li>";
  516. } //end else
  517. } // end foreach
  518. $courses_list_string .= "</ul>";
  519. } else {
  520. //$result .= '<blockquote>', get_lang('_No_course_publicly_available'), "</blockquote>\n";
  521. }
  522. if ($courses_shown > 0) {
  523. // Only display the list of courses and categories if there was more than
  524. // 0 courses visible to the world (we're in the anonymous list here).
  525. $result .= $courses_list_string;
  526. }
  527. if ($category != '') {
  528. $result .= '<p><a href="'.api_get_self().'"> ' . Display :: return_icon('back.png', get_lang('BackToHomePage')) . get_lang('BackToHomePage') . '</a></p>';
  529. }
  530. return $result;
  531. }
  532. /**
  533. * retrieves all the courses that the user has already subscribed to
  534. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  535. * @param int $user_id: the id of the user
  536. * @return array an array containing all the information of the courses of the given user
  537. */
  538. function get_courses_of_user($user_id) {
  539. $table_course = Database::get_main_table(TABLE_MAIN_COURSE);
  540. $table_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  541. // Secondly we select the courses that are in a category (user_course_cat <> 0) and sort these according to the sort of the category
  542. $user_id = intval($user_id);
  543. $sql_select_courses = "SELECT course.code k, course.visual_code vc, course.subscribe subscr, course.unsubscribe unsubscr,
  544. course.title i, course.tutor_name t, course.db_name db, course.directory dir, course_rel_user.status status,
  545. course_rel_user.sort sort, course_rel_user.user_course_cat user_course_cat
  546. FROM $table_course course,
  547. $table_course_user course_rel_user
  548. WHERE course.code = course_rel_user.course_code
  549. AND course_rel_user.user_id = '".$user_id."'
  550. AND course_rel_user.relation_type<>".COURSE_RELATION_TYPE_RRHH."
  551. ORDER BY course_rel_user.sort ASC";
  552. $result = Database::query($sql_select_courses);
  553. $courses = array();
  554. while ($row = Database::fetch_array($result)) {
  555. // We only need the database name of the course.
  556. $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']);
  557. }
  558. return $courses;
  559. }
  560. /**
  561. * @todo use the template system
  562. */
  563. function show_right_block($title, $content, $id = null, $params = null) {
  564. if (!empty($id)) {
  565. $params['id'] = $id;
  566. }
  567. $params['class'] = 'well sidebar-nav';
  568. $html = null;
  569. if (!empty($title)) {
  570. $html.= '<h4>'.$title.'</h4>';
  571. }
  572. $html.= $content;
  573. $html = Display::div($html, $params);
  574. return $html;
  575. }
  576. /**
  577. * Adds a form to let users login
  578. * @version 1.1
  579. */
  580. function display_login_form() {
  581. $form = new FormValidator('formLogin', 'POST', null, null, array('class'=>'form-vertical'));
  582. // 'placeholder'=>get_lang('UserName')
  583. //'autocomplete'=>"off",
  584. $form->addElement('text', 'login', get_lang('UserName'), array('class' => 'span2', 'autofocus' => 'autofocus', 'autocapitalize'=> 'off'));
  585. $form->addElement('password', 'password', get_lang('Pass'), array('class' => 'span2'));
  586. $form->addElement('style_submit_button','submitAuth', get_lang('LoginEnter'), array('class' => 'btn'));
  587. $html = $form->return_form();
  588. if (api_get_setting('openid_authentication') == 'true') {
  589. include_once 'main/auth/openid/login.php';
  590. $html .= '<div>'.openid_form().'</div>';
  591. }
  592. return $html;
  593. }
  594. function return_search_block() {
  595. $html = '';
  596. if (api_get_setting('search_enabled') == 'true') {
  597. $html .= '<div class="searchbox">';
  598. $search_btn = get_lang('Search');
  599. $search_content = '<br />
  600. <form action="main/search/" method="post">
  601. <input type="text" id="query" class="span2" name="query" value="" />
  602. <button class="save" type="submit" name="submit" value="'.$search_btn.'" />'.$search_btn.' </button>
  603. </form></div>';
  604. $html .= self::show_right_block(get_lang('Search'), $search_content, 'search_block');
  605. }
  606. return $html;
  607. }
  608. function return_classes_block() {
  609. $html = '';
  610. if (api_get_setting('show_groups_to_users') == 'true') {
  611. require_once api_get_path(LIBRARY_PATH).'usergroup.lib.php';
  612. $usergroup = new Usergroup();
  613. $usergroup_list = $usergroup->get_usergroup_by_user(api_get_user_id());
  614. $classes = '';
  615. if (!empty($usergroup_list)) {
  616. foreach($usergroup_list as $group_id) {
  617. $data = $usergroup->get($group_id);
  618. $data['name'] = Display::url($data['name'], api_get_path(WEB_CODE_PATH).'user/classes.php?id='.$data['id']);
  619. $classes .= Display::tag('li', $data['name']);
  620. }
  621. }
  622. if (api_is_platform_admin()) {
  623. $classes .= Display::tag('li', Display::url(get_lang('AddClasses') ,api_get_path(WEB_CODE_PATH).'admin/usergroups.php?action=add'));
  624. }
  625. if (!empty($classes)) {
  626. $classes = Display::tag('ul', $classes, array('class'=>'nav nav-list'));
  627. $html .= self::show_right_block(get_lang('Classes'), $classes, 'classes_block');
  628. }
  629. }
  630. return $html;
  631. }
  632. function return_reservation_block() {
  633. $html = '';
  634. if (api_get_setting('allow_reservation') == 'true' && api_is_allowed_to_create_course()) {
  635. $booking_content .='<ul class="nav nav-list">';
  636. $booking_content .='<a href="main/reservation/reservation.php">'.get_lang('ManageReservations').'</a><br />';
  637. $booking_content .='</ul>';
  638. $html .= self::show_right_block(get_lang('Booking'), $booking_content, 'reservation_block');
  639. }
  640. return $html;
  641. }
  642. function return_user_image_block() {
  643. //Always show the user image
  644. $img_array = UserManager::get_user_picture_path_by_id(api_get_user_id(), 'web', true, true);
  645. $no_image = false;
  646. if ($img_array['file'] == 'unknown.jpg') {
  647. $no_image = true;
  648. }
  649. $img_array = UserManager::get_picture_user(api_get_user_id(), $img_array['file'], 50, USER_IMAGE_SIZE_MEDIUM, ' width="90" height="90" ');
  650. if (api_get_setting('allow_social_tool') == 'true') {
  651. if (!$no_image) {
  652. $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>';
  653. } else {
  654. $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>';
  655. }
  656. }
  657. $html = self::show_right_block(null, $profile_content, 'user_image_block', array('style' => 'text-align:center;'));
  658. return $html;
  659. }
  660. function return_profile_block() {
  661. $html = '';
  662. $user_id = api_get_user_id();
  663. if (empty($user_id)) {
  664. return;
  665. }
  666. $profile_content .= '<ul class="nav nav-list">';
  667. // @todo Add a platform setting to add the user image.
  668. if (api_get_setting('allow_message_tool') == 'true') {
  669. require_once api_get_path(LIBRARY_PATH).'group_portal_manager.lib.php';
  670. // New messages.
  671. $number_of_new_messages = MessageManager::get_new_messages();
  672. // New contact invitations.
  673. $number_of_new_messages_of_friend = SocialManager::get_message_number_invitation_by_user_id(api_get_user_id());
  674. // New group invitations sent by a moderator.
  675. $group_pending_invitations = GroupPortalManager::get_groups_by_user(api_get_user_id(), GROUP_USER_PERMISSION_PENDING_INVITATION, false);
  676. $group_pending_invitations = count($group_pending_invitations);
  677. $total_invitations = $number_of_new_messages_of_friend + $group_pending_invitations;
  678. $cant_msg = Display::badge($number_of_new_messages);
  679. $link = '';
  680. if (api_get_setting('allow_social_tool') == 'true') {
  681. $link = '?f=social';
  682. }
  683. $profile_content .= '<li><a href="'.api_get_path(WEB_PATH).'main/messages/inbox.php'.$link.'">'.get_lang('Inbox').$cant_msg.' </a></li>';
  684. $profile_content .= '<li><a href="'.api_get_path(WEB_PATH).'main/messages/new_message.php'.$link.'">'.get_lang('Compose').' </a></li>';
  685. if (api_get_setting('allow_social_tool') == 'true') {
  686. $total_invitations = Display::badge($total_invitations);
  687. $profile_content .= '<li><a href="'.api_get_path(WEB_PATH).'main/social/invitations.php">'.get_lang('PendingInvitations').$total_invitations.'</a></li>';
  688. }
  689. $profile_content .= '<li><a href="'.api_get_path(WEB_PATH).'main/auth/profile.php">'.get_lang('EditProfile').'</a></li>';
  690. }
  691. $profile_content .= '</ul>';
  692. $html = self::show_right_block(get_lang('Profile'), $profile_content, 'profile_block');
  693. return $html;
  694. }
  695. function return_navigation_links() {
  696. $html = '';
  697. // Deleting the myprofile link.
  698. if (api_get_setting('allow_social_tool') == 'true') {
  699. unset($this->tpl->menu_navigation['myprofile']);
  700. }
  701. // Main navigation section.
  702. // Tabs that are deactivated are added here.
  703. if (!empty($this->tpl->menu_navigation)) {
  704. $content = '<ul class="nav nav-list">';
  705. foreach ($this->tpl->menu_navigation as $section => $navigation_info) {
  706. $current = $section == $GLOBALS['this_section'] ? ' id="current"' : '';
  707. $content .= '<li'.$current.'>';
  708. $content .= '<a href="'.$navigation_info['url'].'" target="_self">'.$navigation_info['title'].'</a>';
  709. $content .= '</li>';
  710. }
  711. $content .= '</ul>';
  712. $html = self::show_right_block(get_lang('MainNavigation'), $content, 'navigation_link_block');
  713. }
  714. return $html;
  715. }
  716. function return_course_block() {
  717. $html = '';
  718. $show_create_link = false;
  719. $show_course_link = false;
  720. $display_add_course_link = api_is_allowed_to_create_course() && ($_SESSION['studentview'] != 'studentenview');
  721. if ($display_add_course_link) {
  722. $show_create_link = true;
  723. }
  724. if (api_is_platform_admin() || api_is_course_admin() || api_is_allowed_to_create_course()) {
  725. $show_course_link = true;
  726. } else {
  727. if (api_get_setting('allow_students_to_browse_courses') == 'true') {
  728. $show_course_link = true;
  729. }
  730. }
  731. // My account section
  732. $my_account_content = '<ul class="nav nav-list">';
  733. if ($show_create_link) {
  734. $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>';
  735. }
  736. //Sort courses
  737. $url = api_get_path(WEB_CODE_PATH).'auth/courses.php?action=sortmycourses';
  738. $my_account_content .= '<li>'.Display::url(get_lang('SortMyCourses'), $url, array('class' => 'sort course')).'</li>';
  739. //Course management
  740. if ($show_course_link) {
  741. if (!api_is_drh()) {
  742. $my_account_content .= '<li><a href="main/auth/courses.php" class="list course">'.get_lang('CourseCatalog').'</a></li>';
  743. if (isset($_GET['history']) && intval($_GET['history']) == 1) {
  744. $my_account_content .= '<li><a href="user_portal.php">'.get_lang('DisplayTrainingList').'</a></li>';
  745. } else {
  746. $my_account_content .= '<li><a href="user_portal.php?history=1" class="history course">'.get_lang('HistoryTrainingSessions').'</a></li>';
  747. }
  748. } else {
  749. $my_account_content .= '<li><a href="main/dashboard/index.php">'.get_lang('Dashboard').'</a></li>';
  750. }
  751. }
  752. $my_account_content .= '</ul>';
  753. if (!empty($my_account_content)) {
  754. $html = self::show_right_block(get_lang('Courses'), $my_account_content, 'course_block');
  755. }
  756. return $html;
  757. }
  758. /**
  759. * The most important function here, prints the session and course list (user_portal.php)
  760. *
  761. * */
  762. function return_courses_and_sessions($user_id) {
  763. $session_categories = array();
  764. $load_history = (isset($_GET['history']) && intval($_GET['history']) == 1) ? true : false;
  765. if ($load_history) {
  766. //Load sessions in category in *history*
  767. $session_categories = UserManager::get_sessions_by_category($user_id, true);
  768. } else {
  769. //Load sessions in category
  770. $session_categories = UserManager::get_sessions_by_category($user_id, false);
  771. }
  772. $html = '';
  773. //Showing history title
  774. if ($load_history) {
  775. $html .= Display::page_subheader(get_lang('HistoryTrainingSession'));
  776. if (empty($session_categories)) {
  777. $html .= get_lang('YouDoNotHaveAnySessionInItsHistory');
  778. }
  779. }
  780. $courses_html = '';
  781. $special_courses = '';
  782. // If we're not in the history view...
  783. if (!isset($_GET['history'])) {
  784. //Display special courses
  785. $special_courses = CourseManager :: display_special_courses($user_id, $this->load_directories_preview);
  786. //Display courses
  787. $courses_html .= CourseManager :: display_courses($user_id, $this->load_directories_preview);
  788. }
  789. $sessions_with_category = '';
  790. $sessions_with_no_category = '';
  791. if (is_array($session_categories)) {
  792. foreach ($session_categories as $session_category) {
  793. $session_category_id = $session_category['session_category']['id'];
  794. // Sessions and courses that are not in a session category
  795. if ($session_category_id == 0) {
  796. // Independent sessions
  797. foreach ($session_category['sessions'] as $session) {
  798. $session_id = $session['session_id'];
  799. // Don't show empty sessions.
  800. if (count($session['courses']) < 1) {
  801. continue;
  802. }
  803. // Courses inside the current session.
  804. $date_session_start = $session['date_start'];
  805. $days_access_before_beginning = $session['nb_days_access_before_beginning'] * 24 * 3600;
  806. $session_now = time();
  807. $html_courses_session = '';
  808. $count_courses_session = 0;
  809. foreach ($session['courses'] as $course) {
  810. $is_coach_course = api_is_coach($session_id, $course['code']);
  811. $allowed_time = 0;
  812. if ($date_session_start != '0000-00-00') {
  813. if ($is_coach_course) {
  814. $allowed_time = api_strtotime($date_session_start) - $days_access_before_beginning;
  815. } else {
  816. $allowed_time = api_strtotime($date_session_start);
  817. }
  818. }
  819. if ($session_now > $allowed_time) {
  820. //read only and accesible
  821. if (api_get_setting('hide_courses_in_sessions') == 'false') {
  822. $c = CourseManager :: get_logged_user_course_html($course, $session_id, 'session_course_item', true, $this->load_directories_preview);
  823. $html_courses_session .= $c[1];
  824. }
  825. $count_courses_session++;
  826. }
  827. }
  828. if ($count_courses_session > 0) {
  829. $params = array();
  830. $session_box = Display :: get_session_title_box($session_id);
  831. $params['icon'] = Display::return_icon('window_list.png', $session_box['title'], array('id' => 'session_img_'.$session_id), ICON_SIZE_LARGE);
  832. $extra_info = !empty($session_box['coach']) ? $session_box['coach'] : null;
  833. $extra_info .= !empty($session_box['dates']) ? ' - '.$session_box['dates'] : null;
  834. if (api_is_drh()) {
  835. $session_link = $session_box['title'];
  836. $params['link'] = null;
  837. } else {
  838. $session_link = Display::tag('a', $session_box['title'], array('href'=>api_get_path(WEB_CODE_PATH).'session/index.php?session_id='.$session_id));
  839. $params['link'] = api_get_path(WEB_CODE_PATH).'session/index.php?session_id='.$session_id;
  840. }
  841. $params['title'] = $session_link;
  842. $params['subtitle'] = $extra_info;
  843. $params['right_actions'] = '';
  844. if (api_is_platform_admin()) {
  845. $params['right_actions'] .= '<a href="'.api_get_path(WEB_CODE_PATH).'admin/resume_session.php?id_session='.$session_id.'">';
  846. $params['right_actions'] .= Display::return_icon('edit.png', get_lang('Edit'), array('align' => 'absmiddle'), ICON_SIZE_SMALL).'</a>';
  847. }
  848. if (api_get_setting('hide_courses_in_sessions') == 'false') {
  849. // $params['extra'] .= $html_courses_session;
  850. }
  851. $sessions_with_no_category .= CourseManager::course_item_parent(CourseManager::course_item_html($params, true), $html_courses_session);
  852. }
  853. }
  854. } else {
  855. // All sessions included in
  856. $count_courses_session = 0;
  857. $html_sessions = '';
  858. foreach ($session_category['sessions'] as $session) {
  859. $session_id = $session['session_id'];
  860. //var_dump($session);var_dump($session_category);
  861. // Don't show empty sessions.
  862. if (count($session['courses']) < 1) {
  863. continue;
  864. }
  865. $date_session_start = $session['date_start'];
  866. //api_get_session_visibility($session_id);
  867. $days_access_before_beginning = $session['nb_days_access_before_beginning'] * 24 * 3600;
  868. $session_now = time();
  869. $html_courses_session = '';
  870. $count = 0;
  871. foreach ($session['courses'] as $course) {
  872. $is_coach_course = api_is_coach($session_id, $course['code']);
  873. if ($is_coach_course) {
  874. $allowed_time = api_strtotime($date_session_start) - $days_access_before_beginning;
  875. } else {
  876. $allowed_time = api_strtotime($date_session_start);
  877. }
  878. if ($session_now > $allowed_time) {
  879. $c = CourseManager :: get_logged_user_course_html($course, $session_id, 'session_course_item');
  880. $html_courses_session .= $c[1];
  881. $count_courses_session++;
  882. $count++;
  883. }
  884. }
  885. $params = array();
  886. if ($count > 0) {
  887. $session_box = Display :: get_session_title_box($session_id);
  888. $params['icon'] = Display::return_icon('window_list.png', $session_box['title'], array('width' => '48px', 'align' => 'absmiddle', 'id' => 'session_img_'.$session_id)) . ' ';
  889. if (api_is_drh()) {
  890. $session_link = $session_box['title'];
  891. $params['link'] = null;
  892. } else {
  893. $session_link = Display::tag('a', $session_box['title'], array('href'=>api_get_path(WEB_CODE_PATH).'session/index.php?session_id='.$session_id));
  894. $params['link'] = api_get_path(WEB_CODE_PATH).'session/index.php?session_id='.$session_id;
  895. }
  896. $params['title'] .= $session_link;
  897. $params['subtitle'] = (!empty($session_box['coach']) ? $session_box['coach'].' | ' : '').$session_box['dates'];
  898. if (api_is_platform_admin()) {
  899. $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>';
  900. }
  901. $html_sessions .= CourseManager::course_item_html($params, true).$html_courses_session;
  902. }
  903. }
  904. if ($count_courses_session > 0) {
  905. $params = array();
  906. $params['icon'] = Display::return_icon('folder_blue.png', $session_category['session_category']['name'], array(), ICON_SIZE_LARGE);
  907. if (api_is_platform_admin()) {
  908. $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>';
  909. }
  910. $params['title'] .= $session_category['session_category']['name'];
  911. if (api_is_platform_admin()) {
  912. $params['link'] = api_get_path(WEB_CODE_PATH).'admin/session_category_edit.php?&id='.$session_category['session_category']['id'];
  913. }
  914. $session_category_start_date = $session_category['session_category']['date_start'];
  915. $session_category_end_date = $session_category['session_category']['date_end'];
  916. 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' ) {
  917. $params['subtitle'] = sprintf(get_lang('FromDateXToDateY'), $session_category['session_category']['date_start'], $session_category['session_category']['date_end']);
  918. } else {
  919. if (!empty($session_category_start_date) && $session_category_start_date != '0000-00-00') {
  920. $params['subtitle'] = get_lang('From').' '.$session_category_start_date;
  921. }
  922. if (!empty($session_category_end_date) && $session_category_end_date != '0000-00-00') {
  923. $params['subtitle'] = get_lang('Until').' '.$session_category_end_date;
  924. }
  925. }
  926. $sessions_with_category .= CourseManager::course_item_parent(CourseManager::course_item_html($params, true), $html_sessions);
  927. }
  928. }
  929. }
  930. }
  931. return $sessions_with_category.$sessions_with_no_category.$courses_html.$special_courses;
  932. }
  933. /**
  934. * Shows a welcome message when the user doesn't have any content in the course list
  935. */
  936. function return_welcome_to_course_block() {
  937. $tpl = $this->tpl->get_template('layout/welcome_to_course.tpl');
  938. $course_catalog_url = api_get_path(WEB_CODE_PATH).'auth/courses.php';
  939. $course_list_url = api_get_path(WEB_PATH).'user_portal.php';
  940. $this->tpl->assign('course_catalog_url', $course_catalog_url);
  941. $this->tpl->assign('course_list_url', $course_list_url);
  942. $this->tpl->assign('course_catalog_link', Display::url(get_lang('here'), $course_catalog_url));
  943. $this->tpl->assign('course_list_link', Display::url(get_lang('here'), $course_list_url));
  944. return $this->tpl->fetch($tpl);
  945. }
  946. function return_hot_courses() {
  947. return CourseManager::return_hot_courses();
  948. }
  949. }