First batch of removal of the headers needed for revision-functions.php
[mailer.git] / contrib / ideas / ext-shop.php
1 <?php
2 /************************************************************************
3  * Mailer-Project 0.2.1-FINAL                         Start: 06/04/2004 *
4  * ==========================                   Last change: 08/08/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : ext-shop.php                                     *
8  * -------------------------------------------------------------------- *
9  * Short description : Shop system with referal and reseller programs   *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Shop-System mit Referal- und Reseller-Programmen *
12  * -------------------------------------------------------------------- *
13  *                                                                      *
14  * -------------------------------------------------------------------- *
15  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
16  * Copyright (c) 2009 - 2011 by Mailer Developer Team                   *
17  * For more information visit: http://www.mxchange.org                  *
18  *                                                                      *
19  * This program is free software; you can redistribute it and/or modify *
20  * it under the terms of the GNU General Public License as published by *
21  * the Free Software Foundation; either version 2 of the License, or    *
22  * (at your option) any later version.                                  *
23  *                                                                      *
24  * This program is distributed in the hope that it will be useful,      *
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
27  * GNU General Public License for more details.                         *
28  *                                                                      *
29  * You should have received a copy of the GNU General Public License    *
30  * along with this program; if not, write to the Free Software          *
31  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
32  * MA  02110-1301  USA                                                  *
33  ************************************************************************/
34
35 // Some security stuff...
36 if (!defined('__SECURITY')) {
37         exit();
38 } // END - if
39
40 // Version number
41 setThisExtensionVersion('0.0.0');
42
43 // Version history array (add more with , '0.1' and so on)
44 setExtensionVersionHistory(array('0.0.0'));
45
46 // This extension is in development (non-productive)
47 enableExtensionProductive(false);
48
49 switch (getExtensionMode()) {
50         case 'register': // Do stuff when installtion is running
51                 // Create tables
52                 addDropTableSql('shop_config');
53                 addCreateTableSql('shop_config', "
54 `config` TINYINT(1) UNSIGNED NOT NULL AUTO_INCREMENT,
55 `allow_item_history` ENUM('Y','N') NOT NULL DEFAULT 'Y',
56 `allow_item_gallery` ENUM('Y','N') NOT NULL DEFAULT 'Y',
57 `allow_votes` ENUM('Y','N') NOT NULL DEFAULT 'Y',
58 `allow_vote_comments` ENUM('Y','N') NOT NULL DEFAULT 'Y',
59 `allow_save_search` ENUM('Y','N') NOT NULL DEFAULT 'Y',
60 `allow_points_system` ENUM('Y','N') NOT NULL DEFAULT 'Y',
61 `enable_reseller` ENUM('Y','N') NOT NULL DEFAULT 'Y',
62 `enable_search` ENUM('Y','N') NOT NULL DEFAULT 'Y',
63 `enable_member_preview` ENUM('Y','N') NOT NULL DEFAULT 'Y',
64 `shop_title` VARCHAR(255) NOT NULL DEFAULT '{?MAIN_TITLE?} Shop',
65 `points_ref` BIGINT(20) UNSIGNED NOT NULL DEFAULT '100',
66 `num_preview_guest` TINYINT(4) UNSIGNED NOT NULL DEFAULT '3',
67 `num_preview_member` TINYINT(4) UNSIGNED NOT NULL DEFAULT '3',
68 `show_links_num` ENUM('Y','N') NOT NULL DEFAULT 'Y',
69 PRIMARY KEY (`config`)",
70                         'Shop configuration data');
71
72                 addExtensionSql("INSERT INTO {?_MYSQL_PREFIX?}_shop_config (`config`) VALUES (0)");
73
74                 addDropTableSql('shop_basket');
75                 addCreateTableSql('shop_basket', "
76 `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
77 `item_id` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
78 `customer_id` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
79 `guest_session` VARCHAR(32) NOT NULL DEFAULT '',
80 `amount` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
81 INDEX (`item_id`),
82 INDEX (`customer_id`),
83 PRIMARY KEY (`id`)",
84                         'Shopping baskets');
85
86                 addDropTableSql('shop_cats');
87                 addCreateTableSql('shop_cats', "
88 `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
89 `parent_id` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
90 `active` ENUM('Y','N') NOT NULL DEFAULT 'N',
91 `title` VARCHAR(255) NOT NULL DEFAULT '',
92 `short_descr` MEDIUMTEXT,
93 `long_descr` LONGTEXT,
94 `cat_icon` VARCHAR(255),
95 `counter` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
96 `show_links_num` ENUM('Y','N') NOT NULL DEFAULT 'Y',
97 INDEX (`parent_id`),
98 PRIMARY KEY (`id`)",
99                         'Shopping categories');
100
101                 addDropTableSql('shop_items');
102                 addCreateTableSql('shop_items', "
103 `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
104 `catid` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
105 `required_by` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
106 `suggested_by` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
107 `active` ENUM('Y','N') NOT NULL DEFAULT 'N',
108 `title` VARCHAR(255) NOT NULL DEFAULT '',
109 `version_no` VARCHAR(255) NOT NULL DEFAULT '',
110 `licence` VARCHAR(255) NOT NULL DEFAULT '',
111 `default_price` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
112 `short_descr` MEDIUMTEXT,
113 `long_descr` LONGTEXT,
114 `item_icon` VARCHAR(255) NOT NULL DEFAULT 0,
115 `item_created` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00',
116 `item_amount` BIGINT(20) UNSIGNED NOT NULL DEFAULT '-1',
117 `admin_created` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
118 `admin_unlock` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
119 `tax_type` VARCHAR(255) NOT NULL DEFAULT '',
120 `tax_rate` INT(3) UNSIGNED NOT NULL DEFAULT 0,
121 `counter` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
122 `point_costs` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
123 `point_earned` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
124 INDEX (`suggested_by`),
125 INDEX (`required_by`),
126 INDEX (`admin_unlock`),
127 INDEX (`admin_created`),
128 INDEX (`default_price`),
129 INDEX (`catid`),
130 PRIMARY KEY (`id`)",
131                         'Shop items');
132
133                 addDropTableSql('shop_item_gallery');
134                 addCreateTableSql('shop_item_gallery', "
135 `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
136 `item_id` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
137 `item_pic_url` VARCHAR(255) NOT NULL DEFAULT '',
138 `item_pic_descr` MEDIUMTEXT,
139 `is_private` ENUM('Y','N') NOT NULL DEFAULT 'N',
140 `counter` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
141 INDEX (`item_id`),
142 PRIMARY KEY (`id`)",
143                         'Optional item gallery');
144
145                 addDropTableSql('shop_item_votes');
146                 addCreateTableSql('shop_item_votes', "
147 `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
148 `item_id` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
149 `vote_value` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
150 INDEX (`item_id`),
151 PRIMARY KEY (`id`)",
152                         'Votings on the items');
153
154                 addDropTableSql('shop_customers');
155                 addCreateTableSql('shop_customers', "
156 `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
157 `reseller_id` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
158 `salut` ENUM('M','F') NOT NULL DEFAULT 'M',
159 `company` VARCHAR(255) NOT NULL DEFAULT '',
160 `surname` VARCHAR(255) NOT NULL DEFAULT '',
161 `family` VARCHAR(255) NOT NULL DEFAULT '',
162 `street_nr` VARCHAR(255) NOT NULL DEFAULT '',
163 `street_nr2` VARCHAR(255) NOT NULL DEFAULT '',
164 `zip` VARCHAR(7) NOT NULL DEFAULT '',
165 `city` VARCHAR(255) NOT NULL DEFAULT '',
166 `country` VARCHAR(2) NOT NULL DEFAULT 'DE',
167 `email` VARCHAR(255) NOT NULL DEFAULT '',
168 `phone` VARCHAR(255) NOT NULL DEFAULT '',
169 `fax` VARCHAR(255) NOT NULL DEFAULT '',
170 `b_surname` VARCHAR(255) NOT NULL DEFAULT '',
171 `b_family` VARCHAR(255) NOT NULL DEFAULT '',
172 `b_street_nr` VARCHAR(255) NOT NULL DEFAULT '',
173 `b_street_nr2` VARCHAR(255) NOT NULL DEFAULT '',
174 `b_zip` VARCHAR(7) NOT NULL DEFAULT '',
175 `b_city` VARCHAR(255) NOT NULL DEFAULT '',
176 `b_country` VARCHAR(2) NOT NULL DEFAULT 'DE',
177 `b_email` VARCHAR(255) NOT NULL DEFAULT '',
178 `b_phone` VARCHAR(255) NOT NULL DEFAULT '',
179 `b_fax` VARCHAR(255) NOT NULL DEFAULT '',
180 `joined` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00',
181 `updated` TIMESTAMP NULL DEFAULT NULL,
182 `status` ENUM('UNCONFIRMED','CONFIRMED','LOCKED') NOT NULL DEFAULT 'UNCONFIRMED',
183 `unlock_key` VARCHAR(255) NULL NULL,
184 `points_amount` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
185 INDEX (`reseller_id`),
186 UNIQUE KEY (`unlock_key`),
187 PRIMARY KEY (`id`)",
188                         'Shop customer data');
189
190                 addDropTableSql('shop_resellers');
191                 addCreateTableSql('shop_resellers', "
192 `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
193 `reseller_id` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
194 `salut` ENUM('M','F') NOT NULL DEFAULT 'M',
195 `company` VARCHAR(255) NOT NULL DEFAULT '',
196 `surname` VARCHAR(255) NOT NULL DEFAULT '',
197 `family` VARCHAR(255) NOT NULL DEFAULT '',
198 `street_nr` VARCHAR(255) NOT NULL DEFAULT '',
199 `street_nr2` VARCHAR(255) NOT NULL DEFAULT '',
200 `zip` VARCHAR(7) NOT NULL DEFAULT '',
201 `city` VARCHAR(255) NOT NULL DEFAULT '',
202 `country` VARCHAR(2) NOT NULL DEFAULT 'DE',
203 `email` VARCHAR(255) NOT NULL DEFAULT '',
204 `phone` VARCHAR(255) NOT NULL DEFAULT '',
205 `fax` VARCHAR(255) NOT NULL DEFAULT '',
206 `joined` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00',
207 `updated` TIMESTAMP NULL DEFAULT NULL,
208 `status` ENUM('UNCONFIRMED','CONFIRMED','LOCKED') NOT NULL DEFAULT 'UNCONFIRMED',
209 `unlock_key` VARCHAR(255) NULL NULL,
210 INDEX (`reseller_id`),
211 UNIQUE KEY (`unlock_key`),
212 PRIMARY KEY (`id`)",
213                         'Shop reseller data');
214
215                 addDropTableSql('shop_saved_searches');
216                 addCreateTableSql('shop_saved_searches', "
217 `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
218 `customer_id` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
219 `reseller_id` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
220 `timestamp` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00',
221 `catid` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
222 `search_words` VARCHAR(255) NOT NULL DEFAULT '',
223 INDEX (`catid`),
224 INDEX (`customer_id`),
225 INDEX (`reseller_id`),
226 PRIMARY KEY (`id`)",
227                         'Saved shop searched for customers and resellers');
228
229                 addDropTableSql('shop_price_types');
230                 addCreateTableSql('shop_price_types', "
231 `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
232 `price_type` VARCHAR(255) NOT NULL DEFAULT '',
233 `rate` FLOAT (20,5) NOT NULL DEFAULT '0.0000',
234 PRIMARY KEY (`id`)",
235                         'Shop prices');
236
237                 // Add admin menu system
238                 addAdminMenuSql('shop', NULL, 'Shop-Verwaltung', 'Stellen Sie hier alles am Shop-System ein. Hier k&ouml;nnen Sie auch die Kunden verwalten.', '6');
239                 addAdminMenuSql('shop', 'config_shop', 'Shop-Einstellungen', 'Allgemeine Einstellungen zum Shop.', 1);
240                 addAdminMenuSql('shop', 'add_shop_cat', 'Warenkategorien hinzuf&uuml;gen', 'Neue Warenkategorien hinzuf&uuml;gen.', 2);
241                 addAdminMenuSql('shop', 'edit_shop_cat', 'Warenkategorien &auml;ndern', 'Bestehende Warenkategorien &auml;ndern.', 3);
242                 addAdminMenuSql('shop', 'add_shop_items', 'Neue Ware hinzuf&uuml;gen', 'Neue Waren in die Warenkategorien einsortieren.', 5);
243                 addAdminMenuSql('shop', 'edit_shop_items', 'Ware &auml;ndern', 'Bestehende Ware &auml;ndern oder verschieben.', 6);
244                 addAdminMenuSql('shop', 'add_shop_ptypes', 'Buchungspaket hinzuf&uuml;gen', 'F&uuml;gen Sie eine Bezahlungalternative zum direkten Geld hinzu. Beispiele: Klammlose, MyPoints, Wedis, usw.', 8);
245                 addAdminMenuSql('shop', 'edit_shop_ptypes', 'Buchungspaket &auml;ndern', 'Bestehende Buchungspakete &auml;ndern.', 9);
246                 addAdminMenuSql('shop', 'import_shop_ptyes', 'Import Buchungspakete', 'Importieren Sie bei installierter payout-Erweiterung die bestehenden Auszahlungsarten als Buchungspakete! Banner-Auszahlungsarten werden dabei ignoriert.', 11);
247
248                 // Add guest and member menu entries (just redirects)
249                 addGuestMenuSql('main', 'shop', 'Zum Shop...', 'Y', 'Y', 7);
250                 addMemberMenuSql('main', 'shop', 'Zum Shop...', 'Y', 'Y', 7);
251                 break;
252
253         case 'remove': // Do stuff when removing extension
254                 // SQL commands to run
255                 addDropTableSql('shop_basket');
256                 addDropTableSql('shop_config');
257                 addDropTableSql('shop_cats');
258                 addDropTableSql('shop_items');
259                 addDropTableSql('shop_item_gallery');
260                 addDropTableSql('shop_item_votes');
261                 addDropTableSql('shop_saved_searches');
262                 addDropTableSql('shop_customers');
263                 addDropTableSql('shop_resellers');
264                 addDropTableSql('shop_price_types');
265
266                 // Admin / guest / member menu
267                 addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE `action`='shop' LIMIT 12");
268                 addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_guest_menu` WHERE `what`='shop' LIMIT 1");
269                 addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE `what`='shop' LIMIT 1");
270                 break;
271
272         case 'activate': // Do stuff when admin activates this extension
273                 // SQL commands to run
274                 addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_guest_menu` SET `visible`='Y', `locked`='N' WHERE `what`='shop' LIMIT 1");
275                 addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_member_menu` SET `visible`='Y', `locked`='N' WHERE `what`='shop' LIMIT 1");
276                 break;
277
278         case 'deactivate': // Do stuff when admin deactivates this extension
279                 // SQL commands to run
280                 addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_guest_menu` SET `visible`='Y', `locked`='Y' WHERE `what`='shop' LIMIT 1");
281                 addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_member_menu` SET `visible`='Y', `locked`='Y' WHERE `what`='shop' LIMIT 1");
282                 break;
283
284         case 'update': // Update an extension
285                 switch (getCurrentExtensionVersion()) {
286                         case '0.0.1': // SQL queries for v0.0.1
287                                 addExtensionSql('');
288
289                                 // Update notes (these will be set as task text!)
290                                 setExtensionUpdateNotes('');
291                                 break;
292                 } // END - switch
293                 break;
294
295         case 'modify': // When the extension got modified
296                 break;
297
298         case 'test': // For testing purposes
299                 break;
300
301         case 'init': // Do stuff when extension is initialized
302                 break;
303
304         default: // Unknown extension mode
305                 logDebugMessage(__FILE__, __LINE__, sprintf("Unknown extension mode %s in extension %s detected.", getExtensionMode(), getCurrentExtensionName()));
306                 break;
307 } // END - switch
308
309 // [EOF]
310 ?>