specialty-action-edit.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This script displays a specialty action edit form.
  5. */
  6. require_once '../config.php';
  7. $course_plugin = 'sepe';
  8. $plugin = SepePlugin::create();
  9. $_cid = 0;
  10. if (!empty($_POST)) {
  11. $check = Security::check_token('post');
  12. if ($check) {
  13. $specialtyOrigin = Database::escape_string(trim($_POST['specialty_origin']));
  14. $professionalArea = Database::escape_string(trim($_POST['professional_area']));
  15. $specialtyCode = Database::escape_string(trim($_POST['specialty_code']));
  16. $centerOrigin = Database::escape_string(trim($_POST['center_origin']));
  17. $centerCode = Database::escape_string(trim($_POST['center_code']));
  18. $dayStart = Database::escape_string(trim($_POST['day_start']));
  19. $monthStart = Database::escape_string(trim($_POST['month_start']));
  20. $yearStart = Database::escape_string(trim($_POST['year_start']));
  21. $dayEnd = Database::escape_string(trim($_POST['day_end']));
  22. $monthEnd = Database::escape_string(trim($_POST['month_end']));
  23. $yearEnd = Database::escape_string(trim($_POST['year_end']));
  24. $modality_impartition = Database::escape_string(trim($_POST['modality_impartition']));
  25. $classroomHours = Database::escape_string(trim($_POST['classroom_hours']));
  26. $distanceHours = intval($_POST['distance_hours']);
  27. $morningsParticipantsNumber = intval($_POST['mornings_participants_number']);
  28. $morningsAccessNumber = intval($_POST['mornings_access_number']);
  29. $morningTotalDuration = intval($_POST['morning_total_duration']);
  30. $afternoonParticipantsNumber = intval($_POST['afternoon_participants_number']);
  31. $afternoonAccessNumber = intval($_POST['afternoon_access_number']);
  32. $afternoonTotalDuration = intval($_POST['afternoon_total_duration']);
  33. $nightParticipantsNumber = intval($_POST['night_participants_number']);
  34. $nightAccessNumber = intval($_POST['night_access_number']);
  35. $nightTotalDuration = intval($_POST['night_total_duration']);
  36. $attendeesCount = intval($_POST['attendees_count']);
  37. $learningActivityCount = intval($_POST['learning_activity_count']);
  38. $attemptCount = intval($_POST['attempt_count']);
  39. $evaluationActivityCount = intval($_POST['evaluation_activity_count']);
  40. $actionId = intval($_POST['action_id']);
  41. $specialtyId = intval($_POST['specialty_id']);
  42. $newSpecialty = intval($_POST['new_specialty']);
  43. $startDate = $yearStart."-".$monthStart."-".$dayStart;
  44. $endDate = $yearEnd."-".$monthEnd."-".$dayEnd;
  45. if (isset($newSpecialty) && $newSpecialty != 1) {
  46. $sql = "UPDATE plugin_sepe_specialty SET
  47. specialty_origin='".$specialtyOrigin."',
  48. professional_area='".$professionalArea."',
  49. specialty_code='".$specialtyCode."',
  50. center_origin='".$centerOrigin."',
  51. center_code='".$centerCode."',
  52. start_date='".$startDate."',
  53. end_date='".$endDate."',
  54. modality_impartition='".$modalityImpartition."',
  55. classroom_hours = $classroomHours,
  56. distance_hours = $distanceHours,
  57. mornings_participants_number = $morningsParticipantsNumber,
  58. mornings_access_number = $morningsAccessNumber,
  59. morning_total_duration = $morningTotalDuration,
  60. afternoon_participants_number = $afternoonParticipantsNumber,
  61. afternoon_access_number = $afternoonAccessNumber,
  62. afternoon_total_duration = $afternoonTotalDuration,
  63. night_participants_number = $nightParticipantsNumber,
  64. night_access_number = $nightAccessNumber,
  65. night_total_duration = $nightTotalDuration,
  66. attendees_count = $attendeesCount,
  67. learning_activity_count = $learningActivityCount,
  68. attempt_count = $attemptCount,
  69. evaluation_activity_count = $evaluationActivityCount
  70. WHERE id = $specialtyId;";
  71. } else {
  72. $sql = "INSERT INTO plugin_sepe_specialty (
  73. action_id,
  74. specialty_origin,
  75. professional_area,
  76. specialty_code,
  77. center_origin,
  78. center_code,
  79. start_date,
  80. end_date,
  81. modality_impartition,
  82. classroom_hours,
  83. distance_hours,
  84. mornings_participants_number,
  85. mornings_access_number,
  86. morning_total_duration,
  87. afternoon_participants_number,
  88. afternoon_access_number,
  89. afternoon_total_duration,
  90. night_participants_number,
  91. night_access_number,
  92. night_total_duration,
  93. attendees_count,
  94. learning_activity_count,
  95. attempt_count,
  96. evaluation_activity_count
  97. ) VALUES (
  98. $actionId,
  99. '".$specialtyOrigin."',
  100. '".$professionalArea."',
  101. '".$specialtyCode."',
  102. '".$centerOrigin."',
  103. '".$centerCode."',
  104. '".$startDate."',
  105. '".$endDate."',
  106. '".$modalityImpartition."',
  107. $classroomHours,
  108. $distanceHours,
  109. $morningsParticipantsNumber,
  110. $morningsAccessNumber,
  111. $morningTotalDuration,
  112. $afternoonParticipantsNumber,
  113. $afternoonAccessNumber,
  114. $afternoonTotalDuration,
  115. $nightParticipantsNumber,
  116. $nightAccessNumber,
  117. $nightTotalDuration,
  118. $attendeesCount,
  119. $learningActivityCount,
  120. $attemptCount,
  121. $evaluationActivityCount
  122. );";
  123. }
  124. $res = Database::query($sql);
  125. if (!$res) {
  126. $_SESSION['sepe_message_error'] = $plugin->get_lang('NoSaveChange');
  127. } else {
  128. if ($newSpecialty == 1) {
  129. $specialtyId = Database::insert_id();
  130. $_SESSION['sepe_message_info'] = $plugin->get_lang('SaveChange');
  131. }
  132. }
  133. session_write_close();
  134. header("Location: specialty-action-edit.php?new_specialty=0&specialty_id=".$specialtyId."&action_id=".$actionId);
  135. } else {
  136. $actionId = intval($_POST['action_id']);
  137. $specialtyId = intval($_POST['specialty_id']);
  138. $newSpecialty = intval($_POST['new_specialty']);
  139. Security::clear_token();
  140. $token = Security::get_token();
  141. $_SESSION['sepe_message_error'] = $plugin->get_lang('ProblemToken');
  142. session_write_close();
  143. header("Location: specialty-action-edit.php?new_specialty=".$newSpecialty."&specialty_id=".$specialtyId."&action_id=".$actionId);
  144. }
  145. } else {
  146. $token = Security::get_token();
  147. }
  148. if (api_is_platform_admin()) {
  149. $id_course = getCourse(intval($_GET['action_id']));
  150. $interbreadcrumb[] = [
  151. "url" => "/plugin/sepe/src/sepe-administration-menu.php",
  152. "name" => $plugin->get_lang('MenuSepe'),
  153. ];
  154. $interbreadcrumb[] = [
  155. "url" => "formative-actions-list.php",
  156. "name" => $plugin->get_lang('FormativesActionsList'),
  157. ];
  158. $interbreadcrumb[] = [
  159. "url" => "formative-action.php?cid=".$id_course,
  160. "name" => $plugin->get_lang('FormativeAction'),
  161. ];
  162. if (isset($_GET['new_specialty']) && intval($_GET['new_specialty']) == 1) {
  163. $templateName = $plugin->get_lang('NewSpecialtyAccion');
  164. $tpl = new Template($templateName);
  165. $tpl->assign('action_id', intval($_GET['action_id']));
  166. $info = [];
  167. $tpl->assign('info', $info);
  168. $tpl->assign('new_action', '1');
  169. $yearStart = $yearEnd = date("Y");
  170. } else {
  171. $templateName = $plugin->get_lang('EditSpecialtyAccion');
  172. $tpl = new Template($templateName);
  173. $tpl->assign('action_id', intval($_GET['action_id']));
  174. $info = getSpecialtActionInfo(intval($_GET['specialty_id']));
  175. $tpl->assign('info', $info);
  176. if ($info['start_date'] != '0000-00-00' && $info['start_date'] != null) {
  177. $tpl->assign('day_start', date("j", strtotime($info['start_date'])));
  178. $tpl->assign('month_start', date("n", strtotime($info['start_date'])));
  179. $tpl->assign('year_start', date("Y", strtotime($info['start_date'])));
  180. $yearStart = date("Y", strtotime($info['start_date']));
  181. } elseif (strpos($info['start_date'], '0000') === false) {
  182. $yearStart = date("Y", strtotime($info['start_date']));
  183. } else {
  184. $yearStart = date("Y");
  185. }
  186. if ($info['end_date'] != '0000-00-00' && $info['end_date'] != null) {
  187. $tpl->assign('day_end', date("j", strtotime($info['end_date'])));
  188. $tpl->assign('month_end', date("n", strtotime($info['end_date'])));
  189. $tpl->assign('year_end', date("Y", strtotime($info['end_date'])));
  190. $yearEnd = date("Y", strtotime($info['end_date']));
  191. } elseif (strpos($info['end_date'], '0000') === false) {
  192. $yearEnd = date("Y", strtotime($info['end_date']));
  193. } else {
  194. $yearEnd = date("Y");
  195. }
  196. $tpl->assign('new_action', '0');
  197. $tpl->assign('specialty_id', intval($_GET['specialty_id']));
  198. $listClassroom = classroomList(intval($_GET['specialty_id']));
  199. $tpl->assign('listClassroom', $listClassroom);
  200. $listTutors = tutorsList(intval($_GET['specialty_id']));
  201. $tpl->assign('listTutors', $listTutors);
  202. }
  203. $yearList = [];
  204. if ($yearStart > $yearEnd) {
  205. $tmp = $yearStart;
  206. $yearStart = $yearEnd;
  207. $yearEnd = $tmp;
  208. }
  209. $yearStart -= 5;
  210. $yearEnd += 5;
  211. $fin_rango_anio = (($yearStart + 15) < $yearEnd) ? ($yearEnd + 1) : ($yearStart + 15);
  212. while ($yearStart <= $fin_rango_anio) {
  213. $yearList[] = $yearStart;
  214. $yearStart++;
  215. }
  216. $tpl->assign('list_year', $yearList);
  217. if (isset($_SESSION['sepe_message_info'])) {
  218. $tpl->assign('message_info', $_SESSION['sepe_message_info']);
  219. unset($_SESSION['sepe_message_info']);
  220. }
  221. if (isset($_SESSION['sepe_message_error'])) {
  222. $tpl->assign('message_error', $_SESSION['sepe_message_error']);
  223. unset($_SESSION['sepe_message_error']);
  224. }
  225. $tpl->assign('sec_token', $token);
  226. $listing_tpl = 'sepe/view/specialty-action-edit.tpl';
  227. $content = $tpl->fetch($listing_tpl);
  228. $tpl->assign('content', $content);
  229. $tpl->display_one_col_template();
  230. } else {
  231. header('Location:'.api_get_path(WEB_PATH));
  232. exit;
  233. }