/** * 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; } }
function emptyDir($path) { if ($handle = OPENDIR($path)) { while (FALSE !== ($file = READDIR($handle))) { if ($file != "." && $file != "..") { if (IS_FILE($path . "/" . $file)) { if (UNLINK($path . "/" . $file)) { $debugStr = true; } } } } } return $debugStr; }
/** * 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 clear the CACHE_DIR, of all cache files. Used for a general refresh of the system cache. This method is provided for * functionality that needs to refresh the whole system cache. For the moment, no even the core developers have found an use * for such a method but we provide it anyway; * * @return B Will return true if the cache directory has been cleared * @author Catalin Z. Alexandru <*****@*****.**> * @copyright Under the terms of the GNU General Public License v3 * @version $Id: 10_TPL.php 315 2009-10-11 07:11:31Z catalin.zamfir $ * @since version 1.0 * @access protected * @static * @final */ protected static final function clearCache() { // Do a new FileDirectory, prepended DOCUMENT_ROOT; $cacheFile = new FileDirectory(CACHE_DIR, TRUE); // Clean-up EVERYTHING, except the dots; // Should use DirectoryIterator here, to be implemented soon; for ($i = 2, $cacheCount = count($cacheFile = scandir($cacheFile)); $i < $cacheCount; ++$i) { // Just do skip over .dirs and .files; if ($cacheFile[$i][0] != '.') { UNLINK($cacheDirectory . _S . $cacheFile[$i]); } } // Do return ... return new B(TRUE); }
private function emptyDir($path) { // init the debug string $debugStr = ''; $debugStr .= "Deleting Contents Of: $path<br /><br />"; // parse the folder IF ($handle = OPENDIR($path)) { WHILE (FALSE !== ($file = READDIR($handle))) { IF ($file != "." && $file != "..") { // If it's a file, delete it IF (IS_FILE($path . "/" . $file)) { IF (UNLINK($path . "/" . $file)) { $debugStr .= "Deleted File: " . $file . "<br />"; } } ELSE { // It's a directory... // crawl through the directory and delete the contents IF ($handle2 = OPENDIR($path . "/" . $file)) { WHILE (FALSE !== ($file2 = READDIR($handle2))) { IF ($file2 != "." && $file2 != "..") { IF (UNLINK($path . "/" . $file . "/" . $file2)) { $debugStr .= "Deleted File: $file/$file2<br />"; } } } } IF (RMDIR($path . "/" . $file)) { $debugStr .= "Directory: " . $file . "<br />"; } } } } } return $debugStr; }
function r301depart() { if (isset($_POST['r301']) || !is_file(CR301) || e('nor301', 1) || H == 'cli' || strpos(U, '/sql/')) { return; } $r1 = r3p(mu); if (is_file($r1)) { $r301 = fgc($r1); } else { $r301 = FGC(CR301); } if (J9 && is_file(CR301) && fmt(CR301) < 2000000000) { @UNLINK(CR301); if (is_file($r1)) { @UNLINK($r1); } } #av('a1',fmt(CR301)); if (strlen($r301) > 200 || preg_match("~image/png|base64,|data:~", u)) { db3("r301depart:{$r301}"); return; } if (!$r301 || $r301 == SU) { if (is_file(CR301)) { unlink(CR301); } if (is_file($r1)) { unlink($r1); } return; } $hist = array($r301); FB('r301depart'); #jx('mail','r301:'.$r301."is_file(CR301):".is_file(CR301));db(SU."=>r301 file same or nul=>$r301"); while ($n < 4 && GT('recursiver301') < 400) { $n++; $next = FGC(r3p($r301)); if ($next == SU) { unlink(r3p($r301)); $next = ''; } if ($next) { $hist[] = $next; FPC(CR301, $next, 3); $r301 = $next; } else { $n = 4; } } if (!$r301) { unlink(CR301); return; } #@file_get_contents($r301,'',$GLOBALS['ctx'],0,10);$x=$a=$http_response_header;$a=explode(' ',$a[0]);$a=$a[1];#jx('r'.pre($x)); if (in_Array(SU, $hist)) { db(SU . "=>inArray=>{$r301}"); jx($hist); } if ($r301 == SU) { db(SU . "=>same=>{$r301}=>unlink"); unlink(CR301); return; } if (!$r301) { db("emptyR1" . SU); unlink(CR301); return; } if ($r301) { fmt(CR301); r303($r301); e(',r301'); kill(); } #Fmt(CR301.".count"); #@file_get_contents($r301,'',$GLOBALS['ctx'],0,20);$a=$http_response_header;if(!strpos($a[0],'200 OK'))R301('/'); }
function EMAILFILE1($NODE) { /* This function is the second phase of the EMAIL File process, this is the checking phase and mail process, previously to use this function the SMTP variable in PHP.INI must be set acordingly to your ISPs smtp mail server, an smtp server something like "smtp.your_ip_server.com" (you_ip_server could be anything). */ $CURRENT_FILE = BUILD_PATH($NODE); $REAL_FILE = str_replace(DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, DIRNAME($_SESSION['Server_Path'])) . DIRECTORY_SEPARATOR . $CURRENT_FILE; // the real full filename of the directory PAGEMAIL_HEADER("FILE MANAGER - DIRTREEVIEW", "EMAIL FUNCTION", "BLUE", "WHITE"); ?> <Table WIDTH=100% BORDER=0 CELLPADDING=8 CELLSPACING=0 class=td> <Tr> <Td VALIGN=top ALIGN=left> <Center> <Font FACE=tahoma> <H3>FileName: <?php echo $CURRENT_FILE . "</h3>"; ?> </Td> </Tr> <Tr> <Td> <Form NAME="emailfile1" METHOD="post" ENCTYPE="multipart/form-data" ACTION="<?php echo $_SERVER['PHP_SELF']; ?> "> <Table ALIGN=center BORDER=0 class=td> <Tr> <?php $ERROR_FUNCTION = false; if (empty($_POST['attached'])) { echo "<td><CENTER><h3>No file to send</h3></td>"; $ERROR_FUNCTION = true; } else { CLEARSTATCACHE(); if (!IS_FILE($_POST['attached'])) { echo "<td><CENTER><h3>The File has been erased or moved</h3></td>"; $ERROR_FUNCTION = true; } else { if (!IS_VALID_EMAIL($_POST['target_email'])) { echo "<td><CENTER><h3>The data fields has errors</h3></td>"; $ERROR_FUNCTION = true; } else { $prioridad = "3"; $headers = "From: "; $headers .= $_POST['your_name']; $headers .= " <"; $headers .= $_POST['your_email']; $headers .= ">\n"; $headers .= "Reply-To: "; $headers .= $_POST['your_name']; $headers .= " <"; $headers .= $_POST['your_email']; $headers .= ">\n"; $headers .= "MIME-Version: 1.0\n"; $headers .= "Content-Type: multipart/mixed; boundary=\"MIME_BOUNDRY\"\n"; $headers .= "X-Sender: DIRTREEVIEW 1.0 <"; $headers .= $_POST['your_email']; $headers .= ">\n"; $headers .= "X-Mailer: DIRTREEVIEW 1.0\n"; $headers .= "X-Priority: "; $headers .= $prioridad; $headers .= "\n"; $headers .= "Return-Path: <"; $headers .= $_POST['target_email']; $headers .= ">\n"; $headers .= "This is a multi-part message in MIME format.\n"; $FILE_TO_EMAIL = $_POST['attached']; if ($_POST['ACTIONEMAIL'] == "compress") { CLEARSTATCACHE(); if (IS_FILE($REAL_FILE)) { $ZIP_FILE = DIRNAME($REAL_FILE) . DIRECTORY_SEPARATOR . SUBSTR(BASENAME($REAL_FILE), 0, STRRPOS(BASENAME($REAL_FILE), ".")) . ".zip"; if ($ZIP_FILE != $REAL_FILE) { if (IS_FILE($ZIP_FILE)) { UNLINK($ZIP_FILE); } $FILE_TO_ZIP[1] = $REAL_FILE; //include_once("dirtreezip1.inc.php"); $ziper = new zipfile(); $ziper->addFiles($FILE_TO_ZIP); $ziper->output($ZIP_FILE); if (IS_FILE($ZIP_FILE)) { $FILE_TO_EMAIL = $ZIP_FILE; } } } } $fp = fopen($FILE_TO_EMAIL, "r"); $str = fread($fp, filesize($FILE_TO_EMAIL)); $str = chunk_split(base64_encode($str)); $fp = fclose($fp); $blankline = " \r\n"; $tmp_message = "Hi " . $_POST['target_name']; $tmp_message .= $blankline; $tmp_message .= $blankline; $tmp_message .= "I'am " . $_POST['your_name'] . " and I send you this message and the attached file"; $tmp_message .= $blankline; $tmp_message .= $blankline; $tmp_message .= "Message"; $tmp_message .= $blankline; $tmp_message .= $blankline; $tmp_message .= "======="; $tmp_message .= $blankline; $tmp_message .= $blankline; $tmp_message .= $_POST['email_message']; $message = "--MIME_BOUNDRY\n"; $message .= "Content-Type: text/plain; charset=\"iso-8859-1\"\n"; $message .= "Content-Transfer-Encoding: quoted-printable\n"; $message .= "\n"; $message .= $tmp_message; $message .= "\n"; $message .= "--MIME_BOUNDRY\n"; $message .= "Content-Type: application/octet-stream; name="; $message .= basename($FILE_TO_EMAIL); $message .= "\n"; $message .= "Content-disposition: attachment\n"; $message .= "Content-Transfer-Encoding: base64\n"; $message .= "\n"; $message .= $str; $message .= "\n"; $message .= "\n"; $message .= "--MIME_BOUNDRY--\n"; if (!mail($_POST['target_email'], $_POST['matter'], $message, $headers)) { echo "<td><CENTER><h3>ERROR : email has not been sent, please try it again</h3></td>"; $ERROR_FUNCTION = true; } else { echo "<td><CENTER><h3>The file " . $FILE_TO_EMAIL . " has been sent succesfully</h3></td>"; } if ($_POST['ACTIONEMAIL'] == "compress") { if ($ZIP_FILE != $REAL_FILE) { if (IS_FILE($ZIP_FILE)) { UNLINK($ZIP_FILE); } } unset($_POST['ACTIONEMAIL']); } } } } ?> </Tr> <Input TYPE="hidden" NAME="FILE_EXTENSION" VALUE="<?php echo $_SESSION['File_Extension']; ?> "> <Input TYPE="hidden" NAME="NODE" VALUE="<?php echo $NODE; ?> "> <?php if ($ERROR_FUNCTION) { ?> <Input TYPE="hidden" NAME="ACTION" VALUE=""> <Tr> <Td><Center><Input TYPE="Submit" NAME="emailfileform3a" VALUE=" Cancel "></Td> <?php } else { ?> <Input TYPE="hidden" NAME="ACTION" VALUE=""> <Tr> <Td><Center><Input TYPE="Submit" NAME="emailfileform3b" VALUE=" Accept "></Td> <?php } ?> </Tr> </Table> </Form> </Td> </Tr> </Table> <?php PAGE_FOOTER("BLUE", "WHITE"); exit; }