-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclass.backend.php
1605 lines (1479 loc) · 61.3 KB
/
class.backend.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
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* syncData
*
* @author Ralf Hertsch ([email protected])
* @link http://phpmanufaktur.de
* @copyright 2011
* @license GNU GPL (http://www.gnu.org/licenses/gpl.html)
* @version $Id: class.backend.php 8 2011-08-19 01:26:33Z phpmanufaktur $
*
* FOR VERSION- AND RELEASE NOTES PLEASE LOOK AT INFO.TXT!
*/
// include LEPTON class.secure.php to protect this file and the whole CMS!
$class_secure = '../../framework/class.secure.php';
if (file_exists($class_secure)) {
include($class_secure);
}
else {
trigger_error(sprintf("[ <b>%s</b> ] Can't include LEPTON class.secure.php!", $_SERVER['SCRIPT_NAME']), E_USER_ERROR);
}
// include language file for syncData
if(!file_exists(WB_PATH .'/modules/'.basename(dirname(__FILE__)).'/languages/' .LANGUAGE .'.php')) {
require_once(WB_PATH .'/modules/'.basename(dirname(__FILE__)).'/languages/EN.php');
}
else {
require_once(WB_PATH .'/modules/'.basename(dirname(__FILE__)).'/languages/' .LANGUAGE .'.php');
}
if (file_exists(WB_PATH.'/modules/pclzip/pclzip.lib.php')) {
// LEPTON 1.x
require_once WB_PATH.'/modules/pclzip/pclzip.lib.php';
}
elseif (file_exists(WB_PATH.'/modules/lib_pclzip/pclzip.lib.php')) {
// LEPTON 2.x
require_once WB_PATH.'/modules/lib_pclzip/pclzip.lib.php';
}
elseif (file_exists(WB_PATH.'/include/pclzip/pclzip.lib.php')) {
// WebsiteBaker
require_once WB_PATH.'/include/pclzip/pclzip.lib.php';
}
else {
trigger_error(sprintf("[ <b>%s</b> ] Unable to find pclzip!", $_SERVER['SCRIPT_NAME']), E_USER_ERROR);
}
// set temporary directory for pclzip
if (!defined('PCLZIP_TEMPORARY_DIR')) define('PCLZIP_TEMPORARY_DIR', WB_PATH.'/temp/');
if (!class_exists('Dwoo')) {
// try to load regular Dwoo
if (file_exists(WB_PATH.'/modules/dwoo/include.php')) {
require_once WB_PATH.'/modules/dwoo/include.php';
}
else {
// load Dwoo from include directory
require_once WB_PATH.'/modules/'.basename(dirname(__FILE__)).'/include/dwoo/dwooAutoload.php';
}
}
$cache_path = WB_PATH.'/temp/cache';
if (!file_exists($cache_path)) mkdir($cache_path, 0777, true);
$compiled_path = WB_PATH.'/temp/compiled';
if (!file_exists($compiled_path)) mkdir($compiled_path, 0777, true);
global $parser;
if (!is_object($parser)) $parser = new Dwoo($compiled_path, $cache_path);
if (!class_exists('dbconnectle')) {
// try to load regular dbConnect_LE
if (file_exists(WB_PATH.'/modules/dbconnect_le/include.php')) {
require_once WB_PATH.'/modules/dbconnect_le/include.php';
}
else {
// load dbConnect_LE from include directory
require_once WB_PATH.'/modules/'.basename(dirname(__FILE__)).'/include/dbconnect_le/include.php';
}
}
if (!class_exists('kitToolsLibrary')) {
// try to load required kitTools
if (file_exists(WB_PATH.'/modules/kit_tools/class.tools.php')) {
require_once WB_PATH.'/modules/kit_tools/class.tools.php';
}
else {
// load embedded kitTools library
require_once WB_PATH.'/modules/'.basename(dirname(__FILE__)).'/class.tools.php';
}
}
global $kitTools;
if (!is_object($kitTools)) $kitTools = new kitToolsLibrary();
require_once WB_PATH.'/modules/'.basename(dirname(__FILE__)).'/class.syncdata.php';
require_once WB_PATH.'/framework/functions.php';
require_once WB_PATH.'/modules/'.basename(dirname(__FILE__)).'/class.interface.php';
class syncBackend {
const request_action = 'act';
const request_file_backup_start = 'bus';
const request_items = 'its';
const request_backup = 'bak';
const request_restore = 'rst';
const request_restore_continue = 'rstc';
const request_restore_process = 'rstp';
const request_restore_replace_url = 'rstru';
const request_restore_replace_prefix = 'rstrp';
const request_restore_type = 'rstt';
const action_about = 'abt';
const action_config = 'cfg';
const action_config_check = 'cfgc';
const action_default = 'def';
const action_backup = 'back';
const action_backup_start = 'baks';
const action_backup_start_new = 'baksn';
const action_backup_continue = 'bakc';
const action_process_backup = 'pb';
const action_restore = 'rst';
const action_restore_continue = 'rstc';
const action_restore_info = 'rsti';
const action_restore_start = 'rsts';
const action_update_continue = 'updc';
const action_update_start = 'upds';
private $tab_navigation_array = array(
self::action_backup => sync_tab_backup,
self::action_restore => sync_tab_restore,
self::action_config => sync_tab_cfg,
self::action_about => sync_tab_about
);
const add_max_rows = 5;
private $page_link = '';
private $img_url = '';
private $template_path = '';
private $error = '';
private $message = '';
private $temp_path = '';
private $max_execution_time = 30;
private $limit_execution_time = 25;
private $memory_limit = '256M';
private $next_file = '';
/**
* Constructor
*/
public function __construct() {
global $dbSyncDataCfg;
$this->page_link = ADMIN_URL.'/admintools/tool.php?tool=sync_data';
$this->template_path = WB_PATH . '/modules/' . basename(dirname(__FILE__)) . '/templates/' ;
$this->img_url = WB_URL. '/modules/'.basename(dirname(__FILE__)).'/images/';
date_default_timezone_set(sync_cfg_time_zone);
$this->temp_path = WB_PATH.'/temp/sync_data/';
if (!file_exists($this->temp_path)) mkdir($this->temp_path, 0755, true);
$this->memory_limit = $dbSyncDataCfg->getValue(dbSyncDataCfg::cfgMemoryLimit);
ini_set("memory_limit",$this->memory_limit);
$this->max_execution_time = $dbSyncDataCfg->getValue(dbSyncDataCfg::cfgMaxExecutionTime);
$this->limit_execution_time = $dbSyncDataCfg->getValue(dbSyncDataCfg::cfgLimitExecutionTime);
set_time_limit($this->max_execution_time);
} // __construct()
/**
* Set $this->error to $error
*
* @param STR $error
*/
public function setError($error) {
$debug = debug_backtrace();
$caller = next($debug);
$this->error = sprintf('[%s::%s - %s] %s', basename($caller['file']), $caller['function'], $caller['line'], $error);
} // setError()
/**
* Get Error from $this->error;
*
* @return STR $this->error
*/
public function getError() {
return $this->error;
} // getError()
/**
* Check if $this->error is empty
*
* @return BOOL
*/
public function isError() {
return (bool) !empty($this->error);
} // isError
/**
* Reset Error to empty String
*/
public function clearError() {
$this->error = '';
}
/** Set $this->message to $message
*
* @param STR $message
*/
public function setMessage($message) {
$this->message = $message;
} // setMessage()
/**
* Get Message from $this->message;
*
* @return STR $this->message
*/
public function getMessage() {
return $this->message;
} // getMessage()
/**
* Check if $this->message is empty
*
* @return BOOL
*/
public function isMessage() {
return (bool) !empty($this->message);
} // isMessage
/**
* Return Version of Module
*
* @return FLOAT
*/
public function getVersion() {
// read info.php into array
$info_text = file(WB_PATH.'/modules/'.basename(dirname(__FILE__)).'/info.php');
if ($info_text == false) {
return -1;
}
// walk through array
foreach ($info_text as $item) {
if (strpos($item, '$module_version') !== false) {
// split string $module_version
$value = explode('=', $item);
// return floatval
return floatval(preg_replace('([\'";,\(\)[:space:][:alpha:]])', '', $value[1]));
}
}
return -1;
} // getVersion()
/**
* Get the desired $template within the template path, fills in the
* $template_data and return the template output
*
* @param STR $template
* @param ARRAY $template_data
* @return STR|BOOL template or FALSE on error
*/
public function getTemplate($template, $template_data) {
global $parser;
$result = '';
try {
$result = $parser->get($this->template_path.$template, $template_data);
} catch (Exception $e) {
$this->setError(sprintf(sync_error_template_error, $template, $e->getMessage()));
return false;
}
return $result;
} // getTemplate()
/**
* Verhindert XSS Cross Site Scripting
*
* @param REFERENCE $_REQUEST Array
* @return $request
*/
public function xssPrevent(&$request) {
if (is_string($request)) {
$request = html_entity_decode($request);
$request = strip_tags($request);
$request = trim($request);
$request = stripslashes($request);
}
return $request;
} // xssPrevent()
/**
* Action handler of the class
*
* @return STR dialog or message
*/
public function action() {
$html_allowed = array();
foreach ($_REQUEST as $key => $value) {
if (!in_array($key, $html_allowed)) {
$_REQUEST[$key] = $this->xssPrevent($value);
}
}
isset($_REQUEST[self::request_action]) ? $action = $_REQUEST[self::request_action] : $action = self::action_default;
switch ($action):
case self::action_about:
$this->show(self::action_about, $this->dlgAbout());
break;
case self::action_config:
$this->show(self::action_config, $this->dlgConfig());
break;
case self::action_config_check:
$this->show(self::action_config, $this->checkConfig());
break;
case self::action_process_backup:
$this->show(self::action_backup, $this->processBackup());
break;
case self::action_backup_start:
$this->show(self::action_backup, $this->dlgBackupStart());
break;
case self::action_backup_start_new:
$this->show(self::action_backup, $this->backupStartNewArchive());
break;
case self::action_backup_continue:
$this->show(self::action_backup, $this->backupContinue());
break;
case self::action_restore:
$this->show(self::action_restore, $this->dlgRestore());
break;
case self::action_restore_info:
$this->show(self::action_restore, $this->restoreInfo());
break;
case self::action_restore_start:
$this->show(self::action_restore, $this->restoreStart());
break;
case self::action_restore_continue:
$this->show(self::action_restore, $this->restoreContinue());
break;
case self::action_update_start:
$this->show(self::action_backup, $this->updateStart());
break;
case self::action_update_continue:
$this->show(self::action_backup, $this->updateContinue());
break;
case self::action_default:
default:
$this->show(self::action_backup, $this->dlgBackup());
break;
endswitch;
} // action
/**
* Ausgabe des formatierten Ergebnis mit Navigationsleiste
*
* @param STR $action - aktives Navigationselement
* @param STR $content - Inhalt
*
* @return ECHO RESULT
*/
public function show($action, $content) {
$navigation = array();
foreach ($this->tab_navigation_array as $key => $value) {
$navigation[] = array(
'active' => ($key == $action) ? 1 : 0,
'url' => sprintf('%s&%s=%s', $this->page_link, self::request_action, $key),
'text' => $value
);
}
$data = array(
'WB_URL' => WB_URL,
'navigation' => $navigation,
'error' => ($this->isError()) ? 1 : 0,
'content' => ($this->isError()) ? $this->getError() : $content
);
echo $this->getTemplate('backend.body.lte', $data); echo $this->getError();
} // show()
/**
* About Dialog
*
* @return STR dialog
*/
public function dlgAbout() {
$data = array(
'version' => sprintf('%01.2f', $this->getVersion()),
'img_url' => $this->img_url.'/sync_data_logo.png',
'release_notes' => file_get_contents(WB_PATH.'/modules/'.basename(dirname(__FILE__)).'/info.txt'),
);
return $this->getTemplate('backend.about.lte', $data);
} // dlgAbout()
/**
* Dialog zur Konfiguration und Anpassung von syncData
*
* @return STR dialog
*/
public function dlgConfig() {
global $dbSyncDataCfg;
global $dbSyncDataArchive;
$SQL = sprintf( "SELECT * FROM %s WHERE NOT %s='%s' ORDER BY %s",
$dbSyncDataCfg->getTableName(),
dbSyncDataCfg::field_status,
dbSyncDataCfg::status_deleted,
dbSyncDataCfg::field_name);
$config = array();
if (!$dbSyncDataCfg->sqlExec($SQL, $config)) {
$this->setError($dbSyncDataCfg->getError());
return false;
}
$count = array();
$header = array(
'identifier' => sync_header_cfg_identifier,
'value' => sync_header_cfg_value,
'description' => sync_header_cfg_description
);
$items = array();
// bestehende Eintraege auflisten
foreach ($config as $entry) {
$id = $entry[dbSyncDataCfg::field_id];
$count[] = $id;
$value = ($entry[dbSyncDataCfg::field_type] == dbSyncDataCfg::type_list) ? $dbSyncDataCfg->getValue($entry[dbSyncDataCfg::field_name]) : $entry[dbSyncDataCfg::field_value];
if (isset($_REQUEST[dbSyncDataCfg::field_value.'_'.$id])) $value = $_REQUEST[dbSyncDataCfg::field_value.'_'.$id];
if ($entry[dbSyncDataCfg::field_name] == dbSyncDataCfg::cfgServerArchiveID) {
// Archiv IDs auslesen
$is_value = $value;
$value = array();
$value[] = array(
'value' => '',
'selected' => ($is_value == '') ? 1 : 0,
'text' => '- select -'
);
$where = array(
dbSyncDataArchives::field_status => dbSyncDataArchives::status_active,
dbSyncDataArchives::field_archive_number => 1
);
$archives = array();
if (!$dbSyncDataArchive->sqlSelectRecord($where, $archives)) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $dbSyncDataArchive->getError()));
return false;
}
foreach ($archives as $archive) {
$value[] = array(
'value' => $archive[dbSyncDataArchives::field_archive_id],
'selected' => ($is_value == $archive[dbSyncDataArchives::field_archive_id]) ? 1 : 0,
'text' => sprintf('[ %s ] %s', $archive[dbSyncDataArchives::field_archive_id], $archive[dbSyncDataArchives::field_archive_name])
);
}
}
else {
$value = str_replace('"', '"', stripslashes($value));
}
$items[] = array(
'id' => $id,
'identifier' => constant($entry[dbSyncDataCfg::field_label]),
'value' => $value,
'name' => sprintf('%s_%s', dbSyncDataCfg::field_value, $id),
'description' => constant($entry[dbSyncDataCfg::field_description]),
'type' => $dbSyncDataCfg->type_array[$entry[dbSyncDataCfg::field_type]],
'field' => $entry[dbSyncDataCfg::field_name]
);
}
$data = array(
'form_name' => 'flex_table_cfg',
'form_action' => $this->page_link,
'action_name' => self::request_action,
'action_value' => self::action_config_check,
'items_name' => self::request_items,
'items_value' => implode(",", $count),
'head' => sync_header_cfg,
'intro' => $this->isMessage() ? $this->getMessage() : sprintf(sync_intro_cfg, 'syncData'),
'is_message' => $this->isMessage() ? 1 : 0,
'items' => $items,
'btn_ok' => sync_btn_ok,
'btn_abort' => sync_btn_abort,
'abort_location' => $this->page_link,
'header' => $header
);
return $this->getTemplate('backend.config.lte', $data);
} // dlgConfig()
/**
* Ueberprueft Aenderungen die im Dialog dlgConfig() vorgenommen wurden
* und aktualisiert die entsprechenden Datensaetze.
*
* @return STR DIALOG dlgConfig()
*/
public function checkConfig() {
global $dbSyncDataCfg;
$message = '';
// ueberpruefen, ob ein Eintrag geaendert wurde
if ((isset($_REQUEST[self::request_items])) && (!empty($_REQUEST[self::request_items]))) {
$ids = explode(",", $_REQUEST[self::request_items]);
foreach ($ids as $id) {
if (isset($_REQUEST[dbSyncDataCfg::field_value.'_'.$id])) {
$value = $_REQUEST[dbSyncDataCfg::field_value.'_'.$id];
$where = array();
$where[dbSyncDataCfg::field_id] = $id;
$config = array();
if (!$dbSyncDataCfg->sqlSelectRecord($where, $config)) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $dbSyncDataCfg->getError()));
return false;
}
if (sizeof($config) < 1) {
$this->setError(sprintf(sync_error_cfg_id, $id));
return false;
}
$config = $config[0];
if ($config[dbSyncDataCfg::field_value] != $value) {
// Wert wurde geaendert
if (!$dbSyncDataCfg->setValue($value, $id) && $dbSyncDataCfg->isError()) {
$this->setError($dbSyncDataCfg->getError());
return false;
}
elseif ($dbSyncDataCfg->isMessage()) {
$message .= $dbSyncDataCfg->getMessage();
}
else {
// Datensatz wurde aktualisiert
$message .= sprintf(sync_msg_cfg_id_updated, $config[dbSyncDataCfg::field_name]);
}
}
unset($_REQUEST[dbSyncDataCfg::field_value.'_'.$id]);
}
}
}
$this->setMessage($message);
return $this->dlgConfig();
} // checkConfig()
/**
* Dialog: select existing or new backup
*
* @return STR dialog
*/
public function dlgBackup() {
global $dbSyncDataArchive;
$SQL = sprintf( "SELECT * FROM %s WHERE %s='1' AND %s='%s'",
$dbSyncDataArchive->getTableName(),
dbSyncDataArchives::field_archive_number,
dbSyncDataArchives::field_status,
dbSyncDataArchives::status_active);
$archives = array();
if (!$dbSyncDataArchive->sqlExec($SQL, $archives)) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $dbSyncDataArchive->getError()));
return false;
}
$select_array = array();
$select_array[] = array(
'value' => -1,
'selected' => 1,
'text' => sync_str_new_backup
);
foreach ($archives as $archive) {
$select_array[] = array(
'value' => $archive[dbSyncDataArchives::field_archive_id],
'selected' => 0,
'text' => sprintf('%s - %s', date(sync_cfg_datetime_str, strtotime($archive[dbSyncDataArchives::field_archive_date])), $archive[dbSyncDataArchives::field_archive_name])
);
}
$data = array(
'form' => array( 'name' => 'backup_select',
'link' => $this->page_link,
'action' => array( 'name' => self::request_action,
'value' => self::action_backup_start),
'btn' => array( 'ok' => sync_btn_ok)
),
'backup' => array( 'name' => self::request_backup,
'label' => sync_label_backup_select,
'hint' => sync_hint_backup_select,
'options' => $select_array),
'head' => sync_header_backup,
'is_intro' => $this->isMessage() ? 0 : 1,
'intro' => $this->isMessage() ? $this->getMessage() : sync_intro_backup
);
return $this->getTemplate('backend.backup.select.lte', $data);
} // dlgBackup()
/**
* Dialog zur Auswahl eines neuen Backup oder zur Aktualisierung eines
* bestehenden Backup
*
* @return STR dialog
*/
public function dlgBackupStart() {
global $dbSyncDataArchive;
global $dbSyncDataFile;
global $kitTools;
global $dbSyncDataCfg;
$archiv_id = isset($_REQUEST[self::request_backup]) ? $_REQUEST[self::request_backup] : -1;
if ($archiv_id == -1) {
// neues Archiv anlegen
$select_array = array();
foreach ($dbSyncDataArchive->backup_type_array as $type) {
$select_array[] = array(
'value' => $type['key'],
'text' => $type['value'],
'selected' => ($type['key'] == dbSyncDataArchives::backup_type_complete) ? 1 : 0
);
}
$data = array(
'form' => array( 'name' => 'backup_start',
'link' => $this->page_link,
'action' => array( 'name' => self::request_action,
'value' => self::action_backup_start_new),
'btn' => array( 'ok' => sync_btn_ok)
),
'backup_type' => array('name' => dbSyncDataArchives::field_backup_type,
'label' => sync_label_backup_type_select,
'hint' => sync_hint_backup_type_select,
'options' => $select_array),
'archive_name' => array('name' => dbSyncDataArchives::field_archive_name,
'value' => '',
'label' => sync_label_archive_name,
'hint' => sync_hint_archive_name),
'head' => sync_header_backup_new,
'is_intro' => $this->isMessage() ? 0 : 1,
'intro' => $this->isMessage() ? $this->getMessage() : sync_intro_backup_new,
'text_process' => sprintf(sync_msg_backup_running, $dbSyncDataCfg->getValue(dbSyncDataCfg::cfgLimitExecutionTime)),
'img_url' => $this->img_url
);
return $this->getTemplate('backend.backup.new.lte', $data);
}
else {
/**
* The backup archive should be updated
*/
// first step: read the archive informations
$where = array(dbSyncDataArchives::field_archive_id => $archiv_id);
$archive = array();
if (!$dbSyncDataArchive->sqlSelectRecord($where, $archive)) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $dbSyncDataArchive->getError()));
return false;
}
if (count($archive) < 1) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, sprintf(sync_error_archive_id_invalid, $archiv_id)));
return false;
}
$archive = $archive[0];
// second step: gather the informations about the archived tables and files
$SQL = sprintf( "SELECT COUNT(%s) AS count, SUM(%s) AS bytes FROM %s WHERE %s='%s' AND %s='%s' AND %s='%s'",
dbSyncDataFiles::field_file_name,
dbSyncDataFiles::field_file_size,
$dbSyncDataFile->getTableName(),
dbSyncDataFiles::field_archive_id,
$archive[dbSyncDataArchives::field_archive_id],
dbSyncDataFiles::field_archive_number,
$archive[dbSyncDataFiles::field_archive_number],
dbSyncDataFiles::field_status,
dbSyncDataFiles::status_ok);
$files = array();
if (!$dbSyncDataFile->sqlExec($SQL, $files)) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $dbSyncDataFile->getError()));
return false;
}
if (count($files) < 1) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, sync_error_file_list_invalid));
return false;
}
$files = $files[0];
$values = array(
array('label' => sync_label_archive_id, 'text' => $archive[dbSyncDataArchives::field_archive_id]),
array('label' => sync_label_archive_number, 'text' => $archive[dbSyncDataArchives::field_archive_number]),
array('label' => sync_label_archive_type, 'text' => $dbSyncDataArchive->backup_type_array_text[$archive[dbSyncDataArchives::field_archive_type]]),
array('label' => sync_label_total_files, 'text' => $files['count']),
array('label' => sync_label_total_size, 'text' => $kitTools->bytes2Str($files['bytes'])),
array('label' => sync_label_timestamp, 'text' => date(sync_cfg_datetime_str, strtotime($archive[dbSyncDataArchives::field_timestamp])))
);
$info = array(
'label' => sync_label_archive_info,
'values' => $values
);
$data = array(
'form' => array( 'name' => 'backup_update',
'link' => $this->page_link,
'action' => array( 'name' => self::request_action,
'value' => self::action_update_start),
'archive' => array( 'name' => dbSyncDataArchives::field_archive_id,
'value' => $archiv_id),
'btn' => array( 'ok' => sync_btn_ok,
'abort' => sync_btn_abort)
),
'info' => $info,
'archive_name' => array('name' => dbSyncDataArchives::field_archive_name,
'value' => '',
'label' => sync_label_archive_name,
'hint' => sync_hint_archive_name),
'head' => sync_header_backup_update,
'is_intro' => $this->isMessage() ? 0 : 1,
'intro' => $this->isMessage() ? $this->getMessage() : sync_intro_backup_update,
'text_process' => sprintf(sync_msg_backup_running, $dbSyncDataCfg->getValue(dbSyncDataCfg::cfgLimitExecutionTime)),
'img_url' => $this->img_url
);
return $this->getTemplate('backend.backup.update.lte', $data);
}
} // dlgBackupStart()
/**
* Legt ein neues Backup Archiv an und startet die Datensicherung
*
* @return STR Dialog zum Fortsetzen/Beenden oder BOOL FALSE on error
*/
public function backupStartNewArchive() {
global $interface;
$backup_name = (isset($_REQUEST[dbSyncDataArchives::field_archive_name]) && !empty($_REQUEST[dbSyncDataArchives::field_archive_name])) ? $_REQUEST[dbSyncDataArchives::field_archive_name] : sprintf(sync_str_backup_default_name, date(sync_cfg_datetime_str));
$backup_type = (isset($_REQUEST[dbSyncDataArchives::field_backup_type])) ? $_REQUEST[dbSyncDataArchives::field_backup_type] : dbSyncDataArchives::backup_type_complete;
$job_id = -1;
$status = $interface->backupStart($backup_name, $backup_type, $job_id);
if ($interface->isError()) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $interface->getError()));
return false;
}
if ($status == dbSyncDataJobs::status_time_out) {
return $this->messageBackupInterrupt($job_id);
}
elseif ($status == dbSyncDataJobs::status_finished) {
return $this->messageBackupFinished($job_id);
}
else {
// unknown status ...
$this->setError(sprintf('[%s %s] %s', __METHOD__, __LINE__, sync_error_status_unknown));
return false;
}
} // backupStartNewArchive()
/**
* Generate and show a message that the backup is interrupted,
* shows the actual state of backup
*
* @param INT $job_id
* @return STR message dialog
*/
public function messageBackupInterrupt($job_id) {
global $dbSyncDataJob;
global $dbSyncDataFile;
global $kitTools;
global $dbSyncDataCfg;
$where = array(dbSyncDataJobs::field_id => $job_id);
$job = array();
if (!$dbSyncDataJob->sqlSelectRecord($where, $job)) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $dbSyncDataJob->getError()));
return false;
}
$job = $job[0];
// Anzahl und Umfang der bisher gesicherten Dateien ermitteln
$SQL = sprintf( "SELECT COUNT(%s) AS count, SUM(%s) AS bytes FROM %s WHERE %s='%s' AND %s='%s' AND %s='%s'",
dbSyncDataFiles::field_file_name,
dbSyncDataFiles::field_file_size,
$dbSyncDataFile->getTableName(),
dbSyncDataFiles::field_archive_id,
$job[dbSyncDataJobs::field_archive_id], //$archive_id,
dbSyncDataFiles::field_status,
dbSyncDataFiles::status_ok,
dbSyncDataFiles::field_action,
dbSyncDataFiles::action_add);
$files = array();
if (!$dbSyncDataFile->sqlExec($SQL, $files)) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $dbSyncDataFile->getError()));
return false;
}
$auto_exec_msec = $dbSyncDataCfg->getValue(dbSyncDataCfg::cfgAutoExecMSec);
$auto_exec = $auto_exec_msec > 0 ? sprintf(sync_msg_auto_exec_msec, $auto_exec_msec) : '';
$info = sprintf( sync_msg_backup_to_be_continued,
$this->max_execution_time,
$files[0]['count'],
$kitTools->bytes2Str($files[0]['bytes']),
$auto_exec );
$data = array(
'form' => array( 'name' => 'backup_continue',
'link' => $this->page_link,
'action' => array( 'name' => self::request_action,
'value' => self::action_backup_continue),
'btn' => array( 'abort' => sync_btn_abort,
'ok' => sync_btn_continue)),
'head' => sync_header_backup_continue,
'is_intro' => $this->isMessage() ? 0 : 1,
'intro' => $this->isMessage() ? $this->getMessage() : $info,
'job' => array( 'name' => dbSyncDataJobs::field_id,
'value' => $job_id),
'text_process' => sprintf(sync_msg_backup_running, $dbSyncDataCfg->getValue(dbSyncDataCfg::cfgLimitExecutionTime)),
'img_url' => $this->img_url,
'auto_exec_msec' => $auto_exec_msec
);
// Statusmeldung ausgeben
return $this->getTemplate('backend.backup.interrupt.lte', $data);
} // messageBackupInterrupt()
/**
* Generate and show a message that the backup is finished.
* Shows the main stats of the backup
*
* @param INT $job_id
* @return STR message dialog
*/
public function messageBackupFinished($job_id) {
global $dbSyncDataJob;
global $dbSyncDataFile;
global $kitTools;
global $interface;
global $dbSyncDataArchive;
$where = array(dbSyncDataJobs::field_id => $job_id);
$job = array();
if (!$dbSyncDataJob->sqlSelectRecord($where, $job)) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $dbSyncDataJob->getError()));
return false;
}
if (count($job) < 1) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, sprintf(sync_error_job_id_invalid, $job_id)));
return false;
}
$job = $job[0];
$where = array( dbSyncDataArchives::field_archive_id => $job[dbSyncDataJobs::field_archive_id],
dbSyncDataArchives::field_archive_number => $job[dbSyncDataJobs::field_archive_number]);
$archive = array();
if (!$dbSyncDataArchive->sqlSelectRecord($where, $archive)) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $dbSyncDataArchive->getError()));
return false;
}
if (count($archive) < 1) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, sprintf(sync_error_archive_id_invalid, $job[dbSyncDataJobs::field_archive_id])));
return false;
}
$archive = $archive[0];
// Anzahl und Umfang der bisher gesicherten Dateien ermitteln
$SQL = sprintf( "SELECT COUNT(%s), SUM(%s) FROM %s WHERE %s='%s' AND %s='%s' AND %s='%s'",
dbSyncDataFiles::field_file_name,
dbSyncDataFiles::field_file_size,
$dbSyncDataFile->getTableName(),
dbSyncDataFiles::field_archive_id,
$job[dbSyncDataJobs::field_archive_id],
dbSyncDataFiles::field_status,
dbSyncDataFiles::status_ok,
dbSyncDataFiles::field_action,
dbSyncDataFiles::action_add);
$files = array();
if (!$dbSyncDataFile->sqlExec($SQL, $files)) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $dbSyncDataFile->getError()));
return false;
}
// Meldung zusammenstellen
$info = sprintf( sync_msg_backup_finished,
$files[0][sprintf('COUNT(%s)', dbSyncDataFiles::field_file_name)],
$kitTools->bytes2Str($files[0][sprintf('SUM(%s)', dbSyncDataFiles::field_file_size)]),
str_replace(WB_PATH, WB_URL, $interface->getBackupPath().$archive[dbSyncDataArchives::field_archive_name].'.zip'),
str_replace(WB_PATH, WB_URL, $interface->getBackupPath().$archive[dbSyncDataArchives::field_archive_name].'.zip') );
$data = array(
'form' => array( 'name' => 'backup_continue',
'link' => $this->page_link,
'action' => array( 'name' => self::request_action,
'value' => self::action_default),
'btn' => array( 'ok' => sync_btn_ok)),
'head' => sync_header_backup_finished,
'is_intro' => $this->isMessage() ? 0 : 1,
'intro' => $this->isMessage() ? $this->getMessage() : $info,
'job' => array( 'name' => dbSyncDataJobs::field_id,
'value' => $job_id)
);
// Statusmeldung ausgeben
return $this->getTemplate('backend.backup.message.lte', $data);
} // messageBackupFinished()
/*
* Nimmt das Backup nach einer Unterbrechung wieder auf
*
* @return STR Dialog bzw. Statusmeldung
*/
public function backupContinue() {
global $interface;
$job_id = isset($_REQUEST[dbSyncDataJobs::field_id]) ? $_REQUEST[dbSyncDataJobs::field_id] : -1;
if ($job_id < 1) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, sprintf(sync_error_job_id_invalid, $job_id)));
return false;
}
$status = $interface->backupContinue($job_id);
if ($interface->isError()) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $interface->getError()));
return false;
}
if ($status == dbSyncDataJobs::status_time_out) {
return $this->messageBackupInterrupt($job_id);
}
elseif ($status == dbSyncDataJobs::status_finished) {
return $this->messageBackupFinished($job_id);
}
else {
// in allen anderen Faellen ist nichts zu tun
$this->setMessage(sync_msg_nothing_to_do);
$data = array(
'form' => array( 'name' => 'backup_stop',
'link' => $this->page_link,
'action' => array( 'name' => self::request_action,
'value' => self::action_default),
'btn' => array( 'abort' => sync_btn_abort,
'ok' => sync_btn_ok)),
'head' => sync_header_backup_continue,
'is_intro' => 0, // Meldung anzeigen
'intro' => $this->getMessage(),
'job' => array( 'name' => dbSyncDataJobs::field_id,
'value' => $job_id)
);
// Statusmeldung ausgeben
return $this->getTemplate('backend.backup.message.lte', $data);
}
} // backupContinue()
/**
* Dialog zur Auswahl des Backup Archiv, das fuer einen Restore verwendet
* werden soll
*
* @return STR dialog
*/
public function dlgRestore() {
global $interface;
if (!file_exists($interface->getBackupPath())) {
if (!mkdir($interface->getBackupPath(), 0755, true)) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, sprintf(sync_error_mkdir, $interface->getBackupPath())));
return false;
}
}
$arcs = $interface->directoryTree($interface->getBackupPath());
$archives = array();
foreach ($arcs as $arc) {
if (is_file($arc) && (pathinfo($arc, PATHINFO_EXTENSION) == 'zip')) $archives[] = $arc;
}
$select_array = array();
$select_array[] = array(
'value' => -1,
'selected' => 1,
'text' => sync_str_restore_select
);
foreach ($archives as $archive) {
$select_array[] = array(
'value' => str_replace(WB_PATH, '', $archive),
'selected' => 0,
'text' => basename($archive)
);
}
if (count($archives) < 1) {
// Mitteilung: kein Archiv gefunden!
$dir = str_replace(WB_PATH, '', $interface->getBackupPath());
$this->setMessage(sprintf(sync_msg_no_backup_files_in_dir, $dir, $dir));
}
$data = array(
'form' => array( 'name' => 'restore_select',
'link' => $this->page_link,
'action' => array( 'name' => self::request_action,
'value' => self::action_restore_info),
'btn' => array( 'ok' => sync_btn_ok)
),
'restore' => array( 'name' => self::request_restore,
'label' => sync_label_restore_select,
'hint' => sync_hint_restore_select,
'options' => $select_array),
'head' => sync_header_restore,
'is_intro' => $this->isMessage() ? 0 : 1,
'intro' => $this->isMessage() ? $this->getMessage() : sync_intro_restore
);
return $this->getTemplate('backend.restore.start.lte', $data);
} // dlgRestore()
/**
* Prueft das angegebene Archiv und startet einen Dialog zum Festlegen
* der Parameter fuer den Restore
*
* @return STR dialog
*/
public function restoreInfo() {
global $dbSyncDataJob;
global $kitTools;
global $interface;
global $dbSyncDataCfg;