Exemplo n.º 1
0
// attempt to grab the COMPANYID variable from the user's record in the DB
if ($_REQUEST['uuid']) {
    $result = mysql_query("SET NAMES utf8;", $cnx) or die(mysql_error());
    $query = "SELECT company_id FROM users WHERE uuid = '{$uuid}'";
    $result = mysql_query($query, $cnx) or die(mysql_error() . "<p>Query: {$query}</p>");
    $result_num_rows = mysql_num_rows($result);
    if ($result_num_rows == 1) {
        // only one result should be allowed
        $COMPANYID = mysql_result($result, 0);
    } else {
        $COMPANYID = NULL;
    }
}
//Instantiate the SQL_Export class
require "SQL_Export.php";
$e = new SQL_Export($server, $username, $password, $db, $table_list);
// if the user requested a download
if ($_REQUEST['uuid'] && $result_num_rows == 1) {
    // run the export
    if ($DOWNLOAD) {
        //Run the export (force a file download)
        $sqlFile = $e->export($COMPANYID);
        // option to create a custom filename here
        $DATE = date("Y-m-d");
        $filename = "ClockingIT-backup-{$DATE}.sql";
        force_download($sqlFile, "{$filename}");
    } else {
        //Run the export (to the browser)
        echo '<pre>' . $e->export($COMPANYID) . '</pre>';
    }
} else {
        $query .= "(`customized_type`='Principal' AND `customized_id` IN ({$users})) OR ";
    }
    if (!empty($projects)) {
        $query .= "(`customized_type`='Project'   AND `customized_id` IN ({$projects})) OR ";
    }
    $query .= "FALSE";
    $result = mysql_query($query) or die("Query custom_values failed: " . mysql_error() . "\n");
    $custom_values = "";
    while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
        $custom_values .= $row[0] . ",";
        //echo "custom_values: {$row[0]}\n";
    }
    $custom_values = substr($custom_values, 0, -1);
}
//Instantiate the SQL_Export class
$e = new SQL_Export($server, $username, $password, $db);
// Define the database tables
$tables = $e->get_tables();
// Open the output file
$database_file = "database_{$userId}.sql";
$fp = fopen($database_file, 'w');
# Now UTF-8 - Add byte order mark
fwrite($fp, pack("CCC", 0xef, 0xbb, 0xbf));
//Run the export
foreach ($tables as $t) {
    $header = $e->create_header($t);
    $data = "";
    switch ($t) {
        case 'attachments':
            if (!empty($attachments)) {
                $data = $e->get_data($t, "`id` IN ({$attachments})");