<?php 
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' ); 
/**
* @version $Id: phpshop.php,v 1.14 2005/02/09 17:14:23 soeren_nb Exp $
* @package mambo-phpShop
* @subpackage HTML
* @copyright (C) 2004-2005 Soeren Eberhardt
*
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
* mambo-phpShop is Free Software.
* mambo-phpShop comes with absolute no warranty.
*
* www.mambo-phpshop.net
*/

global $mosConfig_absolute_path, $product_id;
/* Load the phpshop main parse code */
require_once( $mosConfig_absolute_path.'/components/com_phpshop/phpshop_parser.php' );

$PHPSHOP_LANG =& new phpShopLanguage();
$ps_vendor_id = $_SESSION['ps_vendor_id'];
$auth = $_SESSION['auth'];
$no_menu = mosGetParam( $_REQUEST, 'no_menu', 0 );

// Timer Start
if (DEBUG) {
  $start = utime();
}

// update the cart because something could have 
// changed while running a function
$cart = $_SESSION["cart"];
    
if ((defined('_DONT_VIEW_PAGE') || defined('_CANNOT_RUN_FUNC')) 
    && $_REQUEST['page'] != 'checkout.index') {

    /*    $page = ERRORPAGE; 
        $my_page= explode ( '.', $page );
        $modulename = $my_page[0];
        $pagename = $my_page[1];
    */
  if( defined('_DONT_VIEW_PAGE') && _DONT_VIEW_PAGE == '2' ) {
    $page = @$_REQUEST['page'];
    echo "<br/><bv/>"._DO_LOGIN;
    $modulename = "checkout";
    $pagename= "login_form";
  }
  else {
    mosRedirect('index.php?option=com_phpshop&page='.$_SESSION['last_page'], $error." Error Type: ".$error_type);
    exit();
  }
}

// For there's no errorpage to display the error,
// we must echo it before the page is loaded
if (!empty($error) && $page != ERRORPAGE) 
    echo "<span class=\"message\">".$error."</span>";
    
    /*****************************
    ** FRONTEND ADMIN - MOD
    **/
    $pshop_mode = mosgetparam($_REQUEST, 'pshop_mode', "");
    if (($pshop_mode == "admin" 
        || stristr($page,"form") 
        || stristr($page, "list")
        || stristr($page, "cfg")
        || stristr($page, "print") 
        || stristr($page, "display"))
        && ($perm->check("admin,storeadmin")
            && ((!stristr($my->usertype, "admin") ^ PSHOP_ALLOW_FRONTENDADMIN_FOR_NOBACKENDERS == '' ) 
                || stristr($my->usertype, "admin")
               )
            && !stristr($page, "shop.")
            )
        && $no_menu != "1"
    ) {
    
      // The admin header with dropdown menu
      include( ADMINPATH."header.php" );

      // Toolbar (save & back)
      if ( $page == "admin.show_cfg" || stristr($page, "form")) {
      
          require_once( "includes/HTML_toolbar.php" );
          function editorScript($editor1='', $editor2='') {    
            ?>
                 <script>
                    function submitbutton(pressbutton) {
                      var form = document.adminForm;
                      if (pressbutton == 'cancel') {
                        submitform( pressbutton );
                        return;
                      }
                        <?php 
                        if ($editor1 != '')
                          getEditorContents( 'editor1', $editor1 ) ; ?>
                        <?php
                        if ($editor2 != '')
                          getEditorContents( 'editor2', $editor2 ) ; ?>
                        submitform( pressbutton );
            
                    }
                    </script><?php
            }
            $editor1_array = Array('product.product_form' => 'product_desc',
                                              'product.product_category_form' => 'category_description',
                                              'store.store_form' => 'vendor_store_desc',
                                              'vendor.vendor_form' => 'vendor_store_desc');
            $editor2_array = Array('store.store_form' => 'vendor_terms_of_service',
                                              'vendor.vendor_form' => 'vendor_terms_of_service');
           editorScript(isset($editor1_array[$page]) ? $editor1_array[$page] : '', isset($editor2_array[$page]) ? $editor2_array[$page] : '');
            ?>
          <table cellspacing="0" cellpadding="0" border="0" width="100%">
          <tr>
            <td >&nbsp;</td>
            <td width="50%">
              <?php
              mosToolBar::startTable();
              mosToolBar::spacer();
              $image = 'images/save.png';
              $image2 = 'images/save_f2.png'; ?>
              <td width="25" align="center">
                <a href="javascript:submitbutton('Save');" onmouseout="MM_swapImgRestore();"  onmouseover="MM_swapImage('save','','<?php echo $image2;?>',1);">
                <img src="<?php echo $image;?>" width="32" height="32" alt="Save" border="0" name="save" /></a>
              </td><?php
              mosToolBar::spacer(25);?>
              <td width="25" align="center">
                <a href="javascript:window.history.back();" onmouseout="MM_swapImgRestore();"  onmouseover="MM_swapImage('cancel','','administrator/images/back_f2.png',1);">
                <img src="administrator/images/back.png" width="32" height="32" alt="Back" border="0" name="cancel" >
                </a>
              </td>
              <?php
              mosToolBar::endtable();
              ?>
            </td>
          </tr>
        </table>
        <?php
        }
      }
    //}
    /**
    ** END: FRONTEND ADMIN - MOD
    *****************************/
    
    /*****************************
    ** BEGIN affiliate additions
    ** by nhyde <nhyde@bigDrift.com> for phpshop v0.6.1
    */
      if (AFFILIATE_ENABLE == '1') {
          $unset_affiliate = false;
          if (!isset($ps_affiliate)) {
            include_class ( 'affiliate' );
            $unset_affiliate = true;
          }
          
          //keep tracking the affiliate
          if(isset($_SESSION['afid'])){
           $ps_affiliate->visit_update();
          }
          
          //register the affiliated visit but only if the 
          // aid is in our database and it is active.
          else{
            //set the affiliate_id = 0 to log any visitors that are not affiliate visitors
             $aff_details = $ps_affiliate->get_affiliate_details($auth['user_id']);
             $affiliate_id = $aff_details['id'];
            
          
           //the logout function may have wiped out the session so search the database
           //and re-register it.
           $q = "SELECT visit_id FROM #__pshop_visit WHERE visit_id = '".session_id()."'";
           $db->query($q);
           
           if($db->next_record()){
             $ps_affiliate->visit_update();
           }
           
           else {
              
              $ps_affiliate->visit_register();
          }
        }
        if (isset($affiliate_id)) {
          $_SESSION['afid'] = $affiliate_id;
          $GLOBALS['afid'] = $affiliate_id;
        }
      }
      /**
      *    END added for affiliate module
      ****************************/
?>
<style type="text/css" media="screen">
img { behavior:	url("components/com_phpshop/js/pngbehavior.htc"); }
</style>

<?php
if( PSHOP_PDF_BUTTON_ENABLE=='1' && !isset($_REQUEST['output']) && ($page=="shop.browse" || $page=="shop.product_details")) {
  echo "<table align=\"right\"><tr><td><a title=\"PDF\" target=\"_blank\" href=\"index2.php?option=com_phpshop&page=shop.pdf_output&showpage=$page&pop=1&output=pdf&product_id=$product_id&category_id=$category_id\">
      <img src=\"".IMAGEURL."ps_image/acroread.png\" alt=\"PDF\" height=\"32\" width=\"32\" border=\"0\" /></a></td></tr></table>";
}
  // Load requested PAGE
  include( PAGEPATH.$modulename.".".$pagename.".php" );

  if (SHOWVERSION) {
    include(PAGEPATH ."/VERSION.txt");
  }
  // Set debug option on/off
  if (DEBUG) {
      $end = utime();
      $runtime = $end - $start;
      $my_debug_page= explode ( '.', DEBUGPAGE );
      $modname = $my_debug_page[0];
      $pagename = $my_debug_page[1];  
      include( PAGEPATH . "$modname.$pagename.php" );
  }

?>
