actionJsonReaderPanel.php 2.61 KB
Newer Older
remy's avatar
remy committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php

require_once "../config/Plugin.php";
define("PAGE","actionJsonReader");

if(!JSONREADER2_STANDALONE) {
    session_start ();
    if(!isset($_SESSION['username'])) {
        header("Location: ".JSR_PATH."/index.php");
    }
}

require_once JSR_PATH.'/dao/DBquery.php';
require_once '../dao/CReaderPanelQuery.php';
require_once '../dao/CReaderQuery.php';
require_once "../model/CReaderPanel.php";
require_once "../model/CReader.php";
require_once JSR_PATH.'/dao/LogDBQuery.php';
require_once JSR_PATH.'/model/Message.php';
require_once JSR_PATH.'/model/Log.php';

$db = new DBquery();

$action  = NULL;
$message = NULL;
$today = date("Y-m-d G:i:s");

$ID         = -1;
$PanelTitle = NULL;
$position   = NULL;

if(isset($_POST['action'])) {
    $action = $_POST['action'];
} else {
    if(isset($_GET['action'])) {
        $action = $_GET['action'];
    } else {
        $action = "";
    }
}

if(isset($_POST['PanelID'])) {
    $ID = $_POST['PanelID'];
} else {
    if(isset($_GET['PanelID'])) {
        $ID = $_GET['PanelID'];
    } else {
        $ID = -1;
    }
}
if(isset($_POST['PanelTitle'])) {
    $PanelTitle = $_POST['PanelTitle'];
} else {
    if(isset($_GET['PanelTitle'])) {
        $PanelTitle = $_GET['PanelTitle'];
    }
}

if(isset($_POST['position'])) {
    $position = $_POST['position'];
}

$creaderpanel = new CReaderPanel($ID, NULL, $PanelTitle, $position);

if($action == "create") {
    /* uncomment following and comment header Location at the end of this file bellow for debug */
    //var_dump($_POST);
    $creaderpanel->escape($db);
    $message = $db->create($creaderpanel);
    if(!JSONREADER2_STANDALONE) {
        $log = new Log(-1, "admin", $creaderpanel->ID, "insert", $message->value, $today, -1);
        LogDBQuery::createLog($db, $log);

    }
}
if($action == "delete") {
    $CRs = CReaderQuery::getAllCReaderObjects($db);
    $Panels = CReaderPanelQuery::getAllCReaderPanelByTitle($db, $PanelTitle);
    foreach($Panels as $Panel) {
        foreach($CRs as $CR) {
            if($CR->ID == $Panel->CReaderID) {
                $message = CReaderQuery::deleteCReader($db, $CR);
                if(!JSONREADER2_STANDALONE) {
                    $log = new Log(-1, "admin", $CR->ckey, "delete", $message->value, $today, -1);
                    LogDBQuery::createLog($db, $log);
                }
            }
        }
    }
    $message = CReaderPanelQuery::deleteCReaderPanel($db, $PanelTitle);
    if(!JSONREADER2_STANDALONE) {
        $log = new Log(-1, "admin", $PanelTitle, "delete", $message->value, $today, -1);
        LogDBQuery::createLog($db, $log);
    }
}


header("Location: ../services/jsonreaderConfig.php");

?>