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