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

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

Subscribers

People subscribed via source and target branches