protected function setUp()
 {
     if (!defined('ENV')) {
         //setting up only once
         define('DS', DIRECTORY_SEPARATOR);
         define('JPATH_BASE', realpath(dirname(__FILE__) . DS . ".." . DS . ".."));
         define('ENV', 1);
         define('_EW_PROJECT_ID', "");
     }
     $this->instantiateExtraWatch();
     $this->prepareDB(true);
     $this->day = ExtraWatchDate::jwDateToday();
     $this->assertEmpty($this->extraWatch->stat->getIntValuesByName(EW_DB_KEY_KEYWORDS, $this->day));
     $this->assertEmpty($this->extraWatch->stat->getIntValuesByName(EW_DB_KEY_KEYPHRASE, $this->day));
     $this->assertEmpty($this->extraWatch->stat->getIntValuesByName(EW_DB_KEY_SEARCH_RESULT_NUM, $this->day));
     $this->assertEmpty($this->extraWatch->stat->getIntValuesByName(EW_DB_KEY_KEYWORDS, $this->day));
     $this->assertEmpty($this->extraWatch->stat->getIntValuesByName(EW_DB_KEY_KEYPHRASE, $this->day));
     $this->assertEmpty($this->extraWatch->stat->getIntValuesByName(EW_DB_KEY_REFERERS, $this->day));
     $this->assertEmpty($this->extraWatch->stat->getIntValuesByName(EW_DB_KEY_OS, $this->day));
     $this->assertEmpty($this->extraWatch->stat->getIntValuesByName(EW_DB_KEY_DEVICES, $this->day));
     $this->assertEmpty($this->extraWatch->stat->getIntValuesByName(EW_DB_KEY_BROWSER, $this->day));
 }
 /**
  * @param $ipArray
  * @param $date
  */
 public function flushIPBulkFromArray($ipArray)
 {
     $date = ExtraWatchDate::jwDateToday();
     $valuesOutputArray = array();
     $i = 0;
     foreach ($ipArray as $ip) {
         $valuesOutputArray[] = sprintf(" ('%s','%s', '%s', '%d')", $this->database->getEscaped($ip), "", EXTRAWATCH_UNKNOWN_COUNTRY, (int) $date);
         //adding reason as empty, to save db space
         if ($i < sizeof($ipArray)) {
             if ($i != 0 && $i % self::IP_BULK_IMPORT_SIZE == 0) {
                 $valuesOutput = implode(",", $valuesOutputArray) . ";";
                 $this->insertIpBulk($valuesOutput);
                 $valuesOutputArray = array();
             }
             $i++;
         }
     }
     $valuesOutput = implode(",", $valuesOutputArray) . ";";
     $this->insertIpBulk($valuesOutput);
     // remaining IP addresses
 }
?>
</h2>  	 	    	    		  	 	  	 	  		 	 		    	 			 	   		  	 	 		 	 	   	      	  	 		 		 				 			 		  		    	 		 		  
<i>This section allows you navigate between days and see the differences in percents, charts of most popular clicks by hovering on the blue charts icon</i>
<table width='100%' border="0">
  <tr>
    <td colspan="5">  	 	    	    		  	 	  	 	  		 	 		    	 			 	   		  	 	 		 	 	   	      	  	 		 		 				 			 		  		    	 		 		  
      <?php 
echo $extraWatchHTML->renderDateControlGet('heatmap', $day);
?>
  	 	    	    		  	 	  	 	  		 	 		    	 			 	   		  	 	 		 	 	   	      	  	 		 		 				 			 		  		    	 		 		  
    </td>
  </tr>
</table>
<br/>
<?php 
if ($day == ExtraWatchDate::jwDateToday()) {
    $extraWatchHeatmap->updateHeatmapStats($day);
}
?>

<?php 
echo $extraWatchHeatmapHTML->renderHeatmapTable($day);
?>
  	 	    	    		  	 	  	 	  		 	 		    	 			 	   		  	 	 		 	 	   	      	  	 		 		 				 			 		  		    	 		 		  
<i style='color: #ddd'>Displaying only first 20 records</i>  	 	    	    		  	 	  	 	  		 	 		    	 			 	   		  	 	 		 	 	   	      	  	 		 		 				 			 		  		    	 		 		  
<br/><br/>
<br/><br/>
<table width='100%' border="0">  	 	    	    		  	 	  	 	  		 	 		    	 			 	   		  	 	 		 	 	   	      	  	 		 		 				 			 		  		    	 		 		  
    <tr>
        <td colspan="5">  	 	    	    		  	 	  	 	  		 	 		    	 			 	   		  	 	 		 	 	   	      	  	 		 		 				 			 		  		    	 		 		  
            <?php 
 function renderBadge($badgeForSection)
 {
     $today = ExtraWatchDate::jwDateToday();
     switch ($badgeForSection) {
         case 'heatmap':
             $badgeValue = $this->extraWatch->heatmap->getHeatmapClickCountByDate($today);
             break;
         case 'clicks':
             $badgeValue = $this->extraWatch->heatmap->getTotalMostClickedHTMLElementsForDay($today);
             break;
         case 'users':
             $badgeValue = $this->extraWatch->user->getUserCountForDay($today);
             break;
         case 'seo':
             $badgeValue = $this->extraWatch->seo->getTotalVisitsByKeyphrasesByDay($today);
             break;
         case 'download':
             $badgeValue = $this->extraWatch->downloads->getDownloadCountForDay($today);
             break;
         case 'stats':
             $badgeValue = $this->extraWatch->stat->getCountByKeyAndDate(EW_DB_KEY_UNIQUE, $today);
             break;
         case 'visitors':
             $badgeValue = $this->extraWatch->visit->getActiveUsersCount();
             break;
         case 'antiSpam':
             $badgeValue = $this->extraWatch->block->getBlockedCountByDate($today);
             break;
             // ...
     }
     $title = @constant("_EW_BADGE_" . strtoupper($badgeForSection));
     if (@$badgeValue) {
         return "<span class=\"ew_badge\" title='{$title}''>&nbsp;" . $badgeValue . "&nbsp;</span>";
     }
 }
 static function getWeekStartingDay($week = 0)
 {
     ExtraWatchLog::debug("getting week starting day: " . $week);
     if (!$week) {
         $weekDiff = 0;
     } else {
         $currentWeek = ExtraWatchDate::getCurrentWeek();
         // OK
         $weekDiff = $currentWeek - $week;
         // difference between selected week number since 1.1.1970 and current week number
         ExtraWatchLog::debug("current week: {$currentWeek} weekDiff: {$weekDiff}");
     }
     $dayOfWeek = ExtraWatchDate::dayOfWeek();
     $dateToday = ExtraWatchDate::jwDateToday();
     return $dateToday - $dayOfWeek - $weekDiff * 7 + 1;
     // +1 to make it start on monday
 }
 function renderSEOReport($day, $fromEmail = FALSE, $renderAlsoNotChanged = FALSE)
 {
     $allTimeReport = $this->extraWatch->config->getCheckboxValue("EXTRAWATCH_SEO_SHOW_ALL_TIME_REPORT");
     $showEncryptedKeywords = $this->extraWatch->config->getCheckboxValue('EXTRAWATCH_SEO_LIST_ENCRYPTED_KEYWORDS');
     if ($allTimeReport) {
         $day = FALSE;
         // if all-time report is checked, day value won't be passed to query
     }
     $loadsPerDay = $this->extraWatch->stat->getKeyValueInGroupByDate(EW_DB_KEY_LOADS, EW_DB_KEY_LOADS, $day);
     if (!$loadsPerDay && !$allTimeReport) {
         return ExtraWatchHelper::renderNoData();
     }
     $searchEngineHits = $this->extraWatch->seo->getTotalVisitsByKeyphrasesByDay($day);
     if ($loadsPerDay) {
         $percent = sprintf("%.2f", $searchEngineHits / $loadsPerDay * 100);
     }
     if ($day) {
         $day = $day - 1;
     }
     $output = "";
     if (!_EW_CLOUD_MODE) {
         $output .= $this->renderMostDynamicKeyphrases($renderAlsoNotChanged, $day);
     }
     $output .= "<table border='0' class='table'>";
     $output .= "<tr><td></td><td align='right'><b>" . _EW_SEO_TOTAL_VISITS_FROM_SEARCH_ENGINES . ": " . $searchEngineHits . " (" . @$percent . "%)</b></td></tr>";
     $rows = $this->extraWatch->seo->getUri2KeyphrasePosUris($day);
     if ($rows) {
         foreach ($rows as $row) {
             $isChange = FALSE;
             $total = $row->valueTotal;
             $percent = 0;
             if ($loadsPerDay) {
                 $percent = sprintf("%.2f", $total / $loadsPerDay * 100);
             }
             $outputBlock = "<tr><td><h3><a href='" . $row->uri . "'>" . $row->title . "</a></h3><td align='right'><b>" . _EW_STATS_TOTAL . ": " . $total . " ({$percent}%)</b></td></tr><tr><td colspan='2'>";
             $rows2 = $this->extraWatch->seo->getUri2KeyphrasePosById($day, $row->uri2titleId);
             if ($rows2) {
                 $outputBlock .= "<table width='100%' class='tablesorter table table-striped'><thead><tr><th>" . _EW_URI . "</th><th>" . _EW_POSITION . "</th><th>" . _EW_COUNT . "</th><th>" . _EW_EMAIL_REPORTS_PERCENT . "</th><th>" . _EW_EMAIL_REPORTS_1DAY_CHANGE . "</th><th>" . _EW_EMAIL_REPORTS_7DAY_CHANGE . "</th><th>" . _EW_EMAIL_REPORTS_28DAY_CHANGE . "</th><th></th></tr></thead><tbody>";
                 $i = 0;
                 foreach ($rows2 as $row2) {
                     if (@(!$showEncryptedKeywords) && $row2->keyphrase == ExtraWatchHelper::_EW_ENCRYPTED) {
                         continue;
                     }
                     if ($loadsPerDay) {
                         $percent = sprintf("%.2f", $row2->value / $loadsPerDay * 100);
                     }
                     $isChangeForRow = $this->extraWatchStatHTML->isChange(EW_DB_KEY_SEARCH_RESULT_NUM, $row2->uri2keyphrasePosId, $day);
                     if ($renderAlsoNotChanged || $isChangeForRow) {
                         $outputBlock .= "<tr class='tableRow" . $i++ % 2 . "'><td width='100%'>" . $this->renderKeyphraseLink($row2->keyphrase) . "</td>" . "<td width='5%' align='right'>" . $row2->position . "<td width='5%' align='right'>" . $row2->value . "</td>" . "<td width='5%' align='right' style='color: #555'>(" . $percent . "%)</td>";
                         if ($day == FALSE) {
                             $dayChanged = ExtraWatchDate::jwDateToday() - 1;
                         } else {
                             $dayChanged = $day;
                         }
                         $outputBlock .= $this->extraWatchStatHTML->renderDiffTableCellsAndIcon(EW_DB_KEY_SEARCH_RESULT_NUM, $row2->uri2keyphrasePosId, $dayChanged, $fromEmail);
                         $outputBlock .= "</tr>\r\n";
                         $isChange = TRUE;
                     }
                 }
                 $outputBlock .= "</tbody></table><br/>";
             }
             if ($renderAlsoNotChanged || $isChange) {
                 $output .= $outputBlock;
             }
             $output .= "</td></tr>\r\n";
         }
     }
     $output .= "</table>";
     return $output;
 }
 function renderDiffTableCellsAndIcon($group, $origName, $day, $noIcon = FALSE)
 {
     if (@(!$day)) {
         $day = ExtraWatchDate::jwDateToday();
     }
     $oneDayDiff = $this->extraWatch->stat->getRelDiffOfTwoDays($day - 1, $day, $group, $origName);
     $sevenDayDiff = $this->extraWatch->stat->getRelDiffOfTwoDays($day - 7, $day, $group, $origName);
     $twentyEightDayDiff = $this->extraWatch->stat->getRelDiffOfTwoDays($day - 28, $day, $group, $origName);
     $oneDayDiffRendered = $this->renderPercentage($oneDayDiff);
     $sevenDayDiffRendered = $this->renderPercentage($sevenDayDiff);
     $twentyEightDayDiffRendered = $this->renderPercentage($twentyEightDayDiff);
     $trendsIcon = $this->renderTrendsIcon($group, $origName, $day);
     $output = "<td class='ewCentered'>{$oneDayDiffRendered}</td>" . "<td class='ewCentered'>{$sevenDayDiffRendered}</td>" . "<td class='ewCentered'>{$twentyEightDayDiffRendered}</td>";
     if (!$noIcon) {
         $output .= "<td class='ewCentered'>{$trendsIcon}</td>";
     }
     return $output;
 }
 function renderPagesWithHighlightedHTMLElementsTable($day = 0, $limit = 20)
 {
     if (!$day) {
         $day = ExtraWatchDate::jwDateToday();
     }
     $rows = $this->extraWatchHeatmap->getTopHeatmapUris($day, 20);
     $output = sprintf("<table  class='tablesorter table table-striped'>\n        <thead>\n        <tr><th>%s</th>  \t \t    \t    \t\t  \t \t  \t \t  \t\t \t \t\t    \t \t\t\t \t   \t\t  \t \t \t\t \t \t   \t      \t  \t \t\t \t\t \t\t\t\t \t\t\t \t\t  \t\t    \t \t\t \t\t  \n        <th>%s</th>\n        <th>%s</th>", _EW_HEATMAP_CLICKS, _EW_HEATMAP_TITLE, _EW_URI);
     $output .= sprintf("<th align='center'>%s</th><th>%s</th><th>%s</th><th></th></tr>", _EW_EMAIL_REPORTS_1DAY_CHANGE, _EW_EMAIL_REPORTS_7DAY_CHANGE, _EW_EMAIL_REPORTS_28DAY_CHANGE);
     $output .= "</thead><tbody>";
     if (!$rows) {
         $output .= "</table>";
         $output .= ExtraWatchHelper::renderNoData();
         return $output;
     }
     $maxClicksForDay = $this->extraWatchHeatmap->getMaxClicksForDay($day);
     $i = 0;
     if ($rows) {
         foreach ($rows as $row) {
             if (@$row->uri2titleId) {
                 $output .= $this->renderHeatmapTableRow($row, $day, $maxClicksForDay, $i, TRUE);
                 $i++;
             }
         }
     }
     $output .= "</tbody></table>";
     return $output;
 }
 /**
  * stats/info
  */
 function getIntValueByNameAndValue($name, $value, $date = FALSE)
 {
     if ($date == "") {
         $date = ExtraWatchDate::jwDateToday();
     }
     $query = sprintf("select `value` from #__extrawatch_info where (`group` = '%s' and `date` = '%d' and `name` = '%s') limit 1 ", $this->database->getEscaped($name), (int) $date, $this->database->getEscaped($value));
     $count = @$this->database->resultQuery($query);
     return $count;
 }
 * @website http://www.codegravity.com  	 	    	    		  	 	  	 	  		 	 		    	 			 	   		  	 	 		 	 	   	      	  	 		 		 				 			 		  		    	 		 		  
 */
defined('_JEXEC') or die('Restricted access');
?>


<h2><?php 
echo _EW_ADMINHEADER_GRAPHS;
?>
</h2>
<?php 
$group = ExtraWatchHelper::requestPost('group');
if (!$group) {
    $group = EW_DB_KEY_REFERERS;
}
$date = ExtraWatchDate::jwDateToday();
//$name = EW_DB_KEY_REFERERS;
echo $extraWatchTrendHTML->renderGraphSelectionForm($group);
$rows = $extraWatchTrendHTML->findLatestGraphDataRecursively($group, $date, FALSE);
$i = 0;
if (@$rows) {
    foreach ($rows as $row) {
        switch ($group) {
            case EW_DB_KEY_OS:
                $osDecoded = @json_decode($row->name);
                $rowName = $osDecoded->name;
                break;
            default:
                $rowName = $row->name;
                break;
        }