* @revision 2572  	 	    	    		  	 	  	 	  		 	 		    	 			 	   		  	 	 		 	 	   	      	  	 		 		 				 			 		  		    	 		 		  
 * @license http://www.gnu.org/licenses/gpl-3.0.txt     GNU General Public License v3  	 	    	    		  	 	  	 	  		 	 		    	 			 	   		  	 	 		 	 	   	      	  	 		 		 				 			 		  		    	 		 		  
 * @copyright (C) 2015 by CodeGravity.com - All rights reserved!  	 	    	    		  	 	  	 	  		 	 		    	 			 	   		  	 	 		 	 	   	      	  	 		 		 				 			 		  		    	 		 		  
 * @website http://www.codegravity.com  	 	    	    		  	 	  	 	  		 	 		    	 			 	   		  	 	 		 	 	   	      	  	 		 		 				 			 		  		    	 		 		  
 */
defined('_JEXEC') or die('Restricted access');
?>
  	 	    	    		  	 	  	 	  		 	 		    	 			 	   		  	 	 		 	 	   	      	  	 		 		 				 			 		  		    	 		 		  


<table width='100%'>  	 	    	    		  	 	  	 	  		 	 		    	 			 	   		  	 	 		 	 	   	      	  	 		 		 				 			 		  		    	 		 		  
  <tr>
    <td align='left'><?php 
echo "<a href='javascript:extrawatch_setDay({$prev})' id='{$prev}'>&lt;" . ExtraWatchDate::getDateByDay($prev) . "<img src='" . $this->extraWatch->config->getLiveSiteWithSuffix() . "components/com_extrawatch/img/icons/calendar.gif' border='0' align='center' /></a>";
?>
</td>  	 	    	    		  	 	  	 	  		 	 		    	 			 	   		  	 	 		 	 	   	      	  	 		 		 				 			 		  		    	 		 		  
    <td class='ewCentered'><?php 
if ($day != $today) {
    echo "<a href='javascript:extrawatch_setDay({$today})' id='{$today}'>" . _EW_STATS_TODAY . "</a>";
}
?>
</td>
    <td align='right'><?php 
if ($next <= $today) {
    echo "<a href='javascript:extrawatch_setDay({$next})' id='{$next}'><img src='" . $this->extraWatch->config->getLiveSiteWithSuffix() . "components/com_extrawatch/img/icons/calendar.gif' border='0' align='center' />" . ExtraWatchDate::getDateByDay($next) . "&gt;</a>";
}
?>
</td>  	 	    	    		  	 	  	 	  		 	 		    	 			 	   		  	 	 		 	 	   	      	  	 		 		 				 			 		  		    	 		 		  
  </tr>
</table>
 /**
  * stats
  * upper side visits statistics - unique/loads/hits  	 	    	    		  	 	  	 	  		 	 		    	 			 	   		  	 	 		 	 	   	      	  	 		 		 				 			 		  		    	 		 		  
  * @param unknown_type $week  	 	    	    		  	 	  	 	  		 	 		    	 			 	   		  	 	 		 	 	   	      	  	 		 		 				 			 		  		    	 		 		  
  * @return unknown  	 	    	    		  	 	  	 	  		 	 		    	 			 	   		  	 	 		 	 	   	      	  	 		 		 				 			 		  		    	 		 		  
  */
 function renderVisitsGraph($week = 0)
 {
     $output = "";
     $weekOfYear = ExtraWatchDate::getWeekFromTimestamp($week * 3600 * 24 * 7);
     $startDay = ExtraWatchDate::getWeekStartingDay($weekOfYear);
     $searchEngineStats = $this->extraWatch->stat->getSearchEnginesStatsBetweenDays($startDay - 1, $startDay + 6);
     $i = 0xff;
     $statsMax['unique'] = $this->extraWatch->stat->getMaxValueInGroupForWeek(EW_DB_KEY_UNIQUE, EW_DB_KEY_UNIQUE, $startDay);
     $statsMax['loads'] = $this->extraWatch->stat->getMaxValueInGroupForWeek(EW_DB_KEY_LOADS, EW_DB_KEY_LOADS, $startDay);
     //$statsMax['hits'] = $this->extraWatch->stat->getMaxValueInGroupForWeek(EW_DB_KEY_HITS, EW_DB_KEY_HITS, $startDay);
     ExtraWatchLog::debug("Start day: {$startDay} " . ExtraWatchDate::getDateByDay($startDay));
     for ($day = $startDay; $day < $startDay + 7; $day++) {
         $i -= 3;
         $percent = 0;
         //      $stats['search_engines'] = $this->extraWatch->seo->getTotalVisitsByKeyphrasesByDay($day);
         $stats['search_engines'] = $searchEngineStats[$day];
         $statsMax['search_engines'] = $stats['search_engines'];
         $stats['unique'] = $this->extraWatch->stat->getKeyValueInGroupByDate(EW_DB_KEY_UNIQUE, EW_DB_KEY_UNIQUE, $day);
         $stats['loads'] = $this->extraWatch->stat->getKeyValueInGroupByDate(EW_DB_KEY_LOADS, EW_DB_KEY_LOADS, $day);
         //$stats['hits'] = $this->extraWatch->stat->getKeyValueInGroupByDate(EW_DB_KEY_HITS, EW_DB_KEY_HITS, $day);
         if (!$stats['unique'] && !$stats['loads'] && !$stats['search_engines']) {
             //do not render empty values
             continue;
         }
         $once = "";
         foreach ($stats as $key => $value) {
             $progressBarIcon = $this->extraWatch->config->getLiveSiteWithSuffix() . "components/com_extrawatch/img/icons/progress_bar_{$key}.gif";
             $output .= "<tr><td>";
             $dow = ExtraWatchDate::getDateByDay($day, "D");
             ExtraWatchLog::debug("day of week: " . $day * 3600 * 24 . " returns: {$dow}");
             if (@(!$once[$dow])) {
                 $output .= substr(ExtraWatchDate::getDateByDay($day), 0, 6) . "&nbsp;" . $dow;
                 $once[$dow] = 1;
             }
             $output .= "</td>";
             $ratio = 0;
             if ($stats['unique']) {
                 $ratio = sprintf("%.2f", $stats['loads'] / $stats['unique']);
             }
             $percentWidth = 0;
             if ($statsMax[$key]) {
                 if ($statsMax['loads']) {
                     $percent = floor($value / $statsMax['loads'] * 145);
                 } else {
                     if (@$stats['search_engines']) {
                         $percent = floor($value / $statsMax['search_engines'] * 145);
                     }
                 }
                 $percentWidth = floor($percent);
             }
             if (@$value) {
                 switch ($key) {
                     /*            case 'hits' :  	 	    	    		  	 	  	 	  		 	 		    	 			 	   		  	 	 		 	 	   	      	  	 		 		 				 			 		  		    	 		 		  
                                   {
                                   $fontColor = "#aaaaaa";  	 	    	    		  	 	  	 	  		 	 		    	 			 	   		  	 	 		 	 	   	      	  	 		 		 				 			 		  		    	 		 		  
                                   $output .= "";//"<td align='right' style='color:" . $fontColor . "; background-color: " . $color . ";'>" . $value . "</td><td style='background-color: " . $color . ";'> <table cellpadding='0' cellspacing='0' ><tr><td style='background-color: " . $color . ";'></td><td style='color:" . $fontColor . "; background-color: " . $color . ";'>&nbsp;</td></tr></table></td>";  	 	    	    		  	 	  	 	  		 	 		    	 			 	   		  	 	 		 	 	   	      	  	 		 		 				 			 		  		    	 		 		  
                                   break;  	 	    	    		  	 	  	 	  		 	 		    	 			 	   		  	 	 		 	 	   	      	  	 		 		 				 			 		  		    	 		 		  
                                   }*/
                     case 'search_engines':
                         $fontColor = "#DFC4A5";
                         if ($stats['loads']) {
                             $percentagefromHits = floor($stats['search_engines'] / $stats['loads'] * 100);
                         }
                         $output .= "<td align='right' style='color:" . $fontColor . "; background-color: " . $color . ";'>" . $value . "</td><td style='background-color: " . $color . ";'> <table cellpadding='0' cellspacing='0' ><tr><td style='background-color: " . $color . ";'><img src='{$progressBarIcon}' style='width: " . $percentWidth . "px; height:10px' /></td><td style='color:" . $fontColor . "; background-color: " . $color . ";'> &nbsp;" . @$percentagefromHits . "%</td></tr></table></td>";
                         break;
                     case 'loads':
                         $fontColor = "#A4C9CF";
                         $output .= "<td align='right' style='color:" . $fontColor . "; background-color: " . $color . ";'>" . $value . "</td><td style='background-color: " . $color . ";'> <table cellpadding='0' cellspacing='0' ><tr><td style='background-color: " . $color . ";'><img src='{$progressBarIcon}' style='width: " . $percentWidth . "px; height:10px' /></td><td style='color:" . $fontColor . "; background-color: " . $color . ";'></td></tr></table></td>";
                         break;
                     default:
                         $fontColor = "#BFCBA7";
                         $output .= "<td align='right' style='color:" . $fontColor . "; background-color: " . $color . ";'>" . $value . "</td><td style='background-color: " . $color . ";'> <table cellpadding='0' cellspacing='0' ><tr><td style='background-color: " . $color . ";'><img src='{$progressBarIcon}' style='width: " . $percentWidth . "px; height:10px' /></td><td style='color: " . $fontColor . "; background-color: " . $color . ";'>&nbsp;" . $ratio . "x</td></tr></table></td>";
                 }
             } else {
                 $output .= "<td align='right' style='background-color: " . $color . ";'></td><td align='right' style='background-color: " . $color . ";'></td>";
             }
             $output .= "</tr>";
         }
     }
     $output .= "<tr><td colspan='3' align='right'>*  <span style='color:#DFC4A5;'>" . "from search engines" . "</span>, <span style='color:#BFCBA7;'>" . _EW_STATS_UNIQUE . "</span>, <span style='color:#A4C9CF;'>" . _EW_STATS_LOADS . "</span></td></tr>";
     return $output;
 }
 function renderPositionChangeDiff($rows, $day)
 {
     $output = "";
     if ($rows) {
         $lastAveragePosition = 0;
         foreach ($rows as $row) {
             $averagePosition = $row->averagePosition;
             if ($lastAveragePosition != $averagePosition) {
                 if ($lastAveragePosition) {
                     $diff = (double) ($averagePosition - $lastAveragePosition);
                     $diffColor = ExtraWatchTrendHTML::getDiffColor($diff, TRUE);
                     $diffImg = "<img src='" . $this->extraWatch->config->getLiveSiteWithSuffix() . "components/com_extrawatch/img/icons/trend_{$diffColor}.gif' border='0'/>";
                     if ($day == $row->date || !$day) {
                         $output .= sprintf("<td style='color: {$diffColor}' align='right'>%+.2f</td><td>{$diffImg}</td><td class='ewCentered'>%s</td>", $diff, ExtraWatchDate::getDateByDay($row->date));
                     }
                 }
                 $lastAveragePosition = $averagePosition;
             }
         }
     }
     return $output;
 }
 function renderBlockedIPs($date = 0, $expanded = FALSE, $displayedInStats = TRUE)
 {
     $output = "";
     if (!$expanded) {
         $output .= "<a href='javascript:extrawatch_blockIpManually();'>" . _EW_STATS_IP_BLOCKING_ENTER . "</a><br/>";
     }
     $total = FALSE;
     if (!@$date) {
         $total = TRUE;
     }
     $count = $this->extraWatch->block->countBlockedIPs($date);
     if (!$count && !$displayedInStats) {
         $output = ExtraWatchHelper::renderNoData();
         $output .= $this->renderAntispamHowTo();
         return $output;
     }
     $limit = $this->extraWatch->config->getConfigValue('EXTRAWATCH_STATS_MAX_ROWS');
     $output .= "<tr><th></th><th></th><th>IP</th><th>" . strtolower(_EW_STATS_HITS) . "</th>";
     if (!$displayedInStats) {
         $output .= "<th>" . _EW_BLOCKING_BAD_WORD . "</th>";
         $output .= "<th>" . _EW_BLOCKING_REASON . "</th>";
     }
     $output .= "</tr>";
     if ($count > $limit && !$expanded) {
         $output = "<tr><td colspan='4'>" . $this->extraWatchStatHTML->renderExpand('ip_blocking_title', $total) . "</td></tr>";
     }
     if (@$expanded) {
         $rows = $this->extraWatch->block->getBlockedIPs($date, 100);
         // this cannot be unlimited, because otherwise the page would not open
     } else {
         $rows = $this->extraWatch->block->getBlockedIPs($date, $limit);
     }
     $lastDate = 0;
     $i = 0;
     if (@$rows) {
         foreach ($rows as $row) {
             $icon = "";
             if (!strstr($row->ip, "*")) {
                 if (@(!$row->country)) {
                     $country = $this->extraWatch->helper->countryByIp($row->ip);
                     $this->extraWatch->block->updateCountryForBlockedIp($row->ip, $country);
                 } else {
                     $country = $row->country;
                 }
                 $countryName = $this->extraWatch->helper->countryCodeToCountryName($country);
                 if (!$country) {
                     $country = "none";
                 }
                 $icon = "<img src='" . $this->extraWatch->config->getLiveSiteWithSuffix() . "components/com_extrawatch/img/flags/" . @strtolower($country) . ".png' title='{$countryName}' alt='{$countryName}'/>";
             }
             $mapsIcon = "<img src='" . $this->extraWatch->config->getLiveSiteWithSuffix() . "components/com_extrawatch/img/icons/map_icon.gif' border='0'  " . $this->extraWatch->helper->getTooltipOnEvent() . "=\"ajax_showTooltip('" . $this->extraWatch->config->getLiveSite() . $this->extraWatch->env->getEnvironmentSuffix() . $this->extraWatch->env->renderBackendAjaxLink($this->extraWatch->config, 'ajax', 'tooltip') . "&ip=" . @$row->ip . "&env=" . $this->extraWatch->config->getEnvironment() . "&projectId=" . _EW_PROJECT_ID . "',this);return FALSE\"/>";
             if (!$displayedInStats && $lastDate != $row->date) {
                 $output .= "<tr><td colspan='4'><u>" . ExtraWatchDate::getDateByDay($row->date) . "</u></td></tr>";
                 $lastDate = $row->date;
             }
             $output .= "<tr class='tableRow" . $i++ % 2 . "'><td class='ewCentered'>" . $mapsIcon . "</td><td class='ewCentered' title='{$row->reason}'>" . $icon . "</td><td align='left' title='{$row->reason}'>" . $row->ip . "</td><td class='ewCentered' title='{$row->reason}'>" . $row->hits . "</td>";
             if (!$displayedInStats) {
                 if (!$row->badWord) {
                     $spamWordAffected = $this->extraWatch->block->checkForSpamWord($row->reason);
                     if (@$spamWordAffected) {
                         $this->extraWatch->block->updateSpamWordForBlockedIp($row->ip, $spamWordAffected);
                         $row->badWord = $spamWordAffected;
                     }
                 }
                 $output .= "<td class='ewCentered' title='" . $row->badWord . "'>" . ExtraWatchHelper::truncate($row->badWord, 10) . "</td>";
                 $output .= "<td title=\"" . ExtraWatchHelper::htmlspecialchars($row->reason) . "\">" . $this->highlightSpamWord($row->badWord, $row->reason) . "</td>";
             }
             $output .= "<td>";
             if (!$expanded) {
                 $output .= "<a  id='{$row->ip}' href='javascript:extrawatch_blockIpToggle(\"{$row->ip}\");history.go(0);' title='{$row->reason}'>" . _EW_BLOCKING_UNBLOCK . "</a>";
             } else {
                 $output .= "<a  id='{$row->ip}' href='" . $this->extraWatch->config->renderLink("antiSpam", "&action=toggleBlocking&ip=" . $row->ip) . "' title='{$row->reason}'>" . _EW_BLOCKING_UNBLOCK . "</a>";
             }
             $output .= "</td>";
             $output .= "</tr>";
         }
     }
     return $output;
 }