Ejemplo n.º 1
0
 public static function updateFormNav($groupings)
 {
     $groupings = json_decode($groupings, TRUE);
     if (!is_empty($groupings)) {
         foreach ($groupings as $I => $grouping) {
             $positions[$I] = $grouping['position'];
         }
         array_multisort($positions, SORT_ASC, $groupings);
     }
     $groupings = encodeFields($groupings);
     $sql = sprintf("UPDATE `forms` SET `navigation`='%s' WHERE `ID`='%s'", mfcs::$engine->openDB->escape($groupings), mfcs::$engine->cleanGet['MYSQL']['id']);
     $sqlResult = mfcs::$engine->openDB->query($sql);
     if (!$sqlResult['result']) {
         errorHandle::newError(__METHOD__ . "() - " . $sqlResult['error'], errorHandle::DEBUG);
         return FALSE;
     }
     return TRUE;
 }
Ejemplo n.º 2
0
 public static function submitEditTable($formID)
 {
     $form = self::get($formID);
     if ($form === FALSE) {
         return FALSE;
     }
     $engine = EngineAPI::singleton();
     // begin transactions
     $result = $engine->openDB->transBegin("objects");
     if ($result !== TRUE) {
         errorHandle::errorMsg("Database transactions could not begin.");
         errorHandle::newError(__METHOD__ . "() - unable to start database transactions", errorHandle::DEBUG);
         return FALSE;
     }
     // Do the Updates
     $objects = objects::getAllObjectsForForm($formID, NULL, FALSE);
     if (count($objects) > 0) {
         foreach ($objects as $object) {
             $values = array();
             foreach ($form['fields'] as $field) {
                 // @TODO keep an eye on this with edit tables ... this was added to help the modal inserts
                 // from being deleted because the edit table didn't have them listed.
                 if (!isset($engine->cleanPost['RAW'][$field['name'] . "_" . $object['ID']])) {
                     continue 2;
                 }
                 $value = isset($engine->cleanPost['RAW'][$field['name'] . "_" . $object['ID']]) ? $engine->cleanPost['RAW'][$field['name'] . "_" . $object['ID']] : $object['data'][$field['name']];
                 $validationTests = self::validateSubmission($formID, $field, $value, $object['ID']);
                 if (isnull($validationTests) || $validationTests === FALSE) {
                     continue 2;
                 }
                 if (strtolower($field['readonly']) == "true") {
                     // need to pull the data that loaded with the form
                     if ($newObject === TRUE) {
                         // grab it from the database
                         $oldObject = object::get($objectID);
                         $values[$field['name']] = $oldObject['data'][$field['name']];
                     } else {
                         // grab the default value from the form.
                         $values[$field['name']] = $field['value'];
                     }
                     continue;
                 }
                 if (!isset($values[$field['name']])) {
                     $values[$field['name']] = $value;
                 }
                 if (!is_empty($engine->errorStack)) {
                     $engine->openDB->transRollback();
                     $engine->openDB->transEnd();
                     return FALSE;
                 }
             }
             // Check to see if the objects data has changed. if it has, update it.
             if (encodeFields($values) != $object['data']) {
                 if (objects::update($object['ID'], $formID, $values, $form['metadata']) === FALSE) {
                     $engine->openDB->transRollback();
                     $engine->openDB->transEnd();
                     errorHandle::newError(__METHOD__ . "() - error updating edit table", errorHandle::DEBUG);
                     errorHandle::errorMsg("Error updating.");
                     return FALSE;
                 }
             }
         }
     }
     // do the deletes
     if (isset($engine->cleanPost['MYSQL']['delete']) && count($engine->cleanPost['MYSQL']['delete']) > 0) {
         foreach ($engine->cleanPost['MYSQL']['delete'] as $objectID) {
             $sql = sprintf("DELETE FROM `objects` WHERE `ID`='%s'", $objectID);
             $sqlResult = $engine->openDB->query($sql);
             if (!$sqlResult['result']) {
                 $engine->openDB->transRollback();
                 $engine->openDB->transEnd();
                 errorHandle::errorMsg("Error deleting objects.");
                 errorHandle::newError(__METHOD__ . "() - : " . $sqlResult['error'], errorHandle::DEBUG);
                 return FALSE;
             }
             $sql = sprintf("DELETE FROM `dupeMatching` WHERE `objectID`='%s'", $objectID);
             $sqlResult = $engine->openDB->query($sql);
             if (!$sqlResult['result']) {
                 $engine->openDB->transRollback();
                 $engine->openDB->transEnd();
                 errorHandle::errorMsg("Error deleting objects.");
                 errorHandle::newError(__METHOD__ . "() - : " . $sqlResult['error'], errorHandle::DEBUG);
                 return FALSE;
             }
             $sql = sprintf("DELETE FROM `objectsData` WHERE `objectID`='%s'", $objectID);
             $sqlResult = $engine->openDB->query($sql);
             if (!$sqlResult['result']) {
                 $engine->openDB->transRollback();
                 $engine->openDB->transEnd();
                 errorHandle::errorMsg("Error deleting objects. Objects Data table.");
                 errorHandle::newError(__METHOD__ . "() - : " . $sqlResult['error'], errorHandle::DEBUG);
                 return FALSE;
             }
         }
     }
     // end transactions
     $engine->openDB->transCommit();
     $engine->openDB->transEnd();
     return TRUE;
 }
Ejemplo n.º 3
0
 public static function insertObjectData($objectID, $data, $formID)
 {
     if (!is_array($data)) {
         return FALSE;
     }
     if (mfcs::$engine->openDB->transBegin("objectsData") !== TRUE) {
         errorHandle::newError(__METHOD__ . "() - unable to start database transactions", errorHandle::DEBUG);
         return FALSE;
     }
     // remove old data
     $sql = sprintf("DELETE FROM `objectsData` WHERE `objectID`='%s'", $objectID);
     $sqlResult = mfcs::$engine->openDB->query($sql);
     if (!$sqlResult['result']) {
         mfcs::$engine->openDB->transRollback();
         mfcs::$engine->openDB->transEnd();
         errorHandle::newError(__METHOD__ . "() - " . $sql . " -- " . $sqlResult['error'], errorHandle::DEBUG);
         return FALSE;
     }
     // insert new data
     foreach ($data as $I => $V) {
         $encoded = 0;
         if (is_array($V)) {
             // encode it
             $V = encodeFields($V);
             $encoded = 1;
         }
         $sql = sprintf("INSERT INTO `objectsData` (formID,objectID,fieldName,value,encoded) VALUES('%s','%s','%s','%s','%s')", mfcs::$engine->openDB->escape($formID), mfcs::$engine->openDB->escape($objectID), mfcs::$engine->openDB->escape($I), mfcs::$engine->openDB->escape($V), mfcs::$engine->openDB->escape($encoded));
         $sqlResult = mfcs::$engine->openDB->query($sql);
         if (!$sqlResult['result']) {
             mfcs::$engine->openDB->transRollback();
             mfcs::$engine->openDB->transEnd();
             errorHandle::newError(__METHOD__ . "() - " . $sql . " -- " . $sqlResult['error'], errorHandle::DEBUG);
             return FALSE;
         }
     }
     mfcs::$engine->openDB->transCommit();
     mfcs::$engine->openDB->transEnd();
     return TRUE;
 }
Ejemplo n.º 4
0
             }
         }
     } else {
         // Blank linkTable on object forms
         $form['linkTitle'] = '';
     }
     // Update forms table
     $sql = sprintf("UPDATE `forms`\n\t\t\t\t\t\tSET `title`='%s',\n\t\t\t\t\t\t\t`description`=%s,\n\t\t\t\t\t\t\t`fields`='%s',\n\t\t\t\t\t\t\t`idno`='%s',\n\t\t\t\t\t\t\t`submitButton`='%s',\n\t\t\t\t\t\t\t`updateButton`='%s',\n\t\t\t\t\t\t\t`container`='%s',\n\t\t\t\t\t\t\t`production`='%s',\n\t\t\t\t\t\t\t`metadata`='%s',\n\t\t\t\t\t\t\t%s\n\t\t\t\t\t\t\t`displayTitle`='%s',\n\t\t\t\t\t\t\t`objectTitleField`='%s',\n\t\t\t\t\t\t\t`linkTitle`=%s\n\t\t\t\t\t\tWHERE ID='%s' LIMIT 1", $engine->openDB->escape($form['formTitle']), !is_empty($form['formDescription']) ? "'" . $engine->openDB->escape($form['formDescription']) . "'" : "NULL", encodeFields($fields), encodeFields($idno), $engine->openDB->escape($form['submitButton']), $engine->openDB->escape($form['updateButton']), $engine->openDB->escape($form['formContainer']), $engine->openDB->escape($form['formProduction']), $engine->openDB->escape($form['formMetadata']), $countSql, $engine->openDB->escape($form['objectDisplayTitle']), $engine->openDB->escape($form['objectTitleField']), !is_empty($form['linkTitle']) ? "'" . $engine->openDB->escape($form['linkTitle']) . "'" : "NULL", $engine->openDB->escape($formID));
     $sqlResult = $engine->openDB->query($sql);
     if (!$sqlResult['result']) {
         errorHandle::newError(__METHOD__ . "() - updating form: " . $sqlResult['error'], errorHandle::DEBUG);
         errorHandle::errorMsg("Failed to update form.");
     }
 } else {
     // Insert into forms table
     $sql = sprintf("INSERT INTO `forms` (title, description, fields, idno, submitButton, updateButton, container, production, metadata, count, displayTitle, objectTitleField, linkTitle) VALUES ('%s',%s,'%s','%s','%s','%s','%s','%s','%s','%s','%s','%s',%s)", $engine->openDB->escape($form['formTitle']), isset($form['formDescription']) ? "'" . $engine->openDB->escape($form['formDescription']) . "'" : "NULL", encodeFields($fields), encodeFields($idno), $engine->openDB->escape($form['submitButton']), $engine->openDB->escape($form['updateButton']), $engine->openDB->escape($form['formContainer']), $engine->openDB->escape($form['formProduction']), $engine->openDB->escape($form['formMetadata']), $engine->openDB->escape($count), $engine->openDB->escape($form['objectDisplayTitle']), $engine->openDB->escape($form['objectTitleField']), !is_empty($form['linkTitle']) ? "'" . $engine->openDB->escape($form['linkTitle']) . "'" : "NULL");
     $sqlResult = $engine->openDB->query($sql);
     if (!$sqlResult['result']) {
         errorHandle::newError(__METHOD__ . "() - Inserting new form: " . $sqlResult['error'] . " == " . $sql, errorHandle::DEBUG);
         errorHandle::errorMsg("Failed to create form.");
     } else {
         $formID = $sqlResult['id'];
     }
 }
 if (!is_empty($engine->errorStack)) {
     $engine->openDB->transRollback();
     $engine->openDB->transEnd();
 } else {
     $engine->openDB->transCommit();
     $engine->openDB->transEnd();
     errorHandle::successMsg("Successfully submitted form.");