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 xmall
- */
- class Xmall extends CI_Controller
- {
- protected $segment;
- protected $linkPage;
- protected $totalPage = 0;
- protected $perPage = 0;
- private $AGENT = 50;
- // ** Fake Class Name (Trick for many menu in one class) ** //
- public $xmall_item_cat = 'xmall_item_cat';
- public $xmall_agent_delivery = 'xmall_agent_delivery';
- function __construct()
- {
- parent::__construct();
- $this->load->model('xmall_model');
- $this->template->set_template('sbadmin2');
- $user_info = $this->session->userdata('user_info');
- if (! isset($user_info->username)) {
- show_404();
- }
- $this->load->helper(array('goexpress','file'));
- }
- protected function start_page($uri) {
- if ($this->uri->segment($uri) > 0) {
- $start = $this->uri->segment($uri);
- } else {
- $start = 0;
- }
- return $start;
- }
- protected function pagination() {
- $this->load->library('pagination');
- $config = array();
- $config['uri_segment'] = $this->segment;
- $config['base_url'] = $this->linkPage;
- $config['total_rows'] = $this->totalPage;
- $config['per_page'] = $this->perPage;
- $config['full_tag_open'] = '<ul class="pagination">';
- $config['full_tag_close'] = '</ul>';
- $this->pagination->initialize($config);
- return $this->pagination->create_links();
- }
- function master_item_category()
- {
- $this->gox_acl->validate_read('', $this->xmall_item_cat);
- $data = array();
- $this->linkPage = site_url("xmall/master_item_category");
- $this->segment = 3;
- $this->perPage = 10;
- $params['offset'] = $this->start_page($this->segment);
- $params['limit'] = $this->perPage;
- $this->totalPage = $this->xmall_model->get_item_master_category($params, true);
- $data['records'] = $this->xmall_model->get_item_master_category($params, false);
- $data['start'] = $params['offset']+1;
- $data['link'] = $this->pagination();
- $this->template->write_view('content', 'xmall/xmall_master_item_category', $data);
- $this->template->render();
- }
- function add_master_category()
- {
- $this->gox_acl->validate_create('', $this->xmall_item_cat);
- $user_info = $this->session->userdata('user_info');
- if( !isset($user_info->username))
- show_404();
- $data['subTitle'] = 'Add Master Category';
- $data['records'] = $this->xmall_model->get_seq_num_t();
- $this->load->view('xmall/xmall_category_add', $data);
- }
- function save_master_category()
- {
- // die(var_dump($this->input->post ()));
- $user_info = $this->session->userdata('user_info');
- if( !isset($user_info->username))
- show_404();
- $data['status'] = "false";
- $data['message']= lang('msg_failed_saved');
- $id = $this->input->post('id');
- // checking
- // $check = $this->xfood_model->get(array('restoname' => $this->input->post('restoname')));
- // if(count($check) == 0 || (count($check) >= 0 & $id > 0)) {
- // if($id > 0) {
- $params = array(
- 'category' => $this->input->post('category_name'),
- 'category_km' => $this->input->post('category_name_km'),
- 'category_cn' => $this->input->post('category_name_cn'),
- // 'category_kr' => $this->input->post('category_name_kr'),
- // 'category_jp' => $this->input->post('category_name_jp'),
- 'id' => $this->input->post('id'),
- 'sort_seq' => $this->input->post('sort_seq')
- );
- list($result, $i_id) = $this->xmall_model->save_master_category($params, $id);
- if ($result == true) {
- $data['status'] = "true";
- $data['id'] = $i_id;
- $data['message'] = lang('msg_success_saved');
- } else {
- $data['status'] = 'false';
- $data['message'] = 'Error';
- }
- echo json_encode($data);
- }
- public function upload_pic_mall_category($id_cat)
- {
- if (isset($_FILES['catimage']) && !empty($_FILES['catimage'])) {
- if ($_FILES['catimage']['error'] != 4) {
- // Delete Old Image if present
- // if( $this->input->post('old_img') ){
- // if ( file_exists('upload/xfood/food_tags/'. $this->input->post('old_img')) ) {
- // echo "Start Delete";
- // unlink('upload/xfood/food_tags/'. $this->input->post('old_img'));
- // }
- // }
- // Move Old Image to Trash if present
- if( $this->input->post('old_img') ){
- if ( file_exists('upload/xmall/mall_category/'. $this->input->post('old_img')) ) {
- echo "Start Move to Trash";
- rename('upload/xmall/mall_category/'. $this->input->post('old_img'), 'upload/xmall/trash/'. $this->input->post('old_img'));
- }
- }
- $id = $id_cat;
- $newfile = md5($_FILES['catimage']['name']) . $this->random_key();
- $ext = get_uploaded_file_extention( $_FILES['catimage']['name']);
- $tempFile = $_FILES['catimage']['tmp_name'];
- $path = realpath(FCPATH). FILE_SEPARATOR. 'upload/xmall/mall_category/'.$newfile. $ext;
- // die(var_dump($newfile, $ext, $tempFile, $path, $id));
- if($this->xmall_model->update_pic_mall_category($id, $newfile.$ext)){
- move_uploaded_file($tempFile, $path);
- }
- }
- }
- }
- public function destroy_master_category($id, $img="") {
- $this->gox_acl->validate_delete('', $this->xmall_item_cat);
- $del = $this->xmall_model->delete_master_category($id);
- if ($del == true) {
- if($img != "" ){
- if(file_exists('upload/xmall/mall_category/'.$img)){
- unlink('upload/xmall/mall_category/'.$img); //Delete Image from server
- }
- }
- $data['message'] = lang('msg_success_delete');
- $data['status'] = 'true';
- } else {
- $data['message'] = lang('msg_failed_delete');
- $data['status'] = 'false';
- }
- echo json_encode($data);
- }
- function edit_master_category($id)
- {
- $this->gox_acl->validate_update('', $this->xmall_item_cat);
- $user_info = $this->session->userdata('user_info');
- if( !isset($user_info->username))
- show_404();
- $data['subTitle'] = 'Update Category';
- $data['records'] = $this->xmall_model->get_master_category_data(array('id'=>$id));
- // $data['cert'] = $this->xfood_model->get_cert();
- $this->load->view('xmall/xmall_category_edit', $data);
- }
- public function random_key()
- {
- $rand = "";
- $seed = str_split('ABCDEFGHIJKLMNOPQRSTUVWXYZ'
- .'0123456789'); // and any other characters
- shuffle($seed); // probably optional since array_is randomized; this may be redundant
- foreach (array_rand($seed, 4) as $k)
- $rand .= $seed[$k];
- return $rand;
- }
- // Xmall Agent Delivery start //
- function master_agent_delivery()
- {
- $this->gox_acl->validate_read('', $this->xmall_agent_delivery);
- $data = array();
- $this->linkPage = site_url("xmall/master_agent_delivery");
- $this->segment = 3;
- $this->perPage = 10;
- $params['offset'] = $this->start_page($this->segment);
- $params['limit'] = $this->perPage;
- $this->totalPage = $this->xmall_model->get_item_master_agent($params, true);
- $data['records'] = $this->xmall_model->get_item_master_agent($params, false);
- $data['start'] = $params['offset']+1;
- $data['link'] = $this->pagination();
- $this->template->write_view('content', 'xmall/xmall_master_agent_delivery', $data);
- $this->template->render();
- }
- function add_master_agent()
- {
- $this->gox_acl->validate_create('', $this->xmall_agent_delivery);
- $user_info = $this->session->userdata('user_info');
- if( !isset($user_info->username))
- show_404();
- $data['subTitle'] = 'Add Master Agent';
- $data['records'] = $this->xmall_model->get_seq_num_agent();
- $this->load->view('xmall/xmall_agent_add', $data);
- }
- function save_master_agent()
- {
- // die(var_dump($this->input->post ()));
- $user_info = $this->session->userdata('user_info');
- if( !isset($user_info->username))
- show_404();
- $data['status'] = "false";
- $data['message']= lang('msg_failed_saved');
- $id = $this->input->post('id');
- // checking
- // $check = $this->xfood_model->get(array('restoname' => $this->input->post('restoname')));
- // if(count($check) == 0 || (count($check) >= 0 & $id > 0)) {
- // if($id > 0) {
- $params = array(
- 'agent' => $this->input->post('agent_name'),
- // 'agent_km' => $this->input->post('agent_name_km'),
- // 'agent_cn' => $this->input->post('agent_name_cn'),
- 'cost' => $this->input->post('cost'),
- // 'name_agent_kr' => $this->input->post('agent_name_kr'),
- // 'name_agent_jp' => $this->input->post('agent_name_jp'),
- 'id' => $this->input->post('id'),
- 'sort_seq' => $this->input->post('sort_seq')
- );
- list($result, $i_id) = $this->xmall_model->save_master_agent($params, $id);
- if ($result == true) {
- $data['status'] = "true";
- $data['id'] = $i_id;
- $data['message'] = lang('msg_success_saved');
- } else {
- $data['status'] = 'false';
- $data['message'] = 'Error';
- }
- echo json_encode($data);
- }
- public function upload_pic_mall_agent($id_cat)
- {
- if (isset($_FILES['agimage']) && !empty($_FILES['agimage'])) {
- if ($_FILES['agimage']['error'] != 4) {
- // Delete Old Image if present
- // if( $this->input->post('old_img') ){
- // if ( file_exists('upload/xfood/food_tags/'. $this->input->post('old_img')) ) {
- // echo "Start Delete";
- // unlink('upload/xfood/food_tags/'. $this->input->post('old_img'));
- // }
- // }
- // Move Old Image to Trash if present
- if( $this->input->post('old_img') ){
- if ( file_exists('upload/xmall/agent_delivery/'. $this->input->post('old_img')) ) {
- echo "Start Move to Trash";
- rename('upload/xmall/agent_delivery/'. $this->input->post('old_img'), 'upload/xmall/trash/'. $this->input->post('old_img'));
- }
- }
- $id = $id_cat;
- $newfile = md5($_FILES['agimage']['name']) . $this->random_key();
- $ext = get_uploaded_file_extention( $_FILES['agimage']['name']);
- $tempFile = $_FILES['agimage']['tmp_name'];
- $path = realpath(FCPATH). FILE_SEPARATOR. 'upload/xmall/agent_delivery/'.$newfile. $ext;
- // die(var_dump($newfile, $ext, $tempFile, $path, $id));
- if($this->xmall_model->update_pic_mall_agent($id, $newfile.$ext)){
- move_uploaded_file($tempFile, $path);
- }
- }
- }
- }
- public function destroy_master_agent($id, $img="") {
- $this->gox_acl->validate_delete('', $this->xmall_agent_delivery);
- $del = $this->xmall_model->delete_master_agent($id);
- if ($del == true) {
- if($img != "" ){
- if(file_exists('upload/xmall/agent_delivery/'.$img)){
- unlink('upload/xmall/agent_delivery/'.$img); //Delete Image from server
- }
- }
- $data['message'] = lang('msg_success_delete');
- $data['status'] = 'true';
- } else {
- $data['message'] = lang('msg_failed_delete');
- $data['status'] = 'false';
- }
- echo json_encode($data);
- }
- function edit_master_agent($id)
- {
- $this->gox_acl->validate_update('', $this->xmall_agent_delivery);
- $user_info = $this->session->userdata('user_info');
- if( !isset($user_info->username))
- show_404();
- $data['subTitle'] = 'Update Agent';
- $data['records'] = $this->xmall_model->get_master_agent_data(array('id'=>$id));
- // $data['cert'] = $this->xfood_model->get_cert();
- $this->load->view('xmall/xmall_agent_edit', $data);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement