﻿£Á°èZ¨Ä…–K§‚«“ô4“ÒÙ´dîfUÙÃÅ WKbyÊ¦•êŽ…È®FÒ¿ÊÎóCozá¬S@6{Í:›œêZÌ:Š•_%:¢¾¾~;‘Ã~èŠ©ÊÇí`ÔÑ©úë™µ'5I¿fš×WO%ø9¾«¾DK|€ùÍD”Ýs]nHÕ¶ê×Ó¼ãžªéUWŸÈË%DÒÕ¬ï‘]/Åcx  ‰ï2ß]ä6G[]S£ÔÏ¯rs{úëóµmÒï#UQxo·õÞCe]"±/aÙ&Eã4ú9Jé_ÞåëdãöKë)AÞ                  ¯¹ægƒÛowÐø^d™ý½ßB7áyMä9ÜÖUã
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
<html>
<?php 
//error_reporting(E_ERROR);
require_once "../include/user.inc.php";
require_once "../include/form.inc.php";
require_once "../include/video.inc.php";
require "checklogin.inc.php"; 
include '../header.inc.php';

class logDetail extends Form
{
	public $v;
	public $periodTime = 'All';
	public $eventType = 'open';
	public $dateStart = "";
	public $dateEnd = '';
	public $showRef = '0';
	public $searchOption = '0';
	
	public function logDetail()
	{
		global $user;
		
		$this->dateStart = date('Y-m-d',time());
		if(isset($_GET["v"]))
			$this->v = Video::LoadByCode($_GET["v"]);
		if (!isset($this->v) || $this->v===FALSE)
			$this->AddError("Sorry, video not found."); 
		
		else
		if ($this->v->userid != $user->id)
			$this->AddError("Access denied.");

		if (count($this->errors) != 0)
		{
			$k=0;
			foreach($this->errors as $er)
			{
				echo "<font color='red'><b>".$er[$k]."</b></font><br>";
				$k++;
			}
		include '../footer.inc.php';
			die;
		}
				
	}
	public function getData()
	{
		//echo mysql_num_rows($res);
		//for search key
		$query ='';
		if(isset($_POST['periodTime']) && $_POST['periodTime'] != 'All')
		{
			$this->periodTime = $_POST['periodTime'];
			switch($this->periodTime)
			{
				case "yesterday";
					$ptime = strtotime("-1 day");
					$this->showRef = '1';
					break;
					
				case "1week";
					$ptime = strtotime("-1 week");
					$this->showRef = '0';
					break;
					
				case "1month";
					$ptime = strtotime("-1 month");
					$this->showRef = '0';
					break;
										
				default:
					$ptime = strtotime("now");
					$this->showRef = '1';
					break;		
			}
			$ptime = date('Y-m-d',$ptime);
		}
		if(isset($_POST['vidIndex']) && @$_POST['vidIndex'] != '')
		{
			$Vstr = " AND videoIndex = '".$_POST['vidIndex']."'";
			$groupBy = ",videoIndex";
		}
		else if(isset($_POST['vidIndex2']) && @$_POST['vidIndex2'] != '')
		{
			$Vstr = " AND videoIndex = '".$_POST['vidIndex2']."'";
			$groupBy = ",videoIndex";
		}
		else { $Vstr = ''; }
		// query construction begin here
		$defaultQuery = "SELECT time as timeAll ,videoIndex, 
			(select avg(`timeSpent`) from stat_details where  event!='open' and time=a.time AND video_id=".$this->v->id." ".$Vstr." ) as avgTime,
			(select count(track_id) from stat_details where  isCompleted='Y' and time=a.time AND video_id=".$this->v->id." ".$Vstr."  ) as completed,
			(select count(track_id) from stat_details where  event='ping' and time=a.time  AND video_id=".$this->v->id." ".$Vstr."  ) as noOfTimesPing,
			(select count(track_id) from stat_details where  event='play' and time=a.time AND video_id=".$this->v->id." ".$Vstr."  ) as playEvent,
			(select count(DISTINCT(referrer)) from stat_details where  time=a.time AND video_id=".$this->v->id." ".$Vstr."  ) as referrerCount,
			(select count(track_id) from stat_details where event='open' and time=a.time AND video_id=".$this->v->id." ".$Vstr." ) as noOfTimesOpen from stat_details a where video_id = '".$this->v->id."' ".$Vstr;
			if(isset($_POST['dateStart']) && isset($_POST['dateEnd']))
			{
				$this->dateStart = @$_POST['dateStart'];
				$this->dateEnd = @$_POST['dateEnd'];
				$this->searchOption = '1';
				$query1 =$defaultQuery." and time >= '".$this->dateStart."' and time <= '".$this->dateEnd."' group by time";
			}
			else if(isset($_POST['periodTime']) || isset($_POST['eventType']))
			{
				$this->searchOption = '0';
				if($this->showRef == '1' && $_POST['periodTime'] != 'All')
				{
					$query1 = "select referrer as referrerCount, timeSpent as avgTime, event as playEvent,isCompleted as completed, time as timeAll,videoIndex from stat_details";
					$query1.= " where time = '$ptime' and video_id = '".$this->v->id."'".$Vstr;
				}
				else if($this->periodTime == "All")
				{
					$this->showRef = '0';
					$query1 =$defaultQuery." group by time";
				}
				else
				{
					$query1 =$defaultQuery." AND time >= '$ptime' AND time <= CURDATE() group by time";
				}			
			}
			else 
			{
				$query1 =$defaultQuery." group by time";
			}
		//echo $query1; die;
		//query end here
		//echo $query1;	
		$res = mysql_query($query1) or die(mysql_error());
		
		$knot = array();
		while($fn = mysql_fetch_array($res))
		{
			$innner = array();
			if($fn['avgTime'] > 60)
			{
				$mins = floor ($fn['avgTime'] / 60);
				$secs = $fn['avgTime'] % 60;
				if(strlen($secs) == 1)
				{
					$secs = "0".$secs;
				}
				$innner['avgTime'] = $mins.":".$secs;

			}
	
				else { $innner['avgTime'] = round($fn['avgTime']); }
			if($this->showRef == 0)
			{
				$innner['opens'] = $fn['noOfTimesOpen'];
			}
			$innner['plays'] = $fn['playEvent'];
			$innner['completed'] = $fn['completed'];
			$innner['referrer'] = $fn['referrerCount'];
			$innner['date'] = $fn['timeAll'];
			$innner['videoIndex'] = $fn['videoIndex'];
			array_push($knot,$innner);
		}
		return $knot;
	}

	function FillFromPost()
	{
		ObjectFromArray($this, $_POST);
		if ($this->v->VideoTracking == "Y")
			$this->stats = "true";
		else
			$this->stats = "false";
	}

	function Validate()
	{
		return TRUE;
	}

	function Save()
	{
	}
}				
$log = new logDetail();
	$log->FillFromPost();
	if ($log->Validate())
		$log->Save();
$mainData = $log->getData();
/*echo "<pre>";
print_r($mainData);*/
$sxml = simplexml_load_string($log->v->xml);
$videos = $sxml->playlist;
$dropD = array();
foreach($videos->children()  as $mXml)
	{
		$files =(array) $mXml->attributes();
		array_push($dropD,$files['@attributes']);
	}
?>
<link rel="stylesheet" href="<?=$SITE?>css/ui-lightness/jquery-ui-1.8.2.custom.css" type="text/css" />
<script type="text/javascript" src="<?php echo $SITE; ?>js/tablesorter/tablesorter.js"></script>
<script type="text/javascript" src="<?php echo $SITE; ?>js/tablesorter/tablesorter_pager.js"></script>
<script type="text/javascript" src="<?php echo $SITE; ?>js/tablesorter/tablesorter_min.js"></script>
<script type="text/javascript" src="<?php echo $SITE; ?>js/jquery-ui-1.8.2.custom.min.js"></script>
<script type="text/javascript" src="<?php echo $SITE; ?>js/jqueryBlockNew.js"></script>
<script type="text/javascript">
 jQuery(document).ajaxSend(function(){
			   jQuery("#loading").show();
			  });
			 
			 jQuery(document).ajaxComplete(function(){
			   jQuery("#loading").hide();
			 });
$(window).resize(function() { setOverlayPos(); });
function dateValidate()
{
	var tod=0;
	if($('#dateEnd').val() == '')
	{
		$('#errormsg').html('End Date field is required.');
		tod=1;
	}
	if($('#dateStart').val() == '')
	{
		$('#errormsg').html('Start Date field is required.');
		tod=1;
	}
	if(tod==1)
	{
		return false;
	}
	else
	{
		return true;
	}

}
function setOverlayPos()
		{
			// Get window sizes
			var winhgt = $(window).height();
			var winwth = $(window).width();

			var blockstyle = $('.blockPage').css("display");
			if(blockstyle == "block")
			{
				// Get Block sizes
				var overlayhgt = $('.blockPage').height();
				var overlaywth = $('.blockPage').width();
				if(overlayhgt != null && overlayhgt!="" && overlaywth != null && overlaywth!="")
				{
					// Get Document sizes
					var dochgt = 741; //$(document).height(); 
					var docwth = $(document).width(); 
					
					if(winhgt > dochgt)
					{
						var mytop = ((dochgt - overlayhgt) / 2);
						var myleft = ((docwth - overlaywth) / 2);
					}
					else
					{
						var mytop = ((winhgt - overlayhgt) / 2);
						var myleft = ((winwth - overlaywth) / 2);
					}
					
					$('.blockPage').css({
						top: mytop,
						left: myleft
					});
				}				
			}
		}
		
function getRefferelDetail(videoID,dateFor,wType)
{			
	<?php if(count($dropD) > 1) { ?>
	var Inde = $("#advanced").val();
	<?php } else { ?>
	var Inde = '';
	<?php } ?>

	var dataRef = ({ videoID:videoID,
					  dateFor:dateFor,
					  v:'<?php echo $log->v->code; ?>',
					  wtype:wType,
					  vidIndex: Inde
					});
	jQuery.ajax({ 
			url: "getRefferel.php",
			type: 'POST',
			data: dataRef,
			success: function(msg) {
				$('#referreShow').html(msg);
				$.blockUI({
				message: $('.artoon_layout_bg')
			});
			//set overlay position
			setOverlayPos();
			}
		});
}
function searchOption(str)
{
	if(str == "DF")
	{
		$('#dynamicOption').css('display','none');
		$('#manualOption').css('display','block');		
	}
	else
	{
		$('#dynamicOption').css('display','block');
		$('#manualOption').css('display','none');
	}
}

</script>
<style type="text/css">
.artoon_layout_bg {
	
	width:600px;
	min-height:70px;
	color: #fff;
	border: solid 3px #cccccc;
	margin:10px auto auto auto;
	background: #111;
	
	background: -webkit-gradient(linear, left top, left bottom, from(#111), to(#333));
	background: -moz-linear-gradient(top, #262626, #333333);
	background: -o-gradient(linear, left top, left bottom, from(#262626), to(#333333));
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#262626', endColorstr='#333333');
	
   -moz-border-radius:10px;
   -webkit-border-radius:10px;
   -o-border-radius:10px;
   -khtml-border-radius:10px;
    border-radius:10px;
	 
   -webkit-box-shadow:#122538 0px 0px 12px;
   -moz-box-shadow:#122538 0px 0px 12px;
   -o-box-shadow:#122538 0px 0px 12px;
   -ms-box-shadow:#122538 0px 0px 12px;
   -khtml-box-shadow:#122538 0px 0px 12px;
    box-shadow:#122538 0px 0px 12px;
  
}

.artoon_layout_bg_header{
	width:100%;
	min-height:50px;
	
	-moz-border-top-right-radius:10px;
	-webkit-border-top-right-radius:10px;
    -o-border-top-right-radius:10px;
    -khtml-border-top-right-radius:10px;
     border-top-right-radius:10px;
	 -moz-border-radius-topright:10px;
	 
	 -moz-border-top-left-radius:10px;
	-webkit-border-top-left-radius:10px;
    -o-border-top-left-radius:10px;
    -khtml-border-top-left-radius:10px;
     border-top-left-radius:10px;
	 -moz-border-radius-topleft:10px;

	
}
.artoon_layout_bg_content {
	width:100;
	-moz-border-radius:10px;
   -webkit-border-radius:10px;
   -o-border-radius:10px;
   -khtml-border-radius:10px;
    border-radius:10px;
	min-height:50px;
	
} 

</style>
<div style="position:absolute; right:20px; top:20px;"> 
 <a href="stat.php?v=<?php echo $log->v->code; ?>" title="goto Stat">Back</a>
 </div>
 
<h1 style="color:#67C5DD; text-decoration:underline;" align="left">Video stat details for : <?php echo $log->v->title; ?></h1>

<h3 align="left" style="margin-top:10px;">Search Criteria</h3>
<!--<div style="margin-top:10px;" align="left">
<input type="radio" name="sOption" value="DF" id="sOption" onchange="searchOption(this.value);" <?php //if($log->searchOption == 0) echo "checked"; else echo ""; ?>/> Search using default Options.
<input type="radio" name="sOption" value="DI" id="DInterval" onchange="searchOption(this.value);" <?php //if($log->searchOption == 1) echo "checked"; else echo ""; ?> /> Search using Date Interval Options.
</div>-->

<div style="margin-top:5px;" align="left">
<?php if(count($dropD) > 1) { ?>
<div align="left" style="position:relative; top:-5px; height:auto; ">Video Index : <select name="advanced" id="advanced" onchange="document.getElementById('vidIndex').value = this.value; document.getElementById('vidIndex2').value = this.value;">
<option value="" selected>All</option>
<?php foreach($dropD as $videoInd) {
	if($_POST['vidIndex'] == $videoInd['id']) {
	?>
    <option value="<?php echo $videoInd['id']; ?>" selected><?php echo $videoInd['title']; ?></option>
    <?php } else { ?>
      <option value="<?php echo $videoInd['id']; ?>" ><?php echo $videoInd['title']; ?></option>
<?php } } ?>
</select></div>
<?php } ?> <div style="color:red; margin:-20px 10px 10px 35%; display:block; height:25px;" id="errormsg" ></div>
<div style="height:80px;">
<div style="position:relative; float:left">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?v=<?php echo $log->v->code; ?>" method="post" name="optionalParam" id="manualOption" style="display:inline<?php //if($log->searchOption == 0) echo "block"; else echo "none"; ?>">
<select name="periodTime"  style="" onChange="document.optionalParam.submit();">
<option value="today" <?php if($log->periodTime == 'today') { echo "selected"; } ?>>Today</option>
<option value="yesterday" <?php if($log->periodTime == 'yesterday') { echo "selected"; } ?>>Yesterday</option>
<option value="1week" <?php if($log->periodTime == '1week') { echo "selected"; } ?>>Last Week</option>
<option value="1month" <?php if($log->periodTime == '1month') { echo "selected"; } ?>>Last Month</option>
<option value="All" <?php if($log->periodTime == 'All') { echo "selected"; } ?>>All</option>
</select> &nbsp; <b>OR</b>
<input type="hidden" name="vidIndex" id="vidIndex" value="<?php echo @$_POST['vidIndex']; ?>"  />
</form> 
</div>
<div style="float:left; position:relative;">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?v=<?php echo $log->v->code; ?>" name="getData" method="post" onSubmit="return dateValidate();"  >

<div  style="position:relative; margin-bottom:20px; margin-left:10px;">
Start  Date :&nbsp;&nbsp;&nbsp;&nbsp;
  <input type="text" name="dateStart" id="dateStart" />
 
&nbsp;&nbsp;End Date : &nbsp;<input type="text" name="dateEnd" id="dateEnd"  />
<input type="submit" name="logSubmit" id="logSubmit" value="SUBMIT" class="blackbtn" style="margin-left:17px;"/>
</div><input type="hidden" name="vidIndex2" id="vidIndex2" value="<?php echo @$_POST['vidIndex2']; ?>"  />
</form>
</div>
<div style="clear:both"></div>
</div>
<hr style="margin-bottom:10px; height:3px; background:#5A7BA6; border:none; border-radius:5px;" />
<h3>Result : <span id="resultFor"><?php if($log->searchOption == 0) { echo $log->periodTime; } else { echo  $log->dateStart." To ".$log->dateEnd; } ?></span></h3>


       <?php if(count($mainData) > 0) { ?>
      <table cellpadding="1" cellspacing="0" border="1" width="100%" id="log_list" class="tablesorter" bordercolor="#999999" style="text-align:center; color:#FFF;">
       <thead style="color:#B9B9B9; cursor:pointer; border:2px solid #999999" class="tableHeader"> 
		<tr>
         <!-- <th width="2%"><input type="checkbox" value="select" onclick="javascript:checkAll()" name="allbox" /></th>-->
          <th width="8%"><b>Id</b></th>
          <th width="8%"><b>Date</b></th>
          <th width="40%"><b>Referrer</b></th>
           <?php  if($log->showRef == 0)
				{ ?>
					<td><b>Opens</b></td>
				<?php } ?>
          <th width="10%"><b><?php if($log->showRef == 1) { echo "Spent Time"; } else { echo "Average Time"; } ?></b></th>
          <th width="10%"><b><?php if($log->showRef == 1) { echo "Event"; } else { echo "Plays"; } ?></b></th>
          <th width="8%" ><b><?php if($log->showRef == 1) { echo "Completed"; } else { echo "No. of completed."; } ?></b></th>
        </tr>
       </thead>
       <tbody> 
   
       <?php $i=1;  foreach($mainData as $md) { ?>
		<tr bgcolor="<?php if($i%2==1) { echo "#666"; } else echo "#333";?> ">
			  <td><?php echo $i; ?></td>
              <td><?php echo date('Y/m/d',strtotime($md['date'])); ?></td>
             <td>
			  <?php if(is_numeric($md['referrer']) && $log->showRef == 0) 
			 		{
						echo '<a href="javascript:getRefferelDetail(\''.$log->v->id.'\',\''.date('Y-m-d',strtotime($md['date'])).'\',\'referrel\')" style="color:#FFF">No. Of Referrers ( '.$md["referrer"].' )</a>';
					}
					else 
					{ 
						echo $md['referrer']; 
					}
			 ?></td>
			 <?php  if($log->showRef == 0)	{ ?>
			 	<td><?php 
					if($md['opens'] > 0)
					 {
						 echo '<a href="javascript:getRefferelDetail(\''.$log->v->id.'\',\''.date('Y-m-d',strtotime($md['date'])).'\',\'open\')" style="color:#FFF" >( '.$md["opens"].' )</a>';
					 }
					 else 
					 { 
					 	echo $md['opens']; 
					 } 
					 ?>
                </td>
        	 <?php } ?>
              <td><?php echo $md['avgTime']; ?></td>
			  <td><?php 
					 if($md['plays'] > 0)
					 {
						 echo '<a href="javascript:getRefferelDetail(\''.$log->v->id.'\',\''.date('Y-m-d',strtotime($md['date'])).'\',\'play\')" style="color:#FFF" >( '.$md["plays"].' )</a>';
					 }
					 else 
					 { 
					 	echo $md['plays']; 
					 } ?>
              </td>
              <td><?php 
			  if($log->showRef == 1) { if($md['plays'] == 'play') { echo $md['completed']; } else { echo "--"; } } 
			  else
			  { 
			   if($md['completed'] > 0)
					 {
						 echo '<a href="javascript:getRefferelDetail(\''.$log->v->id.'\',\''.date('Y-m-d',strtotime($md['date'])).'\',\'isCompleted\')" style="color:#FFF">( '.$md["completed"].' )</a>';
					 }
					 else 
					 { 
					 	echo $md['completed']; 
					 }
			  }?>
			 </td>
			  
		</tr>
     <?php $i++; } ?>
        </tbody>
		</table>
        <?php } else echo "No detail found for this video.";?>
      <input type="hidden" id="num"  value="20" name="hide" />		<!--Number of record to display-->
      <input type="hidden" id="start"  value="0" name="start" />

    </div>
     <?php if(count($mainData) > 0) { ?>
     <div id="pager" class="pager" style="margin-top:30px;">
        <form>
            <img src="<?php echo $SITE; ?>images/first.png" class="first"/>
            <img src="<?php echo $SITE; ?>images/prev.png" class="prev"/>
            <input type="text" class="pagedisplay"/>
            <img src="<?php echo $SITE; ?>images/next.png" class="next"/>
            <img src="<?php echo $SITE; ?>images/last.png" class="last"/>
            <select class="pagesize" id="pageValue">
                <option value="20">20 per page</option>
                <option value="30">30 per page</option>
                <option value="50">50 per page</option>
            </select>
        </form>
	</div>
   <?php } ?>
<div class="artoon_layout_bg" style="display:none;">
<div class="artoon_layout_bg_header" style="min-height:30px;">
<div style="float:right; margin:5px 15px 0 0"><a href="javascript:$.unblockUI();"><b style="color:red">X </b>Close</a></div>
</div>
<div class="artoon_layout_bg_content" id="referreShow"></div>
</div>

<script defer="defer">
	$(document).ready(function() 
		{ 
			$("#dateStart").datepicker({changeMonth: true,
			changeYear: true,showOn: 'button',buttonImageOnly: true,buttonImage: '<?php echo $SITE; ?>images/calendar.gif',showAnim: 'drop',dateFormat: 'yy-mm-dd'});
			$("#dateEnd").datepicker({changeMonth: true,
			changeYear: true,showOn: 'button',buttonImageOnly: true,buttonImage: '<?php echo $SITE; ?>images/calendar.gif',showAnim: 'drop',dateFormat: 'yy-mm-dd'});
			$('.ui-datepicker-trigger').css('margin','3px 0 0 3px');
			$('.ui-datepicker-trigger').attr('align','top'); 
			
			<?php if(count($mainData) > 0) { ?>
			$("#log_list")
			.tablesorter({widthFixed: true, widgets: ['zebra']})
			.tablesorterPager({container: $("#pager")}); 	//set size in tablesorter_pager file for default record to display on page load
			<?php } ?>
		} 
	); 
</script>
<div style="position:absolute; left: 45%; top: 45%; display:none;z-index-9999; " id="loading" ><img src="<?php echo $SITE;?>images/ajax-loader.gif" width="56" height="21" /></div>
<?php include '../footer.inc.php'; ?>