/**
  * Saves a post to the databases
  *
  * @permissions right1
  * @return string
  */
 protected function actionPostComment()
 {
     if (!$this->validateForm()) {
         return $this->actionList();
     }
     $strSystemidfilter = "";
     if ($this->getSystemid() != "") {
         $strSystemidfilter = $this->getSystemid();
     }
     if (class_module_pages_page::getPageByName($this->getPagename()) !== null) {
         $strPagefilter = class_module_pages_page::getPageByName($this->getPagename())->getSystemid();
     } else {
         $strPagefilter = "";
     }
     $objPost = new class_module_postacomment_post();
     $objPost->setStrUsername($this->getParam("comment_name"));
     $objPost->setStrTitle($this->getParam("comment_subject"));
     $objPost->setStrComment($this->getParam("comment_message"));
     $objPost->setStrAssignedPage($strPagefilter);
     $objPost->setStrAssignedSystemid($strSystemidfilter);
     $objPost->setStrAssignedLanguage($this->getStrPortalLanguage());
     $objPost->updateObjectToDb();
     $this->flushPageFromPagesCache($this->getPagename());
     $strMailtext = $this->getLang("new_comment_mail") . "\r\n\r\n" . $objPost->getStrComment() . "\r\n";
     $strMailtext .= class_link::getLinkAdminHref("postacomment", "edit", "&systemid=" . $objPost->getSystemid(), false);
     $objMessageHandler = new class_module_messaging_messagehandler();
     $arrGroups = array();
     $allGroups = class_module_user_group::getObjectList();
     foreach ($allGroups as $objOneGroup) {
         if (class_rights::getInstance()->checkPermissionForGroup($objOneGroup->getSystemid(), class_rights::$STR_RIGHT_EDIT, $this->getObjModule()->getSystemid())) {
             $arrGroups[] = $objOneGroup;
         }
     }
     $objMessage = new class_module_messaging_message();
     $objMessage->setStrBody($strMailtext);
     $objMessage->setObjMessageProvider(new class_messageprovider_postacomment());
     $objMessageHandler->sendMessageObject($objMessage, $arrGroups);
     $this->portalReload(_indexpath_ . "?" . $this->getHistory(1));
     return "";
 }
 /**
  * saves a post in the database and returns the post as html.
  * In case of missing fields, the form is returned again
  *
  * @return string
  * @permissons right1
  */
 protected function actionSavePost()
 {
     $strXMLContent = "";
     //validate needed fields
     if (!$this->validateForm()) {
         //Create form to reenter values
         $strTemplateID = $this->objTemplate->readTemplate("/module_postacomment/" . $this->getParam("comment_template"), "postacomment_form");
         $arrForm = array();
         $arrForm["formaction"] = class_link::getLinkPortalHref($this->getPagename(), "", "postComment", "", $this->getSystemid());
         $arrForm["comment_name"] = $this->getParam("comment_name");
         $arrForm["comment_subject"] = $this->getParam("comment_subject");
         $arrForm["comment_message"] = $this->getParam("comment_message");
         $arrForm["comment_template"] = $this->getParam("comment_template");
         $arrForm["comment_systemid"] = $this->getParam("comment_systemid");
         $arrForm["comment_page"] = $this->getParam("comment_page");
         $arrForm["validation_errors"] = $this->strErrors;
         foreach ($arrForm as $strKey => $strValue) {
             if (uniStrpos($strKey, "comment_") !== false) {
                 $arrForm[$strKey] = htmlspecialchars($strValue, ENT_QUOTES, "UTF-8", false);
             }
         }
         //texts
         $arrForm["postacomment_write_new"] = $this->getLang("postacomment_write_new");
         $arrForm["form_name_label"] = $this->getLang("form_name_label");
         $arrForm["form_subject_label"] = $this->getLang("form_subject_label");
         $arrForm["form_message_label"] = $this->getLang("form_message_label");
         $arrForm["form_captcha_label"] = $this->getLang("commons_captcha");
         $arrForm["form_captcha_reload_label"] = $this->getLang("commons_captcha_reload");
         $arrForm["form_submit_label"] = $this->getLang("form_submit_label");
         $strXMLContent .= $this->fillTemplate($arrForm, $strTemplateID);
     } else {
         //save the post to the db
         //pageid or systemid to filter?
         $strSystemidfilter = $this->getParam("comment_systemid");
         if (class_module_pages_page::getPageByName($this->getParam("comment_page")) !== null) {
             $strPagefilter = class_module_pages_page::getPageByName($this->getParam("comment_page"))->getSystemid();
         } else {
             $strPagefilter = "";
         }
         $objPost = new class_module_postacomment_post();
         $objPost->setStrUsername($this->getParam("comment_name"));
         $objPost->setStrTitle($this->getParam("comment_subject"));
         $objPost->setStrComment($this->getParam("comment_message"));
         $objPost->setStrAssignedPage($strPagefilter);
         $objPost->setStrAssignedSystemid($strSystemidfilter);
         $objPost->setStrAssignedLanguage($this->getStrPortalLanguage());
         $objPost->updateObjectToDb();
         $this->flushPageFromPagesCache($this->getPagename());
         $strMailtext = $this->getLang("new_comment_mail") . "\r\n\r\n" . $objPost->getStrComment() . "\r\n";
         $strMailtext .= class_link::getLinkAdminHref("postacomment", "edit", "&systemid=" . $objPost->getSystemid(), false);
         $objMessageHandler = new class_module_messaging_messagehandler();
         $arrGroups = array();
         $allGroups = class_module_user_group::getObjectList();
         foreach ($allGroups as $objOneGroup) {
             if (class_rights::getInstance()->checkPermissionForGroup($objOneGroup->getSystemid(), class_rights::$STR_RIGHT_EDIT, $this->getObjModule()->getSystemid())) {
                 $arrGroups[] = $objOneGroup;
             }
         }
         $objMessageHandler->sendMessage($strMailtext, $arrGroups, new class_messageprovider_postacomment());
         //reinit post -> encoded entities
         $objPost->initObject();
         //load the post as a new post to add it at top of the list
         $arrOnePost = array();
         $arrOnePost["postacomment_post_name"] = $objPost->getStrUsername();
         $arrOnePost["postacomment_post_subject"] = $objPost->getStrTitle();
         $arrOnePost["postacomment_post_message"] = $objPost->getStrComment();
         $arrOnePost["postacomment_post_systemid"] = $objPost->getSystemid();
         $arrOnePost["postacomment_post_date"] = timeToString($objPost->getIntDate(), true);
         $strTemplateID = $this->objTemplate->readTemplate("/module_postacomment/" . $this->getParam("comment_template"), "postacomment_post");
         $strXMLContent .= $this->objTemplate->fillTemplate($arrOnePost, $strTemplateID);
     }
     class_response_object::getInstance()->setStrResponseType(class_http_responsetypes::STR_TYPE_JSON);
     return $strXMLContent;
 }