mirror of https://github.com/itflow-org/itflow
added database download script
This commit is contained in:
parent
abe693207d
commit
65e9884d46
|
|
@ -110,7 +110,7 @@ if(isset($_GET['client_id'])){
|
|||
</div>
|
||||
<div class="col-1">
|
||||
<div class="dropdown dropleft text-center">
|
||||
<button class="btn btn-primary btn-sm float-right" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
<button class="btn btn-secondary btn-sm float-right" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
<i class="fas fa-ellipsis-h"></i>
|
||||
</button>
|
||||
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@
|
|||
}
|
||||
$client_email = $row['client_email'];
|
||||
$client_website = $row['client_website'];
|
||||
$client_net_terms = $row['client_net_terms'];
|
||||
|
||||
//Add up all the payments for the invoice and get the total amount paid to the invoice
|
||||
$sql_invoice_amounts = mysqli_query($mysqli,"SELECT SUM(invoice_amount) AS invoice_amounts FROM invoices WHERE client_id = $client_id AND invoice_status NOT LIKE 'Draft'");
|
||||
|
|
|
|||
75
post.php
75
post.php
|
|
@ -74,6 +74,81 @@ if(isset($_POST['edit_invoice_settings'])){
|
|||
|
||||
}
|
||||
|
||||
if(isset($_GET['download_database'])){
|
||||
|
||||
// Get All Table Names From the Database
|
||||
$tables = array();
|
||||
$sql = "SHOW TABLES";
|
||||
$result = mysqli_query($mysqli, $sql);
|
||||
|
||||
while ($row = mysqli_fetch_row($result)) {
|
||||
$tables[] = $row[0];
|
||||
}
|
||||
|
||||
$sqlScript = "";
|
||||
foreach ($tables as $table) {
|
||||
|
||||
// Prepare SQLscript for creating table structure
|
||||
$query = "SHOW CREATE TABLE $table";
|
||||
$result = mysqli_query($mysqli, $query);
|
||||
$row = mysqli_fetch_row($result);
|
||||
|
||||
$sqlScript .= "\n\n" . $row[1] . ";\n\n";
|
||||
|
||||
|
||||
$query = "SELECT * FROM $table";
|
||||
$result = mysqli_query($mysqli, $query);
|
||||
|
||||
$columnCount = mysqli_num_fields($result);
|
||||
|
||||
// Prepare SQLscript for dumping data for each table
|
||||
for ($i = 0; $i < $columnCount; $i ++) {
|
||||
while ($row = mysqli_fetch_row($result)) {
|
||||
$sqlScript .= "INSERT INTO $table VALUES(";
|
||||
for ($j = 0; $j < $columnCount; $j ++) {
|
||||
$row[$j] = $row[$j];
|
||||
|
||||
if (isset($row[$j])) {
|
||||
$sqlScript .= '"' . $row[$j] . '"';
|
||||
} else {
|
||||
$sqlScript .= '""';
|
||||
}
|
||||
if ($j < ($columnCount - 1)) {
|
||||
$sqlScript .= ',';
|
||||
}
|
||||
}
|
||||
$sqlScript .= ");\n";
|
||||
}
|
||||
}
|
||||
|
||||
$sqlScript .= "\n";
|
||||
}
|
||||
|
||||
if(!empty($sqlScript))
|
||||
{
|
||||
// Save the SQL script to a backup file
|
||||
$backup_file_name = date('Y-m-d') . '_' . $config_company_name . '_backup.sql';
|
||||
$fileHandler = fopen($backup_file_name, 'w+');
|
||||
$number_of_lines = fwrite($fileHandler, $sqlScript);
|
||||
fclose($fileHandler);
|
||||
|
||||
// Download the SQL backup file to the browser
|
||||
header('Content-Description: File Transfer');
|
||||
header('Content-Type: application/octet-stream');
|
||||
header('Content-Disposition: attachment; filename=' . basename($backup_file_name));
|
||||
header('Content-Transfer-Encoding: binary');
|
||||
header('Expires: 0');
|
||||
header('Cache-Control: must-revalidate');
|
||||
header('Pragma: public');
|
||||
header('Content-Length: ' . filesize($backup_file_name));
|
||||
ob_clean();
|
||||
flush();
|
||||
readfile($backup_file_name);
|
||||
exec('rm ' . $backup_file_name);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(isset($_POST['add_user'])){
|
||||
|
||||
$name = strip_tags(mysqli_real_escape_string($mysqli,$_POST['name']));
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
</div>
|
||||
<div class="card-body p-5">
|
||||
<center>
|
||||
<button class="btn btn-primary btn-lg"><i class="fa fa-download"></i> Download Database</button>
|
||||
<a class="btn btn-primary btn-lg" href="post.php?download_database"><i class="fa fa-download"></i> Download Database</a>
|
||||
</center>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Reference in New Issue