Created
June 23, 2021 09:09
-
-
Save ALTELMA/eac512d394b31983e7322cf05e3b863b to your computer and use it in GitHub Desktop.
My Code :)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function edit($id = NULL){ | |
if(!empty($id)){ | |
// LOAD SESSION DATA | |
$session_data = $this->session->userdata('userLogData'); | |
// LOAD DATA FROM DATABASE | |
$assetObj = $this->assetModel->getAssetRow($id); | |
$categoryList = $this->assetModel->getDataList('category'); | |
$cond = array('cat_id' => $assetObj->cat_id); // SubCatCondition | |
$subCategoryList = $this->assetModel->getDataList('sub_category',$cond); | |
$statusList = $this->assetModel->getDataList('asset_status'); | |
$departmentList = $this->assetModel->getDataList('department'); | |
// CONFIG DATA SEND TO PAGE | |
$data['title'] = 'เพิ่มข้อมูลทรัพย์สินและครุภัณฑ์'; | |
$data['userID'] = $session_data['user_id']; | |
$data['name'] = $session_data['name']; | |
$data['categoryResult'] = $categoryList; | |
$data['subCategoryResult'] = $subCategoryList; | |
$data['statusResult'] = $statusList; | |
$data['departmentResult'] = $departmentList; | |
$data['assetData'] = $assetObj; | |
// DO ACTION EDIT WHEN SUBMIT | |
if($this->input->post('asset_edit') != NULL){ | |
if(!empty($_FILES['asset_img']['tmp_name'])){ | |
// CONFIG DESTINATION PATH | |
$thumbPath = str_replace(SELF,'',FCPATH).'assets/images/asset_image/thumb'; | |
$resizePath = str_replace(SELF,'',FCPATH).'assets/images/asset_image/resize'; | |
$thumbName = 'asset_cover_thumb'.date('YmdHis'); | |
$resizeName = 'asset_cover_resize'.date('YmdHis'); | |
// THUMB IMAGE 100x100 | |
if($_FILES['asset_img']['tmp_name']){ | |
@unlink($thumbPath.$assetObj->assetThumbPic); | |
$thumb = $this->myupload->imgUploadRatioY($_FILES['asset_img'], $thumbPath, $thumbName, 'gif', 100); | |
}else{ | |
$thumb = ''; | |
$this->myupload->error = ''; | |
} | |
// RESIZE IMAGE 400x400 | |
if($_FILES['asset_img']['tmp_name']){ | |
@unlink($resizePath.$assetObj->assetFullPic); | |
$resize = $this->myupload->imgUploadRatioY($_FILES['asset_img'], $resizePath, $resizeName, 'gif', 400); | |
}else{ | |
$resize = ''; | |
$this->myupload->error = ''; | |
} | |
}else{ | |
$thumb = $assetObj->assetThumbPic; | |
$resize = $assetObj->assetFullPic; | |
} | |
$this->assetModel->assetUpdate($id,$thumb,$resize); | |
redirect('asset/page/'.$this->uri->segment(4),'refresh'); | |
} | |
// LOAD PAGE | |
$this->load->view('templates/header', $data); | |
$this->load->view('templates/userPanel', $data); | |
$this->load->view('asset_edit', $data); | |
$this->load->view('templates/footer', $data); | |
}else{ | |
redirect('asset', 'refresh'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment