page.lib.php 61 KB

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