public static function generateFieldDisplay($object, $fields) { $output = ''; $data = is_array($object['data']) ? $object['data'] : decodeFields($object['data']); foreach ($fields as $field) { $type = $field['type']; $name = $field['name']; $label = $field['label']; switch ($type) { case 'idno': $output .= sprintf('<section class="objectField"><header>%s</header>%s</section>', $label, $object[$name]); break; case 'file': // if the archive isn't set, we assume no files and break out. // otherwise the revisions page won't load properly. if (!isset($data[$name]['files']['archive'])) { break; } $fileLIs = array(); foreach ($data[$name]['files']['archive'] as $file) { $fileLIs[] = sprintf('%s', $file['name']); } $output .= sprintf('<section class="objectField"><header>%s</header>%s file%s <a href="javascript:;" class="toggleFileList">click to list</a><ul style="display:none;">%s</ul></section>', $label, sizeof($fileLIs), sizeof($fileLIs) > 1 ? 's' : '', implode('', $fileLIs)); break; default: case 'text': $output .= sprintf('<section class="objectField"><header>%s</header>%s<!--<aside><button class="btn btn-mini" type="button">Show Diff</button></aside>--></section>', $label, $data[$name]); break; } } return $output; }
/** * returns the database object for the project ID. If no projectID is provided, * returns an array of all the projects, using getProject method defaults * we need to add caching to this, once caching is moved from EngineCMS to EngineAPI * * @author Michael Bond * @param integer $projectID MySQL ID of the project to get * @return array */ public static function get($projectID = NULL) { if (isnull($projectID)) { return self::getProjects(); } $sql = sprintf("SELECT * FROM `projects` WHERE `ID`='%s'", mfcs::$engine->openDB->escape($projectID)); $sqlResult = mfcs::$engine->openDB->query($sql); if (!$sqlResult['result']) { errorHandle::newError(__METHOD__ . "() - " . $sqlResult['error'], errorHandle::DEBUG); return FALSE; } $project = mysql_fetch_array($sqlResult['result'], MYSQL_ASSOC); if (!isempty($project['forms']) && ($project['forms'] = decodeFields($project['forms'])) === FALSE) { return FALSE; } if (!isempty($project['groupings']) && ($project['groupings'] = decodeFields($project['groupings'])) === FALSE) { return FALSE; } return $project; }
public static function retrieveData($formID, $fieldName = NULL) { $sql = sprintf("SELECT * FROM `objectsData` WHERE `formID`='%s'", mfcs::$engine->openDB->escape($formID)); if (!isnull($fieldName)) { $sql .= "AND `fieldName`='" . mfcs::$engine->openDB->escape($fieldName) . "'"; } $sqlResult = mfcs::$engine->openDB->query($sql); if (!$sqlResult['result']) { errorHandle::newError(__METHOD__ . "() - : " . $sqlResult['error'], errorHandle::DEBUG); return FALSE; } $data = array(); while ($row = mysql_fetch_array($sqlResult['result'], MYSQL_ASSOC)) { if (!isnull($fieldName) && $row['fieldName'] != $fieldName) { continue; } if ($row['encoded'] == "1") { $row['value'] = decodeFields($row['value']); } $data[] = $row; } return $data; }
$form = forms::get($object['formID']); $fields = $form['fields']; 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));
public static function retrieveObjectData($objectID) { $sql = sprintf("SELECT * FROM `objectsData` WHERE `objectID`='%s'", mfcs::$engine->openDB->escape($objectID)); $sqlResult = mfcs::$engine->openDB->query($sql); if (!$sqlResult['result']) { errorHandle::newError(__METHOD__ . "() - : " . $sqlResult['error'], errorHandle::DEBUG); return FALSE; } $data = array(); while ($row = mysql_fetch_array($sqlResult['result'], MYSQL_ASSOC)) { $data[$row['fieldName']] = $row['encoded'] == "1" ? decodeFields($row['value']) : $row['value']; } return $data; }
<h3>Metadata Forms</h3> <div class="row-fluid"> <ul class="unstyled draggable span6">%s</ul> <ul class="unstyled draggable span6">%s</ul> </div>', $metadataFormsEven, $metadataFormsOdd)); } // Get existing groupings $sql = sprintf("SELECT * FROM `forms` WHERE `ID`='%s' LIMIT 1", $engine->openDB->escape($formID)); $sqlResult = $engine->openDB->query($sql); if (!$sqlResult['result']) { errorHandle::newError("MySQL Error - Error getting project ({$sqlResult['error']})", errorHandle::DEBUG); throw new Exception("Error getting navigation"); } $row = mysql_fetch_array($sqlResult['result'], MYSQL_ASSOC); if (!is_empty($row['navigation'])) { $tmp = decodeFields($row['navigation']); $groupings = array(); $preview = NULL; // Get all groupings needed foreach ($tmp as $I => $V) { if (!is_empty($V['grouping'])) { $groupings[$V['grouping']] = array("type" => "grouping", "grouping" => $V['grouping']); } } $positionOffset = 0; foreach ($tmp as $I => $V) { $values = json_encode($V); if (!is_empty($V['grouping']) && isset($groupings[$V['grouping']])) { $preview .= sprintf(' <li id="GroupingsPreview_%s"> <div class="groupingPreview">
<?php include "../header.php"; $fields = array(); $sql = sprintf("SELECT ID,fields FROM `forms`"); $sqlResult = $engine->openDB->query($sql); if ($sqlResult['result']) { while ($row = mysql_fetch_array($sqlResult['result'], MYSQL_ASSOC)) { $tmp = decodeFields($row['fields']); if (isset($tmp) && is_array($tmp)) { $field = array(); foreach ($tmp as $f) { $field[] = array("name" => isset($f['name']) ? $f['name'] : '[no name]', "label" => isset($f['label']) ? $f['label'] : '[no label]'); } $fields[$row['ID']] = $field; } } } print json_encode($fields);