public function save_schedule_event() { if (!$this->isAjax || $this->method != 'POST') { $this->app->abort(404, $this->setLocalization('Page not found')); } if ($no_auth = $this->checkAuth()) { return $no_auth; } $data = array(); $data['action'] = 'addEvent'; $error = $this->setlocalization($this->setlocalization('Not enough data')); $from_db = array_flip($this->getFieldFromArray($this->db->getTableFields('schedule_events'), 'Field')); $form_post = $this->postData; $recipient_func = "getRecipientBy" . ucfirst(strtolower(str_replace(array('by_', 'to_'), '', $form_post['user_list_type']))); $form_post['recipient'] = $this->{$recipient_func}($form_post); $form_post['periodic'] = (int) str_replace('schedule_type_', '', $form_post['type']) - 1; $form_post['state'] = 1; $form_post['reboot_after_ok'] = (int) (!empty($form_post['need_reboot']) && (string) $form_post['need_reboot'] != 'false' && (string) $form_post['need_reboot'] != 'off' && (string) $form_post['need_reboot'] != 'false' && (string) $form_post['need_reboot'] != '0'); if (array_key_exists('month', $form_post)) { $form_post['month'] = (int) $form_post['month']; } if (array_key_exists('every_month', $form_post)) { $form_post['every_month'] = (int) $form_post['every_month']; } if (array_key_exists('every_day', $form_post)) { $form_post['every_day'] = (int) $form_post['every_day']; } if (array_key_exists('every_hour', $form_post)) { $form_post['every_hour'] = (int) $form_post['every_hour']; } if (array_key_exists('every_minute', $form_post)) { $form_post['every_minute'] = (int) $form_post['every_minute']; } if (array_key_exists('date_begin', $form_post)) { $date = \DateTime::createFromFormat('d/m/Y', $form_post['date_begin']); $form_post['date_begin'] = $date ? $date->format('Y-m-d G:i:s') : 'NOW()'; } if (array_key_exists('date_end', $form_post)) { $date = \DateTime::createFromFormat('d/m/Y', $form_post['date_end']); $form_post['date_end'] = $date ? $date->format('Y-m-d G:i:s') : ''; } $form_post['schedule'] = \CronForm::getInstance()->setFormData($form_post)->getExpression(); $params = array(); $from_db = array_combine(array_keys($from_db), array_fill(0, count($from_db), NULL)); if (!empty($form_post['id'])) { $id = $form_post['id']; $operation = 'update'; $params[] = array_replace($from_db, array_intersect_key($form_post, $from_db)); $params[] = $id; } else { $operation = 'insert'; $params[] = array_replace($from_db, array_intersect_key($form_post, $from_db)); } unset($params[0]['id']); $result = call_user_func_array(array($this->db, $operation . "ScheduleEvents"), $params); if (is_numeric($result)) { $error = ''; if ($result === 0) { $data['nothing_to_do'] = TRUE; $data['msg'] = $this->setlocalization($this->setlocalization('Nothing to do')); } } $response = $this->generateAjaxResponse($data, $error); return new Response(json_encode($response), empty($error) ? 200 : 500); }