courses_categories.php 16 KB

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