<? session_start();
include("../../dbcon.php");
include("functions.php");
$decimal=1;?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://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>
<script language="JavaScript" type="text/JavaScript">
<!--
function NewWindow(mypage,myname,w,h,scroll){
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
settings =
'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
win = window.open(mypage,myname,settings)
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
//-->
</script>
</head>

<body>
<? $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);
?>
<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="http://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 align="left">
                <th height="25" colspan="4" bgcolor="#296891" scope="row"> </th>
            </tr>
            </table>
            <br />
<a href="index.php?PHPSESSID=<?=$PHPSESSID;?>&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;?>">&lt;&lt;back</a>           <? 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 />
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <th width="32%" align="left" scope="row"><strong class="tdheadername"><?=$linemembers["companyname"]; ?> 
<span class="tdheaderoverview">

</span></strong></th>
                <td width="68%" rowspan="2" align="right"><strong>Date <?=date("d M Y");?></strong>
                  <script language="JavaScript">
function enable_dates(){
form1.from_day.disabled=false;
form1.from_month.disabled=false;
form1.from_year.disabled=false;
form1.to_day.disabled=false;
form1.to_month.disabled=false;
form1.to_year.disabled=false;
form1.selection.disabled=true;
}
function enable_selection(){
form1.from_day.disabled=true;
form1.from_month.disabled=true;
form1.from_year.disabled=true;
form1.to_day.disabled=true;
form1.to_month.disabled=true;
form1.to_year.disabled=true;
form1.selection.disabled=false;
}
</script>
<form action="" method="get" enctype="multipart/form-data" 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>
<input name="domain_id" type="hidden" id="domain_id" value="<?=$domain_id;?>">
</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"><? $linedomain=mysql_fetch_array(mysql_query("SELECT domainname FROM domaincategories WHERE catdom_id='$domain_id'"));echo $linedomain["domainname"];?> Statistics </th>
              </tr>
<tr>
<th class="tdheaderoverview" scope="row">&nbsp;</th>
<td align="right">&nbsp;</td>
</tr>
            </table>
            <br />
<? $showipaddresses="no";?><? if($type<>"ban"){?><? //if(!isset($advertisment_id) && $advertisment_id<1){
$queryadvertisment = "SELECT * FROM advertisment WHERE member_id='$memberid'";
$resultadvertisment = mysql_query ($queryadvertisment);
//echo mysql_num_rows($resultadvertisment);
if(mysql_num_rows($resultadvertisment)>0){
while($lineadv=mysql_fetch_array($resultadvertisment)){

$query_report1="SELECT SUM(views), MIN(added_on) FROM adverts_stats_views_maintained WHERE advertisment_id=$lineadv[advertisment_id] AND domain_id='$domain_id'";
$query_report2=" GROUP BY view_from, ipfrom";
$show_query=$query_report1 . " AND view_from!=''" . $wherequery . $query_report2;
//echo $show_query;
$show_result=mysql_query($show_query) or die(mysql_error());
if(mysql_num_rows($show_result)>0){
//$result_report=mysql_query($query_report) or die(mysql_error());
//while ($line_report=mysql_fetch_array($result_report)){
//echo $line_report["SUM(views)"];
//}
?>            <table width="100%" border="1" cellpadding="3" cellspacing="0" bordercolor="#BEBEBE" class="tableresults">
              <tr>
                <th colspan="6" align="left" scope="row"class="tdshowall" >
&nbsp;Logo:
<?=$lineadv["short_title_en"];?>
<? $imageadvert="../../images/advertisments/$lineadv[advertisment]";if(file_exists($imageadvert) && is_file($imageadvert)){?> (<a href="<?=$path;?>images/advertisments/<?=$lineadv["advertisment"];?>" target="_blank">view logo</a>)
<? }?>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<? if($lineadv["website"]<>""){?>
Links to: <strong><a href="http://<?=$lineadv["website"];?>" target="_blank">
<?=$lineadv["website"];?>
</a></strong><? }?></th>
              </tr>
              <tr>
                <th align="left" nowrap="nowrap" class="tdsort1st" scope="row"><? $count_loc=0;?>Portal Section </th>
                <td nowrap="nowrap" class="tdsort">First Impres.</td>
<td nowrap="nowrap" class="tdsort"><? $total_impr=0;?>
Impressions</td>
                <td nowrap="nowrap" class="tdsort"><? $totalnoofclicks=0;?>
Clicks</td>
                <td nowrap="nowrap" class="tdsort"><? $totalctr=0;$CountTotalctr=0;?>
CTR</td>
                <td nowrap="nowrap" class="tdsort"><?  $queryactive1 = "SELECT * FROM advertisment WHERE advertisment_id='$lineadv[advertisment_id]'";
						  $queryactive=$queryactive1 . " AND active='yes' AND ";
			 // echo $domain_id;
	  		  $domain_idx2=sprintf("%04.0f", $domain_id);
		  $queryactive .=" (catdom_id LIKE '%$domain_idx2%'";
			$result_sub = mysql_query ("SELECT * FROM  domaincategories WHERE parent_id='$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);
?>
Current status </td>
              </tr>
            <? $query_report_home=$query_report1 . " AND (view_from='top' OR view_from='sel') AND (ipfrom='' OR ipfrom=0) ";
			 $query_report_home .=$wherequery;
			 $report_home=mysql_query($query_report_home);
			 
				$line_report_home = mysql_fetch_assoc($report_home); $query_categ = "SELECT * FROM domain_advertisment,advertisment WHERE ((domain_advertisment.active='yes' OR (domain_advertisment.active_from <= NOW() AND domain_advertisment.active_to >= NOW())) OR (domain_advertisment.category_top='yes' OR (domain_advertisment.category_top_from <= NOW() AND domain_advertisment.category_top_to >= NOW()))) AND advertisment.active='yes' AND domain_advertisment.advertisment_id=advertisment.advertisment_id";
				if($line_report_home["SUM(views)"]>0){?><tr onmouseover="this.className='classover'" onmouseout="this.className=''">
                <th class="tdsort1stPortal" scope="row"><? $count_loc++;?>Home
                    page</th>
                <td class="tdsortstats"><? if($line_report_home["MIN(added_on)"]<>""){echo format_datei($line_report_home["MIN(added_on)"]);}else{echo "N/A";}?></td>
<td class="tdsortstats"><?				$total_impr = $line_report_home["SUM(views)"];
				if($line_report_home["SUM(views)"]>0){echo $impr=$line_report_home["SUM(views)"];}else{echo $impr=0;}?></td>
                <td class="tdsortstats"><? $queryclicks="SELECT advert_stats_id FROM adverts_stats_clicks WHERE advertisment_id = '$lineadv[advertisment_id]' AND domain_id=$domain_id AND click_on = 'www' AND catdom_id=0 AND (click_from='sel' OR click_from='top') ";
			 $queryclicks .=$wherequery;
$resultclicks=mysql_query($queryclicks) or die (mysql_error());
echo $noofclicks=mysql_num_rows($resultclicks);
$totalnoofclicks=$totalnoofclicks+$noofclicks;
?></td>
                <td class="tdsortstats"><? if($impr>0){echo $ctr=round($noofclicks/$impr*100,$decimal);$totalctr=$totalctr+$ctr;$CountTotalctr++;}else{echo 0;}?> %</td>
                <td class="tdsortactive">
<?				$query_categhome = $query_categ ." AND advertisment.advertisment_id='$lineadv[advertisment_id]' AND domain_advertisment.catdom_id ='$domain_id' ";
				$result_categhome=mysql_query($query_categhome);
				//echo mysql_num_rows($result_categhome);
				 if(mysql_num_rows($resultactive)>0 && mysql_num_rows($result_categhome)>0){?>Active<? }else{?>
<span class="tdsortinactive">Inactive</span><? }?></td>
            </tr><? }?>
<? $querydomaincategories = "SELECT * FROM  domaincategories WHERE parent_id='$domain_id' ORDER BY order_seq ASC";
$resultdomaincategories = mysql_query ($querydomaincategories);
if (mysql_num_rows($resultdomaincategories) <> 0){?>
<? while($linedomaincategories = mysql_fetch_array($resultdomaincategories)){ 
$query_duration="SELECT SUM(days) FROM adver_prom_history WHERE advertisment_id='$lineadv[advertisment_id]' AND domain_id=$linedomaincategories[catdom_id]";
				$result_duration=mysql_query($query_duration) or die(mysql_error());
$line_duration=mysql_fetch_assoc($result_duration);
if($line_duration["SUM(days)"]>0){?>              <tr onmouseover="this.className='classover'" onmouseout="this.className=''">
                <th class="tdsort1stPortal" scope="row"><? $count_loc++;?><?=$linedomaincategories["title_el"]; ?></th>
                <td class="tdsortstats"><? $query_report_home=$query_report1 . " AND (view_from='top' OR view_from='sel') AND ipfrom='$linedomaincategories[catdom_id]'";
				 $query_report_home .=$wherequery;
			$line_report_home = mysql_fetch_assoc(mysql_query($query_report_home));?>
<? if($line_report_home["MIN(added_on)"]<>""){echo format_datei($line_report_home["MIN(added_on)"]);}else{echo "N/A";}?></td>
<td class="tdsortstats"><?				$total_impr = $total_impr + $line_report_home["SUM(views)"];
				if($line_report_home["SUM(views)"]>0){echo $impr=$line_report_home["SUM(views)"];}else{echo $impr=0;}?></td>
                <td class="tdsortstats"><? $queryclicks="SELECT advert_stats_id FROM adverts_stats_clicks WHERE advertisment_id = '$lineadv[advertisment_id]' AND domain_id=$domain_id AND click_on = 'www' AND (click_from='sel' OR click_from='top') AND catdom_id='$linedomaincategories[catdom_id]' ";
			  $queryclicks .=$wherequery;
$resultclicks=mysql_query($queryclicks) or die (mysql_error());
echo $noofclicks=mysql_num_rows($resultclicks);
$totalnoofclicks=$totalnoofclicks+$noofclicks;
?></td>
                <td class="tdsortstats"><? if($impr>0){echo $ctr=round($noofclicks/$impr*100,$decimal);$totalctr=$totalctr+$ctr;$CountTotalctr++;}else{echo 0;}?>
%</td>
                <td class="tdsortactive"><? $query_categtown = $query_categ ." AND advertisment.advertisment_id='$lineadv[advertisment_id]' AND domain_advertisment.catdom_id ='$linedomaincategories[catdom_id]' ";
				$result_categhome=mysql_query($query_categtown);
				//echo mysql_num_rows($result_categhome);
				 if(mysql_num_rows($resultactive)>0 && mysql_num_rows($result_categhome)>0){?>Active<? }else{?>
<span class="tdsortinactive">Inactive</span><? }?></td>
              </tr><? }}?><? }?>
              <? $query_report_home=$query_report1 . " AND view_from='s'";
			 $query_report_home .=$wherequery;
				$line_report_home = mysql_fetch_assoc(mysql_query($query_report_home));if($line_report_home["SUM(views)"]>0){?><tr onmouseover="this.className='classover'" onmouseout="this.className=''">
                <th class="tdsort1stPortal" scope="row"><? $count_loc++;?>Internal Search Result</th>
                <td class="tdsortstats">
<? if($line_report_home["MIN(added_on)"]<>""){echo format_datei($line_report_home["MIN(added_on)"]);}else{echo "N/A";}?></td>
<td class="tdsortstats"><?				$total_impr = $total_impr + $line_report_home["SUM(views)"];
				if($line_report_home["SUM(views)"]>0){echo $impr=$line_report_home["SUM(views)"];}else{echo $impr=0;}?></td>
                <td class="tdsortstats"><? $queryclicks="SELECT advert_stats_id FROM adverts_stats_clicks WHERE advertisment_id = '$lineadv[advertisment_id]' AND domain_id=$domain_id AND click_on = 'www' AND catdom_id=0 AND click_from='s' ";
			 $queryclicks .=$wherequery;
$resultclicks=mysql_query($queryclicks) or die (mysql_error());
echo $noofclicks=mysql_num_rows($resultclicks);
$totalnoofclicks=$totalnoofclicks+$noofclicks;
?></td>
                <td class="tdsortstats"><? if($impr>0){echo $ctr=round($noofclicks/$impr*100,$decimal);$totalctr=$totalctr+$ctr;$CountTotalctr++;}else{echo 0;}?>
%</td>
                <td class="tdsortactive">
<? $lineactive1=mysql_fetch_assoc(mysql_query($queryactive1));if($domain_id==611 && $lineactive1["active"]=='yes'){?>Active<? }elseif(mysql_num_rows($resultactive)>0){?>Active<? }else{?>
<span class="tdsortinactive">Inactive</span><? }?></td>
              </tr><? }?>
<tr onmouseover="this.className='classover'" onmouseout="this.className=''">
<th class="tdsort1stPortal" scope="row"><? $count_loc++;?>More Info Pop-Up / More Info Page</th>
<td class="tdsortstats"><? $query_report_home=$query_report1 . " AND (view_from='adv' OR  view_from='e')";
			 $query_report_home .=$wherequery;
				$line_report_home = mysql_fetch_assoc(mysql_query($query_report_home));?>
<? if($line_report_home["MIN(added_on)"]<>""){echo format_datei($line_report_home["MIN(added_on)"]);}else{echo "N/A";}?></td>
<td class="tdsortstats"><?				$total_impr = $total_impr + $line_report_home["SUM(views)"];
				if($line_report_home["SUM(views)"]>0){echo $impr=$line_report_home["SUM(views)"];}else{echo $impr=0;}?></td>
<td class="tdsortstats"><? $queryclicks="SELECT advert_stats_id FROM adverts_stats_clicks WHERE advertisment_id = '$lineadv[advertisment_id]' AND domain_id=$domain_id AND click_on = 'www' AND (click_from='adv' OR click_from='e')";
			 $queryclicks .=$wherequery;
$resultclicks=mysql_query($queryclicks) or die (mysql_error());
echo $noofclicks=mysql_num_rows($resultclicks);
$totalnoofclicks=$totalnoofclicks+$noofclicks;
?></td>
<td class="tdsortstats"><? if($impr>0){echo $ctr=round($noofclicks/$impr*100,$decimal);$totalctr=$totalctr+$ctr;$CountTotalctr++;}else{echo 0;}?>
%</td>
<td class="tdsortactive"><? if(mysql_num_rows($resultactive)>0){?>Active<? }else{?>
<span class="tdsortinactive">Inactive</span><? }?></td>
</tr>
              <tr>
                <th class="tdsort1stfooter" scope="row">Total - all <?=$count_loc;?> Section(s) </th>
                <td class="tdsortfooter">&nbsp;</td>
<td class="tdsortfooter"><?=$total_impr;?></td>
                <td class="tdsortfooter"><?=$totalnoofclicks;if($totalnoofclicks>0)$showipaddresses="yes";?></td>
                <td class="tdsortfooter"><? if($total_impr>0 && $totalnoofclicks>0){echo round(($totalnoofclicks/$total_impr)*100,$decimal);}else{echo 0;}?>%</td>
                <td class="tdsortfooter">&nbsp;</td>
              </tr>
            </table>
<br /><? }?>
<? }?>
<? }else{?>
No Advertisment found
<? }?><? }?>
<? //}elseif(isset($banner_id) && $banner_id>0){ ?>
<? if($type<>"adv"){?><br /><? //if(!isset($banner_id) && $banner_id<1){
$querybanner = "SELECT * FROM banner WHERE member_id='$memberid'";
$resultbanner = mysql_query ($querybanner);
//echo mysql_num_rows($resultbanner);
if(mysql_num_rows($resultbanner)>0){
while($lineadv=mysql_fetch_array($resultbanner)){
$query_report1="SELECT *,SUM(views), MIN(added_on) FROM banner_stats_views_maintained WHERE banner_id=$lineadv[module_id] AND domain_id='$domain_id'";
$query_report2=" GROUP BY ipfrom";
$query_report=$query_report1 .$where_query .$wherequery .$query_report2;
$result_banner=mysql_query($query_report) or die(mysql_error());
$show_query=$query_report1 . $wherequery . $query_report2;
//echo $show_query;
$show_result=mysql_query($show_query) or die(mysql_error());
if(mysql_num_rows($show_result)>0){
//$result_report=mysql_query($query_report) or die(mysql_error());
//while ($line_report=mysql_fetch_array($result_report)){
//echo $line_report["SUM(views)"];
//}
?>
            <table width="100%" border="1" cellpadding="3" cellspacing="0" bordercolor="#BEBEBE" class="tableresults">
              <tr>
                <th colspan="6" align="left" scope="row"class="tdshowall" > &nbsp;<strong>
<?=$lineadv["title_en"];?>
</strong>
<? $imageadvert="../../images/banners/$lineadv[banner]";if(file_exists($imageadvert) && is_file($imageadvert)){?>
(<a href="<?=$path;?>images/banners/<?=$lineadv["banner"];?>" target="_blank">view banner</a>)
<? }?>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Links to: <a href="http://<?=$lineadv["url"];?>" target="_blank">
<?=$lineadv["url"];?>
</a></th>
              </tr>
              <tr>
<th align="left" nowrap="nowrap" class="tdsort1st" scope="row">Portal Section </th>
<td nowrap="nowrap" class="tdsort">First Impr. </td>
<td nowrap="nowrap" class="tdsort"><? $total_impr=0;?>
Impressions</td>
<td nowrap="nowrap" class="tdsort"><? $totalnoofclicks=0;?>
Clicks</td>
<td nowrap="nowrap" class="tdsort"><? $totalctr=0;$CountTotalctr=0;?>
CTR</td>
<td nowrap="nowrap" class="tdsort"><?  $queryactive = "SELECT * FROM left_content WHERE catdom_id='$domain_id' AND (module_active='yes' OR (active_from <= NOW() AND active_to >= NOW())) AND module_id='$lineadv[module_id]' AND type='banner'";
$resultactive=mysql_query($queryactive);?>
Current status </td>
</tr>
<? $count_loc=0;while($line_banner=mysql_fetch_assoc($result_banner)){?><tr onmouseover="this.className='classover'" onmouseout="this.className=''">
<th class="tdsort1stPortal" scope="row">All Pages -
<? //$query_content = "SELECT * FROM left_content WHERE catdom_id='$domain_id' AND (module_active='yes' OR (active_from <= NOW() AND active_to >= NOW())) AND module_id='$lineadv[module_id]' AND type='banner'";
//$result_content=mysql_query($query_content);
//$line_content=mysql_fetch_assoc($result_content);
switch ($line_banner["ipfrom"]){
case "left":
echo "Left Column";
break;
case "right":
echo "Right Column";
break;
case "middle":
echo "Middle Column";
break;
}
?></th>
<td class="tdsortstats"><? if($line_banner["MIN(added_on)"]<>""){echo format_datei($line_banner["MIN(added_on)"]);}else{echo "N/A";}?></td>
<td class="tdsortstats"><? //$query_report_home=$query_report1 . " AND (view_from='top' OR view_from='sel') AND ipfrom=''";
				//$result_report_home=mysql_query($query_report1 .$query_report2) or die(mysql_error());
			 //$query_report_home .=$wherequery;
				//$line_report_home = mysql_fetch_assoc($result_report_home);
				if($line_banner["SUM(views)"]>0){echo $impr=$line_banner["SUM(views)"];$total_impr=$total_impr+$impr;}else{echo $impr=0;}?></td>
<td class="tdsortstats"><? $queryclicks="SELECT banner_stats_id FROM banner_stats_clicks WHERE banner_id = '$line_banner[banner_id]' AND domain_id=$domain_id AND location='$line_banner[ipfrom]'";
			 $queryclicks .=$wherequery;
$resultclicks=mysql_query($queryclicks) or die (mysql_error());
echo $noofclicks=mysql_num_rows($resultclicks);
$totalnoofclicks=$totalnoofclicks+$noofclicks;
?></td>
<td class="tdsortstats"><? if($impr>0){echo $ctr=round($noofclicks/$impr*100,$decimal);$totalctr=$totalctr+$ctr;$CountTotalctr++;}else{echo 0;}?>
%</td>
<td class="tdsortactive"><?  $queryactive = "SELECT * FROM left_content WHERE catdom_id='$domain_id' AND (module_active='yes' OR (active_from <= NOW() AND active_to >= NOW())) AND module_id='$lineadv[module_id]' AND type='banner' AND location='$line_banner[ipfrom]'";
$resultactive=mysql_query($queryactive);?><? if(mysql_num_rows($resultactive)>0){?>
Active
<? }else{?>
<span class="tdsortinactive">Inactive</span>
<? }?></td>
</tr><? $count_loc++;}?>
<tr>
<th class="tdsort1stfooter" scope="row">Total - all <?=$count_loc;?> Section(s) </th>
<td class="tdsortfooter">&nbsp;</td>
<td class="tdsortfooter"><?=$total_impr;?></td>
<td class="tdsortfooter"><?=$totalnoofclicks;if($totalnoofclicks>0)$showipaddresses="yes";?></td>
<td class="tdsortfooter"><? if($total_impr>0 && $totalnoofclicks>0){echo round(($totalnoofclicks/$total_impr)*100,$decimal);}else{echo 0;}?>
%</td>
<td class="tdsortfooter">&nbsp;</td>
</tr>
            </table>            
            <br /><? }?><? }?>
<? }else{?>
No Banner found
<? }?><br />
            <? }?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<th width="67%" 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="33%" 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>
<br />
           <? if($showipaddresses=="yes"){?>
<table width="500" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td width="216"> <a href="account/my_stats.html?stats_step=pop-country-statistic&amp;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;?>&type=<?=$type;?>" onclick="NewWindow(this.href,'ipstats','500','400','yes');return false"><img src="imgs/buttons-countrystat.gif" width="202" height="46" border="0"  /></a></td>
                <td width="284"><a href="account/my_stats.html?stats_step=pop-ip&amp;memberid=<?=$memberid;?>&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;?>&type=<?=$type;?>" onclick="NewWindow(this.href,'ipstats','500','400','yes');return false"><img src="imgs/buttons-ipaddresses.gif" width="202" height="46" border="0"></a></td>
              </tr>
          </table><? }?>
<? }else{
echo "Please define either a member or an advertisment or a banner";
}
?>
</body>
</html>
