Ejemplo n.º 1
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 renderBackendPage(S $objPageToRender)
 {
     // Get a specific CSS file for this controller ...
     TPL::manageCSS(new FilePath($this->getPathToSkinCSS()->toRelativePath() . $objPageToRender . CSS_EXTENSION), $objPageToRender);
     // Do pagination ...
     if (isset($_GET[ADMIN_PAGINATION])) {
         $objLowerLimit = (int) $_GET[ADMIN_PAGINATION]->toString() * 10 - 10;
         $objUpperLimit = 10;
     } else {
         $objLowerLimit = 0;
         $objUpperLimit = 10;
     }
     // Do a switch on the rendered page ...
     switch ($objPageToRender) {
         case 'manageArticles':
             // Check if there's an action to take;
             if (isset($_GET[ADMIN_ACTION])) {
                 // Do a switch ...
                 switch ($_GET[ADMIN_ACTION]) {
                     case ADMIN_ACTION_EDIT:
                         $this->renderForm(new S('articleEdit'));
                         break;
                     case ADMIN_ACTION_ERASE:
                         $this->renderForm(new S('articleErase'));
                         break;
                 }
             } else {
                 // Redirect to DescByPublished ...
                 if (!isset($_GET[ADMIN_ACTION_SORT])) {
                     $this->setHeaderKey(URL::rewriteURL(new A(array(ADMIN_ACTION_SORT)), new A(array('DescByPublished'))), new S('Location'));
                 }
                 // Set some requirements ...
                 $objGetCondition = new S();
                 if (isset($_GET[ADMIN_ACTION_BY])) {
                     // Do a switch ...
                     switch ($_GET[ADMIN_ACTION_BY]) {
                         case ARTICLES_SEARCH_TITLE:
                             $objGetCondition->appendString(_SP)->appendString('WHERE %objArticleTableFTitle');
                             break;
                         case ARTICLES_SEARCH_CONTENT:
                             $objGetCondition->appendString(_SP)->appendString('WHERE %objArticleTableFContent');
                             break;
                         case ARTICLES_SEARCH_TAGS:
                             $objGetCondition->appendString(_SP)->appendString('WHERE %objArticleTableFTags');
                             break;
                         case ARTICLES_SEARCH_EXCERPT:
                             $objGetCondition->appendString(_SP)->appendString('WHERE %objArticleTableFExcerpt');
                             break;
                         case ARTICLES_SEARCH_CATEGORY:
                             $objGetCondition->appendString('AS t1 INNER JOIN %objCategoryTable AS t2
                             ON t1.%objArticleTableFCategoryId = t2.%objCategoryTableFId
                             WHERE %objCategoryTableFName');
                             break;
                     }
                     // Add LIKE searching ...
                     $objGetCondition->appendString(_SP)->appendString('LIKE "%%Search%"')->doToken('%Search', $_GET[ADMIN_ACTION_SEARCH]);
                     // Get the count ...
                     $objSearchCount = $this->getArticleCount($objGetCondition);
                 }
                 // Do a sorting, before anything else;
                 if (isset($_GET[ADMIN_ACTION_SORT])) {
                     // Do a switch ...
                     switch ($_GET[ADMIN_ACTION_SORT]) {
                         case 'AscByTitle':
                         case 'DescByTitle':
                             // Make the ordered condition;
                             $objGetCondition->appendString(_SP)->appendString('ORDER BY %objArticleTableFTitle');
                             // Do a switch ...
                             switch ($_GET[ADMIN_ACTION_SORT]) {
                                 case 'AscByTitle':
                                     $objGetCondition->appendString(_SP)->appendString('ASC');
                                     break;
                                 case 'DescByTitle':
                                     $objGetCondition->appendString(_SP)->appendString('DESC');
                                     break;
                             }
                             break;
                         case 'AscByPublished':
                         case 'DescByPublished':
                             // Make the ordered condition;
                             $objGetCondition->appendString(_SP)->appendString('ORDER BY %objArticleTableFDatePublished');
                             // Do a switch ...
                             switch ($_GET[ADMIN_ACTION_SORT]) {
                                 case 'AscByPublished':
                                     $objGetCondition->appendString(_SP)->appendString('ASC');
                                     break;
                                 case 'DescByPublished':
                                     $objGetCondition->appendString(_SP)->appendString('DESC');
                                     break;
                             }
                             break;
                         case 'AscByUpdated':
                         case 'DescByUpdated':
                             // Make the ordered condition;
                             $objGetCondition->appendString(_SP)->appendString('ORDER BY %objArticleTableFDateUpdated');
                             // Do a switch ...
                             switch ($_GET[ADMIN_ACTION_SORT]) {
                                 case 'AscByUpdated':
                                     $objGetCondition->appendString(_SP)->appendString('ASC');
                                     break;
                                 case 'DescByUpdated':
                                     $objGetCondition->appendString(_SP)->appendString('DESC');
                                     break;
                             }
                             break;
                         case 'AscByViews':
                         case 'DescByViews':
                             // Make the ordered condition;
                             $objGetCondition->appendString(_SP)->appendString('ORDER BY %objArticleTableFViews');
                             // Do a switch ...
                             switch ($_GET[ADMIN_ACTION_SORT]) {
                                 case 'AscByViews':
                                     $objGetCondition->appendString(_SP)->appendString('ASC');
                                     break;
                                 case 'DescByViews':
                                     $objGetCondition->appendString(_SP)->appendString('DESC');
                                     break;
                             }
                             break;
                         case 'AscByCategory':
                         case 'DescByCategory':
                             if (isset($_GET[ADMIN_ACTION_BY])) {
                                 if ($_GET[ADMIN_ACTION_BY] == ARTICLES_SEARCH_CATEGORY) {
                                     // Make the ordered condition;
                                     $objGetCondition->appendString(_SP)->appendString('ORDER BY t2.%objCategoryTableFName');
                                 } else {
                                     // Make the ordered condition;
                                     $objGetCondition->doToken('WHERE', _SP . 'AS t1 INNER JOIN %objCategoryTable AS t2
                                     ON t1.%objArticleTableFCategoryId = t2.%objCategoryTableFId WHERE');
                                     $objGetCondition->appendString(_SP)->appendString('ORDER BY t2.%objCategoryTableFName');
                                 }
                             } else {
                                 // Make the ordered condition;
                                 $objGetCondition->appendString(_SP)->appendString('AS t1 INNER JOIN %objCategoryTable AS t2
                                 ON t1.%objArticleTableFCategoryId = t2.%objCategoryTableFId
                                 ORDER BY t2.%objCategoryTableFName');
                             }
                             // Do a switch ...
                             switch ($_GET[ADMIN_ACTION_SORT]) {
                                 case 'AscByCategory':
                                     $objGetCondition->appendString(_SP)->appendString('ASC');
                                     break;
                                 case 'DescByCategory':
                                     $objGetCondition->appendString(_SP)->appendString('DESC');
                                     break;
                             }
                             break;
                     }
                 }
                 // Add some LIMITs
                 $objGetCondition->appendString(_SP)->appendString('LIMIT %LowerLimit, %UpperLimit')->doToken('%LowerLimit', $objLowerLimit)->doToken('%UpperLimit', $objUpperLimit);
                 // Get based on SQL condtion ...
                 $objArticleTable = $this->getArticles($objGetCondition);
                 if (isset($_GET[ADMIN_ACTION_BY])) {
                     $objArticleTableCount = $objSearchCount;
                 } else {
                     $objArticleTableCount = $this->getArticleCount();
                 }
                 // Fix pagination when count is LESS than 10;
                 if (isset($_GET[ADMIN_ACTION_BY]) && isset($_GET[ADMIN_PAGINATION])) {
                     if ($objArticleTableCount->toInt() < 10) {
                         // Remove paging ... & redirect to proper ...
                         TPL::setHeaderKey(URL::rewriteURL(new A(array(ADMIN_PAGINATION))), new S('Location'));
                     } else {
                         if (CEIL($objArticleTableCount->toInt() / 10) < (int) $_GET[ADMIN_PAGINATION]->toString()) {
                             // Redirect to proper ...
                             TPL::setHeaderKey(URL::rewriteURL(new A(array(ADMIN_PAGINATION)), new A(array(CEIL($objArticleTableCount->toInt() / 10)))), new S('Location'));
                         }
                     }
                 }
                 // Set the template file ...
                 $tpF = new FilePath($this->getPathToSkin()->toRelativePath() . 'manageArticles.tp');
                 TPL::tpSet($objArticleTable, new S('articleTable'), $tpF);
                 TPL::tpSet($this, new S('ART'), $tpF);
                 TPL::tpSet($this->STG, new S('STG'), $tpF);
                 TPL::tpExe($tpF);
                 // Do pagination ...
                 if ($objArticleTableCount->toInt() > 10) {
                     self::$objAdministration->setPagination($objArticleTableCount);
                 }
                 // Do the form, make it happen;
                 $this->renderForm(new S('articleSearch'));
                 $this->renderForm(new S('articleCreate'));
             }
             // BK;
             break;
         case 'manageCategories':
             // Add some requirements;
             TPL::manageJSS(new FilePath($this->getPathToSkinJSS()->toRelativePath() . 'manageCategories.js'), new S('manageCategories'));
             // Check if there's an action to take;
             if (isset($_GET[ADMIN_ACTION])) {
                 // Do a switch ...
                 switch ($_GET[ADMIN_ACTION]) {
                     case ADMIN_ACTION_EDIT:
                         $this->renderForm(new S('categoryEdit'));
                         break;
                     case ADMIN_ACTION_ERASE:
                         $this->renderForm(new S('categoryErase'));
                         break;
                     case ADMIN_ACTION_MOVE:
                         $this->renderForm(new S('categoryMove'));
                         break;
                 }
             } else {
                 // Set some requirements ...
                 $objGetCondition = new S();
                 // Do a sorting, before anything else;
                 if (isset($_GET[ADMIN_ACTION_SORT])) {
                     // Do a switch ...
                     switch ($_GET[ADMIN_ACTION_SORT]) {
                         case 'AscByCategory':
                             // Make the ordered condition;
                             $objGetCondition->appendString(_SP)->appendString('ASC');
                             break;
                         case 'DescByCategory':
                             // Make the ordered condition;
                             $objGetCondition->appendString(_SP)->appendString('DESC');
                             break;
                     }
                 }
                 // Add some LIMITs
                 $objGetCondition->appendString(_SP)->appendString('LIMIT %LowerLimit, %UpperLimit')->doToken('%LowerLimit', $objLowerLimit)->doToken('%UpperLimit', $objUpperLimit);
                 // Set some requirements ...
                 $objCategoryTreeCount = $this->getCategoryCount();
                 $objCategoryTree = $this->getCategories(isset($_GET[ADMIN_SHOW_ALL]) ? new S() : $objGetCondition);
                 // Set the template file ...
                 $tpF = new FilePath($this->getPathToSkin()->toRelativePath() . 'manageCategories.tp');
                 TPL::tpSet($objCategoryTree, new S('categoryTree'), $tpF);
                 TPL::tpExe($tpF);
                 // Do pagination ...
                 if ($objCategoryTreeCount->toInt() > 10 && !isset($_GET[ADMIN_SHOW_ALL])) {
                     self::$objAdministration->setPagination($objCategoryTreeCount);
                 }
                 // Do the form, make it happen;
                 $this->renderForm(new S('categoryCreate'));
             }
             // BK;
             break;
         case 'manageComments':
             // Check if there's an action to take;
             if (isset($_GET[ADMIN_ACTION])) {
                 // Switch between actions;
                 switch ($_GET[ADMIN_ACTION]) {
                     case ADMIN_ACTION_EDIT:
                         $this->renderForm(new S('commentEdit'));
                         break;
                     case ADMIN_ACTION_ERASE:
                         $this->renderForm(new S('commentErase'));
                         break;
                 }
             } else {
                 // Do a redirect ...
                 if (!isset($_GET[ADMIN_ACTION_SORT])) {
                     $this->setHeaderKey(URL::rewriteURL(new A(array(ADMIN_ACTION_SORT)), new A(array('DescByDate'))), new S('Location'));
                 }
                 // Set some requirements ...
                 $objGetCondition = new S();
                 // Do a sorting, before anything else;
                 if (isset($_GET[ADMIN_ACTION_SORT])) {
                     // Do a switch ...
                     switch ($_GET[ADMIN_ACTION_SORT]) {
                         case 'AscByName':
                         case 'DescByName':
                             // Make the ordered condition;
                             $objGetCondition->appendString(_SP)->appendString('ORDER BY %objCommentsTableFName');
                             // Do a switch ...
                             switch ($_GET[ADMIN_ACTION_SORT]) {
                                 case 'AscByName':
                                     $objGetCondition->appendString(_SP)->appendString('ASC');
                                     break;
                                 case 'DescByName':
                                     $objGetCondition->appendString(_SP)->appendString('DESC');
                                     break;
                             }
                             break;
                         case 'AscByTitle':
                         case 'DescByTitle':
                             // Make the ordered condition;
                             $objGetCondition->appendString(_SP)->appendString('AS t1 LEFT JOIN %objArticleTable
                             AS t2 ON t1.%objCommentsTableFArticleId = t2.%objArticleTableFId
                             ORDER BY t2.%objArticleTableFTitle');
                             // Do a switch ...
                             switch ($_GET[ADMIN_ACTION_SORT]) {
                                 case 'AscByTitle':
                                     $objGetCondition->appendString(_SP)->appendString('ASC');
                                     break;
                                 case 'DescByTitle':
                                     $objGetCondition->appendString(_SP)->appendString('DESC');
                                     break;
                             }
                             break;
                         case 'AscByApproved':
                         case 'DescByApproved':
                             // Make the ordered condition;
                             $objGetCondition->appendString(_SP)->appendString('ORDER BY %objCommentsTableFApproved');
                             // Do a switch ...
                             switch ($_GET[ADMIN_ACTION_SORT]) {
                                 case 'AscByApproved':
                                     $objGetCondition->appendString(_SP)->appendString('ASC');
                                     break;
                                 case 'DescByApproved':
                                     $objGetCondition->appendString(_SP)->appendString('DESC');
                                     break;
                             }
                             break;
                         case 'AscByDate':
                         case 'DescByDate':
                             // Make the ordered condition;
                             $objGetCondition->appendString(_SP)->appendString('ORDER BY %objCommentsTableFDate');
                             // Do a switch ...
                             switch ($_GET[ADMIN_ACTION_SORT]) {
                                 case 'AscByDate':
                                     $objGetCondition->appendString(_SP)->appendString('ASC');
                                     break;
                                 case 'DescByDate':
                                     $objGetCondition->appendString(_SP)->appendString('DESC');
                                     break;
                             }
                             break;
                     }
                 }
                 // Add some LIMITs
                 $objGetCondition->appendString(_SP)->appendString('LIMIT %LowerLimit, %UpperLimit')->doToken('%LowerLimit', $objLowerLimit)->doToken('%UpperLimit', $objUpperLimit);
                 // Set some requirements;
                 $objComments = $this->getComments($objGetCondition);
                 $objCommentsCount = $this->getCommentCount();
                 // Process them arrays;
                 foreach ($objComments as $k => $v) {
                     if ($v[self::$objCommentsTableFRUId] != new S('0')) {
                         $v[self::$objCommentsTableFName] = $this->ATH->getUserInfoById($v[self::$objCommentsTableFRUId], Authentication::$objAuthUsersTableFUName);
                     }
                 }
                 // Set the template file ...
                 $tpF = new FilePath($this->getPathToSkin()->toRelativePath() . 'manageComments.tp');
                 TPL::tpSet($objComments, new S('articleTable'), $tpF);
                 TPL::tpSet($this->STG, new S('STG'), $tpF);
                 TPL::tpSet($this, new S('ART'), $tpF);
                 TPL::tpExe($tpF);
                 // Do some pagination ...
                 if ($objCommentsCount->toInt() > 10) {
                     self::$objAdministration->setPagination($objCommentsCount);
                 }
             }
             // BK;
             break;
         case 'manageOperations':
             // Do the form, make it happen;
             $this->renderForm(new S('categoryMoveOperation'));
             break;
         case 'manageConfiguration':
             // Do the form, make it happen ...
             if (isset($_GET[ADMIN_ACTION])) {
                 $this->renderForm($_GET[ADMIN_ACTION]);
             } else {
                 $this->renderForm(new S('configurationEdit'));
             }
             break;
     }
 }
Ejemplo n.º 2
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 renderBackendPage(S $objPageToRender)
 {
     // Get a specific CSS file for this controller ...
     TPL::manageCSS(new FilePath($this->getPathToSkinCSS()->toRelativePath() . $objPageToRender . CSS_EXTENSION), $objPageToRender);
     // Do pagination ...
     if (isset($_GET[ADMIN_PAGINATION])) {
         $objLowerLimit = (int) $_GET[ADMIN_PAGINATION]->toString() * 10 - 10;
         $objUpperLimit = 10;
     } else {
         $objLowerLimit = 0;
         $objUpperLimit = 10;
     }
     // Do a switch on the rendered page ...
     switch ($objPageToRender) {
         case 'manageImages':
             // Make an IF;
             if (isset($_GET[PRODUCTS_ACTION_IMAGE])) {
                 // Do a switch ...
                 switch ($_GET[PRODUCTS_ACTION_IMAGE]) {
                     case ADMIN_ACTION_EDIT:
                         $this->renderForm(new S('imageEdit'));
                         break;
                     case ADMIN_ACTION_ERASE:
                         $this->renderForm(new S('imageErase'));
                         break;
                 }
             } else {
                 // Set some requirements ...
                 $objGetCondition = new S();
                 // Do a sorting beforehand;
                 if (isset($_GET[ADMIN_ACTION_SORT])) {
                     // Do a switch ...
                     switch ($_GET[ADMIN_ACTION_SORT]) {
                         case 'AscByImage':
                         case 'DescByImage':
                             $objGetCondition->appendString(_SP)->appendString('ORDER BY %objProductsIMGTableFURL');
                             // Do a switch ...
                             switch ($_GET[ADMIN_ACTION_SORT]) {
                                 case 'AscByImage':
                                     $objGetCondition->appendString(_SP)->appendString('ASC');
                                     break;
                                 case 'DescByImage':
                                     $objGetCondition->appendString(_SP)->appendString('DESC');
                                     break;
                             }
                             // Break out ...
                             break;
                         case 'AscByTitle':
                         case 'DescByTitle':
                             $objGetCondition->appendString(_SP)->appendString('ORDER BY %objProductsIMGTableFTitle');
                             // Do a switch ...
                             switch ($_GET[ADMIN_ACTION_SORT]) {
                                 case 'AscByTitle':
                                     $objGetCondition->appendString(_SP)->appendString('ASC');
                                     break;
                                 case 'DescByTitle':
                                     $objGetCondition->appendString(_SP)->appendString('DESC');
                                     break;
                             }
                             // Break out ...
                             break;
                     }
                 } else {
                     // Set some requirements ...
                     $objGetCondition->appendString(_SP)->appendString('ORDER BY %objProductsIMGTableFId DESC');
                 }
                 // Add some LIMITs
                 $objGetCondition->appendString(_SP)->appendString('LIMIT %LowerLimit, %UpperLimit')->doToken('%LowerLimit', $objLowerLimit)->doToken('%UpperLimit', $objUpperLimit);
                 // Set some requirements ...
                 $objImageTable = $this->getImagesByProductId($_GET[ADMIN_ACTION_ID], $objGetCondition);
                 $objImageTableCount = $this->getImageCountByProductId($_GET[ADMIN_ACTION_ID]);
                 // Set the template file ...
                 $tpF = new FilePath($this->getPathToSkin()->toRelativePath() . 'manageImages.tp');
                 TPL::tpSet($objImageTable, new S('imageTable'), $tpF);
                 TPL::tpSet($this, new S('thisObj'), $tpF);
                 TPL::tpExe($tpF);
                 // Do some pagination;
                 if ($objImageTableCount->toInt() > 10) {
                     self::$objAdministration->setPagination($objImageTableCount);
                 }
                 // Do the form, make it happen;
                 $this->renderForm(new S('imageCreate'));
             }
             // Break out ...
             break;
         case 'manageProperties':
             if (isset($_GET[PRODUCTS_ACTION_PROPERTY])) {
                 // Do a switch ...
                 switch ($_GET[PRODUCTS_ACTION_PROPERTY]) {
                     case ADMIN_ACTION_EDIT:
                         $this->renderForm(new S('propertyEdit'));
                         break;
                     case ADMIN_ACTION_ERASE:
                         $this->renderForm(new S('propertyErase'));
                         break;
                 }
             } else {
                 // Set some requirements ...
                 $objGetCondition = new S();
                 // Do a sorting beforehand;
                 if (isset($_GET[ADMIN_ACTION_SORT])) {
                     // Do a switch ...
                     switch ($_GET[ADMIN_ACTION_SORT]) {
                         case 'AscByKey':
                         case 'DescByKey':
                             // Set some requiremenst;
                             $objGetCondition->appendString(_SP)->appendString('ORDER BY %objProductsPropertyTableFKey');
                             // Do a switch ...
                             switch ($_GET[ADMIN_ACTION_SORT]) {
                                 case 'AscByKey':
                                     $objGetCondition->appendString(_SP)->appendString('ASC');
                                     break;
                                 case 'DescByKey':
                                     $objGetCondition->appendString(_SP)->appendString('DESC');
                                     break;
                             }
                             // Break out ...
                             break;
                         case 'AscByVar':
                         case 'DescByVar':
                             // Set some requiremenst;
                             $objGetCondition->appendString(_SP)->appendString('ORDER BY %objProductsPropertyTableFVar');
                             // Do a switch ...
                             switch ($_GET[ADMIN_ACTION_SORT]) {
                                 case 'AscByVar':
                                     $objGetCondition->appendString(_SP)->appendString('ASC');
                                     break;
                                 case 'DescByVar':
                                     $objGetCondition->appendString(_SP)->appendString('DESC');
                                     break;
                             }
                             // Break out ...
                             break;
                     }
                 } else {
                     // Set some requirements ...
                     $objGetCondition->appendString(_SP)->appendString('ORDER BY %objProductsPropertyTableFId DESC');
                 }
                 // Add some LIMITs
                 $objGetCondition->appendString(_SP)->appendString('LIMIT %LowerLimit, %UpperLimit')->doToken('%LowerLimit', $objLowerLimit)->doToken('%UpperLimit', $objUpperLimit);
                 // Set some requirements ...
                 $objPropertyTable = $this->getPropertiesByProductId($_GET[ADMIN_ACTION_ID], $objGetCondition);
                 $objPropertyTableCount = $this->getPropertyCountByProductId($_GET[ADMIN_ACTION_ID]);
                 // Set the template file ...
                 $tpF = new FilePath($this->getPathToSkin()->toRelativePath() . 'manageProperties.tp');
                 TPL::tpSet($objPropertyTable, new S('propertyTable'), $tpF);
                 TPL::tpSet($this, new S('thisObj'), $tpF);
                 TPL::tpExe($tpF);
                 // Do some pagination;
                 if ($objPropertyTableCount->toInt() > 10) {
                     self::$objAdministration->setPagination($objPropertyTableCount);
                 }
                 // Do the form, make it happen;
                 $this->renderForm(new S('propertyCreate'));
             }
             // Break out ...
             break;
         case 'manageProducts':
             // Set some requirements;
             TPL::manageJSS(new FilePath($this->getPathToSkinJSS()->toRelativePath() . 'manageProducts.js'), new S('manageProducts'));
             // Do some work;
             if (isset($_GET[ADMIN_ACTION])) {
                 // Do a switch;
                 switch ($_GET[ADMIN_ACTION]) {
                     case ADMIN_ACTION_EDIT:
                         $this->renderForm(new S('productEdit'));
                         break;
                     case ADMIN_ACTION_ERASE:
                         $this->renderForm(new S('productErase'));
                         break;
                     case ADMIN_ACTION_IMAGES:
                         // Specific ...
                         $this->renderBackendPage(new S('manageImages'));
                         break;
                     case ADMIN_ACTION_PROPERTIES:
                         // Specific ...
                         $this->renderBackendPage(new S('manageProperties'));
                         break;
                 }
             } else {
                 // Set some requirements ...
                 $objGetCondition = new S();
                 // Do a sorting beforehand;
                 if (isset($_GET[ADMIN_ACTION_SORT])) {
                     // Do a switch ...
                     switch ($_GET[ADMIN_ACTION_SORT]) {
                         case 'AscByCode':
                         case 'DescByCode':
                             // Set some requirements;
                             $objGetCondition->appendString(_SP)->appendString('ORDER BY %objProductsTableFCode');
                             // Do a switch ...
                             switch ($_GET[ADMIN_ACTION_SORT]) {
                                 case 'AscByCode':
                                     $objGetCondition->appendString(_SP)->appendString('ASC');
                                     break;
                                 case 'DescByCode':
                                     $objGetCondition->appendString(_SP)->appendString('DESC');
                                     break;
                             }
                             // Break out ...
                             break;
                         case 'AscByName':
                         case 'DescByName':
                             // Set some requirements;
                             $objGetCondition->appendString(_SP)->appendString('ORDER BY %objProductsTableFName');
                             // Do a switch ...
                             switch ($_GET[ADMIN_ACTION_SORT]) {
                                 case 'AscByName':
                                     $objGetCondition->appendString(_SP)->appendString('ASC');
                                     break;
                                 case 'DescByName':
                                     $objGetCondition->appendString(_SP)->appendString('DESC');
                                     break;
                             }
                             // Break out ...
                             break;
                         case 'AscByStoc':
                         case 'DescByStoc':
                             // Set somre requirements;
                             $objGetCondition->appendString(_SP)->appendString('ORDER BY %objProductsTableFStoc');
                             // Do a switch ...
                             switch ($_GET[ADMIN_ACTION_SORT]) {
                                 case 'AscByStoc':
                                     $objGetCondition->appendString(_SP)->appendString('ASC');
                                     break;
                                 case 'DescByStoc':
                                     $objGetCondition->appendString(_SP)->appendString('DESC');
                                     break;
                             }
                             // Break out ...
                             break;
                         case 'AscByPrice':
                         case 'DescByPrice':
                             // Set some requirements;
                             $objGetCondition->appendString(_SP)->appendString('ORDER BY %objProductsTableFPrice');
                             // Do a switch ...
                             switch ($_GET[ADMIN_ACTION_SORT]) {
                                 case 'AscByPrice':
                                     $objGetCondition->appendString(_SP)->appendString('ASC');
                                     break;
                                 case 'DescByPrice':
                                     $objGetCondition->appendString(_SP)->appendString('DESC');
                                     break;
                             }
                             // Break out ...
                             break;
                         case 'AscByCategory':
                         case 'DescByCategory':
                             // Set some requirements;
                             $objGetCondition->appendString(_SP)->appendString('INNER JOIN %objProductsCategoryTable AS t2
                             ON t1.%objProductsTableFCategoryId = t2.%objCategoryTableFId
                             ORDER BY t2.%objCategoryTableFName');
                             // Do a switch ...
                             switch ($_GET[ADMIN_ACTION_SORT]) {
                                 case 'AscByCategory':
                                     $objGetCondition->appendString(_SP)->appendString('ASC');
                                     break;
                                 case 'DescByCategory':
                                     $objGetCondition->appendString(_SP)->appendString('DESC');
                                     break;
                             }
                             // Break out ...
                             break;
                     }
                 }
                 // Add some LIMITs
                 $objGetCondition->appendString(_SP)->appendString('LIMIT %LowerLimit, %UpperLimit')->doToken('%LowerLimit', $objLowerLimit)->doToken('%UpperLimit', $objUpperLimit);
                 // Set some requirements ...
                 $objProductTable = $this->getProducts($objGetCondition);
                 $objProductTableCount = $this->getProductCount();
                 // Set the template file ...
                 $tpF = new FilePath($this->getPathToSkin()->toRelativePath() . 'manageProducts.tp');
                 TPL::tpSet($objProductTable, new S('productTable'), $tpF);
                 TPL::tpSet($this, new S('thisObj'), $tpF);
                 TPL::tpExe($tpF);
                 // Do some pagination;
                 if ($objProductTableCount->toInt() > 10) {
                     self::$objAdministration->setPagination($objPropertyTableCount);
                 }
                 // Do the form, make it happen;
                 $this->renderForm(new S('productCreate'));
             }
             // Break out ...
             break;
         case 'manageCategories':
             // Add some requirements;
             TPL::manageJSS(new FilePath($this->getPathToSkinJSS()->toRelativePath() . 'manageCategories.js'), new S('manageCategories'));
             // Check if there's an action to take;
             if (isset($_GET[ADMIN_ACTION])) {
                 // Do a switch ...
                 switch ($_GET[ADMIN_ACTION]) {
                     case ADMIN_ACTION_EDIT:
                         $this->renderForm(new S('categoryEdit'));
                         break;
                     case ADMIN_ACTION_ERASE:
                         $this->renderForm(new S('categoryErase'));
                         break;
                     case ADMIN_ACTION_MOVE:
                         $this->renderForm(new S('categoryMove'));
                         break;
                 }
             } else {
                 // Set some requirements ...
                 $objGetCondition = new S();
                 // Do a sorting, before anything else;
                 if (isset($_GET[ADMIN_ACTION_SORT])) {
                     // Do a switch ...
                     switch ($_GET[ADMIN_ACTION_SORT]) {
                         case 'AscByCategory':
                             // Make the ordered condition;
                             $objGetCondition->appendString(_SP)->appendString('ASC');
                             break;
                         case 'DescByCategory':
                             // Make the ordered condition;
                             $objGetCondition->appendString(_SP)->appendString('DESC');
                     }
                 }
                 // Add some LIMITs
                 $objGetCondition->appendString(_SP)->appendString('LIMIT %LowerLimit, %UpperLimit')->doToken('%LowerLimit', $objLowerLimit)->doToken('%UpperLimit', $objUpperLimit);
                 // Set some requirements ...
                 $objCategoryTreeCount = $this->getCategoryCount();
                 $objCategoryTree = $this->getCategories(isset($_GET[ADMIN_SHOW_ALL]) ? new S() : $objGetCondition);
                 // Set the template file ...
                 $tpF = new FilePath($this->getPathToSkin()->toRelativePath() . 'manageCategories.tp');
                 TPL::tpSet($objCategoryTree, new S('categoryTree'), $tpF);
                 TPL::tpExe($tpF);
                 // Do pagination ...
                 if ($objCategoryTreeCount->toInt() > 10 && !isset($_GET[ADMIN_SHOW_ALL])) {
                     self::$objAdministration->setPagination($objCategoryTreeCount);
                 }
                 // Do the form, make it happen;
                 $this->renderForm(new S('categoryCreate'));
             }
             // Break out ...
             break;
         case 'manageOperations':
             // Do the form, make it happen;
             $this->renderForm(new S('categoryMoveOperation'));
             break;
         case 'manageConfiguration':
             // Do the form, make it happen ...
             if (isset($_GET[ADMIN_ACTION])) {
                 $this->renderForm($_GET[ADMIN_ACTION]);
             } else {
                 $this->renderForm(new S('configurationEdit'));
             }
             break;
     }
 }
Ejemplo n.º 3
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 renderBackendPage(S $objPageToRender)
 {
     // Get a specific CSS file for this controller ...
     TPL::manageCSS(new FilePath($this->getPathToSkinCSS()->toRelativePath() . $objPageToRender . CSS_EXTENSION), $objPageToRender);
     // Do pagination ...
     if (isset($_GET[ADMIN_PAGINATION])) {
         $objLowerLimit = (int) $_GET[ADMIN_PAGINATION]->toString() * 10 - 10;
         $objUpperLimit = 10;
     } else {
         $objLowerLimit = 0;
         $objUpperLimit = 10;
     }
     // Do a switch on the rendered page ...
     switch ($objPageToRender) {
         case 'manageNewsletter':
             // Do some work;
             if (isset($_GET[ADMIN_ACTION])) {
                 // Do a switch;
                 switch ($_GET[ADMIN_ACTION]) {
                     case ADMIN_ACTION_EDIT:
                         $this->renderForm(new S('newsletterEdit'));
                         break;
                     case ADMIN_ACTION_ERASE:
                         $this->renderForm(new S('newsletterErase'));
                         break;
                 }
             } else {
                 // Redirect to DescBySubscribed ...
                 if (!isset($_GET[ADMIN_ACTION_SORT])) {
                     $this->setHeaderKey(URL::rewriteURL(new A(array(ADMIN_ACTION_SORT)), new A(array('DescBySubscribed'))), new S('Location'));
                 }
                 // Set some requirements ...
                 $objGetCondition = new S();
                 // Check for sorting ...
                 if (isset($_GET[ADMIN_ACTION_BY])) {
                     // Do a switch ...
                     switch ($_GET[ADMIN_ACTION_BY]) {
                     }
                     // Add LIKE searching ...
                     $objGetCondition->appendString(_SP)->appendString('LIKE "%%Search%"')->doToken('%Search', $_GET[ADMIN_ACTION_SEARCH]);
                     // Get the count, on SQL ...
                     $objSearchCount = $this->getSubscriberCount($objGetCondition);
                 }
                 // Do a sorting beforehand;
                 if (isset($_GET[ADMIN_ACTION_SORT])) {
                     // Do a switch ...
                     switch ($_GET[ADMIN_ACTION_SORT]) {
                         case 'AscByEmail':
                         case 'DescByEmail':
                             // Make the ordered condition;
                             $objGetCondition->appendString(_SP)->appendString('ORDER BY %objLetterTableFEML');
                             // Do a switch ...
                             switch ($_GET[ADMIN_ACTION_SORT]) {
                                 case 'AscByEmail':
                                     $objGetCondition->appendString(_SP)->appendString('ASC');
                                     break;
                                 case 'DescByEmail':
                                     $objGetCondition->appendString(_SP)->appendString('DESC');
                                     break;
                             }
                             // Break out ...
                             break;
                         case 'AscByFirstName':
                         case 'DescByFirstName':
                             // Make the ordered condition;
                             $objGetCondition->appendString(_SP)->appendString('ORDER BY %objLetterTableFFirstName');
                             // Do a switch ...
                             switch ($_GET[ADMIN_ACTION_SORT]) {
                                 case 'AscByFirstName':
                                     $objGetCondition->appendString(_SP)->appendString('ASC');
                                     break;
                                 case 'DescByFirstName':
                                     $objGetCondition->appendString(_SP)->appendString('DESC');
                                     break;
                             }
                             // Break out ...
                             break;
                         case 'AscByLastName':
                         case 'DescByLastName':
                             // Make the ordered condition;
                             $objGetCondition->appendString(_SP)->appendString('ORDER BY %objLetterTableFLastName');
                             // Do a switch ...
                             switch ($_GET[ADMIN_ACTION_SORT]) {
                                 case 'AscByLastName':
                                     $objGetCondition->appendString(_SP)->appendString('ASC');
                                     break;
                                 case 'DescByLastName':
                                     $objGetCondition->appendString(_SP)->appendString('DESC');
                                     break;
                             }
                             // Break out ...
                             break;
                         case 'AscBySubscribed':
                         case 'DescBySubscribed':
                             // Make the ordered condition;
                             $objGetCondition->appendString(_SP)->appendString('ORDER BY %objLetterTableFSubscribed');
                             // Do a switch ...
                             switch ($_GET[ADMIN_ACTION_SORT]) {
                                 case 'AscBySubscribed':
                                     $objGetCondition->appendString(_SP)->appendString('ASC');
                                     break;
                                 case 'DescBySubscribed':
                                     $objGetCondition->appendString(_SP)->appendString('DESC');
                                     break;
                             }
                             // Break out ...
                             break;
                     }
                 }
                 // Add some LIMITs
                 $objGetCondition->appendString(_SP)->appendString('LIMIT %LowerLimit, %UpperLimit')->doToken('%LowerLimit', $objLowerLimit)->doToken('%UpperLimit', $objUpperLimit);
                 // Set some requirements ...
                 $objLetterTable = $this->getSubscribers($objGetCondition);
                 $objLetterTableCount = $this->getSubscriberCount();
                 // Set the template file ...
                 $tpF = new FilePath($this->getPathToSkin()->toRelativePath() . 'manageNewsletter.tp');
                 TPL::tpSet($objLetterTable, new S('newsletterTable'), $tpF);
                 TPL::tpSet($this->STG, new S('STG'), $tpF);
                 TPL::tpExe($tpF);
                 // Do some pagination;
                 if ($objLetterTableCount->toInt() > 10) {
                     self::$objAdministration->setPagination($objLetterTableCount);
                 }
                 // Do the form, make it happen;
                 $this->renderForm(new S('newsletterSearch'));
                 $this->renderForm(new S('newsletterCreate'));
             }
             // Break out ...
             break;
         case 'manageCategories':
             // Add some requirements;
             TPL::manageJSS(new FilePath($this->getPathToSkinJSS()->toRelativePath() . 'manageCategories.js'), new S('manageCategories'));
             // Check if there's an action to take;
             if (isset($_GET[ADMIN_ACTION])) {
                 // Do a switch ...
                 switch ($_GET[ADMIN_ACTION]) {
                     case ADMIN_ACTION_EDIT:
                         $this->renderForm(new S('categoryEdit'));
                         break;
                     case ADMIN_ACTION_ERASE:
                         $this->renderForm(new S('categoryErase'));
                         break;
                     case ADMIN_ACTION_MOVE:
                         $this->renderForm(new S('categoryMove'));
                         break;
                 }
             } else {
                 // Set some requirements ...
                 $objGetCondition = new S();
                 // Do a sorting, before anything else;
                 if (isset($_GET[ADMIN_ACTION_SORT])) {
                     // Do a switch ...
                     switch ($_GET[ADMIN_ACTION_SORT]) {
                         case 'AscByCategory':
                             // Make the ordered condition;
                             $objGetCondition->appendString(_SP)->appendString('ASC');
                             break;
                         case 'DescByCategory':
                             // Make the ordered condition;
                             $objGetCondition->appendString(_SP)->appendString('DESC');
                             break;
                     }
                 }
                 // Add some LIMITs
                 $objGetCondition->appendString(_SP)->appendString('LIMIT %LowerLimit, %UpperLimit')->doToken('%LowerLimit', $objLowerLimit)->doToken('%UpperLimit', $objUpperLimit);
                 // Set some requirements ...
                 $objCategoryTreeCount = $this->getCategoryCount();
                 $objCategoryTree = $this->getCategories(isset($_GET[ADMIN_SHOW_ALL]) ? new S() : $objGetCondition);
                 // Set the template file ...
                 $tpF = new FilePath($this->getPathToSkin()->toRelativePath() . 'manageCategories.tp');
                 TPL::tpSet($objCategoryTree, new S('categoryTree'), $tpF);
                 TPL::tpExe($tpF);
                 // Do pagination ...
                 if ($objCategoryTreeCount->toInt() > 10 && !isset($_GET[ADMIN_SHOW_ALL])) {
                     self::$objAdministration->setPagination($objCategoryTreeCount);
                 }
                 // Do the form, make it happen;
                 $this->renderForm(new S('categoryCreate'));
             }
             // Break out ...
             break;
         case 'manageOperations':
             // Do the form, make it happen;
             $this->renderForm(new S('categoryMoveOperation'));
             break;
         case 'manageConfiguration':
             // Do the form, make it happen ...
             if (isset($_GET[ADMIN_ACTION])) {
                 $this->renderForm($_GET[ADMIN_ACTION]);
             } else {
                 $this->renderForm(new S('configurationEdit'));
             }
             break;
     }
 }
Ejemplo n.º 4
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 renderBackendPage(S $objPageToRender)
 {
     // Get a specific CSS file for this controller ...
     TPL::manageCSS(new FilePath($this->getPathToSkinCSS()->toRelativePath() . $objPageToRender . CSS_EXTENSION), $objPageToRender);
     // Do pagination ...
     if (isset($_GET[ADMIN_PAGINATION])) {
         $objLowerLimit = (int) $_GET[ADMIN_PAGINATION]->toString() * 10 - 10;
         $objUpperLimit = 10;
     } else {
         $objLowerLimit = 0;
         $objUpperLimit = 10;
     }
     // Do a switch on the rendered page ...
     switch ($objPageToRender) {
         case 'welcomePage':
             // Set the template file ...
             $tpF = new FilePath($this->getPathToSkin()->toRelativePath() . 'welcomePage.tp');
             TPL::tpSet(self::$objAdministration->getWidget(NULL), new S('objWidgets'), $tpF);
             TPL::tpExe($tpF);
             break;
         case 'manageUsers':
             // Do specific actions, based on _GET parameters;
             if (isset($_GET[ADMIN_ACTION])) {
                 // Switch ...
                 switch ($_GET[ADMIN_ACTION]) {
                     case ADMIN_ACTION_EDIT:
                         $this->renderForm(new S('userEdit'));
                         break;
                     case ADMIN_ACTION_ERASE:
                         $this->renderForm(new S('userErase'));
                         break;
                 }
             } else {
                 // Show them ordered by DESC;
                 if (!isset($_GET[ADMIN_ACTION_SORT])) {
                     $this->setHeaderKey(URL::rewriteURL(new A(array(ADMIN_ACTION_SORT)), new A(array('DescByRegistered'))), new S('Location'));
                 }
                 // Set some requirements;
                 $objGetCondition = new S();
                 if (isset($_GET[ADMIN_ACTION_BY])) {
                     // Do a switch ...
                     switch ($_GET[ADMIN_ACTION_BY]) {
                         case AUTHENTICATION_PROFILE_USERNAME:
                             $objGetCondition->appendString('WHERE %objAuthUsersTableFUName');
                             break;
                         case AUTHENTICATION_PROFILE_EMAIL:
                             $objGetCondition->appendString('WHERE %objAuthUsersTableFEML');
                             break;
                         case AUTHENTICATION_PROFILE_GROUP:
                             $objGetCondition->appendString('AS t1 LEFT JOIN %objAuthGroupTable
                             AS t2 ON t1.%objAuthUsersTableFUGId = t2.%objAuthGroupTableFId
                             WHERE t2.%objAuthGroupTableFName');
                             break;
                     }
                     // Add LIKE searching ...
                     $objGetCondition->appendString(_SP)->appendString('LIKE "%%Search%"')->doToken('%Search', $_GET[ADMIN_ACTION_SEARCH]);
                 }
                 if (isset($_GET[ADMIN_ACTION_SORT])) {
                     // Switch ...
                     switch ($_GET[ADMIN_ACTION_SORT]) {
                         case 'AscByUsername':
                         case 'DescByUsername':
                             // Set the order ...
                             $objGetCondition->appendString(_SP)->appendString('ORDER BY %objAuthUsersTableFUName');
                             // Switch ...
                             switch ($_GET[ADMIN_ACTION_SORT]) {
                                 case 'AscByUsername':
                                     $objGetCondition->appendString(_SP)->appendString('ASC');
                                     break;
                                 case 'DescByUsername':
                                     $objGetCondition->appendString(_SP)->appendString('DESC');
                                     break;
                             }
                             break;
                         case 'AscByEMail':
                         case 'DescByEMail':
                             // Set the order ...
                             $objGetCondition->appendString(_SP)->appendString('ORDER BY %objAuthUsersTableFEML');
                             // Switch ...
                             switch ($_GET[ADMIN_ACTION_SORT]) {
                                 case 'AscByEMail':
                                     $objGetCondition->appendString(_SP)->appendString('ASC');
                                     break;
                                 case 'DescByEMail':
                                     $objGetCondition->appendString(_SP)->appendString('DESC');
                                     break;
                             }
                             break;
                         case 'AscByGroup':
                         case 'DescByGroup':
                             // Set the order ...
                             if (isset($_GET[ADMIN_ACTION_BY])) {
                                 $objGetCondition->appendString(_SP)->prependString('AS t1 LEFT JOIN %objAuthGroupTable
                                 AS t2 ON t1.%objAuthUsersTableFUGId = t2.%objAuthGroupTableFId ');
                             } else {
                                 $objGetCondition->appendString(_SP)->appendString('AS t1 LEFT JOIN %objAuthGroupTable
                                 AS t2 ON t1.%objAuthUsersTableFUGId = t2.%objAuthGroupTableFId ');
                             }
                             // Add order by ...
                             $objGetCondition->appendString(_SP)->appendString('ORDER BY t2.%objAuthGroupTableFName');
                             // Switch ...
                             switch ($_GET[ADMIN_ACTION_SORT]) {
                                 case 'AscByGroup':
                                     $objGetCondition->appendString(_SP)->appendString('ASC');
                                     break;
                                 case 'DescByGroup':
                                     $objGetCondition->appendString(_SP)->appendString('DESC');
                                     break;
                             }
                             break;
                         case 'AscByRegistered':
                         case 'DescByRegistered':
                             // Set the order ...
                             $objGetCondition->appendString(_SP)->appendString('ORDER BY %objAuthUsersTableFRegOn');
                             // Switch ...
                             switch ($_GET[ADMIN_ACTION_SORT]) {
                                 case 'AscByRegistered':
                                     $objGetCondition->appendString(_SP)->appendString('ASC');
                                     break;
                                 case 'DescByRegistered':
                                     $objGetCondition->appendString(_SP)->appendString('DESC');
                                     break;
                             }
                             break;
                     }
                 }
                 // Make the unordered condition;
                 $objGetCondition = $objGetCondition->appendString(_SP)->appendString('LIMIT %LowerLimit, %UpperLimit')->doToken('%LowerLimit', $objLowerLimit)->doToken('%UpperLimit', $objUpperLimit);
                 // Get the users ...
                 $objUsersTable = $this->getUsers($objGetCondition);
                 if (isset($_GET[ADMIN_ACTION_BY])) {
                     $objUsersTableCount = $objUsersTable->doCount();
                 } else {
                     $objUsersTableCount = $this->getUserCount();
                 }
                 // Get each group for each user ...
                 foreach ($objUsersTable as $k => $v) {
                     $v['group_name'] = $this->getGroupInfoById($v[Authentication::$objAuthUsersTableFUGId], Authentication::$objAuthGroupTableFName);
                 }
                 // Fix pagination when count is LESS than 10;
                 if (isset($_GET[ADMIN_ACTION_BY]) && isset($_GET[ADMIN_PAGINATION])) {
                     if ($objUsersTableCount->toInt() < 10) {
                         // Remove paging ... & redirect to proper ...
                         TPL::setHeaderKey(URL::rewriteURL(new A(array(ADMIN_PAGINATION))), new S('Location'));
                     } else {
                         if (CEIL($objUsersTableCount->toInt() / 10) < (int) $_GET[ADMIN_PAGINATION]->toString()) {
                             // Redirect to proper ...
                             TPL::setHeaderKey(URL::rewriteURL(new A(array(ADMIN_PAGINATION)), new A(array(CEIL($objUsersTableCount->toInt() / 10)))), new S('Location'));
                         }
                     }
                 }
                 // Set the template file ...
                 $tpF = new FilePath($this->getPathToSkin()->toRelativePath() . 'manageUsers.tp');
                 TPL::tpSet($objUsersTable, new S('usersTable'), $tpF);
                 TPL::tpSet($this->STG, new S('STG'), $tpF);
                 TPL::tpExe($tpF);
                 // Do them pagination ...
                 if ($objUsersTableCount->toInt() > 10) {
                     self::$objAdministration->setPagination($objUsersTableCount);
                 }
                 // Set a search form;
                 $this->renderForm(new S('userSearch'));
                 $this->renderForm(new S('userCreate'));
             }
             break;
         case 'manageGroups':
             // Add some requirements;
             TPL::manageJSS(new FilePath($this->getPathToSkinJSS()->toRelativePath() . 'manageGroups.js'), new S('manageCategories'));
             // Do specific actions, based on _GET parameters;
             if (isset($_GET[ADMIN_ACTION])) {
                 switch ($_GET[ADMIN_ACTION]) {
                     case ADMIN_ACTION_EDIT:
                         $this->renderForm(new S('groupEdit'));
                         break;
                     case ADMIN_ACTION_ERASE:
                         $this->renderForm(new S('groupErase'));
                         break;
                     case ADMIN_ACTION_MOVE:
                         $this->renderForm(new S('groupMove'));
                         break;
                 }
             } else {
                 // Do an empty SQL string;
                 $objGetCondition = new S();
                 // Do a sorting, before anything else;
                 if (isset($_GET[ADMIN_ACTION_SORT])) {
                     switch ($_GET[ADMIN_ACTION_SORT]) {
                         case 'DescByGroup':
                             $objGetCondition->appendString(_SP)->appendString('DESC');
                             break;
                         case 'AscByGroup':
                             $objGetCondition->appendString(_SP)->appendString('ASC');
                             break;
                     }
                 }
                 // Add some LIMITs;
                 $objGetCondition->appendString(_SP)->appendString('LIMIT %LowerLimit, %UpperLimit')->doToken('%LowerLimit', $objLowerLimit)->doToken('%UpperLimit', $objUpperLimit);
                 // Set some requirements;
                 $objGroupTable = $this->getGroups(isset($_GET[ADMIN_SHOW_ALL]) ? new S() : $objGetCondition);
                 $objGroupTableCount = $this->getGroupCount();
                 // Set the template file ...
                 $tpF = new FilePath($this->getPathToSkin()->toRelativePath() . 'manageGroups.tp');
                 TPL::tpSet($objGroupTable, new S('groupTree'), $tpF);
                 TPL::tpExe($tpF);
                 // Do them paginations ...
                 if ($objGroupTableCount->toInt() > 10 && !isset($_GET[ADMIN_SHOW_ALL])) {
                     self::$objAdministration->setPagination($objGroupTableCount);
                 }
                 // Do the form, make it happen;
                 $this->renderForm(new S('groupCreate'));
             }
             break;
         case 'manageZones':
             // Do specific actions, based on _GET parameters;
             if (isset($_GET[ADMIN_ACTION])) {
                 // Switch ...
                 switch ($_GET[ADMIN_ACTION]) {
                     case ADMIN_ACTION_EDIT:
                         $this->renderForm(new S('zoneEdit'));
                         break;
                     case ADMIN_ACTION_ERASE:
                         $this->renderForm(new S('zoneErase'));
                         break;
                 }
             } else {
                 // Do a sorting beforehand;
                 $objGetCondition = new S();
                 if (isset($_GET[ADMIN_ACTION_SORT])) {
                     switch ($_GET[ADMIN_ACTION_SORT]) {
                         case 'AscByZone':
                         case 'DescByZone':
                             // Switch ...
                             switch ($_GET[ADMIN_ACTION_SORT]) {
                                 case 'AscByZone':
                                     $objGetCondition->appendString(_SP)->appendString(new S('ASC'));
                                     break;
                                 case 'DescByZone':
                                     $objGetCondition->appendString(_SP)->appendString(new S('DESC'));
                                     break;
                             }
                             break;
                     }
                 }
                 // Add some LIMITs
                 $objGetCondition->appendString(_SP)->appendString('LIMIT %LowerLimit, %UpperLimit')->doToken('%LowerLimit', $objLowerLimit)->doToken('%UpperLimit', $objUpperLimit);
                 // Set some requirements;
                 $objZonesTable = $this->getZones($objGetCondition);
                 $objZonesTableCount = $this->getZoneCount();
                 // Set the template file ...
                 $tpF = new FilePath($this->getPathToSkin()->toRelativePath() . 'manageZones.tp');
                 TPL::tpSet($objZonesTable, new S('zonesTable'), $tpF);
                 TPL::tpExe($tpF);
                 // Do them paginations ...
                 if ($objZonesTableCount->toInt() > 10) {
                     self::$objAdministration->setPagination($objZonesTableCount);
                 }
             }
             break;
         case 'manageMappings':
             // Do specific actions, based on _GET parameters;
             if (isset($_GET[ADMIN_ACTION])) {
                 switch ($_GET[ADMIN_ACTION]) {
                     case ADMIN_ACTION_EDIT:
                         $this->renderForm(new S('zoneMappingEdit'));
                         break;
                     case ADMIN_ACTION_ERASE:
                         $this->renderForm(new S('zoneMappingErase'));
                         break;
                 }
             } else {
                 // Do a sorting beforehand;
                 $objGetCondition = new S();
                 if (isset($_GET[ADMIN_ACTION_SORT])) {
                     // Switch ...
                     switch ($_GET[ADMIN_ACTION_SORT]) {
                         case 'AscByGroup':
                         case 'DescByGroup':
                             // Set some requirements;
                             $objGetCondition->appendString(_SP)->appendString('AS t1 LEFT JOIN %objAuthGroupTable
                             AS t2 ON t1.%objAuthZoneMTableFUGId = t2.%objAuthGroupTableFId
                             ORDER BY t2.%objAuthGroupTableFName');
                             switch ($_GET[ADMIN_ACTION_SORT]) {
                                 case 'AscByGroup':
                                     $objGetCondition->appendString(_SP)->appendString('ASC');
                                     break;
                                 case 'DescByGroup':
                                     $objGetCondition->appendString(_SP)->appendString('DESC');
                                     break;
                             }
                             break;
                         case 'AscByZoneForGroup':
                         case 'DescByZoneForGroup':
                             // Set some requirements;
                             $objGetCondition = new S('AS t1 LEFT JOIN %objAuthZonesTable
                             AS t2 ON t1.%objAuthZoneMTableFZId = t2.%objAuthGroupTableFId
                             ORDER BY t2.%objAuthZonesTableFName');
                             switch ($_GET[ADMIN_ACTION_SORT]) {
                                 case 'AscByZoneForGroup':
                                     $objGetCondition->appendString(_SP)->appendString('ASC');
                                     break;
                                 case 'DescByZoneForGroup':
                                     $objGetCondition->appendString(_SP)->appendString('DESC');
                                     break;
                             }
                             break;
                     }
                 }
                 // LIMIT only TO GROUP;
                 if ($objGetCondition->toLength()->toInt() != 0) {
                     $objGetCondition->doToken('ORDER', new S('WHERE %objAuthZoneMTableFIUG = "Y" ORDER'));
                 } else {
                     $objGetCondition = new S('WHERE %objAuthZoneMTableFIUG = "Y"');
                 }
                 // Add SOME LIMITs;
                 $objGetCondition->appendString(_SP)->appendString('LIMIT %LowerLimit, %UpperLimit')->doToken('%LowerLimit', $objLowerLimit)->doToken('%UpperLimit', $objUpperLimit);
                 // Set some requirements;
                 $objZoneMappings = $this->getZoneMappings($objGetCondition);
                 $objMappingsTableCount = $this->getMappingCount(new S('WHERE %objAuthZoneMTableFIUG = "Y"'));
                 // Set the template file ...
                 $tpF = new FilePath($this->getPathToSkin()->toRelativePath() . 'manageMappings.tp');
                 TPL::tpSet($objZoneMappings, new S('zonesMappingsTableForGroup'), $tpF);
                 TPL::tpExe($tpF);
                 // Do pagination;
                 if ($objMappingsTableCount->toInt() > 10) {
                     self::$objAdministration->setPagination($objMappingsTableCount);
                 }
                 // Do the form, make it happen;
                 $this->renderForm(new S('zoneMappingCreateForGroups'));
             }
             break;
         case 'manageMappingsForUsers':
             // Do specific actions, based on _GET parameters;
             if (isset($_GET[ADMIN_ACTION])) {
                 switch ($_GET[ADMIN_ACTION]) {
                     case ADMIN_ACTION_EDIT:
                         $this->renderForm(new S('zoneMappingEdit'));
                         break;
                     case ADMIN_ACTION_ERASE:
                         $this->renderForm(new S('zoneMappingErase'));
                         break;
                 }
             } else {
                 // Do a sorting beforehand;
                 $objGetUCondition = new S();
                 if (isset($_GET[ADMIN_ACTION_SORT])) {
                     switch ($_GET[ADMIN_ACTION_SORT]) {
                         case 'AscByZone':
                         case 'DescByZone':
                             // Set some requirements;
                             $objGetUCondition = new S('AS t1 LEFT JOIN %objAuthZonesTable
                             AS t2 ON t1.%objAuthZoneMTableFZId = t2.%objAuthUsersTableFId
                             ORDER BY t2.%objAuthZonesTableFName');
                             switch ($_GET[ADMIN_ACTION_SORT]) {
                                 case 'AscByZone':
                                     $objGetUCondition->appendString(_SP)->appendString('ASC');
                                     break;
                                 case 'DescByZone':
                                     $objGetUCondition->appendString(_SP)->appendString('DESC');
                                     break;
                             }
                             break;
                         case 'AscByUsername':
                         case 'DescByUsername':
                             // Set some requirements;
                             $objGetUCondition = new S('AS t1 LEFT JOIN %objAuthUsersTable
                             AS t2 ON t1.%objAuthZoneMTableFUGId = t2.%objAuthUsersTableFId
                             ORDER BY t2.%objAuthUsersTableFUName');
                             switch ($_GET[ADMIN_ACTION_SORT]) {
                                 case 'AscByUsername':
                                     $objGetUCondition->appendString(_SP)->appendString('ASC');
                                     break;
                                 case 'DescByUsername':
                                     $objGetUCondition->appendString(_SP)->appendString('DESC');
                                     break;
                             }
                             break;
                     }
                 }
                 // LIMIT ONLY to USERS;
                 if ($objGetUCondition->toLength()->toInt() != 0) {
                     $objGetUCondition->doToken('ORDER', new S('WHERE %objAuthZoneMTableFIUG = "N" ORDER'));
                 } else {
                     $objGetUCondition = new S('WHERE %objAuthZoneMTableFIUG = "N"');
                 }
                 // Set some requirements;
                 $objMappingsTableCount = $this->getMappingCount(new S('WHERE %objAuthZoneMTableFIUG = "N"'));
                 $objZoneMappings = $this->getZoneMappings($objGetUCondition);
                 // Set the template file;
                 $tpF = new FilePath($this->getPathToSkin()->toRelativePath() . 'manageMappingsForUsers.tp');
                 TPL::tpSet($objZoneMappings, new S('zonesMappingsTableForUsers'), $tpF);
                 TPL::tpExe($tpF);
                 // Do pagination;
                 if ($objMappingsTableCount->toInt() > 10) {
                     self::$objAdministration->setPagination($objMappingsTableCount);
                 }
                 // Do the form, make it happen;
                 $this->renderForm(new S('zoneMappingCreateForUsers'));
             }
             // Break out;
             break;
         case 'manageConfiguration':
             if (isset($_GET[ADMIN_ACTION])) {
                 $this->renderForm($_GET[ADMIN_ACTION]);
             } else {
                 $this->renderForm(new S('configurationEdit'));
             }
             break;
     }
 }
Ejemplo n.º 5
0
 /**
  * Constructs the administration object, taking the authentication object as a parameter and storing it for further use;
  *
  * This method will construct the administration object, which automatically takes an authentication object as a parameter. Thus
  * we can have separate authentication mechanisms (besides the implemented MySQL authentication) that can be used with our
  * administration mechanism, as long as the proper parameters respect the IFaceAuthentication interface;
  *
  * @param IFaceAuthentication $objAuthMech The authentication object, passed as a parameter;
  * @return void Doesn't need to return anything (being a constructor);
  */
 public function __construct(IFaceAuthentication $objAuthMech)
 {
     // Construct any possible parent, parse the configuration meanwhile;
     parent::__construct();
     // Set the execution time start;
     self::setExeTime(new S('administration_start'));
     // Tie in common configuration data;
     $this->tieInCommonConfiguration();
     // Tie in with the authentication mechanism;
     $this->tieInWithAuthenticationMechanism($objAuthMech);
     // Set some requirements ...
     $objPathToSkinJSS = $this->getPathToSkinJSS()->toRelativePath();
     $objPathToSkinCSS = $this->getPathToSkinCSS()->toRelativePath();
     // Auto-LogOut the user if we detect the proper action ...
     if (isset($_GET[ADMIN_INTERFACE_ACTION])) {
         // Switch ...
         switch ($_GET[ADMIN_INTERFACE_ACTION]) {
             case ADMIN_LOG_OUT:
                 self::$objAuthenticationMech->doLogOut();
                 URL::doCleanURLPath();
                 break;
             case ADMIN_SWITCH_THEME:
                 if ($this->objCookie->checkKey(new S('admin_css'))->toBoolean() == TRUE) {
                     switch ($this->objCookie->getKey(new S('admin_css'))) {
                         case 'default.css':
                             $this->objCookie->setKey(new S('admin_css'), new S('default_inverted.css'), new B(TRUE));
                             break;
                         default:
                             $this->objCookie->setKey(new S('admin_css'), new S('default.css'), new B(TRUE));
                             break;
                     }
                 } else {
                     // Set the INVERTED, at first ...
                     $this->objCookie->setKey(new S('admin_css'), new S('default_inverted.css'), new B(TRUE));
                 }
                 // Get out ...
                 $this->setHeaderKey(URL::rewriteURL(new A(array(ADMIN_INTERFACE_ACTION))), new S('Location'));
                 break;
         }
     }
     // Set the required JS dependencies ...
     TPL::manageCSS(new FilePath($objPathToSkinJSS . 'jQ' . _S . 'jQUI.css'), new S('jQUICSS'));
     TPL::manageCSS(new FilePath($objPathToSkinJSS . 'jQ' . _S . 'jQContextMenu.css'), new S('jQCM'));
     TPL::manageCSS(new FilePath($objPathToSkinJSS . 'jQ' . _S . 'jQFancybox.css'), new S('jQFancybox'));
     TPL::manageJSS(new FilePath($objPathToSkinJSS . 'jQ' . _S . 'jQ.js'), new S('jQ'));
     TPL::manageJSS(new FilePath($objPathToSkinJSS . 'jQ' . _S . 'jQUI.js'), new S('jQUI'));
     TPL::manageJSS(new FilePath($objPathToSkinJSS . 'jQ' . _S . 'jQClock.js'), new S('jQClock'));
     TPL::manageJSS(new FilePath($objPathToSkinJSS . 'jQ' . _S . 'jQBind.js'), new S('jQBind'));
     TPL::manageJSS(new FilePath($objPathToSkinJSS . 'jQ' . _S . 'jQUICheckbox.js'), new S('jQUICR'));
     TPL::manageJSS(new FilePath($objPathToSkinJSS . 'jQ' . _S . 'jQFileStyle.js'), new S('jQFStyle'));
     TPL::manageJSS(new FilePath($objPathToSkinJSS . 'jQ' . _S . 'jQEasing.js'), new S('jQEasing'));
     TPL::manageJSS(new FilePath($objPathToSkinJSS . 'jQ' . _S . 'jQFancybox.js'), new S('jQFancybox'));
     TPL::manageJSS(new FilePath($objPathToSkinJSS . 'jQ' . _S . 'jQToolTip.js'), new S('jQTT'));
     TPL::manageJSS(new FilePath($objPathToSkinJSS . 'jQ' . _S . 'jQWidget.js'), new S('jQWidget'));
     TPL::manageJSS(new FilePath($objPathToSkinJSS . 'jQ' . _S . 'jQContextMenu.js'), new S('jQCM'));
     TPL::manageJSS(new FilePath($objPathToSkinJSS . 'jQ' . _S . 'jQMasked.js'), new S('jQMasked'));
     TPL::manageJSS(new FilePath($objPathToSkinJSS . 'jQ' . _S . 'jQTypeFace.js'), new S('jQTF'));
     TPL::manageJSS(new FilePath($objPathToSkinJSS . 'jQ' . _S . 'jQKabelTypeFace.js'), new S('jQTK'));
     TPL::manageJSS(new FilePath($objPathToSkinJSS . 'jQ' . _S . 'jQExe.js'), new S('jQExe'));
     // Add the default CSS, either black or white ...
     if ($this->objCookie->checkKey(new S('admin_css'))->toBoolean() == TRUE) {
         // Set the proper CSS, acording to _SESSION;
         TPL::manageCSS(new FilePath($objPathToSkinCSS . $this->objCookie->getKey(new S('admin_css'))), new S(__CLASS__));
     } else {
         // Set the default to BLACK;
         TPL::manageCSS(new FilePath($objPathToSkinCSS . 'default.css'), new S(__CLASS__));
     }
     // Safari, Google Chrome and maybe others on WebKIT ...
     if ($this->getUserAgentProperty(new S('browser')) == 'sf') {
         // Add'em fixes ...
         TPL::manageCSS(new FilePath($objPathToSkinCSS . 'default_fixed.css'), new S('safari-css-fix'));
     }
     // Get the proper configuration options stored in the object;
     self::$objHeaderText = $this->getConfigKey(new S('administration_header_text'));
     self::$objFooterText = $this->getConfigKey(new S('administration_footer_text'));
     // Do some actions, based on user information;
     if (self::$objAuthenticationMech->checkIfUserIsLoggedIn()->toBoolean() == TRUE and self::$objAuthenticationMech->checkCurrentUserZoneACL(new S(__CLASS__))->toBoolean() == TRUE) {
         // Redirect to the dashboard page;
         if (!isset($_GET[ADMIN_PAGE])) {
             $this->setHeaderKey(URL::rewriteURL(new A(array(ADMIN_PAGE)), new A(array(ADMIN_DASHBOARD))), new S('Location'));
         }
         // Do a CALL to ALL registered administrator interfaces;
         $this->tieALLRegisteredAdminInterfaces();
     } else {
         // Echo an error, for our dear friend, the Internet Explorer (MSIE);
         if ($this->getUserAgentProperty(new S('browser')) == 'ie') {
             self::renderScreenOfDeath(new S(__CLASS__), new S(ADMIN_IE_NOT_ALLOWED), new S(ADMIN_IE_NOT_ALLOWED_FIX));
         } else {
             // Safari, Google Chrome and maybe others on WebKIT ...
             if ($this->getUserAgentProperty(new S('browser')) == 'sf') {
                 // Add'em fixes ...
                 TPL::manageCSS(new FilePath($objPathToSkinCSS . 'default_fixed_adm.css'), new S('safari-fix'));
             }
             // Do the authentication screen;
             self::$objAuthenticationMech->renderForm(new S('adminLoginScreen'));
             // Set some predefines ...
             self::$objMenuArray = new A();
             self::$objSubMArray = new A();
             self::$objLogOutLink = new S();
             self::$objSwitcherLink = new S();
             // After we know all the details, execute the viewer whit these parameters;
             $tpF = new FilePath($this->getPathToSkin()->toRelativePath() . 'administration.tp');
             TPL::tpSet(self::$objHeaderText, new S('objHeaderText'), $tpF);
             TPL::tpSet(self::$objFooterText, new S('objFooterText'), $tpF);
             TPL::tpSet(self::$objMenuArray, new S('objMenuArray'), $tpF);
             TPL::tpSet(self::$objSubMArray, new S('objSubMArray'), $tpF);
             TPL::tpSet(self::$objLogOutLink, new S('objLogOutLink'), $tpF);
             TPL::tpSet(self::$objSwitcherLink, new S('objSwitcherLink'), $tpF);
             TPL::tpExe($tpF);
         }
     }
 }
Ejemplo n.º 6
0
 /**
  * Will execute the footer, and do additional clean-up that are common to the platform;
  *
  * This method will execute the necessary footer templates, and do clean-up operations common for the whole website. It's a
  * way to avoid having to write files with that code, and link'em in every page. We try to avoid such redundant operations as
  * much as we can, thus mappings like this are a good way to get to that ...
  */
 public function doFooterCommonRequirements()
 {
     // The TITLE, per-se ... as we need. It says who we are, what we do ...
     TPL::manageTTL($this->STG->getConfigKey(new S('settings_website_default_title')));
     // HTTP-EQUIVs ... as per HTTP/1.1
     TPL::manageEQV(new S('Content-Type'), new S('text/html; charset=UTF-8'));
     TPL::manageEQV(new S('Content-Script-Type'), new S('text/javascript'));
     TPL::manageEQV(new S('Content-Style-Type'), new S('text/css'));
     // Add'em defaults ... and specifics ... if they need to be added ...
     TPL::manageTAG(new S('copyright'), new S('KIT Software CAZ SRL on the RA PHP Framework code ONLY!'));
     TPL::manageTAG(new S('author'), new S('Catalin Alexandru Zamfir, KIT Software CAZ SRL'));
     TPL::manageTAG(new S('generator'), new S('RA PHP Framework.ro Platform'));
     TPL::manageTAg(new S('robots'), new S('index, follow'));
     TPL::manageTAG(new S('revisit-after'), new S('1 days'));
     // Google, Yahoo, MSN, RA PHP Framework WBMs ...
     TPL::manageTAG(new S('y_key'), new S(YAHOO__WBM_KEY));
     TPL::manageTAG(new S('verify-v1'), new S(GOOGLE_WBM_KEY));
     TPL::manageTAG(new S('msvalidate.01'), new S(BING___WBM_KEY));
     TPL::manageTAG(new S('ra_key'), new S(SHA1(DOCUMENT_HOST)));
     // Add'em DEFAULTS ... forever ...
     TPL::manageCSS(new FilePath($this->objPathToSkinCSS . 'default.css'), new S('default_css'));
     // Check for some IEs, Operas and others ...
     if ($this->getUserAgentProperty(new S('browser')) == 'ie') {
         // Specific IE CSS (believe it ...)
         TPL::manageCSS(new FilePath($this->objPathToSkinCSS . 'default_ie.css'), new S('default_ie'));
         // Specific IE jQuery JSS (ya! ...)
         TPL::manageJSS(new FilePath($this->objPathToSkinJSS . 'jQuery/jQExeIE.js'), new S('jQExeIE'));
     }
     // Set the execution time ...
     TPL::setExeTime(new S('finish'));
 }