ext-network continued (unfinished), weekly and monthly reset scripts fixed
[mailer.git] / inc / extensions / ext-network.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 12/18/2008 *
4  * ================                             Last change: 12/18/2008 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : ext-network.php                                  *
8  * -------------------------------------------------------------------- *
9  * Short description : Generic (sponsor) network connection extension   *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Allgemeine Sponsornetzwerk Erweiterung           *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
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                  *
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');
46
47 // Version history array (add more with , '0.1.0' and so on)
48 setExtensionVersionHistory(array('0.0'));
49
50 switch (getExtensionMode()) {
51         case 'register': // Do stuff when installation is running (modules.php?module=admin is called)
52                 // Main table which hold
53                 addExtensionSql("DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_network_data`");
54                 addExtensionSql("CREATE TABLE `{?_MYSQL_PREFIX?}_network_data` (
55 `network_id` BIGINT(20) NOT NULL AUTO_INCREMENT,
56 `network_name` VARCHAR(255) NOT NULL DEFAULT '',
57 `network_title` VARCHAR(255) NOT NULL DEFAULT '',
58 `network_reflink` VARCHAR(255) NOT NULL DEFAULT '',
59 `network_data_seperator CHAR(4) NOT NULL DEFAULT '|',
60 `network_row_seperator CHAR(4) NOT NULL DEFAULT '|',
61 `network_request_type` ENUM('GET','POST') NOT NULL DEFAULT 'GET',
62 UNIQUE (`network_name`),
63 PRIMARY KEY (`network_id`)
64 ) TYPE={?_TABLE_TYPE?} COMMENT='Network data'");
65
66                 // Types the network provider is supporting (e.g. Forced-Banner and so on)
67                 addExtensionSql("DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_network_types`");
68                 addExtensionSql("CREATE TABLE `{?_MYSQL_PREFIX?}_network_types` (
69 `network_type_id` BIGINT(20) NOT NULL AUTO_INCREMENT,
70 `network_type_name` VARCHAR(255) NOT NULL DEFAULT '',
71 `network_type_title` VARCHAR(255) NOT NULL DEFAULT '',
72 `network_type_request_url` VARCHAR(255) NOT NULL DEFAULT '',
73 `network_type_click_url` VARCHAR(255) NOT NULL DEFAULT '',
74 `network_type_banner_url` VARCHAR(255) NOT NULL DEFAULT '',
75 UNIQUE (`network_type_name`),
76 PRIMARY KEY (`network_type_id`)
77 ) TYPE={?_TABLE_TYPE?} COMMENT='Types provideable by networks'");
78
79                 // Error status codes
80                 addExtensionSql("DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_network_type_errors`");
81                 addExtensionSql("CREATE TABLE `{?_MYSQL_PREFIX?}_network_type_codes` (
82 `network_type_code_id` BIGINT(20) NOT NULL AUTO_INCREMENT,
83 `network_type_code_value` VARCHAR(50) NOT NULL DEFAULT '',
84 `network_type_code_type` VARCHAR(100) NOT NULL DEFAULT 'INVALID_TYPE',
85 `network_type_id` BIGINT(20) NOT NULL DEFAULT 0,
86 UNIQUE `code_type` (`network_type_code_value`,`network_type_id`),
87 INDEX (`network_type_id`),
88 PRIMARY KEY (`network_type_code_id`)
89 ) TYPE={?_TABLE_TYPE?} COMMENT='Error codes for all types'");
90
91                 // Code types (internal table)
92                 addExtensionSql("DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_network_codes`");
93                 addExtensionSql("CREATE TABLE `{?_MYSQL_PREFIX?}_network_codes` (
94 `network_code_id` BIGINT(20) NOT NULL AUTO_INCREMENT,
95 `network_code_type` VARCHAR(100) NOT NULL DEFAULT 'INVALID_TYPE',
96 UNIQUE (`network_code_type`),
97 PRIMARY KEY (`network_code_id`)
98 ) TYPE={?_TABLE_TYPE?} COMMENT='Error types, generic data, DO NOT ALTER!'");
99
100                 // Which network provider is serving which types
101                 addExtensionSql("DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_network_provider_types`");
102                 addExtensionSql("CREATE TABLE `{?_MYSQL_PREFIX?}_network_provider_types` (
103 `network_prodider_type_id` BIGINT(20) NOT NULL AUTO_INCREMENT,
104 `network_id` BIGINT(20) NOT NULL DEFAULT 0,
105 `network_type_id` BIGINT(20) NOT NULL DEFAULT 0,
106 UNIQUE `provider_type` (`network_id`, `network_type_id`),
107 PRIMARY KEY (`network_provider_type_id`)
108 ) TYPE={?_TABLE_TYPE?} COMMENT='Connection table between provider and types'");
109
110                 // Data from the webmaster (you!)
111                 addExtensionSql("DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_network_config_data`");
112                 addExtensionSql("CREATE TABLE `{?_MYSQL_PREFIX?}_network_config_data` (
113 `network_id` BIGINT(20) NOT NULL DEFAULT 0,
114 `network_affiliate_id` BIGINT(20) NOT NULL DEFAULT 0,
115 `network_api_password` VARCHAR(255) NOT NULL DEFAULT '',
116 `network_site_id` BIGINT(20) NOT NULL DEFAULT 0,
117 UNIQUE `network_affiliate` (`network_id`,`network_affiliate_id`),
118 UNIQUE `affiliate_site` (`network_affiliate_id`,`network_site_id`),
119 PRIMARY KEY (`network_id`)
120 ) TYPE={?_TABLE_TYPE?} COMMENT='Configuration data from the webmaster (you!)'");
121
122                 // Insert error code types
123                 // - Affiliate id or interface password wrong
124                 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_network_codes` (`network_code_type`) VALUES ('AFF_ID_PASS_WRONG')");
125                 // - Webmaster's site id is not assigned (invalid, different affiliate id)
126                 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_network_codes` (`network_code_type`) VALUES ('SITE_ID_NOT_ASSIGNED')");
127                 // - Webmaster's site id is locked
128                 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_network_codes` (`network_code_type`) VALUES ('SITE_ID_LOCKED')");
129                 // - General error in interface data
130                 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_network_codes` (`network_code_type`) VALUES ('INTERFACE_DATA_ERROR')");
131                 // - Request amount depleted
132                 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_network_codes` (`network_code_type`) VALUES ('REQUESTS_DEPLETED')");
133                 // - No campaigns found for given criteria (but maybe there are with more widen criteria)
134                 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_network_codes` (`network_code_type`) VALUES ('NO_CAMPAIGNS_FOUND')");
135                 // - No campaigns found with allowed interface output (but there are maybe non-interface campaigns)
136                 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_network_codes` (`network_code_type`) VALUES ('NO_CAMPAIGNS_FOUND_INTERFACE')");
137                 // - Webmaster's site id is not unlocked for choosen type
138                 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_network_codes` (`network_code_type`) VALUES ('SITE_ID_NOT_ALLOWED_TYPE')");
139                 // - Request parameters incomplete
140                 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_network_codes` (`network_code_type`) VALUES ('REQUEST_PARAMS_INCOMPLETE')");
141
142                 // Admin menu entries
143                 addAdminMenuSql('network',NULL,'Sponsorennetzwerke','Verwalten Sie hier Sponsornetzwerke (API-Anbindung), versenden Sie deren Mails, oder &uuml;bernehmen Sie deren Textlinks und vieles mehr. <strong>VORSICHT:</strong> Das Einrichten von weiteren Sponsornetzwerken ist nicht leicht, daf&uuml;r aber sehr flexibel! Sollte ein Netzwerk fehlen, so melden Sie dies bitte <a href="http://forum.mxchange.org" target="_blank" title="Direktlink zum Forum">im Forum</a>!',4);
144                 addAdminMenuSql('network','config_network','API-Daten','Stellen Sie Ihre Affiliate- Webseiten-Id und API-Passwort ein. Diese erhalten Sie zu &uuml;ber 99% aus dem jeweiligen Zugangsbereich des Anbieters. Sollten Sie bei einem Netzwerk noch nicht angemeldet sein, verwenden Sie bitte meinen Referal-Link.',1);
145                 break;
146
147         case 'remove': // Do stuff when removing extension
148                 // SQL commands to run
149                 addExtensionSql("DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_network_data`");
150                 addExtensionSql("DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_network_types`");
151                 addExtensionSql("DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_network_type_errors`");
152                 addExtensionSql("DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_network_provider_types`");
153                 addExtensionSql("DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_network_config_data`");
154
155                 // Admin menu
156                 addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE `action`='network'");
157                 break;
158
159         case 'activate': // Do stuff when admin activates this extension
160                 // SQL commands to run
161                 break;
162
163         case 'deactivate': // Do stuff when admin deactivates this extension
164                 // SQL commands to run
165                 break;
166
167         case 'update': // Update an extension
168                 switch (getCurrentExtensionVersion()) {
169                         case '0.0.1': // SQL queries for v0.0.1
170                                 addExtensionSql('');
171
172                                 // Update notes (these will be set as task text!)
173                                 setExtensionUpdateNotes('');
174                                 break;
175                 } // END - switch
176                 break;
177
178         case 'modify': // When the extension got modified
179                 break;
180
181         case 'test': // For testing purposes. For details see file inc/modules/admin/what-extensions.php, arround line 305.
182                 break;
183
184         case 'init': // Do stuff when extension is initialized
185                 break;
186
187         default: // Unknown extension mode
188                 DEBUG_LOG(__FILE__, __LINE__, sprintf("Unknown extension mode %s detected.", getExtensionMode()));
189                 break;
190 } // END - switch
191
192 // [EOF]
193 ?>