<?php
global $wpdb;
$orderurl = home_url('/my-orders/');
$loginurl = home_url("/wp-login.php?redirect_to=".urlencode($orderurl));
if ( !is_user_logged_in() ) {
$_ohtml =<<<SIGNIN
<center>
Please <a href="{$loginurl}" class="simplemodal-login"><b>Log In or Register</b></a> to access this page
</center>
SIGNIN;
} else {
if($_GET['id']==''&&$_GET['item']=='') {
$orderid=__("Order Id","wpmarketplace");
$date=__("Date","wpmarketplace");
$payment_status=__("Payment Status","wpmarketplace");
$_ohtml = <<<ROW
<table class="wpmp-my-orders" width="100%" cellspacing="0">
<tr>
<th>$orderid</th>
<th>$date</th>
<th style="width: 180px;">$payment_status</th>
</tr>
ROW;
foreach($myorders as $order){
$date = date("Y-m-d h:i a",$order->date);
$items = unserialize($order->items);
$_ohtml .= <<<ROW
<tr class="order">
<td><a href='{$orderurl}?id={$order->order_id}'>{$order->order_id}</a></td>
<td>{$date}</td>
<td>{$order->order_status}</td>
</tr>
ROW;
}
$homeurl = home_url('/');
$_ohtml .=<<<END
</table>
<script language="JavaScript">
<!--
function getkey(file, order_id){
jQuery('#lic_'+file+'_'+order_id).html('Please Wait...');
jQuery.post('{$homeurl}',{action:'wpdm_pp_ajax_call',execute:'getlicensekey',fileid:file,orderid:order_id},function(res){
jQuery('#lic_'+file+'_'+order_id).html("<input type=text style='width:150px;border:0px' readonly=readonly onclick='this.select()' value='"+res+"' />");
});
}
//-->
</script>
END;
}
$odetails=__("Order Details"."wpmarketplace");
$ostatus=__("Order Status"."wpmarketplace");
$prdct=__("Product"."wpmarketplace");
$qnt=__("Quantity"."wpmarketplace");
$ttl=__("Total"."wpmarketplace");
$dnl=__("Download"."wpmarketplace");
if($_GET['id']!=''&&$_GET['item']==''){
$order = $order->GetOrder($_GET['id']);
$cart_data = unserialize($order->cart_data);
$items = array_keys($cart_data);
$_ohtml = <<<OTH
<table class="wpmp-my-orders" width="100%" cellspacing="0">
<caption><b>{$order->title} » $odetails </b> <br>
$ostatus : {$order->order_status}
</caption>
<tr>
<th>$prdct</th>
<th>$qnt</th>
<th>$ttl</th>
<th>$dnl</th>
</tr>
OTH;
$total=0;
foreach($items as $itemid){
$total+=$cart_data[$itemid][item_total];
$item = get_post($itemid);
$dk = md5($item->files);
$download_link = home_url("/?wpmpfile={$itemid}&oid={$order->order_id}");
//$licenseurl = home_url("/?task=getlicensekey&file={$itemid}&oid={$order->order_id}");
$_ohtml .= <<<ITEM
<tr class="item">
<td>{$item->post_title}</td>
<td>{$cart_data[$itemid][quantity]}</td>
<td>{$cart_data[$itemid][item_total]}</td>
ITEM;
@extract(get_post_meta($itemid,"wpmp_list_opts",true));
if($digital_activate){
if($order->payment_status=='Completed'){
$_ohtml .= <<<ITEM
<td><a href="{$download_link}">$dnl</a></td>
</tr>
ITEM;
}else{
$_ohtml .= <<<ITEM
<td>—</td>
</tr>
ITEM;
}
} else {
$_ohtml .= "<td>".__("N/A","wpmarketplace").$dnl."</td>";
}
}
$dsct=__("Discount","wpmarketplace");
$shping=__("Shipping","wpmarketplace");
$cdetails=__("Customer details","wpmarketplace");
$eml=__("Email","wpmarketplace");
$bling=__("Billing Address","wpmarketplace");
$shing_ad=__("Shipping Address","wpmarketplace");
$vdlink=__("Please complete your payment to view download links.","wpmarketplace");
$pnow=__("Pay Now","wpmarketplace");
$usermeta=unserialize(get_user_meta($current_user->ID, 'user_billing_shipping',true));
//print_r($usermeta);
extract($usermeta);
$_ohtml .= <<<ITEM
<tr class="item">
<td colspan="2">$dsct</td>
<td>{$order->cart_discount}</td>
<td></td>
</tr>
<tr class="item">
<td colspan="2">$shping</td>
<td>{$order->shipping_cost}</td>
<td></td>
</tr>
<tr class="item">
<td colspan="2">$ttl</td>
<td>{$order->total}</td>
<td></td>
</tr>
<tr>
<td colspan="3">
<header>
<h2>$cdetails</h2>
</header>
<dl class="customer_details">
<dt>$eml:</dt><dd>$current_user->user_email</dd></dl>
<div class="col2-set addresses" style="width:580px;">
<div class="col-1" style="float:left">
<header class="title">
<h3>$bling</h3>
</header>
<address><p>
$billing[first_name] $billing[last_name]<br>
$billing[company]<br>
$billing[address_1]<br>
$billing[address_2]<br>
$billing[city]<br>
$billing[state]<br>
$billing[postcode]<br>
$billing[country] </p></address>
</div><!-- /.col-1 -->
<div class="col-2" style="float:right; margin:5px;">
<header class="title">
<h3>$shing_ad</h3>
</header>
<address><p>
$shippingin[first_name] $shippingin[last_name]<br>
$shippingin[company]<br>
$shippingin[address_1]<br>
$shippingin[address_2]<br>
$shippingin[city]<br>
$shippingin[state]<br>
$shippingin[postcode]<br>
$shippingin[country] </p></address>
</div><!-- /.col-2 -->
</div>
</td>
</tr>
ITEM;
if($order->payment_status!='Completed'){
$purl = home_url('/?pay_now='.$order->order_id);
$_ohtml .= <<<PAY
<tr class="items"><td colspan="4">$vdlink <div id="proceed_{$order->order_id}" style="float:right">
<select name="payment_method" id="pgdd_{$order->order_id}" style="padding: 0px; margin: 0px;"><option value="PayPal">PayPal IPN</option>
</select> <a onclick="return proceed2payment_{$order->order_id}(this)" href="#"><b>$pnow</b></a>
<script>
function proceed2payment_{$order->order_id}(ob){
jQuery(ob).html('Processing...');
jQuery('#pgdd_{$order->order_id}').attr('disabled','disabled');
jQuery.post('{$purl}',{action:'wpmp_pp_ajax_call',execute:'PayNow',order_id:'{$order->order_id}',payment_method:jQuery('#pgdd_{$order->order_id}').val()},function(res){
jQuery('#proceed_{$order->order_id}').html(res);
});
return false;
}
</script>
</div></td></tr>
PAY;
}
$homeurl = home_url('/');
$_ohtml .=<<<EOT
</table>
<script language="JavaScript">
<!--
function getkey(file, order_id){
jQuery('#lic_'+file+'_'+order_id).html('Please Wait...');
jQuery.post('{$homeurl}',{action:'wpdm_pp_ajax_call',execute:'getlicensekey',fileid:file,orderid:order_id},function(res){
jQuery('#lic_'+file+'_'+order_id).html("<input type=text style='width:150px;border:0px' readonly=readonly onclick='this.select()' value='"+res+"' />");
});
}
//-->
</script>
EOT;
}
if($_GET['id']!=''&&$_GET['item']!=''){
$oid = mysql_escape_string($_GET['id']);
$order = $order->GetOrder($_GET['id']);
$cart_data = unserialize($order->cart_data);
$items = unserialize($order->items);
$item = (int)$_GET['item'];
$mxd = $cart_data[$item]?$cart_data[$item]:1;
$itemd = $wpdb->get_row("select * from {$wpdb->prefix}ahm_files where id='$item'");
$lic = $wpdb->get_row("select * from {$wpdb->prefix}ahm_licenses where oid='$oid' and pid='$item'");
$domain = is_array(unserialize($lic->domain))?unserialize($lic->domain):array($lic->domain);
if(count($domain)==1&&$domain[0]=='') $domain = array();
$ahtml = <<<OTH
<form method="post" action="">
<table class="wpmp-my-orders" width="100%" cellspacing="0">
<caption><b><a href='$orderurl?id={$order->order_id}'>{$order->id}</a> » {$itemd->title} </b><br>
License number can be used with {$mxd} domain(s)<br>
<small><i>contact site admin within 3 days after add dmain if you need to change</i></small>
</caption>
<tr>
<th>Domain Name</th>
<th>Status</th>
</tr>
OTH;
foreach($domain as $d){
$ahtml .= <<<OTD
<tr>
<td>{$d}</td>
<td>active</td>
</tr>
OTD;
}
if(count($domain)<$mxd){
$ahtml .= <<<OTD
<tr>
<td><input style='text-align:left' type=text name='domain' /></td>
<td><input class='button' type='submit' value='Add Domain' /></td>
</tr>
OTD;
}
$ahtml .= <<<OTF
</table>
</form>
OTF;
echo $ahtml;
}
}
?>