public function actionUpdate($id) { $model = $this->loadModel($id); $model->scenario = 'update'; if (issetModule('rbac')) { if (Yii::app()->user->role == User::ROLE_MODERATOR && $model->role == User::ROLE_ADMIN) { throw404(); } } $this->performAjaxValidation($model); if (isset($_POST[$this->modelName])) { $model->attributes = $_POST[$this->modelName]; if (isset($_POST[$this->modelName]['password']) && $_POST[$this->modelName]['password']) { if (demo()) { Yii::app()->user->setFlash('error', tc('Sorry, this action is not allowed on the demo server.')); unset($model->password, $model->salt); $this->redirect(array('update', 'id' => $model->id)); } else { $model->scenario = 'changePass'; } } else { unset($model->password, $model->salt); } if ($model->validate()) { if ($model->scenario == 'changePass') { $model->setPassword(); } if ($model->save(false)) { $this->redirect(array('view', 'id' => $model->id)); } } } $this->render('update', array('model' => $model)); }
public function actionSearch($type = 'all') { if (!param('useShowUserInfo')) { throw new CHttpException(403, tt('Displays information about the users is disabled by the administrator', 'users')); } $usersListPage = Menu::model()->findByPk(Menu::USERS_LIST_ID); if ($usersListPage) { if ($usersListPage->active == 0) { throw404(); } } $this->showSearchForm = false; $existTypes = User::getTypeList('withAll'); $criteria = new CDbCriteria(); $type = in_array($type, array_keys($existTypes)) ? $type : 'all'; //$criteria->compare('active', 1); if ($type != 'all') { $criteria->compare('type', $type); } //$criteria->compare('isAdmin', 0); $criteria->with = array('countAdRel'); $sort = new CSort(); $sort->sortVar = 'sort'; $sort->defaultOrder = 'date_created DESC'; $sort->multiSort = true; $sort->attributes = array('username' => array('label' => tc('by username'), 'default' => 'desc'), 'date_created' => array('label' => tc('by date of registration'), 'default' => 'desc')); $dataProvider = new CActiveDataProvider(User::model()->active(), array('criteria' => $criteria, 'sort' => $sort, 'pagination' => array('pageSize' => 12))); $this->render('search', array('dataProvider' => $dataProvider, 'type' => $type)); }
public function actionRead() { $id = Yii::app()->request->getParam('id'); $apId = (int) Yii::app()->request->getParam('apId'); if (!$id) { throw404(); } $user = User::model()->findByPk($id); Yii::app()->user->setState('menu_active', 'messages.read'); $model = new $this->modelName(); // выставляем флаг о прочитанности $unRealMessages = Messages::model()->unReadUser()->criteriaUser($id, Yii::app()->user->id)->findAll(array('select' => 'id')); $idArr = array(); foreach ($unRealMessages as $item) { $idArr[] = (int) $item->id; } if (count($idArr) > 0) { Messages::model()->updateByPk($idArr, array('is_read' => Messages::STATUS_READ_USER, 'date_read' => new CDbExpression('NOW()'))); } $allMessages = $pages = null; $return = Messages::getAllMessagesUser($id); if ($return) { $allMessages = $return['allMessages']; $pages = $return['pages']; } # если нет сообщений от выбранного пользователя /*if (!$allMessages) throw404();*/ $this->render('read', array('allMessages' => $allMessages, 'pages' => $pages, 'senderInfo' => $user, 'model' => $model, 'uid' => $id, 'apId' => $apId)); }
public function beforeSave() { if (!$this->isNewRecord && $this->owner_id != Yii::app()->user->id) { throw404(); } return parent::beforeSave(); }
public function actionView($id = 0, $url = '') { if ($url && issetModule('seo')) { $seo = SeoFriendlyUrl::getForView($url, $this->modelName); if (!$seo) { throw404(); } $this->setSeo($seo); $id = $seo->model_id; } $model = $this->loadModel($id, 1); if (!$model->active) { throw404(); } if ($model->id == 4) { //User Agreement $field = 'body_' . Yii::app()->language; $model->{$field} = str_replace('{site_domain}', IdnaConvert::checkDecode(Yii::app()->getBaseUrl(true)), $model->{$field}); $model->{$field} = str_replace('{site_title}', CHtml::encode(Yii::app()->name), $model->{$field}); } $this->showSearchForm = $model->widget && $model->widget == 'apartments' ? true : false; if (Yii::app()->request->isAjaxRequest) { $this->renderPartial('view', array('model' => $model)); } else { $this->render('view', array('model' => $model)); } }
protected function beforeAction($action) { if (oreInstall::isInstalled()) { throw404(); } $this->setLangInstall(); return parent::beforeAction($action); }
public function actionDeleteOption($id) { $model = PaidOptions::model()->findByPk($id); if (!$model) { throw404(); } $model->delete(); $this->redirect(array('admin')); }
public function checkOwnerImage($id) { $this->modelName = 'Images'; $model = $this->loadModel($id); if (!$model || !Yii::app()->user->getState('isAdmin') && Yii::app()->user->id != $model->id_owner) { throw404(); } return $model; }
public function init() { parent::init(); $vacancyPage = Menu::model()->findByPk(Menu::VACANCY_ID); if ($vacancyPage) { if ($vacancyPage->active == 0) { throw404(); } } }
public function init() { parent::init(); $reviewsPage = Menu::model()->findByPk(Menu::REVIEWS_ID); if ($reviewsPage) { if ($reviewsPage->active == 0) { throw404(); } } }
public function init() { parent::init(); $specialOfferPage = Menu::model()->findByPk(Menu::SPECIALOFFERS_ID); if ($specialOfferPage) { if ($specialOfferPage->active == 0) { throw404(); } } }
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(); } }
public function init() { // если админ - делаем редирект на просмотр в админку if (Yii::app()->user->getState('isAdmin')) { $this->redirect($this->createAbsoluteUrl('/bookingtable/backend/main/admin')); } if (!param('useUserads')) { throw404(); } parent::init(); }
public function actionIndex() { $newsPage = Menu::model()->findByPk(Menu::NEWS_ID); if ($newsPage) { if ($newsPage->active == 0) { throw404(); } } $model = new $this->modelName(); $result = $model->getAllWithPagination(); $this->render('index', array('items' => $result['items'], 'pages' => $result['pages'])); }
public function actionView($id = 0, $url = '') { if ($url && issetModule('seo')) { $seo = SeoFriendlyUrl::getForView($url, $this->modelName); if (!$seo) { throw404(); } $this->setSeo($seo); $id = $seo->model_id; } $model = $this->loadModel($id, 1); $this->render('view', array('model' => $model)); }
function run() { $path = $_SERVER['REQUEST_URI']; $method = $_SERVER['REQUEST_METHOD']; $endpoints = getEndpoints(); if (!array_key_exists($method, $endpoints)) { throw404(); } if (!array_key_exists($path, $endpoints[$method])) { throw404(); } $endpoint = $endpoints[$method][$path]; header('content-type: ' . $endpoint['contentType']); echo $endpoint['body']; }
public function actionView($id = 0, $url = '') { // if(Yii::app()->user->getState('isAdmin')){ // $this->redirect(array('backend/main/view', 'id' => $id)); // } if ($url && issetModule('seo')) { $seo = SeoFriendlyUrl::getForView($url, $this->modelName); if (!$seo) { throw404(); } $this->setSeo($seo); $id = $seo->model_id; } $model = $this->loadModel($id, 1); $this->render('view', array('model' => $model)); }
public function actionView($id = 0, $url = '') { $criteria = new CDbCriteria(); $criteria->order = 'sorter'; $criteria->condition = 'active=1'; $articles = Article::model()->cache(param('cachingTime', 1209600), Article::getCacheDependency())->findAll($criteria); if ($url && issetModule('seo')) { $seo = SeoFriendlyUrl::getForView($url, $this->modelName); if (!$seo) { throw404(); } $this->setSeo($seo); $id = $seo->model_id; } $this->render('view', array('model' => $this->loadModel($id), 'articles' => $articles)); }
public function actionDeleteImg() { $newsId = Yii::app()->request->getParam('id'); $imageId = Yii::app()->request->getParam('imId'); if ($newsId && $imageId) { $newsModel = News::model()->findByPk($newsId); if ($newsModel->image_id != $imageId) { throw404(); } $newsModel->image_id = 0; $newsModel->update('image_id'); $imageModel = NewsImage::model()->findByPk($imageId); $imageModel->delete(); $this->redirect(array('/news/backend/main/update', 'id' => $newsId)); } throw404(); }
public function actionUpdate($id) { $model = $this->loadModel($id); if (!$model) { throw404(); } //Yii::app()->user->setState('menu_active', 'clients.update'); Yii::app()->user->setState('menu_active', 'clients'); $this->performAjaxValidation($model); if (isset($_POST[$this->modelName])) { $model->attributes = $_POST[$this->modelName]; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('update', array('model' => $model)); }
public function actionComplain($isFancy = 0) { $id = Yii::app()->request->getParam('id', 0); if (!$id) { throw404(); } $model = new $this->modelName(); $modelApartment = Apartment::model()->findByPk($id); if (!$modelApartment) { throw404(); } if (isset($_POST[$this->modelName]) && BlockIp::checkAllowIp(Yii::app()->controller->currentUserIpLong)) { $model->attributes = $_POST[$this->modelName]; $model->apartment_id = $id; $model->session_id = Yii::app()->session->sessionId; $model->user_id = 0; $model->user_ip = Yii::app()->controller->currentUserIp; $model->user_ip_ip2_long = Yii::app()->controller->currentUserIpLong; if (!Yii::app()->user->isGuest) { $model->email = Yii::app()->user->email; $model->name = Yii::app()->user->username; $model->user_id = Yii::app()->user->id; } if ($model->validate()) { if ($this->checkAlreadyComplain($model->apartment_id, $model->user_id, $model->session_id)) { if ($model->save(false)) { $notifier = new Notifier(); $notifier->raiseEvent('onNewComplain', $model); Yii::app()->user->setFlash('success', tt('Thanks_for_complain', 'apartmentsComplain')); $model = new $this->modelName(); // clear fields } } else { Yii::app()->user->setFlash('notice', tt('your_already_post_complain', 'apartmentsComplain')); } } } if ($isFancy) { Yii::app()->clientscript->scriptMap['jquery.js'] = false; Yii::app()->clientscript->scriptMap['jquery.min.js'] = false; Yii::app()->clientscript->scriptMap['jquery-ui.min.js'] = false; $this->renderPartial('complain_form', array('model' => $model, 'apId' => $id, 'isFancy' => true, 'modelApartment' => $modelApartment), false, true); } else { $this->render('complain_form', array('model' => $model, 'apId' => $id, 'modelApartment' => $modelApartment, 'wtf' => 'huilo')); } }
public function actionAjaxSave() { if (isset($_POST['SeoFriendlyUrl'])) { $this->canUseDirectUrl = (int) Yii::app()->request->getPost('canUseDirectUrl'); $friendlyUrl = SeoFriendlyUrl::model()->findByPk($_POST['SeoFriendlyUrl']['id']); if (!$friendlyUrl) { $friendlyUrl = new SeoFriendlyUrl(); } $friendlyUrl->attributes = $_POST['SeoFriendlyUrl']; if ($friendlyUrl->save()) { echo CJSON::encode(array('status' => 'ok', 'html' => $this->renderPartial('//modules/seo/views/_form', array('friendlyUrl' => $friendlyUrl), true))); Yii::app()->end(); } else { echo CJSON::encode(array('status' => 'err', 'html' => $this->renderPartial('//modules/seo/views/_form', array('friendlyUrl' => $friendlyUrl), true))); Yii::app()->end(); } } throw404(); }
public function actionView($id = 0, $url = '') { if ($url && issetModule('seo')) { $seo = SeoFriendlyUrl::getForView($url, $this->modelName); if (!$seo) { throw404(); } $this->setSeo($seo); $id = $seo->model_id; } $model = $this->loadModel($id, 1); if (!$model->active) { throw404(); } if (isset($_GET['is_ajax'])) { $this->renderPartial('view', array('model' => $model)); } else { $this->render('view', array('model' => $model)); } }
public function actionWriteComment() { $model = new CommentForm(); if (isset($_POST['CommentForm']) && BlockIp::checkAllowIp(Yii::app()->controller->currentUserIpLong)) { $model->attributes = $_POST['CommentForm']; $model->defineShowRating(); if ($model->validate() && Comment::checkExist(null, $model->modelName, $model->modelId)) { if ($model->modelName == 'News' && !param('enableCommentsForNews', 1) || $model->modelName == 'Apartment' && !param('enableCommentsForApartments', 1) || $model->modelName == 'Menu' && !param('enableCommentsForPages', 0) || $model->modelName == 'Article' && !param('enableCommentsForFaq', 1) || $model->modelName == 'InfoPages' && !param('enableCommentsForPages', 0)) { throw404(); } $comment = new Comment(); $comment->body = $model->body; $comment->parent_id = $model->rel; $comment->user_ip = Yii::app()->controller->currentUserIp; $comment->user_ip_ip2_long = Yii::app()->controller->currentUserIpLong; if ($model->rel == 0) { $comment->rating = $model->rating; } else { $comment->rating = -1; } $comment->model_name = $model->modelName; $comment->model_id = $model->modelId; if (Yii::app()->user->isGuest) { $comment->user_name = $model->user_name; $comment->user_email = $model->user_email; } else { $comment->owner_id = Yii::app()->user->id; } if (param('commentNeedApproval', 1) && !Yii::app()->user->checkAccess('backend_access')) { $comment->status = Comment::STATUS_PENDING; Yii::app()->user->setFlash('success', Yii::t('module_comments', 'Thank you for your comment. Your comment will be posted once it is approved.')); } else { $comment->status = Comment::STATUS_APPROVED; Yii::app()->user->setFlash('success', Yii::t('module_comments', 'Thank you for your comment.')); } $comment->save(false); $this->redirect($model->url); } } $this->render('commentForm', array('model' => $model)); }
public function actionAjaxTranslate() { if (!Yii::app()->request->isAjaxRequest) { throw404(); } $fromLang = Yii::app()->request->getPost('fromLang'); $fields = Yii::app()->request->getPost('fields'); if (!$fromLang || !$fields) { throw new CException('Lang no req data'); } $translate = new GoogleTranslater(); $fromVal = $fields[$fromLang]; $translateField = array(); foreach ($fields as $lang => $val) { if ($lang == $fromLang) { continue; } $translateField[$lang] = $translate->translateText($fromVal, $fromLang, $lang); } echo json_encode(array('result' => 'ok', 'fields' => $translateField)); Yii::app()->end(); }
public function actionView($id = 0, $url = '') { if ($url && issetModule('seo')) { $seo = SeoFriendlyUrl::getForView($url, $this->modelName); if (!$seo) { throw404(); } $this->setSeo($seo); $id = $seo->model_id; } $model = $this->loadModel($id); if ($model) { if (Yii::app()->request->getParam('is_ajax')) { $this->renderPartial('view', array('model' => $model), false, true); } else { $this->render('view', array('model' => $model)); } } else { Yii::app()->user->setFlash('error', tc('Page not found.')); $this->redirect(array('/site/index')); } }
public function run() { if (!$this->criteria) { throw404(); } $this->criteria->order = 't.date_created DESC'; $subCriteria = clone $this->criteria; $subCriteria->select = 'MAX(t.date_updated) as date_updated'; $maxDateUpdated = Apartment::model()->find($subCriteria); $maxDateUpdated = $maxDateUpdated->date_updated; if (!$maxDateUpdated) { $maxDateUpdated = date("r"); } header('Content-type: text/xml'); header('Pragma: public'); header('Cache-control: private'); header('Expires: -1'); $xmlWriter = new XMLWriter(); $xmlWriter->openMemory(); $xmlWriter->setIndent(true); $xmlWriter->startDocument('1.0', 'UTF-8'); $xmlWriter->startElement('rss'); $xmlWriter->writeAttribute('version', '2.0'); $xmlWriter->startElement("channel"); $xmlWriter->writeElement('title', tt('listings_from', 'rss') . ' ' . CHtml::encode(Yii::app()->name)); $xmlWriter->writeElement('link', Yii::app()->getBaseUrl(true)); $xmlWriter->writeElement('description', tt('description_rss_from', 'rss')); $xmlWriter->writeElement('lastBuildDate', $this->getDateFormat(strtotime($maxDateUpdated))); $this->prepareItems($xmlWriter); $xmlWriter->endElement(); // end channel $xmlWriter->endElement(); // end rss echo $xmlWriter->outputMemory(); Yii::app()->end(); }
} else { if (preg_match('/^([a-z]+)\\/([^\\/]+)$/i', $path, $matches) && is_readable('lib/' . $matches[1] . '.php')) { include 'lib/' . $matches[1] . '.php'; } else { if (preg_match('/^([a-z]+)$/i', $path, $matches)) { if (is_readable('pages/' . $matches[1] . '.php')) { include 'pages/' . $matches[1] . '.php'; } else { if (is_readable('pages/' . $matches[1] . '.md')) { include 'lib/page.php'; } else { throw404(); } } } else { throw404(); } } } } /** * Throws a 404 error and displays the 404 page. */ function throw404() { global $tmpl_vars, $twig; header('HTTP/1.0 404 Not Found'); $twig->display('404.twig.html', $tmpl_vars); } /** * Detect whether the request is an AJAX request or not, and marks the request
public function checkOwnerImage($id) { $this->modelName = 'Images'; $model = $this->loadModel($id); if (!$model || !Yii::app()->user->checkAccess('backend_access') && Yii::app()->user->id != $model->id_owner) { throw404(); } return $model; }
public function actionLoadForm() { if (!Yii::app()->request->isAjaxRequest) { throw404(); } $this->objType = Yii::app()->request->getParam('obj_type_id'); $isInner = Yii::app()->request->getParam('is_inner'); $roomsMin = Yii::app()->request->getParam('room_min'); $roomsMax = Yii::app()->request->getParam('room_max'); if ($roomsMin || $roomsMax) { $this->roomsCountMin = $roomsMin; $this->roomsCountMax = $roomsMax; } $this->sApId = (int) Yii::app()->request->getParam('sApId'); $floorMin = Yii::app()->request->getParam('floor_min'); $floorMax = Yii::app()->request->getParam('floor_max'); if ($floorMin || $floorMax) { $this->floorCountMin = $floorMin; $this->floorCountMax = $floorMax; } $floor = Yii::app()->request->getParam('floor'); if ($floor) { $this->floorCount = $floor; } if (issetModule('selecttoslider') && param('useSquareSlider') == 1) { $squareMin = Yii::app()->request->getParam('square_min'); $squareMax = Yii::app()->request->getParam('square_max'); if ($squareMin || $squareMax) { $this->squareCountMin = $squareMin; $this->squareCountMax = $squareMax; } } else { $square = Yii::app()->request->getParam('square'); if ($square) { $this->squareCount = $square; } } if (issetModule('location') && param('useLocation', 1)) { $country = Yii::app()->request->getParam('country'); if ($country) { $this->selectedCountry = $country; } $region = Yii::app()->request->getParam('region'); if ($region) { $this->selectedRegion = $region; } $city = Yii::app()->request->getParam('city'); if ($city) { $this->selectedCity = $city; } } else { $city = Yii::app()->request->getParam('city'); if ($city) { $this->selectedCity = $city; } } $this->objType = Yii::app()->request->getParam('objType'); $this->apType = Yii::app()->request->getParam('apType'); /* if(issetModule('selecttoslider') && param('usePriceSlider') == 1) { $priceMin = Yii::app()->request->getParam("price_min"); $priceMax = Yii::app()->request->getParam("price_max"); if($priceMin || $priceMax) { $this->priceSlider["min"] = $priceMin; $this->priceSlider["max"] = $priceMax; } } else { $price = Yii::app()->request->getParam('price'); if(issetModule('currency')){ $priceDefault = ceil(Currency::convertToDefault($price)); } else { $priceDefault = $price; } if($priceDefault) { $this->price = $price; } }*/ if (issetModule('formeditor')) { $newFieldsAll = FormDesigner::getNewFields(); foreach ($newFieldsAll as $field) { $value = CHtml::encode(Yii::app()->request->getParam($field->field)); if (!$value) { continue; } $fieldString = $field->field; $this->newFields[$fieldString] = $value; } } $compact = Yii::app()->request->getParam('compact', 0); HAjax::jsonOk('', array('html' => $this->renderPartial('//site/_search_form', array('isInner' => $isInner, 'compact' => $compact), true), 'sliderRangeFields' => SearchForm::getSliderRangeFields(), 'cityField' => SearchForm::getCityField(), 'countFiled' => SearchForm::getCountFiled(), 'compact' => $compact)); }