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
1=== added file 'server/install/database/8.sql'
2--- server/install/database/8.sql 1970-01-01 00:00:00 +0000
3+++ server/install/database/8.sql 2009-09-29 22:15:24 +0000
4@@ -0,0 +1,7 @@
5+/* Add the MD5 and FileSize as columns to the media table */
6+ALTER TABLE `media` ADD `MD5` VARCHAR( 32 ) NULL AFTER `storedAs` ,
7+ADD `FileSize` BIGINT NULL AFTER `MD5` ;
8+
9+UPDATE `version` SET `app_ver` = '1.0.4';
10+UPDATE `setting` SET `value` = 0 WHERE `setting` = 'PHONE_HOME_DATE';
11+UPDATE `version` SET `DBVersion` = '8';
12
13=== modified file 'server/modules/flash.module.php'
14--- server/modules/flash.module.php 2009-06-28 10:47:06 +0000
15+++ server/modules/flash.module.php 2009-09-29 22:15:24 +0000
16@@ -8,7 +8,7 @@
17 * Xibo is free software: you can redistribute it and/or modify
18 * it under the terms of the GNU Affero General Public License as published by
19 * the Free Software Foundation, either version 3 of the License, or
20- * any later version.
21+ * any later version.
22 *
23 * Xibo is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25@@ -17,31 +17,31 @@
26 *
27 * You should have received a copy of the GNU Affero General Public License
28 * along with Xibo. If not, see <http://www.gnu.org/licenses/>.
29- */
30+ */
31 class flash extends Module
32 {
33 // Custom Media information
34 private $uri;
35 private $maxFileSize;
36 private $maxFileSizeBytes;
37-
38+
39 public function __construct(database $db, user $user, $mediaid = '', $layoutid = '', $regionid = '')
40 {
41 // Must set the type of the class
42 $this->type = 'flash';
43-
44+
45 // Get the max upload size from PHP
46 $this->maxFileSize = ini_get('upload_max_filesize');
47 $this->maxFileSizeBytes = convertBytes($this->maxFileSize);
48-
49- // Must call the parent class
50+
51+ // Must call the parent class
52 parent::__construct($db, $user, $mediaid, $layoutid, $regionid);
53 }
54-
55+
56 /**
57 * Sets the Layout and Region Information
58 * it will then fill in any blanks it has about this media if it can
59- * @return
60+ * @return
61 * @param $layoutid Object
62 * @param $regionid Object
63 * @param $mediaid Object
64@@ -53,75 +53,75 @@
65 $this->regionid = $regionid;
66 $mediaid = $this->mediaid;
67 $this->existingMedia = false;
68-
69+
70 if ($this->regionSpecific == 1) return;
71-
72+
73 // Load what we know about this media into the object
74 $SQL = "SELECT name, type, duration, originalFilename, userID, permissionID, retired, storedAs, isEdited, editedMediaID FROM media WHERE mediaID = $mediaid ";
75-
76+
77 if (!$result = $db->query($SQL))
78 {
79 trigger_error($db->error()); //log the error
80 return false;
81 }
82-
83+
84 if ($db->num_rows($result) != 1)
85 {
86 trigger_error("More than one row for mediaId [$mediaid] How can this be?");
87 return false;
88 }
89-
90+
91 $row = $db->get_row($result);
92 $duration = $row[2];
93 $storedAs = $row[7];
94-
95+
96 // Required Attributes
97 $this->duration = $duration;
98-
99+
100 // Any Options
101 $this->SetOption('uri', $storedAs);
102-
103+
104 return true;
105 }
106-
107+
108 /**
109 * Return the Add Form as HTML
110- * @return
111+ * @return
112 */
113 public function AddForm()
114 {
115 global $session;
116 $db =& $this->db;
117 $user =& $this->user;
118-
119- // Would like to get the regions width / height
120+
121+ // Would like to get the regions width / height
122 $layoutid = $this->layoutid;
123 $regionid = $this->regionid;
124-
125+
126 // Set the Session / Security information
127 $sessionId = session_id();
128 $securityToken = CreateFormToken();
129-
130+
131 $session->setSecurityToken($securityToken);
132-
133+
134 //Get the default value for the shared list
135 $default = Config::GetSetting($db,"defaultMedia");
136
137 $permissionid = 0;
138
139- if($default=="private")
140+ if($default=="private")
141 {
142 $permissionid = 1;
143 }
144-
145+
146 //shared list
147 $shared_list = dropdownlist("SELECT permissionID, permission FROM permission", "permissionid", $permissionid);
148-
149+
150 //Save button is different depending on if we are on a region or not
151 if ($regionid != "")
152 {
153 setSession('content','mediatype','flash');
154-
155+
156 $save_button = <<<END
157 <input id="btnSave" type="submit" value="Save" disabled />
158 <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" />
159@@ -135,7 +135,7 @@
160 <input class="XiboFormButton" id="btnCancel" type="button" title="Close" href="index.php?p=content&q=displayForms&sp=add" value="Cancel" />
161 END;
162 }
163-
164+
165 $form = <<<FORM
166 <div style="display:none"><iframe name="fileupload" width="1px" height="1px"></iframe></div>
167 <div>
168@@ -144,7 +144,7 @@
169 <input type="hidden" id="SecurityToken" value="$securityToken" />
170 <input type="hidden" name="MAX_FILE_SIZE" value="$this->maxFileSizeBytes" />
171 <table>
172- <tr>
173+ <tr>
174 <td><label for="file">Flash File<span class="required">*</span></label></td>
175 <td colspan="3">
176 <input type="file" name="media_file" onchange="fileFormSubmit();this.form.submit();" />
177@@ -172,7 +172,7 @@
178 <td><label for="permissionid">Sharing<span class="required">*</span></label></td>
179 <td>
180 $shared_list
181- </td>
182+ </td>
183 </tr>
184 <tr>
185 <td></td>
186@@ -194,49 +194,49 @@
187
188 return $this->response;
189 }
190-
191+
192 /**
193 * Return the Edit Form as HTML
194- * @return
195+ * @return
196 */
197 public function EditForm()
198 {
199 global $session;
200 $db =& $this->db;
201 $user =& $this->user;
202-
203- // Would like to get the regions width / height
204+
205+ // Would like to get the regions width / height
206 $layoutid = $this->layoutid;
207 $regionid = $this->regionid;
208 $mediaid = $this->mediaid;
209 $lkid = $this->lkid;
210 $userid = Kit::GetParam('userid', _SESSION, _INT);
211-
212+
213 // Set the Session / Security information
214 $sessionId = session_id();
215 $securityToken = CreateFormToken();
216-
217+
218 $session->setSecurityToken($securityToken);
219-
220+
221 // 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 ";
223-
224+
225 if (!$result = $db->query($SQL))
226 {
227 trigger_error($db->error()); //log the error
228-
229+
230 $this->message = "Error querying for the Media information with media ID [$mediaid] ";
231 return false;
232 }
233-
234+
235 if ($db->num_rows($result) != 1)
236 {
237 trigger_error("More than one row for mediaId [$mediaid] How can this be?");
238-
239+
240 $this->message = "Error querying for the Media information with media ID [$mediaid] ";
241 return false;
242 }
243-
244+
245 $row = $db->get_row($result);
246 $name = $row[0];
247 $originalFilename = $row[1];
248@@ -246,23 +246,23 @@
249 $storedAs = $row[5];
250 $isEdited = $row[6];
251 $editedMediaID = $row[7];
252-
253+
254 // derive the ext
255 $ext = strtolower(substr(strrchr($originalFilename, "."), 1));
256-
257+
258 //Calc the permissions on it aswell
259 list($see_permissions , $edit_permissions) = $user->eval_permission($userid, $permissionid);
260-
261+
262 //shared list
263 $shared_list = dropdownlist("SELECT permissionID, permission FROM permission", "permissionid", $permissionid);
264-
265+
266 //Save button is different depending on if we are on a region or not
267 if ($regionid != "")
268 {
269 setSession('content','mediatype','flash');
270-
271+
272 $extraNotes = '<em>Note: Uploading a new media item here will replace it on this layout only.</em>';
273-
274+
275 $save_button = <<<END
276 <input id="btnSave" type="submit" value="Save" />
277 <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" />
278@@ -272,13 +272,13 @@
279 else
280 {
281 $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>';
282-
283+
284 $save_button = <<<END
285 <input id="btnSave" type="submit" value="Save" />
286 <input id="btnCancel" type="button" title="Close" onclick="$('#div_dialog').dialog('close')" value="Cancel" />
287 END;
288 }
289-
290+
291 $form = <<<FORM
292 <div style="display:none"><iframe name="fileupload" width="1px" height="1px"></iframe></div>
293 <div>
294@@ -287,7 +287,7 @@
295 <input type="hidden" id="SecurityToken" value="$securityToken" />
296 <input type="hidden" name="MAX_FILE_SIZE" value="$this->maxFileSizeBytes" />
297 <table>
298- <tr>
299+ <tr>
300 <td><label for="file">New Flash File<span class="required">*</span></label></td>
301 <td colspan="3">
302 <input type="file" name="media_file" onchange="fileFormSubmit();this.form.submit();" />
303@@ -319,7 +319,7 @@
304 <td><label for="permissionid">Sharing<span class="required">*</span></label></td>
305 <td>
306 $shared_list
307- </td>
308+ </td>
309 </tr>
310 <tr>
311 <td></td>
312@@ -343,50 +343,50 @@
313 $this->response->dialogWidth = '450px';
314 $this->response->dialogHeight = '280px';
315
316- return $this->response;
317+ return $this->response;
318 }
319-
320+
321 /**
322 * Return the Delete Form as HTML
323- * @return
324+ * @return
325 */
326 public function DeleteForm()
327 {
328 $db =& $this->db;
329 $user =& $this->user;
330-
331- // Would like to get the regions width / height
332+
333+ // Would like to get the regions width / height
334 $layoutid = $this->layoutid;
335 $regionid = $this->regionid;
336 $mediaid = $this->mediaid;
337 $lkid = $this->lkid;
338 $userid = Kit::GetParam('userid', _SESSION, _INT);
339-
340+
341 $options = "";
342 //Always have the abilty to unassign from the region
343 $options .= "unassign|Unassign from this region only";
344-
345+
346 // Load what we know about this media into the object
347 $SQL = "SELECT name, type, duration, originalFilename, userID, permissionID, retired, storedAs, isEdited, editedMediaID FROM media WHERE mediaID = $mediaid ";
348-
349+
350 if (!$result = $db->query($SQL))
351 {
352 trigger_error($db->error()); //log the error
353-
354+
355 $this->response->SetError('Error querying for the Media information with media ID [$mediaid]');
356 $this->response->keepOpen = true;
357 return $this->response;
358 }
359-
360+
361 if ($db->num_rows($result) != 1)
362 {
363 trigger_error("More than one row for mediaId [$mediaid] How can this be?");
364-
365+
366 $this->response->SetError('Error querying for the Media information with media ID [$mediaid]');
367 $this->response->keepOpen = true;
368 return $this->response;
369 }
370-
371+
372 $row = $db->get_row($result);
373 $name = $row[0];
374 $duration = $row[2];
375@@ -397,18 +397,18 @@
376 $storedAs = $row[7];
377 $isEdited = $row[8];
378 $editedMediaID = $row[9];
379-
380+
381 // derive the ext
382 $ext = strtolower(substr(strrchr($originalFilename, "."), 1));
383-
384+
385 //Calc the permissions on it aswell
386 list($see_permissions , $edit_permissions) = $user->eval_permission($userid, $permissionid);
387-
388+
389 //Is this user allowed to edit this media?
390 if ($edit_permissions)
391 {
392 $options .= ",retire|Unassign from this region and retire";
393-
394+
395 //Is this media retired?
396 if ($editedMediaID != "")
397 {
398@@ -418,7 +418,7 @@
399 {
400 $revised = false;
401 }
402-
403+
404 //Is this media being used anywhere else?
405 if ($layoutid == "")
406 {
407@@ -429,8 +429,8 @@
408 {
409 $SQL = "SELECT layoutID FROM lklayoutmedia WHERE mediaID = $mediaid AND layoutid <> $layoutid AND regionID <> '$regionid' ";
410 }
411-
412- if (!$results = $db->query($SQL))
413+
414+ if (!$results = $db->query($SQL))
415 {
416 trigger_error($db->error());
417
418@@ -457,9 +457,9 @@
419 return $this->response;
420 }
421 }
422-
423+
424 $options = ltrim($options, ",");
425-
426+
427 $deleteOptions = listcontent($options,"options");
428
429 //we can delete
430@@ -474,19 +474,19 @@
431 <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" />
432 </form>
433 END;
434-
435+
436 $this->response->html = $form;
437 $this->response->dialogTitle = 'Delete Flash';
438 $this->response->dialogSize = true;
439 $this->response->dialogWidth = '450px';
440 $this->response->dialogHeight = '280px';
441
442- return $this->response;
443+ return $this->response;
444 }
445-
446+
447 /**
448 * Add Media to the Database
449- * @return
450+ * @return
451 */
452 public function AddMedia()
453 {
454@@ -495,29 +495,29 @@
455 $regionid = $this->regionid;
456 $mediaid = $this->mediaid;
457 $userid = Kit::GetParam('userid', _SESSION, _INT);
458-
459+
460 // File data
461 $tmpName = Kit::GetParam('hidFileID', _POST, _STRING);
462-
463+
464 if ($tmpName == '')
465 {
466 $this->response->SetError('Cannot save Flash details. <br/> You must have picked a file.');
467 $this->response->keepOpen = true;
468 return $this->response;
469 }
470-
471+
472 // File name and extension (orignial name)
473 $fileName = Kit::GetParam('txtFileName', _POST, _STRING);
474 $fileName = basename($fileName);
475 $ext = strtolower(substr(strrchr($fileName, "."), 1));
476-
477+
478 // Other properties
479 $name = Kit::GetParam('name', _POST, _STRING);
480 $duration = Kit::GetParam('duration', _POST, _INT, 0);
481 $permissionid = Kit::GetParam('permissionid', _POST, _INT, 1);
482-
483+
484 if ($name == '') $name = Kit::ValidateParam($fileName, _FILENAME);
485-
486+
487 // Validation
488 if ($ext != "swf")
489 {
490@@ -525,32 +525,32 @@
491 $this->response->keepOpen = true;
492 return $this->response;
493 }
494-
495+
496 // Make sure the name isnt too long
497- if (strlen($name) > 100)
498+ if (strlen($name) > 100)
499 {
500 $this->response->SetError('The name cannot be longer than 100 characters');
501 $this->response->keepOpen = true;
502 return $this->response;
503 }
504-
505+
506 if ($duration == 0)
507 {
508 $this->response->SetError('You must enter a duration.');
509 $this->response->keepOpen = true;
510 return $this->response;
511 }
512-
513+
514 // Ensure the name is not already in the database
515 $SQL = sprintf("SELECT name FROM media WHERE name = '%s' AND userid = %d", $db->escape_string($name), $userid);
516
517- if(!$result = $db->query($SQL))
518+ if(!$result = $db->query($SQL))
519 {
520 trigger_error($db->error());
521 $this->response->SetError('Error checking whether the media name is ok. Try choosing a different name.');
522 $this->response->keepOpen = true;
523 return $this->response;
524- }
525+ }
526
527 if ($db->num_rows($result) != 0)
528 {
529@@ -558,11 +558,11 @@
530 $this->response->keepOpen = true;
531 return $this->response;
532 }
533-
534+
535 // All OK to insert this record
536 $SQL = "INSERT INTO media (name, type, duration, originalFilename, permissionID, userID, retired ) ";
537 $SQL .= "VALUES ('%s', 'flash', '%s', '%s', %d, %d, 0) ";
538-
539+
540 $SQL = sprintf($SQL, $db->escape_string($name), $db->escape_string($duration), $db->escape_string($fileName), $permissionid, $userid);
541
542 if (!$mediaid = $db->insert_query($SQL))
543@@ -572,19 +572,19 @@
544 $this->response->keepOpen = true;
545 return $this->response;
546 }
547-
548+
549 // File upload directory.. get this from the settings object
550 $databaseDir = Config::GetSetting($db, "LIBRARY_LOCATION");
551-
552+
553 // What are we going to store this media as...
554 $storedAs = $mediaid.".".$ext;
555-
556+
557 // Now we need to move the file
558 if (!$result = rename($databaseDir."temp/".$tmpName, $databaseDir.$storedAs))
559 {
560 // If we couldnt move it - we need to delete the media record we just added
561 $SQL = sprintf("DELETE FROM media WHERE mediaID = %d ", $mediaid);
562-
563+
564 if (!$db->query($SQL))
565 {
566 trigger_error($db->error());
567@@ -593,23 +593,27 @@
568 return $this->response;
569 }
570 }
571-
572+
573+ // Calculate the MD5 and the file size
574+ $md5 = md5_file($databaseDir.$storedAs);
575+ $fileSize = filesize($databaseDir.$storedAs);
576+
577 // Update the media record to include this information
578- $SQL = sprintf("UPDATE media SET storedAs = '%s' WHERE mediaid = %d", $storedAs, $mediaid);
579-
580+ $SQL = sprintf("UPDATE media SET storedAs = '%s', `MD5` = '%s', FileSize = %d WHERE mediaid = %d", $storedAs, $md5, $fileSize, $mediaid);
581+
582 if (!$db->query($SQL))
583 {
584 trigger_error($db->error());
585 return true;
586 }
587-
588+
589 // Required Attributes
590 $this->mediaid = $mediaid;
591 $this->duration = $duration;
592-
593+
594 // Any Options
595 $this->SetOption('uri', $storedAs);
596-
597+
598 // Should have built the media object entirely by this time
599 if ($regionid != '')
600 {
601@@ -619,18 +623,18 @@
602 }
603 else
604 {
605- $this->response->loadFormUri = "index.php?p=content&q=displayForms&sp=add";
606+ $this->response->loadFormUri = "index.php?p=content&q=displayForms&sp=add";
607 }
608-
609+
610 // We want to load a new form
611 $this->response->loadForm = true;
612-
613+
614 return $this->response;
615 }
616-
617+
618 /**
619 * Edit Media in the Database
620- * @return
621+ * @return
622 */
623 public function EditMedia()
624 {
625@@ -639,13 +643,13 @@
626 $regionid = $this->regionid;
627 $mediaid = $this->mediaid;
628 $userid = Kit::GetParam('userid', _SESSION, _INT);
629-
630+
631 // Stored As from the XML
632 $storedAs = $this->GetOption('uri');
633-
634+
635 // File data
636 $tmpName = Kit::GetParam('hidFileID', _POST, _STRING);
637-
638+
639 if ($tmpName == '')
640 {
641 $fileRevision = false;
642@@ -653,12 +657,12 @@
643 else
644 {
645 $fileRevision = true;
646-
647+
648 // File name and extension (orignial name)
649 $fileName = Kit::GetParam('txtFileName', _POST, _STRING);
650 $fileName = basename($fileName);
651 $ext = strtolower(substr(strrchr($fileName, "."), 1));
652-
653+
654 if ($ext != "swf")
655 {
656 $this->response->SetError('Only SWF files are accepted - Are you sure this is an flash?');
657@@ -666,17 +670,17 @@
658 return $this->response;
659 }
660 }
661-
662+
663 // Other properties
664 $name = Kit::GetParam('name', _POST, _STRING);
665 $duration = Kit::GetParam('duration', _POST, _INT, 0);
666 $permissionid = Kit::GetParam('permissionid', _POST, _INT, 1);
667-
668+
669 if ($name == '')
670 {
671 if ($fileRevision)
672 {
673- $name = Kit::ValidateParam($fileName, _FILENAME);
674+ $name = Kit::ValidateParam($fileName, _FILENAME);
675 }
676 else
677 {
678@@ -684,33 +688,33 @@
679 $this->response->keepOpen = true;
680 return $this->response;
681 }
682- }
683-
684+ }
685+
686 // Make sure the name isnt too long
687- if (strlen($name) > 100)
688+ if (strlen($name) > 100)
689 {
690 $this->response->SetError('The name cannot be longer than 100 characters');
691 $this->response->keepOpen = true;
692 return $this->response;
693 }
694-
695+
696 if ($duration == 0)
697 {
698 $this->response->SetError('You must enter a duration.');
699 $this->response->keepOpen = true;
700 return $this->response;
701 }
702-
703+
704 // 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);
706
707- if(!$result = $db->query($SQL))
708+ if(!$result = $db->query($SQL))
709 {
710 trigger_error($db->error());
711 $this->response->SetError('Error checking whether the media name is ok. Try choosing a different name.');
712 $this->response->keepOpen = true;
713 return $this->response;
714- }
715+ }
716
717 if ($db->num_rows($result) != 0)
718 {
719@@ -718,34 +722,34 @@
720 $this->response->keepOpen = true;
721 return $this->response;
722 }
723-
724+
725 //Are we revising this media - or just plain editing
726 if ($fileRevision)
727 {
728 // All OK to insert this record
729 $SQL = "INSERT INTO media (name, type, duration, originalFilename, permissionID, userID, retired ) ";
730 $SQL .= "VALUES ('%s', '%s', '%s', '%s', %d, %d, 0) ";
731-
732+
733 $SQL = sprintf($SQL, $db->escape_string($name), $this->type, $db->escape_string($duration), $db->escape_string($fileName), $permissionid, $userid);
734-
735+
736 if (!$new_mediaid = $db->insert_query($SQL))
737 {
738 trigger_error($db->error());
739 trigger_error('Error inserting replacement media record.', E_USER_ERROR);
740 }
741-
742+
743 //What are we going to store this media as...
744 $storedAs = $new_mediaid.".".$ext;
745-
746+
747 // File upload directory.. get this from the settings object
748 $databaseDir = Config::GetSetting($db, "LIBRARY_LOCATION");
749-
750+
751 //Now we need to move the file
752 if (!$result = rename($databaseDir."/temp/".$tmpName, $databaseDir.$storedAs))
753 {
754 //If we couldnt move it - we need to delete the media record we just added
755 $SQL = "DELETE FROM media WHERE mediaID = $new_mediaid ";
756-
757+
758 if (!$db->insert_query($SQL))
759 {
760 $this->response->SetError('Error rolling back transcation.');
761@@ -753,9 +757,14 @@
762 return $this->response;
763 }
764 }
765-
766- //Update the media record to include this information
767- $SQL = "UPDATE media SET storedAs = '$storedAs' WHERE mediaid = $new_mediaid";
768+
769+ // Calculate the MD5 and the file size
770+ $md5 = md5_file($databaseDir.$storedAs);
771+ $fileSize = filesize($databaseDir.$storedAs);
772+
773+ // Update the media record to include this information
774+ $SQL = sprintf("UPDATE media SET storedAs = '%s', `MD5` = '%s', FileSize = %d WHERE mediaid = %d", $storedAs, $md5, $fileSize, $new_mediaid);
775+
776 if (!$db->query($SQL))
777 {
778 trigger_error($db->error());
779@@ -763,13 +772,13 @@
780 $this->response->keepOpen = true;
781 return $this->response;
782 }
783-
784+
785 // Update the existing record with the new record's id
786 $SQL = "UPDATE media SET isEdited = 1, editedMediaID = $new_mediaid ";
787 $SQL .= " WHERE IFNULL(editedMediaID,0) <> $new_mediaid AND mediaID = $mediaid ";
788-
789+
790 Debug::LogEntry($db, 'audit', $SQL);
791-
792+
793 if (!$db->query($SQL))
794 {
795 trigger_error($db->error());
796@@ -783,54 +792,54 @@
797 {
798 // Editing the existing record
799 $new_mediaid = $mediaid;
800-
801+
802 $SQL = "UPDATE media SET name = '%s', duration = %d, permissionID = %d";
803 $SQL .= " WHERE mediaID = %d ";
804 $SQL = sprintf($SQL, $db->escape_string($name), $duration, $permissionid, $mediaid);
805-
806+
807 Debug::LogEntry($db, 'audit', $SQL);
808-
809+
810 if (!$db->query($SQL))
811 {
812 trigger_error($db->error());
813-
814+
815 $this->response->SetError('Database error editing this media record.');
816 $this->response->keepOpen = true;
817 return $this->response;
818 }
819 }
820-
821+
822 // Required Attributes
823 $this->mediaid = $new_mediaid;
824 $this->duration = $duration;
825-
826+
827 // Any Options
828 $this->SetOption('uri', $storedAs);
829-
830+
831 // Should have built the media object entirely by this time
832 if ($regionid != '')
833 {
834 // This saves the Media Object to the Region
835 $this->UpdateRegion();
836-
837+
838 $this->response->loadForm = true;
839 $this->response->loadFormUri = "index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions";;
840 }
841 else
842 {
843- $this->response->loadFormUri = "index.php?p=content&q=displayForms&sp=add";
844+ $this->response->loadFormUri = "index.php?p=content&q=displayForms&sp=add";
845 $this->response->message = 'Edited the Flash.';
846-
847+
848 }
849-
850+
851 return $this->response;
852 }
853-
854+
855 /**
856 * Delete Media from the Database
857- * @return
858+ * @return
859 */
860- public function DeleteMedia()
861+ public function DeleteMedia()
862 {
863 $db =& $this->db;
864 $layoutid = $this->layoutid;
865@@ -838,10 +847,10 @@
866 $mediaid = $this->mediaid;
867 $userid = Kit::GetParam('userid', _SESSION, _INT);
868 $options = Kit::GetParam('options', _POST, _WORD);
869-
870+
871 // Stored As from the XML
872 $this->uri = $this->GetOption('uri');
873-
874+
875 // Do we need to remove this from a layout?
876 if ($layoutid != '')
877 {
878@@ -853,72 +862,72 @@
879 // Set this message now in preparation
880 $this->response->message = 'Deleted the Media.';
881 }
882-
883+
884 // If we are set to retire we retire
885 if ($options == "retire")
886 {
887 //Update the media record to say it is retired
888 $SQL = "UPDATE media SET retired = 1 WHERE mediaid = $mediaid ";
889-
890+
891 if (!$db->query($SQL))
892 {
893 trigger_error($db->error());
894-
895+
896 $this->response->SetError('Database error retiring this media record.');
897 $this->response->keepOpen = true;
898 return $this->response;
899 }
900 }
901-
902+
903 //If we are set to delete, we delete
904 if ($options == "delete")
905 {
906 //Update the media record to say it is retired
907 $SQL = "DELETE FROM media WHERE mediaid = $mediaid ";
908-
909+
910 if (!$db->query($SQL))
911 {
912 trigger_error($db->error());
913-
914+
915 $this->response->SetError('Database error deleting this media record.');
916 $this->response->keepOpen = true;
917 return $this->response;
918 }
919-
920+
921 $this->DeleteMediaFiles();
922 }
923
924 return $this->response;
925 }
926-
927+
928 /**
929 * Deletes the media files associated with this record
930- * @return
931+ * @return
932 */
933 private function DeleteMediaFiles()
934 {
935 $db =& $this->db;
936-
937+
938 //Library location
939 $databaseDir = Config::GetSetting($db, "LIBRARY_LOCATION");
940-
941+
942 //3 things to check for..
943 //the actual file, the thumbnail, the background
944 if (file_exists($databaseDir.$this->uri))
945 {
946 unlink($databaseDir.$this->uri);
947 }
948-
949+
950 if (file_exists($databaseDir."tn_".$this->uri))
951 {
952 unlink($databaseDir."tn_".$this->uri);
953 }
954-
955+
956 if (file_exists($databaseDir."bg_".$this->uri))
957 {
958 unlink($databaseDir."bg_".$this->uri);
959 }
960-
961+
962 return true;
963 }
964 }
965
966=== modified file 'server/modules/image.module.php'
967--- server/modules/image.module.php 2009-06-28 10:47:06 +0000
968+++ server/modules/image.module.php 2009-09-29 22:15:24 +0000
969@@ -8,7 +8,7 @@
970 * Xibo is free software: you can redistribute it and/or modify
971 * it under the terms of the GNU Affero General Public License as published by
972 * the Free Software Foundation, either version 3 of the License, or
973- * any later version.
974+ * any later version.
975 *
976 * Xibo is distributed in the hope that it will be useful,
977 * but WITHOUT ANY WARRANTY; without even the implied warranty of
978@@ -17,31 +17,31 @@
979 *
980 * You should have received a copy of the GNU Affero General Public License
981 * along with Xibo. If not, see <http://www.gnu.org/licenses/>.
982- */
983+ */
984 class image extends Module
985 {
986 // Custom Media information
987 private $uri;
988 private $maxFileSize;
989 private $maxFileSizeBytes;
990-
991+
992 public function __construct(database $db, user $user, $mediaid = '', $layoutid = '', $regionid = '')
993 {
994 // Must set the type of the class
995 $this->type = 'image';
996-
997+
998 // Get the max upload size from PHP
999 $this->maxFileSize = ini_get('upload_max_filesize');
1000 $this->maxFileSizeBytes = convertBytes($this->maxFileSize);
1001-
1002- // Must call the parent class
1003+
1004+ // Must call the parent class
1005 parent::__construct($db, $user, $mediaid, $layoutid, $regionid);
1006 }
1007-
1008+
1009 /**
1010 * Sets the Layout and Region Information
1011 * it will then fill in any blanks it has about this media if it can
1012- * @return
1013+ * @return
1014 * @param $layoutid Object
1015 * @param $regionid Object
1016 * @param $mediaid Object
1017@@ -53,75 +53,75 @@
1018 $this->regionid = $regionid;
1019 $mediaid = $this->mediaid;
1020 $this->existingMedia = false;
1021-
1022+
1023 if ($this->regionSpecific == 1) return;
1024-
1025+
1026 // Load what we know about this media into the object
1027 $SQL = "SELECT name, type, duration, originalFilename, userID, permissionID, retired, storedAs, isEdited, editedMediaID FROM media WHERE mediaID = $mediaid ";
1028-
1029+
1030 if (!$result = $db->query($SQL))
1031 {
1032 trigger_error($db->error()); //log the error
1033 return false;
1034 }
1035-
1036+
1037 if ($db->num_rows($result) != 1)
1038 {
1039 trigger_error("More than one row for mediaId [$mediaid] How can this be?");
1040 return false;
1041 }
1042-
1043+
1044 $row = $db->get_row($result);
1045 $duration = $row[2];
1046 $storedAs = $row[7];
1047-
1048+
1049 // Required Attributes
1050 $this->duration = $duration;
1051-
1052+
1053 // Any Options
1054 $this->SetOption('uri', $storedAs);
1055-
1056+
1057 return true;
1058 }
1059-
1060+
1061 /**
1062 * Return the Add Form as HTML
1063- * @return
1064+ * @return
1065 */
1066 public function AddForm()
1067 {
1068 global $session;
1069 $db =& $this->db;
1070 $user =& $this->user;
1071-
1072- // Would like to get the regions width / height
1073+
1074+ // Would like to get the regions width / height
1075 $layoutid = $this->layoutid;
1076 $regionid = $this->regionid;
1077-
1078+
1079 // Set the Session / Security information
1080 $sessionId = session_id();
1081 $securityToken = CreateFormToken();
1082-
1083+
1084 $session->setSecurityToken($securityToken);
1085-
1086+
1087 //Get the default value for the shared list
1088 $default = Config::GetSetting($db,"defaultMedia");
1089
1090 $permissionid = 0;
1091
1092- if($default=="private")
1093+ if($default=="private")
1094 {
1095 $permissionid = 1;
1096 }
1097-
1098+
1099 //shared list
1100 $shared_list = dropdownlist("SELECT permissionID, permission FROM permission", "permissionid", $permissionid);
1101-
1102+
1103 //Save button is different depending on if we are on a region or not
1104 if ($regionid != "")
1105 {
1106 setSession('content','mediatype','image');
1107-
1108+
1109 $save_button = <<<END
1110 <input id="btnSave" type="submit" value="Save" disabled />
1111 <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" />
1112@@ -135,7 +135,7 @@
1113 <input class="XiboFormButton" id="btnCancel" type="button" title="Close" href="index.php?p=content&q=displayForms&sp=add" value="Cancel" />
1114 END;
1115 }
1116-
1117+
1118 $form = <<<FORM
1119 <div style="display:none"><iframe name="fileupload" width="1px" height="1px"></iframe></div>
1120 <div>
1121@@ -144,7 +144,7 @@
1122 <input type="hidden" id="SecurityToken" value="$securityToken" />
1123 <input type="hidden" name="MAX_FILE_SIZE" value="$this->maxFileSizeBytes" />
1124 <table>
1125- <tr>
1126+ <tr>
1127 <td><label for="file">Image File<span class="required">*</span></label></td>
1128 <td colspan="3">
1129 <input type="file" name="media_file" onchange="fileFormSubmit();this.form.submit();" />
1130@@ -172,7 +172,7 @@
1131 <td><label for="permissionid">Sharing<span class="required">*</span></label></td>
1132 <td>
1133 $shared_list
1134- </td>
1135+ </td>
1136 </tr>
1137 <tr>
1138 <td></td>
1139@@ -194,49 +194,49 @@
1140
1141 return $this->response;
1142 }
1143-
1144+
1145 /**
1146 * Return the Edit Form as HTML
1147- * @return
1148+ * @return
1149 */
1150 public function EditForm()
1151 {
1152 global $session;
1153 $db =& $this->db;
1154 $user =& $this->user;
1155-
1156- // Would like to get the regions width / height
1157+
1158+ // Would like to get the regions width / height
1159 $layoutid = $this->layoutid;
1160 $regionid = $this->regionid;
1161 $mediaid = $this->mediaid;
1162 $lkid = $this->lkid;
1163 $userid = Kit::GetParam('userid', _SESSION, _INT);
1164-
1165+
1166 // Set the Session / Security information
1167 $sessionId = session_id();
1168 $securityToken = CreateFormToken();
1169-
1170+
1171 $session->setSecurityToken($securityToken);
1172-
1173+
1174 // Load what we know about this media into the object
1175 $SQL = "SELECT name, originalFilename, userID, permissionID, retired, storedAs, isEdited, editedMediaID FROM media WHERE mediaID = $mediaid ";
1176-
1177+
1178 if (!$result = $db->query($SQL))
1179 {
1180 trigger_error($db->error()); //log the error
1181-
1182+
1183 $this->message = "Error querying for the Media information with media ID [$mediaid] ";
1184 return false;
1185 }
1186-
1187+
1188 if ($db->num_rows($result) != 1)
1189 {
1190 trigger_error("More than one row for mediaId [$mediaid] How can this be?");
1191-
1192+
1193 $this->message = "Error querying for the Media information with media ID [$mediaid] ";
1194 return false;
1195 }
1196-
1197+
1198 $row = $db->get_row($result);
1199 $name = $row[0];
1200 $originalFilename = $row[1];
1201@@ -246,23 +246,23 @@
1202 $storedAs = $row[5];
1203 $isEdited = $row[6];
1204 $editedMediaID = $row[7];
1205-
1206+
1207 // derive the ext
1208 $ext = strtolower(substr(strrchr($originalFilename, "."), 1));
1209-
1210+
1211 //Calc the permissions on it aswell
1212 list($see_permissions , $edit_permissions) = $user->eval_permission($userid, $permissionid);
1213-
1214+
1215 //shared list
1216 $shared_list = dropdownlist("SELECT permissionID, permission FROM permission", "permissionid", $permissionid);
1217-
1218+
1219 //Save button is different depending on if we are on a region or not
1220 if ($regionid != "")
1221 {
1222 setSession('content','mediatype','image');
1223-
1224+
1225 $extraNotes = '<em>Note: Uploading a new media item here will replace it on this layout only.</em>';
1226-
1227+
1228 $save_button = <<<END
1229 <input id="btnSave" type="submit" value="Save" />
1230 <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" />
1231@@ -272,13 +272,13 @@
1232 else
1233 {
1234 $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>';
1235-
1236+
1237 $save_button = <<<END
1238 <input id="btnSave" type="submit" value="Save" />
1239 <input id="btnCancel" type="button" title="Close" onclick="$('#div_dialog').dialog('close')" value="Cancel" />
1240 END;
1241 }
1242-
1243+
1244 $form = <<<FORM
1245 <div style="display:none"><iframe name="fileupload" width="1px" height="1px"></iframe></div>
1246 <div>
1247@@ -287,7 +287,7 @@
1248 <input type="hidden" id="SecurityToken" value="$securityToken" />
1249 <input type="hidden" name="MAX_FILE_SIZE" value="$this->maxFileSizeBytes" />
1250 <table>
1251- <tr>
1252+ <tr>
1253 <td><label for="file">New Image File<span class="required">*</span></label></td>
1254 <td colspan="3">
1255 <input type="file" name="media_file" onchange="fileFormSubmit();this.form.submit();" />
1256@@ -319,7 +319,7 @@
1257 <td><label for="permissionid">Sharing<span class="required">*</span></label></td>
1258 <td>
1259 $shared_list
1260- </td>
1261+ </td>
1262 </tr>
1263 <tr>
1264 <td></td>
1265@@ -343,50 +343,50 @@
1266 $this->response->dialogWidth = '450px';
1267 $this->response->dialogHeight = '280px';
1268
1269- return $this->response;
1270+ return $this->response;
1271 }
1272-
1273+
1274 /**
1275 * Return the Delete Form as HTML
1276- * @return
1277+ * @return
1278 */
1279 public function DeleteForm()
1280 {
1281 $db =& $this->db;
1282 $user =& $this->user;
1283-
1284- // Would like to get the regions width / height
1285+
1286+ // Would like to get the regions width / height
1287 $layoutid = $this->layoutid;
1288 $regionid = $this->regionid;
1289 $mediaid = $this->mediaid;
1290 $lkid = $this->lkid;
1291 $userid = Kit::GetParam('userid', _SESSION, _INT);
1292-
1293+
1294 $options = "";
1295 //Always have the abilty to unassign from the region
1296 $options .= "unassign|Unassign from this region only";
1297-
1298+
1299 // Load what we know about this media into the object
1300 $SQL = "SELECT name, type, duration, originalFilename, userID, permissionID, retired, storedAs, isEdited, editedMediaID FROM media WHERE mediaID = $mediaid ";
1301-
1302+
1303 if (!$result = $db->query($SQL))
1304 {
1305 trigger_error($db->error()); //log the error
1306-
1307+
1308 $this->response->SetError('Error querying for the Media information with media ID [$mediaid]');
1309 $this->response->keepOpen = true;
1310 return $this->response;
1311 }
1312-
1313+
1314 if ($db->num_rows($result) != 1)
1315 {
1316 trigger_error("More than one row for mediaId [$mediaid] How can this be?");
1317-
1318+
1319 $this->response->SetError('Error querying for the Media information with media ID [$mediaid]');
1320 $this->response->keepOpen = true;
1321 return $this->response;
1322 }
1323-
1324+
1325 $row = $db->get_row($result);
1326 $name = $row[0];
1327 $duration = $row[2];
1328@@ -397,18 +397,18 @@
1329 $storedAs = $row[7];
1330 $isEdited = $row[8];
1331 $editedMediaID = $row[9];
1332-
1333+
1334 // derive the ext
1335 $ext = strtolower(substr(strrchr($originalFilename, "."), 1));
1336-
1337+
1338 //Calc the permissions on it aswell
1339 list($see_permissions , $edit_permissions) = $user->eval_permission($userid, $permissionid);
1340-
1341+
1342 //Is this user allowed to edit this media?
1343 if ($edit_permissions)
1344 {
1345 $options .= ",retire|Unassign from this region and retire";
1346-
1347+
1348 //Is this media retired?
1349 if ($editedMediaID != "")
1350 {
1351@@ -418,7 +418,7 @@
1352 {
1353 $revised = false;
1354 }
1355-
1356+
1357 //Is this media being used anywhere else?
1358 if ($layoutid == "")
1359 {
1360@@ -429,8 +429,8 @@
1361 {
1362 $SQL = "SELECT layoutID FROM lklayoutmedia WHERE mediaID = $mediaid AND layoutid <> $layoutid AND regionID <> '$regionid' ";
1363 }
1364-
1365- if (!$results = $db->query($SQL))
1366+
1367+ if (!$results = $db->query($SQL))
1368 {
1369 trigger_error($db->error());
1370
1371@@ -457,9 +457,9 @@
1372 return $this->response;
1373 }
1374 }
1375-
1376+
1377 $options = ltrim($options, ",");
1378-
1379+
1380 $deleteOptions = listcontent($options,"options");
1381
1382 //we can delete
1383@@ -474,19 +474,19 @@
1384 <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" />
1385 </form>
1386 END;
1387-
1388+
1389 $this->response->html = $form;
1390 $this->response->dialogTitle = 'Delete Image';
1391 $this->response->dialogSize = true;
1392 $this->response->dialogWidth = '450px';
1393 $this->response->dialogHeight = '280px';
1394
1395- return $this->response;
1396+ return $this->response;
1397 }
1398-
1399+
1400 /**
1401 * Add Media to the Database
1402- * @return
1403+ * @return
1404 */
1405 public function AddMedia()
1406 {
1407@@ -495,29 +495,29 @@
1408 $regionid = $this->regionid;
1409 $mediaid = $this->mediaid;
1410 $userid = Kit::GetParam('userid', _SESSION, _INT);
1411-
1412+
1413 // File data
1414 $tmpName = Kit::GetParam('hidFileID', _POST, _STRING);
1415-
1416+
1417 if ($tmpName == '')
1418 {
1419 $this->response->SetError('Cannot save Image details. <br/> You must have picked a file.');
1420 $this->response->keepOpen = true;
1421 return $this->response;
1422 }
1423-
1424+
1425 // File name and extension (orignial name)
1426 $fileName = Kit::GetParam('txtFileName', _POST, _STRING);
1427 $fileName = basename($fileName);
1428 $ext = strtolower(substr(strrchr($fileName, "."), 1));
1429-
1430+
1431 // Other properties
1432 $name = Kit::GetParam('name', _POST, _STRING);
1433 $duration = Kit::GetParam('duration', _POST, _INT, 0);
1434 $permissionid = Kit::GetParam('permissionid', _POST, _INT, 1);
1435-
1436+
1437 if ($name == '') $name = Kit::ValidateParam($fileName, _FILENAME);
1438-
1439+
1440 // Validation
1441 if ($ext != "jpeg" && $ext != "jpg" && $ext != "png" && $ext != "gif")
1442 {
1443@@ -525,32 +525,32 @@
1444 $this->response->keepOpen = true;
1445 return $this->response;
1446 }
1447-
1448+
1449 // Make sure the name isnt too long
1450- if (strlen($name) > 100)
1451+ if (strlen($name) > 100)
1452 {
1453 $this->response->SetError('The name cannot be longer than 100 characters');
1454 $this->response->keepOpen = true;
1455 return $this->response;
1456 }
1457-
1458+
1459 if ($duration == 0)
1460 {
1461 $this->response->SetError('You must enter a duration.');
1462 $this->response->keepOpen = true;
1463 return $this->response;
1464 }
1465-
1466+
1467 // Ensure the name is not already in the database
1468 $SQL = sprintf("SELECT name FROM media WHERE name = '%s' AND userid = %d", $db->escape_string($name), $userid);
1469
1470- if(!$result = $db->query($SQL))
1471+ if(!$result = $db->query($SQL))
1472 {
1473 trigger_error($db->error());
1474 $this->response->SetError('Error checking whether the media name is ok. Try choosing a different name.');
1475 $this->response->keepOpen = true;
1476 return $this->response;
1477- }
1478+ }
1479
1480 if ($db->num_rows($result) != 0)
1481 {
1482@@ -558,11 +558,11 @@
1483 $this->response->keepOpen = true;
1484 return $this->response;
1485 }
1486-
1487+
1488 // All OK to insert this record
1489 $SQL = "INSERT INTO media (name, type, duration, originalFilename, permissionID, userID, retired ) ";
1490 $SQL .= "VALUES ('%s', 'image', '%s', '%s', %d, %d, 0) ";
1491-
1492+
1493 $SQL = sprintf($SQL, $db->escape_string($name), $db->escape_string($duration), $db->escape_string($fileName), $permissionid, $userid);
1494
1495 if (!$mediaid = $db->insert_query($SQL))
1496@@ -572,19 +572,19 @@
1497 $this->response->keepOpen = true;
1498 return $this->response;
1499 }
1500-
1501+
1502 // File upload directory.. get this from the settings object
1503 $databaseDir = Config::GetSetting($db, "LIBRARY_LOCATION");
1504-
1505+
1506 // What are we going to store this media as...
1507 $storedAs = $mediaid.".".$ext;
1508-
1509+
1510 // Now we need to move the file
1511 if (!$result = rename($databaseDir."temp/".$tmpName, $databaseDir.$storedAs))
1512 {
1513 // If we couldnt move it - we need to delete the media record we just added
1514 $SQL = sprintf("DELETE FROM media WHERE mediaID = %d ", $mediaid);
1515-
1516+
1517 if (!$db->query($SQL))
1518 {
1519 trigger_error($db->error());
1520@@ -593,26 +593,30 @@
1521 return $this->response;
1522 }
1523 }
1524-
1525+
1526+ // Calculate the MD5 and the file size
1527+ $md5 = md5_file($databaseDir.$storedAs);
1528+ $fileSize = filesize($databaseDir.$storedAs);
1529+
1530 // Update the media record to include this information
1531- $SQL = sprintf("UPDATE media SET storedAs = '%s' WHERE mediaid = %d", $storedAs, $mediaid);
1532-
1533+ $SQL = sprintf("UPDATE media SET storedAs = '%s', `MD5` = '%s', FileSize = %d WHERE mediaid = %d", $storedAs, $md5, $fileSize, $mediaid);
1534+
1535 if (!$db->query($SQL))
1536 {
1537 trigger_error($db->error());
1538 return true;
1539 }
1540-
1541+
1542 // Create the thumb nail
1543 ResizeImage($databaseDir.$storedAs, $databaseDir."tn_".$storedAs, 80, 80);
1544-
1545+
1546 // Required Attributes
1547 $this->mediaid = $mediaid;
1548 $this->duration = $duration;
1549-
1550+
1551 // Any Options
1552 $this->SetOption('uri', $storedAs);
1553-
1554+
1555 // Should have built the media object entirely by this time
1556 if ($regionid != '')
1557 {
1558@@ -622,18 +626,18 @@
1559 }
1560 else
1561 {
1562- $this->response->loadFormUri = "index.php?p=content&q=displayForms&sp=add";
1563+ $this->response->loadFormUri = "index.php?p=content&q=displayForms&sp=add";
1564 }
1565-
1566+
1567 // We want to load a new form
1568 $this->response->loadForm = true;
1569-
1570+
1571 return $this->response;
1572 }
1573-
1574+
1575 /**
1576 * Edit Media in the Database
1577- * @return
1578+ * @return
1579 */
1580 public function EditMedia()
1581 {
1582@@ -642,13 +646,13 @@
1583 $regionid = $this->regionid;
1584 $mediaid = $this->mediaid;
1585 $userid = Kit::GetParam('userid', _SESSION, _INT);
1586-
1587+
1588 // Stored As from the XML
1589 $storedAs = $this->GetOption('uri');
1590-
1591+
1592 // File data
1593 $tmpName = Kit::GetParam('hidFileID', _POST, _STRING);
1594-
1595+
1596 if ($tmpName == '')
1597 {
1598 $fileRevision = false;
1599@@ -656,12 +660,12 @@
1600 else
1601 {
1602 $fileRevision = true;
1603-
1604+
1605 // File name and extension (orignial name)
1606 $fileName = Kit::GetParam('txtFileName', _POST, _STRING);
1607 $fileName = basename($fileName);
1608 $ext = strtolower(substr(strrchr($fileName, "."), 1));
1609-
1610+
1611 if ($ext != "jpeg" && $ext != "jpg" && $ext != "png" && $ext != "gif")
1612 {
1613 $this->response->SetError('Only images are accepted - Are you sure this is an image?');
1614@@ -669,17 +673,17 @@
1615 return $this->response;
1616 }
1617 }
1618-
1619+
1620 // Other properties
1621 $name = Kit::GetParam('name', _POST, _STRING);
1622 $duration = Kit::GetParam('duration', _POST, _INT, 0);
1623 $permissionid = Kit::GetParam('permissionid', _POST, _INT, 1);
1624-
1625+
1626 if ($name == '')
1627 {
1628 if ($fileRevision)
1629 {
1630- $name = Kit::ValidateParam($fileName, _FILENAME);
1631+ $name = Kit::ValidateParam($fileName, _FILENAME);
1632 }
1633 else
1634 {
1635@@ -687,33 +691,33 @@
1636 $this->response->keepOpen = true;
1637 return $this->response;
1638 }
1639- }
1640-
1641+ }
1642+
1643 // Make sure the name isnt too long
1644- if (strlen($name) > 100)
1645+ if (strlen($name) > 100)
1646 {
1647 $this->response->SetError('The name cannot be longer than 100 characters');
1648 $this->response->keepOpen = true;
1649 return $this->response;
1650 }
1651-
1652+
1653 if ($duration == 0)
1654 {
1655 $this->response->SetError('You must enter a duration.');
1656 $this->response->keepOpen = true;
1657 return $this->response;
1658 }
1659-
1660+
1661 // Ensure the name is not already in the database
1662 $SQL = sprintf("SELECT name FROM media WHERE name = '%s' AND userid = %d AND mediaid <> %d ", $db->escape_string($name), $userid, $mediaid);
1663
1664- if(!$result = $db->query($SQL))
1665+ if(!$result = $db->query($SQL))
1666 {
1667 trigger_error($db->error());
1668 $this->response->SetError('Error checking whether the media name is ok. Try choosing a different name.');
1669 $this->response->keepOpen = true;
1670 return $this->response;
1671- }
1672+ }
1673
1674 if ($db->num_rows($result) != 0)
1675 {
1676@@ -721,34 +725,34 @@
1677 $this->response->keepOpen = true;
1678 return $this->response;
1679 }
1680-
1681+
1682 //Are we revising this media - or just plain editing
1683 if ($fileRevision)
1684 {
1685 // All OK to insert this record
1686 $SQL = "INSERT INTO media (name, type, duration, originalFilename, permissionID, userID, retired ) ";
1687 $SQL .= "VALUES ('%s', 'image', '%s', '%s', %d, %d, 0) ";
1688-
1689+
1690 $SQL = sprintf($SQL, $db->escape_string($name), $db->escape_string($duration), $db->escape_string($fileName), $permissionid, $userid);
1691-
1692+
1693 if (!$new_mediaid = $db->insert_query($SQL))
1694 {
1695 trigger_error($db->error());
1696 trigger_error('Error inserting replacement media record.', E_USER_ERROR);
1697 }
1698-
1699+
1700 //What are we going to store this media as...
1701 $storedAs = $new_mediaid.".".$ext;
1702-
1703+
1704 // File upload directory.. get this from the settings object
1705 $databaseDir = Config::GetSetting($db, "LIBRARY_LOCATION");
1706-
1707+
1708 //Now we need to move the file
1709 if (!$result = rename($databaseDir."/temp/".$tmpName, $databaseDir.$storedAs))
1710 {
1711 //If we couldnt move it - we need to delete the media record we just added
1712 $SQL = "DELETE FROM media WHERE mediaID = $new_mediaid ";
1713-
1714+
1715 if (!$db->insert_query($SQL))
1716 {
1717 $this->response->SetError('Error rolling back transcation.');
1718@@ -756,9 +760,14 @@
1719 return $this->response;
1720 }
1721 }
1722-
1723- //Update the media record to include this information
1724- $SQL = "UPDATE media SET storedAs = '$storedAs' WHERE mediaid = $new_mediaid";
1725+
1726+ // Calculate the MD5 and the file size
1727+ $md5 = md5_file($databaseDir.$storedAs);
1728+ $fileSize = filesize($databaseDir.$storedAs);
1729+
1730+ // Update the media record to include this information
1731+ $SQL = sprintf("UPDATE media SET storedAs = '%s', `MD5` = '%s', FileSize = %d WHERE mediaid = %d", $storedAs, $md5, $fileSize, $new_mediaid);
1732+
1733 if (!$db->query($SQL))
1734 {
1735 trigger_error($db->error());
1736@@ -766,20 +775,20 @@
1737 $this->response->keepOpen = true;
1738 return $this->response;
1739 }
1740-
1741+
1742 //Thumb
1743 if ($ext == "jpeg" || $ext == "jpg" || $ext == "png")
1744 {
1745 //Create the thumbnail
1746 ResizeImage($databaseDir.$storedAs, $databaseDir."tn_".$storedAs, 80, 80);
1747 }
1748-
1749+
1750 // Update the existing record with the new record's id
1751 $SQL = "UPDATE media SET isEdited = 1, editedMediaID = $new_mediaid ";
1752 $SQL .= " WHERE IFNULL(editedMediaID,0) <> $new_mediaid AND mediaID = $mediaid ";
1753-
1754+
1755 Debug::LogEntry($db, 'audit', $SQL);
1756-
1757+
1758 if (!$db->query($SQL))
1759 {
1760 trigger_error($db->error());
1761@@ -793,54 +802,54 @@
1762 {
1763 // Editing the existing record
1764 $new_mediaid = $mediaid;
1765-
1766+
1767 $SQL = "UPDATE media SET name = '%s', duration = %d, permissionID = %d";
1768 $SQL .= " WHERE mediaID = %d ";
1769 $SQL = sprintf($SQL, $db->escape_string($name), $duration, $permissionid, $mediaid);
1770-
1771+
1772 Debug::LogEntry($db, 'audit', $SQL);
1773-
1774+
1775 if (!$db->query($SQL))
1776 {
1777 trigger_error($db->error());
1778-
1779+
1780 $this->response->SetError('Database error editing this media record.');
1781 $this->response->keepOpen = true;
1782 return $this->response;
1783 }
1784 }
1785-
1786+
1787 // Required Attributes
1788 $this->mediaid = $new_mediaid;
1789 $this->duration = $duration;
1790-
1791+
1792 // Any Options
1793 $this->SetOption('uri', $storedAs);
1794-
1795+
1796 // Should have built the media object entirely by this time
1797 if ($regionid != '')
1798 {
1799 // This saves the Media Object to the Region
1800 $this->UpdateRegion();
1801-
1802+
1803 $this->response->loadForm = true;
1804 $this->response->loadFormUri = "index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions";;
1805 }
1806 else
1807 {
1808- $this->response->loadFormUri = "index.php?p=content&q=displayForms&sp=add";
1809+ $this->response->loadFormUri = "index.php?p=content&q=displayForms&sp=add";
1810 $this->response->message = 'Edited the Image.';
1811-
1812+
1813 }
1814-
1815+
1816 return $this->response;
1817 }
1818-
1819+
1820 /**
1821 * Delete Media from the Database
1822- * @return
1823+ * @return
1824 */
1825- public function DeleteMedia()
1826+ public function DeleteMedia()
1827 {
1828 $db =& $this->db;
1829 $layoutid = $this->layoutid;
1830@@ -848,10 +857,10 @@
1831 $mediaid = $this->mediaid;
1832 $userid = Kit::GetParam('userid', _SESSION, _INT);
1833 $options = Kit::GetParam('options', _POST, _WORD);
1834-
1835+
1836 // Stored As from the XML
1837 $this->uri = $this->GetOption('uri');
1838-
1839+
1840 // Do we need to remove this from a layout?
1841 if ($layoutid != '')
1842 {
1843@@ -863,72 +872,72 @@
1844 // Set this message now in preparation
1845 $this->response->message = 'Deleted the Media.';
1846 }
1847-
1848+
1849 // If we are set to retire we retire
1850 if ($options == "retire")
1851 {
1852 //Update the media record to say it is retired
1853 $SQL = "UPDATE media SET retired = 1 WHERE mediaid = $mediaid ";
1854-
1855+
1856 if (!$db->query($SQL))
1857 {
1858 trigger_error($db->error());
1859-
1860+
1861 $this->response->SetError('Database error retiring this media record.');
1862 $this->response->keepOpen = true;
1863 return $this->response;
1864 }
1865 }
1866-
1867+
1868 //If we are set to delete, we delete
1869 if ($options == "delete")
1870 {
1871 //Update the media record to say it is retired
1872 $SQL = "DELETE FROM media WHERE mediaid = $mediaid ";
1873-
1874+
1875 if (!$db->query($SQL))
1876 {
1877 trigger_error($db->error());
1878-
1879+
1880 $this->response->SetError('Database error deleting this media record.');
1881 $this->response->keepOpen = true;
1882 return $this->response;
1883 }
1884-
1885+
1886 $this->DeleteMediaFiles();
1887 }
1888-
1889+
1890 return $this->response;
1891 }
1892-
1893+
1894 /**
1895 * Deletes the media files associated with this record
1896- * @return
1897+ * @return
1898 */
1899 private function DeleteMediaFiles()
1900 {
1901 $db =& $this->db;
1902-
1903+
1904 //Library location
1905 $databaseDir = Config::GetSetting($db, "LIBRARY_LOCATION");
1906-
1907+
1908 //3 things to check for..
1909 //the actual file, the thumbnail, the background
1910 if (file_exists($databaseDir.$this->uri))
1911 {
1912 unlink($databaseDir.$this->uri);
1913 }
1914-
1915+
1916 if (file_exists($databaseDir."tn_".$this->uri))
1917 {
1918 unlink($databaseDir."tn_".$this->uri);
1919 }
1920-
1921+
1922 if (file_exists($databaseDir."bg_".$this->uri))
1923 {
1924 unlink($databaseDir."bg_".$this->uri);
1925 }
1926-
1927+
1928 return true;
1929 }
1930 }
1931
1932=== modified file 'server/modules/powerpoint.module.php'
1933--- server/modules/powerpoint.module.php 2009-06-28 10:47:06 +0000
1934+++ server/modules/powerpoint.module.php 2009-09-29 22:15:24 +0000
1935@@ -8,7 +8,7 @@
1936 * Xibo is free software: you can redistribute it and/or modify
1937 * it under the terms of the GNU Affero General Public License as published by
1938 * the Free Software Foundation, either version 3 of the License, or
1939- * any later version.
1940+ * any later version.
1941 *
1942 * Xibo is distributed in the hope that it will be useful,
1943 * but WITHOUT ANY WARRANTY; without even the implied warranty of
1944@@ -17,31 +17,31 @@
1945 *
1946 * You should have received a copy of the GNU Affero General Public License
1947 * along with Xibo. If not, see <http://www.gnu.org/licenses/>.
1948- */
1949+ */
1950 class powerpoint extends Module
1951 {
1952 // Custom Media information
1953 private $uri;
1954 private $maxFileSize;
1955 private $maxFileSizeBytes;
1956-
1957+
1958 public function __construct(database $db, user $user, $mediaid = '', $layoutid = '', $regionid = '')
1959 {
1960 // Must set the type of the class
1961 $this->type = 'powerpoint';
1962-
1963+
1964 // Get the max upload size from PHP
1965 $this->maxFileSize = ini_get('upload_max_filesize');
1966 $this->maxFileSizeBytes = convertBytes($this->maxFileSize);
1967-
1968- // Must call the parent class
1969+
1970+ // Must call the parent class
1971 parent::__construct($db, $user, $mediaid, $layoutid, $regionid);
1972 }
1973-
1974+
1975 /**
1976 * Sets the Layout and Region Information
1977 * it will then fill in any blanks it has about this media if it can
1978- * @return
1979+ * @return
1980 * @param $layoutid Object
1981 * @param $regionid Object
1982 * @param $mediaid Object
1983@@ -53,75 +53,75 @@
1984 $this->regionid = $regionid;
1985 $mediaid = $this->mediaid;
1986 $this->existingMedia = false;
1987-
1988+
1989 if ($this->regionSpecific == 1) return;
1990-
1991+
1992 // Load what we know about this media into the object
1993 $SQL = "SELECT name, type, duration, originalFilename, userID, permissionID, retired, storedAs, isEdited, editedMediaID FROM media WHERE mediaID = $mediaid ";
1994-
1995+
1996 if (!$result = $db->query($SQL))
1997 {
1998 trigger_error($db->error()); //log the error
1999 return false;
2000 }
2001-
2002+
2003 if ($db->num_rows($result) != 1)
2004 {
2005 trigger_error("More than one row for mediaId [$mediaid] How can this be?");
2006 return false;
2007 }
2008-
2009+
2010 $row = $db->get_row($result);
2011 $duration = $row[2];
2012 $storedAs = $row[7];
2013-
2014+
2015 // Required Attributes
2016 $this->duration = $duration;
2017-
2018+
2019 // Any Options
2020 $this->SetOption('uri', $storedAs);
2021-
2022+
2023 return true;
2024 }
2025-
2026+
2027 /**
2028 * Return the Add Form as HTML
2029- * @return
2030+ * @return
2031 */
2032 public function AddForm()
2033 {
2034 global $session;
2035 $db =& $this->db;
2036 $user =& $this->user;
2037-
2038- // Would like to get the regions width / height
2039+
2040+ // Would like to get the regions width / height
2041 $layoutid = $this->layoutid;
2042 $regionid = $this->regionid;
2043-
2044+
2045 // Set the Session / Security information
2046 $sessionId = session_id();
2047 $securityToken = CreateFormToken();
2048-
2049+
2050 $session->setSecurityToken($securityToken);
2051-
2052+
2053 //Get the default value for the shared list
2054 $default = Config::GetSetting($db,"defaultMedia");
2055
2056 $permissionid = 0;
2057
2058- if($default=="private")
2059+ if($default=="private")
2060 {
2061 $permissionid = 1;
2062 }
2063-
2064+
2065 //shared list
2066 $shared_list = dropdownlist("SELECT permissionID, permission FROM permission", "permissionid", $permissionid);
2067-
2068+
2069 //Save button is different depending on if we are on a region or not
2070 if ($regionid != "")
2071 {
2072 setSession('content','mediatype','powerpoint');
2073-
2074+
2075 $save_button = <<<END
2076 <input id="btnSave" type="submit" value="Save" disabled />
2077 <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" />
2078@@ -135,7 +135,7 @@
2079 <input class="XiboFormButton" id="btnCancel" type="button" title="Close" href="index.php?p=content&q=displayForms&sp=add" value="Cancel" />
2080 END;
2081 }
2082-
2083+
2084 $form = <<<FORM
2085 <div style="display:none"><iframe name="fileupload" width="1px" height="1px"></iframe></div>
2086 <div>
2087@@ -144,7 +144,7 @@
2088 <input type="hidden" id="SecurityToken" value="$securityToken" />
2089 <input type="hidden" name="MAX_FILE_SIZE" value="$this->maxFileSizeBytes" />
2090 <table>
2091- <tr>
2092+ <tr>
2093 <td><label for="file">Powerpoint File<span class="required">*</span></label></td>
2094 <td colspan="3">
2095 <input type="file" name="media_file" onchange="fileFormSubmit();this.form.submit();" />
2096@@ -172,7 +172,7 @@
2097 <td><label for="permissionid">Sharing<span class="required">*</span></label></td>
2098 <td>
2099 $shared_list
2100- </td>
2101+ </td>
2102 </tr>
2103 <tr>
2104 <td></td>
2105@@ -194,49 +194,49 @@
2106
2107 return $this->response;
2108 }
2109-
2110+
2111 /**
2112 * Return the Edit Form as HTML
2113- * @return
2114+ * @return
2115 */
2116 public function EditForm()
2117 {
2118 global $session;
2119 $db =& $this->db;
2120 $user =& $this->user;
2121-
2122- // Would like to get the regions width / height
2123+
2124+ // Would like to get the regions width / height
2125 $layoutid = $this->layoutid;
2126 $regionid = $this->regionid;
2127 $mediaid = $this->mediaid;
2128 $lkid = $this->lkid;
2129 $userid = Kit::GetParam('userid', _SESSION, _INT);
2130-
2131+
2132 // Set the Session / Security information
2133 $sessionId = session_id();
2134 $securityToken = CreateFormToken();
2135-
2136+
2137 $session->setSecurityToken($securityToken);
2138-
2139+
2140 // Load what we know about this media into the object
2141 $SQL = "SELECT name, originalFilename, userID, permissionID, retired, storedAs, isEdited, editedMediaID FROM media WHERE mediaID = $mediaid ";
2142-
2143+
2144 if (!$result = $db->query($SQL))
2145 {
2146 trigger_error($db->error()); //log the error
2147-
2148+
2149 $this->message = "Error querying for the Media information with media ID [$mediaid] ";
2150 return false;
2151 }
2152-
2153+
2154 if ($db->num_rows($result) != 1)
2155 {
2156 trigger_error("More than one row for mediaId [$mediaid] How can this be?");
2157-
2158+
2159 $this->message = "Error querying for the Media information with media ID [$mediaid] ";
2160 return false;
2161 }
2162-
2163+
2164 $row = $db->get_row($result);
2165 $name = $row[0];
2166 $originalFilename = $row[1];
2167@@ -246,23 +246,23 @@
2168 $storedAs = $row[5];
2169 $isEdited = $row[6];
2170 $editedMediaID = $row[7];
2171-
2172+
2173 // derive the ext
2174 $ext = strtolower(substr(strrchr($originalFilename, "."), 1));
2175-
2176+
2177 //Calc the permissions on it aswell
2178 list($see_permissions , $edit_permissions) = $user->eval_permission($userid, $permissionid);
2179-
2180+
2181 //shared list
2182 $shared_list = dropdownlist("SELECT permissionID, permission FROM permission", "permissionid", $permissionid);
2183-
2184+
2185 //Save button is different depending on if we are on a region or not
2186 if ($regionid != "")
2187 {
2188 setSession('content','mediatype','powerpoint');
2189-
2190+
2191 $extraNotes = '<em>Note: Uploading a new media item here will replace it on this layout only.</em>';
2192-
2193+
2194 $save_button = <<<END
2195 <input id="btnSave" type="submit" value="Save" />
2196 <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" />
2197@@ -272,13 +272,13 @@
2198 else
2199 {
2200 $extraNotes = '<em>Note: Uploading a new media item here will replace it on this layout only.</em>';
2201-
2202+
2203 $save_button = <<<END
2204 <input id="btnSave" type="submit" value="Save" />
2205 <input id="btnCancel" type="button" title="Close" onclick="$('#div_dialog').dialog('close')" value="Cancel" />
2206 END;
2207 }
2208-
2209+
2210 $form = <<<FORM
2211 <div style="display:none"><iframe name="fileupload" width="1px" height="1px"></iframe></div>
2212 <div>
2213@@ -287,7 +287,7 @@
2214 <input type="hidden" id="SecurityToken" value="$securityToken" />
2215 <input type="hidden" name="MAX_FILE_SIZE" value="$this->maxFileSizeBytes" />
2216 <table>
2217- <tr>
2218+ <tr>
2219 <td><label for="file">New Powerpoint File<span class="required">*</span></label></td>
2220 <td colspan="3">
2221 <input type="file" name="media_file" onchange="fileFormSubmit();this.form.submit();" />
2222@@ -319,7 +319,7 @@
2223 <td><label for="permissionid">Sharing<span class="required">*</span></label></td>
2224 <td>
2225 $shared_list
2226- </td>
2227+ </td>
2228 </tr>
2229 <tr>
2230 <td></td>
2231@@ -343,50 +343,50 @@
2232 $this->response->dialogWidth = '450px';
2233 $this->response->dialogHeight = '280px';
2234
2235- return $this->response;
2236+ return $this->response;
2237 }
2238-
2239+
2240 /**
2241 * Return the Delete Form as HTML
2242- * @return
2243+ * @return
2244 */
2245 public function DeleteForm()
2246 {
2247 $db =& $this->db;
2248 $user =& $this->user;
2249-
2250- // Would like to get the regions width / height
2251+
2252+ // Would like to get the regions width / height
2253 $layoutid = $this->layoutid;
2254 $regionid = $this->regionid;
2255 $mediaid = $this->mediaid;
2256 $lkid = $this->lkid;
2257 $userid = Kit::GetParam('userid', _SESSION, _INT);
2258-
2259+
2260 $options = "";
2261 //Always have the abilty to unassign from the region
2262 $options .= "unassign|Unassign from this region only";
2263-
2264+
2265 // Load what we know about this media into the object
2266 $SQL = "SELECT name, type, duration, originalFilename, userID, permissionID, retired, storedAs, isEdited, editedMediaID FROM media WHERE mediaID = $mediaid ";
2267-
2268+
2269 if (!$result = $db->query($SQL))
2270 {
2271 trigger_error($db->error()); //log the error
2272-
2273+
2274 $this->response->SetError('Error querying for the Media information with media ID [$mediaid]');
2275 $this->response->keepOpen = true;
2276 return $this->response;
2277 }
2278-
2279+
2280 if ($db->num_rows($result) != 1)
2281 {
2282 trigger_error("More than one row for mediaId [$mediaid] How can this be?");
2283-
2284+
2285 $this->response->SetError('Error querying for the Media information with media ID [$mediaid]');
2286 $this->response->keepOpen = true;
2287 return $this->response;
2288 }
2289-
2290+
2291 $row = $db->get_row($result);
2292 $name = $row[0];
2293 $duration = $row[2];
2294@@ -397,18 +397,18 @@
2295 $storedAs = $row[7];
2296 $isEdited = $row[8];
2297 $editedMediaID = $row[9];
2298-
2299+
2300 // derive the ext
2301 $ext = strtolower(substr(strrchr($originalFilename, "."), 1));
2302-
2303+
2304 //Calc the permissions on it aswell
2305 list($see_permissions , $edit_permissions) = $user->eval_permission($userid, $permissionid);
2306-
2307+
2308 //Is this user allowed to edit this media?
2309 if ($edit_permissions)
2310 {
2311 $options .= ",retire|Unassign from this region and retire";
2312-
2313+
2314 //Is this media retired?
2315 if ($editedMediaID != "")
2316 {
2317@@ -418,7 +418,7 @@
2318 {
2319 $revised = false;
2320 }
2321-
2322+
2323 //Is this media being used anywhere else?
2324 if ($layoutid == "")
2325 {
2326@@ -429,8 +429,8 @@
2327 {
2328 $SQL = "SELECT layoutID FROM lklayoutmedia WHERE mediaID = $mediaid AND layoutid <> $layoutid AND regionID <> '$regionid' ";
2329 }
2330-
2331- if (!$results = $db->query($SQL))
2332+
2333+ if (!$results = $db->query($SQL))
2334 {
2335 trigger_error($db->error());
2336
2337@@ -457,9 +457,9 @@
2338 return $this->response;
2339 }
2340 }
2341-
2342+
2343 $options = ltrim($options, ",");
2344-
2345+
2346 $deleteOptions = listcontent($options,"options");
2347
2348 //we can delete
2349@@ -474,19 +474,19 @@
2350 <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" />
2351 </form>
2352 END;
2353-
2354+
2355 $this->response->html = $form;
2356 $this->response->dialogTitle = 'Delete Powerpoint';
2357 $this->response->dialogSize = true;
2358 $this->response->dialogWidth = '450px';
2359 $this->response->dialogHeight = '280px';
2360
2361- return $this->response;
2362+ return $this->response;
2363 }
2364-
2365+
2366 /**
2367 * Add Media to the Database
2368- * @return
2369+ * @return
2370 */
2371 public function AddMedia()
2372 {
2373@@ -495,29 +495,29 @@
2374 $regionid = $this->regionid;
2375 $mediaid = $this->mediaid;
2376 $userid = Kit::GetParam('userid', _SESSION, _INT);
2377-
2378+
2379 // File data
2380 $tmpName = Kit::GetParam('hidFileID', _POST, _STRING);
2381-
2382+
2383 if ($tmpName == '')
2384 {
2385 $this->response->SetError('Cannot save Powerpoint details. <br/> You must have picked a file.');
2386 $this->response->keepOpen = true;
2387 return $this->response;
2388 }
2389-
2390+
2391 // File name and extension (orignial name)
2392 $fileName = Kit::GetParam('txtFileName', _POST, _STRING);
2393 $fileName = basename($fileName);
2394 $ext = strtolower(substr(strrchr($fileName, "."), 1));
2395-
2396+
2397 // Other properties
2398 $name = Kit::GetParam('name', _POST, _STRING);
2399 $duration = Kit::GetParam('duration', _POST, _INT, 0);
2400 $permissionid = Kit::GetParam('permissionid', _POST, _INT, 1);
2401-
2402+
2403 if ($name == '') $name = Kit::ValidateParam($fileName, _FILENAME);
2404-
2405+
2406 // Validation
2407 if ($ext != "ppt")
2408 {
2409@@ -525,32 +525,32 @@
2410 $this->response->keepOpen = true;
2411 return $this->response;
2412 }
2413-
2414+
2415 // Make sure the name isnt too long
2416- if (strlen($name) > 100)
2417+ if (strlen($name) > 100)
2418 {
2419 $this->response->SetError('The name cannot be longer than 100 characters');
2420 $this->response->keepOpen = true;
2421 return $this->response;
2422 }
2423-
2424+
2425 if ($duration == 0)
2426 {
2427 $this->response->SetError('You must enter a duration.');
2428 $this->response->keepOpen = true;
2429 return $this->response;
2430 }
2431-
2432+
2433 // Ensure the name is not already in the database
2434 $SQL = sprintf("SELECT name FROM media WHERE name = '%s' AND userid = %d", $db->escape_string($name), $userid);
2435
2436- if(!$result = $db->query($SQL))
2437+ if(!$result = $db->query($SQL))
2438 {
2439 trigger_error($db->error());
2440 $this->response->SetError('Error checking whether the media name is ok. Try choosing a different name.');
2441 $this->response->keepOpen = true;
2442 return $this->response;
2443- }
2444+ }
2445
2446 if ($db->num_rows($result) != 0)
2447 {
2448@@ -558,11 +558,11 @@
2449 $this->response->keepOpen = true;
2450 return $this->response;
2451 }
2452-
2453+
2454 // All OK to insert this record
2455 $SQL = "INSERT INTO media (name, type, duration, originalFilename, permissionID, userID, retired ) ";
2456 $SQL .= "VALUES ('%s', 'powerpoint', '%s', '%s', %d, %d, 0) ";
2457-
2458+
2459 $SQL = sprintf($SQL, $db->escape_string($name), $db->escape_string($duration), $db->escape_string($fileName), $permissionid, $userid);
2460
2461 if (!$mediaid = $db->insert_query($SQL))
2462@@ -572,19 +572,19 @@
2463 $this->response->keepOpen = true;
2464 return $this->response;
2465 }
2466-
2467+
2468 // File upload directory.. get this from the settings object
2469 $databaseDir = Config::GetSetting($db, "LIBRARY_LOCATION");
2470-
2471+
2472 // What are we going to store this media as...
2473 $storedAs = $mediaid.".".$ext;
2474-
2475+
2476 // Now we need to move the file
2477 if (!$result = rename($databaseDir."temp/".$tmpName, $databaseDir.$storedAs))
2478 {
2479 // If we couldnt move it - we need to delete the media record we just added
2480 $SQL = sprintf("DELETE FROM media WHERE mediaID = %d ", $mediaid);
2481-
2482+
2483 if (!$db->query($SQL))
2484 {
2485 trigger_error($db->error());
2486@@ -593,23 +593,27 @@
2487 return $this->response;
2488 }
2489 }
2490-
2491+
2492+ // Calculate the MD5 and the file size
2493+ $md5 = md5_file($databaseDir.$storedAs);
2494+ $fileSize = filesize($databaseDir.$storedAs);
2495+
2496 // Update the media record to include this information
2497- $SQL = sprintf("UPDATE media SET storedAs = '%s' WHERE mediaid = %d", $storedAs, $mediaid);
2498-
2499+ $SQL = sprintf("UPDATE media SET storedAs = '%s', `MD5` = '%s', FileSize = %d WHERE mediaid = %d", $storedAs, $md5, $fileSize, $mediaid);
2500+
2501 if (!$db->query($SQL))
2502 {
2503 trigger_error($db->error());
2504 return true;
2505 }
2506-
2507+
2508 // Required Attributes
2509 $this->mediaid = $mediaid;
2510 $this->duration = $duration;
2511-
2512+
2513 // Any Options
2514 $this->SetOption('uri', $storedAs);
2515-
2516+
2517 // Should have built the media object entirely by this time
2518 if ($regionid != '')
2519 {
2520@@ -619,18 +623,18 @@
2521 }
2522 else
2523 {
2524- $this->response->loadFormUri = "index.php?p=content&q=displayForms&sp=add";
2525+ $this->response->loadFormUri = "index.php?p=content&q=displayForms&sp=add";
2526 }
2527-
2528+
2529 // We want to load a new form
2530 $this->response->loadForm = true;
2531-
2532+
2533 return $this->response;
2534 }
2535-
2536+
2537 /**
2538 * Edit Media in the Database
2539- * @return
2540+ * @return
2541 */
2542 public function EditMedia()
2543 {
2544@@ -639,13 +643,13 @@
2545 $regionid = $this->regionid;
2546 $mediaid = $this->mediaid;
2547 $userid = Kit::GetParam('userid', _SESSION, _INT);
2548-
2549+
2550 // Stored As from the XML
2551 $storedAs = $this->GetOption('uri');
2552-
2553+
2554 // File data
2555 $tmpName = Kit::GetParam('hidFileID', _POST, _STRING);
2556-
2557+
2558 if ($tmpName == '')
2559 {
2560 $fileRevision = false;
2561@@ -653,12 +657,12 @@
2562 else
2563 {
2564 $fileRevision = true;
2565-
2566+
2567 // File name and extension (orignial name)
2568 $fileName = Kit::GetParam('txtFileName', _POST, _STRING);
2569 $fileName = basename($fileName);
2570 $ext = strtolower(substr(strrchr($fileName, "."), 1));
2571-
2572+
2573 if ($ext != "ppt")
2574 {
2575 $this->response->SetError('Only PPT files are accepted - Are you sure this is a powerpoint?');
2576@@ -666,17 +670,17 @@
2577 return $this->response;
2578 }
2579 }
2580-
2581+
2582 // Other properties
2583 $name = Kit::GetParam('name', _POST, _STRING);
2584 $duration = Kit::GetParam('duration', _POST, _INT, 0);
2585 $permissionid = Kit::GetParam('permissionid', _POST, _INT, 1);
2586-
2587+
2588 if ($name == '')
2589 {
2590 if ($fileRevision)
2591 {
2592- $name = Kit::ValidateParam($fileName, _FILENAME);
2593+ $name = Kit::ValidateParam($fileName, _FILENAME);
2594 }
2595 else
2596 {
2597@@ -684,33 +688,33 @@
2598 $this->response->keepOpen = true;
2599 return $this->response;
2600 }
2601- }
2602-
2603+ }
2604+
2605 // Make sure the name isnt too long
2606- if (strlen($name) > 100)
2607+ if (strlen($name) > 100)
2608 {
2609 $this->response->SetError('The name cannot be longer than 100 characters');
2610 $this->response->keepOpen = true;
2611 return $this->response;
2612 }
2613-
2614+
2615 if ($duration == 0)
2616 {
2617 $this->response->SetError('You must enter a duration.');
2618 $this->response->keepOpen = true;
2619 return $this->response;
2620 }
2621-
2622+
2623 // Ensure the name is not already in the database
2624 $SQL = sprintf("SELECT name FROM media WHERE name = '%s' AND userid = %d AND mediaid <> %d ", $db->escape_string($name), $userid, $mediaid);
2625
2626- if(!$result = $db->query($SQL))
2627+ if(!$result = $db->query($SQL))
2628 {
2629 trigger_error($db->error());
2630 $this->response->SetError('Error checking whether the media name is ok. Try choosing a different name.');
2631 $this->response->keepOpen = true;
2632 return $this->response;
2633- }
2634+ }
2635
2636 if ($db->num_rows($result) != 0)
2637 {
2638@@ -718,34 +722,34 @@
2639 $this->response->keepOpen = true;
2640 return $this->response;
2641 }
2642-
2643+
2644 //Are we revising this media - or just plain editing
2645 if ($fileRevision)
2646 {
2647 // All OK to insert this record
2648 $SQL = "INSERT INTO media (name, type, duration, originalFilename, permissionID, userID, retired ) ";
2649 $SQL .= "VALUES ('%s', '%s', '%s', '%s', %d, %d, 0) ";
2650-
2651+
2652 $SQL = sprintf($SQL, $db->escape_string($name), $this->type, $db->escape_string($duration), $db->escape_string($fileName), $permissionid, $userid);
2653-
2654+
2655 if (!$new_mediaid = $db->insert_query($SQL))
2656 {
2657 trigger_error($db->error());
2658 trigger_error('Error inserting replacement media record.', E_USER_ERROR);
2659 }
2660-
2661+
2662 //What are we going to store this media as...
2663 $storedAs = $new_mediaid.".".$ext;
2664-
2665+
2666 // File upload directory.. get this from the settings object
2667 $databaseDir = Config::GetSetting($db, "LIBRARY_LOCATION");
2668-
2669+
2670 //Now we need to move the file
2671 if (!$result = rename($databaseDir."/temp/".$tmpName, $databaseDir.$storedAs))
2672 {
2673 //If we couldnt move it - we need to delete the media record we just added
2674 $SQL = "DELETE FROM media WHERE mediaID = $new_mediaid ";
2675-
2676+
2677 if (!$db->insert_query($SQL))
2678 {
2679 $this->response->SetError('Error rolling back transcation.');
2680@@ -753,9 +757,14 @@
2681 return $this->response;
2682 }
2683 }
2684-
2685- //Update the media record to include this information
2686- $SQL = "UPDATE media SET storedAs = '$storedAs' WHERE mediaid = $new_mediaid";
2687+
2688+ // Calculate the MD5 and the file size
2689+ $md5 = md5_file($databaseDir.$storedAs);
2690+ $fileSize = filesize($databaseDir.$storedAs);
2691+
2692+ // Update the media record to include this information
2693+ $SQL = sprintf("UPDATE media SET storedAs = '%s', `MD5` = '%s', FileSize = %d WHERE mediaid = %d", $storedAs, $md5, $fileSize, $new_mediaid);
2694+
2695 if (!$db->query($SQL))
2696 {
2697 trigger_error($db->error());
2698@@ -763,13 +772,13 @@
2699 $this->response->keepOpen = true;
2700 return $this->response;
2701 }
2702-
2703+
2704 // Update the existing record with the new record's id
2705 $SQL = "UPDATE media SET isEdited = 1, editedMediaID = $new_mediaid ";
2706 $SQL .= " WHERE IFNULL(editedMediaID,0) <> $new_mediaid AND mediaID = $mediaid ";
2707-
2708+
2709 Debug::LogEntry($db, 'audit', $SQL);
2710-
2711+
2712 if (!$db->query($SQL))
2713 {
2714 trigger_error($db->error());
2715@@ -783,54 +792,54 @@
2716 {
2717 // Editing the existing record
2718 $new_mediaid = $mediaid;
2719-
2720+
2721 $SQL = "UPDATE media SET name = '%s', duration = %d, permissionID = %d";
2722 $SQL .= " WHERE mediaID = %d ";
2723 $SQL = sprintf($SQL, $db->escape_string($name), $duration, $permissionid, $mediaid);
2724-
2725+
2726 Debug::LogEntry($db, 'audit', $SQL);
2727-
2728+
2729 if (!$db->query($SQL))
2730 {
2731 trigger_error($db->error());
2732-
2733+
2734 $this->response->SetError('Database error editing this media record.');
2735 $this->response->keepOpen = true;
2736 return $this->response;
2737 }
2738 }
2739-
2740+
2741 // Required Attributes
2742 $this->mediaid = $new_mediaid;
2743 $this->duration = $duration;
2744-
2745+
2746 // Any Options
2747 $this->SetOption('uri', $storedAs);
2748-
2749+
2750 // Should have built the media object entirely by this time
2751 if ($regionid != '')
2752 {
2753 // This saves the Media Object to the Region
2754 $this->UpdateRegion();
2755-
2756+
2757 $this->response->loadForm = true;
2758 $this->response->loadFormUri = "index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions";;
2759 }
2760 else
2761 {
2762- $this->response->loadFormUri = "index.php?p=content&q=displayForms&sp=add";
2763+ $this->response->loadFormUri = "index.php?p=content&q=displayForms&sp=add";
2764 $this->response->message = 'Edited the Powerpoint.';
2765-
2766+
2767 }
2768-
2769+
2770 return $this->response;
2771 }
2772-
2773+
2774 /**
2775 * Delete Media from the Database
2776- * @return
2777+ * @return
2778 */
2779- public function DeleteMedia()
2780+ public function DeleteMedia()
2781 {
2782 $db =& $this->db;
2783 $layoutid = $this->layoutid;
2784@@ -838,10 +847,10 @@
2785 $mediaid = $this->mediaid;
2786 $userid = Kit::GetParam('userid', _SESSION, _INT);
2787 $options = Kit::GetParam('options', _POST, _WORD);
2788-
2789+
2790 // Stored As from the XML
2791 $this->uri = $this->GetOption('uri');
2792-
2793+
2794 // Do we need to remove this from a layout?
2795 if ($layoutid != '')
2796 {
2797@@ -853,72 +862,72 @@
2798 // Set this message now in preparation
2799 $this->response->message = 'Deleted the Media.';
2800 }
2801-
2802+
2803 // If we are set to retire we retire
2804 if ($options == "retire")
2805 {
2806 //Update the media record to say it is retired
2807 $SQL = "UPDATE media SET retired = 1 WHERE mediaid = $mediaid ";
2808-
2809+
2810 if (!$db->query($SQL))
2811 {
2812 trigger_error($db->error());
2813-
2814+
2815 $this->response->SetError('Database error retiring this media record.');
2816 $this->response->keepOpen = true;
2817 return $this->response;
2818 }
2819 }
2820-
2821+
2822 //If we are set to delete, we delete
2823 if ($options == "delete")
2824 {
2825 //Update the media record to say it is retired
2826 $SQL = "DELETE FROM media WHERE mediaid = $mediaid ";
2827-
2828+
2829 if (!$db->query($SQL))
2830 {
2831 trigger_error($db->error());
2832-
2833+
2834 $this->response->SetError('Database error deleting this media record.');
2835 $this->response->keepOpen = true;
2836 return $this->response;
2837 }
2838-
2839+
2840 $this->DeleteMediaFiles();
2841 }
2842-
2843+
2844 return $this->response;
2845 }
2846-
2847+
2848 /**
2849 * Deletes the media files associated with this record
2850- * @return
2851+ * @return
2852 */
2853 private function DeleteMediaFiles()
2854 {
2855 $db =& $this->db;
2856-
2857+
2858 //Library location
2859 $databaseDir = Config::GetSetting($db, "LIBRARY_LOCATION");
2860-
2861+
2862 //3 things to check for..
2863 //the actual file, the thumbnail, the background
2864 if (file_exists($databaseDir.$this->uri))
2865 {
2866 unlink($databaseDir.$this->uri);
2867 }
2868-
2869+
2870 if (file_exists($databaseDir."tn_".$this->uri))
2871 {
2872 unlink($databaseDir."tn_".$this->uri);
2873 }
2874-
2875+
2876 if (file_exists($databaseDir."bg_".$this->uri))
2877 {
2878 unlink($databaseDir."bg_".$this->uri);
2879 }
2880-
2881+
2882 return true;
2883 }
2884 }
2885
2886=== modified file 'server/modules/video.module.php'
2887--- server/modules/video.module.php 2009-06-28 10:47:06 +0000
2888+++ server/modules/video.module.php 2009-09-29 22:15:24 +0000
2889@@ -8,7 +8,7 @@
2890 * Xibo is free software: you can redistribute it and/or modify
2891 * it under the terms of the GNU Affero General Public License as published by
2892 * the Free Software Foundation, either version 3 of the License, or
2893- * any later version.
2894+ * any later version.
2895 *
2896 * Xibo is distributed in the hope that it will be useful,
2897 * but WITHOUT ANY WARRANTY; without even the implied warranty of
2898@@ -17,31 +17,31 @@
2899 *
2900 * You should have received a copy of the GNU Affero General Public License
2901 * along with Xibo. If not, see <http://www.gnu.org/licenses/>.
2902- */
2903+ */
2904 class video extends Module
2905 {
2906 // Custom Media information
2907 private $uri;
2908 private $maxFileSize;
2909 private $maxFileSizeBytes;
2910-
2911+
2912 public function __construct(database $db, user $user, $mediaid = '', $layoutid = '', $regionid = '')
2913 {
2914 // Must set the type of the class
2915 $this->type = 'video';
2916-
2917+
2918 // Get the max upload size from PHP
2919 $this->maxFileSize = ini_get('upload_max_filesize');
2920 $this->maxFileSizeBytes = convertBytes($this->maxFileSize);
2921-
2922- // Must call the parent class
2923+
2924+ // Must call the parent class
2925 parent::__construct($db, $user, $mediaid, $layoutid, $regionid);
2926 }
2927-
2928+
2929 /**
2930 * Sets the Layout and Region Information
2931 * it will then fill in any blanks it has about this media if it can
2932- * @return
2933+ * @return
2934 * @param $layoutid Object
2935 * @param $regionid Object
2936 * @param $mediaid Object
2937@@ -53,75 +53,75 @@
2938 $this->regionid = $regionid;
2939 $mediaid = $this->mediaid;
2940 $this->existingMedia = false;
2941-
2942+
2943 if ($this->regionSpecific == 1) return;
2944-
2945+
2946 // Load what we know about this media into the object
2947 $SQL = "SELECT name, type, duration, originalFilename, userID, permissionID, retired, storedAs, isEdited, editedMediaID FROM media WHERE mediaID = $mediaid ";
2948-
2949+
2950 if (!$result = $db->query($SQL))
2951 {
2952 trigger_error($db->error()); //log the error
2953 return false;
2954 }
2955-
2956+
2957 if ($db->num_rows($result) != 1)
2958 {
2959 trigger_error("More than one row for mediaId [$mediaid] How can this be?");
2960 return false;
2961 }
2962-
2963+
2964 $row = $db->get_row($result);
2965 $duration = $row[2];
2966 $storedAs = $row[7];
2967-
2968+
2969 // Required Attributes
2970 $this->duration = $duration;
2971-
2972+
2973 // Any Options
2974 $this->SetOption('uri', $storedAs);
2975-
2976+
2977 return true;
2978 }
2979-
2980+
2981 /**
2982 * Return the Add Form as HTML
2983- * @return
2984+ * @return
2985 */
2986 public function AddForm()
2987 {
2988 global $session;
2989 $db =& $this->db;
2990 $user =& $this->user;
2991-
2992- // Would like to get the regions width / height
2993+
2994+ // Would like to get the regions width / height
2995 $layoutid = $this->layoutid;
2996 $regionid = $this->regionid;
2997-
2998+
2999 // Set the Session / Security information
3000 $sessionId = session_id();
3001 $securityToken = CreateFormToken();
3002-
3003+
3004 $session->setSecurityToken($securityToken);
3005-
3006+
3007 //Get the default value for the shared list
3008 $default = Config::GetSetting($db,"defaultMedia");
3009
3010 $permissionid = 0;
3011
3012- if($default=="private")
3013+ if($default=="private")
3014 {
3015 $permissionid = 1;
3016 }
3017-
3018+
3019 //shared list
3020 $shared_list = dropdownlist("SELECT permissionID, permission FROM permission", "permissionid", $permissionid);
3021-
3022+
3023 //Save button is different depending on if we are on a region or not
3024 if ($regionid != "")
3025 {
3026 setSession('content','mediatype','video');
3027-
3028+
3029 $save_button = <<<END
3030 <input id="btnSave" type="submit" value="Save" disabled />
3031 <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" />
3032@@ -135,7 +135,7 @@
3033 <input class="XiboFormButton" id="btnCancel" type="button" title="Close" href="index.php?p=content&q=displayForms&sp=add" value="Cancel" />
3034 END;
3035 }
3036-
3037+
3038 $form = <<<FORM
3039 <div style="display:none"><iframe name="fileupload" width="1px" height="1px"></iframe></div>
3040 <div>
3041@@ -144,7 +144,7 @@
3042 <input type="hidden" id="SecurityToken" value="$securityToken" />
3043 <input type="hidden" name="MAX_FILE_SIZE" value="$this->maxFileSizeBytes" />
3044 <table>
3045- <tr>
3046+ <tr>
3047 <td><label for="file">Video File<span class="required">*</span></label></td>
3048 <td colspan="3">
3049 <input type="file" name="media_file" onchange="fileFormSubmit();this.form.submit();" />
3050@@ -172,7 +172,7 @@
3051 <td><label for="permissionid">Sharing<span class="required">*</span></label></td>
3052 <td>
3053 $shared_list
3054- </td>
3055+ </td>
3056 </tr>
3057 <tr>
3058 <td></td>
3059@@ -194,49 +194,49 @@
3060
3061 return $this->response;
3062 }
3063-
3064+
3065 /**
3066 * Return the Edit Form as HTML
3067- * @return
3068+ * @return
3069 */
3070 public function EditForm()
3071 {
3072 global $session;
3073 $db =& $this->db;
3074 $user =& $this->user;
3075-
3076- // Would like to get the regions width / height
3077+
3078+ // Would like to get the regions width / height
3079 $layoutid = $this->layoutid;
3080 $regionid = $this->regionid;
3081 $mediaid = $this->mediaid;
3082 $lkid = $this->lkid;
3083 $userid = Kit::GetParam('userid', _SESSION, _INT);
3084-
3085+
3086 // Set the Session / Security information
3087 $sessionId = session_id();
3088 $securityToken = CreateFormToken();
3089-
3090+
3091 $session->setSecurityToken($securityToken);
3092-
3093+
3094 // Load what we know about this media into the object
3095 $SQL = "SELECT name, originalFilename, userID, permissionID, retired, storedAs, isEdited, editedMediaID FROM media WHERE mediaID = $mediaid ";
3096-
3097+
3098 if (!$result = $db->query($SQL))
3099 {
3100 trigger_error($db->error()); //log the error
3101-
3102+
3103 $this->message = "Error querying for the Media information with media ID [$mediaid] ";
3104 return false;
3105 }
3106-
3107+
3108 if ($db->num_rows($result) != 1)
3109 {
3110 trigger_error("More than one row for mediaId [$mediaid] How can this be?");
3111-
3112+
3113 $this->message = "Error querying for the Media information with media ID [$mediaid] ";
3114 return false;
3115 }
3116-
3117+
3118 $row = $db->get_row($result);
3119 $name = $row[0];
3120 $originalFilename = $row[1];
3121@@ -246,23 +246,23 @@
3122 $storedAs = $row[5];
3123 $isEdited = $row[6];
3124 $editedMediaID = $row[7];
3125-
3126+
3127 // derive the ext
3128 $ext = strtolower(substr(strrchr($originalFilename, "."), 1));
3129-
3130+
3131 //Calc the permissions on it aswell
3132 list($see_permissions , $edit_permissions) = $user->eval_permission($userid, $permissionid);
3133-
3134+
3135 //shared list
3136 $shared_list = dropdownlist("SELECT permissionID, permission FROM permission", "permissionid", $permissionid);
3137-
3138+
3139 //Save button is different depending on if we are on a region or not
3140 if ($regionid != "")
3141 {
3142 setSession('content','mediatype','image');
3143-
3144+
3145 $extraNotes = '<em>Note: Uploading a new media item here will replace it on this layout only.</em>';
3146-
3147+
3148 $save_button = <<<END
3149 <input id="btnSave" type="submit" value="Save" />
3150 <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" />
3151@@ -272,13 +272,13 @@
3152 else
3153 {
3154 $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>';
3155-
3156+
3157 $save_button = <<<END
3158 <input id="btnSave" type="submit" value="Save" />
3159 <input id="btnCancel" type="button" title="Close" onclick="$('#div_dialog').dialog('close')" value="Cancel" />
3160 END;
3161 }
3162-
3163+
3164 $form = <<<FORM
3165 <div style="display:none"><iframe name="fileupload" width="1px" height="1px"></iframe></div>
3166 <div>
3167@@ -287,7 +287,7 @@
3168 <input type="hidden" id="SecurityToken" value="$securityToken" />
3169 <input type="hidden" name="MAX_FILE_SIZE" value="$this->maxFileSizeBytes" />
3170 <table>
3171- <tr>
3172+ <tr>
3173 <td><label for="file">New Video File<span class="required">*</span></label></td>
3174 <td colspan="3">
3175 <input type="file" name="media_file" onchange="fileFormSubmit();this.form.submit();" />
3176@@ -319,7 +319,7 @@
3177 <td><label for="permissionid">Sharing<span class="required">*</span></label></td>
3178 <td>
3179 $shared_list
3180- </td>
3181+ </td>
3182 </tr>
3183 <tr>
3184 <td></td>
3185@@ -343,50 +343,50 @@
3186 $this->response->dialogWidth = '450px';
3187 $this->response->dialogHeight = '280px';
3188
3189- return $this->response;
3190+ return $this->response;
3191 }
3192-
3193+
3194 /**
3195 * Return the Delete Form as HTML
3196- * @return
3197+ * @return
3198 */
3199 public function DeleteForm()
3200 {
3201 $db =& $this->db;
3202 $user =& $this->user;
3203-
3204- // Would like to get the regions width / height
3205+
3206+ // Would like to get the regions width / height
3207 $layoutid = $this->layoutid;
3208 $regionid = $this->regionid;
3209 $mediaid = $this->mediaid;
3210 $lkid = $this->lkid;
3211 $userid = Kit::GetParam('userid', _SESSION, _INT);
3212-
3213+
3214 $options = "";
3215 //Always have the abilty to unassign from the region
3216 $options .= "unassign|Unassign from this region only";
3217-
3218+
3219 // Load what we know about this media into the object
3220 $SQL = "SELECT name, type, duration, originalFilename, userID, permissionID, retired, storedAs, isEdited, editedMediaID FROM media WHERE mediaID = $mediaid ";
3221-
3222+
3223 if (!$result = $db->query($SQL))
3224 {
3225 trigger_error($db->error()); //log the error
3226-
3227+
3228 $this->response->SetError('Error querying for the Media information with media ID [$mediaid]');
3229 $this->response->keepOpen = true;
3230 return $this->response;
3231 }
3232-
3233+
3234 if ($db->num_rows($result) != 1)
3235 {
3236 trigger_error("More than one row for mediaId [$mediaid] How can this be?");
3237-
3238+
3239 $this->response->SetError('Error querying for the Media information with media ID [$mediaid]');
3240 $this->response->keepOpen = true;
3241 return $this->response;
3242 }
3243-
3244+
3245 $row = $db->get_row($result);
3246 $name = $row[0];
3247 $duration = $row[2];
3248@@ -397,18 +397,18 @@
3249 $storedAs = $row[7];
3250 $isEdited = $row[8];
3251 $editedMediaID = $row[9];
3252-
3253+
3254 // derive the ext
3255 $ext = strtolower(substr(strrchr($originalFilename, "."), 1));
3256-
3257+
3258 //Calc the permissions on it aswell
3259 list($see_permissions , $edit_permissions) = $user->eval_permission($userid, $permissionid);
3260-
3261+
3262 //Is this user allowed to edit this media?
3263 if ($edit_permissions)
3264 {
3265 $options .= ",retire|Unassign from this region and retire";
3266-
3267+
3268 //Is this media retired?
3269 if ($editedMediaID != "")
3270 {
3271@@ -418,7 +418,7 @@
3272 {
3273 $revised = false;
3274 }
3275-
3276+
3277 //Is this media being used anywhere else?
3278 if ($layoutid == "")
3279 {
3280@@ -429,8 +429,8 @@
3281 {
3282 $SQL = "SELECT layoutID FROM lklayoutmedia WHERE mediaID = $mediaid AND layoutid <> $layoutid AND regionID <> '$regionid' ";
3283 }
3284-
3285- if (!$results = $db->query($SQL))
3286+
3287+ if (!$results = $db->query($SQL))
3288 {
3289 trigger_error($db->error());
3290
3291@@ -457,9 +457,9 @@
3292 return $this->response;
3293 }
3294 }
3295-
3296+
3297 $options = ltrim($options, ",");
3298-
3299+
3300 $deleteOptions = listcontent($options,"options");
3301
3302 //we can delete
3303@@ -474,19 +474,19 @@
3304 <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" />
3305 </form>
3306 END;
3307-
3308+
3309 $this->response->html = $form;
3310 $this->response->dialogTitle = 'Delete Video';
3311 $this->response->dialogSize = true;
3312 $this->response->dialogWidth = '450px';
3313 $this->response->dialogHeight = '280px';
3314
3315- return $this->response;
3316+ return $this->response;
3317 }
3318-
3319+
3320 /**
3321 * Add Media to the Database
3322- * @return
3323+ * @return
3324 */
3325 public function AddMedia()
3326 {
3327@@ -495,29 +495,29 @@
3328 $regionid = $this->regionid;
3329 $mediaid = $this->mediaid;
3330 $userid = Kit::GetParam('userid', _SESSION, _INT);
3331-
3332+
3333 // File data
3334 $tmpName = Kit::GetParam('hidFileID', _POST, _STRING);
3335-
3336+
3337 if ($tmpName == '')
3338 {
3339 $this->response->SetError('Cannot save Video details. <br/> You must have picked a file.');
3340 $this->response->keepOpen = true;
3341 return $this->response;
3342 }
3343-
3344+
3345 // File name and extension (orignial name)
3346 $fileName = Kit::GetParam('txtFileName', _POST, _STRING);
3347 $fileName = basename($fileName);
3348 $ext = strtolower(substr(strrchr($fileName, "."), 1));
3349-
3350+
3351 // Other properties
3352 $name = Kit::GetParam('name', _POST, _STRING);
3353 $duration = Kit::GetParam('duration', _POST, _INT, 0);
3354 $permissionid = Kit::GetParam('permissionid', _POST, _INT, 1);
3355-
3356+
3357 if ($name == '') $name = Kit::ValidateParam($fileName, _FILENAME);
3358-
3359+
3360 // Validation
3361 if ($ext != "wmv" && $ext != "mpeg" && $ext != "mpg")
3362 {
3363@@ -525,25 +525,25 @@
3364 $this->response->keepOpen = true;
3365 return $this->response;
3366 }
3367-
3368+
3369 // Make sure the name isnt too long
3370- if (strlen($name) > 100)
3371+ if (strlen($name) > 100)
3372 {
3373 $this->response->SetError('The name cannot be longer than 100 characters');
3374 $this->response->keepOpen = true;
3375 return $this->response;
3376 }
3377-
3378+
3379 // Ensure the name is not already in the database
3380 $SQL = sprintf("SELECT name FROM media WHERE name = '%s' AND userid = %d", $db->escape_string($name), $userid);
3381
3382- if(!$result = $db->query($SQL))
3383+ if(!$result = $db->query($SQL))
3384 {
3385 trigger_error($db->error());
3386 $this->response->SetError('Error checking whether the media name is ok. Try choosing a different name.');
3387 $this->response->keepOpen = true;
3388 return $this->response;
3389- }
3390+ }
3391
3392 if ($db->num_rows($result) != 0)
3393 {
3394@@ -551,11 +551,11 @@
3395 $this->response->keepOpen = true;
3396 return $this->response;
3397 }
3398-
3399+
3400 // All OK to insert this record
3401 $SQL = "INSERT INTO media (name, type, duration, originalFilename, permissionID, userID, retired ) ";
3402 $SQL .= "VALUES ('%s', 'video', '%s', '%s', %d, %d, 0) ";
3403-
3404+
3405 $SQL = sprintf($SQL, $db->escape_string($name), $db->escape_string($duration), $db->escape_string($fileName), $permissionid, $userid);
3406
3407 if (!$mediaid = $db->insert_query($SQL))
3408@@ -565,19 +565,19 @@
3409 $this->response->keepOpen = true;
3410 return $this->response;
3411 }
3412-
3413+
3414 // File upload directory.. get this from the settings object
3415 $databaseDir = Config::GetSetting($db, "LIBRARY_LOCATION");
3416-
3417+
3418 // What are we going to store this media as...
3419 $storedAs = $mediaid.".".$ext;
3420-
3421+
3422 // Now we need to move the file
3423 if (!$result = rename($databaseDir."temp/".$tmpName, $databaseDir.$storedAs))
3424 {
3425 // If we couldnt move it - we need to delete the media record we just added
3426 $SQL = sprintf("DELETE FROM media WHERE mediaID = %d ", $mediaid);
3427-
3428+
3429 if (!$db->query($SQL))
3430 {
3431 trigger_error($db->error());
3432@@ -586,23 +586,27 @@
3433 return $this->response;
3434 }
3435 }
3436-
3437+
3438+ // Calculate the MD5 and the file size
3439+ $md5 = md5_file($databaseDir.$storedAs);
3440+ $fileSize = filesize($databaseDir.$storedAs);
3441+
3442 // Update the media record to include this information
3443- $SQL = sprintf("UPDATE media SET storedAs = '%s' WHERE mediaid = %d", $storedAs, $mediaid);
3444-
3445+ $SQL = sprintf("UPDATE media SET storedAs = '%s', `MD5` = '%s', FileSize = %d WHERE mediaid = %d", $storedAs, $md5, $fileSize, $mediaid);
3446+
3447 if (!$db->query($SQL))
3448 {
3449 trigger_error($db->error());
3450 return true;
3451 }
3452-
3453+
3454 // Required Attributes
3455 $this->mediaid = $mediaid;
3456 $this->duration = $duration;
3457-
3458+
3459 // Any Options
3460 $this->SetOption('uri', $storedAs);
3461-
3462+
3463 // Should have built the media object entirely by this time
3464 if ($regionid != '')
3465 {
3466@@ -612,18 +616,18 @@
3467 }
3468 else
3469 {
3470- $this->response->loadFormUri = "index.php?p=content&q=displayForms&sp=add";
3471+ $this->response->loadFormUri = "index.php?p=content&q=displayForms&sp=add";
3472 }
3473-
3474+
3475 // We want to load a new form
3476 $this->response->loadForm = true;
3477-
3478+
3479 return $this->response;
3480 }
3481-
3482+
3483 /**
3484 * Edit Media in the Database
3485- * @return
3486+ * @return
3487 */
3488 public function EditMedia()
3489 {
3490@@ -632,13 +636,13 @@
3491 $regionid = $this->regionid;
3492 $mediaid = $this->mediaid;
3493 $userid = Kit::GetParam('userid', _SESSION, _INT);
3494-
3495+
3496 // Stored As from the XML
3497 $storedAs = $this->GetOption('uri');
3498-
3499+
3500 // File data
3501 $tmpName = Kit::GetParam('hidFileID', _POST, _STRING);
3502-
3503+
3504 if ($tmpName == '')
3505 {
3506 $fileRevision = false;
3507@@ -646,12 +650,12 @@
3508 else
3509 {
3510 $fileRevision = true;
3511-
3512+
3513 // File name and extension (orignial name)
3514 $fileName = Kit::GetParam('txtFileName', _POST, _STRING);
3515 $fileName = basename($fileName);
3516 $ext = strtolower(substr(strrchr($fileName, "."), 1));
3517-
3518+
3519 // Validation
3520 if ($ext != "wmv" && $ext != "mpeg" && $ext != "mpg")
3521 {
3522@@ -660,17 +664,17 @@
3523 return $this->response;
3524 }
3525 }
3526-
3527+
3528 // Other properties
3529 $name = Kit::GetParam('name', _POST, _STRING);
3530 $duration = Kit::GetParam('duration', _POST, _INT, 0);
3531 $permissionid = Kit::GetParam('permissionid', _POST, _INT, 1);
3532-
3533+
3534 if ($name == '')
3535 {
3536 if ($fileRevision)
3537 {
3538- $name = Kit::ValidateParam($fileName, _FILENAME);
3539+ $name = Kit::ValidateParam($fileName, _FILENAME);
3540 }
3541 else
3542 {
3543@@ -678,26 +682,26 @@
3544 $this->response->keepOpen = true;
3545 return $this->response;
3546 }
3547- }
3548-
3549+ }
3550+
3551 // Make sure the name isnt too long
3552- if (strlen($name) > 100)
3553+ if (strlen($name) > 100)
3554 {
3555 $this->response->SetError('The name cannot be longer than 100 characters');
3556 $this->response->keepOpen = true;
3557 return $this->response;
3558 }
3559-
3560+
3561 // Ensure the name is not already in the database
3562 $SQL = sprintf("SELECT name FROM media WHERE name = '%s' AND userid = %d AND mediaid <> %d ", $db->escape_string($name), $userid, $mediaid);
3563
3564- if(!$result = $db->query($SQL))
3565+ if(!$result = $db->query($SQL))
3566 {
3567 trigger_error($db->error());
3568 $this->response->SetError('Error checking whether the media name is ok. Try choosing a different name.');
3569 $this->response->keepOpen = true;
3570 return $this->response;
3571- }
3572+ }
3573
3574 if ($db->num_rows($result) != 0)
3575 {
3576@@ -705,34 +709,34 @@
3577 $this->response->keepOpen = true;
3578 return $this->response;
3579 }
3580-
3581+
3582 //Are we revising this media - or just plain editing
3583 if ($fileRevision)
3584 {
3585 // All OK to insert this record
3586 $SQL = "INSERT INTO media (name, type, duration, originalFilename, permissionID, userID, retired ) ";
3587 $SQL .= "VALUES ('%s', '%s', '%s', '%s', %d, %d, 0) ";
3588-
3589+
3590 $SQL = sprintf($SQL, $db->escape_string($name), $this->type, $db->escape_string($duration), $db->escape_string($fileName), $permissionid, $userid);
3591-
3592+
3593 if (!$new_mediaid = $db->insert_query($SQL))
3594 {
3595 trigger_error($db->error());
3596 trigger_error('Error inserting replacement media record.', E_USER_ERROR);
3597 }
3598-
3599+
3600 //What are we going to store this media as...
3601 $storedAs = $new_mediaid.".".$ext;
3602-
3603+
3604 // File upload directory.. get this from the settings object
3605 $databaseDir = Config::GetSetting($db, "LIBRARY_LOCATION");
3606-
3607+
3608 //Now we need to move the file
3609 if (!$result = rename($databaseDir."/temp/".$tmpName, $databaseDir.$storedAs))
3610 {
3611 //If we couldnt move it - we need to delete the media record we just added
3612 $SQL = "DELETE FROM media WHERE mediaID = $new_mediaid ";
3613-
3614+
3615 if (!$db->insert_query($SQL))
3616 {
3617 $this->response->SetError('Error rolling back transcation.');
3618@@ -740,23 +744,28 @@
3619 return $this->response;
3620 }
3621 }
3622-
3623+
3624+ // Calculate the MD5 and the file size
3625+ $md5 = md5_file($databaseDir.$storedAs);
3626+ $fileSize = filesize($databaseDir.$storedAs);
3627+
3628 // Update the media record to include this information
3629- $SQL = "UPDATE media SET storedAs = '$storedAs' WHERE mediaid = $new_mediaid";
3630+ $SQL = sprintf("UPDATE media SET storedAs = '%s', `MD5` = '%s', FileSize = %d WHERE mediaid = %d", $storedAs, $md5, $fileSize, $new_mediaid);
3631+
3632 if (!$db->query($SQL))
3633 {
3634 trigger_error($db->error());
3635- $this->response->SetError('Error updating media with Library location.');
3636+ $this->response->SetError('Database error editing this media record.');
3637 $this->response->keepOpen = true;
3638 return $this->response;
3639 }
3640-
3641+
3642 // Update the existing record with the new record's id
3643 $SQL = "UPDATE media SET isEdited = 1, editedMediaID = $new_mediaid ";
3644 $SQL .= " WHERE IFNULL(editedMediaID,0) <> $new_mediaid AND mediaID = $mediaid ";
3645-
3646+
3647 Debug::LogEntry($db, 'audit', $SQL);
3648-
3649+
3650 if (!$db->query($SQL))
3651 {
3652 trigger_error($db->error());
3653@@ -770,54 +779,54 @@
3654 {
3655 // Editing the existing record
3656 $new_mediaid = $mediaid;
3657-
3658+
3659 $SQL = "UPDATE media SET name = '%s', duration = %d, permissionID = %d";
3660 $SQL .= " WHERE mediaID = %d ";
3661 $SQL = sprintf($SQL, $db->escape_string($name), $duration, $permissionid, $mediaid);
3662-
3663+
3664 Debug::LogEntry($db, 'audit', $SQL);
3665-
3666+
3667 if (!$db->query($SQL))
3668 {
3669 trigger_error($db->error());
3670-
3671+
3672 $this->response->SetError('Database error editing this media record.');
3673 $this->response->keepOpen = true;
3674 return $this->response;
3675 }
3676 }
3677-
3678+
3679 // Required Attributes
3680 $this->mediaid = $new_mediaid;
3681 $this->duration = $duration;
3682-
3683+
3684 // Any Options
3685 $this->SetOption('uri', $storedAs);
3686-
3687+
3688 // Should have built the media object entirely by this time
3689 if ($regionid != '')
3690 {
3691 // This saves the Media Object to the Region
3692 $this->UpdateRegion();
3693-
3694+
3695 $this->response->loadForm = true;
3696 $this->response->loadFormUri = "index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions";;
3697 }
3698 else
3699 {
3700- $this->response->loadFormUri = "index.php?p=content&q=displayForms&sp=add";
3701+ $this->response->loadFormUri = "index.php?p=content&q=displayForms&sp=add";
3702 $this->response->message = 'Edited the Video.';
3703-
3704+
3705 }
3706-
3707+
3708 return $this->response;
3709 }
3710-
3711+
3712 /**
3713 * Delete Media from the Database
3714- * @return
3715+ * @return
3716 */
3717- public function DeleteMedia()
3718+ public function DeleteMedia()
3719 {
3720 $db =& $this->db;
3721 $layoutid = $this->layoutid;
3722@@ -825,10 +834,10 @@
3723 $mediaid = $this->mediaid;
3724 $userid = Kit::GetParam('userid', _SESSION, _INT);
3725 $options = Kit::GetParam('options', _POST, _WORD);
3726-
3727+
3728 // Stored As from the XML
3729 $this->uri = $this->GetOption('uri');
3730-
3731+
3732 // Do we need to remove this from a layout?
3733 if ($layoutid != '')
3734 {
3735@@ -840,72 +849,72 @@
3736 // Set this message now in preparation
3737 $this->response->message = 'Deleted the Media.';
3738 }
3739-
3740+
3741 // If we are set to retire we retire
3742 if ($options == "retire")
3743 {
3744 //Update the media record to say it is retired
3745 $SQL = "UPDATE media SET retired = 1 WHERE mediaid = $mediaid ";
3746-
3747+
3748 if (!$db->query($SQL))
3749 {
3750 trigger_error($db->error());
3751-
3752+
3753 $this->response->SetError('Database error retiring this media record.');
3754 $this->response->keepOpen = true;
3755 return $this->response;
3756 }
3757 }
3758-
3759+
3760 //If we are set to delete, we delete
3761 if ($options == "delete")
3762 {
3763 //Update the media record to say it is retired
3764 $SQL = "DELETE FROM media WHERE mediaid = $mediaid ";
3765-
3766+
3767 if (!$db->query($SQL))
3768 {
3769 trigger_error($db->error());
3770-
3771+
3772 $this->response->SetError('Database error deleting this media record.');
3773 $this->response->keepOpen = true;
3774 return $this->response;
3775 }
3776-
3777+
3778 $this->DeleteMediaFiles();
3779 }
3780-
3781+
3782 return $this->response;
3783 }
3784-
3785+
3786 /**
3787 * Deletes the media files associated with this record
3788- * @return
3789+ * @return
3790 */
3791 private function DeleteMediaFiles()
3792 {
3793 $db =& $this->db;
3794-
3795+
3796 //Library location
3797 $databaseDir = Config::GetSetting($db, "LIBRARY_LOCATION");
3798-
3799+
3800 //3 things to check for..
3801 //the actual file, the thumbnail, the background
3802 if (file_exists($databaseDir.$this->uri))
3803 {
3804 unlink($databaseDir.$this->uri);
3805 }
3806-
3807+
3808 if (file_exists($databaseDir."tn_".$this->uri))
3809 {
3810 unlink($databaseDir."tn_".$this->uri);
3811 }
3812-
3813+
3814 if (file_exists($databaseDir."bg_".$this->uri))
3815 {
3816 unlink($databaseDir."bg_".$this->uri);
3817 }
3818-
3819+
3820 return true;
3821 }
3822 }
3823
3824=== modified file 'server/xmds.php'
3825--- server/xmds.php 2009-08-08 11:04:39 +0000
3826+++ server/xmds.php 2009-09-29 22:15:24 +0000
3827@@ -8,7 +8,7 @@
3828 * Xibo is free software: you can redistribute it and/or modify
3829 * it under the terms of the GNU Affero General Public License as published by
3830 * the Free Software Foundation, either version 3 of the License, or
3831- * any later version.
3832+ * any later version.
3833 *
3834 * Xibo is distributed in the hope that it will be useful,
3835 * but WITHOUT ANY WARRANTY; without even the implied warranty of
3836@@ -29,71 +29,71 @@
3837 function Auth($hardwareKey)
3838 {
3839 global $db;
3840-
3841+
3842 //check in the database for this hardwareKey
3843 $SQL = "SELECT licensed, inc_schedule, isAuditing, displayID FROM display WHERE license = '$hardwareKey'";
3844- if (!$result = $db->query($SQL))
3845+ if (!$result = $db->query($SQL))
3846 {
3847 trigger_error("License key query failed:" .$db->error());
3848 return false;
3849 }
3850-
3851+
3852 //Is it there?
3853- if ($db->num_rows($result) == 0)
3854+ if ($db->num_rows($result) == 0)
3855 {
3856 return false;
3857 }
3858- else
3859+ else
3860 {
3861 //we have seen this display before, so check the licensed value
3862 $row = $db->get_row($result);
3863- if ($row[0] == 0)
3864+ if ($row[0] == 0)
3865 {
3866 return false;
3867 }
3868- else
3869+ else
3870 {
3871 $time = date("Y-m-d H:i:s", time());
3872-
3873+
3874 //Set the last accessed flag on the display
3875 $SQL = "UPDATE display SET lastaccessed = '$time', loggedin = 1 WHERE license = '$hardwareKey' ";
3876- if (!$result = $db->query($SQL))
3877+ if (!$result = $db->query($SQL))
3878 {
3879 trigger_error("Display update access failure: " .$db->error());
3880 }
3881-
3882+
3883 //It is licensed
3884 return array("licensed" => true, "inc_schedule" => $row[1], "isAuditing" => $row[2], "displayid" => $row[3]);
3885 }
3886 }
3887-
3888+
3889 return false;
3890 }
3891
3892 /**
3893 * Checks that the calling service is talking the correct version
3894- * @return
3895+ * @return
3896 * @param $version Object
3897 */
3898 function CheckVersion($version)
3899 {
3900 global $db;
3901-
3902+
3903 // Look up the Service XMDS version from the Version table
3904 $serverVersion = Config::Version($db, 'XmdsVersion');
3905-
3906+
3907 if ($version != $serverVersion)
3908 {
3909 Debug::LogEntry($db, 'audit', sprintf('A Client with an incorrect version connected. Client Version: [%s] Server Version [%s]', $version, $serverVersion));
3910 return false;
3911 }
3912-
3913+
3914 return true;
3915 }
3916
3917 /**
3918 * Registers the Display with the server - if there is an available slot
3919- * @return
3920+ * @return
3921 * @param $serverKey Object
3922 * @param $hardwareKey Object
3923 * @param $displayName Object
3924@@ -101,66 +101,66 @@
3925 function RegisterDisplay($serverKey, $hardwareKey, $displayName, $version)
3926 {
3927 global $db;
3928-
3929+
3930 // Sanitize
3931 $serverKey = Kit::ValidateParam($serverKey, _STRING);
3932 $hardwareKey = Kit::ValidateParam($hardwareKey, _STRING);
3933 $displayName = Kit::ValidateParam($displayName, _STRING);
3934 $version = Kit::ValidateParam($version, _STRING);
3935-
3936+
3937 // Make sure we are talking the same language
3938 if (!CheckVersion($version))
3939 {
3940 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);
3941 }
3942-
3943+
3944 define('SERVER_KEY', Config::GetSetting($db, 'SERVER_KEY'));
3945-
3946+
3947 Debug::LogEntry($db, "audit", "[IN]", "xmds", "RegisterDisplay");
3948 Debug::LogEntry($db, "audit", "serverKey [$serverKey], hardwareKey [$hardwareKey], displayName [$displayName]", "xmds", "RegisterDisplay");
3949-
3950+
3951 //Check the serverKey matches the one we have stored in this servers lic.txt file
3952 if ($serverKey != SERVER_KEY)
3953 {
3954 return new soap_fault("SOAP-ENV:Client", "", "The Server key you entered does not match with the server key at this address", $serverKey);
3955 }
3956-
3957+
3958 // Check the Length of the hardwareKey
3959 if (strlen($hardwareKey) > 40)
3960 {
3961 return new soap_fault("SOAP-ENV:Client", "", "The Hardware Key you sent was too long. Only 40 characters are allowed (SHA1).", $hardwareKey);
3962 }
3963-
3964+
3965 //check in the database for this hardwareKey
3966 $SQL = "SELECT licensed, display FROM display WHERE license = '$hardwareKey'";
3967- if (!$result = $db->query($SQL))
3968+ if (!$result = $db->query($SQL))
3969 {
3970 trigger_error("License key query failed:" .$db->error());
3971 return new soap_fault("SOAP-ENV:Server", "", "License Key Query Failed, see server errorlog", $db->error());
3972 }
3973-
3974+
3975 //Is it there?
3976- if ($db->num_rows($result) == 0)
3977+ if ($db->num_rows($result) == 0)
3978 {
3979 //Add this display record
3980 $SQL = sprintf("INSERT INTO display (display, defaultlayoutid, license, licensed) VALUES ('%s', 1, '%s', 0)", $displayName, $hardwareKey);
3981- if (!$displayid = $db->insert_query($SQL))
3982+ if (!$displayid = $db->insert_query($SQL))
3983 {
3984 trigger_error($db->error());
3985 return new soap_fault("SOAP-ENV:Server", "", "Error adding display");
3986 }
3987 $active = "Display added and is awaiting licensing approval from an Administrator";
3988 }
3989- else
3990+ else
3991 {
3992 //we have seen this display before, so check the licensed value
3993 $row = $db->get_row($result);
3994- if ($row[0] == 0)
3995+ if ($row[0] == 0)
3996 {
3997 //Its Not licensed
3998 $active = "Display is awaiting licensing approval from an Administrator.";
3999 }
4000- else
4001+ else
4002 {
4003 //It is licensed
4004 //Now check the names
4005@@ -172,21 +172,21 @@
4006 {
4007 //Update the name
4008 $SQL = sprintf("UPDATE display SET display = '%s' WHERE license = '%s' ", $displayName, $hardwareKey);
4009-
4010- if (!$db->query($SQL))
4011+
4012+ if (!$db->query($SQL))
4013 {
4014 trigger_error($db->error());
4015 return new soap_fault("SOAP-ENV:Server", "", "Error editing the display name");
4016 }
4017-
4018+
4019 $active = "Changed display name from '{$row[1]}' to '$displayName' Display is active and ready to start.";
4020 }
4021 }
4022 }
4023-
4024- Debug::LogEntry($db, "audit", "$active", "xmds", "RegisterDisplay");
4025- Debug::LogEntry($db, "audit", "[OUT]", "xmds", "RegisterDisplay");
4026-
4027+
4028+ Debug::LogEntry($db, "audit", "$active", "xmds", "RegisterDisplay");
4029+ Debug::LogEntry($db, "audit", "[OUT]", "xmds", "RegisterDisplay");
4030+
4031 return $active;
4032 }
4033
4034@@ -198,12 +198,12 @@
4035 function RequiredFiles($serverKey, $hardwareKey, $version)
4036 {
4037 global $db;
4038-
4039+
4040 // Sanitize
4041 $serverKey = Kit::ValidateParam($serverKey, _STRING);
4042 $hardwareKey = Kit::ValidateParam($hardwareKey, _STRING);
4043 $version = Kit::ValidateParam($version, _STRING);
4044-
4045+
4046 // Make sure we are talking the same language
4047 if (!CheckVersion($version))
4048 {
4049@@ -211,29 +211,29 @@
4050 }
4051
4052 $libraryLocation = Config::GetSetting($db, "LIBRARY_LOCATION");
4053-
4054+
4055 //auth this request...
4056 if (!$displayInfo = Auth($hardwareKey))
4057 {
4058 trigger_error("This display is not licensed [$hardwareKey]");
4059 return new soap_fault("SOAP-ENV:Client", "", "This display client is not licensed");
4060 }
4061-
4062- if ($displayInfo['isAuditing'] == 1)
4063+
4064+ if ($displayInfo['isAuditing'] == 1)
4065 {
4066- Debug::LogEntry($db, "audit", "[IN]", "xmds", "RequiredFiles");
4067- Debug::LogEntry($db, "audit", "$hardwareKey", "xmds", "RequiredFiles");
4068+ Debug::LogEntry($db, "audit", "[IN]", "xmds", "RequiredFiles");
4069+ Debug::LogEntry($db, "audit", "$hardwareKey", "xmds", "RequiredFiles");
4070 }
4071-
4072+
4073 $requiredFilesXml = new DOMDocument("1.0");
4074 $fileElements = $requiredFilesXml->createElement("files");
4075-
4076+
4077 $requiredFilesXml->appendChild($fileElements);
4078-
4079+
4080 $currentdate = date("Y-m-d H:i:s");
4081 $time = time();
4082 $plus4hours = date("Y-m-d H:i:s",$time + 86400);
4083-
4084+
4085 //Add file nodes to the $fileElements
4086 //Firstly get all the scheduled layouts
4087 $SQL = " SELECT layout.layoutID, schedule_detail.starttime, schedule_detail.endtime, layout.xml, layout.background ";
4088@@ -241,9 +241,9 @@
4089 $SQL .= " INNER JOIN schedule_detail ON schedule_detail.layoutID = layout.layoutID ";
4090 $SQL .= " INNER JOIN display ON schedule_detail.displayID = display.displayID ";
4091 $SQL .= sprintf(" WHERE display.license = '%s' ", $hardwareKey);
4092-
4093+
4094 $SQLBase = $SQL;
4095-
4096+
4097 //Do we include the default display
4098 if ($displayInfo['inc_schedule'] == 1)
4099 {
4100@@ -254,15 +254,15 @@
4101 {
4102 $SQL .= sprintf(" AND (schedule_detail.starttime < '%s' AND schedule_detail.endtime > '%s' )", $plus4hours, $currentdate);
4103 }
4104-
4105- if ($displayInfo['isAuditing'] == 1) Debug::LogEntry($db, "audit", "$SQL", "xmds", "RequiredFiles");
4106+
4107+ if ($displayInfo['isAuditing'] == 1) Debug::LogEntry($db, "audit", "$SQL", "xmds", "RequiredFiles");
4108
4109 if (!$results = $db->query($SQL))
4110 {
4111 trigger_error($db->error());
4112 return new soap_fault("SOAP-ENV:Server", "", "Unable to get a list of files", $db->error());
4113 }
4114-
4115+
4116 // Was there anything?
4117 if ($db->num_rows($results) == 0)
4118 {
4119@@ -270,119 +270,138 @@
4120 $SQL = $SQLBase;
4121 $SQL .= sprintf(" AND ((schedule_detail.starttime < '%s' AND schedule_detail.endtime > '%s' )", $plus4hours, $currentdate);
4122 $SQL .= " OR (schedule_detail.starttime = '2050-12-31 00:00:00' AND schedule_detail.endtime = '2050-12-31 00:00:00' ))";
4123-
4124+
4125 if (!$results = $db->query($SQL))
4126 {
4127 trigger_error($db->error());
4128 return new soap_fault("SOAP-ENV:Server", "", "Unable to get A list of layouts for the schedule", $db->error());
4129 }
4130 }
4131-
4132+
4133 while ($row = $db->get_row($results))
4134 {
4135 $layoutid = $row[0];
4136 $layoutXml = $row[3];
4137 $background = $row[4];
4138-
4139+
4140 // Add all the associated media first
4141- $SQL = "SELECT storedAs, media.mediaID
4142- FROM media
4143- INNER JOIN lklayoutmedia ON lklayoutmedia.mediaID = media.mediaID
4144- WHERE storedAs IS NOT NULL
4145+ $SQL = "SELECT storedAs, media.mediaID, media.`MD5`, media.FileSize
4146+ FROM media
4147+ INNER JOIN lklayoutmedia ON lklayoutmedia.mediaID = media.mediaID
4148+ WHERE storedAs IS NOT NULL
4149 AND lklayoutmedia.layoutID = $layoutid
4150- AND media.mediaID NOT IN (SELECT MediaID
4151- FROM blacklist
4152- WHERE DisplayID = " . $displayInfo['displayid'] . "
4153+ AND media.mediaID NOT IN (SELECT MediaID
4154+ FROM blacklist
4155+ WHERE DisplayID = " . $displayInfo['displayid'] . "
4156 AND isIgnored = 0 )";
4157-
4158+
4159 if (!$mediaResults = $db->query($SQL))
4160 {
4161 trigger_error($db->error());
4162 return new soap_fault("SOAP-ENV:Server", "", "Unable to get a list of media for the layout [$layoutid]");
4163 }
4164-
4165+
4166 while ($row = $db->get_row($mediaResults))
4167 {
4168+ $storedAs = Kit::ValidateParam($row[0], _STRING);
4169+ $mediaId = Kit::ValidateParam($row[1], _INT);
4170+ $md5 = Kit::ValidateParam($row[2], _STRING);
4171+ $fileSize = Kit::ValidateParam($row[3], _INT);
4172+
4173+ // If they are empty calculate them and save them back to the media.
4174+ if ($md5 == '' || $fileSize == 0)
4175+ {
4176+
4177+ $md5 = md5_file($libraryLocation.$row[0]);
4178+ $fileSize = filesize($libraryLocation.$row[0]);
4179+
4180+ // Update the media record with this information
4181+ $SQL = sprintf("UPDATE media SET `MD5` = '%s', FileSize = %d WHERE MediaID = %d", $md5, $fileSize, $mediaId);
4182+
4183+ if (!$db->query($SQL))
4184+ trigger_error($db->error());
4185+ }
4186+
4187 //Add the file node
4188 $file = $requiredFilesXml->createElement("file");
4189-
4190+
4191 $file->setAttribute("type", "media");
4192- $file->setAttribute("path", $row[0]);
4193- $file->setAttribute("id", $row[1]);
4194- $file->setAttribute("size", filesize($libraryLocation.$row[0]));
4195- $file->setAttribute("md5", md5_file($libraryLocation.$row[0]));
4196-
4197+ $file->setAttribute("path", $storedAs);
4198+ $file->setAttribute("id", $mediaId);
4199+ $file->setAttribute("size", $fileSize);
4200+ $file->setAttribute("md5", $md5);
4201+
4202 $fileElements->appendChild($file);
4203 }
4204-
4205+
4206 //Also append another file node for the background image (if there is one)
4207 if ($background != "")
4208 {
4209 //firstly add this as a node
4210 $file = $requiredFilesXml->createElement("file");
4211-
4212+
4213 $file->setAttribute("type", "media");
4214 $file->setAttribute("path", $background);
4215 $file->setAttribute("md5", md5_file($libraryLocation.$background));
4216 $file->setAttribute("size", filesize($libraryLocation.$background));
4217-
4218+
4219 $fileElements->appendChild($file);
4220 }
4221-
4222+
4223 // Add this layout as node
4224 $file = $requiredFilesXml->createElement("file");
4225-
4226+
4227 $file->setAttribute("type", "layout");
4228 $file->setAttribute("path", $layoutid);
4229 $file->setAttribute("md5", md5($layoutXml . "\n"));
4230-
4231+
4232 $fileElements->appendChild($file);
4233 }
4234-
4235+
4236 //
4237 // Add a blacklist node
4238 //
4239 $blackList = $requiredFilesXml->createElement("file");
4240 $blackList->setAttribute("type", "blacklist");
4241-
4242+
4243 $fileElements->appendChild($blackList);
4244-
4245+
4246 // Populate
4247- $SQL = "SELECT MediaID
4248- FROM blacklist
4249- WHERE DisplayID = " . $displayInfo['displayid'] . "
4250+ $SQL = "SELECT MediaID
4251+ FROM blacklist
4252+ WHERE DisplayID = " . $displayInfo['displayid'] . "
4253 AND isIgnored = 0";
4254-
4255+
4256 if (!$results = $db->query($SQL))
4257 {
4258 trigger_error($db->error());
4259 return new soap_fault("SOAP-ENV:Server", "", "Unable to get a list of blacklisted files", $db->error());
4260 }
4261-
4262+
4263 // Add a black list element for each file
4264 while ($row = $db->get_row($results))
4265 {
4266 $file = $requiredFilesXml->createElement("file");
4267 $file->setAttribute("id", $row[0]);
4268-
4269+
4270 $blackList->appendChild($file);
4271 }
4272
4273 // PHONE_HOME if required.
4274- if (Config::GetSetting($db,'PHONE_HOME') == 'On') {
4275- // Find out when we last PHONED_HOME :D
4276- // If it's been > 28 days since last PHONE_HOME then
4277+ if (Config::GetSetting($db,'PHONE_HOME') == 'On') {
4278+ // Find out when we last PHONED_HOME :D
4279+ // If it's been > 28 days since last PHONE_HOME then
4280 if (Config::GetSetting($db,'PHONE_HOME_DATE') < (time() - (60 * 60 * 24 * 28))) {
4281
4282- if ($displayInfo['isAuditing'] == 1)
4283+ if ($displayInfo['isAuditing'] == 1)
4284 {
4285- Debug::LogEntry($db, "audit", "PHONE_HOME [IN]", "xmds", "RequiredFiles");
4286- }
4287-
4288- // Retrieve number of displays
4289- $SQL = "SELECT COUNT(*)
4290- FROM `display`
4291- WHERE `licensed` = '1'";
4292+ Debug::LogEntry($db, "audit", "PHONE_HOME [IN]", "xmds", "RequiredFiles");
4293+ }
4294+
4295+ // Retrieve number of displays
4296+ $SQL = "SELECT COUNT(*)
4297+ FROM `display`
4298+ WHERE `licensed` = '1'";
4299 if (!$results = $db->query($SQL))
4300 {
4301 trigger_error($db->error());
4302@@ -390,52 +409,52 @@
4303 while ($row = $db->get_row($results))
4304 {
4305 $PHONE_HOME_CLIENTS = Kit::ValidateParam($row[0],_INT);
4306- }
4307-
4308- // Retrieve version number
4309- $PHONE_HOME_VERSION = Config::Version($db, 'app_ver');
4310-
4311- $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);
4312-
4313- if ($displayInfo['isAuditing'] == 1)
4314+ }
4315+
4316+ // Retrieve version number
4317+ $PHONE_HOME_VERSION = Config::Version($db, 'app_ver');
4318+
4319+ $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);
4320+
4321+ if ($displayInfo['isAuditing'] == 1)
4322 {
4323- Debug::LogEntry($db, "audit", "PHONE_HOME_URL " . $PHONE_HOME_URL , "xmds", "RequiredFiles");
4324+ Debug::LogEntry($db, "audit", "PHONE_HOME_URL " . $PHONE_HOME_URL , "xmds", "RequiredFiles");
4325 }
4326-
4327- // Set PHONE_HOME_TIME to NOW.
4328- $SQL = "UPDATE `setting`
4329- SET `value` = '" . time() . "'
4330- WHERE `setting`.`setting` = 'PHONE_HOME_DATE' LIMIT 1";
4331-
4332+
4333+ // Set PHONE_HOME_TIME to NOW.
4334+ $SQL = "UPDATE `setting`
4335+ SET `value` = '" . time() . "'
4336+ WHERE `setting`.`setting` = 'PHONE_HOME_DATE' LIMIT 1";
4337+
4338 if (!$results = $db->query($SQL))
4339 {
4340 trigger_error($db->error());
4341 }
4342-
4343+
4344 @file_get_contents($PHONE_HOME_URL);
4345
4346- if ($displayInfo['isAuditing'] == 1)
4347+ if ($displayInfo['isAuditing'] == 1)
4348 {
4349- Debug::LogEntry($db, "audit", "PHONE_HOME [OUT]", "xmds", "RequiredFiles");
4350+ Debug::LogEntry($db, "audit", "PHONE_HOME [OUT]", "xmds", "RequiredFiles");
4351 }
4352- //endif
4353+ //endif
4354 }
4355 }
4356- // END OF PHONE_HOME CODE
4357-
4358- if ($displayInfo['isAuditing'] == 1)
4359+ // END OF PHONE_HOME CODE
4360+
4361+ if ($displayInfo['isAuditing'] == 1)
4362 {
4363- Debug::LogEntry($db, "audit", $requiredFilesXml->saveXML(), "xmds", "RequiredFiles");
4364- Debug::LogEntry($db, "audit", "[OUT]", "xmds", "RequiredFiles");
4365+ Debug::LogEntry($db, "audit", $requiredFilesXml->saveXML(), "xmds", "RequiredFiles");
4366+ Debug::LogEntry($db, "audit", "[OUT]", "xmds", "RequiredFiles");
4367 }
4368-
4369+
4370 // Return the results of requiredFiles()
4371 return $requiredFilesXml->saveXML();
4372 }
4373
4374 /**
4375 * Gets the specified file
4376- * @return
4377+ * @return
4378 * @param $hardwareKey Object
4379 * @param $filePath Object
4380 * @param $fileType Object
4381@@ -443,7 +462,7 @@
4382 function GetFile($serverKey, $hardwareKey, $filePath, $fileType, $chunkOffset, $chunkSize, $version)
4383 {
4384 global $db;
4385-
4386+
4387 // Sanitize
4388 $serverKey = Kit::ValidateParam($serverKey, _STRING);
4389 $hardwareKey = Kit::ValidateParam($hardwareKey, _STRING);
4390@@ -451,83 +470,83 @@
4391 $chunkOffset = Kit::ValidateParam($chunkOffset, _INT);
4392 $chunkSize = Kit::ValidateParam($chunkSize, _INT);
4393 $version = Kit::ValidateParam($version, _STRING);
4394-
4395+
4396 $libraryLocation = Config::GetSetting($db, "LIBRARY_LOCATION");
4397-
4398+
4399 // Make sure we are talking the same language
4400 if (!CheckVersion($version))
4401 {
4402 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);
4403 }
4404-
4405+
4406 //auth this request...
4407 if (!$displayInfo = Auth($hardwareKey))
4408 {
4409 return new soap_fault("SOAP-ENV:Client", "", "This display client is not licensed");
4410 }
4411-
4412- if ($displayInfo['isAuditing'] == 1)
4413+
4414+ if ($displayInfo['isAuditing'] == 1)
4415 {
4416- Debug::LogEntry($db, "audit", "[IN]", "xmds", "GetFile");
4417- Debug::LogEntry($db, "audit", "Params: [$hardwareKey] [$filePath] [$fileType] [$chunkOffset] [$chunkSize]", "xmds", "GetFile");
4418+ Debug::LogEntry($db, "audit", "[IN]", "xmds", "GetFile");
4419+ Debug::LogEntry($db, "audit", "Params: [$hardwareKey] [$filePath] [$fileType] [$chunkOffset] [$chunkSize]", "xmds", "GetFile");
4420 }
4421
4422 if ($fileType == "layout")
4423 {
4424 $filePath = Kit::ValidateParam($filePath, _INT);
4425-
4426+
4427 $SQL = sprintf("SELECT xml FROM layout WHERE layoutid = %d", $filePath);
4428 if (!$results = $db->query($SQL))
4429 {
4430 trigger_error($db->error());
4431 return new soap_fault("SOAP-ENV:Server", "", "Unable to get a list of files", $db->error());
4432 }
4433-
4434+
4435 $row = $db->get_row($results);
4436-
4437+
4438 $file = $row[0];
4439 }
4440 elseif ($fileType == "media")
4441 {
4442 $filePath = Kit::ValidateParam($filePath, _STRING);
4443-
4444+
4445 //Return the Chunk size specified
4446 $f = fopen($libraryLocation.$filePath,"r");
4447-
4448+
4449 fseek($f, $chunkOffset);
4450-
4451+
4452 $file = fread($f, $chunkSize);
4453 }
4454- else
4455+ else
4456 {
4457 return new soap_fault("SOAP-ENV:Client", "", "Unknown FileType Requested.");
4458 }
4459-
4460- if ($displayInfo['isAuditing'] == 1) Debug::LogEntry($db, "audit", "[OUT]", "xmds", "GetFile");
4461-
4462+
4463+ if ($displayInfo['isAuditing'] == 1) Debug::LogEntry($db, "audit", "[OUT]", "xmds", "GetFile");
4464+
4465 return base64_encode($file);
4466 }
4467
4468 /**
4469 * Returns the schedule for the hardware key specified
4470- * @return
4471+ * @return
4472 * @param $hardwareKey Object
4473 */
4474 function Schedule($serverKey, $hardwareKey, $version)
4475 {
4476 global $db;
4477-
4478+
4479 // Sanitize
4480 $serverKey = Kit::ValidateParam($serverKey, _STRING);
4481 $hardwareKey = Kit::ValidateParam($hardwareKey, _STRING);
4482 $version = Kit::ValidateParam($version, _STRING);
4483-
4484+
4485 // Make sure we are talking the same language
4486 if (!CheckVersion($version))
4487 {
4488 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);
4489 }
4490-
4491+
4492 //auth this request...
4493 if (!$displayInfo = Auth($hardwareKey))
4494 {
4495@@ -535,16 +554,16 @@
4496 }
4497
4498 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry($db, "audit", "[IN] $hardwareKey", "xmds", "Schedule");
4499-
4500+
4501 $scheduleXml = new DOMDocument("1.0");
4502 $layoutElements = $scheduleXml->createElement("schedule");
4503-
4504+
4505 $scheduleXml->appendChild($layoutElements);
4506-
4507+
4508 $currentdate = date("Y-m-d H:i:s");
4509 $time = time();
4510 $plus4hours = date("Y-m-d H:i:s",$time + 86400);
4511-
4512+
4513 //Add file nodes to the $fileElements
4514 //Firstly get all the scheduled layouts
4515 $SQL = " SELECT layout.layoutID, schedule_detail.starttime, schedule_detail.endtime, schedule_detail.eventID ";
4516@@ -553,15 +572,15 @@
4517 $SQL .= " INNER JOIN display ON schedule_detail.displayID = display.displayID ";
4518 $SQL .= " WHERE display.license = '$hardwareKey' ";
4519 $SQL .= " AND layout.retired = 0 ";
4520-
4521+
4522 // Store the Base SQL for this display
4523 $SQLBase = $SQL;
4524-
4525+
4526 // Run the query
4527 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry($db, "audit", "$SQL", "xmds", "Schedule");
4528-
4529-
4530-
4531+
4532+
4533+
4534 // Do we include the default display
4535 if ($displayInfo['inc_schedule'] == 1)
4536 {
4537@@ -572,20 +591,20 @@
4538 {
4539 $SQL .= " AND (schedule_detail.starttime < '$currentdate' AND schedule_detail.endtime > '$currentdate' )";
4540 }
4541-
4542+
4543 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry($db, "audit", "$SQL", "xmds", "Schedule");
4544-
4545-
4546+
4547+
4548 // Before we run the main query we should check to see if there are any priority layouts to deal with
4549 $SQLp = " AND schedule_detail.is_priority = 1 ";
4550-
4551+
4552 // Run the query
4553 if (!$results = $db->query($SQL . $SQLp))
4554 {
4555 trigger_error($db->error());
4556 return new soap_fault("SOAP-ENV:Server", "", "Unable to get A list of layouts for the schedule", $db->error());
4557 }
4558-
4559+
4560 // If there were no results then continue to get the full schedule
4561 if ($db->num_rows($results) == 0)
4562 {
4563@@ -595,7 +614,7 @@
4564 trigger_error($db->error());
4565 return new soap_fault("SOAP-ENV:Server", "", "Unable to get A list of layouts for the schedule", $db->error());
4566 }
4567-
4568+
4569 // Was there anything?
4570 if ($db->num_rows($results) == 0)
4571 {
4572@@ -603,7 +622,7 @@
4573 $SQL = $SQLBase;
4574 $SQL .= " AND ((schedule_detail.starttime < '$currentdate' AND schedule_detail.endtime > '$currentdate' )";
4575 $SQL .= " OR (schedule_detail.starttime = '2050-12-31 00:00:00' AND schedule_detail.endtime = '2050-12-31 00:00:00' ))";
4576-
4577+
4578 if (!$results = $db->query($SQL))
4579 {
4580 trigger_error($db->error());
4581@@ -611,7 +630,7 @@
4582 }
4583 }
4584 }
4585-
4586+
4587 // We must have some results in here by this point
4588 while ($row = $db->get_row($results))
4589 {
4590@@ -619,42 +638,42 @@
4591 $fromdt = $row[1];
4592 $todt = $row[2];
4593 $scheduleid = $row[3];
4594-
4595+
4596 //firstly add this as a node
4597 $layout = $scheduleXml->createElement("layout");
4598-
4599+
4600 $layout->setAttribute("file", $layoutid);
4601 $layout->setAttribute("fromdt", $fromdt);
4602 $layout->setAttribute("todt", $todt);
4603 $layout->setAttribute("scheduleid", $scheduleid);
4604-
4605+
4606 $layoutElements->appendChild($layout);
4607 }
4608-
4609+
4610 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry($db, "audit", $scheduleXml->saveXML(), "xmds", "Schedule");
4611 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry($db, "audit", "[OUT]", "xmds", "Schedule");
4612-
4613+
4614 return $scheduleXml->saveXML();
4615 }
4616
4617 /**
4618 * Recieves the XmlLog from the display
4619- * @return
4620+ * @return
4621 * @param $hardwareKey String
4622 * @param $xml String
4623 */
4624 function RecieveXmlLog($serverKey, $hardwareKey, $xml, $version)
4625 {
4626 global $db;
4627-
4628+
4629 return new soap_fault("SOAP-ENV:Client", "", "This is a depricated service call. You should instead call either SubmitLog or SubmitStats", $serverKey);
4630 }
4631
4632 define('BLACKLIST_ALL', "All");
4633 define('BLACKLIST_SINGLE', "Single");
4634 /**
4635- *
4636- * @return
4637+ *
4638+ * @return
4639 * @param $hardwareKey Object
4640 * @param $mediaId Object
4641 * @param $type Object
4642@@ -662,7 +681,7 @@
4643 function BlackList($serverKey, $hardwareKey, $mediaId, $type, $reason, $version)
4644 {
4645 global $db;
4646-
4647+
4648 // Sanitize
4649 $serverKey = Kit::ValidateParam($serverKey, _STRING);
4650 $hardwareKey = Kit::ValidateParam($hardwareKey, _STRING);
4651@@ -670,7 +689,7 @@
4652 $type = Kit::ValidateParam($type, _STRING);
4653 $reason = Kit::ValidateParam($reason, _STRING);
4654 $version = Kit::ValidateParam($version, _STRING);
4655-
4656+
4657 // Make sure we are talking the same language
4658 if (!CheckVersion($version))
4659 {
4660@@ -682,19 +701,19 @@
4661 {
4662 return new soap_fault("SOAP-ENV:Client", "", "This display client is not licensed", $hardwareKey);
4663 }
4664-
4665+
4666 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry ($db, "audit", "[IN]", "xmds", "BlackList", "", $displayInfo['displayid']);
4667 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry ($db, "audit", "$xml", "xmds", "BlackList", "", $displayInfo['displayid']);
4668-
4669+
4670 // Check to see if this media/display is already blacklisted (and not ignored)
4671 $SQL = "SELECT BlackListID FROM blacklist WHERE MediaID = $mediaId AND isIgnored = 0 AND DisplayID = " . $displayInfo['displayid'];
4672-
4673+
4674 if (!$results = $db->query($SQL))
4675 {
4676 trigger_error($db->error());
4677 return new soap_fault("SOAP-ENV:Server", "", "Unable to query for BlackList records.", $db->error());
4678 }
4679-
4680+
4681 if ($db->num_rows($results) == 0)
4682 {
4683 // Insert the black list record
4684@@ -705,20 +724,20 @@
4685 // Only the current display
4686 $SQL .= " WHERE displayID = " . $displayInfo['displayid'];
4687 }
4688-
4689+
4690 if (!$displays = $db->query($SQL))
4691 {
4692 trigger_error($db->error());
4693 return new soap_fault("SOAP-ENV:Server", "", "Unable to query for BlackList Displays.", $db->error());
4694 }
4695-
4696+
4697 while ($row = $db->get_row($displays))
4698 {
4699 $displayId = $row[0];
4700-
4701+
4702 $SQL = "INSERT INTO blacklist (MediaID, DisplayID, ReportingDisplayID, Reason)
4703 VALUES ($mediaId, $displayId, " . $displayInfo['displayid'] . ", '$reason') ";
4704-
4705+
4706 if (!$db->query($SQL))
4707 {
4708 trigger_error($db->error());
4709@@ -730,15 +749,15 @@
4710 {
4711 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry ($db, "audit", "Media Already BlackListed [$mediaId]", "xmds", "BlackList", "", $displayInfo['displayid']);
4712 }
4713-
4714+
4715 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry ($db, "audit", "[OUT]", "xmds", "BlackList", "", $displayInfo['displayid']);
4716-
4717+
4718 return true;
4719 }
4720
4721 /**
4722 * Submit client logging
4723- * @return
4724+ * @return
4725 * @param $version Object
4726 * @param $serverKey Object
4727 * @param $hardwareKey Object
4728@@ -747,13 +766,13 @@
4729 function SubmitLog($version, $serverKey, $hardwareKey, $logXml)
4730 {
4731 global $db;
4732-
4733+
4734 // Sanitize
4735 $serverKey = Kit::ValidateParam($serverKey, _STRING);
4736 $hardwareKey = Kit::ValidateParam($hardwareKey, _STRING);
4737 $version = Kit::ValidateParam($version, _STRING);
4738 $logXml = Kit::ValidateParam($logXml, _HTMLSTRING);
4739-
4740+
4741 // Make sure we are talking the same language
4742 if (!CheckVersion($version))
4743 {
4744@@ -765,20 +784,20 @@
4745 {
4746 return new soap_fault("SOAP-ENV:Client", "", "This display client is not licensed", $hardwareKey);
4747 }
4748-
4749+
4750 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry ($db, "audit", "IN", "xmds", "SubmitLog", "", $displayInfo['displayid']);
4751 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry ($db, "audit", 'XML [' . $logXml . ']', "xmds", "SubmitLog", "", $displayInfo['displayid']);
4752-
4753+
4754 // Load the XML into a DOMDocument
4755 $document = new DOMDocument("1.0");
4756-
4757+
4758 if (!$document->loadXML($logXml))
4759 {
4760 return new soap_fault("SOAP-ENV:Client", "", "XML Cannot be loaded into DOM Document.", $hardwareKey);
4761 }
4762-
4763+
4764 foreach ($document->documentElement->childNodes as $node)
4765- {
4766+ {
4767 //Zero out the common vars
4768 $date = "";
4769 $message = "";
4770@@ -787,23 +806,23 @@
4771 $mediaID = "";
4772 $cat = '';
4773 $method = '';
4774-
4775+
4776 // This will be a bunch of trace nodes
4777 $message = $node->textContent;
4778-
4779- // Each element should have a category and a date
4780+
4781+ // Each element should have a category and a date
4782 $date = $node->getAttribute('date');
4783 $cat = $node->getAttribute('category');
4784-
4785- if ($date == '' || $cat == '')
4786+
4787+ if ($date == '' || $cat == '')
4788 {
4789 trigger_error('Log submitted without a date or category attribute');
4790 continue;
4791 }
4792-
4793+
4794 // Get the date and the message (all log types have these)
4795 foreach ($node->childNodes as $nodeElements)
4796- {
4797+ {
4798 if ($nodeElements->nodeName == "scheduleID")
4799 {
4800 $scheduleID = $nodeElements->textContent;
4801@@ -825,26 +844,26 @@
4802 $method = $nodeElements->textContent;
4803 }
4804 }
4805-
4806+
4807 // We should have enough information to log this now.
4808 if ($cat == 'error' || $cat == 'Error')
4809 {
4810- Debug::LogEntry($db, $cat, $message, 'Client', $method, $date, $displayInfo['displayid'], $scheduleID, $layoutID, $mediaID);
4811+ Debug::LogEntry($db, $cat, $message, 'Client', $method, $date, $displayInfo['displayid'], $scheduleID, $layoutID, $mediaID);
4812 }
4813 else
4814 {
4815- Debug::LogEntry($db, 'audit', $message, 'Client', $method, $date, $displayInfo['displayid'], $scheduleID, $layoutID, $mediaID);
4816+ Debug::LogEntry($db, 'audit', $message, 'Client', $method, $date, $displayInfo['displayid'], $scheduleID, $layoutID, $mediaID);
4817 }
4818 }
4819
4820 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry ($db, "audit", "OUT", "xmds", "SubmitLog", "", $displayInfo['displayid']);
4821-
4822+
4823 return true;
4824 }
4825
4826 /**
4827 * Submit display statistics to the server
4828- * @return
4829+ * @return
4830 * @param $version Object
4831 * @param $serverKey Object
4832 * @param $hardwareKey Object
4833@@ -853,13 +872,13 @@
4834 function SubmitStats($version, $serverKey, $hardwareKey, $statXml)
4835 {
4836 global $db;
4837-
4838+
4839 // Sanitize
4840 $serverKey = Kit::ValidateParam($serverKey, _STRING);
4841 $hardwareKey = Kit::ValidateParam($hardwareKey, _STRING);
4842 $version = Kit::ValidateParam($version, _STRING);
4843 $statXml = Kit::ValidateParam($statXml, _HTMLSTRING);
4844-
4845+
4846 // Make sure we are talking the same language
4847 if (!CheckVersion($version))
4848 {
4849@@ -871,55 +890,55 @@
4850 {
4851 return new soap_fault("SOAP-ENV:Client", "", "This display client is not licensed", $hardwareKey);
4852 }
4853-
4854+
4855 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry ($db, "audit", "IN", "xmds", "SubmitStats", "", $displayInfo['displayid']);
4856 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry ($db, "audit", "StatXml: [" . $statXml . "]", "xmds", "SubmitStats", "", $displayInfo['displayid']);
4857-
4858+
4859 if ($statXml == "")
4860 {
4861 return new soap_fault("SOAP-ENV:Client", "", "Stat XML is empty.", $hardwareKey);
4862 }
4863-
4864+
4865 // Log
4866 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry ($db, "audit", "About to create Stat Object.", "xmds", "SubmitStats", "", $displayInfo['displayid']);
4867-
4868+
4869 $statObject = new Stat($db);
4870-
4871+
4872 // Log
4873 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry ($db, "audit", "About to Create DOMDocument.", "xmds", "SubmitStats", "", $displayInfo['displayid']);
4874-
4875+
4876 // Load the XML into a DOMDocument
4877 $document = new DOMDocument("1.0");
4878 $document->loadXML($statXml);
4879-
4880+
4881 foreach ($document->documentElement->childNodes as $node)
4882- {
4883+ {
4884 //Zero out the common vars
4885 $fromdt = '';
4886 $todt = '';
4887 $type = '';
4888-
4889+
4890 $scheduleID = 0;
4891 $layoutID = 0;
4892 $mediaID = '';
4893 $tag = '';
4894-
4895+
4896 // Each element should have these attributes
4897 $fromdt = $node->getAttribute('fromdt');
4898 $todt = $node->getAttribute('todt');
4899 $type = $node->getAttribute('type');
4900-
4901- if ($fromdt == '' || $todt == '' || $type == '')
4902+
4903+ if ($fromdt == '' || $todt == '' || $type == '')
4904 {
4905 trigger_error('Stat submitted without the fromdt, todt or type attributes.');
4906 continue;
4907 }
4908-
4909+
4910 $scheduleID = $node->getAttribute('scheduleid');
4911 $layoutID = $node->getAttribute('layoutid');
4912 $mediaID = $node->getAttribute('mediaid');
4913 $tag = $node->getAttribute('tag');
4914-
4915+
4916 // Write the stat record with the information we have available to us.
4917 if (!$statObject->Add($type, $fromdt, $todt, $scheduleID, $displayInfo['displayid'], $layoutID, $mediaID, $tag))
4918 {
4919@@ -929,7 +948,7 @@
4920 }
4921
4922 if ($displayInfo['isAuditing'] == 1) Debug::LogEntry ($db, "audit", "OUT", "xmds", "SubmitStats", "", $displayInfo['displayid']);
4923-
4924+
4925 return true;
4926 }
4927
4928@@ -938,7 +957,7 @@
4929
4930 $service->configureWSDL("xmds", "urn:xmds");
4931
4932-$service->register("RegisterDisplay",
4933+$service->register("RegisterDisplay",
4934 array('serverKey' => 'xsd:string', 'hardwareKey' => 'xsd:string', 'displayName' => 'xsd:string', 'version' => 'xsd:string'),
4935 array('ActivationMessage' => 'xsd:string'),
4936 'urn:xmds',
4937@@ -947,8 +966,8 @@
4938 'encoded',
4939 'Registered the Display on the Xibo Network'
4940 );
4941-
4942-$service->register("RequiredFiles",
4943+
4944+$service->register("RequiredFiles",
4945 array('serverKey' => 'xsd:string', 'hardwareKey' => 'xsd:string', 'version' => 'xsd:string'),
4946 array('RequiredFilesXml' => 'xsd:string'),
4947 'urn:xmds',
4948@@ -957,8 +976,8 @@
4949 'encoded',
4950 'The files required by the requesting display'
4951 );
4952-
4953-$service->register("GetFile",
4954+
4955+$service->register("GetFile",
4956 array('serverKey' => 'xsd:string', 'hardwareKey' => 'xsd:string', 'filePath' => 'xsd:string', 'fileType' => 'xsd:string', 'chunkOffset' => 'xsd:int', 'chuckSize' => 'xsd:int', 'version' => 'xsd:string'),
4957 array('file' => 'xsd:base64Binary'),
4958 'urn:xmds',
4959@@ -966,9 +985,9 @@
4960 'rpc',
4961 'encoded',
4962 'Gets the file requested'
4963- );
4964-
4965-$service->register("Schedule",
4966+ );
4967+
4968+$service->register("Schedule",
4969 array('serverKey' => 'xsd:string', 'hardwareKey' => 'xsd:string', 'version' => 'xsd:string'),
4970 array('ScheduleXml' => 'xsd:string'),
4971 'urn:xmds',
4972@@ -976,8 +995,8 @@
4973 'rpc',
4974 'encoded',
4975 'Gets the schedule'
4976- );
4977-
4978+ );
4979+
4980 $service->register("RecieveXmlLog",
4981 array('serverKey' => 'xsd:string', 'hardwareKey' => 'xsd:string', 'xml' => 'xsd:string', 'version' => 'xsd:string'),
4982 array('success' => 'xsd:boolean'),
4983@@ -997,7 +1016,7 @@
4984 'encoded',
4985 'Set media to be blacklisted'
4986 );
4987-
4988+
4989 $service->register("SubmitLog",
4990 array('version' => 'xsd:string', 'serverKey' => 'xsd:string', 'hardwareKey' => 'xsd:string', 'logXml' => 'xsd:string'),
4991 array('success' => 'xsd:boolean'),
4992@@ -1007,7 +1026,7 @@
4993 'encoded',
4994 'Submit Logging from the Client'
4995 );
4996-
4997+
4998 $service->register("SubmitStats",
4999 array('version' => 'xsd:string', 'serverKey' => 'xsd:string', 'hardwareKey' => 'xsd:string', 'statXml' => 'xsd:string'),
5000 array('success' => 'xsd:boolean'),
The diff has been truncated for viewing.

Subscribers

People subscribed via source and target branches