Skip to content

Commit

Permalink
wip: adding a prefix chosen by user, in order to use only one db for …
Browse files Browse the repository at this point in the history
…multiple sites
  • Loading branch information
davide committed Dec 19, 2022
1 parent 033aff5 commit 7e82551
Show file tree
Hide file tree
Showing 24 changed files with 247 additions and 319 deletions.
19 changes: 10 additions & 9 deletions admin/class/Colors.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ class Colors{

private $conn;
private $table_name = "color";

public $id;
public $color;
public $prx;

// constructor
public function __construct($db){
Expand All @@ -19,7 +20,7 @@ function create(){

// insert query
$query = "INSERT INTO
" . $this->table_name . "
" .$this->prx. $this->table_name . "
SET
color = :color";

Expand All @@ -46,7 +47,7 @@ function create(){
function update(){
// insert query
$query = "UPDATE
" . $this->table_name . "
" .$this->prx. $this->table_name . "
SET
color = :color
WHERE
Expand Down Expand Up @@ -82,7 +83,7 @@ function showAll(){
$query = "SELECT
id, color
FROM
" . $this->table_name . "
" .$this->prx. $this->table_name . "
ORDER BY
color";

Expand All @@ -98,7 +99,7 @@ function showAllList(){
$query = "SELECT
id, color
FROM
" . $this->table_name . "
" .$this->prx. $this->table_name . "
ORDER BY
color";

Expand All @@ -110,7 +111,7 @@ function showAllList(){

public function countAll(){

$query = "SELECT id FROM color";
$query = "SELECT id FROM ".$this->prx."color";

$stmt = $this->conn->prepare( $query );
$stmt->execute();
Expand All @@ -122,7 +123,7 @@ public function countAll(){

function showById(){
$query = "SELECT *
FROM " . $this->table_name . "
FROM " .$this->prx. $this->table_name . "
WHERE id = ?
LIMIT 0,1";

Expand All @@ -143,7 +144,7 @@ function colorExists(){

// query to check if email exists
$query = "SELECT id, color
FROM " . $this->table_name . "
FROM " .$this->prx. $this->table_name . "
WHERE color = ?
LIMIT 0,1";

Expand Down Expand Up @@ -183,7 +184,7 @@ function colorExists(){
// delete the role
function delete(){

$query = "DELETE FROM " . $this->table_name . " WHERE id = ?";
$query = "DELETE FROM " .$this->prx. $this->table_name . " WHERE id = ?";

$stmt = $this->conn->prepare($query);
$stmt->bindParam(1, $this->id);
Expand Down
11 changes: 6 additions & 5 deletions admin/class/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Contact{
public $id;
public $label;
public $email;
public $prx;

// constructor
public function __construct($db){
Expand All @@ -20,7 +21,7 @@ function create(){

// insert query
$query = "INSERT INTO
" . $this->table_name . "
" .$this->prx. $this->table_name . "
SET
label = :label,
email = :email";
Expand Down Expand Up @@ -51,7 +52,7 @@ function update(){

// insert query
$query = "UPDATE
" . $this->table_name . "
" .$this->prx. $this->table_name . "
SET
email = :email
WHERE
Expand Down Expand Up @@ -88,7 +89,7 @@ function showAll(){
$query = "SELECT
*
FROM
" . $this->table_name . "
" .$this->prx. $this->table_name . "
ORDER BY
id";

Expand All @@ -104,7 +105,7 @@ function showAllContacts(){
$query = "SELECT
*
FROM
" . $this->table_name . "
" .$this->prx. $this->table_name . "
WHERE NOT id=1
ORDER BY
id";
Expand All @@ -117,7 +118,7 @@ function showAllContacts(){

function delete(){

$query = "DELETE FROM " . $this->table_name . " WHERE id = :id";
$query = "DELETE FROM " .$this->prx. $this->table_name . " WHERE id = :id";

$stmt = $this->conn->prepare($query);
$stmt->bindParam(":id", $this->id);
Expand Down
11 changes: 6 additions & 5 deletions admin/class/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class File{
public $rolename;
public $file;
public $operation;
public $prx;

// constructor
public function __construct($db){
Expand Down Expand Up @@ -71,13 +72,13 @@ function uploadFile(){
$query="";
if($this->operation=="add"){
$query = "INSERT INTO
" . $this->table_name . "
" .$this->prx. $this->table_name . "
SET
filename = :filename,
title = :title";
}else if($this->operation=="edit"){
$query = "UPDATE
" . $this->table_name . "
" .$this->prx. $this->table_name . "
SET
filename = :filename,
title = :title
Expand Down Expand Up @@ -239,7 +240,7 @@ function showError($stmt){
function update(){
// insert query
$query = "UPDATE
" . $this->table_name . "
" .$this->prx. $this->table_name . "
SET
title = :title
WHERE
Expand Down Expand Up @@ -268,7 +269,7 @@ function update(){
// delete the file
function delete(){

$query = "DELETE FROM " . $this->table_name . " WHERE id = ?";
$query = "DELETE FROM " .$this->prx. $this->table_name . " WHERE id = ?";

$stmt = $this->conn->prepare($query);
$stmt->bindParam(1, $this->id);
Expand All @@ -283,7 +284,7 @@ function delete(){

function showById(){
$query = "SELECT *
FROM " . $this->table_name . "
FROM " .$this->prx. $this->table_name . "
WHERE id = ?
LIMIT 0,1";

Expand Down
7 changes: 4 additions & 3 deletions admin/class/Home.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class Home{

public $id;
public $name_function;
public $prx;


// constructor
Expand All @@ -19,7 +20,7 @@ public function __construct($db){
function create(){
// insert query
$query = "INSERT INTO
" . $this->table_name . "
" .$this->prx. $this->table_name . "
SET
name_function = :name_function";

Expand Down Expand Up @@ -55,7 +56,7 @@ function showAll(){
$query = "SELECT
*
FROM
" . $this->table_name . "
" .$this->prx. $this->table_name . "
ORDER BY
id";

Expand All @@ -69,7 +70,7 @@ function showAll(){

function delete(){

$query = "DELETE FROM " . $this->table_name . " WHERE name_function = :name_function";
$query = "DELETE FROM " .$this->prx. $this->table_name . " WHERE name_function = :name_function";

$stmt = $this->conn->prepare($query);
$stmt->bindParam(':name_function', $this->name_function);
Expand Down
31 changes: 16 additions & 15 deletions admin/class/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Menu{
public $itemorder;
public $parent;
public $childof;
public $prx;

// constructor
public function __construct($db){
Expand All @@ -21,7 +22,7 @@ public function __construct($db){

// create new role record
function insert(){
$query="INSERT INTO menu SET pagename = :page_name";
$query="INSERT INTO ".$this->prx."menu SET pagename = :page_name";
$stmt = $this->conn->prepare($query);
$stmt->bindParam(':page_name', $this->pagename);
if($stmt->execute()){
Expand All @@ -42,7 +43,7 @@ function showError($stmt){

function update(){
$query = "UPDATE
" . $this->table_name . "
" .$this->prx.$this->table_name . "
SET
inmenu = :inmenu,
itemorder = :itemorder,
Expand Down Expand Up @@ -83,7 +84,7 @@ function showAll(){
$query = "SELECT
*
FROM
" . $this->table_name . "
" .$this->prx. $this->table_name . "
ORDER BY
itemorder";

Expand All @@ -98,7 +99,7 @@ function showAllParent(){
$query = "SELECT
*
FROM
" . $this->table_name . "
" .$this->prx. $this->table_name . "
WHERE
parent = 1 AND inmenu = 1
ORDER BY
Expand All @@ -114,7 +115,7 @@ function showOrder(){
$query = "SELECT
*
FROM
" . $this->table_name . "
" .$this->prx. $this->table_name . "
WHERE
id = :id";

Expand All @@ -130,7 +131,7 @@ function showAllChildInMenu(){
$query = "SELECT
*
FROM
" . $this->table_name . "
" .$this->prx. $this->table_name . "
WHERE
childof = :childof AND inmenu = 1 AND parent = 0
ORDER BY
Expand All @@ -147,7 +148,7 @@ function showAllChildNone(){
$query = "SELECT
*
FROM
" . $this->table_name . "
" .$this->prx. $this->table_name . "
WHERE
childof = 'none' AND inmenu = 1 AND parent = 0
ORDER BY
Expand All @@ -165,7 +166,7 @@ public function countChild(){
$query = "SELECT
id
FROM
menu
".$this->prx."menu
WHERE childof = :childof";

$stmt = $this->conn->prepare( $query );
Expand All @@ -184,7 +185,7 @@ public function countChildInMenu(){
$query = "SELECT
id
FROM
menu
".$this->prx."menu
WHERE childof = :childof and inmenu = 1";

$stmt = $this->conn->prepare( $query );
Expand All @@ -204,7 +205,7 @@ function showAllNotInMenu(){
$query = "SELECT
*
FROM
" . $this->table_name . "
" .$this->prx. $this->table_name . "
WHERE
inmenu = 0
ORDER BY
Expand All @@ -226,7 +227,7 @@ function showMenu(){
$query = "SELECT
*
FROM
menu
".$this->prx."menu
WHERE
inmenu = 1 ORDER BY itemorder ASC";

Expand All @@ -239,7 +240,7 @@ function showMenu(){

public function countAll(){

$query = "SELECT id FROM menu";
$query = "SELECT id FROM ".$this->prx."menu";

$stmt = $this->conn->prepare( $query );
$stmt->execute();
Expand All @@ -251,7 +252,7 @@ public function countAll(){

function showById(){
$query = "SELECT *
FROM " . $this->table_name . "
FROM " .$this->prx. $this->table_name . "
WHERE id = ?
LIMIT 0,1";

Expand All @@ -272,7 +273,7 @@ function showById(){

function showByName(){
$query = "SELECT *
FROM " . $this->table_name . "
FROM " .$this->prx. $this->table_name . "
WHERE pagename = :pagename
LIMIT 0,1";

Expand All @@ -298,7 +299,7 @@ function showByName(){
function delete(){


$query = "DELETE FROM menu WHERE pagename = :pagename";
$query = "DELETE FROM ".$this->prx."menu WHERE pagename = :pagename";

$stmt = $this->conn->prepare($query);
$stmt->bindParam(":pagename",$this->pagename);
Expand Down
Loading

0 comments on commit 7e82551

Please sign in to comment.