Introduced wrapper function addCreateTableSql(), fixed parameter order:
[mailer.git] / inc / extensions / ext-doubler.php
index e28b7f3b68ca11ae16de97f9a6c6501a5a6dbdcb..43a732d7293c45a4ac34373cfefc49ba70150141 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /************************************************************************
- * MXChange v0.2.1                                    Start: 02/03/2005 *
- * ================                             Last change: 02/03/2005 *
+ * Mailer v0.2.1-FINAL                                Start: 02/03/2005 *
+ * ===================                          Last change: 02/03/2005 *
  *                                                                      *
  * -------------------------------------------------------------------- *
  * File              : ext-doubler.php                                  *
  * $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 - 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.1.6');
+setThisExtensionVersion('0.1.7');
 
 // 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'));
+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'));
 
 switch (getExtensionMode()) {
        case 'register': // Do stuff when installation is running (modules.php?module=admin is called)
                // Doubler table
-               addExtensionSql("DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_doubler`");
-               addExtensionSql("CREATE TABLE `{?_MYSQL_PREFIX?}_doubler` (
-id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
-userid BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
-refid BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
-points FLOAT(20,5) UNSIGNED NOT NULL DEFAULT 0.00000,
-remote_ip VARCHAR(15) NOT NULL DEFAULT '0.0.0.0',
-timemark VARCHAR(10) NOT NULL DEFAULT '',
-completed ENUM('Y','N') NOT NULL DEFAULT 'N',
-is_ref ENUM('Y','N') NOT NULL DEFAULT 'N',
-KEY (refid),
-KEY (userid),
-PRIMARY KEY (id)
-)TYPE=MYISAM");
+               addDropTableSql('doubler');
+               addCreateTableSql('doubler', "(
+`id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
+`userid` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
+`refid` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
+`points` FLOAT(20,5) UNSIGNED NOT NULL DEFAULT 0.00000,
+`remote_ip` VARCHAR(15) NOT NULL DEFAULT '0.0.0.0',
+`timemark` BIGINT(10) NOT NULL DEFAULT 0,
+`completed` ENUM('Y','N') NOT NULL DEFAULT 'N',
+`is_ref` ENUM('Y','N') NOT NULL DEFAULT 'N',
+KEY (`refid`),
+KEY (`userid`),
+PRIMARY KEY (`id`)
+) ENGINE = {?_TABLE_TYPE?} CHARACTER SET utf8 COLLATE utf8_general_ci COMMENT = 'User doubler data'");
 
                //
                // --- SETTINGS ---
                //
                // Minimum points to double
-               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD doubler_min FLOAT(20,5) UNSIGNED NOT NULL DEFAULT 100.00000");
+               addConfigAddSql('doubler_min', "FLOAT(20,5) UNSIGNED NOT NULL DEFAULT 100.00000");
                // Maximum points to double
-               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD doubler_max FLOAT(20,5) UNSIGNED NOT NULL DEFAULT 10000.00000");
+               addConfigAddSql('doubler_max', "FLOAT(20,5) UNSIGNED NOT NULL DEFAULT 10000.00000");
                // Points left on users account after doubling
-               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD doubler_left BIGINT(20) UNSIGNED NOT NULL DEFAULT 1000");
+               addConfigAddSql('doubler_left', "BIGINT(20) UNSIGNED NOT NULL DEFAULT 1000");
                // Charge for doubling points which goes to the webmaster (shreddered in fact!)
-               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD doubler_charge FLOAT(7,5) UNSIGNED NOT NULL DEFAULT 0.03000");
+               addConfigAddSql('doubler_charge', "FLOAT(7,5) UNSIGNED NOT NULL DEFAULT 0.03000");
                // Referal percents
-               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD doubler_ref FLOAT(7,5) UNSIGNED NOT NULL DEFAULT 0.02000");
+               addConfigAddSql('doubler_ref', "FLOAT(7,5) UNSIGNED NOT NULL DEFAULT 0.02000");
                // Shall I use the jackpot to take points from? (Y/N, default=Y)
-               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD doubler_jackpot ENUM('Y','N') NOT NULL DEFAULT 'Y'");
+               addConfigAddSql('doubler_jackpot', "ENUM('Y','N') NOT NULL DEFAULT 'Y'");
                // A user account to take points from (default: 0->none)
-               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD doubler_userid BIGINT(20) UNSIGNED NOT NULL DEFAULT 0");
+               addConfigAddSql('doubler_userid', "BIGINT(20) UNSIGNED NOT NULL DEFAULT 0");
                // Total payed out points from your doublers
-               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD doubler_points FLOAT(20,5) UNSIGNED NOT NULL DEFAULT 0.00000");
+               addConfigAddSql('doubler_points', "FLOAT(20,5) UNSIGNED NOT NULL DEFAULT 0.00000");
                // Sending mode of mails (immediately/daily reset)
                // --> This also means who fast the doubled points will be payed out!
-               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD doubler_send_mode ENUM('DIRECT','RESET') NOT NULL DEFAULT 'DIRECT'");
+               addConfigAddSql('doubler_send_mode', "ENUM('DIRECT','RESET') NOT NULL DEFAULT 'DIRECT'");
                // Timeout for entries to be purged (default: one week)
-               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD doubler_timeout BIGINT(20) UNSIGNED NOT NULL DEFAULT ".(getConfig('ONE_DAY')*7)."");
+               addConfigAddSql('doubler_timeout', "BIGINT(20) UNSIGNED NOT NULL DEFAULT ".(getOneDay()*7)."");
                // Number of newest entries to display
-               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD doubler_display_new TINYINT(3) UNSIGNED NOT NULL DEFAULT 10");
+               addConfigAddSql('doubler_display_new', "TINYINT(3) UNSIGNED NOT NULL DEFAULT 10");
                // Number of entries which will be payed out soon
-               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD doubler_display_pay TINYINT(3) UNSIGNED NOT NULL DEFAULT 10");
+               addConfigAddSql('doubler_display_pay', "TINYINT(3) UNSIGNED NOT NULL DEFAULT 10");
                // Number of entries which are already payed out
-               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD doubler_display_old TINYINT(3) UNSIGNED NOT NULL DEFAULT 10");
+               addConfigAddSql('doubler_display_old', "TINYINT(3) UNSIGNED NOT NULL DEFAULT 10");
                // Points used by every member
-               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_user_data` ADD doubler_points FLOAT(20,5) UNSIGNED NOT NULL DEFAULT 0.00000");
+               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_user_data` ADD `doubler_points` FLOAT(20,5) UNSIGNED NOT NULL DEFAULT 0.00000");
                // Counter for usage of the doubler
-               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD doubler_counter BIGINT(20) UNSIGNED NOT NULL DEFAULT 0");
+               addConfigAddSql('doubler_counter', "BIGINT(20) UNSIGNED NOT NULL DEFAULT 0");
 
                //
                // --- MENU SYSTEMS ---
                //
                // Admin menu
-               addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES ('doubler', NULL, '{?POINTS?}-Verdoppler','Einstellungen und Eintr&auml;ge auflisten.', 4)");
-               addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES ('doubler','list_doubler','Auflisten','Eintr&auml;ge aus der Verdiensttabelle auflisten', 1)");
-               addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES ('doubler','config_doubler','Einstellungen','Prozentuale Geb&uuml;hr usw. einstellen.', 2)");
+               addAdminMenuSql('doubler', NULL, '{OPEN_CONFIG}POINTS{CLOSE_CONFIG}-Verdoppler','Einstellungen und Eintr&auml;ge auflisten.', 4);
+               addAdminMenuSql('doubler','list_doubler','Auflisten','Eintr&auml;ge aus der Verdiensttabelle auflisten', 1);
+               addAdminMenuSql('doubler','config_doubler','Einstellungen','Prozentuale Geb&uuml;hr usw. einstellen.', 2);
 
                // Guest menu (informations / default doubler link)
-               addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_guest_menu` (`action`,`what`,`title`,`sort`,`visible`,`locked`) VALUES ('main','doubler','Verdoppeln!',3,'Y','Y')");
+               addGuestMenuSql('main','doubler','Verdoppeln!','N','Y',3);
 
                // Member menu
-               addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_member_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES ('main','doubler','Verdoppeln!','Y','Y',7)");
+               addMemberMenuSql('main','doubler','Verdoppeln!','N','Y',7);
                break;
 
        case 'remove': // Do stuff when removing extension
                // SQL commands to run
-               addExtensionSql("DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_doubler`");
+               addDropTableSql('doubler');
                addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE `action`='doubler'");
                addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_guest_menu` WHERE `what`='doubler'");
                addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE `what`='doubler'");
@@ -141,12 +140,12 @@ PRIMARY KEY (id)
                switch (getCurrentExtensionVersion()) {
                        case '0.0.1': // SQL queries for v0.0.1
                                // Update notes (these will be set as task text!)
-                               setExtensionUpdateNotes("Problem mit User-ID behoben!");
+                               setExtensionUpdateNotes("Problem mit Mitglieder-Id behoben.");
                                break;
 
                        case '0.0.2': // SQL queries for v0.0.2
                                // Total used points
-                               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD doubler_used FLOAT(20,5) UNSIGNED NOT NULL DEFAULT 0.00000");
+                               addConfigAddSql('doubler_user', "FLOAT(20,5) UNSIGNED NOT NULL DEFAULT 0.00000");
 
                                // Update notes (these will be set as task text!)
                                setExtensionUpdateNotes("Geb&uuml;hr wird vom Verdoppler-Pott abgezogen.");
@@ -159,10 +158,10 @@ PRIMARY KEY (id)
 
                        case '0.0.4': // SQL queries for v0.0.4
                                // Shall I use the doubler's account to take points from? (Y/N, default=Y)
-                               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD doubler_own ENUM('Y','N') NOT NULL DEFAULT 'Y'");
+                               addConfigAddSql('doubler_own', "ENUM('Y','N') NOT NULL DEFAULT 'Y'");
 
                                // Update notes (these will be set as task text!)
-                               setExtensionUpdateNotes(POINTS."-Guthaben des Verdopplers kann optional nicht mit einbezogen werden.");
+                               setExtensionUpdateNotes("{?POINTS?}-Guthaben des Verdopplers kann optional nicht mit einbezogen werden.");
                                break;
 
                                case '0.0.5': // SQL queries for v0.0.5
@@ -171,9 +170,9 @@ PRIMARY KEY (id)
                                        break;
 
                                case '0.0.6': // SQL queries for v0.0.6
-                                       addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD doubler_max_sent TINYINT(3) UNSIGNED NOT NULL DEFAULT 1");
-                                       addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD doubler_group_sent TINYINT(3) UNSIGNED NOT NULL DEFAULT 1");
-                                       addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD doubler_sent_all ENUM('Y','N') NOT NULL DEFAULT 'Y'");
+                                       addConfigAddSql('doubler_max_sent', "TINYINT(3) UNSIGNED NOT NULL DEFAULT 1");
+                                       addConfigAddSql('doubler_group_sent', "TINYINT(3) UNSIGNED NOT NULL DEFAULT 1");
+                                       addConfigAddSql('doubler_sent_all', "ENUM('Y','N') NOT NULL DEFAULT 'Y'");
 
                                        // Update notes (these will be set as task text!)
                                        setExtensionUpdateNotes("Geb&uuml;hrenabzug wird beim Einzahlen abgezogen (wurde von Auszahlung abgezogen) und maximal bei Auszahlung zu kontrollierende Accounts einstellbar.<br />Template <u>admin_config_doubler_pro.tpl</u> ist &uuml;berfl&uuml;ssig geworden. Bitte l&ouml;schen Sie dies!");
@@ -181,7 +180,7 @@ PRIMARY KEY (id)
 
                                case '0.0.7': // SQL queries for v0.0.7
                                        // Update notes (these will be set as task text!)
-                                       setExtensionUpdateNotes("W&ouml;rter <strong>Mailtausch</strong>, <strong>Mailtausches</strong> und <strong>Mailtauscher</strong> sind austauschbar.<br /><br />Minus-Guthaben des Verdoppler-Accounts repariert und Mitgliedsmail erweitert mit Transaktionsummer und IP-Nummer.");
+                                       setExtensionUpdateNotes("W&ouml;rter <strong>{?mt_word?}</strong>, <strong>{?mt_word2?}</strong> und <strong>{?mt_word3?}</strong> sind austauschbar.<br /><br />Minus-Guthaben des Verdoppler-Accounts repariert und Mitgliedsmail erweitert mit Transaktionsummer und IP-Nummer.");
                                        break;
 
                                case '0.0.8': // SQL queries for v0.0.8
@@ -215,7 +214,7 @@ PRIMARY KEY (id)
                                        break;
 
                                case '0.1.4': // SQL queries for v0.1.4
-                                       addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_member_menu` SET `action`='extras', `sort`='4' WHERE `what`='doubler' LIMIT 1");
+                                       addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_member_menu` SET `action`='extras', `sort`=4 WHERE `what`='doubler' LIMIT 1");
 
                                        // Update notes (these will be set as task text!)
                                        setExtensionUpdateNotes("Mitgliedsmen&uuml; komplett umgebaut.");
@@ -230,22 +229,30 @@ PRIMARY KEY (id)
                                        // Update notes (these will be set as task text!)
                                        setExtensionUpdateNotes("Fehlerhinweis bei deaktivierter Erweiterung verbessert.");
                                        break;
-               }
+
+                               case '0.1.7': // SQL queries for v0.1.7
+                                       addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_config` SET `doubler_charge`=`doubler_charge`*100");
+                                       addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_config` SET `doubler_ref`=`doubler_ref`*100");
+
+                                       // Update notes (these will be set as task text!)
+                                       setExtensionUpdateNotes("Fehlerhinweis bei deaktivierter Erweiterung verbessert.");
+                                       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': // Do stuff when extension is initialized
                break;
 
        default: // Unknown extension mode
-               DEBUG_LOG(__FILE__, __LINE__, sprintf("Unknown extension mode %s detected.", getExtensionMode()));
+               logDebugMessage(__FILE__, __LINE__, sprintf("Unknown extension mode %s in extension %s detected.", getExtensionMode(), getCurrentExtensionName()));
                break;
-}
+} // END - switch
 
 // [EOF]
 ?>