course_request_edit.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * A page for detailed preview or edition of a given course request.
  5. *
  6. * @package chamilo.admin
  7. *
  8. * @author Ivan Tcholakov <ivantcholakov@gmail.com>, 2010
  9. */
  10. $cidReset = true;
  11. require_once __DIR__.'/../inc/global.inc.php';
  12. $this_section = SECTION_PLATFORM_ADMIN;
  13. $tool_name = get_lang('CourseRequestEdit');
  14. api_protect_admin_script();
  15. // A check whether the course validation feature is enabled.
  16. $course_validation_feature = api_get_setting('course_validation') == 'true';
  17. // Filtering passed to this page parameters.
  18. $id = intval($_GET['id']);
  19. $caller = intval($_GET['caller']);
  20. if ($course_validation_feature) {
  21. // Retrieve request's data from the corresponding database record.
  22. $course_request_info = CourseRequestManager::get_course_request_info($id);
  23. if (!is_array($course_request_info)) {
  24. // Prepare an error message notifying that the course request has not been found or does not exist.
  25. Display::addFlash(
  26. Display::return_message(
  27. get_lang('CourseRequestHasNotBeenFound'),
  28. 'warning',
  29. false
  30. )
  31. );
  32. } else {
  33. // Ensure the database prefix + database name do not get over 40 characters.
  34. $maxlength = 40;
  35. // Build the form.
  36. $form = new FormValidator(
  37. 'add_course',
  38. 'post',
  39. 'course_request_edit.php?id='.$id.'&caller='.$caller
  40. );
  41. // Form title.
  42. $form->addElement('header', $tool_name);
  43. // Title.
  44. $form->addElement('text', 'title', get_lang('CourseName'), ['size' => '60', 'id' => 'title']);
  45. $form->applyFilter('title', 'html_filter');
  46. $form->addRule('title', get_lang('ThisFieldIsRequired'), 'required');
  47. // Course category.
  48. $url = api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=search_category';
  49. $courseSelect = $form->addElement(
  50. 'select_ajax',
  51. 'category_code',
  52. get_lang('CourseFaculty'),
  53. null,
  54. ['url' => $url]
  55. );
  56. if (!empty($course_request_info['category_code'])) {
  57. $data = CourseCategory::getCategory($course_request_info['category_code']);
  58. $courseSelect->addOption($data['name'], $data['code'], ['selected' => 'selected']);
  59. }
  60. // Course code.
  61. $form->addText('wanted_code', get_lang('Code'), false, ['size' => '$maxlength', 'maxlength' => $maxlength]);
  62. $form->applyFilter('wanted_code', 'html_filter');
  63. $form->addRule('wanted_code', get_lang('Max'), 'maxlength', $maxlength);
  64. $form->addRule('wanted_code', get_lang('ThisFieldIsRequired'), 'required');
  65. // The teacher.
  66. $titular = $form->addText(
  67. 'tutor_name',
  68. get_lang('Professor'),
  69. null,
  70. ['size' => '60', 'disabled' => 'disabled']
  71. );
  72. // Description of the requested course.
  73. $form->addElement('textarea', 'description', get_lang('Description'));
  74. $form->addRule('description', get_lang('ThisFieldIsRequired'), 'required');
  75. // Objectives of the requested course.
  76. $form->addElement('textarea', 'objetives', get_lang('Objectives'));
  77. $form->addRule('objetives', get_lang('ThisFieldIsRequired'), 'required');
  78. // Target audience of the requested course.
  79. $form->addElement('textarea', 'target_audience', get_lang('TargetAudience'));
  80. $form->addRule('target_audience', get_lang('ThisFieldIsRequired'), 'required');
  81. // Course language.
  82. $form->addSelectLanguage('course_language', get_lang('Ln'));
  83. // Exemplary content checkbox.
  84. $form->addElement('checkbox', 'exemplary_content', get_lang('FillWithExemplaryContent'));
  85. // Submit buttons.
  86. $submit_buttons[] = $form->addButtonSave(get_lang('Save'), 'save_button', true);
  87. if ($course_request_info['status'] != COURSE_REQUEST_ACCEPTED) {
  88. $submit_buttons[] = $form->addButtonSave(get_lang('Accept'), 'accept_button', true);
  89. }
  90. if ($course_request_info['status'] != COURSE_REQUEST_ACCEPTED &&
  91. $course_request_info['status'] != COURSE_REQUEST_REJECTED
  92. ) {
  93. $submit_buttons[] = $form->addButtonCancel(get_lang('Reject'), 'reject_button', true);
  94. }
  95. if ($course_request_info['status'] != COURSE_REQUEST_ACCEPTED && intval($course_request_info['info']) <= 0) {
  96. $submit_buttons[] = $form->addButtonPreview(get_lang('AskAdditionalInfo'), 'ask_info_button', true);
  97. }
  98. $form->addGroup($submit_buttons);
  99. // Hidden form fields.
  100. $form->addElement('hidden', 'user_id');
  101. $form->addElement('hidden', 'directory');
  102. $form->addElement('hidden', 'visual_code');
  103. $form->addElement('hidden', 'request_date');
  104. $form->addElement('hidden', 'status');
  105. $form->addElement('hidden', 'info');
  106. // Set the default values based on the corresponding database record.
  107. $values['wanted_code'] = $course_request_info['code'];
  108. $values['user_id'] = $course_request_info['user_id'];
  109. $values['directory'] = $course_request_info['directory'];
  110. $values['course_language'] = $course_request_info['course_language'];
  111. $values['title'] = $course_request_info['title'];
  112. $values['description'] = $course_request_info['description'];
  113. //$values['category_code'] = $course_request_info['category_code'];
  114. $values['tutor_name'] = $course_request_info['tutor_name'];
  115. $values['visual_code'] = $course_request_info['visual_code'];
  116. $values['request_date'] = $course_request_info['request_date'];
  117. $values['objetives'] = $course_request_info['objetives'];
  118. $values['target_audience'] = $course_request_info['target_audience'];
  119. $values['status'] = $course_request_info['status'];
  120. $values['info'] = $course_request_info['info'];
  121. $values['exemplary_content'] = $course_request_info['exemplary_content'];
  122. $form->setDefaults($values);
  123. // Validate the form and perform the ordered actions.
  124. if ($form->validate()) {
  125. $course_request_values = $form->getSubmitValues();
  126. // Detection which submit button has been pressed.
  127. $submit_button = isset($_POST['save_button']) ? 'save_button'
  128. : (isset($_POST['accept_button']) ? 'accept_button'
  129. : (isset($_POST['reject_button']) ? 'reject_button'
  130. : (isset($_POST['ask_info_button']) ? 'ask_info_button'
  131. : 'submit_button')));
  132. // Check the course code for avoiding duplication.
  133. $course_code_ok = $course_request_values['wanted_code'] == $course_request_info['code']
  134. ? true
  135. : !CourseRequestManager::course_code_exists($course_request_values['wanted_code']);
  136. if ($course_code_ok) {
  137. $message = [];
  138. // Update the course request.
  139. $update_ok = CourseRequestManager::update_course_request(
  140. $id,
  141. $course_request_values['wanted_code'],
  142. $course_request_values['title'],
  143. $course_request_values['description'],
  144. $course_request_values['category_code'],
  145. $course_request_values['course_language'],
  146. $course_request_values['objetives'],
  147. $course_request_values['target_audience'],
  148. $course_request_values['user_id'],
  149. $course_request_values['exemplary_content']
  150. );
  151. if ($update_ok) {
  152. Display::addFlash(
  153. Display::return_message(
  154. sprintf(
  155. get_lang('CourseRequestUpdated'),
  156. $course_request_values['wanted_code']
  157. ),
  158. 'normal',
  159. false
  160. )
  161. );
  162. switch ($submit_button) {
  163. case 'accept_button':
  164. if (CourseRequestManager::accept_course_request($id)) {
  165. Display::addFlash(
  166. Display::return_message(
  167. sprintf(
  168. get_lang('CourseRequestAccepted'),
  169. $course_request_values['wanted_code'],
  170. $course_request_values['wanted_code']
  171. ),
  172. 'normal',
  173. false
  174. )
  175. );
  176. } else {
  177. Display::addFlash(
  178. Display::return_message(
  179. sprintf(
  180. get_lang('CourseRequestAcceptanceFailed'),
  181. $course_request_values['wanted_code']
  182. )
  183. ),
  184. 'error',
  185. false
  186. );
  187. }
  188. break;
  189. case 'reject_button':
  190. if (CourseRequestManager::reject_course_request($id)) {
  191. Display::addFlash(
  192. Display::return_message(
  193. sprintf(
  194. get_lang('CourseRequestRejected'),
  195. $course_request_values['wanted_code']
  196. )
  197. ),
  198. 'normal',
  199. false
  200. );
  201. } else {
  202. Display::addFlash(
  203. Display::return_message(
  204. sprintf(
  205. get_lang('CourseRequestRejectionFailed'),
  206. $course_request_values['wanted_code']
  207. )
  208. ),
  209. 'error',
  210. false
  211. );
  212. }
  213. break;
  214. case 'ask_info_button':
  215. if (CourseRequestManager::ask_for_additional_info($id)) {
  216. Display::addFlash(
  217. Display::return_message(
  218. sprintf(
  219. get_lang('CourseRequestInfoAsked'),
  220. $course_request_values['wanted_code']
  221. )
  222. ),
  223. 'normal',
  224. false
  225. );
  226. } else {
  227. Display::addFlash(
  228. Display::return_message(
  229. sprintf(
  230. get_lang('CourseRequestInfoFailed'),
  231. $course_request_values['wanted_code']
  232. )
  233. ),
  234. 'error',
  235. false
  236. );
  237. }
  238. break;
  239. }
  240. } else {
  241. Display::addFlash(
  242. Display::return_message(
  243. sprintf(
  244. get_lang('CourseRequestUpdateFailed'),
  245. $course_request_values['wanted_code']
  246. )
  247. ),
  248. 'error',
  249. false
  250. );
  251. }
  252. $back_url = get_caller_name($caller);
  253. header('location:'.$back_url);
  254. exit;
  255. } else {
  256. Display::addFlash(
  257. Display::return_message(
  258. $course_request_values['wanted_code'].' - '.get_lang('CourseCodeAlreadyExists')
  259. ),
  260. 'error',
  261. false
  262. );
  263. }
  264. }
  265. }
  266. } else {
  267. // Prepare an error message notifying that the course validation feature has not been enabled.
  268. $link_to_setting = api_get_path(WEB_CODE_PATH).'admin/settings.php?search_field=course_validation&submit_button=&category=search_setting';
  269. $message = sprintf(
  270. get_lang('PleaseActivateCourseValidationFeature'),
  271. sprintf(
  272. '<strong><a href="%s">%s</a></strong>',
  273. $link_to_setting,
  274. get_lang('EnableCourseValidation')
  275. )
  276. );
  277. Display::addFlash(
  278. Display::return_message($message),
  279. 'error',
  280. false
  281. );
  282. }
  283. // Functions.
  284. // Converts the given numerical id to the name of the page that opened this editor.
  285. function get_caller_name($caller_id)
  286. {
  287. switch ($caller_id) {
  288. case 1:
  289. return 'course_request_accepted.php';
  290. case 2:
  291. return 'course_request_rejected.php';
  292. }
  293. return 'course_request_review.php';
  294. }
  295. // The header.
  296. $interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
  297. $interbreadcrumb[] = ['url' => 'course_list.php', 'name' => get_lang('CourseList')];
  298. Display :: display_header($tool_name);
  299. if (!$course_validation_feature) {
  300. // Disabled course validation feature - show nothing after the error message.
  301. Display::display_footer();
  302. exit;
  303. }
  304. // The action bar.
  305. echo '<div class="actions">';
  306. echo '<a href="course_list.php">'.
  307. Display::return_icon('courses.gif', get_lang('CourseList')).get_lang('CourseList').'</a>';
  308. echo '<a href="course_request_review.php">'.
  309. Display::return_icon('course_request_pending.png', get_lang('ReviewCourseRequests')).get_lang('ReviewCourseRequests').
  310. '</a>';
  311. echo '<a href="course_request_accepted.php">'.
  312. Display::return_icon('course_request_accepted.gif', get_lang('AcceptedCourseRequests')).get_lang('AcceptedCourseRequests').
  313. '</a>';
  314. echo '<a href="course_request_rejected.php">'.
  315. Display::return_icon('course_request_rejected.gif', get_lang('RejectedCourseRequests')).get_lang('RejectedCourseRequests').
  316. '</a>';
  317. echo '</div>';
  318. if (!is_array($course_request_info)) {
  319. // Not accessible database record - show the error message and the action bar.
  320. Display::display_footer();
  321. exit;
  322. }
  323. // Display the form.
  324. $form->display();
  325. // The footer.
  326. Display::display_footer();