courses_list.php 16 KB

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