Example #1
0
 /**
  * getInsertUpdate
  *
  * @param type $arrData
  * @return boolean
  */
 public function getInsertUpdate($arrData = array())
 {
     $this->db->trans_start();
     $sql = '';
     if ($arrData['data']['order_by'] > 0) {
         $sql .= "\tUPDATE slides \t";
         $sql .= "\tSET order_by = order_by + 1 \t";
         $sql .= "\twhere order_by >=  \t" . $arrData['data']['order_by'];
         $this->db->query($sql);
     } else {
         $arrData['data']['order_by'] = getMaxValue('order_by', 'brands') + 1;
     }
     if (!isset($arrData['data']['id']) || $arrData['data']['id'] == '') {
         setTime($arrData['data'], MODE_ADD);
         $this->db->insert('slides', $arrData['data']);
     } else {
         setTime($arrData, MODE_EDIT);
         // Insert to slides tbl
         $this->db->where('id', $arrData['data']['id']);
         $this->db->update('slides', $arrData['data']);
     }
     if ($this->db->trans_complete()) {
         return true;
     }
 }
Example #2
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 #3
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 #4
0
<?php

$array = array(1231234, 10, 200, 20, 15, 5, 6, 3, 23, 123);
echo " max value " . getMaxValue($array);
function getMaxValue($array)
{
    $max = $array[0];
    for ($i = 1; $i < count($array); $i++) {
        if ($max < $array[$i]) {
            $max = $array[$i];
        }
    }
    return $max;
}
Example #5
0
 /**
  * getInsertUpdate
  *
  * @param type $arrData
  * @return boolean
  */
 public function getInsertUpdate($arrData = array())
 {
     $this->db->trans_start();
     $sql = '';
     if ($arrData['data']['order_by'] > 0) {
         $sql .= "\tUPDATE products \t";
         $sql .= "\tSET order_by = order_by + 1 \t";
         $sql .= "\twhere order_by >=  \t" . $arrData['data']['order_by'];
         $this->db->query($sql);
     } else {
         $arrData['data']['order_by'] = getMaxValue('order_by', 'products') + 1;
     }
     // Price
     if (!isset($arrData['data']['price']) || $arrData['data']['price'] != '') {
         $arrData['data']['price'] = str_replace('.', '', $arrData['data']['price']);
     }
     // Add to tbl products
     $productId = '';
     if (isset($arrData['data']['id']) && is_numeric($arrData['data']['id'])) {
         setTime($arrData['data'], MODE_EDIT);
         $arrData['data']['publish_at'] = $arrData['data']['publish_at'] . '000000';
         $this->db->where('id', $arrData['data']['id']);
         $this->db->update('products', $arrData['data']);
         $productId = $arrData['data']['id'];
     } else {
         setTime($arrData['data'], MODE_ADD);
         $arrData['data']['publish_at'] = $arrData['data']['publish_at'] . '000000';
         $this->db->insert('products', $arrData['data']);
         $productId = $this->db->insert_id();
     }
     // Insert image
     $cntUpload = count($_FILES['upload']['name']);
     $removeList = $this->input->post('removeList');
     $removeDB = $this->input->post('removeDb');
     $arrRemoveList = array();
     $arrRemoveDb = array();
     if ($removeList != '') {
         $arrRemoveList = explode(',', $removeList);
     }
     if ($removeDB != '') {
         $arrRemoveDb = explode(',', $removeDB);
     }
     if ($cntUpload > 0) {
         for ($i = 0; $i < $cntUpload; $i++) {
             if (!checkExistsInArray($arrRemoveList, $i)) {
                 if ($_FILES['upload']['name'][$i] != '') {
                     $ext = pathinfo($_FILES['upload']['name'][$i], PATHINFO_EXTENSION);
                     $filename = time() . '_' . random_string() . '.' . $ext;
                     $_FILES['file']['name'] = $_FILES['upload']['name'][$i];
                     $_FILES['file']['type'] = $_FILES['upload']['type'][$i];
                     $_FILES['file']['tmp_name'] = $_FILES['upload']['tmp_name'][$i];
                     $_FILES['file']['error'] = $_FILES['upload']['error'][$i];
                     $_FILES['file']['size'] = $_FILES['upload']['size'][$i];
                     $arrConfig = array('upload_path' => './' . UPLOAD_PRODUCTS_PATH, 'allowed_types' => ALLOWED_IMG_TYPES, 'max_size' => MAX_UPLOAD_FILE_SIZE, 'max_width' => 1000, 'max_height' => 1000, 'filename' => $filename, 'overwrite' => true);
                     $upload = uploadFile($arrConfig, false);
                     if ($upload['uploadCode'] == 1) {
                         // Add to tbl files
                         $arrImgData = array('product_id' => $productId, 'filename' => $filename, 'size' => $_FILES['upload']['size'][$i]);
                         $this->db->insert('product_images', $arrImgData);
                     }
                 }
             }
         }
     }
     // Remove image when edit
     if (count($arrRemoveDb) > 0) {
         for ($i = 0; $i < count($arrRemoveDb); $i++) {
             $this->db->where('file_id', $arrRemoveDb[$i]);
             $imageInfo = $this->db->get_where('product_images')->row_array();
             $this->db->where('file_id', $arrRemoveDb[$i]);
             $this->db->delete('product_images');
             // Remove from dir
             if (file_exists('./' . UPLOAD_PRODUCTS_PATH . $imageInfo['filename'])) {
                 unlink('./' . UPLOAD_PRODUCTS_PATH . $imageInfo['filename']);
             }
         }
     }
     if ($this->db->trans_complete()) {
         return true;
     }
 }
Example #6
0
 /**
  * getInsertUpdate
  *
  * @param type $arrData
  * @return boolean
  */
 public function getInsertUpdate($arrData = array())
 {
     $this->db->trans_start();
     $sql = '';
     if ($arrData['data']['order_by'] > 0) {
         $sql .= "\tUPDATE titles \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', 'titles', array('parent' => $arrData['data']['parent'])) + 1;
     }
     $this->db->select('icon');
     $icon = $this->db->get_where('titles', array('id' => $arrData['data']['parent']))->row_array();
     if (!isset($arrData['data']['id']) || $arrData['data']['id'] == '') {
         setTime($arrData['data'], MODE_ADD);
         if ($arrData['data']['parent'] != 0) {
             $this->setIcon($arrData['data'], $icon['icon']);
         }
         $this->db->insert('titles', $arrData['data']);
     } else {
         setTime($arrData, MODE_EDIT);
         if ($arrData['data']['parent'] != 0) {
             $this->setIcon($arrData['data'], $icon['icon']);
         }
         $this->db->where('id', $arrData['data']['id']);
         $this->db->update('titles', $arrData['data']);
     }
     if ($this->db->trans_complete()) {
         return true;
     }
 }
Example #7
0
 /**
  * getInsertUpdate
  *
  * @param type $arrData
  * @return boolean
  */
 public function getInsertUpdate($arrData = array())
 {
     $this->db->trans_start();
     $sql = '';
     if ($arrData['data']['order_by'] > 0) {
         $sql .= "\tUPDATE brands \t";
         $sql .= "\tSET order_by = order_by + 1 \t";
         $sql .= "\twhere order_by >=  \t" . $arrData['data']['order_by'];
         $this->db->query($sql);
     } else {
         $arrData['data']['order_by'] = getMaxValue('order_by', 'brands') + 1;
     }
     if (!isset($arrData['data']['id']) || $arrData['data']['id'] == '') {
         setTime($arrData['data'], MODE_ADD);
         $arrTmp = $arrData['data']['categories'];
         unset($arrData['data']['categories']);
         if ($this->db->insert('brands', $arrData['data'])) {
             $cnt = count($arrTmp);
             if ($cnt > 0) {
                 $insert_id = $this->db->insert_id();
                 $arrCategories = array();
                 for ($i = 0; $i < $cnt; $i++) {
                     $arr = array('brand_id' => $insert_id, 'category_id' => $arrTmp[$i]);
                     array_push($arrCategories, $arr);
                 }
                 $this->db->insert_batch('brand_category', $arrCategories);
             }
         }
     } else {
         setTime($arrData, MODE_EDIT);
         $arrTmp = $arrData['data']['categories'];
         unset($arrData['data']['categories']);
         $this->db->where('id', $arrData['data']['id']);
         if ($this->db->update('brands', $arrData['data'])) {
             $cnt = count($arrTmp);
             if ($cnt > 0) {
                 $this->db->delete('brand_category', array('brand_id' => $arrData['data']['id']));
                 $arrCategories = array();
                 for ($i = 0; $i < $cnt; $i++) {
                     $arr = array('brand_id' => $arrData['data']['id'], 'category_id' => $arrTmp[$i]);
                     array_push($arrCategories, $arr);
                 }
                 $this->db->insert_batch('brand_category', $arrCategories);
             }
         }
     }
     if ($this->db->trans_complete()) {
         return true;
     }
 }
Example #8
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 #9
0
 /**
  * getInsertUpdate
  *
  * @param type $arrData
  * @return boolean
  */
 public function getInsertUpdate($arrData = array())
 {
     $this->db->trans_start();
     if ($arrData['data']['order_by'] > 0) {
         $sql .= "\tUPDATE news \t";
         $sql .= "\tSET order_by = order_by + 1 \t";
         $sql .= "\twhere order_by >=  \t" . $arrData['data']['order_by'];
         $this->db->query($sql);
     } else {
         $arrData['data']['order_by'] = getMaxValue('order_by', 'news') + 1;
     }
     if (!isset($arrData['data']['id']) || $arrData['data']['id'] == '') {
         setTime($arrData['data'], MODE_ADD);
         if (!isset($arrData['data']['publish_at']) || $arrData['data']['publish_at'] == '') {
             $arrData['data']['publish_at'] = $arrData['data']['create_at'];
             if (isset($arrData['data']['status']) && $arrData['data']['status'] == 1) {
                 $arrData['data']['publish_by'] = getCurrentUserId();
             }
         }
         $this->db->insert('news', $arrData['data']);
     } else {
         setTime($arrData, MODE_EDIT);
         if (isset($arrData['data']['status']) && $arrData['data']['status'] == 1) {
             $arrData['data']['publish_by'] = getCurrentUserId();
         }
         $this->db->where('id', $arrData['data']['id']);
         $this->db->update('news', $arrData['data']);
     }
     if ($this->db->trans_complete()) {
         return true;
     }
 }