specialty-tutorial-edit.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This script displays a specialty tutorial 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. $centerOrigin = Database::escape_string(trim($_POST['center_origin']));
  14. $centerCode = Database::escape_string(trim($_POST['center_code']));
  15. $dayStart = Database::escape_string(trim($_POST['day_start']));
  16. $monthStart = Database::escape_string(trim($_POST['month_start']));
  17. $yearStart = Database::escape_string(trim($_POST['year_start']));
  18. $dayEnd = Database::escape_string(trim($_POST['day_end']));
  19. $monthEnd = Database::escape_string(trim($_POST['month_end']));
  20. $yearEnd = Database::escape_string(trim($_POST['year_end']));
  21. $tutorialId = intval($_POST['tutorial_id']);
  22. $actionId = intval($_POST['action_id']);
  23. $specialtyId = intval($_POST['specialty_id']);
  24. $newTutorial = intval($_POST['new_tutorial']);
  25. $starDate = $yearStart."-".$monthStart."-".$dayStart;
  26. $endDate = $yearEnd."-".$monthEnd."-".$dayEnd;
  27. if (isset($newTutorial) && $newTutorial != 1) {
  28. $sql = "UPDATE $tableSepeParticipantsSpecialtyTutorials SET
  29. center_origin='".$centerOrigin."',
  30. center_code='".$centerCode."',
  31. start_date='".$starDate."',
  32. end_date='".$endDate."'
  33. WHERE id = $tutorialId;";
  34. } else {
  35. $sql = "INSERT INTO $tableSepeParticipantsSpecialtyTutorials (
  36. participant_specialty_id,
  37. center_origin,
  38. center_code,
  39. start_date,
  40. end_date
  41. ) VALUES (
  42. $specialtyId,
  43. '".$centerOrigin."',
  44. '".$centerCode."',
  45. '".$starDate."',
  46. '".$endDate."'
  47. );";
  48. }
  49. $res = Database::query($sql);
  50. if (!$res) {
  51. $_SESSION['sepe_message_error'] = $plugin->get_lang('NoSaveChange');
  52. } else {
  53. $_SESSION['sepe_message_info'] = $plugin->get_lang('SaveChange');
  54. }
  55. session_write_close();
  56. $participantId = getParticipantId($specialtyId);
  57. header("Location: participant-specialty-edit.php?new_specialty=0&participant_id=".$participantId."&specialty_id=".$specialtyId."&action_id=".$actionId);
  58. exit;
  59. } else {
  60. $tutorialId = intval($_POST['tutorial_id']);
  61. $actionId = intval($_POST['action_id']);
  62. $specialtyId = intval($_POST['specialty_id']);
  63. $newTutorial = intval($_POST['new_tutorial']);
  64. Security::clear_token();
  65. $token = Security::get_token();
  66. $_SESSION['sepe_message_error'] = $plugin->get_lang('ProblemToken');
  67. session_write_close();
  68. header("Location: specialty-tutorial-edit.php?new_tutorial=".$newTutorial."&specialty_id=".$specialtyId."&tutorial_id=".$tutorialId."&action_id=".$actionId);
  69. exit;
  70. }
  71. } else {
  72. $token = Security::get_token();
  73. }
  74. if (api_is_platform_admin()) {
  75. $courseId = getCourse(intval($_GET['action_id']));
  76. $participantId = getParticipantId(intval($_GET['specialty_id']));
  77. $interbreadcrumb[] = ["url" => "/plugin/sepe/src/sepe-administration-menu.php", "name" => $plugin->get_lang('MenuSepe')];
  78. $interbreadcrumb[] = ["url" => "formative-actions-list.php", "name" => $plugin->get_lang('FormativesActionsList')];
  79. $interbreadcrumb[] = ["url" => "formative-action.php?cid=".$courseId, "name" => $plugin->get_lang('FormativeAction')];
  80. $interbreadcrumb[] = ["url" => "participant-specialty-edit.php?new_specialty=0&participant_id=".$participantId."&specialty_id=".intval($_GET['specialty_id'])."&action_id=".intval($_GET['action_id']), "name" => $plugin->get_lang('SpecialtyFormativeParcipant')];
  81. if (isset($_GET['new_tutorial']) && intval($_GET['new_tutorial']) == 1) {
  82. $templateName = $plugin->get_lang('new_tutorial');
  83. $tpl = new Template($templateName);
  84. $tpl->assign('action_id', intval($_GET['action_id']));
  85. $tpl->assign('specialty_id', intval($_GET['specialty_id']));
  86. $info = [];
  87. $tpl->assign('info', $info);
  88. $tpl->assign('new_tutorial', '1');
  89. $startYear = $endYear = date("Y");
  90. } else {
  91. $templateName = $plugin->get_lang('edit_tutorial');
  92. $tpl = new Template($templateName);
  93. $tpl->assign('action_id', intval($_GET['action_id']));
  94. $tpl->assign('specialty_id', intval($_GET['specialty_id']));
  95. $tpl->assign('tutorial_id', intval($_GET['tutorial_id']));
  96. $info = getInfoSpecialtyTutorial(intval($_GET['tutorial_id']));
  97. $tpl->assign('info', $info);
  98. $tpl->assign('new_tutorial', '0');
  99. if ($info['start_date'] != '0000-00-00' && $info['start_date'] != null) {
  100. $tpl->assign('day_start', date("j", strtotime($info['start_date'])));
  101. $tpl->assign('month_start', date("n", strtotime($info['start_date'])));
  102. $tpl->assign('year_start', date("Y", strtotime($info['start_date'])));
  103. $startYear = date("Y", strtotime($info['start_date']));
  104. } elseif (strpos($info['end_date'], '0000') === false) {
  105. $startYear = date("Y", strtotime($info['start_date']));
  106. } else {
  107. $startYear = date("Y");
  108. }
  109. if ($info['end_date'] != '0000-00-00' && $info['end_date'] != null) {
  110. $tpl->assign('day_end', date("j", strtotime($info['end_date'])));
  111. $tpl->assign('month_end', date("n", strtotime($info['end_date'])));
  112. $tpl->assign('year_end', date("Y", strtotime($info['end_date'])));
  113. $endYear = date("Y", strtotime($info['end_date']));
  114. } elseif (strpos($info['end_date'], '0000') === false) {
  115. $endYear = date("Y", strtotime($info['end_date']));
  116. } else {
  117. $endYear = date("Y");
  118. }
  119. }
  120. $listYears = [];
  121. if ($startYear > $endYear) {
  122. $tmp = $startYear;
  123. $startYear = $endYear;
  124. $endYear = $tmp;
  125. }
  126. $startYear -= 5;
  127. $endYear += 5;
  128. $endRangeYear = (($startYear + 15) < $endYear) ? ($endYear + 1) : ($startYear + 15);
  129. while ($startYear <= $endRangeYear) {
  130. $listYears[] = $startYear;
  131. $startYear++;
  132. }
  133. $tpl->assign('list_year', $listYears);
  134. if (isset($_SESSION['sepe_message_info'])) {
  135. $tpl->assign('message_info', $_SESSION['sepe_message_info']);
  136. unset($_SESSION['sepe_message_info']);
  137. }
  138. if (isset($_SESSION['sepe_message_error'])) {
  139. $tpl->assign('message_error', $_SESSION['sepe_message_error']);
  140. unset($_SESSION['sepe_message_error']);
  141. }
  142. $tpl->assign('sec_token', $token);
  143. $listing_tpl = 'sepe/view/specialty-tutorial-edit.tpl';
  144. $content = $tpl->fetch($listing_tpl);
  145. $tpl->assign('content', $content);
  146. $tpl->display_one_col_template();
  147. } else {
  148. header('Location:'.api_get_path(WEB_PATH));
  149. exit;
  150. }