. */ /** * This file allows the user to create and restore backups. The backups are * kept within the database, so they aren't true backups but more like * snapshots. */ require('includes/basics.php'); $version_temp = get_DBversion(); $versionDB = $version_temp[0]; $revisionDB = $version_temp[1]; $p = $kga['server_prefix']; /** * Execute an sql query in the database. The correct database connection * will be chosen and the query will be logged with the success status. * * @param $query query to execute as string */ function exec_query($query) { global $conn, $pdo_conn, $kga, $errors, $executed_queries; $success = false; if ($kga['server_conn'] == "pdo") { if (is_object($pdo_conn)) { $pdo_query = $pdo_conn->prepare($query); $success = $pdo_query->execute(array()); } else $errorInfo = "No connection object."; } else { if (is_object($conn)) { $success = $conn->Query($query); } else $errorInfo = "No connection object."; } logfile($query); if (!$success) { logfile($errorInfo); $errors=true; } } if (isset($_REQUEST['submit'])) { if ($_REQUEST['submit'] == $kga['lang']['backup'][8]) { /** * Create a backup. */ logfile("-- begin backup -----------------------------------"); $backup_stamp = time(); $query = ("SHOW TABLES;"); if ($kga['server_conn'] == "pdo") { if (is_object($pdo_conn)) { $pdo_query = $pdo_conn->prepare($query); $success = $pdo_query->execute(array()); $tables = $pdo_query->fetchAll(); } } else { if (is_object($conn)) { $success = $conn->Query($query); $tables = $conn->RecordsArray(); } } $prefix_length = strlen($p); foreach($tables as $row) { if ((substr($row[0], 0, $prefix_length) == $p) && (substr($row[0], 0, 10) != "kimai_bak_")) { $primaryKey = ""; if (strlen(strstr($row[0],"evt"))>0) { $primaryKey = "evt_ID";} if (strlen(strstr($row[0],"grp"))>0) { $primaryKey = "grp_ID";} if (strlen(strstr($row[0],"knd"))>0) { $primaryKey = "knd_ID";} if (strlen(strstr($row[0],"pct"))>0) { $primaryKey = "pct_ID";} if (strlen(strstr($row[0],"zef"))>0) { $primaryKey = "zef_ID";} if (strlen(strstr($row[0],"usr"))>0) { $primaryKey = "usr_name";} if (strlen(strstr($row[0],"var"))>0) { $primaryKey = "var";} if ( (strlen(strstr($row[0],"ldr"))>0) || (strlen(strstr($row[0],"grp_evt"))>0) || (strlen(strstr($row[0],"pct_evt"))>0) || (strlen(strstr($row[0],"grp_knd"))>0) || (strlen(strstr($row[0],"grp_pct"))>0)) { $primaryKey = "uid"; } if (strlen(strstr($row[0],"preferences"))>0) { $primaryKey = "userID`,`var"; } if ( ((int)$revisionDB < 733) && (strlen(strstr($row[0],"ldr"))>0) ) { $primaryKey = ""; } if ($primaryKey!="") { $primaryKey = " (PRIMARY KEY (`" .$primaryKey. "`))"; } $query = "CREATE TABLE kimai_bak_" . $backup_stamp . "_" . $row[0] . $primaryKey . " SELECT * FROM " . $row[0] . ";"; exec_query($query,1); if ($errors) die($kga['lang']['updater'][60]); } } logfile("-- backup finished -----------------------------------"); header("location: db_restore.php"); } if ($_REQUEST['submit'] == $kga['lang']['backup'][3]) { /** * Delete backups. */ $dates = $_REQUEST['dates']; $query = ("SHOW TABLES;"); if ($kga['server_conn'] == "pdo") { if (is_object($pdo_conn)) { $pdo_query = $pdo_conn->prepare($query); $success = $pdo_query->execute(array()); $tables = $pdo_query->fetchAll(); } } else { if (is_object($conn)) { $success = $conn->Query($query); $tables = $conn->RecordsArray(); } } foreach ($tables as $row) { if ((substr($row[0], 0, 10) == "kimai_bak_")) { if ( in_array(substr($row[0], 10, 10),$dates) ) { $arr2[] = "DROP TABLE `".$row[0]."`;"; } } } if ($kga['server_conn'] == "pdo") { if (is_object($pdo_conn)) { $query=""; foreach($arr2 AS $row) { $query .= $row; } $pdo_query = $pdo_conn->prepare($query); $success = $pdo_query->execute(array()); } } else { if (is_object($conn)) { foreach($arr2 AS $row) { $success = $conn->Query($row); if (!$success) break; } } } header("location: db_restore.php"); } } ?>