public static function submit($formID, $objectID = NULL, $importing = FALSE) { $engine = mfcs::$engine; $backgroundProcessing = array(); if (isnull($objectID)) { $newObject = TRUE; } else { $newObject = FALSE; } // Get the current Form if (($form = self::get($formID)) === FALSE) { errorHandle::newError(__METHOD__ . "() - retrieving form by formID", errorHandle::DEBUG); return FALSE; } // the form is an object form, make sure that it has an ID field defined. // @TODO this check can probably be removed, its being checked in object class if ($form['metadata'] == "0") { $idnoInfo = self::getFormIDInfo($formID); if ($idnoInfo === FALSE) { errorHandle::newError(__METHOD__ . "() - no IDNO field for object form.", errorHandle::DEBUG); return FALSE; } } $fields = $form['fields']; if (usort($fields, 'sortFieldsByPosition') !== TRUE) { errorHandle::newError(__METHOD__ . "() - usort", errorHandle::DEBUG); if (!$importing) { errorHandle::errorMsg("Error retrieving form."); } return FALSE; } $values = array(); // go through all the fields, get their values foreach ($fields as $field) { $value = isset($engine->cleanPost['RAW'][$field['name']]) ? $engine->cleanPost['RAW'][$field['name']] : ""; $validationTests = self::validateSubmission($formID, $field, $value, $objectID); if (isnull($validationTests) || $validationTests === FALSE) { continue; } if (strtolower($field['readonly']) == "true") { // need to pull the data that loaded with the form if ($newObject === FALSE) { // grab it from the database $oldObject = objects::get($objectID); $values[$field['name']] = $oldObject['data'][$field['name']]; } else { // If the form has a variable in the value we apply the variable, otherwise, field value. // we need to check for disabled on insert form if (!isset($field['disabledInsert']) || isset($field['disabledInsert']) && $field['disabledInsert'] == "false") { $values[$field['name']] = self::hasFieldVariables($field['value']) ? self::applyFieldVariables($value) : $field['value']; } // grab the default value from the form. // $values[$field['name']] = $field['value']; } } else { if (strtolower($field['type']) == "file" && isset($engine->cleanPost['MYSQL'][$field['name']])) { // Process uploaded files $uploadID = $engine->cleanPost['MYSQL'][$field['name']]; // Process the uploads and put them into their archival locations if (($tmpArray = files::processObjectUploads($objectID, $uploadID)) === FALSE) { errorHandle::newError(__METHOD__ . "() - Archival Location", errorHandle::DEBUG); return FALSE; } if ($tmpArray !== TRUE) { // didn't generate a proper uuid for the items, rollback if (!isset($tmpArray['uuid'])) { $engine->openDB->transRollback(); $engine->openDB->transEnd(); errorHandle::newError(__METHOD__ . "() - No UUID", errorHandle::DEBUG); return FALSE; } // ads this field to the files object // we can't do inserts yet because we don't have the objectID on // new objects files::addProcessingField($field['name']); // Should the files be processed now or later? if (isset($field['bgProcessing']) && str2bool($field['bgProcessing']) === TRUE) { $backgroundProcessing[$field['name']] = TRUE; } else { $backgroundProcessing[$field['name']] = FALSE; } $values[$field['name']] = $tmpArray; } else { // if we don't have files, and this is an update, we need to pull the files information from the // version that is already in the system. $oldObject = objects::get($objectID); if ($newObject === FALSE && objects::hasFiles($objectID, $field['name']) === TRUE) { $values[$field['name']] = $oldObject['data'][$field['name']]; } } } else { $values[$field['name']] = $value; } } } if (isset($engine->errorStack['error']) && count($engine->errorStack['error']) > 0) { // errorHandle::newError(__METHOD__."() - Error stack not empty.", errorHandle::DEBUG); return FALSE; } // start transactions $result = $engine->openDB->transBegin("objects"); if ($result !== TRUE) { if (!$importing) { errorHandle::errorMsg("Database transactions could not begin."); } errorHandle::newError(__METHOD__ . "() - unable to start database transactions", errorHandle::DEBUG); return FALSE; } if ($newObject === TRUE) { if (objects::create($formID, $values, $form['metadata'], isset($engine->cleanPost['MYSQL']['parentID']) ? $engine->cleanPost['MYSQL']['parentID'] : "0") === FALSE) { $engine->openDB->transRollback(); $engine->openDB->transEnd(); if (!$importing) { errorHandle::errorMsg("Error inserting new object."); } errorHandle::newError(__METHOD__ . "() - Error inserting new object.", errorHandle::DEBUG); return FALSE; } // Grab the objectID of the new object $objectID = localvars::get("newObjectID"); } else { if (objects::update($objectID, $formID, $values, $form['metadata'], isset($engine->cleanPost['MYSQL']['parentID']) ? $engine->cleanPost['MYSQL']['parentID'] : "0") === FALSE) { $engine->openDB->transRollback(); $engine->openDB->transEnd(); if (!$importing) { errorHandle::errorMsg("Error updating."); } errorHandle::newError(__METHOD__ . "() - Error updating.", errorHandle::DEBUG); return FALSE; } } // Now that we have a valid objectID, we insert into the processing table if (files::insertIntoProcessingTable($objectID) === FALSE) { $engine->openDB->transRollback(); $engine->openDB->transEnd(); errorHandle::newError(__METHOD__ . "() - Processing Table", errorHandle::DEBUG); return FALSE; } // end transactions $engine->openDB->transCommit(); $engine->openDB->transEnd(); if (!is_empty($backgroundProcessing)) { foreach ($backgroundProcessing as $fieldName => $V) { if ($V === FALSE) { // No background processing. do it now. files::process($objectID, $fieldName); } } } if ($newObject === TRUE) { if (!$importing) { errorHandle::successMsg("Object created successfully."); } } else { if (!$importing) { errorHandle::successMsg("Object updated successfully."); } } return TRUE; }
} if (forms::isProductionReady($engine->cleanGet['MYSQL']['formID']) === FALSE) { $permissions = FALSE; throw new Exception("Form is not production ready."); } if (forms::isMetadataForm($engine->cleanGet['MYSQL']['formID'])) { throw new Exception("Metadata form provided (Object forms only)."); } /* Parent Object 'Stuff' */ if (isset($engine->cleanGet['MYSQL']['parentID']) && ($parentObject = objects::get($engine->cleanGet['MYSQL']['parentID'])) === FALSE) { throw new Exception("Unable to retrieve parent object"); } /* End Parent Object 'Stuff' */ // Editor information if (!isnull($engine->cleanGet['MYSQL']['objectID'])) { $object = objects::get($engine->cleanGet['MYSQL']['objectID']); if (is_empty($object['createdBy'])) { localvars::add("createdByUsername", "Unavailable"); } else { $user = users::get($object['createdBy']); localvars::add("createdByUsername", $user['username']); } localvars::add("createdOnDate", date('D, d M Y H:i', $object['createTime'])); if (is_empty($object['modifiedBy'])) { localvars::add("modifiedByUsername", "Unavailable"); } else { $user = users::get($object['modifiedBy']); localvars::add("modifiedByUsername", $user['username']); } localvars::add("modifiedOnDate", date('D, d M Y H:i', $object['modifiedTime'])); }
public static function buildFilesPreview($objectID, $fieldName = NULL) { if (objects::validID(TRUE, $objectID) === FALSE) { return FALSE; } if (($object = objects::get($objectID, TRUE)) === FALSE) { return FALSE; } $output = ''; if (isset($fieldName)) { $field = forms::getField($object['formID'], $fieldName); $fields = array($field); } else { $fields = forms::getFields($object['formID']); } $fileLIs = array(); foreach ($fields as $field) { if ($field['type'] != 'file') { continue; } // If there's nothing uploaded for the field, no need to continue if (empty($object['data'][$field['name']])) { continue; } // Figure out some needed vars for later $fileDataArray = $object['data'][$field['name']]; $assetsID = $fileDataArray['uuid']; $fileLIs = array(); uasort($fileDataArray['files']['archive'], function ($a, $b) { return strnatcasecmp($a['name'], $b['name']); }); foreach ($fileDataArray['files']['archive'] as $fileID => $file) { $_filename = pathinfo($file['name']); $filename = $_filename['filename']; $links = array(); $links['Original'] = sprintf('%sincludes/fileViewer.php?objectID=%s&field=%s&fileID=%s&type=%s', localvars::get('siteRoot'), $objectID, $field['name'], $fileID, 'archive'); if (str2bool($field['convert'])) { $links['Converted'] = sprintf('%sincludes/fileViewer.php?objectID=%s&field=%s&fileID=%s&type=%s', localvars::get('siteRoot'), $objectID, $field['name'], $fileID, 'processed'); } if (str2bool($field['thumbnail'])) { $links['Thumbnail'] = sprintf('%sincludes/fileViewer.php?objectID=%s&field=%s&fileID=%s&type=%s', localvars::get('siteRoot'), $objectID, $field['name'], $fileID, 'thumbs'); } if (str2bool($field['ocr'])) { $links['OCR'] = sprintf('%sincludes/fileViewer.php?objectID=%s&field=%s&fileID=%s&type=%s', localvars::get('siteRoot'), $objectID, $field['name'], $fileID, 'ocr'); } if (str2bool($field['combine'])) { $links['Combined PDF'] = sprintf('%sincludes/fileViewer.php?objectID=%s&field=%s&type=%s', localvars::get('siteRoot'), $objectID, $field['name'], 'combinedPDF'); $links['Combined Thumbnail'] = sprintf('%sincludes/fileViewer.php?objectID=%s&field=%s&type=%s', localvars::get('siteRoot'), $objectID, $field['name'], 'combinedThumb'); } $previewLinks = array(); $downloadLinks = array(); foreach ($links as $linkLabel => $linkURL) { $previewLinks[] = sprintf('<li><a tabindex="-1" href="javascript:;" onclick="previewFile(this,\'%s\')">%s</a></li>', $linkURL, $linkLabel); $downloadLinks[] = sprintf('<li><a tabindex="-1" href="%s&download=1">%s</a></li>', $linkURL, $linkLabel); } // Build the preview dropdown HTML $previewDropdown = '<div class="btn-group">'; $previewDropdown .= ' <a class="btn dropdown-toggle" data-toggle="dropdown" href="#">'; $previewDropdown .= ' Preview <span class="caret"></span>'; $previewDropdown .= ' </a>'; $previewDropdown .= sprintf('<ul class="dropdown-menu">%s</ul>', implode('', $previewLinks)); $previewDropdown .= '</div>'; // Build the download dropbox HTML $downloadDropdown = '<div class="btn-group">'; $downloadDropdown .= ' <a class="btn dropdown-toggle" data-toggle="dropdown" href="#">'; $downloadDropdown .= ' Download <span class="caret"></span>'; $downloadDropdown .= ' </a>'; $downloadDropdown .= sprintf('<ul class="dropdown-menu">%s</ul>', implode('', $downloadLinks)); $downloadDropdown .= '</div>'; $fileLIs[] = sprintf('<li><div class="filename">%s</div><!-- TODO <button class="btn">Field Details</button> -->%s%s</li>', $file['name'], $previewDropdown, $downloadDropdown); } $output .= sprintf('<div class="filePreviewField"><header>%s</header><ul class="filePreviews">%s</ul></div>', $field['label'], implode('', $fileLIs)); } // Include the filePreview Modal, and the CSS and JavaScript links $output .= '<div id="filePreviewModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"><div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button><h3></h3></div><div class="modal-body"><iframe class="filePreview"></iframe></div><div class="modal-footer"><a class="btn previewDownloadLink">Download File</a><a class="btn btn-primary" data-dismiss="modal" aria-hidden="true">Close</a></div></div>'; $output .= sprintf('<link href="%sincludes/css/filePreview.css" rel="stylesheet">', localvars::get('siteRoot')); $output .= sprintf('<script src="%sincludes/js/filePreview.js"></script>', localvars::get('siteRoot')); return $output; }
if (mfcsPerms::isEditor($form['ID']) === FALSE) { throw new Exception("Permission Denied to view objects created with this form."); } log::insert("Data Entry: Revision: View Page", $objectID); ############################################################################################################### // Catch a form submition (which would be a revision being reverted to) if (isset($engine->cleanPost['MYSQL']['revisionID'])) { log::insert("Data Entry: Revision: Revert", $objectID); // @TODO this should use revert2Revision() method instead of this ... $revisionID = $revisions->getRevisionID($engine->cleanGet['MYSQL']['objectID'], $engine->cleanPost['MYSQL']['revisionID']); if (($revision = $revisions->getMetadataForID($revisionID)) === FALSE) { throw new Exception('Could not load revision.'); } if (objects::update($engine->cleanGet['MYSQL']['objectID'], $revision['formID'], decodeFields($revision['data']), $revision['metadata'], $revision['parentID']) !== FALSE) { // Reload the object - To refresh the data $object = objects::get($objectID, TRUE); } else { throw new Exception('Could not update object with revision.'); } } ############################################################################################################### // Is this just a revision AJAX request? if (isset($engine->cleanGet['MYSQL']['revisionID'])) { $revisionID = $revisions->getRevisionID($engine->cleanGet['MYSQL']['objectID'], $engine->cleanGet['MYSQL']['revisionID']); $revision = $revisions->getMetadataForID($revisionID); if (!$revision) { die('Error reading revision'); } else { die(revisions::generateFieldDisplay($revision, $fields)); } }
function getHeadingByID($id) { $object = objects::get($id); return $object['data']['name']; }
<?php include "../header.php"; $permissions = TRUE; try { if (!isset($engine->cleanGet['MYSQL']['objectID']) && isset($engine->cleanPost['MYSQL']['objectID'])) { http::setGet("objectID", $engine->cleanPost['MYSQL']['objectID']); } if (objects::validID() === FALSE) { throw new Exception("ObjectID Provided is invalid."); } if (($object = objects::get($engine->cleanGet['MYSQL']['objectID'])) === FALSE) { throw new Exception("Error retrieving Object"); } if (($form = forms::get($object['formID'])) === FALSE) { throw new Exception("Error retrieving form."); } if (mfcsPerms::isAdmin($object['formID']) === FALSE) { $permissions = FALSE; throw new Exception("Permission Denied to view objects created with this form."); } if (forms::isMetadataForm($object['formID']) === FALSE) { throw new Exception("Object provided (Only Metadata can be moved)."); } // handle submission $return = NULL; if (isset($engine->cleanPost['MYSQL']['moveMetadata'])) { } if (($compatibleForms = forms::compatibleForms($form['ID'])) === FALSE) { throw new Exception("Error getting compatible forms"); }
<?php session_save_path('/tmp'); include "../public_html/header.php"; include "../public_html/includes/functions.php"; include "../public_html/includes/validator.php"; $objects = objects::get(); // Begin the transaction if (mfcs::$engine->openDB->transBegin("objects") !== TRUE) { print __METHOD__ . "() - unable to start database transactions"; exit; } foreach ($objects as $object) { // only rebuild the objects if ($object['metadata'] != '0') { continue; } // Build cleanPost // @TODO this should be stripped when updateDupeTable is fixed to not require cleanPost // Reset cleanPost mfcs::$engine->cleanPost['MYSQL'] = array(); mfcs::$engine->cleanPost['HTML'] = array(); mfcs::$engine->cleanPost['RAW'] = array(); foreach ($object['data'] as $name => $raw) { http::setPost($name, $raw); } if (duplicates::updateDupeTable($object['formID'], $object['ID'], $object['data']) === FALSE) { mfcs::$engine->openDB->transRollback(); mfcs::$engine->openDB->transEnd(); print __METHOD__ . "() - updating dupe matching"; exit;