1 | <?php |
||
2 | /* vim: set expandtab sw=4 ts=4 sts=4: */ |
||
3 | /** |
||
4 | * Functions for event management. |
||
5 | * |
||
6 | * @package PhpMyAdmin |
||
7 | */ |
||
8 | declare(strict_types=1); |
||
9 | |||
10 | namespace PhpMyAdmin\Rte; |
||
11 | |||
12 | use PhpMyAdmin\DatabaseInterface; |
||
13 | use PhpMyAdmin\Message; |
||
14 | use PhpMyAdmin\Response; |
||
15 | use PhpMyAdmin\Url; |
||
16 | use PhpMyAdmin\Util; |
||
17 | |||
18 | /** |
||
19 | * PhpMyAdmin\Rte\Events class |
||
20 | * |
||
21 | * @package PhpMyAdmin |
||
22 | */ |
||
23 | class Events |
||
24 | { |
||
25 | /** |
||
26 | * @var Export |
||
27 | */ |
||
28 | private $export; |
||
29 | |||
30 | /** |
||
31 | * @var Footer |
||
32 | */ |
||
33 | private $footer; |
||
34 | |||
35 | /** |
||
36 | * @var General |
||
37 | */ |
||
38 | private $general; |
||
39 | |||
40 | /** |
||
41 | * @var RteList |
||
42 | */ |
||
43 | private $rteList; |
||
44 | |||
45 | /** |
||
46 | * @var Words |
||
47 | */ |
||
48 | private $words; |
||
49 | |||
50 | /** |
||
51 | * @var DatabaseInterface |
||
52 | */ |
||
53 | private $dbi; |
||
54 | |||
55 | /** |
||
56 | * Events constructor. |
||
57 | * |
||
58 | * @param DatabaseInterface $dbi DatabaseInterface object |
||
59 | */ |
||
60 | public function __construct(DatabaseInterface $dbi) |
||
61 | { |
||
62 | $this->dbi = $dbi; |
||
63 | $this->export = new Export($this->dbi); |
||
64 | $this->footer = new Footer($this->dbi); |
||
65 | $this->general = new General($this->dbi); |
||
66 | $this->rteList = new RteList($this->dbi); |
||
67 | $this->words = new Words(); |
||
68 | } |
||
69 | |||
70 | /** |
||
71 | * Sets required globals |
||
72 | * |
||
73 | * @return void |
||
74 | */ |
||
75 | public function setGlobals() |
||
76 | { |
||
77 | global $event_status, $event_type, $event_interval; |
||
78 | |||
79 | $event_status = [ |
||
80 | 'query' => [ |
||
81 | 'ENABLE', |
||
82 | 'DISABLE', |
||
83 | 'DISABLE ON SLAVE', |
||
84 | ], |
||
85 | 'display' => [ |
||
86 | 'ENABLED', |
||
87 | 'DISABLED', |
||
88 | 'SLAVESIDE_DISABLED', |
||
89 | ], |
||
90 | ]; |
||
91 | $event_type = [ |
||
92 | 'RECURRING', |
||
93 | 'ONE TIME', |
||
94 | ]; |
||
95 | $event_interval = [ |
||
96 | 'YEAR', |
||
97 | 'QUARTER', |
||
98 | 'MONTH', |
||
99 | 'DAY', |
||
100 | 'HOUR', |
||
101 | 'MINUTE', |
||
102 | 'WEEK', |
||
103 | 'SECOND', |
||
104 | 'YEAR_MONTH', |
||
105 | 'DAY_HOUR', |
||
106 | 'DAY_MINUTE', |
||
107 | 'DAY_SECOND', |
||
108 | 'HOUR_MINUTE', |
||
109 | 'HOUR_SECOND', |
||
110 | 'MINUTE_SECOND', |
||
111 | ]; |
||
112 | } |
||
113 | |||
114 | /** |
||
115 | * Main function for the events functionality |
||
116 | * |
||
117 | * @return void |
||
118 | */ |
||
119 | public function main() |
||
120 | { |
||
121 | global $db; |
||
122 | |||
123 | $this->setGlobals(); |
||
124 | /** |
||
125 | * Process all requests |
||
126 | */ |
||
127 | $this->handleEditor(); |
||
128 | $this->export->events(); |
||
129 | /** |
||
130 | * Display a list of available events |
||
131 | */ |
||
132 | $items = $this->dbi->getEvents($db); |
||
133 | echo $this->rteList->get('event', $items); |
||
134 | /** |
||
135 | * Display a link for adding a new event, if |
||
136 | * the user has the privileges and a link to |
||
137 | * toggle the state of the event scheduler. |
||
138 | */ |
||
139 | echo $this->footer->events(); |
||
140 | } |
||
141 | |||
142 | /** |
||
143 | * Handles editor requests for adding or editing an item |
||
144 | * |
||
145 | * @return void |
||
146 | */ |
||
147 | public function handleEditor() |
||
148 | { |
||
149 | global $db, $errors, $message; |
||
150 | |||
151 | if (! empty($_POST['editor_process_add']) |
||
152 | || ! empty($_POST['editor_process_edit']) |
||
153 | ) { |
||
154 | $sql_query = ''; |
||
155 | |||
156 | $item_query = $this->getQueryFromRequest(); |
||
157 | |||
158 | if (! count($errors)) { // set by PhpMyAdmin\Rte\Routines::getQueryFromRequest() |
||
159 | // Execute the created query |
||
160 | if (! empty($_POST['editor_process_edit'])) { |
||
161 | // Backup the old trigger, in case something goes wrong |
||
162 | $create_item = $this->dbi->getDefinition( |
||
163 | $db, |
||
164 | 'EVENT', |
||
165 | $_POST['item_original_name'] |
||
166 | ); |
||
167 | $drop_item = "DROP EVENT " |
||
168 | . Util::backquote($_POST['item_original_name']) |
||
169 | . ";\n"; |
||
170 | $result = $this->dbi->tryQuery($drop_item); |
||
171 | if (! $result) { |
||
172 | $errors[] = sprintf( |
||
173 | __('The following query has failed: "%s"'), |
||
174 | htmlspecialchars($drop_item) |
||
175 | ) |
||
176 | . '<br>' |
||
177 | . __('MySQL said: ') . $this->dbi->getError(); |
||
178 | } else { |
||
179 | $result = $this->dbi->tryQuery($item_query); |
||
180 | if (! $result) { |
||
181 | $errors[] = sprintf( |
||
182 | __('The following query has failed: "%s"'), |
||
183 | htmlspecialchars($item_query) |
||
184 | ) |
||
185 | . '<br>' |
||
186 | . __('MySQL said: ') . $this->dbi->getError(); |
||
187 | // We dropped the old item, but were unable to create |
||
188 | // the new one. Try to restore the backup query |
||
189 | $result = $this->dbi->tryQuery($create_item); |
||
190 | $errors = $this->general->checkResult( |
||
191 | $result, |
||
192 | __( |
||
193 | 'Sorry, we failed to restore the dropped event.' |
||
194 | ), |
||
195 | $create_item, |
||
196 | $errors |
||
197 | ); |
||
198 | } else { |
||
199 | $message = Message::success( |
||
200 | __('Event %1$s has been modified.') |
||
201 | ); |
||
202 | $message->addParam( |
||
203 | Util::backquote($_POST['item_name']) |
||
204 | ); |
||
205 | $sql_query = $drop_item . $item_query; |
||
206 | } |
||
207 | } |
||
208 | } else { |
||
209 | // 'Add a new item' mode |
||
210 | $result = $this->dbi->tryQuery($item_query); |
||
211 | if (! $result) { |
||
212 | $errors[] = sprintf( |
||
213 | __('The following query has failed: "%s"'), |
||
214 | htmlspecialchars($item_query) |
||
215 | ) |
||
216 | . '<br><br>' |
||
217 | . __('MySQL said: ') . $this->dbi->getError(); |
||
218 | } else { |
||
219 | $message = Message::success( |
||
220 | __('Event %1$s has been created.') |
||
221 | ); |
||
222 | $message->addParam( |
||
223 | Util::backquote($_POST['item_name']) |
||
224 | ); |
||
225 | $sql_query = $item_query; |
||
226 | } |
||
227 | } |
||
228 | } |
||
229 | |||
230 | if (count($errors)) { |
||
231 | $message = Message::error( |
||
232 | '<b>' |
||
233 | . __( |
||
234 | 'One or more errors have occurred while processing your request:' |
||
235 | ) |
||
236 | . '</b>' |
||
237 | ); |
||
238 | $message->addHtml('<ul>'); |
||
239 | foreach ($errors as $string) { |
||
240 | $message->addHtml('<li>' . $string . '</li>'); |
||
241 | } |
||
242 | $message->addHtml('</ul>'); |
||
243 | } |
||
244 | |||
245 | $output = Util::getMessage($message, $sql_query); |
||
246 | $response = Response::getInstance(); |
||
247 | if ($response->isAjax()) { |
||
248 | if ($message->isSuccess()) { |
||
249 | $events = $this->dbi->getEvents($db, $_POST['item_name']); |
||
250 | $event = $events[0]; |
||
251 | $response->addJSON( |
||
252 | 'name', |
||
253 | htmlspecialchars( |
||
254 | mb_strtoupper($_POST['item_name']) |
||
255 | ) |
||
256 | ); |
||
257 | if (! empty($event)) { |
||
258 | $response->addJSON('new_row', $this->rteList->getEventRow($event)); |
||
259 | } |
||
260 | $response->addJSON('insert', ! empty($event)); |
||
261 | $response->addJSON('message', $output); |
||
262 | } else { |
||
263 | $response->setRequestStatus(false); |
||
264 | $response->addJSON('message', $message); |
||
265 | } |
||
266 | exit; |
||
267 | } |
||
268 | } |
||
269 | /** |
||
270 | * Display a form used to add/edit a trigger, if necessary |
||
271 | */ |
||
272 | if (count($errors) |
||
273 | || (empty($_POST['editor_process_add']) |
||
274 | && empty($_POST['editor_process_edit']) |
||
275 | && (! empty($_REQUEST['add_item']) |
||
276 | || ! empty($_REQUEST['edit_item']) |
||
277 | || ! empty($_POST['item_changetype']))) |
||
278 | ) { // FIXME: this must be simpler than that |
||
279 | $operation = ''; |
||
280 | $title = null; |
||
281 | $item = null; |
||
282 | $mode = null; |
||
283 | if (! empty($_POST['item_changetype'])) { |
||
284 | $operation = 'change'; |
||
285 | } |
||
286 | // Get the data for the form (if any) |
||
287 | if (! empty($_REQUEST['add_item'])) { |
||
288 | $title = $this->words->get('add'); |
||
289 | $item = $this->getDataFromRequest(); |
||
290 | $mode = 'add'; |
||
291 | } elseif (! empty($_REQUEST['edit_item'])) { |
||
292 | $title = __("Edit event"); |
||
293 | if (! empty($_REQUEST['item_name']) |
||
294 | && empty($_POST['editor_process_edit']) |
||
295 | && empty($_POST['item_changetype']) |
||
296 | ) { |
||
297 | $item = $this->getDataFromName($_REQUEST['item_name']); |
||
298 | if ($item !== false) { |
||
299 | $item['item_original_name'] = $item['item_name']; |
||
300 | } |
||
301 | } else { |
||
302 | $item = $this->getDataFromRequest(); |
||
303 | } |
||
304 | $mode = 'edit'; |
||
305 | } |
||
306 | $this->general->sendEditor('EVN', $mode, $item, $title, $db, $operation); |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
307 | } |
||
308 | } |
||
309 | |||
310 | /** |
||
311 | * This function will generate the values that are required to for the editor |
||
312 | * |
||
313 | * @return array Data necessary to create the editor. |
||
314 | */ |
||
315 | public function getDataFromRequest() |
||
316 | { |
||
317 | $retval = []; |
||
318 | $indices = [ |
||
319 | 'item_name', |
||
320 | 'item_original_name', |
||
321 | 'item_status', |
||
322 | 'item_execute_at', |
||
323 | 'item_interval_value', |
||
324 | 'item_interval_field', |
||
325 | 'item_starts', |
||
326 | 'item_ends', |
||
327 | 'item_definition', |
||
328 | 'item_preserve', |
||
329 | 'item_comment', |
||
330 | 'item_definer', |
||
331 | ]; |
||
332 | foreach ($indices as $index) { |
||
333 | $retval[$index] = isset($_POST[$index]) ? $_POST[$index] : ''; |
||
334 | } |
||
335 | $retval['item_type'] = 'ONE TIME'; |
||
336 | $retval['item_type_toggle'] = 'RECURRING'; |
||
337 | if (isset($_POST['item_type']) && $_POST['item_type'] == 'RECURRING') { |
||
338 | $retval['item_type'] = 'RECURRING'; |
||
339 | $retval['item_type_toggle'] = 'ONE TIME'; |
||
340 | } |
||
341 | return $retval; |
||
342 | } |
||
343 | |||
344 | /** |
||
345 | * This function will generate the values that are required to complete |
||
346 | * the "Edit event" form given the name of a event. |
||
347 | * |
||
348 | * @param string $name The name of the event. |
||
349 | * |
||
350 | * @return array|bool Data necessary to create the editor. |
||
351 | */ |
||
352 | public function getDataFromName($name) |
||
353 | { |
||
354 | global $db; |
||
355 | |||
356 | $retval = []; |
||
357 | $columns = "`EVENT_NAME`, `STATUS`, `EVENT_TYPE`, `EXECUTE_AT`, " |
||
358 | . "`INTERVAL_VALUE`, `INTERVAL_FIELD`, `STARTS`, `ENDS`, " |
||
359 | . "`EVENT_DEFINITION`, `ON_COMPLETION`, `DEFINER`, `EVENT_COMMENT`"; |
||
360 | $where = "EVENT_SCHEMA " . Util::getCollateForIS() . "=" |
||
361 | . "'" . $this->dbi->escapeString($db) . "' " |
||
362 | . "AND EVENT_NAME='" . $this->dbi->escapeString($name) . "'"; |
||
363 | $query = "SELECT $columns FROM `INFORMATION_SCHEMA`.`EVENTS` WHERE $where;"; |
||
364 | $item = $this->dbi->fetchSingleRow($query); |
||
365 | if (! $item) { |
||
366 | return false; |
||
367 | } |
||
368 | $retval['item_name'] = $item['EVENT_NAME']; |
||
369 | $retval['item_status'] = $item['STATUS']; |
||
370 | $retval['item_type'] = $item['EVENT_TYPE']; |
||
371 | if ($retval['item_type'] == 'RECURRING') { |
||
372 | $retval['item_type_toggle'] = 'ONE TIME'; |
||
373 | } else { |
||
374 | $retval['item_type_toggle'] = 'RECURRING'; |
||
375 | } |
||
376 | $retval['item_execute_at'] = $item['EXECUTE_AT']; |
||
377 | $retval['item_interval_value'] = $item['INTERVAL_VALUE']; |
||
378 | $retval['item_interval_field'] = $item['INTERVAL_FIELD']; |
||
379 | $retval['item_starts'] = $item['STARTS']; |
||
380 | $retval['item_ends'] = $item['ENDS']; |
||
381 | $retval['item_preserve'] = ''; |
||
382 | if ($item['ON_COMPLETION'] == 'PRESERVE') { |
||
383 | $retval['item_preserve'] = " checked='checked'"; |
||
384 | } |
||
385 | $retval['item_definition'] = $item['EVENT_DEFINITION']; |
||
386 | $retval['item_definer'] = $item['DEFINER']; |
||
387 | $retval['item_comment'] = $item['EVENT_COMMENT']; |
||
388 | |||
389 | return $retval; |
||
390 | } |
||
391 | |||
392 | /** |
||
393 | * Displays a form used to add/edit an event |
||
394 | * |
||
395 | * @param string $mode If the editor will be used to edit an event |
||
396 | * or add a new one: 'edit' or 'add'. |
||
397 | * @param string $operation If the editor was previously invoked with |
||
398 | * JS turned off, this will hold the name of |
||
399 | * the current operation |
||
400 | * @param array $item Data for the event returned by |
||
401 | * getDataFromRequest() or getDataFromName() |
||
402 | * |
||
403 | * @return string HTML code for the editor. |
||
404 | */ |
||
405 | public function getEditorForm($mode, $operation, array $item) |
||
406 | { |
||
407 | global $db, $table, $event_status, $event_type, $event_interval; |
||
408 | |||
409 | $modeToUpper = mb_strtoupper($mode); |
||
410 | |||
411 | $response = Response::getInstance(); |
||
412 | |||
413 | // Escape special characters |
||
414 | $need_escape = [ |
||
415 | 'item_original_name', |
||
416 | 'item_name', |
||
417 | 'item_type', |
||
418 | 'item_execute_at', |
||
419 | 'item_interval_value', |
||
420 | 'item_starts', |
||
421 | 'item_ends', |
||
422 | 'item_definition', |
||
423 | 'item_definer', |
||
424 | 'item_comment', |
||
425 | ]; |
||
426 | foreach ($need_escape as $index) { |
||
427 | $item[$index] = htmlentities((string) $item[$index], ENT_QUOTES); |
||
428 | } |
||
429 | $original_data = ''; |
||
430 | if ($mode == 'edit') { |
||
431 | $original_data = "<input name='item_original_name' " |
||
432 | . "type='hidden' value='{$item['item_original_name']}'>\n"; |
||
433 | } |
||
434 | // Handle some logic first |
||
435 | if ($operation == 'change') { |
||
436 | if ($item['item_type'] == 'RECURRING') { |
||
437 | $item['item_type'] = 'ONE TIME'; |
||
438 | $item['item_type_toggle'] = 'RECURRING'; |
||
439 | } else { |
||
440 | $item['item_type'] = 'RECURRING'; |
||
441 | $item['item_type_toggle'] = 'ONE TIME'; |
||
442 | } |
||
443 | } |
||
444 | if ($item['item_type'] == 'ONE TIME') { |
||
445 | $isrecurring_class = ' hide'; |
||
446 | $isonetime_class = ''; |
||
447 | } else { |
||
448 | $isrecurring_class = ''; |
||
449 | $isonetime_class = ' hide'; |
||
450 | } |
||
451 | // Create the output |
||
452 | $retval = ""; |
||
453 | $retval .= "<!-- START " . $modeToUpper . " EVENT FORM -->\n\n"; |
||
454 | $retval .= "<form class='rte_form' action='db_events.php' method='post'>\n"; |
||
455 | $retval .= "<input name='{$mode}_item' type='hidden' value='1'>\n"; |
||
456 | $retval .= $original_data; |
||
457 | $retval .= Url::getHiddenInputs($db, $table) . "\n"; |
||
458 | $retval .= "<fieldset>\n"; |
||
459 | $retval .= "<legend>" . __('Details') . "</legend>\n"; |
||
460 | $retval .= "<table class='rte_table'>\n"; |
||
461 | $retval .= "<tr>\n"; |
||
462 | $retval .= " <td>" . __('Event name') . "</td>\n"; |
||
463 | $retval .= " <td><input type='text' name='item_name' \n"; |
||
464 | $retval .= " value='{$item['item_name']}'\n"; |
||
465 | $retval .= " maxlength='64'></td>\n"; |
||
466 | $retval .= "</tr>\n"; |
||
467 | $retval .= "<tr>\n"; |
||
468 | $retval .= " <td>" . __('Status') . "</td>\n"; |
||
469 | $retval .= " <td>\n"; |
||
470 | $retval .= " <select name='item_status'>\n"; |
||
471 | foreach ($event_status['display'] as $key => $value) { |
||
472 | $selected = ""; |
||
473 | if (! empty($item['item_status']) && $item['item_status'] == $value) { |
||
474 | $selected = " selected='selected'"; |
||
475 | } |
||
476 | $retval .= "<option$selected>$value</option>"; |
||
477 | } |
||
478 | $retval .= " </select>\n"; |
||
479 | $retval .= " </td>\n"; |
||
480 | $retval .= "</tr>\n"; |
||
481 | |||
482 | $retval .= "<tr>\n"; |
||
483 | $retval .= " <td>" . __('Event type') . "</td>\n"; |
||
484 | $retval .= " <td>\n"; |
||
485 | if ($response->isAjax()) { |
||
486 | $retval .= " <select name='item_type'>"; |
||
487 | foreach ($event_type as $key => $value) { |
||
488 | $selected = ""; |
||
489 | if (! empty($item['item_type']) && $item['item_type'] == $value) { |
||
490 | $selected = " selected='selected'"; |
||
491 | } |
||
492 | $retval .= "<option$selected>$value</option>"; |
||
493 | } |
||
494 | $retval .= " </select>\n"; |
||
495 | } else { |
||
496 | $retval .= " <input name='item_type' type='hidden' \n"; |
||
497 | $retval .= " value='{$item['item_type']}'>\n"; |
||
498 | $retval .= " <div class='font_weight_bold center half_width'>\n"; |
||
499 | $retval .= " {$item['item_type']}\n"; |
||
500 | $retval .= " </div>\n"; |
||
501 | $retval .= " <input type='submit'\n"; |
||
502 | $retval .= " name='item_changetype' class='half_width'\n"; |
||
503 | $retval .= " value='"; |
||
504 | $retval .= sprintf(__('Change to %s'), $item['item_type_toggle']); |
||
505 | $retval .= "'>\n"; |
||
506 | } |
||
507 | $retval .= " </td>\n"; |
||
508 | $retval .= "</tr>\n"; |
||
509 | $retval .= "<tr class='onetime_event_row $isonetime_class'>\n"; |
||
510 | $retval .= " <td>" . __('Execute at') . "</td>\n"; |
||
511 | $retval .= " <td class='nowrap'>\n"; |
||
512 | $retval .= " <input type='text' name='item_execute_at'\n"; |
||
513 | $retval .= " value='{$item['item_execute_at']}'\n"; |
||
514 | $retval .= " class='datetimefield'>\n"; |
||
515 | $retval .= " </td>\n"; |
||
516 | $retval .= "</tr>\n"; |
||
517 | $retval .= "<tr class='recurring_event_row $isrecurring_class'>\n"; |
||
518 | $retval .= " <td>" . __('Execute every') . "</td>\n"; |
||
519 | $retval .= " <td>\n"; |
||
520 | $retval .= " <input class='half_width' type='text'\n"; |
||
521 | $retval .= " name='item_interval_value'\n"; |
||
522 | $retval .= " value='{$item['item_interval_value']}'>\n"; |
||
523 | $retval .= " <select class='half_width' name='item_interval_field'>"; |
||
524 | foreach ($event_interval as $key => $value) { |
||
525 | $selected = ""; |
||
526 | if (! empty($item['item_interval_field']) |
||
527 | && $item['item_interval_field'] == $value |
||
528 | ) { |
||
529 | $selected = " selected='selected'"; |
||
530 | } |
||
531 | $retval .= "<option$selected>$value</option>"; |
||
532 | } |
||
533 | $retval .= " </select>\n"; |
||
534 | $retval .= " </td>\n"; |
||
535 | $retval .= "</tr>\n"; |
||
536 | $retval .= "<tr class='recurring_event_row$isrecurring_class'>\n"; |
||
537 | $retval .= " <td>" . _pgettext('Start of recurring event', 'Start'); |
||
538 | $retval .= " </td>\n"; |
||
539 | $retval .= " <td class='nowrap'>\n"; |
||
540 | $retval .= " <input type='text'\n name='item_starts'\n"; |
||
541 | $retval .= " value='{$item['item_starts']}'\n"; |
||
542 | $retval .= " class='datetimefield'>\n"; |
||
543 | $retval .= " </td>\n"; |
||
544 | $retval .= "</tr>\n"; |
||
545 | $retval .= "<tr class='recurring_event_row$isrecurring_class'>\n"; |
||
546 | $retval .= " <td>" . _pgettext('End of recurring event', 'End') . "</td>\n"; |
||
547 | $retval .= " <td class='nowrap'>\n"; |
||
548 | $retval .= " <input type='text' name='item_ends'\n"; |
||
549 | $retval .= " value='{$item['item_ends']}'\n"; |
||
550 | $retval .= " class='datetimefield'>\n"; |
||
551 | $retval .= " </td>\n"; |
||
552 | $retval .= "</tr>\n"; |
||
553 | $retval .= "<tr>\n"; |
||
554 | $retval .= " <td>" . __('Definition') . "</td>\n"; |
||
555 | $retval .= " <td><textarea name='item_definition' rows='15' cols='40'>"; |
||
556 | $retval .= $item['item_definition']; |
||
557 | $retval .= "</textarea></td>\n"; |
||
558 | $retval .= "</tr>\n"; |
||
559 | $retval .= "<tr>\n"; |
||
560 | $retval .= " <td>" . __('On completion preserve') . "</td>\n"; |
||
561 | $retval .= " <td><input type='checkbox'\n"; |
||
562 | $retval .= " name='item_preserve'{$item['item_preserve']}></td>\n"; |
||
563 | $retval .= "</tr>\n"; |
||
564 | $retval .= "<tr>\n"; |
||
565 | $retval .= " <td>" . __('Definer') . "</td>\n"; |
||
566 | $retval .= " <td><input type='text' name='item_definer'\n"; |
||
567 | $retval .= " value='{$item['item_definer']}'></td>\n"; |
||
568 | $retval .= "</tr>\n"; |
||
569 | $retval .= "<tr>\n"; |
||
570 | $retval .= " <td>" . __('Comment') . "</td>\n"; |
||
571 | $retval .= " <td><input type='text' name='item_comment' maxlength='64'\n"; |
||
572 | $retval .= " value='{$item['item_comment']}'></td>\n"; |
||
573 | $retval .= "</tr>\n"; |
||
574 | $retval .= "</table>\n"; |
||
575 | $retval .= "</fieldset>\n"; |
||
576 | if ($response->isAjax()) { |
||
577 | $retval .= "<input type='hidden' name='editor_process_{$mode}'\n"; |
||
578 | $retval .= " value='true'>\n"; |
||
579 | $retval .= "<input type='hidden' name='ajax_request' value='true'>\n"; |
||
580 | } else { |
||
581 | $retval .= "<fieldset class='tblFooters'>\n"; |
||
582 | $retval .= " <input type='submit' name='editor_process_{$mode}'\n"; |
||
583 | $retval .= " value='" . __('Go') . "'>\n"; |
||
584 | $retval .= "</fieldset>\n"; |
||
585 | } |
||
586 | $retval .= "</form>\n\n"; |
||
587 | $retval .= "<!-- END " . $modeToUpper . " EVENT FORM -->\n\n"; |
||
588 | |||
589 | return $retval; |
||
590 | } |
||
591 | |||
592 | /** |
||
593 | * Composes the query necessary to create an event from an HTTP request. |
||
594 | * |
||
595 | * @return string The CREATE EVENT query. |
||
596 | */ |
||
597 | public function getQueryFromRequest() |
||
598 | { |
||
599 | global $errors, $event_status, $event_type, $event_interval; |
||
600 | |||
601 | $query = 'CREATE '; |
||
602 | if (! empty($_POST['item_definer'])) { |
||
603 | if (mb_strpos($_POST['item_definer'], '@') !== false |
||
604 | ) { |
||
605 | $arr = explode('@', $_POST['item_definer']); |
||
606 | $query .= 'DEFINER=' . Util::backquote($arr[0]); |
||
607 | $query .= '@' . Util::backquote($arr[1]) . ' '; |
||
608 | } else { |
||
609 | $errors[] = __('The definer must be in the "username@hostname" format!'); |
||
610 | } |
||
611 | } |
||
612 | $query .= 'EVENT '; |
||
613 | if (! empty($_POST['item_name'])) { |
||
614 | $query .= Util::backquote($_POST['item_name']) . ' '; |
||
615 | } else { |
||
616 | $errors[] = __('You must provide an event name!'); |
||
617 | } |
||
618 | $query .= 'ON SCHEDULE '; |
||
619 | if (! empty($_POST['item_type']) |
||
620 | && in_array($_POST['item_type'], $event_type) |
||
621 | ) { |
||
622 | if ($_POST['item_type'] == 'RECURRING') { |
||
623 | if (! empty($_POST['item_interval_value']) |
||
624 | && ! empty($_POST['item_interval_field']) |
||
625 | && in_array($_POST['item_interval_field'], $event_interval) |
||
626 | ) { |
||
627 | $query .= 'EVERY ' . intval($_POST['item_interval_value']) . ' '; |
||
628 | $query .= $_POST['item_interval_field'] . ' '; |
||
629 | } else { |
||
630 | $errors[] |
||
631 | = __('You must provide a valid interval value for the event.'); |
||
632 | } |
||
633 | if (! empty($_POST['item_starts'])) { |
||
634 | $query .= "STARTS '" |
||
635 | . $this->dbi->escapeString($_POST['item_starts']) |
||
636 | . "' "; |
||
637 | } |
||
638 | if (! empty($_POST['item_ends'])) { |
||
639 | $query .= "ENDS '" |
||
640 | . $this->dbi->escapeString($_POST['item_ends']) |
||
641 | . "' "; |
||
642 | } |
||
643 | } else { |
||
644 | if (! empty($_POST['item_execute_at'])) { |
||
645 | $query .= "AT '" |
||
646 | . $this->dbi->escapeString($_POST['item_execute_at']) |
||
647 | . "' "; |
||
648 | } else { |
||
649 | $errors[] |
||
650 | = __('You must provide a valid execution time for the event.'); |
||
651 | } |
||
652 | } |
||
653 | } else { |
||
654 | $errors[] = __('You must provide a valid type for the event.'); |
||
655 | } |
||
656 | $query .= 'ON COMPLETION '; |
||
657 | if (empty($_POST['item_preserve'])) { |
||
658 | $query .= 'NOT '; |
||
659 | } |
||
660 | $query .= 'PRESERVE '; |
||
661 | if (! empty($_POST['item_status'])) { |
||
662 | foreach ($event_status['display'] as $key => $value) { |
||
663 | if ($value == $_POST['item_status']) { |
||
664 | $query .= $event_status['query'][$key] . ' '; |
||
665 | break; |
||
666 | } |
||
667 | } |
||
668 | } |
||
669 | if (! empty($_POST['item_comment'])) { |
||
670 | $query .= "COMMENT '" . $this->dbi->escapeString( |
||
671 | $_POST['item_comment'] |
||
672 | ) . "' "; |
||
673 | } |
||
674 | $query .= 'DO '; |
||
675 | if (! empty($_POST['item_definition'])) { |
||
676 | $query .= $_POST['item_definition']; |
||
677 | } else { |
||
678 | $errors[] = __('You must provide an event definition.'); |
||
679 | } |
||
680 | |||
681 | return $query; |
||
682 | } |
||
683 | } |
||
684 |