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
@@ -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);
|
||||
|
||||
$this->qrcode_instance->deleteQrcode($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");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user