Пример #1
0
 public function create()
 {
     if ($post = $this->input->post()) {
         $form = new Validation($post);
         $form->add_rules('title', 'required');
         $form->add_rules('introduction', 'required');
         if ($form->validate()) {
             $island = ORM::factory('island');
             $island->user_id = Auth::instance()->get_user()->id;
             $island->title = $post['title'];
             $island->introduction = $post['introduction'];
             $now = date('Y-m-d H:i:s');
             $island->created = $now;
             $island->modified = $now;
             $island->save();
             if ($island->saved) {
                 $this->session->set_flash('notice', 'Created new island!');
                 url::redirect('/sail/' . $island->code);
             } else {
                 $this->session->set_flash('error', 'Failed to create new island!');
             }
         } else {
             var_dump($form->errors());
             die;
             $this->session->set_flash('error', 'Error validating.');
         }
     }
 }
Пример #2
0
 private function _get_frm_valid()
 {
     $form = array('txt_name' => '', 'txt_phone' => '', 'txt_fax' => '', 'txt_email' => '', 'txt_address' => '', 'txt_city' => '', 'txt_zipcode' => '', 'txt_contact' => '', 'txt_state' => '', 'txt_slogan' => '', 'txt_title' => '', 'txt_keyword' => '', 'txt_description' => '', 'txt_per_test' => '', 'txt_width' => '', 'txt_height' => '', 'rdo_enable_cart' => '', 'attach_logo' => '');
     $errors = $form;
     if ($_POST) {
         $post = new Validation(array_merge($_POST, $_FILES));
         if (!empty($_FILES['attach_logo']['name'])) {
             $post->add_rules('attach_logo', 'upload::type[gif,jpg,png,jpeg]', 'upload::size[2M]');
         }
         $post->pre_filter('trim', TRUE);
         $post->add_rules('txt_name', 'required');
         $post->add_rules('txt_phone', 'required');
         //$post->add_rules('txt_fax','phone[7,10,11,14]');
         $post->add_rules('txt_email', 'required', 'email');
         $post->pre_filter('trim', TRUE);
         $post->add_rules('txt_width', 'digit');
         $post->add_rules('txt_height', 'digit');
         $post->add_rules('txt_per_test', 'digit');
         if ($post->validate()) {
             $form = arr::overwrite($form, $post->as_array());
             return $form;
         } else {
             $errors = arr::overwrite($errors, $post->errors('site_validation'));
             $str_error = '';
             foreach ($errors as $id => $name) {
                 if ($name) {
                     $str_error .= $name . '<br>';
                 }
             }
             $this->session->set_flash('error_msg', $str_error);
         }
     }
     url::redirect('admin_config');
     die;
 }
Пример #3
0
 public function login()
 {
     $form = $errors = array("user" => "", "password" => "");
     $post = new Validation($_POST);
     $post->add_rules("user", "required");
     $post->add_rules("password", "required");
     if ($valid = $post->validate()) {
         try {
             $token = G3Remote::instance()->get_access_token($post["user"], $post["password"]);
             Session::instance()->set("g3_client_access_token", $token);
             $response = G3Remote::instance()->get_resource("gallery");
             $valid = true;
             $content = $this->_get_main_view($response->resource);
         } catch (Exception $e) {
             Kohana_Log::add("error", Kohana_Exception::text($e));
             $valid = false;
         }
     }
     if (!$valid) {
         $content = new View('login.html');
         $content->form = arr::overwrite($form, $post->as_array());
         $content->errors = arr::overwrite($errors, $post->errors());
     }
     $this->auto_render = false;
     print json_encode(array("status" => $valid ? "ok" : "error", "content" => (string) $content));
 }
Пример #4
0
 public function edit()
 {
     if (isset($_POST['save'])) {
         $post = new Validation(array_merge($_POST, $_FILES));
         //********  TO DO: trim for shipping info     **************/
         $post->pre_filter('trim', 'msg_text1', 'designpath', 'img_approved');
         $post->add_rules('msg_text1', 'required');
         $post->add_rules('designpath', 'required', 'numeric');
         $post->add_rules('img_approved', 'numeric');
         if (!$post->validate()) {
             $errors = $post->errors('form_errors');
             foreach ($errors as $error) {
                 echo '<p class="error">' . $error . '</p>';
             }
         } else {
             $id = $this->uri->segment(3);
             $basket = ORM::factory('orders_basket')->find($id);
             $basket->msg_text1 = $post->msg_text1;
             $basket->designpath = $post->designpath;
             $basket->img_approved = $post->img_approved;
             $basket->save();
             /*************** TO DO: delete more than one category ****************/
         }
     }
     $this->_renderView();
 }
Пример #5
0
 private function _get_record()
 {
     $form = array('txt_name' => '', 'txt_email' => '', 'txt_phone' => '', 'txt_subject' => '', 'txt_content' => '', 'txt_code' => '', 'txt_last_name' => '', 'txt_first_name' => '', 'txt_company' => '');
     $errors = $form;
     if ($_POST) {
         $post = new Validation($_POST);
         $post->pre_filter('trim', TRUE);
         $post->add_rules('txt_name', 'required');
         $post->add_rules('txt_email', 'required', 'email');
         $post->add_rules('txt_subject', 'required');
         $post->add_rules('txt_content', 'required');
         //$post->add_rules('txt_code','required');
         //$post->add_callbacks('txt_random',array($this,'_check_security_code'));
         //$post->add_rules('sel_send','trim');
         if ($post->validate()) {
             $form = arr::overwrite($form, $post->as_array());
             return $form;
         } else {
             $form = arr::overwrite($form, $post->as_array());
             // Retrieve input data
             $this->session->set_flash('input_data', $form);
             // Set input data in session
             $errors = arr::overwrite($errors, $post->errors('contact_validation'));
             $error_msg = '';
             foreach ($errors as $id => $name) {
                 if ($name) {
                     $error_msg .= '<br>' . $name;
                 }
             }
             $this->session->set_flash('error_msg', $error_msg);
             url::redirect('contact');
             die;
         }
     }
 }
Пример #6
0
 private function _get_record_aut_config()
 {
     $form = array('txt_aut_api_login' => '', 'txt_aut_transaction_key' => '', 'sel_aut_post_url' => '');
     $errors = $form;
     if ($_POST) {
         $post = new Validation($_POST);
         $post->pre_filter('trim', TRUE);
         $post->add_rules('txt_aut_api_login', 'trim', 'required');
         $post->add_rules('txt_aut_transaction_key', 'trim', 'required');
         $post->add_rules('sel_aut_post_url', 'trim', 'required');
         $form = arr::overwrite($form, $post->as_array());
         $form = $this->_set_form_aut_config($form);
         if ($post->validate()) {
             return $form;
         } else {
             $this->session->set_flash('frm_aut', $form);
             $errors = arr::overwrite($errors, $post->errors('authorizenet_config_validation'));
             $str_error = '';
             foreach ($errors as $id => $name) {
                 if ($name) {
                     $str_error .= '<br>' . $name;
                 }
             }
             $this->session->set_flash('error_msg', $str_error);
             url::redirect('admin_payment_method');
             die;
         }
     }
 }
Пример #7
0
 public function create()
 {
     $this->template->content = new View('users/create');
     $form = new Validation($_POST);
     $form->pre_filter('trim', true);
     $form->add_rules('username', 'required')->add_rules('password', 'required')->add_rules('email', 'required', 'valid::email');
     $this->template->content->repopulate = $form;
     if ($form->validate()) {
         // Create new user
         $user = new User_Model();
         if (!$user->username_exists($this->input->post('username'))) {
             foreach ($form->as_array() as $key => $val) {
                 // Set user data
                 $user->{$key} = $val;
             }
             if ($user->validate($form->as_array())) {
                 if ($user->add(ORM::factory('role', 'login')) and $user->save()) {
                     // Redirect to the login page
                     url::redirect('login');
                 }
             }
         }
     }
     // Error
     $this->template->content->error = $form->errors('login');
 }
Пример #8
0
 private function pricing()
 {
     $this->shell->meta = 'Plans and pricing for testimonial and review layouts and templates for your website';
     $this->shell->content = new View('marketing/testimonials/start');
     $this->shell->title = 'Plans and Pricing';
     if (empty($_POST)) {
         die($this->shell);
     }
     # handle the POST.
     $this->shell->content->values = $_POST;
     $post = new Validation($_POST);
     $post->pre_filter('trim');
     $post->add_rules('email', 'required', 'valid::email');
     $post->add_rules('password', 'required', 'matches[password2]', 'valid::alpha_dash');
     if (!$post->validate()) {
         $this->shell->content->errors = $post->errors();
         die($this->shell);
     }
     $new_owner = ORM::factory('owner');
     # unique email.
     if (!$new_owner->email_available($_POST['email'])) {
         $this->shell->content->errors = 'Email Already Exists!';
         die($this->shell);
     }
     $new_owner->email = $_POST['email'];
     $new_owner->password = $_POST['password'];
     $new_owner->save();
     # log the user in and take to admin
     $this->auth->force_login($new_owner);
     url::redirect('/admin/login');
 }
Пример #9
0
 public function handler()
 {
     access::verify_csrf();
     $form = $this->_get_form();
     $errors = array_fill_keys(array_keys($form), "");
     if ($_POST) {
         $post = new Validation($_POST);
         $post->add_rules("updates_enabled", array("valid", "numeric"));
         $post->add_rules("popular_enabled", array("valid", "numeric"));
         $post->add_rules("updates_limit", array("valid", "numeric"));
         $post->add_rules("popular_limit", array("valid", "numeric"));
         $post->add_rules("updates_description", "length[0,2048]");
         $post->add_rules("popular_description", "length[0,2048]");
         if ($post->validate()) {
             foreach (array("updates", "popular") as $album) {
                 $album_defn = unserialize(module::get_var("dynamic", $album));
                 $album_defn->enabled = $post["{$album}_enabled"];
                 $album_defn->description = $post["{$album}_description"];
                 $album_defn->limit = $post["{$album}_limit"] === "" ? null : $post["{$album}_limit"];
                 module::set_var("dynamic", $album, serialize($album_defn));
             }
             message::success(t("Dynamic Albums Configured"));
             url::redirect("admin/dynamic");
         } else {
             $form = arr::overwrite($form, $post->as_array());
             $errors = arr::overwrite($errors, $post->errors());
         }
     }
     print $this->_get_view($form, $errors);
 }
Пример #10
0
 public function add()
 {
     $argumentarray = Router::$arguments;
     //$id = $argumentarray[0];
     if (isset($_POST['save'])) {
         $post = new Validation(array_merge($_POST, $_FILES));
         $post->pre_filter('trim', 'foilName', 'foilHexcode');
         $post->add_rules('foilName', 'required');
         $post->add_rules('foilHexcode', 'required');
         if (!$post->validate()) {
             $errors = $post->errors('form_errors');
             foreach ($errors as $error) {
                 echo '<p class="error">' . $error . '</p>';
             }
         } else {
             //$id = $argumentarray[0];
             $foils = new Foil_Color_Model();
             $foil = ORM::factory('foil_color');
             $foil->name = $post->foilName;
             $foil->hexcode = $post->foilHexcode;
             try {
                 $foil->save();
                 $foils = new Foil_Color_Model();
                 $id = $foils->getNextID();
                 url::redirect('/foils/edit/' . $foil->id);
             } catch (Exception $ex) {
                 echo 'There was an error adding this foil: ' . $ex->getMessage();
                 //url::redirect('/foils/');
             }
         }
     }
     $this->_renderView();
 }
Пример #11
0
 private function post_review($page_name, $review_id)
 {
     # validate the form values.
     $post = new Validation($_POST);
     $post->pre_filter('trim');
     $post->add_rules('body', 'required');
     $post->add_rules('name', 'required');
     $post->add_rules('email', 'required');
     # on error
     if (!$post->validate()) {
         $view = new View('public_review/reviews/add_form');
         $view->page_name = $page_name;
         $view->errors = $post->errors();
         $view->values = $_POST;
         return $view;
     }
     # on success
     $new_item = ORM::factory('review_item');
     $new_item->review_id = $review_id;
     $new_item->fk_site = $this->site_id;
     $new_item->body = $_POST['body'];
     $new_item->rating = $_POST['rating'];
     $new_item->name = $_POST['name'];
     $new_item->save();
     $view = new View('public_review/reviews/status');
     $view->success = true;
     return $view;
 }
Пример #12
0
 private function _get_frm_valid()
 {
     $hd_id = $this->input->post('hd_id');
     $form = $this->data_template_model->get_frm();
     $errors = $form;
     if ($_POST) {
         $post = new Validation($_POST);
         $post->pre_filter('trim', TRUE);
         $post->add_rules('txt_name', 'required', 'length[1,200]');
         $post->add_rules('txt_content', 'required');
         if ($post->validate()) {
             $form = arr::overwrite($form, $post->as_array());
             return $form;
         } else {
             $form = arr::overwrite($form, $post->as_array());
             $errors = arr::overwrite($errors, $post->errors('account_validation'));
             $str_error = '';
             foreach ($errors as $id => $name) {
                 if ($name) {
                     $str_error .= $name . '<br>';
                 }
             }
             $this->session->set_flash('error_msg', $str_error);
             if ($hd_id) {
                 url::redirect('admin_emailtemplate/edit/' . $hd_id);
             }
             die;
         }
     }
 }
Пример #13
0
 public function action_show()
 {
     $arr = [];
     //Получаем данные из формы
     if (isset($_POST['submit'])) {
         //Проверяем введенные данные на корректность
         $post = new Validation($_POST);
         $post->rule('prime', 'not_empty')->rule('prime', 'numeric');
         if ($post->check()) {
             $max = $_POST['prime'];
             $arr = Controller_PrimeNumber::getPrime($max);
             Controller_DataArchive::saveDB($max, $arr);
         } else {
             $errors = $post->errors('comments');
         }
     }
     //Подготавливаем данные для вида
     $view = View::factory('index');
     if (isset($errors)) {
         $view->err = $errors;
     } else {
         if (!empty($arr)) {
             $view->arr = $arr;
         }
     }
     $this->response->body($view);
 }
Пример #14
0
 public function action_edit_field()
 {
     $field_id = $this->request->param('options');
     xml::to_XML(array('field' => array('@id' => $field_id, '$content' => User::get_data_field_name($field_id))), $this->xml_content);
     if (count($_POST) && isset($_POST['field_name'])) {
         $post = new Validation($_POST);
         $post->filter('trim');
         $post->rule('Valid::not_empty', 'field_name');
         if ($post->validate()) {
             $post_values = $post->as_array();
             if ($post_values['field_name'] != User::get_data_field_name($field_id) && !User::field_name_available($post_values['field_name'])) {
                 $post->add_error('field_name', 'User::field_name_available');
             }
         }
         // Retry
         if ($post->validate()) {
             $post_values = $post->as_array();
             User::update_field($field_id, $post_values['field_name']);
             $this->add_message('Field ' . $post_values['field_name'] . ' updated');
             $this->set_formdata(array('field_name' => $post_values['field_name']));
         } else {
             $this->add_error('Fix errors and try again');
             $this->add_form_errors($post->errors());
             $this->set_formdata(array_intersect_key($post->as_array(), $_POST));
         }
     } else {
         $this->set_formdata(array('field_name' => User::get_data_field_name($field_id)));
     }
 }
Пример #15
0
 public function add()
 {
     if (isset($_POST['save'])) {
         $post = new Validation(array_merge($_POST, $_FILES));
         $post->pre_filter('trim', 'typeName', 'typeDescription', 'typeShortDescription', 'metaTitle', 'metaDescription', 'metaKeywords');
         $post->add_rules('typeName', 'required');
         if (!$post->validate()) {
             $errors = $post->errors('form_errors');
             foreach ($errors as $error) {
                 echo '<p class="error">' . $error . '</p>';
             }
         } else {
             $id = $this->uri->segment(3);
             $type = ORM::factory('products_type')->find($id);
             $type->name = $post->typeName;
             $type->category_id = $post->category;
             $type_desc = ORM::factory('products_types_description')->where('id', $type->products_types_description_id)->find();
             $type_desc->short_description = $post->typeShortDescription;
             $type_desc->description = $post->typeDescription;
             $type_desc->meta_title = $post->metaTitle;
             $type_desc->meta_description = $post->metaDescription;
             $type_desc->meta_keywords = $post->metaKeywords;
             $type_desc->title_url = $post->metaUrl;
             $type_desc->image_alt = $post->image_alt;
             $type_desc->video = $post->video;
             if (!empty($_FILES['image']['name'])) {
                 // uses Kohana upload helper
                 $_FILES = Validation::factory($_FILES)->add_rules('image', 'upload::valid', 'upload::type[gif,jpg,jpeg,png]', 'upload::size[2M]');
                 if ($_FILES->validate()) {
                     // Temporary file name
                     $filename = upload::save('image', basename($_FILES['image']['tmp_name']));
                     $file = basename($_FILES['image']['name']);
                     // Resize, sharpen, and save the image
                     Image::factory($filename)->save(DOCROOT . '../../env/product_type_images/' . $file);
                     // Remove the temporary file
                     unlink($filename);
                     $type_desc->image = $file;
                     $type_desc->save();
                 } else {
                     $errors = $_FILES->errors('form_user');
                 }
             }
             $type_desc->save();
             $type->products_types_description_id = $type_desc->id;
             $type->save();
             if (!empty($post->productTypeSites)) {
                 foreach ($post->productTypeSites as $site_id) {
                     $sc = ORM::factory('sites_types')->where('products_type_id', $type->id)->where('site_id', $site_id)->find();
                     if ($sc->id == 0) {
                         $sc->products_type_id = $type->id;
                         $sc->site_id = $site_id;
                         $sc->save();
                     }
                 }
             }
             url::redirect(url::base() . $this->uri->segment(1) . '/' . $this->uri->segment(2) . '/' . $type->id);
         }
     }
     $this->_renderView();
 }
Пример #16
0
 private function _get_frm_valid()
 {
     $rdo_type = 'image';
     $file_ext = 'jpg,jpeg,gif,png';
     $form = array('hd_id' => '', 'attach_image' => '', 'txt_width' => '', 'txt_height' => '', 'sel_status' => '');
     $errors = $form;
     if ($_POST) {
         $post = new Validation(array_merge($_FILES, $_POST));
         $post->add_rules('attach_' . $rdo_type, 'upload::type[' . $file_ext . ']', 'upload::size[10M]');
         $post->add_rules('txt_width', 'digit');
         $post->add_rules('txt_height', 'digit');
         if ($post->validate()) {
             $form = arr::overwrite($form, $post->as_array());
             return $form;
         } else {
             $errors = $post->errors('banner_validation');
             $str_error = '';
             foreach ($errors as $id => $name) {
                 if ($name) {
                     $str_error .= $name . '<br>';
                 }
             }
             $this->session->set_flash('error_msg', $str_error);
             url::redirect($this->site['history']['current']);
             die;
         }
     }
 }
Пример #17
0
 public function activate()
 {
     access::verify_csrf();
     $post = new Validation($_POST);
     $post->add_rules("activate_users", "required");
     $post->add_rules("activate", "alpha_numeric");
     if ($post->validate()) {
         $names = array();
         if (!empty($post->activate)) {
             foreach ($post->activate as $id) {
                 $user = register::create_new_user($id);
                 $names[] = $user->name;
             }
             message::success(t("Activated %users.", array("users" => implode(", ", $names))));
         }
         $count = ORM::factory("pending_user")->where("state", "!=", 2)->count_all();
         if ($count == 0) {
             site_status::clear("pending_user_registrations");
         }
         url::redirect("admin/register");
     }
     list($form, $errors) = $this->_get_form();
     $form = array_merge($form, $post->as_array());
     $errors = array_merge($errors, $post->errors());
     print $this->_get_admin_view($form, $errors);
 }
Пример #18
0
 public function index()
 {
     $this->template->content = new View('admin/flickrwijit_form');
     // setup and initialize form field names
     $form = array('flickr_tag' => '', 'flickr_id' => '', 'num_of_photos' => '', 'image_width' => '', 'image_height' => '', 'block_position' => '', 'enable_cache' => '', 'block_no_photos' => '');
     //  Copy the form as errors, so the errors will be stored with keys
     //  corresponding to the form field names
     $errors = $form;
     $form_error = FALSE;
     $form_saved = FALSE;
     // check, has the form been submitted, if so, setup validation
     if ($_POST) {
         // Instantiate Validation, use $post, so we don't overwrite $_POST
         // fields with our own things
         $post = new Validation($_POST);
         // Add some filters
         $post->pre_filter('trim', TRUE);
         $post->add_rules('flickr_tag', 'required', 'length[0,500]');
         $post->add_rules('flickr_id', 'length[0,20]');
         $post->add_rules('num_of_photos', 'numeric');
         $post->add_rules('image_width', 'length[2,600]', 'numeric');
         $post->add_rules('image_height', 'required', 'length[2,600]', 'numeric');
         $post->add_rules('block_position', 'length[1,6]', 'numeric');
         $post->add_rules('enable_cache', 'between[0,1]', 'numeric');
         $post->add_rules('block_no_photos', 'between[4,10]', 'numeric');
         // passed validation test.
         if ($post->validate()) {
             $flickrwijit_settings = new Flickrwijit_Model(1);
             $flickrwijit_settings->flickr_tag = $post->flickr_tag;
             $flickrwijit_settings->flickr_id = $post->flickr_id;
             $flickrwijit_settings->num_of_photos = $post->num_of_photos;
             $flickrwijit_settings->image_height = $post->image_height;
             $flickrwijit_settings->image_width = $post->image_width;
             $flickrwijit_settings->block_position = $post->block_position;
             $flickrwijit_settings->enable_cache = $post->enable_cache;
             $flickrwijit_settings->block_no_photos = $post->block_no_photos;
             $flickrwijit_settings->save();
             // Delete Settings Cache
             // $this->cache->delete('settings');
             // $this->cache->delete_tag('settings');
             // Everything is A-Okay!
             $form_saved = TRUE;
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
         } else {
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
             // populate the error fields, if any
             $errors = arr::overwrite($errors, $post->errors('flickrwijit'));
             $form_error = TRUE;
         }
     } else {
         $flickrwijit_settings = ORM::factory('flickrwijit', 1);
         $form = array('flickr_tag' => $flickrwijit_settings->flickr_tag, 'flickr_id' => $flickrwijit_settings->flickr_id, 'num_of_photos' => $flickrwijit_settings->num_of_photos, 'image_width' => $flickrwijit_settings->image_width, 'image_height' => $flickrwijit_settings->image_height, 'block_position' => $flickrwijit_settings->block_position, 'enable_cache' => $flickrwijit_settings->enable_cache, 'block_no_photos' => $flickrwijit_settings->block_no_photos);
     }
     $this->template->content->form = $form;
     $this->template->content->errors = $errors;
     $this->template->content->form_error = $form_error;
     $this->template->content->form_saved = $form_saved;
 }
Пример #19
0
 /**
  * Show latest PER_PAGE news on page
  * @return void
  */
 public function index($module = NULL, $page = 1)
 {
     $this->set_title(Kohana::lang('search.search'));
     if ($page == 1) {
         $this->add_breadcrumb(Kohana::lang('search.the_best_results'), url::current());
     } else {
         $this->add_breadcrumb(Kohana::lang('search.page_no') . ' ' . $page, url::current());
     }
     // Default values
     $form = array('value' => '');
     $errors = array();
     if ($_POST) {
         $post = new Validation($_POST);
         // Some filters
         $post->pre_filter('trim', TRUE);
         // Rules
         $post->add_rules('value', 'required');
         if ($post->validate()) {
             $form = arr::overwrite($form, $post->as_array());
         } else {
             // Repopulate form with error and original values
             $form = arr::overwrite($form, $post->as_array());
             $errors = $post->errors('search_errors');
         }
     }
     $this->template->content = new View('search');
     $data = $this->products->search($post['value']);
     $data2 = $this->page->search($post['value']);
     $data3 = $this->news->search($post['value']);
     $this->template->content->data = $data;
     $this->template->content->data2 = $data2;
     $this->template->content->data3 = $data3;
     $this->template->content->form = $form;
     $this->template->content->errors = $errors;
 }
Пример #20
0
 public function add()
 {
     $form = array('building_id' => '', 'name' => '', 'index' => '', 'img_uri' => '', 'active' => '');
     $errors = $form;
     if ($_POST) {
         $post = new Validation($_POST);
         $post->pre_filter('trim', true);
         $post->add_rules('buildings_id', 'required', 'digit');
         $post->add_rules('name', 'required');
         $post->add_rules('index', 'required');
         $post->add_rules('img_uri', 'required');
         $post->add_rules('active', 'required');
         if ($post->validate()) {
             // check for invilid
             $form = arr::overwrite($form, $post->as_array());
             $people = new Person_Model();
             $result = $people->save($this->input->get('person'), $person_id);
         } else {
             $form = arr::overwrite($form, $post->as_array());
             client::validation_results(arr::overwrite($errors, $post->errors('hiring_employee_form_validations')));
             client::messageSend("There were errors in some fields", E_USER_WARNING);
         }
     }
     $building = new Building_Model();
     $buildings_list = $building->select_list();
     $this->template->title = 'Seating::Spaces::Add';
     $this->template->content = new View('pages/spaces_add');
     $this->template->content->form = $form;
     $this->template->content->buildings_list = $buildings_list;
 }
Пример #21
0
 private function _get_valid_accinfo($old_pass)
 {
     $form = array('txt_old_pass' => '', 'txt_new_pass' => '', 'txt_cf_new_pass' => '', 'txt_email' => '');
     $errors = $form;
     if ($_POST) {
         $post = new Validation($_POST);
         $post->pre_filter('trim', TRUE);
         if (!empty($old_pass)) {
             $post->add_rules('txt_new_pass', 'required', 'length[6,50]');
             $post->add_rules('txt_cf_new_pass', 'matches[txt_new_pass]');
             $post->add_callbacks('txt_old_pass', array($this, '_check_old_pass'));
         }
         $post->add_rules('txt_email', 'required', 'email');
         $post->add_callbacks('txt_email', array($this, '_check_email'));
         if ($post->validate()) {
             $form = arr::overwrite($form, $post->as_array());
             return $form;
         } else {
             $form = arr::overwrite($form, $post->as_array());
             $this->session->set_flash('input_data', $form);
             $errors = arr::overwrite($errors, $post->errors('account_validation'));
             $str_error = '';
             foreach ($errors as $id => $name) {
                 if ($name) {
                     $str_error .= $name . '<br>';
                 }
             }
             $this->session->set_flash('error_msg', $str_error);
             url::redirect($this->uri->segment(1));
             die;
         }
     }
 }
Пример #22
0
 public function validate(CM_Form_Abstract $form)
 {
     $values = array();
     foreach ($form->get_values() as $name => $value) {
         $values[$name] = $value->get_raw();
         $this->_validation->label($name, $form->get_field($name)->get_label());
     }
     // Validation только read-only, поэтому создаем новый объект
     $this->_validation = $this->_validation->copy($values);
     if ($this->_validation->check()) {
         return TRUE;
     }
     foreach ($this->_validation->errors('validation') as $name => $error) {
         $form->set_error($name, $error);
     }
     return FALSE;
 }
Пример #23
0
 function index()
 {
     $this->template->content = new View('admin/settings/externalapps/main');
     $this->template->content->title = Kohana::lang('ui_admin.settings');
     // setup and initialize form field names
     $form = array('id' => '', 'name' => '', 'url' => '');
     //	Copy the form as errors, so the errors will be stored with keys
     //	corresponding to the form field names
     $errors = $form;
     $form_error = FALSE;
     $form_saved = FALSE;
     // check, has the form been submitted, if so, setup validation
     if ($_POST) {
         // Instantiate Validation, use $post, so we don't overwrite $_POST
         // fields with our own things
         $post = new Validation($_POST);
         // Add some filters
         $post->pre_filter('trim', TRUE);
         // Add some rules, the input field, followed by a list of checks, carried out in order
         $post->add_rules('name', 'length[1,255]');
         $post->add_rules('url', 'length[1,255]');
         // Test to see if things passed the rule checks
         if ($post->validate()) {
             // TODO: Save External App Here
             if ($post->action == 'a') {
                 $app = new Externalapp_Model();
                 $app->id = $post->id;
                 $app->name = $post->name;
                 $app->url = $post->url;
                 $app->save();
             } elseif ($post->action == 'd') {
                 $app = new Externalapp_Model($post->id);
                 $app->delete();
             }
             // Everything is A-Okay!
             $form_saved = TRUE;
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
         } else {
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
             // populate the error fields, if any
             $errors = arr::overwrite($errors, $post->errors('settings'));
             $form_error = TRUE;
         }
     }
     // Grab all of the external apps from the database
     $this->template->content->externalapps = ORM::factory('externalapp')->find_all();
     $this->template->content->total_items = count($this->template->content->externalapps);
     $this->template->content->form = $form;
     $this->template->content->errors = $errors;
     $this->template->content->form_error = $form_error;
     $this->template->content->form_saved = $form_saved;
     // Javascript Header
     $this->template->js = new View('admin/settings/externalapps/externalapps_js');
 }
Пример #24
0
 /**
  * Handles twitter Settings
  */
 function index()
 {
     $this->template->content = new View('admin/settings/twitter/main');
     $this->template->content->title = Kohana::lang('ui_admin.settings');
     // setup and initialize form field names
     $form = array('twitter_api_key' => '', 'twitter_api_key_secret' => '', 'twitter_token' => '', 'twitter_token_secret' => '', 'twitter_hashtags' => '');
     //	Copy the form as errors, so the errors will be stored with keys
     //	corresponding to the form field names
     $errors = $form;
     $form_error = FALSE;
     $form_saved = FALSE;
     // check, has the form been submitted, if so, setup validation
     if ($_POST) {
         // Instantiate Validation, use $post, so we don't overwrite $_POST
         // fields with our own things
         $post = new Validation($_POST);
         // Add some filters
         $post->pre_filter('trim', TRUE);
         // Add some rules, the input field, followed by a list of checks, carried out in order
         $post->add_rules('twitter_api_key', 'required', 'length[1,150]');
         $post->add_rules('twitter_api_key_secret', 'required', 'length[1,150]');
         $post->add_rules('twitter_token', 'required', 'length[1,150]');
         $post->add_rules('twitter_token_secret', 'required', 'length[1,150]');
         $post->add_rules('twitter_hashtags', 'length[1,150]');
         // Test to see if things passed the rule checks
         if ($post->validate()) {
             // Yes! everything is valid
             Settings_Model::save_setting('twitter_api_key', $post->twitter_api_key);
             Settings_Model::save_setting('twitter_api_key_secret', $post->twitter_api_key_secret);
             Settings_Model::save_setting('twitter_token', $post->twitter_token);
             Settings_Model::save_setting('twitter_token_secret', $post->twitter_token_secret);
             Settings_Model::save_setting('twitter_hashtags', $post->twitter_hashtags);
             // Delete Settings Cache
             $this->cache->delete('settings');
             $this->cache->delete_tag('settings');
             // Everything is A-Okay!
             $form_saved = TRUE;
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
         } else {
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
             // populate the error fields, if any
             $errors = arr::overwrite($errors, $post->errors('settings'));
             $form_error = TRUE;
         }
     } else {
         $form = array('twitter_api_key' => Settings_Model::get_setting('twitter_api_key'), 'twitter_api_key_secret' => Settings_Model::get_setting('twitter_api_key_secret'), 'twitter_token' => Settings_Model::get_setting('twitter_token'), 'twitter_token_secret' => Settings_Model::get_setting('twitter_token_secret'), 'twitter_hashtags' => Settings_Model::get_setting('twitter_hashtags'));
     }
     $this->template->content->form = $form;
     $this->template->content->errors = $errors;
     $this->template->content->form_error = $form_error;
     $this->template->content->form_saved = $form_saved;
     // Javascript Header
     $this->themes->js = new View('admin/settings/twitter/twitter_js');
 }
 public function index()
 {
     $this->template->this_page = 'addons';
     // Standard Settings View
     $this->template->content = new View("admin/plugins_settings");
     $this->template->content->title = "CrowdFlower Settings";
     // Settings Form View
     $this->template->content->settings_form = new View("crowdflower/admin/crowdflower_settings");
     // setup and initialize form field names
     $form = array('crowdflower_apikey' => '', 'crowdflower_jobid' => '');
     //	Copy the form as errors, so the errors will be stored with keys
     //  corresponding to the form field names
     $errors = $form;
     $form_error = FALSE;
     $form_saved = FALSE;
     // check, has the form been submitted, if so, setup validation
     if ($_POST) {
         // Instantiate Validation, use $post, so we don't overwrite $_POST
         // fields with our own things
         $post = new Validation($_POST);
         // Add some filters
         $post->pre_filter('trim', TRUE);
         // Add some rules, the input field, followed by a list of checks, carried out in order
         $post->add_rules('crowdflower_apikey', 'length[0,100]');
         $post->add_rules('crowdflower_jobid', 'length[0,100]');
         // Test to see if things passed the rule checks
         if ($post->validate()) {
             // Yes! everything is valid
             $settings = ORM::factory('crowdflower', 1);
             $settings->crowdflower_apikey = $post->crowdflower_apikey;
             $settings->crowdflower_jobid = $post->crowdflower_jobid;
             $settings->save();
             // Transform and roll out
             $form_saved = TRUE;
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
         } else {
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
             // populate the error fields, if any
             $errors = arr::overwrite($errors, $post->errors('crowdflower'));
             $form_error = TRUE;
         }
     } else {
         // Retrieve Current Settings
         $settings = ORM::factory('crowdflower', 1);
         $form = array('crowdflower_apikey' => $settings->crowdflower_apikey, 'crowdflower_jobid' => $settings->crowdflower_jobid);
     }
     // Pass the $form on to the settings_form variable in the view
     $this->template->content->settings_form->form = $form;
     // Other variables
     $this->template->content->errors = $errors;
     $this->template->content->form_error = $form_error;
     $this->template->content->form_saved = $form_saved;
 }
Пример #26
0
 public function handle()
 {
     //echo kohana::debug($this->fileds);
     //数据验证
     $validator = new Validation($this->fileds);
     $validator->pre_filter('trim');
     //$validator->add_rules('cardid', 'required');
     //$validator->add_rules('year_month', 'required');
     $validator->add_rules('money', 'required');
     //$validator->add_rules('name', 'required');
     //$validator->add_rules('idcard', 'required');
     //$validator->add_rules('cvv2', 'required');
     $validator->add_rules('submit_url', 'required');
     if (!$validator->validate()) {
         //错误输出,js层已经过滤,一般不会输出
         $validate_errors = $validator->errors();
         $errors = '';
         foreach ($validate_errors as $key => $val) {
             $errors .= $key . ' failed rule ' . $val . '<br>';
         }
         throw new PaymentException($errors, 400);
     }
     $motoClient = new MotoClient();
     $motoClient->setUrlMerchantTerminalAndKey($this->fileds['submit_url'], $this->fileds['merchantid'], $this->fileds['terminalid'], $this->fileds['key']);
     /*
     $red_ext = 'CUST_EMAIL='.$this->fileds['billing_email'].'~'.
                'CUST_FNAME='.$this->fileds['billing_firstname'].'~'.
                'CUST_LNAME='.$this->fileds['billing_lastname'].'~'.
                'CUST_ADDR1='.$this->fileds['billing_address'].'~'.
                'CUST_CITY='.$this->fileds['billing_city'].'~'.
                'CUST_CNTRY_CD='.$this->fileds['billing_country'].'~'.
                'EBT_USER_DATA18='.$this->fileds['billing_telephone'].'~'.
                'SHIP_FNAME='.$this->fileds['shipping_firstname'].'~'.
                'SHIP_LNAME='.$this->fileds['shipping_lastname'].'~'.
                'SHIP_ADDR1='.$this->fileds['shipping_address'].'~'.
                'SHIP_CITY='.$this->fileds['shipping_city'].'~'.
                'SHIP_CNTRY_CD='.$this->fileds['shipping_country'].'~'.
                'EBT_USER_DATA19=840~'.
                'EBT_USER_DATA13=web~'.
                'CUST_IP_ADDR='.$this->fileds['billing_ip_address'].'~'.
                'ITEM_SEQ[1]=1~'.
                'ITEM_DESC[1]='.$this->fileds['order_num'].'~'.
                'ITEM_CST_AMT[1]='.$this->fileds['money'].'~'.
                'ITEM_QTY[1]=1000';
     */
     //$result = $motoClient->authorize("", $this->fileds['cardid'], $this->fileds['year_month'], $this->fileds['money'], array ('name' => $this->fileds['name'], 'idcard' => $this->fileds['idcard'], 'cvv2' => $this->fileds['cvv2'], 'red_ext'=>$red_ext));
     $result = $motoClient->authorize("", $this->fileds['cardid'], $this->fileds['year_month'], $this->fileds['money'], array('name' => $this->fileds['name'], 'idcard' => $this->fileds['idcard'], 'cvv2' => $this->fileds['cvv2']));
     if (!empty($result['error']) && isset($this->error[$result['error']])) {
         $result['_error_en'] = $this->error[$result['error']];
     } else {
         $result['_error_en'] = 'unkown error';
     }
     return $result;
 }
Пример #27
0
 function index()
 {
     $this->template->content = new View('admin/themes');
     $this->template->content->title = 'Addons';
     // setup and initialize form field names
     $form = array('site_style' => '');
     //  Copy the form as errors, so the errors will be stored with keys
     //  corresponding to the form field names
     $errors = $form;
     $form_error = FALSE;
     $form_saved = FALSE;
     // check, has the form been submitted, if so, setup validation
     if ($_POST) {
         // Instantiate Validation, use $post, so we don't overwrite $_POST
         // fields with our own things
         $post = new Validation($_POST);
         // Add some filters
         $post->pre_filter('trim', TRUE);
         // Add some rules, the input field, followed by a list of checks, carried out in order
         $post->add_rules('site_style', 'length[1,50]');
         // Test to see if things passed the rule checks
         if ($post->validate()) {
             // Yes! everything is valid
             $settings = new Settings_Model(1);
             $settings->site_style = $post->site_style;
             $settings->save();
             //add details to application/config/email.php
             //$this->_add_email_settings($settings);
             // Delete Settings Cache
             $cache = Cache::instance();
             $cache->delete('settings');
             $cache->delete_tag('settings');
             // Everything is A-Okay!
             $form_saved = TRUE;
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
         } else {
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
             // populate the error fields, if any
             $errors = arr::overwrite($errors, $post->errors('settings'));
             $form_error = TRUE;
         }
     } else {
         // Retrieve Current Settings
         $settings = ORM::factory('settings', 1);
         $form = array('site_style' => $settings->site_style);
     }
     $this->template->content->form = $form;
     $this->template->content->errors = $errors;
     $this->template->content->form_error = $form_error;
     $this->template->content->form_saved = $form_saved;
     $this->template->content->themes = $this->_get_themes();
 }
Пример #28
0
 /**
  * Handles SMS Settings
  */
 function index()
 {
     $this->template->content = new View('admin/facebook');
     $this->template->content->title = Kohana::lang('ui_admin.settings');
     // setup and initialize form field names
     $form = array('facebook_appid' => '', 'facebook_appsecret' => '');
     //	Copy the form as errors, so the errors will be stored with keys
     //	corresponding to the form field names
     $errors = $form;
     $form_error = FALSE;
     $form_saved = FALSE;
     // check, has the form been submitted, if so, setup validation
     if ($_POST) {
         // Instantiate Validation, use $post, so we don't overwrite $_POST
         // fields with our own things
         $post = new Validation($_POST);
         // Add some filters
         $post->pre_filter('trim', TRUE);
         // Add some rules, the input field, followed by a list of checks, carried out in order
         $post->add_rules('facebook_appid', 'length[1,150]');
         $post->add_rules('facebook_appsecret', 'length[1,150]');
         // Test to see if things passed the rule checks
         if ($post->validate()) {
             // Yes! everything is valid
             $settings = new Settings_Model(1);
             $settings->facebook_appid = $post->facebook_appid;
             $settings->facebook_appsecret = $post->facebook_appsecret;
             $settings->date_modify = date("Y-m-d H:i:s", time());
             $settings->save();
             // Delete Settings Cache
             $this->cache->delete('settings');
             $this->cache->delete_tag('settings');
             // Everything is A-Okay!
             $form_saved = TRUE;
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
         } else {
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
             // populate the error fields, if any
             $errors = arr::overwrite($errors, $post->errors('settings'));
             $form_error = TRUE;
         }
     } else {
         // Retrieve Current Settings
         $settings = ORM::factory('settings', 1);
         $form = array('facebook_appid' => $settings->facebook_appid, 'facebook_appsecret' => $settings->facebook_appsecret);
     }
     $this->template->content->form = $form;
     $this->template->content->errors = $errors;
     $this->template->content->form_error = $form_error;
     $this->template->content->form_saved = $form_saved;
 }
Пример #29
0
 function index()
 {
     $this->template->content = new View('admin/addons/themes');
     $this->template->content->title = 'Addons';
     // setup and initialize form field names
     $form = array('site_style' => '');
     //  Copy the form as errors, so the errors will be stored with keys
     //  corresponding to the form field names
     $errors = $form;
     $form_error = FALSE;
     $form_saved = FALSE;
     // check, has the form been submitted, if so, setup validation
     if ($_POST) {
         // Instantiate Validation, use $post, so we don't overwrite $_POST
         // fields with our own things
         $post = new Validation($_POST);
         // Add some filters
         $post->pre_filter('trim', TRUE);
         // Add some rules, the input field, followed by a list of checks, carried out in order
         $post->add_rules('site_style', 'length[1,50]');
         // Test to see if things passed the rule checks
         if ($post->validate()) {
             // Yes! everything is valid
             Settings_Model::save_setting('site_style', $post->site_style);
             // Everything is A-Okay!
             $form_saved = TRUE;
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
         } else {
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
             // populate the error fields, if any
             $errors = arr::overwrite($errors, $post->errors('settings'));
             $form_error = TRUE;
         }
     } else {
         $site_style = Settings_Model::get_setting('site_style');
         // Retrieve Current Settings
         $form = array('site_style' => !empty($site_style) ? $site_style : 'default');
     }
     $this->template->content->form = $form;
     $this->template->content->errors = $errors;
     $this->template->content->form_error = $form_error;
     $this->template->content->form_saved = $form_saved;
     $themes = addon::get_addons('theme');
     foreach ($themes as $key => $theme) {
         // We want to hide checkin themes if checkins is not enabled
         if (!Kohana::config('settings.checkins') and $theme['Checkins'] == 1) {
             unset($themes[$key]);
         }
     }
     $this->template->content->themes = $themes;
 }
Пример #30
0
 public static function check($items = array())
 {
     $source = filter_input_array(INPUT_POST);
     $instance = new Validation();
     foreach ($items as $item => $rules) {
         $itemName = isset($rules['name']) ? $rules['name'] : 'No Name';
         foreach ($rules as $rule => $ruleValue) {
             $value = trim($source[$item]);
             if ($rule === 'required' && empty($value)) {
                 $instance->addError("{$itemName} is required");
             } else {
                 if (!empty($value)) {
                     switch ($rule) {
                         case 'min':
                             if (strlen($value) < $ruleValue) {
                                 $instance->addError("{$itemName} must be at least {$ruleValue} characters long");
                             }
                             break;
                         case 'max':
                             if (strlen($value) > $ruleValue) {
                                 $instance->addError("{$itemName} cannot be longer than {$ruleValue} characters");
                             }
                             break;
                         case 'matches':
                             if ($value != $source[$ruleValue]) {
                                 $instance->addError("{$ruleValue} must match {$item} ");
                             }
                             break;
                         case 'unique':
                             $check = $instance->_db->get($ruleValue, array($item, '=', $value));
                             if ($check->count()) {
                                 $instance->addError("{$itemName} must be unique");
                             }
                             break;
                         case 'phone':
                             break;
                         case 'email':
                             break;
                         case 'website':
                             $preg = "/^(https?:\\/\\/)([\\da-z\\.-]+)\\.([a-z\\.]{2,6})(\\/([\\da-z\\.-]+))*\\/?(([\\w\\.-]+)\\.([\\da-z]{2,6}))?((\\#[\\w\\.-]+)|(\\?([\\da-z]+(=[\\da-z]+)?)(&([\\da-z]+(=[\\da-z]+)?))*))?/i";
                             if (!preg_match($preg, $value)) {
                                 $instance->addError("{$itemName} must be  a valid website");
                             }
                     }
                 }
             }
         }
     }
     if (empty($instance->errors())) {
         $instance->confirm();
     }
     return $instance;
 }