courses_categories.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * View (MVC patter) for courses categories
  5. * @author Christian Fasanando <christian1827@gmail.com> - Beeznest
  6. * @package chamilo.auth
  7. */
  8. if (isset($_REQUEST['action']) && Security::remove_XSS($_REQUEST['action']) !== 'subscribe') {
  9. $stok = Security::get_token();
  10. } else {
  11. $stok = $_SESSION['sec_token'];
  12. }
  13. $showCourses = CoursesAndSessionsCatalog::showCourses();
  14. $showSessions = CoursesAndSessionsCatalog::showSessions();
  15. $pageCurrent = isset($pageCurrent) ? $pageCurrent : isset($_GET['pageCurrent']) ? intval($_GET['pageCurrent']) : 1;
  16. $pageLength = isset($pageLength) ? $pageLength : isset($_GET['pageLength']) ? intval($_GET['pageLength']) : CoursesAndSessionsCatalog::PAGE_LENGTH;
  17. $pageTotal = intval(ceil(intval($countCoursesInCategory) / $pageLength));
  18. $cataloguePagination = $pageTotal > 1 ? CourseCategory::getCatalogPagination($pageCurrent, $pageLength, $pageTotal) : '';
  19. $search_term = isset($search_term) ? $search_term : null;
  20. if ($showSessions && isset($_POST['date'])) {
  21. $date = $_POST['date'];
  22. } else {
  23. $date = date('Y-m-d');
  24. }
  25. $userInfo = api_get_user_info();
  26. $code = isset($code) ? $code : null;
  27. ?>
  28. <script>
  29. $(document).ready( function() {
  30. $('.star-rating li a').on('click', function(event) {
  31. var id = $(this).parents('ul').attr('id');
  32. $('#vote_label2_' + id).html("<?php echo get_lang('Loading'); ?>");
  33. $.ajax({
  34. url: $(this).attr('data-link'),
  35. success: function(data) {
  36. $("#rating_wrapper_"+id).html(data);
  37. if(data == 'added') {
  38. //$('#vote_label2_' + id).html("{'Saved'|get_lang}");
  39. }
  40. if(data == 'updated') {
  41. //$('#vote_label2_' + id).html("{'Saved'|get_lang}");
  42. }
  43. }
  44. });
  45. });
  46. var getSessionId = function (el) {
  47. var parts = el.id.split('_');
  48. return parseInt(parts[1], 10);
  49. };
  50. <?php if ($showSessions) { ?>
  51. $('#date').datepicker({
  52. dateFormat: 'yy-mm-dd'
  53. });
  54. <?php } ?>
  55. });
  56. </script>
  57. <div class="row">
  58. <div class="col-md-12">
  59. <h2 class="title-courses"><?php echo get_lang('CourseManagement'); ?></h2>
  60. <div class="search-courses">
  61. <div class="row">
  62. <div class="col-md-6">
  63. <?php
  64. if ($showCourses) {
  65. if (!isset($_GET['hidden_links']) || intval($_GET['hidden_links']) != 1) { ?>
  66. <form method="post" action="<?php echo CourseCategory::getCourseCategoryUrl(1, $pageLength, 'ALL', 0, 'subscribe'); ?>">
  67. <input type="hidden" name="sec_token" value="<?php echo $stok; ?>">
  68. <input type="hidden" name="search_course" value="1" />
  69. <label><?php echo get_lang('Search'); ?></label>
  70. <div class="input-group">
  71. <input class="form-control" type="text" name="search_term" value="<?php echo (empty($_POST['search_term']) ? '' : api_htmlentities(Security::remove_XSS($_POST['search_term']))); ?>" />
  72. <div class="input-group-btn">
  73. <button class="btn btn-default" type="submit">
  74. <em class="fa fa-search"></em> <?php echo get_lang('Search'); ?>
  75. </button>
  76. </div>
  77. </div>
  78. </form>
  79. <?php } ?>
  80. </div>
  81. <div class="col-md-6">
  82. <?php
  83. $webAction = api_get_path(WEB_CODE_PATH).'auth/courses.php';
  84. $action = (!empty($_REQUEST['action']) ? Security::remove_XSS($_REQUEST['action']) : 'display_courses');
  85. $pageLength = !empty($_REQUEST['pageLength']) ? intval($_REQUEST['pageLength']) : CoursesAndSessionsCatalog::PAGE_LENGTH;
  86. $pageCurrent = !empty($_REQUEST['pageCurrent']) ? intval($_REQUEST['pageCurrent']) : 1;
  87. $form = '<form action="'.$webAction.'" method="GET" >';
  88. $form .= '<input type="hidden" name="action" value="'.$action.'">';
  89. $form .= '<input type="hidden" name="pageCurrent" value="'.$pageCurrent.'">';
  90. $form .= '<input type="hidden" name="pageLength" value="'.$pageLength.'">';
  91. $form .= '<div class="form-group">';
  92. $form .= '<label>'.get_lang('CourseCategories').'</label>';
  93. $form .= '<select name="category_code" onchange="submit();" class="selectpicker show-tick form-control">';
  94. $codeType = isset($_REQUEST['category_code']) ? Security::remove_XSS($_REQUEST['category_code']) : '';
  95. foreach ($browse_course_categories[0] as $category) {
  96. $categoryCode = $category['code'];
  97. $countCourse = $category['count_courses'];
  98. $form .= '<option '.($categoryCode == $codeType ? 'selected="selected" ' : '').' value="'.$category['code'].'">'.$category['name'].' ( '.$countCourse.' ) </option>';
  99. if (!empty($browse_course_categories[$categoryCode])) {
  100. foreach ($browse_course_categories[$categoryCode] as $subCategory) {
  101. $subCategoryCode = $subCategory['code'];
  102. $form .= '<option '.($subCategoryCode == $codeType ? 'selected="selected" ' : '').' value="'.$subCategory['code'].'"> ---'.$subCategory['name'].' ( '.$subCategory['count_courses'].' ) </option>';
  103. }
  104. }
  105. }
  106. $form .= '</select>';
  107. $form .= '</form>';
  108. echo $form;
  109. ?>
  110. </div>
  111. </div>
  112. </div>
  113. </div>
  114. <?php if ($showSessions) { ?>
  115. <div class="return-catalog">
  116. <a class="btn btn-default btn-lg btn-block" href="<?php echo CourseCategory::getCourseCategoryUrl(1, $pageLength, null, 0, 'display_sessions'); ?>">
  117. <em class="fa fa-arrow-right"></em> <?php echo get_lang('SessionList'); ?>
  118. </a>
  119. </div>
  120. <?php } ?>
  121. </div>
  122. <?php } ?>
  123. <div class="grid-courses">
  124. <div class="row">
  125. <?php
  126. if ($showCourses && $action != 'display_sessions') {
  127. if (!empty($message)) {
  128. echo Display::return_message($message, 'confirmation', false);
  129. }
  130. if (!empty($error)) {
  131. echo Display::return_message($error, 'error', false);
  132. }
  133. if (!empty($content)) {
  134. echo $content;
  135. }
  136. if (!empty($search_term)) {
  137. echo "<p><strong>".get_lang('SearchResultsFor')." ".Security::remove_XSS($_POST['search_term'])."</strong><br />";
  138. }
  139. $ajax_url = api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=add_course_vote';
  140. $user_id = api_get_user_id();
  141. $categoryList = CourseManager::getCategoriesList();
  142. if (!empty($browse_courses_in_category)) {
  143. foreach ($browse_courses_in_category as $course) {
  144. $course_hidden = $course['visibility'] == COURSE_VISIBILITY_HIDDEN;
  145. if ($course_hidden) {
  146. continue;
  147. }
  148. $userRegisteredInCourse = CourseManager::is_user_subscribed_in_course($user_id, $course['code']);
  149. $userRegisteredInCourseAsTeacher = CourseManager::is_course_teacher($user_id, $course['code']);
  150. $userRegistered = $userRegisteredInCourse && $userRegisteredInCourseAsTeacher;
  151. $course_public = $course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD;
  152. $course_open = $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM;
  153. $course_private = $course['visibility'] == COURSE_VISIBILITY_REGISTERED;
  154. $course_closed = $course['visibility'] == COURSE_VISIBILITY_CLOSED;
  155. $course_subscribe_allowed = ($course['subscribe'] == 1);
  156. $course_unsubscribe_allowed = ($course['unsubscribe'] == 1);
  157. $count_connections = $course['count_connections'];
  158. $creation_date = substr($course['creation_date'], 0, 10);
  159. $html = null;
  160. // display the course bloc
  161. $html .= '<div class="col-xs-12 col-sm-6 col-md-4"><div class="items items-courses">';
  162. $course['category_title'] = '';
  163. if (isset($course['category'])) {
  164. $course['category_title'] = isset($categoryList[$course['category']]) ? $categoryList[$course['category']] : '';
  165. }
  166. // display thumbnail
  167. $html .= returnThumbnail($course, $userRegistered);
  168. $separator = '<div class="separator">&nbsp;</div>';
  169. $subscribeButton = return_register_button($course, $stok, $code, $search_term);
  170. // start buycourse validation
  171. // display the course price and buy button if the buycourses plugin is enabled and this course is configured
  172. $plugin = BuyCoursesPlugin::create();
  173. $isThisCourseInSale = $plugin->buyCoursesForGridCatalogValidator(
  174. $course['real_id'],
  175. BuyCoursesPlugin::PRODUCT_TYPE_COURSE
  176. );
  177. if ($isThisCourseInSale) {
  178. // set the Price label
  179. $separator = $isThisCourseInSale['html'];
  180. // set the Buy button instead register.
  181. if ($isThisCourseInSale['verificator']) {
  182. $subscribeButton = $plugin->returnBuyCourseButton(
  183. $course['real_id'],
  184. BuyCoursesPlugin::PRODUCT_TYPE_COURSE
  185. );
  186. }
  187. }
  188. // end buycourse validation
  189. // display course title and button bloc
  190. $html .= '<div class="description">';
  191. $html .= return_title($course, $userRegisteredInCourse);
  192. $html .= return_teacher($course);
  193. // display button line
  194. $html .= '<div class="toolbar">';
  195. $html .= '<div class="left">';
  196. $html .= $separator;
  197. $html .= '</div>';
  198. $html .= '<div class="right">';
  199. $html .= '<div class="btn-group">';
  200. // if user registered as student
  201. if ($userRegisteredInCourse) {
  202. $html .= return_already_registered_label('student');
  203. if (!$course_closed) {
  204. if ($course_unsubscribe_allowed) {
  205. $html .= return_unregister_button($course, $stok, $search_term, $code);
  206. }
  207. }
  208. } elseif ($userRegisteredInCourseAsTeacher) {
  209. // if user registered as teacher
  210. if ($course_unsubscribe_allowed) {
  211. $html .= return_unregister_button($course, $stok, $search_term, $code);
  212. }
  213. } else {
  214. // if user not registered in the course
  215. if (!$course_closed) {
  216. if (!$course_private) {
  217. if ($course_subscribe_allowed) {
  218. $html .= $subscribeButton;
  219. }
  220. }
  221. }
  222. }
  223. $html .= '</div>';
  224. $html .= '</div>';
  225. $html .= '</div>';
  226. $html .= '</div>';
  227. $html .= '</div>';
  228. $html .= '</div>';
  229. echo $html;
  230. }
  231. } else {
  232. if (!isset($_REQUEST['subscribe_user_with_password']) &&
  233. !isset($_REQUEST['subscribe_course'])
  234. ) {
  235. echo Display::return_message(get_lang('ThereAreNoCoursesInThisCategory'), 'warning');
  236. }
  237. }
  238. }
  239. ?>
  240. </div>
  241. </div>
  242. <?php
  243. echo $cataloguePagination;
  244. /**
  245. * Display the course catalog image of a course
  246. * @param array $course
  247. *
  248. * @return string HTML string
  249. */
  250. function returnThumbnail($course, $registeredUser)
  251. {
  252. $html = '';
  253. $title = cut($course['title'], 70);
  254. $linkCourse = api_get_course_url($course['code']);
  255. // course path
  256. $course_path = api_get_path(SYS_COURSE_PATH).$course['directory'];
  257. if (file_exists($course_path.'/course-pic.png')) {
  258. $course_medium_image = api_get_path(WEB_COURSE_PATH).$course['directory'].'/course-pic.png'; // redimensioned image 85x85
  259. } else {
  260. // without picture
  261. $course_medium_image = Display::return_icon(
  262. 'session_default.png',
  263. null,
  264. null,
  265. null,
  266. null,
  267. true
  268. );
  269. }
  270. $html .= '<div class="image">';
  271. if (!$registeredUser) {
  272. $html .= '<img class="img-responsive"'
  273. .' src="'.$course_medium_image.'" '
  274. .' alt="'.api_htmlentities($title).'"/>';
  275. } else {
  276. $html .= '<a href="'.$linkCourse.'" title="'.$course['title'].'">'
  277. .'<img class="img-responsive" src="'.$course_medium_image.'" '
  278. .'alt="'.api_htmlentities($title).'"/></a>';
  279. }
  280. $categoryTitle = isset($course['category_title']) ? $course['category_title'] : '';
  281. if (!empty($categoryTitle)) {
  282. $html .= '<span class="category">'.$categoryTitle.'</span>';
  283. $html .= '<div class="cribbon"></div>';
  284. }
  285. $html .= '<div class="user-actions">';
  286. $html .= return_description_button($course);
  287. $html .= '</div></div>';
  288. return $html;
  289. }
  290. function return_teacher($course)
  291. {
  292. $courseInfo = api_get_course_info($course['code']);
  293. $teachers = CourseManager::getTeachersFromCourse($courseInfo['real_id']);
  294. $html = null;
  295. $html .= '<div class="block-author">';
  296. $length = count($teachers);
  297. foreach ($teachers as $value) {
  298. $name = $value['firstname'].' '.$value['lastname'];
  299. if ($length > 2) {
  300. $html .= '<a href="'.$value['url'].'" class="ajax" data-title="'.$name.'">
  301. <img src="'.$value['avatar'].'" alt="'.get_lang('UserPicture').'"/></a>';
  302. } else {
  303. $html .= '<a href="'.$value['url'].'" class="ajax" data-title="'.$name.'">
  304. <img src="'.$value['avatar'].'" alt="'.get_lang('UserPicture').'"/></a>';
  305. $html .= '<div class="teachers-details"><h5>
  306. <a href="'.$value['url'].'" class="ajax" data-title="'.$name.'">'
  307. . $name.'</a></h5><p>'.get_lang('Teacher').'</p></div>';
  308. }
  309. }
  310. $html .= '</div>';
  311. return $html;
  312. }
  313. /**
  314. * Display the title of a course in course catalog
  315. * @param $course
  316. * @return string HTML string
  317. */
  318. function return_title($course, $registeredUser)
  319. {
  320. $html = '';
  321. $linkCourse = api_get_course_url($course['code']);
  322. $title = cut($course['title'], 45);
  323. $html .= '<div class="block-title"><h4 class="title">';
  324. if (!$registeredUser) {
  325. $html .= $title;
  326. } else {
  327. $html .= '<a title="'.$title.'" href="'.$linkCourse.'">'.$title.'</a>';
  328. }
  329. $html .= '</h4></div>';
  330. if (api_get_configuration_value('hide_course_rating') === false) {
  331. $ajax_url = api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=add_course_vote';
  332. $rating = Display::return_rating_system(
  333. 'star_'.$course['real_id'],
  334. $ajax_url.'&course_id='.$course['real_id'],
  335. $course['point_info']
  336. );
  337. $html .= '<div class="ranking">'.$rating.'</div>';
  338. }
  339. return $html;
  340. }
  341. /**
  342. * Display the description button of a course in the course catalog
  343. * @param $course
  344. * @return string HTML string
  345. */
  346. function return_description_button($course)
  347. {
  348. $title = $course['title'];
  349. $html = '';
  350. if (api_get_setting('show_courses_descriptions_in_catalog') == 'true') {
  351. $html = Display::url(
  352. Display::returnFontAwesomeIcon('info-circle'),
  353. api_get_path(WEB_CODE_PATH).'inc/ajax/course_home.ajax.php?a=show_course_information&code='.$course['code'],
  354. array(
  355. 'class' => 'ajax btn btn-default btn-sm',
  356. 'data-title' => $title, 'title' => get_lang('Description'),
  357. 'aria-label' => get_lang('Description')
  358. )
  359. );
  360. }
  361. return $html;
  362. }
  363. /**
  364. * Display the goto course button of a course in the course catalog
  365. * @param $course
  366. * @return string HTML string
  367. */
  368. function return_goto_button($course)
  369. {
  370. $title = get_lang('GoToCourse');
  371. $html = Display::url(
  372. Display::returnFontAwesomeIcon('share'),
  373. api_get_course_url($course['code']),
  374. array(
  375. 'class' => 'btn btn-default btn-sm',
  376. 'title' => $title,
  377. 'aria-label' => $title,
  378. )
  379. );
  380. return $html;
  381. }
  382. /**
  383. * Display the already registerd text in a course in the course catalog
  384. * @param $in_status
  385. *
  386. * @return string HTML string
  387. */
  388. function return_already_registered_label($in_status)
  389. {
  390. $icon = '<em class="fa fa-check"></em>';
  391. $title = get_lang("YouAreATeacherOfThisCourse");
  392. if ($in_status == 'student') {
  393. $icon = '<em class="fa fa-check"></em>';
  394. $title = get_lang("AlreadySubscribed");
  395. }
  396. $html = Display::tag(
  397. 'span',
  398. $icon.' '.$title,
  399. array(
  400. 'id' => 'register',
  401. 'class' => 'label-subscribed text-success',
  402. 'title' => $title,
  403. 'aria-label' => $title,
  404. )
  405. );
  406. return $html;
  407. }
  408. /**
  409. * Display the register button of a course in the course catalog
  410. * @param $course
  411. * @param $stok
  412. * @param $code
  413. * @param $search_term
  414. *
  415. * @return string
  416. */
  417. function return_register_button($course, $stok, $code, $search_term)
  418. {
  419. $title = get_lang('Subscribe');
  420. $html = Display::url(
  421. Display::returnFontAwesomeIcon('check').' '.$title,
  422. api_get_self().'?action=subscribe_course&sec_token='.$stok.
  423. '&subscribe_course='.$course['code'].'&search_term='.$search_term.'&category_code='.$code,
  424. array('class' => 'btn btn-success btn-sm', 'title' => $title, 'aria-label' => $title)
  425. );
  426. return $html;
  427. }
  428. /**
  429. * Display the unregister button of a course in the course catalog
  430. * @param $course
  431. * @param $stok
  432. * @param $search_term
  433. * @param $code
  434. *
  435. * @return string
  436. */
  437. function return_unregister_button($course, $stok, $search_term, $code)
  438. {
  439. $title = get_lang('UnsubscriptionAllowed');
  440. $html = Display::url(
  441. Display::returnFontAwesomeIcon('sign-in').' '.$title,
  442. api_get_self().'?action=unsubscribe&sec_token='.$stok
  443. .'&unsubscribe='.$course['code'].'&search_term='.$search_term.'&category_code='.$code,
  444. array('class' => 'btn btn-danger btn-sm', 'title' => $title, 'aria-label' => $title)
  445. );
  446. return $html;
  447. }