/** * Will render a specified form, the name of the form given by the first parameter; * * This method will render one of the forms for our object, invoked by giving the proper form identifier to the current form. * We have chosen this method of invoking forms, because we just had too many this->renderSomethingMethod (), which really had * an impact on code massiveness. Also, having code organized in switch/case statements leads us to be able to share common * settings between different forms, as we've done with the methods defined in the __CALL method above; * * For example, if we wanted to share some common configuration between a create and an edit form, we could have introduced * two switches in this method, one that would have set the common options, and the second, would have just passed through * again, and get the already set configuration options, using them. This means that if we needed to change behavior of * some interconnected forms, that would mean modifying the needed code one place only, which is a big advantage over * having separated methods for each form. Maybe if we extended this object, you guys could understand the functionality; * * @param string $objFormToRender The name of the form to render; * @return mixed Depends on the rendered form if it returns something or not; */ public function renderForm(S $objFormToRender, A $objFormArray = NULL) { // Make them defaults ... if ($objFormArray == NULL) { $objFormArray = new A(); } // Do a switch ... switch ($objFormToRender) { case 'articleSearch': // Get some predefines; if (isset($_GET[ADMIN_ACTION_BY])) { $objSearchBy = $_GET[ADMIN_ACTION_BY]; } else { $objSearchBy = new S(); } if (isset($_GET[ADMIN_ACTION_SEARCH])) { $objSearchWas = $_GET[ADMIN_ACTION_SEARCH]; } else { $objSearchWas = new S(); } // Do some work; if ($this->checkPOST(new S('search_submit'))->toBoolean() == TRUE) { if ($this->getPOST(new S('search_by'))->toLength()->toInt() == 0) { if (isset($_GET[ADMIN_ACTION_SEARCH])) { // Erase search terms ... $this->setHeaderKey(URL::rewriteURL(new A(array(ADMIN_ACTION_SEARCH, ADMIN_ACTION_BY))), new S('Location')); } // Set an input error; $this->setErrorOnInput(new S('search_by'), new S(ARTICLES_SEARCH_FIELD_IS_EMPTY)); // Unset the post ... $this->unsetPOST(); } else { // Get what to search and where ... $objWhatToSearch = $this->getPOST(new S('search_by')); $objWhereToSearch = $this->getPOST(new S('search_field')); // And go there ... $this->setHeaderKey(URL::rewriteURL(new A(array(ADMIN_ACTION_SEARCH, ADMIN_ACTION_BY)), new A(array($objWhatToSearch, $objWhereToSearch))), new S('Location')); } } // Check the option that has been selected; $objWasSelected = new A(array(new B($objSearchBy == ARTICLES_SEARCH_TITLE ? TRUE : FALSE), new B($objSearchBy == ARTICLES_SEARCH_CONTENT ? TRUE : FALSE), new B($objSearchBy == ARTICLES_SEARCH_CATEGORY ? TRUE : FALSE), new B($objSearchBy == ARTICLES_SEARCH_TAGS ? TRUE : FALSE), new B($objSearchBy == ARTICLES_SEARCH_EXCERPT ? TRUE : FALSE))); // Do the form, make it happen; $this->setMethod(new S('POST'))->setEnctype(new S('multipart/form-data'))->setFieldset(new S(ARTICLES_SEARCH_BY))->setName($objFormToRender)->setInputType(new S('text'))->setInputInfoMessage($this->getHELP($objFormToRender))->setName(new S('search_by'))->setvalue($objSearchWas)->setLabel(new S(ARTICLES_SEARCH_BY))->setJSRegExpReplace(new S('[^a-zA-Z0-9 -]'))->setContainerDiv(new B(TRUE))->setInputType(new S('select'))->setName(new S('search_field'))->setContainerDiv(new B(TRUE))->setLabel(new S(ARTICLES_SEARCH_IN))->setInputType(new S('option'))->setName(new S('article_title'))->setValue(new S(ARTICLES_SEARCH_TITLE))->setLabel(new S(ARTICLES_SEARCH_TITLE))->setSelected($objWasSelected[0])->setInputType(new S('option'))->setName(new S('article_content'))->setValue(new S(ARTICLES_SEARCH_CONTENT))->setLabel(new S(ARTICLES_SEARCH_CONTENT))->setSelected($objWasSelected[1])->setInputType(new S('option'))->setName(new S('article_category'))->setValue(new S(ARTICLES_SEARCH_CATEGORY))->setLabel(new S(ARTICLES_SEARCH_CATEGORY))->setSelected($objWasSelected[2])->setInputType(new S('option'))->setName(new S('article_tags'))->setValue(new S(ARTICLES_SEARCH_TAGS))->setLabel(new S(ARTICLES_SEARCH_TAGS))->setSelected($objWasSelected[3])->setInputType(new S('option'))->setName(new S('article_excerpt'))->setValue(new S(ARTICLES_SEARCH_EXCERPT))->setLabel(new S(ARTICLES_SEARCH_EXCERPT))->setSelected($objWasSelected[4])->setInputType(new S('submit'))->setContainerDiv(new B(TRUE))->setValue(new S(ARTICLES_SEARCH_BY))->setName(new S('search_submit'))->setFormEndAndExecute(new B(TRUE)); break; case 'articleCreate': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(); // Do some work; if ($this->checkPOST(self::$objArticleTableFTitle)->toBoolean() == TRUE) { // Set what to check $objToCheck = $this->getPOST(self::$objArticleTableFTitle); if ($objToCheck->toLength()->toInt() == 0) { $this->setErrorOnInput(self::$objArticleTableFTitle, new S(ARTICLES_TITLE_CANNOT_BE_EMPTY)); } else { // Check title is unique; if ($this->checkArticleTitleIsUnique($objToCheck)->toBoolean() == FALSE) { $this->setErrorOnInput(self::$objArticleTableFTitle, new S(ARTICLES_TITLE_MUST_BE_UNIQUE)); } } } if ($this->checkPOST(self::$objArticleTableFContent)->toBoolean() == TRUE) { // Set what to check $objToCheck = $this->getPOST(self::$objArticleTableFContent); if ($objToCheck->toLength()->toInt() == 0) { $this->setErrorOnInput(self::$objArticleTableFContent, new S(ARTICLES_CONTENT_CANNOT_BE_EMPTY)); } } // Check & Get; $this->getAjaxErrors(); // Do the form, make it happen; $this->setMethod(new S('POST'))->setEnctype(new S('multipart/form-data'))->setFieldset(new S(ARTICLES_ADD_ARTICLE))->setSQLAction(new S('update'))->setTableName(self::$objArticleTable)->setUpdateId(new S('#nextTableAutoIncrement'))->setUpdateField(self::$objArticleTableFId); // Do some extra work; if ((int) $this->ATH->getCurrentUserInfoById(Authentication::$objAuthUsersTableFId)->toString() != 1) { // In case we're not the BIG MAN, we're the author ... $this->setExtraUpdateData(self::$objArticleTableFAuthorId, $this->ATH->getCurrentUserInfoById(Authentication::$objAuthUsersTableFId)); } // Set the published date; $this->setExtraUpdateData(self::$objArticleTableFDatePublished, new S((string) $_SERVER['REQUEST_TIME'])); $this->setExtraUpdateData(self::$objArticleTableFDateUpdated, new S((string) $_SERVER['REQUEST_TIME'])); // Add the URL; if ($this->checkPOST(self::$objArticleTableFTitle)->toBoolean() == TRUE) { $this->setExtraUpdateData(self::$objArticleTableFSEO, URL::getURLFromString(new S($this->getPOST(self::$objArticleTableFTitle) . _U . new S((string) $_SERVER['REQUEST_TIME'])))); } // And go back to regular hours; $this->setName($objFormToRender); if ($this->checkPOST(self::$objArticleTableFTitle)->toBoolean() == TRUE) { $this->setRedirect($objURLToGoBack); } $this->setAJAXEnabledForm(new B(FALSE))->setInputType(new S('submit'))->setValue(new S(ARTICLES_ADD_ARTICLE))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objArticleTableFTags)->setLabel(new S(ARTICLES_TAGS))->setJSRegExpReplace(new S(self::REGEXP_JS_TAGS)); // If we're the BIG MAN, we can set the author of an entry; if ((int) $this->ATH->getCurrentUserInfoById(Authentication::$objAuthUsersTableFId)->toString() == 1) { $this->setInputType(new S('select'))->setName(self::$objArticleTableFAuthorId)->setLabel(new S(ARTICLES_AUTHOR))->setContainerDiv(new B(TRUE)); // Users; (or in this case, authors); foreach ($this->ATH->getUsers() as $k => $v) { $this->setInputType(new S('option'))->setName($v[Authentication::$objAuthUsersTableFId])->setValue($v[Authentication::$objAuthUsersTableFId])->setLabel($v[Authentication::$objAuthUsersTableFUName]); } } // Continue; $this->setInputType(new S('select'))->setLabel(new S(ARTICLES_STATE))->setName(self::$objArticleTableFState)->setContainerDiv(new B(TRUE))->setInputType(new S('option'))->setName(new S('draft'))->setValue(new S((string) self::STATE_DRAFT))->setLabel(new S(ARTICLES_DRAFT))->setInputType(new S('option'))->setName(new S('published'))->setValue(new S((string) self::STATE_PUBLISHED))->setLabel(new S(ARTICLES_PUBLISHED))->setInputType(new S('option'))->setName(new S('pending_review'))->setValue(new S((string) self::STATE_PENDING_REVIEW))->setLabel(new S(ARTICLES_PENDING_REVIEW))->setInputType(new S('option'))->setName(new S('sticky'))->setValue(new S((string) self::STATE_STICKY))->setLabel(new S(ARTICLES_STICKY))->setInputType(new S('select'))->setLabel(new S(ARTICLES_CATEGORY_NAME_LABEL))->setName(self::$objArticleTableFCategoryId)->setContainerDiv(new B(TRUE)); // Categories ... foreach ($this->getCategories() as $k => $v) { $this->setInputType(new S('option'))->setName($v[self::$objMPTT->objIdField])->setValue($v[self::$objMPTT->objIdField])->setLabel(new S(str_repeat('--' . _SP, (int) $v['depth']->toString()) . MPTT::mpttRemoveUnique($v[self::$objMPTT->objNameOfNode]))); } // Continue ... $this->setInputType(new S('select'))->setName(self::$objArticleTableFCanComment)->setLabel(new S(ARTICLES_CAN_COMMENT))->setInputType(new S('option'))->setName(new S('yes'))->setValue(new S('Y'))->setLabel(new S(ARTICLES_CAN_COMMENT_YES))->setINputType(new S('option'))->setName(new S('no'))->setValue(new S('N'))->setLabel(new S(ARTICLES_CAN_COMMENT_NO))->setInputType(new S('text'))->setName(self::$objArticleTableFTitle)->setLabel(new S(ARTICLES_TITLE))->setJSRegExpReplace(new S(self::REGEXP_JS_TITLE))->setContainerDiv(new B(TRUE))->setInputType(new S('textarea'))->setName(self::$objArticleTableFExcerpt)->setLabel(new S(ARTICLES_EXCERPT))->setContainerDiv(new B(TRUE))->setInputType(new S('textarea'))->setName(self::$objArticleTableFContent)->setLabel(new S(ARTICLES_CONTENT))->setTinyMCETextarea(new B(TRUE))->setRows(new S('5'))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; case 'articleEdit': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION, ADMIN_ACTION_ID))); // Do some work; if ($this->checkPOST(self::$objArticleTableFTitle)->toBoolean() == TRUE) { // Set what to check; $objToCheck = $this->getPOST(self::$objArticleTableFTitle); // Check to LENGTH; if ($objToCheck->toLength()->toInt() == 0) { $this->setErrorOnInput(self::$objArticleTableFTitle, new S(ARTICLES_TITLE_CANNOT_BE_EMPTY)); } else { // Check if the posted title is different from the one in the database; if ($this->getArticleInfoById($_GET[ADMIN_ACTION_ID], self::$objArticleTableFTitle) != $objToCheck) { if ($this->checkArticleTitleIsUnique($objToCheck)->toBoolean() == FALSE) { $this->setErrorOnInput(self::$objArticleTableFTitle, new S(ARTICLES_TITLE_MUST_BE_UNIQUE)); } } } } if ($this->checkPOST(self::$objArticleTableFContent)->toBoolean() == TRUE) { // Set what to check $objToCheck = $this->getPOST(self::$objArticleTableFContent); if ($objToCheck->toLength()->toInt() == 0) { $this->setErrorOnInput(self::$objArticleTableFContent, new S(ARTICLES_CONTENT_CANNOT_BE_EMPTY)); } } // Check & Get; $this->getAjaxErrors(); // Do the form, make it happen; $this->setMethod(new S('POST'))->setEnctype(new S('multipart/form-data'))->setFieldset(new S(ARTICLES_EDIT_ARTICLE))->setSQLAction(new S('update'))->setTableName(self::$objArticleTable)->setUpdateId($_GET[ADMIN_ACTION_ID])->setUpdateField(self::$objArticleTableFId)->setName($objFormToRender)->setRedirect($objURLToGoBack)->setAJAXEnabledForm(new B(FALSE)); // Do some extra work; $this->setExtraUpdateData(self::$objArticleTableFDateUpdated, new S((string) $_SERVER['REQUEST_TIME'])); // Add the URL; if ($this->checkPOST(self::$objArticleTableFTitle)->toBoolean() == TRUE) { $this->setExtraUpdateData(self::$objArticleTableFSEO, URL::getURLFromString(new S($this->getPOST(self::$objArticleTableFTitle) . _U . $this->getArticleInfoById($_GET[ADMIN_ACTION_ID], self::$objArticleTableFDatePublished)))); } // Continue; $this->setInputType(new S('submit'))->setValue(new S(ARTICLES_EDIT_ARTICLE))->setInputInfoMessage($this->getHELP(new S($objFormToRender)))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objArticleTableFTags)->setLabel(new S(ARTICLES_TAGS))->setJSRegExpReplace(new S(self::REGEXP_JS_TAGS)); // If we're the BIG MAN, we can set the author of an entry; if ((int) $this->ATH->getCurrentUserInfoById(Authentication::$objAuthUsersTableFId)->toString() == 1) { $this->setInputType(new S('select'))->setName(self::$objArticleTableFAuthorId)->setLabel(new S(ARTICLES_AUTHOR))->setContainerDiv(new B(TRUE)); // Users (or in this case, authors); foreach ($this->ATH->getUsers() as $k => $v) { $this->setInputType(new S('option'))->setName($v[Authentication::$objAuthUsersTableFId])->setValue($v[Authentication::$objAuthUsersTableFId])->setLabel($v[Authentication::$objAuthUsersTableFUName]); } } // Continue; $this->setInputType(new S('select'))->setLabel(new S(ARTICLES_STATE))->setName(self::$objArticleTableFState)->setContainerDiv(new B(TRUE))->setInputType(new S('option'))->setName(new S('draft'))->setValue(new S((string) self::STATE_DRAFT))->setLabel(new S(ARTICLES_DRAFT))->setInputType(new S('option'))->setName(new S('published'))->setValue(new S((string) self::STATE_PUBLISHED))->setLabel(new S(ARTICLES_PUBLISHED))->setInputType(new S('option'))->setName(new S('pending_review'))->setValue(new S((string) self::STATE_PENDING_REVIEW))->setLabel(new S(ARTICLES_PENDING_REVIEW))->setInputType(new S('option'))->setName(new S('sticky'))->setValue(new S((string) self::STATE_STICKY))->setLabel(new S(ARTICLES_STICKY))->setInputType(new S('select'))->setName(self::$objArticleTableFCategoryId)->setLabel(new S(ARTICLES_CATEGORY_NAME_LABEL))->setContainerDiv(new B(TRUE)); // Categories ... foreach ($this->getCategories() as $k => $v) { $this->setInputType(new S('option'))->setName($v[self::$objMPTT->objIdField])->setValue($v[self::$objMPTT->objIdField])->setLabel(new S(str_repeat('--' . _SP, (int) $v['depth']->toString()) . MPTT::mpttRemoveUnique($v[self::$objMPTT->objNameOfNode]))); } // Continue ... $this->setInputType(new S('select'))->setName(self::$objArticleTableFCanComment)->setLabel(new S(ARTICLES_CAN_COMMENT))->setInputType(new S('option'))->setName(new S('yes'))->setValue(new S('Y'))->setLabel(new S(ARTICLES_CAN_COMMENT_YES))->setINputType(new S('option'))->setName(new S('no'))->setValue(new S('N'))->setLabel(new S(ARTICLES_CAN_COMMENT_NO))->setInputType(new S('text'))->setName(self::$objArticleTableFTitle)->setLabel(new S(ARTICLES_TITLE))->setJSRegExpReplace(new S(self::REGEXP_JS_TITLE))->setContainerDiv(new B(TRUE))->setInputType(new S('textarea'))->setName(self::$objArticleTableFExcerpt)->setLabel(new S(ARTICLES_EXCERPT))->setContainerDiv(new B(TRUE))->setInputType(new S('textarea'))->setName(self::$objArticleTableFContent)->setLabel(new S(ARTICLES_CONTENT))->setTinyMCETextarea(new B(TRUE))->setRows(new S('5'))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; case 'articleErase': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION, ADMIN_ACTION_ID))); // Do erase it ... $this->_Q(_QS('doDELETE')->doToken('%table', self::$objArticleTable)->doToken('%condition', new S('%objArticleTableFId = "%Id"'))->doToken('%Id', $_GET[ADMIN_ACTION_ID])); // Do a redirect, and get the user back where he belongs; $this->setHeaderKey($objURLToGoBack, new S('Location')); // BK; break; case 'commentEdit': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION, ADMIN_ACTION_ID))); // Do the form, make it happen; $this->setMethod(new S('POST'))->setFieldset(new S(ARTICLES_EDIT_COMMENT))->setAJAXEnabledForm(new B(FALSE))->setRedirect($objURLToGoBack)->setSQLAction(new S('update'))->setTableName(self::$objCommentsTable)->setUpdateId($_GET[ADMIN_ACTION_ID])->setUpdateField(self::$objCommentsTableFId)->setName($objFormToRender)->setInputType(new S('submit'))->setValue(new S(ARTICLES_EDIT_COMMENT))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('select'))->setName(self::$objCommentsTableFApproved)->setLabel(new S(ARTICLES_COMMENT_APPROVED))->setContainerDiv(new B(TRUE))->setInputType(new S('option'))->setName(new S('no'))->setValue(new S('N'))->setLabel(new S(ARTICLES_CAN_COMMENT_NO))->setInputType(new S('option'))->setName(new S('yes'))->setValue(new S('Y'))->setLabel(new S(ARTICLES_CAN_COMMENT_YES))->setInputType(new S('textarea'))->setName(self::$objCommentsTableFComment)->setLabel(new S(ARTICLES_COMMENT))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; case 'commentErase': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION, ADMIN_ACTION_ID))); // Do erase it ... $this->_Q(_QS('doDELETE')->doToken('%table', self::$objCommentsTable)->doToken('%condition', new S('%objCommentsTableFId = "%Id"'))->doToken('%Id', $_GET[ADMIN_ACTION_ID])); // Do a redirect, and get the user back where he belongs; $this->setHeaderKey($objURLToGoBack, new S('Location')); break; case 'categoryCreate': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(); // Do some work ... if ($this->checkPOST(new S('categories_show_all'))->toBoolean() == TRUE) { // Redirect to proper ... $this->setHeaderKey(URL::rewriteURL(new A(array(ADMIN_SHOW_ALL)), new A(array('1'))), new S('Location')); } if ($this->checkPOST(new S('add_category_submit'))->toBoolean() == TRUE) { // Set some requirements; $objFormHappened = new B(FALSE); $objToCheck = $this->getPOST(new S('add_category')); if ($objToCheck->toLength()->toInt() == 0) { $this->setErrorOnInput(new S('add_category'), new S(ARTICLES_CATEGORY_NAME_IS_EMPTY)); // Set the memory; $objFormHappened->switchType(); } else { if (self::$objMPTT->mpttCheckIfNodeExists($objToCheck = MPTT::mpttAddUnique($objToCheck, new S((string) $_SERVER['REQUEST_TIME'])))->toBoolean() == TRUE) { // Check to see if the group exists, and tell the user the group exists; $this->setErrorOnInput(new S('add_category'), new S(ARTICLES_CATEGORY_ALREADY_EXISTS)); // Set the memory; $objFormHappened->switchType(); } if ($this->checkCategoryURLIsUnique(URL::getURLFromString($objToCheck))->toBoolean() == FALSE) { $this->setErrorOnInput(new S('add_category'), new S(ARTICLES_CATEGORY_URL_MUST_BE_UNIQUE)); } } // Get AJAX; $this->getAjaxErrors(); if ($objFormHappened->toBoolean() == FALSE) { // Remember if we should add it as a brother or child; $objAddNodeAS = NULL; // Do a switch ... switch ($this->getPOST(new S('add_category_as_what'))) { case ARTICLES_CATEGORY_CHILD: $objAddNodeAS = new S((string) MPTT::FIRST_CHILD); break; case ARTICLES_CATEGORY_LAST_CHILD: $objAddNodeAS = new S((string) MPTT::LAST_CHILD); break; case ARTICLES_CATEGORY_BROTHER: $objAddNodeAS = new S((string) MPTT::PREVIOUS_BROTHER); break; case ARTICLES_CATEGORY_NEXT_BROTHER: $objAddNodeAS = new S((string) MPTT::NEXT_BROTHER); break; } // Add the node; self::$objMPTT->mpttAddNode($objToCheck, $this->getPOST(new S('add_category_parent_or_bro')), $objAddNodeAS); } } // Do the form, make it happen; $this->setMethod(new S('POST'))->setFieldset(new S(ARTICLES_ADD_CATEGORY))->setName($objFormToRender); if ($this->checkPOST(new S('add_category_submit'))->toBoolean() == TRUE) { $this->setRedirect($objURLToGoBack); } $this->setAJAXEnabledForm(new B(FALSE))->setInputType(new S('submit'))->setName(new S('categories_show_all'))->setValue(new S(ARTICLES_SHOW_ALL_CATEGORIES))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('submit'))->setName(new S('add_category_submit'))->setValue(new S(ARTICLES_ADD_CATEGORY))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(new S('add_category'))->setLabel(new S(ARTICLES_CATEGORY_NAME_LABEL))->setJSRegExpReplace(new S(self::REGEXP_JS_CATEGORY))->setContainerDiv(new B(TRUE))->setInputType(new S('select'))->setContainerDiv(new B(TRUE))->setName(new S('add_category_as_what'))->setLabel(new S(ARTICLES_AS_A))->setInputType(new S('option'))->setName(new S('as_first_child'))->setLabel(new S(ARTICLES_CATEGORY_CHILD))->setInputType(new S('option'))->setName(new S('as_last_child'))->setLabel(new S(ARTICLES_CATEGORY_LAST_CHILD))->setInputType(new S('option'))->setName(new S('as_previous_brother'))->setLabel(new S(ARTICLES_CATEGORY_BROTHER))->setInputType(new S('option'))->setName(new S('as_next_brother'))->setLabel(new S(ARTICLES_CATEGORY_NEXT_BROTHER))->setInputType(new S('select'))->setContainerDiv(new B(TRUE))->setName(new S('add_category_parent_or_bro'))->setLabel(new S(ARTICLES_OF_CATEGORY)); // Category parent or brother of this one ... foreach ($this->getCategories() as $k => $v) { $this->setInputType(new S('option'))->setName($v[self::$objMPTT->objNameOfNode])->setValue($v[self::$objMPTT->objNameOfNode])->setLabel(new S(str_repeat('--' . _SP, (int) $v['depth']->toString()) . MPTT::mpttRemoveUnique(clone $v[self::$objMPTT->objNameOfNode]))); } // Continue, execute the form ... $this->setFormEndAndExecute(new B(TRUE)); break; case 'categoryEdit': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION, ADMIN_ACTION_ID))); // Do validation and error on it if something goes wrong; if ($this->checkPOST()->toBoolean() == TRUE) { // Set some requirements; $objFormHappened = new B(FALSE); $objToCheck = self::$objMPTT->mpttAddUnique($this->getPOST(self::$objCategoryTableFName), $this->getCategoryInfoById($_GET[ADMIN_ACTION_ID], self::$objCategoryTableFDate)); if ($objToCheck->toLength()->toInt() == 0) { // Check for empty group name, and error on it. We don't allow empty group names; $this->setErrorOnInput(self::$objCategoryTableFName, new S(ARTICLES_CATEGORY_NAME_IS_EMPTY)); // Set the memory; $objFormHappened->switchType(); } else { if ($this->getCategoryInfoById($_GET[ADMIN_ACTION_ID], self::$objCategoryTableFName) != $objToCheck) { if (self::$objMPTT->mpttCheckIfNodeExists($objToCheck)->toBoolean() == TRUE) { // Check to see if the group exists; $this->setErrorOnInput(self::$objCategoryTableFName, new S(ARTICLES_CATEGORY_ALREADY_EXISTS)); // Set the memory; $objFormHappened->switchType(); } } } // Get AJAX; $this->getAjaxErrors(); } else { // Nada ... $objFormHappened = new B(FALSE); } // Do the form, make it happen; $this->setMethod(new S('POST'))->setSQLAction(new S('update'))->setTableName(self::$objCategoryTable)->setUpdateId($_GET[ADMIN_ACTION_ID])->setUpdateField(self::$objCategoryTableFId)->setFieldset(new S(ARTICLES_EDIT_CATEGORY))->setName($objFormToRender)->setAJAXEnabledForm(new B(FALSE)); if ($this->checkPOST(new S('edit_category_submit'))->toBoolean() == TRUE && $objFormHappened->toBoolean() == FALSE) { // Set the URL ... $this->setExtraUpdateData(self::$objCategoryTableFSEO, URL::getURLFromString($this->getPOST(self::$objCategoryTableFName)))->setRedirect($objURLToGoBack); } // Continue ... $this->setInputType(new S('submit'))->setName(new S('edit_category_submit'))->setValue(new S(ARTICLES_EDIT_CATEGORY))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objCategoryTableFName)->setLabel(new S(ARTICLES_CATEGORY_NAME_LABEL))->setJSRegExpReplace(new S(self::REGEXP_JS_CATEGORY))->setMPTTRemoveUnique(new B(TRUE))->setContainerDiv(new B(TRUE))->setInputType(new S('textarea'))->setName(self::$objCategoryTableFDescription)->setLabel(new S(ARTICLES_CATEGORY_DESCRIPTION))->setTinyMCETextarea(new B(TRUE))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; case 'categoryErase': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION, ADMIN_ACTION_ID))); // Do erase the group node from the table; self::$objMPTT->mpttRemoveNode($this->getCategoryInfoById($_GET[ADMIN_ACTION_ID], self::$objCategoryTableFName)); // Do a redirect, and get the user back where he belongs; $this->setHeaderKey($objURLToGoBack, new S('Location')); // BK; break; case 'categoryMove': // Set some predefines; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION, ADMIN_ACTION_TO, ADMIN_ACTION_TYPE))); // Get names, as they are unique; $objThatIsMoved = $this->getCategoryInfoById($_GET[ADMIN_ACTION_ID], self::$objCategoryTableFName); $objWhereToMove = $this->getCategoryInfoById($_GET[ADMIN_ACTION_TO], self::$objCategoryTableFName); // Get the node subtree, that's move, make sure the node we move to ain't a child; $objMovedNodeSubTree = self::$objMPTT->mpttGetTree($objThatIsMoved); // Memorize; $objIsChild = new B(FALSE); foreach ($objMovedNodeSubTree as $k => $v) { if ($v[self::$objMPTT->objNameOfNode] == $objWhereToMove) { $objIsChild->switchType(); } } // Check if it's a child or not; if ($objIsChild->toBoolean() == TRUE) { // Set an error message; self::$objAdministration->setErrorMessage(new S(ARTICLES_CATEGORY_MOVED_TO_CHILD), $objURLToGoBack); } else { // Move nodes; self::$objMPTT->mpttMoveNode($objThatIsMoved, $objWhereToMove, $_GET[ADMIN_ACTION_TYPE]); $this->setHeaderKey($objURLToGoBack, new S('Location')); } break; case 'categoryMoveOperation': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_SUBPAGE)), new A(array(ARTICLES_MANAGE_ARTICLES))); // Do some work; $this->checkPOST()->toBoolean() == TRUE ? $objOLDCategoryId = $this->getPOST(new S('old_category_id')) : ($objOLDCategoryId = new S('0')); // Do the form, make it happen; $this->setMethod(new S('POST'))->setFieldset(new S(ARTICLES_MOVE_ARTICLE))->setSQLAction(new S('update'))->setTableName(self::$objArticleTable)->setUpdateField(self::$objArticleTableFId)->setUpdateWhere($this->doModuleToken(_S('%objArticleTableFCategoryId = "%Id"')->doToken('%Id', $objOLDCategoryId)))->setName($objFormToRender)->setRedirect($objURLToGoBack)->setInputType(new S('submit'))->setValue(new S(ARTICLES_MOVE_ARTICLE))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('select'))->setName(new S('old_category_id'))->setLabel(new S(ARTICLES_OLD_CATEGORY))->setContainerDiv(new B(TRUE)); // Cateories; foreach ($this->getCategories() as $k => $v) { $this->setInputType(new S('option'))->setName($v[self::$objMPTT->objIdField])->setValue($v[self::$objMPTT->objIdField])->setLabel(new S(str_repeat('--' . _SP, (int) $v['depth']->toString()) . MPTT::mpttRemoveUnique($v[self::$objMPTT->objNameOfNode]))); } // Categories; $this->setInputType(new S('select'))->setName(self::$objArticleTableFCategoryId)->setLabel(new S(ARTICLES_NEW_CATEGORY))->setContainerDiv(new B(TRUE)); foreach ($this->getCategories() as $k => $v) { $this->setInputType(new S('option'))->setName($v[self::$objMPTT->objIdField])->setValue($v[self::$objMPTT->objIdField])->setLabel(new S(str_repeat('--' . _SP, (int) $v['depth']->toString()) . MPTT::mpttRemoveUnique($v[self::$objMPTT->objNameOfNode]))); } // Continue; $this->setFormEndAndExecute(new B(TRUE)); break; case 'configurationEdit': // Do some work; if ($this->checkPOST()->toBoolean() == TRUE) { $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION)), new A(array($this->getPOST(new S('what'))))); } // Do the form, make it happen; $this->setMethod(new S('POST'))->setFieldset(new S(ARTICLES_MANAGE_ARTICLES_CONFIG))->setName($objFormToRender); // Set redirect; if ($this->checkPOST()->toBoolean() == TRUE) { $this->setRedirect($objURLToGoBack); } // Continue; $this->setInputType(new S('submit'))->setValue(new S(ADMIN_ACTION))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('select'))->setName(new S('what'))->setLabel(new S(ARTICLES_CONFIG_CHOOSE))->setContainerDiv(new B(TRUE))->setInputType(new S('option'))->setName(new S('configurationEdit-articles_per_page'))->setValue(new S('configurationEdit-articles_per_page'))->setLabel(new S(ARTICLES_CONFIG_ARTICLES_PER_PAGE))->setContainerDiv(new B(TRUE))->setInputType(new S('option'))->setName(new S('configurationEdit-users_should_be_auth_to_comment'))->setValue(new S('configurationEdit-users_should_be_auth_to_comment'))->setLabel(new S(ARTICLES_CONFIG_USERS_AUTH_TO_COMMENT))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; case 'configurationEdit-articles_per_page': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION))); // Do some work; if ($this->checkPOST()->toBoolean() == TRUE) { foreach ($this->getPOST() as $k => $v) { $this->setConfigKey(new S($k), $v); } } // Do the form, make it happen; $this->setMethod(new S('POST'))->setFieldset(new S(ARTICLES_UPDATE_CONFIGURATION))->setName($objFormToRender)->setRedirect($objURLToGoBack)->setInputType(new S('submit'))->setValue(new S(ARTICLES_UPDATE_CONFIGURATION))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(new S('articles_per_page'))->setLabel(new S(ARTICLES_CONFIG_CHOOSE))->setValue($this->getConfigKey(new S('articles_per_page')))->setRegExpType(new S('ereg'))->setRegExpErrMsg(new S(ARTICLES_CONFIG_PER_PAGE_ERROR))->setPHPRegExpCheck(new S('[0-9]'))->setJSRegExpReplace(new S('[^0-9]'))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; case 'configurationEdit-users_should_be_auth_to_comment': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION))); // Do some work; if ($this->checkPOST()->toBoolean() == TRUE) { foreach ($this->getPOST() as $k => $v) { $this->setConfigKey(new S($k), $v); } } // Do the form, make it happen; $this->setMethod(new S('POST'))->setFieldset(new S(ARTICLES_UPDATE_CONFIGURATION))->setName($objFormToRender)->setRedirect($objURLToGoBack)->setInputType(new S('submit'))->setValue(new S(ARTICLES_UPDATE_CONFIGURATION))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('select'))->setName(new S('article_settings_article_auth_to_comment'))->setLabel(new S(ARTICLES_CONFIG_CHOOSE))->setContainerDiv(new B(TRUE))->setInputType(new S('option'))->setName(new S('yes'))->setValue(new S('Y'))->setLabel(new S(ARTICLES_CAN_COMMENT_YES))->setSelected($this->getConfigKey(new S('article_settings_article_auth_to_comment')) == 'Y' ? new B(TRUE) : new B(FALSE))->setInputType(new S('option'))->setName(new S('no'))->setValue(new S('N'))->setLabel(new S(ARTICLES_CAN_COMMENT_NO))->setSelected($this->getConfigKey(new S('article_settings_article_auth_to_comment')) == 'N' ? new B(TRUE) : new B(FALSE))->setFormEndAndExecute(new B(TRUE)); break; } }
/** * Will set a configuration key, even if it was not set. This method will also update the key in the configuration table so that * the next time the getConfigKey method is called, the value in the DBs will take precedence over the value in the config file; * * @param S $objConfigKey The key to be set, for dynamic configuration parameters * @return O The current object configuration string * @author Catalin Z. Alexandru <*****@*****.**> * @copyright Under the terms of the GNU General Public License v3 * @version $Id: 14_CNF.php 314 2009-10-09 14:24:35Z catalin.zamfir $ * @since Version 1.0 * @access public */ public function setConfigKey(S $objConfigKey, S $objConfigVar) { if ($this->objConfigArray->doCount()->toInt() != 0) { // Set the INTERNAL array of configuration parameters; $this->objConfigArray[$objConfigKey] = $objConfigVar; // Do an update on the configuration table also ... $this->getQuery(_QS('doUPDATE')->doToken('%table', new S('_T_configuration'))->doToken('%condition', new S('v = "%var" WHERE k = "%key"'))->doToken('%key', $objConfigKey)->doToken('%var', $objConfigVar)); } else { self::renderScreenOfDeath(new S(__CLASS__), new S(CONFIG_ARRAY_NOT_SET), new S(CONFIG_ARRAY_NOT_SET_FIX)); } }
/** * Will render a specified form, the name of the form given by the first parameter; * * This method will render one of the forms for our object, invoked by giving the proper form identifier to the current form. We * have chosen this method of invoking forms, because we just had too many this->renderSomethingMethod (), which really had * an impact on code massiveness. Also, having code organized in switch/case statements leads us to be able to share common * settings between different forms, as we've done with the methods defined in the __CALL method above; * * For example, if we wanted to share some common configuration between a create and an edit form, we could have introduced * two switches in this method, one that would have set the common options, and the second, would have just passed through * again, and get the already set configuration options, using them. This means that if we needed to change behavior of * some interconnected forms, that would mean modifying the needed code one place only, which is a big advantage over * having separated methods for each form. Maybe if we extended this object, you guys could understand the functionality better; * * @param string $objFormToRender The name of the form to render; * @return mixed Depends on the rendered form if it returns something or not; */ public function renderForm(S $objFormToRender, A $objFormArray = NULL) { // Make them defaults ... if ($objFormArray == NULL) { $objFormArray = new A(); } // Do a switch ... switch ($objFormToRender) { case 'countryCreate': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(); // Do the form, make it happen; $this->setMethod(new S('POST'))->setFieldset(new S(SETTINGS_ADD_COUNTRY))->setSQLAction(new S('update'))->setTableName(self::$objSettingsCountryTable); // Make the ISO ... if ($this->checkPOST()->toBoolean() == TRUE) { $this->setUpdateId($this->getPOST(self::$objSettingsCountryTableFIso))->setExtraUpdateData(self::$objSettingsCountryTableFName, $this->getPOST(self::$objSettingsCountryTableFPrnt)->toUpper()); } // Continue; $this->setUpdateField(self::$objSettingsCountryTableFIso)->setName($objFormToRender)->setRedirect($objURLToGoBack)->setInputType(new S('submit'))->setValue(new S(SETTINGS_ADD_COUNTRY))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objSettingsCountryTableFIso)->setLabel(new S(SETTINGS_COUNTRY_ISO))->setInputType(new S('text'))->setName(self::$objSettingsCountryTableFPrnt)->setLabel(new S(SETTINGS_COUNTRY_NAME))->setInputType(new S('text'))->setName(self::$objSettingsCountryTableFIsoT)->setJSRegExpReplace(new S('[^A-Z]'))->setLabel(new S(SETTINGS_COUNTRY_ISO3))->setInputType(new S('text'))->setName(self::$objSettingsCountryTableFCode)->setJSRegExpReplace(new S('[^0-9]'))->setLabel(new S(SETTINGS_COUNTRY_CODE))->setFormEndAndExecute(new B(TRUE)); break; case 'countryEdit': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION, ADMIN_ACTION_ID))); // Do the form, make it happen; $this->setMethod(new S('POST'))->setFieldset(new S(SETTINGS_EDIT_COUNTRY))->setSQLAction(new S('update'))->setTableName(self::$objSettingsCountryTable)->setUpdateId($_GET[ADMIN_ACTION_ID]); // Set the printable country name; if ($this->checkPOST()->toBoolean() == TRUE) { $objCountryName = clone $this->getPOST(self::$objSettingsCountryTableFPrnt); $this->setExtraUpdateData(self::$objSettingsCountryTableFName, $objCountryName->toUpper()); } // Continue; $this->setUpdateField(self::$objSettingsCountryTableFIso)->setName($objFormToRender)->setRedirect($objURLToGoBack)->setInputType(new S('submit'))->setValue(new S(SETTINGS_EDIT_COUNTRY))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objSettingsCountryTableFPrnt)->setLabel(new S(SETTINGS_COUNTRY_NAME))->setInputType(new S('text'))->setName(self::$objSettingsCountryTableFIsoT)->setJSRegExpReplace(new S('[^A-Z]'))->setLabel(new S(SETTINGS_COUNTRY_ISO3))->setInputType(new S('text'))->setName(self::$objSettingsCountryTableFCode)->setJSRegExpReplace(new S('[^0-9]'))->setLabel(new S(SETTINGS_COUNTRY_CODE))->setFormEndAndExecute(new B(TRUE)); break; case 'countryErase': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION, ADMIN_ACTION_ID))); // Set some requirements; $objSQLConditionForUsers = new S('WHERE %objAuthUsersTableFCountry = "%cId"'); if (self::$objAuthenticationMech->getUserCount($objSQLConditionForUsers->doToken('%cId', $_GET[ADMIN_ACTION_ID]))->toInt() == 0) { // Do ERASE; $this->_Q(_QS('doDELETE')->doToken('%table', self::$objSettingsCountryTable)->doToken('%condition', new S('%objSettingsCountryTableFIso = "%sId"'))->doToken('%sId', $_GET[ADMIN_ACTION_ID])); // Redirect; $this->setHeaderKey($objURLToGoBack, new S('Location')); } else { // Do me, ERROR; self::$objAdministration->setErrorMessage(new S(SETTINGS_CANNOT_DELETE_COUNTRY), $objURLToGoBack); } break; case 'errorPageCreate': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(); // Check CODE is unique; if ($this->checkPOST(self::$objSettingsErrTableFCode)->toBoolean() == TRUE) { if ($this->checkErrorPageCodeIsUnique($this->getPOST(self::$objSettingsErrTableFCode))->toBoolean() == FALSE) { $this->setErrorOnInput(self::$objSettingsErrTableFCode, new S(SETTINGS_ERROR_CODE_MUST_BE_UNIQUE)); } } // Do the form, make it happen; $this->setMethod(new S('POST'))->setFieldset(new S(SETTINGS_ADD_ERROR_PAGE))->setSQLAction(new S('update'))->setTableName(self::$objSettingsErrTable)->setUpdateId(new S('#nextTableAutoIncrement'))->setUpdateField(self::$objSettingsErrTableFId)->setName($objFormToRender)->setRedirect($objURLToGoBack)->setInputType(new S('submit'))->setValue(new S(SETTINGS_ADD_ERROR_PAGE))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objSettingsErrTableFCode)->setLabel(new S(SETTINGS_ERROR_PAGE_CODE))->setJSRegExpReplace(new S('[^0-9]'))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objSettingsErrTableFTitle)->setLabel(new S(SETTINGS_ERROR_PAGE_TITLE))->setContainerDiv(new B(TRUE))->setInputType(new S('textarea'))->setName(self::$objSettingsErrTableFContent)->setLabel(new S(SETTINGS_ERROR_PAGE_CONTENT))->setTinyMCETextarea(new B(TRUE))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; case 'errorPageEdit': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION, ADMIN_ACTION_ID))); // Check CODE is unique; if ($this->checkPOST(self::$objSettingsErrTableFCode)->toBoolean() == TRUE) { if ($this->getPOST(self::$objSettingsErrTableFCode) != $this->getErrorPageById($_GET[ADMIN_ACTION_ID], self::$objSettingsErrTableFCode)) { if ($this->checkErrorPageCodeIsUnique($this->getPOST(self::$objSettingsErrTableFCode))->toBoolean() == FALSE) { $this->setErrorOnInput(self::$objSettingsErrTableFCode, new S(SETTINGS_ERROR_CODE_MUST_BE_UNIQUE)); } } } // Do the form, make it happen; $this->setMethod(new S('POST'))->setFieldset(new S(SETTINGS_EDIT_ERROR_PAGE))->setSQLAction(new S('update'))->setTableName(self::$objSettingsErrTable)->setUpdateId($_GET[ADMIN_ACTION_ID])->setUpdateField(self::$objSettingsErrTableFId)->setName($objFormToRender)->setRedirect($objURLToGoBack)->setInputType(new S('submit'))->setValue(new S(SETTINGS_EDIT_ERROR_PAGE))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objSettingsErrTableFCode)->setLabel(new S(SETTINGS_ERROR_PAGE_CODE))->setJSRegExpReplace(new S('[^0-9]'))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objSettingsErrTableFTitle)->setLabel(new S(SETTINGS_ERROR_PAGE_TITLE))->setContainerDiv(new B(TRUE))->setInputType(new S('textarea'))->setName(self::$objSettingsErrTableFContent)->setLabel(new S(SETTINGS_ERROR_PAGE_CONTENT))->setTinyMCETextarea(new B(TRUE))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; case 'errorPageErase': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION, ADMIN_ACTION_ID))); // Make the erase, than redirect; $this->_Q(_QS('doDELETE')->doToken('%table', self::$objSettingsErrTable)->doToken('%condition', new S('%objSettingsErrTableFId = "%sId"'))->doToken('%sId', $_GET[ADMIN_ACTION_ID])); // Redirect; $this->setHeaderKey($objURLToGoBack, new S('Location')); break; case 'configurationEdit': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(); // Do some work; if ($this->checkPOST()->toBoolean() == TRUE) { $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION)), new A(array($this->getPOST(new S('what'))))); } // Do the form, make it happen; $this->setMethod(new S('POST'))->setFieldset(new S(SETTINGS_MANAGE_CONFIG))->setName($objFormToRender)->setRedirect($objURLToGoBack)->setInputType(new S('submit'))->setValue(new S(SETTINGS_DO))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('select'))->setName(new S('what'))->setLabel(new S(SETTINGS_CHOOSE))->setContainerDiv(new B(TRUE))->setInputType(new S('option'))->setName(new S('configurationEditAdminApplicationTitle'))->setValue(new S('configurationEditAdminApplicationTitle'))->setLabel(new S(SETTINGS_ADMIN_TITLE))->setContainerDiv(new B(TRUE))->setInputType(new S('option'))->setName(new S('configurationEditApplicationTitle'))->setValue(new S('configurationEditApplicationTitle'))->setLabel(new S(SETTINGS_FRONTEND_TITLE))->setContainerDiv(new B(TRUE))->setInputType(new S('option'))->setName(new S('configurationEditWebsiteNotificationEmail'))->setValue(new S('configurationEditWebsiteNotificationEmail'))->setLabel(new S(SETTINGS_WEBSITE_NOTIFICATION_EMAIL))->setContainerDiv(new B(TRUE))->setInputType(new S('option'))->setName(new S('configurationEditDefaultDateType'))->setValue(new S('configurationEditDefaultDateType'))->setLabel(new S(SETTINGS_DEFAULT_DATE))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; case 'configurationEditAdminApplicationTitle': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION))); // Do some work; if ($this->checkPOST()->toBoolean() == TRUE) { foreach ($this->getPOST() as $k => $v) { $this->setConfigKey(new S($k), $v); } } // Do the form, make it happen; $this->setMethod(new S('POST'))->setFieldset(new S(SETTINGS_UPDATE_SETTINGS))->setName($objFormToRender)->setRedirect($objURLToGoBack)->setInputType(new S('submit'))->setValue(new S(SETTINGS_UPDATE_SETTINGS))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setInputInfoMessage($this->getHELP($objFormToRender))->setName(new S('administration_header_text'))->setLabel(new S(SETTINGS_ADMIN_APPLICATION_TITLE))->setValue($this->getConfigKey(new S('administration_header_text')))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; case 'configurationEditApplicationTitle': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION))); // Do form validation; if ($this->checkPOST()->toBoolean() == TRUE) { foreach ($this->getPOST() as $k => $v) { $this->setConfigKey(new S($k), $v); } } // Do the form, make it happen; $this->setMethod(new S('POST'))->setFieldset(new S(SETTINGS_UPDATE_SETTINGS))->setName($objFormToRender)->setRedirect($objURLToGoBack)->setInputType(new S('submit'))->setValue(new S(SETTINGS_UPDATE_SETTINGS))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setInputInfoMessage($this->getHELP($objFormToRender))->setName(new S('settings_website_default_title'))->setLabel(new S(SETTINGS_ADMIN_APPLICATION_TITLE))->setValue($this->getConfigKey(new S('settings_website_default_title')))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; case 'configurationEditWebsiteNotificationEmail': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION))); // Do form validation; if ($this->checkPOST()->toBoolean() == TRUE) { foreach ($this->getPOST() as $k => $v) { $this->setConfigKey(new S($k), $v); } } // Do the form, make it happen; $this->setMethod(new S('POST'))->setFieldset(new S(SETTINGS_UPDATE_SETTINGS))->setName($objFormToRender)->setRedirect($objURLToGoBack)->setInputType(new S('submit'))->setValue(new S(SETTINGS_UPDATE_SETTINGS))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setInputInfoMessage($this->getHELP($objFormToRender))->setName(new S('settings_website_notification_email'))->setLabel(new S(SETTINGS_NOTIFICATION_EMAIL_LABEL))->setValue($this->getConfigKey(new S('settings_website_notification_email')))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; case 'configurationEditDefaultDateType': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION))); // Do form validation; if ($this->checkPOST()->toBoolean() == TRUE) { foreach ($this->getPOST() as $k => $v) { $this->setConfigKey(new S($k), $v); } } // Get the date format used for now ... $objDateFormat = $this->getConfigKey(new S('settings_default_date_format')); // Do the form, make it happen; $this->setMethod(new S('POST'))->setFieldset(new S(SETTINGS_UPDATE_SETTINGS))->setName($objFormToRender)->setRedirect($objURLToGoBack)->setInputType(new S('submit'))->setValue(new S(SETTINGS_UPDATE_SETTINGS))->setContainerDiv(new B(TRUE))->setInputType(new S('select'))->setName(new S('settings_default_date_format'))->setLabel(new S(SETTINGS_DEFAULT_DATE_FORMAT))->setInputType(new S('option'))->setName(new S('date_format_1'))->setLabel(new S(date('F j, Y, g:i a')))->setValue(new S('F j, Y, g:i a'))->setSelected(new B($objDateFormat == new S('F j, Y, g:i a') ? TRUE : FALSE))->setContainerDiv(new B(TRUE))->setInputType(new S('option'))->setName(new S('date_format_2'))->setLabel(new S(date('D M j G:i:s T Y')))->setValue(new S('D M j G:i:s T Y'))->setSelected(new B($objDateFormat == new S('D M j G:i:s T Y') ? TRUE : FALSE))->setContainerDiv(new B(TRUE))->setInputType(new S('option'))->setName(new S('date_format_3'))->setLabel(new S(date('r')))->setValue(new S('r'))->setSelected(new B($objDateFormat == new S('r') ? TRUE : FALSE))->setContainerDiv(new B(TRUE))->setInputType(new S('option'))->setName(new S('date_format_4'))->setLabel(new S(date('d-m-Y H:i:s')))->setValue(new S('d-m-Y H:i:s'))->setSelected(new B($objDateFormat == new S('d-m-Y H:i:s') ? TRUE : FALSE))->setContainerDiv(new B(TRUE))->setInputType(new S('option'))->setName(new S('date_format_5'))->setLabel(new S(date('Y-m-d H:i:s')))->setValue(new S('Y-m-d H:i:s'))->setSelected(new B($objDateFormat == new S('Y-m-d H:i:s') ? TRUE : FALSE))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; } }
/** * Will render a specified form, the name of the form given by the first parameter; * * This method will render one of the forms for our object, invoked by giving the proper form identifier to the current form. * We have chosen this method of invoking forms, because we just had too many this->renderSomethingMethod (), which really had * an impact on code massiveness. Also, having code organized in switch/case statements leads us to be able to share common * settings between different forms, as we've done with the methods defined in the __CALL method above; * * For example, if we wanted to share some common configuration between a create and an edit form, we could have introduced * two switches in this method, one that would have set the common options, and the second, would have just passed through * again, and get the already set configuration options, using them. This means that if we needed to change behavior of * some interconnected forms, that would mean modifying the needed code one place only, which is a big advantage over * having separated methods for each form. Maybe if we extended this object, you guys could understand the functionality; * * @param string $objFormToRender The name of the form to render; * @return mixed Depends on the rendered form if it returns something or not; */ public function renderForm(S $objFormToRender, A $objFA = NULL) { // Make them defaults ... if ($objFA == NULL) { $objFA = new A(); } // Do a switch ... switch ($objFormToRender) { case 'contactForm': // Set the URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array('Status')), new A(array('Ok'))); // Set some requirements; $objPHPEMLRegExpCheck = new S(Authentication::REGEXP_PHP_CHECK_EMAIL); // Get some configuration parameters ... $objNameFrm = $objFA['form_name']; $objSubject = $objFA['field_subject']; $objEMAIL = $objFA['field_email']; $objMessage = $objFA['field_message']; $objSendFrm = $objFA['form_submit_contact']; $objErrorE = $objFA['error_must_enter_valid_email']; $objErrorM = $objFA['error_must_enter_message']; $objErrorI = $objFA['error_entered_email_not_valid']; // Do some work; if ($this->checkPOST(self::$objContactTableFEMAIL)->toBoolean() == TRUE) { // Check the EMAIL was set; if ($this->getPOST(self::$objContactTableFEMAIL)->toLength()->toInt() == 0) { $this->setErrorOnInput(self::$objContactTableFEMAIL, $objErrorE); } } if ($this->checkPOST(self::$objContactTableFMessage)->toBoolean() == TRUE) { // Check the MESSAGE is not empty; if ($this->getPOST(self::$objContactTableFMessage)->toLength()->toInt() == 0) { $this->setErrorOnInput(self::$objContactTableFMessage, $objErrorM); } } // Get AJAX; $this->getAjaxErrors(); // Do the form, make it happen; $this->setMethod(new S('POST'))->setFieldset(new S($objNameFrm))->setSQLAction(new S('update'))->setTableName(self::$objContactTable)->setUpdateId(new S('#nextTableAutoIncrement'))->setUpdateField(self::$objContactTableFId)->setExtraUpdateData(self::$objContactTableFReceived, new S((string) $_SERVER['REQUEST_TIME']))->setName($objFormToRender)->setAJAXEnabledForm(new B(FALSE))->setInputType(new S('submit'))->setName(new S('contact_submit'))->setValue($objSendFrm)->setContainerDiv(new B(TRUE))->setInputType(new S('select'))->setName(self::$objContactTableFSubjectId)->setLabel($objSubject)->setContainerDiv(new B(TRUE)); // Get the subjects ... foreach ($this->getSubjects() as $k => $v) { $this->setInputType(new S('option'))->setName($v[self::$objContactSubjectFId])->setValue($v[self::$objContactSubjectFId])->setLabel($v[self::$objContactSubjectFTitle]); } // Continue; $this->setInputType(new S('text'))->setName(self::$objContactTableFEMAIL)->setLabel($objEMAIL)->setRegExpType(new S('preg'))->setRegExpErrMsg($objErrorI)->setPHPRegExpCheck($objPHPEMLRegExpCheck)->setContainerDiv(new B(TRUE))->setInputType(new S('textarea'))->setName(self::$objContactTableFMessage)->setLabel($objMessage)->setRows(new S('10'))->setTinyMCETextarea(new B(TRUE))->setClass(new S('tinyMCESimple'))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); // Do some after work; if ($this->checkPOST(new S('contact_submit'))->toBoolean() == TRUE) { if ($this->checkFormHasErrors()->toBoolean() == FALSE) { // Set some requirements ... $objMAIL = new MAIL(); // Set From: MAIL header; $objMAIL->setFrom($this->getPOST(self::$objContactTableFEMAIL)); $objMAIL->doMAIL($this->getConfigKey(new S('contact_message_email')), $this->getSubjectInfoById($this->getPOST(self::$objContactTableFSubjectId), self::$objContactSubjectFTitle), $this->getPOST(self::$objContactTableFMessage)); } // Do a redirect, to the ok page ... if everything is OK; if ($this->checkFormHasErrors()->toBoolean() == FALSE) { $this->setHeaderKey($objURLToGoBack, new S('Location')); } } // Break out ... break; case 'messageSend': // Set the URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION, ADMIN_ACTION_ID))); // Do some work; if ($this->checkPOST(new S('submit_resend_message'))->toBoolean() == TRUE) { // Set some requirements ... $objTo = $this->getConfigKey(new S('contact_message_email')); $objSubjectId = $this->getMessageInfoById($_GET[ADMIN_ACTION_ID], self::$objContactTableFSubjectId); $objSubject = $this->getSubjectInfoById($objSubjectId, self::$objContactSubjectFTitle); $objFrom = $this->getMessageInfoById($_GET[ADMIN_ACTION_ID], self::$objContactTableFEMAIL); $objMessage = $this->getMessageInfoById($_GET[ADMIN_ACTION_ID], self::$objContactTableFMessage); // Set some requirements ... $objMAIL = new MAIL(); // Set From: MAIL header ... $objMAIL->setFrom($objFrom); $objMAIL->doMAIL($objTo, $objSubject, $objMessage); // Do a redirect, and get the user back where he belongs; $this->setHeaderKey($objURLToGoBack, new S('Location')); } // Do the form, make it happen; $this->setMethod(new S('POST'))->setFieldset(new S(CONTACT_RESEND_MESSAGE))->setName($objFormToRender)->setInputType(new S('submit'))->setName(new S('submit_resend_message'))->setValue(new S(CONTACT_RESEND_MESSAGE))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; case 'messageOperations': // Set some predefines; $objURLToGoBack = URL::rewriteURL(); // Do the form, make it happen; $this->setMethod(new S('POST'))->setFieldset(new S(CONTACT_EDIT_COMMENT_AND_STATUS))->setSQLAction(new S('update'))->setTableName(self::$objContactTable)->setUpdateId($_GET[ADMIN_ACTION_ID])->setUpdateField(self::$objContactTableFId)->setExtraUpdateData(self::$objContactTableFLastEdited, new S((string) $_SERVER['REQUEST_TIME']))->setName($objFormToRender)->setInputType(new S('submit'))->setValue(new S(CONTACT_EDIT_COMMENT_AND_STATUS))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('select'))->setName(self::$objContactTableFResolved)->setLabel(new S(CONTACT_MESSAGE_RESOLVED))->setContainerDiv(new B(TRUE))->setInputType(new S('option'))->setName(new S('yes'))->setValue(new S('Y'))->setLabel(new S(CONTACT_MESSAGE_RESOLVED_YES))->setInputType(new S('option'))->setName(new S('no'))->setValue(new S('N'))->setLabel(new S(CONTACT_MESSAGE_RESOLVED_NO))->setInputType(new S('textarea'))->setName(self::$objContactTableFComment)->setLabel(new S(CONTACT_MESSAGE_COMMENT))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); if ($this->checkPOST(self::$objContactTableFComment)->toBoolean() == TRUE) { // Do a redirect, and get the user back where he belongs; if ($this->checkFormHasErrors()->toBoolean() == FALSE) { $this->setHeaderKey($objURLToGoBack, new S('Location')); } } break; case 'messageErase': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION, ADMIN_ACTION_ID))); // Do erase it ... $this->_Q(_QS('doDELETE')->doToken('%table', self::$objContactTable)->doToken('%condition', new S('%objContactTableFId = "%Id"'))->doToken('%Id', $_GET[ADMIN_ACTION_ID])); // Do a redirect, and get the user back where he belongs; $this->setHeaderKey($objURLToGoBack, new S('Location')); break; case 'subjectCreate': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(); // Do some work; if ($this->checkPOST(self::$objContactSubjectFTitle)->toBoolean() == TRUE) { // Check that the subject title is not empty!; if ($this->getPOST(self::$objContactSubjectFTitle)->toLength()->toInt() == 0) { $this->setErrorOnInput(self::$objContactSubjectFTitle, new S(CONTACT_SUBJECT_CANNOT_BE_EMPTY)); } } // Get AJAX $this->getAjaxErrors(); // Do the form, make it happen; $this->setMethod(new S('POST'))->setFieldset(new S(CONTACT_ADD_SUBJECT))->setSQLAction(new S('update'))->setTableName(self::$objContactSubjectTable)->setUpdateId(new S('#nextTableAutoIncrement'))->setUpdateField(self::$objContactSubjectFId)->setName($objFormToRender)->setRedirect($objURLToGoBack)->setAJAXEnabledForm(new B(FALSE))->setInputType(new S('submit'))->setValue(new S(CONTACT_ADD_SUBJECT))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objContactSubjectFTitle)->setLabel(new S(CONTACT_SUBJECT))->setJSRegExpReplace(new S(self::REGEXP_JS_SUBJECT))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; case 'subjectEdit': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION, ADMIN_ACTION_ID))); // Do some work; if ($this->checkPOST(self::$objContactSubjectFTitle)->toBoolean() == TRUE) { // Check that the subject title is not empty!; if ($this->getPOST(self::$objContactSubjectFTitle)->toLength()->toInt() == 0) { $this->setErrorOnInput(self::$objContactSubjectFTitle, new S(CONTACT_SUBJECT_CANNOT_BE_EMPTY)); } } // Get AJAX $this->getAjaxErrors(); // Do the form, make it happen; $this->setMethod(new S('POST'))->setFieldset(new S(CONTACT_EDIT_SUBJECT))->setSQLAction(new S('update'))->setTableName(self::$objContactSubjectTable)->setUpdateId($_GET[ADMIN_ACTION_ID])->setUpdateField(self::$objContactSubjectFId)->setName($objFormToRender)->setRedirect($objURLToGoBack)->setAJAXEnabledForm(new B(FALSE))->setInputType(new S('submit'))->setValue(new S(CONTACT_EDIT_SUBJECT))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objContactSubjectFTitle)->setLabel(new S(CONTACT_SUBJECT))->setJSRegExpReplace(new S(self::REGEXP_JS_SUBJECT))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; case 'subjectErase': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION, ADMIN_ACTION_ID))); $objSQLCondition = new S('WHERE %objContactTableFSubjectId = "%Id"'); // Do erase it ... $this->_Q(_QS('doDELETE')->doToken('%table', self::$objContactSubjectTable)->doToken('%condition', new S('%objContactSubjectFId = "%Id"'))->doToken('%Id', $_GET[ADMIN_ACTION_ID])); // Do a redirect, and get the user back where he belongs; $this->setHeaderKey($objURLToGoBack, new S('Location')); break; case 'configurationEdit': // Set the URL to go back too; $objURLToGoBack = new S(); // Do some work; if ($this->checkPOST()->toBoolean() == TRUE) { // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION)), new A(array($this->getPOST(new S('what'))))); } // Do the form, make it happen; $this->setMethod(new S('POST'))->setFieldset(new S(CONTACT_MANAGE_CONFIG))->setName($objFormToRender)->setRedirect($objURLToGoBack)->setInputType(new S('submit'))->setValue(new S(CONTACT_CONFIG_DO))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('select'))->setName(new S('what'))->setLabel(new S(CONTACT_CONFIG_CHOOSE))->setContainerDiv(new B(TRUE))->setInputType(new S('option'))->setName(new S('configurationEdit-contact_address'))->setValue(new S('configurationEdit-contact_address'))->setLabel(new S(CONTACT_CONFIG_EMAIL))->setContainerDiv(new B(TRUE))->setInputType(new S('option'))->setName(new S('configurationEdit-page_content'))->setValue(new S('configurationEdit-page_content'))->setLabel(new S(CONTACT_CONFIG_PAGE))->setContainerDiv(new B(TRUE))->setInputType(new S('option'))->setName(new S('configurationEdit-ok_page_content'))->setValue(new S('configurationEdit-ok_page_content'))->setLabel(new S(CONTACT_CONFIG_SUCCES_PAGE))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; case 'configurationEdit-contact_address': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION))); // Do form validation; if ($this->checkPOST()->toBoolean() == TRUE) { foreach ($this->getPOST() as $k => $v) { $this->setConfigKey(new S($k), $v); } } // Do the form, make it happen; $this->setMethod(new S('POST'))->setFieldset(new S(CONTACT_MANAGE_CONFIG))->setName($objFormToRender)->setRedirect($objURLToGoBack)->setInputType(new S('submit'))->setValue(new S(CONTACT_MANAGE_CONFIGURATION_UPDATE))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(new S('contact_message_email'))->setLabel(new S(CONTACT_DEFAULT))->setValue($this->getConfigKey(new S('contact_message_email')))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; case 'configurationEdit-page_content': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION))); // Do form validation; if ($this->checkPOST()->toBoolean() == TRUE) { foreach ($this->getPOST() as $k => $v) { $this->setConfigKey(new S($k), $v); } } // Do the form, make it happen; $this->setMethod(new S('POST'))->setFieldset(new S(CONTACT_MANAGE_CONFIGURATION_UPDATE))->setName($objFormToRender)->setRedirect($objURLToGoBack)->setInputType(new S('submit'))->setValue(new S(CONTACT_MANAGE_CONFIGURATION_UPDATE))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('textarea'))->setName(new S('contact_page_message_content'))->setLabel(new S(CONTACT_PAGE_CONTENT))->setValue($this->getConfigKey(new S('contact_page_message_content')))->setTinyMCETextarea(new B(TRUE))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; case 'configurationEdit-ok_page_content': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION))); // Do form validation; if ($this->checkPOST()->toBoolean() == TRUE) { foreach ($this->getPOST() as $k => $v) { $this->setConfigKey(new S($k), $v); } } // Do the form, make it happen; $this->setMethod(new S('POST'))->setFieldset(new S(CONTACT_MANAGE_CONFIGURATION_UPDATE))->setName($objFormToRender)->setRedirect($objURLToGoBack)->setInputType(new S('submit'))->setValue(new S(CONTACT_MANAGE_CONFIGURATION_UPDATE))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('textarea'))->setName(new S('contact_page_message_content_ok'))->setLabel(new S(CONTACT_PAGE_CONTENT_OK))->setValue($this->getConfigKey(new S('contact_page_message_content_ok')))->setTinyMCETextarea(new B(TRUE))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; } }
/** * Will render a specified form, the name of the form given by the first parameter; * * This method will render one of the forms for our object, invoked by giving the proper form identifier to the current form. We * have chosen this method of invoking forms, because we just had too many this->renderSomethingMethod (), which really had * an impact on code massiveness. Also, having code organized in switch/case statements leads us to be able to share common * settings between different forms, as we've done with the methods defined in the __CALL method above; * * For example, if we wanted to share some common configuration between a create and an edit form, we could have introduced * two switches in this method, one that would have set the common options, and the second, would have just passed through * again, and get the already set configuration options, using them. This means that if we needed to change behavior of * some interconnected forms, that would mean modifying the needed code one place only, which is a big advantage over * having separated methods for each form. Maybe if we extended this object, you guys could understand the functionality better; * * @param string $objFormToRender The name of the form to render; * @return mixed Depends on the rendered form if it returns something or not; */ public function renderForm(S $objFormToRender, A $objFormArray = NULL) { // Make them defaults ... if ($objFormArray == NULL) { $objFormArray = new A(); } // Do a switch ... switch ($objFormToRender) { case 'faqCreate': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(); // Do some work; if ($this->checkPOST(self::$objFaqTableFQuestion)->toBoolean() == TRUE) { if ($this->getPOST(self::$objFaqTableFQuestion)->toLength()->toInt() == 0) { $this->setErrorOnInput(self::$objFaqTableFQuestion, new S(FAQ_QUESTION_CANNOT_BE_EMPTY)); } if ($this->checkFaqQuestionIsUnique($this->getPOST(self::$objFaqTableFQuestion))->toBoolean() == FALSE) { $this->setErrorOnInput(self::$objFaqTableFQuestion, new S(FAQ_QUESTION_MUST_BE_UNIQUE)); } if ($this->checkFaqQuestionIsUnique(URL::getURLFromString($this->getPOST(self::$objFaqTableFQuestion)))->toBoolean() == FALSE) { $this->setErrorOnInput(self::$objFaqTableFQuestion, new S(FAQ_QUESTION_URL_MUST_BE_UNIQUE)); } } if ($this->checkPOST(self::$objFaqTableFAnswer)->toBoolean() == TRUE) { if ($this->getPOST(self::$objFaqTableFAnswer)->toLength()->toInt() == 0) { $this->setErrorOnInput(self::$objFaqTableFAnswer, new S(FAQ_ANSWER_CANNOT_BE_EMPTY)); } } // Get AJAX; $this->getAjaxErrors(); // Do the form, make it happen; $this->setMethod(new S('POST'))->setEnctype(new S('multipart/form-data'))->setFieldset(new S(FAQ_ADD_FAQ))->setSQLAction(new S('update'))->setTableName(self::$objFaqTable)->setUpdateId(new S('#nextTableAutoIncrement'))->setUpdateField(self::$objFaqTableFId); if ($this->checkPOST(self::$objFaqTableFQuestion)->toBoolean() == TRUE) { $this->setExtraUpdateData(self::$objFaqTableFSEO, URL::getURLFromString($this->getPOST(self::$objFaqTableFQuestion))); } $this->setName($objFormToRender)->setRedirect($objURLToGoBack)->setAJAXEnabledForm(new B(FALSE))->setInputType(new S('submit'))->setValue(new S(FAQ_ADD_FAQ))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objFaqTableFQuestion)->setLabel(new S(FAQ_QUESTION))->setContainerDiv(new B(TRUE))->setInputType(new S('textarea'))->setName(self::$objFaqTableFAnswer)->setTinyMCETextarea(new B(TRUE))->setLabel(new S(FAQ_ANSWER))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; case 'faqEdit': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION, ADMIN_ACTION_ID))); // Do some work; if ($this->checkPOST(self::$objFaqTableFAnswer)->toBoolean() == TRUE) { if ($this->getPOST(self::$objFaqTableFAnswer)->toLength()->toInt() == 0) { $this->setErrorOnInput(self::$objFaqTableFAnswer, new S(FAQ_ANSWER_CANNOT_BE_EMPTY)); } } if ($this->checkPOST(self::$objFaqTableFQuestion)->toBoolean() == TRUE) { if ($this->getPOST(self::$objFaqTableFQuestion)->toLength()->toInt() == 0) { $this->setErrorOnInput(self::$objFaqTableFQuestion, new S(FAQ_QUESTION_CANNOT_BE_EMPTY)); } if ($this->getPOST(self::$objFaqTableFQuestion) != $this->getFaqInfoById($_GET[ADMIN_ACTION_ID], self::$objFaqTableFQuestion)) { if ($this->checkFaqQuestionIsUnique($this->getPOST(self::$objFaqTableFQuestion))->toBoolean() == FALSE) { $this->setErrorOnInput(self::$objFaqTableFQuestion, new S(FAQ_QUESTION_MUST_BE_UNIQUE)); } if ($this->checkFaqQuestionIsUnique(URL::getURLFromString($this->getPOST(self::$objFaqTableFQuestion)))->toBoolean() == FALSE) { $this->setErrorOnInput(self::$objFaqTableFQuestion, new S(FAQ_QUESTION_URL_MUST_BE_UNIQUE)); } } } // Get AJAX; $this->getAjaxErrors(); // Do the form, make it happen; $this->setMethod(new S('POST'))->setEnctype(new S('multipart/form-data'))->setFieldset(new S(FAQ_EDIT_FAQ))->setSQLAction(new S('update'))->setTableName(self::$objFaqTable)->setUpdateId($_GET[ADMIN_ACTION_ID])->setUpdateField(self::$objFaqTableFId); if ($this->checkPOST(self::$objFaqTableFQuestion)->toBoolean() == TRUE) { $this->setExtraUpdateData(self::$objFaqTableFSEO, URL::getURLFromString($this->getPOST(self::$objFaqTableFQuestion))); } $this->setName($objFormToRender)->setRedirect($objURLToGoBack)->setAJAXEnabledForm(new B(FALSE))->setInputType(new S('submit'))->setInputInfoMessage($this->getHELP($objFormToRender))->setValue(new S(FAQ_EDIT_FAQ))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objFaqTableFQuestion)->setLabel(new S(FAQ_QUESTION))->setContainerDiv(new B(TRUE))->setInputType(new S('textarea'))->setName(self::$objFaqTableFAnswer)->setTinyMCETextarea(new B(TRUE))->setLabel(new S(FAQ_ANSWER))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; case 'faqErase': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION, ADMIN_ACTION_ID))); // Do erase it ... $this->_Q(_QS('doDELETE')->doToken('%table', self::$objFaqTable)->doToken('%condition', new S('%objFaqTableFId = "%Id"'))->doToken('%Id', $_GET[ADMIN_ACTION_ID])); // Do a redirect back; $this->setHeaderKey($objURLToGoBack, new S('Location')); break; } }
/** * Will render a specified form, the name of the form given by the first parameter; * * This method will render one of the forms for our object, invoked by giving the proper form identifier to the current form. * We have chosen this method of invoking forms, because we just had too many this->renderSomethingMethod (), which really had * an impact on code massiveness. Also, having code organized in switch/case statements leads us to be able to share common * settings between different forms, as we've done with the methods defined in the __CALL method above; * * For example, if we wanted to share some common configuration between a create and an edit form, we could have introduced * two switches in this method, one that would have set the common options, and the second, would have just passed through * again, and get the already set configuration options, using them. This means that if we needed to change behavior of * some interconnected forms, that would mean modifying the needed code one place only, which is a big advantage over * having separated methods for each form. Maybe if we extended this object, you guys could understand the functionality; * * @param string $objFormToRender The name of the form to render; * @return mixed Depends on the rendered form if it returns something or not; */ public function renderForm(S $objFormToRender, A $objFormArray = NULL) { // Make them defaults ... if ($objFormArray == NULL) { $objFormArray = new A(); } // Do a switch ... switch ($objFormToRender) { case 'newsletterSearch': break; case 'newsletterCreate': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(); // Do some work; if ($this->checkPOST(self::$objLetterTableFEML)->toBoolean() == TRUE) { if ($this->checkSubscriberAddressIsUnique($this->getPOST(self::$objLetterTableFEML))->toBoolean() == FALSE) { $this->setErrorOnInput(self::$objLetterTableFEML, new S(NEWSLETTER_EMAIL_MUST_BE_UNIQUE)); } if ($this->getPOST(self::$objLetterTableFEML)->toLength()->toInt() == 0) { $this->setErrorOnInput(self::$objLetterTableFEML, new S(NEWSLETTER_FIELD_IS_EMPTY)); } } if ($this->checkPOST(self::$objLetterTableFFirstName)->toBoolean() == TRUE) { if ($this->getPOST(self::$objLetterTableFFirstName)->toLength()->toInt() == 0) { $this->setErrorOnInput(self::$objLetterTableFFirstName, new S(NEWSLETTER_FIELD_IS_EMPTY)); } } if ($this->checkPOST(self::$objLetterTableFLastName)->toBoolean() == TRUE) { if ($this->getPOST(self::$objLetterTableFLastName)->toLength()->toInt() == 0) { $this->setErrorOnInput(self::$objLetterTableFLastName, new S(NEWSLETTER_FIELD_IS_EMPTY)); } } // Get AJAX; $this->getAjaxErrors(); // Do the form, make it happen; $this->setMethod(new S('POST'))->setEnctype(new S('multipart/form-data'))->setFieldset(new S(NEWSLETTER_ADD))->setSQLAction(new S('update'))->setTableName(self::$objLetterTable)->setUpdateId(new S('#nextTableAutoIncrement'))->setUpdateField(self::$objLetterTableFId)->setExtraUpdateData(self::$objLetterTableFSubscribed, new S((string) time()))->setExtraUpdateData(self::$objLetterTableFConfirmed, new S('Y')); if ($this->checkPOST(self::$objLetterTableFEML)->toBoolean() == TRUE) { $this->setRedirect($objURLToGoBack); } $this->setName($objFormToRender)->setAJAXEnabledForm(new B(FALSE))->setInputType(new S('submit'))->setName(new S('submit'))->setValue(new S(NEWSLETTER_ADD))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objLetterTableFEML)->setLabel(new S(NEWSLETTER_EMAIL))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objLetterTableFFirstName)->setLabel(new S(NEWSLETTER_FIRSTNAME))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objLetterTableFLastName)->setLabel(new S(NEWSLETTER_LASTNAME))->setContainerDiv(new B(TRUE))->setInputType(new S('select'))->setName(self::$objLetterTableFType)->setLabel(new S(NEWSLETTER_TYPE))->setContainerDiv(new B(TRUE))->setInputType(new S('option'))->setName(new S('nw_html'))->setValue(new S('HTML'))->setLabel(new S(NEWSLETTER_HTML))->setContainerDiv(new B(TRUE))->setInputType(new S('option'))->setName(new S('nw_txt'))->setValue(new S('PLAIN'))->setLabel(new S(NEWSLETTER_PLAIN))->setContainerDiv(new B(TRUE))->setInputType(new S('select'))->setLabel(new S(NEWSLETTER_CATEGORY))->setName(self::$objLetterTableFCategoryId)->setContainerDiv(new B(TRUE)); // Categories ... foreach ($this->getCategories() as $k => $v) { $this->setInputType(new S('option'))->setName($v[self::$objMPTT->objIdField])->setValue($v[self::$objMPTT->objIdField])->setLabel(new S(str_repeat('--' . _SP, (int) $v['depth']->toString()) . MPTT::mpttRemoveUnique($v[self::$objMPTT->objNameOfNode]))); } // Continue ... $this->setFormEndAndExecute(new B(TRUE)); break; case 'newsletterEdit': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION, ADMIN_ACTION_ID))); // Do some work; if ($this->checkPOST(self::$objLetterTableFEML)->toBoolean() == TRUE) { if ($this->getPOST(self::$objLetterTableFEML) != $this->getSubscriberInfoById($_GET[ADMIN_ACTION_ID], self::$objLetterTableFEML)) { if ($this->checkSubscriberAddressIsUnique($this->getPOST(self::$objLetterTableFEML))->toBoolean() == FALSE) { $this->setErrorOnInput(self::$objLetterTableFEML, new S(NEWSLETTER_EMAIL_MUST_BE_UNIQUE)); } } if ($this->getPOST(self::$objLetterTableFEML)->toLength()->toInt() == 0) { $this->setErrorOnInput(self::$objLetterTableFEML, new S(NEWSLETTER_FIELD_IS_EMPTY)); } } if ($this->checkPOST(self::$objLetterTableFFirstName)->toBoolean() == TRUE) { if ($this->getPOST(self::$objLetterTableFFirstName)->toLength()->toInt() == 0) { $this->setErrorOnInput(self::$objLetterTableFFirstName, new S(NEWSLETTER_FIELD_IS_EMPTY)); } } if ($this->checkPOST(self::$objLetterTableFLastName)->toBoolean() == TRUE) { if ($this->getPOST(self::$objLetterTableFLastName)->toLength()->toInt() == 0) { $this->setErrorOnInput(self::$objLetterTableFLastName, new S(NEWSLETTER_FIELD_IS_EMPTY)); } } // Get AJAX; $this->getAjaxErrors(); // Do the form, make it happen; $this->setMethod(new S('POST'))->setEnctype(new S('multipart/form-data'))->setFieldset(new S(NEWSLETTER_EDIT))->setSQLAction(new S('update'))->setTableName(self::$objLetterTable)->setUpdateId($_GET[ADMIN_ACTION_ID])->setUpdateField(self::$objLetterTableFId); if ($this->checkPOST(self::$objLetterTableFEML)->toBoolean() == TRUE) { $this->setRedirect($objURLToGoBack); } $this->setName($objFormToRender)->setAJAXEnabledForm(new B(FALSE))->setInputType(new S('submit'))->setName(new S('submit'))->setValue(new S(NEWSLETTER_EDIT))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objLetterTableFEML)->setLabel(new S(NEWSLETTER_EMAIL))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objLetterTableFFirstName)->setLabel(new S(NEWSLETTER_FIRSTNAME))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objLetterTableFLastName)->setLabel(new S(NEWSLETTER_LASTNAME))->setContainerDiv(new B(TRUE))->setInputType(new S('select'))->setName(self::$objLetterTableFType)->setLabel(new S(NEWSLETTER_TYPE))->setContainerDiv(new B(TRUE))->setInputType(new S('option'))->setName(new S('nw_html'))->setValue(new S('HTML'))->setLabel(new S(NEWSLETTER_HTML))->setContainerDiv(new B(TRUE))->setInputType(new S('option'))->setName(new S('nw_txt'))->setValue(new S('PLAIN'))->setLabel(new S(NEWSLETTER_PLAIN))->setContainerDiv(new B(TRUE))->setInputType(new S('select'))->setLabel(new S(NEWSLETTER_CATEGORY))->setName(self::$objLetterTableFCategoryId)->setContainerDiv(new B(TRUE)); // Categories ... foreach ($this->getCategories() as $k => $v) { $this->setInputType(new S('option'))->setName($v[self::$objMPTT->objIdField])->setValue($v[self::$objMPTT->objIdField])->setLabel(new S(str_repeat('--' . _SP, (int) $v['depth']->toString()) . MPTT::mpttRemoveUnique($v[self::$objMPTT->objNameOfNode]))); } // Continue ... $this->setFormEndAndExecute(new B(TRUE)); break; case 'newsletterErase': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION, ADMIN_ACTION_ID))); // Do erase it ... $this->_Q(_QS('doDELETE')->doToken('%table', self::$objLetterTable)->doToken('%condition', new S('%objLetterTableFId = "%Id"'))->doToken('%Id', $_GET[ADMIN_ACTION_ID])); // Do a redirect, and get the user back where he belongs; $this->setHeaderKey($objURLToGoBack, new S('Location')); break; case 'categoryCreate': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(); // Do some work ... if ($this->checkPOST(new S('categories_show_all'))->toBoolean() == TRUE) { // Redirect to proper ... $this->setHeaderKey(URL::rewriteURL(new A(array(ADMIN_SHOW_ALL)), new A(array('1'))), new S('Location')); } if ($this->checkPOST(new S('add_category_submit'))->toBoolean() == TRUE) { // Set some requirements; $objFormHappened = new B(FALSE); $objToCheck = MPTT::mpttAddUnique($this->getPOST(new S('add_category')), new S((string) $_SERVER['REQUEST_TIME'])); if ($objToCheck->toLength()->toInt() == 0) { $this->setErrorOnInput(new S('add_category'), new S(NEWSLETTER_CATEGORY_NAME_IS_EMPTY)); // Set the memory; $objFormHappened->switchType(); } else { if (self::$objMPTT->mpttCheckIfNodeExists($objToCheck)->toBoolean() == TRUE) { // Check to see if the group exists, and tell the user the group exists; $this->setErrorOnInput(new S('add_category'), new S(NEWSLETTER_CATEGORY_ALREADY_EXISTS)); // Set the memory; $objFormHappened->switchType(); } if ($this->checkCategoryURLIsUnique(URL::getURLFromString($objToCheck))->toBoolean() == FALSE) { $this->setErrorOnInput(new S('add_category'), new S(NEWSLETTER_CATEGORY_URL_MUST_BE_UNIQUE)); } } // Get AJAX; $this->getAjaxErrors(); if ($objFormHappened->toBoolean() == FALSE) { // Remember if we should add it as a brother or child; $objAddNodeAS = NULL; // Do a switch ... switch ($this->getPOST(new S('add_category_as_what'))) { case NEWSLETTER_CATEGORY_CHILD: $objAddNodeAS = new S((string) MPTT::FIRST_CHILD); break; case NEWSLETTER_CATEGORY_LAST_CHILD: $objAddNodeAS = new S((string) MPTT::LAST_CHILD); break; case NEWSLETTER_CATEGORY_BROTHER: $objAddNodeAS = new S((string) MPTT::PREVIOUS_BROTHER); break; case NEWSLETTER_CATEGORY_NEXT_BROTHER: $objAddNodeAS = new S((string) MPTT::NEXT_BROTHER); break; } // Add the node; self::$objMPTT->mpttAddNode($objToCheck, $this->getPOST(new S('add_category_parent_or_bro')), $objAddNodeAS); } } // Do the form, make it happen; $this->setMethod(new S('POST'))->setFieldset(new S(NEWSLETTER_ADD_CATEGORY))->setName($objFormToRender)->setRedirect($objURLToGoBack)->setAJAXEnabledForm(new B(FALSE))->setInputType(new S('submit'))->setName(new S('categories_show_all'))->setValue(new S(NEWSLETTER_SHOW_ALL_CATEGORIES))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('submit'))->setName(new S('add_category_submit'))->setValue(new S(NEWSLETTER_ADD_CATEGORY))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(new S('add_category'))->setLabel(new S(NEWSLETTER_CATEGORY_NAME_LABEL))->setJSRegExpReplace(new S(self::REGEXP_JS_CATEGORY))->setContainerDiv(new B(TRUE))->setInputType(new S('select'))->setContainerDiv(new B(TRUE))->setName(new S('add_category_as_what'))->setLabel(new S(NEWSLETTER_AS_A))->setInputType(new S('option'))->setName(new S('as_first_child'))->setLabel(new S(NEWSLETTER_CATEGORY_CHILD))->setInputType(new S('option'))->setName(new S('as_last_child'))->setLabel(new S(NEWSLETTER_CATEGORY_LAST_CHILD))->setInputType(new S('option'))->setName(new S('as_previous_brother'))->setLabel(new S(NEWSLETTER_CATEGORY_BROTHER))->setInputType(new S('option'))->setName(new S('as_next_brother'))->setLabel(new S(NEWSLETTER_CATEGORY_NEXT_BROTHER))->setInputType(new S('select'))->setContainerDiv(new B(TRUE))->setName(new S('add_category_parent_or_bro'))->setLabel(new S(NEWSLETTER_OF_CATEGORY)); // Category parent or brother of this one ... foreach ($this->getCategories() as $k => $v) { $this->setInputType(new S('option'))->setName($v[self::$objMPTT->objNameOfNode])->setValue($v[self::$objMPTT->objNameOfNode])->setLabel(new S(str_repeat('--' . _SP, (int) $v['depth']->toString()) . MPTT::mpttRemoveUnique(clone $v[self::$objMPTT->objNameOfNode]))); } // Continue, execute the form ... $this->setFormEndAndExecute(new B(TRUE)); break; case 'categoryEdit': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION, ADMIN_ACTION_ID))); // Do validation and error on it if something goes wrong; if ($this->checkPOST()->toBoolean() == TRUE) { // Set some requirements; $objFormHappened = new B(FALSE); $objToCheck = MPTT::mpttAddUnique($this->getPOST(self::$objCategoryTableFName), $this->getCategoryInfoById($_GET[ADMIN_ACTION_ID], self::$objCategoryTableFDate)); if ($objToCheck->toLength()->toInt() == 0) { // Check for empty group name, and error on it. We don't allow empty group names; $this->setErrorOnInput(self::$objCategoryTableFName, new S(NEWSLETTER_CATEGORY_NAME_IS_EMPTY)); // Set the memory; $objFormHappened->switchType(); } else { if ($this->getCategoryInfoById($_GET[ADMIN_ACTION_ID], self::$objCategoryTableFName) != $objToCheck) { if (self::$objMPTT->mpttCheckIfNodeExists($objToCheck)->toBoolean() == TRUE) { // Check to see if the group exists; $this->setErrorOnInput(self::$objCategoryTableFName, new S(NEWSLETTER_CATEGORY_ALREADY_EXISTS)); // Set the memory; $objFormHappened->switchType(); } } } // Get AJAX; $this->getAjaxErrors(); if ($objFormHappened->toBoolean() == FALSE) { // Make a form that will auto-insert; (because we have _SESSION['POST']); $this->setMethod(new S('POST'))->setEnctype(new S('multipart/form-data'))->setSQLAction(new S('update'))->setTableName(self::$objCategoryTable)->setUpdateId($_GET[ADMIN_ACTION_ID])->setUpdateField(self::$objCategoryTableFId)->setExtraUpdateData(self::$objCategoryTableFSEO, URL::getURLFromString($this->getPOST(self::$objCategoryTableFName)))->setName($objFormToRender)->setRedirect($objURLToGoBack)->setInputType(new S('textarea'))->setName(self::$objCategoryTableFDescription)->setLabel(new S(NEWSLETTER_CATEGORY_DESCRIPTION))->setTinyMCETextarea(new B(TRUE))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); } } // Do the form, make it happen; $this->setMethod(new S('POST'))->setSQLAction(new S('update'))->setTableName(self::$objCategoryTable)->setUpdateId($_GET[ADMIN_ACTION_ID])->setUpdateField(self::$objCategoryTableFId)->setFieldset(new S(NEWSLETTER_EDIT_CATEGORY))->setName($objFormToRender)->setAJAXEnabledForm(new B(FALSE))->setInputType(new S('submit'))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setName(new S('edit_category_submit'))->setValue(new S(NEWSLETTER_EDIT_CATEGORY))->setInputType(new S('text'))->setName(self::$objCategoryTableFName)->setMPTTRemoveUnique(new B(TRUE))->setLabel(new S(NEWSLETTER_CATEGORY_NAME_LABEL))->setJSRegExpReplace(new S(self::REGEXP_JS_CATEGORY))->setContainerDiv(new B(TRUE))->setInputType(new S('textarea'))->setName(self::$objCategoryTableFDescription)->setLabel(new S(NEWSLETTER_CATEGORY_DESCRIPTION))->setTinyMCETextarea(new B(TRUE))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; case 'categoryErase': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION, ADMIN_ACTION_ID))); // Check if the category has items; if ($this->getSubscriberCount(_S('WHERE %objLetterTableFCategoryId = "%Id"')->doToken('%Id', $_GET[ADMIN_ACTION_ID]))->toInt() != 0) { // Set an error message; self::$objAdministration->setErrorMessage(new S(NEWSLETTER_CATEGORY_HAS_ARTICLES), $objURLToGoBack); } else { // Do erase the group node from the table; self::$objMPTT->mpttRemoveNode($this->getCategoryInfoById($_GET[ADMIN_ACTION_ID], self::$objCategoryTableFName)); // Do a redirect, and get the user back where he belongs; $this->setHeaderKey($objURLToGoBack, new S('Location')); } // Break out ... break; case 'categoryMove': // Set some predefines; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION, ADMIN_ACTION_TO, ADMIN_ACTION_TYPE))); // Get names, as they are unique; $objThatIsMoved = $this->getCategoryInfoById($_GET[ADMIN_ACTION_ID], self::$objCategoryTableFName); $objWhereToMove = $this->getCategoryInfoById($_GET[ADMIN_ACTION_TO], self::$objCategoryTableFName); // Get the node subtree, that's move, make sure the node we move to ain't a child; $objMovedNodeSubTree = self::$objMPTT->mpttGetTree($objThatIsMoved); // Memorize; $objIsChild = new B(FALSE); foreach ($objMovedNodeSubTree as $k => $v) { if ($v[self::$objMPTT->objNameOfNode] == $objWhereToMove) { $objIsChild->switchType(); } } // Check if it's a child or not; if ($objIsChild->toBoolean() == TRUE) { // Set an error message; self::$objAdministration->setErrorMessage(new S(NEWSLETTER_CATEGORY_MOVED_TO_CHILD), $objURLToGoBack); } else { // Move nodes; self::$objMPTT->mpttMoveNode($objThatIsMoved, $objWhereToMove, $_GET[ADMIN_ACTION_TYPE]); $this->setHeaderKey($objURLToGoBack, new S('Location')); } break; case 'categoryMoveOperation': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_SUBPAGE)), new A(array(MANAGE_NEWSLETTER))); // Do some work; $this->checkPOST()->toBoolean() == TRUE ? $objOLDCategoryId = $this->getPOST(new S('old_category_id')) : ($objOLDCategoryId = new S('0')); // Do the form, make it happen; $this->setMethod(new S('POST'))->setFieldset(new S(NEWSLETTER_MOVE_SUBSCRIBERS))->setSQLAction(new S('update'))->setTableName(self::$objLetterTable)->setUpdateField(self::$objLetterTableFId)->setUpdateWhere($this->doModuleToken(_S('%objLetterTableFCategoryId = "%Id"')->doToken('%Id', $objOLDCategoryId)))->setName($objFormToRender)->setRedirect($objURLToGoBack)->setInputType(new S('submit'))->setValue(new S(NEWSLETTER_MOVE_SUBSCRIBERS))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('select'))->setName(new S('old_category_id'))->setLabel(new S(NEWSLETTER_OLD_CATEGORY))->setContainerDiv(new B(TRUE)); // Cateories; foreach ($this->getCategories() as $k => $v) { $this->setInputType(new S('option'))->setName($v[self::$objMPTT->objIdField])->setValue($v[self::$objMPTT->objIdField])->setLabel(new S(str_repeat('--' . _SP, (int) $v['depth']->toString()) . MPTT::mpttRemoveUnique($v[self::$objMPTT->objNameOfNode]))); } // Categories; $this->setInputType(new S('select'))->setName(self::$objLetterTableFCategoryId)->setLabel(new S(NEWSLETTER_NEW_CATEGORY))->setContainerDiv(new B(TRUE)); foreach ($this->getCategories() as $k => $v) { $this->setInputType(new S('option'))->setName($v[self::$objMPTT->objIdField])->setValue($v[self::$objMPTT->objIdField])->setLabel(new S(str_repeat('--' . _SP, (int) $v['depth']->toString()) . MPTT::mpttRemoveUnique($v[self::$objMPTT->objNameOfNode]))); } // Continue; $this->setFormEndAndExecute(new B(TRUE)); break; } }
/** * Will render a specified form, the name of the form given by the first parameter; * * This method will render one of the forms for our object, invoked by giving the proper form identifier to the current form. * We have chosen this method of invoking forms, because we just had too many this->renderSomethingMethod (), which really had * an impact on code massiveness. Also, having code organized in switch/case statements leads us to be able to share common * settings between different forms, as we've done with the methods defined in the __CALL method above; * * For example, if we wanted to share some common configuration between a create and an edit form, we could have introduced * two switches in this method, one that would have set the common options, and the second, would have just passed through * again, and get the already set configuration options, using them. This means that if we needed to change behavior of * some interconnected forms, that would mean modifying the needed code one place only, which is a big advantage over * having separated methods for each form. Maybe if we extended this object, you guys could understand the functionality; * * @param string $objFormToRender The name of the form to render; * @return mixed Depends on the rendered form if it returns something or not; */ public function renderForm(S $objFormToRender, A $objFormArray = NULL) { // Make them defaults ... if ($objFormArray == NULL) { $objFormArray = new A(); } // Do a switch ... switch ($objFormToRender) { case 'propertyCreate': // Set the URL to go back; $objURLToGoBack = URL::rewriteURL(); // Do some work; if ($this->checkPOST()->toBoolean() == TRUE) { if ($this->checkPOST(self::$objProductsPropertyTableFKey)->toBoolean() == FALSE) { $this->setErrorOnInput(self::$objProductsPropertyTableFKey, new S(PRODUCTS_PROPERTY_CANNOT_BE_EMPTY)); } if ($this->checkPOST(self::$objProductsPropertyTableFVar)->toBoolean() == FALSE) { $this->setErrorOnInput(self::$objProductsPropertyTableFVar, new S(PRODUCTS_VALUE_CANNOT_BE_EMPTY)); } } // Do the form, make it happen; $this->setMethod(new S('POST'))->setEnctype(new S('multipart/form-data'))->setFieldset(new S(PRODUCTS_ADD_PROPERTY))->setSQLAction(new S('update'))->setTableName(self::$objProductsPropertyTable)->setUpdateId(new S('#nextTableAutoIncrement'))->setUpdateField(self::$objProductsPropertyTableFId)->setExtraUpdateData(self::$objProductsPropertyTableFPId, $_GET[ADMIN_ACTION_ID])->setName($objFormToRender)->setRedirect($objURLToGoBack)->setAJAXEnabledForm(new B(FALSE))->setInputType(new S('submit'))->setValue(new S(PRODUCTS_ADD_PROPERTY))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objProductsPropertyTableFKey)->setLabel(new S(PRODUCTS_PROPERTY))->setContainerDiv(new B(TRUE))->setInputType(new S('textarea'))->setName(self::$objProductsPropertyTableFVar)->setLabel(new S(PRODUCTS_VALUE))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; case 'propertyEdit': // Set the URL to go back; $objURLToGoBack = URL::rewriteURL(new A(array(PRODUCTS_ACTION_PROPERTY, PRODUCTS_ID_PROPERTY))); // Do some work; if ($this->checkPOST()->toBoolean() == TRUE) { if ($this->checkPOST(self::$objProductsPropertyTableFKey)->toBoolean() == FALSE) { $this->setErrorOnInput(self::$objProductsPropertyTableFKey, new S(PRODUCTS_PROPERTY_CANNOT_BE_EMPTY)); } if ($this->checkPOST(self::$objProductsPropertyTableFVar)->toBoolean() == FALSE) { $this->setErrorOnInput(self::$objProductsPropertyTableFVar, new S(PRODUCTS_VALUE_CANNOT_BE_EMPTY)); } } $this->setMethod(new S('POST'))->setEnctype(new S('multipart/form-data'))->setFieldset(new S(PRODUCTS_EDIT_PROPERTY))->setSQLAction(new S('update'))->setTableName(self::$objProductsPropertyTable)->setUpdateId($_GET[PRODUCTS_ID_PROPERTY])->setUpdateField(self::$objProductsPropertyTableFId)->setName($objFormToRender)->setRedirect($objURLToGoBack)->setAJAXEnabledForm(new B(FALSE))->setInputType(new S('submit'))->setValue(new S(PRODUCTS_EDIT_PROPERTY))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objProductsPropertyTableFKey)->setLabel(new S(PRODUCTS_PROPERTY))->setContainerDiv(new B(TRUE))->setInputType(new S('textarea'))->setName(self::$objProductsPropertyTableFVar)->setLabel(new S(PRODUCTS_VALUE))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; case 'propertyErase': // Set the URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(PRODUCTS_ACTION_PROPERTY, PRODUCTS_ID_PROPERTY))); // Do erase it ... $this->_Q(_QS('doDELETE')->doToken('%table', self::$objProductsPropertyTable)->doToken('%condition', new S('%objProductsPropertyTableFId = "%Id"'))->doToken('%Id', $_GET[PRODUCTS_ID_PROPERTY])); // Do a redirect, and get the user back where he belongs; $this->setHeaderKey($objURLToGoBack, new S('Location')); break; case 'imageCreate': // Set the URL to go back too; $objURLToGoBack = URL::rewriteURL(); // Do some work; if ($this->checkPOST(self::$objProductsIMGTableFTitle)->toBoolean() == TRUE) { if ($this->getPOST(self::$objProductsIMGTableFTitle)->toLength()->toInt() == 0) { $this->setErrorOnInput(self::$objProductsIMGTableFTitle, new S(PRODUCTS_IMAGE_TITLE_CANNOT_BE_EMPTY)); } } // Do the form, make it happen; $this->setMethod(new S('POST'))->setEnctype(new S('multipart/form-data'))->setFieldset(new S(PRODUCTS_ADD_IMAGE))->setSQLAction(new S('update'))->setTableName(self::$objProductsIMGTable)->setUpdateId(new S('#nextTableAutoIncrement'))->setUpdateField(self::$objProductsIMGTableFId)->setUploadDirectory(new S('products/images/' . $_GET[ADMIN_ACTION_ID]))->setUploadImageResize(new A(array(60 => 60, 100 => 100, 128 => 128, 320 => 240, 640 => 480, 800 => 600)))->setExtraUpdateData(self::$objProductsIMGTableFProdId, $_GET[ADMIN_ACTION_ID])->setName($objFormToRender)->setRedirect($objURLToGoBack)->setAJAXEnabledForm(new B(FALSE))->setInputType(new S('submit'))->setInputInfoMessage($this->getHELP($objFormToRender))->setValue(new S(PRODUCTS_ADD_IMAGE))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objProductsIMGTableFTitle)->setLabel(new S(PRODUCTS_IMAGE_TITLE))->setContainerDiv(new B(TRUE))->setInputType(new S('file'))->setName(self::$objProductsIMGTableFURL)->setLabel(new S(PRODUCTS_IMAGE))->setContainerDiv(new B(TRUE))->setInputType(new S('textarea'))->setName(self::$objProductsIMGTableFCaption)->setLabel(new S(PRODUCTS_CAPTION))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; case 'imageEdit': // Set the URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(PRODUCTS_ACTION_IMAGE, PRODUCTS_ID_IMAGE))); // Do the form, make it happen; if ($this->checkPOST(self::$objProductsIMGTableFTitle)->toBoolean() == TRUE) { if ($this->getPOST(self::$objProductsIMGTableFTitle)->toLength()->toInt() == 0) { $this->setErrorOnInput(self::$objProductsIMGTableFTitle, new S(PRODUCTS_IMAGE_TITLE_CANNOT_BE_EMPTY)); } } $this->setMethod(new S('POST'))->setEnctype(new S('multipart/form-data'))->setFieldset(new S(PRODUCTS_EDIT_IMAGE))->setSQLAction(new S('update'))->setTableName(self::$objProductsIMGTable)->setUpdateId($_GET[PRODUCTS_ID_IMAGE])->setUpdateField(self::$objProductsIMGTableFId)->setName($objFormToRender)->setRedirect($objURLToGoBack)->setAJAXEnabledForm(new B(FALSE))->setUploadDirectory(new S('products/images/' . $_GET[ADMIN_ACTION_ID]))->setUploadImageResize(new A(array(60 => 60, 100 => 100, 128 => 128, 320 => 240, 640 => 480, 800 => 600)))->setInputType(new S('submit'))->setValue(new S(PRODUCTS_EDIT_IMAGE))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objProductsIMGTableFTitle)->setLabel(new S(PRODUCTS_IMAGE_TITLE))->setContainerDiv(new B(TRUE))->setInputType(new S('file'))->setName(self::$objProductsIMGTableFURL)->setLabel(new S(PRODUCTS_IMAGE))->setFileController(new B(TRUE))->setContainerDiv(new B(TRUE))->setInputType(new S('textarea'))->setName(self::$objProductsIMGTableFCaption)->setLabel(new S(PRODUCTS_CAPTION))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; case 'imageErase': // Set the URL to back too; $objURLToGoBack = URL::rewriteURL(new A(array(PRODUCTS_ACTION_IMAGE, PRODUCTS_ID_IMAGE))); // First, delete existing images; $objProductImages = $this->_Q(_QS('doSELECT')->doToken('%what', self::$objProductsIMGTableFURL)->doToken('%table', self::$objProductsIMGTable)->doToken('%condition', new S('WHERE %objProductsIMGTableFId = "%Id"'))->doToken('%Id', $_GET[PRODUCTS_ID_IMAGE])); // Knowing the images, delete THEM; foreach ($objProductImages as $k => $v) { UNLINK(DOCUMENT_ROOT . UPLOAD_DIR . _S . 'products/images/' . $_GET[ADMIN_ACTION_ID] . _S . $v['url']); UNLINK(DOCUMENT_ROOT . UPLOAD_DIR . _S . 'products/images/' . $_GET[ADMIN_ACTION_ID] . _S . '60_60_' . $v['url']); UNLINK(DOCUMENT_ROOT . UPLOAD_DIR . _S . 'products/images/' . $_GET[ADMIN_ACTION_ID] . _S . '100_100_' . $v['url']); UNLINK(DOCUMENT_ROOT . UPLOAD_DIR . _S . 'products/images/' . $_GET[ADMIN_ACTION_ID] . _S . '128_128_' . $v['url']); UNLINK(DOCUMENT_ROOT . UPLOAD_DIR . _S . 'products/images/' . $_GET[ADMIN_ACTION_ID] . _S . '320_240_' . $v['url']); UNLINK(DOCUMENT_ROOT . UPLOAD_DIR . _S . 'products/images/' . $_GET[ADMIN_ACTION_ID] . _S . '640_480_' . $v['url']); UNLINK(DOCUMENT_ROOT . UPLOAD_DIR . _S . 'products/images/' . $_GET[ADMIN_ACTION_ID] . _S . '800_600_' . $v['url']); } // Do erase it ... $this->_Q(_QS('doDELETE')->doToken('%table', self::$objProductsIMGTable)->doToken('%condition', new S('%objProductsIMGTableFId = "%Id"'))->doToken('%Id', $_GET[PRODUCTS_ID_IMAGE])); // Do a redirect, and get the user back where he belongs; $this->setHeaderKey($objURLToGoBack, new S('Location')); break; case 'productCreate': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(); // Do some work; if ($this->checkPOST(self::$objProductsTableFCode)->toBoolean() == TRUE) { if ($this->getPOST(self::$objProductsTableFCode)->toLength()->toInt() == 0) { $this->setErrorOnInput(self::$objProductsTableFCode, new S(PRODUCTS_CODE_MUST_BE_ENTERED)); } else { if ($this->checkCodeIsUnique($this->getPOST(self::$objProductsTableFCode))->toBoolean() == FALSE) { $this->setErrorOnInput(self::$objProductsTableFCode, new S(PRODUCTS_CODE_MUST_BE_UNIQUE)); } } } if ($this->checkPOST(self::$objProductsTableFName)->toBoolean() == TRUE) { if ($this->getPOST(self::$objProductsTableFName)->toLength()->toInt() == 0) { $this->setErrorOnInput(self::$objProductsTableFName, new S(PRODUCTS_NAME_MUST_BE_ENTERED)); } else { if ($this->checkProductNameIsUnique($this->getPOST(self::$objProductsTableFName))->toBoolean() == FALSE) { $this->setErrorOnInput(self::$objProductsTableFName, new S(PRODUCTS_NAME_MUST_BE_UNIQUE)); } } } if ($this->checkPOST(self::$objProductsTableFName)->toBoolean() == TRUE) { if ($this->checkProductURLIsUnique(URL::getURLFromString($this->getPOST(self::$objProductsTableFName)))->toBoolean() == FALSE) { $this->setErrorOnInput(self::$objProductsTableFName, new S(PRODUCTS_URL_MUST_BE_UNIQUE)); } } if ($this->checkPOST(self::$objProductsTableFStoc)->toBoolean() == TRUE) { if ($this->getPOST(self::$objProductsTableFStoc)->toLength()->toInt() == 0) { $this->setErrorOnInput(self::$objProductsTableFStoc, new S(PRODUCTS_STOCK_MUST_BE_ENTERED)); } else { // Get some requirements; $objStock = new I((int) $this->getPOST(self::$objProductsTableFStoc)->toString()); // Do some MORE validation; if ($objStock->toInt() < 0) { $this->setErrorOnInput(self::$objProductsTableFStoc, new S(PRODUCTS_STOCK_CANNOT_BE_NEGATIVE)); } } } if ($this->checkPOST(self::$objProductsTableFPrice)->toBoolean() == TRUE) { if ($this->getPOST(self::$objProductsTableFPrice)->toLength()->toInt() == 0) { $this->setErrorOnInput(self::$objProductsTableFPrice, new S(PRODUCTS_PRICE_MUST_BE_ENTERED)); } else { // Get some requirements; $objPrice = new I((int) $this->getPOST(self::$objProductsTableFPrice)->toString()); // Do some MORE validation; if ($objPrice->toInt() < 0) { $this->setErrorOnInput(self::$objProductsTableFPrice, new S(PRODUCTS_PRICE_CANNOT_BE_NEGATIVE)); } } } // Do the form, make it happen; $this->setMethod(new S('POST'))->setEnctype(new S('multipart/form-data'))->setFieldset(new S(PRODUCTS_ADD_PRODUCT))->setSQLAction(new S('update'))->setTableName(self::$objProductsTable)->setUpdateId(new S('#nextTableAutoIncrement'))->setUpdateField(self::$objProductsTableFId)->setUploadDirectory(new S('products/pdf'))->setName($objFormToRender)->setRedirect($objURLToGoBack)->setAJAXEnabledForm(new B(FALSE)); // Set some EXTRA data; if ($this->checkPOST(self::$objProductsTableFName)->toBoolean() == TRUE) { $this->setExtraUpdateData(self::$objProductsTableFSEO, URL::getURLFromString($this->getPOST(self::$objProductsTableFName))); } // Continue; $this->setInputType(new S('submit'))->setValue(new S(PRODUCTS_ADD_PRODUCT))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('select'))->setContainerDiv(new B(TRUE))->setName(self::$objProductsTableFCategoryId)->setLabel(new S(PRODUCTS_CATEGORY)); // Category parent or brother of this one ... foreach ($this->getCategories() as $k => $v) { $this->setInputType(new S('option'))->setName($v[self::$objMPTT->objIdField])->setValue($v[self::$objMPTT->objIdField])->setLabel(new S(str_repeat('--' . _SP, (int) $v['depth']->toString()) . MPTT::mpttRemoveUnique($v[self::$objMPTT->objNameOfNode]))); } // Continue; $this->setInputType(new S('text'))->setName(self::$objProductsTableFCode)->setLabel(new S(PRODUCTS_CODE))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objProductsTableFName)->setLabel(new S(PRODUCTS_NAME))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objProductsTableFURL)->setLabel(new S(PRODUCTS_URL))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objProductsTableFStoc)->setLabel(new S(PRODUCTS_STOCK))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objProductsTableFPrice)->setLabel(new S(PRODUCTS_PRICE))->setContainerDiv(new B(TRUE))->setInputType(new S('file'))->setName(self::$objProductsTableFPDF)->setLabel(new S(PRODUCTS_PDF))->setFileController(new B(TRUE))->setContainerDiv(new B(TRUE))->setInputType(new S('textarea'))->setName(self::$objProductsTableFDescription)->setLabel(new S(PRODUCTS_DECRIPTION))->setTinyMCETextarea(new B(TRUE))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; case 'productEdit': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION, ADMIN_ACTION_ID))); // Do some work; if ($this->checkPOST(self::$objProductsTableFCode)->toBoolean() == TRUE) { if ($this->getPOST(self::$objProductsTableFCode)->toLength()->toInt() == 0) { $this->setErrorOnInput(self::$objProductsTableFCode, new S(PRODUCTS_CODE_MUST_BE_ENTERED)); } else { if ($this->getPOST(self::$objProductsTableFCode) != $this->getProductInfoById($_GET[ADMIN_ACTION_ID], self::$objProductsTableFCode)) { if ($this->checkCodeIsUnique($this->getPOST(self::$objProductsTableFCode))->toBoolean() == FALSE) { $this->setErrorOnInput(self::$objProductsTableFCode, new S(PRODUCTS_CODE_MUST_BE_UNIQUE)); } } } } if ($this->checkPOST(self::$objProductsTableFName)->toBoolean() == TRUE) { if ($this->getPOST(self::$objProductsTableFName)->toLength()->toInt() == 0) { $this->setErrorOnInput(self::$objProductsTableFName, new S(PRODUCTS_NAME_MUST_BE_ENTERED)); } else { if ($this->getPOST(self::$objProductsTableFName) != $this->getProductInfoById($_GET[ADMIN_ACTION_ID], self::$objProductsTableFName)) { if ($this->checkProductNameIsUnique($this->getPOST(self::$objProductsTableFName))->toBoolean() == FALSE) { $this->setErrorOnInput(self::$objProductsTableFName, new S(PRODUCTS_NAME_MUST_BE_UNIQUE)); } if ($this->checkPOST(self::$objProductsTableFName)->toBoolean() == TRUE) { if ($this->checkProductURLIsUnique(URL::getURLFromString($this->getPOST(self::$objProductsTableFName)))->toBoolean() == FALSE) { $this->setErrorOnInput(self::$objProductsTableFName, new S(PRODUCTS_URL_MUST_BE_UNIQUE)); } } } } } if ($this->checkPOST(self::$objProductsTableFStoc)->toBoolean() == TRUE) { if ($this->getPOST(self::$objProductsTableFStoc)->toLength()->toInt() == 0) { $this->setErrorOnInput(self::$objProductsTableFStoc, new S(PRODUCTS_STOCK_MUST_BE_ENTERED)); } else { // Get some requirements; $objStock = new I((int) $this->getPOST(self::$objProductsTableFStoc)->toString()); // Do some MORE validation; if ($objStock->toInt() < 0) { $this->setErrorOnInput(self::$objProductsTableFStoc, new S(PRODUCTS_STOCK_CANNOT_BE_NEGATIVE)); } } } if ($this->checkPOST(self::$objProductsTableFPrice)->toBoolean() == TRUE) { if ($this->getPOST(self::$objProductsTableFPrice)->toLength()->toInt() == 0) { $this->setErrorOnInput(self::$objProductsTableFPrice, new S(PRODUCTS_PRICE_MUST_BE_ENTERED)); } else { // Get some requirements; $objPrice = new I((int) $this->getPOST(self::$objProductsTableFPrice)->toString()); // Do some MORE validation; if ($objPrice->toInt() < 0) { $this->setErrorOnInput(self::$objProductsTableFPrice, new S(PRODUCTS_PRICE_CANNOT_BE_NEGATIVE)); } } } // Do the form, make it happen; $this->setMethod(new S('POST'))->setEnctype(new S('multipart/form-data'))->setFieldset(new S(PRODUCTS_EDIT_PRODUCT))->setSQLAction(new S('update'))->setTableName(self::$objProductsTable)->setUpdateId($_GET[ADMIN_ACTION_ID])->setUpdateField(self::$objProductsTableFId)->setName($objFormToRender)->setRedirect($objURLToGoBack)->setAJAXEnabledForm(new B(FALSE)); // Set some EXTRA data; if ($this->checkPOST(self::$objProductsTableFName)->toBoolean() == TRUE) { $this->setExtraUpdateData(self::$objProductsTableFSEO, URL::getURLFromString($this->getPOST(self::$objProductsTableFName))); } // Continue; $this->setInputType(new S('submit'))->setValue(new S(PRODUCTS_EDIT_PRODUCT))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('select'))->setContainerDiv(new B(TRUE))->setName(self::$objProductsTableFCategoryId)->setLabel(new S(PRODUCTS_CATEGORY)); // Category parent or brother of this one ... foreach ($this->getCategories() as $k => $v) { $this->setInputType(new S('option'))->setName($v[self::$objMPTT->objIdField])->setValue($v[self::$objMPTT->objIdField])->setLabel(new S(str_repeat('--' . _SP, (int) $v['depth']->toString()) . MPTT::mpttRemoveUnique($v[self::$objMPTT->objNameOfNode]))); } // Continue; $this->setInputType(new S('text'))->setName(self::$objProductsTableFCode)->setLabel(new S(PRODUCTS_CODE))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objProductsTableFName)->setLabel(new S(PRODUCTS_NAME))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objProductsTableFURL)->setLabel(new S(PRODUCTS_URL))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objProductsTableFStoc)->setLabel(new S(PRODUCTS_STOCK))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objProductsTableFPrice)->setLabel(new S(PRODUCTS_PRICE))->setContainerDiv(new B(TRUE))->setInputType(new S('file'))->setName(self::$objProductsTableFPDF)->setLabel(new S(PRODUCTS_PDF))->setFileController(new B(TRUE))->setContainerDiv(new B(TRUE))->setInputType(new S('textarea'))->setName(self::$objProductsTableFDescription)->setLabel(new S(PRODUCTS_DECRIPTION))->setTinyMCETextarea(new B(TRUE))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; case 'productErase': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION, ADMIN_ACTION_ID))); // First, delete existing images; $objProductImages = $this->_Q(_QS('doSELECT')->doToken('%what', self::$objProductsIMGTableFURL)->doToken('%table', self::$objProductsIMGTable)->doToken('%condition', new S('WHERE %objProductsIMGTableFProdId = "%Id"'))->doToken('%Id', $_GET[ADMIN_ACTION_ID])); // Knowing the images, delete THEM; foreach ($objProductImages as $k => $v) { UNLINK(DOCUMENT_ROOT . UPLOAD_DIR . _S . 'products/images' . _S . $v['url']); UNLINK(DOCUMENT_ROOT . UPLOAD_DIR . _S . 'products/images' . _S . '60_60_' . $v['url']); UNLINK(DOCUMENT_ROOT . UPLOAD_DIR . _S . 'products/images' . _S . '100_100_' . $v['url']); UNLINK(DOCUMENT_ROOT . UPLOAD_DIR . _S . 'products/images' . _S . '128_128_' . $v['url']); UNLINK(DOCUMENT_ROOT . UPLOAD_DIR . _S . 'products/images' . _S . '320_240_' . $v['url']); UNLINK(DOCUMENT_ROOT . UPLOAD_DIR . _S . 'products/images' . _S . '640_480_' . $v['url']); UNLINK(DOCUMENT_ROOT . UPLOAD_DIR . _S . 'products/images' . _S . '800_600_' . $v['url']); } // Do erase associated images; $this->_Q(_QS('doDELETE')->doToken('%table', self::$objProductsIMGTable)->doToken('%condition', new S('%objProductsIMGTableFProdId = "%Id"'))->doToken('%Id', $_GET[ADMIN_ACTION_ID])); // Do erase associated properties ... $this->_Q(_QS('doDELETE')->doToken('%table', self::$objProductsPropertyTable)->doToken('%condition', new S('%objProductsPropertyTableFPId = "%Id"'))->doToken('%Id', $_GET[ADMIN_ACTION_ID])); // Do erase associated PDF file; $objPDF = $this->getProductInfoById($_GET[ADMIN_ACTION_ID], self::$objProductsTableFPDF); if ($objPDF->toLength()->toInt() != 0) { UNLINK(DOCUMENT_ROOT . UPLOAD_DIR . _S . 'products/pdf' . _S . $objPDF); } // Do erase it ... $this->_Q(_QS('doDELETE')->doToken('%table', self::$objProductsTable)->doToken('%condition', new S('%objProductsTableFId = "%Id"'))->doToken('%Id', $_GET[ADMIN_ACTION_ID])); // Do a redirect, and get the user back where he belongs; $this->setHeaderKey($objURLToGoBack, new S('Location')); break; case 'categoryCreate': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(); // Do some work ... if ($this->checkPOST(new S('categories_show_all'))->toBoolean() == TRUE) { // Redirect to proper ... $this->setHeaderKey(URL::rewriteURL(new A(array(ADMIN_SHOW_ALL)), new A(array('1'))), new S('Location')); } if ($this->checkPOST(new S('add_category_submit'))->toBoolean() == TRUE) { // Set some requirements; $objFormHappened = new B(FALSE); $objToCheck = MPTT::mpttAddUnique($this->getPOST(new S('add_category')), new S((string) $_SERVER['REQUEST_TIME'])); if ($objToCheck->toLength()->toInt() == 0) { $this->setErrorOnInput(new S('add_category'), new S(CATEGORY_NAME_CANNOT_BE_EMPTY)); // Set the memory; $objFormHappened->switchType(); } else { if (self::$objMPTT->mpttCheckIfNodeExists($objToCheck)->toBoolean() == TRUE) { // Check to see if the group exists, and tell the user the group exists; $this->setErrorOnInput(new S('add_category'), new S(CATEGORY_ALREADY_EXISTS)); // Set the memory; $objFormHappened->switchType(); } if ($this->checkCategoryURLIsUnique(URL::getURLFromString($objToCheck))->toBoolean() == FALSE) { $this->setErrorOnInput(new S('add_category'), new S(PRODUCTS_CATEGORY_URL_MUST_BE_UNIQUE)); } } // Get AJAX; $this->getAjaxErrors(); if ($objFormHappened->toBoolean() == FALSE) { // Remember if we should add it as a brother or child; $objAddNodeAS = NULL; switch ($this->getPOST(new S('add_category_as_what'))) { case PRODUCTS_CATEGORY_CHILD: $objAddNodeAS = new S((string) MPTT::FIRST_CHILD); break; case PRODUCTS_CATEGORY_LAST_CHILD: $objAddNodeAS = new S((string) MPTT::LAST_CHILD); break; case PRODUCTS_CATEGORY_BROTHER: $objAddNodeAS = new S((string) MPTT::PREVIOUS_BROTHER); break; case PRODUCTS_CATEGORY_NEXT_BROTHER: $objAddNodeAS = new S((string) MPTT::NEXT_BROTHER); break; } // Add the node; self::$objMPTT->mpttAddNode($objToCheck, $this->getPOST(new S('add_category_parent_or_bro')), $objAddNodeAS); } } // Do the form, make it happen; $this->setMethod(new S('POST'))->setFieldset(new S(PRODUCTS_ADD_CATEGORY))->setName($objFormToRender); if ($this->checkPOST(new S('add_category_submit'))->toBoolean() == TRUE) { $this->setRedirect($objURLToGoBack); } $this->setAJAXEnabledForm(new B(FALSE))->setInputType(new S('submit'))->setName(new S('categories_show_all'))->setValue(new S(PRODUCTS_SHOW_ALL_CATEGORIES))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('submit'))->setName(new S('add_category_submit'))->setValue(new S(PRODUCTS_ADD_CATEGORY))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setContainerDiv(new B(TRUE))->setName(new S('add_category'))->setLabel(new S(PRODUCTS_CATEGORY_NAME_LABEL))->setInputType(new S('select'))->setContainerDiv(new B(TRUE))->setName(new S('add_category_as_what'))->setLabel(new S(PRODUCTS_AS_A))->setInputType(new S('option'))->setName(new S('as_first_child'))->setLabel(new S(PRODUCTS_CATEGORY_CHILD))->setInputType(new S('option'))->setName(new S('as_last_child'))->setLabel(new S(PRODUCTS_CATEGORY_LAST_CHILD))->setInputType(new S('option'))->setName(new S('as_previous_brother'))->setLabel(new S(PRODUCTS_CATEGORY_BROTHER))->setInputType(new S('option'))->setName(new S('as_next_brother'))->setLabel(new S(PRODUCTS_CATEGORY_NEXT_BROTHER))->setInputType(new S('select'))->setContainerDiv(new B(TRUE))->setName(new S('add_category_parent_or_bro'))->setLabel(new S(PRODUCTS_OF_CATEGORY)); // Category parent or brother of this one ... foreach ($this->getCategories() as $k => $v) { $this->setInputType(new S('option'))->setName($v[self::$objMPTT->objNameOfNode])->setValue($v[self::$objMPTT->objNameOfNode])->setLabel(new S(str_repeat('--' . _SP, (int) $v['depth']->toString()) . MPTT::mpttRemoveUnique(clone $v[self::$objMPTT->objNameOfNode]))); } // Continue, execute the form ... $this->setFormEndAndExecute(new B(TRUE)); break; case 'categoryEdit': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION, ADMIN_ACTION_ID))); $objFormHappened = new B(FALSE); // Do validation and error on it if something goes wrong; if ($this->checkPOST()->toBoolean() == TRUE) { // Set some requirements; $objFormHappened = new B(FALSE); $objToCheck = MPTT::mpttAddUnique($this->getPOST(self::$objCategoryTableFName), $this->getCategoryInfoById($_GET[ADMIN_ACTION_ID], self::$objCategoryTableFDate)); if ($objToCheck->toLength()->toInt() == 0) { // Check for empty group name, and error on it. We don't allow empty group names; $this->setErrorOnInput(self::$objCategoryTableFName, new S(PRODUCTS_CATEGORY_NAME_EMPTY)); // Set the memory; $objFormHappened->switchType(); } else { if ($this->getCategoryInfoById($_GET[ADMIN_ACTION_ID], self::$objCategoryTableFName) != $objToCheck) { if (self::$objMPTT->mpttCheckIfNodeExists($objToCheck)->toBoolean() == TRUE) { // Check to see if the group exists; $this->setErrorOnInput(self::$objCategoryTableFName, new S(PRODUCTS_CATEGORY_ALREADY_EXISTS)); // Set the memory; $objFormHappened->switchType(); } } } // Get AJAX; $this->getAjaxErrors(); } // Do the form, make it happen; $this->setMethod(new S('POST'))->setSQLAction(new S('update'))->setTableName(self::$objCategoryTable)->setUpdateId($_GET[ADMIN_ACTION_ID])->setUpdateField(self::$objCategoryTableFId)->setFieldset(new S(PRODUCTS_EDIT_CATEGORY)); if ($this->checkPOST(self::$objCategoryTableFName)->toBoolean() == TRUE) { $this->setExtraUpdateData(self::$objCategoryTableFSEO, URL::getURLFromString($this->getPOST(self::$objCategoryTableFName))); } if ($objFormHappened->toBoolean() == FALSE && $this->checkPOST()->toBoolean() == TRUE) { $this->setRedirect($objURLToGoBack); } $this->setName($objFormToRender)->setAJAXEnabledForm(new B(FALSE))->setInputType(new S('submit'))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setName(new S('edit_category_submit'))->setValue(new S(PRODUCTS_EDIT_CATEGORY))->setInputType(new S('text'))->setName(self::$objCategoryTableFName)->setMPTTRemoveUnique(new B(TRUE))->setLabel(new S(PRODUCTS_NAME))->setJSRegExpReplace(new S('[^a-zA-Z0-9 -]'))->setContainerDiv(new B(TRUE))->setInputType(new S('textarea'))->setName(self::$objCategoryTableFDescription)->setLabel(new S(PRODUCTS_DECRIPTION))->setTinyMCETextarea(new B(TRUE))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; case 'categoryErase': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION, ADMIN_ACTION_ID))); // Memorize if it has kids ... $objNodeHasKids = new B(FALSE); // Check if the category has articles; if ($this->getProductCount(_S('WHERE %objProductsTableFCategoryId = "%Id"')->doToken('%Id', $_GET[ADMIN_ACTION_ID]))->toInt() != 0) { // Set an error message; self::$objAdministration->setErrorMessage(new S(PRODUCTS_CANNOT_DELETE_CATEGORY), $objURLToGoBack); } else { // Do erase the group node from the table; self::$objMPTT->mpttRemoveNode($this->getCategoryInfoById($_GET[ADMIN_ACTION_ID], self::$objCategoryTableFName)); // Do a redirect, and get the user back where he belongs; $this->setHeaderKey($objURLToGoBack, new S('Location')); } // Break out ... break; case 'categoryMove': // Set some predefines; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION, ADMIN_ACTION_TO, ADMIN_ACTION_TYPE))); // Get names, as they are unique; $objThatIsMoved = $this->getCategoryInfoById($_GET[ADMIN_ACTION_ID], self::$objCategoryTableFName); $objWhereToMove = $this->getCategoryInfoById($_GET[ADMIN_ACTION_TO], self::$objCategoryTableFName); // Get the node subtree, that's move, make sure the node we move to ain't a child; $objMovedNodeSubTree = self::$objMPTT->mpttGetTree($objThatIsMoved); // Memorize; $objIsChild = new B(FALSE); foreach ($objMovedNodeSubTree as $k => $v) { if ($v[self::$objMPTT->objNameOfNode] == $objWhereToMove) { $objIsChild->switchType(); } } // Check if it's a child or not; if ($objIsChild->toBoolean() == TRUE) { // Set an error message; self::$objAdministration->setErrorMessage(new S(PRODUCTS_CATEGORY_CANNOT_BE_MOVED), $objURLToGoBack); } else { // Move nodes; self::$objMPTT->mpttMoveNode($objThatIsMoved, $objWhereToMove, $_GET[ADMIN_ACTION_TYPE]); $this->setHeaderKey($objURLToGoBack, new S('Location')); } // Break out ... break; case 'categoryMoveOperation': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_SUBPAGE)), new A(array(MANAGE_PRODUCTS))); // Do some work; $this->checkPOST()->toBoolean() == TRUE ? $objOLDCategoryId = $this->getPOST(new S('old_category_id')) : ($objOLDCategoryId = new S('0')); // Do the form, make it happen; $this->setMethod(new S('POST'))->setFieldset(new S(PRODUCTS_MOVE_PRODUCTS))->setSQLAction(new S('update'))->setTableName(self::$objProductsTable)->setUpdateField(self::$objProductsTableFId)->setUpdateWhere($this->doModuleToken(_S('%objProductsTableFCategoryId = "%Id"')->doToken('%Id', $objOLDCategoryId)))->setName($objFormToRender)->setRedirect($objURLToGoBack)->setInputType(new S('submit'))->setValue(new S(PRODUCTS_MOVE_PRODUCTS))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('select'))->setName(new S('old_category_id'))->setLabel(new S(PRODUCTS_OLD_CATEGORY))->setContainerDiv(new B(TRUE)); // Cateories; foreach ($this->getCategories() as $k => $v) { $this->setInputType(new S('option'))->setName($v[self::$objMPTT->objIdField])->setValue($v[self::$objMPTT->objIdField])->setLabel(new S(str_repeat('--' . _SP, (int) $v['depth']->toString()) . MPTT::mpttRemoveUnique($v[self::$objMPTT->objNameOfNode]))); } // Categories; $this->setInputType(new S('select'))->setName(self::$objProductsTableFCategoryId)->setLabel(new S(PRODUCTS_NEW_CATEGORY))->setContainerDiv(new B(TRUE)); foreach ($this->getCategories() as $k => $v) { $this->setInputType(new S('option'))->setName($v[self::$objMPTT->objIdField])->setValue($v[self::$objMPTT->objIdField])->setLabel(new S(str_repeat('--' . _SP, (int) $v['depth']->toString()) . MPTT::mpttRemoveUnique($v[self::$objMPTT->objNameOfNode]))); } // Continue; $this->setFormEndAndExecute(new B(TRUE)); break; case 'configurationEdit': // Do some work; if ($this->checkPOST()->toBoolean() == TRUE) { $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION)), new A(array($this->getPOST(new S('what'))))); } // Do the form, make it happen; $this->setMethod(new S('POST'))->setFieldset(new S(PRODUCTS_MANAGE_CONFIGURATION))->setName($objFormToRender); // Set redirect; if ($this->checkPOST()->toBoolean() == TRUE) { $this->setRedirect($objURLToGoBack); } // Continue; $this->setInputType(new S('submit'))->setValue(new S(ADMIN_ACTION))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('select'))->setName(new S('what'))->setLabel(new S(PRODUCTS_CONFIG_CHOOSE))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; } }
/** * Will render a specified form, the name of the form given by the first parameter; * * This method will render one of the forms for our object, invoked by giving the proper form identifier to the current form. * We have chosen this method of invoking forms, because we just had too many this->renderSomethingMethod (), which really had * an impact on code massiveness. Also, having code organized in switch/case statements leads us to be able to share common * settings between different forms, as we've done with the methods defined in the __CALL method above; * * For example, if we wanted to share some common configuration between a create and an edit form, we could have introduced * two switches in this method, one that would have set the common options, and the second, would have just passed through * again, and get the already set configuration options, using them. This means that if we needed to change behavior of * some interconnected forms, that would mean modifying the needed code one place only, which is a big advantage over * having separated methods for each form. Maybe if we extended this object, you guys could understand the functionality; * * @param string $objFormToRender The name of the form to render; * @return mixed Depends on the rendered form if it returns something or not; */ public function renderForm(S $objFormToRender, A $objFA = NULL) { // Make them defaults ... if ($objFA == NULL) { $objFA = new A(); } // Do a switch ... switch ($objFormToRender) { case 'uploadForm': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(AUDIO_STATUS_URL)), new A(array(AUDIO_STATUS_OK_URL))); // Do some work ... if ($this->checkPOST(self::$objAudioTableFTitle)->toBoolean() == TRUE) { // Check non empty ... if ($this->getPOST(self::$objAudioTableFTitle)->toLength()->toInt() == 0) { $this->setErrorOnInput(self::$objAudioTableFTitle, new S($objFA['error_title_empty'])); } } if ($this->checkPOST(self::$objAudioTableFArtist)->toBoolean() == TRUE) { // Check non empty ... if ($this->getPOST(self::$objAudioTableFArtist)->toLength()->toInt() == 0) { $this->setErrorOnInput(self::$objAudioTableFArtist, new S($objFA['error_artist_empty'])); } } if ($this->checkPOST(self::$objAudioTableFAlbum)->toBoolean() == TRUE) { // Check non empty ... if ($this->getPOST(self::$objAudioTableFAlbum)->toLength()->toInt() == 0) { $this->setErrorOnInput(self::$objAudioTableFAlbum, new S($objFA['error_album_empty'])); } } // Check & Get; $this->getAjaxErrors(); // Do the form, make it happen; $this->setMethod(new S('POST'))->setEnctype(new S('multipart/form-data'))->setFieldset(new S($objFA['upload_audio_file']))->setSQLAction(new S('update'))->setTableName(self::$objAudioTable)->setUpdateId(new S('#nextTableAutoIncrement'))->setUpdateField(self::$objAudioTableFId)->setExtraUpdateData(self::$objAudioTableFUploadedDate, new S((string) $_SERVER['REQUEST_TIME']))->setExtraUpdateData(self::$objAudioTableFUploaderId, $this->ATH->getCurrentUserInfoById(Authentication::$objAuthUsersTableFId))->setExtraUpdateData(self::$objAudioTableFApproved, new S('N'))->setUploadDirectory(new S('audio/mp3/' . date('Y/m/d', $_SERVER['REQUEST_TIME'])))->setUploadImageResize(new A(array(128 => 128, 640 => 480, 800 => 600))); // Add the URL ... if ($this->checkPOST(self::$objAudioTableFTitle)->toBoolean() == TRUE && $this->checkPOST(self::$objAudioTableFArtist)->toBoolean() == TRUE) { // CLONE them little monkeys ... $objURL = clone $this->getPOST(self::$objAudioTableFTitle); $objART = clone $this->getPOST(self::$objAudioTableFArtist); // CONCAT'enate them ... $this->setExtraUpdateData(self::$objAudioTableFSEO, URL::getURLFromString($objURL->appendString(_U)->appendString($objART)->appendString(_U)->appendString((string) $_SERVER['REQUEST_TIME']))); } // Continue ... $this->setName($objFormToRender)->setRedirect($objURLToGoBack)->setAJAXEnabledForm(new B(FALSE))->setInputType(new S('submit'))->setValue(new S($objFA['upload_audio_file']))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objAudioTableFTitle)->setLabel(new S($objFA['audio_file_title']))->setContainerDiv(new B(TRUE))->setInputType(new S('select'))->setName(self::$objAudioTableFCategoryId)->setLabel(new S($objFA['audio_file_category']))->setContainerDiv(new B(TRUE)); // Categories ... foreach ($this->getCategories() as $k => $v) { $this->setInputType(new S('option'))->setName($v[self::$objMPTT->objIdField])->setValue($v[self::$objMPTT->objIdField])->setLabel(new S(str_repeat('--' . _SP, (int) $v['depth']->toString()) . MPTT::mpttRemoveUnique($v[self::$objMPTT->objNameOfNode]))); } // Continue ... $this->setInputType(new S('text'))->setName(self::$objAudioTableFArtist)->setLabel(new S($objFA['audio_file_artist']))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objAudioTableFAlbum)->setLabel(new S($objFA['audio_file_album']))->setContainerDiv(new B(TRUE))->setInputType(new S('file'))->setName(self::$objAudioTableFFile)->setLabel(new S($objFA['audio_file_file']))->setContainerDiv(new B(TRUE))->setInputType(new S('file'))->setName(self::$objAudioTableFArtwork)->setLabel(new S($objFA['audio_file_artwork']))->setContainerDiv(new B(TRUE))->setInputType(new S('textarea'))->setName(self::$objAudioTableFLyrics)->setLabel(new S($objFA['audio_file_lyrics']))->setTinyMCETextarea(new B(TRUE))->setClass(new S('tinyMCESimple'))->setContainerDiv(new B(TRUE))->setInputType(new S('textarea'))->setName(self::$objAudioTableFDescription)->setLabel(new S($objFA['audio_file_description']))->setTinyMCETextarea(new B(TRUE))->setClass(new S('tinyMCESimple'))->setContainerDiv(new B(TRUE)); // Notify ... if ($this->checkFormHasErrors()->toBoolean() == FALSE) { // Go ... $objMAIL = new MAIL(); $objMAIL->doMAIL($this->STG->getConfigKey(new S('settings_website_notification_email')), new S(AUDIO_FRONT_FILE_HAS_BEEN_UPLOADED), $this->getHELP(new S('uploadFormEMLMessage'))->doToken('%t', $this->getPOST(self::$objAudioTableFTitle))->doToken('%a', $this->getPOST(self::$objAudioTableFArtist))->doToken('%b', $this->getPOST(self::$objAudioTableFAlbum))->doToken('%u', $this->ATH->getCurrentUserInfoById(Authentication::$objAuthUsersTableFUName))); } // End form and execute ... $this->setFormEndAndExecute(new B(TRUE)); break; case 'audioSearchOnFrontend': // Do the form, make it happen ... $this->setMethod(new S('POST'))->setName($objFormToRender); // Do some work ... if ($this->checkPOST(new S('search'))->toBoolean() == TRUE) { // Get the title, and check it's name ... if ($this->getPOST(new S('audio_file_title'))->toLength()->toInt() == 0) { // Well, sadly, we have an issue ... $this->setErrorOnInput(new S('audio_file_title'), new S($objFA['error_empty_search'])); } else { // Notify ... $objMAIL = new MAIL(); $objMAIL->doMAIL($this->STG->getConfigKey(new S('settings_website_notification_email')), new S(AUDIO_SEARCH_HAS_BEEN_PERFORMED), $this->getHELP(new S('audioSearchOnFrontend'))->doToken('%s', $this->getPOST(new S('audio_file_title')))); // Go ... $this->setHeaderKey($objURLToGoBack = URL::staticURL(new A(array(FRONTEND_SECTION_URL, AUDIO_SEARCH_URL)), new A(array(FRONTEND_AUDIO_URL, $this->getPOST(new S('audio_file_title'))->entityDecode(ENT_QUOTES)->stripSlashes()))), new S('Location')); } } // Continue ... $this->setInputType(new S('submit'))->setName(new S('search'))->setValue(new S($objFA['search_submit']))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(new S('audio_file_title')); // If it's set ... add the VALUE ... if (isset($_GET[AUDIO_SEARCH_URL])) { $this->setValue($_GET[AUDIO_SEARCH_URL]); } // Continue ... $this->setLabel(new S($objFA['search_title']))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; case 'audioSearch': // Get some predefines; if (isset($_GET[ADMIN_ACTION_BY])) { $objSearchBy = $_GET[ADMIN_ACTION_BY]; } else { $objSearchBy = new S(); } if (isset($_GET[ADMIN_ACTION_SEARCH])) { $objSearchWas = $_GET[ADMIN_ACTION_SEARCH]; } else { $objSearchWas = new S(); } // Do some work; if ($this->checkPOST(new S('search_submit'))->toBoolean() == TRUE) { if ($this->getPOST(new S('search_by'))->toLength()->toInt() == 0) { if (isset($_GET[ADMIN_ACTION_SEARCH])) { // Erase search terms ... $this->setHeaderKey(URL::rewriteURL(new A(array(ADMIN_ACTION_SEARCH, ADMIN_ACTION_BY))), new S('Location')); } // Set an input error; $this->setErrorOnInput(new S('search_by'), new S(AUDIO_SEARCH_FIELD_IS_EMPTY)); // Unset the post ... $this->unsetPOST(); } else { // Get what to search and where ... $objWhatToSearch = $this->getPOST(new S('search_by')); $objWhereToSearch = $this->getPOST(new S('search_field')); // And go there ... $this->setHeaderKey(URL::rewriteURL(new A(array(ADMIN_ACTION_SEARCH, ADMIN_ACTION_BY)), new A(array($objWhatToSearch, $objWhereToSearch))), new S('Location')); } } // Check the option that has been selected; $objWasSelected = new A(array(new B($objSearchBy == AUDIO_SEARCH_TITLE ? TRUE : FALSE), new B($objSearchBy == AUDIO_SEARCH_ARTIST ? TRUE : FALSE), new B($objSearchBy == AUDIO_SEARCH_ALBUM ? TRUE : FALSE))); // Do the form, make it happen; $this->setMethod(new S('POST'))->setEnctype(new S('multipart/form-data'))->setFieldset(new S(AUDIO_SEARCH_BY))->setName($objFormToRender)->setInputType(new S('text'))->setInputInfoMessage($this->getHELP($objFormToRender))->setName(new S('search_by'))->setvalue($objSearchWas)->setLabel(new S(AUDIO_SEARCH_BY))->setJSRegExpReplace(new S('[^a-zA-Z0-9 -]'))->setContainerDiv(new B(TRUE))->setInputType(new S('select'))->setName(new S('search_field'))->setContainerDiv(new B(TRUE))->setLabel(new S(AUDIO_SEARCH_IN))->setInputType(new S('option'))->setName(new S('article_title'))->setValue(new S(AUDIO_SEARCH_TITLE))->setLabel(new S(AUDIO_SEARCH_TITLE))->setSelected($objWasSelected[0])->setInputType(new S('option'))->setName(new S('article_content'))->setValue(new S(AUDIO_SEARCH_ARTIST))->setLabel(new S(AUDIO_SEARCH_ARTIST))->setSelected($objWasSelected[1])->setInputType(new S('option'))->setName(new S('article_category'))->setValue(new S(AUDIO_SEARCH_ALBUM))->setLabel(new S(AUDIO_SEARCH_ALBUM))->setSelected($objWasSelected[2])->setInputType(new S('submit'))->setContainerDiv(new B(TRUE))->setValue(new S(AUDIO_SEARCH_BY))->setName(new S('search_submit'))->setFormEndAndExecute(new B(TRUE)); break; case 'audioCreate': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(); $objUPDirectory = date('Y/m/d', $_SERVER['REQUEST_TIME']); // Do some work ... if ($this->checkPOST(self::$objAudioTableFTitle)->toBoolean() == TRUE) { // Check non empty ... if ($this->getPOST(self::$objAudioTableFTitle)->toLength()->toInt() == 0) { $this->setErrorOnInput(self::$objAudioTableFTitle, new S(AUDIO_TITLE_REQUIRED)); } } if ($this->checkPOST(self::$objAudioTableFArtist)->toBoolean() == TRUE) { // Check non empty ... if ($this->getPOST(self::$objAudioTableFArtist)->toLength()->toInt() == 0) { $this->setErrorOnInput(self::$objAudioTableFArtist, new S(AUDIO_ARTIST_REQUIRED)); } } if ($this->checkPOST(self::$objAudioTableFAlbum)->toBoolean() == TRUE) { // Check non empty ... if ($this->getPOST(self::$objAudioTableFAlbum)->toLength()->toInt() == 0) { $this->setErrorOnInput(self::$objAudioTableFAlbum, new S(AUDIO_ALBUM_REQUIRED)); } } // Check & Get; $this->getAjaxErrors(); // Do the form, make it happen; $this->setMethod(new S('POST'))->setEnctype(new S('multipart/form-data'))->setFieldset(new S(AUDIO_ADD_AUDIO))->setSQLAction(new S('update'))->setTableName(self::$objAudioTable)->setUpdateId(new S('#nextTableAutoIncrement'))->setUpdateField(self::$objAudioTableFId)->setExtraUpdateData(self::$objAudioTableFUploaderId, $this->ATH->getCurrentUserInfoById(Authentication::$objAuthUsersTableFId))->setUploadDirectory(new S('audio/mp3/' . $objUPDirectory))->setUploadImageResize(new A(array(128 => 128, 640 => 480, 800 => 600))); // Add the URL ... if ($this->checkPOST(self::$objAudioTableFTitle)->toBoolean() == TRUE && $this->checkPOST(self::$objAudioTableFArtist)->toBoolean() == TRUE) { // CLONE them little monkeys ... $objURL = clone $this->getPOST(self::$objAudioTableFTitle); $objART = clone $this->getPOST(self::$objAudioTableFArtist); // CONCAT'enate them ... $this->setExtraUpdateData(self::$objAudioTableFSEO, URL::getURLFromString($objURL->appendString(_U)->appendString($objART)->appendString(_U)->appendString((string) $_SERVER['REQUEST_TIME']))); } // Continue ... $this->setName($objFormToRender); if ($this->checkPOST(self::$objAudioTableFTitle)->toBoolean() == TRUE) { $this->setRedirect($objURLToGoBack); } $this->setAJAXEnabledForm(new B(FALSE))->setInputType(new S('submit'))->setValue(new S(AUDIO_ADD_AUDIO))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('select'))->setName(self::$objAudioTableFApproved)->setLabel(new S(AUDIO_FILE_APPROVED))->setContainerDiv(new B(TRUE))->setInputType(new S('option'))->setName(new S('yes'))->setValue(new S('Y'))->setLabel(new S(AUDIO_FILE_APPROVED_YES))->setInputType(new S('option'))->setName(new S('no'))->setValue(new S('N'))->setLabel(new S(AUDIO_FILE_APPROVED_NO))->setInputType(new S('select'))->setName(self::$objAudioTableFCanComment)->setLabel(new S(AUDIO_CAN_COMMENT))->setContainerDiv(new B(TRUE))->setInputType(new S('option'))->setName(new S('no'))->setValue(new S('N'))->setLabel(new S(AUDIO_CAN_COMMENT_NO))->setInputType(new S('option'))->setName(new S('yes'))->setValue(new S('Y'))->setLabel(new S(AUDIO_CAN_COMMENT_YES))->setInputType(new S('text'))->setName(self::$objAudioTableFTitle)->setLabel(new S(AUDIO_FILE_TITLE))->setContainerDiv(new B(TRUE))->setInputType(new S('select'))->setName(self::$objAudioTableFCategoryId)->setLabel(new S(AUDIO_FILE_CATEGORY))->setContainerDiv(new B(TRUE)); // Categories ... foreach ($this->getCategories() as $k => $v) { $this->setInputType(new S('option'))->setName($v[self::$objMPTT->objIdField])->setValue($v[self::$objMPTT->objIdField])->setLabel(new S(str_repeat('--' . _SP, (int) $v['depth']->toString()) . MPTT::mpttRemoveUnique($v[self::$objMPTT->objNameOfNode]))); } // Continue ... $this->setInputType(new S('file'))->setName(self::$objAudioTableFFile)->setLabel(new S(AUDIO_FILE))->setContainerDiv(new B(TRUE))->setInputType(new S('file'))->setName(self::$objAudioTableFArtwork)->setLabel(new S(AUDIO_FILE_ARTWORK))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objAudioTableFArtist)->setLabel(new S(AUDIO_FILE_ARTIST))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objAudioTableFAlbum)->setLabel(new S(AUDIO_FILE_ALBUM))->setContainerDiv(new B(TRUE))->setInputType(new S('textarea'))->setName(self::$objAudioTableFLyrics)->setLabel(new S(AUDIO_FILE_LYRICS))->setTinyMCETextarea(new B(TRUE))->setContainerDiv(new B(TRUE))->setInputType(new S('textarea'))->setName(self::$objAudioTableFDescription)->setLabel(new S(AUDIO_FILE_DESCRIPTION))->setTinyMCETextarea(new B(TRUE))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; case 'audioEdit': // God send us our info ... $tpF = new FilePath($this->getPathToSkin()->toRelativePath() . 'audioEditInfo.tp'); TPL::tpSet($this, new S('AUD'), $tpF); TPL::tpExe($tpF); // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION, ADMIN_ACTION_ID))); $objUPDirectory = date('Y/m/d', (int) $this->getAudioFileInfoById($_GET[ADMIN_ACTION_ID], self::$objAudioTableFUploadedDate)->toString()); // Check & Get; $this->getAjaxErrors(); // Do the form, make it happen; $this->setMethod(new S('POST'))->setEnctype(new S('multipart/form-data'))->setFieldset(new S(AUDIO_EDIT_AUDIO))->setSQLAction(new S('update'))->setTableName(self::$objAudioTable)->setUpdateId($_GET[ADMIN_ACTION_ID])->setUpdateField(self::$objAudioTableFId)->setUploadDirectory(new S('audio/mp3/' . $objUPDirectory))->setUploadImageResize(new A(array(128 => 128, 640 => 480, 800 => 600))); // Add the URL ... if ($this->checkPOST(self::$objAudioTableFTitle)->toBoolean() == TRUE && $this->checkPOST(self::$objAudioTableFArtist)->toBoolean() == TRUE) { // CLONE them little monkeys ... $objURL = clone $this->getPOST(self::$objAudioTableFTitle); $objART = clone $this->getPOST(self::$objAudioTableFArtist); // CONCAT'enate them ... $this->setExtraUpdateData(self::$objAudioTableFSEO, URL::getURLFromString($objURL->appendString(_U)->appendString($objART)->appendString(_U)->appendString($this->getAudioFileInfoById($_GET[ADMIN_ACTION_ID], self::$objAudioTableFUploadedDate)))); } // Continue ... $this->setName($objFormToRender)->setRedirect($objURLToGoBack)->setAJAXEnabledForm(new B(FALSE))->setInputType(new S('submit'))->setValue(new S(AUDIO_EDIT_AUDIO))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('select'))->setName(self::$objAudioTableFApproved)->setLabel(new S(AUDIO_FILE_APPROVED))->setContainerDiv(new B(TRUE))->setInputType(new S('option'))->setName(new S('yes'))->setValue(new S('Y'))->setLabel(new S(AUDIO_FILE_APPROVED_YES))->setInputType(new S('option'))->setName(new S('no'))->setValue(new S('N'))->setLabel(new S(AUDIO_FILE_APPROVED_NO))->setInputType(new S('select'))->setName(self::$objAudioTableFCanComment)->setLabel(new S(AUDIO_CAN_COMMENT))->setContainerDiv(new B(TRUE))->setInputType(new S('option'))->setName(new S('no'))->setValue(new S('N'))->setLabel(new S(AUDIO_CAN_COMMENT_NO))->setInputType(new S('option'))->setName(new S('yes'))->setValue(new S('Y'))->setLabel(new S(AUDIO_CAN_COMMENT_YES))->setInputType(new S('text'))->setName(self::$objAudioTableFTitle)->setLabel(new S(AUDIO_FILE_TITLE))->setContainerDiv(new B(TRUE))->setInputType(new S('select'))->setName(self::$objAudioTableFCategoryId)->setLabel(new S(AUDIO_FILE_CATEGORY))->setContainerDiv(new B(TRUE)); // Categories ... foreach ($this->getCategories() as $k => $v) { $this->setInputType(new S('option'))->setName($v[self::$objMPTT->objIdField])->setValue($v[self::$objMPTT->objIdField])->setLabel(new S(str_repeat('--' . _SP, (int) $v['depth']->toString()) . MPTT::mpttRemoveUnique($v[self::$objMPTT->objNameOfNode]))); } // Continue ... $this->setInputType(new S('file'))->setName(self::$objAudioTableFFile)->setLabel(new S(AUDIO_FILE))->setFileController(new B(TRUE))->setContainerDiv(new B(TRUE))->setInputType(new S('file'))->setName(self::$objAudioTableFArtwork)->setLabel(new S(AUDIO_FILE_ARTWORK))->setFileController(new B(TRUE))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objAudioTableFArtist)->setLabel(new S(AUDIO_FILE_ARTIST))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objAudioTableFAlbum)->setLabel(new S(AUDIO_FILE_ALBUM))->setContainerDiv(new B(TRUE))->setInputType(new S('textarea'))->setName(self::$objAudioTableFLyrics)->setLabel(new S(AUDIO_FILE_LYRICS))->setTinyMCETextarea(new B(TRUE))->setContainerDiv(new B(TRUE))->setInputType(new S('textarea'))->setName(self::$objAudioTableFDescription)->setLabel(new S(AUDIO_FILE_DESCRIPTION))->setTinyMCETextarea(new B(TRUE))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; case 'audioErase': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION, ADMIN_ACTION_ID))); $objUPDirectory = date('Y/m/d/', (int) $this->getAudioFileInfoById($_GET[ADMIN_ACTION_ID], self::$objAudioTableFUploadedDate)->toString()); if ($this->getCommentCount(_S('WHERE %objCommentsTableFAudioFileId = "%Id"')->doToken('%Id', $_GET[ADMIN_ACTION_ID]))->toInt() != 0) { self::$objAdministration->setErrorMessage(new S(AUDIO_HAS_COMMENTS), $objURLToGoBack); } else { // Remove them files ... $objPath = new FilePath('upd/audio/mp3/' . $objUPDirectory); // First: check to see if file is there ... $objArtF = $this->getAudioFileInfoById($_GET[ADMIN_ACTION_ID], self::$objAudioTableFFile); // Go ... if ($objArtF->toLength()->toInt() != 0) { // Kill'em ALL ... UNLINK($objPath . $objArtF); } // Second: check to see if artwork is there ... $objArtF = $this->getAudioFileInfoById($_GET[ADMIN_ACTION_ID], self::$objAudioTableFArtwork); // Go ... if ($objArtF->toLength()->toInt() != 0) { // Kill'em ALL ... UNLINK($objPath . '' . $objArtF); UNLINK($objPath . '128_128_' . $objArtF); UNLINK($objPath . '640_480_' . $objArtF); UNLINK($objPath . '800_600_' . $objArtF); } // Do erase it ... $this->_Q(_QS('doDELETE')->doToken('%table', self::$objAudioTable)->doToken('%condition', new S('%objAudioTableFId = "%Id"'))->doToken('%Id', $_GET[ADMIN_ACTION_ID])); // Do a redirect, and get the user back where he belongs; $this->setHeaderKey($objURLToGoBack, new S('Location')); } // BK; break; case 'commentEdit': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION, ADMIN_ACTION_ID))); // Do the form, make it happen; $this->setMethod(new S('POST'))->setFieldset(new S(AUDIO_EDIT_COMMENT))->setAJAXEnabledForm(new B(FALSE))->setRedirect($objURLToGoBack)->setSQLAction(new S('update'))->setTableName(self::$objCommentsTable)->setUpdateId($_GET[ADMIN_ACTION_ID])->setUpdateField(self::$objCommentsTableFId)->setName($objFormToRender)->setInputType(new S('submit'))->setValue(new S(AUDIO_EDIT_COMMENT))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('select'))->setName(self::$objCommentsTableFApproved)->setLabel(new S(AUDIO_COMMENT_APPROVED))->setContainerDiv(new B(TRUE))->setInputType(new S('option'))->setName(new S('no'))->setValue(new S('N'))->setLabel(new S(AUDIO_CAN_COMMENT_NO))->setInputType(new S('option'))->setName(new S('yes'))->setValue(new S('Y'))->setLabel(new S(AUDIO_CAN_COMMENT_YES))->setInputType(new S('textarea'))->setName(self::$objCommentsTableFComment)->setLabel(new S(AUDIO_COMMENT))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; case 'commentErase': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION, ADMIN_ACTION_ID))); // Do erase it ... $this->_Q(_QS('doDELETE')->doToken('%table', self::$objCommentsTable)->doToken('%condition', new S('%objCommentsTableFId = "%Id"'))->doToken('%Id', $_GET[ADMIN_ACTION_ID])); // Do a redirect, and get the user back where he belongs; $this->setHeaderKey($objURLToGoBack, new S('Location')); break; case 'categoryCreate': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(); // Do some work; if ($this->checkPOST(new S('categories_show_all'))->toBoolean() == TRUE) { // Redirect to proper ... $this->setHeaderKey(URL::rewriteURL(new A(array(ADMIN_SHOW_ALL)), new A(array('1'))), new S('Location')); } if ($this->checkPOST(new S('add_category_submit'))->toBoolean() == TRUE) { // Set some requirements; $objFormHappened = new B(FALSE); $objToCheck = MPTT::mpttAddUnique($this->getPOST(new S('add_category')), new S((string) $_SERVER['REQUEST_TIME'])); if ($objToCheck->toLength()->toInt() == 0) { $this->setErrorOnInput(new S('add_category'), new S(AUDIO_CATEGORY_NAME_IS_EMPTY)); // Set the memory; $objFormHappened->switchType(); } else { if (self::$objMPTT->mpttCheckIfNodeExists($objToCheck)->toBoolean() == TRUE) { // Check to see if the group exists, and tell the user the group exists; $this->setErrorOnInput(new S('add_category'), new S(AUDIO_CATEGORY_ALREADY_EXISTS)); // Set the memory; $objFormHappened->switchType(); } if ($this->checkCategoryURLIsUnique(URL::getURLFromString($objToCheck))->toBoolean() == FALSE) { $this->setErrorOnInput(new S('add_category'), new S(AUDIO_CATEGORY_URL_MUST_BE_UNIQUE)); } } // Get AJAX; $this->getAjaxErrors(); if ($objFormHappened->toBoolean() == FALSE) { // Remember if we should add it as a brother or child; $objAddNodeAS = NULL; switch ($this->getPOST(new S('add_category_as_what'))) { case AUDIO_CATEGORY_CHILD: $objAddNodeAS = new S((string) MPTT::FIRST_CHILD); break; case AUDIO_CATEGORY_LAST_CHILD: $objAddNodeAS = new S((string) MPTT::LAST_CHILD); break; case AUDIO_CATEGORY_BROTHER: $objAddNodeAS = new S((string) MPTT::PREVIOUS_BROTHER); break; case AUDIO_CATEGORY_NEXT_BROTHER: $objAddNodeAS = new S((string) MPTT::NEXT_BROTHER); break; } // Add the node; self::$objMPTT->mpttAddNode($objToCheck, $this->getPOST(new S('add_category_parent_or_bro')), $objAddNodeAS); } } // Do the form, make it happen; $this->setMethod(new S('POST'))->setFieldset(new S(AUDIO_ADD_CATEGORY))->setName($objFormToRender); if ($this->checkPOST(new S('add_category_submit'))->toBoolean() == TRUE) { $this->setRedirect($objURLToGoBack); } $this->setAJAXEnabledForm(new B(FALSE))->setInputType(new S('submit'))->setName(new S('categories_show_all'))->setValue(new S(AUDIO_SHOW_ALL_CATEGORIES))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('submit'))->setName(new S('add_category_submit'))->setValue(new S(AUDIO_ADD_CATEGORY))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setJSRegExpReplace(new S('[^a-zA-Z0-9 ,.!?;&-]'))->setContainerDiv(new B(TRUE))->setName(new S('add_category'))->setLabel(new S(AUDIO_CATEGORY_NAME_LABEL))->setInputType(new S('select'))->setContainerDiv(new B(TRUE))->setName(new S('add_category_as_what'))->setLabel(new S(AUDIO_AS_A))->setInputType(new S('option'))->setName(new S('as_first_child'))->setLabel(new S(AUDIO_CATEGORY_CHILD))->setInputType(new S('option'))->setName(new S('as_last_child'))->setLabel(new S(AUDIO_CATEGORY_LAST_CHILD))->setInputType(new S('option'))->setName(new S('as_previous_brother'))->setLabel(new S(AUDIO_CATEGORY_BROTHER))->setInputType(new S('option'))->setName(new S('as_next_brother'))->setLabel(new S(AUDIO_CATEGORY_NEXT_BROTHER))->setInputType(new S('select'))->setContainerDiv(new B(TRUE))->setName(new S('add_category_parent_or_bro'))->setLabel(new S(AUDIO_OF_CATEGORY)); // Category parent or brother of this one ... foreach ($this->getCategories() as $k => $v) { $this->setInputType(new S('option'))->setName($v[self::$objMPTT->objNameOfNode])->setValue($v[self::$objMPTT->objNameOfNode])->setLabel(new S(str_repeat('--' . _SP, (int) $v['depth']->toString()) . MPTT::mpttRemoveUnique(clone $v[self::$objMPTT->objNameOfNode]))); } // Continue, execute the form ... $this->setFormEndAndExecute(new B(TRUE)); break; case 'categoryEdit': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION, ADMIN_ACTION_ID))); // Do validation and error on it if something goes wrong; if ($this->checkPOST()->toBoolean() == TRUE) { // Set some requirements; $objFormHappened = new B(FALSE); $objToCheck = MPTT::mpttAddUnique($this->getPOST(self::$objCategoryTableFName), $this->getCategoryInfoById($_GET[ADMIN_ACTION_ID], self::$objCategoryTableFDate)); if ($objToCheck->toLength()->toInt() == 0) { // Check for empty group name, and error on it. We don't allow empty group names; $this->setErrorOnInput(self::$objCategoryTableFName, new S(AUDIO_CATEGORY_NAME_IS_EMPTY)); // Set the memory; $objFormHappened->switchType(); } else { if ($this->getCategoryInfoById($_GET[ADMIN_ACTION_ID], self::$objCategoryTableFName) != $objToCheck) { if (self::$objMPTT->mpttCheckIfNodeExists($objToCheck)->toBoolean() == TRUE) { // Check to see if the group exists; $this->setErrorOnInput(self::$objCategoryTableFName, new S(AUDIO_CATEGORY_ALREADY_EXISTS)); // Set the memory; $objFormHappened->switchType(); } } } // Get AJAX; $this->getAjaxErrors(); } // Do the form, make it happen; $this->setMethod(new S('POST'))->setSQLAction(new S('update'))->setTableName(self::$objCategoryTable)->setUpdateId($_GET[ADMIN_ACTION_ID])->setUpdateField(self::$objCategoryTableFId)->setFieldset(new S(AUDIO_EDIT_CATEGORY)); if ($this->checkPOST(self::$objCategoryTableFName)->toBoolean() == TRUE && $objFormHappened->toBoolean() == FALSE) { // Add the URL processing ... $this->setExtraUpdateData(self::$objCategoryTableFSEO, URL::getURLFromString($this->getPOST(self::$objCategoryTableFName))); $this->setRedirect($objURLToGoBack); } // Continue ... $this->setName($objFormToRender)->setAJAXEnabledForm(new B(FALSE))->setInputType(new S('submit'))->setName(new S('edit_category_submit'))->setValue(new S(AUDIO_EDIT_CATEGORY))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objCategoryTableFName)->setLabel(new S(AUDIO_CATEGORY_NAME_LABEL))->setJSRegExpReplace(new S('[^a-zA-Z0-9 ,.!?;&-]'))->setMPTTRemoveUnique(new B(TRUE))->setContainerDiv(new B(TRUE))->setInputType(new S('textarea'))->setName(self::$objCategoryTableFDescription)->setLabel(new S(AUDIO_CATEGORY_DESCRIPTION))->setTinyMCETextarea(new B(TRUE))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; case 'categoryErase': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION, ADMIN_ACTION_ID))); // Do erase the group node from the table; self::$objMPTT->mpttRemoveNode($this->getCategoryInfoById($_GET[ADMIN_ACTION_ID], self::$objCategoryTableFName)); // Do a redirect, and get the user back where he belongs; $this->setHeaderKey($objURLToGoBack, new S('Location')); break; case 'categoryMove': // Set some predefines; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION, ADMIN_ACTION_TO, ADMIN_ACTION_TYPE))); // Get names, as they are unique; $objThatIsMoved = $this->getCategoryInfoById($_GET[ADMIN_ACTION_ID], self::$objCategoryTableFName); $objWhereToMove = $this->getCategoryInfoById($_GET[ADMIN_ACTION_TO], self::$objCategoryTableFName); // Get the node subtree, that's move, make sure the node we move to ain't a child; $objMovedNodeSubTree = self::$objMPTT->mpttGetTree($objThatIsMoved); // Memorize; $objIsChild = new B(FALSE); foreach ($objMovedNodeSubTree as $k => $v) { if ($v[self::$objMPTT->objNameOfNode] == $objWhereToMove) { $objIsChild->switchType(); } } // Check if it's a child or not; if ($objIsChild->toBoolean() == TRUE) { // Set an error message; self::$objAdministration->setErrorMessage(new S(AUDIO_CATEGORY_MOVED_TO_CHILD), $objURLToGoBack); } else { // Move nodes; self::$objMPTT->mpttMoveNode($objThatIsMoved, $objWhereToMove, $_GET[ADMIN_ACTION_TYPE]); $this->setHeaderKey($objURLToGoBack, new S('Location')); } // BK; break; case 'categoryMoveOperation': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_SUBPAGE)), new A(array(AUDIO_MANAGE_AUDIO))); // Do some work; $this->checkPOST()->toBoolean() == TRUE ? $objOLDCategoryId = $this->getPOST(new S('old_category_id')) : ($objOLDCategoryId = new S('0')); // Do the form, make it happen; $this->setMethod(new S('POST'))->setFieldset(new S(AUDIO_MOVE_ARTICLE))->setSQLAction(new S('update'))->setTableName(self::$objAudioTable)->setUpdateField(self::$objAudioTableFId)->setUpdateWhere($this->doModuleToken(_S('%objAudioTableFCategoryId = "%Id"')->doToken('%Id', $objOLDCategoryId)))->setName($objFormToRender)->setRedirect($objURLToGoBack)->setInputType(new S('submit'))->setValue(new S(AUDIO_MOVE_ARTICLE))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('select'))->setName(new S('old_category_id'))->setLabel(new S(AUDIO_OLD_CATEGORY))->setContainerDiv(new B(TRUE)); // Cateories; foreach ($this->getCategories() as $k => $v) { $this->setInputType(new S('option'))->setName($v[self::$objMPTT->objIdField])->setValue($v[self::$objMPTT->objIdField])->setLabel(new S(str_repeat('--' . _SP, (int) $v['depth']->toString()) . MPTT::mpttRemoveUnique($v[self::$objMPTT->objNameOfNode]))); } // Categories; $this->setInputType(new S('select'))->setName(self::$objAudioTableFCategoryId)->setLabel(new S(AUDIO_NEW_CATEGORY))->setContainerDiv(new B(TRUE)); foreach ($this->getCategories() as $k => $v) { $this->setInputType(new S('option'))->setName($v[self::$objMPTT->objIdField])->setValue($v[self::$objMPTT->objIdField])->setLabel(new S(str_repeat('--' . _SP, (int) $v['depth']->toString()) . MPTT::mpttRemoveUnique($v[self::$objMPTT->objNameOfNode]))); } // Continue; $this->setFormEndAndExecute(new B(TRUE)); break; case 'configurationEdit': // Do some work; if ($this->checkPOST()->toBoolean() == TRUE) { $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION)), new A(array($this->getPOST(new S('what'))))); } // Do the form, make it happen; $this->setMethod(new S('POST'))->setFieldset(new S(AUDIO_UPDATE_CONFIGURATION))->setName($objFormToRender); // Set redirect; if ($this->checkPOST()->toBoolean() == TRUE) { $this->setRedirect($objURLToGoBack); } // Continue; $this->setInputType(new S('submit'))->setValue(new S(ADMIN_ACTION))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('select'))->setName(new S('what'))->setLabel(new S(AUDIO_CONFIG_CHOOSE))->setContainerDiv(new B(TRUE))->setInputType(new S('option'))->setName(new S('configurationEdit-message_on_top_of_upload_form_page'))->setValue(new S('configurationEdit-message_on_top_of_upload_form_page'))->setLabel(new S(AUDIO_CONFIG_MESSAGE_ON_UPLOAD))->setContainerDiv(new B(TRUE))->setInputType(new S('option'))->setName(new S('configurationEdit-message_upon_upload_ok'))->setValue(new S('configurationEdit-message_upon_upload_ok'))->setLabel(new S(AUDIO_CONFIG_MESSAGE_ON_UPLOAD_OK))->setContainerDiv(new B(TRUE))->setInputType(new S('option'))->setName(new S('configurationEdit-message_if_not_auth'))->setValue(new S('configurationEdit-message_if_not_auth'))->setLabel(new S(AUDIO_CONFIG_MESSAGE_USER_NOT_AUTH))->setContainerDiv(new B(TRUE))->setInputType(new S('option'))->setName(new S('configurationEdit-items_per_page'))->setValue(new S('configurationEdit-items_per_page'))->setLabel(new S(AUDIO_CONFIG_ITEMS_PER_PAGE))->setContainerDiv(new B(TRUE))->setInputType(new S('option'))->setName(new S('configurationEdit-users_should_be_auth_to_comment'))->setValue(new S('configurationEdit-users_should_be_auth_to_comment'))->setLabel(new S(AUDIO_CONFIG_USER_LOGGED_TO_COMM))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; case 'configurationEdit-message_on_top_of_upload_form_page': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION))); // Do some work; if ($this->checkPOST()->toBoolean() == TRUE) { foreach ($this->getPOST() as $k => $v) { $this->setConfigKey(new S($k), $v); } } // Do the form, make it happen; $this->setMethod(new S('POST'))->setFieldset(new S(AUDIO_UPDATE_CONFIGURATION))->setName($objFormToRender)->setRedirect($objURLToGoBack)->setInputType(new S('submit'))->setValue(new S(AUDIO_UPDATE_CONFIGURATION))->setContainerDiv(new B(TRUE))->setInputType(new S('textarea'))->setName(new S('audio_settings_audio_form_page'))->setLabel(new S(AUDIO_CONFIG_DEFAULT))->setValue($this->getConfigKey(new S('audio_settings_audio_form_page')))->setTinyMCETextarea(new B(TRUE))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; case 'configurationEdit-message_upon_upload_ok': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION))); // Do some work; if ($this->checkPOST()->toBoolean() == TRUE) { foreach ($this->getPOST() as $k => $v) { $this->setConfigKey(new S($k), $v); } } // Do the form, make it happen; $this->setMethod(new S('POST'))->setFieldset(new S(AUDIO_UPDATE_CONFIGURATION))->setName($objFormToRender)->setRedirect($objURLToGoBack)->setInputType(new S('submit'))->setValue(new S(AUDIO_UPDATE_CONFIGURATION))->setContainerDiv(new B(TRUE))->setInputType(new S('textarea'))->setName(new S('audio_settings_audio_form_page_status_ok'))->setLabel(new S(AUDIO_CONFIG_DEFAULT))->setValue($this->getConfigKey(new S('audio_settings_audio_form_page_status_ok')))->setTinyMCETextarea(new B(TRUE))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; case 'configurationEdit-message_if_not_auth': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION))); // Do some work; if ($this->checkPOST()->toBoolean() == TRUE) { foreach ($this->getPOST() as $k => $v) { $this->setConfigKey(new S($k), $v); } } // Do the form, make it happen; $this->setMethod(new S('POST'))->setFieldset(new S(AUDIO_UPDATE_CONFIGURATION))->setName($objFormToRender)->setRedirect($objURLToGoBack)->setInputType(new S('submit'))->setValue(new S(AUDIO_UPDATE_CONFIGURATION))->setContainerDiv(new B(TRUE))->setInputType(new S('textarea'))->setName(new S('audio_settings_audio_form_not_authenticated'))->setLabel(new S(AUDIO_CONFIG_DEFAULT))->setValue($this->getConfigKey(new S('audio_settings_audio_form_not_authenticated')))->setTinyMCETextarea(new B(TRUE))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; case 'configurationEdit-items_per_page': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION))); // Do some work; if ($this->checkPOST()->toBoolean() == TRUE) { foreach ($this->getPOST() as $k => $v) { $this->setConfigKey(new S($k), $v); } } // Do the form, make it happen; $this->setMethod(new S('POST'))->setFieldset(new S(AUDIO_UPDATE_CONFIGURATION))->setName($objFormToRender)->setRedirect($objURLToGoBack)->setInputType(new S('submit'))->setValue(new S(AUDIO_UPDATE_CONFIGURATION))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(new S('audio_settings_audio_items_per_page'))->setLabel(new S(AUDIO_CONFIG_DEFAULT))->setValue($this->getConfigKey(new S('audio_settings_audio_items_per_page')))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; case 'configurationEdit-users_should_be_auth_to_comment': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION))); // Do some work; if ($this->checkPOST()->toBoolean() == TRUE) { foreach ($this->getPOST() as $k => $v) { $this->setConfigKey(new S($k), $v); } } // Do the form, make it happen; $this->setMethod(new S('POST'))->setFieldset(new S(AUDIO_UPDATE_CONFIGURATION))->setName($objFormToRender)->setRedirect($objURLToGoBack)->setInputType(new S('submit'))->setValue(new S(AUDIO_UPDATE_CONFIGURATION))->setContainerDiv(new B(TRUE))->setInputType(new S('select'))->setName(new S('audio_settings_audio_auth_to_comment'))->setLabel(new S(AUDIO_CONFIG_CHOOSE))->setContainerDiv(new B(TRUE))->setInputType(new S('option'))->setName(new S('yes'))->setValue(new S('Y'))->setLabel(new S('Yes'))->setSelected($this->getConfigKey(new S('audio_settings_audio_auth_to_comment')) == 'Y' ? new B(TRUE) : new B(FALSE))->setInputType(new S('option'))->setName(new S('no'))->setValue(new S('N'))->setLabel(new S('No'))->setSelected($this->getConfigKey(new S('audio_settings_audio_auth_to_comment')) == 'N' ? new B(TRUE) : new B(FALSE))->setFormEndAndExecute(new B(TRUE)); break; } }
/** * Will render a specified form, the name of the form given by the first parameter; * * This method will render one of the forms for our object, invoked by giving the proper form identifier to the current form. * have chosen this method of invoking forms, because we just had too many this->renderSomethingMethod (), which really had * an impact on code massiveness. Also, having code organized in switch/case statements leads us to be able to share common * settings between different forms, as we've done with the methods defined in the __CALL method above; * * For example, if we wanted to share some common configuration between a create and an edit form, we could have introduced * two switches in this method, one that would have set the common options, and the second, would have just passed through * again, and get the already set configuration options, using them. This means that if we needed to change behavior of * some interconnected forms, that would mean modifying the needed code one place only, which is a big advantage over * having separated methods for each form. Maybe if we extended this object, you guys could understand the functionality best; * * @param string $objFormToRender The name of the form to render; * @return mixed Depends on the rendered form if it returns something or not; */ public function renderForm(S $objFormToRender, A $objFA = NULL) { // Make them defaults ... if ($objFA == NULL) { $objFA = new A(); } // Do a switch ... switch ($objFormToRender) { case 'adminLoginScreen': // Do some URL mangling, redirect back to a pure index; URL::doCleanURLPath(); // Add a <title> tag, saying we need to log in; $this->manageTTL(new S(AUTHENTICATION_LOGIN_FORM)); // Get the personalized CSS; $this->manageCSS(new FilePath($this->getPathToSkin()->toRelativePath() . SKIN_CSS_DIR . _S . 'renderAdminLoginScreen.css'), new S(__FUNCTION__)); // Do the authentication mechanism, check the _POST; if ($this->checkPOST()->toBoolean() == TRUE) { if ($this->doLogIn($this->getPOST(self::$objAuthUsersTableFUName), $this->getPOST(self::$objAuthUsersTableFUPass))->toBoolean() == TRUE) { // OK; $this->setHeaderKey(URL::rewriteURL(new A(array(ADMIN_PAGE)), new A(array(ADMIN_DASHBOARD))), new S('Location')); } else { // Do an error, and retain the user; $this->setErrorOnInput(self::$objAuthUsersTableFUName, new S(AUTHENTICATION_ACCESS_DENIED)); } } // Do the form, make it happen; $this->setMethod(new S('POST'))->setName($objFormToRender)->setFieldset(new S(AUTHENTICATION_LOGIN_FORM))->setInputType(new S('submit'))->setName(new S('submit'))->setValue(new S(AUTHENTICATION_LOGIN_GO))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objAuthUsersTableFUName)->setLabel(new S(AUTHENTICATION_USERNAME))->setJSRegExpReplace(new S('[^a-zA-Z0-9 .-]'))->setTooltip($this->getHELP(new S('adminLoginScreenU')))->setContainerDiv(new B(TRUE))->setInputType(new S('password'))->setName(self::$objAuthUsersTableFUPass)->setLabel(new S(AUTHENTICATION_PASSWORD))->setTooltip($this->getHELP(new S('adminLoginScreenP')))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; case 'userLogIn': // Do the authentication mechanism, check the _POST; if ($this->checkPOST(new S('submit_log_in'))->toBoolean() == TRUE) { // ELSE ... go authenticate us ... if ($this->doLogIn($this->getPOST(new S('user_username')), $this->getPOST(new S('user_password')))->toBoolean() == TRUE) { // Set the proper POST ... $this->setPOST(self::$objAuthUsersTableFIp, new S($_SERVER['REMOTE_ADDR'])); // Make and auto-executing form ... $this->setMethod(new S('POST'))->setSQLAction(new S('update'))->setTableName(self::$objAuthUsersTable)->setUpdateId($this->getUserInfoByName($this->getPOST(new S('user_username')), self::$objAuthUsersTableFId))->setUpdateField(self::$objAuthUsersTableFId)->setName($objFormToRender)->setInputType(new S('text'))->setName(self::$objAuthUsersTableFIp)->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); // Ok ... do nothin' ... $this->setHeaderKey(URL::staticURL(new A(array(FRONTEND_SECTION_URL)), new A(array(FRONTEND_HOME))), new S('Location')); } else { // Do an error, and retain the user; $this->setErrorOnInput(new S('user_username'), new S($objFA['log_in_failed'])); } } // Do the form, make it happen; $this->setMethod(new S('POST'))->setName($objFormToRender)->setInputType(new S('submit'))->setName(new S('submit_log_in'))->setValue(new S($objFA['log_in']))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(new S('user_username'))->setLabel(new S($objFA['log_in_username']))->setJSRegExpReplace(new S('[^a-zA-Z0-9 .-]'))->setContainerDiv(new B(TRUE))->setInputType(new S('password'))->setName(new S('user_password'))->setLabel(new S($objFA['log_in_password']))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; case 'userSignUp': // Set some predefines; $objURLToGoBack = URL::rewriteURL(new A(array(AUTHENTICATION_STATUS_URL)), new A(array(AUTHENTICATION_STATUS_OK_URL))); // Check if both password fields have been entered correctly; if ($this->checkPOST(new S('submit_signup'))->toBoolean() == TRUE) { // Check username ... if ($this->getPOST(self::$objAuthUsersTableFUName)->toLength()->toInt() == 0) { //Check non-empty username, and error if the username is empty; $this->setErrorOnInput(self::$objAuthUsersTableFUName, new S($objFA['error_username_mandatory'])); } else { // Check USERNAME; if ($this->checkUserNameExists($this->getPOST(self::$objAuthUsersTableFUName))->toBoolean() == TRUE) { $this->setErrorOnInput(self::$objAuthUsersTableFUName, new S($objFA['error_username_exists'])); } // Check EMAIL; if ($this->checkUserMailExists($this->getPOST(self::$objAuthUsersTableFEML))->toBoolean() == TRUE) { $this->setErrorOnInput(self::$objAuthUsersTableFEML, new S($objFA['error_email_exists'])); } } // Check password; if ($this->getPOST(self::$objAuthUsersTableFUPass) != $this->getPOST(new S('confirmation_password'))) { // Check password mismatch, and error on it if so; $this->setErrorOnInput(self::$objAuthUsersTableFUPass, new S($objFA['error_passwords_do_not_match'])); } // Check phone number has 10 chars, only if it is required; if (self::PHONE_IS_REQUIRED == 1) { if ($this->getPOST(self::$objAuthUsersTableFPhone)->toLength()->toInt() != 10) { $this->setErrorOnInput(self::$objAuthUsersTableFPhone, new S($objFA['error_phone_ten_chars'])); } } } // Get AJAX; $this->getAjaxErrors(); // Do the form, make it happen; $this->setMethod(new S('POST'))->setEnctype(new S('multipart/form-data'))->setFieldset(new S($objFA['form_signup']))->setSQLAction(new S('update'))->setTableName(self::$objAuthUsersTable)->setUpdateId(new S('#nextTableAutoIncrement'))->setUpdateField(self::$objAuthUsersTableFId)->setExtraUpdateData(self::$objAuthUsersTableFRegOn, new S((string) $_SERVER['REQUEST_TIME']))->setExtraUpdateData(self::$objAuthUsersTableFUGId, $objFA['default_group_id'])->setExtraUpdateData(self::$objAuthUsersTableFActivated, new S('N'))->setName($objFormToRender)->setRedirect($objURLToGoBack)->setAJAXEnabledForm(new B(FALSE))->setInputType(new S('submit'))->setName(new S('submit_signup'))->setValue(new S($objFA['form_submit']))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objAuthUsersTableFUName)->setLabel(new S($objFA['form_username']))->setContainerDiv(new B(TRUE))->setJSRegExpReplace(new S('[^a-zA-Z0-9 .-]'))->setInputType(new S('password'))->setName(self::$objAuthUsersTableFUPass)->setLabel(new S($objFA['form_password']))->setContainerDiv(new B(TRUE))->setInputType(new S('password'))->setName(new S('confirmation_password'))->setLabel(new S($objFA['form_password_confirm']))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objAuthUsersTableFEML)->setRegExpType(new S('preg'))->setRegExpErrMsg(new S($objFA['form_regexp_invalid_email']))->setPHPRegExpCheck(new S(self::REGEXP_PHP_CHECK_EMAIL))->setJSRegExpReplace(new S('[^a-zA-Z0-9.@_-]'))->setLabel(new S($objFA['form_email']))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objAuthUsersTableFPhone)->setLabel(new S($objFA['form_phone']))->setContainerDiv(new B(TRUE))->setJSRegExpReplace(new S('[^0-9]'))->setInputType(new S('text'))->setName(self::$objAuthUsersTableFLName)->setLabel(new S($objFA['form_last_name']))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objAuthUsersTableFFName)->setLabel(new S($objFA['form_first_name']))->setContainerDiv(new B(TRUE))->setInputType(new S('select'))->setContainerDiv(new B(TRUE))->setName(self::$objAuthUsersTableFCountry)->setLabel(new S($objFA['form_country'])); // Get the COUNTRIES; foreach ($this->STG->getCountries() as $k => $v) { $this->setInputType(new S('option'))->setName($v[Settings::$objSettingsCountryTableFIso])->setValue($v[Settings::$objSettingsCountryTableFIso])->setLabel($v[Settings::$objSettingsCountryTableFPrnt]); } // Continue; $this->setInputType(new S('text'))->setName(self::$objAuthUsersTableFCity)->setLabel(new S($objFA['form_city']))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objAuthUsersTableFYM)->setLabel(new S($objFA['form_ym']))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objAuthUsersTableFMSN)->setLabel(new S($objFA['form_msn']))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objAuthUsersTableFICQ)->setLabel(new S($objFA['form_icq']))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objAuthUsersTableFAOL)->setLabel(new S($objFA['form_aol']))->setContainerDiv(new B(TRUE))->setInputType(new S('textarea'))->setName(self::$objAuthUsersTableFDesc)->setLabel(new S($objFA['form_description']))->setContainerDiv(new B(TRUE))->setInputType(new S('textarea'))->setName(self::$objAuthUsersTableFSignature)->setLabel(new S($objFA['form_signature']))->setContainerDiv(new B(TRUE)); // Encrypt the data; if ($this->checkFormHasErrors()->toBoolean() == FALSE) { // Make them passwords OK ... if ($this->checkPOST()->toBoolean() == TRUE) { $this->setPOST(self::$objAuthUsersTableFUPass, $this->getPOST(self::$objAuthUsersTableFUPass)->encryptIt(sha1($this->getPOST(self::$objAuthUsersTableFUPass)))); $this->setPOST(new S('confirmation_password'), $this->getPOST(self::$objAuthUsersTableFUPass)); } $this->setExtraUpdateData(self::$objAuthUsersTableFHash, new S(sha1(md5($this->getPOST(self::$objAuthUsersTableFEML))))); // Send the activation EML ... $objEML = new MAIL(); $objEML->doMAIL($this->getPOST(self::$objAuthUsersTableFEML), $objFA['form_activation_subject'], $this->getHELP(new S('activationEMLMessage'))->doToken('%u', $this->getPOST(self::$objAuthUsersTableFUName))->doToken('%a', URL::staticURL(new A(array(FRONTEND_SECTION_URL, AUTHENTICATION_ACTION_URL, AUTHENTICATION_HASH_URL)), new A(array(FRONTEND_AUTHENTICATION_URL, AUTHENTICATION_ACTIVATE_URL, sha1(md5($this->getPOST(self::$objAuthUsersTableFEML)))))))); } // Continue; $this->setFormEndAndExecute(new B(TRUE)); break; case 'userProfile': // Set some predefines; $objURLToGoBack = URL::rewriteURL(new A(array(AUTHENTICATION_STATUS_URL)), new A(array(AUTHENTICATION_STATUS_OK_URL))); // Check if both password fields have been entered correctly; if ($this->checkPOST(new S('submit_signup'))->toBoolean() == TRUE) { // Check username ... if ($this->getPOST(self::$objAuthUsersTableFUName)->toLength()->toInt() == 0) { //Check non-empty username, and error if the username is empty; $this->setErrorOnInput(self::$objAuthUsersTableFUName, new S($objFA['error_username_mandatory'])); } else { if ($this->getPOST(self::$objAuthUsersTableFUName) != $this->getCurrentUserInfoById(self::$objAuthUsersTableFUName)) { // Check USERNAME; if ($this->checkUserNameExists($this->getPOST(self::$objAuthUsersTableFUName))->toBoolean() == TRUE) { $this->setErrorOnInput(self::$objAuthUsersTableFUName, new S($objFA['error_username_exists'])); } } if ($this->getPOST(self::$objAuthUsersTableFEML) != $this->getCurrentUserInfoById(self::$objAuthUsersTableFEML)) { // Check EMAIL; if ($this->checkUserMailExists($this->getPOST(self::$objAuthUsersTableFEML))->toBoolean() == TRUE) { $this->setErrorOnInput(self::$objAuthUsersTableFEML, new S($objFA['error_email_exists'])); } } } // Check password; if ($this->getPOST(self::$objAuthUsersTableFUPass) != $this->getPOST(new S('confirmation_password'))) { // Check password mismatch, and error on it if so; $this->setErrorOnInput(self::$objAuthUsersTableFUPass, new S($objFA['error_passwords_do_not_match'])); } // Check phone number has 10 chars, only if it is required; if (self::PHONE_IS_REQUIRED == 1) { if ($this->getPOST(self::$objAuthUsersTableFPhone)->toLength()->toInt() != 10) { $this->setErrorOnInput(self::$objAuthUsersTableFPhone, new S($objFA['error_phone_ten_chars'])); } } } // Get AJAX; $this->getAjaxErrors(); // Do the form, make it happen; $this->setMethod(new S('POST'))->setEnctype(new S('multipart/form-data'))->setFieldset(new S($objFA['form_signup']))->setSQLAction(new S('update'))->setTableName(self::$objAuthUsersTable)->setUpdateId(new S($this->getCurrentUserInfoById(self::$objAuthUsersTableFId)))->setUpdateField(self::$objAuthUsersTableFId)->setUploadDirectory(new S('users/avatars'))->setUploadImageResize(new A(array(128 => 128)))->setExtraUpdateData(self::$objAuthUsersTableFActivated, new S('N'))->setName($objFormToRender)->setRedirect($objURLToGoBack)->setAJAXEnabledForm(new B(FALSE))->setInputType(new S('submit'))->setName(new S('submit_signup'))->setValue(new S($objFA['form_submit']))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objAuthUsersTableFUName)->setLabel(new S($objFA['form_username']))->setReadOnly(new B(TRUE))->setContainerDiv(new B(TRUE))->setJSRegExpReplace(new S('[^a-zA-Z0-9 .-]'))->setInputType(new S('password'))->setName(self::$objAuthUsersTableFUPass)->setLabel(new S($objFA['form_password']))->setContainerDiv(new B(TRUE))->setInputType(new S('password'))->setName(new S('confirmation_password'))->setValue($this->getCurrentUserInfoById(self::$objAuthUsersTableFUPass))->setLabel(new S($objFA['form_password_confirm']))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objAuthUsersTableFEML)->setRegExpType(new S('preg'))->setRegExpErrMsg(new S($objFA['form_regexp_invalid_email']))->setPHPRegExpCheck(new S(self::REGEXP_PHP_CHECK_EMAIL))->setJSRegExpReplace(new S('[^a-zA-Z0-9.@_-]'))->setLabel(new S($objFA['form_email']))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objAuthUsersTableFPhone)->setLabel(new S($objFA['form_phone']))->setContainerDiv(new B(TRUE))->setJSRegExpReplace(new S('[^0-9]'))->setInputType(new S('text'))->setName(self::$objAuthUsersTableFLName)->setLabel(new S($objFA['form_last_name']))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objAuthUsersTableFFName)->setLabel(new S($objFA['form_first_name']))->setContainerDiv(new B(TRUE))->setInputType(new S('select'))->setContainerDiv(new B(TRUE))->setName(self::$objAuthUsersTableFCountry)->setLabel(new S($objFA['form_country'])); // Get the COUNTRIES; foreach ($this->STG->getCountries() as $k => $v) { $this->setInputType(new S('option'))->setName($v[Settings::$objSettingsCountryTableFIso])->setValue($v[Settings::$objSettingsCountryTableFIso])->setLabel($v[Settings::$objSettingsCountryTableFPrnt]); } // Continue; $this->setInputType(new S('text'))->setName(self::$objAuthUsersTableFCity)->setLabel(new S($objFA['form_city']))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objAuthUsersTableFYM)->setLabel(new S($objFA['form_ym']))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objAuthUsersTableFMSN)->setLabel(new S($objFA['form_msn']))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objAuthUsersTableFICQ)->setLabel(new S($objFA['form_icq']))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objAuthUsersTableFAOL)->setLabel(new S($objFA['form_aol']))->setContainerDiv(new B(TRUE))->setInputType(new S('file'))->setFileController(new B(TRUE))->setName(self::$objAuthUsersTableFAvatar)->setLabel(new S($objFA['form_avatar']))->setContainerDiv(new B(TRUE))->setInputType(new S('textarea'))->setName(self::$objAuthUsersTableFDesc)->setLabel(new S($objFA['form_description']))->setContainerDiv(new B(TRUE))->setInputType(new S('textarea'))->setName(self::$objAuthUsersTableFSignature)->setLabel(new S($objFA['form_signature']))->setContainerDiv(new B(TRUE)); // Encrypt the data; if ($this->checkFormHasErrors()->toBoolean() == FALSE) { // Make them passwords OK ... if ($this->checkPOST(self::$objAuthUsersTableFUPass)->toBoolean() == TRUE) { // If they differ ... if ($this->getPOST(self::$objAuthUsersTableFUPass) != $this->getCurrentUserInfoById(self::$objAuthUsersTableFUPass)) { $this->setPOST(self::$objAuthUsersTableFUPass, $this->getPOST(self::$objAuthUsersTableFUPass)->encryptIt(sha1($this->getPOST(self::$objAuthUsersTableFUPass)))); $this->setPOST(new S('confirmation_password'), $this->getPOST(self::$objAuthUsersTableFUPass)); } } $this->setExtraUpdateData(self::$objAuthUsersTableFHash, new S(sha1(md5($this->getPOST(self::$objAuthUsersTableFEML))))); // Send the activation EML ... $objEML = new MAIL(); $objEML->doMAIL($this->getPOST(self::$objAuthUsersTableFEML), $objFA['form_activation_subject'], $this->getHELP(new S('activationEMLMessage'))->doToken('%u', $this->getPOST(self::$objAuthUsersTableFUName))->doToken('%a', URL::staticURL(new A(array(FRONTEND_SECTION_URL, AUTHENTICATION_ACTION_URL, AUTHENTICATION_HASH_URL)), new A(array(FRONTEND_AUTHENTICATION_URL, AUTHENTICATION_ACTIVATE_URL, sha1(md5($this->getPOST(self::$objAuthUsersTableFEML)))))))); } // Continue; $this->setFormEndAndExecute(new B(TRUE)); break; case 'userCreate': // Set some predefines; $objURLToGoBack = URL::rewriteURL(); // Check if both password fields have been entered correctly; if ($this->checkPOST(self::$objAuthUsersTableFUName)->toBoolean() == TRUE) { // Check username ... if ($this->getPOST(self::$objAuthUsersTableFUName)->toLength()->toInt() == 0) { //Check non-empty username, and error if the username is empty; $this->setErrorOnInput(self::$objAuthUsersTableFUName, new S(AUTHENTICATION_USERNAME_IS_MANDATORY)); } else { // Check USERNAME; if ($this->checkUserNameExists($this->getPOST(self::$objAuthUsersTableFUName))->toBoolean() == TRUE) { $this->setErrorOnInput(self::$objAuthUsersTableFUName, new S(AUTHENTICATION_USERNAME_ALREADY_EXISTS)); } // Check EMAIL; if ($this->checkUserMailExists($this->getPOST(self::$objAuthUsersTableFEML))->toBoolean() == TRUE) { $this->setErrorOnInput(self::$objAuthUsersTableFEML, new S(AUTHENTICATION_EMAIL_ALREADY_EXISTS)); } } // Check password; if ($this->getPOST(self::$objAuthUsersTableFUPass) != $this->getPOST(new S('confirmation_password'))) { // Check password mismatch, and error on it if so; $this->setErrorOnInput(self::$objAuthUsersTableFUPass, new S(AUTHENTICATION_USER_PASSWORDS_DONT_MATCH)); } // Check phone number has 10 chars, only if it is required; if (self::PHONE_IS_REQUIRED == 1) { if ($this->getPOST(self::$objAuthUsersTableFPhone)->toLength()->toInt() != 10) { $this->setErrorOnInput(self::$objAuthUsersTableFPhone, new S(AUTHENTICATION_PHONE_TEN_CHARS)); } } } // Get AJAX; $this->getAjaxErrors(); // Do the form, make it happen; $this->setMethod(new S('POST'))->setEnctype(new S('multipart/form-data'))->setFieldset(new S(AUTHENTICATION_PROFILE_ADD))->setSQLAction(new S('update'))->setTableName(self::$objAuthUsersTable)->setUpdateId(new S('#nextTableAutoIncrement'))->setUpdateField(self::$objAuthUsersTableFId)->setUploadDirectory(new S('users/avatars'))->setUploadImageResize(new A(array(128 => 128)))->setExtraUpdateData(self::$objAuthUsersTableFRegOn, new S((string) $_SERVER['REQUEST_TIME'])); if ($this->checkPOST(self::$objAuthUsersTableFUName)->toBoolean() == TRUE) { $this->setRedirect($objURLToGoBack); } $this->setName($objFormToRender)->setAJAXEnabledForm(new B(FALSE))->setInputType(new S('submit'))->setName(new S('submit'))->setValue(new S(AUTHENTICATION_PROFILE_ADD))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objAuthUsersTableFUName)->setLabel(new S(AUTHENTICATION_PROFILE_USERNAME))->setContainerDiv(new B(TRUE))->setJSRegExpReplace(new S('[^a-zA-Z0-9 .-]'))->setInputType(new S('password'))->setName(self::$objAuthUsersTableFUPass)->setLabel(new S(AUTHENTICATION_PROFILE_PASSWORD))->setContainerDiv(new B(TRUE))->setInputType(new S('password'))->setName(new S('confirmation_password'))->setLabel(new S(AUTHENTICATION_PROFILE_PASSWORD_CONFIRM))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objAuthUsersTableFEML)->setRegExpType(new S('preg'))->setRegExpErrMsg(new S(AUTHENTICATION_INVALID_EMAIL))->setPHPRegExpCheck(new S(self::REGEXP_PHP_CHECK_EMAIL))->setJSRegExpReplace(new S('[^a-zA-Z0-9.@_-]'))->setLabel(new S(AUTHENTICATION_PROFILE_EMAIL))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objAuthUsersTableFPhone)->setLabel(new S(AUTHENTICATION_PROFILE_PHONE))->setContainerDiv(new B(TRUE))->setJSRegExpReplace(new S('[^0-9]'))->setInputType(new S('text'))->setName(self::$objAuthUsersTableFLName)->setLabel(new S(AUTHENTICATION_PROFILE_LAST_NAME))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objAuthUsersTableFFName)->setLabel(new S(AUTHENTICATION_PROFILE_FIRST_NAME))->setContainerDiv(new B(TRUE))->setInputType(new S('select'))->setContainerDiv(new B(TRUE))->setName(self::$objAuthUsersTableFCountry)->setLabel(new S(AUTHENTICATION_PROFILE_COUNTRY)); // Get the COUNTRIES; foreach ($this->STG->getCountries() as $k => $v) { $this->setInputType(new S('option'))->setName($v[Settings::$objSettingsCountryTableFIso])->setValue($v[Settings::$objSettingsCountryTableFIso])->setLabel($v[Settings::$objSettingsCountryTableFPrnt]); } // Continue; $this->setInputType(new S('text'))->setName(self::$objAuthUsersTableFCity)->setLabel(new S(AUTHENTICATION_PROFILE_CITY))->setContainerDiv(new B(TRUE))->setInputType(new S('select'))->setContainerDiv(new B(TRUE))->setName(self::$objAuthUsersTableFUGId)->setLabel(new S(AUTHENTICATION_PROFILE_GROUP)); // Get the groups of the user; foreach (self::$objMPTT->mpttGetTree() as $k => $v) { $this->setInputType(new S('option'))->setName($v['id'])->setValue($v['id'])->setLabel(new S(str_repeat('--' . _SP, (int) $v['depth']->toString()) . $v['name'])); } // Continue; $this->setInputType(new S('text'))->setName(self::$objAuthUsersTableFYM)->setLabel(new S(AUTHENTICATION_PROFILE_YM))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objAuthUsersTableFMSN)->setLabel(new S(AUTHENTICATION_PROFILE_MSN))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objAuthUsersTableFICQ)->setLabel(new S(AUTHENTICATION_PROFILE_ICQ))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objAuthUsersTableFAOL)->setLabel(new S(AUTHENTICATION_PROFILE_AOL))->setContainerDiv(new B(TRUE))->setInputType(new S('file'))->setFileController(new B(TRUE))->setName(self::$objAuthUsersTableFAvatar)->setLabel(new S(AUTHENTICATION_PROFILE_AVATAR))->setContainerDiv(new B(TRUE))->setInputType(new S('textarea'))->setName(self::$objAuthUsersTableFDesc)->setLabel(new S(AUTHENTICATION_PROFILE_DESCRIPTION))->setContainerDiv(new B(TRUE))->setInputType(new S('textarea'))->setName(self::$objAuthUsersTableFSignature)->setLabel(new S(AUTHENTICATION_PROFILE_SIGNATURE))->setContainerDiv(new B(TRUE)); // Encrypt the data; if ($this->checkFormHasErrors()->toBoolean() == FALSE) { if ($this->checkPOST(self::$objAuthUsersTableFUPass)->toBoolean() == TRUE) { $this->setPOST(self::$objAuthUsersTableFUPass, $this->getPOST(self::$objAuthUsersTableFUPass)->encryptIt(sha1($this->getPOST(self::$objAuthUsersTableFUPass)))); $this->setPOST(new S('confirmation_password'), $this->getPOST(self::$objAuthUsersTableFUPass)); } } // Continue; $this->setFormEndAndExecute(new B(TRUE)); break; case 'userEdit': // Set some predefines; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION, ADMIN_ACTION_ID))); // Check if both password fields have been entered correctly; if ($this->checkPOST()->toBoolean() == TRUE) { // Check username ... if ($this->getPOST(self::$objAuthUsersTableFUName)->toLength()->toInt() == 0) { //Check non-empty username, and error if the username is empty; $this->setErrorOnInput(self::$objAuthUsersTableFUName, new S(AUTHENTICATION_USERNAME_IS_MANDATORY)); } // Check password mismatch; if ($this->getPOST(self::$objAuthUsersTableFUPass) == $this->getUserInfoById($_GET[ADMIN_ACTION_ID], self::$objAuthUsersTableFUPass) && $this->getPOST(new S('confirmation_password')) == $this->getPOST(self::$objAuthUsersTableFUPass)) { // Unset ... $this->unsetPOST(self::$objAuthUsersTableFUPass); } else { if ($this->getPOST(self::$objAuthUsersTableFUPass) != $this->getPOST(new S('confirmation_password'))) { $this->setErrorOnInput(self::$objAuthUsersTableFUPass, new S(AUTHENTICATION_USER_PASSWORDS_DONT_MATCH)); } } // Check phone number has 10 chars, only if it's required; if (self::PHONE_IS_REQUIRED == 1) { if ($this->getPOST(self::$objAuthUsersTableFPhone)->toLength()->toInt() != 10) { $this->setErrorOnInput(self::$objAuthUsersTableFPhone, new S(AUTHENTICATION_PHONE_TEN_CHARS)); } } } // Get AJAX; $this->getAjaxErrors(); // Make the form, make it happen; $this->setMethod(new S('POST'))->setEnctype(new S('multipart/form-data'))->setFieldset(new S(AUTHENTICATION_PROFILE_EDIT))->setSQLAction(new S('update'))->setUpdateId($_GET[ADMIN_ACTION_ID])->setUploadDirectory(new S('users/avatars'))->setUploadImageResize(new A(array(128 => 128)))->setTableName(self::$objAuthUsersTable)->setUpdateField(self::$objAuthUsersTableFId)->setAJAXEnabledForm(new B(FALSE))->setName($objFormToRender)->setRedirect($objURLToGoBack)->setInputType(new S('submit'))->setName(new S('submit'))->setValue(new S(AUTHENTICATION_PROFILE_EDIT))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE)); // ONLY if we're NOT the BIG MAN, we cand de-activate; if ((int) $this->getUserInfoById($_GET[ADMIN_ACTION_ID], self::$objAuthUsersTableFId)->toString() != 1) { $this->setInputType(new S('select'))->setName(self::$objAuthUsersTableFActivated)->setContainerDiv(new B(TRUE))->setLabel(new S(AUTHENTICATION_PROFILE_ACTIVATED))->setInputType(new S('option'))->setName(new S('yes'))->setValue(new S('Y'))->setLabel(new S(AUTHENTICATION_PROFILE_ACTIVATED_YES))->setInputType(new S('option'))->setName(new S('no'))->setValue(new S('N'))->setLabel(new S(AUTHENTICATION_PROFILE_ACTIVATED_NO)); } $this->setInputType(new S('text'))->setName(self::$objAuthUsersTableFUName)->setLabel(new S(AUTHENTICATION_PROFILE_USERNAME))->setContainerDiv(new B(TRUE))->setJSRegExpReplace(new S('[^a-zA-Z0-9 .-]'))->setInputType(new S('password'))->setName(self::$objAuthUsersTableFUPass)->setValue($this->getUserInfoById($_GET[ADMIN_ACTION_ID], self::$objAuthUsersTableFUPass))->setLabel(new S(AUTHENTICATION_PROFILE_PASSWORD))->setContainerDiv(new B(TRUE))->setInputType(new S('password'))->setName(new S('confirmation_password'))->setValue($this->getUserInfoById($_GET[ADMIN_ACTION_ID], self::$objAuthUsersTableFUPass))->setLabel(new S(AUTHENTICATION_PROFILE_PASSWORD_CONFIRM))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objAuthUsersTableFEML)->setJSRegExpReplace(new S('[^a-zA-Z0-9.@_-]'))->setLabel(new S(AUTHENTICATION_PROFILE_EMAIL))->setContainerDiv(new B(TRUE))->setRegExpType(new S('preg'))->setRegExpErrMsg(new S(AUTHENTICATION_INVALID_EMAIL))->setPHPRegExpCheck(new S(self::REGEXP_PHP_CHECK_EMAIL))->setInputType(new S('text'))->setName(self::$objAuthUsersTableFPhone)->setLabel(new S(AUTHENTICATION_PROFILE_PHONE))->setContainerDiv(new B(TRUE))->setJSRegExpReplace(new S('[^0-9]'))->setInputType(new S('text'))->setName(self::$objAuthUsersTableFLName)->setLabel(new S(AUTHENTICATION_PROFILE_LAST_NAME))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objAuthUsersTableFFName)->setLabel(new S(AUTHENTICATION_PROFILE_FIRST_NAME))->setContainerDiv(new B(TRUE))->setInputType(new S('select'))->setContainerDiv(new B(TRUE))->setName(self::$objAuthUsersTableFCountry)->setLabel(new S(AUTHENTICATION_PROFILE_COUNTRY)); // Countries ... foreach ($this->STG->getCountries() as $k => $v) { $this->setInputType(new S('option'))->setName($v[Settings::$objSettingsCountryTableFIso])->setValue($v[Settings::$objSettingsCountryTableFIso])->setLabel($v[Settings::$objSettingsCountryTableFPrnt]); } // Continue ... $this->setInputType(new S('text'))->setName(self::$objAuthUsersTableFCity)->setLabel(new S(AUTHENTICATION_PROFILE_CITY))->setContainerDiv(new B(TRUE)); // ONLY if we're not the BIG MAN, can we change the group; if ((int) $this->getUserInfoById($_GET[ADMIN_ACTION_ID], self::$objAuthUsersTableFId)->toString() != 1) { $this->setInputType(new S('select'))->setContainerDiv(new B(TRUE))->setName(self::$objAuthUsersTableFUGId)->setLabel(new S(AUTHENTICATION_PROFILE_GROUP)); foreach (self::$objMPTT->mpttGetTree() as $k => $v) { $this->setInputType(new S('option'))->setName($v['id'])->setValue($v['id'])->setLabel(new S(str_repeat('--' . _SP, (int) $v['depth']->toString()) . $v['name'])); } } // Execute the form, make it happen; $this->setInputType(new S('text'))->setName(self::$objAuthUsersTableFYM)->setLabel(new S(AUTHENTICATION_PROFILE_YM))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objAuthUsersTableFMSN)->setLabel(new S(AUTHENTICATION_PROFILE_MSN))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objAuthUsersTableFICQ)->setLabel(new S(AUTHENTICATION_PROFILE_ICQ))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objAuthUsersTableFAOL)->setLabel(new S(AUTHENTICATION_PROFILE_AOL))->setContainerDiv(new B(TRUE))->setInputType(new S('file'))->setFileController(new B(TRUE))->setName(self::$objAuthUsersTableFAvatar)->setLabel(new S(AUTHENTICATION_PROFILE_AVATAR))->setContainerDiv(new B(TRUE))->setInputType(new S('textarea'))->setName(self::$objAuthUsersTableFDesc)->setLabel(new S(AUTHENTICATION_PROFILE_DESCRIPTION))->setContainerDiv(new B(TRUE))->setInputType(new S('textarea'))->setName(self::$objAuthUsersTableFSignature)->setLabel(new S(AUTHENTICATION_PROFILE_SIGNATURE))->setContainerDiv(new B(TRUE)); // Encrypt the data; if ($this->checkFormHasErrors()->toBoolean() == FALSE) { if ($this->checkPOST(self::$objAuthUsersTableFUPass)->toBoolean() == TRUE) { $this->setPOST(self::$objAuthUsersTableFUPass, $this->getPOST(self::$objAuthUsersTableFUPass)->encryptIt(sha1($this->getPOST(self::$objAuthUsersTableFUPass)))); $this->setPOST(new S('confirmation_password'), $this->getPOST(self::$objAuthUsersTableFUPass)); } } // Continue; $this->setFormEndAndExecute(new B(TRUE)); break; case 'userErase': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION, ADMIN_ACTION_ID))); // Check if it's administrator user, and don't delete it; if ((int) $_GET[ADMIN_ACTION_ID]->toString() == 1) { // Do not permit the deletion of the administrator user; self::$objAdministration->setErrorMessage(new S(CANNOT_DELETE_ADMINISTRATOR_USER), $objURLToGoBack); } else { // Check to see if there are any zone mappings, for the current zone; if ($this->_Q(_QS('doSELECT')->doToken('%what', new S('*'))->doToken('%table', self::$objAuthZoneMTable)->doToken('%condition', new S('WHERE %objAuthZoneMTableFUGId = "%Id" AND %objAuthZoneMTableFIUG = "N"'))->doToken('%Id', $_GET[ADMIN_ACTION_ID]))->doCount()->toInt() != 0) { // Do not delete users that have specific mappings; self::$objAdministration->setErrorMessage(new S(CANNOT_DELETE_MAPPED_USERS), $objURLToGoBack); } else { // Go further ... and erase the user ... $this->_Q(_QS('doDELETE')->doToken('%table', self::$objAuthUsersTable)->doToken('%condition', new S('%objAuthUsersTableFId = "%Id"'))->doToken('%Id', $_GET[ADMIN_ACTION_ID])); // Do a redirect, and get the user back where he belongs; $this->setHeaderKey($objURLToGoBack, new S('Location')); } } break; case 'userSearch': // Get some predefines; if (isset($_GET[ADMIN_ACTION_SEARCH])) { $objSearchWas = $_GET[ADMIN_ACTION_SEARCH]; } else { $objSearchWas = new S(); } if (isset($_GET[ADMIN_ACTION_BY])) { $objSearchBy = $_GET[ADMIN_ACTION_BY]; } else { $objSearchBy = new S(); } // Do some work; if ($this->checkPOST(new S('search_submit'))->toBoolean() == TRUE) { if ($this->getPOST(new S('search_user_by'))->toLength()->toInt() == 0) { if (isset($_GET[ADMIN_ACTION_SEARCH])) { // Erase search terms ... $this->setHeaderKey(URL::rewriteURL(new A(array(ADMIN_ACTION_SEARCH, ADMIN_ACTION_BY))), new S('Location')); } // Set an error, notify me ... $this->setErrorOnInput(new S('search_user_by'), new S(AUTHENTICATION_SEARCH_FIELD_IS_EMPTY)); // Unset the post ... $this->unsetPOST(); } else { // Get what to search and where ... $objWhatToSearch = $this->getPOST(new S('search_user_by')); $objWhereToSearch = $this->getPOST(new S('search_user_field')); // And go there ... $this->setHeaderKey(URL::rewriteURL(new A(array(ADMIN_ACTION_SEARCH, ADMIN_ACTION_BY)), new A(array($objWhatToSearch, $objWhereToSearch))), new S('Location')); } } $objWasSelected = new A(array(new B($objSearchBy == AUTHENTICATION_PROFILE_USERNAME ? TRUE : FALSE), new B($objSearchBy == AUTHENTICATION_PROFILE_EMAIL ? TRUE : FALSE), new B($objSearchBy == AUTHENTICATION_PROFILE_GROUP ? TRUE : FALSE))); // Do the form, make it happen; $this->setMethod(new S('POST'))->setEnctype(new S('multipart/form-data'))->setFieldset(new S(AUTHENTICATION_SEARCH_USER_BY))->setName($objFormToRender)->setInputType(new S('text'))->setInputInfoMessage($this->getHELP($objFormToRender))->setName(new S('search_user_by'))->setvalue($objSearchWas)->setLabel(new S(AUTHENTICATION_SEARCH_USER_BY))->setContainerDiv(new B(TRUE))->setInputType(new S('select'))->setName(new S('search_user_field'))->setContainerDiv(new B(TRUE))->setLabel(new S(AUTHENTICATION_SEARCH_USER_IN))->setInputType(new S('option'))->setName(new S('username_search'))->setValue(new S(AUTHENTICATION_PROFILE_USERNAME))->setLabel(new S(AUTHENTICATION_PROFILE_USERNAME))->setSelected($objWasSelected[0])->setInputType(new S('option'))->setName(new S('email_search'))->setValue(new S(AUTHENTICATION_PROFILE_EMAIL))->setLabel(new S(AUTHENTICATION_PROFILE_EMAIL))->setSelected($objWasSelected[1])->setInputType(new S('option'))->setName(new S('group_serach'))->setValue(new S(AUTHENTICATION_PROFILE_GROUP))->setLabel(new S(AUTHENTICATION_PROFILE_GROUP))->setSelected($objWasSelected[2])->setInputType(new S('submit'))->setContainerDiv(new B(TRUE))->setValue(new S(AUTHENTICATION_SEARCH_USER_BY))->setName(new S('search_submit'))->setFormEndAndExecute(new B(TRUE)); break; case 'groupCreate': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(); // Do some work ... if ($this->checkPOST(new S('categories_show_all'))->toBoolean() == TRUE) { // Redirect to proper ... $this->setHeaderKey(URL::rewriteURL(new A(array(ADMIN_SHOW_ALL)), new A(array('1'))), new S('Location')); } // Do some work; if ($this->checkPOST(new S('submit_add_group'))->toBoolean() == TRUE) { // Set some requirements; $objFormHappened = new B(FALSE); if ($this->getPOST(new S('group'))->toLength()->toInt() == 0) { // Check for empty group name, and error on it. We don't allow empty group names; $this->setErrorOnInput(new S('group'), new S(GROUP_NAME_CANNOT_BE_EMPTY)); // Set to memory; $objFormHappened->switchType(); } else { if (self::$objMPTT->mpttCheckIfNodeExists($this->getPOST(new S('group')))->toBoolean() == TRUE) { // Check to see if the group exists, and tell the user the group exists; $this->setErrorOnInput(new S('group'), new S(GROUP_ALREADY_EXISTS)); // Set to memory; $objFormHappened->switchType(); } } // Get AJAX; $this->getAjaxErrors(); if ($objFormHappened->toBoolean() == FALSE) { // Remember if we should add it as a brother or child; $objAddNodeAS = NULL; // Switch ... switch ($this->getPOST(new S('group_as_what'))) { case AUTHENTICATION_GROUP_CHILD: $objAddNodeAS = new S((string) MPTT::FIRST_CHILD); break; case AUTHENTICATION_GROUP_LAST_CHILD: $objAddNodeAS = new S((string) MPTT::LAST_CHILD); break; case AUTHENTICATION_GROUP_BROTHER: $objAddNodeAS = new S((string) MPTT::PREVIOUS_BROTHER); break; case AUTHENTICATION_GROUP_NEXT_BROTHER: $objAddNodeAS = new S((string) MPTT::NEXT_BROTHER); break; } // Add the node; self::$objMPTT->mpttAddNode($this->getPOST(new S('group')), $this->getPOST(new S('group_parent_or_bro')), $objAddNodeAS); // Do a redirect back; $this->setHeaderKey($objURLToGoBack, new S('Location')); } } // Do the form, make it happen; $this->setMethod(new S('POST'))->setFieldset(new S(ADD_NEW_GROUP_OF_USERS))->setName(new S($objFormToRender))->setAJAXEnabledForm(new B(FALSE))->setInputType(new S('submit'))->setName(new S('categories_show_all'))->setValue(new S(AUTHENTICATION_SHOW_ALL_CATEGORIES))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('submit'))->setContainerDiv(new B(TRUE))->setName(new S('submit_add_group'))->setValue(new S(AUTHENTICATION_ADD_GROUP))->setInputType(new S('text'))->setContainerDiv(new B(TRUE))->setName(new S('group'))->setLabel(new S(AUTHENTICATION_GROUP_NAME_LABEL))->setRegExpType(new S('ereg'))->setJSRegExpReplace(new S('[^a-zA-Z0-9 -]'))->setInputType(new S('select'))->setContainerDiv(new B(TRUE))->setName(new S('group_as_what'))->setLabel(new S(AUTHENTICATION_AS_A))->setInputType(new S('option'))->setName(new S('as_child'))->setLabel(new S(AUTHENTICATION_GROUP_CHILD))->setInputType(new S('option'))->setName(new S('as_child'))->setLabel(new S(AUTHENTICATION_GROUP_LAST_CHILD))->setInputType(new S('option'))->setName(new S('as_brother'))->setLabel(new S(AUTHENTICATION_GROUP_BROTHER))->setInputType(new S('option'))->setName(new S('as_brother'))->setLabel(new S(AUTHENTICATION_GROUP_NEXT_BROTHER))->setInputType(new S('select'))->setContainerDiv(new B(TRUE))->setName(new S('group_parent_or_bro'))->setLabel(new S(AUTHENTICATION_OF_GROUP)); // Do a foreach on the already existing groups; foreach (self::$objMPTT->mpttGetTree() as $k => $v) { $this->setInputType(new S('option'))->setName($v['name'])->setValue($v['name'])->setLabel(new S(str_repeat('--' . _SP, (int) $v['depth']->toString()) . $v['name'])); } // Execute the form; $this->setFormEndAndExecute(new B(TRUE)); break; case 'groupEdit': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION, ADMIN_ACTION_ID))); // Do validation and error on it if something goes wrong; if ($this->checkPOST(self::$objAuthGroupTableFName)->toBoolean() == TRUE) { // Set some requirements; $objFormHappened = new B(FALSE); if ($this->getPOST(self::$objAuthGroupTableFName)->toLength()->toInt() == 0) { // Check for empty group name, and error on it. We don't allow empty group names; $this->setErrorOnInput(self::$objAuthGroupTableFName, new S(GROUP_NAME_CANNOT_BE_EMPTY)); // Set to memory; $objFormHappened->switchType(); } else { if (self::$objMPTT->mpttCheckIfNodeExists($this->getPOST(self::$objAuthGroupTableFName))->toBoolean() == TRUE) { // Check to see if the group exists, and tell the user the group exists; $this->setErrorOnInput(self::$objAuthGroupTableFName, new S(GROUP_ALREADY_EXISTS)); // Set to memory; $objFormHappened->switchType(); } } // Get AJAX; $this->getAjaxErrors(); } else { // Set some requirements; $objFormHappened = new B(FALSE); } // Do the form, make it happen; $this->setMethod(new S('POST'))->setSQLAction(new S('update'))->setTableName(self::$objAuthGroupTable)->setUpdateField(self::$objAuthGroupTableFId)->setUpdateId($_GET[ADMIN_ACTION_ID]); if ($this->checkPOST(self::$objAuthGroupTableFName)->toBoolean() == TRUE && $objFormHappened->toBoolean() == FALSE) { // Set the URL ... $this->setExtraUpdateData(self::$objAuthGroupTableFSEO, URL::getURLFromString($this->getPOST(self::$objAuthGroupTableFName)))->setRedirect($objURLToGoBack); } // Continue ... $this->setFieldset(new S(AUTHENTICATION_EDIT_GROUP))->setName($objFormToRender)->setAJAXEnabledForm(new B(FALSE))->setInputType(new S('submit'))->setName(new S('submit'))->setValue(new S(AUTHENTICATION_EDIT_GROUP))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setInputInfoMessage($this->getHELP($objFormToRender))->setName(self::$objAuthGroupTableFName)->setLabel(new S(AUTHENTICATION_GROUP_NAME_LABEL))->setContainerDiv(new B(TRUE))->setJSRegExpReplace(new S('[^a-zA-Z0-9 -]'))->setFormEndAndExecute(new B(TRUE)); break; case 'groupErase': // The URL to go back too; $objNodeHasKids = new B(FALSE); $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION, ADMIN_ACTION_ID))); // Check if it's administrator group; if ((int) $_GET[ADMIN_ACTION_ID]->toString() == 1) { // Show the ERRORs; self::$objAdministration->setErrorMessage(new S(CANNOT_ERASE_AUTHENTICATION_GROUP), $objURLToGoBack); } else { // Check to see if there are any zone mappings; if ($this->_Q(_QS('doSELECT')->doToken('%what', new S('*'))->doToken('%table', self::$objAuthZoneMTable)->doToken('%condition', new S('WHERE %objAuthZoneMTableFUGId = "%Id" AND %objAuthZoneMTableFIUG = "Y"'))->doToken('%Id', $_GET[ADMIN_ACTION_ID]))->doCount()->toInt() != 0) { // Do not delete groups with users in them; self::$objAdministration->setErrorMessage(new S(CANNOT_DELETE_MAPPED_GROUPS), $objURLToGoBack); } else { // Do erase the group node from the table; self::$objMPTT->mpttRemoveNode($this->getGroupInfoById($_GET[ADMIN_ACTION_ID], self::$objAuthGroupTableFName)); // Redirect back; $this->setHeaderKey($objURLToGoBack, new S('Location')); } } // BK; break; case 'groupMove': // Set some predefines; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION, ADMIN_ACTION_TO, ADMIN_ACTION_TYPE))); // Get names, as they are unique; $objThatIsMoved = $this->getGroupInfoById($_GET[ADMIN_ACTION_ID], self::$objAuthGroupTableFName); $objWhereToMove = $this->getGroupInfoById($_GET[ADMIN_ACTION_TO], self::$objAuthGroupTableFName); // Get the node subtree, that's move, make sure the node we move to ain't a child; $objMovedNodeSubTree = self::$objMPTT->mpttGetTree($objThatIsMoved); // Memorize; $objIsChild = new B(FALSE); foreach ($objMovedNodeSubTree as $k => $v) { if ($v[self::$objMPTT->objNameOfNode] == $objWhereToMove) { $objIsChild->switchType(); } } // Check if it's a child or not; if ($objIsChild->toBoolean() == TRUE) { // Set an error message; self::$objAdministration->setErrorMessage(new S(AUTHENTICATION_GROUP_MOVED_TO_CHILD), $objURLToGoBack); } else { // Move nodes; self::$objMPTT->mpttMoveNode($objThatIsMoved, $objWhereToMove, $_GET[ADMIN_ACTION_TYPE]); $this->setHeaderKey($objURLToGoBack, new S('Location')); } break; case 'zoneCreate': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(); // Do some work; if ($this->checkPOST()->toBoolean() == TRUE) { # Check that the zone name is not empty! if ($this->getPOST(self::$objAuthZonesTableFName)->toLength()->toInt() == 0) { $this->setErrorOnInput(self::$objAuthZonesTableFName, new S(AUTHENTICATION_ZONE_NAME_CANNOT_BE_EMPTY)); } // Get AJAX; $this->getAjaxErrors(); } // Do the form, make it happen; $this->setMethod(new S('POST'))->setEnctype(new S('multipart/form-data'))->setFieldset(new S(AUTHENTICATION_ADD_ZONE))->setSQLAction(new S('update'))->setTableName(self::$objAuthZonesTable)->setUpdateId(new S('#nextTableAutoIncrement'))->setUpdateField(self::$objAuthZonesTableFId)->setName($objFormToRender)->setRedirect($objURLToGoBack)->setAJAXEnabledForm(new B(FALSE))->setContainerDiv(new B(TRUE))->setInputType(new S('submit'))->setContainerDiv(new B(TRUE))->setValue(new S(AUTHENTICATION_ADD_ZONE))->setInputInfoMessage($this->getHELP($objFormToRender))->setInputType(new S('text'))->setName(self::$objAuthZonesTableFName)->setLabel(new S(AUTHENTICATION_ZONE_NAME))->setContainerDiv(new B(TRUE))->setJSRegExpReplace(new S('[^a-zA-Z0-9 ]'))->setInputType(new S('text'))->setName(self::$objAuthZonesTableFPrice)->setLabel(new S(AUTHENTICATION_ZONE_PRICE))->setContainerDiv(new B(TRUE))->setInputType(new S('textarea'))->setContainerDiv(new B(TRUE))->setName(self::$objAuthZonesTableFDesc)->setLabel(new S(AUTHENTICATION_ZONE_DESCRIPTION))->setTinyMCETextarea(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; case 'zoneEdit': // Set some predefines; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION, ADMIN_ACTION_ID))); // Do some validation, beforehand; if ($this->checkPOST()->toBoolean() == TRUE) { if ($this->checkPOST(self::$objAuthZonesTableFName)->toBoolean() == TRUE) { // Check that the zone name is not empty! if ($this->getPOST(self::$objAuthZonesTableFName)->toLength()->toInt() == 0) { $this->setErrorOnInput(self::$objAuthZonesTableFName, new S(AUTHENTICATION_ZONE_NAME_CANNOT_BE_EMPTY)); } } // Get AJAX; $this->getAjaxErrors(); } // Add some restrictions ... if ($this->_Q(_QS('doSELECT')->doToken('%what', new S('*'))->doToken('%table', self::$objAuthZoneMTable)->doToken('%condition', new S('WHERE %objAuthZoneMTableFZId = "%Id"'))->doToken('%Id', $_GET[ADMIN_ACTION_ID]))->doCount()->toInt() != 0) { // The name should not be changed, due to mapping; $objNameChangeDisabled = new B(TRUE); } else { // The name can be changed; $objNameChangeDisabled = new B(FALSE); } // Do the form, make it happen; $this->setMethod(new S('POST'))->setEnctype(new S('multipart/form-data'))->setFieldset(new S(AUTHENTICATION_EDIT_ZONE))->setSQLAction(new S('update'))->setTableName(self::$objAuthZonesTable)->setUpdateId($_GET[ADMIN_ACTION_ID])->setUpdateField(self::$objAuthZonesTableFId)->setName($objFormToRender)->setRedirect($objURLToGoBack)->setAJAXEnabledForm(new B(FALSE))->setInputType(new S('submit'))->setContainerDiv(new B(TRUE))->setValue(new S(AUTHENTICATION_EDIT_ZONE))->setInputInfoMessage($this->getHELP($objFormToRender))->setInputType(new S('text'))->setName(self::$objAuthZonesTableFName)->setLabel(new S(AUTHENTICATION_ZONE_NAME))->setContainerDiv(new B(TRUE))->setReadOnly($objNameChangeDisabled)->setJSRegExpReplace(new S('[^a-zA-Z0-9 .]'))->setInputType(new S('text'))->setName(self::$objAuthZonesTableFPrice)->setLabel(new S(AUTHENTICATION_ZONE_PRICE))->setContainerDiv(new B(TRUE))->setInputType(new S('textarea'))->setName(self::$objAuthZonesTableFDesc)->setLabel(new S(AUTHENTICATION_ZONE_DESCRIPTION))->setTinyMCETextarea(new B(TRUE))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; case 'zoneErase': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION, ADMIN_ACTION_ID))); // Check to see if there are any zone mappings, for the current zone; $objSQLCondition = new S('WHERE %s = %i'); // Erase it; $this->_Q(_QS('doDELETE')->doToken('%table', self::$objAuthZonesTable)->doToken('%condition', new S('%objAuthZonesTableFId = "%Id"'))->doToken('%Id', $_GET[ADMIN_ACTION_ID])); // Redirect the user back; $this->setHeaderKey($objURLToGoBack, new S('Location')); break; case 'zoneMappingCreateForGroups': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(); // Do the form, make it happen; $this->setMethod(new S('POST'))->setEnctype(new S('multipart/form-data'))->setFieldset(new S(AUTHENTICATION_ADD_ACL))->setSQLAction(new S('update'))->setTableName(self::$objAuthZoneMTable)->setUpdateId(new S('#nextTableAutoIncrement'))->setUpdateField(self::$objAuthZoneMTableFId)->setExtraUpdateData(self::$objAuthZoneMTableFIUG, new S('Y'))->setName($objFormToRender)->setRedirect($objURLToGoBack)->setInputType(new S('submit'))->setValue(new S(AUTHENTICATION_ADD_ACL))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('select'))->setContainerDiv(new B(TRUE))->setName(self::$objAuthZoneMTableFUGId)->setLabel(new S(AUTHENTICATION_ACL_ENTITY)); // Get the groups; foreach (self::$objMPTT->mpttGetTree() as $k => $v) { $this->setInputType(new S('option'))->setName($v[self::$objAuthGroupTableFId])->setValue($v[self::$objAuthGroupTableFId])->setLabel(new S(str_repeat('--' . _SP, (int) $v['depth']->toString()) . $v[self::$objAuthGroupTableFName])); } // Continue; $this->setInputType(new S('select'))->setContainerDiv(new B(TRUE))->setName(self::$objAuthZoneMTableFZId)->setLabel(new S(AUTHENTICATION_ZONE_NAME)); // Get the zones; foreach ($this->getZones(NULL) as $k => $v) { $this->setInputType(new S('option'))->setName($v[self::$objAuthZonesTableFId])->setValue($v[self::$objAuthZonesTableFId])->setLabel(new S(str_repeat('--' . _SP, (int) $v['depth']->toString()) . $v[self::$objAuthZonesTableFName])); } // Continue; $this->setInputType(new S('select'))->setContainerDiv(new B(TRUE))->setName(self::$objAuthZoneMTableFAorD)->setLabel(new S(AUTHENTICATION_ACL_ACCESS_TYPE))->setInputType(new S('option'))->setName(new S('deny_or_allow_allow'))->setValue(new S('A'))->setLabel(new S(AUTHENTICATION_ACL_ALLOWED))->setInputType(new S('option'))->setName(new S('deny_or_allow_deny'))->setValue(new S('D'))->setLabel(new S(AUTHENTICATION_ACL_DENIED))->setFormEndAndExecute(new B(TRUE)); break; case 'zoneMappingCreateForUsers': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(); // Do the form, make it happen; $this->setMethod(new S('POST'))->setEnctype(new S('multipart/form-data'))->setFieldset(new S(AUTHENTICATION_ADD_ACL))->setSQLAction(new S('update'))->setTableName(self::$objAuthZoneMTable)->setUpdateId(new S('#nextTableAutoIncrement'))->setUpdateField(self::$objAuthZoneMTableFId)->setExtraUpdateData(self::$objAuthZoneMTableFIUG, new S('N'))->setName($objFormToRender)->setRedirect($objURLToGoBack)->setInputType(new S('submit'))->setInputInfoMessage($this->getHELP($objFormToRender))->setValue(new S(AUTHENTICATION_ADD_ACL))->setContainerDiv(new B(TRUE))->setInputType(new S('select'))->setContainerDiv(new B(TRUE))->setName(self::$objAuthZoneMTableFUGId)->setLabel(new S(AUTHENTICATION_ACL_ENTITY)); // Get the users; foreach ($this->getUsers() as $k => $v) { $this->setInputType(new S('option'))->setName($v[self::$objAuthUsersTableFId])->setValue($v[self::$objAuthUsersTableFId])->setLabel($v[self::$objAuthUsersTableFUName]); } // Continue; $this->setInputType(new S('select'))->setContainerDiv(new B(TRUE))->setName(self::$objAuthZoneMTableFZId)->setLabel(new S(AUTHENTICATION_ZONE_NAME)); // Get zones; foreach ($this->getZones(NULL) as $k => $v) { $this->setInputType(new S('option'))->setName($v[self::$objAuthZonesTableFId])->setValue($v[self::$objAuthZonesTableFId])->setLabel(new S(str_repeat('--' . _SP, (int) $v['depth']->toString()) . $v[self::$objAuthZonesTableFName])); } // Continue; $this->setInputType(new S('select'))->setContainerDiv(new B(TRUE))->setName(self::$objAuthZoneMTableFAorD)->setLabel(new S(AUTHENTICATION_ACL_ACCESS_TYPE))->setInputType(new S('option'))->setName(new S('deny_or_allow_allow'))->setValue(new S('A'))->setLabel(new S(AUTHENTICATION_ACL_ALLOWED))->setInputType(new S('option'))->setName(new S('deny_or_allow_deny'))->setValue(new S('D'))->setLabel(new S(AUTHENTICATION_ACL_DENIED))->setFormEndAndExecute(new B(TRUE)); break; case 'zoneMappingEdit': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION, ADMIN_ACTION_ID))); // Do the form, make it happen; $this->setMethod(new S('POST'))->setEnctype(new S('multipart/form-data'))->setFieldset(new S(AUTHENTICATION_EDIT_ACL))->setSQLAction(new S('update'))->setTableName(self::$objAuthZoneMTable)->setUpdateId($_GET[ADMIN_ACTION_ID])->setUpdateField(self::$objAuthZoneMTableFId)->setName($objFormToRender)->setRedirect($objURLToGoBack)->setInputType(new S('submit'))->setValue(new S(AUTHENTICATION_EDIT_ACL))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('select'))->setContainerDiv(new B(TRUE))->setName(self::$objAuthZoneMTableFAorD)->setLabel(new S(AUTHENTICATION_ACL_ACCESS_TYPE))->setInputType(new S('option'))->setName(new S('deny_or_allow_allow'))->setValue(new S('A'))->setLabel(new S(AUTHENTICATION_ACL_ALLOWED))->setInputType(new S('option'))->setName(new S('deny_or_allow_deny'))->setValue(new S('D'))->setLabel(new S(AUTHENTICATION_ACL_DENIED))->setFormEndAndExecute(new B(TRUE)); break; case 'zoneMappingErase': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION, ADMIN_ACTION_ID))); // Erase it; $this->_Q(_QS('doDELETE')->doToken('%table', self::$objAuthZoneMTable)->doToken('%condition', new S('%objAuthZoneMTableFId = "%Id"'))->doToken('%Id', $_GET[ADMIN_ACTION_ID])); // Do a redirect, and get the user back where he belongs; $this->setHeaderKey($objURLToGoBack, new S('Location')); break; case 'configurationEdit': // Set some requirements; $objURLToGoBack = URL::rewriteURL(); // Do form validation; if ($this->checkPOST()->toBoolean() == TRUE) { // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION)), new A(array($this->getPOST(new S('what'))))); } // Do the form, make it happen; $this->setMethod(new S('POST'))->setFieldset(new S(AUTHENTICATION_MANAGE_CONFIGURATION))->setName($objFormToRender)->setRedirect($objURLToGoBack)->setInputType(new S('submit'))->setValue(new S('Do'))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('select'))->setName(new S('what'))->setLabel(new S('Choose'))->setContainerDiv(new B(TRUE))->setInputType(new S('option'))->setName(new S('configurationEdit-register_page_content'))->setValue(new S('configurationEdit-register_page_content'))->setLabel(new S(AUTHENTICATION_REG_PAGE_FORM_CONTENT))->setContainerDiv(new B(TRUE))->setInputType(new S('option'))->setName(new S('configurationEdit-register_ok_page_content'))->setValue(new S('configurationEdit-register_ok_page_content'))->setLabel(new S(AUTHENTICATION_REG_PAGE_FORM_SUCCESS_CONTENT))->setContainerDiv(new B(TRUE))->setInputType(new S('option'))->setName(new S('configurationEdit-activation_page_content'))->setValue(new S('configurationEdit-activation_page_content'))->setLabel(new S(AUTHENTICATION_REG_PAGE_FORM_ACTIVATE_CONTENT))->setInputType(new S('option'))->setName(new S('configurationEdit-activation_not_ok_page_content'))->setValue(new S('configurationEdit-activation_not_ok_page_content'))->setLabel(new S(AUTHENTICATION_REG_PAGE_FORM_ACTIVATE_NOTOK))->setFormEndAndExecute(new B(TRUE)); break; case 'configurationEdit-register_page_content': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION))); // Do some work; if ($this->checkPOST()->toBoolean() == TRUE) { foreach ($this->getPOST() as $k => $v) { $this->setConfigKey(new S($k), $v); } } // Do the form, make it happen; $this->setMethod(new S('POST'))->setFieldset(new S(AUTHENTICATION_MANAGE_CONFIGURATION))->setName($objFormToRender)->setRedirect($objURLToGoBack)->setInputType(new S('submit'))->setValue(new S(AUTHENTICATION_MANAGE_CONFIGURATION))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('textarea'))->setName(new S('authentication_page_register_message'))->setLabel(new S(AUTHENTICATION_CONFIG_DEFAULT))->setTinyMCETextarea(new B(TRUE))->setValue($this->getConfigKey(new S('authentication_page_register_message')))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; case 'configurationEdit-register_ok_page_content': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION))); // Do some work; if ($this->checkPOST()->toBoolean() == TRUE) { foreach ($this->getPOST() as $k => $v) { $this->setConfigKey(new S($k), $v); } } // Do the form, make it happen; $this->setMethod(new S('POST'))->setFieldset(new S(AUTHENTICATION_MANAGE_CONFIGURATION))->setName($objFormToRender)->setRedirect($objURLToGoBack)->setInputType(new S('submit'))->setValue(new S(AUTHENTICATION_MANAGE_CONFIGURATION))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('textarea'))->setName(new S('authentication_page_register_ok_message'))->setLabel(new S(AUTHENTICATION_CONFIG_DEFAULT))->setTinyMCETextarea(new B(TRUE))->setValue($this->getConfigKey(new S('authentication_page_register_ok_message')))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; case 'configurationEdit-activation_page_content': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION))); // Do some work; if ($this->checkPOST()->toBoolean() == TRUE) { foreach ($this->getPOST() as $k => $v) { $this->setConfigKey(new S($k), $v); } } // Do the form, make it happen; $this->setMethod(new S('POST'))->setFieldset(new S(AUTHENTICATION_MANAGE_CONFIGURATION))->setName($objFormToRender)->setRedirect($objURLToGoBack)->setInputType(new S('submit'))->setValue(new S(AUTHENTICATION_MANAGE_CONFIGURATION))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('textarea'))->setName(new S('authentication_page_activation_ok_message'))->setLabel(new S(AUTHENTICATION_CONFIG_DEFAULT))->setTinyMCETextarea(new B(TRUE))->setValue($this->getConfigKey(new S('authentication_page_activation_ok_message')))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; case 'configurationEdit-activation_not_ok_page_content': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION))); // Do some work; if ($this->checkPOST()->toBoolean() == TRUE) { foreach ($this->getPOST() as $k => $v) { $this->setConfigKey(new S($k), $v); } } // Do the form, make it happen; $this->setMethod(new S('POST'))->setFieldset(new S(AUTHENTICATION_MANAGE_CONFIGURATION))->setName($objFormToRender)->setRedirect($objURLToGoBack)->setInputType(new S('submit'))->setValue(new S(AUTHENTICATION_MANAGE_CONFIGURATION))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('textarea'))->setName(new S('authentication_page_activation_not_ok_message'))->setLabel(new S(AUTHENTICATION_CONFIG_DEFAULT))->setTinyMCETextarea(new B(TRUE))->setValue($this->getConfigKey(new S('authentication_page_activation_not_ok_message')))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; } }
/** * Will shift left and right values in a range; * * This method will update left and right values that are in a given range. This method is used to do updates on adding new * nodes or moving/deletion of those nodes; * * @param S $objFirst Where to start; * @param S $objLast Where to end; * @param S $objDelta What delta to use for size; */ private function shiftRLRange(S $objFirst, S $objLast, S $objDelta) { $this->_Q(_QS('doUPDATE')->doToken('%table', $this->objTable)->doToken('%condition', new S('%objLeftyField = %objLeftyField + %dId WHERE %objLeftyField >= %fId AND %objLeftyField <= %eId'))->doToken('%dId', $objDelta)->doToken('%fId', $objFirst)->doToken('%eId', $objLast)); $this->_Q(_QS('doUPDATE')->doToken('%table', $this->objTable)->doToken('%condition', new S('%objRightField = %objRightField + %dId WHERE %objRightField >= %fId AND %objRightField <= %eId'))->doToken('%dId', $objDelta)->doToken('%fId', $objFirst)->doToken('%eId', $objLast)); }
/** * Will render a specified form, the name of the form given by the first parameter; * * This method will render one of the forms for our object, invoked by giving the proper form identifier to the current form. * We have chosen this method of invoking forms, because we just had too many this->renderSomethingMethod (), which really had * an impact on code massiveness. Also, having code organized in switch/case statements leads us to be able to share common * settings between different forms, as we've done with the methods defined in the __CALL method above; * * For example, if we wanted to share some common configuration between a create and an edit form, we could have introduced * two switches in this method, one that would have set the common options, and the second, would have just passed through * again, and get the already set configuration options, using them. This means that if we needed to change behavior of * some interconnected forms, that would mean modifying the needed code one place only, which is a big advantage over * having separated methods for each form. Maybe if we extended this object, you guys could understand the functionality best; * * @param string $objFormToRender The name of the form to render; * @return mixed Depends on the rendered form if it returns something or not; */ public function renderForm(S $objFormToRender, A $objFA = NULL) { // Make them defaults ... if ($objFA == NULL) { $objFA = new A(); } // Do a switch ... switch ($objFormToRender) { case 'textSearch': // Get some predefines; if (isset($_GET[ADMIN_ACTION_BY])) { $objSearchBy = $_GET[ADMIN_ACTION_BY]; } else { $objSearchBy = new S(); } if (isset($_GET[ADMIN_ACTION_SEARCH])) { $objSearchWas = $_GET[ADMIN_ACTION_SEARCH]; } else { $objSearchWas = new S(); } // Do some work; if ($this->checkPOST(new S('search_submit'))->toBoolean() == TRUE) { if ($this->getPOST(new S('search_by'))->toLength()->toInt() == 0) { if (isset($_GET[ADMIN_ACTION_SEARCH])) { // Erase search terms ... $this->setHeaderKey(URL::rewriteURL(new A(array(ADMIN_ACTION_SEARCH, ADMIN_ACTION_BY))), new S('Location')); } // Set an input error; $this->setErrorOnInput(new S('search_by'), new S(ARTICLE_SEARCH_FIELD_IS_EMPTY)); // Unset the post ... $this->unsetPOST(); } else { // Get what to search and where ... $objWhatToSearch = $this->getPOST(new S('search_by')); $objWhereToSearch = $this->getPOST(new S('search_field')); // And go there ... $this->setHeaderKey(URL::rewriteURL(new A(array(ADMIN_ACTION_SEARCH, ADMIN_ACTION_BY)), new A(array($objWhatToSearch, $objWhereToSearch))), new S('Location')); } } // Check the option that has been selected; $objWasSelected = new A(array(new B($objSearchBy == TEXTS_SEARCH_TITLE ? TRUE : FALSE), new B($objSearchBy == TEXTS_SEARCH_CONTENT ? TRUE : FALSE))); // Do the form, make it happen; $this->setMethod(new S('POST'))->setEnctype(new S('multipart/form-data'))->setFieldset(new S(TEXTS_SEARCH_BY))->setName($objFormToRender)->setInputType(new S('text'))->setInputInfoMessage($this->getHELP($objFormToRender))->setName(new S('search_by'))->setvalue($objSearchWas)->setLabel(new S(TEXTS_SEARCH_BY))->setJSRegExpReplace(new S('[^a-zA-Z0-9 -]'))->setContainerDiv(new B(TRUE))->setInputType(new S('select'))->setName(new S('search_field'))->setContainerDiv(new B(TRUE))->setLabel(new S(TEXTS_SEARCH_IN))->setInputType(new S('option'))->setName(new S('article_title'))->setValue(new S(TEXTS_SEARCH_TITLE))->setLabel(new S(TEXTS_SEARCH_TITLE))->setSelected($objWasSelected[0])->setInputType(new S('option'))->setName(new S('article_content'))->setValue(new S(TEXTS_SEARCH_CONTENT))->setLabel(new S(TEXTS_SEARCH_CONTENT))->setSelected($objWasSelected[1])->setInputType(new S('submit'))->setContainerDiv(new B(TRUE))->setValue(new S(TEXTS_SEARCH_BY))->setName(new S('search_submit'))->setFormEndAndExecute(new B(TRUE)); break; case 'textCreate': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(); // Do some work; if ($this->checkPOST(self::$objTextTableFTitle)->toBoolean() == TRUE) { if ($this->getPOST(self::$objTextTableFTitle)->toLength()->toInt() == 0) { $this->setErrorOnInput(self::$objTextTableFTitle, new S(TEXTS_TITLE_CANNOT_BE_EMPTY)); } else { // Set some requirements ... $objToCheck = $this->getPOST(self::$objTextTableFTitle); // Check title is unique; if ($this->checkTextTitleIsUnique($objToCheck)->toBoolean() == FALSE) { $this->setErrorOnInput(self::$objTextTableFTitle, new S(TEXTS_TITLE_MUST_BE_UNIQUE)); } // Check URL is unique; if ($this->checkTextURLIsUnique(URL::getURLFromString(clone $objToCheck))->toBoolean() == FALSE) { $this->setErrorOnInput(self::$objTextTableFTitle, new S(TEXTS_URL_MUST_BE_UNIQUE)); } } if ($this->getPOST(self::$objTextTableFContent)->toLength()->toInt() == 0) { $this->setErrorOnInput(self::$objTextTableFContent, new S(TEXTS_CONTENT_CANNOT_BE_EMPTY)); } } // Get AJAX; $this->getAjaxErrors(); // Do the form, make it happen; $this->setMethod(new S('POST'))->setName($objFormToRender)->setAJAXEnabledForm(new B(FALSE))->setFieldset(new S(TEXTS_ADD_ARTICLE))->setRedirect($objURLToGoBack)->setSQLAction(new S('update'))->setTableName(self::$objTextTable)->setUpdateId(new S('#nextTableAutoIncrement'))->setUpdateField(self::$objTextTableFId); if ($this->checkPOST(self::$objTextTableFTitle)->toBoolean() == TRUE) { $this->setExtraUpdateData(self::$objTextTableFSEO, URL::getURLFromString($this->getPOST(self::$objTextTableFTitle))); } // ONLY if != BIG-MAN; if ((int) $this->ATH->getCurrentUserInfoById(Authentication::$objAuthUsersTableFId)->toString() != 1) { $this->setExtraUpdateData(self::$objTextTableAuthorId, $this->ATH->getCurrentUserInfoById(Authentication::$objAuthUsersTableFId)); } // Add the SEO ... $this->setExtraUpdateData(self::$objTextTableFDatePublished, new S((string) $_SERVER['REQUEST_TIME']))->setInputType(new S('submit'))->setValue(new S(TEXTS_ADD_ARTICLE))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objTextTableFTags)->setLabel(new S(TEXTS_TAGS))->setJSRegExpReplace(new S(self::REGEXP_JS_TAGS))->setContainerDiv(new B(TRUE)); // If we're the BIG MAN, we can set the author of an entry; if ((int) $this->ATH->getCurrentUserInfoById(Authentication::$objAuthUsersTableFId)->toString() == 1) { $this->setInputType(new S('select'))->setName(self::$objTextTableFAuthorId)->setLabel(new S(TEXTS_AUTHOR))->setContainerDiv(new B(TRUE)); // Categories ... foreach ($this->ATH->getUsers() as $k => $v) { $this->setInputType(new S('option'))->setName($v[Authentication::$objAuthUsersTableFId])->setValue($v[Authentication::$objAuthUsersTableFId])->setLabel($v[Authentication::$objAuthUsersTableFUName]); } } $this->setInputType(new S('select'))->setLabel(new S(TEXTS_CATEGORY_NAME_LABEL))->setName(self::$objTextTableFCategoryId)->setContainerDiv(new B(TRUE)); // Categories; foreach (self::$objMPTT->mpttGetTree() as $k => $v) { $this->setInputType(new S('option'))->setName($v[self::$objCategoryTableFId])->setValue($v[self::$objCategoryTableFId])->setLabel(new S(str_repeat('--' . _SP, (int) $v['depth']->toString()) . $v[self::$objCategoryTableFName])); } // Continue; $this->setInputType(new S('select'))->setName(self::$objTextTableFCanComment)->setLabel(new S(TEXTS_CAN_COMMENT))->setContainerDiv(new B(TRUE))->setInputType(new S('option'))->setName(new S('no'))->setValue(new S('N'))->setLabel(new S(TEXTS_CAN_COMMENT_NO))->setInputType(new S('option'))->setName(new S('yes'))->setValue(new S('Y'))->setLabel(new S(TEXTS_CAN_COMMENT_YES))->setInputType(new S('text'))->setName(self::$objTextTableFTitle)->setLabel(new S(TEXTS_TITLE))->setJSRegExpReplace(new S(self::REGEXP_JS_TITLE))->setContainerDiv(new B(TRUE))->setInputType(new S('textarea'))->setName(self::$objTextTableFContent)->setLabel(new S(TEXTS_CONTENT))->setTinyMCETextarea(new B(TRUE))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; case 'textEdit': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION, ADMIN_ACTION_ID))); // Do some work; if ($this->checkPOST()->toBoolean() == TRUE) { if ($this->getPOST(self::$objTextTableFTitle)->toLength()->toInt() == 0) { $this->setErrorOnInput(self::$objTextTableFTitle, new S(TEXTS_TITLE_CANNOT_BE_EMPTY)); } if ($this->getPOST(self::$objTextTableFContent)->toLength()->toInt() == 0) { $this->setErrorOnInput(self::$objTextTableFContent, new S(TEXTS_CONTENT_CANNOT_BE_EMPTY)); } } // Get AJAX; $this->getAjaxErrors(); // Do the form, make it happen; $this->setMethod(new S('POST'))->setFieldset(new S(TEXTS_EDIT_ARTICLE))->setAJAXEnabledForm(new B(FALSE))->setRedirect($objURLToGoBack)->setSQLAction(new S('update'))->setTableName(self::$objTextTable)->setUpdateId($_GET[ADMIN_ACTION_ID])->setUpdateField(self::$objTextTableFId)->setName($objFormToRender)->setExtraUpdateData(self::$objTextTableFDateUpdated, new S((string) $_SERVER['REQUEST_TIME']))->setInputType(new S('submit'))->setValue(new S(TEXTS_EDIT_ARTICLE))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objTextTableFTags)->setLabel(new S(TEXTS_TAGS))->setJSRegExpReplace(new S(self::REGEXP_JS_TAGS)); // Add the SEO ... if ($this->checkPOST(self::$objTextTableFTitle)->toBoolean() == TRUE) { $this->setExtraUpdateData(self::$objTextTableFSEO, URL::getURLFromString($this->getPOST(self::$objTextTableFTitle))); } // If we're the BIG MAN, we can set the author of an entry; if ((int) $this->ATH->getCurrentUserInfoById(Authentication::$objAuthUsersTableFId)->toString() == 1) { $this->setInputType(new S('select'))->setName(self::$objTextTableFAuthorId)->setLabel(new S(TEXTS_AUTHOR))->setContainerDiv(new B(TRUE)); // Users ... foreach ($this->ATH->getUsers() as $k => $v) { $this->setInputType(new S('option'))->setName($v[Authentication::$objAuthUsersTableFId])->setValue($v[Authentication::$objAuthUsersTableFId])->setLabel($v[Authentication::$objAuthUsersTableFUName]); } } $this->setContainerDiv(new B(TRUE))->setInputType(new S('select'))->setName(self::$objTextTableFCategoryId)->setLabel(new S(TEXTS_CATEGORY_NAME_LABEL))->setContainerDiv(new B(TRUE)); // Categories ... foreach (self::$objMPTT->mpttGetTree() as $k => $v) { $this->setInputType(new S('option'))->setName($v[self::$objCategoryTableFId])->setValue($v[self::$objCategoryTableFId])->setLabel(new S(str_repeat('--' . _SP, (int) $v['depth']->toString()) . $v[self::$objCategoryTableFName])); } // Continue; $this->setInputType(new S('select'))->setName(self::$objTextTableFCanComment)->setLabel(new S(TEXTS_CAN_COMMENT))->setContainerDiv(new B(TRUE))->setInputType(new S('option'))->setName(new S('no'))->setValue(new S('N'))->setLabel(new S(TEXTS_CAN_COMMENT_NO))->setInputType(new S('option'))->setName(new S('yes'))->setValue(new S('Y'))->setLabel(new S(TEXTS_CAN_COMMENT_YES))->setInputType(new S('text'))->setName(self::$objTextTableFTitle)->setLabel(new S(TEXTS_TITLE))->setJSRegExpReplace(new S(self::REGEXP_JS_TITLE))->setContainerDiv(new B(TRUE))->setInputType(new S('textarea'))->setName(self::$objTextTableFContent)->setLabel(new S(TEXTS_CONTENT))->setTinyMCETextarea(new B(TRUE))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; case 'textErase': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION, ADMIN_ACTION_ID))); // Do erase it ... $this->_Q(_QS('doDELETE')->doToken('%table', self::$objTextTable)->doToken('%condition', new S('%objTextTableFId = "%Id"'))->doToken('%Id', $_GET[ADMIN_ACTION_ID])); // And ALL associated comments ... $this->_Q(_QS('doDELETE')->doToken('%table', self::$objCommentsTable)->doToken('%condition', new S('%objCommentsTableFTextId = "%Id"'))->doToken('%Id', $_GET[ADMIN_ACTION_ID])); // Do a redirect, and get the user back where he belongs; $this->setHeaderKey($objURLToGoBack, new S('Location')); break; case 'commentEdit': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION, ADMIN_ACTION_ID))); // Do the form, make it happen; $this->setMethod(new S('POST'))->setFieldset(new S(TEXTS_EDIT_COMMENT))->setAJAXEnabledForm(new B(FALSE))->setRedirect($objURLToGoBack)->setSQLAction(new S('update'))->setTableName(self::$objCommentsTable)->setUpdateId($_GET[ADMIN_ACTION_ID])->setUpdateField(self::$objCommentsTableFId)->setName($objFormToRender)->setInputType(new S('submit'))->setValue(new S(TEXTS_EDIT_COMMENT))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('select'))->setName(self::$objCommentsTableFApproved)->setLabel(new S(TEXTS_COMMENT_APPROVED))->setContainerDiv(new B(TRUE))->setInputType(new S('option'))->setName(new S('no'))->setValue(new S('N'))->setLabel(new S(TEXTS_CAN_COMMENT_NO))->setInputType(new S('option'))->setName(new S('yes'))->setValue(new S('Y'))->setLabel(new S(TEXTS_CAN_COMMENT_YES))->setInputType(new S('textarea'))->setName(self::$objCommentsTableFComment)->setLabel(new S(TEXTS_COMMENT))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; case 'commentErase': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION, ADMIN_ACTION_ID))); // Do erase it ... $this->_Q(_QS('doDELETE')->doToken('%table', self::$objCommentsTable)->doToken('%condition', new S('%objCommentsTableFId = "%Id"'))->doToken('%Id', $_GET[ADMIN_ACTION_ID])); // Do a redirect, and get the user back where he belongs; $this->setHeaderKey($objURLToGoBack, new S('Location')); break; case 'textCategoryCreate': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(); // Do some work ... if ($this->checkPOST(new S('categories_show_all'))->toBoolean() == TRUE) { // Redirect to proper ... $this->setHeaderKey(URL::rewriteURL(new A(array(ADMIN_SHOW_ALL)), new A(array('1'))), new S('Location')); } // Do some work; if ($this->checkPOST(new S('add_category_submit'))->toBoolean() == TRUE) { // Set some requirements; $objFormHappened = new B(FALSE); if ($this->getPOST(new S('add_category'))->toLength()->toInt() == 0) { // Check for empty group name, and error on it; $this->setErrorOnInput(new S('add_category'), new S(TEXTS_CATEGORY_NAME_CANNOT_BE_EMPTY)); // Set to memory; $objFormHappened->switchType(); } else { if (self::$objMPTT->mpttCheckIfNodeExists($this->getPOST(new S('add_category')))->toBoolean() == TRUE) { // Check to see if the group exists; $this->setErrorOnInput(new S('add_category'), new S(TEXTS_CATEGORY_ALREADY_EXISTS)); // Set to memory; $objFormHappened->switchType(); } } // Get AJAX; $this->getAjaxErrors(); if ($objFormHappened->toBoolean() == FALSE) { // Remember if we should add it as a brother or child; $objAddNodeAS = NULL; switch ($this->getPOST(new S('add_category_as_what'))) { case TEXTS_CATEGORY_CHILD: $objAddNodeAS = new S((string) MPTT::FIRST_CHILD); break; case TEXTS_CATEGORY_LAST_CHILD: $objAddNodeAS = new S((string) MPTT::LAST_CHILD); break; case TEXTS_CATEGORY_BROTHER: $objAddNodeAS = new S((string) MPTT::PREVIOUS_BROTHER); break; case TEXTS_CATEGORY_NEXT_BROTHER: $objAddNodeAS = new S((string) MPTT::NEXT_BROTHER); break; } // Add the node; self::$objMPTT->mpttAddNode($this->getPOST(new S('add_category')), $this->getPOST(new S('add_category_parent_or_bro')), $objAddNodeAS); // Redirect back; $this->setHeaderKey($objURLToGoBack, new S('Location')); } } // Do the form, make it happen; $this->setMethod(new S('POST'))->setFieldset(new S(TEXTS_ADD_CATEGORY))->setName($objFormToRender)->setAJAXEnabledForm(new B(FALSE))->setInputType(new S('submit'))->setName(new S('categories_show_all'))->setValue(new S(TEXTS_SHOW_ALL_CATEGORIES))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('submit'))->setContainerDiv(new B(TRUE))->setName(new S('add_category_submit'))->setValue(new S(TEXTS_ADD_CATEGORY))->setInputType(new S('text'))->setContainerDiv(new B(TRUE))->setName(new S('add_category'))->setLabel(new S(TEXTS_CATEGORY_NAME_LABEL))->setJSRegExpReplace(new S(self::REGEXP_JS_CATEGORY))->setInputType(new S('select'))->setContainerDiv(new B(TRUE))->setName(new S('add_category_as_what'))->setLabel(new S(TEXTS_AS_A))->setInputType(new S('option'))->setName(new S('as_child'))->setLabel(new S(TEXTS_CATEGORY_CHILD))->setInputType(new S('option'))->setName(new S('as_child'))->setLabel(new S(TEXTS_CATEGORY_LAST_CHILD))->setInputType(new S('option'))->setName(new S('as_brother'))->setLabel(new S(TEXTS_CATEGORY_BROTHER))->setInputType(new S('option'))->setName(new S('as_brother'))->setLabel(new S(TEXTS_CATEGORY_NEXT_BROTHER))->setInputType(new S('select'))->setContainerDiv(new B(TRUE))->setName(new S('add_category_parent_or_bro'))->setLabel(new S(TEXTS_OF_CATEGORY)); // Categories ... foreach (self::$objMPTT->mpttGetTree() as $k => $v) { $this->setInputType(new S('option'))->setName($v[self::$objCategoryTableFName])->setValue($v[self::$objCategoryTableFName])->setLabel(new S(str_repeat('--' . _SP, (int) $v['depth']->toString()) . $v[self::$objCategoryTableFName])); } // Execute the form; $this->setFormEndAndExecute(new B(TRUE)); break; case 'textCategoryEdit': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION, ADMIN_ACTION_ID))); // Do some work; if ($this->checkPOST()->toBoolean() == TRUE) { // Set some requirements; $objFormHappened = new B(FALSE); if ($this->getPOST(self::$objCategoryTableFName)->toLength()->toInt() == 0) { // Check for empty group name, and error on it; $this->setErrorOnInput(self::$objCategoryTableFName, new S(CATEGORY_NAME_CANNOT_BE_EMPTY)); // Set to memory; $objFormHappened->switchType(); } else { if (self::$objMPTT->mpttCheckIfNodeExists($this->getPOST(self::$objCategoryTableFName))->toBoolean() == TRUE) { // Check to see if the group exists; $this->setErrorOnInput(self::$objCategoryTableFName, new S(TEXTS_CATEGORY_ALREADY_EXISTS)); // Set to memory; $objFormHappened->switchType(); } } // Get AJAX; $this->getAjaxErrors(); } else { // Do nothing ... $objFormHappened = new B(TRUE); } // Do the form, make it happen; $this->setMethod(new S('POST'))->setSQLAction(new S('update'))->setTableName(self::$objCategoryTable)->setUpdateId($_GET[ADMIN_ACTION_ID])->setUpdateField(self::$objCategoryTableFId)->setFieldset(new S(TEXTS_EDIT_CATEGORY)); if ($objFormHappened->toBoolean() == FALSE) { $this->setRedirect($objURLToGoBack, new S('Location')); } $this->setName($objFormToRender)->setAJAXEnabledForm(new B(FALSE)); // Add the SEO ... if ($this->checkPOST(self::$objCategoryTableFName)->toBoolean() == TRUE) { $this->setExtraUpdateData(self::$objCategoryTableFSEO, URL::getURLFromString($this->getPOST(self::$objCategoryTableFName))); } $this->setInputType(new S('submit'))->setName(new S('edit_category_submit'))->setValue(new S(TEXTS_EDIT_CATEGORY))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objCategoryTableFName)->setLabel(new S(TEXTS_CATEGORY_NAME_LABEL))->setJSRegExpReplace(new S(self::REGEXP_JS_CATEGORY))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; case 'textCategoryErase': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION, ADMIN_ACTION_ID))); // Memorize if it has kids; $objNodeHasKids = new B(FALSE); if ($this->getTextCount(_S('WHERE %objTextTableFCategoryId = "%Id"')->doToken('%Id', $_GET[ADMIN_ACTION_ID]))->toInt() != 0) { // Set an error message; self::$objAdministration->setErrorMessage(new S(TEXTS_CANNOT_DELETE_CATEGORY_WA), $objURLToGoBack); } else { // Do erase the group node from the table; self::$objMPTT->mpttRemoveNode($this->getCategoryInfoById($_GET[ADMIN_ACTION_ID], self::$objCategoryTableFName)); // Do a redirect, and get the user back where he belongs; $this->setHeaderKey($objURLToGoBack, new S('Location')); } break; case 'textCategoryMove': // Set some predefines; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION, ADMIN_ACTION_TO, ADMIN_ACTION_TYPE))); // Get names, as they are unique; $objThatIsMoved = $this->getCategoryInfoById($_GET[ADMIN_ACTION_ID], self::$objCategoryTableFName); $objWhereToMove = $this->getCategoryInfoById($_GET[ADMIN_ACTION_TO], self::$objCategoryTableFName); $objMovedNodeSubTree = self::$objMPTT->mpttGetTree($objThatIsMoved); // Memorize; $objIsChild = new B(FALSE); foreach ($objMovedNodeSubTree as $k => $v) { if ($v[self::$objMPTT->objNameOfNode] == $objWhereToMove) { $objIsChild->switchType(); } } // Check if it's a child or not; if ($objIsChild->toBoolean() == TRUE) { // Set an error message; self::$objAdministration->setErrorMessage(new S(TEXTS_CATEGORY_MOVED_TO_CHILD), $objURLToGoBack); } else { // Move nodes; self::$objMPTT->mpttMoveNode($objThatIsMoved, $objWhereToMove, $_GET[ADMIN_ACTION_TYPE]); $this->setHeaderKey($objURLToGoBack, new S('Location')); } // Break out ... break; case 'categoryMoveOperation': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_SUBPAGE)), new A(array(MANAGE_TEXTS))); // Do some work; $this->checkPOST()->toBoolean() == TRUE ? $objOLDCategoryId = $this->getPOST(new S('old_category_id')) : ($objOLDCategoryId = new S('0')); // Do the form, make it happen; $this->setMethod(new S('POST'))->setFieldset(new S(TEXTS_MOVE_ARTICLE))->setSQLAction(new S('update'))->setTableName(self::$objTextTable)->setUpdateField(self::$objTextTableFId)->setUpdateWhere($this->doModuleToken(_S('%objTextTableFCategoryId = "%Id"')->doToken('%Id', $objOLDCategoryId)))->setName($objFormToRender)->setRedirect($objURLToGoBack)->setInputType(new S('submit'))->setValue(new S(TEXTS_MOVE_ARTICLE))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('select'))->setName(new S('old_category_id'))->setLabel(new S(TEXTS_OLD_CATEGORY))->setContainerDiv(new B(TRUE)); // Categories ... foreach (self::$objMPTT->mpttGetTree() as $k => $v) { $this->setInputType(new S('option'))->setName($v[self::$objMPTT->objIdField])->setValue($v[self::$objMPTT->objIdField])->setLabel(new S(str_repeat('--' . _SP, (int) $v['depth']->toString()) . $v[self::$objMPTT->objNameOfNode])); } // Continue ... $this->setInputType(new S('select'))->setName(self::$objTextTableFCategoryId)->setLabel(new S(TEXTS_NEW_CATEGORY))->setContainerDiv(new B(TRUE)); // Categories, again ... foreach (self::$objMPTT->mpttGetTree() as $k => $v) { $this->setInputType(new S('option'))->setName($v[self::$objMPTT->objIdField])->setValue($v[self::$objMPTT->objIdField])->setLabel(new S(str_repeat('--' . _SP, (int) $v['depth']->toString()) . $v[self::$objMPTT->objNameOfNode])); } // Continue ... $this->setFormEndAndExecute(new B(TRUE)); break; case 'configurationEdit': // Set the URL to go back too; $objURLToGoBack = new S(); // Do some work; if ($this->checkPOST()->toBoolean() == TRUE) { $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION)), new A(array($this->getPOST(new S('what'))))); } // Do the form, make it happen; $this->setMethod(new S('POST'))->setFieldset(new S(MANAGE_TEXTS_CONFIG))->setName($objFormToRender)->setRedirect($objURLToGoBack)->setInputType(new S('submit'))->setValue(new S(TEXTS_CONFIG_DO))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('select'))->setName(new S('what'))->setLabel(new S(TEXTS_CONFIG_CHOOSE))->setContainerDiv(new B(TRUE))->setInputType(new S('option'))->setName(new S('configurationEditMustBeAuthToComment'))->setValue(new S('configurationEditMustBeAuthToComment'))->setLabel(new S(TEXTS_USER_MUST_BE_LOGGED_TO_COMMENT))->setInputType(new S('option'))->setName(new S('configurationEditTextsPerCategory'))->setValue(new S('configurationEditTextsPerCategory'))->setLabel(new S(TEXTS_PER_CATEGORY))->setFormEndAndExecute(new B(TRUE)); break; case 'configurationEditMustBeAuthToComment': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION))); // Do some work; if ($this->checkPOST()->toBoolean() == TRUE) { foreach ($this->getPOST() as $k => $v) { $this->setConfigKey(new S($k), $v); } } // Do the form, make it happen; $this->setMethod(new S('POST'))->setFieldset(new S(TEXTS_UPDATE_CONFIGURATION))->setName($objFormToRender)->setRedirect($objURLToGoBack)->setInputType(new S('submit'))->setValue(new S(TEXTS_UPDATE_CONFIGURATION))->setContainerDiv(new B(TRUE))->setInputType(new S('select'))->setName(new S('texts_settings_authenticated_to_comment'))->setLabel(new S(TEXTS_CONFIG_CHOOSE))->setContainerDiv(new B(TRUE))->setInputType(new S('option'))->setName(new S('yes'))->setValue(new S('Y'))->setLabel(new S('Yes'))->setSelected($this->getConfigKey(new S('texts_settings_authenticated_to_comment')) == 'Y' ? new B(TRUE) : new B(FALSE))->setInputType(new S('option'))->setName(new S('no'))->setValue(new S('N'))->setLabel(new S('No'))->setSelected($this->getConfigKey(new S('texts_settings_authenticated_to_comment')) == 'N' ? new B(TRUE) : new B(FALSE))->setFormEndAndExecute(new B(TRUE)); break; case 'configurationEditTextsPerCategory': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION))); // Do some work; if ($this->checkPOST()->toBoolean() == TRUE) { foreach ($this->getPOST() as $k => $v) { $this->setConfigKey(new S($k), $v); } } // Do the form, make it happen; $this->setMethod(new S('POST'))->setFieldset(new S(TEXTS_UPDATE_CONFIGURATION))->setName($objFormToRender)->setRedirect($objURLToGoBack)->setInputType(new S('submit'))->setValue(new S(TEXTS_UPDATE_CONFIGURATION))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(new S('texts_settings_per_page'))->setLabel(new S(TEXTS_PER_PAGE))->setValue($this->getConfigKey(new S('texts_settings_per_page')))->setRegExpType(new S('ereg'))->setRegExpErrMsg(new S(TEXTS_CONFIG_PER_PAGE_ERROR))->setPHPRegExpCheck(new S('[0-9]'))->setJSRegExpReplace(new S('[^0-9]'))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; } }
/** * Will render a specified form, the name of the form given by the first parameter; * * This method will render one of the forms for our object, invoked by giving the proper form identifier to the current form. We * have chosen this method of invoking forms, because we just had too many this->renderSomethingMethod (), which really had * an impact on code massiveness. Also, having code organized in switch/case statements leads us to be able to share common * settings between different forms, as we've done with the methods defined in the __CALL method above; * * For example, if we wanted to share some common configuration between a create and an edit form, we could have introduced * two switches in this method, one that would have set the common options, and the second, would have just passed through * again, and get the already set configuration options, using them. This means that if we needed to change behavior of * some interconnected forms, that would mean modifying the needed code one place only, which is a big advantage over * having separated methods for each form. Maybe if we extended this object, you guys could understand the functionality better; * * @param string $objFormToRender The name of the form to render; * @return mixed Depends on the rendered form if it returns something or not; */ public function renderForm(S $objFormToRender, A $objFormArray = NULL) { // Make them defaults ... if ($objFormArray == NULL) { $objFormArray = new A(); } // Do a switch ... switch ($objFormToRender) { case 'widgetSearch': // Do the form, make it happen ... $this->setMethod(new S('POST'))->setName($objFormToRender); // Do some work ... if ($this->checkPOST(new S('search_lyrics'))->toBoolean() == TRUE) { // Get the title, and check it's name ... if ($this->getPOST(new S('lyrics_search_keyword'))->toLength()->toInt() == 0) { // Well, sadly, we have an issue ... $this->setErrorOnInput(new S('lyrics_search_keyword'), new S('Nu ai completat cautarea!')); } else { // Go ... $this->setHeaderKey($objURLToGoBack = URL::staticURL(new A(array(FRONTEND_SECTION_URL, LYRICS_SEARCH_URL)), new A(array(FRONTEND_LYRICS_URL, $this->getPOST(new S('lyrics_search_keyword'))->entityDecode(ENT_QUOTES)->stripSlashes()))), new S('Location')); } } // Continue ... $this->setInputType(new S('text'))->setName(new S('lyrics_search_keyword')); // If it's set ... add the VALUE ... if (isset($_GET[LYRICS_SEARCH_URL])) { $this->setValue($_GET[LYRICS_SEARCH_URL]); } // Continue ... $this->setLabel(new S('Cuvant'))->setContainerDiv(new B(TRUE))->setInputType(new S('submit'))->setName(new S('search_lyrics'))->setValue(new S('Cauta'))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; case 'lyricCreate': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(); $objErrorHappen = new B(FALSE); // Do some work; if ($this->checkPOST(self::$objLyricsTableFTitle)->toBoolean() == TRUE) { // Check != 0 ... if ($this->getPOST(self::$objLyricsTableFTitle)->toLength()->toInt() == 0) { self::setErrorOnInput(self::$objLyricsTableFTitle, new S(LYRICS_TITLE_CANNOT_BE_EMPTY)); $objErrorHappen = new B(TRUE); } } if ($this->checkPOST(self::$objLyricsTableFArtist)->toBoolean() == TRUE) { // Check != 0 ... if ($this->getPOST(self::$objLyricsTableFArtist)->toLength()->toInt() == 0) { self::setErrorOnInput(self::$objLyricsTableFArtist, new S(LYRICS_ARTIST_CANNOT_BE_EMPTY)); $objErrorHappen = new B(TRUE); } } if ($this->checkPOST(self::$objLyricsTableFAlbum)->toBoolean() == TRUE) { // Check != 0 ... if ($this->getPOST(self::$objLyricsTableFAlbum)->toLength()->toInt() == 0) { self::setErrorOnInput(self::$objLyricsTableFAlbum, new S(LYRICS_ALBUM_CANNOT_BE_EMPTY)); $objErrorHappen = new B(TRUE); } } // Get AJAX; $this->getAjaxErrors(); // Do the form, make it happen; $this->setMethod(new S('POST'))->setEnctype(new S('multipart/form-data'))->setFieldset(new S(LYRICS_ADD_LYRIC))->setSQLAction(new S('update'))->setTableName(self::$objLyricsTable)->setUpdateId(new S('#nextTableAutoIncrement'))->setUpdateField(self::$objLyricsTableFId)->setExtraUpdateData(self::$objLyricsTableFDateAdded, new S((string) $_SERVER['REQUEST_TIME'])); if ($this->checkPOST(self::$objLyricsTableFTitle)->toBoolean() == TRUE && $objErrorHappen->toBoolean() == FALSE) { $this->setExtraUpdateData(self::$objLyricsTableFSEO, URL::getURLFromString(new S($this->getPOST(self::$objLyricsTableFTitle) . _U . $this->getPOST(self::$objLyricsTableFArtist) . _U . $this->getPOST(self::$objLyricsTableFAlbum) . _U . $_SERVER['REQUEST_TIME']))); } $this->setName($objFormToRender)->setRedirect($objURLToGoBack)->setAJAXEnabledForm(new B(FALSE))->setInputType(new S('submit'))->setInputInfoMessage($this->getHELP($objFormToRender))->setValue(new S(LYRICS_ADD_LYRIC))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objLyricsTableFTitle)->setLabel(new S(LYRICS_TITLE))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objLyricsTableFArtist)->setLabel(new S(LYRICS_ARTIST))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objLyricsTableFAlbum)->setLabel(new S(LYRICS_ALBUM))->setContainerDiv(new B(TRUE))->setInputType(new S('textarea'))->setName(self::$objLyricsTableFLyrics)->setLabel(new S(LYRICS_LYRIC))->setTinyMCETextarea(new B(TRUE))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; case 'lyricEdit': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION, ADMIN_ACTION_ID))); $objErrorHappen = new B(FALSE); // Do some work; if ($this->checkPOST(self::$objLyricsTableFTitle)->toBoolean() == TRUE) { // Check != 0 ... if ($this->getPOST(self::$objLyricsTableFTitle)->toLength()->toInt() == 0) { self::setErrorOnInput(self::$objLyricsTableFTitle, new S(LYRICS_TITLE_CANNOT_BE_EMPTY)); $objErrorHappen = new B(TRUE); } } if ($this->checkPOST(self::$objLyricsTableFArtist)->toBoolean() == TRUE) { // Check != 0 ... if ($this->getPOST(self::$objLyricsTableFArtist)->toLength()->toInt() == 0) { self::setErrorOnInput(self::$objLyricsTableFArtist, new S(LYRICS_ARTIST_CANNOT_BE_EMPTY)); $objErrorHappen = new B(TRUE); } } if ($this->checkPOST(self::$objLyricsTableFAlbum)->toBoolean() == TRUE) { // Check != 0 ... if ($this->getPOST(self::$objLyricsTableFAlbum)->toLength()->toInt() == 0) { self::setErrorOnInput(self::$objLyricsTableFAlbum, new S(LYRICS_ALBUM_CANNOT_BE_EMPTY)); $objErrorHappen = new B(TRUE); } } // Get AJAX; $this->getAjaxErrors(); // Do the form, make it happen; $this->setMethod(new S('POST'))->setEnctype(new S('multipart/form-data'))->setFieldset(new S(LYRICS_EDIT_LYRIC))->setSQLAction(new S('update'))->setTableName(self::$objLyricsTable)->setUpdateId($_GET[ADMIN_ACTION_ID])->setUpdateField(self::$objLyricsTableFId); if ($this->checkPOST(self::$objLyricsTableFTitle)->toBoolean() == TRUE && $objErrorHappen->toBoolean() == FALSE) { $this->setExtraUpdateData(self::$objLyricsTableFSEO, URL::getURLFromString(new S($this->getPOST(self::$objLyricsTableFTitle) . _U . $this->getPOST(self::$objLyricsTableFArtist) . _U . $this->getPOST(self::$objLyricsTableFAlbum) . _U . $this->getLyricInfoById($_GET[ADMIN_ACTION_ID], self::$objLyricsTableFDateAdded)))); } $this->setName($objFormToRender)->setRedirect($objURLToGoBack)->setAJAXEnabledForm(new B(FALSE))->setInputType(new S('submit'))->setInputInfoMessage($this->getHELP($objFormToRender))->setValue(new S(LYRICS_EDIT_LYRIC))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objLyricsTableFTitle)->setLabel(new S(LYRICS_TITLE))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objLyricsTableFArtist)->setLabel(new S(LYRICS_ARTIST))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objLyricsTableFAlbum)->setLabel(new S(LYRICS_ALBUM))->setContainerDiv(new B(TRUE))->setInputType(new S('textarea'))->setName(self::$objLyricsTableFLyrics)->setLabel(new S(LYRICS_LYRIC))->setTinyMCETextarea(new B(TRUE))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; case 'lyricErase': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION, ADMIN_ACTION_ID))); // Do erase it ... $this->_Q(_QS('doDELETE')->doToken('%table', self::$objLyricsTable)->doToken('%condition', new S('%objLyricsTableFId = "%Id"'))->doToken('%Id', $_GET[ADMIN_ACTION_ID])); // Do a redirect back; $this->setHeaderKey($objURLToGoBack, new S('Location')); break; } }