Issues (2128)

plugin/sepe/src/specialty-action-edit.php (1 issue)

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