Exemple #1
0
 public function actionCreate()
 {
     IsAuth::Admin();
     $model = new Proposal();
     if (isset($_POST['Proposal'])) {
         $model->attributes = $_POST['Proposal'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->ID_PROPOSAL));
         }
     }
     $this->render('create', array('model' => $model));
 }
 public function addorderformAction()
 {
     $this->view->disable();
     if ($this->security->checkToken()) {
         ///  $this->elements->var_print($_POST);
         function valid_order()
         {
             $sub_mess = '';
             if (!isset($_POST['name-tex']) || strlen($_POST['name-tex']) < 3) {
                 $sub_mess['name-tex'] = "Не корректно заполнено поле Модель !";
             }
             if (!isset($_POST['city-tex']) || strlen($_POST['city-tex']) < 3) {
                 $sub_mess['city-tex'] = "Не корректно заполнено поле Город !";
             }
             if (!isset($_POST['price-tex']) || strlen($_POST['city-tex']) < 3) {
                 $sub_mess['price-tex'] = "Не заполнено поле Цена !";
             }
             if (!isset($_POST['price-usd'])) {
                 $sub_mess['price-usd'] = "Попытка подделки формы !";
             }
             if (!isset($_POST['date-to-tex']) || strlen($_POST['date-to-tex']) < 3) {
                 $sub_mess['date-to-tex'] = "Не заполнено поле Дата начала показа!";
             }
             if (!isset($_POST['date-from-tex']) || strlen($_POST['date-from-tex']) < 3) {
                 $sub_mess['date-from-tex'] = "Не заполнено поле Дата окончания показа!";
             }
             if (!isset($_POST['text-tex']) || strlen($_POST['text-tex']) < 3) {
                 $sub_mess['text-tex'] = "Не заполнено поле Описание !";
             }
             if (is_array($sub_mess)) {
                 echo json_encode($sub_mess);
                 return false;
             } else {
                 return true;
             }
         }
         if (valid_order()) {
             if ($this->request->hasPost('order_id')) {
                 $prop = Proposal::findFirst($this->request->getPost('order_id'));
             } else {
                 $prop = new Proposal();
             }
             $prop->user_id = $this->session->get('user_id');
             if ($this->request->hasPost('sub_cat_id')) {
                 $prop->category_id = $this->request->getPost('sub_cat_id');
             } else {
                 $prop->category_id = $this->request->getPost('cat_id');
             }
             $prop->creation_date = date('Y-m-d-H-i-s');
             $prop->date_to = $this->request->getPost('date-to-tex');
             $prop->date_from = $this->request->getPost('date-from-tex');
             $prop->text = $this->request->getPost('text-tex');
             $prop->price_hour = $this->request->getPost('price-usd');
             if ($this->request->hasPost('public') && $this->request->getPost('public') == 'y') {
                 $prop->status = 1;
             }
             $prop->save();
             if ($this->request->hasPost('name-tex')) {
                 $md = new Model();
                 $md->name = $this->request->getPost('name-tex');
                 $this->modelsCache->delete("md");
                 $md->save();
                 if ($this->request->hasPost('order_id')) {
                     $dann = DannProposal::findFirst(array("proposal_id = {$prop->id} and field_type_id = 22"));
                     if (isset($dann->id)) {
                         $dann->dann = $this->request->getPost('name-tex');
                         $dann->proposal_id = $prop->id;
                         $dann->field_type_id = 22;
                         $dann->active = 1;
                         $dann->save();
                     } else {
                         $dann = new DannProposal();
                         $dann->dann = $this->request->getPost('name-tex');
                         $dann->proposal_id = $prop->id;
                         $dann->field_type_id = 22;
                         $dann->active = 1;
                         $dann->save();
                     }
                 } else {
                     $dann = new DannProposal();
                     $dann->dann = $this->request->getPost('name-tex');
                     $dann->proposal_id = $prop->id;
                     $dann->field_type_id = 22;
                     $dann->active = 1;
                     $dann->save();
                 }
             }
             if ($this->request->hasPost('city-tex')) {
                 if ($this->request->hasPost('order_id')) {
                     $dann = DannProposal::findFirst(array("proposal_id = {$prop->id} and field_type_id = 4"));
                     if (isset($dann->id)) {
                         $dann->dann = $this->request->getPost('city-tex');
                         $dann->proposal_id = $prop->id;
                         $dann->field_type_id = 4;
                         $dann->active = 1;
                         $dann->save();
                     } else {
                         $dann = new DannProposal();
                         $dann->dann = $this->request->getPost('city-tex');
                         $dann->proposal_id = $prop->id;
                         $dann->field_type_id = 4;
                         $dann->active = 1;
                         $dann->save();
                     }
                 } else {
                     $dann = new DannProposal();
                     $dann->dann = $this->request->getPost('city-tex');
                     $dann->proposal_id = $prop->id;
                     $dann->field_type_id = 4;
                     $dann->active = 1;
                     $dann->save();
                 }
             }
             if ($this->request->hasPost('price-tex')) {
                 if ($this->request->hasPost('order_id')) {
                     $dann = DannProposal::findFirst(array("proposal_id = {$prop->id} and field_type_id = 5"));
                     if (isset($dann->id)) {
                         $dann->dann = $this->request->getPost('price-tex');
                         $dann->proposal_id = $prop->id;
                         $dann->field_type_id = 5;
                         $dann->active = 1;
                         $dann->save();
                     } else {
                         $dann = new DannProposal();
                         $dann->dann = $this->request->getPost('price-tex');
                         $dann->proposal_id = $prop->id;
                         $dann->field_type_id = 5;
                         $dann->active = 1;
                         $dann->save();
                     }
                 } else {
                     $dann = new DannProposal();
                     $dann->dann = $this->request->getPost('price-tex');
                     $dann->proposal_id = $prop->id;
                     $dann->field_type_id = 5;
                     $dann->active = 1;
                     $dann->save();
                 }
             }
             echo json_encode(array('success' => "Предложение  добавлено", 'order_id' => $prop->id));
         }
     }
 }