response->addScriptFiles(['database/events.js', 'sql.js']); if (! $request->isAjax()) { if (! $this->checkParameters(['db'])) { return null; } $GLOBALS['errorUrl'] = Util::getScriptNameForOption( Config::getInstance()->settings['DefaultTabDatabase'], 'database', ); $GLOBALS['errorUrl'] .= Url::getCommon(['db' => Current::$database], '&'); $databaseName = DatabaseName::tryFrom($request->getParam('db')); if ($databaseName === null || ! $this->dbTableExists->selectDatabase($databaseName)) { $this->redirect('/', ['reload' => true, 'message' => __('No databases selected.')]); return null; } } elseif (Current::$database !== '') { $this->dbi->selectDb(Current::$database); } /** * Keep a list of errors that occurred while * processing an 'Add' or 'Edit' operation. */ $GLOBALS['errors'] = []; $GLOBALS['message'] ??= null; if (! empty($_POST['editor_process_add']) || ! empty($_POST['editor_process_edit'])) { $output = $this->events->handleEditor(); if ($request->isAjax()) { if ($GLOBALS['message']->isSuccess()) { $events = $this->events->getDetails(Current::$database, $_POST['item_name']); $event = $events[0]; $this->response->addJSON( 'name', htmlspecialchars( mb_strtoupper($_POST['item_name']), ), ); $sqlDrop = sprintf( 'DROP EVENT IF EXISTS %s', Util::backquote($event['name']), ); $this->response->addJSON( 'new_row', $this->template->render('database/events/row', [ 'db' => Current::$database, 'table' => Current::$table, 'event' => $event, 'has_privilege' => Util::currentUserHasPrivilege('EVENT', Current::$database), 'sql_drop' => $sqlDrop, 'row_class' => '', ]), ); $this->response->addJSON('insert', true); $this->response->addJSON('message', $output); } else { $this->response->setRequestStatus(false); $this->response->addJSON('message', $GLOBALS['message']); } $this->response->addJSON('tableType', 'events'); return null; } } /** * Display a form used to add/edit a trigger, if necessary */ if ( count($GLOBALS['errors']) || empty($_POST['editor_process_add']) && empty($_POST['editor_process_edit']) && ( ! empty($_REQUEST['add_item']) || ! empty($_REQUEST['edit_item']) || ! empty($_POST['item_changetype']) ) ) { // FIXME: this must be simpler than that $operation = ''; $title = ''; $item = null; $mode = ''; if (! empty($_POST['item_changetype'])) { $operation = 'change'; } // Get the data for the form (if any) if (! empty($_REQUEST['add_item'])) { $title = __('Add event'); $item = $this->events->getDataFromRequest(); $mode = 'add'; } elseif (! empty($_REQUEST['edit_item'])) { $title = __('Edit event'); if ( ! empty($_REQUEST['item_name']) && empty($_POST['editor_process_edit']) && empty($_POST['item_changetype']) ) { $item = $this->events->getDataFromName($_REQUEST['item_name']); if ($item !== null) { $item['item_original_name'] = $item['item_name']; } } else { $item = $this->events->getDataFromRequest(); } $mode = 'edit'; } if ($item !== null) { if ($operation === 'change') { if ($item['item_type'] === 'RECURRING') { $item['item_type'] = 'ONE TIME'; $item['item_type_toggle'] = 'RECURRING'; } else { $item['item_type'] = 'RECURRING'; $item['item_type_toggle'] = 'ONE TIME'; } } $editor = $this->template->render('database/events/editor_form', [ 'db' => Current::$database, 'event' => $item, 'mode' => $mode, 'is_ajax' => $request->isAjax(), 'status_display' => $this->events->status['display'], 'event_type' => $this->events->type, 'event_interval' => $this->events->interval, ]); if ($request->isAjax()) { $this->response->addJSON('message', $editor); $this->response->addJSON('title', $title); return null; } $this->response->addHTML("\n\n