/** * login * * Phương thức đăng nhập * * @param type $arrOutput * @param type $arrInput * @param type $strRedirect * @param type $strMode */ function login(&$arrOutput = array(), $arrInput = array(), $strRedirect = '', $strMode = '') { // get the CI object $CI =& get_instance(); $CI->load->helper('cookie'); $CI->load->library('session'); $CI->load->model('common_model'); if ($strMode == 'account') { $CI->db->where('username', $arrInput['username']); $CI->db->where('password', $arrInput['password']); $CI->db->where('status', 1); $arrUserInfo = $CI->db->get('users')->row_array(); if ($arrUserInfo != null && count($arrUserInfo) > 0) { if ($this->checkAllowLogin($arrUserInfo['role_id'])) { if ($arrInput['remember'] == 1) { set_cookie('user_id', $arrUserInfo['id'], 86500); } else { $CI->session->set_userdata('user_id', $arrUserInfo['id']); } // Update last login $CI->db->where('id', $arrUserInfo['id']); $CI->db->update('users', array('lastlogin' => getCurrentDt())); // Redirect to admin panel redirect($strRedirect); } else { $arrOutput['errLogin'] = LTV0055; } } else { $arrOutput['errLogin'] = LTV0001; } } }
function setTime(&$arrOutput = array(), $mode = '') { if (isset($arrOutput['name']) && $arrOutput['name'] != '') { $arrOutput['encode'] = replaceUnicode($arrOutput['name']); } if (isset($arrOutput['password']) && $arrOutput['password'] != '') { $arrOutput['password'] = md5($arrOutput['password']); } switch ($mode) { case MODE_ADD: $arrOutput['create_at'] = getCurrentDt(); $arrOutput['create_by'] = getCurrentUserId(); break; case MODE_EDIT: $arrOutput['update_at'] = getCurrentDt(); $arrOutput['update_by'] = getCurrentUserId(); break; case MODE_DELETE: $arrOutput['delete_at'] = getCurrentDt(); $arrOutput['delete_by'] = getCurrentUserId(); break; } }
/** * uploadFiles * * @param type $action * @param type $id * @return boolean */ public function uploadFiles($path = '', $resize_width = '90') { if (isset($_FILES['file']) && $_FILES['file']['name'] != '') { $ico_id = $this->input->post('myPreview'); $filename = getCurrentDt() . '_' . random_string() . '_' . removeHttpUrl(base_url()) . '.' . pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION); $arrFile = explode('.', $filename); $size = $_FILES['file']['size']; $arrFileData = array('data' => array('path' => $path, 'filename' => $filename, 'size' => $size)); // Upload file $arrConfig = array('upload_path' => $path, 'resize_path' => $path . 'thumb', 'allowed_types' => ALLOWED_IMG_TYPES, 'max_size' => '150', 'resize_width' => $resize_width, 'max_width' => '1000', 'max_height' => '1000', 'filename' => $filename, 'overwrite' => true); if ($ico_id == 'ico_preview') { $arrFileData['data']['filename'] = $arrFile[0] . '.ico'; $arrConfig['ico_file'] = $arrFile[0] . '.ico'; } $arrResult = $this->my_uploader->uploadFile($arrConfig, true); if ($arrResult['uploadCode'] == 1) { if ($this->files_model->getInsertUpdate($arrFileData)) { return true; } } else { return $arrResult; } return false; } }
/** * 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()); } }