Example #1
0
 function index()
 {
     //we're going to use flash data and redirect() after form submissions to stop people from refreshing and duplicating submissions
     //$this->session->set_flashdata('message', 'this is our message');
     $data['page_title'] = lang('categories');
     $data['title_btn'] = generate_title_btn(lang('add_new_category'), 'categories/form');
     $data['categories'] = $this->Category_model->get_categories_tiered(true);
     $this->view($this->config->item('admin_folder') . '/categories', $data);
 }
Example #2
0
 function groups()
 {
     $data['groups'] = $this->Customer_model->get_groups();
     $data['title_btn'] = generate_title_btn(lang('add_new_group'), 'customers/edit_group');
     $data['page_title'] = lang('customer_groups');
     $this->view($this->config->item('admin_folder') . '/customer_groups', $data);
 }
Example #3
0
 function banner_form($banner_collection_id, $id = false)
 {
     $config['upload_path'] = 'uploads';
     $config['allowed_types'] = 'gif|jpg|png';
     $config['max_size'] = $this->config->item('size_limit');
     $config['encrypt_name'] = true;
     $this->load->library('upload', $config);
     $this->load->helper(array('form', 'date'));
     $this->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) $this->banner_model->banner($id));
         $data['enable_date'] = format_mdy($data['enable_date']);
         $data['disable_date'] = format_mdy($data['disable_date']);
         $data['new_window'] = (bool) $data['new_window'];
     }
     $data['page_title'] = lang('banner_form');
     $data['title_btn'] = generate_title_btn(lang('banner_collection'), 'banners/banner_collection/' . $banner_collection_id, 'ti-arrow-left');
     $this->form_validation->set_rules('name', 'lang:name', 'trim|required|full_decode');
     $this->form_validation->set_rules('enable_date', 'lang:enable_date', 'trim');
     $this->form_validation->set_rules('disable_date', 'lang:disable_date', 'trim|callback_date_check');
     $this->form_validation->set_rules('image', 'lang:image', 'trim');
     $this->form_validation->set_rules('link', 'lang:link', 'trim');
     $this->form_validation->set_rules('new_window', 'lang:new_window', 'trim');
     if ($this->form_validation->run() == false) {
         $data['error'] = validation_errors();
         $this->view(config_item('admin_folder') . '/banner_form', $data);
     } else {
         $uploaded = $this->upload->do_upload('image');
         $save['banner_collection_id'] = $banner_collection_id;
         $save['name'] = $this->input->post('name');
         $save['enable_date'] = format_ymd($this->input->post('enable_date'));
         $save['disable_date'] = format_ymd($this->input->post('disable_date'));
         $save['link'] = $this->input->post('link');
         $save['new_window'] = $this->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'] = $this->upload->display_errors();
                 $this->view(config_item('admin_folder') . '/banner_form', $data);
                 return;
                 //end script here if there is an error
             }
         }
         if ($uploaded) {
             $image = $this->upload->data();
             $save['image'] = $image['file_name'];
         }
         $this->banner_model->save_banner($save);
         $this->session->set_flashdata('message', lang('message_banner_saved'));
         redirect(config_item('admin_folder') . '/banners/banner_collection/' . $banner_collection_id);
     }
 }
Example #4
0
 function form($id = false)
 {
     //die(print_r($_POST));
     $this->load->helper(array('form', 'date'));
     $this->load->library('form_validation');
     $this->form_validation->set_error_delimiters('<div class="error">', '</div>');
     $this->coupon_id = $id;
     $data['page_title'] = lang('coupon_form');
     $data['title_btn'] = generate_title_btn('Coupon list', 'coupons', 'ti-arrow-left');
     //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_target'] = '';
     $data['reduction_type'] = '';
     $data['reduction_amount'] = '';
     $added = array();
     if ($id) {
         $coupon = $this->Coupon_model->get_coupon($id);
         //if the product does not exist, redirect them to the product list with an error
         if (!$coupon) {
             $this->session->set_flashdata('message', lang('error_not_found'));
             redirect($this->config->item('admin_folder') . '/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_target'] = $coupon->reduction_target;
         $data['reduction_type'] = $coupon->reduction_type;
         $data['reduction_amount'] = $coupon->reduction_amount;
         $added = $this->Coupon_model->get_product_ids($id);
     }
     $this->form_validation->set_rules('code', 'lang:code', 'trim|required|callback_check_code');
     $this->form_validation->set_rules('max_uses', 'lang:max_uses', 'trim|numeric');
     $this->form_validation->set_rules('max_product_instances', 'lang:limit_per_order', 'trim|numeric');
     $this->form_validation->set_rules('whole_order_coupon', 'lang:whole_order_discount');
     $this->form_validation->set_rules('reduction_target', 'lang:reduction_target', 'trim|required');
     $this->form_validation->set_rules('reduction_type', 'lang:reduction_type', 'trim');
     $this->form_validation->set_rules('reduction_amount', 'lang:reduction_amount', 'trim|numeric');
     $this->form_validation->set_rules('start_date', 'lang:start_date');
     $this->form_validation->set_rules('end_date', 'lang:end_date');
     // create product list
     $products = $this->Product_model->get_products();
     // set up a 2x2 row list for now
     $data['product_rows'] = "";
     $x = 0;
     while (TRUE) {
         // Yes, forever, until we find the end of our list
         if (!isset($products[$x])) {
             break;
         }
         // stop if we get to the end of our list
         $checked = "";
         if (in_array($products[$x]->id, $added)) {
             $checked = "checked='checked'";
         }
         $data['product_rows'] .= "<tr><td><input type='checkbox' name='product[]' value='" . $products[$x]->id . "' {$checked}></td><td> " . $products[$x]->name . "</td>";
         $x++;
         //reset the checked value to nothing
         $checked = "";
         if (isset($products[$x])) {
             // if we've gotten to the end on this row
             if (in_array($products[$x]->id, $added)) {
                 $checked = "checked='checked'";
             }
             $data['product_rows'] .= "<td><input type='checkbox' name='product[]' value='" . $products[$x]->id . "' {$checked}><td><td> " . $products[$x]->name . "</td></tr>";
         } else {
             $data['product_rows'] .= "<td> </td></tr>";
         }
         $x++;
     }
     if ($this->form_validation->run() == FALSE) {
         $this->view($this->config->item('admin_folder') . '/coupon_form', $data);
     } else {
         $save['id'] = $id;
         $save['code'] = $this->input->post('code');
         $save['start_date'] = $this->input->post('start_date');
         $save['end_date'] = $this->input->post('end_date');
         $save['max_uses'] = $this->input->post('max_uses');
         $save['whole_order_coupon'] = $this->input->post('whole_order_coupon');
         $save['max_product_instances'] = $this->input->post('max_product_instances');
         $save['reduction_target'] = $this->input->post('reduction_target');
         $save['reduction_type'] = $this->input->post('reduction_type');
         $save['reduction_amount'] = $this->input->post('reduction_amount');
         $save['updated_at'] = Carbon::now();
         if (!$id) {
             $save['created_at'] = Carbon::now();
         }
         if ($save['start_date'] == '') {
             $save['start_date'] = null;
         }
         if ($save['end_date'] == '') {
             $save['end_date'] = null;
         }
         $product = $this->input->post('product');
         // save coupon
         $promo_id = $this->Coupon_model->save($save);
         // save products if not a whole order coupon
         //   clear products first, then save again (the lazy way, but sequence is not utilized at the moment)
         $this->Coupon_model->remove_product($id);
         if (!$save['whole_order_coupon'] && $product) {
             while (list(, $product_id) = each($product)) {
                 $this->Coupon_model->add_product($promo_id, $product_id);
             }
         }
         // We're done
         $this->session->set_flashdata('message', lang('message_saved_coupon'));
         //go back to the product list
         redirect($this->config->item('admin_folder') . '/coupons');
     }
 }