function.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <?php
  2. /* For license terms, see /license.txt */
  3. /**
  4. * Functions for the Sepe plugin.
  5. *
  6. * @package chamilo.plugin.sepe
  7. */
  8. require_once '../config.php';
  9. $plugin = SepePlugin::create();
  10. if ($_REQUEST['tab'] == 'delete_center_data') {
  11. $sql = "DELETE FROM $tableSepeCenter;";
  12. $res = Database::query($sql);
  13. if (!$res) {
  14. $sql = "DELETE FROM $tableSepeActions;";
  15. $res = Database::query($sql);
  16. $content = $plugin->get_lang('ProblemToDeleteInfoCenter');
  17. echo json_encode(["status" => "false", "content" => $content]);
  18. } else {
  19. $content = $plugin->get_lang('DeleteOk');
  20. echo json_encode(["status" => "true", "content" => $content]);
  21. }
  22. }
  23. if ($_REQUEST['tab'] == 'delete_action') {
  24. $id = intval($_REQUEST['id']);
  25. $sql = "DELETE FROM $tableSepeActions WHERE id = $id;";
  26. $res = Database::query($sql);
  27. if (!$res) {
  28. $content = $plugin->get_lang('ProblemToDeleteInfoAction');
  29. echo json_encode(["status" => "false", "content" => $content]);
  30. } else {
  31. $content = $plugin->get_lang('DeleteOk');
  32. $_SESSION['sepe_message_info'] = $content;
  33. echo json_encode(["status" => "true"]);
  34. }
  35. }
  36. if ($_REQUEST['tab'] == 'delete_specialty') {
  37. $id = intval(substr($_REQUEST['id'], 9));
  38. $sql = "DELETE FROM $tableSepeSpecialty WHERE id = $id;";
  39. $res = Database::query($sql);
  40. if (!$res) {
  41. $content = $plugin->get_lang('ProblemToDeleteInfoSpecialty');
  42. echo json_encode(["status" => "false", "content" => $content]);
  43. } else {
  44. $content = $plugin->get_lang('DeleteOk');
  45. echo json_encode(["status" => "true", "content" => $content]);
  46. }
  47. }
  48. if ($_REQUEST['tab'] == 'delete_specialty_participant') {
  49. $id = intval(substr($_REQUEST['id'], 9));
  50. $sql = "DELETE FROM $tableSepeParticipantsSpecialty WHERE id = $id;";
  51. $res = Database::query($sql);
  52. if (!$res) {
  53. $content = $plugin->get_lang('ProblemToDeleteInfoSpecialty');
  54. echo json_encode(["status" => "false", "content" => $content]);
  55. } else {
  56. $content = $plugin->get_lang('DeleteOk');
  57. echo json_encode(["status" => "true", "content" => $content]);
  58. }
  59. }
  60. if ($_REQUEST['tab'] == 'delete_classroom') {
  61. $id = intval(substr($_REQUEST['id'], 9));
  62. $sql = "DELETE FROM $tableSepeSpecialtyClassroom WHERE id = $id;";
  63. $res = Database::query($sql);
  64. if (!$res) {
  65. $content = $plugin->get_lang('ProblemToDeleteInfoSpecialtyClassroom');
  66. echo json_encode(["status" => "false", "content" => $content]);
  67. } else {
  68. $content = $plugin->get_lang('DeleteOk');
  69. echo json_encode(["status" => "true", "content" => $content]);
  70. }
  71. }
  72. if ($_REQUEST['tab'] == 'checkTutorEdit') {
  73. $type = Database::escape_string(trim($_REQUEST['type']));
  74. $number = Database::escape_string(trim($_REQUEST['number']));
  75. $letter = Database::escape_string(trim($_REQUEST['letter']));
  76. $platform_user_id = intval($_REQUEST['platform_user_id']);
  77. $sql = "SELECT platform_user_id
  78. FROM $tableSepeTutors
  79. WHERE document_type='".$type."' AND document_number='".$number."' AND document_letter='".$letter."';";
  80. $res = Database::query($sql);
  81. if (!$res) {
  82. $content = $plugin->get_lang('ProblemDataBase');
  83. error_log(print_r($content, 1));
  84. exit;
  85. } else {
  86. $aux = Database::fetch_assoc($res);
  87. if ($aux['platform_user_id'] == $platform_user_id || $aux['platform_user_id'] == 0) {
  88. echo json_encode(["status" => "true"]);
  89. } else {
  90. $content = $plugin->get_lang('ModDataTeacher');
  91. echo json_encode(["status" => "false", "content" => $content]);
  92. }
  93. }
  94. }
  95. if ($_REQUEST['tab'] == 'delete_tutor') {
  96. $id = intval(substr($_REQUEST['id'], 5));
  97. $sql = "DELETE FROM $tableSepeSpecialtyTutors WHERE id = $id;";
  98. $res = Database::query($sql);
  99. if (!$res) {
  100. $content = $plugin->get_lang('ProblemToDeleteInfoSpecialtyTutor');
  101. echo json_encode(["status" => "false", "content" => $content]);
  102. } else {
  103. $content = $plugin->get_lang('DeleteOk');
  104. echo json_encode(["status" => "true", "content" => $content]);
  105. }
  106. }
  107. if ($_REQUEST['tab'] == 'delete_participant') {
  108. $id = intval(substr($_REQUEST['id'], 11));
  109. $sql = "SELECT platform_user_id, action_id FROM $tableSepeParticipants WHERE id = $id;";
  110. $res = Database::query($sql);
  111. $row = Database::fetch_assoc($res);
  112. $sql = "UPDATE plugin_sepe_log_participant SET fecha_baja='".date("Y-m-d H:i:s")."' WHERE platform_user_id='".$row['platform_user_id']."' AND action_id='".$row['action_id']."';";
  113. $res = Database::query($sql);
  114. $sql = "DELETE FROM $tableSepeParticipants WHERE id = $id;";
  115. $res = Database::query($sql);
  116. if (!$res) {
  117. $content = $plugin->get_lang('ProblemToDeleteInfoParticipant');
  118. echo json_encode(["status" => "false", "content" => $content]);
  119. } else {
  120. $content = $plugin->get_lang('DeleteOk');
  121. echo json_encode(["status" => "true", "content" => $content]);
  122. }
  123. }
  124. if ($_REQUEST['tab'] == 'unlink_action') {
  125. $id = intval(substr($_REQUEST['id'], 16));
  126. $sql = "DELETE FROM $tableSepeCourseActions WHERE id = $id;";
  127. $res = Database::query($sql);
  128. if (!$res) {
  129. $content = $plugin->get_lang('ProblemToDesvincularInfoAction');
  130. echo json_encode(["status" => "false", "content" => $content]);
  131. } else {
  132. $content = $plugin->get_lang('DeleteOk');
  133. echo json_encode(["status" => "true", "content" => $content]);
  134. }
  135. }
  136. if ($_REQUEST['tab'] == 'assign_action') {
  137. $course_id = intval(substr($_REQUEST['course_id'], 9));
  138. $action_id = intval($_REQUEST['action_id']);
  139. if ($action_id != 0 && $course_id != 0) {
  140. $sql = "SELECT * FROM $tableSepeCourseActions WHERE action_id = $action_id;";
  141. $rs = Database::query($sql);
  142. if (Database::num_rows($rs) > 0) {
  143. $content = $plugin->get_lang('FormativeActionInUse');
  144. echo json_encode(["status" => "false", "content" => $content]);
  145. } else {
  146. $sql = "SELECT 1 FROM course WHERE id = $course_id;";
  147. $rs = Database::query($sql);
  148. if (Database::num_rows($rs) == 0) {
  149. $content = $plugin->get_lang('NoExistsCourse');
  150. echo json_encode(["status" => "false", "content" => $content]);
  151. } else {
  152. $sql = "INSERT INTO $tableSepeCourseActions (course_id, action_id) VALUES ($course_id, $action_id);";
  153. $rs = Database::query($sql);
  154. if (!$rs) {
  155. $content = $plugin->get_lang('NoSaveData');
  156. echo json_encode(["status" => "false", "content" => utf8_encode($content)]);
  157. } else {
  158. echo json_encode(["status" => "true"]);
  159. }
  160. }
  161. }
  162. } else {
  163. $content = $plugin->get_lang('ErrorDataIncorrect');
  164. echo json_encode(["status" => "false", "content" => $content]);
  165. }
  166. }
  167. if ($_REQUEST['tab'] == 'key_sepe_generator') {
  168. $tApi = Database::get_main_table(TABLE_MAIN_USER_API_KEY);
  169. $info_user = api_get_user_info_from_username('SEPE');
  170. $array_list_key = [];
  171. $user_id = $info_user['user_id'];
  172. $api_service = 'dokeos';
  173. $num = UserManager::update_api_key($user_id, $api_service);
  174. $array_list_key = UserManager::get_api_keys($user_id, $api_service);
  175. if (trim($array_list_key[$num]) != '') {
  176. $content = $array_list_key[$num];
  177. echo json_encode(["status" => "true", "content" => $content]);
  178. } else {
  179. $content = $plugin->get_lang('ProblemGenerateApiKey');
  180. echo json_encode(["status" => "false", "content" => $content]);
  181. }
  182. }