Advertisement
Guest User

contrll

a guest
Feb 22nd, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 20.36 KB | None | 0 0
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3.  
  4. class Product extends User_Controller {
  5.  
  6.     /**
  7.      * Index Page for this controller.
  8.      *
  9.      * Maps to the following URL
  10.      *      http://example.com/index.php/welcome
  11.      *  - or -
  12.      *      http://example.com/index.php/welcome/index
  13.      *  - or -
  14.      * Since this controller is set as the default controller in
  15.      * config/routes.php, it's displayed at http://example.com/
  16.      *
  17.      * So any other public methods not prefixed with an underscore will
  18.      * map to /index.php/welcome/<method_name>
  19.      * @see https://codeigniter.com/user_guide/general/urls.html
  20.      */
  21.     public function index()
  22.     {
  23.  
  24.     }
  25.  
  26.  
  27.     public function preview($id = null)
  28.     {
  29.         //---------------------- ZALADOWANIE PODGLADU PO EDYCJI (Z ID) ---------------------- START
  30.         if($id)
  31.         {
  32.             if (!empty($_POST))
  33.             {
  34.                 //** TYMCZASOWE ID (wygenerowane po stronie front-end w celu atkualizacji id po utworzeniu podgladowego ogloszenia)
  35.                 $img_number = $this->input->post('temp_id', true);
  36.                 //-------------------------------------------------------------
  37.  
  38.                 //** SPRAWDZANIE TYPU OGLOSZENIA I OKRESLENIE STATUSU (1 = KUP TERAZ; 2 = AUKCJA)
  39.                 $typ = $this->input->post('typ', true);
  40.                 if($typ == 1)
  41.                 {
  42.                     $status = $this->input->post('status', true);
  43.                 }
  44.                 else if($typ == 2)
  45.                 {
  46.                     $status = 0;
  47.                 }
  48.                 //-------------------------------------------------------------
  49.  
  50.                 //----** ZMIENNE FUNKCJONALNE
  51.                 $waznosc = time() + ($this->input->post('waznosc', true) * 24 * 60 * 60);  
  52.                 $dostawa = $this->input->post('d_nazwa', true);
  53.                 //-------------------------------------------------------------
  54.  
  55.                 //----** DANE PODGLADU DO DB (@return ID)
  56.                 $data['products'] = array(
  57.                     'u_id' => $this->session->userdata('id'),
  58.                     'nazwa' => $this->input->post('nazwa', true),
  59.                     'cena' => $this->input->post('cena', true),
  60.                     'status' => $status,
  61.                     'kategoria' => $this->input->post('kategoria', true),
  62.                     'typ' => $this->input->post('typ', true),
  63.                     'opis' => $this->input->post('opis', true),
  64.                     'v_link' => $this->input->post('v_link', true),
  65.                     'waznosc' => $this->input->post('waznosc', true)
  66.                 );
  67.  
  68.                 $where = array('id' => $id);
  69.                 $this->Site_model->update('p_preview', $where, $data['products']);
  70.                 $insertId = $id;
  71.                 //-------------------------------------------------------------
  72.  
  73.                 //----** DANE O DOSTAWIE DO DB
  74.                 if($dostawa)
  75.                 {
  76.                     $where = array('p_id' => $id, 'preview' => 1);
  77.                     $this->Site_model->delete('p_supply', $where);
  78.  
  79.                     foreach($dostawa as $key=>$dost)
  80.                     {
  81.                         $dost_data[] = array(
  82.                             'p_id' => $insertId,
  83.                             'sposob' => $this->input->post('d_nazwa', true)[$key],
  84.                             'koszt' => $this->input->post('d_cena', true)[$key],
  85.                             'realizacja' => $this->input->post('d_realizacja', true)[$key],
  86.                             'preview' => 1
  87.                         );
  88.                     }
  89.                     $this->db->insert_batch('p_supply', $dost_data);
  90.                 }
  91.                 //-------------------------------------------------------------
  92.                
  93.                 //----** AKTUALIZUJE ID PODGLADU DLA WGRANYCH OBRAZKOW
  94.                 $up_img_id = array(
  95.                     'p_p_id' => $insertId,
  96.                 );
  97.  
  98.                 $where = array('p_p_id' => $img_number);
  99.                 $this->Site_model->update('p_preview_img', $where, $up_img_id);
  100.                 //-------------------------------------------------------------
  101.  
  102.                 //----** DANE O AUKCJI DO DB
  103.                 if($typ == 2)
  104.                 {
  105.                     $where = array('p_id' => $id, 'preview' => 1);
  106.                     $auct_data = array(
  107.                         'p_id' => $insertId,
  108.                         'waznosc' => $waznosc,
  109.                         'godzina' => $this->input->post('a_godzina', true),
  110.                         'preview' => 1
  111.                     );
  112.                     $this->Site_model->update('auction_list', $where, $auct_data);
  113.                 }
  114.                 //-------------------------------------------------------------
  115.  
  116.                 //----** FUNKCJE GET DO WYSWIETLENIA
  117.                 if($typ ==2)
  118.                 {
  119.  
  120.                     $curr_date1 = time();
  121.                     $waznosc_date2 = $waznosc - $curr_date1;
  122.                     $diff_date = round($waznosc_date2 / 86400);
  123.  
  124.                     if($diff_date >= 2)
  125.                     {
  126.                         $diff_date_title = ' dni do końca aukcji';
  127.                     }
  128.                     else if($diff_date == 1)
  129.                     {
  130.                         $temp_diff_date = round($waznosc_date2 / 60);
  131.                         if($temp_diff_date < 1440 && $temp_diff_date > 0)
  132.                         {
  133.                             $diff_date_title = $diff_date_title = ' do końca aukcji';
  134.                             $diff_date = 0;
  135.                         }
  136.                         else
  137.                         {
  138.                             $diff_date_title = ' dzień do końca aukcji';
  139.                         }
  140.                     }
  141.                     else if($diff_date == 0)
  142.                     {
  143.                         $temp_diff_date = round($waznosc_date2 / 60);
  144.                         if($temp_diff_date < 1440 && $temp_diff_date > 0)
  145.                         {
  146.                             $diff_date_title = $diff_date_title = ' do końca aukcji';
  147.                             $diff_date = 0;
  148.                         }
  149.                         else
  150.                         {
  151.                             $diff_date_title = 'Aukcja zakończona';
  152.                             $diff_date = -1;
  153.                         }
  154.                     }
  155.                     else if($diff_date < 0)
  156.                     {
  157.                         $diff_date_title = 'Aukcja zakończona';
  158.                         $diff_date = -1;
  159.                     }
  160.  
  161.                     $dzien = date('d.m.Y', $waznosc);
  162.                     $godzina = $this->input->post('a_godzina', true).':00:00';
  163.                     $js_data = array(
  164.                         'rok' => date('Y', $waznosc),
  165.                         'miesiac' => date('m', $waznosc),
  166.                         'dzien' => date('d', $waznosc),
  167.                         );
  168.                     $data['auction'] = array(
  169.                         'data' => $dzien,
  170.                         'js_data' => $js_data,
  171.                         'godzina' => $godzina,
  172.                         'pozostalo' => $diff_date,
  173.                         'pozostalo_t' => $diff_date_title,
  174.                     );
  175.  
  176.  
  177.  
  178.                     $data['auction'] = json_decode (json_encode ($data['auction']), FALSE);
  179.                 }
  180.  
  181.                 $data['number'] = array('id' => $insertId);
  182.                 $data['number'] = json_decode (json_encode ($data['number']), FALSE);
  183.  
  184.                 $where = array('u_id' => $this->session->userdata('id'));
  185.                 $data['company'] = $this->Site_model->get_single('company_data', $where);
  186.  
  187.                 $where = array('p_p_id' => $insertId);
  188.                 $data['imgs'] = $this->Site_model->get('p_preview_img', $where);
  189.  
  190.                 $where = array('p_id' => $insertId, 'preview' => 1);
  191.                 $data['supply'] = $this->Site_model->get('p_supply', $where);
  192.  
  193.                 $data['products'] = json_decode (json_encode ($data['products']), FALSE);
  194.                 //-------------------------------------------------------------
  195.  
  196.                 //----** LADUJE WIDOK W ZALEZNOSCI OD TYPU OGLOSZENIA (1 = KUP TERAZ; 2 = AUKCJA)
  197.                 if($typ == 1)
  198.                 {
  199.                     $this->load->view('user/product_preview', $data);
  200.                 }
  201.                 else if($typ == 2)
  202.                 {
  203.                     $this->load->view('user/auction_preview', $data);
  204.                 }
  205.                 //-------------------------------------------------------------
  206.             }
  207.         }
  208.         //---------------------- ZALADOWANIE PODGLADU PO EDYCJI (Z ID) ---------------------- KONIEC
  209.         else
  210.         //---------------------- ZALADOWANIE PODGLADU PIERWSZY RAZ(BEZ ID) ---------------------- START
  211.         {
  212.             if (!empty($_POST))
  213.             {
  214.                 //** TYMCZASOWE ID (wygenerowane po stronie front-end w celu atkualizacji id po utworzeniu podgladowego ogloszenia)
  215.                 $img_number = $this->input->post('temp_id', true);
  216.                 //-------------------------------------------------------------
  217.  
  218.                 //** SPRAWDZANIE TYPU OGLOSZENIA I OKRESLENIE STATUSU (1 = KUP TERAZ; 2 = AUKCJA)
  219.                 $typ = $this->input->post('typ', true);
  220.                 if($typ == 1)
  221.                 {
  222.                     $status = $this->input->post('status', true);
  223.                 }
  224.                 else if($typ == 2)
  225.                 {
  226.                     $status = 0;
  227.                 }
  228.                 //-------------------------------------------------------------
  229.  
  230.                 //----** ZMIENNE FUNKCJONALNE
  231.                 $waznosc = time() + ($this->input->post('waznosc', true) * 24 * 60 * 60);  
  232.                 $dostawa = $this->input->post('d_nazwa', true);
  233.                 //-------------------------------------------------------------
  234.  
  235.                 //----** DANE PODGLADU DO DB (@return ID)
  236.                 $data['products'] = array(
  237.                     'u_id' => $this->session->userdata('id'),
  238.                     'nazwa' => $this->input->post('nazwa', true),
  239.                     'cena' => $this->input->post('cena', true),
  240.                     'status' => $status,
  241.                     'kategoria' => $this->input->post('kategoria', true),
  242.                     'typ' => $this->input->post('typ', true),
  243.                     'opis' => $this->input->post('opis', true),
  244.                     'v_link' => $this->input->post('v_link', true),
  245.                     'waznosc' => $this->input->post('waznosc', true)
  246.                 );
  247.  
  248.                 $this->Site_model->create('p_preview', $data['products']);
  249.                 $insertId = $this->db->insert_id();
  250.                 //-------------------------------------------------------------
  251.  
  252.                 //----** DANE O DOSTAWIE DO DB
  253.                 if($dostawa)
  254.                 {
  255.                     foreach($dostawa as $key=>$dost)
  256.                     {
  257.                         $dost_data[] = array(
  258.                             'p_id' => $insertId,
  259.                             'sposob' => $this->input->post('d_nazwa', true)[$key],
  260.                             'koszt' => $this->input->post('d_cena', true)[$key],
  261.                             'realizacja' => $this->input->post('d_realizacja', true)[$key],
  262.                             'preview' => 1
  263.                         );
  264.                     }
  265.  
  266.                     $this->db->insert_batch('p_supply', $dost_data);
  267.                 }
  268.                 //-------------------------------------------------------------
  269.  
  270.                 //----** AKTUALIZUJE ID PODGLADU DLA WGRANYCH OBRAZKOW
  271.                 $up_img_id = array(
  272.                     'p_p_id' => $insertId,
  273.                 );
  274.  
  275.                 $where = array('p_p_id' => $img_number);
  276.                 $this->Site_model->update('p_preview_img', $where, $up_img_id);
  277.                 //-------------------------------------------------------------
  278.  
  279.                 //----** DANE O AUKCJI DO DB
  280.                 if($typ == 2)
  281.                 {
  282.                     $auct_data = array(
  283.                         'p_id' => $insertId,
  284.                         'waznosc' => $waznosc,
  285.                         'godzina' => $this->input->post('a_godzina', true),
  286.                         'preview' => 1
  287.                     );
  288.                     $this->Site_model->create('auction_list', $auct_data);
  289.                 }
  290.                 //-------------------------------------------------------------
  291.  
  292.                 //----** FUNKCJE GET DO WYSWIETLENIA
  293.                 if($typ ==2)
  294.                 {
  295.  
  296.                     $curr_date1 = time();
  297.                     $waznosc_date2 = $waznosc - $curr_date1;
  298.                     $diff_date = round($waznosc_date2 / 86400);
  299.  
  300.                     if($diff_date >= 2)
  301.                     {
  302.                         $diff_date_title = ' dni do końca aukcji';
  303.                     }
  304.                     else if($diff_date == 1)
  305.                     {
  306.                         $temp_diff_date = round($waznosc_date2 / 60);
  307.                         if($temp_diff_date < 1440 && $temp_diff_date > 0)
  308.                         {
  309.                             $diff_date_title = $diff_date_title = ' do końca aukcji';
  310.                             $diff_date = 0;
  311.                         }
  312.                         else
  313.                         {
  314.                             $diff_date_title = ' dzień do końca aukcji';
  315.                         }
  316.                     }
  317.                     else if($diff_date == 0)
  318.                     {
  319.                         $temp_diff_date = round($waznosc_date2 / 60);
  320.                         if($temp_diff_date < 1440 && $temp_diff_date > 0)
  321.                         {
  322.                             $diff_date_title = $diff_date_title = ' do końca aukcji';
  323.                             $diff_date = 0;
  324.                         }
  325.                         else
  326.                         {
  327.                             $diff_date_title = 'Aukcja zakończona';
  328.                             $diff_date = -1;
  329.                         }
  330.                     }
  331.                     else if($diff_date < 0)
  332.                     {
  333.                         $diff_date_title = 'Aukcja zakończona';
  334.                         $diff_date = -1;
  335.                     }
  336.  
  337.                     $dzien = date('d.m.Y', $waznosc);
  338.                     $godzina = $this->input->post('a_godzina', true).':00:00';
  339.                     $js_data = array(
  340.                         'rok' => date('Y', $waznosc),
  341.                         'miesiac' => date('m', $waznosc),
  342.                         'dzien' => date('d', $waznosc),
  343.                         );
  344.                     $data['auction'] = array(
  345.                         'data' => $dzien,
  346.                         'js_data' => $js_data,
  347.                         'godzina' => $godzina,
  348.                         'pozostalo' => $diff_date,
  349.                         'pozostalo_t' => $diff_date_title,
  350.                     );
  351.  
  352.  
  353.  
  354.                     $data['auction'] = json_decode (json_encode ($data['auction']), FALSE);
  355.                 }
  356.  
  357.                 $data['number'] = array('id' => $insertId);
  358.                 $data['number'] = json_decode (json_encode ($data['number']), FALSE);
  359.  
  360.                 $where = array('u_id' => $this->session->userdata('id'));
  361.                 $data['company'] = $this->Site_model->get_single('company_data', $where);
  362.  
  363.                 $where = array('p_p_id' => $insertId);
  364.                 $data['imgs'] = $this->Site_model->get('p_preview_img', $where);
  365.  
  366.                 $where = array('p_id' => $insertId, 'preview' => 1);
  367.                 $data['supply'] = $this->Site_model->get('p_supply', $where);
  368.  
  369.                 $data['products'] = json_decode (json_encode ($data['products']), FALSE);
  370.                 //-------------------------------------------------------------
  371.  
  372.                 //----** LADUJE WIDOK W ZALEZNOSCI OD TYPU OGLOSZENIA (1 = KUP TERAZ; 2 = AUKCJA)
  373.                 if($typ == 1)
  374.                 {
  375.                     $this->load->view('user/product_preview', $data);
  376.                 }
  377.                 else if($typ == 2)
  378.                 {
  379.                     $this->load->view('user/auction_preview', $data);
  380.                 }
  381.             }
  382.         }
  383.         //---------------------- ZALADOWANIE PODGLADU PIERWSZY RAZ(BEZ ID) ---------------------- KONIEC
  384.     }
  385.  
  386.     public function add($id = null)
  387.     {
  388.         $where = array('main' => 1);
  389.         $data['cats'] = $this->Site_model->get('p_categories', $where);
  390.        
  391.         for ($i = 0; $i < sizeof($data['cats']); $i++) {
  392.  
  393.             $where = array('sub_cat' => $data['cats'][$i]->id);
  394.            
  395.             $data['cats'][$i]->subcat = $this->Site_model->get('p_categories', $where);
  396.         }
  397.  
  398.         if($id)
  399.         {
  400.             $where = array('id' => $id);
  401.             $data['product'] = $this->Site_model->get_single('p_preview', $where);
  402.  
  403.             //----** JEZELI AUKCJA TO WCZYTUJE DANE Z DB
  404.             if($data['product']->typ == 2)
  405.             {
  406.                 $where = array('p_id' => $id, 'preview' => 1);
  407.                 $data['auction'] = $this->Site_model->get_single('auction_list', $where);
  408.             }
  409.             //-------------------------------------------------------------
  410.             $where = array('p_id' => $id, 'preview' => 1);
  411.             $data['supply'] = $this->Site_model->get('p_supply', $where);
  412.  
  413.             $where = array('p_p_id' => $id);
  414.             $data['img'] = $this->Site_model->get('p_preview_img', $where);
  415.             $this->load->view('user/product_re_add', $data);
  416.         }
  417.         else
  418.         {
  419.             $this->load->view('user/product_add', $data);  
  420.         }
  421.     }
  422.  
  423.     public function edit($id = null)
  424.     {
  425.         $where = array('id' => $id);
  426.         $product_data = $this->Site_model->get_single( 'p_list' , $where );
  427.         if($product_data->u_id == $this->session->userdata('id'))
  428.         {
  429.             $where = array('main' => 1);
  430.             $data['cats'] = $this->Site_model->get('p_categories', $where);
  431.            
  432.             for ($i = 0; $i < sizeof($data['cats']); $i++) {
  433.  
  434.                 $where = array('sub_cat' => $data['cats'][$i]->id);
  435.                
  436.                 $data['cats'][$i]->subcat = $this->Site_model->get('p_categories', $where);
  437.             }
  438.  
  439.             if($id && $product_data->active == 1)
  440.             {
  441.                 $where = array('id' => $id);
  442.                 $data['product'] = $this->Site_model->get_single('p_list', $where);
  443.  
  444.                 $where = array('p_id' => $id);
  445.                 $data['img'] = $this->Site_model->get('p_preview_img', $where);
  446.                 $this->load->view('user/product_edit', $data);
  447.             }
  448.             else
  449.             {
  450.                 $this->session->set_flashdata( 'error' , 'Nie znaleziono takiego ogłoszenia' );
  451.                 redirect('profile/products_list');
  452.             }
  453.         }
  454.         else
  455.         {
  456.             $this->session->set_flashdata( 'error' , 'Nie posiadasz uprawnień do edycji tego ogłoszenia.' );
  457.             redirect('profile/products_list');
  458.         }
  459.     }
  460.  
  461.     public function addimg()
  462.     {
  463.         if($_FILES)
  464.         {
  465.             // image upload&resize
  466.             if(!empty($_FILES['userfile']['name'][0]))
  467.             {
  468.                 $this->load->library('upload');
  469.                 $this->load->library('image_lib');
  470.                 $dataInfo = array();
  471.                 $img = array();
  472.                 $number = $this->input->post( 'number' , true );
  473.                 $img_id = $this->input->post( 'img_id' , true );
  474.                 $file_id = $this->input->post( 'file_id' , true );
  475.                 $files = $_FILES;
  476.  
  477.                 $_FILES['userfile']['name'] = $files['userfile']['name'][0];
  478.                 $_FILES['userfile']['type'] = $files['userfile']['type'][0];
  479.                 $_FILES['userfile']['tmp_name'] = $files['userfile']['tmp_name'][0];
  480.                 $_FILES['userfile']['error'] = $files['userfile']['error'][0];
  481.                 $_FILES['userfile']['size'] = $files['userfile']['size'][0];
  482.                 $gen_name = $number.$file_id;
  483.  
  484.                
  485.                 $this->upload->initialize($this->set_upload_options($gen_name));
  486.                 $this->upload->do_upload();
  487.  
  488.                 $this->image_lib->initialize($this->manipulation_image($this->upload->data('file_name')));
  489.                 $this->image_lib->resize();
  490.  
  491.                 if($img_id == 0)
  492.                 {
  493.                     $gen_id = $number;
  494.                 }
  495.                 else
  496.                 {
  497.                     $gen_id = $img_id;
  498.                 }
  499.                 $temparr = array(
  500.                     'u_id' => $this->session->userdata('id'),
  501.                     'p_p_id' => $gen_id,
  502.                     'img' => $this->upload->data('file_name'),
  503.                     'orig_img' => $files['userfile']['name'][0]
  504.                 );
  505.                 array_push($img, $temparr);
  506.                
  507.                 //
  508.                 $this->db->insert_batch('p_preview_img', $img);
  509.                 $arr['success'] = true;
  510.                 echo json_encode($arr);
  511.             }
  512.         }
  513.     }
  514.  
  515.     public function dellimg($id)
  516.     {
  517.         $where = array('id' => $id);
  518.         $data = $this->Site_model->get_single('p_preview_img', $where);
  519.  
  520.         unlink('./assets/pimg/'.$data->img);
  521.         $this->Site_model->delete('p_preview_img', $where);
  522.  
  523.         $arr['success'] = true;
  524.         echo json_encode($arr);
  525.     }
  526.  
  527.     //---------------------- FINALNE DODANIE OGLOSZENIA ---------------------- START
  528.     public function newadd($id)
  529.     {
  530.  
  531.         $where = array('id' => $id);
  532.         $p_data = $this->Site_model->get_single('p_preview', $where);
  533.  
  534.         $typ = $p_data->typ;   
  535.         $waznosc = time() + ($p_data->waznosc * 24 * 60 * 60); 
  536.  
  537.         $data = array(
  538.             'u_id' => $p_data->u_id,
  539.             'nazwa' => $p_data->nazwa,
  540.             'cena' => $p_data->cena,
  541.             'status' => $p_data->status,
  542.             'kategoria' => $p_data->kategoria,
  543.             'opis' => $p_data->opis,
  544.             'typ' => $p_data->typ,
  545.             'v_link' => $p_data->v_link,
  546.             'waznosc' => $waznosc,
  547.             'created_time' => time()
  548.         );
  549.  
  550.         $this->Site_model->create('p_list', $data);
  551.         $insertId = $this->db->insert_id();
  552.  
  553.         $new_p_id = array(
  554.             'p_p_id' => '',
  555.             'p_id' => $insertId,
  556.         );
  557.  
  558.         $where = array('p_p_id' => $id);
  559.         $this->Site_model->update('p_preview_img', $where, $new_p_id);
  560.  
  561.         $new_id_supp = array(
  562.             'p_id' => $insertId,
  563.             'preview' => 0,
  564.         );
  565.         $where = array('p_id' => $id);
  566.         $this->Site_model->update('p_supply', $where, $new_id_supp);
  567.  
  568.         if($typ == 2)
  569.         {
  570.             $where = array('p_id' => $id);
  571.             $a_data = $this->Site_model->get_single('auction_list', $where);
  572.  
  573.             $dzien = date('Y-m-d', $a_data->waznosc);
  574.             $dokladna_data = new DateTime($dzien.' '.$a_data->godzina.':00:00');
  575.            
  576.             $new_id_auction = array(
  577.                 'p_id' => $insertId,
  578.                 'waznosc' => $dokladna_data->getTimestamp(),
  579.                 'preview' => 0,
  580.             );
  581.             $where = array('p_id' => $id);
  582.             $this->Site_model->update('auction_list', $where, $new_id_auction);
  583.         }
  584.  
  585.         $where = array('id' => $id);
  586.         $this->Site_model->delete('p_preview', $where);
  587.  
  588.         redirect('product/'.$insertId);
  589.     }
  590.     //---------------------- FINALNE DODANIE OGLOSZENIA ---------------------- START
  591.  
  592.     public function update($id)
  593.     {
  594.         $where = array('id' => $id);
  595.         $product_data = $this->Site_model->get_single( 'p_list' , $where );
  596.         if($product_data->u_id == $this->session->userdata('id'))
  597.         {  
  598.             $img_number = $this->input->post( 'temp_id' , true );
  599.  
  600.                 $data = array(
  601.                     'nazwa' => $this->input->post( 'nazwa' , true ),
  602.                     'cena' => $this->input->post( 'cena' , true ),
  603.                     'status' => $this->input->post( 'status' , true ),
  604.                     'kategoria' => $this->input->post( 'kategoria' , true ),
  605.                     'opis' => $this->input->post( 'opis' , true ),
  606.                     'v_link' => $this->input->post( 'v_link' , true )
  607.                 );
  608.  
  609.                 $this->Site_model->update('p_list', $where, $data);
  610.  
  611.  
  612.             $new_p_id = array(
  613.                 'p_p_id' => '',
  614.                 'p_id' => $id,
  615.             );
  616.  
  617.             $where = array('p_p_id' => $img_number);
  618.             $this->Site_model->update('p_preview_img', $where, $new_p_id);
  619.             redirect('product/'.$id.'-'.make_alias($product_data->nazwa));
  620.         }
  621.  
  622.        
  623.     }
  624.  
  625.     public function obs_add($id)
  626.     {
  627.         $where = array('p_id' => $id, 'u_id' => $this->session->userdata('id'));
  628.         $o_product = $this->Site_model->get_single( 'p_obs' , $where );
  629.  
  630.         if(empty($o_product))
  631.         {
  632.             $data = array(
  633.                 'u_id' => $this->session->userdata('id'),
  634.                 'p_id' => $id
  635.             );
  636.  
  637.             $this->Site_model->create('p_obs', $data);
  638.             $arr['success'] = true;
  639.         }
  640.         else
  641.         {
  642.             $arr['success'] = false;
  643.         }
  644.        
  645.         echo json_encode($arr);
  646.     }
  647.  
  648.     public function obs_del($id)
  649.     {
  650.         $where = array('p_id' => $id, 'u_id' => $this->session->userdata('id'));
  651.         $o_product = $this->Site_model->get_single( 'p_obs' , $where );
  652.  
  653.         if(!empty($o_product))
  654.         {
  655.             $this->Site_model->delete('p_obs', $where);
  656.             $arr['success'] = true;
  657.         }
  658.         else
  659.         {
  660.             $arr['success'] = false;
  661.         }
  662.        
  663.         echo json_encode($arr);
  664.     }
  665.  
  666.     private function set_upload_options($name)
  667.     {  
  668.         //upload an image options
  669.         $config = array();
  670.         $config['upload_path'] = './assets/pimg/';
  671.         $config['file_name'] = $name;
  672.         $config['allowed_types'] = 'gif|jpg|png';
  673.         $config['max_size']      = '0';
  674.         $config['overwrite'] = TRUE;
  675.         $config['overwrite']     = FALSE;
  676.  
  677.         return $config;
  678.     }
  679.  
  680.     private function manipulation_image($name)
  681.     {  
  682.         //upload an image options
  683.         $image = array();
  684.         $image['image_library'] = 'gd2';
  685.         $image['source_image'] = './assets/pimg/'.$name;
  686.         $image['new_image']= './assets/pimg/'.$name;
  687.         $image['create_thumb'] = FALSE;
  688.         $image['maintain_ratio'] = TRUE;
  689.         $image['width'] = 635;
  690.         $image['height'] = 300;
  691.  
  692.         return $image;
  693.     }
  694.  
  695. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement