public static function backup($database, $tables, $filename, $structure = true, $data = true, $drop = true, $compress = true, $full = false) { if (!is_array($tables) || empty($tables)) { trigger_error('No tables to backup', E_USER_WARNING); return false; } $crlf = "\n"; $esc = SQL_LAYER == 'postgresql' ? '--' : '#'; # doing some DOS-CRLF magic... # this looks better under WinX if (preg_match('#[^(]*\\((.*)\\)[^)]*#', $_SERVER['HTTP_USER_AGENT'], $regs)) { if (false !== stripos($regs[1], 'Win')) { $crlf = "\r\n"; } } if (GZIPSUPPORT) { while (ob_end_clean()) { } header('Content-Encoding: '); } else { $compress = false; } if ($compress) { $filename .= '.gz'; header("Content-Type: application/x-gzip; name=\"{$filename}\""); } else { header("Content-Type: text/x-delimtext; name=\"{$filename}\""); } header("Content-disposition: attachment; filename={$filename}"); DBCtrl::output("{$esc} ========================================================{$crlf}" . "{$esc}{$crlf}" . "{$esc} Database : {$database}{$crlf}" . "{$esc} " . _ON . " " . formatDateTime(time(), _DATESTRING) . " !{$crlf}" . "{$esc}{$crlf}" . "{$esc} ========================================================{$crlf}" . "{$crlf}", $compress); set_time_limit(0); if (SQL_LAYER == 'mysql') { $database = "`{$database}`"; } foreach ($tables as $table) { if ($structure) { DBCtrl::output("{$crlf}{$esc}{$crlf}" . "{$esc} Table structure for table '{$table}'{$crlf}" . "{$esc}{$crlf}{$crlf}", $compress); DBCtrl::output(SQLCtrl::get_table_struct($database, $table, $crlf, $drop) . ";{$crlf}{$crlf}", $compress); } if ($data) { DBCtrl::output("{$crlf}{$esc}{$crlf}" . "{$esc} Dumping data for table '{$table}'{$crlf}" . "{$esc}{$crlf}{$crlf}", $compress); SQLCtrl::get_table_content($database, $table, $crlf, false, true, $compress); } } if ($compress) { DBCtrl::output('', true, true); } exit; }
public static function backup($database, $tables, $filename, $structure = true, $data = true, $drop = true, $compress = true, $full = false) { global $db; $schema = $database; if (!is_array($tables) || empty($tables)) { trigger_error('No tables to backup', E_USER_WARNING); return false; } $crlf = "\n"; $current_user = $db->sql_ufetchrowset('SELECT CURRENT_USER', SQL_NUM); $current_user = $current_user[0][0]; //$search_path = $db->sql_ufetchrowset('SELECT current_schemas(true)'); //$search_path = preg_replace('#^{(.*?)}$#', '\\1', $search_path[0][0]); # doing some DOS-CRLF magic... # this looks better under WinX if (preg_match('#[^(]*\\((.*)\\)[^)]*#', $_SERVER['HTTP_USER_AGENT'], $regs)) { if (false !== stripos($regs[1], 'Win')) { $crlf = "\r\n"; } } if (GZIPSUPPORT) { while (ob_end_clean()) { } header('Content-Encoding: '); } else { $compress = false; } if ($compress) { $filename .= '.gz'; header("Content-Type: application/x-gzip; name=\"{$filename}\""); } else { header("Content-Type: text/x-delimtext; name=\"{$filename}\""); } header("Content-disposition: attachment; filename={$filename}"); $controls = "--{$crlf}-- PostgreSQL dump : {$database}{$crlf}" . "-- " . _ON . " " . formatDateTime(time(), _DATESTRING) . " !{$crlf}--{$crlf}{$crlf}" . "SET client_encoding = '" . pg_client_encoding() . "';{$crlf}" . "SET check_function_bodies = false;{$crlf}" . "SET SESSION AUTHORIZATION '{$current_user}';{$crlf}{$crlf}"; if ($full) { if ($drop) { $controls .= 'DROP SCHEMA ' . $schema . ' CASCADE;' . $crlf; } $controls .= "CREATE SCHEMA {$schema} AUTHORIZATION {$current_user};{$crlf}" . "REVOKE ALL ON SCHEMA {$schema} FROM PUBLIC;{$crlf}" . 'ALTER USER ' . $current_user . ' SET search_path TO ' . $schema . ";{$crlf}" . "{$crlf}"; } DBCtrl::output($controls, $compress); set_time_limit(0); if ($drop && !$full) { SQLCtrl::drop_table_struct($schema, $tables, $crlf, $compress); } if ($structure) { if ($full) { DBCtrl::output(SQLCtrl::get_function($schema, $crlf), $compress); } SQLCtrl::get_table_struct($schema, $tables, $crlf, $compress); } if ($data) { SQLCtrl::get_table_content($schema, $tables, $crlf, false, $compress); } if ($structure) { SQLCtrl::get_index($schema, $tables, $crlf, $compress); DBCtrl::output(SQLCtrl::get_sequence($schema, $tables, $crlf, $full), $compress); } DBCtrl::output($crlf . 'VACUUM ANALYZE;', $compress); if ($compress) { DBCtrl::output('', true, true); } exit; }
break; case 'StatusDB': $showblocks = 0; if (DB_TYPE == 'postgresql') { $schema = $db->sql_ufetchrowset('SELECT current_schema()'); $query = 'SELECT relname, seq_scan, seq_tup_read, idx_scan, idx_tup_fetch, n_tup_upd, n_tup_del FROM pg_stat_user_tables WHERE schemaname = \'' . $schema[0][0] . '\' ORDER BY relname'; } else { $query = "SHOW TABLE STATUS"; } show($mode, $tablelist, $query); break; case 'RestoreDB': require_once 'header.php'; GraphicAdmin('_AMENU0'); require_once CORE_PATH . 'classes/sqlctrl.php'; if (!SQLCtrl::query_file($_FILES['sqlfile'], $error)) { cpg_error($error); } OpenTable(); echo '<span class="genmed"><strong>' . _DATABASE . ': ' . $dbname . '</strong></span><br /><br />Importation of <em>' . $_FILES['sqlfile']['name'] . '</em> was successful'; CloseTable(); break; case 'Installer': if (!is_dir('cache') || !is_writable('cache')) { cpg_error('Cache directory doesn\'t exists or not writable'); } require_once 'header.php'; GraphicAdmin('_AMENU0'); foreach ($tablelist as $table) { $list = $db->list_columns($table); if (0 === strpos($table, $prefix . '_')) {
define('ADMIN_MOD_INSTALL', 1); include 'modules/' . $class . '/sql/cpg_inst.php'; } else { if (file_exists(BASEDIR . 'modules/' . $class . '/cpg_inst.php')) { define('ADMIN_MOD_INSTALL', 1); include 'modules/' . $class . '/cpg_inst.php'; } } if (defined('ADMIN_MOD_INSTALL') && class_exists($class)) { $module = new $class(); $tables = array(); require_once CORE_PATH . 'classes/sqlctrl.php'; foreach ($module->dbtables as $table) { $tables[] = $prefix . '_' . $table; } SQLCtrl::backup($dbname, $tables, str_replace(' ', '_', $module->modname) . '.sql'); } } else { if (isset($_POST['save'])) { if ($CPG_SESS['admin']['page'] != 'modules') { cpg_error(_ERROR_BAD_LINK, _SEC_ERROR); } $mid = intval($_POST['save']); $custom_title = Fix_Quotes($_POST['custom_title'], true); $view = intval($_POST['view']); $inmenu = intval($_POST['inmenu']); $blocks = intval($_POST['blocks']); $result = $db->sql_query('SELECT title FROM ' . $prefix . "_modules WHERE mid={$mid}"); if ($db->sql_numrows($result) > 0) { list($title) = $db->sql_fetchrow($result); if ($title == 'Your_Account') {