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