Example #1
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;
 }
 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)));
     }
 }
Example #3
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 #4
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;
 }
Example #5
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');
 }
Example #6
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;
 }
Example #7
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 #8
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 #9
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');
 }
Example #10
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');
 }
 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;
 }
Example #12
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();
 }
Example #13
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;
 }
Example #14
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;
 }
Example #15
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));
 }
Example #16
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 #17
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;
         }
     }
 }
 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);
 }
Example #19
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 #20
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;
 }
 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 #22
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('user_id', 'required');
     $values = $array->as_array();
     // Explicitly add those fields for which we don't do validation
     $this->unvalidatedFields = array('survey_id', 'location_id', 'taxon_group_id', 'deleted');
     return parent::validate($array, $save);
 }
 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('identifier', 'required', 'length[1,300]');
     $array->add_rules('type_id', 'required');
     $array->add_rules('user_id', 'required');
     $values = $array->as_array();
     return parent::validate($array, $save);
 }
Example #24
0
 public function validate(Validation $array, $save = FALSE)
 {
     if (array_key_exists('validation_rules', $array->as_array())) {
         $this->validation_rules = $array['validation_rules'];
         $save = $save && $this->validateValidationRules();
     } else {
         $this->validation_rules = null;
     }
     return parent::validate($array, $save);
 }
Example #25
0
 public function validate(Validation $array, $save = FALSE)
 {
     $orig_values = $array->as_array();
     // uses PHP trim() to remove whitespace from beginning and end of all fields before validation
     $array->pre_filter('trim');
     $array->add_rules('name', 'required');
     $this->add_sref_rules($array, 'centroid_sref', 'centroid_sref_system');
     // Explicitly add those fields for which we don't do validation
     $this->unvalidatedFields = array('code', 'parent_id', 'deleted', 'centroid_geom', 'boundary_geom', 'location_type_id', 'comment', 'public', 'external_key');
     return parent::validate($array, $save);
 }
Example #26
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('name', 'required', 'length[1,100]');
     $array->add_rules('trigger_template_file', 'required');
     $array->add_rules('params_json', 'required');
     $values = $array->as_array();
     $array['public'] = isset($values['public']) && ($values['public'] == 'on' || $values['public'] == 1) ? 't' : 'f';
     $this->unvalidatedFields = array('description', 'public');
     return parent::validate($array, $save);
 }
Example #27
0
 /**
  * Validate and save the data.
  *
  * @todo add a validation rule for valid date types.
  * @todo validate at least a location_name or sref required
  */
 public function validate(Validation $array, $save = FALSE)
 {
     $orig_values = $array->as_array();
     // uses PHP trim() to remove whitespace from beginning and end of all fields before validation
     $array->pre_filter('trim');
     if ($this->id && preg_match('/[RDV]/', $this->record_status) && empty($this->submission['fields']['record_status']) && $this->wantToUpdateMetadata) {
         // If we update a processed occurrence but don't set the verification state, revert it to completed/awaiting verification.
         $array->verified_by_id = null;
         $array->verified_on = null;
         $array->record_status = 'C';
         $this->requeuedForVerification = true;
     }
     // Any fields that don't have a validation rule need to be copied into the model manually
     $this->unvalidatedFields = array('date_end', 'location_name', 'survey_id', 'deleted', 'recorder_names', 'parent_id', 'comment', 'sample_method_id', 'input_form', 'external_key', 'group_id', 'privacy_precision', 'record_status', 'verified_by_id', 'verified_on');
     $array->add_rules('survey_id', 'required');
     // when deleting a sample, only need the id and the deleted flag, don't need the date or location details, but copy over if they are there.
     if (array_key_exists('deleted', $orig_values) && $orig_values['deleted'] == 't') {
         $this->unvalidatedFields = array_merge($this->unvalidatedFields, array('date_type', 'date_start', 'date_end', 'location_id', 'entered_sref', 'entered_sref_system', 'geom'));
     } else {
         $array->add_rules('date_type', 'required', 'length[1,2]');
         $array->add_rules('date_start', 'date_in_past');
         // We need either at least one of the location_id and sref/geom : in some cases may have both
         if (empty($orig_values['location_id'])) {
             // if a location is provided, we don't need an sref.
             // without a location_id, default to requires an sref.
             // no need to copy over location_id, as not present.
             $array->add_rules('entered_sref', "required");
             $array->add_rules('entered_sref_system', 'required');
             $array->add_rules('geom', 'required');
             // even though our location_id is empty, still mark it as unvalidated so it gets copied over
             $this->unvalidatedFields[] = 'location_id';
             if (array_key_exists('entered_sref_system', $orig_values) && $orig_values['entered_sref_system'] !== '') {
                 $system = $orig_values['entered_sref_system'];
                 $array->add_rules('entered_sref', "sref[{$system}]");
                 $array->add_rules('entered_sref_system', 'sref_system');
             }
         } else {
             // got a location_id so may as well require it to make sure it gets copied across
             $array->add_rules('location_id', 'required');
             // if any of the sref fields are also supplied, need all 3 fields
             if (!empty($orig_values['entered_sref']) || !empty($orig_values['entered_sref_system']) || !empty($orig_values['geom'])) {
                 $this->add_sref_rules($array, 'entered_sref', 'entered_sref_system');
             } else {
                 // we are not requiring  the fields so they must go in unvalidated fields, allowing them to get blanked out on edit
                 $this->unvalidatedFields[] = 'entered_sref';
                 $this->unvalidatedFields[] = 'entered_sref_system';
             }
             $this->unvalidatedFields[] = 'geom';
         }
     }
     return parent::validate($array, $save);
 }
 public function validate(Validation $array, $save = false)
 {
     $array->pre_filter('trim');
     $array->add_rules('occurrence_id', 'required');
     // Explicitly add those fields for which we don't do validation
     $this->unvalidatedFields = array('email_address', 'person_name', 'cms_ref', 'taxa_taxon_list_id', 'comment', 'taxon_extra_info', 'deleted', 'determination_type', 'taxon_details', 'taxa_taxon_list_id_list');
     if (array_key_exists('taxa_taxon_list_id_list', $array->as_array())) {
         if (count($array['taxa_taxon_list_id_list']) == 1 && $array['taxa_taxon_list_id_list'][0] == '') {
             $array['taxa_taxon_list_id_list'] = array();
         }
     }
     return parent::validate($array, $save);
 }
Example #29
0
 public function action_edit_customer()
 {
     $customer_id = $this->request->param('options');
     $customer_model = new Customer($customer_id);
     xml::to_XML(array('customer' => $customer_model->get()), $this->xml_content, NULL, 'id');
     if (count($_POST)) {
         $post = new Validation($_POST);
         $post->filter('trim');
         if ($post->validate()) {
             $customer_model->set($post->as_array());
             $this->add_message('Customer "' . $post->get('name') . '" updated');
         }
     }
     $this->set_formdata($customer_model->get());
 }
 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('trigger_id', 'required');
     $array->add_rules('type', 'required');
     $values = $array->as_array();
     $this->unvalidatedFields = array('param1', 'param2');
     // for email notifications, param 3 is a comma separated list of emails.
     if ($values['type'] == 'E') {
         $array->add_rules('param3', 'email_list');
     } else {
         $this->unvalidatedFields[] = 'param3';
     }
     return parent::validate($array, $save);
 }