~xibo-maintainers/xibo/tempel

380 by Dan Garner
Converted all old page classes into controllers (namespace, name and file name only).
1
<?php
2
/*
3
 * Xibo - Digital Signage - http://www.xibo.org.uk
4
 * Copyright (C) 2006-2014 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
namespace Xibo\Controller;
22
use baseDAO;
23
use Config;
24
use database;
25
use DisplayGroup;
26
use DOMDocument;
27
use DOMXPath;
28
use finfo;
29
use FormManager;
30
use Session;
31
use Xibo\Helper\ApplicationState;
32
use Xibo\Helper\Date;
33
use Xibo\Helper\Help;
34
use Xibo\Helper\Log;
35
use Xibo\Helper\Theme;
36
37
defined('XIBO') or die("Sorry, you are not allowed to directly access this page.<br /> Please press the back button in your browser.");
38
39
class Display extends Base
40
{
41
42
    /**
43
     * Include display page template page based on sub page selected
44
     * @return
45
     */
46
    function displayPage()
47
    {
48
        // Configure the theme
49
        $id = uniqid();
50
        Theme::Set('id', $id);
51
        Theme::Set('form_meta', '<input type="hidden" name="p" value="display"><input type="hidden" name="q" value="DisplayGrid">');
52
        Theme::Set('filter_id', 'XiboFilterPinned' . uniqid('filter'));
53
        Theme::Set('pager', ApplicationState::Pager($id));
54
55
        // Default options
56
        if (\Kit::IsFilterPinned('display', 'DisplayFilter')) {
57
            $filter_pinned = 1;
58
            $filter_displaygroup = Session::Get('display', 'filter_displaygroup');
59
            $filter_display = Session::Get('display', 'filter_display');
60
            $filterMacAddress = Session::Get('display', 'filterMacAddress');
61
            $filter_showView = Session::Get('display', 'filter_showView');
62
            $filter_autoRefresh = Session::Get('display', 'filter_autoRefresh');
63
        } else {
64
            $filter_pinned = 0;
65
            $filter_displaygroup = NULL;
66
            $filter_display = NULL;
67
            $filterMacAddress = NULL;
68
            $filter_showView = 0;
69
            $filter_autoRefresh = 0;
70
        }
71
72
        $formFields = array();
73
74
        $formFields[] = FormManager::AddCombo(
75
            'filter_showView',
76
            __('View'),
77
            $filter_showView,
78
            array(
79
                array('key' => 0, 'value' => __('Default')),
80
                array('key' => 1, 'value' => __('Screen shot thumbnails')),
81
                array('key' => 2, 'value' => __('Screen shot thumbnails when Logged In')),
82
                array('key' => 3, 'value' => __('Extended Display Status')),
83
            ),
84
            'key',
85
            'value',
86
            NULL,
87
            't');
88
89
        $formFields[] = FormManager::AddText('filter_display', __('Name'), $filter_display, NULL, 'n');
90
        $formFields[] = FormManager::AddText('filterMacAddress', __('Mac Address'), $filterMacAddress, NULL, 'm');
91
92
        $displayGroups = $this->user->DisplayGroupList(0);
93
        array_unshift($displayGroups, array('displaygroupid' => '0', 'displaygroup' => 'All'));
94
        $formFields[] = FormManager::AddCombo(
95
            'filter_displaygroup',
96
            __('Display Group'),
97
            $filter_displaygroup,
98
            $displayGroups,
99
            'displaygroupid',
100
            'displaygroup',
101
            NULL,
102
            'd');
103
104
        $formFields[] = FormManager::AddNumber('filter_autoRefresh', __('Auto Refresh'), $filter_autoRefresh,
105
            NULL, 'r');
106
107
        $formFields[] = FormManager::AddCheckbox('XiboFilterPinned', __('Keep Open'),
108
            $filter_pinned, NULL,
109
            'k');
110
111
        // Call to render the template
112
        Theme::Set('header_text', __('Displays'));
113
        Theme::Set('form_fields', $formFields);
114
        $this->getState()->html .= Theme::RenderReturn('grid_render');
115
    }
116
117
    function actionMenu()
118
    {
119
120
        return array(
121
            array('title' => __('Filter'),
122
                'class' => '',
123
                'selected' => false,
124
                'link' => '#',
125
                'help' => __('Open the filter form'),
126
                'onclick' => 'ToggleFilterView(\'Filter\')'
127
            )
128
        );
129
    }
130
131
    /**
132
     * Modifies the selected display record
133
     * @return
134
     */
135
    function modify()
136
    {
137
138
139
        $response = $this->getState();
140
141
        $displayObject = new Display();
142
        $displayObject->displayId = \Xibo\Helper\Sanitize::getInt('displayid');
143
144
        $auth = $this->user->DisplayGroupAuth($this->GetDisplayGroupId($displayObject->displayId), true);
145
        if (!$auth->edit)
146
            trigger_error(__('You do not have permission to edit this display'), E_USER_ERROR);
147
148
        if (!$displayObject->Load())
149
            trigger_error($displayObject->GetErrorMessage(), E_USER_ERROR);
150
151
        // Update properties
152
        $displayObject->display = \Xibo\Helper\Sanitize::getString('display');
153
        $displayObject->description = \Xibo\Helper\Sanitize::getString('description');
154
        $displayObject->isAuditing = \Xibo\Helper\Sanitize::getInt('auditing');
155
        $displayObject->defaultLayoutId = \Xibo\Helper\Sanitize::getInt('defaultlayoutid');
156
        $displayObject->licensed = \Xibo\Helper\Sanitize::getInt('licensed');
157
        $displayObject->incSchedule = \Xibo\Helper\Sanitize::getInt('inc_schedule');
158
        $displayObject->emailAlert = \Xibo\Helper\Sanitize::getInt('email_alert');
159
        $displayObject->alertTimeout = \Xibo\Helper\Sanitize::getCheckbox('alert_timeout');
160
        $displayObject->wakeOnLanEnabled = \Xibo\Helper\Sanitize::getCheckbox('wakeOnLanEnabled');
161
        $displayObject->wakeOnLanTime = \Xibo\Helper\Sanitize::getString('wakeOnLanTime');
162
        $displayObject->broadCastAddress = \Xibo\Helper\Sanitize::getString('broadCastAddress');
163
        $displayObject->secureOn = \Xibo\Helper\Sanitize::getString('secureOn');
164
        $displayObject->cidr = \Xibo\Helper\Sanitize::getString('cidr');
165
        $displayObject->latitude = \Kit::GetParam('latitude', _POST, _DOUBLE);
166
        $displayObject->longitude = \Kit::GetParam('longitude', _POST, _DOUBLE);
167
        $displayObject->displayProfileId = \Xibo\Helper\Sanitize::getInt('displayprofileid');
168
169
        if (!$displayObject->Edit())
170
            trigger_error($displayObject->GetErrorMessage(), E_USER_ERROR);
171
172
        $response->SetFormSubmitResponse(__('Display Saved.'));
173
174
    }
175
176
    /**
177
     * Modify Display form
178
     */
179
    function displayForm()
180
    {
181
        $response = $this->getState();
182
183
        // Get the display Id
184
        $displayObject = new Display();
185
        $displayObject->displayId = \Xibo\Helper\Sanitize::getInt('displayid');
186
187
        $auth = $this->user->DisplayGroupAuth($this->GetDisplayGroupId($displayObject->displayId), true);
188
        if (!$auth->edit)
189
            trigger_error(__('You do not have permission to edit this display'), E_USER_ERROR);
190
191
        // Load this display
192
        if (!$displayObject->Load())
193
            trigger_error($displayObject->GetErrorMessage(), E_USER_ERROR);
194
195
        // Set some information about the form
196
        Theme::Set('form_id', 'DisplayEditForm');
197
        Theme::Set('form_action', 'index.php?p=display&q=modify');
198
        Theme::Set('form_meta', '<input type="hidden" name="displayid" value="' . $displayObject->displayId . '" />');
199
200
        // Column 1
201
        $formFields = array();
202
        $formFields[] = FormManager::AddText('display', __('Display'), $displayObject->display,
203
            __('The Name of the Display - (1 - 50 characters).'), 'd', 'required');
204
205
        $formFields[] = FormManager::AddText('hardwareKey', __('Display\'s Hardware Key'), $displayObject->license,
206
            __('A unique identifier for this display.'), 'h', 'required', NULL, false);
207
208
        $formFields[] = FormManager::AddText('description', __('Description'), $displayObject->description,
209
            __('A description - (1 - 254 characters).'), 'p', 'maxlength="50"');
210
211
        $formFields[] = FormManager::AddCombo(
212
            'licensed',
213
            __('Licence Display?'),
214
            $displayObject->licensed,
215
            array(array('licensedid' => '1', 'licensed' => 'Yes'), array('licensedid' => '0', 'licensed' => 'No')),
216
            'licensedid',
217
            'licensed',
218
            __('Use one of the available licenses for this display?'),
219
            'l');
220
221
        $formFields[] = FormManager::AddCombo(
222
            'defaultlayoutid',
223
            __('Default Layout'),
224
            $displayObject->defaultLayoutId,
225
            $this->user->LayoutList(),
226
            'layoutid',
227
            'layout',
228
            __('The Default Layout to Display where there is no other content.'),
229
            't');
230
231
        Theme::Set('form_fields_general', $formFields);
232
233
        // Maintenance
234
        $formFields = array();
235
        $formFields[] = FormManager::AddCombo(
236
            'email_alert',
237
            __('Email Alerts'),
238
            $displayObject->emailAlert,
239
            array(array('id' => '1', 'value' => 'Yes'), array('id' => '0', 'value' => 'No')),
240
            'id',
241
            'value',
242
            __('Do you want to be notified by email if there is a problem with this display?'),
243
            'a');
244
245
        $formFields[] = FormManager::AddCheckbox('alert_timeout', __('Use the Global Timeout?'), $displayObject->alertTimeout,
246
            __('Should this display be tested against the global time out or the client collection interval?'),
247
            'o');
248
249
        Theme::Set('form_fields_maintenance', $formFields);
250
251
        // Location
252
        $formFields = array();
253
254
        $formFields[] = FormManager::AddNumber('latitude', __('Latitude'), $displayObject->latitude,
255
            __('The Latitude of this display'), 'g');
256
257
        $formFields[] = FormManager::AddNumber('longitude', __('Longitude'), $displayObject->longitude,
258
            __('The Longitude of this Display'), 'g');
259
260
        Theme::Set('form_fields_location', $formFields);
261
262
        // Wake on LAN
263
        $formFields = array();
264
265
        $formFields[] = FormManager::AddCheckbox('wakeOnLanEnabled', __('Enable Wake on LAN'),
266
            $displayObject->wakeOnLanEnabled, __('Wake on Lan requires the correct network configuration to route the magic packet to the display PC'),
267
            'w');
268
269
        $formFields[] = FormManager::AddText('broadCastAddress', __('BroadCast Address'), (($displayObject->broadCastAddress == '') ? $displayObject->clientAddress : $displayObject->broadCastAddress),
270
            __('The IP address of the remote host\'s broadcast address (or gateway)'), 'b');
271
272
        $formFields[] = FormManager::AddText('secureOn', __('Wake on LAN SecureOn'), $displayObject->secureOn,
273
            __('Enter a hexadecimal password of a SecureOn enabled Network Interface Card (NIC) of the remote host. Enter a value in this pattern: \'xx-xx-xx-xx-xx-xx\'. Leave the following field empty, if SecureOn is not used (for example, because the NIC of the remote host does not support SecureOn).'), 's');
274
275
        $formFields[] = FormManager::AddText('wakeOnLanTime', __('Wake on LAN Time'), $displayObject->wakeOnLanTime,
276
            __('The time this display should receive the WOL command, using the 24hr clock - e.g. 19:00. Maintenance must be enabled.'), 't');
277
278
        $formFields[] = FormManager::AddText('cidr', __('Wake on LAN CIDR'), $displayObject->cidr,
279
            __('Enter a number within the range of 0 to 32 in the following field. Leave the following field empty, if no subnet mask should be used (CIDR = 0). If the remote host\'s broadcast address is unknown: Enter the host name or IP address of the remote host in Broad Cast Address and enter the CIDR subnet mask of the remote host in this field.'), 'c');
280
281
        Theme::Set('form_fields_wol', $formFields);
282
283
        // Advanced
284
        $formFields = array();
285
286
        $displayProfileList = $this->user->DisplayProfileList(NULL, array('type' => $displayObject->clientType));
287
        array_unshift($displayProfileList, array('displayprofileid' => 0, 'name' => ''));
288
289
        $formFields[] = FormManager::AddCombo(
290
            'displayprofileid',
291
            __('Settings Profile?'),
292
            $displayObject->displayProfileId,
293
            $displayProfileList,
294
            'displayprofileid',
295
            'name',
296
            __('What display profile should this display use?'),
297
            'p');
298
299
        $formFields[] = FormManager::AddCombo(
300
            'inc_schedule',
301
            __('Interleave Default'),
302
            $displayObject->incSchedule,
303
            array(array('id' => '1', 'value' => 'Yes'), array('id' => '0', 'value' => 'No')),
304
            'id',
305
            'value',
306
            __('Whether to always put the default layout into the cycle.'),
307
            'i');
308
309
        $formFields[] = FormManager::AddCombo(
310
            'auditing',
311
            __('Auditing'),
312
            $displayObject->isAuditing,
313
            array(array('id' => '1', 'value' => 'Yes'), array('id' => '0', 'value' => 'No')),
314
            'id',
315
            'value',
316
            __('Collect auditing from this client. Should only be used if there is a problem with the display.'),
317
            'a');
318
319
        // Show the resolved settings for this display.
320
        $formFields[] = FormManager::AddMessage(__('The settings for this display are shown below. They are taken from the active Display Profile for this Display, which can be changed in Display Settings. If you have altered the Settings Profile above, you will need to save and re-show the form.'));
321
322
        // Build a table for the settings to be shown in
323
        $cols = array(
324
            array('name' => 'title', 'title' => __('Setting')),
325
            array('name' => 'valueString', 'title' => __('Value'))
326
        );
327
328
        // Get the settings from the profile
329
        $profile = $displayObject->getSettingsProfile();
330
331
        // Go through each one, and see if it is a drop down
332
        for ($i = 0; $i < count($profile); $i++) {
333
            // Always update the value string with the source value
334
            $profile[$i]['valueString'] = $profile[$i]['value'];
335
336
            // Overwrite the value string when we are dealing with dropdowns
337
            if ($profile[$i]['fieldType'] == 'dropdown') {
338
                // Update our value
339
                foreach ($profile[$i]['options'] as $option) {
340
                    if ($option['id'] == $profile[$i]['value'])
341
                        $profile[$i]['valueString'] = $option['value'];
342
                }
343
            } else if ($profile[$i]['fieldType'] == 'timePicker') {
344
                $profile[$i]['valueString'] = Date::getSystemDate($profile[$i]['value'] / 1000, 'H:i');
345
            }
346
        }
347
348
        Theme::Set('table_cols', $cols);
349
        Theme::Set('table_rows', $profile);
350
        $formFields[] = FormManager::AddRaw(Theme::RenderReturn('table_render'));
351
352
        Theme::Set('form_fields_advanced', $formFields);
353
354
        // Two tabs
355
        $tabs = array();
356
        $tabs[] = FormManager::AddTab('general', __('General'));
357
        $tabs[] = FormManager::AddTab('location', __('Location'));
358
        $tabs[] = FormManager::AddTab('maintenance', __('Maintenance'));
359
        $tabs[] = FormManager::AddTab('wol', __('Wake on LAN'));
360
        $tabs[] = FormManager::AddTab('advanced', __('Advanced'));
361
362
        Theme::Set('form_tabs', $tabs);
363
364
        $response->SetFormRequestResponse(NULL, __('Edit a Display'), '650px', '350px');
365
        $response->AddButton(__('Help'), 'XiboHelpRender("' . Help::Link('Display', 'Edit') . '")');
366
        $response->AddButton(__('Cancel'), 'XiboDialogClose()');
367
        $response->AddButton(__('Save'), '$("#DisplayEditForm").submit()');
368
369
    }
370
371
    /**
372
     * Grid of Displays
373
     * @return
374
     */
375
    function DisplayGrid()
376
    {
377
        // validate displays so we get a realistic view of the table
378
        Display::ValidateDisplays();
379
380
381
        $user =& $this->user;
382
        $response = new ApplicationState();
383
384
        // Filter by Name
385
        $filter_display = \Xibo\Helper\Sanitize::getString('filter_display');
386
        \Session::Set('display', 'filter_display', $filter_display);
387
388
        // Filter by Name
389
        $filterMacAddress = \Xibo\Helper\Sanitize::getString('filterMacAddress');
390
        \Session::Set('display', 'filterMacAddress', $filterMacAddress);
391
392
        // Display Group
393
        $filter_displaygroupid = \Xibo\Helper\Sanitize::getInt('filter_displaygroup');
394
        \Session::Set('display', 'filter_displaygroup', $filter_displaygroupid);
395
396
        // Thumbnail?
397
        $filter_showView = \Xibo\Helper\Sanitize::getInt('filter_showView');
398
        \Session::Set('display', 'filter_showView', $filter_showView);
399
400
        // filter_autoRefresh?
401
        $filter_autoRefresh = \Kit::GetParam('filter_autoRefresh', _REQUEST, _INT, 0);
402
        \Session::Set('display', 'filter_autoRefresh', $filter_autoRefresh);
403
404
        // Pinned option?
405
        \Session::Set('display', 'DisplayFilter', \Kit::GetParam('XiboFilterPinned', _REQUEST, _CHECKBOX, 'off'));
406
407
        $displays = $user->DisplayList(array('displayid'), array('displaygroupid' => $filter_displaygroupid, 'display' => $filter_display, 'macAddress' => $filterMacAddress));
408
409
        if (!is_array($displays)) {
410
            trigger_error($db->error());
411
            trigger_error(__('Unable to get list of displays'), E_USER_ERROR);
412
        }
413
414
        // Do we want to make a VNC link out of the display name?
415
        $vncTemplate = Config::GetSetting('SHOW_DISPLAY_AS_VNCLINK');
416
        $linkTarget = \Xibo\Helper\Sanitize::string(Config::GetSetting('SHOW_DISPLAY_AS_VNC_TGT'));
417
418
        $cols = array(
419
            array('name' => 'displayid', 'title' => __('ID')),
420
            array('name' => 'displayWithLink', 'title' => __('Display')),
421
            array('name' => 'status', 'title' => __('Status'), 'icons' => true, 'iconDescription' => 'statusDescription'),
422
            array('name' => 'licensed', 'title' => __('License'), 'icons' => true),
423
            array('name' => 'currentLayout', 'title' => __('Current Layout'), 'hidden' => ($filter_showView != 3)),
424
            array('name' => 'storageAvailableSpaceFormatted', 'title' => __('Storage Available'), 'hidden' => ($filter_showView != 3)),
425
            array('name' => 'storageTotalSpaceFormatted', 'title' => __('Storage Total'), 'hidden' => ($filter_showView != 3)),
426
            array('name' => 'storagePercentage', 'title' => __('Storage Free %'), 'hidden' => ($filter_showView != 3)),
427
            array('name' => 'description', 'title' => __('Description'), 'hidden' => ($filter_showView != 0)),
428
            array('name' => 'layout', 'title' => __('Default Layout'), 'hidden' => ($filter_showView == 1 || $filter_showView == 2)),
429
            array('name' => 'inc_schedule', 'title' => __('Interleave Default'), 'icons' => true, 'hidden' => ($filter_showView == 1 || $filter_showView == 2)),
430
            array('name' => 'email_alert', 'title' => __('Email Alert'), 'icons' => true, 'hidden' => ($filter_showView != 0)),
431
            array('name' => 'loggedin', 'title' => __('Logged In'), 'icons' => true),
432
            array('name' => 'lastaccessed', 'title' => __('Last Accessed')),
433
            array('name' => 'clientaddress', 'title' => __('IP Address'), 'hidden' => ($filter_showView == 1)),
434
            array('name' => 'macaddress', 'title' => __('Mac Address'), 'hidden' => ($filter_showView == 1)),
435
            array('name' => 'screenShotRequested', 'title' => __('Screen shot?'), 'icons' => true, 'hidden' => ($filter_showView != 1 && $filter_showView != 2)),
436
            array('name' => 'thumbnail', 'title' => __('Thumbnail'), 'hidden' => ($filter_showView != 1 && $filter_showView != 2))
437
        );
438
439
        Theme::Set('table_cols', $cols);
440
        Theme::Set('rowClass', 'rowColor');
441
442
        $rows = array();
443
444
        foreach ($displays as $row) {
445
            // VNC Template as display name?
446
            if ($vncTemplate != '' && $row['clientaddress'] != '') {
447
                if ($linkTarget == '')
448
                    $linkTarget = '_top';
449
450
                $row['displayWithLink'] = sprintf('<a href="' . $vncTemplate . '" title="VNC to ' . $row['display'] . '" target="' . $linkTarget . '">' . Theme::Prepare($row['display']) . '</a>', $row['clientaddress']);
451
            } else {
452
                $row['displayWithLink'] = $row['display'];
453
            }
454
455
            // Format last accessed
456
            $row['lastaccessed'] = Date::getLocalDate($row['lastaccessed']);
457
458
            // Create some login lights
459
            $row['rowColor'] = ($row['mediainventorystatus'] == 1) ? 'success' : (($row['mediainventorystatus'] == 2) ? 'danger' : 'warning');
460
            $row['status'] = ($row['mediainventorystatus'] == 1) ? 1 : (($row['mediainventorystatus'] == 2) ? 0 : -1);
461
462
            // Set some text for the display status
463
            switch ($row['status']) {
464
                case 1:
465
                    $row['statusDescription'] = __('Display is up to date');
466
                    break;
467
468
                case 2:
469
                    $row['statusDescription'] = __('Display is downloading new files');
470
                    break;
471
472
                case 3:
473
                    $row['statusDescription'] = __('Display is out of date but has not yet checked in with the server');
474
                    break;
475
476
                default:
477
                    $row['statusDescription'] = __('Unknown Display Status');
478
            }
479
480
            // Thumbnail
481
            $row['thumbnail'] = '';
482
            // If we aren't logged in, and we are showThumbnail == 2, then show a circle
483
            if ($filter_showView == 2 && $row['loggedin'] == 0) {
484
                $row['thumbnail'] = '<i class="fa fa-times-circle"></i>';
485
            } else if ($filter_showView <> 0 && file_exists(Config::GetSetting('LIBRARY_LOCATION') . 'screenshots/' . $row['displayid'] . '_screenshot.jpg')) {
486
                $row['thumbnail'] = '<a data-toggle="lightbox" data-type="image" href="index.php?p=display&q=ScreenShot&DisplayId=' . $row['displayid'] . '"><img class="display-screenshot" src="index.php?p=display&q=ScreenShot&DisplayId=' . $row['displayid'] . '&' . \Kit::uniqueId() . '" /></a>';
487
            }
488
489
            // Format the storage available / total space
490
            $row['storageAvailableSpaceFormatted'] = \Kit::formatBytes($row['storageAvailableSpace']);
491
            $row['storageTotalSpaceFormatted'] = \Kit::formatBytes($row['storageTotalSpace']);
492
            $row['storagePercentage'] = ($row['storageTotalSpace'] == 0) ? 100 : round($row['storageAvailableSpace'] / $row['storageTotalSpace'] * 100.0, 2);
493
494
            // Edit and Delete buttons first
495
            if ($row['edit'] == 1) {
496
                // Edit
497
                $row['buttons'][] = array(
498
                    'id' => 'display_button_edit',
499
                    'url' => 'index.php?p=display&q=displayForm&displayid=' . $row['displayid'],
500
                    'text' => __('Edit')
501
                );
502
            }
503
504
            // Delete
505
            if ($row['del'] == 1) {
506
                $row['buttons'][] = array(
507
                    'id' => 'display_button_delete',
508
                    'url' => 'index.php?p=display&q=DeleteForm&displayid=' . $row['displayid'],
509
                    'text' => __('Delete')
510
                );
511
            }
512
513
            if ($row['edit'] == 1 || $row['del'] == 1) {
514
                $row['buttons'][] = array('linkType' => 'divider');
515
            }
516
517
            // Schedule Now
518
            if ($row['edit'] == 1 || Config::GetSetting('SCHEDULE_WITH_VIEW_PERMISSION') == 'Yes') {
519
                $row['buttons'][] = array(
520
                    'id' => 'display_button_schedulenow',
521
                    'url' => 'index.php?p=schedule&q=ScheduleNowForm&displayGroupId=' . $row['displaygroupid'],
522
                    'text' => __('Schedule Now')
523
                );
524
            }
525
526
            if ($row['edit'] == 1) {
527
528
                // Default Layout
529
                $row['buttons'][] = array(
530
                    'id' => 'display_button_defaultlayout',
531
                    'url' => 'index.php?p=display&q=DefaultLayoutForm&DisplayId=' . $row['displayid'],
532
                    'text' => __('Default Layout')
533
                );
534
535
                // File Associations
536
                $row['buttons'][] = array(
537
                    'id' => 'displaygroup_button_fileassociations',
538
                    'url' => 'index.php?p=displaygroup&q=FileAssociations&DisplayGroupID=' . $row['displaygroupid'],
539
                    'text' => __('Assign Files')
540
                );
541
542
                // Screen Shot
543
                $row['buttons'][] = array(
544
                    'id' => 'display_button_requestScreenShot',
545
                    'url' => 'index.php?p=display&q=RequestScreenShotForm&displayId=' . $row['displayid'],
546
                    'text' => __('Request Screen Shot'),
547
                    'multi-select' => true,
548
                    'dataAttributes' => array(
549
                        array('name' => 'multiselectlink', 'value' => 'index.php?p=display&q=RequestScreenShot'),
550
                        array('name' => 'rowtitle', 'value' => $row['display']),
551
                        array('name' => 'displayId', 'value' => $row['displayid'])
552
                    )
553
                );
554
555
                $row['buttons'][] = array('linkType' => 'divider');
556
            }
557
558
            // Media Inventory
559
            $row['buttons'][] = array(
560
                'id' => 'display_button_mediainventory',
561
                'url' => 'index.php?p=display&q=MediaInventory&DisplayId=' . $row['displayid'],
562
                'text' => __('Media Inventory')
563
            );
564
565
            if ($row['edit'] == 1) {
566
567
                // Logs
568
                $row['buttons'][] = array(
569
                    'id' => 'displaygroup_button_logs',
570
                    'url' => 'index.php?p=log&q=LastHundredForDisplay&displayid=' . $row['displayid'],
571
                    'text' => __('Recent Log')
572
                );
573
574
                $row['buttons'][] = array('linkType' => 'divider');
575
            }
576
577
            if ($row['modifypermissions'] == 1) {
578
579
                // Display Groups
580
                $row['buttons'][] = array(
581
                    'id' => 'display_button_group_membership',
582
                    'url' => 'index.php?p=display&q=MemberOfForm&DisplayID=' . $row['displayid'],
583
                    'text' => __('Display Groups')
584
                );
585
586
                // Permissions
587
                $row['buttons'][] = array(
588
                    'id' => 'display_button_group_membership',
589
                    'url' => 'index.php?p=displaygroup&q=PermissionsForm&DisplayGroupID=' . $row['displaygroupid'],
590
                    'text' => __('Permissions')
591
                );
592
593
                // Version Information
594
                $row['buttons'][] = array(
595
                    'id' => 'display_button_version_instructions',
596
                    'url' => 'index.php?p=displaygroup&q=VersionInstructionsForm&displaygroupid=' . $row['displaygroupid'] . '&displayid=' . $row['displayid'],
597
                    'text' => __('Version Information')
598
                );
599
600
                $row['buttons'][] = array('linkType' => 'divider');
601
            }
602
603
            if ($row['edit'] == 1) {
604
                // Wake On LAN
605
                $row['buttons'][] = array(
606
                    'id' => 'display_button_wol',
607
                    'url' => 'index.php?p=display&q=WakeOnLanForm&DisplayId=' . $row['displayid'],
608
                    'text' => __('Wake on LAN')
609
                );
610
            }
611
612
            // Assign this to the table row
613
            $rows[] = $row;
614
        }
615
616
        Theme::Set('table_rows', $rows);
617
618
        $output = Theme::RenderReturn('table_render');
619
620
        $response->SetGridResponse($output);
621
        $response->refresh = \Kit::GetParam('filter_autoRefresh', _REQUEST, _INT, 0);
622
623
    }
624
625
    /**
626
     * Delete form
627
     */
628
    function DeleteForm()
629
    {
630
631
        $user = $this->getUser();
632
        $response = $this->getState();
633
        $displayid = \Xibo\Helper\Sanitize::getInt('displayid');
634
635
        // Auth
636
        $auth = $this->user->DisplayGroupAuth($this->GetDisplayGroupId($displayid), true);
637
        if (!$auth->del)
638
            trigger_error(__('You do not have permission to edit this display'), E_USER_ERROR);
639
640
        Theme::Set('form_id', 'DisplayDeleteForm');
641
        Theme::Set('form_action', 'index.php?p=display&q=Delete');
642
        Theme::Set('form_meta', '<input type="hidden" name="displayid" value="' . $displayid . '">');
643
644
        Theme::Set('form_fields', array(FormManager::AddMessage(__('Are you sure you want to delete this display? This cannot be undone.'))));
645
646
        $response->SetFormRequestResponse(NULL, __('Delete this Display?'), '350px', '210');
647
        $response->AddButton(__('Help'), 'XiboHelpRender("' . Help::Link('Display', 'Delete') . '")');
648
        $response->AddButton(__('No'), 'XiboDialogClose()');
649
        $response->AddButton(__('Yes'), '$("#DisplayDeleteForm").submit()');
650
651
    }
652
653
    /**
654
     * Delete a display
655
     */
656
    function Delete()
657
    {
658
659
660
661
        $response = $this->getState();
662
        $displayid = \Kit::GetParam('displayid', _POST, _INT, 0);
663
664
        $auth = $this->user->DisplayGroupAuth($this->GetDisplayGroupId($displayid), true);
665
        if (!$auth->del)
666
            trigger_error(__('You do not have permission to edit this display'), E_USER_ERROR);
667
668
        if ($displayid == 0)
669
            trigger_error(__("No Display selected for Deletion."));
670
671
        $displayObject = new Display($db);
672
673
        if (!$displayObject->Delete($displayid))
674
            trigger_error($displayObject->GetErrorMessage(), E_USER_ERROR);
675
676
        $response->SetFormSubmitResponse(__("The Display has been Deleted"));
677
678
    }
679
680
    /**
681
     * Form for editing the default layout of a display
682
     */
683
    public function DefaultLayoutForm()
684
    {
685
686
        $response = $this->getState();
687
688
        $displayId = \Xibo\Helper\Sanitize::getInt('DisplayId');
689
690
        $auth = $this->user->DisplayGroupAuth($this->GetDisplayGroupId($displayId), true);
691
        if (!$auth->edit)
692
            trigger_error(__('You do not have permission to edit this display'), E_USER_ERROR);
693
694
        if (!$defaultLayoutId = $this->db->GetSingleValue(sprintf("SELECT defaultlayoutid FROM display WHERE displayid = %d", $displayId), 'defaultlayoutid', _INT)) {
695
            trigger_error($db->error());
696
            trigger_error(__('Unable to get the default layout'), E_USER_ERROR);
697
        }
698
699
        Theme::Set('form_id', 'DefaultLayoutForm');
700
        Theme::Set('form_action', 'index.php?p=display&q=DefaultLayout');
701
        Theme::Set('form_meta', '<input type="hidden" name="DisplayId" value="' . $displayId . '">');
702
703
        $formFields = array();
704
        $formFields[] = FormManager::AddCombo(
705
            'defaultlayoutid',
706
            __('Default Layout'),
707
            $defaultLayoutId,
708
            $this->user->LayoutList(),
709
            'layoutid',
710
            'layout',
711
            __('The Default Layout will be shown there are no other scheduled Layouts. It is usually a full screen logo or holding image.'),
712
            'd');
713
714
        Theme::Set('form_fields', $formFields);
715
716
        $response->SetFormRequestResponse(NULL, __('Edit Default Layout'), '300px', '150px');
717
        $response->AddButton(__('Help'), 'XiboHelpRender("' . Help::Link('Display', 'DefaultLayout') . '")');
718
        $response->AddButton(__('Cancel'), 'XiboDialogClose()');
719
        $response->AddButton(__('Save'), '$("#DefaultLayoutForm").submit()');
720
721
    }
722
723
    /**
724
     * Edit the default layout for a display
725
     */
726
    public function DefaultLayout()
727
    {
728
729
730
731
        $response = $this->getState();
732
        $displayObject = new Display($db);
733
734
        $displayId = \Xibo\Helper\Sanitize::getInt('DisplayId');
735
        $defaultLayoutId = \Xibo\Helper\Sanitize::getInt('defaultlayoutid');
736
737
        $auth = $this->user->DisplayGroupAuth($this->GetDisplayGroupId($displayId), true);
738
        if (!$auth->edit)
739
            trigger_error(__('You do not have permission to edit this display'), E_USER_ERROR);
740
741
        if (!$displayObject->EditDefaultLayout($displayId, $defaultLayoutId))
742
            trigger_error(__('Cannot Edit this Display'), E_USER_ERROR);
743
744
        $response->SetFormSubmitResponse(__('Display Saved.'));
745
746
    }
747
748
    /**
749
     * Shows the inventory XML for the display
750
     */
751
    public function MediaInventory()
752
    {
753
754
        $response = $this->getState();
755
        $displayId = \Xibo\Helper\Sanitize::getInt('DisplayId');
756
757
        $auth = $this->user->DisplayGroupAuth($this->GetDisplayGroupId($displayId), true);
758
        if (!$auth->view)
759
            trigger_error(__('You do not have permission to view this display'), E_USER_ERROR);
760
761
        if ($displayId == 0)
762
            trigger_error(__('No DisplayId Given'));
763
764
        // Get the media inventory xml for this display
765
        $SQL = "SELECT IFNULL(MediaInventoryXml, '<xml></xml>') AS MediaInventoryXml FROM display WHERE DisplayId = %d";
766
        $SQL = sprintf($SQL, $displayId);
767
768
        if (!$mediaInventoryXml = $db->GetSingleValue($SQL, 'MediaInventoryXml', _HTMLSTRING)) {
769
            trigger_error($db->error());
770
            trigger_error(__('Unable to get the Inventory for this Display'), E_USER_ERROR);
771
        }
772
773
        // Load the XML into a DOMDocument
774
        $document = new DOMDocument("1.0");
775
776
        if (!$document->loadXML($mediaInventoryXml))
777
            trigger_error(__('Invalid Media Inventory'), E_USER_ERROR);
778
779
        $cols = array(
780
            array('name' => 'id', 'title' => __('ID')),
781
            array('name' => 'type', 'title' => __('Type')),
782
            array('name' => 'complete', 'title' => __('Complete')),
783
            array('name' => 'last_checked', 'title' => __('Last Checked'))
784
        );
785
        Theme::Set('table_cols', $cols);
786
787
        // Need to parse the XML and return a set of rows
788
        $xpath = new DOMXPath($document);
789
        $fileNodes = $xpath->query("//file");
790
791
        $rows = array();
792
793
        foreach ($fileNodes as $node) {
794
            $row = array();
795
            $row['type'] = $node->getAttribute('type');
796
            $row['id'] = $node->getAttribute('id');
797
            $row['complete'] = ($node->getAttribute('complete') == 0) ? __('No') : __('Yes');
798
            $row['last_checked'] = $node->getAttribute('lastChecked');
799
            $row['md5'] = $node->getAttribute('md5');
800
801
            $rows[] = $row;
802
        }
803
804
        // Store the table rows
805
        Theme::Set('table_rows', $rows);
806
807
        $response->SetFormRequestResponse(Theme::RenderReturn('table_render'), __('Media Inventory'), '550px', '350px');
808
        $response->AddButton(__('Help'), 'XiboHelpRender("' . Help::Link('Display', 'MediaInventory') . '")');
809
        $response->AddButton(__('Close'), 'XiboDialogClose()');
810
811
    }
812
813
    /**
814
     * Get DisplayGroupID
815
     * @param <type> $displayId
816
     */
817
    private function GetDisplayGroupId($displayId)
818
    {
819
        $sql = "SELECT displaygroup.DisplayGroupID ";
820
        $sql .= "  FROM `displaygroup` ";
821
        $sql .= "   INNER JOIN `lkdisplaydg` ON lkdisplaydg.DisplayGroupID = displaygroup.DisplayGroupID ";
822
        $sql .= " WHERE displaygroup.IsDisplaySpecific = 1 AND lkdisplaydg.DisplayID = %d";
823
824
        if (!$id = $this->db->GetSingleValue(sprintf($sql, $displayId), 'DisplayGroupID', _INT)) {
825
            trigger_error($this->db->error());
826
            trigger_error(__('Unable to determine permissions'), E_USER_ERROR);
827
        }
828
829
        return $id;
830
    }
831
832
    /**
833
     * Member of Display Groups Form
834
     */
835
    public function MemberOfForm()
836
    {
837
838
        $response = $this->getState();
839
        $displayID = \Xibo\Helper\Sanitize::getInt('DisplayID');
840
841
        // Auth
842
        $auth = $this->user->DisplayGroupAuth($this->GetDisplayGroupId($displayID), true);
843
        if (!$auth->modifyPermissions)
844
            trigger_error(__('You do not have permission to change Display Groups on this display'), E_USER_ERROR);
845
846
        // There needs to be two lists here.
847
        //  - DisplayGroups this Display is already assigned to
848
        //  - DisplayGroups this Display could be assigned to
849
850
        // Set some information about the form
851
        Theme::Set('displaygroups_assigned_id', 'displaysIn');
852
        Theme::Set('displaygroups_available_id', 'displaysOut');
853
        Theme::Set('displaygroups_assigned_url', 'index.php?p=display&q=SetMemberOf&DisplayID=' . $displayID);
854
855
        // Display Groups Assigned
856
        $SQL = "";
857
        $SQL .= "SELECT displaygroup.DisplayGroupID, ";
858
        $SQL .= "       displaygroup.DisplayGroup, ";
859
        $SQL .= "       CONCAT('DisplayGroupID_', displaygroup.DisplayGroupID) AS list_id ";
860
        $SQL .= "FROM   displaygroup ";
861
        $SQL .= "   INNER JOIN lkdisplaydg ON lkdisplaydg.DisplayGroupID = displaygroup.DisplayGroupID ";
862
        $SQL .= sprintf("WHERE  lkdisplaydg.DisplayID   = %d ", $displayID);
863
        $SQL .= " AND displaygroup.IsDisplaySpecific = 0 ";
864
        $SQL .= " ORDER BY displaygroup.DisplayGroup ";
865
866
        $displaygroupsAssigned = $db->GetArray($SQL);
867
868
        if (!is_array($displaygroupsAssigned)) {
869
            trigger_error($db->error());
870
            trigger_error(__('Error getting Display Groups'), E_USER_ERROR);
871
        }
872
873
        Theme::Set('displaygroups_assigned', $displaygroupsAssigned);
874
875
        // Display Groups not assigned
876
        $SQL = "";
877
        $SQL .= "SELECT displaygroup.DisplayGroupID, ";
878
        $SQL .= "       displaygroup.DisplayGroup, ";
879
        $SQL .= "       CONCAT('DisplayGroupID_', displaygroup.DisplayGroupID) AS list_id ";
880
        $SQL .= "  FROM displaygroup ";
881
        $SQL .= " WHERE displaygroup.IsDisplaySpecific = 0 ";
882
        $SQL .= " AND displaygroup.DisplayGroupID NOT IN ";
883
        $SQL .= "       (SELECT lkdisplaydg.DisplayGroupID ";
884
        $SQL .= "          FROM lkdisplaydg ";
885
        $SQL .= sprintf(" WHERE  lkdisplaydg.DisplayID   = %d ", $displayID);
886
        $SQL .= "       )";
887
        $SQL .= " ORDER BY displaygroup.DisplayGroup ";
888
889
        Log::notice($SQL);
890
891
        $displaygroups_available = $db->GetArray($SQL);
892
893
        if (!is_array($displaygroups_available)) {
894
            trigger_error($db->error());
895
            trigger_error(__('Error getting Display Groups'), E_USER_ERROR);
896
        }
897
898
        Theme::Set('displaygroups_available', $displaygroups_available);
899
900
        // Render the theme
901
        $form = Theme::RenderReturn('display_form_group_assign');
902
903
        $response->SetFormRequestResponse($form, __('Manage Membership'), '400', '375', 'DisplayGroupManageMembersCallBack');
904
        $response->AddButton(__('Help'), 'XiboHelpRender("' . Help::Link('DisplayGroup', 'Members') . '")');
905
        $response->AddButton(__('Cancel'), 'XiboDialogClose()');
906
        $response->AddButton(__('Save'), 'DisplayGroupMembersSubmit()');
907
908
    }
909
910
    /**
911
     * Sets the Members of a group
912
     * @return
913
     */
914
    public function SetMemberOf()
915
    {
916
917
        $response = $this->getState();
918
919
920
        $displayGroupObject = new DisplayGroup($db);
921
922
        $displayID = \Xibo\Helper\Sanitize::getInt('DisplayID');
923
        $displayGroups = \Kit::GetParam('DisplayGroupID', _POST, _ARRAY, array());
924
        $members = array();
925
926
        // Get a list of current members
927
        $SQL = "";
928
        $SQL .= "SELECT displaygroup.DisplayGroupID ";
929
        $SQL .= "FROM   displaygroup ";
930
        $SQL .= "   INNER JOIN lkdisplaydg ON lkdisplaydg.DisplayGroupID = displaygroup.DisplayGroupID ";
931
        $SQL .= sprintf("WHERE  lkdisplaydg.DisplayID   = %d ", $displayID);
932
        $SQL .= " AND displaygroup.IsDisplaySpecific = 0 ";
933
934
        if (!$resultIn = $db->query($SQL)) {
935
            trigger_error($db->error());
936
            trigger_error(__('Error getting Display Groups'), E_USER_ERROR);
937
        }
938
939
        while ($row = $db->get_assoc_row($resultIn)) {
940
            // Test whether this ID is in the array or not
941
            $displayGroupID = \Xibo\Helper\Sanitize::int($row['DisplayGroupID']);
942
943
            if (!in_array($displayGroupID, $displayGroups)) {
944
                // Its currently assigned but not in the $displays array
945
                //  so we unassign
946
                if (!$displayGroupObject->Unlink($displayGroupID, $displayID)) {
947
                    trigger_error($displayGroupObject->GetErrorMessage(), E_USER_ERROR);
948
                }
949
            } else {
950
                $members[] = $displayGroupID;
951
            }
952
        }
953
954
        foreach ($displayGroups as $displayGroupID) {
955
            // Add any that are missing
956
            if (!in_array($displayGroupID, $members)) {
957
                if (!$displayGroupObject->Link($displayGroupID, $displayID)) {
958
                    trigger_error($displayGroupObject->GetErrorMessage(), E_USER_ERROR);
959
                }
960
            }
961
        }
962
963
        $response->SetFormSubmitResponse(__('Group membership set'), false);
964
965
    }
966
967
    /**
968
     * Form for wake on Lan
969
     */
970
    public function WakeOnLanForm()
971
    {
972
973
        $response = $this->getState();
974
975
        $displayId = \Xibo\Helper\Sanitize::getInt('DisplayId');
976
977
        // Get the MAC Address
978
        $macAddress = $db->GetSingleValue(sprintf("SELECT MacAddress FROM `display` WHERE DisplayID = %d", $displayId), 'MacAddress', _STRING);
979
980
        if (!$macAddress || $macAddress == '')
981
            trigger_error(__('This display has no mac address recorded against it yet. Make sure the display is running.'), E_USER_ERROR);
982
983
        // Set some information about the form
984
        Theme::Set('form_id', 'WakeOnLanForm');
985
        Theme::Set('form_action', 'index.php?p=display&q=WakeOnLan');
986
        Theme::Set('form_meta', '<input type="hidden" name="DisplayId" value="' . $displayId . '"><input type="hidden" name="MacAddress" value="' . $macAddress . '">');
987
988
        Theme::Set('form_fields', array(FormManager::AddMessage(__('Are you sure you want to send a Wake On Lan message to this display?'))));
989
990
        $response->SetFormRequestResponse(NULL, __('Wake On Lan'), '300px', '250px');
991
        $response->AddButton(__('Cancel'), 'XiboDialogClose()');
992
        $response->AddButton(__('Send'), '$("#WakeOnLanForm").submit()');
993
994
    }
995
996
    /**
997
     * Wake on LAN
998
     */
999
    public function WakeOnLan()
1000
    {
1001
1002
1003
1004
        $response = $this->getState();
1005
        $displayObject = new Display($db);
1006
1007
        $displayId = \Xibo\Helper\Sanitize::getInt('DisplayId');
1008
1009
        if (!$displayObject->WakeOnLan($displayId))
1010
            trigger_error($displayObject->GetErrorMessage(), E_USER_ERROR);
1011
1012
        $response->SetFormSubmitResponse(__('Wake on Lan command sent.'));
1013
1014
    }
1015
1016
    public function ScreenShot()
1017
    {
1018
        $displayId = \Xibo\Helper\Sanitize::getInt('DisplayId');
1019
1020
        // Output an image if present, otherwise not found image.
1021
        $file = 'screenshots/' . $displayId . '_screenshot.jpg';
1022
1023
        // File upload directory.. get this from the settings object
1024
        $library = Config::GetSetting("LIBRARY_LOCATION");
1025
        $fileName = $library . $file;
1026
1027
        if (!file_exists($fileName)) {
1028
            $fileName = Theme::ImageUrl('forms/filenotfound.gif');
1029
        }
1030
1031
        $size = filesize($fileName);
1032
1033
        $fi = new finfo(FILEINFO_MIME_TYPE);
1034
        $mime = $fi->file($fileName);
1035
        header("Content-Type: {$mime}");
1036
1037
        //Output a header
1038
        header('Cache-Control: no-cache, must-revalidate');
1039
        header('Content-Length: ' . $size);
1040
1041
        // Return the file with PHP
1042
        // Disable any buffering to prevent OOM errors.
1043
        @ob_end_clean();
1044
        @ob_end_flush();
1045
        readfile($fileName);
1046
    }
1047
1048
    public function RequestScreenShotForm()
1049
    {
1050
1051
        $response = $this->getState();
1052
1053
        $displayId = \Xibo\Helper\Sanitize::getInt('displayId');
1054
1055
        // Set some information about the form
1056
        Theme::Set('form_id', 'RequestScreenShotForm');
1057
        Theme::Set('form_action', 'index.php?p=display&q=RequestScreenShot');
1058
        Theme::Set('form_meta', '<input type="hidden" name="displayId" value="' . $displayId . '">');
1059
1060
        Theme::Set('form_fields', array(FormManager::AddMessage(__('Are you sure you want to request a screen shot? The next time the client connects to the CMS the screen shot will be sent.'))));
1061
1062
        $response->SetFormRequestResponse(NULL, __('Request Screen Shot'), '300px', '250px');
1063
        $response->AddButton(__('Cancel'), 'XiboDialogClose()');
1064
        $response->AddButton(__('Request'), '$("#RequestScreenShotForm").submit()');
1065
1066
    }
1067
1068
    public function RequestScreenShot()
1069
    {
1070
1071
1072
1073
        $response = $this->getState();
1074
        $displayObject = new Display($db);
1075
1076
        $displayId = \Xibo\Helper\Sanitize::getInt('displayId');
1077
1078
        if (!$displayObject->RequestScreenShot($displayId))
1079
            trigger_error($displayObject->GetErrorMessage(), E_USER_ERROR);
1080
1081
        $response->SetFormSubmitResponse(__('Request Sent.'));
1082
1083
    }
1084
}
1085
1086
?>