Is it on controller or not? fyi, this one is on ProjectController, at function create.
indent: public function actionCreate()
{
if (isset(Yii::app()->session['company_id']) && !empty(Yii::app()->session['company_id']))
$activeCompanyId = Yii::app()->session['company_id'];
else
$activeCompanyId = Yii::app()->user->company_id;
$model = new Project;
$modelClient=Client::model()->findAll();
$modelProjectPriority=ProjectPriority::model()->findAll();
$modelAircraftRegistration=AircraftRegistration::model()->findAll();
$modelAircraftSerielNumber=AircraftSerielNumber::model()->findAll();
$modelAircraftType=AircraftType::model()->findAll();
$modelProjectApproval=ProjectApproval::model()->findAll();
$model->project_date=date('j M Y');
if(isset($_POST['Project']))
{
$model->attributes=$_POST['Project'];
$model->id = Project::model()->getMax()+1;
$model->user_id=Yii::app()->user->account_id;
$tempDate = $model->project_date;
$model->project_date = date('Y-m-d', strtotime($tempDate));
$model->client_id = $_POST['client-id-select'];
$model->project_priority_id = $_POST['project-priority-id-select'];
$model->aircraft_type_id = $_POST['aircraft-type-id-select'];
$model->aircraft_reg_id = $_POST['aircraft-reg-id-select'];
$model->aircraft_sn_id = $_POST['aircraft-sn-id-select'];
$model->project_status_id = 1;
//Moc No. (format:company-dept/MOC/year/running #)
$runningNo=Project::model()->count(array(
'condition'=>'YEAR(created_time)=YEAR(CURRENT_DATE)',
));
if (strlen(Yii::app()->session['company_shortname']) <= 2)
$ref_no = Yii::app()->session['company_shortname'];
else
$ref_no = substr(Yii::app()->session['company_shortname'],0,-2);
$ref_no .= '/PRO';
$ref_no .= '/'.date('y');
$ref_no .= '/'.str_pad($runningNo+1, 4, '0', STR_PAD_LEFT);
$model->project_no = $ref_no;
date_default_timezone_set("Asia/Kuala_Lumpur");
$time = date_default_timezone_get() ;
$time = date('Y-m-d H:i:s');
$model->created_time = $time;
$model->updated_time = $time;
$model->updated_user_id = Yii::app()->user->user_id;
if($model->save()) {
if (isset($_FILES['DocumentUpload'])) {
$files = $_FILES['DocumentUpload'];
$documentUploadPath = Yii::getPathOfAlias('webroot.uploaded.project').'/';
for ($i=1;$i<=3;$i++){
$mod_file = 'mod_file'.$i;
// file upload - mod project
if(!is_null($files['name'][$mod_file]) && !empty($files['name'][$mod_file])) {
list($fn, $ext) = explode(".", basename($files['name'][$mod_file]));
$filename = substr(str_replace(" ", "_", $fn),0,5).'_'.date('Ymd_His').".".$ext;
$file = $documentUploadPath.$filename;
if (file_exists($file)) {
unlink($file);
}
move_uploaded_file($files['tmp_name'][$mod_file], $file);
$modelProjectMod = new ProjectDocumentUpload;
$modelProjectMod->id = ProjectDocumentUpload::model()->getMax()+1;
$modelProjectMod->project_id = $model->id;
$modelProjectMod->media_code_id = 1; // Project Mod
$modelProjectMod->reference_no = 'Project Mod';
$modelProjectMod->filename = $filename;
$modelProjectMod->date = $time;
if ($modelProjectMod->save()) {
// add into audit trails
$modelAuditTrail=new AuditTrail;
$modelAuditTrail->id = AuditTrail::model()->getMax()+1;
$modelAuditTrail->controller = Yii::app()->controller->id;
$modelAuditTrail->action = Yii::app()->controller->action->id;
$modelAuditTrail->account_id = Yii::app()->user->account_id;
$modelAuditTrail->company_id = $activeCompanyId;
$modelAuditTrail->department_id = Yii::app()->user->department_id;
$modelAuditTrail->user_role_id = Yii::app()->user->user_role_id;
$modelAuditTrail->level = 1;
$modelAuditTrail->description = 'Add Mod in Project No. '.$model->project_no;
$modelAuditTrail->created_time = $time;
$modelAuditTrail->updated_user_id = Yii::app()->user->user_id;
$modelAuditTrail->updated_time = $time;
$modelAuditTrail->save();
}
}
}
}
}//tutup if $model->save
// //add into timeline
$modelProjectStatusLog=new ProjectStatusLog;
$modelProjectStatusLog->id = ProjectStatusLog::model()->getMax()+1;
$modelProjectStatusLog->project_id = $model->id;
$modelProjectStatusLog->project_status_id = $model->project_status_id;
$modelProjectStatusLog->updated_user_id = Yii::app()->user->user_id;
$modelProjectStatusLog->updated_time = $time;
$modelProjectStatusLog->save();
$this->redirect(array('view','id'=>$model->id));
// }
}
$this->render('create',array(
'section'=>1,
'model'=>$model,
'modelProjectPriority'=>$modelProjectPriority,
'modelClient'=>$modelClient,
'modelAircraftRegistration'=>$modelAircraftRegistration,
'modelAircraftType'=>$modelAircraftType,
'modelAircraftSerielNumber'=>$modelAircraftSerielNumber,
'modelProjectApproval'=>$modelProjectApproval,
));
}
this is my function update
indent: public function actionUpdate($id,$section)
{
if (isset(Yii::app()->session['company_id']) && !empty(Yii::app()->session['company_id']))
$activeCompanyId = Yii::app()->session['company_id'];
else
$activeCompanyId = Yii::app()->user->company_id;
$model=$this->loadModel($id);
$modelClient=Client::model()->findAll();
$modelProjectPriority=ProjectPriority::model()->findAll();
$modelAircraftRegistration=AircraftRegistration::model()->findAll();
$modelAircraftType=AircraftType::model()->findAll();
$modelAircraftSerielNumber=AircraftSerielNumber::model()->findAll();
$modelProjectType=ProjectType::model()->findAll();
$modelDepartment=Department::model()->findAll();
$modelProjectApproval=ProjectApproval::model()->findAll(array('condition'=>'id!=1',
));
$modelProjectMod=ProjectDocumentUpload::model()->findAll(array(
'condition'=>'media_code_id=:media_code_id AND project_id=:project_id',
'params'=>array(':media_code_id'=>1,':project_id'=>$id,),
'order'=>'date DESC',
));
$modelProjectMcr=ProjectDocumentUpload::model()->findAll(array(
'condition'=>'media_code_id=:media_code_id AND project_id=:project_id',
'params'=>array(':media_code_id'=>2,':project_id'=>$id,),
'order'=>'date DESC',
));
$modelProjectCP=ProjectDocumentUpload::model()->findAll(array(
'condition'=>'media_code_id=:media_code_id AND project_id=:project_id',
'params'=>array(':media_code_id'=>3,':project_id'=>$id,),
'order'=>'date DESC',
));
// $modelProjectMD=ProjectDocumentUpload::model()->findAll(array(
// 'condition'=>'media_code_id=:media_code_id AND project_id=:project_id',
// 'params'=>array(':media_code_id'=>4,':project_id'=>$id,),
// 'order'=>'date DESC',
// ));
// $modelProjectEDStructure=ProjectDocumentUpload::model()->findAll(array(
// 'condition'=>'media_code_id=:media_code_id AND project_id=:project_id',
// 'params'=>array(':media_code_id'=>5,':project_id'=>$id,),
// 'order'=>'date DESC',
// ));
// $modelProjectEDAvionics=ProjectDocumentUpload::model()->findAll(array(
// 'condition'=>'media_code_id=:media_code_id AND project_id=:project_id',
// 'params'=>array(':media_code_id'=>6,':project_id'=>$id,),
// 'order'=>'date DESC',
// ));
// $modelProjectICA=ProjectDocumentUpload::model()->findAll(array(
// 'condition'=>'media_code_id=:media_code_id AND project_id=:project_id',
// 'params'=>array(':media_code_id'=>7,':project_id'=>$id,),
// 'order'=>'date DESC',
// ));
// $modelProjectFMS=ProjectDocumentUpload::model()->findAll(array(
// 'condition'=>'media_code_id=:media_code_id AND project_id=:project_id',
// 'params'=>array(':media_code_id'=>8,':project_id'=>$id,),
// 'order'=>'date DESC',
// ));
// $modelProjectGTP=ProjectDocumentUpload::model()->findAll(array(
// 'condition'=>'media_code_id=:media_code_id AND project_id=:project_id',
// 'params'=>array(':media_code_id'=>7,':project_id'=>$id,),
// 'order'=>'date DESC',
// ));
// $modelProjectJRAvionics=ProjectDocumentUpload::model()->findAll(array(
// 'condition'=>'media_code_id=:media_code_id AND project_id=:project_id',
// 'params'=>array(':media_code_id'=>8,':project_id'=>$id,),
// 'order'=>'date DESC',
// ));
// $modelProjectJRStructure=ProjectDocumentUpload::model()->findAll(array(
// 'condition'=>'media_code_id=:media_code_id AND project_id=:project_id',
// 'params'=>array(':media_code_id'=>9,':project_id'=>$id,),
// 'order'=>'date DESC',
// ));
// $modelProjectFTP=ProjectDocumentUpload::model()->findAll(array(
// 'condition'=>'media_code_id=:media_code_id AND project_id=:project_id',
// 'params'=>array(':media_code_id'=>10,':project_id'=>$id,),
// 'order'=>'date DESC',
// ));
// $modelProjectFTR=ProjectDocumentUpload::model()->findAll(array(
// 'condition'=>'media_code_id=:media_code_id AND project_id=:project_id',
// 'params'=>array(':media_code_id'=>11,':project_id'=>$id,),
// 'order'=>'date DESC',
// ));
// $modelProjectSupportingDocument=ProjectDocumentUpload::model()->findAll(array(
// 'condition'=>'media_code_id=:media_code_id AND project_id=:project_id',
// 'params'=>array(':media_code_id'=>12,':project_id'=>$id,),
// 'order'=>'date DESC',
// ));
// $modelProjectCcd=ProjectDocumentUpload::model()->findAll(array(
// 'condition'=>'media_code_id=:media_code_id AND project_id=:project_id',
// 'params'=>array(':media_code_id'=>13,':project_id'=>$id,),
// 'order'=>'date DESC',
// ));
// $modelProjectDc=ProjectDocumentUpload::model()->findAll(array(
// 'condition'=>'media_code_id=:media_code_id AND project_id=:project_id',
// 'params'=>array(':media_code_id'=>14,':project_id'=>$id,),
// 'order'=>'date DESC',
// ));
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Project']))
{
$model->attributes=$_POST['Project'];
date_default_timezone_set("Asia/Kuala_Lumpur");
$time = date_default_timezone_get() ;
$time = date('Y-m-d H:i:s');
$model->updated_time = $time;
$model->updated_user_id = Yii::app()->user->user_id;
//Section A
if (isset($_POST['BtnUpdate'])) {
$model->project_status_id = 2; // Updated Project
$tempDate1 = $model->project_date;
$model->project_date = date('Y-m-d', strtotime($tempDate1));
if (isset($_FILES['DocumentUpload'])) {
$files = $_FILES['DocumentUpload'];
$documentUploadPath = Yii::getPathOfAlias('webroot.uploaded.project').'/';
for ($i=1;$i<=3;$i++){
$mod_file1 = 'mod_file1'.$i;
// file upload - User document
if(!is_null($files['name']['mod_file1']) && !empty($files['name']['mod_file1'])) {
list($fn, $ext) = explode(".", basename($files['name']['mod_file1']));
$filename = substr(str_replace(" ", "_", $fn),0,5).'_'.date('Ymd_His').".".$ext;
$file = $documentUploadPath.$filename;
if (file_exists($file)) {
unlink($file);
}
move_uploaded_file($files['tmp_name']['mod_file1'], $file);
$modelProjectMod = new ProjectDocumentUpload;
$modelProjectMod->id = ProjectDocumentUpload::model()->getMax()+1;
$modelProjectMod->project_id = $model->id;
$modelProjectMod->media_code_id = 1;
// project admin User
$modelProjectMod->reference_no = 'Project Mod';
$modelProjectMod->filename = $filename;
$modelProjectMod->date = $time;
if ($modelProjectMod->save()) {
// add into audit trails
$modelAuditTrail=new AuditTrail;
$modelAuditTrail->id = AuditTrail::model()->getMax()+1;
$modelAuditTrail->controller = Yii::app()->controller->id;
$modelAuditTrail->action = Yii::app()->controller->action->id;
$modelAuditTrail->account_id = Yii::app()->user->account_id;
$modelAuditTrail->company_id = $activeCompanyId;
$modelAuditTrail->department_id = Yii::app()->user->department_id;
$modelAuditTrail->user_role_id = Yii::app()->user->user_role_id;
$modelAuditTrail->level = 1;
$modelAuditTrail->description = 'Add Request in Project No. '.$model->project_no;
$modelAuditTrail->created_time = $time;
$modelAuditTrail->updated_user_id = Yii::app()->user->user_id;
$modelAuditTrail->updated_time = $time;
$modelAuditTrail->save();
}
}
}
}
// get department list for moc
/*$department_list = "";
$modelProjectDepartment=ProjectDepartment::model()->findAll(array(
'condition'=>'project_id=:project_id',
'params'=>array(':project_id'=>$model->id),
));
foreach ($modelProjectDepartment as $projectDepartment) {
if(!empty($department_list))
$department_list .= " / ";
$department_list .= $projectDepartment->department->name;
}*/
// get 1st level approval list and All HOD email list
/*$recipient_names = "";
$recipient_emails = "";
$recipients=Account::model()->getProjectApproval($activeCompanyId);
foreach ($recipients as $email => $name) {
if(!empty($recipient_names))
$recipient_names .= "/";
$recipient_names .= $name;
if(!empty($recipient_emails))
$recipient_emails .= ", ";
$recipient_emails .= $email;
}*/
// Send notification to all HOD.
/*Yii::app()->globalFunction->sendUpdatedPROJECTNotification(
$model->User->firstname,
$model->project_no,
$model->forDepartment->name,
$department_list,
//Yii::app()->session['company_name'],
//$recipient_names,
$recipient_emails);*/
}
// Section B
if (isset($_POST['BtnMCR'])) {
if (isset($_FILES['DocumentUpload'])) {
$files = $_FILES['DocumentUpload'];
$documentUploadPath = Yii::getPathOfAlias('webroot.uploaded.project').'/';
for ($i=1;$i<=3;$i++){
$mcr_file1 = 'mcr_file1'.$i;
// file upload - User document
if(!is_null($files['name']['mcr_file1']) && !empty($files['name']['mcr_file1'])) {
list($fn, $ext) = explode(".", basename($files['name']['mcr_file1']));
$filename = substr(str_replace(" ", "_", $fn),0,5).'_'.date('Ymd_His').".".$ext;
$file = $documentUploadPath.$filename;
if (file_exists($file)) {
unlink($file);
}
move_uploaded_file($files['tmp_name']['mcr_file1'], $file);
$modelProjectMcr = new ProjectDocumentUpload;
$modelProjectMcr->id = ProjectDocumentUpload::model()->getMax()+1;
$modelProjectMcr->project_id = $model->id;
$modelProjectMcr->media_code_id = 2;
// project admin User
$modelProjectMcr->reference_no = 'Project Mcr';
$modelProjectMcr->filename = $filename;
$modelProjectMcr->date = $time;
if ($modelProjectMcr->save()) {
// add into audit trails
$modelAuditTrail=new AuditTrail;
$modelAuditTrail->id = AuditTrail::model()->getMax()+1;
$modelAuditTrail->controller = Yii::app()->controller->id;
$modelAuditTrail->action = Yii::app()->controller->action->id;
$modelAuditTrail->account_id = Yii::app()->user->account_id;
$modelAuditTrail->company_id = $activeCompanyId;
$modelAuditTrail->department_id = Yii::app()->user->department_id;
$modelAuditTrail->user_role_id = Yii::app()->user->user_role_id;
$modelAuditTrail->level = 1;
$modelAuditTrail->description = 'Add Request in Project No. '.$model->project_no;
$modelAuditTrail->created_time = $time;
$modelAuditTrail->updated_user_id = Yii::app()->user->user_id;
$modelAuditTrail->updated_time = $time;
$modelAuditTrail->save();
}
}
}
}
}
if (isset($_POST['BtnApprovalHOA'])) {
if (isset($_POST['hoa-approval-id-radio'])) {
$modelhoaApprovalStatus = $_POST['hoa-approval-id-radio'];
$model->project_type_id = $_POST['project-type-id-select'];
$tempDate2 = $model->hoa_approval_date;
$model->hoa_approval_date = date('Y-m-d', strtotime($tempDate2));
if ($modelhoaApprovalStatus == 2) { // Approved
$model->project_status_id = 5; // Approved by 1st Level
$model->hoa_approval_status_id = 5; // Approved by 1st Level
}
if ($modelhoaApprovalStatus == 3) { // Rejected
$model->project_status_id = 6; // Rejected by 1st Level
$model->hoa_approval_status_id = 6; // Rejected by 1st Level
}
if ($modelhoaApprovalStatus == 4) { // Review
$model->project_status_id = 3; //ssReview MOC by 1st Level
$model->hoa_approval_status_id = 3; // Review MOC by 1st Level
}
}
}
if (isset($_POST['BtnApprovalCAAM'])) {
if (isset($_POST['caam-approval-id-radio'])) {
$modelcaamApprovalStatus = $_POST['caam-approval-id-radio'];
$tempDate3 = $model->caam_approval_date;
$model->caam_approval_date = date('Y-m-d', strtotime($tempDate3));
if ($modelcaamApprovalStatus == 2) { // Approved
$model->project_status_id = 28; // Approved by 1st Level
$model->caam_approval_status_id = 28; // Approved by 1st Level
}
// if ($modelcaamApprovalStatus == 3) { // Rejected
// $model->project_status_id = 27; // Rejected by 1st Level
// $model->caam_approval_status_id = 27; // Rejected by 1st Level
// }
if ($modelcaamApprovalStatus == 4) { // Review
$model->project_status_id = 26; //ssReview MC by CAAM
$model->caam_approval_status_id = 26; // Review MOC by 1st Level
}
}
}
if (isset($_POST['BtnCP'])) {
if (isset($_FILES['DocumentUpload'])) {
$files = $_FILES['DocumentUpload'];
$documentUploadPath = Yii::getPathOfAlias('webroot.uploaded.project').'/';
for ($i=1;$i<=3;$i++){
$cp_file1 = 'cp_file1'.$i;
// file upload - User document
if(!is_null($files['name']['cp_file1']) && !empty($files['name']['cp_file1'])) {
list($fn, $ext) = explode(".", basename($files['name']['cp_file1']));
$filename = substr(str_replace(" ", "_", $fn),0,5).'_'.date('Ymd_His').".".$ext;
$file = $documentUploadPath.$filename;
if (file_exists($file)) {
unlink($file);
}
move_uploaded_file($files['tmp_name']['cp_file1'], $file);
$modelProjectCP = new ProjectDocumentUpload;
$modelProjectCP->id = ProjectDocumentUpload::model()->getMax()+1;
$modelProjectCP->project_id = $model->id;
$modelProjectCP->media_code_id = 3;
// project admin User
$modelProjectCP->reference_no = 'Project Cp';
$modelProjectCP->filename = $filename;
$modelProjectCP->date = $time;
if ($modelProjectCP->save()) {
// add into audit trails
$modelAuditTrail=new AuditTrail;
$modelAuditTrail->id = AuditTrail::model()->getMax()+1;
$modelAuditTrail->controller = Yii::app()->controller->id;
$modelAuditTrail->action = Yii::app()->controller->action->id;
$modelAuditTrail->account_id = Yii::app()->user->account_id;
$modelAuditTrail->company_id = $activeCompanyId;
$modelAuditTrail->department_id = Yii::app()->user->department_id;
$modelAuditTrail->user_role_id = Yii::app()->user->user_role_id;
$modelAuditTrail->level = 1;
$modelAuditTrail->description = 'Add Request in Project No. '.$model->project_no;
$modelAuditTrail->created_time = $time;
$modelAuditTrail->updated_user_id = Yii::app()->user->user_id;
$modelAuditTrail->updated_time = $time;
$modelAuditTrail->save();
}
}
}
}
}
if (isset($_POST['BtnApprovalHOA2'])) {
if (isset($_POST['hoa-approval-level2-id-radio'])) {
$modelhoaApproval2Status = $_POST['hoa-approval-level2-id-radio'];
$tempDate4 = $model->hoa_approval_level2_date;
$model->hoa_approval_level2_date = date('Y-m-d', strtotime($tempDate4));
if ($modelhoaApproval2Status == 2) { // Approved
$model->project_status_id = 10; // Approved by 1st Level
$model->hoa_approval_level2_status_id = 10; // Approved by 1st Level
}
if ($modelhoaApproval2Status == 3) { // Rejected
$model->project_status_id = 11; // Rejected by 1st Level
$model->hoa_approval_level2_status_id = 11; // Rejected by 1st Level
}
if ($modelhoaApproval2Status == 4) { // Review
$model->project_status_id = 8; //ssReview MOC by 1st Level
$model->hoa_approval_level2_status_id = 8; // Review MOC by 1st Level
}
}
}
if (isset($_POST['BtnSupportingDocument'])) {
if (isset($_FILES['DocumentUpload'])) {
$files = $_FILES['DocumentUpload'];
$documentUploadPath = Yii::getPathOfAlias('webroot.uploaded.project').'/';
for ($i=1;$i<=3;$i++){
$md_file = 'md_file'.$i;
// file upload - User document
if(!is_null($files['name']['md_file']) && !empty($files['name']['md_file'])) {
list($fn, $ext) = explode(".", basename($files['name']['md_file']));
$filename = substr(str_replace(" ", "_", $fn),0,5).'_'.date('Ymd_His').".".$ext;
$file = $documentUploadPath.$filename;
if (file_exists($file)) {
unlink($file);
}
move_uploaded_file($files['tmp_name']['md_file'], $file);
$modelProjectMD = new ProjectDocumentUpload;
$modelProjectMD->id = ProjectDocumentUpload::model()->getMax()+1;
$modelProjectMD->project_id = $model->id;
$modelProjectMD->media_code_id = 5;
// project admin User
$modelProjectMD->reference_no = 'Project MD';
$modelProjectMD->filename = $filename;
$modelProjectMD->date = $time;
if ($modelProjectMD->save()) {
// add into audit trails
$modelAuditTrail=new AuditTrail;
$modelAuditTrail->id = AuditTrail::model()->getMax()+1;
$modelAuditTrail->controller = Yii::app()->controller->id;
$modelAuditTrail->action = Yii::app()->controller->action->id;
$modelAuditTrail->account_id = Yii::app()->user->account_id;
$modelAuditTrail->company_id = $activeCompanyId;
$modelAuditTrail->department_id = Yii::app()->user->department_id;
$modelAuditTrail->user_role_id = Yii::app()->user->user_role_id;
$modelAuditTrail->level = 1;
$modelAuditTrail->description = 'Add Request in Project No. '.$model->project_no;
$modelAuditTrail->created_time = $time;
$modelAuditTrail->updated_user_id = Yii::app()->user->user_id;
$modelAuditTrail->updated_time = $time;
$modelAuditTrail->save();
}
}
}
}
}
$tempDate5 = $model->hoa_approval_level3_date;
if (!is_null($tempDate5) && !empty($tempDate5))
$model->hoa_approval_level3_date = date('Y-m-d', strtotime($tempDate5));
else
$model->hoa_approval_level3_date = NULL;
$tempDate6 = $model->hoa_approval_level4_date;
if (!is_null($tempDate6) && !empty($tempDate6))
$model->hoa_approval_level4_date = date('Y-m-d', strtotime($tempDate6));
else
$model->hoa_approval_level4_date = NULL;
$tempDate7 = $model->cve_approval_date;
if (!is_null($tempDate7) && !empty($tempDate7))
$model->cve_approval_date = date('Y-m-d', strtotime($tempDate7));
else
$model->cve_approval_date = NULL;
$tempDate8 = $model->hodo_approval_date;
if (!is_null($tempDate8) && !empty($tempDate8))
$model->hodo_approval_date = date('Y-m-d', strtotime($tempDate8));
else
$model->hodo_approval_date = NULL;
$tempDate9 = $model->caam_approval_level2_date;
if (!is_null($tempDate9) && !empty($tempDate9))
$model->caam_approval_level2_date = date('Y-m-d', strtotime($tempDate9));
else
$model->caam_approval_level2_date = NULL;
if (isset($_POST['BtnApprovalCVE'])) {
if (isset($_POST['cve-approval-id-radio'])) {
$modelcveApprovalStatus = $_POST['cve-approval-id-radio'];
if ($modelcveApprovalStatus == 2) { // Approved
$model->project_status_id = 5; // Approved by 1st Level
$model->cve_approval_status_id = 5; // Approved by 1st Level
}
if ($modelcveApprovalStatus == 3) { // Rejected
$model->project_status_id = 6; // Rejected by 1st Level
$model->cve_approval_status_id = 6; // Rejected by 1st Level
}
if ($modelcveApprovalStatus == 4) { // Review
$model->project_status_id = 3; //ssReview MOC by 1st Level
$model->cve_approval_status_id = 3; // Review MOC by 1st Level
}
}
}
if (isset($_POST['BtnApprovalHOA3'])) {
if (isset($_POST['hoa-approval-level3-id-radio'])) {
$modelhoaApproval3Status = $_POST['hoa-approval-level3-id-radio'];
if ($modelhoaApproval3Status == 2) { // Approved
$model->project_status_id = 10; // Approved by 1st Level
$model->hoa_approval_level3_status_id = 10; // Approved by 1st Level
}
if ($modelhoaApproval3Status == 3) { // Rejected
$model->project_status_id = 11; // Rejected by 1st Level
$model->hoa_approval_level3_status_id = 11; // Rejected by 1st Level
}
if ($modelhoaApproval3Status == 4) { // Review
$model->project_status_id = 8; //ssReview MOC by 1st Level
$model->hoa_approval_level3_status_id = 8; // Review MOC by 1st Level
}
}
}
if (isset($_POST['BtnApprovalHOA4'])) {
if (isset($_POST['hoa-approval-level4-id-radio'])) {
$modelhoaApproval4Status = $_POST['hoa-approval-level4-id-radio'];
if ($modelhoaApproval4Status == 2) { // Approved
$model->project_status_id = 10; // Approved by 1st Level
$model->hoa_approval_level4_status_id = 10; // Approved by 1st Level
}
if ($modelhoaApproval4Status == 3) { // Rejected
$model->project_status_id = 11; // Rejected by 1st Level
$model->hoa_approval_level4_status_id = 11; // Rejected by 1st Level
}
if ($modelhoaApproval4Status == 4) { // Review
$model->project_status_id = 8; //ssReview MOC by 1st Level
$model->hoa_approval_level4_status_id = 8; // Review MOC by 1st Level
}
}
}
if (isset($_POST['BtnApprovalHODO'])) {
if (isset($_POST['hodo-approval-id-radio'])) {
$modelhodoApprovalStatus = $_POST['hodo-approval-id-radio'];
if ($modelhodoApprovalStatus == 2) { // Approved
$model->project_status_id = 5; // Approved by 1st Level
$model->hodo_approval_status_id = 5; // Approved by 1st Level
}
if ($modelhodoApprovalStatus == 3) { // Rejected
$model->project_status_id = 6; // Rejected by 1st Level
$model->hodo_approval_status_id = 6; // Rejected by 1st Level
}
if ($modelhodoApprovalStatus == 4) { // Review
$model->project_status_id = 3; //ssReview MOC by 1st Level
$model->hodo_approval_status_id = 3; // Review MOC by 1st Level
}
}
}
if (isset($_POST['BtnApprovalCAAM2'])) {
if (isset($_POST['caam-approval-level2-id-radio'])) {
$modelcaamApproval2Status = $_POST['caam-approval-level2-id-radio'];
if ($modelcaamApproval2Status == 2) { // Approved
$model->project_status_id = 28; // Approved by 1st Level
$model->caam_approval_level2_status_id = 28; // Approved by 1st Level
}
// if ($modelcaamApprovalStatus == 3) { // Rejected
// $model->project_status_id = 27; // Rejected by 1st Level
// $model->caam_approval_status_id = 27; // Rejected by 1st Level
// }
if ($modelcaamApproval2Status == 4) { // Review
$model->project_status_id = 26; //ssReview MC by CAAM
$model->caam_approval_level2_status_id = 26; // Review MOC by 1st Level
}
}
}
if($model->save()) {
//add into timeline
$modelProjectStatusLog=new ProjectStatusLog;
$modelProjectStatusLog->id = ProjectStatusLog::model()->getMax()+1;
$modelProjectStatusLog->project_id = $model->id;
$modelProjectStatusLog->project_status_id = $model->project_status_id;
$modelProjectStatusLog->updated_user_id = Yii::app()->user->user_id;
$modelProjectStatusLog->updated_time = $time;
$modelProjectStatusLog->save();
}
else
$model->project_date = $tempDate1;
// $model->hoa_approval_date = $tempDate2;
// $model->caam_approval_date = $tempDate3;
// $model->hoa_approval_level2_date = $tempDate4;
// $model->cve_approval_date = $tempDate5;
// $model->hoa_approval_level3_date = $tempDate6;
// $model->hoa_approval_level4_date = $tempDate7;
// $model->hodo_approval_date = $tempDate8;
// $model->caam_approval_level2_date = $tempDate9;
}
$tempDate1 = $model->project_date;
if (!is_null($tempDate1) && !empty($tempDate1))
$model->project_date = date('j M Y', strtotime($tempDate1));
$tempDate2 = $model->hoa_approval_date;
if (!is_null($tempDate2) && !empty($tempDate2))
$model->hoa_approval_date = date('j M Y', strtotime($tempDate2));
$tempDate3 = $model->caam_approval_date;
if (!is_null($tempDate3) && !empty($tempDate3))
$model->caam_approval_date = date('j M Y', strtotime($tempDate3));
$tempDate4 = $model->hoa_approval_level2_date;
if (!is_null($tempDate4) && !empty($tempDate4))
$model->hoa_approval_level2_date = date('j M Y', strtotime($tempDate4));
$tempDate5 = $model->cve_approval_date;
if (!is_null($tempDate5) && !empty($tempDate5))
$model->cve_approval_date = date('j M Y', strtotime($tempDate5));
$tempDate6 = $model->hoa_approval_level3_date;
if (!is_null($tempDate6) && !empty($tempDate6))
$model->hoa_approval_level3_date = date('j M Y', strtotime($tempDate6));
$tempDate7 = $model->hoa_approval_level4_date;
if (!is_null($tempDate7) && !empty($tempDate7))
$model->hoa_approval_level4_date = date('j M Y', strtotime($tempDate7));
$tempDate8 = $model->hodo_approval_date;
if (!is_null($tempDate8) && !empty($tempDate8))
$model->hodo_approval_date = date('j M Y', strtotime($tempDate8));
$tempDate9 = $model->caam_approval_level2_date;
if (!is_null($tempDate9) && !empty($tempDate9))
$model->caam_approval_level2_date = date('j M Y', strtotime($tempDate9));
$this->render('update',array(
'section'=>$section,
'model'=>$model,
'modelProjectPriority'=>$modelProjectPriority,
'modelClient'=>$modelClient,
'modelAircraftRegistration'=>$modelAircraftRegistration,
'modelAircraftType'=>$modelAircraftType,
'modelAircraftSerielNumber'=>$modelAircraftSerielNumber,
'modelDepartment'=>$modelDepartment,
'modelProjectMod'=>$modelProjectMod,
'modelProjectMcr'=>$modelProjectMcr,
'modelProjectCP'=>$modelProjectCP,
'modelProjectApproval'=>$modelProjectApproval,
'modelProjectType'=>$modelProjectType,
));
}