cman /pages/web-traffic.php

Language PHP Lines 724
MD5 Hash a0c0b4c30f763b0b1f243e8f6fd949ea Estimated Cost $800 (why?)
Repository https://bitbucket.org/14rego/cman.git View Raw File
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
<h1>Web Traffic</h1>
<script src="http://code.highcharts.com/highcharts.js" type="text/javascript"></script>
<script src="http://code.highcharts.com/modules/exporting.js" type="text/javascript"></script>
<script src="/resources/scripts/excanvas.min.js" type="text/javascript"></script>
<div id="holder-web-traffic2"></div>
<div id="holder-web-traffic"></div>
<br /><br />
<p>
<a id="button-search" class="notice" href="#update-data">Update</a> 
<a id="button-reset" class="notice" href="#reset-data">Reset</a> 
<a id="button-show" class="notice" href="#reset-data">Show Data Below</a>
<style>
ul li label { width: 90px; }
ul li select { min-width: 45px; }
</style>
<ul>
	<li>
		<label>VisiStat Key</label>
		<select id="filter-traffic-client" class="update-list">
			<option value="ALL">Encompassing</option>
			<option value="SSI">Softek</option>
			<option value="ILM">Illuminate</option>
			<option value="OTK">Ontrack</option>
		</select>
		<label>Data Type</label>
		<select id="filter-traffic-code" class="update-list">
			<option value="pv">Page Visits</option>
			<option value="uv">Unique Visitors</option>
			<option value="pp">Popular Pages</option>
			<optgroup label="Single Page Traffic" id="filter-select-single-page"><?php
				// SINGLE PAGE SELECT
				$apiYr = date('Y');
				$apiMo = sprintf('%02d', (date('m')-1)); 
				if ($apiMo==0) { $apiMo = 12; $apiYr = date('Y')-1; }
				$pages = file('http://api.visistat.com/stats-api.php?key=skW74P.TiTpIE&qt=pp&d=pipe&sdate='.$apiYr.'-'.$apiMo.'-01&edate='.date('Y').'-'.date('m').'-'.sprintf('%02d', (date('d'))));
				sort($pages);
				foreach ($pages as $pageData) {
					$page_name = explode("|",$pageData);
					
					if ((strpos($page_name[0],'gclid')) || (strpos($page_name[0],'https'))){
						// do nothing if there's a click ID attached or security
					} else {
						if ($page_name[0]=='Home Page') { $page_name[0] = '/index'; }
						echo '<option value="'.$page_name[0].'" title="';
						if (strpos($page_name[0],'illuminate/')) { echo 'ilm'; }
						else if (strpos($page_name[0],'ontrack/')) { echo 'otk'; }
						else { echo 'ssi'; }
						echo '">'.substr($page_name[0], 0, 56);
						if (strlen($page_name[0])>56) { echo '&hellip;'; }
						echo '</option>';
					}
					
				} ?>
			</optgroup>
		</select>
	</li>
	<li>
		<label>From</label>
		<select id="filter-traffic-s_mo" class="update-list">
			<?php for ($mo = 1; $mo < 13; $mo++) { echo '<option value="'.sprintf('%02d', $mo).'">'.date('F', mktime(0, 0, 0, $mo, 1, 2000)).'</option>'; } ?>
		</select>
		
		<select id="filter-traffic-s_dy" class="update-list">
			<?php for ($dy = 1; $dy < 32; $dy++) { echo '<option value="'.sprintf('%02d', $dy).'">'.$dy.'</option>'; } ?>
		</select>
		
		<select id="filter-traffic-s_yr" class="update-list">
			<?php $thisYear = date('Y'); for ($yr = 2009; $yr <= $thisYear; $yr++) { echo '<option value="'.$yr.'">'.$yr.'</option>'; } ?>
		</select>
		<label>To</label>
		<select id="filter-traffic-e_mo" class="update-list">
			<?php for ($mo = 1; $mo < 13; $mo++) { echo '<option value="'.sprintf('%02d', $mo).'">'.date('F', mktime(0, 0, 0, $mo, 1, 2000)).'</option>'; } ?>
		</select>
		
		<select id="filter-traffic-e_dy" class="update-list">
			<?php for ($dy = 1; $dy < 32; $dy++) { echo '<option value="'.sprintf('%02d', $dy).'">'.$dy.'</option>'; } ?>
		</select>
		
		<select id="filter-traffic-e_yr" class="update-list">
			<?php $thisYear = date('Y'); for ($yr = 2009; $yr <= $thisYear; $yr++) { echo '<option value="'.$yr.'">'.$yr.'</option>'; } ?>
		</select>
	</li>
	<li>
		<label>Chart Type</label>
		<select id="filter-traffic-type" class="update-list">
			<option value="line">Jagged Lines</option>
			<option value="spline">Smooth Lines</option>
			<option value="column">Columns</option>
			<option value="area">Area</option>
			<option value="bar">Bars</option>
		</select>
		<label>Labels</label>
		<select id="filter-traffic-show" class="update-list">
			<option value="yes">Yes</option>
			<option value="no">No</option>
		</select>, every: 
		<select id="filter-traffic-step" class="update-list">
			<option value="1">day</option>
			<option value="7">week</option>
			<option value="14">2 weeks</option>
			<option value="28">4 weeks</option>
		</select>
	</li>
</ul>
Showing more than a few months of data at a time can take a significant amount of time and could cause browser time-out errors.
</p>
<br /><br />
<h6 id="holder-web-data"></h6>

<script>
$.nextDay = function(year, month, day){
	var jMo = parseInt(month, 10)-1;
	var today = new Date(year, jMo, day);
	var tomorrow = new Date(today.getTime() + (24 * 60 * 60 * 1000));
	var nextDy = tomorrow.getDate(); 
	var nextMo = tomorrow.getMonth()+1; 
	var nextYr = tomorrow.getFullYear();
	if (nextDy<10) { nextDy = '0'+nextDy; }
	if (nextMo<10) { nextMo = '0'+nextMo; }
	var tomDate = parseInt(nextYr+''+nextMo+''+nextDy, 10);
	return tomDate;
};
$.buildGraph = function(code, type, data, starter, ender){
	// SET CLIENT TITLE
	var sClient = $('#filter-traffic-client').val();
	<?php $minus1 = $thisYear-1; $minus2 = $thisYear-2; $minus3 = $thisYear-3; ?>
	var labelOne = '<?php echo $minus3; ?>';
	var labelTwo = '<?php echo $minus2; ?>';
	var labelThree = '<?php echo $minus1; ?>';
	var labelFour = '<?php echo $thisYear; ?>';
	
		if (sClient==='OTK') { setCLIENT = 'OnTrack'; }
	else if (sClient==='ILM') { setCLIENT = 'Illuminate'; }
	else if (sClient==='SSI') { setCLIENT = 'Softek'; }
	else { 
		setCLIENT = 'All Sites'; 
		var labelOne = 'Illuminate'; var labelTwo = 'OnTrack'; var labelThree = 'Softek'; var labelFour = 'Encompassing';
	}
	// SET DATA TYPE
		if (code==='uv') { setTITLE = 'Unique Visitors'; }
	else if (code==='pp') { setTITLE = 'Popular Pages'; }
	else if (code==='seo') { setTITLE = 'Keywords'; }
	else { setTITLE = 'Page Views'; }
	// SET MONTHLY SUBTITLE
	var sMonthName = $('#filter-traffic-s_mo').val();
	var eMonthName = $('#filter-traffic-e_mo').val();
	var setSUBTITLE = $('#filter-traffic-s_mo option[value="'+sMonthName+'"]').text();
	if (sMonthName!=eMonthName) {
		setSUBTITLE = setSUBTITLE+' thru '+$('#filter-traffic-e_mo option[value="'+eMonthName+'"]').text();
	}
	// SET LABELS
	if ($('#filter-traffic-show').val()==='yes') { var showLABELS = true; } else { var showLABELS = false; }
	var numLABELS = $('#filter-traffic-step').val();
	// SPLIT DATA INTO SITES
	var parsedSITES = data.split('!!');
	// SPLIT DATA INTO DAYS
	var parsedDATA = [];
	for (s = 0; s < 4; s++) {
		parsedDATA[s] = [];
		parsedDATA[s].push(parsedSITES[s]);
		parsedDATA[s] = parsedDATA[s].toString().split('##');
		
		$.each(parsedDATA[s], function(index, value) {
			var showDATA = value.toString().split('|');
			if (showDATA[1]>0) {
				$('#holder-web-data').append(showDATA[0]+': '+showDATA[1]+'<br />');
			} else {
				$('#holder-web-data').append('<br />');
			}
		});
	}
	
	// SET DATE RANGE FOR THE TWO STRINGS
	var starterCATS = parseInt(starter, 10);
	// BUILD CATEGORY ARRAY OF DATES
	var arrCATS = [];
	while (starterCATS <= ender) {
		starterCATS = starterCATS.toString();
		var year = starterCATS.substr(0, 4);
		var month = starterCATS.substr(4, 2);
		var day = starterCATS.substr(6, 2);
		
		var pushingDate = ''+month+'-'+day+'';

		arrCATS.push(pushingDate);
		starterCATS = $.nextDay(year, month, day);
	}
	// BUILD VALUES, DISPLAYING 0 IF NO DATA
	var arrVALS = [];
	for (i = 0; i < 4; i++) {
		var dayCount = 1;
		arrVALS[i] = [];
		var starterVALS = starter;
		while (starterVALS <= ender) {
			starterVALS = starterVALS.toString();
			var year = starterVALS.substr(0, 4);
			var month = starterVALS.substr(4, 2);
			var day = starterVALS.substr(6, 2);
			var marker = month+'-'+day;
			
			var itemVALUE = [];
			itemVALUE[i] = [];
			itemVALUE[i].push(parsedDATA[i][dayCount]);
			itemVALUE[i] = itemVALUE[i].toString().split('|');
			
			var dataDay = itemVALUE[i][0].substr(5, 5).toString();
			
			if (dataDay===marker) {
				arrVALS[i].push(parseInt(itemVALUE[i][1], 10));
				dayCount++;
			} else {
				arrVALS[i].push(0);
			}
	
			starterVALS = $.nextDay(year, month, day);
		}
	}
	
	
	var chart = new Highcharts.Chart({
		chart: {
			renderTo: 'holder-web-traffic',
			defaultSeriesType: type,
			margin: [60, 10, 70, 80]
		},
		colors: [
			'#0022CC', 
			'#EE8800',
			'#0099EE', 
			'#AABBBB'
		],
		title: { 
			text: setCLIENT+' '+setTITLE
		},
		subtitle: { 
			text: setSUBTITLE
		},
		xAxis: {
			categories: arrCATS,
			labels: {
				rotation: -90,
				align: 'center',
				step: numLABELS,
				enabled: showLABELS,
				y: 23,
				x: 3
			}
		},
		yAxis: {
			min: 0,
			title: { text: 'Each Day' },
			plotLines: [{
				value: 0,
				width: 1,
				color: '#808080'
			}]
		},
		series: [
			{
				name: labelOne,
				data: arrVALS[0],
				marker: { enabled: false }
			},
			{
				name: labelTwo,
				data: arrVALS[1],
				marker: { enabled: false }
			},
			{
				name: labelThree,
				data: arrVALS[2],
				marker: { enabled: false }
			},
			{
				name: labelFour,
				data: arrVALS[3],
				marker: { enabled: false }
			}
		],
		credits: { enabled: false },
		legend: {
			align: 'center',
			floating: false,
         		verticalAlign: 'bottom',
			borderWidth: 0,
			y: 10
		},
		tooltip: {
			formatter: function() {
				return '<b>'+ this.x +'</b><br />'+
				this.series.name +': '+ this.y;
			}
		}
	});
	
};
$.buildSingle = function(type, data, starter, ender){
	
	// SET CLIENT TITLE
	var sClient = $('#filter-traffic-client').val();
	<?php $minus1 = $thisYear-1; $minus2 = $thisYear-2; $minus3 = $thisYear-3; ?>
	var labelOne = '<?php echo $minus3; ?>';
	var labelTwo = '<?php echo $minus2; ?>';
	var labelThree = '<?php echo $minus1; ?>';
	var labelFour = '<?php echo $thisYear; ?>';
	
		if (sClient==='OTK') { setCLIENT = 'OnTrack'; }
	else if (sClient==='ILM') { setCLIENT = 'Illuminate'; }
	else if (sClient==='SSI') { setCLIENT = 'Softek'; }

	var setTITLE = setCLIENT+' Page Detail';
	
	// SET MONTHLY SUBTITLE
	var sMonthName = $('#filter-traffic-s_mo').val();
	var eMonthName = $('#filter-traffic-e_mo').val();
	var setSUBTITLE = $('#filter-traffic-s_mo option[value="'+sMonthName+'"]').text();
	if (sMonthName!=eMonthName) {
		setSUBTITLE = setSUBTITLE+' thru '+$('#filter-traffic-e_mo option[value="'+eMonthName+'"]').text();
	}
	// SET LABELS
	if ($('#filter-traffic-show').val()==='yes') { var showLABELS = true; } else { var showLABELS = false; }
	var numLABELS = $('#filter-traffic-step').val();

	// Build the dates in the date range into arrCATS
	// BUILD CATEGORY ARRAY OF DATES
	var arrCATS = [];

	// BUILD ARRAYS TO PUSH VALUES
	var valViews = [];
	var valUnique = [];
	var valBounce = [];
	var valEntry = [];
	var valExit = [];
	
	// Split the data by day
	var dataDay = data.split('##');

	// SET DATE RANGE FOR THE TWO STRINGS
	var dayIndex = dataDay.length - 1; // skip 0 and 1
	var starterCATS = starter;
	while (starterCATS <= ender) {
		starterCATS = starterCATS.toString();
		var year = starterCATS.substr(0, 4);
		var month = starterCATS.substr(4, 2);
		var day = starterCATS.substr(6, 2);
		
		var marker = ''+month+'-'+day+'';
		arrCATS.push(marker);
		
		// each set of values
		var valAll	= dataDay[dayIndex].split('|');		// split all values
		var valDay	= valAll[0].substr(5, 5).toString();	// date with hyphen
		
		if (valDay===marker) {
			valViews.push(parseInt(valAll[1], 10));	// Page views
			valUnique.push(parseInt(valAll[2], 10));	// Unique visitors
			valBounce.push(parseInt(valAll[3], 10));	// Bounces
			valEntry.push(parseInt(valAll[4], 10));	// Entries
			valExit.push(parseInt(valAll[5], 10));	// Exits
			dayIndex--;
		} else {
			valViews.push(0);			// Page views
			valUnique.push(0);			// Unique visitors
			valBounce.push(0);			// Bounces
			valEntry.push(0);			// Entries
			valExit.push(0);			// Exits
		}
		
		starterCATS = $.nextDay(year, month, day);
	}
	// DISPLAY THE DATA IN THE HIDDEN DIV
	$('#holder-web-data').append('<table><thead><tr><th>Date</th><th>Hits</th><th>Unique</th><th>Bounces</th><th>Entries</th><th>Exits</th></tr></thead><tbody></tbody></table>');
	$.each(dataDay, function(index, value) {
		var showDATA = value.toString().split('|');
		if (showDATA[1]>0) {
			$('#holder-web-data tbody').append('<tr><td>'+showDATA[0]+'</td><td>'+showDATA[1]+'</td><td>'+showDATA[2]+'</td><td>'+showDATA[3]+'</td><td>'+showDATA[4]+'</td><td>'+showDATA[5]+'</td></tr>');
		}
	});
	
	var chart = new Highcharts.Chart({
		chart: {
			renderTo: 'holder-web-traffic',
			defaultSeriesType: type,
			margin: [60, 10, 70, 80]
		},
		colors: [
			'#0022CC', 
			'#EE8800',
			'#0099EE', 
			'#AABBBB'
		],
		title: { 
			text: setTITLE
		},
		subtitle: { 
			text: setSUBTITLE
		},
		xAxis: {
			categories: arrCATS,
			labels: {
				rotation: -90,
				align: 'center',
				step: numLABELS,
				enabled: showLABELS,
				y: 23,
				x: 3
			}
		},
		yAxis: {
			min: 0,
			title: { text: 'Each Day' },
			plotLines: [{
				value: 0,
				width: 1,
				color: '#808080'
			}]
		},
		series: [
			{
				name: 'Page Views',
				data: valViews,
				marker: { enabled: false }
			},
			{
				name: 'Unique Visitors',
				data: valUnique,
				marker: { enabled: false }
			},
			{
				name: 'Bounces',
				data: valBounce,
				marker: { enabled: false }
			},
			{
				name: 'Entries',
				data: valEntry,
				marker: { enabled: false }
			},
			{
				name: 'Exits',
				data: valExit,
				marker: { enabled: false }
			}
		],
		credits: { enabled: false },
		legend: {
			align: 'center',
			floating: false,
         		verticalAlign: 'bottom',
			borderWidth: 0,
			y: 10
		},
		tooltip: {
			formatter: function() {
				return '<b>'+ this.x +'</b><br />'+
				this.series.name +': '+ this.y;
			}
		},
		plotOptions: {
                spline: {
                    marker: {
                        enable: false
                    }
                }
          }
	});

};
$.buildPopular = function(type, data, starter, ender){
	
	// SET MONTHLY SUBTITLE
	var sMonthName = $('#filter-traffic-s_mo').val();
	var eMonthName = $('#filter-traffic-e_mo').val();
	var setSUBTITLE = $('#filter-traffic-s_mo option[value="'+sMonthName+'"]').text();
	if (sMonthName!=eMonthName) {
		setSUBTITLE = setSUBTITLE+' thru '+$('#filter-traffic-e_mo option[value="'+eMonthName+'"]').text();
	}
	// SET LABELS
	if ($('#filter-traffic-show').val()==='yes') { var showLABELS = true; } else { var showLABELS = false; }
	var numLABELS = $('#filter-traffic-step').val();
	
	// SPLIT INTO DIRECTORIES
	var eachDir = data.split('!!');

	var sClient = $('#filter-traffic-client').val();
		if (sClient==='OTK')	{ var setCLIENT = 'OnTrack '; var dirDATA = eachDir[1]; }
	else if (sClient==='ILM')	{ var setCLIENT = 'Illuminate '; var dirDATA = eachDir[0]; }
	else if (sClient==='SSI')	{ var setCLIENT = 'Softek '; var dirDATA = eachDir[2]; }
	else 					{ var setCLIENT = ''; var dirDATA = eachDir[3]; }

	var setTITLE = setCLIENT+' Popular Pages';

	// SPLIT INTO PAGES
	var pageDATA = dirDATA.split('##');
	var pgNAMES = [];
	var pgVIEWS = [];
	var pgUNIQUE = [];
	$.each(pageDATA, function(index, value) {
		if (index>=1 && index<=25) {
			var pgDATA = value.split('|'); // SPLIT INTO VALUES
			if (pgDATA[0].length > 25) { pgDATA[0] = pgDATA[0].substr(0, 25)+'...'; }
			pgNAMES.push(pgDATA[0]);
			pgVIEWS.push(parseInt(pgDATA[1], 10));
			pgUNIQUE.push(parseInt(pgDATA[2], 10));
		}
	});
	
	$('#holder-web-data').append('<table><thead><tr><th>Page</th><th>Hits</th><th>Unique</th></tr></thead><tbody></tbody></table>');
	$.each(pageDATA, function(index, value) {
		var showDATA = value.toString().split('|');
		if (showDATA[1]>0) {
			$('#holder-web-data tbody').append('<tr><td>'+showDATA[0]+'</td><td>'+showDATA[1]+'</td><td>'+showDATA[2]+'</td></tr>');
		}
	});
	
	var chart = new Highcharts.Chart({
		chart: {
			renderTo: 'holder-web-traffic',
			defaultSeriesType: type,
			margin: [55, 10, 160, 80]
		},
		colors: [
			'#0099EE', 
			'#0022CC'
		],
		title: { 
			text: setCLIENT+' '+setTITLE
		},
		subtitle: { 
			text: setSUBTITLE
		},
		xAxis: {
			categories: pgNAMES,
			labels: {
				rotation: -90,
				align: 'right',
				step: numLABELS,
				enabled: showLABELS,
				y: 6,
				x: 3
			}
		},
		yAxis: {
			min: 0,
			title: { text: 'Each Day' },
			plotLines: [{
				value: 0,
				width: 1,
				color: '#808080'
			}]
		},
		series: [
			{
				name: 'Page Views',
				data: pgVIEWS,
				marker: { enabled: false }
			},
			{
				name: 'Unique Visitors',
				data: pgUNIQUE,
				marker: { enabled: false }
			}
		],
		credits: { enabled: false },
		legend: {
			align: 'center',
			floating: false,
         		verticalAlign: 'top',
			borderWidth: 0,
			y: 50
		},
		tooltip: {
			formatter: function() {
				return '<b>'+ this.x +'</b><br />'+
				this.series.name +': '+ this.y;
			}
		}
	});

};

$.resetTraffic = function(list, filter){
	$('body').addClass('loading');
	
	$('#holder-web-data').hide();
	
	$('#filter-traffic-client').val('ALL');
	$('#filter-traffic-code').val('pv');
	$('#filter-traffic-type').val('spline');

	var thisDate = new Date();
	thisDate.setDate(thisDate.getDate()-1); // UP TO YESTERDAY
	var nowDY = thisDate.getDate();
	var nowMO = thisDate.getMonth()+1; 
	var nowYR = thisDate.getFullYear();
	if (nowMO===1) {
		var lastYR = new Date().getFullYear()-1;
		var lastMO = 12;
	} else {
		var lastYR = nowYR;
		var lastMO = new Date().getMonth();
	}
	if (nowDY<10) { nowDY = '0'+nowDY; }
	if (nowMO<10) { nowMO = '0'+nowMO; }
	if (lastMO<10) { lastMO = '0'+lastMO; }

	$('#filter-traffic-s_yr').val(lastYR);
	$('#filter-traffic-s_mo').val(lastMO);
	$('#filter-traffic-s_dy').val(01);
	
	$('#filter-traffic-e_yr').val(nowYR);
	$('#filter-traffic-e_mo').val(nowMO);
	$('#filter-traffic-e_dy').val(nowDY);
	
	$.updateTraffic();
	
};
$.updateTraffic = function(){
	$('#holder-web-data').html('');
	
	var setCLIENT	= $('#filter-traffic-client').val();
	var setCODE	= $('#filter-traffic-code').val();
	var setTYPE	= $('#filter-traffic-type').val();

	var setSYR	= $('#filter-traffic-s_yr').val();
	var setSMO	= $('#filter-traffic-s_mo').val();
	var setSDY	= $('#filter-traffic-s_dy').val();

	var setEYR	= $('#filter-traffic-e_yr').val();
	var setEMO	= $('#filter-traffic-e_mo').val();
	var setEDY	= $('#filter-traffic-e_dy').val();

	if (setCODE!=='uv' && setCODE!=='pp' && setCODE!=='pv' && setCODE!=='seo') { var setPAGE = setCODE; setCODE = 'ps'; }

	var nowDY = new Date().getDate()-1; 
	var nowMO = new Date().getMonth()+1; 
	var nowYR = new Date().getFullYear();
	if (nowDY<10) { nowDY = '0'+nowDY; }
	if (nowMO<10) { nowMO = '0'+nowMO; }
	var today = parseInt(nowYR+''+nowMO+''+nowDY, 10);

	var starter = parseInt(setSYR+''+setSMO+''+setSDY, 10);
	
	if (
		(setCLIENT=='ALL' && setCODE!=='pp')
		|| setCODE==='ps'
		|| setCODE==='pp'
	) { 
			$('#filter-traffic-s_yr').show();
			$('#filter-traffic-e_yr').show();
			var ender = setEYR+''+setEMO+''+setEDY;
	} else {
		$('#filter-traffic-s_yr').hide();
		$('#filter-traffic-e_yr').hide().val($('#filter-traffic-s_yr').val());
		var ender = setSYR+''+setEMO+''+setEDY;
	}
	
	if (ender>today) {
		ender = today;
		$('#filter-traffic-e_yr').val(nowYR);
		$('#filter-traffic-e_mo').val(nowMO);
		$('#filter-traffic-e_dy').val(nowDY);
		var setEYR = nowYR;
		var setEMO = nowMO;
		var setEDY = nowDY;
		
		$.sendMsg('Date Error', 'You cannot pull data from the future.');
	}


	if (starter>ender) {
		$.sendMsg('Date Error', 'The start date cannot be after the end date.');
	} else {
		var serialData = 'site='+setCLIENT+'&code='+setCODE+'&s_yr='+setSYR+'&s_mo='+setSMO+'&s_dy='+setSDY+'&e_yr='+setEYR+'&e_mo='+setEMO+'&e_dy='+setEDY;
		if (setCODE==='ps') { serialData = serialData +'&pg='+setPAGE; }
		$.get('/manage/rows/web-traffic-feed.php', serialData)
			.success(function(data) {
				if (setCODE==='ps') { 
					$.buildSingle(setTYPE, data, starter, ender);
				} else if (setCODE==='pp') { 
					$.buildPopular(setTYPE, data, starter, ender);
				} else {
					$.buildGraph(setCODE, setTYPE, data, starter, ender);
				}
				$('body').delay(250).removeClass('loading');
			})
			.error(function(data) { $.sendMsg('error'); });
	}
};
$(function() {
	$.resetTraffic();
	
	$('#filter-traffic-code').change(function(e){
		var parentCODE = $('#filter-traffic-code option:selected').attr('title');

		if ( parentCODE==='ilm' ) {
			$('#filter-traffic-client').val('ILM');
		} else if ( parentCODE==='ssi' ) {
			$('#filter-traffic-client').val('SSI');
		} else if ( parentCODE==='otk' ) {
			$('#filter-traffic-client').val('OTK');
		}
	});
	 	
	$('.body').keyup( function (e){
		if (e.keyCode === 13) { // RETURN
			e.preventDefault(); 
			$.updateTraffic();
		}
	});
	$('#button-search').click(function(e){
		e.preventDefault();
		$.updateTraffic();
	});
	$('#button-reset').click(function(e){
		e.preventDefault();
		$.resetTraffic();
	});
	$('#button-show').click(function(e){
		e.preventDefault();
		$('#holder-web-data').toggle();
	});
});
</script>
Back to Top