courses_categories.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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. $stok = Security::get_token();
  9. ?>
  10. <script>
  11. $(document).ready( function() {
  12. $('.star-rating li a').live('click', function(event) {
  13. var id = $(this).parents('ul').attr('id');
  14. $('#vote_label2_' + id).html("<?php echo get_lang('Loading'); ?>");
  15. $.ajax({
  16. url: $(this).attr('data-link'),
  17. success: function(data) {
  18. $("#rating_wrapper_"+id).html(data);
  19. if(data == 'added') {
  20. //$('#vote_label2_' + id).html("{'Saved'|get_lang}");
  21. }
  22. if(data == 'updated') {
  23. //$('#vote_label2_' + id).html("{'Saved'|get_lang}");
  24. }
  25. }
  26. });
  27. });
  28. });
  29. </script>
  30. <div class="row">
  31. <div class="span3">
  32. <div id="course_category_well" class="well">
  33. <ul class="nav nav-list">
  34. <?php if (!isset($_GET['hidden_links']) || isset($_GET['hidden_links']) && intval($_GET['hidden_links']) != 1) { ?>
  35. <form class="form-search" method="post" action="<?php echo api_get_self(); ?>?action=subscribe&amp;hidden_links=0">
  36. <fieldset>
  37. <input type="hidden" name="sec_token" value="<?php echo $stok; ?>">
  38. <input type="hidden" name="search_course" value="1" />
  39. <div class="control-group">
  40. <div class="controls">
  41. <div class="input-append">
  42. <input class="span2" type="text" name="search_term" value="<?php echo (empty($_POST['search_term']) ? '' : api_htmlentities(Security::remove_XSS($_POST['search_term']))); ?>" />
  43. <button class="btn" type="submit"><?php echo get_lang('Search'); ?></button>
  44. </div>
  45. </div>
  46. </div>
  47. </fieldset>
  48. </form>
  49. <?php
  50. $hidden_links = 0;
  51. } else {
  52. $hidden_links = 1;
  53. }
  54. /* Categories will only show down to 4 levels, if you want more,
  55. * you will have to patch the following code. We don't recommend
  56. * it, as this can considerably slow down your system
  57. */
  58. if (!empty($browse_course_categories)) {
  59. echo '<a class="btn" href="'.api_get_self().'?action=display_random_courses">'.get_lang('RandomPick').'</a><br /><br />';
  60. echo '<li class="nav-header">'.get_lang('CourseCategories').'</li>';
  61. // level 1
  62. foreach ($browse_course_categories[0] as $category) {
  63. $category_name = $category['name'];
  64. $category_code = isset($category['code']) ? $category['code'] : null;
  65. $count_courses_lv1 = $category['count_courses'];
  66. if (isset($code) && $code == $category_code) {
  67. $category_link = '<strong>'.$category_name.' ('.$count_courses_lv1.')</strong>';
  68. } else {
  69. if (!empty($count_courses_lv1)) {
  70. $category_link = '<a href="'. api_get_self().'?action=display_courses&amp;category_code='.$category_code.'&amp;hidden_links='.$hidden_links.'">'.$category_name.' ('.$count_courses_lv1.') </a>';
  71. } else {
  72. $category_link = ''.$category_name.' ('.$count_courses_lv1.')';
  73. }
  74. }
  75. echo '<li>'.$category_link.'</li>';
  76. // level 2
  77. if (!empty($browse_course_categories[$category_code])) {
  78. foreach ($browse_course_categories[$category_code] as $subcategory1) {
  79. $subcategory1_name = $subcategory1['name'];
  80. $subcategory1_code = $subcategory1['code'];
  81. $count_courses_lv2 = $subcategory1['count_courses'];
  82. if ($code == $subcategory1_code) {
  83. $subcategory1_link = '<strong>'.$subcategory1_name.' ('.$count_courses_lv2.')</strong>';
  84. } else {
  85. $subcategory1_link = '<a href="'. api_get_self().'?action=display_courses&amp;category_code='.$subcategory1_code.'&amp;hidden_links='.$hidden_links.'">'.$subcategory1_name.' ('.$count_courses_lv2.') </a> ';
  86. }
  87. echo '<li style="margin-left:20px;">'.$subcategory1_link.'</li>';
  88. // level 3
  89. if (!empty($browse_course_categories[$subcategory1_code])) {
  90. foreach ($browse_course_categories[$subcategory1_code] as $subcategory2) {
  91. $subcategory2_name = $subcategory2['name'];
  92. $subcategory2_code = $subcategory2['code'];
  93. $count_courses_lv3 = $subcategory2['count_courses'];
  94. if ($code == $subcategory2_code) {
  95. $subcategory2_link = '<strong>'.$subcategory2_name.' ('.$count_courses_lv3.')</strong>';
  96. } else {
  97. $subcategory2_link = '<a href="'. api_get_self().'?action=display_courses&amp;category_code='.$subcategory2_code.'&amp;hidden_links='.$hidden_links.'">'.$subcategory2_name.'</a> ('.$count_courses_lv3.')';
  98. }
  99. echo '<li style="margin-left:40px;">'.$subcategory2_link.'</li>';
  100. // level 4
  101. if (!empty($browse_course_categories[$subcategory2_code])) {
  102. foreach ($browse_course_categories[$subcategory2_code] as $subcategory3) {
  103. $subcategory3_name = $subcategory3['name'];
  104. $subcategory3_code = $subcategory3['code'];
  105. $count_courses_lv4 = $subcategory3['count_courses'];
  106. if ($code == $subcategory3_code) {
  107. $subcategory3_link = '<strong>'.$subcategory3_name.' ('.$count_courses_lv4.')</strong>';
  108. } else {
  109. $subcategory3_link = '<a href="'. api_get_self().'?action=display_courses&amp;category_code='.$subcategory3_code.'&amp;hidden_links='.$hidden_links.'">'.$subcategory3_name.' ('.$count_courses_lv4.') </a>';
  110. }
  111. echo '<li style="margin-left:60px;">'.$subcategory3_link.'</li>';
  112. }
  113. }
  114. }
  115. }
  116. }
  117. }
  118. }
  119. }
  120. ?>
  121. </div>
  122. </div>
  123. <div class="span9">
  124. <?php
  125. if (!empty($message)) { Display::display_confirmation_message($message, false); }
  126. if (!empty($error)) { Display::display_error_message($error, false); }
  127. if (!empty($content)) { echo $content; }
  128. if (!empty($search_term)) {
  129. echo "<p><strong>".get_lang('SearchResultsFor')." ".Security::remove_XSS($_POST['search_term'])."</strong><br />";
  130. }
  131. $ajax_url = api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=add_course_vote';
  132. if (!empty($browse_courses_in_category)) {
  133. foreach ($browse_courses_in_category as $course) {
  134. // if course is closed, don't show it.
  135. if ($course['visibility'] == COURSE_VISIBILITY_CLOSED || $course['visibility'] == COURSE_VISIBILITY_HIDDEN) {
  136. continue;
  137. }
  138. // course isn't closed
  139. $title = Text::cut($course['title'], 70);
  140. $tutor_name = $course['tutor'];
  141. $creation_date = substr($course['creation_date'],0,10);
  142. $count_connections = $course['count_connections'];
  143. $course_path = api_get_path(SYS_COURSE_PATH).$course['directory']; // course path
  144. if (file_exists($course_path.'/course-pic85x85.png')) {
  145. $course_medium_image = api_get_path(WEB_COURSE_PATH).$course['directory'].'/course-pic85x85.png'; // redimensioned image 85x85
  146. } else {
  147. $course_medium_image = api_get_path(WEB_IMG_PATH).'without_picture.png'; // without picture
  148. }
  149. $pointInfo = isset($course['point_info']) ? $course['point_info'] : null;
  150. $rating = Display::return_rating_system('star_'.$course['real_id'], $ajax_url.'&amp;course_id='.$course['real_id'], $pointInfo);
  151. echo '<div class="well_border"><div class="row">';
  152. echo '<div class="span2">';
  153. echo '<div class="thumbnail">';
  154. if (api_get_setting('show_courses_descriptions_in_catalog') == 'true') {
  155. echo '<a class="ajax" href="'.api_get_path(WEB_CODE_PATH).'inc/ajax/course_home.ajax.php?a=show_course_information&amp;code='.$course['code'].'" rel="gb_page_center[778]">';
  156. echo '<img src="'.$course_medium_image.'" alt="" />';
  157. echo '</a>';
  158. } else {
  159. echo '<img src="'.$course_medium_image.'" alt="'.$title.'"/>';
  160. }
  161. echo '</div>';//thumb
  162. echo '</div>';
  163. echo '<div class="span4">';
  164. $teachers = CourseManager::get_teacher_list_from_course_code_to_string($course['real_id']);
  165. $teachers = '<h5>'.$teachers.'</h5>';
  166. echo '<div class="categories-course-description"><h3>'.Text::cut($title, 60).'</h3>'.$teachers.$rating.'</div>';
  167. echo '<p>';
  168. // we display the icon to subscribe or the text already subscribed
  169. echo '<div class="btn-toolbar">';
  170. if (api_get_setting('show_courses_descriptions_in_catalog') == 'true') {
  171. echo '<a class="ajax btn" href="'.api_get_path(WEB_CODE_PATH).'inc/ajax/course_home.ajax.php?a=show_course_information&amp;code='.$course['code'].'" class="thickbox">'.get_lang('Description').'</a>';
  172. }
  173. // Get access type for course button ("enter" or/and "register")
  174. $access_type = CourseManager::get_access_link_by_user(api_get_user_id(), $course);
  175. // Go To Course button (only if admin, if course public or if student already subscribed)
  176. if ($access_type && in_array('enter', $access_type)) {
  177. echo ' <a class="btn btn-primary" href="'. api_get_course_url($course['code']).'">'.get_lang('GoToCourse').'</a>';
  178. }
  179. // Register button
  180. if ($access_type && in_array('register', $access_type)) {
  181. echo ' <a class="btn btn-primary" href="'. api_get_self().'?action=subscribe_course&amp;sec_token='.$stok.'&amp;subscribe_course='.$course['code'].'&amp;search_term='.$search_term.'&amp;category_code='.$code.'">'.get_lang('Subscribe').'</a>';
  182. }
  183. // If user is already subscribed to the course
  184. if (!api_is_anonymous() && in_array($course['code'], $user_coursecodes)) {
  185. if ($course['unsubscribe'] == UNSUBSCRIBE_ALLOWED) {
  186. echo ' <a class="btn btn-primary" href="'. api_get_self().'?action=unsubscribe&amp;sec_token='.$stok.'&amp;unsubscribe='.$course['code'].'&amp;search_term='.$search_term.'&amp;category_code='.$code.'">'.get_lang('Unsubscribe').'</a>';
  187. }
  188. echo '<br />';
  189. echo '<br />';
  190. echo Display::label(get_lang("AlreadyRegisteredToCourse"), "info");
  191. }
  192. echo '</div>';
  193. echo '</p>';
  194. echo '</div>';
  195. echo '<div class="span2">';
  196. echo '<div class="course-block-popularity"><span>'.get_lang('ConnectionsLastMonth').'</span><div class="course-block-popularity-score">'.$count_connections.'</div></div>';
  197. echo '</div>';
  198. echo '</div></div>';
  199. }
  200. } else {
  201. if (!isset($_REQUEST['subscribe_user_with_password']) && !isset($_REQUEST['subscribe_course'])) {
  202. echo Display::display_warning_message(get_lang('ThereAreNoCoursesInThisCategory'));
  203. }
  204. }
  205. ?>
  206. </div>
  207. </div>