-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupgrade.php
469 lines (434 loc) · 19.4 KB
/
upgrade.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
<?php
/**
* kitEvent
*
* @author Team phpManufaktur <[email protected]>
* @link https://addons.phpmanufaktur.de/kitEvent
* @copyright 2011 Ralf Hertsch <[email protected]>
* @license MIT License (MIT) http://www.opensource.org/licenses/MIT
*/
// include class.secure.php to protect this file and the whole CMS!
if (defined('WB_PATH')) {
if (defined('LEPTON_VERSION')) include (WB_PATH . '/framework/class.secure.php');
}
else {
$oneback = "../";
$root = $oneback;
$level = 1;
while (($level < 10) && (!file_exists($root . '/framework/class.secure.php'))) {
$root .= $oneback;
$level += 1;
}
if (file_exists($root . '/framework/class.secure.php')) {
include ($root . '/framework/class.secure.php');
}
else {
trigger_error(sprintf("[ <b>%s</b> ] Can't include class.secure.php!", $_SERVER['SCRIPT_NAME']), E_USER_ERROR);
}
}
// end include class.secure.php
// wb2lepton compatibility
if (!defined('LEPTON_PATH'))
require_once WB_PATH . '/modules/' . basename(dirname(__FILE__)) . '/wb2lepton.php';
// use LEPTON 2.x I18n for access to language files
if (!class_exists('LEPTON_Helper_I18n'))
require_once LEPTON_PATH.'/modules/manufaktur_config/framework/LEPTON/Helper/I18n.php';
global $I18n;
if (!is_object($I18n))
$I18n = new LEPTON_Helper_I18n();
if (file_exists(LEPTON_PATH.'/modules/'.basename(dirname(__FILE__)).'/languages/'.LANGUAGE.'.php')) {
$I18n->addFile(LANGUAGE.'.php', LEPTON_PATH.'/modules/'.basename(dirname(__FILE__)).'/languages/');
}
// load language depending configuration file
if (file_exists(LEPTON_PATH.'/modules/manufaktur_config/languages/'.LANGUAGE.'.cfg.php'))
require_once LEPTON_PATH.'/modules/manufaktur_config/languages/'.LANGUAGE.'.cfg.php';
else
require_once LEPTON_PATH.'/modules/manufaktur_config/languages/EN.cfg.php';
require_once WB_PATH.'/modules/manufaktur_config/library.php';
require_once WB_PATH.'/modules/kit/class.interface.php';
global $admin;
global $database;
global $kitContactInterface;
$error = '';
/**
* Check if the specified $field in the $table exists
*
* @param string $table
* @param string $field
* @return boolean
*/
function fieldExists($table, $field) {
global $database;
global $admin;
if (null === ($query = $database->query("DESCRIBE `".TABLE_PREFIX."$table`")))
$admin->print_error($database->get_error());
while (false !== ($data = $query->fetchRow(MYSQL_ASSOC)))
if ($data['Field'] == $field) return true;
return false;
} // sqlFieldExists()
/**
* Iterate directory tree very efficient
* Function postet from [email protected] at
* http://www.php.net/manual/de/function.scandir.php
*
* @param STR $dir
* @return ARRAY - directoryTree
*/
function directoryTree($dir) {
if (substr($dir,-1) == "/") $dir = substr($dir,0,-1);
$path = array();
$stack = array();
$stack[] = $dir;
while ($stack) {
$thisdir = array_pop($stack);
if (false !== ($dircont = scandir($thisdir))) {
$i=0;
while (isset($dircont[$i])) {
if ($dircont[$i] !== '.' && $dircont[$i] !== '..') {
$current_file = "{$thisdir}/{$dircont[$i]}";
if (is_file($current_file)) {
$path[] = "{$thisdir}/{$dircont[$i]}";
}
elseif (is_dir($current_file)) {
$stack[] = $current_file;
}
}
$i++;
}
}
}
return $path;
} // directoryTree()
function getSubDirectories($dir) {
if (substr($dir,-1) == "/") $dir = substr($dir,0,-1);
$path = array();
$stack = array();
$stack[] = $dir;
while ($stack) {
$thisdir = array_pop($stack);
if (false !== ($dircont = scandir($thisdir))) {
$i=0;
while (isset($dircont[$i])) {
if ($dircont[$i] !== '.' && $dircont[$i] !== '..') {
$current_file = "{$thisdir}/{$dircont[$i]}";
if (is_dir($current_file)) {
$path[] = "{$thisdir}/{$dircont[$i]}";
$stack[] = $current_file;
}
}
$i++;
}
}
}
return $path;
} // getSubDirectories()
function __move_recursive($dirsource, $dirdest) {
if (is_dir($dirsource)) {
$dir_handle = opendir($dirsource);
}
while (false !== ($file = readdir($dir_handle))) {
if ($file != "." && $file != "..") {
if (!is_dir($dirsource."/".$file)) {
copy($dirsource."/".$file, $dirdest.'/'.$file);
unlink($dirsource.'/'.$file);
}
else {
if (!is_dir($dirdest."/".$file)) {
make_dir($dirdest."/".$file);
__move_recursive($dirsource."/".$file, $dirdest.'/'.$file);
}
rm_full_dir($dirsource.'/'.$file);
}
}
}
closedir($dir_handle);
return true;
}
// Release 0.28
if (!fieldExists('mod_kit_event_group', 'group_perma_pattern')) {
$database->query("ALTER TABLE `".TABLE_PREFIX."mod_kit_Event_group` ADD `group_perma_pattern` VARCHAR(128) NOT NULL DEFAULT '' AFTER `group_name`");
if ($database->is_error())
$error .= sprintf("<p>[UPGRADE] %s</p>", $database->get_error());
}
if (!fieldExists('mod_kit_event_group', 'group_redirect_page')) {
$database->query("ALTER TABLE `".TABLE_PREFIX."mod_kit_Event_group` ADD `group_redirect_page` VARCHAR(255) NOT NULL DEFAULT '' AFTER `group_perma_pattern`");
if ($database->is_error())
$error .= sprintf("<p>[UPGRADE] %s</p>", $database->get_error());
}
if (!fieldExists('mod_kit_event', 'evt_perma_link')) {
$database->query("ALTER TABLE `".TABLE_PREFIX."mod_kit_event` ADD `evt_perma_link` VARCHAR(128) NOT NULL DEFAULT '' AFTER `evt_deadline`");
if ($database->is_error())
$error .= sprintf("<p>[UPGRADE] %s</p>", $database->get_error());
}
if (!fieldExists('mod_kit_event', 'evt_ical_file')) {
$database->query("ALTER TABLE `".TABLE_PREFIX."mod_kit_event` ADD `evt_ical_file` VARCHAR(32) NOT NULL DEFAULT '' AFTER `evt_perma_link`");
if ($database->is_error())
$error .= sprintf("<p>[UPGRADE] %s</p>", $database->get_error());
}
if (!fieldExists('mod_kit_event', 'evt_qrcode_image')) {
$database->query("ALTER TABLE `".TABLE_PREFIX."mod_kit_event` ADD `evt_qrcode_image` VARCHAR(32) NOT NULL DEFAULT '' AFTER `evt_ical_file`");
if ($database->is_error())
$error .= sprintf("<p>[UPGRADE] %s</p>", $database->get_error());
}
// Release 0.33
if (!fieldExists('mod_kit_event_item', 'item_free_1')) {
$database->query("ALTER TABLE `".TABLE_PREFIX."mod_kit_event_item` ADD `item_free_1` TEXT NOT NULL AFTER `item_costs`");
if ($database->is_error())
$error .= sprintf("<p>[UPGRADE] %s</p>", $database->get_error());
$database->query("ALTER TABLE `".TABLE_PREFIX."mod_kit_event_item` ADD `item_free_2` TEXT NOT NULL AFTER `item_free_1`");
if ($database->is_error())
$error .= sprintf("<p>[UPGRADE] %s</p>", $database->get_error());
$database->query("ALTER TABLE `".TABLE_PREFIX."mod_kit_event_item` ADD `item_free_3` TEXT NOT NULL AFTER `item_free_2`");
if ($database->is_error())
$error .= sprintf("<p>[UPGRADE] %s</p>", $database->get_error());
$database->query("ALTER TABLE `".TABLE_PREFIX."mod_kit_event_item` ADD `item_free_4` TEXT NOT NULL AFTER `item_free_3`");
if ($database->is_error())
$error .= sprintf("<p>[UPGRADE] %s</p>", $database->get_error());
$database->query("ALTER TABLE `".TABLE_PREFIX."mod_kit_event_item` ADD `item_free_5` TEXT NOT NULL AFTER `item_free_4`");
if ($database->is_error())
$error .= sprintf("<p>[UPGRADE] %s</p>", $database->get_error());
}
// Release 0.39
if (!fieldExists('mod_kit_event_order', 'kit_id')) {
$database->query("ALTER TABLE `".TABLE_PREFIX."mod_kit_event_order` ADD `kit_id` INT(11) NOT NULL DEFAULT '-1' AFTER `evt_id`");
if ($database->is_error())
$error .= sprintf("<p>[UPGRADE] %s</p>", $database->get_error());
}
if (fieldExists('mod_kit_event_order', 'ord_email')) {
// the ord_ contact fields exists und must be moved to KIT
$SQL = "SELECT * FROM `".TABLE_PREFIX."mod_kit_event_order` WHERE `ord_email`!=''";
if (null === ($query = $database->query($SQL))) {
$error .= sprintf("<p>[UPGRADE] %s</p>", $database->get_error());
}
else {
// move contact data to KIT
$distribution = '';
if (!$kitContactInterface->existsCategory(kitContactInterface::category_type_distribution, 'kitEvent')) {
if ($kitContactInterface->addCategory(kitContactInterface::category_type_distribution, 'distKITevent', 'kitEvent'))
$distribution = 'kitEvent';
else
$error .= sprintf("<p>[UPGRADE] %s</p>", $kitContactInterface->getError());
}
while (false !== ($order = $query->fetchRow(MYSQL_ASSOC))) {
$contact = array(
'kit_first_name' => $order['ord_first_name'],
'kit_last_name' => $order['ord_last_name'],
'kit_title' => $order['ord_title'],
'kit_company' => $order['ord_company'],
'kit_street' => $order['ord_street'],
'kit_zip' => $order['ord_zip'],
'kit_email' => $order['ord_email'],
'kit_phone' => $order['ord_phone'],
'kit_distribution' => 'distKITevent'
);
$registry = array();
$kit_id = -1;
$status = null;
if ($kitContactInterface->isEMailRegistered($contact['kit_email'], $kit_id, $status)) {
// this contact already exists
$distribution = array('distKITevent');
$categories = array();
// get existing distributions
$kitContactInterface->getCategories($kit_id, $categories, true);
foreach ($categories as $category) {
if (($category['type'] == 'kit_distribution') && !in_array($category['value'], $distribution))
$distribution[] = $category['value'];
}
$contact['kit_distribution'] = implode(',', $distribution);
if (!$kitContactInterface->updateContact($kit_id, $contact)) {
$error .= sprintf("<p>[UPGRADE] %s</p>", $kitContactInterface->getError());
continue;
}
}
else {
// we add a new contact to KIT
if (!$kitContactInterface->addContact($contact, $kit_id, $registry)) {
$error .= sprintf("<p>[UPGRADE] %s</p>", $kitContactInterface->getError());
continue;
}
}
$dt = strtotime($order['ord_confirm']);
if (checkdate(date('n', $dt), date('j', $dt), date('Y', $dt))) {
// add a notice and a link to the contact
$note = $I18n->translate('[kitEvent] The contact has <a href="{{ link }}">registered for a event</a>.',
array('link' => ADMIN_URL.'/admintools/tool.php?tool=kit_event&kea=msgd&ord_id='.$order['ord_id']));
$kitContactInterface->addNotice($kit_id, $note);
}
// add the KIT_ID to the order record
$SQL = "UPDATE `".TABLE_PREFIX."mod_kit_event_order` SET `kit_id`='$kit_id' WHERE `ord_id`='{$order['ord_id']}'";
if (null === $database->query($SQL)) {
$error .= sprintf("<p>[UPGRADE] %s</p>", $database->get_error());
continue;
}
}
// now we can delete the ord_ contact fields
if (null === $database->query("ALTER TABLE `".TABLE_PREFIX."mod_kit_event_order` DROP COLUMN `ord_first_name`"))
$error .= sprintf("<p>[UPGRADE] %s</p>", $database->get_error());
if (null === $database->query("ALTER TABLE `".TABLE_PREFIX."mod_kit_event_order` DROP COLUMN `ord_last_name`"))
$error .= sprintf("<p>[UPGRADE] %s</p>", $database->get_error());
if (null === $database->query("ALTER TABLE `".TABLE_PREFIX."mod_kit_event_order` DROP COLUMN `ord_title`"))
$error .= sprintf("<p>[UPGRADE] %s</p>", $database->get_error());
if (null === $database->query("ALTER TABLE `".TABLE_PREFIX."mod_kit_event_order` DROP COLUMN `ord_company`"))
$error .= sprintf("<p>[UPGRADE] %s</p>", $database->get_error());
if (null === $database->query("ALTER TABLE `".TABLE_PREFIX."mod_kit_event_order` DROP COLUMN `ord_street`"))
$error .= sprintf("<p>[UPGRADE] %s</p>", $database->get_error());
if (null === $database->query("ALTER TABLE `".TABLE_PREFIX."mod_kit_event_order` DROP COLUMN `ord_zip`"))
$error .= sprintf("<p>[UPGRADE] %s</p>", $database->get_error());
if (null === $database->query("ALTER TABLE `".TABLE_PREFIX."mod_kit_event_order` DROP COLUMN `ord_city`"))
$error .= sprintf("<p>[UPGRADE] %s</p>", $database->get_error());
if (null === $database->query("ALTER TABLE `".TABLE_PREFIX."mod_kit_event_order` DROP COLUMN `ord_email`"))
$error .= sprintf("<p>[UPGRADE] %s</p>", $database->get_error());
if (null === $database->query("ALTER TABLE `".TABLE_PREFIX."mod_kit_event_order` DROP COLUMN `ord_phone`"))
$error .= sprintf("<p>[UPGRADE] %s</p>", $database->get_error());
}
} // if fieldExists()
if (!fieldExists('mod_kit_event_group', 'kit_distribution_participant')) {
$database->query("ALTER TABLE `".TABLE_PREFIX."mod_kit_event_group` ADD `kit_distribution_participant` VARCHAR(255) NOT NULL DEFAULT '' AFTER `group_desc`");
if ($database->is_error())
$error .= sprintf("<p>[UPGRADE] %s</p>", $database->get_error());
}
if (!fieldExists('mod_kit_event_group', 'kit_distribution_organizer')) {
$database->query("ALTER TABLE `".TABLE_PREFIX."mod_kit_event_group` ADD `kit_distribution_organizer` VARCHAR(255) NOT NULL DEFAULT '' AFTER `kit_distribution_participant`");
if ($database->is_error())
$error .= sprintf("<p>[UPGRADE] %s</p>", $database->get_error());
}
if (!fieldExists('mod_kit_event_group', 'kit_distribution_location')) {
$database->query("ALTER TABLE `".TABLE_PREFIX."mod_kit_event_group` ADD `kit_distribution_location` VARCHAR(255) NOT NULL DEFAULT '' AFTER `kit_distribution_organizer`");
if ($database->is_error())
$error .= sprintf("<p>[UPGRADE] %s</p>", $database->get_error());
}
if (!fieldExists('mod_kit_event', 'organizer_id')) {
$database->query("ALTER TABLE `".TABLE_PREFIX."mod_kit_event` ADD `organizer_id` INT(11) NOT NULL DEFAULT '-1' AFTER `item_id`");
if ($database->is_error())
$error .= sprintf("<p>[UPGRADE] %s</p>", $database->get_error());
}
if (!fieldExists('mod_kit_event', 'location_id')) {
$database->query("ALTER TABLE `".TABLE_PREFIX."mod_kit_event` ADD `location_id` INT(11) NOT NULL DEFAULT '-1' AFTER `organizer_id`");
if ($database->is_error())
$error .= sprintf("<p>[UPGRADE] %s</p>", $database->get_error());
}
$database->query("ALTER TABLE `".TABLE_PREFIX."mod_kit_event_item` MODIFY `item_desc_link` TEXT NOT NULL");
if ($database->is_error())
$error .= sprintf("<p>[UPGRADE] %s</p>", $database->get_error());
if (!fieldExists('mod_kit_event_item', 'item_location_link')) {
$database->query("ALTER TABLE `".TABLE_PREFIX."mod_kit_event_item` ADD `item_location_link` TEXT NOT NULL AFTER `item_location`");
if ($database->is_error())
$error .= sprintf("<p>[UPGRADE] %s</p>", $database->get_error());
}
if (!fieldExists('mod_kit_event_item', 'item_category')) {
$database->query("ALTER TABLE `".TABLE_PREFIX."mod_kit_event_item` ADD `item_category` VARCHAR(255) NOT NULL DEFAULT '' AFTER `item_location_link`");
if ($database->is_error())
$error .= sprintf("<p>[UPGRADE] %s</p>", $database->get_error());
}
// END Release 0.39
if (file_exists(WB_PATH.'/modules/kit_event/htt')) {
// check for individual presets and move them to the new template directory
$directories = getSubDirectories(WB_PATH.'/modules/kit_event/htt');
foreach ($directories as $directory) {
$test = substr($directory, strlen(WB_PATH.'/modules/kit_event/htt/'));
if (false !== strpos($test, DIRECTORY_SEPARATOR)) continue;
if (intval($test) >= 100) {
// move this individual preset to the new directory
if (__move_recursive($directory, WB_PATH."/modules/kit_event/templates/frontend/presets/$test")) {
// now we have to rename the .htt extensions to .dwoo
$files = directoryTree(WB_PATH."/modules/kit_event/templates/frontend/presets/$test");
foreach ($files as $file) {
if (false !== strpos($file, '.htt')) {
$rename = str_replace('.htt', '.dwoo', $file);
rename($file, $rename);
}
}
}
}
}
rm_full_dir(WB_PATH.'/modules/kit_event/htt');
}
// delete no longer needed files
@unlink(WB_PATH.'/modules/kit_event/class.droplets.php');
@unlink(WB_PATH.'/modules/kit_event/frontend.css');
@unlink(WB_PATH.'/modules/kit_event/class.editor.php');
@unlink(WB_PATH.'/modules/kit_event/backend_body.js');
rm_full_dir(WB_PATH.'/modules/kit_event/include/jquery');
@unlink(WB_PATH.'/modules/kit_event/templates/backend/DE/config.dwoo');
@unlink(WB_PATH.'/modules/kit_event/templates/backend/DE/event.group.dwoo');
@unlink(WB_PATH.'/modules/kit_event/class.event.php');
// install or upgrade droplets
if (file_exists(WB_PATH.'/modules/droplets/functions.inc.php')) {
include_once(WB_PATH.'/modules/droplets/functions.inc.php');
}
if (!function_exists('wb_unpack_and_import')) {
function wb_unpack_and_import($temp_file, $temp_unzip) {
global $admin, $database;
// Include the PclZip class file
require_once (WB_PATH . '/include/pclzip/pclzip.lib.php');
$errors = array();
$count = 0;
$archive = new PclZip($temp_file);
$list = $archive->extract(PCLZIP_OPT_PATH, $temp_unzip);
// now, open all *.php files and search for the header;
// an exported droplet starts with "//:"
if (false !== ($dh = opendir($temp_unzip))) {
while (false !== ($file = readdir($dh))) {
if ($file != "." && $file != "..") {
if (preg_match('/^(.*)\.php$/i', $file, $name_match)) {
// Name of the Droplet = Filename
$name = $name_match[1];
// Slurp file contents
$lines = file($temp_unzip . '/' . $file);
// First line: Description
if (preg_match('#^//\:(.*)$#', $lines[0], $match)) {
$description = $match[1];
}
// Second line: Usage instructions
if (preg_match('#^//\:(.*)$#', $lines[1], $match)) {
$usage = addslashes($match[1]);
}
// Remaining: Droplet code
$code = implode('', array_slice($lines, 2));
// replace 'evil' chars in code
$tags = array(
'<?php',
'?>',
'<?'
);
$code = addslashes(str_replace($tags, '', $code));
// Already in the DB?
$stmt = 'INSERT';
$id = NULL;
$found = $database->get_one("SELECT * FROM " . TABLE_PREFIX . "mod_droplets WHERE name='$name'");
if ($found && $found > 0) {
$stmt = 'REPLACE';
$id = $found;
}
// execute
$result = $database->query("$stmt INTO " . TABLE_PREFIX . "mod_droplets VALUES('$id','$name','$code','$description','" . time() . "','" . $admin->get_user_id() . "',1,0,0,0,'$usage')");
if (!$database->is_error()) {
$count++;
$imports[$name] = 1;
}
else {
$errors[$name] = $database->get_error();
}
}
}
}
closedir($dh);
}
return array(
'count' => $count,
'errors' => $errors,
'imported' => $imports
);
} // function wb_unpack_and_import()
}
wb_unpack_and_import(WB_PATH.'/modules/kit_event/droplets/droplet_kit_event.zip', WB_PATH . '/temp/unzip/');
wb_unpack_and_import(WB_PATH.'/modules/kit_event/droplets/droplet_kit_monthly_calendar.zip', WB_PATH . '/temp/unzip/');
// initialize the configuration
$config = new manufakturConfig();
if (!$config->readXMLfile(WB_PATH.'/modules/'.basename(dirname(__FILE__)).'/config/kitEvent.xml', 'kit_event', false)) {
$error .= $config->getError();
}
// Prompt Errors
if (!empty($error)) {
$admin->print_error($error, 'javascript:history_back();');
}