userportal.lib.php 66 KB

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