Advertisement
ahmadtri26

xmall

Mar 6th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 13.25 KB | None | 0 0
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2.  
  3. /**
  4. * Class xmall
  5. */
  6. class Xmall extends CI_Controller
  7. {
  8.     protected $segment;
  9.     protected $linkPage;
  10.     protected $totalPage    = 0;
  11.     protected $perPage      = 0;
  12.     private $AGENT = 50;
  13.  
  14.     // ** Fake Class Name (Trick for many menu in one class) ** //
  15.     public $xmall_item_cat = 'xmall_item_cat';
  16.     public $xmall_agent_delivery = 'xmall_agent_delivery';
  17.  
  18.     function __construct()
  19.     {
  20.         parent::__construct();
  21.         $this->load->model('xmall_model');
  22.  
  23.         $this->template->set_template('sbadmin2');
  24.  
  25.         $user_info = $this->session->userdata('user_info');
  26.  
  27.         if (! isset($user_info->username)) {
  28.             show_404();
  29.         }
  30.         $this->load->helper(array('goexpress','file'));
  31.     }
  32.     protected function start_page($uri) {
  33.         if ($this->uri->segment($uri) > 0) {
  34.             $start = $this->uri->segment($uri);
  35.         } else {
  36.             $start = 0;
  37.         }
  38.         return $start;
  39.     }
  40.  
  41.     protected function pagination() {
  42.         $this->load->library('pagination');
  43.         $config = array();
  44.         $config['uri_segment']    = $this->segment;
  45.         $config['base_url']       = $this->linkPage;
  46.         $config['total_rows']     = $this->totalPage;
  47.         $config['per_page']       = $this->perPage;
  48.         $config['full_tag_open']  = '<ul class="pagination">';
  49.         $config['full_tag_close'] = '</ul>';
  50.         $this->pagination->initialize($config);
  51.         return $this->pagination->create_links();
  52.     }
  53.  
  54.     function master_item_category()
  55.     {
  56.         $this->gox_acl->validate_read('', $this->xmall_item_cat);
  57.         $data = array();
  58.         $this->linkPage = site_url("xmall/master_item_category");
  59.         $this->segment = 3;
  60.         $this->perPage = 10;
  61.         $params['offset'] = $this->start_page($this->segment);
  62.         $params['limit'] = $this->perPage;
  63.         $this->totalPage = $this->xmall_model->get_item_master_category($params, true);
  64.         $data['records'] = $this->xmall_model->get_item_master_category($params, false);
  65.         $data['start']   = $params['offset']+1;
  66.         $data['link']    = $this->pagination();
  67.         $this->template->write_view('content', 'xmall/xmall_master_item_category', $data);
  68.         $this->template->render();
  69.     }
  70.  
  71.     function add_master_category()
  72.     {
  73.         $this->gox_acl->validate_create('', $this->xmall_item_cat);
  74.         $user_info = $this->session->userdata('user_info');
  75.  
  76.         if( !isset($user_info->username))
  77.             show_404();
  78.  
  79.         $data['subTitle']   = 'Add Master Category';
  80.         $data['records']    = $this->xmall_model->get_seq_num_t();
  81.         $this->load->view('xmall/xmall_category_add', $data);
  82.     }
  83.  
  84.     function save_master_category()
  85.     {
  86.         // die(var_dump($this->input->post     ()));
  87.         $user_info = $this->session->userdata('user_info');
  88.  
  89.         if( !isset($user_info->username))
  90.             show_404();
  91.  
  92.         $data['status'] = "false";
  93.         $data['message']= lang('msg_failed_saved');
  94.         $id = $this->input->post('id');
  95.  
  96.         // checking
  97.         // $check  = $this->xfood_model->get(array('restoname' => $this->input->post('restoname')));
  98.         // if(count($check) == 0 || (count($check) >= 0 & $id > 0)) {
  99.  
  100.  
  101.         // if($id > 0) {
  102.        
  103.         $params = array(
  104.             'category'     => $this->input->post('category_name'),
  105.             'category_km'  => $this->input->post('category_name_km'),
  106.             'category_cn'  => $this->input->post('category_name_cn'),
  107.             // 'category_kr'  => $this->input->post('category_name_kr'),
  108.             // 'category_jp'  => $this->input->post('category_name_jp'),
  109.             'id'       => $this->input->post('id'),
  110.             'sort_seq' => $this->input->post('sort_seq')
  111.         );
  112.        
  113.         list($result, $i_id) = $this->xmall_model->save_master_category($params, $id);
  114.  
  115.         if ($result == true) {
  116.             $data['status'] = "true";
  117.             $data['id'] = $i_id;
  118.             $data['message'] = lang('msg_success_saved');
  119.  
  120.         } else {
  121.             $data['status'] = 'false';
  122.             $data['message'] = 'Error';
  123.         }
  124.  
  125.        echo json_encode($data);
  126.     }
  127.  
  128.     public function upload_pic_mall_category($id_cat)
  129.     {
  130.         if (isset($_FILES['catimage']) && !empty($_FILES['catimage'])) {
  131.             if ($_FILES['catimage']['error'] != 4) {
  132.  
  133.                 // Delete Old Image if present
  134.                 // if( $this->input->post('old_img') ){
  135.                 //     if ( file_exists('upload/xfood/food_tags/'. $this->input->post('old_img')) ) {
  136.                 //         echo "Start Delete";
  137.                 //         unlink('upload/xfood/food_tags/'. $this->input->post('old_img'));
  138.                 //     }
  139.                 // }
  140.  
  141.                 // Move Old Image to Trash if present
  142.                 if( $this->input->post('old_img') ){
  143.                     if ( file_exists('upload/xmall/mall_category/'. $this->input->post('old_img')) ) {
  144.                         echo "Start Move to Trash";
  145.                         rename('upload/xmall/mall_category/'. $this->input->post('old_img'), 'upload/xmall/trash/'. $this->input->post('old_img'));
  146.                     }
  147.                 }
  148.  
  149.                 $id         = $id_cat;
  150.                 $newfile    = md5($_FILES['catimage']['name']) . $this->random_key();
  151.                 $ext        = get_uploaded_file_extention( $_FILES['catimage']['name']);
  152.                 $tempFile   = $_FILES['catimage']['tmp_name'];
  153.                 $path       = realpath(FCPATH). FILE_SEPARATOR. 'upload/xmall/mall_category/'.$newfile. $ext;
  154.  
  155.                 // die(var_dump($newfile, $ext, $tempFile, $path, $id));
  156.  
  157.                 if($this->xmall_model->update_pic_mall_category($id, $newfile.$ext)){
  158.                     move_uploaded_file($tempFile, $path);
  159.                 }
  160.             }
  161.         }
  162.     }
  163.  
  164.     public function destroy_master_category($id, $img="") {
  165.         $this->gox_acl->validate_delete('', $this->xmall_item_cat);
  166.         $del = $this->xmall_model->delete_master_category($id);
  167.  
  168.         if ($del == true) {
  169.             if($img != "" ){
  170.                 if(file_exists('upload/xmall/mall_category/'.$img)){
  171.                     unlink('upload/xmall/mall_category/'.$img); //Delete Image from server
  172.                 }
  173.             }    
  174.             $data['message']    = lang('msg_success_delete');
  175.             $data['status']     = 'true';
  176.         } else {
  177.             $data['message']    = lang('msg_failed_delete');
  178.             $data['status']     = 'false';
  179.         }
  180.  
  181.         echo json_encode($data);
  182.     }
  183.  
  184.     function edit_master_category($id)
  185.     {
  186.         $this->gox_acl->validate_update('', $this->xmall_item_cat);
  187.         $user_info = $this->session->userdata('user_info');
  188.  
  189.         if( !isset($user_info->username))
  190.             show_404();
  191.  
  192.         $data['subTitle']   = 'Update Category';
  193.         $data['records']    = $this->xmall_model->get_master_category_data(array('id'=>$id));
  194.         // $data['cert']       =   $this->xfood_model->get_cert();
  195.         $this->load->view('xmall/xmall_category_edit', $data);
  196.     }
  197.  
  198.     public function random_key()
  199.     {
  200.         $rand = "";
  201.         $seed = str_split('ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  202.                  .'0123456789'); // and any other characters
  203.         shuffle($seed); // probably optional since array_is randomized; this may be redundant
  204.         foreach (array_rand($seed, 4) as $k)
  205.             $rand .= $seed[$k];
  206.  
  207.         return $rand;
  208.     }
  209.  
  210.  
  211.     //    Xmall Agent Delivery start   //
  212.  
  213.     function master_agent_delivery()
  214.     {
  215.         $this->gox_acl->validate_read('', $this->xmall_agent_delivery);
  216.         $data = array();
  217.         $this->linkPage = site_url("xmall/master_agent_delivery");
  218.         $this->segment = 3;
  219.         $this->perPage = 10;
  220.         $params['offset'] = $this->start_page($this->segment);
  221.         $params['limit'] = $this->perPage;
  222.         $this->totalPage = $this->xmall_model->get_item_master_agent($params, true);
  223.         $data['records'] = $this->xmall_model->get_item_master_agent($params, false);
  224.         $data['start']   = $params['offset']+1;
  225.         $data['link']    = $this->pagination();
  226.         $this->template->write_view('content', 'xmall/xmall_master_agent_delivery', $data);
  227.         $this->template->render();
  228.     }
  229.  
  230.     function add_master_agent()
  231.     {
  232.         $this->gox_acl->validate_create('', $this->xmall_agent_delivery);
  233.         $user_info = $this->session->userdata('user_info');
  234.  
  235.         if( !isset($user_info->username))
  236.             show_404();
  237.  
  238.         $data['subTitle']   = 'Add Master Agent';
  239.         $data['records']    = $this->xmall_model->get_seq_num_agent();
  240.         $this->load->view('xmall/xmall_agent_add', $data);
  241.     }
  242.  
  243.     function save_master_agent()
  244.     {
  245.         // die(var_dump($this->input->post     ()));
  246.         $user_info = $this->session->userdata('user_info');
  247.  
  248.         if( !isset($user_info->username))
  249.             show_404();
  250.  
  251.         $data['status'] = "false";
  252.         $data['message']= lang('msg_failed_saved');
  253.         $id = $this->input->post('id');
  254.  
  255.         // checking
  256.         // $check  = $this->xfood_model->get(array('restoname' => $this->input->post('restoname')));
  257.         // if(count($check) == 0 || (count($check) >= 0 & $id > 0)) {
  258.  
  259.  
  260.         // if($id > 0) {
  261.        
  262.         $params = array(
  263.             'agent'     => $this->input->post('agent_name'),
  264.             // 'agent_km'  => $this->input->post('agent_name_km'),
  265.             // 'agent_cn'  => $this->input->post('agent_name_cn'),
  266.             'cost'  => $this->input->post('cost'),
  267.             // 'name_agent_kr'  => $this->input->post('agent_name_kr'),
  268.             // 'name_agent_jp'  => $this->input->post('agent_name_jp'),
  269.             'id'       => $this->input->post('id'),
  270.             'sort_seq' => $this->input->post('sort_seq')
  271.         );
  272.        
  273.         list($result, $i_id) = $this->xmall_model->save_master_agent($params, $id);
  274.  
  275.         if ($result == true) {
  276.             $data['status'] = "true";
  277.             $data['id'] = $i_id;
  278.             $data['message'] = lang('msg_success_saved');
  279.  
  280.         } else {
  281.             $data['status'] = 'false';
  282.             $data['message'] = 'Error';
  283.         }
  284.  
  285.        echo json_encode($data);
  286.     }
  287.  
  288.     public function upload_pic_mall_agent($id_cat)
  289.     {
  290.         if (isset($_FILES['agimage']) && !empty($_FILES['agimage'])) {
  291.             if ($_FILES['agimage']['error'] != 4) {
  292.  
  293.                 // Delete Old Image if present
  294.                 // if( $this->input->post('old_img') ){
  295.                 //     if ( file_exists('upload/xfood/food_tags/'. $this->input->post('old_img')) ) {
  296.                 //         echo "Start Delete";
  297.                 //         unlink('upload/xfood/food_tags/'. $this->input->post('old_img'));
  298.                 //     }
  299.                 // }
  300.  
  301.                 // Move Old Image to Trash if present
  302.                 if( $this->input->post('old_img') ){
  303.                     if ( file_exists('upload/xmall/agent_delivery/'. $this->input->post('old_img')) ) {
  304.                         echo "Start Move to Trash";
  305.                         rename('upload/xmall/agent_delivery/'. $this->input->post('old_img'), 'upload/xmall/trash/'. $this->input->post('old_img'));
  306.                     }
  307.                 }
  308.  
  309.                 $id         = $id_cat;
  310.                 $newfile    = md5($_FILES['agimage']['name']) . $this->random_key();
  311.                 $ext        = get_uploaded_file_extention( $_FILES['agimage']['name']);
  312.                 $tempFile   = $_FILES['agimage']['tmp_name'];
  313.                 $path       = realpath(FCPATH). FILE_SEPARATOR. 'upload/xmall/agent_delivery/'.$newfile. $ext;
  314.  
  315.                 // die(var_dump($newfile, $ext, $tempFile, $path, $id));
  316.  
  317.                 if($this->xmall_model->update_pic_mall_agent($id, $newfile.$ext)){
  318.                     move_uploaded_file($tempFile, $path);
  319.                 }
  320.             }
  321.         }
  322.     }
  323.  
  324.     public function destroy_master_agent($id, $img="") {
  325.         $this->gox_acl->validate_delete('', $this->xmall_agent_delivery);
  326.         $del = $this->xmall_model->delete_master_agent($id);
  327.  
  328.         if ($del == true) {
  329.             if($img != "" ){
  330.                 if(file_exists('upload/xmall/agent_delivery/'.$img)){
  331.                     unlink('upload/xmall/agent_delivery/'.$img); //Delete Image from server
  332.                 }
  333.             }    
  334.             $data['message']    = lang('msg_success_delete');
  335.             $data['status']     = 'true';
  336.         } else {
  337.             $data['message']    = lang('msg_failed_delete');
  338.             $data['status']     = 'false';
  339.         }
  340.  
  341.         echo json_encode($data);
  342.     }
  343.  
  344.     function edit_master_agent($id)
  345.     {
  346.         $this->gox_acl->validate_update('', $this->xmall_agent_delivery);
  347.         $user_info = $this->session->userdata('user_info');
  348.  
  349.         if( !isset($user_info->username))
  350.             show_404();
  351.  
  352.         $data['subTitle']   = 'Update Agent';
  353.         $data['records']    = $this->xmall_model->get_master_agent_data(array('id'=>$id));
  354.         // $data['cert']       =   $this->xfood_model->get_cert();
  355.         $this->load->view('xmall/xmall_agent_edit', $data);
  356.     }
  357.  
  358.  
  359. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement