/** * creates a user from email if exists doesn't... * @param string $email * @param string $name * @param string $password * @return Model_User */ public static function create_email($email, $name = NULL, $password = NULL) { $user = new self(); $user->where('email', '=', $email)->limit(1)->find(); if (!$user->loaded()) { if ($password === NULL) { $password = Text::random('alnum', 8); } $user->email = $email; $user->name = ($name === NULL or !isset($name)) ? substr($email, 0, strpos($email, '@')) : $name; $user->status = self::STATUS_ACTIVE; $user->id_role = Model_Role::ROLE_USER; $user->seoname = $user->gen_seo_title($user->name); $user->password = $password; $user->subscriber = 1; $user->last_ip = ip2long(Request::$client_ip); $user->country = euvat::country_code(); //geo info EU try { $user->save(); //send welcome email $url = $user->ql('oc-panel', array('controller' => 'profile', 'action' => 'edit'), TRUE); $user->email('auth-register', array('[USER.PWD]' => $password, '[URL.QL]' => $url)); } catch (ORM_Validation_Exception $e) { throw HTTP_Exception::factory(500, $e->getMessage()); } } return $user; }
/** * returns the price of the product checking if there's an offer or coupon * @param boolean $calculate_VAT * @return float */ public function final_price($calculate_VAT = TRUE) { $final_price = $this->price; // no current valid offer, normal product price // no current valid coupon: check for valid curent offer if ($this->valid_coupon() === FALSE and $this->has_offer() and Date::mysql2unix($this->offer_valid) > time()) { // in case not any coupon returns the offer price if any valid one $final_price = $this->price_offer; } elseif ($this->valid_coupon() === TRUE) { //calculating price by applying either a discount amount or a discount percentage $discounted_price = abs(Model_Coupon::current()->discount_amount); if ($discounted_price > 0) { $discounted_price = round($this->price - $discounted_price, 2); } else { $discounted_price = abs(Model_Coupon::current()->discount_percentage); if ($discounted_price > 0) { $discounted_price = round($this->price - $this->price * $discounted_price / 100.0, 2); } else { // both discount_amount and discount_percentage are 0 $discounted_price = 0; } } //in case calculated price is negative $final_price = max($discounted_price, 0); } //do we need to charge vat? if (($vat = euvat::vat_percentage()) > 0 and $calculate_VAT === TRUE) { $final_price = $final_price + $vat * $final_price / 100; } //return the price return $final_price; }
public function action_edit() { $this->template->scripts['footer'] = array('js/oc-panel/edit_profile.js'); Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Edit profile'))); // $this->template->title = $user->name; //$this->template->meta_description = $user->name;//@todo phpseo $user = Auth::instance()->get_user(); $this->template->bind('content', $content); $this->template->content = View::factory('oc-panel/profile/edit', array('user' => $user, 'custom_fields' => Model_UserField::get_all())); if ($this->request->post()) { //change elastic email status, he was subscribed but not anymore if (Core::config('email.elastic_listname') != '' and $user->subscriber == 1 and core::post('subscriber', 0) == 0) { ElasticEmail::unsubscribe(Core::config('email.elastic_listname'), $user->email); } elseif (Core::config('email.elastic_listname') != '' and $user->subscriber == 0 and core::post('subscriber', 0) == 1) { ElasticEmail::subscribe(Core::config('email.elastic_listname'), $user->email, $user->name); } $user->name = core::post('name'); $user->description = core::post('description'); $user->email = core::post('email'); $user->subscriber = core::post('subscriber', 0); //$user->seoname = $user->gen_seo_title(core::post('name')); $user->last_modified = Date::unix2mysql(); //modify custom fields foreach ($this->request->post() as $custom_field => $value) { if (strpos($custom_field, 'cf_') !== FALSE) { $user->{$custom_field} = $value; } } if (core::post('cf_vatnumber') and core::post('cf_vatcountry')) { if (!euvat::verify_vies(core::post('cf_vatnumber'), core::post('cf_vatcountry'))) { Alert::set(Alert::ERROR, __('Invalid EU Vat Number, please verify number and country match')); $this->redirect(Route::url('oc-panel', array('controller' => 'profile', 'action' => 'edit'))); } } try { $user->save(); Alert::set(Alert::SUCCESS, __('You have successfully changed your data')); } catch (Exception $e) { //throw 500 throw HTTP_Exception::factory(500, $e->getMessage()); } $this->redirect(Route::url('oc-panel', array('controller' => 'profile', 'action' => 'edit'))); } }
/** * Simple register for user * */ public function action_register() { //validates captcha if (Core::post('ajaxValidateCaptcha')) { $this->auto_render = FALSE; $this->template = View::factory('js'); if (captcha::check('register', TRUE)) { $this->template->content = 'true'; } else { $this->template->content = 'false'; } return; } $this->template->meta_description = __('Create a new profile at') . ' ' . core::config('general.site_name'); $this->template->content = View::factory('pages/auth/register'); $this->template->content->msg = ''; //if user loged in redirect home if (Auth::instance()->logged_in()) { $this->redirect(Route::get('oc-panel')->uri()); } elseif ($this->request->post()) { if (captcha::check('register')) { $validation = Validation::factory($this->request->post())->rule('name', 'not_empty')->rule('email', 'not_empty')->rule('email', 'email')->rule('email', 'email_domain')->rule('password1', 'not_empty')->rule('password2', 'not_empty')->rule('password1', 'matches', array(':validation', 'password1', 'password2')); if (core::post('cf_vatnumber') and core::post('cf_vatcountry')) { if (!euvat::verify_vies(core::post('cf_vatnumber'), core::post('cf_vatcountry'))) { Alert::set(Alert::ERROR, __('Invalid EU Vat Number, please verify number and country match')); $this->redirect(Route::url('oc-panel', array('controller' => 'auth', 'action' => 'register'))); } } if ($validation->check()) { //posting data so try to remember password if (CSRF::valid('register')) { $email = core::post('email'); //check we have this email in the DB $user = new Model_User(); $user = $user->where('email', '=', $email)->limit(1)->find(); if ($user->loaded()) { Form::set_errors(array(__('User already exists'))); } else { //creating the user $user = Model_User::create_email($email, core::post('name'), core::post('password1')); //add custom fields $save_cf = FALSE; foreach ($this->request->post() as $custom_field => $value) { if (strpos($custom_field, 'cf_') !== FALSE) { $user->{$custom_field} = $value; $save_cf = TRUE; } } //saves the user only if there was CF if ($save_cf === TRUE) { $user->save(); } //login the user Auth::instance()->login(core::post('email'), core::post('password1')); Alert::set(Alert::SUCCESS, __('Welcome!')); //login the user $this->redirect(Core::post('auth_redirect', Route::url('oc-panel'))); } } } else { $errors = $validation->errors('auth'); foreach ($errors as $error) { Alert::set(Alert::ALERT, $error); } } } else { Alert::set(Alert::ALERT, __('Captcha is not correct')); } } //template header $this->template->title = __('Register new user'); }
/** * creates an order * @param Model_Ad $ad * @param Model_User $user * @param integer $id_product * @param numeric $amount * @param string $currency * @param string $description * @return Model_Order */ public static function new_order(Model_Ad $ad = NULL, $user, $id_product, $amount, $currency = NULL, $description = NULL, $featured_days = NULL) { if ($currency === NULL) { $currency = core::config('payment.paypal_currency'); } if ($description === NULL) { $description = Model_Order::product_desc($id_product); } //get if theres an unpaid order for this product and this ad $order = new Model_Order(); if ($ad !== NULL and $ad->loaded()) { $order->where('id_ad', '=', $ad->id_ad); } $order->where('id_user', '=', $user->id_user)->where('status', '=', Model_Order::STATUS_CREATED)->where('id_product', '=', $id_product)->where('amount', '=', $amount)->where('currency', '=', $currency)->limit(1)->find(); //if no unpaid create order if (!$order->loaded()) { //add coupon ID and discount only if not AD_SELL if (Model_Coupon::valid($id_product)) { $amount = Model_Coupon::price($id_product, $amount); $order->id_coupon = Model_Coupon::current()->id_coupon; } //create order $order = new Model_Order(); $order->id_user = $user->id_user; if ($ad !== NULL and $ad->loaded()) { $order->id_ad = $ad->id_ad; } $order->id_product = $id_product; $order->currency = $currency; $order->amount = $amount; $order->description = $description; // check product if ($order->id_product == Model_Order::PRODUCT_AD_SELL) { // check if ad has VAT if (isset($order->ad->cf_vatnumber) and $order->ad->cf_vatnumber and isset($order->ad->cf_vatcountry) and $order->ad->cf_vatcountry) { $order->VAT_country = $order->ad->cf_vatcountry; $order->VAT_number = $order->ad->cf_vatnumber; $order->VAT = euvat::vat_by_country($order->ad->cf_vatcountry); } elseif (isset($order->user->cf_vatnumber) and $order->user->cf_vatnumber and isset($order->user->cf_vatcountry) and $order->user->cf_vatcountry) { $order->VAT_country = $order->user->cf_vatcountry; $order->VAT_number = $order->user->cf_vatnumber; $order->VAT = euvat::vat_by_country($order->user->cf_vatcountry); } } else { if (core::config('payment.vat_country') and core::config('payment.vat_number')) { $order->VAT_country = core::config('payment.vat_country'); $order->VAT_number = core::config('payment.vat_number'); $order->VAT = euvat::vat_by_country(core::config('payment.vat_country')); } } //store how many days the ad is featured if ($featured_days !== NULL and is_numeric($featured_days)) { $order->featured_days = $featured_days; } try { $order->save(); } catch (Exception $e) { throw HTTP_Exception::factory(500, $e->getMessage()); } //send email to user with link to pay $url_checkout = $user->ql('default', array('controller' => 'ad', 'action' => 'checkout', 'id' => $order->id_order)); $replace = array('[ORDER.ID]' => $order->id_order, '[ORDER.DESC]' => $order->description, '[URL.CHECKOUT]' => $url_checkout); //$user->email('new-order',$replace); } return $order; }
/** * Edit advertisement: Update * * All post fields are validated */ public function action_update() { //template header $this->template->title = __('Edit advertisement'); $this->template->meta_description = __('Edit advertisement'); Controller::$full_width = TRUE; //local files if (Theme::get('cdn_files') == FALSE) { $this->template->styles = array('css/jquery.sceditor.default.theme.min.css' => 'screen', 'css/jasny-bootstrap.min.css' => 'screen', '//cdnjs.cloudflare.com/ajax/libs/selectize.js/0.12.1/css/selectize.bootstrap3.min.css' => 'screen', '//cdn.jsdelivr.net/sweetalert/1.1.3/sweetalert.css' => 'screen'); $this->template->scripts['footer'] = array('js/jquery.sceditor.bbcode.min.js', 'js/jasny-bootstrap.min.js', '//cdn.jsdelivr.net/sweetalert/1.1.3/sweetalert.min.js', '//cdnjs.cloudflare.com/ajax/libs/selectize.js/0.12.1/js/standalone/selectize.min.js', 'js/canvasResize.js', 'js/load-image.all.min.js', 'js/oc-panel/edit_ad.js'); $this->template->scripts['async_defer'][] = '//maps.google.com/maps/api/js?libraries=geometry&v=3&key=' . core::config("advertisement.gm_api_key") . '&callback=initLocationsGMap'; } else { $this->template->styles = array('css/jquery.sceditor.default.theme.min.css' => 'screen', '//cdnjs.cloudflare.com/ajax/libs/selectize.js/0.12.1/css/selectize.bootstrap3.min.css' => 'screen', '//cdn.jsdelivr.net/sweetalert/1.1.3/sweetalert.css' => 'screen'); $this->template->scripts['footer'] = array('js/jquery.sceditor.bbcode.min.js', '//cdn.jsdelivr.net/sweetalert/1.1.3/sweetalert.min.js', '//cdnjs.cloudflare.com/ajax/libs/selectize.js/0.12.1/js/standalone/selectize.min.js', 'js/canvasResize.js', 'js/oc-panel/edit_ad.js'); $this->template->scripts['async_defer'][] = '//maps.google.com/maps/api/js?libraries=geometry&v=3&key=' . core::config("advertisement.gm_api_key") . '&callback=initLocationsGMap'; } Breadcrumbs::add(Breadcrumb::factory()->set_title(__('My ads'))->set_url(Route::url('oc-panel', array('controller' => 'myads', 'action' => 'index')))); $form = new Model_Ad($this->request->param('id')); if ($form->loaded() and (Auth::instance()->get_user()->id_user == $form->id_user or Auth::instance()->get_user()->is_admin() or Auth::instance()->get_user()->is_moderator())) { // deleting single image by path if (is_numeric($deleted_image = core::request('img_delete'))) { $form->delete_image($deleted_image); $this->redirect(Route::url('oc-panel', array('controller' => 'myads', 'action' => 'update', 'id' => $form->id_ad))); } // end of img delete // set primary image if (is_numeric($primary_image = core::request('primary_image'))) { $form->set_primary_image($primary_image); $this->redirect(Route::url('oc-panel', array('controller' => 'myads', 'action' => 'update', 'id' => $form->id_ad))); } $original_category = $form->category; $extra_payment = core::config('payment'); if ($this->request->post()) { $data = $this->request->post(); //to make it backward compatible with older themes: UGLY!! if (isset($data['category']) and is_numeric($data['category'])) { $data['id_category'] = $data['category']; unset($data['category']); } if (isset($data['location']) and is_numeric($data['location'])) { $data['id_location'] = $data['location']; unset($data['location']); } if (isset($data['cf_vatcountry']) and $data['cf_vatcountry'] and isset($data['cf_vatnumber']) and $data['cf_vatnumber']) { if (!euvat::verify_vies($data['cf_vatnumber'], $data['cf_vatcountry'])) { Alert::set(Alert::ERROR, __('Invalid EU Vat Number, please verify number and country match')); $this->redirect(Route::url('post_new')); } } $return = $form->save_ad($data); //there was an error on the validation if (isset($return['validation_errors']) and is_array($return['validation_errors'])) { foreach ($return['validation_errors'] as $f => $err) { Alert::set(Alert::ALERT, $err); } } elseif (isset($return['error'])) { Alert::set($return['error_type'], $return['error']); } elseif (isset($return['message'])) { // IMAGE UPLOAD // in case something wrong happens user is redirected to edit advert. $filename = NULL; for ($i = 0; $i < core::config("advertisement.num_images"); $i++) { if (Core::post('base64_image' . $i)) { $filename = $form->save_base64_image(Core::post('base64_image' . $i)); } elseif (isset($_FILES['image' . $i])) { $filename = $form->save_image($_FILES['image' . $i]); } } if ($filename !== NULL) { $form->last_modified = Date::unix2mysql(); try { $form->save(); } catch (Exception $e) { throw HTTP_Exception::factory(500, $e->getMessage()); } } Alert::set(Alert::SUCCESS, $return['message']); //redirect user to pay if (isset($return['checkout_url']) and !empty($return['checkout_url'])) { $this->redirect($return['checkout_url']); } } $this->redirect(Route::url('oc-panel', array('controller' => 'myads', 'action' => 'update', 'id' => $form->id_ad))); } //get all orders $orders = new Model_Order(); $orders = $orders->where('id_user', '=', $form->id_user)->where('status', '=', Model_Order::STATUS_CREATED)->where('id_ad', '=', $form->id_ad)->find_all(); Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Update'))); $this->template->content = View::factory('oc-panel/profile/edit_ad', array('ad' => $form, 'extra_payment' => $extra_payment, 'orders' => $orders)); } else { Alert::set(Alert::ERROR, __('You dont have permission to access this link')); $this->redirect(Route::url('default')); } }
/** * verify if a transaction is fraudulent * @return boolean */ public function is_fraud() { //only production and api set if ($this->loaded() and core::config('payment.fraudlabspro') != '') { //get the country $country_code = euvat::country_code(); // Include FraudLabs Pro library require Kohana::find_file('vendor/', 'FraudLabsPro.class'); $fraud = new FraudLabsPro(core::config('payment.fraudlabspro')); try { // Check this transaction for possible fraud. FraudLabs Pro support comprehensive validation check, // and for this example, we only perform the IP address, BIN and billing country validation. // For complete validation, please check our developer page at http://www.fraudlabspro.com/developer $fraud_result = $fraud->check(array('ipAddress' => Request::$client_ip, 'billingCountry' => $country_code, 'quantity' => 1, 'amount' => $this->amount, 'currency' => $this->currency, 'emailAddress' => $this->user->email, 'paymentMode' => 'others', 'sessionId' => session_id())); $fraud_result_status = $fraud_result->fraudlabspro_status; } catch (Exception $e) { $fraud_result_status = 'DECLINED'; } // This transaction is legitimate, let's submit to Stripe if ($fraud_result_status == 'APPROVE') { return FALSE; } else { Kohana::$log->add(Log::ERROR, 'Fraud detected id_order:' . $this->id_order); return TRUE; } } //by default we say is not fraud return FALSE; }
/** * Payment deatails and paypal configuration can be configured here * @return [view] Renders view with form inputs */ public function action_payment() { //delete featured plan if (is_numeric(Core::get('delete_plan'))) { Model_Order::delete_featured_plan(Core::get('delete_plan')); $this->redirect(Route::url('oc-panel', array('controller' => 'settings', 'action' => 'payment'))); } Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Payments'))); $this->template->title = __('Payments'); // all form config values $paymentconf = new Model_Config(); $config = $paymentconf->where('group_name', '=', 'payment')->find_all(); // save only changed values if ($this->request->post()) { if (is_numeric(Core::request('featured_days')) and is_numeric(Core::request('featured_price'))) { Model_Order::set_featured_plan(Core::request('featured_days'), Core::request('featured_price'), Core::request('featured_days_key')); Alert::set(Alert::SUCCESS, __('Featured plan updated')); $this->redirect(Route::url('oc-panel', array('controller' => 'settings', 'action' => 'payment'))); } $validation = Validation::factory($this->request->post())->rule('pay_to_go_on_top', 'not_empty')->rule('pay_to_go_on_top', 'price')->rule('stripe_appfee', 'numeric')->rule('stripe_appfee', 'range', array(':value', 0, 100))->rule('to_featured', 'range', array(':value', 0, 1))->rule('to_top', 'range', array(':value', 0, 1))->rule('sandbox', 'range', array(':value', 0, 1))->rule('paypal_seller', 'range', array(':value', 0, 1))->rule('stock', 'range', array(':value', 0, 1))->rule('authorize_sandbox', 'range', array(':value', 0, 1))->rule('stripe_address', 'range', array(':value', 0, 1)); //not updatable fields $do_nothing = array('featured_days', 'pay_to_go_on_feature', 'featured_plans'); if (Core::request('vat_country') and Core::request('vat_number')) { if (!euvat::verify_vies(Core::request('vat_number'), Core::request('vat_country'))) { Alert::set(Alert::ERROR, __('Invalid EU Vat Number, please verify number and country match')); $this->redirect(Route::url('oc-panel', array('controller' => 'settings', 'action' => 'payment'))); } } if ($validation->check()) { foreach ($config as $c) { $config_res = $this->request->post($c->config_key); if (!in_array($c->config_key, $do_nothing) and $config_res != $c->config_value) { if ($c->config_key == 'pay_to_go_on_top') { $config_res = str_replace(',', '.', $config_res); } $c->config_value = $config_res; try { $c->save(); } catch (Exception $e) { throw HTTP_Exception::factory(500, $e->getMessage()); } } } } else { $errors = $validation->errors('config'); foreach ($errors as $error) { Alert::set(Alert::ALERT, $error); } $this->redirect(Route::url('oc-panel', array('controller' => 'settings', 'action' => 'payment'))); } Alert::set(Alert::SUCCESS, __('Payments Configuration updated')); $this->redirect(Route::url('oc-panel', array('controller' => 'settings', 'action' => 'payment'))); } $pages = array('' => __('Deactivated')); foreach (Model_Content::get_pages() as $key => $value) { $pages[$value->seotitle] = $value->title; } $this->template->content = View::factory('oc-panel/pages/settings/payment', array('config' => $config, 'pages' => $pages, 'featured_plans' => Model_Order::get_featured_plans())); }
/** * * NEW ADVERTISEMENT * */ public function action_index() { //advertisement.only_admin_post if (Core::config('advertisement.only_admin_post') == TRUE and (!Auth::instance()->logged_in() or Auth::instance()->logged_in() and !$this->user->is_admin())) { $this->redirect(Route::url('default')); } elseif ((Core::config('advertisement.login_to_post') == TRUE or Core::config('payment.stripe_connect') == TRUE or Core::config('general.subscriptions') == TRUE) and !Auth::instance()->logged_in()) { Alert::set(Alert::INFO, __('Please, login before posting advertisement!')); HTTP::redirect(Route::url('oc-panel', array('controller' => 'auth', 'action' => 'login')) . '?auth_redirect=' . URL::current()); } elseif (core::config('general.black_list') == TRUE and Model_User::is_spam(Core::post('email')) === TRUE) { Alert::set(Alert::ALERT, __('Your profile has been disable for posting, due to recent spam content! If you think this is a mistake please contact us.')); $this->redirect(Route::url('default')); } elseif (Core::config('payment.stripe_connect') == TRUE and empty($this->user->stripe_user_id)) { Alert::set(Alert::INFO, __('Please, connect with Stripe')); $this->redirect(Route::url('oc-panel', array('controller' => 'profile', 'action' => 'edit'))); } elseif (Core::config('general.subscriptions') == TRUE and Theme::get('premium') == TRUE) { $subscription = $this->user->subscription(); //if theres no subscription or expired or without free ads if (!$subscription->loaded() or $subscription->loaded() and (Date::mysql2unix($subscription->expire_date) < time() or $subscription->amount_ads_left == 0)) { Alert::set(Alert::INFO, __('Please, choose a plan first')); HTTP::redirect(Route::url('pricing')); } } //validates captcha if (Core::post('ajaxValidateCaptcha')) { $this->auto_render = FALSE; $this->template = View::factory('js'); if (captcha::check('publish_new', TRUE)) { $this->template->content = 'true'; } else { $this->template->content = 'false'; } return; } Controller::$full_width = TRUE; //template header $this->template->title = __('Publish new advertisement'); $this->template->meta_description = __('Publish new advertisement'); $this->template->styles = array('css/jquery.sceditor.default.theme.min.css' => 'screen', 'css/jasny-bootstrap.min.css' => 'screen', '//cdnjs.cloudflare.com/ajax/libs/selectize.js/0.12.1/css/selectize.bootstrap3.min.css' => 'screen', '//cdn.jsdelivr.net/sweetalert/1.1.3/sweetalert.css' => 'screen'); $this->template->scripts['footer'][] = 'js/jquery.sceditor.bbcode.min.js'; $this->template->scripts['footer'][] = 'js/jasny-bootstrap.min.js'; $this->template->scripts['footer'][] = '//cdn.jsdelivr.net/sweetalert/1.1.3/sweetalert.min.js'; $this->template->scripts['footer'][] = '//cdnjs.cloudflare.com/ajax/libs/selectize.js/0.12.1/js/standalone/selectize.min.js'; $this->template->scripts['footer'][] = '//cdnjs.cloudflare.com/ajax/libs/ouibounce/0.0.10/ouibounce.min.js'; $this->template->scripts['footer'][] = 'js/canvasResize.js'; $this->template->scripts['footer'][] = 'js/load-image.all.min.js'; if (core::config('advertisement.map_pub_new')) { $this->template->scripts['async_defer'][] = '//maps.google.com/maps/api/js?libraries=geometry&v=3&key=' . core::config("advertisement.gm_api_key") . '&callback=initLocationsGMap'; } $this->template->scripts['footer'][] = 'js/new.js?v=' . Core::VERSION; $categories = new Model_Category(); $categories = $categories->where('id_category_parent', '=', '1'); // NO categories redirect ADMIN to categories panel if ($categories->count_all() == 0) { if (Auth::instance()->logged_in() and Auth::instance()->get_user()->is_admin()) { Alert::set(Alert::INFO, __('Please, first create some categories.')); $this->redirect(Route::url('oc-panel', array('controller' => 'category', 'action' => 'index'))); } else { Alert::set(Alert::INFO, __('Posting advertisements is not yet available.')); $this->redirect(Route::url('default')); } } //get locations $locations = new Model_Location(); $locations = $locations->where('id_location', '!=', '1'); // bool values from DB, to show or hide this fields in view $form_show = array('captcha' => core::config('advertisement.captcha'), 'website' => core::config('advertisement.website'), 'phone' => core::config('advertisement.phone'), 'location' => core::config('advertisement.location'), 'description' => core::config('advertisement.description'), 'address' => core::config('advertisement.address'), 'price' => core::config('advertisement.price')); $id_category = NULL; $selected_category = new Model_Category(); //if theres a category by post or by get if (Core::request('category') !== NULL) { if (is_numeric(Core::request('category'))) { $selected_category->where('id_category', '=', core::request('category'))->limit(1)->find(); } else { $selected_category->where('seoname', '=', core::request('category'))->limit(1)->find(); } if ($selected_category->loaded()) { $id_category = $selected_category->id_category; } } $id_location = NULL; $selected_location = new Model_Location(); //if theres a location by post or by get if (Core::request('location') !== NULL) { if (is_numeric(Core::request('location'))) { $selected_location->where('id_location', '=', core::request('location'))->limit(1)->find(); } else { $selected_location->where('seoname', '=', core::request('location'))->limit(1)->find(); } if ($selected_location->loaded()) { $id_location = $selected_location->id_location; } } //render view publish new $this->template->content = View::factory('pages/ad/new', array('form_show' => $form_show, 'id_category' => $id_category, 'selected_category' => $selected_category, 'id_location' => $id_location, 'selected_location' => $selected_location, 'fields' => Model_Field::get_all())); if ($this->request->post()) { if (captcha::check('publish_new')) { $data = $this->request->post(); $validation = Validation::factory($data); //validate location since its optional if (core::config('advertisement.location')) { if ($locations->count_all() > 1) { $validation = $validation->rule('location', 'not_empty')->rule('location', 'digit'); } } //user is not logged in validate input if (!Auth::instance()->logged_in()) { $validation = $validation->rule('email', 'not_empty')->rule('email', 'email')->rule('email', 'email_domain')->rule('name', 'not_empty')->rule('name', 'min_length', array(':value', 2))->rule('name', 'max_length', array(':value', 145)); } // Optional banned words validation if (core::config('advertisement.validate_banned_words')) { $validation = $validation->rule('title', 'no_banned_words'); $validation = $validation->rule('description', 'no_banned_words'); } if (isset($data['cf_vatcountry']) and $data['cf_vatcountry'] and isset($data['cf_vatnumber']) and $data['cf_vatnumber']) { if (!euvat::verify_vies($data['cf_vatnumber'], $data['cf_vatcountry'])) { Alert::set(Alert::ERROR, __('Invalid EU Vat Number, please verify number and country match')); $this->redirect(Route::url('post_new')); } } if ($validation->check()) { // User detection, if doesnt exists create if (!Auth::instance()->logged_in()) { $user = Model_User::create_email(core::post('email'), core::post('name')); } else { $user = Auth::instance()->get_user(); } //to make it backward compatible with older themes: UGLY!! if (isset($data['category']) and is_numeric($data['category'])) { $data['id_category'] = $data['category']; unset($data['category']); } if (isset($data['location']) and is_numeric($data['location'])) { $data['id_location'] = $data['location']; unset($data['location']); } //lets create!! $return = Model_Ad::new_ad($data, $user); //there was an error on the validation if (isset($return['validation_errors']) and is_array($return['validation_errors'])) { foreach ($return['validation_errors'] as $f => $err) { Alert::set(Alert::ALERT, $err); } } elseif (isset($return['error'])) { Alert::set($return['error_type'], $return['error']); } elseif (isset($return['message']) and isset($return['ad'])) { $new_ad = $return['ad']; // IMAGE UPLOAD $filename = NULL; for ($i = 0; $i < core::config('advertisement.num_images'); $i++) { if (Core::post('base64_image' . $i)) { $filename = $new_ad->save_base64_image(Core::post('base64_image' . $i)); } elseif (isset($_FILES['image' . $i])) { $filename = $new_ad->save_image($_FILES['image' . $i]); } } Alert::set(Alert::SUCCESS, $return['message']); //redirect user if (isset($return['checkout_url']) and !empty($return['checkout_url'])) { $this->redirect($return['checkout_url']); } else { $this->redirect(Route::url('default', array('action' => 'thanks', 'controller' => 'ad', 'id' => $new_ad->id_ad))); } } } else { $errors = $validation->errors('ad'); foreach ($errors as $f => $err) { Alert::set(Alert::ALERT, $err); } } } else { Alert::set(Alert::ALERT, __('Captcha is not correct')); } } }
<td></td> <td></td> <td class="text-right"> <h4><?php echo __('VAT'); ?> <?php echo round($order->VAT, 1); ?> %</h4> <small> <?php echo euvat::country_name($order->country); ?> <?php echo (euvat::is_eu_country($order->country) and strlen($order->VAT_number) > 2) ? 'VIES' : ''; ?> </small> </td> <td class="text-center"><h4> <?php if (!$order->coupon->loaded()) { ?> <?php echo i18n::format_currency($order->VAT * $order->product->price / 100, $order->currency); ?> <?php } else { ?> <?php echo i18n::format_currency($order->VAT * ($order->product->price - $discount) / 100, $order->currency);
public function action_billing() { Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Billing Information'))); $this->template->title = __('Billing Information'); $user = Auth::instance()->get_user(); $this->template->bind('content', $content); $this->template->content = View::factory('oc-panel/profile/edit', array('user' => $user)); $this->template->content->msg = ''; if ($this->request->post()) { $user = Auth::instance()->get_user(); $user->country = core::post('country'); $user->city = core::post('city'); $user->postal_code = core::post('postal_code'); $user->address = core::post('address'); $user->last_modified = Date::unix2mysql(); $user->VAT_number = core::post('VAT_number'); //theres VAT sent if (core::post('VAT_number') != NULL) { //if VAT submited and country is from EU verify it, not valid do not store it and display on page if (!euvat::verify_vies(core::post('VAT_number'), $user->country)) { Alert::set(Alert::ERROR, __('Invalid EU Vat Number, please verify number and country match')); $this->redirect(Route::url('oc-panel', array('controller' => 'profile', 'action' => 'billing')) . '?order_id=' . core::request('order_id') . ''); } } //save user data try { $user->save(); Alert::set(Alert::SUCCESS, __('Billing information changed')); } catch (ORM_Validation_Exception $e) { Form::set_errors($e->errors('')); } catch (Exception $e) { throw HTTP_Exception::factory(500, $e->getMessage()); } //in case there was an order rediret him to checkout if (is_numeric(core::request('order_id'))) { $this->redirect(Route::url('default', array('controller' => 'product', 'action' => 'checkout', 'id' => core::request('order_id')))); } } }