$value) { if (ereg('^rule', $key)) { $rule = $this->makeRule($value); $this->rules[$rule->module][$rule->manager][$rule->action] = $rule->params; } if (ereg('^omit', $key)) { $rule = $this->makeRule($value); $this->omit[$rule->module][$rule->manager][$rule->action] = true; } } } } /** * Makes rule from a rule sting defined in config file */ function makeRule($ruleString) { $ruleArray = split('#', $ruleString); $rule->module = $ruleArray[0]; $rule->manager = $ruleArray[1]; $rule->action = $ruleArray[2]; $rule->params = array_slice($ruleArray, 3); return $rule; } /** * Count a visit */ function count() { $module = $GLOBALS['_SGL']['REQUEST']['moduleName']; $manager = $GLOBALS['_SGL']['REQUEST']['managerName']; if (isset($GLOBALS['_SGL']['REQUEST']['action'])) { $action = $GLOBALS['_SGL']['REQUEST']['action']; } else { $action = ''; } //if has rule then add if (isset($this->rules[$module][$manager][$action])) { if($this->_exists($module, $manager, $action, $this->rules[$module][$manager][$action])) { $this->_up($module, $manager, $action, $this->rules[$module][$manager][$action]); } else { $this->_add($module, $manager, $action, $this->rules[$module][$manager][$action]); } //else - does't have add rule } else { //add only if configured to add all if (!isset($this->omit[$module][$manager][$action]) && isset($GLOBALS['_SGL']['CONF']['StatisticsVarico']['storeAll']) && $GLOBALS['_SGL']['CONF']['StatisticsVarico']['storeAll'] == 1) { $uri = substr(addslashes($GLOBALS['REQUEST_URI']), 0, URI_IMPORTANT_LEN); //insert if ($this->_exists($module, $manager, $action, $uri)) { $this->_up($module, $manager, $action, $uri); } else { $this->_add($module, $manager, $action, $uri); } } } } /** * Check if entry in statistics exits */ function _exists($module, $manager, $action, &$params) { $dbh = & SGL_DB::singleton(); $query = "SELECT * FROM statistics_varico WHERE modulename='$module' AND managername='$manager' AND actionname='$action' AND visitdate='". date('Y-m-d', time()) ."' AND usr_id=" . SGL_HTTP_Session::getUid(); if (is_array($params)) { for ($i=1; $i<=count($params); $i++) { $query .= ' AND id' . $i . "='" . $GLOBALS['_SGL']['REQUEST'][$params[$i-1]] . "'"; } if ($dbh->getRow($query)) { return true; } } else { if ($dbh->getRow($query . " AND full_url='$params'")) { return true; } } return false; } /** * Increment existing statistics value */ function _up($module, $manager, $action, &$params) { $dbh = & SGL_DB::singleton(); $query = "UPDATE statistics_varico SET count=count + 1 WHERE modulename='$module' AND managername='$manager' AND actionname='$action' AND visitdate='". date('Y-m-d', time()) ."' AND usr_id=" . SGL_HTTP_Session::getUid(); if (is_array($params)) { for ($i=1; $i<=count($params); $i++) { $query .= ' AND id' . $i . "='" . $GLOBALS['_SGL']['REQUEST'][$params[$i-1]] . "'"; } } else { $query .= " AND full_url ='" . $params . "'"; } $dbh->query($query); } /** * Add new statistics entry */ function _add($module, $manager, $action, &$params) { $insert['modulename'] = $module; $insert['managername'] = $manager; $insert['actionname'] = $action; $insert['visitdate'] = 'now()'; $insert['count'] = 1; $insert['usr_id'] = SGL_HTTP_Session::getUid(); if (is_array($params)) { for ($i=1; $i<=count($params); $i++) { $insert['id' . $i] = $GLOBALS['_SGL']['REQUEST'][$params[$i-1]]; } } else { $insert['full_url'] = $params; } $dbh = & SGL_DB::singleton(); $dbh->autoExecute('statistics_varico', $insert, DB_AUTOQUERY_INSERT); } } ?> $value) { if (ereg('^rule', $key)) { $rule = $this->makeRule($value); $this->rules[$rule->module][$rule->manager][$rule->action] = $rule->params; } if (ereg('^omit', $key)) { $rule = $this->makeRule($value); $this->omit[$rule->module][$rule->manager][$rule->action] = true; } } } } /** * Makes rule from a rule sting defined in config file */ function makeRule($ruleString) { $ruleArray = split('#', $ruleString); $rule->module = $ruleArray[0]; $rule->manager = $ruleArray[1]; $rule->action = $ruleArray[2]; $rule->params = array_slice($ruleArray, 3); return $rule; } /** * Count a visit */ function count() { $module = $GLOBALS['_SGL']['REQUEST']['moduleName']; $manager = $GLOBALS['_SGL']['REQUEST']['managerName']; if (isset($GLOBALS['_SGL']['REQUEST']['action'])) { $action = $GLOBALS['_SGL']['REQUEST']['action']; } else { $action = ''; } //if has rule then add if (isset($this->rules[$module][$manager][$action])) { if($this->_exists($module, $manager, $action, $this->rules[$module][$manager][$action])) { $this->_up($module, $manager, $action, $this->rules[$module][$manager][$action]); } else { $this->_add($module, $manager, $action, $this->rules[$module][$manager][$action]); } //else - does't have add rule } else { //add only if configured to add all if (!isset($this->omit[$module][$manager][$action]) && isset($GLOBALS['_SGL']['CONF']['StatisticsVarico']['storeAll']) && $GLOBALS['_SGL']['CONF']['StatisticsVarico']['storeAll'] == 1) { $uri = substr(addslashes($GLOBALS['REQUEST_URI']), 0, URI_IMPORTANT_LEN); //insert if ($this->_exists($module, $manager, $action, $uri)) { $this->_up($module, $manager, $action, $uri); } else { $this->_add($module, $manager, $action, $uri); } } } } /** * Check if entry in statistics exits */ function _exists($module, $manager, $action, &$params) { $dbh = & SGL_DB::singleton(); $query = "SELECT * FROM statistics_varico WHERE modulename='$module' AND managername='$manager' AND actionname='$action' AND visitdate='". date('Y-m-d', time()) ."' AND usr_id=" . SGL_HTTP_Session::getUid(); if (is_array($params)) { for ($i=1; $i<=count($params); $i++) { $query .= ' AND id' . $i . "='" . $GLOBALS['_SGL']['REQUEST'][$params[$i-1]] . "'"; } if ($dbh->getRow($query)) { return true; } } else { if ($dbh->getRow($query . " AND full_url='$params'")) { return true; } } return false; } /** * Increment existing statistics value */ function _up($module, $manager, $action, &$params) { $dbh = & SGL_DB::singleton(); $query = "UPDATE statistics_varico SET count=count + 1 WHERE modulename='$module' AND managername='$manager' AND actionname='$action' AND visitdate='". date('Y-m-d', time()) ."' AND usr_id=" . SGL_HTTP_Session::getUid(); if (is_array($params)) { for ($i=1; $i<=count($params); $i++) { $query .= ' AND id' . $i . "='" . $GLOBALS['_SGL']['REQUEST'][$params[$i-1]] . "'"; } } else { $query .= " AND full_url ='" . $params . "'"; } $dbh->query($query); } /** * Add new statistics entry */ function _add($module, $manager, $action, &$params) { $insert['modulename'] = $module; $insert['managername'] = $manager; $insert['actionname'] = $action; $insert['visitdate'] = 'now()'; $insert['count'] = 1; $insert['usr_id'] = SGL_HTTP_Session::getUid(); if (is_array($params)) { for ($i=1; $i<=count($params); $i++) { $insert['id' . $i] = $GLOBALS['_SGL']['REQUEST'][$params[$i-1]]; } } else { $insert['full_url'] = $params; } $dbh = & SGL_DB::singleton(); $dbh->autoExecute('statistics_varico', $insert, DB_AUTOQUERY_INSERT); } } ?>