<?php

Class Template_v3 extends Template {
	function HTMLheadTag($headAddition = "") {
		global $conf, $baseurl, $profiles, $ourpath, $from, $to, $cm;
		if (method_exists($cm, 'testcookie')) {
			$cm->testcookie();
			$cm->testdashboard();
		}
		?>
		<!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>
				<title>Logaholic</title>
		        <meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
		        <?php
		        if(isset($baseurl) && ($baseurl)) { # Set in PDF on software.logaholic.com
		        	echo "<base href=\"{$baseurl}\">".PHP_EOL; 
		        }
		        ?>
		        <link rel="icon" href="favicon.ico" type="image/x-icon">
		        <link rel="shortcut icon" href="favicon.ico" type="image/x-icon">

		        <link href="components/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
		        <link rel="stylesheet" href="templates/logaholic_6/font-awesome-4.3.0/css/font-awesome.min.css">

		        <link href="templates/logaholic_6/css/jvectormap/jquery-jvectormap-1.2.2.css" rel="stylesheet" type="text/css" />
		        
		        <link href="templates/logaholic_6/css/daterangepicker/daterangepicker-bs3.css" rel="stylesheet" type="text/css" />
		        
		        <link href="templates/logaholic_6/css/datatables/dataTables.bootstrap.css" rel="stylesheet" type="text/css" />

		        <link type="text/css" rel="stylesheet" href="components/jquery/jqplot/jquery.jqplot.min.css" />

		        <link href="templates/logaholic_6/css/ionslider/ion.rangeSlider.css" rel="stylesheet" type="text/css" />
		        <link href="templates/logaholic_6/css/ionslider/ion.rangeSlider.skinHTML5.css" rel="stylesheet" type="text/css" />

		        <link href="templates/logaholic_6/css/AdminLTE.css" rel="stylesheet" type="text/css" />

		        <link href="templates/logaholic_6/css/reports.css" rel="stylesheet" type="text/css"  />
				<link href="components/d3.v3/nv.d3.css" rel="stylesheet" type="text/css"  />
				<link href="components/jquery/jqplot/jquery.jqplot.min.css" rel="stylesheet" type="text/css"  />
				<link href="templates/logaholic_6/css/print-overview.css" rel="stylesheet" type="text/css"  />
				<link href="templates/logaholic_6/css/print.css" rel="stylesheet" type="text/css" media="print" />
				<link href="components/leaflet-0.6.4/leaflet.css" rel="stylesheet" type="text/css"  />
		        
		        <link href="images/infographics/infograhic.css" rel="stylesheet" type="text/css" />

		        <link href="templates/logaholic_6/css/ui.css" rel="stylesheet" type="text/css" />
		        <link href="templates/logaholic_6/css/ui.responsive.css" rel="stylesheet" type="text/css" />

		        <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
		        <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
		        <!--[if lt IE 9]>
		          <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
		          <script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
		        <![endif]-->

		        <!-- JS resources -->        
		        <script src="components/jquery/js/jquery-1.11.3.min.js"></script>
		        
		        <script src="components/jquery/js/jquery-ui.min.js" type="text/javascript"></script>
		        <script src="components/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
		        
		        <script src="components/d3.v3/d3.min.js" type="text/javascript"></script>
		        <script src="components/d3.v3/nv.d3.js" type="text/javascript"></script>
		        <script src="components/leaflet-0.6.4/leaflet-src.js" type="text/javascript"></script>
		        
		        <!-- Sparkline -->
		        <script src="templates/logaholic_6/js/plugins/sparkline/jquery.sparkline.min.js" type="text/javascript"></script>
		        <!-- jvectormap -->

		        <script src="templates/logaholic_6/js/plugins/jvectormap/jquery-jvectormap-1.2.2.min.js" type="text/javascript"></script>
		        <script src="templates/logaholic_6/js/plugins/jvectormap/jquery-jvectormap-world-mill-en.js" type="text/javascript"></script>
		        

		        <!-- daterangepicker -->
		        <script src="templates/logaholic_6/js/plugins/daterangepicker/daterangepicker.js" type="text/javascript"></script>
		        
		        <!-- DATA TABES SCRIPT -->        
		        <script src="templates/logaholic_6/js/plugins/datatables/jquery.dataTables10.js" type="text/javascript"></script>        		       

		        <script>(function($){var d=$(document),h=$("head"),drag=null,tables=[],count=0,ID="id",PX="px",SIGNATURE="JColResizer",FLEX="JCLRFlex",I=parseInt,M=Math,ie=navigator.userAgent.indexOf('Trident/4.0')>0,S;try{S=sessionStorage}catch(e){}h.append("<style type='text/css'>  .JColResizer{table-layout:fixed;} .JColResizer td, .JColResizer th{overflow:hidden;padding-left:0!important; padding-right:0!important;}  .JCLRgrips{ height:0; position:relative;} .JCLRgrip{margin-left:-5px; position:absolute; z-index:5; } .JCLRgrip .JColResizer{position:absolute;background-color:red;filter:alpha(opacity=1);opacity:0;width:10px;height:100%;cursor: e-resize;top:0} .JCLRLastGrip{position:absolute; width:1px; } .JCLRgripDrag{ border-left:1px dotted black; } .JCLRFlex{width:auto!important;}</style>");var init=function(tb,options){var t=$(tb);t.opt=options;if(t.opt.disable)return destroy(t);var id=t.id=t.attr(ID)||SIGNATURE+ count++;t.p=t.opt.postbackSafe;if(!t.is("table")||tables[id]&&!t.opt.partialRefresh)return;t.addClass(SIGNATURE).attr(ID,id).before('<div class="JCLRgrips"/>');t.g=[];t.c=[];t.w=t.width();t.gc=t.prev();t.f=t.opt.fixed;if(options.marginLeft)t.gc.css("marginLeft",options.marginLeft);if(options.marginRight)t.gc.css("marginRight",options.marginRight);t.cs=I(ie?tb.cellSpacing||tb.currentStyle.borderSpacing:t.css('border-spacing'))||2;t.b=I(ie?tb.border||tb.currentStyle.borderLeftWidth:t.css('border-left-width'))||1;tables[id]=t;createGrips(t)},destroy=function(t){var id=t.attr(ID),t=tables[id];if(!t||!t.is("table"))return;t.removeClass(SIGNATURE+" "+FLEX).gc.remove();delete tables[id]},createGrips=function(t){var th=t.find(">thead>tr>th,>thead>tr>td");if(!th.length)th=t.find(">tbody>tr:first>th,>tr:first>th,>tbody>tr:first>td, >tr:first>td");th=th.filter(":visible");t.cg=t.find("col");t.ln=th.length;if(t.p&&S&&S[t.id])memento(t,th);th.each(function(i){var c=$(this),g=$(t.gc.append('<div class="JCLRgrip"></div>')[0].lastChild);g.append(t.opt.gripInnerHtml).append('<div class="'+SIGNATURE+'"></div>');if(i==t.ln-1){g.addClass("JCLRLastGrip");if(t.f)g.html("")}g.bind('touchstart mousedown',onGripMouseDown);g.t=t;g.i=i;g.c=c;c.w=c.width();t.g.push(g);t.c.push(c);c.width(c.w).removeAttr("width");g.data(SIGNATURE,{i:i,t:t.attr(ID),last:i==t.ln-1})});t.cg.removeAttr("width");syncGrips(t);t.find('td, th').not(th).not('table th, table td').each(function(){$(this).removeAttr('width')});if(!t.f)t.removeAttr('width').addClass(FLEX)},memento=function(t,th){var w,m=0,i=0,aux=[],tw;if(th){t.cg.removeAttr("width");if(t.opt.flush){S[t.id]="";return}w=S[t.id].split(";");tw=w[t.ln+1];if(!t.f&&tw)t.width(tw);for(;i<t.ln;i++){aux.push(100*w[i]/w[t.ln]+"%");th.eq(i).css("width",aux[i])}for(i=0;i<t.ln;i++)t.cg.eq(i).css("width",aux[i])}else{S[t.id]="";for(;i<t.c.length;i++){w=t.c[i].width();S[t.id]+=w+";";m+=w}S[t.id]+=m;if(!t.f)S[t.id]+=";"+t.width()}},syncGrips=function(t){t.gc.width(t.w);for(var i=0;i<t.ln;i++){var c=t.c[i];t.g[i].css({left:c.offset().left-t.offset().left+c.outerWidth(false)+t.cs/2+PX,height:t.opt.headerOnly?t.c[0].outerHeight(false):t.outerHeight(false)})}},syncCols=function(t,i,isOver){var inc=drag.x-drag.l,c=t.c[i],c2=t.c[i+1],w=c.w+inc,w2=c2.w-inc;c.width(w+PX);t.cg.eq(i).width(w+PX);if(t.f){c2.width(w2+PX);t.cg.eq(i+1).width(w2+PX)}if(isOver){c.w=w;c2.w=t.f?w2:c2.w}},applyBounds=function(t){var w=$.map(t.c,function(c){return c.width()});t.width(t.width()).removeClass(FLEX);$.each(t.c,function(i,c){c.width(w[i]).w=w[i]});t.addClass(FLEX)},onGripDrag=function(e){if(!drag)return;var t=drag.t,oe=e.originalEvent.touches,ox=oe?oe[0].pageX:e.pageX,x=ox-drag.ox+drag.l,mw=t.opt.minWidth,i=drag.i,l=t.cs*1.5+mw+t.b,last=i==t.ln-1,min=i?t.g[i-1].position().left+t.cs+mw:l,max=t.f?i==t.ln-1?t.w-l:t.g[i+1].position().left-t.cs-mw:Infinity;x=M.max(min,M.min(max,x));drag.x=x;drag.css("left",x+PX);if(last){var c=t.c[drag.i];drag.w=c.w+x-drag.l}if(t.opt.liveDrag){if(last){c.width(drag.w);t.w=t.width()}else syncCols(t,i);syncGrips(t);var cb=t.opt.onDrag;if(cb){e.currentTarget=t[0];cb(e)}}return false},onGripDragOver=function(e){d.unbind('touchend.'+SIGNATURE+' mouseup.'+SIGNATURE).unbind('touchmove.'+SIGNATURE+' mousemove.'+SIGNATURE);$("head :last-child").remove();if(!drag)return;drag.removeClass(drag.t.opt.draggingClass);var t=drag.t,cb=t.opt.onResize,i=drag.i,last=i==t.ln-1,c=t.g[i].c;if(last){c.width(drag.w);c.w=drag.w}else syncCols(t,i,true);if(!t.f)applyBounds(t);syncGrips(t);if(cb){e.currentTarget=t[0];cb(e)}if(t.p&&S)memento(t);drag=null},onGripMouseDown=function(e){var o=$(this).data(SIGNATURE),t=tables[o.t],g=t.g[o.i],oe=e.originalEvent.touches;g.ox=oe?oe[0].pageX:e.pageX;g.l=g.position().left;d.bind('touchmove.'+SIGNATURE+' mousemove.'+SIGNATURE,onGripDrag).bind('touchend.'+SIGNATURE+' mouseup.'+SIGNATURE,onGripDragOver);h.append("<style type='text/css'>*{cursor:"+t.opt.dragCursor+"!important}</style>");g.addClass(t.opt.draggingClass);drag=g;if(t.c[o.i].l)for(var i=0,c;i<t.ln;i++){c=t.c[i];c.l=false;c.w=c.width()}return false},onResize=function(){for(t in tables){var t=tables[t],i,mw=0;t.removeClass(SIGNATURE);if(t.f&&t.w!=t.width()){t.w=t.width();for(i=0;i<t.ln;i++)mw+=t.c[i].w;for(i=0;i<t.ln;i++)t.c[i].css("width",M.round(1e3*t.c[i].w/mw)/10+"%").l=true}syncGrips(t.addClass(SIGNATURE))}};$(window).bind('resize.'+SIGNATURE,onResize);$.fn.extend({colResizable:function(options){var defaults={draggingClass:'JCLRgripDrag',gripInnerHtml:'',liveDrag:false,fixed:true,minWidth:15,headerOnly:false,hoverCursor:"e-resize",dragCursor:"e-resize",postbackSafe:false,flush:false,marginLeft:null,marginRight:null,disable:false,partialRefresh:false,onDrag:null,onResize:null},options=$.extend(defaults,options);return this.each(function(){init(this,options)})}})})(jQuery)</script>
		        <!-- InputMask -->
		        <script src="templates/logaholic_6/js/plugins/input-mask/jquery.inputmask.js" type="text/javascript"></script>
		        <script src="templates/logaholic_6/js/plugins/input-mask/jquery.inputmask.date.extensions.js" type="text/javascript"></script>
		        <script src="templates/logaholic_6/js/plugins/input-mask/jquery.inputmask.extensions.js" type="text/javascript"></script>
		        

		        <script src="components/jquery/jqplot/jquery.jqplot.min.js" type="text/javascript"></script>
			    <script src="components/jquery/jqplot/plugins/jqplot.canvasTextRenderer.min.js" type="text/javascript"></script>
			    <script src="components/jquery/jqplot/plugins/jqplot.canvasAxisTickRenderer.min.js" type="text/javascript"></script>
			    <script src="components/jquery/jqplot/plugins/jqplot.canvasAxisLabelRenderer.min.js" type="text/javascript"></script>
			    <script src="components/jquery/jqplot/plugins/jqplot.dateAxisRenderer.min.js" type="text/javascript"></script>
			    <script src="components/jquery/jqplot/plugins/jqplot.barRenderer.min.js" type="text/javascript"></script>
			    <script src="components/jquery/jqplot/plugins/jqplot.categoryAxisRenderer.min.js" type="text/javascript"></script>
			    <script src="components/jquery/jqplot/plugins/jqplot.pieRenderer.min.js" type="text/javascript"></script>
			    <script src="components/jquery/jqplot/plugins/jqplot.donutRenderer.min.js" type="text/javascript"></script>
			   	<script src="components/jquery/jqplot/plugins/jqplot.trendline.min.js" type="text/javascript"></script>
			    <script src="components/jquery/jqplot/plugins/jqplot.meterGaugeRenderer.js" type="text/javascript"></script>
			    <script src="components/jquery/jqplot/plugins/jqplot.bubbleRenderer.min.js" type="text/javascript"></script>
			    <script src="components/jquery/jqplot/plugins/jqplot.cursor.min.js" type="text/javascript"></script>
			    <script src="components/jquery/jqplot/plugins/jqplot.highlighter.js" type="text/javascript"></script>
			    <script src="components/jquery/jqplot/plugins/jqplot.smoothFunnelRenderer.js" type="text/javascript"></script>
			    <script src="components/jquery/jqplot/plugins/jqplot.pointLabels.min.js" type="text/javascript"></script>

		        <script src="app/functions.js" type="text/javascript"></script>		
			</head>
		<?php
	}
	
	function BodyStart() {	
		echo '<body>'.PHP_EOL;
	}
		
	function ReturnURL() {
		global $profile;
		$pagename = substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);
		$return_address = 'http';
		if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") { $return_address .= "s"; }
			$return_address .= "://";
		if ($_SERVER["SERVER_PORT"] != "80") {
			$return_address .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
		} else {
			$return_address .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
		}
		$return_address = urlencode(str_replace($pagename . "?" . $_SERVER["QUERY_STRING"], "", $return_address));
		return $return_address;
	}
	
	function AffiliateID() {
		if (!isset($this->affiliate_id)) {			
			if(!isset($_SESSION["affiliate_id"])){
				$_SESSION["affiliate_id"] = getGlobalSetting('affiliate_id');
			}
			$this->affiliate_id = $_SESSION["affiliate_id"];
		}
		return $this->affiliate_id;	
	}
	
	function NoAccess($message="") {
		global $baseurl;
		if (empty($message)) {
			$message = _SORRY_NO_PERMISSIONS;
		}
		$content = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">".PHP_EOL;
		$content .= "<html xmlns=\"http://www.w3.org/1999/xhtml\">".PHP_EOL;
		$content .= "<head>".PHP_EOL;
		$content .= "	<meta name=\"ROBOTS\" content=\"NOINDEX, NOFOLLOW\" />".PHP_EOL;
		if(isset($baseurl) && ($baseurl)) { $content .= "<base href=\"{$baseurl}\">".PHP_EOL; }
		$content .= "	<title>".$message."</title>".PHP_EOL;		
		$content .= "	<link type=\"text/css\" rel=\"stylesheet\" href=\"templates/template_v3.css\" />".PHP_EOL;
		$content .= "	<link type=\"text/css\" rel=\"stylesheet\" href=\"components/jquery/css/lightness/jquery-ui-1.8.custom.css\" />".PHP_EOL;
		$content .= "</head>".PHP_EOL;
		$content .= "<body>".PHP_EOL;
		$content .= Notice($message,"width:400px;margin:0 auto;margin-top:20px").PHP_EOL;
		$content .= "</body>".PHP_EOL;
		$content .= "</html>".PHP_EOL;
		return $content;		
	}
	
}
?>