diff --git a/extension/Documentation/Manual.rst b/extension/Documentation/Manual.rst index 5b9f7dfed374c232e11439b21c775388e4853f62..353e8e9ea3f7bccee6bcf629c9283d38a50bfd5d 100644 --- a/extension/Documentation/Manual.rst +++ b/extension/Documentation/Manual.rst @@ -2048,7 +2048,7 @@ The CLIENT `submit_reason` shows the user action: Example forwardPage ^^^^^^^^^^^^^^^^^^^ -* `{{SELECT IF('{{formModeGlobal:S:anumx}}'='requiredOff', 'no', 'client') }}` +* `{{SELECT IF('{{formModeGlobal:S:alnumx}}'='requiredOff', 'no', 'client') }}` * `{{SELECT IF('{{submit_reason:CE:alnumx}}'='save', 'no', 'url'), '|http://example.com' }}` Type: combined dynamic mode & URL/page @@ -2124,7 +2124,8 @@ Parameter +-----------------------------+--------+----------------------------------------------------------------------------------------------------------+ | submitButtonText | string | Show a save button at the bottom of the form, with <submitButtonText> . See `submitButtonText`_. | +-----------------------------+--------+----------------------------------------------------------------------------------------------------------+ -| saveButtonActive | - | Make the 'save'-button active on *Form* load (instead of waiting for the first user change). | +| saveButtonActive | - | 0: off, 1: Make the 'save'-button active on *Form* load (instead of waiting for the first user change). | +| | | The save button is still 'gray' (record not dirty), but the user can click 'save'. | +-----------------------------+--------+----------------------------------------------------------------------------------------------------------+ | saveButtonText | string | Overwrite default from configuration_ | +-----------------------------+--------+----------------------------------------------------------------------------------------------------------+ diff --git a/extension/qfq/api/delete.php b/extension/qfq/api/delete.php index 5b75fea990db57057c6fdd512c9514cdcecc0c66..d1bfcc37d169a65a9becb6d93ebe4d8a5be27b18 100644 --- a/extension/qfq/api/delete.php +++ b/extension/qfq/api/delete.php @@ -79,13 +79,14 @@ try { $answer = $qfq->delete(); // in case everything is fine, an empty string is returned. Else an Array. - $flagSuccess = ($answer == ''); + $flagSuccess = ($answer === ''); $targetUrl = Store::getVar(SIP_TARGET_URL, STORE_SIP); $modeAnswer = Store::getVar(SIP_MODE_ANSWER, STORE_SIP); switch ($modeAnswer) { case MODE_JSON: + $answer = array(); if ($flagSuccess) { $answer[API_MESSAGE] = 'Deleted'; $answer[API_REDIRECT] = API_ANSWER_REDIRECT_CLIENT; diff --git a/extension/qfq/api/draganddrop.php b/extension/qfq/api/draganddrop.php new file mode 100644 index 0000000000000000000000000000000000000000..f5e57c466ef0872c8f9552ea5f6b3295d9811979 --- /dev/null +++ b/extension/qfq/api/draganddrop.php @@ -0,0 +1,86 @@ +<?php +/** + * Created by PhpStorm. + * User: ep + * Date: 12/23/15 + * Time: 6:17 PM + */ + +namespace qfq; + +use qfq; + +require_once(__DIR__ . '/../qfq/store/Store.php'); +require_once(__DIR__ . '/../qfq/Constants.php'); +require_once(__DIR__ . '/../qfq/QuickFormQuery.php'); + + +/** + * Return JSON encoded answer + * + * status: success|error + * message: <message> + * redirect: client|url|no + * redirect-url: <url> + * field-name: <field name> + * field-message: <message> + * form-data: [ fieldname1 => value1, fieldname2 => value2, ... ] + * form-control: [ fieldname1 => status1, fieldname2 => status2, ... ] status: show|hide, enabled|disabled, + * readonly|readwrite + * + * Description: + * + * Save successful. Button 'close', 'new'. Form.forward: 'auto'. Client logic decide to redirect or not. Show message + * if no redirect. status = 'success' message = <message> redirect = 'client' + * + * Save successful. Button 'close': Form.forward: 'page'. Client redirect to url. + * status = 'success' + * message = <message> + * redirect = 'url' + * redirect-url = <URL> + * + * Save failed: Button: any. Show message and set 'alert' on _optional_ specified form element. Bring 'pill' of + * specified form element to front. status = 'error' message = <message> redirect = 'no' Optional: field-name = <field + * name> field-message = <message appearing as tooltip (or similar) near the form element> + */ + +$answer = array(); + +$answer[API_REDIRECT] = API_ANSWER_REDIRECT_NO; +$answer[API_STATUS] = API_ANSWER_STATUS_ERROR; +$answer[API_MESSAGE] = ''; + +try { + $qfq = new QuickFormQuery(['bodytext' => '']); + + $data = $qfq->dragAndDrop(); + +// $answer[API_REDIRECT] = $qfq->getForwardMode($answer[API_REDIRECT_URL]); + $answer[API_STATUS] = API_ANSWER_STATUS_SUCCESS; + $answer[API_MESSAGE] = 'load: success'; + $answer[API_FORM_UPDATE] = $data[API_FORM_UPDATE]; + $answer[API_ELEMENT_UPDATE] = $data[API_ELEMENT_UPDATE]; +// unset($answer[API_FORM_UPDATE][API_ELEMENT_UPDATE]); + +} catch (qfq\UserFormException $e) { + $answer[API_MESSAGE] = $e->formatMessage(); + + $val = Store::getVar(SYSTEM_FORM_ELEMENT, STORE_SYSTEM); + if ($val !== false) + $answer[API_FIELD_NAME] = $val; + + $val = Store::getVar(SYSTEM_FORM_ELEMENT_MESSAGE, STORE_SYSTEM); + if ($val !== false) + $answer[API_FIELD_MESSAGE] = $val; + +} catch (qfq\CodeException $e) { + $answer[API_MESSAGE] = $e->formatMessage(); +} catch (qfq\DbException $e) { + $answer[API_MESSAGE] = $e->formatMessage(); +} catch (\Exception $e) { + $answer[API_MESSAGE] = "Generic Exception: " . $e->getMessage(); +} + +header("Content-Type: application/json"); +echo json_encode($answer); + diff --git a/extension/qfq/qfq/AbstractBuildForm.php b/extension/qfq/qfq/AbstractBuildForm.php index 567e30abf00d14f82bab928962d35643723a2249..6dc85c838d5026dbce982f9eef30a0b89d0ff66f 100644 --- a/extension/qfq/qfq/AbstractBuildForm.php +++ b/extension/qfq/qfq/AbstractBuildForm.php @@ -86,8 +86,6 @@ abstract class AbstractBuildForm { * @param array $feSpecAction * @param array $feSpecNative * @param array $db - * @throws CodeException - * @throws UserFormException */ public function __construct(array $formSpec, array $feSpecAction, array $feSpecNative, array $db = null) { $this->formSpec = $formSpec; @@ -174,8 +172,6 @@ abstract class AbstractBuildForm { * @param array $latestFeSpecNative * @return array|string $mode=LOAD_FORM: The whole form as HTML, $mode=FORM_UPDATE: array of all * formElement.dynamicUpdate-yes values/states - * @throws CodeException - * @throws DbException * @throws UserFormException */ public function process($mode, $htmlElementNameIdZero = false, $latestFeSpecNative = array()) { @@ -251,9 +247,6 @@ abstract class AbstractBuildForm { * * @param string $mode * @return string - * @throws CodeException - * @throws DbException - * @throws UserFormException */ public function head($mode = FORM_LOAD) { $html = ''; @@ -283,8 +276,6 @@ abstract class AbstractBuildForm { * * @return string String: <a href="?pageId&sip=....">Edit</a> <small>[sip:..., r:..., urlparam:..., * ...]</small> - * @throws CodeException - * @throws UserFormException */ public function createFormEditorUrl($form, $recordId, array $param = array()) { @@ -330,8 +321,6 @@ abstract class AbstractBuildForm { * Returns '<form ...>'-tag with various attributes. * * @return string - * @throws CodeException - * @throws DbException */ public function getFormTag() { $md5 = ''; @@ -349,8 +338,6 @@ abstract class AbstractBuildForm { * Build MD5 from the current record. Return HTML Input element. * * @return string - * @throws \qfq\CodeException - * @throws \qfq\DbException */ public function buildInputRecordHashMd5() { @@ -370,8 +357,6 @@ abstract class AbstractBuildForm { * @param $recordId * * @return string - * @throws \qfq\CodeException - * @throws \qfq\DbException */ public function buildRecordHashMd5($tableName, $recordId) { $record = array(); @@ -387,7 +372,6 @@ abstract class AbstractBuildForm { * Create HTML Input vars to detect bot automatic filling of forms. * * @return string - * @throws CodeException */ public function getHoneypotVars() { $html = ''; @@ -412,8 +396,6 @@ abstract class AbstractBuildForm { * Build an assoc array with standard form attributes. * * @return array - * @throws CodeException - * @throws DbException */ public function getFormTagAttributes() { @@ -460,8 +442,6 @@ abstract class AbstractBuildForm { * See: https://www.w3.org/wiki/HTML/Elements/form#HTML_Attributes * * @return string - * @throws CodeException - * @throws DbException */ public function getEncType() { @@ -477,8 +457,6 @@ abstract class AbstractBuildForm { * @param array|string $value * * @return array|string - * @throws CodeException - * @throws UserFormException */ private function processReportSyntax($value) { @@ -524,9 +502,6 @@ abstract class AbstractBuildForm { * @param string $mode FORM_LOAD | FORM_UPDATE | FORM_SAVE * * @return string - * @throws CodeException - * @throws DbException - * @throws \qfq\UserFormException */ public function elements($recordId, $filter = FORM_ELEMENTS_NATIVE, $feIdContainer = 0, array &$json, $modeCollectFe = FLAG_DYNAMIC_UPDATE, $htmlElementNameIdZero = false, @@ -697,8 +672,6 @@ abstract class AbstractBuildForm { * @param array $formElement * * @return array - * @throws CodeException - * @throws UserFormException */ private function prepareFillStoreFireLdap(array $formElement) { @@ -793,8 +766,7 @@ abstract class AbstractBuildForm { * Copy a subset of current STORE_TYPO3 variables to SIP. Set a hidden form field to submit the assigned SIP to * save/update. * - * @throws CodeException - * @throws UserFormException + * @return string */ private function prepareT3VarsForSave() { @@ -830,8 +802,6 @@ abstract class AbstractBuildForm { * Get all elements from STORE_ADDITIONAL_FORM_ELEMENTS and return them as a string. * * @return string - * @throws CodeException - * @throws \qfq\UserFormException */ private function buildAdditionalFormElements() { @@ -846,8 +816,6 @@ abstract class AbstractBuildForm { * @param array $json * * @return string <input type='hidden' name='s' value='<sip>'> - * @throws CodeException - * @throws \qfq\UserFormException */ public function buildHiddenSip(array &$json) { @@ -878,8 +846,6 @@ abstract class AbstractBuildForm { * @param array $formElement * * @return array - * @throws CodeException - * @throws UserFormException */ private function getFormElementForJson($htmlFormElementName, $value, array $formElement) { @@ -955,7 +921,6 @@ abstract class AbstractBuildForm { * @param array $feMode * * @return array - * @throws UserFormException */ private function getJsonFeMode($feMode) { @@ -1005,7 +970,6 @@ abstract class AbstractBuildForm { * @param string $addClass * * @return string - * @throws CodeException */ public function buildLabel($htmlFormElementName, $label, $addClass = '') { $attributes = Support::doAttribute('for', $htmlFormElementName); @@ -1021,8 +985,6 @@ abstract class AbstractBuildForm { * * @param $toolTipNew * @return string - * @throws CodeException - * @throws UserFormException */ public function deriveNewRecordUrlFromExistingSip(&$toolTipNew) { @@ -1086,8 +1048,6 @@ abstract class AbstractBuildForm { * @param string $mode FORM_LOAD | FORM_UPDATE | FORM_SAVE * * @return string complete rendered HTML input element. - * @throws CodeException - * @throws UserFormException */ public function buildInput(array $formElement, $htmlFormElementName, $value, array &$json, $mode = FORM_LOAD) { $textarea = ''; @@ -1232,7 +1192,6 @@ abstract class AbstractBuildForm { * @param array $formElement * * @return string - * @throws CodeException * @throws UserFormException */ private function typeAheadBuildParam(array &$formElement) { @@ -1338,7 +1297,6 @@ abstract class AbstractBuildForm { * @param bool $flagOmitEmpty * * @return string - * @throws CodeException */ private function getAttributeList(array $formElement, array $attributeList, $flagOmitEmpty = true) { $attribute = ''; @@ -1357,7 +1315,6 @@ abstract class AbstractBuildForm { * * @param bool $cssDisable * @return string - * @throws CodeException * @throws UserFormException */ private function getAttributeFeMode($feMode, $cssDisable = true) { @@ -1414,8 +1371,7 @@ abstract class AbstractBuildForm { * @param string $mode FORM_LOAD | FORM_UPDATE | FORM_SAVE* * * @return string - * @throws CodeException - * @throws \qfq\UserFormException + * @throws UserFormException */ public function buildCheckbox(array $formElement, $htmlFormElementName, $value, array &$json, $mode = FORM_LOAD) { $itemKey = array(); @@ -1470,8 +1426,7 @@ abstract class AbstractBuildForm { * @param array $itemKey * @param array $itemValue * - * @throws CodeException - * @throws \qfq\UserFormException + * @throws UserFormException */ public function getKeyValueListFromSqlEnumSpec(array $formElement, array &$itemKey, array &$itemValue) { $fieldType = ''; @@ -1543,7 +1498,6 @@ abstract class AbstractBuildForm { * @param string $fieldType * * @return array - * @throws CodeException * @throws UserFormException */ private function getItemsForEnumOrSet($column, &$fieldType) { @@ -1589,7 +1543,6 @@ abstract class AbstractBuildForm { * @param array $itemKey * @param array $formElement * - * @throws CodeException * @throws UserFormException */ private function prepareCheckboxCheckedUncheckedValue(array $itemKey, array &$formElement) { @@ -1630,8 +1583,6 @@ abstract class AbstractBuildForm { * @param string $mode FORM_LOAD | FORM_UPDATE | FORM_SAVE * * @return string - * @throws CodeException - * @throws UserFormException */ public function buildCheckboxSingle(array $formElement, $htmlFormElementName, $attribute, $value, array &$json, $mode = FORM_LOAD) { @@ -1665,8 +1616,6 @@ abstract class AbstractBuildForm { * @param array $json * * @return string - * @throws CodeException - * @throws UserFormException */ public function constructCheckboxSingleButton(array $formElement, $htmlFormElementName, $attribute, $value, array &$json) { $html = ''; @@ -1725,8 +1674,6 @@ abstract class AbstractBuildForm { * @param array $json * * @return string - * @throws CodeException - * @throws UserFormException */ public function constructCheckboxSinglePlain(array $formElement, $htmlFormElementName, $attribute, $value, array &$json) { $html = ''; @@ -1775,8 +1722,6 @@ abstract class AbstractBuildForm { * @param array $itemValue * @param array $json * @return string - * @throws CodeException - * @throws UserFormException */ public function buildCheckboxMulti(array $formElement, $htmlFormElementName, $attributeBase, $value, array $itemKey, array $itemValue, array &$json) { @@ -1797,8 +1742,6 @@ abstract class AbstractBuildForm { * @param string $htmlFormElementName * @param string $htmlHidden * - * @throws CodeException - * @throws UserFormException */ private function fillStoreAdditionalFormElementsCheckboxHidden(array $formElement, $htmlFormElementName, $htmlHidden) { @@ -1828,8 +1771,6 @@ abstract class AbstractBuildForm { * @param array $json * * @return string - * @throws CodeException - * @throws UserFormException */ public function constructCheckboxMultiButton(array $formElement, $htmlFormElementName, $attributeBase, $value, array $itemKey, array $itemValue, array &$json) { $json = array(); @@ -1901,8 +1842,6 @@ abstract class AbstractBuildForm { * @param array $json * * @return string - * @throws CodeException - * @throws UserFormException */ public function constructCheckboxMultiPlain(array $formElement, $htmlFormElementName, $attributeBase, $value, array $itemKey, array $itemValue, array &$json) { $json = array(); @@ -1991,14 +1930,14 @@ abstract class AbstractBuildForm { * @param string $mode FORM_LOAD | FORM_UPDATE | FORM_SAVE * * @return string - * @throws CodeException - * @throws \qfq\UserFormException */ public function buildExtra(array $formElement, $htmlFormElementName, $value, array &$json, $mode = FORM_LOAD) { if ($mode === FORM_LOAD) { $this->store->setVar($formElement[FE_NAME], $value, STORE_SIP, false); } + + return; } /** @@ -2015,8 +1954,6 @@ abstract class AbstractBuildForm { * @param string $mode FORM_LOAD | FORM_UPDATE | FORM_SAVE * * @return string - * @throws CodeException - * @throws \qfq\UserFormException */ public function buildRadio(array $formElement, $htmlFormElementName, $value, array &$json, $mode = FORM_LOAD) { @@ -2063,8 +2000,6 @@ abstract class AbstractBuildForm { * @param string $mode FORM_LOAD | FORM_UPDATE | FORM_SAVE * * @return string - * @throws CodeException - * @throws \qfq\UserFormException */ private function constructRadioButton(array $formElement, $htmlFormElementName, $value, array &$json, $mode = FORM_LOAD) { $itemKey = array(); @@ -2146,8 +2081,6 @@ abstract class AbstractBuildForm { * @param string $mode FORM_LOAD | FORM_UPDATE | FORM_SAVE * * @return string - * @throws CodeException - * @throws \qfq\UserFormException */ private function constructRadioPlain(array $formElement, $htmlFormElementName, $value, array &$json, $mode = FORM_LOAD) { $attributeBase = ''; @@ -2236,8 +2169,6 @@ abstract class AbstractBuildForm { * @param string $mode FORM_LOAD | FORM_UPDATE | FORM_SAVE * * @return mixed - * @throws CodeException - * @throws \qfq\UserFormException */ public function buildSelect(array $formElement, $htmlFormElementName, $value, array &$json, $mode = FORM_LOAD) { $itemKey = array(); @@ -2311,7 +2242,6 @@ abstract class AbstractBuildForm { * @param array $control Array with <th> column names / format. * * @return string - * @throws UserFormException */ private function subrecordHead($linkNew, $flagDelete, array $firstRow, array &$control) { @@ -2344,8 +2274,6 @@ abstract class AbstractBuildForm { * @param string $mode FORM_LOAD | FORM_UPDATE | FORM_SAVE * * @return string - * @throws CodeException - * @throws \qfq\UserFormException */ public function buildSubrecord(array $formElement, $htmlFormElementName, $value, array &$json, $mode = FORM_LOAD) { $rcText = false; @@ -2503,8 +2431,6 @@ abstract class AbstractBuildForm { * @param $toolTip * @param array $currentRow * @return string - * @throws CodeException - * @throws UserFormException */ private function createFormLink(array $formElement, $targetRecordId, array $record, $symbol, $toolTip, $currentRow = array()) { @@ -2572,8 +2498,6 @@ abstract class AbstractBuildForm { * @param string $formName * * @return string tableName for $formName - * @throws CodeException - * @throws DbException */ private function getFormTable($formName) { $row = $this->dbArray[$this->dbIndexQfq]->sql("SELECT " . F_TABLE_NAME . " FROM Form AS f WHERE f.name = ?", ROW_EXPECT_0_1, [$formName]); @@ -2604,7 +2528,6 @@ abstract class AbstractBuildForm { * @param array $titleRaw * * @return array - * @throws UserFormException */ private function getSubrecordColumnControl(array $titleRaw) { $control = array(); @@ -2682,9 +2605,6 @@ abstract class AbstractBuildForm { * @param string $columnValue * * @return string - * @throws CodeException - * @throws UserFormException - * @throws UserReportException */ private function renderCell(array $control, $columnName, $columnValue) { $link = null; @@ -2747,8 +2667,6 @@ abstract class AbstractBuildForm { * parameters. * * @return string String: "API_DIR/delete.php?sip=...." - * @throws CodeException - * @throws UserFormException */ public function createDeleteUrl($formName, $recordId, $mode = RETURN_URL) { @@ -2776,10 +2694,7 @@ abstract class AbstractBuildForm { * @param string $mode FORM_LOAD | FORM_UPDATE | FORM_SAVE * * @return string - * @throws CodeException - * @throws DbException * @throws UserFormException - * @throws UserReportException */ public function buildFile(array $formElement, $htmlFormElementName, $value, array &$json, $mode = FORM_LOAD) { $attribute = ''; @@ -2896,8 +2811,7 @@ abstract class AbstractBuildForm { * @param string $mode FORM_LOAD | FORM_UPDATE | FORM_SAVE * * @return string - * @throws CodeException - * @throws \qfq\UserFormException + * @throws UserFormException */ public function buildAnnotate(array $formElement, $htmlFormElementName, $value, array &$json, $mode = FORM_LOAD) { @@ -2949,8 +2863,7 @@ abstract class AbstractBuildForm { * @param string $mode FORM_LOAD | FORM_UPDATE | FORM_SAVE * * @return string - * @throws CodeException - * @throws \qfq\UserFormException + * @throws UserFormException */ public function buildImageCut(array $formElement, $htmlFormElementName, $value, array &$json, $mode = FORM_LOAD) { @@ -3017,8 +2930,6 @@ abstract class AbstractBuildForm { /** * @param string $pathFileName * @return string SIP encoded URL - * @throws CodeException - * @throws UserFormException */ private function fileToSipUrl($pathFileName) { $param[DOWNLOAD_MODE] = DOWNLOAD_MODE_FILE; @@ -3042,7 +2953,6 @@ abstract class AbstractBuildForm { * @param string $mode FORM_LOAD | FORM_UPDATE | FORM_SAVE * * @return string - * @throws CodeException * @throws UserFormException */ public function buildDateTime(array $formElement, $htmlFormElementName, $value, array &$json, $mode = FORM_LOAD) { @@ -3155,8 +3065,6 @@ abstract class AbstractBuildForm { * @param string $mode FORM_LOAD | FORM_UPDATE | FORM_SAVE * * @return string - * @throws CodeException - * @throws UserFormException */ public function buildDateJQW(array $formElement, $htmlFormElementName, $value, array &$json, $mode = FORM_LOAD) { $arrMinMax = null; @@ -3239,8 +3147,6 @@ abstract class AbstractBuildForm { * @param string $mode * * @return string - * @throws CodeException - * @throws UserFormException */ public function buildEditor(array $formElement, $htmlFormElementName, $value, array &$json, $mode = FORM_LOAD) { $attribute = ''; @@ -3391,8 +3297,6 @@ abstract class AbstractBuildForm { * * @param string $mode FORM_LOAD | FORM_UPDATE | FORM_SAVE * @return mixed - * @throws CodeException - * @throws UserFormException */ public function buildNote(array $formElement, $htmlFormElementName, $value, array &$json, $mode = FORM_LOAD) { @@ -3427,9 +3331,6 @@ abstract class AbstractBuildForm { * @param string $mode FORM_LOAD | FORM_UPDATE | FORM_SAVE * * @return mixed - * @throws CodeException - * @throws DbException - * @throws UserFormException */ public function buildFieldset(array $formElement, $htmlFormElementName, $value, array &$json, $mode = FORM_LOAD) { $attribute = ''; @@ -3496,9 +3397,6 @@ abstract class AbstractBuildForm { * @param string $mode FORM_LOAD | FORM_UPDATE | FORM_SAVE * * @return mixed - * @throws CodeException - * @throws DbException - * @throws UserFormException */ public function buildTemplateGroup(array $formElement, $htmlFormElementName, $value, array &$json, $mode = FORM_LOAD) { $attribute = ''; @@ -3611,9 +3509,6 @@ EOT; * @param array $json * * @return string - * @throws CodeException - * @throws DbException - * @throws UserFormException */ private function templateGroupCollectFilledElements($max, $htmlDelete, array &$json) { @@ -3696,7 +3591,6 @@ EOT; * Additional the maximum count of all select rows will be determined and returned. * * @return int max number of records in FormElement[FE_VALUE] over all FormElements. - * @throws UserFormException */ private function templateGroupDoValue() { diff --git a/extension/qfq/qfq/BodytextParser.php b/extension/qfq/qfq/BodytextParser.php index 3b66f6c8692f42c50d6205633415cec3084fe5b2..8190e442675f7c2cc653278ee099536f37bef58d 100644 --- a/extension/qfq/qfq/BodytextParser.php +++ b/extension/qfq/qfq/BodytextParser.php @@ -42,7 +42,7 @@ class BodytextParser { $bodytext = Support::decryptDoubleCurlyBraces($bodytext); if (strpos($bodytext, NESTING_TOKEN_OPEN) !== false) { - throw new \qfq\UserFormException("Missing close delimiter: $bodytext", ERROR_MISSING_CLOSE_DELIMITER); + throw new UserFormException("Missing close delimiter: $bodytext", ERROR_MISSING_CLOSE_DELIMITER); } return $bodytext; @@ -275,7 +275,7 @@ class BodytextParser { if ($posMatchOpen === false) { $result = $this->decryptNestingDelimeter($result, $nestingOpen, $nestingClose); - throw new \qfq\UserFormException("Missing open delimiter: $result", ERROR_MISSING_OPEN_DELIMITER); + throw new UserFormException("Missing open delimiter: $result", ERROR_MISSING_OPEN_DELIMITER); } $pre = substr($result, 0, $posMatchOpen); diff --git a/extension/qfq/qfq/BuildFormBootstrap.php b/extension/qfq/qfq/BuildFormBootstrap.php index 6d0ffa3aa3480e630c2c0609c6113b69753ce494..0a686799147e0d6012c59bf732b373e44f83aa12 100644 --- a/extension/qfq/qfq/BuildFormBootstrap.php +++ b/extension/qfq/qfq/BuildFormBootstrap.php @@ -240,6 +240,7 @@ class BuildFormBootstrap extends AbstractBuildForm { * * @return string * @throws CodeException + * @throws DbException * @throws UserFormException */ private function buildButtons() { @@ -519,7 +520,7 @@ class BuildFormBootstrap extends AbstractBuildForm { $attribute['class'] = 'form-horizontal'; $attribute['data-toggle'] = 'validator'; - if (isset($this->formSpec[F_SAVE_BUTTON_ACTIVE])) { + if (isset($this->formSpec[F_SAVE_BUTTON_ACTIVE]) && $this->formSpec[F_SAVE_BUTTON_ACTIVE]!='0') { $attribute[DATA_ENABLE_SAVE_BUTTON] = 'true'; } @@ -751,9 +752,9 @@ EOF; /** * Builds a fieldset * - * @param $formElement + * @param array $formElement * @param $elementHtml - * @return + * @return mixed */ public function buildRowFieldset(array $formElement, $elementHtml) { $html = $elementHtml; diff --git a/extension/qfq/qfq/Constants.php b/extension/qfq/qfq/Constants.php index b7d84ed492a81619d031b1755a838812125c4a3a..9a78fe60cd2a0c9514ba7635f0a26f355e49ca07 100644 --- a/extension/qfq/qfq/Constants.php +++ b/extension/qfq/qfq/Constants.php @@ -33,6 +33,7 @@ const FORM_LOAD = 'form_load'; const FORM_SAVE = 'form_save'; const FORM_UPDATE = 'form_update'; const FORM_DELETE = 'form_delete'; +const FORM_DRAG_AND_DROP = 'form_drag_and_drop'; const FORM_PERMISSION_SIP = 'sip'; const FORM_PERMISSION_LOGGED_IN = 'logged_id'; const FORM_PERMISSION_LOGGED_OUT = 'logged_out'; @@ -143,7 +144,7 @@ const ERROR_DEBUG = 1031; const ERROR_UNKNOWN_MODE = 1032; const ERROR_NOT_IMPLEMENTED = 1033; const ERROR_RESERVED_KEY_NAME = 1034; - +const ERROR_MISSING_FORM = 1035; const ERROR_UNKNOWN_FORWARD_MODE = 1036; const ERROR_MISSING_HIDDEN_FIELD_IN_SIP = 1038; @@ -851,6 +852,8 @@ const F_NEW_BUTTON_GLYPH_ICON = SYSTEM_NEW_BUTTON_GLYPH_ICON; const F_ENTER_AS_SUBMIT = SYSTEM_ENTER_AS_SUBMIT; +const F_DRAG_AND_DROP_ORDER_SQL = 'dragAndDropOrderSql'; + // FORM_ELEMENT_STATI const FE_MODE_SHOW = 'show'; const FE_MODE_READONLY = 'readonly'; diff --git a/extension/qfq/qfq/Delete.php b/extension/qfq/qfq/Delete.php index afd4ec52101ba9a08f6d96123fbc53dc66a1020a..70abc44f504aacfb002c4c220072db1914173807 100644 --- a/extension/qfq/qfq/Delete.php +++ b/extension/qfq/qfq/Delete.php @@ -32,6 +32,7 @@ class Delete { * @param bool $dbIndexData * @param bool $phpUnit * @throws CodeException + * @throws DbException * @throws UserFormException */ public function __construct($dbIndexData = false, $phpUnit = false) { diff --git a/extension/qfq/qfq/Evaluate.php b/extension/qfq/qfq/Evaluate.php index 6c1946c576cf0be551e2668e9f1016b0200e9f08..b29a27101aadbd1475977026aea2108a6b3cd00c 100644 --- a/extension/qfq/qfq/Evaluate.php +++ b/extension/qfq/qfq/Evaluate.php @@ -55,6 +55,7 @@ class Evaluate { * @param string $startDelimiter * @param string $endDelimiter * @throws CodeException + * @throws UserFormException */ public function __construct(Store $store, Database $db, $startDelimiter = '{{', $endDelimiter = '}}') { $this->store = $store; @@ -78,7 +79,10 @@ class Evaluate { * @param array $debugStack * * @return array + * @throws CodeException + * @throws DbException * @throws UserFormException + * @throws UserReportException */ public function parseArray($tokenArray, array $skip = array(), &$debugStack = array()) { $arr = array(); @@ -139,7 +143,7 @@ class Evaluate { $posMatchOpen = strrpos(substr($result, 0, $posFirstClose), $this->startDelimiter); if ($posMatchOpen === false) { - throw new \qfq\UserFormException("Missing open delimiter: $result", ERROR_MISSING_OPEN_DELIMITER); + throw new UserFormException("Missing open delimiter: $result", ERROR_MISSING_OPEN_DELIMITER); } $pre = substr($result, 0, $posMatchOpen); diff --git a/extension/qfq/qfq/QuickFormQuery.php b/extension/qfq/qfq/QuickFormQuery.php index f8be5100d9ddc654ec19c8c71341163ba6b43c09..87f91c84021fb3fb8d67520d030e2c54cc15de52 100644 --- a/extension/qfq/qfq/QuickFormQuery.php +++ b/extension/qfq/qfq/QuickFormQuery.php @@ -61,7 +61,8 @@ require_once(__DIR__ . '/form/Dirty.php'); * Class Qfq * @package qfq */ -class QuickFormQuery { +class QuickFormQuery +{ /** * @var \qfq\Store instantiated class @@ -122,9 +123,12 @@ class QuickFormQuery { * @param bool $phpUnit * * @throws CodeException + * @throws DbException * @throws UserFormException + * @throws UserReportException */ - public function __construct(array $t3data = array(), $phpUnit = false) { + public function __construct(array $t3data = array(), $phpUnit = false) + { $this->phpUnit = $phpUnit; @@ -193,7 +197,8 @@ class QuickFormQuery { * @throws CodeException * @throws UserFormException */ - public function getForwardMode() { + public function getForwardMode() + { $forwardPage = $this->formSpec[F_FORWARD_PAGE]; @@ -218,8 +223,10 @@ class QuickFormQuery { * @throws CodeException * @throws DbException * @throws UserFormException + * @throws UserReportException */ - public function process() { + public function process() + { $html = ''; if ($this->store->getVar(TYPO3_DEBUG_SHOW_BODY_TEXT, STORE_TYPO3) === 'yes') { @@ -246,7 +253,8 @@ class QuickFormQuery { /** * Determine the name of the language parameter field, which has to be taken to fill language specific defintions. */ - private function setParameterLanguageFieldName() { + private function setParameterLanguageFieldName() + { $typo3PageLanguage = $this->store->getVar(TYPO3_PAGE_LANGUAGE, STORE_TYPO3); if (empty($typo3PageLanguage)) { @@ -262,6 +270,7 @@ class QuickFormQuery { } } + /** * Process form. * $mode= @@ -276,13 +285,15 @@ class QuickFormQuery { * @throws CodeException * @throws DbException * @throws UserFormException + * @throws UserReportException */ - private function doForm($formMode) { + private function doForm($formMode) + { $data = ''; $foundInStore = ''; // Fill STORE_FORM - if ($formMode === FORM_UPDATE || $formMode === FORM_SAVE) { + if ($formMode === FORM_UPDATE || $formMode === FORM_SAVE || $formMode === FORM_DRAG_AND_DROP) { $fillStoreForm = new FillStoreForm(); $fillStoreForm->process($formMode); } @@ -291,9 +302,15 @@ class QuickFormQuery { $this->setParameterLanguageFieldName(); $formName = $this->loadFormSpecification($formMode, $recordId, $foundInStore); - if ($formName === false && $formMode !== FORM_DELETE) { - // No form found: do nothing - return ''; + if ($formName === false) { + switch ($formName) { + case FORM_DELETE: + break; + case FORM_DRAG_AND_DROP: + throw new CodeException('Missing form in SIP', ERROR_MISSING_FORM); + default: + return '';// No form found: do nothing + } } if ($formName !== false) { @@ -306,6 +323,7 @@ class QuickFormQuery { if ($table === false) { throw new UserFormException("No 'form' and no 'table' definition found.", ERROR_MISSING_VALUE); } + $sipFound = true; $this->formSpec[F_NAME] = ''; $this->formSpec[F_TABLE_NAME] = $table; @@ -472,6 +490,14 @@ class QuickFormQuery { } break; + case FORM_DRAG_AND_DROP: + $formAction->elements($recordId, $this->feSpecAction, FE_TYPE_BEFORE_LOAD); + + $draganddrop = new DragAndDrop(); + $draganddrop->process($this->formSpec[F_TABLE_NAME], $this->formSpec[F_DRAG_AND_DROP_ORDER_SQL]); + + $formAction->elements($recordId, $this->feSpecAction, FE_TYPE_AFTER_LOAD); + break; default: throw new CodeException("This statement should never be reached", ERROR_CODE_SHOULD_NOT_HAPPEN); @@ -502,9 +528,13 @@ class QuickFormQuery { * * @return bool TRUE if F_FORWARD_MODE = 'url..', else FALSE * + * @throws CodeException + * @throws DbException * @throws UserFormException + * @throws UserReportException */ - private function setForwardModePage() { + private function setForwardModePage() + { if ('url' != substr($this->formSpec[F_FORWARD_MODE], 0, 3)) { return false; @@ -560,8 +590,10 @@ class QuickFormQuery { * @throws CodeException * @throws DbException * @throws UserFormException + * @throws UserReportException */ - private function pasteClipboard($formId, FormAction $formAction) { + private function pasteClipboard($formId, FormAction $formAction) + { if (!$this->isPasteRecord()) { return; @@ -586,7 +618,8 @@ class QuickFormQuery { /** * @return bool true if there is at least one paste record, else false. */ - private function isPasteRecord() { + private function isPasteRecord() + { foreach ($this->feSpecAction as $formElement) { if ($formElement[FE_TYPE] == FE_TYPE_PASTE) { @@ -609,7 +642,8 @@ class QuickFormQuery { * @throws CodeException * @throws UserFormException */ - private function buildNSetReloadUrl(array $formSpec, $recordId) { + private function buildNSetReloadUrl(array $formSpec, $recordId) + { $formSpec[F_FORWARD_MODE] = API_ANSWER_REDIRECT_URL_SKIP_HISTORY; @@ -645,8 +679,10 @@ class QuickFormQuery { * @throws CodeException * @throws DbException * @throws UserFormException + * @throws UserReportException */ - private function loadFormSpecification($mode, $recordId, &$foundInStore = '') { + private function loadFormSpecification($mode, $recordId, &$foundInStore = '') + { // formName if (false === ($formName = $this->getFormName($mode, $foundInStore))) { @@ -755,7 +791,7 @@ class QuickFormQuery { case FORM_SAVE: case FORM_UPDATE: - $feSpecNative = $this->getNativeFormElements(SQL_FORM_ELEMENT_NATIVE_TG_COUNT, [$this->formSpec[F_ID]], $this->formSpec); + $feSpecNative = $this->getNativeFormElements(SQL_FORM_ELEMENT_NATIVE_TG_COUNT, [$this->formSpec[F_ID]], $this->formSpec); break; case FORM_DELETE: @@ -787,7 +823,8 @@ class QuickFormQuery { * @throws UserFormException * @throws UserReportException */ - public function getNativeFormElements($sql, array $param, $formSpec) { + public function getNativeFormElements($sql, array $param, $formSpec) + { $feSpecNative = $this->dbArray[$this->dbIndexQfq]->sql($sql, ROW_REGULAR, $param); @@ -827,7 +864,8 @@ class QuickFormQuery { * @throws UserFormException * @throws UserReportException */ - private function explodeTemplateGroupElements(array $elements) { + private function explodeTemplateGroupElements(array $elements) + { $new = array(); // No FormElements or no NAME_TG_COPIES column: nothing to do, return. @@ -879,9 +917,12 @@ class QuickFormQuery { * * @return bool|string Formname (Form.name) or FALSE (if no formname found) * @throws CodeException + * @throws DbException * @throws UserFormException + * @throws UserReportException */ - public function getFormName($mode, &$foundInStore = '') { + public function getFormName($mode, &$foundInStore = '') + { $dummy = array(); switch ($mode) { @@ -919,7 +960,8 @@ class QuickFormQuery { * @throws CodeException * @throws UserFormException */ - private function modeCleanFormConfig($mode, array $form) { + private function modeCleanFormConfig($mode, array $form) + { switch ($mode) { case FORM_DELETE: @@ -950,7 +992,8 @@ class QuickFormQuery { * @throws CodeException * @throws UserFormException */ - private function syncSystemFormConfig(array $formSpec) { + private function syncSystemFormConfig(array $formSpec) + { $keys = [F_BS_COLUMNS, F_BS_LABEL_COLUMNS, @@ -1020,7 +1063,8 @@ class QuickFormQuery { * @throws CodeException * @throws UserFormException */ - private function initForm(array $formSpec) { + private function initForm(array $formSpec) + { Support::setIfNotSet($formSpec, F_EXTRA_DELETE_FORM, ''); Support::setIfNotSet($formSpec, F_SUBMIT_BUTTON_TEXT, ''); @@ -1061,7 +1105,8 @@ class QuickFormQuery { * @throws \qfq\UserFormException * @internal param $foundInStore */ - private function validateForm($formNameFoundInStore, $formMode) { + private function validateForm($formNameFoundInStore, $formMode) + { // Retrieve record_id either from SIP (prefered) or via URL $r = $this->store->getVar(SIP_RECORD_ID, STORE_SIP . STORE_TYPO3 . STORE_CLIENT, '', $recordIdFoundInStore); @@ -1156,7 +1201,8 @@ class QuickFormQuery { * @throws DbException * @throws UserFormException */ - private function fillStoreWithRecord($table, $recordId, $store = STORE_RECORD) { + private function fillStoreWithRecord($table, $recordId, $store = STORE_RECORD) + { if ($recordId !== false && $recordId > 0) { $record = $this->dbArray[$this->dbIndexData]->sql("SELECT * FROM $table WHERE id = ?", ROW_EXPECT_1, [$recordId]); $this->store->setStore($record, $store, true); @@ -1171,7 +1217,8 @@ class QuickFormQuery { * * @return array to build JSON */ - private function groupElementUpdateEntries(array $dataArray) { + private function groupElementUpdateEntries(array $dataArray) + { $collect = array(); foreach ($dataArray as $data) { @@ -1195,8 +1242,13 @@ class QuickFormQuery { * Process the SQL Queries from bodytext. Return the output. * * @return string + * @throws CodeException + * @throws DbException + * @throws UserFormException + * @throws UserReportException */ - private function doReport() { + private function doReport() + { $report = new Report($this->t3data, $this->eval, $this->phpUnit); @@ -1213,8 +1265,10 @@ class QuickFormQuery { * @throws CodeException * @throws DbException * @throws UserFormException + * @throws UserReportException */ - public function saveForm() { + public function saveForm() + { $json = $this->doForm(FORM_SAVE); @@ -1228,14 +1282,33 @@ class QuickFormQuery { * @throws CodeException * @throws DbException * @throws UserFormException + * @throws UserReportException */ - public function updateForm() { + public function updateForm() + { $json = $this->doForm(FORM_UPDATE); return $json; } + /** + * Update FormElements and form values. Receives the current form values via POST. + * + * @return array + * @throws CodeException + * @throws DbException + * @throws UserFormException + * @throws UserReportException + */ + public function dragAndDrop() + { + + $json = $this->doForm(FORM_DRAG_AND_DROP); + + return $json; + } + /** * Delete a record (tablename and recordid are given) or process a 'delete form' * @@ -1243,8 +1316,10 @@ class QuickFormQuery { * @throws CodeException * @throws DbException * @throws UserFormException + * @throws UserReportException */ - public function delete() { + public function delete() + { return $this->doForm(FORM_DELETE); @@ -1258,7 +1333,8 @@ class QuickFormQuery { * @throws CodeException * @throws UserFormException */ - private function newRecordCreateSip(array $sipArray, $recordId) { + private function newRecordCreateSip(array $sipArray, $recordId) + { $tmpParam = array(); @@ -1296,7 +1372,8 @@ class QuickFormQuery { /** * @return string */ - private function getModalCode() { + private function getModalCode() + { $code = <<<EOF <!-- Modal --> diff --git a/extension/qfq/qfq/Save.php b/extension/qfq/qfq/Save.php index 0f63fed3a052522ea3a4c0117c972cfe50d7cbc4..bd523da9eac15e255862050e4876b81a89877ea9 100644 --- a/extension/qfq/qfq/Save.php +++ b/extension/qfq/qfq/Save.php @@ -289,6 +289,7 @@ class Save { * @return bool|int false if $values is empty, else affectedrows * @throws CodeException * @throws DbException + * @throws UserFormException */ public function updateRecord($tableName, array $values, $recordId) { @@ -549,7 +550,9 @@ class Save { * * @return array|mixed|null|string * @throws CodeException + * @throws DbException * @throws UserFormException + * @throws UserReportException */ private function copyUploadFile(array $formElement, array $statusUpload) { $pathFileName = ''; @@ -613,6 +616,7 @@ class Save { * @throws CodeException * @throws DbException * @throws UserFormException + * @throws UserReportException */ private function splitUpload(array $formElement, $pathFileName) { @@ -716,7 +720,9 @@ class Save { * @param $modeUpload * @return int * @throws CodeException + * @throws DbException * @throws UserFormException + * @throws UserReportException */ private function doUploadSlave(array $fe, $modeUpload) { $sql = ''; diff --git a/extension/qfq/qfq/database/Database.php b/extension/qfq/qfq/database/Database.php index 437455e37bc63a31885472d4c4b628fcaa85b0a8..babf2684c3f9aedc915d68f3a7e154df01e1097b 100644 --- a/extension/qfq/qfq/database/Database.php +++ b/extension/qfq/qfq/database/Database.php @@ -415,7 +415,6 @@ class Database { * @param string $sql * @param array $parameterArray * - * @return string * @throws CodeException * @throws UserFormException */ @@ -632,7 +631,9 @@ class Database { * * @return array the definition of the column as retrieved by Database::getTableDefinition(). * - * @throws \qfq\DbException + * @throws CodeException + * @throws DbException + * @throws UserFormException */ private function getFieldDefinitionFromTable($table, $columnName) { $tableDefinition = $this->getTableDefinition($table); @@ -660,6 +661,7 @@ class Database { * @return array column definition of table as returned by SHOW FIELDS FROM as associative array. * @throws CodeException * @throws DbException + * @throws UserFormException */ public function getTableDefinition($table) { return $this->sql("SHOW FIELDS FROM `$table`"); @@ -673,8 +675,9 @@ class Database { * @param array $stat * * @return array|bool - * @throws \qfq\CodeException - * @throws \qfq\DbException + * @throws CodeException + * @throws DbException + * @throws UserFormException */ public function sqlKeys($sql, array &$keys, array &$stat = array()) { @@ -699,6 +702,7 @@ class Database { * @return bool true if found, else false * @throws CodeException * @throws DbException + * @throws UserFormException */ public function existTable($name) { $found = false; diff --git a/extension/qfq/qfq/database/DatabaseUpdate.php b/extension/qfq/qfq/database/DatabaseUpdate.php index 8e2b50aa75c96832a9dbe35c11e996100517bfc2..4fc39793e579518f123147a2d552aee15ff748e8 100644 --- a/extension/qfq/qfq/database/DatabaseUpdate.php +++ b/extension/qfq/qfq/database/DatabaseUpdate.php @@ -69,6 +69,7 @@ class DatabaseUpdate { * @return bool|string false if there is no table 'Form' or if there is no comment set in table 'Form'. * @throws CodeException * @throws DbException + * @throws UserFormException */ private function getDatabaseVersion() { @@ -95,6 +96,7 @@ class DatabaseUpdate { * * @throws CodeException * @throws DbException + * @throws UserFormException */ private function setDatabaseVersion($version) { @@ -154,6 +156,7 @@ class DatabaseUpdate { * @param $new * @throws CodeException * @throws DbException + * @throws UserFormException */ private function dbUpdateStatements($old, $new) { if ($new == '' || $old === false) { diff --git a/extension/qfq/qfq/exceptions/AbstractException.php b/extension/qfq/qfq/exceptions/AbstractException.php index ec8886239c10b5072378f30d07be1e8cfb796ca9..14ca5f6bd776dd2e99e0950e34d19b8fba6bbc1a 100644 --- a/extension/qfq/qfq/exceptions/AbstractException.php +++ b/extension/qfq/qfq/exceptions/AbstractException.php @@ -46,8 +46,6 @@ class AbstractException extends \Exception { // In a very early stage, it might be possible that Store can't be initialized: take care not to use it. $store = Store::getInstance(); $t3Vars = $store->getStore(STORE_TYPO3); - } catch (UserFormException $e) { - $store = null; } catch (CodeException $e) { $store = null; } diff --git a/extension/qfq/qfq/form/Dirty.php b/extension/qfq/qfq/form/Dirty.php index f974739a547062d9c32dd28970d0b3cbce235836..fce24a45f62fdaccfd34e3fa0e7454c27682b757 100644 --- a/extension/qfq/qfq/form/Dirty.php +++ b/extension/qfq/qfq/form/Dirty.php @@ -55,6 +55,7 @@ class Dirty { * @param bool $phpUnit * @param bool $dbIndexData * @param bool $dbIndexQfq + * @throws CodeException */ public function __construct($phpUnit = false, $dbIndexData = false, $dbIndexQfq = false) { @@ -92,6 +93,7 @@ class Dirty { * * @return array|int * @throws CodeException + * @throws DbException * @throws UserFormException */ public function process() { @@ -183,7 +185,6 @@ class Dirty { * * @return array DirtyRecord or empty array. * @throws CodeException - * @throws DbException */ private function getRecordDirty($tableName, $recordId) { @@ -205,8 +206,6 @@ class Dirty { * @param string $currentFormDirtyMode * * @return array - * @throws CodeException - * @throws DbException */ private function conflict(array $recordDirty, $currentFormDirtyMode) { $status = API_ANSWER_STATUS_CONFLICT; diff --git a/extension/qfq/qfq/form/DragAndDrop.php b/extension/qfq/qfq/form/DragAndDrop.php new file mode 100644 index 0000000000000000000000000000000000000000..39f18f231896ab8f17cda1a4781f63a333e6cff7 --- /dev/null +++ b/extension/qfq/qfq/form/DragAndDrop.php @@ -0,0 +1,168 @@ +<?php +/** + * Created by PhpStorm. + * User: crose + * Date: 3/13/17 + * Time: 9:29 PM + */ + +namespace qfq; + +//use TYPO3\CMS\Core\FormProtection\Exception; + +require_once(__DIR__ . '/../store/Sip.php'); +require_once(__DIR__ . '/../store/Session.php'); +require_once(__DIR__ . '/../Constants.php'); +require_once(__DIR__ . '/../helper/Ldap.php'); +require_once(__DIR__ . '/../database/Database.php'); + + +/** + * Class DragAndDrop + * @package qfq + */ +class DragAndDrop { + + /** + * @var Database instantiated class + */ + private $db = null; + + /** + * @var array + */ + private $vars = array(); + + + /** + * @return array|int + * @throws CodeException + * @throws DbException + * @throws UserFormException + */ + public function process($tableName, $dragAndDropOrderSql) { + + $arr = array(); + $dbIndex = DB_INDEX_DEFAULT; //TODO hier muss noch die aktuelle DB ermittelt werden (kann im iform angegeben sein) + + $sipClass = new Sip(); + + $sipVars = $sipClass->getVarsFromSip($this->vars[TYPEAHEAD_API_SIP]); + + // Check for an optional given dbIndex: '[<int>]SELECT ...' + $sql = $sipVars[FE_TYPEAHEAD_SQL]; + if ($sql[0] === '[') { + $pos = strpos($sql, ']'); + $dbIndex = substr($sql, 1, $pos - 1); + $sipVars[FE_TYPEAHEAD_SQL] = substr($sql, $pos + 1); + } + + $this->db = new Database($dbIndex); + + if (isset($sipVars[FE_TYPEAHEAD_SQL])) { + if($this->vars[TYPEAHEAD_API_PREFETCH] == '') { + $arr = $this->typeAheadSql($sipVars, $this->vars[TYPEAHEAD_API_QUERY]); + } else { + $arr = $this->typeAheadSqlPrefetch($sipVars, $this->vars[TYPEAHEAD_API_PREFETCH]); + } + } elseif (isset($sipVars[FE_LDAP_SERVER])) { + $ldap = new Ldap(); + + if ($this->vars[TYPEAHEAD_API_PREFETCH] == '') { + $mode = MODE_LDAP_MULTI; + $key = $this->vars[TYPEAHEAD_API_QUERY]; + } else { + $mode = MODE_LDAP_PREFETCH; + $key = $this->vars[TYPEAHEAD_API_PREFETCH]; + } + + $arr = $ldap->process($sipVars, $key, $mode); + } + + return $arr; + } + + /** + * Do a wildcard search on the prepared statement $config[FE_TYPEAHEAD_SQL]. + * All '?' will be replaced by '%$value%'. + * If there is no 'LIMIT x' defined, append it. + * Returns an dict array [ API_TYPEAHEAD_KEY => key, API_TYPEAHEAD_VALUE => value ] + * + * @param array $config + * @param string $value + * + * @return array + * @throws CodeException + * @throws DbException + * @throws UserFormException + */ + private function typeAheadSql(array $config, $value) { + $values = array(); + + $sql = $config[FE_TYPEAHEAD_SQL]; + $value = '%' . $value . '%'; + $cnt = substr_count($sql, '?'); + + if ($cnt == 0) { + throw new UserFormException("Missing at least one '?' in " . FE_TYPEAHEAD_SQL); + } + + for ($ii = 0; $ii < $cnt; $ii++) { + $values[] = $value; + } + + if (!$this->db->hasLimit($sql)) { + $sql .= ' LIMIT ' . $config[FE_TYPEAHEAD_LIMIT]; + } + + $arr = $this->db->sql($sql, ROW_REGULAR, $values); + if ($arr == false || count($arr) == 0) { + return array(); + } + + return $this->db->makeArrayDict($arr, TYPEAHEAD_SQL_KEY_NAME, API_TYPEAHEAD_VALUE, API_TYPEAHEAD_KEY, API_TYPEAHEAD_VALUE); + } + + /** + * Returns a dict array [ API_TYPEAHEAD_KEY => key, API_TYPEAHEAD_VALUE => value ] with the prefetch result + * + * @param array $config + * @param string $key + * + * @return array + * @throws CodeException + * @throws DbException + * @throws UserFormException + */ + + private function typeAheadSqlPrefetch(array $config, $key) { + $keys = array(); + + $sql = $config[FE_TYPEAHEAD_SQL_PREFETCH]; + if ($config[FE_TYPEAHEAD_SQL_PREFETCH] == '') { + throw new UserFormException("Missing definition for `" . FE_TYPEAHEAD_SQL_PREFETCH . "`", ERROR_MISSING_TYPE_AHEAD_SQL_PREFETCH); + } + + $cnt = substr_count($sql, '?'); + if ($cnt == 0) { + throw new UserFormException("Missing at least one '?' in " . FE_TYPEAHEAD_SQL_PREFETCH); + } + + for ($ii = 0; $ii < $cnt; $ii++) { + $keys[] = $key; + } + + $arr = $this->db->sql($sql, ROW_REGULAR, $keys); + if ($arr == false || count($arr) == 0) { + return array(); + } + + // return first result as key-value pair (concatenate columns) + $value = ''; + foreach($arr[0] AS $name => $column) { + $value .= $column; + } + return [ [ API_TYPEAHEAD_KEY => $key, API_TYPEAHEAD_VALUE => $value ] ]; + } + +} \ No newline at end of file diff --git a/extension/qfq/qfq/form/FormAction.php b/extension/qfq/qfq/form/FormAction.php index ee804a31c5cbb1def46ce49820f227ec9fccf516..43edcf6bfb3b36bf92e7cddd736b6c0784d91c0b 100644 --- a/extension/qfq/qfq/form/FormAction.php +++ b/extension/qfq/qfq/form/FormAction.php @@ -72,6 +72,7 @@ class FormAction { * @throws CodeException * @throws DbException * @throws UserFormException + * @throws UserReportException */ public function elements($recordId, array $feSpecAction, $feTypeList) { @@ -218,6 +219,7 @@ class FormAction { * * @return bool true if none FE is specified or all specified are non empty. * @throws CodeException + * @throws UserFormException */ private function checkRequiredList(array $fe) { @@ -280,7 +282,10 @@ class FormAction { * * @param array $fe * + * @throws CodeException + * @throws DbException * @throws UserFormException + * @throws UserReportException */ private function validate(array $fe) { @@ -329,6 +334,7 @@ class FormAction { * @throws CodeException * @throws DbException * @throws UserFormException + * @throws UserReportException */ private function doSlave(array $fe, $recordId) { @@ -405,6 +411,7 @@ class FormAction { * @return bool true if at lease one of the named elements is non empty on STORE_FORM (use SANATIZE_ALLOW_ALL to * perform the check) * @throws CodeException + * @throws UserFormException */ private function checkFormElements($listOfFormElementNames) { $arr = explode(',', $listOfFormElementNames); @@ -574,6 +581,7 @@ class FormAction { * @param string $tableName * @throws CodeException * @throws DbException + * @throws UserFormException */ private function translateId(array $translateMap, $translateIdColumn, $tableName) { @@ -628,6 +636,7 @@ class FormAction { * @return int - lastInsertId * @throws CodeException * @throws DbException + * @throws UserFormException */ function copyRecord(array $row, $destTable) { $keys = array(); diff --git a/extension/qfq/qfq/report/Download.php b/extension/qfq/qfq/report/Download.php index bdd6735e3afffbb77a23d8129a492dc87e7efa97..6d63a592887bb689e75ce6e15c84572c97970d67 100644 --- a/extension/qfq/qfq/report/Download.php +++ b/extension/qfq/qfq/report/Download.php @@ -362,6 +362,7 @@ class Download { /** * @param string $urlParam * @return string + * @throws CodeException * @throws UserFormException * @throws UserReportException */ @@ -383,6 +384,7 @@ class Download { * @throws CodeException * @throws DownloadException * @throws UserFormException + * @throws UserReportException */ public function process($vars, $outputMode = OUTPUT_MODE_DIRECT) { diff --git a/extension/qfq/qfq/report/Link.php b/extension/qfq/qfq/report/Link.php index 71930fb3c76120dea69367097cf8675f91140dda..6e3a6990ca9d7585d42d489c230470db91ed4008 100644 --- a/extension/qfq/qfq/report/Link.php +++ b/extension/qfq/qfq/report/Link.php @@ -1072,6 +1072,7 @@ EOF; * @param array $vars * * @return string + * @throws CodeException * @throws UserFormException * @throws UserReportException */ @@ -1420,6 +1421,7 @@ EOF; * @param $value * * @return array + * @throws UserFormException * @throws UserReportException */ private function buildActionDelete($vars, $value) { diff --git a/extension/qfq/qfq/report/Report.php b/extension/qfq/qfq/report/Report.php index c441c6f4614ccd37ed82b2afdf16d54281cc8047..6c44a55ce5723e5c50cd22bcb170773563f3bad0 100644 --- a/extension/qfq/qfq/report/Report.php +++ b/extension/qfq/qfq/report/Report.php @@ -667,6 +667,7 @@ class Report { * * @return string rendered column * @throws CodeException + * @throws DbException * @throws UserFormException * @throws UserReportException */ diff --git a/extension/qfq/qfq/report/SendMail.php b/extension/qfq/qfq/report/SendMail.php index af306b205007825076ab71bb73ff5c60623a6030..e2528ab11d247006ab40d905365e23200e81bc0b 100644 --- a/extension/qfq/qfq/report/SendMail.php +++ b/extension/qfq/qfq/report/SendMail.php @@ -44,6 +44,7 @@ class SendMail { * @param array $mailConfig * @throws CodeException * @throws DbException + * @throws DownloadException * @throws UserFormException * @throws UserReportException */ @@ -108,6 +109,7 @@ class SendMail { * @param array $mailConfig * @return string * @throws CodeException + * @throws DownloadException * @throws UserFormException * @throws UserReportException */ @@ -123,8 +125,9 @@ class SendMail { if (is_array($value)) { continue; } - $mailConfig[$key] = Support::escapeDoubleTick($value); -// $mailConfig[$key] = addslashes($value); + if($key!=SENDMAIL_TOKEN_SUBJECT) { // do not escape double ticks in subject - this breaks the UTF8 encoding later + $mailConfig[$key] = Support::escapeDoubleTick($value); + } } $args[] = '-f "' . $mailConfig[SENDMAIL_TOKEN_SENDER] . '"'; @@ -151,6 +154,8 @@ class SendMail { $encodedSubject = iconv_mime_encode("Subject", $mailConfig[SENDMAIL_TOKEN_SUBJECT], $preferences); $encodedSubject = substr($encodedSubject, 9); // remove 'Subject: ' + $encodedSubject = Support::escapeDoubleTick($encodedSubject); // now, escape double ticks. + $args[] = '-u "' . $encodedSubject . '"';; } diff --git a/extension/qfq/qfq/report/Thumbnail.php b/extension/qfq/qfq/report/Thumbnail.php index 506e818a66936a55995d083195545d2bb51f6704..69be01450fa1e8cc3984ead02e190f432d624d2f 100644 --- a/extension/qfq/qfq/report/Thumbnail.php +++ b/extension/qfq/qfq/report/Thumbnail.php @@ -57,6 +57,7 @@ class Thumbnail { * @param string $str * @param string $modeRender * @return string + * @throws CodeException * @throws UserFormException * @throws UserReportException */ diff --git a/extension/qfq/qfq/store/FillStoreForm.php b/extension/qfq/qfq/store/FillStoreForm.php index 2ef50b3d85cff9ff42388d0e4aa0d950bb5ca116..9eadf27730d98b3f8f8f3bc9f3434bedfef804c6 100644 --- a/extension/qfq/qfq/store/FillStoreForm.php +++ b/extension/qfq/qfq/store/FillStoreForm.php @@ -148,7 +148,9 @@ class FillStoreForm { * @param string $formMode * * @throws CodeException + * @throws DbException * @throws UserFormException + * @throws UserReportException */ public function process($formMode = FORM_SAVE) {