<?php

/*

 osCommerce, Open Source E-Commerce Solutions 
http://www.oscommerce.com 

Copyright (c) 2003 osCommerce 

osCommRes, Services Oline 
http://www.oscommres.com 
Copyright (c) 2005 osCommRes 

Freeway eCommerce 
http://www.zac-ware.com/freeway 
Copyright (c) 2007 ZacWare

Released under the GNU General Public License
*/
// Set flag that this is a parent file
	define( '_FEXEC', 1 );

  require('includes/application_top.php');

  require(DIR_WS_CLASSES . 'currencies.php');
  $currencies = new currencies();

  $affiliate_banner_history_raw = "select sum(affiliate_banners_shown) as count from " . TABLE_AFFILIATE_BANNERS_HISTORY .  " where affiliate_banners_affiliate_id  = '" .  (int)$HTTP_GET_VARS['acID'] . "'";
  $affiliate_banner_history_query = tep_db_query($affiliate_banner_history_raw);
  $affiliate_banner_history = tep_db_fetch_array($affiliate_banner_history_query);
  $affiliate_impressions = $affiliate_banner_history['count'];
  if ($affiliate_impressions == 0) $affiliate_impressions = "n/a"; 
  
  $affiliate_query = tep_db_query("select * from " . TABLE_AFFILIATE . " where affiliate_id ='" . (int)$HTTP_GET_VARS['acID'] . "'");
 
  $affiliate = tep_db_fetch_array($affiliate_query);
  $affiliate_percent = 0;
  $affiliate_percent = $affiliate['affiliate_commission_percent'];
  if ($affiliate_percent < AFFILIATE_PERCENT) $affiliate_percent = AFFILIATE_PERCENT;
  
  $affiliate_clickthroughs_raw = "select count(*) as count from " . TABLE_AFFILIATE_CLICKTHROUGHS . " where affiliate_id = '" . (int)$HTTP_GET_VARS['acID'] . "'";
  $affiliate_clickthroughs_query = tep_db_query($affiliate_clickthroughs_raw);
  $affiliate_clickthroughs = tep_db_fetch_array($affiliate_clickthroughs_query);
  $affiliate_clickthroughs = $affiliate_clickthroughs['count'];

  $affiliate_sales_raw = "
    select count(*) as count, sum(affiliate_value) as total, sum(affiliate_payment) as payment from " . TABLE_AFFILIATE_SALES . " a 
    left join " . TABLE_ORDERS . " o on (a.affiliate_orders_id=o.orders_id) 
    where a.affiliate_id = '" . (int)$HTTP_GET_VARS['acID'] . "' and o.orders_status >= " . AFFILIATE_PAYMENT_ORDER_MIN_STATUS . "
    ";
  $affiliate_sales_query = tep_db_query($affiliate_sales_raw);
  $affiliate_sales = tep_db_fetch_array($affiliate_sales_query);

  $affiliate_transactions=$affiliate_sales['count'];
  if ($affiliate_clickthroughs > 0) {
	  $affiliate_conversions = tep_round(($affiliate_transactions / $affiliate_clickthroughs)*100,2) . "%";
  } else {
    $affiliate_conversions = "n/a";
  }

  if ($affiliate_sales['total'] > 0) {
    $affiliate_average = $affiliate_sales['total'] / $affiliate_sales['count'];
  } else {
    $affiliate_average = 0;
  }
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo TITLE; ?></title>
<link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
<style type="text/css">
	#pup {position:absolute; visibility:hidden; z-index:200; width:130; }
</style>
<script language="javascript" src="includes/menu.js"></script>
<script language="javascript" src="includes/general.js"></script>
<script language="javascript"><!--
/*function popupWindow(url) {
  window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=450,height=120,screenX=150,screenY=150,top=150,left=150')
}*/
//--></script>
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF">
<script language="javascript" src="includes/popup.js"></script>
<script language="javascript">
var baby=new Array();
				baby[1]="";
function popupWindow(action){ 
var contentText;
	switch(action){
		case '1':
			contentText='<?php echo TEXT_IMPRESSIONS_HELP;?>';
			break;
		case '2':
			contentText='<?php echo TEXT_VISITS_HELP;?>';
			break;
		case '3':
			contentText='<?php echo TEXT_TRANSACTIONS_HELP;?>';
			break;
		case '4':
			contentText='<?php echo TEXT_CONVERSION_HELP;?>';
			break;
		case '5':
			contentText='<?php echo TEXT_AMOUNT_HELP;?>';
			break;
		case '6':
			contentText='<?php echo TEXT_AVERAGE_HELP;?>';
			break;
		case '7':
			contentText='<?php echo TEXT_COMMISSION_RATE_HELP;?>';
			break;
		case '8':
			contentText='<?php echo TEXT_COMMISSION_HELP;?>';
			break;
	}
					content='<table border="0" cellspacing="0" cellpadding="4" class="formArea" width="100%"><tr><td class=smallText>';
					content+=contentText;
					content+='</td></tr></table>';
					popwidth=250;
					baby[1]=content;
					if (baby[1]!="")
					{
						popup("1","#ffffff");
					}	
}</script>
<!-- header //-->
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<!-- header_eof //-->

<!-- body //-->
<table border="0" width="100%" cellspacing="2" cellpadding="2">
  <tr> 
<!-- body_text //-->
    <td width="100%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="0">
      <tr>
        <td width="100%"><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td class="pageHeading"><?php echo HEADING_TITLE; ?></td>
            <td class="pageHeading" align="right"><?php echo tep_draw_separator('pixel_trans.gif', 1, HEADING_IMAGE_HEIGHT); ?></td>
            <td class="pageHeading" align="right"><?php echo '<a href="' . tep_href_link(FILENAME_AFFILIATE, tep_get_all_get_params(array('action'))) . '">' . tep_image_button('button_back.gif', IMAGE_BACK) . '</a>'; ?></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
              <tr class="dataTableHeadingRow">
                <td class="dataTableHeadingContent"><?php echo TEXT_SUMMARY_TITLE; ?></td>
              </tr>
            </table></td>
          </tr>
          <tr>
            <td><table width="100%" border="0" cellpadding="4" cellspacing="2" class="dataTableContent">
              <center>
                <tr>
                  <td width="20%" align="right" class="dataTableContent"><b><?php echo TEXT_AFFILIATE_NAME; ?></b>&nbsp;&nbsp;&nbsp;&nbsp;</td>
                  <td width="6%" class="dataTableContent"><?php echo $affiliate['affiliate_firstname'] . ' ' . $affiliate['affiliate_lastname']; ?></td>
				  <td width="7%">&nbsp;</td>
                  <td width="20%" align="right" class="dataTableContent"><?php echo TEXT_AFFILIATE_JOINDATE; ?>&nbsp;&nbsp;&nbsp;&nbsp;</td>
                  <td width="6%" class="dataTableContent"><?php echo format_date($affiliate['affiliate_date_account_created']); ?></td>
				  <td width="7%">&nbsp;</td>
                </tr>
             <!--<tr>
                  <td width="35%" align="right" class="dataTableContent"><?php echo TEXT_IMPRESSIONS; ?><?php echo '<a href="javascript:popupWindow(\'' . (HTTP_SERVER . DIR_WS_CATALOG . FILENAME_AFFILIATE_HELP_1) . '\')">' . TEXT_SUMMARY_HELP . '</a>'; ?></td>
                 <td width="15%" class="dataTableContent"><?php echo $affiliate_impressions . '<span onMouseOver="javascript:popupWindow(\'1\')" onMouseOut="javascript:kill();">' . tep_image(DIR_WS_IMAGES. 'icon_info.gif') . '</span>'; ?></td>
                 <td width="35%" align="right" class="dataTableContent"><?php echo TEXT_VISITS; ?><?php echo '<a href="javascript:popupWindow(\'' . (HTTP_SERVER . DIR_WS_CATALOG . FILENAME_AFFILIATE_HELP_2) . '\')">' . TEXT_SUMMARY_HELP . '</a>'; ?></td>
                  <td width="15%" class="dataTableContent"><?php echo $affiliate_clickthroughs; ?></td>
                </tr>
                <tr>
                  <td width="35%" align="right" class="dataTableContent"><?php echo TEXT_TRANSACTIONS; ?><?php echo '<a href="javascript:popupWindow(\'' . (HTTP_SERVER . DIR_WS_CATALOG . FILENAME_AFFILIATE_HELP_3) . '\')">' . TEXT_SUMMARY_HELP . '</a>'; ?></td>
                  <td width="15%" class="dataTableContent"><?php echo $affiliate_sales['count']; ?></td>
                  <td width="35%" align="right" class="dataTableContent"><?php echo TEXT_CONVERSION; ?><?php echo '<a href="javascript:popupWindow(\'' . (HTTP_SERVER . DIR_WS_CATALOG . FILENAME_AFFILIATE_HELP_4) . '\')">' . TEXT_SUMMARY_HELP . '</a>'; ?></td>
                  <td width="15%" class="dataTableContent"><?php echo $affiliate_conversions.' %';?></td>
                </tr>
                <tr>
                  <td width="35%" align="right" class="dataTableContent"><?php echo TEXT_AMOUNT; ?><?php echo '<a href="javascript:popupWindow(\'' . (HTTP_SERVER . DIR_WS_CATALOG . FILENAME_AFFILIATE_HELP_5) . '\')">' . TEXT_SUMMARY_HELP . '</a>'; ?></td>
                  <td width="15%" class="dataTableContent"><?php echo $currencies->display_price($affiliate_sales['total'], ''); ?></td>
                  <td width="35%" align="right" class="dataTableContent"><?php echo TEXT_AVERAGE; ?><?php echo '<a href="javascript:popupWindow(\'' . (HTTP_SERVER . DIR_WS_CATALOG . FILENAME_AFFILIATE_HELP_6) . '\')">' . TEXT_SUMMARY_HELP . '</a>'; ?></td>
                  <td width="15%" class="dataTableContent"><?php echo $currencies->display_price($affiliate_average, ''); ?></td>
                </tr>
                <tr>
                  <td width="35%" align="right" class="dataTableContent"><?php echo TEXT_COMMISSION_RATE; ?><?php echo '<a href="javascript:popupWindow(\'' . (HTTP_SERVER . DIR_WS_CATALOG . FILENAME_AFFILIATE_HELP_7) . '\')">' . TEXT_SUMMARY_HELP . '</a>'; ?></td>
                  <td width="15%" class="dataTableContent"><?php echo $affiliate_percent, ' %'; ?></td>
                  <td width="35%" align="right" class="dataTableContent"><b><?php echo TEXT_COMMISSION; ?><?php echo '<a href="javascript:popupWindow(\'' . (HTTP_SERVER . DIR_WS_CATALOG . FILENAME_AFFILIATE_HELP_8) . '\')">' . TEXT_SUMMARY_HELP . '</a>'; ?></b></td>
                  <td width="15%" class="dataTableContent"><b><?php echo $currencies->display_price($affiliate_sales['payment'], ''); ?></b></td>
                </tr>-->
				<tr>
                  <td width="20%" align="right" class="dataTableContent"><?php echo TEXT_IMPRESSIONS; ?></td>
                  <td width="6%" class="dataTableContent"><?php echo $affiliate_impressions; ?></td>
				  <td width="7%"><?php echo '<span onMouseOver="javascript:popupWindow(\'1\')" onMouseOut="javascript:kill();">' . tep_image(DIR_WS_IMAGES. 'icon_info.gif') . '</span>'; ?></td>
                  <td width="20%" align="right" class="dataTableContent"><?php echo TEXT_VISITS; ?></td>
                  <td width="6%" class="dataTableContent"><?php echo $affiliate_clickthroughs; ?></td>
				  <td width="7%"><?php echo '<span onMouseOver="javascript:popupWindow(\'2\')" onMouseOut="javascript:kill();">' . tep_image(DIR_WS_IMAGES. 'icon_info.gif') . '</span>'; ?></td>
                </tr>
                <tr>
                  <td width="20%" align="right" class="dataTableContent"><?php echo TEXT_TRANSACTIONS; ?></td>
                  <td width="6%" class="dataTableContent"><?php echo $affiliate_transactions; ?></td>
				  <td width="7%"><?php echo '<span onMouseOver="javascript:popupWindow(\'3\')" onMouseOut="javascript:kill();">' . tep_image(DIR_WS_IMAGES. 'icon_info.gif') . '</span>'; ?></td>
                  <td width="20%" align="right" class="dataTableContent"><?php echo TEXT_CONVERSION; ?></td>
                  <td width="6%" class="dataTableContent"><?php echo $affiliate_conversions;?></td>
				  <td width="7%"><?php echo '<span onMouseOver="javascript:popupWindow(\'4\')" onMouseOut="javascript:kill();">' . tep_image(DIR_WS_IMAGES. 'icon_info.gif') . '</span>'; ?></td>
                </tr>
                <tr>
                  <td width="20%" align="right" class="dataTableContent"><?php echo TEXT_AMOUNT; ?></td>
                  <td width="6%" class="dataTableContent"><?php echo $currencies->display_price($affiliate_amount, ''); ?></td>
				  <td width="7%"><?php echo '<span onMouseOver="javascript:popupWindow(\'5\')" onMouseOut="javascript:kill();">' . tep_image(DIR_WS_IMAGES. 'icon_info.gif') . '</span>'; ?></td>
                  <td width="20%" align="right" class="dataTableContent"><?php echo TEXT_AVERAGE; ?></td>
                  <td width="6%" class="dataTableContent"><?php echo $currencies->display_price($affiliate_average, ''); ?></td>
				  <td width="7%"><?php echo '<span onMouseOver="javascript:popupWindow(\'6\')" onMouseOut="javascript:kill();">' . tep_image(DIR_WS_IMAGES. 'icon_info.gif') . '</span>'; ?></td>
                </tr>
                <tr>
                  <td width="20%" align="right" class="dataTableContent"><?php echo TEXT_COMMISSION_RATE; ?></td>
                  <td width="6%" class="dataTableContent"><?php echo tep_round(AFFILIATE_PERCENT, 2) . ' %'; ?></td>
				  <td width="7%"><?php echo '<span onMouseOver="javascript:popupWindow(\'7\')" onMouseOut="javascript:kill();">' . tep_image(DIR_WS_IMAGES. 'icon_info.gif') . '</span>'; ?></td>
                  <td width="20%" align="right" class="dataTableContent"><b><?php echo TEXT_COMMISSION; ?></b></td>
                  <td width="6%" class="dataTableContent"><b><?php echo $currencies->display_price($affiliate_commission, ''); ?></b></td>
				  <td width="7%"><?php echo '<span onMouseOver="javascript:popupWindow(\'8\')" onMouseOut="javascript:kill();">' . tep_image(DIR_WS_IMAGES. 'icon_info.gif') . '</span>'; ?></td>
                </tr>
                <tr>
                  <td colspan="4"><?php echo tep_draw_separator(); ?></td>
                </tr>
                <tr>
                  <td align="center" class="dataTableContent" colspan="4"><b><?php echo TEXT_SUMMARY; ?></b></td>
                </tr>
                <tr>
                  <td colspan="4"><?php echo tep_draw_separator(); ?></td>
                </tr>
                <tr>
                  <td align="center" class="dataTableContent" colspan="4"><?php echo '<a href="' . tep_href_link(FILENAME_AFFILIATE_CLICKS, 'acID=' . $HTTP_GET_VARS['acID']) . '">' . tep_image_button('button_affiliate_clickthroughs.gif', IMAGE_CLICKTHROUGHS) . '</a> <a href="' . tep_href_link(FILENAME_AFFILIATE_SALES, 'acID=' . $HTTP_GET_VARS['acID']) . '">' . tep_image_button('button_affiliate_sales.gif', IMAGE_SALES) . '</a>'; ?></td>
                </tr>
              </center>
            </table></td>
          </tr>
        </table></td>
      </tr>
    </table></td>
<!-- body_text_eof //-->
  </tr>
</table>
<!-- body_eof //-->

<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php');?>
