<?php
/*
  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Implemented by Blake Schwendiman (blake@intechra.net)
	Updated 2002/3/30 -- Ross Lapkoff (rlapkoff@austin.rr.com)

  Copyright (c) 2002 osCommerce

  Released under the GNU General Public License
*/
    
    $aADMBoxes = array ( 
		         'administrators.php'   => BOX_HEADING_ADMINISTRATORS, 
                         'catalog.php'          => BOX_HEADING_CATALOG, 
                         'configuration.php'    => BOX_HEADING_CONFIGURATION,
                         'customers.php'        => BOX_HEADING_CUSTOMERS, 
                         'localization.php'     => BOX_HEADING_LOCALIZATION,
		         'taxes.php'            => BOX_HEADING_LOCATION_AND_TAXES, 
                         'modules.php'          => BOX_HEADING_MODULES, 
                         'reports.php'          => BOX_HEADING_REPORTS,
                         'tools.php'            => BOX_HEADING_TOOLS,
                         'polls.php'            => BOX_HEADING_POLLS,
                         'gv_admin.php'         => BOX_HEADING_GV_ADMIN,
                         'paypalipn.php.php'    => BOX_HEADING_PAYPALIPN
                         );
                      
    // associate all the admin pages with the box class that includes it                      
    $aADMPages = array( 'configuration.php'            => 'configuration.php',
                        'modules.php'                  => 'modules.php',
			'categories.php'	       => 'catalog.php',
                        'products_attributes.php'      => 'catalog.php',
                        'manufacturers.php'            => 'catalog.php',
                        'reviews.php'                  => 'catalog.php',
                        'specials.php'                 => 'catalog.php', 
                        'products_expected.php'        => 'catalog.php',
                        'customers.php'                => 'customers.php',
                        'orders.php'                   => 'customers.php',
                        'countries.php'                => 'taxes.php',
                        'zones.php'                    => 'taxes.php',
                        'geo_zones.php'                => 'taxes.php',
                        'tax_classes.php'              => 'taxes.php',
                        'tax_rates.php'                => 'taxes.php',
                        'banner_manager.php'           => 'banners.php',
                        'currencies.php'               => 'localization.php',
                        'languages.php'                => 'localization.php',
                        'orders_status.php'            => 'localization.php',
                        'stats_products_viewed.php'    => 'reports.php',
                        'stats_products_purchased.php' => 'reports.php',
                        'stats_customers.php'          => 'reports.php',
                        'file_manager.php'             => 'tools.php',
                        'backup.php'                   => 'tools.php',
			'banner_manager.php'	       => 'tools.php',
			'define_languages.php'	       => 'tools.php',
                        'whos_online.php'              => 'tools.php',
                        'cache.php'                    => 'tools.php',
                        'mail.php'                     => 'tools.php',
			'newsletters.php'	       => 'tools.php',
			'server_info.php'	       => 'tools.php',
                        'administrators.php'           => 'administrators.php',
			'update_admin.php'	       => 'administrators.php',
			'index.php'		       => 'support',
			'logoff.php'		       => 'support',
			'login.php'		       => 'support',												
			'paypalipn_txn.php'	       => 'paypalipn.php'												
                     );                    
    

    function RequireLoginValidForPage($aRetPage)
    {
    global $PHP_SELF, $in_login, $login_id, $aADMPages;
     
if (!$aRetPage) die('no return page');
if (basename($aRetPage)=='') $aRetPage = 'index.php';
         $aRetPage = basename($aRetPage);
         if ($aRetPage == 'admin') $aRetPage = 'index.php';
	$aThisPage = basename($PHP_SELF);
//        $aRetPage  = str_replace( $aThisPage, 'index.php', $aRetPage );
//	$aRetPage = 'index.php';			    
        if (empty($in_login ))
        {
            if (!tep_session_is_registered('login_id')) 
            {
            tep_redirect(tep_href_link('login.php','in_login=yes&retpage=' . urlencode($aRetPage)));

            } else {
              $aSQL = "select allowed_pages from administrators where (admin_id = '$login_id')";
              $aRes = tep_db_query($aSQL);
                if ($aVal = tep_db_fetch_array($aRes))
                {
                  $aPages = $aVal['allowed_pages'];
                  if (trim($aPages != '*'))
                  {
                    $aAllowedPages   = explode('|', $aPages);
                    $aCurrentPageBox = $aADMPages[$aThisPage];
                      if ($aCurrentPageBox != '*')
                        {
                          if (!in_array( $aCurrentPageBox, $aAllowedPages))
                          {
				 echo '<center><p><font size="+2">You are not authorized to view this page, please go back.';
				 exit();
                          }
                       }
                   }
               } 
           }
       }
   }
    
    function CanShowBox($aBoxName)
    {
        global $login_id;
        $aSQL = "select allowed_pages from administrators where (admin_id = '$login_id')";
        $aRes = tep_db_query($aSQL);
        if ( $aVal = tep_db_fetch_array( $aRes ) )
        {
            $aPages = $aVal['allowed_pages'];
            if (trim( $aPages != '*' ))
            {
                $aAllowedPages   = explode('|', $aPages);
                $aCurrentPageBox = $aBoxName;
                if (in_array($aCurrentPageBox, $aAllowedPages))
                {
                    return true;
                }
            } else {
                return true;
            }
        }
        return false;
    }
?>