From 1ab6846ed00feafea105da8f1c0ca3db791a4913 Mon Sep 17 00:00:00 2001 From: Rod Roark Date: Thu, 19 Jun 2014 13:01:51 -0700 Subject: [PATCH] New feature to export individual lists and layouts. --- interface/main/backup.php | 93 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 74 insertions(+), 19 deletions(-) diff --git a/interface/main/backup.php b/interface/main/backup.php index 05b1b2f4e..5ef4adca9 100644 --- a/interface/main/backup.php +++ b/interface/main/backup.php @@ -1,6 +1,6 @@ +// Copyright (C) 2008-2014 Rod Roark // Adapted for cross-platform operation by Bill Cernansky (www.mi-squared.com) // // This program is free software; you can redistribute it and/or @@ -121,7 +121,7 @@ if ($form_step == 104) {  
- +>
@@ -317,18 +317,16 @@ if ($form_step == 7) { // create the final compressed tar containing all files $auto_continue = true; } - if ($form_step == 101) { - echo xl('Select the configuration items to export') . ":"; - echo "
 
\n"; + echo "

 " . xl('Select the configuration items to export') . ":

"; + + echo "\n\n\n\n
\n"; + + echo "" . xlt('Tables') . "
\n"; echo "\n"; echo " " . xl('Services') . "
\n"; echo "\n"; echo " " . xl('Products') . "
\n"; - echo "\n"; - echo " " . xl('Lists') . "
\n"; - echo "\n"; - echo " " . xl('Layouts') . "
\n"; echo "\n"; echo " " . xl('Prices') . "
\n"; echo "\n"; @@ -338,6 +336,31 @@ if ($form_step == 101) { echo "\n"; echo " " . xl('Translations') . "
\n"; + // Multi-select for lists. + echo "
\n"; + echo "" . xlt('Lists') . "
\n"; + echo "\n"; + + // Multi-select for layouts. + echo "
\n"; + echo "" . xlt('Layouts') . "
\n"; + echo "\n"; + + echo "
\n"; echo " 
\n"; } @@ -345,26 +368,58 @@ if ($form_step == 102) { $tables = ''; if ($_POST['form_cb_services' ]) $tables .= ' codes'; if ($_POST['form_cb_products' ]) $tables .= ' drugs drug_templates'; - if ($_POST['form_cb_lists' ]) $tables .= ' list_options'; - if ($_POST['form_cb_layouts' ]) $tables .= ' layout_options'; if ($_POST['form_cb_prices' ]) $tables .= ' prices'; if ($_POST['form_cb_categories']) $tables .= ' categories categories_seq'; if ($_POST['form_cb_feesheet' ]) $tables .= ' fee_sheet_options'; if ($_POST['form_cb_lang' ]) $tables .= ' lang_languages lang_constants lang_definitions'; - if ($tables) { + if ($tables || is_array($_POST['form_sel_lists']) || is_array($_POST['form_sel_layouts'])) { $form_status .= xl('Creating export file') . "...
"; echo nl2br($form_status); - if (file_exists($EXPORT_FILE)) + if (file_exists($EXPORT_FILE)) { if (! unlink($EXPORT_FILE)) die(xl("Couldn't remove old export file: ") . $EXPORT_FILE); - + } + $cmd = "echo 'SET character_set_client = utf8;' > $EXPORT_FILE;"; // The substitutions below use perl because sed's not usually on windows systems. $perl = $PERL_PATH . DIRECTORY_SEPARATOR . 'perl'; - $cmd = "$mysql_dump_cmd -u " . escapeshellarg($sqlconf["login"]) . + if ($tables) { + $cmd .= "$mysql_dump_cmd -u " . escapeshellarg($sqlconf["login"]) . + " -p" . escapeshellarg($sqlconf["pass"]) . + " --opt --quote-names " . + escapeshellarg($sqlconf["dbase"]) . " $tables" . + " | $perl -pe 's/ DEFAULT CHARSET=utf8//i; s/ collate[ =][^ ;,]*//i;'" . + " >> $EXPORT_FILE;"; + } + $dumppfx = "$mysql_dump_cmd -u " . escapeshellarg($sqlconf["login"]) . " -p" . escapeshellarg($sqlconf["pass"]) . - " --opt --quote-names " . - escapeshellarg($sqlconf["dbase"]) . " $tables" . - " | $perl -pe 's/ DEFAULT CHARSET=utf8//i; s/ collate[ =][^ ;,]*//i;'" . - " > $EXPORT_FILE;"; + " --skip-opt --quote-names --complete-insert --no-create-info"; + // Individual lists. + if (is_array($_POST['form_sel_lists'])) { + foreach ($_POST['form_sel_lists'] as $listid) { + $cmd .= "echo \"DELETE FROM list_options WHERE list_id = '$listid';\" >> $EXPORT_FILE;"; + $cmd .= "echo \"DELETE FROM list_options WHERE list_id = 'lists' AND option_id = '$listid';\" >> $EXPORT_FILE;"; + $cmd .= $dumppfx . + " --where=\"list_id = 'lists' AND option_id = '$listid' OR list_id = '$listid'\" " . + escapeshellarg($sqlconf["dbase"]) . " list_options" . + " >> $EXPORT_FILE;"; + } + } + // Individual layouts. + if (is_array($_POST['form_sel_layouts'])) { + foreach ($_POST['form_sel_layouts'] as $layoutid) { + $cmd .= "echo \"DELETE FROM layout_options WHERE form_id = '$layoutid';\" >> $EXPORT_FILE;"; + if (strpos($layoutid, 'LBF') === 0) { + $cmd .= "echo \"DELETE FROM list_options WHERE list_id = 'lbfnames' AND option_id = '$layoutid';\" >> $EXPORT_FILE;"; + $cmd .= $dumppfx . + " --where=\"list_id = 'lbfnames' AND option_id = '$layoutid'\" " . + escapeshellarg($sqlconf["dbase"]) . " list_options" . + " >> $EXPORT_FILE;"; + } + $cmd .= $dumppfx . + " --where=\"form_id = '$layoutid'\" " . + escapeshellarg($sqlconf["dbase"]) . " layout_options" . + " >> $EXPORT_FILE;"; + } + } } else { echo xl('No items were selected!'); -- 2.11.4.GIT