public function actionConfirmation()
 {
     $hash = trim(Yii::app()->request->getParam('hash', null));
     if (!empty($hash) && ($user = User::model()->find('sha(concat(email, "' . Yii::app()->params['salt'] . '")) = :hash', array(':hash' => $hash)))) {
         // Пользователь найден, регистрация окончена
         $user->password_confirm = $user->password;
         $user->status = L::r_item('userStatus', 'active');
         $user->activated = date('Y-m-d H:i:s');
         $user->save();
         if (empty($user->errors)) {
             // добавляю пользователя в RBAC
             $auth = Yii::app()->authManager;
             $auth->assign('user', $user->username);
             $loginForm = new LoginForm();
             $loginForm->username = $user->username;
             $loginForm->password = $user->password;
             $loginForm->login();
             $this->redirect(array('users/view', 'username' => $user->username));
         }
     } elseif (!empty($hash)) {
         Yii::app()->user->setFlash('registration', 'Вы ввели неверный ключ. Попробуйте еще раз.');
     } else {
         Yii::app()->user->setFlash('registration', 'На указанный Вами e-mail было отправленно письмо с кодом подтверждения. Введите его.');
     }
     $this->render('confirmation', array('hash' => $hash));
 }
 public function actionApprove($id)
 {
     if (Yii::app()->request->isPostRequest) {
         // we only allow deletion via POST request
         $model = $this->loadModel($id);
         Comment::model()->updateByPk($id, array('status' => L::r_item('commentStatus', 'approved')));
         $model->updateParentComments();
         // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
         if (!isset($_GET['ajax'])) {
             $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
         }
     } else {
         throw new CHttpException(400, 'Ошибка запроса. Пожалуйста, не повторяйте этот запрос.');
     }
 }
 public function actionIndex()
 {
     $cart = Yii::app()->shoppingCart;
     $model = new OrderForm();
     if (Yii::app()->user->isGuest) {
         $model->scenario = 'guest_order';
     } else {
         $user = User::model()->findByPk(Yii::app()->user->name);
         $model->client = Yii::app()->user->name;
         if (!empty($user->client)) {
             $model->name = $user->client->name;
             $model->phone = $user->client->phone;
             $model->email = $user->client->email;
             $model->city = $user->client->city;
             $model->address = $user->client->address;
         }
     }
     if (isset($_POST['OrderForm'])) {
         $model->attributes = $_POST['OrderForm'];
         if ($model->validate()) {
             $order = new Order();
             $order->attributes = $model->attributes;
             $order->created = date('Y-m-d H:i:s');
             $tmp = array();
             $positions = $cart->getPositions();
             foreach ($positions as $k => $position) {
                 $tmp[] = array('item' => preg_split('/_/', $k), 'price' => $position->getPrice(), 'quantity' => $position->getQuantity());
             }
             $order->order = CJSON::encode($tmp);
             $order->status = L::r_item('orderStatus', 'new');
             $order->data = CJSON::encode($order->attributes);
             if ($order->save()) {
                 Yii::app()->getSession()->add('order', $order);
                 $cart->clear();
                 $this->redirect(array('basket/done'));
             } else {
                 $model->addError('error', 'Мы не можем обработать Ваш заказ.');
             }
         }
     }
     $this->render('index', array('model' => $model, 'cart' => $cart));
 }
Пример #4
0
 /**
  * @return array relational rules.
  */
 public function relations()
 {
     // NOTE: you may need to adjust the relation name and the related
     // class name for the relations automatically generated below.
     return array('model' => array(self::BELONGS_TO, 'Car', 'model_id'), 'characteristic' => array(self::HAS_ONE, 'Characteristic', 'modification_id'), 'comments' => array(self::HAS_MANY, 'Comment', 'object_id', 'condition' => 'comments.type=' . L::r_item('CommentType', __CLASS__)));
 }
Пример #5
0
 /**
  * Функция добавление комментов 
  */
 protected function addComment(&$model)
 {
     if (isset($_POST['CommentForm'])) {
         $commentForm = new CommentForm();
         $commentForm->attributes = $_POST['CommentForm'];
         if ($commentForm->validate()) {
             Yii::app()->user->setState('CommentForm', null);
             $comment = new Comment();
             $comment->attributes = $_POST['CommentForm'];
             $comment->object_type = L::r_item('CommentType', get_class($model));
             $comment->object_id = $model->id;
             $comment->created = date('Y-m-d H:i:s');
             $comment->rating = 0;
             $comment->status = L::r_item('commentStatus', 'new');
             if ($parent = Comment::model()->findbyPk((int) $commentForm->parent)) {
                 $parent->append($comment);
             } else {
                 $comment->saveNode();
             }
             Yii::app()->user->setFlash('comment', array('text' => 'Спасибо за Ваш комментарий', 'class' => 'error'));
             $this->redirect(Yii::app()->request->requestUri . '#comment-' . $comment->id);
         } else {
             Yii::app()->user->setState('CommentForm', $commentForm);
         }
     } else {
         Yii::app()->user->setState('CommentForm', null);
     }
 }
 private function showTyresByModel($alias, $season = null, $stud = null)
 {
     $criteria = new CDbCriteria();
     $criteria->condition = 'tyre.alias = :alias';
     $criteria->params = array(':alias' => $alias);
     if (!($model = Tyre::model()->find('alias = :alias', array(':alias' => $alias)))) {
         throw new CHttpException(400, 'Такой страницы нет');
     }
     // Сезонность
     if ($season && L::r_item('tyreSeason', $season)) {
         $criteria->addCondition('tyre.season = ' . L::r_item('tyreSeason', $season));
     }
     // Шипованность
     if ($stud == 'studded') {
         $criteria->addCondition('tyre.stud = 1');
     }
     if ($stud == 'not_studded') {
         $criteria->addCondition('tyre.stud = 0');
     }
     $criteria->addCondition('t.rest <> "0"');
     $criteria->with = array('tyre');
     $dataProvider = new CActiveDataProvider('TyreSizes', array('criteria' => $criteria));
     $this->addComment($model);
     $this->render('tyres/sizes', array('dataProvider' => $dataProvider, 'season' => $season, 'stud' => $stud, 'model' => $model));
 }
 /**
  * Declares the validation rules.
  * The rules state that username and password are required,
  * and password needs to be authenticated.
  */
 public function rules()
 {
     return array(array('username, password, password_confirm, email, name, phone, city, address', 'required'), array('username', 'unique', 'className' => 'User', 'attributeName' => 'username', 'criteria' => array('condition' => 'status != ' . L::r_item('userStatus', 'not_active'))), array('password', 'compare', 'compareAttribute' => 'password_confirm'), array('email', 'email'), array('verifyCode', 'captcha', 'allowEmpty' => !extension_loaded('gd'), 'captchaAction' => Yii::app()->params['captchaAction']));
 }
 public function actionNomenclature()
 {
     ini_set('memory_limit', '650M');
     set_time_limit(0);
     $tyresForm = new ImportForm();
     $result = array();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['ImportForm'])) {
         $tyresForm->attributes = $_POST['ImportForm'];
         if ($tyresForm->validate()) {
             # Вот тут начинается импорт
             Yii::import('ext.markdown.*');
             Yii::import('ext.markdownify.*');
             Yii::import('webroot.helpers.*');
             #$tyresForm->file = CUploadedFile::getInstance($tyresForm, 'file');
             /* Первая страница
              * 1. CAI
              * 2. Производитель
              * 3. Модель
              * 4. Сезон
              * 5. Применяемость
              * 6. Тип протектора
              * 7. Шипованность
              * 8. Ширина профиля(мм)
              * 9. Высота профиля (%)
              * 10. Диаметр (,R)
              * 11. Индекс скорости
              * 12. Индекс нагрузки
              * 13. Цена
              * 14. Фото, большое
              * 15. Фото, мелкое
             */
             $uploaded = Yii::app()->file->set('ImportForm[file]');
             Yii::app()->file->set(Yii::getPathOfAlias('webroot.files.' . $this->id . '.' . $this->action->id))->createDir();
             $newfile = $uploaded->copy(strtolower(Yii::getPathOfAlias('webroot.files.' . $this->id . '.' . $this->action->id)) . '/' . $uploaded->basename);
             $newfile->filename = $newfile->filename . '.' . date('YmdHis');
             Yii::import('ext.phpexcelreader.EPhpExcelReader');
             $data = new EPhpExcelReader($newfile->realpath, false);
             $rowcount = $data->rowcount();
             #$colcount = $data->colcount();
             #$rowcount = 3;
             $r = 2;
             while ($r <= $rowcount) {
                 $producer_alias = EString::strtolower(EString::sanitize($data->val($r, 2)));
                 if (!($producer = TyreProducers::model()->find('alias=:alias', array(':alias' => $producer_alias)))) {
                     $producer = new TyreProducers();
                     @($result['new_producers'] += 1);
                 } else {
                     @($result['old_producers'] += 1);
                 }
                 $producer->title = $data->val($r, 2);
                 $producer->alias = $producer_alias;
                 if (!$producer->save()) {
                     $result['errors']['producer:' . $data->val($r, 1)] = $producer->errors;
                 }
                 $tyre_alias = EString::strtolower(EString::sanitize($data->val($r, 3)));
                 if (!($tyre = Tyre::model()->find('alias=:alias', array(':alias' => $tyre_alias)))) {
                     $tyre = new Tyre();
                     @($result['new_tyres'] += 1);
                 } else {
                     @($result['old_tyres'] += 1);
                 }
                 $tyre->producer_id = $producer->id;
                 $tyre->title = $data->val($r, 3);
                 $tyre->alias = $tyre_alias;
                 $tyre->new = true;
                 $tyre->currency = L::r_item('tyreCurrency', $data->val($r, 5)) ? L::r_item('tyreCurrency', $data->val($r, 5)) : 0;
                 if ($data->val($r, 4) == 'зимние') {
                     $tyre->season = L::r_item('tyreSeason', 'winter');
                 }
                 if ($data->val($r, 4) == 'летние') {
                     $tyre->season = L::r_item('tyreSeason', 'summer');
                 }
                 if ($data->val($r, 4) == 'всесезонные') {
                     $tyre->season = L::r_item('tyreSeason', 'yearround');
                 }
                 $tyre->stud = $data->val($r, 7) ? 1 : 0;
                 $tyre->construction_type = 1;
                 $tyre->runflat_type = 0;
                 // загрузка картинок...
                 $alias = EString::sanitize($producer_alias . '_' . $tyre_alias);
                 $path0 = Yii::getPathOfAlias('webroot.files.' . EString::strtolower('Tyre') . '.' . 'photo') . DIRECTORY_SEPARATOR;
                 $f = false;
                 $tmp_image = str_replace('.jpg', '.png', $data->val($r, 14));
                 if (!empty($tmp_image) && empty($tyre->photo)) {
                     #d($tmp_image);
                     #d($tyre->photo);
                     foreach (Tyre::model()->images['photo']['sizes'] as $key => $size) {
                         $pic = null;
                         // папка в которой будет хранится картинка
                         $path = $path0 . $key . DIRECTORY_SEPARATOR;
                         // создаю папку если ее не было
                         EFile::set($path)->createDir();
                         $pic = @file_get_contents('http://www.4tochki.ru' . $tmp_image);
                         $info = pathinfo($tmp_image);
                         #$row['pic_file'] - 117*(65-88) (лента слева)
                         if (empty($pic)) {
                             continue;
                         }
                         $fullpath = $path . $alias . '.jpg';
                         file_put_contents($fullpath, $pic);
                         $pic = Yii::app()->image->load($fullpath);
                         $pic->thumb(isset($size[0]) ? $size[0] : 0, isset($size[1]) ? $size[1] : 0, true, '#FFFFFF');
                         if ($key == 'big') {
                             $pic->watermark(Yii::getPathOfAlias('webroot') . Yii::app()->params['watermark'], 5);
                         }
                         $pic->save($fullpath);
                         $f = true;
                     }
                     if ($f) {
                         if (!($image = Image::model()->find('filename=:alias', array(':alias' => '/files/tyre/photo/::size::/' . $alias . '.jpg')))) {
                             $image = new Image();
                         }
                         $image->created = date('Y-m-d H:i:s', strtotime($row['add_date']));
                         $image->filename = '/files/tyre/photo/::size::/' . $alias . '.jpg';
                         $image->title = $producer->title . ' ' . $tyre->title;
                         $image->alt = $producer->title . ' ' . $tyre->title;
                         $image->save();
                         $tyre->photo = '/files/tyre/photo/::size::/' . $alias . '.jpg';
                     } else {
                         $tyre->photo = null;
                     }
                 }
                 if (!$tyre->save()) {
                     $result['errors']['tyre:' . $data->val($r, 1)] = $tyre->errors;
                 }
                 $cai = $data->val($r, 1);
                 if (!($size = TyreSizes::model()->find('code=:code', array(':code' => $cai)))) {
                     $size = new TyreSizes();
                     $size->alias = uniqid();
                     $size->save(false);
                     @($result['new_size'] += 1);
                 } else {
                     @($result['old_size'] += 1);
                 }
                 $size->tyre_id = $tyre->id;
                 $size->code = $cai;
                 $size->width = $data->val($r, 8);
                 $size->height = $data->val($r, 9);
                 $size->diameter = $data->val($r, 10);
                 $size->speed_rating = preg_replace('/[0-9]/isU', '', $data->val($r, 11));
                 $size->load_index = preg_replace('/[a-z]/isU', '', $data->val($r, 12));
                 $size->price = 0;
                 $size->rest = 0;
                 #d($size->attributes);
                 $size->alias = $size->id . '-' . $size->width . '-' . $size->height . '-' . $size->diameter . '-' . $size->speed_rating . $size->load_index;
                 # Сохраняю...
                 if (!$size->save()) {
                     $result['errors']['size:' . $data->val($r, 1)] = $size->errors;
                 }
                 $r++;
             }
             #$this->redirect(array('view','id'=>$model->id));
         }
     }
     $this->render('nomenclature', array('model' => $tyresForm, 'results' => $result));
 }
Пример #9
0
 /**
  * @return array relational rules.
  */
 public function relations()
 {
     // NOTE: you may need to adjust the relation name and the related
     // class name for the relations automatically generated below.
     return array('comments' => array(self::HAS_MANY, 'Comment', 'object_id', 'condition' => 'comments.status != ' . L::r_item('commentStatus', 'blocked') . ' and comments.object_type=' . L::r_item('CommentType', __CLASS__), 'together' => false, 'order' => 'comments.root, comments.lft'));
 }
 public function actionNomenclature()
 {
     ini_set('memory_limit', '650M');
     set_time_limit(0);
     $tyresForm = new ImportForm();
     $result = array();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['ImportForm'])) {
         $tyresForm->attributes = $_POST['ImportForm'];
         if ($tyresForm->validate()) {
             # Вот тут начинается импорт
             $uploaded = Yii::app()->file->set('ImportForm[file]');
             Yii::app()->file->set(Yii::getPathOfAlias('webroot.files.' . $this->id . '.' . $this->action->id))->createDir();
             $newfile = $uploaded->copy(strtolower(Yii::getPathOfAlias('webroot.files.' . $this->id . '.' . $this->action->id)) . '/' . $uploaded->basename);
             $newfile->filename = $newfile->filename . '.' . date('YmdHis');
             Yii::import('ext.phpexcelreader.EPhpExcelReader');
             $data = new EPhpExcelReader($newfile->realpath, false);
             $sheet = 1;
             $rowcount = $data->rowcount($sheet);
             #$colcount = $data->colcount();
             #$rowcount = 10;
             $r = 2;
             while ($r <= $rowcount) {
                 $cai = $data->val($r, 1);
                 if (empty($cai)) {
                     $r++;
                     continue;
                 }
                 $producer_alias = EString::strtolower(EString::sanitize($data->val($r, 2)));
                 if (!($producer = DiskProducers::model()->find('alias=:alias', array(':alias' => $producer_alias)))) {
                     $producer = new DiskProducers();
                     @($result['new_producers'] += 1);
                 } else {
                     @($result['old_producers'] += 1);
                 }
                 $producer->title = $data->val($r, 2);
                 $producer->alias = $producer_alias;
                 if (!$producer->save()) {
                     $result['errors']['producer:' . $data->val($r, 1)] = $producer->errors;
                 }
                 $disk_alias = EString::strtolower(EString::sanitize($data->val($r, 3)));
                 if (!($disk = Disk::model()->find('alias=:alias', array(':alias' => $disk_alias)))) {
                     $disk = new Disk();
                     @($result['new_disks'] += 1);
                 } else {
                     @($result['old_disks'] += 1);
                 }
                 $disk->producer_id = $producer->id;
                 $disk->title = $data->val($r, 3);
                 $disk->alias = $disk_alias;
                 $disk->color = 1;
                 $disk->construction_type = L::r_item('diskConstructionType', 'alloy');
                 if ($data->val($r, 5)) {
                     $disk->construction_type = L::r_item('diskConstructionType', 'forged');
                 }
                 /*
                 if($data->val($r, 4) && $data->val($r,5))
                 	$disk->construction_type = L::r_item('diskConstructionType', 'scratched');
                 if(!($data->val($r, 4)) && !($data->val($r,5)) ))
                 	$disk->construction_type = L::r_item('diskConstructionType', 'stamped');
                 */
                 // загрузка картинок...
                 $alias = EString::sanitize($producer_alias . '_' . $disk_alias);
                 $path0 = Yii::getPathOfAlias('webroot.files.' . EString::strtolower('Disk') . '.' . 'photo') . DIRECTORY_SEPARATOR;
                 $f = false;
                 $tmp_image = str_replace('.jpg', '.png', $data->val($r, 12));
                 if (!empty($tmp_image) && empty($disk->photo)) {
                     #d($tmp_image);
                     #d($tyre->photo);
                     foreach (Disk::model()->images['photo']['sizes'] as $key => $size) {
                         $pic = null;
                         // папка в которой будет хранится картинка
                         $path = $path0 . $key . DIRECTORY_SEPARATOR;
                         // создаю папку если ее не было
                         EFile::set($path)->createDir();
                         $pic = @file_get_contents('http://www.4tochki.ru' . $tmp_image);
                         $info = pathinfo($tmp_image);
                         #$row['pic_file'] - 117*(65-88) (лента слева)
                         if (empty($pic)) {
                             continue;
                         }
                         $fullpath = $path . $alias . '.jpg';
                         file_put_contents($fullpath, $pic);
                         $pic = Yii::app()->image->load($fullpath);
                         $pic->thumb(isset($size[0]) ? $size[0] : 0, isset($size[1]) ? $size[1] : 0, true, '#FFFFFF');
                         if ($key == 'big') {
                             $pic->watermark(Yii::getPathOfAlias('webroot') . Yii::app()->params['watermark'], 5);
                         }
                         $pic->save($fullpath);
                         $f = true;
                     }
                     if ($f) {
                         if (!($image = Image::model()->find('filename=:alias', array(':alias' => '/files/disk/photo/::size::/' . $alias . '.jpg')))) {
                             $image = new Image();
                         }
                         $image->created = date('Y-m-d H:i:s', strtotime($row['add_date']));
                         $image->filename = '/files/disk/photo/::size::/' . $alias . '.jpg';
                         $image->title = $producer->title . ' ' . $disk->title;
                         $image->alt = $producer->title . ' ' . $disk->title;
                         $image->save();
                         $disk->photo = '/files/disk/photo/::size::/' . $alias . '.jpg';
                     } else {
                         $disk->photo = null;
                     }
                 }
                 if (!$disk->save()) {
                     $result['errors']['disk:' . $data->val($r, 1)] = $disk->errors;
                 }
                 if (!($size = DiskSizes::model()->find('code=:code', array(':code' => $cai)))) {
                     $size = new DiskSizes();
                     $size->alias = uniqid();
                     $size->save(false);
                     @($result['new_size'] += 1);
                 } else {
                     @($result['old_size'] += 1);
                 }
                 $size->disk_id = $disk->id;
                 $size->code = $cai;
                 /*
                  * 1. cae	
                  * 2. producer.name
                  * 3. model.name
                  * 4. lit
                  * 5. kov
                  * 6. sh
                  * 7. d	
                  * 8. pcd
                  * 9. pcd2
                  * 10.vil
                  * 11.dia
                  */
                 $width_fl_point = preg_replace("/,/", ".", $data->val($r, 6));
                 $width_c = floatval(preg_replace("/^[^0-9\\.]/", "", $width_fl_point));
                 $size->width = $width_c;
                 $size->diameter = $data->val($r, 7);
                 $ET_fl_point = preg_replace("/,/", ".", $data->val($r, 10));
                 $ET_c = floatval(preg_replace("/^[^0-9\\.\\-]/", "", $ET_fl_point));
                 $size->ET = floatval($ET_c);
                 list($size->PCD_screws, $PCD_diameter_fl_point) = preg_split('/[^\\d,\\.]+/i', $data->val($r, 8));
                 $PCD_diameter_fl_point = preg_replace("/,/", ".", $PCD_diameter_fl_point);
                 $PCD_diameter_c = floatval(preg_replace("/^[^0-9\\.]/", "", $PCD_diameter_fl_point));
                 $size->PCD_diameter = $PCD_diameter_c;
                 $DIA_fl_point = preg_replace("/,/", ".", $data->val($r, 11));
                 $DIA_c = floatval(preg_replace("/^[^0-9\\.]/", "", $DIA_fl_point));
                 $size->DIA = $DIA_c;
                 $size->price = 0;
                 $size->rest = 0;
                 $size->alias = $size->id . '-' . $size->width . '-' . $size->diameter . '-' . $size->PCD_screws . '-' . $size->PCD_diameter . '-ET' . $size->ET . '-' . $size->DIA;
                 if (!$size->save()) {
                     $size->delete();
                     $result['errors']['size:' . $data->val($r, 1)] = $size->errors;
                 }
                 $r++;
             }
             #$this->redirect(array('view','id'=>$model->id));
         }
     }
     $this->render('nomenclature', array('model' => $tyresForm, 'results' => $result));
 }
Пример #11
0
 /**
  * @return array of scopes
  */
 public function scopes()
 {
     $db = $this->getDbConnection();
     $alias = $db->quoteColumnName($this->getTableAlias());
     return array('approved' => array('condition' => $alias . '.status=' . L::r_item('CommentStatus', 'approved')), 'notblocked' => array('condition' => $alias . '.status!=' . L::r_item('CommentStatus', 'blocked')), 'recently' => array('order' => $alias . '.created DESC'));
 }
Пример #12
0
 /**
  * @return array relational rules.
  */
 public function relations()
 {
     // NOTE: you may need to adjust the relation name and the related
     // class name for the relations automatically generated below.
     return array('producer' => array(self::BELONGS_TO, 'DiskProducers', 'producer_id'), 'sizes' => array(self::HAS_MANY, 'DiskSizes', 'disk_id', 'joinType' => 'inner join'), 'model' => array(self::BELONGS_TO, 'Car', 'model_id'), 'comments' => array(self::HAS_MANY, 'Comment', 'object_id', 'condition' => 'comments.status != ' . L::r_item('commentStatus', 'blocked') . ' and comments.object_type=' . L::r_item('CommentType', __CLASS__), 'together' => false, 'order' => 'comments.root, comments.lft'));
 }