/**
  * Edit comment (ajax)
  */
 public function editAction()
 {
     $request = $this->getRequest();
     $user_role = Zend_Auth::getInstance()->getIdentity()->role;
     $comment_id = (int) $request->getParam('id', false);
     $Comments = new Application_Model_Comments();
     $comment = $Comments->getComment($comment_id);
     if (!$comment && !isset($comment['content'])) {
         $this->getHelper('json')->sendJson($this->view->translate('Resource not available'));
         return;
     }
     // check if my comment or an admin
     if ($Comments->getCommentAuthorId($comment_id) != Zend_Auth::getInstance()->getIdentity()->id && ($user_role != 'admin' && $user_role != 'reviewer')) {
         $this->getHelper('json')->sendJson($this->view->translate('Error - not permitted'));
         return;
     }
     // load and fill up form
     $edit_comment_form = new Application_Form_EditComment();
     $edit_comment_form->getElement('comment')->setValue($comment['content']);
     // get and render form only
     if ($request->isPost() && $request->getParam('form_render')) {
         $edit_comment_form->setAction(Zend_Controller_Front::getInstance()->getBaseUrl() . '/comments/edit/id/' . $comment_id);
         $this->getHelper('json')->sendJson($edit_comment_form->render());
         return;
     }
     if ($request->isPost() && $edit_comment_form->isValid($_POST)) {
         $comment_content = $edit_comment_form->getElement('comment')->getValue();
         $comment_content = Application_Plugin_Common::prepareComment($comment_content);
         // drop on false
         if ($comment_content === false) {
             $this->getHelper('json')->sendJson($this->view->translate('Error - not permitted'));
             return;
         }
         $ret = $Comments->updateComment($comment_id, $comment_content);
         $this->getHelper('json')->sendJson($this->view->RenderOutput($comment_content, 'comment'));
         return;
     }
     $this->getHelper('json')->sendJson($this->view->translate('Error - not permitted'));
     return;
 }
 /**
  * Edit comment
  */
 public function editcommentAction()
 {
     $Reports = new Application_Model_Reports();
     $total_counts = $Reports->getTotalCount();
     $this->buildMenu($total_counts);
     $request = $this->getRequest();
     $page = (int) $request->getParam('page');
     $comment_id = (int) $request->getParam('comment');
     $Comments = new Application_Model_Comments();
     $comment = $Comments->getComment($comment_id);
     // load and fill up form
     $edit_comment_form = new Application_Form_EditComment();
     $edit_comment_form->getElement('comment')->setValue($comment['content']);
     $this->view->edit_comment_form = $edit_comment_form;
     if ($request->isPost() && $edit_comment_form->isValid($_POST)) {
         $comment_content = $edit_comment_form->getElement('comment')->getValue();
         $comment_content = Application_Plugin_Common::prepareComment($comment_content);
         // drop on false
         if ($comment_content === false) {
             return;
         }
         $Comments->updateComment($comment_id, $comment_content);
         Application_Plugin_Alerts::success($this->view->translate('Comment updated'));
         if ($page > 0) {
             $this->redirect('reports/reviewcomments/page/' . $page);
         }
     }
 }