A lot has been rewritten, ext-teams added, ext-forced continued:
[mailer.git] / inc / extensions / ext-funcoins.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 08/19/2010 *
4  * ===================                          Last change: 08/19/2010 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : ext-funcoins.php                                 *
8  * -------------------------------------------------------------------- *
9  * Short description : Extension for the FunCoins API integration       *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Erweiterung fuer die Integration der             *
12  *                     FunCoins-API (FoCo-Ex&#178;)                          *
13  * -------------------------------------------------------------------- *
14  * $Revision::                                                        $ *
15  * $Date::                                                            $ *
16  * $Tag:: 0.2.1-FINAL                                                 $ *
17  * $Author::                                                          $ *
18  * -------------------------------------------------------------------- *
19  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
20  * Copyright (c) 2009 - 2011 by Mailer Developer Team                   *
21  * For more information visit: http://www.mxchange.org                  *
22  *                                                                      *
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.                                  *
27  *                                                                      *
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.                         *
32  *                                                                      *
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,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
41         die();
42 } // END - if
43
44 // Version number
45 setThisExtensionVersion('0.0.0');
46
47 // Version history array (add more with , '0.0.1' and so on)
48 setExtensionVersionHistory(array('0.0.0'));
49
50 // This extension is in development (non-productive)
51 enableExtensionProductive(false);
52
53 switch (getExtensionMode()) {
54         case 'register': // Do stuff when installation is running
55                 // This depends on ext-sql_patches
56                 addExtensionDependency('sql_patches');
57
58                 // SQL commands to run
59                 addDropTableSql('user_funcoins');
60                 addCreateTableSql('user_funcoins', "
61 `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'Record identification',
62 `userid` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'Local userid',
63 `funcoins_account` VARCHAR(255) NOT NULL DEFAULT '' COMMENT 'FunCoins account',
64 `funcoins_amount` FLOAT(20,5) UNSIGNED NOT NULL DEFAULT 0.00000 COMMENT 'Transfered amount',
65 `funcoins_timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Booking timestamp',
66 `funcoins_type` ENUM('WITHDRAW','PAYOUT','FAILED') NOT NULL DEFAULT 'FAILED' COMMENT 'Transaction type',
67 `funcoins_tan` VARCHAR(255) NULL DEFAULT NULL COMMENT 'TAN from API',
68 `funcoins_api_response` TINYTEXT COMMENT 'Clear text API response (only for debugging)',
69 `funcoins_api_status` INT(4) NULL DEFAULT NULL COMMENT 'Status code from API',
70 PRIMARY KEY (`id`),
71 UNIQUE (`funcoins_tan`),
72 INDEX (`userid`)",
73                         'Transfered FunCoins per user');
74
75                 // Confiuration
76                 addConfigAddSql('funcoins_min_payout', 'BIGINT(20) UNSIGNED NOT NULL DEFAULT 40000');
77                 addConfigAddSql('funcoins_min_withdraw', 'BIGINT(20) UNSIGNED NOT NULL DEFAULT 5000');
78                 addConfigAddSql('funcoins_api_id', 'BIGINT(20) UNSIGNED NOT NULL DEFAULT 0');
79                 addConfigAddSql('funcoins_api_password', "VARCHAR(255) NOT NULL DEFAULT ''");
80                 addConfigAddSql('funcoins_refid', 'BIGINT(20) UNSIGNED NOT NULL DEFAULT 0');
81                 addConfigAddSql('funcoins_payout_active', "ENUM ('Y','N') NOT NULL DEFAULT 'Y'");
82                 addConfigAddSql('funcoins_withdraw_active', "ENUM ('Y','N') NOT NULL DEFAULT 'Y'");
83                 addConfigAddSql('funcoins_payout_factor', 'FLOAT(20,5) UNSIGNED NOT NULL DEFAULT 1.00000');
84                 addConfigAddSql('funcoins_withdraw_factor', 'FLOAT(20,5) UNSIGNED NOT NULL DEFAULT 1.00000');
85                 addConfigAddSql('funcoins_payout_fee_percent', 'FLOAT(8,5) UNSIGNED NOT NULL DEFAULT 0.00000');
86                 addConfigAddSql('funcoins_withdraw_fee_percent', 'FLOAT(8,5) UNSIGNED NOT NULL DEFAULT 0.00000');
87                 addConfigAddSql('funcoins_payout_fee_fix', 'BIGINT(20) UNSIGNED NOT NULL DEFAULT 0');
88                 addConfigAddSql('funcoins_withdraw_fee_fix', 'BIGINT(20) UNSIGNED NOT NULL DEFAULT 0');
89
90                 // Points data
91                 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_points_data` (`subject`,`column_name`,`locked_mode`,`payment_method`) VALUES ('funcoins_withdraw','order_points','LOCKED','DIRECT')");
92
93                 // User data
94                 addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_user_data` ADD `funcoins_userid` BIGINT(20) NULL DEFAULT NULL");
95
96                 // Admin menu
97                 addAdminMenuSql('funcoins', NULL, 'FunCoins-Management', 'Konfiguration zur FuCo-Ex&#178; einstellen, Auszahlungen auflisten usw..', 15);
98                 addAdminMenuSql('funcoins', 'config_funcoins', 'FuCo-Ex&#178;-Einstellungen', 'Konfiguration zur FuCo-Ex&#178; einstellen.', 1);
99                 addAdminMenuSql('funcoins', 'list_funcoins', 'Anfragen auflisten', 'Listet alle FunCoins-Ein- und -Auszahlungsanfragen Ihrer Mitglieder und Sponsoren auf.', 2);
100
101                 // Member menu
102                 addMemberMenuSql('main', 'funcoins', 'FunCoins-Ein-/Auszahlungen', 11);
103                 break;
104
105         case 'remove': // Do stuff when removing extension
106                 // SQL commands to run
107                 addDropTableSql('user_funcoins');
108                 addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE `action`='funcoins'");
109                 addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE `what`='funcoins' LIMIT 1");
110                 addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_guest_menu` WHERE `what`='funcoins_portal' LIMIT 1");
111                 break;
112
113         case 'activate': // Do stuff when admin activates this extension
114                 // SQL commands to run
115                 addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_guest_menu` SET `visible`='Y', `locked`='N' WHERE `what`='funcoins_portal' LIMIT 1");
116                 addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_member_menu` SET `visible`='Y', `locked`='N' WHERE `what`='funcoins' LIMIT 1");
117                 break;
118
119         case 'deactivate': // Do stuff when admin deactivates this extension
120                 // SQL commands to run
121                 addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_guest_menu` SET `visible`='N', `locked`='Y' WHERE `what`='funcoins_portal' LIMIT 1");
122                 addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_member_menu` SET `visible`='N', `locked`='Y' WHERE `what`='funcoins' LIMIT 1");
123                 break;
124
125         case 'update': // Update an extension
126                 switch (getCurrentExtensionVersion()) {
127                         case '0.0.1': // SQL queries for v0.0.1
128                                 addExtensionSql('');
129
130                                 // Update notes (these will be set as task text!)
131                                 setExtensionUpdateNotes('');
132                                 break;
133                 } // END - switch
134                 break;
135
136         case 'modify': // When the extension got modified
137                 break;
138
139         case 'test': // For testing purposes
140                 break;
141
142         case 'init': // Do stuff when extension is initialized
143                 // Init array
144                 $GLOBALS['funcoins_data'] = array();
145                 break;
146
147         default: // Unknown extension mode
148                 logDebugMessage(__FILE__, __LINE__, sprintf("Unknown extension mode %s in extension %s detected.", getExtensionMode(), getCurrentExtensionName()));
149                 break;
150 } // END - switch
151
152 // [EOF]
153 ?>