public static function getIDNO($formID, $increment = TRUE) { $engine = self::$engine; $idno = forms::getFormIDInfo($formID); $sqlResult = $engine->openDB->query(sprintf("SELECT `count` FROM `forms` WHERE `ID`='%s'", $engine->openDB->escape($formID))); if (!$sqlResult['result']) { return FALSE; } $row = mysql_fetch_array($sqlResult['result'], MYSQL_ASSOC); if ($increment === TRUE) { $row['count'] = (string) ((int) $row['count'] + 1); } if (isempty($idno['idnoFormat'])) { return $row['count']; } $idno = $idno['idnoFormat']; $len = strrpos($idno, "#") - strpos($idno, "#") + 1; $padding = str_pad($row['count'], $len, "0", STR_PAD_LEFT); $idno = preg_replace("/#+/", $padding, $idno); return $idno; }
public static function update($objectID, $formID, $data, $metadata, $parentID = 0, $modifiedTime = NULL) { if (!is_array($data)) { errorHandle::newError(__METHOD__ . "() - : data is not array", errorHandle::DEBUG); return FALSE; } // Get the current Form if (($form = forms::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. if (($idnoInfo = forms::getFormIDInfo($formID)) === FALSE) { errorHandle::newError(__METHOD__ . "() - no IDNO field for object form.", errorHandle::DEBUG); return FALSE; } // begin transactions $result = mfcs::$engine->openDB->transBegin("objects"); if ($result !== TRUE) { errorHandle::newError(__METHOD__ . "() - unable to start database transactions", errorHandle::DEBUG); return FALSE; } // place old version into revision control // excluding metadata objects if ($metadata == 0) { $rcs = revisions::create(); $return = $rcs->insertRevision($objectID); if ($return !== TRUE) { mfcs::$engine->openDB->transRollback(); mfcs::$engine->openDB->transEnd(); errorHandle::newError(__METHOD__ . "() - unable to insert revisions", errorHandle::DEBUG); return FALSE; } } // insert new version $sql = sprintf("UPDATE `objects` SET `parentID`='%s', `data`='%s', `formID`='%s', `metadata`='%s', `modifiedTime`='%s', `modifiedBy`='%s' WHERE `ID`='%s'", isset(mfcs::$engine->cleanPost['MYSQL']['parentID']) ? mfcs::$engine->cleanPost['MYSQL']['parentID'] : mfcs::$engine->openDB->escape($parentID), encodeFields($data), mfcs::$engine->openDB->escape($formID), mfcs::$engine->openDB->escape($metadata), isnull($modifiedTime) ? time() : $modifiedTime, mfcs::$engine->openDB->escape(users::user('ID')), mfcs::$engine->openDB->escape($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 into the new data table if (self::insertObjectData($objectID, $data, $formID) === FALSE) { mfcs::$engine->openDB->transRollback(); mfcs::$engine->openDB->transEnd(); errorHandle::newError(__METHOD__ . "() - inserting objects", errorHandle::DEBUG); return FALSE; } // Update duplicate matching table if (duplicates::updateDupeTable($formID, $objectID, $data) === FALSE) { mfcs::$engine->openDB->transRollback(); mfcs::$engine->openDB->transEnd(); errorHandle::newError(__METHOD__ . "() - updating dupe matching", errorHandle::DEBUG); return FALSE; } // if it is an object form (not a metadata form) // do the IDNO stuff // We only have to do this if the IDNO is managed by the user if ($form['metadata'] == "0" && $idnoInfo['managedBy'] != "system") { // the form is an object form, make sure that it has an ID field defined. if (($idnoInfo = forms::getFormIDInfo($formID)) === FALSE) { errorHandle::newError(__METHOD__ . "() - no IDNO field for object form.", errorHandle::DEBUG); return FALSE; } $idno = isset(mfcs::$engine->cleanPost['MYSQL']['idno']) && !isempty(mfcs::$engine->cleanPost['MYSQL']['idno']) ? mfcs::$engine->cleanPost['MYSQL']['idno'] : self::getIDNOForObjectID($objectID); if ($idno === FALSE || isempty($idno)) { mfcs::$engine->openDB->transRollback(); mfcs::$engine->openDB->transEnd(); return FALSE; } if (!self::updateIDNO($objectID, $idno)) { mfcs::$engine->openDB->transRollback(); mfcs::$engine->openDB->transEnd(); errorHandle::newError(__METHOD__ . "() - updating the IDNO: " . $sqlResult['error'], errorHandle::DEBUG); return FALSE; } } // end transactions mfcs::$engine->openDB->transCommit(); mfcs::$engine->openDB->transEnd(); return TRUE; }