public function actionManagersCancel()
 {
     $this->_prepairJson();
     $orderId = $this->_request->getParam('order_id');
     $payment = ProjectPayments::model()->find('order_id = :ORDER_ID', array('ORDER_ID' => $orderId));
     $payment->to_receive = 0;
     if ($payment->save()) {
         PaymentImage::model()->remove($orderId);
         $this->_response->setData(array('to_receive' => $payment->to_receive));
     } else {
         $this->_response->setData(array('to_receive' => $payment->to_receive));
     }
     $this->_response->send();
 }
 /**
  *  Вывод и добавление сообщений
  */
 public function actionIndex($orderId, $role = null)
 {
     $isCorrector = $role == 'Corrector' ? 1 : 0;
     $isGuest = Yii::app()->user->isGuest;
     if ($isGuest) {
         $url = 'http://' . $_SERVER['SERVER_NAME'] . '/user/login';
         $this->redirect($url);
     }
     Yii::app()->session['project_id'] = $orderId;
     $order = Zakaz::model()->resetScope()->findByPk($orderId);
     if (Yii::app()->request->isAjaxRequest) {
         if (Yii::app()->request->getPost('ProjectMessages')) {
             $id = (int) $_POST['ProjectMessages']['id'];
             if ($id > 0) {
                 // редактирование сообщения
                 $model = ProjectMessages::model()->findByPk($id);
             } else {
                 // новое сообщение
                 $model = new ProjectMessages();
                 $model->sender = Yii::app()->user->id;
                 $model->moderated = 0;
                 $model->order = $orderId;
             }
             $post = $_POST['ProjectMessages']['message'];
             $post = str_replace("\r\n", '<br>', $post);
             $post = str_replace("\n", '<br>', $post);
             $_POST['ProjectMessages']['message'] = $post;
             $model->attributes = Yii::app()->request->getPost('ProjectMessages');
             $model->date = date('Y-m-d H:i:s');
             switch ($model->recipient) {
                 case 'author_to_manager':
                     $model->sender_role = ProjectMessages::model()->getRoleId('Author');
                     $model->recipient_role = ProjectMessages::model()->getRoleId('Admin');
                     $model->recipient = 1;
                     break;
                 case 'customer_to_manager':
                     $model->sender_role = ProjectMessages::model()->getRoleId('Customer');
                     $model->recipient_role = ProjectMessages::model()->getRoleId('Admin');
                     $model->recipient = 1;
                     break;
                 case 'corrector_to_manager':
                     $model->sender_role = ProjectMessages::model()->getRoleId('Corrector');
                     $model->recipient_role = ProjectMessages::model()->getRoleId('Admin');
                     $model->recipient = 1;
                     break;
                 case 'author_to_customer':
                     $model->sender_role = ProjectMessages::model()->getRoleId('Author');
                     $model->recipient_role = ProjectMessages::model()->getRoleId('Customer');
                     $model->recipient = Zakaz::model()->findByPk($orderId)->attributes['user_id'];
                     break;
                 case 'corrector_to_customer':
                     $model->sender_role = ProjectMessages::model()->getRoleId('Corrector');
                     $model->recipient_role = ProjectMessages::model()->getRoleId('Customer');
                     $model->recipient = Zakaz::model()->findByPk($orderId)->attributes['user_id'];
                     break;
                 case 'customer_to_author':
                     $model->sender_role = ProjectMessages::model()->getRoleId('Customer');
                     $model->recipient_role = ProjectMessages::model()->getRoleId('Author');
                     $model->recipient = Zakaz::model()->resetScope()->findByPk($orderId)->attributes['executor'];
                     break;
                 case 'corrector_to_author':
                     $model->sender_role = ProjectMessages::model()->getRoleId('Corrector');
                     $model->recipient_role = ProjectMessages::model()->getRoleId('Author');
                     $model->recipient = Zakaz::model()->resetScope()->findByPk($orderId)->attributes['executor'];
                     break;
                 case 'author_to_corrector':
                     $model->sender_role = ProjectMessages::model()->getRoleId('Author');
                     $model->recipient_role = ProjectMessages::model()->getRoleId('Corrector');
                     $model->recipient = -2;
                     break;
                 case 'customer_to_corrector':
                     $model->sender_role = ProjectMessages::model()->getRoleId('Customer');
                     $model->recipient_role = ProjectMessages::model()->getRoleId('Corrector');
                     $model->recipient = -2;
                     break;
             }
             $model->save();
             EventHelper::addMessage($orderId, $model->message);
         }
         $this->renderPartial('chat', array('order' => $order, 'orderId' => $orderId, 'isGuest' => $isGuest));
         Yii::app()->end();
     }
     if (User::model()->isAuthor() && (!User::model()->isCorrector() || !$order->technicalspec) && !User::model()->isExecutor($orderId)) {
         $this->redirect(Yii::app()->createUrl('/project/chat/view', array('orderId' => $orderId)));
     }
     if (User::model()->isCustomer() && $order->user_id != Yii::app()->user->id) {
         $this->redirect('/');
     }
     $parts = ZakazParts::model()->findAll(array('condition' => "`proj_id`='{$orderId}'"));
     if (User::model()->isExecutor($order->id)) {
         $order->executor_event = null;
     }
     if (User::model()->isCustomer()) {
         $order->customer_event = null;
     }
     $order->save(false);
     $moderate_types = EventHelper::get_moderate_types_string();
     $events = Events::model()->findAll(array('condition' => "`event_id`='{$orderId}' AND `type` in ({$moderate_types})", 'order' => 'timestamp DESC'), array(':event_id' => $orderId));
     $PaymentImages = PaymentImage::model()->findAll(array('condition' => "`project_id`='{$orderId}'"));
     $moderated = count($events) == 0;
     $this->render('index', array('orderId' => $orderId, 'order' => $order, 'executor' => Zakaz::getExecutor($orderId), 'moderated' => $moderated, 'parts' => $parts, 'PaymentImages' => $PaymentImages, 'isCorrector' => $isCorrector));
 }