Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
- class Products_manage_model extends Base_module_model {
- public $required = array('product_name','product_subcategory','product_part_number','product_first_image');
- public $image_fields=array('product_first_image_upload','product_second_image_upload','product_third_image_upload');
- public $thumb = array("width"=>88,"height"=>88);
- public $big = array("width"=>300,"height"=>300);
- public $product_path;
- function __construct() {
- parent::__construct('fuel_products');
- $this->sanitize_images = TRUE;
- $this->filters[]='product_part_number';
- $this->product_path = realpath(APPPATH . '../images/products');
- }
- function form_fields($values=array()) {
- $fields = parent::form_fields($values);
- $this->load->helper('url');
- /*
- $fields['product_installation_pdf']['class']='asset_select pdf';
- $fields['product_manual_pdf']['class']='asset_select pdf';
- $fields['product_installation_pdf']['accept'] = 'pdf';
- $fields['product_manual_pdf']['accept']='pdf';
- $fields['product_first_image_upload']['upload_path'].='products';
- $fields['product_first_image']['class']='asset_select images/products';
- */
- $fields['product_installation_pdf'] = array('label' => 'Upload Installation PDF', 'type' => 'file', 'upload_path' =>assets_server_path('products', 'pdf'), 'overwrite' => TRUE);
- $fields['product_manual_pdf'] = array('label' => 'Upload Manual PDF', 'type' => 'file', 'upload_path' =>assets_server_path('products', 'pdf'), 'overwrite' => TRUE);
- $fields['product_service_pdf'] = array('label' => 'Upload Service PDF', 'type' => 'file', 'upload_path' =>assets_server_path('products', 'pdf'), 'overwrite' => TRUE);
- unset($fields['product_first_image_upload']);
- unset($fields['product_second_image_upload']);
- unset($fields['product_third_image_upload']);
- unset($fields['product_logo_image_upload']);
- // SHow Current PDFS
- $pdf = $values['product_installation_pdf']==''?'':'<a href="'.base_url().'assets/products/'.$values['product_installation_pdf'].'"/>'.$values['product_installation_pdf'].'</a><br/>';
- $fields['product_installation_pdf'] = array(
- 'label' => '
- Upload Installation PDF
- <br/>Current Installation PDF: '.$pdf.'<a href="'.base_url().'index.php/admin/products/THISISWHATINEED/'.$values['id'].'">Delete</a>',
- 'readonly' => 'readonly',
- 'type' => 'file',
- 'upload_path' =>assets_server_path('assets/products/'),
- 'overwrite' => TRUE,
- 'accept'=>'pdf',
- );
- $pdf = $values['product_manual_pdf']==''?'':'<a href="'.base_url().'assets/products/'.$values['product_manual_pdf'].'"/>'.$values['product_manual_pdf'].'</a><br/>';
- $fields['product_manual_pdf'] = array(
- 'label' => '
- Upload Manual PDF
- <br/>Current Manual: '.$pdf.'<a href="">Delete</a>',
- 'readonly' => 'readonly',
- 'type' => 'file',
- 'upload_path' =>assets_server_path('assets/products/'),
- 'overwrite' => TRUE,
- 'accept'=>'pdf',
- );
- $pdf = $values['product_service_pdf']==''?'':'<a href="'.base_url().'assets/products/'.$values['product_service_pdf'].'"/>'.$values['product_service_pdf'].'</a><br/>';
- $fields['product_service_pdf'] = array(
- 'label' => '
- Upload Service PDF
- <br/>Current Service PDF: '.$pdf.'<a href="">Delete</a>',
- 'readonly' => 'readonly',
- 'type' => 'file',
- 'upload_path' =>assets_server_path('assets/products/'),
- 'overwrite' => TRUE,
- 'accept'=>'pdf',
- );
- // Show Subcats
- $fields['product_subcategory'] = array(
- 'label'=>'Product subcategory',
- 'type'=>'select',
- 'options'=>$this->getsubcats($values['product_category'],$values['product_subcategory']),
- );
- //Show current uploaded images
- $cross_img='<img src="'.base_url().'fuel/modules/fuel/assets/images/ico_cancel.png"/>';
- $delete_img='<a>'.$cross_img.'</a>';
- $img=$values['product_first_image']==''?'':'<img src="'.base_url().'assets/images/products/thumb/88'.$values['product_first_image'].'"/><br/>';
- $img2=$values['product_second_image']==''?'':'<img src="'.base_url().'assets/images/products/thumb/88'.$values['product_second_image'].'"/><br/>';
- $img3=$values['product_third_image']==''?'':'<img src="'.base_url().'assets/images/products/thumb/88'.$values['product_third_image'].'"/><br/>';
- $prodlogo = $values['product_logo_image']==''?'':'<img src="'.base_url().'assets/images/'.$values['product_logo_image'].'"/><br/>';
- $fields['product_logo_image'] = array(
- 'label' => '
- Current Logo
- <br/>'.$prodlogo,
- 'type' => 'file',
- 'upload_path' =>assets_server_path('images/'),
- 'overwrite' => TRUE,
- 'accept'=>'jpg|jpeg|gif|tiff|png',
- );
- $fields['product_first_image'] = array(
- 'label' => '
- Upload First Image</label>
- <br/>'.$img,
- 'type' => 'file',
- 'upload_path' =>assets_server_path('images/products'),
- 'overwrite' => TRUE,
- 'accept'=>'jpg|jpe|jpeg|gif|png',
- );
- $fields['product_second_image'] = array(
- 'label' => '
- Upload Second Image</label>
- <br/>'.$img2,
- 'type' => 'file',
- 'upload_path' =>assets_server_path('images/products'),
- 'overwrite' => TRUE,
- 'accept'=>'jpg|jpeg|gif|tiff|png',
- );
- $fields['product_third_image'] = array(
- 'label' => '
- Upload Third Image</label>
- <br/>'.$img3,
- 'type' => 'file',
- 'upload_path' =>assets_server_path('images/products'),
- 'overwrite' => TRUE,
- 'accept'=>'jpg|jpeg|gif|tiff|png',
- );
- return $fields;
- }
- function on_after_post($values) {
- $CI =& get_instance();
- $CI->load->library('image_lib');
- $delete=$this->input->post('delete');
- if($delete==false) {
- // create the thumbnail if an image is uploaded
- if (!empty($CI->upload)) {
- $CI->upload->data();
- foreach($this->upload_data as $data) {
- if (!empty($data['full_path'])) {
- if($data['file_ext']!='.pdf') {
- // resize to proper dimensions
- $config = array();
- $config['source_image'] = $data['full_path'];
- $config['create_thumb'] = FALSE;
- $config['new_image'] = strtolower(assets_server_path('products/thumbs/256'.$data['file_name'], 'images'));
- $config['width'] = 256;
- $config['height'] = 256;
- $config['master_dim'] = 'auto';
- $config['maintain_ratio'] = TRUE;
- $CI->image_lib->clear();
- $CI->image_lib->initialize($config);
- if (!$CI->image_lib->resize()) {
- $this->add_error($CI->image_lib->display_errors());
- }
- // create thumb
- $config = array();
- $config['source_image'] = $data['full_path'];
- $config['create_thumb'] = FALSE;
- $config['new_image'] = strtolower(assets_server_path('products/thumbs/88'.$data['file_name'], 'images'));
- $config['width'] = 88;
- $config['height'] = 88;
- $config['master_dim'] = 'auto';
- $config['maintain_ratio'] = TRUE;
- $CI->image_lib->clear();
- $CI->image_lib->initialize($config);
- if (!$CI->image_lib->resize()) {
- $this->add_error($CI->image_lib->display_errors());
- }
- } else {
- $data['is_image']=0;
- }
- }
- }
- }
- } else {
- /*
- $set=array(
- $delete=>''
- );
- $this->db->where('id',$values['id']);
- $this->db->update('fuel_products',$set);
- if($this->db->_error_message()!='') {
- if(file_exists(base_url().'assets/images/'.$values[$delete])) {
- unlink(base_url().'assets/images/'.$values[$delete]);
- } else if(file_exists(base_url().'assets/products/')) {
- }
- }*/
- }
- return $values;
- }
- function getsubcats($cat,$sub) {
- $subcats=array();
- $q=$this->db->get_where('fuel_product_categories',array('category_name'=>$cat));
- foreach($q->result() as $row) {
- if($sub!=$row->subcategory_name) {
- $subcats[$row->subcategory_name]=$row->subcategory_name;
- }
- }
- $subcats[$sub]=$sub;
- return $subcats;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement