PageRenderTime 31ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 1ms

/app/controllers/analytics_controller.php

https://github.com/hilkeros/MMM-php-cake
PHP | 3520 lines | 2417 code | 839 blank | 264 comment | 250 complexity | a97a5f3d268ddc9a30cfe58331463575 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. class AnalyticsController extends AppController {
  3. var $name = 'Analytics';
  4. var $etime = NULL;
  5. var $uses = array('User','Band','Lfm','Lfmtrack','Lfmalbum','Lfmlistener','Mss','Mssstat','Msscomm','Msslogin','Fb','Fbpage','Yt','Ytstat','Ytcommstat');
  6. var $helpers = array('Html', 'Error', 'Javascript' , 'FlashChart');
  7. var $components = array('Cookie'); // use component email
  8. /**
  9. * Name: beforeFilter
  10. * Desc: Performs necessary steps and function calls prior to executing
  11. * any view function calls.
  12. */
  13. function beforeFilter() {
  14. $this->auth();
  15. } // function beforeFilter() {
  16. /* Name: index
  17. * Desc: set MySpace , Facebook , Last.fm , Youtube ID's by select option box.
  18. */
  19. function index()
  20. {
  21. $this->layout = "analytics";
  22. if($this->data)
  23. {
  24. $this->Session->write('mssvideo', $this->data['data']['mssvideo']);
  25. $this->Session->write('video', $this->data['data']['video']);
  26. $this->Session->write('topalbum', $this->data['data']['album']);
  27. $this->Session->write('toptrack', $this->data['data']['tracks']);
  28. $this->redirect('/analytics/cmslist/');
  29. exit;
  30. } // if($this->data)
  31. else
  32. {
  33. $mmm_id = $this->Session->read('id');
  34. if(@$this->params['url']['bandid'])
  35. {
  36. $band_id = $this->params['url']['bandid'];
  37. } // if(@$this->params['url']['bandid'])
  38. else
  39. {
  40. $band = $this->Band->find(array('mmm_id'=>$mmm_id,'status'=>'1'));
  41. if($band)
  42. {
  43. $band_id = $band['Band']['band_id'];
  44. }
  45. else
  46. {
  47. $this->Session->setFlash('Please Add Band');
  48. $this->redirect('/band/index/');
  49. }
  50. } // if(@$this->params['url']['bandid'])
  51. $band = $this->Band->findAll(array('mmm_id'=>$mmm_id,'status'=>'1'));
  52. if($band)
  53. {
  54. $this->set('band',$band);
  55. foreach($band as $bandkey =>$bandval)
  56. {
  57. if($bandval['Band']['band_id']==$band_id)
  58. {
  59. $bandname = $bandval['Band']['name'];
  60. break;
  61. }
  62. }
  63. $this->set('bandname',$bandname);
  64. $this->Session->write('bandname',$bandname);
  65. }
  66. $this->Session->write('band_id',$band_id);
  67. $qry_mss = "select p.title from mss_play_stat p , mss_login m where p.mss_id = m.mss_id and m.mmm_id='$mmm_id' and m.band_id=$band_id";
  68. $mss_plays = $this->Mssstat->findBySql($qry_mss);
  69. if($mss_plays)
  70. {
  71. $this->set('mss_plays',$mss_plays);
  72. } // if($results)
  73. else
  74. {
  75. $mss_plays[0]['p']['title'] = 'No data';
  76. $this->set('mss_plays',$mss_plays);
  77. }
  78. $qry_lfm_album = "select a.name from lfm_top_album a , lfm_music m where a.lfm_m_id = m.lfm_m_id and m.mmm_id='$mmm_id' and m.band_id=$band_id";
  79. $lfm_album = $this->Lfmalbum->findBySql($qry_lfm_album);
  80. if($lfm_album)
  81. {
  82. $this->set('lfm_album',$lfm_album);
  83. } // if($results)
  84. else
  85. {
  86. $lfm_album[0]['a']['name'] = 'No data';
  87. $this->set('lfm_album',$lfm_album);
  88. }
  89. $qry_lfm_track = "select t.name from lfm_top_tracks t , lfm_music m where t.lfm_m_id = m.lfm_m_id and m.mmm_id='$mmm_id' and m.band_id=$band_id";
  90. $lfm_track = $this->Lfmalbum->findBySql($qry_lfm_track);
  91. if($lfm_track)
  92. {
  93. $this->set('lfm_track',$lfm_track);
  94. } // if($results)
  95. else
  96. {
  97. $lfm_track[0]['t']['name'] = 'No data';
  98. $this->set('lfm_track',$lfm_track);
  99. }
  100. $qry_yt_video= "select y.title from yt_comments_stat y , yt_login l where y.yt_id = l.yt_id and l.mmm_id='$mmm_id' and l.band_id=$band_id";
  101. $ytvideo = $this->Ytcommstat->findBySql($qry_yt_video);
  102. if($ytvideo)
  103. {
  104. $this->set('ytvideo',$ytvideo);
  105. } // if($results)
  106. else
  107. {
  108. $ytvideo[0]['y']['title'] = 'No data';
  109. $this->set('ytvideo',$ytvideo);
  110. }
  111. $fb = $this->Fb->find(array('mmm_id'=>$mmm_id , 'band_id'=>$band_id , 'status'=>1));
  112. if($fb)
  113. {
  114. $page = $fb['Fb']['page'];
  115. $group = $fb['Fb']['group'];
  116. if($page)
  117. {
  118. $this->Session->write('fbpages', $page);
  119. }
  120. else
  121. {
  122. $page = 'No data';
  123. $this->Session->write('fbpages', $page);
  124. }
  125. if($group)
  126. {
  127. $this->Session->write('fbgroups', $group);
  128. }
  129. else
  130. {
  131. $group = 'No data';
  132. $this->Session->write('fbgroups', $group);
  133. }
  134. } // if($results)
  135. else
  136. {
  137. $page = 'No data';
  138. $group = 'No data';
  139. $this->Session->write('fbpages', $page);
  140. $this->Session->write('fbgroups', $group);
  141. }
  142. } // if($this->data)
  143. } // function index()
  144. /*
  145. Name : album
  146. Desc : Ajax Album to get top album against last.fm Music Group
  147. */
  148. function album()
  149. {
  150. if(!empty($this->params['url']['id']))
  151. {
  152. $id = $this->params['url']['id'];
  153. $qry="select distinct l.name from lfm_top_album l where l.lfm_m_id = $id";
  154. $result = $this->Lfmalbum->findBySql($qry);
  155. $data = "[";
  156. foreach($result as $key =>$val)
  157. {
  158. $nm = str_replace(array("\"","'"),array(" "," "),$val['l']['name']);
  159. $data.= "{ optionValue:'$nm' , optionDisplay:'$nm'},";
  160. }
  161. $data= substr($data,0,strlen($data)-1);
  162. $data.="]";
  163. echo $data;
  164. exit;
  165. }
  166. } // function album
  167. /*
  168. Name : tracks
  169. Desc : Ajax Album to get top tracks against last.fm Music Group
  170. */
  171. function tracks()
  172. {
  173. if(!empty($this->params['url']['id']))
  174. {
  175. $id = $this->params['url']['id'];
  176. $qry="select distinct l.name from lfm_top_tracks l where l.lfm_m_id = $id";
  177. $result = $this->Lfmalbum->findBySql($qry);
  178. $data = "[";
  179. foreach($result as $key =>$val)
  180. {
  181. $nm = str_replace(array("\"","'"),array(" "," "),$val['l']['name']);
  182. $data.= "{ optionValue:'$nm' , optionDisplay:'$nm'},";
  183. }
  184. $data= substr($data,0,strlen($data)-1);
  185. $data.="]";
  186. echo $data;
  187. exit;
  188. }
  189. } // function tracks
  190. /*
  191. Name : comments
  192. Desc : Ajax to get youtube video title
  193. */
  194. function comments()
  195. {
  196. if(!empty($this->params['url']['id']))
  197. {
  198. $id = $this->params['url']['id'];
  199. $qry="select distinct y.title from yt_comments_stat y where y.yt_id = $id";
  200. $result = $this->Lfmalbum->findBySql($qry);
  201. $data = "[";
  202. foreach($result as $key =>$val)
  203. {
  204. $nm = str_replace(array("\"","'"),array(" "," "),$val['y']['title']);
  205. $data.= "{ optionValue:'$nm' , optionDisplay:'$nm'},";
  206. }
  207. $data= substr($data,0,strlen($data)-1);
  208. $data.="]";
  209. echo $data;
  210. exit;
  211. }
  212. } // function comments()
  213. /*
  214. Name : mssplays
  215. Desc : Ajax to get Myspace title
  216. */
  217. function mssplays()
  218. {
  219. if(!empty($this->params['url']['id']))
  220. {
  221. $id = $this->params['url']['id'];
  222. $qry="select distinct m.title from mss_play_stat m where m.mss_id = $id";
  223. $result = $this->Lfmalbum->findBySql($qry);
  224. $data = "[";
  225. foreach($result as $key =>$val)
  226. {
  227. $nm = str_replace(array("\"","'"),array(" "," "),$val['m']['title']);
  228. $data.= "{ optionValue:'$nm' , optionDisplay:'$nm'},";
  229. }
  230. $data= substr($data,0,strlen($data)-1);
  231. $data.="]";
  232. echo $data;
  233. exit;
  234. }
  235. } // function comments()
  236. /*
  237. Name : Facebook Pages
  238. Desc : Ajax to get Fbs pages
  239. */
  240. function fbspages()
  241. {
  242. if(!empty($this->params['url']['id']))
  243. {
  244. $id = $this->params['url']['id'];
  245. $qry="select distinct f.name from fb_pages f where f.login_id = $id and f.is_admin=1";
  246. $result = $this->Lfmalbum->findBySql($qry);
  247. $data = "[";
  248. foreach($result as $key =>$val)
  249. {
  250. $nm = str_replace(array("\"","'"),array(" "," "),$val['f']['name']);
  251. $data.= "{ optionValue:'$nm' , optionDisplay:'$nm'},";
  252. }
  253. $data= substr($data,0,strlen($data)-1);
  254. $data.="]";
  255. echo $data;
  256. exit;
  257. }
  258. } // function fbspages()
  259. /*
  260. Name : Facebook Groups
  261. Desc : Ajax to get Fbs Groups
  262. */
  263. function fbsgroups()
  264. {
  265. if(!empty($this->params['url']['id']))
  266. {
  267. $id = $this->params['url']['id'];
  268. $qry="select distinct f.name from fb_group f where f.login_id = $id and f.isCreator='Yes'";
  269. $result = $this->Lfmalbum->findBySql($qry);
  270. $data = "[";
  271. foreach($result as $key =>$val)
  272. {
  273. $nm = str_replace(array("\"","'"),array(" "," "),$val['f']['name']);
  274. $data.= "{ optionValue:'$nm' , optionDisplay:'$nm'},";
  275. }
  276. $data= substr($data,0,strlen($data)-1);
  277. $data.="]";
  278. echo $data;
  279. exit;
  280. }
  281. } // function fbspages()
  282. /*
  283. Name : cmslist
  284. Desc : link hits , view , plays and comments
  285. */
  286. function cmslist()
  287. {
  288. if($this->Session->check('id') and $this->Session->check('band_id') and $this->Session->check('bandname') and $this->Session->check('toptrack') and $this->Session->check('topalbum') and $this->Session->check('video') and $this->Session->check('mssvideo'))
  289. {
  290. $bandname = $this->Session->read('bandname');
  291. $this->set('bandname',$bandname);
  292. if($this->Session->read('mssvideo')!='No data')
  293. { $this->Session->write('msh','msh');
  294. $this->Session->write('msv','msv');
  295. $this->Session->write('msp','msp');
  296. $this->Session->write('msc','msc');
  297. }
  298. if($this->Session->read('video')!='No data')
  299. {
  300. $this->Session->write('yth','yth');
  301. $this->Session->write('ytv','ytv');
  302. $this->Session->write('ytp','ytp');
  303. $this->Session->write('ytc','ytc');
  304. }
  305. if(($this->Session->read('topalbum')!='No data') and ($this->Session->read('toptrack')!='No data'))
  306. {
  307. $this->Session->write('lfmsh','lfmsh');
  308. $this->Session->write('lfmsv','lfmsv');
  309. $this->Session->write('lfmsp','lfmsp');
  310. }
  311. if($this->Session->read('fbpages')!='No data')
  312. $this->Session->write('fbspages','fbspages');
  313. if($this->Session->read('fbgroups')!='No data')
  314. $this->Session->write('fbsgroups','fbsgroups');
  315. $this->layout = 'analyticcms';
  316. } // if($this->Session->check('id') and $this->Session->check('band_id') and $this->Session->check('bandname') and $this->Session->check('toptrack') and $this->Session->check('topalbum') and $this->Session->check('video') and $this->Session->check('mssvideo'))
  317. else
  318. {
  319. $this->redirect('/analytics/index');
  320. } // if($this->Session->check('email') and $this->Session->check('band_id') and $this->Session->check('bandname') and $this->Session->check('toptrack') and $this->Session->check('topalbum') and $this->Session->check('video') and $this->Session->check('mssvideo'))
  321. } // function cmslist()
  322. /*
  323. name : chart
  324. set : get and set data for fans , hits , tracks & comments
  325. */
  326. function chart()
  327. {
  328. /*
  329. get and set light box & graph width & height
  330. */
  331. if(!empty($this->params['url']['width']) and !empty($this->params['url']['height']))
  332. {
  333. $width = $this->params['url']['width'] ;
  334. $height = $this->params['url']['height'] ;
  335. }
  336. else
  337. {
  338. $width = 600;
  339. $height=400;
  340. }
  341. $this->set('cwidth',$width);
  342. $this->set('cheight',$height);
  343. $this->set('width',round($width/1.25));
  344. $this->set('height',round($height/1.5));
  345. // End get and set light box & graph width & height
  346. $mmm_id = $this->Session->read('id');
  347. // get and set band ID
  348. if(!empty($this->params['url']['bandid']))
  349. {
  350. $band_id = $this->params['url']['bandid'];
  351. $this->Session->write('band_id',$band_id);
  352. } // if(@$this->params['url']['bandid'])
  353. elseif($this->Session->check('band_id'))
  354. {
  355. $band_id = $this->Session->read('band_id');
  356. }
  357. else
  358. {
  359. $this->set('flag',1);
  360. }//if(@$this->params['url']['bandid'])
  361. $band = $this->Band->find(array('mmm_id'=>$mmm_id,'status'=>'1','band_id'=>$band_id));
  362. if($band)
  363. {
  364. $bandname = $band['Band']['name'];
  365. $this->set('bandname',$bandname);
  366. $this->Session->write('bandname',$bandname);
  367. }
  368. $this->Session->write('band_id',$band_id);
  369. // Get and set values for Myspace , youtube , last.fm
  370. // Get and set values for MySpace Tracks Tab
  371. $qry_mss = "select distinct p.title from mss_play_stat p , mss_login m where p.mss_id = m.mss_id and m.mmm_id='$mmm_id' and m.band_id=$band_id and m.status=1";
  372. $mss_plays = $this->Mssstat->findBySql($qry_mss);
  373. $mss = NULL;
  374. if($mss_plays)
  375. {
  376. if(!empty($this->params['url']['mss'])) // if option select from light box
  377. {
  378. $this->Session->write('mssvideo', $this->params['url']['mss']);
  379. $this->set('mssval',$this->params['url']['mss']); // to select dropdown list value
  380. }
  381. else
  382. {
  383. $this->Session->write('mssvideo', $mss_plays[0]['p']['title']);
  384. $this->set('mssval',$mss_plays[0]['p']['title']);
  385. }
  386. foreach($mss_plays as $key => $mssval)
  387. {
  388. $mss[$mssval['p']['title']] = $mssval['p']['title'] ;
  389. }
  390. $this->set('mss',$mss);
  391. } // if($results)
  392. else
  393. {
  394. $mss_plays[0]['p']['title'] = 'No data';
  395. $this->Session->write('mssvideo', $mss_plays[0]['p']['title']);
  396. $mss['No data'] = 'No data';
  397. $this->set('mssval','No data');
  398. $this->set('mss',$mss);
  399. }
  400. // Get and set values for Last.fm Tracks Tab
  401. $qry_lfm_track = "select distinct t.name from lfm_top_tracks t , lfm_music m where t.lfm_m_id = m.lfm_m_id and m.mmm_id='$mmm_id' and m.band_id=$band_id and m.status=1";
  402. $lfm_track = $this->Lfmalbum->findBySql($qry_lfm_track);
  403. $lfmt=NULL;
  404. if($lfm_track)
  405. {
  406. if(!empty($this->params['url']['lfmt']))
  407. {
  408. $this->Session->write('toptrack', $this->params['url']['lfmt']);
  409. $this->set('lfmtval',$this->params['url']['lfmt']);
  410. }
  411. else
  412. {
  413. $this->Session->write('toptrack', $lfm_track[0]['t']['name']);
  414. $this->set('lfmtval',$lfm_track[0]['t']['name']);
  415. }
  416. foreach($lfm_track as $key => $lfmval)
  417. {
  418. $lfmt[$lfmval['t']['name']] = $lfmval['t']['name'];
  419. }
  420. $this->set('lfmt',$lfmt);
  421. } // if($results)
  422. else
  423. {
  424. $lfm_track[0]['t']['name'] = 'No data';
  425. $this->Session->write('toptrack', $lfm_track[0]['t']['name']);
  426. $lfmt['No data'] = 'No data';
  427. $this->set('lfmt',$lfmt);
  428. $this->set('lfmtval','No data');
  429. }
  430. // Get and set values for Youtubne Tracks & comments Tab
  431. $qry_yt_video= "select distinct y.title from yt_comments_stat y , yt_login l where y.yt_id = l.yt_id and l.mmm_id='$mmm_id' and l.band_id=$band_id and l.status=1";
  432. $ytvideo = $this->Ytcommstat->findBySql($qry_yt_video);
  433. $yt=NULL;
  434. if($ytvideo)
  435. {
  436. if(!empty($this->params['url']['yt']))
  437. {
  438. $this->Session->write('video', $this->params['url']['yt']);
  439. $this->set('ytval',$this->params['url']['yt']);
  440. }
  441. else
  442. {
  443. $this->Session->write('video', $ytvideo[0]['y']['title']);
  444. $this->set('ytval',$ytvideo[0]['y']['title']);
  445. }
  446. foreach($ytvideo as $key => $ytval)
  447. {
  448. $yt[$ytval['y']['title']] = $ytval['y']['title'];
  449. }
  450. $this->set('yt',$yt);
  451. } // if($results)
  452. else
  453. {
  454. $ytvideo[0]['y']['title'] = 'No data';
  455. $this->Session->write('video', $ytvideo[0]['y']['title']);
  456. $yt['No data'] = 'No data';
  457. $this->set('yt',$yt);
  458. $this->set('ytval','No data');
  459. }
  460. // Get and set facebook pages & group data for Fans Tab
  461. $fb = $this->Fb->find(array('mmm_id'=>$mmm_id , 'band_id'=>$band_id , 'status'=>1));
  462. if($fb)
  463. {
  464. $page = $fb['Fb']['page'];
  465. $group = $fb['Fb']['group'];
  466. if($page)
  467. {
  468. $this->Session->write('fbpages', $page);
  469. }
  470. else
  471. {
  472. $page = 'No data';
  473. $this->Session->write('fbpages', $page);
  474. }
  475. if($group)
  476. {
  477. $this->Session->write('fbgroups', $group);
  478. }
  479. else
  480. {
  481. $group = 'No data';
  482. $this->Session->write('fbgroups', $group);
  483. }
  484. } // if($results)
  485. else
  486. {
  487. $page = 'No data';
  488. $group = 'No data';
  489. $this->Session->write('fbpages', $page);
  490. $this->Session->write('fbgroups', $group);
  491. }
  492. /*
  493. if in case chart call within the chart
  494. else in case of chart first time call without dates then default date & option applied
  495. */
  496. if(!empty($this->params['url']['date']))
  497. {
  498. $lastdate = $this->params['url']['date'];
  499. $this->Session->write('lastdate',$lastdate);
  500. $this->set('lastdate',$lastdate );
  501. if(!empty($this->params['url']['id']))
  502. {
  503. $id = $this->params['url']['id'];
  504. // set On / Off buttons
  505. switch($id)
  506. {
  507. case 'hall' :
  508. $this->Session->write('msv','msv');// Myspace hits
  509. $this->Session->write('ytv','ytv');// Youtube hits
  510. $this->Session->write('lfmsv','lfmsv'); // last.fm hits
  511. $this->Session->write('hnone',0);
  512. break;
  513. case 'hnone' :
  514. $this->Session->delete('msv');// Myspace hits
  515. $this->Session->delete('ytv');// Youtube hits
  516. $this->Session->delete('lfmsv');// last.fm hits
  517. if($this->Session->read('hnone')==1)
  518. {
  519. $this->Session->write('hnone',0);
  520. }
  521. else
  522. {
  523. $this->Session->write('hnone',1);
  524. }
  525. break;
  526. case 'fall' :
  527. $this->Session->write('msh','msh');// Myspace fans
  528. $this->Session->write('yth','yth');// Youtube fans
  529. $this->Session->write('lfmsh','lfmsh'); // last.fm fans
  530. $this->Session->write('fbspages','fbspages'); // facebook page flag
  531. $this->Session->write('fbsgroups','fbsgroups'); // facebook group flag
  532. $this->Session->write('fnone',0);
  533. break;
  534. case 'fnone' :
  535. $this->Session->delete('msh');// Myspace fans
  536. $this->Session->delete('yth');// Youtube fans
  537. $this->Session->delete('lfmsh'); // last.fm fans
  538. $this->Session->delete('fbspages'); // facebook page flag
  539. $this->Session->delete('fbsgroups'); // facebook group flag
  540. if($this->Session->read('fnone')==1)
  541. {
  542. $this->Session->write('fnone',0);
  543. }
  544. else
  545. {
  546. $this->Session->write('fnone',1);
  547. }
  548. break;
  549. case 'tall' :
  550. $this->Session->write('msp','msp');// Myspace tracks
  551. $this->Session->write('ytp','ytp');// Youtube tracks
  552. $this->Session->write('lfmsp','lfmsp'); // last.fm tracks
  553. $this->Session->write('tnone',0);
  554. break;
  555. case 'tnone' :
  556. $this->Session->delete('msp');// Myspace tracks
  557. $this->Session->delete('ytp');// Youtube tracks
  558. $this->Session->delete('lfmsp'); // last.fm tracks
  559. if($this->Session->read('tnone')==1)
  560. {
  561. $this->Session->write('tnone',0);
  562. }
  563. else
  564. {
  565. $this->Session->write('tnone',1);
  566. }
  567. break;
  568. case 'call' :
  569. $this->Session->write('msc','msc');// Myspace comments
  570. $this->Session->write('ytc','ytc');// Youtube comments
  571. $this->Session->write('cnone',0);
  572. break;
  573. case 'cnone' :
  574. $this->Session->delete('msc');// Myspace comments
  575. $this->Session->delete('ytc');// Youtube comments
  576. if($this->Session->read('cnone')==1)
  577. {
  578. $this->Session->write('cnone',0);
  579. }
  580. else
  581. {
  582. $this->Session->write('cnone',1);
  583. }
  584. break;
  585. default :
  586. $type = $this->params['url']['type'];
  587. if($type=='fans')
  588. {
  589. $this->Session->write('fnone',0);
  590. }
  591. elseif($type=='hits')
  592. {
  593. $this->Session->write('hnone',0);
  594. }
  595. elseif($type=='tracks')
  596. {
  597. $this->Session->write('tnone',0);
  598. }
  599. elseif($type=='comments')
  600. {
  601. $this->Session->write('cnone',0);
  602. }
  603. if (!$this->Session->check($id))
  604. {
  605. $this->Session->write($id,$id);
  606. }
  607. else
  608. {
  609. $this->Session->delete($id);
  610. }
  611. break;
  612. }
  613. $this->set('id',$id);
  614. } // if(!empty($this->params['url']['id']))
  615. $this->sethitschart(); // get fans for facebook pages & groups , youtueb , myspace , last.fm
  616. if($this->params['url']['type']=='fans')
  617. {
  618. $this->Session->write('type','fans');
  619. }
  620. $this->setviewschart(); // get hits for youtube , myspace , last.fm
  621. if($this->params['url']['type']=='hits')
  622. {
  623. $this->Session->write('type','hits');
  624. }
  625. $this->setplayschart(); // get tracks for youtube , myspace , last.fm
  626. if($this->params['url']['type']=='tracks')
  627. {
  628. $this->Session->write('type','tracks');
  629. }
  630. $this->setcommentchart(); // get comments for youtube , myspace
  631. if($this->params['url']['type']=='comments')
  632. {
  633. $this->Session->write('type','comments');
  634. }
  635. } // if(!empty($this->params['url']['date']) and !empty($this->params['url']['opt']))
  636. else
  637. {
  638. if($this->Session->check('lastdate'))
  639. {
  640. $this->Session->delete('lastdate');
  641. }
  642. $this->Session->write('lastdate','w');
  643. $this->set('lastdate','w');
  644. $this->Session->write('msh','msh');// Myspace fans
  645. $this->Session->write('msv','msv');// Myspace hits
  646. $this->Session->write('msp','msp');// Myspace tracks
  647. $this->Session->write('msc','msc');// Myspace comments
  648. $this->Session->write('yth','yth');// Youtube fans
  649. $this->Session->write('ytv','ytv');// Youtube hits
  650. $this->Session->write('ytp','ytp');// Youtube tracks
  651. $this->Session->write('ytc','ytc');// Youtube comments
  652. $this->Session->write('lfmsh','lfmsh'); // last.fm fans
  653. $this->Session->write('lfmsv','lfmsv'); // last.fm hits
  654. $this->Session->write('lfmsp','lfmsp'); // last.fm tracks
  655. $this->Session->write('fbspages','fbspages'); // facebook page flag
  656. $this->Session->write('fbsgroups','fbsgroups'); // facebook group flag
  657. $this->Session->write('type','fans');
  658. $this->setcommentchart(); // get comments for youtube , myspace
  659. $this->setviewschart(); // get hits for youtube , myspace , last.fm
  660. $this->setplayschart(); // get tracks for youtube , myspace , last.fm
  661. $this->sethitschart(); // get fans for facebook , youtube , myspace & last.fm
  662. } // if(!empty($this->params['url']['date']) and !empty($this->params['url']['opt']))
  663. $this->layout="stats";
  664. } // function chart()
  665. /*
  666. Name : commentchart
  667. Desc : Get graph values from sessions and display graph
  668. */
  669. function commentchart()
  670. {
  671. $dt = $this->Session->read('dt');
  672. $mscomment = $this->Session->read('mscomment');
  673. $ytcomment = $this->Session->read('ytcomment');
  674. $this->set('dt',$dt);
  675. $this->set('mscomment',$mscomment);
  676. $this->set('ytcomment',$ytcomment);
  677. } // function setcommentchart()
  678. /*
  679. Name : setcommentchart
  680. Desc : Get graph values and return to comment()
  681. */
  682. function setcommentchart()
  683. {
  684. if($this->Session->check('id') and $this->Session->check('band_id') and $this->Session->check('video'))
  685. {
  686. $mmm_id = $this->Session->read('id');
  687. $band_id = $this->Session->read('band_id');
  688. $video = $this->Session->read('video');
  689. }
  690. else
  691. {
  692. //$this->Session->setFlash('Session Expired');
  693. //$this->redirect('/analytics/index/');
  694. return ;
  695. } // if($this->Session->check('email') and $this->Session->check('band_id') and $this->Session->check('video'))
  696. $mss= NULL;
  697. $yt=NULL;
  698. $album=NULL;
  699. if($this->Session->read('lastdate')=='w') // weekly graphs quries
  700. {
  701. $qry_mss = "select s.comments , s.etime from mss_stat s , mss_login l where s.mss_id = l.mss_id and l.band_id=$band_id and l.mmm_id = '$mmm_id' and l.status=1 and FROM_UNIXTIME(s.etime) between DATE_SUB(CURDATE(), INTERVAL 9 DAY) AND CURDATE( ) order by etime";
  702. $qry_yt = "select y.total_comments comments , y.etime from yt_comments_stat y , yt_login l where title='$video' and y.yt_id = l.yt_id and l.band_id=$band_id and l.mmm_id='$mmm_id' and l.status=1 and FROM_UNIXTIME(y.etime) between DATE_SUB(CURDATE(), INTERVAL 9 DAY) AND CURDATE( ) order by etime";
  703. if(!empty($this->params['url']['id']))
  704. {
  705. if ($this->Session->check('msc'))
  706. {
  707. $mss = $this->Mss->findBySql($qry_mss);
  708. }
  709. if ($this->Session->check('ytc'))
  710. {
  711. $yt = $this->Ytstat->findBySql($qry_yt);
  712. }
  713. } // if(!empty($this->params['url']['id']))
  714. else
  715. {
  716. $mss = $this->Mss->findBySql($qry_mss);
  717. $yt = $this->Ytstat->findBySql($qry_yt);
  718. } // if(!empty($this->params['url']['id']))
  719. $qry= "select DATE_SUB(CURDATE(), INTERVAL 7 DAY) last, CURDATE() curr";
  720. $tfdate = $this->Ytstat->findBySql($qry);
  721. $dt =NULL;
  722. $date = NULL;
  723. $c=0;
  724. $dt[$c]=$tfdate['0']['0']['last'];
  725. while($tfdate['0']['0']['curr']!=$date)
  726. {
  727. $date = date('Y-m-d',strtotime(date("Y-m-d", strtotime($dt[$c])) . " +1 day"));
  728. $c ++;
  729. if($c==7) // i.e 0-6 last 7 days
  730. {
  731. break;
  732. }
  733. $dt[$c]= $date;
  734. } // while($tfdate['0']['0']['curr']!=$date)
  735. } // if($this->Session->read('lastdate')=='w') // weekly graphs quries
  736. elseif($this->Session->read('lastdate')=='m') // monthly graphs quries
  737. {
  738. $qry_mss = "select s.comments , s.etime from mss_stat s , mss_login l where s.mss_id = l.mss_id and l.band_id=$band_id and l.mmm_id = '$mmm_id' and l.status=1 and FROM_UNIXTIME(s.etime) between DATE_SUB(CURDATE(), INTERVAL 1 Month) AND CURDATE( ) order by etime";
  739. $qry_yt = "select y.total_comments comments , y.etime from yt_comments_stat y , yt_login l where y.title='$video' and y.yt_id = l.yt_id and l.band_id=$band_id and l.mmm_id='$mmm_id' and l.status=1 and FROM_UNIXTIME(y.etime) between DATE_SUB(CURDATE(), INTERVAL 1 Month) AND CURDATE( ) order by etime";
  740. if(!empty($this->params['url']['id']))
  741. {
  742. if ($this->Session->check('msc'))
  743. {
  744. $mss = $this->Mss->findBySql($qry_mss);
  745. }
  746. if ($this->Session->check('ytc'))
  747. {
  748. $yt = $this->Ytstat->findBySql($qry_yt);
  749. }
  750. } // if(!empty($this->params['url']['id']))
  751. else
  752. {
  753. $mss = $this->Mss->findBySql($qry_mss);
  754. $yt = $this->Ytstat->findBySql($qry_yt);
  755. } // if(!empty($this->params['url']['id']))
  756. $qry= "select DATE_SUB(CURDATE(), INTERVAL 1 Month) last, CURDATE() curr";
  757. $tfdate = $this->Ytstat->findBySql($qry);
  758. $dt =NULL;
  759. $date = NULL;
  760. $c=0;
  761. $cdate= $tfdate['0']['0']['curr'];
  762. $curdate = date('Y-m-d',strtotime(date("Y-m-d", strtotime($cdate)) . " -1 day"));
  763. $d=$tfdate['0']['0']['last'];
  764. $dt[$c]=date('Y-m-d',strtotime(date("Y-m-d", strtotime($d)) . " +1 day"));
  765. while($curdate!=$date)
  766. {
  767. $date = date('Y-m-d',strtotime(date("Y-m-d", strtotime($dt[$c])) . " +1 day"));
  768. $c ++;
  769. $dt[$c]= $date;
  770. } // while($tfdate['0']['0']['curr']!=$date)
  771. $this->Session->write('mm',count($dt));
  772. } // elseif($this->Session->read('lastdate')=='m') // monthly graphs quries
  773. elseif($this->Session->read('lastdate')=='y') // yearly graphs quries
  774. {
  775. $qry_mss = "select s.comments , s.etime from mss_stat s , mss_login l where s.mss_id = l.mss_id and l.band_id=$band_id and l.mmm_id = '$mmm_id' and l.status=1 and FROM_UNIXTIME(s.etime) between DATE_SUB(CURDATE(), INTERVAL 1 Year) AND CURDATE( ) order by etime";
  776. $qry_yt = "select y.total_comments comments , y.etime from yt_comments_stat y , yt_login l where y.title='$video' and y.yt_id = l.yt_id and l.band_id=$band_id and l.mmm_id='$mmm_id' and l.status=1 and FROM_UNIXTIME(y.etime) between DATE_SUB(CURDATE(), INTERVAL 1 Year) AND CURDATE( ) order by etime";
  777. if(!empty($this->params['url']['id']))
  778. {
  779. if ($this->Session->check('msc'))
  780. {
  781. $mss = $this->Mss->findBySql($qry_mss);
  782. $mss_data = $this->getyear($mss,'s','comments');
  783. }
  784. if ($this->Session->check('ytc'))
  785. {
  786. $yt = $this->Ytstat->findBySql($qry_yt);
  787. $yt_data =$this->getyear($yt,'y','comments');
  788. }
  789. } // if(!empty($this->params['url']['id']))
  790. else
  791. {
  792. /*
  793. select sum(s.views) , date_format(FROM_UNIXTIME(s.etime),'%m') from mss_stat s group by date_format(FROM_UNIXTIME(s.etime),'%m')
  794. */
  795. $mss = $this->Mss->findBySql($qry_mss);
  796. $yt = $this->Ytstat->findBySql($qry_yt);
  797. $mss_data = $this->getyear($mss,'s','comments');
  798. $yt_data =$this->getyear($yt,'y','comments');
  799. } // if(!empty($this->params['url']['id']))
  800. /*
  801. Month Wise Yearly date create
  802. */
  803. $qry= "select DATE_SUB(CURDATE(), INTERVAL 1 Year) last, CURDATE() curr";
  804. $tfdate = $this->Ytstat->findBySql($qry);
  805. $dt =NULL;
  806. $date = NULL;
  807. $c=0;
  808. $td= $tfdate['0']['0']['curr'];
  809. $td=date('M',strtotime(date("Y-m-d", strtotime($td))));
  810. $d=$tfdate['0']['0']['last'];
  811. $edate=date('Y-m-d',strtotime(date("Y-m-d", strtotime($d)). " +1 Month"));
  812. $dt[$c]=date('M',strtotime(date("Y-m-d", strtotime($d)). " +1 Month"));
  813. while($td!=$date)
  814. {
  815. $date = date('M',strtotime(date("Y-m-d", strtotime($edate)) . " +1 Month"));
  816. $c ++;
  817. $dt[$c]= $date;
  818. $edate=date('Y-m-d',strtotime(date("Y-m-d", strtotime($edate)). " +1 Month"));
  819. if($c>12)
  820. {
  821. break;
  822. } // if($c>12)
  823. } // while($tfdate['0']['0']['curr']!=$date)
  824. } // elseif($this->Session->read('lastdate')=='y') // yearly graphs quries
  825. $mscommentcount=NULL;
  826. $ytcommentcount=NULL;
  827. if($this->Session->read('lastdate')=='y') // set data according to date for yearly graph
  828. {
  829. $flg=0;
  830. if(empty($mss_data))
  831. {
  832. $mscount = 0;
  833. }
  834. else
  835. {
  836. $mscount = count($mss_data);
  837. }
  838. if(empty($yt_data))
  839. {
  840. $ytcount = 0;
  841. }
  842. else
  843. {
  844. $ytcount = count($yt_data);
  845. }
  846. $cnt=0;
  847. $ycnt=0;
  848. $lfcnt=0;
  849. foreach($dt as $key => $val) // main date loop
  850. {
  851. $flg=0;
  852. for($i=0 ; $i < $mscount ; $i++) // set Myspace views according to main loop date
  853. {
  854. if($mss_data[$i]['s']['etime']==$val)
  855. {
  856. $mscomment[$cnt]= $mss_data[$i]['s']['comments'] ;
  857. $mscommentcount += $mscomment[$cnt] ;
  858. $flg=1;
  859. $cnt++;
  860. break;
  861. } // if($mss_data[$i]['s']['etime'])==$val)
  862. } // for($i=0 ; $i < $mscount-1 ; $i++)
  863. if($flg==0)
  864. {
  865. $mscomment[$cnt]=0;
  866. $cnt++;
  867. }
  868. $flg=0;
  869. $count=0;
  870. for($i=0 ; $i < $ytcount ; $i++) // set Youtube views according to main loop date
  871. {
  872. if($yt_data[$i]['y']['etime']==$val)
  873. {
  874. $ytcomment[$ycnt]= $yt_data[$i]['y']['comments'] ;
  875. $ytcommentcount+=$ytcomment[$ycnt] ;
  876. $flg=1;
  877. $ycnt ++;
  878. break;
  879. } // if($yt_data[$i]['y']['etime']==$val)
  880. } // for($i=0 ; $i < $ytcount-1 ; $i++)
  881. if($flg==0)
  882. {
  883. $ytcomment[$ycnt]=0;
  884. $ycnt++;
  885. }
  886. /* if($flg==0 and $albumcount!=0)
  887. {
  888. $album_play[]= 0;
  889. } // if($flg==0)
  890. */
  891. } // foreach($dt as $key => $val)
  892. } // if($this->Session->read('lastdate')=='y')
  893. else // // set data according to date for Weekly & Monthly Graph
  894. {
  895. $flg=0;
  896. $mscount = count($mss);
  897. $ytcount = count($yt);
  898. $mscomment = NULL;
  899. $ytcomment=NULL;
  900. $flg=0;
  901. $cnt=0;
  902. $ycnt=0;
  903. $lfcnt=0;
  904. foreach($dt as $key => $val) // main date loop
  905. {
  906. $flg=0;
  907. for($i=0 ; $i < $mscount ; $i++) // set Myspace views according to main loop date
  908. {
  909. if(date('Y-m-d',$mss[$i]['s']['etime'])==$val)
  910. {
  911. if($i!=0)
  912. {
  913. $mscomment[$cnt]= $mss[$i]['s']['comments']-$mss[$i-1]['s']['comments'];
  914. $mscommentcount += $mscomment[$cnt] ;
  915. }
  916. else
  917. {
  918. $mscomment[$cnt] = 0;
  919. }
  920. $flg=1;
  921. $cnt++;
  922. break;
  923. } // if(date('Y-m-d',$mss[$i]['s']['etime'])==$val)
  924. } // for($i=0 ; $i < $mscount-1 ; $i++)
  925. if($flg==0)
  926. {
  927. $mscomment[$cnt]=0;
  928. $cnt++;
  929. }
  930. $flg=0;
  931. $count=0;
  932. for($i=0 ; $i < $ytcount ; $i++) // set Youtube views according to main loop date
  933. {
  934. if(date('Y-m-d',$yt[$i]['y']['etime'])==$val)
  935. {
  936. if($i!=0)
  937. {
  938. $ytcomment[$ycnt]= $yt[$i]['y']['comments']-$yt[$i-1]['y']['comments'];
  939. $ytcommentcount = $ytcomment[$ycnt] ;
  940. }else
  941. {
  942. $ytcomment[$ycnt]=0;
  943. }
  944. $flg=1;
  945. $ycnt ++;
  946. break;
  947. } // if(date('Y-m-d',$yt[$i]['y']['etime'])==$val)
  948. } // for($i=0 ; $i < $ytcount-1 ; $i++)
  949. if($flg==0)
  950. {
  951. $ytcomment[$ycnt]=0;
  952. $ycnt++;
  953. }
  954. } // foreach($dt as $key => $val)
  955. } // if($this->Session->read('lastdate')=='y')
  956. /*
  957. * Session to set Average hits
  958. */
  959. $this->Session->write('ytcommentcount',$ytcommentcount);
  960. $this->Session->write('mscommentcount',$mscommentcount);
  961. /*
  962. * youtube and myspace data
  963. */
  964. $this->Session->write('dt',$dt);
  965. $this->Session->write('mscomment',$mscomment);
  966. $this->Session->write('ytcomment',$ytcomment);
  967. $msaverage = 0;
  968. $ytaverage = 0;
  969. $lfmaverage = 0;
  970. if($this->Session->read('lastdate')=='w')
  971. {
  972. $msaverage = round($mscommentcount/7,2);
  973. $ytaverage = round($ytcommentcount/7,2);
  974. }
  975. elseif($this->Session->read('lastdate')=='m')
  976. {
  977. $mm=$this->Session->read('mm');
  978. $msaverage = round($mscommentcount/$mm,2);
  979. $ytaverage = round($ytcommentcount/$mm,2);
  980. }
  981. elseif($this->Session->read('lastdate')=='y')
  982. {
  983. $msaverage = round($mscommentcount/12,2);
  984. $ytaverage = round($ytcommentcount/12,2);
  985. }
  986. $this->Session->write('msaverage',$msaverage);
  987. $this->Session->write('ytaverage',$ytaverage);
  988. $this->Session->write('lfmaverage',$lfmaverage);
  989. return true;
  990. } // function setcommentchart()
  991. /*
  992. Name : viewschart
  993. Desc : Get graph values from Session and display graph
  994. */
  995. function viewschart()
  996. {
  997. $dt = $this->Session->read('dt');
  998. $msview = $this->Session->read('msview');
  999. $ytview = $this->Session->read('ytview');
  1000. $lfmplay = $this->Session->read('lfmplay');
  1001. $this->set('dt',$dt);
  1002. $this->set('msview',$msview);
  1003. $this->set('ytview',$ytview);
  1004. $this->set('lfmplay',$lfmplay);
  1005. }
  1006. /*
  1007. Name : setviewschart
  1008. Desc : Get graph values and return to views()
  1009. */
  1010. function setviewschart()
  1011. {
  1012. if($this->Session->check('id') and $this->Session->check('band_id'))
  1013. {
  1014. $mmm_id = $this->Session->read('id');
  1015. $band_id = $this->Session->read('band_id');
  1016. }
  1017. else
  1018. {
  1019. //$this->Session->setFlash('Session Expired');
  1020. //$this->redirect('/analytics/index/');
  1021. return ;
  1022. } // if($this->Session->check('music') and $this->Session->check('profile') and $this->Session->check('channel') and $this->Session->check('email') and $this->Session->check('topalbum'))
  1023. $mss= NULL;
  1024. $yt=NULL;
  1025. $album=NULL;
  1026. if($this->Session->read('lastdate')=='w') // weekly graphs quries
  1027. {
  1028. $qry_mss = "select s.views , s.etime from mss_stat s , mss_login l where s.mss_id = l.mss_id and l.band_id=$band_id and l.mmm_id = '$mmm_id' and l.status=1 and FROM_UNIXTIME(s.etime) between DATE_SUB(CURDATE(), INTERVAL 9 DAY) AND CURDATE( ) order by etime";
  1029. $qry_yt = "select y.views , y.etime from yt_stat y , yt_login l where y.yt_id = l.yt_id and l.band_id=$band_id and l.mmm_id='$mmm_id' and l.status=1 and FROM_UNIXTIME(y.etime) between DATE_SUB(CURDATE(), INTERVAL 9 DAY) AND CURDATE( ) order by etime";
  1030. $qry_lfm = "select sum(t.playcount) playcount , t.etime from lfm_top_tracks t , lfm_music l where l.lfm_m_id =t.lfm_m_id and l.band_id=$band_id and l.mmm_id='$mmm_id' and l.status=1 and FROM_UNIXTIME(t.etime) between DATE_SUB(CURDATE(), INTERVAL 9 DAY) AND CURDATE( ) group by t.etime order by etime";
  1031. if(!empty($this->params['url']['id']))
  1032. {
  1033. if ($this->Session->check('msv'))
  1034. {
  1035. $mss = $this->Mss->findBySql($qry_mss);
  1036. }
  1037. if ($this->Session->check('ytv'))
  1038. {
  1039. $yt = $this->Ytstat->findBySql($qry_yt);
  1040. }
  1041. if ($this->Session->check('lfmsv'))
  1042. {
  1043. $album = $this->Lfmalbum->findBySql($qry_lfm);
  1044. }
  1045. } // if(!empty($this->params['url']['id']))
  1046. else
  1047. {
  1048. $mss = $this->Mss->findBySql($qry_mss);
  1049. $yt = $this->Ytstat->findBySql($qry_yt);
  1050. $album = $this->Lfmalbum->findBySql($qry_lfm);
  1051. } // if(!empty($this->params['url']['id']))
  1052. $qry= "select DATE_SUB(CURDATE(), INTERVAL 7 DAY) last, CURDATE() curr";
  1053. $tfdate = $this->Ytstat->findBySql($qry);
  1054. $dt =NULL;
  1055. $date = NULL;
  1056. $c=0;
  1057. $dt[$c]=$tfdate['0']['0']['last'];
  1058. while($tfdate['0']['0']['curr']!=$date)
  1059. {
  1060. $date = date('Y-m-d',strtotime(date("Y-m-d", strtotime($dt[$c])) . " +1 day"));
  1061. $c ++;
  1062. if($c==7) // i.e 0-6 last 7 days
  1063. {
  1064. break;
  1065. }
  1066. $dt[$c]= $date;
  1067. } // while($tfdate['0']['0']['curr']!=$date)
  1068. } // if($this->Session->read('lastdate')=='w') // weekly graphs quries
  1069. elseif($this->Session->read('lastdate')=='m') // monthly graphs quries
  1070. {
  1071. $qry_mss = "select s.views , s.etime from mss_stat s , mss_login l where s.mss_id = l.mss_id and l.band_id=$band_id and l.mmm_id ='$mmm_id' and l.status=1 and FROM_UNIXTIME(s.etime) between DATE_SUB(CURDATE(), INTERVAL 1 Month) AND CURDATE( ) order by etime";
  1072. $qry_yt = "select y.views , y.etime from yt_stat y , yt_login l where y.yt_id = l.yt_id and l.band_id=$band_id and l.mmm_id='$mmm_id' and l.status=1 and FROM_UNIXTIME(y.etime) between DATE_SUB(CURDATE(), INTERVAL 1 Month) AND CURDATE( ) order by etime";
  1073. $qry_lfm = "select sum(t.playcount) playcount , t.etime from lfm_top_tracks t , lfm_music l where l.lfm_m_id =t.lfm_m_id and l.band_id=$band_id and l.mmm_id='$mmm_id' and l.status=1 and FROM_UNIXTIME(t.etime) between DATE_SUB(CURDATE(), INTERVAL 1 Month) AND CURDATE( ) group by t.etime order by etime";
  1074. if(!empty($this->params['url']['id']))
  1075. {
  1076. if ($this->Session->check('msv'))
  1077. {
  1078. $mss = $this->Mss->findBySql($qry_mss);
  1079. }
  1080. if ($this->Session->check('ytv'))
  1081. {
  1082. $yt = $this->Ytstat->findBySql($qry_yt);
  1083. }
  1084. if ($this->Session->check('lfmsv'))
  1085. {
  1086. $album = $this->Lfmalbum->findBySql($qry_lfm);
  1087. }
  1088. } // if(!empty($this->params['url']['id']))
  1089. else
  1090. {
  1091. $mss = $this->Mss->findBySql($qry_mss);
  1092. $yt = $this->Ytstat->findBySql($qry_yt);
  1093. $album = $this->Lfmalbum->findBySql($qry_lfm);
  1094. } // if(!empty($this->params['url']['id']))
  1095. $qry= "select DATE_SUB(CURDATE(), INTERVAL 1 Month) last, CURDATE() curr";
  1096. $tfdate = $this->Ytstat->findBySql($qry);
  1097. $dt =NULL;
  1098. $date = NULL;
  1099. $c=0;
  1100. $cdate= $tfdate['0']['0']['curr'];
  1101. $curdate = date('Y-m-d',strtotime(date("Y-m-d", strtotime($cdate)) . " -1 day"));
  1102. $d=$tfdate['0']['0']['last'];
  1103. $dt[$c]=date('Y-m-d',strtotime(date("Y-m-d", strtotime($d))));
  1104. while($curdate!=$date)
  1105. {
  1106. $date = date('Y-m-d',strtotime(date("Y-m-d", strtotime($dt[$c])) . " +1 day"));
  1107. $c ++;
  1108. $dt[$c]= $date;
  1109. } // while($tfdate['0']['0']['curr']!=$date)
  1110. $this->Session->write('mm',count($dt));
  1111. } // elseif($this->Session->read('lastdate')=='m') // monthly graphs quries
  1112. elseif($this->Session->read('lastdate')=='y') // yearly graphs quries
  1113. {
  1114. $qry_mss = "select s.views , s.etime from mss_stat s , mss_login l where s.mss_id = l.mss_id and l.band_id=$band_id and l.mmm_id = '$mmm_id' and l.status=1 and FROM_UNIXTIME(s.etime) between DATE_SUB(CURDATE(), INTERVAL 1 Year) AND CURDATE( ) order by etime";
  1115. $qry_yt = "select y.views , y.etime from yt_stat y , yt_login l where y.yt_id = l.yt_id and l.band_id=$band_id and l.mmm_id='$mmm_id' and l.status=1 and FROM_UNIXTIME(y.etime) between DATE_SUB(CURDATE(), INTERVAL 1 Year) AND CURDATE( ) order by etime";
  1116. // special condition applied in getyear function because of sum(t.playcount) reutrn [0][playcount] instead of [t][playcount]
  1117. $qry_lfm = "select sum(t.playcount) playcount , t.etime etime from lfm_top_tracks t , lfm_music l where l.lfm_m_id =t.lfm_m_id and l.band_id=$band_id and l.mmm_id='$mmm_id' and l.status=1 and FROM_UNIXTIME(t.etime) between DATE_SUB(CURDATE(), INTERVAL 1 Year) AND CURDATE( ) group by t.etime order by t.etime";
  1118. if(!empty($this->params['url']['id']))
  1119. {
  1120. if ($this->Session->check('msv'))
  1121. {
  1122. $mss = $this->Mss->findBySql($qry_mss);
  1123. $mss_data = $this->getyear($mss,'s','views');
  1124. }
  1125. if ($this->Session->check('ytv'))
  1126. {
  1127. $yt = $this->Ytstat->findBySql($qry_yt);
  1128. $yt_data =$this->getyear($yt,'y','views');
  1129. }
  1130. if ($this->Session->check('lfmsv'))
  1131. {
  1132. $album = $this->Lfmalbum->findBySql($qry_lfm);
  1133. $album_data = $this->getyear($album,'t','playcount');
  1134. }
  1135. } // if(!empty($this->params['url']['id']))
  1136. else
  1137. {
  1138. $mss = $this->Mss->findBySql($qry_mss);
  1139. $yt = $this->Ytstat->findBySql($qry_yt);
  1140. $album = $this->Lfmalbum->findBySql($qry_lfm);
  1141. $mss_data = $this->getyear($mss,'s','views');
  1142. $yt_data =$this->getyear($yt,'y','views');
  1143. $album_data = $this->getyear($album,'t','playcount');
  1144. } // if(!empty($this->params['url']['id']))
  1145. /*
  1146. Month Wise Yearly date create
  1147. */
  1148. $qry= "select DATE_SUB(CURDATE(), INTERVAL 1 Year) last, CURDATE() curr";
  1149. $tfdate = $this->Ytstat->findBySql($qry);
  1150. $dt =NULL;
  1151. $date = NULL;
  1152. $c=0;
  1153. $td= $tfdate['0']['0']['curr'];
  1154. $td=date('M',strtotime(date("Y-m-d", strtotime($td))));
  1155. $d=$tfdate['0']['0']['last'];
  1156. $edate=date('Y-m-d',strtotime(date("Y-m-d", strtotime($d)). " +1 Month"));
  1157. $dt[$c]=date('M',strtotime(date("Y-m-d", strtotime($d)). " +1 Month"));
  1158. while($td!=$date)
  1159. {
  1160. $date = date('M',strtotime(date("Y-m-d", strtotime($edate)) . " +1 Month"));
  1161. $c ++;
  1162. $dt[$c]= $date;
  1163. $edate=date('Y-m-d',strtotime(date("Y-m-d", strtotime($edate)). " +1 Month"));
  1164. if($c>12)
  1165. {
  1166. break;
  1167. } // if($c>12)
  1168. } // while($tfdate['0']['0']['curr']!=$date)
  1169. } // elseif($this->Session->read('lastdate')=='y') // yearly graphs quries
  1170. $msviewscount = NULL;
  1171. $ytviewscount = NULL;
  1172. $lfmviewscount = NULL;
  1173. if($this->Session->read('lastdate')=='y') // set data according to date for yearly graph
  1174. {
  1175. $flg=0;
  1176. if(empty($mss_data))
  1177. {
  1178. $mscount = 0;
  1179. }
  1180. else
  1181. {
  1182. $mscount = count($mss_data);
  1183. }
  1184. if(empty($yt_data))
  1185. {
  1186. $ytcount = 0;
  1187. }
  1188. else
  1189. {
  1190. $ytcount = count($yt_data);
  1191. }
  1192. if(empty($album_data))
  1193. {
  1194. $albumcount = 0;
  1195. }
  1196. else
  1197. {
  1198. $albumcount = count($album_data);
  1199. }
  1200. $flg=0;
  1201. $cnt=0;
  1202. $ycnt=0;
  1203. $lfcnt=0;
  1204. foreach($dt as $key => $val) // main date loop
  1205. {
  1206. $flg=0;
  1207. for($i=0 ; $i < $mscount ; $i++) // set Myspace views according to main loop date
  1208. {
  1209. if($mss_data[$i]['s']['etime']==$val)
  1210. {
  1211. $msview[$cnt]= $mss_data[$i]['s']['views'] ;
  1212. $msviewscount+=$msview[$cnt];
  1213. $flg=1;
  1214. $cnt++;
  1215. break;
  1216. } // if($mss_data[$i]['s']['etime'])==$val)
  1217. } // for($i=0 ; $i < $mscount-1 ; $i++)
  1218. if($flg==0)
  1219. {
  1220. $msview[$cnt]=0;
  1221. $cnt++;
  1222. }
  1223. $flg=0;
  1224. $count=0;
  1225. for($i=0 ; $i < $ytcount ; $i++) // set Youtube views according to main loop date
  1226. {
  1227. if($yt_data[$i]['y']['etime']==$val)
  1228. {
  1229. $ytview[$ycnt]= $yt_data[$i]['y']['views'] ;
  1230. $ytviewscount+=$ytview[$ycnt];
  1231. $flg=1;
  1232. $ycnt ++;
  1233. break;
  1234. } // if($yt_data[$i]['y']['etime']==$val)
  1235. } // for($i=0 ; $i < $ytcount-1 ; $i++)
  1236. if($flg==0)
  1237. {
  1238. $ytview[$ycnt]=0;
  1239. $ycnt++;
  1240. }
  1241. $flg=0;
  1242. for($i=0 ; $i < $albumcount ; $i++) // set Las.fm top album playcount according to main loop date
  1243. {
  1244. if($album_data[$i]['t']['etime']==$val)
  1245. {
  1246. $lfmplay[$lfcnt]= $album_data[$i]['t']['playcount'];
  1247. $lfmviewscount+=$album_play[$lfcnt];
  1248. $flg=1;
  1249. $lfcnt++;
  1250. break;
  1251. } // if($album_data[$i]['t']['etime']==$val)
  1252. } // for($i=0 ; $i < $ytcount-1 ; $i++)
  1253. if($flg==0)
  1254. {
  1255. $lfmplay[$lfcnt]=0;
  1256. $lfcnt++;
  1257. }
  1258. /* if($flg==0 and $albumcount!=0)
  1259. {
  1260. $album_play[]= 0;
  1261. } // if($flg==0)
  1262. */
  1263. } // foreach($dt as $key => $val)
  1264. } // if($this->Session->read('lastdate')=='y')
  1265. else // // set data according to date for Weekly & Monthly Graph
  1266. {
  1267. $flg=0;
  1268. $mscount = count($mss);
  1269. $ytcount = count($yt);
  1270. $albumcount = count($album);
  1271. $flg=0;
  1272. $cnt=0;
  1273. $ycnt=0;
  1274. $lfcnt=0;
  1275. foreach($dt as $key => $val) // main date loop
  1276. {
  1277. $flg=0;
  1278. for($i=0 ; $i < $mscount ; $i++) // set Myspace views according to main loop date
  1279. {
  1280. if(date('Y-m-d',$mss[$i]['s']['etime'])==$val)
  1281. {
  1282. if($i!=0)
  1283. {
  1284. $msview[$cnt]= $mss[$i]['s']['views']-$mss[$i-1]['s']['views'];
  1285. $msviewscount+=$msview[$cnt];
  1286. }
  1287. else
  1288. {
  1289. $msview[$cnt] = 0;
  1290. }
  1291. $flg=1;
  1292. $cnt++;
  1293. break;
  1294. } // if(date('Y-m-d',$mss[$i]['s']['etime'])==$val)
  1295. } // for($i=0 ; $i < $mscount-1 ; $i++)
  1296. if($flg==0)
  1297. {
  1298. $msview[$cnt]=0;
  1299. $cnt++;
  1300. }
  1301. $flg=0;
  1302. $count=0;
  1303. for($i=0 ; $i < $ytcount ; $i++) // set Youtube views according to main loop date
  1304. {
  1305. if(date('Y-m-d',$yt[$i]['y']['etime'])==$val)
  1306. {
  1307. if($i!=0)
  1308. {
  1309. $ytview[$ycnt]= $yt[$i]['y']['views']-$yt[$i-1]['y']['views'];
  1310. $ytviewscount+=$ytview[$ycnt];
  1311. }else
  1312. {
  1313. $ytview[$ycnt]=0;
  1314. }
  1315. $flg=1;
  1316. $ycnt ++;
  1317. break;
  1318. } // if(date('Y-m-d',$yt[$i]['y']['etime'])==$val)
  1319. } // for($i=0 ; $i < $ytcount-1 ; $i++)
  1320. if($flg==0)
  1321. {
  1322. $ytview[$ycnt]=0;
  1323. $ycnt++;
  1324. }
  1325. $flg=0;
  1326. for($i=0 ; $i < $albumcount ; $i++) // set Las.fm top album playcount according to main loop date
  1327. {
  1328. if(date('Y-m-d',$album[$i]['t']['etime'])==$val)
  1329. {
  1330. if($i!=0)
  1331. {
  1332. $lfmplay[$lfcnt]= $album[$i][0]['playcount']-$album[$i-1][0]['playcount'];
  1333. $lfmviewscount+=$lfmplay[$lfcnt];
  1334. }
  1335. else
  1336. {
  1337. $lfmplay[$lfcnt]=0;
  1338. }
  1339. $flg=1;
  1340. $lfcnt++;
  1341. break;
  1342. } // if(date('Y-m-d',$yt[$i]['y']['etime'])==$val)
  1343. } // for($i=0 ; $i < $ytcount-1 ; $i++)
  1344. if($flg==0)
  1345. {
  1346. $lfmplay[$lfcnt]=0;
  1347. $lfcnt++;
  1348. }
  1349. /* if($flg==0 and $albumcount!=0)
  1350. {
  1351. $album_play[]= 0;
  1352. } // if($flg==0)
  1353. */
  1354. } // foreach($dt as $key => $val)
  1355. } // if($this->Session->read('lastdate')=='y')
  1356. /*
  1357. * Session set to get weekly , monthly & yearly average / Percentage
  1358. */
  1359. $this->Session->write('msviewscount',$msviewscount);
  1360. $this->Session->write('ytviewscount',$ytviewscount);
  1361. $this->Session->write('lfmviewscount',$lfmviewscount);
  1362. /*
  1363. * Session to set Graph data
  1364. */
  1365. $this->Session->write('dt',$dt);
  1366. $this->Session->write('msview',$msview);
  1367. $this->Session->write('ytview',$ytview);
  1368. $this->Session->write('lfmplay',$lfmplay);
  1369. $msaverage = 0;
  1370. $ytaverage = 0;
  1371. $lfmaverage = 0;
  1372. if($this->Session->read('lastdate')=='w')
  1373. {
  1374. $msaverage = round($msviewscount/7,2);
  1375. $ytaverage = round($ytviewscount/7,2);
  1376. $lfmaverage = round($lfmviewscount/7,2);
  1377. }
  1378. elseif($this->Session->read('lastdate')=='m')
  1379. {
  1380. $mm=$this->Session->read('mm');
  1381. $msaverage = round($msviewscount/$mm,2);
  1382. $ytaverage = round($ytviewscount/$mm,2);
  1383. $lfmaverage = round($lfmviewscount/$mm,2);
  1384. }
  1385. elseif($this->Session->read('lastdate')=='y')
  1386. {
  1387. $msaverage = round($msviewscount/12,2);
  1388. $ytaverage = round($ytviewscount/12,2);
  1389. $lfmaverage = round($lfmviewscount/12,2);
  1390. }
  1391. $this->Session->write('msaverage',$msaverage);
  1392. $this->Session->write('ytaverage',$ytaverage);
  1393. $this->Session->write('lfmaverage',$lfmaverage);
  1394. return true;
  1395. } // function viewschart()
  1396. /*
  1397. Name : playschart
  1398. Desc : Get graph values from sessions and display graph
  1399. */
  1400. function playschart()
  1401. {
  1402. $dt = $this->Session->read('dt');
  1403. $msplays = $this->Session->read('msplays');
  1404. $ytplays = $this->Session->read('ytplays');
  1405. $lfmplays = $this->Session->read('lfmplays');
  1406. $this->set('dt',$dt);
  1407. $this->set('msplays',$msplays);
  1408. $this->set('ytplays',$ytplays);
  1409. $this->set('lfmplays',$lfmplays);
  1410. } // function playschart()
  1411. /*
  1412. Name : setplayschart
  1413. Desc : Get graph values and return to plays()
  1414. */
  1415. function setplayschart()
  1416. {
  1417. if($this->Session->check('id') and $this->Session->check('band_id') and $this->Session->check('mssvideo') and $this->Session->check('video') and $this->Session->check('toptrack'))
  1418. {
  1419. $mmm_id = $this->Session->read('id');
  1420. $band_id = $this->Session->read('band_id');
  1421. $mssvideo = addslashes($this->Session->read('mssvideo'));
  1422. $video = addslashes($this->Session->read('video'));
  1423. $lfm_track = addslashes($this->Session->read('toptrack'));
  1424. }
  1425. else
  1426. {
  1427. //$this->Session->setFlash('Session Expired');
  1428. //$this->redirect('/analytics/index/');
  1429. return ;
  1430. } // if($this->Session->check('music') and $this->Session->check('profile') and $this->Session->ch
  1431. $mss= NULL;
  1432. $yt=NULL;
  1433. $album=NULL;
  1434. if($this->Session->read('lastdate')=='w') // weekly graphs quries
  1435. {
  1436. $qry_mss = "select s.plays , s.etime from mss_play_stat s , mss_login l where s.title='$mssvideo' and s.mss_id = l.mss_id and l.band_id=$band_id and l.mmm_id = '$mmm_id' and l.status=1 and FROM_UNIXTIME(s.etime) between DATE_SUB(CURDATE(), INTERVAL 9 DAY) AND CURDATE( ) order by etime";
  1437. $qry_yt = "select y.views plays , y.etime from yt_comments_stat y , yt_login l where title='$video' and y.yt_id = l.yt_id and l.band_id=$band_id and l.mmm_id='$mmm_id' and l.status=1 and FROM_UNIXTIME(y.etime) between DATE_SUB(CURDATE(), INTERVAL 9 DAY) AND CURDATE( ) order by etime";
  1438. $qry_lfm = "select t.playcount plays , t.etime from lfm_top_tracks t , lfm_music l where t.name='$lfm_track' and l.lfm_m_id =t.lfm_m_id and l.band_id=$band_id and l.mmm_id='$mmm_id' and l.status=1 and FROM_UNIXTIME(t.etime) between DATE_SUB(CURDATE(), INTERVAL 9 DAY) AND CURDATE( ) order by etime";
  1439. if(!empty($this->params['url']['id']))
  1440. {
  1441. if ($this->Session->check('msp'))
  1442. {
  1443. $mss = $this->Mss->findBySql($qry_mss);
  1444. }
  1445. if ($this->Session->check('ytp'))
  1446. {
  1447. $yt = $this->Ytstat->findBySql($qry_yt);
  1448. }
  1449. if ($this->Session->check('lfmsp'))
  1450. {
  1451. $lfm = $this->Ytstat->findBySql($qry_lfm);
  1452. }
  1453. } // if(!empty($this->params['url']['id']))
  1454. else
  1455. {
  1456. $mss = $this->Mss->findBySql($qry_mss);
  1457. $yt = $this->Ytstat->findBySql($qry_yt);
  1458. $lfm = $this->Ytstat->findBySql($qry_lfm);
  1459. } // if(!empty($this->params['url']['id']))
  1460. $qry= "select DATE_SUB(CURDATE(), INTERVAL 7 DAY) last, CURDATE() curr";
  1461. $tfdate = $this->Ytstat->findBySql($qry);
  1462. $dt =NULL;
  1463. $date = NULL;
  1464. $c=0;
  1465. $dt[$c]=$tfdate['0']['0']['last'];
  1466. while($tfdate['0']['0']['curr']!=$date)
  1467. {
  1468. $date = date('Y-m-d',strtotime(date("Y-m-d", strtotime($dt[$c])) . " +1 day"));
  1469. $c ++;
  1470. if($c==7) // i.e 0-6 last 7 days
  1471. {
  1472. break;
  1473. }
  1474. $dt[$c]= $date;
  1475. } // while($tfdate['0']['0']['curr']!=$date)
  1476. } // if($this->Session->read('lastdate')=='w') // weekly graphs quries
  1477. elseif($this->Session->read('lastdate')=='m') // monthly graphs quries
  1478. {
  1479. $qry_mss = "select s.plays , s.etime from mss_play_stat s , mss_login l where s.title='$mssvideo' and s.mss_id = l.mss_id and l.band_id=$band_id and l.mmm_id = '$mmm_id' and l.status=1 and FROM_UNIXTIME(s.etime) between DATE_SUB(CURDATE(), INTERVAL 1 Month) AND CURDATE( ) order by etime";
  1480. $qry_yt = "select y.views plays , y.etime from yt_comments_stat y , yt_login l where y.title='$video' and y.yt_id = l.yt_id and l.band_id=$band_id and l.mmm_id='$mmm_id' and l.status=1 and FROM_UNIXTIME(y.etime) between DATE_SUB(CURDATE(), INTERVAL 1 Month) AND CURDATE( ) order by etime";
  1481. $qry_lfm = "select t.playcount plays , t.etime from lfm_top_tracks t , lfm_music l where t.name='$lfm_track' and l.lfm_m_id =t.lfm_m_id and l.band_id=$band_id and l.mmm_id='$mmm_id' and l.status=1 and FROM_UNIXTIME(t.etime) between DATE_SUB(CURDATE(), INTERVAL 1 Month) AND CURDATE( ) order by etime";
  1482. if(!empty($this->params['url']['id']))
  1483. {
  1484. if ($this->Session->check('msp'))
  1485. {
  1486. $mss = $this->Mss->findBySql($qry_mss);
  1487. }
  1488. if ($this->Session->check('ytp'))
  1489. {
  1490. $yt = $this->Ytstat->findBySql($qry_yt);
  1491. }
  1492. if ($this->Session->check('lfmsp'))
  1493. {
  1494. $lfm = $this->Ytstat->findBySql($qry_lfm);
  1495. }
  1496. } // if(!empty($this->params['url']['id']))
  1497. else
  1498. {
  1499. $mss = $this->Mss->findBySql($qry_mss);
  1500. $yt = $this->Ytstat->findBySql($qry_yt);
  1501. $lfm = $this->Ytstat->findBySql($qry_lfm);
  1502. } // if(!empty($this->params['url']['id']))
  1503. $qry= "select DATE_SUB(CURDATE(), INTERVAL 1 Month) last, CURDATE() curr";
  1504. $tfdate = $this->Ytstat->findBySql($qry);
  1505. $dt =NULL;
  1506. $date = NULL;
  1507. $c=0;
  1508. $cdate= $tfdate['0']['0']['curr'];
  1509. $curdate = date('Y-m-d',strtotime(date("Y-m-d", strtotime($cdate)) . " -1 day"));
  1510. $d=$tfdate['0']['0']['last'];
  1511. $dt[$c]=date('Y-m-d',strtotime(date("Y-m-d", strtotime($d)) . " +1 day"));
  1512. while($curdate!=$date)
  1513. {
  1514. $date = date('Y-m-d',strtotime(date("Y-m-d", strtotime($dt[$c])) . " +1 day"));
  1515. $c ++;
  1516. $dt[$c]= $date;
  1517. } // while($tfdate['0']['0']['curr']!=$date)
  1518. $this->Session->write('mm',count($dt));
  1519. } // elseif($this->Session->read('lastdate')=='m') // monthly graphs quries
  1520. elseif($this->Session->read('lastdate')=='y') // yearly graphs quries
  1521. {
  1522. $qry_mss = "select s.plays , s.etime from mss_play_stat s , mss_login l where s.title='$mssvideo' and s.mss_id = l.mss_id and l.band_id=$band_id and l.mmm_id = '$mmm_id' and l.status=1 and FROM_UNIXTIME(s.etime) between DATE_SUB(CURDATE(), INTERVAL 1 Year) AND CURDATE( ) order by etime";
  1523. $qry_yt = "select y.views plays , y.etime from yt_comments_stat y , yt_login l where y.title='$video' and y.yt_id = l.yt_id and l.band_id=$band_id and l.mmm_id='$mmm_id' and l.status=1 and FROM_UNIXTIME(y.etime) between DATE_SUB(CURDATE(), INTERVAL 1 Year) AND CURDATE( ) order by etime";
  1524. $qry_lfm = "select t.playcount plays , t.etime from lfm_top_tracks t , lfm_music l where t.name='$lfm_track' and l.lfm_m_id =t.lfm_m_id and l.band_id=$band_id and l.mmm_id='$mmm_id' and l.status=1 and FROM_UNIXTIME(t.etime) between DATE_SUB(CURDATE(), INTERVAL 1 Year) AND CURDATE( ) order by etime";
  1525. if(!empty($this->params['url']['id']))
  1526. {
  1527. if ($this->Session->check('msp'))
  1528. {
  1529. $mss = $this->Mss->findBySql($qry_mss);
  1530. $mss_data = $this->getyear($mss,'s','plays');
  1531. }
  1532. if ($this->Session->check('ytp'))
  1533. {
  1534. $yt = $this->Ytstat->findBySql($qry_yt);
  1535. $yt_data =$this->getyear($yt,'y','plays');
  1536. }
  1537. if ($this->Session->check('lfmsp'))
  1538. {
  1539. $lfm = $this->Ytstat->findBySql($qry_lfm);
  1540. $lfm_data =$this->getyear($lfm,'t','plays');
  1541. }
  1542. } // if(!empty($this->params['url']['id']))
  1543. else
  1544. {
  1545. /*
  1546. select sum(s.views) , date_format(FROM_UNIXTIME(s.etime),'%m') from mss_stat s group by date_format(FROM_UNIXTIME(s.etime),'%m')
  1547. */
  1548. $mss = $this->Mss->findBySql($qry_mss);
  1549. $yt = $this->Ytstat->findBySql($qry_yt);
  1550. $lfm = $this->Ytstat->findBySql($qry_lfm);
  1551. $mss_data = $this->getyear($mss,'s','plays');
  1552. $yt_data =$this->getyear($yt,'y','plays');
  1553. $lfm_data =$this->getyear($lfm,'t','plays');
  1554. } // if(!empty($this->params['url']['id']))
  1555. /*
  1556. Month Wise Yearly date create
  1557. */
  1558. $qry= "select DATE_SUB(CURDATE(), INTERVAL 1 Year) last, CURDATE() curr";
  1559. $tfdate = $this->Ytstat->findBySql($qry);
  1560. $dt =NULL;
  1561. $date = NULL;
  1562. $c=0;
  1563. $td= $tfdate['0']['0']['curr'];
  1564. $td=date('M',strtotime(date("Y-m-d", strtotime($td))));
  1565. $d=$tfdate['0']['0']['last'];
  1566. $edate=date('Y-m-d',strtotime(date("Y-m-d", strtotime($d)). " +1 Month"));
  1567. $dt[$c]=date('M',strtotime(date("Y-m-d", strtotime($d)). " +1 Month"));
  1568. while($td!=$date)
  1569. {
  1570. $date = date('M',strtotime(date("Y-m-d", strtotime($edate)) . " +1 Month"));
  1571. $c ++;
  1572. $dt[$c]= $date;
  1573. $edate=date('Y-m-d',strtotime(date("Y-m-d", strtotime($edate)). " +1 Month"));
  1574. if($c>12)
  1575. {
  1576. break;
  1577. } // if($c>12)
  1578. } // while($tfdate['0']['0']['curr']!=$date)
  1579. } // elseif($this->Session->read('lastdate')=='y') // yearly graphs quries
  1580. $msplayscount=0;
  1581. $ytplayscount=0;
  1582. $lfmplayscount=0;
  1583. if($this->Session->read('lastdate')=='y') // set data according to date for yearly graph
  1584. {
  1585. $flg=0;
  1586. if(empty($mss_data))
  1587. {
  1588. $mscount = 0;
  1589. }
  1590. else
  1591. {
  1592. $mscount = count($mss_data);
  1593. }
  1594. if(empty($yt_data))
  1595. {
  1596. $ytcount = 0;
  1597. }
  1598. else
  1599. {
  1600. $ytcount = count($yt_data);
  1601. }
  1602. if(empty($lfm_data))
  1603. {
  1604. $lfmcount = 0;
  1605. }
  1606. else
  1607. {
  1608. $lfmcount = count($lfm_data);
  1609. }
  1610. $cnt=0;
  1611. $ycnt=0;
  1612. $lfcnt=0;
  1613. foreach($dt as $key => $val) // main date loop
  1614. {
  1615. $flg=0;
  1616. for($i=0 ; $i < $mscount ; $i++) // set Myspace views according to main loop date
  1617. {
  1618. if($mss_data[$i]['s']['etime']==$val)
  1619. {
  1620. $msplays[$cnt]= $mss_data[$i]['s']['plays'] ;
  1621. $msplayscount += $msplays[$cnt] ;
  1622. $flg=1;
  1623. $cnt++;
  1624. break;
  1625. } // if($mss_data[$i]['s']['etime'])==$val)
  1626. } // for($i=0 ; $i < $mscount-1 ; $i++)
  1627. if($flg==0)
  1628. {
  1629. $msplays[$cnt]=0;
  1630. $cnt++;
  1631. }
  1632. $flg=0;
  1633. $count=0;
  1634. for($i=0 ; $i < $ytcount ; $i++) // set Youtube views according to main loop date
  1635. {
  1636. if($yt_data[$i]['y']['etime']==$val)
  1637. {
  1638. $ytplays[$ycnt]= $yt_data[$i]['y']['plays'] ;
  1639. $ytplayscount+=$ytplays[$ycnt] ;
  1640. $flg=1;
  1641. $ycnt ++;
  1642. break;
  1643. } // if($yt_data[$i]['y']['etime']==$val)
  1644. } // for($i=0 ; $i < $ytcount-1 ; $i++)
  1645. if($flg==0)
  1646. {
  1647. $ytplays[$ycnt]=0;
  1648. $ycnt++;
  1649. }
  1650. $flg=0;
  1651. $count=0;
  1652. for($i=0 ; $i < $lfmcount ; $i++) // set Youtube views according to main loop date
  1653. {
  1654. if($lfm_data[$i]['t']['etime']==$val)
  1655. {
  1656. $lfmplays[$lfcnt]= $lfm_data[$i]['t']['plays'] ;
  1657. $lfmplayscount+=$lfmplays[$lfcnt] ;
  1658. $flg=1;
  1659. $lfcnt ++;
  1660. break;
  1661. } // if($yt_data[$i]['y']['etime']==$val)
  1662. } // for($i=0 ; $i < $ytcount-1 ; $i++)
  1663. if($flg==0)
  1664. {
  1665. $lfmplays[$lfcnt]=0;
  1666. $lfcnt++;
  1667. }
  1668. /* if($flg==0 and $albumcount!=0)
  1669. {
  1670. $album_play[]= 0;
  1671. } // if($flg==0)
  1672. */
  1673. } // foreach($dt as $key => $val)
  1674. } // if($this->Session->read('lastdate')=='y')
  1675. else // // set data according to date for Weekly & Monthly Graph
  1676. {
  1677. $flg=0;
  1678. if(empty($mss))
  1679. {
  1680. $mscount=0;
  1681. }
  1682. else
  1683. {
  1684. $mscount = count($mss);
  1685. }
  1686. if(empty($yt))
  1687. {
  1688. $ytcount=0;
  1689. }
  1690. else
  1691. {
  1692. $ytcount = count($yt);
  1693. }
  1694. if(empty($lfm))
  1695. {
  1696. $lfmcount=0;
  1697. }
  1698. else
  1699. {
  1700. $lfmcount = count($lfm);
  1701. }
  1702. $flg=0;
  1703. $cnt=0;
  1704. $ycnt=0;
  1705. $lfcnt=0;
  1706. foreach($dt as $key => $val) // main date loop
  1707. {
  1708. $flg=0;
  1709. for($i=0 ; $i < $mscount ; $i++) // set Myspace views according to main loop date
  1710. {
  1711. if(date('Y-m-d',$mss[$i]['s']['etime'])==$val)
  1712. {
  1713. if($i!=0)
  1714. {
  1715. $msplays[$cnt]= $mss[$i]['s']['plays']-$mss[$i-1]['s']['plays'];
  1716. $msplayscount += $msplays[$cnt] ;
  1717. }
  1718. else
  1719. {
  1720. $msplays[$cnt] = 0;
  1721. }
  1722. $flg=1;
  1723. $cnt++;
  1724. break;
  1725. } // if(date('Y-m-d',$mss[$i]['s']['etime'])==$val)
  1726. } // for($i=0 ; $i < $mscount-1 ; $i++)
  1727. if($flg==0)
  1728. {
  1729. $msplays[$cnt]=0;
  1730. $cnt++;
  1731. }
  1732. $flg=0;
  1733. $count=0;
  1734. for($i=0 ; $i < $ytcount ; $i++) // set Youtube views according to main loop date
  1735. {
  1736. if(date('Y-m-d',$yt[$i]['y']['etime'])==$val)
  1737. {
  1738. if($i!=0)
  1739. {
  1740. $ytplays[$ycnt]= $yt[$i]['y']['plays']-$yt[$i-1]['y']['plays'];
  1741. $ytplayscount += $ytplays[$ycnt] ;
  1742. }else
  1743. {
  1744. $ytplays[$ycnt]=0;
  1745. }
  1746. $flg=1;
  1747. $ycnt ++;
  1748. break;
  1749. } // if(date('Y-m-d',$yt[$i]['y']['etime'])==$val)
  1750. } // for($i=0 ; $i < $ytcount-1 ; $i++)
  1751. if($flg==0)
  1752. {
  1753. $ytplays[$ycnt]=0;
  1754. $ycnt++;
  1755. }
  1756. $flg=0;
  1757. $count=0;
  1758. for($i=0 ; $i < $lfmcount ; $i++) // set Youtube views according to main loop date
  1759. {
  1760. if(date('Y-m-d',$lfm[$i]['t']['etime'])==$val)
  1761. {
  1762. if($i!=0)
  1763. {
  1764. $lfmplays[$lfcnt]= $lfm[$i]['t']['plays']-$lfm[$i-1]['t']['plays'];
  1765. $lfmplayscount += $lfmplays[$lfcnt] ;
  1766. }else
  1767. {
  1768. $lfmplays[$lfcnt]=0;
  1769. }
  1770. $flg=1;
  1771. $lfcnt ++;
  1772. break;
  1773. } // if(date('Y-m-d',$yt[$i]['y']['etime'])==$val)
  1774. } // for($i=0 ; $i < $ytcount-1 ; $i++)
  1775. if($flg==0)
  1776. {
  1777. $lfmplays[$lfcnt]=0;
  1778. $lfcnt++;
  1779. }
  1780. } // foreach($dt as $key => $val)
  1781. } // if($this->Session->read('lastdate')=='y')
  1782. /*
  1783. * Session to set Average hits
  1784. */
  1785. $this->Session->write('ytplayscount',$ytplayscount);
  1786. $this->Session->write('msplayscount',$msplayscount);
  1787. $this->Session->write('lfmplayscount',$lfmplayscount);
  1788. /*
  1789. * youtube and myspace data
  1790. */
  1791. $this->Session->write('dt',$dt);
  1792. $this->Session->write('msplays',$msplays);
  1793. $this->Session->write('ytplays',$ytplays);
  1794. $this->Session->write('lfmplays',$lfmplays);
  1795. $msaverage = NULL;
  1796. $ytaverage = NULL;
  1797. $lfmaverage = NULL;
  1798. if($this->Session->read('lastdate')=='w')
  1799. {
  1800. $msaverage = round($msplayscount/7,2);
  1801. $ytaverage = round($ytplayscount/7,2);
  1802. $lfmaverage = round($lfmplayscount/7,2);
  1803. }
  1804. elseif($this->Session->read('lastdate')=='m')
  1805. {
  1806. $mm=$this->Session->read('mm');
  1807. $msaverage = round($msplayscount/$mm,2);
  1808. $ytaverage = round($ytplayscount/$mm,2);
  1809. $lfmaverage = round($lfmplayscount/$mm,2);
  1810. }
  1811. elseif($this->Session->read('lastdate')=='y')
  1812. {
  1813. $msaverage = round($msplayscount/12,2);
  1814. $ytaverage = round($ytplayscount/12,2);
  1815. $lfmaverage = round($lfmplayscount/12,2);
  1816. }
  1817. $this->Session->write('msaverage',$msaverage);
  1818. $this->Session->write('ytaverage',$ytaverage);
  1819. $this->Session->write('lfmaverage',$lfmaverage);
  1820. return true;
  1821. } // function setplayschart()
  1822. /*
  1823. Name : hitschart
  1824. Desc : Get graph values from Session and display graph
  1825. */
  1826. function hitschart()
  1827. {
  1828. $dt = $this->Session->read('dt');
  1829. $pageshits = $this->Session->read('pageshits');
  1830. $groupshits = $this->Session->read('groupshits');
  1831. $mshit = $this->Session->read('mshit');
  1832. $ythit = $this->Session->read('ythit');
  1833. $album_play = $this->Session->read('album_play');
  1834. $this->set('dt',$dt);
  1835. $this->set('pageshits',$pageshits);
  1836. $this->set('groupshits',$groupshits);
  1837. $this->set('mshit',$mshit);
  1838. $this->set('ythit',$ythit);
  1839. $this->set('album_play',$album_play);
  1840. }
  1841. /*
  1842. Name : sethitschart
  1843. Desc : Get graph values and return to hit()
  1844. */
  1845. function sethitschart()
  1846. {
  1847. if($this->Session->check('id') and $this->Session->check('band_id'))
  1848. {
  1849. $mmm_id = $this->Session->read('id');
  1850. $band_id = $this->Session->read('band_id');
  1851. $fbpages = addslashes($this->Session->read('fbpages'));
  1852. $fbgroups = addslashes($this->Session->read('fbgroups'));
  1853. }
  1854. else
  1855. {
  1856. //$this->Session->setFlash('Session Expired');
  1857. //$this->redirect('/analytics/index/');
  1858. return ;
  1859. } // if($this->Session->check('music') and $this->Session->check('profile') and $this->Session->check('channel') and $this->Session->check('email') and $this->Session->check('topalbum'))
  1860. $mss= 0;
  1861. $yt=0;
  1862. $album=0;
  1863. $pages=0;
  1864. $groups=0;
  1865. if($this->Session->read('lastdate')=='w') // weekly graphs quries
  1866. {
  1867. $qry_mss = "select s.friends fbs , s.etime from mss_stat s , mss_login l where s.mss_id = l.mss_id and l.band_id = $band_id and l.mmm_id = '$mmm_id' and l.status=1 and FROM_UNIXTIME(s.etime) between DATE_SUB(CURDATE(), INTERVAL 9 DAY) AND CURDATE( ) order by etime";
  1868. $qry_yt = "select y.subscriber fbs , y.etime from yt_stat y , yt_login l where y.yt_id = l.yt_id and l.band_id=$band_id and l.mmm_id='$mmm_id' and l.status=1 and FROM_UNIXTIME(y.etime) between DATE_SUB(CURDATE(), INTERVAL 9 DAY) AND CURDATE( ) order by etime";
  1869. $qry_lfm = "select t.listeners fbs , t.etime from lfm_listeners t , lfm_music l where l.lfm_m_id =t.lfm_m_id and l.band_id=$band_id and l.mmm_id='$mmm_id' and l.status=1 and FROM_UNIXTIME(t.etime) between DATE_SUB(CURDATE(), INTERVAL 9 DAY) AND CURDATE( ) order by etime";
  1870. $qry_fbs_pages = "select s.fan_count fbs , s.etime from fb_pages s , fb_login l where s.name='$fbpages' and s.login_id = l.login_id and l.band_id=$band_id and l.mmm_id = '$mmm_id' and l.status=1 and FROM_UNIXTIME(s.etime) between DATE_SUB(CURDATE(), INTERVAL 9 DAY) AND CURDATE( ) order by etime";
  1871. $qry_fbs_groups = "select s.member fbs , s.etime from fb_group s , fb_login l where s.name='$fbgroups' and s.login_id = l.login_id and l.band_id=$band_id and l.mmm_id = '$mmm_id' and l.status=1 and FROM_UNIXTIME(s.etime) between DATE_SUB(CURDATE(), INTERVAL 9 DAY) AND CURDATE( ) order by etime";
  1872. if(!empty($this->params['url']['id']))
  1873. {
  1874. if ($this->Session->check('msh'))
  1875. {
  1876. $mss = $this->Mss->findBySql($qry_mss);
  1877. }
  1878. if ($this->Session->check('yth'))
  1879. {
  1880. $yt = $this->Ytstat->findBySql($qry_yt);
  1881. }
  1882. if ($this->Session->check('lfmsh'))
  1883. {
  1884. $album = $this->Lfmalbum->findBySql($qry_lfm);
  1885. }
  1886. if ($this->Session->check('fbspages'))
  1887. {
  1888. $pages = $this->Lfmalbum->findBySql($qry_fbs_pages);
  1889. }
  1890. if ($this->Session->check('fbsgroups'))
  1891. {
  1892. $groups = $this->Lfmalbum->findBySql($qry_fbs_groups);
  1893. }
  1894. } // if(!empty($this->params['url']['id']))
  1895. else
  1896. {
  1897. $mss = $this->Mss->findBySql($qry_mss);
  1898. $yt = $this->Ytstat->findBySql($qry_yt);
  1899. $album = $this->Lfmalbum->findBySql($qry_lfm);
  1900. $pages = $this->Lfmalbum->findBySql($qry_fbs_pages);
  1901. $groups = $this->Lfmalbum->findBySql($qry_fbs_groups);
  1902. } // if(!empty($this->params['url']['id']))
  1903. $qry= "select DATE_SUB(CURDATE(), INTERVAL 7 DAY) last, CURDATE() curr";
  1904. $tfdate = $this->Ytstat->findBySql($qry);
  1905. $dt =NULL;
  1906. $date = NULL;
  1907. $c=0;
  1908. $dt[$c]=$tfdate['0']['0']['last'];
  1909. while($tfdate['0']['0']['curr']!=$date)
  1910. {
  1911. $date = date('Y-m-d',strtotime(date("Y-m-d", strtotime($dt[$c])) . " +1 day"));
  1912. $c ++;
  1913. if($c==7) // i.e 0-6 last 7 days
  1914. {
  1915. break;
  1916. }
  1917. $dt[$c]= $date;
  1918. } // while($tfdate['0']['0']['curr']!=$date)
  1919. } // if($this->Session->read('lastdate')=='w') // weekly graphs quries
  1920. elseif($this->Session->read('lastdate')=='m') // monthly graphs quries
  1921. {
  1922. $qry_mss = "select s.friends fbs , s.etime from mss_stat s , mss_login l where s.mss_id = l.mss_id and l.band_id = $band_id and l.mmm_id = '$mmm_id' and l.status=1 and FROM_UNIXTIME(s.etime) between DATE_SUB(CURDATE(), INTERVAL 1 Month) AND CURDATE( ) order by etime";
  1923. $qry_yt = "select y.subscriber fbs , y.etime from yt_stat y , yt_login l where y.yt_id = l.yt_id and l.band_id = $band_id and l.mmm_id='$mmm_id' and l.status=1 and FROM_UNIXTIME(y.etime) between DATE_SUB(CURDATE(), INTERVAL 1 Month) AND CURDATE( ) order by etime";
  1924. $qry_lfm = "select t.listeners fbs , t.etime from lfm_listeners t , lfm_music l where l.lfm_m_id =t.lfm_m_id and l.band_id = $band_id and l.mmm_id='$mmm_id' and l.status=1 and FROM_UNIXTIME(t.etime) between DATE_SUB(CURDATE(), INTERVAL 1 Month) AND CURDATE( ) order by etime";
  1925. $qry_fbs_pages = "select s.fan_count fbs , s.etime from fb_pages s , fb_login l where s.name='$fbpages' and s.login_id = l.login_id and l.band_id = $band_id and l.mmm_id = '$mmm_id' and l.status=1 and FROM_UNIXTIME(s.etime) between DATE_SUB(CURDATE(), INTERVAL 1 Month) AND CURDATE( ) order by etime";
  1926. $qry_fbs_groups = "select s.member fbs , s.etime from fb_group s , fb_login l where s.name='$fbgroups' and s.login_id = l.login_id and l.band_id = $band_id and l.mmm_id = '$mmm_id' and l.status=1 and FROM_UNIXTIME(s.etime) between DATE_SUB(CURDATE(), INTERVAL 1 Month) AND CURDATE( ) order by etime";
  1927. if(!empty($this->params['url']['id']))
  1928. {
  1929. if ($this->Session->check('msh'))
  1930. {
  1931. $mss = $this->Mss->findBySql($qry_mss);
  1932. }
  1933. if ($this->Session->check('yth'))
  1934. {
  1935. $yt = $this->Ytstat->findBySql($qry_yt);
  1936. }
  1937. if ($this->Session->check('lfmsh'))
  1938. {
  1939. $album = $this->Lfmalbum->findBySql($qry_lfm);
  1940. }
  1941. if ($this->Session->check('fbspages'))
  1942. {
  1943. $pages = $this->Lfmalbum->findBySql($qry_fbs_pages);
  1944. }
  1945. if ($this->Session->check('fbsgroups'))
  1946. {
  1947. $groups = $this->Lfmalbum->findBySql($qry_fbs_groups);
  1948. }
  1949. } // if(!empty($this->params['url']['id']))
  1950. else
  1951. {
  1952. $mss = $this->Mss->findBySql($qry_mss);
  1953. $yt = $this->Ytstat->findBySql($qry_yt);
  1954. $album = $this->Lfmalbum->findBySql($qry_lfm);
  1955. $pages = $this->Lfmalbum->findBySql($qry_fbs_pages);
  1956. $groups = $this->Lfmalbum->findBySql($qry_fbs_groups);
  1957. } // if(!empty($this->params['url']['id']))
  1958. $qry= "select DATE_SUB(CURDATE(), INTERVAL 1 Month) last, CURDATE() curr";
  1959. $tfdate = $this->Ytstat->findBySql($qry);
  1960. $dt =NULL;
  1961. $date = NULL;
  1962. $c=0;
  1963. $cdate= $tfdate['0']['0']['curr'];
  1964. $curdate = date('Y-m-d',strtotime(date("Y-m-d", strtotime($cdate)) . " -1 day"));
  1965. $d=$tfdate['0']['0']['last'];
  1966. $dt[$c]=date('Y-m-d',strtotime(date("Y-m-d", strtotime($d))));
  1967. while($curdate!=$date)
  1968. {
  1969. $date = date('Y-m-d',strtotime(date("Y-m-d", strtotime($dt[$c])) . " +1 day"));
  1970. $c ++;
  1971. $dt[$c]= $date;
  1972. } // while($tfdate['0']['0']['curr']!=$date)
  1973. $this->Session->write('mm',count($dt));
  1974. } // elseif($this->Session->read('lastdate')=='m') // monthly graphs quries
  1975. elseif($this->Session->read('lastdate')=='y') // yearly graphs quries
  1976. {
  1977. $qry_mss = "select s.friends fbs , s.etime from mss_stat s , mss_login l where s.mss_id = l.mss_id and l.band_id = $band_id and l.mmm_id = '$mmm_id' and l.status=1 and FROM_UNIXTIME(s.etime) between DATE_SUB(CURDATE(), INTERVAL 1 Year) AND CURDATE( ) order by etime";
  1978. $qry_yt = "select y.subscriber fbs , y.etime from yt_stat y , yt_login l where y.yt_id = l.yt_id and l.band_id = $band_id and l.mmm_id='$mmm_id' and l.status=1 and FROM_UNIXTIME(y.etime) between DATE_SUB(CURDATE(), INTERVAL 1 Year) AND CURDATE( ) order by etime";
  1979. $qry_lfm = "select t.listeners fbs , t.etime from lfm_listeners t , lfm_music l where l.lfm_m_id =t.lfm_m_id and l.band_id = $band_id and l.mmm_id='$mmm_id' and l.status=1 and FROM_UNIXTIME(t.etime) between DATE_SUB(CURDATE(), INTERVAL 1 Year) AND CURDATE( ) order by etime";
  1980. $qry_fbs_pages = "select s.fan_count fbs , s.etime from fb_pages s , fb_login l where s.name='$fbpages' and s.login_id = l.login_id and l.band_id = $band_id and l.mmm_id = '$mmm_id' and l.status=1 and FROM_UNIXTIME(s.etime) between DATE_SUB(CURDATE(), INTERVAL 1 Year) AND CURDATE( ) order by etime";
  1981. $qry_fbs_groups = "select s.member fbs , s.etime from fb_group s , fb_login l where s.name='$fbgroups' and s.login_id = l.login_id and l.band_id = $band_id and l.mmm_id = '$mmm_id' and l.status=1 and FROM_UNIXTIME(s.etime) between DATE_SUB(CURDATE(), INTERVAL 1 Year) AND CURDATE( ) order by etime";
  1982. if(!empty($this->params['url']['id']))
  1983. {
  1984. if ($this->Session->check('msh'))
  1985. {
  1986. $mss = $this->Mss->findBySql($qry_mss);
  1987. $mss_data = $this->getyear($mss,'s','fbs');
  1988. }
  1989. if ($this->Session->check('yth'))
  1990. {
  1991. $yt = $this->Ytstat->findBySql($qry_yt);
  1992. $yt_data =$this->getyear($yt,'y','fbs');
  1993. }
  1994. if ($this->Session->check('lfmsh'))
  1995. {
  1996. $album = $this->Lfmalbum->findBySql($qry_lfm);
  1997. $album_data = $this->getyear($album,'t','fbs');
  1998. }
  1999. if ($this->Session->check('fbspages'))
  2000. {
  2001. $pages = $this->Lfmalbum->findBySql($qry_fbs_pages);
  2002. $pages_data = $this->getyear($pages,'s','fbs');
  2003. }
  2004. if ($this->Session->check('fbsgroups'))
  2005. {
  2006. $groups = $this->Lfmalbum->findBySql($qry_fbs_groups);
  2007. $groups_data = $this->getyear($groups,'s','fbs');
  2008. }
  2009. } // if(!empty($this->params['url']['id']))
  2010. else
  2011. {
  2012. $mss = $this->Mss->findBySql($qry_mss);
  2013. $yt = $this->Ytstat->findBySql($qry_yt);
  2014. $album = $this->Lfmalbum->findBySql($qry_lfm);
  2015. $pages = $this->Lfmalbum->findBySql($qry_fbs_pages);
  2016. $groups = $this->Lfmalbum->findBySql($qry_fbs_groups);
  2017. $mss_data = $this->getyear($mss,'s','fbs');
  2018. $yt_data =$this->getyear($yt,'y','fbs');
  2019. $album_data = $this->getyear($album,'t','fbs');
  2020. $pages_data = $this->getyear($pages,'s','fbs');
  2021. $groups_data = $this->getyear($groups,'s','fbs');
  2022. } // if(!empty($this->params['url']['id']))
  2023. /*
  2024. Month Wise Yearly date create
  2025. */
  2026. $qry= "select DATE_SUB(CURDATE(), INTERVAL 1 Year) last, CURDATE() curr";
  2027. $tfdate = $this->Ytstat->findBySql($qry);
  2028. $dt =NULL;
  2029. $date = NULL;
  2030. $c=0;
  2031. $td= $tfdate['0']['0']['curr'];
  2032. $td=date('M',strtotime(date("Y-m-d", strtotime($td))));
  2033. $d=$tfdate['0']['0']['last'];
  2034. $edate=date('Y-m-d',strtotime(date("Y-m-d", strtotime($d)). " +1 Month"));
  2035. $dt[$c]=date('M',strtotime(date("Y-m-d", strtotime($d)). " +1 Month"));
  2036. while($td!=$date)
  2037. {
  2038. $date = date('M',strtotime(date("Y-m-d", strtotime($edate)) . " +1 Month"));
  2039. $c ++;
  2040. $dt[$c]= $date;
  2041. $edate=date('Y-m-d',strtotime(date("Y-m-d", strtotime($edate)). " +1 Month"));
  2042. if($c>12)
  2043. {
  2044. break;
  2045. } // if($c>12)
  2046. } // while($tfdate['0']['0']['curr']!=$date)
  2047. } // elseif($this->Session->read('lastdate')=='y') // yearly graphs quries
  2048. $mshitscount = 0;
  2049. $ythitscount = 0;
  2050. $lfmhitscount = 0;
  2051. $groupshitscount=0;
  2052. $pageshitscount=0;
  2053. if($this->Session->read('lastdate')=='y') // set data according to date for yearly graph
  2054. {
  2055. $flg=0;
  2056. if(empty($mss_data))
  2057. {
  2058. $mscount = 0;
  2059. }
  2060. else
  2061. {
  2062. $mscount = count($mss_data);
  2063. }
  2064. if(empty($yt_data))
  2065. {
  2066. $ytcount = 0;
  2067. }
  2068. else
  2069. {
  2070. $ytcount = count($yt_data);
  2071. }
  2072. if(empty($album_data))
  2073. {
  2074. $albumcount = 0;
  2075. }
  2076. else
  2077. {
  2078. $albumcount = count($album_data);
  2079. }
  2080. if(empty($pages_data))
  2081. {
  2082. $pagescount = 0;
  2083. }
  2084. else
  2085. {
  2086. $pagescount = count($pages_data);
  2087. }
  2088. if(empty($groups_data))
  2089. {
  2090. $groupscount = 0;
  2091. }
  2092. else
  2093. {
  2094. $groupscount = count($groups_data);
  2095. }
  2096. $flg=0;
  2097. $cnt=0;
  2098. $ycnt=0;
  2099. $lfcnt=0;
  2100. $pcnt=0;
  2101. $gcnt=0;
  2102. foreach($dt as $key => $val) // main date loop
  2103. {
  2104. $flg=0;
  2105. for($i=0 ; $i < $mscount ; $i++) // set Myspace views according to main loop date
  2106. {
  2107. if($mss_data[$i]['s']['etime']==$val)
  2108. {
  2109. $mshit[$cnt]= $mss_data[$i]['s']['fbs'] ;
  2110. $mshitscount+=$mshit[$cnt];
  2111. $flg=1;
  2112. $cnt++;
  2113. break;
  2114. } // if($mss_data[$i]['s']['etime'])==$val)
  2115. } // for($i=0 ; $i < $mscount-1 ; $i++)
  2116. if($flg==0)
  2117. {
  2118. $mshit[$cnt]=0;
  2119. $cnt++;
  2120. }
  2121. $flg=0;
  2122. $count=0;
  2123. for($i=0 ; $i < $ytcount ; $i++) // set Youtube views according to main loop date
  2124. {
  2125. if($yt_data[$i]['y']['etime']==$val)
  2126. {
  2127. $ythit[$ycnt]= $yt_data[$i]['y']['fbs'] ;
  2128. $ythitscount+=$ythit[$ycnt];
  2129. $flg=1;
  2130. $ycnt ++;
  2131. break;
  2132. } // if($yt_data[$i]['y']['etime']==$val)
  2133. } // for($i=0 ; $i < $ytcount-1 ; $i++)
  2134. if($flg==0)
  2135. {
  2136. $ythit[$ycnt]=0;
  2137. $ycnt++;
  2138. }
  2139. $flg=0;
  2140. for($i=0 ; $i < $albumcount ; $i++) // set Las.fm top album playcount according to main loop date
  2141. {
  2142. if($album_data[$i]['t']['etime']==$val)
  2143. {
  2144. $album_play[$lfcnt]= $album_data[$i]['t']['fbs'];
  2145. $lfmhitscount+=$album_play[$lfcnt];
  2146. $flg=1;
  2147. $lfcnt++;
  2148. break;
  2149. } // if($album_data[$i]['t']['etime']==$val)
  2150. } // for($i=0 ; $i < $ytcount-1 ; $i++)
  2151. if($flg==0)
  2152. {
  2153. $album_play[$lfcnt]=0;
  2154. $lfcnt++;
  2155. }
  2156. $flg=0;
  2157. $count=0;
  2158. for($i=0 ; $i < $pagescount ; $i++) // set Youtube views according to main loop date
  2159. {
  2160. if($pages_data[$i]['s']['etime']==$val)
  2161. {
  2162. $pageshits[$pcnt]= $pages_data[$i]['s']['fbs'] ;
  2163. $pageshitscount+=$pageshits[$pcnt];
  2164. $flg=1;
  2165. $pcnt ++;
  2166. break;
  2167. } // if($yt_data[$i]['y']['etime']==$val)
  2168. } // for($i=0 ; $i < $ytcount-1 ; $i++)
  2169. if($flg==0)
  2170. {
  2171. $pageshits[$pcnt]=0;
  2172. $pcnt++;
  2173. }
  2174. $flg=0;
  2175. $count=0;
  2176. for($i=0 ; $i < $groupscount ; $i++) // set Youtube views according to main loop date
  2177. {
  2178. if($groups_data[$i]['s']['etime']==$val)
  2179. {
  2180. $groupshits[$gcnt]= $groups_data[$i]['s']['fbs'] ;
  2181. $groupshitscount+=$groupshits[$gcnt];
  2182. $flg=1;
  2183. $pcnt ++;
  2184. break;
  2185. } // if($yt_data[$i]['y']['etime']==$val)
  2186. } // for($i=0 ; $i < $ytcount-1 ; $i++)
  2187. if($flg==0)
  2188. {
  2189. $groupshits[$gcnt]=0;
  2190. $gcnt++;
  2191. }
  2192. } // foreach($dt as $key => $val)
  2193. } // if($this->Session->read('lastdate')=='y')
  2194. else // // set data according to date for Weekly & Monthly Graph
  2195. {
  2196. $flg=0;
  2197. if(empty($mss))
  2198. {
  2199. $mscount = 0;
  2200. }
  2201. else
  2202. {
  2203. $mscount = count($mss);
  2204. }
  2205. if(empty($yt))
  2206. {
  2207. $ytcount = 0;
  2208. }
  2209. else
  2210. {
  2211. $ytcount = count($yt);
  2212. }
  2213. if(empty($album))
  2214. {
  2215. $albumcount = 0;
  2216. }
  2217. else
  2218. {
  2219. $albumcount = count($album);
  2220. }
  2221. if(empty($pages))
  2222. {
  2223. $pagescount = 0;
  2224. }
  2225. else
  2226. {
  2227. $pagescount = count($pages);
  2228. }
  2229. if(empty($groups))
  2230. {
  2231. $groupscount = 0;
  2232. }
  2233. else
  2234. {
  2235. $groupscount = count($groups);
  2236. }
  2237. $flg=0;
  2238. $cnt=0;
  2239. $ycnt=0;
  2240. $lfcnt=0;
  2241. $pcnt=0;
  2242. $gcnt=0;
  2243. foreach($dt as $key => $val) // main date loop
  2244. {
  2245. $flg=0;
  2246. for($i=0 ; $i < $mscount ; $i++) // set Myspace views according to main loop date
  2247. {
  2248. if(date('Y-m-d',$mss[$i]['s']['etime'])==$val)
  2249. {
  2250. if($i!=0)
  2251. {
  2252. $mshit[$cnt]= $mss[$i]['s']['fbs']-$mss[$i-1]['s']['fbs'];
  2253. $mshitscount+=$mshit[$cnt];
  2254. }
  2255. else
  2256. {
  2257. $mshit[$cnt] = 0;
  2258. }
  2259. $flg=1;
  2260. $cnt++;
  2261. break;
  2262. } // if(date('Y-m-d',$mss[$i]['s']['etime'])==$val)
  2263. } // for($i=0 ; $i < $mscount-1 ; $i++)
  2264. if($flg==0)
  2265. {
  2266. $mshit[$cnt]=0;
  2267. $cnt++;
  2268. }
  2269. $flg=0;
  2270. $count=0;
  2271. for($i=0 ; $i < $ytcount ; $i++) // set Youtube views according to main loop date
  2272. {
  2273. if(date('Y-m-d',$yt[$i]['y']['etime'])==$val)
  2274. {
  2275. if($i!=0)
  2276. {
  2277. $ythit[$ycnt]= $yt[$i]['y']['fbs']-$yt[$i-1]['y']['fbs'];
  2278. $ythitscount+=$ythit[$ycnt];
  2279. }else
  2280. {
  2281. $ythit[$ycnt]=0;
  2282. }
  2283. $flg=1;
  2284. $ycnt ++;
  2285. break;
  2286. } // if(date('Y-m-d',$yt[$i]['y']['etime'])==$val)
  2287. } // for($i=0 ; $i < $ytcount-1 ; $i++)
  2288. if($flg==0)
  2289. {
  2290. $ythit[$ycnt]=0;
  2291. $ycnt++;
  2292. }
  2293. $flg=0;
  2294. for($i=0 ; $i < $albumcount ; $i++) // set Las.fm top album playcount according to main loop date
  2295. {
  2296. if(date('Y-m-d',$album[$i]['t']['etime'])==$val)
  2297. {
  2298. if($i!=0)
  2299. {
  2300. $album_play[$lfcnt]= $album[$i]['t']['fbs']-$album[$i-1]['t']['fbs'];
  2301. $lfmhitscount+=$album_play[$lfcnt];
  2302. }
  2303. else
  2304. {
  2305. $album_play[$lfcnt]=0;
  2306. }
  2307. $flg=1;
  2308. $lfcnt++;
  2309. break;
  2310. } // if(date('Y-m-d',$yt[$i]['y']['etime'])==$val)
  2311. } // for($i=0 ; $i < $ytcount-1 ; $i++)
  2312. if($flg==0)
  2313. {
  2314. $album_play[$lfcnt]=0;
  2315. $lfcnt++;
  2316. }
  2317. $flg=0;
  2318. for($i=0 ; $i < $pagescount ; $i++) // set Youtube views according to main loop date
  2319. {
  2320. if(date('Y-m-d',$pages[$i]['s']['etime'])==$val)
  2321. {
  2322. if($i!=0)
  2323. {
  2324. $pageshits[$pcnt]= $pages[$i]['s']['fbs']-$pages[$i-1]['s']['fbs'];
  2325. $pageshitscount+=$pageshits[$pcnt] ;
  2326. }else
  2327. {
  2328. $pageshits[$pcnt]=0;
  2329. }
  2330. $flg=1;
  2331. $pcnt ++;
  2332. break;
  2333. } // if(date('Y-m-d',$yt[$i]['y']['etime'])==$val)
  2334. } // for($i=0 ; $i < $ytcount-1 ; $i++)
  2335. if($flg==0)
  2336. {
  2337. $pageshits[$pcnt]=0;
  2338. $pcnt++;
  2339. }
  2340. $flg=0;
  2341. for($i=0 ; $i < $groupscount ; $i++) // set Youtube views according to main loop date
  2342. {
  2343. if(date('Y-m-d',$groups[$i]['s']['etime'])==$val)
  2344. {
  2345. if($i!=0)
  2346. {
  2347. $groupshits[$gcnt]= $groups[$i]['s']['fbs']-$groups[$i-1]['s']['fbs'];
  2348. $groupshitscount+=$groupshits[$gcnt] ;
  2349. }else
  2350. {
  2351. $groupshits[$gcnt]=0;
  2352. }
  2353. $flg=1;
  2354. $gcnt ++;
  2355. break;
  2356. } // if(date('Y-m-d',$yt[$i]['y']['etime'])==$val)
  2357. } // for($i=0 ; $i < $ytcount-1 ; $i++)
  2358. if($flg==0)
  2359. {
  2360. $groupshits[$gcnt]=0;
  2361. $gcnt++;
  2362. }
  2363. } // foreach($dt as $key => $val)
  2364. } // if($this->Session->read('lastdate')=='y')
  2365. /*
  2366. * Session set to get weekly , monthly & yearly average / Percentage
  2367. */
  2368. $this->Session->write('mshitscount',$mshitscount);
  2369. $this->Session->write('ythitscount',$ythitscount);
  2370. $this->Session->write('lfmhitscount',$lfmhitscount);
  2371. $this->Session->write('pageshitscount',$pageshitscount);
  2372. $this->Session->write('groupshitscount',$groupshitscount);
  2373. /*
  2374. * Session to set Graph data
  2375. */
  2376. $this->Session->write('dt',$dt);
  2377. $this->Session->write('mshit',$mshit);
  2378. $this->Session->write('ythit',$ythit);
  2379. $this->Session->write('album_play',$album_play);
  2380. $this->Session->write('pageshits',$pageshits);
  2381. $this->Session->write('groupshits',$groupshits);
  2382. $pagesaverage = 0;
  2383. $groupsaverage = 0;
  2384. $msaverage = 0;
  2385. $ytaverage = 0;
  2386. $lfmaverage = 0;
  2387. if($this->Session->read('lastdate')=='w')
  2388. {
  2389. $pagesaverage = round($pageshitscount/7,2);
  2390. $groupsaverage = round($groupshitscount/7,2);
  2391. $msaverage = round($mshitscount/7,2);
  2392. $ytaverage = round($ythitscount/7,2);
  2393. $lfmaverage = round($lfmhitscount/7,2);
  2394. }
  2395. elseif($this->Session->read('lastdate')=='m')
  2396. {
  2397. $mm=$this->Session->read('mm');
  2398. $pagesaverage = round($pageshitscount/$mm,2);
  2399. $groupsaverage = round($groupshitscount/$mm,2);
  2400. $msaverage = round($mshitscount/$mm,2);
  2401. $ytaverage = round($ythitscount/$mm,2);
  2402. $lfmaverage = round($lfmhitscount/$mm,2);
  2403. }
  2404. elseif($this->Session->read('lastdate')=='y')
  2405. {
  2406. $pagesaverage = round($pageshitscount/12,2);
  2407. $groupsaverage = round($groupshitscount/12,2);
  2408. $msaverage = round($mshitscount/12,2);
  2409. $ytaverage = round($ythitscount/12,2);
  2410. $lfmaverage = round($lfmhitscount/12,2);
  2411. }
  2412. $this->Session->write('pagesaverage',$pagesaverage);
  2413. $this->Session->write('groupsaverage',$groupsaverage);
  2414. $this->Session->write('msaverage',$msaverage);
  2415. $this->Session->write('ytaverage',$ytaverage);
  2416. $this->Session->write('lfmaverage',$lfmaverage);
  2417. return true;
  2418. } // function hitchart()
  2419. function getyear($mss,$type,$field)
  2420. {
  2421. /*
  2422. $views_data = NULL;
  2423. if($mss)
  2424. {
  2425. $vms=NULL;
  2426. for($i=0 ; $i<count($mss);$i++)
  2427. {
  2428. if($i==0)
  2429. {
  2430. $vms[]= array($field=>0 , 'time'=>$mss[$i][$type]['etime']);
  2431. }
  2432. else
  2433. {
  2434. if($type=='t' and $field=='playcount')
  2435. {
  2436. $vms[] = array($field=>$mss[$i][0][$field]-$mss[$i-1][0][$field],'time'=>$mss[$i][$type]['etime']);
  2437. }
  2438. else
  2439. {
  2440. $vms[] = array($field=>$mss[$i][$type][$field]-$mss[$i-1][$type][$field],'time'=>$mss[$i][$type]['etime']);
  2441. }
  2442. }
  2443. } // for($i=0 ; $i<count($mss);$i)
  2444. $j=0;
  2445. $vdata[$j]=0;
  2446. $views_data = NULL;
  2447. $count = count($vms);
  2448. $flag =0;
  2449. foreach($vms as $key => $val)
  2450. {
  2451. if($count-1!=$key)
  2452. {
  2453. $ctd=date('M',strtotime(date("Y-m-d", $val['time'])));
  2454. $ntd=date('M',strtotime(date("Y-m-d", $vms[$key+1]['time'])));
  2455. }
  2456. else
  2457. {
  2458. $vdata[$j]=$vdata[$j]+$val[$field];
  2459. break;
  2460. }
  2461. if($ctd==$ntd)
  2462. {
  2463. $vdata[$j]=$vdata[$j]+$val[$field];
  2464. } // if($ctd==$ntd)
  2465. else
  2466. {
  2467. $vdata[$j]=$vdata[$j]+$val[$field];
  2468. $views_data[][$type] = array($field=>$vdata[$j] , 'etime'=>$ctd);
  2469. $j++;
  2470. $vdata[$j]=0;
  2471. $flag=1;
  2472. }
  2473. } // foreach($vms as $key => $val)
  2474. if($flag==1) // if more than 1 month data found
  2475. {
  2476. $views_data[][$type] = array($field=>$vdata[$j] , 'etime'=>$ctd);
  2477. }
  2478. if(empty($views_data)) // if only one month data found
  2479. {
  2480. $views_data[][$type] = array($field=>$vdata[$j] , 'etime'=>$ctd);
  2481. } // if(empty($views_data))
  2482. }
  2483. return $views_data;
  2484. */
  2485. $vms=NULL;
  2486. for($i=0 ; $i<count($mss);$i++)
  2487. {
  2488. $vms[] = array($field=>$mss[$i][$type][$field],'time'=>$mss[$i][$type]['etime']);
  2489. } // for($i=0 ; $i<count($mss);$i)
  2490. $j=0;
  2491. $vdata[$j]=0;
  2492. $views_data = NULL;
  2493. $count = count($vms);
  2494. $flag =0;
  2495. if($vms)
  2496. {
  2497. if($count==1)
  2498. {
  2499. $vdata[$j]=$vms[0][$field];
  2500. $ctd=date('M',strtotime(date("Y-m-d", $vms[0]['time'])));
  2501. $views_data[][$type] = array($field=>$vdata[$j] , 'etime'=>$ctd);
  2502. } // if(count==1)
  2503. else
  2504. {
  2505. foreach($vms as $key => $val)
  2506. {
  2507. if($count-1!=$key)
  2508. {
  2509. $ctd=date('M',strtotime(date("Y-m-d", $val['time'])));
  2510. $ntd=date('M',strtotime(date("Y-m-d", $vms[$key+1]['time'])));
  2511. }
  2512. else
  2513. {
  2514. $vdata[$j]=$val[$field];
  2515. break;
  2516. }
  2517. if($ctd==$ntd)
  2518. {
  2519. $vdata[$j]=$val[$field];
  2520. } // if($ctd==$ntd)
  2521. else
  2522. {
  2523. $vdata[$j]=$val[$field];
  2524. $views_data[][$type] = array($field=>$vdata[$j] , 'etime'=>$ctd);
  2525. $j++;
  2526. $flag=1;
  2527. }
  2528. } // foreach($vms as $key => $val)
  2529. if($flag==1) // if more than 1 month data found
  2530. {
  2531. $views_data[][$type] = array($field=>$vdata[$j] , 'etime'=>$ctd);
  2532. }
  2533. if(empty($views_data)) // if only one month data found
  2534. {
  2535. $views_data[][$type] = array($field=>$vdata[$j] , 'etime'=>$ctd);
  2536. } // if(empty($views_data))
  2537. } //if(count==1)
  2538. return $views_data;
  2539. }
  2540. } // function getviewyear()
  2541. } //class AnalyticsController extends AppController {
  2542. /*
  2543. Open Flash Chart functions to display flash chart on page
  2544. */
  2545. function open_flash_chart_object_str( $width, $height, $url, $use_swfobject=true, $base='' )
  2546. {
  2547. //
  2548. // return the HTML as a string
  2549. //
  2550. return _ofc( $width, $height, $url, $use_swfobject, $base );
  2551. }
  2552. function open_flash_chart_object( $width, $height, $url, $use_swfobject=true, $base='' )
  2553. {
  2554. //
  2555. // stream the HTML into the page
  2556. //
  2557. echo _ofc( $width, $height, $url, $use_swfobject, $base );
  2558. }
  2559. function _ofc( $width, $height, $url, $use_swfobject, $base )
  2560. {
  2561. //
  2562. // I think we may use swfobject for all browsers,
  2563. // not JUST for IE...
  2564. //
  2565. //$ie = strstr(getenv('HTTP_USER_AGENT'), 'MSIE');
  2566. //
  2567. // escape the & and stuff:
  2568. //
  2569. $url = urlencode($url);
  2570. //
  2571. // output buffer
  2572. //
  2573. $out = array();
  2574. //
  2575. // check for http or https:
  2576. //
  2577. if (isset ($_SERVER['HTTPS']))
  2578. {
  2579. if (strtoupper ($_SERVER['HTTPS']) == 'ON')
  2580. {
  2581. $protocol = 'https';
  2582. }
  2583. else
  2584. {
  2585. $protocol = 'http';
  2586. }
  2587. }
  2588. else
  2589. {
  2590. $protocol = 'http';
  2591. }
  2592. //
  2593. // if there are more than one charts on the
  2594. // page, give each a different ID
  2595. //
  2596. global $open_flash_chart_seqno;
  2597. $obj_id = 'chart';
  2598. $div_name = 'flashcontent';
  2599. //$out[] = '<script type="text/javascript" src="'. $base .'js/ofc.js"></script>';
  2600. if( !isset( $open_flash_chart_seqno ) )
  2601. {
  2602. $open_flash_chart_seqno = 1;
  2603. $out[] = '<script type="text/javascript" src="'. $base .'js/swfobject.js"></script>';
  2604. }
  2605. else
  2606. {
  2607. $open_flash_chart_seqno++;
  2608. $obj_id .= '_'. $open_flash_chart_seqno;
  2609. $div_name .= '_'. $open_flash_chart_seqno;
  2610. }
  2611. if( $use_swfobject )
  2612. {
  2613. // Using library for auto-enabling Flash object on IE, disabled-Javascript proof
  2614. $out[] = '<div id="'. $div_name .'"></div>';
  2615. $out[] = '<script type="text/javascript">';
  2616. $out[] = 'var so = new SWFObject("'. $base .'open-flash-chart.swf", "'. $obj_id .'", "'. $width . '", "' . $height . '", "9", "#FFFFFF");';
  2617. //$out[] = 'so.addVariable("width", "' . $width . '");';
  2618. //$out[] = 'so.addVariable("height", "' . $height . '");';
  2619. $out[] = 'so.addVariable("data", "'. $url . '");';
  2620. $out[] = 'so.addParam("allowScriptAccess", "sameDomain");';
  2621. $out[] = 'so.write("'. $div_name .'");';
  2622. $out[] = '</script>';
  2623. $out[] = '<noscript>';
  2624. }
  2625. $out[] = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="' . $protocol . '://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" ';
  2626. $out[] = 'width="' . $width . '" height="' . $height . '" id="ie_'. $obj_id .'" align="middle">';
  2627. $out[] = '<param name="allowScriptAccess" value="sameDomain" />';
  2628. $out[] = '<param name="movie" value="'. $base .'open-flash-chart.swf?width='. $width .'&height='. $height . '&data='. $url .'" />';
  2629. $out[] = '<param name="quality" value="high" />';
  2630. $out[] = '<param name="bgcolor" value="#FFFFFF" />';
  2631. $out[] = '<embed src="'. $base .'open-flash-chart.swf?data=' . $url .'" quality="high" bgcolor="#FFFFFF" width="'. $width .'" height="'. $height .'" name="'. $obj_id .'" align="middle" allowScriptAccess="sameDomain" ';
  2632. $out[] = 'type="application/x-shockwave-flash" pluginspage="' . $protocol . '://www.macromedia.com/go/getflashplayer" id="'. $obj_id .'"/>';
  2633. $out[] = '</object>';
  2634. if ( $use_swfobject ) {
  2635. $out[] = '</noscript>';
  2636. }
  2637. return implode("\n",$out);
  2638. }
  2639. ?>