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 forgotPassword() { //redirect if the user is already logged in $redirect = \CI::auth()->isLoggedIn(false, false); if ($redirect) { redirect('admin/dashboard'); } \CI::form_validation()->set_rules('username', 'lang:username', ['trim', 'required', ['username_callable', function ($str) { $success = \CI::auth()->resetPassword($str); if (!$success) { \CI::form_validation()->set_message('username_callable', lang('username_doesnt_exist')); return FALSE; } else { //user does exist. and the password is reset. return TRUE; } }]]); if (\CI::form_validation()->run() == FALSE) { $this->views->show('admin/header'); $this->views->show('admin/forgot_password'); $this->views->show('admin/footer'); } else { \CI::session()->set_flashdata('message', lang('password_reset_message')); redirect('admin/login'); } }
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() { //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'); if (\CI::form_validation()->run() == FALSE) { $settings = \CI::Settings()->get_settings('cod'); $enabled = $settings['enabled']; $this->view('cod_form', ['enabled' => $enabled]); } else { \CI::Settings()->save_settings('cod', array('enabled' => $_POST['enabled'])); redirect('admin/payments'); } }
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 check_email($str) { $email = \CI::Customers()->check_email($str); if ($email) { \CI::form_validation()->set_message('check_email_callable', lang('error_email')); return FALSE; } else { return TRUE; } }
$.post($(this).attr('action'), $(this).serialize(), function(data){ if(data === 1) { closeAddressForm(); } else { $('#addressFormWrapper').html(data); } }); }) }); <?php if (validation_errors()) { $errors = \CI::form_validation()->get_error_array(); ?> var formErrors = <?php echo json_encode($errors); ?> for (var key in formErrors) { if (formErrors.hasOwnProperty(key)) { $('[name="'+key+'"]').parent().append('<div class="form-error text-red">'+formErrors[key]+'</div>') } } <?php } ?> </script>
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 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'); } }
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 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 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 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'); } }
public function order($orderNumber) { $data['order'] = \CI::Orders()->getOrder($orderNumber); if (!$data['order']) { redirect('admin/orders'); } \CI::form_validation()->set_rules('notes', 'lang:notes'); \CI::form_validation()->set_rules('status', 'lang:status', 'required'); if (\CI::form_validation()->run() == TRUE) { $save = ['id' => $data['order']->id, 'notes' => \CI::input()->post('notes')]; $status = \CI::input()->post('status'); if (trim(strtolower($status)) != 'cart') { $save['status'] = \CI::input()->post('status'); } $data['message'] = lang('message_order_updated'); \CI::Orders()->saveOrder($save); } $this->view('order', $data); }
public function banner_form($banner_collection_id, $id = false) { $config['upload_path'] = 'uploads'; $config['allowed_types'] = 'gif|jpg|png'; $config['encrypt_name'] = true; \CI::load()->library('upload', $config); \CI::load()->helper(array('form', 'date')); \CI::load()->library('form_validation'); //set the default values $data = array('banner_id' => $id, 'banner_collection_id' => $banner_collection_id, 'name' => '', 'enable_date' => '', 'disable_date' => '', 'image' => '', 'link' => '', 'new_window' => false); if ($id) { $data = array_merge($data, (array) \CI::Banners()->banner($id)); $data['new_window'] = (bool) $data['new_window']; } $data['page_title'] = lang('banner_form'); \CI::form_validation()->set_rules('name', 'lang:name', 'trim|required|full_decode'); \CI::form_validation()->set_rules('enable_date', 'lang:enable_date', 'trim'); \CI::form_validation()->set_rules('disable_date', 'lang:disable_date', 'trim'); \CI::form_validation()->set_rules('image', 'lang:image', 'trim'); \CI::form_validation()->set_rules('link', 'lang:link', 'trim'); \CI::form_validation()->set_rules('new_window', 'lang:new_window', 'trim'); if (\CI::form_validation()->run() == false) { $data['error'] = validation_errors(); $this->view('banner_form', $data); } else { $uploaded = \CI::upload()->do_upload('image'); $save['banner_collection_id'] = $banner_collection_id; $save['name'] = \CI::input()->post('name'); $save['enable_date'] = \CI::input()->post('enable_date'); $save['disable_date'] = \CI::input()->post('disable_date'); $save['link'] = \CI::input()->post('link'); $save['new_window'] = (bool) \CI::input()->post('new_window'); if ($id) { $save['banner_id'] = $id; //delete the original file if another is uploaded if ($uploaded) { if ($data['image'] != '') { $file = 'uploads/' . $data['image']; //delete the existing file if needed if (file_exists($file)) { unlink($file); } } } } else { if (!$uploaded) { $data['error'] = \CI::upload()->display_errors(); $this->view('banner_form', $data); return; //end script here if there is an error } } if ($uploaded) { $image = \CI::upload()->data(); $save['image'] = $image['file_name']; } \CI::Banners()->save_banner($save); \CI::session()->set_flashdata('message', lang('message_banner_saved')); redirect('admin/banners/banner_collection/' . $banner_collection_id); } }