courses_list.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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. $teachersIcon = Display::return_icon('teacher.png', get_lang('Teachers'), null, ICON_SIZE_TINY);
  28. // COURSES WITH CATEGORIES
  29. if (!empty($user_course_categories)) {
  30. $counter = 0;
  31. $last = end($user_course_categories);
  32. foreach ($user_course_categories as $row) {
  33. echo Display::page_subheader($row['title']);
  34. echo '<a name="category'.$row['id'].'"></a>';
  35. $url = api_get_path(WEB_CODE_PATH).'auth/courses.php?categoryid='.$row['id'].'&sec_token='.$stok;
  36. if (isset($_GET['categoryid']) && $_GET['categoryid'] == $row['id']) {
  37. ?>
  38. <!-- We display the edit form for the category -->
  39. <form name="edit_course_category" method="post" action="courses.php?action=<?php echo $action; ?>">
  40. <input type="hidden" name="edit_course_category" value="<?php echo $row['id']; ?>" />
  41. <input type="hidden" name="sec_token" value="<?php echo $stok; ?>">
  42. <input type="text" name="title_course_category" value="<?php echo $row['title']; ?>" />
  43. <button class="save" type="submit" name="submit_edit_course_category"><?php echo get_lang('Ok'); ?></button>
  44. </form>
  45. <?php
  46. }
  47. if ($action != 'unsubscribe') {
  48. if ($allowCollapsable) {
  49. if ($row['collapsed'] == 0) {
  50. echo Display::url(
  51. '<i class="fa fa-folder-open"></i>',
  52. $url.'&action=set_collapsable&option=1'
  53. );
  54. } else {
  55. echo Display::url(
  56. '<i class="fa fa-folder"></i>',
  57. $url.'&action=set_collapsable&option=0'
  58. );
  59. }
  60. } ?>
  61. <a href="courses.php?action=sortmycourses&amp;categoryid=<?php echo $row['id']; ?>&amp;sec_token=<?php echo $stok; ?>#category<?php echo $row['id']; ?>">
  62. <?php echo Display::display_icon('edit.png', get_lang('Edit'), '', 22); ?>
  63. </a>
  64. <?php if (0 != $counter) {
  65. ?>
  66. <a href="courses.php?action=<?php echo $action; ?>&amp;move=up&amp;category=<?php echo $row['id']; ?>&amp;sec_token=<?php echo $stok; ?>">
  67. <?php echo Display::return_icon('up.png', get_lang('Up'), '', 22); ?>
  68. </a>
  69. <?php
  70. } else {
  71. ?>
  72. <?php echo Display::return_icon('up_na.png', get_lang('Up'), '', 22); ?>
  73. <?php
  74. }
  75. if ($row['id'] != $last['id']) {
  76. ?>
  77. <a href="courses.php?action=<?php echo $action; ?>&amp;move=down&amp;category=<?php echo $row['id']; ?>&amp;sec_token=<?php echo $stok; ?>">
  78. <?php echo Display::return_icon('down.png', get_lang('Down'), '', 22); ?>
  79. </a>
  80. <?php
  81. } else {
  82. 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. [
  90. 'onclick' => "javascript: if (!confirm('".addslashes(
  91. api_htmlentities(
  92. get_lang('CourseCategoryAbout2bedeleted'),
  93. ENT_QUOTES,
  94. api_get_system_encoding()
  95. )
  96. )."')) return false;",
  97. ],
  98. 22
  99. ); ?>
  100. </a>
  101. <?php
  102. }
  103. $counter++;
  104. echo '<br /><br />';
  105. // Show the courses inside this category
  106. echo '<table class="data_table">';
  107. $number_of_courses = isset($courses_in_category[$row['id']]) ? count($courses_in_category[$row['id']]) : 0;
  108. $key = 0;
  109. if (!empty($courses_in_category[$row['id']])) {
  110. foreach ($courses_in_category[$row['id']] as $course) {
  111. echo '<tr><td>';
  112. echo '<a name="course'.$course['code'].'"></a>';
  113. echo '<strong>'.$course['title'].'</strong>';
  114. echo ' ('.$course['visual_code'].')';
  115. echo '<br />';
  116. echo $teachersIcon;
  117. echo '&nbsp;';
  118. echo CourseManager::getTeacherListFromCourseCodeToString($course['code']);
  119. echo '<br />';
  120. if (api_get_setting('display_teacher_in_courselist') === 'true') {
  121. echo $course['tutor'];
  122. }
  123. echo '</td><td valign="top">';
  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><td>';
  214. echo '<a name="course'.$course['code'].'"></a>';
  215. echo '<strong>'.$course['title'].'</strong>';
  216. echo ' ('.$course['visual_code'].')';
  217. echo '<br />';
  218. echo $teachersIcon;
  219. echo '&nbsp;';
  220. echo CourseManager::getTeacherListFromCourseCodeToString($course['code']);
  221. echo '<br />';
  222. if (api_get_setting('display_teacher_in_courselist') === 'true') {
  223. echo $course['tutor'];
  224. }
  225. echo '</td><td valign="top">';
  226. // the edit icon OR the edit dropdown list
  227. if (isset($_GET['edit']) && $course['code'] == $_GET['edit']) {
  228. $edit_course = Security::remove_XSS($_GET['edit']); ?>
  229. <div style="float:left;">
  230. <form name="edit_course_category" method="post" action="courses.php?action=<?php echo $action; ?>">
  231. <input type="hidden" name="sec_token" value="<?php echo $stok; ?>">
  232. <input type="hidden" name="course_2_edit_category" value="<?php echo $edit_course; ?>" />
  233. <select name="course_categories">
  234. <option value="0"><?php echo get_lang("NoCourseCategory"); ?></option>
  235. <?php foreach ($user_course_categories as $row) {
  236. ?>
  237. <option value="<?php echo $row['id']; ?>"><?php echo $row['title']; ?></option>
  238. <?php
  239. } ?>
  240. </select>
  241. <button class="save" type="submit" name="submit_change_course_category"><?php echo get_lang('Ok'); ?></button>
  242. </form><br />
  243. </div>
  244. <?php
  245. } ?>
  246. <div style="float:left; width:110px">
  247. <?php
  248. if (api_get_setting('show_courses_descriptions_in_catalog') == 'true') {
  249. $icon_title = get_lang('CourseDetails').' - '.$course['title']; ?>
  250. <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">
  251. <?php echo Display::return_icon('info.png', $icon_title, '', '22'); ?>
  252. </a>
  253. <?php
  254. }
  255. if (isset($_GET['edit']) && $course['code'] == $_GET['edit']) {
  256. echo Display::display_icon('edit_na.png', get_lang('Edit'), '', 22);
  257. } else {
  258. ?>
  259. <a href="courses.php?action=<?php echo $action; ?>&amp;edit=<?php echo $course['code']; ?>&amp;sec_token=<?php echo $stok; ?>">
  260. <?php echo Display::display_icon('edit.png', get_lang('Edit'), '', 22); ?>
  261. </a>
  262. <?php
  263. }
  264. if ($key > 0) {
  265. ?>
  266. <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; ?>">
  267. <?php echo Display::display_icon('up.png', get_lang('Up'), '', 22); ?>
  268. </a>
  269. <?php
  270. } else {
  271. echo Display::display_icon('up_na.png', get_lang('Up'), '', 22);
  272. }
  273. if ($key < $number_of_courses - 1) {
  274. ?>
  275. <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; ?>">
  276. <?php echo Display::display_icon('down.png', get_lang('Down'), '', 22); ?>
  277. </a>
  278. <?php
  279. } else {
  280. echo Display::display_icon('down_na.png', get_lang('Down'), '', 22);
  281. } ?>
  282. </div>
  283. <div style="float:left; margin-right:10px;">
  284. <!-- cancel subscrioption-->
  285. <?php
  286. if ($course['status'] != 1) {
  287. if ($course['unsubscr'] == 1) {
  288. ?>
  289. <!-- changed link to submit to avoid action by the search tool indexer -->
  290. <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;">
  291. <input type="hidden" name="sec_token" value="<?php echo $stok; ?>">
  292. <input type="hidden" name="unsubscribe" value="<?php echo $course['code']; ?>" />
  293. <button class="btn btn-default" value="<?php echo get_lang('Unsubscribe'); ?>" name="unsub">
  294. <?php echo get_lang('Unsubscribe'); ?>
  295. </button>
  296. </form>
  297. </div>
  298. <?php
  299. }
  300. } ?>
  301. </td>
  302. </tr>
  303. <?php
  304. $key++;
  305. }
  306. }
  307. ?>
  308. </table>