1+ <?php
2+
3+ /*
4+ Copyright (c) 2012, Till Brehm, ISPConfig UG
5+ All rights reserved.
6+
7+ Redistribution and use in source and binary forms, with or without modification,
8+ are permitted provided that the following conditions are met:
9+
10+ * Redistributions of source code must retain the above copyright notice,
11+ this list of conditions and the following disclaimer.
12+ * Redistributions in binary form must reproduce the above copyright notice,
13+ this list of conditions and the following disclaimer in the documentation
14+ and/or other materials provided with the distribution.
15+ * Neither the name of ISPConfig nor the names of its contributors
16+ may be used to endorse or promote products derived from this software without
17+ specific prior written permission.
18+
19+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22+ IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23+ INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24+ BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26+ OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+ */
30+
31+ class plugin_backuplist extends plugin_base {
32+
33+ var $ module ;
34+ var $ form ;
35+ var $ tab ;
36+ var $ record_id ;
37+ var $ formdef ;
38+ var $ options ;
39+
40+ function onShow () {
41+
42+ global $ app ;
43+
44+ $ listTpl = new tpl ;
45+ $ listTpl ->newTemplate ('templates/web_backup_list.htm ' );
46+
47+ //* Loading language file
48+ $ lng_file = "lib/lang/ " .$ _SESSION ["s " ]["language " ]."_web_backup_list.lng " ;
49+ include ($ lng_file );
50+ $ listTpl ->setVar ($ wb );
51+
52+ $ message = '' ;
53+ $ error = '' ;
54+
55+ if (isset ($ _GET ['backup_action ' ])) {
56+ $ backup_id = intval ($ _GET ['backup_id ' ]);
57+
58+ if ($ _GET ['backup_action ' ] == 'download ' && $ backup_id > 0 ) {
59+ $ sql = "SELECT count(action_id) as number FROM sys_remoteaction WHERE action_state = 'pending' AND action_type = 'backup_download' AND action_param = ' $ backup_id' " ;
60+ $ tmp = $ app ->db ->queryOneRecord ($ sql );
61+ if ($ tmp ['number ' ] == 0 ) {
62+ $ message .= $ wb ['download_info_txt ' ];
63+ $ sql = "INSERT INTO sys_remoteaction (server_id, tstamp, action_type, action_param, action_state, response) " .
64+ "VALUES ( " .
65+ (int )$ this ->form ->dataRecord ['server_id ' ] . ", " .
66+ time () . ", " .
67+ "'backup_download', " .
68+ "' " .$ backup_id ."', " .
69+ "'pending', " .
70+ "'' " .
71+ ") " ;
72+ $ app ->db ->query ($ sql );
73+ } else {
74+ $ error .= $ wb ['download_pending_txt ' ];
75+ }
76+ }
77+ if ($ _GET ['backup_action ' ] == 'restore ' && $ backup_id > 0 ) {
78+ $ sql = "SELECT count(action_id) as number FROM sys_remoteaction WHERE action_state = 'pending' AND action_type = 'backup_restore' AND action_param = ' $ backup_id' " ;
79+ $ tmp = $ app ->db ->queryOneRecord ($ sql );
80+ if ($ tmp ['number ' ] == 0 ) {
81+ $ message .= $ wb ['restore_info_txt ' ];
82+ $ sql = "INSERT INTO sys_remoteaction (server_id, tstamp, action_type, action_param, action_state, response) " .
83+ "VALUES ( " .
84+ (int )$ this ->form ->dataRecord ['server_id ' ] . ", " .
85+ time () . ", " .
86+ "'backup_restore', " .
87+ "' " .$ backup_id ."', " .
88+ "'pending', " .
89+ "'' " .
90+ ") " ;
91+ $ app ->db ->query ($ sql );
92+ } else {
93+ $ error .= $ wb ['restore_pending_txt ' ];
94+ }
95+ }
96+
97+ }
98+
99+ //* Get the data
100+ $ sql = "SELECT * FROM web_backup WHERE parent_domain_id = " .$ this ->form ->id ." ORDER BY tstamp DESC, backup_type ASC " ;
101+ $ records = $ app ->db ->queryAllRecords ($ sql );
102+
103+ $ bgcolor = "#FFFFFF " ;
104+ if (is_array ($ records )) {
105+ foreach ($ records as $ rec ) {
106+
107+ // Change of color
108+ $ bgcolor = ($ bgcolor == "#FFFFFF " )?"#EEEEEE " :"#FFFFFF " ;
109+ $ rec ["bgcolor " ] = $ bgcolor ;
110+
111+ $ rec ['date ' ] = date ($ app ->lng ('conf_format_datetime ' ),$ rec ['tstamp ' ]);
112+ $ rec ['backup_type ' ] = $ wb [('backup_type_ ' .$ rec ['backup_type ' ])];
113+
114+ $ records_new [] = $ rec ;
115+ }
116+ }
117+
118+ $ listTpl ->setLoop ('records ' ,@$ records_new );
119+
120+ $ listTpl ->setVar ('parent_id ' ,$ this ->form ->id );
121+ $ listTpl ->setVar ('msg ' ,$ message );
122+ $ listTpl ->setVar ('error ' ,$ error );
123+
124+ // Setting Returnto information in the session
125+ $ list_name = 'backup_list ' ;
126+ // $_SESSION["s"]["list"][$list_name]["parent_id"] = $app->tform_actions->id;
127+ $ _SESSION ["s " ]["list " ][$ list_name ]["parent_id " ] = $ this ->form ->id ;
128+ $ _SESSION ["s " ]["list " ][$ list_name ]["parent_name " ] = $ app ->tform ->formDef ["name " ];
129+ $ _SESSION ["s " ]["list " ][$ list_name ]["parent_tab " ] = $ _SESSION ["s " ]["form " ]["tab " ];
130+ $ _SESSION ["s " ]["list " ][$ list_name ]["parent_script " ] = $ app ->tform ->formDef ["action " ];
131+ $ _SESSION ["s " ]["form " ]["return_to " ] = $ list_name ;
132+
133+ return $ listTpl ->grab ();
134+ }
135+
136+ }
137+
138+ ?>
0 commit comments