Merge lp:~dangarner/xibo/store-media-md5 into lp:xibo/1.0

Proposed by Dan Garner
Status: Merged
Approved by: Dan Garner
Approved revision: 68
Merged at revision: not available
Proposed branch: lp:~dangarner/xibo/store-media-md5
Merge into: lp:xibo/1.0
Diff against target: 5012 lines
6 files modified
server/install/database/8.sql (+7/-0)
server/modules/flash.module.php (+173/-164)
server/modules/image.module.php (+176/-167)
server/modules/powerpoint.module.php (+174/-165)
server/modules/video.module.php (+172/-163)
server/xmds.php (+255/-236)
To merge this branch: bzr merge lp:~dangarner/xibo/store-media-md5
Reviewer Review Type Date Requested Status
Xibo Maintainters Pending
Review via email: mp+12624@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
=== added file 'server/install/database/8.sql'
--- server/install/database/8.sql 1970-01-01 00:00:00 +0000
+++ server/install/database/8.sql 2009-09-29 22:15:24 +0000
@@ -0,0 +1,7 @@
1/* Add the MD5 and FileSize as columns to the media table */
2ALTER TABLE `media` ADD `MD5` VARCHAR( 32 ) NULL AFTER `storedAs` ,
3ADD `FileSize` BIGINT NULL AFTER `MD5` ;
4
5UPDATE `version` SET `app_ver` = '1.0.4';
6UPDATE `setting` SET `value` = 0 WHERE `setting` = 'PHONE_HOME_DATE';
7UPDATE `version` SET `DBVersion` = '8';
08
=== modified file 'server/modules/flash.module.php'
--- server/modules/flash.module.php 2009-06-28 10:47:06 +0000
+++ server/modules/flash.module.php 2009-09-29 22:15:24 +0000
@@ -8,7 +8,7 @@
8 * Xibo is free software: you can redistribute it and/or modify8 * 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 by9 * 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, or10 * the Free Software Foundation, either version 3 of the License, or
11 * any later version. 11 * any later version.
12 *12 *
13 * Xibo is distributed in the hope that it will be useful,13 * Xibo is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -17,31 +17,31 @@
17 *17 *
18 * You should have received a copy of the GNU Affero General Public License18 * 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/>.19 * along with Xibo. If not, see <http://www.gnu.org/licenses/>.
20 */ 20 */
21class flash extends Module21class flash extends Module
22{22{
23 // Custom Media information23 // Custom Media information
24 private $uri;24 private $uri;
25 private $maxFileSize;25 private $maxFileSize;
26 private $maxFileSizeBytes;26 private $maxFileSizeBytes;
27 27
28 public function __construct(database $db, user $user, $mediaid = '', $layoutid = '', $regionid = '')28 public function __construct(database $db, user $user, $mediaid = '', $layoutid = '', $regionid = '')
29 {29 {
30 // Must set the type of the class30 // Must set the type of the class
31 $this->type = 'flash';31 $this->type = 'flash';
32 32
33 // Get the max upload size from PHP33 // Get the max upload size from PHP
34 $this->maxFileSize = ini_get('upload_max_filesize');34 $this->maxFileSize = ini_get('upload_max_filesize');
35 $this->maxFileSizeBytes = convertBytes($this->maxFileSize);35 $this->maxFileSizeBytes = convertBytes($this->maxFileSize);
36 36
37 // Must call the parent class 37 // Must call the parent class
38 parent::__construct($db, $user, $mediaid, $layoutid, $regionid);38 parent::__construct($db, $user, $mediaid, $layoutid, $regionid);
39 }39 }
40 40
41 /**41 /**
42 * Sets the Layout and Region Information42 * Sets the Layout and Region Information
43 * it will then fill in any blanks it has about this media if it can43 * it will then fill in any blanks it has about this media if it can
44 * @return 44 * @return
45 * @param $layoutid Object45 * @param $layoutid Object
46 * @param $regionid Object46 * @param $regionid Object
47 * @param $mediaid Object47 * @param $mediaid Object
@@ -53,75 +53,75 @@
53 $this->regionid = $regionid;53 $this->regionid = $regionid;
54 $mediaid = $this->mediaid;54 $mediaid = $this->mediaid;
55 $this->existingMedia = false;55 $this->existingMedia = false;
56 56
57 if ($this->regionSpecific == 1) return;57 if ($this->regionSpecific == 1) return;
58 58
59 // Load what we know about this media into the object59 // Load what we know about this media into the object
60 $SQL = "SELECT name, type, duration, originalFilename, userID, permissionID, retired, storedAs, isEdited, editedMediaID FROM media WHERE mediaID = $mediaid ";60 $SQL = "SELECT name, type, duration, originalFilename, userID, permissionID, retired, storedAs, isEdited, editedMediaID FROM media WHERE mediaID = $mediaid ";
61 61
62 if (!$result = $db->query($SQL))62 if (!$result = $db->query($SQL))
63 {63 {
64 trigger_error($db->error()); //log the error64 trigger_error($db->error()); //log the error
65 return false;65 return false;
66 }66 }
67 67
68 if ($db->num_rows($result) != 1)68 if ($db->num_rows($result) != 1)
69 {69 {
70 trigger_error("More than one row for mediaId [$mediaid] How can this be?");70 trigger_error("More than one row for mediaId [$mediaid] How can this be?");
71 return false;71 return false;
72 }72 }
73 73
74 $row = $db->get_row($result);74 $row = $db->get_row($result);
75 $duration = $row[2];75 $duration = $row[2];
76 $storedAs = $row[7];76 $storedAs = $row[7];
77 77
78 // Required Attributes78 // Required Attributes
79 $this->duration = $duration;79 $this->duration = $duration;
80 80
81 // Any Options81 // Any Options
82 $this->SetOption('uri', $storedAs);82 $this->SetOption('uri', $storedAs);
83 83
84 return true;84 return true;
85 }85 }
86 86
87 /**87 /**
88 * Return the Add Form as HTML88 * Return the Add Form as HTML
89 * @return 89 * @return
90 */90 */
91 public function AddForm()91 public function AddForm()
92 {92 {
93 global $session;93 global $session;
94 $db =& $this->db;94 $db =& $this->db;
95 $user =& $this->user;95 $user =& $this->user;
96 96
97 // Would like to get the regions width / height 97 // Would like to get the regions width / height
98 $layoutid = $this->layoutid;98 $layoutid = $this->layoutid;
99 $regionid = $this->regionid;99 $regionid = $this->regionid;
100 100
101 // Set the Session / Security information101 // Set the Session / Security information
102 $sessionId = session_id();102 $sessionId = session_id();
103 $securityToken = CreateFormToken();103 $securityToken = CreateFormToken();
104 104
105 $session->setSecurityToken($securityToken);105 $session->setSecurityToken($securityToken);
106 106
107 //Get the default value for the shared list107 //Get the default value for the shared list
108 $default = Config::GetSetting($db,"defaultMedia");108 $default = Config::GetSetting($db,"defaultMedia");
109109
110 $permissionid = 0;110 $permissionid = 0;
111111
112 if($default=="private") 112 if($default=="private")
113 {113 {
114 $permissionid = 1;114 $permissionid = 1;
115 }115 }
116 116
117 //shared list117 //shared list
118 $shared_list = dropdownlist("SELECT permissionID, permission FROM permission", "permissionid", $permissionid);118 $shared_list = dropdownlist("SELECT permissionID, permission FROM permission", "permissionid", $permissionid);
119 119
120 //Save button is different depending on if we are on a region or not120 //Save button is different depending on if we are on a region or not
121 if ($regionid != "")121 if ($regionid != "")
122 {122 {
123 setSession('content','mediatype','flash');123 setSession('content','mediatype','flash');
124 124
125 $save_button = <<<END125 $save_button = <<<END
126 <input id="btnSave" type="submit" value="Save" disabled />126 <input id="btnSave" type="submit" value="Save" disabled />
127 <input class="XiboFormButton" id="btnCancel" type="button" title="Return to the Region Options" href="index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions" value="Cancel" />127 <input class="XiboFormButton" id="btnCancel" type="button" title="Return to the Region Options" href="index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions" value="Cancel" />
@@ -135,7 +135,7 @@
135 <input class="XiboFormButton" id="btnCancel" type="button" title="Close" href="index.php?p=content&q=displayForms&sp=add" value="Cancel" />135 <input class="XiboFormButton" id="btnCancel" type="button" title="Close" href="index.php?p=content&q=displayForms&sp=add" value="Cancel" />
136END;136END;
137 }137 }
138 138
139 $form = <<<FORM139 $form = <<<FORM
140 <div style="display:none"><iframe name="fileupload" width="1px" height="1px"></iframe></div>140 <div style="display:none"><iframe name="fileupload" width="1px" height="1px"></iframe></div>
141 <div>141 <div>
@@ -144,7 +144,7 @@
144 <input type="hidden" id="SecurityToken" value="$securityToken" />144 <input type="hidden" id="SecurityToken" value="$securityToken" />
145 <input type="hidden" name="MAX_FILE_SIZE" value="$this->maxFileSizeBytes" />145 <input type="hidden" name="MAX_FILE_SIZE" value="$this->maxFileSizeBytes" />
146 <table>146 <table>
147 <tr> 147 <tr>
148 <td><label for="file">Flash File<span class="required">*</span></label></td>148 <td><label for="file">Flash File<span class="required">*</span></label></td>
149 <td colspan="3">149 <td colspan="3">
150 <input type="file" name="media_file" onchange="fileFormSubmit();this.form.submit();" />150 <input type="file" name="media_file" onchange="fileFormSubmit();this.form.submit();" />
@@ -172,7 +172,7 @@
172 <td><label for="permissionid">Sharing<span class="required">*</span></label></td>172 <td><label for="permissionid">Sharing<span class="required">*</span></label></td>
173 <td>173 <td>
174 $shared_list174 $shared_list
175 </td> 175 </td>
176 </tr>176 </tr>
177 <tr>177 <tr>
178 <td></td>178 <td></td>
@@ -194,49 +194,49 @@
194194
195 return $this->response;195 return $this->response;
196 }196 }
197 197
198 /**198 /**
199 * Return the Edit Form as HTML199 * Return the Edit Form as HTML
200 * @return 200 * @return
201 */201 */
202 public function EditForm()202 public function EditForm()
203 {203 {
204 global $session;204 global $session;
205 $db =& $this->db;205 $db =& $this->db;
206 $user =& $this->user;206 $user =& $this->user;
207 207
208 // Would like to get the regions width / height 208 // Would like to get the regions width / height
209 $layoutid = $this->layoutid;209 $layoutid = $this->layoutid;
210 $regionid = $this->regionid;210 $regionid = $this->regionid;
211 $mediaid = $this->mediaid;211 $mediaid = $this->mediaid;
212 $lkid = $this->lkid;212 $lkid = $this->lkid;
213 $userid = Kit::GetParam('userid', _SESSION, _INT);213 $userid = Kit::GetParam('userid', _SESSION, _INT);
214 214
215 // Set the Session / Security information215 // Set the Session / Security information
216 $sessionId = session_id();216 $sessionId = session_id();
217 $securityToken = CreateFormToken();217 $securityToken = CreateFormToken();
218 218
219 $session->setSecurityToken($securityToken);219 $session->setSecurityToken($securityToken);
220 220
221 // Load what we know about this media into the object221 // Load what we know about this media into the object
222 $SQL = "SELECT name, originalFilename, userID, permissionID, retired, storedAs, isEdited, editedMediaID FROM media WHERE mediaID = $mediaid ";222 $SQL = "SELECT name, originalFilename, userID, permissionID, retired, storedAs, isEdited, editedMediaID FROM media WHERE mediaID = $mediaid ";
223 223
224 if (!$result = $db->query($SQL))224 if (!$result = $db->query($SQL))
225 {225 {
226 trigger_error($db->error()); //log the error226 trigger_error($db->error()); //log the error
227 227
228 $this->message = "Error querying for the Media information with media ID [$mediaid] ";228 $this->message = "Error querying for the Media information with media ID [$mediaid] ";
229 return false;229 return false;
230 }230 }
231 231
232 if ($db->num_rows($result) != 1)232 if ($db->num_rows($result) != 1)
233 {233 {
234 trigger_error("More than one row for mediaId [$mediaid] How can this be?");234 trigger_error("More than one row for mediaId [$mediaid] How can this be?");
235 235
236 $this->message = "Error querying for the Media information with media ID [$mediaid] ";236 $this->message = "Error querying for the Media information with media ID [$mediaid] ";
237 return false;237 return false;
238 }238 }
239 239
240 $row = $db->get_row($result);240 $row = $db->get_row($result);
241 $name = $row[0];241 $name = $row[0];
242 $originalFilename = $row[1];242 $originalFilename = $row[1];
@@ -246,23 +246,23 @@
246 $storedAs = $row[5];246 $storedAs = $row[5];
247 $isEdited = $row[6];247 $isEdited = $row[6];
248 $editedMediaID = $row[7];248 $editedMediaID = $row[7];
249 249
250 // derive the ext250 // derive the ext
251 $ext = strtolower(substr(strrchr($originalFilename, "."), 1));251 $ext = strtolower(substr(strrchr($originalFilename, "."), 1));
252 252
253 //Calc the permissions on it aswell253 //Calc the permissions on it aswell
254 list($see_permissions , $edit_permissions) = $user->eval_permission($userid, $permissionid);254 list($see_permissions , $edit_permissions) = $user->eval_permission($userid, $permissionid);
255 255
256 //shared list256 //shared list
257 $shared_list = dropdownlist("SELECT permissionID, permission FROM permission", "permissionid", $permissionid);257 $shared_list = dropdownlist("SELECT permissionID, permission FROM permission", "permissionid", $permissionid);
258 258
259 //Save button is different depending on if we are on a region or not259 //Save button is different depending on if we are on a region or not
260 if ($regionid != "")260 if ($regionid != "")
261 {261 {
262 setSession('content','mediatype','flash');262 setSession('content','mediatype','flash');
263 263
264 $extraNotes = '<em>Note: Uploading a new media item here will replace it on this layout only.</em>';264 $extraNotes = '<em>Note: Uploading a new media item here will replace it on this layout only.</em>';
265 265
266 $save_button = <<<END266 $save_button = <<<END
267 <input id="btnSave" type="submit" value="Save" />267 <input id="btnSave" type="submit" value="Save" />
268 <input class="XiboFormButton" id="btnCancel" type="button" title="Return to the Region Options" href="index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions" value="Cancel" />268 <input class="XiboFormButton" id="btnCancel" type="button" title="Return to the Region Options" href="index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions" value="Cancel" />
@@ -272,13 +272,13 @@
272 else272 else
273 {273 {
274 $extraNotes = '<em>Note: As you editing from the library uploading a new media item will not replace the old one from any layouts. To do this nagivate to the layout and edit the media from there.</em>';274 $extraNotes = '<em>Note: As you editing from the library uploading a new media item will not replace the old one from any layouts. To do this nagivate to the layout and edit the media from there.</em>';
275 275
276 $save_button = <<<END276 $save_button = <<<END
277 <input id="btnSave" type="submit" value="Save" />277 <input id="btnSave" type="submit" value="Save" />
278 <input id="btnCancel" type="button" title="Close" onclick="$('#div_dialog').dialog('close')" value="Cancel" />278 <input id="btnCancel" type="button" title="Close" onclick="$('#div_dialog').dialog('close')" value="Cancel" />
279END;279END;
280 }280 }
281 281
282 $form = <<<FORM282 $form = <<<FORM
283 <div style="display:none"><iframe name="fileupload" width="1px" height="1px"></iframe></div>283 <div style="display:none"><iframe name="fileupload" width="1px" height="1px"></iframe></div>
284 <div>284 <div>
@@ -287,7 +287,7 @@
287 <input type="hidden" id="SecurityToken" value="$securityToken" />287 <input type="hidden" id="SecurityToken" value="$securityToken" />
288 <input type="hidden" name="MAX_FILE_SIZE" value="$this->maxFileSizeBytes" />288 <input type="hidden" name="MAX_FILE_SIZE" value="$this->maxFileSizeBytes" />
289 <table>289 <table>
290 <tr> 290 <tr>
291 <td><label for="file">New Flash File<span class="required">*</span></label></td>291 <td><label for="file">New Flash File<span class="required">*</span></label></td>
292 <td colspan="3">292 <td colspan="3">
293 <input type="file" name="media_file" onchange="fileFormSubmit();this.form.submit();" />293 <input type="file" name="media_file" onchange="fileFormSubmit();this.form.submit();" />
@@ -319,7 +319,7 @@
319 <td><label for="permissionid">Sharing<span class="required">*</span></label></td>319 <td><label for="permissionid">Sharing<span class="required">*</span></label></td>
320 <td>320 <td>
321 $shared_list321 $shared_list
322 </td> 322 </td>
323 </tr>323 </tr>
324 <tr>324 <tr>
325 <td></td>325 <td></td>
@@ -343,50 +343,50 @@
343 $this->response->dialogWidth = '450px';343 $this->response->dialogWidth = '450px';
344 $this->response->dialogHeight = '280px';344 $this->response->dialogHeight = '280px';
345345
346 return $this->response; 346 return $this->response;
347 }347 }
348 348
349 /**349 /**
350 * Return the Delete Form as HTML350 * Return the Delete Form as HTML
351 * @return 351 * @return
352 */352 */
353 public function DeleteForm()353 public function DeleteForm()
354 {354 {
355 $db =& $this->db;355 $db =& $this->db;
356 $user =& $this->user;356 $user =& $this->user;
357 357
358 // Would like to get the regions width / height 358 // Would like to get the regions width / height
359 $layoutid = $this->layoutid;359 $layoutid = $this->layoutid;
360 $regionid = $this->regionid;360 $regionid = $this->regionid;
361 $mediaid = $this->mediaid;361 $mediaid = $this->mediaid;
362 $lkid = $this->lkid;362 $lkid = $this->lkid;
363 $userid = Kit::GetParam('userid', _SESSION, _INT);363 $userid = Kit::GetParam('userid', _SESSION, _INT);
364 364
365 $options = "";365 $options = "";
366 //Always have the abilty to unassign from the region366 //Always have the abilty to unassign from the region
367 $options .= "unassign|Unassign from this region only";367 $options .= "unassign|Unassign from this region only";
368 368
369 // Load what we know about this media into the object369 // Load what we know about this media into the object
370 $SQL = "SELECT name, type, duration, originalFilename, userID, permissionID, retired, storedAs, isEdited, editedMediaID FROM media WHERE mediaID = $mediaid ";370 $SQL = "SELECT name, type, duration, originalFilename, userID, permissionID, retired, storedAs, isEdited, editedMediaID FROM media WHERE mediaID = $mediaid ";
371 371
372 if (!$result = $db->query($SQL))372 if (!$result = $db->query($SQL))
373 {373 {
374 trigger_error($db->error()); //log the error374 trigger_error($db->error()); //log the error
375 375
376 $this->response->SetError('Error querying for the Media information with media ID [$mediaid]');376 $this->response->SetError('Error querying for the Media information with media ID [$mediaid]');
377 $this->response->keepOpen = true;377 $this->response->keepOpen = true;
378 return $this->response;378 return $this->response;
379 }379 }
380 380
381 if ($db->num_rows($result) != 1)381 if ($db->num_rows($result) != 1)
382 {382 {
383 trigger_error("More than one row for mediaId [$mediaid] How can this be?");383 trigger_error("More than one row for mediaId [$mediaid] How can this be?");
384 384
385 $this->response->SetError('Error querying for the Media information with media ID [$mediaid]');385 $this->response->SetError('Error querying for the Media information with media ID [$mediaid]');
386 $this->response->keepOpen = true;386 $this->response->keepOpen = true;
387 return $this->response;387 return $this->response;
388 }388 }
389 389
390 $row = $db->get_row($result);390 $row = $db->get_row($result);
391 $name = $row[0];391 $name = $row[0];
392 $duration = $row[2];392 $duration = $row[2];
@@ -397,18 +397,18 @@
397 $storedAs = $row[7];397 $storedAs = $row[7];
398 $isEdited = $row[8];398 $isEdited = $row[8];
399 $editedMediaID = $row[9];399 $editedMediaID = $row[9];
400 400
401 // derive the ext401 // derive the ext
402 $ext = strtolower(substr(strrchr($originalFilename, "."), 1));402 $ext = strtolower(substr(strrchr($originalFilename, "."), 1));
403 403
404 //Calc the permissions on it aswell404 //Calc the permissions on it aswell
405 list($see_permissions , $edit_permissions) = $user->eval_permission($userid, $permissionid);405 list($see_permissions , $edit_permissions) = $user->eval_permission($userid, $permissionid);
406 406
407 //Is this user allowed to edit this media?407 //Is this user allowed to edit this media?
408 if ($edit_permissions)408 if ($edit_permissions)
409 {409 {
410 $options .= ",retire|Unassign from this region and retire";410 $options .= ",retire|Unassign from this region and retire";
411 411
412 //Is this media retired?412 //Is this media retired?
413 if ($editedMediaID != "")413 if ($editedMediaID != "")
414 {414 {
@@ -418,7 +418,7 @@
418 {418 {
419 $revised = false;419 $revised = false;
420 }420 }
421 421
422 //Is this media being used anywhere else?422 //Is this media being used anywhere else?
423 if ($layoutid == "")423 if ($layoutid == "")
424 {424 {
@@ -429,8 +429,8 @@
429 {429 {
430 $SQL = "SELECT layoutID FROM lklayoutmedia WHERE mediaID = $mediaid AND layoutid <> $layoutid AND regionID <> '$regionid' ";430 $SQL = "SELECT layoutID FROM lklayoutmedia WHERE mediaID = $mediaid AND layoutid <> $layoutid AND regionID <> '$regionid' ";
431 }431 }
432 432
433 if (!$results = $db->query($SQL)) 433 if (!$results = $db->query($SQL))
434 {434 {
435 trigger_error($db->error());435 trigger_error($db->error());
436436
@@ -457,9 +457,9 @@
457 return $this->response;457 return $this->response;
458 }458 }
459 }459 }
460 460
461 $options = ltrim($options, ",");461 $options = ltrim($options, ",");
462 462
463 $deleteOptions = listcontent($options,"options");463 $deleteOptions = listcontent($options,"options");
464464
465 //we can delete465 //we can delete
@@ -474,19 +474,19 @@
474 <input id="btnCancel" type="button" title="No / Cancel" href="index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions" onclick="$('#div_dialog').dialog('close');return false; " value="No" />474 <input id="btnCancel" type="button" title="No / Cancel" href="index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions" onclick="$('#div_dialog').dialog('close');return false; " value="No" />
475 </form>475 </form>
476END;476END;
477 477
478 $this->response->html = $form;478 $this->response->html = $form;
479 $this->response->dialogTitle = 'Delete Flash';479 $this->response->dialogTitle = 'Delete Flash';
480 $this->response->dialogSize = true;480 $this->response->dialogSize = true;
481 $this->response->dialogWidth = '450px';481 $this->response->dialogWidth = '450px';
482 $this->response->dialogHeight = '280px';482 $this->response->dialogHeight = '280px';
483483
484 return $this->response; 484 return $this->response;
485 }485 }
486 486
487 /**487 /**
488 * Add Media to the Database488 * Add Media to the Database
489 * @return 489 * @return
490 */490 */
491 public function AddMedia()491 public function AddMedia()
492 {492 {
@@ -495,29 +495,29 @@
495 $regionid = $this->regionid;495 $regionid = $this->regionid;
496 $mediaid = $this->mediaid;496 $mediaid = $this->mediaid;
497 $userid = Kit::GetParam('userid', _SESSION, _INT);497 $userid = Kit::GetParam('userid', _SESSION, _INT);
498 498
499 // File data499 // File data
500 $tmpName = Kit::GetParam('hidFileID', _POST, _STRING);500 $tmpName = Kit::GetParam('hidFileID', _POST, _STRING);
501 501
502 if ($tmpName == '')502 if ($tmpName == '')
503 {503 {
504 $this->response->SetError('Cannot save Flash details. <br/> You must have picked a file.');504 $this->response->SetError('Cannot save Flash details. <br/> You must have picked a file.');
505 $this->response->keepOpen = true;505 $this->response->keepOpen = true;
506 return $this->response;506 return $this->response;
507 }507 }
508 508
509 // File name and extension (orignial name)509 // File name and extension (orignial name)
510 $fileName = Kit::GetParam('txtFileName', _POST, _STRING);510 $fileName = Kit::GetParam('txtFileName', _POST, _STRING);
511 $fileName = basename($fileName);511 $fileName = basename($fileName);
512 $ext = strtolower(substr(strrchr($fileName, "."), 1));512 $ext = strtolower(substr(strrchr($fileName, "."), 1));
513 513
514 // Other properties514 // Other properties
515 $name = Kit::GetParam('name', _POST, _STRING);515 $name = Kit::GetParam('name', _POST, _STRING);
516 $duration = Kit::GetParam('duration', _POST, _INT, 0);516 $duration = Kit::GetParam('duration', _POST, _INT, 0);
517 $permissionid = Kit::GetParam('permissionid', _POST, _INT, 1);517 $permissionid = Kit::GetParam('permissionid', _POST, _INT, 1);
518 518
519 if ($name == '') $name = Kit::ValidateParam($fileName, _FILENAME);519 if ($name == '') $name = Kit::ValidateParam($fileName, _FILENAME);
520 520
521 // Validation521 // Validation
522 if ($ext != "swf")522 if ($ext != "swf")
523 {523 {
@@ -525,32 +525,32 @@
525 $this->response->keepOpen = true;525 $this->response->keepOpen = true;
526 return $this->response;526 return $this->response;
527 }527 }
528 528
529 // Make sure the name isnt too long529 // Make sure the name isnt too long
530 if (strlen($name) > 100) 530 if (strlen($name) > 100)
531 {531 {
532 $this->response->SetError('The name cannot be longer than 100 characters');532 $this->response->SetError('The name cannot be longer than 100 characters');
533 $this->response->keepOpen = true;533 $this->response->keepOpen = true;
534 return $this->response;534 return $this->response;
535 }535 }
536 536
537 if ($duration == 0)537 if ($duration == 0)
538 {538 {
539 $this->response->SetError('You must enter a duration.');539 $this->response->SetError('You must enter a duration.');
540 $this->response->keepOpen = true;540 $this->response->keepOpen = true;
541 return $this->response;541 return $this->response;
542 }542 }
543 543
544 // Ensure the name is not already in the database544 // Ensure the name is not already in the database
545 $SQL = sprintf("SELECT name FROM media WHERE name = '%s' AND userid = %d", $db->escape_string($name), $userid);545 $SQL = sprintf("SELECT name FROM media WHERE name = '%s' AND userid = %d", $db->escape_string($name), $userid);
546546
547 if(!$result = $db->query($SQL)) 547 if(!$result = $db->query($SQL))
548 {548 {
549 trigger_error($db->error());549 trigger_error($db->error());
550 $this->response->SetError('Error checking whether the media name is ok. Try choosing a different name.');550 $this->response->SetError('Error checking whether the media name is ok. Try choosing a different name.');
551 $this->response->keepOpen = true;551 $this->response->keepOpen = true;
552 return $this->response;552 return $this->response;
553 } 553 }
554554
555 if ($db->num_rows($result) != 0)555 if ($db->num_rows($result) != 0)
556 {556 {
@@ -558,11 +558,11 @@
558 $this->response->keepOpen = true;558 $this->response->keepOpen = true;
559 return $this->response;559 return $this->response;
560 }560 }
561 561
562 // All OK to insert this record562 // All OK to insert this record
563 $SQL = "INSERT INTO media (name, type, duration, originalFilename, permissionID, userID, retired ) ";563 $SQL = "INSERT INTO media (name, type, duration, originalFilename, permissionID, userID, retired ) ";
564 $SQL .= "VALUES ('%s', 'flash', '%s', '%s', %d, %d, 0) ";564 $SQL .= "VALUES ('%s', 'flash', '%s', '%s', %d, %d, 0) ";
565 565
566 $SQL = sprintf($SQL, $db->escape_string($name), $db->escape_string($duration), $db->escape_string($fileName), $permissionid, $userid);566 $SQL = sprintf($SQL, $db->escape_string($name), $db->escape_string($duration), $db->escape_string($fileName), $permissionid, $userid);
567567
568 if (!$mediaid = $db->insert_query($SQL))568 if (!$mediaid = $db->insert_query($SQL))
@@ -572,19 +572,19 @@
572 $this->response->keepOpen = true;572 $this->response->keepOpen = true;
573 return $this->response;573 return $this->response;
574 }574 }
575 575
576 // File upload directory.. get this from the settings object576 // File upload directory.. get this from the settings object
577 $databaseDir = Config::GetSetting($db, "LIBRARY_LOCATION");577 $databaseDir = Config::GetSetting($db, "LIBRARY_LOCATION");
578 578
579 // What are we going to store this media as...579 // What are we going to store this media as...
580 $storedAs = $mediaid.".".$ext;580 $storedAs = $mediaid.".".$ext;
581 581
582 // Now we need to move the file582 // Now we need to move the file
583 if (!$result = rename($databaseDir."temp/".$tmpName, $databaseDir.$storedAs))583 if (!$result = rename($databaseDir."temp/".$tmpName, $databaseDir.$storedAs))
584 {584 {
585 // If we couldnt move it - we need to delete the media record we just added585 // If we couldnt move it - we need to delete the media record we just added
586 $SQL = sprintf("DELETE FROM media WHERE mediaID = %d ", $mediaid);586 $SQL = sprintf("DELETE FROM media WHERE mediaID = %d ", $mediaid);
587 587
588 if (!$db->query($SQL))588 if (!$db->query($SQL))
589 {589 {
590 trigger_error($db->error());590 trigger_error($db->error());
@@ -593,23 +593,27 @@
593 return $this->response;593 return $this->response;
594 }594 }
595 }595 }
596 596
597 // Calculate the MD5 and the file size
598 $md5 = md5_file($databaseDir.$storedAs);
599 $fileSize = filesize($databaseDir.$storedAs);
600
597 // Update the media record to include this information601 // Update the media record to include this information
598 $SQL = sprintf("UPDATE media SET storedAs = '%s' WHERE mediaid = %d", $storedAs, $mediaid);602 $SQL = sprintf("UPDATE media SET storedAs = '%s', `MD5` = '%s', FileSize = %d WHERE mediaid = %d", $storedAs, $md5, $fileSize, $mediaid);
599 603
600 if (!$db->query($SQL))604 if (!$db->query($SQL))
601 {605 {
602 trigger_error($db->error());606 trigger_error($db->error());
603 return true;607 return true;
604 }608 }
605 609
606 // Required Attributes610 // Required Attributes
607 $this->mediaid = $mediaid;611 $this->mediaid = $mediaid;
608 $this->duration = $duration;612 $this->duration = $duration;
609 613
610 // Any Options614 // Any Options
611 $this->SetOption('uri', $storedAs);615 $this->SetOption('uri', $storedAs);
612 616
613 // Should have built the media object entirely by this time617 // Should have built the media object entirely by this time
614 if ($regionid != '')618 if ($regionid != '')
615 {619 {
@@ -619,18 +623,18 @@
619 }623 }
620 else624 else
621 {625 {
622 $this->response->loadFormUri = "index.php?p=content&q=displayForms&sp=add"; 626 $this->response->loadFormUri = "index.php?p=content&q=displayForms&sp=add";
623 }627 }
624 628
625 // We want to load a new form629 // We want to load a new form
626 $this->response->loadForm = true;630 $this->response->loadForm = true;
627 631
628 return $this->response;632 return $this->response;
629 }633 }
630 634
631 /**635 /**
632 * Edit Media in the Database636 * Edit Media in the Database
633 * @return 637 * @return
634 */638 */
635 public function EditMedia()639 public function EditMedia()
636 {640 {
@@ -639,13 +643,13 @@
639 $regionid = $this->regionid;643 $regionid = $this->regionid;
640 $mediaid = $this->mediaid;644 $mediaid = $this->mediaid;
641 $userid = Kit::GetParam('userid', _SESSION, _INT);645 $userid = Kit::GetParam('userid', _SESSION, _INT);
642 646
643 // Stored As from the XML647 // Stored As from the XML
644 $storedAs = $this->GetOption('uri');648 $storedAs = $this->GetOption('uri');
645 649
646 // File data650 // File data
647 $tmpName = Kit::GetParam('hidFileID', _POST, _STRING);651 $tmpName = Kit::GetParam('hidFileID', _POST, _STRING);
648 652
649 if ($tmpName == '')653 if ($tmpName == '')
650 {654 {
651 $fileRevision = false;655 $fileRevision = false;
@@ -653,12 +657,12 @@
653 else657 else
654 {658 {
655 $fileRevision = true;659 $fileRevision = true;
656 660
657 // File name and extension (orignial name)661 // File name and extension (orignial name)
658 $fileName = Kit::GetParam('txtFileName', _POST, _STRING);662 $fileName = Kit::GetParam('txtFileName', _POST, _STRING);
659 $fileName = basename($fileName);663 $fileName = basename($fileName);
660 $ext = strtolower(substr(strrchr($fileName, "."), 1));664 $ext = strtolower(substr(strrchr($fileName, "."), 1));
661 665
662 if ($ext != "swf")666 if ($ext != "swf")
663 {667 {
664 $this->response->SetError('Only SWF files are accepted - Are you sure this is an flash?');668 $this->response->SetError('Only SWF files are accepted - Are you sure this is an flash?');
@@ -666,17 +670,17 @@
666 return $this->response;670 return $this->response;
667 }671 }
668 }672 }
669 673
670 // Other properties674 // Other properties
671 $name = Kit::GetParam('name', _POST, _STRING);675 $name = Kit::GetParam('name', _POST, _STRING);
672 $duration = Kit::GetParam('duration', _POST, _INT, 0);676 $duration = Kit::GetParam('duration', _POST, _INT, 0);
673 $permissionid = Kit::GetParam('permissionid', _POST, _INT, 1);677 $permissionid = Kit::GetParam('permissionid', _POST, _INT, 1);
674 678
675 if ($name == '')679 if ($name == '')
676 {680 {
677 if ($fileRevision)681 if ($fileRevision)
678 {682 {
679 $name = Kit::ValidateParam($fileName, _FILENAME); 683 $name = Kit::ValidateParam($fileName, _FILENAME);
680 }684 }
681 else685 else
682 {686 {
@@ -684,33 +688,33 @@
684 $this->response->keepOpen = true;688 $this->response->keepOpen = true;
685 return $this->response;689 return $this->response;
686 }690 }
687 } 691 }
688 692
689 // Make sure the name isnt too long693 // Make sure the name isnt too long
690 if (strlen($name) > 100) 694 if (strlen($name) > 100)
691 {695 {
692 $this->response->SetError('The name cannot be longer than 100 characters');696 $this->response->SetError('The name cannot be longer than 100 characters');
693 $this->response->keepOpen = true;697 $this->response->keepOpen = true;
694 return $this->response;698 return $this->response;
695 }699 }
696 700
697 if ($duration == 0)701 if ($duration == 0)
698 {702 {
699 $this->response->SetError('You must enter a duration.');703 $this->response->SetError('You must enter a duration.');
700 $this->response->keepOpen = true;704 $this->response->keepOpen = true;
701 return $this->response;705 return $this->response;
702 }706 }
703 707
704 // Ensure the name is not already in the database708 // Ensure the name is not already in the database
705 $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 ", $db->escape_string($name), $userid, $mediaid);
706710
707 if(!$result = $db->query($SQL)) 711 if(!$result = $db->query($SQL))
708 {712 {
709 trigger_error($db->error());713 trigger_error($db->error());
710 $this->response->SetError('Error checking whether the media name is ok. Try choosing a different name.');714 $this->response->SetError('Error checking whether the media name is ok. Try choosing a different name.');
711 $this->response->keepOpen = true;715 $this->response->keepOpen = true;
712 return $this->response;716 return $this->response;
713 } 717 }
714718
715 if ($db->num_rows($result) != 0)719 if ($db->num_rows($result) != 0)
716 {720 {
@@ -718,34 +722,34 @@
718 $this->response->keepOpen = true;722 $this->response->keepOpen = true;
719 return $this->response;723 return $this->response;
720 }724 }
721 725
722 //Are we revising this media - or just plain editing726 //Are we revising this media - or just plain editing
723 if ($fileRevision)727 if ($fileRevision)
724 {728 {
725 // All OK to insert this record729 // All OK to insert this record
726 $SQL = "INSERT INTO media (name, type, duration, originalFilename, permissionID, userID, retired ) ";730 $SQL = "INSERT INTO media (name, type, duration, originalFilename, permissionID, userID, retired ) ";
727 $SQL .= "VALUES ('%s', '%s', '%s', '%s', %d, %d, 0) ";731 $SQL .= "VALUES ('%s', '%s', '%s', '%s', %d, %d, 0) ";
728 732
729 $SQL = sprintf($SQL, $db->escape_string($name), $this->type, $db->escape_string($duration), $db->escape_string($fileName), $permissionid, $userid);733 $SQL = sprintf($SQL, $db->escape_string($name), $this->type, $db->escape_string($duration), $db->escape_string($fileName), $permissionid, $userid);
730 734
731 if (!$new_mediaid = $db->insert_query($SQL))735 if (!$new_mediaid = $db->insert_query($SQL))
732 {736 {
733 trigger_error($db->error());737 trigger_error($db->error());
734 trigger_error('Error inserting replacement media record.', E_USER_ERROR);738 trigger_error('Error inserting replacement media record.', E_USER_ERROR);
735 }739 }
736 740
737 //What are we going to store this media as...741 //What are we going to store this media as...
738 $storedAs = $new_mediaid.".".$ext;742 $storedAs = $new_mediaid.".".$ext;
739 743
740 // File upload directory.. get this from the settings object744 // File upload directory.. get this from the settings object
741 $databaseDir = Config::GetSetting($db, "LIBRARY_LOCATION");745 $databaseDir = Config::GetSetting($db, "LIBRARY_LOCATION");
742 746
743 //Now we need to move the file747 //Now we need to move the file
744 if (!$result = rename($databaseDir."/temp/".$tmpName, $databaseDir.$storedAs))748 if (!$result = rename($databaseDir."/temp/".$tmpName, $databaseDir.$storedAs))
745 {749 {
746 //If we couldnt move it - we need to delete the media record we just added750 //If we couldnt move it - we need to delete the media record we just added
747 $SQL = "DELETE FROM media WHERE mediaID = $new_mediaid ";751 $SQL = "DELETE FROM media WHERE mediaID = $new_mediaid ";
748 752
749 if (!$db->insert_query($SQL))753 if (!$db->insert_query($SQL))
750 {754 {
751 $this->response->SetError('Error rolling back transcation.');755 $this->response->SetError('Error rolling back transcation.');
@@ -753,9 +757,14 @@
753 return $this->response;757 return $this->response;
754 }758 }
755 }759 }
756 760
757 //Update the media record to include this information761 // Calculate the MD5 and the file size
758 $SQL = "UPDATE media SET storedAs = '$storedAs' WHERE mediaid = $new_mediaid";762 $md5 = md5_file($databaseDir.$storedAs);
763 $fileSize = filesize($databaseDir.$storedAs);
764
765 // Update the media record to include this information
766 $SQL = sprintf("UPDATE media SET storedAs = '%s', `MD5` = '%s', FileSize = %d WHERE mediaid = %d", $storedAs, $md5, $fileSize, $new_mediaid);
767
759 if (!$db->query($SQL))768 if (!$db->query($SQL))
760 {769 {
761 trigger_error($db->error());770 trigger_error($db->error());
@@ -763,13 +772,13 @@
763 $this->response->keepOpen = true;772 $this->response->keepOpen = true;
764 return $this->response;773 return $this->response;
765 }774 }
766 775
767 // Update the existing record with the new record's id776 // Update the existing record with the new record's id
768 $SQL = "UPDATE media SET isEdited = 1, editedMediaID = $new_mediaid ";777 $SQL = "UPDATE media SET isEdited = 1, editedMediaID = $new_mediaid ";
769 $SQL .= " WHERE IFNULL(editedMediaID,0) <> $new_mediaid AND mediaID = $mediaid ";778 $SQL .= " WHERE IFNULL(editedMediaID,0) <> $new_mediaid AND mediaID = $mediaid ";
770 779
771 Debug::LogEntry($db, 'audit', $SQL);780 Debug::LogEntry($db, 'audit', $SQL);
772 781
773 if (!$db->query($SQL))782 if (!$db->query($SQL))
774 {783 {
775 trigger_error($db->error());784 trigger_error($db->error());
@@ -783,54 +792,54 @@
783 {792 {
784 // Editing the existing record793 // Editing the existing record
785 $new_mediaid = $mediaid;794 $new_mediaid = $mediaid;
786 795
787 $SQL = "UPDATE media SET name = '%s', duration = %d, permissionID = %d";796 $SQL = "UPDATE media SET name = '%s', duration = %d, permissionID = %d";
788 $SQL .= " WHERE mediaID = %d ";797 $SQL .= " WHERE mediaID = %d ";
789 $SQL = sprintf($SQL, $db->escape_string($name), $duration, $permissionid, $mediaid);798 $SQL = sprintf($SQL, $db->escape_string($name), $duration, $permissionid, $mediaid);
790 799
791 Debug::LogEntry($db, 'audit', $SQL);800 Debug::LogEntry($db, 'audit', $SQL);
792 801
793 if (!$db->query($SQL))802 if (!$db->query($SQL))
794 {803 {
795 trigger_error($db->error());804 trigger_error($db->error());
796 805
797 $this->response->SetError('Database error editing this media record.');806 $this->response->SetError('Database error editing this media record.');
798 $this->response->keepOpen = true;807 $this->response->keepOpen = true;
799 return $this->response;808 return $this->response;
800 }809 }
801 }810 }
802 811
803 // Required Attributes812 // Required Attributes
804 $this->mediaid = $new_mediaid;813 $this->mediaid = $new_mediaid;
805 $this->duration = $duration;814 $this->duration = $duration;
806 815
807 // Any Options816 // Any Options
808 $this->SetOption('uri', $storedAs);817 $this->SetOption('uri', $storedAs);
809 818
810 // Should have built the media object entirely by this time819 // Should have built the media object entirely by this time
811 if ($regionid != '')820 if ($regionid != '')
812 {821 {
813 // This saves the Media Object to the Region822 // This saves the Media Object to the Region
814 $this->UpdateRegion();823 $this->UpdateRegion();
815 824
816 $this->response->loadForm = true;825 $this->response->loadForm = true;
817 $this->response->loadFormUri = "index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions";;826 $this->response->loadFormUri = "index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions";;
818 }827 }
819 else828 else
820 {829 {
821 $this->response->loadFormUri = "index.php?p=content&q=displayForms&sp=add"; 830 $this->response->loadFormUri = "index.php?p=content&q=displayForms&sp=add";
822 $this->response->message = 'Edited the Flash.';831 $this->response->message = 'Edited the Flash.';
823 832
824 }833 }
825 834
826 return $this->response;835 return $this->response;
827 }836 }
828 837
829 /**838 /**
830 * Delete Media from the Database839 * Delete Media from the Database
831 * @return 840 * @return
832 */841 */
833 public function DeleteMedia() 842 public function DeleteMedia()
834 {843 {
835 $db =& $this->db;844 $db =& $this->db;
836 $layoutid = $this->layoutid;845 $layoutid = $this->layoutid;
@@ -838,10 +847,10 @@
838 $mediaid = $this->mediaid;847 $mediaid = $this->mediaid;
839 $userid = Kit::GetParam('userid', _SESSION, _INT);848 $userid = Kit::GetParam('userid', _SESSION, _INT);
840 $options = Kit::GetParam('options', _POST, _WORD);849 $options = Kit::GetParam('options', _POST, _WORD);
841 850
842 // Stored As from the XML851 // Stored As from the XML
843 $this->uri = $this->GetOption('uri');852 $this->uri = $this->GetOption('uri');
844 853
845 // Do we need to remove this from a layout?854 // Do we need to remove this from a layout?
846 if ($layoutid != '')855 if ($layoutid != '')
847 {856 {
@@ -853,72 +862,72 @@
853 // Set this message now in preparation862 // Set this message now in preparation
854 $this->response->message = 'Deleted the Media.';863 $this->response->message = 'Deleted the Media.';
855 }864 }
856 865
857 // If we are set to retire we retire866 // If we are set to retire we retire
858 if ($options == "retire")867 if ($options == "retire")
859 {868 {
860 //Update the media record to say it is retired869 //Update the media record to say it is retired
861 $SQL = "UPDATE media SET retired = 1 WHERE mediaid = $mediaid ";870 $SQL = "UPDATE media SET retired = 1 WHERE mediaid = $mediaid ";
862 871
863 if (!$db->query($SQL))872 if (!$db->query($SQL))
864 {873 {
865 trigger_error($db->error());874 trigger_error($db->error());
866 875
867 $this->response->SetError('Database error retiring this media record.');876 $this->response->SetError('Database error retiring this media record.');
868 $this->response->keepOpen = true;877 $this->response->keepOpen = true;
869 return $this->response;878 return $this->response;
870 }879 }
871 }880 }
872 881
873 //If we are set to delete, we delete882 //If we are set to delete, we delete
874 if ($options == "delete")883 if ($options == "delete")
875 {884 {
876 //Update the media record to say it is retired885 //Update the media record to say it is retired
877 $SQL = "DELETE FROM media WHERE mediaid = $mediaid ";886 $SQL = "DELETE FROM media WHERE mediaid = $mediaid ";
878 887
879 if (!$db->query($SQL))888 if (!$db->query($SQL))
880 {889 {
881 trigger_error($db->error());890 trigger_error($db->error());
882 891
883 $this->response->SetError('Database error deleting this media record.');892 $this->response->SetError('Database error deleting this media record.');
884 $this->response->keepOpen = true;893 $this->response->keepOpen = true;
885 return $this->response;894 return $this->response;
886 }895 }
887 896
888 $this->DeleteMediaFiles();897 $this->DeleteMediaFiles();
889 }898 }
890899
891 return $this->response;900 return $this->response;
892 }901 }
893 902
894 /**903 /**
895 * Deletes the media files associated with this record904 * Deletes the media files associated with this record
896 * @return 905 * @return
897 */906 */
898 private function DeleteMediaFiles()907 private function DeleteMediaFiles()
899 {908 {
900 $db =& $this->db;909 $db =& $this->db;
901 910
902 //Library location911 //Library location
903 $databaseDir = Config::GetSetting($db, "LIBRARY_LOCATION");912 $databaseDir = Config::GetSetting($db, "LIBRARY_LOCATION");
904 913
905 //3 things to check for..914 //3 things to check for..
906 //the actual file, the thumbnail, the background915 //the actual file, the thumbnail, the background
907 if (file_exists($databaseDir.$this->uri))916 if (file_exists($databaseDir.$this->uri))
908 {917 {
909 unlink($databaseDir.$this->uri);918 unlink($databaseDir.$this->uri);
910 }919 }
911 920
912 if (file_exists($databaseDir."tn_".$this->uri))921 if (file_exists($databaseDir."tn_".$this->uri))
913 {922 {
914 unlink($databaseDir."tn_".$this->uri);923 unlink($databaseDir."tn_".$this->uri);
915 }924 }
916 925
917 if (file_exists($databaseDir."bg_".$this->uri))926 if (file_exists($databaseDir."bg_".$this->uri))
918 {927 {
919 unlink($databaseDir."bg_".$this->uri);928 unlink($databaseDir."bg_".$this->uri);
920 }929 }
921 930
922 return true;931 return true;
923 }932 }
924}933}
925934
=== modified file 'server/modules/image.module.php'
--- server/modules/image.module.php 2009-06-28 10:47:06 +0000
+++ server/modules/image.module.php 2009-09-29 22:15:24 +0000
@@ -8,7 +8,7 @@
8 * Xibo is free software: you can redistribute it and/or modify8 * 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 by9 * 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, or10 * the Free Software Foundation, either version 3 of the License, or
11 * any later version. 11 * any later version.
12 *12 *
13 * Xibo is distributed in the hope that it will be useful,13 * Xibo is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -17,31 +17,31 @@
17 *17 *
18 * You should have received a copy of the GNU Affero General Public License18 * 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/>.19 * along with Xibo. If not, see <http://www.gnu.org/licenses/>.
20 */ 20 */
21class image extends Module21class image extends Module
22{22{
23 // Custom Media information23 // Custom Media information
24 private $uri;24 private $uri;
25 private $maxFileSize;25 private $maxFileSize;
26 private $maxFileSizeBytes;26 private $maxFileSizeBytes;
27 27
28 public function __construct(database $db, user $user, $mediaid = '', $layoutid = '', $regionid = '')28 public function __construct(database $db, user $user, $mediaid = '', $layoutid = '', $regionid = '')
29 {29 {
30 // Must set the type of the class30 // Must set the type of the class
31 $this->type = 'image';31 $this->type = 'image';
32 32
33 // Get the max upload size from PHP33 // Get the max upload size from PHP
34 $this->maxFileSize = ini_get('upload_max_filesize');34 $this->maxFileSize = ini_get('upload_max_filesize');
35 $this->maxFileSizeBytes = convertBytes($this->maxFileSize);35 $this->maxFileSizeBytes = convertBytes($this->maxFileSize);
36 36
37 // Must call the parent class 37 // Must call the parent class
38 parent::__construct($db, $user, $mediaid, $layoutid, $regionid);38 parent::__construct($db, $user, $mediaid, $layoutid, $regionid);
39 }39 }
40 40
41 /**41 /**
42 * Sets the Layout and Region Information42 * Sets the Layout and Region Information
43 * it will then fill in any blanks it has about this media if it can43 * it will then fill in any blanks it has about this media if it can
44 * @return 44 * @return
45 * @param $layoutid Object45 * @param $layoutid Object
46 * @param $regionid Object46 * @param $regionid Object
47 * @param $mediaid Object47 * @param $mediaid Object
@@ -53,75 +53,75 @@
53 $this->regionid = $regionid;53 $this->regionid = $regionid;
54 $mediaid = $this->mediaid;54 $mediaid = $this->mediaid;
55 $this->existingMedia = false;55 $this->existingMedia = false;
56 56
57 if ($this->regionSpecific == 1) return;57 if ($this->regionSpecific == 1) return;
58 58
59 // Load what we know about this media into the object59 // Load what we know about this media into the object
60 $SQL = "SELECT name, type, duration, originalFilename, userID, permissionID, retired, storedAs, isEdited, editedMediaID FROM media WHERE mediaID = $mediaid ";60 $SQL = "SELECT name, type, duration, originalFilename, userID, permissionID, retired, storedAs, isEdited, editedMediaID FROM media WHERE mediaID = $mediaid ";
61 61
62 if (!$result = $db->query($SQL))62 if (!$result = $db->query($SQL))
63 {63 {
64 trigger_error($db->error()); //log the error64 trigger_error($db->error()); //log the error
65 return false;65 return false;
66 }66 }
67 67
68 if ($db->num_rows($result) != 1)68 if ($db->num_rows($result) != 1)
69 {69 {
70 trigger_error("More than one row for mediaId [$mediaid] How can this be?");70 trigger_error("More than one row for mediaId [$mediaid] How can this be?");
71 return false;71 return false;
72 }72 }
73 73
74 $row = $db->get_row($result);74 $row = $db->get_row($result);
75 $duration = $row[2];75 $duration = $row[2];
76 $storedAs = $row[7];76 $storedAs = $row[7];
77 77
78 // Required Attributes78 // Required Attributes
79 $this->duration = $duration;79 $this->duration = $duration;
80 80
81 // Any Options81 // Any Options
82 $this->SetOption('uri', $storedAs);82 $this->SetOption('uri', $storedAs);
83 83
84 return true;84 return true;
85 }85 }
86 86
87 /**87 /**
88 * Return the Add Form as HTML88 * Return the Add Form as HTML
89 * @return 89 * @return
90 */90 */
91 public function AddForm()91 public function AddForm()
92 {92 {
93 global $session;93 global $session;
94 $db =& $this->db;94 $db =& $this->db;
95 $user =& $this->user;95 $user =& $this->user;
96 96
97 // Would like to get the regions width / height 97 // Would like to get the regions width / height
98 $layoutid = $this->layoutid;98 $layoutid = $this->layoutid;
99 $regionid = $this->regionid;99 $regionid = $this->regionid;
100 100
101 // Set the Session / Security information101 // Set the Session / Security information
102 $sessionId = session_id();102 $sessionId = session_id();
103 $securityToken = CreateFormToken();103 $securityToken = CreateFormToken();
104 104
105 $session->setSecurityToken($securityToken);105 $session->setSecurityToken($securityToken);
106 106
107 //Get the default value for the shared list107 //Get the default value for the shared list
108 $default = Config::GetSetting($db,"defaultMedia");108 $default = Config::GetSetting($db,"defaultMedia");
109109
110 $permissionid = 0;110 $permissionid = 0;
111111
112 if($default=="private") 112 if($default=="private")
113 {113 {
114 $permissionid = 1;114 $permissionid = 1;
115 }115 }
116 116
117 //shared list117 //shared list
118 $shared_list = dropdownlist("SELECT permissionID, permission FROM permission", "permissionid", $permissionid);118 $shared_list = dropdownlist("SELECT permissionID, permission FROM permission", "permissionid", $permissionid);
119 119
120 //Save button is different depending on if we are on a region or not120 //Save button is different depending on if we are on a region or not
121 if ($regionid != "")121 if ($regionid != "")
122 {122 {
123 setSession('content','mediatype','image');123 setSession('content','mediatype','image');
124 124
125 $save_button = <<<END125 $save_button = <<<END
126 <input id="btnSave" type="submit" value="Save" disabled />126 <input id="btnSave" type="submit" value="Save" disabled />
127 <input class="XiboFormButton" id="btnCancel" type="button" title="Return to the Region Options" href="index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions" value="Cancel" />127 <input class="XiboFormButton" id="btnCancel" type="button" title="Return to the Region Options" href="index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions" value="Cancel" />
@@ -135,7 +135,7 @@
135 <input class="XiboFormButton" id="btnCancel" type="button" title="Close" href="index.php?p=content&q=displayForms&sp=add" value="Cancel" />135 <input class="XiboFormButton" id="btnCancel" type="button" title="Close" href="index.php?p=content&q=displayForms&sp=add" value="Cancel" />
136END;136END;
137 }137 }
138 138
139 $form = <<<FORM139 $form = <<<FORM
140 <div style="display:none"><iframe name="fileupload" width="1px" height="1px"></iframe></div>140 <div style="display:none"><iframe name="fileupload" width="1px" height="1px"></iframe></div>
141 <div>141 <div>
@@ -144,7 +144,7 @@
144 <input type="hidden" id="SecurityToken" value="$securityToken" />144 <input type="hidden" id="SecurityToken" value="$securityToken" />
145 <input type="hidden" name="MAX_FILE_SIZE" value="$this->maxFileSizeBytes" />145 <input type="hidden" name="MAX_FILE_SIZE" value="$this->maxFileSizeBytes" />
146 <table>146 <table>
147 <tr> 147 <tr>
148 <td><label for="file">Image File<span class="required">*</span></label></td>148 <td><label for="file">Image File<span class="required">*</span></label></td>
149 <td colspan="3">149 <td colspan="3">
150 <input type="file" name="media_file" onchange="fileFormSubmit();this.form.submit();" />150 <input type="file" name="media_file" onchange="fileFormSubmit();this.form.submit();" />
@@ -172,7 +172,7 @@
172 <td><label for="permissionid">Sharing<span class="required">*</span></label></td>172 <td><label for="permissionid">Sharing<span class="required">*</span></label></td>
173 <td>173 <td>
174 $shared_list174 $shared_list
175 </td> 175 </td>
176 </tr>176 </tr>
177 <tr>177 <tr>
178 <td></td>178 <td></td>
@@ -194,49 +194,49 @@
194194
195 return $this->response;195 return $this->response;
196 }196 }
197 197
198 /**198 /**
199 * Return the Edit Form as HTML199 * Return the Edit Form as HTML
200 * @return 200 * @return
201 */201 */
202 public function EditForm()202 public function EditForm()
203 {203 {
204 global $session;204 global $session;
205 $db =& $this->db;205 $db =& $this->db;
206 $user =& $this->user;206 $user =& $this->user;
207 207
208 // Would like to get the regions width / height 208 // Would like to get the regions width / height
209 $layoutid = $this->layoutid;209 $layoutid = $this->layoutid;
210 $regionid = $this->regionid;210 $regionid = $this->regionid;
211 $mediaid = $this->mediaid;211 $mediaid = $this->mediaid;
212 $lkid = $this->lkid;212 $lkid = $this->lkid;
213 $userid = Kit::GetParam('userid', _SESSION, _INT);213 $userid = Kit::GetParam('userid', _SESSION, _INT);
214 214
215 // Set the Session / Security information215 // Set the Session / Security information
216 $sessionId = session_id();216 $sessionId = session_id();
217 $securityToken = CreateFormToken();217 $securityToken = CreateFormToken();
218 218
219 $session->setSecurityToken($securityToken);219 $session->setSecurityToken($securityToken);
220 220
221 // Load what we know about this media into the object221 // Load what we know about this media into the object
222 $SQL = "SELECT name, originalFilename, userID, permissionID, retired, storedAs, isEdited, editedMediaID FROM media WHERE mediaID = $mediaid ";222 $SQL = "SELECT name, originalFilename, userID, permissionID, retired, storedAs, isEdited, editedMediaID FROM media WHERE mediaID = $mediaid ";
223 223
224 if (!$result = $db->query($SQL))224 if (!$result = $db->query($SQL))
225 {225 {
226 trigger_error($db->error()); //log the error226 trigger_error($db->error()); //log the error
227 227
228 $this->message = "Error querying for the Media information with media ID [$mediaid] ";228 $this->message = "Error querying for the Media information with media ID [$mediaid] ";
229 return false;229 return false;
230 }230 }
231 231
232 if ($db->num_rows($result) != 1)232 if ($db->num_rows($result) != 1)
233 {233 {
234 trigger_error("More than one row for mediaId [$mediaid] How can this be?");234 trigger_error("More than one row for mediaId [$mediaid] How can this be?");
235 235
236 $this->message = "Error querying for the Media information with media ID [$mediaid] ";236 $this->message = "Error querying for the Media information with media ID [$mediaid] ";
237 return false;237 return false;
238 }238 }
239 239
240 $row = $db->get_row($result);240 $row = $db->get_row($result);
241 $name = $row[0];241 $name = $row[0];
242 $originalFilename = $row[1];242 $originalFilename = $row[1];
@@ -246,23 +246,23 @@
246 $storedAs = $row[5];246 $storedAs = $row[5];
247 $isEdited = $row[6];247 $isEdited = $row[6];
248 $editedMediaID = $row[7];248 $editedMediaID = $row[7];
249 249
250 // derive the ext250 // derive the ext
251 $ext = strtolower(substr(strrchr($originalFilename, "."), 1));251 $ext = strtolower(substr(strrchr($originalFilename, "."), 1));
252 252
253 //Calc the permissions on it aswell253 //Calc the permissions on it aswell
254 list($see_permissions , $edit_permissions) = $user->eval_permission($userid, $permissionid);254 list($see_permissions , $edit_permissions) = $user->eval_permission($userid, $permissionid);
255 255
256 //shared list256 //shared list
257 $shared_list = dropdownlist("SELECT permissionID, permission FROM permission", "permissionid", $permissionid);257 $shared_list = dropdownlist("SELECT permissionID, permission FROM permission", "permissionid", $permissionid);
258 258
259 //Save button is different depending on if we are on a region or not259 //Save button is different depending on if we are on a region or not
260 if ($regionid != "")260 if ($regionid != "")
261 {261 {
262 setSession('content','mediatype','image');262 setSession('content','mediatype','image');
263 263
264 $extraNotes = '<em>Note: Uploading a new media item here will replace it on this layout only.</em>';264 $extraNotes = '<em>Note: Uploading a new media item here will replace it on this layout only.</em>';
265 265
266 $save_button = <<<END266 $save_button = <<<END
267 <input id="btnSave" type="submit" value="Save" />267 <input id="btnSave" type="submit" value="Save" />
268 <input class="XiboFormButton" id="btnCancel" type="button" title="Return to the Region Options" href="index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions" value="Cancel" />268 <input class="XiboFormButton" id="btnCancel" type="button" title="Return to the Region Options" href="index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions" value="Cancel" />
@@ -272,13 +272,13 @@
272 else272 else
273 {273 {
274 $extraNotes = '<em>Note: As you editing from the library uploading a new media item will not replace the old one from any layouts. To do this nagivate to the layout and edit the media from there.</em>';274 $extraNotes = '<em>Note: As you editing from the library uploading a new media item will not replace the old one from any layouts. To do this nagivate to the layout and edit the media from there.</em>';
275 275
276 $save_button = <<<END276 $save_button = <<<END
277 <input id="btnSave" type="submit" value="Save" />277 <input id="btnSave" type="submit" value="Save" />
278 <input id="btnCancel" type="button" title="Close" onclick="$('#div_dialog').dialog('close')" value="Cancel" />278 <input id="btnCancel" type="button" title="Close" onclick="$('#div_dialog').dialog('close')" value="Cancel" />
279END;279END;
280 }280 }
281 281
282 $form = <<<FORM282 $form = <<<FORM
283 <div style="display:none"><iframe name="fileupload" width="1px" height="1px"></iframe></div>283 <div style="display:none"><iframe name="fileupload" width="1px" height="1px"></iframe></div>
284 <div>284 <div>
@@ -287,7 +287,7 @@
287 <input type="hidden" id="SecurityToken" value="$securityToken" />287 <input type="hidden" id="SecurityToken" value="$securityToken" />
288 <input type="hidden" name="MAX_FILE_SIZE" value="$this->maxFileSizeBytes" />288 <input type="hidden" name="MAX_FILE_SIZE" value="$this->maxFileSizeBytes" />
289 <table>289 <table>
290 <tr> 290 <tr>
291 <td><label for="file">New Image File<span class="required">*</span></label></td>291 <td><label for="file">New Image File<span class="required">*</span></label></td>
292 <td colspan="3">292 <td colspan="3">
293 <input type="file" name="media_file" onchange="fileFormSubmit();this.form.submit();" />293 <input type="file" name="media_file" onchange="fileFormSubmit();this.form.submit();" />
@@ -319,7 +319,7 @@
319 <td><label for="permissionid">Sharing<span class="required">*</span></label></td>319 <td><label for="permissionid">Sharing<span class="required">*</span></label></td>
320 <td>320 <td>
321 $shared_list321 $shared_list
322 </td> 322 </td>
323 </tr>323 </tr>
324 <tr>324 <tr>
325 <td></td>325 <td></td>
@@ -343,50 +343,50 @@
343 $this->response->dialogWidth = '450px';343 $this->response->dialogWidth = '450px';
344 $this->response->dialogHeight = '280px';344 $this->response->dialogHeight = '280px';
345345
346 return $this->response; 346 return $this->response;
347 }347 }
348 348
349 /**349 /**
350 * Return the Delete Form as HTML350 * Return the Delete Form as HTML
351 * @return 351 * @return
352 */352 */
353 public function DeleteForm()353 public function DeleteForm()
354 {354 {
355 $db =& $this->db;355 $db =& $this->db;
356 $user =& $this->user;356 $user =& $this->user;
357 357
358 // Would like to get the regions width / height 358 // Would like to get the regions width / height
359 $layoutid = $this->layoutid;359 $layoutid = $this->layoutid;
360 $regionid = $this->regionid;360 $regionid = $this->regionid;
361 $mediaid = $this->mediaid;361 $mediaid = $this->mediaid;
362 $lkid = $this->lkid;362 $lkid = $this->lkid;
363 $userid = Kit::GetParam('userid', _SESSION, _INT);363 $userid = Kit::GetParam('userid', _SESSION, _INT);
364 364
365 $options = "";365 $options = "";
366 //Always have the abilty to unassign from the region366 //Always have the abilty to unassign from the region
367 $options .= "unassign|Unassign from this region only";367 $options .= "unassign|Unassign from this region only";
368 368
369 // Load what we know about this media into the object369 // Load what we know about this media into the object
370 $SQL = "SELECT name, type, duration, originalFilename, userID, permissionID, retired, storedAs, isEdited, editedMediaID FROM media WHERE mediaID = $mediaid ";370 $SQL = "SELECT name, type, duration, originalFilename, userID, permissionID, retired, storedAs, isEdited, editedMediaID FROM media WHERE mediaID = $mediaid ";
371 371
372 if (!$result = $db->query($SQL))372 if (!$result = $db->query($SQL))
373 {373 {
374 trigger_error($db->error()); //log the error374 trigger_error($db->error()); //log the error
375 375
376 $this->response->SetError('Error querying for the Media information with media ID [$mediaid]');376 $this->response->SetError('Error querying for the Media information with media ID [$mediaid]');
377 $this->response->keepOpen = true;377 $this->response->keepOpen = true;
378 return $this->response;378 return $this->response;
379 }379 }
380 380
381 if ($db->num_rows($result) != 1)381 if ($db->num_rows($result) != 1)
382 {382 {
383 trigger_error("More than one row for mediaId [$mediaid] How can this be?");383 trigger_error("More than one row for mediaId [$mediaid] How can this be?");
384 384
385 $this->response->SetError('Error querying for the Media information with media ID [$mediaid]');385 $this->response->SetError('Error querying for the Media information with media ID [$mediaid]');
386 $this->response->keepOpen = true;386 $this->response->keepOpen = true;
387 return $this->response;387 return $this->response;
388 }388 }
389 389
390 $row = $db->get_row($result);390 $row = $db->get_row($result);
391 $name = $row[0];391 $name = $row[0];
392 $duration = $row[2];392 $duration = $row[2];
@@ -397,18 +397,18 @@
397 $storedAs = $row[7];397 $storedAs = $row[7];
398 $isEdited = $row[8];398 $isEdited = $row[8];
399 $editedMediaID = $row[9];399 $editedMediaID = $row[9];
400 400
401 // derive the ext401 // derive the ext
402 $ext = strtolower(substr(strrchr($originalFilename, "."), 1));402 $ext = strtolower(substr(strrchr($originalFilename, "."), 1));
403 403
404 //Calc the permissions on it aswell404 //Calc the permissions on it aswell
405 list($see_permissions , $edit_permissions) = $user->eval_permission($userid, $permissionid);405 list($see_permissions , $edit_permissions) = $user->eval_permission($userid, $permissionid);
406 406
407 //Is this user allowed to edit this media?407 //Is this user allowed to edit this media?
408 if ($edit_permissions)408 if ($edit_permissions)
409 {409 {
410 $options .= ",retire|Unassign from this region and retire";410 $options .= ",retire|Unassign from this region and retire";
411 411
412 //Is this media retired?412 //Is this media retired?
413 if ($editedMediaID != "")413 if ($editedMediaID != "")
414 {414 {
@@ -418,7 +418,7 @@
418 {418 {
419 $revised = false;419 $revised = false;
420 }420 }
421 421
422 //Is this media being used anywhere else?422 //Is this media being used anywhere else?
423 if ($layoutid == "")423 if ($layoutid == "")
424 {424 {
@@ -429,8 +429,8 @@
429 {429 {
430 $SQL = "SELECT layoutID FROM lklayoutmedia WHERE mediaID = $mediaid AND layoutid <> $layoutid AND regionID <> '$regionid' ";430 $SQL = "SELECT layoutID FROM lklayoutmedia WHERE mediaID = $mediaid AND layoutid <> $layoutid AND regionID <> '$regionid' ";
431 }431 }
432 432
433 if (!$results = $db->query($SQL)) 433 if (!$results = $db->query($SQL))
434 {434 {
435 trigger_error($db->error());435 trigger_error($db->error());
436436
@@ -457,9 +457,9 @@
457 return $this->response;457 return $this->response;
458 }458 }
459 }459 }
460 460
461 $options = ltrim($options, ",");461 $options = ltrim($options, ",");
462 462
463 $deleteOptions = listcontent($options,"options");463 $deleteOptions = listcontent($options,"options");
464464
465 //we can delete465 //we can delete
@@ -474,19 +474,19 @@
474 <input id="btnCancel" type="button" title="No / Cancel" href="index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions" onclick="$('#div_dialog').dialog('close');return false; " value="No" />474 <input id="btnCancel" type="button" title="No / Cancel" href="index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions" onclick="$('#div_dialog').dialog('close');return false; " value="No" />
475 </form>475 </form>
476END;476END;
477 477
478 $this->response->html = $form;478 $this->response->html = $form;
479 $this->response->dialogTitle = 'Delete Image';479 $this->response->dialogTitle = 'Delete Image';
480 $this->response->dialogSize = true;480 $this->response->dialogSize = true;
481 $this->response->dialogWidth = '450px';481 $this->response->dialogWidth = '450px';
482 $this->response->dialogHeight = '280px';482 $this->response->dialogHeight = '280px';
483483
484 return $this->response; 484 return $this->response;
485 }485 }
486 486
487 /**487 /**
488 * Add Media to the Database488 * Add Media to the Database
489 * @return 489 * @return
490 */490 */
491 public function AddMedia()491 public function AddMedia()
492 {492 {
@@ -495,29 +495,29 @@
495 $regionid = $this->regionid;495 $regionid = $this->regionid;
496 $mediaid = $this->mediaid;496 $mediaid = $this->mediaid;
497 $userid = Kit::GetParam('userid', _SESSION, _INT);497 $userid = Kit::GetParam('userid', _SESSION, _INT);
498 498
499 // File data499 // File data
500 $tmpName = Kit::GetParam('hidFileID', _POST, _STRING);500 $tmpName = Kit::GetParam('hidFileID', _POST, _STRING);
501 501
502 if ($tmpName == '')502 if ($tmpName == '')
503 {503 {
504 $this->response->SetError('Cannot save Image details. <br/> You must have picked a file.');504 $this->response->SetError('Cannot save Image details. <br/> You must have picked a file.');
505 $this->response->keepOpen = true;505 $this->response->keepOpen = true;
506 return $this->response;506 return $this->response;
507 }507 }
508 508
509 // File name and extension (orignial name)509 // File name and extension (orignial name)
510 $fileName = Kit::GetParam('txtFileName', _POST, _STRING);510 $fileName = Kit::GetParam('txtFileName', _POST, _STRING);
511 $fileName = basename($fileName);511 $fileName = basename($fileName);
512 $ext = strtolower(substr(strrchr($fileName, "."), 1));512 $ext = strtolower(substr(strrchr($fileName, "."), 1));
513 513
514 // Other properties514 // Other properties
515 $name = Kit::GetParam('name', _POST, _STRING);515 $name = Kit::GetParam('name', _POST, _STRING);
516 $duration = Kit::GetParam('duration', _POST, _INT, 0);516 $duration = Kit::GetParam('duration', _POST, _INT, 0);
517 $permissionid = Kit::GetParam('permissionid', _POST, _INT, 1);517 $permissionid = Kit::GetParam('permissionid', _POST, _INT, 1);
518 518
519 if ($name == '') $name = Kit::ValidateParam($fileName, _FILENAME);519 if ($name == '') $name = Kit::ValidateParam($fileName, _FILENAME);
520 520
521 // Validation521 // Validation
522 if ($ext != "jpeg" && $ext != "jpg" && $ext != "png" && $ext != "gif")522 if ($ext != "jpeg" && $ext != "jpg" && $ext != "png" && $ext != "gif")
523 {523 {
@@ -525,32 +525,32 @@
525 $this->response->keepOpen = true;525 $this->response->keepOpen = true;
526 return $this->response;526 return $this->response;
527 }527 }
528 528
529 // Make sure the name isnt too long529 // Make sure the name isnt too long
530 if (strlen($name) > 100) 530 if (strlen($name) > 100)
531 {531 {
532 $this->response->SetError('The name cannot be longer than 100 characters');532 $this->response->SetError('The name cannot be longer than 100 characters');
533 $this->response->keepOpen = true;533 $this->response->keepOpen = true;
534 return $this->response;534 return $this->response;
535 }535 }
536 536
537 if ($duration == 0)537 if ($duration == 0)
538 {538 {
539 $this->response->SetError('You must enter a duration.');539 $this->response->SetError('You must enter a duration.');
540 $this->response->keepOpen = true;540 $this->response->keepOpen = true;
541 return $this->response;541 return $this->response;
542 }542 }
543 543
544 // Ensure the name is not already in the database544 // Ensure the name is not already in the database
545 $SQL = sprintf("SELECT name FROM media WHERE name = '%s' AND userid = %d", $db->escape_string($name), $userid);545 $SQL = sprintf("SELECT name FROM media WHERE name = '%s' AND userid = %d", $db->escape_string($name), $userid);
546546
547 if(!$result = $db->query($SQL)) 547 if(!$result = $db->query($SQL))
548 {548 {
549 trigger_error($db->error());549 trigger_error($db->error());
550 $this->response->SetError('Error checking whether the media name is ok. Try choosing a different name.');550 $this->response->SetError('Error checking whether the media name is ok. Try choosing a different name.');
551 $this->response->keepOpen = true;551 $this->response->keepOpen = true;
552 return $this->response;552 return $this->response;
553 } 553 }
554554
555 if ($db->num_rows($result) != 0)555 if ($db->num_rows($result) != 0)
556 {556 {
@@ -558,11 +558,11 @@
558 $this->response->keepOpen = true;558 $this->response->keepOpen = true;
559 return $this->response;559 return $this->response;
560 }560 }
561 561
562 // All OK to insert this record562 // All OK to insert this record
563 $SQL = "INSERT INTO media (name, type, duration, originalFilename, permissionID, userID, retired ) ";563 $SQL = "INSERT INTO media (name, type, duration, originalFilename, permissionID, userID, retired ) ";
564 $SQL .= "VALUES ('%s', 'image', '%s', '%s', %d, %d, 0) ";564 $SQL .= "VALUES ('%s', 'image', '%s', '%s', %d, %d, 0) ";
565 565
566 $SQL = sprintf($SQL, $db->escape_string($name), $db->escape_string($duration), $db->escape_string($fileName), $permissionid, $userid);566 $SQL = sprintf($SQL, $db->escape_string($name), $db->escape_string($duration), $db->escape_string($fileName), $permissionid, $userid);
567567
568 if (!$mediaid = $db->insert_query($SQL))568 if (!$mediaid = $db->insert_query($SQL))
@@ -572,19 +572,19 @@
572 $this->response->keepOpen = true;572 $this->response->keepOpen = true;
573 return $this->response;573 return $this->response;
574 }574 }
575 575
576 // File upload directory.. get this from the settings object576 // File upload directory.. get this from the settings object
577 $databaseDir = Config::GetSetting($db, "LIBRARY_LOCATION");577 $databaseDir = Config::GetSetting($db, "LIBRARY_LOCATION");
578 578
579 // What are we going to store this media as...579 // What are we going to store this media as...
580 $storedAs = $mediaid.".".$ext;580 $storedAs = $mediaid.".".$ext;
581 581
582 // Now we need to move the file582 // Now we need to move the file
583 if (!$result = rename($databaseDir."temp/".$tmpName, $databaseDir.$storedAs))583 if (!$result = rename($databaseDir."temp/".$tmpName, $databaseDir.$storedAs))
584 {584 {
585 // If we couldnt move it - we need to delete the media record we just added585 // If we couldnt move it - we need to delete the media record we just added
586 $SQL = sprintf("DELETE FROM media WHERE mediaID = %d ", $mediaid);586 $SQL = sprintf("DELETE FROM media WHERE mediaID = %d ", $mediaid);
587 587
588 if (!$db->query($SQL))588 if (!$db->query($SQL))
589 {589 {
590 trigger_error($db->error());590 trigger_error($db->error());
@@ -593,26 +593,30 @@
593 return $this->response;593 return $this->response;
594 }594 }
595 }595 }
596 596
597 // Calculate the MD5 and the file size
598 $md5 = md5_file($databaseDir.$storedAs);
599 $fileSize = filesize($databaseDir.$storedAs);
600
597 // Update the media record to include this information601 // Update the media record to include this information
598 $SQL = sprintf("UPDATE media SET storedAs = '%s' WHERE mediaid = %d", $storedAs, $mediaid);602 $SQL = sprintf("UPDATE media SET storedAs = '%s', `MD5` = '%s', FileSize = %d WHERE mediaid = %d", $storedAs, $md5, $fileSize, $mediaid);
599 603
600 if (!$db->query($SQL))604 if (!$db->query($SQL))
601 {605 {
602 trigger_error($db->error());606 trigger_error($db->error());
603 return true;607 return true;
604 }608 }
605 609
606 // Create the thumb nail610 // Create the thumb nail
607 ResizeImage($databaseDir.$storedAs, $databaseDir."tn_".$storedAs, 80, 80);611 ResizeImage($databaseDir.$storedAs, $databaseDir."tn_".$storedAs, 80, 80);
608 612
609 // Required Attributes613 // Required Attributes
610 $this->mediaid = $mediaid;614 $this->mediaid = $mediaid;
611 $this->duration = $duration;615 $this->duration = $duration;
612 616
613 // Any Options617 // Any Options
614 $this->SetOption('uri', $storedAs);618 $this->SetOption('uri', $storedAs);
615 619
616 // Should have built the media object entirely by this time620 // Should have built the media object entirely by this time
617 if ($regionid != '')621 if ($regionid != '')
618 {622 {
@@ -622,18 +626,18 @@
622 }626 }
623 else627 else
624 {628 {
625 $this->response->loadFormUri = "index.php?p=content&q=displayForms&sp=add"; 629 $this->response->loadFormUri = "index.php?p=content&q=displayForms&sp=add";
626 }630 }
627 631
628 // We want to load a new form632 // We want to load a new form
629 $this->response->loadForm = true;633 $this->response->loadForm = true;
630 634
631 return $this->response;635 return $this->response;
632 }636 }
633 637
634 /**638 /**
635 * Edit Media in the Database639 * Edit Media in the Database
636 * @return 640 * @return
637 */641 */
638 public function EditMedia()642 public function EditMedia()
639 {643 {
@@ -642,13 +646,13 @@
642 $regionid = $this->regionid;646 $regionid = $this->regionid;
643 $mediaid = $this->mediaid;647 $mediaid = $this->mediaid;
644 $userid = Kit::GetParam('userid', _SESSION, _INT);648 $userid = Kit::GetParam('userid', _SESSION, _INT);
645 649
646 // Stored As from the XML650 // Stored As from the XML
647 $storedAs = $this->GetOption('uri');651 $storedAs = $this->GetOption('uri');
648 652
649 // File data653 // File data
650 $tmpName = Kit::GetParam('hidFileID', _POST, _STRING);654 $tmpName = Kit::GetParam('hidFileID', _POST, _STRING);
651 655
652 if ($tmpName == '')656 if ($tmpName == '')
653 {657 {
654 $fileRevision = false;658 $fileRevision = false;
@@ -656,12 +660,12 @@
656 else660 else
657 {661 {
658 $fileRevision = true;662 $fileRevision = true;
659 663
660 // File name and extension (orignial name)664 // File name and extension (orignial name)
661 $fileName = Kit::GetParam('txtFileName', _POST, _STRING);665 $fileName = Kit::GetParam('txtFileName', _POST, _STRING);
662 $fileName = basename($fileName);666 $fileName = basename($fileName);
663 $ext = strtolower(substr(strrchr($fileName, "."), 1));667 $ext = strtolower(substr(strrchr($fileName, "."), 1));
664 668
665 if ($ext != "jpeg" && $ext != "jpg" && $ext != "png" && $ext != "gif")669 if ($ext != "jpeg" && $ext != "jpg" && $ext != "png" && $ext != "gif")
666 {670 {
667 $this->response->SetError('Only images are accepted - Are you sure this is an image?');671 $this->response->SetError('Only images are accepted - Are you sure this is an image?');
@@ -669,17 +673,17 @@
669 return $this->response;673 return $this->response;
670 }674 }
671 }675 }
672 676
673 // Other properties677 // Other properties
674 $name = Kit::GetParam('name', _POST, _STRING);678 $name = Kit::GetParam('name', _POST, _STRING);
675 $duration = Kit::GetParam('duration', _POST, _INT, 0);679 $duration = Kit::GetParam('duration', _POST, _INT, 0);
676 $permissionid = Kit::GetParam('permissionid', _POST, _INT, 1);680 $permissionid = Kit::GetParam('permissionid', _POST, _INT, 1);
677 681
678 if ($name == '')682 if ($name == '')
679 {683 {
680 if ($fileRevision)684 if ($fileRevision)
681 {685 {
682 $name = Kit::ValidateParam($fileName, _FILENAME); 686 $name = Kit::ValidateParam($fileName, _FILENAME);
683 }687 }
684 else688 else
685 {689 {
@@ -687,33 +691,33 @@
687 $this->response->keepOpen = true;691 $this->response->keepOpen = true;
688 return $this->response;692 return $this->response;
689 }693 }
690 } 694 }
691 695
692 // Make sure the name isnt too long696 // Make sure the name isnt too long
693 if (strlen($name) > 100) 697 if (strlen($name) > 100)
694 {698 {
695 $this->response->SetError('The name cannot be longer than 100 characters');699 $this->response->SetError('The name cannot be longer than 100 characters');
696 $this->response->keepOpen = true;700 $this->response->keepOpen = true;
697 return $this->response;701 return $this->response;
698 }702 }
699 703
700 if ($duration == 0)704 if ($duration == 0)
701 {705 {
702 $this->response->SetError('You must enter a duration.');706 $this->response->SetError('You must enter a duration.');
703 $this->response->keepOpen = true;707 $this->response->keepOpen = true;
704 return $this->response;708 return $this->response;
705 }709 }
706 710
707 // Ensure the name is not already in the database711 // Ensure the name is not already in the database
708 $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 ", $db->escape_string($name), $userid, $mediaid);
709713
710 if(!$result = $db->query($SQL)) 714 if(!$result = $db->query($SQL))
711 {715 {
712 trigger_error($db->error());716 trigger_error($db->error());
713 $this->response->SetError('Error checking whether the media name is ok. Try choosing a different name.');717 $this->response->SetError('Error checking whether the media name is ok. Try choosing a different name.');
714 $this->response->keepOpen = true;718 $this->response->keepOpen = true;
715 return $this->response;719 return $this->response;
716 } 720 }
717721
718 if ($db->num_rows($result) != 0)722 if ($db->num_rows($result) != 0)
719 {723 {
@@ -721,34 +725,34 @@
721 $this->response->keepOpen = true;725 $this->response->keepOpen = true;
722 return $this->response;726 return $this->response;
723 }727 }
724 728
725 //Are we revising this media - or just plain editing729 //Are we revising this media - or just plain editing
726 if ($fileRevision)730 if ($fileRevision)
727 {731 {
728 // All OK to insert this record732 // All OK to insert this record
729 $SQL = "INSERT INTO media (name, type, duration, originalFilename, permissionID, userID, retired ) ";733 $SQL = "INSERT INTO media (name, type, duration, originalFilename, permissionID, userID, retired ) ";
730 $SQL .= "VALUES ('%s', 'image', '%s', '%s', %d, %d, 0) ";734 $SQL .= "VALUES ('%s', 'image', '%s', '%s', %d, %d, 0) ";
731 735
732 $SQL = sprintf($SQL, $db->escape_string($name), $db->escape_string($duration), $db->escape_string($fileName), $permissionid, $userid);736 $SQL = sprintf($SQL, $db->escape_string($name), $db->escape_string($duration), $db->escape_string($fileName), $permissionid, $userid);
733 737
734 if (!$new_mediaid = $db->insert_query($SQL))738 if (!$new_mediaid = $db->insert_query($SQL))
735 {739 {
736 trigger_error($db->error());740 trigger_error($db->error());
737 trigger_error('Error inserting replacement media record.', E_USER_ERROR);741 trigger_error('Error inserting replacement media record.', E_USER_ERROR);
738 }742 }
739 743
740 //What are we going to store this media as...744 //What are we going to store this media as...
741 $storedAs = $new_mediaid.".".$ext;745 $storedAs = $new_mediaid.".".$ext;
742 746
743 // File upload directory.. get this from the settings object747 // File upload directory.. get this from the settings object
744 $databaseDir = Config::GetSetting($db, "LIBRARY_LOCATION");748 $databaseDir = Config::GetSetting($db, "LIBRARY_LOCATION");
745 749
746 //Now we need to move the file750 //Now we need to move the file
747 if (!$result = rename($databaseDir."/temp/".$tmpName, $databaseDir.$storedAs))751 if (!$result = rename($databaseDir."/temp/".$tmpName, $databaseDir.$storedAs))
748 {752 {
749 //If we couldnt move it - we need to delete the media record we just added753 //If we couldnt move it - we need to delete the media record we just added
750 $SQL = "DELETE FROM media WHERE mediaID = $new_mediaid ";754 $SQL = "DELETE FROM media WHERE mediaID = $new_mediaid ";
751 755
752 if (!$db->insert_query($SQL))756 if (!$db->insert_query($SQL))
753 {757 {
754 $this->response->SetError('Error rolling back transcation.');758 $this->response->SetError('Error rolling back transcation.');
@@ -756,9 +760,14 @@
756 return $this->response;760 return $this->response;
757 }761 }
758 }762 }
759 763
760 //Update the media record to include this information764 // Calculate the MD5 and the file size
761 $SQL = "UPDATE media SET storedAs = '$storedAs' WHERE mediaid = $new_mediaid";765 $md5 = md5_file($databaseDir.$storedAs);
766 $fileSize = filesize($databaseDir.$storedAs);
767
768 // Update the media record to include this information
769 $SQL = sprintf("UPDATE media SET storedAs = '%s', `MD5` = '%s', FileSize = %d WHERE mediaid = %d", $storedAs, $md5, $fileSize, $new_mediaid);
770
762 if (!$db->query($SQL))771 if (!$db->query($SQL))
763 {772 {
764 trigger_error($db->error());773 trigger_error($db->error());
@@ -766,20 +775,20 @@
766 $this->response->keepOpen = true;775 $this->response->keepOpen = true;
767 return $this->response;776 return $this->response;
768 }777 }
769 778
770 //Thumb779 //Thumb
771 if ($ext == "jpeg" || $ext == "jpg" || $ext == "png")780 if ($ext == "jpeg" || $ext == "jpg" || $ext == "png")
772 {781 {
773 //Create the thumbnail782 //Create the thumbnail
774 ResizeImage($databaseDir.$storedAs, $databaseDir."tn_".$storedAs, 80, 80);783 ResizeImage($databaseDir.$storedAs, $databaseDir."tn_".$storedAs, 80, 80);
775 }784 }
776 785
777 // Update the existing record with the new record's id786 // Update the existing record with the new record's id
778 $SQL = "UPDATE media SET isEdited = 1, editedMediaID = $new_mediaid ";787 $SQL = "UPDATE media SET isEdited = 1, editedMediaID = $new_mediaid ";
779 $SQL .= " WHERE IFNULL(editedMediaID,0) <> $new_mediaid AND mediaID = $mediaid ";788 $SQL .= " WHERE IFNULL(editedMediaID,0) <> $new_mediaid AND mediaID = $mediaid ";
780 789
781 Debug::LogEntry($db, 'audit', $SQL);790 Debug::LogEntry($db, 'audit', $SQL);
782 791
783 if (!$db->query($SQL))792 if (!$db->query($SQL))
784 {793 {
785 trigger_error($db->error());794 trigger_error($db->error());
@@ -793,54 +802,54 @@
793 {802 {
794 // Editing the existing record803 // Editing the existing record
795 $new_mediaid = $mediaid;804 $new_mediaid = $mediaid;
796 805
797 $SQL = "UPDATE media SET name = '%s', duration = %d, permissionID = %d";806 $SQL = "UPDATE media SET name = '%s', duration = %d, permissionID = %d";
798 $SQL .= " WHERE mediaID = %d ";807 $SQL .= " WHERE mediaID = %d ";
799 $SQL = sprintf($SQL, $db->escape_string($name), $duration, $permissionid, $mediaid);808 $SQL = sprintf($SQL, $db->escape_string($name), $duration, $permissionid, $mediaid);
800 809
801 Debug::LogEntry($db, 'audit', $SQL);810 Debug::LogEntry($db, 'audit', $SQL);
802 811
803 if (!$db->query($SQL))812 if (!$db->query($SQL))
804 {813 {
805 trigger_error($db->error());814 trigger_error($db->error());
806 815
807 $this->response->SetError('Database error editing this media record.');816 $this->response->SetError('Database error editing this media record.');
808 $this->response->keepOpen = true;817 $this->response->keepOpen = true;
809 return $this->response;818 return $this->response;
810 }819 }
811 }820 }
812 821
813 // Required Attributes822 // Required Attributes
814 $this->mediaid = $new_mediaid;823 $this->mediaid = $new_mediaid;
815 $this->duration = $duration;824 $this->duration = $duration;
816 825
817 // Any Options826 // Any Options
818 $this->SetOption('uri', $storedAs);827 $this->SetOption('uri', $storedAs);
819 828
820 // Should have built the media object entirely by this time829 // Should have built the media object entirely by this time
821 if ($regionid != '')830 if ($regionid != '')
822 {831 {
823 // This saves the Media Object to the Region832 // This saves the Media Object to the Region
824 $this->UpdateRegion();833 $this->UpdateRegion();
825 834
826 $this->response->loadForm = true;835 $this->response->loadForm = true;
827 $this->response->loadFormUri = "index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions";;836 $this->response->loadFormUri = "index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions";;
828 }837 }
829 else838 else
830 {839 {
831 $this->response->loadFormUri = "index.php?p=content&q=displayForms&sp=add"; 840 $this->response->loadFormUri = "index.php?p=content&q=displayForms&sp=add";
832 $this->response->message = 'Edited the Image.';841 $this->response->message = 'Edited the Image.';
833 842
834 }843 }
835 844
836 return $this->response;845 return $this->response;
837 }846 }
838 847
839 /**848 /**
840 * Delete Media from the Database849 * Delete Media from the Database
841 * @return 850 * @return
842 */851 */
843 public function DeleteMedia() 852 public function DeleteMedia()
844 {853 {
845 $db =& $this->db;854 $db =& $this->db;
846 $layoutid = $this->layoutid;855 $layoutid = $this->layoutid;
@@ -848,10 +857,10 @@
848 $mediaid = $this->mediaid;857 $mediaid = $this->mediaid;
849 $userid = Kit::GetParam('userid', _SESSION, _INT);858 $userid = Kit::GetParam('userid', _SESSION, _INT);
850 $options = Kit::GetParam('options', _POST, _WORD);859 $options = Kit::GetParam('options', _POST, _WORD);
851 860
852 // Stored As from the XML861 // Stored As from the XML
853 $this->uri = $this->GetOption('uri');862 $this->uri = $this->GetOption('uri');
854 863
855 // Do we need to remove this from a layout?864 // Do we need to remove this from a layout?
856 if ($layoutid != '')865 if ($layoutid != '')
857 {866 {
@@ -863,72 +872,72 @@
863 // Set this message now in preparation872 // Set this message now in preparation
864 $this->response->message = 'Deleted the Media.';873 $this->response->message = 'Deleted the Media.';
865 }874 }
866 875
867 // If we are set to retire we retire876 // If we are set to retire we retire
868 if ($options == "retire")877 if ($options == "retire")
869 {878 {
870 //Update the media record to say it is retired879 //Update the media record to say it is retired
871 $SQL = "UPDATE media SET retired = 1 WHERE mediaid = $mediaid ";880 $SQL = "UPDATE media SET retired = 1 WHERE mediaid = $mediaid ";
872 881
873 if (!$db->query($SQL))882 if (!$db->query($SQL))
874 {883 {
875 trigger_error($db->error());884 trigger_error($db->error());
876 885
877 $this->response->SetError('Database error retiring this media record.');886 $this->response->SetError('Database error retiring this media record.');
878 $this->response->keepOpen = true;887 $this->response->keepOpen = true;
879 return $this->response;888 return $this->response;
880 }889 }
881 }890 }
882 891
883 //If we are set to delete, we delete892 //If we are set to delete, we delete
884 if ($options == "delete")893 if ($options == "delete")
885 {894 {
886 //Update the media record to say it is retired895 //Update the media record to say it is retired
887 $SQL = "DELETE FROM media WHERE mediaid = $mediaid ";896 $SQL = "DELETE FROM media WHERE mediaid = $mediaid ";
888 897
889 if (!$db->query($SQL))898 if (!$db->query($SQL))
890 {899 {
891 trigger_error($db->error());900 trigger_error($db->error());
892 901
893 $this->response->SetError('Database error deleting this media record.');902 $this->response->SetError('Database error deleting this media record.');
894 $this->response->keepOpen = true;903 $this->response->keepOpen = true;
895 return $this->response;904 return $this->response;
896 }905 }
897 906
898 $this->DeleteMediaFiles();907 $this->DeleteMediaFiles();
899 }908 }
900 909
901 return $this->response;910 return $this->response;
902 }911 }
903 912
904 /**913 /**
905 * Deletes the media files associated with this record914 * Deletes the media files associated with this record
906 * @return 915 * @return
907 */916 */
908 private function DeleteMediaFiles()917 private function DeleteMediaFiles()
909 {918 {
910 $db =& $this->db;919 $db =& $this->db;
911 920
912 //Library location921 //Library location
913 $databaseDir = Config::GetSetting($db, "LIBRARY_LOCATION");922 $databaseDir = Config::GetSetting($db, "LIBRARY_LOCATION");
914 923
915 //3 things to check for..924 //3 things to check for..
916 //the actual file, the thumbnail, the background925 //the actual file, the thumbnail, the background
917 if (file_exists($databaseDir.$this->uri))926 if (file_exists($databaseDir.$this->uri))
918 {927 {
919 unlink($databaseDir.$this->uri);928 unlink($databaseDir.$this->uri);
920 }929 }
921 930
922 if (file_exists($databaseDir."tn_".$this->uri))931 if (file_exists($databaseDir."tn_".$this->uri))
923 {932 {
924 unlink($databaseDir."tn_".$this->uri);933 unlink($databaseDir."tn_".$this->uri);
925 }934 }
926 935
927 if (file_exists($databaseDir."bg_".$this->uri))936 if (file_exists($databaseDir."bg_".$this->uri))
928 {937 {
929 unlink($databaseDir."bg_".$this->uri);938 unlink($databaseDir."bg_".$this->uri);
930 }939 }
931 940
932 return true;941 return true;
933 }942 }
934}943}
935944
=== modified file 'server/modules/powerpoint.module.php'
--- server/modules/powerpoint.module.php 2009-06-28 10:47:06 +0000
+++ server/modules/powerpoint.module.php 2009-09-29 22:15:24 +0000
@@ -8,7 +8,7 @@
8 * Xibo is free software: you can redistribute it and/or modify8 * 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 by9 * 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, or10 * the Free Software Foundation, either version 3 of the License, or
11 * any later version. 11 * any later version.
12 *12 *
13 * Xibo is distributed in the hope that it will be useful,13 * Xibo is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -17,31 +17,31 @@
17 *17 *
18 * You should have received a copy of the GNU Affero General Public License18 * 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/>.19 * along with Xibo. If not, see <http://www.gnu.org/licenses/>.
20 */ 20 */
21class powerpoint extends Module21class powerpoint extends Module
22{22{
23 // Custom Media information23 // Custom Media information
24 private $uri;24 private $uri;
25 private $maxFileSize;25 private $maxFileSize;
26 private $maxFileSizeBytes;26 private $maxFileSizeBytes;
27 27
28 public function __construct(database $db, user $user, $mediaid = '', $layoutid = '', $regionid = '')28 public function __construct(database $db, user $user, $mediaid = '', $layoutid = '', $regionid = '')
29 {29 {
30 // Must set the type of the class30 // Must set the type of the class
31 $this->type = 'powerpoint';31 $this->type = 'powerpoint';
32 32
33 // Get the max upload size from PHP33 // Get the max upload size from PHP
34 $this->maxFileSize = ini_get('upload_max_filesize');34 $this->maxFileSize = ini_get('upload_max_filesize');
35 $this->maxFileSizeBytes = convertBytes($this->maxFileSize);35 $this->maxFileSizeBytes = convertBytes($this->maxFileSize);
36 36
37 // Must call the parent class 37 // Must call the parent class
38 parent::__construct($db, $user, $mediaid, $layoutid, $regionid);38 parent::__construct($db, $user, $mediaid, $layoutid, $regionid);
39 }39 }
40 40
41 /**41 /**
42 * Sets the Layout and Region Information42 * Sets the Layout and Region Information
43 * it will then fill in any blanks it has about this media if it can43 * it will then fill in any blanks it has about this media if it can
44 * @return 44 * @return
45 * @param $layoutid Object45 * @param $layoutid Object
46 * @param $regionid Object46 * @param $regionid Object
47 * @param $mediaid Object47 * @param $mediaid Object
@@ -53,75 +53,75 @@
53 $this->regionid = $regionid;53 $this->regionid = $regionid;
54 $mediaid = $this->mediaid;54 $mediaid = $this->mediaid;
55 $this->existingMedia = false;55 $this->existingMedia = false;
56 56
57 if ($this->regionSpecific == 1) return;57 if ($this->regionSpecific == 1) return;
58 58
59 // Load what we know about this media into the object59 // Load what we know about this media into the object
60 $SQL = "SELECT name, type, duration, originalFilename, userID, permissionID, retired, storedAs, isEdited, editedMediaID FROM media WHERE mediaID = $mediaid ";60 $SQL = "SELECT name, type, duration, originalFilename, userID, permissionID, retired, storedAs, isEdited, editedMediaID FROM media WHERE mediaID = $mediaid ";
61 61
62 if (!$result = $db->query($SQL))62 if (!$result = $db->query($SQL))
63 {63 {
64 trigger_error($db->error()); //log the error64 trigger_error($db->error()); //log the error
65 return false;65 return false;
66 }66 }
67 67
68 if ($db->num_rows($result) != 1)68 if ($db->num_rows($result) != 1)
69 {69 {
70 trigger_error("More than one row for mediaId [$mediaid] How can this be?");70 trigger_error("More than one row for mediaId [$mediaid] How can this be?");
71 return false;71 return false;
72 }72 }
73 73
74 $row = $db->get_row($result);74 $row = $db->get_row($result);
75 $duration = $row[2];75 $duration = $row[2];
76 $storedAs = $row[7];76 $storedAs = $row[7];
77 77
78 // Required Attributes78 // Required Attributes
79 $this->duration = $duration;79 $this->duration = $duration;
80 80
81 // Any Options81 // Any Options
82 $this->SetOption('uri', $storedAs);82 $this->SetOption('uri', $storedAs);
83 83
84 return true;84 return true;
85 }85 }
86 86
87 /**87 /**
88 * Return the Add Form as HTML88 * Return the Add Form as HTML
89 * @return 89 * @return
90 */90 */
91 public function AddForm()91 public function AddForm()
92 {92 {
93 global $session;93 global $session;
94 $db =& $this->db;94 $db =& $this->db;
95 $user =& $this->user;95 $user =& $this->user;
96 96
97 // Would like to get the regions width / height 97 // Would like to get the regions width / height
98 $layoutid = $this->layoutid;98 $layoutid = $this->layoutid;
99 $regionid = $this->regionid;99 $regionid = $this->regionid;
100 100
101 // Set the Session / Security information101 // Set the Session / Security information
102 $sessionId = session_id();102 $sessionId = session_id();
103 $securityToken = CreateFormToken();103 $securityToken = CreateFormToken();
104 104
105 $session->setSecurityToken($securityToken);105 $session->setSecurityToken($securityToken);
106 106
107 //Get the default value for the shared list107 //Get the default value for the shared list
108 $default = Config::GetSetting($db,"defaultMedia");108 $default = Config::GetSetting($db,"defaultMedia");
109109
110 $permissionid = 0;110 $permissionid = 0;
111111
112 if($default=="private") 112 if($default=="private")
113 {113 {
114 $permissionid = 1;114 $permissionid = 1;
115 }115 }
116 116
117 //shared list117 //shared list
118 $shared_list = dropdownlist("SELECT permissionID, permission FROM permission", "permissionid", $permissionid);118 $shared_list = dropdownlist("SELECT permissionID, permission FROM permission", "permissionid", $permissionid);
119 119
120 //Save button is different depending on if we are on a region or not120 //Save button is different depending on if we are on a region or not
121 if ($regionid != "")121 if ($regionid != "")
122 {122 {
123 setSession('content','mediatype','powerpoint');123 setSession('content','mediatype','powerpoint');
124 124
125 $save_button = <<<END125 $save_button = <<<END
126 <input id="btnSave" type="submit" value="Save" disabled />126 <input id="btnSave" type="submit" value="Save" disabled />
127 <input class="XiboFormButton" id="btnCancel" type="button" title="Return to the Region Options" href="index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions" value="Cancel" />127 <input class="XiboFormButton" id="btnCancel" type="button" title="Return to the Region Options" href="index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions" value="Cancel" />
@@ -135,7 +135,7 @@
135 <input class="XiboFormButton" id="btnCancel" type="button" title="Close" href="index.php?p=content&q=displayForms&sp=add" value="Cancel" />135 <input class="XiboFormButton" id="btnCancel" type="button" title="Close" href="index.php?p=content&q=displayForms&sp=add" value="Cancel" />
136END;136END;
137 }137 }
138 138
139 $form = <<<FORM139 $form = <<<FORM
140 <div style="display:none"><iframe name="fileupload" width="1px" height="1px"></iframe></div>140 <div style="display:none"><iframe name="fileupload" width="1px" height="1px"></iframe></div>
141 <div>141 <div>
@@ -144,7 +144,7 @@
144 <input type="hidden" id="SecurityToken" value="$securityToken" />144 <input type="hidden" id="SecurityToken" value="$securityToken" />
145 <input type="hidden" name="MAX_FILE_SIZE" value="$this->maxFileSizeBytes" />145 <input type="hidden" name="MAX_FILE_SIZE" value="$this->maxFileSizeBytes" />
146 <table>146 <table>
147 <tr> 147 <tr>
148 <td><label for="file">Powerpoint File<span class="required">*</span></label></td>148 <td><label for="file">Powerpoint File<span class="required">*</span></label></td>
149 <td colspan="3">149 <td colspan="3">
150 <input type="file" name="media_file" onchange="fileFormSubmit();this.form.submit();" />150 <input type="file" name="media_file" onchange="fileFormSubmit();this.form.submit();" />
@@ -172,7 +172,7 @@
172 <td><label for="permissionid">Sharing<span class="required">*</span></label></td>172 <td><label for="permissionid">Sharing<span class="required">*</span></label></td>
173 <td>173 <td>
174 $shared_list174 $shared_list
175 </td> 175 </td>
176 </tr>176 </tr>
177 <tr>177 <tr>
178 <td></td>178 <td></td>
@@ -194,49 +194,49 @@
194194
195 return $this->response;195 return $this->response;
196 }196 }
197 197
198 /**198 /**
199 * Return the Edit Form as HTML199 * Return the Edit Form as HTML
200 * @return 200 * @return
201 */201 */
202 public function EditForm()202 public function EditForm()
203 {203 {
204 global $session;204 global $session;
205 $db =& $this->db;205 $db =& $this->db;
206 $user =& $this->user;206 $user =& $this->user;
207 207
208 // Would like to get the regions width / height 208 // Would like to get the regions width / height
209 $layoutid = $this->layoutid;209 $layoutid = $this->layoutid;
210 $regionid = $this->regionid;210 $regionid = $this->regionid;
211 $mediaid = $this->mediaid;211 $mediaid = $this->mediaid;
212 $lkid = $this->lkid;212 $lkid = $this->lkid;
213 $userid = Kit::GetParam('userid', _SESSION, _INT);213 $userid = Kit::GetParam('userid', _SESSION, _INT);
214 214
215 // Set the Session / Security information215 // Set the Session / Security information
216 $sessionId = session_id();216 $sessionId = session_id();
217 $securityToken = CreateFormToken();217 $securityToken = CreateFormToken();
218 218
219 $session->setSecurityToken($securityToken);219 $session->setSecurityToken($securityToken);
220 220
221 // Load what we know about this media into the object221 // Load what we know about this media into the object
222 $SQL = "SELECT name, originalFilename, userID, permissionID, retired, storedAs, isEdited, editedMediaID FROM media WHERE mediaID = $mediaid ";222 $SQL = "SELECT name, originalFilename, userID, permissionID, retired, storedAs, isEdited, editedMediaID FROM media WHERE mediaID = $mediaid ";
223 223
224 if (!$result = $db->query($SQL))224 if (!$result = $db->query($SQL))
225 {225 {
226 trigger_error($db->error()); //log the error226 trigger_error($db->error()); //log the error
227 227
228 $this->message = "Error querying for the Media information with media ID [$mediaid] ";228 $this->message = "Error querying for the Media information with media ID [$mediaid] ";
229 return false;229 return false;
230 }230 }
231 231
232 if ($db->num_rows($result) != 1)232 if ($db->num_rows($result) != 1)
233 {233 {
234 trigger_error("More than one row for mediaId [$mediaid] How can this be?");234 trigger_error("More than one row for mediaId [$mediaid] How can this be?");
235 235
236 $this->message = "Error querying for the Media information with media ID [$mediaid] ";236 $this->message = "Error querying for the Media information with media ID [$mediaid] ";
237 return false;237 return false;
238 }238 }
239 239
240 $row = $db->get_row($result);240 $row = $db->get_row($result);
241 $name = $row[0];241 $name = $row[0];
242 $originalFilename = $row[1];242 $originalFilename = $row[1];
@@ -246,23 +246,23 @@
246 $storedAs = $row[5];246 $storedAs = $row[5];
247 $isEdited = $row[6];247 $isEdited = $row[6];
248 $editedMediaID = $row[7];248 $editedMediaID = $row[7];
249 249
250 // derive the ext250 // derive the ext
251 $ext = strtolower(substr(strrchr($originalFilename, "."), 1));251 $ext = strtolower(substr(strrchr($originalFilename, "."), 1));
252 252
253 //Calc the permissions on it aswell253 //Calc the permissions on it aswell
254 list($see_permissions , $edit_permissions) = $user->eval_permission($userid, $permissionid);254 list($see_permissions , $edit_permissions) = $user->eval_permission($userid, $permissionid);
255 255
256 //shared list256 //shared list
257 $shared_list = dropdownlist("SELECT permissionID, permission FROM permission", "permissionid", $permissionid);257 $shared_list = dropdownlist("SELECT permissionID, permission FROM permission", "permissionid", $permissionid);
258 258
259 //Save button is different depending on if we are on a region or not259 //Save button is different depending on if we are on a region or not
260 if ($regionid != "")260 if ($regionid != "")
261 {261 {
262 setSession('content','mediatype','powerpoint');262 setSession('content','mediatype','powerpoint');
263 263
264 $extraNotes = '<em>Note: Uploading a new media item here will replace it on this layout only.</em>';264 $extraNotes = '<em>Note: Uploading a new media item here will replace it on this layout only.</em>';
265 265
266 $save_button = <<<END266 $save_button = <<<END
267 <input id="btnSave" type="submit" value="Save" />267 <input id="btnSave" type="submit" value="Save" />
268 <input class="XiboFormButton" id="btnCancel" type="button" title="Return to the Region Options" href="index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions" value="Cancel" />268 <input class="XiboFormButton" id="btnCancel" type="button" title="Return to the Region Options" href="index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions" value="Cancel" />
@@ -272,13 +272,13 @@
272 else272 else
273 {273 {
274 $extraNotes = '<em>Note: Uploading a new media item here will replace it on this layout only.</em>';274 $extraNotes = '<em>Note: Uploading a new media item here will replace it on this layout only.</em>';
275 275
276 $save_button = <<<END276 $save_button = <<<END
277 <input id="btnSave" type="submit" value="Save" />277 <input id="btnSave" type="submit" value="Save" />
278 <input id="btnCancel" type="button" title="Close" onclick="$('#div_dialog').dialog('close')" value="Cancel" />278 <input id="btnCancel" type="button" title="Close" onclick="$('#div_dialog').dialog('close')" value="Cancel" />
279END;279END;
280 }280 }
281 281
282 $form = <<<FORM282 $form = <<<FORM
283 <div style="display:none"><iframe name="fileupload" width="1px" height="1px"></iframe></div>283 <div style="display:none"><iframe name="fileupload" width="1px" height="1px"></iframe></div>
284 <div>284 <div>
@@ -287,7 +287,7 @@
287 <input type="hidden" id="SecurityToken" value="$securityToken" />287 <input type="hidden" id="SecurityToken" value="$securityToken" />
288 <input type="hidden" name="MAX_FILE_SIZE" value="$this->maxFileSizeBytes" />288 <input type="hidden" name="MAX_FILE_SIZE" value="$this->maxFileSizeBytes" />
289 <table>289 <table>
290 <tr> 290 <tr>
291 <td><label for="file">New Powerpoint File<span class="required">*</span></label></td>291 <td><label for="file">New Powerpoint File<span class="required">*</span></label></td>
292 <td colspan="3">292 <td colspan="3">
293 <input type="file" name="media_file" onchange="fileFormSubmit();this.form.submit();" />293 <input type="file" name="media_file" onchange="fileFormSubmit();this.form.submit();" />
@@ -319,7 +319,7 @@
319 <td><label for="permissionid">Sharing<span class="required">*</span></label></td>319 <td><label for="permissionid">Sharing<span class="required">*</span></label></td>
320 <td>320 <td>
321 $shared_list321 $shared_list
322 </td> 322 </td>
323 </tr>323 </tr>
324 <tr>324 <tr>
325 <td></td>325 <td></td>
@@ -343,50 +343,50 @@
343 $this->response->dialogWidth = '450px';343 $this->response->dialogWidth = '450px';
344 $this->response->dialogHeight = '280px';344 $this->response->dialogHeight = '280px';
345345
346 return $this->response; 346 return $this->response;
347 }347 }
348 348
349 /**349 /**
350 * Return the Delete Form as HTML350 * Return the Delete Form as HTML
351 * @return 351 * @return
352 */352 */
353 public function DeleteForm()353 public function DeleteForm()
354 {354 {
355 $db =& $this->db;355 $db =& $this->db;
356 $user =& $this->user;356 $user =& $this->user;
357 357
358 // Would like to get the regions width / height 358 // Would like to get the regions width / height
359 $layoutid = $this->layoutid;359 $layoutid = $this->layoutid;
360 $regionid = $this->regionid;360 $regionid = $this->regionid;
361 $mediaid = $this->mediaid;361 $mediaid = $this->mediaid;
362 $lkid = $this->lkid;362 $lkid = $this->lkid;
363 $userid = Kit::GetParam('userid', _SESSION, _INT);363 $userid = Kit::GetParam('userid', _SESSION, _INT);
364 364
365 $options = "";365 $options = "";
366 //Always have the abilty to unassign from the region366 //Always have the abilty to unassign from the region
367 $options .= "unassign|Unassign from this region only";367 $options .= "unassign|Unassign from this region only";
368 368
369 // Load what we know about this media into the object369 // Load what we know about this media into the object
370 $SQL = "SELECT name, type, duration, originalFilename, userID, permissionID, retired, storedAs, isEdited, editedMediaID FROM media WHERE mediaID = $mediaid ";370 $SQL = "SELECT name, type, duration, originalFilename, userID, permissionID, retired, storedAs, isEdited, editedMediaID FROM media WHERE mediaID = $mediaid ";
371 371
372 if (!$result = $db->query($SQL))372 if (!$result = $db->query($SQL))
373 {373 {
374 trigger_error($db->error()); //log the error374 trigger_error($db->error()); //log the error
375 375
376 $this->response->SetError('Error querying for the Media information with media ID [$mediaid]');376 $this->response->SetError('Error querying for the Media information with media ID [$mediaid]');
377 $this->response->keepOpen = true;377 $this->response->keepOpen = true;
378 return $this->response;378 return $this->response;
379 }379 }
380 380
381 if ($db->num_rows($result) != 1)381 if ($db->num_rows($result) != 1)
382 {382 {
383 trigger_error("More than one row for mediaId [$mediaid] How can this be?");383 trigger_error("More than one row for mediaId [$mediaid] How can this be?");
384 384
385 $this->response->SetError('Error querying for the Media information with media ID [$mediaid]');385 $this->response->SetError('Error querying for the Media information with media ID [$mediaid]');
386 $this->response->keepOpen = true;386 $this->response->keepOpen = true;
387 return $this->response;387 return $this->response;
388 }388 }
389 389
390 $row = $db->get_row($result);390 $row = $db->get_row($result);
391 $name = $row[0];391 $name = $row[0];
392 $duration = $row[2];392 $duration = $row[2];
@@ -397,18 +397,18 @@
397 $storedAs = $row[7];397 $storedAs = $row[7];
398 $isEdited = $row[8];398 $isEdited = $row[8];
399 $editedMediaID = $row[9];399 $editedMediaID = $row[9];
400 400
401 // derive the ext401 // derive the ext
402 $ext = strtolower(substr(strrchr($originalFilename, "."), 1));402 $ext = strtolower(substr(strrchr($originalFilename, "."), 1));
403 403
404 //Calc the permissions on it aswell404 //Calc the permissions on it aswell
405 list($see_permissions , $edit_permissions) = $user->eval_permission($userid, $permissionid);405 list($see_permissions , $edit_permissions) = $user->eval_permission($userid, $permissionid);
406 406
407 //Is this user allowed to edit this media?407 //Is this user allowed to edit this media?
408 if ($edit_permissions)408 if ($edit_permissions)
409 {409 {
410 $options .= ",retire|Unassign from this region and retire";410 $options .= ",retire|Unassign from this region and retire";
411 411
412 //Is this media retired?412 //Is this media retired?
413 if ($editedMediaID != "")413 if ($editedMediaID != "")
414 {414 {
@@ -418,7 +418,7 @@
418 {418 {
419 $revised = false;419 $revised = false;
420 }420 }
421 421
422 //Is this media being used anywhere else?422 //Is this media being used anywhere else?
423 if ($layoutid == "")423 if ($layoutid == "")
424 {424 {
@@ -429,8 +429,8 @@
429 {429 {
430 $SQL = "SELECT layoutID FROM lklayoutmedia WHERE mediaID = $mediaid AND layoutid <> $layoutid AND regionID <> '$regionid' ";430 $SQL = "SELECT layoutID FROM lklayoutmedia WHERE mediaID = $mediaid AND layoutid <> $layoutid AND regionID <> '$regionid' ";
431 }431 }
432 432
433 if (!$results = $db->query($SQL)) 433 if (!$results = $db->query($SQL))
434 {434 {
435 trigger_error($db->error());435 trigger_error($db->error());
436436
@@ -457,9 +457,9 @@
457 return $this->response;457 return $this->response;
458 }458 }
459 }459 }
460 460
461 $options = ltrim($options, ",");461 $options = ltrim($options, ",");
462 462
463 $deleteOptions = listcontent($options,"options");463 $deleteOptions = listcontent($options,"options");
464464
465 //we can delete465 //we can delete
@@ -474,19 +474,19 @@
474 <input id="btnCancel" type="button" title="No / Cancel" href="index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions" onclick="$('#div_dialog').dialog('close');return false; " value="No" />474 <input id="btnCancel" type="button" title="No / Cancel" href="index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions" onclick="$('#div_dialog').dialog('close');return false; " value="No" />
475 </form>475 </form>
476END;476END;
477 477
478 $this->response->html = $form;478 $this->response->html = $form;
479 $this->response->dialogTitle = 'Delete Powerpoint';479 $this->response->dialogTitle = 'Delete Powerpoint';
480 $this->response->dialogSize = true;480 $this->response->dialogSize = true;
481 $this->response->dialogWidth = '450px';481 $this->response->dialogWidth = '450px';
482 $this->response->dialogHeight = '280px';482 $this->response->dialogHeight = '280px';
483483
484 return $this->response; 484 return $this->response;
485 }485 }
486 486
487 /**487 /**
488 * Add Media to the Database488 * Add Media to the Database
489 * @return 489 * @return
490 */490 */
491 public function AddMedia()491 public function AddMedia()
492 {492 {
@@ -495,29 +495,29 @@
495 $regionid = $this->regionid;495 $regionid = $this->regionid;
496 $mediaid = $this->mediaid;496 $mediaid = $this->mediaid;
497 $userid = Kit::GetParam('userid', _SESSION, _INT);497 $userid = Kit::GetParam('userid', _SESSION, _INT);
498 498
499 // File data499 // File data
500 $tmpName = Kit::GetParam('hidFileID', _POST, _STRING);500 $tmpName = Kit::GetParam('hidFileID', _POST, _STRING);
501 501
502 if ($tmpName == '')502 if ($tmpName == '')
503 {503 {
504 $this->response->SetError('Cannot save Powerpoint details. <br/> You must have picked a file.');504 $this->response->SetError('Cannot save Powerpoint details. <br/> You must have picked a file.');
505 $this->response->keepOpen = true;505 $this->response->keepOpen = true;
506 return $this->response;506 return $this->response;
507 }507 }
508 508
509 // File name and extension (orignial name)509 // File name and extension (orignial name)
510 $fileName = Kit::GetParam('txtFileName', _POST, _STRING);510 $fileName = Kit::GetParam('txtFileName', _POST, _STRING);
511 $fileName = basename($fileName);511 $fileName = basename($fileName);
512 $ext = strtolower(substr(strrchr($fileName, "."), 1));512 $ext = strtolower(substr(strrchr($fileName, "."), 1));
513 513
514 // Other properties514 // Other properties
515 $name = Kit::GetParam('name', _POST, _STRING);515 $name = Kit::GetParam('name', _POST, _STRING);
516 $duration = Kit::GetParam('duration', _POST, _INT, 0);516 $duration = Kit::GetParam('duration', _POST, _INT, 0);
517 $permissionid = Kit::GetParam('permissionid', _POST, _INT, 1);517 $permissionid = Kit::GetParam('permissionid', _POST, _INT, 1);
518 518
519 if ($name == '') $name = Kit::ValidateParam($fileName, _FILENAME);519 if ($name == '') $name = Kit::ValidateParam($fileName, _FILENAME);
520 520
521 // Validation521 // Validation
522 if ($ext != "ppt")522 if ($ext != "ppt")
523 {523 {
@@ -525,32 +525,32 @@
525 $this->response->keepOpen = true;525 $this->response->keepOpen = true;
526 return $this->response;526 return $this->response;
527 }527 }
528 528
529 // Make sure the name isnt too long529 // Make sure the name isnt too long
530 if (strlen($name) > 100) 530 if (strlen($name) > 100)
531 {531 {
532 $this->response->SetError('The name cannot be longer than 100 characters');532 $this->response->SetError('The name cannot be longer than 100 characters');
533 $this->response->keepOpen = true;533 $this->response->keepOpen = true;
534 return $this->response;534 return $this->response;
535 }535 }
536 536
537 if ($duration == 0)537 if ($duration == 0)
538 {538 {
539 $this->response->SetError('You must enter a duration.');539 $this->response->SetError('You must enter a duration.');
540 $this->response->keepOpen = true;540 $this->response->keepOpen = true;
541 return $this->response;541 return $this->response;
542 }542 }
543 543
544 // Ensure the name is not already in the database544 // Ensure the name is not already in the database
545 $SQL = sprintf("SELECT name FROM media WHERE name = '%s' AND userid = %d", $db->escape_string($name), $userid);545 $SQL = sprintf("SELECT name FROM media WHERE name = '%s' AND userid = %d", $db->escape_string($name), $userid);
546546
547 if(!$result = $db->query($SQL)) 547 if(!$result = $db->query($SQL))
548 {548 {
549 trigger_error($db->error());549 trigger_error($db->error());
550 $this->response->SetError('Error checking whether the media name is ok. Try choosing a different name.');550 $this->response->SetError('Error checking whether the media name is ok. Try choosing a different name.');
551 $this->response->keepOpen = true;551 $this->response->keepOpen = true;
552 return $this->response;552 return $this->response;
553 } 553 }
554554
555 if ($db->num_rows($result) != 0)555 if ($db->num_rows($result) != 0)
556 {556 {
@@ -558,11 +558,11 @@
558 $this->response->keepOpen = true;558 $this->response->keepOpen = true;
559 return $this->response;559 return $this->response;
560 }560 }
561 561
562 // All OK to insert this record562 // All OK to insert this record
563 $SQL = "INSERT INTO media (name, type, duration, originalFilename, permissionID, userID, retired ) ";563 $SQL = "INSERT INTO media (name, type, duration, originalFilename, permissionID, userID, retired ) ";
564 $SQL .= "VALUES ('%s', 'powerpoint', '%s', '%s', %d, %d, 0) ";564 $SQL .= "VALUES ('%s', 'powerpoint', '%s', '%s', %d, %d, 0) ";
565 565
566 $SQL = sprintf($SQL, $db->escape_string($name), $db->escape_string($duration), $db->escape_string($fileName), $permissionid, $userid);566 $SQL = sprintf($SQL, $db->escape_string($name), $db->escape_string($duration), $db->escape_string($fileName), $permissionid, $userid);
567567
568 if (!$mediaid = $db->insert_query($SQL))568 if (!$mediaid = $db->insert_query($SQL))
@@ -572,19 +572,19 @@
572 $this->response->keepOpen = true;572 $this->response->keepOpen = true;
573 return $this->response;573 return $this->response;
574 }574 }
575 575
576 // File upload directory.. get this from the settings object576 // File upload directory.. get this from the settings object
577 $databaseDir = Config::GetSetting($db, "LIBRARY_LOCATION");577 $databaseDir = Config::GetSetting($db, "LIBRARY_LOCATION");
578 578
579 // What are we going to store this media as...579 // What are we going to store this media as...
580 $storedAs = $mediaid.".".$ext;580 $storedAs = $mediaid.".".$ext;
581 581
582 // Now we need to move the file582 // Now we need to move the file
583 if (!$result = rename($databaseDir."temp/".$tmpName, $databaseDir.$storedAs))583 if (!$result = rename($databaseDir."temp/".$tmpName, $databaseDir.$storedAs))
584 {584 {
585 // If we couldnt move it - we need to delete the media record we just added585 // If we couldnt move it - we need to delete the media record we just added
586 $SQL = sprintf("DELETE FROM media WHERE mediaID = %d ", $mediaid);586 $SQL = sprintf("DELETE FROM media WHERE mediaID = %d ", $mediaid);
587 587
588 if (!$db->query($SQL))588 if (!$db->query($SQL))
589 {589 {
590 trigger_error($db->error());590 trigger_error($db->error());
@@ -593,23 +593,27 @@
593 return $this->response;593 return $this->response;
594 }594 }
595 }595 }
596 596
597 // Calculate the MD5 and the file size
598 $md5 = md5_file($databaseDir.$storedAs);
599 $fileSize = filesize($databaseDir.$storedAs);
600
597 // Update the media record to include this information601 // Update the media record to include this information
598 $SQL = sprintf("UPDATE media SET storedAs = '%s' WHERE mediaid = %d", $storedAs, $mediaid);602 $SQL = sprintf("UPDATE media SET storedAs = '%s', `MD5` = '%s', FileSize = %d WHERE mediaid = %d", $storedAs, $md5, $fileSize, $mediaid);
599 603
600 if (!$db->query($SQL))604 if (!$db->query($SQL))
601 {605 {
602 trigger_error($db->error());606 trigger_error($db->error());
603 return true;607 return true;
604 }608 }
605 609
606 // Required Attributes610 // Required Attributes
607 $this->mediaid = $mediaid;611 $this->mediaid = $mediaid;
608 $this->duration = $duration;612 $this->duration = $duration;
609 613
610 // Any Options614 // Any Options
611 $this->SetOption('uri', $storedAs);615 $this->SetOption('uri', $storedAs);
612 616
613 // Should have built the media object entirely by this time617 // Should have built the media object entirely by this time
614 if ($regionid != '')618 if ($regionid != '')
615 {619 {
@@ -619,18 +623,18 @@
619 }623 }
620 else624 else
621 {625 {
622 $this->response->loadFormUri = "index.php?p=content&q=displayForms&sp=add"; 626 $this->response->loadFormUri = "index.php?p=content&q=displayForms&sp=add";
623 }627 }
624 628
625 // We want to load a new form629 // We want to load a new form
626 $this->response->loadForm = true;630 $this->response->loadForm = true;
627 631
628 return $this->response;632 return $this->response;
629 }633 }
630 634
631 /**635 /**
632 * Edit Media in the Database636 * Edit Media in the Database
633 * @return 637 * @return
634 */638 */
635 public function EditMedia()639 public function EditMedia()
636 {640 {
@@ -639,13 +643,13 @@
639 $regionid = $this->regionid;643 $regionid = $this->regionid;
640 $mediaid = $this->mediaid;644 $mediaid = $this->mediaid;
641 $userid = Kit::GetParam('userid', _SESSION, _INT);645 $userid = Kit::GetParam('userid', _SESSION, _INT);
642 646
643 // Stored As from the XML647 // Stored As from the XML
644 $storedAs = $this->GetOption('uri');648 $storedAs = $this->GetOption('uri');
645 649
646 // File data650 // File data
647 $tmpName = Kit::GetParam('hidFileID', _POST, _STRING);651 $tmpName = Kit::GetParam('hidFileID', _POST, _STRING);
648 652
649 if ($tmpName == '')653 if ($tmpName == '')
650 {654 {
651 $fileRevision = false;655 $fileRevision = false;
@@ -653,12 +657,12 @@
653 else657 else
654 {658 {
655 $fileRevision = true;659 $fileRevision = true;
656 660
657 // File name and extension (orignial name)661 // File name and extension (orignial name)
658 $fileName = Kit::GetParam('txtFileName', _POST, _STRING);662 $fileName = Kit::GetParam('txtFileName', _POST, _STRING);
659 $fileName = basename($fileName);663 $fileName = basename($fileName);
660 $ext = strtolower(substr(strrchr($fileName, "."), 1));664 $ext = strtolower(substr(strrchr($fileName, "."), 1));
661 665
662 if ($ext != "ppt")666 if ($ext != "ppt")
663 {667 {
664 $this->response->SetError('Only PPT files are accepted - Are you sure this is a powerpoint?');668 $this->response->SetError('Only PPT files are accepted - Are you sure this is a powerpoint?');
@@ -666,17 +670,17 @@
666 return $this->response;670 return $this->response;
667 }671 }
668 }672 }
669 673
670 // Other properties674 // Other properties
671 $name = Kit::GetParam('name', _POST, _STRING);675 $name = Kit::GetParam('name', _POST, _STRING);
672 $duration = Kit::GetParam('duration', _POST, _INT, 0);676 $duration = Kit::GetParam('duration', _POST, _INT, 0);
673 $permissionid = Kit::GetParam('permissionid', _POST, _INT, 1);677 $permissionid = Kit::GetParam('permissionid', _POST, _INT, 1);
674 678
675 if ($name == '')679 if ($name == '')
676 {680 {
677 if ($fileRevision)681 if ($fileRevision)
678 {682 {
679 $name = Kit::ValidateParam($fileName, _FILENAME); 683 $name = Kit::ValidateParam($fileName, _FILENAME);
680 }684 }
681 else685 else
682 {686 {
@@ -684,33 +688,33 @@
684 $this->response->keepOpen = true;688 $this->response->keepOpen = true;
685 return $this->response;689 return $this->response;
686 }690 }
687 } 691 }
688 692
689 // Make sure the name isnt too long693 // Make sure the name isnt too long
690 if (strlen($name) > 100) 694 if (strlen($name) > 100)
691 {695 {
692 $this->response->SetError('The name cannot be longer than 100 characters');696 $this->response->SetError('The name cannot be longer than 100 characters');
693 $this->response->keepOpen = true;697 $this->response->keepOpen = true;
694 return $this->response;698 return $this->response;
695 }699 }
696 700
697 if ($duration == 0)701 if ($duration == 0)
698 {702 {
699 $this->response->SetError('You must enter a duration.');703 $this->response->SetError('You must enter a duration.');
700 $this->response->keepOpen = true;704 $this->response->keepOpen = true;
701 return $this->response;705 return $this->response;
702 }706 }
703 707
704 // Ensure the name is not already in the database708 // Ensure the name is not already in the database
705 $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 ", $db->escape_string($name), $userid, $mediaid);
706710
707 if(!$result = $db->query($SQL)) 711 if(!$result = $db->query($SQL))
708 {712 {
709 trigger_error($db->error());713 trigger_error($db->error());
710 $this->response->SetError('Error checking whether the media name is ok. Try choosing a different name.');714 $this->response->SetError('Error checking whether the media name is ok. Try choosing a different name.');
711 $this->response->keepOpen = true;715 $this->response->keepOpen = true;
712 return $this->response;716 return $this->response;
713 } 717 }
714718
715 if ($db->num_rows($result) != 0)719 if ($db->num_rows($result) != 0)
716 {720 {
@@ -718,34 +722,34 @@
718 $this->response->keepOpen = true;722 $this->response->keepOpen = true;
719 return $this->response;723 return $this->response;
720 }724 }
721 725
722 //Are we revising this media - or just plain editing726 //Are we revising this media - or just plain editing
723 if ($fileRevision)727 if ($fileRevision)
724 {728 {
725 // All OK to insert this record729 // All OK to insert this record
726 $SQL = "INSERT INTO media (name, type, duration, originalFilename, permissionID, userID, retired ) ";730 $SQL = "INSERT INTO media (name, type, duration, originalFilename, permissionID, userID, retired ) ";
727 $SQL .= "VALUES ('%s', '%s', '%s', '%s', %d, %d, 0) ";731 $SQL .= "VALUES ('%s', '%s', '%s', '%s', %d, %d, 0) ";
728 732
729 $SQL = sprintf($SQL, $db->escape_string($name), $this->type, $db->escape_string($duration), $db->escape_string($fileName), $permissionid, $userid);733 $SQL = sprintf($SQL, $db->escape_string($name), $this->type, $db->escape_string($duration), $db->escape_string($fileName), $permissionid, $userid);
730 734
731 if (!$new_mediaid = $db->insert_query($SQL))735 if (!$new_mediaid = $db->insert_query($SQL))
732 {736 {
733 trigger_error($db->error());737 trigger_error($db->error());
734 trigger_error('Error inserting replacement media record.', E_USER_ERROR);738 trigger_error('Error inserting replacement media record.', E_USER_ERROR);
735 }739 }
736 740
737 //What are we going to store this media as...741 //What are we going to store this media as...
738 $storedAs = $new_mediaid.".".$ext;742 $storedAs = $new_mediaid.".".$ext;
739 743
740 // File upload directory.. get this from the settings object744 // File upload directory.. get this from the settings object
741 $databaseDir = Config::GetSetting($db, "LIBRARY_LOCATION");745 $databaseDir = Config::GetSetting($db, "LIBRARY_LOCATION");
742 746
743 //Now we need to move the file747 //Now we need to move the file
744 if (!$result = rename($databaseDir."/temp/".$tmpName, $databaseDir.$storedAs))748 if (!$result = rename($databaseDir."/temp/".$tmpName, $databaseDir.$storedAs))
745 {749 {
746 //If we couldnt move it - we need to delete the media record we just added750 //If we couldnt move it - we need to delete the media record we just added
747 $SQL = "DELETE FROM media WHERE mediaID = $new_mediaid ";751 $SQL = "DELETE FROM media WHERE mediaID = $new_mediaid ";
748 752
749 if (!$db->insert_query($SQL))753 if (!$db->insert_query($SQL))
750 {754 {
751 $this->response->SetError('Error rolling back transcation.');755 $this->response->SetError('Error rolling back transcation.');
@@ -753,9 +757,14 @@
753 return $this->response;757 return $this->response;
754 }758 }
755 }759 }
756 760
757 //Update the media record to include this information761 // Calculate the MD5 and the file size
758 $SQL = "UPDATE media SET storedAs = '$storedAs' WHERE mediaid = $new_mediaid";762 $md5 = md5_file($databaseDir.$storedAs);
763 $fileSize = filesize($databaseDir.$storedAs);
764
765 // Update the media record to include this information
766 $SQL = sprintf("UPDATE media SET storedAs = '%s', `MD5` = '%s', FileSize = %d WHERE mediaid = %d", $storedAs, $md5, $fileSize, $new_mediaid);
767
759 if (!$db->query($SQL))768 if (!$db->query($SQL))
760 {769 {
761 trigger_error($db->error());770 trigger_error($db->error());
@@ -763,13 +772,13 @@
763 $this->response->keepOpen = true;772 $this->response->keepOpen = true;
764 return $this->response;773 return $this->response;
765 }774 }
766 775
767 // Update the existing record with the new record's id776 // Update the existing record with the new record's id
768 $SQL = "UPDATE media SET isEdited = 1, editedMediaID = $new_mediaid ";777 $SQL = "UPDATE media SET isEdited = 1, editedMediaID = $new_mediaid ";
769 $SQL .= " WHERE IFNULL(editedMediaID,0) <> $new_mediaid AND mediaID = $mediaid ";778 $SQL .= " WHERE IFNULL(editedMediaID,0) <> $new_mediaid AND mediaID = $mediaid ";
770 779
771 Debug::LogEntry($db, 'audit', $SQL);780 Debug::LogEntry($db, 'audit', $SQL);
772 781
773 if (!$db->query($SQL))782 if (!$db->query($SQL))
774 {783 {
775 trigger_error($db->error());784 trigger_error($db->error());
@@ -783,54 +792,54 @@
783 {792 {
784 // Editing the existing record793 // Editing the existing record
785 $new_mediaid = $mediaid;794 $new_mediaid = $mediaid;
786 795
787 $SQL = "UPDATE media SET name = '%s', duration = %d, permissionID = %d";796 $SQL = "UPDATE media SET name = '%s', duration = %d, permissionID = %d";
788 $SQL .= " WHERE mediaID = %d ";797 $SQL .= " WHERE mediaID = %d ";
789 $SQL = sprintf($SQL, $db->escape_string($name), $duration, $permissionid, $mediaid);798 $SQL = sprintf($SQL, $db->escape_string($name), $duration, $permissionid, $mediaid);
790 799
791 Debug::LogEntry($db, 'audit', $SQL);800 Debug::LogEntry($db, 'audit', $SQL);
792 801
793 if (!$db->query($SQL))802 if (!$db->query($SQL))
794 {803 {
795 trigger_error($db->error());804 trigger_error($db->error());
796 805
797 $this->response->SetError('Database error editing this media record.');806 $this->response->SetError('Database error editing this media record.');
798 $this->response->keepOpen = true;807 $this->response->keepOpen = true;
799 return $this->response;808 return $this->response;
800 }809 }
801 }810 }
802 811
803 // Required Attributes812 // Required Attributes
804 $this->mediaid = $new_mediaid;813 $this->mediaid = $new_mediaid;
805 $this->duration = $duration;814 $this->duration = $duration;
806 815
807 // Any Options816 // Any Options
808 $this->SetOption('uri', $storedAs);817 $this->SetOption('uri', $storedAs);
809 818
810 // Should have built the media object entirely by this time819 // Should have built the media object entirely by this time
811 if ($regionid != '')820 if ($regionid != '')
812 {821 {
813 // This saves the Media Object to the Region822 // This saves the Media Object to the Region
814 $this->UpdateRegion();823 $this->UpdateRegion();
815 824
816 $this->response->loadForm = true;825 $this->response->loadForm = true;
817 $this->response->loadFormUri = "index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions";;826 $this->response->loadFormUri = "index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions";;
818 }827 }
819 else828 else
820 {829 {
821 $this->response->loadFormUri = "index.php?p=content&q=displayForms&sp=add"; 830 $this->response->loadFormUri = "index.php?p=content&q=displayForms&sp=add";
822 $this->response->message = 'Edited the Powerpoint.';831 $this->response->message = 'Edited the Powerpoint.';
823 832
824 }833 }
825 834
826 return $this->response;835 return $this->response;
827 }836 }
828 837
829 /**838 /**
830 * Delete Media from the Database839 * Delete Media from the Database
831 * @return 840 * @return
832 */841 */
833 public function DeleteMedia() 842 public function DeleteMedia()
834 {843 {
835 $db =& $this->db;844 $db =& $this->db;
836 $layoutid = $this->layoutid;845 $layoutid = $this->layoutid;
@@ -838,10 +847,10 @@
838 $mediaid = $this->mediaid;847 $mediaid = $this->mediaid;
839 $userid = Kit::GetParam('userid', _SESSION, _INT);848 $userid = Kit::GetParam('userid', _SESSION, _INT);
840 $options = Kit::GetParam('options', _POST, _WORD);849 $options = Kit::GetParam('options', _POST, _WORD);
841 850
842 // Stored As from the XML851 // Stored As from the XML
843 $this->uri = $this->GetOption('uri');852 $this->uri = $this->GetOption('uri');
844 853
845 // Do we need to remove this from a layout?854 // Do we need to remove this from a layout?
846 if ($layoutid != '')855 if ($layoutid != '')
847 {856 {
@@ -853,72 +862,72 @@
853 // Set this message now in preparation862 // Set this message now in preparation
854 $this->response->message = 'Deleted the Media.';863 $this->response->message = 'Deleted the Media.';
855 }864 }
856 865
857 // If we are set to retire we retire866 // If we are set to retire we retire
858 if ($options == "retire")867 if ($options == "retire")
859 {868 {
860 //Update the media record to say it is retired869 //Update the media record to say it is retired
861 $SQL = "UPDATE media SET retired = 1 WHERE mediaid = $mediaid ";870 $SQL = "UPDATE media SET retired = 1 WHERE mediaid = $mediaid ";
862 871
863 if (!$db->query($SQL))872 if (!$db->query($SQL))
864 {873 {
865 trigger_error($db->error());874 trigger_error($db->error());
866 875
867 $this->response->SetError('Database error retiring this media record.');876 $this->response->SetError('Database error retiring this media record.');
868 $this->response->keepOpen = true;877 $this->response->keepOpen = true;
869 return $this->response;878 return $this->response;
870 }879 }
871 }880 }
872 881
873 //If we are set to delete, we delete882 //If we are set to delete, we delete
874 if ($options == "delete")883 if ($options == "delete")
875 {884 {
876 //Update the media record to say it is retired885 //Update the media record to say it is retired
877 $SQL = "DELETE FROM media WHERE mediaid = $mediaid ";886 $SQL = "DELETE FROM media WHERE mediaid = $mediaid ";
878 887
879 if (!$db->query($SQL))888 if (!$db->query($SQL))
880 {889 {
881 trigger_error($db->error());890 trigger_error($db->error());
882 891
883 $this->response->SetError('Database error deleting this media record.');892 $this->response->SetError('Database error deleting this media record.');
884 $this->response->keepOpen = true;893 $this->response->keepOpen = true;
885 return $this->response;894 return $this->response;
886 }895 }
887 896
888 $this->DeleteMediaFiles();897 $this->DeleteMediaFiles();
889 }898 }
890 899
891 return $this->response;900 return $this->response;
892 }901 }
893 902
894 /**903 /**
895 * Deletes the media files associated with this record904 * Deletes the media files associated with this record
896 * @return 905 * @return
897 */906 */
898 private function DeleteMediaFiles()907 private function DeleteMediaFiles()
899 {908 {
900 $db =& $this->db;909 $db =& $this->db;
901 910
902 //Library location911 //Library location
903 $databaseDir = Config::GetSetting($db, "LIBRARY_LOCATION");912 $databaseDir = Config::GetSetting($db, "LIBRARY_LOCATION");
904 913
905 //3 things to check for..914 //3 things to check for..
906 //the actual file, the thumbnail, the background915 //the actual file, the thumbnail, the background
907 if (file_exists($databaseDir.$this->uri))916 if (file_exists($databaseDir.$this->uri))
908 {917 {
909 unlink($databaseDir.$this->uri);918 unlink($databaseDir.$this->uri);
910 }919 }
911 920
912 if (file_exists($databaseDir."tn_".$this->uri))921 if (file_exists($databaseDir."tn_".$this->uri))
913 {922 {
914 unlink($databaseDir."tn_".$this->uri);923 unlink($databaseDir."tn_".$this->uri);
915 }924 }
916 925
917 if (file_exists($databaseDir."bg_".$this->uri))926 if (file_exists($databaseDir."bg_".$this->uri))
918 {927 {
919 unlink($databaseDir."bg_".$this->uri);928 unlink($databaseDir."bg_".$this->uri);
920 }929 }
921 930
922 return true;931 return true;
923 }932 }
924}933}
925934
=== modified file 'server/modules/video.module.php'
--- server/modules/video.module.php 2009-06-28 10:47:06 +0000
+++ server/modules/video.module.php 2009-09-29 22:15:24 +0000
@@ -8,7 +8,7 @@
8 * Xibo is free software: you can redistribute it and/or modify8 * 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 by9 * 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, or10 * the Free Software Foundation, either version 3 of the License, or
11 * any later version. 11 * any later version.
12 *12 *
13 * Xibo is distributed in the hope that it will be useful,13 * Xibo is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -17,31 +17,31 @@
17 *17 *
18 * You should have received a copy of the GNU Affero General Public License18 * 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/>.19 * along with Xibo. If not, see <http://www.gnu.org/licenses/>.
20 */ 20 */
21class video extends Module21class video extends Module
22{22{
23 // Custom Media information23 // Custom Media information
24 private $uri;24 private $uri;
25 private $maxFileSize;25 private $maxFileSize;
26 private $maxFileSizeBytes;26 private $maxFileSizeBytes;
27 27
28 public function __construct(database $db, user $user, $mediaid = '', $layoutid = '', $regionid = '')28 public function __construct(database $db, user $user, $mediaid = '', $layoutid = '', $regionid = '')
29 {29 {
30 // Must set the type of the class30 // Must set the type of the class
31 $this->type = 'video';31 $this->type = 'video';
32 32
33 // Get the max upload size from PHP33 // Get the max upload size from PHP
34 $this->maxFileSize = ini_get('upload_max_filesize');34 $this->maxFileSize = ini_get('upload_max_filesize');
35 $this->maxFileSizeBytes = convertBytes($this->maxFileSize);35 $this->maxFileSizeBytes = convertBytes($this->maxFileSize);
36 36
37 // Must call the parent class 37 // Must call the parent class
38 parent::__construct($db, $user, $mediaid, $layoutid, $regionid);38 parent::__construct($db, $user, $mediaid, $layoutid, $regionid);
39 }39 }
40 40
41 /**41 /**
42 * Sets the Layout and Region Information42 * Sets the Layout and Region Information
43 * it will then fill in any blanks it has about this media if it can43 * it will then fill in any blanks it has about this media if it can
44 * @return 44 * @return
45 * @param $layoutid Object45 * @param $layoutid Object
46 * @param $regionid Object46 * @param $regionid Object
47 * @param $mediaid Object47 * @param $mediaid Object
@@ -53,75 +53,75 @@
53 $this->regionid = $regionid;53 $this->regionid = $regionid;
54 $mediaid = $this->mediaid;54 $mediaid = $this->mediaid;
55 $this->existingMedia = false;55 $this->existingMedia = false;
56 56
57 if ($this->regionSpecific == 1) return;57 if ($this->regionSpecific == 1) return;
58 58
59 // Load what we know about this media into the object59 // Load what we know about this media into the object
60 $SQL = "SELECT name, type, duration, originalFilename, userID, permissionID, retired, storedAs, isEdited, editedMediaID FROM media WHERE mediaID = $mediaid ";60 $SQL = "SELECT name, type, duration, originalFilename, userID, permissionID, retired, storedAs, isEdited, editedMediaID FROM media WHERE mediaID = $mediaid ";
61 61
62 if (!$result = $db->query($SQL))62 if (!$result = $db->query($SQL))
63 {63 {
64 trigger_error($db->error()); //log the error64 trigger_error($db->error()); //log the error
65 return false;65 return false;
66 }66 }
67 67
68 if ($db->num_rows($result) != 1)68 if ($db->num_rows($result) != 1)
69 {69 {
70 trigger_error("More than one row for mediaId [$mediaid] How can this be?");70 trigger_error("More than one row for mediaId [$mediaid] How can this be?");
71 return false;71 return false;
72 }72 }
73 73
74 $row = $db->get_row($result);74 $row = $db->get_row($result);
75 $duration = $row[2];75 $duration = $row[2];
76 $storedAs = $row[7];76 $storedAs = $row[7];
77 77
78 // Required Attributes78 // Required Attributes
79 $this->duration = $duration;79 $this->duration = $duration;
80 80
81 // Any Options81 // Any Options
82 $this->SetOption('uri', $storedAs);82 $this->SetOption('uri', $storedAs);
83 83
84 return true;84 return true;
85 }85 }
86 86
87 /**87 /**
88 * Return the Add Form as HTML88 * Return the Add Form as HTML
89 * @return 89 * @return
90 */90 */
91 public function AddForm()91 public function AddForm()
92 {92 {
93 global $session;93 global $session;
94 $db =& $this->db;94 $db =& $this->db;
95 $user =& $this->user;95 $user =& $this->user;
96 96
97 // Would like to get the regions width / height 97 // Would like to get the regions width / height
98 $layoutid = $this->layoutid;98 $layoutid = $this->layoutid;
99 $regionid = $this->regionid;99 $regionid = $this->regionid;
100 100
101 // Set the Session / Security information101 // Set the Session / Security information
102 $sessionId = session_id();102 $sessionId = session_id();
103 $securityToken = CreateFormToken();103 $securityToken = CreateFormToken();
104 104
105 $session->setSecurityToken($securityToken);105 $session->setSecurityToken($securityToken);
106 106
107 //Get the default value for the shared list107 //Get the default value for the shared list
108 $default = Config::GetSetting($db,"defaultMedia");108 $default = Config::GetSetting($db,"defaultMedia");
109109
110 $permissionid = 0;110 $permissionid = 0;
111111
112 if($default=="private") 112 if($default=="private")
113 {113 {
114 $permissionid = 1;114 $permissionid = 1;
115 }115 }
116 116
117 //shared list117 //shared list
118 $shared_list = dropdownlist("SELECT permissionID, permission FROM permission", "permissionid", $permissionid);118 $shared_list = dropdownlist("SELECT permissionID, permission FROM permission", "permissionid", $permissionid);
119 119
120 //Save button is different depending on if we are on a region or not120 //Save button is different depending on if we are on a region or not
121 if ($regionid != "")121 if ($regionid != "")
122 {122 {
123 setSession('content','mediatype','video');123 setSession('content','mediatype','video');
124 124
125 $save_button = <<<END125 $save_button = <<<END
126 <input id="btnSave" type="submit" value="Save" disabled />126 <input id="btnSave" type="submit" value="Save" disabled />
127 <input class="XiboFormButton" id="btnCancel" type="button" title="Return to the Region Options" href="index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions" value="Cancel" />127 <input class="XiboFormButton" id="btnCancel" type="button" title="Return to the Region Options" href="index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions" value="Cancel" />
@@ -135,7 +135,7 @@
135 <input class="XiboFormButton" id="btnCancel" type="button" title="Close" href="index.php?p=content&q=displayForms&sp=add" value="Cancel" />135 <input class="XiboFormButton" id="btnCancel" type="button" title="Close" href="index.php?p=content&q=displayForms&sp=add" value="Cancel" />
136END;136END;
137 }137 }
138 138
139 $form = <<<FORM139 $form = <<<FORM
140 <div style="display:none"><iframe name="fileupload" width="1px" height="1px"></iframe></div>140 <div style="display:none"><iframe name="fileupload" width="1px" height="1px"></iframe></div>
141 <div>141 <div>
@@ -144,7 +144,7 @@
144 <input type="hidden" id="SecurityToken" value="$securityToken" />144 <input type="hidden" id="SecurityToken" value="$securityToken" />
145 <input type="hidden" name="MAX_FILE_SIZE" value="$this->maxFileSizeBytes" />145 <input type="hidden" name="MAX_FILE_SIZE" value="$this->maxFileSizeBytes" />
146 <table>146 <table>
147 <tr> 147 <tr>
148 <td><label for="file">Video File<span class="required">*</span></label></td>148 <td><label for="file">Video File<span class="required">*</span></label></td>
149 <td colspan="3">149 <td colspan="3">
150 <input type="file" name="media_file" onchange="fileFormSubmit();this.form.submit();" />150 <input type="file" name="media_file" onchange="fileFormSubmit();this.form.submit();" />
@@ -172,7 +172,7 @@
172 <td><label for="permissionid">Sharing<span class="required">*</span></label></td>172 <td><label for="permissionid">Sharing<span class="required">*</span></label></td>
173 <td>173 <td>
174 $shared_list174 $shared_list
175 </td> 175 </td>
176 </tr>176 </tr>
177 <tr>177 <tr>
178 <td></td>178 <td></td>
@@ -194,49 +194,49 @@
194194
195 return $this->response;195 return $this->response;
196 }196 }
197 197
198 /**198 /**
199 * Return the Edit Form as HTML199 * Return the Edit Form as HTML
200 * @return 200 * @return
201 */201 */
202 public function EditForm()202 public function EditForm()
203 {203 {
204 global $session;204 global $session;
205 $db =& $this->db;205 $db =& $this->db;
206 $user =& $this->user;206 $user =& $this->user;
207 207
208 // Would like to get the regions width / height 208 // Would like to get the regions width / height
209 $layoutid = $this->layoutid;209 $layoutid = $this->layoutid;
210 $regionid = $this->regionid;210 $regionid = $this->regionid;
211 $mediaid = $this->mediaid;211 $mediaid = $this->mediaid;
212 $lkid = $this->lkid;212 $lkid = $this->lkid;
213 $userid = Kit::GetParam('userid', _SESSION, _INT);213 $userid = Kit::GetParam('userid', _SESSION, _INT);
214 214
215 // Set the Session / Security information215 // Set the Session / Security information
216 $sessionId = session_id();216 $sessionId = session_id();
217 $securityToken = CreateFormToken();217 $securityToken = CreateFormToken();
218 218
219 $session->setSecurityToken($securityToken);219 $session->setSecurityToken($securityToken);
220 220
221 // Load what we know about this media into the object221 // Load what we know about this media into the object
222 $SQL = "SELECT name, originalFilename, userID, permissionID, retired, storedAs, isEdited, editedMediaID FROM media WHERE mediaID = $mediaid ";222 $SQL = "SELECT name, originalFilename, userID, permissionID, retired, storedAs, isEdited, editedMediaID FROM media WHERE mediaID = $mediaid ";
223 223
224 if (!$result = $db->query($SQL))224 if (!$result = $db->query($SQL))
225 {225 {
226 trigger_error($db->error()); //log the error226 trigger_error($db->error()); //log the error
227 227
228 $this->message = "Error querying for the Media information with media ID [$mediaid] ";228 $this->message = "Error querying for the Media information with media ID [$mediaid] ";
229 return false;229 return false;
230 }230 }
231 231
232 if ($db->num_rows($result) != 1)232 if ($db->num_rows($result) != 1)
233 {233 {
234 trigger_error("More than one row for mediaId [$mediaid] How can this be?");234 trigger_error("More than one row for mediaId [$mediaid] How can this be?");
235 235
236 $this->message = "Error querying for the Media information with media ID [$mediaid] ";236 $this->message = "Error querying for the Media information with media ID [$mediaid] ";
237 return false;237 return false;
238 }238 }
239 239
240 $row = $db->get_row($result);240 $row = $db->get_row($result);
241 $name = $row[0];241 $name = $row[0];
242 $originalFilename = $row[1];242 $originalFilename = $row[1];
@@ -246,23 +246,23 @@
246 $storedAs = $row[5];246 $storedAs = $row[5];
247 $isEdited = $row[6];247 $isEdited = $row[6];
248 $editedMediaID = $row[7];248 $editedMediaID = $row[7];
249 249
250 // derive the ext250 // derive the ext
251 $ext = strtolower(substr(strrchr($originalFilename, "."), 1));251 $ext = strtolower(substr(strrchr($originalFilename, "."), 1));
252 252
253 //Calc the permissions on it aswell253 //Calc the permissions on it aswell
254 list($see_permissions , $edit_permissions) = $user->eval_permission($userid, $permissionid);254 list($see_permissions , $edit_permissions) = $user->eval_permission($userid, $permissionid);
255 255
256 //shared list256 //shared list
257 $shared_list = dropdownlist("SELECT permissionID, permission FROM permission", "permissionid", $permissionid);257 $shared_list = dropdownlist("SELECT permissionID, permission FROM permission", "permissionid", $permissionid);
258 258
259 //Save button is different depending on if we are on a region or not259 //Save button is different depending on if we are on a region or not
260 if ($regionid != "")260 if ($regionid != "")
261 {261 {
262 setSession('content','mediatype','image');262 setSession('content','mediatype','image');
263 263
264 $extraNotes = '<em>Note: Uploading a new media item here will replace it on this layout only.</em>';264 $extraNotes = '<em>Note: Uploading a new media item here will replace it on this layout only.</em>';
265 265
266 $save_button = <<<END266 $save_button = <<<END
267 <input id="btnSave" type="submit" value="Save" />267 <input id="btnSave" type="submit" value="Save" />
268 <input class="XiboFormButton" id="btnCancel" type="button" title="Return to the Region Options" href="index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions" value="Cancel" />268 <input class="XiboFormButton" id="btnCancel" type="button" title="Return to the Region Options" href="index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions" value="Cancel" />
@@ -272,13 +272,13 @@
272 else272 else
273 {273 {
274 $extraNotes = '<em>Note: As you editing from the library uploading a new media item will not replace the old one from any layouts. To do this nagivate to the layout and edit the media from there.</em>';274 $extraNotes = '<em>Note: As you editing from the library uploading a new media item will not replace the old one from any layouts. To do this nagivate to the layout and edit the media from there.</em>';
275 275
276 $save_button = <<<END276 $save_button = <<<END
277 <input id="btnSave" type="submit" value="Save" />277 <input id="btnSave" type="submit" value="Save" />
278 <input id="btnCancel" type="button" title="Close" onclick="$('#div_dialog').dialog('close')" value="Cancel" />278 <input id="btnCancel" type="button" title="Close" onclick="$('#div_dialog').dialog('close')" value="Cancel" />
279END;279END;
280 }280 }
281 281
282 $form = <<<FORM282 $form = <<<FORM
283 <div style="display:none"><iframe name="fileupload" width="1px" height="1px"></iframe></div>283 <div style="display:none"><iframe name="fileupload" width="1px" height="1px"></iframe></div>
284 <div>284 <div>
@@ -287,7 +287,7 @@
287 <input type="hidden" id="SecurityToken" value="$securityToken" />287 <input type="hidden" id="SecurityToken" value="$securityToken" />
288 <input type="hidden" name="MAX_FILE_SIZE" value="$this->maxFileSizeBytes" />288 <input type="hidden" name="MAX_FILE_SIZE" value="$this->maxFileSizeBytes" />
289 <table>289 <table>
290 <tr> 290 <tr>
291 <td><label for="file">New Video File<span class="required">*</span></label></td>291 <td><label for="file">New Video File<span class="required">*</span></label></td>
292 <td colspan="3">292 <td colspan="3">
293 <input type="file" name="media_file" onchange="fileFormSubmit();this.form.submit();" />293 <input type="file" name="media_file" onchange="fileFormSubmit();this.form.submit();" />
@@ -319,7 +319,7 @@
319 <td><label for="permissionid">Sharing<span class="required">*</span></label></td>319 <td><label for="permissionid">Sharing<span class="required">*</span></label></td>
320 <td>320 <td>
321 $shared_list321 $shared_list
322 </td> 322 </td>
323 </tr>323 </tr>
324 <tr>324 <tr>
325 <td></td>325 <td></td>
@@ -343,50 +343,50 @@
343 $this->response->dialogWidth = '450px';343 $this->response->dialogWidth = '450px';
344 $this->response->dialogHeight = '280px';344 $this->response->dialogHeight = '280px';
345345
346 return $this->response; 346 return $this->response;
347 }347 }
348 348
349 /**349 /**
350 * Return the Delete Form as HTML350 * Return the Delete Form as HTML
351 * @return 351 * @return
352 */352 */
353 public function DeleteForm()353 public function DeleteForm()
354 {354 {
355 $db =& $this->db;355 $db =& $this->db;
356 $user =& $this->user;356 $user =& $this->user;
357 357
358 // Would like to get the regions width / height 358 // Would like to get the regions width / height
359 $layoutid = $this->layoutid;359 $layoutid = $this->layoutid;
360 $regionid = $this->regionid;360 $regionid = $this->regionid;
361 $mediaid = $this->mediaid;361 $mediaid = $this->mediaid;
362 $lkid = $this->lkid;362 $lkid = $this->lkid;
363 $userid = Kit::GetParam('userid', _SESSION, _INT);363 $userid = Kit::GetParam('userid', _SESSION, _INT);
364 364
365 $options = "";365 $options = "";
366 //Always have the abilty to unassign from the region366 //Always have the abilty to unassign from the region
367 $options .= "unassign|Unassign from this region only";367 $options .= "unassign|Unassign from this region only";
368 368
369 // Load what we know about this media into the object369 // Load what we know about this media into the object
370 $SQL = "SELECT name, type, duration, originalFilename, userID, permissionID, retired, storedAs, isEdited, editedMediaID FROM media WHERE mediaID = $mediaid ";370 $SQL = "SELECT name, type, duration, originalFilename, userID, permissionID, retired, storedAs, isEdited, editedMediaID FROM media WHERE mediaID = $mediaid ";
371 371
372 if (!$result = $db->query($SQL))372 if (!$result = $db->query($SQL))
373 {373 {
374 trigger_error($db->error()); //log the error374 trigger_error($db->error()); //log the error
375 375
376 $this->response->SetError('Error querying for the Media information with media ID [$mediaid]');376 $this->response->SetError('Error querying for the Media information with media ID [$mediaid]');
377 $this->response->keepOpen = true;377 $this->response->keepOpen = true;
378 return $this->response;378 return $this->response;
379 }379 }
380 380
381 if ($db->num_rows($result) != 1)381 if ($db->num_rows($result) != 1)
382 {382 {
383 trigger_error("More than one row for mediaId [$mediaid] How can this be?");383 trigger_error("More than one row for mediaId [$mediaid] How can this be?");
384 384
385 $this->response->SetError('Error querying for the Media information with media ID [$mediaid]');385 $this->response->SetError('Error querying for the Media information with media ID [$mediaid]');
386 $this->response->keepOpen = true;386 $this->response->keepOpen = true;
387 return $this->response;387 return $this->response;
388 }388 }
389 389
390 $row = $db->get_row($result);390 $row = $db->get_row($result);
391 $name = $row[0];391 $name = $row[0];
392 $duration = $row[2];392 $duration = $row[2];
@@ -397,18 +397,18 @@
397 $storedAs = $row[7];397 $storedAs = $row[7];
398 $isEdited = $row[8];398 $isEdited = $row[8];
399 $editedMediaID = $row[9];399 $editedMediaID = $row[9];
400 400
401 // derive the ext401 // derive the ext
402 $ext = strtolower(substr(strrchr($originalFilename, "."), 1));402 $ext = strtolower(substr(strrchr($originalFilename, "."), 1));
403 403
404 //Calc the permissions on it aswell404 //Calc the permissions on it aswell
405 list($see_permissions , $edit_permissions) = $user->eval_permission($userid, $permissionid);405 list($see_permissions , $edit_permissions) = $user->eval_permission($userid, $permissionid);
406 406
407 //Is this user allowed to edit this media?407 //Is this user allowed to edit this media?
408 if ($edit_permissions)408 if ($edit_permissions)
409 {409 {
410 $options .= ",retire|Unassign from this region and retire";410 $options .= ",retire|Unassign from this region and retire";
411 411
412 //Is this media retired?412 //Is this media retired?
413 if ($editedMediaID != "")413 if ($editedMediaID != "")
414 {414 {
@@ -418,7 +418,7 @@
418 {418 {
419 $revised = false;419 $revised = false;
420 }420 }
421 421
422 //Is this media being used anywhere else?422 //Is this media being used anywhere else?
423 if ($layoutid == "")423 if ($layoutid == "")
424 {424 {
@@ -429,8 +429,8 @@
429 {429 {
430 $SQL = "SELECT layoutID FROM lklayoutmedia WHERE mediaID = $mediaid AND layoutid <> $layoutid AND regionID <> '$regionid' ";430 $SQL = "SELECT layoutID FROM lklayoutmedia WHERE mediaID = $mediaid AND layoutid <> $layoutid AND regionID <> '$regionid' ";
431 }431 }
432 432
433 if (!$results = $db->query($SQL)) 433 if (!$results = $db->query($SQL))
434 {434 {
435 trigger_error($db->error());435 trigger_error($db->error());
436436
@@ -457,9 +457,9 @@
457 return $this->response;457 return $this->response;
458 }458 }
459 }459 }
460 460
461 $options = ltrim($options, ",");461 $options = ltrim($options, ",");
462 462
463 $deleteOptions = listcontent($options,"options");463 $deleteOptions = listcontent($options,"options");
464464
465 //we can delete465 //we can delete
@@ -474,19 +474,19 @@
474 <input id="btnCancel" type="button" title="No / Cancel" href="index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions" onclick="$('#div_dialog').dialog('close');return false; " value="No" />474 <input id="btnCancel" type="button" title="No / Cancel" href="index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions" onclick="$('#div_dialog').dialog('close');return false; " value="No" />
475 </form>475 </form>
476END;476END;
477 477
478 $this->response->html = $form;478 $this->response->html = $form;
479 $this->response->dialogTitle = 'Delete Video';479 $this->response->dialogTitle = 'Delete Video';
480 $this->response->dialogSize = true;480 $this->response->dialogSize = true;
481 $this->response->dialogWidth = '450px';481 $this->response->dialogWidth = '450px';
482 $this->response->dialogHeight = '280px';482 $this->response->dialogHeight = '280px';
483483
484 return $this->response; 484 return $this->response;
485 }485 }
486 486
487 /**487 /**
488 * Add Media to the Database488 * Add Media to the Database
489 * @return 489 * @return
490 */490 */
491 public function AddMedia()491 public function AddMedia()
492 {492 {
@@ -495,29 +495,29 @@
495 $regionid = $this->regionid;495 $regionid = $this->regionid;
496 $mediaid = $this->mediaid;496 $mediaid = $this->mediaid;
497 $userid = Kit::GetParam('userid', _SESSION, _INT);497 $userid = Kit::GetParam('userid', _SESSION, _INT);
498 498
499 // File data499 // File data
500 $tmpName = Kit::GetParam('hidFileID', _POST, _STRING);500 $tmpName = Kit::GetParam('hidFileID', _POST, _STRING);
501 501
502 if ($tmpName == '')502 if ($tmpName == '')
503 {503 {
504 $this->response->SetError('Cannot save Video details. <br/> You must have picked a file.');504 $this->response->SetError('Cannot save Video details. <br/> You must have picked a file.');
505 $this->response->keepOpen = true;505 $this->response->keepOpen = true;
506 return $this->response;506 return $this->response;
507 }507 }
508 508
509 // File name and extension (orignial name)509 // File name and extension (orignial name)
510 $fileName = Kit::GetParam('txtFileName', _POST, _STRING);510 $fileName = Kit::GetParam('txtFileName', _POST, _STRING);
511 $fileName = basename($fileName);511 $fileName = basename($fileName);
512 $ext = strtolower(substr(strrchr($fileName, "."), 1));512 $ext = strtolower(substr(strrchr($fileName, "."), 1));
513 513
514 // Other properties514 // Other properties
515 $name = Kit::GetParam('name', _POST, _STRING);515 $name = Kit::GetParam('name', _POST, _STRING);
516 $duration = Kit::GetParam('duration', _POST, _INT, 0);516 $duration = Kit::GetParam('duration', _POST, _INT, 0);
517 $permissionid = Kit::GetParam('permissionid', _POST, _INT, 1);517 $permissionid = Kit::GetParam('permissionid', _POST, _INT, 1);
518 518
519 if ($name == '') $name = Kit::ValidateParam($fileName, _FILENAME);519 if ($name == '') $name = Kit::ValidateParam($fileName, _FILENAME);
520 520
521 // Validation521 // Validation
522 if ($ext != "wmv" && $ext != "mpeg" && $ext != "mpg")522 if ($ext != "wmv" && $ext != "mpeg" && $ext != "mpg")
523 {523 {
@@ -525,25 +525,25 @@
525 $this->response->keepOpen = true;525 $this->response->keepOpen = true;
526 return $this->response;526 return $this->response;
527 }527 }
528 528
529 // Make sure the name isnt too long529 // Make sure the name isnt too long
530 if (strlen($name) > 100) 530 if (strlen($name) > 100)
531 {531 {
532 $this->response->SetError('The name cannot be longer than 100 characters');532 $this->response->SetError('The name cannot be longer than 100 characters');
533 $this->response->keepOpen = true;533 $this->response->keepOpen = true;
534 return $this->response;534 return $this->response;
535 }535 }
536 536
537 // Ensure the name is not already in the database537 // Ensure the name is not already in the database
538 $SQL = sprintf("SELECT name FROM media WHERE name = '%s' AND userid = %d", $db->escape_string($name), $userid);538 $SQL = sprintf("SELECT name FROM media WHERE name = '%s' AND userid = %d", $db->escape_string($name), $userid);
539539
540 if(!$result = $db->query($SQL)) 540 if(!$result = $db->query($SQL))
541 {541 {
542 trigger_error($db->error());542 trigger_error($db->error());
543 $this->response->SetError('Error checking whether the media name is ok. Try choosing a different name.');543 $this->response->SetError('Error checking whether the media name is ok. Try choosing a different name.');
544 $this->response->keepOpen = true;544 $this->response->keepOpen = true;
545 return $this->response;545 return $this->response;
546 } 546 }
547547
548 if ($db->num_rows($result) != 0)548 if ($db->num_rows($result) != 0)
549 {549 {
@@ -551,11 +551,11 @@
551 $this->response->keepOpen = true;551 $this->response->keepOpen = true;
552 return $this->response;552 return $this->response;
553 }553 }
554 554
555 // All OK to insert this record555 // All OK to insert this record
556 $SQL = "INSERT INTO media (name, type, duration, originalFilename, permissionID, userID, retired ) ";556 $SQL = "INSERT INTO media (name, type, duration, originalFilename, permissionID, userID, retired ) ";
557 $SQL .= "VALUES ('%s', 'video', '%s', '%s', %d, %d, 0) ";557 $SQL .= "VALUES ('%s', 'video', '%s', '%s', %d, %d, 0) ";
558 558
559 $SQL = sprintf($SQL, $db->escape_string($name), $db->escape_string($duration), $db->escape_string($fileName), $permissionid, $userid);559 $SQL = sprintf($SQL, $db->escape_string($name), $db->escape_string($duration), $db->escape_string($fileName), $permissionid, $userid);
560560
561 if (!$mediaid = $db->insert_query($SQL))561 if (!$mediaid = $db->insert_query($SQL))
@@ -565,19 +565,19 @@
565 $this->response->keepOpen = true;565 $this->response->keepOpen = true;
566 return $this->response;566 return $this->response;
567 }567 }
568 568
569 // File upload directory.. get this from the settings object569 // File upload directory.. get this from the settings object
570 $databaseDir = Config::GetSetting($db, "LIBRARY_LOCATION");570 $databaseDir = Config::GetSetting($db, "LIBRARY_LOCATION");
571 571
572 // What are we going to store this media as...572 // What are we going to store this media as...
573 $storedAs = $mediaid.".".$ext;573 $storedAs = $mediaid.".".$ext;
574 574
575 // Now we need to move the file575 // Now we need to move the file
576 if (!$result = rename($databaseDir."temp/".$tmpName, $databaseDir.$storedAs))576 if (!$result = rename($databaseDir."temp/".$tmpName, $databaseDir.$storedAs))
577 {577 {
578 // If we couldnt move it - we need to delete the media record we just added578 // If we couldnt move it - we need to delete the media record we just added
579 $SQL = sprintf("DELETE FROM media WHERE mediaID = %d ", $mediaid);579 $SQL = sprintf("DELETE FROM media WHERE mediaID = %d ", $mediaid);
580 580
581 if (!$db->query($SQL))581 if (!$db->query($SQL))
582 {582 {
583 trigger_error($db->error());583 trigger_error($db->error());
@@ -586,23 +586,27 @@
586 return $this->response;586 return $this->response;
587 }587 }
588 }588 }
589 589
590 // Calculate the MD5 and the file size
591 $md5 = md5_file($databaseDir.$storedAs);
592 $fileSize = filesize($databaseDir.$storedAs);
593
590 // Update the media record to include this information594 // Update the media record to include this information
591 $SQL = sprintf("UPDATE media SET storedAs = '%s' WHERE mediaid = %d", $storedAs, $mediaid);595 $SQL = sprintf("UPDATE media SET storedAs = '%s', `MD5` = '%s', FileSize = %d WHERE mediaid = %d", $storedAs, $md5, $fileSize, $mediaid);
592 596
593 if (!$db->query($SQL))597 if (!$db->query($SQL))
594 {598 {
595 trigger_error($db->error());599 trigger_error($db->error());
596 return true;600 return true;
597 }601 }
598 602
599 // Required Attributes603 // Required Attributes
600 $this->mediaid = $mediaid;604 $this->mediaid = $mediaid;
601 $this->duration = $duration;605 $this->duration = $duration;
602 606
603 // Any Options607 // Any Options
604 $this->SetOption('uri', $storedAs);608 $this->SetOption('uri', $storedAs);
605 609
606 // Should have built the media object entirely by this time610 // Should have built the media object entirely by this time
607 if ($regionid != '')611 if ($regionid != '')
608 {612 {
@@ -612,18 +616,18 @@
612 }616 }
613 else617 else
614 {618 {
615 $this->response->loadFormUri = "index.php?p=content&q=displayForms&sp=add"; 619 $this->response->loadFormUri = "index.php?p=content&q=displayForms&sp=add";
616 }620 }
617 621
618 // We want to load a new form622 // We want to load a new form
619 $this->response->loadForm = true;623 $this->response->loadForm = true;
620 624
621 return $this->response;625 return $this->response;
622 }626 }
623 627
624 /**628 /**
625 * Edit Media in the Database629 * Edit Media in the Database
626 * @return 630 * @return
627 */631 */
628 public function EditMedia()632 public function EditMedia()
629 {633 {
@@ -632,13 +636,13 @@
632 $regionid = $this->regionid;636 $regionid = $this->regionid;
633 $mediaid = $this->mediaid;637 $mediaid = $this->mediaid;
634 $userid = Kit::GetParam('userid', _SESSION, _INT);638 $userid = Kit::GetParam('userid', _SESSION, _INT);
635 639
636 // Stored As from the XML640 // Stored As from the XML
637 $storedAs = $this->GetOption('uri');641 $storedAs = $this->GetOption('uri');
638 642
639 // File data643 // File data
640 $tmpName = Kit::GetParam('hidFileID', _POST, _STRING);644 $tmpName = Kit::GetParam('hidFileID', _POST, _STRING);
641 645
642 if ($tmpName == '')646 if ($tmpName == '')
643 {647 {
644 $fileRevision = false;648 $fileRevision = false;
@@ -646,12 +650,12 @@
646 else650 else
647 {651 {
648 $fileRevision = true;652 $fileRevision = true;
649 653
650 // File name and extension (orignial name)654 // File name and extension (orignial name)
651 $fileName = Kit::GetParam('txtFileName', _POST, _STRING);655 $fileName = Kit::GetParam('txtFileName', _POST, _STRING);
652 $fileName = basename($fileName);656 $fileName = basename($fileName);
653 $ext = strtolower(substr(strrchr($fileName, "."), 1));657 $ext = strtolower(substr(strrchr($fileName, "."), 1));
654 658
655 // Validation659 // Validation
656 if ($ext != "wmv" && $ext != "mpeg" && $ext != "mpg")660 if ($ext != "wmv" && $ext != "mpeg" && $ext != "mpg")
657 {661 {
@@ -660,17 +664,17 @@
660 return $this->response;664 return $this->response;
661 }665 }
662 }666 }
663 667
664 // Other properties668 // Other properties
665 $name = Kit::GetParam('name', _POST, _STRING);669 $name = Kit::GetParam('name', _POST, _STRING);
666 $duration = Kit::GetParam('duration', _POST, _INT, 0);670 $duration = Kit::GetParam('duration', _POST, _INT, 0);
667 $permissionid = Kit::GetParam('permissionid', _POST, _INT, 1);671 $permissionid = Kit::GetParam('permissionid', _POST, _INT, 1);
668 672
669 if ($name == '')673 if ($name == '')
670 {674 {
671 if ($fileRevision)675 if ($fileRevision)
672 {676 {
673 $name = Kit::ValidateParam($fileName, _FILENAME); 677 $name = Kit::ValidateParam($fileName, _FILENAME);
674 }678 }
675 else679 else
676 {680 {
@@ -678,26 +682,26 @@
678 $this->response->keepOpen = true;682 $this->response->keepOpen = true;
679 return $this->response;683 return $this->response;
680 }684 }
681 } 685 }
682 686
683 // Make sure the name isnt too long687 // Make sure the name isnt too long
684 if (strlen($name) > 100) 688 if (strlen($name) > 100)
685 {689 {
686 $this->response->SetError('The name cannot be longer than 100 characters');690 $this->response->SetError('The name cannot be longer than 100 characters');
687 $this->response->keepOpen = true;691 $this->response->keepOpen = true;
688 return $this->response;692 return $this->response;
689 }693 }
690 694
691 // Ensure the name is not already in the database695 // Ensure the name is not already in the database
692 $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 ", $db->escape_string($name), $userid, $mediaid);
693697
694 if(!$result = $db->query($SQL)) 698 if(!$result = $db->query($SQL))
695 {699 {
696 trigger_error($db->error());700 trigger_error($db->error());
697 $this->response->SetError('Error checking whether the media name is ok. Try choosing a different name.');701 $this->response->SetError('Error checking whether the media name is ok. Try choosing a different name.');
698 $this->response->keepOpen = true;702 $this->response->keepOpen = true;
699 return $this->response;703 return $this->response;
700 } 704 }
701705
702 if ($db->num_rows($result) != 0)706 if ($db->num_rows($result) != 0)
703 {707 {
@@ -705,34 +709,34 @@
705 $this->response->keepOpen = true;709 $this->response->keepOpen = true;
706 return $this->response;710 return $this->response;
707 }711 }
708 712
709 //Are we revising this media - or just plain editing713 //Are we revising this media - or just plain editing
710 if ($fileRevision)714 if ($fileRevision)
711 {715 {
712 // All OK to insert this record716 // All OK to insert this record
713 $SQL = "INSERT INTO media (name, type, duration, originalFilename, permissionID, userID, retired ) ";717 $SQL = "INSERT INTO media (name, type, duration, originalFilename, permissionID, userID, retired ) ";
714 $SQL .= "VALUES ('%s', '%s', '%s', '%s', %d, %d, 0) ";718 $SQL .= "VALUES ('%s', '%s', '%s', '%s', %d, %d, 0) ";
715 719
716 $SQL = sprintf($SQL, $db->escape_string($name), $this->type, $db->escape_string($duration), $db->escape_string($fileName), $permissionid, $userid);720 $SQL = sprintf($SQL, $db->escape_string($name), $this->type, $db->escape_string($duration), $db->escape_string($fileName), $permissionid, $userid);
717 721
718 if (!$new_mediaid = $db->insert_query($SQL))722 if (!$new_mediaid = $db->insert_query($SQL))
719 {723 {
720 trigger_error($db->error());724 trigger_error($db->error());
721 trigger_error('Error inserting replacement media record.', E_USER_ERROR);725 trigger_error('Error inserting replacement media record.', E_USER_ERROR);
722 }726 }
723 727
724 //What are we going to store this media as...728 //What are we going to store this media as...
725 $storedAs = $new_mediaid.".".$ext;729 $storedAs = $new_mediaid.".".$ext;
726 730
727 // File upload directory.. get this from the settings object731 // File upload directory.. get this from the settings object
728 $databaseDir = Config::GetSetting($db, "LIBRARY_LOCATION");732 $databaseDir = Config::GetSetting($db, "LIBRARY_LOCATION");
729 733
730 //Now we need to move the file734 //Now we need to move the file
731 if (!$result = rename($databaseDir."/temp/".$tmpName, $databaseDir.$storedAs))735 if (!$result = rename($databaseDir."/temp/".$tmpName, $databaseDir.$storedAs))
732 {736 {
733 //If we couldnt move it - we need to delete the media record we just added737 //If we couldnt move it - we need to delete the media record we just added
734 $SQL = "DELETE FROM media WHERE mediaID = $new_mediaid ";738 $SQL = "DELETE FROM media WHERE mediaID = $new_mediaid ";
735 739
736 if (!$db->insert_query($SQL))740 if (!$db->insert_query($SQL))
737 {741 {
738 $this->response->SetError('Error rolling back transcation.');742 $this->response->SetError('Error rolling back transcation.');
@@ -740,23 +744,28 @@
740 return $this->response;744 return $this->response;
741 }745 }
742 }746 }
743 747
748 // Calculate the MD5 and the file size
749 $md5 = md5_file($databaseDir.$storedAs);
750 $fileSize = filesize($databaseDir.$storedAs);
751
744 // Update the media record to include this information752 // Update the media record to include this information
745 $SQL = "UPDATE media SET storedAs = '$storedAs' WHERE mediaid = $new_mediaid";753 $SQL = sprintf("UPDATE media SET storedAs = '%s', `MD5` = '%s', FileSize = %d WHERE mediaid = %d", $storedAs, $md5, $fileSize, $new_mediaid);
754
746 if (!$db->query($SQL))755 if (!$db->query($SQL))
747 {756 {
748 trigger_error($db->error());757 trigger_error($db->error());
749 $this->response->SetError('Error updating media with Library location.');758 $this->response->SetError('Database error editing this media record.');
750 $this->response->keepOpen = true;759 $this->response->keepOpen = true;
751 return $this->response;760 return $this->response;
752 }761 }
753 762
754 // Update the existing record with the new record's id763 // Update the existing record with the new record's id
755 $SQL = "UPDATE media SET isEdited = 1, editedMediaID = $new_mediaid ";764 $SQL = "UPDATE media SET isEdited = 1, editedMediaID = $new_mediaid ";
756 $SQL .= " WHERE IFNULL(editedMediaID,0) <> $new_mediaid AND mediaID = $mediaid ";765 $SQL .= " WHERE IFNULL(editedMediaID,0) <> $new_mediaid AND mediaID = $mediaid ";
757 766
758 Debug::LogEntry($db, 'audit', $SQL);767 Debug::LogEntry($db, 'audit', $SQL);
759 768
760 if (!$db->query($SQL))769 if (!$db->query($SQL))
761 {770 {
762 trigger_error($db->error());771 trigger_error($db->error());
@@ -770,54 +779,54 @@
770 {779 {
771 // Editing the existing record780 // Editing the existing record
772 $new_mediaid = $mediaid;781 $new_mediaid = $mediaid;
773 782
774 $SQL = "UPDATE media SET name = '%s', duration = %d, permissionID = %d";783 $SQL = "UPDATE media SET name = '%s', duration = %d, permissionID = %d";
775 $SQL .= " WHERE mediaID = %d ";784 $SQL .= " WHERE mediaID = %d ";
776 $SQL = sprintf($SQL, $db->escape_string($name), $duration, $permissionid, $mediaid);785 $SQL = sprintf($SQL, $db->escape_string($name), $duration, $permissionid, $mediaid);
777 786
778 Debug::LogEntry($db, 'audit', $SQL);787 Debug::LogEntry($db, 'audit', $SQL);
779 788
780 if (!$db->query($SQL))789 if (!$db->query($SQL))
781 {790 {
782 trigger_error($db->error());791 trigger_error($db->error());
783 792
784 $this->response->SetError('Database error editing this media record.');793 $this->response->SetError('Database error editing this media record.');
785 $this->response->keepOpen = true;794 $this->response->keepOpen = true;
786 return $this->response;795 return $this->response;
787 }796 }
788 }797 }
789 798
790 // Required Attributes799 // Required Attributes
791 $this->mediaid = $new_mediaid;800 $this->mediaid = $new_mediaid;
792 $this->duration = $duration;801 $this->duration = $duration;
793 802
794 // Any Options803 // Any Options
795 $this->SetOption('uri', $storedAs);804 $this->SetOption('uri', $storedAs);
796 805
797 // Should have built the media object entirely by this time806 // Should have built the media object entirely by this time
798 if ($regionid != '')807 if ($regionid != '')
799 {808 {
800 // This saves the Media Object to the Region809 // This saves the Media Object to the Region
801 $this->UpdateRegion();810 $this->UpdateRegion();
802 811
803 $this->response->loadForm = true;812 $this->response->loadForm = true;
804 $this->response->loadFormUri = "index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions";;813 $this->response->loadFormUri = "index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions";;
805 }814 }
806 else815 else
807 {816 {
808 $this->response->loadFormUri = "index.php?p=content&q=displayForms&sp=add"; 817 $this->response->loadFormUri = "index.php?p=content&q=displayForms&sp=add";
809 $this->response->message = 'Edited the Video.';818 $this->response->message = 'Edited the Video.';
810 819
811 }820 }
812 821
813 return $this->response;822 return $this->response;
814 }823 }
815 824
816 /**825 /**
817 * Delete Media from the Database826 * Delete Media from the Database
818 * @return 827 * @return
819 */828 */
820 public function DeleteMedia() 829 public function DeleteMedia()
821 {830 {
822 $db =& $this->db;831 $db =& $this->db;
823 $layoutid = $this->layoutid;832 $layoutid = $this->layoutid;
@@ -825,10 +834,10 @@
825 $mediaid = $this->mediaid;834 $mediaid = $this->mediaid;
826 $userid = Kit::GetParam('userid', _SESSION, _INT);835 $userid = Kit::GetParam('userid', _SESSION, _INT);
827 $options = Kit::GetParam('options', _POST, _WORD);836 $options = Kit::GetParam('options', _POST, _WORD);
828 837
829 // Stored As from the XML838 // Stored As from the XML
830 $this->uri = $this->GetOption('uri');839 $this->uri = $this->GetOption('uri');
831 840
832 // Do we need to remove this from a layout?841 // Do we need to remove this from a layout?
833 if ($layoutid != '')842 if ($layoutid != '')
834 {843 {
@@ -840,72 +849,72 @@
840 // Set this message now in preparation849 // Set this message now in preparation
841 $this->response->message = 'Deleted the Media.';850 $this->response->message = 'Deleted the Media.';
842 }851 }
843 852
844 // If we are set to retire we retire853 // If we are set to retire we retire
845 if ($options == "retire")854 if ($options == "retire")
846 {855 {
847 //Update the media record to say it is retired856 //Update the media record to say it is retired
848 $SQL = "UPDATE media SET retired = 1 WHERE mediaid = $mediaid ";857 $SQL = "UPDATE media SET retired = 1 WHERE mediaid = $mediaid ";
849 858
850 if (!$db->query($SQL))859 if (!$db->query($SQL))
851 {860 {
852 trigger_error($db->error());861 trigger_error($db->error());
853 862
854 $this->response->SetError('Database error retiring this media record.');863 $this->response->SetError('Database error retiring this media record.');
855 $this->response->keepOpen = true;864 $this->response->keepOpen = true;
856 return $this->response;865 return $this->response;
857 }866 }
858 }867 }
859 868
860 //If we are set to delete, we delete869 //If we are set to delete, we delete
861 if ($options == "delete")870 if ($options == "delete")
862 {871 {
863 //Update the media record to say it is retired872 //Update the media record to say it is retired
864 $SQL = "DELETE FROM media WHERE mediaid = $mediaid ";873 $SQL = "DELETE FROM media WHERE mediaid = $mediaid ";
865 874
866 if (!$db->query($SQL))875 if (!$db->query($SQL))
867 {876 {
868 trigger_error($db->error());877 trigger_error($db->error());
869 878
870 $this->response->SetError('Database error deleting this media record.');879 $this->response->SetError('Database error deleting this media record.');
871 $this->response->keepOpen = true;880 $this->response->keepOpen = true;
872 return $this->response;881 return $this->response;
873 }882 }
874 883
875 $this->DeleteMediaFiles();884 $this->DeleteMediaFiles();
876 }885 }
877 886
878 return $this->response;887 return $this->response;
879 }888 }
880 889
881 /**890 /**
882 * Deletes the media files associated with this record891 * Deletes the media files associated with this record
883 * @return 892 * @return
884 */893 */
885 private function DeleteMediaFiles()894 private function DeleteMediaFiles()
886 {895 {
887 $db =& $this->db;896 $db =& $this->db;
888 897
889 //Library location898 //Library location
890 $databaseDir = Config::GetSetting($db, "LIBRARY_LOCATION");899 $databaseDir = Config::GetSetting($db, "LIBRARY_LOCATION");
891 900
892 //3 things to check for..901 //3 things to check for..
893 //the actual file, the thumbnail, the background902 //the actual file, the thumbnail, the background
894 if (file_exists($databaseDir.$this->uri))903 if (file_exists($databaseDir.$this->uri))
895 {904 {
896 unlink($databaseDir.$this->uri);905 unlink($databaseDir.$this->uri);
897 }906 }
898 907
899 if (file_exists($databaseDir."tn_".$this->uri))908 if (file_exists($databaseDir."tn_".$this->uri))
900 {909 {
901 unlink($databaseDir."tn_".$this->uri);910 unlink($databaseDir."tn_".$this->uri);
902 }911 }
903 912
904 if (file_exists($databaseDir."bg_".$this->uri))913 if (file_exists($databaseDir."bg_".$this->uri))
905 {914 {
906 unlink($databaseDir."bg_".$this->uri);915 unlink($databaseDir."bg_".$this->uri);
907 }916 }
908 917
909 return true;918 return true;
910 }919 }
911}920}
912921
=== modified file 'server/xmds.php'
--- server/xmds.php 2009-08-08 11:04:39 +0000
+++ server/xmds.php 2009-09-29 22:15:24 +0000
@@ -8,7 +8,7 @@
8 * Xibo is free software: you can redistribute it and/or modify8 * 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 by9 * 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, or10 * the Free Software Foundation, either version 3 of the License, or
11 * any later version. 11 * any later version.
12 *12 *
13 * Xibo is distributed in the hope that it will be useful,13 * Xibo is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -29,71 +29,71 @@
29function Auth($hardwareKey)29function Auth($hardwareKey)
30{30{
31 global $db;31 global $db;
32 32
33 //check in the database for this hardwareKey33 //check in the database for this hardwareKey
34 $SQL = "SELECT licensed, inc_schedule, isAuditing, displayID FROM display WHERE license = '$hardwareKey'";34 $SQL = "SELECT licensed, inc_schedule, isAuditing, displayID FROM display WHERE license = '$hardwareKey'";
35 if (!$result = $db->query($SQL)) 35 if (!$result = $db->query($SQL))
36 {36 {
37 trigger_error("License key query failed:" .$db->error());37 trigger_error("License key query failed:" .$db->error());
38 return false;38 return false;
39 }39 }
40 40
41 //Is it there?41 //Is it there?
42 if ($db->num_rows($result) == 0) 42 if ($db->num_rows($result) == 0)
43 {43 {
44 return false;44 return false;
45 }45 }
46 else 46 else
47 {47 {
48 //we have seen this display before, so check the licensed value48 //we have seen this display before, so check the licensed value
49 $row = $db->get_row($result);49 $row = $db->get_row($result);
50 if ($row[0] == 0) 50 if ($row[0] == 0)
51 {51 {
52 return false;52 return false;
53 }53 }
54 else 54 else
55 {55 {
56 $time = date("Y-m-d H:i:s", time());56 $time = date("Y-m-d H:i:s", time());
57 57
58 //Set the last accessed flag on the display58 //Set the last accessed flag on the display
59 $SQL = "UPDATE display SET lastaccessed = '$time', loggedin = 1 WHERE license = '$hardwareKey' ";59 $SQL = "UPDATE display SET lastaccessed = '$time', loggedin = 1 WHERE license = '$hardwareKey' ";
60 if (!$result = $db->query($SQL)) 60 if (!$result = $db->query($SQL))
61 {61 {
62 trigger_error("Display update access failure: " .$db->error());62 trigger_error("Display update access failure: " .$db->error());
63 }63 }
64 64
65 //It is licensed65 //It is licensed
66 return array("licensed" => true, "inc_schedule" => $row[1], "isAuditing" => $row[2], "displayid" => $row[3]);66 return array("licensed" => true, "inc_schedule" => $row[1], "isAuditing" => $row[2], "displayid" => $row[3]);
67 }67 }
68 }68 }
69 69
70 return false;70 return false;
71}71}
7272
73/**73/**
74 * Checks that the calling service is talking the correct version74 * Checks that the calling service is talking the correct version
75 * @return 75 * @return
76 * @param $version Object76 * @param $version Object
77 */77 */
78function CheckVersion($version)78function CheckVersion($version)
79{79{
80 global $db;80 global $db;
81 81
82 // Look up the Service XMDS version from the Version table82 // Look up the Service XMDS version from the Version table
83 $serverVersion = Config::Version($db, 'XmdsVersion');83 $serverVersion = Config::Version($db, 'XmdsVersion');
84 84
85 if ($version != $serverVersion)85 if ($version != $serverVersion)
86 {86 {
87 Debug::LogEntry($db, 'audit', sprintf('A Client with an incorrect version connected. Client Version: [%s] Server Version [%s]', $version, $serverVersion));87 Debug::LogEntry($db, 'audit', sprintf('A Client with an incorrect version connected. Client Version: [%s] Server Version [%s]', $version, $serverVersion));
88 return false;88 return false;
89 }89 }
90 90
91 return true;91 return true;
92}92}
9393
94/**94/**
95 * Registers the Display with the server - if there is an available slot95 * Registers the Display with the server - if there is an available slot
96 * @return 96 * @return
97 * @param $serverKey Object97 * @param $serverKey Object
98 * @param $hardwareKey Object98 * @param $hardwareKey Object
99 * @param $displayName Object99 * @param $displayName Object
@@ -101,66 +101,66 @@
101function RegisterDisplay($serverKey, $hardwareKey, $displayName, $version)101function RegisterDisplay($serverKey, $hardwareKey, $displayName, $version)
102{102{
103 global $db;103 global $db;
104 104
105 // Sanitize105 // Sanitize
106 $serverKey = Kit::ValidateParam($serverKey, _STRING);106 $serverKey = Kit::ValidateParam($serverKey, _STRING);
107 $hardwareKey = Kit::ValidateParam($hardwareKey, _STRING);107 $hardwareKey = Kit::ValidateParam($hardwareKey, _STRING);
108 $displayName = Kit::ValidateParam($displayName, _STRING);108 $displayName = Kit::ValidateParam($displayName, _STRING);
109 $version = Kit::ValidateParam($version, _STRING);109 $version = Kit::ValidateParam($version, _STRING);
110 110
111 // Make sure we are talking the same language111 // Make sure we are talking the same language
112 if (!CheckVersion($version))112 if (!CheckVersion($version))
113 {113 {
114 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);114 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);
115 }115 }
116 116
117 define('SERVER_KEY', Config::GetSetting($db, 'SERVER_KEY'));117 define('SERVER_KEY', Config::GetSetting($db, 'SERVER_KEY'));
118 118
119 Debug::LogEntry($db, "audit", "[IN]", "xmds", "RegisterDisplay");119 Debug::LogEntry($db, "audit", "[IN]", "xmds", "RegisterDisplay");
120 Debug::LogEntry($db, "audit", "serverKey [$serverKey], hardwareKey [$hardwareKey], displayName [$displayName]", "xmds", "RegisterDisplay");120 Debug::LogEntry($db, "audit", "serverKey [$serverKey], hardwareKey [$hardwareKey], displayName [$displayName]", "xmds", "RegisterDisplay");
121 121
122 //Check the serverKey matches the one we have stored in this servers lic.txt file122 //Check the serverKey matches the one we have stored in this servers lic.txt file
123 if ($serverKey != SERVER_KEY)123 if ($serverKey != SERVER_KEY)
124 {124 {
125 return new soap_fault("SOAP-ENV:Client", "", "The Server key you entered does not match with the server key at this address", $serverKey);125 return new soap_fault("SOAP-ENV:Client", "", "The Server key you entered does not match with the server key at this address", $serverKey);
126 }126 }
127 127
128 // Check the Length of the hardwareKey128 // Check the Length of the hardwareKey
129 if (strlen($hardwareKey) > 40)129 if (strlen($hardwareKey) > 40)
130 {130 {
131 return new soap_fault("SOAP-ENV:Client", "", "The Hardware Key you sent was too long. Only 40 characters are allowed (SHA1).", $hardwareKey);131 return new soap_fault("SOAP-ENV:Client", "", "The Hardware Key you sent was too long. Only 40 characters are allowed (SHA1).", $hardwareKey);
132 }132 }
133 133
134 //check in the database for this hardwareKey134 //check in the database for this hardwareKey
135 $SQL = "SELECT licensed, display FROM display WHERE license = '$hardwareKey'";135 $SQL = "SELECT licensed, display FROM display WHERE license = '$hardwareKey'";
136 if (!$result = $db->query($SQL)) 136 if (!$result = $db->query($SQL))
137 {137 {
138 trigger_error("License key query failed:" .$db->error());138 trigger_error("License key query failed:" .$db->error());
139 return new soap_fault("SOAP-ENV:Server", "", "License Key Query Failed, see server errorlog", $db->error());139 return new soap_fault("SOAP-ENV:Server", "", "License Key Query Failed, see server errorlog", $db->error());
140 }140 }
141 141
142 //Is it there?142 //Is it there?
143 if ($db->num_rows($result) == 0) 143 if ($db->num_rows($result) == 0)
144 {144 {
145 //Add this display record145 //Add this display record
146 $SQL = sprintf("INSERT INTO display (display, defaultlayoutid, license, licensed) VALUES ('%s', 1, '%s', 0)", $displayName, $hardwareKey);146 $SQL = sprintf("INSERT INTO display (display, defaultlayoutid, license, licensed) VALUES ('%s', 1, '%s', 0)", $displayName, $hardwareKey);
147 if (!$displayid = $db->insert_query($SQL)) 147 if (!$displayid = $db->insert_query($SQL))
148 {148 {
149 trigger_error($db->error());149 trigger_error($db->error());
150 return new soap_fault("SOAP-ENV:Server", "", "Error adding display");150 return new soap_fault("SOAP-ENV:Server", "", "Error adding display");
151 }151 }
152 $active = "Display added and is awaiting licensing approval from an Administrator";152 $active = "Display added and is awaiting licensing approval from an Administrator";
153 }153 }
154 else 154 else
155 {155 {
156 //we have seen this display before, so check the licensed value156 //we have seen this display before, so check the licensed value
157 $row = $db->get_row($result);157 $row = $db->get_row($result);
158 if ($row[0] == 0) 158 if ($row[0] == 0)
159 {159 {
160 //Its Not licensed160 //Its Not licensed
161 $active = "Display is awaiting licensing approval from an Administrator.";161 $active = "Display is awaiting licensing approval from an Administrator.";
162 }162 }
163 else 163 else
164 {164 {
165 //It is licensed165 //It is licensed
166 //Now check the names166 //Now check the names
@@ -172,21 +172,21 @@
172 {172 {
173 //Update the name173 //Update the name
174 $SQL = sprintf("UPDATE display SET display = '%s' WHERE license = '%s' ", $displayName, $hardwareKey);174 $SQL = sprintf("UPDATE display SET display = '%s' WHERE license = '%s' ", $displayName, $hardwareKey);
175 175
176 if (!$db->query($SQL)) 176 if (!$db->query($SQL))
177 {177 {
178 trigger_error($db->error());178 trigger_error($db->error());
179 return new soap_fault("SOAP-ENV:Server", "", "Error editing the display name");179 return new soap_fault("SOAP-ENV:Server", "", "Error editing the display name");
180 }180 }
181 181
182 $active = "Changed display name from '{$row[1]}' to '$displayName' Display is active and ready to start.";182 $active = "Changed display name from '{$row[1]}' to '$displayName' Display is active and ready to start.";
183 }183 }
184 }184 }
185 }185 }
186 186
187 Debug::LogEntry($db, "audit", "$active", "xmds", "RegisterDisplay"); 187 Debug::LogEntry($db, "audit", "$active", "xmds", "RegisterDisplay");
188 Debug::LogEntry($db, "audit", "[OUT]", "xmds", "RegisterDisplay"); 188 Debug::LogEntry($db, "audit", "[OUT]", "xmds", "RegisterDisplay");
189 189
190 return $active;190 return $active;
191}191}
192192
@@ -198,12 +198,12 @@
198function RequiredFiles($serverKey, $hardwareKey, $version)198function RequiredFiles($serverKey, $hardwareKey, $version)
199{199{
200 global $db;200 global $db;
201 201
202 // Sanitize202 // Sanitize
203 $serverKey = Kit::ValidateParam($serverKey, _STRING);203 $serverKey = Kit::ValidateParam($serverKey, _STRING);
204 $hardwareKey = Kit::ValidateParam($hardwareKey, _STRING);204 $hardwareKey = Kit::ValidateParam($hardwareKey, _STRING);
205 $version = Kit::ValidateParam($version, _STRING);205 $version = Kit::ValidateParam($version, _STRING);
206 206
207 // Make sure we are talking the same language207 // Make sure we are talking the same language
208 if (!CheckVersion($version))208 if (!CheckVersion($version))
209 {209 {
@@ -211,29 +211,29 @@
211 }211 }
212212
213 $libraryLocation = Config::GetSetting($db, "LIBRARY_LOCATION");213 $libraryLocation = Config::GetSetting($db, "LIBRARY_LOCATION");
214 214
215 //auth this request...215 //auth this request...
216 if (!$displayInfo = Auth($hardwareKey))216 if (!$displayInfo = Auth($hardwareKey))
217 {217 {
218 trigger_error("This display is not licensed [$hardwareKey]");218 trigger_error("This display is not licensed [$hardwareKey]");
219 return new soap_fault("SOAP-ENV:Client", "", "This display client is not licensed");219 return new soap_fault("SOAP-ENV:Client", "", "This display client is not licensed");
220 }220 }
221 221
222 if ($displayInfo['isAuditing'] == 1) 222 if ($displayInfo['isAuditing'] == 1)
223 {223 {
224 Debug::LogEntry($db, "audit", "[IN]", "xmds", "RequiredFiles"); 224 Debug::LogEntry($db, "audit", "[IN]", "xmds", "RequiredFiles");
225 Debug::LogEntry($db, "audit", "$hardwareKey", "xmds", "RequiredFiles"); 225 Debug::LogEntry($db, "audit", "$hardwareKey", "xmds", "RequiredFiles");
226 }226 }
227 227
228 $requiredFilesXml = new DOMDocument("1.0");228 $requiredFilesXml = new DOMDocument("1.0");
229 $fileElements = $requiredFilesXml->createElement("files");229 $fileElements = $requiredFilesXml->createElement("files");
230 230
231 $requiredFilesXml->appendChild($fileElements);231 $requiredFilesXml->appendChild($fileElements);
232 232
233 $currentdate = date("Y-m-d H:i:s");233 $currentdate = date("Y-m-d H:i:s");
234 $time = time();234 $time = time();
235 $plus4hours = date("Y-m-d H:i:s",$time + 86400);235 $plus4hours = date("Y-m-d H:i:s",$time + 86400);
236 236
237 //Add file nodes to the $fileElements237 //Add file nodes to the $fileElements
238 //Firstly get all the scheduled layouts238 //Firstly get all the scheduled layouts
239 $SQL = " SELECT layout.layoutID, schedule_detail.starttime, schedule_detail.endtime, layout.xml, layout.background ";239 $SQL = " SELECT layout.layoutID, schedule_detail.starttime, schedule_detail.endtime, layout.xml, layout.background ";
@@ -241,9 +241,9 @@
241 $SQL .= " INNER JOIN schedule_detail ON schedule_detail.layoutID = layout.layoutID ";241 $SQL .= " INNER JOIN schedule_detail ON schedule_detail.layoutID = layout.layoutID ";
242 $SQL .= " INNER JOIN display ON schedule_detail.displayID = display.displayID ";242 $SQL .= " INNER JOIN display ON schedule_detail.displayID = display.displayID ";
243 $SQL .= sprintf(" WHERE display.license = '%s' ", $hardwareKey);243 $SQL .= sprintf(" WHERE display.license = '%s' ", $hardwareKey);
244 244
245 $SQLBase = $SQL;245 $SQLBase = $SQL;
246 246
247 //Do we include the default display247 //Do we include the default display
248 if ($displayInfo['inc_schedule'] == 1)248 if ($displayInfo['inc_schedule'] == 1)
249 {249 {
@@ -254,15 +254,15 @@
254 {254 {
255 $SQL .= sprintf(" AND (schedule_detail.starttime < '%s' AND schedule_detail.endtime > '%s' )", $plus4hours, $currentdate);255 $SQL .= sprintf(" AND (schedule_detail.starttime < '%s' AND schedule_detail.endtime > '%s' )", $plus4hours, $currentdate);
256 }256 }
257 257
258 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry($db, "audit", "$SQL", "xmds", "RequiredFiles"); 258 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry($db, "audit", "$SQL", "xmds", "RequiredFiles");
259259
260 if (!$results = $db->query($SQL))260 if (!$results = $db->query($SQL))
261 {261 {
262 trigger_error($db->error());262 trigger_error($db->error());
263 return new soap_fault("SOAP-ENV:Server", "", "Unable to get a list of files", $db->error());263 return new soap_fault("SOAP-ENV:Server", "", "Unable to get a list of files", $db->error());
264 }264 }
265 265
266 // Was there anything?266 // Was there anything?
267 if ($db->num_rows($results) == 0)267 if ($db->num_rows($results) == 0)
268 {268 {
@@ -270,119 +270,138 @@
270 $SQL = $SQLBase;270 $SQL = $SQLBase;
271 $SQL .= sprintf(" AND ((schedule_detail.starttime < '%s' AND schedule_detail.endtime > '%s' )", $plus4hours, $currentdate);271 $SQL .= sprintf(" AND ((schedule_detail.starttime < '%s' AND schedule_detail.endtime > '%s' )", $plus4hours, $currentdate);
272 $SQL .= " OR (schedule_detail.starttime = '2050-12-31 00:00:00' AND schedule_detail.endtime = '2050-12-31 00:00:00' ))";272 $SQL .= " OR (schedule_detail.starttime = '2050-12-31 00:00:00' AND schedule_detail.endtime = '2050-12-31 00:00:00' ))";
273 273
274 if (!$results = $db->query($SQL))274 if (!$results = $db->query($SQL))
275 {275 {
276 trigger_error($db->error());276 trigger_error($db->error());
277 return new soap_fault("SOAP-ENV:Server", "", "Unable to get A list of layouts for the schedule", $db->error());277 return new soap_fault("SOAP-ENV:Server", "", "Unable to get A list of layouts for the schedule", $db->error());
278 }278 }
279 }279 }
280 280
281 while ($row = $db->get_row($results))281 while ($row = $db->get_row($results))
282 {282 {
283 $layoutid = $row[0];283 $layoutid = $row[0];
284 $layoutXml = $row[3];284 $layoutXml = $row[3];
285 $background = $row[4];285 $background = $row[4];
286 286
287 // Add all the associated media first287 // Add all the associated media first
288 $SQL = "SELECT storedAs, media.mediaID 288 $SQL = "SELECT storedAs, media.mediaID, media.`MD5`, media.FileSize
289 FROM media 289 FROM media
290 INNER JOIN lklayoutmedia ON lklayoutmedia.mediaID = media.mediaID 290 INNER JOIN lklayoutmedia ON lklayoutmedia.mediaID = media.mediaID
291 WHERE storedAs IS NOT NULL 291 WHERE storedAs IS NOT NULL
292 AND lklayoutmedia.layoutID = $layoutid292 AND lklayoutmedia.layoutID = $layoutid
293 AND media.mediaID NOT IN (SELECT MediaID 293 AND media.mediaID NOT IN (SELECT MediaID
294 FROM blacklist 294 FROM blacklist
295 WHERE DisplayID = " . $displayInfo['displayid'] . " 295 WHERE DisplayID = " . $displayInfo['displayid'] . "
296 AND isIgnored = 0 )";296 AND isIgnored = 0 )";
297 297
298 if (!$mediaResults = $db->query($SQL))298 if (!$mediaResults = $db->query($SQL))
299 {299 {
300 trigger_error($db->error());300 trigger_error($db->error());
301 return new soap_fault("SOAP-ENV:Server", "", "Unable to get a list of media for the layout [$layoutid]");301 return new soap_fault("SOAP-ENV:Server", "", "Unable to get a list of media for the layout [$layoutid]");
302 }302 }
303 303
304 while ($row = $db->get_row($mediaResults))304 while ($row = $db->get_row($mediaResults))
305 {305 {
306 $storedAs = Kit::ValidateParam($row[0], _STRING);
307 $mediaId = Kit::ValidateParam($row[1], _INT);
308 $md5 = Kit::ValidateParam($row[2], _STRING);
309 $fileSize = Kit::ValidateParam($row[3], _INT);
310
311 // If they are empty calculate them and save them back to the media.
312 if ($md5 == '' || $fileSize == 0)
313 {
314
315 $md5 = md5_file($libraryLocation.$row[0]);
316 $fileSize = filesize($libraryLocation.$row[0]);
317
318 // Update the media record with this information
319 $SQL = sprintf("UPDATE media SET `MD5` = '%s', FileSize = %d WHERE MediaID = %d", $md5, $fileSize, $mediaId);
320
321 if (!$db->query($SQL))
322 trigger_error($db->error());
323 }
324
306 //Add the file node325 //Add the file node
307 $file = $requiredFilesXml->createElement("file");326 $file = $requiredFilesXml->createElement("file");
308 327
309 $file->setAttribute("type", "media");328 $file->setAttribute("type", "media");
310 $file->setAttribute("path", $row[0]);329 $file->setAttribute("path", $storedAs);
311 $file->setAttribute("id", $row[1]);330 $file->setAttribute("id", $mediaId);
312 $file->setAttribute("size", filesize($libraryLocation.$row[0]));331 $file->setAttribute("size", $fileSize);
313 $file->setAttribute("md5", md5_file($libraryLocation.$row[0]));332 $file->setAttribute("md5", $md5);
314 333
315 $fileElements->appendChild($file);334 $fileElements->appendChild($file);
316 }335 }
317 336
318 //Also append another file node for the background image (if there is one)337 //Also append another file node for the background image (if there is one)
319 if ($background != "")338 if ($background != "")
320 {339 {
321 //firstly add this as a node340 //firstly add this as a node
322 $file = $requiredFilesXml->createElement("file");341 $file = $requiredFilesXml->createElement("file");
323 342
324 $file->setAttribute("type", "media");343 $file->setAttribute("type", "media");
325 $file->setAttribute("path", $background);344 $file->setAttribute("path", $background);
326 $file->setAttribute("md5", md5_file($libraryLocation.$background));345 $file->setAttribute("md5", md5_file($libraryLocation.$background));
327 $file->setAttribute("size", filesize($libraryLocation.$background));346 $file->setAttribute("size", filesize($libraryLocation.$background));
328 347
329 $fileElements->appendChild($file);348 $fileElements->appendChild($file);
330 }349 }
331 350
332 // Add this layout as node351 // Add this layout as node
333 $file = $requiredFilesXml->createElement("file");352 $file = $requiredFilesXml->createElement("file");
334 353
335 $file->setAttribute("type", "layout");354 $file->setAttribute("type", "layout");
336 $file->setAttribute("path", $layoutid);355 $file->setAttribute("path", $layoutid);
337 $file->setAttribute("md5", md5($layoutXml . "\n"));356 $file->setAttribute("md5", md5($layoutXml . "\n"));
338 357
339 $fileElements->appendChild($file);358 $fileElements->appendChild($file);
340 }359 }
341 360
342 //361 //
343 // Add a blacklist node362 // Add a blacklist node
344 //363 //
345 $blackList = $requiredFilesXml->createElement("file");364 $blackList = $requiredFilesXml->createElement("file");
346 $blackList->setAttribute("type", "blacklist");365 $blackList->setAttribute("type", "blacklist");
347 366
348 $fileElements->appendChild($blackList);367 $fileElements->appendChild($blackList);
349 368
350 // Populate369 // Populate
351 $SQL = "SELECT MediaID 370 $SQL = "SELECT MediaID
352 FROM blacklist 371 FROM blacklist
353 WHERE DisplayID = " . $displayInfo['displayid'] . " 372 WHERE DisplayID = " . $displayInfo['displayid'] . "
354 AND isIgnored = 0";373 AND isIgnored = 0";
355 374
356 if (!$results = $db->query($SQL))375 if (!$results = $db->query($SQL))
357 {376 {
358 trigger_error($db->error());377 trigger_error($db->error());
359 return new soap_fault("SOAP-ENV:Server", "", "Unable to get a list of blacklisted files", $db->error());378 return new soap_fault("SOAP-ENV:Server", "", "Unable to get a list of blacklisted files", $db->error());
360 }379 }
361 380
362 // Add a black list element for each file381 // Add a black list element for each file
363 while ($row = $db->get_row($results))382 while ($row = $db->get_row($results))
364 {383 {
365 $file = $requiredFilesXml->createElement("file");384 $file = $requiredFilesXml->createElement("file");
366 $file->setAttribute("id", $row[0]);385 $file->setAttribute("id", $row[0]);
367 386
368 $blackList->appendChild($file);387 $blackList->appendChild($file);
369 }388 }
370389
371 // PHONE_HOME if required.390 // PHONE_HOME if required.
372 if (Config::GetSetting($db,'PHONE_HOME') == 'On') {391 if (Config::GetSetting($db,'PHONE_HOME') == 'On') {
373 // Find out when we last PHONED_HOME :D392 // Find out when we last PHONED_HOME :D
374 // If it's been > 28 days since last PHONE_HOME then393 // If it's been > 28 days since last PHONE_HOME then
375 if (Config::GetSetting($db,'PHONE_HOME_DATE') < (time() - (60 * 60 * 24 * 28))) {394 if (Config::GetSetting($db,'PHONE_HOME_DATE') < (time() - (60 * 60 * 24 * 28))) {
376395
377 if ($displayInfo['isAuditing'] == 1) 396 if ($displayInfo['isAuditing'] == 1)
378 {397 {
379 Debug::LogEntry($db, "audit", "PHONE_HOME [IN]", "xmds", "RequiredFiles"); 398 Debug::LogEntry($db, "audit", "PHONE_HOME [IN]", "xmds", "RequiredFiles");
380 }399 }
381400
382 // Retrieve number of displays401 // Retrieve number of displays
383 $SQL = "SELECT COUNT(*)402 $SQL = "SELECT COUNT(*)
384 FROM `display`403 FROM `display`
385 WHERE `licensed` = '1'";404 WHERE `licensed` = '1'";
386 if (!$results = $db->query($SQL))405 if (!$results = $db->query($SQL))
387 {406 {
388 trigger_error($db->error());407 trigger_error($db->error());
@@ -390,52 +409,52 @@
390 while ($row = $db->get_row($results))409 while ($row = $db->get_row($results))
391 {410 {
392 $PHONE_HOME_CLIENTS = Kit::ValidateParam($row[0],_INT);411 $PHONE_HOME_CLIENTS = Kit::ValidateParam($row[0],_INT);
393 }412 }
394 413
395 // Retrieve version number414 // Retrieve version number
396 $PHONE_HOME_VERSION = Config::Version($db, 'app_ver');415 $PHONE_HOME_VERSION = Config::Version($db, 'app_ver');
397416
398 $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);417 $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);
399418
400 if ($displayInfo['isAuditing'] == 1) 419 if ($displayInfo['isAuditing'] == 1)
401 {420 {
402 Debug::LogEntry($db, "audit", "PHONE_HOME_URL " . $PHONE_HOME_URL , "xmds", "RequiredFiles"); 421 Debug::LogEntry($db, "audit", "PHONE_HOME_URL " . $PHONE_HOME_URL , "xmds", "RequiredFiles");
403 }422 }
404 423
405 // Set PHONE_HOME_TIME to NOW.424 // Set PHONE_HOME_TIME to NOW.
406 $SQL = "UPDATE `setting`425 $SQL = "UPDATE `setting`
407 SET `value` = '" . time() . "'426 SET `value` = '" . time() . "'
408 WHERE `setting`.`setting` = 'PHONE_HOME_DATE' LIMIT 1";427 WHERE `setting`.`setting` = 'PHONE_HOME_DATE' LIMIT 1";
409428
410 if (!$results = $db->query($SQL))429 if (!$results = $db->query($SQL))
411 {430 {
412 trigger_error($db->error());431 trigger_error($db->error());
413 }432 }
414 433
415 @file_get_contents($PHONE_HOME_URL);434 @file_get_contents($PHONE_HOME_URL);
416435
417 if ($displayInfo['isAuditing'] == 1) 436 if ($displayInfo['isAuditing'] == 1)
418 {437 {
419 Debug::LogEntry($db, "audit", "PHONE_HOME [OUT]", "xmds", "RequiredFiles"); 438 Debug::LogEntry($db, "audit", "PHONE_HOME [OUT]", "xmds", "RequiredFiles");
420 }439 }
421 //endif440 //endif
422 }441 }
423 }442 }
424 // END OF PHONE_HOME CODE443 // END OF PHONE_HOME CODE
425444
426 if ($displayInfo['isAuditing'] == 1) 445 if ($displayInfo['isAuditing'] == 1)
427 {446 {
428 Debug::LogEntry($db, "audit", $requiredFilesXml->saveXML(), "xmds", "RequiredFiles"); 447 Debug::LogEntry($db, "audit", $requiredFilesXml->saveXML(), "xmds", "RequiredFiles");
429 Debug::LogEntry($db, "audit", "[OUT]", "xmds", "RequiredFiles"); 448 Debug::LogEntry($db, "audit", "[OUT]", "xmds", "RequiredFiles");
430 }449 }
431 450
432 // Return the results of requiredFiles()451 // Return the results of requiredFiles()
433 return $requiredFilesXml->saveXML();452 return $requiredFilesXml->saveXML();
434}453}
435454
436/**455/**
437 * Gets the specified file456 * Gets the specified file
438 * @return 457 * @return
439 * @param $hardwareKey Object458 * @param $hardwareKey Object
440 * @param $filePath Object459 * @param $filePath Object
441 * @param $fileType Object460 * @param $fileType Object
@@ -443,7 +462,7 @@
443function GetFile($serverKey, $hardwareKey, $filePath, $fileType, $chunkOffset, $chunkSize, $version)462function GetFile($serverKey, $hardwareKey, $filePath, $fileType, $chunkOffset, $chunkSize, $version)
444{463{
445 global $db;464 global $db;
446 465
447 // Sanitize466 // Sanitize
448 $serverKey = Kit::ValidateParam($serverKey, _STRING);467 $serverKey = Kit::ValidateParam($serverKey, _STRING);
449 $hardwareKey = Kit::ValidateParam($hardwareKey, _STRING);468 $hardwareKey = Kit::ValidateParam($hardwareKey, _STRING);
@@ -451,83 +470,83 @@
451 $chunkOffset = Kit::ValidateParam($chunkOffset, _INT);470 $chunkOffset = Kit::ValidateParam($chunkOffset, _INT);
452 $chunkSize = Kit::ValidateParam($chunkSize, _INT);471 $chunkSize = Kit::ValidateParam($chunkSize, _INT);
453 $version = Kit::ValidateParam($version, _STRING);472 $version = Kit::ValidateParam($version, _STRING);
454 473
455 $libraryLocation = Config::GetSetting($db, "LIBRARY_LOCATION");474 $libraryLocation = Config::GetSetting($db, "LIBRARY_LOCATION");
456 475
457 // Make sure we are talking the same language476 // Make sure we are talking the same language
458 if (!CheckVersion($version))477 if (!CheckVersion($version))
459 {478 {
460 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);479 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);
461 }480 }
462 481
463 //auth this request...482 //auth this request...
464 if (!$displayInfo = Auth($hardwareKey))483 if (!$displayInfo = Auth($hardwareKey))
465 {484 {
466 return new soap_fault("SOAP-ENV:Client", "", "This display client is not licensed");485 return new soap_fault("SOAP-ENV:Client", "", "This display client is not licensed");
467 }486 }
468 487
469 if ($displayInfo['isAuditing'] == 1) 488 if ($displayInfo['isAuditing'] == 1)
470 {489 {
471 Debug::LogEntry($db, "audit", "[IN]", "xmds", "GetFile"); 490 Debug::LogEntry($db, "audit", "[IN]", "xmds", "GetFile");
472 Debug::LogEntry($db, "audit", "Params: [$hardwareKey] [$filePath] [$fileType] [$chunkOffset] [$chunkSize]", "xmds", "GetFile"); 491 Debug::LogEntry($db, "audit", "Params: [$hardwareKey] [$filePath] [$fileType] [$chunkOffset] [$chunkSize]", "xmds", "GetFile");
473 }492 }
474493
475 if ($fileType == "layout")494 if ($fileType == "layout")
476 {495 {
477 $filePath = Kit::ValidateParam($filePath, _INT);496 $filePath = Kit::ValidateParam($filePath, _INT);
478 497
479 $SQL = sprintf("SELECT xml FROM layout WHERE layoutid = %d", $filePath);498 $SQL = sprintf("SELECT xml FROM layout WHERE layoutid = %d", $filePath);
480 if (!$results = $db->query($SQL))499 if (!$results = $db->query($SQL))
481 {500 {
482 trigger_error($db->error());501 trigger_error($db->error());
483 return new soap_fault("SOAP-ENV:Server", "", "Unable to get a list of files", $db->error());502 return new soap_fault("SOAP-ENV:Server", "", "Unable to get a list of files", $db->error());
484 }503 }
485 504
486 $row = $db->get_row($results);505 $row = $db->get_row($results);
487 506
488 $file = $row[0];507 $file = $row[0];
489 }508 }
490 elseif ($fileType == "media")509 elseif ($fileType == "media")
491 {510 {
492 $filePath = Kit::ValidateParam($filePath, _STRING);511 $filePath = Kit::ValidateParam($filePath, _STRING);
493 512
494 //Return the Chunk size specified513 //Return the Chunk size specified
495 $f = fopen($libraryLocation.$filePath,"r");514 $f = fopen($libraryLocation.$filePath,"r");
496 515
497 fseek($f, $chunkOffset);516 fseek($f, $chunkOffset);
498 517
499 $file = fread($f, $chunkSize);518 $file = fread($f, $chunkSize);
500 }519 }
501 else 520 else
502 {521 {
503 return new soap_fault("SOAP-ENV:Client", "", "Unknown FileType Requested.");522 return new soap_fault("SOAP-ENV:Client", "", "Unknown FileType Requested.");
504 }523 }
505 524
506 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry($db, "audit", "[OUT]", "xmds", "GetFile"); 525 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry($db, "audit", "[OUT]", "xmds", "GetFile");
507 526
508 return base64_encode($file);527 return base64_encode($file);
509}528}
510529
511/**530/**
512 * Returns the schedule for the hardware key specified531 * Returns the schedule for the hardware key specified
513 * @return 532 * @return
514 * @param $hardwareKey Object533 * @param $hardwareKey Object
515 */534 */
516function Schedule($serverKey, $hardwareKey, $version)535function Schedule($serverKey, $hardwareKey, $version)
517{536{
518 global $db;537 global $db;
519 538
520 // Sanitize539 // Sanitize
521 $serverKey = Kit::ValidateParam($serverKey, _STRING);540 $serverKey = Kit::ValidateParam($serverKey, _STRING);
522 $hardwareKey = Kit::ValidateParam($hardwareKey, _STRING);541 $hardwareKey = Kit::ValidateParam($hardwareKey, _STRING);
523 $version = Kit::ValidateParam($version, _STRING);542 $version = Kit::ValidateParam($version, _STRING);
524 543
525 // Make sure we are talking the same language544 // Make sure we are talking the same language
526 if (!CheckVersion($version))545 if (!CheckVersion($version))
527 {546 {
528 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);547 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);
529 }548 }
530 549
531 //auth this request...550 //auth this request...
532 if (!$displayInfo = Auth($hardwareKey))551 if (!$displayInfo = Auth($hardwareKey))
533 {552 {
@@ -535,16 +554,16 @@
535 }554 }
536555
537 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry($db, "audit", "[IN] $hardwareKey", "xmds", "Schedule");556 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry($db, "audit", "[IN] $hardwareKey", "xmds", "Schedule");
538 557
539 $scheduleXml = new DOMDocument("1.0");558 $scheduleXml = new DOMDocument("1.0");
540 $layoutElements = $scheduleXml->createElement("schedule");559 $layoutElements = $scheduleXml->createElement("schedule");
541 560
542 $scheduleXml->appendChild($layoutElements);561 $scheduleXml->appendChild($layoutElements);
543 562
544 $currentdate = date("Y-m-d H:i:s");563 $currentdate = date("Y-m-d H:i:s");
545 $time = time();564 $time = time();
546 $plus4hours = date("Y-m-d H:i:s",$time + 86400);565 $plus4hours = date("Y-m-d H:i:s",$time + 86400);
547 566
548 //Add file nodes to the $fileElements567 //Add file nodes to the $fileElements
549 //Firstly get all the scheduled layouts568 //Firstly get all the scheduled layouts
550 $SQL = " SELECT layout.layoutID, schedule_detail.starttime, schedule_detail.endtime, schedule_detail.eventID ";569 $SQL = " SELECT layout.layoutID, schedule_detail.starttime, schedule_detail.endtime, schedule_detail.eventID ";
@@ -553,15 +572,15 @@
553 $SQL .= " INNER JOIN display ON schedule_detail.displayID = display.displayID ";572 $SQL .= " INNER JOIN display ON schedule_detail.displayID = display.displayID ";
554 $SQL .= " WHERE display.license = '$hardwareKey' ";573 $SQL .= " WHERE display.license = '$hardwareKey' ";
555 $SQL .= " AND layout.retired = 0 ";574 $SQL .= " AND layout.retired = 0 ";
556 575
557 // Store the Base SQL for this display576 // Store the Base SQL for this display
558 $SQLBase = $SQL;577 $SQLBase = $SQL;
559 578
560 // Run the query579 // Run the query
561 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry($db, "audit", "$SQL", "xmds", "Schedule");580 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry($db, "audit", "$SQL", "xmds", "Schedule");
562 581
563582
564 583
565 // Do we include the default display584 // Do we include the default display
566 if ($displayInfo['inc_schedule'] == 1)585 if ($displayInfo['inc_schedule'] == 1)
567 {586 {
@@ -572,20 +591,20 @@
572 {591 {
573 $SQL .= " AND (schedule_detail.starttime < '$currentdate' AND schedule_detail.endtime > '$currentdate' )";592 $SQL .= " AND (schedule_detail.starttime < '$currentdate' AND schedule_detail.endtime > '$currentdate' )";
574 }593 }
575 594
576 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry($db, "audit", "$SQL", "xmds", "Schedule");595 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry($db, "audit", "$SQL", "xmds", "Schedule");
577 596
578 597
579 // Before we run the main query we should check to see if there are any priority layouts to deal with598 // Before we run the main query we should check to see if there are any priority layouts to deal with
580 $SQLp = " AND schedule_detail.is_priority = 1 ";599 $SQLp = " AND schedule_detail.is_priority = 1 ";
581 600
582 // Run the query601 // Run the query
583 if (!$results = $db->query($SQL . $SQLp))602 if (!$results = $db->query($SQL . $SQLp))
584 {603 {
585 trigger_error($db->error());604 trigger_error($db->error());
586 return new soap_fault("SOAP-ENV:Server", "", "Unable to get A list of layouts for the schedule", $db->error());605 return new soap_fault("SOAP-ENV:Server", "", "Unable to get A list of layouts for the schedule", $db->error());
587 }606 }
588 607
589 // If there were no results then continue to get the full schedule608 // If there were no results then continue to get the full schedule
590 if ($db->num_rows($results) == 0)609 if ($db->num_rows($results) == 0)
591 {610 {
@@ -595,7 +614,7 @@
595 trigger_error($db->error());614 trigger_error($db->error());
596 return new soap_fault("SOAP-ENV:Server", "", "Unable to get A list of layouts for the schedule", $db->error());615 return new soap_fault("SOAP-ENV:Server", "", "Unable to get A list of layouts for the schedule", $db->error());
597 }616 }
598 617
599 // Was there anything?618 // Was there anything?
600 if ($db->num_rows($results) == 0)619 if ($db->num_rows($results) == 0)
601 {620 {
@@ -603,7 +622,7 @@
603 $SQL = $SQLBase;622 $SQL = $SQLBase;
604 $SQL .= " AND ((schedule_detail.starttime < '$currentdate' AND schedule_detail.endtime > '$currentdate' )";623 $SQL .= " AND ((schedule_detail.starttime < '$currentdate' AND schedule_detail.endtime > '$currentdate' )";
605 $SQL .= " OR (schedule_detail.starttime = '2050-12-31 00:00:00' AND schedule_detail.endtime = '2050-12-31 00:00:00' ))";624 $SQL .= " OR (schedule_detail.starttime = '2050-12-31 00:00:00' AND schedule_detail.endtime = '2050-12-31 00:00:00' ))";
606 625
607 if (!$results = $db->query($SQL))626 if (!$results = $db->query($SQL))
608 {627 {
609 trigger_error($db->error());628 trigger_error($db->error());
@@ -611,7 +630,7 @@
611 }630 }
612 }631 }
613 }632 }
614 633
615 // We must have some results in here by this point634 // We must have some results in here by this point
616 while ($row = $db->get_row($results))635 while ($row = $db->get_row($results))
617 {636 {
@@ -619,42 +638,42 @@
619 $fromdt = $row[1];638 $fromdt = $row[1];
620 $todt = $row[2];639 $todt = $row[2];
621 $scheduleid = $row[3];640 $scheduleid = $row[3];
622 641
623 //firstly add this as a node642 //firstly add this as a node
624 $layout = $scheduleXml->createElement("layout");643 $layout = $scheduleXml->createElement("layout");
625 644
626 $layout->setAttribute("file", $layoutid);645 $layout->setAttribute("file", $layoutid);
627 $layout->setAttribute("fromdt", $fromdt);646 $layout->setAttribute("fromdt", $fromdt);
628 $layout->setAttribute("todt", $todt);647 $layout->setAttribute("todt", $todt);
629 $layout->setAttribute("scheduleid", $scheduleid);648 $layout->setAttribute("scheduleid", $scheduleid);
630 649
631 $layoutElements->appendChild($layout);650 $layoutElements->appendChild($layout);
632 }651 }
633 652
634 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry($db, "audit", $scheduleXml->saveXML(), "xmds", "Schedule");653 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry($db, "audit", $scheduleXml->saveXML(), "xmds", "Schedule");
635 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry($db, "audit", "[OUT]", "xmds", "Schedule");654 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry($db, "audit", "[OUT]", "xmds", "Schedule");
636 655
637 return $scheduleXml->saveXML();656 return $scheduleXml->saveXML();
638}657}
639658
640/**659/**
641 * Recieves the XmlLog from the display660 * Recieves the XmlLog from the display
642 * @return 661 * @return
643 * @param $hardwareKey String662 * @param $hardwareKey String
644 * @param $xml String663 * @param $xml String
645 */664 */
646function RecieveXmlLog($serverKey, $hardwareKey, $xml, $version)665function RecieveXmlLog($serverKey, $hardwareKey, $xml, $version)
647{666{
648 global $db;667 global $db;
649 668
650 return new soap_fault("SOAP-ENV:Client", "", "This is a depricated service call. You should instead call either SubmitLog or SubmitStats", $serverKey);669 return new soap_fault("SOAP-ENV:Client", "", "This is a depricated service call. You should instead call either SubmitLog or SubmitStats", $serverKey);
651}670}
652671
653define('BLACKLIST_ALL', "All");672define('BLACKLIST_ALL', "All");
654define('BLACKLIST_SINGLE', "Single");673define('BLACKLIST_SINGLE', "Single");
655/**674/**
656 * 675 *
657 * @return 676 * @return
658 * @param $hardwareKey Object677 * @param $hardwareKey Object
659 * @param $mediaId Object678 * @param $mediaId Object
660 * @param $type Object679 * @param $type Object
@@ -662,7 +681,7 @@
662function BlackList($serverKey, $hardwareKey, $mediaId, $type, $reason, $version)681function BlackList($serverKey, $hardwareKey, $mediaId, $type, $reason, $version)
663{682{
664 global $db;683 global $db;
665 684
666 // Sanitize685 // Sanitize
667 $serverKey = Kit::ValidateParam($serverKey, _STRING);686 $serverKey = Kit::ValidateParam($serverKey, _STRING);
668 $hardwareKey = Kit::ValidateParam($hardwareKey, _STRING);687 $hardwareKey = Kit::ValidateParam($hardwareKey, _STRING);
@@ -670,7 +689,7 @@
670 $type = Kit::ValidateParam($type, _STRING);689 $type = Kit::ValidateParam($type, _STRING);
671 $reason = Kit::ValidateParam($reason, _STRING);690 $reason = Kit::ValidateParam($reason, _STRING);
672 $version = Kit::ValidateParam($version, _STRING);691 $version = Kit::ValidateParam($version, _STRING);
673 692
674 // Make sure we are talking the same language693 // Make sure we are talking the same language
675 if (!CheckVersion($version))694 if (!CheckVersion($version))
676 {695 {
@@ -682,19 +701,19 @@
682 {701 {
683 return new soap_fault("SOAP-ENV:Client", "", "This display client is not licensed", $hardwareKey);702 return new soap_fault("SOAP-ENV:Client", "", "This display client is not licensed", $hardwareKey);
684 }703 }
685 704
686 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry ($db, "audit", "[IN]", "xmds", "BlackList", "", $displayInfo['displayid']);705 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry ($db, "audit", "[IN]", "xmds", "BlackList", "", $displayInfo['displayid']);
687 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry ($db, "audit", "$xml", "xmds", "BlackList", "", $displayInfo['displayid']);706 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry ($db, "audit", "$xml", "xmds", "BlackList", "", $displayInfo['displayid']);
688 707
689 // Check to see if this media/display is already blacklisted (and not ignored)708 // Check to see if this media/display is already blacklisted (and not ignored)
690 $SQL = "SELECT BlackListID FROM blacklist WHERE MediaID = $mediaId AND isIgnored = 0 AND DisplayID = " . $displayInfo['displayid'];709 $SQL = "SELECT BlackListID FROM blacklist WHERE MediaID = $mediaId AND isIgnored = 0 AND DisplayID = " . $displayInfo['displayid'];
691 710
692 if (!$results = $db->query($SQL))711 if (!$results = $db->query($SQL))
693 {712 {
694 trigger_error($db->error());713 trigger_error($db->error());
695 return new soap_fault("SOAP-ENV:Server", "", "Unable to query for BlackList records.", $db->error());714 return new soap_fault("SOAP-ENV:Server", "", "Unable to query for BlackList records.", $db->error());
696 }715 }
697 716
698 if ($db->num_rows($results) == 0)717 if ($db->num_rows($results) == 0)
699 {718 {
700 // Insert the black list record719 // Insert the black list record
@@ -705,20 +724,20 @@
705 // Only the current display724 // Only the current display
706 $SQL .= " WHERE displayID = " . $displayInfo['displayid'];725 $SQL .= " WHERE displayID = " . $displayInfo['displayid'];
707 }726 }
708 727
709 if (!$displays = $db->query($SQL))728 if (!$displays = $db->query($SQL))
710 {729 {
711 trigger_error($db->error());730 trigger_error($db->error());
712 return new soap_fault("SOAP-ENV:Server", "", "Unable to query for BlackList Displays.", $db->error());731 return new soap_fault("SOAP-ENV:Server", "", "Unable to query for BlackList Displays.", $db->error());
713 }732 }
714 733
715 while ($row = $db->get_row($displays))734 while ($row = $db->get_row($displays))
716 {735 {
717 $displayId = $row[0];736 $displayId = $row[0];
718 737
719 $SQL = "INSERT INTO blacklist (MediaID, DisplayID, ReportingDisplayID, Reason)738 $SQL = "INSERT INTO blacklist (MediaID, DisplayID, ReportingDisplayID, Reason)
720 VALUES ($mediaId, $displayId, " . $displayInfo['displayid'] . ", '$reason') ";739 VALUES ($mediaId, $displayId, " . $displayInfo['displayid'] . ", '$reason') ";
721 740
722 if (!$db->query($SQL))741 if (!$db->query($SQL))
723 {742 {
724 trigger_error($db->error());743 trigger_error($db->error());
@@ -730,15 +749,15 @@
730 {749 {
731 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry ($db, "audit", "Media Already BlackListed [$mediaId]", "xmds", "BlackList", "", $displayInfo['displayid']);750 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry ($db, "audit", "Media Already BlackListed [$mediaId]", "xmds", "BlackList", "", $displayInfo['displayid']);
732 }751 }
733 752
734 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry ($db, "audit", "[OUT]", "xmds", "BlackList", "", $displayInfo['displayid']);753 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry ($db, "audit", "[OUT]", "xmds", "BlackList", "", $displayInfo['displayid']);
735 754
736 return true;755 return true;
737}756}
738757
739/**758/**
740 * Submit client logging759 * Submit client logging
741 * @return 760 * @return
742 * @param $version Object761 * @param $version Object
743 * @param $serverKey Object762 * @param $serverKey Object
744 * @param $hardwareKey Object763 * @param $hardwareKey Object
@@ -747,13 +766,13 @@
747function SubmitLog($version, $serverKey, $hardwareKey, $logXml)766function SubmitLog($version, $serverKey, $hardwareKey, $logXml)
748{767{
749 global $db;768 global $db;
750 769
751 // Sanitize770 // Sanitize
752 $serverKey = Kit::ValidateParam($serverKey, _STRING);771 $serverKey = Kit::ValidateParam($serverKey, _STRING);
753 $hardwareKey = Kit::ValidateParam($hardwareKey, _STRING);772 $hardwareKey = Kit::ValidateParam($hardwareKey, _STRING);
754 $version = Kit::ValidateParam($version, _STRING);773 $version = Kit::ValidateParam($version, _STRING);
755 $logXml = Kit::ValidateParam($logXml, _HTMLSTRING);774 $logXml = Kit::ValidateParam($logXml, _HTMLSTRING);
756 775
757 // Make sure we are talking the same language776 // Make sure we are talking the same language
758 if (!CheckVersion($version))777 if (!CheckVersion($version))
759 {778 {
@@ -765,20 +784,20 @@
765 {784 {
766 return new soap_fault("SOAP-ENV:Client", "", "This display client is not licensed", $hardwareKey);785 return new soap_fault("SOAP-ENV:Client", "", "This display client is not licensed", $hardwareKey);
767 }786 }
768 787
769 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry ($db, "audit", "IN", "xmds", "SubmitLog", "", $displayInfo['displayid']);788 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry ($db, "audit", "IN", "xmds", "SubmitLog", "", $displayInfo['displayid']);
770 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry ($db, "audit", 'XML [' . $logXml . ']', "xmds", "SubmitLog", "", $displayInfo['displayid']);789 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry ($db, "audit", 'XML [' . $logXml . ']', "xmds", "SubmitLog", "", $displayInfo['displayid']);
771 790
772 // Load the XML into a DOMDocument791 // Load the XML into a DOMDocument
773 $document = new DOMDocument("1.0");792 $document = new DOMDocument("1.0");
774 793
775 if (!$document->loadXML($logXml))794 if (!$document->loadXML($logXml))
776 {795 {
777 return new soap_fault("SOAP-ENV:Client", "", "XML Cannot be loaded into DOM Document.", $hardwareKey);796 return new soap_fault("SOAP-ENV:Client", "", "XML Cannot be loaded into DOM Document.", $hardwareKey);
778 }797 }
779 798
780 foreach ($document->documentElement->childNodes as $node)799 foreach ($document->documentElement->childNodes as $node)
781 { 800 {
782 //Zero out the common vars801 //Zero out the common vars
783 $date = "";802 $date = "";
784 $message = "";803 $message = "";
@@ -787,23 +806,23 @@
787 $mediaID = "";806 $mediaID = "";
788 $cat = '';807 $cat = '';
789 $method = '';808 $method = '';
790 809
791 // This will be a bunch of trace nodes810 // This will be a bunch of trace nodes
792 $message = $node->textContent;811 $message = $node->textContent;
793 812
794 // Each element should have a category and a date 813 // Each element should have a category and a date
795 $date = $node->getAttribute('date');814 $date = $node->getAttribute('date');
796 $cat = $node->getAttribute('category');815 $cat = $node->getAttribute('category');
797 816
798 if ($date == '' || $cat == '') 817 if ($date == '' || $cat == '')
799 {818 {
800 trigger_error('Log submitted without a date or category attribute');819 trigger_error('Log submitted without a date or category attribute');
801 continue;820 continue;
802 }821 }
803 822
804 // Get the date and the message (all log types have these)823 // Get the date and the message (all log types have these)
805 foreach ($node->childNodes as $nodeElements)824 foreach ($node->childNodes as $nodeElements)
806 { 825 {
807 if ($nodeElements->nodeName == "scheduleID")826 if ($nodeElements->nodeName == "scheduleID")
808 {827 {
809 $scheduleID = $nodeElements->textContent;828 $scheduleID = $nodeElements->textContent;
@@ -825,26 +844,26 @@
825 $method = $nodeElements->textContent;844 $method = $nodeElements->textContent;
826 }845 }
827 }846 }
828 847
829 // We should have enough information to log this now.848 // We should have enough information to log this now.
830 if ($cat == 'error' || $cat == 'Error')849 if ($cat == 'error' || $cat == 'Error')
831 {850 {
832 Debug::LogEntry($db, $cat, $message, 'Client', $method, $date, $displayInfo['displayid'], $scheduleID, $layoutID, $mediaID); 851 Debug::LogEntry($db, $cat, $message, 'Client', $method, $date, $displayInfo['displayid'], $scheduleID, $layoutID, $mediaID);
833 }852 }
834 else853 else
835 {854 {
836 Debug::LogEntry($db, 'audit', $message, 'Client', $method, $date, $displayInfo['displayid'], $scheduleID, $layoutID, $mediaID); 855 Debug::LogEntry($db, 'audit', $message, 'Client', $method, $date, $displayInfo['displayid'], $scheduleID, $layoutID, $mediaID);
837 }856 }
838 }857 }
839858
840 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry ($db, "audit", "OUT", "xmds", "SubmitLog", "", $displayInfo['displayid']);859 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry ($db, "audit", "OUT", "xmds", "SubmitLog", "", $displayInfo['displayid']);
841 860
842 return true;861 return true;
843}862}
844863
845/**864/**
846 * Submit display statistics to the server865 * Submit display statistics to the server
847 * @return 866 * @return
848 * @param $version Object867 * @param $version Object
849 * @param $serverKey Object868 * @param $serverKey Object
850 * @param $hardwareKey Object869 * @param $hardwareKey Object
@@ -853,13 +872,13 @@
853function SubmitStats($version, $serverKey, $hardwareKey, $statXml)872function SubmitStats($version, $serverKey, $hardwareKey, $statXml)
854{873{
855 global $db;874 global $db;
856 875
857 // Sanitize876 // Sanitize
858 $serverKey = Kit::ValidateParam($serverKey, _STRING);877 $serverKey = Kit::ValidateParam($serverKey, _STRING);
859 $hardwareKey = Kit::ValidateParam($hardwareKey, _STRING);878 $hardwareKey = Kit::ValidateParam($hardwareKey, _STRING);
860 $version = Kit::ValidateParam($version, _STRING);879 $version = Kit::ValidateParam($version, _STRING);
861 $statXml = Kit::ValidateParam($statXml, _HTMLSTRING);880 $statXml = Kit::ValidateParam($statXml, _HTMLSTRING);
862 881
863 // Make sure we are talking the same language882 // Make sure we are talking the same language
864 if (!CheckVersion($version))883 if (!CheckVersion($version))
865 {884 {
@@ -871,55 +890,55 @@
871 {890 {
872 return new soap_fault("SOAP-ENV:Client", "", "This display client is not licensed", $hardwareKey);891 return new soap_fault("SOAP-ENV:Client", "", "This display client is not licensed", $hardwareKey);
873 }892 }
874 893
875 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry ($db, "audit", "IN", "xmds", "SubmitStats", "", $displayInfo['displayid']);894 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry ($db, "audit", "IN", "xmds", "SubmitStats", "", $displayInfo['displayid']);
876 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry ($db, "audit", "StatXml: [" . $statXml . "]", "xmds", "SubmitStats", "", $displayInfo['displayid']);895 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry ($db, "audit", "StatXml: [" . $statXml . "]", "xmds", "SubmitStats", "", $displayInfo['displayid']);
877 896
878 if ($statXml == "")897 if ($statXml == "")
879 {898 {
880 return new soap_fault("SOAP-ENV:Client", "", "Stat XML is empty.", $hardwareKey);899 return new soap_fault("SOAP-ENV:Client", "", "Stat XML is empty.", $hardwareKey);
881 }900 }
882 901
883 // Log902 // Log
884 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry ($db, "audit", "About to create Stat Object.", "xmds", "SubmitStats", "", $displayInfo['displayid']);903 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry ($db, "audit", "About to create Stat Object.", "xmds", "SubmitStats", "", $displayInfo['displayid']);
885 904
886 $statObject = new Stat($db);905 $statObject = new Stat($db);
887 906
888 // Log907 // Log
889 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry ($db, "audit", "About to Create DOMDocument.", "xmds", "SubmitStats", "", $displayInfo['displayid']);908 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry ($db, "audit", "About to Create DOMDocument.", "xmds", "SubmitStats", "", $displayInfo['displayid']);
890 909
891 // Load the XML into a DOMDocument910 // Load the XML into a DOMDocument
892 $document = new DOMDocument("1.0");911 $document = new DOMDocument("1.0");
893 $document->loadXML($statXml);912 $document->loadXML($statXml);
894 913
895 foreach ($document->documentElement->childNodes as $node)914 foreach ($document->documentElement->childNodes as $node)
896 { 915 {
897 //Zero out the common vars916 //Zero out the common vars
898 $fromdt = '';917 $fromdt = '';
899 $todt = '';918 $todt = '';
900 $type = '';919 $type = '';
901 920
902 $scheduleID = 0;921 $scheduleID = 0;
903 $layoutID = 0;922 $layoutID = 0;
904 $mediaID = '';923 $mediaID = '';
905 $tag = '';924 $tag = '';
906 925
907 // Each element should have these attributes926 // Each element should have these attributes
908 $fromdt = $node->getAttribute('fromdt');927 $fromdt = $node->getAttribute('fromdt');
909 $todt = $node->getAttribute('todt');928 $todt = $node->getAttribute('todt');
910 $type = $node->getAttribute('type');929 $type = $node->getAttribute('type');
911 930
912 if ($fromdt == '' || $todt == '' || $type == '') 931 if ($fromdt == '' || $todt == '' || $type == '')
913 {932 {
914 trigger_error('Stat submitted without the fromdt, todt or type attributes.');933 trigger_error('Stat submitted without the fromdt, todt or type attributes.');
915 continue;934 continue;
916 }935 }
917 936
918 $scheduleID = $node->getAttribute('scheduleid');937 $scheduleID = $node->getAttribute('scheduleid');
919 $layoutID = $node->getAttribute('layoutid');938 $layoutID = $node->getAttribute('layoutid');
920 $mediaID = $node->getAttribute('mediaid');939 $mediaID = $node->getAttribute('mediaid');
921 $tag = $node->getAttribute('tag');940 $tag = $node->getAttribute('tag');
922 941
923 // Write the stat record with the information we have available to us.942 // Write the stat record with the information we have available to us.
924 if (!$statObject->Add($type, $fromdt, $todt, $scheduleID, $displayInfo['displayid'], $layoutID, $mediaID, $tag))943 if (!$statObject->Add($type, $fromdt, $todt, $scheduleID, $displayInfo['displayid'], $layoutID, $mediaID, $tag))
925 {944 {
@@ -929,7 +948,7 @@
929 }948 }
930949
931 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry ($db, "audit", "OUT", "xmds", "SubmitStats", "", $displayInfo['displayid']);950 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry ($db, "audit", "OUT", "xmds", "SubmitStats", "", $displayInfo['displayid']);
932 951
933 return true;952 return true;
934}953}
935954
@@ -938,7 +957,7 @@
938957
939$service->configureWSDL("xmds", "urn:xmds");958$service->configureWSDL("xmds", "urn:xmds");
940959
941$service->register("RegisterDisplay", 960$service->register("RegisterDisplay",
942 array('serverKey' => 'xsd:string', 'hardwareKey' => 'xsd:string', 'displayName' => 'xsd:string', 'version' => 'xsd:string'),961 array('serverKey' => 'xsd:string', 'hardwareKey' => 'xsd:string', 'displayName' => 'xsd:string', 'version' => 'xsd:string'),
943 array('ActivationMessage' => 'xsd:string'),962 array('ActivationMessage' => 'xsd:string'),
944 'urn:xmds',963 'urn:xmds',
@@ -947,8 +966,8 @@
947 'encoded',966 'encoded',
948 'Registered the Display on the Xibo Network'967 'Registered the Display on the Xibo Network'
949 );968 );
950 969
951$service->register("RequiredFiles", 970$service->register("RequiredFiles",
952 array('serverKey' => 'xsd:string', 'hardwareKey' => 'xsd:string', 'version' => 'xsd:string'),971 array('serverKey' => 'xsd:string', 'hardwareKey' => 'xsd:string', 'version' => 'xsd:string'),
953 array('RequiredFilesXml' => 'xsd:string'),972 array('RequiredFilesXml' => 'xsd:string'),
954 'urn:xmds',973 'urn:xmds',
@@ -957,8 +976,8 @@
957 'encoded',976 'encoded',
958 'The files required by the requesting display'977 'The files required by the requesting display'
959 );978 );
960 979
961$service->register("GetFile", 980$service->register("GetFile",
962 array('serverKey' => 'xsd:string', 'hardwareKey' => 'xsd:string', 'filePath' => 'xsd:string', 'fileType' => 'xsd:string', 'chunkOffset' => 'xsd:int', 'chuckSize' => 'xsd:int', 'version' => 'xsd:string'),981 array('serverKey' => 'xsd:string', 'hardwareKey' => 'xsd:string', 'filePath' => 'xsd:string', 'fileType' => 'xsd:string', 'chunkOffset' => 'xsd:int', 'chuckSize' => 'xsd:int', 'version' => 'xsd:string'),
963 array('file' => 'xsd:base64Binary'),982 array('file' => 'xsd:base64Binary'),
964 'urn:xmds',983 'urn:xmds',
@@ -966,9 +985,9 @@
966 'rpc',985 'rpc',
967 'encoded',986 'encoded',
968 'Gets the file requested'987 'Gets the file requested'
969 ); 988 );
970 989
971$service->register("Schedule", 990$service->register("Schedule",
972 array('serverKey' => 'xsd:string', 'hardwareKey' => 'xsd:string', 'version' => 'xsd:string'),991 array('serverKey' => 'xsd:string', 'hardwareKey' => 'xsd:string', 'version' => 'xsd:string'),
973 array('ScheduleXml' => 'xsd:string'),992 array('ScheduleXml' => 'xsd:string'),
974 'urn:xmds',993 'urn:xmds',
@@ -976,8 +995,8 @@
976 'rpc',995 'rpc',
977 'encoded',996 'encoded',
978 'Gets the schedule'997 'Gets the schedule'
979 ); 998 );
980 999
981$service->register("RecieveXmlLog",1000$service->register("RecieveXmlLog",
982 array('serverKey' => 'xsd:string', 'hardwareKey' => 'xsd:string', 'xml' => 'xsd:string', 'version' => 'xsd:string'),1001 array('serverKey' => 'xsd:string', 'hardwareKey' => 'xsd:string', 'xml' => 'xsd:string', 'version' => 'xsd:string'),
983 array('success' => 'xsd:boolean'),1002 array('success' => 'xsd:boolean'),
@@ -997,7 +1016,7 @@
997 'encoded',1016 'encoded',
998 'Set media to be blacklisted'1017 'Set media to be blacklisted'
999 );1018 );
1000 1019
1001$service->register("SubmitLog",1020$service->register("SubmitLog",
1002 array('version' => 'xsd:string', 'serverKey' => 'xsd:string', 'hardwareKey' => 'xsd:string', 'logXml' => 'xsd:string'),1021 array('version' => 'xsd:string', 'serverKey' => 'xsd:string', 'hardwareKey' => 'xsd:string', 'logXml' => 'xsd:string'),
1003 array('success' => 'xsd:boolean'),1022 array('success' => 'xsd:boolean'),
@@ -1007,7 +1026,7 @@
1007 'encoded',1026 'encoded',
1008 'Submit Logging from the Client'1027 'Submit Logging from the Client'
1009 );1028 );
1010 1029
1011$service->register("SubmitStats",1030$service->register("SubmitStats",
1012 array('version' => 'xsd:string', 'serverKey' => 'xsd:string', 'hardwareKey' => 'xsd:string', 'statXml' => 'xsd:string'),1031 array('version' => 'xsd:string', 'serverKey' => 'xsd:string', 'hardwareKey' => 'xsd:string', 'statXml' => 'xsd:string'),
1013 array('success' => 'xsd:boolean'),1032 array('success' => 'xsd:boolean'),
The diff has been truncated for viewing.

Subscribers

People subscribed via source and target branches