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
=== added file 'server/install/database/8.sql'
--- server/install/database/8.sql 1970-01-01 00:00:00 +0000
+++ server/install/database/8.sql 2009-10-01 21:40:24 +0000
@@ -0,0 +1,13 @@
1ALTER TABLE `module` ADD `ValidExtensions` VARCHAR( 254 ) NULL ;
2
3UPDATE `module` SET `ValidExtensions` = 'jpg,jpeg,png,bmp,gif' WHERE `module`.`ModuleID` =1 LIMIT 1 ;
4
5UPDATE `module` SET `ValidExtensions` = 'wmv,avi,mpg,mpeg' WHERE `module`.`ModuleID` =2 LIMIT 1 ;
6
7UPDATE `module` SET `ValidExtensions` = 'swf' WHERE `module`.`ModuleID` =3 LIMIT 1 ;
8
9UPDATE `module` SET `ValidExtensions` = 'ppt,pps' WHERE `module`.`ModuleID` =4 LIMIT 1 ;
10
11UPDATE `version` SET `app_ver` = '1.0.4';
12UPDATE `setting` SET `value` = 0 WHERE `setting` = 'PHONE_HOME_DATE';
13UPDATE `version` SET `DBVersion` = '8';
014
=== modified file 'server/lib/modules/module.class.php'
--- server/lib/modules/module.class.php 2009-09-22 18:39:19 +0000
+++ server/lib/modules/module.class.php 2009-10-01 21:40:24 +0000
@@ -8,7 +8,7 @@
8 * Xibo is free software: you can redistribute it and/or modify8 * Xibo is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Affero General Public License as published by9 * it under the terms of the GNU Affero General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or10 * the Free Software Foundation, either version 3 of the License, or
11 * any later version. 11 * any later version.
12 *12 *
13 * Xibo is distributed in the hope that it will be useful,13 * Xibo is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -27,26 +27,28 @@
27 protected $user;27 protected $user;
28 protected $region;28 protected $region;
29 protected $response;29 protected $response;
30 30
31 protected $layoutid;31 protected $layoutid;
32 protected $regionid;32 protected $regionid;
33 33
34 protected $mediaid;34 protected $mediaid;
35 protected $name;35 protected $name;
36 protected $type;36 protected $type;
37 private $schemaVersion;37 private $schemaVersion;
38 protected $regionSpecific;38 protected $regionSpecific;
39 protected $duration;39 protected $duration;
40 protected $lkid;40 protected $lkid;
41 protected $validExtensions;
42 protected $validExtensionsText;
4143
42 protected $xml;44 protected $xml;
43 45
44 protected $existingMedia;46 protected $existingMedia;
45 protected $deleteFromRegion;47 protected $deleteFromRegion;
46 48
47 /**49 /**
48 * Constructor - sets up this media object with all the available information50 * Constructor - sets up this media object with all the available information
49 * @return 51 * @return
50 * @param $db database52 * @param $db database
51 * @param $user user53 * @param $user user
52 * @param $mediaid String[optional]54 * @param $mediaid String[optional]
@@ -56,74 +58,77 @@
56 public function __construct(database $db, user $user, $mediaid = '', $layoutid = '', $regionid = '')58 public function __construct(database $db, user $user, $mediaid = '', $layoutid = '', $regionid = '')
57 {59 {
58 include_once("lib/pages/region.class.php");60 include_once("lib/pages/region.class.php");
59 61
60 $this->db =& $db;62 $this->db =& $db;
61 $this->user =& $user;63 $this->user =& $user;
62 64
63 $this->mediaid = $mediaid;65 $this->mediaid = $mediaid;
64 $this->name = '';66 $this->name = '';
65 $this->layoutid = $layoutid;67 $this->layoutid = $layoutid;
66 $this->regionid = $regionid;68 $this->regionid = $regionid;
67 69
68 $this->region = new region($db, $user);70 $this->region = new region($db, $user);
69 $this->response = new ResponseManager();71 $this->response = new ResponseManager();
70 72
71 $this->existingMedia = false;73 $this->existingMedia = false;
72 $this->deleteFromRegion = false;74 $this->deleteFromRegion = false;
73 $this->lkid = '';75 $this->lkid = '';
74 $this->duration = '';76 $this->duration = '';
75 77
76 // Determine which type this module is78 // Determine which type this module is
77 $this->SetModuleInformation();79 $this->SetModuleInformation();
78 80
79 Debug::LogEntry($db, 'audit', 'New module created with MediaID: ' . $mediaid . ' LayoutID: ' . $layoutid . ' and RegionID: ' . $regionid);81 Debug::LogEntry($db, 'audit', 'New module created with MediaID: ' . $mediaid . ' LayoutID: ' . $layoutid . ' and RegionID: ' . $regionid);
80 82
81 // Either the information from the region - or some blanks83 // Either the information from the region - or some blanks
82 $this->SetMediaInformation($this->layoutid, $this->regionid, $mediaid);84 $this->SetMediaInformation($this->layoutid, $this->regionid, $mediaid);
83 85
84 return true;86 return true;
85 }87 }
86 88
87 /**89 /**
88 * Sets the module information90 * Sets the module information
89 * @return 91 * @return
90 */92 */
91 final private function SetModuleInformation()93 final private function SetModuleInformation()
92 {94 {
93 $db =& $this->db;95 $db =& $this->db;
94 $type = $this->type;96 $type = $this->type;
95 97
96 if ($type == '')98 if ($type == '')
97 {99 {
98 $this->response->SetError(__('Unable to create Module [No type given] - please refer to the Module Documentation.'));100 $this->response->SetError(__('Unable to create Module [No type given] - please refer to the Module Documentation.'));
99 $this->response->Respond();101 $this->response->Respond();
100 }102 }
101 103
102 $SQL = sprintf("SELECT * FROM module WHERE Module = '%s'", $db->escape_string($type));104 $SQL = sprintf("SELECT * FROM module WHERE Module = '%s'", $db->escape_string($type));
103 105
104 if (!$result = $db->query($SQL)) 106 if (!$result = $db->query($SQL))
105 {107 {
106 $this->response->SetError(__('Unable to create Module [Cannot find type in the database] - please refer to the Module Documentation.'));108 $this->response->SetError(__('Unable to create Module [Cannot find type in the database] - please refer to the Module Documentation.'));
107 $this->response->Respond();109 $this->response->Respond();
108 }110 }
109 111
110 if ($db->num_rows($result) != 1)112 if ($db->num_rows($result) != 1)
111 {113 {
112 $this->response->SetError(__('Unable to create Module [No registered modules of this type] - please refer to the Module Documentation.'));114 $this->response->SetError(__('Unable to create Module [No registered modules of this type] - please refer to the Module Documentation.'));
113 $this->response->Respond();115 $this->response->Respond();
114 }116 }
115 117
116 $row = $db->get_assoc_row($result);118 $row = $db->get_assoc_row($result);
117 119
118 $this->schemaVersion = Kit::ValidateParam($row['SchemaVersion'], _INT);120 $this->schemaVersion = Kit::ValidateParam($row['SchemaVersion'], _INT);
119 $this->regionSpecific = Kit::ValidateParam($row['RegionSpecific'], _INT);121 $this->regionSpecific = Kit::ValidateParam($row['RegionSpecific'], _INT);
120 122 $this->validExtensionsText = Kit::ValidateParam($row['ValidExtensions'], _STRING);
123 $this->validExtensions = explode(',', $this->validExtensionsText);
124 $this->validExtensionsText = str_replace(',', ', ', $this->validExtensionsText);
125
121 return true;126 return true;
122 }127 }
123 128
124 /**129 /**
125 * Gets the information about this Media on this region on this layout130 * Gets the information about this Media on this region on this layout
126 * @return 131 * @return
127 * @param $layoutid Object132 * @param $layoutid Object
128 * @param $regionid Object133 * @param $regionid Object
129 * @param $mediaid Object134 * @param $mediaid Object
@@ -133,28 +138,28 @@
133 $db =& $this->db;138 $db =& $this->db;
134 $region =& $this->region;139 $region =& $this->region;
135 $xmlDoc = new DOMDocument();140 $xmlDoc = new DOMDocument();
136 141
137 if ($this->mediaid != '' && $this->regionid != '' && $this->layoutid != '')142 if ($this->mediaid != '' && $this->regionid != '' && $this->layoutid != '')
138 {143 {
139 $this->existingMedia = true;144 $this->existingMedia = true;
140 145
141 // Set the layout Xml146 // Set the layout Xml
142 $layoutXml = $region->GetLayoutXml($layoutid);147 $layoutXml = $region->GetLayoutXml($layoutid);
143 148
144 Debug::LogEntry($db, 'audit', 'Layout XML retrieved: ' . $layoutXml);149 Debug::LogEntry($db, 'audit', 'Layout XML retrieved: ' . $layoutXml);
145 150
146 $layoutDoc = new DOMDocument();151 $layoutDoc = new DOMDocument();
147 $layoutDoc->loadXML($layoutXml);152 $layoutDoc->loadXML($layoutXml);
148 153
149 $layoutXpath = new DOMXPath($layoutDoc);154 $layoutXpath = new DOMXPath($layoutDoc);
150 155
151 // Get the media node and extract the info156 // Get the media node and extract the info
152 $mediaNodeXpath = $layoutXpath->query("//region[@id='$regionid']/media[@id='$mediaid']");157 $mediaNodeXpath = $layoutXpath->query("//region[@id='$regionid']/media[@id='$mediaid']");
153 158
154 if ($mediaNodeXpath->length > 0)159 if ($mediaNodeXpath->length > 0)
155 {160 {
156 Debug::LogEntry($db, 'audit', 'Media Node Found.');161 Debug::LogEntry($db, 'audit', 'Media Node Found.');
157 162
158 // Create a Media node in the DOMDocument for us to replace163 // Create a Media node in the DOMDocument for us to replace
159 $xmlDoc->loadXML('<root/>');164 $xmlDoc->loadXML('<root/>');
160 }165 }
@@ -163,13 +168,13 @@
163 $this->response->SetError(__('Cannot find this media item. Please refresh the region options.'));168 $this->response->SetError(__('Cannot find this media item. Please refresh the region options.'));
164 $this->response->Respond();169 $this->response->Respond();
165 }170 }
166 171
167 $mediaNode = $mediaNodeXpath->item(0);172 $mediaNode = $mediaNodeXpath->item(0);
168 $mediaNode->setAttribute('schemaVersion', $this->schemaVersion);173 $mediaNode->setAttribute('schemaVersion', $this->schemaVersion);
169 174
170 $this->duration = $mediaNode->getAttribute('duration');175 $this->duration = $mediaNode->getAttribute('duration');
171 $this->lkid = $mediaNode->getAttribute('lkid');176 $this->lkid = $mediaNode->getAttribute('lkid');
172 177
173 $mediaNode = $xmlDoc->importNode($mediaNode, true);178 $mediaNode = $xmlDoc->importNode($mediaNode, true);
174 $xmlDoc->documentElement->appendChild($mediaNode);179 $xmlDoc->documentElement->appendChild($mediaNode);
175 }180 }
@@ -181,25 +186,25 @@
181 // But this is some existing media186 // But this is some existing media
182 // Therefore make sure we get the bare minimum!187 // Therefore make sure we get the bare minimum!
183 $this->existingMedia = true;188 $this->existingMedia = true;
184 189
185 // Load what we know about this media into the object190 // Load what we know about this media into the object
186 $SQL = "SELECT duration, name FROM media WHERE mediaID = '$mediaid'";191 $SQL = "SELECT duration, name FROM media WHERE mediaID = '$mediaid'";
187 192
188 Debug::LogEntry($db, 'audit', $SQL, 'Module', 'SetMediaInformation');193 Debug::LogEntry($db, 'audit', $SQL, 'Module', 'SetMediaInformation');
189 194
190 if (!$result = $db->query($SQL))195 if (!$result = $db->query($SQL))
191 {196 {
192 trigger_error($db->error()); //log the error197 trigger_error($db->error()); //log the error
193 }198 }
194 199
195 if ($db->num_rows($result) != 0)200 if ($db->num_rows($result) != 0)
196 {201 {
197 $row = $db->get_row($result);202 $row = $db->get_row($result);
198 $this->duration = $row[0];203 $this->duration = $row[0];
199 $this->name = $row[1];204 $this->name = $row[1];
200 }205 }
201 }206 }
202 207
203 $xml = <<<XML208 $xml = <<<XML
204 <root>209 <root>
205 <media id="" type="$this->type" duration="" lkid="" schemaVersion="$this->schemaVersion">210 <media id="" type="$this->type" duration="" lkid="" schemaVersion="$this->schemaVersion">
@@ -210,32 +215,32 @@
210XML;215XML;
211 $xmlDoc->loadXML($xml);216 $xmlDoc->loadXML($xml);
212 }217 }
213 218
214 $this->xml = $xmlDoc;219 $this->xml = $xmlDoc;
215 220
216 Debug::LogEntry($db, 'audit', 'XML is: ' . $this->xml->saveXML());221 Debug::LogEntry($db, 'audit', 'XML is: ' . $this->xml->saveXML());
217 222
218 return true;223 return true;
219 }224 }
220 225
221 /**226 /**
222 * Sets the Layout and Region Information227 * Sets the Layout and Region Information
223 * @return 228 * @return
224 * @param $layoutid Object229 * @param $layoutid Object
225 * @param $regionid Object230 * @param $regionid Object
226 * @param $mediaid Object231 * @param $mediaid Object
227 */232 */
228 public function SetRegionInformation($layoutid, $regionid)233 public function SetRegionInformation($layoutid, $regionid)
229 { 234 {
230 $this->layoutid = $layoutid;235 $this->layoutid = $layoutid;
231 $this->regionid = $regionid;236 $this->regionid = $regionid;
232 237
233 return true;238 return true;
234 }239 }
235 240
236 /**241 /**
237 * This Media item represented as XML242 * This Media item represented as XML
238 * @return 243 * @return
239 */244 */
240 final public function AsXml()245 final public function AsXml()
241 {246 {
@@ -248,17 +253,17 @@
248 // LkID is done by the region code (where applicable - otherwise it will be left blank)253 // LkID is done by the region code (where applicable - otherwise it will be left blank)
249 $mediaNodes = $this->xml->getElementsByTagName('media');254 $mediaNodes = $this->xml->getElementsByTagName('media');
250 $mediaNode = $mediaNodes->item(0);255 $mediaNode = $mediaNodes->item(0);
251 256
252 $mediaNode->setAttribute('id', $this->mediaid);257 $mediaNode->setAttribute('id', $this->mediaid);
253 $mediaNode->setAttribute('duration', $this->duration);258 $mediaNode->setAttribute('duration', $this->duration);
254 $mediaNode->setAttribute('type', $this->type);259 $mediaNode->setAttribute('type', $this->type);
255 260
256 return $this->xml->saveXML($mediaNode);261 return $this->xml->saveXML($mediaNode);
257 }262 }
258 263
259 /**264 /**
260 * Adds the name/value element to the XML Options sequence 265 * Adds the name/value element to the XML Options sequence
261 * @return 266 * @return
262 * @param $name String267 * @param $name String
263 * @param $value String268 * @param $value String
264 */269 */
@@ -266,25 +271,25 @@
266 {271 {
267 $db =& $this->db;272 $db =& $this->db;
268 if ($name == '') return;273 if ($name == '') return;
269 274
270 Debug::LogEntry($db, 'audit', sprintf('IN with Name=%s and value=%s', $name, $value), 'module', 'Set Option'); 275 Debug::LogEntry($db, 'audit', sprintf('IN with Name=%s and value=%s', $name, $value), 'module', 'Set Option');
271 276
272 // Get the options node from this document277 // Get the options node from this document
273 $optionNodes = $this->xml->getElementsByTagName('options');278 $optionNodes = $this->xml->getElementsByTagName('options');
274 // There is only 1279 // There is only 1
275 $optionNode = $optionNodes->item(0);280 $optionNode = $optionNodes->item(0);
276 281
277 // Create a new option node282 // Create a new option node
278 $newNode = $this->xml->createElement($name, $value);283 $newNode = $this->xml->createElement($name, $value);
279 284
280 Debug::LogEntry($db, 'audit', sprintf('Created a new Option Node with Name=%s and value=%s', $name, $value), 'module', 'Set Option');285 Debug::LogEntry($db, 'audit', sprintf('Created a new Option Node with Name=%s and value=%s', $name, $value), 'module', 'Set Option');
281 286
282 // Check to see if we already have this option or not287 // Check to see if we already have this option or not
283 $xpath = new DOMXPath($this->xml);288 $xpath = new DOMXPath($this->xml);
284 289
285 // Xpath for it290 // Xpath for it
286 $userOptions = $xpath->query('//options/' . $name);291 $userOptions = $xpath->query('//options/' . $name);
287 292
288 if ($userOptions->length == 0)293 if ($userOptions->length == 0)
289 {294 {
290 // Append the new node to the list295 // Append the new node to the list
@@ -293,28 +298,28 @@
293 else298 else
294 {299 {
295 // Replace the old node we found with XPath with the new node we just created300 // Replace the old node we found with XPath with the new node we just created
296 $optionNode->replaceChild($newNode, $userOptions->item(0)); 301 $optionNode->replaceChild($newNode, $userOptions->item(0));
297 }302 }
298 }303 }
299 304
300 /**305 /**
301 * Gets the value for the option in Parameter 1306 * Gets the value for the option in Parameter 1
302 * @return 307 * @return
303 * @param $name String The Option Name308 * @param $name String The Option Name
304 * @param $default Object[optional] The Default Value309 * @param $default Object[optional] The Default Value
305 */310 */
306 final protected function GetOption($name, $default = false)311 final protected function GetOption($name, $default = false)
307 {312 {
308 $db =& $this->db;313 $db =& $this->db;
309 314
310 if ($name == '') return false;315 if ($name == '') return false;
311 316
312 // Check to see if we already have this option or not317 // Check to see if we already have this option or not
313 $xpath = new DOMXPath($this->xml);318 $xpath = new DOMXPath($this->xml);
314 319
315 // Xpath for it320 // Xpath for it
316 $userOptions = $xpath->query('//options/' . $name);321 $userOptions = $xpath->query('//options/' . $name);
317 322
318 if ($userOptions->length == 0)323 if ($userOptions->length == 0)
319 {324 {
320 // We do not have an option - return the default325 // We do not have an option - return the default
@@ -328,37 +333,37 @@
328 return $userOptions->item(0)->nodeValue;333 return $userOptions->item(0)->nodeValue;
329 }334 }
330 }335 }
331 336
332 /**337 /**
333 * Sets the RAW XML string that is given as the content for Raw338 * Sets the RAW XML string that is given as the content for Raw
334 * @return 339 * @return
335 * @param $xml String340 * @param $xml String
336 * @param $replace Boolean[optional]341 * @param $replace Boolean[optional]
337 */342 */
338 final protected function SetRaw($xml, $replace = false)343 final protected function SetRaw($xml, $replace = false)
339 {344 {
340 if ($xml == '') return;345 if ($xml == '') return;
341 346
342 // Load the XML we are given into its own document347 // Load the XML we are given into its own document
343 $rawNode = new DOMDocument();348 $rawNode = new DOMDocument();
344 $rawNode->loadXML('<raw>' . $xml . '</raw>');349 $rawNode->loadXML('<raw>' . $xml . '</raw>');
345 350
346 // Import the Raw node into this document (with all sub nodes)351 // Import the Raw node into this document (with all sub nodes)
347 $importedNode = $this->xml->importNode($rawNode->documentElement, true);352 $importedNode = $this->xml->importNode($rawNode->documentElement, true);
348 353
349 // Get the Raw Xml node from our document354 // Get the Raw Xml node from our document
350 $rawNodes = $this->xml->getElementsByTagName('raw');355 $rawNodes = $this->xml->getElementsByTagName('raw');
351356
352 // There is only 1357 // There is only 1
353 $rawNode = $rawNodes->item(0);358 $rawNode = $rawNodes->item(0);
354 359
355 // Append the imported node (at the end of whats already there)360 // Append the imported node (at the end of whats already there)
356 $rawNode->parentNode->replaceChild($importedNode, $rawNode);361 $rawNode->parentNode->replaceChild($importedNode, $rawNode);
357 }362 }
358 363
359 /**364 /**
360 * Gets the XML string from RAW365 * Gets the XML string from RAW
361 * @return 366 * @return
362 */367 */
363 final protected function GetRaw()368 final protected function GetRaw()
364 {369 {
@@ -367,21 +372,21 @@
367372
368 // There is only 1373 // There is only 1
369 $rawNode = $rawNodes->item(0);374 $rawNode = $rawNodes->item(0);
370 375
371 // Return it as a XML string376 // Return it as a XML string
372 return $this->xml->saveXML($rawNode);377 return $this->xml->saveXML($rawNode);
373 }378 }
374 379
375 /**380 /**
376 * Updates the region information with this media record381 * Updates the region information with this media record
377 * @return 382 * @return
378 */383 */
379 final public function UpdateRegion()384 final public function UpdateRegion()
380 {385 {
381 // By this point we expect to have a MediaID, duration386 // By this point we expect to have a MediaID, duration
382 $layoutid = $this->layoutid;387 $layoutid = $this->layoutid;
383 $regionid = $this->regionid;388 $regionid = $this->regionid;
384 389
385 if ($this->deleteFromRegion)390 if ($this->deleteFromRegion)
386 {391 {
387 // We call region delete392 // We call region delete
@@ -412,18 +417,27 @@
412 }417 }
413 }418 }
414 }419 }
415 420
416 return true;421 return true;
417 }422 }
418 423
424 /**
425 * Determines whether or not the provided file extension is valid for this module
426 *
427 */
428 final protected function IsValidExtension($extension)
429 {
430 return in_array($extension, $this->validExtensions);
431 }
432
419 /**433 /**
420 * Return the Delete Form as HTML434 * Return the Delete Form as HTML
421 * @return 435 * @return
422 */436 */
423 public function DeleteForm()437 public function DeleteForm()
424 {438 {
425 $db =& $this->db;439 $db =& $this->db;
426 440
427 //Parameters441 //Parameters
428 $layoutid = $this->layoutid;442 $layoutid = $this->layoutid;
429 $regionid = $this->regionid;443 $regionid = $this->regionid;
@@ -445,96 +459,115 @@
445 <input class="XiboFormButton" id="btnCancel" type="button" title="$msgTitle" href="index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions" value="No" />459 <input class="XiboFormButton" id="btnCancel" type="button" title="$msgTitle" href="index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions" value="No" />
446 </form>460 </form>
447END;461END;
448 462
449 $this->response->html = $form;463 $this->response->html = $form;
450 $this->response->dialogTitle = __('Delete Item');464 $this->response->dialogTitle = __('Delete Item');
451 $this->response->dialogSize = true;465 $this->response->dialogSize = true;
452 $this->response->dialogWidth = '450px';466 $this->response->dialogWidth = '450px';
453 $this->response->dialogHeight = '150px';467 $this->response->dialogHeight = '150px';
454468
455 return $this->response; 469 return $this->response;
456 }470 }
457 471
458 /**472 /**
459 * Delete Media from the Database473 * Delete Media from the Database
460 * @return 474 * @return
461 */475 */
462 public function DeleteMedia() 476 public function DeleteMedia()
463 {477 {
464 $db =& $this->db;478 $db =& $this->db;
465 479
466 $layoutid = $this->layoutid;480 $layoutid = $this->layoutid;
467 $regionid = $this->regionid;481 $regionid = $this->regionid;
468 482
469 $url = "index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions";483 $url = "index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions";
470 484
471 $this->deleteFromRegion = true;485 $this->deleteFromRegion = true;
472 $this->UpdateRegion();486 $this->UpdateRegion();
473 487
474 // We want to load a new form488 // We want to load a new form
475 $this->response->loadForm = true;489 $this->response->loadForm = true;
476 $this->response->loadFormUri= $url;490 $this->response->loadFormUri= $url;
477 491
478 return $this->response; 492 return $this->response;
479 }493 }
480 494
481 /**495 /**
482 * Default AddForm496 * Default AddForm
483 * @return 497 * @return
484 */498 */
485 public function AddForm()499 public function AddForm()
486 {500 {
487 $form = '<p>' . __('Not yet implemented by this module.') . '</p>';501 $form = '<p>' . __('Not yet implemented by this module.') . '</p>';
488END;502END;
489 503
490 $this->response->html = $form;504 $this->response->html = $form;
491 $this->response->dialogTitle = __('Add Item');505 $this->response->dialogTitle = __('Add Item');
492 $this->response->dialogSize = true;506 $this->response->dialogSize = true;
493 $this->response->dialogWidth = '450px';507 $this->response->dialogWidth = '450px';
494 $this->response->dialogHeight = '150px';508 $this->response->dialogHeight = '150px';
495509
496 return $this->response; 510 return $this->response;
497 }511 }
498 512
499 /**513 /**
500 * Default Edit Form514 * Default Edit Form
501 * @return 515 * @return
502 */516 */
503 public function EditForm()517 public function EditForm()
504 {518 {
519<<<<<<< TREE
505 $form = '<p>' . __('Not yet implemented by this module.') . '</p>';520 $form = '<p>' . __('Not yet implemented by this module.') . '</p>';
506 521
522=======
523 $form = <<<END
524 <p>Not yet implemented by this module.</p>
525END;
526
527>>>>>>> MERGE-SOURCE
507 $this->response->html = $form;528 $this->response->html = $form;
508 $this->response->dialogTitle = __('Add Item');529 $this->response->dialogTitle = __('Add Item');
509 $this->response->dialogSize = true;530 $this->response->dialogSize = true;
510 $this->response->dialogWidth = '450px';531 $this->response->dialogWidth = '450px';
511 $this->response->dialogHeight = '150px';532 $this->response->dialogHeight = '150px';
512533
513 return $this->response; 534 return $this->response;
514 }535 }
515 536
516 /**537 /**
517 * Default Add Media538 * Default Add Media
518 * @return 539 * @return
519 */540 */
520 public function AddMedia()541 public function AddMedia()
521 {542 {
522 // We want to load a new form543 // We want to load a new form
544<<<<<<< TREE
523 $this->response->message = __('Add Media has not been implemented for this module.');545 $this->response->message = __('Add Media has not been implemented for this module.');
524 546
525 return $this->response; 547 return $this->response;
548=======
549 $this->response->message = 'Add Media has not been implemented for this module.';
550
551 return $this->response;
552>>>>>>> MERGE-SOURCE
526 }553 }
527 554
528 /**555 /**
529 * Default EditMedia556 * Default EditMedia
530 * @return 557 * @return
531 */558 */
532 public function EditMedia()559 public function EditMedia()
533 {560 {
534 // We want to load a new form561 // We want to load a new form
562<<<<<<< TREE
535 $this->response->message = __('Edit Media has not been implemented for this module.');563 $this->response->message = __('Edit Media has not been implemented for this module.');
536 564
537 return $this->response; 565 return $this->response;
566=======
567 $this->response->message = 'Edit Media has not been implemented for this module.';
568
569 return $this->response;
570>>>>>>> MERGE-SOURCE
538 }571 }
539572
540 /**573 /**
@@ -544,10 +577,10 @@
544 public function GetName()577 public function GetName()
545 {578 {
546 $db =& $this->db;579 $db =& $this->db;
547 580
548 Debug::LogEntry($db, 'audit', sprintf('Module name returned for MediaID: %s is %s', $this->mediaid, $this->name), 'Module', 'GetName');581 Debug::LogEntry($db, 'audit', sprintf('Module name returned for MediaID: %s is %s', $this->mediaid, $this->name), 'Module', 'GetName');
549 582
550 return $this->name;583 return $this->name;
551 }584 }
552}585}
553?>586?>
554\ No newline at end of file587\ No newline at end of file
555588
=== modified file 'server/modules/flash.module.php'
--- server/modules/flash.module.php 2009-06-28 10:47:06 +0000
+++ server/modules/flash.module.php 2009-10-01 21:40:25 +0000
@@ -8,7 +8,7 @@
8 * Xibo is free software: you can redistribute it and/or modify8 * Xibo is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Affero General Public License as published by9 * it under the terms of the GNU Affero General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or10 * the Free Software Foundation, either version 3 of the License, or
11 * any later version. 11 * any later version.
12 *12 *
13 * Xibo is distributed in the hope that it will be useful,13 * Xibo is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -17,31 +17,31 @@
17 *17 *
18 * You should have received a copy of the GNU Affero General Public License18 * You should have received a copy of the GNU Affero General Public License
19 * along with Xibo. If not, see <http://www.gnu.org/licenses/>.19 * along with Xibo. If not, see <http://www.gnu.org/licenses/>.
20 */ 20 */
21class flash extends Module21class flash extends Module
22{22{
23 // Custom Media information23 // Custom Media information
24 private $uri;24 private $uri;
25 private $maxFileSize;25 private $maxFileSize;
26 private $maxFileSizeBytes;26 private $maxFileSizeBytes;
27 27
28 public function __construct(database $db, user $user, $mediaid = '', $layoutid = '', $regionid = '')28 public function __construct(database $db, user $user, $mediaid = '', $layoutid = '', $regionid = '')
29 {29 {
30 // Must set the type of the class30 // Must set the type of the class
31 $this->type = 'flash';31 $this->type = 'flash';
32 32
33 // Get the max upload size from PHP33 // Get the max upload size from PHP
34 $this->maxFileSize = ini_get('upload_max_filesize');34 $this->maxFileSize = ini_get('upload_max_filesize');
35 $this->maxFileSizeBytes = convertBytes($this->maxFileSize);35 $this->maxFileSizeBytes = convertBytes($this->maxFileSize);
36 36
37 // Must call the parent class 37 // Must call the parent class
38 parent::__construct($db, $user, $mediaid, $layoutid, $regionid);38 parent::__construct($db, $user, $mediaid, $layoutid, $regionid);
39 }39 }
40 40
41 /**41 /**
42 * Sets the Layout and Region Information42 * Sets the Layout and Region Information
43 * it will then fill in any blanks it has about this media if it can43 * it will then fill in any blanks it has about this media if it can
44 * @return 44 * @return
45 * @param $layoutid Object45 * @param $layoutid Object
46 * @param $regionid Object46 * @param $regionid Object
47 * @param $mediaid Object47 * @param $mediaid Object
@@ -53,75 +53,75 @@
53 $this->regionid = $regionid;53 $this->regionid = $regionid;
54 $mediaid = $this->mediaid;54 $mediaid = $this->mediaid;
55 $this->existingMedia = false;55 $this->existingMedia = false;
56 56
57 if ($this->regionSpecific == 1) return;57 if ($this->regionSpecific == 1) return;
58 58
59 // Load what we know about this media into the object59 // Load what we know about this media into the object
60 $SQL = "SELECT name, type, duration, originalFilename, userID, permissionID, retired, storedAs, isEdited, editedMediaID FROM media WHERE mediaID = $mediaid ";60 $SQL = "SELECT name, type, duration, originalFilename, userID, permissionID, retired, storedAs, isEdited, editedMediaID FROM media WHERE mediaID = $mediaid ";
61 61
62 if (!$result = $db->query($SQL))62 if (!$result = $db->query($SQL))
63 {63 {
64 trigger_error($db->error()); //log the error64 trigger_error($db->error()); //log the error
65 return false;65 return false;
66 }66 }
67 67
68 if ($db->num_rows($result) != 1)68 if ($db->num_rows($result) != 1)
69 {69 {
70 trigger_error("More than one row for mediaId [$mediaid] How can this be?");70 trigger_error("More than one row for mediaId [$mediaid] How can this be?");
71 return false;71 return false;
72 }72 }
73 73
74 $row = $db->get_row($result);74 $row = $db->get_row($result);
75 $duration = $row[2];75 $duration = $row[2];
76 $storedAs = $row[7];76 $storedAs = $row[7];
77 77
78 // Required Attributes78 // Required Attributes
79 $this->duration = $duration;79 $this->duration = $duration;
80 80
81 // Any Options81 // Any Options
82 $this->SetOption('uri', $storedAs);82 $this->SetOption('uri', $storedAs);
83 83
84 return true;84 return true;
85 }85 }
86 86
87 /**87 /**
88 * Return the Add Form as HTML88 * Return the Add Form as HTML
89 * @return 89 * @return
90 */90 */
91 public function AddForm()91 public function AddForm()
92 {92 {
93 global $session;93 global $session;
94 $db =& $this->db;94 $db =& $this->db;
95 $user =& $this->user;95 $user =& $this->user;
96 96
97 // Would like to get the regions width / height 97 // Would like to get the regions width / height
98 $layoutid = $this->layoutid;98 $layoutid = $this->layoutid;
99 $regionid = $this->regionid;99 $regionid = $this->regionid;
100 100
101 // Set the Session / Security information101 // Set the Session / Security information
102 $sessionId = session_id();102 $sessionId = session_id();
103 $securityToken = CreateFormToken();103 $securityToken = CreateFormToken();
104 104
105 $session->setSecurityToken($securityToken);105 $session->setSecurityToken($securityToken);
106 106
107 //Get the default value for the shared list107 //Get the default value for the shared list
108 $default = Config::GetSetting($db,"defaultMedia");108 $default = Config::GetSetting($db,"defaultMedia");
109109
110 $permissionid = 0;110 $permissionid = 0;
111111
112 if($default=="private") 112 if($default=="private")
113 {113 {
114 $permissionid = 1;114 $permissionid = 1;
115 }115 }
116 116
117 //shared list117 //shared list
118 $shared_list = dropdownlist("SELECT permissionID, permission FROM permission", "permissionid", $permissionid);118 $shared_list = dropdownlist("SELECT permissionID, permission FROM permission", "permissionid", $permissionid);
119 119
120 //Save button is different depending on if we are on a region or not120 //Save button is different depending on if we are on a region or not
121 if ($regionid != "")121 if ($regionid != "")
122 {122 {
123 setSession('content','mediatype','flash');123 setSession('content','mediatype','flash');
124 124
125 $save_button = <<<END125 $save_button = <<<END
126 <input id="btnSave" type="submit" value="Save" disabled />126 <input id="btnSave" type="submit" value="Save" disabled />
127 <input class="XiboFormButton" id="btnCancel" type="button" title="Return to the Region Options" href="index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions" value="Cancel" />127 <input class="XiboFormButton" id="btnCancel" type="button" title="Return to the Region Options" href="index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions" value="Cancel" />
@@ -135,7 +135,7 @@
135 <input class="XiboFormButton" id="btnCancel" type="button" title="Close" href="index.php?p=content&q=displayForms&sp=add" value="Cancel" />135 <input class="XiboFormButton" id="btnCancel" type="button" title="Close" href="index.php?p=content&q=displayForms&sp=add" value="Cancel" />
136END;136END;
137 }137 }
138 138
139 $form = <<<FORM139 $form = <<<FORM
140 <div style="display:none"><iframe name="fileupload" width="1px" height="1px"></iframe></div>140 <div style="display:none"><iframe name="fileupload" width="1px" height="1px"></iframe></div>
141 <div>141 <div>
@@ -144,7 +144,7 @@
144 <input type="hidden" id="SecurityToken" value="$securityToken" />144 <input type="hidden" id="SecurityToken" value="$securityToken" />
145 <input type="hidden" name="MAX_FILE_SIZE" value="$this->maxFileSizeBytes" />145 <input type="hidden" name="MAX_FILE_SIZE" value="$this->maxFileSizeBytes" />
146 <table>146 <table>
147 <tr> 147 <tr>
148 <td><label for="file">Flash File<span class="required">*</span></label></td>148 <td><label for="file">Flash File<span class="required">*</span></label></td>
149 <td colspan="3">149 <td colspan="3">
150 <input type="file" name="media_file" onchange="fileFormSubmit();this.form.submit();" />150 <input type="file" name="media_file" onchange="fileFormSubmit();this.form.submit();" />
@@ -172,11 +172,11 @@
172 <td><label for="permissionid">Sharing<span class="required">*</span></label></td>172 <td><label for="permissionid">Sharing<span class="required">*</span></label></td>
173 <td>173 <td>
174 $shared_list174 $shared_list
175 </td> 175 </td>
176 </tr>176 </tr>
177 <tr>177 <tr>
178 <td></td>178 <td></td>
179 <td>This form accepts: <span class="required">swf</span> files up to a maximum size of <span class="required">$this->maxFileSize</span>.</td>179 <td>This form accepts: <span class="required">$this->validExtensionsText</span> files up to a maximum size of <span class="required">$this->maxFileSize</span>.</td>
180 </tr>180 </tr>
181 <tr>181 <tr>
182 <td></td>182 <td></td>
@@ -194,49 +194,49 @@
194194
195 return $this->response;195 return $this->response;
196 }196 }
197 197
198 /**198 /**
199 * Return the Edit Form as HTML199 * Return the Edit Form as HTML
200 * @return 200 * @return
201 */201 */
202 public function EditForm()202 public function EditForm()
203 {203 {
204 global $session;204 global $session;
205 $db =& $this->db;205 $db =& $this->db;
206 $user =& $this->user;206 $user =& $this->user;
207 207
208 // Would like to get the regions width / height 208 // Would like to get the regions width / height
209 $layoutid = $this->layoutid;209 $layoutid = $this->layoutid;
210 $regionid = $this->regionid;210 $regionid = $this->regionid;
211 $mediaid = $this->mediaid;211 $mediaid = $this->mediaid;
212 $lkid = $this->lkid;212 $lkid = $this->lkid;
213 $userid = Kit::GetParam('userid', _SESSION, _INT);213 $userid = Kit::GetParam('userid', _SESSION, _INT);
214 214
215 // Set the Session / Security information215 // Set the Session / Security information
216 $sessionId = session_id();216 $sessionId = session_id();
217 $securityToken = CreateFormToken();217 $securityToken = CreateFormToken();
218 218
219 $session->setSecurityToken($securityToken);219 $session->setSecurityToken($securityToken);
220 220
221 // Load what we know about this media into the object221 // Load what we know about this media into the object
222 $SQL = "SELECT name, originalFilename, userID, permissionID, retired, storedAs, isEdited, editedMediaID FROM media WHERE mediaID = $mediaid ";222 $SQL = "SELECT name, originalFilename, userID, permissionID, retired, storedAs, isEdited, editedMediaID FROM media WHERE mediaID = $mediaid ";
223 223
224 if (!$result = $db->query($SQL))224 if (!$result = $db->query($SQL))
225 {225 {
226 trigger_error($db->error()); //log the error226 trigger_error($db->error()); //log the error
227 227
228 $this->message = "Error querying for the Media information with media ID [$mediaid] ";228 $this->message = "Error querying for the Media information with media ID [$mediaid] ";
229 return false;229 return false;
230 }230 }
231 231
232 if ($db->num_rows($result) != 1)232 if ($db->num_rows($result) != 1)
233 {233 {
234 trigger_error("More than one row for mediaId [$mediaid] How can this be?");234 trigger_error("More than one row for mediaId [$mediaid] How can this be?");
235 235
236 $this->message = "Error querying for the Media information with media ID [$mediaid] ";236 $this->message = "Error querying for the Media information with media ID [$mediaid] ";
237 return false;237 return false;
238 }238 }
239 239
240 $row = $db->get_row($result);240 $row = $db->get_row($result);
241 $name = $row[0];241 $name = $row[0];
242 $originalFilename = $row[1];242 $originalFilename = $row[1];
@@ -246,23 +246,23 @@
246 $storedAs = $row[5];246 $storedAs = $row[5];
247 $isEdited = $row[6];247 $isEdited = $row[6];
248 $editedMediaID = $row[7];248 $editedMediaID = $row[7];
249 249
250 // derive the ext250 // derive the ext
251 $ext = strtolower(substr(strrchr($originalFilename, "."), 1));251 $ext = strtolower(substr(strrchr($originalFilename, "."), 1));
252 252
253 //Calc the permissions on it aswell253 //Calc the permissions on it aswell
254 list($see_permissions , $edit_permissions) = $user->eval_permission($userid, $permissionid);254 list($see_permissions , $edit_permissions) = $user->eval_permission($userid, $permissionid);
255 255
256 //shared list256 //shared list
257 $shared_list = dropdownlist("SELECT permissionID, permission FROM permission", "permissionid", $permissionid);257 $shared_list = dropdownlist("SELECT permissionID, permission FROM permission", "permissionid", $permissionid);
258 258
259 //Save button is different depending on if we are on a region or not259 //Save button is different depending on if we are on a region or not
260 if ($regionid != "")260 if ($regionid != "")
261 {261 {
262 setSession('content','mediatype','flash');262 setSession('content','mediatype','flash');
263 263
264 $extraNotes = '<em>Note: Uploading a new media item here will replace it on this layout only.</em>';264 $extraNotes = '<em>Note: Uploading a new media item here will replace it on this layout only.</em>';
265 265
266 $save_button = <<<END266 $save_button = <<<END
267 <input id="btnSave" type="submit" value="Save" />267 <input id="btnSave" type="submit" value="Save" />
268 <input class="XiboFormButton" id="btnCancel" type="button" title="Return to the Region Options" href="index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions" value="Cancel" />268 <input class="XiboFormButton" id="btnCancel" type="button" title="Return to the Region Options" href="index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions" value="Cancel" />
@@ -272,13 +272,13 @@
272 else272 else
273 {273 {
274 $extraNotes = '<em>Note: As you editing from the library uploading a new media item will not replace the old one from any layouts. To do this nagivate to the layout and edit the media from there.</em>';274 $extraNotes = '<em>Note: As you editing from the library uploading a new media item will not replace the old one from any layouts. To do this nagivate to the layout and edit the media from there.</em>';
275 275
276 $save_button = <<<END276 $save_button = <<<END
277 <input id="btnSave" type="submit" value="Save" />277 <input id="btnSave" type="submit" value="Save" />
278 <input id="btnCancel" type="button" title="Close" onclick="$('#div_dialog').dialog('close')" value="Cancel" />278 <input id="btnCancel" type="button" title="Close" onclick="$('#div_dialog').dialog('close')" value="Cancel" />
279END;279END;
280 }280 }
281 281
282 $form = <<<FORM282 $form = <<<FORM
283 <div style="display:none"><iframe name="fileupload" width="1px" height="1px"></iframe></div>283 <div style="display:none"><iframe name="fileupload" width="1px" height="1px"></iframe></div>
284 <div>284 <div>
@@ -287,7 +287,7 @@
287 <input type="hidden" id="SecurityToken" value="$securityToken" />287 <input type="hidden" id="SecurityToken" value="$securityToken" />
288 <input type="hidden" name="MAX_FILE_SIZE" value="$this->maxFileSizeBytes" />288 <input type="hidden" name="MAX_FILE_SIZE" value="$this->maxFileSizeBytes" />
289 <table>289 <table>
290 <tr> 290 <tr>
291 <td><label for="file">New Flash File<span class="required">*</span></label></td>291 <td><label for="file">New Flash File<span class="required">*</span></label></td>
292 <td colspan="3">292 <td colspan="3">
293 <input type="file" name="media_file" onchange="fileFormSubmit();this.form.submit();" />293 <input type="file" name="media_file" onchange="fileFormSubmit();this.form.submit();" />
@@ -319,11 +319,11 @@
319 <td><label for="permissionid">Sharing<span class="required">*</span></label></td>319 <td><label for="permissionid">Sharing<span class="required">*</span></label></td>
320 <td>320 <td>
321 $shared_list321 $shared_list
322 </td> 322 </td>
323 </tr>323 </tr>
324 <tr>324 <tr>
325 <td></td>325 <td></td>
326 <td>This form accepts: <span class="required">swf</span> files up to a maximum size of <span class="required">$this->maxFileSize</span>.</td>326 <td>This form accepts: <span class="required">$this->validExtensionsText</span> files up to a maximum size of <span class="required">$this->maxFileSize</span>.</td>
327 </tr>327 </tr>
328 <tr>328 <tr>
329 <td></td>329 <td></td>
@@ -343,50 +343,50 @@
343 $this->response->dialogWidth = '450px';343 $this->response->dialogWidth = '450px';
344 $this->response->dialogHeight = '280px';344 $this->response->dialogHeight = '280px';
345345
346 return $this->response; 346 return $this->response;
347 }347 }
348 348
349 /**349 /**
350 * Return the Delete Form as HTML350 * Return the Delete Form as HTML
351 * @return 351 * @return
352 */352 */
353 public function DeleteForm()353 public function DeleteForm()
354 {354 {
355 $db =& $this->db;355 $db =& $this->db;
356 $user =& $this->user;356 $user =& $this->user;
357 357
358 // Would like to get the regions width / height 358 // Would like to get the regions width / height
359 $layoutid = $this->layoutid;359 $layoutid = $this->layoutid;
360 $regionid = $this->regionid;360 $regionid = $this->regionid;
361 $mediaid = $this->mediaid;361 $mediaid = $this->mediaid;
362 $lkid = $this->lkid;362 $lkid = $this->lkid;
363 $userid = Kit::GetParam('userid', _SESSION, _INT);363 $userid = Kit::GetParam('userid', _SESSION, _INT);
364 364
365 $options = "";365 $options = "";
366 //Always have the abilty to unassign from the region366 //Always have the abilty to unassign from the region
367 $options .= "unassign|Unassign from this region only";367 $options .= "unassign|Unassign from this region only";
368 368
369 // Load what we know about this media into the object369 // Load what we know about this media into the object
370 $SQL = "SELECT name, type, duration, originalFilename, userID, permissionID, retired, storedAs, isEdited, editedMediaID FROM media WHERE mediaID = $mediaid ";370 $SQL = "SELECT name, type, duration, originalFilename, userID, permissionID, retired, storedAs, isEdited, editedMediaID FROM media WHERE mediaID = $mediaid ";
371 371
372 if (!$result = $db->query($SQL))372 if (!$result = $db->query($SQL))
373 {373 {
374 trigger_error($db->error()); //log the error374 trigger_error($db->error()); //log the error
375 375
376 $this->response->SetError('Error querying for the Media information with media ID [$mediaid]');376 $this->response->SetError('Error querying for the Media information with media ID [$mediaid]');
377 $this->response->keepOpen = true;377 $this->response->keepOpen = true;
378 return $this->response;378 return $this->response;
379 }379 }
380 380
381 if ($db->num_rows($result) != 1)381 if ($db->num_rows($result) != 1)
382 {382 {
383 trigger_error("More than one row for mediaId [$mediaid] How can this be?");383 trigger_error("More than one row for mediaId [$mediaid] How can this be?");
384 384
385 $this->response->SetError('Error querying for the Media information with media ID [$mediaid]');385 $this->response->SetError('Error querying for the Media information with media ID [$mediaid]');
386 $this->response->keepOpen = true;386 $this->response->keepOpen = true;
387 return $this->response;387 return $this->response;
388 }388 }
389 389
390 $row = $db->get_row($result);390 $row = $db->get_row($result);
391 $name = $row[0];391 $name = $row[0];
392 $duration = $row[2];392 $duration = $row[2];
@@ -397,18 +397,18 @@
397 $storedAs = $row[7];397 $storedAs = $row[7];
398 $isEdited = $row[8];398 $isEdited = $row[8];
399 $editedMediaID = $row[9];399 $editedMediaID = $row[9];
400 400
401 // derive the ext401 // derive the ext
402 $ext = strtolower(substr(strrchr($originalFilename, "."), 1));402 $ext = strtolower(substr(strrchr($originalFilename, "."), 1));
403 403
404 //Calc the permissions on it aswell404 //Calc the permissions on it aswell
405 list($see_permissions , $edit_permissions) = $user->eval_permission($userid, $permissionid);405 list($see_permissions , $edit_permissions) = $user->eval_permission($userid, $permissionid);
406 406
407 //Is this user allowed to edit this media?407 //Is this user allowed to edit this media?
408 if ($edit_permissions)408 if ($edit_permissions)
409 {409 {
410 $options .= ",retire|Unassign from this region and retire";410 $options .= ",retire|Unassign from this region and retire";
411 411
412 //Is this media retired?412 //Is this media retired?
413 if ($editedMediaID != "")413 if ($editedMediaID != "")
414 {414 {
@@ -418,7 +418,7 @@
418 {418 {
419 $revised = false;419 $revised = false;
420 }420 }
421 421
422 //Is this media being used anywhere else?422 //Is this media being used anywhere else?
423 if ($layoutid == "")423 if ($layoutid == "")
424 {424 {
@@ -429,8 +429,8 @@
429 {429 {
430 $SQL = "SELECT layoutID FROM lklayoutmedia WHERE mediaID = $mediaid AND layoutid <> $layoutid AND regionID <> '$regionid' ";430 $SQL = "SELECT layoutID FROM lklayoutmedia WHERE mediaID = $mediaid AND layoutid <> $layoutid AND regionID <> '$regionid' ";
431 }431 }
432 432
433 if (!$results = $db->query($SQL)) 433 if (!$results = $db->query($SQL))
434 {434 {
435 trigger_error($db->error());435 trigger_error($db->error());
436436
@@ -457,9 +457,9 @@
457 return $this->response;457 return $this->response;
458 }458 }
459 }459 }
460 460
461 $options = ltrim($options, ",");461 $options = ltrim($options, ",");
462 462
463 $deleteOptions = listcontent($options,"options");463 $deleteOptions = listcontent($options,"options");
464464
465 //we can delete465 //we can delete
@@ -474,19 +474,19 @@
474 <input id="btnCancel" type="button" title="No / Cancel" href="index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions" onclick="$('#div_dialog').dialog('close');return false; " value="No" />474 <input id="btnCancel" type="button" title="No / Cancel" href="index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions" onclick="$('#div_dialog').dialog('close');return false; " value="No" />
475 </form>475 </form>
476END;476END;
477 477
478 $this->response->html = $form;478 $this->response->html = $form;
479 $this->response->dialogTitle = 'Delete Flash';479 $this->response->dialogTitle = 'Delete Flash';
480 $this->response->dialogSize = true;480 $this->response->dialogSize = true;
481 $this->response->dialogWidth = '450px';481 $this->response->dialogWidth = '450px';
482 $this->response->dialogHeight = '280px';482 $this->response->dialogHeight = '280px';
483483
484 return $this->response; 484 return $this->response;
485 }485 }
486 486
487 /**487 /**
488 * Add Media to the Database488 * Add Media to the Database
489 * @return 489 * @return
490 */490 */
491 public function AddMedia()491 public function AddMedia()
492 {492 {
@@ -495,62 +495,62 @@
495 $regionid = $this->regionid;495 $regionid = $this->regionid;
496 $mediaid = $this->mediaid;496 $mediaid = $this->mediaid;
497 $userid = Kit::GetParam('userid', _SESSION, _INT);497 $userid = Kit::GetParam('userid', _SESSION, _INT);
498 498
499 // File data499 // File data
500 $tmpName = Kit::GetParam('hidFileID', _POST, _STRING);500 $tmpName = Kit::GetParam('hidFileID', _POST, _STRING);
501 501
502 if ($tmpName == '')502 if ($tmpName == '')
503 {503 {
504 $this->response->SetError('Cannot save Flash details. <br/> You must have picked a file.');504 $this->response->SetError('Cannot save Flash details. <br/> You must have picked a file.');
505 $this->response->keepOpen = true;505 $this->response->keepOpen = true;
506 return $this->response;506 return $this->response;
507 }507 }
508 508
509 // File name and extension (orignial name)509 // File name and extension (orignial name)
510 $fileName = Kit::GetParam('txtFileName', _POST, _STRING);510 $fileName = Kit::GetParam('txtFileName', _POST, _STRING);
511 $fileName = basename($fileName);511 $fileName = basename($fileName);
512 $ext = strtolower(substr(strrchr($fileName, "."), 1));512 $ext = strtolower(substr(strrchr($fileName, "."), 1));
513 513
514 // Other properties514 // Other properties
515 $name = Kit::GetParam('name', _POST, _STRING);515 $name = Kit::GetParam('name', _POST, _STRING);
516 $duration = Kit::GetParam('duration', _POST, _INT, 0);516 $duration = Kit::GetParam('duration', _POST, _INT, 0);
517 $permissionid = Kit::GetParam('permissionid', _POST, _INT, 1);517 $permissionid = Kit::GetParam('permissionid', _POST, _INT, 1);
518 518
519 if ($name == '') $name = Kit::ValidateParam($fileName, _FILENAME);519 if ($name == '') $name = Kit::ValidateParam($fileName, _FILENAME);
520 520
521 // Validation521 // Validation
522 if ($ext != "swf")522 if (!$this->IsValidExtension($ext))
523 {523 {
524 $this->response->SetError('Only SWF files are accepted - Are you sure this is an flash?');524 $this->response->SetError('Your file has an extension not supported by this Media Type.');
525 $this->response->keepOpen = true;525 $this->response->keepOpen = true;
526 return $this->response;526 return $this->response;
527 }527 }
528 528
529 // Make sure the name isnt too long529 // Make sure the name isnt too long
530 if (strlen($name) > 100) 530 if (strlen($name) > 100)
531 {531 {
532 $this->response->SetError('The name cannot be longer than 100 characters');532 $this->response->SetError('The name cannot be longer than 100 characters');
533 $this->response->keepOpen = true;533 $this->response->keepOpen = true;
534 return $this->response;534 return $this->response;
535 }535 }
536 536
537 if ($duration == 0)537 if ($duration == 0)
538 {538 {
539 $this->response->SetError('You must enter a duration.');539 $this->response->SetError('You must enter a duration.');
540 $this->response->keepOpen = true;540 $this->response->keepOpen = true;
541 return $this->response;541 return $this->response;
542 }542 }
543 543
544 // Ensure the name is not already in the database544 // Ensure the name is not already in the database
545 $SQL = sprintf("SELECT name FROM media WHERE name = '%s' AND userid = %d", $db->escape_string($name), $userid);545 $SQL = sprintf("SELECT name FROM media WHERE name = '%s' AND userid = %d", $db->escape_string($name), $userid);
546546
547 if(!$result = $db->query($SQL)) 547 if(!$result = $db->query($SQL))
548 {548 {
549 trigger_error($db->error());549 trigger_error($db->error());
550 $this->response->SetError('Error checking whether the media name is ok. Try choosing a different name.');550 $this->response->SetError('Error checking whether the media name is ok. Try choosing a different name.');
551 $this->response->keepOpen = true;551 $this->response->keepOpen = true;
552 return $this->response;552 return $this->response;
553 } 553 }
554554
555 if ($db->num_rows($result) != 0)555 if ($db->num_rows($result) != 0)
556 {556 {
@@ -558,11 +558,11 @@
558 $this->response->keepOpen = true;558 $this->response->keepOpen = true;
559 return $this->response;559 return $this->response;
560 }560 }
561 561
562 // All OK to insert this record562 // All OK to insert this record
563 $SQL = "INSERT INTO media (name, type, duration, originalFilename, permissionID, userID, retired ) ";563 $SQL = "INSERT INTO media (name, type, duration, originalFilename, permissionID, userID, retired ) ";
564 $SQL .= "VALUES ('%s', 'flash', '%s', '%s', %d, %d, 0) ";564 $SQL .= "VALUES ('%s', 'flash', '%s', '%s', %d, %d, 0) ";
565 565
566 $SQL = sprintf($SQL, $db->escape_string($name), $db->escape_string($duration), $db->escape_string($fileName), $permissionid, $userid);566 $SQL = sprintf($SQL, $db->escape_string($name), $db->escape_string($duration), $db->escape_string($fileName), $permissionid, $userid);
567567
568 if (!$mediaid = $db->insert_query($SQL))568 if (!$mediaid = $db->insert_query($SQL))
@@ -572,19 +572,19 @@
572 $this->response->keepOpen = true;572 $this->response->keepOpen = true;
573 return $this->response;573 return $this->response;
574 }574 }
575 575
576 // File upload directory.. get this from the settings object576 // File upload directory.. get this from the settings object
577 $databaseDir = Config::GetSetting($db, "LIBRARY_LOCATION");577 $databaseDir = Config::GetSetting($db, "LIBRARY_LOCATION");
578 578
579 // What are we going to store this media as...579 // What are we going to store this media as...
580 $storedAs = $mediaid.".".$ext;580 $storedAs = $mediaid.".".$ext;
581 581
582 // Now we need to move the file582 // Now we need to move the file
583 if (!$result = rename($databaseDir."temp/".$tmpName, $databaseDir.$storedAs))583 if (!$result = rename($databaseDir."temp/".$tmpName, $databaseDir.$storedAs))
584 {584 {
585 // If we couldnt move it - we need to delete the media record we just added585 // If we couldnt move it - we need to delete the media record we just added
586 $SQL = sprintf("DELETE FROM media WHERE mediaID = %d ", $mediaid);586 $SQL = sprintf("DELETE FROM media WHERE mediaID = %d ", $mediaid);
587 587
588 if (!$db->query($SQL))588 if (!$db->query($SQL))
589 {589 {
590 trigger_error($db->error());590 trigger_error($db->error());
@@ -593,23 +593,23 @@
593 return $this->response;593 return $this->response;
594 }594 }
595 }595 }
596 596
597 // Update the media record to include this information597 // Update the media record to include this information
598 $SQL = sprintf("UPDATE media SET storedAs = '%s' WHERE mediaid = %d", $storedAs, $mediaid);598 $SQL = sprintf("UPDATE media SET storedAs = '%s' WHERE mediaid = %d", $storedAs, $mediaid);
599 599
600 if (!$db->query($SQL))600 if (!$db->query($SQL))
601 {601 {
602 trigger_error($db->error());602 trigger_error($db->error());
603 return true;603 return true;
604 }604 }
605 605
606 // Required Attributes606 // Required Attributes
607 $this->mediaid = $mediaid;607 $this->mediaid = $mediaid;
608 $this->duration = $duration;608 $this->duration = $duration;
609 609
610 // Any Options610 // Any Options
611 $this->SetOption('uri', $storedAs);611 $this->SetOption('uri', $storedAs);
612 612
613 // Should have built the media object entirely by this time613 // Should have built the media object entirely by this time
614 if ($regionid != '')614 if ($regionid != '')
615 {615 {
@@ -619,18 +619,18 @@
619 }619 }
620 else620 else
621 {621 {
622 $this->response->loadFormUri = "index.php?p=content&q=displayForms&sp=add"; 622 $this->response->loadFormUri = "index.php?p=content&q=displayForms&sp=add";
623 }623 }
624 624
625 // We want to load a new form625 // We want to load a new form
626 $this->response->loadForm = true;626 $this->response->loadForm = true;
627 627
628 return $this->response;628 return $this->response;
629 }629 }
630 630
631 /**631 /**
632 * Edit Media in the Database632 * Edit Media in the Database
633 * @return 633 * @return
634 */634 */
635 public function EditMedia()635 public function EditMedia()
636 {636 {
@@ -639,13 +639,13 @@
639 $regionid = $this->regionid;639 $regionid = $this->regionid;
640 $mediaid = $this->mediaid;640 $mediaid = $this->mediaid;
641 $userid = Kit::GetParam('userid', _SESSION, _INT);641 $userid = Kit::GetParam('userid', _SESSION, _INT);
642 642
643 // Stored As from the XML643 // Stored As from the XML
644 $storedAs = $this->GetOption('uri');644 $storedAs = $this->GetOption('uri');
645 645
646 // File data646 // File data
647 $tmpName = Kit::GetParam('hidFileID', _POST, _STRING);647 $tmpName = Kit::GetParam('hidFileID', _POST, _STRING);
648 648
649 if ($tmpName == '')649 if ($tmpName == '')
650 {650 {
651 $fileRevision = false;651 $fileRevision = false;
@@ -653,30 +653,30 @@
653 else653 else
654 {654 {
655 $fileRevision = true;655 $fileRevision = true;
656 656
657 // File name and extension (orignial name)657 // File name and extension (orignial name)
658 $fileName = Kit::GetParam('txtFileName', _POST, _STRING);658 $fileName = Kit::GetParam('txtFileName', _POST, _STRING);
659 $fileName = basename($fileName);659 $fileName = basename($fileName);
660 $ext = strtolower(substr(strrchr($fileName, "."), 1));660 $ext = strtolower(substr(strrchr($fileName, "."), 1));
661 661
662 if ($ext != "swf")662 if (!$this->IsValidExtension($ext))
663 {663 {
664 $this->response->SetError('Only SWF files are accepted - Are you sure this is an flash?');664 $this->response->SetError('Your file has an extension not supported by this Media Type.');
665 $this->response->keepOpen = true;665 $this->response->keepOpen = true;
666 return $this->response;666 return $this->response;
667 }667 }
668 }668 }
669 669
670 // Other properties670 // Other properties
671 $name = Kit::GetParam('name', _POST, _STRING);671 $name = Kit::GetParam('name', _POST, _STRING);
672 $duration = Kit::GetParam('duration', _POST, _INT, 0);672 $duration = Kit::GetParam('duration', _POST, _INT, 0);
673 $permissionid = Kit::GetParam('permissionid', _POST, _INT, 1);673 $permissionid = Kit::GetParam('permissionid', _POST, _INT, 1);
674 674
675 if ($name == '')675 if ($name == '')
676 {676 {
677 if ($fileRevision)677 if ($fileRevision)
678 {678 {
679 $name = Kit::ValidateParam($fileName, _FILENAME); 679 $name = Kit::ValidateParam($fileName, _FILENAME);
680 }680 }
681 else681 else
682 {682 {
@@ -684,33 +684,33 @@
684 $this->response->keepOpen = true;684 $this->response->keepOpen = true;
685 return $this->response;685 return $this->response;
686 }686 }
687 } 687 }
688 688
689 // Make sure the name isnt too long689 // Make sure the name isnt too long
690 if (strlen($name) > 100) 690 if (strlen($name) > 100)
691 {691 {
692 $this->response->SetError('The name cannot be longer than 100 characters');692 $this->response->SetError('The name cannot be longer than 100 characters');
693 $this->response->keepOpen = true;693 $this->response->keepOpen = true;
694 return $this->response;694 return $this->response;
695 }695 }
696 696
697 if ($duration == 0)697 if ($duration == 0)
698 {698 {
699 $this->response->SetError('You must enter a duration.');699 $this->response->SetError('You must enter a duration.');
700 $this->response->keepOpen = true;700 $this->response->keepOpen = true;
701 return $this->response;701 return $this->response;
702 }702 }
703 703
704 // Ensure the name is not already in the database704 // Ensure the name is not already in the database
705 $SQL = sprintf("SELECT name FROM media WHERE name = '%s' AND userid = %d AND mediaid <> %d ", $db->escape_string($name), $userid, $mediaid);705 $SQL = sprintf("SELECT name FROM media WHERE name = '%s' AND userid = %d AND mediaid <> %d ", $db->escape_string($name), $userid, $mediaid);
706706
707 if(!$result = $db->query($SQL)) 707 if(!$result = $db->query($SQL))
708 {708 {
709 trigger_error($db->error());709 trigger_error($db->error());
710 $this->response->SetError('Error checking whether the media name is ok. Try choosing a different name.');710 $this->response->SetError('Error checking whether the media name is ok. Try choosing a different name.');
711 $this->response->keepOpen = true;711 $this->response->keepOpen = true;
712 return $this->response;712 return $this->response;
713 } 713 }
714714
715 if ($db->num_rows($result) != 0)715 if ($db->num_rows($result) != 0)
716 {716 {
@@ -718,34 +718,34 @@
718 $this->response->keepOpen = true;718 $this->response->keepOpen = true;
719 return $this->response;719 return $this->response;
720 }720 }
721 721
722 //Are we revising this media - or just plain editing722 //Are we revising this media - or just plain editing
723 if ($fileRevision)723 if ($fileRevision)
724 {724 {
725 // All OK to insert this record725 // All OK to insert this record
726 $SQL = "INSERT INTO media (name, type, duration, originalFilename, permissionID, userID, retired ) ";726 $SQL = "INSERT INTO media (name, type, duration, originalFilename, permissionID, userID, retired ) ";
727 $SQL .= "VALUES ('%s', '%s', '%s', '%s', %d, %d, 0) ";727 $SQL .= "VALUES ('%s', '%s', '%s', '%s', %d, %d, 0) ";
728 728
729 $SQL = sprintf($SQL, $db->escape_string($name), $this->type, $db->escape_string($duration), $db->escape_string($fileName), $permissionid, $userid);729 $SQL = sprintf($SQL, $db->escape_string($name), $this->type, $db->escape_string($duration), $db->escape_string($fileName), $permissionid, $userid);
730 730
731 if (!$new_mediaid = $db->insert_query($SQL))731 if (!$new_mediaid = $db->insert_query($SQL))
732 {732 {
733 trigger_error($db->error());733 trigger_error($db->error());
734 trigger_error('Error inserting replacement media record.', E_USER_ERROR);734 trigger_error('Error inserting replacement media record.', E_USER_ERROR);
735 }735 }
736 736
737 //What are we going to store this media as...737 //What are we going to store this media as...
738 $storedAs = $new_mediaid.".".$ext;738 $storedAs = $new_mediaid.".".$ext;
739 739
740 // File upload directory.. get this from the settings object740 // File upload directory.. get this from the settings object
741 $databaseDir = Config::GetSetting($db, "LIBRARY_LOCATION");741 $databaseDir = Config::GetSetting($db, "LIBRARY_LOCATION");
742 742
743 //Now we need to move the file743 //Now we need to move the file
744 if (!$result = rename($databaseDir."/temp/".$tmpName, $databaseDir.$storedAs))744 if (!$result = rename($databaseDir."/temp/".$tmpName, $databaseDir.$storedAs))
745 {745 {
746 //If we couldnt move it - we need to delete the media record we just added746 //If we couldnt move it - we need to delete the media record we just added
747 $SQL = "DELETE FROM media WHERE mediaID = $new_mediaid ";747 $SQL = "DELETE FROM media WHERE mediaID = $new_mediaid ";
748 748
749 if (!$db->insert_query($SQL))749 if (!$db->insert_query($SQL))
750 {750 {
751 $this->response->SetError('Error rolling back transcation.');751 $this->response->SetError('Error rolling back transcation.');
@@ -753,7 +753,7 @@
753 return $this->response;753 return $this->response;
754 }754 }
755 }755 }
756 756
757 //Update the media record to include this information757 //Update the media record to include this information
758 $SQL = "UPDATE media SET storedAs = '$storedAs' WHERE mediaid = $new_mediaid";758 $SQL = "UPDATE media SET storedAs = '$storedAs' WHERE mediaid = $new_mediaid";
759 if (!$db->query($SQL))759 if (!$db->query($SQL))
@@ -763,13 +763,13 @@
763 $this->response->keepOpen = true;763 $this->response->keepOpen = true;
764 return $this->response;764 return $this->response;
765 }765 }
766 766
767 // Update the existing record with the new record's id767 // Update the existing record with the new record's id
768 $SQL = "UPDATE media SET isEdited = 1, editedMediaID = $new_mediaid ";768 $SQL = "UPDATE media SET isEdited = 1, editedMediaID = $new_mediaid ";
769 $SQL .= " WHERE IFNULL(editedMediaID,0) <> $new_mediaid AND mediaID = $mediaid ";769 $SQL .= " WHERE IFNULL(editedMediaID,0) <> $new_mediaid AND mediaID = $mediaid ";
770 770
771 Debug::LogEntry($db, 'audit', $SQL);771 Debug::LogEntry($db, 'audit', $SQL);
772 772
773 if (!$db->query($SQL))773 if (!$db->query($SQL))
774 {774 {
775 trigger_error($db->error());775 trigger_error($db->error());
@@ -783,54 +783,54 @@
783 {783 {
784 // Editing the existing record784 // Editing the existing record
785 $new_mediaid = $mediaid;785 $new_mediaid = $mediaid;
786 786
787 $SQL = "UPDATE media SET name = '%s', duration = %d, permissionID = %d";787 $SQL = "UPDATE media SET name = '%s', duration = %d, permissionID = %d";
788 $SQL .= " WHERE mediaID = %d ";788 $SQL .= " WHERE mediaID = %d ";
789 $SQL = sprintf($SQL, $db->escape_string($name), $duration, $permissionid, $mediaid);789 $SQL = sprintf($SQL, $db->escape_string($name), $duration, $permissionid, $mediaid);
790 790
791 Debug::LogEntry($db, 'audit', $SQL);791 Debug::LogEntry($db, 'audit', $SQL);
792 792
793 if (!$db->query($SQL))793 if (!$db->query($SQL))
794 {794 {
795 trigger_error($db->error());795 trigger_error($db->error());
796 796
797 $this->response->SetError('Database error editing this media record.');797 $this->response->SetError('Database error editing this media record.');
798 $this->response->keepOpen = true;798 $this->response->keepOpen = true;
799 return $this->response;799 return $this->response;
800 }800 }
801 }801 }
802 802
803 // Required Attributes803 // Required Attributes
804 $this->mediaid = $new_mediaid;804 $this->mediaid = $new_mediaid;
805 $this->duration = $duration;805 $this->duration = $duration;
806 806
807 // Any Options807 // Any Options
808 $this->SetOption('uri', $storedAs);808 $this->SetOption('uri', $storedAs);
809 809
810 // Should have built the media object entirely by this time810 // Should have built the media object entirely by this time
811 if ($regionid != '')811 if ($regionid != '')
812 {812 {
813 // This saves the Media Object to the Region813 // This saves the Media Object to the Region
814 $this->UpdateRegion();814 $this->UpdateRegion();
815 815
816 $this->response->loadForm = true;816 $this->response->loadForm = true;
817 $this->response->loadFormUri = "index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions";;817 $this->response->loadFormUri = "index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions";;
818 }818 }
819 else819 else
820 {820 {
821 $this->response->loadFormUri = "index.php?p=content&q=displayForms&sp=add"; 821 $this->response->loadFormUri = "index.php?p=content&q=displayForms&sp=add";
822 $this->response->message = 'Edited the Flash.';822 $this->response->message = 'Edited the Flash.';
823 823
824 }824 }
825 825
826 return $this->response;826 return $this->response;
827 }827 }
828 828
829 /**829 /**
830 * Delete Media from the Database830 * Delete Media from the Database
831 * @return 831 * @return
832 */832 */
833 public function DeleteMedia() 833 public function DeleteMedia()
834 {834 {
835 $db =& $this->db;835 $db =& $this->db;
836 $layoutid = $this->layoutid;836 $layoutid = $this->layoutid;
@@ -838,10 +838,10 @@
838 $mediaid = $this->mediaid;838 $mediaid = $this->mediaid;
839 $userid = Kit::GetParam('userid', _SESSION, _INT);839 $userid = Kit::GetParam('userid', _SESSION, _INT);
840 $options = Kit::GetParam('options', _POST, _WORD);840 $options = Kit::GetParam('options', _POST, _WORD);
841 841
842 // Stored As from the XML842 // Stored As from the XML
843 $this->uri = $this->GetOption('uri');843 $this->uri = $this->GetOption('uri');
844 844
845 // Do we need to remove this from a layout?845 // Do we need to remove this from a layout?
846 if ($layoutid != '')846 if ($layoutid != '')
847 {847 {
@@ -853,72 +853,72 @@
853 // Set this message now in preparation853 // Set this message now in preparation
854 $this->response->message = 'Deleted the Media.';854 $this->response->message = 'Deleted the Media.';
855 }855 }
856 856
857 // If we are set to retire we retire857 // If we are set to retire we retire
858 if ($options == "retire")858 if ($options == "retire")
859 {859 {
860 //Update the media record to say it is retired860 //Update the media record to say it is retired
861 $SQL = "UPDATE media SET retired = 1 WHERE mediaid = $mediaid ";861 $SQL = "UPDATE media SET retired = 1 WHERE mediaid = $mediaid ";
862 862
863 if (!$db->query($SQL))863 if (!$db->query($SQL))
864 {864 {
865 trigger_error($db->error());865 trigger_error($db->error());
866 866
867 $this->response->SetError('Database error retiring this media record.');867 $this->response->SetError('Database error retiring this media record.');
868 $this->response->keepOpen = true;868 $this->response->keepOpen = true;
869 return $this->response;869 return $this->response;
870 }870 }
871 }871 }
872 872
873 //If we are set to delete, we delete873 //If we are set to delete, we delete
874 if ($options == "delete")874 if ($options == "delete")
875 {875 {
876 //Update the media record to say it is retired876 //Update the media record to say it is retired
877 $SQL = "DELETE FROM media WHERE mediaid = $mediaid ";877 $SQL = "DELETE FROM media WHERE mediaid = $mediaid ";
878 878
879 if (!$db->query($SQL))879 if (!$db->query($SQL))
880 {880 {
881 trigger_error($db->error());881 trigger_error($db->error());
882 882
883 $this->response->SetError('Database error deleting this media record.');883 $this->response->SetError('Database error deleting this media record.');
884 $this->response->keepOpen = true;884 $this->response->keepOpen = true;
885 return $this->response;885 return $this->response;
886 }886 }
887 887
888 $this->DeleteMediaFiles();888 $this->DeleteMediaFiles();
889 }889 }
890890
891 return $this->response;891 return $this->response;
892 }892 }
893 893
894 /**894 /**
895 * Deletes the media files associated with this record895 * Deletes the media files associated with this record
896 * @return 896 * @return
897 */897 */
898 private function DeleteMediaFiles()898 private function DeleteMediaFiles()
899 {899 {
900 $db =& $this->db;900 $db =& $this->db;
901 901
902 //Library location902 //Library location
903 $databaseDir = Config::GetSetting($db, "LIBRARY_LOCATION");903 $databaseDir = Config::GetSetting($db, "LIBRARY_LOCATION");
904 904
905 //3 things to check for..905 //3 things to check for..
906 //the actual file, the thumbnail, the background906 //the actual file, the thumbnail, the background
907 if (file_exists($databaseDir.$this->uri))907 if (file_exists($databaseDir.$this->uri))
908 {908 {
909 unlink($databaseDir.$this->uri);909 unlink($databaseDir.$this->uri);
910 }910 }
911 911
912 if (file_exists($databaseDir."tn_".$this->uri))912 if (file_exists($databaseDir."tn_".$this->uri))
913 {913 {
914 unlink($databaseDir."tn_".$this->uri);914 unlink($databaseDir."tn_".$this->uri);
915 }915 }
916 916
917 if (file_exists($databaseDir."bg_".$this->uri))917 if (file_exists($databaseDir."bg_".$this->uri))
918 {918 {
919 unlink($databaseDir."bg_".$this->uri);919 unlink($databaseDir."bg_".$this->uri);
920 }920 }
921 921
922 return true;922 return true;
923 }923 }
924}924}
925925
=== modified file 'server/modules/image.module.php'
--- server/modules/image.module.php 2009-06-28 10:47:06 +0000
+++ server/modules/image.module.php 2009-10-01 21:40:25 +0000
@@ -8,7 +8,7 @@
8 * Xibo is free software: you can redistribute it and/or modify8 * Xibo is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Affero General Public License as published by9 * it under the terms of the GNU Affero General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or10 * the Free Software Foundation, either version 3 of the License, or
11 * any later version. 11 * any later version.
12 *12 *
13 * Xibo is distributed in the hope that it will be useful,13 * Xibo is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -17,31 +17,31 @@
17 *17 *
18 * You should have received a copy of the GNU Affero General Public License18 * You should have received a copy of the GNU Affero General Public License
19 * along with Xibo. If not, see <http://www.gnu.org/licenses/>.19 * along with Xibo. If not, see <http://www.gnu.org/licenses/>.
20 */ 20 */
21class image extends Module21class image extends Module
22{22{
23 // Custom Media information23 // Custom Media information
24 private $uri;24 private $uri;
25 private $maxFileSize;25 private $maxFileSize;
26 private $maxFileSizeBytes;26 private $maxFileSizeBytes;
27 27
28 public function __construct(database $db, user $user, $mediaid = '', $layoutid = '', $regionid = '')28 public function __construct(database $db, user $user, $mediaid = '', $layoutid = '', $regionid = '')
29 {29 {
30 // Must set the type of the class30 // Must set the type of the class
31 $this->type = 'image';31 $this->type = 'image';
32 32
33 // Get the max upload size from PHP33 // Get the max upload size from PHP
34 $this->maxFileSize = ini_get('upload_max_filesize');34 $this->maxFileSize = ini_get('upload_max_filesize');
35 $this->maxFileSizeBytes = convertBytes($this->maxFileSize);35 $this->maxFileSizeBytes = convertBytes($this->maxFileSize);
36 36
37 // Must call the parent class 37 // Must call the parent class
38 parent::__construct($db, $user, $mediaid, $layoutid, $regionid);38 parent::__construct($db, $user, $mediaid, $layoutid, $regionid);
39 }39 }
40 40
41 /**41 /**
42 * Sets the Layout and Region Information42 * Sets the Layout and Region Information
43 * it will then fill in any blanks it has about this media if it can43 * it will then fill in any blanks it has about this media if it can
44 * @return 44 * @return
45 * @param $layoutid Object45 * @param $layoutid Object
46 * @param $regionid Object46 * @param $regionid Object
47 * @param $mediaid Object47 * @param $mediaid Object
@@ -53,75 +53,75 @@
53 $this->regionid = $regionid;53 $this->regionid = $regionid;
54 $mediaid = $this->mediaid;54 $mediaid = $this->mediaid;
55 $this->existingMedia = false;55 $this->existingMedia = false;
56 56
57 if ($this->regionSpecific == 1) return;57 if ($this->regionSpecific == 1) return;
58 58
59 // Load what we know about this media into the object59 // Load what we know about this media into the object
60 $SQL = "SELECT name, type, duration, originalFilename, userID, permissionID, retired, storedAs, isEdited, editedMediaID FROM media WHERE mediaID = $mediaid ";60 $SQL = "SELECT name, type, duration, originalFilename, userID, permissionID, retired, storedAs, isEdited, editedMediaID FROM media WHERE mediaID = $mediaid ";
61 61
62 if (!$result = $db->query($SQL))62 if (!$result = $db->query($SQL))
63 {63 {
64 trigger_error($db->error()); //log the error64 trigger_error($db->error()); //log the error
65 return false;65 return false;
66 }66 }
67 67
68 if ($db->num_rows($result) != 1)68 if ($db->num_rows($result) != 1)
69 {69 {
70 trigger_error("More than one row for mediaId [$mediaid] How can this be?");70 trigger_error("More than one row for mediaId [$mediaid] How can this be?");
71 return false;71 return false;
72 }72 }
73 73
74 $row = $db->get_row($result);74 $row = $db->get_row($result);
75 $duration = $row[2];75 $duration = $row[2];
76 $storedAs = $row[7];76 $storedAs = $row[7];
77 77
78 // Required Attributes78 // Required Attributes
79 $this->duration = $duration;79 $this->duration = $duration;
80 80
81 // Any Options81 // Any Options
82 $this->SetOption('uri', $storedAs);82 $this->SetOption('uri', $storedAs);
83 83
84 return true;84 return true;
85 }85 }
86 86
87 /**87 /**
88 * Return the Add Form as HTML88 * Return the Add Form as HTML
89 * @return 89 * @return
90 */90 */
91 public function AddForm()91 public function AddForm()
92 {92 {
93 global $session;93 global $session;
94 $db =& $this->db;94 $db =& $this->db;
95 $user =& $this->user;95 $user =& $this->user;
96 96
97 // Would like to get the regions width / height 97 // Would like to get the regions width / height
98 $layoutid = $this->layoutid;98 $layoutid = $this->layoutid;
99 $regionid = $this->regionid;99 $regionid = $this->regionid;
100 100
101 // Set the Session / Security information101 // Set the Session / Security information
102 $sessionId = session_id();102 $sessionId = session_id();
103 $securityToken = CreateFormToken();103 $securityToken = CreateFormToken();
104 104
105 $session->setSecurityToken($securityToken);105 $session->setSecurityToken($securityToken);
106 106
107 //Get the default value for the shared list107 //Get the default value for the shared list
108 $default = Config::GetSetting($db,"defaultMedia");108 $default = Config::GetSetting($db,"defaultMedia");
109109
110 $permissionid = 0;110 $permissionid = 0;
111111
112 if($default=="private") 112 if($default=="private")
113 {113 {
114 $permissionid = 1;114 $permissionid = 1;
115 }115 }
116 116
117 //shared list117 //shared list
118 $shared_list = dropdownlist("SELECT permissionID, permission FROM permission", "permissionid", $permissionid);118 $shared_list = dropdownlist("SELECT permissionID, permission FROM permission", "permissionid", $permissionid);
119 119
120 //Save button is different depending on if we are on a region or not120 //Save button is different depending on if we are on a region or not
121 if ($regionid != "")121 if ($regionid != "")
122 {122 {
123 setSession('content','mediatype','image');123 setSession('content','mediatype','image');
124 124
125 $save_button = <<<END125 $save_button = <<<END
126 <input id="btnSave" type="submit" value="Save" disabled />126 <input id="btnSave" type="submit" value="Save" disabled />
127 <input class="XiboFormButton" id="btnCancel" type="button" title="Return to the Region Options" href="index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions" value="Cancel" />127 <input class="XiboFormButton" id="btnCancel" type="button" title="Return to the Region Options" href="index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions" value="Cancel" />
@@ -135,7 +135,7 @@
135 <input class="XiboFormButton" id="btnCancel" type="button" title="Close" href="index.php?p=content&q=displayForms&sp=add" value="Cancel" />135 <input class="XiboFormButton" id="btnCancel" type="button" title="Close" href="index.php?p=content&q=displayForms&sp=add" value="Cancel" />
136END;136END;
137 }137 }
138 138
139 $form = <<<FORM139 $form = <<<FORM
140 <div style="display:none"><iframe name="fileupload" width="1px" height="1px"></iframe></div>140 <div style="display:none"><iframe name="fileupload" width="1px" height="1px"></iframe></div>
141 <div>141 <div>
@@ -144,7 +144,7 @@
144 <input type="hidden" id="SecurityToken" value="$securityToken" />144 <input type="hidden" id="SecurityToken" value="$securityToken" />
145 <input type="hidden" name="MAX_FILE_SIZE" value="$this->maxFileSizeBytes" />145 <input type="hidden" name="MAX_FILE_SIZE" value="$this->maxFileSizeBytes" />
146 <table>146 <table>
147 <tr> 147 <tr>
148 <td><label for="file">Image File<span class="required">*</span></label></td>148 <td><label for="file">Image File<span class="required">*</span></label></td>
149 <td colspan="3">149 <td colspan="3">
150 <input type="file" name="media_file" onchange="fileFormSubmit();this.form.submit();" />150 <input type="file" name="media_file" onchange="fileFormSubmit();this.form.submit();" />
@@ -172,11 +172,11 @@
172 <td><label for="permissionid">Sharing<span class="required">*</span></label></td>172 <td><label for="permissionid">Sharing<span class="required">*</span></label></td>
173 <td>173 <td>
174 $shared_list174 $shared_list
175 </td> 175 </td>
176 </tr>176 </tr>
177 <tr>177 <tr>
178 <td></td>178 <td></td>
179 <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>179 <td>This form accepts: <span class="required">$this->validExtensionsText</span> files up to a maximum size of <span class="required">$this->maxFileSize</span>.</td>
180 </tr>180 </tr>
181 <tr>181 <tr>
182 <td></td>182 <td></td>
@@ -194,49 +194,49 @@
194194
195 return $this->response;195 return $this->response;
196 }196 }
197 197
198 /**198 /**
199 * Return the Edit Form as HTML199 * Return the Edit Form as HTML
200 * @return 200 * @return
201 */201 */
202 public function EditForm()202 public function EditForm()
203 {203 {
204 global $session;204 global $session;
205 $db =& $this->db;205 $db =& $this->db;
206 $user =& $this->user;206 $user =& $this->user;
207 207
208 // Would like to get the regions width / height 208 // Would like to get the regions width / height
209 $layoutid = $this->layoutid;209 $layoutid = $this->layoutid;
210 $regionid = $this->regionid;210 $regionid = $this->regionid;
211 $mediaid = $this->mediaid;211 $mediaid = $this->mediaid;
212 $lkid = $this->lkid;212 $lkid = $this->lkid;
213 $userid = Kit::GetParam('userid', _SESSION, _INT);213 $userid = Kit::GetParam('userid', _SESSION, _INT);
214 214
215 // Set the Session / Security information215 // Set the Session / Security information
216 $sessionId = session_id();216 $sessionId = session_id();
217 $securityToken = CreateFormToken();217 $securityToken = CreateFormToken();
218 218
219 $session->setSecurityToken($securityToken);219 $session->setSecurityToken($securityToken);
220 220
221 // Load what we know about this media into the object221 // Load what we know about this media into the object
222 $SQL = "SELECT name, originalFilename, userID, permissionID, retired, storedAs, isEdited, editedMediaID FROM media WHERE mediaID = $mediaid ";222 $SQL = "SELECT name, originalFilename, userID, permissionID, retired, storedAs, isEdited, editedMediaID FROM media WHERE mediaID = $mediaid ";
223 223
224 if (!$result = $db->query($SQL))224 if (!$result = $db->query($SQL))
225 {225 {
226 trigger_error($db->error()); //log the error226 trigger_error($db->error()); //log the error
227 227
228 $this->message = "Error querying for the Media information with media ID [$mediaid] ";228 $this->message = "Error querying for the Media information with media ID [$mediaid] ";
229 return false;229 return false;
230 }230 }
231 231
232 if ($db->num_rows($result) != 1)232 if ($db->num_rows($result) != 1)
233 {233 {
234 trigger_error("More than one row for mediaId [$mediaid] How can this be?");234 trigger_error("More than one row for mediaId [$mediaid] How can this be?");
235 235
236 $this->message = "Error querying for the Media information with media ID [$mediaid] ";236 $this->message = "Error querying for the Media information with media ID [$mediaid] ";
237 return false;237 return false;
238 }238 }
239 239
240 $row = $db->get_row($result);240 $row = $db->get_row($result);
241 $name = $row[0];241 $name = $row[0];
242 $originalFilename = $row[1];242 $originalFilename = $row[1];
@@ -246,23 +246,23 @@
246 $storedAs = $row[5];246 $storedAs = $row[5];
247 $isEdited = $row[6];247 $isEdited = $row[6];
248 $editedMediaID = $row[7];248 $editedMediaID = $row[7];
249 249
250 // derive the ext250 // derive the ext
251 $ext = strtolower(substr(strrchr($originalFilename, "."), 1));251 $ext = strtolower(substr(strrchr($originalFilename, "."), 1));
252 252
253 //Calc the permissions on it aswell253 //Calc the permissions on it aswell
254 list($see_permissions , $edit_permissions) = $user->eval_permission($userid, $permissionid);254 list($see_permissions , $edit_permissions) = $user->eval_permission($userid, $permissionid);
255 255
256 //shared list256 //shared list
257 $shared_list = dropdownlist("SELECT permissionID, permission FROM permission", "permissionid", $permissionid);257 $shared_list = dropdownlist("SELECT permissionID, permission FROM permission", "permissionid", $permissionid);
258 258
259 //Save button is different depending on if we are on a region or not259 //Save button is different depending on if we are on a region or not
260 if ($regionid != "")260 if ($regionid != "")
261 {261 {
262 setSession('content','mediatype','image');262 setSession('content','mediatype','image');
263 263
264 $extraNotes = '<em>Note: Uploading a new media item here will replace it on this layout only.</em>';264 $extraNotes = '<em>Note: Uploading a new media item here will replace it on this layout only.</em>';
265 265
266 $save_button = <<<END266 $save_button = <<<END
267 <input id="btnSave" type="submit" value="Save" />267 <input id="btnSave" type="submit" value="Save" />
268 <input class="XiboFormButton" id="btnCancel" type="button" title="Return to the Region Options" href="index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions" value="Cancel" />268 <input class="XiboFormButton" id="btnCancel" type="button" title="Return to the Region Options" href="index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions" value="Cancel" />
@@ -272,13 +272,13 @@
272 else272 else
273 {273 {
274 $extraNotes = '<em>Note: As you editing from the library uploading a new media item will not replace the old one from any layouts. To do this nagivate to the layout and edit the media from there.</em>';274 $extraNotes = '<em>Note: As you editing from the library uploading a new media item will not replace the old one from any layouts. To do this nagivate to the layout and edit the media from there.</em>';
275 275
276 $save_button = <<<END276 $save_button = <<<END
277 <input id="btnSave" type="submit" value="Save" />277 <input id="btnSave" type="submit" value="Save" />
278 <input id="btnCancel" type="button" title="Close" onclick="$('#div_dialog').dialog('close')" value="Cancel" />278 <input id="btnCancel" type="button" title="Close" onclick="$('#div_dialog').dialog('close')" value="Cancel" />
279END;279END;
280 }280 }
281 281
282 $form = <<<FORM282 $form = <<<FORM
283 <div style="display:none"><iframe name="fileupload" width="1px" height="1px"></iframe></div>283 <div style="display:none"><iframe name="fileupload" width="1px" height="1px"></iframe></div>
284 <div>284 <div>
@@ -287,7 +287,7 @@
287 <input type="hidden" id="SecurityToken" value="$securityToken" />287 <input type="hidden" id="SecurityToken" value="$securityToken" />
288 <input type="hidden" name="MAX_FILE_SIZE" value="$this->maxFileSizeBytes" />288 <input type="hidden" name="MAX_FILE_SIZE" value="$this->maxFileSizeBytes" />
289 <table>289 <table>
290 <tr> 290 <tr>
291 <td><label for="file">New Image File<span class="required">*</span></label></td>291 <td><label for="file">New Image File<span class="required">*</span></label></td>
292 <td colspan="3">292 <td colspan="3">
293 <input type="file" name="media_file" onchange="fileFormSubmit();this.form.submit();" />293 <input type="file" name="media_file" onchange="fileFormSubmit();this.form.submit();" />
@@ -319,11 +319,11 @@
319 <td><label for="permissionid">Sharing<span class="required">*</span></label></td>319 <td><label for="permissionid">Sharing<span class="required">*</span></label></td>
320 <td>320 <td>
321 $shared_list321 $shared_list
322 </td> 322 </td>
323 </tr>323 </tr>
324 <tr>324 <tr>
325 <td></td>325 <td></td>
326 <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>326 <td>This form accepts: <span class="required">$this->validExtensionsText</span> files up to a maximum size of <span class="required">$this->maxFileSize</span>.</td>
327 </tr>327 </tr>
328 <tr>328 <tr>
329 <td></td>329 <td></td>
@@ -343,50 +343,50 @@
343 $this->response->dialogWidth = '450px';343 $this->response->dialogWidth = '450px';
344 $this->response->dialogHeight = '280px';344 $this->response->dialogHeight = '280px';
345345
346 return $this->response; 346 return $this->response;
347 }347 }
348 348
349 /**349 /**
350 * Return the Delete Form as HTML350 * Return the Delete Form as HTML
351 * @return 351 * @return
352 */352 */
353 public function DeleteForm()353 public function DeleteForm()
354 {354 {
355 $db =& $this->db;355 $db =& $this->db;
356 $user =& $this->user;356 $user =& $this->user;
357 357
358 // Would like to get the regions width / height 358 // Would like to get the regions width / height
359 $layoutid = $this->layoutid;359 $layoutid = $this->layoutid;
360 $regionid = $this->regionid;360 $regionid = $this->regionid;
361 $mediaid = $this->mediaid;361 $mediaid = $this->mediaid;
362 $lkid = $this->lkid;362 $lkid = $this->lkid;
363 $userid = Kit::GetParam('userid', _SESSION, _INT);363 $userid = Kit::GetParam('userid', _SESSION, _INT);
364 364
365 $options = "";365 $options = "";
366 //Always have the abilty to unassign from the region366 //Always have the abilty to unassign from the region
367 $options .= "unassign|Unassign from this region only";367 $options .= "unassign|Unassign from this region only";
368 368
369 // Load what we know about this media into the object369 // Load what we know about this media into the object
370 $SQL = "SELECT name, type, duration, originalFilename, userID, permissionID, retired, storedAs, isEdited, editedMediaID FROM media WHERE mediaID = $mediaid ";370 $SQL = "SELECT name, type, duration, originalFilename, userID, permissionID, retired, storedAs, isEdited, editedMediaID FROM media WHERE mediaID = $mediaid ";
371 371
372 if (!$result = $db->query($SQL))372 if (!$result = $db->query($SQL))
373 {373 {
374 trigger_error($db->error()); //log the error374 trigger_error($db->error()); //log the error
375 375
376 $this->response->SetError('Error querying for the Media information with media ID [$mediaid]');376 $this->response->SetError('Error querying for the Media information with media ID [$mediaid]');
377 $this->response->keepOpen = true;377 $this->response->keepOpen = true;
378 return $this->response;378 return $this->response;
379 }379 }
380 380
381 if ($db->num_rows($result) != 1)381 if ($db->num_rows($result) != 1)
382 {382 {
383 trigger_error("More than one row for mediaId [$mediaid] How can this be?");383 trigger_error("More than one row for mediaId [$mediaid] How can this be?");
384 384
385 $this->response->SetError('Error querying for the Media information with media ID [$mediaid]');385 $this->response->SetError('Error querying for the Media information with media ID [$mediaid]');
386 $this->response->keepOpen = true;386 $this->response->keepOpen = true;
387 return $this->response;387 return $this->response;
388 }388 }
389 389
390 $row = $db->get_row($result);390 $row = $db->get_row($result);
391 $name = $row[0];391 $name = $row[0];
392 $duration = $row[2];392 $duration = $row[2];
@@ -397,18 +397,18 @@
397 $storedAs = $row[7];397 $storedAs = $row[7];
398 $isEdited = $row[8];398 $isEdited = $row[8];
399 $editedMediaID = $row[9];399 $editedMediaID = $row[9];
400 400
401 // derive the ext401 // derive the ext
402 $ext = strtolower(substr(strrchr($originalFilename, "."), 1));402 $ext = strtolower(substr(strrchr($originalFilename, "."), 1));
403 403
404 //Calc the permissions on it aswell404 //Calc the permissions on it aswell
405 list($see_permissions , $edit_permissions) = $user->eval_permission($userid, $permissionid);405 list($see_permissions , $edit_permissions) = $user->eval_permission($userid, $permissionid);
406 406
407 //Is this user allowed to edit this media?407 //Is this user allowed to edit this media?
408 if ($edit_permissions)408 if ($edit_permissions)
409 {409 {
410 $options .= ",retire|Unassign from this region and retire";410 $options .= ",retire|Unassign from this region and retire";
411 411
412 //Is this media retired?412 //Is this media retired?
413 if ($editedMediaID != "")413 if ($editedMediaID != "")
414 {414 {
@@ -418,7 +418,7 @@
418 {418 {
419 $revised = false;419 $revised = false;
420 }420 }
421 421
422 //Is this media being used anywhere else?422 //Is this media being used anywhere else?
423 if ($layoutid == "")423 if ($layoutid == "")
424 {424 {
@@ -429,8 +429,8 @@
429 {429 {
430 $SQL = "SELECT layoutID FROM lklayoutmedia WHERE mediaID = $mediaid AND layoutid <> $layoutid AND regionID <> '$regionid' ";430 $SQL = "SELECT layoutID FROM lklayoutmedia WHERE mediaID = $mediaid AND layoutid <> $layoutid AND regionID <> '$regionid' ";
431 }431 }
432 432
433 if (!$results = $db->query($SQL)) 433 if (!$results = $db->query($SQL))
434 {434 {
435 trigger_error($db->error());435 trigger_error($db->error());
436436
@@ -457,9 +457,9 @@
457 return $this->response;457 return $this->response;
458 }458 }
459 }459 }
460 460
461 $options = ltrim($options, ",");461 $options = ltrim($options, ",");
462 462
463 $deleteOptions = listcontent($options,"options");463 $deleteOptions = listcontent($options,"options");
464464
465 //we can delete465 //we can delete
@@ -474,19 +474,19 @@
474 <input id="btnCancel" type="button" title="No / Cancel" href="index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions" onclick="$('#div_dialog').dialog('close');return false; " value="No" />474 <input id="btnCancel" type="button" title="No / Cancel" href="index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions" onclick="$('#div_dialog').dialog('close');return false; " value="No" />
475 </form>475 </form>
476END;476END;
477 477
478 $this->response->html = $form;478 $this->response->html = $form;
479 $this->response->dialogTitle = 'Delete Image';479 $this->response->dialogTitle = 'Delete Image';
480 $this->response->dialogSize = true;480 $this->response->dialogSize = true;
481 $this->response->dialogWidth = '450px';481 $this->response->dialogWidth = '450px';
482 $this->response->dialogHeight = '280px';482 $this->response->dialogHeight = '280px';
483483
484 return $this->response; 484 return $this->response;
485 }485 }
486 486
487 /**487 /**
488 * Add Media to the Database488 * Add Media to the Database
489 * @return 489 * @return
490 */490 */
491 public function AddMedia()491 public function AddMedia()
492 {492 {
@@ -495,62 +495,62 @@
495 $regionid = $this->regionid;495 $regionid = $this->regionid;
496 $mediaid = $this->mediaid;496 $mediaid = $this->mediaid;
497 $userid = Kit::GetParam('userid', _SESSION, _INT);497 $userid = Kit::GetParam('userid', _SESSION, _INT);
498 498
499 // File data499 // File data
500 $tmpName = Kit::GetParam('hidFileID', _POST, _STRING);500 $tmpName = Kit::GetParam('hidFileID', _POST, _STRING);
501 501
502 if ($tmpName == '')502 if ($tmpName == '')
503 {503 {
504 $this->response->SetError('Cannot save Image details. <br/> You must have picked a file.');504 $this->response->SetError('Cannot save Image details. <br/> You must have picked a file.');
505 $this->response->keepOpen = true;505 $this->response->keepOpen = true;
506 return $this->response;506 return $this->response;
507 }507 }
508 508
509 // File name and extension (orignial name)509 // File name and extension (orignial name)
510 $fileName = Kit::GetParam('txtFileName', _POST, _STRING);510 $fileName = Kit::GetParam('txtFileName', _POST, _STRING);
511 $fileName = basename($fileName);511 $fileName = basename($fileName);
512 $ext = strtolower(substr(strrchr($fileName, "."), 1));512 $ext = strtolower(substr(strrchr($fileName, "."), 1));
513 513
514 // Other properties514 // Other properties
515 $name = Kit::GetParam('name', _POST, _STRING);515 $name = Kit::GetParam('name', _POST, _STRING);
516 $duration = Kit::GetParam('duration', _POST, _INT, 0);516 $duration = Kit::GetParam('duration', _POST, _INT, 0);
517 $permissionid = Kit::GetParam('permissionid', _POST, _INT, 1);517 $permissionid = Kit::GetParam('permissionid', _POST, _INT, 1);
518 518
519 if ($name == '') $name = Kit::ValidateParam($fileName, _FILENAME);519 if ($name == '') $name = Kit::ValidateParam($fileName, _FILENAME);
520 520
521 // Validation521 // Validation
522 if ($ext != "jpeg" && $ext != "jpg" && $ext != "png" && $ext != "gif")522 if (!$this->IsValidExtension($ext))
523 {523 {
524 $this->response->SetError('Only images are accepted - Are you sure this is an image?');524 $this->response->SetError('Your file has an extension not supported by Media Type.');
525 $this->response->keepOpen = true;525 $this->response->keepOpen = true;
526 return $this->response;526 return $this->response;
527 }527 }
528 528
529 // Make sure the name isnt too long529 // Make sure the name isnt too long
530 if (strlen($name) > 100) 530 if (strlen($name) > 100)
531 {531 {
532 $this->response->SetError('The name cannot be longer than 100 characters');532 $this->response->SetError('The name cannot be longer than 100 characters');
533 $this->response->keepOpen = true;533 $this->response->keepOpen = true;
534 return $this->response;534 return $this->response;
535 }535 }
536 536
537 if ($duration == 0)537 if ($duration == 0)
538 {538 {
539 $this->response->SetError('You must enter a duration.');539 $this->response->SetError('You must enter a duration.');
540 $this->response->keepOpen = true;540 $this->response->keepOpen = true;
541 return $this->response;541 return $this->response;
542 }542 }
543 543
544 // Ensure the name is not already in the database544 // Ensure the name is not already in the database
545 $SQL = sprintf("SELECT name FROM media WHERE name = '%s' AND userid = %d", $db->escape_string($name), $userid);545 $SQL = sprintf("SELECT name FROM media WHERE name = '%s' AND userid = %d", $db->escape_string($name), $userid);
546546
547 if(!$result = $db->query($SQL)) 547 if(!$result = $db->query($SQL))
548 {548 {
549 trigger_error($db->error());549 trigger_error($db->error());
550 $this->response->SetError('Error checking whether the media name is ok. Try choosing a different name.');550 $this->response->SetError('Error checking whether the media name is ok. Try choosing a different name.');
551 $this->response->keepOpen = true;551 $this->response->keepOpen = true;
552 return $this->response;552 return $this->response;
553 } 553 }
554554
555 if ($db->num_rows($result) != 0)555 if ($db->num_rows($result) != 0)
556 {556 {
@@ -558,11 +558,11 @@
558 $this->response->keepOpen = true;558 $this->response->keepOpen = true;
559 return $this->response;559 return $this->response;
560 }560 }
561 561
562 // All OK to insert this record562 // All OK to insert this record
563 $SQL = "INSERT INTO media (name, type, duration, originalFilename, permissionID, userID, retired ) ";563 $SQL = "INSERT INTO media (name, type, duration, originalFilename, permissionID, userID, retired ) ";
564 $SQL .= "VALUES ('%s', 'image', '%s', '%s', %d, %d, 0) ";564 $SQL .= "VALUES ('%s', 'image', '%s', '%s', %d, %d, 0) ";
565 565
566 $SQL = sprintf($SQL, $db->escape_string($name), $db->escape_string($duration), $db->escape_string($fileName), $permissionid, $userid);566 $SQL = sprintf($SQL, $db->escape_string($name), $db->escape_string($duration), $db->escape_string($fileName), $permissionid, $userid);
567567
568 if (!$mediaid = $db->insert_query($SQL))568 if (!$mediaid = $db->insert_query($SQL))
@@ -572,19 +572,19 @@
572 $this->response->keepOpen = true;572 $this->response->keepOpen = true;
573 return $this->response;573 return $this->response;
574 }574 }
575 575
576 // File upload directory.. get this from the settings object576 // File upload directory.. get this from the settings object
577 $databaseDir = Config::GetSetting($db, "LIBRARY_LOCATION");577 $databaseDir = Config::GetSetting($db, "LIBRARY_LOCATION");
578 578
579 // What are we going to store this media as...579 // What are we going to store this media as...
580 $storedAs = $mediaid.".".$ext;580 $storedAs = $mediaid.".".$ext;
581 581
582 // Now we need to move the file582 // Now we need to move the file
583 if (!$result = rename($databaseDir."temp/".$tmpName, $databaseDir.$storedAs))583 if (!$result = rename($databaseDir."temp/".$tmpName, $databaseDir.$storedAs))
584 {584 {
585 // If we couldnt move it - we need to delete the media record we just added585 // If we couldnt move it - we need to delete the media record we just added
586 $SQL = sprintf("DELETE FROM media WHERE mediaID = %d ", $mediaid);586 $SQL = sprintf("DELETE FROM media WHERE mediaID = %d ", $mediaid);
587 587
588 if (!$db->query($SQL))588 if (!$db->query($SQL))
589 {589 {
590 trigger_error($db->error());590 trigger_error($db->error());
@@ -593,26 +593,26 @@
593 return $this->response;593 return $this->response;
594 }594 }
595 }595 }
596 596
597 // Update the media record to include this information597 // Update the media record to include this information
598 $SQL = sprintf("UPDATE media SET storedAs = '%s' WHERE mediaid = %d", $storedAs, $mediaid);598 $SQL = sprintf("UPDATE media SET storedAs = '%s' WHERE mediaid = %d", $storedAs, $mediaid);
599 599
600 if (!$db->query($SQL))600 if (!$db->query($SQL))
601 {601 {
602 trigger_error($db->error());602 trigger_error($db->error());
603 return true;603 return true;
604 }604 }
605 605
606 // Create the thumb nail606 // Create the thumb nail
607 ResizeImage($databaseDir.$storedAs, $databaseDir."tn_".$storedAs, 80, 80);607 ResizeImage($databaseDir.$storedAs, $databaseDir."tn_".$storedAs, 80, 80);
608 608
609 // Required Attributes609 // Required Attributes
610 $this->mediaid = $mediaid;610 $this->mediaid = $mediaid;
611 $this->duration = $duration;611 $this->duration = $duration;
612 612
613 // Any Options613 // Any Options
614 $this->SetOption('uri', $storedAs);614 $this->SetOption('uri', $storedAs);
615 615
616 // Should have built the media object entirely by this time616 // Should have built the media object entirely by this time
617 if ($regionid != '')617 if ($regionid != '')
618 {618 {
@@ -622,18 +622,18 @@
622 }622 }
623 else623 else
624 {624 {
625 $this->response->loadFormUri = "index.php?p=content&q=displayForms&sp=add"; 625 $this->response->loadFormUri = "index.php?p=content&q=displayForms&sp=add";
626 }626 }
627 627
628 // We want to load a new form628 // We want to load a new form
629 $this->response->loadForm = true;629 $this->response->loadForm = true;
630 630
631 return $this->response;631 return $this->response;
632 }632 }
633 633
634 /**634 /**
635 * Edit Media in the Database635 * Edit Media in the Database
636 * @return 636 * @return
637 */637 */
638 public function EditMedia()638 public function EditMedia()
639 {639 {
@@ -642,13 +642,13 @@
642 $regionid = $this->regionid;642 $regionid = $this->regionid;
643 $mediaid = $this->mediaid;643 $mediaid = $this->mediaid;
644 $userid = Kit::GetParam('userid', _SESSION, _INT);644 $userid = Kit::GetParam('userid', _SESSION, _INT);
645 645
646 // Stored As from the XML646 // Stored As from the XML
647 $storedAs = $this->GetOption('uri');647 $storedAs = $this->GetOption('uri');
648 648
649 // File data649 // File data
650 $tmpName = Kit::GetParam('hidFileID', _POST, _STRING);650 $tmpName = Kit::GetParam('hidFileID', _POST, _STRING);
651 651
652 if ($tmpName == '')652 if ($tmpName == '')
653 {653 {
654 $fileRevision = false;654 $fileRevision = false;
@@ -656,30 +656,30 @@
656 else656 else
657 {657 {
658 $fileRevision = true;658 $fileRevision = true;
659 659
660 // File name and extension (orignial name)660 // File name and extension (orignial name)
661 $fileName = Kit::GetParam('txtFileName', _POST, _STRING);661 $fileName = Kit::GetParam('txtFileName', _POST, _STRING);
662 $fileName = basename($fileName);662 $fileName = basename($fileName);
663 $ext = strtolower(substr(strrchr($fileName, "."), 1));663 $ext = strtolower(substr(strrchr($fileName, "."), 1));
664 664
665 if ($ext != "jpeg" && $ext != "jpg" && $ext != "png" && $ext != "gif")665 if (!$this->IsValidExtension($ext))
666 {666 {
667 $this->response->SetError('Only images are accepted - Are you sure this is an image?');667 $this->response->SetError('Your file has an extension not supported by this Media Type.');
668 $this->response->keepOpen = true;668 $this->response->keepOpen = true;
669 return $this->response;669 return $this->response;
670 }670 }
671 }671 }
672 672
673 // Other properties673 // Other properties
674 $name = Kit::GetParam('name', _POST, _STRING);674 $name = Kit::GetParam('name', _POST, _STRING);
675 $duration = Kit::GetParam('duration', _POST, _INT, 0);675 $duration = Kit::GetParam('duration', _POST, _INT, 0);
676 $permissionid = Kit::GetParam('permissionid', _POST, _INT, 1);676 $permissionid = Kit::GetParam('permissionid', _POST, _INT, 1);
677 677
678 if ($name == '')678 if ($name == '')
679 {679 {
680 if ($fileRevision)680 if ($fileRevision)
681 {681 {
682 $name = Kit::ValidateParam($fileName, _FILENAME); 682 $name = Kit::ValidateParam($fileName, _FILENAME);
683 }683 }
684 else684 else
685 {685 {
@@ -687,33 +687,33 @@
687 $this->response->keepOpen = true;687 $this->response->keepOpen = true;
688 return $this->response;688 return $this->response;
689 }689 }
690 } 690 }
691 691
692 // Make sure the name isnt too long692 // Make sure the name isnt too long
693 if (strlen($name) > 100) 693 if (strlen($name) > 100)
694 {694 {
695 $this->response->SetError('The name cannot be longer than 100 characters');695 $this->response->SetError('The name cannot be longer than 100 characters');
696 $this->response->keepOpen = true;696 $this->response->keepOpen = true;
697 return $this->response;697 return $this->response;
698 }698 }
699 699
700 if ($duration == 0)700 if ($duration == 0)
701 {701 {
702 $this->response->SetError('You must enter a duration.');702 $this->response->SetError('You must enter a duration.');
703 $this->response->keepOpen = true;703 $this->response->keepOpen = true;
704 return $this->response;704 return $this->response;
705 }705 }
706 706
707 // Ensure the name is not already in the database707 // Ensure the name is not already in the database
708 $SQL = sprintf("SELECT name FROM media WHERE name = '%s' AND userid = %d AND mediaid <> %d ", $db->escape_string($name), $userid, $mediaid);708 $SQL = sprintf("SELECT name FROM media WHERE name = '%s' AND userid = %d AND mediaid <> %d ", $db->escape_string($name), $userid, $mediaid);
709709
710 if(!$result = $db->query($SQL)) 710 if(!$result = $db->query($SQL))
711 {711 {
712 trigger_error($db->error());712 trigger_error($db->error());
713 $this->response->SetError('Error checking whether the media name is ok. Try choosing a different name.');713 $this->response->SetError('Error checking whether the media name is ok. Try choosing a different name.');
714 $this->response->keepOpen = true;714 $this->response->keepOpen = true;
715 return $this->response;715 return $this->response;
716 } 716 }
717717
718 if ($db->num_rows($result) != 0)718 if ($db->num_rows($result) != 0)
719 {719 {
@@ -721,34 +721,34 @@
721 $this->response->keepOpen = true;721 $this->response->keepOpen = true;
722 return $this->response;722 return $this->response;
723 }723 }
724 724
725 //Are we revising this media - or just plain editing725 //Are we revising this media - or just plain editing
726 if ($fileRevision)726 if ($fileRevision)
727 {727 {
728 // All OK to insert this record728 // All OK to insert this record
729 $SQL = "INSERT INTO media (name, type, duration, originalFilename, permissionID, userID, retired ) ";729 $SQL = "INSERT INTO media (name, type, duration, originalFilename, permissionID, userID, retired ) ";
730 $SQL .= "VALUES ('%s', 'image', '%s', '%s', %d, %d, 0) ";730 $SQL .= "VALUES ('%s', 'image', '%s', '%s', %d, %d, 0) ";
731 731
732 $SQL = sprintf($SQL, $db->escape_string($name), $db->escape_string($duration), $db->escape_string($fileName), $permissionid, $userid);732 $SQL = sprintf($SQL, $db->escape_string($name), $db->escape_string($duration), $db->escape_string($fileName), $permissionid, $userid);
733 733
734 if (!$new_mediaid = $db->insert_query($SQL))734 if (!$new_mediaid = $db->insert_query($SQL))
735 {735 {
736 trigger_error($db->error());736 trigger_error($db->error());
737 trigger_error('Error inserting replacement media record.', E_USER_ERROR);737 trigger_error('Error inserting replacement media record.', E_USER_ERROR);
738 }738 }
739 739
740 //What are we going to store this media as...740 //What are we going to store this media as...
741 $storedAs = $new_mediaid.".".$ext;741 $storedAs = $new_mediaid.".".$ext;
742 742
743 // File upload directory.. get this from the settings object743 // File upload directory.. get this from the settings object
744 $databaseDir = Config::GetSetting($db, "LIBRARY_LOCATION");744 $databaseDir = Config::GetSetting($db, "LIBRARY_LOCATION");
745 745
746 //Now we need to move the file746 //Now we need to move the file
747 if (!$result = rename($databaseDir."/temp/".$tmpName, $databaseDir.$storedAs))747 if (!$result = rename($databaseDir."/temp/".$tmpName, $databaseDir.$storedAs))
748 {748 {
749 //If we couldnt move it - we need to delete the media record we just added749 //If we couldnt move it - we need to delete the media record we just added
750 $SQL = "DELETE FROM media WHERE mediaID = $new_mediaid ";750 $SQL = "DELETE FROM media WHERE mediaID = $new_mediaid ";
751 751
752 if (!$db->insert_query($SQL))752 if (!$db->insert_query($SQL))
753 {753 {
754 $this->response->SetError('Error rolling back transcation.');754 $this->response->SetError('Error rolling back transcation.');
@@ -756,7 +756,7 @@
756 return $this->response;756 return $this->response;
757 }757 }
758 }758 }
759 759
760 //Update the media record to include this information760 //Update the media record to include this information
761 $SQL = "UPDATE media SET storedAs = '$storedAs' WHERE mediaid = $new_mediaid";761 $SQL = "UPDATE media SET storedAs = '$storedAs' WHERE mediaid = $new_mediaid";
762 if (!$db->query($SQL))762 if (!$db->query($SQL))
@@ -766,20 +766,20 @@
766 $this->response->keepOpen = true;766 $this->response->keepOpen = true;
767 return $this->response;767 return $this->response;
768 }768 }
769 769
770 //Thumb770 //Thumb
771 if ($ext == "jpeg" || $ext == "jpg" || $ext == "png")771 if ($ext == "jpeg" || $ext == "jpg" || $ext == "png")
772 {772 {
773 //Create the thumbnail773 //Create the thumbnail
774 ResizeImage($databaseDir.$storedAs, $databaseDir."tn_".$storedAs, 80, 80);774 ResizeImage($databaseDir.$storedAs, $databaseDir."tn_".$storedAs, 80, 80);
775 }775 }
776 776
777 // Update the existing record with the new record's id777 // Update the existing record with the new record's id
778 $SQL = "UPDATE media SET isEdited = 1, editedMediaID = $new_mediaid ";778 $SQL = "UPDATE media SET isEdited = 1, editedMediaID = $new_mediaid ";
779 $SQL .= " WHERE IFNULL(editedMediaID,0) <> $new_mediaid AND mediaID = $mediaid ";779 $SQL .= " WHERE IFNULL(editedMediaID,0) <> $new_mediaid AND mediaID = $mediaid ";
780 780
781 Debug::LogEntry($db, 'audit', $SQL);781 Debug::LogEntry($db, 'audit', $SQL);
782 782
783 if (!$db->query($SQL))783 if (!$db->query($SQL))
784 {784 {
785 trigger_error($db->error());785 trigger_error($db->error());
@@ -793,54 +793,54 @@
793 {793 {
794 // Editing the existing record794 // Editing the existing record
795 $new_mediaid = $mediaid;795 $new_mediaid = $mediaid;
796 796
797 $SQL = "UPDATE media SET name = '%s', duration = %d, permissionID = %d";797 $SQL = "UPDATE media SET name = '%s', duration = %d, permissionID = %d";
798 $SQL .= " WHERE mediaID = %d ";798 $SQL .= " WHERE mediaID = %d ";
799 $SQL = sprintf($SQL, $db->escape_string($name), $duration, $permissionid, $mediaid);799 $SQL = sprintf($SQL, $db->escape_string($name), $duration, $permissionid, $mediaid);
800 800
801 Debug::LogEntry($db, 'audit', $SQL);801 Debug::LogEntry($db, 'audit', $SQL);
802 802
803 if (!$db->query($SQL))803 if (!$db->query($SQL))
804 {804 {
805 trigger_error($db->error());805 trigger_error($db->error());
806 806
807 $this->response->SetError('Database error editing this media record.');807 $this->response->SetError('Database error editing this media record.');
808 $this->response->keepOpen = true;808 $this->response->keepOpen = true;
809 return $this->response;809 return $this->response;
810 }810 }
811 }811 }
812 812
813 // Required Attributes813 // Required Attributes
814 $this->mediaid = $new_mediaid;814 $this->mediaid = $new_mediaid;
815 $this->duration = $duration;815 $this->duration = $duration;
816 816
817 // Any Options817 // Any Options
818 $this->SetOption('uri', $storedAs);818 $this->SetOption('uri', $storedAs);
819 819
820 // Should have built the media object entirely by this time820 // Should have built the media object entirely by this time
821 if ($regionid != '')821 if ($regionid != '')
822 {822 {
823 // This saves the Media Object to the Region823 // This saves the Media Object to the Region
824 $this->UpdateRegion();824 $this->UpdateRegion();
825 825
826 $this->response->loadForm = true;826 $this->response->loadForm = true;
827 $this->response->loadFormUri = "index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions";;827 $this->response->loadFormUri = "index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions";;
828 }828 }
829 else829 else
830 {830 {
831 $this->response->loadFormUri = "index.php?p=content&q=displayForms&sp=add"; 831 $this->response->loadFormUri = "index.php?p=content&q=displayForms&sp=add";
832 $this->response->message = 'Edited the Image.';832 $this->response->message = 'Edited the Image.';
833 833
834 }834 }
835 835
836 return $this->response;836 return $this->response;
837 }837 }
838 838
839 /**839 /**
840 * Delete Media from the Database840 * Delete Media from the Database
841 * @return 841 * @return
842 */842 */
843 public function DeleteMedia() 843 public function DeleteMedia()
844 {844 {
845 $db =& $this->db;845 $db =& $this->db;
846 $layoutid = $this->layoutid;846 $layoutid = $this->layoutid;
@@ -848,10 +848,10 @@
848 $mediaid = $this->mediaid;848 $mediaid = $this->mediaid;
849 $userid = Kit::GetParam('userid', _SESSION, _INT);849 $userid = Kit::GetParam('userid', _SESSION, _INT);
850 $options = Kit::GetParam('options', _POST, _WORD);850 $options = Kit::GetParam('options', _POST, _WORD);
851 851
852 // Stored As from the XML852 // Stored As from the XML
853 $this->uri = $this->GetOption('uri');853 $this->uri = $this->GetOption('uri');
854 854
855 // Do we need to remove this from a layout?855 // Do we need to remove this from a layout?
856 if ($layoutid != '')856 if ($layoutid != '')
857 {857 {
@@ -863,72 +863,72 @@
863 // Set this message now in preparation863 // Set this message now in preparation
864 $this->response->message = 'Deleted the Media.';864 $this->response->message = 'Deleted the Media.';
865 }865 }
866 866
867 // If we are set to retire we retire867 // If we are set to retire we retire
868 if ($options == "retire")868 if ($options == "retire")
869 {869 {
870 //Update the media record to say it is retired870 //Update the media record to say it is retired
871 $SQL = "UPDATE media SET retired = 1 WHERE mediaid = $mediaid ";871 $SQL = "UPDATE media SET retired = 1 WHERE mediaid = $mediaid ";
872 872
873 if (!$db->query($SQL))873 if (!$db->query($SQL))
874 {874 {
875 trigger_error($db->error());875 trigger_error($db->error());
876 876
877 $this->response->SetError('Database error retiring this media record.');877 $this->response->SetError('Database error retiring this media record.');
878 $this->response->keepOpen = true;878 $this->response->keepOpen = true;
879 return $this->response;879 return $this->response;
880 }880 }
881 }881 }
882 882
883 //If we are set to delete, we delete883 //If we are set to delete, we delete
884 if ($options == "delete")884 if ($options == "delete")
885 {885 {
886 //Update the media record to say it is retired886 //Update the media record to say it is retired
887 $SQL = "DELETE FROM media WHERE mediaid = $mediaid ";887 $SQL = "DELETE FROM media WHERE mediaid = $mediaid ";
888 888
889 if (!$db->query($SQL))889 if (!$db->query($SQL))
890 {890 {
891 trigger_error($db->error());891 trigger_error($db->error());
892 892
893 $this->response->SetError('Database error deleting this media record.');893 $this->response->SetError('Database error deleting this media record.');
894 $this->response->keepOpen = true;894 $this->response->keepOpen = true;
895 return $this->response;895 return $this->response;
896 }896 }
897 897
898 $this->DeleteMediaFiles();898 $this->DeleteMediaFiles();
899 }899 }
900 900
901 return $this->response;901 return $this->response;
902 }902 }
903 903
904 /**904 /**
905 * Deletes the media files associated with this record905 * Deletes the media files associated with this record
906 * @return 906 * @return
907 */907 */
908 private function DeleteMediaFiles()908 private function DeleteMediaFiles()
909 {909 {
910 $db =& $this->db;910 $db =& $this->db;
911 911
912 //Library location912 //Library location
913 $databaseDir = Config::GetSetting($db, "LIBRARY_LOCATION");913 $databaseDir = Config::GetSetting($db, "LIBRARY_LOCATION");
914 914
915 //3 things to check for..915 //3 things to check for..
916 //the actual file, the thumbnail, the background916 //the actual file, the thumbnail, the background
917 if (file_exists($databaseDir.$this->uri))917 if (file_exists($databaseDir.$this->uri))
918 {918 {
919 unlink($databaseDir.$this->uri);919 unlink($databaseDir.$this->uri);
920 }920 }
921 921
922 if (file_exists($databaseDir."tn_".$this->uri))922 if (file_exists($databaseDir."tn_".$this->uri))
923 {923 {
924 unlink($databaseDir."tn_".$this->uri);924 unlink($databaseDir."tn_".$this->uri);
925 }925 }
926 926
927 if (file_exists($databaseDir."bg_".$this->uri))927 if (file_exists($databaseDir."bg_".$this->uri))
928 {928 {
929 unlink($databaseDir."bg_".$this->uri);929 unlink($databaseDir."bg_".$this->uri);
930 }930 }
931 931
932 return true;932 return true;
933 }933 }
934}934}
935935
=== modified file 'server/modules/powerpoint.module.php'
--- server/modules/powerpoint.module.php 2009-06-28 10:47:06 +0000
+++ server/modules/powerpoint.module.php 2009-10-01 21:40:25 +0000
@@ -8,7 +8,7 @@
8 * Xibo is free software: you can redistribute it and/or modify8 * Xibo is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Affero General Public License as published by9 * it under the terms of the GNU Affero General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or10 * the Free Software Foundation, either version 3 of the License, or
11 * any later version. 11 * any later version.
12 *12 *
13 * Xibo is distributed in the hope that it will be useful,13 * Xibo is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -17,31 +17,31 @@
17 *17 *
18 * You should have received a copy of the GNU Affero General Public License18 * You should have received a copy of the GNU Affero General Public License
19 * along with Xibo. If not, see <http://www.gnu.org/licenses/>.19 * along with Xibo. If not, see <http://www.gnu.org/licenses/>.
20 */ 20 */
21class powerpoint extends Module21class powerpoint extends Module
22{22{
23 // Custom Media information23 // Custom Media information
24 private $uri;24 private $uri;
25 private $maxFileSize;25 private $maxFileSize;
26 private $maxFileSizeBytes;26 private $maxFileSizeBytes;
27 27
28 public function __construct(database $db, user $user, $mediaid = '', $layoutid = '', $regionid = '')28 public function __construct(database $db, user $user, $mediaid = '', $layoutid = '', $regionid = '')
29 {29 {
30 // Must set the type of the class30 // Must set the type of the class
31 $this->type = 'powerpoint';31 $this->type = 'powerpoint';
32 32
33 // Get the max upload size from PHP33 // Get the max upload size from PHP
34 $this->maxFileSize = ini_get('upload_max_filesize');34 $this->maxFileSize = ini_get('upload_max_filesize');
35 $this->maxFileSizeBytes = convertBytes($this->maxFileSize);35 $this->maxFileSizeBytes = convertBytes($this->maxFileSize);
36 36
37 // Must call the parent class 37 // Must call the parent class
38 parent::__construct($db, $user, $mediaid, $layoutid, $regionid);38 parent::__construct($db, $user, $mediaid, $layoutid, $regionid);
39 }39 }
40 40
41 /**41 /**
42 * Sets the Layout and Region Information42 * Sets the Layout and Region Information
43 * it will then fill in any blanks it has about this media if it can43 * it will then fill in any blanks it has about this media if it can
44 * @return 44 * @return
45 * @param $layoutid Object45 * @param $layoutid Object
46 * @param $regionid Object46 * @param $regionid Object
47 * @param $mediaid Object47 * @param $mediaid Object
@@ -53,75 +53,75 @@
53 $this->regionid = $regionid;53 $this->regionid = $regionid;
54 $mediaid = $this->mediaid;54 $mediaid = $this->mediaid;
55 $this->existingMedia = false;55 $this->existingMedia = false;
56 56
57 if ($this->regionSpecific == 1) return;57 if ($this->regionSpecific == 1) return;
58 58
59 // Load what we know about this media into the object59 // Load what we know about this media into the object
60 $SQL = "SELECT name, type, duration, originalFilename, userID, permissionID, retired, storedAs, isEdited, editedMediaID FROM media WHERE mediaID = $mediaid ";60 $SQL = "SELECT name, type, duration, originalFilename, userID, permissionID, retired, storedAs, isEdited, editedMediaID FROM media WHERE mediaID = $mediaid ";
61 61
62 if (!$result = $db->query($SQL))62 if (!$result = $db->query($SQL))
63 {63 {
64 trigger_error($db->error()); //log the error64 trigger_error($db->error()); //log the error
65 return false;65 return false;
66 }66 }
67 67
68 if ($db->num_rows($result) != 1)68 if ($db->num_rows($result) != 1)
69 {69 {
70 trigger_error("More than one row for mediaId [$mediaid] How can this be?");70 trigger_error("More than one row for mediaId [$mediaid] How can this be?");
71 return false;71 return false;
72 }72 }
73 73
74 $row = $db->get_row($result);74 $row = $db->get_row($result);
75 $duration = $row[2];75 $duration = $row[2];
76 $storedAs = $row[7];76 $storedAs = $row[7];
77 77
78 // Required Attributes78 // Required Attributes
79 $this->duration = $duration;79 $this->duration = $duration;
80 80
81 // Any Options81 // Any Options
82 $this->SetOption('uri', $storedAs);82 $this->SetOption('uri', $storedAs);
83 83
84 return true;84 return true;
85 }85 }
86 86
87 /**87 /**
88 * Return the Add Form as HTML88 * Return the Add Form as HTML
89 * @return 89 * @return
90 */90 */
91 public function AddForm()91 public function AddForm()
92 {92 {
93 global $session;93 global $session;
94 $db =& $this->db;94 $db =& $this->db;
95 $user =& $this->user;95 $user =& $this->user;
96 96
97 // Would like to get the regions width / height 97 // Would like to get the regions width / height
98 $layoutid = $this->layoutid;98 $layoutid = $this->layoutid;
99 $regionid = $this->regionid;99 $regionid = $this->regionid;
100 100
101 // Set the Session / Security information101 // Set the Session / Security information
102 $sessionId = session_id();102 $sessionId = session_id();
103 $securityToken = CreateFormToken();103 $securityToken = CreateFormToken();
104 104
105 $session->setSecurityToken($securityToken);105 $session->setSecurityToken($securityToken);
106 106
107 //Get the default value for the shared list107 //Get the default value for the shared list
108 $default = Config::GetSetting($db,"defaultMedia");108 $default = Config::GetSetting($db,"defaultMedia");
109109
110 $permissionid = 0;110 $permissionid = 0;
111111
112 if($default=="private") 112 if($default=="private")
113 {113 {
114 $permissionid = 1;114 $permissionid = 1;
115 }115 }
116 116
117 //shared list117 //shared list
118 $shared_list = dropdownlist("SELECT permissionID, permission FROM permission", "permissionid", $permissionid);118 $shared_list = dropdownlist("SELECT permissionID, permission FROM permission", "permissionid", $permissionid);
119 119
120 //Save button is different depending on if we are on a region or not120 //Save button is different depending on if we are on a region or not
121 if ($regionid != "")121 if ($regionid != "")
122 {122 {
123 setSession('content','mediatype','powerpoint');123 setSession('content','mediatype','powerpoint');
124 124
125 $save_button = <<<END125 $save_button = <<<END
126 <input id="btnSave" type="submit" value="Save" disabled />126 <input id="btnSave" type="submit" value="Save" disabled />
127 <input class="XiboFormButton" id="btnCancel" type="button" title="Return to the Region Options" href="index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions" value="Cancel" />127 <input class="XiboFormButton" id="btnCancel" type="button" title="Return to the Region Options" href="index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions" value="Cancel" />
@@ -135,7 +135,7 @@
135 <input class="XiboFormButton" id="btnCancel" type="button" title="Close" href="index.php?p=content&q=displayForms&sp=add" value="Cancel" />135 <input class="XiboFormButton" id="btnCancel" type="button" title="Close" href="index.php?p=content&q=displayForms&sp=add" value="Cancel" />
136END;136END;
137 }137 }
138 138
139 $form = <<<FORM139 $form = <<<FORM
140 <div style="display:none"><iframe name="fileupload" width="1px" height="1px"></iframe></div>140 <div style="display:none"><iframe name="fileupload" width="1px" height="1px"></iframe></div>
141 <div>141 <div>
@@ -144,7 +144,7 @@
144 <input type="hidden" id="SecurityToken" value="$securityToken" />144 <input type="hidden" id="SecurityToken" value="$securityToken" />
145 <input type="hidden" name="MAX_FILE_SIZE" value="$this->maxFileSizeBytes" />145 <input type="hidden" name="MAX_FILE_SIZE" value="$this->maxFileSizeBytes" />
146 <table>146 <table>
147 <tr> 147 <tr>
148 <td><label for="file">Powerpoint File<span class="required">*</span></label></td>148 <td><label for="file">Powerpoint File<span class="required">*</span></label></td>
149 <td colspan="3">149 <td colspan="3">
150 <input type="file" name="media_file" onchange="fileFormSubmit();this.form.submit();" />150 <input type="file" name="media_file" onchange="fileFormSubmit();this.form.submit();" />
@@ -172,11 +172,11 @@
172 <td><label for="permissionid">Sharing<span class="required">*</span></label></td>172 <td><label for="permissionid">Sharing<span class="required">*</span></label></td>
173 <td>173 <td>
174 $shared_list174 $shared_list
175 </td> 175 </td>
176 </tr>176 </tr>
177 <tr>177 <tr>
178 <td></td>178 <td></td>
179 <td>This form accepts: <span class="required">ppt/pps</span> files up to a maximum size of <span class="required">$this->maxFileSize</span>.</td>179 <td>This form accepts: <span class="required">$this->validExtensionsText</span> files up to a maximum size of <span class="required">$this->maxFileSize</span>.</td>
180 </tr>180 </tr>
181 <tr>181 <tr>
182 <td></td>182 <td></td>
@@ -194,49 +194,49 @@
194194
195 return $this->response;195 return $this->response;
196 }196 }
197 197
198 /**198 /**
199 * Return the Edit Form as HTML199 * Return the Edit Form as HTML
200 * @return 200 * @return
201 */201 */
202 public function EditForm()202 public function EditForm()
203 {203 {
204 global $session;204 global $session;
205 $db =& $this->db;205 $db =& $this->db;
206 $user =& $this->user;206 $user =& $this->user;
207 207
208 // Would like to get the regions width / height 208 // Would like to get the regions width / height
209 $layoutid = $this->layoutid;209 $layoutid = $this->layoutid;
210 $regionid = $this->regionid;210 $regionid = $this->regionid;
211 $mediaid = $this->mediaid;211 $mediaid = $this->mediaid;
212 $lkid = $this->lkid;212 $lkid = $this->lkid;
213 $userid = Kit::GetParam('userid', _SESSION, _INT);213 $userid = Kit::GetParam('userid', _SESSION, _INT);
214 214
215 // Set the Session / Security information215 // Set the Session / Security information
216 $sessionId = session_id();216 $sessionId = session_id();
217 $securityToken = CreateFormToken();217 $securityToken = CreateFormToken();
218 218
219 $session->setSecurityToken($securityToken);219 $session->setSecurityToken($securityToken);
220 220
221 // Load what we know about this media into the object221 // Load what we know about this media into the object
222 $SQL = "SELECT name, originalFilename, userID, permissionID, retired, storedAs, isEdited, editedMediaID FROM media WHERE mediaID = $mediaid ";222 $SQL = "SELECT name, originalFilename, userID, permissionID, retired, storedAs, isEdited, editedMediaID FROM media WHERE mediaID = $mediaid ";
223 223
224 if (!$result = $db->query($SQL))224 if (!$result = $db->query($SQL))
225 {225 {
226 trigger_error($db->error()); //log the error226 trigger_error($db->error()); //log the error
227 227
228 $this->message = "Error querying for the Media information with media ID [$mediaid] ";228 $this->message = "Error querying for the Media information with media ID [$mediaid] ";
229 return false;229 return false;
230 }230 }
231 231
232 if ($db->num_rows($result) != 1)232 if ($db->num_rows($result) != 1)
233 {233 {
234 trigger_error("More than one row for mediaId [$mediaid] How can this be?");234 trigger_error("More than one row for mediaId [$mediaid] How can this be?");
235 235
236 $this->message = "Error querying for the Media information with media ID [$mediaid] ";236 $this->message = "Error querying for the Media information with media ID [$mediaid] ";
237 return false;237 return false;
238 }238 }
239 239
240 $row = $db->get_row($result);240 $row = $db->get_row($result);
241 $name = $row[0];241 $name = $row[0];
242 $originalFilename = $row[1];242 $originalFilename = $row[1];
@@ -246,23 +246,23 @@
246 $storedAs = $row[5];246 $storedAs = $row[5];
247 $isEdited = $row[6];247 $isEdited = $row[6];
248 $editedMediaID = $row[7];248 $editedMediaID = $row[7];
249 249
250 // derive the ext250 // derive the ext
251 $ext = strtolower(substr(strrchr($originalFilename, "."), 1));251 $ext = strtolower(substr(strrchr($originalFilename, "."), 1));
252 252
253 //Calc the permissions on it aswell253 //Calc the permissions on it aswell
254 list($see_permissions , $edit_permissions) = $user->eval_permission($userid, $permissionid);254 list($see_permissions , $edit_permissions) = $user->eval_permission($userid, $permissionid);
255 255
256 //shared list256 //shared list
257 $shared_list = dropdownlist("SELECT permissionID, permission FROM permission", "permissionid", $permissionid);257 $shared_list = dropdownlist("SELECT permissionID, permission FROM permission", "permissionid", $permissionid);
258 258
259 //Save button is different depending on if we are on a region or not259 //Save button is different depending on if we are on a region or not
260 if ($regionid != "")260 if ($regionid != "")
261 {261 {
262 setSession('content','mediatype','powerpoint');262 setSession('content','mediatype','powerpoint');
263 263
264 $extraNotes = '<em>Note: Uploading a new media item here will replace it on this layout only.</em>';264 $extraNotes = '<em>Note: Uploading a new media item here will replace it on this layout only.</em>';
265 265
266 $save_button = <<<END266 $save_button = <<<END
267 <input id="btnSave" type="submit" value="Save" />267 <input id="btnSave" type="submit" value="Save" />
268 <input class="XiboFormButton" id="btnCancel" type="button" title="Return to the Region Options" href="index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions" value="Cancel" />268 <input class="XiboFormButton" id="btnCancel" type="button" title="Return to the Region Options" href="index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions" value="Cancel" />
@@ -272,13 +272,13 @@
272 else272 else
273 {273 {
274 $extraNotes = '<em>Note: Uploading a new media item here will replace it on this layout only.</em>';274 $extraNotes = '<em>Note: Uploading a new media item here will replace it on this layout only.</em>';
275 275
276 $save_button = <<<END276 $save_button = <<<END
277 <input id="btnSave" type="submit" value="Save" />277 <input id="btnSave" type="submit" value="Save" />
278 <input id="btnCancel" type="button" title="Close" onclick="$('#div_dialog').dialog('close')" value="Cancel" />278 <input id="btnCancel" type="button" title="Close" onclick="$('#div_dialog').dialog('close')" value="Cancel" />
279END;279END;
280 }280 }
281 281
282 $form = <<<FORM282 $form = <<<FORM
283 <div style="display:none"><iframe name="fileupload" width="1px" height="1px"></iframe></div>283 <div style="display:none"><iframe name="fileupload" width="1px" height="1px"></iframe></div>
284 <div>284 <div>
@@ -287,7 +287,7 @@
287 <input type="hidden" id="SecurityToken" value="$securityToken" />287 <input type="hidden" id="SecurityToken" value="$securityToken" />
288 <input type="hidden" name="MAX_FILE_SIZE" value="$this->maxFileSizeBytes" />288 <input type="hidden" name="MAX_FILE_SIZE" value="$this->maxFileSizeBytes" />
289 <table>289 <table>
290 <tr> 290 <tr>
291 <td><label for="file">New Powerpoint File<span class="required">*</span></label></td>291 <td><label for="file">New Powerpoint File<span class="required">*</span></label></td>
292 <td colspan="3">292 <td colspan="3">
293 <input type="file" name="media_file" onchange="fileFormSubmit();this.form.submit();" />293 <input type="file" name="media_file" onchange="fileFormSubmit();this.form.submit();" />
@@ -319,11 +319,11 @@
319 <td><label for="permissionid">Sharing<span class="required">*</span></label></td>319 <td><label for="permissionid">Sharing<span class="required">*</span></label></td>
320 <td>320 <td>
321 $shared_list321 $shared_list
322 </td> 322 </td>
323 </tr>323 </tr>
324 <tr>324 <tr>
325 <td></td>325 <td></td>
326 <td>This form accepts: <span class="required">ppt/pps</span> files up to a maximum size of <span class="required">$this->maxFileSize</span>.</td>326 <td>This form accepts: <span class="required">$this->validExtensionsText</span> files up to a maximum size of <span class="required">$this->maxFileSize</span>.</td>
327 </tr>327 </tr>
328 <tr>328 <tr>
329 <td></td>329 <td></td>
@@ -343,50 +343,50 @@
343 $this->response->dialogWidth = '450px';343 $this->response->dialogWidth = '450px';
344 $this->response->dialogHeight = '280px';344 $this->response->dialogHeight = '280px';
345345
346 return $this->response; 346 return $this->response;
347 }347 }
348 348
349 /**349 /**
350 * Return the Delete Form as HTML350 * Return the Delete Form as HTML
351 * @return 351 * @return
352 */352 */
353 public function DeleteForm()353 public function DeleteForm()
354 {354 {
355 $db =& $this->db;355 $db =& $this->db;
356 $user =& $this->user;356 $user =& $this->user;
357 357
358 // Would like to get the regions width / height 358 // Would like to get the regions width / height
359 $layoutid = $this->layoutid;359 $layoutid = $this->layoutid;
360 $regionid = $this->regionid;360 $regionid = $this->regionid;
361 $mediaid = $this->mediaid;361 $mediaid = $this->mediaid;
362 $lkid = $this->lkid;362 $lkid = $this->lkid;
363 $userid = Kit::GetParam('userid', _SESSION, _INT);363 $userid = Kit::GetParam('userid', _SESSION, _INT);
364 364
365 $options = "";365 $options = "";
366 //Always have the abilty to unassign from the region366 //Always have the abilty to unassign from the region
367 $options .= "unassign|Unassign from this region only";367 $options .= "unassign|Unassign from this region only";
368 368
369 // Load what we know about this media into the object369 // Load what we know about this media into the object
370 $SQL = "SELECT name, type, duration, originalFilename, userID, permissionID, retired, storedAs, isEdited, editedMediaID FROM media WHERE mediaID = $mediaid ";370 $SQL = "SELECT name, type, duration, originalFilename, userID, permissionID, retired, storedAs, isEdited, editedMediaID FROM media WHERE mediaID = $mediaid ";
371 371
372 if (!$result = $db->query($SQL))372 if (!$result = $db->query($SQL))
373 {373 {
374 trigger_error($db->error()); //log the error374 trigger_error($db->error()); //log the error
375 375
376 $this->response->SetError('Error querying for the Media information with media ID [$mediaid]');376 $this->response->SetError('Error querying for the Media information with media ID [$mediaid]');
377 $this->response->keepOpen = true;377 $this->response->keepOpen = true;
378 return $this->response;378 return $this->response;
379 }379 }
380 380
381 if ($db->num_rows($result) != 1)381 if ($db->num_rows($result) != 1)
382 {382 {
383 trigger_error("More than one row for mediaId [$mediaid] How can this be?");383 trigger_error("More than one row for mediaId [$mediaid] How can this be?");
384 384
385 $this->response->SetError('Error querying for the Media information with media ID [$mediaid]');385 $this->response->SetError('Error querying for the Media information with media ID [$mediaid]');
386 $this->response->keepOpen = true;386 $this->response->keepOpen = true;
387 return $this->response;387 return $this->response;
388 }388 }
389 389
390 $row = $db->get_row($result);390 $row = $db->get_row($result);
391 $name = $row[0];391 $name = $row[0];
392 $duration = $row[2];392 $duration = $row[2];
@@ -397,18 +397,18 @@
397 $storedAs = $row[7];397 $storedAs = $row[7];
398 $isEdited = $row[8];398 $isEdited = $row[8];
399 $editedMediaID = $row[9];399 $editedMediaID = $row[9];
400 400
401 // derive the ext401 // derive the ext
402 $ext = strtolower(substr(strrchr($originalFilename, "."), 1));402 $ext = strtolower(substr(strrchr($originalFilename, "."), 1));
403 403
404 //Calc the permissions on it aswell404 //Calc the permissions on it aswell
405 list($see_permissions , $edit_permissions) = $user->eval_permission($userid, $permissionid);405 list($see_permissions , $edit_permissions) = $user->eval_permission($userid, $permissionid);
406 406
407 //Is this user allowed to edit this media?407 //Is this user allowed to edit this media?
408 if ($edit_permissions)408 if ($edit_permissions)
409 {409 {
410 $options .= ",retire|Unassign from this region and retire";410 $options .= ",retire|Unassign from this region and retire";
411 411
412 //Is this media retired?412 //Is this media retired?
413 if ($editedMediaID != "")413 if ($editedMediaID != "")
414 {414 {
@@ -418,7 +418,7 @@
418 {418 {
419 $revised = false;419 $revised = false;
420 }420 }
421 421
422 //Is this media being used anywhere else?422 //Is this media being used anywhere else?
423 if ($layoutid == "")423 if ($layoutid == "")
424 {424 {
@@ -429,8 +429,8 @@
429 {429 {
430 $SQL = "SELECT layoutID FROM lklayoutmedia WHERE mediaID = $mediaid AND layoutid <> $layoutid AND regionID <> '$regionid' ";430 $SQL = "SELECT layoutID FROM lklayoutmedia WHERE mediaID = $mediaid AND layoutid <> $layoutid AND regionID <> '$regionid' ";
431 }431 }
432 432
433 if (!$results = $db->query($SQL)) 433 if (!$results = $db->query($SQL))
434 {434 {
435 trigger_error($db->error());435 trigger_error($db->error());
436436
@@ -457,9 +457,9 @@
457 return $this->response;457 return $this->response;
458 }458 }
459 }459 }
460 460
461 $options = ltrim($options, ",");461 $options = ltrim($options, ",");
462 462
463 $deleteOptions = listcontent($options,"options");463 $deleteOptions = listcontent($options,"options");
464464
465 //we can delete465 //we can delete
@@ -474,19 +474,19 @@
474 <input id="btnCancel" type="button" title="No / Cancel" href="index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions" onclick="$('#div_dialog').dialog('close');return false; " value="No" />474 <input id="btnCancel" type="button" title="No / Cancel" href="index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions" onclick="$('#div_dialog').dialog('close');return false; " value="No" />
475 </form>475 </form>
476END;476END;
477 477
478 $this->response->html = $form;478 $this->response->html = $form;
479 $this->response->dialogTitle = 'Delete Powerpoint';479 $this->response->dialogTitle = 'Delete Powerpoint';
480 $this->response->dialogSize = true;480 $this->response->dialogSize = true;
481 $this->response->dialogWidth = '450px';481 $this->response->dialogWidth = '450px';
482 $this->response->dialogHeight = '280px';482 $this->response->dialogHeight = '280px';
483483
484 return $this->response; 484 return $this->response;
485 }485 }
486 486
487 /**487 /**
488 * Add Media to the Database488 * Add Media to the Database
489 * @return 489 * @return
490 */490 */
491 public function AddMedia()491 public function AddMedia()
492 {492 {
@@ -495,62 +495,62 @@
495 $regionid = $this->regionid;495 $regionid = $this->regionid;
496 $mediaid = $this->mediaid;496 $mediaid = $this->mediaid;
497 $userid = Kit::GetParam('userid', _SESSION, _INT);497 $userid = Kit::GetParam('userid', _SESSION, _INT);
498 498
499 // File data499 // File data
500 $tmpName = Kit::GetParam('hidFileID', _POST, _STRING);500 $tmpName = Kit::GetParam('hidFileID', _POST, _STRING);
501 501
502 if ($tmpName == '')502 if ($tmpName == '')
503 {503 {
504 $this->response->SetError('Cannot save Powerpoint details. <br/> You must have picked a file.');504 $this->response->SetError('Cannot save Powerpoint details. <br/> You must have picked a file.');
505 $this->response->keepOpen = true;505 $this->response->keepOpen = true;
506 return $this->response;506 return $this->response;
507 }507 }
508 508
509 // File name and extension (orignial name)509 // File name and extension (orignial name)
510 $fileName = Kit::GetParam('txtFileName', _POST, _STRING);510 $fileName = Kit::GetParam('txtFileName', _POST, _STRING);
511 $fileName = basename($fileName);511 $fileName = basename($fileName);
512 $ext = strtolower(substr(strrchr($fileName, "."), 1));512 $ext = strtolower(substr(strrchr($fileName, "."), 1));
513 513
514 // Other properties514 // Other properties
515 $name = Kit::GetParam('name', _POST, _STRING);515 $name = Kit::GetParam('name', _POST, _STRING);
516 $duration = Kit::GetParam('duration', _POST, _INT, 0);516 $duration = Kit::GetParam('duration', _POST, _INT, 0);
517 $permissionid = Kit::GetParam('permissionid', _POST, _INT, 1);517 $permissionid = Kit::GetParam('permissionid', _POST, _INT, 1);
518 518
519 if ($name == '') $name = Kit::ValidateParam($fileName, _FILENAME);519 if ($name == '') $name = Kit::ValidateParam($fileName, _FILENAME);
520 520
521 // Validation521 // Validation
522 if ($ext != "ppt")522 if (!$this->IsValidExtension($ext))
523 {523 {
524 $this->response->SetError('Only PPT files are accepted - Are you sure this is an powerpoint?');524 $this->response->SetError('Your file has an extension not supported by this Media Type.');
525 $this->response->keepOpen = true;525 $this->response->keepOpen = true;
526 return $this->response;526 return $this->response;
527 }527 }
528 528
529 // Make sure the name isnt too long529 // Make sure the name isnt too long
530 if (strlen($name) > 100) 530 if (strlen($name) > 100)
531 {531 {
532 $this->response->SetError('The name cannot be longer than 100 characters');532 $this->response->SetError('The name cannot be longer than 100 characters');
533 $this->response->keepOpen = true;533 $this->response->keepOpen = true;
534 return $this->response;534 return $this->response;
535 }535 }
536 536
537 if ($duration == 0)537 if ($duration == 0)
538 {538 {
539 $this->response->SetError('You must enter a duration.');539 $this->response->SetError('You must enter a duration.');
540 $this->response->keepOpen = true;540 $this->response->keepOpen = true;
541 return $this->response;541 return $this->response;
542 }542 }
543 543
544 // Ensure the name is not already in the database544 // Ensure the name is not already in the database
545 $SQL = sprintf("SELECT name FROM media WHERE name = '%s' AND userid = %d", $db->escape_string($name), $userid);545 $SQL = sprintf("SELECT name FROM media WHERE name = '%s' AND userid = %d", $db->escape_string($name), $userid);
546546
547 if(!$result = $db->query($SQL)) 547 if(!$result = $db->query($SQL))
548 {548 {
549 trigger_error($db->error());549 trigger_error($db->error());
550 $this->response->SetError('Error checking whether the media name is ok. Try choosing a different name.');550 $this->response->SetError('Error checking whether the media name is ok. Try choosing a different name.');
551 $this->response->keepOpen = true;551 $this->response->keepOpen = true;
552 return $this->response;552 return $this->response;
553 } 553 }
554554
555 if ($db->num_rows($result) != 0)555 if ($db->num_rows($result) != 0)
556 {556 {
@@ -558,11 +558,11 @@
558 $this->response->keepOpen = true;558 $this->response->keepOpen = true;
559 return $this->response;559 return $this->response;
560 }560 }
561 561
562 // All OK to insert this record562 // All OK to insert this record
563 $SQL = "INSERT INTO media (name, type, duration, originalFilename, permissionID, userID, retired ) ";563 $SQL = "INSERT INTO media (name, type, duration, originalFilename, permissionID, userID, retired ) ";
564 $SQL .= "VALUES ('%s', 'powerpoint', '%s', '%s', %d, %d, 0) ";564 $SQL .= "VALUES ('%s', 'powerpoint', '%s', '%s', %d, %d, 0) ";
565 565
566 $SQL = sprintf($SQL, $db->escape_string($name), $db->escape_string($duration), $db->escape_string($fileName), $permissionid, $userid);566 $SQL = sprintf($SQL, $db->escape_string($name), $db->escape_string($duration), $db->escape_string($fileName), $permissionid, $userid);
567567
568 if (!$mediaid = $db->insert_query($SQL))568 if (!$mediaid = $db->insert_query($SQL))
@@ -572,19 +572,19 @@
572 $this->response->keepOpen = true;572 $this->response->keepOpen = true;
573 return $this->response;573 return $this->response;
574 }574 }
575 575
576 // File upload directory.. get this from the settings object576 // File upload directory.. get this from the settings object
577 $databaseDir = Config::GetSetting($db, "LIBRARY_LOCATION");577 $databaseDir = Config::GetSetting($db, "LIBRARY_LOCATION");
578 578
579 // What are we going to store this media as...579 // What are we going to store this media as...
580 $storedAs = $mediaid.".".$ext;580 $storedAs = $mediaid.".".$ext;
581 581
582 // Now we need to move the file582 // Now we need to move the file
583 if (!$result = rename($databaseDir."temp/".$tmpName, $databaseDir.$storedAs))583 if (!$result = rename($databaseDir."temp/".$tmpName, $databaseDir.$storedAs))
584 {584 {
585 // If we couldnt move it - we need to delete the media record we just added585 // If we couldnt move it - we need to delete the media record we just added
586 $SQL = sprintf("DELETE FROM media WHERE mediaID = %d ", $mediaid);586 $SQL = sprintf("DELETE FROM media WHERE mediaID = %d ", $mediaid);
587 587
588 if (!$db->query($SQL))588 if (!$db->query($SQL))
589 {589 {
590 trigger_error($db->error());590 trigger_error($db->error());
@@ -593,23 +593,23 @@
593 return $this->response;593 return $this->response;
594 }594 }
595 }595 }
596 596
597 // Update the media record to include this information597 // Update the media record to include this information
598 $SQL = sprintf("UPDATE media SET storedAs = '%s' WHERE mediaid = %d", $storedAs, $mediaid);598 $SQL = sprintf("UPDATE media SET storedAs = '%s' WHERE mediaid = %d", $storedAs, $mediaid);
599 599
600 if (!$db->query($SQL))600 if (!$db->query($SQL))
601 {601 {
602 trigger_error($db->error());602 trigger_error($db->error());
603 return true;603 return true;
604 }604 }
605 605
606 // Required Attributes606 // Required Attributes
607 $this->mediaid = $mediaid;607 $this->mediaid = $mediaid;
608 $this->duration = $duration;608 $this->duration = $duration;
609 609
610 // Any Options610 // Any Options
611 $this->SetOption('uri', $storedAs);611 $this->SetOption('uri', $storedAs);
612 612
613 // Should have built the media object entirely by this time613 // Should have built the media object entirely by this time
614 if ($regionid != '')614 if ($regionid != '')
615 {615 {
@@ -619,18 +619,18 @@
619 }619 }
620 else620 else
621 {621 {
622 $this->response->loadFormUri = "index.php?p=content&q=displayForms&sp=add"; 622 $this->response->loadFormUri = "index.php?p=content&q=displayForms&sp=add";
623 }623 }
624 624
625 // We want to load a new form625 // We want to load a new form
626 $this->response->loadForm = true;626 $this->response->loadForm = true;
627 627
628 return $this->response;628 return $this->response;
629 }629 }
630 630
631 /**631 /**
632 * Edit Media in the Database632 * Edit Media in the Database
633 * @return 633 * @return
634 */634 */
635 public function EditMedia()635 public function EditMedia()
636 {636 {
@@ -639,13 +639,13 @@
639 $regionid = $this->regionid;639 $regionid = $this->regionid;
640 $mediaid = $this->mediaid;640 $mediaid = $this->mediaid;
641 $userid = Kit::GetParam('userid', _SESSION, _INT);641 $userid = Kit::GetParam('userid', _SESSION, _INT);
642 642
643 // Stored As from the XML643 // Stored As from the XML
644 $storedAs = $this->GetOption('uri');644 $storedAs = $this->GetOption('uri');
645 645
646 // File data646 // File data
647 $tmpName = Kit::GetParam('hidFileID', _POST, _STRING);647 $tmpName = Kit::GetParam('hidFileID', _POST, _STRING);
648 648
649 if ($tmpName == '')649 if ($tmpName == '')
650 {650 {
651 $fileRevision = false;651 $fileRevision = false;
@@ -653,30 +653,30 @@
653 else653 else
654 {654 {
655 $fileRevision = true;655 $fileRevision = true;
656 656
657 // File name and extension (orignial name)657 // File name and extension (orignial name)
658 $fileName = Kit::GetParam('txtFileName', _POST, _STRING);658 $fileName = Kit::GetParam('txtFileName', _POST, _STRING);
659 $fileName = basename($fileName);659 $fileName = basename($fileName);
660 $ext = strtolower(substr(strrchr($fileName, "."), 1));660 $ext = strtolower(substr(strrchr($fileName, "."), 1));
661 661
662 if ($ext != "ppt")662 if (!$this->IsValidExtension($ext))
663 {663 {
664 $this->response->SetError('Only PPT files are accepted - Are you sure this is a powerpoint?');664 $this->response->SetError('Your file has an extension not supported by this Media Type.');
665 $this->response->keepOpen = true;665 $this->response->keepOpen = true;
666 return $this->response;666 return $this->response;
667 }667 }
668 }668 }
669 669
670 // Other properties670 // Other properties
671 $name = Kit::GetParam('name', _POST, _STRING);671 $name = Kit::GetParam('name', _POST, _STRING);
672 $duration = Kit::GetParam('duration', _POST, _INT, 0);672 $duration = Kit::GetParam('duration', _POST, _INT, 0);
673 $permissionid = Kit::GetParam('permissionid', _POST, _INT, 1);673 $permissionid = Kit::GetParam('permissionid', _POST, _INT, 1);
674 674
675 if ($name == '')675 if ($name == '')
676 {676 {
677 if ($fileRevision)677 if ($fileRevision)
678 {678 {
679 $name = Kit::ValidateParam($fileName, _FILENAME); 679 $name = Kit::ValidateParam($fileName, _FILENAME);
680 }680 }
681 else681 else
682 {682 {
@@ -684,33 +684,33 @@
684 $this->response->keepOpen = true;684 $this->response->keepOpen = true;
685 return $this->response;685 return $this->response;
686 }686 }
687 } 687 }
688 688
689 // Make sure the name isnt too long689 // Make sure the name isnt too long
690 if (strlen($name) > 100) 690 if (strlen($name) > 100)
691 {691 {
692 $this->response->SetError('The name cannot be longer than 100 characters');692 $this->response->SetError('The name cannot be longer than 100 characters');
693 $this->response->keepOpen = true;693 $this->response->keepOpen = true;
694 return $this->response;694 return $this->response;
695 }695 }
696 696
697 if ($duration == 0)697 if ($duration == 0)
698 {698 {
699 $this->response->SetError('You must enter a duration.');699 $this->response->SetError('You must enter a duration.');
700 $this->response->keepOpen = true;700 $this->response->keepOpen = true;
701 return $this->response;701 return $this->response;
702 }702 }
703 703
704 // Ensure the name is not already in the database704 // Ensure the name is not already in the database
705 $SQL = sprintf("SELECT name FROM media WHERE name = '%s' AND userid = %d AND mediaid <> %d ", $db->escape_string($name), $userid, $mediaid);705 $SQL = sprintf("SELECT name FROM media WHERE name = '%s' AND userid = %d AND mediaid <> %d ", $db->escape_string($name), $userid, $mediaid);
706706
707 if(!$result = $db->query($SQL)) 707 if(!$result = $db->query($SQL))
708 {708 {
709 trigger_error($db->error());709 trigger_error($db->error());
710 $this->response->SetError('Error checking whether the media name is ok. Try choosing a different name.');710 $this->response->SetError('Error checking whether the media name is ok. Try choosing a different name.');
711 $this->response->keepOpen = true;711 $this->response->keepOpen = true;
712 return $this->response;712 return $this->response;
713 } 713 }
714714
715 if ($db->num_rows($result) != 0)715 if ($db->num_rows($result) != 0)
716 {716 {
@@ -718,34 +718,34 @@
718 $this->response->keepOpen = true;718 $this->response->keepOpen = true;
719 return $this->response;719 return $this->response;
720 }720 }
721 721
722 //Are we revising this media - or just plain editing722 //Are we revising this media - or just plain editing
723 if ($fileRevision)723 if ($fileRevision)
724 {724 {
725 // All OK to insert this record725 // All OK to insert this record
726 $SQL = "INSERT INTO media (name, type, duration, originalFilename, permissionID, userID, retired ) ";726 $SQL = "INSERT INTO media (name, type, duration, originalFilename, permissionID, userID, retired ) ";
727 $SQL .= "VALUES ('%s', '%s', '%s', '%s', %d, %d, 0) ";727 $SQL .= "VALUES ('%s', '%s', '%s', '%s', %d, %d, 0) ";
728 728
729 $SQL = sprintf($SQL, $db->escape_string($name), $this->type, $db->escape_string($duration), $db->escape_string($fileName), $permissionid, $userid);729 $SQL = sprintf($SQL, $db->escape_string($name), $this->type, $db->escape_string($duration), $db->escape_string($fileName), $permissionid, $userid);
730 730
731 if (!$new_mediaid = $db->insert_query($SQL))731 if (!$new_mediaid = $db->insert_query($SQL))
732 {732 {
733 trigger_error($db->error());733 trigger_error($db->error());
734 trigger_error('Error inserting replacement media record.', E_USER_ERROR);734 trigger_error('Error inserting replacement media record.', E_USER_ERROR);
735 }735 }
736 736
737 //What are we going to store this media as...737 //What are we going to store this media as...
738 $storedAs = $new_mediaid.".".$ext;738 $storedAs = $new_mediaid.".".$ext;
739 739
740 // File upload directory.. get this from the settings object740 // File upload directory.. get this from the settings object
741 $databaseDir = Config::GetSetting($db, "LIBRARY_LOCATION");741 $databaseDir = Config::GetSetting($db, "LIBRARY_LOCATION");
742 742
743 //Now we need to move the file743 //Now we need to move the file
744 if (!$result = rename($databaseDir."/temp/".$tmpName, $databaseDir.$storedAs))744 if (!$result = rename($databaseDir."/temp/".$tmpName, $databaseDir.$storedAs))
745 {745 {
746 //If we couldnt move it - we need to delete the media record we just added746 //If we couldnt move it - we need to delete the media record we just added
747 $SQL = "DELETE FROM media WHERE mediaID = $new_mediaid ";747 $SQL = "DELETE FROM media WHERE mediaID = $new_mediaid ";
748 748
749 if (!$db->insert_query($SQL))749 if (!$db->insert_query($SQL))
750 {750 {
751 $this->response->SetError('Error rolling back transcation.');751 $this->response->SetError('Error rolling back transcation.');
@@ -753,7 +753,7 @@
753 return $this->response;753 return $this->response;
754 }754 }
755 }755 }
756 756
757 //Update the media record to include this information757 //Update the media record to include this information
758 $SQL = "UPDATE media SET storedAs = '$storedAs' WHERE mediaid = $new_mediaid";758 $SQL = "UPDATE media SET storedAs = '$storedAs' WHERE mediaid = $new_mediaid";
759 if (!$db->query($SQL))759 if (!$db->query($SQL))
@@ -763,13 +763,13 @@
763 $this->response->keepOpen = true;763 $this->response->keepOpen = true;
764 return $this->response;764 return $this->response;
765 }765 }
766 766
767 // Update the existing record with the new record's id767 // Update the existing record with the new record's id
768 $SQL = "UPDATE media SET isEdited = 1, editedMediaID = $new_mediaid ";768 $SQL = "UPDATE media SET isEdited = 1, editedMediaID = $new_mediaid ";
769 $SQL .= " WHERE IFNULL(editedMediaID,0) <> $new_mediaid AND mediaID = $mediaid ";769 $SQL .= " WHERE IFNULL(editedMediaID,0) <> $new_mediaid AND mediaID = $mediaid ";
770 770
771 Debug::LogEntry($db, 'audit', $SQL);771 Debug::LogEntry($db, 'audit', $SQL);
772 772
773 if (!$db->query($SQL))773 if (!$db->query($SQL))
774 {774 {
775 trigger_error($db->error());775 trigger_error($db->error());
@@ -783,54 +783,54 @@
783 {783 {
784 // Editing the existing record784 // Editing the existing record
785 $new_mediaid = $mediaid;785 $new_mediaid = $mediaid;
786 786
787 $SQL = "UPDATE media SET name = '%s', duration = %d, permissionID = %d";787 $SQL = "UPDATE media SET name = '%s', duration = %d, permissionID = %d";
788 $SQL .= " WHERE mediaID = %d ";788 $SQL .= " WHERE mediaID = %d ";
789 $SQL = sprintf($SQL, $db->escape_string($name), $duration, $permissionid, $mediaid);789 $SQL = sprintf($SQL, $db->escape_string($name), $duration, $permissionid, $mediaid);
790 790
791 Debug::LogEntry($db, 'audit', $SQL);791 Debug::LogEntry($db, 'audit', $SQL);
792 792
793 if (!$db->query($SQL))793 if (!$db->query($SQL))
794 {794 {
795 trigger_error($db->error());795 trigger_error($db->error());
796 796
797 $this->response->SetError('Database error editing this media record.');797 $this->response->SetError('Database error editing this media record.');
798 $this->response->keepOpen = true;798 $this->response->keepOpen = true;
799 return $this->response;799 return $this->response;
800 }800 }
801 }801 }
802 802
803 // Required Attributes803 // Required Attributes
804 $this->mediaid = $new_mediaid;804 $this->mediaid = $new_mediaid;
805 $this->duration = $duration;805 $this->duration = $duration;
806 806
807 // Any Options807 // Any Options
808 $this->SetOption('uri', $storedAs);808 $this->SetOption('uri', $storedAs);
809 809
810 // Should have built the media object entirely by this time810 // Should have built the media object entirely by this time
811 if ($regionid != '')811 if ($regionid != '')
812 {812 {
813 // This saves the Media Object to the Region813 // This saves the Media Object to the Region
814 $this->UpdateRegion();814 $this->UpdateRegion();
815 815
816 $this->response->loadForm = true;816 $this->response->loadForm = true;
817 $this->response->loadFormUri = "index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions";;817 $this->response->loadFormUri = "index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions";;
818 }818 }
819 else819 else
820 {820 {
821 $this->response->loadFormUri = "index.php?p=content&q=displayForms&sp=add"; 821 $this->response->loadFormUri = "index.php?p=content&q=displayForms&sp=add";
822 $this->response->message = 'Edited the Powerpoint.';822 $this->response->message = 'Edited the Powerpoint.';
823 823
824 }824 }
825 825
826 return $this->response;826 return $this->response;
827 }827 }
828 828
829 /**829 /**
830 * Delete Media from the Database830 * Delete Media from the Database
831 * @return 831 * @return
832 */832 */
833 public function DeleteMedia() 833 public function DeleteMedia()
834 {834 {
835 $db =& $this->db;835 $db =& $this->db;
836 $layoutid = $this->layoutid;836 $layoutid = $this->layoutid;
@@ -838,10 +838,10 @@
838 $mediaid = $this->mediaid;838 $mediaid = $this->mediaid;
839 $userid = Kit::GetParam('userid', _SESSION, _INT);839 $userid = Kit::GetParam('userid', _SESSION, _INT);
840 $options = Kit::GetParam('options', _POST, _WORD);840 $options = Kit::GetParam('options', _POST, _WORD);
841 841
842 // Stored As from the XML842 // Stored As from the XML
843 $this->uri = $this->GetOption('uri');843 $this->uri = $this->GetOption('uri');
844 844
845 // Do we need to remove this from a layout?845 // Do we need to remove this from a layout?
846 if ($layoutid != '')846 if ($layoutid != '')
847 {847 {
@@ -853,72 +853,72 @@
853 // Set this message now in preparation853 // Set this message now in preparation
854 $this->response->message = 'Deleted the Media.';854 $this->response->message = 'Deleted the Media.';
855 }855 }
856 856
857 // If we are set to retire we retire857 // If we are set to retire we retire
858 if ($options == "retire")858 if ($options == "retire")
859 {859 {
860 //Update the media record to say it is retired860 //Update the media record to say it is retired
861 $SQL = "UPDATE media SET retired = 1 WHERE mediaid = $mediaid ";861 $SQL = "UPDATE media SET retired = 1 WHERE mediaid = $mediaid ";
862 862
863 if (!$db->query($SQL))863 if (!$db->query($SQL))
864 {864 {
865 trigger_error($db->error());865 trigger_error($db->error());
866 866
867 $this->response->SetError('Database error retiring this media record.');867 $this->response->SetError('Database error retiring this media record.');
868 $this->response->keepOpen = true;868 $this->response->keepOpen = true;
869 return $this->response;869 return $this->response;
870 }870 }
871 }871 }
872 872
873 //If we are set to delete, we delete873 //If we are set to delete, we delete
874 if ($options == "delete")874 if ($options == "delete")
875 {875 {
876 //Update the media record to say it is retired876 //Update the media record to say it is retired
877 $SQL = "DELETE FROM media WHERE mediaid = $mediaid ";877 $SQL = "DELETE FROM media WHERE mediaid = $mediaid ";
878 878
879 if (!$db->query($SQL))879 if (!$db->query($SQL))
880 {880 {
881 trigger_error($db->error());881 trigger_error($db->error());
882 882
883 $this->response->SetError('Database error deleting this media record.');883 $this->response->SetError('Database error deleting this media record.');
884 $this->response->keepOpen = true;884 $this->response->keepOpen = true;
885 return $this->response;885 return $this->response;
886 }886 }
887 887
888 $this->DeleteMediaFiles();888 $this->DeleteMediaFiles();
889 }889 }
890 890
891 return $this->response;891 return $this->response;
892 }892 }
893 893
894 /**894 /**
895 * Deletes the media files associated with this record895 * Deletes the media files associated with this record
896 * @return 896 * @return
897 */897 */
898 private function DeleteMediaFiles()898 private function DeleteMediaFiles()
899 {899 {
900 $db =& $this->db;900 $db =& $this->db;
901 901
902 //Library location902 //Library location
903 $databaseDir = Config::GetSetting($db, "LIBRARY_LOCATION");903 $databaseDir = Config::GetSetting($db, "LIBRARY_LOCATION");
904 904
905 //3 things to check for..905 //3 things to check for..
906 //the actual file, the thumbnail, the background906 //the actual file, the thumbnail, the background
907 if (file_exists($databaseDir.$this->uri))907 if (file_exists($databaseDir.$this->uri))
908 {908 {
909 unlink($databaseDir.$this->uri);909 unlink($databaseDir.$this->uri);
910 }910 }
911 911
912 if (file_exists($databaseDir."tn_".$this->uri))912 if (file_exists($databaseDir."tn_".$this->uri))
913 {913 {
914 unlink($databaseDir."tn_".$this->uri);914 unlink($databaseDir."tn_".$this->uri);
915 }915 }
916 916
917 if (file_exists($databaseDir."bg_".$this->uri))917 if (file_exists($databaseDir."bg_".$this->uri))
918 {918 {
919 unlink($databaseDir."bg_".$this->uri);919 unlink($databaseDir."bg_".$this->uri);
920 }920 }
921 921
922 return true;922 return true;
923 }923 }
924}924}
925925
=== modified file 'server/modules/video.module.php'
--- server/modules/video.module.php 2009-06-28 10:47:06 +0000
+++ server/modules/video.module.php 2009-10-01 21:40:25 +0000
@@ -8,7 +8,7 @@
8 * Xibo is free software: you can redistribute it and/or modify8 * Xibo is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Affero General Public License as published by9 * it under the terms of the GNU Affero General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or10 * the Free Software Foundation, either version 3 of the License, or
11 * any later version. 11 * any later version.
12 *12 *
13 * Xibo is distributed in the hope that it will be useful,13 * Xibo is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -17,31 +17,31 @@
17 *17 *
18 * You should have received a copy of the GNU Affero General Public License18 * You should have received a copy of the GNU Affero General Public License
19 * along with Xibo. If not, see <http://www.gnu.org/licenses/>.19 * along with Xibo. If not, see <http://www.gnu.org/licenses/>.
20 */ 20 */
21class video extends Module21class video extends Module
22{22{
23 // Custom Media information23 // Custom Media information
24 private $uri;24 private $uri;
25 private $maxFileSize;25 private $maxFileSize;
26 private $maxFileSizeBytes;26 private $maxFileSizeBytes;
27 27
28 public function __construct(database $db, user $user, $mediaid = '', $layoutid = '', $regionid = '')28 public function __construct(database $db, user $user, $mediaid = '', $layoutid = '', $regionid = '')
29 {29 {
30 // Must set the type of the class30 // Must set the type of the class
31 $this->type = 'video';31 $this->type = 'video';
32 32
33 // Get the max upload size from PHP33 // Get the max upload size from PHP
34 $this->maxFileSize = ini_get('upload_max_filesize');34 $this->maxFileSize = ini_get('upload_max_filesize');
35 $this->maxFileSizeBytes = convertBytes($this->maxFileSize);35 $this->maxFileSizeBytes = convertBytes($this->maxFileSize);
36 36
37 // Must call the parent class 37 // Must call the parent class
38 parent::__construct($db, $user, $mediaid, $layoutid, $regionid);38 parent::__construct($db, $user, $mediaid, $layoutid, $regionid);
39 }39 }
40 40
41 /**41 /**
42 * Sets the Layout and Region Information42 * Sets the Layout and Region Information
43 * it will then fill in any blanks it has about this media if it can43 * it will then fill in any blanks it has about this media if it can
44 * @return 44 * @return
45 * @param $layoutid Object45 * @param $layoutid Object
46 * @param $regionid Object46 * @param $regionid Object
47 * @param $mediaid Object47 * @param $mediaid Object
@@ -53,75 +53,75 @@
53 $this->regionid = $regionid;53 $this->regionid = $regionid;
54 $mediaid = $this->mediaid;54 $mediaid = $this->mediaid;
55 $this->existingMedia = false;55 $this->existingMedia = false;
56 56
57 if ($this->regionSpecific == 1) return;57 if ($this->regionSpecific == 1) return;
58 58
59 // Load what we know about this media into the object59 // Load what we know about this media into the object
60 $SQL = "SELECT name, type, duration, originalFilename, userID, permissionID, retired, storedAs, isEdited, editedMediaID FROM media WHERE mediaID = $mediaid ";60 $SQL = "SELECT name, type, duration, originalFilename, userID, permissionID, retired, storedAs, isEdited, editedMediaID FROM media WHERE mediaID = $mediaid ";
61 61
62 if (!$result = $db->query($SQL))62 if (!$result = $db->query($SQL))
63 {63 {
64 trigger_error($db->error()); //log the error64 trigger_error($db->error()); //log the error
65 return false;65 return false;
66 }66 }
67 67
68 if ($db->num_rows($result) != 1)68 if ($db->num_rows($result) != 1)
69 {69 {
70 trigger_error("More than one row for mediaId [$mediaid] How can this be?");70 trigger_error("More than one row for mediaId [$mediaid] How can this be?");
71 return false;71 return false;
72 }72 }
73 73
74 $row = $db->get_row($result);74 $row = $db->get_row($result);
75 $duration = $row[2];75 $duration = $row[2];
76 $storedAs = $row[7];76 $storedAs = $row[7];
77 77
78 // Required Attributes78 // Required Attributes
79 $this->duration = $duration;79 $this->duration = $duration;
80 80
81 // Any Options81 // Any Options
82 $this->SetOption('uri', $storedAs);82 $this->SetOption('uri', $storedAs);
83 83
84 return true;84 return true;
85 }85 }
86 86
87 /**87 /**
88 * Return the Add Form as HTML88 * Return the Add Form as HTML
89 * @return 89 * @return
90 */90 */
91 public function AddForm()91 public function AddForm()
92 {92 {
93 global $session;93 global $session;
94 $db =& $this->db;94 $db =& $this->db;
95 $user =& $this->user;95 $user =& $this->user;
96 96
97 // Would like to get the regions width / height 97 // Would like to get the regions width / height
98 $layoutid = $this->layoutid;98 $layoutid = $this->layoutid;
99 $regionid = $this->regionid;99 $regionid = $this->regionid;
100 100
101 // Set the Session / Security information101 // Set the Session / Security information
102 $sessionId = session_id();102 $sessionId = session_id();
103 $securityToken = CreateFormToken();103 $securityToken = CreateFormToken();
104 104
105 $session->setSecurityToken($securityToken);105 $session->setSecurityToken($securityToken);
106 106
107 //Get the default value for the shared list107 //Get the default value for the shared list
108 $default = Config::GetSetting($db,"defaultMedia");108 $default = Config::GetSetting($db,"defaultMedia");
109109
110 $permissionid = 0;110 $permissionid = 0;
111111
112 if($default=="private") 112 if($default=="private")
113 {113 {
114 $permissionid = 1;114 $permissionid = 1;
115 }115 }
116 116
117 //shared list117 //shared list
118 $shared_list = dropdownlist("SELECT permissionID, permission FROM permission", "permissionid", $permissionid);118 $shared_list = dropdownlist("SELECT permissionID, permission FROM permission", "permissionid", $permissionid);
119 119
120 //Save button is different depending on if we are on a region or not120 //Save button is different depending on if we are on a region or not
121 if ($regionid != "")121 if ($regionid != "")
122 {122 {
123 setSession('content','mediatype','video');123 setSession('content','mediatype','video');
124 124
125 $save_button = <<<END125 $save_button = <<<END
126 <input id="btnSave" type="submit" value="Save" disabled />126 <input id="btnSave" type="submit" value="Save" disabled />
127 <input class="XiboFormButton" id="btnCancel" type="button" title="Return to the Region Options" href="index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions" value="Cancel" />127 <input class="XiboFormButton" id="btnCancel" type="button" title="Return to the Region Options" href="index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions" value="Cancel" />
@@ -135,7 +135,7 @@
135 <input class="XiboFormButton" id="btnCancel" type="button" title="Close" href="index.php?p=content&q=displayForms&sp=add" value="Cancel" />135 <input class="XiboFormButton" id="btnCancel" type="button" title="Close" href="index.php?p=content&q=displayForms&sp=add" value="Cancel" />
136END;136END;
137 }137 }
138 138
139 $form = <<<FORM139 $form = <<<FORM
140 <div style="display:none"><iframe name="fileupload" width="1px" height="1px"></iframe></div>140 <div style="display:none"><iframe name="fileupload" width="1px" height="1px"></iframe></div>
141 <div>141 <div>
@@ -144,7 +144,7 @@
144 <input type="hidden" id="SecurityToken" value="$securityToken" />144 <input type="hidden" id="SecurityToken" value="$securityToken" />
145 <input type="hidden" name="MAX_FILE_SIZE" value="$this->maxFileSizeBytes" />145 <input type="hidden" name="MAX_FILE_SIZE" value="$this->maxFileSizeBytes" />
146 <table>146 <table>
147 <tr> 147 <tr>
148 <td><label for="file">Video File<span class="required">*</span></label></td>148 <td><label for="file">Video File<span class="required">*</span></label></td>
149 <td colspan="3">149 <td colspan="3">
150 <input type="file" name="media_file" onchange="fileFormSubmit();this.form.submit();" />150 <input type="file" name="media_file" onchange="fileFormSubmit();this.form.submit();" />
@@ -172,11 +172,11 @@
172 <td><label for="permissionid">Sharing<span class="required">*</span></label></td>172 <td><label for="permissionid">Sharing<span class="required">*</span></label></td>
173 <td>173 <td>
174 $shared_list174 $shared_list
175 </td> 175 </td>
176 </tr>176 </tr>
177 <tr>177 <tr>
178 <td></td>178 <td></td>
179 <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>179 <td>This form accepts: <span class="required">$this->validExtensionsText</span> files up to a maximum size of <span class="required">$this->maxFileSize</span>.</td>
180 </tr>180 </tr>
181 <tr>181 <tr>
182 <td></td>182 <td></td>
@@ -194,49 +194,49 @@
194194
195 return $this->response;195 return $this->response;
196 }196 }
197 197
198 /**198 /**
199 * Return the Edit Form as HTML199 * Return the Edit Form as HTML
200 * @return 200 * @return
201 */201 */
202 public function EditForm()202 public function EditForm()
203 {203 {
204 global $session;204 global $session;
205 $db =& $this->db;205 $db =& $this->db;
206 $user =& $this->user;206 $user =& $this->user;
207 207
208 // Would like to get the regions width / height 208 // Would like to get the regions width / height
209 $layoutid = $this->layoutid;209 $layoutid = $this->layoutid;
210 $regionid = $this->regionid;210 $regionid = $this->regionid;
211 $mediaid = $this->mediaid;211 $mediaid = $this->mediaid;
212 $lkid = $this->lkid;212 $lkid = $this->lkid;
213 $userid = Kit::GetParam('userid', _SESSION, _INT);213 $userid = Kit::GetParam('userid', _SESSION, _INT);
214 214
215 // Set the Session / Security information215 // Set the Session / Security information
216 $sessionId = session_id();216 $sessionId = session_id();
217 $securityToken = CreateFormToken();217 $securityToken = CreateFormToken();
218 218
219 $session->setSecurityToken($securityToken);219 $session->setSecurityToken($securityToken);
220 220
221 // Load what we know about this media into the object221 // Load what we know about this media into the object
222 $SQL = "SELECT name, originalFilename, userID, permissionID, retired, storedAs, isEdited, editedMediaID FROM media WHERE mediaID = $mediaid ";222 $SQL = "SELECT name, originalFilename, userID, permissionID, retired, storedAs, isEdited, editedMediaID FROM media WHERE mediaID = $mediaid ";
223 223
224 if (!$result = $db->query($SQL))224 if (!$result = $db->query($SQL))
225 {225 {
226 trigger_error($db->error()); //log the error226 trigger_error($db->error()); //log the error
227 227
228 $this->message = "Error querying for the Media information with media ID [$mediaid] ";228 $this->message = "Error querying for the Media information with media ID [$mediaid] ";
229 return false;229 return false;
230 }230 }
231 231
232 if ($db->num_rows($result) != 1)232 if ($db->num_rows($result) != 1)
233 {233 {
234 trigger_error("More than one row for mediaId [$mediaid] How can this be?");234 trigger_error("More than one row for mediaId [$mediaid] How can this be?");
235 235
236 $this->message = "Error querying for the Media information with media ID [$mediaid] ";236 $this->message = "Error querying for the Media information with media ID [$mediaid] ";
237 return false;237 return false;
238 }238 }
239 239
240 $row = $db->get_row($result);240 $row = $db->get_row($result);
241 $name = $row[0];241 $name = $row[0];
242 $originalFilename = $row[1];242 $originalFilename = $row[1];
@@ -246,23 +246,23 @@
246 $storedAs = $row[5];246 $storedAs = $row[5];
247 $isEdited = $row[6];247 $isEdited = $row[6];
248 $editedMediaID = $row[7];248 $editedMediaID = $row[7];
249 249
250 // derive the ext250 // derive the ext
251 $ext = strtolower(substr(strrchr($originalFilename, "."), 1));251 $ext = strtolower(substr(strrchr($originalFilename, "."), 1));
252 252
253 //Calc the permissions on it aswell253 //Calc the permissions on it aswell
254 list($see_permissions , $edit_permissions) = $user->eval_permission($userid, $permissionid);254 list($see_permissions , $edit_permissions) = $user->eval_permission($userid, $permissionid);
255 255
256 //shared list256 //shared list
257 $shared_list = dropdownlist("SELECT permissionID, permission FROM permission", "permissionid", $permissionid);257 $shared_list = dropdownlist("SELECT permissionID, permission FROM permission", "permissionid", $permissionid);
258 258
259 //Save button is different depending on if we are on a region or not259 //Save button is different depending on if we are on a region or not
260 if ($regionid != "")260 if ($regionid != "")
261 {261 {
262 setSession('content','mediatype','image');262 setSession('content','mediatype','image');
263 263
264 $extraNotes = '<em>Note: Uploading a new media item here will replace it on this layout only.</em>';264 $extraNotes = '<em>Note: Uploading a new media item here will replace it on this layout only.</em>';
265 265
266 $save_button = <<<END266 $save_button = <<<END
267 <input id="btnSave" type="submit" value="Save" />267 <input id="btnSave" type="submit" value="Save" />
268 <input class="XiboFormButton" id="btnCancel" type="button" title="Return to the Region Options" href="index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions" value="Cancel" />268 <input class="XiboFormButton" id="btnCancel" type="button" title="Return to the Region Options" href="index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions" value="Cancel" />
@@ -272,13 +272,13 @@
272 else272 else
273 {273 {
274 $extraNotes = '<em>Note: As you editing from the library uploading a new media item will not replace the old one from any layouts. To do this nagivate to the layout and edit the media from there.</em>';274 $extraNotes = '<em>Note: As you editing from the library uploading a new media item will not replace the old one from any layouts. To do this nagivate to the layout and edit the media from there.</em>';
275 275
276 $save_button = <<<END276 $save_button = <<<END
277 <input id="btnSave" type="submit" value="Save" />277 <input id="btnSave" type="submit" value="Save" />
278 <input id="btnCancel" type="button" title="Close" onclick="$('#div_dialog').dialog('close')" value="Cancel" />278 <input id="btnCancel" type="button" title="Close" onclick="$('#div_dialog').dialog('close')" value="Cancel" />
279END;279END;
280 }280 }
281 281
282 $form = <<<FORM282 $form = <<<FORM
283 <div style="display:none"><iframe name="fileupload" width="1px" height="1px"></iframe></div>283 <div style="display:none"><iframe name="fileupload" width="1px" height="1px"></iframe></div>
284 <div>284 <div>
@@ -287,7 +287,7 @@
287 <input type="hidden" id="SecurityToken" value="$securityToken" />287 <input type="hidden" id="SecurityToken" value="$securityToken" />
288 <input type="hidden" name="MAX_FILE_SIZE" value="$this->maxFileSizeBytes" />288 <input type="hidden" name="MAX_FILE_SIZE" value="$this->maxFileSizeBytes" />
289 <table>289 <table>
290 <tr> 290 <tr>
291 <td><label for="file">New Video File<span class="required">*</span></label></td>291 <td><label for="file">New Video File<span class="required">*</span></label></td>
292 <td colspan="3">292 <td colspan="3">
293 <input type="file" name="media_file" onchange="fileFormSubmit();this.form.submit();" />293 <input type="file" name="media_file" onchange="fileFormSubmit();this.form.submit();" />
@@ -319,11 +319,11 @@
319 <td><label for="permissionid">Sharing<span class="required">*</span></label></td>319 <td><label for="permissionid">Sharing<span class="required">*</span></label></td>
320 <td>320 <td>
321 $shared_list321 $shared_list
322 </td> 322 </td>
323 </tr>323 </tr>
324 <tr>324 <tr>
325 <td></td>325 <td></td>
326 <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>326 <td>This form accepts: <span class="required">$this->validExtensionsText</span> files up to a maximum size of <span class="required">$this->maxFileSize</span>.</td>
327 </tr>327 </tr>
328 <tr>328 <tr>
329 <td></td>329 <td></td>
@@ -343,50 +343,50 @@
343 $this->response->dialogWidth = '450px';343 $this->response->dialogWidth = '450px';
344 $this->response->dialogHeight = '280px';344 $this->response->dialogHeight = '280px';
345345
346 return $this->response; 346 return $this->response;
347 }347 }
348 348
349 /**349 /**
350 * Return the Delete Form as HTML350 * Return the Delete Form as HTML
351 * @return 351 * @return
352 */352 */
353 public function DeleteForm()353 public function DeleteForm()
354 {354 {
355 $db =& $this->db;355 $db =& $this->db;
356 $user =& $this->user;356 $user =& $this->user;
357 357
358 // Would like to get the regions width / height 358 // Would like to get the regions width / height
359 $layoutid = $this->layoutid;359 $layoutid = $this->layoutid;
360 $regionid = $this->regionid;360 $regionid = $this->regionid;
361 $mediaid = $this->mediaid;361 $mediaid = $this->mediaid;
362 $lkid = $this->lkid;362 $lkid = $this->lkid;
363 $userid = Kit::GetParam('userid', _SESSION, _INT);363 $userid = Kit::GetParam('userid', _SESSION, _INT);
364 364
365 $options = "";365 $options = "";
366 //Always have the abilty to unassign from the region366 //Always have the abilty to unassign from the region
367 $options .= "unassign|Unassign from this region only";367 $options .= "unassign|Unassign from this region only";
368 368
369 // Load what we know about this media into the object369 // Load what we know about this media into the object
370 $SQL = "SELECT name, type, duration, originalFilename, userID, permissionID, retired, storedAs, isEdited, editedMediaID FROM media WHERE mediaID = $mediaid ";370 $SQL = "SELECT name, type, duration, originalFilename, userID, permissionID, retired, storedAs, isEdited, editedMediaID FROM media WHERE mediaID = $mediaid ";
371 371
372 if (!$result = $db->query($SQL))372 if (!$result = $db->query($SQL))
373 {373 {
374 trigger_error($db->error()); //log the error374 trigger_error($db->error()); //log the error
375 375
376 $this->response->SetError('Error querying for the Media information with media ID [$mediaid]');376 $this->response->SetError('Error querying for the Media information with media ID [$mediaid]');
377 $this->response->keepOpen = true;377 $this->response->keepOpen = true;
378 return $this->response;378 return $this->response;
379 }379 }
380 380
381 if ($db->num_rows($result) != 1)381 if ($db->num_rows($result) != 1)
382 {382 {
383 trigger_error("More than one row for mediaId [$mediaid] How can this be?");383 trigger_error("More than one row for mediaId [$mediaid] How can this be?");
384 384
385 $this->response->SetError('Error querying for the Media information with media ID [$mediaid]');385 $this->response->SetError('Error querying for the Media information with media ID [$mediaid]');
386 $this->response->keepOpen = true;386 $this->response->keepOpen = true;
387 return $this->response;387 return $this->response;
388 }388 }
389 389
390 $row = $db->get_row($result);390 $row = $db->get_row($result);
391 $name = $row[0];391 $name = $row[0];
392 $duration = $row[2];392 $duration = $row[2];
@@ -397,18 +397,18 @@
397 $storedAs = $row[7];397 $storedAs = $row[7];
398 $isEdited = $row[8];398 $isEdited = $row[8];
399 $editedMediaID = $row[9];399 $editedMediaID = $row[9];
400 400
401 // derive the ext401 // derive the ext
402 $ext = strtolower(substr(strrchr($originalFilename, "."), 1));402 $ext = strtolower(substr(strrchr($originalFilename, "."), 1));
403 403
404 //Calc the permissions on it aswell404 //Calc the permissions on it aswell
405 list($see_permissions , $edit_permissions) = $user->eval_permission($userid, $permissionid);405 list($see_permissions , $edit_permissions) = $user->eval_permission($userid, $permissionid);
406 406
407 //Is this user allowed to edit this media?407 //Is this user allowed to edit this media?
408 if ($edit_permissions)408 if ($edit_permissions)
409 {409 {
410 $options .= ",retire|Unassign from this region and retire";410 $options .= ",retire|Unassign from this region and retire";
411 411
412 //Is this media retired?412 //Is this media retired?
413 if ($editedMediaID != "")413 if ($editedMediaID != "")
414 {414 {
@@ -418,7 +418,7 @@
418 {418 {
419 $revised = false;419 $revised = false;
420 }420 }
421 421
422 //Is this media being used anywhere else?422 //Is this media being used anywhere else?
423 if ($layoutid == "")423 if ($layoutid == "")
424 {424 {
@@ -429,8 +429,8 @@
429 {429 {
430 $SQL = "SELECT layoutID FROM lklayoutmedia WHERE mediaID = $mediaid AND layoutid <> $layoutid AND regionID <> '$regionid' ";430 $SQL = "SELECT layoutID FROM lklayoutmedia WHERE mediaID = $mediaid AND layoutid <> $layoutid AND regionID <> '$regionid' ";
431 }431 }
432 432
433 if (!$results = $db->query($SQL)) 433 if (!$results = $db->query($SQL))
434 {434 {
435 trigger_error($db->error());435 trigger_error($db->error());
436436
@@ -457,9 +457,9 @@
457 return $this->response;457 return $this->response;
458 }458 }
459 }459 }
460 460
461 $options = ltrim($options, ",");461 $options = ltrim($options, ",");
462 462
463 $deleteOptions = listcontent($options,"options");463 $deleteOptions = listcontent($options,"options");
464464
465 //we can delete465 //we can delete
@@ -474,19 +474,19 @@
474 <input id="btnCancel" type="button" title="No / Cancel" href="index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions" onclick="$('#div_dialog').dialog('close');return false; " value="No" />474 <input id="btnCancel" type="button" title="No / Cancel" href="index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions" onclick="$('#div_dialog').dialog('close');return false; " value="No" />
475 </form>475 </form>
476END;476END;
477 477
478 $this->response->html = $form;478 $this->response->html = $form;
479 $this->response->dialogTitle = 'Delete Video';479 $this->response->dialogTitle = 'Delete Video';
480 $this->response->dialogSize = true;480 $this->response->dialogSize = true;
481 $this->response->dialogWidth = '450px';481 $this->response->dialogWidth = '450px';
482 $this->response->dialogHeight = '280px';482 $this->response->dialogHeight = '280px';
483483
484 return $this->response; 484 return $this->response;
485 }485 }
486 486
487 /**487 /**
488 * Add Media to the Database488 * Add Media to the Database
489 * @return 489 * @return
490 */490 */
491 public function AddMedia()491 public function AddMedia()
492 {492 {
@@ -495,55 +495,55 @@
495 $regionid = $this->regionid;495 $regionid = $this->regionid;
496 $mediaid = $this->mediaid;496 $mediaid = $this->mediaid;
497 $userid = Kit::GetParam('userid', _SESSION, _INT);497 $userid = Kit::GetParam('userid', _SESSION, _INT);
498 498
499 // File data499 // File data
500 $tmpName = Kit::GetParam('hidFileID', _POST, _STRING);500 $tmpName = Kit::GetParam('hidFileID', _POST, _STRING);
501 501
502 if ($tmpName == '')502 if ($tmpName == '')
503 {503 {
504 $this->response->SetError('Cannot save Video details. <br/> You must have picked a file.');504 $this->response->SetError('Cannot save Video details. <br/> You must have picked a file.');
505 $this->response->keepOpen = true;505 $this->response->keepOpen = true;
506 return $this->response;506 return $this->response;
507 }507 }
508 508
509 // File name and extension (orignial name)509 // File name and extension (orignial name)
510 $fileName = Kit::GetParam('txtFileName', _POST, _STRING);510 $fileName = Kit::GetParam('txtFileName', _POST, _STRING);
511 $fileName = basename($fileName);511 $fileName = basename($fileName);
512 $ext = strtolower(substr(strrchr($fileName, "."), 1));512 $ext = strtolower(substr(strrchr($fileName, "."), 1));
513 513
514 // Other properties514 // Other properties
515 $name = Kit::GetParam('name', _POST, _STRING);515 $name = Kit::GetParam('name', _POST, _STRING);
516 $duration = Kit::GetParam('duration', _POST, _INT, 0);516 $duration = Kit::GetParam('duration', _POST, _INT, 0);
517 $permissionid = Kit::GetParam('permissionid', _POST, _INT, 1);517 $permissionid = Kit::GetParam('permissionid', _POST, _INT, 1);
518 518
519 if ($name == '') $name = Kit::ValidateParam($fileName, _FILENAME);519 if ($name == '') $name = Kit::ValidateParam($fileName, _FILENAME);
520 520
521 // Validation521 // Validation
522 if ($ext != "wmv" && $ext != "mpeg" && $ext != "mpg")522 if (!$this->IsValidExtension($ext))
523 {523 {
524 $this->response->SetError('Only Vidoes are accepted - wmv, mpeg, mpg [this is ' . $ext . ']');524 $this->response->SetError('Your file has an extension not supported by this Media Type.');
525 $this->response->keepOpen = true;525 $this->response->keepOpen = true;
526 return $this->response;526 return $this->response;
527 }527 }
528 528
529 // Make sure the name isnt too long529 // Make sure the name isnt too long
530 if (strlen($name) > 100) 530 if (strlen($name) > 100)
531 {531 {
532 $this->response->SetError('The name cannot be longer than 100 characters');532 $this->response->SetError('The name cannot be longer than 100 characters');
533 $this->response->keepOpen = true;533 $this->response->keepOpen = true;
534 return $this->response;534 return $this->response;
535 }535 }
536 536
537 // Ensure the name is not already in the database537 // Ensure the name is not already in the database
538 $SQL = sprintf("SELECT name FROM media WHERE name = '%s' AND userid = %d", $db->escape_string($name), $userid);538 $SQL = sprintf("SELECT name FROM media WHERE name = '%s' AND userid = %d", $db->escape_string($name), $userid);
539539
540 if(!$result = $db->query($SQL)) 540 if(!$result = $db->query($SQL))
541 {541 {
542 trigger_error($db->error());542 trigger_error($db->error());
543 $this->response->SetError('Error checking whether the media name is ok. Try choosing a different name.');543 $this->response->SetError('Error checking whether the media name is ok. Try choosing a different name.');
544 $this->response->keepOpen = true;544 $this->response->keepOpen = true;
545 return $this->response;545 return $this->response;
546 } 546 }
547547
548 if ($db->num_rows($result) != 0)548 if ($db->num_rows($result) != 0)
549 {549 {
@@ -551,11 +551,11 @@
551 $this->response->keepOpen = true;551 $this->response->keepOpen = true;
552 return $this->response;552 return $this->response;
553 }553 }
554 554
555 // All OK to insert this record555 // All OK to insert this record
556 $SQL = "INSERT INTO media (name, type, duration, originalFilename, permissionID, userID, retired ) ";556 $SQL = "INSERT INTO media (name, type, duration, originalFilename, permissionID, userID, retired ) ";
557 $SQL .= "VALUES ('%s', 'video', '%s', '%s', %d, %d, 0) ";557 $SQL .= "VALUES ('%s', 'video', '%s', '%s', %d, %d, 0) ";
558 558
559 $SQL = sprintf($SQL, $db->escape_string($name), $db->escape_string($duration), $db->escape_string($fileName), $permissionid, $userid);559 $SQL = sprintf($SQL, $db->escape_string($name), $db->escape_string($duration), $db->escape_string($fileName), $permissionid, $userid);
560560
561 if (!$mediaid = $db->insert_query($SQL))561 if (!$mediaid = $db->insert_query($SQL))
@@ -565,19 +565,19 @@
565 $this->response->keepOpen = true;565 $this->response->keepOpen = true;
566 return $this->response;566 return $this->response;
567 }567 }
568 568
569 // File upload directory.. get this from the settings object569 // File upload directory.. get this from the settings object
570 $databaseDir = Config::GetSetting($db, "LIBRARY_LOCATION");570 $databaseDir = Config::GetSetting($db, "LIBRARY_LOCATION");
571 571
572 // What are we going to store this media as...572 // What are we going to store this media as...
573 $storedAs = $mediaid.".".$ext;573 $storedAs = $mediaid.".".$ext;
574 574
575 // Now we need to move the file575 // Now we need to move the file
576 if (!$result = rename($databaseDir."temp/".$tmpName, $databaseDir.$storedAs))576 if (!$result = rename($databaseDir."temp/".$tmpName, $databaseDir.$storedAs))
577 {577 {
578 // If we couldnt move it - we need to delete the media record we just added578 // If we couldnt move it - we need to delete the media record we just added
579 $SQL = sprintf("DELETE FROM media WHERE mediaID = %d ", $mediaid);579 $SQL = sprintf("DELETE FROM media WHERE mediaID = %d ", $mediaid);
580 580
581 if (!$db->query($SQL))581 if (!$db->query($SQL))
582 {582 {
583 trigger_error($db->error());583 trigger_error($db->error());
@@ -586,23 +586,23 @@
586 return $this->response;586 return $this->response;
587 }587 }
588 }588 }
589 589
590 // Update the media record to include this information590 // Update the media record to include this information
591 $SQL = sprintf("UPDATE media SET storedAs = '%s' WHERE mediaid = %d", $storedAs, $mediaid);591 $SQL = sprintf("UPDATE media SET storedAs = '%s' WHERE mediaid = %d", $storedAs, $mediaid);
592 592
593 if (!$db->query($SQL))593 if (!$db->query($SQL))
594 {594 {
595 trigger_error($db->error());595 trigger_error($db->error());
596 return true;596 return true;
597 }597 }
598 598
599 // Required Attributes599 // Required Attributes
600 $this->mediaid = $mediaid;600 $this->mediaid = $mediaid;
601 $this->duration = $duration;601 $this->duration = $duration;
602 602
603 // Any Options603 // Any Options
604 $this->SetOption('uri', $storedAs);604 $this->SetOption('uri', $storedAs);
605 605
606 // Should have built the media object entirely by this time606 // Should have built the media object entirely by this time
607 if ($regionid != '')607 if ($regionid != '')
608 {608 {
@@ -612,18 +612,18 @@
612 }612 }
613 else613 else
614 {614 {
615 $this->response->loadFormUri = "index.php?p=content&q=displayForms&sp=add"; 615 $this->response->loadFormUri = "index.php?p=content&q=displayForms&sp=add";
616 }616 }
617 617
618 // We want to load a new form618 // We want to load a new form
619 $this->response->loadForm = true;619 $this->response->loadForm = true;
620 620
621 return $this->response;621 return $this->response;
622 }622 }
623 623
624 /**624 /**
625 * Edit Media in the Database625 * Edit Media in the Database
626 * @return 626 * @return
627 */627 */
628 public function EditMedia()628 public function EditMedia()
629 {629 {
@@ -632,13 +632,13 @@
632 $regionid = $this->regionid;632 $regionid = $this->regionid;
633 $mediaid = $this->mediaid;633 $mediaid = $this->mediaid;
634 $userid = Kit::GetParam('userid', _SESSION, _INT);634 $userid = Kit::GetParam('userid', _SESSION, _INT);
635 635
636 // Stored As from the XML636 // Stored As from the XML
637 $storedAs = $this->GetOption('uri');637 $storedAs = $this->GetOption('uri');
638 638
639 // File data639 // File data
640 $tmpName = Kit::GetParam('hidFileID', _POST, _STRING);640 $tmpName = Kit::GetParam('hidFileID', _POST, _STRING);
641 641
642 if ($tmpName == '')642 if ($tmpName == '')
643 {643 {
644 $fileRevision = false;644 $fileRevision = false;
@@ -646,31 +646,31 @@
646 else646 else
647 {647 {
648 $fileRevision = true;648 $fileRevision = true;
649 649
650 // File name and extension (orignial name)650 // File name and extension (orignial name)
651 $fileName = Kit::GetParam('txtFileName', _POST, _STRING);651 $fileName = Kit::GetParam('txtFileName', _POST, _STRING);
652 $fileName = basename($fileName);652 $fileName = basename($fileName);
653 $ext = strtolower(substr(strrchr($fileName, "."), 1));653 $ext = strtolower(substr(strrchr($fileName, "."), 1));
654 654
655 // Validation655 // Validation
656 if ($ext != "wmv" && $ext != "mpeg" && $ext != "mpg")656 if (!$this->IsValidExtension($ext))
657 {657 {
658 $this->response->SetError('Only Vidoes are accepted - wmv, mpeg, mpg [this is ' . $ext . ']');658 $this->response->SetError('Your file has an extension not supported by this Media Type.');
659 $this->response->keepOpen = true;659 $this->response->keepOpen = true;
660 return $this->response;660 return $this->response;
661 }661 }
662 }662 }
663 663
664 // Other properties664 // Other properties
665 $name = Kit::GetParam('name', _POST, _STRING);665 $name = Kit::GetParam('name', _POST, _STRING);
666 $duration = Kit::GetParam('duration', _POST, _INT, 0);666 $duration = Kit::GetParam('duration', _POST, _INT, 0);
667 $permissionid = Kit::GetParam('permissionid', _POST, _INT, 1);667 $permissionid = Kit::GetParam('permissionid', _POST, _INT, 1);
668 668
669 if ($name == '')669 if ($name == '')
670 {670 {
671 if ($fileRevision)671 if ($fileRevision)
672 {672 {
673 $name = Kit::ValidateParam($fileName, _FILENAME); 673 $name = Kit::ValidateParam($fileName, _FILENAME);
674 }674 }
675 else675 else
676 {676 {
@@ -678,26 +678,26 @@
678 $this->response->keepOpen = true;678 $this->response->keepOpen = true;
679 return $this->response;679 return $this->response;
680 }680 }
681 } 681 }
682 682
683 // Make sure the name isnt too long683 // Make sure the name isnt too long
684 if (strlen($name) > 100) 684 if (strlen($name) > 100)
685 {685 {
686 $this->response->SetError('The name cannot be longer than 100 characters');686 $this->response->SetError('The name cannot be longer than 100 characters');
687 $this->response->keepOpen = true;687 $this->response->keepOpen = true;
688 return $this->response;688 return $this->response;
689 }689 }
690 690
691 // Ensure the name is not already in the database691 // Ensure the name is not already in the database
692 $SQL = sprintf("SELECT name FROM media WHERE name = '%s' AND userid = %d AND mediaid <> %d ", $db->escape_string($name), $userid, $mediaid);692 $SQL = sprintf("SELECT name FROM media WHERE name = '%s' AND userid = %d AND mediaid <> %d ", $db->escape_string($name), $userid, $mediaid);
693693
694 if(!$result = $db->query($SQL)) 694 if(!$result = $db->query($SQL))
695 {695 {
696 trigger_error($db->error());696 trigger_error($db->error());
697 $this->response->SetError('Error checking whether the media name is ok. Try choosing a different name.');697 $this->response->SetError('Error checking whether the media name is ok. Try choosing a different name.');
698 $this->response->keepOpen = true;698 $this->response->keepOpen = true;
699 return $this->response;699 return $this->response;
700 } 700 }
701701
702 if ($db->num_rows($result) != 0)702 if ($db->num_rows($result) != 0)
703 {703 {
@@ -705,34 +705,34 @@
705 $this->response->keepOpen = true;705 $this->response->keepOpen = true;
706 return $this->response;706 return $this->response;
707 }707 }
708 708
709 //Are we revising this media - or just plain editing709 //Are we revising this media - or just plain editing
710 if ($fileRevision)710 if ($fileRevision)
711 {711 {
712 // All OK to insert this record712 // All OK to insert this record
713 $SQL = "INSERT INTO media (name, type, duration, originalFilename, permissionID, userID, retired ) ";713 $SQL = "INSERT INTO media (name, type, duration, originalFilename, permissionID, userID, retired ) ";
714 $SQL .= "VALUES ('%s', '%s', '%s', '%s', %d, %d, 0) ";714 $SQL .= "VALUES ('%s', '%s', '%s', '%s', %d, %d, 0) ";
715 715
716 $SQL = sprintf($SQL, $db->escape_string($name), $this->type, $db->escape_string($duration), $db->escape_string($fileName), $permissionid, $userid);716 $SQL = sprintf($SQL, $db->escape_string($name), $this->type, $db->escape_string($duration), $db->escape_string($fileName), $permissionid, $userid);
717 717
718 if (!$new_mediaid = $db->insert_query($SQL))718 if (!$new_mediaid = $db->insert_query($SQL))
719 {719 {
720 trigger_error($db->error());720 trigger_error($db->error());
721 trigger_error('Error inserting replacement media record.', E_USER_ERROR);721 trigger_error('Error inserting replacement media record.', E_USER_ERROR);
722 }722 }
723 723
724 //What are we going to store this media as...724 //What are we going to store this media as...
725 $storedAs = $new_mediaid.".".$ext;725 $storedAs = $new_mediaid.".".$ext;
726 726
727 // File upload directory.. get this from the settings object727 // File upload directory.. get this from the settings object
728 $databaseDir = Config::GetSetting($db, "LIBRARY_LOCATION");728 $databaseDir = Config::GetSetting($db, "LIBRARY_LOCATION");
729 729
730 //Now we need to move the file730 //Now we need to move the file
731 if (!$result = rename($databaseDir."/temp/".$tmpName, $databaseDir.$storedAs))731 if (!$result = rename($databaseDir."/temp/".$tmpName, $databaseDir.$storedAs))
732 {732 {
733 //If we couldnt move it - we need to delete the media record we just added733 //If we couldnt move it - we need to delete the media record we just added
734 $SQL = "DELETE FROM media WHERE mediaID = $new_mediaid ";734 $SQL = "DELETE FROM media WHERE mediaID = $new_mediaid ";
735 735
736 if (!$db->insert_query($SQL))736 if (!$db->insert_query($SQL))
737 {737 {
738 $this->response->SetError('Error rolling back transcation.');738 $this->response->SetError('Error rolling back transcation.');
@@ -740,7 +740,7 @@
740 return $this->response;740 return $this->response;
741 }741 }
742 }742 }
743 743
744 // Update the media record to include this information744 // Update the media record to include this information
745 $SQL = "UPDATE media SET storedAs = '$storedAs' WHERE mediaid = $new_mediaid";745 $SQL = "UPDATE media SET storedAs = '$storedAs' WHERE mediaid = $new_mediaid";
746 if (!$db->query($SQL))746 if (!$db->query($SQL))
@@ -750,13 +750,13 @@
750 $this->response->keepOpen = true;750 $this->response->keepOpen = true;
751 return $this->response;751 return $this->response;
752 }752 }
753 753
754 // Update the existing record with the new record's id754 // Update the existing record with the new record's id
755 $SQL = "UPDATE media SET isEdited = 1, editedMediaID = $new_mediaid ";755 $SQL = "UPDATE media SET isEdited = 1, editedMediaID = $new_mediaid ";
756 $SQL .= " WHERE IFNULL(editedMediaID,0) <> $new_mediaid AND mediaID = $mediaid ";756 $SQL .= " WHERE IFNULL(editedMediaID,0) <> $new_mediaid AND mediaID = $mediaid ";
757 757
758 Debug::LogEntry($db, 'audit', $SQL);758 Debug::LogEntry($db, 'audit', $SQL);
759 759
760 if (!$db->query($SQL))760 if (!$db->query($SQL))
761 {761 {
762 trigger_error($db->error());762 trigger_error($db->error());
@@ -770,54 +770,54 @@
770 {770 {
771 // Editing the existing record771 // Editing the existing record
772 $new_mediaid = $mediaid;772 $new_mediaid = $mediaid;
773 773
774 $SQL = "UPDATE media SET name = '%s', duration = %d, permissionID = %d";774 $SQL = "UPDATE media SET name = '%s', duration = %d, permissionID = %d";
775 $SQL .= " WHERE mediaID = %d ";775 $SQL .= " WHERE mediaID = %d ";
776 $SQL = sprintf($SQL, $db->escape_string($name), $duration, $permissionid, $mediaid);776 $SQL = sprintf($SQL, $db->escape_string($name), $duration, $permissionid, $mediaid);
777 777
778 Debug::LogEntry($db, 'audit', $SQL);778 Debug::LogEntry($db, 'audit', $SQL);
779 779
780 if (!$db->query($SQL))780 if (!$db->query($SQL))
781 {781 {
782 trigger_error($db->error());782 trigger_error($db->error());
783 783
784 $this->response->SetError('Database error editing this media record.');784 $this->response->SetError('Database error editing this media record.');
785 $this->response->keepOpen = true;785 $this->response->keepOpen = true;
786 return $this->response;786 return $this->response;
787 }787 }
788 }788 }
789 789
790 // Required Attributes790 // Required Attributes
791 $this->mediaid = $new_mediaid;791 $this->mediaid = $new_mediaid;
792 $this->duration = $duration;792 $this->duration = $duration;
793 793
794 // Any Options794 // Any Options
795 $this->SetOption('uri', $storedAs);795 $this->SetOption('uri', $storedAs);
796 796
797 // Should have built the media object entirely by this time797 // Should have built the media object entirely by this time
798 if ($regionid != '')798 if ($regionid != '')
799 {799 {
800 // This saves the Media Object to the Region800 // This saves the Media Object to the Region
801 $this->UpdateRegion();801 $this->UpdateRegion();
802 802
803 $this->response->loadForm = true;803 $this->response->loadForm = true;
804 $this->response->loadFormUri = "index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions";;804 $this->response->loadFormUri = "index.php?p=layout&layoutid=$layoutid&regionid=$regionid&q=RegionOptions";;
805 }805 }
806 else806 else
807 {807 {
808 $this->response->loadFormUri = "index.php?p=content&q=displayForms&sp=add"; 808 $this->response->loadFormUri = "index.php?p=content&q=displayForms&sp=add";
809 $this->response->message = 'Edited the Video.';809 $this->response->message = 'Edited the Video.';
810 810
811 }811 }
812 812
813 return $this->response;813 return $this->response;
814 }814 }
815 815
816 /**816 /**
817 * Delete Media from the Database817 * Delete Media from the Database
818 * @return 818 * @return
819 */819 */
820 public function DeleteMedia() 820 public function DeleteMedia()
821 {821 {
822 $db =& $this->db;822 $db =& $this->db;
823 $layoutid = $this->layoutid;823 $layoutid = $this->layoutid;
@@ -825,10 +825,10 @@
825 $mediaid = $this->mediaid;825 $mediaid = $this->mediaid;
826 $userid = Kit::GetParam('userid', _SESSION, _INT);826 $userid = Kit::GetParam('userid', _SESSION, _INT);
827 $options = Kit::GetParam('options', _POST, _WORD);827 $options = Kit::GetParam('options', _POST, _WORD);
828 828
829 // Stored As from the XML829 // Stored As from the XML
830 $this->uri = $this->GetOption('uri');830 $this->uri = $this->GetOption('uri');
831 831
832 // Do we need to remove this from a layout?832 // Do we need to remove this from a layout?
833 if ($layoutid != '')833 if ($layoutid != '')
834 {834 {
@@ -840,72 +840,72 @@
840 // Set this message now in preparation840 // Set this message now in preparation
841 $this->response->message = 'Deleted the Media.';841 $this->response->message = 'Deleted the Media.';
842 }842 }
843 843
844 // If we are set to retire we retire844 // If we are set to retire we retire
845 if ($options == "retire")845 if ($options == "retire")
846 {846 {
847 //Update the media record to say it is retired847 //Update the media record to say it is retired
848 $SQL = "UPDATE media SET retired = 1 WHERE mediaid = $mediaid ";848 $SQL = "UPDATE media SET retired = 1 WHERE mediaid = $mediaid ";
849 849
850 if (!$db->query($SQL))850 if (!$db->query($SQL))
851 {851 {
852 trigger_error($db->error());852 trigger_error($db->error());
853 853
854 $this->response->SetError('Database error retiring this media record.');854 $this->response->SetError('Database error retiring this media record.');
855 $this->response->keepOpen = true;855 $this->response->keepOpen = true;
856 return $this->response;856 return $this->response;
857 }857 }
858 }858 }
859 859
860 //If we are set to delete, we delete860 //If we are set to delete, we delete
861 if ($options == "delete")861 if ($options == "delete")
862 {862 {
863 //Update the media record to say it is retired863 //Update the media record to say it is retired
864 $SQL = "DELETE FROM media WHERE mediaid = $mediaid ";864 $SQL = "DELETE FROM media WHERE mediaid = $mediaid ";
865 865
866 if (!$db->query($SQL))866 if (!$db->query($SQL))
867 {867 {
868 trigger_error($db->error());868 trigger_error($db->error());
869 869
870 $this->response->SetError('Database error deleting this media record.');870 $this->response->SetError('Database error deleting this media record.');
871 $this->response->keepOpen = true;871 $this->response->keepOpen = true;
872 return $this->response;872 return $this->response;
873 }873 }
874 874
875 $this->DeleteMediaFiles();875 $this->DeleteMediaFiles();
876 }876 }
877 877
878 return $this->response;878 return $this->response;
879 }879 }
880 880
881 /**881 /**
882 * Deletes the media files associated with this record882 * Deletes the media files associated with this record
883 * @return 883 * @return
884 */884 */
885 private function DeleteMediaFiles()885 private function DeleteMediaFiles()
886 {886 {
887 $db =& $this->db;887 $db =& $this->db;
888 888
889 //Library location889 //Library location
890 $databaseDir = Config::GetSetting($db, "LIBRARY_LOCATION");890 $databaseDir = Config::GetSetting($db, "LIBRARY_LOCATION");
891 891
892 //3 things to check for..892 //3 things to check for..
893 //the actual file, the thumbnail, the background893 //the actual file, the thumbnail, the background
894 if (file_exists($databaseDir.$this->uri))894 if (file_exists($databaseDir.$this->uri))
895 {895 {
896 unlink($databaseDir.$this->uri);896 unlink($databaseDir.$this->uri);
897 }897 }
898 898
899 if (file_exists($databaseDir."tn_".$this->uri))899 if (file_exists($databaseDir."tn_".$this->uri))
900 {900 {
901 unlink($databaseDir."tn_".$this->uri);901 unlink($databaseDir."tn_".$this->uri);
902 }902 }
903 903
904 if (file_exists($databaseDir."bg_".$this->uri))904 if (file_exists($databaseDir."bg_".$this->uri))
905 {905 {
906 unlink($databaseDir."bg_".$this->uri);906 unlink($databaseDir."bg_".$this->uri);
907 }907 }
908 908
909 return true;909 return true;
910 }910 }
911}911}

Subscribers

People subscribed via source and target branches