courses_categories.php 17 KB

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