Esempio n. 1
0
 public function __construct()
 {
     // Construct any possible parent;
     parent::__construct();
     // Do the tie ...
     $this->tieInCommonConfiguration();
     // Set the proper configuration options, from the config file;
     self::$objSettingsCountryTable = $this->getConfigKey(new S('settings_country_table'));
     self::$objSettingsCountryTableFIso = $this->getConfigKey(new S('settings_country_table_field_iso'));
     self::$objSettingsCountryTableFName = $this->getConfigKey(new S('settings_country_table_field_name'));
     self::$objSettingsCountryTableFPrnt = $this->getConfigKey(new S('settings_country_table_field_printable_name'));
     self::$objSettingsCountryTableFIsoT = $this->getConfigKey(new S('settings_country_table_field_iso3'));
     self::$objSettingsCountryTableFCode = $this->getConfigKey(new S('settings_country_table_field_numcode'));
     // Errors ...
     self::$objSettingsErrTable = $this->getConfigKey(new S('settings_error_pages_table'));
     self::$objSettingsErrTableFId = $this->getConfigKey(new S('settings_error_pages_table_field_id'));
     self::$objSettingsErrTableFCode = $this->getConfigKey(new S('settings_error_pages_table_error_code'));
     self::$objSettingsErrTableFTitle = $this->getConfigKey(new S('settings_error_pages_table_title'));
     self::$objSettingsErrTableFContent = $this->getConfigKey(new S('settings_error_pages_table_content'));
     // DB: Auto-CREATE:
     $objQueryDB = new FileContent($this->getPathToModule()->toRelativePath() . _S . CFG_DIR . _S . __CLASS__ . SCH_EXTENSION);
     // Make a FOREACH on each ...
     foreach (_S($objQueryDB->toString())->fromStringToArray(RA_SCHEMA_HASH_TAG) as $k => $v) {
         // Make'em ...
         $this->_Q(_S($v));
     }
 }
Esempio n. 2
0
 public function __construct()
 {
     // Construct any possible parent;
     parent::__construct();
     // Do the tie ...
     $this->tieInCommonConfiguration();
     // Set some configuration defaults, taking them from the config file;
     self::$objContactTable = $this->getConfigKey(new S('contact_table_message'));
     self::$objContactTableFId = $this->getConfigKey(new S('contact_table_message_field_id'));
     self::$objContactTableFMessage = $this->getConfigKey(new S('contact_table_message_content'));
     self::$objContactTableFSubjectId = $this->getConfigKey(new S('contact_table_message_subject_id'));
     self::$objContactTableFEMAIL = $this->getConfigKey(new S('contact_table_message_email'));
     self::$objContactTableFResolved = $this->getConfigKey(new S('contact_table_message_resolved'));
     self::$objContactTableFComment = $this->getConfigKey(new S('contact_table_message_comment'));
     self::$objContactTableFReceived = $this->getConfigKey(new S('contact_table_message_received'));
     self::$objContactTableFLastEdited = $this->getConfigKey(new S('contact_table_message_last_edited'));
     // Subjects ..
     self::$objContactSubjectTable = $this->getConfigKey(new S('contact_table_subject'));
     self::$objContactSubjectFId = $this->getConfigKey(new S('contact_table_subject_field_id'));
     self::$objContactSubjectFTitle = $this->getConfigKey(new S('contact_table_subject_title'));
     // DB: Auto-CREATE:
     $objQueryDB = new FileContent($this->getPathToModule()->toRelativePath() . _S . CFG_DIR . _S . __CLASS__ . SCH_EXTENSION);
     // Make a FOREACH on each ...
     foreach (_S($objQueryDB->toString())->fromStringToArray(RA_SCHEMA_HASH_TAG) as $k => $v) {
         // Make'em ...
         $this->_Q(_S($v));
     }
     // Load'em defaults ... ATH, STG and others ...
     $this->ATH = MOD::activateModule(new FilePath('mod/authentication'), new B(TRUE));
     $this->STG = MOD::activateModule(new FilePath('mod/settings'), new B(TRUE));
 }
Esempio n. 3
0
 /**
  * Subscribe to a signal.
  *
  * Signal::connect('user.auth', 'function');
  *
  * The subscribed function should receive a two arguments and will have
  * this signature:
  *
  * function callback($object, $data);
  *
  * Where the $object argument is the object originating the signal, and
  * the $options is a hash-array of other information originating from-
  * and pertaining to the signal.
  *
  * The value of the $data argument is not defined. It is signal
  * specific. It should be a hash-array of data; however, no runtime
  * checks are made to ensure such an interface.
  *
  * Optionally, if $object is a class and is passed into the ::connect()
  * method, only instances of the named class or subclass will actually
  * be connected to the callable function.
  *
  * A predicate function, $check, can be used to filter calls to the
  * signal handler. The function will receive the signal data and should
  * return true if the signal handler should be called.
  */
 static function connect($signal, $callable, $object = null, $check = null)
 {
     if (!isset(self::$subscribers[$signal])) {
         self::$subscribers[$signal] = array();
     }
     // XXX: Ensure $object if set is a class
     if ($object && !is_string($object)) {
         trigger_error(sprintf(_S("Invalid object: %s: Expected class"), $object));
     } elseif ($check && !is_callable($check)) {
         trigger_error(_S("Invalid check function: Must be callable"));
         $check = null;
     }
     self::$subscribers[$signal][] = array($object, $callable, $check);
 }
Esempio n. 4
0
 /**
  * @param array $set array to be managed
  */
 public function __construct($type, $set = null)
 {
     if (is_callable($type)) {
         $this->type = $type;
     } else {
         if (!string::isString($type)) {
             throw new \InvalidArgumentException('invalid type specifier');
         } else {
             $this->type = trim(_S($type)->asUtf8);
         }
     }
     if (func_num_args() > 1) {
         parent::__construct($this->filterByType($set, false));
     } else {
         parent::__construct();
     }
 }
Esempio n. 5
0
 public function __construct()
 {
     // Construct any possible parent;
     parent::__construct();
     // Do the tie ...
     $this->tieInCommonConfiguration();
     // Set the proper configuration options, from the config file;
     self::$objFaqTable = $this->getConfigKey(new S('faq_table'));
     self::$objFaqTableFId = $this->getConfigKey(new S('faq_table_field_id'));
     self::$objFaqTableFQuestion = $this->getConfigKey(new S('faq_table_field_question'));
     self::$objFaqTableFSEO = $this->getConfigKey(new S('faq_table_field_seo'));
     self::$objFaqTableFAnswer = $this->getConfigKey(new S('faq_table_field_answer'));
     // Load'em defaults ... ATH, STG and others ...
     $this->ATH = MOD::activateModule(new FilePath('mod/authentication'), new B(TRUE));
     $this->STG = MOD::activateModule(new FilePath('mod/settings'), new B(TRUE));
     // DB: Auto-CREATE:
     $objQueryDB = new FileContent($this->getPathToModule()->toRelativePath() . _S . CFG_DIR . _S . __CLASS__ . SCH_EXTENSION);
     // Make a FOREACH on each ...
     foreach (_S($objQueryDB->toString())->fromStringToArray(RA_SCHEMA_HASH_TAG) as $k => $v) {
         // Make'em ...
         $this->_Q(_S($v));
     }
 }
Esempio n. 6
0
 /**
  * Will render a specified form, the name of the form given by the first parameter;
  *
  * This method will render one of the forms for our object, invoked by giving the proper form identifier to the current form.
  * We have chosen this method of invoking forms, because we just had too many this->renderSomethingMethod (), which really had
  * an impact on code massiveness. Also, having code organized in switch/case statements leads us to be able to share common
  * settings between different forms, as we've done with the methods defined in the __CALL method above;
  *
  * For example, if we wanted to share some common configuration between a create and an edit form, we could have introduced
  * two switches in this method, one that would have set the common options, and the second, would have just passed through
  * again, and get the already set configuration options, using them. This means that if we needed to change behavior of
  * some interconnected forms, that would mean modifying the needed code one place only, which is a big advantage over
  * having separated methods for each form. Maybe if we extended this object, you guys could understand the functionality best;
  *
  * @param string $objFormToRender The name of the form to render;
  * @return mixed Depends on the rendered form if it returns something or not;
  */
 public function renderForm(S $objFormToRender, A $objFA = NULL)
 {
     // Make them defaults ...
     if ($objFA == NULL) {
         $objFA = new A();
     }
     // Do a switch ...
     switch ($objFormToRender) {
         case 'textSearch':
             // Get some predefines;
             if (isset($_GET[ADMIN_ACTION_BY])) {
                 $objSearchBy = $_GET[ADMIN_ACTION_BY];
             } else {
                 $objSearchBy = new S();
             }
             if (isset($_GET[ADMIN_ACTION_SEARCH])) {
                 $objSearchWas = $_GET[ADMIN_ACTION_SEARCH];
             } else {
                 $objSearchWas = new S();
             }
             // Do some work;
             if ($this->checkPOST(new S('search_submit'))->toBoolean() == TRUE) {
                 if ($this->getPOST(new S('search_by'))->toLength()->toInt() == 0) {
                     if (isset($_GET[ADMIN_ACTION_SEARCH])) {
                         // Erase search terms ...
                         $this->setHeaderKey(URL::rewriteURL(new A(array(ADMIN_ACTION_SEARCH, ADMIN_ACTION_BY))), new S('Location'));
                     }
                     // Set an input error;
                     $this->setErrorOnInput(new S('search_by'), new S(ARTICLE_SEARCH_FIELD_IS_EMPTY));
                     // Unset the post ...
                     $this->unsetPOST();
                 } else {
                     // Get what to search and where ...
                     $objWhatToSearch = $this->getPOST(new S('search_by'));
                     $objWhereToSearch = $this->getPOST(new S('search_field'));
                     // And go there ...
                     $this->setHeaderKey(URL::rewriteURL(new A(array(ADMIN_ACTION_SEARCH, ADMIN_ACTION_BY)), new A(array($objWhatToSearch, $objWhereToSearch))), new S('Location'));
                 }
             }
             // Check the option that has been selected;
             $objWasSelected = new A(array(new B($objSearchBy == TEXTS_SEARCH_TITLE ? TRUE : FALSE), new B($objSearchBy == TEXTS_SEARCH_CONTENT ? TRUE : FALSE)));
             // Do the form, make it happen;
             $this->setMethod(new S('POST'))->setEnctype(new S('multipart/form-data'))->setFieldset(new S(TEXTS_SEARCH_BY))->setName($objFormToRender)->setInputType(new S('text'))->setInputInfoMessage($this->getHELP($objFormToRender))->setName(new S('search_by'))->setvalue($objSearchWas)->setLabel(new S(TEXTS_SEARCH_BY))->setJSRegExpReplace(new S('[^a-zA-Z0-9 -]'))->setContainerDiv(new B(TRUE))->setInputType(new S('select'))->setName(new S('search_field'))->setContainerDiv(new B(TRUE))->setLabel(new S(TEXTS_SEARCH_IN))->setInputType(new S('option'))->setName(new S('article_title'))->setValue(new S(TEXTS_SEARCH_TITLE))->setLabel(new S(TEXTS_SEARCH_TITLE))->setSelected($objWasSelected[0])->setInputType(new S('option'))->setName(new S('article_content'))->setValue(new S(TEXTS_SEARCH_CONTENT))->setLabel(new S(TEXTS_SEARCH_CONTENT))->setSelected($objWasSelected[1])->setInputType(new S('submit'))->setContainerDiv(new B(TRUE))->setValue(new S(TEXTS_SEARCH_BY))->setName(new S('search_submit'))->setFormEndAndExecute(new B(TRUE));
             break;
         case 'textCreate':
             // The URL to go back too;
             $objURLToGoBack = URL::rewriteURL();
             // Do some work;
             if ($this->checkPOST(self::$objTextTableFTitle)->toBoolean() == TRUE) {
                 if ($this->getPOST(self::$objTextTableFTitle)->toLength()->toInt() == 0) {
                     $this->setErrorOnInput(self::$objTextTableFTitle, new S(TEXTS_TITLE_CANNOT_BE_EMPTY));
                 } else {
                     // Set some requirements ...
                     $objToCheck = $this->getPOST(self::$objTextTableFTitle);
                     // Check title is unique;
                     if ($this->checkTextTitleIsUnique($objToCheck)->toBoolean() == FALSE) {
                         $this->setErrorOnInput(self::$objTextTableFTitle, new S(TEXTS_TITLE_MUST_BE_UNIQUE));
                     }
                     // Check URL is unique;
                     if ($this->checkTextURLIsUnique(URL::getURLFromString(clone $objToCheck))->toBoolean() == FALSE) {
                         $this->setErrorOnInput(self::$objTextTableFTitle, new S(TEXTS_URL_MUST_BE_UNIQUE));
                     }
                 }
                 if ($this->getPOST(self::$objTextTableFContent)->toLength()->toInt() == 0) {
                     $this->setErrorOnInput(self::$objTextTableFContent, new S(TEXTS_CONTENT_CANNOT_BE_EMPTY));
                 }
             }
             // Get AJAX;
             $this->getAjaxErrors();
             // Do the form, make it happen;
             $this->setMethod(new S('POST'))->setName($objFormToRender)->setAJAXEnabledForm(new B(FALSE))->setFieldset(new S(TEXTS_ADD_ARTICLE))->setRedirect($objURLToGoBack)->setSQLAction(new S('update'))->setTableName(self::$objTextTable)->setUpdateId(new S('#nextTableAutoIncrement'))->setUpdateField(self::$objTextTableFId);
             if ($this->checkPOST(self::$objTextTableFTitle)->toBoolean() == TRUE) {
                 $this->setExtraUpdateData(self::$objTextTableFSEO, URL::getURLFromString($this->getPOST(self::$objTextTableFTitle)));
             }
             // ONLY if != BIG-MAN;
             if ((int) $this->ATH->getCurrentUserInfoById(Authentication::$objAuthUsersTableFId)->toString() != 1) {
                 $this->setExtraUpdateData(self::$objTextTableAuthorId, $this->ATH->getCurrentUserInfoById(Authentication::$objAuthUsersTableFId));
             }
             // Add the SEO ...
             $this->setExtraUpdateData(self::$objTextTableFDatePublished, new S((string) $_SERVER['REQUEST_TIME']))->setInputType(new S('submit'))->setValue(new S(TEXTS_ADD_ARTICLE))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objTextTableFTags)->setLabel(new S(TEXTS_TAGS))->setJSRegExpReplace(new S(self::REGEXP_JS_TAGS))->setContainerDiv(new B(TRUE));
             // If we're the BIG MAN, we can set the author of an entry;
             if ((int) $this->ATH->getCurrentUserInfoById(Authentication::$objAuthUsersTableFId)->toString() == 1) {
                 $this->setInputType(new S('select'))->setName(self::$objTextTableFAuthorId)->setLabel(new S(TEXTS_AUTHOR))->setContainerDiv(new B(TRUE));
                 // Categories ...
                 foreach ($this->ATH->getUsers() as $k => $v) {
                     $this->setInputType(new S('option'))->setName($v[Authentication::$objAuthUsersTableFId])->setValue($v[Authentication::$objAuthUsersTableFId])->setLabel($v[Authentication::$objAuthUsersTableFUName]);
                 }
             }
             $this->setInputType(new S('select'))->setLabel(new S(TEXTS_CATEGORY_NAME_LABEL))->setName(self::$objTextTableFCategoryId)->setContainerDiv(new B(TRUE));
             // Categories;
             foreach (self::$objMPTT->mpttGetTree() as $k => $v) {
                 $this->setInputType(new S('option'))->setName($v[self::$objCategoryTableFId])->setValue($v[self::$objCategoryTableFId])->setLabel(new S(str_repeat('--' . _SP, (int) $v['depth']->toString()) . $v[self::$objCategoryTableFName]));
             }
             // Continue;
             $this->setInputType(new S('select'))->setName(self::$objTextTableFCanComment)->setLabel(new S(TEXTS_CAN_COMMENT))->setContainerDiv(new B(TRUE))->setInputType(new S('option'))->setName(new S('no'))->setValue(new S('N'))->setLabel(new S(TEXTS_CAN_COMMENT_NO))->setInputType(new S('option'))->setName(new S('yes'))->setValue(new S('Y'))->setLabel(new S(TEXTS_CAN_COMMENT_YES))->setInputType(new S('text'))->setName(self::$objTextTableFTitle)->setLabel(new S(TEXTS_TITLE))->setJSRegExpReplace(new S(self::REGEXP_JS_TITLE))->setContainerDiv(new B(TRUE))->setInputType(new S('textarea'))->setName(self::$objTextTableFContent)->setLabel(new S(TEXTS_CONTENT))->setTinyMCETextarea(new B(TRUE))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE));
             break;
         case 'textEdit':
             // The URL to go back too;
             $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION, ADMIN_ACTION_ID)));
             // Do some work;
             if ($this->checkPOST()->toBoolean() == TRUE) {
                 if ($this->getPOST(self::$objTextTableFTitle)->toLength()->toInt() == 0) {
                     $this->setErrorOnInput(self::$objTextTableFTitle, new S(TEXTS_TITLE_CANNOT_BE_EMPTY));
                 }
                 if ($this->getPOST(self::$objTextTableFContent)->toLength()->toInt() == 0) {
                     $this->setErrorOnInput(self::$objTextTableFContent, new S(TEXTS_CONTENT_CANNOT_BE_EMPTY));
                 }
             }
             // Get AJAX;
             $this->getAjaxErrors();
             // Do the form, make it happen;
             $this->setMethod(new S('POST'))->setFieldset(new S(TEXTS_EDIT_ARTICLE))->setAJAXEnabledForm(new B(FALSE))->setRedirect($objURLToGoBack)->setSQLAction(new S('update'))->setTableName(self::$objTextTable)->setUpdateId($_GET[ADMIN_ACTION_ID])->setUpdateField(self::$objTextTableFId)->setName($objFormToRender)->setExtraUpdateData(self::$objTextTableFDateUpdated, new S((string) $_SERVER['REQUEST_TIME']))->setInputType(new S('submit'))->setValue(new S(TEXTS_EDIT_ARTICLE))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objTextTableFTags)->setLabel(new S(TEXTS_TAGS))->setJSRegExpReplace(new S(self::REGEXP_JS_TAGS));
             // Add the SEO ...
             if ($this->checkPOST(self::$objTextTableFTitle)->toBoolean() == TRUE) {
                 $this->setExtraUpdateData(self::$objTextTableFSEO, URL::getURLFromString($this->getPOST(self::$objTextTableFTitle)));
             }
             // If we're the BIG MAN, we can set the author of an entry;
             if ((int) $this->ATH->getCurrentUserInfoById(Authentication::$objAuthUsersTableFId)->toString() == 1) {
                 $this->setInputType(new S('select'))->setName(self::$objTextTableFAuthorId)->setLabel(new S(TEXTS_AUTHOR))->setContainerDiv(new B(TRUE));
                 // Users ...
                 foreach ($this->ATH->getUsers() as $k => $v) {
                     $this->setInputType(new S('option'))->setName($v[Authentication::$objAuthUsersTableFId])->setValue($v[Authentication::$objAuthUsersTableFId])->setLabel($v[Authentication::$objAuthUsersTableFUName]);
                 }
             }
             $this->setContainerDiv(new B(TRUE))->setInputType(new S('select'))->setName(self::$objTextTableFCategoryId)->setLabel(new S(TEXTS_CATEGORY_NAME_LABEL))->setContainerDiv(new B(TRUE));
             // Categories ...
             foreach (self::$objMPTT->mpttGetTree() as $k => $v) {
                 $this->setInputType(new S('option'))->setName($v[self::$objCategoryTableFId])->setValue($v[self::$objCategoryTableFId])->setLabel(new S(str_repeat('--' . _SP, (int) $v['depth']->toString()) . $v[self::$objCategoryTableFName]));
             }
             // Continue;
             $this->setInputType(new S('select'))->setName(self::$objTextTableFCanComment)->setLabel(new S(TEXTS_CAN_COMMENT))->setContainerDiv(new B(TRUE))->setInputType(new S('option'))->setName(new S('no'))->setValue(new S('N'))->setLabel(new S(TEXTS_CAN_COMMENT_NO))->setInputType(new S('option'))->setName(new S('yes'))->setValue(new S('Y'))->setLabel(new S(TEXTS_CAN_COMMENT_YES))->setInputType(new S('text'))->setName(self::$objTextTableFTitle)->setLabel(new S(TEXTS_TITLE))->setJSRegExpReplace(new S(self::REGEXP_JS_TITLE))->setContainerDiv(new B(TRUE))->setInputType(new S('textarea'))->setName(self::$objTextTableFContent)->setLabel(new S(TEXTS_CONTENT))->setTinyMCETextarea(new B(TRUE))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE));
             break;
         case 'textErase':
             // The URL to go back too;
             $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION, ADMIN_ACTION_ID)));
             // Do erase it ...
             $this->_Q(_QS('doDELETE')->doToken('%table', self::$objTextTable)->doToken('%condition', new S('%objTextTableFId = "%Id"'))->doToken('%Id', $_GET[ADMIN_ACTION_ID]));
             // And ALL associated comments ...
             $this->_Q(_QS('doDELETE')->doToken('%table', self::$objCommentsTable)->doToken('%condition', new S('%objCommentsTableFTextId = "%Id"'))->doToken('%Id', $_GET[ADMIN_ACTION_ID]));
             // Do a redirect, and get the user back where he belongs;
             $this->setHeaderKey($objURLToGoBack, new S('Location'));
             break;
         case 'commentEdit':
             // The URL to go back too;
             $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION, ADMIN_ACTION_ID)));
             // Do the form, make it happen;
             $this->setMethod(new S('POST'))->setFieldset(new S(TEXTS_EDIT_COMMENT))->setAJAXEnabledForm(new B(FALSE))->setRedirect($objURLToGoBack)->setSQLAction(new S('update'))->setTableName(self::$objCommentsTable)->setUpdateId($_GET[ADMIN_ACTION_ID])->setUpdateField(self::$objCommentsTableFId)->setName($objFormToRender)->setInputType(new S('submit'))->setValue(new S(TEXTS_EDIT_COMMENT))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('select'))->setName(self::$objCommentsTableFApproved)->setLabel(new S(TEXTS_COMMENT_APPROVED))->setContainerDiv(new B(TRUE))->setInputType(new S('option'))->setName(new S('no'))->setValue(new S('N'))->setLabel(new S(TEXTS_CAN_COMMENT_NO))->setInputType(new S('option'))->setName(new S('yes'))->setValue(new S('Y'))->setLabel(new S(TEXTS_CAN_COMMENT_YES))->setInputType(new S('textarea'))->setName(self::$objCommentsTableFComment)->setLabel(new S(TEXTS_COMMENT))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE));
             break;
         case 'commentErase':
             // The URL to go back too;
             $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION, ADMIN_ACTION_ID)));
             // Do erase it ...
             $this->_Q(_QS('doDELETE')->doToken('%table', self::$objCommentsTable)->doToken('%condition', new S('%objCommentsTableFId = "%Id"'))->doToken('%Id', $_GET[ADMIN_ACTION_ID]));
             // Do a redirect, and get the user back where he belongs;
             $this->setHeaderKey($objURLToGoBack, new S('Location'));
             break;
         case 'textCategoryCreate':
             // The URL to go back too;
             $objURLToGoBack = URL::rewriteURL();
             // Do some work ...
             if ($this->checkPOST(new S('categories_show_all'))->toBoolean() == TRUE) {
                 // Redirect to proper ...
                 $this->setHeaderKey(URL::rewriteURL(new A(array(ADMIN_SHOW_ALL)), new A(array('1'))), new S('Location'));
             }
             // Do some work;
             if ($this->checkPOST(new S('add_category_submit'))->toBoolean() == TRUE) {
                 // Set some requirements;
                 $objFormHappened = new B(FALSE);
                 if ($this->getPOST(new S('add_category'))->toLength()->toInt() == 0) {
                     // Check for empty group name, and error on it;
                     $this->setErrorOnInput(new S('add_category'), new S(TEXTS_CATEGORY_NAME_CANNOT_BE_EMPTY));
                     // Set to memory;
                     $objFormHappened->switchType();
                 } else {
                     if (self::$objMPTT->mpttCheckIfNodeExists($this->getPOST(new S('add_category')))->toBoolean() == TRUE) {
                         // Check to see if the group exists;
                         $this->setErrorOnInput(new S('add_category'), new S(TEXTS_CATEGORY_ALREADY_EXISTS));
                         // Set to memory;
                         $objFormHappened->switchType();
                     }
                 }
                 // Get AJAX;
                 $this->getAjaxErrors();
                 if ($objFormHappened->toBoolean() == FALSE) {
                     // Remember if we should add it as a brother or child;
                     $objAddNodeAS = NULL;
                     switch ($this->getPOST(new S('add_category_as_what'))) {
                         case TEXTS_CATEGORY_CHILD:
                             $objAddNodeAS = new S((string) MPTT::FIRST_CHILD);
                             break;
                         case TEXTS_CATEGORY_LAST_CHILD:
                             $objAddNodeAS = new S((string) MPTT::LAST_CHILD);
                             break;
                         case TEXTS_CATEGORY_BROTHER:
                             $objAddNodeAS = new S((string) MPTT::PREVIOUS_BROTHER);
                             break;
                         case TEXTS_CATEGORY_NEXT_BROTHER:
                             $objAddNodeAS = new S((string) MPTT::NEXT_BROTHER);
                             break;
                     }
                     // Add the node;
                     self::$objMPTT->mpttAddNode($this->getPOST(new S('add_category')), $this->getPOST(new S('add_category_parent_or_bro')), $objAddNodeAS);
                     // Redirect back;
                     $this->setHeaderKey($objURLToGoBack, new S('Location'));
                 }
             }
             // Do the form, make it happen;
             $this->setMethod(new S('POST'))->setFieldset(new S(TEXTS_ADD_CATEGORY))->setName($objFormToRender)->setAJAXEnabledForm(new B(FALSE))->setInputType(new S('submit'))->setName(new S('categories_show_all'))->setValue(new S(TEXTS_SHOW_ALL_CATEGORIES))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('submit'))->setContainerDiv(new B(TRUE))->setName(new S('add_category_submit'))->setValue(new S(TEXTS_ADD_CATEGORY))->setInputType(new S('text'))->setContainerDiv(new B(TRUE))->setName(new S('add_category'))->setLabel(new S(TEXTS_CATEGORY_NAME_LABEL))->setJSRegExpReplace(new S(self::REGEXP_JS_CATEGORY))->setInputType(new S('select'))->setContainerDiv(new B(TRUE))->setName(new S('add_category_as_what'))->setLabel(new S(TEXTS_AS_A))->setInputType(new S('option'))->setName(new S('as_child'))->setLabel(new S(TEXTS_CATEGORY_CHILD))->setInputType(new S('option'))->setName(new S('as_child'))->setLabel(new S(TEXTS_CATEGORY_LAST_CHILD))->setInputType(new S('option'))->setName(new S('as_brother'))->setLabel(new S(TEXTS_CATEGORY_BROTHER))->setInputType(new S('option'))->setName(new S('as_brother'))->setLabel(new S(TEXTS_CATEGORY_NEXT_BROTHER))->setInputType(new S('select'))->setContainerDiv(new B(TRUE))->setName(new S('add_category_parent_or_bro'))->setLabel(new S(TEXTS_OF_CATEGORY));
             // Categories ...
             foreach (self::$objMPTT->mpttGetTree() as $k => $v) {
                 $this->setInputType(new S('option'))->setName($v[self::$objCategoryTableFName])->setValue($v[self::$objCategoryTableFName])->setLabel(new S(str_repeat('--' . _SP, (int) $v['depth']->toString()) . $v[self::$objCategoryTableFName]));
             }
             // Execute the form;
             $this->setFormEndAndExecute(new B(TRUE));
             break;
         case 'textCategoryEdit':
             // The URL to go back too;
             $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION, ADMIN_ACTION_ID)));
             // Do some work;
             if ($this->checkPOST()->toBoolean() == TRUE) {
                 // Set some requirements;
                 $objFormHappened = new B(FALSE);
                 if ($this->getPOST(self::$objCategoryTableFName)->toLength()->toInt() == 0) {
                     // Check for empty group name, and error on it;
                     $this->setErrorOnInput(self::$objCategoryTableFName, new S(CATEGORY_NAME_CANNOT_BE_EMPTY));
                     // Set to memory;
                     $objFormHappened->switchType();
                 } else {
                     if (self::$objMPTT->mpttCheckIfNodeExists($this->getPOST(self::$objCategoryTableFName))->toBoolean() == TRUE) {
                         // Check to see if the group exists;
                         $this->setErrorOnInput(self::$objCategoryTableFName, new S(TEXTS_CATEGORY_ALREADY_EXISTS));
                         // Set to memory;
                         $objFormHappened->switchType();
                     }
                 }
                 // Get AJAX;
                 $this->getAjaxErrors();
             } else {
                 // Do nothing ...
                 $objFormHappened = new B(TRUE);
             }
             // Do the form, make it happen;
             $this->setMethod(new S('POST'))->setSQLAction(new S('update'))->setTableName(self::$objCategoryTable)->setUpdateId($_GET[ADMIN_ACTION_ID])->setUpdateField(self::$objCategoryTableFId)->setFieldset(new S(TEXTS_EDIT_CATEGORY));
             if ($objFormHappened->toBoolean() == FALSE) {
                 $this->setRedirect($objURLToGoBack, new S('Location'));
             }
             $this->setName($objFormToRender)->setAJAXEnabledForm(new B(FALSE));
             // Add the SEO ...
             if ($this->checkPOST(self::$objCategoryTableFName)->toBoolean() == TRUE) {
                 $this->setExtraUpdateData(self::$objCategoryTableFSEO, URL::getURLFromString($this->getPOST(self::$objCategoryTableFName)));
             }
             $this->setInputType(new S('submit'))->setName(new S('edit_category_submit'))->setValue(new S(TEXTS_EDIT_CATEGORY))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objCategoryTableFName)->setLabel(new S(TEXTS_CATEGORY_NAME_LABEL))->setJSRegExpReplace(new S(self::REGEXP_JS_CATEGORY))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE));
             break;
         case 'textCategoryErase':
             // The URL to go back too;
             $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION, ADMIN_ACTION_ID)));
             // Memorize if it has kids;
             $objNodeHasKids = new B(FALSE);
             if ($this->getTextCount(_S('WHERE %objTextTableFCategoryId = "%Id"')->doToken('%Id', $_GET[ADMIN_ACTION_ID]))->toInt() != 0) {
                 // Set an error message;
                 self::$objAdministration->setErrorMessage(new S(TEXTS_CANNOT_DELETE_CATEGORY_WA), $objURLToGoBack);
             } else {
                 // Do erase the group node from the table;
                 self::$objMPTT->mpttRemoveNode($this->getCategoryInfoById($_GET[ADMIN_ACTION_ID], self::$objCategoryTableFName));
                 // Do a redirect, and get the user back where he belongs;
                 $this->setHeaderKey($objURLToGoBack, new S('Location'));
             }
             break;
         case 'textCategoryMove':
             // Set some predefines;
             $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION, ADMIN_ACTION_TO, ADMIN_ACTION_TYPE)));
             // Get names, as they are unique;
             $objThatIsMoved = $this->getCategoryInfoById($_GET[ADMIN_ACTION_ID], self::$objCategoryTableFName);
             $objWhereToMove = $this->getCategoryInfoById($_GET[ADMIN_ACTION_TO], self::$objCategoryTableFName);
             $objMovedNodeSubTree = self::$objMPTT->mpttGetTree($objThatIsMoved);
             // Memorize;
             $objIsChild = new B(FALSE);
             foreach ($objMovedNodeSubTree as $k => $v) {
                 if ($v[self::$objMPTT->objNameOfNode] == $objWhereToMove) {
                     $objIsChild->switchType();
                 }
             }
             // Check if it's a child or not;
             if ($objIsChild->toBoolean() == TRUE) {
                 // Set an error message;
                 self::$objAdministration->setErrorMessage(new S(TEXTS_CATEGORY_MOVED_TO_CHILD), $objURLToGoBack);
             } else {
                 // Move nodes;
                 self::$objMPTT->mpttMoveNode($objThatIsMoved, $objWhereToMove, $_GET[ADMIN_ACTION_TYPE]);
                 $this->setHeaderKey($objURLToGoBack, new S('Location'));
             }
             // Break out ...
             break;
         case 'categoryMoveOperation':
             // The URL to go back too;
             $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_SUBPAGE)), new A(array(MANAGE_TEXTS)));
             // Do some work;
             $this->checkPOST()->toBoolean() == TRUE ? $objOLDCategoryId = $this->getPOST(new S('old_category_id')) : ($objOLDCategoryId = new S('0'));
             // Do the form, make it happen;
             $this->setMethod(new S('POST'))->setFieldset(new S(TEXTS_MOVE_ARTICLE))->setSQLAction(new S('update'))->setTableName(self::$objTextTable)->setUpdateField(self::$objTextTableFId)->setUpdateWhere($this->doModuleToken(_S('%objTextTableFCategoryId = "%Id"')->doToken('%Id', $objOLDCategoryId)))->setName($objFormToRender)->setRedirect($objURLToGoBack)->setInputType(new S('submit'))->setValue(new S(TEXTS_MOVE_ARTICLE))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('select'))->setName(new S('old_category_id'))->setLabel(new S(TEXTS_OLD_CATEGORY))->setContainerDiv(new B(TRUE));
             // Categories ...
             foreach (self::$objMPTT->mpttGetTree() as $k => $v) {
                 $this->setInputType(new S('option'))->setName($v[self::$objMPTT->objIdField])->setValue($v[self::$objMPTT->objIdField])->setLabel(new S(str_repeat('--' . _SP, (int) $v['depth']->toString()) . $v[self::$objMPTT->objNameOfNode]));
             }
             // Continue ...
             $this->setInputType(new S('select'))->setName(self::$objTextTableFCategoryId)->setLabel(new S(TEXTS_NEW_CATEGORY))->setContainerDiv(new B(TRUE));
             // Categories, again ...
             foreach (self::$objMPTT->mpttGetTree() as $k => $v) {
                 $this->setInputType(new S('option'))->setName($v[self::$objMPTT->objIdField])->setValue($v[self::$objMPTT->objIdField])->setLabel(new S(str_repeat('--' . _SP, (int) $v['depth']->toString()) . $v[self::$objMPTT->objNameOfNode]));
             }
             // Continue ...
             $this->setFormEndAndExecute(new B(TRUE));
             break;
         case 'configurationEdit':
             // Set the URL to go back too;
             $objURLToGoBack = new S();
             // Do some work;
             if ($this->checkPOST()->toBoolean() == TRUE) {
                 $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION)), new A(array($this->getPOST(new S('what')))));
             }
             // Do the form, make it happen;
             $this->setMethod(new S('POST'))->setFieldset(new S(MANAGE_TEXTS_CONFIG))->setName($objFormToRender)->setRedirect($objURLToGoBack)->setInputType(new S('submit'))->setValue(new S(TEXTS_CONFIG_DO))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('select'))->setName(new S('what'))->setLabel(new S(TEXTS_CONFIG_CHOOSE))->setContainerDiv(new B(TRUE))->setInputType(new S('option'))->setName(new S('configurationEditMustBeAuthToComment'))->setValue(new S('configurationEditMustBeAuthToComment'))->setLabel(new S(TEXTS_USER_MUST_BE_LOGGED_TO_COMMENT))->setInputType(new S('option'))->setName(new S('configurationEditTextsPerCategory'))->setValue(new S('configurationEditTextsPerCategory'))->setLabel(new S(TEXTS_PER_CATEGORY))->setFormEndAndExecute(new B(TRUE));
             break;
         case 'configurationEditMustBeAuthToComment':
             // The URL to go back too;
             $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION)));
             // Do some work;
             if ($this->checkPOST()->toBoolean() == TRUE) {
                 foreach ($this->getPOST() as $k => $v) {
                     $this->setConfigKey(new S($k), $v);
                 }
             }
             // Do the form, make it happen;
             $this->setMethod(new S('POST'))->setFieldset(new S(TEXTS_UPDATE_CONFIGURATION))->setName($objFormToRender)->setRedirect($objURLToGoBack)->setInputType(new S('submit'))->setValue(new S(TEXTS_UPDATE_CONFIGURATION))->setContainerDiv(new B(TRUE))->setInputType(new S('select'))->setName(new S('texts_settings_authenticated_to_comment'))->setLabel(new S(TEXTS_CONFIG_CHOOSE))->setContainerDiv(new B(TRUE))->setInputType(new S('option'))->setName(new S('yes'))->setValue(new S('Y'))->setLabel(new S('Yes'))->setSelected($this->getConfigKey(new S('texts_settings_authenticated_to_comment')) == 'Y' ? new B(TRUE) : new B(FALSE))->setInputType(new S('option'))->setName(new S('no'))->setValue(new S('N'))->setLabel(new S('No'))->setSelected($this->getConfigKey(new S('texts_settings_authenticated_to_comment')) == 'N' ? new B(TRUE) : new B(FALSE))->setFormEndAndExecute(new B(TRUE));
             break;
         case 'configurationEditTextsPerCategory':
             // The URL to go back too;
             $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION)));
             // Do some work;
             if ($this->checkPOST()->toBoolean() == TRUE) {
                 foreach ($this->getPOST() as $k => $v) {
                     $this->setConfigKey(new S($k), $v);
                 }
             }
             // Do the form, make it happen;
             $this->setMethod(new S('POST'))->setFieldset(new S(TEXTS_UPDATE_CONFIGURATION))->setName($objFormToRender)->setRedirect($objURLToGoBack)->setInputType(new S('submit'))->setValue(new S(TEXTS_UPDATE_CONFIGURATION))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(new S('texts_settings_per_page'))->setLabel(new S(TEXTS_PER_PAGE))->setValue($this->getConfigKey(new S('texts_settings_per_page')))->setRegExpType(new S('ereg'))->setRegExpErrMsg(new S(TEXTS_CONFIG_PER_PAGE_ERROR))->setPHPRegExpCheck(new S('[0-9]'))->setJSRegExpReplace(new S('[^0-9]'))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE));
             break;
     }
 }
Esempio n. 7
0
 function checkOverdue()
 {
     $sql = 'SELECT ticket_id FROM ' . TICKET_TABLE . ' T1 ' . ' INNER JOIN ' . TICKET_STATUS_TABLE . ' status
             ON (status.id=T1.status_id AND status.state="open") ' . ' LEFT JOIN ' . SLA_TABLE . ' T2 ON (T1.sla_id=T2.id AND T2.isactive=1) ' . ' WHERE isoverdue=0 ' . ' AND ((reopened is NULL AND duedate is NULL AND TIME_TO_SEC(TIMEDIFF(NOW(),T1.created))>=T2.grace_period*3600) ' . ' OR (reopened is NOT NULL AND duedate is NULL AND TIME_TO_SEC(TIMEDIFF(NOW(),reopened))>=T2.grace_period*3600) ' . ' OR (duedate is NOT NULL AND duedate<NOW()) ' . ' ) ORDER BY T1.created LIMIT 50';
     //Age upto 50 tickets at a time?
     if (($res = db_query($sql)) && db_num_rows($res)) {
         while (list($id) = db_fetch_row($res)) {
             if (($ticket = Ticket::lookup($id)) && $ticket->markOverdue()) {
                 $ticket->logActivity(_S('Ticket Marked Overdue'), _S('Ticket flagged as overdue by the system.'));
             }
         }
     } else {
         //TODO: Trigger escalation on already overdue tickets - make sure last overdue event > grace_period.
     }
 }
Esempio n. 8
0
 function logDBError($title, $error, $alert = true)
 {
     if ($alert && !$this->getConfig()->alertONSQLError()) {
         $alert = false;
     }
     $e = new Exception();
     $bt = str_replace(ROOT_DIR, _S('(root)') . '/', $e->getTraceAsString());
     $error .= nl2br("\n\n---- " . _S('Backtrace') . " ----\n" . $bt);
     return $this->log(LOG_ERR, $title, $error, $alert);
 }
Esempio n. 9
0
 /**
  * Sets some automatic RA PHP Framework .htaccess options that really drive the core of the framework. These include some Apache
  * specific settings, or some of the PHP_INI_PERDIR configuration options that can be set only through the .htaccess file. Also,
  * the auto_append_file and auto_prepend_file settings are automatically written here so the developer is cleared having to
  * think what's included and where, as we provide an autoloading mechanism for this framework;
  *
  * @return B Will return true if everything was fine and dandy
  * @author Catalin Z. Alexandru <*****@*****.**>
  * @copyright Under the terms of the GNU General Public License v3
  * @version $Id: 07_APC.php 313 2009-10-09 13:27:52Z catalin.zamfir $
  * @since Version 1.0
  * @access protected
  * @static
  * @final
  */
 protected static final function setHTAutoPHP()
 {
     self::$objHTWriteIt = new I(1);
     if (is_writeable(DOCUMENT_ROOT)) {
         // Make them URLs VALID && the 401 error URL, needs to be LOCAL ...
         define('ERROR_DOC_HOST', _S(DOCUMENT_HOST)->doToken(_SP, '%20')->doToken('www.', _NONE));
         define('ERROR_401_HOST', _S(DOCUMENT_HOST)->doToken(_SP, '%20')->doToken(DOCUMENT_HOST, _NONE));
         // We need some .htaccess defaults;
         self::$objHT[] = 'IndexIgnore *';
         self::$objHT[] = 'AddType text/x-component .htc';
         self::$objHT[] = 'SetEnv TZ ' . DATE_TIMEZONE;
         self::$objHT[] = 'Options All ' . APACHE_OPTIONS;
         self::$objHT[] = 'AddDefaultCharset ' . DEFAULT_CHARSET;
         self::$objHT[] = 'ServerSignature ' . APACHE_SERVER_SIGNATURE;
         self::$objHT[] = 'php_value auto_prepend_file "' . DOCUMENT_ROOT . INCLUDE_DIR . _S . AUTO_PREPEND_FILE . '"';
         self::$objHT[] = 'php_value auto_append_file  "' . DOCUMENT_ROOT . INCLUDE_DIR . _S . AUTO_APPEND_FILE . '"';
         self::$objHT[] = 'php_value upload_max_filesize ' . UPLOAD_MAX_FILESIZE;
         self::$objHT[] = 'php_value post_max_size ' . POST_MAX_SIZE;
         self::$objHT[] = 'php_value asp_tags ' . ASP_TAGS;
         self::$objHT[] = 'php_value register_long_arrays ' . REGISTER_LONG_GPC;
         self::$objHT[] = 'php_value short_open_tag ' . SHORT_OPEN_TAG;
         self::$objHT[] = 'php_value max_input_time ' . MAX_INPUT_TIME;
         self::$objHT[] = 'php_value tidy.clean_output ' . TIDY_CLEAN_OUTPUT;
         self::$objHT[] = 'php_value session.gc_maxlifetime ' . SESSIONCACHEEXPIRE;
         self::$objHT[] = 'php_value session.use_trans_sid ' . SESSION_USE_TRANSPARENT_ID;
         self::$objHT[] = 'ErrorDocument 400 ' . ERROR_DOC_HOST . 'Error/400';
         self::$objHT[] = 'ErrorDocument 401 ' . ERROR_401_HOST . 'Error/401';
         self::$objHT[] = 'ErrorDocument 402 ' . ERROR_DOC_HOST . 'Error/402';
         self::$objHT[] = 'ErrorDocument 403 ' . ERROR_DOC_HOST . 'Error/403';
         self::$objHT[] = 'ErrorDocument 404 ' . ERROR_DOC_HOST . 'Error/404';
         self::$objHT[] = 'ErrorDocument 405 ' . ERROR_DOC_HOST . 'Error/405';
         self::$objHT[] = 'ErrorDocument 406 ' . ERROR_DOC_HOST . 'Error/406';
         self::$objHT[] = 'ErrorDocument 407 ' . ERROR_DOC_HOST . 'Error/407';
         self::$objHT[] = 'ErrorDocument 408 ' . ERROR_DOC_HOST . 'Error/408';
         self::$objHT[] = 'ErrorDocument 409 ' . ERROR_DOC_HOST . 'Error/409';
         self::$objHT[] = 'ErrorDocument 410 ' . ERROR_DOC_HOST . 'Error/410';
         self::$objHT[] = 'ErrorDocument 411 ' . ERROR_DOC_HOST . 'Error/411';
         self::$objHT[] = 'ErrorDocument 412 ' . ERROR_DOC_HOST . 'Error/412';
         self::$objHT[] = 'ErrorDocument 413 ' . ERROR_DOC_HOST . 'Error/413';
         self::$objHT[] = 'ErrorDocument 414 ' . ERROR_DOC_HOST . 'Error/414';
         self::$objHT[] = 'ErrorDocument 415 ' . ERROR_DOC_HOST . 'Error/415';
         self::$objHT[] = 'ErrorDocument 416 ' . ERROR_DOC_HOST . 'Error/416';
         self::$objHT[] = 'ErrorDocument 417 ' . ERROR_DOC_HOST . 'Error/417';
         self::$objHT[] = 'ErrorDocument 422 ' . ERROR_DOC_HOST . 'Error/422';
         self::$objHT[] = 'ErrorDocument 423 ' . ERROR_DOC_HOST . 'Error/423';
         self::$objHT[] = 'ErrorDocument 424 ' . ERROR_DOC_HOST . 'Error/424';
         self::$objHT[] = 'ErrorDocument 426 ' . ERROR_DOC_HOST . 'Error/426';
         self::$objHT[] = 'ErrorDocument 500 ' . ERROR_DOC_HOST . 'Error/500';
         self::$objHT[] = 'ErrorDocument 501 ' . ERROR_DOC_HOST . 'Error/501';
         self::$objHT[] = 'ErrorDocument 502 ' . ERROR_DOC_HOST . 'Error/502';
         self::$objHT[] = 'ErrorDocument 503 ' . ERROR_DOC_HOST . 'Error/503';
         self::$objHT[] = 'ErrorDocument 504 ' . ERROR_DOC_HOST . 'Error/504';
         self::$objHT[] = 'ErrorDocument 505 ' . ERROR_DOC_HOST . 'Error/505';
         self::$objHT[] = 'ErrorDocument 506 ' . ERROR_DOC_HOST . 'Error/506';
         self::$objHT[] = 'ErrorDocument 507 ' . ERROR_DOC_HOST . 'Error/507';
         self::$objHT[] = 'ErrorDocument 510 ' . ERROR_DOC_HOST . 'Error/510';
         // Add CSS/JS PHP interpretation;
         if (PHPIZE_JSS_FILES == TRUE) {
             self::$objHT[] = 'AddHandler application/x-httpd-php .js';
         }
         if (PHPIZE_CSS_FILES == TRUE) {
             self::$objHT[] = 'AddHandler application/x-httpd-php .css';
         }
         // Check the mod_rewrite is ON;
         if (in_array('mod_rewrite', apache_get_modules())) {
             // What should we do with the REWRITE_ENGINE
             REWRITE_ENGINE == TRUE ? self::rewriteHTLine(new S('RewriteEngine On')) : self::rewriteHTLine(new S('RewriteEngine Off'));
             // ONLY, if the rewrite is OK;
             if (REWRITE_ENGINE == TRUE) {
                 // Protect US from BOTS;
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^BlackWidow [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^Bot\\ mailto:craftbot@yahoo.com [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^ChinaClaw [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^Custo [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^DISCo [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^Download\\ Demon [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^eCatch [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^EirGrabber [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^EmailSiphon [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^EmailWolf [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^Express\\ WebPictures [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^ExtractorPro [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^EyeNetIE [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^WebGo\\ IS [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^WebFetch [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^WebCopier [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^WebAuto [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^Web\\ Sucker [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^Web\\ Image\\ Collector [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^VoidEYE [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^Teleport\\ Pro [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^tAkeOut [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^Surfbot [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^SuperHTTP [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^SuperBot [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^SmartDownload [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^SiteSnagger [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^ReGet [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^RealDownload [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^pcBrowser [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^pavuk [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^Papa\\ Foto [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^PageGrabber [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^Offline\\ Navigator [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^Offline\\ Explorer [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^Octopus [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^NetZIP [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^Net\\ Vampire [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^NetSpider [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^NetAnts [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^NearSite [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^Navroad [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^Mister\\ PiX [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^MIDown\\ tool [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^Mass\\ Downloader [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^LeechFTP [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^larbin [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^JOC\\ Web\\ Spider [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^JetCar [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^Internet\\ Ninja [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^InterGET [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} Indy\\ Library [NC,OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^Image\\ Sucker [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^Image\\ Stripper [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} HTTrack [NC,OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^HMView [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^Grafula [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^GrabNet [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^Go-Ahead-Got-It [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^GetWeb! [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^Go!Zilla [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^GetRight [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^FlashGet [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^WebLeacher [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^WebSauger [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^Website\\ eXtractor [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^Website\\ Quester [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^WebStripper [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^WebWhacker [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^WebZIP [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^Wget [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^Widow [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^WWWOFFLE [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^Xaldon\\ WebSpider [OR]'));
                 self::rewriteHTLine(new S('RewriteCond %{HTTP_USER_AGENT} ^Zeus'));
                 self::rewriteHTLine(new S('RewriteRule ^.* - [F,L]'));
                 // Make'em SEO friendly, the mod_rewrite way (non-PHP);
                 self::rewriteHTLine(new S('RewriteCond %{REQUEST_FILENAME} !-f'));
                 self::rewriteHTLine(new S('RewriteCond %{REQUEST_FILENAME} !-d'));
                 self::rewriteHTLine(new S('RewriteRule ^((.*)/(.*))$ index.php/$1 [L]'));
             }
         }
     } else {
         // CHECK: We can write the .htaccess file;
         self::renderScreenOfDeath(new S(__CLASS__), new S(CANNOT_WRITE_HTACCESS_FILE), new S(CANNOT_WRITE_HTACCESS_FILE_FIX));
     }
     // CHECK: The CCH directory is writeable ...
     if (!is_writeable(DOCUMENT_ROOT . CACHE_DIR)) {
         self::renderScreenOfDeath(new S(__CLASS__), new S(CANNOT_WRITE_CACHE_DIR), new S(CANNOT_WRITE_FIX_PERMISSIONS));
     }
     // CHECK: The LOG directory is writeable ...
     if (!is_writeable(DOCUMENT_ROOT . LOG_DIR)) {
         self::renderScreenOfDeath(new S(__CLASS__), new S(CANNOT_WRITE_LOG_DIR), new S(CANNOT_WRITE_FIX_PERMISSIONS));
     }
     // CHECK: The UPD directory is writeable ...
     if (!is_writeable(DOCUMENT_ROOT . UPLOAD_DIR)) {
         self::renderScreenOfDeath(new S(__CLASS__), new S(CANNOT_WRITE_UPLOAD_DIR), new S(CANNOT_WRITE_FIX_PERMISSIONS));
     } else {
         if (!is_writeable(DOCUMENT_ROOT . UPLOAD_DIR . _S . TEMP_DIR)) {
             self::renderScreenOfDeath(new S(__CLASS__), new S(CANNOT_WRITE_TEMP_DIR), new S(CANNOT_WRITE_FIX_PERMISSIONS));
         }
     }
     // Do return ...
     return new B(TRUE);
 }
Esempio n. 10
0
 public function __construct()
 {
     // Construct any possible parent, parse the configuration while doing that;
     parent::__construct();
     // Tie in common configuration data;
     $this->tieInCommonConfiguration();
     // Set the proper configuration options for this object;
     self::$objAuthUsersTable = $this->getConfigKey(new S('authentication_users_table'));
     self::$objAuthUsersTableFId = $this->getConfigKey(new S('authentication_users_table_field_id'));
     self::$objAuthUsersTableFUName = $this->getConfigKey(new S('authentication_users_table_field_username'));
     self::$objAuthUsersTableFUPass = $this->getConfigKey(new S('authentication_users_table_field_password'));
     self::$objAuthUsersTableFEML = $this->getConfigKey(new S('authentication_users_table_field_email'));
     self::$objAuthUsersTableFPhone = $this->getConfigKey(new S('authentication_users_table_field_phone'));
     self::$objAuthUsersTableFFName = $this->getConfigKey(new S('authentication_users_table_field_first_name'));
     self::$objAuthUsersTableFLName = $this->getConfigKey(new S('authentication_users_table_field_last_name'));
     self::$objAuthUsersTableFUGId = $this->getConfigKey(new S('authentication_users_table_field_group_id'));
     self::$objAuthUsersTableFRegOn = $this->getConfigKey(new S('authentication_users_table_field_registered_on'));
     self::$objAuthUsersTableFLastLog = $this->getConfigKey(new S('authentication_users_table_field_visited_on'));
     self::$objAuthUsersTableFHash = $this->getConfigKey(new S('authentication_users_table_field_hash'));
     self::$objAuthUsersTableFActivated = $this->getConfigKey(new S('authentication_users_table_field_activated'));
     self::$objAuthUsersTableFCountry = $this->getConfigKey(new S('authentication_users_table_field_country'));
     self::$objAuthUsersTableFSignature = $this->getConfigKey(new S('authentication_users_table_field_signature'));
     self::$objAuthUsersTableFDesc = $this->getConfigKey(new S('authentication_users_table_field_description'));
     self::$objAuthUsersTableFYM = $this->getConfigKey(new S('authentication_users_table_field_ym'));
     self::$objAuthUsersTableFMSN = $this->getConfigKey(new S('authentication_users_table_field_msn'));
     self::$objAuthUsersTableFICQ = $this->getConfigKey(new S('authentication_users_table_field_icq'));
     self::$objAuthUsersTableFAOL = $this->getConfigKey(new S('authentication_users_table_field_aol'));
     self::$objAuthUsersTableFCity = $this->getConfigKey(new S('authentication_users_table_field_city'));
     self::$objAuthUsersTableFAvatar = $this->getConfigKey(new S('authentication_users_table_field_avatar'));
     self::$objAuthUsersTableFIp = $this->getConfigKey(new S('authentication_users_table_field_ip'));
     // Groups ...
     self::$objAuthGroupTable = $this->getConfigKey(new S('authentication_group_table'));
     self::$objAuthGroupTableFId = $this->getConfigKey(new S('authentication_group_table_field_id'));
     self::$objAuthGroupTableFName = $this->getConfigKey(new S('authentication_group_table_field_name'));
     self::$objAuthGroupTableFSEO = $this->getConfigKey(new S('authentication_group_table_field_seo'));
     // Zones ...
     self::$objAuthZonesTable = $this->getConfigKey(new S('authentication_zones_table'));
     self::$objAuthZonesTableFId = $this->getConfigKey(new S('authentication_zones_table_field_id'));
     self::$objAuthZonesTableFName = $this->getConfigKey(new S('authentication_zones_table_field_name'));
     self::$objAuthZonesTableFDesc = $this->getConfigKey(new S('authentication_zones_table_field_description'));
     self::$objAuthZonesTableFPrice = $this->getConfigKey(new S('authentication_zones_table_field_price'));
     // Zone mappings ...
     self::$objAuthZoneMTable = $this->getConfigKey(new S('authentication_gtozm_table'));
     self::$objAuthZoneMTableFId = $this->getConfigKey(new S('authentication_gtozm_table_field_id'));
     self::$objAuthZoneMTableFZId = $this->getConfigKey(new S('authentication_gtozm_table_field_zone_id'));
     self::$objAuthZoneMTableFUGId = $this->getConfigKey(new S('authentication_gtozm_table_field_ug_id'));
     self::$objAuthZoneMTableFIUG = $this->getConfigKey(new S('authentication_gtozm_table_field_is_group'));
     self::$objAuthZoneMTableFAorD = $this->getConfigKey(new S('authentication_gtozm_table_field_deny_or_allow'));
     self::$objAuthZoneMTableFErase = $this->getConfigKey(new S('authentication_gtozm_table_field_eraseable'));
     // Configuration ...
     self::$objAuthDefaultGroup = $this->getConfigKey(new S('authentication_default_group'));
     self::$objAuthDefaultUsername = $this->getConfigKey(new S('authentication_default_admin_username'));
     self::$objAuthDefaultPassword = $this->getConfigKey(new S('authentication_default_admin_password'));
     // DB: Auto-CREATE:
     $objQueryDB = new FileContent($this->getPathToModule()->toRelativePath() . _S . CFG_DIR . _S . __CLASS__ . SCH_EXTENSION);
     // Make a FOREACH on each ...
     foreach (_S($objQueryDB->toString())->fromStringToArray(RA_SCHEMA_HASH_TAG) as $k => $v) {
         // Make'em ...
         $this->_Q(_S($v));
     }
     // Check non-modified user data, to prevent hackers;
     if ($this->checkIfUserIsLoggedIn()->toBoolean() == TRUE) {
         $this->checkIfUserDataIsOK();
     }
     // Get an MPTT Object, build the ROOT, make sure the table is OK;
     self::$objMPTT = new MPTT(self::$objAuthGroupTable, self::$objAuthDefaultGroup);
     self::$objMPTTForZones = new MPTT(self::$objAuthZonesTable, $this->getObjectCLASS());
     // Load'em defaults ... ATH, STG and others ...
     $this->STG = MOD::activateModule(new FilePath('mod/settings'), new B(TRUE));
     // Check that the default administrator user exists, or create it;
     $this->setDefaultAdministratorSettings();
     // Check to see if this zone exists, and if not, add it;
     if ($this->checkZoneByName(new S(__CLASS__))->toBoolean() == FALSE) {
         $this->doMakeZone(new S(__CLASS__), self::$objAuthZonesTableFName);
     }
     if ($this->checkAdministratorIsMappedToZone($this->getObjectCLASS())->toBoolean() == FALSE) {
         $this->doMapAdministratorToZone($this->getObjectCLASS());
     }
     // Do the tie, with myself, just for sub-zones;
     $this->tieInWithAuthentication($this);
 }
Esempio n. 11
0
 /**
  * Will render a requested widget;
  *
  * This method is used to render a widget that usually is used in the frontend part of any website done with the help of this
  * platform. What are widgets you ask?! Well, it's quite simple. They are pieces of PHP code, usually tied to some
  * configuration options that control the way the widget functions or showns;
  *
  * Usually, configured widgets have enough power to be used in any way you want or need. For most of the times, the widgets
  * are called in the proper section of the frontend, but this method must permit the use of widgets, independent of the place
  * the developer needs them;
  *
  * @param $objWidgetToRender The widget to render;
  * @return mixed Depends on the widget;
  */
 public function renderWidget(S $objW, A $objWA = NULL)
 {
     // Make an empty array if NULL ...
     if ($objWA == NULL) {
         $objWA = new A();
     }
     // XML & RSS: Do a switch ...
     switch ($objW) {
         case 'widgetXML':
             // Yo man ... woohoooooo ...
             foreach ($this->getLyrics(_S('ORDER
             BY %objLyricsTableFDateAdded DESC LIMIT %LowerLimit, %UpperLimit')->doToken('%LowerLimit', ((int) $objWA['objId']->toString() - 1) * 25000)->doToken('%UpperLimit', 25000)) as $k => $v) {
                 // Set some requirements ...
                 $objDTE = date('Y-m-d', (int) $v[self::$objLyricsTableFDateAdded]->toString());
                 $objLOC = URL::staticURL(new A(array(LYRICS_ITEM_URL, FRONTEND_SECTION_URL)), new A(array($v[self::$objLyricsTableFSEO], FRONTEND_LYRICS_URL)));
                 // Get the (INNER) CHILD of every young SEO freak ...
                 $objURL = $objWA['objXML']->addCHILD(Frontend::XML_URL);
                 // Set the XML Sitemap kids ...
                 $objURL->addCHILD(Frontend::XML_LOCATION, $objLOC);
                 $objURL->addCHILD(Frontend::XML_LAST_MOD, $objDTE);
                 $objURL->addCHILD(Frontend::XML_CHANGE_FREQ, self::XML_SITEMAP_FREQUENCY);
                 $objURL->addCHILD(Frontend::XML_PRIORITY, self::XML_SITEMAP_PRIORITY);
             }
             // BK;
             break;
         case 'widgetRSS':
             // Yo man ... woohoooooo ...
             if ($_GET[FRONTEND_FEED_URL] == __CLASS__) {
                 // Get'em 30 ...
                 foreach ($this->getApprovedAudioFiles(new S('ORDER BY %objAudioTableFUploadedDate
                 DESC LIMIT 0, 30')) as $k => $v) {
                     // Set some requirements ...
                     $objDTE = date(DATE_RFC822, (int) $v[self::$objAudioTableFUploadedDate]->toString());
                     $objLOC = URL::staticURL(new A(array(AUDIO_ITEM_URL, FRONTEND_SECTION_URL)), new A(array($v[self::$objAudioTableFSEO], FRONTEND_AUDIO_URL)));
                     $objTTL = $v[self::$objAudioTableFTitle]->appendString(_DCSP)->appendString($v[self::$objAudioTableFArtist])->appendString(_DCSP)->appendString($v[self::$objAudioTableFAlbum]);
                     $objDSC = $v[self::$objAudioTableFDescription]->entityEncode(ENT_QUOTES)->entityDecode(ENT_QUOTES)->stripTags();
                     // Get the (INNER) CHILD of every young SEO freak ...
                     $objURL = $objWA['objXML']->addCHILD(Frontend::RSS_ITEM);
                     // Set the RSS kids ...
                     $objURL->addCHILD(Frontend::RSS_TITLE, $objTTL);
                     $objURL->addCHILD(Frontend::RSS_LINK, $objLOC);
                     $objURL->addCHILD(Frontend::RSS_GUID, $objLOC);
                     $objURL->addCHILD(Frontend::RSS_PUBLISHED_DATE, $objDTE);
                     $objURL->addCHILD(Frontend::RSS_DESCRIPTION, $objDSC);
                 }
             }
             // BK;
             break;
     }
     // Do a switch ...
     switch ($objW) {
         case 'widgetList':
             // Check some needed requirements ...
             if ($_GET[FRONTEND_SECTION_URL] == FRONTEND_LYRICS_URL) {
                 // Set some requirements ...
                 $objPag = isset($_GET[LYRICS_PAGE_URL]) ? $_GET[LYRICS_PAGE_URL] : new S((string) 1);
                 $objPag = new I((int) $objPag->toString());
                 // Fixes for a bugged user ...
                 if ($objPag->toInt() == 0) {
                     // Make the proper header, at first ...
                     $this->setHeaderStr(new S(HDR::HEADER_404_NOT_FOUND));
                     // Give me back my free hardcore, Quoth the server, '404' ...
                     $this->setHeaderKey(URL::staticURL(new A(array(FRONTEND_ERROR_URL)), new A(array('404'))), new S('Location'));
                 } else {
                     // Make it a string again ...
                     $objPag = new S((string) $objPag->toInt());
                 }
                 // Get your switches on ...
                 if (isset($_GET[LYRICS_ITEM_URL])) {
                     // Check that the article exists, before doing anything stupid ...
                     if ($this->checkLyricURLIsUnique($objURL = $_GET[LYRICS_ITEM_URL])->toBoolean() == TRUE) {
                         // Make the proper header, at first ...
                         $this->setHeaderStr(new S(HDR::HEADER_404_NOT_FOUND));
                         // Give me back my free hardcore, Quoth the server, '404' ...
                         $this->setHeaderKey(URL::staticURL(new A(array(FRONTEND_ERROR_URL)), new A(array('404'))), new S('Location'));
                     } else {
                         // Make me SEO ... yah!
                         TPL::manageTTL($objTTL = $this->getLyricInfoByURL($objURL, self::$objLyricsTableFTitle));
                         TPL::manageTTL($objART = $this->getLyricInfoByURL($objURL, self::$objLyricsTableFArtist));
                         TPL::manageTTL($objALB = $this->getLyricInfoByURL($objURL, self::$objLyricsTableFAlbum));
                         TPL::manageTAG(new S('description'), new S('Titlu: ' . $objTTL . ', Artist: ' . $objART . ', Album: ' . $objALB . ', Lyrics: ' . $this->getLyricInfoByURL($objURL, self::$objLyricsTableFLyrics)->entityDecode(ENT_QUOTES)->doToken('<br />', _SP)->stripTags()->doSubStr(0, 128)));
                         // Set the template file ...
                         $tpF = new FilePath($this->getPathToSkin()->toRelativePath() . $objW . '-Item' . TPL_EXTENSION);
                         TPL::tpSet($objWA, new S('objWidgetArray'), $tpF);
                         TPL::tpSet($objURL, new S('objURL'), $tpF);
                         TPL::tpSet($this->ATH, new S('ATH'), $tpF);
                         TPL::tpSet($this->STG, new S('STG'), $tpF);
                         TPL::tpSet($this, new S('LRQ'), $tpF);
                         TPL::tpExe($tpF);
                     }
                 } else {
                     if (isset($_GET[LYRICS_SEARCH_URL])) {
                         // Get audio by page ...
                         $objCnt = $this->getLyricCountForSearch($_GET[LYRICS_SEARCH_URL]);
                         $objArt = $this->getLyricsByPageAndSearch($objPag, $_GET[LYRICS_SEARCH_URL]);
                     } else {
                         // Do me SEO, yah baby! ...
                         TPL::manageTTL(_S(FRONTEND_LYRICS_URL));
                         // Make a condition to avoid dup. title tags on different pages ...
                         if ((int) $objPag->toString() >= 1 && isset($_GET[LYRICS_PAGE_URL])) {
                             TPL::manageTTL(_S(LYRICS_PAGE_URL)->appendString(_SP)->appendString($objPag));
                         }
                         // Set some requirements ...
                         $objArt = $this->getLyricsByPage($objPag);
                         $objCnt = $this->getLyricCount();
                     }
                     // Set the template file ...
                     $tpF = new FilePath($this->getPathToSkin()->toRelativePath() . $objW . TPL_EXTENSION);
                     TPL::tpSet($objWA, new S('objWidgetArray'), $tpF);
                     TPL::tpSet($objArt, new S('objAr'), $tpF);
                     TPL::tpSet($this, new S('LRQ'), $tpF);
                     TPL::tpExe($tpF);
                     // Set them paginations ...
                     if ($objCnt->toInt() > (int) self::$objItemsPerPage->toString()) {
                         self::$objFrontend->setPagination($objCnt, new I((int) self::$objItemsPerPage->toString()));
                     }
                 }
             } else {
                 // Do the biggest error on the PLANET ...
                 self::renderScreenOfDeath(new S(__CLASS__), new S(LYRICS_NEED_PROPER_SECTION), new S(LYRICS_NEED_PROPER_SECTION_FIX));
             }
             // BK;
             break;
         case 'widgetTopN':
             if ($objWA['type'] == 1) {
                 $objArt = $this->_Q(_QS('doSELECT')->doToken('%what', new S('%objLyricsTableFArtist, COUNT(%objLyricsTableFTitle) as count'))->doToken('%table', self::$objLyricsTable)->doToken('%condition', new S('GROUP BY %objLyricsTableFArtist ORDER BY count DESC LIMIT 0, 30')));
             } else {
                 $objArt = $this->_Q(_QS('doSELECT')->doToken('%what', new S('%objLyricsTableFAlbum, COUNT(%objLyricsTableFTitle) as count'))->doToken('%table', self::$objLyricsTable)->doToken('%condition', new S('GROUP BY %objLyricsTableFAlbum ORDER BY count DESC LIMIT 0, 30')));
             }
             // Set the template file ...
             $tpF = new FilePath($this->getPathToSkin()->toRelativePath() . $objW . TPL_EXTENSION);
             TPL::tpSet($objWA, new S('objWidgetArray'), $tpF);
             TPL::tpSet($objArt, new S('objAr'), $tpF);
             TPL::tpSet($this, new S('LRQ'), $tpF);
             TPL::tpExe($tpF);
             break;
         case 'widgetSearch':
             $this->renderForm(new S('widgetSearch'));
             break;
     }
 }
Esempio n. 12
0
 /**
  * Will send the email, at the specified address, using the specified subject and content;
  *
  * This method will send out the given email and subject, to the given address, while decoding the content from entities; You,
  * as the user, SHOULD ALWAYS remember, that the content gets decoded in this method, thus allowing you to work with your
  * content where you've called it, without modifying it;
  *
  * @param S $objMAILTo The email to send it to;
  * @param S $objMAILSubject The subject to set;
  * @param S $objMAILContent And the content;
  * @todo CLEAN THIS URGENTLY! ...
  */
 public function doMAIL(S $objMAILTo, S $objMAILSubject, S $objMAILContent)
 {
     // First of ALL, get a CLONE ...
     $objMAILClone = clone $objMAILContent;
     $objMAILClone = $objMAILClone->entityDecode(ENT_QUOTES)->stripTags();
     // #0: proper MULTIPART;
     $objMAILContent->prependString(new S(_N_))->prependString(_S(self::MAIL_HEADER_CONTENT_ENCODING_SEVENBIT . _N_))->prependString(_S(self::MAIL_HEADER_CONTENT_TYPE_HTML . _N_))->prependString(_S(self::MAIL_HEADER_PHP_ALTERNATIVE . _N_)->doToken('%s', self::$objHASHId))->prependString(_S(_N_))->prependString(_S($objMAILClone . _N_))->prependString(_S(_N_))->prependString(_S(self::MAIL_HEADER_CONTENT_ENCODING_SEVENBIT . _N_))->prependString(_S(self::MAIL_HEADER_CONTENT_TYPE_PLAIN . _N_))->prependString(_S(self::MAIL_HEADER_PHP_ALTERNATIVE . _N_)->doToken('%s', self::$objHASHId))->prependString(_S(_N_))->prependString(_S(self::MAIL_HEADER_MULTIPART_ALTERNATIVE . _N_)->doToken('%s', self::$objHASHId))->prependString(_S(self::MAIL_HEADER_PHP_MIXED . _N_)->doToken('%s', self::$objHASHId));
     // #4: ... end PLAIN and HTML ...
     $objMAILContent->appendString(_S(_N_))->appendString(_S(self::MAIL_HEADER_PHP_ALTERNATIVE_END . _N_)->doToken('%s', self::$objHASHId));
     // #5: ... attachments;
     foreach (self::$objEMLAttachment as $k => $v) {
         // #5.1
         $objMAILContent->appendString(_S(self::MAIL_HEADER_PHP_MIXED . _N_)->doToken('%s', self::$objHASHId))->appendString(_S(self::MAIL_HEADER_ATTACHMENT_TYPE_NAME . _N_)->doToken('%t', $v['attachment_type'])->doToken('%n', $v['attachment_name']))->appendString(_S(self::MAIL_HEADER_ENCODING_BASE64 . _N_))->appendString(_S(self::MAIL_HEADER_DISPOSITION_ATTACHMENT . _N_))->appendString(_S(_N_))->appendString($v['attachment_base64'])->appendString(_S(self::MAIL_HEADER_PHP_MIXED . _N_)->doToken('%s', self::$objHASHId));
     }
     // Finish ...
     $objMAILContent->appendString(_S(_N_))->appendString(_S(self::MAIL_HEADER_PHP_MIXED_END)->doToken('%s', self::$objHASHId));
     // Go ... everyhing IS ok and life's grand ...
     MAIL($objMAILTo, $objMAILSubject, $objMAILContent->entityDecode(ENT_QUOTES), self::$objFromHeader . self::$objReceiptTo . self::$objReplyTo . self::$objMIMEHeader . self::$objTypeHTML);
 }
Esempio n. 13
0
 function authstrike($credentials)
 {
     global $ost;
     $cfg = $ost->getConfig();
     $authsession =& $_SESSION['_auth']['user'];
     $username = $credentials['username'];
     $password = $credentials['password'];
     $authsession['strikes'] += 1;
     if ($authsession['strikes'] > $cfg->getClientMaxLogins()) {
         $authsession['laststrike'] = time();
         $alert = _S('Excessive login attempts by a user.') . "\n" . _S('Username') . ": {$username}\n" . _S('IP') . ": {$_SERVER['REMOTE_ADDR']}\n" . _S('Time') . ": " . date('M j, Y, g:i a T') . "\n\n" . _S('Attempts') . ": {$authsession['strikes']}";
         $ost->logError(_S('Excessive login attempts (user)'), $alert, $cfg->alertONLoginError());
         return new AccessDenied(__('Access Denied'));
     } elseif ($authsession['strikes'] % 3 == 0) {
         //Log every third failed login attempt as a warning.
         $alert = _S('Username') . ": {$username}\n" . _S('IP') . ": {$_SERVER['REMOTE_ADDR']}\n" . _S('Time') . ": " . date('M j, Y, g:i a T') . "\n\n" . _S('Attempts') . ": {$authsession['strikes']}";
         $ost->logWarning(_S('Failed login attempt (user)'), $alert);
     }
 }
Esempio n. 14
0
 protected function sendUnlockEmail($template)
 {
     global $ost, $cfg;
     $token = Misc::randCode(48);
     // 290-bits
     $email = $cfg->getDefaultEmail();
     $content = Page::lookup(Page::getIdByType($template));
     if (!$email || !$content) {
         return new Error(sprintf(_S('%s: Unable to retrieve template'), $template));
     }
     $vars = array('url' => $ost->getConfig()->getBaseUrl(), 'token' => $token, 'user' => $this->getUser(), 'recipient' => $this->getUser(), 'link' => sprintf("%s/pwreset.php?token=%s", $ost->getConfig()->getBaseUrl(), $token));
     $vars['reset_link'] =& $vars['link'];
     $info = array('email' => $email, 'vars' => &$vars, 'log' => true);
     Signal::send('auth.pwreset.email', $this->getUser(), $info);
     $msg = $ost->replaceTemplateVariables(array('subj' => $content->getName(), 'body' => $content->getBody()), $vars);
     $_config = new Config('pwreset');
     $_config->set($vars['token'], $this->getUser()->getId());
     $email->send($this->getUser()->getEmail(), Format::striptags($msg['subj']), $msg['body']);
     return true;
 }
 function __construct($body, $type = 'text', $options = array())
 {
     $type = strtolower($type);
     if (!in_array($type, static::$types)) {
         throw new Exception("{$type}: Unsupported ThreadBody type");
     }
     $this->body = (string) $body;
     if (strlen($this->body) > 250000) {
         $max_packet = db_get_variable('max_allowed_packet', 'global');
         // Truncate just short of the max_allowed_packet
         $this->body = substr($this->body, 0, $max_packet - 2048) . ' ... ' . _S('(truncated)');
     }
     $this->type = $type;
     $this->options = array_merge($this->options, $options);
 }
Esempio n. 16
0
 /**
  * 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;
     }
 }
Esempio n. 17
0
 /**
  * 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;
     }
 }
Esempio n. 18
0
 /**
  * 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;
     }
 }
Esempio n. 19
0
 /**
  * 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;
     }
 }
Esempio n. 20
0
 function sendResetEmail($template = 'pwreset-staff', $log = true)
 {
     global $ost, $cfg;
     $content = Page::lookup(Page::getIdByType($template));
     $token = Misc::randCode(48);
     // 290-bits
     if (!$content) {
         return new Error('Unable to retrieve password reset email template');
     }
     $vars = array('url' => $ost->getConfig()->getBaseUrl(), 'token' => $token, 'staff' => $this, 'recipient' => $this, 'reset_link' => sprintf("%s/scp/pwreset.php?token=%s", $ost->getConfig()->getBaseUrl(), $token));
     $vars['link'] =& $vars['reset_link'];
     if (!($email = $cfg->getAlertEmail())) {
         $email = $cfg->getDefaultEmail();
     }
     $info = array('email' => $email, 'vars' => &$vars, 'log' => $log);
     Signal::send('auth.pwreset.email', $this, $info);
     if ($info['log']) {
         $ost->logWarning(_S('Agent Password Reset'), sprintf(_S('Password reset was attempted for agent: %1$s<br><br>
             Requested-User-Id: %2$s<br>
             Source-Ip: %3$s<br>
             Email-Sent-To: %4$s<br>
             Email-Sent-Via: %5$s'), $this->getName(), $_POST['userid'], $_SERVER['REMOTE_ADDR'], $this->getEmail(), $email->getEmail()), false);
     }
     $msg = $ost->replaceTemplateVariables(array('subj' => $content->getName(), 'body' => $content->getBody()), $vars);
     $_config = new Config('pwreset');
     $_config->set($vars['token'], $this->getId());
     $email->send($this->getEmail(), Format::striptags($msg['subj']), $msg['body']);
 }
Esempio n. 21
0
 public function testXmlConversionConsistency2()
 {
     $source = array('message' => array(_S('Hello'), _S('World!')), 'data' => _A());
     $this->assertEquals($source, set::fromXml(_A($source)->toXml())->elements);
 }
Esempio n. 22
0
if ($sec < 180 || !$ost || $ost->isUpgradePending())
    ob_end_clean();

require_once(INCLUDE_DIR.'class.cron.php');

// Clear staff obj to avoid false credit internal notes & auto-assignment
$thisstaff = null;

// Release the session to prevent locking a future request while this is
// running
$_SESSION['lastcroncall'] = time();
session_write_close();

// Age tickets: We're going to age tickets regardless of cron settings.
Cron::TicketMonitor();

// Run file purging about every 20 cron runs (1h40 on a five minute cron)
if (mt_rand(1, 20) == 4)
    Cron::CleanOrphanedFiles();

if($cfg && $cfg->isAutoCronEnabled()) { //ONLY fetch tickets if autocron is enabled!
    Cron::MailFetcher();  //Fetch mail.
    $ost->logDebug(_S('Auto Cron'), sprintf(_S('Mail fetcher cron call [%s]'), $caller));
}

$data = array('autocron'=>true);
Signal::send('cron', $data);

ob_end_clean();
?>
Esempio n. 23
0
 function parse($stream)
 {
     global $cfg;
     $contents = '';
     if (is_resource($stream)) {
         while (!feof($stream)) {
             $contents .= fread($stream, 8192);
         }
     } else {
         $contents = $stream;
     }
     $parser = new Mail_Parse($contents);
     if (!$parser->decode()) {
         //Decode...returns false on decoding errors
         return $this->err('Email parse failed [' . $parser->getError() . ']');
     }
     $data = array();
     $data['emailId'] = 0;
     $data['recipients'] = array();
     $data['subject'] = $parser->getSubject();
     $data['header'] = $parser->getHeader();
     $data['mid'] = $parser->getMessageId();
     $data['priorityId'] = $parser->getPriority();
     $data['flags'] = new ArrayObject();
     //FROM address: who sent the email.
     if ($fromlist = $parser->getFromAddressList()) {
         $from = $fromlist[0];
         //Default.
         foreach ($fromlist as $fromobj) {
             if (!Validator::is_email($fromobj->mailbox . '@' . $fromobj->host)) {
                 continue;
             }
             $from = $fromobj;
             break;
         }
         $data['email'] = $from->mailbox . '@' . $from->host;
         $data['name'] = trim($from->personal, '"');
         if ($from->comment && $from->comment[0]) {
             $data['name'] .= ' (' . $from->comment[0] . ')';
         }
         //Use email address as name  when FROM address doesn't  have a name.
         if (!$data['name'] && $data['email']) {
             $data['name'] = $data['email'];
         }
     }
     /* Scan through the list of addressees (via To, Cc, and Delivered-To headers), and identify
      * how the mail arrived at the system. One of the mails should be in the system email list.
      * The recipient list (without the Delivered-To addressees) will be made available to the
      * ticket filtering system. However, addresses in the Delivered-To header should never be
      * considered for the collaborator list.
      */
     $tolist = array();
     if ($to = $parser->getToAddressList()) {
         $tolist['to'] = $to;
     }
     if ($cc = $parser->getCcAddressList()) {
         $tolist['cc'] = $cc;
     }
     if ($dt = $parser->getDeliveredToAddressList()) {
         $tolist['delivered-to'] = $dt;
     }
     foreach ($tolist as $source => $list) {
         foreach ($list as $addr) {
             if (!($emailId = Email::getIdByEmail(strtolower($addr->mailbox) . '@' . $addr->host))) {
                 //Skip virtual Delivered-To addresses
                 if ($source == 'delivered-to') {
                     continue;
                 }
                 $data['recipients'][] = array('source' => sprintf(_S("Email (%s)"), $source), 'name' => trim(@$addr->personal, '"'), 'email' => strtolower($addr->mailbox) . '@' . $addr->host);
             } elseif (!$data['emailId']) {
                 $data['emailId'] = $emailId;
             }
         }
     }
     /*
      * In the event that the mail was delivered to the system although none of the system
      * mail addresses are in the addressee lists, be careful not to include the addressee
      * in the collaborator list. Therefore, the delivered-to addressees should be flagged so they
      * are not added to the collaborator list in the ticket creation process.
      */
     if ($tolist['delivered-to']) {
         foreach ($tolist['delivered-to'] as $addr) {
             foreach ($data['recipients'] as $i => $r) {
                 if (strcasecmp($r['email'], $addr->mailbox . '@' . $addr->host) === 0) {
                     $data['recipients'][$i]['source'] = 'delivered-to';
                 }
             }
         }
     }
     //maybe we got BCC'ed??
     if (!$data['emailId']) {
         $emailId = 0;
         if ($bcc = $parser->getBccAddressList()) {
             foreach ($bcc as $addr) {
                 if ($emailId = Email::getIdByEmail($addr->mailbox . '@' . $addr->host)) {
                     break;
                 }
             }
         }
         $data['emailId'] = $emailId;
     }
     if ($parser->isBounceNotice()) {
         // Fetch the original References and assign to 'references'
         if ($headers = $parser->getOriginalMessageHeaders()) {
             $data['references'] = $headers['references'];
             $data['in-reply-to'] = @$headers['in-reply-to'] ?: null;
         }
         // Fetch deliver status report
         $data['message'] = $parser->getDeliveryStatusMessage() ?: $parser->getBody();
         $data['thread-type'] = 'N';
         $data['flags']['bounce'] = true;
     } else {
         // Typical email
         $data['message'] = $parser->getBody();
         $data['in-reply-to'] = @$parser->struct->headers['in-reply-to'];
         $data['references'] = @$parser->struct->headers['references'];
         $data['flags']['bounce'] = TicketFilter::isBounce($data['header']);
     }
     $data['to-email-id'] = $data['emailId'];
     if ($replyto = $parser->getReplyTo()) {
         $replyto = $replyto[0];
         $data['reply-to'] = $replyto->mailbox . '@' . $replyto->host;
         if ($replyto->personal) {
             $data['reply-to-name'] = trim($replyto->personal, " \t\n\r\v\"");
         }
     }
     $data['attachments'] = $parser->getAttachments();
     return $data;
 }
Esempio n. 24
0
 /**
  * Trims string at its end.
  *
  * @param string $chars set of characters to remove at end of string
  * @return \de\toxa\txf\string trimmed string
  */
 public function rtrim(string $chars = null)
 {
     $chars = is_null($chars) ? " \r\t\n\f" : _S($chars)->asUtf8;
     return static::wrap(rtrim($this->asUtf8, $chars), 'utf-8')->convertTo($this->encoding);
 }
 function getTitle()
 {
     return get_class($this) . ': ' . _S(static::$title);
 }
Esempio n. 26
0
 function cleanup()
 {
     $file = $this->getSQLDir() . $this->phash . '.cleanup.sql';
     if (!file_exists($file)) {
         //No cleanup script.
         return 0;
     }
     //We have a cleanup script  ::XXX: Don't abort on error?
     if ($this->load_sql_file($file, $this->getTablePrefix(), false, true)) {
         $this->log(sprintf(_S("Upgrader - %s cleanup"), $this->phash), sprintf(_S("Applied cleanup script %s"), $file));
         return 0;
     }
     $this->log(_S('Upgrader'), sprintf(_S("%s: Unable to process cleanup file"), $this->phash));
     return 0;
 }
Esempio n. 27
0
 /**
  * Load the template from the initial_data directory. The format of the
  * file should be free flow text. The first line is the subject and the
  * rest of the file is the body.
  */
 function fromInitialData($name, $group = null)
 {
     $templ = new EmailTemplate(0, $group);
     $lang = $group ? $group->getLanguage() : 'en_US';
     $i18n = new Internationalization($lang);
     if (!($tpl = $i18n->getTemplate("templates/email/{$name}.yaml")) || !($info = $tpl->getData())) {
         return false;
     }
     if (isset($info['subject']) && isset($info['body'])) {
         $templ->ht = $info;
         return $templ;
     }
     raise_error("{$lang}/templates/{$name}.yaml: " . _S('Email templates must define both "subject" and "body" parts of the template'), 'InitialDataError');
     return false;
 }
Esempio n. 28
0
 /**
  * Adds provided code to form's content.
  *
  * @param string $htmlCode code to add to form's content
  * @param boolean $prepend true to prepend code, false to append
  * @return html_form
  */
 public function addContent($htmlCode, $prepend = false)
 {
     if ($prepend) {
         $this->code = _S($htmlCode)->asUtf8 . $this->code;
     } else {
         $this->code .= _S($htmlCode)->asUtf8;
     }
     return $this;
 }
Esempio n. 29
0
 function run()
 {
     global $ost;
     if (!$ost->getConfig()->isEmailPollingEnabled()) {
         return;
     }
     //We require imap ext to fetch emails via IMAP/POP3
     //We check here just in case the extension gets disabled post email config...
     if (!function_exists('imap_open')) {
         $msg = _S('osTicket requires PHP IMAP extension enabled for IMAP/POP3 email fetch to work!');
         $ost->logWarning(_S('Mail Fetch Error'), $msg);
         return;
     }
     //Hardcoded error control...
     $MAXERRORS = 5;
     //Max errors before we start delayed fetch attempts
     $TIMEOUT = 10;
     //Timeout in minutes after max errors is reached.
     $sql = ' SELECT email_id, mail_errors FROM ' . EMAIL_TABLE . ' WHERE mail_active=1 ' . '  AND (mail_errors<=' . $MAXERRORS . ' OR (TIME_TO_SEC(TIMEDIFF(NOW(), mail_lasterror))>' . $TIMEOUT * 60 . ') )' . '  AND (mail_lastfetch IS NULL OR TIME_TO_SEC(TIMEDIFF(NOW(), mail_lastfetch))>mail_fetchfreq*60)' . ' ORDER BY mail_lastfetch ASC';
     if (!($res = db_query($sql)) || !db_num_rows($res)) {
         return;
     }
     /* Failed query (get's logged) or nothing to do... */
     //Get max execution time so we can figure out how long we can fetch
     // take fetching emails.
     if (!($max_time = ini_get('max_execution_time'))) {
         $max_time = 300;
     }
     //Start time
     $start_time = Misc::micro_time();
     while (list($emailId, $errors) = db_fetch_row($res)) {
         //Break if we're 80% into max execution time
         if (Misc::micro_time() - $start_time > $max_time * 0.8) {
             break;
         }
         $fetcher = new MailFetcher($emailId);
         if ($fetcher->connect()) {
             db_query('UPDATE ' . EMAIL_TABLE . ' SET mail_errors=0, mail_lastfetch=NOW() WHERE email_id=' . db_input($emailId));
             $fetcher->fetchEmails();
             $fetcher->close();
         } else {
             db_query('UPDATE ' . EMAIL_TABLE . ' SET mail_errors=mail_errors+1, mail_lasterror=NOW() WHERE email_id=' . db_input($emailId));
             if (++$errors >= $MAXERRORS) {
                 //We've reached the MAX consecutive errors...will attempt logins at delayed intervals
                 $msg = "\n" . _S('osTicket is having trouble fetching emails from the following mail account') . ": \n" . "\n" . _S('User') . ": " . $fetcher->getUsername() . "\n" . _S('Host') . ": " . $fetcher->getHost() . "\n" . _S('Error') . ": " . $fetcher->getLastError() . "\n\n " . sprintf(_S('%1$d consecutive errors. Maximum of %2$d allowed'), $errors, $MAXERRORS) . "\n\n " . sprintf(_S('This could be connection issues related to the mail server. Next delayed login attempt in aprox. %d minutes'), $TIMEOUT);
                 $ost->alertAdmin(_S('Mail Fetch Failure Alert'), $msg, true);
             }
         }
     }
     //end while.
 }
Esempio n. 30
0
File: set.php Progetto: cepharum/txf
 /**
  * Recursively converts provided value to XML thread.
  *
  * @param mixed $set data to convert
  * @param string $indent indentation to use on value
  * @param string $name name used to wrap around converted data
  * @return string XML notation of provided data
  */
 protected static function array2Xml($set, $indent = null, $name = 'root')
 {
     $name = _S($name)->asUtf8;
     if (!xml::isValidName($name)) {
         throw new \UnexpectedValueException('invalid element name cannot be converted to XML');
     }
     if (is_array($set)) {
         // there are subordinated elements to be converted into XML nodes
         //
         // collect hash-like and set-like elements separately
         $separateName = $sameName = array();
         foreach ($set as $subName => $sub) {
             if (ctype_digit(trim($subName))) {
                 $sameName[] = static::array2Xml($sub, $indent, $name);
             } else {
                 $separateName[$subName] = static::array2Xml($sub, "{$indent} ", $subName);
             }
         }
         // exclude to have both sorts of elements (as it can't be mapped into XML notation)
         if (count($separateName) && count($sameName)) {
             throw new \UnexpectedValueException('unsupported state of mixing hash-like and set-like array in converting to XML');
         }
         // convert elements to XML
         if (count($separateName)) {
             return "{$indent}<{$name}>\n" . implode('', $separateName) . "{$indent}</{$name}>\n";
         } else {
             if (count($sameName)) {
                 // prevent multiple root nodes here
                 if (strval($indent) === '') {
                     if (count($set) > 1) {
                         throw new \UnexpectedValueException('cannot convert array with multiple root elements into XML');
                     }
                 }
                 return implode('', $sameName);
             } else {
                 // support empty elements
                 return "{$indent}<{$name}/>\n";
             }
         }
     } else {
         // it's a leaf node
         // -> convert to element containing single text element
         if (string::isString($set)) {
             $set = _S($set)->asUtf8;
         } else {
             $set = data::asAutoTypable($set);
         }
         return "{$indent}<{$name}>{$set}</{$name}>\n";
     }
 }