/** * Jun 07, 2014 - ANH DUNG * To do: save file * @param: $model is model ProGlobalEnquiry * @param: $fieldName file_name * @return: name of image upload/global_enquiry */ public static function saveFile($model, $fieldName) { if (is_null($model->{$fieldName})) { return ''; } $aDate = explode('-', $model->date_only); $pathUpload = ProGlobalEnquiry::$folderUpload . "/{$aDate['0']}/{$aDate['1']}/{$aDate['2']}"; $ext = $model->{$fieldName}->getExtensionName(); $file_name_slug = strtolower(MyFunctionCustom::slugify($model->{$fieldName}->getName())); $file_name_slug = str_replace(strtolower($ext), '', $file_name_slug); $model->file_name_slug = $file_name_slug; $fileName = date('Y-m-d'); $fileName = time() . '-' . ActiveRecord::randString() . '.' . $ext; $imageProcessing = new ImageProcessing(); $imageProcessing->createDirectoryByPath($pathUpload); $model->{$fieldName}->saveAs($pathUpload . '/' . $fileName); $model->{$fieldName} = $fileName; return $fileName; }
public function actionResetPassword() { $id = Yii::app()->request->getParam('id'); $key = Yii::app()->request->getParam('key'); $model = Users::model()->findByPk((int) $id); if ($model !== null && $key == ForgotPasswordForm::generateKey($model)) { $pass = ActiveRecord::randString(6); $model->password_hash = md5($pass); $model->temp_password = $pass; $model->update(); $name = $model->first_name . ' ' . $model->last_name; $login_link = '<a href="' . Yii::app()->createAbsoluteUrl("admin/site/login") . '">' . Yii::app()->createAbsoluteUrl("admin/site/login") . '</a>'; $aBody = array('{NAME}' => $name, '{PASSWORD}' => $model->temp_password, '{LINK_LOGIN}' => $login_link); if (CmsEmail::sendmail(2, array(), $aBody, $model->email)) { Yii::app()->user->setFlash("success", "An email has sent to: {$model->email}. Please check email to get new password."); } else { $model->addError('email', 'Can not send email to: ' . $model->email); } } else { Yii::log('Invalid request. Please do not repeat this request again.'); throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.'); } $this->render('ResetPassword', array('model' => $model)); }
/** * @Author: ANH DUNG Aug 12, 2014 * @Todo: save photo listing upload * @Param: $model model */ public static function SavePhotoListing($model) { $uid = Yii::app()->user->id; if (isset($_FILES['Listing']['name']['photo_listing_anhdung']) && count($_FILES['Listing']['name']['photo_listing_anhdung'])) { $cMaxDisplay = ProListingPhotos::GetMaxDisplayOrder($model->id); foreach ($_FILES['Listing']['name']['photo_listing_anhdung'] as $key => $item) { if (Listing::CountPhotoListing($model->id) >= Listing::GetLimitPhotoUpload()) { return; } $mFile = new ProListingPhotos(); $mFile->FileValidate = CUploadedFile::getInstanceByName('Listing[photo_listing_anhdung][' . $key . ']'); $mFile->validate(); if (!$mFile->hasErrors()) { $ext = $mFile->FileValidate->getExtensionName(); $mFile->image = $uid . "-" . time() . ActiveRecord::randString() . $key . '.' . $ext; // file name $mFile->listing_id = $model->id; $mFile->default = 0; $mFile->display_order = ++$cMaxDisplay; $mFile->save(); Listing::saveFile($mFile, 'FileValidate', $mFile->image); Listing::ResizePhotoListing($mFile); Listing::PutWarterMarkPhotoListing($mFile); Listing::ResizePhotoListingSmall($mFile); } } Listing::AutoSetCoverPhotoListing($model->id); } }
/** * Jun 07, 2014 - ANH DUNG * To do: save file * @param: $model is model ProGlobalEnquiry * @param: $fieldName file_name * @return: name of image upload/global_enquiry */ public static function saveFile($model, $fieldName) { if (is_null($model->{$fieldName})) { return ''; } $pathUpload = ProInventoryPhoto::$folderUpload; $ext = $model->{$fieldName}->getExtensionName(); $file_name_slug = strtolower(MyFunctionCustom::slugify($model->{$fieldName}->getName())); $file_name_slug = str_replace(strtolower($ext), '', $file_name_slug); $model->file_name_slug = $file_name_slug; $fileName = date('Y-m-d'); $uid = isset(Yii::app()->user->id) ? Yii::app()->user->id : 999999; $fileName = $uid . '-' . time() . '-' . ActiveRecord::randString() . '.' . $ext; $imageProcessing = new ImageProcessing(); $imageProcessing->createDirectoryByPath($pathUpload); $model->{$fieldName}->saveAs($pathUpload . '/' . $fileName); $model->{$fieldName} = $fileName; return $fileName; }
return; } if (!empty($name)) { $result = Users::model()->findByPk($id)->{$name}; } else { $result = Users::model()->findByPk($id); } return $result; } public static function loadItems($emptyOption = false) { $_items = array(); if ($emptyOption) { $_items[""] = ""; } $model = self::model()->findByPk(Yii::app()->user->getId()); //foreach($models as $model) $_items[$model->id] = $model->email; return $_items; } public static function generateKey($user)
/** * Jul 08, 2014 - ANH DUNG * To do: save file * @param: $model model ProAirconService: * @param: $nameField ex: file_name * @param: $pathUpload ex: 'upload/aircon_service:' * @return: name of image */ public static function saveFile($model, $nameField, $pathUpload, $count) { if (is_null($model->{$nameField})) { return ''; } $ext = $model->{$nameField}->getExtensionName(); $fileName = MyFunctionCustom::slugify($model->{$nameField}->getName()); $fileName = str_replace(strtolower($ext), '', $fileName); $fileName = trim($fileName, '-'); $fileName = trim($fileName); $fileName = $fileName . '-' . time() . ActiveRecord::randString() . '.' . $ext; $imageProcessing = new ImageProcessing(); $imageProcessing->createDirectoryByPath($pathUpload); // $imageProcessing->createDirectoryByPath($pathUpload.'/'.$model->id); // $model->$nameField->saveAs($pathUpload.'/'.$model->id.'/'.$fileName); $model->{$nameField}->saveAs($pathUpload . '/' . $fileName); return $fileName; }