Example #1
0
 /**
  * getList
  * Enter description here ...
  */
 public function getList()
 {
     $table = safe_data('table');
     $value = safe_data('value');
     $arrConditions = array();
     switch ($table) {
         case 'categories':
         case 'titles':
             $arrConditions['delete_flg'] = 0;
             $arrConditions['status'] = 1;
             $arrConditions['parent'] = $value;
             $this->db->select('id,name,order_by,parent');
             $this->db->where($arrConditions);
             $arrOutput = $this->db->get($table)->result_array();
             $maxOrderBy = getMaxValue('order_by', $table, $arrConditions) + 1;
             $html = '<option value="' . $maxOrderBy . '">--- Tự sắp xếp ---</option>';
             foreach ($arrOutput as $output) {
                 $html .= '<option value="' . $output['order_by'] . '">' . $output['name'] . '</option>';
             }
             echo $html;
             break;
         case 'modules':
             $arrConditions['delete_flg'] = 0;
             $arrConditions['parent'] = $value;
             $this->db->select('id,name,order_by,parent');
             $this->db->where($arrConditions);
             $arrOutput = $this->db->get($table)->result_array();
             $maxOrderBy = getMaxValue('order_by', $table, $arrConditions) + 1;
             $html = '<option value="' . $maxOrderBy . '">--- Tự sắp xếp ---</option>';
             foreach ($arrOutput as $output) {
                 $html .= '<option value="' . $output['order_by'] . '">' . $output['name'] . '</option>';
             }
             echo $html;
             break;
     }
 }
Example #2
0
 protected function doAction($action = '', $table)
 {
     switch ($action) {
         case 'search':
             if ($this->input->post()) {
                 $keyword = safe_data($this->input->post('keyword'));
                 $arrInput = array('url' => base_url(URL_ADMIN_BRAND . '/' . MODE_SEARCH), 'table' => $this->table, 'segment' => 3, 'conditions' => array('wheres' => array('name' => $keyword, 'encode' => friendlyUrl($keyword), 'create_at' => cnvDateToString($keyword)), 'limit' => $this->rowPerPage, 'order_by' => array('create_at' => 'DESC')));
                 $this->my_paging->createPagination($this->arrCommon, $arrInput, 'search');
                 $this->loadPage('admin/list/' . $this->table . '_list_view');
             } else {
                 redirect(URL_ADMIN_BRAND);
             }
             break;
         case 'add':
         case 'edit':
             // Get detail data
             $this->arrCommon['category'] = array();
             if (is_numeric($id) && $action == 'edit') {
                 $arrConditions = array('wheres' => array('brand_id' => $id));
                 $this->arrCommon[$this->table] = $this->common_model->getOne($this->table, array('id' => $id));
                 $this->arrCommon['category'] = $this->common_model->getAll('brand_category', $arrConditions);
             } else {
                 $this->arrCommon[$this->table] = array('name' => '', 'cate_id' => 0, 'status' => 1, 'desc' => '', 'id' => '');
             }
             // Submit form
             if ($this->input->post() && $this->setValidate($this->arrCommon)) {
                 // Array data for insert
                 $arrInput[0] = array('name' => safe_data($this->input->post('name')), 'encode' => friendlyUrl($this->input->post('name')), 'status' => $this->input->post('status') != '' ? safe_data($this->input->post('status')) : '0', 'desc' => $this->input->post('desc'), 'create_by' => $this->arrCommon['user_id'], 'update_by' => $this->arrCommon['user_id']);
                 $arrWheres = array('id' => $this->input->post('id'));
                 $arrCategory = $this->input->post('category');
                 if ($action == 'add' && $this->common_model->insert($this->table, $arrInput) || $action == 'edit' && $this->common_model->update($this->table, $arrWheres, $arrInput)) {
                     // If has file upload input
                     if (isset($_FILES['file']) && $_FILES['file']['name'] != '') {
                         // Upload file
                         $arrConfig = array('upload_path' => 'upload/' . $this->table . '/', 'resize_path' => 'upload/' . $this->table . '/thumb/', 'allowed_types' => 'jpg|png|jpeg|gif', 'max_size' => '150', 'resize_width' => '90', 'resize_height' => '90', 'max_width' => '1000', 'max_height' => '1000', 'filename' => getCurrentDt() . '_' . $_FILES['file']['name'], 'overwrite' => true);
                         $arrResult = $this->my_uploader->uploadFile($arrConfig, true);
                         if ($arrResult['uploadCode'] == 1) {
                             // Insert to DB
                             $arrFileData[0] = array('path' => isset($arrConfig['upload_path']) ? $arrConfig['upload_path'] : '', 'filename' => isset($arrConfig['filename']) ? $arrConfig['filename'] : '', 'size' => isset($_FILES['file']['size']) ? $_FILES['file']['size'] : '', 'table_id' => 'brands', 'owner_id' => getMaxValue('id', $this->table), 'path_thumb' => isset($arrConfig['resize_path']) ? $arrConfig['resize_path'] : '', 'file_thumb' => isset($arrResult['thumbnail']) ? $arrResult['thumbnail'] : '');
                             if ($action == 'edit') {
                                 $arrFileData[0]['owner_id'] = $id;
                             }
                             $arrFileWheres = array('owner_id' => $id, 'table_id' => $this->table);
                             if ($action == 'add' && $this->common_model->insert('files', $arrFileData) || $action == 'edit' && $this->common_model->update('files', $arrFileWheres, $arrFileData)) {
                                 // Show messages
                                 $this->setMessage(LTV0002, 'success');
                                 redirect(URL_ADMIN_BRAND);
                             }
                         } else {
                             $this->setMessage($arrResult['errorUpload'], 'error');
                         }
                     }
                     // Show messages
                     $this->setMessage(LTV0002, 'success');
                     redirect(URL_ADMIN_BRAND);
                 }
             }
             $this->loadPage('admin/form/' . $this->table . '_form_view');
             break;
         case 'delete':
             $arrWheres = array();
             $arrFileWheres = array();
             $arrCheck = $this->input->post('checkAll');
             if (is_numeric($id)) {
                 $arrCheck[] = $id;
             }
             for ($i = 0; $i < count($arrCheck); $i++) {
                 $arrWheres[$i] = array('id' => $arrCheck[$i]);
                 $arrFileWheres[$i] = array('owner_id' => $arrCheck[$i], 'table_id' => $this->table);
             }
             // Delete files
             if ($this->common_model->delete($this->table, $arrWheres)) {
                 $this->setMessage(LTV0007, 'success');
                 redirect(URL_ADMIN_BRAND);
             }
         default:
             $arrInput = array('url' => base_url('admin/' . $this->table . '/'), 'table' => $this->table, 'segment' => 3, 'conditions' => array('limit' => $this->rowPerPage, 'wheres' => array(), 'order_by' => array('create_at' => 'DESC')));
             $this->my_paging->createPagination($this->arrCommon, $arrInput);
             $this->loadPage('admin/list/' . $this->table . '_list_view');
             break;
     }
 }
Example #3
0
 /**
  * logIn
  * Đăng nhập
  */
 private function logIn()
 {
     $this->arrCommon['mode'] = MODE_LOGIN;
     $this->session->unset_userdata('realname');
     $this->session->unset_userdata('user_id');
     delete_cookie('realname');
     delete_cookie('user_id');
     $this->arrCommon['errLogin'] = '';
     if ($this->input->post() && $this->setValidate($this->arrCommon)) {
         $arrInput = array('username' => safe_data('username'), 'password' => md5(safe_data('password')), 'remember' => $this->input->post('remember'));
         $this->my_login->login($this->arrCommon, $arrInput, URL_ADMIN_PRODUCT, LOGIN_MODE_01);
     }
 }