Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- defined('BASEPATH') OR exit('No direct script access allowed');
- class Product extends User_Controller {
- /**
- * Index Page for this controller.
- *
- * Maps to the following URL
- * http://example.com/index.php/welcome
- * - or -
- * http://example.com/index.php/welcome/index
- * - or -
- * Since this controller is set as the default controller in
- * config/routes.php, it's displayed at http://example.com/
- *
- * So any other public methods not prefixed with an underscore will
- * map to /index.php/welcome/<method_name>
- * @see https://codeigniter.com/user_guide/general/urls.html
- */
- public function index()
- {
- }
- public function preview($id = null)
- {
- //---------------------- ZALADOWANIE PODGLADU PO EDYCJI (Z ID) ---------------------- START
- if($id)
- {
- if (!empty($_POST))
- {
- //** TYMCZASOWE ID (wygenerowane po stronie front-end w celu atkualizacji id po utworzeniu podgladowego ogloszenia)
- $img_number = $this->input->post('temp_id', true);
- //-------------------------------------------------------------
- //** SPRAWDZANIE TYPU OGLOSZENIA I OKRESLENIE STATUSU (1 = KUP TERAZ; 2 = AUKCJA)
- $typ = $this->input->post('typ', true);
- if($typ == 1)
- {
- $status = $this->input->post('status', true);
- }
- else if($typ == 2)
- {
- $status = 0;
- }
- //-------------------------------------------------------------
- //----** ZMIENNE FUNKCJONALNE
- $waznosc = time() + ($this->input->post('waznosc', true) * 24 * 60 * 60);
- $dostawa = $this->input->post('d_nazwa', true);
- //-------------------------------------------------------------
- //----** DANE PODGLADU DO DB (@return ID)
- $data['products'] = array(
- 'u_id' => $this->session->userdata('id'),
- 'nazwa' => $this->input->post('nazwa', true),
- 'cena' => $this->input->post('cena', true),
- 'status' => $status,
- 'kategoria' => $this->input->post('kategoria', true),
- 'typ' => $this->input->post('typ', true),
- 'opis' => $this->input->post('opis', true),
- 'v_link' => $this->input->post('v_link', true),
- 'waznosc' => $this->input->post('waznosc', true)
- );
- $where = array('id' => $id);
- $this->Site_model->update('p_preview', $where, $data['products']);
- $insertId = $id;
- //-------------------------------------------------------------
- //----** DANE O DOSTAWIE DO DB
- if($dostawa)
- {
- $where = array('p_id' => $id, 'preview' => 1);
- $this->Site_model->delete('p_supply', $where);
- foreach($dostawa as $key=>$dost)
- {
- $dost_data[] = array(
- 'p_id' => $insertId,
- 'sposob' => $this->input->post('d_nazwa', true)[$key],
- 'koszt' => $this->input->post('d_cena', true)[$key],
- 'realizacja' => $this->input->post('d_realizacja', true)[$key],
- 'preview' => 1
- );
- }
- $this->db->insert_batch('p_supply', $dost_data);
- }
- //-------------------------------------------------------------
- //----** AKTUALIZUJE ID PODGLADU DLA WGRANYCH OBRAZKOW
- $up_img_id = array(
- 'p_p_id' => $insertId,
- );
- $where = array('p_p_id' => $img_number);
- $this->Site_model->update('p_preview_img', $where, $up_img_id);
- //-------------------------------------------------------------
- //----** DANE O AUKCJI DO DB
- if($typ == 2)
- {
- $where = array('p_id' => $id, 'preview' => 1);
- $auct_data = array(
- 'p_id' => $insertId,
- 'waznosc' => $waznosc,
- 'godzina' => $this->input->post('a_godzina', true),
- 'preview' => 1
- );
- $this->Site_model->update('auction_list', $where, $auct_data);
- }
- //-------------------------------------------------------------
- //----** FUNKCJE GET DO WYSWIETLENIA
- if($typ ==2)
- {
- $curr_date1 = time();
- $waznosc_date2 = $waznosc - $curr_date1;
- $diff_date = round($waznosc_date2 / 86400);
- if($diff_date >= 2)
- {
- $diff_date_title = ' dni do końca aukcji';
- }
- else if($diff_date == 1)
- {
- $temp_diff_date = round($waznosc_date2 / 60);
- if($temp_diff_date < 1440 && $temp_diff_date > 0)
- {
- $diff_date_title = $diff_date_title = ' do końca aukcji';
- $diff_date = 0;
- }
- else
- {
- $diff_date_title = ' dzień do końca aukcji';
- }
- }
- else if($diff_date == 0)
- {
- $temp_diff_date = round($waznosc_date2 / 60);
- if($temp_diff_date < 1440 && $temp_diff_date > 0)
- {
- $diff_date_title = $diff_date_title = ' do końca aukcji';
- $diff_date = 0;
- }
- else
- {
- $diff_date_title = 'Aukcja zakończona';
- $diff_date = -1;
- }
- }
- else if($diff_date < 0)
- {
- $diff_date_title = 'Aukcja zakończona';
- $diff_date = -1;
- }
- $dzien = date('d.m.Y', $waznosc);
- $godzina = $this->input->post('a_godzina', true).':00:00';
- $js_data = array(
- 'rok' => date('Y', $waznosc),
- 'miesiac' => date('m', $waznosc),
- 'dzien' => date('d', $waznosc),
- );
- $data['auction'] = array(
- 'data' => $dzien,
- 'js_data' => $js_data,
- 'godzina' => $godzina,
- 'pozostalo' => $diff_date,
- 'pozostalo_t' => $diff_date_title,
- );
- $data['auction'] = json_decode (json_encode ($data['auction']), FALSE);
- }
- $data['number'] = array('id' => $insertId);
- $data['number'] = json_decode (json_encode ($data['number']), FALSE);
- $where = array('u_id' => $this->session->userdata('id'));
- $data['company'] = $this->Site_model->get_single('company_data', $where);
- $where = array('p_p_id' => $insertId);
- $data['imgs'] = $this->Site_model->get('p_preview_img', $where);
- $where = array('p_id' => $insertId, 'preview' => 1);
- $data['supply'] = $this->Site_model->get('p_supply', $where);
- $data['products'] = json_decode (json_encode ($data['products']), FALSE);
- //-------------------------------------------------------------
- //----** LADUJE WIDOK W ZALEZNOSCI OD TYPU OGLOSZENIA (1 = KUP TERAZ; 2 = AUKCJA)
- if($typ == 1)
- {
- $this->load->view('user/product_preview', $data);
- }
- else if($typ == 2)
- {
- $this->load->view('user/auction_preview', $data);
- }
- //-------------------------------------------------------------
- }
- }
- //---------------------- ZALADOWANIE PODGLADU PO EDYCJI (Z ID) ---------------------- KONIEC
- else
- //---------------------- ZALADOWANIE PODGLADU PIERWSZY RAZ(BEZ ID) ---------------------- START
- {
- if (!empty($_POST))
- {
- //** TYMCZASOWE ID (wygenerowane po stronie front-end w celu atkualizacji id po utworzeniu podgladowego ogloszenia)
- $img_number = $this->input->post('temp_id', true);
- //-------------------------------------------------------------
- //** SPRAWDZANIE TYPU OGLOSZENIA I OKRESLENIE STATUSU (1 = KUP TERAZ; 2 = AUKCJA)
- $typ = $this->input->post('typ', true);
- if($typ == 1)
- {
- $status = $this->input->post('status', true);
- }
- else if($typ == 2)
- {
- $status = 0;
- }
- //-------------------------------------------------------------
- //----** ZMIENNE FUNKCJONALNE
- $waznosc = time() + ($this->input->post('waznosc', true) * 24 * 60 * 60);
- $dostawa = $this->input->post('d_nazwa', true);
- //-------------------------------------------------------------
- //----** DANE PODGLADU DO DB (@return ID)
- $data['products'] = array(
- 'u_id' => $this->session->userdata('id'),
- 'nazwa' => $this->input->post('nazwa', true),
- 'cena' => $this->input->post('cena', true),
- 'status' => $status,
- 'kategoria' => $this->input->post('kategoria', true),
- 'typ' => $this->input->post('typ', true),
- 'opis' => $this->input->post('opis', true),
- 'v_link' => $this->input->post('v_link', true),
- 'waznosc' => $this->input->post('waznosc', true)
- );
- $this->Site_model->create('p_preview', $data['products']);
- $insertId = $this->db->insert_id();
- //-------------------------------------------------------------
- //----** DANE O DOSTAWIE DO DB
- if($dostawa)
- {
- foreach($dostawa as $key=>$dost)
- {
- $dost_data[] = array(
- 'p_id' => $insertId,
- 'sposob' => $this->input->post('d_nazwa', true)[$key],
- 'koszt' => $this->input->post('d_cena', true)[$key],
- 'realizacja' => $this->input->post('d_realizacja', true)[$key],
- 'preview' => 1
- );
- }
- $this->db->insert_batch('p_supply', $dost_data);
- }
- //-------------------------------------------------------------
- //----** AKTUALIZUJE ID PODGLADU DLA WGRANYCH OBRAZKOW
- $up_img_id = array(
- 'p_p_id' => $insertId,
- );
- $where = array('p_p_id' => $img_number);
- $this->Site_model->update('p_preview_img', $where, $up_img_id);
- //-------------------------------------------------------------
- //----** DANE O AUKCJI DO DB
- if($typ == 2)
- {
- $auct_data = array(
- 'p_id' => $insertId,
- 'waznosc' => $waznosc,
- 'godzina' => $this->input->post('a_godzina', true),
- 'preview' => 1
- );
- $this->Site_model->create('auction_list', $auct_data);
- }
- //-------------------------------------------------------------
- //----** FUNKCJE GET DO WYSWIETLENIA
- if($typ ==2)
- {
- $curr_date1 = time();
- $waznosc_date2 = $waznosc - $curr_date1;
- $diff_date = round($waznosc_date2 / 86400);
- if($diff_date >= 2)
- {
- $diff_date_title = ' dni do końca aukcji';
- }
- else if($diff_date == 1)
- {
- $temp_diff_date = round($waznosc_date2 / 60);
- if($temp_diff_date < 1440 && $temp_diff_date > 0)
- {
- $diff_date_title = $diff_date_title = ' do końca aukcji';
- $diff_date = 0;
- }
- else
- {
- $diff_date_title = ' dzień do końca aukcji';
- }
- }
- else if($diff_date == 0)
- {
- $temp_diff_date = round($waznosc_date2 / 60);
- if($temp_diff_date < 1440 && $temp_diff_date > 0)
- {
- $diff_date_title = $diff_date_title = ' do końca aukcji';
- $diff_date = 0;
- }
- else
- {
- $diff_date_title = 'Aukcja zakończona';
- $diff_date = -1;
- }
- }
- else if($diff_date < 0)
- {
- $diff_date_title = 'Aukcja zakończona';
- $diff_date = -1;
- }
- $dzien = date('d.m.Y', $waznosc);
- $godzina = $this->input->post('a_godzina', true).':00:00';
- $js_data = array(
- 'rok' => date('Y', $waznosc),
- 'miesiac' => date('m', $waznosc),
- 'dzien' => date('d', $waznosc),
- );
- $data['auction'] = array(
- 'data' => $dzien,
- 'js_data' => $js_data,
- 'godzina' => $godzina,
- 'pozostalo' => $diff_date,
- 'pozostalo_t' => $diff_date_title,
- );
- $data['auction'] = json_decode (json_encode ($data['auction']), FALSE);
- }
- $data['number'] = array('id' => $insertId);
- $data['number'] = json_decode (json_encode ($data['number']), FALSE);
- $where = array('u_id' => $this->session->userdata('id'));
- $data['company'] = $this->Site_model->get_single('company_data', $where);
- $where = array('p_p_id' => $insertId);
- $data['imgs'] = $this->Site_model->get('p_preview_img', $where);
- $where = array('p_id' => $insertId, 'preview' => 1);
- $data['supply'] = $this->Site_model->get('p_supply', $where);
- $data['products'] = json_decode (json_encode ($data['products']), FALSE);
- //-------------------------------------------------------------
- //----** LADUJE WIDOK W ZALEZNOSCI OD TYPU OGLOSZENIA (1 = KUP TERAZ; 2 = AUKCJA)
- if($typ == 1)
- {
- $this->load->view('user/product_preview', $data);
- }
- else if($typ == 2)
- {
- $this->load->view('user/auction_preview', $data);
- }
- }
- }
- //---------------------- ZALADOWANIE PODGLADU PIERWSZY RAZ(BEZ ID) ---------------------- KONIEC
- }
- public function add($id = null)
- {
- $where = array('main' => 1);
- $data['cats'] = $this->Site_model->get('p_categories', $where);
- for ($i = 0; $i < sizeof($data['cats']); $i++) {
- $where = array('sub_cat' => $data['cats'][$i]->id);
- $data['cats'][$i]->subcat = $this->Site_model->get('p_categories', $where);
- }
- if($id)
- {
- $where = array('id' => $id);
- $data['product'] = $this->Site_model->get_single('p_preview', $where);
- //----** JEZELI AUKCJA TO WCZYTUJE DANE Z DB
- if($data['product']->typ == 2)
- {
- $where = array('p_id' => $id, 'preview' => 1);
- $data['auction'] = $this->Site_model->get_single('auction_list', $where);
- }
- //-------------------------------------------------------------
- $where = array('p_id' => $id, 'preview' => 1);
- $data['supply'] = $this->Site_model->get('p_supply', $where);
- $where = array('p_p_id' => $id);
- $data['img'] = $this->Site_model->get('p_preview_img', $where);
- $this->load->view('user/product_re_add', $data);
- }
- else
- {
- $this->load->view('user/product_add', $data);
- }
- }
- public function edit($id = null)
- {
- $where = array('id' => $id);
- $product_data = $this->Site_model->get_single( 'p_list' , $where );
- if($product_data->u_id == $this->session->userdata('id'))
- {
- $where = array('main' => 1);
- $data['cats'] = $this->Site_model->get('p_categories', $where);
- for ($i = 0; $i < sizeof($data['cats']); $i++) {
- $where = array('sub_cat' => $data['cats'][$i]->id);
- $data['cats'][$i]->subcat = $this->Site_model->get('p_categories', $where);
- }
- if($id && $product_data->active == 1)
- {
- $where = array('id' => $id);
- $data['product'] = $this->Site_model->get_single('p_list', $where);
- $where = array('p_id' => $id);
- $data['img'] = $this->Site_model->get('p_preview_img', $where);
- $this->load->view('user/product_edit', $data);
- }
- else
- {
- $this->session->set_flashdata( 'error' , 'Nie znaleziono takiego ogłoszenia' );
- redirect('profile/products_list');
- }
- }
- else
- {
- $this->session->set_flashdata( 'error' , 'Nie posiadasz uprawnień do edycji tego ogłoszenia.' );
- redirect('profile/products_list');
- }
- }
- public function addimg()
- {
- if($_FILES)
- {
- // image upload&resize
- if(!empty($_FILES['userfile']['name'][0]))
- {
- $this->load->library('upload');
- $this->load->library('image_lib');
- $dataInfo = array();
- $img = array();
- $number = $this->input->post( 'number' , true );
- $img_id = $this->input->post( 'img_id' , true );
- $file_id = $this->input->post( 'file_id' , true );
- $files = $_FILES;
- $_FILES['userfile']['name'] = $files['userfile']['name'][0];
- $_FILES['userfile']['type'] = $files['userfile']['type'][0];
- $_FILES['userfile']['tmp_name'] = $files['userfile']['tmp_name'][0];
- $_FILES['userfile']['error'] = $files['userfile']['error'][0];
- $_FILES['userfile']['size'] = $files['userfile']['size'][0];
- $gen_name = $number.$file_id;
- $this->upload->initialize($this->set_upload_options($gen_name));
- $this->upload->do_upload();
- $this->image_lib->initialize($this->manipulation_image($this->upload->data('file_name')));
- $this->image_lib->resize();
- if($img_id == 0)
- {
- $gen_id = $number;
- }
- else
- {
- $gen_id = $img_id;
- }
- $temparr = array(
- 'u_id' => $this->session->userdata('id'),
- 'p_p_id' => $gen_id,
- 'img' => $this->upload->data('file_name'),
- 'orig_img' => $files['userfile']['name'][0]
- );
- array_push($img, $temparr);
- //
- $this->db->insert_batch('p_preview_img', $img);
- $arr['success'] = true;
- echo json_encode($arr);
- }
- }
- }
- public function dellimg($id)
- {
- $where = array('id' => $id);
- $data = $this->Site_model->get_single('p_preview_img', $where);
- unlink('./assets/pimg/'.$data->img);
- $this->Site_model->delete('p_preview_img', $where);
- $arr['success'] = true;
- echo json_encode($arr);
- }
- //---------------------- FINALNE DODANIE OGLOSZENIA ---------------------- START
- public function newadd($id)
- {
- $where = array('id' => $id);
- $p_data = $this->Site_model->get_single('p_preview', $where);
- $typ = $p_data->typ;
- $waznosc = time() + ($p_data->waznosc * 24 * 60 * 60);
- $data = array(
- 'u_id' => $p_data->u_id,
- 'nazwa' => $p_data->nazwa,
- 'cena' => $p_data->cena,
- 'status' => $p_data->status,
- 'kategoria' => $p_data->kategoria,
- 'opis' => $p_data->opis,
- 'typ' => $p_data->typ,
- 'v_link' => $p_data->v_link,
- 'waznosc' => $waznosc,
- 'created_time' => time()
- );
- $this->Site_model->create('p_list', $data);
- $insertId = $this->db->insert_id();
- $new_p_id = array(
- 'p_p_id' => '',
- 'p_id' => $insertId,
- );
- $where = array('p_p_id' => $id);
- $this->Site_model->update('p_preview_img', $where, $new_p_id);
- $new_id_supp = array(
- 'p_id' => $insertId,
- 'preview' => 0,
- );
- $where = array('p_id' => $id);
- $this->Site_model->update('p_supply', $where, $new_id_supp);
- if($typ == 2)
- {
- $where = array('p_id' => $id);
- $a_data = $this->Site_model->get_single('auction_list', $where);
- $dzien = date('Y-m-d', $a_data->waznosc);
- $dokladna_data = new DateTime($dzien.' '.$a_data->godzina.':00:00');
- $new_id_auction = array(
- 'p_id' => $insertId,
- 'waznosc' => $dokladna_data->getTimestamp(),
- 'preview' => 0,
- );
- $where = array('p_id' => $id);
- $this->Site_model->update('auction_list', $where, $new_id_auction);
- }
- $where = array('id' => $id);
- $this->Site_model->delete('p_preview', $where);
- redirect('product/'.$insertId);
- }
- //---------------------- FINALNE DODANIE OGLOSZENIA ---------------------- START
- public function update($id)
- {
- $where = array('id' => $id);
- $product_data = $this->Site_model->get_single( 'p_list' , $where );
- if($product_data->u_id == $this->session->userdata('id'))
- {
- $img_number = $this->input->post( 'temp_id' , true );
- $data = array(
- 'nazwa' => $this->input->post( 'nazwa' , true ),
- 'cena' => $this->input->post( 'cena' , true ),
- 'status' => $this->input->post( 'status' , true ),
- 'kategoria' => $this->input->post( 'kategoria' , true ),
- 'opis' => $this->input->post( 'opis' , true ),
- 'v_link' => $this->input->post( 'v_link' , true )
- );
- $this->Site_model->update('p_list', $where, $data);
- $new_p_id = array(
- 'p_p_id' => '',
- 'p_id' => $id,
- );
- $where = array('p_p_id' => $img_number);
- $this->Site_model->update('p_preview_img', $where, $new_p_id);
- redirect('product/'.$id.'-'.make_alias($product_data->nazwa));
- }
- }
- public function obs_add($id)
- {
- $where = array('p_id' => $id, 'u_id' => $this->session->userdata('id'));
- $o_product = $this->Site_model->get_single( 'p_obs' , $where );
- if(empty($o_product))
- {
- $data = array(
- 'u_id' => $this->session->userdata('id'),
- 'p_id' => $id
- );
- $this->Site_model->create('p_obs', $data);
- $arr['success'] = true;
- }
- else
- {
- $arr['success'] = false;
- }
- echo json_encode($arr);
- }
- public function obs_del($id)
- {
- $where = array('p_id' => $id, 'u_id' => $this->session->userdata('id'));
- $o_product = $this->Site_model->get_single( 'p_obs' , $where );
- if(!empty($o_product))
- {
- $this->Site_model->delete('p_obs', $where);
- $arr['success'] = true;
- }
- else
- {
- $arr['success'] = false;
- }
- echo json_encode($arr);
- }
- private function set_upload_options($name)
- {
- //upload an image options
- $config = array();
- $config['upload_path'] = './assets/pimg/';
- $config['file_name'] = $name;
- $config['allowed_types'] = 'gif|jpg|png';
- $config['max_size'] = '0';
- $config['overwrite'] = TRUE;
- $config['overwrite'] = FALSE;
- return $config;
- }
- private function manipulation_image($name)
- {
- //upload an image options
- $image = array();
- $image['image_library'] = 'gd2';
- $image['source_image'] = './assets/pimg/'.$name;
- $image['new_image']= './assets/pimg/'.$name;
- $image['create_thumb'] = FALSE;
- $image['maintain_ratio'] = TRUE;
- $image['width'] = 635;
- $image['height'] = 300;
- return $image;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement