Exemplo n.º 1
0
 /**
  * search
  */
 public function search($arrConditions = array(), $mode = '')
 {
     $SQL = '     SELECT             ';
     if ($mode == 'count') {
         $SQL .= '     COUNT(*) AS cnt             ';
     } else {
         $SQL .= '         b.id,             ';
         $SQL .= '         b.name,             ';
         $SQL .= '         b.url,             ';
         $SQL .= '         b.order_by,             ';
         $SQL .= '         b.desc,             ';
         $SQL .= '         DATE_FORMAT(b.create_at,\'%d-%m-%Y %H:%i:%S\') AS create_at,             ';
         $SQL .= '         b.status,             ';
         $SQL .= '         u.username AS create_by,             ';
         $SQL .= '         b.delete_flg,             ';
         $SQL .= '         CASE WHEN b.img IS NOT NULL THEN CONCAT(\'' . base_url() . '\',\'' . UPLOAD_BRANDS_PATH . '\',b.img) ELSE CONCAT(\'' . base_url() . '\',\'' . NO_IMG_URL . ' \') END AS file_url              ';
     }
     $SQL .= '     FROM slides b             ';
     $SQL .= '     LEFT OUTER JOIN users u             ';
     $SQL .= '     ON             ';
     $SQL .= '         u.id = b.create_by             ';
     $SQL .= '    WHERE 1 = 1           ';
     if (isset($arrConditions['delete_flg']) && $arrConditions['delete_flg'] == 1) {
         $SQL .= '    AND b.delete_flg = 1           ';
     } else {
         $SQL .= '    AND b.delete_flg = 0           ';
     }
     if (isset($arrConditions['id'])) {
         $SQL .= '    AND b.id =  ' . $this->db->escape($arrConditions['id']);
     }
     if (isset($arrConditions['datefrom']) && isset($arrConditions['dateto'])) {
         $SQL .= '    AND substr(b.create_at,1,8) >=  ' . $this->db->escape(cnvDateToString($arrConditions['datefrom']));
         $SQL .= '    AND substr(b.create_at,1,8) <=  ' . $this->db->escape(cnvDateToString($arrConditions['dateto']));
     }
     if (isset($arrConditions['status'])) {
         $SQL .= '    AND b.status =  ' . $this->db->escape(isset($arrConditions['status']));
     }
     if (isset($arrConditions['create_by'])) {
         $SQL .= '    AND b.create_by =  ' . $this->db->escape($arrConditions['create_by']);
     }
     $SQL .= ' ORDER BY b.create_at DESC ';
     if (isset($arrConditions['start']) && isset($arrConditions['end'])) {
         $SQL .= ' LIMIT ' . $this->db->escape($arrConditions['start']) . ',' . $arrConditions['end'];
     }
     if ($mode == 'count') {
         $result = $this->db->query($SQL)->row_array();
         return $result['cnt'];
     }
     if ($mode == 'detail') {
         $arrOutput = $this->db->query($SQL)->row_array();
         return $arrOutput;
     }
     return $this->db->query($SQL)->result_array();
 }
Exemplo n.º 2
0
 /**
  * search
  */
 public function search($arrConditions = array(), $mode = '')
 {
     $SQL = '     SELECT             ';
     if ($mode == 'count') {
         $SQL .= '     COUNT(*) AS cnt             ';
     } else {
         $SQL .= '         b.id,             ';
         $SQL .= '         b.name,             ';
         $SQL .= '         DATE_FORMAT(b.create_at,\'%d-%m-%Y %H:%i:%S\') AS create_at,             ';
         $SQL .= '         b.status,             ';
         $SQL .= '         u.username AS create_by,             ';
         $SQL .= '           b.delete_flg             ';
     }
     $SQL .= '     FROM roles b             ';
     $SQL .= '     LEFT OUTER JOIN users u             ';
     $SQL .= '     ON             ';
     $SQL .= '         u.id = b.create_by             ';
     $SQL .= '    WHERE 1 = 1           ';
     if (isset($arrConditions['delete_flg']) && $arrConditions['delete_flg'] == 1) {
         $SQL .= '    AND b.delete_flg = 1           ';
     } else {
         $SQL .= '    AND b.delete_flg = 0           ';
     }
     if (isset($arrConditions['id'])) {
         $SQL .= '    AND b.id =  ' . $this->db->escape($arrConditions['id']);
     }
     if (isset($arrConditions['datefrom']) && isset($arrConditions['dateto'])) {
         $SQL .= '    AND substr(b.create_at,1,8) >=  ' . $this->db->escape(cnvDateToString($arrConditions['datefrom']));
         $SQL .= '    AND substr(b.create_at,1,8) <=  ' . $this->db->escape(cnvDateToString($arrConditions['dateto']));
     }
     if (isset($arrConditions['status'])) {
         $SQL .= '    AND b.status =  ' . $this->db->escape(isset($arrConditions['status']));
     }
     if (isset($arrConditions['create_by'])) {
         $SQL .= '    AND b.create_by =  ' . $this->db->escape($arrConditions['create_by']);
     }
     $SQL .= ' ORDER BY b.create_at DESC ';
     if (isset($arrConditions['start']) && isset($arrConditions['end'])) {
         $SQL .= ' LIMIT ' . $this->db->escape($arrConditions['start']) . ',' . $arrConditions['end'];
     }
     if ($mode == 'count') {
         $result = $this->db->query($SQL)->row_array();
         return $result['cnt'];
     }
     if ($mode == 'detail') {
         $arrOutput = array_merge($this->db->query($SQL)->row_array(), $this->getAccessUrl($arrConditions['id']));
         return $arrOutput;
     }
     return $this->db->query($SQL)->result_array();
 }
Exemplo n.º 3
0
 /**
  * search
  */
 public function search($arrConditions = array(), $mode = '')
 {
     $SQL = '    SELECT            ';
     if ($mode == 'count') {
         $SQL .= '    COUNT(*)  AS cnt           ';
     } else {
         $SQL .= '        m.id,           ';
         $SQL .= '        m.name,           ';
         $SQL .= '        DATE_FORMAT(m.create_at,\'%d-%m-%Y %H:%i:%S\') AS create_at ,           ';
         $SQL .= '        m.status,           ';
         $SQL .= '        u.username     AS create_by,           ';
         $SQL .= '        m.delete_flg,             ';
         $SQL .= '        m.order_by,             ';
         $SQL .= '        m1.name        AS parent,          ';
         $SQL .= '        m.icon        AS icon,          ';
         $SQL .= '        m.is_group        AS is_group,          ';
         $SQL .= '        m.url        AS url,          ';
         $SQL .= '        m.parent      ,          ';
         $SQL .= '        m1.name AS parent_name,           ';
         $SQL .= '        m.delete_flg    AS delete_flg          ';
     }
     $SQL .= '    FROM modules m           ';
     $SQL .= '    LEFT OUTER JOIN users u           ';
     $SQL .= '    ON           ';
     $SQL .= '        u.id = m.create_by           ';
     $SQL .= '    LEFT OUTER JOIN modules m1           ';
     $SQL .= '    ON           ';
     $SQL .= '        m1.id = m.parent           ';
     $SQL .= '    WHERE 1 = 1           ';
     if (isset($arrConditions['delete_flg']) && $arrConditions['delete_flg'] == 1) {
         $SQL .= '    AND m.delete_flg = 1           ';
     } else {
         $SQL .= '    AND m.delete_flg = 0           ';
     }
     if (isset($arrConditions['id'])) {
         $SQL .= '    AND m.id =  ' . $this->db->escape($arrConditions['id']);
     }
     if (isset($arrConditions['name'])) {
         $SQL .= '    AND m.encode LIKE ' . $this->db->escape('%' . $arrConditions['name'] . '%');
     }
     if (isset($arrConditions['datefrom']) && isset($arrConditions['dateto'])) {
         $SQL .= '    AND substr(m.create_at,1,8) >=  ' . $this->db->escape(cnvDateToString($arrConditions['datefrom']));
         $SQL .= '    AND substr(m.create_at,1,8) <=  ' . $this->db->escape(cnvDateToString($arrConditions['dateto']));
     }
     if (isset($arrConditions['status'])) {
         $SQL .= '    AND m.status =  ' . $this->db->escape($arrConditions['status']);
     }
     if (isset($arrConditions['parent'])) {
         $SQL .= '    AND m.parent =  ' . $this->db->escape($arrConditions['parent']);
     }
     if (isset($arrConditions['create_by'])) {
         $SQL .= '    AND m.create_by =  ' . $this->db->escape($arrConditions['create_by']);
     }
     $SQL .= ' ORDER BY m.order_by ';
     if (isset($arrConditions['start']) && isset($arrConditions['end'])) {
         $SQL .= ' LIMIT ' . $this->db->escape($arrConditions['start']) . ',' . $arrConditions['end'];
     }
     if ($mode == 'count') {
         $result = $this->db->query($SQL)->row_array();
         return $result['cnt'];
     }
     if ($mode == 'detail') {
         $arrOutput = $this->db->query($SQL)->row_array();
         return $arrOutput;
     }
     return $this->db->query($SQL)->result_array();
 }
Exemplo n.º 4
0
 /**
  * search
  */
 public function search($arrConditions = array(), $mode = '')
 {
     $SQL = '     SELECT             ';
     if ($mode == 'count') {
         $SQL .= '     COUNT(*) AS cnt             ';
     } else {
         $SQL .= '         b.id,             ';
         $SQL .= '         b.name,             ';
         $SQL .= '         b.price,             ';
         $SQL .= '         b.delete_flg,             ';
         $SQL .= '         b.order_by,             ';
         $SQL .= '         b.discount,             ';
         $SQL .= '         b.order_by,             ';
         $SQL .= '         b.desc,             ';
         $SQL .= '         b.category_id,             ';
         $SQL .= '         b.brand_id,             ';
         $SQL .= '         b.meta_title,             ';
         $SQL .= '         b.meta_keywords,             ';
         $SQL .= '         b.meta_desc,             ';
         $SQL .= '         \'\' AS other_file_url,             ';
         $SQL .= '         DATE_FORMAT(b.create_at,\'%d-%m-%Y %H:%i:%S\') AS create_at,             ';
         $SQL .= '        DATE_FORMAT(b.publish_at,\'%d-%m-%Y %H:%i:%S\') AS publish_at,             ';
         $SQL .= '         b.status,             ';
         $SQL .= '         u.username AS create_by,             ';
         $SQL .= '( ';
         $SQL .= '	SELECT CASE WHEN pi.filename IS NOT NULL THEN CONCAT(\'' . base_url() . '\',\'' . UPLOAD_PRODUCTS_PATH . '\',pi.filename) ELSE CONCAT(\'' . base_url() . '\',\'' . NO_IMG_URL . '\') END ';
         $SQL .= '	FROM product_images pi ';
         $SQL .= '	WHERE pi.product_id = b.id LIMIT 0,1 ';
         $SQL .= ') AS file_url ';
     }
     $SQL .= '     FROM products b             ';
     $SQL .= '     LEFT OUTER JOIN users u             ';
     $SQL .= '     ON             ';
     $SQL .= '         u.id = b.create_by             ';
     $SQL .= '    WHERE 1 = 1           ';
     if (isset($arrConditions['delete_flg']) && $arrConditions['delete_flg'] == 1) {
         $SQL .= '    AND b.delete_flg = 1           ';
     } else {
         $SQL .= '    AND b.delete_flg = 0           ';
     }
     if (isset($arrConditions['id'])) {
         $SQL .= '    AND b.id =  ' . $this->db->escape($arrConditions['id']);
     }
     if (isset($arrConditions['name'])) {
         $SQL .= '    AND b.encode LIKE ' . $this->db->escape('%' . $arrConditions['name'] . '%');
     }
     if (isset($arrConditions['datefrom']) && isset($arrConditions['dateto'])) {
         $SQL .= '    AND substr(b.create_at,1,8) >=  ' . $this->db->escape(cnvDateToString($arrConditions['datefrom']));
         $SQL .= '    AND substr(b.create_at,1,8) <=  ' . $this->db->escape(cnvDateToString($arrConditions['dateto']));
     }
     if (isset($arrConditions['publishfrom']) && isset($arrConditions['publishto'])) {
         $SQL .= '    AND substr(b.publish_at,1,8) >=  ' . $this->db->escape(cnvDateToString($arrConditions['publishfrom']));
         $SQL .= '    AND substr(b.publish_at,1,8) <=  ' . $this->db->escape(cnvDateToString($arrConditions['publishto']));
     }
     if (isset($arrConditions['status'])) {
         $SQL .= '    AND b.status =  ' . $this->db->escape($arrConditions['status']);
     }
     if (isset($arrConditions['category_id'])) {
         $SQL .= '    AND b.category_id =  ' . $this->db->escape($arrConditions['category_id']);
     }
     if (isset($arrConditions['brand_id'])) {
         $SQL .= '    AND b.brand_id =  ' . $this->db->escape($arrConditions['brand_id']);
     }
     if (isset($arrConditions['create_by'])) {
         $SQL .= '    AND b.create_by =  ' . $this->db->escape($arrConditions['create_by']);
     }
     $SQL .= ' ORDER BY b.order_by DESC ';
     if (isset($arrConditions['start']) && isset($arrConditions['end'])) {
         $SQL .= ' LIMIT ' . $this->db->escape($arrConditions['start']) . ',' . $arrConditions['end'];
     }
     if ($mode == 'count') {
         $result = $this->db->query($SQL)->row_array();
         return $result['cnt'];
     }
     if ($mode == 'detail') {
         $arrOutput = $this->db->query($SQL)->row_array();
         $this->db->select('filename,file_id');
         $arrOutput['images'] = $this->db->get_where('product_images', array('product_id' => $arrConditions['id']))->result_array();
         return $arrOutput;
     }
     return $this->db->query($SQL)->result_array();
 }
Exemplo n.º 5
0
 /**
  * search
  */
 public function search($arrConditions = array(), $mode = '')
 {
     $SQL = '     SELECT             ';
     if ($mode == 'count') {
         $SQL .= '     COUNT(*) AS cnt             ';
     } else {
         $SQL .= '         b.id,             ';
         $SQL .= '         b.name,             ';
         $SQL .= '         DATE_FORMAT(b.create_at,\'%d-%m-%Y %H:%i:%S\') AS create_at,             ';
         $SQL .= '         b.status,             ';
         $SQL .= '         b.delete_flg,             ';
         $SQL .= '         b.order_by,             ';
         $SQL .= '         b.meta_title,             ';
         $SQL .= '         b.meta_keywords,             ';
         $SQL .= '         b.meta_desc,             ';
         $SQL .= '         b.desc,             ';
         $SQL .= '         u.username AS create_by,             ';
         $SQL .= '         CASE WHEN b.img IS NOT NULL THEN CONCAT(\'' . base_url() . '\',\'' . UPLOAD_BRANDS_PATH . '\',b.img) ELSE CONCAT(\'' . base_url() . '\',\'' . NO_IMG_URL . ' \') END AS file_url              ';
     }
     $SQL .= '     FROM brands b             ';
     $SQL .= '     LEFT OUTER JOIN users u             ';
     $SQL .= '     ON             ';
     $SQL .= '         u.id = b.create_by             ';
     if (isset($arrConditions['category_id'])) {
         $SQL .= '     LEFT OUTER JOIN brand_category bc             ';
         $SQL .= '     ON             ';
         $SQL .= '         bc.brand_id = b.id             ';
     }
     $SQL .= '    WHERE 1 = 1           ';
     if (isset($arrConditions['delete_flg']) && $arrConditions['delete_flg'] == 1) {
         $SQL .= '    AND b.delete_flg = 1           ';
     } else {
         $SQL .= '    AND b.delete_flg = 0           ';
     }
     if (isset($arrConditions['id'])) {
         $SQL .= '    AND b.id =  ' . $this->db->escape($arrConditions['id']);
     }
     if (isset($arrConditions['name'])) {
         $SQL .= '    AND b.encode LIKE ' . $this->db->escape('%' . $arrConditions['name'] . '%');
     }
     if (isset($arrConditions['datefrom']) != '' && isset($arrConditions['dateto']) != '') {
         $SQL .= '    AND substr(b.create_at,1,8) >=  ' . $this->db->escape(cnvDateToString($arrConditions['datefrom']));
         $SQL .= '    AND substr(b.create_at,1,8) <=  ' . $this->db->escape(cnvDateToString($arrConditions['dateto']));
     }
     if (isset($arrConditions['status'])) {
         $SQL .= '    AND b.status =  ' . $this->db->escape($arrConditions['status']);
     }
     if (isset($arrConditions['category_id'])) {
         $SQL .= '    AND bc.category_id =  ' . $this->db->escape($arrConditions['category_id']);
     }
     if (isset($arrConditions['create_by'])) {
         $SQL .= '    AND b.create_by =  ' . $this->db->escape($arrConditions['create_by']);
     }
     $SQL .= ' ORDER BY b.order_by DESC ';
     if (isset($arrConditions['start']) && isset($arrConditions['end'])) {
         $SQL .= ' LIMIT ' . $this->db->escape($arrConditions['start']) . ',' . $arrConditions['end'];
     }
     if ($mode == 'count') {
         $result = $this->db->query($SQL)->row_array();
         return $result['cnt'];
     }
     if ($mode == 'detail') {
         $arrOutput = $this->db->query($SQL)->row_array();
         $categories = $this->db->get_where('brand_category', array('brand_id' => $arrConditions['id']))->result_array();
         foreach ($categories as $output) {
             $arrOutput['categories'][] = $output['category_id'];
         }
         return $arrOutput;
     }
     return $this->db->query($SQL)->result_array();
 }
Exemplo n.º 6
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;
     }
 }
Exemplo n.º 7
0
 /**
  * getSQL
  * @param type $arrConditions
  * @return string
  */
 public function search($arrConditions = array(), $mode = '')
 {
     $SQL = '     SELECT             ';
     if ($mode == 'count') {
         $SQL .= '     COUNT(*) AS cnt             ';
     } else {
         $SQL .= '         b.id,             ';
         $SQL .= '         b.order_id,             ';
         $SQL .= '         b.total_qty,             ';
         $SQL .= '         b.total_money,             ';
         $SQL .= '         CONCAT(b.tax_rt,"%")  AS tax_rt,             ';
         $SQL .= '         b.msg,             ';
         $SQL .= '         b.status,             ';
         $SQL .= '         b.delete_flg,             ';
         $SQL .= '         DATE_FORMAT(b.create_at,\'%d-%m-%Y %H:%i:%S\') AS create_at,             ';
         $SQL .= '         DATE_FORMAT(b.delivery_at,\'%d-%m-%Y %H:%i:%S\') AS delivery_at,             ';
         $SQL .= '         b.delete_flg,             ';
         if ($mode == 'detail') {
             $SQL .= '         do.product_id,             ';
             $SQL .= '         do.qty,             ';
             $SQL .= '         do.price,             ';
             $SQL .= '         do.sub_total,             ';
             $SQL .= '         p.name as product_name,             ';
         }
         $SQL .= '         u.name  as customer_name,             ';
         $SQL .= '         u.address  as customer_address,             ';
         $SQL .= '         u.phone  as customer_phone             ';
     }
     $SQL .= '     FROM orders b             ';
     if ($mode == 'detail') {
         $SQL .= '     LEFT OUTER JOIN detail_orders do             ';
         $SQL .= '     ON             ';
         $SQL .= '         do.order_id = b.order_id             ';
         $SQL .= '     LEFT OUTER JOIN products p             ';
         $SQL .= '     ON             ';
         $SQL .= '         p.id = do.product_id             ';
     }
     if ($mode != 'count') {
         $SQL .= '     LEFT OUTER JOIN users u             ';
         $SQL .= '     ON             ';
         $SQL .= '         u.id = b.create_by             ';
     }
     $SQL .= '    WHERE 1 = 1           ';
     if (isset($arrConditions['delete_flg']) && is_numeric($arrConditions['delete_flg'])) {
         $SQL .= '    AND b.delete_flg = ' . $arrConditions['delete_flg'];
     }
     if (isset($arrConditions['name'])) {
         $SQL .= '    AND u.encode LIKE ' . $this->db->escape('%' . $arrConditions['name'] . '%');
     }
     if (isset($arrConditions['id'])) {
         $SQL .= '    AND b.id = ' . $this->db->escape($arrConditions['id']);
     }
     if (isset($arrConditions['order_id'])) {
         $SQL .= '    AND b.order_id = ' . $this->db->escape($arrConditions['order_id']);
     }
     if (isset($arrConditions['status'])) {
         $SQL .= '    AND b.status = ' . $this->db->escape($arrConditions['status']);
     }
     if (isset($arrConditions['datefrom']) && isset($arrConditions['dateto'])) {
         $SQL .= '    AND substr(b.create_at,1,8) >=  ' . $this->db->escape(cnvDateToString($arrConditions['datefrom']));
         $SQL .= '    AND substr(b.create_at,1,8) <=  ' . $this->db->escape(cnvDateToString($arrConditions['dateto']));
     }
     if (isset($arrConditions['deliveryfrom']) && isset($arrConditions['deliveryto'])) {
         $SQL .= '    AND substr(b.delivery_at,1,8) >=  ' . $this->db->escape(cnvDateToString($arrConditions['deliveryfrom']));
         $SQL .= '    AND substr(b.delivery_at,1,8) <=  ' . $this->db->escape(cnvDateToString($arrConditions['deliveryto']));
     }
     $SQL .= ' ORDER BY b.create_at DESC';
     if (isset($arrConditions['start']) && isset($arrConditions['end'])) {
         $SQL .= ' LIMIT ' . $this->db->escape($arrConditions['start']) . ',' . $arrConditions['end'];
     }
     if ($mode == 'count') {
         $result = $this->db->query($SQL)->row_array();
         return $result['cnt'];
     }
     return $this->db->query($SQL)->result_array();
 }
Exemplo n.º 8
0
 /**
  * search
  */
 public function search($arrConditions = array(), $mode = '')
 {
     $SQL = '     SELECT             ';
     if ($mode == 'count') {
         $SQL .= '     COUNT(*) AS cnt             ';
     } else {
         $SQL .= '         b.id,             ';
         $SQL .= '         b.name,             ';
         $SQL .= '         b.phone,             ';
         $SQL .= '         b.address,             ';
         $SQL .= '         b.email,             ';
         $SQL .= '         DATE_FORMAT(b.create_at,\'%d-%m-%Y %H:%i:%S\') AS create_at,             ';
         $SQL .= '         b.status,             ';
         $SQL .= '         b.username,             ';
         $SQL .= '         b.role_id,             ';
         $SQL .= '         u.username AS create_by,             ';
         $SQL .= '         b.delete_flg,             ';
         $SQL .= '         CASE WHEN b.img IS NOT NULL THEN CONCAT(\'' . base_url() . '\',\'' . UPLOAD_USER_PATH . '\',b.img) ELSE CONCAT(\'' . base_url() . '\',\'' . NO_IMG_URL . ' \') END AS file_url,              ';
         $SQL .= '         DATE_FORMAT(b.lastlogin,\'%d-%m-%Y %H:%i:%S\') AS lastlogin             ';
     }
     $SQL .= '     FROM users b             ';
     $SQL .= '     LEFT OUTER JOIN users u             ';
     $SQL .= '     ON             ';
     $SQL .= '         u.id = b.create_by             ';
     $SQL .= '    WHERE 1 = 1 ';
     if (isset($arrConditions['current_role_id']) && $arrConditions['current_role_id'] != SUPPORT) {
         $SQL .= '   AND b.role_id != ' . SUPPORT;
     }
     if (isset($arrConditions['delete_flg']) && $arrConditions['delete_flg'] == 1) {
         $SQL .= '    AND b.delete_flg = 1           ';
     } else {
         $SQL .= '    AND b.delete_flg = 0           ';
     }
     if (isset($arrConditions['id'])) {
         $SQL .= '    AND b.id =  ' . $this->db->escape($arrConditions['id']);
     }
     if (isset($arrConditions['name'])) {
         $SQL .= '    AND b.encode LIKE ' . $this->db->escape('%' . $arrConditions['name'] . '%');
     }
     if (isset($arrConditions['username'])) {
         $SQL .= '    AND b.username LIKE ' . $this->db->escape('%' . $arrConditions['username'] . '%');
     }
     if (isset($arrConditions['datefrom']) && isset($arrConditions['dateto'])) {
         $SQL .= '    AND substr(b.create_at,1,8) >=  ' . $this->db->escape(cnvDateToString($arrConditions['datefrom']));
         $SQL .= '    AND substr(b.create_at,1,8) <=  ' . $this->db->escape(cnvDateToString($arrConditions['dateto']));
     }
     if (isset($arrConditions['status'])) {
         $SQL .= '    AND b.status =  ' . $this->db->escape($arrConditions['status']);
     }
     if (isset($arrConditions['create_by'])) {
         $SQL .= '    AND b.create_by =  ' . $this->db->escape($arrConditions['create_by']);
     }
     if (isset($arrConditions['role_id'])) {
         $SQL .= '    AND b.role_id =  ' . $this->db->escape($arrConditions['role_id']);
     }
     $SQL .= ' ORDER BY b.create_at DESC ';
     if (isset($arrConditions['start']) && isset($arrConditions['end'])) {
         $SQL .= ' LIMIT ' . $this->db->escape($arrConditions['start']) . ',' . $arrConditions['end'];
     }
     if ($mode == 'count') {
         $result = $this->db->query($SQL)->row_array();
         return $result['cnt'];
     }
     if ($mode == 'detail') {
         return $this->db->query($SQL)->row_array();
     }
     return $this->db->query($SQL)->result_array();
 }
Exemplo n.º 9
0
 /**
  * search
  */
 public function search($arrConditions = array(), $mode = '')
 {
     $SQL = '     SELECT             ';
     if ($mode == 'count') {
         $SQL .= '     COUNT(*) AS cnt             ';
     } else {
         $SQL .= '         b.id,             ';
         $SQL .= '         b.name,             ';
         $SQL .= '         DATE_FORMAT(b.create_at,\'%d-%m-%Y %H:%i:%S\') AS create_at,             ';
         $SQL .= '         b.status,             ';
         $SQL .= '         b.order_by,             ';
         $SQL .= '         b.delete_flg,             ';
         $SQL .= '         b.title_id,             ';
         $SQL .= '         b.content,             ';
         $SQL .= '         b.meta_title,             ';
         $SQL .= '         b.meta_keywords,             ';
         $SQL .= '         b.meta_desc,             ';
         $SQL .= '         u.username AS create_by,             ';
         $SQL .= '         DATE_FORMAT(b.publish_at,\'%d-%m-%Y %H:%i:%S\') AS publish_at,             ';
         $SQL .= '         b.publish_by,             ';
         $SQL .= '         CASE WHEN p.username IS NOT NULL THEN p.username ELSE \'-\' END AS publish_by,             ';
         $SQL .= '         t.name  as title_name,             ';
         $SQL .= '         CASE WHEN b.img IS NOT NULL THEN CONCAT(\'' . base_url() . '\',\'' . UPLOAD_NEWS_PATH . '\',b.img) ELSE CONCAT(\'' . base_url() . '\',\'' . NO_IMG_URL . ' \') END AS file_url              ';
     }
     $SQL .= '     FROM news b             ';
     if ($mode != 'count') {
         $SQL .= '     LEFT OUTER JOIN users u             ';
         $SQL .= '     ON             ';
         $SQL .= '         u.id = b.create_by             ';
         $SQL .= '     LEFT OUTER JOIN users p             ';
         $SQL .= '     ON             ';
         $SQL .= '         p.id = b.publish_by             ';
         $SQL .= '     LEFT OUTER JOIN titles t             ';
         $SQL .= '     ON             ';
         $SQL .= '         t.id = b.title_id             ';
     }
     $SQL .= '    WHERE 1 = 1           ';
     if (isset($arrConditions['delete_flg']) && is_numeric($arrConditions['delete_flg'])) {
         $SQL .= '    AND b.delete_flg = ' . $arrConditions['delete_flg'];
     }
     if (isset($arrConditions['name'])) {
         $SQL .= '    AND b.encode LIKE ' . $this->db->escape('%' . $arrConditions['name'] . '%');
     }
     if (isset($arrConditions['title_id'])) {
         $SQL .= '    AND b.title_id = ' . $this->db->escape($arrConditions['title_id']);
     }
     if (isset($arrConditions['status'])) {
         $SQL .= '    AND b.status = ' . $this->db->escape($arrConditions['status']);
     }
     if (isset($arrConditions['datefrom']) && isset($arrConditions['dateto'])) {
         $SQL .= '    AND substr(b.create_at,1,8) >=  ' . $this->db->escape(cnvDateToString($arrConditions['datefrom']));
         $SQL .= '    AND substr(b.create_at,1,8) <=  ' . $this->db->escape(cnvDateToString($arrConditions['dateto']));
     }
     if (isset($arrConditions['publishfrom']) && isset($arrConditions['publishto'])) {
         $SQL .= '    AND substr(b.publish_at,1,8) >=  ' . $this->db->escape(cnvDateToString($arrConditions['publishfrom']));
         $SQL .= '    AND substr(b.publish_at,1,8) <=  ' . $this->db->escape(cnvDateToString($arrConditions['publishto']));
     }
     $SQL .= ' ORDER BY b.order_by DESC';
     if (isset($arrConditions['start']) && isset($arrConditions['end'])) {
         $SQL .= ' LIMIT ' . $this->db->escape($arrConditions['start']) . ',' . $arrConditions['end'];
     }
     if ($mode == 'count') {
         $result = $this->db->query($SQL)->row_array();
         return $result['cnt'];
     }
     if ($mode == 'detail') {
         return $this->db->query($SQL)->row_array();
     }
     return $this->db->query($SQL)->result_array();
 }
Exemplo n.º 10
0
 /**
  * confirm
  * Xử lý add/edit record
  */
 private function confirm($id = '')
 {
     $model = $this->uri->segment(2) . '_model';
     if ($this->arrCommon['mode'] == MODE_EDIT && is_numeric($id)) {
         $arrWheres = array('id' => $id);
         $this->arrCommon['form_data'] = $this->{$model}->search($arrWheres, 'detail');
     } else {
         $this->arrCommon['form_data'] = array('id' => '', 'name' => '', 'status' => 1, 'price' => 0, 'discount' => 0, 'desc' => '', 'brand_id' => '', 'url' => '', 'is_group' => 0, 'publish_at' => cnvStringToDate(getCurrentDt(), 'dd-mm-yyyy'), 'address' => '', 'phone' => '', 'email' => '', 'username' => '', 'role_id' => '', 'content' => '', 'is_published' => 0, 'author' => '', 'content' => '', 'order_by' => -1, 'file_url' => base_url(NO_IMG_URL), 'file_id' => "", 'logo_id' => "", 'ico_id' => "", 'start_at' => cnvStringToDate(getCurrentDt(), 'dd-mm-yyyy'), 'finish_at' => cnvStringToDate(getCurrentDt(), 'dd-mm-yyyy'), 'other_file_url' => "", 'files_id' => "", 'meta_title' => "", 'meta_keywords' => "", 'meta_desc' => "");
     }
     $this->setSelectData();
     // Submit form
     if ($this->input->post() && $this->setValidate($this->arrCommon)) {
         $arrForm = $this->input->post();
         // On form
         $arrNotSubmit = array('datefrom', 'dateto', 'search', 'search_id', 'confpass', 'count', 'removeList', 'removeDb');
         $arrInput = array();
         foreach ($arrForm as $key => $vl) {
             if (strpos($key, 'rules') == 0 && !in_array($key, $arrNotSubmit)) {
                 switch ($key) {
                     case 'publish_at':
                         $arrInput['data'][$key] = cnvDateToString($vl);
                         break;
                     case 'modules':
                         $arrInput['data']['modules'] = $vl;
                         break;
                     default:
                         $arrInput['data'][$key] = $vl;
                         break;
                 }
             }
             if (!isset($arrForm['status'])) {
                 $arrInput['data']['status'] = 0;
             }
         }
         if ($this->{$model}->getInsertUpdate($arrInput)) {
             $this->setMessage(LTV0002, 'success');
         }
         redirect(current_url());
     }
 }