]> git.mxchange.org Git - mailer.git/blobdiff - inc/extensions/ext-coupon.php
Moved "fix" files (which only helps to fix stuff) in own inc/fixes/ folder.
[mailer.git] / inc / extensions / ext-coupon.php
index f173b2c4f8261f639cc7b1a02b017263d9675071..544d111ea849deeade0610a4bf4884c0a4d7c4fe 100644 (file)
@@ -18,8 +18,8 @@
  * $Author::                                                          $ *
  * -------------------------------------------------------------------- *
  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
- * Copyright (c) 2009 - 2011 by Mailer Developer Team                   *
- * For more information visit: http://www.mxchange.org                  *
+ * Copyright (c) 2009 - 2016 by Mailer Developer Team                   *
+ * For more information visit: http://mxchange.org                      *
  *                                                                      *
  * This program is free software; you can redistribute it and/or modify *
  * it under the terms of the GNU General Public License as published by *
@@ -43,71 +43,124 @@ if (!defined('__SECURITY')) {
 } // END - if
 
 // Version number
-setThisExtensionVersion('0.0');
+setThisExtensionVersion('0.0.3');
 
 // Version history array (add more with , '0.1' and so on)
-setExtensionVersionHistory(array('0.0'));
-
-// This extension is in development (non-productive)
-enableExtensionProductive(false);
+setExtensionVersionHistory(array('0.0.0', '0.0.1', '0.0.2', '0.0.3'));
 
 switch (getExtensionMode()) {
-       case 'register': // Do stuff when installtion is running (modules.php?module=admin&action=login is called)
+       case 'setup': // Do stuff when installtion is running
+               // This extension requires an up-to-date ext-user
+               addExtensionDependency('user');
+               addExtensionDependency('autopurge');
+
                // Coupon data
-               addDropTableSql('coupons');
-               addCreateTableSql('coupons', "(
+               addDropTableSql('coupon_data');
+               addCreateTableSql('coupon_data', "
 `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
-`timestamp_created` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00',
-`timestamp_expired` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00',
+`coupon_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
+`coupon_expired` TIMESTAMP NULL DEFAULT NULL,
 `coupon_type` ENUM('CODE','API') NOT NULL DEFAULT 'CODE',
-`coupon_code` VARCHAR(30) NULL DEFAULT NULL,
-`total_created` UNSIGNED BIGINT(20) NOT NULL DEFAULT 0,
-`total_used` UNSIGNED BIGINT(20) NOT NULL DEFAULT 0,
-`coupon_description` TEXT,
-PRIMARY KEY (`id`),
-UNIQUE KEY (`coupon_code`)
-) TYPE = {?_TABLE_TYPE?} CHARACTER SET utf8 COLLATE utf8_general_ci COMMENT = 'Created coupons'");
+`total_created` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
+`total_cashed` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
+`points` FLOAT(20,5) UNSIGNED NOT NULL DEFAULT 0.00000,
+`coupon_description` TEXT NOT NULL,
+PRIMARY KEY (`id`)",
+               'Created coupons');
 
                // Coupon->user connection table
                addDropTableSql('user_coupons');
-               addCreateTableSql('coupons', "(
+               addCreateTableSql('user_coupons', "
 `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
-`coupon_id BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
+`coupon_id` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
 `userid` BIGINT(2) UNSIGNED NOT NULL DEFAULT 0,
+`coupon_code` VARCHAR(30) NULL DEFAULT NULL,
+`cashed_on` TIMESTAMP NULL DEFAULT NULL,
 PRIMARY KEY (`id`),
-UNIQUE KEY `coupon_user` (`coupon_id`,`userid`)
-) TYPE = {?_TABLE_TYPE?} CHARACTER SET utf8 COLLATE utf8_general_ci COMMENT = 'Coupon->user connection'");
+UNIQUE INDEX `coupon_user` (`coupon_id`, `userid`),
+UNIQUE INDEX (`coupon_code`)",
+                       'Coupon->user connection');
 
                // Configuration entries
-
-               // Admin menus
-               addAdminMenuSql('setup','config_coupon','Gutscheine','Allgemeine Einstellungen zu Code-Gutscheinen und Gutscheinen von Sponsoren (z.B. per API) können hier vorgenommen werden.', 15);
+               addConfigAddSql('coupon_default_time', 'BIGINT(20) NOT NULL DEFAULT ' . (getOneDay() * 7));
+               addConfigAddSql('coupon_default_points', 'FLOAT(20,5) UNSIGNED NOT NULL DEFAULT 100.00000');
+               addConfigAddSql('coupon_autopurge_time', 'BIGINT(20) NOT NULL DEFAULT ' . (getOneDay() * 7));
+               addConfigAddSql('coupon_userid', 'BIGINT(20) UNSIGNED NOT NULL DEFAULT 0');
+
+               // User data table
+               addExtensionAddTableColumnSql('user_data', 'receiving_coupons', "ENUM('Y','N') NOT NULL DEFAULT 'Y'");
+
+               // Menu systems:
+               //  - Admin entries
+               addAdminMenuSql('coupon', NULL, 'Gutscheine', 'Einrichten und Versenden von Code-Gutscheinen, sowie per API (noch in Planung). Bei Code-Gutscheinen wird ein Code pro Mitglied erzeugt, der dann an das Mitglied ausgesandt wird. Löst das Mitglied den Gutschein ein, erhält es die Gutschrift auf sein Konto gutgeschrieben. Ausgangseinstellung ist die Gutschrift auf das Werbeguthaben, was für Paidmailer von Wichtigkeit ist, dass Guthaben aus Gutscheinen nicht auszahlungsfähig ist.', 6);
+               addAdminMenuSql('coupon', 'list_coupon', 'Auflisten', 'Listet alle Gutscheine und Einlösungen durch die Mitglieder auf.', 1);
+               addAdminMenuSql('coupon', 'send_coupon', 'Versenden/Neuen erstellen', 'Versendet neue Gutscheine an die Mitglieder. Wenn Sie auf "Absenden" klicken, warten Sie bitte die Folgeseite ab, da der Versand der Gutscheine derzeit nicht gepoolt ist.', 2);
+               addAdminMenuSql('coupon', 'config_coupon', 'Einstellungen', 'Allgemeine Einstellungen zu Code-Gutscheinen und Gutscheinen von Sponsoren (z.B. per API) können hier vorgenommen werden.', 3);
+               //  - Member entries
+               addMemberMenuSql('coupon', NULL, 'Gutscheine', 3);
+               addMemberMenuSql('coupon', 'cash_coupon', 'Gutschein einlösen', 1);
+               addMemberMenuSql('coupon', 'list_coupon', 'Eingelöste auflisten', 2);
+
+               // Add filter (for changing user_points column dynamically
+               registerFilter(__FILE__, __LINE__, 'determine_points_column_name', 'COUPON_CHANGE_POINTS_COLUMN_NAME', FALSE, TRUE, isExtensionDryRun());
                break;
 
        case 'remove': // Do stuff when removing extension
                // SQL commands to run
-               addDropTableSql('coupons');
+               addDropTableSql('coupon_data');
                addDropTableSql('user_coupons');
+               addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE `action`='coupon' LIMIT 4");
+               addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE `action`='coupon' LIMIT 3");
+
+               // Remove points data
+               unregisterExtensionPointsData('coupon_cashed');
+
+               // Remove all filters
+               unregisterFilter(__FILE__, __LINE__, 'determine_points_column_name', 'COUPON_CHANGE_POINTS_COLUMN_NAME', TRUE, isExtensionDryRun());
+               unregisterFilter(__FILE__, __LINE__, 'post_cash_coupon', 'POST_CASH_COUPON', TRUE, isExtensionDryRun());
                break;
 
        case 'activate': // Do stuff when admin activates this extension
                // SQL commands to run
-               addExtensionSql('');
+               addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_member_menu` SET `visible`='Y',`locked`='N' WHERE `action`='coupon' LIMIT 3");
                break;
 
        case 'deactivate': // Do stuff when admin deactivates this extension
                // SQL commands to run
-               addExtensionSql('');
+               addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_member_menu` SET `visible`='N',`locked`='Y' WHERE `action`='coupon' LIMIT 3");
                break;
 
        case 'update': // Update an extension
                switch (getCurrentExtensionVersion()) {
                        case '0.0.1': // SQL queries for v0.0.1
-                               addExtensionSql('');
+                               addConfigDropSql('coupon_points_account');
+                               addConfigDropSql('coupon_payment_method');
+                               addConfigDropSql('coupon_locked_points_mode');
+
+                               // This extension's update requires an up-to-date ext-order
+                               addExtensionDependency('order');
+
+                               // Insert data in new table
+                               registerExtensionPointsData('coupon_cashed', 'order_points', 'LOCKED', 'DIRECT');
 
                                // Update notes (these will be set as task text!)
                                setExtensionUpdateNotes('');
                                break;
+
+                       case '0.0.2': // SQL queries for v0.0.2
+                               // Update data in points_data table
+                               addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_points_data` SET `subject`='coupon_cashed' WHERE `subject`='coupon' LIMIT 1");
+
+                               // Update notes (these will be set as task text!)
+                               setExtensionUpdateNotes('Eintrag in <strong>{CONFIG_OPEN}_MYSQL_PREFIX{CONFIG_CLOSE}_points_data</strong> umbenannt.');
+                               break;
+
+                       case '0.0.3': // SQL queries for v0.0.3
+                               registerFilter(__FILE__, __LINE__, 'post_cash_coupon', 'POST_CASH_COUPON', FALSE, TRUE, isExtensionDryRun());
+
+                               // Update notes (these will be set as task text!)
+                               setExtensionUpdateNotes('Filter zum Post- und Pre-Filter hinzugef&uuml;gt.');
+                               break;
                } // END - switch
                break;
 
@@ -121,7 +174,7 @@ UNIQUE KEY `coupon_user` (`coupon_id`,`userid`)
                break;
 
        default: // Unknown extension mode
-               logDebugMessage(__FILE__, __LINE__, sprintf("Unknown extension mode %s in extension %s detected.", getExtensionMode(), getCurrentExtensionName()));
+               reportBug(__FILE__, __LINE__, sprintf('Unknown extension mode %s in extension %s detected.', getExtensionMode(), getCurrentExtensionName()));
                break;
 } // END - switch