Advertisement
Guest User

Untitled

a guest
Apr 27th, 2012
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 8.01 KB | None | 0 0
  1. <?php  if (!defined('BASEPATH')) exit('No direct script access allowed');
  2.  
  3. class Products_manage_model extends Base_module_model {
  4.     public $required = array('product_name','product_subcategory','product_part_number','product_first_image');
  5.     public $image_fields=array('product_first_image_upload','product_second_image_upload','product_third_image_upload');
  6.     public $thumb = array("width"=>88,"height"=>88);
  7.     public $big = array("width"=>300,"height"=>300);
  8.     public $product_path;
  9.    
  10.     function __construct() {
  11.         parent::__construct('fuel_products');
  12.         $this->sanitize_images = TRUE;
  13.         $this->filters[]='product_part_number';
  14.         $this->product_path = realpath(APPPATH . '../images/products');
  15.     }
  16.  
  17.     function form_fields($values=array()) {
  18.         $fields = parent::form_fields($values);
  19.         $this->load->helper('url');
  20.         /*
  21.        
  22.         $fields['product_installation_pdf']['class']='asset_select pdf';
  23.             $fields['product_manual_pdf']['class']='asset_select pdf';
  24.             $fields['product_installation_pdf']['accept'] = 'pdf';
  25.             $fields['product_manual_pdf']['accept']='pdf';
  26.           $fields['product_first_image_upload']['upload_path'].='products';
  27.           $fields['product_first_image']['class']='asset_select images/products';
  28.        
  29.         */
  30.        
  31.         $fields['product_installation_pdf'] = array('label' => 'Upload Installation PDF', 'type' => 'file', 'upload_path' =>assets_server_path('products', 'pdf'), 'overwrite' => TRUE);
  32.         $fields['product_manual_pdf'] = array('label' => 'Upload Manual PDF', 'type' => 'file', 'upload_path' =>assets_server_path('products', 'pdf'), 'overwrite' => TRUE);
  33.         $fields['product_service_pdf'] = array('label' => 'Upload Service PDF', 'type' => 'file', 'upload_path' =>assets_server_path('products', 'pdf'), 'overwrite' => TRUE);
  34.         unset($fields['product_first_image_upload']);
  35.         unset($fields['product_second_image_upload']);
  36.         unset($fields['product_third_image_upload']);
  37.         unset($fields['product_logo_image_upload']);
  38.        
  39.         // SHow Current PDFS
  40.         $pdf = $values['product_installation_pdf']==''?'':'<a href="'.base_url().'assets/products/'.$values['product_installation_pdf'].'"/>'.$values['product_installation_pdf'].'</a><br/>';
  41.         $fields['product_installation_pdf'] = array(
  42.               'label' => '
  43.                 Upload Installation PDF
  44.                     <br/>Current Installation PDF:&nbsp;'.$pdf.'<a href="'.base_url().'index.php/admin/products/THISISWHATINEED/'.$values['id'].'">Delete</a>',
  45.                 'readonly' => 'readonly',
  46.                 'type' => 'file',
  47.                 'upload_path' =>assets_server_path('assets/products/'),
  48.                 'overwrite' => TRUE,
  49.                 'accept'=>'pdf',       
  50.        
  51.         );
  52.         $pdf = $values['product_manual_pdf']==''?'':'<a href="'.base_url().'assets/products/'.$values['product_manual_pdf'].'"/>'.$values['product_manual_pdf'].'</a><br/>';
  53.         $fields['product_manual_pdf'] = array(
  54.               'label' => '
  55.                     Upload Manual PDF
  56.                     <br/>Current Manual:&nbsp;'.$pdf.'<a href="">Delete</a>',
  57.                 'readonly' => 'readonly',
  58.                 'type' => 'file',
  59.                 'upload_path' =>assets_server_path('assets/products/'),
  60.                 'overwrite' => TRUE,
  61.                 'accept'=>'pdf',       
  62.        
  63.         );
  64.         $pdf = $values['product_service_pdf']==''?'':'<a href="'.base_url().'assets/products/'.$values['product_service_pdf'].'"/>'.$values['product_service_pdf'].'</a><br/>';
  65.         $fields['product_service_pdf'] = array(
  66.               'label' => '
  67.                     Upload Service PDF
  68.                     <br/>Current Service PDF:&nbsp;'.$pdf.'<a href="">Delete</a>',
  69.                 'readonly' => 'readonly',
  70.                 'type' => 'file',
  71.                 'upload_path' =>assets_server_path('assets/products/'),
  72.                 'overwrite' => TRUE,
  73.                 'accept'=>'pdf',       
  74.        
  75.         );
  76.         // Show Subcats
  77.         $fields['product_subcategory'] = array(
  78.             'label'=>'Product subcategory',
  79.             'type'=>'select',
  80.             'options'=>$this->getsubcats($values['product_category'],$values['product_subcategory']),
  81.         );
  82.         //Show current uploaded images
  83.         $cross_img='<img src="'.base_url().'fuel/modules/fuel/assets/images/ico_cancel.png"/>';
  84.         $delete_img='<a>'.$cross_img.'</a>';
  85.         $img=$values['product_first_image']==''?'':'<img src="'.base_url().'assets/images/products/thumb/88'.$values['product_first_image'].'"/><br/>';
  86.         $img2=$values['product_second_image']==''?'':'<img src="'.base_url().'assets/images/products/thumb/88'.$values['product_second_image'].'"/><br/>';
  87.         $img3=$values['product_third_image']==''?'':'<img src="'.base_url().'assets/images/products/thumb/88'.$values['product_third_image'].'"/><br/>';
  88.         $prodlogo = $values['product_logo_image']==''?'':'<img src="'.base_url().'assets/images/'.$values['product_logo_image'].'"/><br/>';
  89.        
  90.        
  91.         $fields['product_logo_image'] = array(
  92.             'label' => '
  93.                     Current Logo
  94.                     <br/>'.$prodlogo,
  95.                
  96.             'type' => 'file',
  97.             'upload_path' =>assets_server_path('images/'),
  98.             'overwrite' => TRUE,
  99.             'accept'=>'jpg|jpeg|gif|tiff|png',     
  100.         );
  101.        
  102.  
  103.         $fields['product_first_image'] = array(
  104.               'label' => '
  105.                     Upload First Image</label>
  106.                     <br/>'.$img,
  107.             'type' => 'file',
  108.             'upload_path' =>assets_server_path('images/products'),
  109.             'overwrite' => TRUE,
  110.             'accept'=>'jpg|jpe|jpeg|gif|png',
  111.         );
  112.        
  113.         $fields['product_second_image'] = array(
  114.             'label' => '
  115.                     Upload Second Image</label>
  116.                     <br/>'.$img2,
  117.             'type' => 'file',
  118.             'upload_path' =>assets_server_path('images/products'),
  119.             'overwrite' => TRUE,
  120.             'accept'=>'jpg|jpeg|gif|tiff|png',     
  121.         );
  122.  
  123.         $fields['product_third_image'] = array(
  124.             'label' => '
  125.                     Upload Third Image</label>
  126.                     <br/>'.$img3,
  127.             'type' => 'file',
  128.             'upload_path' =>assets_server_path('images/products'),
  129.             'overwrite' => TRUE,
  130.             'accept'=>'jpg|jpeg|gif|tiff|png',     
  131.         );
  132.         return $fields;
  133.     }
  134.    
  135.     function on_after_post($values) {
  136.         $CI =& get_instance();
  137.         $CI->load->library('image_lib');
  138.         $delete=$this->input->post('delete');
  139.         if($delete==false) {
  140.             // create the thumbnail if an image is uploaded
  141.             if (!empty($CI->upload)) {
  142.                 $CI->upload->data();
  143.                 foreach($this->upload_data as $data) {
  144.                  
  145.                     if (!empty($data['full_path'])) {  
  146.                         if($data['file_ext']!='.pdf') {
  147.                             // resize to proper dimensions
  148.                             $config = array();
  149.                             $config['source_image'] = $data['full_path'];
  150.                             $config['create_thumb'] = FALSE;
  151.                             $config['new_image'] = strtolower(assets_server_path('products/thumbs/256'.$data['file_name'], 'images'));
  152.                             $config['width'] = 256;
  153.                             $config['height'] = 256;
  154.                             $config['master_dim'] = 'auto';
  155.                             $config['maintain_ratio'] = TRUE;
  156.                             $CI->image_lib->clear();
  157.                             $CI->image_lib->initialize($config);
  158.                             if (!$CI->image_lib->resize()) {
  159.                                 $this->add_error($CI->image_lib->display_errors());
  160.                             }
  161.            
  162.                             // create thumb
  163.                             $config = array();
  164.                             $config['source_image'] = $data['full_path'];
  165.                             $config['create_thumb'] = FALSE;
  166.                             $config['new_image'] = strtolower(assets_server_path('products/thumbs/88'.$data['file_name'], 'images'));
  167.                             $config['width'] = 88;
  168.                             $config['height'] = 88;
  169.                             $config['master_dim'] = 'auto';
  170.                             $config['maintain_ratio'] = TRUE;
  171.                             $CI->image_lib->clear();
  172.                             $CI->image_lib->initialize($config);
  173.                             if (!$CI->image_lib->resize()) {
  174.                                 $this->add_error($CI->image_lib->display_errors());
  175.                             }
  176.                         } else {   
  177.                             $data['is_image']=0;
  178.                         }  
  179.                     }
  180.                 }  
  181.             }
  182.         } else {
  183.             /*
  184.             $set=array(
  185.                 $delete=>''
  186.             );
  187.             $this->db->where('id',$values['id']);
  188.             $this->db->update('fuel_products',$set);
  189.             if($this->db->_error_message()!='') {
  190.                 if(file_exists(base_url().'assets/images/'.$values[$delete])) {
  191.                     unlink(base_url().'assets/images/'.$values[$delete]);
  192.                 } else if(file_exists(base_url().'assets/products/')) {
  193.                 }
  194.             }*/
  195.            
  196.         }
  197.         return $values;
  198.     }
  199.    
  200.     function getsubcats($cat,$sub) {
  201.         $subcats=array();
  202.         $q=$this->db->get_where('fuel_product_categories',array('category_name'=>$cat));
  203.         foreach($q->result() as $row) {
  204.         if($sub!=$row->subcategory_name) {
  205.             $subcats[$row->subcategory_name]=$row->subcategory_name;
  206.         }        
  207.     }
  208.     $subcats[$sub]=$sub;
  209.         return $subcats;
  210.     }
  211.  
  212. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement