specialty-classroom-edit.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This script displays a specialty classroom 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. $sltCentersExists = intval($_POST['slt_centers_exists']);
  14. $specialtyId = intval($_POST['specialty_id']);
  15. $existsCenterId = intval($_POST['exists_center_id']);
  16. $centerOrigin = Database::escape_string(trim($_POST['center_origin']));
  17. $centerCode = Database::escape_string(trim($_POST['center_code']));
  18. $newClassroom = intval($_POST['new_classroom']);
  19. $actionId = intval($_POST['action_id']);
  20. $classroomId = intval($_POST['classroom_id']);
  21. if ($sltCentersExists == 1) {
  22. $sql = "INSERT INTO $tableSepeSpecialtyClassroom (specialty_id, center_id)
  23. VALUES ($specialtyId, $existsCenterId);";
  24. $res = Database::query($sql);
  25. if (!$res) {
  26. $_SESSION['sepe_message_error'] = $plugin->get_lang('NoSaveChange');
  27. } else {
  28. if ($newClassroom == 1) {
  29. $classroomId = Database::insert_id();
  30. }
  31. $_SESSION['sepe_message_info'] = $plugin->get_lang('SaveChange');
  32. }
  33. } else {
  34. //Checker exists centers
  35. $sql = "SELECT * FROM $tableCenters
  36. WHERE center_origin='".$centerOrigin."' AND center_code='".$centerCode."'";
  37. $rs_tmp = Database::query($sql);
  38. if (Database::num_rows($rs_tmp) > 0) {
  39. $aux = Database::fetch_assoc($rs_tmp);
  40. $centerId = $aux['id'];
  41. } else {
  42. $params = [
  43. 'center_origin' => $centerOrigin,
  44. 'center_code' => $centerCode,
  45. ];
  46. $centerId = Database::insert($tableCenters, $params);
  47. }
  48. if (isset($newClassroom) && $newClassroom != 1) {
  49. $sql = "UPDATE $tableSepeSpecialtyClassroom SET center_id = $centerId WHERE id = $classroomId;";
  50. } else {
  51. $sql = "INSERT INTO $tableSepeSpecialtyClassroom (specialty_id, center_id) VALUES ($specialtyId, $centerId);";
  52. }
  53. $res = Database::query($sql);
  54. if (!$res) {
  55. $_SESSION['sepe_message_error'] = $plugin->get_lang('NoSaveChange');
  56. } else {
  57. if ($newClassroom == 1) {
  58. $classroomId = Database::insert_id();
  59. }
  60. $_SESSION['sepe_message_info'] = $plugin->get_lang('SaveChange');
  61. }
  62. }
  63. session_write_close();
  64. header("Location: specialty-action-edit.php?new_specialty=0&specialty_id=".$specialtyId."&action_id=".$actionId);
  65. exit;
  66. } else {
  67. $newClassroom = intval($_POST['new_classroom']);
  68. $actionId = intval($_POST['action_id']);
  69. $classroomId = intval($_POST['classroom_id']);
  70. $specialtyId = intval($_POST['specialty_id']);
  71. Security::clear_token();
  72. $_SESSION['sepe_message_error'] = $plugin->get_lang('ProblemToken');
  73. $token = Security::get_token();
  74. session_write_close();
  75. header("Location:specialty-classroom-edit.php?new_classroom=".$newClassroom."&specialty_id=".$specialtyId."&classroom_id=".$classroomId."&action_id=".$actionId);
  76. exit;
  77. }
  78. } else {
  79. $token = Security::get_token();
  80. }
  81. if (api_is_platform_admin()) {
  82. $courseId = getCourse($_GET['action_id']);
  83. $interbreadcrumb[] = ["url" => "/plugin/sepe/src/sepe-administration-menu.php", "name" => $plugin->get_lang('MenuSepe')];
  84. $interbreadcrumb[] = ["url" => "formative-actions-list.php", "name" => $plugin->get_lang('FormativesActionsList')];
  85. $interbreadcrumb[] = ["url" => "formative-action.php?cid=".$courseId, "name" => $plugin->get_lang('FormativeAction')];
  86. $interbreadcrumb[] = ["url" => "specialty-action-edit.php?new_specialty=0&specialty_id=".intval($_GET['specialty_id'])."&action_id=".intval($_GET['action_id']), "name" => $plugin->get_lang('SpecialtyFormativeAction')];
  87. if (isset($_GET['new_classroom']) && intval($_GET['new_classroom']) == 1) {
  88. $templateName = $plugin->get_lang('NewSpecialtyClassroom');
  89. $tpl = new Template($templateName);
  90. $tpl->assign('action_id', intval($_GET['action_id']));
  91. $tpl->assign('specialty_id', intval($_GET['specialty_id']));
  92. $info = [];
  93. $tpl->assign('info', $info);
  94. $tpl->assign('new_classroom', '1');
  95. } else {
  96. $templateName = $plugin->get_lang('EditSpecialtyClassroom');
  97. $tpl = new Template($templateName);
  98. $tpl->assign('action_id', intval($_GET['action_id']));
  99. $tpl->assign('specialty_id', intval($_GET['specialty_id']));
  100. $tpl->assign('classroom_id', intval($_GET['classroom_id']));
  101. $info = getInfoSpecialtyClassroom($_GET['classroom_id']);
  102. $tpl->assign('info', $info);
  103. $tpl->assign('new_classroom', '0');
  104. }
  105. $centerList = getCentersList();
  106. $tpl->assign('listExistsCenters', $centerList);
  107. if (isset($_SESSION['sepe_message_info'])) {
  108. $tpl->assign('message_info', $_SESSION['sepe_message_info']);
  109. unset($_SESSION['sepe_message_info']);
  110. }
  111. if (isset($_SESSION['sepe_message_error'])) {
  112. $tpl->assign('message_error', $_SESSION['sepe_message_error']);
  113. unset($_SESSION['sepe_message_error']);
  114. }
  115. $tpl->assign('sec_token', $token);
  116. $listing_tpl = 'sepe/view/specialty-classroom-edit.tpl';
  117. $content = $tpl->fetch($listing_tpl);
  118. $tpl->assign('content', $content);
  119. $tpl->display_one_col_template();
  120. } else {
  121. header('Location:'.api_get_path(WEB_PATH));
  122. exit;
  123. }