Пример #1
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;
         }
     }
 }
Пример #2
0
 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()));
     }
 }
 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");
     }
 }
Пример #4
0
 public function validate(Validation $array, $save = FALSE)
 {
     $array->pre_filter('trim');
     $array->add_rules('title', 'required');
     $array->add_callbacks('deleted', array($this, '_dependents'));
     // Explicitly add those fields for which we don't do validation
     $this->unvalidatedFields = array('description', 'website_id', 'parent_id', 'deleted');
     return parent::validate($array, $save);
 }
Пример #5
0
 function create()
 {
     $this->template->title = Kohana::lang('user.sign_up');
     $this->template->view->errors = array();
     $this->template->view->username = '';
     $this->template->view->email = '';
     if ($post = $this->input->post()) {
         $this->template->view->email = $post['email'];
         $this->template->view->username = $post['username'];
         $form = new Validation($post);
         $form->add_rules('email', 'required', 'valid::email');
         $form->add_rules('username', 'required');
         $form->add_rules('password', 'required');
         $form->add_callbacks('email', array($this, '_unique_email'));
         $form->add_callbacks('username', array($this, '_unique_username'));
         if ($form->validate()) {
             $user = ORM::factory('user');
             $user->email = $post['email'];
             $user->username = $post['username'];
             $user->password = $post['password'];
             if ($user->save()) {
                 // Save confirm code
                 $prop = ORM::factory('user_property');
                 $prop->user_id = $user->id;
                 $prop->key = 'confirm';
                 $prop->value = sha1($user->id . time() . Kohana::config('qaargh.confirm_salt'));
                 $prop->save();
                 // Send confirm email
                 $to = $post['email'];
                 $from = Kohana::config('qaargh.mailer');
                 $subject = Kohana::lang('user.email_account_created');
                 $email_view = new View('user/confirm_email');
                 $email_view->code = $prop->value;
                 $message = $email_view->render();
                 email::send($to, $from, $subject, $message, TRUE);
                 // And bounce.
                 $this->session->set_flash('notice', Kohana::lang('user.user_created'));
                 url::redirect("/user/confirm");
             }
         } else {
             $this->template->view->errors = $form->errors('form_errors');
         }
     }
 }
Пример #6
0
 public function saveprefs()
 {
     // Prevent Cross Site Request Forgery
     access::verify_csrf();
     $post = new Validation($_POST);
     $post->add_callbacks("IccPath", array($this, "_validate_icc_path"));
     $icc_path = Input::instance()->post("IccPath");
     if ($post->validate()) {
         module::set_var("rawphoto", "icc_path", $icc_path);
         message::success(t("Your preferences have been saved."));
     } else {
         message::error(t("Your preferences are not valid."));
     }
     print $this->_get_view($post->errors(), $icc_path);
 }
Пример #7
0
 /**
  * Settings
  * @return void
  */
 public function setting($state = NULL)
 {
     if (user::is_logged()) {
         // Messages about success
         $success = array();
         if ($state == "changed") {
             $success[] = Kohana::lang('user.successfully_changed');
         }
         $this->add_breadcrumb(Kohana::lang('user.settings'), url::current());
         $this->set_title(Kohana::lang('user.settings'));
         // default values
         $form = array('password' => '', 'password2' => '', 'password3' => '');
         $form['fullname'] = $this->user->get_name($this->LogSession->who_is_logged());
         //$errors = $form;
         $errors = array();
         // change data
         if ($_POST) {
             $post = new Validation($_POST);
             $post->add_rules('password3', 'required');
             // old password is always required
             $post->add_rules('fullname', 'required');
             $post->add_rules('password', 'depends_on[password2]');
             $post->add_rules('password2', 'depends_on[password]');
             $post->add_rules('password', 'length[6,128]');
             $post->add_rules('password', 'matches[password2]', 'depends_on[password]', 'depends_on[password2]');
             $post['email'] = $this->LogSession->who_is_logged();
             $post->add_callbacks('password3', array($this->user, '_password_match'));
             // Some filters
             $post->pre_filter('trim', TRUE);
             if ($post->validate()) {
                 $this->user->change_data($post, $this->LogSession->who_is_logged());
                 if (!empty($post['password'])) {
                     $this->user->change_password($this->LogSession->who_is_logged(), $post['password']);
                 }
                 url::redirect('/user/setting/changed');
             } else {
                 // Repopulate form with error and original values
                 $form = arr::overwrite($form, $post->as_array());
                 $errors = $post->errors('users_settings_errors');
                 $success = array();
             }
         }
         $this->template->content = new View('setting');
         $this->template->content->form = $form;
         $this->template->content->errors = $errors;
         $this->template->content->success = $success;
     } else {
         // User is not suppose to be here, redirect
         url::redirect('/user/login');
     }
 }
Пример #8
0
 public function index()
 {
     // Create new session
     $this->session->create();
     $this->template->header->this_page = 'alerts';
     $this->template->content = new View('alerts');
     // Display news feeds?
     $this->template->content->allow_feed = Kohana::config('settings.allow_feed');
     // Retrieve default country, latitude, longitude
     $default_country = Kohana::config('settings.default_country');
     // Retrieve Country Cities
     $this->template->content->cities = $this->_get_cities($default_country);
     // setup and initialize form field names
     $form = array('alert_mobile' => '', 'alert_mobile_yes' => '', 'alert_email' => '', 'alert_email_yes' => '', 'alert_lat' => '', 'alert_lon' => '');
     // 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
         if (!empty($_POST['alert_mobile']) || isset($_POST['alert_mobile_yes'])) {
             $post->add_rules('alert_mobile', 'required', 'numeric', 'length[6,20]');
         }
         if (!empty($_POST['alert_email']) || isset($_POST['alert_email_yes'])) {
             $post->add_rules('alert_email', 'required', 'email', 'length[3,64]');
         }
         if (empty($_POST['alert_email']) && empty($_POST['alert_mobile'])) {
             $post->add_error('alert_mobile', 'one_required');
             $post->add_error('alert_email', 'one_required');
         }
         $post->add_rules('alert_lat', 'required', 'between[-90,90]');
         // Validate for maximum and minimum latitude values
         $post->add_rules('alert_lon', 'required', 'between[-180,180]');
         // Validate for maximum and minimum longitude values
         // Add a callback, to validate the mobile phone/email (See the methods below)
         $post->add_callbacks('alert_mobile', array($this, 'mobile_check'));
         $post->add_callbacks('alert_email', array($this, 'email_check'));
         // Test to see if things passed the rule checks
         if ($post->validate()) {
             // Yes! everything is valid
             // Save alert and send out confirmation code
             $email_confirmation_saved = FALSE;
             $sms_confirmation_saved = FALSE;
             if (!empty($post->alert_mobile)) {
                 $alert_code = $this->_mk_code();
                 $settings = ORM::factory('settings', 1);
                 if ($settings->loaded == true) {
                     // Get SMS Numbers
                     if (!empty($settings->sms_no3)) {
                         $sms_from = $settings->sms_no3;
                     } elseif (!empty($settings->sms_no2)) {
                         $sms_from = $settings->sms_no2;
                     } elseif (!empty($settings->sms_no1)) {
                         $sms_from = $settings->sms_no1;
                     } else {
                         $sms_from = "000";
                         // User needs to set up an SMS number
                     }
                     $sms = new Clickatell();
                     $sms->api_id = $settings->clickatell_api;
                     $sms->user = $settings->clickatell_username;
                     $sms->password = $settings->clickatell_password;
                     $sms->use_ssl = false;
                     $sms->sms();
                     $message = "Your alerts confirmation code\n\t\t\t\t\t\t\t\tis: " . $alert_code . " This code is NOT case sensitive";
                     if ($sms->send($post->alert_mobile, $sms_from, $message) == "OK") {
                         $alert = ORM::factory('alert');
                         $alert->alert_type = self::MOBILE_ALERT;
                         $alert->alert_recipient = $post->alert_mobile;
                         $alert->alert_code = $alert_code;
                         $alert->alert_lon = $post->alert_lon;
                         $alert->alert_lat = $post->alert_lat;
                         $alert->save();
                         if ($alert->saved == TRUE) {
                             $sms_confirmation_saved = TRUE;
                         }
                     }
                 }
             }
             if (!empty($post->alert_email)) {
                 $alert_code = $this->_mk_code();
                 //Send verification email
                 $config = kohana::config('alerts');
                 $settings = kohana::config('settings');
                 $to = $post->alert_email;
                 $from = $config['alerts_email'];
                 $subject = $settings['site_name'] . ' alerts - verification';
                 $message = 'Please follow ' . url::base() . 'alerts/verify/' . $alert_code . ' to confirm your alert request';
                 if (email::send($to, $from, $subject, $message, TRUE) == 1) {
                     $alert = ORM::factory('alert');
                     $alert->alert_type = self::EMAIL_ALERT;
                     $alert->alert_recipient = $post->alert_email;
                     $alert->alert_code = $alert_code;
                     $alert->alert_lon = $post->alert_lon;
                     $alert->alert_lat = $post->alert_lat;
                     $alert->save();
                     if ($alert->saved == TRUE) {
                         $email_confirmation_saved = TRUE;
                     }
                 }
             }
             $this->session->set('alert_mobile', $post->alert_mobile);
             $this->session->set('alert_email', $post->alert_email);
             $this->session->set('sms_confirmation_saved', $sms_confirmation_saved);
             $this->session->set('email_confirmation_saved', $email_confirmation_saved);
             url::redirect('alerts/confirm');
         } else {
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
             // populate the error fields, if any
             $errors = arr::overwrite($errors, $post->errors('alerts'));
             $form_error = TRUE;
         }
     } else {
         $form['alert_lat'] = Kohana::config('settings.default_lat');
         $form['alert_lon'] = Kohana::config('settings.default_lon');
     }
     $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->header->map_enabled = TRUE;
     $this->template->header->js = new View('alerts_js');
     $this->template->header->js->default_map = Kohana::config('settings.default_map');
     $this->template->header->js->default_zoom = Kohana::config('settings.default_zoom');
     $this->template->header->js->latitude = $form['alert_lat'];
     $this->template->header->js->longitude = $form['alert_lon'];
 }
Пример #9
0
 private function _get_frm_valid()
 {
     $form = $this->promotion_model->get_frm();
     $hd_id = $this->input->post('hd_id');
     $errors = $form;
     if ($_POST) {
         $post = new Validation($_POST);
         $post->add_rules('txt_company', 'required');
         $post->add_rules('txt_email', 'required');
         $post->add_rules('txt_code', 'required');
         if (empty($hd_id)) {
             // create account
             $post->add_callbacks('txt_code', array($this, '_check_code'));
         } else {
             $post->add_callbacks('txt_code', array($this, '_check_code_exist'));
         }
         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('promotion_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_promotion/edit/' . $hd_id);
             } else {
                 url::redirect('admin_promotion/create');
             }
             die;
         }
     }
 }
Пример #10
0
 /**
  * Checkout
  */
 public function checkout()
 {
     $output = '';
     if ($_SERVER['REQUEST_METHOD'] != 'POST') {
         $output = $this->_checkout_step_1();
     } else {
         //valid helper
         include 'classes/valid.class.php';
         $valid = new Valid();
         //validation class
         include 'classes/validation.class.php';
         $step = $_POST['step'];
         if ($step == '1') {
             //step 1 validation
             $post = new Validation($_POST['order']);
             $post->add_rules('first_name', 'required');
             $post->add_rules('last_name', 'required');
             $post->add_rules('company', 'required');
             $post->add_rules('address', 'required');
             $post->add_rules('city', 'required');
             $post->add_rules('state', 'required');
             $post->add_rules('country', 'required');
             $post->add_rules('zip', 'required');
             $post->add_rules('phone', 'required', array($valid, 'phone'));
             $post->add_rules('email', 'required', array($valid, 'email'));
             if (!isset($_POST['billing_is_shipping'])) {
                 $post->add_rules('ship_first_name', 'required');
                 $post->add_rules('ship_last_name', 'required');
                 $post->add_rules('ship_company', 'required');
                 $post->add_rules('ship_address', 'required');
                 $post->add_rules('ship_city', 'required');
                 $post->add_rules('ship_state', 'required');
                 $post->add_rules('ship_country', 'required');
                 $post->add_rules('ship_zip', 'required');
                 $post->add_rules('ship_phone', 'required', array($valid, 'phone'));
             }
             $post->pre_filter('trim');
             //success, go to step 2
             if ($post->validate()) {
                 //save order data
                 $_SESSION['order'] = $_POST['order'];
                 $output = $this->_checkout_step_2();
             } else {
                 $errors = $post->errors();
                 $output = $this->_checkout_step_1($_POST, $errors);
             }
         } elseif ($step == '2') {
             //step 2 validation
             $post = new Validation($_POST['order']);
             $post->add_rules('cc_name', 'required');
             $post->add_rules('cc_type', 'required');
             $post->add_rules('cc_number', 'required', array($valid, 'credit_card'));
             $post->add_rules('cc_cvv', 'required', 'length[3,4]', array($valid, 'digit'));
             $post->add_rules('cc_exp_month', 'required');
             $post->add_rules('cc_exp_year', 'required');
             if (isset($_POST['order']['cc_exp_month']) && isset($_POST['order']['cc_exp_year'])) {
                 $post->add_callbacks('cc_exp_year', array($this, '_validate_cc_exp_date'));
             }
             $post->pre_filter('trim');
             if ($post->validate()) {
                 $cart = new Cart('shopping_cart');
                 //order data array
                 $order_arr = array_merge($_SESSION['order'], $_POST['order']);
                 $full_cc_number = $order_arr['cc_number'];
                 $order_arr['cc_number'] = substr($order_arr['cc_number'], -4);
                 $order_arr['promo_discount'] = $cart->getDiscount($order_arr['promo_code']);
                 $order_arr['subtotal'] = $cart->getTotal();
                 $order_arr['tax'] = $cart->getTax();
                 //process payment
                 include 'merchants/firstdata.class.php';
                 $merchant = new FirstData();
                 //billing info
                 $merchant->name = $order_arr['first_name'] . ' ' . $order_arr['last_name'];
                 $merchant->company = $order_arr['company'];
                 $merchant->address = $order_arr['address'];
                 $merchant->address2 = $order_arr['address2'];
                 $merchant->city = $order_arr['city'];
                 $merchant->state = $order_arr['state'];
                 $merchant->country = $order_arr['country'];
                 $merchant->phone = $order_arr['phone'];
                 $merchant->fax = $order_arr['fax'];
                 $merchant->email = $order_arr['email'];
                 $merchant->zip = $order_arr['zip'];
                 //shipping info
                 $merchant->ship_name = $order_arr['ship_first_name'] . ' ' . $order_arr['ship_last_name'];
                 $merchant->ship_address = $order_arr['ship_address'];
                 $merchant->ship_saddress2 = $order_arr['ship_address2'];
                 $merchant->ship_city = $order_arr['ship_city'];
                 $merchant->ship_state = $order_arr['ship_state'];
                 $merchant->ship_country = $order_arr['ship_country'];
                 $merchant->ship_zip = $order_arr['ship_zip'];
                 //payment info
                 $merchant->cc_number = $full_cc_number;
                 $merchant->cc_exp_month = $order_arr['cc_exp_month'];
                 $merchant->cc_exp_year = substr($order_arr['cc_exp_year'], -2);
                 $merchant->cc_cvv = $order_arr['cc_cvv'];
                 $merchant->subtotal = $order_arr['subtotal'];
                 $merchant->shipping = 0;
                 $merchant->tax = $order_arr['tax'];
                 $merchant->total = $order_arr['subtotal'] + $order_arr['tax'] - $order_arr['promo_discount'];
                 // set to GOOD for test or LIVE
                 $merchant->result = 'LIVE';
                 $merchant_success = false;
                 $result = $merchant->sale();
                 if ($result['r_approved'] == "APPROVED") {
                     $merchant_success = true;
                 }
                 //merchant error
                 if (!$merchant_success) {
                     $errors = $post->errors();
                     $this->set_flash($result['r_error'], 'error');
                     $output = $this->_checkout_step_2($_POST, $errors);
                 } else {
                     //save order to database
                     $record = Record::insert('ecommerce_order', $order_arr);
                     $order_id = Record::lastInsertId();
                     //save order items to database
                     foreach ($cart->getItems() as $variant_id => $quantity) {
                         //get variant data
                         $variant = Record::findByIdFrom('ProductVariant', $variant_id);
                         $variant->order_id = $order_id;
                         $variant->quantity = $quantity;
                         $variant_arr = (array) $variant;
                         //remove unneeded fields
                         unset($variant_arr['id']);
                         unset($variant_arr['created_on']);
                         unset($variant_arr['updated_on']);
                         unset($variant_arr['position']);
                         //insert
                         $record = Record::insert('ecommerce_order_variant', $variant_arr);
                     }
                     //save log
                     $this->_insert_log('Order <a href="' . get_url('plugin/ecommerce/order_show/' . $order_id) . '">' . $order_id . '</a> was placed.');
                     //send emails to client and buyer
                     $this->_send_order_email('*****@*****.**', $order_id, $order_arr, $variant_arr);
                     $this->_send_order_email($order_arr['email'], $order_id, $order_arr, $variant_arr);
                     //success
                     $this->set_flash('Thank you for your order. You will receive a confirmation email shortly.', 'success');
                     //clear cart and order session
                     unset($_SESSION['order']);
                     unset($_SESSION['Cart']);
                 }
             } else {
                 $errors = $post->errors();
                 $output = $this->_checkout_step_2($_POST, $errors);
             }
         }
     }
     return $output;
 }
Пример #11
0
 /**
  * 创建活动
  */
 public function create()
 {
     if ($this->get_method() != 'POST') {
         $this->send_response(405, NULL, '请求的方法不存在');
     }
     $data = $this->get_data();
     if (!$data) {
         $this->send_response(400, NULL, '400505:活动信息非法');
     }
     $post = new Validation($data);
     $post->add_rules('title', 'required', 'length[1, 30]');
     $post->add_rules('start_at', 'required', 'numeric');
     $post->add_rules('end_at', 'required', 'numeric');
     $post->add_rules('spot', 'required', 'length[1, 30]');
     $post->add_rules('type', 'required', 'numeric', array($this, '_check_type_validation'));
     $post->add_rules('is_allow_invite', 'required', 'numeric', array($this, '_check_allow_invite_validation'));
     $post->add_rules('content', 'length[0, 300]');
     $post->add_rules('group_ids', array($this, '_check_group_ids_validation'));
     $post->add_callbacks(TRUE, array($this, '_check_time_validation'));
     if ($post->validate()) {
         $activity = array();
         $form = $post->as_array();
         $activity['creator_id'] = $this->user_id;
         $activity['title'] = $form['title'];
         $activity['start_time'] = $form['start_at'];
         $activity['end_time'] = $form['end_at'];
         $nowTime = time();
         $activity['create_time'] = $nowTime;
         $activity['spot'] = $form['spot'];
         $activity['type'] = $form['type'];
         $activity['is_allow_invite'] = $form['is_allow_invite'];
         if (isset($form['content'])) {
             $activity['content'] = $form['content'];
         }
         $groupIds = array();
         if (isset($form['group_ids'])) {
             $groupIds = $form['group_ids'];
         }
         $groupModel = new Group_Model();
         $gidArray = array();
         foreach ($groupIds as $id) {
             $id = floatval($id);
             if ($id != -1) {
                 $groupInfo = $groupModel->getGroupInfo($id);
                 if (!$groupInfo) {
                     $this->send_response(400, NULL, '400506:活动发布到的群不存在');
                 }
                 $grade = $groupModel->getMemberGrade($id, $this->user_id);
                 if ($grade < 1) {
                     $this->send_response(400, NULL, '400507:您不是活动指定发布到群的成员');
                 }
             }
             $gidArray[] = $id;
         }
         if (!$gidArray) {
             $activity['is_publish'] = 0;
         } else {
             $activity['is_publish'] = 1;
         }
         $activity_id = $this->model->add($activity);
         $activityMember = array('aid' => $activity_id, 'uid' => $this->user_id, 'apply_type' => Kohana::config('activity.apply_type.join'), 'apply_time' => $nowTime, 'grade' => Kohana::config('activity.grade.creator'));
         $result = $this->model->applyActivity($activityMember);
         $this->model->addActivityUser($activity_id, $this->user_id);
         $friendModel = new Friend_Model();
         $fidList = $friendModel->getAllFriendIDs($this->user_id, false);
         //活动动态发送到指定momo成员
         foreach ($gidArray as $gid) {
             $this->model->addActivityGroup($activity_id, $gid);
             if ($gid == -1) {
                 $friendModel = new Friend_Model();
                 $fidList = $friendModel->getAllFriendIDs($this->user_id, false);
                 foreach ($fidList as $fid) {
                     $this->model->addActivityUser($activity_id, $fid);
                 }
             } else {
                 $this->model->addActivityGroup($activity_id, $gid);
                 $members = $groupModel->getGroupAllMember($gid);
                 foreach ($members as $value) {
                     $this->model->addActivityUser($activity_id, $value['uid']);
                 }
             }
         }
         $feedModel = new Feed_Model();
         $title = array('uid' => $this->user_id, 'name' => sns::getrealname($this->user_id), 'id' => $activity_id, 'title' => $activity['title']);
         $messageModel = new Message_Model();
         if ($activity['is_publish']) {
             $feedModel->addFeed($this->user_id, 'action_add', Kohana::config('uap.app.action'), $title, array(), $activity_id);
         }
         $this->send_response(200, array('id' => floatval($activity_id)));
     }
     $errors = $post->errors();
     $this->send_response(400, NULL, '400505:活动信息非法');
 }
Пример #12
0
 /**
  * 
  * 活动邀请
  */
 public function invite($id = NULL)
 {
     if ($this->get_method() != 'POST') {
         $this->send_response(405, NULL, '请求的方法不存在');
     }
     if (empty($id)) {
         $this->send_response(400, NULL, '400501:活动ID为空');
     }
     $data = $this->get_data();
     if (!$data) {
         $this->send_response(400, NULL, '400412:活动信息非法');
     }
     $event_info = $this->model->get($id);
     if (!$event_info) {
         $this->send_response(400, NULL, '400506:活动不存在');
     }
     if (empty($data['user'])) {
         $this->send_response(400, NULL, '400508:活动报名信息为空');
     }
     $return = array();
     $update_apply_type = false;
     $post = new Validation($data);
     $post->add_rules('user', 'required');
     $post->add_callbacks(TRUE, array($this, '_check_user_validation'));
     if ($post->validate()) {
         $form = $post->as_array();
         if (count($form['user'] > 0)) {
             $user_array = $this->_get_event_uid($form['user']);
             $i = 0;
             $cover = Event_Image_Model::instance()->getCover($id);
             $cover = $cover ? $cover : '';
             $opt = array('event' => array('id' => $id, 'name' => $event_info['title'], 'cover' => $cover), 'no_sign' => 1);
             foreach ($user_array as $mobile => $user) {
                 $i++;
                 if ($this->user_id == $user['user_id'] || empty($user['user_id'])) {
                     continue;
                 }
                 $apply_type = $this->model->getApplyType(array('eid' => $id, 'uid' => $user['user_id']));
                 if (!$apply_type || $apply_type == Kohana::config('event.apply_type.refused')) {
                     if ($apply_type == Kohana::config('event.apply_type.refused')) {
                         $update_apply_type = true;
                     }
                     $eventUser = array('eid' => $id, 'pid' => 0, 'uid' => $user['user_id'], 'name' => $user['name'], 'mobile' => $mobile, 'apply_type' => Kohana::config('event.apply_type.unconfirmed'), 'apply_time' => time(), 'invite_by' => $this->user_id, 'grade' => Kohana::config('event.grade.normal'));
                     $this->model->applyEvent($eventUser, $update_apply_type);
                 }
                 if (!in_array($apply_type, array(Kohana::config('event.apply_type.joined'), Kohana::config('event.apply_type.interested')))) {
                     $return[] = array('uid' => $user['user_id'], 'name' => $user['name'], 'mobile' => $mobile, 'avatar' => sns::getAvatar($user['user_id']));
                     $device_id = md5($mobile . '_' . '0');
                     $token = User_Model::instance()->request_access_token(0, $user['user_id'], $device_id, Kohana::config('event.appid'));
                     $event_url = MO_EVENT . 'event/show/' . $id . '?token=' . $token['oauth_token'];
                     $event_short_url = url::getShortUrl($event_url);
                     $content = '邀请你参加活动:' . $event_short_url;
                     $this->send_event_mq($this->user_id, $user['user_id'], $content, $opt);
                 } else {
                     $this->send_response(400, NULL, '400511:该用户已报名');
                 }
             }
             $this->send_response(200, array('num' => $i, 'user' => $return));
         }
     }
     $errors = $post->errors();
     foreach ($errors as $key => $value) {
         switch ($key) {
             case 'user_name_empty':
                 $this->send_response(400, NULL, '400502:名字为空');
                 break;
             case 'user_mobile_empty':
                 $this->send_response(400, NULL, '400503:手机号为空');
                 break;
             case 'user_mobile_format':
                 $this->send_response(400, NULL, '400504:手机号格式不正确');
                 break;
         }
     }
 }
Пример #13
0
 /**
  *  Add page
  * @return void
  */
 public function add()
 {
     // Check for user permission
     if (user::is_got()) {
         // Settings
         $this->set_title(Kohana::lang('page.add_page'));
         $this->add_breadcrumb(Kohana::lang('page.add_page'), url::current());
         // Load tinymce
         $this->add_javascript('/libs/tinymce/tiny_mce.js');
         $this->add_javascript('/libs/tinymce/richEditor.js');
         // Default values
         $form = array('heading' => '', 'url' => '', 'page_text' => '', 'display_menu' => 0);
         $errors = array();
         // Validation
         if ($_POST) {
             $post = new Validation($_POST);
             // Some filters
             $post->pre_filter('trim', TRUE);
             // Rules
             $post->add_rules('heading', 'required');
             $post->add_rules('url', 'required', 'alpha_dash');
             $post->add_rules('page_text', 'required');
             $post->add_callbacks('url', array($this->page, '_url_is_free'));
             if ($post->validate()) {
                 // Everything seems to be ok, insert into db
                 $this->page->add_data($post);
                 url::redirect('/page/' . $post['url']);
             } else {
                 // Repopulate form with error and original values
                 $form = arr::overwrite($form, $post->as_array());
                 $errors = $post->errors('page_errors');
             }
         }
         // View
         $this->template->content = new View('admin/page_add');
         $this->template->content->form = $form;
         $this->template->content->errors = $errors;
     } else {
         url::redirect('/denied');
     }
 }
Пример #14
0
 /**
  * Checkout 
  * @return void
  */
 public function checkout()
 {
     // Check user permission
     if (user::is_logged()) {
         if ($this->cart->count_cart() != 0) {
             $customer = new Customer_Model();
             if ($customer->has_info()) {
                 // check if customer profile is set (at least personal informations)
                 // Settings
                 $this->set_title(Kohana::lang('eshop.checkout'));
                 $this->add_breadcrumb(Kohana::lang('eshop.checkout'), '/cart/checkout');
                 // Other needed models, and data
                 $shipping = new Shipping_Model();
                 $payment = new Payment_Model();
                 $order = new Order_Model();
                 // Fetching values
                 $cart = $this->cart->get_cart();
                 $total = $this->cart->get_total();
                 $shipping_methods = $shipping->get_all();
                 $payment_methods = $payment->get_all();
                 $profile = $customer->get_profile(user::user_id());
                 // Default values
                 $form = array('delivery_name' => $profile['name'], 'delivery_street' => $profile['customer_street'], 'delivery_city' => $profile['customer_city'], 'delivery_postal_code' => $profile['customer_postal_code'], 'shipping' => $shipping->get_default(), 'payment' => $payment->get_default());
                 $errors = array();
                 // Validation
                 if ($_POST) {
                     $post = new Validation($_POST);
                     // Some filters
                     $post->pre_filter('trim', TRUE);
                     // Rules
                     $post->add_rules('delivery_name', 'required', 'length[0,255]');
                     $post->add_rules('delivery_street', 'required');
                     $post->add_rules('delivery_city', 'required');
                     $post->add_rules('delivery_postal_code', 'required', 'length[0,255]');
                     $post->add_rules('shipping', 'required');
                     $post->add_callbacks('shipping', array($shipping, '_exists'));
                     $post->add_rules('payment', 'required');
                     $post->add_callbacks('payment', array($payment, '_exists'));
                     if ($post->validate()) {
                         // Everything seems to be ok, insert to db
                         $id = $order->add_data($post, $profile, $cart);
                         $this->cart->empty_cart();
                         // Now payment
                         url::redirect('/cart/payment/' . $id);
                     } else {
                         // Repopulate form with error and original values
                         $form = arr::overwrite($form, $post->as_array());
                         $errors = $post->errors('cart_checkout_errors');
                     }
                 }
                 // View
                 $this->template->content = new View('cart_checkout');
                 $this->template->content->cart = $cart;
                 $this->template->content->total = $total;
                 $this->template->content->profile = $profile;
                 $this->template->content->shipping_methods = $shipping_methods;
                 $this->template->content->payment_methods = $payment_methods;
                 $this->template->content->form = $form;
                 $this->template->content->errors = $errors;
             } else {
                 url::redirect('/customer/profile/needed');
             }
         } else {
             url::redirect('/cart/show');
         }
     } else {
         url::redirect('/user/login/login');
     }
 }
Пример #15
0
 public function removeSetting()
 {
     $user = $this->authenticate();
     $emptyrequest = !isset($_GET) && !isset($_POST) || sizeof($_GET) == 0 && sizeof($_POST) == 0;
     $input;
     if (!$emptyrequest) {
         $input = new Validation(array_merge($_GET, $_POST));
         $input->add_rules('setting_id', 'required', 'numeric');
         $validator = new SettingValidation_Model();
         $validator->expectedUser_id = $user->user_id;
         $input->add_callbacks('setting_id', array($validator, "validateExists"));
         $input->add_callbacks('setting_id', array($validator, "validateUserOwnsSetting"));
     } else {
         $input = new Validation(array());
         $input->add_error('setting_id', 'required');
     }
     if ($input->validate()) {
         $setting = new Setting_Model();
         $setting->setting_id = $input->setting_id;
         $setting->retrieveInfoFromDB();
         $setting->removeFromDB();
         Kohana::render($this->encode($setting));
     } else {
         //@TODO : make better error messages......
         Kohana::render($this->encode(NULL, $input->errors()));
     }
 }
Пример #16
0
 /**
  * Validation for models
  * @Developer brandon
  * @Date Apr 21, 2010
  */
 protected function validation($params)
 {
     $validation = new Validation($params);
     // Validate required fields
     foreach ($this->validates_presence_of as $required_field) {
         $validation->add_rules($required_field, 'required');
     }
     // Validate the formatting of the fields
     foreach ($this->validates_format_of as $format => $value) {
         foreach ($value as $field) {
             $validation->add_rules($field, $format);
         }
     }
     // Validate the uniqueness of a field
     foreach ($this->validates_uniqueness_of as $field) {
         $validation->add_callbacks($field, array($this, '_validate_unique'));
     }
     // Validation callbacks
     foreach ($this->validates_custom as $field) {
         $validation->add_callbacks($field, array($this, '_validate_' . $field));
     }
     return $validation->validate();
 }
Пример #17
0
 function password_reset()
 {
     $email = $this->input->post('email_address');
     $token = $this->input->post('token');
     $password = $this->input->post('password');
     $form = array('email_address' => '', 'token' => '', 'password' => '');
     //  copy the form as errors, so the errors will be stored with keys corresponding to the form field names
     $errors = $form;
     // Has the form been submitted?
     if ($_POST) {
         $post = new Validation($_POST);
         $post->add_rules('email_address', 'required', 'email');
         $post->add_rules('token', 'required', 'length[10,60]');
         $post->add_rules('password', 'required', 'length[5,20]');
         // Add some rules, the input field, followed by a list of checks, carried out in order
         $post->add_callbacks('password', array($this, '_strong_pwd'));
         $post->add_rules('*', 'required');
         // Add some filters
         $post->pre_filter('trim', TRUE);
         if ($post->validate()) {
             // We have all required fields - is this a valid reset request?
             if (Auth::instance()->driver->resetPassword($email, $token, $password)) {
                 // Show confirmation of reset page and offer link to login again
                 $this->template->content = new View(Router::$controller . '/password_reset_confirm');
             } else {
                 // Unknown user
                 $post->add_error('email_address', 'unknown');
             }
         }
         if (!$post->validate()) {
             // Errors in validation
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
             // populate the error fields, if any
             // We need to already have created an error message file, for Kohana to use
             // Pass the error message file name to the errors() method
             $errors = arr::overwrite($errors, $post->errors('error_messages'));
         }
     }
     $this->view->form = $form;
     $this->view->errors = $errors;
 }
Пример #18
0
 private function _get_myacc_valid()
 {
     $old_pass = $this->input->post('txt_old_pass');
     $new_pass = $this->input->post('txt_new_pass');
     $re_pass = $this->input->post('txt_cf_new_pass');
     $form = array('txt_first_name' => '', 'txt_last_name' => '', 'txt_email' => '', 'txt_company_name' => '', 'txt_contact_name' => '', 'txt_contact_email' => '', 'txt_old_pass' => '', 'txt_new_pass' => '', 'txt_cf_new_pass' => '');
     $errors = $form;
     if ($_POST) {
         $post = new Validation($_POST);
         $post->pre_filter('trim', TRUE);
         $post->add_rules('txt_email', 'required', 'email');
         if ($this->sess_cus['email'] !== $this->input->post('txt_email')) {
             $post->add_callbacks('txt_email', array($this, '_check_email'));
         }
         if (!empty($old_pass) || !empty($new_pass)) {
             $post->add_rules('txt_new_pass', 'length[6,30]');
             $post->add_rules('txt_cf_new_pass', 'matches[txt_new_pass]');
             $post->add_callbacks('txt_old_pass', array($this, '_check_old_pass'));
         }
         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;
                 }
             }
             $this->session->set_flash('error_msg', $str_error);
             url::redirect('mypage/viewaccount');
             die;
         }
     }
 }
Пример #19
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;
         }
     }
 }
Пример #20
0
 private function _valid_frm_forgot_pass()
 {
     $form = array('txt_email' => '');
     $errors = $form;
     if ($_POST) {
         $post = new Validation($_POST);
         $post->pre_filter('trim', TRUE);
         $post->add_rules('txt_email', 'required', 'email');
         $post->add_callbacks('txt_email', array($this, '_check_email_db'));
         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('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(uri::segment(1) . '/forgot_pass');
             die;
         }
     }
 }
Пример #21
0
 private function _get_frm_valid()
 {
     $hd_id = $this->input->post('hd_id');
     $hd_id_author = $this->input->post('hd_id_author');
     $txt_pass = $this->input->post('txt_pass');
     $form = $this->author_model->get_frm();
     $errors = $form;
     if ($_POST) {
         $post = new Validation($_POST);
         $post->pre_filter('trim', TRUE);
         //$post->add_rules('txt_username','required','length[3,50]');
         $post->add_rules('txt_email', 'email', 'required');
         if (empty($hd_id)) {
             //print_r('abc');die();
             $post->add_rules('txt_pass', 'required', 'length[6,30]');
             //$post->add_callbacks('txt_username',array($this,'_check_username'));
             $post->add_callbacks('txt_email', array($this, '_check_email'));
         } elseif (!empty($txt_pass)) {
             $post->add_rules('txt_pass', 'length[6,30]');
         }
         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_author/edit/' . $hd_id);
             } else {
                 url::redirect('admin_author/create');
             }
             die;
         }
     }
 }
Пример #22
0
 /**
  * Add Edit decayimage 
  */
 public function index()
 {
     // The default decayimage thumb file name
     $default_decayimage_thumb = 'Question_icon_thumb.png';
     $this->template->content = new View('decayimage/settings');
     $this->template->content->title = Kohana::lang('decayimage.decayimage');
     plugin::add_stylesheet('decayimage/css/decayimage');
     // Setup and initialize form field names
     $form = array('action' => '', 'decayimage_id' => '', 'decayimage_image' => '', 'decayimage_file' => '', 'decayimage_thumb' => '', 'category_id' => '');
     // 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;
     $form_action = "";
     $parents_array = array();
     // Check, has the form been submitted, if so, setup validation
     if ($_POST) {
         $post = new Validation($_POST);
         $post->pre_filter('trim');
         $post->add_callbacks('category_id', array($this, '_is_valid_category'));
         // if we have an action == 'a' but and a decayimage_id then what we really
         // mean is to perform and edit
         if ($post->action == 'a' && isset($post->category_id)) {
             $post->add_rules('category_id', 'required', 'numeric');
             if ($post->validate() && ($decayimage = ORM::factory('decayimage')->where('category_id', $post->category_id)->find()) && $decayimage->loaded) {
                 $post->decayimage_id = $decayimage->id;
                 $post->action = 'e';
             }
         }
         // Check for action
         if ($post->action == 'a') {
             // Create a new decayimage row
             $decayimage = new Decayimage_Model($post->decayimage_id);
             // Handle the case where we recieve new files
             if (upload::valid($_FILES['decayimage_file']) && strlen($_FILES['decayimage_file']['name']) && ($_FILES = Validation::factory($_FILES)->add_rules('decayimage_file', 'upload::valid', 'upload::type[gif,jpg,png]', 'upload::size[50K]')) && $_FILES->validate() && $post->validate()) {
                 // Upload the file and create a thumb
                 $modified_files = $this->_handle_new_decayimage_fileupload(0);
                 if (!$modified_files) {
                     $form_saved = false;
                     $form_error = TRUE;
                     $post->add_error('decayimage', Kohana::lang('decayimage.cant_upload_file'));
                 } else {
                     $decayimage->decayimage_image = $modified_files[0];
                     $decayimage->decayimage_thumb = $modified_files[1];
                     // Update the relevant decayimage from the db
                     $decayimage->category_id = $post->category_id;
                     $decayimage->save();
                     $form_saved = TRUE;
                     $form_action = Kohana::lang('decayimage.added');
                 }
             } else {
                 if ($post->add_rules('decayimage_thumb', 'required', 'length[5,255]') && $post->add_callbacks('decayimage_thumb', array($this, '_is_valid_decayimage_thumb')) && $post->validate()) {
                     // Upload the file and create a thumb
                     $decayimage->decayimage_thumb = $post->decayimage_thumb;
                     // Update the relevant decayimage from the db
                     $decayimage->category_id = $post->category_id;
                     $decayimage->save();
                     $form_saved = TRUE;
                     $form_action = Kohana::lang('decayimage.added');
                 } else {
                     // There was an error in validation
                     $form_error = TRUE;
                     $form = arr::overwrite($form, $post->as_array());
                     $errors = arr::overwrite($errors, $post->errors('decayimage'));
                 }
             }
         } elseif ($post->action == 'e') {
             // Setup validation for new $_FILES
             if (upload::valid($_FILES['decayimage_file']) && strlen($_FILES['decayimage_file']['name'])) {
                 $_FILES = Validation::factory($_FILES)->add_rules('decayimage_file', 'upload::valid', 'upload::type[gif,jpg,png]', 'upload::size[50K]');
             } else {
                 $post->add_rules('decayimage_thumb', 'required', 'length[5,255]');
                 $post->add_callbacks('decayimage_thumb', array($this, '_is_valid_decayimage_thumb'));
             }
             // Validate all input
             $post->add_rules('decayimage_id', 'required', 'numeric');
             $post->add_callbacks('decayimage_id', array($this, '_is_valid_decayimage_id'));
             if ($post->validate()) {
                 // Get the relevant decayimage from the db
                 $decayimage = new Decayimage_Model($post->decayimage_id);
                 // If a file was uploaded we will need to convert it to an apropriate icon size
                 if (upload::valid($_FILES['decayimage_file']) && strlen($_FILES['decayimage_file']['name']) && $_FILES->validate()) {
                     $modified_files = $this->_handle_new_decayimage_fileupload($post->decayimage_id);
                     if (!$modified_files) {
                         $form_saved = false;
                         $form_error = TRUE;
                         $post->add_error('decayimage', Kohana::lang('decayimage.cant_upload_file'));
                     } else {
                         $decayimage->decayimage_image = $modified_files[0];
                         $decayimage->decayimage_thumb = $modified_files[1];
                     }
                 } else {
                     $decayimage->decayimage_thumb = $post->decayimage_thumb;
                 }
                 // Update the relevant decayimage from the db
                 $decayimage->category_id = $post->category_id;
                 $decayimage->save();
                 $form_saved = TRUE;
                 $form_action = Kohana::lang('decayimage.updated');
             } else {
                 // There were errors
                 $form_error = TRUE;
             }
         } elseif ($post->action == 'd') {
             // TODO: https://github.com/March-hare/decayimage/issues/3
             // Make sure its not the Default entry
             $post->add_rules('decayimage_id', 'required', 'numeric');
             if ($post->validate()) {
                 $decayimage = ORM::factory('decayimage', $post->decayimage_id);
                 if ($decayimage->decayimage_image != 'Question_icon.png') {
                     $decayimage->delete();
                 } else {
                     $form_error = TRUE;
                     $post->add_error('decayimage', Kohana::lang('decayimage.cant_del_default'));
                 }
             } else {
                 $form_error = TRUE;
             }
         } elseif ($post->action == 'r') {
             // TODO: Revert to default decayimage action
             $decayimage = ORM::factory('decayimage')->where('category_id', 0)->find();
             $decayimage->decayimage_image = 'Question_icon.png';
             $decayimage->decayimage_thumb = 'Question_icon_thumb.png';
             $decayimage->save();
         }
         if ($form_error) {
             $form = arr::overwrite($form, $post->as_array());
             $errors = arr::overwrite($errors, $post->errors('decayimage'));
         }
     }
     //get array of categories
     $categories = ORM::factory("category")->where("category_visible", "1")->find_all();
     $cat_array[0] = Kohana::lang('decayimage.default_incident_icon');
     foreach ($categories as $category) {
         $cat_array[$category->id] = $category->category_title;
     }
     //get array of decay images
     $decayimages = ORM::factory("decayimage")->find_all();
     $decayimage_array = array();
     foreach ($decayimages as $decayimage) {
         $decayimage_array[$decayimage->decayimage_thumb] = $decayimage->decayimage_thumb;
     }
     $this->template->content->form_action = $form_action;
     $this->template->content->errors = $errors;
     $this->template->content->cat_array = $cat_array;
     $this->template->content->decayimage_array = $decayimage_array;
     $this->template->content->url_site = url::site();
     $this->template->content->default_decayimage_thumb = $default_decayimage_thumb;
     $this->template->content->decayimages = $decayimages;
     $this->template->content->form_error = $form_error;
     $this->template->content->form_saved = $form_saved;
     $this->template->js = new View('decayimage/settings_js');
     $this->template->js->default_decayimage_thumb = $default_decayimage_thumb;
 }