2 /************************************************************************
3 * Mailer v0.2.1-FINAL Start: 10/25/2009 *
4 * =================== Last change: 10/25/2009 *
6 * -------------------------------------------------------------------- *
7 * File : stats-functions.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Automatical purging of outdated mail links *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Auto-Loeschung von veralteten Mail-Links *
12 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
17 * Needs to be in all Files and every File needs "svn propset *
18 * svn:keywords Date Revision" (autoprobset!) at least!!!!!! *
19 * -------------------------------------------------------------------- *
20 * Copyright (c) 2003 - 2009 by Roland Haeder *
21 * For more information visit: http://www.mxchange.org *
23 * This program is free software; you can redistribute it and/or modify *
24 * it under the terms of the GNU General Public License as published by *
25 * the Free Software Foundation; either version 2 of the License, or *
26 * (at your option) any later version. *
28 * This program is distributed in the hope that it will be useful, *
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
31 * GNU General Public License for more details. *
33 * You should have received a copy of the GNU General Public License *
34 * along with this program; if not, write to the Free Software *
35 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
37 ************************************************************************/
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
45 function initStatsSystem () {
46 // Is stats cache loaded?
47 if ((!isset($GLOBALS['stats_loaded'])) && (getConfig('STATS_ENABLED') == 'Y')) {
48 // Init statistics array
49 $GLOBALS['stats'] = array();
51 // Load statistics entry from temporary table
55 $GLOBALS['stats_loaded'] = true;
59 // Checks if we have a statistics entry
60 function isStatsEntrySet ($entry) {
61 // Do we have the entry?
62 return (isset($GLOBALS['stats'][$entry]));
65 // Increments a statistics entry
66 function incrementStatsEntry ($entry, $amount=1) {
67 // Do we have stats enabled?
68 if (getConfig('STATS_ENABLED') != 'Y') return;
71 if (isStatsEntrySet($entry)) {
73 $GLOBALS['stats'][$entry] += $amount;
76 $GLOBALS['stats'][$entry] = $amount;
81 function getStatsEntry ($entry) {
86 if (isStatsEntrySet($entry)) {
88 $stats = $GLOBALS['stats'][$entry];
96 function setStatsEntry ($entry, $value) {
97 $GLOBALS['stats'][$entry] = $value;
101 function loadStatsTable () {
102 // Check if the link is up
103 if (!SQL_IS_LINK_UP()) return false;
105 // Do we have it there for today?
106 if (!isStatsTableCreated()) {
107 // Then create a default one
111 // Load it from database
112 $result = SQL_QUERY_ESC("SELECT `stats_entry`,`stats_value` FROM `{?_MYSQL_PREFIX?}_stats_%s` ORDER BY `stats_entry` ASC",
113 array(date('Ymd', time())), __FUNCTION__, __LINE__);
116 while ($row = SQL_FETCHARRAY($result)) {
117 $GLOBALS['stats'][$row['stats_entry']] = $row['stats_value'];
121 SQL_FREERESULT($result);
124 // Checks if the the statistics table is created
125 function isStatsTableCreated () {
126 // Check if the link is up
127 if (!SQL_IS_LINK_UP()) return false;
130 $result = SQL_QUERY_ESC("SHOW TABLES LIKE '{?_MYSQL_PREFIX?}_stats_%s'",
131 array(date('Ymd', time())), __FUNCTION__, __LINE__);
134 return SQL_NUMROWS($result);
137 // Create the dummy table
138 function createStatsTable () {
139 // Check if the link is up
140 if (!SQL_IS_LINK_UP()) return false;
143 $result = SQL_QUERY_ESC("CREATE TABLE IF NOT EXISTS `{?_MYSQL_PREFIX?}_stats_%s` (
144 `stats_entry` VARCHAR(100) NOT NULL DEFAULT '',
145 `stats_value` BIGINT(20) NOT NULL DEFAULT 0,
146 PRIMARY KEY (`stats_entry`)
147 ) TYPE=HEAP COMMENT='Temporary statistics table'",
148 array(date('Ymd', time())), __FUNCTION__, __LINE__);
151 // Write all entries to the table
152 function writeStatsTable () {
153 // Check if the link is up
154 if (!SQL_IS_LINK_UP()) return false;
156 // Empty the table first
157 SQL_QUERY_ESC("TRUNCATE `{?_MYSQL_PREFIX?}_stats_%s`",
158 array(date('Ymd', time())), __FUNCTION__, __LINE__);
160 // Begin the SQL command
161 $sql = sprintf("REPLACE INTO `{?_MYSQL_PREFIX?}_stats_%s` (`stats_entry`,`stats_value`) VALUES ",
162 date('Ymd', time()));
164 // Add all entries to the final query
165 foreach ($GLOBALS['stats'] as $entry => $value) {
166 $sql .= sprintf("('%s', %s),", $entry, bigintval($value));
169 // Finalize it and run it
170 SQL_QUERY(substr($sql, 0, -1), __FUNCTION__, __LINE__);
173 // Filter for flushing statistics
174 function FILTER_FLUSH_STATS () {
175 // Now do we have stats?
176 if ((isset($GLOBALS['stats'])) && (getConfig('STATS_ENABLED') == 'Y')) {
177 // Write statistics to temporary table