~dangarner/xibo/client-132

« back to all changes in this revision

Viewing changes to server/lib/data/datasetgroupsecurity.data.class.php

MergedĀ ~dangarner/xibo/server-layout-media-permissions

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/*
 
3
 * Xibo - Digitial Signage - http://www.xibo.org.uk
 
4
 * Copyright (C) 2011 Daniel Garner
 
5
 *
 
6
 * This file is part of Xibo.
 
7
 *
 
8
 * Xibo is free software: you can redistribute it and/or modify
 
9
 * it under the terms of the GNU Affero General Public License as published by
 
10
 * the Free Software Foundation, either version 3 of the License, or
 
11
 * any later version.
 
12
 *
 
13
 * Xibo is distributed in the hope that it will be useful,
 
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
 * GNU Affero General Public License for more details.
 
17
 *
 
18
 * You should have received a copy of the GNU Affero General Public License
 
19
 * along with Xibo.  If not, see <http://www.gnu.org/licenses/>.
 
20
 */
 
21
defined('XIBO') or die('Sorry, you are not allowed to directly access this page.<br /> Please press the back button in your browser.');
 
22
 
 
23
class DataSetGroupSecurity extends Data
 
24
{
 
25
    public function __construct(database $db)
 
26
    {
 
27
        parent::__construct($db);
 
28
    }
 
29
 
 
30
    /**
 
31
     * Links a Display Group to a Group
 
32
     * @return
 
33
     * @param $displayGroupID Object
 
34
     * @param $groupID Object
 
35
     */
 
36
    public function Link($dataSetId, $groupId, $view, $edit, $del)
 
37
    {
 
38
        $db =& $this->db;
 
39
 
 
40
        Debug::LogEntry($db, 'audit', 'IN', 'DataSetGroupSecurity', 'Link');
 
41
 
 
42
        $SQL  = "";
 
43
        $SQL .= "INSERT ";
 
44
        $SQL .= "INTO   lkdatasetgroup ";
 
45
        $SQL .= "       ( ";
 
46
        $SQL .= "              DataSetID, ";
 
47
        $SQL .= "              GroupID, ";
 
48
        $SQL .= "              View, ";
 
49
        $SQL .= "              Edit, ";
 
50
        $SQL .= "              Del ";
 
51
        $SQL .= "       ) ";
 
52
        $SQL .= "       VALUES ";
 
53
        $SQL .= "       ( ";
 
54
        $SQL .= sprintf("  %d, %d, %d, %d, %d ", $dataSetId, $groupId, $view, $edit, $del);
 
55
        $SQL .= "       )";
 
56
 
 
57
        if (!$db->query($SQL))
 
58
        {
 
59
            trigger_error($db->error());
 
60
            $this->SetError(25024, __('Could not Link DataSet to Group'));
 
61
 
 
62
            return false;
 
63
        }
 
64
 
 
65
        Debug::LogEntry($db, 'audit', 'OUT', 'DataSetGroupSecurity', 'Link');
 
66
 
 
67
        return true;
 
68
    }
 
69
 
 
70
    /**
 
71
     * Links everyone to the layout specified
 
72
     * @param <type> $layoutId
 
73
     * @param <type> $view
 
74
     * @param <type> $edit
 
75
     * @param <type> $del
 
76
     * @return <type>
 
77
     */
 
78
    public function LinkEveryone($dataSetId, $view, $edit, $del)
 
79
    {
 
80
        $db =& $this->db;
 
81
 
 
82
        Debug::LogEntry($db, 'audit', 'IN', 'DataSetGroupSecurity', 'LinkEveryone');
 
83
 
 
84
        $groupId = $db->GetSingleValue("SELECT GroupID FROM `group` WHERE IsEveryone = 1", 'GroupID', _INT);
 
85
 
 
86
        return $this->Link($dataSetId, $groupId, $view, $edit, $del);
 
87
    }
 
88
 
 
89
    /**
 
90
     * Unlinks a display group from a group
 
91
     * @return
 
92
     * @param $displayGroupID Object
 
93
     * @param $groupID Object
 
94
     */
 
95
    public function Unlink($dataSetId, $groupId)
 
96
    {
 
97
        $db =& $this->db;
 
98
 
 
99
        Debug::LogEntry($db, 'audit', 'IN', 'DataSetGroupSecurity', 'Unlink');
 
100
 
 
101
        $SQL  = "";
 
102
        $SQL .= "DELETE FROM ";
 
103
        $SQL .= "   lkdatasetgroup ";
 
104
        $SQL .= sprintf("  WHERE DataSetID = %d AND GroupID = %d ", $dataSetId, $groupId);
 
105
 
 
106
        if (!$db->query($SQL))
 
107
        {
 
108
            trigger_error($db->error());
 
109
            $this->SetError(25025, __('Could not Unlink DataSet from Group'));
 
110
 
 
111
            return false;
 
112
        }
 
113
 
 
114
        Debug::LogEntry($db, 'audit', 'OUT', 'DataSetGroupSecurity', 'Unlink');
 
115
 
 
116
        return true;
 
117
    }
 
118
 
 
119
        /**
 
120
     * Unlinks a display group from a group
 
121
     * @return
 
122
     * @param $displayGroupID Object
 
123
     * @param $groupID Object
 
124
     */
 
125
    public function UnlinkAll($dataSetId)
 
126
    {
 
127
        $db =& $this->db;
 
128
 
 
129
        Debug::LogEntry($db, 'audit', 'IN', 'DataSetGroupSecurity', 'Unlink');
 
130
 
 
131
        $SQL  = "";
 
132
        $SQL .= "DELETE FROM ";
 
133
        $SQL .= "   lkdatasetgroup ";
 
134
        $SQL .= sprintf("  WHERE DataSetID = %d ", $dataSetId);
 
135
 
 
136
        if (!$db->query($SQL))
 
137
        {
 
138
            trigger_error($db->error());
 
139
            $this->SetError(25025, __('Could not Unlink DataSet from Group'));
 
140
 
 
141
            return false;
 
142
        }
 
143
 
 
144
        Debug::LogEntry($db, 'audit', 'OUT', 'DataSetGroupSecurity', 'Unlink');
 
145
 
 
146
        return true;
 
147
    }
 
148
}
 
149
?>
 
 
b'\\ No newline at end of file'