Exemple #1
0
 function launch()
 {
     global $interface;
     global $configArray;
     $isNew = true;
     if (isset($_REQUEST['id']) && strlen($_REQUEST['id']) > 0) {
         $editorialReview = new EditorialReview();
         $editorialReview->editorialReviewId = $_REQUEST['id'];
         $editorialReview->find();
         if ($editorialReview->N > 0) {
             $editorialReview->fetch();
             $interface->assign('object', $editorialReview);
             $interface->setPageTitle('Edit Editorial Review');
             $isNew = false;
         }
     }
     $structure = EditorialReview::getObjectStructure();
     if ($isNew) {
         if (isset($_REQUEST['recordId'])) {
             $structure['recordId']['default'] = strip_tags($_REQUEST['recordId']);
         }
     }
     if (isset($_REQUEST['submit']) || isset($_REQUEST['submitStay']) || isset($_REQUEST['submitReturnToList']) || isset($_REQUEST['submitAddAnother'])) {
         //Save the object
         $results = DataObjectUtil::saveObject($structure, 'EditorialReview');
         $editorialReview = $results['object'];
         //redirect to the view of the competency if we saved ok.
         if (!$results['validatedOk'] || !$results['saveOk']) {
             //Display the errors for the user.
             $interface->assign('errors', $results['errors']);
             $interface->assign('object', $editorialReview);
             $_REQUEST['id'] = $editorialReview->editorialReviewId;
         } else {
             //Show the new tip that was created
             if (isset($_REQUEST['submitReturnToList'])) {
                 if (strpos($editorialReview->recordId, 'econtentRecord') === 0) {
                     $shortId = str_replace('econtentRecord', '', $editorialReview->recordId);
                     header('Location:' . $configArray['Site']['path'] . "/EcontentRecord/{$shortId}/Home");
                 } else {
                     header('Location:' . $configArray['Site']['path'] . "/Record/{$editorialReview->recordId}/Home");
                 }
             } elseif (isset($_REQUEST['submitAddAnother'])) {
                 header('Location:' . $configArray['Site']['path'] . "/EditorialReview/Edit?recordId={$editorialReview->recordId}");
             } else {
                 header('Location:' . $configArray['Site']['path'] . "/EditorialReview/{$editorialReview->editorialReviewId}/View");
                 exit;
             }
         }
     }
     //Manipulate the structure as needed
     if ($isNew) {
     } else {
     }
     $interface->assign('isNew', $isNew);
     $interface->assign('submitUrl', $configArray['Site']['path'] . '/EditorialReview/Edit');
     $interface->assign('editForm', DataObjectUtil::getEditForm($structure));
     $interface->setTemplate('edit.tpl');
     $interface->display('layout.tpl');
 }
Exemple #2
0
 function launch()
 {
     global $interface;
     global $configArray;
     global $user;
     //If the user isn't logged in, take them to the login page
     if (!$user) {
         header("Location: {$configArray['Site']['path']}/MyAccount/Login");
         die;
     }
     //Make sure the user has permission to access the page
     if (!$user->hasRole('epubAdmin')) {
         $interface->setTemplate('../Admin/noPermission.tpl');
         $interface->display('layout.tpl');
         exit;
     }
     $structure = EContentRecord::getObjectStructure();
     if (isset($_REQUEST['submitStay']) || isset($_REQUEST['submit']) || isset($_REQUEST['submitReturnToList']) || isset($_REQUEST['submitAddAnother'])) {
         //Save the object
         $results = DataObjectUtil::saveObject($structure, 'EContentRecord');
         $eContentRecord = $results['object'];
         //redirect to the view of the eContentRecord if we saved ok.
         if (!$results['validatedOk'] || !$results['saveOk']) {
             //Display the errors for the user.
             $interface->assign('errors', $results['errors']);
             $interface->assign('object', $eContentRecord);
             $_REQUEST['id'] = ${$eContentRecord}->id;
         } else {
             //Show the new tip that was created
             header('Location:' . $configArray['Site']['path'] . "/EcontentRecord/{$eContentRecord->id}/Home");
             exit;
         }
     }
     $isNew = true;
     if (isset($_REQUEST['id']) && strlen($_REQUEST['id']) > 0 && is_numeric($_REQUEST['id'])) {
         $object = EContentRecord::staticGet('id', strip_tags($_REQUEST['id']));
         $interface->assign('object', $object);
         $interface->setPageTitle('Edit EContentRecord');
         $isNew = false;
     } else {
         $interface->setPageTitle('Submit a New EContentRecord');
     }
     //Manipulate the structure as needed
     if ($isNew) {
     } else {
     }
     $interface->assign('isNew', $isNew);
     $interface->assign('submitUrl', $configArray['Site']['path'] . '/EcontentRecord/Edit');
     $interface->assign('editForm', DataObjectUtil::getEditForm($structure));
     $interface->setTemplate('edit.tpl');
     $interface->display('layout.tpl');
 }
Exemple #3
0
 function launch()
 {
     global $interface;
     global $timer;
     global $configArray;
     global $user;
     $id = $_REQUEST['id'];
     $structure = EContentItem::getObjectStructure();
     $ret = DataObjectUtil::saveObject($structure, 'EContentItem');
     if (!$ret['validatedOk']) {
         echo "Item failed validation.";
     } elseif (!$ret['saveOk']) {
         echo "Could not save the new item";
     } else {
         $object = $ret['object'];
         header("Location: " . $configArray['Site']['path'] . "/EcontentRecord/{$object->recordId}/Home");
     }
 }
Exemple #4
0
 function launch()
 {
     global $interface;
     global $configArray;
     $isNew = true;
     if (isset($_REQUEST['id']) && strlen($_REQUEST['id']) > 0) {
         $epubFile = new EContentItem();
         $epubFile->id = $_REQUEST['id'];
         $epubFile->find();
         if ($epubFile->N > 0) {
             $epubFile->fetch();
             $interface->assign('object', $epubFile);
             $interface->setPageTitle('Edit EPUB File');
             $isNew = false;
         }
     }
     $structure = EContentItem::getObjectStructure();
     if (isset($_REQUEST['submit'])) {
         //Save the object
         $results = DataObjectUtil::saveObject($structure, 'EContentItem');
         $epubFile = $results['object'];
         //redirect to the view of the competency if we saved ok.
         if (!$results['validatedOk'] || !$results['saveOk']) {
             //Display the errors for the user.
             $interface->assign('errors', $results['errors']);
             $interface->assign('object', $epubFile);
             $_REQUEST['id'] = $epubFile->id;
         } else {
             //Show the new tip that was created
             header('Location:' . $configArray['Site']['path'] . "/EContent/{$epubFile->id}/View");
             exit;
         }
     }
     //Manipulate the structure as needed
     if ($isNew) {
     } else {
     }
     $interface->assign('isNew', $isNew);
     $interface->assign('submitUrl', $configArray['Site']['path'] . '/EContent/Edit');
     $interface->assign('editForm', DataObjectUtil::getEditForm($structure));
     $interface->setTemplate('edit.tpl');
     $interface->display('layout.tpl');
 }
 function validateEpub()
 {
     //Setup validation return array
     $validationResults = array('validatedOk' => true, 'errors' => array());
     //Check to see if we have an existing file
     if (isset($_REQUEST['filename_existing']) && $_FILES['filename']['error'] != 4) {
         if ($_FILES['filename']["error"] != 0) {
             $validationResults['errors'][] = DataObjectUtil::getFileUploadMessage($_FILES['filename']["error"], 'filename');
         }
         //Make sure that the epub is unique, the title for the object should already be filled out.
         $query = "SELECT * FROM epub_files WHERE filename='" . mysql_escape_string($this->filename) . "' and id != '{$this->id}'";
         $result = mysql_query($query);
         if (mysql_numrows($result) > 0) {
             //The title is not unique
             $validationResults['errors'][] = "This file has already been uploaded.\tPlease select another name.";
         }
         if ($this->type == 'epub') {
             if ($_FILES['filename']['type'] != 'application/epub+zip' && $_FILES['filename']['type'] != 'application/octet-stream') {
                 $validationResults['errors'][] = "It appears that the file uploaded is not an EPUB file.\tPlease upload a valid EPUB without DRM.\tDetected {$_FILES['filename']['type']}.";
             }
         } else {
             if ($this->type == 'pdf') {
                 if ($_FILES['filename']['type'] != 'application/pdf') {
                     $validationResults['errors'][] = "It appears that the file uploaded is not a PDF file.\tPlease upload a valid PDF without DRM.\tDetected {$_FILES['filename']['type']}.";
                 }
             }
         }
     } else {
         //Using the existing file.
     }
     //Make sure there aren't errors
     if (count($validationResults['errors']) > 0) {
         $validationResults['validatedOk'] = false;
     }
     return $validationResults;
 }
Exemple #6
0
 function EditItem()
 {
     require_once ROOT_DIR . '/sys/eContent/EContentItem.php';
     require_once ROOT_DIR . '/sys/DataObjectUtil.php';
     global $user;
     global $interface;
     global $configArray;
     $structure = EContentItem::getObjectStructure();
     $object = new EContentItem();
     $recordId = strip_tags($_REQUEST['id']);
     $itemId = strip_tags($_REQUEST['itemId']);
     $object->id = $itemId;
     if ($object->find(true)) {
         $interface->assign('object', $object);
         $interface->assign('title', 'Edit eContent Item');
         $interface->assign('submitUrl', $configArray['Site']['path'] . "/EcontentRecord/SaveItem");
         $interface->assign('editForm', DataObjectUtil::getEditForm($structure));
         return $interface->fetch('EcontentRecord/ajax-editItem.tpl');
     } else {
         return "Could not find a record for item {$itemId}";
     }
 }
 function launch()
 {
     global $configArray;
     global $interface;
     global $user;
     $interface->assign('canAddNew', $this->canAddNew());
     $interface->assign('canDelete', $this->canDelete());
     $interface->assign('showReturnToList', $this->showReturnToList());
     $interface->assign('showExportAndCompare', $this->showExportAndCompare());
     //Figure out what mode we are in
     if (isset($_REQUEST['objectAction'])) {
         $objectAction = $_REQUEST['objectAction'];
     } else {
         $objectAction = 'list';
     }
     if ($objectAction == 'delete' && isset($_REQUEST['id'])) {
         parent::launch();
         exit;
     }
     //Get all available widgets
     $availableWidgets = array();
     $listWidget = new ListWidget();
     if ($user->hasRole('libraryAdmin') || $user->hasRole('contentEditor')) {
         $homeLibrary = Library::getPatronHomeLibrary();
         $listWidget->libraryId = $homeLibrary->libraryId;
     }
     $listWidget->orderBy('name ASC');
     $listWidget->find();
     while ($listWidget->fetch()) {
         $availableWidgets[$listWidget->id] = clone $listWidget;
     }
     $interface->assign('availableWidgets', $availableWidgets);
     //Get the selected widget
     if (isset($_REQUEST['id']) && is_numeric($_REQUEST['id'])) {
         $widget = $availableWidgets[$_REQUEST['id']];
         $interface->assign('object', $widget);
     }
     //Do actions that require preprocessing
     if ($objectAction == 'save') {
         if (!isset($widget)) {
             $widget = new ListWidget();
         }
         DataObjectUtil::updateFromUI($widget, $listWidget->getObjectStructure());
         $validationResults = DataObjectUtil::saveObject($listWidget->getObjectStructure(), "ListWidget");
         if (!$validationResults['validatedOk']) {
             $interface->assign('object', $widget);
             $interface->assign('errors', $validationResults['errors']);
             $objectAction = 'edit';
         } else {
             $interface->assign('object', $validationResults['object']);
             $objectAction = 'view';
         }
     }
     if ($objectAction == 'list') {
         $interface->setTemplate('listWidgets.tpl');
     } else {
         if ($objectAction == 'edit' || $objectAction == 'add') {
             if (isset($_REQUEST['id'])) {
                 $interface->assign('widgetid', $_REQUEST['id']);
                 $interface->assign('id', $_REQUEST['id']);
             }
             $editForm = DataObjectUtil::getEditForm($listWidget->getObjectStructure());
             $interface->assign('editForm', $editForm);
             $interface->setTemplate('listWidgetEdit.tpl');
         } else {
             $interface->setTemplate('listWidget.tpl');
         }
     }
     $interface->setPageTitle('List Widgets');
     $interface->display('layout.tpl');
 }
 static function processProperty($object, $property)
 {
     global $logger;
     $propertyName = $property['property'];
     if ($property['type'] == 'section') {
         foreach ($property['properties'] as $subProperty) {
             DataObjectUtil::processProperty($object, $subProperty);
         }
     } else {
         if (in_array($property['type'], array('text', 'enum', 'hidden', 'url', 'email'))) {
             $object->{$propertyName} = strip_tags(trim($_REQUEST[$propertyName]));
         } else {
             if (in_array($property['type'], array('textarea', 'html', 'folder', 'crSeparated'))) {
                 if (strlen(trim($_REQUEST[$propertyName])) == 0) {
                     $object->{$propertyName} = null;
                 } else {
                     $object->{$propertyName} = trim($_REQUEST[$propertyName]);
                 }
                 //Strip tags from the input to avoid problems
                 if ($property['type'] == 'textarea' || $property['type'] == 'crSeparated') {
                     $object->{$propertyName} = strip_tags($object->{$propertyName});
                 } else {
                     $allowableTags = isset($property['allowableTags']) ? $property['allowableTags'] : '<p><a><b><em><ul><ol><em><li><strong><i><br>';
                     $object->{$propertyName} = strip_tags($object->{$propertyName}, $allowableTags);
                 }
             } else {
                 if ($property['type'] == 'integer') {
                     if (preg_match('/\\d+/', $_REQUEST[$propertyName])) {
                         $object->{$propertyName} = $_REQUEST[$propertyName];
                     } else {
                         $object->{$propertyName} = 0;
                     }
                 } else {
                     if ($property['type'] == 'currency') {
                         if (preg_match('/\\$?\\d*\\.?\\d*/', $_REQUEST[$propertyName])) {
                             if (substr($_REQUEST[$propertyName], 0, 1) == '$') {
                                 $object->{$propertyName} = substr($_REQUEST[$propertyName], 1);
                             } else {
                                 $object->{$propertyName} = $_REQUEST[$propertyName];
                             }
                         } else {
                             $object->{$propertyName} = 0;
                         }
                     } else {
                         if ($property['type'] == 'checkbox') {
                             $object->{$propertyName} = isset($_REQUEST[$propertyName]) && $_REQUEST[$propertyName] == 'on' ? 1 : 0;
                         } else {
                             if ($property['type'] == 'multiSelect') {
                                 if (isset($_REQUEST[$propertyName]) && is_array($_REQUEST[$propertyName])) {
                                     $object->{$propertyName} = $_REQUEST[$propertyName];
                                 } else {
                                     $object->{$propertyName} = array();
                                 }
                             } else {
                                 if ($property['type'] == 'date') {
                                     if (strlen($_REQUEST[$propertyName]) == 0 || $_REQUEST[$propertyName] == '0000-00-00') {
                                         $object->{$propertyName} = null;
                                     } else {
                                         $dateParts = date_parse($_REQUEST[$propertyName]);
                                         $time = $dateParts['year'] . '-' . $dateParts['month'] . '-' . $dateParts['day'];
                                         $object->{$propertyName} = $time;
                                     }
                                 } else {
                                     if ($property['type'] == 'partialDate') {
                                         $dayField = $property['propNameDay'];
                                         $object->{$dayField} = $_REQUEST[$dayField];
                                         $monthField = $property['propNameMonth'];
                                         $object->{$monthField} = $_REQUEST[$monthField];
                                         $yearField = $property['propNameYear'];
                                         $object->{$yearField} = $_REQUEST[$yearField];
                                     } else {
                                         if ($property['type'] == 'image') {
                                             //Make sure that the type is correct (jpg, png, or gif)
                                             if (isset($_REQUEST["remove{$propertyName}"])) {
                                                 $object->{$propertyName} = '';
                                             } else {
                                                 if (isset($_FILES[$propertyName])) {
                                                     if (isset($_FILES[$propertyName]["error"]) && $_FILES[$propertyName]["error"] == 4) {
                                                         $logger->log("No file was uploaded for {$propertyName}", PEAR_LOG_DEBUG);
                                                         //No image supplied, use the existing value
                                                     } else {
                                                         if (isset($_FILES[$propertyName]["error"]) && $_FILES[$propertyName]["error"] > 0) {
                                                             //return an error to the browser
                                                             $logger->log("Error in file upload for {$propertyName}", PEAR_LOG_ERR);
                                                         } else {
                                                             if (in_array($_FILES[$propertyName]["type"], array('image/gif', 'image/jpeg', 'image/png'))) {
                                                                 $logger->log("Processing uploaded file for {$propertyName}", PEAR_LOG_DEBUG);
                                                                 //Copy the full image to the files directory
                                                                 //Filename is the name of the object + the original filename
                                                                 global $configArray;
                                                                 if (isset($property['storagePath'])) {
                                                                     $destFileName = $_FILES[$propertyName]["name"];
                                                                     $destFolder = $property['storagePath'];
                                                                     $destFullPath = $destFolder . '/' . $destFileName;
                                                                     $copyResult = copy($_FILES[$propertyName]["tmp_name"], $destFullPath);
                                                                     $logger->log("Copied file to {$destFullPath}", PEAR_LOG_DEBUG);
                                                                 } else {
                                                                     $logger->log("Creating thumbnails for {$propertyName}", PEAR_LOG_DEBUG);
                                                                     $destFileName = $propertyName . $_FILES[$propertyName]["name"];
                                                                     $destFolder = $configArray['Site']['local'] . '/files/original';
                                                                     $pathToThumbs = $configArray['Site']['local'] . '/files/thumbnail';
                                                                     $pathToMedium = $configArray['Site']['local'] . '/files/medium';
                                                                     $destFullPath = $destFolder . '/' . $destFileName;
                                                                     $copyResult = copy($_FILES[$propertyName]["tmp_name"], $destFullPath);
                                                                     if ($copyResult) {
                                                                         $img = imagecreatefromstring(file_get_contents($destFullPath));
                                                                         $width = imagesx($img);
                                                                         $height = imagesy($img);
                                                                         if (isset($property['thumbWidth'])) {
                                                                             //Create a thumbnail if needed
                                                                             $thumbWidth = $property['thumbWidth'];
                                                                             $new_width = $thumbWidth;
                                                                             $new_height = floor($height * ($thumbWidth / $width));
                                                                             // create a new temporary image
                                                                             $tmp_img = imagecreatetruecolor($new_width, $new_height);
                                                                             // copy and resize old image into new image
                                                                             imagecopyresized($tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
                                                                             // save thumbnail into a file
                                                                             imagejpeg($tmp_img, "{$pathToThumbs}/{$destFileName}");
                                                                         }
                                                                         if (isset($property['mediumWidth'])) {
                                                                             //Create a thumbnail if needed
                                                                             $thumbWidth = $property['mediumWidth'];
                                                                             $new_width = $thumbWidth;
                                                                             $new_height = floor($height * ($thumbWidth / $width));
                                                                             // create a new temporary image
                                                                             $tmp_img = imagecreatetruecolor($new_width, $new_height);
                                                                             // copy and resize old image into new image
                                                                             imagecopyresized($tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
                                                                             // save thumbnail into a file
                                                                             imagejpeg($tmp_img, "{$pathToMedium}/{$destFileName}");
                                                                         }
                                                                     }
                                                                 }
                                                                 //store the actual filename
                                                                 $object->{$propertyName} = $destFileName;
                                                                 $logger->log("Set {$propertyName} to {$destFileName}", PEAR_LOG_DEBUG);
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         } else {
                                             if ($property['type'] == 'file') {
                                                 //Make sure that the type is correct (jpg, png, or gif)
                                                 if (isset($_REQUEST["remove{$propertyName}"])) {
                                                     $object->{$propertyName} = '';
                                                 } elseif (isset($_REQUEST["{$propertyName}_existing"]) && $_FILES[$propertyName]['error'] == 4) {
                                                     $object->{$propertyName} = $_REQUEST["{$propertyName}_existing"];
                                                 } else {
                                                     if (isset($_FILES[$propertyName])) {
                                                         if ($_FILES[$propertyName]["error"] > 0) {
                                                             //return an error to the browser
                                                         } else {
                                                             if (true) {
                                                                 //TODO: validate the file type
                                                                 //Copy the full image to the correct location
                                                                 //Filename is the name of the object + the original filename
                                                                 global $configArray;
                                                                 $destFileName = $_FILES[$propertyName]["name"];
                                                                 $destFolder = $property['path'];
                                                                 $destFullPath = $destFolder . '/' . $destFileName;
                                                                 $copyResult = copy($_FILES[$propertyName]["tmp_name"], $destFullPath);
                                                                 if ($copyResult) {
                                                                     $logger->log("Copied file from {$_FILES[$propertyName]["tmp_name"]} to {$destFullPath}", PEAR_LOG_INFO);
                                                                 } else {
                                                                     $logger->log("Could not copy file from {$_FILES[$propertyName]["tmp_name"]} to {$destFullPath}", PEAR_LOG_ERR);
                                                                     if (!file_exists($_FILES[$propertyName]["tmp_name"])) {
                                                                         $logger->log("  Uploaded file did not exist", PEAR_LOG_ERR);
                                                                     }
                                                                     if (!is_writable($destFullPath)) {
                                                                         $logger->log("  Destination is not writable", PEAR_LOG_ERR);
                                                                     }
                                                                 }
                                                                 //store the actual filename
                                                                 $object->{$propertyName} = $destFileName;
                                                             }
                                                         }
                                                     }
                                                 }
                                             } else {
                                                 if ($property['type'] == 'password') {
                                                     if (strlen($_REQUEST[$propertyName]) > 0 && $_REQUEST[$propertyName] == $_REQUEST[$propertyName . 'Repeat']) {
                                                         $object->{$propertyName} = md5($_REQUEST[$propertyName]);
                                                     }
                                                 } else {
                                                     if ($property['type'] == 'oneToMany') {
                                                         //Check for deleted associations
                                                         $deletions = isset($_REQUEST[$propertyName . 'Deleted']) ? $_REQUEST[$propertyName . 'Deleted'] : array();
                                                         //Check for changes to the sort order
                                                         if ($property['sortable'] == true && isset($_REQUEST[$propertyName . 'Weight'])) {
                                                             $weights = $_REQUEST[$propertyName . 'Weight'];
                                                         }
                                                         $values = array();
                                                         if (isset($_REQUEST[$propertyName . 'Id'])) {
                                                             $idsToSave = $_REQUEST[$propertyName . 'Id'];
                                                             $existingValues = $object->{$propertyName};
                                                             $subObjectType = $property['subObjectType'];
                                                             $subStructure = $property['structure'];
                                                             foreach ($idsToSave as $id) {
                                                                 //Create the subObject
                                                                 if ($id < 0) {
                                                                     $subObject = new $subObjectType();
                                                                 } else {
                                                                     $subObject = $existingValues[$id];
                                                                 }
                                                                 $deleted = isset($deletions[$id]) ? $deletions[$id] : false;
                                                                 if ($deleted == 'true') {
                                                                     $subObject->deleteOnSave = true;
                                                                 } else {
                                                                     //Update properties of each associated object
                                                                     foreach ($subStructure as $subProperty) {
                                                                         $requestKey = $propertyName . '_' . $subProperty['property'];
                                                                         if (in_array($subProperty['type'], array('text', 'enum', 'date', 'integer'))) {
                                                                             $subObject->{$subProperty}['property'] = $_REQUEST[$requestKey][$id];
                                                                         } elseif (in_array($subProperty['type'], array('checkbox'))) {
                                                                             $subObject->{$subProperty}['property'] = isset($_REQUEST[$requestKey][$id]) ? 1 : 0;
                                                                         }
                                                                     }
                                                                 }
                                                                 if ($property['sortable'] == true) {
                                                                     $subObject->weight = $weights[$id];
                                                                 }
                                                                 //Update the values array
                                                                 $values[$id] = $subObject;
                                                             }
                                                         }
                                                         $object->{$propertyName} = $values;
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
 private function saveElement()
 {
     $listWidgetLinks = new ListWidgetListsLinks();
     DataObjectUtil::updateFromUI($listWidgetLinks, $listWidgetLinks->getObjectStructure());
     $validationResults = DataObjectUtil::saveObject($listWidgetLinks->getObjectStructure(), "ListWidgetListsLinks");
 }
 function updateFromUI($object, $structure)
 {
     require_once ROOT_DIR . '/sys/DataObjectUtil.php';
     return DataObjectUtil::updateFromUI($object, $structure);
 }
Exemple #11
0
 function launch()
 {
     global $interface;
     global $user;
     $interface->assign('canAddNew', $this->canAddNew());
     $interface->assign('canDelete', $this->canDelete());
     $interface->assign('showReturnToList', $this->showReturnToList());
     $interface->assign('showExportAndCompare', $this->showExportAndCompare());
     //Figure out what mode we are in
     if (isset($_REQUEST['objectAction'])) {
         $objectAction = $_REQUEST['objectAction'];
     } else {
         $objectAction = 'list';
     }
     if ($objectAction == 'delete' && isset($_REQUEST['id'])) {
         parent::launch();
         exit;
     }
     //Get all available widgets
     $availableWidgets = array();
     $listWidget = new ListWidget();
     if ($user->hasRole('libraryAdmin') || $user->hasRole('contentEditor')) {
         $homeLibrary = Library::getPatronHomeLibrary();
         $listWidget->libraryId = $homeLibrary->libraryId;
     }
     $listWidget->orderBy('name ASC');
     $listWidget->find();
     while ($listWidget->fetch()) {
         $availableWidgets[$listWidget->id] = clone $listWidget;
     }
     $interface->assign('availableWidgets', $availableWidgets);
     //Get the selected widget
     if (isset($_REQUEST['id']) && is_numeric($_REQUEST['id'])) {
         $widget = $availableWidgets[$_REQUEST['id']];
         $interface->assign('object', $widget);
     }
     //Do actions that require pre-processing
     if ($objectAction == 'save') {
         if (!isset($widget)) {
             $widget = new ListWidget();
         }
         DataObjectUtil::updateFromUI($widget, $listWidget->getObjectStructure());
         $validationResults = DataObjectUtil::saveObject($listWidget->getObjectStructure(), "ListWidget");
         if (!$validationResults['validatedOk']) {
             $interface->assign('object', $widget);
             $interface->assign('errors', $validationResults['errors']);
             $objectAction = 'edit';
         } else {
             $interface->assign('object', $validationResults['object']);
             $objectAction = 'view';
         }
     }
     if ($objectAction == 'list') {
         $interface->setTemplate('listWidgets.tpl');
     } else {
         if ($objectAction == 'edit' || $objectAction == 'add') {
             if (isset($_REQUEST['id'])) {
                 $interface->assign('widgetid', $_REQUEST['id']);
                 $interface->assign('id', $_REQUEST['id']);
             }
             $editForm = DataObjectUtil::getEditForm($listWidget->getObjectStructure());
             $interface->assign('editForm', $editForm);
             $interface->setTemplate('listWidgetEdit.tpl');
         } else {
             // Set some default sizes for the iframe we embed on the view page
             switch ($widget->style) {
                 case 'horizontal':
                     $width = 650;
                     $height = 275;
                     break;
                 case 'vertical':
                     $width = 175;
                     $height = 400;
                     break;
                 case 'text-list':
                     $width = 400;
                     $height = 200;
                     break;
                 case 'single':
                 case 'single-with-next':
                     $width = 225;
                     $height = 275;
                     break;
             }
             $interface->assign('width', $width);
             $interface->assign('height', $height);
             $interface->setTemplate('listWidget.tpl');
         }
     }
     $interface->assign('sidebar', 'MyAccount/account-sidebar.tpl');
     $interface->setPageTitle('List Widgets');
     $interface->display('layout.tpl');
 }
 function updateFromUI($object, $structure)
 {
     require_once ROOT_DIR . '/sys/DataObjectUtil.php';
     DataObjectUtil::updateFromUI($object, $structure);
     $validationResults = DataObjectUtil::validateObject($structure, $object);
     return $validationResults;
 }