/**
  * Returns a list of all categories and all postacomment
  * The list could be filtered by categories
  *
  * @return string
  * @permissions view
  * @autoTestable
  */
 protected function actionList()
 {
     //a small filter would be nice...
     $strReturn = $this->objToolkit->formHeader(getLinkAdminHref($this->arrModule["modul"], "list"));
     $arrPages = array();
     $arrPages[""] = "---";
     foreach (class_module_pages_page::getAllPages() as $objOnePage) {
         $arrPages[$objOnePage->getSystemid()] = $objOnePage->getStrName();
     }
     $strReturn .= $this->objToolkit->formInputDropdown("filterId", $arrPages, $this->getLang("postacomment_filter"), $this->getParam("filterId"));
     $strReturn .= $this->objToolkit->formInputSubmit($this->getLang("postacomment_dofilter"));
     $strReturn .= $this->objToolkit->formClose();
     $strReturn .= $this->objToolkit->divider();
     $objArraySectionIterator = new class_array_section_iterator(class_module_postacomment_post::getNumberOfPostsAvailable(false, $this->getParam("filterId")));
     $objArraySectionIterator->setPageNumber((int) ($this->getParam("pv") != "" ? $this->getParam("pv") : 1));
     $objArraySectionIterator->setArraySection(class_module_postacomment_post::loadPostList(false, $this->getParam("filterId"), false, "", $objArraySectionIterator->calculateStartPos(), $objArraySectionIterator->calculateEndPos()));
     $strReturn .= $this->renderList($objArraySectionIterator);
     return $strReturn;
 }
 /**
  * Removes the elements / modules handled by the current installer.
  * Use the reference param to add a human readable logging.
  *
  * @param string &$strReturn
  *
  * @return bool
  */
 public function remove(&$strReturn)
 {
     //delete the page-element
     $objElement = class_module_pages_element::getElement("postacomment");
     if ($objElement != null) {
         $strReturn .= "Deleting page-element 'postacomment'...\n";
         $objElement->deleteObjectFromDatabase();
     } else {
         $strReturn .= "Error finding page-element 'postacomment', aborting.\n";
         return false;
     }
     /** @var class_module_postacomment_post $objOneObject */
     foreach (class_module_postacomment_post::getObjectList() as $objOneObject) {
         $strReturn .= "Deleting object '" . $objOneObject->getStrDisplayName() . "' ...\n";
         if (!$objOneObject->deleteObjectFromDatabase()) {
             $strReturn .= "Error deleting object, aborting.\n";
             return false;
         }
     }
     //delete the module-node
     $strReturn .= "Deleting the module-registration...\n";
     $objModule = class_module_system_module::getModuleByName($this->objMetadata->getStrTitle(), true);
     if (!$objModule->deleteObjectFromDatabase()) {
         $strReturn .= "Error deleting module, aborting.\n";
         return false;
     }
     //delete the tables
     foreach (array("postacomment") as $strOneTable) {
         $strReturn .= "Dropping table " . $strOneTable . "...\n";
         if (!$this->objDB->_pQuery("DROP TABLE " . $this->objDB->encloseTableName(_dbprefix_ . $strOneTable) . "", array())) {
             $strReturn .= "Error deleting table, aborting.\n";
             return false;
         }
     }
     return true;
 }
 /**
  * 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;
 }
 /**
  * Loads and renders the list of comments provided by the current news-entry
  *
  * @param string $strNewsSystemid
  * @param string $strTemplateSection
  *
  * @return array
  */
 private function loadPostacomments($strNewsSystemid, $strTemplateSection)
 {
     if ($this->isPostacommentOnTemplate($this->arrElementData["news_template"], $strTemplateSection)) {
         $objPacModule = class_module_system_module::getModuleByName("postacomment");
         $arrReturn = array();
         if ($objPacModule != null) {
             $arrComments = class_module_postacomment_post::loadPostList(false, "", $strNewsSystemid, $this->getStrPortalLanguage());
             //the rendered list
             $objPacPortal = new class_module_postacomment_portal(array("char1" => "postacomment_ajax.tpl"));
             $objPacPortal->setSystemid($strNewsSystemid);
             $objPacPortal->setStrPagefilter("");
             $strListCode = $objPacPortal->action();
             $arrReturn["nrOfComments"] = count($arrComments);
             $arrReturn["commentList"] = $strListCode;
         } else {
             return null;
         }
         return $arrReturn;
     }
     return null;
 }