$model->scanned_employment_pass = CUploadedFile::getInstance($model, 'scanned_employment_pass'); $model->scanned_passport = CUploadedFile::getInstance($model, 'scanned_passport'); if (!empty($model->user_id)) { $model->scenario = 'AgentAddTenantExitUid'; } $model->validate(); if (!$model->hasErrors()) { $oldUser = false; if (!empty($model->user_id)) { $oldUser = true; } ProTransactionsVendorPurchaserDetail::saveOneTenant($model, 0); if ($oldUser) { // không xử lý cho edit tenant nữa, chỉ lưu user_id của tenant thôi, // nên không cần phải copy file qua nữa // $mUser = Users::model()->findByPk($model->user_id); // Users::copyTwoFileFromUserToTenant($mUser, $model); } // $model->type = Users::USER_TENANT; // $mUser = Users::saveUserVendorPurchaser($model); // $model->user_id = $mUser->id; // $model->pass_expiry_date = MyFormat::dateConverDmyToYmd($model->pass_expiry_date); // $model->save(); // ProTransactionsVendorPurchaserDetail::saveSomeFile($model,'scanned_employment_pass'); // ProTransactionsVendorPurchaserDetail::saveSomeFile($model,'scanned_passport'); die('<script type="text/javascript">parent.$.fancybox.close(); parent.fnUpdateBoxTenant();</script>'); } } $this->render('CreateTransaction/AgentAddTenant', array('model' => $model)); } catch (Exception $exc) { throw new CHttpException(404, $exc->getMessage()); } } public function actionAgentUpdateTenant($id) { try { $oldUser = false; $model = $this->loadModelVendorPurchaserDetail($id); $uidOld = $model->user_id; $model->scenario = 'AgentUpdateTenantFromTenancy'; if (isset($_GET['from_transactions'])) { $model->scenario = 'AgentUpdateTenant'; } if (isset($_GET['add_property']) && $_GET['add_property'] == ProTransactions::ADD_UNLISTED) { $model->scenario = 'AgentUpdateTenantUnlisted'; } $oldscanned_employment_pass = $model->scanned_employment_pass; $oldscanned_passport = $model->scanned_passport; $cmsFormater = new CmsFormatter(); $model->pass_expiry_date = $cmsFormater->formatDatePickerInput($model->pass_expiry_date); if (isset($_POST['ProTransactionsVendorPurchaserDetail'])) { $model->attributes = $_POST['ProTransactionsVendorPurchaserDetail']; $model->scanned_employment_pass = CUploadedFile::getInstance($model, 'scanned_employment_pass'); $model->scanned_passport = CUploadedFile::getInstance($model, 'scanned_passport'); $model->validate(); if (!$model->hasErrors()) { if ($model->user_id != $uidOld) { $oldUser = true; } if (!is_null($model->scanned_employment_pass)) { ProTransactionsVendorPurchaserDetail::deleteOldFile($model, 'scanned_employment_pass'); $model->scanned_employment_pass = ProTransactionsVendorPurchaserDetail::saveSomeFile($model, 'scanned_employment_pass');
/** * @Author: ANH DUNG Apr 21, 2014 * @Todo: save one record of tenant * @Param: $model model ProTransactionsVendorPurchaserDetail */ public static function saveOneTenant($model, $is_default = 0, $needMore = array()) { $model->type = Users::USER_TENANT; $model->is_default = $is_default; $model->pass_expiry_date = MyFormat::dateConverDmyToYmd($model->pass_expiry_date); $mUser = null; if (empty($model->user_id)) { $mUser = Users::saveUserVendorPurchaser($model, ROLE_TENANT); $model->user_id = $mUser->id; $model->is_new_user = 1; } if (isset($needMore['scenario_null'])) { $model->scenario = null; } $model->save(); //add $FileInput = $_FILES["ProTransactionsVendorPurchaserDetail"]["name"]["scanned_employment_pass"]; $FileInput2 = $_FILES["ProTransactionsVendorPurchaserDetail"]["name"]["scanned_passport"]; if (!empty($FileInput)) { ProTransactionsVendorPurchaserDetail::saveSomeFile($model, 'scanned_employment_pass'); } if (!empty($FileInput2)) { ProTransactionsVendorPurchaserDetail::saveSomeFile($model, 'scanned_passport'); } // if($mUser && $model->is_new_user && $model->id_type!= Users::ID_TYPE_CITIZENSHIP){ if ($mUser && $model->is_new_user) { // save 2 file upload if have to table user Users::saveTwoFileOfTenant($mUser, $model); } }