/** * Удаление новости автосервиса * @return void */ function action_delete() { $settings = ORM::factory('payment_settings', $this->request->param('id', null)); if (!$settings->loaded()) { Message::set(Message::ERROR, Kohana::message('admin', 'payment.settings_not_found')); $this->request->redirect('admin/payment/settings'); } if ($settings->system == 'Y') { Message::set(Message::NOTICE, 'Нельзя удалять системные настройки'); $this->request->redirect('admin/payment/settings'); } if ($_POST) { $action = Arr::extract($_POST, array('submit', 'cancel')); if ($action['cancel']) { $this->request->redirect('admin/payment/settings'); } if ($action['submit']) { $name = $settings->name; $settings->delete(); Message::set(Message::SUCCESS, 'Платежная настройка <strong>' . $name . '</strong> удалена'); $this->request->redirect('admin/payment/settings'); } } $this->view = View::factory('backend/delete')->set('url', 'admin/payment/settings/delete/' . $settings->id)->set('from_url', 'admin/payment/settings')->set('title', 'Удаление платежной настройки: ' . $settings->name)->set('text', 'Вы действительно хотите удалить "' . $settings->name . '?'); $this->template->title = 'Удаление новости "' . $settings->name . '"'; $this->template->bc['#'] = $this->template->title; $this->template->content = $this->view; }
/** * REST endpoint for sharing droplets via email */ public function action_share() { $this->template = ''; $this->auto_render = FALSE; if ($this->request->method() != "POST") { throw HTTP_Exception::factory(405)->allowed('POST'); } // Extract the input data to be used for sending the email $post = Arr::extract($_POST, array('recipient', 'drop_title', 'drop_url', 'security_code')); $csrf_token = $this->request->headers('x-csrf-token'); // Setup validation $validation = Validation::factory($post)->rule('recipient', 'not_empty')->rule('recipient', 'email')->rule('security_code', 'Captcha::valid')->rule('drop_title', 'not_empty')->rule('drop_url', 'url'); // Validate if (!CSRF::valid($csrf_token) or !$validation->check()) { Kohana::$log->add(Log::DEBUG, "CSRF token or form validation failure"); throw HTTP_Exception::factory(400); } else { list($recipient, $subject) = array($post['recipient'], $post['drop_title']); // Modify the mail body to include the email address of the // use sharing content $mail_body = __(":user has shared a drop with you via SwiftRiver\n\n:url", array(':user' => $this->user['owner']['username'], ':url' => $post['drop_url'])); // Send the email Swiftriver_Mail::send($recipient, $subject, $mail_body); } }
public function action_register() { if (isset($_POST['submit'])) { $data = Arr::extract($_POST, array('username', 'password', 'first_name', 'password_confirm', 'email', 'phone', 'address', 'country_id', 'zone_id', 'city_id', 'agree')); $users = ORM::factory('user'); // $content->message = ''; // $content->message = Captcha::valid($_POST['captcha'])? 'Не угадал'; try { $regdate = date("Y-M-D"); $users->create_user($_POST, array('username', 'first_name', 'password', 'email', 'phone', 'address', 'country_id', 'zone_id', 'city_id', 'regdate' => $regdate)); $role = ORM::factory('role', array('name' => 'login')); $users->add('roles', $role); // $users->add('roles', 1); $email = Email::factory('Регистрация на сайте', 'Регистрация на сайте успешно завешена')->to($data['email'], $data['first_name'])->from('*****@*****.**', 'mykohan')->send(); $this->action_login(); $this->request->redirect('account'); // $this->reg_ok = "<p><b>Ваш профил успешно созданно</b></p>"; $this->action_login(); $this->request->redirect('account'); } catch (ORM_Validation_Exception $e) { $errors = $e->errors('user'); } } $captcha = Captcha::instance(); $captcha_image = $captcha->render(); $country = ORM::factory('country')->find_all(); $zones = ORM::factory('zone')->where('country_id', '=', 176)->find_all(); $form_register = View::factory('v_registration', array('country' => $country, 'zones' => $zones))->bind('errors', $errors)->bind('data', $data)->bind('captcha_image', $captcha_image); // Выводим в шаблон $this->template->title = 'Регистрация'; $this->template->page_title = 'Регистрация новога пользователя'; $this->template->block_center = array('form_register' => $form_register); }
public function action_edit() { $id = (int) $this->request->param('id'); $m = ORM::factory('manufactures', $id); if (!$m->loaded()) { $this->request->redirect('/admin/manufactures'); } $data = $m->as_array(); // Редактирование if (isset($_POST['submit'])) { $data = Arr::extract($_POST, array('title', 'alias', 'url', 'image')); $m->values($data); try { $m->save(); if (!empty($_FILES['image']['name'])) { $image = $_FILES['image']['tmp_name']; $filename = $this->_upload_img($image); // Запись в БД $m->image = $filename; $m->save(); } $this->request->redirect('admin/manufactures'); } catch (ORM_Validation_Exception $e) { $errors = $e->errors('validation'); } } $content = View::factory('/admin/v_manufactureedit')->bind('id', $id)->bind('errors', $errors)->bind('data', $data); $this->template->page_title = 'Редактировть страницу'; $this->template->block_center = $content; }
/** * Удаление новости автосервиса * @return void */ function action_delete() { $news = ORM::factory('newsservice', $this->request->param('id', NULL)); if (!$news->loaded()) { Message::set(Message::ERROR, Kohana::message('admin', 'news_not_found')); $this->request->redirect('admin/news/service'); } if ($_POST) { $action = Arr::extract($_POST, array('submit', 'cancel')); if ($action['cancel']) { $this->request->redirect('admin/news/service'); } if ($action['submit']) { $title = $news->title; $service_name = $news->service->name; $news->delete(); Message::set(Message::SUCCESS, 'Новость автосервиса <strong>' . $service_name . '</strong> "' . $title . '" удалена'); $this->request->redirect('admin/news/service'); } } $this->view = View::factory('backend/delete')->set('url', 'admin/news/service/delete/' . $news->id)->set('from_url', 'admin/news/service')->set('title', 'Удаление новости компании ' . $news->service->name)->set('text', 'Вы действительно хотите удалить новость "' . $news->title . '" сервиса "' . $news->service->name . '"?'); $this->template->title = 'Удаление новости "' . $news->title . '"'; $this->template->bc['#'] = $this->template->title; $this->template->content = $this->view; }
public function action_reg() { if ($this->request->method() == 'POST') { $date = Arr::extract($_POST, array('username', 'first_name', 'email', 'password', 'password_confirm')); $users = ORM::factory('user'); try { $users->create_user($_POST, array('email', 'username', 'password', 'first_name')); $role = ORM::factory('role')->where('name', '=', 'login')->find(); $users->add('roles', $role); $this->action_login(); // $this->request->redirect('http://kohana/catalog'); } catch (ORM_Validation_Exception $e) { $errors = $e->errors('auto'); } header('Location: /'); exit; } //закэшировал $content = $this->cache->get('v_reg'); //$this->cache->delete('v_reg'); if ($content == NULL) { $content = View::factory('/index/auth/v_auth_register')->bind('errors', $errors); $this->cache->set('v_reg', $content->render()); } //выводим в шаблон $this->template->page_title = 'Регистрация'; $this->template->block_center = array($content); }
public function action_index() { $data_pages = ORM::factory('Page')->where('title_en', '=', 'contacts')->find()->as_array(); $id = $data_pages['id']; $data_contacts = ORM::factory('Setting', 1)->as_array(); if (isset($_POST['submit'])) { $data_pages = Arr::extract($_POST, array('seo_snippet', 'keywords', 'title_head')); $data_contacts = Arr::extract($_POST, array('main_adress', 'branch_adress')); try { $page = ORM::factory('Page', $id); $page->values($data_pages); $page->save(); $contacts = ORM::factory('Setting', 1); $contacts->values($data_contacts); $contacts->save(); Controller::redirect('admin/contacts'); } catch (ORM_Validation_Exception $e) { $errors = $e->errors('validation'); } } $content = View::factory('admin/contacts/v_contacts_edit'); $content->bind('errors', $errors); $content->bind('data_pages', $data_pages); $content->bind('data_contacts', $data_contacts); $this->template->page_title = 'Контакты'; $this->template->block_center = array($content); }
/** * Basic */ public function action_edit() { $this->title = __('settings.settings_general'); // Fields for save $for_extract = ['per_page_frontend', 'per_page_backend', 'sitename', 'siteslogan', 'copyright', 'year_creation_site', 'type_backend_menu']; $config = Config::get('settings'); $data = Arr::extract($_POST, $for_extract); if ($this->request->is_post()) { $data = Validation::factory(array_map('trim', $data))->rules('per_page_frontend', [['not_empty'], ['digit']])->rules('per_page_backend', [['not_empty'], ['digit']])->rules('year_creation_site', [['not_empty'], ['digit']])->rule('sitename', 'not_empty'); if ($data->check()) { foreach ($for_extract as $field) { $config[$field] = $data[$field]; } $config->save(); Message::success(__('settings.changes_saved')); HTTP::redirect(Route::url('b_settings')); } else { Message::error(__('settings.error_saving')); $errors = $data->errors('validation'); } } else { $data = $config; } $this->content = View::factory($this->view, ['data' => $data])->bind('errors', $errors); }
public function before() { parent::before(); $this->params = Arr::extract($this->request->param(), array('year', 'month', 'day')); View::bind_global('params', $this->params); View::bind_global('content', $this->content); }
public function action_edit() { $this->request->response = View::factory($this->request->param('format') . '/movement/edit')->bind('movement', $this->movement)->set('sources', ORM::factory('source')->where('parent_id', 'IS', NULL)->find_all()->as_array('id', 'name'))->set('equities', $this->user->equities->where('parent_id', 'IS', NULL)->find_all()->as_array('id', 'name'))->set('drains', ORM::factory('drain')->where('parent_id', 'IS', NULL)->find_all()->as_array('id', 'name')); $this->movement = ORM::factory('movement', $this->request->param('id')); if (isset($this->input['name'])) { $this->movement->values($this->input); $transactions = Arr::extract($this->input, array('incomes', 'transfers', 'expenses'), array()); foreach ($transactions as $type => $transaction_array) { foreach ($transaction_array as $transaction) { $this->movement->add_transaction(ORM::factory(rtrim($type, 's'))->values($transaction)); } } if ($this->movement->check()) { $this->movement->save(); $this->request->redirect('movement/view/' . $this->movement->id . '.' . $this->request->param('format')); } } else { foreach ($this->movement->incomes->find_all() as $income) { $this->movement->add_transaction($income); } foreach ($this->movement->transfers->find_all() as $transfer) { $this->movement->add_transaction($transfer); } foreach ($this->movement->expenses->find_all() as $expense) { $this->movement->add_transaction($expense); } } }
public function action_login() { $this->template->menu_login = TRUE; // Если залогинен, то перекидываем на дерево if (Auth::instance()->logged_in()) { $this->redirect(Route::url('user/id', array('user_id' => Auth::instance()->get_user()->id))); } $post = Arr::extract($this->request->post(), array('email', 'password')); $data['errors'] = NULL; if ($this->request->method() == 'POST') { $valid = Validation::factory($post)->rules('email', array(array('not_empty')))->rules('password', array(array('not_empty')))->labels(array('email' => 'Адрес электронной почты', 'password' => 'Пароль')); if (!$valid->check()) { $data['errors'] = $valid->errors('valid'); } else { if (Auth::instance()->login($valid['email'], $valid['password'], TRUE)) { // Авторизация прошла успешно if (!is_null($this->request->referrer())) { $this->redirect($this->request->referrer()); } else { $this->redirect(Route::url('user/id', array('user_id' => Auth::instance()->get_user()->id))); } } else { $data['errors'] = array('usermail' => '', 'userpass' => Kohana::message('valid', 'login.incorrect')); } } } $data += $post; $this->template->content = View::factory('auth/login', $data); }
public function action_index() { if (Auth::instance()->logged_in()) { $this->request->redirect('admin'); } if ($_POST) { $data = Arr::extract($_POST, array('username', 'password', 'remember')); $status = Auth::instance()->login($data['username'], $data['password'], (bool) $data['remember']); if ($status) { $user = ORM::factory('user')->where('username', '=', $data['username'])->find(); if ($user->status == 1) { if (Auth::instance()->logged_in()) { $this->request->redirect('admin'); } } else { $faillogin = "******"; Auth::instance()->logout(TRUE); } } else { $faillogin = "******"; $this->response->body(View::factory('/admin/login')->bind('faillogin', $faillogin)); } } $this->response->body(View::factory('/admin/login')->bind('faillogin', $faillogin)); }
public function action_save() { $data = Arr::extract($_POST, array('sitename', 'description', 'session', 'keywords', 'robots', 'email', 'author', 'copyright', 'page404', 'status', 'debug', 'cache')); foreach ($data as $key => $value) { Kohana::$config->_write_config('site', $key, $value); } }
public function action_delete() { $dispute = ORM::factory('admin_dispute', $this->request->param('id', NULL)); if (!$dispute->loaded()) { Message::set(Message::ERROR, 'Такое дополнение не найдено'); $this->request->redirect('admin/development'); } $task_url = 'admin/development/task/view/' . $dispute->task->id; if ($_POST) { $actions = Arr::extract($_POST, array('submit', 'cancel'), FALSE); /* if ($actions['cancel']) $this->request->redirect('admin/development/task/view/'.$dispute->task->id); */ if ($actions['submit']) { $dispute->delete(); Message::set(Message::SUCCESS, 'Дополнение к задаче удалено'); } $this->request->redirect($task_url); } $this->view = View::factory('backend/delete')->set('url', $this->request->uri())->set('from_url', $task_url)->set('title', 'Удаление дополнения к задаче')->set('text', 'Вы действительно хотите удалить дополнение к задаче "' . $dispute->task->title . '"'); $this->template->title = 'Удаление дополнения к задаче'; $this->template->bc['#'] = $this->template->title; $this->template->content = $this->view; }
/** * Edit */ public function action_edit() { $this->title = __('home.page_edit'); // Fields for save $for_extract = ['text', 'meta_t', 'meta_d', 'meta_k']; $config = Config::get('home'); $data = Arr::extract($_POST, $for_extract); if ($this->request->is_post()) { $data = Validation::factory(array_map('trim', $data))->rule('meta_t', 'not_empty')->rule('meta_d', 'not_empty')->rule('meta_k', 'not_empty'); if ($data->check()) { foreach ($for_extract as $field) { $config[$field] = $data[$field]; } $config->save(); Message::success(__('settings.changes_saved')); HTTP::redirect(Route::url('b_home')); } else { Message::error(__('settings.error_saving')); $errors = $data->errors('validation'); } } else { $data = $config; } $this->content = View::factory($this->view, ['data' => $data])->bind('errors', $errors); }
public function test_extract() { $array = array('one' => 'foo', 'two' => 'bar'); // The "one" and "xxx" keys should be present // "xxx" should be NULL, because it does exist $expect = array('one' => 'foo', 'xxx' => NULL); $this->assert_equal(Arr::extract($array, array('one', 'xxx'), NULL), $expect); }
public function action_create() { if ($this->request->method() == Request::POST) { # Get data $data = Arr::extract($_POST, array('name', 'surname', 'email', 'phone')); # Create new user $number = ORM::factory('User')->created($data); $this->request->body(json_encode(array('number' => $number))); } }
public function registration($data) { $keys = array('lastname', 'firstname', 'secondname', 'phone', 'additional_phones', 'email', 'password', 'is_subscribed', 'city_id', 'street', 'home', 'housing', 'apartment', 'floor', 'lift'); $data = \Arr::extract($data, $keys); $data['reg_date'] = date("Y-m-d H:i:s"); $data['owner_id'] = OWNER_ID; if (!$data['city_id']) { $data['city_id'] = \Model::factory('Geo')->getCityId(); } $comuser = $this->getByAttributes(['email' => $data['email']]); if ($data['phone']) { $comuser2 = $this->getByAttributes(['phone' => $data['phone']]); if (null !== $comuser2) { if (null === $comuser || $comuser['id'] == $comuser2['id']) { $comuser = $comuser2; } else { if ($comuser['phone'] && $comuser['phone'] != $comuser2['phone']) { $additionals = []; if ($data['additional_phones']) { $additionals[] = $data['additional_phones']; } $additionals[] = '+7' . $comuser['phone']; if ($comuser['additional_phones']) { $additionals[] = $comuser['additional_phones']; } if ($comuser2['additional_phones']) { $additionals[] = $comuser2['additional_phones']; } $data['additional_phones'] = implode(', ', $additionals); $comuser['phone'] = $data['phone']; } $query = $this->_db->newStatement("\n UPDATE `order`\n SET user_id = :new_user_id:\n WHERE user_id = :old_user_id:\n "); $query->setInteger('new_user_id', $comuser['id']); $query->setInteger('old_user_id', $comuser2['id']); $query->execute(); } } if (null !== $comuser) { if ($comuser['phone'] && $comuser['phone'] != $data['phone']) { $additionals = []; if ($data['additional_phones']) { $additionals[] = $data['additional_phones']; } $additionals[] = '+7' . $comuser['phone']; if ($comuser['additional_phones']) { $additionals[] = $comuser['additional_phones']; } $data['additional_phones'] = implode(', ', $additionals); } $this->update($data, $comuser['id']); return $comuser['id']; } } return $this->insert($data); }
public function action_index() { // todo: try/catch OAuthClientException $server = service('oauth.server.auth'); $params = $server->getGrantType('authorization_code')->checkAuthoriseParams(); $this->session->set('oauth', $params); if (!$this->user) { $this->redirect('user/login' . URL::query(array('from_url' => 'oauth/authorize' . URL::query()), FALSE)); } $this->redirect('oauth/authorize' . URL::query(Arr::extract($params, $this->oauth_params))); }
public function catInsert($parentId, $data = array()) { $data = Arr::extract($data, array('name')); $vData = $data; $vData['parentId'] = $parentId; if (!$this->validate($vData)) { return FALSE; } $this->nstree->insert($parentId, $data); return TRUE; }
public function demo_acl() { $this->content = View::factory('demo/bonafide/acl/debug')->set('matrix', $this->request->url(array('demo' => 'acl_matrix')))->set('roles', $this->acl->roles())->bind('role', $role)->set('actions', $this->acl->actions())->bind('action', $action)->set('resources', $this->acl->resources())->bind('resource', $resource)->bind('can', $can)->bind('allowed', $allowed); if (Request::$method === 'POST') { // Get role, action, and resource from POST data list($role, $action, $resource) = array_values(Arr::extract($_POST, array('role', 'action', 'resource'))); // Does this resource have the action? $can = $this->acl->can($action, $resource); // Is this action allowed? $allowed = $this->acl->allowed($role, $action, $resource); } }
public function action_get_image() { $this->auto_render = FALSE; if (Arr::get($_SERVER, 'HTTP_X_REQUESTED_WITH', '') == 'XMLHttpRequest') { $image = ORM::factory('image', Arr::get($_POST, 'id')); $image = Arr::merge($image->as_array(), Arr::extract((array) Image::factory('images/' . $image->id . '/original' . $image->ext), array('width', 'height'))); $this->response->headers('Content-Type: application/json; charset=utf-8'); $this->response->body(json_encode($image)); } else { $this->response->body('Only AJAX request'); } }
public function action_contacts() { if ($this->request->method() == "POST") { $data = Arr::extract($_POST, array('name', 'email', 'text')); $admin_email = Kohana::$config->load('settings.admin_email'); $site_name = Kohana::$config->load('setting.site_name'); $email = Email::factory('Контакты', $data['text'])->to($data['email'], $data['name'])->from($admin_email, $site_name)->send(); header('Location: /main/contacts'); exit; } $contact = View::factory('index/contact/v_contact'); $this->template->block_center = array($contact); }
public function action_update() { $this->userId(); if ($this->request->method() == 'POST') { $this->userId(); $data = Arr::extract($_POST, array("first_name", 'email')); $this->user->update_user($data, array("first_name", 'email')); header('Location: /admin/auth/user'); exit; } $content = View::factory('/admin/auth/v_auth_update', array('user' => $this->user, 'id' => $this->idUser)); $this->template->block_center = array($content); }
/** * Sets the unique "any field" key and creates an ArrayObject from the * passed array. * * @param array $array array to validate */ public function __construct(array $array) { if ($this->_fields()) { $array = Arr::extract($array, $this->_fields()); } $this->_data = $array; // Add labels $this->labels($this->_labels()); // Add rules foreach ($this->_rules() as $field => $rules) { $this->rules($field, $rules); } }
public function action_create() { $post_model = Model::factory('Post'); if (Arr::get($_POST, 'hidden') == 'add_post') { $keys = array('title', 'author', 'content'); $view_input = Arr::extract($_POST, $keys, NULL); $post_model->add_post($view_input); } else { die('Something in Controller_Editpost::action_create() failed!'); } $front_route = Route::get('default')->uri(array('controller' => 'front', 'action' => 'index')); $this->request->redirect($front_route); }
/** * Action: edit */ public function action_edit() { $this->history = false; // Load area $area_id = (int) $this->request->param('id'); if ($area_id) { $area = Model_Forum_Area::factory($area_id); if (!$area->loaded()) { throw new Model_Exception($area, $area_id); } Permission::required($area, Model_Forum_Area::PERMISSION_UPDATE, self::$user); } else { $area = new Model_Forum_Area(); $area->author_id = self::$user->id; $area->created = time(); } // Load group if ($area->loaded()) { $group = $area->group(); } else { if ($group_id = (int) $this->request->param('group_id')) { $group = Model_Forum_Group::factory($group_id); $area->forum_group_id = $group->id; if (!$group->loaded()) { throw new Model_Exception($group, $group_id); } Permission::required($group, Model_Forum_Group::PERMISSION_CREATE_AREA, self::$user); } } // Handle post $errors = array(); if ($_POST) { $area->set_fields(Arr::extract($_POST, Model_Forum_Area::$editable_fields)); try { $area->save(); $this->request->redirect(Route::model($area)); } catch (Validation_Exception $e) { $errors = $e->array->errors('validate'); } } // Build page $this->view = new View_Page(__('Forum area') . ($area->name ? ': ' . HTML::chars($area->name) : '')); $this->view->tab = 'areas'; // Set actions if ($area->loaded() && Permission::has($area, Model_Forum_Area::PERMISSION_DELETE, self::$user)) { $this->view->actions[] = array('link' => Route::model($area, 'delete'), 'text' => '<i class="icon-trash icon-white"></i> ' . __('Delete area'), 'class' => 'btn btn-danger area-delete'); } $this->view->add(View_Page::COLUMN_MAIN, $this->section_edit($area, $errors)); }
public function catUpdate($id, $data = array()) { $data = Arr::extract($data, array('name', 'keywords', 'description')); $vData = $data; $validation = Validation::factory($vData); $validation->rule('name', 'not_empty'); $validation->rule('name', 'min_length', array(':value', '3')); $validation->rule('name', 'max_length', array(':value', '250')); if (!$validation->check()) { $this->errors = $validation->errors('catErrors'); return FALSE; } $result = DB::update($this->tableName)->set(array('name' => $data['name'], 'keywords' => $data['keywords'], 'description' => $data['description']))->where('id', '=', $id)->execute(); return TRUE; }
public function extract($object, $fields = NULL) { if (is_object($object) and method_exists($object, 'as_array')) { $object = $object->as_array(); } if ($fields === NULL) { $this->json = $object + $this->json; } else { if (is_string($fields)) { $fields = array_slice(func_get_args(), 1); } $this->json = Arr::extract($object, $fields) + $this->json; } return $this; }
public function params($params = NULL) { if ($params === NULL) { return Arr::extract($this->params, self::$available_params); } $params = (array) $params; if (isset($params[0])) { $params = Arr::merge($this->column_params_for($params[0]), array_slice($params, 1)); } if ($illigal = array_diff(array_keys($params), self::$available_params)) { throw new Migration_Driver_Exception_Params($illigal); } $this->params = $params; return $this; }