Example #1
0
 /**
  * Merges an ORM_Validation_Exception object into the current exception
  * Useful when you want to combine errors into one array
  *
  * @param  ORM_Validation_Exception $object   The exception to merge
  * @param  mixed                    $has_many The array key to use if this exception can be merged multiple times
  * @return ORM_Validation_Exception
  */
 public function merge(ORM_Validation_Exception $object, $has_many = FALSE)
 {
     $alias = $object->alias();
     // We will need this when generating errors
     $this->_objects[$alias]['_has_many'] = $has_many !== FALSE;
     if ($has_many === TRUE) {
         // This is most likely a has_many relationship
         $this->_objects[$alias][] = $object->objects();
     } elseif ($has_many) {
         // This is most likely a has_many relationship
         $this->_objects[$alias][$has_many] = $object->objects();
     } else {
         $this->_objects[$alias] = $object->objects();
     }
     return $this;
 }
Example #2
0
 public function delete()
 {
     if ($this->id == 1) {
         $v = new Validation(array("id"));
         $v->add_error("id", "cant_delete_root_album");
         ORM_Validation_Exception::handle_validation($this->table_name, $v);
     }
     $old = clone $this;
     module::event("item_before_delete", $this);
     $parent = $this->parent();
     if ($parent->album_cover_item_id == $this->id) {
         item::remove_album_cover($parent);
     }
     $path = $this->file_path();
     $resize_path = $this->resize_path();
     $thumb_path = $this->thumb_path();
     parent::delete();
     if (is_dir($path)) {
         // Take some precautions against accidentally deleting way too much
         $delete_resize_path = dirname($resize_path);
         $delete_thumb_path = dirname($thumb_path);
         if ($delete_resize_path == VARPATH . "resizes" || $delete_thumb_path == VARPATH . "thumbs" || $path == VARPATH . "albums") {
             throw new Exception("@todo DELETING_TOO_MUCH ({$delete_resize_path}, {$delete_thumb_path}, {$path})");
         }
         @dir::unlink($path);
         @dir::unlink($delete_resize_path);
         @dir::unlink($delete_thumb_path);
     } else {
         @unlink($path);
         @unlink($resize_path);
         @unlink($thumb_path);
     }
     module::event("item_deleted", $old);
 }
Example #3
0
 public function action_home($page = null)
 {
     // To store any form errors
     $errors = array();
     // Store success message
     $session = Session::instance();
     $success_message = null;
     if ($session->get('success_message')) {
         $success_message = $session->get('success_message');
         $session->delete('success_message');
     }
     $this->template->scripts = array('media/js/contact.js');
     // Make sure this is a POST request
     if ($this->request->method() == 'POST') {
         // Get required parameters from the web form for the request
         $fields = array();
         $fields['name'] = urlencode(arr::get($_POST, 'name'));
         $fields['company'] = urlencode(arr::get($_POST, 'company'));
         $fields['email'] = arr::get($_POST, 'email');
         $fields['website'] = arr::get($_POST, 'website');
         $fields['subject'] = urlencode(arr::get($_POST, 'subject'));
         $fields['message'] = urlencode(arr::get($_POST, 'message'));
         // validates fields
         $validation = Validation::factory($fields);
         $contact = new Model_Contact();
         $rules = $contact->rules();
         $validation->rules('name', $rules['name'])->rules('company', $rules['company'])->rules('email', $rules['email'])->rules('website', $rules['website'])->rules('subject', $rules['subject'])->rules('message', $rules['message']);
         if ($validation->check()) {
             // Send email to admin
             $template = View::factory('emails/contact', array('name' => $fields['name'], 'company' => $fields['company'], 'email' => $fields['email'], 'website' => $fields['website'], 'subject' => $fields['subject'], 'message' => $fields['message']))->render();
             Email::send($this->config['global']['email_info'], $fields['email'], $fields['subject'], $template, TRUE);
             // Redirect user
             $session->set('success_message', "Thank you. Your message was successfully sent.");
             $this->request->redirect('/contact');
         } else {
             // If form did not pass, get errors
             $e = new ORM_Validation_Exception('payment', $validation);
             $errors = $e->errors('models');
         }
     }
     $this->template->title = __("Contact Us  - gowork@");
     $this->template->content = View::factory("static/contact_us", array('errors' => $errors, 'success_message' => $success_message));
 }
Example #4
0
 /**
  * Merges an ORM_Validation_Exception object into the current exception
  * Useful when you want to combine errors into one array
  *
  * @param  string                   $alias    The relationship alias from the model
  * @param  ORM_Validation_Exception $object   The exception to merge
  * @param  mixed                    $has_many The array key to use if this exception can be merged multiple times
  * @return ORM_Validation_Exception
  */
 public function merge($alias, ORM_Validation_Exception $object, $has_many = FALSE)
 {
     if ($has_many === TRUE) {
         // This is most likely a has_many relationship
         $this->_objects[$alias][] = $object->objects();
     } elseif ($has_many) {
         // This is most likely a has_many relationship
         $this->_objects[$alias][$has_many] = $object->objects();
     } else {
         $this->_objects[$alias] = $object->objects();
     }
     return $this;
 }
Example #5
0
 /**
  * Validates the current model's data
  *
  * @param  Validation $extra_validation Validation object [Optional]
  * @return ORM
  * @throws ORM_Validation_Exception
  */
 public function check(Validation $extra_validation = NULL)
 {
     // Determine if any external validation failed
     $extra_errors = ($extra_validation and !$extra_validation->check());
     // Always build a new validation object
     $this->_validation();
     // add custom rules to $this->_validation();
     Module::event($this->_object_name . '_validation', $this->_validation, $extra_errors);
     $array = $this->_validation;
     if (($this->_valid = $array->check()) === FALSE or $extra_errors) {
         $exception = new ORM_Validation_Exception($this->errors_filename(), $array);
         if ($extra_errors) {
             // Merge any possible errors from the external object
             $exception->add_object('_external', $extra_validation);
         }
         // Fixed memory leak @http://dev.kohanaframework.org/issues/4286
         $this->_validation = NULL;
         throw $exception;
     }
     // Fixed memory leak @http://dev.kohanaframework.org/issues/4286
     $this->_validation = NULL;
     return $this;
 }
Example #6
0
 /**
  * Validates the current object. This method requires that rules are set to be useful, if called with out
  * any rules set, or if a Validation object isn't passed, nothing happens.
  *
  * @param   object   Validation array
  * @param   boolean  Save on validate
  * @return  ORM
  * @chainable
  */
 public function validate(Validation $array = NULL)
 {
     if ($array === NULL) {
         $array = new Validation($this->object);
     }
     if (count($this->rules) > 0) {
         foreach ($this->rules as $field => $parameters) {
             foreach ($parameters as $type => $value) {
                 switch ($type) {
                     case 'pre_filter':
                         $array->pre_filter($value, $field);
                         break;
                     case 'rules':
                         $rules = array_merge(array($field), $value);
                         call_user_func_array(array($array, 'add_rules'), $rules);
                         break;
                     case 'callbacks':
                         $callbacks = array_merge(array($field), $value);
                         call_user_func_array(array($array, 'add_callbacks'), $callbacks);
                         break;
                 }
             }
         }
     }
     // Validate the array
     if (($this->_valid = $array->validate()) === FALSE) {
         ORM_Validation_Exception::handle_validation($this->table_name, $array);
     }
     // Fields may have been modified by filters
     $this->object = array_merge($this->object, $array->getArrayCopy());
     // Return validation status
     return $this;
 }
Example #7
0
 /**
  * Validates the current model's data
  *
  * @param  Validation $extra_validation Validation object
  * @return ORM
  */
 public function check(Validation $extra_validation = NULL)
 {
     // Determine if any external validation failed
     $extra_errors = ($extra_validation and !$extra_validation->check());
     // Always build a new validation object
     $this->_validation();
     $array = $this->_validation;
     if (($this->_valid = $array->check()) === FALSE or $extra_errors) {
         $exception = new ORM_Validation_Exception($this->errors_filename(), $array);
         if ($extra_errors) {
             // Merge any possible errors from the external object
             $exception->add_object('_external', $extra_validation);
         }
         throw $exception;
     }
     return $this;
 }
Example #8
0
 protected function errors_extract(ORM_Validation_Exception $e)
 {
     $errors = $e->errors('');
     if (!empty($errors['_files'])) {
         $errors = array_merge($errors, $errors['_files']);
         unset($errors['_files']);
     }
     if (!empty($errors['_external'])) {
         $errors = array_merge($errors, $errors['_external']);
         unset($errors['_external']);
     }
     return $errors;
 }
Example #9
0
 /**
  * Shows the payment form
  */
 public function action_home()
 {
     // To store any form errors
     $errors = array();
     // Check for a valid AD session form
     $session = Session::instance();
     $temp_ad = $session->get('temp_ad');
     // Redirects user to the create form if temp ad was not found
     if (!$temp_ad) {
         $this->request->redirect('/ads/create');
     }
     $amount = $this->config['ad']['price_base'];
     if (1 == $temp_ad['highlight']) {
         $amount += $this->config['ad']['price_highlight'];
     }
     // Make sure this is a POST request
     if ($this->request->method() == 'POST') {
         // Get required parameters from the web form for the request
         $fields['paymentType'] = urlencode('Sale');
         $fields['amount'] = $this->config['ad']['price_base'];
         $fields['amount'] += $amount;
         $fields['currencyCode'] = 'USD';
         $fields['firstName'] = urlencode(arr::get($_POST, 'firstName'));
         $fields['lastName'] = urlencode(arr::get($_POST, 'lastName'));
         $fields['creditCardType'] = urlencode(arr::get($_POST, 'creditCardType'));
         $fields['creditCardNumber'] = urlencode(arr::get($_POST, 'creditCardNumber'));
         $fields['expDateMonth'] = urlencode(arr::get($_POST, 'expDateMonth'));
         $fields['expDateYear'] = urlencode(arr::get($_POST, 'expDateYear'));
         $fields['cvv2Number'] = urlencode(arr::get($_POST, 'cvv2Number'));
         $fields['address1'] = urlencode(arr::get($_POST, 'address1'));
         $fields['city'] = urlencode(arr::get($_POST, 'city'));
         $fields['state'] = urlencode(arr::get($_POST, 'state'));
         $fields['zip'] = urlencode(arr::get($_POST, 'zip'));
         $fields['country'] = urlencode(arr::get($_POST, 'country'));
         // validates fields
         $validation = Validation::factory($fields);
         $payment = new Model_Payment();
         $rules = $payment->rules();
         $validation->rules('paymentType', $rules['paymentType'])->rules('amount', $rules['amount'])->rules('currencyCode', $rules['currencyCode'])->rules('firstName', $rules['firstName'])->rules('lastName', $rules['lastName'])->rules('creditCardType', $rules['creditCardType'])->rules('creditCardNumber', $rules['creditCardNumber'])->rules('expDateMonth', $rules['expDateMonth'])->rules('expDateYear', $rules['expDateYear'])->rules('cvv2Number', $rules['cvv2Number'])->rules('address1', $rules['address1'])->rules('city', $rules['city'])->rules('state', $rules['state'])->rules('zip', $rules['zip'])->rules('country', $rules['country']);
         if ($validation->check()) {
             // Data seems good, try to send ti to paypal
             $result = $payment->transaction($fields);
             if ($result) {
                 // Adds AD to DB
                 $ad = ORM::factory('ad');
                 $ad->set_fields($temp_ad);
                 $ad->active = 1;
                 // Ugly ugly hack !
                 $ad->_valid = TRUE;
                 $ad->save();
                 // Deleted session
                 $session->delete('temp_ad');
                 // Create temp session value
                 $session->set('ad_created_id', $ad->id);
                 // Send email to client
                 $this->request->redirect('/payment/complete');
             } else {
                 $errors['paypal'] = $payment->resArray['L_LONGMESSAGE0'];
             }
         } else {
             // If form did not pass, get errors
             $e = new ORM_Validation_Exception('payment', $validation);
             $errors = $e->errors('models');
         }
     }
     // Fixed arrays
     $creditCardTypes = array('Visa' => 'Visa', 'MasterCard' => 'MasterCard', 'Discover' => 'Discover', 'Amex' => 'Amex');
     // Months
     $expDateMonths = array('01' => '01', '02' => '02', '03' => '03', '04' => '04', '05' => '05', '06' => '06', '07' => '07', '08' => '08', '09' => '09', '10' => '10', '11' => '11', '12' => '12');
     // Years
     $expDateYears = array();
     for ($i = date('Y'); $i <= (int) date('Y') + 10; $i++) {
         $expDateYears[$i] = $i;
     }
     $this->template->scripts = array('media/js/payment.js');
     // Show view
     $this->template->title = __('Purchase and complete (Final step)');
     $this->template->content = View::factory('payment/purchase', array('creditCardTypes' => $creditCardTypes, 'expDateMonths' => $expDateMonths, 'expDateYears' => $expDateYears, 'countries' => $this->country_list(), 'errors' => $errors, 'temp_payment' => $_POST, 'amount' => $amount));
 }
Example #10
0
 /**
  * It will display the form to create a new AD
  */
 public function action_create()
 {
     die;
     // To store any form errors
     $errors = array();
     // Start session
     $session = Session::instance();
     // Set default discount code
     $discount_code = Arr::get($_POST, 'discount_code', Arr::get($session->get('temp_ad'), 'discount_code'));
     if (!isset($this->config['paypal'][$discount_code])) {
         $discount_code = null;
     }
     // Make sure this is a POST request
     if ($this->request->method() == 'POST') {
         // Deletes session data
         $session->delete('temp_ad');
         // validates form
         $ad = ORM::factory('ad');
         $ad->set_fields($_POST);
         $ad->company_logo = arr::get($_FILES, 'company_logo');
         // Check if form is valid
         if ($ad->validation()->check()) {
             $ad->company_logo = $this->save_image($_FILES['company_logo']);
             $session->set('temp_ad', array('title' => $ad->title, 'description' => $ad->description, 'budget' => $ad->budget, 'category_id' => $ad->category_id, 'jobtype_id' => $ad->jobtype_id, 'contact' => $ad->contact, 'telecommute' => $ad->telecommute, 'location' => $ad->location, 'highlight' => $ad->highlight, 'private_company' => arr::get($_POST, 'private_company', 0), 'company_logo' => $ad->company_logo, 'company_name' => $ad->company_name, 'company_url' => $ad->company_url, 'company_address' => $ad->company_address, 'email' => $ad->email, 'jobboard_id' => 1, 'discount_code' => $ad->discount_code));
             // Redirects user to the preview
             $this->request->redirect('/ads/preview');
         } else {
             // If form did not pass, get errors
             $e = new ORM_Validation_Exception('ad', $ad->validation());
             $errors = $e->errors('models');
         }
     }
     $this->template->scripts = array('media/js/tiny_mce/jquery.tinymce.js', 'media/js/create.js');
     $this->template->title = __('Create Ad (Step 1) - gowork@');
     $this->template->content = View::factory('ads/create', array('categories' => array_merge(array('--'), ORM::factory('category')->find_all()->as_array('id', 'name')), 'jobtypes' => array_merge(array('--'), ORM::factory('jobtype')->find_all()->as_array('id', 'name')), 'errors' => $errors, 'temp_ad' => $session->get('temp_ad'), 'price_highlight' => $this->config['paypal'][$discount_code]['price_highlight']));
 }
Example #11
0
 /**
  * Set validation errors.
  *
  * @param ORM_Validation_Exception|Validation $validation
  * @param string $file File or directory to error messages.
  * @return mixed
  */
 public static function validation($validation, $file = 'models')
 {
     $messages = $validation->errors($file);
     self::$_data[Messages::VALIDATION] = !empty(self::$_data[Messages::VALIDATION]) ? Arr::merge(self::$_data[Messages::VALIDATION], $messages) : $messages;
 }