course_request_edit.php 14 KB

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