refactoring of table database, added script for upgrading to versions >= 2.0, added multi-user support
Signed-off-by: giandonato.inverso@edempg.it <giandonato.inverso@studenti.unimi.it>
This commit is contained in:
committed by
giandonato.inverso@edempg.it
parent
e36c26a37a
commit
876b6736b6
@@ -13,8 +13,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST')
|
||||
// Get DB instance.
|
||||
$db = getDbInstance();
|
||||
|
||||
$db->where('user_name', $username);
|
||||
$row = $db->getOne('admin_accounts');
|
||||
$db->where('username', $username);
|
||||
$row = $db->getOne('users');
|
||||
|
||||
if ($db->count >= 1)
|
||||
{
|
||||
@@ -24,7 +24,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST')
|
||||
if (password_verify($password, $db_password))
|
||||
{
|
||||
$_SESSION['user_logged_in'] = TRUE;
|
||||
$_SESSION['admin_type'] = $row['admin_type'];
|
||||
$_SESSION['type'] = $row['type'];
|
||||
$_SESSION['user_id'] = $row['id'];
|
||||
|
||||
if ($remember)
|
||||
@@ -47,7 +47,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST')
|
||||
'remember_token' => $encryted_remember_token,
|
||||
'expires' =>$expiry_time
|
||||
);
|
||||
$db->update('admin_accounts', $update_remember);
|
||||
$db->update('users', $update_remember);
|
||||
}
|
||||
// Authentication successfull redirect user
|
||||
header('Location: index.php');
|
||||
|
||||
@@ -22,6 +22,7 @@ if($_SERVER["REQUEST_METHOD"] === "POST" && isset($_POST["edit"])) {
|
||||
isset($_POST["filename"]) &&
|
||||
isset($_POST["link"]) &&
|
||||
isset($_POST["state"]) &&
|
||||
isset($_POST["id_owner"]) &&
|
||||
isset($_POST["id"])
|
||||
)
|
||||
$dynamic_qrcode_instance->editQrcode($_POST);
|
||||
@@ -33,7 +34,8 @@ if($_SERVER["REQUEST_METHOD"] === "POST" && !isset($_POST["edit"])) {
|
||||
isset($_POST["background"]) &&
|
||||
isset($_POST["link"]) &&
|
||||
isset($_POST["filename"]) &&
|
||||
isset($_POST["format"])
|
||||
isset($_POST["format"]) &&
|
||||
isset($_POST["id_owner"])
|
||||
)
|
||||
$dynamic_qrcode_instance->addQrcode($_POST);
|
||||
}
|
||||
|
||||
@@ -7,11 +7,17 @@ require_once BASE_PATH . '/lib/DynamicQrcode/DynamicQrcode.php';
|
||||
$db = getDbInstance();
|
||||
$dynamic_qrcode = new DynamicQrcode();
|
||||
|
||||
$select = array('id', 'filename', 'identifier', 'link', 'qrcode', 'scan', 'state', 'created_at', 'updated_at');
|
||||
$select = array('id', 'id_owner', 'filename', 'identifier', 'link', 'qrcode', 'scan', 'state', 'created_at', 'updated_at');
|
||||
$search_fields = array('filename', 'identifier', 'link');
|
||||
require_once BASE_PATH . '/includes/search_order.php';
|
||||
$page = filter_input(INPUT_GET, 'page', FILTER_SANITIZE_FULL_SPECIAL_CHARS) ?? 1;
|
||||
$db->pageLimit = 15;
|
||||
|
||||
if($_SESSION['type'] !== 'super') {
|
||||
$db->where("id_owner", $_SESSION['user_id']);
|
||||
$db->orWhere ("id_owner", NULL, 'IS');
|
||||
}
|
||||
|
||||
$rows = $db->arraybuilder()->paginate('dynamic_qrcodes', $page, $select);
|
||||
$total_pages = $db->totalPages;
|
||||
?>
|
||||
|
||||
@@ -86,7 +86,7 @@
|
||||
<div class="col-6 col-md-1">
|
||||
<label for="format">Format *</label>
|
||||
<select name="format" class="form-control" required="required">
|
||||
<option value="png" selected >PNG</option>
|
||||
<option value="png" selected>PNG</option>
|
||||
<option value="gif">GIF</option>
|
||||
<option value="jpeg">JPEG</option>
|
||||
<option value="jpg">JPG</option>
|
||||
@@ -96,4 +96,29 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if($_SESSION['type'] === 'super') { ?>
|
||||
<div class="col-sm-12 mb-2">
|
||||
<div class="row">
|
||||
<div class="col-sm-4">
|
||||
<div class="form-group">
|
||||
<label for="id_owner">Owner *</label>
|
||||
<select name="id_owner" class="form-control">
|
||||
<option value="" selected>All</option>
|
||||
<?php
|
||||
|
||||
require_once BASE_PATH . '/lib/Users/Users.php';
|
||||
$users_instance = new Users();
|
||||
$users = $users_instance->getAllUsers();
|
||||
|
||||
foreach ($users as $user) {
|
||||
?>
|
||||
<option value="<?php echo $user["id"];?>"><?php echo $user["username"];?></option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</fieldset>
|
||||
|
||||
@@ -34,6 +34,32 @@
|
||||
<input type="radio" name="state" value="disable" <?php echo ($edit && $dynamic_qrcode['state'] =='disable')? "checked": "" ; ?> required="required" id="disable"/> Disable</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if($_SESSION['type'] === 'super') { ?>
|
||||
<div class="col-sm-4">
|
||||
<div class="form-group">
|
||||
<label for="id_owner">Owner *</label>
|
||||
<select name="id_owner" class="form-control" required="required">
|
||||
<?php
|
||||
require_once BASE_PATH . '/lib/Users/Users.php';
|
||||
$users_instance = new Users();
|
||||
|
||||
if(isset($dynamic_qrcode['id_owner'])) {
|
||||
$owner = $users_instance->getUser($dynamic_qrcode['id_owner']);
|
||||
echo "<option selected value=\"" . $owner["id"] . "\">" . $owner["username"] . "</option>";
|
||||
}
|
||||
|
||||
$users = $users_instance->getAllUsers();
|
||||
foreach ($users as $user) {
|
||||
?>
|
||||
<option value="<?php echo $user["id"];?>"><?php echo $user["username"];?></option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
|
||||
<input type="hidden" name="id" value="<?php echo $dynamic_qrcode['id'];?>"/>
|
||||
<input type="hidden" name="edit" value="true"/>
|
||||
<input type="hidden" name="old_filename" value="<?php echo $dynamic_qrcode['filename'];?>"/>
|
||||
|
||||
@@ -7,6 +7,32 @@
|
||||
<input type="text" name="filename" value="<?php echo htmlspecialchars($edit ? $static_qrcode['filename'] : '', ENT_QUOTES, 'UTF-8'); ?>" placeholder="Filename" class="form-control" required="required" id = "filename">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if($_SESSION['type'] === 'super') { ?>
|
||||
<div class="col-sm-4">
|
||||
<div class="form-group">
|
||||
<label for="id_owner">Owner *</label>
|
||||
<select name="id_owner" class="form-control" required="required">
|
||||
<?php
|
||||
require_once BASE_PATH . '/lib/Users/Users.php';
|
||||
$users_instance = new Users();
|
||||
|
||||
if(isset($static_qrcode['id_owner'])) {
|
||||
$owner = $users_instance->getUser($static_qrcode['id_owner']);
|
||||
echo "<option selected value=\"" . $owner["id"] . "\">" . $owner["username"] . "</option>";
|
||||
echo "<option value=\"\">All</option>";
|
||||
}
|
||||
|
||||
$users = $users_instance->getAllUsers();
|
||||
foreach ($users as $user) {
|
||||
?>
|
||||
<option value="<?php echo $user["id"];?>"><?php echo $user["username"];?></option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<input type="hidden" name="id" value="<?php echo $static_qrcode['id'];?>"/>
|
||||
<input type="hidden" name="edit" value="true"/>
|
||||
<input type="hidden" name="old_filename" value="<?php echo $static_qrcode['filename'];?>"/>
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<span class="input-group-text"><i class="fa fa-user"></i></span>
|
||||
</div>
|
||||
|
||||
<input type="text" name="user_name" placeholder="Username" class="form-control" required="required" value="<?php echo ($edit) ? $user['user_name'] : ''; ?>" autocomplete="off">
|
||||
<input type="text" name="username" placeholder="Username" class="form-control" required="required" value="<?php echo ($edit) ? $user['username'] : ''; ?>" autocomplete="off">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -31,12 +31,12 @@
|
||||
<div class="form-group">
|
||||
<div class="radio">
|
||||
<label class="radio">
|
||||
<input type="radio" name="admin_type" value="super" required="required" <?php echo ($edit && $user['admin_type'] =='super') ? "checked": "" ; ?>/> Super admin</label>
|
||||
<input type="radio" name="type" value="super" required="required" <?php echo ($edit && $user['type'] =='super') ? "checked": "" ; ?>/> Super admin</label>
|
||||
</div>
|
||||
|
||||
<div class="radio">
|
||||
<label class="radio">
|
||||
<input type="radio" name="admin_type" value="admin" required="required" <?php echo ($edit && $user['admin_type'] =='admin') ? "checked": "" ; ?>/> Admin</label>
|
||||
<input type="radio" name="type" value="admin" required="required" <?php echo ($edit && $user['type'] =='admin') ? "checked": "" ; ?>/> Admin</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -80,4 +80,29 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if($_SESSION['type'] === 'super') { ?>
|
||||
<div class="col-sm-12 mb-2">
|
||||
<div class="row">
|
||||
<div class="col-sm-4">
|
||||
<div class="form-group">
|
||||
<label for="id_owner">Owner *</label>
|
||||
<select name="id_owner" class="form-control">
|
||||
<option value="" selected>All</option>
|
||||
<?php
|
||||
|
||||
require_once BASE_PATH . '/lib/Users/Users.php';
|
||||
$users_instance = new Users();
|
||||
$users = $users_instance->getAllUsers();
|
||||
|
||||
foreach ($users as $user) {
|
||||
?>
|
||||
<option value="<?php echo $user["id"];?>"><?php echo $user["username"];?></option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<br>
|
||||
@@ -16,6 +16,7 @@
|
||||
<tr>
|
||||
<th><input type="checkbox" name="bulk-select" value="1"></th>
|
||||
<th>ID</th>
|
||||
<th>Owner</th>
|
||||
<th>Filename</th>
|
||||
<th>Unique redirect identifier</th>
|
||||
<th>URL</th>
|
||||
@@ -30,6 +31,21 @@
|
||||
<tr>
|
||||
<td><input type="checkbox" name="action[]" value="<?=$row['id']?>" onchange="updateBulkActionVisibility()"></td>
|
||||
<td><?php echo $row['id']; ?></td>
|
||||
<td>
|
||||
<?php
|
||||
if(!isset($row['id_owner']))
|
||||
echo "";
|
||||
else {
|
||||
require_once BASE_PATH . '/lib/Users/Users.php';
|
||||
$users = new Users();
|
||||
$user = $users->getUser($row['id_owner']);
|
||||
if($user !== NULL)
|
||||
echo $user["username"];
|
||||
else
|
||||
echo "";
|
||||
}
|
||||
?>
|
||||
</td>
|
||||
<td><?php echo htmlspecialchars($row['filename']); ?></td>
|
||||
<td><?php echo htmlspecialchars($row['identifier']); ?></td>
|
||||
<td><?php echo htmlspecialchars($row['link']); ?></td>
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
<tr>
|
||||
<th><input type="checkbox" name="bulk-select" value="1"></th>
|
||||
<th>ID</th>
|
||||
<th>Owner</th>
|
||||
<th>Filename</th>
|
||||
<th>Type</th>
|
||||
<th>Content</th>
|
||||
@@ -28,6 +29,21 @@
|
||||
<tr>
|
||||
<td><input type="checkbox" name="action[]" value="<?=$row['id']?>" onchange="updateBulkActionVisibility()"></td>
|
||||
<td><?php echo $row['id']; ?></td>
|
||||
<td>
|
||||
<?php
|
||||
if(!isset($row['id_owner']))
|
||||
echo "";
|
||||
else {
|
||||
require_once BASE_PATH . '/lib/Users/Users.php';
|
||||
$users = new Users();
|
||||
$user = $users->getUser($row['id_owner']);
|
||||
if($user !== NULL)
|
||||
echo $user["username"];
|
||||
else
|
||||
echo "";
|
||||
}
|
||||
?>
|
||||
</td>
|
||||
<td><?php echo htmlspecialchars($row['filename']); ?></td>
|
||||
<td><?php echo htmlspecialchars($row['type']); ?></td>
|
||||
<td><?php echo $row['content']; ?></td>
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<tr>
|
||||
<th width="5%">ID</th>
|
||||
<th width="45%">Username</th>
|
||||
<th width="40%">Admin type</th>
|
||||
<th width="40%">Type</th>
|
||||
<th width="10%">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@@ -15,11 +15,11 @@
|
||||
<?php foreach ($rows as $row): ?>
|
||||
<tr>
|
||||
<td><?php echo $row['id']; ?></td>
|
||||
<td><?php echo htmlspecialchars($row['user_name']); ?></td>
|
||||
<td><?php echo htmlspecialchars($row['admin_type']); ?></td>
|
||||
<td><?php echo htmlspecialchars($row['username']); ?></td>
|
||||
<td><?php echo htmlspecialchars($row['type']); ?></td>
|
||||
<td>
|
||||
<!-- EDIT -->
|
||||
<a href="admin_user.php?edit=true&id=<?php echo $row['id']; ?>" class="btn btn-primary"><i class="fas fa-edit"></i></a>
|
||||
<a href="user.php?edit=true&id=<?php echo $row['id']; ?>" class="btn btn-primary"><i class="fas fa-edit"></i></a>
|
||||
|
||||
<!-- DELETE -->
|
||||
<a
|
||||
@@ -36,7 +36,7 @@
|
||||
</div><!-- /.Card body -->
|
||||
|
||||
<div class="card-footer clearfix">
|
||||
<?php echo paginationLinks($page, $total_pages, 'admin_users.php'); ?>
|
||||
<?php echo paginationLinks($page, $total_pages, 'users.php'); ?>
|
||||
</div><!-- /.Card footer -->
|
||||
|
||||
</div><!-- /.Card -->
|
||||
@@ -46,7 +46,7 @@
|
||||
<!-- Delete Confirmation Modal -->
|
||||
<div class="modal fade" id="delete-modal" role="dialog">
|
||||
<div class="modal-dialog">
|
||||
<form action="admin_user.php" method="POST">
|
||||
<form action="user.php" method="POST">
|
||||
<!-- Modal content -->
|
||||
|
||||
<div class="modal-content">
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<strong>Copyright © <?php echo date("Y");?> <a href="#">PHP Qrcode Generator</a> - </strong>
|
||||
All rights reserved by Giandonato Inverso.
|
||||
<div class="float-right d-none d-sm-inline-block">
|
||||
<b>Version</b> 2.0.0
|
||||
<b>Version</b> 2.1.0
|
||||
</div>
|
||||
</footer>
|
||||
</div>
|
||||
|
||||
@@ -80,7 +80,7 @@
|
||||
</ul>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a href="./admin_users.php" <?php echo ((substr(CURRENT_PAGE, 0, 15) == 'admin_users.php') || (substr(CURRENT_PAGE, 0, 14) == 'admin_user.php')) ? ' class="nav-link active"' : ' class="nav-link"'; ?>>
|
||||
<a href="./users.php" <?php echo ((substr(CURRENT_PAGE, 0, 15) == 'users.php') || (substr(CURRENT_PAGE, 0, 14) == 'user.php')) ? ' class="nav-link active"' : ' class="nav-link"'; ?>>
|
||||
<i class="fas fa-users nav-icon"></i>
|
||||
<p>Users</p>
|
||||
</a>
|
||||
|
||||
+20
-2
@@ -6,21 +6,36 @@ require_once 'includes/auth_validate.php';
|
||||
$db = getDbInstance();
|
||||
|
||||
//Get Dynamic qr code rows
|
||||
if($_SESSION['type'] !== 'super') {
|
||||
$db->where("id_owner", $_SESSION['user_id']);
|
||||
$db->orWhere ("id_owner", NULL, 'IS');
|
||||
}
|
||||
$numQrcode_dynamic = $db->getValue("dynamic_qrcodes", "count(*)");
|
||||
|
||||
//Get Static qr code rows
|
||||
if($_SESSION['type'] !== 'super') {
|
||||
$db->where("id_owner", $_SESSION['user_id']);
|
||||
$db->orWhere ("id_owner", NULL, 'IS');
|
||||
}
|
||||
$numQrcode_static = $db->getValue("static_qrcodes", "count(*)");
|
||||
|
||||
$total = $numQrcode_dynamic + $numQrcode_static;
|
||||
|
||||
//Get Total scan
|
||||
if($_SESSION['type'] !== 'super') {
|
||||
$db->where("id_owner", $_SESSION['user_id']);
|
||||
$db->orWhere ("id_owner", NULL, 'IS');
|
||||
}
|
||||
$numScan = $db->getOne(DATABASE_PREFIX."dynamic_qrcodes", "sum(scan) as numScan");
|
||||
|
||||
/* CREATED CHART */
|
||||
//I initialize the variables that will contain the daily values to 0 otherwise in the foreach loop they will be reset every time
|
||||
|
||||
//Get the number of DYNAMIC qr code created in 7 days and total scan
|
||||
$createdQrcode_dynamic = $db->query("select `created_at`, `scan` from ".DATABASE_PREFIX."dynamic_qrcodes where `created_at` > curdate()-7;");
|
||||
if($_SESSION['type'] !== 'super')
|
||||
$createdQrcode_dynamic = $db->query("select `created_at`, `scan` from " . DATABASE_PREFIX . "dynamic_qrcodes where `created_at` > curdate()-7 AND (`id_owner`=" . $_SESSION['user_id'] . " OR `id_owner` IS NULL);");
|
||||
else
|
||||
$createdQrcode_dynamic = $db->query("select `created_at`, `scan` from ".DATABASE_PREFIX."dynamic_qrcodes where `created_at` > curdate()-7;");
|
||||
|
||||
|
||||
$dynamic_today = $dynamic_oneday = $dynamic_twoday = $dynamic_threeday = $dynamic_fourday = $dynamic_fiveday = $dynamic_sixday = 0;
|
||||
@@ -40,7 +55,10 @@ foreach ($createdQrcode_dynamic as $row) {
|
||||
|
||||
/* SCAN CHART */
|
||||
//Get the number of STATIC qr code created in 7 days
|
||||
$createdQrcode_static = $db->query("select `created_at` from ".DATABASE_PREFIX."static_qrcodes where `created_at` > curdate()-7;");
|
||||
if($_SESSION['type'] !== 'super')
|
||||
$createdQrcode_static = $db->query("select `created_at` from " . DATABASE_PREFIX . "static_qrcodes where `created_at` > curdate()-7 AND (`id_owner`=" . $_SESSION['user_id'] . " OR `id_owner` IS NULL);");
|
||||
else
|
||||
$createdQrcode_static = $db->query("select `created_at` from ".DATABASE_PREFIX."static_qrcodes where `created_at` > curdate()-7;");
|
||||
|
||||
$static_today = $static_oneday = $static_twoday = $static_threeday = $static_fourday = $static_fiveday = $static_sixday = 0;
|
||||
foreach ($createdQrcode_static as $row) {
|
||||
|
||||
@@ -1,14 +1,4 @@
|
||||
<?php
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
|
||||
class Database {
|
||||
|
||||
// Function to the database and tables and fill them with the default data
|
||||
|
||||
@@ -1,14 +1,4 @@
|
||||
<?php
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
|
||||
require_once ('../config/environment.php');
|
||||
require_once('includes/database_class.php');
|
||||
|
||||
|
||||
@@ -1,58 +1,29 @@
|
||||
-- phpMyAdmin SQL Dump
|
||||
-- version 3.5.8.2
|
||||
-- http://www.phpmyadmin.net
|
||||
--
|
||||
-- Host: 89.46.111.192
|
||||
-- Generato il: Set 01, 2020 alle 17:55
|
||||
-- Versione del server: 5.7.29-32-log
|
||||
-- Versione PHP: 5.3.8
|
||||
|
||||
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
|
||||
SET time_zone = "+00:00";
|
||||
|
||||
|
||||
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
|
||||
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
|
||||
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
|
||||
/*!40101 SET NAMES utf8 */;
|
||||
|
||||
--
|
||||
-- Database: `Sql1431296_1`
|
||||
--
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- Struttura della tabella `admin_accounts`
|
||||
--
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `#prefix#admin_accounts` (
|
||||
CREATE TABLE IF NOT EXISTS `#prefix#users` (
|
||||
`id` int(25) NOT NULL AUTO_INCREMENT,
|
||||
`user_name` varchar(50) NOT NULL,
|
||||
`username` varchar(50) NOT NULL,
|
||||
`password` varchar(255) NOT NULL,
|
||||
`series_id` varchar(60) DEFAULT NULL,
|
||||
`remember_token` varchar(255) DEFAULT NULL,
|
||||
`expires` datetime DEFAULT NULL,
|
||||
`admin_type` varchar(10) NOT NULL,
|
||||
`type` varchar(10) NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `user_name` (`user_name`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=14 ;
|
||||
UNIQUE KEY `username` (`username`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=0 ;
|
||||
|
||||
--
|
||||
-- Dump dei dati per la tabella `admin_accounts`
|
||||
--
|
||||
|
||||
INSERT INTO `#prefix#admin_accounts` (`id`, `user_name`, `password`, `series_id`, `remember_token`, `expires`, `admin_type`) VALUES
|
||||
INSERT INTO `#prefix#users` (`id`, `username`, `password`, `series_id`, `remember_token`, `expires`, `type`) VALUES
|
||||
(1, 'superadmin', '$2y$10$xpZc5KC.aU2XHkcqhuZGFuAnqmtL4Unt8MysOyylceq.19XIyoZpG', 'F5V8N81eQKYJbiyj', '$2y$10$MRWA31CVjAmtrojbm4r18ezDfqC3msAxzJ1ZdbyoRpD5pxF3IdJG6', '2020-09-30 16:19:08', 'super');
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- Struttura della tabella `dynamic_qrcodes`
|
||||
--
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `#prefix#dynamic_qrcodes` (
|
||||
`id` int(10) NOT NULL AUTO_INCREMENT,
|
||||
`id_owner` int(25) NOT NULL AUTO_INCREMENT,
|
||||
`filename` varchar(45) NOT NULL,
|
||||
`format` varchar(45) DEFAULT NULL,
|
||||
`identifier` longtext,
|
||||
@@ -65,28 +36,19 @@ CREATE TABLE IF NOT EXISTS `#prefix#dynamic_qrcodes` (
|
||||
`updated_by` int(10) unsigned NOT NULL DEFAULT '0',
|
||||
`updated_at` timestamp NULL DEFAULT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=221 ;
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=0 ;
|
||||
|
||||
--
|
||||
-- Dump dei dati per la tabella `dynamic_qrcodes`
|
||||
--
|
||||
|
||||
INSERT INTO `#prefix#dynamic_qrcodes` (`id`, `filename`, `format`, `identifier`, `link`, `qrcode`, `scan`, `state`, `created_by`, `created_at`, `updated_by`, `updated_at`) VALUES
|
||||
(1, 'Facebook', 'png', 'rcCeC', 'https://facebook.com', 'Facebook.png', 0, 'enable', 0, '2020-09-01 15:35:13', 0, NULL),
|
||||
(2, 'Amazon', 'png', 'F7GOY6', 'https://amazon.com', 'Amazon.png', 0, 'enable', 0, '2020-09-01 15:40:34', 0, NULL),
|
||||
(3, 'Youtube', 'png', '8dK5Nd', 'https://youtube.com', 'Youtube.png', 0, 'enable', 0, '2020-09-01 15:41:43', 0, NULL),
|
||||
(4, 'Apple', 'jpg', '7zxTKn', 'https://apple.com', 'Apple.jpg', 0, 'enable', 0, '2020-09-01 15:44:20', 0, NULL),
|
||||
(5, 'Ebay', 'svg', 'a4F3kr', 'https://ebay.com', 'Ebay.svg', 0, 'enable', 0, '2020-09-01 15:44:46', 0, NULL),
|
||||
(6, 'Google', 'png', 'saJV1y', 'https://google.it', 'Google.png', 0, 'enable', 0, '2020-09-01 15:46:37', 0, NULL);
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- Struttura della tabella `static_qrcodes`
|
||||
--
|
||||
INSERT INTO `#prefix#dynamic_qrcodes` (`id`, `id_owner`, `filename`, `format`, `identifier`, `link`, `qrcode`, `scan`, `state`, `created_by`, `created_at`, `updated_by`, `updated_at`) VALUES
|
||||
(1, 0, 'Facebook', 'png', 'rcCeC', 'https://facebook.com', 'Facebook.png', 0, 'enable', 0, '2020-09-01 15:35:13', 0, NULL),
|
||||
(2, 0, 'Amazon', 'png', 'F7GOY6', 'https://amazon.com', 'Amazon.png', 0, 'enable', 0, '2020-09-01 15:40:34', 0, NULL),
|
||||
(3, 0, 'Youtube', 'png', '8dK5Nd', 'https://youtube.com', 'Youtube.png', 0, 'enable', 0, '2020-09-01 15:41:43', 0, NULL),
|
||||
(4, 0, 'Apple', 'jpg', '7zxTKn', 'https://apple.com', 'Apple.jpg', 0, 'enable', 0, '2020-09-01 15:44:20', 0, NULL),
|
||||
(5, 0, 'Ebay', 'svg', 'a4F3kr', 'https://ebay.com', 'Ebay.svg', 0, 'enable', 0, '2020-09-01 15:44:46', 0, NULL),
|
||||
(6, 0, 'Google', 'png', 'saJV1y', 'https://google.it', 'Google.png', 0, 'enable', 0, '2020-09-01 15:46:37', 0, NULL);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `#prefix#static_qrcodes` (
|
||||
`id` int(10) NOT NULL AUTO_INCREMENT,
|
||||
`id_owner` int(25) NOT NULL AUTO_INCREMENT,
|
||||
`filename` varchar(45) CHARACTER SET utf8 NOT NULL,
|
||||
`format` varchar(45) DEFAULT NULL,
|
||||
`type` varchar(45) CHARACTER SET utf8 DEFAULT NULL,
|
||||
@@ -98,25 +60,21 @@ CREATE TABLE IF NOT EXISTS `#prefix#static_qrcodes` (
|
||||
`updated_by` int(10) unsigned NOT NULL DEFAULT '0',
|
||||
`updated_at` timestamp NULL DEFAULT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=87 ;
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=0 ;
|
||||
|
||||
--
|
||||
-- Dump dei dati per la tabella `static_qrcodes`
|
||||
--
|
||||
|
||||
INSERT INTO `#prefix#static_qrcodes` (`id`, `filename`, `format`, `type`, `content`, `qrcode`, `state`, `created_by`, `created_at`, `updated_by`, `updated_at`) VALUES
|
||||
(1, 'Text qr code', 'png', 'text', '<strong>Text:</strong> My first text', 'Text qr code.png', 'enable', 0, '2020-08-24 08:41:31', 0, NULL),
|
||||
(2, 'Email', 'jpg', 'email', '<strong>Email:</strong> assistance@domain.com<br><strong>Subject:</strong> Assistance request<br><strong>Message:</strong> Regarding my order N ° ... I require assistance', 'Email.jpg', 'enable', 0, '2020-08-24 08:44:13', 0, NULL),
|
||||
(3, 'Call me', 'png', 'phone', '<strong>Phone number:</strong> 12563776756', 'Call me.png', 'enable', 0, '2020-08-24 08:45:10', 0, NULL),
|
||||
(4, 'Send sms', 'png', 'sms', '<strong>Phone number:</strong> 12563776756<br><strong>Message:</strong> Test message', 'Send sms.png', 'enable', 0, '2020-08-24 08:46:52', 0, NULL),
|
||||
(5, 'wa.me', 'svg', 'whatsapp', '<strong>Phone number:</strong> 12563776756<br><strong>Message:</strong> Hey there! I am using WhatsApp', 'wa.me.svg', 'enable', 0, '2020-08-24 08:47:49', 0, NULL),
|
||||
(6, 'New York', 'png', 'location', '<strong>Latitude:</strong> 40.7127753<br><strong>Longitude:</strong> -74.0059728', 'New York.png', 'enable', 0, '2020-08-24 08:51:55', 0, NULL),
|
||||
(7, 'John Doe', 'png', 'vcard', '<div class="row"><div class="col-sm-4"><strong>Full name:</strong> John Doe<br><strong>Nickname:</strong> John<br><strong>Email:</strong> john@domain.com<br><strong>Website:</strong> https://johndoe.com</div><div class="col-sm-4"><strong>Company:</strong> Doe Inc.<br><strong>Role:</strong> CEO<br><strong>Categories:</strong> electronics, vcard<br><strong>Note:</strong> </div><div class="col-sm-4"><strong>Phone:</strong> 412-999-9988<br><strong>Home Phone:</strong> 412-999-5555<br><strong>Work phone:</strong> 412-444-2222<br><strong>Address:</strong> 123 Main Street Anywhere 15523 Arizona</div></div>', 'John Doe.png', 'enable', 0, '2020-08-24 08:55:59', 0, NULL),
|
||||
(8, 'Boat party', 'png', 'event', '<div class="row"><div class="col-sm-4"><strong>Title:</strong> Party with friends<br><strong>Start event:</strong> 2020-08-26 09:00 AM<br><strong>End event:</strong> 2020-08-26 03:00 PM<br></div><div class="col-sm-4"><strong>Location:</strong> New York<br><strong>Description:</strong> Happy Birthday Carl!<br><strong>URL:</strong> </div></div>', 'Boat party.png', 'enable', 0, '2020-08-24 08:58:20', 0, NULL),
|
||||
(9, 'Save me', 'svg', 'bookmark', '<strong>Title:</strong> Google search<br><strong>Url:</strong> https://google.it', 'Save me.svg', 'enable', 0, '2020-08-24 08:59:46', 0, NULL),
|
||||
(10, 'Free wifi', 'png', 'wifi', '<strong>Encryption:</strong> WPA<br><strong>SSID:</strong> TP-LINK-AB123<br><strong>Password:</strong> bBB8MR7TwbbUWMZT', 'Free wifi.png', 'enable', 0, '2020-08-24 09:02:35', 0, NULL),
|
||||
(11, 'Pay here', 'png', 'paypal', '<div class="row"><div class="col-sm-4"><strong>Payment type:</strong> _click<br><strong>Email:</strong> paypal@domain.com<br><strong>Item name:</strong> T-shirt<br><strong>Item id:</strong> 177</div><div class="col-sm-4"><strong>Amount:</strong> 15<br><strong>Currency:</strong> USD<br><strong>Shipping:</strong> 4<br><strong>Tax rate:</strong> </div></div>', 'Pay here.png', 'enable', 0, '2020-08-24 09:04:13', 0, NULL),
|
||||
(12, 'Send BTC ', 'jpg', 'bitcoin', '<strong>BTC address:</strong> 1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa<br><strong>Amount:</strong> 1<br><strong>Label:</strong> <br><strong>Message:</strong> ', 'Send BTC .jpg', 'enable', 0, '2020-09-01 10:51:08', 0, NULL);
|
||||
INSERT INTO `#prefix#static_qrcodes` (`id`, `id_owner`, `filename`, `format`, `type`, `content`, `qrcode`, `state`, `created_by`, `created_at`, `updated_by`, `updated_at`) VALUES
|
||||
(1, 0, 'Text qr code', 'png', 'text', '<strong>Text:</strong> My first text', 'Text qr code.png', 'enable', 0, '2020-08-24 08:41:31', 0, NULL),
|
||||
(2, 0, 'Email', 'jpg', 'email', '<strong>Email:</strong> assistance@domain.com<br><strong>Subject:</strong> Assistance request<br><strong>Message:</strong> Regarding my order N ° ... I require assistance', 'Email.jpg', 'enable', 0, '2020-08-24 08:44:13', 0, NULL),
|
||||
(3, 0, 'Call me', 'png', 'phone', '<strong>Phone number:</strong> 12563776756', 'Call me.png', 'enable', 0, '2020-08-24 08:45:10', 0, NULL),
|
||||
(4, 0, 'Send sms', 'png', 'sms', '<strong>Phone number:</strong> 12563776756<br><strong>Message:</strong> Test message', 'Send sms.png', 'enable', 0, '2020-08-24 08:46:52', 0, NULL),
|
||||
(5, 0, 'wa.me', 'svg', 'whatsapp', '<strong>Phone number:</strong> 12563776756<br><strong>Message:</strong> Hey there! I am using WhatsApp', 'wa.me.svg', 'enable', 0, '2020-08-24 08:47:49', 0, NULL),
|
||||
(6, 0, 'New York', 'png', 'location', '<strong>Latitude:</strong> 40.7127753<br><strong>Longitude:</strong> -74.0059728', 'New York.png', 'enable', 0, '2020-08-24 08:51:55', 0, NULL),
|
||||
(7, 0, 'John Doe', 'png', 'vcard', '<div class="row"><div class="col-sm-4"><strong>Full name:</strong> John Doe<br><strong>Nickname:</strong> John<br><strong>Email:</strong> john@domain.com<br><strong>Website:</strong> https://johndoe.com</div><div class="col-sm-4"><strong>Company:</strong> Doe Inc.<br><strong>Role:</strong> CEO<br><strong>Categories:</strong> electronics, vcard<br><strong>Note:</strong> </div><div class="col-sm-4"><strong>Phone:</strong> 412-999-9988<br><strong>Home Phone:</strong> 412-999-5555<br><strong>Work phone:</strong> 412-444-2222<br><strong>Address:</strong> 123 Main Street Anywhere 15523 Arizona</div></div>', 'John Doe.png', 'enable', 0, '2020-08-24 08:55:59', 0, NULL),
|
||||
(8, 0, 'Boat party', 'png', 'event', '<div class="row"><div class="col-sm-4"><strong>Title:</strong> Party with friends<br><strong>Start event:</strong> 2020-08-26 09:00 AM<br><strong>End event:</strong> 2020-08-26 03:00 PM<br></div><div class="col-sm-4"><strong>Location:</strong> New York<br><strong>Description:</strong> Happy Birthday Carl!<br><strong>URL:</strong> </div></div>', 'Boat party.png', 'enable', 0, '2020-08-24 08:58:20', 0, NULL),
|
||||
(9, 0, 'Save me', 'svg', 'bookmark', '<strong>Title:</strong> Google search<br><strong>Url:</strong> https://google.it', 'Save me.svg', 'enable', 0, '2020-08-24 08:59:46', 0, NULL),
|
||||
(10, 0, 'Free wifi', 'png', 'wifi', '<strong>Encryption:</strong> WPA<br><strong>SSID:</strong> TP-LINK-AB123<br><strong>Password:</strong> bBB8MR7TwbbUWMZT', 'Free wifi.png', 'enable', 0, '2020-08-24 09:02:35', 0, NULL),
|
||||
(11, 0, 'Pay here', 'png', 'paypal', '<div class="row"><div class="col-sm-4"><strong>Payment type:</strong> _click<br><strong>Email:</strong> paypal@domain.com<br><strong>Item name:</strong> T-shirt<br><strong>Item id:</strong> 177</div><div class="col-sm-4"><strong>Amount:</strong> 15<br><strong>Currency:</strong> USD<br><strong>Shipping:</strong> 4<br><strong>Tax rate:</strong> </div></div>', 'Pay here.png', 'enable', 0, '2020-08-24 09:04:13', 0, NULL),
|
||||
(12, 0, 'Send BTC ', 'jpg', 'bitcoin', '<strong>BTC address:</strong> 1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa<br><strong>Amount:</strong> 1<br><strong>Label:</strong> <br><strong>Message:</strong> ', 'Send BTC .jpg', 'enable', 0, '2020-09-01 10:51:08', 0, NULL);
|
||||
|
||||
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
|
||||
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
|
||||
|
||||
@@ -26,6 +26,7 @@ class DynamicQrcode {
|
||||
{
|
||||
$ordering = [
|
||||
'id' => 'ID',
|
||||
'id_owner' => 'Owner',
|
||||
'filename' => 'File Name',
|
||||
'identifier' => 'Identifier',
|
||||
'link' => 'Link',
|
||||
@@ -48,6 +49,11 @@ class DynamicQrcode {
|
||||
* We save into db the url of qrcode image
|
||||
*/
|
||||
public function addQrcode($input_data) {
|
||||
if($input_data['id_owner'] != "")
|
||||
$data_to_db['id_owner'] = $input_data['id_owner'];
|
||||
else
|
||||
$data_to_db['id_owner'] = NULL;
|
||||
|
||||
$data_to_db['filename'] = htmlspecialchars($input_data['filename'], ENT_QUOTES, 'UTF-8');
|
||||
$data_to_db['created_at'] = date('Y-m-d H:i:s');
|
||||
$data_to_db['link'] = htmlspecialchars($input_data['link'], ENT_QUOTES, 'UTF-8');
|
||||
@@ -66,6 +72,10 @@ class DynamicQrcode {
|
||||
*
|
||||
*/
|
||||
public function editQrcode($input_data) {
|
||||
if($input_data['id_owner'] != "")
|
||||
$data_to_db['id_owner'] = $input_data['id_owner'];
|
||||
else
|
||||
$data_to_db['id_owner'] = NULL;
|
||||
$data_to_db['filename'] = htmlspecialchars($input_data['filename'], ENT_QUOTES, 'UTF-8');
|
||||
$data_to_db['created_at'] = date('Y-m-d H:i:s');
|
||||
$data_to_db['link'] = htmlspecialchars($input_data['link'], ENT_QUOTES, 'UTF-8');
|
||||
@@ -80,10 +90,23 @@ class DynamicQrcode {
|
||||
*
|
||||
*/
|
||||
public function deleteQrcode($id) {
|
||||
if($_SESSION['admin_type'] !== 'super')
|
||||
$this->failure("You don't have permission to perform this action");
|
||||
|
||||
if($_SESSION['type'] === "super") {
|
||||
$this->qrcode_instance->deleteQrcode($id);
|
||||
} else if ($_SESSION['type'] === "admin") {
|
||||
$qrcode = $this->getQrcode($id);
|
||||
|
||||
if(!isset($qrcode["id_owner"]))
|
||||
$this->failure("You cannot delete this qrcode");
|
||||
|
||||
require_once BASE_PATH . '/lib/users/Users.php';
|
||||
$users = new Users();
|
||||
$user = $users->getUser($_SESSION['user_id']);
|
||||
|
||||
if($user["id"] === $qrcode["id_owner"])
|
||||
$this->qrcode_instance->deleteQrcode($id);
|
||||
else
|
||||
$this->failure("You cannot delete this qrcode because it's of another user");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -156,9 +156,6 @@ class Qrcode {
|
||||
*
|
||||
*/
|
||||
public function deleteQrcode($id) {
|
||||
if($_SESSION['admin_type'] !== 'super')
|
||||
$this->failure("You don't have permission to perform this action");
|
||||
|
||||
$db = getDbInstance();
|
||||
|
||||
$qrcode = $this->getQrcode($id);
|
||||
|
||||
@@ -29,6 +29,7 @@ class StaticQrcode {
|
||||
{
|
||||
$ordering = [
|
||||
'id' => 'ID',
|
||||
'id_owner' => 'Owner',
|
||||
'filename' => 'File Name',
|
||||
'type' => 'Type',
|
||||
'content' => 'Content',
|
||||
@@ -343,6 +344,10 @@ class StaticQrcode {
|
||||
* We save into db the url of qrcode image
|
||||
*/
|
||||
private function addQrcode($type) {
|
||||
if($_POST['id_owner'] != "")
|
||||
$data_to_db['id_owner'] = $_POST['id_owner'];
|
||||
else
|
||||
$data_to_db['id_owner'] = NULL;
|
||||
$data_to_db['created_at'] = date('Y-m-d H:i:s');
|
||||
$data_to_db['created_by'] = $_SESSION['user_id'];
|
||||
$data_to_db['filename'] = htmlspecialchars($_POST['filename'], ENT_QUOTES, 'UTF-8');
|
||||
@@ -371,6 +376,10 @@ class StaticQrcode {
|
||||
*
|
||||
*/
|
||||
public function editQrcode($input_data) {
|
||||
if($input_data['id_owner'] != "")
|
||||
$data_to_db['id_owner'] = $input_data['id_owner'];
|
||||
else
|
||||
$data_to_db['id_owner'] = NULL;
|
||||
$data_to_db['filename'] = htmlspecialchars($input_data['filename'], ENT_QUOTES, 'UTF-8');
|
||||
$data_to_db['created_at'] = date('Y-m-d H:i:s');
|
||||
|
||||
@@ -382,10 +391,23 @@ class StaticQrcode {
|
||||
*
|
||||
*/
|
||||
public function deleteQrcode($id) {
|
||||
if($_SESSION['admin_type'] !== 'super')
|
||||
$this->failure("You don't have permission to perform this action");
|
||||
|
||||
if($_SESSION['type'] === "super") {
|
||||
$this->qrcode_instance->deleteQrcode($id);
|
||||
} else if ($_SESSION['type'] === "admin") {
|
||||
$qrcode = $this->getQrcode($id);
|
||||
|
||||
if(!isset($qrcode["id_owner"]))
|
||||
$this->failure("You cannot delete this qrcode");
|
||||
|
||||
require_once BASE_PATH . '/lib/users/Users.php';
|
||||
$users = new Users();
|
||||
$user = $users->getUser($_SESSION['user_id']);
|
||||
|
||||
if($user["id"] === $qrcode["id_owner"])
|
||||
$this->qrcode_instance->deleteQrcode($id);
|
||||
else
|
||||
$this->failure("You cannot delete this qrcode because it's of another user");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+25
-22
@@ -8,8 +8,6 @@ class Users
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
if ($_SESSION['admin_type'] !== 'super')
|
||||
$this->failure('Only a "super admin" account can access the admin listing page', 'Location: index.php');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -26,18 +24,23 @@ class Users
|
||||
{
|
||||
$ordering = [
|
||||
'id' => 'ID',
|
||||
'user_name' => 'Username',
|
||||
'admin_type' => 'Admin Type'
|
||||
'username' => 'Username',
|
||||
'type' => 'Type'
|
||||
];
|
||||
|
||||
return $ordering;
|
||||
}
|
||||
|
||||
public function getAllUsers() {
|
||||
$db = getDbInstance();
|
||||
return $db->get(DATABASE_PREFIX.'users');
|
||||
}
|
||||
|
||||
public function getUser($id) {
|
||||
$db = getDbInstance();
|
||||
|
||||
$db->where('id', $id);
|
||||
$result = $db->getOne(DATABASE_PREFIX.'admin_accounts');
|
||||
$result = $db->getOne(DATABASE_PREFIX.'users');
|
||||
|
||||
if($result !== NULL)
|
||||
return $result;
|
||||
@@ -51,17 +54,17 @@ class Users
|
||||
public function addUser($input_data) {
|
||||
$db = getDbInstance();
|
||||
|
||||
$data_to_db["user_name"] = $input_data["user_name"];
|
||||
$data_to_db["username"] = $input_data["username"];
|
||||
$data_to_db['password'] = password_hash($input_data['password'], PASSWORD_DEFAULT);
|
||||
$data_to_db["admin_type"] = $input_data["admin_type"];
|
||||
$data_to_db["type"] = $input_data["type"];
|
||||
|
||||
$db->where('user_name', $data_to_db['user_name']);
|
||||
$db->get('admin_accounts');
|
||||
$db->where('username', $data_to_db['username']);
|
||||
$db->get('users');
|
||||
|
||||
if ($db->count >= 1)
|
||||
$this->failure('Username already exists');
|
||||
|
||||
$last_id = $db->insert('admin_accounts', $data_to_db);
|
||||
$last_id = $db->insert('users', $data_to_db);
|
||||
|
||||
if ($last_id)
|
||||
$this->success('User added successfully');
|
||||
@@ -74,24 +77,24 @@ class Users
|
||||
public function editUser($input_data) {
|
||||
$db = getDbInstance();
|
||||
|
||||
$db->where('user_name', $input_data['user_name']);
|
||||
$db->where('username', $input_data['username']);
|
||||
$db->where('id', $input_data["id"], '!=');
|
||||
$row = $db->getOne('admin_accounts');
|
||||
$row = $db->getOne('users');
|
||||
|
||||
if (!empty($row['user_name'])) {
|
||||
if (!empty($row['username'])) {
|
||||
$query_string = http_build_query(array(
|
||||
'id' => $input_data["id"],
|
||||
'edit' => "true",
|
||||
));
|
||||
$this->failure('Username already exists', 'Location: admin_user.php?'.$query_string);
|
||||
$this->failure('Username already exists', 'Location: user.php?'.$query_string);
|
||||
}
|
||||
|
||||
$data_to_db["user_name"] = $input_data["user_name"];
|
||||
$data_to_db["username"] = $input_data["username"];
|
||||
$data_to_db['password'] = password_hash($input_data['password'], PASSWORD_DEFAULT);
|
||||
$data_to_db["admin_type"] = $input_data["admin_type"];
|
||||
$data_to_db["type"] = $input_data["type"];
|
||||
|
||||
$db->where('id', $input_data["id"]);
|
||||
$stat = $db->update('admin_accounts', $data_to_db);
|
||||
$stat = $db->update('users', $data_to_db);
|
||||
|
||||
if ($stat)
|
||||
$this->success('User updated successfully!');
|
||||
@@ -104,14 +107,14 @@ class Users
|
||||
*
|
||||
*/
|
||||
public function deleteUser($id) {
|
||||
if($_SESSION['admin_type']!='super'){
|
||||
if($_SESSION['type']!='super'){
|
||||
header('HTTP/1.1 401 Unauthorized', true, 401);
|
||||
exit("401 Unauthorized");
|
||||
}
|
||||
|
||||
$db = getDbInstance();
|
||||
$db->where('id', $id);
|
||||
$stat = $db->delete('admin_accounts');
|
||||
$stat = $db->delete('users');
|
||||
|
||||
if ($stat)
|
||||
$this->info('User deleted successfully!');
|
||||
@@ -122,7 +125,7 @@ class Users
|
||||
/**
|
||||
* Flash message Failure process
|
||||
*/
|
||||
public function failure($message, $location = 'Location: admin_users.php') {
|
||||
public function failure($message, $location = 'Location: users.php') {
|
||||
$_SESSION['failure'] = $message;
|
||||
header($location);
|
||||
exit();
|
||||
@@ -133,7 +136,7 @@ class Users
|
||||
*/
|
||||
public function success($message) {
|
||||
$_SESSION['success'] = $message;
|
||||
header('Location: admin_users.php');
|
||||
header('Location: users.php');
|
||||
exit();
|
||||
}
|
||||
|
||||
@@ -142,7 +145,7 @@ class Users
|
||||
*/
|
||||
public function info($message) {
|
||||
$_SESSION['info'] = $message;
|
||||
header('Location: admin_users.php');
|
||||
header('Location: users.php');
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -18,7 +18,7 @@ if (isset($_COOKIE['series_id']) && isset($_COOKIE['remember_token']))
|
||||
$db = getDbInstance();
|
||||
// Get user By series ID:
|
||||
$db->where('series_id', $series_id);
|
||||
$row = $db->getOne('admin_accounts');
|
||||
$row = $db->getOne('users');
|
||||
|
||||
if ($db->count >= 1)
|
||||
{
|
||||
@@ -37,7 +37,7 @@ if (isset($_COOKIE['series_id']) && isset($_COOKIE['remember_token']))
|
||||
}
|
||||
|
||||
$_SESSION['user_logged_in'] = TRUE;
|
||||
$_SESSION['admin_type'] = $row['admin_type'];
|
||||
$_SESSION['type'] = $row['type'];
|
||||
header('Location: index.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ if($_SERVER["REQUEST_METHOD"] === "POST" && isset($_POST["del_id"])) {
|
||||
if($_SERVER["REQUEST_METHOD"] === "POST" && isset($_POST["edit"])) {
|
||||
if(
|
||||
isset($_POST["filename"]) &&
|
||||
isset($_POST["id_owner"]) &&
|
||||
isset($_POST["id"])
|
||||
)
|
||||
$static_qrcode_instance->editQrcode($_POST);
|
||||
|
||||
@@ -7,11 +7,17 @@ require_once BASE_PATH . '/lib/StaticQrcode/StaticQrcode.php';
|
||||
$db = getDbInstance();
|
||||
$static_qrcode = new StaticQrcode();
|
||||
|
||||
$select = array('id', 'filename', 'type', 'content', 'qrcode', 'created_at', 'updated_at');
|
||||
$select = array('id', 'id_owner', 'filename', 'type', 'content', 'qrcode', 'created_at', 'updated_at');
|
||||
$search_fields = array('filename', 'type', 'content');
|
||||
require_once BASE_PATH . '/includes/search_order.php';
|
||||
$page = filter_input(INPUT_GET, 'page', FILTER_SANITIZE_FULL_SPECIAL_CHARS) ?? 1;
|
||||
$db->pageLimit = 15;
|
||||
|
||||
if($_SESSION['type'] !== 'super') {
|
||||
$db->where("id_owner", $_SESSION['user_id']);
|
||||
$db->orWhere ("id_owner", NULL, 'IS');
|
||||
}
|
||||
|
||||
$rows = $db->arraybuilder()->paginate('static_qrcodes', $page, $select);
|
||||
$total_pages = $db->totalPages;
|
||||
?>
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
require_once ('../config/environment.php');
|
||||
|
||||
$conn = new mysqli(DATABASE_HOST,DATABASE_USER,DATABASE_PASSWORD,DATABASE_NAME, DATABASE_PORT);
|
||||
|
||||
if ($conn->connect_error) {
|
||||
die("Connection failed: " . $conn->connect_error);
|
||||
}
|
||||
|
||||
echo "Upgrading from version 1.0 to a version >= 2.0.<br>";
|
||||
|
||||
$sql = "ALTER TABLE " . DATABASE_PREFIX . "admin_accounts" ." RENAME TO " . DATABASE_PREFIX . "users";
|
||||
if ($conn->query($sql) === TRUE) {
|
||||
echo "The admin_accounts table has been renamed to users successfully.<br>";
|
||||
} else {
|
||||
echo "Error renaming table: " . $conn->error . "<br>";
|
||||
}
|
||||
|
||||
$sql = "ALTER TABLE " . DATABASE_PREFIX . "users" . " CHANGE `user_name` `username` VARCHAR(50) NOT NULL";
|
||||
if ($conn->query($sql) === TRUE) {
|
||||
echo "The user_name column has been renamed to username successfully.<br>";
|
||||
} else {
|
||||
echo "Error renaming column: " . $conn->error . "<br>";
|
||||
}
|
||||
|
||||
$sql = "ALTER TABLE " . DATABASE_PREFIX . "users" . " CHANGE `admin_type` `type` VARCHAR(10) NOT NULL";
|
||||
if ($conn->query($sql) === TRUE) {
|
||||
echo "The admin_type column was renamed to type successfully.<br>";
|
||||
} else {
|
||||
echo "Error renaming column: " . $conn->error . "<br>";
|
||||
}
|
||||
|
||||
$sql = "ALTER TABLE " . DATABASE_PREFIX . "dynamic_qrcodes" . " ADD `id_owner` INT(25) NULL AFTER `id`";
|
||||
if ($conn->query($sql) === TRUE) {
|
||||
echo "The id_owner column has been added to dynamic_qrcodes successfully.<br>";
|
||||
} else {
|
||||
echo "Error adding column: " . $conn->error . "<br>";
|
||||
}
|
||||
|
||||
$sql = "ALTER TABLE " . DATABASE_PREFIX . "static_qrcodes" . " ADD `id_owner` INT(25) NULL AFTER `id`";
|
||||
if ($conn->query($sql) === TRUE) {
|
||||
echo "The id_owner column has been added to static_qrcodes successfully.<br>";
|
||||
} else {
|
||||
echo "Error adding column: " . $conn->error . "<br>";
|
||||
}
|
||||
|
||||
$conn->close();
|
||||
?>
|
||||
@@ -6,6 +6,10 @@ require_once BASE_PATH . '/lib/Users/Users.php';
|
||||
|
||||
$user_instance = new Users();
|
||||
|
||||
if ($_SESSION['type'] !== 'super')
|
||||
$user_instance->failure('Only a "super admin" account can access the admin listing page', 'Location: index.php');
|
||||
|
||||
|
||||
$edit = false;
|
||||
if($_SERVER["REQUEST_METHOD"] === "GET" && isset($_GET["edit"]) && $_GET["edit"] == "true" && isset($_GET["id"])) {
|
||||
$edit = true;
|
||||
@@ -18,9 +22,9 @@ if($_SERVER["REQUEST_METHOD"] === "POST" && isset($_POST["del_id"])) {
|
||||
|
||||
if($_SERVER["REQUEST_METHOD"] === "POST" && isset($_POST["edit"])) {
|
||||
if(
|
||||
isset($_POST["user_name"]) &&
|
||||
isset($_POST["username"]) &&
|
||||
isset($_POST["password"]) &&
|
||||
isset($_POST["admin_type"]) &&
|
||||
isset($_POST["type"]) &&
|
||||
isset($_POST["id"])
|
||||
)
|
||||
$user_instance->editUser($_POST);
|
||||
@@ -28,9 +32,9 @@ if($_SERVER["REQUEST_METHOD"] === "POST" && isset($_POST["edit"])) {
|
||||
|
||||
if($_SERVER["REQUEST_METHOD"] === "POST" && !isset($_POST["edit"])) {
|
||||
if(
|
||||
isset($_POST["user_name"]) &&
|
||||
isset($_POST["username"]) &&
|
||||
isset($_POST["password"]) &&
|
||||
isset($_POST["admin_type"])
|
||||
isset($_POST["type"])
|
||||
)
|
||||
$user_instance->addUser($_POST);
|
||||
}
|
||||
@@ -5,14 +5,17 @@ require_once BASE_PATH . '/includes/auth_validate.php';
|
||||
require_once BASE_PATH . '/lib/Users/Users.php';
|
||||
|
||||
$db = getDbInstance();
|
||||
$Users = new Users();
|
||||
$users = new Users();
|
||||
|
||||
$select = array('id', 'user_name', 'admin_type');
|
||||
$search_fields = array('user_name');
|
||||
if ($_SESSION['type'] !== 'super')
|
||||
$users->failure('Only a "super admin" account can access the admin listing page', 'Location: index.php');
|
||||
|
||||
$select = array('id', 'username', 'type');
|
||||
$search_fields = array('username');
|
||||
require_once BASE_PATH . '/includes/search_order.php';
|
||||
$page = filter_input(INPUT_GET, 'page', FILTER_SANITIZE_FULL_SPECIAL_CHARS) ?? 1;
|
||||
$db->pageLimit = 15;
|
||||
$rows = $db->arraybuilder()->paginate('admin_accounts', $page, $select);
|
||||
$rows = $db->arraybuilder()->paginate('users', $page, $select);
|
||||
$total_pages = $db->totalPages;
|
||||
?>
|
||||
|
||||
@@ -40,13 +43,13 @@ $total_pages = $db->totalPages;
|
||||
<div class="row mb-2">
|
||||
|
||||
<div class="col-sm-6">
|
||||
<h1 class="m-0 text-dark">Admin users</h1>
|
||||
<h1 class="m-0 text-dark">Users</h1>
|
||||
</div><!-- /.col -->
|
||||
|
||||
<div class="col-sm-6">
|
||||
<ol class="breadcrumb float-sm-right">
|
||||
<li class="breadcrumb-item">
|
||||
<a href="admin_user.php" class="btn btn-success"><i class="fa fa-plus"></i> Add new</a>
|
||||
<a href="user.php" class="btn btn-success"><i class="fa fa-plus"></i> Add new</a>
|
||||
</li>
|
||||
</ol>
|
||||
</div><!-- /.col -->
|
||||
@@ -59,7 +62,7 @@ $total_pages = $db->totalPages;
|
||||
<!-- /.Flash message-->
|
||||
|
||||
<!-- Filters -->
|
||||
<?php $options = $Users->setOrderingValues();
|
||||
<?php $options = $users->setOrderingValues();
|
||||
include BASE_PATH . '/forms/filters.php'; ?>
|
||||
<!-- /.Filters -->
|
||||
|
||||
Reference in New Issue
Block a user