public function validate(Validation $array, $save = FALSE)
 {
     $array->pre_filter('trim');
     $array->add_rules('taxon_group_id', 'required');
     $array->add_rules('taxon_list_id', 'required');
     return parent::validate($array, $save);
 }
Example #2
0
 private function _get_register_valid()
 {
     $form = array('txt_email' => '', 'txt_password' => '', 'txt_cfpass' => '', 'txt_email' => '', 'txt_random' => '', 'txt_fname' => '', 'txt_lname' => '', 'txt_cpname' => '', 'txt_spname' => '', 'txt_spemail' => '');
     $errors = $form;
     if ($_POST) {
         $post = new Validation($_POST);
         $post->pre_filter('trim', TRUE);
         $post->add_rules('txt_password', 'required', 'length[1,50]');
         $post->add_rules('txt_cfpass', 'required', 'matches[txt_password]');
         $post->add_rules('txt_email', 'required', 'email');
         $post->add_rules('txt_random', 'required');
         $post->add_callbacks('txt_email', array($this, '_check_email'));
         //$post->add_callbacks('txt_random',array($this,'_check_security_code'));
         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('register_validation'));
             $str_error = '';
             foreach ($errors as $id => $name) {
                 if ($name) {
                     $str_error .= $name . '<br>';
                 }
             }
             $this->session->set_flash('error_msg', $str_error);
             url::redirect('register');
             die;
         }
     }
 }
Example #3
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;
 }
Example #4
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.');
         }
     }
 }
Example #5
0
 public function validate(Validation $array, $save = FALSE)
 {
     // uses PHP trim() to remove whitespace from beginning and end of all fields before validation
     $array->pre_filter('trim');
     // merge unvalidated fields, in case the subclass has set any.
     if (!isset($this->unvalidatedFields)) {
         $this->unvalidatedFields = array();
     }
     $this->unvalidatedFields = array_merge($this->unvalidatedFields, array('validation_rules', 'public', 'multi_value', 'deleted'));
     $array->add_rules('caption', 'required');
     $array->add_rules('data_type', 'required');
     if (array_key_exists('data_type', $array->as_array()) && $array['data_type'] == 'L') {
         if (empty($array['termlist_id'])) {
             $array->add_rules('termlist_id', 'required');
         } else {
             array_push($this->unvalidatedFields, 'termlist_id');
         }
     }
     $array->add_rules('system_function', 'length[1,30]');
     $parent_valid = parent::validate($array, $save);
     // clean up cached required fields in case validation rules have changed
     $cache = Cache::instance();
     $cache->delete_tag('required-fields');
     if ($save && $parent_valid) {
         // clear the cache used for attribute datatype and validation rules since the attribute has changed
         $cache = new Cache();
         // Type is the object name with _attribute stripped from the end
         $type = substr($this->object_name, 0, strlen($this->object_name) - 10);
         $cache->delete('attrInfo_' . $type . '_' . $this->id);
     }
     return $save && $parent_valid;
 }
Example #6
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;
 }
 public function validation_settings(Validation $v)
 {
     // Rules
     $v->add_rules('good_id', 'required', 'numeric', 'length[30]', array($v, 'unique_ids'));
     $v->add_rules('bad_id', 'required', 'numeric', 'length[30]', array($v, 'unique_ids'));
     // Errors
 }
Example #8
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();
 }
Example #9
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));
 }
 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);
 }
Example #11
0
 private function form_handler($page_name, $newsletter)
 {
     $view = new View('public_newsletter/newsletters/form');
     $view->page_name = $page_name;
     $values = array('name' => '', 'email' => '');
     $view->values = $values;
     if ($_POST) {
         $post = new Validation($_POST);
         $post->pre_filter('trim');
         $post->add_rules('name', 'required');
         $post->add_rules('email', 'required', 'valid::email');
         if (!$post->validate()) {
             $view->errors = arr::overwrite($values, $post->errors('form_error_messages'));
             $view->values = arr::overwrite($values, $post->as_array());
             return $view;
         }
         include Kohana::find_file('vendor', 'CMBase');
         $cm = new CampaignMonitor(null, null, $newsletter->cm_list_id);
         $result = $cm->subscriberAdd($_POST['email'], $_POST['name']);
         if ($result['Result']['Code'] != 0) {
             kohana::log('error', $result['Result']['Message']);
             return 'There was an error adding you to the emailing list. Please try again later.';
         }
         return 'Thank you! You have been adding to our mailing list.';
     }
     return $view;
 }
 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();
 }
 public function upload()
 {
     access::verify_csrf();
     $validation = new Validation(array_merge($_POST, $_FILES));
     $validation->add_rules("zip_file", "upload::valid", "upload::required", "upload::type[zip]");
     $validation->add_rules("is_admin", "chars[0,1]");
     $validation->add_callbacks("zip_file", array($this, "_unload_zip"));
     if ($validation->validate()) {
         $session = Session::instance();
         $themeroller_name = $session->get("themeroller_name");
         $is_admin = $validation["is_admin"];
         $counter = 0;
         $theme_name_generated = $theme_name = ($is_admin ? "admin_" : "") . $themeroller_name;
         while (file_exists(THEMEPATH . "{$theme_name_generated}/theme.info")) {
             $counter++;
             $theme_name_generated = "{$theme_name}_{$counter}";
         }
         $theme_name = strtolower(strtr($theme_name_generated, " ", "_"));
         $session->set("theme_name", $theme_name);
         $session->set("themeroller_is_admin", $is_admin);
         print "FILEID: {$validation["zip_file"]["tmp_name"]}";
     } else {
         header("HTTP/1.1 400 Bad Request");
         print "ERROR: " . t("Invalid zip archive");
     }
 }
Example #14
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;
         }
     }
 }
Example #15
0
 public function validate(Validation $array, $save = FALSE)
 {
     $array->pre_filter('trim');
     $array->add_rules('term', 'required');
     $array->add_rules('language_id', 'required');
     return parent::validate($array, $save);
 }
 public function test_data_create()
 {
     access::verify_csrf();
     list($form, $errors) = $this->_get_test_data_form();
     $post = new Validation($_POST);
     $post->add_rules("albums", "numeric");
     $post->add_rules("photos", "numeric");
     $post->add_rules("comments", "numeric");
     $post->add_rules("tags", "numeric");
     $post->add_callbacks("albums", array($this, "_set_default"));
     $post->add_callbacks("photos", array($this, "_set_default"));
     $post->add_callbacks("comments", array($this, "_set_default"));
     $post->add_callbacks("tags", array($this, "_set_default"));
     if ($post->validate()) {
         $task_def = Task_Definition::factory()->callback("developer_task::create_content")->description(t("Create test content"))->name(t("Create Test Data"));
         $total = $post->albums + $post->photos + $post->comments + $post->tags;
         $success_msg = t("Successfully generated test data");
         $error_msg = t("Problems with test data generation was encountered");
         $task = task::create($task_def, array("total" => $total, "batch" => (int) ceil($total / 10), "success_msg" => $success_msg, "current" => 0, "error_msg" => $error_msg, "albums" => $post->albums, "photos" => $post->photos, "comments" => $post->comments, "tags" => $post->tags));
         batch::start();
         print json_encode(array("result" => "started", "max_iterations" => $total + 5, "url" => url::site("admin/developer/run_task/{$task->id}?csrf=" . access::csrf_token()), "task" => $task->as_array()));
     } else {
         $v = $this->_get_test_data_view(arr::overwrite($form, $post->as_array()), arr::overwrite($errors, $post->errors()));
         print json_encode(array("result" => "error", "form" => $v->__toString()));
     }
 }
Example #17
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;
         }
     }
 }
Example #18
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;
         }
     }
 }
Example #19
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');
 }
Example #20
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;
         }
     }
 }
Example #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;
         }
     }
 }
Example #22
0
 function validate()
 {
     $post = new Validation($_POST);
     $post->add_rules('username', 'required');
     $post->add_rules('password', 'required');
     if (!$post->validate()) {
         echo '必须填写用户名和密码';
         return;
     }
     $username = $_POST['username'];
     $password = $_POST['password'];
     $user_orm = ORM::factory('user')->where(array('name' => $username, 'password' => sha1($password)))->find();
     if ($user_orm->loaded) {
         $id = $user_orm->id;
         if ($user_orm->active == 1) {
             $this->session->set('user_id', $id);
             $this->session->set('username', $username);
             $this->session->set('role_id', $user_orm->role_id);
             respOk(array());
         } else {
             $message = "登录失败,用户处于禁止状态";
             respFailed($message);
         }
     } else {
         $message = "登录失败,用户名或密码错误";
         respFailed($message);
     }
     return;
 }
 public function validate(Validation $array, $save = FALSE)
 {
     $array->pre_filter('trim');
     $array->add_rules('group_id', 'required');
     $array->add_rules('location_id', 'required');
     $this->unvalidatedFields = array('deleted');
     return parent::validate($array, $save);
 }
Example #24
0
 public function validate(Validation $array, $save = FALSE)
 {
     // uses PHP trim() to remove whitespace from beginning and end of all fields before validation
     $array->pre_filter('trim');
     $array->add_rules('filter_id', 'required');
     $array->add_rules('user_id', 'required');
     return parent::validate($array, $save);
 }
Example #25
0
 public function validate(Validation $array, $save = FALSE)
 {
     $array->pre_filter('trim');
     $array->add_rules('group_id', 'required');
     $array->add_rules('user_id', 'required');
     $this->unvalidatedFields = array('administrator', 'deleted', 'pending');
     return parent::validate($array, $save);
 }
Example #26
0
 public function validate(Validation $array, $save = false)
 {
     $array->pre_filter('trim');
     $array->add_rules('taxon_meaning_id', 'required');
     $array->add_rules('path', 'required');
     $this->unvalidatedFields = array('caption', 'external_details', 'media_type_id');
     return parent::validate($array, $save);
 }
 public function validate(Validation $array, $save = FALSE)
 {
     $array->pre_filter('trim');
     $array->add_rules('taxon_id', 'required');
     $array->add_rules('taxon_designation_id', 'required');
     $this->unvalidatedFields = array('start_date', 'source', 'geographical_constraint', 'deleted');
     return parent::validate($array, $save);
 }
Example #28
0
 public function validate(Validation $array, $save = FALSE)
 {
     $array->pre_filter('trim');
     $array->add_rules('title', 'required');
     $array->add_rules('website_id', 'required');
     $this->unvalidatedFields = array('description', 'deleted', 'parent_id', 'owner_id', 'auto_accept', 'auto_accept_max_difficulty');
     return parent::validate($array, $save);
 }
 public function validate(Validation $array, $save = FALSE)
 {
     $array->pre_filter('trim');
     $array->add_rules('association_type_id', 'required');
     $array->add_rules('from_occurrence_id', 'required');
     $array->add_rules('to_occurrence_id', 'required');
     $this->unvalidatedFields = array('part_id', 'position_id', 'impact_id', 'deleted');
     return parent::validate($array, $save);
 }
Example #30
0
 public function validate(Validation $array, $save = FALSE)
 {
     // uses PHP trim() to remove whitespace from beginning and end of all fields before validation
     $array->pre_filter('trim');
     $array->add_rules('iso', 'required', 'length[3]');
     $array->add_rules('language', 'required', 'length[1,100]');
     $this->unvalidatedFields = array('deleted');
     return parent::validate($array, $save);
 }