コード例 #1
0
 public function run()
 {
     if (!$this->userId) {
         $this->userId = Yii::app()->user->id;
     }
     $info = TariffPlans::getTariffInfoByUserId($this->userId);
     $this->render('userTariffInfoViewWidget', array('id' => $info['id'], 'name' => $info['name'], 'description' => $info['description'], 'limitObjects' => $info['limitObjects'], 'limitPhotos' => $info['limitPhotos'], 'price' => $info['price'], 'duration' => $info['duration'], 'showAddress' => $info['showAddress'], 'showPhones' => $info['showPhones'], 'currency' => Currency::getDefaultCurrencyModel()->name, 'userCountObjects' => TariffPlans::getCountUserObjects($this->userId), 'tariffDateStart' => $info['tariffDateStart'], 'tariffDateEnd' => $info['tariffDateEnd'], 'tariffStatus' => $info['tariffStatus'], 'tariffDateStartFormat' => $info['tariffDateStartFormat'], 'tariffDateEndFormat' => $info['tariffDateEndFormat'], 'isDefaultTariffPlan' => $info['id'] == TariffPlans::DEFAULT_TARIFF_PLAN_ID ? true : false));
 }
コード例 #2
0
ファイル: MainController.php プロジェクト: barricade86/raui
 public function actionBuyTariffPlan()
 {
     $this->layout = '//layouts/usercpanel';
     $user = HUser::getModel();
     $tariffId = Yii::app()->request->getParam('tariffid');
     if (!$user || !$tariffId) {
         throw404();
     }
     $currentTariffModel = TariffPlans::model()->findByPk($tariffId);
     if (!$currentTariffModel || $currentTariffModel->active != TariffPlans::STATUS_ACTIVE) {
         throw404();
     }
     // check current user tariff plan
     $currentTariffPlanInfo = TariffPlans::getTariffInfoByUserId($user->id);
     if ($currentTariffPlanInfo['issetTariff'] && $currentTariffPlanInfo['tariffDuration']) {
         if (!$currentTariffPlanInfo['activeTariff']) {
             Yii::app()->user->setFlash('error', Yii::t("module_tariffPlans", "You can only extend the tariff plan {name}", array("{name}" => $currentTariffPlanInfo['tariffName'])));
             $this->redirect(array('choosetariffplans'));
             Yii::app()->end();
         }
     }
     // check balance
     if ($currentTariffModel->price) {
         # платный тариф
         if ($currentTariffModel->price > $user->balance) {
             Yii::app()->user->setFlash('error', tt('On your balance is not enough money to buy the chosen tariff plan', 'tariffPlans'));
             $this->redirect(array('choosetariffplans'));
             Yii::app()->end();
         }
     }
     // check object count
     if ($currentTariffModel->limit_objects) {
         $usersObjects = TariffPlans::getCountUserObjects($user->id);
         if ($usersObjects > $currentTariffModel->limit_objects) {
             Yii::app()->user->setFlash('error', tt('The number of added ads exceeds the limit of the tariff. Remove its not relevant your ads and try again.', 'tariffPlans'));
             $this->redirect(array('choosetariffplans'));
             Yii::app()->end();
         }
     }
     // apply action
     $interval = 'INTERVAL ' . $currentTariffModel->duration . ' DAY';
     $dateEnd = new CDbExpression('NOW() + ' . $interval);
     if (TariffPlans::applyToUser($user->id, $tariffId, $dateEnd, $interval)) {
         if ($currentTariffModel->price) {
             # платный тариф
             $user->deductBalance($currentTariffModel->price);
         }
         Yii::app()->user->setFlash('success', tt('Tariff plan has been successfully applied', 'tariffPlans'));
         $this->redirect(array('tariffhistory'));
     } else {
         Yii::app()->user->setFlash('error', tc('Error. Repeat attempt later'));
         $this->redirect(array('choosetariffplans'));
         Yii::app()->end();
     }
 }
コード例 #3
0
ファイル: MainController.php プロジェクト: barricade86/raui
 public function actionUpload($id)
 {
     $model = $this->checkOwner($id);
     $maxImgs = 0;
     # unlimited
     $currImgCount = 0;
     if (issetModule('tariffPlans') && issetModule('paidservices')) {
         $sql = 'SELECT COUNT(id) FROM {{images}} WHERE id_object = ' . $model->id;
         $currImgCount = Yii::app()->db->createCommand($sql)->queryScalar();
         $userTariffInfo = TariffPlans::getTariffInfoByUserId($model->owner_id);
         $maxImgs = $userTariffInfo['limitPhotos'];
         if (Yii::app()->user->checkAccess("backend_access")) {
             # admin or moderator
             $maxImgs = 0;
         }
     }
     if ($maxImgs > 0 && $currImgCount >= $maxImgs) {
         $result['error'] = Yii::t("module_tariffPlans", "You are trying to download more than {num} pictures ( your tariff limit )", array("{num}" => $maxImgs));
         $result = htmlspecialchars(json_encode($result), ENT_NOQUOTES);
         echo $result;
         Yii::app()->end();
     }
     Yii::import("ext.EAjaxUpload.qqFileUploader");
     $allowedExtensions = param('allowedImgExtensions', array('jpg', 'jpeg', 'gif', 'png'));
     //$sizeLimit = param('maxImgFileSize', 8 * 1024 * 1024);
     $sizeLimit = Images::getMaxSizeLimit();
     $uploader = new qqFileUploader($allowedExtensions, $sizeLimit);
     $path = Yii::getPathOfAlias('webroot.uploads.objects.' . $model->id . '.' . Images::ORIGINAL_IMG_DIR);
     $pathMod = Yii::getPathOfAlias('webroot.uploads.objects.' . $model->id . '.' . Images::MODIFIED_IMG_DIR);
     $oldUMask = umask(0);
     if (!is_dir($path)) {
         @mkdir($path, 0777, true);
     }
     if (!is_dir($pathMod)) {
         @mkdir($pathMod, 0777, true);
     }
     umask($oldUMask);
     if (is_writable($path) && is_writable($pathMod)) {
         touch($path . DIRECTORY_SEPARATOR . 'index.htm');
         touch($pathMod . DIRECTORY_SEPARATOR . 'index.htm');
         $result = $uploader->handleUpload($path . DIRECTORY_SEPARATOR, false, uniqid());
         if (isset($result['success']) && $result['success']) {
             $resize = new CImageHandler();
             if ($resize->load($path . DIRECTORY_SEPARATOR . $result['filename'])) {
                 $resize->thumb(param('maxImageWidth', 1024), param('maxImageHeight', 768), Images::KEEP_PHOTO_PROPORTIONAL)->save();
                 $image = new Images();
                 $image->id_object = $model->id;
                 $image->id_owner = $model->owner_id;
                 $image->file_name = $result['filename'];
                 if ($image->save() && $model->hasAttribute('count_img')) {
                     $model->count_img++;
                     $model->update('count_img');
                 }
             } else {
                 $result['error'] = 'Wrong image type.';
                 @unlink($path . DIRECTORY_SEPARATOR . $result['filename']);
             }
         }
     } else {
         $result['error'] = 'Access denied.';
     }
     // to pass data through iframe you will need to encode all html tags
     $result = htmlspecialchars(json_encode($result), ENT_NOQUOTES);
     echo $result;
 }