userportal.lib.php 54 KB

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