courses_list.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * View (MVC patter) for courses
  5. * @todo fix this. use twig templates
  6. * @author Christian Fasanando <christian1827@gmail.com> - Beeznest
  7. * @package chamilo.auth
  8. */
  9. // Access rights: anonymous users can't do anything usefull here.
  10. api_block_anonymous_users();
  11. $stok = Security::get_token();
  12. $courses_without_category = isset($courses_in_category[0]) ? $courses_in_category[0] : null;
  13. ?>
  14. <!-- Actions: The menu with the different options in cathe course management -->
  15. <div id="actions" class="actions">
  16. <?php if ($action != 'createcoursecategory') { ?>
  17. <a href="<?php echo api_get_self(); ?>?action=createcoursecategory">
  18. <?php echo Display::return_icon('new_folder.png', get_lang('CreateCourseCategory'), '', '32'); ?></a>
  19. <?php } ?>
  20. </div>
  21. <?php
  22. if (!empty($message)) {
  23. echo Display::return_message($message, 'confirm', false);
  24. }
  25. // COURSES WITH CATEGORIES
  26. if (!empty($user_course_categories)) {
  27. $counter = 0;
  28. $last = end($user_course_categories);
  29. foreach ($user_course_categories as $row) {
  30. echo Display::page_subheader($row['title']);
  31. echo '<a name="category'.$row['id'].'"></a>';
  32. if (isset($_GET['categoryid']) && $_GET['categoryid'] == $row['id']) { ?>
  33. <!-- We display the edit form for the category -->
  34. <form name="edit_course_category" method="post" action="courses.php?action=<?php echo $action; ?>">
  35. <input type="hidden" name="edit_course_category" value="<?php echo $row['id']; ?>" />
  36. <input type="hidden" name="sec_token" value="<?php echo $stok; ?>">
  37. <input type="text" name="title_course_category" value="<?php echo $row['title']; ?>" />
  38. <button class="save" type="submit" name="submit_edit_course_category"><?php echo get_lang('Ok'); ?></button>
  39. </form>
  40. <?php
  41. }
  42. $max_category_key = count($user_course_categories);
  43. if ($action != 'unsubscribe') { ?>
  44. <a href="courses.php?action=sortmycourses&amp;categoryid=<?php echo $row['id']; ?>&amp;sec_token=<?php echo $stok; ?>#category<?php echo $row['id']; ?>">
  45. <?php echo Display::display_icon('edit.png', get_lang('Edit'), '', 22); ?>
  46. </a>
  47. <?php if (0 != $counter) { ?>
  48. <a href="courses.php?action=<?php echo $action ?>&amp;move=up&amp;category=<?php echo $row['id']; ?>&amp;sec_token=<?php echo $stok; ?>">
  49. <?php echo Display::return_icon('up.png', get_lang('Up'), '', 22); ?>
  50. </a>
  51. <?php } else { ?>
  52. <?php echo Display::return_icon('up_na.png', get_lang('Up'), '', 22); ?>
  53. <?php } ?>
  54. <?php if ($row['id'] != $last['id']) { ?>
  55. <a href="courses.php?action=<?php echo $action; ?>&amp;move=down&amp;category=<?php echo $row['id']; ?>&amp;sec_token=<?php echo $stok; ?>">
  56. <?php echo Display::return_icon('down.png', get_lang('Down'), '', 22); ?>
  57. </a>
  58. <?php } else { ?>
  59. <?php echo Display::return_icon('down_na.png', get_lang('Down'), '', 22); ?>
  60. <?php } ?>
  61. <a href="courses.php?action=deletecoursecategory&amp;id=<?php echo $row['id']; ?>&amp;sec_token=<?php echo $stok; ?>">
  62. <?php echo Display::display_icon('delete.png', get_lang('Delete'), array('onclick' => "javascript: if (!confirm('".addslashes(api_htmlentities(get_lang("CourseCategoryAbout2bedeleted"), ENT_QUOTES, api_get_system_encoding()))."')) return false;"), 22) ?>
  63. </a>
  64. <?php }
  65. $counter++;
  66. echo '<br /><br />';
  67. // Show the courses inside this category
  68. echo '<table class="data_table">';
  69. $number_of_courses = isset($courses_in_category[$row['id']]) ? count($courses_in_category[$row['id']]) : 0;
  70. $key = 0;
  71. if (!empty($courses_in_category[$row['id']])) {
  72. foreach ($courses_in_category[$row['id']] as $course) {
  73. ?>
  74. <tr>
  75. <td>
  76. <a name="course<?php echo $course['code']; ?>"></a>
  77. <strong><?php echo $course['title']; ?></strong><br />
  78. <?php
  79. if (api_get_setting('display_coursecode_in_courselist') === 'true') {
  80. echo $course['visual_code'];
  81. }
  82. if (api_get_setting('display_coursecode_in_courselist') === 'true' &&
  83. api_get_setting('display_teacher_in_courselist') === 'true'
  84. ) {
  85. echo " - ";
  86. }
  87. if (api_get_setting('display_teacher_in_courselist') === 'true') {
  88. echo $course['tutor'];
  89. }
  90. ?>
  91. </td>
  92. <td valign="top">
  93. <!-- edit -->
  94. <?php
  95. if (isset($_GET['edit']) && $course['code'] == $_GET['edit']) {
  96. $edit_course = Security::remove_XSS($_GET['edit']); ?>
  97. <form name="edit_course_category" method="post" action="courses.php?action=<?php echo $action; ?>">
  98. <input type="hidden" name="sec_token" value="<?php echo $stok; ?>">
  99. <input type="hidden" name="course_2_edit_category" value="<?php echo $edit_course; ?>" />
  100. <select name="course_categories">
  101. <option value="0"><?php echo get_lang("NoCourseCategory"); ?></option>
  102. <?php foreach ($user_course_categories as $row) { ?>
  103. <option value="<?php echo $row['id'] ?>"><?php echo $row['title']; ?></option>
  104. <?php } ?>
  105. </select>
  106. <button class="save" type="submit" name="submit_change_course_category"><?php echo get_lang('Ok'); ?></button>
  107. </form>
  108. <?php } ?>
  109. <div style="float:left;width:110px;">
  110. <?php
  111. if (api_get_setting('show_courses_descriptions_in_catalog') == 'true') {
  112. $icon_title = get_lang('CourseDetails').' - '.$course['title'];
  113. ?>
  114. <a href="<?php echo api_get_path(WEB_CODE_PATH); ?>inc/ajax/course_home.ajax.php?a=show_course_information&code=<?php echo $course['code'] ?>" data-title="<?php echo $icon_title ?>" title="<?php echo $icon_title ?>" class="ajax">
  115. <?php echo Display::return_icon('info.png', $icon_title, '', '22') ?>
  116. <?php } ?>
  117. </a>
  118. <?php if (isset($_GET['edit']) && $course['code'] == $_GET['edit']) { ?>
  119. <?php echo Display::display_icon('edit_na.png', get_lang('Edit'), '', 22); ?>
  120. <?php } else { ?>
  121. <a href="courses.php?action=<?php echo $action; ?>&amp;edit=<?php echo $course['code']; ?>&amp;sec_token=<?php echo $stok; ?>">
  122. <?php echo Display::display_icon('edit.png', get_lang('Edit'), '', 22); ?>
  123. </a>
  124. <?php } ?>
  125. <?php if ($key > 0) { ?>
  126. <a href="courses.php?action=<?php echo $action; ?>&amp;move=up&amp;course=<?php echo $course['code']; ?>&amp;category=<?php echo $course['user_course_cat']; ?>&amp;sec_token=<?php echo $stok; ?>">
  127. <?php echo Display::display_icon('up.png', get_lang('Up'), '', 22); ?>
  128. </a>
  129. <?php } else { ?>
  130. <?php echo Display::display_icon('up_na.png', get_lang('Up'), '', 22); ?>
  131. <?php } ?>
  132. <?php if ($key < $number_of_courses - 1) { ?>
  133. <a href="courses.php?action=<?php echo $action; ?>&amp;move=down&amp;course=<?php echo $course['code']; ?>&amp;category=<?php echo $course['user_course_cat']; ?>&amp;sec_token=<?php echo $stok; ?>">
  134. <?php echo Display::display_icon('down.png', get_lang('Down'), '', 22); ?>
  135. </a>
  136. <?php } else { ?>
  137. <?php echo Display::display_icon('down_na.png', get_lang('Down'), '', 22); ?>
  138. <?php } ?>
  139. </div>
  140. <div style="float:left; margin-right:10px;">
  141. <?php
  142. if ($course['status'] != 1) {
  143. if ($course['unsubscr'] == 1) {
  144. ?>
  145. <form action="<?php echo api_get_self(); ?>" method="post" onsubmit="javascript: if (!confirm('<?php echo addslashes(api_htmlentities(get_lang("ConfirmUnsubscribeFromCourse"), ENT_QUOTES, api_get_system_encoding()))?>')) return false">
  146. <input type="hidden" name="sec_token" value="<?php echo $stok; ?>">
  147. <input type="hidden" name="unsubscribe" value="<?php echo $course['code']; ?>" />
  148. <button class="btn btn-default" value="<?php echo get_lang('Unsubscribe'); ?>" name="unsub">
  149. <?php echo get_lang('Unsubscribe'); ?>
  150. </button>
  151. </form>
  152. </div>
  153. <?php }
  154. }
  155. $key++;
  156. }
  157. echo '</table>';
  158. }
  159. }
  160. }
  161. echo Display::page_subheader(get_lang('NoCourseCategory'));
  162. echo '<table class="data_table">';
  163. // COURSES WITHOUT CATEGORY
  164. if (!empty($courses_without_category)) {
  165. $number_of_courses = count($courses_without_category);
  166. $key = 0;
  167. foreach ($courses_without_category as $course) {
  168. echo '<tr>';
  169. ?>
  170. <td>
  171. <a name="course<?php echo $course['code']; ?>"></a>
  172. <strong><?php echo $course['title']; ?></strong><br />
  173. <?php
  174. if (api_get_setting('display_coursecode_in_courselist') === 'true') {
  175. echo $course['visual_code'];
  176. }
  177. if (api_get_setting('display_coursecode_in_courselist') === 'true' &&
  178. api_get_setting('display_teacher_in_courselist') === 'true'
  179. ) {
  180. echo " - ";
  181. }
  182. if (api_get_setting('display_teacher_in_courselist') === 'true') {
  183. echo $course['tutor'];
  184. }
  185. ?>
  186. </td>
  187. <td valign="top">
  188. <!-- the edit icon OR the edit dropdown list -->
  189. <?php if (isset($_GET['edit']) && $course['code'] == $_GET['edit']) {
  190. $edit_course = Security::remove_XSS($_GET['edit']);
  191. ?>
  192. <div style="float:left;">
  193. <form name="edit_course_category" method="post" action="courses.php?action=<?php echo $action; ?>">
  194. <input type="hidden" name="sec_token" value="<?php echo $stok; ?>">
  195. <input type="hidden" name="course_2_edit_category" value="<?php echo $edit_course; ?>" />
  196. <select name="course_categories">
  197. <option value="0"><?php echo get_lang("NoCourseCategory"); ?></option>
  198. <?php foreach ($user_course_categories as $row) { ?>
  199. <option value="<?php echo $row['id']; ?>"><?php echo $row['title']; ?></option>
  200. <?php } ?>
  201. </select>
  202. <button class="save" type="submit" name="submit_change_course_category"><?php echo get_lang('Ok') ?></button>
  203. </form><br />
  204. </div>
  205. <?php } ?>
  206. <div style="float:left; width:110px">
  207. <?php
  208. if (api_get_setting('show_courses_descriptions_in_catalog') == 'true') {
  209. $icon_title = get_lang('CourseDetails').' - '.$course['title'];
  210. ?>
  211. <a href="<?php echo api_get_path(WEB_CODE_PATH); ?>inc/ajax/course_home.ajax.php?a=show_course_information&code=<?php echo $course['code'] ?>" data-title="<?php echo $icon_title ?>" title="<?php echo $icon_title ?>" class="ajax">
  212. <?php echo Display::return_icon('info.png', $icon_title, '', '22'); ?>
  213. </a>
  214. <?php }
  215. if (isset($_GET['edit']) && $course['code'] == $_GET['edit']) { ?>
  216. <?php echo Display::display_icon('edit_na.png', get_lang('Edit'), '', 22); ?>
  217. <?php } else { ?>
  218. <a href="courses.php?action=<?php echo $action; ?>&amp;edit=<?php echo $course['code']; ?>&amp;sec_token=<?php echo $stok; ?>">
  219. <?php echo Display::display_icon('edit.png', get_lang('Edit'), '', 22); ?>
  220. </a>
  221. <?php } ?>
  222. <!-- up /down icons-->
  223. <?php if ($key > 0) { ?>
  224. <a href="courses.php?action=<?php echo $action; ?>&amp;move=up&amp;course=<?php echo $course['code']; ?>&amp;category=<?php echo $course['user_course_cat']; ?>&amp;sec_token=<?php echo $stok; ?>">
  225. <?php echo Display::display_icon('up.png', get_lang('Up'), '', 22) ?>
  226. </a>
  227. <?php } else {
  228. echo Display::display_icon('up_na.png', get_lang('Up'), '', 22);
  229. }
  230. if ($key < $number_of_courses - 1) { ?>
  231. <a href="courses.php?action=<?php echo $action; ?>&amp;move=down&amp;course=<?php echo $course['code']; ?>&amp;category=<?php echo $course['user_course_cat']; ?>&amp;sec_token=<?php echo $stok; ?>">
  232. <?php echo Display::display_icon('down.png', get_lang('Down'), '', 22); ?>
  233. </a>
  234. <?php } else {
  235. echo Display::display_icon('down_na.png', get_lang('Down'), '', 22);
  236. }?>
  237. </div>
  238. <div style="float:left; margin-right:10px;">
  239. <!-- cancel subscrioption-->
  240. <?php
  241. if ($course['status'] != 1) {
  242. if ($course['unsubscr'] == 1) {
  243. ?>
  244. <!-- changed link to submit to avoid action by the search tool indexer -->
  245. <form action="<?php echo api_get_self(); ?>" method="post" onsubmit="javascript: if (!confirm('<?php echo addslashes(api_htmlentities(get_lang("ConfirmUnsubscribeFromCourse"), ENT_QUOTES, api_get_system_encoding())) ?>')) return false;">
  246. <input type="hidden" name="sec_token" value="<?php echo $stok; ?>">
  247. <input type="hidden" name="unsubscribe" value="<?php echo $course['code']; ?>" />
  248. <button class="btn btn-default" value="<?php echo get_lang('Unsubscribe'); ?>" name="unsub">
  249. <?php echo get_lang('Unsubscribe'); ?>
  250. </button>
  251. </form>
  252. </div>
  253. <?php }
  254. }
  255. ?>
  256. </td>
  257. </tr>
  258. <?php
  259. $key++;
  260. }
  261. }
  262. ?>
  263. </table>