PageRenderTime 226ms CodeModel.GetById 133ms app.highlight 80ms RepoModel.GetById 1ms app.codeStats 1ms

/pages/social-report.php

https://bitbucket.org/14rego/cman
PHP | 882 lines | 828 code | 28 blank | 26 comment | 176 complexity | a485a67fb016c5efcc1dd3cb13c96e7e MD5 | raw file
  1<?php
  2if ($fromDate == '') { $fromDate = '20100101'; };
  3if ($toDate == '') { $toDate = '20200131'; };
  4$result = $sql->que("SELECT * FROM socnet_engage WHERE dat>='" .$fromDate. "' AND dat<='" .$toDate. "' ORDER BY dat ASC");
  5?>
  6<h1>Social Networking Data</h1>
  7<script src="http://code.highcharts.com/highcharts.js" type="text/javascript"></script>
  8<script src="http://code.highcharts.com/modules/exporting.js" type="text/javascript"></script>
  9<script src="/resources/scripts/excanvas.min.js" type="text/javascript"></script>
 10<div id="holder-social-data" style="height:550px;"></div>
 11<br /><br />
 12<p>
 13<a id="button-search" class="notice" href="#update-data">Update</a> 
 14<a id="button-reset" class="notice" href="#reset-data">Reset</a> 
 15<br /><br />
 16<select id="filter-select-code" class="update-list">
 17	<option value="connect">Connections</option>
 18	<option value="activity">Activity</option>
 19	<option value="distribution">Distribution</option>
 20</select> 
 21<select id="filter-select-sub" class="update-list">
 22	<option value="Post">Posts</option>
 23	<option value="Connection">Connections</option>
 24	<option value="Share">Sharing</option>
 25	<option value="Reply">Replies</option>
 26	<option value="Feedback">Feedback</option>
 27</select> 
 28<select id="filter-select-client" class="update-list">
 29	<option value="SSI">Softek</option>
 30	<option value="ILM">Illuminate</option>
 31	<option value="OTK">Ontrack</option>
 32</select> 
 33<select id="filter-select-site" class="update-list">
 34	<option value="Facebook">Facebook</option>
 35	<option value="Twitter">Twitter</option>
 36	<option value="LinkedIn">LinkedIn</option>
 37	<option value="Google+">Google+</option>
 38	<option value="Millennium Medic">Millennium Medic</option>
 39</select> 
 40<select id="filter-select-type" class="update-list">
 41	<option value="line">Jagged Lines</option>
 42	<option value="spline">Smooth Lines</option>
 43	<option value="column">Columns</option>
 44	<option value="area">Area</option>
 45	<option value="bar">Bars</option>
 46</select>
 47</p>
 48
 49<script>
 50$.buildGraph = function(code, type){
 51	// SET CLIENT TITLE
 52	var sSite = $('#filter-select-site').val(); 
 53	
 54	if (sSite === 'Millennium Medic') {
 55		$('#filter-select-client').val('OTK');
 56	} else if (sSite === 'Millennium Medic') {
 57		$('#filter-select-client').val('OTK');
 58	}
 59		
 60	var sClient = $('#filter-select-client').val(); 
 61	
 62		if (sClient==='OTK') { setCLIENT = 'OnTrack'; }
 63	else if (sClient==='ILM') { setCLIENT = 'Illuminate'; }
 64	else if (sClient==='SSI') { setCLIENT = 'Softek'; }
 65	else { 
 66		setCLIENT = 'All Sites'; 
 67	}
 68	
 69	var sSub = $('#filter-select-sub').val(); 
 70
 71	// SET DATA TYPE
 72	if (code==='connect') {
 73		<?php
 74			while ($row = pg_fetch_array($result)) {
 75				$mos = $mos."'".$row['dsc']."', ";
 76				$sFb = $sFb.$row['s_fb_conx'].", ";
 77				$iFb = $iFb.$row['i_fb_conx'].", ";
 78				$oFb = $oFb.$row['o_fb_conx'].", ";
 79				$sTw = $sTw.$row['s_tw_conx'].", ";
 80				$iTw = $iTw.$row['i_tw_conx'].", ";
 81				$oTw = $oTw.$row['o_tw_conx'].", ";
 82				$sLi = $sLi.$row['s_li_conx'].", ";
 83				$iGp = $iGp.$row['i_gp_conx'].", ";
 84				$oGp = $oGp.$row['o_gp_conx'].", ";
 85				$oMm = $oMm.$row['o_mm_conx'].", ";
 86			} pg_result_seek($result, 0);
 87		?>
 88		var setTITLE = 'Connections';
 89		var setSUBTITLE = 'each month';
 90		
 91		chart = new Highcharts.Chart({
 92			chart: {
 93				renderTo: 'holder-social-data',
 94				defaultSeriesType: type,
 95				margin: [60, 10, 95, 50]
 96			},
 97			colors: [
 98				'#0099EE', 
 99				'#0022CC', 
100				'#EE8800',
101				'#AABBBB',
102				'#FF6600', 
103				'#FFCC00',
104				'#445555', 
105				'#990000'
106			],
107			title: {
108				text: setTITLE,
109			},
110			subtitle: {
111				text: setSUBTITLE,
112			},
113			xAxis: {
114				categories: [
115					<?php echo substr($mos, 0, -2); ?>
116				],
117				labels: {
118					rotation: -90,
119					align: 'center',
120					y: 23,
121					x: 3
122				},
123				plotBands: [
124					{ 
125						from: 3,
126						to: 4,
127						color: 'rgba(68, 170, 213, .1)',
128						label: {
129							text: 'CHC Campaign',
130							align: "center",
131							verticalAlign: "bottom",
132							y: -8
133						}
134					},
135					{ 
136						from: 5,
137						to: 6,
138						color: 'rgba(68, 170, 213, .1)',
139						label: {
140							text: 'RSNA Campaign',
141							align: "center",
142							verticalAlign: "bottom",
143							y: -8
144						}
145					},
146					{ 
147						from: 8,
148						to: 9,
149						color: 'rgba(68, 170, 213, .1)',
150						label: {
151							text: 'HIMSS Campaign',
152							align: "center",
153							verticalAlign: "bottom",
154							y: -8
155						}
156					},
157					{ 
158						from: 16,
159						to: 17,
160						color: 'rgba(68, 170, 213, .1)',
161						label: {
162							text: 'CHC Campaign',
163							align: "center",
164							verticalAlign: "bottom",
165							y: -8
166						}
167					},
168					{ 
169						from: 18,
170						to: 19,
171						color: 'rgba(68, 170, 213, .1)',
172						label: {
173							text: 'RSNA Campaign',
174							align: "center",
175							verticalAlign: "bottom",
176							y: -8
177						}
178					},
179					{ 
180						from: 21,
181						to: 22,
182						color: 'rgba(68, 170, 213, .1)',
183						label: {
184							text: 'HIMSS Campaign',
185							align: "center",
186							verticalAlign: "bottom",
187							y: -8
188						}
189					}
190				],
191				plotLines: [{
192					value: 2.75,
193					width: 1,
194					color: '#808080',
195					label: {
196						text: 'Social Networking Push',
197						align: "center",
198						verticalAlign: "top",
199						y: 75
200					}
201				}]
202			},
203			yAxis: {
204				min: 0,
205				title: {
206					text: setTITLE
207				}
208			},
209			tooltip: {
210				formatter: function() {
211					return '<b>'+ this.series.name +'</b><br />'+
212					this.x +': '+ this.y +'';
213				}
214			},
215			credits: { enabled: false },
216			legend: {
217				align: 'center',
218				floating: false,
219				verticalAlign: 'bottom',
220				borderWidth: 0,
221				y: 10
222			},
223			plotOptions: {
224				spline: {
225					lineWidth: 2,
226					states: {
227						hover: {
228							lineWidth: 4
229						}
230					},
231					marker: {
232						enabled: false,
233						states: {
234							hover: {
235								enabled: true,
236								symbol: 'circle',
237								radius: 5,
238								lineWidth: 1
239							}
240						}   
241					},
242				}
243			},
244			series: [
245				{
246					name: 'SSI Facebook Friends',
247					data: [<?php echo substr($sFb, 0, -2); ?>]
248				},
249				{
250					name: 'ILM Facebook Page Likes',
251					data: [<?php echo substr($iFb, 0, -2); ?>]
252				},
253				{
254					name: 'OTK Facebook Page Likes',
255					data: [<?php echo substr($oFb, 0, -2); ?>]
256				},
257				{
258					name: 'SSI Twitter Followers',
259					data: [<?php echo substr($sTw, 0, -2); ?>]
260				},
261				{
262					name: 'ILM Twitter Followers',
263					data: [<?php echo substr($iTw, 0, -2); ?>]
264				},
265				{
266					name: 'OTK Twitter Followers',
267					data: [<?php echo substr($oTw, 0, -2); ?>]
268				},
269				{
270					name: 'LinkedIn Followers',
271					data: [<?php echo substr($sLi, 0, -2); ?>]
272				},
273				{
274					name: 'ILM Google+ Followers',
275					data: [<?php echo substr($iGp, 0, -2); ?>]
276				},
277				{
278					name: 'OTK Google+ Followers',
279					data: [<?php echo substr($oGp, 0, -2); ?>]
280				},
281				{
282					name: 'Mill. Medic Subscribers',
283					data: [<?php echo substr($oMm, 0, -2); ?>]
284				}
285			]
286		});
287		
288	} else if (code==='activity') {
289		var gConx = [];
290		var gPost = [];
291		var gReply = [];
292		var gChare = [];
293		var gLink = [];
294		// FACEBOOK
295		if (sSite=='Facebook') {
296			var tConx		= 'Page Likes / Friends';	
297			var tPost		= 'Posts';				
298			var tReply	= 'Comments or Likes';		
299			var tChare	= 'Shares';				
300			var tLink		= 'Links to Web';			
301			if (sClient=='ILM') {
302				<?php
303				while ($row = pg_fetch_array($result)) { echo 'gConx.push('.$row['i_fb_conx'].'); '; } pg_result_seek($result, 0);
304				while ($row = pg_fetch_array($result)) { echo 'gPost.push('.$row['i_fb_post'].'); '; } pg_result_seek($result, 0);
305				while ($row = pg_fetch_array($result)) { echo 'gReply.push('.$row['i_fb_reply'].'); '; } pg_result_seek($result, 0);
306				while ($row = pg_fetch_array($result)) { echo 'gChare.push('.$row['i_fb_chare'].'); '; } pg_result_seek($result, 0);
307				while ($row = pg_fetch_array($result)) { echo 'gLink.push('.$row['fb_link'].'); '; } pg_result_seek($result, 0); 
308				?>
309			} else if (sClient=='OTK') {
310				<?php
311				while ($row = pg_fetch_array($result)) { echo 'gConx.push('.$row['o_fb_conx'].'); '; } pg_result_seek($result, 0);
312				while ($row = pg_fetch_array($result)) { echo 'gPost.push('.$row['o_fb_post'].'); '; } pg_result_seek($result, 0);
313				while ($row = pg_fetch_array($result)) { echo 'gReply.push('.$row['o_fb_reply'].'); '; } pg_result_seek($result, 0);
314				while ($row = pg_fetch_array($result)) { echo 'gChare.push('.$row['o_fb_chare'].'); '; } pg_result_seek($result, 0);
315				while ($row = pg_fetch_array($result)) { echo 'gLink.push('.$row['fb_link'].'); '; } pg_result_seek($result, 0);
316				?>
317			} else {
318				<?php
319				while ($row = pg_fetch_array($result)) { echo 'gConx.push('.$row['s_fb_conx'].'); '; } pg_result_seek($result, 0);
320				while ($row = pg_fetch_array($result)) { echo 'gPost.push('.$row['s_fb_post'].'); '; } pg_result_seek($result, 0);
321				while ($row = pg_fetch_array($result)) { echo 'gReply.push('.$row['s_fb_reply'].'); '; } pg_result_seek($result, 0);
322				while ($row = pg_fetch_array($result)) { echo 'gChare.push('.$row['s_fb_chare'].'); '; } pg_result_seek($result, 0);
323				while ($row = pg_fetch_array($result)) { echo 'gLink.push('.$row['fb_link'].'); '; } pg_result_seek($result, 0);
324				?>
325			}
326		}
327		// TWITTER
328		else if (sSite=='Twitter') {
329			var tConx		= 'Followers';
330			var tPost		= 'Posts';
331			var tReply	= 'Mentions';
332			var tChare	= 'Re-tweets';
333			var tLink		= 'Links to Web';
334			if (sClient=='ILM') {
335				<?php
336				while ($row = pg_fetch_array($result)) { echo 'gConx.push('.$row['i_tw_conx'].'); '; } pg_result_seek($result, 0);
337				while ($row = pg_fetch_array($result)) { echo 'gPost.push('.$row['i_tw_post'].'); '; } pg_result_seek($result, 0);
338				while ($row = pg_fetch_array($result)) { echo 'gReply.push('.$row['i_tw_reply'].'); '; } pg_result_seek($result, 0);
339				while ($row = pg_fetch_array($result)) { echo 'gChare.push('.$row['i_tw_chare'].'); '; } pg_result_seek($result, 0);
340				while ($row = pg_fetch_array($result)) { echo 'gLink.push('.$row['tw_link'].'); '; } pg_result_seek($result, 0);
341				?>
342			} else if (sClient=='OTK') {
343				<?php
344				while ($row = pg_fetch_array($result)) { echo 'gConx.push('.$row['o_tw_conx'].'); '; } pg_result_seek($result, 0);
345				while ($row = pg_fetch_array($result)) { echo 'gPost.push('.$row['o_tw_post'].'); '; } pg_result_seek($result, 0);
346				while ($row = pg_fetch_array($result)) { echo 'gReply.push('.$row['o_tw_reply'].'); '; } pg_result_seek($result, 0);
347				while ($row = pg_fetch_array($result)) { echo 'gChare.push('.$row['o_tw_chare'].'); '; } pg_result_seek($result, 0);
348				while ($row = pg_fetch_array($result)) { echo 'gLink.push('.$row['tw_link'].'); '; } pg_result_seek($result, 0);
349				?>
350			} else {
351				<?php
352				while ($row = pg_fetch_array($result)) { echo 'gConx.push('.$row['s_tw_conx'].'); '; } pg_result_seek($result, 0);
353				while ($row = pg_fetch_array($result)) { echo 'gPost.push('.$row['s_tw_post'].'); '; } pg_result_seek($result, 0);
354				while ($row = pg_fetch_array($result)) { echo 'gReply.push('.$row['s_tw_reply'].'); '; } pg_result_seek($result, 0);
355				while ($row = pg_fetch_array($result)) { echo 'gChare.push('.$row['s_tw_chare'].'); '; } pg_result_seek($result, 0);
356				while ($row = pg_fetch_array($result)) { echo 'gLink.push('.$row['tw_link'].'); '; } pg_result_seek($result, 0);
357				?>
358			}
359		}
360		// LINKEDIN
361		else if (sSite=='LinkedIn') {
362			var tConx		= 'Followers';
363			var tPost		= 'Updates or Msgs Sent';
364			var tReply	= 'Comments or Replies';
365			var tChare	= 'Shares';
366			var tLink		= 'Links to Web';
367			if (sClient=='ILM') {
368				<?php
369				while ($row = pg_fetch_array($result)) { echo 'gConx.push('.$row['s_li_conx'].'); '; } pg_result_seek($result, 0);
370				while ($row = pg_fetch_array($result)) { echo 'gPost.push('.$row['i_li_post'].'); '; } pg_result_seek($result, 0);
371				while ($row = pg_fetch_array($result)) { echo 'gReply.push('.$row['i_li_reply'].'); '; } pg_result_seek($result, 0);
372				while ($row = pg_fetch_array($result)) { echo 'gChare.push('.$row['i_li_chare'].'); '; } pg_result_seek($result, 0);
373				while ($row = pg_fetch_array($result)) { echo 'gLink.push('.$row['li_link'].'); '; } pg_result_seek($result, 0);
374				?>
375			} else if (sClient=='OTK') {
376				<?php
377				while ($row = pg_fetch_array($result)) { echo 'gConx.push('.$row['s_li_conx'].'); '; } pg_result_seek($result, 0);
378				while ($row = pg_fetch_array($result)) { echo 'gPost.push('.$row['o_li_post'].'); '; } pg_result_seek($result, 0);
379				while ($row = pg_fetch_array($result)) { echo 'gReply.push('.$row['o_li_reply'].'); '; } pg_result_seek($result, 0);
380				while ($row = pg_fetch_array($result)) { echo 'gChare.push('.$row['o_li_chare'].'); '; } pg_result_seek($result, 0);
381				while ($row = pg_fetch_array($result)) { echo 'gLink.push('.$row['li_link'].'); '; } pg_result_seek($result, 0);
382				?>
383			} else {
384				<?php
385				while ($row = pg_fetch_array($result)) { echo 'gConx.push('.$row['s_li_conx'].'); '; } pg_result_seek($result, 0);
386				while ($row = pg_fetch_array($result)) { echo 'gPost.push('.$row['s_li_post'].'); '; } pg_result_seek($result, 0);
387				while ($row = pg_fetch_array($result)) { echo 'gReply.push('.$row['s_li_reply'].'); '; } pg_result_seek($result, 0);
388				while ($row = pg_fetch_array($result)) { echo 'gChare.push('.$row['s_li_chare'].'); '; } pg_result_seek($result, 0);
389				while ($row = pg_fetch_array($result)) { echo 'gLink.push('.$row['li_link'].'); '; } pg_result_seek($result, 0);
390				?>
391			}
392		}
393		// GOOGLE
394		else if (sSite=='Google+') {
395			var tConx		= 'Followers';
396			var tPost		= 'Updates';
397			var tReply	= 'Comments or +1s';
398			var tChare	= 'Shares';
399			var tLink		= 'Links to Web';
400			if (sClient=='ILM') {
401				<?php
402				while ($row = pg_fetch_array($result)) { echo 'gConx.push('.$row['i_gp_conx'].'); '; } pg_result_seek($result, 0);
403				while ($row = pg_fetch_array($result)) { echo 'gPost.push('.$row['i_gp_post'].'); '; } pg_result_seek($result, 0);
404				while ($row = pg_fetch_array($result)) { echo 'gReply.push('.$row['i_gp_reply'].'); '; } pg_result_seek($result, 0);
405				while ($row = pg_fetch_array($result)) { echo 'gChare.push('.$row['i_gp_chare'].'); '; } pg_result_seek($result, 0);
406				while ($row = pg_fetch_array($result)) { echo 'gLink.push('.$row['gp_link'].'); '; } pg_result_seek($result, 0);
407				?>
408			} else {
409				<?php
410				while ($row = pg_fetch_array($result)) { echo 'gConx.push('.$row['o_gp_conx'].'); '; } pg_result_seek($result, 0);
411				while ($row = pg_fetch_array($result)) { echo 'gPost.push('.$row['o_gp_post'].'); '; } pg_result_seek($result, 0);
412				while ($row = pg_fetch_array($result)) { echo 'gReply.push('.$row['o_gp_reply'].'); '; } pg_result_seek($result, 0);
413				while ($row = pg_fetch_array($result)) { echo 'gChare.push('.$row['o_gp_chare'].'); '; } pg_result_seek($result, 0);
414				while ($row = pg_fetch_array($result)) { echo 'gLink.push('.$row['gp_link'].'); '; } pg_result_seek($result, 0);
415				?>
416			}
417		}
418		// MEDIC
419		else if (sSite=='Millennium Medic') {
420			var tConx		= 'Subscribers';
421			var tPost		= 'Posts';
422			var tReply	= 'Comments';
423			var tChare	= 'Shares';
424			var tLink		= 'Links to Web';
425				<?php
426				while ($row = pg_fetch_array($result)) { echo 'gConx.push('.$row['o_mm_conx'].'); '; } pg_result_seek($result, 0);
427				while ($row = pg_fetch_array($result)) { echo 'gPost.push('.$row['o_mm_post'].'); '; } pg_result_seek($result, 0);
428				while ($row = pg_fetch_array($result)) { echo 'gReply.push('.$row['o_mm_reply'].'); '; } pg_result_seek($result, 0);
429				while ($row = pg_fetch_array($result)) { echo 'gChare.push('.$row['o_mm_chare'].'); '; } pg_result_seek($result, 0);
430				while ($row = pg_fetch_array($result)) { echo 'gLink.push('.$row['mm_link'].'); '; } pg_result_seek($result, 0);
431				?>
432		}
433		
434		var setTITLE = 'Profile Activity';
435		var setSUBTITLE = sClient+' '+sSite;
436		
437		chart = new Highcharts.Chart({
438			chart: {
439				renderTo: 'holder-social-data',
440				defaultSeriesType: type,
441				margin: [60, 10, 95, 50]
442			},
443			colors: [
444				'#0099EE', 
445				'#0022CC', 
446				'#EE8800',
447				'#AABBBB',
448				'#FF6600', 
449				'#FFCC00',
450				'#445555', 
451				'#990000'
452			],
453			title: {
454				text: setTITLE,
455			},
456			subtitle: {
457				text: setSUBTITLE,
458			},
459			xAxis: {
460				categories: [<?php
461					while ($row = pg_fetch_array($result)) {
462						echo "'".$row['dsc']."', ";
463					} pg_result_seek($result, 0); ?>
464				],
465				labels: {
466					rotation: -90,
467					align: 'center',
468					y: 23,
469					x: 3
470				},
471				plotBands: [
472					{ 
473						from: 3,
474						to: 4,
475						color: 'rgba(68, 170, 213, .1)',
476						label: {
477							text: 'CHC Campaign',
478							align: "center",
479							verticalAlign: "bottom",
480							y: -8
481						}
482					},
483					{ 
484						from: 5,
485						to: 6,
486						color: 'rgba(68, 170, 213, .1)',
487						label: {
488							text: 'RSNA Campaign',
489							align: "center",
490							verticalAlign: "bottom",
491							y: -8
492						}
493					},
494					{ 
495						from: 8,
496						to: 9,
497						color: 'rgba(68, 170, 213, .1)',
498						label: {
499							text: 'HIMSS Campaign',
500							align: "center",
501							verticalAlign: "bottom",
502							y: -8
503						}
504					},
505					{ 
506						from: 16,
507						to: 17,
508						color: 'rgba(68, 170, 213, .1)',
509						label: {
510							text: 'CHC Campaign',
511							align: "center",
512							verticalAlign: "bottom",
513							y: -8
514						}
515					},
516					{ 
517						from: 18,
518						to: 19,
519						color: 'rgba(68, 170, 213, .1)',
520						label: {
521							text: 'RSNA Campaign',
522							align: "center",
523							verticalAlign: "bottom",
524							y: -8
525						}
526					},
527					{ 
528						from: 21,
529						to: 22,
530						color: 'rgba(68, 170, 213, .1)',
531						label: {
532							text: 'HIMSS Campaign',
533							align: "center",
534							verticalAlign: "bottom",
535							y: -8
536						}
537					}
538				],
539				plotLines: [{
540					value: 2.75,
541					width: 1,
542					color: '#808080',
543					label: {
544						text: 'Social Networking Push',
545						align: "center",
546						verticalAlign: "top",
547						y: 75
548					}
549				}]
550			},
551			yAxis: {
552				min: -1,
553				title: {
554					text: setTITLE
555				}
556			},
557			tooltip: {
558				formatter: function() {
559					return '<b>'+ this.series.name +'</b><br />'+
560					this.x +': '+ this.y +'';
561				}
562			},
563			credits: { enabled: false },
564			legend: {
565				align: 'center',
566				floating: false,
567				verticalAlign: 'bottom',
568				borderWidth: 0,
569				y: 10
570			},
571			plotOptions: {
572				spline: {
573					lineWidth: 2,
574					states: {
575						hover: {
576							lineWidth: 4
577						}
578					},
579					marker: {
580						enabled: false,
581						states: {
582							hover: {
583								enabled: true,
584								symbol: 'circle',
585								radius: 5,
586								lineWidth: 1
587							}
588						}   
589					},
590				}
591			},
592			series: [
593				{ name: tConx, data: gConx },
594				{ name: tPost, data: gPost },
595				{ name: tReply, data: gReply },
596				{ name: tChare, data: gChare },
597				{ name: tLink, data: gLink }
598			]
599		});
600	
601	} else if (code==='distribution') {
602		var sFb = 0;
603		var sTw = 0;
604		var sLi = 0;
605		var sMm = 0;
606		var sGp = 0;
607		
608		var iFb = 0;
609		var iTw = 0;
610		var iLi = 0;
611		var iMm = 0;
612		var iGp = 0;
613		
614		var oFb = 0;
615		var oTw = 0;
616		var oLi = 0;
617		var oMm = 0;
618		var oGp = 0;
619		
620		if (sSub==='Post') {
621			<?php
622			while ($row = pg_fetch_array($result)) { echo 'sFb = sFb + parseInt('.$row['s_fb_post'].'); '; } pg_result_seek($result, 0);
623			while ($row = pg_fetch_array($result)) { echo 'sTw = sTw + parseInt('.$row['s_tw_post'].'); '; } pg_result_seek($result, 0);
624			while ($row = pg_fetch_array($result)) { echo 'sLi = sLi + parseInt('.$row['s_li_post'].'); '; } pg_result_seek($result, 0);
625			//while ($row = pg_fetch_array($result)) { echo 'sMm = sMm + parseInt('.$row['s_mm_post'].'); '; } pg_result_seek($result, 0);
626			//while ($row = pg_fetch_array($result)) { echo 'sGp = sGp + parseInt('.$row['s_gp_post'].'); '; } pg_result_seek($result, 0);
627
628			while ($row = pg_fetch_array($result)) { echo 'iFb = iFb + parseInt('.$row['i_fb_post'].'); '; } pg_result_seek($result, 0);
629			while ($row = pg_fetch_array($result)) { echo 'iTw = iTw + parseInt('.$row['i_tw_post'].'); '; } pg_result_seek($result, 0);
630			//while ($row = pg_fetch_array($result)) { echo 'iLi = iLi + parseInt('.$row['i_li_post'].'); '; } pg_result_seek($result, 0);
631			//while ($row = pg_fetch_array($result)) { echo 'iMm = iMm + parseInt('.$row['i_mm_post'].'); '; } pg_result_seek($result, 0);
632			while ($row = pg_fetch_array($result)) { echo 'iGp = iGp + parseInt('.$row['i_gp_post'].'); '; } pg_result_seek($result, 0);
633
634			while ($row = pg_fetch_array($result)) { echo 'oFb = oFb + parseInt('.$row['o_fb_post'].'); '; } pg_result_seek($result, 0);
635			while ($row = pg_fetch_array($result)) { echo 'oTw = oTw + parseInt('.$row['o_tw_post'].'); '; } pg_result_seek($result, 0);
636			//while ($row = pg_fetch_array($result)) { echo 'oLi = oLi + parseInt('.$row['o_li_post'].'); '; } pg_result_seek($result, 0);
637			while ($row = pg_fetch_array($result)) { echo 'oMm = oMm + parseInt('.$row['o_mm_post'].'); '; } pg_result_seek($result, 0);
638			while ($row = pg_fetch_array($result)) { echo 'oGp = oGp + parseInt('.$row['o_gp_post'].'); '; } pg_result_seek($result, 0);
639			?>
640		} else if (sSub==='Share') {
641			<?php
642			while ($row = pg_fetch_array($result)) { echo 'sFb = sFb + parseInt('.$row['s_fb_chare'].'); '; } pg_result_seek($result, 0);
643			while ($row = pg_fetch_array($result)) { echo 'sTw = sTw + parseInt('.$row['s_tw_chare'].'); '; } pg_result_seek($result, 0);
644			while ($row = pg_fetch_array($result)) { echo 'sLi = sLi + parseInt('.$row['s_li_chare'].'); '; } pg_result_seek($result, 0);
645			//while ($row = pg_fetch_array($result)) { echo 'sMm = sMm + parseInt('.$row['s_mm_chare'].'); '; } pg_result_seek($result, 0);
646			//while ($row = pg_fetch_array($result)) { echo 'sGp = sGp + parseInt('.$row['s_gp_chare'].'); '; } pg_result_seek($result, 0);
647
648			while ($row = pg_fetch_array($result)) { echo 'iFb = iFb + parseInt('.$row['i_fb_chare'].'); '; } pg_result_seek($result, 0);
649			while ($row = pg_fetch_array($result)) { echo 'iTw = iTw + parseInt('.$row['i_tw_chare'].'); '; } pg_result_seek($result, 0);
650			while ($row = pg_fetch_array($result)) { echo 'iLi = iLi + parseInt('.$row['i_li_chare'].'); '; } pg_result_seek($result, 0);
651			//while ($row = pg_fetch_array($result)) { echo 'iMm = iMm + parseInt('.$row['i_mm_chare'].'); '; } pg_result_seek($result, 0);
652			while ($row = pg_fetch_array($result)) { echo 'iGp = iGp + parseInt('.$row['i_gp_chare'].'); '; } pg_result_seek($result, 0);
653
654			while ($row = pg_fetch_array($result)) { echo 'oFb = oFb + parseInt('.$row['o_fb_chare'].'); '; } pg_result_seek($result, 0);
655			while ($row = pg_fetch_array($result)) { echo 'oTw = oTw + parseInt('.$row['o_tw_chare'].'); '; } pg_result_seek($result, 0);
656			while ($row = pg_fetch_array($result)) { echo 'oLi = oLi + parseInt('.$row['o_li_chare'].'); '; } pg_result_seek($result, 0);
657			while ($row = pg_fetch_array($result)) { echo 'oMm = oMm + parseInt('.$row['o_mm_chare'].'); '; } pg_result_seek($result, 0);
658			while ($row = pg_fetch_array($result)) { echo 'oGp = oGp + parseInt('.$row['o_gp_chare'].'); '; } pg_result_seek($result, 0);
659			?>
660		} else if (sSub==='Reply') {
661			<?php
662			while ($row = pg_fetch_array($result)) { echo 'sFb = sFb + parseInt('.$row['s_fb_reply'].'); '; } pg_result_seek($result, 0);
663			while ($row = pg_fetch_array($result)) { echo 'sTw = sTw + parseInt('.$row['s_tw_reply'].'); '; } pg_result_seek($result, 0);
664			while ($row = pg_fetch_array($result)) { echo 'sLi = sLi + parseInt('.$row['s_li_reply'].'); '; } pg_result_seek($result, 0);
665			//while ($row = pg_fetch_array($result)) { echo 'sMm = sMm + parseInt('.$row['s_mm_reply'].'); '; } pg_result_seek($result, 0);
666			//while ($row = pg_fetch_array($result)) { echo 'sGp = sGp + parseInt('.$row['s_gp_reply'].'); '; } pg_result_seek($result, 0);
667
668			while ($row = pg_fetch_array($result)) { echo 'iFb = iFb + parseInt('.$row['i_fb_reply'].'); '; } pg_result_seek($result, 0);
669			while ($row = pg_fetch_array($result)) { echo 'iTw = iTw + parseInt('.$row['i_tw_reply'].'); '; } pg_result_seek($result, 0);
670			while ($row = pg_fetch_array($result)) { echo 'iLi = iLi + parseInt('.$row['i_li_reply'].'); '; } pg_result_seek($result, 0);
671			//while ($row = pg_fetch_array($result)) { echo 'iMm = iMm + parseInt('.$row['i_mm_reply'].'); '; } pg_result_seek($result, 0);
672			while ($row = pg_fetch_array($result)) { echo 'iGp = iGp + parseInt('.$row['i_gp_reply'].'); '; } pg_result_seek($result, 0);
673
674			while ($row = pg_fetch_array($result)) { echo 'oFb = oFb + parseInt('.$row['o_fb_reply'].'); '; } pg_result_seek($result, 0);
675			while ($row = pg_fetch_array($result)) { echo 'oTw = oTw + parseInt('.$row['o_tw_reply'].'); '; } pg_result_seek($result, 0);
676			while ($row = pg_fetch_array($result)) { echo 'oLi = oLi + parseInt('.$row['o_li_reply'].'); '; } pg_result_seek($result, 0);
677			while ($row = pg_fetch_array($result)) { echo 'oMm = oMm + parseInt('.$row['o_mm_reply'].'); '; } pg_result_seek($result, 0);
678			while ($row = pg_fetch_array($result)) { echo 'oGp = oGp + parseInt('.$row['o_gp_reply'].'); '; } pg_result_seek($result, 0);
679			?>
680		} else if (sSub==='Connection') {
681			<?php
682			while ($row = pg_fetch_array($result)) { echo 'sFb = sFb + parseInt('.$row['s_fb_conx'].'); '; } pg_result_seek($result, 0);
683			while ($row = pg_fetch_array($result)) { echo 'sTw = sTw + parseInt('.$row['s_tw_conx'].'); '; } pg_result_seek($result, 0);
684			while ($row = pg_fetch_array($result)) { echo 'sLi = sLi + parseInt('.$row['s_li_conx'].'); '; } pg_result_seek($result, 0);
685			//while ($row = pg_fetch_array($result)) { echo 'sMm = sMm + parseInt('.$row['s_mm_conx'].'); '; } pg_result_seek($result, 0);
686			//while ($row = pg_fetch_array($result)) { echo 'sGp = sGp + parseInt('.$row['s_gp_conx'].'); '; } pg_result_seek($result, 0);
687
688			while ($row = pg_fetch_array($result)) { echo 'iFb = iFb + parseInt('.$row['i_fb_conx'].'); '; } pg_result_seek($result, 0);
689			while ($row = pg_fetch_array($result)) { echo 'iTw = iTw + parseInt('.$row['i_tw_conx'].'); '; } pg_result_seek($result, 0);
690			//while ($row = pg_fetch_array($result)) { echo 'iLi = iLi + parseInt('.$row['i_li_conx'].'); '; } pg_result_seek($result, 0);
691			//while ($row = pg_fetch_array($result)) { echo 'iMm = iMm + parseInt('.$row['i_mm_conx'].'); '; } pg_result_seek($result, 0);
692			while ($row = pg_fetch_array($result)) { echo 'iGp = iGp + parseInt('.$row['i_gp_conx'].'); '; } pg_result_seek($result, 0);
693
694			while ($row = pg_fetch_array($result)) { echo 'oFb = oFb + parseInt('.$row['o_fb_conx'].'); '; } pg_result_seek($result, 0);
695			while ($row = pg_fetch_array($result)) { echo 'oTw = oTw + parseInt('.$row['o_tw_conx'].'); '; } pg_result_seek($result, 0);
696			//while ($row = pg_fetch_array($result)) { echo 'oLi = oLi + parseInt('.$row['o_li_conx'].'); '; } pg_result_seek($result, 0);
697			while ($row = pg_fetch_array($result)) { echo 'oMm = oMm + parseInt('.$row['o_mm_conx'].'); '; } pg_result_seek($result, 0);
698			while ($row = pg_fetch_array($result)) { echo 'oGp = oGp + parseInt('.$row['o_gp_conx'].'); '; } pg_result_seek($result, 0);
699			?>
700		} else if (sSub==='Feedback') {
701			<?php
702			while ($row = pg_fetch_array($result)) { echo 'sFb = sFb + parseInt('.$row['s_fb_ratep'].') + parseInt('.$row['s_fb_raten'].'); '; } pg_result_seek($result, 0);
703			while ($row = pg_fetch_array($result)) { echo 'sTw = sTw + parseInt('.$row['s_tw_ratep'].') + parseInt('.$row['s_tw_raten'].'); '; } pg_result_seek($result, 0);
704			while ($row = pg_fetch_array($result)) { echo 'sLi = sLi + parseInt('.$row['s_li_ratep'].') + parseInt('.$row['s_li_raten'].'); '; } pg_result_seek($result, 0);
705			//while ($row = pg_fetch_array($result)) { echo 'sMm = sMm + parseInt('.$row['s_mm_ratep'].') + parseInt('.$row['s_mm_raten'].'); '; } pg_result_seek($result, 0);
706			//while ($row = pg_fetch_array($result)) { echo 'sGp = sGp + parseInt('.$row['s_gp_ratep'].') + parseInt('.$row['s_gp_raten'].'); '; } pg_result_seek($result, 0);
707
708			while ($row = pg_fetch_array($result)) { echo 'iFb = iFb + parseInt('.$row['i_fb_ratep'].') + parseInt('.$row['i_fb_raten'].'); '; } pg_result_seek($result, 0);
709			while ($row = pg_fetch_array($result)) { echo 'iTw = iTw + parseInt('.$row['i_tw_ratep'].') + parseInt('.$row['i_tw_raten'].'); '; } pg_result_seek($result, 0);
710			while ($row = pg_fetch_array($result)) { echo 'iLi = iLi + parseInt('.$row['i_li_ratep'].') + parseInt('.$row['i_li_raten'].'); '; } pg_result_seek($result, 0);
711			//while ($row = pg_fetch_array($result)) { echo 'iMm = iMm + parseInt('.$row['i_mm_ratep'].') + parseInt('.$row['i_mm_raten'].'); '; } pg_result_seek($result, 0);
712			while ($row = pg_fetch_array($result)) { echo 'iGp = iGp + parseInt('.$row['i_gp_ratep'].') + parseInt('.$row['i_gp_raten'].'); '; } pg_result_seek($result, 0);
713
714			while ($row = pg_fetch_array($result)) { echo 'oFb = oFb + parseInt('.$row['o_fb_ratep'].') + parseInt('.$row['o_fb_raten'].'); '; } pg_result_seek($result, 0);
715			while ($row = pg_fetch_array($result)) { echo 'oTw = oTw + parseInt('.$row['o_tw_ratep'].') + parseInt('.$row['o_tw_raten'].'); '; } pg_result_seek($result, 0);
716			while ($row = pg_fetch_array($result)) { echo 'oLi = oLi + parseInt('.$row['o_li_ratep'].') + parseInt('.$row['o_li_raten'].'); '; } pg_result_seek($result, 0);
717			while ($row = pg_fetch_array($result)) { echo 'oMm = oMm + parseInt('.$row['o_mm_ratep'].') + parseInt('.$row['o_mm_raten'].'); '; } pg_result_seek($result, 0);
718			while ($row = pg_fetch_array($result)) { echo 'oGp = oGp + parseInt('.$row['o_gp_ratep'].') + parseInt('.$row['o_gp_raten'].'); '; } pg_result_seek($result, 0);
719			?>
720		}
721		
722		var tFb = sFb + iFb + oFb;
723		var tTw = sTw + iTw + oTw;
724		var tLi = sLi + iLi + oLi;
725		var tMm = sMm + iMm + oMm;
726		var tGp = sGp + iGp + oGp;
727
728		var setTITLE = sSub+' Distribution';
729		
730		chart = new Highcharts.Chart({
731			chart: {
732			renderTo: 'holder-social-data',
733				defaultSeriesType: 'column',
734				margin: [60, 10, 50, 50]
735			},
736			title: {
737				text: setTITLE
738			},
739			xAxis: {
740				categories: ['Softek', 'Illuminate', 'OnTrack']
741			},
742			yAxis: {
743				min: 0,
744				title: {
745					text: sSub+'(s)'
746				}
747			},
748			tooltip: {
749				formatter: function() {
750					var s;
751					if (this.point.name) { // the pie chart
752						s = ''+ this.series.name +': '+ this.y +' ('+ Math.round(this.percentage) +'%)';
753					} else {
754						s = ''+ this.series.name +': '+ this.y +' ('+ Math.round(this.percentage) +'%)';
755					}
756					return s;
757				}
758			},
759			credits: { enabled: false },
760			legend: {
761				align: 'center',
762				floating: false,
763				verticalAlign: 'bottom',
764				borderWidth: 0,
765				y: 10
766			},
767			plotOptions: {
768				column: {
769					stacking: 'percent'
770				}
771			},
772			series: [
773				{
774					type: 'column',
775					name: 'Facebook',
776					color: '#006',
777					data: [ sFb, iFb, oFb ]
778				}, {
779					type: 'column',
780					name: 'Twitter',
781					color: '#0784C6',
782					data: [ sTw, iTw, oTw ]
783				}, {
784					type: 'column',
785					name: 'LinkedIn',
786					color: '#0047A1',
787					data: [ sLi, iLi, oLi ]
788				}, {
789					type: 'column',
790					name: 'Google+',
791					color: '#F60',
792					data: [ sGp, iGp, oGp ]
793				}, {
794					type: 'column',
795					name: 'M. Medic',
796					color: '#C30000',
797					data: [ sMm, iMm, oMm ]
798				}, {
799					type: 'pie',
800					name: 'Total',
801					data: [
802						{
803							name: 'Facebook',
804							y: tFb,
805							color: '#006'
806						}, {
807							name: 'Twitter',
808							y: tTw,
809							color: '#0784C6'
810						}, {
811							name: 'LinkedIn',
812							y: tLi,
813							color: '#0047A1'
814						}, {
815							name: 'Google+',
816							y: tGp,
817							color: '#F60'
818						}, {
819							name: 'M. Medic',
820							y: tMm,
821							color: '#C30000'
822						}
823					],
824					center: [470, 250],
825					size: 200,
826					showInLegend: false,
827					dataLabels: {
828						enabled: false
829					}
830				}
831			]
832		});
833	} // END TYPE CHECK
834};
835$.resetData = function(list, filter){	
836	$('#filter-select-client').val('ALL').hide();
837	$('#filter-select-code').val('connect').show();
838	$('#filter-select-type').val('spline').hide();
839	$('#filter-select-site').val('SSI').hide();
840	$('#filter-select-sub').val('Post').hide();
841	$.updateData();
842};
843$.updateData = function(){
844	var setCODE	= $('#filter-select-code').val();
845	var setTYPE	= $('#filter-select-type').val();
846	if (setCODE==='connect') {
847		$('#filter-select-client').hide();
848		$('#filter-select-type').show();
849		$('#filter-select-site').hide();
850		$('#filter-select-sub').hide();
851	} else if (setCODE==='activity') {
852		$('#filter-select-client').show();
853		$('#filter-select-type').show();
854		$('#filter-select-site').show();
855		$('#filter-select-sub').hide();
856	} else if (setCODE==='distribution') {
857		$('#filter-select-client').hide();
858		$('#filter-select-type').hide();
859		$('#filter-select-site').hide();
860		$('#filter-select-sub').show();
861	}
862	$.buildGraph(setCODE, setTYPE);
863};
864$(function() {
865	$.resetData();
866	
867	$('.body').keyup( function (e){
868		if (e.keyCode === 13) { // RETURN
869			e.preventDefault(); 
870			$.updateData();
871		}
872	});
873	$('#button-search').click(function(e){
874		e.preventDefault();
875		$.updateData();
876	});
877	$('#button-reset').click(function(e){
878		e.preventDefault();
879		$.resetData();
880	});
881});
882</script>