%PDF-1.7 GIF89;
Server IP : 5.161.254.237 / Your IP : 216.73.216.93 Web Server : Apache System : Linux diamond.sialwebvps.com 4.18.0-553.8.1.el8_10.x86_64 #1 SMP Tue Jul 2 07:26:33 EDT 2024 x86_64 User : stellasp ( 1131) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /home/stellasp/public_html/application/controllers/admin/ |
Upload File : |
<?php class Products extends Admin_Controller { private $use_inventory = false; function __construct() { parent::__construct(); $this->auth->check_access('Admin', true); $this->load->model('Product_model'); $this->load->helper('form'); $this->lang->load('product'); } function index($order_by="name", $sort_order="ASC", $code=0, $page=0, $rows=50) { $data['page_title'] = lang('products'); $data['code'] = $code; $term = false; $category_id = false; //get the category list for the drop menu $this->load->model(array('Option_model', 'Category_model', 'Digital_Product_model')); $data['categories'] = $this->Category_model->get_categories_tierd(); $post = $this->input->post(null, false); $this->load->model('Search_model'); if($post) { $term = json_encode($post); $code = $this->Search_model->record_term($term); $data['code'] = $code; } elseif ($code) { $term = $this->Search_model->get_term($code); } //store the search term $data['term'] = $term; $data['order_by'] = $order_by; $data['sort_order'] = $sort_order; //$data['products'] = $this->Product_model->get_products(); $data['products'] = $this->Product_model->products(array('term'=>$term, 'order_by'=>$order_by, 'sort_order'=>$sort_order, 'rows'=>$rows, 'page'=>$page)); //total number of products $data['total'] = $this->Product_model->products(array('term'=>$term, 'order_by'=>$order_by, 'sort_order'=>$sort_order), true); $this->load->library('pagination'); $config['base_url'] = site_url($this->config->item('admin_folder').'/products/index/'.$order_by.'/'.$sort_order.'/'.$code.'/'); $config['total_rows'] = $data['total']; $config['per_page'] = $rows; $config['uri_segment'] = 7; $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>'; $this->pagination->initialize($config); $this->load->view($this->config->item('admin_folder').'/products', $data); } function bulk_save() { $products = $this->input->post('product'); if(!$products) { $this->session->set_flashdata('error', lang('error_bulk_no_products')); redirect($this->config->item('admin_folder').'/products'); } foreach($products as $id=>$product) { $product['id'] = $id; $this->Product_model->save($product); } $this->session->set_flashdata('message', lang('message_bulk_update')); redirect($this->config->item('admin_folder').'/products'); } function form($id = null, $duplicate = false) { // echo '<pre>'; // print_r($_FILES); // print_r( $this->input->post()); // die; $this->product_id = $id; $this->load->library('form_validation'); $this->load->model(array('Option_model', 'Category_model', 'Digital_Product_model')); $this->lang->load('digital_product'); $this->form_validation->set_error_delimiters('<div class="error">', '</div>'); $data['categories'] = $this->Category_model->get_categories_tierd(); $data['product_list'] = $this->Product_model->get_products(); $data['file_list'] = $this->Digital_Product_model->get_list(); $data['page_title'] = lang('product_form'); //default values are empty if the product is new $data['id'] = ''; $data['sku'] = ''; $data['name'] = ''; $data['size_chart'] = ''; $data['slug'] = ''; $data['description'] = ''; $data['features'] = ''; $data['returnstext'] = ''; $data['excerpt'] = ''; $data['price'] = 0; $data['saleprice'] = 0; $data['weight'] = ''; $data['rating'] = 4; $data['reviews'] = 12; $data['track_stock'] = ''; $data['seo_title'] = ''; $data['meta'] = ''; $data['costpersqft'] = 0; $data['shippable'] = ''; $data['taxable'] = ''; $data['fixed_quantity'] = ''; $data['quantity'] = ''; $data['enabled'] = ''; $data['favourite'] = ''; $data['arrival'] = ''; $data['sort_order'] = 0; $data['category_arrival'] = ''; $data['related_products'] = array(); $data['product_categories'] = array(); $data['images'] = array(); $data['icons'] = array(); $data['sheets'] = array(); $data['product_files'] = array(); //create the photos array for later use $data['photos'] = array(); if ($id) { // get the existing file associations and create a format we can read from the form to set the checkboxes $pr_files = $this->Digital_Product_model->get_associations_by_product($id); foreach($pr_files as $f) { $data['product_files'][] = $f->file_id; } // get product & options data $data['product_options'] = $this->Option_model->get_product_options($id); $data['product_pdf_options'] = $this->Digital_Product_model->get_product_pdf_options($id); // print_r($data['product_pdf_options']); // die; $product = $this->Product_model->get_product($id); //if the product does not exist, redirect them to the product list with an error if (!$product) { $this->session->set_flashdata('error', lang('error_not_found')); redirect($this->config->item('admin_folder').'/products'); } //helps us with the slug generation $this->product_name = $this->input->post('slug', $product->slug); //set values to db values $data['id'] = $id; $data['sku'] = $product->sku; $data['name'] = $product->name; $data['seo_title'] = $product->seo_title; $data['meta'] = $product->meta; $data['slug'] = $product->slug; $data['description'] = $product->description; $data['features'] = $product->features; $data['returnstext'] = $product->returnstext; $data['excerpt'] = $product->excerpt; $data['price'] = 0; $data['saleprice'] = 0; $data['weight'] = $product->weight; $data['rating'] = $product->rating; $data['reviews'] = $product->reviews; $data['track_stock'] = $product->track_stock; $data['shippable'] = $product->shippable; $data['costpersqft'] = $product->costpersqft; $data['quantity'] = $product->quantity; $data['taxable'] = $product->taxable; $data['fixed_quantity'] = $product->fixed_quantity; $data['enabled'] = $product->enabled; $data['favourite'] = $product->favourite; $data['arrival'] = $product->arrival; $data['category_arrival'] = $product->category_arrival; $data['sort_order'] = $product->sort_order; $data['size_chart'] = $product->size_chart; //make sure we haven't submitted the form yet before we pull in the images/related products from the database if(!$this->input->post('submit')) { $data['product_categories'] = $product->categories_list; $data['related_products'] = json_decode($product->related_products); $data['images'] = (array)json_decode($product->images); $data['icons'] = (array)json_decode($product->icons); $data['sheets'] = (array)json_decode($product->sheets); } } //if $data['related_products'] is not an array, make it one. if(!is_array($data['related_products'])) { $data['related_products'] = array(); } if(!is_array($data['product_categories'])) { $data['product_categories'] = array(); } //no error checking on these $this->form_validation->set_rules('caption', 'Caption'); $this->form_validation->set_rules('primary_photo', 'Primary'); $this->form_validation->set_rules('sku', 'lang:sku', 'trim'); $this->form_validation->set_rules('seo_title', 'lang:seo_title', 'trim'); $this->form_validation->set_rules('meta', 'lang:meta_data', 'trim'); $this->form_validation->set_rules('name', 'lang:name', 'trim|required|max_length[64]'); $this->form_validation->set_rules('slug', 'lang:slug', 'trim'); $this->form_validation->set_rules('description', 'lang:description', 'trim'); $this->form_validation->set_rules('features', 'lang:features', 'trim'); $this->form_validation->set_rules('returnstext', 'lang:returnstext', 'trim'); $this->form_validation->set_rules('excerpt', 'lang:excerpt', 'trim'); $this->form_validation->set_rules('price', 'lang:price', 'trim|numeric|floatval'); $this->form_validation->set_rules('saleprice', 'lang:saleprice', 'trim|numeric|floatval'); $this->form_validation->set_rules('weight', 'lang:weight', 'trim|numeric|floatval'); $this->form_validation->set_rules('rating', 'lang:rating', 'trim|numeric|floatval'); $this->form_validation->set_rules('reviews', 'lang:reviews', 'trim|numeric|floatval'); $this->form_validation->set_rules('track_stock', 'lang:track_stock', 'trim|numeric'); $this->form_validation->set_rules('quantity', 'lang:quantity', 'trim|numeric'); $this->form_validation->set_rules('costpersqft', 'lang:costpersqft', 'trim|numeric'); $this->form_validation->set_rules('shippable', 'lang:shippable', 'trim|numeric'); $this->form_validation->set_rules('taxable', 'lang:taxable', 'trim|numeric'); $this->form_validation->set_rules('fixed_quantity', 'lang:fixed_quantity', 'trim|numeric'); $this->form_validation->set_rules('enabled', 'lang:enabled', 'trim|numeric'); $this->form_validation->set_rules('favourite', 'lang:favourite', 'trim|numeric'); $this->form_validation->set_rules('arrival', 'lang:arrival', '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($this->input->post('submit')) { //reset the product options that were submitted in the post $data['product_options'] = $this->input->post('option'); $data['related_products'] = $this->input->post('related_products'); $data['product_categories'] = $this->input->post('categories'); $data['images'] = $this->input->post('images'); $data['icons'] = $this->input->post('icons'); $data['sheets'] = $this->input->post('sheets'); $data['product_files'] = $this->input->post('downloads'); } if ($this->form_validation->run() == FALSE) { $this->load->view($this->config->item('admin_folder').'/product_form', $data); } else { $this->load->helper('text'); //first check the slug field $slug = $this->input->post('slug'); //if it's empty assign the name field if(empty($slug) || $slug=='') { $slug = $this->input->post('name'); } $slug = url_title(convert_accented_characters($slug), 'dash', TRUE); //validate the slug $this->load->model('Routes_model'); if($id) { $slug = $this->Routes_model->validate_slug($slug, $product->route_id); $route_id = $product->route_id; } else { $slug = $this->Routes_model->validate_slug($slug); $route['slug'] = $slug; $route_id = $this->Routes_model->save($route); } $save['id'] = $id; $save['sku'] = $this->input->post('sku'); $save['name'] = $this->input->post('name'); $save['seo_title'] = $this->input->post('seo_title'); $save['meta'] = $this->input->post('meta'); $save['description'] = $this->input->post('description'); $save['features'] = $this->input->post('features'); $save['returnstext'] = $this->input->post('returnstext'); $save['excerpt'] = $this->input->post('excerpt'); $save['price'] = 1;//$this->input->post('price'); $save['saleprice'] = 0;//$this->input->post('saleprice'); $save['weight'] = $this->input->post('weight'); $save['rating'] = $this->input->post('rating'); $save['reviews'] = $this->input->post('reviews'); $save['track_stock'] = $this->input->post('track_stock'); $save['fixed_quantity'] = $this->input->post('fixed_quantity'); $save['quantity'] = 0;//$this->input->post('quantity'); $save['shippable'] = $this->input->post('shippable'); $save['costpersqft'] = $this->input->post('costpersqft'); $save['taxable'] = $this->input->post('taxable'); $save['enabled'] = $this->input->post('enabled'); $save['favourite'] = $this->input->post('favourite'); $save['arrival'] = $this->input->post('arrival'); $save['category_arrival'] = $this->input->post('category_arrival'); $save['sort_order'] = $this->input->post('sort_order'); $save['size_chart'] = $this->input->post('size_chart'); $post_icons = $this->input->post('icons'); $post_sheets = $this->input->post('sheets'); $post_images = $this->input->post('images'); // echo '<pre>'; // print_r($this->input->post()); // die; $save['slug'] = $slug; $save['route_id'] = $route_id; if($primary = $this->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($icon_primary = $this->input->post('icon_primary_image')) { if($post_icons) { foreach($post_icons as $key => &$pi) { if($icon_primary == $key) { $pi['icon_primary'] = true; continue; } } } } $save['icons'] = json_encode($post_icons); if($sheet_primary = $this->input->post('sheet_primary')) { if($post_sheets) { foreach($post_sheets as $key => &$pi) { if($sheet_primary == $key) { $pi['sheet_primary'] = true; continue; } } } } $save['sheets'] = json_encode($post_sheets); // echo '<pre>'; // print_r($save); // die; if($this->input->post('related_products')) { $save['related_products'] = json_encode($this->input->post('related_products')); } else { $save['related_products'] = ''; } //save categories $categories = $this->input->post('categories'); // format options $options = array(); if($this->input->post('option')) { foreach ($this->input->post('option') as $option) { $options[] = $option; } } $options_pdf = array(); if($this->input->post('option_pdf')) { foreach ($this->input->post('option_pdf') as $option_pdf) { $options_pdf[] = $option_pdf; } } // save product $product_id = $this->Product_model->save($save, $options, $categories); //ADD Multiple PDF if(!empty($options_pdf)){ $counter = 1; $maxAllowedFileSize = 500000000000; $allowed = ['pdf']; foreach($options_pdf as $okey => $oval){ $imagesArray = array(); if(!empty($_FILES['option_pdf']['name'][$counter])){ //$this->Digital_Product_model->disassociate_pdf($product_id); foreach($_FILES['option_pdf']['name'][$counter] as $k => $f){ $name = $_FILES['option_pdf']['name'][$counter][$k]; $tmp_name = $_FILES['option_pdf']['tmp_name'][$counter][$k]; $tmp_file = $_FILES['option_pdf']['tmp_name'][$counter][$k]; $size = $_FILES['option_pdf']['size'][$counter][$k]; $type = $_FILES['option_pdf']['type'][$counter][$k]; $error = $_FILES['option_pdf']['error'][$counter][$k]; if($error === UPLOAD_ERR_OK) { $extension = pathinfo($name, PATHINFO_EXTENSION); if(!in_array($extension, $allowed)) { } else if ($size > $maxAllowedFileSize) { } else { $originalFileName = $name; $newFileName = time().$name; $imagesArray[] = array( 'product_id' => $product_id, 'name' => $originalFileName, 'sequence' => 1, 'version' => '1.1', 'max_downloads' => 100, 'size' => $size, 'filename' => $newFileName ); $upload_dir = 'uploads/digital_uploads'; $newFileName = time().$name; if(move_uploaded_file($tmp_file, $upload_dir.'/'.$newFileName)); { } } } } } if(!empty($_FILES['option_pdf']['name'][$counter])){ $data = [ 'product_id' => $product_id, 'sequence' => 1, 'name' => $oval['name'], 'type' => $oval['type'], 'required' => 1, 'images' => $imagesArray, ]; $this->Digital_Product_model->associate_pdf($data); } $counter++; } } //die; // add file associations // clear existsing $this->Digital_Product_model->disassociate(false, $product_id); // save new $downloads = $this->input->post('downloads'); if(is_array($downloads)) { foreach($downloads as $d) { $this->Digital_Product_model->associate($d, $product_id); } } //save the route $route['id'] = $route_id; $route['slug'] = $slug; $route['route'] = 'cart/product/'.$product_id; $this->Routes_model->save($route); $this->session->set_flashdata('message', lang('message_saved_product')); //go back to the product list redirect($this->config->item('admin_folder').'/products'); } } function product_image_form() { $data['file_name'] = false; $data['error'] = false; $this->load->view($this->config->item('admin_folder').'/iframe/product_image_uploader', $data); } function product_icon_image_form() { $data['file_name'] = false; $data['error'] = false; $this->load->view($this->config->item('admin_folder').'/iframe/product_icon_image_uploader', $data); } function product_data_sheet_form() { $data['file_name'] = false; $data['error'] = false; $this->load->view($this->config->item('admin_folder').'/iframe/product_data_sheet_uploader', $data); } function product_data_sheet_upload() { $data['file_name'] = false; $data['error'] = false; $config['allowed_types'] = '*'; //$config['max_size'] = $this->config->item('size_limit'); $config['upload_path'] = 'uploads/sheets'; $config['encrypt_name'] = true; $config['remove_spaces'] = true; $this->load->library('upload', $config); if ( $this->upload->do_upload()) { $upload_data = $this->upload->data(); $this->load->library('image_lib'); /* I find that ImageMagick is more efficient that GD2 but not everyone has it if your server has ImageMagick then you can change out the line $config['image_library'] = 'gd2'; with $config['library_path'] = '/usr/bin/convert'; //make sure you use the correct path to ImageMagic $config['image_library'] = 'ImageMagick'; */ //this is the larger image /*$config['image_library'] = 'gd2'; $config['source_image'] = 'uploads/images/full/'.$upload_data['file_name']; $config['new_image'] = 'uploads/images/medium/'.$upload_data['file_name']; $config['maintain_ratio'] = TRUE; $config['width'] = 600; $config['height'] = 500; $this->image_lib->initialize($config); $this->image_lib->resize(); $this->image_lib->clear(); //small image $config['image_library'] = 'gd2'; $config['source_image'] = 'uploads/images/medium/'.$upload_data['file_name']; $config['new_image'] = 'uploads/images/small/'.$upload_data['file_name']; $config['maintain_ratio'] = TRUE; $config['width'] = 235; $config['height'] = 235; $this->image_lib->initialize($config); $this->image_lib->resize(); $this->image_lib->clear(); //cropped thumbnail $config['image_library'] = 'gd2'; $config['source_image'] = 'uploads/images/small/'.$upload_data['file_name']; $config['new_image'] = 'uploads/images/thumbnails/'.$upload_data['file_name']; $config['maintain_ratio'] = TRUE; $config['width'] = 150; $config['height'] = 150; $this->image_lib->initialize($config); $this->image_lib->resize(); $this->image_lib->clear();*/ $data['file_name'] = $upload_data['file_name']; } if($this->upload->display_errors() != '') { $data['error'] = $this->upload->display_errors(); } $this->load->view($this->config->item('admin_folder').'/iframe/product_data_sheet_uploader', $data); } function product_image_upload() { $data['file_name'] = false; $data['error'] = false; $config['allowed_types'] = '*'; //$config['max_size'] = $this->config->item('size_limit'); $config['upload_path'] = 'uploads/images/full'; $config['encrypt_name'] = true; $config['remove_spaces'] = true; $this->load->library('upload', $config); if ( $this->upload->do_upload()) { $upload_data = $this->upload->data(); $this->load->library('image_lib'); /* I find that ImageMagick is more efficient that GD2 but not everyone has it if your server has ImageMagick then you can change out the line $config['image_library'] = 'gd2'; $config['library_path'] = '/usr/bin/convert'; //make sure you use the correct path to ImageMagic $config['image_library'] = 'ImageMagick'; */ //this is the larger image $config['image_library'] = 'gd2'; $config['source_image'] = 'uploads/images/full/'.$upload_data['file_name']; $config['new_image'] = 'uploads/images/medium/'.$upload_data['file_name']; $config['maintain_ratio'] = TRUE; $config['width'] = 437; $config['height'] = 494; $this->image_lib->initialize($config); $this->image_lib->resize(); $this->image_lib->clear(); //small image $config['image_library'] = 'gd2'; $config['source_image'] = 'uploads/images/medium/'.$upload_data['file_name']; $config['new_image'] = 'uploads/images/small/'.$upload_data['file_name']; $config['maintain_ratio'] = TRUE; $config['width'] = 235; $config['height'] = 235; $this->image_lib->initialize($config); $this->image_lib->resize(); $this->image_lib->clear(); //cropped thumbnail $config['image_library'] = 'gd2'; $config['source_image'] = 'uploads/images/small/'.$upload_data['file_name']; $config['new_image'] = 'uploads/images/thumbnails/'.$upload_data['file_name']; $config['maintain_ratio'] = TRUE; $config['width'] = 150; $config['height'] = 150; $this->image_lib->initialize($config); $this->image_lib->resize(); $this->image_lib->clear(); $data['file_name'] = $upload_data['file_name']; } if($this->upload->display_errors() != '') { $data['error'] = $this->upload->display_errors(); } $this->load->view($this->config->item('admin_folder').'/iframe/product_image_uploader', $data); } function product_icon_image_upload() { $data['file_name'] = false; $data['error'] = false; $config['allowed_types'] = '*'; //$config['max_size'] = $this->config->item('size_limit'); $config['upload_path'] = 'uploads/images/full'; $config['encrypt_name'] = true; $config['remove_spaces'] = true; $this->load->library('upload', $config); if ( $this->upload->do_upload()) { $upload_data = $this->upload->data(); $this->load->library('image_lib'); /* I find that ImageMagick is more efficient that GD2 but not everyone has it if your server has ImageMagick then you can change out the line $config['image_library'] = 'gd2'; with $config['library_path'] = '/usr/bin/convert'; //make sure you use the correct path to ImageMagic $config['image_library'] = 'ImageMagick'; */ //this is the larger image $config['image_library'] = 'gd2'; $config['source_image'] = 'uploads/images/full/'.$upload_data['file_name']; $config['new_image'] = 'uploads/images/medium/'.$upload_data['file_name']; $config['maintain_ratio'] = TRUE; $config['width'] = 600; $config['height'] = 500; $this->image_lib->initialize($config); $this->image_lib->resize(); $this->image_lib->clear(); //small image $config['image_library'] = 'gd2'; $config['source_image'] = 'uploads/images/medium/'.$upload_data['file_name']; $config['new_image'] = 'uploads/images/small/'.$upload_data['file_name']; $config['maintain_ratio'] = TRUE; $config['width'] = 235; $config['height'] = 235; $this->image_lib->initialize($config); $this->image_lib->resize(); $this->image_lib->clear(); //cropped thumbnail $config['image_library'] = 'gd2'; $config['source_image'] = 'uploads/images/small/'.$upload_data['file_name']; $config['new_image'] = 'uploads/images/thumbnails/'.$upload_data['file_name']; $config['maintain_ratio'] = TRUE; $config['width'] = 150; $config['height'] = 150; $this->image_lib->initialize($config); $this->image_lib->resize(); $this->image_lib->clear(); $data['file_name'] = $upload_data['file_name']; } if($this->upload->display_errors() != '') { $data['error'] = $this->upload->display_errors(); } $this->load->view($this->config->item('admin_folder').'/iframe/product_icon_image_uploader', $data); } function delete($id = null) { if ($id) { $product = $this->Product_model->get_product($id); //if the product does not exist, redirect them to the customer list with an error if (!$product) { $this->session->set_flashdata('error', lang('error_not_found')); redirect($this->config->item('admin_folder').'/products'); } else { // remove the slug $this->load->model('Routes_model'); $this->Routes_model->remove('('.$product->slug.')'); //if the product is legit, delete them $this->Product_model->delete_product($id); $this->session->set_flashdata('message', lang('message_deleted_product')); redirect($this->config->item('admin_folder').'/products'); } } else { //if they do not provide an id send them to the product list page with an error $this->session->set_flashdata('error', lang('error_not_found')); redirect($this->config->item('admin_folder').'/products'); } } public function remove_pdf_section_with_options() { $action = $this->input->post('action'); $section_id = $this->input->post('section_id'); $this->load->model(array('Option_model', 'Digital_Product_model')); $this->Digital_Product_model->disassociate_pdf_with_options($section_id); echo json_encode(array('status' => true, 'message' => 'Section PDF has been deleted.')); } public function remove_pdf_options() { $action = $this->input->post('action'); $id = $this->input->post('id'); $this->load->model(array('Option_model', 'Digital_Product_model')); $this->Digital_Product_model->disassociate_pdf_options($id); echo json_encode(array('status' => true, 'message' => 'PDF Options has been deleted.')); } }