Merge lp:~dangarner/xibo/bug-455630 into lp:~xibo-maintainers/xibo/encke

Proposed by Dan Garner
Status: Merged
Merged at revision: not available
Proposed branch: lp:~dangarner/xibo/bug-455630
Merge into: lp:~xibo-maintainers/xibo/encke
Diff against target: 1933 lines (+1742/-43)
10 files modified
server/install/database/7.sql (+4/-0)
server/install/database/8.sql (+36/-16)
server/lib/modules/module.class.php (+19/-0)
server/lib/pages/content.class.php (+3/-18)
server/modules/flash.module.php (+1/-1)
server/modules/image.module.php (+1/-1)
server/modules/powerpoint.module.php (+17/-6)
server/modules/video.module.php (+1/-1)
server/upgrade.php.OTHER (+598/-0)
server/xmds.php (+1062/-0)
To merge this branch: bzr merge lp:~dangarner/xibo/bug-455630
Reviewer Review Type Date Requested Status
Xibo Maintainters Pending
Review via email: mp+15374@code.launchpad.net
To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'server/install/database/7.sql'
--- server/install/database/7.sql 2009-09-26 12:09:58 +0000
+++ server/install/database/7.sql 2009-11-29 18:45:38 +0000
@@ -21,4 +21,8 @@
2121
22UPDATE `version` SET `app_ver` = '1.0.3';22UPDATE `version` SET `app_ver` = '1.0.3';
23UPDATE `setting` SET `value` = 0 WHERE `setting` = 'PHONE_HOME_DATE';23UPDATE `setting` SET `value` = 0 WHERE `setting` = 'PHONE_HOME_DATE';
24<<<<<<< TREE
24UPDATE `version` SET `DBVersion` = '7';25UPDATE `version` SET `DBVersion` = '7';
26=======
27UPDATE `version` SET `DBVersion` = '7';
28>>>>>>> MERGE-SOURCE
2529
=== modified file 'server/install/database/8.sql'
--- server/install/database/8.sql 2009-10-04 17:40:01 +0000
+++ server/install/database/8.sql 2009-11-29 18:45:38 +0000
@@ -1,16 +1,36 @@
1ALTER TABLE `media` ADD `MD5` VARCHAR( 32 ) NULL AFTER `storedAs` ,1<<<<<<< TREE
2ADD `FileSize` BIGINT NULL AFTER `MD5` ;2ALTER TABLE `media` ADD `MD5` VARCHAR( 32 ) NULL AFTER `storedAs` ,
33ADD `FileSize` BIGINT NULL AFTER `MD5` ;
4ALTER TABLE `module` ADD `ValidExtensions` VARCHAR( 254 ) NULL ;4
55ALTER TABLE `module` ADD `ValidExtensions` VARCHAR( 254 ) NULL ;
6UPDATE `module` SET `ValidExtensions` = 'jpg,jpeg,png,bmp,gif' WHERE `module`.`ModuleID` =1 LIMIT 1 ;6
77UPDATE `module` SET `ValidExtensions` = 'jpg,jpeg,png,bmp,gif' WHERE `module`.`ModuleID` =1 LIMIT 1 ;
8UPDATE `module` SET `ValidExtensions` = 'wmv,avi,mpg,mpeg' WHERE `module`.`ModuleID` =2 LIMIT 1 ;8
99UPDATE `module` SET `ValidExtensions` = 'wmv,avi,mpg,mpeg' WHERE `module`.`ModuleID` =2 LIMIT 1 ;
10UPDATE `module` SET `ValidExtensions` = 'swf' WHERE `module`.`ModuleID` =3 LIMIT 1 ;10
1111UPDATE `module` SET `ValidExtensions` = 'swf' WHERE `module`.`ModuleID` =3 LIMIT 1 ;
12UPDATE `module` SET `ValidExtensions` = 'ppt,pps' WHERE `module`.`ModuleID` =4 LIMIT 1 ;12
1313UPDATE `module` SET `ValidExtensions` = 'ppt,pps' WHERE `module`.`ModuleID` =4 LIMIT 1 ;
14UPDATE `version` SET `app_ver` = '1.0.4';14
15UPDATE `setting` SET `value` = 0 WHERE `setting` = 'PHONE_HOME_DATE';15UPDATE `version` SET `app_ver` = '1.0.4';
16UPDATE `version` SET `DBVersion` = '8';16UPDATE `setting` SET `value` = 0 WHERE `setting` = 'PHONE_HOME_DATE';
17UPDATE `version` SET `DBVersion` = '8';
18=======
19ALTER TABLE `module` ADD `ValidExtensions` VARCHAR( 254 ) NULL ;
20
21UPDATE `module` SET `ValidExtensions` = 'jpg,jpeg,png,bmp,gif' WHERE `module`.`ModuleID` =1 LIMIT 1 ;
22
23UPDATE `module` SET `ValidExtensions` = 'wmv,avi,mpg,mpeg' WHERE `module`.`ModuleID` =2 LIMIT 1 ;
24
25UPDATE `module` SET `ValidExtensions` = 'swf' WHERE `module`.`ModuleID` =3 LIMIT 1 ;
26
27UPDATE `module` SET `ValidExtensions` = 'ppt,pps' WHERE `module`.`ModuleID` =4 LIMIT 1 ;
28
29/* Add the MD5 and FileSize as columns to the media table */
30ALTER TABLE `media` ADD `MD5` VARCHAR( 32 ) NULL AFTER `storedAs` ,
31ADD `FileSize` BIGINT NULL AFTER `MD5` ;
32
33UPDATE `version` SET `app_ver` = '1.0.4';
34UPDATE `setting` SET `value` = 0 WHERE `setting` = 'PHONE_HOME_DATE';
35UPDATE `version` SET `DBVersion` = '8';
36>>>>>>> MERGE-SOURCE
1737
=== modified file 'server/lib/modules/module.class.php'
--- server/lib/modules/module.class.php 2009-10-04 17:40:01 +0000
+++ server/lib/modules/module.class.php 2009-11-29 18:45:38 +0000
@@ -516,8 +516,15 @@
516 */516 */
517 public function EditForm()517 public function EditForm()
518 {518 {
519<<<<<<< TREE
519 $form = '<p>' . __('Not yet implemented by this module.') . '</p>';520 $form = '<p>' . __('Not yet implemented by this module.') . '</p>';
520521
522=======
523 $form = <<<END
524 <p>Not yet implemented by this module.</p>
525END;
526
527>>>>>>> MERGE-SOURCE
521 $this->response->html = $form;528 $this->response->html = $form;
522 $this->response->dialogTitle = __('Add Item');529 $this->response->dialogTitle = __('Add Item');
523 $this->response->dialogSize = true;530 $this->response->dialogSize = true;
@@ -534,9 +541,15 @@
534 public function AddMedia()541 public function AddMedia()
535 {542 {
536 // We want to load a new form543 // We want to load a new form
544<<<<<<< TREE
537 $this->response->message = __('Add Media has not been implemented for this module.');545 $this->response->message = __('Add Media has not been implemented for this module.');
538 546
539 return $this->response; 547 return $this->response;
548=======
549 $this->response->message = 'Add Media has not been implemented for this module.';
550
551 return $this->response;
552>>>>>>> MERGE-SOURCE
540 }553 }
541554
542 /**555 /**
@@ -546,9 +559,15 @@
546 public function EditMedia()559 public function EditMedia()
547 {560 {
548 // We want to load a new form561 // We want to load a new form
562<<<<<<< TREE
549 $this->response->message = __('Edit Media has not been implemented for this module.');563 $this->response->message = __('Edit Media has not been implemented for this module.');
550 564
551 return $this->response; 565 return $this->response;
566=======
567 $this->response->message = 'Edit Media has not been implemented for this module.';
568
569 return $this->response;
570>>>>>>> MERGE-SOURCE
552 }571 }
553572
554 /**573 /**
555574
=== modified file 'server/lib/pages/content.class.php'
--- server/lib/pages/content.class.php 2009-10-09 20:27:08 +0000
+++ server/lib/pages/content.class.php 2009-11-29 18:45:38 +0000
@@ -27,22 +27,6 @@
27 private $isadmin = false;27 private $isadmin = false;
28 private $has_permissions = true;28 private $has_permissions = true;
29 private $sub_page = "";29 private $sub_page = "";
30
31 //Table Fields
32 private $mediaid;
33 private $name = "";
34 private $filepath = "";
35 private $type = "";
36 private $length = "";
37 private $width = "";
38 private $height = "";
39 private $permissionid;
40 private $media_class = "";
41 private $retired;
42
43 //are we redirecting to another page once we are done?
44 private $redirect = false;
45 private $redirect_addr = "";
4630
47 function __construct(database $db, user $user) 31 function __construct(database $db, user $user)
48 {32 {
@@ -653,8 +637,8 @@
653 637
654 if (isset($_FILES["media_file"]) && is_uploaded_file($_FILES["media_file"]["tmp_name"]) && $_FILES["media_file"]["error"] == 0) 638 if (isset($_FILES["media_file"]) && is_uploaded_file($_FILES["media_file"]["tmp_name"]) && $_FILES["media_file"]["error"] == 0)
655 {639 {
656 $error = 0;640 $error = 0;
657 $fileName = $_FILES["media_file"]["name"];641 $fileName = Kit::ValidateParam($_FILES["media_file"]["name"], _FILENAME);
658 $fileLocation = $libraryFolder."temp/".$fileId;642 $fileLocation = $libraryFolder."temp/".$fileId;
659 643
660 // Save the FILE644 // Save the FILE
@@ -697,6 +681,7 @@
697 681
698 echo $complete_page;682 echo $complete_page;
699 683
684 Debug::LogEntry($db, "audit", $complete_page, "FileUpload");
700 Debug::LogEntry($db, "audit", "[OUT]", "FileUpload");685 Debug::LogEntry($db, "audit", "[OUT]", "FileUpload");
701 exit;686 exit;
702 }687 }
703688
=== modified file 'server/modules/flash.module.php'
--- server/modules/flash.module.php 2009-10-04 17:40:01 +0000
+++ server/modules/flash.module.php 2009-11-29 18:45:38 +0000
@@ -706,7 +706,7 @@
706 }706 }
707707
708 // Ensure the name is not already in the database708 // Ensure the name is not already in the database
709 $SQL = sprintf("SELECT name FROM media WHERE name = '%s' AND userid = %d AND mediaid <> %d ", $db->escape_string($name), $userid, $mediaid);709 $SQL = sprintf("SELECT name FROM media WHERE name = '%s' AND userid = %d AND mediaid <> %d AND IsEdited = 0 ", $db->escape_string($name), $userid, $mediaid);
710710
711 if(!$result = $db->query($SQL))711 if(!$result = $db->query($SQL))
712 {712 {
713713
=== modified file 'server/modules/image.module.php'
--- server/modules/image.module.php 2009-10-04 17:40:01 +0000
+++ server/modules/image.module.php 2009-11-29 18:45:39 +0000
@@ -709,7 +709,7 @@
709 }709 }
710710
711 // Ensure the name is not already in the database711 // Ensure the name is not already in the database
712 $SQL = sprintf("SELECT name FROM media WHERE name = '%s' AND userid = %d AND mediaid <> %d ", $db->escape_string($name), $userid, $mediaid);712 $SQL = sprintf("SELECT name FROM media WHERE name = '%s' AND userid = %d AND mediaid <> %d AND IsEdited = 0", $db->escape_string($name), $userid, $mediaid);
713713
714 if(!$result = $db->query($SQL))714 if(!$result = $db->query($SQL))
715 {715 {
716716
=== modified file 'server/modules/powerpoint.module.php'
--- server/modules/powerpoint.module.php 2009-10-04 17:40:01 +0000
+++ server/modules/powerpoint.module.php 2009-11-29 18:45:39 +0000
@@ -599,9 +599,14 @@
599 $fileSize = filesize($databaseDir.$storedAs);599 $fileSize = filesize($databaseDir.$storedAs);
600600
601 // Update the media record to include this information601 // Update the media record to include this information
602602<<<<<<< TREE
603 $SQL = sprintf("UPDATE media SET storedAs = '%s', `MD5` = '%s', FileSize = %d WHERE mediaid = %d", $storedAs, $md5, $fileSize, $mediaid);603
604604 $SQL = sprintf("UPDATE media SET storedAs = '%s', `MD5` = '%s', FileSize = %d WHERE mediaid = %d", $storedAs, $md5, $fileSize, $mediaid);
605
606=======
607 $SQL = sprintf("UPDATE media SET storedAs = '%s', `MD5` = '%s', FileSize = %d WHERE mediaid = %d", $storedAs, $md5, $fileSize, $mediaid);
608
609>>>>>>> MERGE-SOURCE
605 if (!$db->query($SQL))610 if (!$db->query($SQL))
606 {611 {
607 trigger_error($db->error());612 trigger_error($db->error());
@@ -663,8 +668,14 @@
663 $fileName = Kit::GetParam('txtFileName', _POST, _STRING);668 $fileName = Kit::GetParam('txtFileName', _POST, _STRING);
664 $fileName = basename($fileName);669 $fileName = basename($fileName);
665 $ext = strtolower(substr(strrchr($fileName, "."), 1));670 $ext = strtolower(substr(strrchr($fileName, "."), 1));
666671<<<<<<< TREE
667 if (!$this->IsValidExtension($ext))672
673 if (!$this->IsValidExtension($ext))
674=======
675
676
677 if (!$this->IsValidExtension($ext))
678>>>>>>> MERGE-SOURCE
668 {679 {
669 $this->response->SetError('Your file has an extension not supported by this Media Type.');680 $this->response->SetError('Your file has an extension not supported by this Media Type.');
670 $this->response->keepOpen = true;681 $this->response->keepOpen = true;
@@ -707,7 +718,7 @@
707 }718 }
708719
709 // Ensure the name is not already in the database720 // Ensure the name is not already in the database
710 $SQL = sprintf("SELECT name FROM media WHERE name = '%s' AND userid = %d AND mediaid <> %d ", $db->escape_string($name), $userid, $mediaid);721 $SQL = sprintf("SELECT name FROM media WHERE name = '%s' AND userid = %d AND mediaid <> %d AND IsEdited = 0", $db->escape_string($name), $userid, $mediaid);
711722
712 if(!$result = $db->query($SQL))723 if(!$result = $db->query($SQL))
713 {724 {
714725
=== modified file 'server/modules/video.module.php'
--- server/modules/video.module.php 2009-10-04 17:40:01 +0000
+++ server/modules/video.module.php 2009-11-29 18:45:39 +0000
@@ -693,7 +693,7 @@
693 }693 }
694694
695 // Ensure the name is not already in the database695 // Ensure the name is not already in the database
696 $SQL = sprintf("SELECT name FROM media WHERE name = '%s' AND userid = %d AND mediaid <> %d ", $db->escape_string($name), $userid, $mediaid);696 $SQL = sprintf("SELECT name FROM media WHERE name = '%s' AND userid = %d AND mediaid <> %d AND IsEdited = 0", $db->escape_string($name), $userid, $mediaid);
697697
698 if(!$result = $db->query($SQL))698 if(!$result = $db->query($SQL))
699 {699 {
700700
=== added file 'server/upgrade.php.OTHER'
--- server/upgrade.php.OTHER 1970-01-01 00:00:00 +0000
+++ server/upgrade.php.OTHER 2009-11-29 18:45:38 +0000
@@ -0,0 +1,598 @@
1<?php
2/*
3 * Xibo - Digitial Signage - http://www.xibo.org.uk
4 * Copyright (C) 2009 Alex Harrington
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
22DEFINE('XIBO', true);
23
24include('lib/app/kit.class.php');
25include('config/db_config.php');
26include('config/config.class.php');
27require('settings.php');
28
29// Once we've calculated the upgrade in step 2 below, we need
30// to have included the appropriate upgrade php files
31// before we restore the session, so objects get recreated properly.
32//
33// Check to see if we've passed that point, and if so look at what was posted
34// to include those classes.
35
36if (Kit::GetParam("includes", _POST, _BOOL)) {
37 foreach ($_POST as $key => $post) {
38 // $key should be like 1-2, 1-3 etc
39 // Split $key on - character.
40
41 $parts = explode('-', $key);
42 if (count($parts) == 2) {
43 $step = Kit::ValidateParam($parts[0], _INT);
44 if (file_exists('install/database/' . $step . '.php')) {
45 include_once('install/database/' . $step . '.php');
46 }
47 }
48 }
49}
50
51session_start();
52
53define('_CHECKBOX', "checkbox");
54define('_INPUTBOX', "inputbox");
55define('_PASSWORDBOX', "password");
56
57// create a database class instance
58$db = new database();
59
60if (!$db->connect_db($dbhost, $dbuser, $dbpass)) reportError(0, "Unable to connect to the MySQL database using the settings stored in settings.php.<br /><br />MySQL Error:<br />" . $db->error());
61if (!$db->select_db($dbname)) reportError(0, "Unable to select the MySQL database using the settings stored in settings.php.<br /><br />MySQL Error:<br />" . $db->error());
62
63include('install/header_upgrade.inc');
64
65if (! $_SESSION['step']) {
66 $_SESSION['step'] = 0;
67}
68
69if (Kit::GetParam('skipstep',_POST,_INT) == 1) {
70 // Cheat the $_SESSION['step'] variable if required
71 // Used if there are environment warnings and we want to retest.
72 $_SESSION['step'] = 1;
73}
74
75if ($_SESSION['step'] == 0) {
76
77 $_SESSION['step'] = 1;
78
79 # First step of the process.
80 # Show a welcome screen and authenticate the user
81 ?>
82 Welcome to the Xibo Upgrade!<br /><br />
83 The upgrade program will take you through the process one step at a time.<br /><br />
84 Lets get started!<br /><br />
85 Please enter your xibo_admin password:<br /><br />
86 <form action="upgrade.php" method="POST">
87 <div class="install_table">
88 <input type="password" name="password" length="12" />
89 </div>
90 <div class="loginbutton"><button type="submit">Next ></button></div>
91 </form>
92 <?php
93}
94elseif ($_SESSION['step'] == 1) {
95 $_SESSION['step'] = 2;
96
97 if (! $_SESSION['auth']) {
98
99 # Check password
100
101 $password = Kit::GetParam('password',_POST,_PASSWORD);
102 $password_hash = md5($password);
103
104 $SQL = sprintf("SELECT `UserID` FROM `user` WHERE UserPassword='%s' AND UserName='xibo_admin'",
105 $db->escape_string($password_hash));
106 if (! $result = $db->query($SQL)) {
107 reportError("0", "An error occured checking your password.<br /><br />MySQL Error:<br />" . mysql_error());
108 }
109
110 if ($db->num_rows($result) == 0) {
111 $_SESSION['auth'] = false;
112 reportError("0", "Password incorrect. Please try again.");
113 }
114 else {
115 $_SESSION['auth'] = true;
116 $_SESSION['db'] = $db;
117 }
118
119 }
120## Check server meets specs (as specs might have changed in this release)
121 ?>
122 <p>First we need to check if your server meets Xibo's requirements.</p>
123 <?php
124 $db = new Database();
125 $cObj = new Config($db);
126 echo $cObj->CheckEnvironment();
127 if ($cObj->EnvironmentFault()) {
128 $_SESSION['step'] = 1;
129 ?>
130 <form action="upgrade.php" method="POST">
131 <div class="loginbutton"><button type="submit">Retest</button></div>
132 </form>
133 <?php
134 }
135 else if ($cObj->EnvironmentWarning()) {
136 ?>
137 <form action="upgrade.php" method="POST">
138 <input type="hidden" name="skipstep" value="1">
139 <div class="loginbutton"><button type="submit">Retest</button></div>
140 </form>
141 <form action="upgrade.php" method="POST">
142 <div class="loginbutton"><button type="submit">Next ></button></div>
143 </form>
144 <?php
145 }
146 else {
147 ?>
148 <form action="upgrade.php" method="POST">
149 <div class="loginbutton"><button type="submit">Next ></button></div>
150 </form>
151 <?php
152 }
153}
154elseif ($_SESSION['step'] == 2) {
155 checkAuth();
156# Calculate the upgrade
157
158 $_SESSION['upgradeFrom'] = Config::Version($db, 'DBVersion');
159
160 if ($_SESSION['upgradeFrom'] < 1) {
161 $_SESSION['upgradeFrom'] = 1;
162 }
163
164 // Get a list of .sql and .php files for the upgrade
165 $sql_files = ls('*.sql','install/database',false,array('return_files'));
166 $php_files = ls('*.php','install/database',false,array('return_files'));
167
168 // Sort by natural filename (eg 10 is bigger than 2)
169 natcasesort($sql_files);
170 natcasesort($php_files);
171
172 $_SESSION['phpFiles'] = $php_files;
173 $_SESSION['sqlFiles'] = $sql_files;
174
175 $max_sql = Kit::ValidateParam(substr(end($sql_files),0,-4),_INT);
176 $max_php = Kit::ValidateParam(substr(end($php_files),0,-4),_INT);
177 $_SESSION['upgradeTo'] = max($max_sql, $max_php);
178
179 if (! $_SESSION['upgradeTo']) {
180 reportError("2", "Unable to calculate the upgradeTo value. Check for non-numeric SQL and PHP files in the 'install/datbase' directory.", "Retry");
181 }
182
183 echo '<div class="info">';
184 echo '<p>Upgrading from database version ' . $_SESSION['upgradeFrom'] . ' to ' . $_SESSION['upgradeTo'];
185 echo '</p></div><hr width="25%"/>';
186 echo '<form action="upgrade.php" method="POST">';
187
188 // Loop for $i between upgradeFrom + 1 and upgradeTo.
189 // If a php file exists for that upgrade, make an instance of it and call Questions so we can
190 // Ask the user for input.
191 for ($i=$_SESSION['upgradeFrom'] + 1; $i <= $_SESSION['upgradeTo']; $i++) {
192 if (file_exists('install/database/' . $i . '.php')) {
193 include_once('install/database/' . $i . '.php');
194 $stepName = 'Step' . $i;
195
196 // Check that a class called Step$i exists
197 if (class_exists($stepName)) {
198 $_SESSION['Step' . $i] = new $stepName($db);
199 // Call Questions on the object and send the resulting hash to createQuestions routine
200 createQuestions($i, $_SESSION['Step' . $i]->Questions());
201 }
202 else {
203 print "Warning: We included $i.php, but it did not include a class of appropriate name.";
204 }
205 }
206 }
207
208 echo '<div class="info"><p>';
209 echo "Perform automatic database upgrade?";
210 echo '</p></div><div class="install-table">';
211 echo '<input type="checkbox" name="doBackup" checked />';
212 echo '</div><hr width="25%" />';
213
214 $_SESSION['step'] = 3;
215 echo '<input type="hidden" name="includes" value="true" />';
216 echo '<p><input type="submit" value="Next >" /></p>';
217 echo '</form>';
218
219?>
220 <?php
221}
222elseif ($_SESSION['step'] == 3) {
223 // $_SESSION['step'] = 0;
224 $fault = false;
225 $fault_string = "";
226
227 foreach ($_POST as $key => $post) {
228 // $key should be like 1-2, 1-3 etc
229 // Split $key on - character.
230
231 $parts = explode('-', $key);
232 if (count($parts) == 2) {
233 $step_num = 'Step' . $parts[0];
234 include_once('install/database/' . $parts[0] . '.php');
235 // $_SESSION['q'][$step_num] = unserialize($_SESSION['q'][$step_num]);
236;
237 $response = $_SESSION[$step_num]->ValidateQuestion($parts[1], $post);
238 if (! $response == true) {
239 // The upgrade routine for this step wasn't happy.
240 $fault = true;
241 $fault_string .= $response . "<br />\n";
242 }
243 }
244 }
245
246 if ($fault) {
247 // Report the error, and a back button
248 echo "FAIL: " . $fault_string;
249 }
250 else {
251 $doBackup = Kit::GetParam("doBackup", $_POST, _BOOL);
252
253 set_time_limit(0);
254 // Backup the database
255 echo '<div class="info"><p>';
256 if ($doBackup) {
257 echo 'Backing up your database';
258 backup_tables($db, '*');
259 }
260 else {
261 echo 'Skipping database backup';
262 }
263 echo '</p>';
264
265 $sqlStatementCount = 0;
266 // Now loop over the entire upgrade. Run the SQLs and PHP interleaved.
267 for ($i=$_SESSION['upgradeFrom'] + 1; (($i <= $_SESSION['upgradeTo']) && ($fault==false)) ; $i++) {
268 if (file_exists('install/database/' . $i . '.sql')) {
269 echo '<p>' . $i . '.sql ';
270 flush();
271 $delimiter = ';';
272 $sql_file = @file_get_contents('install/database/' . $i . '.sql');
273 $sql_file = remove_remarks($sql_file);
274 $sql_file = split_sql_file($sql_file, $delimiter);
275
276 foreach ($sql_file as $sql) {
277 print ".";
278 $sqlStatementCount++;
279 flush();
280 if (! $db->query($sql)) {
281 $fault = true;
282 reportError("0", "An error occured populating the database.<br /><br />MySQL Error:<br />" . $db->error() . "<br /><br />SQL executed:<br />" . $sql . "<br /><br />Statement number: " . $sqlStatementCount);
283 }
284 }
285 echo '</p>';
286 }
287 if (file_exists('install/database/' . $i . '.php')) {
288 $stepName = 'Step' . $i;
289 echo '<p>' . $i . '.php ';
290 flush();
291 if (! $_SESSION[$stepName]->Boot()) {
292 $fault = true;
293 }
294 echo '</p>';
295 }
296 }
297 echo '</div>';
298 if (! $fault) {
299 if (! unlink('install.php')) {
300 echo "Unable to delete install.php. Please remove this file manually.";
301 }
302 if (! unlink('upgrade.php')) {
303 echo "Unable to delete upgrade.php. Please remove this file manually.";
304 }
305
306 echo '<b>Upgrade is complete!</b><br /><br />';
307 echo '<form method="POST" action="index.php">';
308 echo '<input type="submit" value="Login" />';
309 echo '</form>';
310 }
311 else {
312 echo '<b>There was an error during the upgrade. Please take a screenshot of this page and seek help!</b>';
313 }
314 session_destroy();
315 }
316}
317else {
318 reportError("0","A required parameter was missing. Please go through the installer sequentially!","Start Again");
319}
320
321include('install/footer.inc');
322
323# Functions
324function checkPHP() {
325 # Check PHP version > 5
326 return (version_compare("5.1.0",phpversion(), "<="));
327}
328
329function reportError($step, $message, $button_text="&lt; Back") {
330 $_SESSION['step'] = $step;
331?>
332 <div class="info">
333 <?php print $message; ?>
334 </div>
335 <form action="upgrade.php" method="POST">
336 <button type="submit"><?php print $button_text; ?></button>
337 </form>
338 <?php
339 include('install/footer.inc');
340 die();
341}
342
343function checkAuth() {
344 if (! $_SESSION['auth']) {
345 reportError(1, "You must authenticate to run the upgrade.");
346 }
347}
348
349// Taken from http://forums.devshed.com/php-development-5/php-wont-load-sql-from-file-515902.html
350// By Crackster
351/**
352 * remove_remarks will strip the sql comment lines out of an uploaded sql file
353 */
354function remove_remarks($sql){
355 $sql = preg_replace('/\n{2,}/', "\n", preg_replace('/^[-].*$/m', "\n", $sql));
356 $sql = preg_replace('/\n{2,}/', "\n", preg_replace('/^#.*$/m', "\n", $sql));
357 return $sql;
358}
359
360// Taken from http://forums.devshed.com/php-development-5/php-wont-load-sql-from-file-515902.html
361// By Crackster
362/**
363 * split_sql_file will split an uploaded sql file into single sql statements.
364 * Note: expects trim() to have already been run on $sql.
365 */
366function split_sql_file($sql, $delimiter){
367 $sql = str_replace("\r" , '', $sql);
368 $data = preg_split('/' . preg_quote($delimiter, '/') . '$/m', $sql);
369 $data = array_map('trim', $data);
370 // The empty case
371 $end_data = end($data);
372 if (empty($end_data))
373 {
374 unset($data[key($data)]);
375 }
376 return $data;
377}
378
379/**
380 * This funtion will take a pattern and a folder as the argument and go thru it(recursivly if needed)and return the list of
381 * all files in that folder.
382 * Link : http://www.bin-co.com/php/scripts/filesystem/ls/
383 * License : BSD
384 * Arguments : $pattern - The pattern to look out for [OPTIONAL]
385 * $folder - The path of the directory of which's directory list you want [OPTIONAL]
386 * $recursivly - The funtion will traverse the folder tree recursivly if this is true. Defaults to false. [OPTIONAL]
387 * $options - An array of values 'return_files' or 'return_folders' or both
388 * Returns : A flat list with the path of all the files(no folders) that matches the condition given.
389 */
390function ls($pattern="*", $folder="", $recursivly=false, $options=array('return_files','return_folders')) {
391 if($folder) {
392 $current_folder = realpath('.');
393 if(in_array('quiet', $options)) { // If quiet is on, we will suppress the 'no such folder' error
394 if(!file_exists($folder)) return array();
395 }
396
397 if(!chdir($folder)) return array();
398 }
399
400
401 $get_files = in_array('return_files', $options);
402 $get_folders= in_array('return_folders', $options);
403 $both = array();
404 $folders = array();
405
406 // Get the all files and folders in the given directory.
407 if($get_files) $both = glob($pattern, GLOB_BRACE + GLOB_MARK);
408 if($recursivly or $get_folders) $folders = glob("*", GLOB_ONLYDIR + GLOB_MARK);
409
410 //If a pattern is specified, make sure even the folders match that pattern.
411 $matching_folders = array();
412 if($pattern !== '*') $matching_folders = glob($pattern, GLOB_ONLYDIR + GLOB_MARK);
413
414 //Get just the files by removing the folders from the list of all files.
415 $all = array_values(array_diff($both,$folders));
416
417 if($recursivly or $get_folders) {
418 foreach ($folders as $this_folder) {
419 if($get_folders) {
420 //If a pattern is specified, make sure even the folders match that pattern.
421 if($pattern !== '*') {
422 if(in_array($this_folder, $matching_folders)) array_push($all, $this_folder);
423 }
424 else array_push($all, $this_folder);
425 }
426
427 if($recursivly) {
428 // Continue calling this function for all the folders
429 $deep_items = ls($pattern, $this_folder, $recursivly, $options); # :RECURSION:
430 foreach ($deep_items as $item) {
431 array_push($all, $this_folder . $item);
432 }
433 }
434 }
435 }
436
437 if($folder) chdir($current_folder);
438 return $all;
439}
440
441// Taken from http://davidwalsh.name/backup-mysql-database-php
442// No explicit license. Assumed public domain.
443// Ammended to use a database object by Alex Harrington.
444// If this is your code, and wish for us to remove it, please contact
445// info@xibo.org.uk
446/* backup the db OR just a table */
447function backup_tables($db,$tables = '*')
448{
449 //get all of the tables
450 if($tables == '*')
451 {
452 $tables = array();
453 $result = $db->query('SHOW TABLES');
454 while($row = $db->get_row($result))
455 {
456 $tables[] = $row[0];
457 }
458 }
459 else
460 {
461 $tables = is_array($tables) ? $tables : explode(',',$tables);
462 }
463
464 // Open file for writing at length 0.
465 $handle = fopen(Config::GetSetting($db,'LIBRARY_LOCATION') . 'db-backup-'.time().'-'.(md5(implode(',',$tables))).'.sql','w+');
466
467 //cycle through
468 foreach($tables as $table)
469 {
470 echo '.';
471 flush();
472 $result = $db->query('SELECT * FROM `'.$table .'`');
473 $num_fields = $db->num_fields($result);
474
475 $return = 'DROP TABLE IF EXISTS `'.$table.'`;';
476 fwrite($handle, $return);
477
478 $row2 = $db->get_row($db->query('SHOW CREATE TABLE `'.$table.'`'));
479 $return = "\n\n".$row2[1].";\n\n";
480 fwrite($handle,$return);
481
482 for ($i = 0; $i < $num_fields; $i++)
483 {
484 while($row = $db->get_row($result))
485 {
486 $return = 'INSERT INTO `'.$table.'` VALUES(';
487 fwrite($handle, $return);
488 for($j=0; $j<$num_fields; $j++)
489 {
490 $return = '';
491 $row[$j] = addslashes($row[$j]);
492 $row[$j] = ereg_replace("\n","\\n",$row[$j]);
493 if (isset($row[$j])) { $return.= '"'.$row[$j].'"' ; } else { $return.= '""'; }
494 if ($j<($num_fields-1)) { $return.= ','; }
495 fwrite($handle, $return);
496 }
497 $return = ");\n";
498 fwrite($handle, $return);
499 }
500 }
501 $return ="\n\n\n";
502 fwrite ($handle, $return);
503 }
504
505 fclose($handle);
506}
507
508
509function gen_secret() {
510 # Generates a random 12 character alphanumeric string to use as a salt
511 mt_srand((double)microtime()*1000000);
512 $key = "";
513 for ($i=0; $i < 12; $i++) {
514 $c = mt_rand(0,2);
515 if ($c == 0) {
516 $key .= chr(mt_rand(65,90));
517 }
518 elseif ($c == 1) {
519 $key .= chr(mt_rand(97,122));
520 }
521 else {
522 $key .= chr(mt_rand(48,57));
523 }
524 }
525
526 return $key;
527}
528
529function createQuestions($step, $questions) {
530 // Takes a multi-dimensional array eg:
531 // $q[0]['question'] = "May we collect anonymous usage statistics?";
532 // $q[0]['type'] = _CHECKBOX;
533 // $q[0]['default'] = true;
534 //
535 // And turns it in to an HTML form for the user to complete.
536 foreach ($questions as $qnum => $question) {
537 echo '<div class="info"><p>';
538 echo $question['question'];
539 echo '</p></div><div class="install-table">';
540
541 if (($question['type'] == _INPUTBOX) || ($question['type'] == _PASSWORD)) {
542 echo '<input type="';
543 if ($question['type'] == _INPUTBOX) {
544 echo 'text';
545 }
546 else {
547 echo 'password';
548 }
549 echo '" name="' . $step . '-' . $qnum .'" value="'. $question['default'] .'" length="12" />';
550 }
551 elseif ($question['type'] == _CHECKBOX) {
552 echo '<input type="checkbox" name="' . $step . '-' . $qnum . '" ';
553 if ($question['default']) {
554 echo 'checked ';
555 }
556 echo '/>';
557 }
558 echo '</div><hr width="25%" />';
559 }
560}
561
562//function __autoload($class_name) {
563// if (substr($class_name,0,4) == "Step") {
564// $class_name = substr($class_name,4);
565// require_once install/database/$class_name . '.php';
566// }
567//}
568
569class UpgradeStep
570{
571 protected $db;
572 protected $q;
573 protected $a;
574
575 public function __construct($db)
576 {
577 $this->db =& $db;
578 $this->q = array();
579 $this->a = array();
580 }
581
582 public function Boot()
583 {
584
585 }
586
587 public function Questions()
588 {
589 return array();
590 }
591
592 public function ValidateQuestion($questionNumber,$response)
593 {
594 return true;
595 }
596}
597
598?>
0599
=== modified file 'server/xmds.php'
--- server/xmds.php 2009-11-26 20:03:41 +0000
+++ server/xmds.php 2009-11-29 18:45:38 +0000
@@ -1,3 +1,4 @@
1<<<<<<< TREE
1<?php2<?php
2/*3/*
3 * Xibo - Digitial Signage - http://www.xibo.org.uk4 * Xibo - Digitial Signage - http://www.xibo.org.uk
@@ -1060,4 +1061,1065 @@
10601061
1061//Debug::LogEntry($db, 'audit', $service->debug_str, "xmds", "NuSOAP");1062//Debug::LogEntry($db, 'audit', $service->debug_str, "xmds", "NuSOAP");
10621063
1064=======
1065<?php
1066/*
1067 * Xibo - Digitial Signage - http://www.xibo.org.uk
1068 * Copyright (C) 2006,2007,2008 Daniel Garner and James Packer
1069 *
1070 * This file is part of Xibo.
1071 *
1072 * Xibo is free software: you can redistribute it and/or modify
1073 * it under the terms of the GNU Affero General Public License as published by
1074 * the Free Software Foundation, either version 3 of the License, or
1075 * any later version.
1076 *
1077 * Xibo is distributed in the hope that it will be useful,
1078 * but WITHOUT ANY WARRANTY; without even the implied warranty of
1079 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1080 * GNU Affero General Public License for more details.
1081 *
1082 * You should have received a copy of the GNU Affero General Public License
1083 * along with Xibo. If not, see <http://www.gnu.org/licenses/>.
1084 */
1085 DEFINE('XIBO', true);
1086 include_once("lib/xmds.inc.php");
1087
1088/**
1089 * Auths the hardwareKey
1090 * @return True is licensed, False if not
1091 * @param $hardwareKey Object
1092 */
1093function Auth($hardwareKey)
1094{
1095 global $db;
1096
1097 //check in the database for this hardwareKey
1098 $SQL = "SELECT licensed, inc_schedule, isAuditing, displayID FROM display WHERE license = '$hardwareKey'";
1099 if (!$result = $db->query($SQL))
1100 {
1101 trigger_error("License key query failed:" .$db->error());
1102 return false;
1103 }
1104
1105 //Is it there?
1106 if ($db->num_rows($result) == 0)
1107 {
1108 return false;
1109 }
1110 else
1111 {
1112 //we have seen this display before, so check the licensed value
1113 $row = $db->get_row($result);
1114 if ($row[0] == 0)
1115 {
1116 return false;
1117 }
1118 else
1119 {
1120 $time = date("Y-m-d H:i:s", time());
1121
1122 //Set the last accessed flag on the display
1123 $SQL = "UPDATE display SET lastaccessed = '$time', loggedin = 1 WHERE license = '$hardwareKey' ";
1124 if (!$result = $db->query($SQL))
1125 {
1126 trigger_error("Display update access failure: " .$db->error());
1127 }
1128
1129 //It is licensed
1130 return array("licensed" => true, "inc_schedule" => $row[1], "isAuditing" => $row[2], "displayid" => $row[3]);
1131 }
1132 }
1133
1134 return false;
1135}
1136
1137/**
1138 * Checks that the calling service is talking the correct version
1139 * @return
1140 * @param $version Object
1141 */
1142function CheckVersion($version)
1143{
1144 global $db;
1145
1146 // Look up the Service XMDS version from the Version table
1147 $serverVersion = Config::Version($db, 'XmdsVersion');
1148
1149 if ($version != $serverVersion)
1150 {
1151 Debug::LogEntry($db, 'audit', sprintf('A Client with an incorrect version connected. Client Version: [%s] Server Version [%s]', $version, $serverVersion));
1152 return false;
1153 }
1154
1155 return true;
1156}
1157
1158/**
1159 * Registers the Display with the server - if there is an available slot
1160 * @return
1161 * @param $serverKey Object
1162 * @param $hardwareKey Object
1163 * @param $displayName Object
1164 */
1165function RegisterDisplay($serverKey, $hardwareKey, $displayName, $version)
1166{
1167 global $db;
1168
1169 // Sanitize
1170 $serverKey = Kit::ValidateParam($serverKey, _STRING);
1171 $hardwareKey = Kit::ValidateParam($hardwareKey, _STRING);
1172 $displayName = Kit::ValidateParam($displayName, _STRING);
1173 $version = Kit::ValidateParam($version, _STRING);
1174
1175 // Make sure we are talking the same language
1176 if (!CheckVersion($version))
1177 {
1178 return new soap_fault("SOAP-ENV:Client", "", "Your client is not of the correct version for communication with this server. You can get the latest from http://www.xibo.org.uk", $serverKey);
1179 }
1180
1181 define('SERVER_KEY', Config::GetSetting($db, 'SERVER_KEY'));
1182
1183 Debug::LogEntry($db, "audit", "[IN]", "xmds", "RegisterDisplay");
1184 Debug::LogEntry($db, "audit", "serverKey [$serverKey], hardwareKey [$hardwareKey], displayName [$displayName]", "xmds", "RegisterDisplay");
1185
1186 //Check the serverKey matches the one we have stored in this servers lic.txt file
1187 if ($serverKey != SERVER_KEY)
1188 {
1189 return new soap_fault("SOAP-ENV:Client", "", "The Server key you entered does not match with the server key at this address", $serverKey);
1190 }
1191
1192 // Check the Length of the hardwareKey
1193 if (strlen($hardwareKey) > 40)
1194 {
1195 return new soap_fault("SOAP-ENV:Client", "", "The Hardware Key you sent was too long. Only 40 characters are allowed (SHA1).", $hardwareKey);
1196 }
1197
1198 //check in the database for this hardwareKey
1199 $SQL = "SELECT licensed, display FROM display WHERE license = '$hardwareKey'";
1200 if (!$result = $db->query($SQL))
1201 {
1202 trigger_error("License key query failed:" .$db->error());
1203 return new soap_fault("SOAP-ENV:Server", "", "License Key Query Failed, see server errorlog", $db->error());
1204 }
1205
1206 //Is it there?
1207 if ($db->num_rows($result) == 0)
1208 {
1209 //Add this display record
1210 $SQL = sprintf("INSERT INTO display (display, defaultlayoutid, license, licensed) VALUES ('%s', 1, '%s', 0)", $displayName, $hardwareKey);
1211 if (!$displayid = $db->insert_query($SQL))
1212 {
1213 trigger_error($db->error());
1214 return new soap_fault("SOAP-ENV:Server", "", "Error adding display");
1215 }
1216 $active = "Display added and is awaiting licensing approval from an Administrator";
1217 }
1218 else
1219 {
1220 //we have seen this display before, so check the licensed value
1221 $row = $db->get_row($result);
1222 if ($row[0] == 0)
1223 {
1224 //Its Not licensed
1225 $active = "Display is awaiting licensing approval from an Administrator.";
1226 }
1227 else
1228 {
1229 //It is licensed
1230 //Now check the names
1231 if ($row[1] == $displayName)
1232 {
1233 $active = "Display is active and ready to start.";
1234 }
1235 else
1236 {
1237 //Update the name
1238 $SQL = sprintf("UPDATE display SET display = '%s' WHERE license = '%s' ", $displayName, $hardwareKey);
1239
1240 if (!$db->query($SQL))
1241 {
1242 trigger_error($db->error());
1243 return new soap_fault("SOAP-ENV:Server", "", "Error editing the display name");
1244 }
1245
1246 $active = "Changed display name from '{$row[1]}' to '$displayName' Display is active and ready to start.";
1247 }
1248 }
1249 }
1250
1251 Debug::LogEntry($db, "audit", "$active", "xmds", "RegisterDisplay");
1252 Debug::LogEntry($db, "audit", "[OUT]", "xmds", "RegisterDisplay");
1253
1254 return $active;
1255}
1256
1257/**
1258 * Returns a string containing the required files xml for the requesting display
1259 * @param string $hardwareKey Display Hardware Key
1260 * @return string $requiredXml Xml Formatted String
1261 */
1262function RequiredFiles($serverKey, $hardwareKey, $version)
1263{
1264 global $db;
1265
1266 // Sanitize
1267 $serverKey = Kit::ValidateParam($serverKey, _STRING);
1268 $hardwareKey = Kit::ValidateParam($hardwareKey, _STRING);
1269 $version = Kit::ValidateParam($version, _STRING);
1270
1271 // Make sure we are talking the same language
1272 if (!CheckVersion($version))
1273 {
1274 return new soap_fault("SOAP-ENV:Client", "", "Your client is not of the correct version for communication with this server. You can get the latest from http://www.xibo.org.uk", $serverKey);
1275 }
1276
1277 $libraryLocation = Config::GetSetting($db, "LIBRARY_LOCATION");
1278
1279 //auth this request...
1280 if (!$displayInfo = Auth($hardwareKey))
1281 {
1282 trigger_error("This display is not licensed [$hardwareKey]");
1283 return new soap_fault("SOAP-ENV:Client", "", "This display client is not licensed");
1284 }
1285
1286 if ($displayInfo['isAuditing'] == 1)
1287 {
1288 Debug::LogEntry($db, "audit", "[IN]", "xmds", "RequiredFiles");
1289 Debug::LogEntry($db, "audit", "$hardwareKey", "xmds", "RequiredFiles");
1290 }
1291
1292 $requiredFilesXml = new DOMDocument("1.0");
1293 $fileElements = $requiredFilesXml->createElement("files");
1294
1295 $requiredFilesXml->appendChild($fileElements);
1296
1297 $currentdate = date("Y-m-d H:i:s");
1298 $time = time();
1299 $plus4hours = date("Y-m-d H:i:s",$time + 86400);
1300
1301 //Add file nodes to the $fileElements
1302 //Firstly get all the scheduled layouts
1303 $SQL = " SELECT layout.layoutID, schedule_detail.starttime, schedule_detail.endtime, layout.xml, layout.background ";
1304 $SQL .= " FROM layout ";
1305 $SQL .= " INNER JOIN schedule_detail ON schedule_detail.layoutID = layout.layoutID ";
1306 $SQL .= " INNER JOIN display ON schedule_detail.displayID = display.displayID ";
1307 $SQL .= sprintf(" WHERE display.license = '%s' ", $hardwareKey);
1308
1309 $SQLBase = $SQL;
1310
1311 //Do we include the default display
1312 if ($displayInfo['inc_schedule'] == 1)
1313 {
1314 $SQL .= sprintf(" AND ((schedule_detail.starttime < '%s' AND schedule_detail.endtime > '%s' )", $plus4hours, $currentdate);
1315 $SQL .= " OR (schedule_detail.starttime = '2050-12-31 00:00:00' AND schedule_detail.endtime = '2050-12-31 00:00:00' ))";
1316 }
1317 else
1318 {
1319 $SQL .= sprintf(" AND (schedule_detail.starttime < '%s' AND schedule_detail.endtime > '%s' )", $plus4hours, $currentdate);
1320 }
1321
1322 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry($db, "audit", "$SQL", "xmds", "RequiredFiles");
1323
1324 if (!$results = $db->query($SQL))
1325 {
1326 trigger_error($db->error());
1327 return new soap_fault("SOAP-ENV:Server", "", "Unable to get a list of files", $db->error());
1328 }
1329
1330 // Was there anything?
1331 if ($db->num_rows($results) == 0)
1332 {
1333 // No rows, run the query for default layout
1334 $SQL = $SQLBase;
1335 $SQL .= sprintf(" AND ((schedule_detail.starttime < '%s' AND schedule_detail.endtime > '%s' )", $plus4hours, $currentdate);
1336 $SQL .= " OR (schedule_detail.starttime = '2050-12-31 00:00:00' AND schedule_detail.endtime = '2050-12-31 00:00:00' ))";
1337
1338 if (!$results = $db->query($SQL))
1339 {
1340 trigger_error($db->error());
1341 return new soap_fault("SOAP-ENV:Server", "", "Unable to get A list of layouts for the schedule", $db->error());
1342 }
1343 }
1344
1345 while ($row = $db->get_row($results))
1346 {
1347 $layoutid = $row[0];
1348 $layoutXml = $row[3];
1349 $background = $row[4];
1350
1351 // Add all the associated media first
1352 $SQL = "SELECT storedAs, media.mediaID, media.`MD5`, media.FileSize
1353 FROM media
1354 INNER JOIN lklayoutmedia ON lklayoutmedia.mediaID = media.mediaID
1355 WHERE storedAs IS NOT NULL
1356 AND lklayoutmedia.layoutID = $layoutid
1357 AND media.mediaID NOT IN (SELECT MediaID
1358 FROM blacklist
1359 WHERE DisplayID = " . $displayInfo['displayid'] . "
1360 AND isIgnored = 0 )";
1361
1362 if (!$mediaResults = $db->query($SQL))
1363 {
1364 trigger_error($db->error());
1365 return new soap_fault("SOAP-ENV:Server", "", "Unable to get a list of media for the layout [$layoutid]");
1366 }
1367
1368 while ($row = $db->get_row($mediaResults))
1369 {
1370 $storedAs = Kit::ValidateParam($row[0], _STRING);
1371 $mediaId = Kit::ValidateParam($row[1], _INT);
1372 $md5 = Kit::ValidateParam($row[2], _STRING);
1373 $fileSize = Kit::ValidateParam($row[3], _INT);
1374
1375 // If they are empty calculate them and save them back to the media.
1376 if ($md5 == '' || $fileSize == 0)
1377 {
1378
1379 $md5 = md5_file($libraryLocation.$row[0]);
1380 $fileSize = filesize($libraryLocation.$row[0]);
1381
1382 // Update the media record with this information
1383 $SQL = sprintf("UPDATE media SET `MD5` = '%s', FileSize = %d WHERE MediaID = %d", $md5, $fileSize, $mediaId);
1384
1385 if (!$db->query($SQL))
1386 trigger_error($db->error());
1387 }
1388
1389 //Add the file node
1390 $file = $requiredFilesXml->createElement("file");
1391
1392 $file->setAttribute("type", "media");
1393 $file->setAttribute("path", $storedAs);
1394 $file->setAttribute("id", $mediaId);
1395 $file->setAttribute("size", $fileSize);
1396 $file->setAttribute("md5", $md5);
1397
1398 $fileElements->appendChild($file);
1399 }
1400
1401 //Also append another file node for the background image (if there is one)
1402 if ($background != "")
1403 {
1404 //firstly add this as a node
1405 $file = $requiredFilesXml->createElement("file");
1406
1407 $file->setAttribute("type", "media");
1408 $file->setAttribute("path", $background);
1409 $file->setAttribute("md5", md5_file($libraryLocation.$background));
1410 $file->setAttribute("size", filesize($libraryLocation.$background));
1411
1412 $fileElements->appendChild($file);
1413 }
1414
1415 // Add this layout as node
1416 $file = $requiredFilesXml->createElement("file");
1417
1418 $file->setAttribute("type", "layout");
1419 $file->setAttribute("path", $layoutid);
1420 $file->setAttribute("md5", md5($layoutXml . "\n"));
1421
1422 $fileElements->appendChild($file);
1423 }
1424
1425 //
1426 // Add a blacklist node
1427 //
1428 $blackList = $requiredFilesXml->createElement("file");
1429 $blackList->setAttribute("type", "blacklist");
1430
1431 $fileElements->appendChild($blackList);
1432
1433 // Populate
1434 $SQL = "SELECT MediaID
1435 FROM blacklist
1436 WHERE DisplayID = " . $displayInfo['displayid'] . "
1437 AND isIgnored = 0";
1438
1439 if (!$results = $db->query($SQL))
1440 {
1441 trigger_error($db->error());
1442 return new soap_fault("SOAP-ENV:Server", "", "Unable to get a list of blacklisted files", $db->error());
1443 }
1444
1445 // Add a black list element for each file
1446 while ($row = $db->get_row($results))
1447 {
1448 $file = $requiredFilesXml->createElement("file");
1449 $file->setAttribute("id", $row[0]);
1450
1451 $blackList->appendChild($file);
1452 }
1453
1454 // PHONE_HOME if required.
1455 if (Config::GetSetting($db,'PHONE_HOME') == 'On') {
1456 // Find out when we last PHONED_HOME :D
1457 // If it's been > 28 days since last PHONE_HOME then
1458 if (Config::GetSetting($db,'PHONE_HOME_DATE') < (time() - (60 * 60 * 24 * 28))) {
1459
1460 if ($displayInfo['isAuditing'] == 1)
1461 {
1462 Debug::LogEntry($db, "audit", "PHONE_HOME [IN]", "xmds", "RequiredFiles");
1463 }
1464
1465 // Retrieve number of displays
1466 $SQL = "SELECT COUNT(*)
1467 FROM `display`
1468 WHERE `licensed` = '1'";
1469 if (!$results = $db->query($SQL))
1470 {
1471 trigger_error($db->error());
1472 }
1473 while ($row = $db->get_row($results))
1474 {
1475 $PHONE_HOME_CLIENTS = Kit::ValidateParam($row[0],_INT);
1476 }
1477
1478 // Retrieve version number
1479 $PHONE_HOME_VERSION = Config::Version($db, 'app_ver');
1480
1481 $PHONE_HOME_URL = Config::GetSetting($db,'PHONE_HOME_URL') . "?id=" . urlencode(Config::GetSetting($db,'PHONE_HOME_KEY')) . "&version=" . urlencode($PHONE_HOME_VERSION) . "&numClients=" . urlencode($PHONE_HOME_CLIENTS);
1482
1483 if ($displayInfo['isAuditing'] == 1)
1484 {
1485 Debug::LogEntry($db, "audit", "PHONE_HOME_URL " . $PHONE_HOME_URL , "xmds", "RequiredFiles");
1486 }
1487
1488 // Set PHONE_HOME_TIME to NOW.
1489 $SQL = "UPDATE `setting`
1490 SET `value` = '" . time() . "'
1491 WHERE `setting`.`setting` = 'PHONE_HOME_DATE' LIMIT 1";
1492
1493 if (!$results = $db->query($SQL))
1494 {
1495 trigger_error($db->error());
1496 }
1497
1498 @file_get_contents($PHONE_HOME_URL);
1499
1500 if ($displayInfo['isAuditing'] == 1)
1501 {
1502 Debug::LogEntry($db, "audit", "PHONE_HOME [OUT]", "xmds", "RequiredFiles");
1503 }
1504 //endif
1505 }
1506 }
1507 // END OF PHONE_HOME CODE
1508
1509 if ($displayInfo['isAuditing'] == 1)
1510 {
1511 Debug::LogEntry($db, "audit", $requiredFilesXml->saveXML(), "xmds", "RequiredFiles");
1512 Debug::LogEntry($db, "audit", "[OUT]", "xmds", "RequiredFiles");
1513 }
1514
1515 // Return the results of requiredFiles()
1516 return $requiredFilesXml->saveXML();
1517}
1518
1519/**
1520 * Gets the specified file
1521 * @return
1522 * @param $hardwareKey Object
1523 * @param $filePath Object
1524 * @param $fileType Object
1525 */
1526function GetFile($serverKey, $hardwareKey, $filePath, $fileType, $chunkOffset, $chunkSize, $version)
1527{
1528 global $db;
1529
1530 // Sanitize
1531 $serverKey = Kit::ValidateParam($serverKey, _STRING);
1532 $hardwareKey = Kit::ValidateParam($hardwareKey, _STRING);
1533 $fileType = Kit::ValidateParam($fileType, _WORD);
1534 $chunkOffset = Kit::ValidateParam($chunkOffset, _INT);
1535 $chunkSize = Kit::ValidateParam($chunkSize, _INT);
1536 $version = Kit::ValidateParam($version, _STRING);
1537
1538 $libraryLocation = Config::GetSetting($db, "LIBRARY_LOCATION");
1539
1540 // Make sure we are talking the same language
1541 if (!CheckVersion($version))
1542 {
1543 return new soap_fault("SOAP-ENV:Client", "", "Your client is not of the correct version for communication with this server. You can get the latest from http://www.xibo.org.uk", $serverKey);
1544 }
1545
1546 //auth this request...
1547 if (!$displayInfo = Auth($hardwareKey))
1548 {
1549 return new soap_fault("SOAP-ENV:Client", "", "This display client is not licensed");
1550 }
1551
1552 if ($displayInfo['isAuditing'] == 1)
1553 {
1554 Debug::LogEntry($db, "audit", "[IN]", "xmds", "GetFile");
1555 Debug::LogEntry($db, "audit", "Params: [$hardwareKey] [$filePath] [$fileType] [$chunkOffset] [$chunkSize]", "xmds", "GetFile");
1556 }
1557
1558 if ($fileType == "layout")
1559 {
1560 $filePath = Kit::ValidateParam($filePath, _INT);
1561
1562 $SQL = sprintf("SELECT xml FROM layout WHERE layoutid = %d", $filePath);
1563 if (!$results = $db->query($SQL))
1564 {
1565 trigger_error($db->error());
1566 return new soap_fault("SOAP-ENV:Server", "", "Unable to get a list of files", $db->error());
1567 }
1568
1569 $row = $db->get_row($results);
1570
1571 $file = $row[0];
1572 }
1573 elseif ($fileType == "media")
1574 {
1575 $filePath = Kit::ValidateParam($filePath, _STRING);
1576
1577 if (strstr($filePath, '/') || strstr($filePath, '\\'))
1578 {
1579 return new soap_fault("SOAP-ENV:Client", "", "Invalid file path.", $serverKey);
1580 }
1581
1582 // Return the Chunk size specified
1583 $f = fopen($libraryLocation.$filePath,"r");
1584
1585 fseek($f, $chunkOffset);
1586
1587 $file = fread($f, $chunkSize);
1588 }
1589 else
1590 {
1591 return new soap_fault("SOAP-ENV:Client", "", "Unknown FileType Requested.");
1592 }
1593
1594 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry($db, "audit", "[OUT]", "xmds", "GetFile");
1595
1596 return base64_encode($file);
1597}
1598
1599/**
1600 * Returns the schedule for the hardware key specified
1601 * @return
1602 * @param $hardwareKey Object
1603 */
1604function Schedule($serverKey, $hardwareKey, $version)
1605{
1606 global $db;
1607
1608 // Sanitize
1609 $serverKey = Kit::ValidateParam($serverKey, _STRING);
1610 $hardwareKey = Kit::ValidateParam($hardwareKey, _STRING);
1611 $version = Kit::ValidateParam($version, _STRING);
1612
1613 // Make sure we are talking the same language
1614 if (!CheckVersion($version))
1615 {
1616 return new soap_fault("SOAP-ENV:Client", "", "Your client is not of the correct version for communication with this server. You can get the latest from http://www.xibo.org.uk", $serverKey);
1617 }
1618
1619 //auth this request...
1620 if (!$displayInfo = Auth($hardwareKey))
1621 {
1622 return new soap_fault("SOAP-ENV:Client", "", "This display client is not licensed", $hardwareKey);
1623 }
1624
1625 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry($db, "audit", "[IN] $hardwareKey", "xmds", "Schedule");
1626
1627 $scheduleXml = new DOMDocument("1.0");
1628 $layoutElements = $scheduleXml->createElement("schedule");
1629
1630 $scheduleXml->appendChild($layoutElements);
1631
1632 $currentdate = date("Y-m-d H:i:s");
1633 $time = time();
1634 $plus4hours = date("Y-m-d H:i:s",$time + 86400);
1635
1636 //Add file nodes to the $fileElements
1637 //Firstly get all the scheduled layouts
1638 $SQL = " SELECT layout.layoutID, schedule_detail.starttime, schedule_detail.endtime, schedule_detail.eventID ";
1639 $SQL .= " FROM layout ";
1640 $SQL .= " INNER JOIN schedule_detail ON schedule_detail.layoutID = layout.layoutID ";
1641 $SQL .= " INNER JOIN display ON schedule_detail.displayID = display.displayID ";
1642 $SQL .= " WHERE display.license = '$hardwareKey' ";
1643 $SQL .= " AND layout.retired = 0 ";
1644
1645 // Store the Base SQL for this display
1646 $SQLBase = $SQL;
1647
1648 // Run the query
1649 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry($db, "audit", "$SQL", "xmds", "Schedule");
1650
1651
1652
1653 // Do we include the default display
1654 if ($displayInfo['inc_schedule'] == 1)
1655 {
1656 $SQL .= " AND ((schedule_detail.starttime < '$currentdate' AND schedule_detail.endtime > '$currentdate' )";
1657 $SQL .= " OR (schedule_detail.starttime = '2050-12-31 00:00:00' AND schedule_detail.endtime = '2050-12-31 00:00:00' ))";
1658 }
1659 else
1660 {
1661 $SQL .= " AND (schedule_detail.starttime < '$currentdate' AND schedule_detail.endtime > '$currentdate' )";
1662 }
1663
1664 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry($db, "audit", "$SQL", "xmds", "Schedule");
1665
1666
1667 // Before we run the main query we should check to see if there are any priority layouts to deal with
1668 $SQLp = " AND schedule_detail.is_priority = 1 ";
1669
1670 // Run the query
1671 if (!$results = $db->query($SQL . $SQLp))
1672 {
1673 trigger_error($db->error());
1674 return new soap_fault("SOAP-ENV:Server", "", "Unable to get A list of layouts for the schedule", $db->error());
1675 }
1676
1677 // If there were no results then continue to get the full schedule
1678 if ($db->num_rows($results) == 0)
1679 {
1680 // Run the query
1681 if (!$results = $db->query($SQL))
1682 {
1683 trigger_error($db->error());
1684 return new soap_fault("SOAP-ENV:Server", "", "Unable to get A list of layouts for the schedule", $db->error());
1685 }
1686
1687 // Was there anything?
1688 if ($db->num_rows($results) == 0)
1689 {
1690 // No rows, run the query for default layout
1691 $SQL = $SQLBase;
1692 $SQL .= " AND ((schedule_detail.starttime < '$currentdate' AND schedule_detail.endtime > '$currentdate' )";
1693 $SQL .= " OR (schedule_detail.starttime = '2050-12-31 00:00:00' AND schedule_detail.endtime = '2050-12-31 00:00:00' ))";
1694
1695 if (!$results = $db->query($SQL))
1696 {
1697 trigger_error($db->error());
1698 return new soap_fault("SOAP-ENV:Server", "", "Unable to get A list of layouts for the schedule", $db->error());
1699 }
1700 }
1701 }
1702
1703 // We must have some results in here by this point
1704 while ($row = $db->get_row($results))
1705 {
1706 $layoutid = $row[0];
1707 $fromdt = $row[1];
1708 $todt = $row[2];
1709 $scheduleid = $row[3];
1710
1711 //firstly add this as a node
1712 $layout = $scheduleXml->createElement("layout");
1713
1714 $layout->setAttribute("file", $layoutid);
1715 $layout->setAttribute("fromdt", $fromdt);
1716 $layout->setAttribute("todt", $todt);
1717 $layout->setAttribute("scheduleid", $scheduleid);
1718
1719 $layoutElements->appendChild($layout);
1720 }
1721
1722 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry($db, "audit", $scheduleXml->saveXML(), "xmds", "Schedule");
1723 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry($db, "audit", "[OUT]", "xmds", "Schedule");
1724
1725 return $scheduleXml->saveXML();
1726}
1727
1728/**
1729 * Recieves the XmlLog from the display
1730 * @return
1731 * @param $hardwareKey String
1732 * @param $xml String
1733 */
1734function RecieveXmlLog($serverKey, $hardwareKey, $xml, $version)
1735{
1736 global $db;
1737
1738 return new soap_fault("SOAP-ENV:Client", "", "This is a depricated service call. You should instead call either SubmitLog or SubmitStats", $serverKey);
1739}
1740
1741define('BLACKLIST_ALL', "All");
1742define('BLACKLIST_SINGLE', "Single");
1743/**
1744 *
1745 * @return
1746 * @param $hardwareKey Object
1747 * @param $mediaId Object
1748 * @param $type Object
1749 */
1750function BlackList($serverKey, $hardwareKey, $mediaId, $type, $reason, $version)
1751{
1752 global $db;
1753
1754 // Sanitize
1755 $serverKey = Kit::ValidateParam($serverKey, _STRING);
1756 $hardwareKey = Kit::ValidateParam($hardwareKey, _STRING);
1757 $mediaId = Kit::ValidateParam($mediaId, _STRING);
1758 $type = Kit::ValidateParam($type, _STRING);
1759 $reason = Kit::ValidateParam($reason, _STRING);
1760 $version = Kit::ValidateParam($version, _STRING);
1761
1762 // Make sure we are talking the same language
1763 if (!CheckVersion($version))
1764 {
1765 return new soap_fault("SOAP-ENV:Client", "", "Your client is not of the correct version for communication with this server. You can get the latest from http://www.xibo.org.uk", $serverKey);
1766 }
1767
1768 // Auth this request...
1769 if (!$displayInfo = Auth($hardwareKey))
1770 {
1771 return new soap_fault("SOAP-ENV:Client", "", "This display client is not licensed", $hardwareKey);
1772 }
1773
1774 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry ($db, "audit", "[IN]", "xmds", "BlackList", "", $displayInfo['displayid']);
1775 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry ($db, "audit", "$xml", "xmds", "BlackList", "", $displayInfo['displayid']);
1776
1777 // Check to see if this media/display is already blacklisted (and not ignored)
1778 $SQL = "SELECT BlackListID FROM blacklist WHERE MediaID = $mediaId AND isIgnored = 0 AND DisplayID = " . $displayInfo['displayid'];
1779
1780 if (!$results = $db->query($SQL))
1781 {
1782 trigger_error($db->error());
1783 return new soap_fault("SOAP-ENV:Server", "", "Unable to query for BlackList records.", $db->error());
1784 }
1785
1786 if ($db->num_rows($results) == 0)
1787 {
1788 // Insert the black list record
1789 // Get all the displays and create a blacklist records
1790 $SQL = "SELECT displayID FROM display";
1791 if ($type == BLACKLIST_SINGLE)
1792 {
1793 // Only the current display
1794 $SQL .= " WHERE displayID = " . $displayInfo['displayid'];
1795 }
1796
1797 if (!$displays = $db->query($SQL))
1798 {
1799 trigger_error($db->error());
1800 return new soap_fault("SOAP-ENV:Server", "", "Unable to query for BlackList Displays.", $db->error());
1801 }
1802
1803 while ($row = $db->get_row($displays))
1804 {
1805 $displayId = $row[0];
1806
1807 $SQL = "INSERT INTO blacklist (MediaID, DisplayID, ReportingDisplayID, Reason)
1808 VALUES ($mediaId, $displayId, " . $displayInfo['displayid'] . ", '$reason') ";
1809
1810 if (!$db->query($SQL))
1811 {
1812 trigger_error($db->error());
1813 return new soap_fault("SOAP-ENV:Server", "", "Unable to insert BlackList records.", $db->error());
1814 }
1815 }
1816 }
1817 else
1818 {
1819 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry ($db, "audit", "Media Already BlackListed [$mediaId]", "xmds", "BlackList", "", $displayInfo['displayid']);
1820 }
1821
1822 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry ($db, "audit", "[OUT]", "xmds", "BlackList", "", $displayInfo['displayid']);
1823
1824 return true;
1825}
1826
1827/**
1828 * Submit client logging
1829 * @return
1830 * @param $version Object
1831 * @param $serverKey Object
1832 * @param $hardwareKey Object
1833 * @param $logXml Object
1834 */
1835function SubmitLog($version, $serverKey, $hardwareKey, $logXml)
1836{
1837 global $db;
1838
1839 // Sanitize
1840 $serverKey = Kit::ValidateParam($serverKey, _STRING);
1841 $hardwareKey = Kit::ValidateParam($hardwareKey, _STRING);
1842 $version = Kit::ValidateParam($version, _STRING);
1843 $logXml = Kit::ValidateParam($logXml, _HTMLSTRING);
1844
1845 // Make sure we are talking the same language
1846 if (!CheckVersion($version))
1847 {
1848 return new soap_fault("SOAP-ENV:Client", "", "Your client is not of the correct version for communication with this server. You can get the latest from http://www.xibo.org.uk", $serverKey);
1849 }
1850
1851 // Auth this request...
1852 if (!$displayInfo = Auth($hardwareKey))
1853 {
1854 return new soap_fault("SOAP-ENV:Client", "", "This display client is not licensed", $hardwareKey);
1855 }
1856
1857 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry ($db, "audit", "IN", "xmds", "SubmitLog", "", $displayInfo['displayid']);
1858 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry ($db, "audit", 'XML [' . $logXml . ']', "xmds", "SubmitLog", "", $displayInfo['displayid']);
1859
1860 // Load the XML into a DOMDocument
1861 $document = new DOMDocument("1.0");
1862
1863 if (!$document->loadXML($logXml))
1864 {
1865 return new soap_fault("SOAP-ENV:Client", "", "XML Cannot be loaded into DOM Document.", $hardwareKey);
1866 }
1867
1868 foreach ($document->documentElement->childNodes as $node)
1869 {
1870 // Make sure we dont consider any text nodes
1871 if ($node->nodeType == XML_TEXT_NODE) continue;
1872
1873 // Zero out the common vars
1874 $date = "";
1875 $message = "";
1876 $scheduleID = "";
1877 $layoutID = "";
1878 $mediaID = "";
1879 $cat = '';
1880 $method = '';
1881
1882 // This will be a bunch of trace nodes
1883 $message = $node->textContent;
1884
1885 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry ($db, "audit", 'Trace Message: [' . $message . ']', "xmds", "SubmitLog", "", $displayInfo['displayid']);
1886
1887 // Each element should have a category and a date
1888 $date = $node->getAttribute('date');
1889 $cat = $node->getAttribute('category');
1890
1891 if ($date == '' || $cat == '')
1892 {
1893 trigger_error('Log submitted without a date or category attribute');
1894 continue;
1895 }
1896
1897 // Get the date and the message (all log types have these)
1898 foreach ($node->childNodes as $nodeElements)
1899 {
1900 if ($nodeElements->nodeName == "scheduleID")
1901 {
1902 $scheduleID = $nodeElements->textContent;
1903 }
1904 else if ($nodeElements->nodeName == "layoutID")
1905 {
1906 $layoutID = $nodeElements->textContent;
1907 }
1908 else if ($nodeElements->nodeName == "mediaID")
1909 {
1910 $mediaID = $nodeElements->textContent;
1911 }
1912 else if ($nodeElements->nodeName == "type")
1913 {
1914 $type = $nodeElements->textContent;
1915 }
1916 else if ($nodeElements->nodeName == "method")
1917 {
1918 $method = $nodeElements->textContent;
1919 }
1920 }
1921
1922 // We should have enough information to log this now.
1923 if ($cat == 'error' || $cat == 'Error')
1924 {
1925 Debug::LogEntry($db, $cat, $message, 'Client', $method, $date, $displayInfo['displayid'], $scheduleID, $layoutID, $mediaID);
1926 }
1927 else
1928 {
1929 Debug::LogEntry($db, 'audit', $message, 'Client', $method, $date, $displayInfo['displayid'], $scheduleID, $layoutID, $mediaID);
1930 }
1931 }
1932
1933 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry ($db, "audit", "OUT", "xmds", "SubmitLog", "", $displayInfo['displayid']);
1934
1935 return true;
1936}
1937
1938/**
1939 * Submit display statistics to the server
1940 * @return
1941 * @param $version Object
1942 * @param $serverKey Object
1943 * @param $hardwareKey Object
1944 * @param $statXml Object
1945 */
1946function SubmitStats($version, $serverKey, $hardwareKey, $statXml)
1947{
1948 global $db;
1949
1950 // Sanitize
1951 $serverKey = Kit::ValidateParam($serverKey, _STRING);
1952 $hardwareKey = Kit::ValidateParam($hardwareKey, _STRING);
1953 $version = Kit::ValidateParam($version, _STRING);
1954 $statXml = Kit::ValidateParam($statXml, _HTMLSTRING);
1955
1956 // Make sure we are talking the same language
1957 if (!CheckVersion($version))
1958 {
1959 return new soap_fault("SOAP-ENV:Client", "", "Your client is not of the correct version for communication with this server. You can get the latest from http://www.xibo.org.uk", $serverKey);
1960 }
1961
1962 // Auth this request...
1963 if (!$displayInfo = Auth($hardwareKey))
1964 {
1965 return new soap_fault("SOAP-ENV:Client", "", "This display client is not licensed", $hardwareKey);
1966 }
1967
1968 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry ($db, "audit", "IN", "xmds", "SubmitStats", "", $displayInfo['displayid']);
1969 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry ($db, "audit", "StatXml: [" . $statXml . "]", "xmds", "SubmitStats", "", $displayInfo['displayid']);
1970
1971 if ($statXml == "")
1972 {
1973 return new soap_fault("SOAP-ENV:Client", "", "Stat XML is empty.", $hardwareKey);
1974 }
1975
1976 // Log
1977 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry ($db, "audit", "About to create Stat Object.", "xmds", "SubmitStats", "", $displayInfo['displayid']);
1978
1979 $statObject = new Stat($db);
1980
1981 // Log
1982 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry ($db, "audit", "About to Create DOMDocument.", "xmds", "SubmitStats", "", $displayInfo['displayid']);
1983
1984 // Load the XML into a DOMDocument
1985 $document = new DOMDocument("1.0");
1986 $document->loadXML($statXml);
1987
1988 foreach ($document->documentElement->childNodes as $node)
1989 {
1990 // Make sure we dont consider any text nodes
1991 if ($node->nodeType == XML_TEXT_NODE) continue;
1992
1993 //Zero out the common vars
1994 $fromdt = '';
1995 $todt = '';
1996 $type = '';
1997
1998 $scheduleID = 0;
1999 $layoutID = 0;
2000 $mediaID = '';
2001 $tag = '';
2002
2003 // Each element should have these attributes
2004 $fromdt = $node->getAttribute('fromdt');
2005 $todt = $node->getAttribute('todt');
2006 $type = $node->getAttribute('type');
2007
2008 if ($fromdt == '' || $todt == '' || $type == '')
2009 {
2010 trigger_error('Stat submitted without the fromdt, todt or type attributes.');
2011 continue;
2012 }
2013
2014 $scheduleID = $node->getAttribute('scheduleid');
2015 $layoutID = $node->getAttribute('layoutid');
2016 $mediaID = $node->getAttribute('mediaid');
2017 $tag = $node->getAttribute('tag');
2018
2019 // Write the stat record with the information we have available to us.
2020 if (!$statObject->Add($type, $fromdt, $todt, $scheduleID, $displayInfo['displayid'], $layoutID, $mediaID, $tag))
2021 {
2022 trigger_error(sprintf('Stat Add failed with error: %s', $statObject->GetErrorMessage()));
2023 continue;
2024 }
2025 }
2026
2027 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry ($db, "audit", "OUT", "xmds", "SubmitStats", "", $displayInfo['displayid']);
2028
2029 return true;
2030}
2031
2032//$debug = 1;
2033$service = new soap_server();
2034
2035$service->configureWSDL("xmds", "urn:xmds");
2036
2037$service->register("RegisterDisplay",
2038 array('serverKey' => 'xsd:string', 'hardwareKey' => 'xsd:string', 'displayName' => 'xsd:string', 'version' => 'xsd:string'),
2039 array('ActivationMessage' => 'xsd:string'),
2040 'urn:xmds',
2041 'urn:xmds#RegisterDisplay',
2042 'rpc',
2043 'encoded',
2044 'Registered the Display on the Xibo Network'
2045 );
2046
2047$service->register("RequiredFiles",
2048 array('serverKey' => 'xsd:string', 'hardwareKey' => 'xsd:string', 'version' => 'xsd:string'),
2049 array('RequiredFilesXml' => 'xsd:string'),
2050 'urn:xmds',
2051 'urn:xmds#RequiredFiles',
2052 'rpc',
2053 'encoded',
2054 'The files required by the requesting display'
2055 );
2056
2057$service->register("GetFile",
2058 array('serverKey' => 'xsd:string', 'hardwareKey' => 'xsd:string', 'filePath' => 'xsd:string', 'fileType' => 'xsd:string', 'chunkOffset' => 'xsd:int', 'chuckSize' => 'xsd:int', 'version' => 'xsd:string'),
2059 array('file' => 'xsd:base64Binary'),
2060 'urn:xmds',
2061 'urn:xmds#GetFile',
2062 'rpc',
2063 'encoded',
2064 'Gets the file requested'
2065 );
2066
2067$service->register("Schedule",
2068 array('serverKey' => 'xsd:string', 'hardwareKey' => 'xsd:string', 'version' => 'xsd:string'),
2069 array('ScheduleXml' => 'xsd:string'),
2070 'urn:xmds',
2071 'urn:xmds#Schedule',
2072 'rpc',
2073 'encoded',
2074 'Gets the schedule'
2075 );
2076
2077$service->register("RecieveXmlLog",
2078 array('serverKey' => 'xsd:string', 'hardwareKey' => 'xsd:string', 'xml' => 'xsd:string', 'version' => 'xsd:string'),
2079 array('success' => 'xsd:boolean'),
2080 'urn:xmds',
2081 'urn:xmds#RecieveXmlLog',
2082 'rpc',
2083 'encoded',
2084 'Recieves the Log Xml'
2085 );
2086
2087$service->register("BlackList",
2088 array('serverKey' => 'xsd:string', 'hardwareKey' => 'xsd:string', 'mediaId' => 'xsd:int', 'type' => 'xsd:string', 'reason'=>'xsd:string', 'version' => 'xsd:string'),
2089 array('success' => 'xsd:boolean'),
2090 'urn:xmds',
2091 'urn:xmds#BlackList',
2092 'rpc',
2093 'encoded',
2094 'Set media to be blacklisted'
2095 );
2096
2097$service->register("SubmitLog",
2098 array('version' => 'xsd:string', 'serverKey' => 'xsd:string', 'hardwareKey' => 'xsd:string', 'logXml' => 'xsd:string'),
2099 array('success' => 'xsd:boolean'),
2100 'urn:xmds',
2101 'urn:xmds#SubmitLog',
2102 'rpc',
2103 'encoded',
2104 'Submit Logging from the Client'
2105 );
2106
2107$service->register("SubmitStats",
2108 array('version' => 'xsd:string', 'serverKey' => 'xsd:string', 'hardwareKey' => 'xsd:string', 'statXml' => 'xsd:string'),
2109 array('success' => 'xsd:boolean'),
2110 'urn:xmds',
2111 'urn:xmds#SubmitLog',
2112 'rpc',
2113 'encoded',
2114 'Submit Display statistics from the Client'
2115 );
2116
2117
2118
2119$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
2120$service->service($HTTP_RAW_POST_DATA);
2121
2122//Debug::LogEntry($db, 'audit', $service->debug_str, "xmds", "NuSOAP");
2123
2124>>>>>>> MERGE-SOURCE
1063?>2125?>
1064\ No newline at end of file2126\ No newline at end of file

Subscribers

People subscribed via source and target branches