Cheetah
db.php
Go to the documentation of this file.
1 <?php
2 
8 require_once( '../inc/header.inc.php' );
9 require_once( CH_DIRECTORY_PATH_INC . 'design.inc.php' );
10 require_once( CH_DIRECTORY_PATH_INC . 'admin_design.inc.php' );
11 ch_import('ChWsbDatabaseBackup');
12 ch_import('ChTemplFormView');
13 
14 $logged['admin'] = member_auth(1, true, true);
15 set_time_limit(36000);
16 
18  'perform' => 1,
19 );
20 $oZ = new ChWsbAlerts('system', 'admin_db_backup_actions', 0, 0, array(
21  'actions' => &$aEnabledDbAction
22 ));
23 $oZ->alert();
24 
26 if(isset($aEnabledDbAction['perform']))
28 
29 $sRestoreC = _t('_adm_dbtools_Database_restore');
30 
34 
35 $sBoxContent = <<<EOF
36 <style>
37  div.hidden {
38  display:none;
39  }
40 </style>
41 <script type="text/javascript">
42  <!--
43  function switchAdmPage(oLink)
44  {
45  var sType = jQuery(oLink).attr('id').replace('main_menu', '');
46  var sName = '#page' + sType;
47 
48  jQuery(oLink).parent('.notActive').hide().siblings('.notActive:hidden').show().siblings('.active').hide().siblings('#' + jQuery(oLink).attr('id') + '-act').show();
49  jQuery(sName).siblings('div:visible').ch_anim('hide', 'fade', 'slow', function(){
50  jQuery(sName).ch_anim('show', 'fade', 'slow');
51  });
52 
53  return false;
54  }
55  -->
56 </script>
57 
58 <div class="boxContent" id="adm_pages">
59  <div id="page1" class="visible">{$sTablesBackupToolsBlock}</div>
60  <div id="page2" class="hidden">{$sDatabaseBackupToolsBlock}</div>
61 </div>
62 EOF;
63 
64 $aTopItems = array(
65  'main_menu1' => array('href' => 'javascript:void(0)', 'onclick' => 'javascript:switchAdmPage(this)', 'title' => _t('_adm_dbtools_Tables_backup_tools'), 'active' => 1),
66  'main_menu2' => array('href' => 'javascript:void(0)', 'onclick' => 'javascript:switchAdmPage(this)', 'title' => _t('_adm_dbtools_Database_backup_tools'), 'active' => 0)
67 );
68 
70 $sResult .= DesignBoxAdmin(_t('_adm_dbtools_Database_restore'), $sStatusTextRestore . $sDatabaseRestoreBlock);
72 
74 $_page = array(
75  'name_index' => $iNameIndex,
76  'css_name' => array('forms_adv.css'),
77  'header' => _t('_adm_dbtools_title'),
78 );
79 
80 $_page_cont[$iNameIndex]['page_main_code'] = $sResult;
81 
82 $oZ = new ChWsbAlerts('system', 'admin_db_backup_page', 0, 0, array(
83  'page_vars' => &$_page,
84  'page_cont' => &$_page_cont,
85 ));
86 
87 $oZ->alert();
88 
90 
91 // Functions
93 {
94  $sSuccDumpedIntoFileC = _t('_adm_dbtools_succ_dumped_into_file');
95  $sDumpFileSuccDeletedC = _t('_adm_dbtools_Dump_file_succefully_deleted');
96  $sPleaseSelectDumpFileC = _t('_adm_dbtools_Please_select_dump_file');
97  $sDateRestoredFromDumpC = _t('_adm_dbtools_Data_succefully_restored_from_dump');
98  $sPleaseSelectCorrectDumpFileC = _t('_adm_dbtools_Please_select_correct_dump_file');
99  $sDateRestoredFromPcC = _t('_adm_dbtools_Data_succefully_restored_from_PC');
100 
101  $status_text = $status_text_restore = '';
102 
103  if (isset($_POST['TablesBackup'])) { ##Block of table backup create
104  //echo "For: Tables Tools". $_POST['tbl_op'] . ' Table - ' . $_POST['tbl'] . ' Show param - ' . $_POST['savetype'] ;
105 
106  $OutPutType = preg_replace("/[^0-9]/", '', $_POST['tbl_op']);
107  $oNewBackup = new ChWsbDatabaseBackup();
108  $oNewBackup -> _getTableStruct($_POST['tbl'], $OutPutType);
109 
110  if ($_POST['savetype'] == 'client') {
111  $sqlfile = date("Y-m-d_H:i:s").'_'.$_POST['tbl'].'.sql';
112  header("Content-Type: text/plain");
113  header("Content-Disposition: attachment;filename=\"".$sqlfile."\"");
114  echo $oNewBackup -> sInputs;
115  exit();
116  }
117  if ($_POST['savetype'] == 'server') {
118  $sqlfile = CH_DIRECTORY_PATH_ROOT . 'backup/'.date("Y-m-d_H-i-s").'_'.$_POST['tbl'].'.sql';
119  $file = fopen($sqlfile, 'w');
120  fputs($file, $oNewBackup -> sInputs);
121  $status_text .= "<hr size=1 /><font color='green'><center>{$sSuccDumpedIntoFileC} <b>{$sqlfile}</b></center></font>\n";
122  fclose($file);
123  }
124  if ($_POST['savetype'] == 'show') {
125  $status_text = "<center><textarea cols='100' rows='30' name='content' style='font-family: Arial; font-size: 11px' readonly='readonly'>" . $oNewBackup -> sInputs ."</textarea></center>";
126  }
127  }
128 
129  if (isset($_POST['DatabasesBackup'])) {
130  $OutPutType = preg_replace("/[^0-9]/", '', $_POST['db_op']);
131  $oNewBackup = new ChWsbDatabaseBackup();
132  $oNewBackup -> _getAllTables($OutPutType);
133 
134  if ($_POST['savetype'] == 'show') {
135  $status_text = "<center><textarea cols='100' rows='30' name='content' style='font-family: Arial; font-size: 11px' readonly='readonly'>" . $oNewBackup -> sInputs ."</textarea></center>";
136  }
137  if ($_POST['savetype'] == 'server') {
138  $sqlfile = CH_DIRECTORY_PATH_ROOT . 'backup/'.date("Y-m-d_H-i-s").'_all.sql';
139  $file = fopen($sqlfile, 'w');
140  fputs($file, $oNewBackup -> sInputs);
141  $status_text .= "<hr size=1 /><font color='green'><center>{$sSuccDumpedIntoFileC} <b>{$sqlfile}</b></center></font>\n";
142  fclose($file);
143  }
144  if ($_POST['savetype'] == 'client') {
145  $sqlfile = date("Y-m-d_H:i:s").'_all.sql';
146  header("Content-Type: text/plain");
147  header("Content-Disposition: attachment;filename=\"".$sqlfile."\"");
148  echo $oNewBackup -> sInputs;
149  exit();
150  }
151  }
152 
153  if (isset($_POST['DatabasesRestore'])) {
154  if ($_POST['savetype'] == 'delete') {
155  if(is_file(CH_DIRECTORY_PATH_ROOT.'backup/'.$_POST['dump_file'])) {
156  @unlink(CH_DIRECTORY_PATH_ROOT.'backup/'.$_POST['dump_file']);
157  $status_text_restore .= "<hr size=1 /><font color='green'><center>{$sDumpFileSuccDeletedC} <b>{$sqlfile}</b></center></font>\n";
158  } else
159  $status_text_restore .= "<hr size=1 /><font color='red'><center>{$sPleaseSelectDumpFileC} <b>{$sqlfile}</b></center></font>\n";
160  }
161  if ($_POST['savetype'] == 'restore') {
162  if(is_file(CH_DIRECTORY_PATH_ROOT.'backup/'.$_POST['dump_file'])) {
163  $oNewBackup = new ChWsbDatabaseBackup();
164  $oNewBackup -> _restoreFromDumpFile(CH_DIRECTORY_PATH_ROOT.'backup/'.$_POST['dump_file']);
165  $status_text_restore .= "<hr size=1 /><font color='green'><center>{$sDateRestoredFromDumpC}</center></font>\n";
166  } else
167  $status_text_restore .= "<hr size=1 /><font color='red'><center>{$sPleaseSelectDumpFileC} <b>{$sqlfile}</b></center></font>\n";
168  }
169  }
170 
171  if (isset($_FILES['sqlfile'])) {
172  if (preg_match("/.sql/", $_FILES['sqlfile']['name'])) { #it is correct
173  $oNewBackup = new ChWsbDatabaseBackup();
174  $oNewBackup -> _restoreFromDumpFile($_FILES['sqlfile']['tmp_name'] );
175  @unlink($_FILES['sqlfile']['tmp_name']);
176  $status_text_restore .= "<hr size=1 /><font color='green'><center>{$sDateRestoredFromPcC} </center></font>\n";
177  } else
178  $status_text_restore .= "<hr size=1 /><font color='red'><center>{$sPleaseSelectCorrectDumpFileC}</center></font>\n";
179  }
180 
181  return array($status_text, $status_text_restore);
182 }
183 
184 function getTablesBackupTools($status_text)
185 {
186  $sChooseOperationC = _t('_adm_dbtools_Choose_operation_and_table');
187  $sBackup1C = _t('_adm_dbtools_Backup_structure_content');
188  $sBackup2C = _t('_adm_dbtools_Backup_structure');
189  $sBackup3C = _t('_adm_dbtools_Backup_content');
190  $sSaveOption1C = _t('_adm_dbtools_Save_to_server');
191  $sSaveOption2C = _t('_adm_dbtools_Save_to_your_PC');
192  $sSaveOption3C = _t('_adm_dbtools_Show_on_the_screen');
193  $sBackupTableC = _t('_adm_dbtools_Backup_table');
194  $sActionC = _t('_Action');
195 
196  // All tables of Database
197  $aTablesOptions = array();
198  $tbls = db_list_tables();
199  foreach ($tbls as $tbl) {
200  $aTablesOptions[$tbl] = $tbl;
201  }
202 
203  $sStatusText = ($status_text and isset($_POST['TablesBackup'])) ? $status_text : '';
204 
205  $aForm = array(
206  'form_attrs' => array(
207  'name' => 'TablesBackupTools_form',
208  'action' => $GLOBALS['site']['url_admin'] . 'db.php',
209  'method' => 'post',
210  ),
211  'inputs' => array(
212  'TablesBackup' => array(
213  'type' => 'hidden',
214  'name' => 'TablesBackup',
215  'value' => 'YES',
216  ),
217  'tbl_op' => array(
218  'type' => 'select',
219  'name' => 'tbl_op',
220  'caption' => $sChooseOperationC,
221  'values' => array (
222  2 => $sBackup1C,
223  0 => $sBackup2C,
224  1 => $sBackup3C,
225  ),
226  ),
227  'tbl' => array(
228  'type' => 'select',
229  'name' => 'tbl',
230  'caption' => '',
231  'values' => $aTablesOptions,
232  ),
233  'savetype' => array(
234  'type' => 'radio_set',
235  'name' => 'savetype',
236  'caption' => $sActionC,
237  'values' => array (
238  'server' => $sSaveOption1C,
239  'client' => $sSaveOption2C,
240  'show' => $sSaveOption3C,
241  ),
242  ),
243  'tables_backup_tool' => array(
244  'type' => 'submit',
245  'name' => 'tables_backup_tool',
246  'caption' => '',
247  'value' => $sBackupTableC,
248  ),
249  ),
250  );
251 
253  return $GLOBALS['oAdmTemplate']->parseHtmlByName('design_box_content.html', array('content' => $oForm->getCode() . $sStatusText));
254  //return DesignBoxContent(_t('_adm_dbtools_Tables_backup_tools'), '<div style="margin:9px;">' . $oForm->getCode() . '</div>' . $sStatusText, 1);
255 }
256 
257 function DatabaseBackupTools($status_text)
258 {
259  $sChooseOperationC = _t('_adm_dbtools_Choose_operation');
260  $sBackup1C = _t('_adm_dbtools_Backup_structure_content');
261  $sBackup2C = _t('_adm_dbtools_Backup_structure');
262  $sSaveOption1C = _t('_adm_dbtools_Save_to_server');
263  $sSaveOption2C = _t('_adm_dbtools_Save_to_your_PC');
264  $sSaveOption3C = _t('_adm_dbtools_Show_on_the_screen');
265  $sBackupDatabaseC = _t('_adm_dbtools_Backup_database');
266  $sActionC = _t('_Action');
267 
268  $sStatusText = ($status_text and isset($_POST['DatabasesBackup'])) ? $status_text : '';
269 
270  $aForm = array(
271  'form_attrs' => array(
272  'name' => 'DatabaseBackupTools_form',
273  'action' => $GLOBALS['site']['url_admin'] . 'db.php',
274  'method' => 'post',
275  ),
276  'inputs' => array(
277  'DatabasesBackup' => array(
278  'type' => 'hidden',
279  'name' => 'DatabasesBackup',
280  'value' => 'YES',
281  ),
282  'db_op' => array(
283  'type' => 'select',
284  'name' => 'db_op',
285  'caption' => $sChooseOperationC,
286  'values' => array (
287  2 => $sBackup1C,
288  0 => $sBackup2C,
289  ),
290  ),
291  'savetype' => array(
292  'type' => 'radio_set',
293  'name' => 'savetype',
294  'caption' => $sActionC,
295  'values' => array (
296  'server' => $sSaveOption1C,
297  'client' => $sSaveOption2C,
298  'show' => $sSaveOption3C,
299  ),
300  ),
301  'database_backup_tool' => array(
302  'type' => 'submit',
303  'name' => 'database_backup_tool',
304  'caption' => '',
305  'value' => $sBackupDatabaseC,
306  ),
307  ),
308  );
309 
311  return $GLOBALS['oAdmTemplate']->parseHtmlByName('design_box_content.html', array('content' => $oForm->getCode() . $sStatusText));
312  //return DesignBoxContent(_t('_adm_dbtools_Database_backup_tools'), '<div style="margin:9px;">' . $oForm->getCode() . '</div>' . $sStatusText, 1);
313 }
314 
315 function getDatabaseRestoreBlock($status_text)
316 {
317  $sPleaseSelectDumpFileC = _t('_adm_dbtools_Please_select_dump_file');
318  $sRestoreDataFromDumpC = _t('_adm_dbtools_Restore_data_from_dump');
319  $sDeleteDumpFromServerC = _t('_adm_dbtools_Delete_dump_from_server');
320  $sDatabaseRestoreFromPCC = _t('_adm_dbtools_Database_restore_from_your_PC');
321  $sSendC = _t('_Send');
322  $sSubmitC = _t('_Submit');
323  $sActionC = _t('_Action');
324 
325  $aExistedFilesOptions = array();
326  if ( $handle = @opendir(CH_DIRECTORY_PATH_ROOT.'backup/') ) {
327  while ( $file = readdir($handle) ) {
328  if ( preg_match("/.sql/", $file) )
329  $aExistedFilesOptions[$file] = $file;
330  }
331  }
332 
333  $sStatusText = ($status_text and isset($_POST['DatabasesRestore']) or isset($_FILES['sqlfile']) ) ? $status_text : '';
334 
335  $aForm = array(
336  'form_attrs' => array(
337  'name' => 'DatabaseRestore1_form',
338  'action' => $GLOBALS['site']['url_admin'] . 'db.php',
339  'method' => 'post',
340  ),
341  'inputs' => array(
342  'DatabasesRestore' => array(
343  'type' => 'hidden',
344  'name' => 'DatabasesRestore',
345  'value' => 'YES',
346  ),
347  'dump_file' => array(
348  'type' => 'select',
349  'name' => 'dump_file',
350  'caption' => $sPleaseSelectDumpFileC,
351  'values' => $aExistedFilesOptions,
352  ),
353  'savetype' => array(
354  'type' => 'radio_set',
355  'name' => 'savetype',
356  'caption' => $sActionC,
357  'values' => array (
358  'restore' => $sRestoreDataFromDumpC,
359  'delete' => $sDeleteDumpFromServerC,
360  ),
361  'value' => 'restore',
362  ),
363  'DatabaseRestore1' => array(
364  'type' => 'submit',
365  'name' => 'DatabaseRestore1',
366  'caption' => '',
367  'value' => $sSubmitC,
368  ),
369  ),
370  );
372 
373  $aForm2 = array(
374  'form_attrs' => array(
375  'name' => 'DatabaseRestore1_form',
376  'action' => $GLOBALS['site']['url_admin'] . 'db.php',
377  'method' => 'post',
378  'enctype' => 'multipart/form-data',
379  ),
380  'inputs' => array(
381  'header1' => array(
382  'type' => 'block_header',
383  'caption' => $sDatabaseRestoreFromPCC,
384  ),
385  'sqlfile' => array(
386  'type' => 'file',
387  'name' => 'sqlfile',
388  'caption' => $sPleaseSelectDumpFileC,
389  'required' => true,
390  ),
391  'DatabaseRestore2' => array(
392  'type' => 'submit',
393  'name' => 'DatabaseRestore2',
394  'caption' => '',
395  'value' => $sSendC,
396  ),
397  ),
398  );
399  $oForm2 = new ChTemplFormView($aForm2);
400 
401  return $GLOBALS['oAdmTemplate']->parseHtmlByName('design_box_content.html', array('content' => $oForm->getCode() . '<br />' . $oForm2->getCode() . $sStatusText));
402 }
header
</code > Be careful enabling this directive if you have a redirector script that does not use the< code > Location</code > HTTP header
Definition: URI.MungeResources.txt:10
adm_hosting_promo
adm_hosting_promo()
Definition: admin_design.inc.php:134
ChTemplFormView
Definition: ChTemplFormView.php:11
it
HTML AllowedModules you can quickly activate or disable these modules by specifying which modules you wish to allow with this directive This is most useful for unit testing specific although end users may find it useful for their own ends</p >< p > If you specify a module that does not the manager will silently fail to use it
Definition: HTML.AllowedModules.txt:16
$sRestoreC
$sRestoreC
Definition: db.php:29
$sBoxContent
$sBoxContent
Definition: db.php:35
db_list_tables
db_list_tables()
Definition: db.inc.php:29
ch_import
ch_import($sClassName, $aModule=array())
Definition: utils.inc.php:1218
$_page
$_page
Definition: db.php:74
php
$oZ
$oZ
Definition: db.php:20
$aTopItems
$aTopItems
Definition: db.php:64
$sDatabaseBackupToolsBlock
$sDatabaseBackupToolsBlock
Definition: db.php:32
$oForm
$oForm
Definition: host_tools.php:42
getActionResultBlock
getActionResultBlock()
Definition: db.php:92
DesignBoxAdmin
DesignBoxAdmin($sTitle, $sContent, $mixedTopItems='', $sBottomItems='', $iIndex=1)
Definition: admin_design.inc.php:50
getDatabaseRestoreBlock
getDatabaseRestoreBlock($status_text)
Definition: db.php:315
ChWsbAlerts
Definition: ChWsbAlerts.php:39
exit
exit
Definition: cart.php:21
and
and
Definition: license.txt:18
$aEnabledDbAction
$aEnabledDbAction
Definition: db.php:17
table
and distribute a copy of this License along with the Library You may charge a fee for the physical act of transferring a and you may at your option offer warranty protection in exchange for a fee You may modify your copy or copies of the Library or any portion of thus forming a work based on the and copy and distribute such modifications or work under the terms of Section provided that you also meet all of these other than as an argument passed when the facility is then you must make a good faith effort to ensure in the event an application does not supply such function or table
Definition: license.txt:180
$logged
$logged['admin']
Definition: db.php:14
of
however that any such election will not serve to withdraw this and this License will continue in full force and effect unless terminated as stated above Miscellaneous Each time You Distribute or Publicly Perform the Work or a the Licensor offers to the recipient a license to the Work on the same terms and conditions as the license granted to You under this License Each time You Distribute or Publicly Perform an Licensor offers to the recipient a license to the original Work on the same terms and conditions as the license granted to You under this License If any provision of this License is invalid or unenforceable under applicable it shall not affect the validity or enforceability of the remainder of the terms of this and without further action by the parties to this such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable No term or provision of this License shall be deemed waived and no breach consented to unless such waiver or consent shall be in writing and signed by the party to be charged with such waiver or consent This License constitutes the entire agreement between the parties with respect to the Work licensed here There are no agreements or representations with respect to the Work not specified here Licensor shall not be bound by any additional provisions that may appear in any communication from You This License may not be modified without the mutual written agreement of the Licensor and You The rights granted and the subject matter in this License were drafted utilizing the terminology of the Berne Convention for the Protection of Literary and Artistic the Rome Convention of
Definition: license.txt:65
getTablesBackupTools
getTablesBackupTools($status_text)
Definition: db.php:184
type
if(!defined("USER_STATUS_TYPE")) define("USER_STATUS_TYPE" type
Definition: constants.inc.php:13
$sDatabaseRestoreBlock
$sDatabaseRestoreBlock
Definition: db.php:33
PageCodeAdmin
PageCodeAdmin($oTemplate=null)
Definition: admin_design.inc.php:45
_t
_t($key, $arg0="", $arg1="", $arg2="")
Definition: languages.inc.php:509
member_auth
member_auth($member=0, $error_handle=true, $bAjx=false)
Definition: admin.inc.php:262
ChWsbDatabaseBackup
Definition: ChWsbDatabaseBackup.php:11
$_page_cont
$_page_cont[$iNameIndex]['page_main_code']
Definition: db.php:80
DatabaseBackupTools
DatabaseBackupTools($status_text)
Definition: db.php:257
$sStatusText
$sStatusText
Definition: db.php:25
$aForm
$aForm
Definition: forgot.php:43
$sResult
$sResult
Definition: db.php:69
as
as
Definition: Filter.ExtractStyleBlocks.Escaping.txt:10
display
CSS AllowTricky< code > display
Definition: CSS.AllowTricky.txt:9
$iNameIndex
$iNameIndex
Definition: db.php:73
$sTablesBackupToolsBlock
$sTablesBackupToolsBlock
Definition: db.php:31
$GLOBALS
$GLOBALS['iAdminPage']
Definition: advanced_settings.php:10
or
Voluntary License Schemes The Licensor waives the right to collect whether individually or
Definition: license.txt:37
$sStatusTextRestore
if(isset($aEnabledDbAction['perform'])) list($sStatusText $sStatusTextRestore
Definition: db.php:27