1 | <?php
|
---|
2 |
|
---|
3 | include_once(dirname(__FILE__).'/../../Base/View.php');
|
---|
4 |
|
---|
5 | class BackupView extends View
|
---|
6 | {
|
---|
7 | var $ItemListFormClass = array(
|
---|
8 | 'Title' => 'Zálohy',
|
---|
9 | 'Table' => '(SELECT * FROM `Backup`)',
|
---|
10 | 'Items' => array(
|
---|
11 | 'Time' => array('Type' => 'DateTime', 'Caption' => 'Čas', 'Default' => ''),
|
---|
12 | 'Description' => array('Type' => 'String', 'Caption' => 'Popis', 'Default' => ''),
|
---|
13 | ),
|
---|
14 | );
|
---|
15 |
|
---|
16 | function ShowListOnRow($Row)
|
---|
17 | {
|
---|
18 | //$Row['Name'] = '<a href="?Action=EmulatorShow&Id='.$Row['Id'].'">'.$Row['Name'].'</a>';
|
---|
19 | return($Row);
|
---|
20 | }
|
---|
21 |
|
---|
22 | function ItemList()
|
---|
23 | {
|
---|
24 | $ServerId = $_GET['Id'];
|
---|
25 | if($this->System->Modules['User']->User['Role'] >= USER_ROLE_USER)
|
---|
26 | {
|
---|
27 | $Server = new Server($this->System, $_GET['Id']);
|
---|
28 | if(($this->System->Modules['User']->User['Id'] == $Server->Server['User']) or ($this->System->Modules['User']->User['Role'] >= USER_ROLE_ADMINISTRATOR))
|
---|
29 | {
|
---|
30 | $Output = '<h4>Dostupné zálohy</h4>';
|
---|
31 | $Table = new Table($this->ItemListFormClass, $this->System);
|
---|
32 | $Table->OnRow = array($this, 'ShowListOnRow');
|
---|
33 | $Table->Definition['Table'] = '(SELECT * FROM `Backup` WHERE `Server` = '.$Server->Id.')';
|
---|
34 | $Table->Definition['Items']['Id'] = array('Type' => 'Hidden', 'Caption' => 'Id', 'Default' => '');
|
---|
35 | $Table->Definition['Items']['Lock'] = array('Type' => 'Hidden', 'Caption' => 'Zámek', 'Default' => '');
|
---|
36 | $Table->LoadValuesFromDatabase($this->Database);
|
---|
37 | $Table->Definition['Items']['Actions'] = array('Type' => 'String', 'Caption' => '', 'Default' => '');
|
---|
38 | foreach($Table->Values as $Index => $Value)
|
---|
39 | {
|
---|
40 | $Table->Values[$Index]['Actions'] = '';
|
---|
41 | if($Value['Lock'] == 0) $Table->Values[$Index]['Actions'] = '<a href="?Action=BackupDownload&Id='.$Value['Id'].'">Stáhnout</a>';
|
---|
42 | if(($Server->Server['Lock'] == 0) and ($Value['Lock'] == 0)) $Table->Values[$Index]['Actions'] .= ' <a href="?Action=BackupRestore&Id='.$Value['Id'].'">Obnovit</a>';
|
---|
43 | unset($Table->Values[$Index]['Id']);
|
---|
44 | unset($Table->Values[$Index]['Lock']);
|
---|
45 | }
|
---|
46 | $Output .= $Table->Show();
|
---|
47 | if($this->System->Modules['User']->User['Role'] >= USER_ROLE_ADMINISTRATOR)
|
---|
48 | {
|
---|
49 | if($Server->Server['Lock'] == 0) $Output .= '<br /><div style="text-align: center;"><a href="?Action=BackupAdd&Id='.$ServerId.'">Zálohovat</a></dev>';
|
---|
50 | }
|
---|
51 | } else $Output = $this->SystemMessage('Zastavení serveru', 'Nemáte oprávnění');
|
---|
52 | } else $Output = USER_BAD_ROLE;
|
---|
53 | return($Output);
|
---|
54 | }
|
---|
55 |
|
---|
56 | function Download()
|
---|
57 | {
|
---|
58 | if(!array_key_exists('Id', $_GET)) $Output = $this->SystemMessage('Stažení souboru zálohy', 'Nebylo zadáno Id zálohy');
|
---|
59 | else if($this->System->Modules['User']->User['Role'] >= USER_ROLE_USER)
|
---|
60 | {
|
---|
61 | $Backup = new Backup($this->System, $_GET['Id']);
|
---|
62 | $Server = new Server($this->System, $Backup->Backup['Server']);
|
---|
63 | if(($this->System->Modules['User']->User['Id'] == $Server->Server['User']) or ($this->System->Modules['User']->User['Role'] >= USER_ROLE_ADMINISTRATOR))
|
---|
64 | {
|
---|
65 | Header('Content-Type: application/x-tar-gz');
|
---|
66 | Header('Content-Disposition: attachment; filename="wowhosting-'.$Backup->Id.'.tar.bz2"');
|
---|
67 | echo(file_get_contents('../backup/wowhosting-'.$Backup->Id.'.tar.bz2'));
|
---|
68 | exit;
|
---|
69 | } else $this->SystemMessage('Stažení souboru zálohy', 'Nemáte oprávnění');
|
---|
70 | } else $Output = USER_BAD_ROLE;
|
---|
71 | return($Output);
|
---|
72 | }
|
---|
73 |
|
---|
74 | function Restore()
|
---|
75 | {
|
---|
76 | if(!array_key_exists('Id', $_GET)) $Output = $this->SystemMessage('Obnovení ze zálohy', 'Nebylo zadáno Id zálohy');
|
---|
77 | else if($this->System->Modules['User']->User['Role'] >= USER_ROLE_USER)
|
---|
78 | {
|
---|
79 | $Backup = new Backup($this->System, $_GET['Id']);
|
---|
80 | $Server = new Server($this->System, $Backup->Backup['Server']);
|
---|
81 | if(($this->System->Modules['User']->User['Id'] == $Server->Server['User']) or ($this->System->Modules['User']->User['Role'] >= USER_ROLE_ADMINISTRATOR))
|
---|
82 | {
|
---|
83 | $Output = $this->SystemMessage('Obnovení ze zálohy', $Backup->Restore());
|
---|
84 | $Output .= $this->ShowTaskList();
|
---|
85 | } else $this->SystemMessage('Obnovení ze zálohy', 'Nemáte oprávnění');
|
---|
86 | } else $Output = USER_BAD_ROLE;
|
---|
87 | return($Output);
|
---|
88 | }
|
---|
89 |
|
---|
90 | function Add()
|
---|
91 | {
|
---|
92 | if(!array_key_exists('Id', $_GET)) $Output = $this->SystemMessage('Ladící informace', 'Nebylo zadáno Id serveru');
|
---|
93 | else if($this->System->Modules['User']->User['Role'] >= USER_ROLE_USER)
|
---|
94 | {
|
---|
95 | $Server = new Server($this->System, $_GET['Id']);
|
---|
96 | if(($this->System->Modules['User']->User['Id'] == $Server->Server['User']) or ($this->System->Modules['User']->User['Role'] >= USER_ROLE_ADMINISTRATOR))
|
---|
97 | {
|
---|
98 | $Backup = new Backup($this->System, 0);
|
---|
99 | $Output = $this->SystemMessage('Ruční zálohování', $Backup->Create($Server->Id));
|
---|
100 | $Output .= $this->ShowTaskList();
|
---|
101 | } else $this->SystemMessage('Ladící informace', 'Nemáte oprávnění');
|
---|
102 | } else $Output = USER_BAD_ROLE;
|
---|
103 | return($Output);
|
---|
104 | }
|
---|
105 | }
|
---|