public function _validate_icc_path(Validation $post, $field) { if (!empty($post->{$field})) { if (!@is_file($post->{$field})) { $post->add_error($field, t("No ICC profile exists at the location <code>%icc_path</code>", array("icc_path" => $post->{$field}))); } $dcraw = rawphoto_graphics::detect_dcraw(); if (version_compare($dcraw->version, "8.00", "<")) { $post->add_error($field, t("Versions of <em>dcraw</em> before <code>8.00</code> do not support an ICC profile")); } } }
/** * Performs validation checks on the layer url and layer file - Checks that at least * one of them has been specified using the applicable validation rules * * @param Validation $array Validation object containing the field names to be checked */ public function layer_url_file_check(Validation $array) { // Ensure at least a layer URL or layer file has been specified if (empty($array->layer_url) and empty($array->layer_file) and empty($array->layer_file_old)) { $array->add_error('layer_url', 'atleast'); } // Add validation rule for the layer URL if specified if (!empty($array->layer_url) and (empty($array->layer_file) or empty($array->layer_file_old))) { $array->add_rules('layer_url', 'url'); } // Check if both the layer URL and the layer file have been specified if (!empty($array->layer_url) and (!empty($array->layer_file_old) or !empty($array->layer_file))) { $array->add_error('layer_url', 'both'); } }
/** * Validate the item name. It can't conflict with other names, can't contain slashes or * trailing periods. */ public function valid_name(Validation $v, $field) { $postage_band = ORM::factory("postage_band")->where("name", "=", $this->name)->find(); if ($postage_band->loaded() && $postage_band->id != $this->id) { $v->add_error("name", "in_use"); } }
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))); } }
/** * Performs validation checks on the geometry file - Checks that at least * one of them has been specified using the applicable validation rules * * @param Validation $array Validation object containing the field names to be checked */ public function file_check(Validation $array) { // Ensure at least a geometry URL or geometry file has been specified if (empty($array->kml_file) and empty($array->kml_file_old)) { $array->add_error('geometry_url', 'atleast'); } }
/** * Validate the item name. It can't conflict with other names, can't contain slashes or * trailing periods. */ public function valid_name(Validation $v, $field) { Kohana_Log::add("error", print_r("valid_name!", 1)); $product = ORM::factory("product")->where("name", "=", $this->name)->find(); if ($product->loaded() && $product->id != $this->id) { $v->add_error("name", "in_use"); } }
/** * If we want to delete the record, we need to check that no dependents exist. */ public function __dependents(Validation $array, $field) { if ($array['deleted'] == 'true') { $record = ORM::factory('termlists_term', $array['id']); if (count($record->children) != 0) { $array->add_error($field, 'has_children'); } } }
public function _unique_email(Validation $array, $field) { // check the database for existing records $email_exists = (bool) ORM::factory('launchingsoon_user')->where('email', $array[$field])->count_all(); if ($email_exists) { // add error to validation object $array->add_error($field, 'email_exists'); } }
/** * If we want to delete the record, we need to check that no dependents exist. */ public function _dependents(Validation $array, $field) { if ($array['deleted'] == 'true') { $record = ORM::factory('termlist', $array['id']); if ($record->terms->count() != 0) { $array->add_error($field, 'has_taxa'); } } }
/** * Look if email and password match with db * @param Validation Validation object * @param string field that all goes on * @return boolean */ public function _url_is_free(Validation $array, $field) { // Questing database if url string $url_is_free = $this->db->from(self::TN_PAGES)->where('url', $array[$field])->count_records(); if ($url_is_free != 0) { $array->add_error($field, 'is_set'); } else { return TRUE; } }
/** * Callback - check if payment exists in db * @return void * @param integer id of payment method */ public function _exists(Validation $post) { // If add->rules validation found any errors, get me out of here! if (array_key_exists('payment', $post->errors())) { return; } // Check if shipping method exists $data = $this->db->select('id')->from(self::TN_PAYMENT)->where('id', $post['payment'])->get(); if (count($data) <= 0) { // Add a validation error, this will cause $post->validate() to return FALSE $post->add_error('payment', 'required'); } }
public function _admin_check_address(Validation $array, $input) { if ($array[$input] == '') { return; } // Fetch the lat and lon via Gmap list($lat, $lon) = Gmap::address_to_ll($array[$input]); if ($lat === NULL or $lon === NULL) { // Add an error $array->add_error($input, 'address'); } else { // Set the latitude and longitude $_POST['lat'] = $lat; $_POST['lon'] = $lon; } }
/** * @method status_update * @abstract Post status update to Twitter * @author Josh Turmel * @ * @return array */ public static function status_update($config) { $username = isset($config['username']) ? $config['username'] : ''; $password = isset($config['password']) ? $config['password'] : ''; $status = isset($config['status']) ? $config['status'] : ''; $v = new Validation(array('username' => $username, 'password' => $password, 'status' => $status)); // TODO: Add in the real requirements by Twitter, for now just required $v->add_rules('username', 'required'); $v->add_rules('password', 'required'); $v->add_rules('status', 'required'); if ($v->validate() === false) { return array('success' => false, 'errors' => $v->errors('twitter')); } $appended_message = Kohana::config('twitter.appended_message'); $max_length = self::status_length(); if (strlen($status) > $max_length) { $status = substr($status, 0, $max_length - 2) . '...'; } // Now add appended_message $status = $status . $appended_message; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://twitter.com/statuses/update.json'); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, 'status=' . $status); curl_setopt($ch, CURLOPT_USERPWD, $username . ':' . $password); $output = curl_exec($ch); curl_close($ch); // Check for success or failure if (empty($output)) { $v = new Validation(array('twitter_response' => '')); $v->add_error('twitter_response', 'connection_failed'); return array('success' => false, 'errors' => $v->errors('twitter')); } else { $output = json_decode($output); if (isset($output->error) && $output->error == 'Could not authenticate you.') { $v = new Validation(array('twitter_response' => '')); $v->add_error('twitter_response', 'authentication_failed'); return array('success' => false, 'errors' => $v->errors('twitter')); } else { $output->success = true; return $output; } } }
/** * Checks if email address is associated with an account. * @param Validation $post $_POST variable with validation rules */ public function email_exists_chk(Validation $post) { $users = ORM::factory('user'); if (array_key_exists('resetemail', $post->errors())) { return; } if (!$users->email_exists($post->resetemail)) { $post->add_error('resetemail', 'invalid'); } }
/** * Ensures that only a superadmin can modify superadmin users, or upgrade a user to superadmin * @note this assumes the currently logged-in user isn't a superadmin */ public static function prevent_superadmin_modification(Validation $post, $field) { if ($post[$field] == 'superadmin') { $post->add_error($field, 'superadmin_modify'); } }
/** * Checks if parent_id for this category exists * @param Validation $post $_POST variable with validation rules */ public function parent_id_chk(Validation $post) { // If add->rules validation found any errors, get me out of here! if (array_key_exists('parent_id', $post->errors())) { return; } $category_id = $post->category_id; $parent_id = $post->parent_id; // This is a parent category - exit if ($parent_id == 0) { return; } $parent_exists = ORM::factory('category')->where('id', $parent_id)->find(); if (!$parent_exists->loaded) { // Parent Category Doesn't Exist $post->add_error('parent_id', 'exists'); } if (!empty($category_id) && $category_id == $parent_id) { // Category ID and Parent ID can't be the same! $post->add_error('parent_id', 'same'); } }
/** * Checks if url already exists. * @param Validation $post $_POST variable with validation rules */ public function url_exists_chk(Validation $post) { // If add->rules validation found any errors, get me out of here! if (array_key_exists('sharing_url', $post->errors())) { return; } $sharing_type = $post->sharing_type && ($post->sharing_type == 1 || $post->sharing_type == 2) ? $post->sharing_type : 1; $share_exists = ORM::factory('sharing')->where('sharing_url', $this->_clean_urls($post->sharing_url))->find(); if ($share_exists->loaded && $share_exists->id != $post->sharing_id && $share_exists->sharing_type == $sharing_type) { $post->add_error('sharing_url', 'exists'); } }
/** * Checks if user_id is associated with an account. * @param Validation $post $_POST variable with validation rules */ private function _user_name_chk($name, $post) { $account = ORM::factory('user')->where("name", $name)->orwhere("username", $name)->orwhere("email", $name)->where("id !=" . $this->user->id)->find(); if (!$account->loaded) { $post->add_error('private_to', 'exists'); } }
/** * Checks if email address is associated with an account. * @param Validation $post $_POST variable with validation rules */ public function email_exists_chk(Validation $post) { if (array_key_exists('email', $post->errors())) { return; } $users = ORM::factory('user')->where('id <> ' . $this->user_id); if ($users->email_exists($post->email)) { $post->add_error('email', 'exists'); } }
/** * Validate the user name. Make sure there are no conflicts. */ public function valid_name(Validation $v, $field) { if (db::build()->from("groups")->where("name", "=", $this->name)->where("id", "<>", $this->id)->count_records() == 1) { $v->add_error("name", "conflict"); } }
/** * Checks if translation for this report & locale exists * @param Validation $post $_POST variable with validation rules * @param int $iid The unique incident_id of the original report */ public function translate_exists_chk(Validation $post) { // If add->rules validation found any errors, get me out of here! if (array_key_exists('locale', $post->errors())) { return; } $iid = $_GET['iid']; if (empty($iid)) { $iid = 0; } $translate = ORM::factory('incident_lang')->where('incident_id', $iid)->where('locale', $post->locale)->find(); if ($translate->loaded == true) { $post->add_error('locale', 'exists'); // Not found } else { return; } }
/** * Check if bind config is OK * * @see $callbacks * @param Validation $array * @param string $field */ public static function bind_config(Validation $array, $field) { if ($array['access'] & self::TYPE_BIND) { if (!isset($array[$field]) || !$array[$field]) { // Bind config is required is area type bind is set $array->add_error($field, 'required'); } else { if (!in_array($array[$field], array_keys(self::area_types()))) { // Invalid bind config, this should not happen(tm) $array->add_error($field, 'invalid'); } } } else { $array[$field] = null; } }
/** * This field cannot be changed after it's been set. */ public function read_only(Validation $v, $field) { if ($this->loaded() && isset($this->changed[$field])) { $v->add_error($field, "read_only"); } }
/** * Validate Custom Form Fields * @param Validation $post Validation object from form post * XXX This whole function is being done backwards * Need to pull the list of custom form fields first * Then look through them to see if they're set, not the other way around. */ public static function validate_custom_form_fields(&$post) { $custom_fields = array(); if (!isset($post->custom_field)) { return; } /* XXX Checkboxes hackery Checkboxes are submitted in the post as custom_field[field_id-boxnum] This foreach loop consolidates them into one variable separated by commas. If no checkboxes are selected then the custom_field[] for that variable is not sent To get around that the view sets a hidden custom_field[field_id-BLANKHACK] field that ensures the checkbox custom_field is there to be tested. */ foreach ($post->custom_field as $field_id => $field_response) { $split = explode("-", $field_id); if (isset($split[1])) { // The view sets a hidden field for blankhack if ($split[1] == 'BLANKHACK') { if (!isset($custom_fields[$split[0]])) { // then no checkboxes were checked $custom_fields[$split[0]] = ''; } // E.Kala - Removed the else {} block; either way continue is still invoked continue; } if (isset($custom_fields[$split[0]])) { $custom_fields[$split[0]] .= ",{$field_response}"; } else { $custom_fields[$split[0]] = $field_response; } } else { $custom_fields[$split[0]] = $field_response; } } $post->custom_field = $custom_fields; // Kohana::log('debug', Kohana::debug($custom_fields)); foreach ($post->custom_field as $field_id => $field_response) { $field_param = ORM::factory('form_field', $field_id); $custom_name = $field_param->field_name; // Validate that this custom field already exists if (!$field_param->loaded) { // Populate the error field //$errors[$field_id] = "The $custom_name field does not exist"; $post->add_error('custom_field', 'not_exist', array($field_id)); return; } $max_auth = self::get_user_max_auth(); $required_role = ORM::factory('role', $field_param->field_ispublic_submit); if (($required_role->loaded ? $required_role->access_level : 0) > $max_auth) { // Populate the error field $post->add_error('custom_field', 'permission', array($custom_name)); return; } // Validate that the field is required if ($field_param->field_required == 1 and $field_response == "") { $post->add_error('custom_field', 'required', array($custom_name)); return; } // Grab the custom field options for this field $field_options = self::get_custom_field_options($field_id); // Validate Custom fields for text boxes if ($field_param->field_type == 1 and isset($field_options) and $field_response != '') { if (isset($field_options['field_datatype'])) { if ($field_options['field_datatype'] == 'email' and !valid::email($field_response)) { $post->add_error('custom_field', 'email', array($custom_name)); } if ($field_options['field_datatype'] == 'phonenumber' and !valid::phone($field_response)) { $post->add_error('custom_field', 'phone', array($custom_name)); } if ($field_options['field_datatype'] == 'numeric' and !valid::numeric($field_response)) { $post->add_error('custom_field', 'numeric', array($custom_name)); } } } // Validate for date if ($field_param->field_type == 3 and $field_response != "") { $field_default = $field_param->field_default; if (!valid::date_mmddyyyy($field_response)) { $post->add_error('custom_field', 'date_mmddyyyy', array($custom_name)); } } // Validate multi-value boxes only have acceptable values if ($field_param->field_type >= 5 and $field_param->field_type <= 7) { $defaults = explode('::', $field_param->field_default); $options = array(); if (preg_match("/[0-9]+-[0-9]+/", $defaults[0]) and count($defaults) == 1) { $dashsplit = explode('-', $defaults[0]); $start = $dashsplit[0]; $end = $dashsplit[1]; for ($i = $start; $i <= $end; $i++) { array_push($options, $i); } } else { $options = array_map('trim', explode(',', $defaults[0])); } $responses = explode(',', $field_response); foreach ($responses as $response) { if (!in_array($response, $options) and $response != '') { $post->add_error('custom_field', 'values', array($custom_name)); //$errors[$field_id] = "The $custom_name field does not include $response as an option"; } } } // Validate that a required checkbox is checked if ($field_param->field_type == 6 and $field_response == 'BLANKHACK' and $field_param->field_required == 1) { $post->add_error('custom_field', 'required', array($custom_name)); } } return; }
public function _is_module_defined(Validation $post, $field) { $module_name = strtolower(strtr($post[$field], " ", "_")); if (file_exists(MODPATH . "{$module_name}/module.info")) { $post->add_error($field, "module_exists"); } }
/** * Checks if translation for this report & locale exists * @param Validation $post $_POST variable with validation rules * @param int $iid The unique incident_id of the original report */ public function translate_exists_chk(Validation $post) { // If add->rules validation found any errors, get me out of here! if (array_key_exists('locale', $post->errors())) { return; } $iid = (isset($_GET['iid']) and intval($_GTE['iid'] > 0)) ? intval($_GET['iid']) : 0; // Load translation $translate = ORM::factory('incident_lang')->where('incident_id', $iid)->where('locale', $post->locale)->find(); if ($translate->loaded) { $post->add_error('locale', 'exists'); } else { // Not found return; } }
/** * Tests if an email accounts exists in the database for this alert * @param mixed mobile number to check * @return boolean */ public function _mobile_or_email(Validation $array) { if (empty($array->alert_mobile) && empty($array->alert_email)) { $array->add_error('alert_mobile', 'one_required'); } }
/** * Make sure we have a valid associated item id. */ public function valid_item(Validation $v, $field) { if (db::build()->from("items")->where("id", "=", $this->item_id)->count_records() != 1) { $v->add_error("item_id", "invalid"); } }
public function action_edit_page() { $id = $this->request->param('options'); $content_page = new Content_Page($id); if ($content_page->get_page_id()) { $this->xml_content_page = $this->xml_content->appendChild($this->dom->createElement('page')); // Get all tags associated with pages and images $this->xml_content_tags = $this->xml_content->appendChild($this->dom->createElement('tags')); $tags = array(); foreach (Content_Page::get_tags() as $tag) { $tags[] = $tag; } foreach (Content_Image::get_tags() as $tag) { foreach ($tags as $tag_to_check) { if ($tag_to_check['name'] == $tag['name']) { break 2; } } $tags[] = $tag; } foreach ($tags as $tag) { $tag_node = $this->xml_content_tags->appendChild($this->dom->createElement('tag', $tag['name'])); $tag_node->setAttribute('id', $tag['id']); } if (count($_POST) && isset($_POST['URI']) && isset($_POST['name'])) { if ($_POST['URI'] == '') { $_POST['URI'] = $_POST['name']; } $_POST['URI'] = URL::title($_POST['URI'], '-', TRUE); $post = new Validation($_POST); $post->filter('trim'); $post->rule('Valid::not_empty', 'name'); if ($post->validate()) { $post_values = $post->as_array(); $current_page_data = $content_page->get_page_data(); if ($post_values['name'] != $current_page_data['name'] && !Content_Page::page_name_available($post_values['name'])) { $post->add_error('name', 'Content_Page::page_name_available'); } if ($post_values['URI'] != $current_page_data['URI'] && !Content_Page::page_URI_available($post_values['URI'])) { $post->add_error('URI', 'Content_Page::page_URI_available'); } } // Retry if ($post->validate()) { $tags = array(); foreach ($post_values['template_position'] as $nr => $template_position) { if ($post_values['tag_id'][$nr] > 0) { if (!isset($tags[$template_position])) { $tags[$template_position] = array(); } $tags[$template_position][] = $post_values['tag_id'][$nr]; } } $content_page->update_page_data($post_values['name'], $post_values['URI'], $tags); $this->add_message('Page "' . $post_values['name'] . '" updated'); $page_data = $content_page->get_page_data(); unset($page_data['tag_ids']); $this->set_formdata($page_data); } else { $this->add_error('Fix errors and try again'); $this->add_form_errors($post->errors()); // Fix template position data $tmp_node = $this->xml_content->appendChild($this->dom->createElement('tmp')); foreach ($post_values['template_position'] as $nr => $template_position) { $template_field_node = $tmp_node->appendChild($this->dom->createElement('template_field')); $template_field_node->setAttribute('id', $template_position); if ($post_values['tag_id'][$nr] > 0) { $tag_node = $template_field_node->appendChild($this->dom->createElement('tag')); $tag_node->setAttribute('id', $post_values['tag_id'][$nr]); } } unset($post_values['template_position'], $post_values['tag_id']); $this->set_formdata($post_values); } } else { $page_data = $content_page->get_page_data(); unset($page_data['tag_ids']); $this->set_formdata($page_data); } /** * Put the page data to the XML * */ $page_data = $content_page->get_page_data(); $page_data['template_fields'] = array(); foreach ($page_data['tag_ids'] as $template_field_id => $tag_ids) { $page_data['template_fields'][$template_field_id . 'template_field'] = array('@id' => $template_field_id); foreach ($tag_ids as $tag_id) { $page_data['template_fields'][$template_field_id . 'template_field'][$tag_id . 'tag'] = array('@id' => $tag_id); } } // Unset this, or it will cludge our XML unset($page_data['tag_ids']); // Set the page data to the page node xml::to_XML($page_data, $this->xml_content_page, NULL, 'id'); } else { $this->redirect(); } }
/** * Checks if current password being passed is correct * @param Validation $post $_POST variable with validation rules */ public function current_pw_valid_chk(Validation $post) { if (array_key_exists('current_password', $post->errors())) { return; } $user = User_Model::get_user_by_id($this->user_id); if (!User_Model::check_password($user->email, $post->current_password)) { $post->add_error('current_password', 'incorrect'); } }