Esempio n. 1
0
 protected function EditLibraryMedia()
 {
     $this->response = new ResponseManager();
     $db =& $this->db;
     $user =& $this->user;
     $layoutid = $this->layoutid;
     $regionid = $this->regionid;
     $mediaid = $this->mediaid;
     $userid = $this->user->userid;
     if (!$this->auth->edit) {
         $this->response->SetError('You do not have permission to edit this media.');
         $this->response->keepOpen = false;
         return $this->response;
     }
     // Hand off to the media module
     $mediaObject = new Media($db);
     // Stored As from the XML
     $storedAs = $this->GetOption('uri');
     // File data
     $tmpName = Kit::GetParam('hidFileID', _POST, _STRING);
     $name = Kit::GetParam('name', _POST, _STRING);
     $tags = Kit::GetParam('tags', _POST, _STRING);
     if ($this->auth->modifyPermissions) {
         $this->duration = Kit::GetParam('duration', _POST, _INT, 0, false);
     }
     // Revise this file?
     if ($tmpName != '') {
         Debug::LogEntry('audit', 'Uploading a new revision', 'module', 'EditLibraryMedia');
         // File name and extension (orignial name)
         $fileName = Kit::GetParam('txtFileName', _POST, _STRING);
         if ($name == '') {
             $name = $fileName;
         }
         if (!($new_mediaid = $mediaObject->FileRevise($mediaid, $tmpName, $fileName, $userid))) {
             $this->response->SetError($mediaObject->GetErrorMessage());
             $this->response->keepOpen = true;
             return $this->response;
         }
         // Are we on a region
         if ($regionid != '') {
             $security = new LayoutMediaGroupSecurity($db);
             $security->Copy($layoutid, $regionid, $mediaid, $new_mediaid);
         }
         // Required Attributes
         $this->mediaid = $new_mediaid;
         // Find out what we stored this item as
         try {
             $dbh = PDOConnect::init();
             $sth = $dbh->prepare('SELECT StoredAs FROM `media` WHERE mediaid = :mediaId');
             $sth->execute(array('mediaId' => $new_mediaid));
             $storedAs = Kit::ValidateParam($sth->fetchColumn(0), _FILENAME);
             $this->SetOption('uri', $storedAs);
         } catch (Exception $e) {
             Debug::LogEntry('error', $e->getMessage(), get_class(), __FUNCTION__);
             trigger_error(__('Unable to find uploaded file.'), E_USER_ERROR);
         }
         Debug::LogEntry('audit', 'New revision uploaded: ' . $storedAs, 'module', 'EditLibraryMedia');
     }
     // Edit the media record
     if (!$mediaObject->Edit($this->mediaid, $name, $this->duration, $userid, $tags)) {
         $this->response->SetError($mediaObject->GetErrorMessage());
         $this->response->keepOpen = true;
         return $this->response;
     }
     // Should have built the media object entirely by this time
     if ($regionid != '' && $this->showRegionOptions) {
         // This saves the Media Object to the Region
         $this->UpdateRegion();
         $this->response->loadForm = true;
         $this->response->loadFormUri = "index.php?p=timeline&layoutid={$layoutid}&regionid={$regionid}&q=RegionOptions";
     } elseif ($regionid != '' && !$this->showRegionOptions) {
         $this->UpdateRegion();
         $this->response->loadForm = false;
     } else {
         $this->response->message = 'Edited the ' . $this->displayType;
     }
     // Edit from the library - check to see if we are replacing this media in *all* layouts.
     $replaceInLayouts = Kit::GetParam('replaceInLayouts', _POST, _CHECKBOX) == 1;
     $replaceBackgroundImages = Kit::GetParam('replaceBackgroundImages', _POST, _CHECKBOX) == 1;
     if ($mediaid != $this->mediaid && ($replaceInLayouts || $replaceBackgroundImages)) {
         $this->ReplaceMediaInAllLayouts($replaceInLayouts, $replaceBackgroundImages, $mediaid, $this->mediaid, $this->duration);
     }
     // Do we need to delete the old media item?
     if ($tmpName != '' && Kit::GetParam('deleteOldVersion', _POST, _CHECKBOX) == 1) {
         // We pass in the newMediaId as the second parameter so that we can correctly link a prior revision if one exists.
         if (!$mediaObject->Delete($mediaid, $this->mediaid)) {
             $this->response->message .= ' ' . __('Failed to remove old media');
         }
     }
     return $this->response;
 }
Esempio n. 2
0
 /**
  * Lists enabled modules
  * @return <XiboAPIResponse>
  */
 public function ModuleList()
 {
     // Does this user have permission to call this webservice method?
     if (!$this->user->PageAuth('content')) {
         return $this->Error(1, 'Access Denied');
     }
     Kit::ClassLoader('Media');
     // Create a media object and gather the required parameters.
     $media = new Media();
     if (!($modules = $media->ModuleList())) {
         return $this->Error($media->GetErrorNumber(), $media->GetErrorMessage());
     }
     return $this->Respond($this->NodeListFromArray($modules, 'module'));
 }
Esempio n. 3
0
 /**
  * Tidies up the library
  */
 public function tidyLibrary()
 {
     $response = new ResponseManager();
     if (Config::GetSetting('SETTING_LIBRARY_TIDY_ENABLED') != 1) {
         trigger_error(__('Sorry this function is disabled.'), E_USER_ERROR);
     }
     $media = new Media();
     if (!$media->deleteUnusedForUser($this->user->userid)) {
         trigger_error($media->GetErrorMessage(), E_USER_ERROR);
     }
     $response->SetFormSubmitResponse(__('Library Tidy Complete'));
     $response->Respond();
 }
Esempio n. 4
0
 function Import($zipFile, $layout, $userId, $template, $replaceExisting, $importTags, $delete = true)
 {
     // I think I might add a layout and then import
     if (!file_exists($zipFile)) {
         return $this->SetError(__('File does not exist'));
     }
     // Open the Zip file
     $zip = new ZipArchive();
     if (!$zip->open($zipFile)) {
         return $this->SetError(__('Unable to open ZIP'));
     }
     try {
         $dbh = PDOConnect::init();
         $sth = $dbh->prepare('SELECT mediaid, storedAs FROM `media` WHERE name = :name AND IsEdited = 0');
         // Get the layout details
         $layoutDetails = json_decode($zip->getFromName('layout.json'), true);
         // Set the layout name
         $layout = $layout != '' ? $layout : $layoutDetails['layout'];
         $description = isset($layoutDetails['description']) ? $layoutDetails['description'] : '';
         // Get the layout xml
         $xml = $zip->getFromName('layout.xml');
         // Add the layout
         if (!($layoutId = $this->Add($layout, $description, NULL, $userId, NULL, NULL, $xml))) {
             return false;
         }
         // Either remove out the tags, or add them to the DB
         if ($importTags) {
             // Pull the tags out of the XML
             $xmlDoc = new DOMDocument();
             $xmlDoc->loadXML($xml);
             $xpath = new DOMXPath($xmlDoc);
             $tagsNode = $xpath->query("//tags");
             foreach ($tagsNode as $tag) {
                 $this->tag($tag->nodeValue, $layoutId);
             }
         } else {
             $this->EditTags($layoutId, array());
         }
         // Are we a template?
         if ($template) {
             $this->tag('template', $layoutId);
         }
         // Tag as imported
         $this->tag('imported', $layoutId);
         // Set the DOM XML
         $this->SetDomXml($layoutId);
         // Set the user on each region
         foreach ($this->DomXml->getElementsByTagName('region') as $region) {
             $region->setAttribute('userId', $userId);
         }
         // Set the user on each media node
         foreach ($this->DomXml->getElementsByTagName('media') as $media) {
             $media->setAttribute('userId', $userId);
         }
         // We will need a file object and a media object
         $fileObject = new File();
         $mediaObject = new Media();
         $currentType = '';
         // Go through each region and add the media (updating the media ids)
         $mappings = json_decode($zip->getFromName('mapping.json'), true);
         foreach ($mappings as $file) {
             Debug::LogEntry('audit', 'Found file ' . json_encode($file));
             // Do we need to recharge our media object
             if ($currentType != '' && $file['type'] != $currentType) {
                 $mediaObject = new Media();
             }
             // Set the current type
             $currentType = $file['type'];
             // Does a media item with this name already exist?
             $sth->execute(array('name' => $file['name']));
             $rows = $sth->fetchAll();
             if (count($rows) > 0) {
                 if ($replaceExisting) {
                     // Alter the name of the file and add it
                     $file['name'] = 'import_' . $layout . '_' . uniqid();
                     // Add the file
                     if (!($fileId = $fileObject->NewFile($zip->getFromName('library/' . $file['file']), $userId))) {
                         return $this->SetError(__('Unable to add a media item'));
                     }
                     // Add this media to the library
                     if (!($mediaId = $mediaObject->Add($fileId, $file['type'], $file['name'], $file['duration'], $file['file'], $userId))) {
                         return $this->SetError($mediaObject->GetErrorMessage());
                     }
                     // Tag it
                     $mediaObject->tag('imported', $mediaId);
                 } else {
                     // Don't add the file, use the one that already exists
                     $mediaObject->mediaId = $rows[0]['mediaid'];
                     $mediaObject->storedAs = $rows[0]['storedAs'];
                 }
             } else {
                 // Add the file
                 if (!($fileId = $fileObject->NewFile($zip->getFromName('library/' . $file['file']), $userId))) {
                     return $this->SetError(__('Unable to add a media item'));
                 }
                 // Add this media to the library
                 if (!($mediaId = $mediaObject->Add($fileId, $file['type'], $file['name'], $file['duration'], $file['file'], $userId))) {
                     return $this->SetError($mediaObject->GetErrorMessage());
                 }
                 // Tag it
                 $mediaObject->tag('imported', $mediaId);
             }
             Debug::LogEntry('audit', 'Post File Import Fix', get_class(), __FUNCTION__);
             // Get this media node from the layout using the old media id
             if (!$this->PostImportFix($userId, $layoutId, $file['mediaid'], $mediaObject->mediaId, $mediaObject->storedAs, $file['background'])) {
                 return false;
             }
         }
         Debug::LogEntry('audit', 'Saving XLF', get_class(), __FUNCTION__);
         // Save the updated XLF
         if (!$this->SetLayoutXml($layoutId, $this->DomXml->saveXML())) {
             return false;
         }
         $this->SetValid($layoutId);
         // Finished, so delete
         $zip->close();
         if ($delete) {
             @unlink($zipFile);
         }
         return true;
     } catch (Exception $e) {
         Debug::LogEntry('error', $e->getMessage());
         if (!$this->IsError()) {
             $this->SetError(1, __('Unknown Error'));
         }
         return false;
     }
 }
Esempio n. 5
0
 protected function EditLibraryMedia()
 {
     $db =& $this->db;
     $user =& $this->user;
     $layoutid = $this->layoutid;
     $regionid = $this->regionid;
     $mediaid = $this->mediaid;
     $userid = $this->user->userid;
     if (!$this->auth->edit) {
         $this->response->SetError('You do not have permission to edit this media.');
         $this->response->keepOpen = false;
         return $this->response;
     }
     // Hand off to the media module
     Kit::ClassLoader('media');
     $mediaObject = new Media($db);
     // Stored As from the XML
     $storedAs = $this->GetOption('uri');
     // File data
     $tmpName = Kit::GetParam('hidFileID', _POST, _STRING);
     $name = Kit::GetParam('name', _POST, _STRING);
     if ($this->auth->modifyPermissions) {
         $this->duration = Kit::GetParam('duration', _POST, _INT, 0);
     }
     // Revise this file?
     if ($tmpName != '') {
         Debug::LogEntry('audit', 'Uploading a new revision', 'module', 'EditLibraryMedia');
         // File name and extension (orignial name)
         $fileName = Kit::GetParam('txtFileName', _POST, _STRING);
         if ($name == '') {
             $name = $fileName;
         }
         if (!($new_mediaid = $mediaObject->FileRevise($mediaid, $tmpName, $fileName))) {
             $this->response->SetError($mediaObject->GetErrorMessage());
             $this->response->keepOpen = true;
             return $this->response;
         }
         // Are we on a region
         if ($regionid != '') {
             Kit::ClassLoader('layoutmediagroupsecurity');
             $security = new LayoutMediaGroupSecurity($db);
             $security->Copy($layoutid, $regionid, $mediaid, $new_mediaid);
         }
         // Required Attributes
         $this->mediaid = $new_mediaid;
         // Find out what we stored this item as
         $storedAs = $db->GetSingleValue(sprintf("SELECT StoredAs FROM `media` WHERE mediaid = %d", $new_mediaid), 'StoredAs', _STRING);
         $this->SetOption('uri', $storedAs);
         Debug::LogEntry('audit', 'New revision uploaded: ' . $storedAs, 'module', 'EditLibraryMedia');
     }
     // Edit the media record
     if (!$mediaObject->Edit($this->mediaid, $name, $this->duration, $userid)) {
         $this->response->SetError($mediaObject->GetErrorMessage());
         $this->response->keepOpen = true;
         return $this->response;
     }
     // Should have built the media object entirely by this time
     if ($regionid != '' && $this->showRegionOptions) {
         // This saves the Media Object to the Region
         $this->UpdateRegion();
         $this->response->loadForm = true;
         $this->response->loadFormUri = "index.php?p=timeline&layoutid={$layoutid}&regionid={$regionid}&q=RegionOptions";
     } elseif ($regionid != '' && !$this->showRegionOptions) {
         $this->UpdateRegion();
         $this->response->loadForm = false;
     } else {
         $this->response->message = 'Edited the ' . $this->displayType;
     }
     // Edit from the library - check to see if we are replacing this media in *all* layouts.
     if (Kit::GetParam('replaceInLayouts', _POST, _CHECKBOX) == 1) {
         $this->ReplaceMediaInAllLayouts($mediaid, $this->mediaid, $this->duration);
     }
     return $this->response;
 }
Esempio n. 6
0
 /**
  * Delete User
  * @return bool
  */
 public function Delete()
 {
     if (!isset($this->userId) || $this->userId == 0) {
         return $this->SetError(__('Missing userId'));
     }
     try {
         $dbh = PDOConnect::init();
         // Delete all layouts
         $layout = new Layout();
         if (!$layout->deleteAllForUser($this->userId)) {
             return $this->SetError($layout->GetErrorMessage());
         }
         // Delete all Campaigns
         $campaign = new Campaign();
         if (!$campaign->deleteAllForUser($this->userId)) {
             return $this->SetError($campaign->GetErrorMessage());
         }
         // Delete all media
         $media = new Media();
         if (!$media->deleteAllForUser($this->userId)) {
             return $this->SetError($media->GetErrorMessage());
         }
         // Delete all schedules that have not been caught by deleting layouts and campaigns
         // These would be schedules for other peoples layouts
         $schedule = new Schedule();
         if (!$schedule->deleteAllForUser($this->userId)) {
         }
         // Delete the user itself
         $sth = $dbh->prepare('DELETE FROM `user` WHERE userid = :userid');
         $sth->execute(array('userid' => $this->userId));
         // Delete from the session table
         $sth = $dbh->prepare('DELETE FROM `session` WHERE userid = :userid');
         $sth->execute(array('userid' => $this->userId));
         return true;
     } catch (Exception $e) {
         Debug::LogEntry('error', $e->getMessage(), get_class(), __FUNCTION__);
         if (!$this->IsError()) {
             $this->SetError(1, __('Unknown Error'));
         }
         return false;
     }
 }