Example #1
0
 function form()
 {
     $message = '';
     $validFiles = array('jpg', 'jpge', 'jpeg', 'gif', 'png');
     try {
         if (!$_POST['varName']) {
             throw new Exception('Información incompleta');
         }
         if (!$_POST['idReg'] && !array_key_exists('uploadImage', $_FILES)) {
             throw new Exception('Debe incluir una imágen en un nuevo registro');
         } elseif ($_POST['idReg'] && !$_POST['varImage'] && !array_key_exists('uploadImage', $_FILES)) {
             throw new Exception('Debe incluir una imágen en un nuevo registro');
         }
         if (array_key_exists('uploadImage', $_FILES) && $_FILES['uploadImage']['name']) {
             $fileInfo = pathinfo($_FILES['uploadImage']['name']);
             if ($_FILES['uploadImage']['name'] && !in_array($fileInfo['extension'], $validFiles)) {
                 throw new Exception('Solo se permiten imágenes de formato JPG, GIF y PNG');
             }
             $varImage = friendlyUrl($fileInfo['filename']) . '.' . $fileInfo['extension'];
             $dest = MALETEKPL__PLUGIN_DIR . 'resources' . DS . 'color' . DS . $varImage;
             if (!move_uploaded_file($_FILES['uploadImage']['tmp_name'], $dest)) {
                 throw new Exception('Error al subir imagen');
             }
         } else {
             $varImage = $_POST['varImage'];
         }
         $data = array('varName' => $_POST['varName'], 'varImage' => $varImage, 'dateUpdate' => date('Y-m-d H:i:s'));
         if ($_POST['idReg']) {
             $this->DB->update($this->table_name, $data, 'id="' . $_POST['idReg'] . '"');
         } else {
             $this->DB->insert($this->table_name, $data);
         }
         $message = '<div class="updated">Se guardó la información correctamente</div>';
     } catch (Exception $ex) {
         $message = '<div class="error">' . $ex->getMessage() . '</div>';
     }
     exit($message);
 }
Example #2
0
 /**
  * getInsertUpdate
  *
  * @param type $arrData
  * @return boolean
  */
 public function getInsertUpdate($arrData = array())
 {
     $arrBase = array();
     if (isset($arrData['data']['base'])) {
         $arrBase = $arrData['data']['base'];
     }
     $this->db->trans_start();
     $sql = '';
     if ($arrData['data']['order_by'] > 0) {
         $sql .= "\tUPDATE modules \t";
         $sql .= "\tSET order_by = order_by + 1 \t";
         $sql .= "\twhere order_by >=  \t" . $arrData['data']['order_by'] . ' AND parent = ' . $arrData['data']['parent'];
         $this->db->query($sql);
     } else {
         $arrData['data']['order_by'] = getMaxValue('order_by', 'modules', array('parent' => $arrData['data']['parent'])) + 1;
     }
     $this->db->select('icon');
     $icon = $this->db->get_where('modules', array('id' => $arrData['data']['parent']))->row_array();
     if (!isset($arrData['data']['id']) || $arrData['data']['id'] == '') {
         setTime($arrData['data'], MODE_ADD);
         if (!isset($arrData['data']['is_group']) || $arrData['data']['is_group'] != 1) {
             $this->setIcon($arrData['data'], $icon['icon']);
         }
         unset($arrData['data']['base']);
         $this->db->insert('modules', $arrData['data']);
         $parent_id = $this->db->insert_id();
         // Insert base modules
         $orderBy = getMaxValue('order_by', 'modules', array('parent' => $parent_id));
         $cntBase = count($arrBase);
         if ($cntBase > 0) {
             for ($i = 0; $i < $cntBase; $i++) {
                 $name = '';
                 $url = '';
                 $status = 0;
                 switch ($arrBase[$i]) {
                     case MODE_ADD:
                         $name = 'Đăng ký ' . strtolower($arrData['data']['name']);
                         $url = $arrData['data']['url'] . '/' . MODE_ADD;
                         $status = 1;
                         break;
                     case MODE_EDIT:
                         $name = 'Chỉnh sửa ' . strtolower($arrData['data']['name']);
                         $url = $arrData['data']['url'] . '/' . MODE_EDIT;
                         break;
                     case MODE_DELETE:
                         $name = 'Xóa ' . strtolower($arrData['data']['name']);
                         $url = $arrData['data']['url'] . '/' . MODE_DELETE;
                         break;
                     case MODE_SEARCH:
                         $name = 'Tìm kiếm ' . strtolower($arrData['data']['name']);
                         $url = $arrData['data']['url'] . '/' . MODE_SEARCH;
                         break;
                     case MODE_ENABLE:
                         $name = 'Hiển thị ' . strtolower($arrData['data']['name']);
                         $url = $arrData['data']['url'] . '/' . MODE_ENABLE;
                         break;
                     case MODE_DISABLE:
                         $name = 'Ẩn ' . strtolower($arrData['data']['name']);
                         $url = $arrData['data']['url'] . '/' . MODE_DISABLE;
                         break;
                     case MODE_TRASH:
                         $name = $arrData['data']['name'] . ' đã xóa';
                         $url = $arrData['data']['url'] . '/' . MODE_TRASH;
                         $status = 1;
                         break;
                     case MODE_REFRESH:
                         $name = 'Phục hồi ' . strtolower($arrData['data']['name']);
                         $url = $arrData['data']['url'] . '/' . MODE_REFRESH;
                         break;
                     case MODE_DESTROY:
                         $name = 'Hủy ' . strtolower($arrData['data']['name']);
                         $url = $arrData['data']['url'] . '/' . MODE_DESTROY;
                         break;
                 }
                 $orderBy++;
                 $arrSub = array('name' => $name, 'encode' => friendlyUrl($name), 'url' => $url, 'status' => $status, 'delete_flg' => 0, 'parent' => $parent_id, 'is_group' => 0, 'icon' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . ICON, 'order_by' => $orderBy);
                 setTime($arrSub, MODE_ADD);
                 $this->db->insert('modules', $arrSub);
             }
         }
     } else {
         setTime($arrData, MODE_EDIT);
         if ($arrData['data']['is_group'] != 1) {
             $this->setIcon($arrData['data'], $icon['icon']);
         }
         $this->db->where('id', $arrData['data']['id']);
         $this->db->update('modules', $arrData['data']);
     }
     if ($this->db->trans_complete()) {
         return true;
     }
 }
Example #3
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 #4
0
                if (get_sub_field('menu_items')) {
                    ?>
									<?php 
                    $single_tab = 1;
                    ?>
									
									<?php 
                    while (has_sub_field('menu_items')) {
                        ?>
										
										<?php 
                        $str = get_sub_field('menu_item_title');
                        ?>
										
										<div id="menu-<?php 
                        echo friendlyUrl($str);
                        ?>
"></div>	
										
										<?php 
                        $single_tab++;
                        ?>
									
									<?php 
                    }
                    ?>
								<?php 
                }
                ?>
								
							<?php