function __construct($database)
 {
     $this->database = $database;
     $this->env = ExtraWatchEnvFactory::getEnvironment();
     $this->config = new ExtraWatchConfig($this->database);
     $this->helper = new ExtraWatchHelper($this->database);
     $this->date = new ExtraWatchDate($this->database);
 }
 function __construct()
 {
     $this->env = ExtraWatchEnvFactory::getEnvironment();
     $this->database =& $this->env->getDatabase(_EW_PROJECT_ID);
     $this->config = new ExtraWatchConfig($this->database);
     $this->helper = new ExtraWatchHelper($this->database);
     $this->goal = new ExtraWatchGoal($this->database);
     $this->visit = new ExtraWatchVisit();
 }
 function __construct($database)
 {
     $this->database = $database;
     $this->env = ExtraWatchEnvFactory::getEnvironment();
     $this->config = new ExtraWatchConfig($this->database);
     $this->helper = new ExtraWatchHelper($this->database);
     $this->date = new ExtraWatchDate($this->database);
     $this->stat = new ExtraWatchStat($this->database);
     $this->user_agent_string = ExtraWatchInput::validate(_EW_INPUT_USER_AGENT, @$_SERVER['HTTP_USER_AGENT']);
     ///
 }
 function __construct()
 {
     $this->env = ExtraWatchEnvFactory::getEnvironment();
     $this->database = $this->env->getDatabase(_EW_PROJECT_ID);
     $this->config = new ExtraWatchConfig($this->database);
     $this->helper = new ExtraWatchHelper($this->database);
     $this->stat = new ExtraWatchStat($this->database);
     $this->block = new ExtraWatchBlock($this->database);
     $this->goal = new ExtraWatchGoal($this->database);
     $this->flow = new ExtraWatchFlow($this, $this->database);
     $this->sizes = new ExtraWatchSizes($this->database);
     $this->date = new ExtraWatchDate($this->database);
     $this->heatmap = new ExtraWatchHeatmap($this->database);
     $this->seo = new ExtraWatchSEO($this->database);
     $this->referer = new ExtraWatchReferer($this->database);
     $this->user = new ExtraWatchUser($this->database);
 }
 function sendAlertEmails($ip)
 {
     if (!$this->config->getCheckboxValue("EXTRAWATCH_USERS_SEND_ALERT_EMAILS")) {
         return;
     }
     $env = ExtraWatchEnvFactory::getEnvironment();
     ///
     $adminEmail = $this->config->getConfigValue("EXTRAWATCH_EMAIL_REPORTS_ADDRESS");
     $users = $this->getUsersSharingSameLogin();
     if (@$users) {
         foreach ($users as $user) {
             if (!$this->wasAlertSentForUserId($user->userId)) {
                 $username = $env->getUsernameById($user->userId);
                 $emailSubject = sprintf(_EW_USERS_ALERT_EMAIL_SUBJECT, $username, $ip);
                 $emailContent = _EW_USERS_ALERT_EMAIL_CONTENT;
                 $this->helper->sendEmail($env, $adminEmail, $adminEmail, $emailSubject, $emailContent);
                 $this->setAlertEmailAsSent($user->userId);
             }
         }
     }
 }

<?php 
if (!$extraWatch->config->checkLiveSite()) {
    ?>
<div style="border: 1px solid red; width:40%; padding: 10px;">  	 	    	    		  	 	  	 	  		 	 		    	 			 	   		  	 	 		 	 	   	      	  	 		 		 				 			 		  		    	 		 		  
  <?php 
    echo sprintf("" . _EW_ADMINBODY_LIVE_SITE . "", "<b>" . ExtraWatchEnvFactory::getEnvironment()->getRootSite() . "</b>", "<b>" . $extraWatch->config->getLiveSiteWithSuffix() . "</b>");
    ?>
  	 	    	    		  	 	  	 	  		 	 		    	 			 	   		  	 	 		 	 	   	      	  	 		 		 				 			 		  		    	 		 		  
  <br/><br/>
  <a href="<?php 
    echo ExtraWatchEnvFactory::getEnvironment()->renderLink("resetLiveSite", "&rand=" . $extraWatch->config->getBackendToken());
    ?>
"><?php 
    echo sprintf("" . _EW_ADMINBODY_SET_LIVE_SITE . "", ExtraWatchEnvFactory::getEnvironment()->getRootSite());
    ?>
</a>
</div>
<?php 
}
?>

<?php 
echo $extraWatch->block->checkBlocked(ExtraWatchVisit::getRemoteIPAddress());
?>
	<div <?php 
echo $extraWatch->helper->getTooltipOnEventHide();
?>
 >  	 	    	    		  	 	  	 	  		 	 		    	 			 	   		  	 	 		 	 	   	      	  	 		 		 				 			 		  		    	 		 		  
      
 public static function validate($type, $input = "")
 {
     switch ($type) {
         case _EW_INPUT_IP:
             $inputModified = $input;
             if (@strstr($inputModified, _EW_IP_SEPARATOR)) {
                 //has multiple entries splitted by "," ?
                 self::splitAndValidateMultipleIp($inputModified);
                 return $inputModified;
             } else {
                 $inputModified = self::replaceWildcardWithRealNumber($inputModified);
                 if (!(filter_var($inputModified, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) || filter_var($inputModified, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6))) {
                     throw new ExtraWatchInputException(_EW_INPUT_IP, $input);
                 }
             }
             return $input;
         case _EW_INPUT_URL:
             if (!filter_var($input, FILTER_VALIDATE_URL)) {
                 throw new ExtraWatchInputException(_EW_INPUT_URL, $input);
             }
             return $input;
         case _EW_INPUT_ONE_STRING:
             if (@$input && !filter_var($input, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH)) {
                 throw new ExtraWatchInputException(_EW_INPUT_ONE_STRING, $input);
             }
             return $input;
         case _EW_INPUT_FILE_PATH:
             $dir = realpath(dirname(__FILE__) . DS . "..");
             if (!ExtraWatchHelper::startsWith($input, $dir)) {
                 throw new ExtraWatchInputException(_EW_INPUT_FILE_PATH, $input);
             }
             return $input;
         case _EW_INPUT_FILE_PATH_TMP:
             $dir = self::getUploadTmpDir();
             if (!ExtraWatchHelper::startsWith($input, $dir)) {
                 throw new ExtraWatchInputException(_EW_INPUT_FILE_PATH_TMP, $input);
             }
             return $input;
         case _EW_INPUT_FILE_ROOT_PATH_HTACCESS:
             $env = ExtraWatchEnvFactory::getEnvironment();
             $rootPath = $env->getRootPath();
             $dir = $rootPath . DS . ".htaccess";
             if (!ExtraWatchHelper::startsWith($input, $dir)) {
                 throw new ExtraWatchInputException(_EW_INPUT_FILE_ROOT_PATH_HTACCESS, $input);
             }
             return $input;
         case _EW_INPUT_EXTRACT:
             if (@$input && $input != "getParams=") {
                 $object = @$input['params'];
                 if ($object) {
                     if ($object && $object != "getParams=") {
                         $getParams = ExtraWatchHelper::convertUrlQuery($object);
                         if ($getParams) {
                             foreach ($getParams as $getParam => $getParamValue) {
                                 if ($getParam && !array_search($getParam, unserialize(_EW_ALLOWED_PARAMS_TO_EXTRACT))) {
                                     throw new ExtraWatchInputException(_EW_INPUT_EXTRACT, $getParam);
                                 }
                             }
                         } else {
                             $reflector = new ReflectionClass(get_class($object));
                             $classFileName = dirname($reflector->getFileName());
                             if (!self::validate(_EW_INPUT_FILE_PATH, $classFileName)) {
                                 throw new ExtraWatchInputException(_EW_INPUT_EXTRACT, $classFileName);
                             }
                         }
                     }
                 }
             }
             return $input;
             break;
         case _EW_INPUT_EMAIL:
             if (filter_var($input, FILTER_VALIDATE_EMAIL) === false) {
                 throw new ExtraWatchInputException(_EW_INPUT_EMAIL, $input);
             }
             return $input;
             break;
         case _EW_INPUT_FILE_NAME:
             $tmpUploadDir = self::getUploadTmpDir();
             $tmpUploadDir = str_replace("/", DS, $tmpUploadDir);
             if (!ExtraWatchHelper::startsWith($input['file']['tmp_name'], $tmpUploadDir)) {
                 throw new ExtraWatchInputException(_EW_INPUT_FILE_NAME, $input);
             }
             return $input;
         case _EW_INPUT_FILE_EXTERNAL_PATH:
         case _EW_INPUT_DIR:
             $env = ExtraWatchEnvFactory::getEnvironment();
             if (!ExtraWatchHelper::startsWith(realpath($input), realpath($env->getCMSFileSystemRootPath()))) {
                 throw new ExtraWatchInputException(_EW_INPUT_FILE_EXTERNAL_PATH, $input);
             }
             return $input;
         case _EW_INPUT_HOST:
             $isIpValid = filter_var($input, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) || filter_var($input, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6);
             $isHostValid = preg_match("/^([a-z\\d](-*[a-z\\d])*)(\\.([a-z\\d](-*[a-z\\d])*))*\$/i", $input) && preg_match("/^.{1,253}\$/", $input) && preg_match("/^[^\\.]{1,63}(\\.[^\\.]{1,63})*\$/", $input);
             //length of each label
             if (!($isIpValid || $isHostValid)) {
                 throw new ExtraWatchInputException(_EW_INPUT_HOST, $input);
             }
             return $input;
         case _EW_INPUT_REFERRER_SAME_SITE:
             $env = ExtraWatchEnvFactory::getEnvironment();
             if (!ExtraWatchHelper::startsWith($_SERVER["HTTP_REFERER"], $env->getCMSBaseURL())) {
                 throw new ExtraWatchInputException(_EW_INPUT_REFERRER_SAME_SITE, $_SERVER["HTTP_REFERER"]);
             }
             return $input;
         case _EW_INPUT_LANGUAGE:
             $input = ExtraWatchInput::validate(_EW_INPUT_ONE_STRING, $input);
             //prevent from using anything else than single string !
             $langDir = realpath(dirname(__FILE__) . DS . ".." . DS . "lang" . DS . $input . ".php");
             if (!file_exists($langDir)) {
                 throw new ExtraWatchInputException(_EW_INPUT_LANGUAGE, $langDir);
             }
             return $input;
         default:
             return $input;
     }
 }
 function uninstall()
 {
     $env = ExtraWatchEnvFactory::getEnvironment();
     $database = $env->getDatabase();
     ExtraWatchEnvSetupWordpress::drop_tables($database);
 }
 /**
  * Returns url like: http://www.thisweburl.com/directory  	 	    	    		  	 	  	 	  		 	 		    	 			 	   		  	 	 		 	 	   	      	  	 		 		 				 			 		  		    	 		 		  
  * @return string  	 	    	    		  	 	  	 	  		 	 		    	 			 	   		  	 	 		 	 	   	      	  	 		 		 				 			 		  		    	 		 		  
  */
 static function getAbsoluteWebURL()
 {
     $hostname = ExtraWatchHelper::getProtocol() . "://" . ExtraWatchInput::validate(_EW_INPUT_HOST, $_SERVER['HTTP_HOST']);
     ///
     $scriptName = ExtraWatchInput::validate(_EW_INPUT_SCRIPT_NAME, $_SERVER['SCRIPT_NAME']);
     ///
     $subdir = str_replace("/index.php", "", $scriptName);
     $env = ExtraWatchInput::validate(_EW_INPUT_ENV, ExtraWatchEnvFactory::getEnvironment());
     ///
     $adminDirName = $env->getAdminDir();
     $subdir = str_replace("/" . $adminDirName, "", $subdir);
     return $hostname . $subdir;
 }
 /**
  * Only checking the particular directories is allowed  	 	    	    		  	 	  	 	  		 	 		    	 			 	   		  	 	 		 	 	   	      	  	 		 		 				 			 		  		    	 		 		  
  * @param  $dir
  * @return bool
  */
 function isAllowed($dir)
 {
     $env = ExtraWatchEnvFactory::getEnvironment();
     ///
     switch (get_class($env)) {
         case "ExtraWatchMagentoEnv":
             $realPathBase = realpath(".." . DS . ".." . DS . ".." . DS . ".." . DS . ".." . DS . ".." . DS);
             break;
         case "ExtraWatchWordpressEnv":
             $realPathBase = realpath(".." . DS . ".." . DS . ".." . DS);
             break;
         case "ExtraWatchPrestaShopEnv":
             $realPathBase = realpath(".." . DS . ".." . DS . ".." . DS . ".." . DS);
             break;
         default:
             $realPathBase = realpath(dirname(__FILE__) . DS . ".." . DS . ".." . DS . ".." . DS);
             break;
     }
     $dir = dirname(__FILE__) . DS . $dir;
     //"..".DS."..".DS."..".DS."modules".DS);
     $realPath = realpath($dir);
     //echo("NEW: checking whether $realPathBase is in $realPath ";
     if (!strstr($realPath, $realPathBase)) {
         return FALSE;
     }
     $allowedDirs = $this->env->getAllowedDirsToCheckForSize();
     foreach ($allowedDirs as $allowedDir) {
         //echo("NEW: checking whether $realPathBase is in $realPath ".realpath($allowedDir));
         $dirToCheck = realpath(dirname(__FILE__) . DS . $allowedDir);
         if (!strstr($dirToCheck, $realPathBase)) {
             return FALSE;
         }
     }
     return TRUE;
 }
 /**
  * goals
  */
 function checkGoals($title, $username, $ip, $came_from, $liveSite = "", $clickedXpath = "")
 {
     $query = sprintf("select * from #__extrawatch_goals");
     $rows = $this->database->objectListQuery($query);
     if (@$rows) {
         foreach ($rows as $row) {
             $achieved = array();
             if ($row->disabled) {
                 continue;
             }
             if (@trim(@$row->clicked_element_xpath_condition)) {
                 @($achieved[clicked_element_xpath_condition] = FALSE);
                 if (@$this->helper->wildcardSearch(trim(@$row->clicked_element_xpath_condition), $clickedXpath)) {
                     @($achieved[clicked_element_xpath_condition] = TRUE);
                 }
             } else {
                 if (@trim($row->uri_inversed) == "on") {
                     if (@trim($row->uri_condition)) {
                         @($achieved[uri_condition] = FALSE);
                         if (@$this->helper->wildcardSearch($row->uri_condition, trim($this->helper->getURI()))) {
                         } else {
                             @($achieved[uri_condition] = TRUE);
                         }
                     }
                 } else {
                     if (@trim($row->uri_condition)) {
                         @($achieved[uri_condition] = FALSE);
                         if (@$this->helper->wildcardSearch($row->uri_condition, trim($this->helper->getURI()))) {
                             @($achieved[uri_condition] = TRUE);
                         }
                     }
                 }
                 if (@trim($row->get_inversed) == "on") {
                     if (@trim($row->get_condition)) {
                         @($achieved[get_condition] = FALSE);
                         if (@$this->helper->wildcardSearch($row->get_condition, trim(ExtraWatchInput::validate(_EW_INPUT_ONE_STRING, ExtraWatchHelper::requestGet($row->get_var))))) {
                             ///
                         } else {
                             if ($row->get_var == "*") {
                                 $found = FALSE;
                                 foreach (ExtraWatchHelper::requestGet() as $get) {
                                     ///
                                     if ($this->helper->wildcardSearch($row->get_condition, trim($get))) {
                                         $found = TRUE;
                                     }
                                 }
                                 if ($found) {
                                     @($achieved[uri_condition] = FALSE);
                                 }
                             } else {
                                 @($achieved[uri_condition] = TRUE);
                             }
                         }
                     }
                 } else {
                     if (@trim($row->get_condition)) {
                         @($achieved[get_condition] = FALSE);
                         if (@$this->helper->wildcardSearch($row->get_condition, trim(ExtraWatchInput::validate(_EW_INPUT_ONE_STRING, ExtraWatchHelper::requestGet($row->get_var))))) {
                             ///
                             @($achieved[get_condition] = TRUE);
                         } else {
                             if ($row->get_var == "*") {
                                 foreach (ExtraWatchHelper::requestGet() as $get) {
                                     ///
                                     if ($this->helper->wildcardSearch($row->get_condition, trim($get))) {
                                         @($achieved[get_condition] = TRUE);
                                     }
                                 }
                             }
                         }
                     }
                 }
                 if (@trim($row->post_inversed) == "on") {
                     if (@trim($row->post_condition)) {
                         @($achieved[post_condition] = FALSE);
                         if (@$this->helper->wildcardSearch($row->post_condition, trim(ExtraWatchInput::validate(_EW_INPUT_ONE_STRING, ExtraWatchHelper::requestPost($row->post_var))))) {
                             ///
                         } else {
                             if ($row->post_var == "*") {
                                 $found = FALSE;
                                 foreach (ExtraWatchHelper::requestPost() as $post) {
                                     ///
                                     if ($this->helper->wildcardSearch($row->post_condition, trim($post))) {
                                         ///
                                         $found = TRUE;
                                     }
                                 }
                                 if ($found) {
                                     @($achieved[post_condition] = FALSE);
                                 }
                             } else {
                                 @($achieved[post_condition] = TRUE);
                             }
                         }
                     }
                 } else {
                     if (@trim($row->post_condition)) {
                         @($achieved[post_condition] = FALSE);
                         if (@$this->helper->wildcardSearch($row->post_condition, trim(ExtraWatchInput::validate(_EW_INPUT_ONE_STRING, ExtraWatchHelper::requestPost($row->post_var))))) {
                             ///
                             @($achieved[post_condition] = TRUE);
                         } else {
                             if ($row->post_var == "*") {
                                 foreach (ExtraWatchHelper::requestPost() as $post) {
                                     if ($this->helper->wildcardSearch($row->post_condition, trim($post))) {
                                         @($achieved[post_condition] = TRUE);
                                     }
                                 }
                             }
                         }
                     }
                 }
                 if (@trim($row->title_inversed) == "on") {
                     if (@trim($row->title_condition)) {
                         @($achieved[title_condition] = FALSE);
                         if (@$this->helper->wildcardSearch($row->title_condition, trim($title))) {
                         } else {
                             @($achieved[title_condition] = TRUE);
                         }
                     }
                 } else {
                     if (@trim($row->title_condition)) {
                         @($achieved[title_condition] = FALSE);
                         if (@$this->helper->wildcardSearch($row->title_condition, trim($title))) {
                             @($achieved[title_condition] = TRUE);
                         }
                     }
                 }
                 if (@trim($row->username_inversed) == "on") {
                     if (@trim($row->username_condition)) {
                         @($achieved[username_condition] = FALSE);
                         if (@$this->helper->wildcardSearch($row->username_condition, trim($username))) {
                         } else {
                             @($achieved[username_condition] = TRUE);
                         }
                     }
                 } else {
                     if (@trim($row->username_condition)) {
                         @($achieved[username_condition] = FALSE);
                         if (@$this->helper->wildcardSearch($row->username_condition, trim($username))) {
                             @($achieved[username_condition] = TRUE);
                         }
                     }
                 }
                 if (@trim($row->ip_inversed) == "on") {
                     if (@trim($row->ip_condition)) {
                         @($achieved[ip_condition] = FALSE);
                         if (@$this->helper->wildcardSearch($row->ip_condition, trim($ip))) {
                         } else {
                             @($achieved[ip_condition] = TRUE);
                         }
                     }
                 } else {
                     if (@trim($row->ip_condition)) {
                         @($achieved[ip_condition] = FALSE);
                         if (@$this->helper->wildcardSearch($row->ip_condition, trim($ip))) {
                             @($achieved[ip_condition] = TRUE);
                         }
                     }
                 }
                 if (@trim($row->came_from_inversed) == "on") {
                     if (@trim($row->came_from_condition)) {
                         @($achieved[came_from_condition] = FALSE);
                         if (@$this->helper->wildcardSearch($row->came_from_condition, trim($came_from)) || $this->helper->wildcardSearch($liveSite . $row->came_from_condition, trim($came_from))) {
                         } else {
                             @($achieved[came_from_condition] = TRUE);
                         }
                     }
                 } else {
                     if (@trim($row->came_from_condition)) {
                         @($achieved[came_from_condition] = FALSE);
                         if (@$this->helper->wildcardSearch($row->came_from_condition, trim($came_from)) || $this->helper->wildcardSearch($liveSite . $row->came_from_condition, trim($came_from))) {
                             @($achieved[came_from_condition] = TRUE);
                         }
                     }
                 }
                 if (@trim($row->country_inversed) == "on") {
                     if (@trim($row->country_condition)) {
                         @($achieved[came_from_condition] = FALSE);
                         $country = $this->helper->countryByIp($ip);
                         //performance optim. - checking country only if there is some condition
                         if (@$this->helper->wildcardSearch($row->country_condition, trim($country))) {
                         } else {
                             @($achieved[came_from_condition] = TRUE);
                         }
                     }
                 } else {
                     if (@trim($row->country_condition)) {
                         @($achieved[country_condition] = FALSE);
                         $country = $this->helper->countryByIp($ip);
                         //performance optim. - checking country only if there is some condition
                         if (@$this->helper->wildcardSearch($row->country_condition, trim($country))) {
                             @($achieved[country_condition] = TRUE);
                         }
                     }
                 }
             }
             if ($this->evaluateAchievedGoals($achieved)) {
                 $this->stat->increaseKeyValueInGroup(EW_DB_KEY_GOALS, $row->id);
                 $this->addIp2GoalId($ip, $row->id);
                 if ($this->config->getCheckboxBooleanValue($row->send_email)) {
                     $totalAchievedCountToday = $this->stat->getIntValueByNameAndValue(EW_DB_KEY_GOALS, $row->id);
                     $email = $this->config->getConfigValue("EXTRAWATCH_EMAIL_REPORTS_ADDRESS");
                     $env = ExtraWatchInput::validate(_EW_INPUT_ENV, ExtraWatchEnvFactory::getEnvironment());
                     $ip = ExtraWatchInput::validate(_EW_INPUT_IP, ExtraWatchVisit::getRemoteIPAddress());
                     ///
                     $subject = sprintf(_EW_GOAL_EMAIL_SUBJECT, $row->name, $totalAchievedCountToday);
                     require_once realpath(dirname(__FILE__)) . DS . "html" . DS . "class.extrawatch.visit.html.php";
                     $extraWatch = new ExtraWatchMain();
                     $extraWatchVisitHTML = new ExtraWatchVisitHTML($extraWatch);
                     $visitsOutput = $extraWatchVisitHTML->renderTable(FALSE, 0, $ip, TRUE);
                     $visitsOutput .= $extraWatchVisitHTML->renderTable(FALSE, 1, $ip, TRUE);
                     $body = "ip: <b>{$ip}</b><br/>{$visitsOutput}";
                     ExtraWatchHelper::sendEmail($env, $email, $email, $subject, $body);
                 }
                 if (@$row->redirect) {
                     $env = ExtraWatchInput::validate(_EW_INPUT_ENV, ExtraWatchEnvFactory::getEnvironment());
                     ///
                     $env->redirect(@$row->redirect);
                 }
                 if (@$row->block) {
                     $blockReason = sprintf(_EW_BLOCKED_BASED_ON_GOAL, $row->id);
                     $this->block->blockIp($ip, $blockReason);
                     try {
                         $this->block->dieWithBlockingMessage($ip);
                     } catch (ExtraWatchIPBlockedException $exception) {
                         die($exception->getBlockingMessage());
                     }
                 }
             }
         }
     }
 }
function extrawatch_mainController($task = "")
{
    $current_error_reporting = error_reporting();
    error_reporting(E_ALL & ~(E_STRICT | E_NOTICE));
    $extraWatch = new ExtraWatchMain();
    $extraWatchHTML = new ExtraWatchHTML();
    $extraWatchGoalHTML = new ExtraWatchGoalHTML($extraWatch);
    $extraWatchTrendHTML = new ExtraWatchTrendHTML($extraWatch);
    $env = ExtraWatchEnvFactory::getEnvironment();
    $queryParams = ExtraWatchHelper::getUrlQueryParams();
    $action = ExtraWatchInput::validate(_EW_INPUT_ONE_STRING, @$queryParams['action']);
    ///
    if (!$task) {
        $task = ExtraWatchInput::validate(_EW_INPUT_ONE_STRING, @$queryParams['task']);
        ///
    }
    ExtraWatchHelper::checkIfRequestPathAllowed($extraWatch, $env, $task);
    $taskFromNavigation = ExtraWatchInput::validate(_EW_INPUT_ONE_STRING, @ExtraWatchHelper::request('task'));
    ///
    if ($taskFromNavigation) {
        $task = $taskFromNavigation;
    }
    $option = ExtraWatchInput::validate(_EW_INPUT_ONE_STRING, @ExtraWatchHelper::requestGet('option'));
    ///
    $result = ExtraWatchInput::validate(_EW_INPUT_ONE_STRING, @ExtraWatchHelper::requestGet('result'));
    ///
    $params = @$queryParams['params'];
    ///
    $output = "";
    if (!$extraWatch->config->getLiveSite()) {
        $extraWatch->config->setLiveSite($env->getRootSite());
        if ($env->getRootSite() != $extraWatch->config->getLiveSite()) {
            die("<span style='color: red; font-weight: bold;'>Error: It was not possible to write data to the database! Check your database permissions</span>");
        }
    }
    $extraWatch->setup->runAdditionalSQLScripts();
    $extraWatch->config->saveRandValue();
    switch ($task) {
        case "ajax":
            $includePath = JPATH_BASE2 . DS . "components" . DS . "com_extrawatch" . DS . "ajax";
            ExtraWatchHelper::checkIfFileExistsInDir($includePath, $action . ".php");
            if ($action == "download") {
                if (ExtraWatchInput::validate(_EW_INPUT_FILE_PATH, $includePath . DS . $action . ".php")) {
                    include_once $includePath . DS . $action . ".php";
                }
                die;
            } else {
                $extraWatch->config->validateRequestToken($queryParams);
                $output = ExtraWatchHelper::get_include_contents("ajax" . DS . $action . ".php", array("params" => $params));
                die($output);
            }
            break;
        case "js":
            $extraWatch->config->validateRequestToken($queryParams);
            $includePath = "js";
            ExtraWatchHelper::checkIfFileExistsInDir(JPATH_BASE2 . DS . "components" . DS . "com_extrawatch" . DS . $includePath, $action . ".php");
            $output = ExtraWatchHelper::get_include_contents($includePath . DS . $action . ".php", array());
            die($output);
            break;
        case "useFreeVersion":
            $output .= $extraWatchHTML->renderAdminStyles($extraWatch);
            $extraWatch->config->useFreeVersion();
            $extraWatch->config->saveVersionIntoDatabase();
            $extraWatch->config->setLiveSite($env->getRootSite());
            break;
        case "activate":
            $output .= $extraWatchHTML->renderAdminStyles($extraWatch);
            if ($action == "codecanyon") {
                $extraWatch->config->saveConfigValue("EXTRAWATCH_MARKETPLACE", $action);
            }
            $extraWatch->config->activate(ExtraWatchInput::validate(_EW_INPUT_ONE_STRING, ExtraWatchHelper::requestGet('key')));
            ///
            $extraWatch->config->saveVersionIntoDatabase();
            $extraWatch->config->setLiveSite($env->getRootSite());
            break;
        case "licenseAccepted":
            $extraWatch->config->setLiveSite($env->getRootSite());
            $extraWatch->config->setLicenseAccepted();
            $extraWatch->config->setHtAccessPermissions();
            $extraWatch->config->saveVersionIntoDatabase();
            break;
        case "resetLiveSite":
            $extraWatch->block->checkPermissions();
            $extraWatch->config->setLiveSite($env->getRootSite());
            break;
    }
    if (!_EW_CLOUD_MODE && !$extraWatch->config->checkLicenseAccepted()) {
        //remove check license accepted if cloud mode
        $output .= $extraWatchHTML->renderAdminStyles($extraWatch);
        $output .= $extraWatchHTML->renderHeader($extraWatch);
        $output .= $extraWatchHTML->renderAcceptLicense();
        return $output;
    } else {
        if (!_EW_CLOUD_MODE && (!$extraWatch->config->isFree() && !$extraWatch->config->isAdFree() && !$extraWatch->config->isUnregistered())) {
            $output .= $extraWatchHTML->renderAdminStyles($extraWatch);
            $output .= $extraWatchHTML->renderHeader($extraWatch);
            $output .= $extraWatchHTML->renderAdFreeLicense();
            return $output;
        }
        switch ($task) {
            case "storeIpInfoDbKey":
                $output .= $extraWatchHTML->renderAdminStyles($extraWatch);
                $output .= $extraWatchHTML->renderHeader($extraWatch);
                $keyValue = ExtraWatchInput::validate(_EW_INPUT_ONE_STRING, ExtraWatchHelper::requestPost('storeIpInfoDbKey'));
                ///
                if ($keyValue) {
                    $extraWatch->config->saveConfigValue("EXTRAWATCH_IPINFODB_KEY", $keyValue);
                } else {
                    $output = "<br/><div style='border: 1px solid red; width: 50%; padding: 10px;'>" . _EW_STATS_MAP_INVALID_KEY . "</div>";
                }
                $output .= $extraWatchHTML->renderLocation();
                $output .= $extraWatchHTML->renderFooter();
                break;
            case "users":
                switch ($action) {
                    case "save":
                        $result = $extraWatch->helper->saveUserSettings(ExtraWatchHelper::requestPost());
                        ///
                    default:
                        $output .= $extraWatchHTML->renderAdminStyles($extraWatch);
                        $output .= $extraWatchHTML->renderHeader($extraWatch);
                        $output .= $extraWatchHTML->renderUsers($extraWatch);
                        $output .= $extraWatchHTML->renderFooter();
                        break;
                }
                break;
            case "update":
                $output .= $extraWatchHTML->renderAdminStyles($extraWatch);
                $output .= $extraWatchHTML->renderHeader($extraWatch);
                $output .= $extraWatchHTML->renderUpdate();
                $output .= $extraWatchHTML->renderFooter();
                break;
            case "sizes":
                if (!$extraWatch->config->isFree()) {
                    $output .= $extraWatchHTML->renderAdminStyles($extraWatch);
                    $output .= $extraWatchHTML->renderHeader($extraWatch);
                    $output .= $extraWatchHTML->renderSizes();
                    $output .= $extraWatchHTML->renderFooter();
                }
                break;
            case "seo":
                switch ($action) {
                    case "save":
                        $result = $extraWatch->helper->saveSEOSettings(ExtraWatchHelper::requestPost());
                        ///
                    default:
                        $output .= $extraWatchHTML->renderAdminStyles($extraWatch);
                        $output .= $extraWatchHTML->renderHeader($extraWatch);
                        $output .= $extraWatchHTML->renderSEO();
                        $output .= $extraWatchHTML->renderFooter();
                        break;
                }
                break;
            case "graphs":
                $output .= $extraWatchHTML->renderAdminStyles($extraWatch);
                $output .= $extraWatchHTML->renderHeader($extraWatch);
                $extraWatchTrendHTML = new ExtraWatchTrendHTML($extraWatch);
                $output .= $extraWatchHTML->renderGraphs($extraWatchTrendHTML);
                $output .= $extraWatchHTML->renderFooter();
                break;
            case "trends":
                $output .= $extraWatchHTML->renderAdminStyles($extraWatch);
                $output .= $extraWatchHTML->renderHeader($extraWatch);
                $extraWatchTrendHTML->renderTrends();
                $output .= $extraWatchHTML->renderFooter();
                break;
            case "credits":
                $output .= $extraWatchHTML->renderAdminStyles($extraWatch);
                $output .= $extraWatchHTML->renderHeader($extraWatch);
                $output .= $extraWatchHTML->renderCredits();
                $output .= $extraWatchHTML->renderFooter();
                break;
            case "goals":
                switch ($action) {
                    case "insert":
                        $output .= $extraWatchHTML->renderAdminStyles($extraWatch);
                        $output .= $extraWatchHTML->renderHeader($extraWatch);
                        $output .= $extraWatchGoalHTML->renderBackToGoals();
                        $output .= $extraWatchGoalHTML->renderGoalsInsert((int) @ExtraWatchHelper::requestGet('id'), (int) @ExtraWatchHelper::requestGet('postid'));
                        ///
                        $output .= $extraWatchHTML->renderFooter();
                        break;
                    case "save":
                        $output .= $extraWatchHTML->renderAdminStyles($extraWatch);
                        $output .= $extraWatchHTML->renderHeader($extraWatch);
                        $extraWatch->goal->saveGoal(ExtraWatchHelper::requestPost());
                        ///
                        $output .= $extraWatchGoalHTML->renderGoals(@$result);
                        $output .= $extraWatchHTML->renderFooter();
                        break;
                    case "edit":
                        $output .= $extraWatchHTML->renderAdminStyles($extraWatch);
                        $output .= $extraWatchHTML->renderHeader($extraWatch);
                        $output .= $extraWatchGoalHTML->renderBackToGoals();
                        $output .= $extraWatchGoalHTML->renderGoalEdit(@ExtraWatchHelper::requestGet('goalId'));
                        ///
                        $output .= $extraWatchHTML->renderFooter();
                        break;
                    case "delete":
                        $output .= $extraWatchHTML->renderAdminStyles($extraWatch);
                        $output .= $extraWatchHTML->renderHeader($extraWatch);
                        $result = $extraWatch->goal->deleteGoal(@ExtraWatchHelper::requestGet('goalId'));
                        ///
                        $output .= $extraWatchGoalHTML->renderGoals(@$result);
                        $output .= $extraWatchHTML->renderFooter();
                        break;
                    case "enable":
                        $output .= $extraWatchHTML->renderAdminStyles($extraWatch);
                        $output .= $extraWatchHTML->renderHeader($extraWatch);
                        $result = $extraWatch->goal->enableGoal(@ExtraWatchHelper::requestGet('goalId'));
                        ///
                        $output .= $extraWatchGoalHTML->renderGoals(@$result);
                        $output .= $extraWatchHTML->renderFooter();
                        break;
                    case "disable":
                        $output .= $extraWatchHTML->renderAdminStyles($extraWatch);
                        $output .= $extraWatchHTML->renderHeader($extraWatch);
                        $result = $extraWatch->goal->disableGoal(@ExtraWatchHelper::requestGet('goalId'));
                        ///
                        $output .= $extraWatchGoalHTML->renderGoals(@$result);
                        $output .= $extraWatchHTML->renderFooter();
                        break;
                    case "export":
                        //$output .= $extraWatchHTML->renderAdminStyles($extraWatch);
                        //$output .= $extraWatchHTML->renderHeader($extraWatch);
                        $extraWatch->goal->exportGoals(ExtraWatchHelper::requestPost());
                        ///
                        $extraWatchGoalHTML->renderExportGoals(@$result);
                        $output .= $extraWatchHTML->renderFooter();
                        break;
                    case "import":
                        $output .= $extraWatchHTML->renderAdminStyles($extraWatch);
                        $output .= $extraWatchHTML->renderHeader($extraWatch);
                        $output .= $extraWatchGoalHTML->renderImportGoals();
                        $output .= $extraWatchHTML->renderFooter();
                        break;
                    case "saveImportGoal":
                        $output .= $extraWatchHTML->renderAdminStyles($extraWatch);
                        $output .= $extraWatchHTML->renderHeader($extraWatch);
                        $extraWatch->goal->saveImportGoal(ExtraWatchHelper::requestPost());
                        ///
                        $output .= $extraWatchGoalHTML->renderGoals(@$result);
                        $output .= $extraWatchHTML->renderFooter();
                    default:
                        $output .= $extraWatchHTML->renderAdminStyles($extraWatch);
                        $output .= $extraWatchHTML->renderHeader($extraWatch);
                        $output .= $extraWatchGoalHTML->renderGoals(@$result);
                        $output .= $extraWatchHTML->renderFooter();
                        break;
                }
                break;
            case "settings":
                $output .= $extraWatchHTML->renderAdminStyles($extraWatch);
                $output .= $extraWatchHTML->renderHeader($extraWatch);
                $output .= $extraWatchHTML->renderSettings(@$result);
                $output .= $extraWatchHTML->renderFooter();
                break;
            case "settingsSave":
                $result = $extraWatch->helper->saveSettings(ExtraWatchHelper::requestPost());
                ///
                $output .= $extraWatchHTML->renderAdminStyles($extraWatch);
                $output .= $extraWatchHTML->renderHeader($extraWatch);
                $output .= $extraWatchHTML->renderSettings(@$result);
                $output .= $extraWatchHTML->renderFooter();
                break;
            case "resetData":
                $output .= $extraWatchHTML->renderAdminStyles($extraWatch);
                $output .= $extraWatchHTML->renderHeader($extraWatch);
                $result = $extraWatch->helper->resetData(ExtraWatchHelper::requestPost());
                ///
                $output .= $extraWatchHTML->renderResetData($result);
                $output .= $extraWatchHTML->renderFooter();
                break;
            case "antiSpam":
                switch ($action) {
                    case "toggleBlocking":
                        $output .= $extraWatchHTML->renderAdminStyles($extraWatch);
                        $output .= $extraWatchHTML->renderHeader($extraWatch);
                        $ip = @ExtraWatchHelper::requestGet('ip');
                        ///
                        $extraWatch->block->extrawatch_blockIpToggle($ip);
                        $output .= $extraWatchHTML->renderAntiSpam();
                        $output .= $extraWatchHTML->renderFooter();
                        break;
                    case "save":
                        $numRecordsImported = $extraWatch->block->saveBadWordsList(ExtraWatchHelper::requestPost());
                        $output .= $extraWatchHTML->renderAdminStyles($extraWatch);
                        $output .= $extraWatchHTML->renderHeader($extraWatch);
                        $output .= $extraWatchHTML->renderAntiSpam();
                        $output .= $extraWatchHTML->renderFooter();
                        break;
                    case "antiSpamSave":
                        $output .= $extraWatchHTML->renderAdminStyles($extraWatch);
                        $output .= $extraWatchHTML->renderHeader($extraWatch);
                        $output .= nl2br($extraWatch->block->saveImportAntiSpamIp(ExtraWatchHelper::requestPost()));
                        $output .= $extraWatchHTML->renderAntiSpam();
                        $output .= $extraWatchHTML->renderFooter();
                        break;
                    default:
                        $output .= $extraWatchHTML->renderAdminStyles($extraWatch);
                        $output .= $extraWatchHTML->renderHeader($extraWatch);
                        $output .= $extraWatchHTML->renderAntiSpam();
                        $output .= $extraWatchHTML->renderFooter();
                        break;
                }
                break;
            case "status":
                if (!$extraWatch->config->isFree()) {
                    $output .= $extraWatchHTML->renderAdminStyles($extraWatch);
                    $output .= $extraWatchHTML->renderHeader($extraWatch);
                    $output .= $extraWatchHTML->renderStatus();
                    $output .= $extraWatchHTML->renderFooter();
                }
                break;
                /*			case "upgrade" :  	 	    	    		  	 	  	 	  		 	 		    	 			 	   		  	 	 		 	 	   	      	  	 		 		 				 			 		  		    	 		 		  
                     {
                         $output .= $extraWatchHTML->renderAdminStyles($extraWatch);  	 	    	    		  	 	  	 	  		 	 		    	 			 	   		  	 	 		 	 	   	      	  	 		 		 				 			 		  		    	 		 		  
                         $output .= $extraWatchHTML->renderHeader($extraWatch);  	 	    	    		  	 	  	 	  		 	 		    	 			 	   		  	 	 		 	 	   	      	  	 		 		 				 			 		  		    	 		 		  
                         $output .= $extraWatchHTML->renderUpgrade();  	 	    	    		  	 	  	 	  		 	 		    	 			 	   		  	 	 		 	 	   	      	  	 		 		 				 			 		  		    	 		 		  
                         break;  	 	    	    		  	 	  	 	  		 	 		    	 			 	   		  	 	 		 	 	   	      	  	 		 		 				 			 		  		    	 		 		  
                     }*/
            /*			case "upgrade" :  	 	    	    		  	 	  	 	  		 	 		    	 			 	   		  	 	 		 	 	   	      	  	 		 		 				 			 		  		    	 		 		  
                 {
                     $output .= $extraWatchHTML->renderAdminStyles($extraWatch);  	 	    	    		  	 	  	 	  		 	 		    	 			 	   		  	 	 		 	 	   	      	  	 		 		 				 			 		  		    	 		 		  
                     $output .= $extraWatchHTML->renderHeader($extraWatch);  	 	    	    		  	 	  	 	  		 	 		    	 			 	   		  	 	 		 	 	   	      	  	 		 		 				 			 		  		    	 		 		  
                     $output .= $extraWatchHTML->renderUpgrade();  	 	    	    		  	 	  	 	  		 	 		    	 			 	   		  	 	 		 	 	   	      	  	 		 		 				 			 		  		    	 		 		  
                     break;  	 	    	    		  	 	  	 	  		 	 		    	 			 	   		  	 	 		 	 	   	      	  	 		 		 				 			 		  		    	 		 		  
                 }*/
            case "license":
                $output .= $extraWatchHTML->renderAdminStyles($extraWatch);
                $output .= $extraWatchHTML->renderHeader($extraWatch);
                $output .= $extraWatchHTML->renderAdFreeLicense();
                $output .= $extraWatchHTML->renderFooter();
                break;
            case "history":
                $output .= $extraWatchHTML->renderAdminStyles($extraWatch);
                $output .= $extraWatchHTML->renderHeader($extraWatch);
                $output .= $extraWatchHTML->renderVisitsHistory();
                $output .= $extraWatchHTML->renderFooter();
                break;
            case "flow":
                if (!$extraWatch->config->isFree()) {
                    $output .= $extraWatchHTML->renderAdminStyles($extraWatch);
                    $output .= $extraWatchHTML->renderHeader($extraWatch);
                    $output .= $extraWatchHTML->renderFlow();
                    $output .= $extraWatchHTML->renderFooter();
                }
                break;
            case "emails":
                switch ($action) {
                    case "save":
                        $output .= $extraWatchHTML->renderAdminStyles($extraWatch);
                        $output .= $extraWatchHTML->renderHeader($extraWatch);
                        $result = $extraWatch->helper->saveEmailSettings(ExtraWatchHelper::requestPost());
                        ///
                        $output .= $extraWatchHTML->renderEmails();
                        $output .= $extraWatchHTML->renderFooter();
                        break;
                    case "send":
                        $output .= $extraWatchHTML->renderAdminStyles($extraWatch);
                        $output .= $extraWatchHTML->renderHeader($extraWatch);
                        $extraWatch->visit->sendNightlyEmails();
                        $output .= $extraWatchHTML->renderEmails();
                        $output .= $extraWatchHTML->renderFooter();
                        break;
                    default:
                        $output .= $extraWatchHTML->renderAdminStyles($extraWatch);
                        $output .= $extraWatchHTML->renderHeader($extraWatch);
                        $output .= $extraWatchHTML->renderEmails();
                        $output .= $extraWatchHTML->renderFooter();
                        break;
                }
                break;
            case "heatmap":
                $output .= $extraWatchHTML->renderAdminStyles($extraWatch);
                $output .= $extraWatchHTML->renderHeader($extraWatch);
                $output .= $extraWatchHTML->renderHeatMap();
                $output .= $extraWatchHTML->renderFooter();
                return $output;
                break;
            case "clicks":
                $output .= $extraWatchHTML->renderAdminStyles($extraWatch);
                $output .= $extraWatchHTML->renderHeader($extraWatch);
                $output .= $extraWatchHTML->renderClicks();
                $output .= $extraWatchHTML->renderFooter();
                return $output;
                break;
            case "downloads":
                $extraWatchDownloads = new ExtraWatchDownloads($extraWatch->database);
                $extraWatchDownloadsHTML = new ExtraWatchDownloadsHTML($extraWatch->database);
                switch ($action) {
                    case "addExtension":
                        $output .= $extraWatchHTML->renderAdminStyles($extraWatch);
                        $output .= $extraWatchHTML->renderHeader($extraWatch);
                        $output .= $extraWatchDownloadsHTML->renderAddExtension();
                        $output .= $extraWatchHTML->renderDownloads();
                        $output .= $extraWatchHTML->renderFooter();
                        break;
                    case "saveAddExtension":
                        $output .= $extraWatchHTML->renderAdminStyles($extraWatch);
                        $output .= $extraWatchHTML->renderHeader($extraWatch);
                        $output .= $extraWatchDownloads->addExtension(ExtraWatchHelper::requestPost('extname'));
                        ///
                        $output .= $extraWatchHTML->renderDownloads();
                        $output .= $extraWatchHTML->renderFooter();
                        return $output;
                        break;
                    case "editExtension":
                        $output .= $extraWatchHTML->renderAdminStyles($extraWatch);
                        $output .= $extraWatchHTML->renderHeader($extraWatch);
                        $output .= $extraWatchDownloadsHTML->renderEditExtension(ExtraWatchHelper::requestGet('eid'));
                        ///
                        $output .= $extraWatchHTML->renderDownloads();
                        $output .= $extraWatchHTML->renderFooter();
                        break;
                    case "saveEditExtension":
                        $output .= $extraWatchHTML->renderAdminStyles($extraWatch);
                        $output .= $extraWatchHTML->renderHeader($extraWatch);
                        $output .= $extraWatchDownloads->updateExtension(ExtraWatchHelper::requestPost('eid'), ExtraWatchHelper::requestPost('extname'));
                        ///
                        $output .= $extraWatchHTML->renderDownloads();
                        $output .= $extraWatchHTML->renderFooter();
                        return $output;
                        break;
                    case "deleteExtension":
                        $output .= $extraWatchHTML->renderAdminStyles($extraWatch);
                        $output .= $extraWatchHTML->renderHeader($extraWatch);
                        $output .= $extraWatchDownloads->deleteExtension(ExtraWatchHelper::requestGet('co'));
                        ///
                        $output .= $extraWatchHTML->renderDownloads();
                        $output .= $extraWatchHTML->renderFooter();
                        break;
                    case "addFile":
                        $output .= $extraWatchHTML->renderAdminStyles($extraWatch);
                        $output .= $extraWatchHTML->renderHeader($extraWatch);
                        $output .= $extraWatchDownloadsHTML->renderAddFile();
                        $output .= $extraWatchHTML->renderDownloads();
                        $output .= $extraWatchHTML->renderFooter();
                        break;
                    case "editFile":
                        $output .= $extraWatchHTML->renderAdminStyles($extraWatch);
                        $output .= $extraWatchHTML->renderHeader($extraWatch);
                        $output .= $extraWatchDownloadsHTML->renderEditFile(ExtraWatchHelper::requestGet('did'));
                        ///
                        $output .= $extraWatchHTML->renderDownloads();
                        $output .= $extraWatchHTML->renderFooter();
                        break;
                    case "saveEditFile":
                        $output .= $extraWatchHTML->renderAdminStyles($extraWatch);
                        $output .= $extraWatchHTML->renderHeader($extraWatch);
                        $output .= $extraWatchDownloads->updateFilePath(ExtraWatchHelper::requestPost('did'), ExtraWatchHelper::requestPost('filepathname'));
                        ///
                        $output .= $extraWatchHTML->renderDownloads();
                        $output .= $extraWatchHTML->renderFooter();
                        return $output;
                        break;
                    case "saveAddFile":
                        $output .= $extraWatchHTML->renderAdminStyles($extraWatch);
                        $output .= $extraWatchHTML->renderHeader($extraWatch);
                        $output .= $extraWatchDownloads->addFilePath(ExtraWatchHelper::requestPost('filepathname'));
                        ///
                        $output .= $extraWatchHTML->renderDownloads();
                        $output .= $extraWatchHTML->renderFooter();
                        return $output;
                        break;
                    case "deleteFile":
                        $output .= $extraWatchHTML->renderAdminStyles($extraWatch);
                        $output .= $extraWatchHTML->renderHeader($extraWatch);
                        $output .= $extraWatchDownloads->deleteFilePath(ExtraWatchHelper::requestGet('co'));
                        ///
                        $output .= $extraWatchHTML->renderDownloads();
                        $output .= $extraWatchHTML->renderFooter();
                        break;
                    default:
                        $output .= $extraWatchHTML->renderAdminStyles($extraWatch);
                        $output .= $extraWatchHTML->renderHeader($extraWatch);
                        $output .= $extraWatchHTML->renderDownloads();
                        $output .= $extraWatchHTML->renderFooter();
                        return $output;
                        break;
                }
                break;
            case "location":
                $output .= $extraWatchHTML->renderAdminStyles($extraWatch);
                $output .= $extraWatchHTML->renderHeader($extraWatch);
                $output .= $extraWatchHTML->renderLocation();
                $output .= $extraWatchHTML->renderFooter();
                break;
            case "stats":
                $output .= $extraWatchHTML->renderAdminStyles($extraWatch);
                $output .= $extraWatchHTML->renderHeader($extraWatch);
                $output .= $extraWatchHTML->renderStats();
                $output .= $extraWatchHTML->renderFooter();
                break;
            default:
                $output .= $extraWatchHTML->renderAdminStyles($extraWatch);
                $output .= $extraWatchHTML->renderHeader($extraWatch);
                $output .= $extraWatchHTML->renderBody($option);
                $output .= $extraWatchHTML->renderFooter();
                return $output;
                break;
        }
    }
    error_reporting($current_error_reporting);
    return $output;
}
 function LookUp()
 {
     if (!@$this->database) {
         $this->env = ExtraWatchEnvFactory::getEnvironment();
         $this->database =& $this->env->getDatabase(_EW_PROJECT_ID);
     }
     if ($this->UseDB) {
         /*
          * The Fastest Way is to import the CSV file in your database and to  	 	    	    		  	 	  	 	  		 	 		    	 			 	   		  	 	 		 	 	   	      	  	 		 		 				 			 		  		    	 		 		  
          * set UseDB to TRUE !  	 	    	    		  	 	  	 	  		 	 		    	 			 	   		  	 	 		 	 	   	      	  	 		 		 				 			 		  		    	 		 		  
          * I use MySQL but feel free to use your database functions ;)  	 	    	    		  	 	  	 	  		 	 		    	 			 	   		  	 	 		 	 	   	      	  	 		 		 				 			 		  		    	 		 		  
          */
         $query = sprintf("SELECT %s FROM %s WHERE %s >= %s AND %s <= %s", $this->database->getEscaped($this->db_country_colname), $this->database->getEscaped($this->db_tablename), $this->database->getEscaped($this->_IPn), $this->database->getEscaped($this->db_ip_from_colname), $this->database->getEscaped($this->_IPn), $this->database->getEscaped($this->db_ip_to_colname));
         $rows = $this->database->objectListQuery($query);
         $row = @$rows[0];
         if ($row) {
             $country_colname = $this->db_country_colname;
             $this->Country = $row->{$country_colname};
             return TRUE;
         } else {
             return FALSE;
         }
         //			mysql_close($conn);
     }
 }
 function __construct($extraWatch)
 {
     $this->extraWatch = $extraWatch;
     $this->env = ExtraWatchEnvFactory::getEnvironment();
 }
 static function initializeMenu()
 {
     $env = ExtraWatchEnvFactory::getEnvironment();
     ///
     $database = $env->getDatabase(_EW_PROJECT_ID);
     ///
     if (version_compare(JVERSION, "2.5.0", "<")) {
         $query = "UPDATE #__components SET admin_menu_img='../components/com_extrawatch/img/icons/extrawatch-logo-16x16.png' WHERE admin_menu_link='option=com_extrawatch'";
         $database->setQuery(trim($query));
         $database->query();
         $query = "DELETE FROM #__components where admin_menu_link like '%option=com_extrawatch%'  and admin_menu_img like '%../components/com_extrawatch/icons/%' and admin_menu_img<>'../components/com_extrawatch/img/icons/extrawatch-logo-16x16.png'";
         $database->setQuery(trim($query));
         $database->query();
         $query = sprintf("select id from #__components where `name` = '%s' limit 1", "ExtraWatch");
         $database->setQuery(trim($query));
         $id = $database->loadResult();
         $query = sprintf("INSERT INTO #__components (`name`, menuid, parent, link, ordering, admin_menu_img, enabled) values ('Live Stats', 0, %d, 'option=com_extrawatch', 0, '../components/com_extrawatch/img/icons/map_icon.gif', 1)", (int) $id);
         $database->setQuery($query);
         $database->query();
         $query = sprintf("INSERT INTO #__components (`name`, menuid, parent, link, ordering, admin_menu_img, enabled) values ('SEO', 0, %d, 'option=com_extrawatch&task=seo', 1, '../components/com_extrawatch/img/icons/seo.png', 1)", (int) $id);
         $database->setQuery($query);
         $database->query();
         $query = sprintf("INSERT INTO #__components (`name`, menuid, parent, link, ordering, admin_menu_img, enabled) values ('Clicks', 0, %d, 'option=com_extrawatch&task=heatmap', 2, '../components/com_extrawatch/img/icons/click.png', 1)", (int) $id);
         $database->setQuery($query);
         $database->query();
         $query = sprintf("INSERT INTO #__components (`name`, menuid, parent, link, ordering, admin_menu_img, enabled) values ('Downloads', 0, %d, 'option=com_extrawatch&task=downloads', 3, '../components/com_extrawatch/img/icons/downloads.png', 1)", (int) $id);
         $database->setQuery($query);
         $database->query();
         $query = sprintf("   INSERT INTO #__components (`name`, menuid, parent, link, ordering, admin_menu_img, enabled) values ('Traffic Flow', 0, %d, 'option=com_extrawatch&task=flow', 4, '../components/com_extrawatch/img/icons/flow.png', 1)", (int) $id);
         $database->setQuery($query);
         $database->query();
         $query = sprintf("   INSERT INTO #__components (`name`, menuid, parent, link, ordering, admin_menu_img, enabled) values ('Graphs & Trends', 0, %d, 'option=com_extrawatch&task=graphs', 5, '../components/com_extrawatch/img/icons/trend_icon.gif', 1)", (int) $id);
         $database->setQuery($query);
         $database->query();
         $query = sprintf("   INSERT INTO #__components (`name`, menuid, parent, link, ordering, admin_menu_img, enabled) values ('Goals', 0, %d, 'option=com_extrawatch&task=goals', 6, '../components/com_extrawatch/img/icons/goal.gif', 1)", (int) $id);
         $database->setQuery($query);
         $database->query();
         $query = sprintf("   INSERT INTO #__components (`name`, menuid, parent, link, ordering, admin_menu_img, enabled) values ('Visit History', 0, %d, 'option=com_extrawatch&task=history', 7, '../components/com_extrawatch/img/icons/history.png', 1)", (int) $id);
         $database->setQuery($query);
         $database->query();
         $query = sprintf("   INSERT INTO #__components (`name`, menuid, parent, link, ordering, admin_menu_img, enabled) values ('Anti-spam & Blocking', 0, %d, 'option=com_extrawatch&task=antiSpam', 8, '../components/com_extrawatch/img/icons/antispam.gif', 1)", (int) $id);
         $database->setQuery($query);
         $database->query();
         $query = sprintf("   INSERT INTO #__components (`name`, menuid, parent, link, ordering, admin_menu_img, enabled) values ('Email Reports', 0, %d, 'option=com_extrawatch&task=emails', 9, '../components/com_extrawatch/img/icons/emails.png', 1)", (int) $id);
         $database->setQuery($query);
         $database->query();
         $query = sprintf("   INSERT INTO #__components (`name`, menuid, parent, link, ordering, admin_menu_img, enabled) values ('Your License', 0, %d, 'option=com_extrawatch&task=license', 10, '../components/com_extrawatch/img/icons/license.png', 1)", (int) $id);
         $database->setQuery($query);
         $database->query();
         $query = sprintf("   INSERT INTO #__components (`name`, menuid, parent, link, ordering, admin_menu_img, enabled) values ('Database Status', 0, %d, 'option=com_extrawatch&task=status', 11, '../components/com_extrawatch/img/icons/status.png', 1)", (int) $id);
         $database->setQuery($query);
         $database->query();
         $query = sprintf("   INSERT INTO #__components (`name`, menuid, parent, link, ordering, admin_menu_img, enabled) values ('Modules / Components Sizes', 0, %d, 'option=com_extrawatch&task=sizes', 12, '../components/com_extrawatch/img/icons/sizes.png', 1)", (int) $id);
         $database->setQuery($query);
         $database->query();
         $query = sprintf("   INSERT INTO #__components (`name`, menuid, parent, link, ordering, admin_menu_img, enabled) values ('Settings', 0, %d, 'option=com_extrawatch&task=settings', 13, '../components/com_extrawatch/img/icons/settings.gif', 1)", (int) $id);
         $database->setQuery($query);
         $database->query();
         $query = sprintf("   INSERT INTO #__components (`name`, menuid, parent, link, ordering, admin_menu_img, enabled) ('Update', 0, %d, 'option=com_extrawatch&task=update', 14, '../components/com_extrawatch/img/icons/update.png', 1)", (int) $id);
         $database->setQuery($query);
         $database->query();
         $query = sprintf("   INSERT INTO #__components (`name`, menuid, parent, link, ordering, admin_menu_img, enabled) ('Credits', 0, %d, 'option=com_extrawatch&task=credits', 15, '../components/com_extrawatch/img/icons/credits.png', 1)", (int) $id);
         $database->setQuery($query);
         $database->query();
     }
 }
 * @file
 * ExtraWatch - A real-time ajax monitor and live stats  	 	    	    		  	 	  	 	  		 	 		    	 			 	   		  	 	 		 	 	   	      	  	 		 		 				 			 		  		    	 		 		  
 * @package ExtraWatch  	 	    	    		  	 	  	 	  		 	 		    	 			 	   		  	 	 		 	 	   	      	  	 		 		 				 			 		  		    	 		 		  
 * @version 2.3  	 	    	    		  	 	  	 	  		 	 		    	 			 	   		  	 	 		 	 	   	      	  	 		 		 				 			 		  		    	 		 		  
 * @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.extrawatch.com  	 	    	    		  	 	  	 	  		 	 		    	 			 	   		  	 	 		 	 	   	      	  	 		 		 				 			 		  		    	 		 		  
 */
/** ensure this file is being included by a parent file */
defined('_JEXEC') or die('Restricted access');
if (!defined("JPATH_BASE2")) {
    define("JPATH_BASE2", JPATH_BASE);
}
if (!defined("DS")) {
    define("DS", DIRECTORY_SEPARATOR);
}
require_once JPATH_BASE . DS . "components" . DS . "com_extrawatch" . DS . "includes.php";
function renderExtraWatchVisitors()
{
    $output = "";
    $extraWatch = new ExtraWatchMain();
    $extraWatch->config->initializeTranslations();
    $extraWatchStatHTML = new ExtraWatchStatHTML($extraWatch);
    $output .= $extraWatchStatHTML->renderFrontendStats($extraWatch);
    return $output;
}
$env = ExtraWatchEnvFactory::getEnvironment()->getEnvironmentName();
if (!defined('ENV') | $env == "nocms") {
    echo renderExtraWatchVisitors();
}
 /**
  * If on HTTPS site, use the https links  	 	    	    		  	 	  	 	  		 	 		    	 			 	   		  	 	 		 	 	   	      	  	 		 		 				 			 		  		    	 		 		  
  * @param  $originalLink  	 	    	    		  	 	  	 	  		 	 		    	 			 	   		  	 	 		 	 	   	      	  	 		 		 				 			 		  		    	 		 		  
  * @return mixed
  */
 static function replaceHttpByHttps($originalLink)
 {
     $env = ExtraWatchEnvFactory::getEnvironment();
     if ($env->isSSL()) {
         return str_ireplace("http://", "https://", $originalLink);
     }
     return str_ireplace("https://", "http://", $originalLink);
 }
 /**
  * date
  * @return mixed|string|void  	 	    	    		  	 	  	 	  		 	 		    	 			 	   		  	 	 		 	 	   	      	  	 		 		 				 			 		  		    	 		 		  
  */
 static function getUserTimezone()
 {
     $env = ExtraWatchEnvFactory::getEnvironment();
     //	    if we have an anonymous user, then use global config, instead of the user params
     if ($env->getUsersCustomTimezoneOffset()) {
         $userTimezone = $env->getTimezoneOffset();
     } else {
         $userTimezone = $env->getTimezoneOffset();
     }
     /* if the user has no timezone defined, use the timezone from server configuratio */
     if (!isset($userTimezone)) {
         $config = new JConfig();
         $userTimezone = $config->offset;
     }
     if ($userTimezone && !is_numeric($userTimezone)) {
         $userTimezone = ExtraWatchHelper::getTimezoneOffsetByTimezoneName($userTimezone);
     }
     return $userTimezone;
 }