userportal.lib.php 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099
  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. $img_array = UserManager::get_user_picture_path_by_id(api_get_user_id(), 'web', true, true);
  645. $img_array = UserManager::get_picture_user(api_get_user_id(), $img_array['file'], 50, USER_IMAGE_SIZE_MEDIUM, ' width="90" height="90" ');
  646. if (api_get_setting('allow_social_tool') == 'true') {
  647. $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>';
  648. } else {
  649. $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>';
  650. }
  651. $html = self::show_right_block(null, $profile_content, 'user_image_block', array('style' => 'text-align:center;'));
  652. return $html;
  653. }
  654. function return_profile_block() {
  655. $html = '';
  656. $user_id = api_get_user_id();
  657. if (empty($user_id)) {
  658. return;
  659. }
  660. $profile_content .= '<ul class="nav nav-list">';
  661. // @todo Add a platform setting to add the user image.
  662. if (api_get_setting('allow_message_tool') == 'true') {
  663. require_once api_get_path(LIBRARY_PATH).'group_portal_manager.lib.php';
  664. // New messages.
  665. $number_of_new_messages = MessageManager::get_new_messages();
  666. // New contact invitations.
  667. $number_of_new_messages_of_friend = SocialManager::get_message_number_invitation_by_user_id(api_get_user_id());
  668. // New group invitations sent by a moderator.
  669. $group_pending_invitations = GroupPortalManager::get_groups_by_user(api_get_user_id(), GROUP_USER_PERMISSION_PENDING_INVITATION, false);
  670. $group_pending_invitations = count($group_pending_invitations);
  671. $total_invitations = $number_of_new_messages_of_friend + $group_pending_invitations;
  672. $cant_msg = Display::badge($number_of_new_messages);
  673. $link = '';
  674. if (api_get_setting('allow_social_tool') == 'true') {
  675. $link = '?f=social';
  676. }
  677. $profile_content .= '<li><a href="'.api_get_path(WEB_PATH).'main/messages/inbox.php'.$link.'">'.get_lang('Inbox').$cant_msg.' </a></li>';
  678. $profile_content .= '<li><a href="'.api_get_path(WEB_PATH).'main/messages/new_message.php'.$link.'">'.get_lang('Compose').' </a></li>';
  679. if (api_get_setting('allow_social_tool') == 'true') {
  680. $total_invitations = Display::badge($total_invitations);
  681. $profile_content .= '<li><a href="'.api_get_path(WEB_PATH).'main/social/invitations.php">'.get_lang('PendingInvitations').$total_invitations.'</a></li>';
  682. }
  683. $profile_content .= '<li><a href="'.api_get_path(WEB_PATH).'main/auth/profile.php">'.get_lang('EditProfile').'</a></li>';
  684. }
  685. $profile_content .= '</ul>';
  686. $html = self::show_right_block(get_lang('Profile'), $profile_content, 'profile_block');
  687. return $html;
  688. }
  689. function return_navigation_links() {
  690. $html = '';
  691. // Deleting the myprofile link.
  692. if (api_get_setting('allow_social_tool') == 'true') {
  693. unset($this->tpl->menu_navigation['myprofile']);
  694. }
  695. // Main navigation section.
  696. // Tabs that are deactivated are added here.
  697. if (!empty($this->tpl->menu_navigation)) {
  698. $content = '<ul class="nav nav-list">';
  699. foreach ($this->tpl->menu_navigation as $section => $navigation_info) {
  700. $current = $section == $GLOBALS['this_section'] ? ' id="current"' : '';
  701. $content .= '<li'.$current.'>';
  702. $content .= '<a href="'.$navigation_info['url'].'" target="_self">'.$navigation_info['title'].'</a>';
  703. $content .= '</li>';
  704. }
  705. $content .= '</ul>';
  706. $html = self::show_right_block(get_lang('MainNavigation'), $content, 'navigation_link_block');
  707. }
  708. return $html;
  709. }
  710. function return_course_block() {
  711. $html = '';
  712. $show_create_link = false;
  713. $show_course_link = false;
  714. if ((api_get_setting('allow_users_to_create_courses') == 'false' && !api_is_platform_admin()) || api_is_student()) {
  715. $display_add_course_link = false;
  716. } else {
  717. $display_add_course_link = true;
  718. }
  719. //$display_add_course_link = api_is_allowed_to_create_course() && ($_SESSION['studentview'] != 'studentenview');
  720. if ($display_add_course_link) {
  721. $show_create_link = true;
  722. }
  723. if (api_is_platform_admin() || api_is_course_admin() || api_is_allowed_to_create_course()) {
  724. $show_course_link = true;
  725. } else {
  726. if (api_get_setting('allow_students_to_browse_courses') == 'true') {
  727. $show_course_link = true;
  728. }
  729. }
  730. // My account section
  731. $my_account_content = '<ul class="nav nav-list">';
  732. if ($show_create_link) {
  733. $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>';
  734. }
  735. //Sort courses
  736. $url = api_get_path(WEB_CODE_PATH).'auth/courses.php?action=sortmycourses';
  737. $my_account_content .= '<li>'.Display::url(get_lang('SortMyCourses'), $url, array('class' => 'sort course')).'</li>';
  738. //Course management
  739. if ($show_course_link) {
  740. if (!api_is_drh()) {
  741. $my_account_content .= '<li><a href="main/auth/courses.php" class="list course">'.get_lang('CourseCatalog').'</a></li>';
  742. if (isset($_GET['history']) && intval($_GET['history']) == 1) {
  743. $my_account_content .= '<li><a href="user_portal.php">'.get_lang('DisplayTrainingList').'</a></li>';
  744. } else {
  745. $my_account_content .= '<li><a href="user_portal.php?history=1" class="history course">'.get_lang('HistoryTrainingSessions').'</a></li>';
  746. }
  747. } else {
  748. $my_account_content .= '<li><a href="main/dashboard/index.php">'.get_lang('Dashboard').'</a></li>';
  749. }
  750. }
  751. $my_account_content .= '</ul>';
  752. if (!empty($my_account_content)) {
  753. $html = self::show_right_block(get_lang('Courses'), $my_account_content, 'course_block');
  754. }
  755. return $html;
  756. }
  757. /**
  758. * The most important function here, prints the session and course list (user_portal.php)
  759. *
  760. * */
  761. function return_courses_and_sessions($user_id) {
  762. $session_categories = array();
  763. $load_history = (isset($_GET['history']) && intval($_GET['history']) == 1) ? true : false;
  764. if ($load_history) {
  765. //Load sessions in category in *history*
  766. $session_categories = UserManager::get_sessions_by_category($user_id, true);
  767. } else {
  768. //Load sessions in category
  769. $session_categories = UserManager::get_sessions_by_category($user_id, false);
  770. }
  771. $html = '';
  772. //Showing history title
  773. if ($load_history) {
  774. $html .= Display::page_subheader(get_lang('HistoryTrainingSession'));
  775. if (empty($session_categories)) {
  776. $html .= get_lang('YouDoNotHaveAnySessionInItsHistory');
  777. }
  778. }
  779. $courses_html = '';
  780. $special_courses = '';
  781. // If we're not in the history view...
  782. if (!isset($_GET['history'])) {
  783. //Display special courses
  784. $special_courses = CourseManager::display_special_courses($user_id, $this->load_directories_preview);
  785. //Display courses
  786. $courses_html .= CourseManager::display_courses($user_id, $this->load_directories_preview);
  787. }
  788. $sessions_with_category = '';
  789. $sessions_with_no_category = '';
  790. if (is_array($session_categories)) {
  791. foreach ($session_categories as $session_category) {
  792. $session_category_id = $session_category['session_category']['id'];
  793. // Sessions and courses that are not in a session category
  794. if ($session_category_id == 0) {
  795. // Independent sessions
  796. foreach ($session_category['sessions'] as $session) {
  797. $session_id = $session['session_id'];
  798. // Don't show empty sessions.
  799. if (count($session['courses']) < 1) {
  800. continue;
  801. }
  802. // Courses inside the current session.
  803. $date_session_start = $session['date_start'];
  804. $days_access_before_beginning = $session['nb_days_access_before_beginning'];
  805. $days_access_after_end = $session['nb_days_access_after_end'];
  806. $date_session_end = $session['date_end'];
  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. $dif_time_after = 0;
  814. if ($date_session_start != '0000-00-00') {
  815. if ($is_coach_course) {
  816. $allowed_time = api_strtotime($date_session_start) - ($days_access_before_beginning*86400);
  817. if ($session_now > $date_session_end) {
  818. $dif_time_after = $session_now - api_strtotime($date_session_end);
  819. $dif_time_after = round($dif_time_after/86400);
  820. }
  821. } else {
  822. $allowed_time = api_strtotime($date_session_start);
  823. }
  824. }
  825. if ($session_now > $allowed_time && $days_access_after_end >= $dif_time_after-1) {
  826. //read only and accesible
  827. if (api_get_setting('hide_courses_in_sessions') == 'false') {
  828. $c = CourseManager :: get_logged_user_course_html($course, $session_id, 'session_course_item', true, $this->load_directories_preview);
  829. $html_courses_session .= $c[1];
  830. }
  831. $count_courses_session++;
  832. }
  833. }
  834. if ($count_courses_session > 0) {
  835. $params = array();
  836. $session_box = Display :: get_session_title_box($session_id);
  837. $params['icon'] = Display::return_icon('window_list.png', $session_box['title'], array('id' => 'session_img_'.$session_id), ICON_SIZE_LARGE);
  838. $extra_info = !empty($session_box['coach']) ? $session_box['coach'] : null;
  839. $extra_info .= !empty($session_box['coach']) ? ' - '.$session_box['dates'] : $session_box['dates'];
  840. if (api_is_drh()) {
  841. $session_link = $session_box['title'];
  842. $params['link'] = null;
  843. } else {
  844. $session_link = Display::tag('a', $session_box['title'], array('href'=>api_get_path(WEB_CODE_PATH).'session/index.php?session_id='.$session_id));
  845. $params['link'] = api_get_path(WEB_CODE_PATH).'session/index.php?session_id='.$session_id;
  846. }
  847. $params['title'] = $session_link;
  848. $params['subtitle'] = $extra_info;
  849. $params['right_actions'] = '';
  850. if (api_is_platform_admin()) {
  851. $params['right_actions'] .= '<a href="'.api_get_path(WEB_CODE_PATH).'admin/resume_session.php?id_session='.$session_id.'">';
  852. $params['right_actions'] .= Display::return_icon('edit.png', get_lang('Edit'), array('align' => 'absmiddle'), ICON_SIZE_SMALL).'</a>';
  853. }
  854. if (api_get_setting('hide_courses_in_sessions') == 'false') {
  855. // $params['extra'] .= $html_courses_session;
  856. }
  857. $sessions_with_no_category .= CourseManager::course_item_parent(CourseManager::course_item_html($params, true), $html_courses_session);
  858. }
  859. }
  860. } else {
  861. // All sessions included in
  862. $count_courses_session = 0;
  863. $html_sessions = '';
  864. foreach ($session_category['sessions'] as $session) {
  865. $session_id = $session['session_id'];
  866. //var_dump($session);var_dump($session_category);
  867. // Don't show empty sessions.
  868. if (count($session['courses']) < 1) {
  869. continue;
  870. }
  871. $date_session_start = $session['date_start'];
  872. //api_get_session_visibility($session_id);
  873. $days_access_before_beginning = $session['nb_days_access_before_beginning'];
  874. $days_access_after_end = $session['nb_days_access_after_end'];
  875. $date_session_end = $session['date_end'];
  876. $session_now = time();
  877. $html_courses_session = '';
  878. $count = 0;
  879. foreach ($session['courses'] as $course) {
  880. $is_coach_course = api_is_coach($session_id, $course['code']);
  881. $dif_time_after = 0;
  882. if ($is_coach_course) {
  883. $allowed_time = api_strtotime($date_session_start) - ($days_access_before_beginning*86400);
  884. if ($session_now > $date_session_end) {
  885. $dif_time_after = $session_now - api_strtotime($date_session_end);
  886. $dif_time_after = round($dif_time_after/86400);
  887. }
  888. } else {
  889. $allowed_time = api_strtotime($date_session_start);
  890. }
  891. if ($session_now > $allowed_time && $days_access_after_end >= $dif_time_after-1) {
  892. if (api_get_setting('hide_courses_in_sessions') == 'false') {
  893. $c = CourseManager :: get_logged_user_course_html($course, $session_id, 'session_course_item');
  894. $html_courses_session .= $c[1];
  895. }
  896. $count_courses_session++;
  897. $count++;
  898. }
  899. }
  900. $params = array();
  901. if ($count > 0) {
  902. $session_box = Display :: get_session_title_box($session_id);
  903. $params['icon'] = Display::return_icon('window_list.png', $session_box['title'], array('width' => '48px', 'align' => 'absmiddle', 'id' => 'session_img_'.$session_id)) . ' ';
  904. if (api_is_drh()) {
  905. $session_link = $session_box['title'];
  906. $params['link'] = null;
  907. } else {
  908. $session_link = Display::tag('a', $session_box['title'], array('href'=>api_get_path(WEB_CODE_PATH).'session/index.php?session_id='.$session_id));
  909. $params['link'] = api_get_path(WEB_CODE_PATH).'session/index.php?session_id='.$session_id;
  910. }
  911. $params['title'] .= $session_link;
  912. $params['subtitle'] = (!empty($session_box['coach']) ? $session_box['coach'].' | ' : '').$session_box['dates'];
  913. if (api_is_platform_admin()) {
  914. $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>';
  915. }
  916. $html_sessions .= CourseManager::course_item_html($params, true).$html_courses_session;
  917. }
  918. }
  919. if ($count_courses_session > 0) {
  920. $params = array();
  921. $params['icon'] = Display::return_icon('folder_blue.png', $session_category['session_category']['name'], array(), ICON_SIZE_LARGE);
  922. if (api_is_platform_admin()) {
  923. $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>';
  924. }
  925. $params['title'] .= $session_category['session_category']['name'];
  926. if (api_is_platform_admin()) {
  927. $params['link'] = api_get_path(WEB_CODE_PATH).'admin/session_category_edit.php?&id='.$session_category['session_category']['id'];
  928. }
  929. $session_category_start_date = $session_category['session_category']['date_start'];
  930. $session_category_end_date = $session_category['session_category']['date_end'];
  931. 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' ) {
  932. $params['subtitle'] = sprintf(get_lang('FromDateXToDateY'), $session_category['session_category']['date_start'], $session_category['session_category']['date_end']);
  933. } else {
  934. if (!empty($session_category_start_date) && $session_category_start_date != '0000-00-00') {
  935. $params['subtitle'] = get_lang('From').' '.$session_category_start_date;
  936. }
  937. if (!empty($session_category_end_date) && $session_category_end_date != '0000-00-00') {
  938. $params['subtitle'] = get_lang('Until').' '.$session_category_end_date;
  939. }
  940. }
  941. $sessions_with_category .= CourseManager::course_item_parent(CourseManager::course_item_html($params, true), $html_sessions);
  942. }
  943. }
  944. }
  945. }
  946. return $sessions_with_category.$sessions_with_no_category.$courses_html.$special_courses;
  947. }
  948. /**
  949. * Shows a welcome message when the user doesn't have any content in the course list
  950. */
  951. function return_welcome_to_course_block() {
  952. $count_courses = CourseManager::count_courses();
  953. $tpl = $this->tpl->get_template('layout/welcome_to_course.tpl');
  954. $course_catalog_url = api_get_path(WEB_CODE_PATH).'auth/courses.php';
  955. $course_list_url = api_get_path(WEB_PATH).'user_portal.php';
  956. $this->tpl->assign('course_catalog_url', $course_catalog_url);
  957. $this->tpl->assign('course_list_url', $course_list_url);
  958. $this->tpl->assign('course_catalog_link', Display::url(get_lang('here'), $course_catalog_url));
  959. $this->tpl->assign('course_list_link', Display::url(get_lang('here'), $course_list_url));
  960. $this->tpl->assign('count_courses', $count_courses);
  961. return $this->tpl->fetch($tpl);
  962. }
  963. function return_hot_courses() {
  964. return CourseManager::return_hot_courses();
  965. }
  966. }