Add files via upload

This commit is contained in:
Giandonato Inverso
2020-09-08 18:09:19 +02:00
committed by GitHub
parent 97df13f3f0
commit 86f32b6327
83 changed files with 12716 additions and 0 deletions
+61
View File
@@ -0,0 +1,61 @@
/**
* PHP Dynamic Qr code
*
* @author Giandonato Inverso <info@giandonatoinverso.it>
* @copyright Copyright (c) 2020-2021
* @license https://opensource.org/licenses/MIT MIT License
* @link https://github.com/giandonatoinverso/PHP-Dynamic-Qr-code
* @version 1.0
*/
<?php
class Core {
// Function to validate the post data
function validate_post($data)
{
/* Validating the hostname, the database name and the username. The password is optional. */
return !empty($data['db_host']) && !empty($data['db_user']) && !empty($data['db_name']);
}
// Function to show an error
function show_message($type,$message) {
return $message;
}
// Function to write the config file
function write_config($data) {
// Config path
$template_path = 'config/database.php';
$output_path = '../config/config.php';
// Open the file
$database_file = file_get_contents($template_path);
$new = str_replace("%HOSTNAME%",$data['db_host'],$database_file);
$new = str_replace("%USERNAME%",$data['db_user'],$new);
$new = str_replace("%PASSWORD%",$data['db_password'],$new);
$new = str_replace("%DATABASE%",$data['db_name'],$new);
// Write the new database.php file
$handle = fopen($output_path,'w+');
// Chmod the file, in case the user forgot
@chmod($output_path,0777);
// Verify file permissions
if(is_writable($output_path)) {
// Write the file
if(fwrite($handle,$new)) {
return true;
} else {
return false;
}
} else {
return false;
}
}
}
@@ -0,0 +1,54 @@
/**
* PHP Dynamic Qr code
*
* @author Giandonato Inverso <info@giandonatoinverso.it>
* @copyright Copyright (c) 2020-2021
* @license https://opensource.org/licenses/MIT MIT License
* @link https://github.com/giandonatoinverso/PHP-Dynamic-Qr-code
* @version 1.0
*/
<?php
class Database {
// Function to the database and tables and fill them with the default data
function create_database($data)
{
// Connect to the database
$mysqli = new mysqli($data['db_host'],$data['db_user'],$data['db_password'],'');
// Check for errors
if(mysqli_connect_errno())
return false;
// Create the prepared statement
$mysqli->query("CREATE DATABASE IF NOT EXISTS ".$data['db_name']);
// Close the connection
$mysqli->close();
return true;
}
// Function to create the tables and fill them with the default data
function create_tables($data)
{
// Connect to the database
$mysqli = new mysqli($data['db_host'],$data['db_user'],$data['db_password'],$data['db_name']);
// Check for errors
if(mysqli_connect_errno())
return false;
// Open the default SQL file
$query = file_get_contents('sql/sample_data.sql');
// Execute a multi query
$mysqli->multi_query($query);
// Close the connection
$mysqli->close();
return true;
}
}