course_request_edit.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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 '../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. // Filltering 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. $message = get_lang('CourseRequestHasNotBeenFound');
  24. $is_error_message = true;
  25. } else {
  26. // Ensure the database prefix + database name do not get over 40 characters.
  27. $maxlength = 40;
  28. // Build the form.
  29. $form = new FormValidator('add_course', 'post', 'course_request_edit.php?id='.$id.'&caller='.$caller);
  30. // Form title.
  31. $form->addElement('header', $tool_name);
  32. // Title.
  33. $form->addElement('text', 'title', get_lang('CourseName'), array('size' => '60', 'id' => 'title'));
  34. $form->applyFilter('title', 'html_filter');
  35. $form->addRule('title', get_lang('ThisFieldIsRequired'), 'required');
  36. // Course category.
  37. $url = api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=search_category';
  38. $courseSelect = $form->addElement(
  39. 'select_ajax',
  40. 'category_code',
  41. get_lang('CourseFaculty'),
  42. null,
  43. array('url' => $url)
  44. );
  45. if (!empty($course_request_info['category_code'])) {
  46. $data = getCategory($course_request_info['category_code']);
  47. $courseSelect->addOption($data['name'], $data['code'], ['selected' => 'selected']);
  48. }
  49. // Course code.
  50. $form->addText('wanted_code', get_lang('Code'), false, array('size' => '$maxlength', 'maxlength' => $maxlength));
  51. $form->applyFilter('wanted_code', 'html_filter');
  52. $form->addRule('wanted_code', get_lang('Max'), 'maxlength', $maxlength);
  53. $form->addRule('wanted_code', get_lang('ThisFieldIsRequired'), 'required');
  54. // The teacher.
  55. $titular = $form->addText('tutor_name', get_lang('Professor'), null, array('size' => '60', 'disabled' => 'disabled'));
  56. // Description of the requested course.
  57. $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'));
  58. $form->addRule('description', get_lang('ThisFieldIsRequired'), 'required');
  59. // Objectives of the requested course.
  60. $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'));
  61. $form->addRule('objetives', get_lang('ThisFieldIsRequired'), 'required');
  62. // Target audience of the requested course.
  63. $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'));
  64. $form->addRule('target_audience', get_lang('ThisFieldIsRequired'), 'required');
  65. // Course language.
  66. $form->addElement('select_language', 'course_language', get_lang('Ln'));
  67. $form->applyFilter('select_language', 'html_filter');
  68. // Exemplary content checkbox.
  69. $form->addElement('checkbox', 'exemplary_content', get_lang('FillWithExemplaryContent'));
  70. // Submit buttons.
  71. $submit_buttons[] = $form->addButtonSave(get_lang('Save'), 'save_button', true);
  72. if ($course_request_info['status'] != COURSE_REQUEST_ACCEPTED) {
  73. $submit_buttons[] = $form->addButtonSave(get_lang('Accept'), 'accept_button', true);
  74. }
  75. if ($course_request_info['status'] != COURSE_REQUEST_ACCEPTED && $course_request_info['status'] != COURSE_REQUEST_REJECTED) {
  76. $submit_buttons[] = $form->addButtonCancel(get_lang('Reject'), 'reject_button', true);
  77. }
  78. if ($course_request_info['status'] != COURSE_REQUEST_ACCEPTED && intval($course_request_info['info']) <= 0) {
  79. $submit_buttons[] = $form->addButtonPreview(get_lang('AskAdditionalInfo'), 'ask_info_button', true);
  80. }
  81. $form->addGroup($submit_buttons);
  82. // Hidden form fields.
  83. $form->addElement('hidden', 'user_id');
  84. $form->addElement('hidden', 'directory');
  85. $form->addElement('hidden', 'visual_code');
  86. $form->addElement('hidden', 'request_date');
  87. $form->addElement('hidden', 'status');
  88. $form->addElement('hidden', 'info');
  89. // Set the default values based on the corresponding database record.
  90. $values['wanted_code'] = $course_request_info['code'];
  91. $values['user_id'] = $course_request_info['user_id'];
  92. $values['directory'] = $course_request_info['directory'];
  93. $values['course_language'] = $course_request_info['course_language'];
  94. $values['title'] = $course_request_info['title'];
  95. $values['description'] = $course_request_info['description'];
  96. //$values['category_code'] = $course_request_info['category_code'];
  97. $values['tutor_name'] = $course_request_info['tutor_name'];
  98. $values['visual_code'] = $course_request_info['visual_code'];
  99. $values['request_date'] = $course_request_info['request_date'];
  100. $values['objetives'] = $course_request_info['objetives'];
  101. $values['target_audience'] = $course_request_info['target_audience'];
  102. $values['status'] = $course_request_info['status'];
  103. $values['info'] = $course_request_info['info'];
  104. $values['exemplary_content'] = $course_request_info['exemplary_content'];
  105. $form->setDefaults($values);
  106. // Validate the form and perform the ordered actions.
  107. if ($form->validate()) {
  108. $course_request_values = $form->getSubmitValues();
  109. // Detection which submit button has been pressed.
  110. $submit_button = isset($_POST['save_button']) ? 'save_button'
  111. : (isset($_POST['accept_button']) ? 'accept_button'
  112. : (isset($_POST['reject_button']) ? 'reject_button'
  113. : (isset($_POST['ask_info_button']) ? 'ask_info_button'
  114. : 'submit_button')));
  115. // Check the course code for avoiding duplication.
  116. $course_code_ok = $course_request_values['wanted_code'] == $course_request_info['code']
  117. ? true
  118. : !CourseRequestManager::course_code_exists($course_request_values['wanted_code']);
  119. if ($course_code_ok) {
  120. $message = array();
  121. $is_error_message = false;
  122. // Update the course request.
  123. $update_ok = CourseRequestManager::update_course_request(
  124. $id,
  125. $course_request_values['wanted_code'],
  126. $course_request_values['title'],
  127. $course_request_values['description'],
  128. $course_request_values['category_code'],
  129. $course_request_values['course_language'],
  130. $course_request_values['objetives'],
  131. $course_request_values['target_audience'],
  132. $course_request_values['user_id'],
  133. $course_request_values['exemplary_content']
  134. );
  135. if ($update_ok) {
  136. $message[] = sprintf(get_lang('CourseRequestUpdated'), $course_request_values['wanted_code']);
  137. switch ($submit_button) {
  138. case 'accept_button':
  139. if (CourseRequestManager::accept_course_request($id)) {
  140. $message[] = sprintf(get_lang('CourseRequestAccepted'), $course_request_values['wanted_code'], $course_request_values['wanted_code']);
  141. } else {
  142. $message[] = sprintf(get_lang('CourseRequestAcceptanceFailed'), $course_request_values['wanted_code']);
  143. $is_error_message = true;
  144. }
  145. break;
  146. case 'reject_button':
  147. if (CourseRequestManager::reject_course_request($id)) {
  148. $message[] = sprintf(get_lang('CourseRequestRejected'), $course_request_values['wanted_code']);
  149. } else {
  150. $message[] = sprintf(get_lang('CourseRequestRejectionFailed'), $course_request_values['wanted_code']);
  151. $is_error_message = true;
  152. }
  153. break;
  154. case 'ask_info_button':
  155. if (CourseRequestManager::ask_for_additional_info($id)) {
  156. $message[] = sprintf(get_lang('CourseRequestInfoAsked'), $course_request_values['wanted_code']);
  157. } else {
  158. $message[] = sprintf(get_lang('CourseRequestInfoFailed'), $course_request_values['wanted_code']);
  159. $is_error_message = true;
  160. }
  161. break;
  162. }
  163. // Line of code for testing purposes, to be removed
  164. //$message = 'The button "'.$submit_button.'" has been pressed.';
  165. } else {
  166. $message[] = sprintf(get_lang('CourseRequestUpdateFailed'), $course_request_values['wanted_code']);
  167. $is_error_message = true;
  168. }
  169. $message = implode(' ', $message);
  170. $back_url = get_caller_name($caller);
  171. if ($message != '') {
  172. $back_url = api_add_url_param($back_url, 'message='.urlencode(Security::remove_XSS($message)), false);
  173. }
  174. if ($is_error_message) {
  175. $back_url = api_add_url_param($back_url, 'is_error_message=1', false);
  176. }
  177. header('location:'.$back_url);
  178. exit;
  179. } else {
  180. $message = $course_request_values['wanted_code'].' - '.get_lang('CourseCodeAlreadyExists');
  181. $is_error_message = true;
  182. }
  183. }
  184. }
  185. } else {
  186. // Prepare an error message notifying that the course validation feature has not been enabled.
  187. $link_to_setting = api_get_path(WEB_CODE_PATH).'admin/settings.php?search_field=course_validation&submit_button=&category=search_setting';
  188. $message = sprintf(get_lang('PleaseActivateCourseValidationFeature'), sprintf('<strong><a href="%s">%s</a></strong>', $link_to_setting, get_lang('EnableCourseValidation')));
  189. $is_error_message = true;
  190. }
  191. // Functions.
  192. // Converts the given numerical id to the name of the page that opened this editor.
  193. function get_caller_name($caller_id) {
  194. switch ($caller_id) {
  195. case 1:
  196. return 'course_request_accepted.php';
  197. case 2:
  198. return 'course_request_rejected.php';
  199. }
  200. return 'course_request_review.php';
  201. }
  202. // The header.
  203. $interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
  204. $interbreadcrumb[] = array('url' => 'course_list.php', 'name' => get_lang('CourseList'));
  205. Display :: display_header($tool_name);
  206. // Display confirmation or error message.
  207. if (!empty($message)) {
  208. if ($is_error_message) {
  209. Display::display_error_message($message, false);
  210. } else {
  211. Display::display_normal_message($message, false);
  212. }
  213. }
  214. if (!$course_validation_feature) {
  215. // Disabled course validation feature - show nothing after the error message.
  216. Display :: display_footer();
  217. exit;
  218. }
  219. // The action bar.
  220. echo '<div class="actions">';
  221. echo '<a href="course_list.php">'.Display::return_icon('courses.gif', get_lang('CourseList')).get_lang('CourseList').'</a>';
  222. echo '<a href="course_request_review.php">'.Display::return_icon('course_request_pending.png', get_lang('ReviewCourseRequests')).get_lang('ReviewCourseRequests').'</a>';
  223. echo '<a href="course_request_accepted.php">'.Display::return_icon('course_request_accepted.gif', get_lang('AcceptedCourseRequests')).get_lang('AcceptedCourseRequests').'</a>';
  224. echo '<a href="course_request_rejected.php">'.Display::return_icon('course_request_rejected.gif', get_lang('RejectedCourseRequests')).get_lang('RejectedCourseRequests').'</a>';
  225. echo '</div>';
  226. if (!is_array($course_request_info)) {
  227. // Not accessible database record - show the error message and the action bar.
  228. Display :: display_footer();
  229. exit;
  230. }
  231. // Display the form.
  232. $form->display();
  233. // The footer.
  234. Display :: display_footer();