course_request_edit.php 15 KB

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