public function form() { \CI::form_validation()->set_rules('to_email', 'lang:recipient_email', 'trim|required'); \CI::form_validation()->set_rules('to_name', 'lang:recipient_name', 'trim|required'); \CI::form_validation()->set_rules('from', 'lang:sender_name', 'trim|required'); \CI::form_validation()->set_rules('personal_message', 'lang:personal_message', 'trim'); \CI::form_validation()->set_rules('beginning_amount', 'lang:amount', 'trim|required|numeric'); $data['page_title'] = lang('add_gift_card'); if (\CI::form_validation()->run() == FALSE) { $this->view('gift_card_form', $data); } else { $save['code'] = generate_code(); // from the string helper $save['to_email'] = \CI::input()->post('to_email'); $save['to_name'] = \CI::input()->post('to_name'); $save['from'] = \CI::input()->post('from'); $save['personal_message'] = \CI::input()->post('personal_message'); $save['beginning_amount'] = \CI::input()->post('beginning_amount'); \CI::GiftCards()->saveCard($save); if (\CI::input()->post('sendNotification')) { \GoCart\Emails::giftCardNotification($save); } \CI::session()->set_flashdata('message', lang('message_saved_gift_card')); redirect('admin/gift-cards'); } }
public function login() { $redirect = \CI::auth()->isLoggedIn(false, false); if ($redirect) { redirect('admin/dashboard'); } \CI::load()->helper('form'); $data['redirect'] = \CI::session()->flashdata('redirect'); $submitted = \CI::input()->post('submitted'); if ($submitted) { $username = \CI::input()->post('username'); $password = \CI::input()->post('password'); $remember = \CI::input()->post('remember'); $redirect = \CI::input()->post('redirect'); $login = \CI::auth()->login_admin($username, $password, $remember); if ($login) { if ($redirect == '') { $redirect = 'admin/dashboard'; } redirect($redirect); } else { //this adds the redirect back to flash data if they provide an incorrect credentials \CI::session()->set_flashdata('redirect', $redirect); \CI::session()->set_flashdata('error', lang('error_authentication_failed')); redirect('admin/login'); } } $this->views->show('admin/header', $data); $this->views->show('admin/login', $data); $this->views->show('admin/footer', $data); }
public function form($direction = false, $id = false) { $data = array(); if ($direction == 'coefficients') { $data = array('code' => \CI::input()->post('code'), 'value' => \CI::input()->post('value'), 'description' => \CI::input()->post('description'), 'group' => \CI::input()->post('group')); } if ($direction == 'constants') { $data = array('code' => \CI::input()->post('code'), 'value' => \CI::input()->post('value'), 'description' => \CI::input()->post('description'), 'group' => \CI::input()->post('group')); } if ($direction == 'febrifuge') { $data = array('kVA' => \CI::input()->post('kVA'), 'width' => \CI::input()->post('width'), 'height' => \CI::input()->post('height'), 'value_vtp' => \CI::input()->post('value_vtp'), 'note' => \CI::input()->post('note')); } if ($direction == 'basic') { $data = array('code' => \CI::input()->post('code'), 'description' => \CI::input()->post('description'), 'value' => \CI::input()->post('value'), 'condition' => \CI::input()->post('condition'), 'condition_value' => \CI::input()->post('condition_value'), 'unit' => \CI::input()->post('unit'), 'group' => \CI::input()->post('group')); } if ($direction == 'funnel') { $data = array('phi' => \CI::input()->post('phi'), 'value_mabi' => \CI::input()->post('value_mabi'), 'value_coha' => \CI::input()->post('value_coha'), 'value_vtp' => \CI::input()->post('value_vtp'), 'value_noch' => \CI::input()->post('value_noch'), 'value_onnh' => \CI::input()->post('value_onnh'), 'description' => \CI::input()->post('description'), 'group' => \CI::input()->post('group'), 'note' => \CI::input()->post('note')); } if ($direction == 'cable') { $data = array('kVA' => \CI::input()->post('kVA'), 'ampe' => \CI::input()->post('ampe'), 'section' => \CI::input()->post('section'), 'trademark' => \CI::input()->post('trademark'), 'symbol' => \CI::input()->post('symbol'), 'unit' => \CI::input()->post('unit'), 'value' => \CI::input()->post('value'), 'description' => \CI::input()->post('description'), 'note' => \CI::input()->post('note')); } if (!empty($_POST)) { if ($id) { \CI::db()->where('id', $id)->update($this->_db_table[$direction], $data); return; } else { \CI::db()->insert($this->_db_table[$direction], $data); redirect('admin/materials/' . $direction); } } }
public function generateProducts() { $limit = \CI::input()->post('limit'); $offset = \CI::input()->post('col-md-offset-'); $products = \CI::Products()->products(['rows' => $limit, 'page' => $offset]); $xml = $this->partial('product_xml', ['products' => $products], true); echo $xml; $file = fopen('sitemap.xml', 'a'); fwrite($file, $xml); fclose($file); }
public function index($code = false, $page = 0) { $pagination_base_url = site_url('search/' . $code); //how many products do we want to display per page? //this is configurable from the admin settings page. $per_page = config_item('products_per_page'); \CI::load()->model('Search'); //check to see if we have a search term if (!$code) { //if the term is in post, save it to the db and give me a reference $term = \CI::input()->post('term', true); if (empty($term)) { //if there is still no search term throw an error $data['error'] = lang('search_error'); $this->view('search_error', $data); return; } else { $code = \CI::Search()->recordTerm($term); // no code? redirect so we can have the code in place for the sorting. // I know this isn't the best way... redirect('search/' . $code . '/' . $page); } } else { //if we have the md5 string, get the term $term = \CI::Search()->getTerm($code); } //fix for the category view page. $data['base_url'] = []; $sortArray = array('name/asc' => array('by' => 'name', 'sort' => 'ASC'), 'name/desc' => array('by' => 'name', 'sort' => 'DESC'), 'price/asc' => array('by' => 'price', 'sort' => 'ASC'), 'price/desc' => array('by' => 'price', 'sort' => 'DESC')); $sortBy = array('by' => false, 'sort' => false); if (isset($_GET['by'])) { if (isset($sortArray[$_GET['by']])) { $sortBy = $sortArray[$_GET['by']]; } } if (empty($term)) { //if there is still no search term throw an error $this->view('search_error', $data); return; } else { $result = \CI::Products()->search_products($term, $per_page, $page, $sortBy['by'], $sortBy['sort']); $config['total_rows'] = $result['count']; \CI::load()->library('pagination'); $config['base_url'] = $pagination_base_url; $config['uri_segment'] = 3; $config['per_page'] = $per_page; $config['num_links'] = 3; $config['total_rows'] = $result['count']; \CI::pagination()->initialize($config); $data['products'] = $result['products']; $data['category'] = (object) ['name' => str_replace('{term}', $term, lang('search_title'))]; $this->view('categories/category', $data); } }
public function form() { //this same function processes the form \CI::load()->helper('form'); \CI::load()->library('form_validation'); \CI::form_validation()->set_rules('enabled', 'lang:enabled', 'trim|numeric'); \CI::form_validation()->set_rules('rate', 'lang:rate', 'trim|floatval'); if (\CI::form_validation()->run() == FALSE) { $settings = \CI::Settings()->get_settings('FlatRate'); $this->view('flat_rate_form', $settings); } else { \CI::Settings()->save_settings('FlatRate', \CI::input()->post()); redirect('admin/shipping'); } }
public function form($id = 0) { \CI::load()->helper('form_helper'); \CI::load()->library('form_validation'); \CI::form_validation()->set_error_delimiters('<div class="error">', '</div>'); $data = ['id' => '', 'filename' => '', 'max_downloads' => '', 'title' => '', 'size' => '']; if ($id) { $data = array_merge($data, (array) \CI::DigitalProducts()->getFileInfo($id)); } $data['page_title'] = lang('digital_products_form'); \CI::form_validation()->set_rules('max_downloads', 'lang:max_downloads', 'numeric'); \CI::form_validation()->set_rules('title', 'lang:title', 'trim|required'); if (\CI::form_validation()->run() == FALSE) { $this->view('digital_product_form', $data); } else { if ($id == 0) { $data['file_name'] = false; $data['error'] = false; $config['allowed_types'] = '*'; $config['upload_path'] = 'uploads/digital_products'; //config_item('digital_products_path'); $config['remove_spaces'] = true; \CI::load()->library('upload', $config); if (\CI::upload()->do_upload()) { $upload_data = \CI::upload()->data(); } else { $data['error'] = \CI::upload()->display_errors(); $this->view('digital_product_form', $data); return; } $save['filename'] = $upload_data['file_name']; $save['size'] = $upload_data['file_size']; } else { $save['id'] = $id; } $save['max_downloads'] = \CI::input()->post('max_downloads'); $save['title'] = \CI::input()->post('title'); \CI::DigitalProducts()->save($save); redirect('admin/digital_products'); } }
public function forgotPassword() { $data['page_title'] = lang('forgot_password'); $submitted = \CI::input()->post('submitted'); \CI::form_validation()->set_rules('email', 'lang:address_email', ['trim', 'required', 'valid_email', ['email_callable', function ($str) { $reset = \CI::Customers()->reset_password($str); if (!$reset) { \CI::form_validation()->set_message('email_callable', lang('error_no_account_record')); return FALSE; } else { //user does exist. and the password is reset. return TRUE; } }]]); if (\CI::form_validation()->run() == FALSE) { $this->view('forgot_password', $data); } else { \CI::session()->set_flashdata('message', lang('message_new_password')); redirect('login'); } }
public function submitGiftCard() { //get the giftcards from the database $giftCard = \CI::GiftCards()->getGiftCard(\CI::input()->post('gift_card')); if (!$giftCard) { echo json_encode(['error' => lang('gift_card_not_exist')]); } else { //does the giftcard have any value left? if (\CI::GiftCards()->isValid($giftCard)) { $message = \GC::addGiftCard($giftCard); if ($message['success']) { \GC::saveCart(); echo json_encode(['message' => lang('gift_card_balance_applied')]); } else { echo json_encode($message); } } else { echo json_encode(['error' => lang('gift_card_zero_balance')]); } } }
public function index() { $redirect = \CI::Login()->isLoggedIn(false, false); //if they are logged in, we send them back to the my_account by default if ($redirect) { redirect('my-account'); } \CI::load()->library('form_validation'); //default values are empty if the customer is new $data = ['company' => '', 'firstname' => '', 'lastname' => '', 'email' => '', 'phone' => '', 'address1' => '', 'address2' => '', 'city' => '', 'state' => '', 'zip' => '', 'redirect' => \CI::session()->flashdata('redirect')]; \CI::form_validation()->set_rules('company', 'lang:address_company', 'trim|max_length[128]'); \CI::form_validation()->set_rules('firstname', 'lang:address_firstname', 'trim|required|max_length[32]'); \CI::form_validation()->set_rules('lastname', 'lang:address_lastname', 'trim|required|max_length[32]'); \CI::form_validation()->set_rules('email', 'lang:address_email', ['trim', 'required', 'valid_email', 'max_length[128]', ['check_email_callable', function ($str) { return $this->check_email($str); }]]); \CI::form_validation()->set_rules('phone', 'lang:address_phone', 'trim|required|max_length[32]'); \CI::form_validation()->set_rules('email_subscribe', 'lang:account_newsletter_subscribe', 'trim|numeric|max_length[1]'); \CI::form_validation()->set_rules('password', 'Password', 'required|min_length[6]'); \CI::form_validation()->set_rules('confirm', 'Confirm Password', 'required|matches[password]'); if (\CI::form_validation()->run() == FALSE) { //if they have submitted the form already and it has returned with errors, reset the redirect if (\CI::input()->post('submitted')) { $data['redirect'] = \CI::input()->post('redirect'); } // load other page content //\CI::load()->model('banner_model'); \CI::load()->helper('directory'); $this->view('register', $data); } else { $save['id'] = false; $save['firstname'] = \CI::input()->post('firstname'); $save['lastname'] = \CI::input()->post('lastname'); $save['email'] = \CI::input()->post('email'); $save['phone'] = \CI::input()->post('phone'); $save['company'] = \CI::input()->post('company'); $save['active'] = config_item('new_customer_status'); $save['email_subscribe'] = intval((bool) \CI::input()->post('email_subscribe')); $save['password'] = \CI::input()->post('password'); $redirect = \CI::input()->post('redirect'); //if we don't have a value for redirect if ($redirect == '') { $redirect = 'my-account'; } // save the customer info and get their new id $id = \CI::Customers()->save($save); /* send an email */ // get the email template $row = \CI::db()->where('id', '6')->get('canned_messages')->row_array(); // set replacement values for subject & body // {customer_name} $row['subject'] = str_replace('{customer_name}', \CI::input()->post('firstname') . ' ' . \CI::input()->post('lastname'), $row['subject']); $row['content'] = str_replace('{customer_name}', \CI::input()->post('firstname') . ' ' . \CI::input()->post('lastname'), $row['content']); // {url} $row['subject'] = str_replace('{url}', config_item('base_url'), $row['subject']); $row['content'] = str_replace('{url}', config_item('base_url'), $row['content']); // {site_name} $row['subject'] = str_replace('{site_name}', config_item('company_name'), $row['subject']); $row['content'] = str_replace('{site_name}', config_item('company_name'), $row['content']); \CI::load()->library('email'); $config['mailtype'] = 'html'; \CI::email()->initialize($config); \CI::email()->from(config_item('email'), config_item('company_name')); \CI::email()->to($save['email']); \CI::email()->bcc(config_item('email')); \CI::email()->subject($row['subject']); \CI::email()->message(html_entity_decode($row['content'])); \CI::email()->send(); \CI::session()->set_flashdata('message', sprintf(lang('registration_thanks'), \CI::input()->post('firstname'))); //lets automatically log them in \CI::Login()->loginCustomer($save['email'], \CI::input()->post('confirm')); //we're just going to make this secure regardless, because we don't know if they are //wanting to redirect to an insecure location, if it needs to be secured then we can use the secure redirect in the controller //to redirect them, if there is no redirect, the it should redirect to the homepage. redirect($redirect); } }
public function zone_area_form($zone_id, $area_id = false) { \CI::load()->helper('form'); \CI::load()->library('form_validation'); \CI::form_validation()->set_error_delimiters('<div class="error">', '</div>'); $zone = \CI::Locations()->get_zone($zone_id); $data['zone'] = $zone; //default values are empty if the product is new $data['id'] = ''; $data['code'] = ''; $data['zone_id'] = $zone_id; $data['tax'] = 0; if ($area_id) { $area = (array) \CI::Locations()->get_zone_area($area_id); //if the country does not exist, redirect them to the country list with an error if (!$area) { \CI::session()->set_flashdata('error', lang('error_zone_area_not_found')); redirect('admin/locations/zone_areas/' . $zone_id); } $data = array_merge($data, $area); } \CI::form_validation()->set_rules('code', 'lang:code', 'trim|required'); \CI::form_validation()->set_rules('tax', 'lang:tax', 'trim|numeric'); if (\CI::form_validation()->run() == FALSE) { $this->view('country_zone_area_form', $data); } else { $save['id'] = $area_id; $save['zone_id'] = $zone_id; $save['code'] = \CI::input()->post('code'); $save['tax'] = \CI::input()->post('tax'); \CI::Locations()->save_zone_area($save); \CI::session()->set_flashdata('message', lang('message_saved_zone_area')); //go back to the product list redirect('admin/locations/zone_areas/' . $save['zone_id']); } }
public function index($offset = 0) { //make sure they're logged in \CI::Login()->isLoggedIn('my-account'); $data['customer'] = (array) \CI::Customers()->get_customer($this->customer->id); $data['addresses'] = \CI::Customers()->get_address_list($this->customer->id); $data['customer_addresses'] = \CI::Customers()->get_address_list($this->customer->id); // load other page content //\CI::load()->model('banner_model'); \CI::load()->helper('directory'); \CI::load()->helper('date'); // paginate the orders \CI::load()->library('pagination'); $config['base_url'] = site_url('my_account'); $config['total_rows'] = \CI::Orders()->countCustomerOrders($this->customer->id); $config['per_page'] = '15'; $config['first_link'] = 'First'; $config['first_tag_open'] = '<li>'; $config['first_tag_close'] = '</li>'; $config['last_link'] = 'Last'; $config['last_tag_open'] = '<li>'; $config['last_tag_close'] = '</li>'; $config['full_tag_open'] = '<div class="pagination"><ul>'; $config['full_tag_close'] = '</ul></div>'; $config['cur_tag_open'] = '<li class="active"><a href="#">'; $config['cur_tag_close'] = '</a></li>'; $config['num_tag_open'] = '<li>'; $config['num_tag_close'] = '</li>'; $config['prev_link'] = '«'; $config['prev_tag_open'] = '<li>'; $config['prev_tag_close'] = '</li>'; $config['next_link'] = '»'; $config['next_tag_open'] = '<li>'; $config['next_tag_close'] = '</li>'; \CI::pagination()->initialize($config); $data['orders_pagination'] = \CI::pagination()->create_links(); $data['orders'] = \CI::Orders()->getCustomerOrders($this->customer->id, $offset); //print_r($offset); \CI::load()->library('form_validation'); // \CI::form_validation()->set_rules('company', 'lang:address_company', 'trim|max_length[128]'); \CI::form_validation()->set_rules('firstname', 'lang:address_firstname', 'trim|required|max_length[32]'); \CI::form_validation()->set_rules('lastname', 'lang:address_lastname', 'trim|required|max_length[32]'); \CI::form_validation()->set_rules('email', 'lang:address_email', ['trim', 'required', 'valid_email', 'max_length[128]', ['check_email_callable', function ($str) { return $this->check_email($str); }]]); \CI::form_validation()->set_rules('phone', 'lang:address_phone', 'trim|required|max_length[32]'); \CI::form_validation()->set_rules('email_subscribe', 'lang:account_newsletter_subscribe', 'trim|numeric|max_length[1]'); if (\CI::input()->post('password') != '' || \CI::input()->post('confirm') != '') { \CI::form_validation()->set_rules('password', 'Password', 'required|min_length[6]|sha1'); \CI::form_validation()->set_rules('confirm', 'Confirm Password', 'required|matches[password]'); } else { \CI::form_validation()->set_rules('password', 'Password'); \CI::form_validation()->set_rules('confirm', 'Confirm Password'); } if (\CI::form_validation()->run() == FALSE) { $this->view('my_account', $data); } else { $customer = []; $customer['id'] = $this->customer->id; // $customer['company'] = \CI::input()->post('company'); $customer['firstname'] = \CI::input()->post('firstname'); $customer['lastname'] = \CI::input()->post('lastname'); $customer['email'] = \CI::input()->post('email'); $customer['phone'] = \CI::input()->post('phone'); $customer['email_subscribe'] = intval((bool) \CI::input()->post('email_subscribe')); if (\CI::input()->post('password') != '') { $customer['password'] = \CI::input()->post('password'); } \GC::save_customer($this->customer); \CI::Customers()->save($customer); \CI::session()->set_flashdata('message', lang('message_account_updated')); redirect('my-account'); } }
public function form($id = false) { \CI::load()->helper(array('form', 'date')); \CI::load()->library('form_validation'); \CI::form_validation()->set_error_delimiters('<div class="error">', '</div>'); $this->coupon_id = $id; $data['page_title'] = lang('coupon_form'); //default values are empty if the product is new $data['id'] = ''; $data['code'] = ''; $data['start_date'] = ''; $data['whole_order_coupon'] = 0; $data['max_product_instances'] = ''; $data['end_date'] = ''; $data['max_uses'] = ''; $data['reduction_type'] = ''; $data['reduction_amount'] = ''; $data['products'] = []; if ($id) { $coupon = \CI::Coupons()->getCoupon($id); //if the product does not exist, redirect them to the product list with an error if (!$coupon) { \CI::session()->set_flashdata('message', lang('error_not_found')); redirect('admin/product'); } //set values to db values $data['id'] = $coupon->id; $data['code'] = $coupon->code; $data['start_date'] = $coupon->start_date; $data['end_date'] = $coupon->end_date; $data['whole_order_coupon'] = $coupon->whole_order_coupon; $data['max_product_instances'] = $coupon->max_product_instances; $data['num_uses'] = $coupon->num_uses; $data['max_uses'] = $coupon->max_uses; $data['reduction_type'] = $coupon->reduction_type; $data['reduction_amount'] = $coupon->reduction_amount; $data['products'] = \CI::Coupons()->getProducts($id); } \CI::form_validation()->set_rules('code', 'lang:code', ['trim', 'required', ['code_callable', function ($str) { $code = \CI::Coupons()->checkCode($str, $this->coupon_id); if ($code) { \CI::form_validation()->set_message('code_callable', lang('error_already_used')); return FALSE; } else { return TRUE; } }]]); \CI::form_validation()->set_rules('max_uses', 'lang:max_uses', 'trim|numeric'); \CI::form_validation()->set_rules('max_product_instances', 'lang:limit_per_order', 'trim|numeric'); \CI::form_validation()->set_rules('whole_order_coupon', 'lang:whole_order_discount'); \CI::form_validation()->set_rules('reduction_type', 'lang:reduction_type', 'trim'); \CI::form_validation()->set_rules('reduction_amount', 'lang:reduction_amount', 'trim|numeric'); \CI::form_validation()->set_rules('start_date', 'lang:start_date'); \CI::form_validation()->set_rules('end_date', 'lang:end_date'); if (\CI::form_validation()->run() == FALSE) { if (\CI::input()->post()) { $data['products'] = json_decode(json_encode(\CI::input()->post('product'))); } $this->view('coupon_form', $data); } else { $save['id'] = $id; $save['code'] = \CI::input()->post('code'); $save['start_date'] = \CI::input()->post('start_date'); $save['end_date'] = \CI::input()->post('end_date'); $save['max_uses'] = \CI::input()->post('max_uses'); $save['whole_order_coupon'] = \CI::input()->post('whole_order_coupon'); $save['max_product_instances'] = \CI::input()->post('max_product_instances'); $save['reduction_type'] = \CI::input()->post('reduction_type'); $save['reduction_amount'] = \CI::input()->post('reduction_amount'); if ($save['start_date'] == '') { $save['start_date'] = null; } if ($save['end_date'] == '') { $save['end_date'] = null; } $products = \CI::input()->post('product'); // save coupon $id = \CI::Coupons()->save($save); \CI::Coupons()->removeProduct($id); if (!$save['whole_order_coupon'] && $products) { \CI::Coupons()->addProducts($id, $products); } // We're done \CI::session()->set_flashdata('message', lang('message_saved_coupon')); //go back to the product list redirect('admin/coupons'); } }
<?php include 'header.php'; ?> <script type="text/javascript"> <?php if (CI::input()->post('submit')) { ?> $(window).ready(function(){ $('#iframe_uploader', window.parent.document).height($('body').height()); }); <?php } ?> <?php if ($file_name) { ?> var filename = '<?php echo $file_name; ?> '; var uploaded = filename.split('.'); parent.addProductImage(uploaded[0], filename, '', '', ''); <?php } ?> </script>
public function giftCardForm($id = false, $duplicate = false) { $this->product_id = $id; \CI::load()->library('form_validation'); \CI::load()->model(array('ProductOptions', 'Categories')); \CI::form_validation()->set_error_delimiters('<div class="error">', '</div>'); $data['categories'] = \CI::Categories()->get_categories_tiered(); $data['page_title'] = lang('giftcard_product_form'); $data['groups'] = \CI::Customers()->get_groups(); //default values are empty if the product is new $data['id'] = ''; $data['sku'] = ''; $data['primary_category'] = ''; $data['name'] = ''; $data['slug'] = ''; $data['description'] = ''; $data['excerpt'] = ''; $data['track_stock'] = ''; $data['seo_title'] = ''; $data['meta'] = ''; $data['is_giftcard'] = 1; $data['taxable'] = ''; $data['images'] = []; $data['product_categories'] = []; $data['product_files'] = []; foreach ($data['groups'] as $group) { $data['enabled_' . $group->id] = ''; } //create the photos array for later use $data['photos'] = []; if ($id) { // get product & options data $data['ProductOptions'] = \CI::ProductOptions()->getProductOptions($id); $product = \CI::Products()->find($id, true); //if the product does not exist, redirect them to the product list with an error if (!$product) { \CI::session()->set_flashdata('error', lang('error_not_found')); redirect('admin/products'); } //helps us with the slug generation $this->product_name = \CI::input()->post('slug', $product->slug); //set values to db values $data['id'] = $id; $data['sku'] = $product->sku; $data['primary_category'] = $product->primary_category; $data['name'] = $product->name; $data['seo_title'] = $product->seo_title; $data['meta'] = $product->meta; $data['slug'] = $product->slug; $data['description'] = $product->description; $data['excerpt'] = $product->excerpt; $data['quantity'] = $product->quantity; $data['taxable'] = $product->taxable; $data['fixed_quantity'] = $product->fixed_quantity; $data['is_giftcard'] = $product->is_giftcard; foreach ($data['groups'] as $group) { $data['enabled_' . $group->id] = $product->{'enabled_' . $group->id}; } //make sure we haven't submitted the form yet before we pull in the images/related products from the database if (!\CI::input()->post('submit')) { $data['product_categories'] = []; foreach ($product->categories as $product_category) { $data['product_categories'][] = $product_category->id; } $data['related_products'] = $product->related_products; $data['images'] = (array) json_decode($product->images); } } if (!is_array($data['product_categories'])) { $data['product_categories'] = []; } //no error checking on these \CI::form_validation()->set_rules('caption', 'Caption'); \CI::form_validation()->set_rules('primary_photo', 'Primary'); \CI::form_validation()->set_rules('sku', 'lang:sku', 'trim'); \CI::form_validation()->set_rules('seo_title', 'lang:seo_title', 'trim'); \CI::form_validation()->set_rules('meta', 'lang:meta_data', 'trim'); \CI::form_validation()->set_rules('name', 'lang:name', 'trim|required|max_length[64]'); \CI::form_validation()->set_rules('slug', 'lang:slug', 'trim'); \CI::form_validation()->set_rules('description', 'lang:description', 'trim'); \CI::form_validation()->set_rules('excerpt', 'lang:excerpt', 'trim'); \CI::form_validation()->set_rules('taxable', 'lang:taxable', 'trim|numeric'); \CI::form_validation()->set_rules('fixed_quantity', 'lang:fixed_quantity', 'trim|numeric'); \CI::form_validation()->set_rules('option[giftcard_values]', 'lang:giftcard_values', 'required'); foreach ($data['groups'] as $group) { \CI::form_validation()->set_rules('enabled_' . $group->id, lang('enabled') . '(' . $group->name . ')', 'trim|numeric'); } /* if we've posted already, get the photo stuff and organize it if validation comes back negative, we feed this info back into the system if it comes back good, then we send it with the save item submit button has a value, so we can see when it's posted */ if ($duplicate) { $data['id'] = false; } if (\CI::input()->post('submit')) { //reset the product options that were submitted in the post $data['ProductOptions'] = \CI::input()->post('option'); $data['product_categories'] = \CI::input()->post('categories'); $data['images'] = \CI::input()->post('images'); } if (\CI::form_validation()->run() == FALSE) { $this->view('giftcard_product_form', $data); } else { \CI::load()->helper('text'); //first check the slug field $slug = \CI::input()->post('slug'); //if it's empty assign the name field if (empty($slug) || $slug == '') { $slug = \CI::input()->post('name'); } $slug = url_title(convert_accented_characters($slug), '-', TRUE); //validate the slug $slug = $id ? \CI::Products()->validate_slug($slug, $product->id) : \CI::Products()->validate_slug($slug); $save['id'] = $id; $save['sku'] = \CI::input()->post('sku'); $save['name'] = \CI::input()->post('name'); $save['seo_title'] = \CI::input()->post('seo_title'); $save['meta'] = \CI::input()->post('meta'); $save['description'] = \CI::input()->post('description'); $save['excerpt'] = \CI::input()->post('excerpt'); foreach ($data['groups'] as $group) { $save['enabled_' . $group->id] = \CI::input()->post('enabled_' . $group->id); $save['price_' . $group->id] = '0.00'; $save['saleprice_' . $group->id] = '0.00'; } $save['is_giftcard'] = 1; $save['taxable'] = \CI::input()->post('taxable'); $save['taxable'] = \CI::input()->post('taxable'); $post_images = \CI::input()->post('images'); $save['slug'] = $slug; if ($primary = \CI::input()->post('primary_image')) { if ($post_images) { foreach ($post_images as $key => &$pi) { if ($primary == $key) { $pi['primary'] = true; continue; } } } } $save['images'] = json_encode($post_images); if (\CI::input()->post('related_products')) { $save['related_products'] = json_encode(\CI::input()->post('related_products')); } else { $save['related_products'] = ''; } //save categories $categories = \CI::input()->post('categories'); if (!$categories) { $categories = []; } //(\CI::input()->post('primary_category')) ? \CI::input()->post('primary_category') : 0; if (!\CI::input()->post('primary_category') && $categories) { $save['primary_category'] = $categories[0]; } elseif (!\CI::input()->post('primary_category') && !$categories) { $save['primary_category'] = 0; } else { $save['primary_category'] = \CI::input()->post('primary_category'); } // format options $options = []; array_push($options, ['type' => 'textfield', 'name' => 'from', 'required' => 1, 'values' => ['0' => ['name' => 'from', 'value' => '', 'price' => 0, 'limit' => 0]]]); array_push($options, ['type' => 'textfield', 'name' => 'to_email', 'required' => 1, 'values' => ['0' => ['name' => 'to_email', 'value' => '', 'price' => 0, 'limit' => 0]]]); array_push($options, ['type' => 'textarea', 'name' => 'personal_message', 'required' => 1, 'values' => ['0' => ['name' => 'personal_message', 'value' => '', 'price' => 0]]]); $giftcard_values = []; $postedValues = \CI::input()->post('option[giftcard_values]'); if ($postedValues) { foreach ($postedValues as $giftcard_value) { array_push($giftcard_values, ['name' => 'beginning_amount', 'value' => $giftcard_value, 'weight' => '', 'price' => $giftcard_value]); } } array_push($options, ['type' => 'droplist', 'name' => 'beginning_amount', 'required' => 1, 'values' => $giftcard_values]); // save product $product_id = \CI::Products()->save($save, $options, $categories); \CI::session()->set_flashdata('message', lang('message_saved_giftcard_product')); //go back to the product list redirect('admin/products'); } }
function link_form($id = false) { //set the default values $data['id'] = ''; $data['title'] = ''; $data['url'] = ''; $data['new_window'] = false; $data['sequence'] = 0; $data['parent_id'] = 0; $data['page_title'] = lang('link_form'); $data['pages'] = \CI::Pages()->get_pages(); if ($id) { $page = \CI::Pages()->find($id); if (!$page) { //page does not exist \CI::session()->set_flashdata('error', lang('error_link_not_found')); redirect('admin/pages'); } //set values to db values $data['id'] = $page->id; $data['parent_id'] = $page->parent_id; $data['title'] = $page->title; $data['url'] = $page->url; $data['new_window'] = (bool) $page->new_window; $data['sequence'] = $page->sequence; } \CI::form_validation()->set_rules('title', 'lang:title', 'trim|required'); \CI::form_validation()->set_rules('url', 'lang:url', 'trim|required'); \CI::form_validation()->set_rules('sequence', 'lang:sequence', 'trim|integer'); \CI::form_validation()->set_rules('new_window', 'lang:new_window', 'trim|integer'); \CI::form_validation()->set_rules('parent_id', 'lang:parent_id', 'trim|integer'); // Validate the form if (\CI::form_validation()->run() == false) { $this->view('link_form', $data); } else { $save = []; $save['id'] = $id; $save['parent_id'] = \CI::input()->post('parent_id'); $save['title'] = \CI::input()->post('title'); $save['menu_title'] = \CI::input()->post('title'); $save['url'] = \CI::input()->post('url'); $save['sequence'] = \CI::input()->post('sequence'); $save['new_window'] = (bool) \CI::input()->post('new_window'); //save the page \CI::Pages()->save($save); \CI::session()->set_flashdata('message', lang('message_saved_link')); //go back to the page list redirect('admin/pages'); } }
public function form($id = 0) { $data['addressCount'] = \CI::Customers()->count_addresses($this->customer->id); $customer = \CI::Login()->customer(); //grab the address if it's available $data['id'] = false; $data['firstname'] = $customer->firstname; $data['lastname'] = $customer->lastname; $data['email'] = $customer->email; $data['phone'] = $customer->phone; $data['address1'] = ''; $data['address2'] = ''; $data['city'] = ''; $data['country_id'] = ''; $data['zone_id'] = ''; $data['zip'] = ''; if ($id != 0) { $a = \CI::Customers()->get_address($id); if ($a['customer_id'] != $this->customer->id) { redirect('addresses/form'); // don't allow cross-customer editing } $data = array_merge($data, $a); $data['zones_menu'] = \CI::Locations()->get_zones_menu($data['country_id']); } //get the countries list for the dropdown $data['countries_menu'] = \CI::Locations()->get_countries_menu(); if ($id == 0) { //if there is no set ID, the get the zones of the first country in the countries menu $data['zones_menu'] = \CI::Locations()->get_zones_menu(array_shift(array_keys($data['countries_menu']))); } else { $data['zones_menu'] = \CI::Locations()->get_zones_menu($data['country_id']); } \CI::load()->library('form_validation'); // \CI::form_validation()->set_rules('company', 'lang:address_company', 'trim|max_length[128]'); \CI::form_validation()->set_rules('firstname', 'lang:address_firstname', 'trim|required|max_length[32]'); \CI::form_validation()->set_rules('lastname', 'lang:address_lastname', 'trim|required|max_length[32]'); \CI::form_validation()->set_rules('email', 'lang:address_email', 'trim|required|valid_email|max_length[128]'); \CI::form_validation()->set_rules('phone', 'lang:address_phone', 'trim|required|max_length[32]'); \CI::form_validation()->set_rules('address1', 'lang:address', 'trim|required|max_length[128]'); \CI::form_validation()->set_rules('address2', 'lang:address2', 'trim|max_length[128]'); \CI::form_validation()->set_rules('city', 'lang:address_city', 'trim|required|max_length[32]'); \CI::form_validation()->set_rules('country_id', 'lang:address_country', 'trim|required|numeric'); \CI::form_validation()->set_rules('zone_id', 'lang:address_state', 'trim|required|numeric'); \CI::form_validation()->set_rules('zip', 'lang:address_zip', 'trim|required|max_length[32]'); if (\CI::form_validation()->run() == FALSE) { $this->partial('address_form', $data); } else { $a = []; $a['id'] = $id == 0 ? '' : $id; $a['customer_id'] = $this->customer->id; $a['firstname'] = \CI::input()->post('firstname'); $a['lastname'] = \CI::input()->post('lastname'); $a['email'] = \CI::input()->post('email'); $a['phone'] = \CI::input()->post('phone'); $a['address1'] = \CI::input()->post('address1'); $a['address2'] = \CI::input()->post('address2'); $a['city'] = \CI::input()->post('city'); $a['zip'] = \CI::input()->post('zip'); // get zone / country data using the zone id submitted as state $country = \CI::Locations()->get_country(assign_value('country_id')); $zone = \CI::Locations()->get_zone(assign_value('zone_id')); if (!empty($country)) { $a['zone'] = $zone->code; // save the state for output formatted addresses $a['country'] = $country->name; // some shipping libraries require country name $a['country_code'] = $country->iso_code_2; // some shipping libraries require the code $a['country_id'] = \CI::input()->post('country_id'); $a['zone_id'] = \CI::input()->post('zone_id'); } \CI::Customers()->save_address($a); echo 1; } }
public function form($id = false) { \CI::load()->helper('form'); \CI::load()->library('form_validation'); \CI::form_validation()->set_error_delimiters('<div class="error">', '</div>'); $data['page_title'] = lang('admin_form'); //default values are empty if the customer is new $data['id'] = ''; $data['firstname'] = ''; $data['lastname'] = ''; $data['email'] = ''; $data['username'] = ''; $data['access'] = ''; if ($id) { $this->admin_id = $id; $admin = \CI::auth()->getAdmin($id); //if the administrator does not exist, redirect them to the admin list with an error if (!$admin) { \CI::session()->set_flashdata('message', lang('admin_not_found')); redirect('admin/users'); } //set values to db values $data['id'] = $admin->id; $data['firstname'] = $admin->firstname; $data['lastname'] = $admin->lastname; $data['email'] = $admin->email; $data['username'] = $admin->username; $data['access'] = $admin->access; } \CI::form_validation()->set_rules('firstname', 'lang:firstname', 'trim|max_length[32]'); \CI::form_validation()->set_rules('lastname', 'lang:lastname', 'trim|max_length[32]'); \CI::form_validation()->set_rules('email', 'lang:email', 'trim|required|valid_email|max_length[128]'); \CI::form_validation()->set_rules('username', 'lang:username', ['trim', 'required', 'max_length[128]', ['username_callable', function ($str) { $email = \CI::auth()->check_username($str, $this->admin_id); if ($email) { \CI::form_validation()->set_message('username_callable', lang('error_username_taken')); return FALSE; } else { return TRUE; } }]]); \CI::form_validation()->set_rules('access', 'lang:access', 'trim|required'); //if this is a new account require a password, or if they have entered either a password or a password confirmation if (\CI::input()->post('password') != '' || \CI::input()->post('confirm') != '' || !$id) { \CI::form_validation()->set_rules('password', 'lang:password', 'required|min_length[6]|sha1'); \CI::form_validation()->set_rules('confirm', 'lang:confirm_password', 'required|sha1|matches[password]'); } if (\CI::form_validation()->run() == FALSE) { $this->view('user_form', $data); } else { $save['id'] = $id; $save['firstname'] = \CI::input()->post('firstname'); $save['lastname'] = \CI::input()->post('lastname'); $save['email'] = \CI::input()->post('email'); $save['username'] = \CI::input()->post('username'); $save['access'] = \CI::input()->post('access'); if (\CI::input()->post('password') != '' || !$id) { $save['password'] = \CI::input()->post('password'); } \CI::auth()->save($save); \CI::session()->set_flashdata('message', lang('message_user_saved')); //go back to the customer list redirect('admin/users'); } }
public function addressForm($customer_id, $id = false) { $data['id'] = $id; $data['company'] = ''; $data['firstname'] = ''; $data['lastname'] = ''; $data['email'] = ''; $data['phone'] = ''; $data['address1'] = ''; $data['address2'] = ''; $data['city'] = ''; $data['country_id'] = ''; $data['zone_id'] = ''; $data['zip'] = ''; $data['customer_id'] = $customer_id; $data['page_title'] = lang('address_form'); //get the countries list for the dropdown $data['countries_menu'] = \CI::Locations()->get_countries_menu(); if ($id) { $address = \CI::Customers()->get_address($id); //fully escape the address form_decode($address); //merge the array $data = array_merge($data, $address); $data['zones_menu'] = \CI::Locations()->get_zones_menu($data['country_id']); } else { //if there is no set ID, the get the zones of the first country in the countries menu $country_keys = array_keys($data['countries_menu']); $data['zones_menu'] = \CI::Locations()->get_zones_menu(array_shift($country_keys)); } \CI::load()->library('form_validation'); \CI::form_validation()->set_rules('company', 'lang:company', 'trim|max_length[128]'); \CI::form_validation()->set_rules('firstname', 'lang:firstname', 'trim|required|max_length[32]'); \CI::form_validation()->set_rules('lastname', 'lang:lastname', 'trim|required|max_length[32]'); \CI::form_validation()->set_rules('email', 'lang:email', 'trim|required|valid_email|max_length[128]'); \CI::form_validation()->set_rules('phone', 'lang:phone', 'trim|required|max_length[32]'); \CI::form_validation()->set_rules('address1', 'lang:address', 'trim|required|max_length[128]'); \CI::form_validation()->set_rules('address2', 'lang:address', 'trim|max_length[128]'); \CI::form_validation()->set_rules('city', 'lang:city', 'trim|required'); \CI::form_validation()->set_rules('country_id', 'lang:country', 'trim|required'); \CI::form_validation()->set_rules('zone_id', 'lang:state', 'trim|required'); \CI::form_validation()->set_rules('zip', 'lang:zip', 'trim|required|max_length[32]'); if (\CI::form_validation()->run() == FALSE) { $this->view('customer_address_form', $data); } else { $a['customer_id'] = $customer_id; // this is needed for new records $a['id'] = empty($id) ? '' : $id; $a['field_data']['company'] = \CI::input()->post('company'); $a['field_data']['firstname'] = \CI::input()->post('firstname'); $a['field_data']['lastname'] = \CI::input()->post('lastname'); $a['field_data']['email'] = \CI::input()->post('email'); $a['field_data']['phone'] = \CI::input()->post('phone'); $a['field_data']['address1'] = \CI::input()->post('address1'); $a['field_data']['address2'] = \CI::input()->post('address2'); $a['field_data']['city'] = \CI::input()->post('city'); $a['field_data']['zip'] = \CI::input()->post('zip'); $a['field_data']['zone_id'] = \CI::input()->post('zone_id'); $a['field_data']['country_id'] = \CI::input()->post('country_id'); $country = \CI::Locations()->get_country(\CI::input()->post('country_id')); $zone = \CI::Locations()->get_zone(\CI::input()->post('zone_id')); $a['field_data']['zone'] = $zone->code; // save the state for output formatted addresses $a['field_data']['country'] = $country->name; // some shipping libraries require country name $a['field_data']['country_code'] = $country->iso_code_2; // some shipping libraries require the code \CI::Customers()->save_address($a); \CI::session()->set_flashdata('message', lang('message_saved_address')); redirect('admin/customers/addresses/' . $customer_id); } }
function sales() { $data['year'] = \CI::input()->post('year'); $data['orders'] = \CI::Orders()->getGrossMonthlySales($data['year']); $this->partial('reports/sales', $data); }
public function canned_message_form($id = false) { $data['page_title'] = lang('canned_message_form'); $data['id'] = $id; $data['name'] = ''; $data['subject'] = ''; $data['content'] = ''; $data['deletable'] = 1; if ($id) { $message = \CI::Messages()->get_message($id); $data = array_merge($data, $message); } \CI::load()->helper('form'); \CI::load()->library('form_validation'); \CI::form_validation()->set_rules('name', 'lang:message_name', 'trim|required|max_length[50]'); \CI::form_validation()->set_rules('subject', 'lang:subject', 'trim|required|max_length[100]'); \CI::form_validation()->set_rules('content', 'lang:message_content', 'trim|required'); if (\CI::form_validation()->run() == FALSE) { $data['errors'] = validation_errors(); $this->view('canned_message_form', $data); } else { $save['id'] = $id; $save['name'] = \CI::input()->post('name'); $save['subject'] = \CI::input()->post('subject'); $save['content'] = \CI::input()->post('content'); //all created messages are typed to order so admins can send them from the view order page. if ($data['deletable']) { $save['type'] = 'order'; } \CI::Messages()->save_message($save); \CI::session()->set_flashdata('message', lang('message_saved_message')); redirect('admin/settings/canned_messages'); } }
function form($id = false) { $data['groups'] = \CI::Customers()->get_groups(); $config['upload_path'] = 'uploads/images/full'; $config['allowed_types'] = 'gif|jpg|png'; $config['max_size'] = config_item('size_limit'); $config['max_width'] = '1024'; $config['max_height'] = '768'; $config['encrypt_name'] = true; \CI::load()->library('upload', $config); $this->category_id = $id; \CI::load()->helper('form'); \CI::load()->library('form_validation'); \CI::form_validation()->set_error_delimiters('<div class="error">', '</div>'); $data['categories'] = \CI::Categories()->getCategoryOptionsMenu($id); $data['page_title'] = lang('category_form'); //default values are empty if the customer is new $data['id'] = ''; $data['name'] = ''; $data['slug'] = ''; $data['description'] = ''; $data['excerpt'] = ''; $data['sequence'] = ''; $data['image'] = ''; $data['seo_title'] = ''; $data['meta'] = ''; $data['parent_id'] = 0; $data['error'] = ''; foreach ($data['groups'] as $group) { $data['enabled_' . $group->id] = ''; } //create the photos array for later use $data['photos'] = []; if ($id) { $category = \CI::Categories()->find($id); //if the category does not exist, redirect them to the category list with an error if (!$category) { \CI::session()->set_flashdata('error', lang('error_not_found')); redirect('admin/categories'); } //helps us with the slug generation $this->category_name = \CI::input()->post('slug', $category->slug); //set values to db values $data['id'] = $category->id; $data['name'] = $category->name; $data['slug'] = $category->slug; $data['description'] = $category->description; $data['excerpt'] = $category->excerpt; $data['sequence'] = $category->sequence; $data['parent_id'] = $category->parent_id; $data['image'] = $category->image; $data['seo_title'] = $category->seo_title; $data['meta'] = $category->meta; foreach ($data['groups'] as $group) { $data['enabled_' . $group->id] = $category->{'enabled_' . $group->id}; } } \CI::form_validation()->set_rules('name', 'lang:name', 'trim|required|max_length[64]'); \CI::form_validation()->set_rules('slug', 'lang:slug', 'trim'); \CI::form_validation()->set_rules('description', 'lang:description', 'trim'); \CI::form_validation()->set_rules('excerpt', 'lang:excerpt', 'trim'); \CI::form_validation()->set_rules('sequence', 'lang:sequence', 'trim|integer'); \CI::form_validation()->set_rules('parent_id', 'parent_id', 'trim'); \CI::form_validation()->set_rules('image', 'lang:image', 'trim'); \CI::form_validation()->set_rules('seo_title', 'lang:seo_title', 'trim'); \CI::form_validation()->set_rules('meta', 'lang:meta', 'trim'); foreach ($data['groups'] as $group) { \CI::form_validation()->set_rules('enabled_' . $group->id, lang('enabled') . '(' . $group->name . ')', 'trim|numeric'); } // validate the form if (\CI::form_validation()->run() == FALSE) { $this->view('category_form', $data); } else { $uploaded = \CI::upload()->do_upload('image'); if ($id) { //delete the original file if another is uploaded if ($uploaded) { if ($data['image'] != '') { $file = []; $file[] = 'uploads/images/full/' . $data['image']; $file[] = 'uploads/images/medium/' . $data['image']; $file[] = 'uploads/images/small/' . $data['image']; $file[] = 'uploads/images/thumbnails/' . $data['image']; foreach ($file as $f) { //delete the existing file if needed if (file_exists($f)) { unlink($f); } } } } } if (!$uploaded) { $data['error'] = \CI::upload()->display_errors(); if ($_FILES['image']['error'] != 4) { $data['error'] .= \CI::upload()->display_errors(); $this->view('category_form', $data); return; //end script here if there is an error } } else { $image = \CI::upload()->data(); $save['image'] = $image['file_name']; \CI::load()->library('image_lib'); //this is the larger image $config['image_library'] = 'gd2'; $config['source_image'] = 'uploads/images/full/' . $save['image']; $config['new_image'] = 'uploads/images/medium/' . $save['image']; $config['maintain_ratio'] = TRUE; $config['width'] = 600; $config['height'] = 500; \CI::image_lib()->initialize($config); \CI::image_lib()->resize(); \CI::image_lib()->clear(); //small image $config['image_library'] = 'gd2'; $config['source_image'] = 'uploads/images/medium/' . $save['image']; $config['new_image'] = 'uploads/images/small/' . $save['image']; $config['maintain_ratio'] = TRUE; $config['width'] = 300; $config['height'] = 300; \CI::image_lib()->initialize($config); \CI::image_lib()->resize(); \CI::image_lib()->clear(); //cropped thumbnail $config['image_library'] = 'gd2'; $config['source_image'] = 'uploads/images/small/' . $save['image']; $config['new_image'] = 'uploads/images/thumbnails/' . $save['image']; $config['maintain_ratio'] = TRUE; $config['width'] = 150; $config['height'] = 150; \CI::image_lib()->initialize($config); \CI::image_lib()->resize(); \CI::image_lib()->clear(); } \CI::load()->helper('text'); //first check the slug field $slug = \CI::input()->post('slug'); //if it's empty assign the name field if (empty($slug) || $slug == '') { $slug = \CI::input()->post('name'); } $slug = url_title(convert_accented_characters($slug), 'dash', TRUE); if ($id) { $slug = \CI::Categories()->validate_slug($slug, $category->id); } else { $slug = \CI::Categories()->validate_slug($slug); } $save['id'] = $id; $save['name'] = \CI::input()->post('name'); $save['description'] = \CI::input()->post('description'); $save['excerpt'] = \CI::input()->post('excerpt'); $save['parent_id'] = intval(\CI::input()->post('parent_id')); $save['sequence'] = intval(\CI::input()->post('sequence')); $save['seo_title'] = \CI::input()->post('seo_title'); $save['meta'] = \CI::input()->post('meta'); $save['slug'] = $slug; foreach ($data['groups'] as $group) { $save['enabled_' . $group->id] = \CI::input()->post('enabled_' . $group->id); } \CI::Categories()->save($save); \CI::session()->set_flashdata('message', lang('message_category_saved')); //go back to the category list redirect('admin/categories'); } }
public function register() { $redirect = \CI::Login()->isLoggedIn(false, false); //if they are logged in, we send them back to the my_account by default if ($redirect) { redirect('my-account'); } \CI::load()->library('form_validation'); //default values are empty if the customer is new $data = ['company' => '', 'firstname' => '', 'lastname' => '', 'email' => '', 'phone' => '', 'address1' => '', 'address2' => '', 'city' => '', 'state' => '', 'zip' => '', 'redirect' => \CI::session()->flashdata('redirect')]; \CI::form_validation()->set_rules('company', 'lang:account_company', 'trim|max_length[128]'); \CI::form_validation()->set_rules('firstname', 'lang:account_firstname', 'trim|required|max_length[32]'); \CI::form_validation()->set_rules('lastname', 'lang:account_lastname', 'trim|required|max_length[32]'); \CI::form_validation()->set_rules('email', 'lang:account_email', ['trim', 'required', 'valid_email', 'max_length[128]', ['check_email_callable', function ($str) { return $this->check_email($str); }]]); \CI::form_validation()->set_rules('phone', 'lang:account_phone', 'trim|required|max_length[32]'); \CI::form_validation()->set_rules('email_subscribe', 'lang:email_subscribe', 'trim|numeric|max_length[1]'); \CI::form_validation()->set_rules('password', 'lang:account_password', 'required|min_length[6]'); \CI::form_validation()->set_rules('confirm', 'lang:account_confirm', 'required|matches[password]'); if (\CI::form_validation()->run() == FALSE) { //if they have submitted the form already and it has returned with errors, reset the redirect if (\CI::input()->post('submitted')) { $data['redirect'] = \CI::input()->post('redirect'); } // load other page content //\CI::load()->model('banner_model'); \CI::load()->helper('directory'); $data['registrationErrors'] = \CI::form_validation()->get_error_array(); $this->view('login', $data); } else { $save['id'] = false; $save['firstname'] = \CI::input()->post('firstname'); $save['lastname'] = \CI::input()->post('lastname'); $save['email'] = \CI::input()->post('email'); $save['phone'] = \CI::input()->post('phone'); $save['company'] = \CI::input()->post('company'); $save['active'] = (bool) config_item('new_customer_status'); $save['email_subscribe'] = intval((bool) \CI::input()->post('email_subscribe')); $save['password'] = \CI::input()->post('password'); $redirect = \CI::input()->post('redirect'); //if we don't have a value for redirect if ($redirect == '') { $redirect = 'my-account'; } // save the customer info and get their new id $id = \CI::Customers()->save($save); //send the registration email \GoCart\Emails::registration($save); //load twig for this language string $loader = new \Twig_Loader_String(); $twig = new \Twig_Environment($loader); //if they're automatically activated log them in and send them where they need to go if ($save['active']) { \CI::session()->set_flashdata('message', $twig->render(lang('registration_thanks'), $save)); //lets automatically log them in \CI::Login()->loginCustomer($save['email'], \CI::input()->post('confirm')); //to redirect them, if there is no redirect, the it should redirect to the homepage. redirect($redirect); } else { //redirect to the login page if they need to wait for activation \CI::session()->set_flashdata('message', $twig->render(lang('registration_awaiting_activation'), $save)); redirect('login'); } } }
public function setShippingMethod() { $rates = \GC::getShippingMethodOptions(); $hash = \CI::input()->post('method'); foreach ($rates as $key => $rate) { $test = md5(json_encode(['key' => $key, 'rate' => $rate])); if ($hash == $test) { \GC::setShippingMethod($key, $rate, $hash); //save the cart \GC::saveCart(); echo json_encode(['success' => true]); return false; } } echo json_encode(['error' => lang('shipping_method_is_no_longer_valid')]); }
public function sendNotification($order_id = '') { // send the message $config['mailtype'] = 'html'; \CI::load()->library('email'); \CI::email()->initialize($config); \CI::email()->from(config_item('email'), config_item('company_name')); \CI::email()->to(\CI::input()->post('recipient')); \CI::email()->subject(\CI::input()->post('subject')); \CI::email()->message(html_entity_decode(\CI::input()->post('content'))); \CI::email()->send(); \CI::session()->set_flashdata('message', lang('sent_notification_message')); redirect('admin/orders/order/' . $order_id); }
public function organize() { $banners = \CI::input()->post('banners'); \CI::Banners()->organize($banners); }