xtc_redirect(xtc_href_link(FILENAME_LOGIN, '', 'SSL'));
}
// if there is nothing in the customers cart, redirect them to the shopping cart page
if ($_SESSION['cart']->count_contents() < 1) {
    xtc_redirect(xtc_href_link(FILENAME_SHOPPING_CART));
}
// avoid hack attempts during the checkout procedure by checking the internal cartID
if (isset($_SESSION['cart']->cartID) && isset($_SESSION['cartID'])) {
    if ($_SESSION['cart']->cartID != $_SESSION['cartID']) {
        xtc_redirect(xtc_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));
    }
}
// if no shipping method has been selected, redirect the customer to the shipping method selection page
if (!isset($_SESSION['shipping'])) {
    xtc_redirect(xtc_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));
}
// include needed classes
require_once DIR_FS_EXTERNAL . 'paypal/classes/PayPalPayment.php';
$found = false;
$selection = get_third_party_payments();
for ($i = 0, $n = sizeof($selection); $i < $n; $i++) {
    if ($selection[$i]['id'] == $_GET['payment']) {
        $_SESSION['payment'] = $selection[$i]['id'];
        $found = true;
    }
}
if ($found === true) {
    xtc_redirect(xtc_href_link(FILENAME_CHECKOUT_CONFIRMATION, 'conditions=true', 'SSL'));
} else {
    xtc_redirect(xtc_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL'));
}
 function selection()
 {
     global $smarty;
     $payments = get_third_party_payments();
     if (ACTIVATE_GIFT_SYSTEM == 'true') {
         require_once DIR_WS_CLASSES . 'order_total.php';
         $order_total_modules = new order_total();
         $credit_selection = $order_total_modules->credit_selection();
     }
     if (isset($credit_selection) && is_array($credit_selection) && count($credit_selection) > 0) {
         $payments = array();
     }
     if (isset($_SESSION['payment'])) {
         for ($i = 0, $n = count($payments); $i < $n; $i++) {
             if ($payments[$i]['id'] == $_SESSION['payment']) {
                 $_SESSION['payment'] = $this->code;
             }
         }
     }
     $_SESSION['paypal']['approval'] = $this->payment_redirect(false, true);
     if ($_SESSION['paypal']['approval'] == '') {
         $GLOBALS['paypalplus']->enabled = false;
     } else {
         $description = '<div id="ppp_result"></div>
   <script type="text/javascript">
     (function() {
       var pp = document . createElement(\'script\');
       pp.type = \'text/javascript\';
       pp.async = true;
       pp.src = \'https://www.paypalobjects.com/webstatic/ppplus/ppplus.min.js\';
       var s = document.getElementsByTagName(\'script\')[0];
       s . parentNode . insertBefore(pp, s);
     })();
     $(window).on(\'load\',function() {
       ' . (count($payments) > 0 ? '
       if ($(\'input[name="payment"]:checked\', \'#checkout_payment\').val() == "' . $this->code . '") {
         $("#continueButton").attr("onclick", "ppp.doContinue(); return false;");
       }
       ' : '') . '
       $("#checkout_payment").attr("name", "checkout_payment");        
       $.get("' . xtc_href_link('callback/paypal/paypalplus.php', '', 'SSL') . '", function(data) {
         $("#ppp_result").html(data);
       });
       ' . ($this->get_config('MODULE_PAYMENT_' . strtoupper($this->code) . '_USE_TABS') == '1' || count($payments) > 0 ? '
       $("[id*=\\"rd\\"]").click(function(e) {
         if ($(\'input[name="payment"]:checked\', \'#checkout_payment\').val() == "' . $this->code . '") {
           ' . ($this->get_config('MODULE_PAYMENT_' . strtoupper($this->code) . '_USE_TABS') == '1' ? '
           $.get("' . xtc_href_link('callback/paypal/paypalplus.php', '', 'SSL') . '", function(data) {
             $("#ppp_result").html(data);
           });
           ' : '') . '
           ' . (count($payments) > 0 ? '
           $("#continueButton").removeAttr("onclick");
           $("#continueButton").attr("onclick", "ppp.doContinue(); return false;");
           ' : '') . '
         } else {
           ' . (count($payments) > 0 ? '$("#continueButton").removeAttr("onclick");' : '') . '
         }
       });' : '') . '
     });
   </script>';
         $smarty->assign('BUTTON_CONTINUE', xtc_image_submit('button_continue.gif', IMAGE_BUTTON_CONTINUE, 'id="continueButton"'));
         return array('id' => $this->code, 'module' => $this->title, 'description' => $this->info . $description);
     }
 }