page.lib.php 62 KB

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