XOOPS  2.6.0
dump.php
Go to the documentation of this file.
1 <?php
2 /*
3  You may not change or alter any portion of this comment or credits
4  of supporting developers from this source code or any supporting source code
5  which is considered copyrighted (c) material of the original comment or credit authors.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 */
11 
23 include __DIR__ . '/header.php';
24 // Get main instance
27 $xoops->db();
28 global $xoopsDB;
29 
30 // Get Action type
31 $op = $system->cleanVars($_REQUEST, 'op', 'list', 'string');
32 
33 // Call Header
34 $xoops->header('admin:maintenance/maintenance_dump.tpl');
35 
36 $admin_page = new \Xoops\Module\Admin();
37 $admin_page->renderNavigation('dump.php');
38 
39 switch ($op) {
40 
41  case 'list':
42  default:
43  $files = glob(\XoopsBaseConfig::get('root-path') . '/modules/maintenance/dump/*.*');
44  $count = 0;
45  foreach ($files as $filename_path) {
46  $filename = basename(strtolower($filename_path));
47  if ($filename != 'index.html') {
48  $file_arr[$count]['name'] = $filename;
49  $stat = stat($filename_path);
50  $file_arr[$count]['size'] = number_format($stat['size']/1024);
51  ++$count;
52  unset($filename);
53  }
54  }
55  if (isset($file_arr)) {
56  $xoops->tpl()->assign('file_arr', array_reverse($file_arr));
57  }
58  if ($count == 0 && $op == 'list') {
59  $form = $xoops->getModuleForm(null, 'maintenance');
60  $form->getDump();
61  $form->display();
62  } else {
63  $admin_page->addItemButton(_AM_MAINTENANCE_DUMP_FORM, 'dump.php?op=dump', 'cd');
64  $admin_page->renderButton();
65  $xoops->tpl()->assign('files', true);
66  }
67  break;
68 
69  case 'dump_save':
70  // Check security
71  if (!$xoops->security()->check()) {
72  $xoops->redirect('dump.php', 3, implode('<br />', $xoops->security()->getErrors()));
73  }
74  $admin_page->addItemButton(_AM_MAINTENANCE_DUMP_LIST, 'dump.php', 'application-view-detail');
75  $admin_page->addItemButton(_AM_MAINTENANCE_DUMP_FORM, 'dump.php?op=dump', 'cd');
76  $admin_page->renderButton();
77  $dump_modules = isset($_REQUEST['dump_modules']) ? $_REQUEST['dump_modules'] : false;
78  $dump_tables = isset($_REQUEST['dump_tables']) ? $_REQUEST['dump_tables'] : false;
79  $drop = $system->cleanVars($_REQUEST, 'drop', 1, 'int');
80 
81  if (($dump_tables == true && $dump_modules == true) || ($dump_tables == false && $dump_modules == false)) {
82  $xoops->redirect("dump.php", 2, _AM_MAINTENANCE_DUMP_ERROR_TABLES_OR_MODULES);
83  }
84  $db = $xoopsDB;
85  $dump = new Maintenance();
86  $sql_text = "# \n";
87  $sql_text .= "# Dump SQL, Generated by XOOPS \n";
88  $sql_text .= "# Date : " . date(XoopsLocale::getFormatMediumDate()) . " \n";
89  $sql_text .= "# \n\n";
90  if ($dump_tables != false) {
91  $result_module = array();
92  for ($i = 0; $i < count($dump_tables); ++$i) {
93  //structure
94  $result_tables[$i]['name'] = $db->prefix . '_' . $dump_tables[$i];
95  $result_structure = $dump->dump_table_structure($db->prefix . '_' . $dump_tables[$i], $drop);
96  $sql_text .= $result_structure['sql_text'];
97  $result_tables[$i]['structure'] = $result_structure['structure'];
98  //data
99  $result_data = $dump->dump_table_datas($db->prefix . '_' . $dump_tables[$i]);
100  $sql_text .= $result_data['sql_text'];
101  $result_tables[$i]['records'] = $result_data['records'];
102  }
103  $xoops->tpl()->assign('result_t', $result_tables);
104  }
105  if ($dump_modules != false) {
106  $result_module = array();
107  for ($i = 0; $i < count($dump_modules); ++$i) {
108  $module_handler = $xoops->getHandlerModule();
109  $module = $xoops->getModuleByDirname($dump_modules[$i]);
110  $result_module[$i]['name'] = ucfirst($dump_modules[$i]);
111  $modtables = $module->getInfo('tables');
112  if ($modtables != false && is_array($modtables)) {
113  $count = 0;
114  foreach ($modtables as $table) {
115  //structure
116  $result_tables[$count]['name'] = $db->prefix . '_' . $table;
117  $result_structure = $dump->dump_table_structure($db->prefix . '_' . $table, $drop);
118  $sql_text .= $result_structure['sql_text'];
119  $result_tables[$count]['structure'] = $result_structure['structure'];
120 
121  //data
122  $result_data = $dump->dump_table_datas($db->prefix . '_' . $table);
123  $sql_text .= $result_data['sql_text'];
124  $result_tables[$count]['records'] = $result_data['records'];
125  ++$count;
126  }
127  $result_module[$i]['table'] = $result_tables;
128  } else {
129  $result_module[$i]['table'] = false;
130  }
131  unset($result_tables);
132  }
133  $xoops->tpl()->assign('result_m', $result_module);
134  }
135  $xoops->tpl()->assign('result_write', true);
136  $result_write = $dump->dump_write($sql_text);
137  $xoops->tpl()->assign('write', $result_write['write']);
138  $xoops->tpl()->assign('file_name', $result_write['file_name']);
139  break;
140 
141  case 'dump_delete':
142  $filename = $system->cleanVars($_REQUEST, 'filename', '', 'string');
143  if ($filename == '') {
144  $xoops->redirect("dump.php", 2, _AM_MAINTENANCE_DUMP_NOFILE);
145  }
146  unlink(\XoopsBaseConfig::get('root-path') . '/modules/maintenance/dump/' . $filename);
147  $xoops->redirect("dump.php", 2, _AM_MAINTENANCE_DUMP_DELETED);
148  break;
149 
150  case 'dump_deleteall':
151  $files = glob(\XoopsBaseConfig::get('root-path') . '/modules/maintenance/dump/*.*');
152  $count = 0;
153  foreach ($files as $filename_path) {
154  if (basename(strtolower($filename_path)) != 'index.html') {
155  unlink($filename_path);
156  }
157  }
158  $xoops->redirect("dump.php", 2, _AM_MAINTENANCE_DUMP_DELETEDALL);
159  break;
160 
161  case 'dump':
162  $form = $xoops->getModuleForm(null, 'maintenance');
163  $form->getDump();
164  $form->display();
165  break;
166 }
167 $xoops->footer();
$xoops
Definition: dump.php:26
const _AM_MAINTENANCE_DUMP_ERROR_TABLES_OR_MODULES
Definition: admin.php:65
$i
Definition: dialog.php:68
static getInstance()
Definition: system.php:46
static getInstance()
Definition: Xoops.php:160
global $xoopsDB
Definition: dump.php:28
$form
Definition: xoops_code.php:21
$files
Definition: index.php:35
$admin_page
Definition: dump.php:36
const _AM_MAINTENANCE_DUMP_DELETED
Definition: admin.php:60
static getFormatMediumDate()
Definition: Abstract.php:173
static get($name)
$module
Definition: main.php:52
const _AM_MAINTENANCE_DUMP_LIST
Definition: admin.php:70
const _AM_MAINTENANCE_DUMP_NOFILE
Definition: admin.php:72
$system
Definition: dump.php:25
$module_handler
Definition: main.php:55
$op
Definition: dump.php:31
const _AM_MAINTENANCE_DUMP_DELETEDALL
Definition: admin.php:62
const _AM_MAINTENANCE_DUMP_FORM
Definition: admin.php:69