~dangarner/xibo/client-132

« back to all changes in this revision

Viewing changes to server/lib/data/layoutmediagroupsecurity.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 LayoutMediaGroupSecurity 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($layoutId, $regionId, $mediaId, $groupId, $view, $edit, $del)
 
37
    {
 
38
        $db =& $this->db;
 
39
 
 
40
        Debug::LogEntry($db, 'audit', 'IN', 'LayoutMediaGroupSecurity', 'Link');
 
41
 
 
42
        $SQL  = "";
 
43
        $SQL .= "INSERT ";
 
44
        $SQL .= "INTO   lklayoutmediagroup ";
 
45
        $SQL .= "       ( ";
 
46
        $SQL .= "              LayoutID, ";
 
47
        $SQL .= "              RegionID, ";
 
48
        $SQL .= "              MediaID, ";
 
49
        $SQL .= "              GroupID, ";
 
50
        $SQL .= "              View, ";
 
51
        $SQL .= "              Edit, ";
 
52
        $SQL .= "              Del ";
 
53
        $SQL .= "       ) ";
 
54
        $SQL .= "       VALUES ";
 
55
        $SQL .= "       ( ";
 
56
        $SQL .= sprintf("  %d, '%s', '%s', %d, %d, %d, %d ", $layoutId, $regionId, $mediaId, $groupId, $view, $edit, $del);
 
57
        $SQL .= "       )";
 
58
 
 
59
        if (!$db->query($SQL))
 
60
        {
 
61
            trigger_error($db->error());
 
62
            $this->SetError(25026, __('Could not Link Layout Media to Group'));
 
63
 
 
64
            return false;
 
65
        }
 
66
 
 
67
        Debug::LogEntry($db, 'audit', 'OUT', 'LayoutMediaGroupSecurity', 'Link');
 
68
 
 
69
        return true;
 
70
    }
 
71
 
 
72
    /**
 
73
     * Links everyone to the layout specified
 
74
     * @param <type> $layoutId
 
75
     * @param <type> $view
 
76
     * @param <type> $edit
 
77
     * @param <type> $del
 
78
     * @return <type>
 
79
     */
 
80
    public function LinkEveryone($layoutId, $regionId, $mediaId, $view, $edit, $del)
 
81
    {
 
82
        $db =& $this->db;
 
83
 
 
84
        Debug::LogEntry($db, 'audit', 'IN', 'LayoutMediaGroupSecurity', 'LinkEveryone');
 
85
 
 
86
        $groupId = $db->GetSingleValue("SELECT GroupID FROM `group` WHERE IsEveryone = 1", 'GroupID', _INT);
 
87
 
 
88
        return $this->Link($layoutId, $regionId, $mediaId, $groupId, $view, $edit, $del);
 
89
    }
 
90
 
 
91
    /**
 
92
     * Unlinks a display group from a group
 
93
     * @return
 
94
     * @param $displayGroupID Object
 
95
     * @param $groupID Object
 
96
     */
 
97
    public function Unlink($layoutId, $regionId, $mediaId, $groupId)
 
98
    {
 
99
        $db =& $this->db;
 
100
 
 
101
        Debug::LogEntry($db, 'audit', 'IN', 'LayoutMediaGroupSecurity', 'Unlink');
 
102
 
 
103
        $SQL  = "";
 
104
        $SQL .= "DELETE FROM ";
 
105
        $SQL .= "   lklayoutmediagroup ";
 
106
        $SQL .= sprintf("  WHERE LayoutID = %d AND RegionID = '%s' AND MediaID = '%s' AND GroupID = %d ", $layoutId, $regionId, $mediaId, $groupId);
 
107
 
 
108
        if (!$db->query($SQL))
 
109
        {
 
110
            trigger_error($db->error());
 
111
            $this->SetError(25027, __('Could not Unlink Layout Media from Group'));
 
112
 
 
113
            return false;
 
114
        }
 
115
 
 
116
        Debug::LogEntry($db, 'audit', 'OUT', 'LayoutMediaGroupSecurity', 'Unlink');
 
117
 
 
118
        return true;
 
119
    }
 
120
 
 
121
        /**
 
122
     * Unlinks a display group from a group
 
123
     * @return
 
124
     * @param $displayGroupID Object
 
125
     * @param $groupID Object
 
126
     */
 
127
    public function UnlinkAll($layoutId, $regionId, $mediaId)
 
128
    {
 
129
        $db =& $this->db;
 
130
 
 
131
        Debug::LogEntry($db, 'audit', 'IN', 'LayoutMediaGroupSecurity', 'Unlink');
 
132
 
 
133
        $SQL  = "";
 
134
        $SQL .= "DELETE FROM ";
 
135
        $SQL .= "   lklayoutmediagroup ";
 
136
        $SQL .= sprintf("  WHERE LayoutID = %d AND RegionID = '%s' AND MediaID = '%s' ", $layoutId, $regionId, $mediaId);
 
137
 
 
138
        if (!$db->query($SQL))
 
139
        {
 
140
            trigger_error($db->error());
 
141
            $this->SetError(25028, __('Could not Unlink Layout Media from Group'));
 
142
 
 
143
            return false;
 
144
        }
 
145
 
 
146
        Debug::LogEntry($db, 'audit', 'OUT', 'LayoutMediaGroupSecurity', 'Unlink');
 
147
 
 
148
        return true;
 
149
    }
 
150
 
 
151
    /**
 
152
     * Copies a media items permissions
 
153
     * @param <type> $layoutId
 
154
     * @param <type> $regionId
 
155
     * @param <type> $mediaId
 
156
     * @param <type> $newMediaId
 
157
     * @return <type>
 
158
     */
 
159
    public function Copy($layoutId, $regionId, $mediaId, $newMediaId)
 
160
    {
 
161
        $db =& $this->db;
 
162
 
 
163
        Debug::LogEntry($db, 'audit', 'IN', 'LayoutMediaGroupSecurity', 'Copy');
 
164
 
 
165
        $SQL  = "";
 
166
        $SQL .= "INSERT ";
 
167
        $SQL .= "INTO   lklayoutmediagroup ";
 
168
        $SQL .= "       ( ";
 
169
        $SQL .= "              LayoutID, ";
 
170
        $SQL .= "              RegionID, ";
 
171
        $SQL .= "              MediaID, ";
 
172
        $SQL .= "              GroupID, ";
 
173
        $SQL .= "              View, ";
 
174
        $SQL .= "              Edit, ";
 
175
        $SQL .= "              Del ";
 
176
        $SQL .= "       ) ";
 
177
        $SQL .= " SELECT LayoutID, RegionID, '%s', GroupID, View, Edit, Del ";
 
178
        $SQL .= "   FROM lklayoutmediagroup ";
 
179
        $SQL .= "  WHERE LayoutID = %d AND RegionID = '%s' AND MediaID = '%s' ";
 
180
 
 
181
        $SQL = sprintf($SQL, $newMediaId, $layoutId, $regionId, $mediaId);
 
182
 
 
183
        if (!$db->query($SQL))
 
184
        {
 
185
            trigger_error($db->error());
 
186
            $this->SetError(25028, __('Could not Copy Layout Media Security'));
 
187
 
 
188
            return false;
 
189
        }
 
190
 
 
191
        return true;
 
192
    }
 
193
}
 
194
?>
 
 
b'\\ No newline at end of file'