/** * 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 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. * 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 set the form ending ... * * This method, setFormEndAndExecute, will set the form ending, and execute catched information about each input, in the * objDataContainer. It will assign the form attributes to the first input of the form, beucase the form tag needs to be * delcared prior to declaring any input, if we want that input to be part of the form. Also, it prepends and appends the * fieldset tags for the form ... * * @param boolean $objFormAttributeVar A boolean value, that if true, will render the form above; * @return object The current object instance; */ public static final function setFormEndAndExecute(B $objFormAttributeVar) { if ($objFormAttributeVar->toBoolean() == TRUE) { // Do content cleaning rutine; if (self::checkPOST()->toBoolean() == TRUE) { foreach ($_SESSION['POST'] as $k => $v) { # $_SESSION['POST'][$k] = mysql_real_escape_string ($v); } } // Update and START; self::updateObjectPropertiesonSQLUpdateorInsert(); self::setFormHeaderOnInputStart(); // Do the foreach ... $tp = new FilePath(FORM_TP_DIR . _S . 'frm_input_gen.tp'); foreach (self::$objDataContainer as $k => $v) { // Tie SQL operations to the first input that has a name ... if (!isset(self::$objFormDataContainer['SQL_operations_tied_to_input'])) { if (isset(self::$objFormDataContainer['update_or_insert'])) { if (isset(self::$objDataContainer[$k]['name'])) { self::$objFormDataContainer['SQL_operations_tied_to_input'] = self::$objDataContainer[$k]['name']; } } } // Set a hook before form _POST or _QUERY data, got from the database ... if (isset(self::$objRegisteredFunctionArray['hook:beforeFormPOSTOrQuery'])) { foreach (self::$objRegisteredFunctionArray['hook:beforeFormPOSTOrQuery'] as $objFunction) { call_user_func($objFunction->toString(), self::$objDataContainer[$k]); } } // Generate the FILE controller; self::makeInputFileController(new I($k)); // Check if the _SESSION['POST'] was set; if (self::checkPOST()->toBoolean() == TRUE) { self::optionSELECTOnPOST(new I($k)); self::checkboxRadioSQLOperations(new I($k)); self::sessionToInputValueSetter(new I($k)); // Set a hook for a innerFormPOST; if (isset(self::$objRegisteredFunctionArray['hook:innerFormPOST'])) { foreach (self::$objRegisteredFunctionArray['hook:innerFormPOST'] as $objFunction) { call_user_func($objFunction->toString(), self::$objDataContainer[$k], $_SESSION['POST']); } } } else { if (isset(self::$objUpdateSELECTData[0])) { if (isset(self::$objDataContainer[$k]['name'])) { if (in_array(self::$objDataContainer[$k]['name'], self::$objUpdateTableFields->toArray())) { self::queryToInputValueSetter(new I($k)); } } // REMBER ME: This used of be an 'else if', so if bugs appear, be sure to check this out! if (self::$objDataContainer[$k]['type'] == new S('option')) { if (isset(self::$objDataContainer[$k]['value'])) { // REMEMBER ME: BIND options to SELECTs; if (self::$objDataContainer[$k]['value'] == self::$objUpdateSELECTData[0][self::$objDataContainer[$k]['bound_to']]) { self::$objDataContainer[$k]['selected'] = new S('yes'); } } } // Set a hook innerFormQUERY; if (isset(self::$objRegisteredFunctionArray['hook:innerFormQUERY'])) { foreach (self::$objRegisteredFunctionArray['hook:innerFormQUERY'] as $objFunction) { call_user_func($objFunction->toString(), self::$objDataContainer[$k], self::$objUpdateSELECTData[0]); } } } } // Clear the MPTT unique flag ... if (isset(self::$objDataContainer[$k]['mptt_remove_unique'])) { // Remove it ... self::$objDataContainer[$k]['value'] = MPTT::mpttRemoveUnique(self::$objDataContainer[$k]['value']); } // Set a hook after a FormPOSTOrQuery; if (isset(self::$objRegisteredFunctionArray['hook:afterFormPOSTOrQuery'])) { foreach (self::$objRegisteredFunctionArray['hook:afterFormPOSTOrQuery'] as $objFunction) { call_user_func($objFunction->toString(), self::$objDataContainer[$k]); } } // Set the number index; self::$objDataContainer[$k]['index_of_input'] = $k; // Generate an HTML element; self::generateHTML(self::$objDataContainer[$k]['type'], self::$objDataContainer[$k], $tp); } // End the form; self::setFormFooterOnInputEnd(); self::$objDataContainer = new A(); self::$objDataCountInput = new I(0); self::$objDataToForm = new I(0); self::$objFormDataContainer = new A(); self::$objOtherSQLData = new A(); self::$objUpdateSELECTData = new A(); self::$objRegisteredFunctionArray = new A(); // Return to chain ... return TheFactoryMethodOfSingleton::getInstance(__CLASS__); } else { // Return to chain ... return TheFactoryMethodOfSingleton::getInstance(__CLASS__); } }