SQLs fixed
[mailer.git] / inc / extensions / ext-beg.php
index abd28703d655fea77a3fe3f87ccae1f4adefc60c..e05528c26b2ed499877b2a3222c295561e7abee8 100644 (file)
  * $Date::                                                            $ *
  * $Tag:: 0.2.1-FINAL                                                 $ *
  * $Author::                                                          $ *
- * Needs to be in all Files and every File needs "svn propset           *
- * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
  * -------------------------------------------------------------------- *
  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
- * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
+ * Copyright (c) 2009 - 2011 by Mailer Developer Team                   *
  * For more information visit: http://www.mxchange.org                  *
  *                                                                      *
  * This program is free software; you can redistribute it and/or modify *
 // Some security stuff...
 if (!defined('__SECURITY')) {
        die();
-}
+} // END - if
 
 // Version number
-setThisExtensionVersion('0.2.6');
+setThisExtensionVersion('0.2.9');
 
 // Version history array (add more with , '0.1.0' and so on)
-setExtensionVersionHistory(array('0.0', '0.0.1', '0.0.2', '0.0.3', '0.0.4', '0.0.5', '0.0.6', '0.0.7', '0.0.8', '0.0.9', '0.1.0', '0.1.1', '0.1.2', '0.1.3', '0.1.4', '0.1.5', '0.1.6', '0.1.7', '0.1.8', '0.1.9', '0.2.0', '0.2.1', '0.2.2', '0.2.3', '0.2.4', '0.2.5', '0.2.6'));
+setExtensionVersionHistory(array('0.0', '0.0.1', '0.0.2', '0.0.3', '0.0.4', '0.0.5', '0.0.6', '0.0.7', '0.0.8', '0.0.9', '0.1.0', '0.1.1', '0.1.2', '0.1.3', '0.1.4', '0.1.5', '0.1.6', '0.1.7', '0.1.8', '0.1.9', '0.2.0', '0.2.1', '0.2.2', '0.2.3', '0.2.4', '0.2.5', '0.2.6', '0.2.7', '0.2.8', '0.2.9'));
 
 switch (getExtensionMode()) {
        case 'register': // Do stuff when installation is running (modules.php?module=admin is called)
                // SQL commands to run
-               addAdminMenuSql('setup','config_beg','Bettel-Link','IP-Sperre, {OPEN_CONFIG}POINTS{CLOSE_CONFIG}-Vergütung usw. können Sie hier einstellen.', 10);
-               addGuestMenuSql('main','beg','{OPEN_CONFIG}POINTS{CLOSE_CONFIG} erbetteln!','N','Y',4);
-               addMemberMenuSql('main','beg','Ihr Bettel-Link','N','Y',6);
-               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD beg_timeout BIGINT(20) UNSIGNED NOT NULL DEFAULT '600'");
-               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD beg_userid_timeout BIGINT(20) UNSIGNED NOT NULL DEFAULT 1800");
-               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD beg_points FLOAT(20,5) UNSIGNED NOT NULL DEFAULT 0.00100");
-               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_user_data` ADD beg_clicks BIGINT(20) UNSIGNED NOT NULL DEFAULT 0");
-               addExtensionSql("DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_beg_ips`");
-               addExtensionSql("CREATE TABLE `{?_MYSQL_PREFIX?}_beg_ips` (
-id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
-userid BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
-remote_ip VARCHAR(15) NOT NULL DEFAULT '0.0.0.0',
-timeout VARCHAR(10) NOT NULL DEFAULT '',
-KEY (userid),
-PRIMARY KEY (id)
-) TYPE={?_TABLE_TYPE?}");
+               addAdminMenuSql('setup', 'config_beg', 'Bettel-Link', 'IP-Sperre, {OPEN_CONFIG}POINTS{CLOSE_CONFIG}-Vergütung usw. können Sie hier einstellen.', 10);
+               addGuestMenuSql('main', 'beg', '{OPEN_CONFIG}POINTS{CLOSE_CONFIG} erbetteln!', 'N', 'Y', 4);
+               addMemberMenuSql('main', 'beg', 'Ihr Bettel-Link', 'N', 'Y', 6);
+               addConfigAddSql('beg_timeout', 'BIGINT(20) UNSIGNED NOT NULL DEFAULT 600');
+               addConfigAddSql('beg_userid_timeout', 'BIGINT(20) UNSIGNED NOT NULL DEFAULT 1800');
+               addConfigAddSql('beg_points', 'FLOAT(20,5) UNSIGNED NOT NULL DEFAULT 0.00100');
+               addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_user_data` ADD `beg_clicks` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0');
+
+               // Table for IP locks
+               addDropTableSql('beg_ips');
+               addCreateTableSql('beg_ips', "(
+`id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
+`userid` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
+`remote_ip` VARCHAR(15) NOT NULL DEFAULT '0.0.0.0',
+`timeout` VARCHAR(10) NOT NULL DEFAULT '',
+`sid` VARCHAR(255) NOT NULL DEFAULT '',
+KEY (`userid`),
+PRIMARY KEY (`id`)
+) ENGINE = {?_TABLE_TYPE?} CHARACTER SET utf8 COLLATE utf8_general_ci COMMENT = 'IP lock data for beg links'");
                break;
 
        case 'remove': // Do stuff when removing extension
                // SQL commands to run
-               addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE `what`='config_beg' OR `what`='list_beg'");
+               addDropTableSql('beg_ips');
+               addDropTableSql('beg_referals');
+               addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE `what` IN ('config_beg','list_beg','list_beg_referal_urls')");
                addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_guest_menu` WHERE `what`='beg'");
-               addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE `what`='beg' OR `what`='beg2'");
-               addExtensionSql("DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_beg_ips`");
+               addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE `what` IN ('beg','beg2')");
                break;
 
        case 'activate': // Do stuff when admin activates this extension
                // SQL commands to run
                addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_guest_menu` SET `visible`='Y', `locked`='N' WHERE `what`='beg' LIMIT 1");
-               addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_member_menu` SET `visible`='Y', `locked`='N' WHERE `what`='beg' LIMIT 1");
+               addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_member_menu` SET `visible`='Y', `locked`='N' WHERE `what` IN ('beg','beg2') LIMIT 2");
                addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_mod_reg` SET `locked`='N', `hidden`='N', `admin_only`='N', `mem_only`='N' WHERE `module`='beg' LIMIT 1");
                break;
 
@@ -104,10 +106,10 @@ PRIMARY KEY (id)
                                break;
 
                        case '0.0.3': // SQL queries for v0.0.3
-                               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD beg_points_max FLOAT(20,5) UNSIGNED NOT NULL DEFAULT '0.10000'");
+                               addConfigAddSql('beg_points_max', 'FLOAT(20,5) UNSIGNED NOT NULL DEFAULT 0.10000');
 
                                // Update notes (these will be set as task text!)
-                               setExtensionUpdateNotes("Maximale Obergrenze an {?POINTS?} einstellbar (Standart: 0,1 {?POINTS?})");
+                               setExtensionUpdateNotes("Maximale Obergrenze an {?POINTS?} einstellbar (Standard: 0,1 {?POINTS?})");
                                break;
 
                        case '0.0.4': // SQL queries for v0.0.4
@@ -121,14 +123,14 @@ PRIMARY KEY (id)
                                break;
 
                        case '0.0.6': // SQL queries for v0.0.6
-                               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD beg_userid BIGINT(20) UNSIGNED NOT NULL DEFAULT 0");
+                               addConfigAddSql('beg_userid', 'BIGINT(20) UNSIGNED NOT NULL DEFAULT 0');
 
                                // Update notes (these will be set as task text!)
                                setExtensionUpdateNotes("Ein Mitgliedsaccount (empfehlenswert ist Ihr eigenes!) kann zum Abbuchen der {?POINTS?} verwendet werden. Template <u>admin_config_beg.tpl</u> (und pro!) nicht vergessen, zu aktualisieren.");
                                break;
 
                        case '0.0.8': // SQL queries for v0.0.8
-                               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD beg_ip_timeout BIGINT(20) UNSIGNED NOT NULL DEFAULT 1800");
+                               addConfigAddSql('beg_ip_timeout', 'BIGINT(20) UNSIGNED NOT NULL DEFAULT 1800');
 
                                // Update notes (these will be set as task text!)
                                setExtensionUpdateNotes("Zeitsperre gegen die selbe IP-Nummer hinzugef&uuml;gt.");
@@ -151,16 +153,19 @@ PRIMARY KEY (id)
 
                        case '0.1.2':
                                // SQL queries for v0.1.2
-                               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD `beg_mode` ENUM('DIRECT','REF') NOT NULL DEFAULT 'REF'");
-                               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD `beg_ranks` TINYINT(3) UNSIGNED NOT NULL DEFAULT 10");
-                               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD `beg_active` ENUM('Y','N') NOT NULL DEFAULT 'N'");
-                               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD `beg_rallye` ENUM('Y','N') NOT NULL DEFAULT 'N'");
+                               addConfigAddSql('beg_mode', "ENUM('DIRECT','REF') NOT NULL DEFAULT 'REF'");
+                               addConfigAddSql('beg_ranks', 'TINYINT(3) UNSIGNED NOT NULL DEFAULT 10');
+                               addConfigAddSql('beg_active', "ENUM('Y','N') NOT NULL DEFAULT 'N'");
+                               addConfigAddSql('beg_rallye', "ENUM('Y','N') NOT NULL DEFAULT 'N'");
                                addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_user_data` ADD `beg_points` FLOAT(21,5) UNSIGNED NOT NULL DEFAULT 0.00000");
 
-                               $VIS = 'N'; $LOCKED = 'Y';
-                               if (isExtensionActive('beg')) { $VIS = 'Y'; $LOCKED = 'N'; }
+                               $visible = 'N'; $locked = 'Y';
+                               if (isExtensionActive('beg')) {
+                                       $visible = 'Y';
+                                       $locked = 'N';
+                               } // END - if
 
-                               addMemberMenuSql('main','beg2','Bettel-Rallye',$VIS,$LOCKED,7);
+                               addMemberMenuSql('main','beg2','Bettel-Rallye', $visible, $locked, 7);
                                addAdminMenuSql('user','list_beg','Bettel-Rallye','Listet alle Teilnehmer der monatlichen Bettel-Rallye auf.','12');
 
                                // Update notes (these will be set as task text!)
@@ -190,14 +195,14 @@ PRIMARY KEY (id)
                                break;
 
                        case '0.1.7': // SQL queries for v0.1.7
-                               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD `beg_ral_en_notify` ENUM('Y','N') NOT NULL DEFAULT 'N'");
-                               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD `beg_ral_di_notify` ENUM('Y','N') NOT NULL DEFAULT 'N'");
-                               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD `beg_new_mem_notify` ENUM('Y','N') NOT NULL DEFAULT 'N'");
-                               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD `beg_notify_bonus`  FLOAT(20,5) UNSIGNED NOT NULL DEFAULT 0.00000");
-                               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD `beg_notify_wait` BIGINT(20) UNSIGNED NOT NULL DEFAULT '30'");
-                               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_user_data` ADD `beg_ral_notify` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0");
-                               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_user_data` ADD `beg_ral_en_notify` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0");
-                               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_user_data` ADD `beg_ral_di_notify` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0");
+                               addConfigAddSql('beg_ral_en_notify', "ENUM('Y','N') NOT NULL DEFAULT 'N'");
+                               addConfigAddSql('beg_ral_di_notify', "ENUM('Y','N') NOT NULL DEFAULT 'N'");
+                               addConfigAddSql('beg_new_mem_notify', "ENUM('Y','N') NOT NULL DEFAULT 'N'");
+                               addConfigAddSql('beg_notify_bonus', 'FLOAT(20,5) UNSIGNED NOT NULL DEFAULT 0.00000');
+                               addConfigAddSql('beg_notify_wait', 'BIGINT(20) UNSIGNED NOT NULL DEFAULT 30');
+                               addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_user_data` ADD `beg_ral_notify` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0');
+                               addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_user_data` ADD `beg_ral_en_notify` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0');
+                               addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_user_data` ADD `beg_ral_di_notify` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0');
 
                                // Update notes (these will be set as task text!)
                                setExtensionUpdateNotes("Die Mitglieder k&ouml;nnen nun optional automatisch &uuml;ber eine aktivierte und/oder deaktivierte Bettel-Rallye informiert werden. Beide Benachrichtigungen k&ouml;nnen Sie unter <strong>Einstellungen --&gt; Bettel-Link/-rallye</strong> seperat ein- und ausschalten! Zudem ist eine Sperre gegen eingeloggte Mitglieder eingebaut, die das Klicken auf den eigenen Bettel-Link etwas erschweren soll.");
@@ -224,7 +229,7 @@ PRIMARY KEY (id)
                                break;
 
                        case '0.2.2': // SQL queries for v0.2.2
-                               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD beg_include_own ENUM('Y','N') NOT NULL DEFAULT 'N'");
+                               addConfigAddSql('beg_include_own', "ENUM('Y','N') NOT NULL DEFAULT 'N'");
 
                                // Update notes (these will be set as task text!)
                                setExtensionUpdateNotes("Eigene Mitglieder-Ids sind von der Bettel-Rallye nun ausschliessbar.");
@@ -248,30 +253,69 @@ PRIMARY KEY (id)
                                setExtensionUpdateNotes("Fehlerhinweis bei deaktivierter Erweiterung verbessert.");
                                break;
 
-                       case '0.2.6': // SQL queries for v0.2.6
-                               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_beg_ips` ADD sid VARCHAR(255) NOT NULL DEFAULT ''");
-                               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD `beg_pay_mode` ENUM('IMG','JS','BOTH','NONE') DEFAULT 'NONE' NOT NULL ;");
+                       case '0.2.6': // SQL queries for v0.2.6
+                               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_beg_ips` ADD `sid` VARCHAR(255) NOT NULL DEFAULT ''");
+                               addConfigAddSql('beg_pay_mode', "ENUM('IMG','JS','BOTH','NONE') DEFAULT 'NONE' NOT NULL ;");
 
                                // Update notes (these will be set as task text!)
                                setExtensionUpdateNotes("IP-Lock mit Session-Id erweitert. Tracker-Script eingef&uuml;gt, dass das Einbinden des Bettel-Links als Bild/Script/CSS verhindern soll.");
                                break;
-               }
+
+                       case '0.2.7': // SQL queries for v0.2.7
+                               addConfigChangeSql('beg_ral_en_notify', 'beg_ral_enable_notify', "ENUM('Y','N') NOT NULL DEFAULT 'N'");
+                               addConfigChangeSql('beg_ral_di_notify', 'beg_ral_disable_notify', "ENUM('Y','N') NOT NULL DEFAULT 'N'");
+                               addConfigChangeSql('beg_new_mem_notify', 'beg_new_member_notify', "ENUM('Y','N') NOT NULL DEFAULT 'N'");
+                               addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_user_data` CHANGE `beg_ral_en_notify` `beg_ral_enable_notify` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0');
+                               addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_user_data` CHANGE `beg_ral_di_notify` `beg_ral_disable_notify` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0');
+
+                               // Update notes (these will be set as task text!)
+                               setExtensionUpdateNotes("Umbenannt nach neuer Namenskonvention");
+                               break;
+
+                       case '0.2.8': // SQL queries for v0.2.8
+                               addConfigChangeSql('beg_ral_enable_notify', 'beg_rallye_enable_notify', "ENUM('Y','N') NOT NULL DEFAULT 'N'");
+                               addConfigChangeSql('beg_ral_disable_notify', 'beg_rallye_disable_notify', "ENUM('Y','N') NOT NULL DEFAULT 'N'");
+                               addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_user_data` CHANGE `beg_ral_enable_notify` `beg_rallye_enable_notify` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0');
+                               addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_user_data` CHANGE `beg_ral_disable_notify` `beg_rallye_disable_notify` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0');
+
+                               // Update notes (these will be set as task text!)
+                               setExtensionUpdateNotes("Umbenannt nach neuer Namenskonvention");
+                               break;
+
+                       case '0.2.9': // SQL queries for v0.2.9
+                               addDropTableSql('beg_referals');
+                               addCreateTableSql('beg_referals', "(
+`id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
+`userid` BIGINT(20) UNSIGNED NULL DEFAULT NULL ,
+`remote_ip` VARCHAR(15) NOT NULL DEFAULT '0.0.0.0',
+`timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ,
+`referal_url` TINYTEXT NOT NULL ,
+INDEX (`userid`)
+) ENGINE = {?_TABLE_TYPE?} CHARACTER SET utf8 COLLATE utf8_general_ci COMMENT = 'Recorded Referal URLs'");
+
+                               // Add admin menu
+                               addAdminMenuSql('user','list_beg_referal_urls','Bettel-Referals auflisten','Listet alle Bettellink-Aufrufe inklusive Referal-URL auf.','13');
+
+                               // Update notes (these will be set as task text!)
+                               setExtensionUpdateNotes("Loggen der Referal-URLs hinzugef&uuml;gt.");
+                               break;
+               } // END - switch
                break;
 
        case 'modify': // When the extension got modified
                break;
 
-       case 'test': // For testing purposes. For details see file inc/modules/admin/what-extensions.php, arround line 305.
+       case 'test': // For testing purposes
                break;
 
        case 'init': // When extension is initialized
                // Remove old entries
-               $OLD = getConfig('beg_timeout');
-               if (getConfig('beg_userid_timeout') > $OLD) $OLD = getConfig('beg_userid_timeout');
-               $result_ext = SQL_QUERY("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_beg_ips` WHERE `timeout` < (UNIX_TIMESTAMP() -".($OLD + 60*60).")", __FILE__, __LINE__);
+               $OLD = getBegTimeout();
+               if (getBegUseridTimeout() > $OLD) $OLD = getBegUseridTimeout();
+               SQL_QUERY('DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_beg_ips` WHERE `timeout` < (UNIX_TIMESTAMP() - ' . ($OLD + 60*60) . ')', __FILE__, __LINE__);
 
                // Check for beg rallye is active and send mails out
-               if ((getConfig('beg_rallye') == 'Y') && (getConfig('beg_new_mem_notify') == 'Y')) {
+               if ((isBegRallyeEnabled()) && (isBegNewMemberNotifyEnabled())) {
                        // Include file for sending out mails
                        addIncludeToPool('notify', 'inc/mails/beg_mails.php');
                } // END - if
@@ -280,7 +324,7 @@ PRIMARY KEY (id)
        default: // Unknown extension mode
                logDebugMessage(__FILE__, __LINE__, sprintf("Unknown extension mode %s in extension %s detected.", getExtensionMode(), getCurrentExtensionName()));
                break;
-}
+} // END - switch
 
-//
+// [EOF]
 ?>