courses_categories.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  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-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']) : 10);
  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. $userRegisterdInCourse = CourseManager::is_user_subscribed_in_course($user_id, $course['code']);
  149. $userRegisterdInCourseAsTeacher = CourseManager::is_course_teacher($user_id, $course['code']);
  150. $userRegisterd = ($userRegisterdInCourse && $userRegisterdInCourseAsTeacher);
  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, $userRegisterd);
  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, $userRegisterdInCourse);
  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 ($userRegisterdInCourse) {
  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 ($userRegisterdInCourseAsTeacher) {
  209. // if user registered as teacher
  210. if ($course_unsubscribe_allowed) {
  211. $html .= return_unregister_button($course, $stok, $search_term, $code);
  212. }
  213. //$html .= return_already_registered_label('teacher');
  214. } else {
  215. // if user not registered in the course
  216. if (!$course_closed) {
  217. if (!$course_private) {
  218. if ($course_subscribe_allowed) {
  219. $html .= $subscribeButton;
  220. }
  221. }
  222. }
  223. }
  224. $html .= '</div>';
  225. $html .= '</div>';
  226. $html .= '</div>';
  227. $html .= '</div>';
  228. $html .= '</div>';
  229. $html .= '</div>';
  230. echo $html;
  231. }
  232. } else {
  233. if (!isset($_REQUEST['subscribe_user_with_password']) &&
  234. !isset($_REQUEST['subscribe_course'])
  235. ) {
  236. echo Display::return_message(get_lang('ThereAreNoCoursesInThisCategory'), 'warning');
  237. }
  238. }
  239. }
  240. ?>
  241. </div>
  242. </div>
  243. <?php
  244. echo $cataloguePagination;
  245. /**
  246. * Display the course catalog image of a course
  247. * @param array $course
  248. *
  249. * @return string HTML string
  250. */
  251. function returnThumbnail($course, $registeredUser)
  252. {
  253. $html = '';
  254. $title = cut($course['title'], 70);
  255. $linkCourse = api_get_course_url($course['code']);
  256. // course path
  257. $course_path = api_get_path(SYS_COURSE_PATH).$course['directory'];
  258. if (file_exists($course_path.'/course-pic.png')) {
  259. $course_medium_image = api_get_path(WEB_COURSE_PATH).$course['directory'].'/course-pic.png'; // redimensioned image 85x85
  260. } else {
  261. // without picture
  262. $course_medium_image = Display::return_icon('session_default.png', null, null, null, null, true);
  263. }
  264. $html .= '<div class="image">';
  265. if (!$registeredUser) {
  266. $html .= '<img class="img-responsive"'
  267. .' src="'.$course_medium_image.'" '
  268. .' alt="'.api_htmlentities($title).'"/>';
  269. } else {
  270. $html .= '<a href="'.$linkCourse.'" title="'.$course['title'].'">'
  271. .'<img class="img-responsive" src="'.$course_medium_image.'" '
  272. .'alt="'.api_htmlentities($title).'"/></a>';
  273. }
  274. $categoryTitle = isset($course['category_title']) ? $course['category_title'] : '';
  275. if (!empty($categoryTitle)) {
  276. $html .= '<span class="category">'.$categoryTitle.'</span>';
  277. $html .= '<div class="cribbon"></div>';
  278. }
  279. $html .= '<div class="user-actions">';
  280. $html .= return_description_button($course);
  281. $html .= '</div></div>';
  282. return $html;
  283. }
  284. function return_teacher($course)
  285. {
  286. //Info course
  287. $courseInfo = api_get_course_info($course['code']);
  288. $teachers = CourseManager::getTeachersFromCourse($courseInfo['real_id']);
  289. //$count = 0;
  290. $html = null;
  291. $html .= '<div class="block-author">';
  292. $length = count($teachers);
  293. foreach ($teachers as $value) {
  294. $name = $value['firstname'].' ' . $value['lastname'];
  295. if ($length > 2) {
  296. $html .= '<a href="'.$value['url'].'" class="ajax" data-title="'.$name.'">
  297. <img src="'.$value['avatar'].'" alt="'.get_lang('UserPicture').'"/></a>';
  298. } else {
  299. $html .= '<a href="'.$value['url'].'" class="ajax" data-title="'.$name.'">
  300. <img src="'.$value['avatar'].'" alt="'.get_lang('UserPicture').'"/></a>';
  301. $html .= '<div class="teachers-details"><h5>
  302. <a href="'.$value['url'].'" class="ajax" data-title="'.$name.'">'
  303. . $name . '</a></h5><p>'. get_lang('Teacher').'</p></div>';
  304. }
  305. }
  306. $html .= '</div>';
  307. return $html;
  308. }
  309. /**
  310. * Display the title of a course in course catalog
  311. * @param $course
  312. * @return string HTML string
  313. */
  314. function return_title($course, $registeredUser)
  315. {
  316. $html = '';
  317. $linkCourse = api_get_course_url($course['code']);
  318. $title = cut($course['title'], 45);
  319. $html .= '<div class="block-title"><h4 class="title">';
  320. if (!$registeredUser) {
  321. $html .= $title;
  322. } else {
  323. $html .= '<a title="'.$title.'" href="' . $linkCourse . '">' . $title . '</a>';
  324. }
  325. $html .= '</h4></div>';
  326. if (api_get_configuration_value('hide_course_rating') === false) {
  327. $ajax_url = api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=add_course_vote';
  328. $rating = Display::return_rating_system(
  329. 'star_'.$course['real_id'],
  330. $ajax_url.'&course_id='.$course['real_id'],
  331. $course['point_info']
  332. );
  333. $html .= '<div class="ranking">'.$rating.'</div>';
  334. }
  335. return $html;
  336. }
  337. /**
  338. * Display the description button of a course in the course catalog
  339. * @param $course
  340. * @return string HTML string
  341. */
  342. function return_description_button($course)
  343. {
  344. $title = $course['title'];
  345. $html = '';
  346. if (api_get_setting('show_courses_descriptions_in_catalog') == 'true') {
  347. $html = Display::url(
  348. Display::returnFontAwesomeIcon('info-circle'),
  349. api_get_path(WEB_CODE_PATH).'inc/ajax/course_home.ajax.php?a=show_course_information&code='.$course['code'],
  350. array(
  351. 'class' => 'ajax btn btn-default btn-sm',
  352. 'data-title' => $title,'title' => get_lang('Description'),
  353. 'aria-label' => get_lang('Description')
  354. )
  355. );
  356. }
  357. return $html;
  358. }
  359. /**
  360. * Display the goto course button of a course in the course catalog
  361. * @param $course
  362. * @return string HTML string
  363. */
  364. function return_goto_button($course)
  365. {
  366. $title=get_lang('GoToCourse');
  367. $html = Display::url(
  368. Display::returnFontAwesomeIcon('share'),
  369. api_get_course_url($course['code']),
  370. array('class' => 'btn btn-default btn-sm', 'title' => $title, 'aria-label' => $title)
  371. );
  372. return $html;
  373. }
  374. /**
  375. * Display the already registerd text in a course in the course catalog
  376. * @param $in_status
  377. *
  378. * @return string HTML string
  379. */
  380. function return_already_registered_label($in_status)
  381. {
  382. $icon = '<em class="fa fa-check"></em>';
  383. $title = get_lang("YouAreATeacherOfThisCourse");
  384. if ($in_status == 'student') {
  385. $icon = '<em class="fa fa-check"></em>';
  386. $title = get_lang("AlreadySubscribed");
  387. }
  388. $html = Display::tag(
  389. 'span',
  390. $icon . ' ' . $title,
  391. array('id' => 'register', 'class' => 'label-subscribed text-success', 'title' => $title, 'aria-label' => $title)
  392. );
  393. return $html;
  394. }
  395. /**
  396. * Display the register button of a course in the course catalog
  397. * @param $course
  398. * @param $stok
  399. * @param $code
  400. * @param $search_term
  401. *
  402. * @return string
  403. */
  404. function return_register_button($course, $stok, $code, $search_term)
  405. {
  406. $title = get_lang('Subscribe');
  407. $html = Display::url(
  408. Display::returnFontAwesomeIcon('check') . ' ' . $title,
  409. api_get_self() . '?action=subscribe_course&sec_token=' . $stok.
  410. '&subscribe_course='.$course['code'].'&search_term='.$search_term.'&category_code='.$code,
  411. array('class' => 'btn btn-success btn-sm', 'title' => $title, 'aria-label' => $title)
  412. );
  413. return $html;
  414. }
  415. /**
  416. * Display the unregister button of a course in the course catalog
  417. * @param $course
  418. * @param $stok
  419. * @param $search_term
  420. * @param $code
  421. *
  422. * @return string
  423. */
  424. function return_unregister_button($course, $stok, $search_term, $code)
  425. {
  426. $title = get_lang('UnsubscriptionAllowed');
  427. $html = Display::url(
  428. Display::returnFontAwesomeIcon('sign-in').' '.$title,
  429. api_get_self() . '?action=unsubscribe&sec_token='.$stok
  430. .'&unsubscribe='.$course['code'].'&search_term='.$search_term.'&category_code='.$code,
  431. array('class' => 'btn btn-danger btn-sm', 'title' => $title, 'aria-label' => $title)
  432. );
  433. return $html;
  434. }