Advertisement
vasik

Checkout

Jun 2nd, 2013
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 50.84 KB | None | 0 0
  1. <?php
  2. if ('checkout.php' == basename($_SERVER['SCRIPT_FILENAME']))
  3.      die ('<h2>Direct File Access Prohibited</h2>');
  4.  
  5. global $wpdb;
  6.  
  7. if (!function_exists('eshopShowform')) {
  8.     function eshopShowform($first_name,$last_name,$company,$phone,$email,$address1,$address2,$city,$state,$altstate,$zip,$country,$reference,$comments,$ship_name,$ship_company,$ship_phone,$ship_address,$ship_city,$ship_postcode,$ship_state,$ship_altstate,$ship_country){
  9.     global $wpdb, $blog_id,$eshopoptions;
  10.     $reqdvalues=array('shipping','first_name','last_name','email','phone','address','city','zip','pay');
  11.     //setupshipping arrays
  12.     if($eshopoptions['shipping']!='4'){
  13.         if($eshopoptions['shipping_zone']=='country'){
  14.             $reqdvalues[]='country';
  15.         }else{
  16.             $reqdvalues[]='state';
  17.         }
  18.     }else{
  19.         $creqd='';
  20.         $dtable=$wpdb->prefix.'eshop_rates';
  21.         $query=$wpdb->get_results("SELECT DISTINCT(area) from $dtable where rate_type='ship_weight'");
  22.         foreach($query as $k)
  23.             $reqdvalues[]=$k->area;
  24.     }
  25.     $linkattr=apply_filters('eShopCheckoutLinksAttr','');
  26.    
  27.     $reqdarray=apply_filters('eshopCheckoutReqd', $reqdvalues );
  28.  
  29.     $xtralinks=eshop_show_extra_links();
  30.  
  31.     $echo = '
  32.     <div class="hr"></div>
  33.     <div class="eshopcustdetails custdetails">
  34.     <p><small class="privacy"><span class="reqd" title="Asterisk">*</span> '.__('Denotes Required Field ','eshop').'
  35.     '.__($xtralinks,'eshop').'</small></p>
  36.     <form action="'.esc_url($_SERVER['REQUEST_URI']).'" method="post" class="eshop eshopform">';
  37.    
  38.     if($eshopoptions['shipping']=='4' && 'no' == $eshopoptions['downloads_only'] && !eshop_only_downloads()){
  39.         //only for ship by weight
  40.         $echo.='<fieldset class="eshop fld0"><legend id="shiplegend">'. __('Please Choose Shipping','eshop').eshop_checkreqd($reqdarray,'shipping').'</legend>';
  41.         $typearr=explode("\n", $eshopoptions['ship_types']);
  42.         $cartweight=$_SESSION['eshop_totalweight'.$blog_id]['totalweight'];
  43.         $eshopshiptable='';
  44.         $eshopletter = "A";
  45.         $dtable=$wpdb->prefix.'eshop_rates';
  46.         $weightsymbol=$eshopoptions['weight_unit'];
  47.         $currsymbol=$eshopoptions['currency_symbol'];
  48.         $stype='';
  49.         if(isset($_POST['eshop_shiptype'])) $stype=$_POST['eshop_shiptype'];
  50.         $first=apply_filters('eshop_default_shipping','1');
  51.         /* '1- text 2 - weight 3-weight symbol' */
  52.         $echo .='<p>'.sprintf( __('%1$s %2$s %3$s','eshop'),__('Total weight: ','eshop'), number_format_i18n($cartweight,__('2','eshop')),$weightsymbol).'</p>';
  53.         foreach ($typearr as $k=>$type){
  54.             $k++;
  55.             $query=$wpdb->get_results("SELECT * from $dtable  where weight<='$cartweight' &&  class='$k' && rate_type='ship_weight' order by weight DESC limit 1");
  56.             if(count($query)==0)
  57.                 continue;
  58.             if($query['0']->maxweight!='' && $cartweight > $query['0']->maxweight)
  59.                 continue;
  60.             $eshopshiptableinner ='
  61.             <table class="eshopshiprates eshop" summary="'.__('Shipping rates per mode','eshop').'">
  62.             <thead>
  63.             <tr>';
  64.             for($z=1;$z<=$eshopoptions['numb_shipzones'];$z++){
  65.                 $y='zone'.$z;
  66.                 $echozone=sprintf(__('Zone %1$d','eshop'),$z);
  67.                 $dispzone=apply_filters('eshop_rename_ship_zone',array());
  68.                 if(isset($dispzone[$z]))
  69.                     $echozone=$dispzone[$z];
  70.                 $eshopshiptableinner.='<th id="'.$eshopletter.$y.'" class="'.$y.'">'. $echozone .'</th>';
  71.             }
  72.             $eshopshiptableinner.='</tr>
  73.             </thead>
  74.             <tbody>';
  75.            
  76.             $x=1;
  77.             foreach ($query as $row){
  78.                 $alt = ($x % 2) ? '' : ' class="alt"';
  79.                 $eshopshiptableinner.='
  80.                 <tr'.$alt.'>';
  81.                 for($z=1;$z<=$eshopoptions['numb_shipzones'];$z++){
  82.                     $y='zone'.$z;
  83.                     $eshopshiptableinner.='<td headers="'.$eshopletter.$y.'" class="'.$y.'">'.sprintf( __('%1$s%2$s','eshop'), $currsymbol, $row->$y).'</td>';
  84.                 }
  85.                 $eshopshiptableinner.='</tr>';
  86.                 $x++;
  87.             }
  88.             $eshopletter++;
  89.             $eshopshiptableinner.='</tbody></table>'."\n";
  90.            
  91.             if($row->area=='country')
  92.                 $eshopshiptableheadtext = sprintf( __('%1$s <small>%2$s</small>','eshop'),stripslashes(esc_attr($type)), __('(Shipping Zones by Country)','eshop'));
  93.             else
  94.                 $eshopshiptableheadtext = sprintf( __('%1$s <small>%2$s</small>','eshop'),stripslashes(esc_attr($type)), __('(Shipping Zones by State/County/Province)','eshop'));
  95.            
  96.             if(isset($row->maxweight) && $row->maxweight!='')
  97.                 $eshopshiptableheadtext .= ' '.sprintf( __('Max. Weight %1$s %2$s','eshop'),$row->maxweight,$eshopoptions['weight_unit']);
  98.             if($first=='1' && $stype==''){
  99.                 $stype=$k;
  100.                 $first=0;
  101.             }
  102.             $eshopshiptablehead='<span><input class="rad" type="radio" name="eshop_shiptype" value="'.$k.'" id="eshop_shiptype'.$k.'"'.checked($stype,$k,false).' /> <label for="eshop_shiptype'.$k.'">'.$eshopshiptableheadtext.'</label></span>';
  103.            
  104.             $eshopshiptable .= $eshopshiptablehead.$eshopshiptableinner;
  105.  
  106.         }
  107.         if($eshopshiptable != '')
  108.             $echo .= $eshopshiptable;
  109.         else
  110.             $echo .= '<input type="hidden" name="eshop_shiptype" value="0" id="eshop_shiptype0" />';
  111.         $echo .='</fieldset>';
  112.     }
  113.    
  114.    
  115.     $echo.='<fieldset class="eshop fld1"><legend id="mainlegend">'. __('Please Enter Your Details','eshop').'</legend>
  116.     <fieldset class="eshop fld2">';
  117.     if('no' == $eshopoptions['downloads_only']){
  118.         $echo .='<legend>'.__('Mailing Address','eshop').'</legend>';
  119.     }else{
  120.         $echo .='<legend>'.__('Contact Details','eshop').'</legend>';
  121.     }
  122.     $echo .='<span class="firstname"><label for="first_name">'.__('First Name','eshop').eshop_checkreqd($reqdarray,'first_name').'</label>
  123.       <input class="med" type="text" name="first_name" value="'.$first_name.'" id="first_name" maxlength="40" size="40" /><br /></span>
  124.      <span class="lastname"><label for="last_name">'.__('Last Name','eshop').eshop_checkreqd($reqdarray,'last_name').'</label>
  125.       <input class="med" type="text" name="last_name" value="'.$last_name.'" id="last_name" maxlength="40" size="40" /><br /></span>';
  126.     if('no' == $eshopoptions['downloads_only']){
  127.     $echo .='<span class="company"><label for="company">'.__('Company','eshop').eshop_checkreqd($reqdarray,'company').'</label>
  128.       <input class="med" type="text" name="company" value="'.$company.'" id="company" size="40" /><br /></span>';
  129.     }
  130.     $echo .='<span class="email"><label for="email">'.__('Email','eshop').eshop_checkreqd($reqdarray,'email').'</label>
  131.       <input class="med" type="text" name="email" value="'.$email.'" id="email" maxlength="100" size="40" /><br /></span>';
  132.     if('no' == $eshopoptions['downloads_only']){
  133.         $echo .='<span class="phone"><label for="phone">'.__('Phone','eshop').eshop_checkreqd($reqdarray,'phone').'</label>
  134.           <input class="med" type="text" name="phone" value="'.$phone.'" id="phone" maxlength="30" size="30" /><br /></span>
  135.          <span class="address1"><label for="address1">'.__('Address','eshop').eshop_checkreqd($reqdarray,'address').'</label>
  136.           <input class="med" type="text" name="address1" id="address1" value="'.$address1.'" maxlength="40" size="40" /><br /></span>
  137.          <span class="address2"><label for="address2">'.__('Address (continued)','eshop').'</label>
  138.           <input class="med" type="text" name="address2" id="address2" value="'.$address2.'" maxlength="40" size="40" /><br /></span>
  139.          <span class="city"><label for="city">'.__('City or town','eshop').eshop_checkreqd($reqdarray,'city').'</label>
  140.           <input class="med" type="text" name="city" value="'.$city.'" id="city" maxlength="40" size="40" /><br /></span>'."\n";
  141.  
  142.         // state list from db
  143.         $table=$wpdb->prefix.'eshop_states';
  144.         $getstate=$eshopoptions['shipping_state'];
  145.         if($eshopoptions['show_allstates'] != '1'){
  146.             $stateList=$wpdb->get_results("SELECT id,code,stateName FROM $table WHERE list='$getstate' ORDER BY stateName",ARRAY_A);
  147.         }else{
  148.             $stateList=$wpdb->get_results("SELECT id,code,stateName,list FROM $table ORDER BY list,stateName",ARRAY_A);
  149.         }
  150.        
  151.         if(sizeof($stateList)>0){
  152.             $echo .='<span class="state"><label for="state">'.__('State/County/Province','eshop').eshop_checkreqd($reqdarray,'state').'</label>
  153.               <select class="med pointer" name="state" id="state">';
  154.             $echo .='<option value="">'.__('Please Select','eshop').'</option>';
  155.             $echo .= apply_filters('eshop_states_na','<option value="">'.__('not applicable','eshop').'</option>');
  156.             foreach($stateList as $code => $value){
  157.                 if(isset($value['list'])) $li=$value['list'];
  158.                 else $li='1';
  159.                 $eshopstatelist[$li][$value['id']]=array($value['code'],$value['stateName']);
  160.             }
  161.             $tablec=$wpdb->prefix.'eshop_countries';
  162.             foreach($eshopstatelist as $egroup =>$value){
  163.                 $eshopcname=$wpdb->get_var("SELECT country FROM $tablec where code='$egroup' limit 1");
  164.                 $echo .='<optgroup label="'.$eshopcname.'">'."\n";
  165.  
  166.                 foreach($value as $code =>$stateName){
  167.                     //$stateName=esc_attr($stateName);
  168.                     if (isset($state) && ($state == $stateName['0'] || $state == $code)){
  169.                         $echo.= '<option value="'.$code.'" selected="selected">'.$stateName['1']."</option>\n";
  170.                     }else{
  171.                         $echo.='<option value="'.$code.'">'.$stateName['1']."</option>\n";
  172.                     }
  173.                 }
  174.                 $echo .="</optgroup>\n";
  175.             }
  176.             $echo.= "</select><br /></span>\n";
  177.         }else{
  178.             $echo .='<input type="hidden" name="state" value="" />';
  179.         }
  180.         $echo .= '<span class="altstate"><label for="altstate">'.__('State/County/Province <small>if not listed above</small>','eshop').'</label>
  181.                   <input class="short" type="text" name="altstate" value="'.$altstate.'" id="altstate" size="20" /><br /></span>';
  182.         $echo .= '
  183.          <span class="zip"><label for="zip">'.__('Zip/Post code','eshop').eshop_checkreqd($reqdarray,'zip').'</label>
  184.           <input class="short" type="text" name="zip" value="'.$zip.'" id="zip" maxlength="20" size="20" /><br /></span>
  185.          <span class="country"><label for="country">'.__('Country','eshop').eshop_checkreqd($reqdarray,'country').'</label>
  186.           <select class="med pointer" name="country" id="country">
  187.         ';
  188.         // country list from db
  189.         $tablec=$wpdb->prefix.'eshop_countries';
  190.         $List=$wpdb->get_results("SELECT code,country FROM $tablec GROUP BY list,country",ARRAY_A);
  191.         foreach($List as $key=>$value){
  192.             $k=$value['code'];
  193.             $v=$value['country'];
  194.             $countryList[$k]=$v;
  195.         }
  196.         if(!isset($countryList)){
  197.             wp_die(__('Error, please contact site owner.','eshop'));
  198.         }
  199.         $echo .='<option value="" selected="selected">'.__('Select your Country','eshop').'</option>';
  200.         foreach($countryList as $code => $label){
  201.             $label=htmlspecialchars($label);
  202.             if (isset($country) && $country == $code){
  203.                 $echo.= "<option value=\"$code\" selected=\"selected\">$label</option>\n";
  204.             }else{
  205.                 $echo.="<option value=\"$code\">$label</option>";
  206.             }
  207.         }
  208.         $echo.= "</select></span>";
  209.     }
  210.     $echo .=""; // smazal jsem </fieldset>
  211.    
  212.     $echo = apply_filters('eshopaddtocheckout',$echo);
  213.  
  214.     if('yes' != $eshopoptions['hide_addinfo']){
  215.         $echo .= '
  216.         <legend>'.__('Additional information','eshop').'</legend>
  217.          <span class="eshopreference"><label for="reference">'.__('Reference or <abbr title="Purchase Order number">PO</abbr>','eshop').eshop_checkreqd($reqdarray,'ref').'</label>
  218.           <input type="text" class="med" name="reference" value="'.$reference.'" id="reference" size="30" /><br /></span>
  219.          <label for="eshop-comments">'.__('Poznámka','eshop').eshop_checkreqd($reqdarray,'comments').'</label>
  220.           <textarea class="textbox" name="comments" id="eshop-comments" cols="60" rows="5">'.$comments.'</textarea>';
  221.          $echo = apply_filters('eshopaddtoadditionalinformation',$echo);
  222.          $echo .= "</fieldset>\n";
  223.     }
  224.     if('no' == $eshopoptions['downloads_only']){
  225.         if('yes' != $eshopoptions['hide_shipping']){
  226.             $echo .='<fieldset class="eshop fld4">
  227.             <legend>'.__('Shipping address (if different)','eshop').'</legend>
  228.              <span class="ship_name"><label for="ship_name">'.__('Name','eshop').'</label>
  229.               <input class="med" type="text" name="ship_name" id="ship_name" value="'.stripslashes(esc_attr($ship_name)).'" maxlength="40" size="40" /><br /></span>
  230.              <span class="ship_company"><label for="ship_company">'.__('Company','eshop').'</label>
  231.               <input class="med" type="text" name="ship_company" value="'.stripslashes(esc_attr($ship_company)).'" id="ship_company" size="40" /><br /></span>
  232.              <span class="ship_phone"><label for="ship_phone">'.__('Phone','eshop').'</label>
  233.               <input class="med" type="text" name="ship_phone" value="'.$ship_phone.'" id="ship_phone" maxlength="30" size="30" /><br /></span>
  234.              <span class="ship_address"><label for="ship_address">'.__('Address','eshop').'</label>
  235.               <input class="med" type="text" name="ship_address" id="ship_address" value="'.stripslashes(esc_attr($ship_address)).'" maxlength="40" size="40" /><br /></span>
  236.              <span class="ship_city"><label for="ship_city">'.__('City or town','eshop').'</label>
  237.               <input class="med" type="text" name="ship_city" id="ship_city" value="'.stripslashes(esc_attr($ship_city)).'" maxlength="40" size="40" /><br /></span>'."\n";
  238.             if(isset($stateList) && sizeof($stateList)>0){
  239.                 $echo .='<span class="ship_state"><label for="shipstate">'.__('State/County/Province','eshop').'</label>
  240.                   <select class="med pointer" name="ship_state" id="shipstate">';
  241.                 //state list from db, as above
  242.                 $echo .='<option value="" selected="selected">'.__('Please Select','eshop').'</option>';
  243.                 $echo .=apply_filters('eshop_states_na','<option value="">'.__('not applicable','eshop').'</option>');
  244.                 foreach($eshopstatelist as $egroup =>$value){
  245.                     $eshopcname=$wpdb->get_var("SELECT country FROM $tablec where code='$egroup' limit 1");
  246.  
  247.                     $echo .='<optgroup label="'.$eshopcname.'">'."\n";
  248.                     foreach($value as $code =>$stateName){
  249.                         //$stateName=htmlspecialchars($stateName);
  250.                         if (isset($ship_state) && ($ship_state == $code ||$ship_state == $stateName['0']) ){
  251.                             $echo.= '<option value="'.$code.'" selected="selected">'.$stateName['1']."</option>\n";
  252.                         }else{
  253.                             $echo.='<option value="'.$code.'">'.$stateName['1']."</option>\n";
  254.                         }
  255.                     }
  256.                     $echo .="</optgroup>\n";
  257.                 }
  258.                 $echo .= '</select><br /></span>';
  259.             }else{
  260.                 $echo .='<input type="hidden" name="ship_state" value="" />';
  261.             }
  262.             $echo .= '<span class="ship_altstate"><label for="ship_altstate">'.__('State/County/Province <small>if not listed above</small>','eshop').'</label>
  263.                      <input class="short" type="text" name="ship_altstate" value="'.stripslashes(esc_attr($ship_altstate)).'" id="ship_altstate" size="20" /><br /></span>';
  264.  
  265.             $echo .='<span class="shippostcode"><label for="ship_postcode">'.__('Zip/Post Code','eshop').'</label>
  266.               <input class="short" type="text" name="ship_postcode" id="ship_postcode" value="'.$ship_postcode.'" maxlength="20" size="20" />
  267.               <br /></span>
  268.             <span class="shipcountry"><label for="shipcountry">'.__('Country','eshop').'</label>
  269.               <select class="med pointer" name="ship_country" id="shipcountry">
  270.             ';
  271.             $echo .='<option value="" selected="selected">'.__('Select your Country','eshop').'</option>';
  272.             foreach($countryList as $code => $label){
  273.                 $label=htmlspecialchars($label);
  274.                 if (isset($ship_country) && $ship_country == $code){
  275.                     $echo.= "<option value=\"$code\" selected=\"selected\">$label</option>\n";
  276.                 }else{
  277.                     $echo.="<option value=\"$code\">$label</option>";
  278.                 }
  279.             }
  280.             $echo.= "</select></span>";
  281.             $echo .='</fieldset>';
  282.         }
  283.     }
  284.     $final_price=number_format($_SESSION['final_price'.$blog_id], 2,'.','');
  285.     $discounttotal=0;
  286.     if(eshop_discount_codes_check()){
  287.         $eshop_discount='';
  288.         if(isset($_POST['eshop_discount'])) $eshop_discount=esc_attr($_POST['eshop_discount']);
  289.         $echo .='<fieldset class="eshop fld5"><legend><label for="eshop_discount">'.__('Discount Code','eshop').'</label></legend>
  290.         <input class="med" type="text" name="eshop_discount" value="'.$eshop_discount.'" id="eshop_discount" size="40" /></fieldset>'."\n";
  291.     }
  292.     if(is_array($eshopoptions['method'])){
  293.         $i=1;
  294.         $eshopfiles=eshop_files_directory();
  295.         $echo .='<fieldset class="eshop fld6 eshoppayvia"><legend>'.__('Pay Via', 'eshop').eshop_checkreqd($reqdarray,'pay').'</legend>'."\n";
  296.         $echo = apply_filters('eshopaddtocheckoutpayvia',$echo);
  297.         $echo .= "<ul class=\"vyber-ul\">\n";
  298.         $eshop_paymentx='';
  299.         if(isset($_POST['eshop_payment'])) $eshop_paymentx = $_POST['eshop_payment'];
  300.         if(sizeof((array)$eshopoptions['method'])!=1){
  301.             foreach($eshopoptions['method'] as $k=>$eshoppayment){
  302.                 $replace = array(".");
  303.                 $eshoppayment = str_replace($replace, "", $eshoppayment);
  304.                 $eshoppayment_text=$eshoppayment;
  305.                 if($eshoppayment_text=='cash'){
  306.                     $eshopcash = $eshopoptions['cash'];
  307.                     if($eshopcash['rename']!='')
  308.                         $eshoppayment_text=$eshopcash['rename'];
  309.                 }
  310.                 if($eshoppayment_text=='bank'){
  311.                     $eshopbank = $eshopoptions['bank'];
  312.                     if($eshopbank['rename']!='')
  313.                         $eshoppayment_text=$eshopbank['rename'];
  314.                 }
  315.                 $eshopmi=apply_filters('eshop_merchant_img_'.$eshoppayment,array('path'=>$eshopfiles['0'].$eshoppayment.'.png','url'=>$eshopfiles['1'].$eshoppayment.'.png'));
  316.                 $eshopmerchantimgpath=$eshopmi['path'];
  317.                 $eshopmerchantimgurl=$eshopmi['url'];
  318.                 $dims=array('3'=>'');
  319.                 if(file_exists($eshopmerchantimgpath))
  320.                     $dims=getimagesize($eshopmerchantimgpath);
  321.                 $echo .='<li><input class="rad" type="radio" name="eshop_payment" onclick="changeSel(15'.$i.');" value="'.$eshoppayment.'" id="eshop_payment'.$i.'"'.checked($eshop_paymentx,$eshoppayment,false).' /><label for="eshop_payment'.$i.'"><span>'.$eshoppayment_text.'</span></label></li>'."\n";
  322.                 $i++;
  323.             }
  324.         }else{
  325.             foreach($eshopoptions['method'] as $k=>$eshoppayment){
  326.                 $replace = array(".");
  327.                 $eshoppayment = str_replace($replace, "", $eshoppayment);
  328.                 $eshoppayment_text=$eshoppayment;
  329.                 if($eshoppayment_text=='cash'){
  330.                     $eshopcash = $eshopoptions['cash'];
  331.                     if($eshopcash['rename']!='')
  332.                         $eshoppayment_text=$eshopcash['rename'];
  333.                 }
  334.                 if($eshoppayment_text=='bank'){
  335.                     $eshopbank = $eshopoptions['bank'];
  336.                     if($eshopbank['rename']!='')
  337.                         $eshoppayment_text=$eshopbank['rename'];
  338.                 }
  339.                 $eshopmi=apply_filters('eshop_merchant_img_'.$eshoppayment,array('path'=>$eshopfiles['0'].$eshoppayment.'.png','url'=>$eshopfiles['1'].$eshoppayment.'.png'));
  340.                 $eshopmerchantimgpath=$eshopmi['path'];
  341.                 $eshopmerchantimgurl=$eshopmi['url'];
  342.                 $dims='';
  343.                 if(file_exists($eshopmerchantimgpath))
  344.                     $dims=getimagesize($eshopmerchantimgpath);
  345.                 $echo .='<li><img src="'.$eshopmerchantimgurl.'" '.$dims[3].' alt="'.__('Pay via','eshop').' '.$eshoppayment_text.'" title="'.__('Pay via','eshop').' '.$eshoppayment_text.'" /><input type="hidden" name="eshop_payment" value="'.$eshoppayment.'" id="eshop_payment'.$i.'" /><span>'.__('Pay via','eshop').' '.$eshoppayment_text.'</span></li>'."\n";
  346.                 $i++;
  347.             }
  348.         }
  349.         $echo .="</ul><div class=\"clear\"></div><br /><div class=\"pplsk\">Cena za doručení službou PPL platí pro území ČR, <strong>při doručení na Slovensko bude za dopravu účtována částka 260,-Kč</strong></div>\n";
  350.         $echo .= eshopCartFields();
  351.         $echo .="</fieldset>\n";
  352.     }
  353.     if('yes' == $eshopoptions['tandc_use']){
  354.         if($eshopoptions['tandc_id']!='')
  355.             $eshoptc='<a href="'.get_permalink($eshopoptions['tandc_id']).'"'.$linkattr.'>'.$eshopoptions['tandc'].'</a>';
  356.         else
  357.             $eshoptc=$eshopoptions['tandc'];
  358.  
  359.         $echo .='<p class="eshop_tandc"><input type="checkbox" name="eshop_tandc" id="eshop_tandc" value="1" /><label for="eshop_tandc">'.$eshoptc.'<span class="reqd">*</span></label></p>';
  360.     }
  361.     if(isset($eshopoptions['users']) && $eshopoptions['users']=='yes' && !is_user_logged_in()){
  362.             if(isset($eshopoptions['users_text']) && $eshopoptions['users_text']!='')
  363.                 $edisplay=$eshopoptions['users_text'];
  364.             else
  365.                 $edisplay=__('Sign me up to the site so I can view my orders.','eshop');
  366.             $echo .='<p class="eshop_users"><input type="checkbox" name="eshop_users" id="eshop_users" value="1" /><label for="eshop_users">'.$edisplay.eshop_checkreqd($reqdarray,'signup').'</label></p>';
  367.     }
  368.     if('no' == $eshopoptions['downloads_only']){
  369.             $echo .='<div class="podminky"><input type="checkbox" name="podminky" id="podminky" /><label for="podminky">Pro úspěšné dokončení objednávky musíte souhlasit s <a target="_blank" href="http://www.mydomain.com/podminky/">obchodními podmínkami</a>.</label><br /><a target="_blank" href="http://www.mydomain.com/reklamacni-rad/">Reklamační řád</a><div class="clear"></div><br /><br />';
  370.     }
  371.        
  372.     $echo .= '<input type="hidden" name="amount" value="'.$final_price.'" />';
  373.  
  374.     $echo .='<span class="buttonwrap"><input type="submit" class="button" id="submitit" name="submit" value=" " /></span>
  375.     </fieldset>
  376.     </form>
  377.     </div>
  378.     ';
  379.     if(get_bloginfo('version')<'2.5.1')
  380.         remove_filter('the_content', 'wpautop');
  381.        
  382.     return $echo;
  383.     }
  384. }
  385. if (!function_exists('eshop_checkout')) {
  386.     function eshop_checkout($_POST){
  387.         $_POST=stripslashes_deep($_POST);
  388.         global $blog_id,$eshopoptions,$wpdb;
  389.         $contineproceed='1';
  390.         //cache
  391.         eshop_cache();
  392.         $echoit='';
  393.         include_once(ABSPATH.'wp-includes/wp-db.php');
  394.         include_once WP_PLUGIN_DIR."/eshop/cart-functions.php";
  395.         if(isset($_POST['eshop_payment']))
  396.             $_SESSION['eshop_payment'.$blog_id]=preg_replace('/[^a-zA-Z0-9\-_]/','',$_POST['eshop_payment']);
  397.            
  398.         if(!isset($_SESSION['eshop_payment'.$blog_id])){
  399.             $paymentmethod='paypal';
  400.         }else{
  401.             $paymentmethod=$_SESSION['eshop_payment'.$blog_id];
  402.         }
  403.         //left over from previous script, leaving in just in case another payment method is used.
  404.         $chkerror=0;
  405.         $numberofproducts=0;
  406.         //filter for plugin merchant gateways
  407.         $eshopmgincpath=apply_filters('eshop_mg_inc_path',WP_PLUGIN_DIR.'/eshop/'.$paymentmethod.'.php',$paymentmethod);
  408.         // if everything went ok do the following, hopefully the rest won't happen!
  409.         if(isset($_GET['eshopaction'])){
  410.             if($_GET['eshopaction']=='success'){
  411.                 include_once($eshopmgincpath);
  412.             }
  413.         }
  414.         //filter for plugin merchant gateways
  415.         $eshopmgincidxpath=apply_filters('eshop_mg_inc_idx_path',WP_PLUGIN_DIR.'/eshop/'.$paymentmethod.'/index.php',$paymentmethod);
  416.         if(file_exists($eshopmgincidxpath))
  417.             include_once($eshopmgincidxpath);
  418.  
  419.         if(isset($_SESSION['eshopcart'.$blog_id])){
  420.             $shopcart=$_SESSION['eshopcart'.$blog_id];
  421.             $numberofproducts=sizeof($_SESSION['eshopcart'.$blog_id]);
  422.             $productsandqty='';
  423.             while (list ($product, $amount) = each ($_SESSION['eshopcart'.$blog_id])){
  424.                 $productsandqty.=" $product-$amount";
  425.                 $productsandqty=trim($productsandqty);
  426.             }
  427.             $keys = array_keys($_SESSION['eshopcart'.$blog_id]);
  428.             $productidkeys=implode(",", $keys);
  429.             $productidkeys=trim($productidkeys);
  430.             //reqd for shipping - finds the correct state for working out shipping, and set things up for later usage.
  431.             if(isset($_POST['ship_name'])){
  432.                 if($_POST['ship_name']!='' || $_POST['ship_address']!=''
  433.                 || $_POST['ship_city']!='' || $_POST['ship_postcode']!=''
  434.                 || $_POST['ship_company']!='' || $_POST['ship_phone']!=''
  435.                 || $_POST['ship_country']!='' || $_POST['ship_state']!=''){
  436.                 if($_POST['ship_name']==''){
  437.                     $_POST['ship_name']=$_POST['first_name']." ".$_POST['last_name'];
  438.                 }
  439.                 if($_POST['ship_company']==''){
  440.                     $_POST['ship_company']=$_POST['company'];
  441.                 }
  442.                 if($_POST['ship_phone']==''){
  443.                     $_POST['ship_phone']=$_POST['phone'];
  444.                 }
  445.                 if($_POST['ship_address']==''){
  446.                     $_POST['ship_address']=$_POST['address1'];
  447.                     if($_POST['address2']!=''){
  448.                         $_POST['ship_address'].=", ".$_POST['address2'];
  449.                     }
  450.                 }
  451.                 if($_POST['ship_city']==''){
  452.                     $_POST['ship_city']=$_POST['city'];
  453.                 }
  454.                 if($_POST['ship_postcode']==''){
  455.                     $_POST['ship_postcode']=$_POST['zip'];
  456.                 }
  457.                 if($_POST['ship_country']==''){
  458.                     $_POST['ship_country']=$_POST['country'];
  459.                 }
  460.                 if($_POST['ship_state']==''){
  461.                     $_POST['ship_state']=$_POST['state'];
  462.                 }
  463.                 if($_POST['ship_altstate']==''){
  464.                     $_POST['ship_altstate']=$_POST['altstate'];
  465.                 }
  466.             }else{
  467.                 $_POST['ship_name']=$_POST['first_name']." ".$_POST['last_name'];
  468.                 $_POST['ship_company']=$_POST['company'];
  469.                 $_POST['ship_phone']=$_POST['phone'];
  470.                 if($_POST['ship_address']==''){
  471.                     $_POST['ship_address']=$_POST['address1'];
  472.                     if($_POST['address2']!=''){
  473.                         $_POST['ship_address'].=", ".$_POST['address2'];
  474.                     }
  475.                 }
  476.                 $_POST['ship_city']=$_POST['city'];
  477.                 $_POST['ship_postcode']=$_POST['zip'];
  478.                 $_POST['ship_country']=$_POST['country'];
  479.                 $_POST['ship_state']=$_POST['state'];
  480.                 $_POST['ship_altstate']=$_POST['altstate'];
  481.             }
  482.             $tablecountries=$wpdb->prefix.'eshop_countries';
  483.             $tablestates=$wpdb->prefix.'eshop_states';
  484.             $shippingzone=$eshopoptions['shipping_zone'];
  485.             if(isset($_POST['eshop_shiptype']) && $_POST['eshop_shiptype'] != '0'){
  486.                 $sztype=$_POST['eshop_shiptype'];
  487.                 $shippingzone=$wpdb->get_var("SELECT area FROM ".$wpdb->prefix."eshop_rates WHERE rate_type='ship_weight' && class='$sztype' LIMIT 1");
  488.             }
  489.             $pzoneid='';//$eshopoptions['unknown_state'];
  490.             if($shippingzone=='country'){
  491.                 if(isset($_POST['ship_country']) && $_POST['ship_country']!=''){
  492.                     $pzoneid=$_POST['ship_country'];
  493.                 }elseif(isset($_POST['country']) && $_POST['country']!=''){
  494.                     $pzoneid=$_POST['country'];
  495.                 }
  496.                 $pzone=$wpdb->get_var("SELECT zone FROM $tablecountries WHERE code='$pzoneid' LIMIT 1");
  497.  
  498.             }else{
  499.                 if(isset($_POST['state']) && $_POST['state']!=''){
  500.                     $pzoneid=$_POST['state'];
  501.                 }
  502.                 if(isset($_POST['ship_state']) && $_POST['ship_state']!=''){
  503.                     $pzoneid=$_POST['ship_state'];
  504.                 }
  505.                 $pzone=$wpdb->get_var("SELECT zone FROM $tablestates WHERE id='$pzoneid' LIMIT 1");
  506.                 if(isset($_POST['altstate']) && $_POST['altstate']!=''){
  507.                     $pzone=$eshopoptions['unknown_state'];
  508.                 }
  509.                 if(isset($_POST['ship_altstate']) && $_POST['ship_altstate']!=''){
  510.                     $pzone=$eshopoptions['unknown_state'];
  511.                 }
  512.             }
  513.            
  514.             $_SESSION['shiptocountry'.$blog_id] = $eshopoptions['location'];
  515.             if(isset($_POST['ship_country']) && $_POST['ship_country']!=''){
  516.                 $_SESSION['shiptocountry'.$blog_id] = $_POST['ship_country'];
  517.             }elseif(isset($_POST['country']) && $_POST['country']!=''){
  518.                 $_SESSION['shiptocountry'.$blog_id] = $_POST['country'];
  519.             }
  520.         }else{
  521.             $pzoneid='';//$eshopoptions['unknown_state'];
  522.             $tablecountries=$wpdb->prefix.'eshop_countries';
  523.             $tablestates=$wpdb->prefix.'eshop_states';
  524.             $shippingzone=$eshopoptions['shipping_zone'];
  525.             if(isset($_POST['eshop_shiptype'])){
  526.                 $sztype=$_POST['eshop_shiptype'];
  527.                 $shippingzone=$wpdb->get_var("SELECT area FROM ".$wpdb->prefix."eshop_rates WHERE rate_type='ship_weight' && class='$sztype' LIMIT 1");
  528.             }
  529.             if($shippingzone=='country'){
  530.                 if(isset($_POST['ship_country']) && $_POST['ship_country']!=''){
  531.                     $pzoneid=$_POST['ship_country'];
  532.                 }elseif(isset($_POST['country']) && $_POST['country']!=''){
  533.                     $pzoneid=$_POST['country'];
  534.                 }
  535.                 $pzone=$wpdb->get_var("SELECT zone FROM $tablecountries WHERE code='$pzoneid' LIMIT 1");
  536.  
  537.             }else{
  538.                 if(isset($_POST['ship_state']) && $_POST['ship_state']!=''){
  539.                     $pzoneid=$_POST['ship_state'];
  540.                 }
  541.                 if(isset($_POST['state']) && $_POST['state']!=''){
  542.                     $pzoneid=$_POST['state'];
  543.                 }
  544.                 $pzone=$wpdb->get_var("SELECT zone FROM $tablestates WHERE id='$pzoneid' LIMIT 1");
  545.                 if(isset($_POST['altstate']) && $_POST['altstate']!=''){
  546.                     $pzone=$eshopoptions['unknown_state'];
  547.                 }
  548.                 if(isset($_POST['ship_altstate']) && $_POST['ship_altstate']!=''){
  549.                     $pzone=$eshopoptions['unknown_state'];
  550.                 }
  551.             }
  552.         }
  553.         //
  554.         $shiparray=array();
  555.         $eshopcartarray=$_SESSION['eshopcart'.$blog_id];
  556.         foreach ($eshopcartarray as $productid => $opt){
  557.             if(is_array($opt)){
  558.                 switch($eshopoptions['shipping']){
  559.                 case '1'://( per quantity of 1, prices reduced for additional items )
  560.                     for($i=1;$i<=$opt['qty'];$i++){
  561.                         array_push($shiparray, $opt["pclas"]);
  562.                     }
  563.                     break;
  564.                 case '2'://( once per shipping class no matter what quantity is ordered )
  565.                     if(!in_array($opt["pclas"], $shiparray)) {
  566.                         array_push($shiparray, $opt["pclas"]);
  567.                     }
  568.                     break;
  569.                 case '3'://( one overall charge no matter how many are ordered )
  570.                     if(!in_array($opt["pclas"], $shiparray)) {
  571.                         if($opt["pclas"]!='F'){
  572.                             array_push($shiparray, 'A');
  573.                         }
  574.                     }
  575.                     break;
  576.                
  577.                 case '4'://( weight )
  578.                     if(isset($_POST['eshop_shiptype'])){
  579.                         unset ($shiparray);
  580.                         $shiparray=$_POST['eshop_shiptype'];
  581.                     }
  582.                     break;
  583.                 }
  584.             }
  585.         }
  586.         //need an extra check
  587.         if($eshopoptions['shipping']=='4' && 'no' == $eshopoptions['downloads_only'] && isset($_POST['submit']) && !isset($_POST['eshop_shiptype']) && !eshop_only_downloads()){
  588.             $pzone='';
  589.         }
  590.         //need to check the discount codes here as well:
  591.         if(eshop_discount_codes_check()){
  592.             $_SESSION['eshop_discount'.$blog_id]='';
  593.             unset($_SESSION['eshop_discount'.$blog_id]);
  594.             if(isset($_POST['eshop_discount']) && $_POST['eshop_discount']!=''){
  595.                 $chkcode=valid_eshop_discount_code($_POST['eshop_discount']);
  596.                 if($chkcode)
  597.                     $_SESSION['eshop_discount'.$blog_id]=$_POST['eshop_discount'];
  598.             }
  599.         }
  600.         //show the cart
  601.         if((isset($_GET['eshopaction']) && $_GET['eshopaction']!='redirect')||!isset($_GET['eshopaction'])){
  602.             $echoit.= display_cart($_SESSION['eshopcart'.$blog_id], false,$eshopoptions['checkout'],$pzone,$shiparray);
  603.         }
  604.     }
  605.     $error='';
  606.  
  607.     if (isset ($_POST['submit'])) {
  608.         //form handling
  609.         foreach($_POST as $key=>$value) {
  610.             $key = $value;
  611.         }
  612.         //setupshipping arrays
  613.         $reqdvalues=array('shipping','first_name','last_name','email','phone','address','city','zip','pay');
  614.  
  615.         if($eshopoptions['shipping']!='4'){
  616.             if($eshopoptions['shipping_zone']=='country'){
  617.                 $reqdvalues[]='country';
  618.             }else{
  619.                 $reqdvalues[]='state';
  620.             }
  621.         }else{
  622.             $creqd='';
  623.             $dtable=$wpdb->prefix.'eshop_rates';
  624.             $query=$wpdb->get_results("SELECT DISTINCT(area) from $dtable where rate_type='ship_weight'");
  625.             foreach($query as $k)
  626.                 $reqdvalues[]=$k->area;
  627.         }
  628.         $linkattr=apply_filters('eShopCheckoutLinksAttr','');
  629.            
  630.         $reqdarray=apply_filters('eshopCheckoutReqd', $reqdvalues );
  631.  
  632.         if($eshopoptions['shipping']=='4' && 'no' == $eshopoptions['downloads_only'] && !isset($_POST['eshop_shiptype']) && !eshop_only_downloads()){
  633.             $error.= '<li>'.__('<strong>Shipping</strong> - not selected.','eshop').'</li>';
  634.         }
  635.         if(isset($_POST['first_name'])){
  636.             $valid=checkAlpha($_POST['first_name']);
  637.             if($valid==FALSE && eshop_checkreqd($reqdarray,'first_name')){
  638.                 $error.= '<li>'.__('<strong>First name</strong> - missing or incorrect.','eshop').'</li>';
  639.             }
  640.         }
  641.         if(isset($_POST['last_name'])){
  642.                 $valid=checkAlpha($_POST['last_name']);
  643.                 if($valid==FALSE && eshop_checkreqd($reqdarray,'last_name')) {
  644.                     $error.= '<li>'.__('<strong>Last name</strong> - missing or incorrect.','eshop').'</li>';
  645.                 }
  646.         }
  647.         if(isset($_POST['email'])){
  648.                 $valid=checkEmail($_POST['email']);
  649.                 if($valid==FALSE && eshop_checkreqd($reqdarray,'email')){
  650.                     $error.= '<li>'.__('<strong>Email address</strong> - missing or incorrect.','eshop').'</li>';
  651.                 }
  652.         }
  653.         if(isset($_POST['phone'])){
  654.                 $valid=checkPhone($_POST['phone']);
  655.                 if($valid==FALSE && eshop_checkreqd($reqdarray,'phone')){
  656.                     $error.= '<li>'.__('<strong>Phone Number</strong> - missing or incorrect','eshop').'.</li>';
  657.                 }
  658.         }
  659.         if(isset($_POST['address1'])){
  660.                 $valid=checkAlpha($_POST['address1']);
  661.                 if($valid==FALSE && eshop_checkreqd($reqdarray,'address')){
  662.                     $error.= '<li>'.__('<strong>Address</strong> - missing or incorrect.','eshop').'</li>';
  663.                 }
  664.         }
  665.         if(isset($_POST['city'])){
  666.                 $valid=checkAlpha($_POST['city']);
  667.                 if($valid==FALSE && eshop_checkreqd($reqdarray,'city')){
  668.                     $error.= '<li>'.__('<strong>City or town</strong> - missing or incorrect.','eshop').'</li>';
  669.                 }
  670.         }
  671.        
  672.         if(eshop_checkreqd($reqdarray,'state') and false){
  673.             if(isset($_POST['state']) && $_POST['state']=='' &&  $_POST['altstate']==''){
  674.                 $error.= '<li>'.__('<strong>State/County/Province</strong> - missing or incorrect.','eshop').'</li>';
  675.             }
  676.         }
  677.         if(eshop_checkreqd($reqdarray,'country')){
  678.             if(isset($_POST['country'])){
  679.                 $valid=checkAlpha($_POST['country']);
  680.                 if($valid==FALSE){
  681.                     $error.= '<li>'.__('<strong>Country</strong> - missing or incorrect.','eshop').'</li>';
  682.                 }
  683.             }
  684.         }
  685.         if(isset($_POST['country']) && $_POST['country']=='US' && $_POST['state']=='' && $_POST['altstate']==''){
  686.             //must pick a state for US deliveries
  687.                 $error.= '<li>'.__('<strong><abbr title="United States">US</abbr> State</strong> - missing or incorrect.','eshop').'</li>';
  688.         }
  689.         if(isset($_POST['zip'])){
  690.                 $valid=checkAlphaNum($_POST['zip']);
  691.                 if($valid==FALSE && eshop_checkreqd($reqdarray,'zip')){
  692.                     $error.= '<li>'.__('<strong>Zip/Post code</strong> - missing or incorrect.','eshop').'</li>';
  693.                 }
  694.         }
  695.         if(isset($_POST['reference'])){
  696.                 if($_POST['reference']=='' && eshop_checkreqd($reqdarray,'ref')){
  697.                     $error.= '<li>'.__('<strong>Reference</strong> - missing.','eshop').'</li>';
  698.                 }
  699.         }
  700.         if(isset($_POST['comments'])){
  701.                 if($_POST['comments']=='' && eshop_checkreqd($reqdarray,'comments')){
  702.                     $error.= '<li>'.__('<strong>Comments</strong> - missing.','eshop').'</li>';
  703.                 }
  704.         }
  705.         if(isset($eshopoptions['users']) && $eshopoptions['users']=='yes' && !is_user_logged_in()){
  706.             if(!isset($_POST['eshop_users']) && eshop_checkreqd($reqdarray,'signup')){
  707.                 $error.= '<li>'.__('<strong>Sign Up</strong> - not checked.','eshop').'</li>';
  708.             }
  709.         }
  710.  
  711.         //add in error checking for any new values here
  712.         $temperror=apply_filters('eshoperrorcheckout',$_POST);
  713.         if(!is_array($temperror)) $error .= $temperror;
  714.        
  715.         ////////////////////////////////////////////////
  716.         if('yes' == $eshopoptions['tandc_use']){
  717.             if(!isset($_POST['eshop_tandc'])){
  718.                 $error.= '<li><strong>'.$eshopoptions['tandc'].'</strong>'.__(' - not checked.','eshop').'</li>';
  719.             }
  720.         }
  721.            
  722.         if(!isset($_POST['eshop_payment'])){
  723.             $error.= '<li>'.__('You have not chosen a <strong>payment option</strong>.','eshop').'</li>';
  724.         }
  725.         if(eshop_discount_codes_check()){
  726.             $_SESSION['eshop_discount'.$blog_id]='';
  727.             unset($_SESSION['eshop_discount'.$blog_id]);
  728.             if(isset($_POST['eshop_discount']) && $_POST['eshop_discount']!=''){
  729.                 $chkcode=valid_eshop_discount_code($_POST['eshop_discount']);
  730.                 if(!$chkcode)
  731.                     $error.= '<li>'.__('<strong>Discount Code</strong> - is not valid.','eshop').'</li>';
  732.                 else
  733.                     $_SESSION['eshop_discount'.$blog_id]=$_POST['eshop_discount'];
  734.             }
  735.         }
  736.         if(isset($eshopoptions['users']) && $eshopoptions['users']=='yes' && isset($_POST['eshop_users']) && !is_user_logged_in()){
  737.             $_SESSION['eshop_user'.$blog_id]='1';
  738.         }
  739.  
  740.         if($error!=''){
  741.                 $echoit.= "<p><strong class=\"eshoperror error\">".__('There were some errors in the details you entered&#8230;','eshop')."</strong></p><ul class=\"eshoperrors errors\">".$error.'</ul>';
  742.                 $first_name=$last_name=$company=$phone=$reference='';
  743.                 $email=$address1=$address2=$city=$country='';
  744.                 $state=$altstate=$zip=$ship_name=$ship_company='';
  745.                 $ship_phone=$ship_address=$ship_city=$ship_postcode='';
  746.                 $ship_country=$ship_state=$ship_altstate=$comments='';
  747.                 if(isset($_POST['first_name']))
  748.                     $first_name=$_POST['first_name'];
  749.                 if(isset($_POST['last_name']))
  750.                     $last_name=$_POST['last_name'];
  751.                 if(isset($_POST['phone']))
  752.                     $phone=$_POST['phone'];
  753.                 if(isset($_POST['reference']))
  754.                     $reference=$_POST['reference'];
  755.                 if(isset($_POST['email']))
  756.                     $email=$_POST['email'];
  757.                 if(isset($_POST['address1']))
  758.                     $address1=$_POST['address1'];
  759.                 if(isset($_POST['address2']))
  760.                     $address2=$_POST['address2'];
  761.                 if(isset($_POST['city']))
  762.                     $city=$_POST['city'];
  763.                 if(isset($_POST['country']))
  764.                     $country=$_POST['country'];
  765.                 if(isset($_POST['state']))
  766.                     $state=$_POST['state'];
  767.                 if(isset($_POST['altstate']))
  768.                     $altstate=$_POST['altstate'];
  769.                 if(isset($_POST['zip']))
  770.                     $zip=$_POST['zip'];
  771.                 if(isset($_POST['ship_name ']))
  772.                     $ship_name=$_POST['ship_name'];
  773.                 if(isset($_POST['ship_company']))
  774.                     $ship_company=$_POST['ship_company'];
  775.                 if(isset($_POST['ship_phone']))
  776.                     $ship_phone=$_POST['ship_phone'];
  777.                 if(isset($_POST['ship_address']))
  778.                     $ship_address=$_POST['ship_address'];
  779.                 if(isset($_POST['ship_city']))
  780.                     $ship_city=$_POST['ship_city'];
  781.                 if(isset($_POST['ship_country']))
  782.                     $ship_country=$_POST['ship_country'];
  783.                 if(isset($_POST['ship_state']))
  784.                     $ship_state=$_POST['ship_state'];
  785.                 if(isset($_POST['ship_altstate']))
  786.                     $ship_altstate=$_POST['ship_altstate'];
  787.                 if(isset($_POST['ship_postcode']))
  788.                     $ship_postcode=$_POST['ship_postcode'];
  789.                 if(isset($_POST['comments']))
  790.                     $comments=$_POST['comments'];
  791.                 $chkerror='1';
  792.         }else{
  793.             if(!isset($_GET['eshopaction'])){
  794.                 $shipping=0;
  795.                 $echoit.= "<div class=\"hr\"></div><div class=\"eshopcheckoutconf\"><h3>".__('<span class="noprint">Please Confirm </span>Your Details','eshop').'</h3>';
  796.                 // create a custom id, and shove details in database
  797.                 $date=date('YmdHis');
  798.                 $_SESSION['date'.$blog_id]=$date;
  799.                 $fprice=number_format($_SESSION['final_price'.$blog_id], 2,'.','');
  800.                 $_POST['amount']=$fprice;
  801.                 $_POST['custom']=$date;
  802.                 $_POST['numberofproducts']=sizeof($_SESSION['eshopcart'.$blog_id]);
  803.  
  804.                 //shipping
  805.                 if(isset($_SESSION['shipping'.$blog_id]))$shipping=eshopShipTaxAmt();
  806.                 //discount shipping
  807.                 if(is_shipfree(calculate_total())) $shipping=0;
  808.                 //shipping
  809.                 $_POST['shipping_1']=$shipping;
  810.                 $ctable=$wpdb->prefix.'eshop_countries';
  811.                 $stable=$wpdb->prefix.'eshop_states';
  812.                 if('no' == $eshopoptions['downloads_only']){
  813.                     $echoit.='<h4>'.__('Mailing Address','eshop').'</h4><ul class="eshop confirm">';
  814.                 }else{
  815.                     $echoit.='<h4>'.__('Contact Details','eshop').'</h4><ul class="eshop confirm">';
  816.                 }
  817.                 $echoit.= "<li><span class=\"items fullname\">".__('Full name:','eshop')."</span> ".$_POST['first_name']." ".$_POST['last_name']."</li>\n";
  818.                 if('no' == $eshopoptions['downloads_only']){
  819.                     $echoit.= "<li class=\"company\"><span class=\"items\">".__('Company:','eshop')."</span> ".$_POST['company']."</li>\n";
  820.                 }
  821.                 $echoit.= "<li class=\"email\"><span class=\"items\">".__('Email:','eshop')."</span> ".$_POST['email']."</li>\n";
  822.                 if('no' == $eshopoptions['downloads_only']){
  823.                     $echoit.= "<li class=\"phone\"><span class=\"items\">".__('Phone:','eshop')."</span> ".$_POST['phone']."</li>\n";
  824.                     $echoit.= "<li class=\"address\"><span class=\"items\">".__('Address:','eshop')."</span> ".$_POST['address1']." ".$_POST['address2']."</li>\n";
  825.                     $echoit.= "<li class=\"city\"><span class=\"items\">".__('City or town:','eshop')."</span> ".$_POST['city']."</li>\n";
  826.                     $qcode=$wpdb->escape($_POST['state']);
  827.                     $qstate = $wpdb->get_var("SELECT stateName FROM $stable WHERE id='$qcode' limit 1");
  828.                     if($_POST['altstate']!='')
  829.                         $echoit.= "<li class=\"state\"><span class=\"items\">".__('State/County/Province:','eshop')."</span> ".$_POST['altstate']."</li>\n";
  830.                     elseif($qstate!='')
  831.                         $echoit.= "<li class=\"state\"><span class=\"items\">".__('State/County/Province:','eshop')."</span> ".$qstate."</li>\n";
  832.                                        
  833.                     $echoit.= "<li class=\"zip\"><span class=\"items\">".__('Zip/Post code:','eshop')."</span> ".$_POST['zip']."</li>\n";
  834.                     $qccode=$wpdb->escape($_POST['country']);
  835.                     $qcountry = $wpdb->get_var("SELECT country FROM $ctable WHERE code='$qccode' limit 1");
  836.                     $echoit.= "<li class=\"country\"><span class=\"items\">".__('Country:','eshop')."</span> ".$qcountry."</li>\n";
  837.                    
  838.                    
  839.                 }
  840.                 $echoit.= "</ul>\n";
  841.                 //
  842.                 $temp=apply_filters('eshopconfcheckout',$_POST);
  843.                 if(!is_array($temp)) $echoit .= $temp;
  844.                 //
  845.                 if(!isset($_POST['reference'])) $_POST['reference']='';
  846.                 if(!isset($_POST['comments'])) $_POST['comments']='';
  847.                 if( (trim($_POST['reference'])!='') && trim($_POST['comments'])==''){
  848.                     $echoit.= "<div class=\"eshop fld3\"><h4>".__('Additional information','eshop')."</h4>\n<ul class=\"eshop confirmref\">\n";
  849.                     $echoit.= '<li><span class="items">'.__('Reference or <abbr title="Purchase Order number">PO</abbr>','eshop').'</span> '.$_POST['reference'].'</li>'."\n";
  850.                     $echoit.= '</ul></div>'."\n";
  851.                 }
  852.                 if( (trim($_POST['reference'])=='') && trim($_POST['comments'])!=''){
  853.                     $echoit.= "<div class=\"eshop fld3\"><h4>".__('Additional information','eshop')."</h4>\n<ul class=\"eshop confirmref\">\n";
  854.                     $echoit.= '<li class=\"comments\"><span class="items">'.__('Comments or instructions:','eshop').'</span> '.$_POST['comments'].'</li>'."\n";
  855.                    
  856.                     $echoit.= "<li class=\"osobni\"><span class=\"items\">Osobní odběr</span> <br />Plzeň: Spolková 31, 312 00 Plzeň<br />Rokycany: Dukelská 1262, 337 01 Rokycany</li>\n";
  857.                     $echoit.= '</ul></div>'."\n";
  858.                 }
  859.                 if( (trim($_POST['reference'])!='') && trim($_POST['comments'])!=''){
  860.                     $echoit.= "<div class=\"eshop fld3\"><h4>".__('Additional information','eshop')."</h4>\n<ul class=\"eshop confirmref\">\n";
  861.                     $echoit.= '<li><span class="items">'.__('Reference or PO:','eshop').'</span> '.$_POST['reference'].'</li>'."\n";
  862.                     $echoit.= '<li><span class="items">'.__('Comments or instructions:','eshop').'</span> '.$_POST['comments'].'</li>'."\n";
  863.                     $echoit.= '</ul></div>'."\n";
  864.                 }
  865.                 if('no' == $eshopoptions['downloads_only']){
  866.                     if('yes' != $eshopoptions['hide_shipping']){
  867.                         if($_POST['ship_name']!='' || $_POST['ship_address']!='' || $_POST['ship_city']!='' || $_POST['ship_postcode']!=''){
  868.                             $echoit.= "<div class=\"eshop fld4\"><h4>".__('Shipping Address','eshop')."</h4>\n<ul class=\"eshop confirmship\">\n";
  869.                             $echoit.= "<li><span class=\"items\">".__('Full name:','eshop')."</span> ".$_POST['ship_name']."</li>\n";
  870.                             $echoit.= "<li class=\"ship_company\"><span class=\"items\">".__('Company:','eshop')."</span> ".$_POST['ship_company']."</li>\n";
  871.                             $echoit.= "<li><span class=\"items\">".__('Phone:','eshop')."</span> ".$_POST['ship_phone']."</li>\n";
  872.                             $echoit.= "<li><span class=\"items\">".__('Address:','eshop')."</span> ".$_POST['ship_address']."</li>\n";
  873.                             $echoit.= "<li><span class=\"items\">".__('City or town:','eshop')."</span> ".$_POST['ship_city']."</li>\n";
  874.                             $qcode=$wpdb->escape($_POST['ship_state']);
  875.                             $qstate = $wpdb->get_var("SELECT stateName FROM $stable WHERE id='$qcode' limit 1");
  876.                             if($_POST['ship_altstate']!='')
  877.                                 $echoit.= "<li class=\"ship_state\"><span class=\"items\">".__('State/County/Province:','eshop')."</span> ".$_POST['ship_altstate']."</li>\n";
  878.                             elseif($qstate!='')
  879.                                 $echoit.= "<li class=\"ship_state\"><span class=\"items\">".__('State/County/Province:','eshop')."</span> ".$qstate."</li>\n";
  880.  
  881.                             $echoit.= "<li><span class=\"items\">".__('Zip/Post code:','eshop')."</span> ".$_POST['ship_postcode']."</li>\n";
  882.                             $qccode=$wpdb->escape($_POST['ship_country']);
  883.                             $qcountry = $wpdb->get_var("SELECT country FROM $ctable WHERE code='$qccode' limit 1");
  884.                             $echoit.= "<li class=\"shipcountry\"><span class=\"items\">".__('Country:','eshop')."</span> ".$qcountry."</li>\n";
  885.                             $echoit.= "</ul></div>\n";
  886.                         }
  887.                     }
  888.                 }
  889.                 $echoit.= "\n";
  890.                 $echoit .= "</div>\n";
  891.             }
  892.            
  893.             //add to a session to store address:
  894.             $_SESSION['addy'.$blog_id]['first_name']=$_POST['first_name'];
  895.             $_SESSION['addy'.$blog_id]['last_name']=$_POST['last_name'];
  896.             $_SESSION['addy'.$blog_id]['email']=$_POST['email'];
  897.             if(isset($_POST['company']))
  898.                 $_SESSION['addy'.$blog_id]['company']=$_POST['company'];
  899.             else
  900.                 $_SESSION['addy'.$blog_id]['company']='';
  901.             if(isset($_POST['phone']))
  902.                 $_SESSION['addy'.$blog_id]['phone']=$_POST['phone'];
  903.             else
  904.                 $_SESSION['addy'.$blog_id]['phone']='';
  905.             if(isset($_POST['reference']))
  906.                 $_SESSION['addy'.$blog_id]['reference']=$_POST['reference'];
  907.             else
  908.                 $_SESSION['addy'.$blog_id]['reference']='';
  909.             if(isset($_POST['address1']))
  910.                 $_SESSION['addy'.$blog_id]['address1']=$_POST['address1'];
  911.             else
  912.                 $_SESSION['addy'.$blog_id]['address1']='';
  913.             if(isset($_POST['address2']))
  914.                 $_SESSION['addy'.$blog_id]['address2']=$_POST['address2'];
  915.             else
  916.                 $_SESSION['addy'.$blog_id]['address2']='';
  917.             if(isset($_POST['city']))
  918.                 $_SESSION['addy'.$blog_id]['city']=$_POST['city'];
  919.             if(isset($_POST['country']))
  920.                 $_SESSION['addy'.$blog_id]['country']=$_POST['country'];
  921.             else
  922.                 $_SESSION['addy'.$blog_id]['country']='';
  923.             if(isset($_POST['state']))
  924.                 $_SESSION['addy'.$blog_id]['state']=$_POST['state'];
  925.             else
  926.                 $_SESSION['addy'.$blog_id]['state']='';
  927.        
  928.             if(isset($_POST['altstate']) && $_POST['altstate']!='')
  929.                 $_SESSION['addy'.$blog_id]['state']=$_POST['altstate'];
  930.             if(isset($_POST['zip']))
  931.                 $_SESSION['addy'.$blog_id]['zip']=$_POST['zip'];
  932.             else
  933.                 $_SESSION['addy'.$blog_id]['zip']='';
  934.             if(isset($_POST['ship_name'])){
  935.                 $_SESSION['addy'.$blog_id]['ship_name']=$_POST['ship_name'];
  936.                 $_SESSION['addy'.$blog_id]['ship_company']=$_POST['ship_company'];
  937.                 $_SESSION['addy'.$blog_id]['ship_phone']=$_POST['ship_phone'];
  938.                 $_SESSION['addy'.$blog_id]['ship_address']=$_POST['ship_address'];
  939.                 $_SESSION['addy'.$blog_id]['ship_city']=$_POST['ship_city'];
  940.                 $_SESSION['addy'.$blog_id]['ship_country']=$_POST['ship_country'];
  941.                 $_SESSION['addy'.$blog_id]['ship_state']=$_POST['ship_state'];
  942.                 if(isset($_POST['ship_altstate']) && $_POST['ship_altstate']!='')
  943.                     $_SESSION['addy'.$blog_id]['ship_state']=$_POST['ship_altstate'];
  944.                 $_SESSION['addy'.$blog_id]['ship_postcode']=$_POST['ship_postcode'];
  945.             }
  946.             if(isset($_POST['comments']))
  947.                 $_SESSION['addy'.$blog_id]['comments']=$_POST['comments'];
  948.             else
  949.                 $_SESSION['addy'.$blog_id]['comments']='';
  950.            
  951.             if(!isset($_SESSION['shipping'.$blog_id]))$_SESSION['shipping'.$blog_id]['cost']=$shipping;
  952.  
  953.             //grab all the POST variables and store in cookie
  954.             $array=$_POST;
  955.             //but first make a few extra equal nothing
  956.             //add others in here if needed
  957.             $array['comments']=$array['reference']='';
  958.             $eshopsetcookie=apply_filters('eshop_use_cookie',true);
  959.             if($eshopsetcookie==true){
  960.                 $biscuits=eshop_build_cookie($array);
  961.                 setcookie("eshopcart", $biscuits,time()+60*60*24*365);
  962.             }
  963.             $eshopmgincpath=apply_filters('eshop_mg_inc_path',WP_PLUGIN_DIR.'/eshop/'.$paymentmethod.'.php',$paymentmethod);
  964.             include_once($eshopmgincpath);
  965.             $contineproceed='3';
  966.         }
  967.     }else{
  968.         //for first time form usage.
  969.         if(isset($_SESSION['addy'.$blog_id])){
  970.             $first_name=$_SESSION['addy'.$blog_id]['first_name'];
  971.             $last_name=$_SESSION['addy'.$blog_id]['last_name'];
  972.             $company=$_SESSION['addy'.$blog_id]['company'];
  973.             $phone=$_SESSION['addy'.$blog_id]['phone'];
  974.             $reference=$_SESSION['addy'.$blog_id]['reference'];
  975.             $email=$_SESSION['addy'.$blog_id]['email'];
  976.             $address1=$_SESSION['addy'.$blog_id]['address1'];
  977.             $address2=$_SESSION['addy'.$blog_id]['address2'];
  978.             $city='';
  979.             if(isset($_SESSION['addy'.$blog_id]['city']))
  980.                 $city=$_SESSION['addy'.$blog_id]['city'];
  981.             $country=$_SESSION['addy'.$blog_id]['country'];
  982.             $state=$_SESSION['addy'.$blog_id]['state'];
  983.             if (!is_numeric($state) ){
  984.                 $li = $wpdb->escape($state);
  985.                 $table=$wpdb->prefix.'eshop_states';
  986.                 $stateList = $wpdb->get_var("SELECT id FROM $table WHERE code='$li' limit 1");
  987.                 $state = $stateList;
  988.             }
  989.            
  990.             if(isset($_SESSION['addy'.$blog_id]['altstate']))
  991.                 $altstate=$_SESSION['addy'.$blog_id]['altstate'];
  992.             else
  993.                 $altstate='';
  994.             $zip=$_SESSION['addy'.$blog_id]['zip'];
  995.             /* defaults */
  996.             $ship_name=$ship_company='';
  997.             $ship_phone=$ship_address=$ship_city=$ship_postcode='';
  998.             $ship_country=$ship_state=$ship_altstate=$comments='';
  999.             if(isset($_SESSION['addy'.$blog_id]['ship_name']))
  1000.                 $ship_name=$_SESSION['addy'.$blog_id]['ship_name'];
  1001.             if(isset($_SESSION['addy'.$blog_id]['ship_company']))
  1002.                 $ship_company=$_SESSION['addy'.$blog_id]['ship_company'];
  1003.             if(isset($_SESSION['addy'.$blog_id]['ship_phone']))
  1004.                 $ship_phone=$_SESSION['addy'.$blog_id]['ship_phone'];
  1005.             if(isset($_SESSION['addy'.$blog_id]['ship_address']))
  1006.                 $ship_address=$_SESSION['addy'.$blog_id]['ship_address'];
  1007.             if(isset($_SESSION['addy'.$blog_id]['ship_city']))
  1008.                 $ship_city=$_SESSION['addy'.$blog_id]['ship_city'];
  1009.             if(isset($_SESSION['addy'.$blog_id]['ship_country']))
  1010.                 $ship_country=$_SESSION['addy'.$blog_id]['ship_country'];
  1011.             if(isset($_SESSION['addy'.$blog_id]['ship_state'])){
  1012.                 $ship_state=$_SESSION['addy'.$blog_id]['ship_state'];
  1013.                 if (!is_numeric($ship_state) ){
  1014.                     $li = $wpdb->escape($ship_state);
  1015.                     $table=$wpdb->prefix.'eshop_states';
  1016.                     $stateSList = $wpdb->get_var("SELECT id FROM $table WHERE code='$li' limit 1");
  1017.                     $ship_state = $stateSList;
  1018.                 }
  1019.             }
  1020.            
  1021.             if(isset($_SESSION['addy'.$blog_id]['ship_altstate']))
  1022.                 $ship_altstate=$_SESSION['addy'.$blog_id]['ship_altstate'];
  1023.             else
  1024.                 $ship_altstate='';
  1025.             if(isset($_SESSION['addy'.$blog_id]['ship_postcode']))
  1026.                 $ship_postcode=$_SESSION['addy'.$blog_id]['ship_postcode'];
  1027.             if(isset($_SESSION['addy'.$blog_id]['comments']))
  1028.                 $comments=$_SESSION['addy'.$blog_id]['comments'];
  1029.         }else{
  1030.             $first_name=$last_name=$company=$phone=$reference='';
  1031.             $email=$address1=$address2=$city=$country='';
  1032.             $state=$altstate=$zip=$ship_name=$ship_company='';
  1033.             $ship_phone=$ship_address=$ship_city=$ship_postcode='';
  1034.             $ship_country=$ship_state=$ship_altstate=$comments='';
  1035.             $eshopsetcookie=apply_filters('eshop_use_cookie',true);
  1036.             if(isset($_COOKIE["eshopcart"]) && calculate_items()!=0 && $eshopsetcookie==true){
  1037.                 $crumbs=eshop_break_cookie($_COOKIE["eshopcart"]);
  1038.                 foreach($crumbs as $k=>$v){
  1039.                     $$k=$v;
  1040.                 }
  1041.             }
  1042.             if(is_user_logged_in() && isset($eshopoptions['users']) && 'yes' == $eshopoptions['users']){
  1043.                 global $current_user;
  1044.                 get_currentuserinfo();
  1045.                 $crumbs=stripslashes_deep(get_the_author_meta( 'eshop', $current_user->ID )) ;
  1046.                 if(is_array($crumbs)){
  1047.                     foreach($crumbs as $k=>$v){
  1048.                         $$k=esc_attr($v);
  1049.                     }
  1050.                     $first_name=esc_attr($current_user->user_firstname);
  1051.                     $last_name=esc_attr($current_user->user_lastname);
  1052.                     $email=esc_attr($current_user->user_email);
  1053.                 }
  1054.             }
  1055.         }
  1056.     }
  1057.  
  1058.     if($chkerror!=0 || (!isset ($_POST['submit'])) && $numberofproducts>=1){
  1059.         // only show form if not filled in.
  1060.         $echoit.= eshopShowform($first_name,$last_name,$company,$phone,$email,$address1,$address2,$city,$state,$altstate,$zip,$country,$reference,$comments,$ship_name,$ship_company,$ship_phone,$ship_address,$ship_city,$ship_postcode,$ship_state,$ship_altstate,$ship_country);
  1061.     }
  1062.  
  1063.     if(isset($_SESSION['eshopcart'.$blog_id])){
  1064.         switch($contineproceed){
  1065.             case ('1'):
  1066.                 $echoit.='<ul class="continue-proceed"><li class="editcart"><a href="http://www.mydomain.com/shopping-cart/"></a></li></ul>';
  1067.                 break;
  1068.             case ('2'):
  1069.                 $echoit.='<ul class="continue-proceed redirect"><li class="editcheckout"><a href="javascript:history.go(-1)"></a></li></ul>';
  1070.                 break;
  1071.             case ('3'):
  1072.                 $echoit.='<ul class="continue-proceed redirect"><li class="editcheckout"><a href="javascript:history.go(-1)"></a></li></ul>';
  1073.                 break;
  1074.         }
  1075.  
  1076.     }else{
  1077.         $echoit.= "<p><strong class=\"eshoperror error\">".__('Your shopping cart is currently empty.','eshop')."</strong></p>";
  1078.     }
  1079.     return $echoit;
  1080.  }
  1081. }
  1082. if (!function_exists('eshop_checkreqd')) {
  1083.     function eshop_checkreqd($reqdarray,$tocheck){
  1084.         if(in_array($tocheck,$reqdarray)){
  1085.             $reqd='<span class="reqd">*</span>';
  1086.         }else{
  1087.             $reqd='';
  1088.         }
  1089.         return $reqd;
  1090.     }
  1091. }
  1092. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement