Commit 35a053b4 authored by Carsten  Rose's avatar Carsten Rose
Browse files

AbstractBuildForm.php, BuildFormBootstrap.php: split buildRecordHashMd5 in two functions.

parent 360de0a6
...@@ -181,11 +181,18 @@ abstract class AbstractBuildForm { ...@@ -181,11 +181,18 @@ abstract class AbstractBuildForm {
$htmlElements = $this->elements($recordId, $filter, 0, $json, $modeCollectFe, $htmlElementNameIdZero, $storeUse, $mode); $htmlElements = $this->elements($recordId, $filter, 0, $json, $modeCollectFe, $htmlElementNameIdZero, $storeUse, $mode);
if ($mode === FORM_SAVE && $recordId != 0) { if ($mode === FORM_SAVE && $recordId != 0) {
$record = $this->db->sql("SELECT * FROM " . $this->formSpec[F_TABLE_NAME] . " WHERE id=?", ROW_EXPECT_1, [$recordId], "Record to load not found."); // $json[] = [API_ELEMENT_UPDATE => [DIRTY_RECORD_HASH_MD5 => [API_ELEMENT_ATTRIBUTE => ['value' => $newMd5]]]];
$newMd5 = OnArray::getMd5($record);
$json[] = [API_ELEMENT_UPDATE => [DIRTY_RECORD_HASH_MD5 => [API_ELEMENT_ATTRIBUTE => ['value' => $newMd5]]]];
// $json[] = [API_ELEMENT_UPDATE => [DIRTY_RECORD_HASH_MD5 => ['value' => $newMd5]]]; // $json[] = [API_ELEMENT_UPDATE => [DIRTY_RECORD_HASH_MD5 => ['value' => $newMd5]]];
// $json[DIRTY_RECORD_HASH_MD5][API_ELEMENT_UPDATE][DIRTY_RECORD_HASH_MD5][API_ELEMENT_ATTRIBUTE]['value'] = $newMd5;
// element-update: with 'content'
// $inputMd5 = $this->buildInputRecordHashMd5(false);
// $json[][API_ELEMENT_UPDATE][DIRTY_RECORD_HASH_MD5_SPAN][API_ELEMENT_CONTENT] = $inputMd5;
// element-update: with 'value'
$recordId = $this->store->getVar(SIP_RECORD_ID, STORE_SIP . STORE_ZERO);
$md5 = $this->buildRecordHashMd5($this->formSpec[F_TABLE_NAME], $recordId);
$json[][API_ELEMENT_UPDATE][DIRTY_RECORD_HASH_MD5][API_ELEMENT_ATTRIBUTE]['value'] = $md5;
} }
} }
...@@ -284,23 +291,47 @@ abstract class AbstractBuildForm { ...@@ -284,23 +291,47 @@ abstract class AbstractBuildForm {
$honeypot = $this->getHoneypotVars(); $honeypot = $this->getHoneypotVars();
$md5 = $this->buildRecordHashMd5(); $md5 = $this->buildInputRecordHashMd5();
return '<form ' . OnArray::toString($attribute, '=', ' ', "'") . '>' . $honeypot . $md5; return '<form ' . OnArray::toString($attribute, '=', ' ', "'") . '>' . $honeypot . $md5;
} }
/** /**
* Build MD5 from the current record. Return HTML Input element. * Build MD5 from the current record. Return HTML Input element.
* @param bool $flagWithSpan
* @return string
* @throws \qfq\CodeException
* @throws \qfq\DbException
*/ */
public function buildRecordHashMd5() { public function buildInputRecordHashMd5($flagWithSpan = true) {
$record = array();
$recordId = $this->store->getVar(SIP_RECORD_ID, STORE_SIP . STORE_ZERO); $recordId = $this->store->getVar(SIP_RECORD_ID, STORE_SIP . STORE_ZERO);
$md5 = $this->buildRecordHashMd5($this->formSpec[F_TABLE_NAME], $recordId);
$data = "<input id='" . DIRTY_RECORD_HASH_MD5 . "' name='" . DIRTY_RECORD_HASH_MD5 . "' type='hidden' value='$md5'>";
if ($flagWithSpan) {
$data = Support::wrapTag('<span id="' . DIRTY_RECORD_HASH_MD5_SPAN . '">', $data);
}
return $data;
}
/**
* @param $tableName
* @param $recordId
* @return string
* @throws \qfq\CodeException
* @throws \qfq\DbException
*/
public function buildRecordHashMd5($tableName, $recordId){
$record = array();
if ($recordId != 0) { if ($recordId != 0) {
$record = $this->db->sql("SELECT * FROM " . $this->formSpec[F_TABLE_NAME] . " WHERE id=?", ROW_EXPECT_1, [$recordId], "Record to load not found."); $record = $this->db->sql("SELECT * FROM $tableName WHERE id=?", ROW_EXPECT_1, [$recordId], "Record to load not found.");
} }
return "<input id='" . DIRTY_RECORD_HASH_MD5 . "' name='" . DIRTY_RECORD_HASH_MD5 . "' type='hidden' value='" . OnArray::getMd5($record) . "'>"; return OnArray::getMd5($record);
} }
/** /**
......
...@@ -445,7 +445,7 @@ class BuildFormBootstrap extends AbstractBuildForm { ...@@ -445,7 +445,7 @@ class BuildFormBootstrap extends AbstractBuildForm {
} }
$honeypot = $this->getHoneypotVars(); $honeypot = $this->getHoneypotVars();
$md5 = $this->buildRecordHashMd5(); $md5 = $this->buildInputRecordHashMd5();
return '<form ' . OnArray::toString($attribute, '=', ' ', "'") . '>' . $honeypot . $md5; return '<form ' . OnArray::toString($attribute, '=', ' ', "'") . '>' . $honeypot . $md5;
} }
......
...@@ -1122,6 +1122,7 @@ const DIRTY_EXPIRE = 'expire'; ...@@ -1122,6 +1122,7 @@ const DIRTY_EXPIRE = 'expire';
const DIRTY_TABLE_NAME = 'tableName'; const DIRTY_TABLE_NAME = 'tableName';
const DIRTY_RECORD_ID = 'recordId'; const DIRTY_RECORD_ID = 'recordId';
const DIRTY_RECORD_HASH_MD5 = 'recordHashMd5'; const DIRTY_RECORD_HASH_MD5 = 'recordHashMd5';
const DIRTY_RECORD_HASH_MD5_SPAN = 'recordHashMd5Span';
const DIRTY_REMOTE_ADDRESS = 'remoteAddress'; const DIRTY_REMOTE_ADDRESS = 'remoteAddress';
const DIRTY_API_ACTION = 'action'; // Name of parameter in API call of dirty.php?action=...&s=... const DIRTY_API_ACTION = 'action'; // Name of parameter in API call of dirty.php?action=...&s=...
const DIRTY_API_ACTION_LOCK = 'lock'; const DIRTY_API_ACTION_LOCK = 'lock';
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment