'; print $message; print ''; } function is__writable($path) { if ($path[strlen($path) - 1] == '/' || $path[strlen($path) - 1] == '\\') { return is__writable($path.uniqid(mt_rand()).'.tmp'); } if (file_exists($path)) { if (!($f = @fopen($path, 'r+'))) { return false; } fclose($f); return true; } if (!($f = @fopen($path, 'w'))) { return false; } fclose($f); unlink($path); return true; } function validate_writable($continue, $path) { if (!is__writable($path)) { printalert("danger", "Failed to get write permissions on " . htmlentities($path)); return false; } return $continue; } function create_use_database($continue_r, $con, $database) { $continue = $continue_r; if ($continue) { $sql = "CREATE DATABASE `" . mysqli_real_escape_string($con, $database) . "` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"; if (mysqli_query($con, $sql)) { printalert("success", "Database " . $database . " created"); } else { printalert("danger", "Error creating " . $database . " database: " . mysqli_error($con)); $continue = false; } } if ($continue) { $sql = "USE `" . mysqli_real_escape_string($con, $database) . "`;"; if (mysqli_query($con, $sql)) { printalert("success", "Database " . $database . " selected"); } else { printalert("danger", "Error selecting " . $database . " database: " . mysqli_error($con)); $continue = false; } } return $continue; } function update_database_structure($continue_r, $con, $file) { $continue = $continue_r; global $PRIVATE_PHP_PATH; if ($continue) { $sql = file_get_contents($PRIVATE_PHP_PATH . "/setup/sql/" . $file); if (!$sql) { printalert("danger", "Cannot read " . $file . ""); $continue = false; } else { if (mysqli_multi_query($con, $sql)) { printalert("success", "Database structure updated using " . $file . ""); while (mysqli_more_results($con) && mysqli_next_result($con)) { // no-op } } else { printalert("danger", "Error updating database using " . $file . ": " . mysqli_error($con)); $continue = false; } } } return $continue; } ?>