<?
session_start();
if(!isset($_SESSION["member_id"])){
session_id($_GET['PHPSESSID']);
}
session_start();
include("../../dbcon.php");
include("functions.php");
function datediff($date1, $date2) { 
// $date1 is subtracted from $date2. 
// if $date2 is not specified, then current date is assumed.

//Splits date apart
list($date1_year, $date1_month, $date1_day) = split('[/.-]', $date1); 

//if (!$date2) { 
//  $date2_year = date("Y"); //Gets Current Year
//  $date2_month = date("m"); //Gets Current Month
//  $date2_day = date("d"); //Gets Current Day
//} else {
  list($date2_year, $date2_month, $date2_day) = split('[/.-]', $date2);
//}

$date1 = mktime(0,0,0,$date1_month, $date1_day, $date1_year); //Gets Unix timestamp for $date1
$date2 = mktime(0,0,0,$date2_month, $date2_day, $date2_year); //Gets Unix timestamp for $date2

$difference = $date2-$date1; //Calcuates Difference
//return floor($difference/60/60/24)+1; //Calculates Days Old
return $difference/60/60/24; //Calculates Days Old
}
?>
<? 
$memberid="";
if(isset($_SESSION["member_id"])){
$memberid=$_SESSION["member_id"];
$querymembers = "SELECT * FROM members WHERE member_id='$memberid'";
$resultmembers = mysql_query ($querymembers);
$linemembers=mysql_fetch_array($resultmembers);
}
else if(isset($_REQUEST['member_id'])) {
	$_SESSION['member_id']=$_REQUEST['member_id'];
	$memberid=$_SESSION["member_id"];
	$querymembers = "SELECT * FROM members WHERE member_id='$memberid'";
	$resultmembers = mysql_query ($querymembers);
	$linemembers=mysql_fetch_array($resultmembers);
}
else{
echo "Please define either a member or an advertisment or a banner";
exit;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="https://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title><? echo $websitename;?> Administration Panel - Statistics </title>
<link href="stylestats.css" rel="stylesheet" type="text/css" />
<script language="JavaScript" type="text/JavaScript">
<!--
function formsubmit(form1){
window.document.form1.submit();
}
//-->
</script>
<script language="JavaScript">
function checkFields() {
missinginfo = "";
if (form1.r1[1].checked) {
	if (form1.from_day.value=="" || form1.from_month.value=="" || form1.from_year.value=="" || form1.to_day.value=="" || form1.to_month.value=="" || form1.to_year.value=="") {
	missinginfo += "\nSelect valid From and To Dates";
	}
}
if (missinginfo != "") {
missinginfo ="_____________________________\n" +
"You have failed submitting the below:\n" +
//missinginfo + "\n_____________________________" +
//"\n<?=$str_post_cv_FormMsg2;?>";
alert(missinginfo);
return false;
}
}
</script>
</head>

<body bgcolor="#FFFFFF" background="imgs/spacer.gif">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr> 
        <td background="imgs/logobg.gif"> <table width="100%" border="0" cellspacing="0" cellpadding="3">
              <tr> 
                <td width="23%" rowspan="2"><a href="<?=$protocol;?>www.cyprusnet.com" target="_blank"><img src="imgs/logo.gif" alt="CyprusNet" width="211" height="48" border="0" /></a></td>
                <td width="77%" align="right"><strong><?=$linemembers["shipmail"]; ?> | </strong><a href="#">Help</a><strong> |</strong></td>
              </tr>
              <tr>
                <td align="right">Customer ID: <?=$linemembers["member_id"]; ?> </td>
              </tr>
            </table>
            <br />
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td width="7%" align="left" scope="row"><table border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <th width="8" scope="row"><img src="imgs/tab-d-l.gif" width="8" height="22" /></th>
                    <td valign="middle" nowrap="nowrap" bgcolor="#296891" class="tdmenudark">Statistics</td>
                    <td width="8"><img src="imgs/tab-d-r.gif" width="8" height="22" /></td>
                  </tr>
                </table>
                </td>
                <td width="6%">&nbsp;</td>
<td width="8%">&nbsp;</td>
                <td width="79%">&nbsp;</td>
              </tr>
              <tr>
                <th height="25" colspan="4" bgcolor="#296891" scope="row">&nbsp;</th>
              </tr>
            </table>
            Statistics recording started on the 17th of October 2005 <? if(!isset($r1) || $r1==""){
			$r1=="default";
}
if($r1=="FDTD"){
	$fromdate="$from_year-$from_month-$from_day 00:00:00";
	$todate="$to_year-$to_month-$to_day 23:59:59";
	$wherequery=" AND added_on>='$fromdate' AND added_on<='$todate'";
}else{
 if($selection=="CM"){
//	$wherequery=" AND MONTH(added_on)=MONTH(NOW())";
	$from_year=date("Y");
	$from_month=date("m");
	$from_day="01";
	$to_year=date("Y");
	$to_month=date("m");
	$to_day=date("t");
	$fromdate="$from_year-$from_month-$from_day 00:00:00";
	$todate="$to_year-$to_month-$to_day 23:59:59";
	$wherequery=" AND added_on>='$fromdate' AND added_on<='$todate'";
//	}elseif($selection=="FDTD"){
	}elseif($selection=="LM"){
 $LM  = mktime(0, 0, 0, date("m")-1  , date("d"), date("Y"));
	$from_year=date("Y", $LM);
	$from_month=date("m", $LM);
	$from_day="01";
	$to_year=date("Y", $LM);
	$to_month=date("m", $LM);
	$to_day=date("t", $LM);
	$fromdate="$from_year-$from_month-$from_day 00:00:00";
	$todate="$to_year-$to_month-$to_day 23:59:59";
	$wherequery=" AND added_on>='$fromdate' AND added_on<='$todate'";
//	$wherequery=" AND MONTH(added_on)=MONTH(NOW() - INTERVAL 1 MONTH)";
	}elseif($selection=="Y"){
 $Y  = mktime(0, 0, 0, date("m")  , date("d")-1, date("Y"));
	$from_year=date("Y", $Y);
	$from_month=date("m", $Y);
	$from_day=date("d", $Y);
	$to_year=date("Y", $Y);
	$to_month=date("m", $Y);
	$to_day=date("d", $Y);
	$fromdate="$from_year-$from_month-$from_day 00:00:00";
	$todate="$to_year-$to_month-$to_day 23:59:59";
	$wherequery=" AND added_on>='$fromdate' AND added_on<='$todate'";
//	$wherequery=" AND DATE_SUB('$today', INTERVAL 1 DAY) LIKE added_on";
	}else{
	$from_year="";
	$from_month="";
	$from_day="";
	$to_year="";
	$to_month="";
	$to_day="";
	$wherequery="";
	}
}
	$today=date("Y-m-d");
$wherequery .=" AND added_on < '$today' AND added_on > '2005-10-16'";
// $tomorrow  = mktime(0, 0, 0, date("m")  , date("d")+1, date("Y"));
?><br />
            <br />
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <th width="32%" align="left" scope="row"><strong class="tdheadername"><?=$linemembers["companyname"]; ?></strong></th>
                <td width="68%" rowspan="2" align="right"><strong>Date <?=date("d M Y");?></strong>
                  <script language="JavaScript">
function enable_dates(){
  if (document.all||document.getElementById){
	document.form1.from_day.disabled=false;
	document.form1.from_month.disabled=false;
	document.form1.from_year.disabled=false;
	document.form1.to_day.disabled=false;
	document.form1.to_month.disabled=false;
	document.form1.to_year.disabled=false;
	document.form1.selection.disabled=true;
}
}
function enable_selection(){
  if (document.all||document.getElementById){
	document.form1.from_day.disabled=true;
	document.form1.from_month.disabled=true;
	document.form1.from_year.disabled=true;
	document.form1.to_day.disabled=true;
	document.form1.to_month.disabled=true;
	document.form1.to_year.disabled=true;
	document.form1.selection.disabled=false;
	}
}
</script>
<form action="" method="get" enctype="application/x-www-form-urlencoded" name="form1" onSubmit="return checkFields();">
				  <table border="0" cellspacing="0" cellpadding="2">
                    <tr>
                      <td class="left"><input name="r1" type="radio" value="default" checked="checked" onclick="enable_selection();">
                      </td>
                    <td align="left" class="left"><select name="selection" onchange="formsubmit('form1')" <? if($r1=="FDTD"){?>disabled="disabled"<? }?>>
                          <option value="All" selected>ALL
                          Time</option>
                          <option value="Y"<? if($selection=="Y")echo " selected";?>>Yesterday</option>
                          <option value="CM"<? if($selection=="CM")echo " selected";?>>Current
                          Month</option>
                          <option value="LM"<? if($selection=="LM")echo " selected";?>>Last
                          Month</option>
                          <!--<option value="FDTD"<? if($selection=="FDTD")echo " selected";?>>From Date to Date</option>-->
                        </select></td>
<td class="left">&nbsp;</td>
<td class="left">&nbsp;</td>
                      <td class="left">&nbsp;</td>
                    </tr>
                    <tr>
                      <td nowrap="nowrap" class="left"><input name="r1" type="radio" value="FDTD"<? if($r1=="FDTD")echo " checked";?> onclick="enable_dates();">
                      </td>
                    <td nowrap="nowrap" class="left"><select name="from_day" <? if($r1<>"FDTD"){?>disabled="disabled"<? }?> id="from_day">
                          <option value="" selected="selected">Day</option>
                          <? for($i=1;$i<=31;$i++){?>
                          <option value="<?=sprintf("%02.0f", $i);?>"<? if($from_day==$i)echo " selected";?>>
                          <?=sprintf("%02.0f", $i);?>
                          </option>
                          <? }?>
                        </select>
                          <select name="from_month" id="from_month"<? if($r1<>"FDTD"){?>disabled="disabled"<? }?> >
                            <option value="" selected="selected">Month</option>
                            <? for($i=1;$i<=12;$i++){?>
                            <option value="<?=sprintf("%02.0f", $i);?>"<? if($from_month==$i)echo " selected";?>>
                            <?=sprintf("%02.0f", $i);?>
                            </option>
                            <? }?>
                          </select>
                          <select name="from_year" id="from_year"<? if($r1<>"FDTD"){?>disabled="disabled"<? }?> >
                            <option value="" selected="selected">Year</option>
                            <? for($i=date("Y");$i>=2005;$i--){?>
                            <option value="<?=$i;?>"<? if($from_year==$i)echo " selected";?>>
                            <?=$i;?>
                            </option>
                            <? }?>
                          </select>
                    </td>
                      <td nowrap="nowrap" class="left">-</td>
<td nowrap="nowrap" class="left"><select name="to_day" id="to_day"<? if($r1<>"FDTD"){?>disabled="disabled"<? }?> >
    <option value="" selected="selected">Day</option>
    <? for($i=1;$i<=31;$i++){?>
    <option value="<?=sprintf("%02.0f", $i);?>"<? if($to_day==$i)echo " selected";?>>
    <?=sprintf("%02.0f", $i);?>
    </option>
    <? }?>
  </select>
    <select name="to_month" id="to_month"<? if($r1<>"FDTD"){?>disabled="disabled"<? }?> >
      <option value="" selected="selected">Month</option>
      <? for($i=1;$i<=12;$i++){?>
      <option value="<?=sprintf("%02.0f", $i);?>"<? if($to_month==$i)echo " selected";?>>
      <?=sprintf("%02.0f", $i);?>
      </option>
      <? }?>
    </select>
    <select name="to_year" id="to_year"<? if($r1<>"FDTD"){?>disabled="disabled"<? }?> >
      <option value="" selected="selected">Year</option>
      <? for($i=date("Y");$i>=2005;$i--){?>
      <option value="<?=$i;?>"<? if($to_year==$i)echo " selected";?>>
      <?=$i;?>
      </option>
      <? }?>
</select>
</td>
                      <td nowrap="nowrap" class="left"><input type="submit" name="Submit" value="Go" />
                      </td>
                    </tr>
                </table>
</form></td>
              </tr>
              <tr>
                <th class="tdheaderoverview" scope="row">Overview Statistics </th>
              </tr>
            </table>
            <br />
<!--
<strong class="red">Logos</strong>
<hr size="1" noshade="noshade" />
<? $query="SELECT *, SUM(views), MIN(added_on) FROM adverts_stats_views_maintained WHERE view_from!=''";
	$query .=$wherequery;
	$queryadv="SELECT * FROM advertisment WHERE member_id='$memberid'";
 $resultadv=mysql_query($queryadv);
	$NoOfAdvs=mysql_num_rows($resultadv);
	if($NoOfAdvs>0){
$query .= " AND (";	
$i=1;
while($lineadv=mysql_fetch_assoc($resultadv)){
$query .= " advertisment_id = '$lineadv[advertisment_id]'";
$advert_ids[]=$lineadv[advertisment_id];
if($i<$NoOfAdvs){ $query .= " OR ";}
$i++;
}
$query .= ")";
		$query .=" GROUP BY domain_id";
	$query .=" ORDER BY views DESC";
$result=mysql_query($query) or die (mysql_error());?>            <table width="100%" border="1" cellpadding="3" cellspacing="0" bordercolor="#BEBEBE" class="tableresults">
              <tr>
                <th colspan="6" align="left" scope="row"class="tdshowall" >
                  &nbsp;
                  Statistics of <?=$linemembers["companyname"]; ?> Logos in All Portals </th>
              </tr>
               <tr>
                <th align="left" nowrap="nowrap" class="tdsort1st" scope="row">Portal name</th>
                <td nowrap="nowrap" class="tdsort">First Impr. </td>
<td nowrap="nowrap" class="tdsort"><? $sumviews=0;?>
Impressions</td>
                <td nowrap="nowrap" class="tdsort"><? $totalnoofclicks=0;?>
Clicks</td>
                <td nowrap="nowrap" class="tdsort"><? $totalctr=0;?>
CTR</td>
              <td nowrap="nowrap" class="tdsort">

Current status </td>
</tr>
<? $countdomains=1;while($line=mysql_fetch_assoc($result)){?>              <tr onmouseover="this.className='classover'" onmouseout="this.className=''">
                <th class="tdsort1stPortal" scope="row"><a href="stat_analit.php?memberid=<?=$memberid;?>&domain_id=<?=$line[domain_id];?>&selection=<?=$selection;?>&r1=<?=$r1;?>&from_day=<?=$from_day;?>&from_month=<?=$from_month;?>&from_year=<?=$from_year;?>&to_day=<?=$to_day;?>&to_month=<?=$to_month;?>&to_year=<?=$to_year;?>&type=adv" class="tdsort1stPortal"><? $linedomain=mysql_fetch_array(mysql_query("SELECT domainname FROM domaincategories WHERE catdom_id=$line[domain_id]"));if($linedomain["domainname"]<>""){echo $linedomain["domainname"];}else{echo "Undefined";}?></a><? $array_logos["domain_id"][]=$line[domain_id];?></th>
                <td class="tdsortstats"><? if($line["MIN(added_on)"]<>""){echo format_datei($line["MIN(added_on)"]);}else{echo "N/A";}?><? $array_logos["first_impr"][]=$line["MIN(added_on)"];?></td>
<td class="tdsortstats"><? if($line["SUM(views)"]>0){
echo $line["SUM(views)"];
$sumviews=$sumviews+$line["SUM(views)"];?>
<? }else{
echo "0";
}
//}?>
<? $array_logos["Impres"][]=$line["SUM(views)"];?>
</td>
                <td class="tdsortstats"><? $queryclicks="SELECT advert_stats_id FROM adverts_stats_clicks WHERE domain_id=$line[domain_id] AND click_on = 'www' AND click_from!=''"; $resultadv=mysql_query($queryadv);
	$NoOfAdvs=mysql_num_rows($resultadv);
	if($NoOfAdvs>0){
$queryclicks .= " AND (";	
$i=1;
while($lineadv=mysql_fetch_assoc($resultadv)){
$queryclicks .= " advertisment_id = '$lineadv[advertisment_id]'";
if($i<$NoOfAdvs){ $queryclicks .= " OR ";}
$i++;
}
$queryclicks .= ")";
}
//advertisment_id = '$lineadv[advertisment_id]' AND";
			 $queryclicks .=$wherequery;
$resultclicks=mysql_query($queryclicks) or die (mysql_error());
echo $noofclicks=mysql_num_rows($resultclicks);
$totalnoofclicks=$totalnoofclicks+$noofclicks;
?><? $array_logos["Clicks"][]=$noofclicks;?></td>
                <td class="tdsortstats"><? if($noofclicks>0 && $line["SUM(views)"]>0){
echo $ctr=round($noofclicks/$line["SUM(views)"],3)*100;
$totalctr=$totalctr+$ctr/100;?><? }else{?>0<? }?>
%</td>
                <td class="tdsortactive"><?  if($line["domain_id"]==611){$active="yes";}else{
				$active="no"; reset($advert_ids);while (list($key, $advert_id) = each($advert_ids)) {
$queryactive = "SELECT * FROM advertisment WHERE active='yes' AND advertisment_id='$advert_id'";
						  $queryactive .=" AND";
			 // echo $domain_id;
	  		  $domain_idx2=sprintf("%04.0f", $line["domain_id"]);
		  $queryactive .=" (catdom_id LIKE '%$domain_idx2%'";
			$result_sub = mysql_query ("SELECT * FROM  domaincategories WHERE parent_id='$line[domain_id]'");
			if (mysql_num_rows($result_sub) <> 0){			  
					while($line_sub = mysql_fetch_array($result_sub)){ 
					  $domain_idx2=sprintf("%04.0f", $line_sub["catdom_id"]);
					  $queryactive .=" OR catdom_id LIKE '%$domain_idx2%'";
				}
				}
			  $queryactive .=")";
			//  echo $queryactive;
$resultactive=mysql_query($queryactive);
				 if(mysql_num_rows($resultactive)>0){
				 $active="yes";
				 }
}
}
				 if($active=="yes"){
?>
Active
<? }else{?>
<span class="tdsortinactive">Inactive</span>
<? }?><? $array_logos["Active"][]=$active;?></td>
</tr><? $countdomains++;}?>
              <tr>
                <th class="tdsort1stfooter" scope="row">Total - all <?=mysql_num_rows($result);?> Portal(s)</th>
                <td class="tdsortfooter">&nbsp;</td>
<td class="tdsortfooter"><? if($sumviews>0){echo $sumviews;}else{echo $sumviews=0;}?></td>
                <td class="tdsortfooter"><? if($totalnoofclicks>0){echo $totalnoofclicks;}else{echo $totalnoofclicks=0;}?></td>
                <td class="tdsortfooter"><span class="tdsortstats">
<? if($sumviews>0 && $totalnoofclicks>0){echo round($totalnoofclicks/$sumviews,3)*100;}else{?>0<? }?>
%</span></td>
              <td class="tdsortfooter">&nbsp;</td>
</tr>
            </table>
<? //}?>
<? }else{?>
No Logos are bound with this Customer.
<? }?><br />
            <br />
<br />
<table width="100%"  border="0" cellspacing="0" cellpadding="0">
<tr>
<td><strong class="red">Banners</strong>
<? $query="SELECT *, SUM(views), MIN(added_on) FROM banner_stats_views_maintained WHERE 1";
	$query .=$wherequery;
	$queryadv="SELECT * FROM banner WHERE member_id='$memberid'";
 $resultadv=mysql_query($queryadv);
	$NoOfAdvs=mysql_num_rows($resultadv);
	if($NoOfAdvs>0){
$query .= " AND (";	
$i=1;
while($lineadv=mysql_fetch_assoc($resultadv)){
$query .= " banner_id = '$lineadv[module_id]'";
$ban_ids[]=$lineadv[module_id];
if($i<$NoOfAdvs){ $query .= " OR ";}
$i++;
}
$query .= ")";
		$query .=" GROUP BY domain_id";
	$query .=" ORDER BY views DESC";
$result=mysql_query($query) or die (mysql_error());?> 



<? //$resultadv=mysql_query("SELECT * FROM banner WHERE member_id='$memberid'");
	//$NoOfAdvs=mysql_num_rows($resultadv);
	//if($NoOfAdvs>0){
	//while($lineadv=mysql_fetch_assoc($resultadv)){?>
<? //$query="SELECT *, SUM(views) FROM banner_stats_views_maintained WHERE banner_id = '$lineadv[module_id]'";
		//	$query .=$wherequery;
//$query .=" GROUP BY domain_id ORDER BY views DESC";
//$result=mysql_query($query) or die (mysql_error());?>
<hr size="1" noshade="noshade" />
 <table width="100%" border="1" cellpadding="3" cellspacing="0" bordercolor="#BEBEBE" class="tableresults">
 <tr>
<td colspan="6" class="tdshowall"><strong>
&nbsp; Statistics of
<?=$linemembers["companyname"]; ?> Banners in All Portals </strong></td>
</tr>
<tr bordercolor="#BEBEBE" class="tableresults">
<th align="left" nowrap="nowrap" class="tdsort1st" scope="row">Portal name</th>
<td nowrap="nowrap" class="tdsort">First Impr. </td>
<td align="left" nowrap="nowrap" class="tdsort"><? $sumviews=0;?>
Impressions</td>
<td nowrap="nowrap" class="tdsort"><? $totalnoofclicks=0;?>
Clicks</td>
<td nowrap="nowrap" class="tdsort"><? $totalctr=0;?>
CTR</td>
<td nowrap="nowrap" class="tdsort">

Current status </td>
</tr>
<? $countdomains=1;while($line=mysql_fetch_assoc($result)){?>
<tr>
<td  class="tdsort1stPortal" scope="row">
<a href="stat_analit.php?memberid=<?=$memberid;?>&domain_id=<?=$line[domain_id];?>&selection=<?=$selection;?>&r1=<?=$r1;?>&from_day=<?=$from_day;?>&from_month=<?=$from_month;?>&from_year=<?=$from_year;?>&to_day=<?=$to_day;?>&to_month=<?=$to_month;?>&to_year=<?=$to_year;?>&type=ban" class="tdsort1stPortal"><? $linedomain=mysql_fetch_array(mysql_query("SELECT domainname FROM domaincategories WHERE catdom_id=$line[domain_id]"));echo $linedomain["domainname"];?></a><?  $key = array_search($line["domain_id"], $array_logos["domain_id"]);if($key>-1){echo "ok";}else{$array_logos["domain_id"][]=$line[domain_id];}?></td>
<td class="tdsortstats"><? if($line["MIN(added_on)"]<>""){echo format_datei($line["MIN(added_on)"]);}else{echo "N/A";}?>
<? if($key>-1){
if(datediff($line["MIN(added_on)"], $array_logos["first_impr"][$key])>0){
echo $array_logos["first_impr"][$key]=$line["MIN(added_on)"];
}
}else{
$array_logos["first_impr"][]=$line["MIN(added_on)"];
}
?></td>
<td nowrap="nowrap" class="tdsortstats"><? 
if($line["SUM(views)"]>0){
echo $line["SUM(views)"];
$sumviews=$sumviews+$line["SUM(views)"];
}else{
echo "0";
}?><? if($key>-1){$array_logos["Impres"][$key]=$array_logos["Impres"][$key]+$line["SUM(views)"];}else{$array_logos["Impres"][]=$line["SUM(views)"];}?></td>
<td class="tdsortstats"><? $queryclicks="SELECT banner_stats_id FROM banner_stats_clicks WHERE domain_id=$line[domain_id] "; $resultadv=mysql_query($queryadv);
	$NoOfAdvs=mysql_num_rows($resultadv);
	if($NoOfAdvs>0){
$queryclicks .= " AND (";	
$i=1;
while($lineadv=mysql_fetch_assoc($resultadv)){
$queryclicks .= " banner_id = '$lineadv[module_id]'";
if($i<$NoOfAdvs){ $queryclicks .= " OR ";}
$i++;
}
$queryclicks .= ")";
}
//advertisment_id = '$lineadv[advertisment_id]' AND";
			 $queryclicks .=$wherequery;
			 		$queryclicks .=" AND location!=''";

$resultclicks=mysql_query($queryclicks) or die (mysql_error());
$noofclicks=mysql_num_rows($resultclicks);
if($noofclicks>0){
echo $noofclicks;
$totalnoofclicks=$totalnoofclicks+$noofclicks;
}else{
echo $noofclicks=0;
}
?><? if($key>-1){$array_logos["Clicks"][$key]=$array_logos["Clicks"][$key]+$noofclicks;}else{$array_logos["Clicks"][]=$noofclicks;}?>
</td>
<td class="tdsortstats"><? if($noofclicks>0 && $line["SUM(views)"]>0){
echo $ctr=round($noofclicks/$line["SUM(views)"],3)*100;
$totalctr=$totalctr+$ctr/100;}else{?>0<? }?>%
</td>
<td class="tdsortactive"><?  $active="no"; reset($ban_ids);while (list($keyban, $ban_id) = each($ban_ids)) {
 $queryactive = "SELECT * FROM left_content WHERE catdom_id='$line[domain_id]' AND (module_active='yes' OR (active_from <= NOW() AND active_to >= NOW())) AND module_id='$ban_id' AND type='banner'";
$resultactive=mysql_query($queryactive);?>
<? if(mysql_num_rows($resultactive)>0){
$active="yes";
}
}?>
<? if($active==="yes"){?>
Active
<? }else{?>
<span class="tdsortinactive">Inactive</span>
<? }?><? echo $key;if($key>-1){
if($active=="yes"){
echo $array_logos["Active"][$key]="yes";
}
}else{
echo $array_logos["Active"][]=$active;
}
?></td>
</tr>
<? $countdomains++;}?>
<tr>
<th class="tdsort1stfooter" scope="row">Total - all
<?=mysql_num_rows($result);?> Portal(s)</th>
<td nowrap="nowrap" class="tdsortfooter">&nbsp;</td>
<td nowrap="nowrap" class="tdsortfooter"><? if($sumviews>0){echo $sumviews;}else{echo $sumviews=0;}?></td>
<td class="tdsortfooter"><? if($totalnoofclicks>0){echo $totalnoofclicks;}else{echo $totalnoofclicks=0;}?></td>
<td class="tdsortfooter"><span class="tdsortstats">
<?  if($sumviews>0 && $totalnoofclicks>0){echo round($totalnoofclicks/$sumviews,3)*100;}else{?>0<? }?>
%</span></td>
<td class="tdsortfooter">&nbsp;</td>
</tr>
</table>
<? //}?>
<? }else{?>
: No banners are bound with this Customer.
<? }?></td>
</tr>
</table>-->
<? if(is_array($array_logos)){?><table width="100%" border="1" cellpadding="3" cellspacing="0" bordercolor="#BEBEBE" class="tableresults">
  <tr>
    <th colspan="6" align="left" scope="row"class="tdshowall" > &nbsp; Statistics
      of
        <?=$linemembers["companyname"]; ?>
       in All Portals </th>
  </tr>
  <tr>
    <th align="left" nowrap="nowrap" class="tdsort1st" scope="row">Portal name</th>
    <td nowrap="nowrap" class="tdsort">First Impr. </td>
    <td nowrap="nowrap" class="tdsort"><? $sumviews=0;?>
      Impressions</td>
    <td nowrap="nowrap" class="tdsort"><? $totalnoofclicks=0;?>
      Clicks</td>
    <td nowrap="nowrap" class="tdsort"><? $totalctr=0;?>
      CTR</td>
    <td nowrap="nowrap" class="tdsort"> Current status </td>
  </tr>
  <? $count=0;while (list($key, $val) = each($array_logos["domain_id"])){?>
  <tr onmouseover="this.className='classover'" onmouseout="this.className=''">
    <th class="tdsort1stPortal" scope="row"><? $domain_id=$array_logos[domain_id][$count]?><a href="stat_analit.php?domain_id=<?=$domain_id;?>&selection=<?=$selection;?>&r1=<?=$r1;?>&from_day=<?=$from_day;?>&from_month=<?=$from_month;?>&from_year=<?=$from_year;?>&to_day=<?=$to_day;?>&to_month=<?=$to_month;?>&to_year=<?=$to_year;?>" class="tdsort1stPortal">
      <? $resultdomain=mysql_query("SELECT domainname FROM domaincategories WHERE catdom_id='$domain_id'") or die (mysql_error());$linedomain=mysql_fetch_array($resultdomain);if($linedomain["domainname"]<>""){echo $linedomain["domainname"];}else{echo "Undefined";}?>
      </a>
        </th>
    <td class="tdsortstats"><?  if($array_logos[first_impr][$count]<>""){
	echo format_datei($array_logos[first_impr][$count]);}else{echo "N/A";}?></td>
    <td class="tdsortstats"><? $sumviews=$sumviews+$array_logos[Impres][$count];
	echo $array_logos[Impres][$count];?>
    </td>
    <td class="tdsortstats"><? $totalnoofclicks=$totalnoofclicks+$array_logos[Clicks][$count];
	echo $array_logos[Clicks][$count];?></td>
    <td class="tdsortstats"><? if($array_logos[Impres][$count]>0 && $array_logos[Clicks][$count]>0){
echo $ctr=round($array_logos[Clicks][$count]/$array_logos[Impres][$count]*100,1);
$totalctr=$totalctr+$ctr/100;?>
        <? }else{?>
        0
        <? }?>
      %</td>
    <td class="tdsortactive"><?				 if($array_logos[Active][$count]=="yes"){
?>
      Active
        <? }else{?>
        <span class="tdsortinactive">Inactive</span>
        <? }?>
        </td>
  </tr>
  <? $count++;}?>
  <tr>
    <th class="tdsort1stfooter" scope="row">Total - all
        <?=$count;?>
      Portal(s)</th>
    <td class="tdsortfooter">&nbsp;</td>
    <td class="tdsortfooter"><? if($sumviews>0){echo $sumviews;}else{echo $sumviews=0;}?></td>
    <td class="tdsortfooter"><? if($totalnoofclicks>0){echo $totalnoofclicks;}else{echo $totalnoofclicks=0;}?></td>
    <td class="tdsortfooter"><span class="tdsortstats">
      <? if($sumviews>0 && $totalnoofclicks>0){echo round($totalnoofclicks/$sumviews*100,1);}else{?>
      0
      <? }?>
      %</span></td>
    <td class="tdsortfooter">&nbsp;</td>
  </tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<th width="64%" align="left" class="tdfooter" scope="row">Reporting is not real-time. Clicks and impressions received in the last 24 hours may not be included</th>
<td width="36%" align="right" class="tdfooter"><img src="imgs/print.gif" width="18" height="17" /> <a href="javascript:window.print();" class="tdfooter">Print this report</a> </td>
</tr>
</table><? }else{?>Nothing is recorded during this period<? }?>
</body>
</html>
