page.lib.php 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Controller for pages presentation in general
  5. * @package chamilo.page.controller
  6. * @author Julio Montoya <gugli100@gmail.com>
  7. */
  8. /**
  9. * Page controller
  10. */
  11. use Silex\Application;
  12. use Pagerfanta\Adapter\FixedAdapter;
  13. use Pagerfanta\Pagerfanta;
  14. use Pagerfanta\View\TwitterBootstrapView;
  15. class PageController
  16. {
  17. public $maxPerPage = 2;
  18. private $app;
  19. public function __construct(Application $app)
  20. {
  21. $this->app = $app;
  22. }
  23. /**
  24. * Returns an HTML block with the user picture (as a link in a <div>)
  25. * @param int User ID (if not provided, will use the user ID from session)
  26. * @return string HTML div with a link to the user's profile
  27. * @uses UserManager::get_user_pictur_path_by_id() to get the image path
  28. * @uses UserManager::get_picture_user() to get the details of the image in a specific format
  29. * @uses PageController::show_right_block() to include the image in a larger user block
  30. * @assert (-1) === false
  31. */
  32. public function return_user_image_block($user_id = null)
  33. {
  34. if (empty($user_id)) {
  35. $user_id = api_get_user_id();
  36. }
  37. //Always show the user image
  38. $img_array = UserManager::get_user_picture_path_by_id($user_id, 'web', true, true);
  39. $no_image = false;
  40. if ($img_array['file'] == 'unknown.jpg') {
  41. $no_image = true;
  42. }
  43. $img_array = UserManager::get_picture_user($user_id, $img_array['file'], 100, USER_IMAGE_SIZE_ORIGINAL);
  44. $profile_content = null;
  45. if (api_get_setting('allow_social_tool') == 'true') {
  46. if (!$no_image) {
  47. $profile_content .= '<a style="text-align:center" href="'.api_get_path(WEB_CODE_PATH).'social/home.php">
  48. <img src="'.$img_array['file'].'"></a>';
  49. } else {
  50. $profile_content .= '<a style="text-align:center" href="'.api_get_path(WEB_CODE_PATH).'auth/profile.php">
  51. <img title="'.get_lang('EditProfile').'" src="'.$img_array['file'].'"></a>';
  52. }
  53. }
  54. $this->show_right_block(null, null, 'user_image_block', array('content' => $profile_content));
  55. }
  56. /**
  57. * Return a block with course-related links. The resulting HTML block's
  58. * contents are only based on the user defined by the active session.
  59. *
  60. * @return string HTML <div> with links
  61. * @assert () != ''
  62. */
  63. public function return_course_block($filter = null)
  64. {
  65. $show_create_link = false;
  66. $show_course_link = false;
  67. if ((api_get_setting('allow_users_to_create_courses') == 'false' && !api_is_platform_admin()) || api_is_student(
  68. )
  69. ) {
  70. $display_add_course_link = false;
  71. } else {
  72. $display_add_course_link = true;
  73. }
  74. if ($display_add_course_link) {
  75. $show_create_link = true;
  76. }
  77. if (api_is_platform_admin() || api_is_course_admin() || api_is_allowed_to_create_course()) {
  78. $show_course_link = true;
  79. } else {
  80. if (api_get_setting('allow_students_to_browse_courses') == 'true') {
  81. $show_course_link = true;
  82. }
  83. }
  84. // My account section
  85. $my_account_content = array();
  86. if ($show_create_link) {
  87. $my_account_content[] = array(
  88. 'href' => api_get_path(WEB_CODE_PATH).'create_course/add_course.php',
  89. 'title' => api_get_setting('course_validation') == 'true' ? get_lang('CreateCourseRequest') : get_lang(
  90. 'CourseCreate'
  91. )
  92. );
  93. }
  94. //Sort courses
  95. $url = api_get_path(WEB_CODE_PATH).'auth/courses.php?action=sortmycourses';
  96. $my_account_content[] = array(
  97. 'href' => $url,
  98. 'title' => get_lang('SortMyCourses')
  99. );
  100. //Course management
  101. if ($show_course_link) {
  102. if (!api_is_drh()) {
  103. $my_account_content[] = array(
  104. 'href' => api_get_path(WEB_CODE_PATH).'auth/courses.php',
  105. 'title' => get_lang('CourseCatalog')
  106. );
  107. if (isset($filter) && $filter == 'history') {
  108. $my_account_content[] = array(
  109. 'href' => api_get_path(WEB_PUBLIC_PATH).'userportal',
  110. 'title' => get_lang('DisplayTrainingList')
  111. );
  112. } else {
  113. $my_account_content[] = array(
  114. 'href' => api_get_path(WEB_PUBLIC_PATH).'userportal/history',
  115. 'title' => get_lang('HistoryTrainingSessions')
  116. );
  117. }
  118. } else {
  119. $my_account_content .= array(
  120. 'href' => api_get_path(WEB_CODE_PATH).'dashboard/index.php',
  121. 'title' => get_lang('Dashboard')
  122. );
  123. }
  124. }
  125. $this->show_right_block(get_lang('Courses'), $my_account_content, 'course_block');
  126. }
  127. /**
  128. * Returns the profile block, showing links to the messaging and social
  129. * network tools. The user ID is taken from the active session
  130. * @return string HTML <div> block
  131. * @assert () != ''
  132. */
  133. public function return_profile_block()
  134. {
  135. if (api_get_setting('allow_message_tool') == 'true') {
  136. if (api_get_setting('allow_social_tool') == 'true') {
  137. $this->show_right_block(get_lang('Profile'), array(), 'profile_social_block');
  138. } else {
  139. $this->show_right_block(get_lang('Profile'), array(), 'profile_block');
  140. }
  141. }
  142. }
  143. /**
  144. * Get the section course section
  145. */
  146. public function getSectionCourseBlock()
  147. {
  148. $app = $this->app;
  149. $courseURL = $app['url_generator']->generate('userportal', array('type' => 'courses'));
  150. $sessionURL = $app['url_generator']->generate('userportal', array('type' => 'sessions'));
  151. $myCourseCategoriesURL = $app['url_generator']->generate('userportal', array('type' => 'mycoursecategories'));
  152. $specialCoursesURL = $app['url_generator']->generate('userportal', array('type' => 'specialcourses'));
  153. $sessionCategoriesURL = $app['url_generator']->generate('userportal', array('type' => 'sessioncategories'));
  154. $params = array(
  155. array('href' => $courseURL, 'title' => get_lang('Courses')),
  156. array('href' => $specialCoursesURL, 'title' => get_lang('SpecialCourses')),
  157. array('href' => $myCourseCategoriesURL, 'title' => get_lang('MyCourseCategories')),
  158. array('href' => $sessionURL, 'title' => get_lang('Sessions')),
  159. array('href' => $sessionCategoriesURL, 'title' => get_lang('SessionsCategories')),
  160. );
  161. $this->show_right_block(get_lang('CourseSessionBlock'), $params, 'course_session_block');
  162. }
  163. /**
  164. * Returns a list of the most popular courses of the moment (also called
  165. * "hot courses").
  166. * @uses CourseManager::return_hot_courses() in fact, the current method is only a bypass to this method
  167. * @return string HTML <div> with the most popular courses
  168. * @assert () != ''
  169. */
  170. public function return_hot_courses()
  171. {
  172. return CourseManager::return_hot_courses();
  173. }
  174. /**
  175. * Returns an online help block read from the home/home_menu_[lang].html
  176. * file
  177. * @return string HTML block
  178. * @assert () != ''
  179. */
  180. public function return_help()
  181. {
  182. $home = api_get_home_path();
  183. $user_selected_language = api_get_interface_language();
  184. $sys_path = api_get_path(SYS_PATH);
  185. $platformLanguage = api_get_setting('platformLanguage');
  186. if (!isset($user_selected_language)) {
  187. $user_selected_language = $platformLanguage;
  188. }
  189. $home_menu = @(string)file_get_contents($sys_path.$home.'home_menu_'.$user_selected_language.'.html');
  190. if (!empty($home_menu)) {
  191. $home_menu_content = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
  192. $this->show_right_block(
  193. get_lang('MenuGeneral'),
  194. null,
  195. 'help_block',
  196. array('content' => $home_menu_content)
  197. );
  198. }
  199. }
  200. /**
  201. * Returns an HTML block with links to the skills tools
  202. * @return string HTML <div> block
  203. * @assert () != ''
  204. */
  205. public function return_skills_links()
  206. {
  207. if (api_get_setting('allow_skills_tool') == 'true') {
  208. $content = array();
  209. $content[] = array(
  210. 'title' => get_lang('MySkills'),
  211. 'href' => api_get_path(WEB_CODE_PATH).'social/skills_wheel.php'
  212. );
  213. if (api_get_setting('allow_hr_skills_management') == 'true' || api_is_platform_admin()) {
  214. $content[] = array(
  215. 'title' => get_lang('ManageSkills'),
  216. 'href' => api_get_path(WEB_CODE_PATH).'admin/skills_wheel.php'
  217. );
  218. }
  219. $this->show_right_block(get_lang("Skills"), $content, 'skill_block');
  220. }
  221. }
  222. /**
  223. * Returns an HTML block with the notice, as found in the
  224. * home/home_notice_[lang].html file
  225. * @return string HTML <div> block
  226. * @assert () != ''
  227. */
  228. public function return_notice()
  229. {
  230. $sys_path = api_get_path(SYS_PATH);
  231. $user_selected_language = api_get_interface_language();
  232. $home = api_get_home_path();
  233. // Notice
  234. $home_notice = @(string)file_get_contents($sys_path.$home.'home_notice_'.$user_selected_language.'.html');
  235. if (empty($home_notice)) {
  236. $home_notice = @(string)file_get_contents($sys_path.$home.'home_notice.html');
  237. }
  238. if (!empty($home_notice)) {
  239. $home_notice = api_to_system_encoding($home_notice, api_detect_encoding(strip_tags($home_notice)));
  240. $home_notice = Display::div($home_notice, array('class' => 'homepage_notice'));
  241. $this->show_right_block(get_lang('Notice'), null, 'notice_block', array('content' => $home_notice));
  242. }
  243. }
  244. /**
  245. * Returns the received content packaged in <div> block, with the title as
  246. * <h4>
  247. * @param string Title to include as h4
  248. * @param string Longer content to show (usually a <ul> list)
  249. * @param string ID to be added to the HTML attributes for the block
  250. * @param array Array of attributes to add to the HTML block
  251. * @return string HTML <div> block
  252. * @assert ('a','') != ''
  253. * @todo use the menu builder
  254. */
  255. public function show_right_block($title, $content, $id, $params = null)
  256. {
  257. $app = $this->app;
  258. if (!empty($id)) {
  259. $params['id'] = $id;
  260. }
  261. $block_menu = array(
  262. 'id' => $params['id'],
  263. 'title' => $title,
  264. 'elements' => $content,
  265. 'content' => isset($params['content']) ? $params['content'] : null
  266. );
  267. $app['template']->assign($id, $block_menu);
  268. }
  269. /**
  270. * Adds a form to let users login
  271. * @return string An HTML string with the user login form
  272. * @assert () != ''
  273. * @version 1.1
  274. */
  275. public function displayLoginForm()
  276. {
  277. $form = new FormValidator('formLogin', 'POST', null, null, array('class' => 'form-vertical'));
  278. // 'placeholder'=>get_lang('UserName')
  279. //'autocomplete'=>"off",
  280. $form->addElement(
  281. 'text',
  282. 'login',
  283. get_lang('UserName'),
  284. array('class' => 'span2 autocapitalize_off', 'autofocus' => 'autofocus')
  285. );
  286. $form->addElement('password', 'password', get_lang('Pass'), array('class' => 'span2'));
  287. $form->addElement('style_submit_button', 'submitAuth', get_lang('LoginEnter'), array('class' => 'btn'));
  288. $html = $form->return_form();
  289. if (api_get_setting('openid_authentication') == 'true') {
  290. include_once 'main/auth/openid/login.php';
  291. $html .= '<div>'.openid_form().'</div>';
  292. }
  293. return $html;
  294. }
  295. /**
  296. * Returns a content search form in an HTML <div>, pointing at the
  297. * main/search/ directory. If search_enabled is not set, then it returns
  298. * an empty string
  299. * @return string HTML <div> block showing the search form, or an empty string if search not enabled
  300. * @assert () !== false
  301. */
  302. public function return_search_block()
  303. {
  304. $html = '';
  305. if (api_get_setting('search_enabled') == 'true') {
  306. $html .= '<div class="searchbox">';
  307. $search_btn = get_lang('Search');
  308. $search_content = '<br />
  309. <form action="main/search/" method="post">
  310. <input type="text" id="query" class="span2" name="query" value="" />
  311. <button class="save" type="submit" name="submit" value="'.$search_btn.'" />'.$search_btn.' </button>
  312. </form></div>';
  313. $html .= $this->show_right_block(get_lang('Search'), $search_content, 'search_block');
  314. }
  315. return $html;
  316. }
  317. /**
  318. * Returns a list of announcements
  319. * @param int User ID
  320. * @param bool True: show the announcements as a slider. False: show them as a vertical list
  321. * @return string HTML list of announcements
  322. * @assert () != ''
  323. * @assert (1) != ''
  324. */
  325. public function return_announcements($user_id = null, $show_slide = true)
  326. {
  327. // Display System announcements
  328. $announcement = isset($_GET['announcement']) ? intval($_GET['announcement']) : null;
  329. if (!api_is_anonymous() && $user_id) {
  330. $visibility = api_is_allowed_to_create_course(
  331. ) ? SystemAnnouncementManager::VISIBLE_TEACHER : SystemAnnouncementManager::VISIBLE_STUDENT;
  332. if ($show_slide) {
  333. $announcements = SystemAnnouncementManager :: display_announcements_slider($visibility, $announcement);
  334. } else {
  335. $announcements = SystemAnnouncementManager :: display_all_announcements($visibility, $announcement);
  336. }
  337. } else {
  338. if ($show_slide) {
  339. $announcements = SystemAnnouncementManager :: display_announcements_slider(
  340. SystemAnnouncementManager::VISIBLE_GUEST,
  341. $announcement
  342. );
  343. } else {
  344. $announcements = SystemAnnouncementManager :: display_all_announcements(
  345. SystemAnnouncementManager::VISIBLE_GUEST,
  346. $announcement
  347. );
  348. }
  349. }
  350. return $announcements;
  351. }
  352. /**
  353. * Return the homepage, including announcements
  354. * @return string The portal's homepage as an HTML string
  355. * @assert () != ''
  356. */
  357. public function returnHomePage()
  358. {
  359. // Including the page for the news
  360. $html = null;
  361. $home = api_get_path(SYS_PATH).api_get_home_path();
  362. $home_top_temp = null;
  363. if (!empty($_GET['include']) && preg_match('/^[a-zA-Z0-9_-]*\.html$/', $_GET['include'])) {
  364. $open = @(string)file_get_contents(api_get_path(SYS_PATH).$home.$_GET['include']);
  365. $html = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
  366. } else {
  367. $user_selected_language = api_get_user_language();
  368. if (!file_exists($home.'home_news_'.$user_selected_language.'.html')) {
  369. if (file_exists($home.'home_top.html')) {
  370. $home_top_temp = file($home.'home_top.html');
  371. } else {
  372. //$home_top_temp = file('home/'.'home_top.html');
  373. }
  374. if (!empty($home_top_temp)) {
  375. $home_top_temp = implode('', $home_top_temp);
  376. }
  377. } else {
  378. if (file_exists($home.'home_top_'.$user_selected_language.'.html')) {
  379. $home_top_temp = file_get_contents($home.'home_top_'.$user_selected_language.'.html');
  380. } else {
  381. $home_top_temp = file_get_contents($home.'home_top.html');
  382. }
  383. }
  384. if (empty($home_top_temp) && api_is_platform_admin()) {
  385. $home_top_temp = get_lang('PortalHomepageDefaultIntroduction');
  386. }
  387. $open = str_replace('{rel_path}', api_get_path(REL_PATH), $home_top_temp);
  388. if (!empty($open)) {
  389. $html = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
  390. }
  391. }
  392. return $html;
  393. }
  394. /**
  395. * Returns the reservation block (if the reservation tool is enabled)
  396. * @return string HTML block, or empty string if reservation tool is disabled
  397. * @assert () == ''
  398. */
  399. public function return_reservation_block()
  400. {
  401. $html = '';
  402. $booking_content = null;
  403. if (api_get_setting('allow_reservation') == 'true' && api_is_allowed_to_create_course()) {
  404. $booking_content .= '<ul class="nav nav-list">';
  405. $booking_content .= '<a href="main/reservation/reservation.php">'.get_lang(
  406. 'ManageReservations'
  407. ).'</a><br />';
  408. $booking_content .= '</ul>';
  409. $html .= $this->show_right_block(get_lang('Booking'), $booking_content, 'reservation_block');
  410. }
  411. return $html;
  412. }
  413. /**
  414. * Returns an HTML block with classes (if show_groups_to_users is true)
  415. * @return string A list of links to users classes tools, or an empty string if show_groups_to_users is disabled
  416. * @assert () == ''
  417. */
  418. public function return_classes_block()
  419. {
  420. $html = '';
  421. if (api_get_setting('show_groups_to_users') == 'true') {
  422. $usergroup = new Usergroup();
  423. $usergroup_list = $usergroup->get_usergroup_by_user(api_get_user_id());
  424. $classes = '';
  425. if (!empty($usergroup_list)) {
  426. foreach ($usergroup_list as $group_id) {
  427. $data = $usergroup->get($group_id);
  428. $data['name'] = Display::url(
  429. $data['name'],
  430. api_get_path(WEB_CODE_PATH).'user/classes.php?id='.$data['id']
  431. );
  432. $classes .= Display::tag('li', $data['name']);
  433. }
  434. }
  435. if (api_is_platform_admin()) {
  436. $classes .= Display::tag(
  437. 'li',
  438. Display::url(get_lang('AddClasses'), api_get_path(WEB_CODE_PATH).'admin/usergroups.php?action=add')
  439. );
  440. }
  441. if (!empty($classes)) {
  442. $classes = Display::tag('ul', $classes, array('class' => 'nav nav-list'));
  443. $html .= $this->show_right_block(get_lang('Classes'), $classes, 'classes_block');
  444. }
  445. }
  446. return $html;
  447. }
  448. /**
  449. * Prepares a block with all the pending exercises in all courses
  450. * @param array Array of courses (arrays) of the user
  451. * @return void Doesn't return anything but prepares and HTML block for use in templates
  452. * @assert () !== 1
  453. */
  454. public function return_exercise_block($personal_course_list, $tpl)
  455. {
  456. $exercise_list = array();
  457. if (!empty($personal_course_list)) {
  458. foreach ($personal_course_list as $course_item) {
  459. $course_code = $course_item['c'];
  460. $session_id = $course_item['id_session'];
  461. $exercises = ExerciseLib::get_exercises_to_be_taken($course_code, $session_id);
  462. foreach ($exercises as $exercise_item) {
  463. $exercise_item['course_code'] = $course_code;
  464. $exercise_item['session_id'] = $session_id;
  465. $exercise_item['tms'] = api_strtotime($exercise_item['end_time'], 'UTC');
  466. $exercise_list[] = $exercise_item;
  467. }
  468. }
  469. if (!empty($exercise_list)) {
  470. $exercise_list = ArrayClass::msort($exercise_list, 'tms');
  471. $my_exercise = $exercise_list[0];
  472. $url = Display::url(
  473. $my_exercise['title'],
  474. api_get_path(
  475. WEB_CODE_PATH
  476. ).'exercice/overview.php?exerciseId='.$my_exercise['id'].'&cidReq='.$my_exercise['course_code'].'&id_session='.$my_exercise['session_id']
  477. );
  478. $tpl->assign('exercise_url', $url);
  479. $tpl->assign(
  480. 'exercise_end_date',
  481. api_convert_and_format_date($my_exercise['end_time'], DATE_FORMAT_SHORT)
  482. );
  483. }
  484. }
  485. }
  486. /**
  487. * Returns links to teachers tools (create course, etc) based on the user
  488. * in the active session
  489. * @return string HTML <div> block
  490. * @assert () == ''
  491. */
  492. public function return_teacher_link()
  493. {
  494. $user_id = api_get_user_id();
  495. if (!empty($user_id)) {
  496. // tabs that are deactivated are added here
  497. $show_menu = false;
  498. $show_create_link = false;
  499. $show_course_link = false;
  500. if (api_is_platform_admin() || api_is_course_admin() || api_is_allowed_to_create_course()) {
  501. $show_menu = true;
  502. $show_course_link = true;
  503. } else {
  504. if (api_get_setting('allow_students_to_browse_courses') == 'true') {
  505. $show_menu = true;
  506. $show_course_link = true;
  507. }
  508. }
  509. if ($show_menu && ($show_create_link || $show_course_link)) {
  510. $show_menu = true;
  511. } else {
  512. $show_menu = false;
  513. }
  514. }
  515. // My Account section
  516. $elements = array();
  517. if ($show_menu) {
  518. if ($show_create_link) {
  519. $elements[] = array(
  520. 'href' => api_get_path(WEB_CODE_PATH).'create_course/add_course.php',
  521. 'title' => (api_get_setting('course_validation') == 'true' ? get_lang(
  522. 'CreateCourseRequest'
  523. ) : get_lang('CourseCreate'))
  524. );
  525. }
  526. if ($show_course_link) {
  527. if (!api_is_drh() && !api_is_session_admin()) {
  528. $elements[] = array(
  529. 'href' => api_get_path(WEB_CODE_PATH).'auth/courses.php',
  530. 'title' => get_lang('CourseCatalog')
  531. );
  532. } else {
  533. $elements[] = array(
  534. 'href' => api_get_path(WEB_CODE_PATH).'dashboard/index.php',
  535. 'title' => get_lang('Dashboard')
  536. );
  537. }
  538. }
  539. }
  540. $this->show_right_block(get_lang('Courses'), $elements, 'teacher_block');
  541. }
  542. /**
  543. * Display list of courses in a category.
  544. * (for anonymous users)
  545. *
  546. * @version 1.1
  547. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University - refactoring and code cleaning
  548. * @author Julio Montoya <gugli100@gmail.com>, Beeznest template modifs
  549. * @assert () !== 0
  550. */
  551. public function return_courses_in_categories()
  552. {
  553. $result = '';
  554. $stok = Security::get_token();
  555. // Initialization.
  556. $user_identified = (api_get_user_id() > 0 && !api_is_anonymous());
  557. $web_course_path = api_get_path(WEB_COURSE_PATH);
  558. $category = Database::escape_string($_GET['category']);
  559. $setting_show_also_closed_courses = api_get_setting('show_closed_courses') == 'true';
  560. // Database table definitions.
  561. $main_course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
  562. $main_category_table = Database :: get_main_table(TABLE_MAIN_CATEGORY);
  563. // Get list of courses in category $category.
  564. $sql_get_course_list = "SELECT * FROM $main_course_table cours
  565. WHERE category_code = '".Database::escape_string($_GET['category'])."'
  566. ORDER BY title, UPPER(visual_code)";
  567. // Showing only the courses of the current access_url_id.
  568. if (api_is_multiple_url_enabled()) {
  569. $url_access_id = api_get_current_access_url_id();
  570. if ($url_access_id != -1) {
  571. $tbl_url_rel_course = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
  572. $sql_get_course_list = "SELECT * FROM $main_course_table as course INNER JOIN $tbl_url_rel_course as url_rel_course
  573. ON (url_rel_course.c_id = course.id)
  574. WHERE access_url_id = $url_access_id AND category_code = '".Database::escape_string(
  575. $_GET['category']
  576. )."' ORDER BY title, UPPER(visual_code)";
  577. }
  578. }
  579. // Removed: AND cours.visibility='".COURSE_VISIBILITY_OPEN_WORLD."'
  580. $sql_result_courses = Database::query($sql_get_course_list);
  581. while ($course_result = Database::fetch_array($sql_result_courses)) {
  582. $course_list[] = $course_result;
  583. }
  584. $platform_visible_courses = '';
  585. // $setting_show_also_closed_courses
  586. if ($user_identified) {
  587. if ($setting_show_also_closed_courses) {
  588. $platform_visible_courses = '';
  589. } else {
  590. $platform_visible_courses = " AND (t3.visibility='".COURSE_VISIBILITY_OPEN_WORLD."' OR t3.visibility='".COURSE_VISIBILITY_OPEN_PLATFORM."' )";
  591. }
  592. } else {
  593. if ($setting_show_also_closed_courses) {
  594. $platform_visible_courses = '';
  595. } else {
  596. $platform_visible_courses = " AND (t3.visibility='".COURSE_VISIBILITY_OPEN_WORLD."' )";
  597. }
  598. }
  599. $sqlGetSubCatList = "
  600. SELECT t1.name,t1.code,t1.parent_id,t1.children_count,COUNT(DISTINCT t3.code) AS nbCourse
  601. FROM $main_category_table t1
  602. LEFT JOIN $main_category_table t2 ON t1.code=t2.parent_id
  603. LEFT JOIN $main_course_table t3 ON (t3.category_code=t1.code $platform_visible_courses)
  604. WHERE t1.parent_id ".(empty($category) ? "IS NULL" : "='$category'")."
  605. GROUP BY t1.name,t1.code,t1.parent_id,t1.children_count ORDER BY t1.tree_pos, t1.name";
  606. // Showing only the category of courses of the current access_url_id
  607. if (api_is_multiple_url_enabled()) {
  608. $url_access_id = api_get_current_access_url_id();
  609. if ($url_access_id != -1) {
  610. $tbl_url_rel_course = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
  611. $sqlGetSubCatList = "
  612. SELECT t1.name,t1.code,t1.parent_id,t1.children_count,COUNT(DISTINCT t3.code) AS nbCourse
  613. FROM $main_category_table t1
  614. LEFT JOIN $main_category_table t2 ON t1.code=t2.parent_id
  615. LEFT JOIN $main_course_table t3 ON (t3.category_code=t1.code $platform_visible_courses)
  616. INNER JOIN $tbl_url_rel_course as url_rel_course
  617. ON (url_rel_course.c_id = t3.id)
  618. WHERE access_url_id = $url_access_id AND t1.parent_id ".(empty($category) ? "IS NULL" : "='$category'")."
  619. GROUP BY t1.name,t1.code,t1.parent_id,t1.children_count ORDER BY t1.tree_pos, t1.name";
  620. }
  621. }
  622. $resCats = Database::query($sqlGetSubCatList);
  623. $thereIsSubCat = false;
  624. if (Database::num_rows($resCats) > 0) {
  625. $htmlListCat = Display::page_header(get_lang('CatList'));
  626. $htmlListCat .= '<ul>';
  627. while ($catLine = Database::fetch_array($resCats)) {
  628. if ($catLine['code'] != $category) {
  629. $category_has_open_courses = $this->category_has_open_courses($catLine['code']);
  630. if ($category_has_open_courses) {
  631. // The category contains courses accessible to anonymous visitors.
  632. $htmlListCat .= '<li>';
  633. $htmlListCat .= '<a href="'.api_get_self(
  634. ).'?category='.$catLine['code'].'">'.$catLine['name'].'</a>';
  635. if (api_get_setting('show_number_of_courses') == 'true') {
  636. $htmlListCat .= ' ('.$catLine['nbCourse'].' '.get_lang('Courses').')';
  637. }
  638. $htmlListCat .= "</li>";
  639. $thereIsSubCat = true;
  640. } elseif ($catLine['children_count'] > 0) {
  641. // The category has children, subcategories.
  642. $htmlListCat .= '<li>';
  643. $htmlListCat .= '<a href="'.api_get_self(
  644. ).'?category='.$catLine['code'].'">'.$catLine['name'].'</a>';
  645. $htmlListCat .= "</li>";
  646. $thereIsSubCat = true;
  647. } /* End changed code to eliminate the (0 courses) after empty categories. */ elseif (api_get_setting(
  648. 'show_empty_course_categories'
  649. ) == 'true'
  650. ) {
  651. $htmlListCat .= '<li>';
  652. $htmlListCat .= $catLine['name'];
  653. $htmlListCat .= "</li>";
  654. $thereIsSubCat = true;
  655. } // Else don't set thereIsSubCat to true to avoid printing things if not requested.
  656. } else {
  657. $htmlTitre = '<p>';
  658. if (api_get_setting('show_back_link_on_top_of_tree') == 'true') {
  659. $htmlTitre .= '<a href="'.api_get_self().'">&lt;&lt; '.get_lang('BackToHomePage').'</a>';
  660. }
  661. if (!is_null($catLine['parent_id']) || (api_get_setting(
  662. 'show_back_link_on_top_of_tree'
  663. ) != 'true' && !is_null($catLine['code']))
  664. ) {
  665. $htmlTitre .= '<a href="'.api_get_self(
  666. ).'?category='.$catLine['parent_id'].'">&lt;&lt; '.get_lang('Up').'</a>';
  667. }
  668. $htmlTitre .= "</p>";
  669. if ($category != "" && !is_null($catLine['code'])) {
  670. $htmlTitre .= '<h3>'.$catLine['name']."</h3>";
  671. } else {
  672. $htmlTitre .= '<h3>'.get_lang('Categories')."</h3>";
  673. }
  674. }
  675. }
  676. $htmlListCat .= "</ul>";
  677. }
  678. $result .= $htmlTitre;
  679. if ($thereIsSubCat) {
  680. $result .= $htmlListCat;
  681. }
  682. while ($categoryName = Database::fetch_array($resCats)) {
  683. $result .= '<h3>'.$categoryName['name']."</h3>\n";
  684. }
  685. $numrows = Database::num_rows($sql_result_courses);
  686. $courses_list_string = '';
  687. $courses_shown = 0;
  688. if ($numrows > 0) {
  689. $courses_list_string .= Display::page_header(get_lang('CourseList'));
  690. $courses_list_string .= "<ul>";
  691. if (api_get_user_id()) {
  692. $courses_of_user = $this->get_courses_of_user(api_get_user_id());
  693. }
  694. foreach ($course_list as $course) {
  695. // $setting_show_also_closed_courses
  696. if (!$setting_show_also_closed_courses) {
  697. // If we do not show the closed courses
  698. // we only show the courses that are open to the world (to everybody)
  699. // and the courses that are open to the platform (if the current user is a registered user.
  700. if (($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM) || ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD)) {
  701. $courses_shown++;
  702. $courses_list_string .= "<li>\n";
  703. $courses_list_string .= '<a href="'.$web_course_path.$course['directory'].'/">'.$course['title'].'</a><br />';
  704. $course_details = array();
  705. if (api_get_setting('display_coursecode_in_courselist') == 'true') {
  706. $course_details[] = $course['visual_code'];
  707. }
  708. if (api_get_setting('display_teacher_in_courselist') == 'true') {
  709. $course_details[] = $course['tutor_name'];
  710. }
  711. if (api_get_setting(
  712. 'show_different_course_language'
  713. ) == 'true' && $course['course_language'] != api_get_setting('platformLanguage')
  714. ) {
  715. $course_details[] = $course['course_language'];
  716. }
  717. $courses_list_string .= implode(' - ', $course_details);
  718. $courses_list_string .= "</li>\n";
  719. }
  720. } else {
  721. // We DO show the closed courses.
  722. // The course is accessible if (link to the course homepage):
  723. // 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);
  724. // 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);
  725. // 3. the user is logged in and the user is subscribed to the course and the course visibility is not COURSE_VISIBILITY_CLOSED;
  726. // 4. the user is logged in and the user is course admin of te course (regardless of the course visibility setting);
  727. // 5. the user is the platform admin api_is_platform_admin().
  728. //
  729. $courses_shown++;
  730. $courses_list_string .= "<li>\n";
  731. if ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD
  732. || ($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM)
  733. || ($user_identified && key_exists(
  734. $course['code'],
  735. $courses_of_user
  736. ) && $course['visibility'] != COURSE_VISIBILITY_CLOSED)
  737. || $courses_of_user[$course['code']]['status'] == '1'
  738. || api_is_platform_admin()
  739. ) {
  740. $courses_list_string .= '<a href="'.$web_course_path.$course['directory'].'/">';
  741. }
  742. $courses_list_string .= $course['title'];
  743. if ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD
  744. || ($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM)
  745. || ($user_identified && key_exists(
  746. $course['code'],
  747. $courses_of_user
  748. ) && $course['visibility'] != COURSE_VISIBILITY_CLOSED)
  749. || $courses_of_user[$course['code']]['status'] == '1'
  750. || api_is_platform_admin()
  751. ) {
  752. $courses_list_string .= '</a><br />';
  753. }
  754. $course_details = array();
  755. if (api_get_setting('display_coursecode_in_courselist') == 'true') {
  756. $course_details[] = $course['visual_code'];
  757. }
  758. // if (api_get_setting('display_coursecode_in_courselist') == 'true' && api_get_setting('display_teacher_in_courselist') == 'true') {
  759. // $courses_list_string .= ' - ';
  760. // }
  761. if (api_get_setting('display_teacher_in_courselist') == 'true') {
  762. $course_details[] = $course['tutor_name'];
  763. }
  764. if (api_get_setting(
  765. 'show_different_course_language'
  766. ) == 'true' && $course['course_language'] != api_get_setting('platformLanguage')
  767. ) {
  768. $course_details[] = $course['course_language'];
  769. }
  770. if (api_get_setting(
  771. 'show_different_course_language'
  772. ) == 'true' && $course['course_language'] != api_get_setting('platformLanguage')
  773. ) {
  774. $course_details[] = $course['course_language'];
  775. }
  776. $courses_list_string .= implode(' - ', $course_details);
  777. // We display a subscription link if:
  778. // 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
  779. // 2.
  780. if ($user_identified && !key_exists($course['code'], $courses_of_user)) {
  781. if ($course['subscribe'] == '1') {
  782. $courses_list_string .= '<form action="main/auth/courses.php?action=subscribe&category='.Security::remove_XSS(
  783. $_GET['category']
  784. ).'" method="post">';
  785. $courses_list_string .= '<input type="hidden" name="sec_token" value="'.$stok.'">';
  786. $courses_list_string .= '<input type="hidden" name="subscribe" value="'.$course['code'].'" />';
  787. $courses_list_string .= '<input type="image" name="unsub" src="main/img/enroll.gif" alt="'.get_lang(
  788. 'Subscribe'
  789. ).'" />'.get_lang('Subscribe').'</form>';
  790. } else {
  791. $courses_list_string .= '<br />'.get_lang('SubscribingNotAllowed');
  792. }
  793. }
  794. $courses_list_string .= "</li>";
  795. } //end else
  796. } // end foreach
  797. $courses_list_string .= "</ul>";
  798. }
  799. if ($courses_shown > 0) {
  800. // Only display the list of courses and categories if there was more than
  801. // 0 courses visible to the world (we're in the anonymous list here).
  802. $result .= $courses_list_string;
  803. }
  804. if ($category != '') {
  805. $result .= '<p><a href="'.api_get_self().'"> '.Display :: return_icon(
  806. 'back.png',
  807. get_lang('BackToHomePage')
  808. ).get_lang('BackToHomePage').'</a></p>';
  809. }
  810. return $result;
  811. }
  812. public function returnMyCourseCategories($user_id, $filter, $page)
  813. {
  814. if (empty($user_id)) {
  815. return false;
  816. }
  817. $loadDirs = api_get_setting('show_documents_preview') == 'true' ? true : false;
  818. $start = ($page - 1) * $this->maxPerPage;
  819. $nbResults = (int)CourseManager::displayPersonalCourseCategories($user_id, $filter, $loadDirs, true);
  820. $html = CourseManager::displayPersonalCourseCategories(
  821. $user_id,
  822. $filter,
  823. $loadDirs,
  824. false,
  825. $start,
  826. $this->maxPerPage
  827. );
  828. $adapter = new FixedAdapter($nbResults, array());
  829. $pagerfanta = new Pagerfanta($adapter);
  830. $pagerfanta->setMaxPerPage($this->maxPerPage); // 10 by default
  831. $pagerfanta->setCurrentPage($page); // 1 by default
  832. $this->app['pagerfanta.view.router.name'] = 'userportal';
  833. $this->app['pagerfanta.view.router.params'] = array(
  834. 'filter' => $filter,
  835. 'type' => 'courses',
  836. 'page' => $page
  837. );
  838. $this->app['template']->assign('pagination', $pagerfanta);
  839. return $html;
  840. }
  841. function returnSpecialCourses($user_id, $filter, $page)
  842. {
  843. if (empty($user_id)) {
  844. return false;
  845. }
  846. $loadDirs = api_get_setting('show_documents_preview') == 'true' ? true : false;
  847. $start = ($page - 1) * $this->maxPerPage;
  848. $nbResults = CourseManager::displaySpecialCourses($user_id, $filter, $loadDirs, true);
  849. $html = CourseManager::displaySpecialCourses($user_id, $filter, $loadDirs, false, $start, $this->maxPerPage);
  850. if (!empty($html)) {
  851. $adapter = new FixedAdapter($nbResults, array());
  852. $pagerfanta = new Pagerfanta($adapter);
  853. $pagerfanta->setMaxPerPage($this->maxPerPage); // 10 by default
  854. $pagerfanta->setCurrentPage($page); // 1 by default
  855. $this->app['pagerfanta.view.router.name'] = 'userportal';
  856. $this->app['pagerfanta.view.router.params'] = array(
  857. 'filter' => $filter,
  858. 'type' => 'courses',
  859. 'page' => $page
  860. );
  861. $this->app['template']->assign('pagination', $pagerfanta);
  862. }
  863. return $html;
  864. }
  865. /**
  866. * The most important function here, prints the session and course list (user_portal.php)
  867. *
  868. * @param int User ID
  869. * @param string filter
  870. * @param int page
  871. * @return string HTML list of sessions and courses
  872. * @assert () === false
  873. *
  874. */
  875. public function returnCourses($user_id, $filter, $page)
  876. {
  877. if (empty($user_id)) {
  878. return false;
  879. }
  880. $loadDirs = api_get_setting('show_documents_preview') == 'true' ? true : false;
  881. $start = ($page - 1) * $this->maxPerPage;
  882. $nbResults = CourseManager::displayCourses($user_id, $filter, $loadDirs, true);
  883. $html = CourseManager::displayCourses($user_id, $filter, $loadDirs, false, $start, $this->maxPerPage);
  884. if (!empty($html)) {
  885. $adapter = new FixedAdapter($nbResults, array());
  886. $pagerfanta = new Pagerfanta($adapter);
  887. $pagerfanta->setMaxPerPage($this->maxPerPage); // 10 by default
  888. $pagerfanta->setCurrentPage($page); // 1 by default
  889. /*
  890. Original pagination construction
  891. $view = new TwitterBootstrapView();
  892. $routeGenerator = function($page) use ($app, $filter) {
  893. return $app['url_generator']->generate('userportal', array(
  894. 'filter' => $filter,
  895. 'type' => 'courses',
  896. 'page' => $page)
  897. );
  898. };
  899. $pagination = $view->render($pagerfanta, $routeGenerator, array(
  900. 'proximity' => 3,
  901. ));
  902. */
  903. //Pagination using the pagerfanta silex service provider
  904. $this->app['pagerfanta.view.router.name'] = 'userportal';
  905. $this->app['pagerfanta.view.router.params'] = array(
  906. 'filter' => $filter,
  907. 'type' => 'courses',
  908. 'page' => $page
  909. );
  910. $this->app['template']->assign('pagination', $pagerfanta);
  911. }
  912. return $html;
  913. }
  914. public function returnSessionsCategories($user_id, $filter, $page)
  915. {
  916. if (empty($user_id)) {
  917. return false;
  918. }
  919. $load_history = (isset($filter) && $filter == 'history') ? true : false;
  920. $start = ($page - 1) * $this->maxPerPage;
  921. $nbResults = UserManager::getCategories($user_id, false, true, true);
  922. $session_categories = UserManager::getCategories($user_id, false, false, true, $start, $this->maxPerPage);
  923. $html = null;
  924. //Showing history title
  925. if ($load_history) {
  926. $html .= Display::page_subheader(get_lang('HistoryTrainingSession'));
  927. if (empty($session_categories)) {
  928. $html .= get_lang('YouDoNotHaveAnySessionInItsHistory');
  929. }
  930. }
  931. $load_directories_preview = api_get_setting('show_documents_preview') == 'true' ? true : false;
  932. $sessions_with_category = $html;
  933. if (isset($session_categories) && !empty($session_categories)) {
  934. foreach ($session_categories as $session_category) {
  935. $session_category_id = $session_category['session_category']['id'];
  936. // All sessions included in
  937. $count_courses_session = 0;
  938. $html_sessions = '';
  939. foreach ($session_category['sessions'] as $session) {
  940. $session_id = $session['session_id'];
  941. // Don't show empty sessions.
  942. if (count($session['courses']) < 1) {
  943. continue;
  944. }
  945. $html_courses_session = '';
  946. $count = 0;
  947. foreach ($session['courses'] as $course) {
  948. if (api_get_setting('hide_courses_in_sessions') == 'false') {
  949. $html_courses_session .= CourseManager::get_logged_user_course_html($course, $session_id);
  950. }
  951. $count_courses_session++;
  952. $count++;
  953. }
  954. $params = array();
  955. if ($count > 0) {
  956. $params['icon'] = Display::return_icon(
  957. 'window_list.png',
  958. $session['session_name'],
  959. array('id' => 'session_img_'.$session_id),
  960. ICON_SIZE_LARGE
  961. );
  962. //Default session name
  963. $session_link = $session['session_name'];
  964. $params['link'] = null;
  965. if (api_get_setting('session_page_enabled') == 'true' && !api_is_drh()) {
  966. //session name with link
  967. $session_link = Display::tag(
  968. 'a',
  969. $session['session_name'],
  970. array('href' => api_get_path(WEB_CODE_PATH).'session/index.php?session_id='.$session_id)
  971. );
  972. $params['link'] = api_get_path(WEB_CODE_PATH).'session/index.php?session_id='.$session_id;
  973. }
  974. $params['title'] = $session_link;
  975. $moved_status = SessionManager::get_session_change_user_reason($session['moved_status']);
  976. $moved_status = isset($moved_status) && !empty($moved_status) ? ' ('.$moved_status.')' : null;
  977. $params['subtitle'] = isset($session['coach_info']) ? $session['coach_info']['complete_name'] : null.$moved_status;
  978. $params['dates'] = $session['date_message'];
  979. if (api_is_platform_admin()) {
  980. $params['right_actions'] = '<a href="'.api_get_path(
  981. WEB_CODE_PATH
  982. ).'admin/resume_session.php?id_session='.$session_id.'">'.Display::return_icon(
  983. 'edit.png',
  984. get_lang('Edit'),
  985. array('align' => 'absmiddle'),
  986. ICON_SIZE_SMALL
  987. ).'</a>';
  988. }
  989. $html_sessions .= CourseManager::course_item_html($params, true).$html_courses_session;
  990. }
  991. }
  992. if ($count_courses_session > 0) {
  993. $params = array();
  994. $params['icon'] = Display::return_icon(
  995. 'folder_blue.png',
  996. $session_category['session_category']['name'],
  997. array(),
  998. ICON_SIZE_LARGE
  999. );
  1000. if (api_is_platform_admin()) {
  1001. $params['right_actions'] = '<a href="'.api_get_path(
  1002. WEB_CODE_PATH
  1003. ).'admin/session_category_edit.php?&id='.$session_category['session_category']['id'].'">'.Display::return_icon(
  1004. 'edit.png',
  1005. get_lang('Edit'),
  1006. array(),
  1007. ICON_SIZE_SMALL
  1008. ).'</a>';
  1009. }
  1010. $params['title'] = $session_category['session_category']['name'];
  1011. if (api_is_platform_admin()) {
  1012. $params['link'] = api_get_path(
  1013. WEB_CODE_PATH
  1014. ).'admin/session_category_edit.php?&id='.$session_category['session_category']['id'];
  1015. }
  1016. $session_category_start_date = $session_category['session_category']['date_start'];
  1017. $session_category_end_date = $session_category['session_category']['date_end'];
  1018. 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') {
  1019. $params['subtitle'] = sprintf(
  1020. get_lang('FromDateXToDateY'),
  1021. $session_category['session_category']['date_start'],
  1022. $session_category['session_category']['date_end']
  1023. );
  1024. } else {
  1025. if (!empty($session_category_start_date) && $session_category_start_date != '0000-00-00') {
  1026. $params['subtitle'] = get_lang('From').' '.$session_category_start_date;
  1027. }
  1028. if (!empty($session_category_end_date) && $session_category_end_date != '0000-00-00') {
  1029. $params['subtitle'] = get_lang('Until').' '.$session_category_end_date;
  1030. }
  1031. }
  1032. $sessions_with_category .= CourseManager::course_item_parent(
  1033. CourseManager::course_item_html($params, true),
  1034. $html_sessions
  1035. );
  1036. }
  1037. }
  1038. //Pagination
  1039. $adapter = new FixedAdapter($nbResults, array());
  1040. $pagerfanta = new Pagerfanta($adapter);
  1041. $pagerfanta->setMaxPerPage($this->maxPerPage); // 10 by default
  1042. $pagerfanta->setCurrentPage($page); // 1 by default
  1043. $this->app['pagerfanta.view.router.name'] = 'userportal';
  1044. $this->app['pagerfanta.view.router.params'] = array(
  1045. 'filter' => $filter,
  1046. 'type' => 'sessioncategories',
  1047. 'page' => $page
  1048. );
  1049. $this->app['template']->assign('pagination', $pagerfanta);
  1050. }
  1051. return $sessions_with_category;
  1052. }
  1053. public function returnSessions($user_id, $filter, $page)
  1054. {
  1055. if (empty($user_id)) {
  1056. return false;
  1057. }
  1058. $app = $this->app;
  1059. $loadHistory = (isset($filter) && $filter == 'history') ? true : false;
  1060. $app['session_menu'] = function ($app) use ($loadHistory) {
  1061. $menu = $app['knp_menu.factory']->createItem(
  1062. 'root',
  1063. array(
  1064. 'childrenAttributes' => array(
  1065. 'class' => 'nav nav-tabs',
  1066. 'currentClass' => 'active'
  1067. )
  1068. )
  1069. );
  1070. //$menu->setUri($app['request']->getRequestUri());
  1071. /*
  1072. $menu->setChildrenAttributes(array(
  1073. 'currentClass' => 'active'
  1074. ));*/
  1075. $current = $menu->addChild(
  1076. get_lang('Current'),
  1077. array(
  1078. 'route' => 'userportal',
  1079. 'routeParameters' => array(
  1080. 'filter' => 'current',
  1081. 'type' => 'sessions'
  1082. )
  1083. )
  1084. );
  1085. $history = $menu->addChild(
  1086. get_lang('HistoryTrainingSession'),
  1087. array(
  1088. 'route' => 'userportal',
  1089. 'routeParameters' => array(
  1090. 'filter' => 'history',
  1091. 'type' => 'sessions'
  1092. )
  1093. )
  1094. );
  1095. //@todo use URIVoter
  1096. if ($loadHistory) {
  1097. $history->setCurrent(true);
  1098. } else {
  1099. $current->setCurrent(true);
  1100. }
  1101. return $menu;
  1102. };
  1103. //@todo move this in template
  1104. $app['knp_menu.menus'] = array('actions_menu' => 'session_menu');
  1105. $start = ($page - 1) * $this->maxPerPage;
  1106. if ($loadHistory) {
  1107. //Load sessions in category in *history*
  1108. $nbResults = (int)UserManager::get_sessions_by_category(
  1109. $user_id,
  1110. true,
  1111. true,
  1112. true,
  1113. null,
  1114. null,
  1115. 'no_category'
  1116. );
  1117. $session_categories = UserManager::get_sessions_by_category(
  1118. $user_id,
  1119. true,
  1120. false,
  1121. true,
  1122. $start,
  1123. $this->maxPerPage,
  1124. 'no_category'
  1125. );
  1126. } else {
  1127. //Load sessions in category
  1128. $nbResults = (int)UserManager::get_sessions_by_category(
  1129. $user_id,
  1130. false,
  1131. true,
  1132. false,
  1133. null,
  1134. null,
  1135. 'no_category'
  1136. );
  1137. $session_categories = UserManager::get_sessions_by_category(
  1138. $user_id,
  1139. false,
  1140. false,
  1141. false,
  1142. $start,
  1143. $this->maxPerPage,
  1144. 'no_category'
  1145. );
  1146. }
  1147. $html = null;
  1148. //Showing history title
  1149. if ($loadHistory) {
  1150. // $html .= Display::page_subheader(get_lang('HistoryTrainingSession'));
  1151. if (empty($session_categories)) {
  1152. $html .= get_lang('YouDoNotHaveAnySessionInItsHistory');
  1153. }
  1154. }
  1155. $load_directories_preview = api_get_setting('show_documents_preview') == 'true' ? true : false;
  1156. $sessions_with_no_category = $html;
  1157. if (isset($session_categories) && !empty($session_categories)) {
  1158. foreach ($session_categories as $session_category) {
  1159. $session_category_id = $session_category['session_category']['id'];
  1160. // Sessions does not belong to a session category
  1161. if ($session_category_id == 0) {
  1162. // Independent sessions
  1163. if (isset($session_category['sessions'])) {
  1164. foreach ($session_category['sessions'] as $session) {
  1165. $session_id = $session['session_id'];
  1166. // Don't show empty sessions.
  1167. if (count($session['courses']) < 1) {
  1168. continue;
  1169. }
  1170. $html_courses_session = '';
  1171. $count_courses_session = 0;
  1172. foreach ($session['courses'] as $course) {
  1173. //Read only and accessible
  1174. if (api_get_setting('hide_courses_in_sessions') == 'false') {
  1175. $html_courses_session .= CourseManager::get_logged_user_course_html(
  1176. $course,
  1177. $session_id,
  1178. $load_directories_preview
  1179. );
  1180. }
  1181. $count_courses_session++;
  1182. }
  1183. if ($count_courses_session > 0) {
  1184. $params = array();
  1185. $params['icon'] = Display::return_icon(
  1186. 'window_list.png',
  1187. $session['session_name'],
  1188. array('id' => 'session_img_'.$session_id),
  1189. ICON_SIZE_LARGE
  1190. );
  1191. $params['is_session'] = true;
  1192. //Default session name
  1193. $session_link = $session['session_name'];
  1194. $params['link'] = null;
  1195. if (api_get_setting('session_page_enabled') == 'true' && !api_is_drh()) {
  1196. //session name with link
  1197. $session_link = Display::tag(
  1198. 'a',
  1199. $session['session_name'],
  1200. array(
  1201. 'href' => api_get_path(
  1202. WEB_CODE_PATH
  1203. ).'session/index.php?session_id='.$session_id
  1204. )
  1205. );
  1206. $params['link'] = api_get_path(
  1207. WEB_CODE_PATH
  1208. ).'session/index.php?session_id='.$session_id;
  1209. }
  1210. $params['title'] = $session_link;
  1211. $moved_status = SessionManager::get_session_change_user_reason(
  1212. $session['moved_status']
  1213. );
  1214. $moved_status = isset($moved_status) && !empty($moved_status) ? ' ('.$moved_status.')' : null;
  1215. $params['subtitle'] = isset($session['coach_info']) ? $session['coach_info']['complete_name'] : null.$moved_status;
  1216. $params['dates'] = $session['date_message'];
  1217. $params['right_actions'] = '';
  1218. if (api_is_platform_admin()) {
  1219. $params['right_actions'] .= '<a href="'.api_get_path(
  1220. WEB_CODE_PATH
  1221. ).'admin/resume_session.php?id_session='.$session_id.'">';
  1222. $params['right_actions'] .= Display::return_icon(
  1223. 'edit.png',
  1224. get_lang('Edit'),
  1225. array('align' => 'absmiddle'),
  1226. ICON_SIZE_SMALL
  1227. ).'</a>';
  1228. }
  1229. if (api_get_setting('hide_courses_in_sessions') == 'false') {
  1230. // $params['extra'] .= $html_courses_session;
  1231. }
  1232. $sessions_with_no_category .= CourseManager::course_item_parent(
  1233. CourseManager::course_item_html($params, true),
  1234. $html_courses_session
  1235. );
  1236. }
  1237. }
  1238. }
  1239. }
  1240. }
  1241. $adapter = new FixedAdapter($nbResults, array());
  1242. $pagerfanta = new Pagerfanta($adapter);
  1243. $pagerfanta->setMaxPerPage($this->maxPerPage); // 10 by default
  1244. $pagerfanta->setCurrentPage($page); // 1 by default
  1245. $this->app['pagerfanta.view.router.name'] = 'userportal';
  1246. $this->app['pagerfanta.view.router.params'] = array(
  1247. 'filter' => $filter,
  1248. 'type' => 'sessions',
  1249. 'page' => $page
  1250. );
  1251. $this->app['template']->assign('pagination', $pagerfanta);
  1252. }
  1253. return $sessions_with_no_category;
  1254. }
  1255. /**
  1256. * Shows a welcome message when the user doesn't have any content in
  1257. * the course list
  1258. * @param object A Template object used to declare variables usable in the given template
  1259. * @return void
  1260. * @assert () === false
  1261. */
  1262. public function return_welcome_to_course_block($tpl)
  1263. {
  1264. if (empty($tpl)) {
  1265. return false;
  1266. }
  1267. $count_courses = CourseManager::count_courses();
  1268. $course_catalog_url = api_get_path(WEB_CODE_PATH).'auth/courses.php';
  1269. $course_list_url = api_get_path(WEB_PATH).'user_portal.php';
  1270. $tpl->assign('course_catalog_url', $course_catalog_url);
  1271. $tpl->assign('course_list_url', $course_list_url);
  1272. $tpl->assign('course_catalog_link', Display::url(get_lang('here'), $course_catalog_url));
  1273. $tpl->assign('course_list_link', Display::url(get_lang('here'), $course_list_url));
  1274. $tpl->assign('count_courses', $count_courses);
  1275. $tpl->assign('welcome_to_course_block', 1);
  1276. }
  1277. /**
  1278. * @param array
  1279. */
  1280. public function returnNavigationLinks($items)
  1281. {
  1282. // Main navigation section.
  1283. // Tabs that are deactivated are added here.
  1284. if (!empty($items)) {
  1285. $content = '<ul class="nav nav-list">';
  1286. foreach ($items as $section => $navigation_info) {
  1287. $current = isset($GLOBALS['this_section']) && $section == $GLOBALS['this_section'] ? ' id="current"' : '';
  1288. $content .= '<li '.$current.'>';
  1289. $content .= '<a href="'.$navigation_info['url'].'" target="_self">'.$navigation_info['title'].'</a>';
  1290. $content .= '</li>';
  1291. }
  1292. $content .= '</ul>';
  1293. $this->show_right_block(get_lang('MainNavigation'), null, 'navigation_block', array('content' => $content));
  1294. }
  1295. }
  1296. }