Commit edd9830b authored by Carsten  Rose's avatar Carsten Rose
Browse files

Variables: unified naming of tt_content_uid.

AbstractBuildForm: implementd uniqe formId.
BuildFromBootstrap: Save-Button will receive 'formId'
Constants: new field TYPO3_TT_CONTENET_ID
BuildFromPlainTest: implemented test for getFormId.
EvaluateTest: fixed wrong assert test
parent 76a08c33
......@@ -7,7 +7,7 @@ General
* When qfq starts, it looks for the formname at:
1. Typo3 Bodytext Element,
2. For the 'SIP' ($_GET['s'])
3. $_GET variables 'form' and 'r' (=recordId)
3. $_GET variables 'form' and 'r' (=recordId) - the parameter 'form' has to be allowed in 'Permit URL Parameter'
* The active formname is stored in $this->store->setVar(SYSTEM_FORM, $formName, STORE_SYSTEM);
......@@ -45,7 +45,7 @@ SYSTEM_FORM_ELEMENT_COLUMN = 'formElementColumn'; // '<columnname of current pro
Stores
======
* Get submitted POST variables by
* Retrieve 'get' or 'post' variables by:
[src] $values = $this->store->getStore(STORE_CLIENT)
......
......@@ -35,6 +35,8 @@ abstract class AbstractBuildForm {
protected $pattern = array();
protected $wrap = array();
private $formId = null;
public function __construct(array $formSpec, array $feSpecAction, array $feSpecNative) {
$this->formSpec = $formSpec;
$this->feSpecAction = $feSpecAction;
......@@ -42,6 +44,7 @@ abstract class AbstractBuildForm {
$this->store = Store::getInstance();
$this->db = new Database();
$this->evaluate = new Evaluate($this->store, $this->db);
// $sip = $this->store->getVar(CLIENT_SIP, STORE_CLIENT);
// render mode specific
......@@ -176,7 +179,7 @@ abstract class AbstractBuildForm {
//TODO: ttconetn id eintragen
// $attribute['id'] = $this->store->getVar(STORE_TYPO3,'1234');
$attribute['id'] = 1234;
$attribute['id'] = $this->getFormId();
$attribute['method'] = 'post';
$attribute['action'] = $this->getActionUrl();
$attribute['target'] = '_top';
......@@ -187,6 +190,16 @@ abstract class AbstractBuildForm {
return $attribute;
}
/**
* @return string
*/
public function getFormId() {
if ($this->formId === null) {
$this->formId = uniqid('qfq-form-');
}
return $this->formId;
}
/**
* Builds the HTML 'form'-tag inlcuding all attributes and target.
*
......
......@@ -208,6 +208,8 @@ BUTTONS;
$html = '';
$html .= $this->builtNewSip();
$formId = $this->getFormId();
// TODO: bootstrap. See BuildFormTable.tail()
$html .= '</div> <!--class="tab-content" -->'; // <div class="tab-content">
......@@ -225,7 +227,7 @@ BUTTONS;
$("#save-button").click(function() {
$.post("typo3conf/ext/qfq/qfq/api/save.php_", $("#1234").serialize())
$.post("typo3conf/ext/qfq/qfq/api/save.php_", $("#$formId").serialize())
.done(function() {
alert("success");
})
......
......@@ -182,7 +182,7 @@ const TYPO3_DEBUG_SHOW_STACK = 'debugShowStack';
const TYPO3_FE_USER = 'feUser';
const TYPO3_FE_USER_UID = 'feUserUid';
const TYPO3_FE_USER_GROUP = 'feUserGroup';
const TYPO3_TT_CONTENT_UID = 'ttcontentUid';
// System
const SYSTEM_DBUSER = 'DBUSER';
const SYSTEM_DBSERVER = 'DBSERVER';
......
......@@ -104,6 +104,7 @@ class QuickFormQuery {
$bodytext = $this->t3data['bodytext'];
$this->store = Store::getInstance($bodytext, $phpUnit);
$this->store->setVar(TYPO3_TT_CONTENT_UID, (isset($t3data['uid'])) ? $t3data['uid'] : 0, STORE_TYPO3);
$this->db = new Database();
$this->eval = new Evaluate($this->store, $this->db);
}
......
......@@ -36,10 +36,10 @@ class Variables {
/**
* @param int $tmp_ttcontent_uid
*/
public function __construct($tmp_ttcontent_uid = 0) {
public function __construct($tt_content_uid = 0) {
// specified once during initialisation.
$this->tt_content_uid = $tmp_ttcontent_uid;
$this->tt_content_uid = $tt_content_uid;
}
......@@ -88,15 +88,25 @@ class Variables {
$arr["REMOTE_ADDR"] = $_SERVER["REMOTE_ADDR"];
$arr["HTTP_HOST"] = $_SERVER["HTTP_HOST"];
$arr["REQUEST_URI"] = $_SERVER["REQUEST_URI"];
$arr["fe_user_uid"] = $GLOBALS["TSFE"]->fe_user->user["uid"] ?: '-';
$arr["fe_user"] = $GLOBALS["TSFE"]->fe_user->user["username"] ?: '-';
$arr["be_user_uid"] = $GLOBALS['BE_USER']->user["uid"] ?: '-';
if (isset($GLOBALS["TSFE"]->fe_user)) {
$arr["fe_user_uid"] = $GLOBALS["TSFE"]->fe_user->user["uid"] ?: '-';
$arr["fe_user"] = $GLOBALS["TSFE"]->fe_user->user["username"] ?: '-';
} else {
$arr["fe_user_uid"] = '-';
$arr["fe_user"] = '-';
}
$arr["be_user_uid"] = (isset($GLOBALS['BE_USER'])) ? $GLOBALS['BE_USER']->user["uid"] : '-';
$arr["page_id"] = $GLOBALS["TSFE"]->id;
$arr["page_type"] = $GLOBALS["TSFE"]->type;
$arr["page_language_uid"] = $GLOBALS["TSFE"]->sys_language_uid;
$arr["ttcontent_uid"] = $this->tt_content_uid;
$protocol = (!$_SERVER["HTTPS"] || $_SERVER["HTTPS"] == "off") ? "http" : "https";
$arr["url"] = $protocol . "://" . $arr["HTTP_HOST"];
$protocol = 'http';
if (isset($_SERVER['HTTPS'])) {
if ($_SERVER["HTTPS"] != "off")
$protocol = 'https';
}
$arr["url"] = $protocol . "://" . $_SERVER["HTTP_HOST"];
if ($_SERVER["SERVER_PORT"] != 80)
$arr["url"] .= ":" . $_SERVER["SERVER_PORT"];
$arr["url"] .= $arr["REQUEST_URI"];
......@@ -105,7 +115,8 @@ class Variables {
// database aliases can be used in form sql queries (e.g. select * from "~global.t3_name".fe_users...)
// localconf can be used to configure an application
$tmp = array();
$this->linearizeArray($GLOBALS['TYPO3_CONF_VARS'][FORMREPORT], $tmp);
if (isset($GLOBALS['TYPO3_CONF_VARS']))
$this->linearizeArray($GLOBALS['TYPO3_CONF_VARS'][FORMREPORT], $tmp);
// remove anything that contains "_password" "_username" in the key to prevent the webmaster from doing something stupid
foreach ($tmp as $key => $value) {
......
......@@ -19,6 +19,20 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
$this->assertEquals(FORM_ELEMENTS_NATIVE, $build->getProcessFilter());
}
/**
*
*/
public function testGetFormId() {
$build = new \qfq\BuildFormPlain(array(), array(), array());
$formId1 = $build->getFormId();
$this->assertRegExp('/qfq-form-[0-9a-f]{13}/', $formId1);
$formId2 = $build->getFormId();
$this->assertEquals($formId1, $formId2);
}
public function testWrapItem() {
$build = new \qfq\BuildFormPlain(array(), array(), array());
......@@ -390,7 +404,7 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
$GLOBALS["TSFE"] = new FakeTSFE();
$this->form = new \qfq\QuickFormQuery(['bodytext' => "form=form\nr=3"], true);
$this->form = new \qfq\QuickFormQuery(['bodytext' => "form=form\nr=3", 'uid' => 1234], true);
// this is necessary to initialize SIP
$content = $this->form->process();
}
......@@ -400,5 +414,10 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
class FakeTSFE {
public $id = 1;
public $type = 1;
public $sys_language_uid = 1;
}
......@@ -66,7 +66,7 @@ class EvaluateTest extends \AbstractDatabaseTest {
'name' => 'Smith'
],
];
$this->assertSame($expected, $eval->parse('{{!SELECT id, name FROM Person WHERE id < 3 ORDER BY id}}'));
$this->assertEquals($expected, $eval->parse('{{!SELECT id, name FROM Person WHERE id < 3 ORDER BY id}}'));
// INSERT: Use eval() to write a record
$eval->parse('{{INSERT INTO Person (name, firstname) VALUES (\'Sinatra\', \'Frank\')}}');
......
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