courses_categories.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. <?php if (!isset($_GET['hidden_links']) || ($_GET['hidden_links']) != 1) { ?>
  31. <div class="actions">
  32. <form class="form-search" method="post" action="<?php echo api_get_self(); ?>?action=subscribe&amp;hidden_links=0">
  33. <input type="hidden" name="sec_token" value="<?php echo $stok; ?>">
  34. <input type="hidden" name="search_course" value="1" />
  35. <input type="text" name="search_term" value="<?php echo (empty($_POST['search_term']) ? '' : api_htmlentities(Security::remove_XSS($_POST['search_term']))); ?>" />
  36. &nbsp;<button class="search" type="submit"><?php echo get_lang('SearchCourse'); ?></button>
  37. </form>
  38. </div>
  39. <?php
  40. $hidden_links = 0;
  41. } else {
  42. $hidden_links = 1;
  43. }
  44. ?>
  45. <div class="row">
  46. <div class="span3">
  47. <div id="course_category_well" class="well">
  48. <ul class="nav nav-list">
  49. <?php
  50. if (!empty($browse_course_categories)) {
  51. echo '<a class="btn" href="'.api_get_self().'?action=display_random_courses">'.get_lang('RandomPick').'</a><br /><br />';
  52. echo '<li class="nav-header">'.get_lang('CourseCategories').'</li>';
  53. // level 1
  54. foreach ($browse_course_categories[0] as $category) {
  55. $category_name = $category['name'];
  56. $category_code = $category['code'];
  57. $count_courses_lv1 = $category['count_courses'];
  58. if ($code == $category_code) {
  59. $category_link = '<strong>'.$category_name.' ('.$count_courses_lv1.')</strong>';
  60. } else {
  61. if (!empty($count_courses_lv1)) {
  62. $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>';
  63. } else {
  64. $category_link = ''.$category_name.' ('.$count_courses_lv1.')';
  65. }
  66. }
  67. echo '<li>'.$category_link.'</li>';
  68. // level 2
  69. if (!empty($browse_course_categories[$category_code])) {
  70. foreach ($browse_course_categories[$category_code] as $subcategory1) {
  71. $subcategory1_name = $subcategory1['name'];
  72. $subcategory1_code = $subcategory1['code'];
  73. $count_courses_lv2 = $subcategory1['count_courses'];
  74. if ($code == $subcategory1_code) {
  75. $subcategory1_link = '<strong>'.$subcategory1_name.' ('.$count_courses_lv2.')</strong>';
  76. } else {
  77. $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> ';
  78. }
  79. echo '<li style="margin-left:20px;">'.$subcategory1_link.'</li>';
  80. }
  81. // level 3
  82. if (!empty($browse_course_categories[$subcategory1_code])) {
  83. foreach ($browse_course_categories[$subcategory1_code] as $subcategory2) {
  84. $subcategory2_name = $subcategory2['name'];
  85. $subcategory2_code = $subcategory2['code'];
  86. $count_courses_lv3 = $subcategory2['count_courses'];
  87. if ($code == $subcategory2_code) {
  88. $subcategory2_link = '<strong>'.$subcategory2_name.' ('.$count_courses_lv3.')</strong>';
  89. } else {
  90. $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.')';
  91. }
  92. echo '<li style="margin-left:40px;">'.$subcategory2_link.'</li>';
  93. }
  94. }
  95. }
  96. }
  97. }
  98. ?>
  99. </div>
  100. </div>
  101. <div class="span9">
  102. <?php
  103. if (!empty($message)) { Display::display_confirmation_message($message, false); }
  104. if (!empty($error)) { Display::display_error_message($error, false); }
  105. if (!empty($content)) { echo $content; }
  106. if (!empty($search_term)) {
  107. echo "<p><strong>".get_lang('SearchResultsFor')." ".Security::remove_XSS($_POST['search_term'])."</strong><br />";
  108. }
  109. $ajax_url = api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=add_course_vote';
  110. if (!empty($browse_courses_in_category)) {
  111. foreach ($browse_courses_in_category as $course) {
  112. // if course is closed, don't show it.
  113. if ($course['visibility'] == COURSE_VISIBILITY_CLOSED) {
  114. continue;
  115. }
  116. // course isn't closed
  117. $title = cut($course['title'], 70);
  118. $tutor_name = $course['tutor'];
  119. $creation_date = substr($course['creation_date'],0,10);
  120. $count_connections = $course['count_connections'];
  121. $course_path = api_get_path(SYS_COURSE_PATH).$course['directory']; // course path
  122. if (file_exists($course_path.'/course-pic85x85.png')) {
  123. $course_medium_image = api_get_path(WEB_COURSE_PATH).$course['directory'].'/course-pic85x85.png'; // redimensioned image 85x85
  124. } else {
  125. $course_medium_image = api_get_path(WEB_IMG_PATH).'without_picture.png'; // without picture
  126. }
  127. $rating = Display::return_rating_system('star_'.$course['real_id'], $ajax_url.'&amp;course_id='.$course['real_id'], $course['point_info']);
  128. $icon_title = null;
  129. echo '<div class="well_border"><div class="row">';
  130. echo '<div class="span2">';
  131. echo '<div class="thumbnail">';
  132. if (api_get_setting('show_courses_descriptions_in_catalog') == 'true') {
  133. 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'].'" title="'.$icon_title.'" rel="gb_page_center[778]">';
  134. echo '<img src="'.$course_medium_image.'" alt="" />';
  135. echo '</a>';
  136. } else {
  137. echo '<img src="'.$course_medium_image.'" alt="'.$title.'"/>';
  138. }
  139. echo '</div>';//thumb
  140. echo '</div>';
  141. echo '<div class="span4">';
  142. $teachers = CourseManager::get_teacher_list_from_course_code_to_string($course['code']);
  143. $teachers = '<h5>'.$teachers.'</h5>';
  144. echo '<div class="categories-course-description"><h3>'.cut($title, 60).'</h3>'.$teachers.$rating.'</div>';
  145. echo '<p>';
  146. // we display the icon to subscribe or the text already subscribed
  147. echo '<div class="btn-toolbar">';
  148. if (api_get_setting('show_courses_descriptions_in_catalog') == 'true') {
  149. 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'].'" title="'.$icon_title.'" class="thickbox">'.get_lang('Description').'</a>';
  150. }
  151. // Get access type for course button ("enter" or/and "register")
  152. $access_type = CourseManager::get_access_link_by_user(api_get_user_id(), $course);
  153. // Go To Course button (only if admin, if course public or if student already subscribed)
  154. if ($access_type && in_array('enter', $access_type)) {
  155. echo ' <a class="btn btn-primary" href="'. api_get_course_url($course['code']).'">'.get_lang('GoToCourse').'</a>';
  156. }
  157. // Register button
  158. if ($access_type && in_array('register', $access_type)) {
  159. 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>';
  160. }
  161. // If user is already subscribed to the course
  162. if (!api_is_anonymous() && in_array($course['code'], $user_coursecodes)) {
  163. if ($course['unsubscribe'] == UNSUBSCRIBE_ALLOWED) {
  164. 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>';
  165. }
  166. echo '<br />';
  167. echo '<br />';
  168. echo Display::label(get_lang("AlreadyRegisteredToCourse"), "info");
  169. }
  170. echo '</div>';
  171. echo '</p>';
  172. echo '</div>';
  173. echo '<div class="span2">';
  174. echo '<div class="course-block-popularity"><span>'.get_lang('ConnectionsLastMonth').'</span><div class="course-block-popularity-score">'.$count_connections.'</div></div>';
  175. echo '</div>';
  176. echo '</div></div>';
  177. }
  178. } else {
  179. if (!isset($_REQUEST['subscribe_user_with_password']) && !isset($_REQUEST['subscribe_course'])) {
  180. echo Display::display_warning_message(get_lang('ThereAreNoCoursesInThisCategory'));
  181. }
  182. }
  183. ?>
  184. </div>
  185. </div>