/** * Method called when form details are being saved to a normal table. * @param Array $formValues The list of details being saved. * @return Integer The ID of the newly saved record, or false if something went wrong. */ protected function handleSaveMainDetails($formValues) { if (!$this->primaryKey || !$this->tableName) { $this->messages = $this->showMessage('handleSave(): Nothing could be saved, as the table name and primary key details are invalid.', true); return false; } global $wpdb; $wpdb->show_errors(); // Have we already got this entry in the database? $this->alreadyExists = false; // Check #1 - See if we've got a primary key for it? $this->primaryKeyValue = $this->formObj->getArrayValue($formValues, $this->primaryKey); if ($this->primaryKeyValue) { //ÊCheck #2 - See if the record exists already $details = getRecordDetails($this->tableName, $this->primaryKey, $this->primaryKeyValue); if (!empty($details)) { $this->alreadyExists = true; } } // Record already exists, so updated it... if ($this->alreadyExists) { $SQL = arrayToSQLUpdate($this->tableName, $formValues, $this->primaryKey); $wpdb->query($SQL); $this->messages = $this->showMessage($this->msg_record_updated); // Update the locally stored details $this->recordDetails = getRecordDetails($this->tableName, $this->primaryKey, $this->primaryKeyValue, ARRAY_A); // Function called when record has been updated. if ($this->fn_record_updated && function_exists($this->fn_record_updated)) { call_user_func($this->fn_record_updated, $this->recordDetails); } // ID of existign record return $this->primaryKeyValue; } else { // Ensure that primary key is not set when creating a new one, to ensure non-dup // of IDs unset($formValues[$this->primaryKey]); // Create new record... $SQL = arrayToSQLInsert($this->tableName, $formValues); $wpdb->query($SQL); // ...then get the newly inserted ID so that we can update, without inserting again. $this->primaryKeyValue = $wpdb->insert_id; // DJH 2013-12-03 - Moved to below //$this->formObj->setDefaultValues(array($this->primaryKey => $this->primaryKeyValue)); $this->messages = $this->showMessage($this->msg_record_created); // Update the locally stored details $this->recordDetails = getRecordDetails($this->tableName, $this->primaryKey, $this->primaryKeyValue, ARRAY_A); // DJH 2013-12-03 - Added to use the stored details in the form. $this->formObj->setDefaultValues($this->recordDetails); // Function called when record has been created. if ($this->fn_record_created && function_exists($this->fn_record_created)) { call_user_func($this->fn_record_created, $this->recordDetails); } // Newly inserted ID. return $this->primaryKeyValue; } }
function getAndParseTimerTable($mac, &$s20Table) { $timerList = array(); $table = 3; $vflag = "02"; $tab3 = getTable($mac, $table, $vflag, $s20Table); $recs = getRecordsFromTable($tab3, $s20Table); for ($i = 0; $i < count($recs); $i++) { $timerList[$i] = getRecordDetails($recs[$i]); $timerList[$i]['recCode'] = substr($recs[$i], 2 * 2, 2 * 2); } usort($timerList, "cmpTimers"); $s20Table[$mac]['details'] = $timerList; return $timerList; }
/** * Get the certificate details for a user, or false if not found. * * @param String $accessID The unique access key for the certificate. * * @return Object The certificate details if they were found, or false if not found. */ function WPCW_certificate_getCertificateDetails_byAccessKey($accessKey) { // Validate for a MD5 hash if (!preg_match('/^[A-Za-z0-9]{32}$/', $accessKey)) { return false; } global $wpcwdb; return getRecordDetails($wpcwdb->certificates, 'cert_access_key', $accessKey); }
/** * Main method that parses POST and update details for given record ID * * @param int $recID */ function updateRecord($recID, $rtyID = null) { // Update the given record. // This is non-trivial: so that the versioning stuff (achive_*) works properly // we need to separate this into updates, inserts and deletes. // We get the currect record details and compare them against the post // if the details id is in the post[dtyID][dtlID] then compare the values $recID = intval($recID); // Check that the user has permissions to edit it. $res = mysql_query("select * from Records" . " left join sysUsrGrpLinks on ugl_GroupID=rec_OwnerUGrpID" . " left join defRecTypes on rty_ID=rec_RecTypeID" . " where rec_ID={$recID} and (! rec_OwnerUGrpID or rec_OwnerUGrpID=" . get_user_id() . " or ugl_UserID=" . get_user_id() . ")"); if (mysql_num_rows($res) == 0) { $res = mysql_query("select grp.ugr_Name from Records, " . USERS_DATABASE . ".sysUGrps grp where rec_ID={$recID} and grp.ugr_ID=rec_OwnerUGrpID"); $grpName = mysql_fetch_row($res); $grpName = $grpName[0]; print '({ error: "\\nSorry - you can\'t edit this record.\\nYou aren\'t in the ' . slash($grpName) . ' workgroup" })'; return; } $record = mysql_fetch_assoc($res); /*****DEBUG****/ error_log("save record dtls POST " . print_r($_POST, true)); // Upload any files submitted ... (doesn't have to take place right now, but may as well) uploadFiles(); //Artem: it does not work here - since we uploaded files at once // Get the existing records details and compare them to the incoming data $recDetails = getRecordDetails($recID); // find UPDATES - everything that is in current record and has a post value is treated as an update $recDetailUpdates = array(); /*****DEBUG****/ //error_log("save record dtls ".print_r($recDetails,true)); foreach ($recDetails as $dtyID => $dtlIDs) { $eltName = "type:" . $dtyID; if (!(@$_POST[$eltName] && is_array($_POST[$eltName]))) { // element wasn't in POST: ignore it -this could be a non-rectype detail unset($recDetails[$dtyID]); // remove from details so it's not deleted continue; } if (count($_POST[$eltName]) == 0) { // element was in POST but without content: values have been deleted client-side (need to be deleted in DB so leave POST) continue; } $bdInputHandler = getInputHandlerForType($dtyID); //returns the particular handler (processor) for given field type foreach ($dtlIDs as $dtlID => $val) { /*****DEBUG****/ //error_log(" in saveRecord details loop $dtyID, $dtlID, ".print_r($val,true)); $eltID = "bd:" . $dtlID; $val = @$_POST[$eltName][$eltID]; if (!$bdInputHandler->inputOK($val, $dtyID, $rtyID)) { /*****DEBUG****/ //error_log(" in saveRecord update details value check error $dtyID, $dtlID, ".print_r($val,true)); continue; // faulty input ... ignore } $toadd = $bdInputHandler->convertPostToMysql($val); /*****DEBUG****/ //error_log(" in saveRecord update details value converted from $val to $toadd"); if ($toadd == null) { continue; } $recDetailUpdates[$dtlID] = $toadd; $recDetailUpdates[$dtlID]["dtl_DetailTypeID"] = $dtyID; /* @TODO Since this function is utilized in (email)import we need to add verification of values according to detail type at the first for terms (enumeration field type) */ unset($_POST[$eltName][$eltID]); // remove data from post submission if (count($_POST[$eltName]) == 0) { // if nothing left in post dtyID then remove it also unset($_POST[$eltName]); } unset($recDetails[$dtyID][$dtlID]); // remove data from local reflection of the database } } /*****DEBUG****/ //error_log("save record dtls POST after updates removed ".print_r($_POST,true)); /*****DEBUG****/ //error_log("save record dtls after updates removed ".print_r($recDetails,true)); // find DELETES // Anything left in recDetails now represents recDetails rows that need to be deleted $bibDetailDeletes = array(); foreach ($recDetails as $dtyID => $dtlIDs) { foreach ($dtlIDs as $dtlID => $val) { array_push($bibDetailDeletes, $dtlID); } } // find INSERTS // Try to insert anything left in POST as new recDetails rows $bibDetailInserts = array(); /*****DEBUG****/ error_log(" in saveRecord checking for inserts _POST =" . print_r($_POST, true)); foreach ($_POST as $eltName => $bds) { // if not properly formatted or empty or an empty array then skip it if (!preg_match("/^type:\\d+\$/", $eltName) || !$_POST[$eltName] || count($_POST[$eltName]) == 0) { continue; } $dtyID = substr($eltName, 5); $bdInputHandler = getInputHandlerForType($dtyID); foreach ($bds as $eltID => $val) { if (!$bdInputHandler->inputOK($val, $dtyID, $rtyID)) { /*****DEBUG****/ //error_log(" in saveRecord insert details value check error for $eltName, $eltID, ".print_r($val,true)); continue; // faulty input ... ignore } $newBibDetail = $bdInputHandler->convertPostToMysql($val); $newBibDetail["dtl_DetailTypeID"] = $dtyID; $newBibDetail["dtl_RecID"] = $recID; /*****DEBUG****/ //error_log("new detail ".print_r($newBibDetail,true)); array_push($bibDetailInserts, $newBibDetail); unset($_POST[$eltName][$eltID]); // remove data from post submission } } // Anything left in POST now is stuff that we have no intention of inserting ... ignore it // We now have: // - $recDetailUpdates: an assoc. array of dtl_ID => column values to be updated in recDetails // - $bibDetailInserts: an array of column values to be inserted into recDetails // - $bibDetailDeletes: an array of dtl_ID values corresponding to rows to be deleted from recDetails // Commence versioning ... mysql_query("start transaction"); $recUpdates = array("rec_Modified" => array("now()"), "rec_FlagTemporary" => 0); $recUpdates["rec_ScratchPad"] = $_POST["notes"]; if (intval(@$_POST["rectype"])) { $recUpdates["rec_RecTypeID"] = intval($_POST["rectype"]); } if (array_key_exists("rec_url", $_POST)) { $recUpdates["rec_URL"] = $_POST["rec_url"]; } $owner = $record['rec_OwnerUGrpID']; if (is_admin() || is_admin('group', $owner) || $owner == get_user_id()) { // must be grpAdmin or record owner to changes ownership or visibility if (array_key_exists("rec_owner", $_POST)) { $recUpdates["rec_OwnerUGrpID"] = $_POST["rec_owner"]; } if (array_key_exists("rec_visibility", $_POST)) { $recUpdates["rec_NonOwnerVisibility"] = $_POST["rec_visibility"]; } else { if ($record['rec_NonOwnerVisibility'] == 'public' && HEURIST_PUBLIC_TO_PENDING) { $recUpdates["rec_NonOwnerVisibility"] = 'pending'; } } } /*****DEBUG****/ error_log(" in saveRecord update recUpdates = " . print_r($recUpdates, true)); mysql__update("Records", "rec_ID={$recID}", $recUpdates); $biblioUpdated = mysql_affected_rows() > 0 ? true : false; if (mysql_error()) { error_log("error rec update" . mysql_error()); } $updatedRowCount = 0; foreach ($recDetailUpdates as $bdID => $vals) { /*****DEBUG****/ error_log(" in saveRecord update details dtl_ID = {$bdID} value =" . print_r($vals, true)); mysql__update("recDetails", "dtl_ID={$bdID} and dtl_RecID={$recID}", $vals); if (mysql_affected_rows() > 0) { ++$updatedRowCount; } } if (mysql_error()) { error_log("error detail updates" . mysql_error()); } $insertedRowCount = 0; foreach ($bibDetailInserts as $vals) { /*****DEBUG****/ error_log(" in saveRecord insert details detail =" . print_r($vals, true)); mysql__insert("recDetails", $vals); if (mysql_affected_rows() > 0) { ++$insertedRowCount; } } if (mysql_error()) { error_log("error detail inserts" . mysql_error()); } $deletedRowCount = 0; if ($bibDetailDeletes) { /*****DEBUG****/ error_log(" in saveRecord delete details " . print_r($bibDetailDeletes, true)); mysql_query("delete from recDetails where dtl_ID in (" . join($bibDetailDeletes, ",") . ") and dtl_RecID={$recID}"); if (mysql_affected_rows() > 0) { $deletedRowCount = mysql_affected_rows(); } } if (mysql_error()) { error_log("error detail deletes" . mysql_error()); } // eliminate any duplicated lines $notesIn = explode("\n", str_replace("\r", "", $_POST["notes"])); $notesOut = ""; $notesMap = array(); for ($i = 0; $i < count($notesIn); ++$i) { if (!@$notesMap[$notesIn[$i]] || !$notesIn[$i]) { // preserve blank lines $notesOut .= $notesIn[$i] . "\n"; $notesMap[$notesIn[$i]] = true; } } $_POST["notes"] = preg_replace("/\n\n+/", "\n", $notesOut); if ($updatedRowCount > 0 || $insertedRowCount > 0 || $deletedRowCount > 0 || $biblioUpdated) { /* something changed: update the records title and commit all changes */ $title_check = check_title_mask2($record["rty_TitleMask"], $record["rec_RecTypeID"], true); if ($title_check != '') { $new_title = "Please go to Designer View > Essentials > Record types/fields and edit the title mask for this record type"; } else { $new_title = fill_title_mask($record["rty_TitleMask"], $record["rec_ID"], $record["rec_RecTypeID"]); } mysql_query("update Records\n set rec_Title = '" . addslashes($new_title) . "'\n where rec_ID = {$recID}"); mysql_query("commit"); // Update memcached's copy of record (if it is cached) updateCachedRecord($recID); return true; } else { /* nothing changed: rollback the transaction so we don't get false versioning */ mysql_query("rollback"); return false; } }
function doesRecordExistAlready($table, $field, $value) { return getRecordDetails($table, $field, $value); }
/** * Returns an array of all Map Documents for this database * * Document object: * ----------------------------------------- * - id: Record ID * - title: Record title * - rectypeID: Record type ID * ----------------------------------------- * - topLayer: Layer object * - layers: Array of Layer objects * - long: Longitude * - lat: Latitude * - minZoom: Minimum zoom * - maxZoom: Maximum zoom * - minorSpan: Initial minor span in degrees * - thumbnail: Thumbnail file * ------------------------------------------ * * @param mixed $system System reference */ function getMapDocuments($system, $recId) { //echo "getMapDocuments() called!"; global $recordQuery, $recordWhere; global $detailQuery; $documents = array(); if (defined('RT_MAP_DOCUMENT') && RT_MAP_DOCUMENT > 0) { // Select all Map Document types $query = $recordQuery . " WHERE " . $recordWhere . " and rec_RecTypeID=" . RT_MAP_DOCUMENT; //InOriginatingDB if ($recId) { $query = $query . ' and rec_ID=' . $recId; } $mysqli = $system->get_mysqli(); $res = $mysqli->query($query); if ($res) { // Loop through all rows while ($row = $res->fetch_assoc()) { // Document object containing the row values $document = getRecord($row); $document = getRecordDetails($system, $document); //print_r($document); array_push($documents, $document); } } } //print_r($documents); return $documents; }