diff --git a/protected/components/Controller.php b/protected/components/Controller.php index 0fc80b3..685bbda 100644 --- a/protected/components/Controller.php +++ b/protected/components/Controller.php @@ -220,5 +220,77 @@ public function logFromEmailActivity($type) } return $result; } + + protected function getInputAsJson() + { + return CJSON::decode(file_get_contents('php://input')); + } + + /** + * Send raw HTTP response + * @param int $status HTTP status code + * @param string $body The body of the HTTP response + * @param string $contentType Header content-type + * @return HTTP response + */ + protected function sendResponse($status = 200, $body = '', $contentType = 'application/json') + { + // Set the status + $statusHeader = 'HTTP/1.1 ' . $status . ' ' . $this->getStatusCodeMessage($status); + header($statusHeader); + // Set the content type + header('Content-type: ' . $contentType); + + echo $body; + Yii::app()->end(); + } + + protected function getStatusCodeMessage($status) + { + $codes = array( + 100 => 'Continue', + 101 => 'Switching Protocols', + 200 => 'OK', + 201 => 'Created', + 202 => 'Accepted', + 203 => 'Non-Authoritative Information', + 204 => 'No Content', + 205 => 'Reset Content', + 206 => 'Partial Content', + 300 => 'Multiple Choices', + 301 => 'Moved Permanently', + 302 => 'Found', + 303 => 'See Other', + 304 => 'Not Modified', + 305 => 'Use Proxy', + 306 => '(Unused)', + 307 => 'Temporary Redirect', + 400 => 'Bad Request', + 401 => 'Unauthorized', + 402 => 'Payment Required', + 403 => 'Forbidden', + 404 => 'Not Found', + 405 => 'Method Not Allowed', + 406 => 'Not Acceptable', + 407 => 'Proxy Authentication Required', + 408 => 'Request Timeout', + 409 => 'Conflict', + 410 => 'Gone', + 411 => 'Length Required', + 412 => 'Precondition Failed', + 413 => 'Request Entity Too Large', + 414 => 'Request-URI Too Long', + 415 => 'Unsupported Media Type', + 416 => 'Requested Range Not Satisfiable', + 417 => 'Expectation Failed', + 500 => 'Internal Server Error', + 501 => 'Not Implemented', + 502 => 'Bad Gateway', + 503 => 'Service Unavailable', + 504 => 'Gateway Timeout', + 505 => 'HTTP Version Not Supported', + ); + return (isset($codes[$status])) ? $codes[$status] : ''; + } } \ No newline at end of file diff --git a/protected/config/main.php b/protected/config/main.php index 968933d..29c0c2f 100644 --- a/protected/config/main.php +++ b/protected/config/main.php @@ -15,13 +15,9 @@ 'application.extensions.sweekit.Sweeml', 'application.extensions.MobileDetect.Mobile_Detect', 'application.extensions.calc.eqEOS', - 'ext.eoauth.*', - 'ext.eoauth.lib.*', - 'ext.lightopenid.*', - 'ext.eauth.*', - 'ext.eauth.services.*', 'application.vendors', 'ext.yii-mail.YiiMailMessage', + 'ext.imperavi-redactor-widget.ImperaviRedactorWidget', ), 'modules' => array( 'gii' => array( @@ -35,9 +31,6 @@ 'admin' => array( 'defaultController' =>'user', ), - 'exel' => array( - 'defaultController' =>'index', - ), 'mailingList'=>array( 'defaultController'=>'email', ), @@ -68,12 +61,12 @@ ), //'session' => array( //'timeout' => 86400, - //), + //), 'request' => array( 'class' => 'HttpRequest', 'enableCsrfValidation' => true, 'enableCookieValidation' => true, - 'noCsrfValidationRoutes' => array('admin/item', 'register/SaveComment'), ///, 'logg/History' + 'noCsrfValidationRoutes' => array('admin/item', 'register/SaveComment','site/modal','site/Getmenu'), ///, 'logg/History' ), 'languageManager' => array( 'class' => 'DbLanguageManager', @@ -158,9 +151,6 @@ 'class' => 'ext.image.ImageComponent', 'driver' => 'Gd', ), - 'loid' => array( - 'class' => 'ext.lightopenid.loid', - ), 'mail' => array( 'class' => 'ext.yii-mail.YiiMail', 'transportType' => 'php', @@ -168,94 +158,6 @@ 'logging' => false, 'dryRun' => false ), - 'eauth' => array( - 'class' => 'ext.eauth.EAuth', - 'popup' => true, // Use the popup window instead of redirecting. - 'cache' => false, // Cache component name or false to disable cache. Defaults to 'cache'. - 'cacheExpire' => 0, // Cache lifetime. Defaults to 0 - means unlimited. - 'services' => array(// You can change the providers and their classes. -// 'google' => array( -// 'class' => 'GoogleOpenIDService', -// ), -// 'yandex' => array( -// 'class' => 'YandexOpenIDService', -// ), -// 'twitter' => array( - // register your app here: https://dev.twitter.com/apps/new -// 'class' => 'TwitterOAuthService', -// 'key' => '...', -// 'secret' => '...', -// ), - 'google_oauth' => array( - // register your app here: https://code.google.com/apis/console/ - 'class' => 'CustomGoogleService', - 'client_id' => '121482514649-7orl2mum6mco54pe33rvl743j9bp2353.apps.googleusercontent.com', - 'client_secret' => 's19p91oTKTLJvvMKGVEi_kebs', - 'title' => 'Google (OAuth)', - ), -// 'yandex_oauth' => array( - // register your app here: https://oauth.yandex.ru/client/my -// 'class' => 'YandexOAuthService', -// 'client_id' => '...', -// 'client_secret' => '...', -// 'title' => 'Yandex (OAuth)', -// ), - 'facebook' => array( - // register your app here: https://developers.facebook.com/apps/ - 'class' => 'CustomFacebookService', - 'client_id' => '689556884392541', - 'client_secret' => '5af00ac919412ac2dcaa416e29adeec3', - ), -// 'linkedin' => array( - // register your app here: https://www.linkedin.com/secure/developer -// 'class' => 'LinkedinOAuthService', -// 'key' => '...', -// 'secret' => '...', -// ), -// 'github' => array( - // register your app here: https://github.com/settings/applications -// 'class' => 'GitHubOAuthService', -// 'client_id' => '...', -// 'client_secret' => '...', -// ), -// 'live' => array( - // register your app here: https://manage.dev.live.com/Applications/Index -// 'class' => 'LiveOAuthService', -// 'client_id' => '...', -// 'client_secret' => '...', -// ), - 'vkontakte' => array( - // register your app here: https://vk.com/editapp?act=create&site=1 - 'class' => 'CustomVKontakteService', - 'client_id' => '3792586', - 'client_secret' => 'VY2T0rp0SMkHtyRmrTSJ', - ), -// 'mailru' => array( - // register your app here: http://api.mail.ru/sites/my/add -// 'class' => 'MailruOAuthService', -// 'client_id' => '...', -// 'client_secret' => '...', -// ), -// 'moikrug' => array( - // register your app here: https://oauth.yandex.ru/client/my -// 'class' => 'MoikrugOAuthService', -// 'client_id' => '...', -// 'client_secret' => '...', -// ), -// 'odnoklassniki' => array( - // register your app here: http://dev.odnoklassniki.ru/wiki/pages/viewpage.action?pageId=13992188 - // ... or here: http://www.odnoklassniki.ru/dk?st.cmd=appsInfoMyDevList&st._aid=Apps_Info_MyDev -// 'class' => 'OdnoklassnikiOAuthService', -// 'client_id' => '...', -// 'client_public' => '...', -// 'client_secret' => '...', -// 'title' => 'Odnokl.', -// ), - ), - ), - 'excel'=>array( - 'class'=>'application.extensions.PHPExcel', - ), ), 'params' => array( 'adminEmail' => 'dobrynina@astrafit.com', diff --git a/protected/controllers/SiteController.php b/protected/controllers/SiteController.php index ff92cad..a517dd1 100644 --- a/protected/controllers/SiteController.php +++ b/protected/controllers/SiteController.php @@ -13,7 +13,7 @@ public function accessRules() { return array( array('allow', 'roles' => array('client','superadmin','admin'), - 'actions' => array('myData'), + 'actions' => array('myData','modal'), ), array('deny', 'roles' => array('guest'), @@ -218,9 +218,26 @@ public function actionError() { $this->render('error', $error); } } - public static function Logging() { -// $this->actionLogin(); + + public function actionModal() { + $data = $this->getInputAsJson(); + $model = new Joinus(); + if(empty($data['name']) || empty($data['email'])) + { + $this->sendResponse(401, 'There was an error while sending data'); + } else { + $model->attributes = $data; + if($model->validate()) { + $model->save(); + $this->sendResponse(200, 'Email was sended successfull'); + } + } + } + + public function actionGetmenu() { + echo json_encode(Pages::getPages()); } + public function actionLogin() { $this->layout = '//layouts/main-temp'; $model = new User('login'); diff --git a/protected/models/JoinUs.php b/protected/models/JoinUs.php new file mode 100644 index 0000000..e45af97 --- /dev/null +++ b/protected/models/JoinUs.php @@ -0,0 +1,90 @@ + Yii::t('page', 'Ваше имя'), + 'company' => Yii::t('page', 'Название компании'), + 'url' => Yii::t('page', 'Ссылка на сайт магазина'), + 'phone' => Yii::t('page', 'Телефон для обратной связи'), + 'email'=> Yii::t('page', 'Емейл'), + 'text'=>Yii::t('page', 'Коментарии'), + ); + } + + public function scopes() { + return array( + 'notBlocked' => array( + 'condition' => 'is_blocked=0', + ), + ); + } + + public function getPages() { + return self::model()->findAll(); + } + + public function rules() { + return array( + array('name', 'required', 'on' => 'insert,update'), + array('company', 'required', 'on' => 'insert,update'), + array('email', 'required', 'on' => 'insert,update'), + array('url', 'required', 'on' => 'insert,update'), + array('name,company,url,phone,email,text', 'safe', 'on' => 'search,insert,update'), + ); + //$charset = Yii::app()->charset; + } + + public function getId() { + return $this->_id; + } + + public function getName() { + return $this->name; + } + + public function getCompany() { + return $this->company; + } + + public function getUrl() { + return $this->url; + } + + public function getPhone() { + return $this->phone; + } + + public function getEmail() { + return $this->email; + } + + public function getText() { + return $this->text; + } + +} diff --git a/protected/models/Page.php b/protected/models/Page.php new file mode 100644 index 0000000..24c8f1a --- /dev/null +++ b/protected/models/Page.php @@ -0,0 +1,91 @@ + Yii::t('page', 'Имя'), + 'info' => Yii::t('page', 'Информация'), + 'body' => Yii::t('page', 'Контент'), + 'weight' => Yii::t('page', 'Позиция'), + 'pages_id'=> Yii::t('page', 'Где отображать'), + 'create_time'=>Yii::t('page', 'Дата создания'), + ); + } + + public function scopes() { + return array( + 'notBlocked' => array( + 'condition' => 'is_blocked=0', + ), + ); + } + + public function getPages() { + return self::model()->findAll(); + } + + public function rules() { + return array( + array('title', 'required', 'on' => 'insert,update'), + array('info', 'required', 'on' => 'insert,update'), + //array('pages_id', 'required', 'on' => 'insert,update'), + array('weight', 'required', 'on' => 'insert,update'), + array('body', 'required', 'on' => 'insert,update'), + array('name,info,body,weight', 'safe', 'on' => 'search,insert,update'), + ); + //$charset = Yii::app()->charset; + } + + public function getId() { + return $this->_id; + } + + public function getName() { + return $this->name; + } + + public function getIsBlocked() { + return $this->is_blocked; + } + + public function getInfo() { + return $this->info; + } + + public function getWeight() { + return $this->weight; + } + + public function getBody() { + return $this->body; + } + + public function getPagesId() { + return $this->pages_id; + } + +} diff --git a/protected/models/Pages.php b/protected/models/Pages.php new file mode 100644 index 0000000..52fad4c --- /dev/null +++ b/protected/models/Pages.php @@ -0,0 +1,72 @@ + Yii::t('pages', 'Имя'), + 'info' => Yii::t('pages', 'Информация'), + 'weight' => Yii::t('pages', 'Позиция'), + ); + } + + public function scopes() { + return array( + 'notBlocked' => array( + 'condition' => 'is_blocked=0', + ), + ); + } + + public static function getPages() { + $connection=Yii::app()->db; + $sql = 'SELECT * FROM pages'; + return $connection->createCommand($sql)->queryAll(); + } + + public function rules() { + return array( + array('name', 'required', 'on' => 'insert,update'), + array('info', 'required', 'on' => 'insert,update'), + array('name,info,weight', 'safe', 'on' => 'search,insert,update'), + ); + //$charset = Yii::app()->charset; + } + + public function getName() { + return $this->name; + } + + public function getIsBlocked() { + return $this->is_blocked; + } + + public function getInfo() { + return $this->info; + } + + public function getWeight() { + return $this->weight; + } + + +} diff --git a/protected/modules/admin/controllers/PagesController.php b/protected/modules/admin/controllers/PagesController.php new file mode 100644 index 0000000..5264192 --- /dev/null +++ b/protected/modules/admin/controllers/PagesController.php @@ -0,0 +1,117 @@ + array( + 'class' => 'application.modules.admin.components.actions.BlockAction', + 'modelClass' => 'Pages', + 'message_block' => Yii::t('infoMessages', 'Страница разблокирован!'), + 'errorMessage_block' => Yii::t('infoMessages', 'Произошла ошибка при разблокировании страницы!'), + 'message_unBlock' => Yii::t('infoMessages', 'Страница заблокирован!'), + 'errorMessage_unBlock' => Yii::t('infoMessages', 'Произошла ошибка при блокировании страницы!'), + ), + 'markAsDeleted' => array( + 'class' => 'application.modules.admin.components.actions.MarkAsDeletedAction', + 'modelClass' => 'Pages', + 'message_mark' => Yii::t('infoMessages', 'Страница удалена!'), + 'errorMessage_mark' => Yii::t('infoMessages', 'Произошла ошибка при удалении страницы!'), + ) + ); + } + + public function actionIndex() { + $search = new Pages('search'); + $search->unsetAttributes(); + + if (!is_null(Yii::app()->request->getQuery('Pages'))) + $search->attributes = Yii::app()->request->getQuery('Pages'); + + $criteria = new CDbCriteria; + $criteria->compare('t.name', $search->name, true); + $criteria->compare('t.is_blocked', array('0' => 0, '1' => 1)); + + $dataProvider = new ActiveDataProvider('Pages', array( + 'criteria' => $criteria, + 'sort' => array( + 'defaultOrder' => array('weight' => true), + 'sortVar' => 'sort', + ), + 'pagination' => array( + 'pageVar' => 'page', + 'sizeVar' => 'size', + 'pageSize' => Yii::app()->params['defaultPageSize'], + 'sizeOptions' => Yii::app()->params['sizeOptions'], + ), + )); + $this->render('index', + array('dataProvider'=>$dataProvider,'search'=>$search) + ); + } + + public function actionCreate() { + $model = new Pages; + + if (!is_null(Yii::app()->request->getPost('ajax')) && Yii::app()->request->getPost('ajax') === 'create-user-form') + $this->performAjaxValidation($model); + + if (!is_null(Yii::app()->request->getPost('Pages'))) { + $model->attributes = Yii::app()->request->getPost('Pages'); + $model->is_blocked = 0; + if(!$model->weight) + $model->weight = 1; + //var_dump($model);die; + if ($model->save()) { + //save client role for user + $this->setFlashSuccess(Yii::t('infoMessages', 'Новая страница добавлена!')); + $this->redirect(array('index')); + } + } + + $this->render('create', array( + 'model' => $model + )); + } + + public function actionUpdate() { + $model = $this->loadModel(); + + if (!is_null(Yii::app()->request->getPost('ajax')) && Yii::app()->request->getPost('ajax') === 'update-user-form') { + $this->performAjaxValidation($model); + } + + if ($model === null) + throw new CHttpException(404); + + if (!is_null(Yii::app()->request->getPost('Pages'))) { + $model->attributes = Yii::app()->request->getPost('Pages'); + + if ($model->save()) { + $this->setFlashSuccess(Yii::t('infoMessages', 'Данные обновлены!')); + $this->redirect(array('index')); + } + } + + $this->render('update', array( + 'model' => $model, + 'uid' => $model->id + )); + } +} diff --git a/protected/modules/admin/views/layouts/main.php b/protected/modules/admin/views/layouts/main.php index 3d81f51..f52d2ba 100644 --- a/protected/modules/admin/views/layouts/main.php +++ b/protected/modules/admin/views/layouts/main.php @@ -58,8 +58,15 @@ -
  • - +
  • + +