courses_categories.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  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']) : 12;
  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. /*$('.courses-list-btn').toggle(function (e) {
  47. e.preventDefault();
  48. var $el = $(this);
  49. var sessionId = getSessionId(this);
  50. $el.children('img').remove();
  51. $el.prepend('<?php echo Display::display_icon('nolines_minus.gif'); ?>');
  52. $.ajax({
  53. url: '<?php echo api_get_path(WEB_AJAX_PATH) . 'course.ajax.php' ?>',
  54. type: 'GET',
  55. dataType: 'json',
  56. data: {
  57. a: 'display_sessions_courses',
  58. session: sessionId
  59. },
  60. success: function (response){
  61. var $container = $el.prev('.course-list');
  62. var $courseList = $('<ul>');
  63. $.each(response, function (index, course) {
  64. $courseList.append('<li><div><strong>' + course.name + '</strong><br>' + course.coachName + '</div></li>');
  65. });
  66. $container.append($courseList).show(250);
  67. }
  68. });
  69. }, function (e) {
  70. e.preventDefault();
  71. var $el = $(this);
  72. var $container = $el.prev('.course-list');
  73. $container.hide(250).empty();
  74. $el.children('img').remove();
  75. $el.prepend('<?php echo Display::display_icon('nolines_plus.gif'); ?>');
  76. });*/
  77. var getSessionId = function (el) {
  78. var parts = el.id.split('_');
  79. return parseInt(parts[1], 10);
  80. };
  81. <?php if ($showSessions) { ?>
  82. $('#date').datepicker({
  83. dateFormat: 'yy-mm-dd'
  84. });
  85. <?php } ?>
  86. });
  87. </script>
  88. <div class="row">
  89. <div class="col-md-4">
  90. <h5><?php echo get_lang('Search'); ?></h5>
  91. <?php
  92. if ($showCourses) {
  93. if (!isset($_GET['hidden_links']) || intval($_GET['hidden_links']) != 1) { ?>
  94. <form class="form-horizontal" method="post" action="<?php echo CourseCategory::getCourseCategoryUrl(1, $pageLength, 'ALL', 0, 'subscribe'); ?>">
  95. <input type="hidden" name="sec_token" value="<?php echo $stok; ?>">
  96. <input type="hidden" name="search_course" value="1" />
  97. <div class="input-group">
  98. <input class="form-control" type="text" name="search_term" value="<?php echo (empty($_POST['search_term']) ? '' : api_htmlentities(Security::remove_XSS($_POST['search_term']))); ?>" />
  99. <div class="input-group-btn">
  100. <button class="btn btn-default" type="submit">
  101. <em class="fa fa-search"></em> <?php echo get_lang('Search'); ?>
  102. </button>
  103. </div>
  104. </div>
  105. </form>
  106. <?php } ?>
  107. </div>
  108. <div class="col-md-4">
  109. <h5><?php echo get_lang('CourseCategories'); ?></h5>
  110. <?php
  111. $webAction = api_get_path(WEB_CODE_PATH).'auth/courses.php';
  112. $action = (!empty($_REQUEST['action']) ? Security::remove_XSS($_REQUEST['action']) : 'display_courses');
  113. $pageLength = (!empty($_REQUEST['pageLength']) ? intval($_REQUEST['pageLength']) : 10);
  114. $pageCurrent = (!empty($_REQUEST['pageCurrent']) ? intval($_REQUEST['pageCurrent']) : 1);
  115. $form = '<form action="'.$webAction.'" method="GET" class="form-horizontal">';
  116. $form .= '<input type="hidden" name="action" value="' . $action . '">';
  117. $form .= '<input type="hidden" name="pageCurrent" value="' . $pageCurrent . '">';
  118. $form .= '<input type="hidden" name="pageLength" value="' . $pageLength . '">';
  119. $form .= '<div class="form-group">';
  120. $form .= '<div class="col-sm-12">';
  121. $form .= '<select name="category_code" onchange="submit();" class="selectpicker show-tick form-control">';
  122. $codeType = isset($_REQUEST['category_code']) ? Security::remove_XSS($_REQUEST['category_code']) : '';
  123. foreach ($browse_course_categories[0] as $category) {
  124. $categoryCode = $category['code'];
  125. $countCourse = $category['count_courses'];
  126. $form .= '<option '. ($categoryCode == $codeType? 'selected="selected" ':'') .' value="' . $category['code'] . '">' . $category['name'] . ' ( '. $countCourse .' ) </option>';
  127. if (!empty($browse_course_categories[$categoryCode])) {
  128. foreach ($browse_course_categories[$categoryCode] as $subCategory){
  129. $subCategoryCode = $subCategory['code'];
  130. $form .= '<option '. ($subCategoryCode == $codeType ? 'selected="selected" ':'') .' value="' . $subCategory['code'] . '"> ---' . $subCategory['name'] . ' ( '. $subCategory['count_courses'] .' ) </option>';
  131. }
  132. }
  133. }
  134. $form .= '</select>';
  135. $form .= '</div>';
  136. $form .= '</form>';
  137. echo $form;
  138. ?>
  139. </div>
  140. </div>
  141. <?php
  142. if ($showSessions) { ?>
  143. <div class="col-md-4">
  144. <h5><?php echo get_lang('Sessions'); ?></h5>
  145. <a class="btn btn-default btn-block" href="<?php echo CourseCategory::getCourseCategoryUrl(1, $pageLength, null, 0, 'display_sessions'); ?>">
  146. <?php echo get_lang('SessionList'); ?>
  147. </a>
  148. </div>
  149. <?php } ?>
  150. </div>
  151. <?php } ?>
  152. <div class="grid-courses">
  153. <div class="row">
  154. <?php
  155. if ($showCourses && $action != 'display_sessions') {
  156. if (!empty($message)) {
  157. Display::display_confirmation_message($message, false);
  158. }
  159. if (!empty($error)) {
  160. Display::display_error_message($error, false);
  161. }
  162. if (!empty($content)) {
  163. echo $content;
  164. }
  165. if (!empty($search_term)) {
  166. echo "<p><strong>".get_lang('SearchResultsFor')." ".Security::remove_XSS($_POST['search_term'])."</strong><br />";
  167. }
  168. $ajax_url = api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=add_course_vote';
  169. $user_id = api_get_user_id();
  170. if (!empty($browse_courses_in_category)) {
  171. foreach ($browse_courses_in_category as $course) {
  172. $course_hidden = $course['visibility'] == COURSE_VISIBILITY_HIDDEN;
  173. if ($course_hidden) {
  174. continue;
  175. }
  176. $user_registerd_in_course = CourseManager::is_user_subscribed_in_course($user_id, $course['code']);
  177. $user_registerd_in_course_as_teacher = CourseManager::is_course_teacher($user_id, $course['code']);
  178. $user_registerd_in_course_as_student = ($user_registerd_in_course && !$user_registerd_in_course_as_teacher);
  179. $course_public = ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD);
  180. $course_open = ($course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM);
  181. $course_private = ($course['visibility'] == COURSE_VISIBILITY_REGISTERED);
  182. $course_closed = ($course['visibility'] == COURSE_VISIBILITY_CLOSED);
  183. $course_subscribe_allowed = ($course['subscribe'] == 1);
  184. $course_unsubscribe_allowed = ($course['unsubscribe'] == 1);
  185. $count_connections = $course['count_connections'];
  186. $creation_date = substr($course['creation_date'], 0, 10);
  187. $html = null;
  188. // display the course bloc
  189. $html .= '<div class="col-xs-6 col-sm-6 col-md-3"><div class="items items-courses">';
  190. // display thumbnail
  191. $html .= returnThumbnail($course);
  192. $separator = '<div class="separator">&nbsp;</div>';
  193. $subscribeButton = return_register_button($course, $stok, $code, $search_term);
  194. // start buycourse validation
  195. // display the course price and buy button if the buycourses plugin is enabled and this course is configured
  196. $plugin = BuyCoursesPlugin::create();
  197. $isThisCourseInSale = $plugin->buyCoursesForGridCatalogVerificator($course['real_id'], BuyCoursesPlugin::PRODUCT_TYPE_COURSE);
  198. if ($isThisCourseInSale) {
  199. // set the Price label
  200. $separator = $isThisCourseInSale['html'];
  201. // set the Buy button instead register.
  202. if ($isThisCourseInSale['verificator']) {
  203. $subscribeButton = $plugin->returnBuyCourseButton($course['real_id'], BuyCoursesPlugin::PRODUCT_TYPE_COURSE);
  204. }
  205. }
  206. // end buycourse validation
  207. // display course title and button bloc
  208. $html .= '<div class="description">';
  209. $html .= return_title($course);
  210. // display button line
  211. $html .= '<div class="toolbar">';
  212. $html .= '<div class="left">';
  213. $html .= $separator;
  214. $html .= '</div>';
  215. $html .= '<div class="right">';
  216. $html .= '<div class="btn-group">';
  217. // if user registered as student
  218. if ($user_registerd_in_course_as_student) {
  219. $html .= return_already_registered_label('student');
  220. if (!$course_closed) {
  221. if ($course_unsubscribe_allowed) {
  222. $html .= return_unregister_button($course, $stok, $search_term, $code);
  223. }
  224. }
  225. } elseif ($user_registerd_in_course_as_teacher) {
  226. // if user registered as teacher
  227. if ($course_unsubscribe_allowed) {
  228. $html .= return_unregister_button($course, $stok, $search_term, $code);
  229. }
  230. $html .= return_already_registered_label('teacher');
  231. } else {
  232. // if user not registered in the course
  233. if (!$course_closed) {
  234. if (!$course_private) {
  235. if ($course_subscribe_allowed) {
  236. $html .= $subscribeButton;
  237. }
  238. }
  239. }
  240. }
  241. $html .= '</div>';
  242. $html .= '</div>';
  243. $html .= '</div>';
  244. $html .= '</div>';
  245. $html .= '</div>';
  246. $html .= '</div>';
  247. echo $html;
  248. }
  249. } else {
  250. if (!isset($_REQUEST['subscribe_user_with_password']) &&
  251. !isset($_REQUEST['subscribe_course'])
  252. ) {
  253. Display::display_warning_message(get_lang('ThereAreNoCoursesInThisCategory'));
  254. }
  255. }
  256. }
  257. ?>
  258. </div>
  259. </div>
  260. <?php
  261. echo $cataloguePagination;
  262. /**
  263. * Display the course catalog image of a course
  264. * @param array $course
  265. * @return string HTML string
  266. */
  267. function returnThumbnail($course)
  268. {
  269. $html = '';
  270. $title = cut($course['title'], 70);
  271. // course path
  272. $course_path = api_get_path(SYS_COURSE_PATH).$course['directory'];
  273. if (file_exists($course_path.'/course-pic.png')) {
  274. $course_medium_image = api_get_path(WEB_COURSE_PATH).$course['directory'].'/course-pic.png'; // redimensioned image 85x85
  275. } else {
  276. // without picture
  277. $course_medium_image = Display::return_icon('session_default.png', null, null, null, null, true);
  278. }
  279. $html .= '<div class="image">';
  280. $html .= '<img class="img-responsive" src="'.$course_medium_image.'" alt="'.api_htmlentities($title).'"/>';
  281. $categoryTitle = $course['category'];
  282. if (!empty($categoryTitle)) {
  283. $listCategory = CourseManager::getCategoriesList();
  284. $categoryTitle = $listCategory[$categoryTitle];
  285. $html .= '<span class="category">'. $categoryTitle.'</span>';
  286. $html .= '<div class="cribbon"></div>';
  287. }
  288. $teachers = CourseManager::getTeachersFromCourseByCode($course['code']);
  289. $html .= '<div class="black-shadow">';
  290. $html .= '<div class="author-card">';
  291. $count = 0;
  292. foreach ($teachers as $value) {
  293. if ($count > 2) {
  294. break;
  295. }
  296. $name = $value['firstname'].' ' . $value['lastname'];
  297. $html .= '<a href="'.$value['url'].'" class="ajax" data-title="'.$name.'">
  298. <img src="'.$value['avatar'].'"/></a>';
  299. $html .= '<div class="teachers-details"><h5>
  300. <a href="'.$value['url'].'" class="ajax" data-title="'.$name.'">'
  301. . $name . '</a></h5></div>';
  302. $count ++;
  303. }
  304. $html .= '</div></div>';
  305. $html .= '<div class="user-actions">';
  306. $html .= return_description_button($course);
  307. $html .= '</div></div>';
  308. return $html;
  309. }
  310. /**
  311. * Display the title of a course in course catalog
  312. * @param $course
  313. * @return string HTML string
  314. */
  315. function return_title($course)
  316. {
  317. $html = '';
  318. $linkCourse = api_get_course_url($course['code']);
  319. $title = cut($course['title'], 70);
  320. $ajax_url = api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=add_course_vote';
  321. $rating = Display::return_rating_system('star_'.$course['real_id'], $ajax_url.'&course_id='.$course['real_id'], $course['point_info']);
  322. $html .= '<h4 class="title"><a href="' . $linkCourse . '">' . cut($title, 60) . '</a></h4>';
  323. $html .= '<div class="ranking">'. $rating . '</div>';
  324. return $html;
  325. }
  326. /**
  327. * Display the description button of a course in the course catalog
  328. * @param $course
  329. * @return string HTML string
  330. */
  331. function return_description_button($course)
  332. {
  333. $title = $course['title'];
  334. $html = '';
  335. if (api_get_setting('show_courses_descriptions_in_catalog') == 'true') {
  336. $html = '<a data-title="' . $title . '" class="ajax btn btn-default btn-sm" href="'.api_get_path(WEB_CODE_PATH).'inc/ajax/course_home.ajax.php?a=show_course_information&code='.$course['code'].'" title="' . get_lang('Description') . '">' .
  337. Display::returnFontAwesomeIcon('info-circle') . '</a>';
  338. }
  339. return $html;
  340. }
  341. /**
  342. * Display the goto course button of a course in the course catalog
  343. * @param $course
  344. * @return string HTML string
  345. */
  346. function return_goto_button($course)
  347. {
  348. $html = ' <a class="btn btn-default btn-sm" title="' . get_lang('GoToCourse') . '" href="'.api_get_course_url($course['code']).'">'.
  349. Display::returnFontAwesomeIcon('share').'</a>';
  350. return $html;
  351. }
  352. /**
  353. * Display the already registerd text in a course in the course catalog
  354. * @param $in_status
  355. * @return string HTML string
  356. */
  357. function return_already_registered_label($in_status)
  358. {
  359. $icon = '<em class="fa fa-suitcase"></em>';
  360. $title = get_lang("YouAreATeacherOfThisCourse");
  361. if ($in_status == 'student') {
  362. $icon = '<em class="fa fa-graduation-cap"></em>';
  363. $title = get_lang("AlreadyRegisteredToCourse");
  364. }
  365. $html = Display::tag(
  366. 'button',
  367. $icon,
  368. array('id' => 'register', 'class' => 'btn btn-default btn-sm', 'title' => $title)
  369. );
  370. return $html;
  371. }
  372. /**
  373. * Display the register button of a course in the course catalog
  374. * @param $course
  375. * @param $stok
  376. * @param $code
  377. * @param $search_term
  378. * @return html
  379. */
  380. function return_register_button($course, $stok, $code, $search_term)
  381. {
  382. $html = ' <a class="btn btn-success btn-sm" title="' . get_lang('Subscribe') . '" href="'.api_get_self().'?action=subscribe_course&sec_token='.$stok.'&subscribe_course='.$course['code'].'&search_term='.$search_term.'&category_code='.$code.'">' .
  383. Display::returnFontAwesomeIcon('sign-in') . '</a>';
  384. return $html;
  385. }
  386. /**
  387. * Display the unregister button of a course in the course catalog
  388. * @param $course
  389. * @param $stok
  390. * @param $search_term
  391. * @param $code
  392. * @return html
  393. */
  394. function return_unregister_button($course, $stok, $search_term, $code)
  395. {
  396. $html = ' <a class="btn btn-danger btn-sm" title="' . get_lang('Unsubscribe') . '" href="'. api_get_self().'?action=unsubscribe&sec_token='.$stok.'&unsubscribe='.$course['code'].'&search_term='.$search_term.'&category_code='.$code.'">' .
  397. Display::returnFontAwesomeIcon('sign-out') . '</a>';
  398. return $html;
  399. }