public function actionTicket()
 {
     if (Yii::app()->user->isGuest) {
         $this->redirect('/');
     }
     $request = Yii::app()->request;
     $ticketid = $request->getParam('id');
     if (!$ticketid) {
         $this->redirect('/');
     }
     $user = Yii::app()->user->data();
     $model = new CreateTicketForm();
     $formData = $request->getPost(get_class($model), false);
     if ($formData) {
         $model->attributes = $formData;
         if (!$model->hasErrors()) {
             $newticket_message = new SupportTicketMessage();
             $newticket_message->body = $model->body;
             if (!Yii::app()->user->isGuest) {
                 $newticket_message->id_ticket = $ticketid;
                 $newticket_message->id_user = $user->id;
             }
             if (!$newticket_message->save()) {
                 Yii::app()->user->setFlash('error', Yii::t('translation', 'Unable to create ticket'));
             }
             Yii::app()->user->setFlash('success', Yii::t('translation', 'Ticket #{ticket_id} Updated', array('{ticket_id}' => $ticketid)));
         }
     }
     $messages = SupportTicketMessage::model()->findAllByAttributes(array('id_ticket' => $ticketid));
     $this->render('ticket', array('model' => SupportTicket::model()->findByPk($ticketid), 'updatemodel' => $model, 'user' => $user, 'messages' => $messages));
 }
 public function loadModel($id)
 {
     $model = SupportTicket::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }