courses_list.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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. if (api_get_setting('display_coursecode_in_courselist') === 'true') {
  115. echo ' ('.$course['visual_code'].')';
  116. }
  117. echo '<br />';
  118. echo $teachersIcon;
  119. echo '&nbsp;';
  120. echo CourseManager::getTeacherListFromCourseCodeToString($course['code']);
  121. echo '<br />';
  122. if (api_get_setting('display_teacher_in_courselist') === 'true') {
  123. echo $course['tutor'];
  124. }
  125. echo '</td><td valign="top">';
  126. if (isset($_GET['edit']) && $course['code'] == $_GET['edit']) {
  127. $edit_course = Security::remove_XSS($_GET['edit']); ?>
  128. <form name="edit_course_category" method="post" action="courses.php?action=<?php echo $action; ?>">
  129. <input type="hidden" name="sec_token" value="<?php echo $stok; ?>">
  130. <input type="hidden" name="course_2_edit_category" value="<?php echo $edit_course; ?>" />
  131. <select name="course_categories">
  132. <option value="0"><?php echo get_lang('NoCourseCategory'); ?></option>
  133. <?php foreach ($user_course_categories as $row) {
  134. ?>
  135. <option value="<?php echo $row['id']; ?>"><?php echo $row['title']; ?></option>
  136. <?php
  137. } ?>
  138. </select>
  139. <button class="save" type="submit" name="submit_change_course_category"><?php echo get_lang('Ok'); ?></button>
  140. </form>
  141. <?php
  142. } ?>
  143. <div style="float:left;width:110px;">
  144. <?php
  145. if (api_get_setting('show_courses_descriptions_in_catalog') == 'true') {
  146. $icon_title = get_lang('CourseDetails').' - '.$course['title']; ?>
  147. <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">
  148. <?php echo Display::return_icon('info.png', $icon_title, '', '22'); ?>
  149. <?php
  150. } ?>
  151. </a>
  152. <?php if (isset($_GET['edit']) && $course['code'] == $_GET['edit']) {
  153. ?>
  154. <?php echo Display::display_icon('edit_na.png', get_lang('Edit'), '', 22); ?>
  155. <?php
  156. } else {
  157. ?>
  158. <a href="courses.php?action=<?php echo $action; ?>&amp;edit=<?php echo $course['code']; ?>&amp;sec_token=<?php echo $stok; ?>">
  159. <?php echo Display::display_icon('edit.png', get_lang('Edit'), '', 22); ?>
  160. </a>
  161. <?php
  162. } ?>
  163. <?php if ($key > 0) {
  164. ?>
  165. <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; ?>">
  166. <?php echo Display::display_icon('up.png', get_lang('Up'), '', 22); ?>
  167. </a>
  168. <?php
  169. } else {
  170. ?>
  171. <?php echo Display::display_icon('up_na.png', get_lang('Up'), '', 22); ?>
  172. <?php
  173. } ?>
  174. <?php if ($key < $number_of_courses - 1) {
  175. ?>
  176. <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; ?>">
  177. <?php echo Display::display_icon('down.png', get_lang('Down'), '', 22); ?>
  178. </a>
  179. <?php
  180. } else {
  181. ?>
  182. <?php echo Display::display_icon('down_na.png', get_lang('Down'), '', 22); ?>
  183. <?php
  184. } ?>
  185. </div>
  186. <div style="float:left; margin-right:10px;">
  187. <?php
  188. if ($course['status'] != 1) {
  189. if ($course['unsubscr'] == 1) {
  190. ?>
  191. <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">
  192. <input type="hidden" name="sec_token" value="<?php echo $stok; ?>">
  193. <input type="hidden" name="unsubscribe" value="<?php echo $course['code']; ?>" />
  194. <button class="btn btn-default" value="<?php echo get_lang('Unsubscribe'); ?>" name="unsub">
  195. <?php echo get_lang('Unsubscribe'); ?>
  196. </button>
  197. </form>
  198. </div>
  199. <?php
  200. }
  201. }
  202. $key++;
  203. }
  204. echo '</table>';
  205. }
  206. }
  207. }
  208. echo Display::page_subheader(get_lang('NoCourseCategory'));
  209. echo '<table class="data_table">';
  210. // COURSES WITHOUT CATEGORY
  211. if (!empty($courses_without_category)) {
  212. $number_of_courses = count($courses_without_category);
  213. $key = 0;
  214. foreach ($courses_without_category as $course) {
  215. echo '<tr><td>';
  216. echo '<a name="course'.$course['code'].'"></a>';
  217. echo '<strong>'.$course['title'].'</strong>';
  218. if (api_get_setting('display_coursecode_in_courselist') === 'true') {
  219. echo ' ('.$course['visual_code'].')';
  220. }
  221. echo '<br />';
  222. echo $teachersIcon;
  223. echo '&nbsp;';
  224. echo CourseManager::getTeacherListFromCourseCodeToString($course['code']);
  225. echo '<br />';
  226. if (api_get_setting('display_teacher_in_courselist') === 'true') {
  227. echo $course['tutor'];
  228. }
  229. echo '</td><td valign="top">';
  230. // the edit icon OR the edit dropdown list
  231. if (isset($_GET['edit']) && $course['code'] == $_GET['edit']) {
  232. $edit_course = Security::remove_XSS($_GET['edit']); ?>
  233. <div style="float:left;">
  234. <form name="edit_course_category" method="post" action="courses.php?action=<?php echo $action; ?>">
  235. <input type="hidden" name="sec_token" value="<?php echo $stok; ?>">
  236. <input type="hidden" name="course_2_edit_category" value="<?php echo $edit_course; ?>" />
  237. <select name="course_categories">
  238. <option value="0"><?php echo get_lang("NoCourseCategory"); ?></option>
  239. <?php foreach ($user_course_categories as $row) {
  240. ?>
  241. <option value="<?php echo $row['id']; ?>"><?php echo $row['title']; ?></option>
  242. <?php
  243. } ?>
  244. </select>
  245. <button class="save" type="submit" name="submit_change_course_category"><?php echo get_lang('Ok'); ?></button>
  246. </form><br />
  247. </div>
  248. <?php
  249. } ?>
  250. <div style="float:left; width:110px">
  251. <?php
  252. if (api_get_setting('show_courses_descriptions_in_catalog') == 'true') {
  253. $icon_title = get_lang('CourseDetails').' - '.$course['title']; ?>
  254. <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">
  255. <?php echo Display::return_icon('info.png', $icon_title, '', '22'); ?>
  256. </a>
  257. <?php
  258. }
  259. if (isset($_GET['edit']) && $course['code'] == $_GET['edit']) {
  260. echo Display::display_icon('edit_na.png', get_lang('Edit'), '', 22);
  261. } else {
  262. ?>
  263. <a href="courses.php?action=<?php echo $action; ?>&amp;edit=<?php echo $course['code']; ?>&amp;sec_token=<?php echo $stok; ?>">
  264. <?php echo Display::display_icon('edit.png', get_lang('Edit'), '', 22); ?>
  265. </a>
  266. <?php
  267. }
  268. if ($key > 0) {
  269. ?>
  270. <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; ?>">
  271. <?php echo Display::display_icon('up.png', get_lang('Up'), '', 22); ?>
  272. </a>
  273. <?php
  274. } else {
  275. echo Display::display_icon('up_na.png', get_lang('Up'), '', 22);
  276. }
  277. if ($key < $number_of_courses - 1) {
  278. ?>
  279. <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; ?>">
  280. <?php echo Display::display_icon('down.png', get_lang('Down'), '', 22); ?>
  281. </a>
  282. <?php
  283. } else {
  284. echo Display::display_icon('down_na.png', get_lang('Down'), '', 22);
  285. } ?>
  286. </div>
  287. <div style="float:left; margin-right:10px;">
  288. <!-- cancel subscrioption-->
  289. <?php
  290. if ($course['status'] != 1) {
  291. if ($course['unsubscr'] == 1) {
  292. ?>
  293. <!-- changed link to submit to avoid action by the search tool indexer -->
  294. <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;">
  295. <input type="hidden" name="sec_token" value="<?php echo $stok; ?>">
  296. <input type="hidden" name="unsubscribe" value="<?php echo $course['code']; ?>" />
  297. <button class="btn btn-default" value="<?php echo get_lang('Unsubscribe'); ?>" name="unsub">
  298. <?php echo get_lang('Unsubscribe'); ?>
  299. </button>
  300. </form>
  301. </div>
  302. <?php
  303. }
  304. } ?>
  305. </td>
  306. </tr>
  307. <?php
  308. $key++;
  309. }
  310. }
  311. ?>
  312. </table>