예제 #1
1
 public function addComment($data)
 {
     /** @var myModel $this */
     $comment = new Comments();
     $comment->content = $data['content'];
     $comment->commentable_id = $this->id;
     $comment->commentable_type = get_class($this);
     //        $comment->user_id = $this->getDI()->getShared('session')->get('auth')['id'];//获得当前登录对象的id
     $user = \Phalcon\Di::getDefault()->get('auth');
     $comment->user_id = $user->id;
     //获得当前登录对象的id
     //        dd($comment);
     $comment->save();
     /** @var myModel $this */
     if (method_exists($this, 'increaseCount')) {
         $this->increaseCount('commentCount');
     } else {
         $this->save();
         //更新时间
     }
     if (is_a($this, 'Tags')) {
         $meta = $this->getTagmetaOrNew();
         $meta->save();
     }
     return $this;
 }
 /**
  * Change Case status using select-box
  */
 public function actionChangeStatus()
 {
     // check if user has permissions to changeStatusCases
     if (Yii::app()->user->checkAccess('changeStatusCases')) {
         // verify is request was made via post ajax
         if (Yii::app()->request->isAjaxRequest && isset($_POST)) {
             // get Cases object model
             $model = $this->loadModel($_REQUEST['id']);
             // set new status
             $model->status_id = $_POST['changeto'];
             // validate and save
             if ($model->save()) {
                 // save log
                 $attributes = array('log_date' => date("Y-m-d G:i:s"), 'log_activity' => 'CaseStatusChanged', 'log_resourceid' => $model->case_id, 'log_type' => Logs::LOG_UPDATED, 'user_id' => Yii::app()->user->id, 'module_id' => Yii::app()->controller->id, 'project_id' => $model->project_id);
                 Logs::model()->saveLog($attributes);
                 // create comment to let then know that some user change the case status
                 $modelComment = new Comments();
                 $modelComment->comment_date = date("Y-m-d G:i:s");
                 $modelComment->comment_text = Status::STATUS_COMMENT . ": " . $model->Status->status_id;
                 $modelComment->user_id = Yii::app()->user->id;
                 $modelComment->module_id = Modules::model()->find(array('condition' => 't.module_name = :module_name', 'params' => array(':module_name' => $this->getId())))->module_id;
                 $modelComment->comment_resourceid = $model->case_id;
                 $modelComment->save(false);
                 // prepare email template for each project manager
                 Yii::import('application.extensions.phpMailer.yiiPhpMailer');
                 $mailer = new yiiPhpMailer();
                 $subject = Yii::t('email', 'CaseStatusChange') . " - " . $model->case_name;
                 //$Users = Users::model()->with('Clients')->findManagersByProject($model->project_id);
                 $Users = Projects::model()->findAllUsersByProject($model->project_id);
                 $recipientsList = array();
                 foreach ($Users as $client) {
                     $recipientsList[] = array('name' => $client->CompleteName, 'email' => $client->user_email);
                 }
                 // load template
                 $str = $this->renderPartial('//templates/cases/StatusChanged', array('case' => $model, 'user' => Users::model()->findByPk(Yii::app()->user->id), 'urlToCase' => "http://" . $_SERVER['SERVER_NAME'] . Yii::app()->createUrl('cases/view', array('id' => $model->case_id)), 'typeNews' => $model->status_id == Status::STATUS_ACCEPTED || $model->status_id == Status::STATUS_TOREVIEW ? 'buenas' : 'malas', 'applicationName' => Yii::app()->name, 'applicationUrl' => "http://" . $_SERVER['SERVER_NAME'] . Yii::app()->request->baseUrl), true);
                 $mailer->pushMail($subject, $str, $recipientsList, Emails::PRIORITY_NORMAL);
                 $output = Yii::t('cases', 'StatusChanged');
             } else {
                 $output = Yii::t('cases', 'StatusError');
             }
             echo $output;
             Yii::app()->end();
         } else {
             throw new CHttpException(403, Yii::t('site', '403_Error'));
         }
     } else {
         throw new CHttpException(403, Yii::t('site', '403_Error'));
     }
 }
예제 #3
0
 public function addComment($user_id, $post_id, $content)
 {
     $model = new Comments();
     $model->post_id = $post_id;
     $model->created_by = $user_id;
     $model->updated_at = time();
     $model->comment_content = $content;
     $model->status = 1;
     $model->created_at = time();
     $model->updated_at = time();
     $model->save(FALSE);
     $post = Posts::model()->findByPk($post_id);
     $post->post_comment_count++;
     $user = User::model()->findByPk($model->created_by);
     $user_commented = User::model()->findByPk($post->user_id);
     if ($user_commented) {
         if ($user->id != $post->user_id) {
             $users_have_commented = $this->getListUserCommentedOnPost($post_id);
             if ($users_have_commented) {
                 foreach ($users_have_commented as $item) {
                     if ($user_id != $item->created_by && $post->user_id != $item->created_by) {
                         $arr_noti_others = array('user_id' => $user->id, 'content' => "{$user->username} cũng đã bình luận bài viết của {$user_commented->username}", 'type' => 'comment_also', 'recipient_id' => $item->created_by, 'url' => Yii::app()->createAbsoluteUrl('post/viewPost', array('post_id' => $post_id, array('ref' => 'noti'))));
                         Notifications::model()->add($arr_noti_others);
                     }
                 }
             }
             $arr_noti = array('user_id' => $user->id, 'content' => "{$user->username} vừa bình luận bài viết của bạn", 'type' => 'comment', 'recipient_id' => $user_commented->id, 'url' => Yii::app()->createAbsoluteUrl('post/viewPost', array('post_id' => $post_id, array('ref' => 'noti'))));
             Notifications::model()->add($arr_noti);
         } else {
             $users_have_commented = $this->getListUserCommentedOnPost($post_id);
             if ($users_have_commented) {
                 foreach ($users_have_commented as $item) {
                     if ($user_id != $item->created_by) {
                         $arr_noti_others = array('user_id' => $user->id, 'content' => "{$user->username} cũng đã bình luận bài viết của họ", 'type' => 'comment_also', 'recipient_id' => $item->created_by, 'url' => Yii::app()->createAbsoluteUrl('post/viewPost', array('post_id' => $post_id, array('ref' => 'noti'))));
                         Notifications::model()->add($arr_noti_others);
                     }
                 }
             }
         }
     }
     if ($model->save(FALSE) && $post->save(FALSE)) {
         $returnArr = array();
         $returnArr['created_by'] = $model->created_by;
         $returnArr['username'] = $user->username;
         $returnArr['photo'] = StringHelper::generateUrlImage($user->photo);
         $returnArr['created_at'] = Util::time_elapsed_string($model->created_at);
         $returnArr['comment_content'] = $model->comment_content;
         return $returnArr;
     }
     return FALSE;
 }
예제 #4
0
 /**
  * Добавление / редактирование комментариев
  */
 public function actionSave_comment()
 {
     if (Yii::app()->user->isGuest) {
         $this->redirect($this->createAbsoluteUrl('base'));
     }
     // Редактирование или добавление новой
     if (isset($_GET['idComment'])) {
         $model = Comments::model()->findByPk($_GET['idComment']);
     } else {
         $model = new Comments();
     }
     if (isset($_POST['idArticle']) && isset($_POST['text']) && isset($_POST['idAuthor'])) {
         $model->idArticle = $_POST['idArticle'];
         $model->text = $_POST['text'];
         $model->idUser = empty($this->_user) ? Users::getIdUserForAdmin() : $this->_user['idUser'];
         $model->typeUser = $model->idUser == $_POST['idAuthor'] ? 'author' : (empty($this->_user) ? 'admin' : 'user');
         if ($model->save()) {
             if (Yii::app()->request->isAjaxRequest) {
                 $criteria = new CDbCriteria();
                 $criteria->with = array('idUser0');
                 $criteria->condition = 'idArticle = :idArticle AND deleted = 0 AND public = 1';
                 $criteria->params = array(':idArticle' => $_POST['idArticle']);
                 $comments = Comments::model()->findAll($criteria);
                 $commentsDataProvider = new CArrayDataProvider($comments, array('keyField' => 'idComment', 'pagination' => array('pageSize' => 50)));
                 $listComments = $this->renderPartial('_list_comments', array('dataProvider' => $commentsDataProvider), true);
                 echo CJSON::encode(array('listComments' => $listComments));
                 exit;
             }
         }
     }
 }
예제 #5
0
 /**
  * Store a newly created resource in storage.
  * @param itemid <=== What?
  * @param itemtype
  * @param userid
  * @param string key
  * @return Response
  */
 public function store()
 {
     $itemid = Input::get('itemid');
     $itemtype = Input::get('itemtype');
     $userid = Input::get('userid');
     $usercomment = Input::get('comment');
     $key = Input::get('key');
     $retVal = array('status' => 'ERR', 'msg' => 'Invalid Session');
     try {
         $user = \Member::where('session_key', '=', $key)->exists();
         if (!$user) {
             return Response::json($retVal);
         }
         $media = \Media::where('_id', '=', $itemid)->exists();
         //var_dump($media);
         if (!$media) {
             $retVal = array('status' => 'ERR', 'msg' => 'Invalid item.');
             return Response::json($retVal);
         }
         $comment = new \Comments();
         $comment->itemid = $itemid;
         $comment->itemtype = $itemtype;
         $comment->userid = $userid;
         $comment->comment = $usercomment;
         $comment->save();
         $retVal = array('status' => 'OK');
         return Response::json($retVal);
     } catch (ModelNotFoundException $e) {
     }
 }
예제 #6
0
 public function actionSendMail()
 {
     if (!empty($_POST)) {
         Yii::import('ext.yii-mail.YiiMailMessage');
         $message = new YiiMailMessage();
         $message->setBody($_POST['content']);
         $message->subject = $_POST['subject'];
         $message->from = $_POST['email'];
         $message->to = Yii::app()->params['adminEmail'];
         if (Yii::app()->mail->send($message)) {
             $model = new Comments();
             $model->title = $_POST['subject'];
             $model->content = $_POST['content'];
             $model->email = $_POST['email'];
             $model->name = $_POST['fullName'];
             $model->phone = $_POST['phone'];
             $model->created = time();
             if ($model->save()) {
                 return jsonOut(array('error' => false, 'message' => 'Cảm ơn bạn đã gửi thông tin, chúng tôi sẽ phản hồi cho bạn trong thời gian sớm nhất!'));
             } else {
                 return json_encode(array('error' => true, 'message' => 'Lỗi hệ thống, gửi thông tin không thành công.'));
             }
         } else {
             return json_encode(array('error' => true, 'message' => 'Gửi thông tin không thành công'));
         }
     }
 }
예제 #7
0
 public function setAction()
 {
     $post = ['name' => false, 'email' => false, 'comment' => true];
     if ($this->_status['response']['status'] && !$this->_getPost($post)) {
         $this->_status['response']['status'] = false;
         $this->_status['response']['code'] = 201;
         $this->_status['response']['detail'] = $post['empty'];
     }
     $urlId = $this->dispatcher->getParam('id');
     if (!$this->_status['response']['status'] && empty($urlId)) {
         $this->_status['response']['status'] = false;
         $this->_status['response']['code'] = 203;
     }
     $posts = Posts::findFirst($urlId);
     if ($this->_status['response']['status'] && !$posts) {
         $this->_status['response']['status'] = false;
         $this->_status['response']['code'] = 404;
     }
     if (!$this->_status['response']['status']) {
         return $this->response->setJsonContent($this->_status);
     }
     $comments = new Comments();
     $comments->assign(['posts_id' => $posts->id, 'name' => $this->_post['name'], 'email' => $this->_post['email'], 'comment' => $this->_post['comment']]);
     if (!$comments->save()) {
         $this->_status['response']['status'] = false;
         $this->_status['response']['code'] = 102;
     }
     return $this->response->setJsonContent($this->_status);
 }
예제 #8
0
 public function indexAction()
 {
     if ($this->request->isPost()) {
         $comment = new Comments();
         $comment->setName($this->request->getPost('name'));
         $comment->setEmail($this->request->getPost('email'));
         $comment->setContent($this->request->getPost('comment'));
         //store comment on the comments table
         if ($comment->save() == false) {
             echo "These errors occurred: ";
             foreach ($comment->getMessages() as $msg) {
                 echo $msg;
             }
         } else {
             //store on the post_comments table
             $post_id = $this->request->getPost('id');
             $post_comment = new PostComments();
             $post_comment->setCommentId($comment->id());
             $post_comment->setPostId($post_id);
             if ($post_comment->save() == false) {
                 echo "These errors occurred: ";
                 foreach ($post_comment->getMessages() as $msg) {
                     echo $msg;
                 }
             } else {
                 return (new \Phalcon\Http\Response())->redirect('posts/post/' . $post_id);
             }
         }
     }
 }
 public function newComment()
 {
     // POST İLE GÖNDERİLEN DEĞERLERİ ALALIM.
     $postData = Input::all();
     // FORM KONTROLLERİNİ BELİRLEYELİM
     $rules = array('question_id' => 'required|integer', 'comment' => 'required');
     // HATA MESAJLARINI OLUŞTURALIM
     $messages = array('question_id.required' => 'İşleminiz yapılırken teknik bir sorun oluştu', 'question_id.integer' => 'İşleminiz yapılırken teknik bir sorun oluştu', 'comment.required' => 'Lütfen yanıtınızı yazın');
     // KONTROL (VALIDATION) İŞLEMİNİ GERÇEKLEŞTİRELİM
     $validator = Validator::make($postData, $rules, $messages);
     // EĞER VALİDASYON BAŞARISIZ OLURSA HATALARI GÖSTERELİM
     if ($validator->fails()) {
         // KULLANICIYI SORU SAYFASINA GERİ GÖNDERELİM
         return Redirect::to(URL::previous())->withErrors($validator->messages());
     } else {
         // SORUYU VERİTABANINA EKLEYELİM
         $comment = new Comments();
         $comment->user_id = Auth::user()->id;
         $comment->question_id = $postData['question_id'];
         $comment->comment = e(trim($postData['comment']));
         $comment->created_at = date('Y-m-d H:i:s');
         $comment->created_ip = Request::getClientIp();
         $comment->save();
         // KULLANICIYI YENİDEN SORUYA YÖNLENDİRELİM
         return Redirect::to(URL::previous());
     }
 }
예제 #10
0
 /**
  * 这里可以作为一个通用的保存评论的方法来使用
  * @param myModel $model
  * @param $data
  */
 protected function saveCommentTo(myModel $model, $data)
 {
     $comment = new Comments();
     $comment->content = $data['content'];
     $comment->commentable_id = $model->id;
     $comment->commentable_type = get_class($model);
     $comment->user_id = $this->auth->id;
     $comment->save();
 }
예제 #11
0
 /**
  * Вывод инфы о бане
  * @param integer $id ID бана
  */
 public function actionView($id)
 {
     // Подгружаем комментарии и файлы
     $files = new Files();
     //$this->performAjaxValidation($files);
     $files->unsetAttributes();
     $comments = new Comments();
     $comments->unsetAttributes();
     // Подгружаем баны
     $model = Bans::model()->with('admin')->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     $geo = false;
     // Проверка прав на просмотр IP
     $ipaccess = Webadmins::checkAccess('ip_view');
     if ($ipaccess) {
         $geo = array('city' => 'Н/А', 'region' => 'Не определен', 'country' => 'Не определен', 'lat' => 0, 'lng' => 0);
         $get = @file_get_contents('http://ipgeobase.ru:7020/geo?ip=' . $model->player_ip);
         if ($get) {
             $xml = @simplexml_load_string($get);
             if (!empty($xml->ip)) {
                 $geo['city'] = $xml->ip->city;
                 $geo['region'] = $xml->ip->region;
                 $geo['country'] = $xml->ip->country;
                 $geo['lat'] = $xml->ip->lat;
                 $geo['lng'] = $xml->ip->lng;
             }
         }
     }
     // Добавление файла
     if (isset($_POST['Files']) && !empty($_POST['Files']['name'])) {
         // Задаем аттрибуты
         $files->attributes = $_POST['Files'];
         $files->bid = intval($id);
         $files->save();
         $this->refresh();
     }
     // Добавление комментария
     if (isset($_POST['Comments'])) {
         //exit(print_r($_POST['Comments']));
         $comments->attributes = $_POST['Comments'];
         $comments->bid = $id;
         if ($comments->save()) {
             $this->refresh();
         }
     }
     // Выборка комментариев
     $c = new CActiveDataProvider($comments, array('criteria' => array('condition' => 'bid = :bid', 'params' => array(':bid' => $id))));
     // Выборка файлов
     $f = new CActiveDataProvider(Files::model(), array('criteria' => array('condition' => 'bid = :bid', 'params' => array(':bid' => $id))));
     // История банов
     $history = new CActiveDataProvider('Bans', array('criteria' => array('condition' => '`bid` <> :hbid AND (`player_ip` = :hip OR `player_id` = :hid)', 'params' => array(':hbid' => $id, ':hip' => $model->player_ip, ':hid' => $model->player_id)), 'pagination' => array('pageSize' => 5)));
     // Вывод всего на вьюху
     $this->render('view', array('geo' => $geo, 'ipaccess' => $ipaccess, 'model' => $model, 'files' => $files, 'comments' => $comments, 'f' => $f, 'c' => $c, 'history' => $history));
 }
예제 #12
0
 public function addCommentBy(Users $user, $data)
 {
     $comment = new Comments();
     $comment->content = $data['content'];
     $comment->commentable_id = $this->id;
     $comment->commentable_type = get_class($this);
     $comment->user_id = $user->id;
     $comment->save();
     return $this;
 }
예제 #13
0
 /**
  * Creates a new comment
  * TODO: Figure out how to fix the email issues
  * @param  int  $id   The Comment id
  * @return array
  */
 private function createComment()
 {
     $model = new Comments();
     $model->attributes = $_POST;
     $model->approved = Cii::getConfig('autoApproveComments', 0);
     if ($model->save()) {
         return $model->getApiAttributes();
     }
     return $this->returnError(400, NULL, $model->getErrors());
 }
예제 #14
0
 public function actionAdd()
 {
     $model = new Comments();
     if (isset($_POST['comments'])) {
         $model->attributes = $_POST['comments'];
         if ($model->save()) {
             $this->redirect($this->createUrl('comments/index'));
         }
     }
     $this->render('add', array('model' => $model));
 }
예제 #15
0
파일: Logs.php 프로젝트: Headrun-php/TLG
 static function addLog($input)
 {
     $comments = new Comments();
     $comments->customer_id = $input['customerId'];
     $comments->franchisee_id = Session::get('franchiseId');
     $comments->log_text = $input['logText'];
     $comments->created_by = "0";
     $comments->created_at = date("Y-m-d H:i:s");
     $comments->save();
     return $comments;
 }
예제 #16
0
파일: Comments.php 프로젝트: huynt57/hatch
 public function addComment($attr)
 {
     $model = new Comments();
     $model->setAttributes($attr);
     $model->created_at = time();
     $model->updated_at = time();
     $model->status = 1;
     if ($model->save(FALSE)) {
         return TRUE;
     }
     return FALSE;
 }
예제 #17
0
 public function actionComment()
 {
     $rows = Comments::model()->findAll();
     $model = new Comments();
     if (isset($_POST['Comments'])) {
         $model->attributes = $_POST['Comments'];
         if ($model->save()) {
             $this->redirect($this->createUrl('pages/comment'));
         }
     }
     $this->render('comment', array('rows' => $rows, 'model' => $model));
 }
예제 #18
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Comments();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Comments'])) {
         $model->attributes = $_POST['Comments'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
예제 #19
0
 /**
  * Provides functionality to make a comment
  */
 public function actionComment()
 {
     if (Yii::app()->request->isAjaxRequest && Cii::get($_POST, 'Comments')) {
         $comment = new Comments();
         $comment->attributes = array('user_id' => Yii::app()->user->id, 'content_id' => $_POST['Comments']['content_id'], 'comment' => $_POST['Comments']['comment'], 'parent_id' => Cii::get($_POST['Comments'], 'parent_id', 0), 'approved' => Cii::getConfig('autoApproveComments', 1) == null ? 1 : Cii::getConfig('autoApproveComments', 1));
         if ($comment->save()) {
             $content = Content::model()->findByPk($comment->content_id);
             // Pass the values as "now" for the comment view"
             $comment->created = $comment->updated = Yii::t('Dashboard.main', 'now');
             // Set the attributed id to make life easier...
             header("X-Attribute-Id: {$comment->id}");
             $this->renderPartial('/content/comments', array('count' => $content->comment_count, 'comment' => $comment, 'depth' => 0, 'md' => new CMarkdownParser()));
         } else {
             throw new CHttpException(400, Yii::t('Dashboard.main', 'There was an error saving your comment.'));
         }
     }
 }
예제 #20
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Comments();
     // var_dump($model);
     // die;
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Comments'])) {
         // 	var_dump($_POST);
         // die;
         // $_POST['Comments']['created_at'] = date('Y-m-d H:i:s');
         // $_POST['Comments']['updated_at'] = date('Y-m-d H:i:s');
         $model->attributes = $_POST['Comments'];
         // var_dump($model);
         // die;
         if ($model->save()) {
             $this->redirect('/index.php?r=posts/index', array('view', 'id' => $_POST['Comments']['post_id']));
         }
     }
     $this->render('create', array('model' => $model));
 }
예제 #21
0
 protected function beforeAction($action)
 {
     if (isset($_REQUEST['Comments'])) {
         $comment = $_REQUEST['Comments'];
         //Yii::app()->notify->add("Добавлен комментарий");
         if (isset($comment)) {
             if (isset($comment['id']) and isset($comment['model'])) {
             }
             $entry = new Comments();
             $entry->entryid = $comment['id'];
             $entry->comment = $comment['comment'];
             $entry->model = "Solutions";
             $entry->student = Yii::app()->my->id;
             if ($entry->save()) {
                 Yii::app()->notify->add("Добавлен комментарий ");
             } else {
                 Yii::app()->notify->addErrors($entry->getErrors());
             }
         }
     }
     return true;
 }
예제 #22
0
 public function addAction()
 {
     if (!$this->getRequest()->isPost()) {
         // Deny
     }
     $stream = $this->_getParam('stream', null);
     if (null === $stream) {
         // Deny
     }
     $comment = new Comments();
     $comment->post_id = $stream;
     $comment->name = $_POST['name'];
     $comment->email = $_POST['email'];
     $comment->website = $_POST['website'];
     $comment->body = $_POST['body'];
     $comment->date = time();
     $comment->save();
     if (isset($_SERVER['HTTP_REFERER'])) {
         $this->_redirect($_SERVER['HTTP_REFERER']);
     } else {
         $this->render('success.phtml');
     }
 }
 public function actionAdd()
 {
     $text = Yii::app()->getRequest()->getPost('text');
     $tbl = Yii::app()->getRequest()->getPost('tbl');
     $item_id = Yii::app()->getRequest()->getPost('item_id');
     $lastCommentId = Yii::app()->getRequest()->getPost('lastCommentId');
     $owner_id = Yii::app()->getRequest()->getPost('owner');
     if ($text == 'Добавить комментарий' || empty($text) || empty($tbl) || empty($item_id) || empty($owner_id)) {
         echo json_encode(array('status' => 'error', 'data' => 'Заполните все обязательные поля!'));
         exit;
     }
     $commentsObj = new Comments();
     $commentsObj->tbl = $tbl;
     $commentsObj->item_id = $item_id;
     $commentsObj->author_id = Yii::app()->user->id;
     $commentsObj->owner_id = $owner_id;
     $commentsObj->text = $text;
     $commentsObj->timestamp = time();
     if ($commentsObj->save()) {
         if (Yii::app()->request->isAjaxRequest) {
             $comments = array_reverse($commentsObj->lastAfterId($tbl, $item_id, $lastCommentId));
             $res = '';
             foreach ($comments as $item) {
                 $res .= $this->renderPartial('//comments/comments/_commentsItem', array('item' => $item, 'display' => 'none'), true);
             }
             echo json_encode(array('status' => 'ok', 'data' => $res));
         } else {
             throw new CException('Not Found', 404);
         }
     } else {
         if (Yii::app()->request->isAjaxRequest) {
             echo json_encode(array('status' => 'error', 'data' => 'Не могу соединиться с БД'));
         } else {
             throw new CException('Server error', 500);
         }
     }
 }
 /**
  * Displays a particular model.
  * @return string with success message
  */
 public function actionchangeStatus()
 {
     // check if user has permissions to changeStatusInvoices
     if (Yii::app()->user->checkAccess('changeStatusInvoices')) {
         // verify is request was made via post ajax
         if (Yii::app()->request->isAjaxRequest && isset($_POST)) {
             // get Invoice object model
             $model = $this->loadModel();
             // set new status
             $model->status_id = $_POST['changeto'];
             // validate and save
             if ($model->save()) {
                 // save log
                 $attributes = array('log_date' => date("Y-m-d G:i:s"), 'log_activity' => 'InvoiceStatusChanged', 'log_resourceid' => $model->invoice_id, 'log_type' => Logs::LOG_UPDATED, 'user_id' => Yii::app()->user->id, 'module_id' => Yii::app()->controller->id, 'project_id' => $model->project_id);
                 Logs::model()->saveLog($attributes);
                 // create comment to let then know that some user change the invoice status
                 $modelComment = new Comments();
                 $modelComment->comment_date = date("Y-m-d G:i:s");
                 $modelComment->comment_text = "StatusChanged: " . $model->Status->status_id;
                 $modelComment->user_id = Yii::app()->user->id;
                 $modelComment->module_id = Modules::model()->find(array('condition' => 't.module_name = :module_name', 'params' => array(':module_name' => $this->getId())))->module_id;
                 $modelComment->comment_resourceid = $model->invoice_id;
                 $modelComment->save(false);
                 $output = Yii::t('invoices', 'StatusChanged');
             } else {
                 $output = Yii::t('invoices', 'StatusError');
             }
             echo $output;
             Yii::app()->end();
         } else {
             throw new CHttpException(403, Yii::t('site', '403_Error'));
         }
     } else {
         throw new CHttpException(403, Yii::t('site', '403_Error'));
     }
 }
예제 #25
0
 public function addComment($user_id, $post_id, $content)
 {
     $model = new Comments();
     $model->post_id = $post_id;
     $model->created_by = $user_id;
     $model->updated_at = time();
     $model->comment_content = $content;
     $model->status = 1;
     $model->created_at = time();
     $model->updated_at = time();
     $post = Posts::model()->findByPk($post_id);
     $post->post_comment_count++;
     $user = User::model()->findByPk($model->created_by);
     if ($model->save(FALSE) && $post->save(FALSE)) {
         $returnArr = array();
         $returnArr['created_by'] = $model->created_by;
         $returnArr['username'] = $user->username;
         $returnArr['photo'] = $user->photo;
         $returnArr['created_at'] = Util::time_elapsed_string($model->created_at);
         $returnArr['comment_content'] = $model->comment_content;
         return $returnArr;
     }
     return FALSE;
 }
 /**
  * Creates a new model.
  */
 public function actionCreate()
 {
     // create Comments Object
     $model = new Comments();
     // if Comments form exist
     if (isset($_POST['Comments'])) {
         // set form elements to Comments model attributes
         $model->attributes = $_POST['Comments'];
         $module = Modules::model()->find(array('condition' => 't.module_name = :module_name', 'params' => array(':module_name' => $model->module_id)));
         // set module_id finded to model
         $model->module_id = $module->module_id;
         $project = Yii::app()->user->getState('project_selected');
         $model->project_id = $project;
         // validate and save
         if ($model->save()) {
             // create an instance of file uploaded
             $image = CUploadedFile::getInstancesByName('Comment');
             // if file upload exist
             if (count($image > 0)) {
                 // for each file uploaded
                 for ($i = 0; $i < count($image); $i++) {
                     // create an Document object
                     $modeldocs = new Documents();
                     $modeldocs->image = $image[$i];
                     if (!$modeldocs->image->getError()) {
                         // name is formed by date(day+month+year+hour+minutes+seconds+dayofyear+microtime())
                         $this->tmpFileName = str_replace(" ", "", date('dmYHis-z-') . microtime());
                         // set the extension file uploaded
                         $extension = $modeldocs->image->getExtensionName();
                         // if no error saving file
                         if ($modeldocs->image->saveAs(self::FOLDERIMAGES . $this->tmpFileName . '.' . $extension)) {
                             $modeldocs->project_id = $project;
                             $modeldocs->document_name = substr($modeldocs->image->getName(), 0, 30);
                             $modeldocs->document_description = $model->comment_text;
                             $modeldocs->document_path = self::FOLDERIMAGES . $this->tmpFileName . '.' . $extension;
                             $modeldocs->document_revision = '1';
                             $modeldocs->document_uploadDate = date("Y-m-d");
                             $modeldocs->document_type = $modeldocs->image->getType();
                             $modeldocs->document_baseRevision = date('dmYHis');
                             $modeldocs->user_id = Yii::app()->user->id;
                             $modeldocs->comment_id = $model->primaryKey;
                             // save file uploaded as document
                             if ($modeldocs->save()) {
                                 Yii::app()->user->setFlash('CommentMessageSuccess', $modeldocs->image->getName() . " " . Yii::t('comments', 'UploadOk'));
                             } else {
                                 Yii::app()->user->setFlash('CommentMessage', $modeldocs->getErrors());
                             }
                         } else {
                             Yii::app()->user->setFlash('CommentMessage', $modeldocs->image->getName() . " " . Yii::t('comments', 'UploadError'));
                         }
                     } else {
                         Yii::app()->user->setFlash('CommentMessage', $modeldocs->image->error . " " . Yii::t('comments', 'UploadCheckErrors'));
                     }
                 }
             }
             // save log
             $attributes = array('log_date' => date("Y-m-d G:i:s"), 'log_activity' => 'CommentPosted', 'log_resourceid' => $model->comment_resourceid, 'log_type' => Logs::LOG_COMMENTED, 'log_commentid' => $model->primaryKey, 'user_id' => Yii::app()->user->id, 'module_id' => $module->module_name, 'project_id' => $project);
             Logs::model()->saveLog($attributes);
             // find project managers to sent comment via mail
             $recipientsList = array();
             $ProjectManagers = Projects::model()->findManagersByProject($project);
             $managersArray = array();
             foreach ($ProjectManagers as $manager) {
                 $managersArray['email'] = $manager->user_email;
                 $managersArray['name'] = $manager->CompleteName;
                 array_push($recipientsList, $managersArray);
             }
             // find task owners to send comment via mail
             if ($module->module_name == 'tasks') {
                 $collaborators = Projects::model()->findAllUsersByProject($project);
                 $ColaboratorsArray = array();
                 foreach ($collaborators as $colaborator) {
                     $ColaboratorsArray['email'] = $colaborator->user_email;
                     $ColaboratorsArray['name'] = $colaborator->CompleteName;
                     // avoid to repeat email address
                     if (!in_array($ColaboratorsArray, $recipientsList)) {
                         array_push($recipientsList, $ColaboratorsArray);
                     }
                 }
             }
             // finding resource title
             switch ($module->module_name) {
                 case "budgets":
                     $resourceModelTitle = Budgets::model()->findByPk($model->comment_resourceid)->budget_title;
                     break;
                 case "invoices":
                     $resourceModelTitle = Invoices::model()->findByPk($model->comment_resourceid)->invoice_number;
                     break;
                 case "expenses":
                     $resourceModelTitle = Expenses::model()->findByPk($model->comment_resourceid)->expense_name;
                     break;
                 case "documents":
                     $resourceModelTitle = Documents::model()->findByPk($model->comment_resourceid)->document_name;
                     break;
                 case "milestones":
                     $resourceModelTitle = Milestones::model()->findByPk($model->comment_resourceid)->milestone_title;
                     break;
                 case "cases":
                     $resourceModelTitle = Cases::model()->findByPk($model->comment_resourceid)->case_name;
                     break;
                 case "tasks":
                     $resourceModelTitle = Tasks::model()->findByPk($model->comment_resourceid)->task_name;
                     break;
                 default:
                     $resourceModelTitle = "{empty}";
                     break;
             }
             // get project information
             $project = Projects::model()->findByPk($project);
             // prepare template to send via email
             $str = $this->renderPartial('//templates/comments/created', array('model' => $model, 'projectName' => $project->project_name, 'userposted' => Yii::app()->user->CompleteName, 'resourceTitle' => $resourceModelTitle, 'moduleName' => Yii::t('modules', $module->module_name), 'applicationName' => Yii::app()->name, 'applicationUrl' => Yii::app()->createAbsoluteUrl($module->module_name . '/view', array('id' => $model->comment_resourceid))), true);
             Yii::import('application.extensions.phpMailer.yiiPhpMailer');
             $mailer = new yiiPhpMailer();
             $subject = Yii::t('email', 'CommentPosted') . " - " . $project->project_name . " - " . Yii::t('modules', $module->module_name);
             $mailer->pushMail($subject, $str, $recipientsList, Emails::PRIORITY_NORMAL);
         } else {
             Yii::app()->user->setFlash('CommentMessage', Yii::t('comments', 'RequiredComment'));
         }
     }
     $this->redirect(Yii::app()->createUrl($_GET['module'] . '/' . $_GET['action'], array('id' => $_GET['id'], '#' => 'comment-' . $model->primaryKey)));
 }
예제 #27
0
 public function saveItem()
 {
     $cat_id = Input::get('cat_id');
     $item_id = Input::get('id');
     //获取表单
     if ($cat_id == 0) {
         //新闻编辑
         $title = Input::get('title');
         $content = Input::get('content');
         $abstract = Input::get('abstract');
         $item = News::find($item_id);
     } else {
         if ($cat_id == 1) {
             //项目编辑
             $title = Input::get('title');
             $content = Input::get('content');
             $abstract = Input::get('abstract');
             $begin_time = Input::get('begin_time');
             $end_time = Input::get('end_time');
             $item = Researches::find($item_id);
         } else {
             if ($cat_id == 2) {
                 //通知编辑
                 //
                 $title = Input::get('title');
                 $content = Input::get('content');
                 $item = Notices::find($item_id);
             } else {
                 if ($cat_id == 3) {
                     //课程编辑
                     $course_name = Input::get('course_name');
                     $course_info = Input::get('course_info');
                     $teacher_address = Input::get('teacher_address');
                     $teacher_mail = Input::get('teacher_mail');
                     $TA_name = Input::get('TA_name');
                     $TA_address = Input::get('TA_address');
                     $TA_mail = Input::get('TA_mail');
                     $item = Courses::find($item_id);
                     $homeworks = Courses::find($item_id)->homework;
                     $coursewares = Courses::find($item_id)->courseware;
                     $course_notices = Courses::find($item_id)->comments;
                     foreach ($course_notices as $notice) {
                         $update_notice = Comments::find($notice->id);
                         $update_notice->comment = Input::get('course_notice_content' . $notice->id);
                         $update_notice->updated_at = date("Y-m-d H:i:s");
                         $update_notice->save();
                     }
                     foreach ($homeworks as $homework) {
                         //对已有项进行编辑
                         $delete_or_not = Input::get('homework_delete' . $homework->id);
                         if ($delete_or_not) {
                             //如果标记为删除则将已有作业进行删除
                             $delete_item = Homework::find($homework->id);
                             $delete_item->delete();
                         } else {
                             $update_item = Homework::find($homework->id);
                             $update_item->homework_item = Input::get('homework_label' . $homework->id);
                             $update_item->submit_deadline = Input::get('homework_submit_time' . $homework->id);
                             $update_item->deliver_deadline = Input::get('homework_deliver_time' . $homework->id);
                             $update_item->updated_at = date("Y-m-d H:i:s");
                             $update_item->save();
                         }
                     }
                     foreach ($coursewares as $courseware) {
                         $update_item = Courseware::find($courseware->id);
                         $update_item->label = Input::get('courseware_label' . $courseware->id);
                         $update_file_source = 'courseware_ppt' . $courseware->id;
                         $new_source = HomeController::upload_course($item_id, $update_file_source);
                         if ($new_source != "") {
                             //跟新源的同时将旧的课件删除
                             HomeController::delete_file($update_item->source);
                             $update_item->source = $new_source;
                         } else {
                         }
                         $update_item->updated_at = date("Y-m-d H:i:s");
                         $update_item->save();
                     }
                 }
             }
         }
     }
     //保存数据
     if ($item) {
         //表中已经存在该条目
         if ($cat_id == 0) {
             //新闻编辑
             $item->title = $title;
             $item->content = $content;
             $item->abstract = $abstract;
             $item->save();
             return Redirect::to(URL::to('/news-detail', [$item_id]));
         } else {
             if ($cat_id == 1) {
                 //项目编辑
                 $item->title = $title;
                 $item->content = $content;
                 $item->abstract = $abstract;
                 $item->begin_time = $begin_time;
                 $item->end_time = $end_time;
                 $item->save();
                 return Redirect::to(URL::to('/research-detail', [$item_id]));
             } else {
                 if ($cat_id == 2) {
                     //通知编辑
                     $item->title = $title;
                     $item->content = $content;
                     $item->save();
                     return Redirect::to(URL::to('/notice-detail', [$item_id]));
                 } else {
                     if ($cat_id == 3) {
                         //课程编辑
                         $item->course_name = $course_name;
                         $item->course_info = $course_info;
                         $item->teacher_address = $teacher_address;
                         $item->teacher_mail = $teacher_mail;
                         $item->TA_name = $TA_name;
                         $item->TA_address = $TA_address;
                         $item->TA_mail = $TA_mail;
                         $item->save();
                         $course_notices_add_count = Input::get('course_notice_add_count');
                         if ($course_notices_add_count) {
                             //增加新的通知
                             for ($i = 1; $i <= $course_notices_add_count; $i++) {
                                 $add_or_not = Input::get('course_notice_add_or_not' . $i);
                                 if (!$add_or_not) {
                                     $notice = new Comments();
                                     $notice->course_id = $item_id;
                                     $notice->comment = Input::get('course_notice_add_content' . $i);
                                     $notice->created_at = date("Y-m-d H:i:s");
                                     $notice->updated_at = date("Y-m-d H:i:s");
                                     $notice->save();
                                 }
                             }
                         }
                         $homework_add_count = Input::get('homework_add_count');
                         if ($homework_add_count) {
                             //当添加了新的作业,将其添加到homework数据库中
                             for ($i = 1; $i <= $homework_add_count; $i++) {
                                 $add_or_not = Input::get('homework_add_or_not' . $i);
                                 if (!$add_or_not) {
                                     $homework = new Homework();
                                     $homework->course_id = $item_id;
                                     $homework->homework_item = Input::get('homework_add_item' . $i);
                                     $homework->submit_deadline = Input::get('homework_add_submit_time' . $i);
                                     $homework->deliver_deadline = Input::get('homework_add_deliver_time' . $i);
                                     $homework->created_at = date("Y-m-d H:i:s");
                                     $homework->updated_at = date("Y-m-d H:i:s");
                                     $homework->save();
                                 }
                             }
                         }
                         $courseware_add_count = Input::get('courseware_add_count');
                         if ($courseware_add_count) {
                             //当添加了新的课件,将其添加到courseware表中
                             for ($i = 1; $i <= $courseware_add_count; $i++) {
                                 $courseware = new Courseware();
                                 $courseware->course_id = $item_id;
                                 $courseware->label = Input::get('courseware_add_label' . $i);
                                 //先将课件上传到数据库中
                                 $file_source = 'courseware_add_source' . $i;
                                 $courseware->source = HomeController::upload_course($item_id, $file_source);
                                 $courseware->created_at = date("Y-m-d H:i:s");
                                 $courseware->updated_at = date("Y-m-d H:i:s");
                                 $courseware->save();
                             }
                         }
                         return Redirect::to(URL::to('/course', [$item_id]));
                     }
                 }
             }
         }
     } else {
         //对已有条目进行更新
         if ($cat_id == 0) {
             //新闻条目
             News::insert(['title' => $title, 'abstract' => $abstract, 'content' => $content]);
             $item = News::all()->last();
             return Redirect::to(URL::to('/news-detail', [$item->id]));
         } else {
             if ($cat_id == 1) {
                 //项目条目
                 Researches::insert(['title' => $title, 'abstract' => $abstract, 'content' => $content, 'begin_time' => $begin_time, 'end_time' => $end_time]);
                 $item = Researches::all()->last();
                 return Redirect::to(URL::to('/research-detail', [$item->id]));
             } else {
                 if ($cat_id == 2) {
                     //通知编辑
                     Notices::insert(['title' => $title, 'content' => $content]);
                     $item = Notices::all()->last();
                     return Redirect::to(URL::to('/notice-detail', [$item->id]));
                 } else {
                     if ($cat_id == 3) {
                         Courses::insert(['course_name' => $course_name, 'course_info' => $course_info, 'teacher_address' => $teacher_address, 'TA_name' => $TA_name, 'TA_address' => $TA_address]);
                         $item = Courses::all()->last();
                         return Redirect::to(URL::to('/course', [$item->id]));
                     }
                 }
             }
         }
     }
     //return View::make('/news-detail',[$item_id]);
 }
예제 #28
0
    public function actionAnswer()
    {
        $model = new Comments();
        $model->answer = $_POST['value'];
        $model->question_id = $_POST['qId'];
        $model->user_id = Yii::app()->session['userId'];
        if ($model->save(false)) {
            // echo "success";
        }
        $questionDetail = Yii::app()->db->createCommand()->select('*')->from('comments u')->join('users p', 'p.id=u.user_id')->where('u.question_id=:id', array(':id' => $_POST['qId']))->queryAll();
        $html = '';
        // echo"<pre>";print_r($questionDetail);die;
        foreach ($questionDetail as $questionDetail) {
            $html .= '<div class="well">
									<address>
									' . $questionDetail['answer'] . '
									 </address>
									<address>
									<strong>' . $questionDetail['name'] . '</strong><br>
									<a href="mailto:#">
									' . $questionDetail['creation_Datetime'] . ' </a>
									</address>
								</div>';
        }
        echo $html;
    }
예제 #29
0
     */
    function save()
    {
        global $DB, $ID, $USER, $CURRENT, $CONFIG;
        $_POST->setType('commentbody', 'any');
        $_POST->setType('author', 'string');
        if ($USER->ID === NOBODY) {
            if ($CONFIG->comments->CAPTCHA_for_guests && !reCAPTCHA::verify()) {
                Flash::create(__('CAPTCHA verification failed'), 'warning');
                return false;
            }
            $ctype = $CONFIG->comments->guest_comments;
        } else {
            $ctype = $CONFIG->comments->user_comments;
        }
        if ($ctype == 'none') {
            return false;
        }
        $DB->comments->insert(array('id' => $ID, 'comment' => $_POST['commentbody'], 'author' => $_POST['author'] && $USER->ID === NOBODY ? $_POST['author'] : $USER->ID, 'ip' => $_SERVER['REMOTE_ADDR'], 'authd_by' => $CURRENT->mayI(EDIT) ? $USER->ID : ($ctype == 'review' ? 0 : $USER->ID), 'created' => time()));
        $_POST->clear('commentbody', 'author');
        return true;
    }
}
global $CONFIG;
$CONFIG->comments->setType('CAPTCHA_for_guests', 'check');
$CONFIG->comments->setType('guest_comments', 'select', array('none' => 'None', 'review' => 'Review comments', 'allow' => 'Allow all comments (not recommended)'));
$CONFIG->comments->setType('user_comments', 'select', array('none' => 'None', 'review' => 'Review comments', 'allow' => 'Allow all comments'));
$_POST->setType('commentForm', 'any');
if ($_POST['commentForm']) {
    Comments::save();
}
 /**
  * Displays a particular model.
  */
 public function actionChangeStatus()
 {
     if (Yii::app()->user->checkAccess('changeStatusTasks')) {
         if (Yii::app()->request->isAjaxRequest && isset($_POST)) {
             $model = $this->loadModel($_REQUEST['id']);
             $model->status_id = $_POST['changeto'];
             // Set startDate or endDate for real dates to work
             switch ($model->status_id) {
                 case Status::STATUS_ACCEPTED:
                     $model->task_startDate = date("Y-m-d");
                     //new CDbExpression('NOW()');
                     break;
                 case Status::STATUS_CLOSED:
                     $model->task_endDate = date("Y-m-d");
                     //new CDbExpression('NOW()');
                     break;
                 default:
                     break;
             }
             if ($model->save()) {
                 // Guardar log
                 $attributes = array('log_date' => date("Y-m-d G:i:s"), 'log_activity' => 'TaskStatusChanged', 'log_resourceid' => $model->task_id, 'log_type' => 'updated', 'user_id' => Yii::app()->user->id, 'module_id' => Yii::app()->controller->id, 'project_id' => $model->project_id);
                 Logs::model()->saveLog($attributes);
                 $modelComment = new Comments();
                 $modelComment->comment_date = date("Y-m-d G:i:s");
                 $modelComment->comment_text = Status::STATUS_COMMENT . ": " . $model->Status->status_id;
                 $modelComment->user_id = Yii::app()->user->id;
                 $modelComment->module_id = Modules::model()->find(array('condition' => 't.module_name = :module_name', 'params' => array(':module_name' => $this->getId())))->module_id;
                 $modelComment->comment_resourceid = $model->task_id;
                 $modelComment->save(false);
                 //$Users = Projects::model()->findManagersByProject($model->project_id);
                 $Users = Projects::model()->findAllUsersByProject($model->project_id);
                 $recipientsList = array();
                 foreach ($Users as $client) {
                     $recipientsList[] = array('name' => $client->CompleteName, 'email' => $client->user_email);
                 }
                 $subject = Yii::t('email', 'TaskStatusChanged') . " - " . $model->task_name;
                 $str = $this->renderPartial('//templates/tasks/statusChanged', array('task' => $model, 'username' => Users::model()->findByPk(Yii::app()->user->id)->completeName, 'task_url' => "http://" . $_SERVER['SERVER_NAME'] . Yii::app()->createUrl('tasks/view', array('id' => $model->task_id)), 'applicationName' => Yii::app()->name, 'applicationUrl' => "http://" . $_SERVER['SERVER_NAME'] . Yii::app()->request->baseUrl), true);
                 Yii::import('application.extensions.phpMailer.yiiPhpMailer');
                 $mailer = new yiiPhpMailer();
                 $mailer->pushMail($subject, $str, $recipientsList, Emails::PRIORITY_NORMAL);
                 echo "Status has been changed.";
             } else {
                 echo "Something wrong, can not change status.";
                 print_r($model->getErrors());
             }
             Yii::app()->end();
         } else {
             throw new CHttpException(403, Yii::t('site', '403_Error'));
         }
     } else {
         throw new CHttpException(403, Yii::t('site', '403_Error'));
     }
 }