Merge lp:~dangarner/xibo/store-media-md5 into lp:~xibo-maintainers/xibo/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
Reviewer Review Type Date Requested Status
Xibo Maintainters Pending
Review via email: mp+12623@code.launchpad.net
To post a comment you must log in.

Preview Diff

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

Subscribers

People subscribed via source and target branches