Commit 3f6fedaa authored by Carsten  Rose's avatar Carsten Rose
Browse files

UserReportException.php: Added field SYSTEM_REPORT_COLUMN_NAME to output....

UserReportException.php: Added field SYSTEM_REPORT_COLUMN_NAME to output. Array members renamed to SYSTEM_*.
Various files adjusted to inlcude renamed file `UserFormException.php`.
Link.php: Mamut switch() in parseItem() refactored to use $callTable.
Report.php: refactoring started to use UserReportException() instead of SyntaxReportException. Startet removing all fr_error usages.
parent 9040de60
......@@ -15,7 +15,7 @@ use qfq\OnArray;
require_once(__DIR__ . '/../qfq/store/Store.php');
require_once(__DIR__ . '/../qfq/Constants.php');
require_once(__DIR__ . '/../qfq/exceptions/DbException.php');
require_once(__DIR__ . '/../qfq/exceptions/UserException.php');
require_once(__DIR__ . '/../qfq/exceptions/UserFormException.php');
require_once(__DIR__ . '/../qfq/Database.php');
require_once(__DIR__ . '/../qfq/helper/HelperFormElement.php');
require_once(__DIR__ . '/../qfq/helper/Support.php');
......
......@@ -14,7 +14,7 @@ use qfq\UserFormException;
require_once(__DIR__ . '/../qfq/Constants.php');
require_once(__DIR__ . '/../qfq/helper/OnArray.php');
require_once(__DIR__ . '/../qfq/AbstractBuildForm.php');
require_once(__DIR__ . '/../qfq/exceptions/UserException.php');
require_once(__DIR__ . '/../qfq/exceptions/UserFormException.php');
/**
* Class BuildFormBootstrap
......
......@@ -135,6 +135,9 @@ const ERROR_IO_READ_FILE = 1200;
const ERROR_IO_WRITE = 1203;
const ERROR_IO_OPEN = 1204;
//Report
const ERROR_UNKNOWN_LINK_QUALIFIER = 1300;
// KeyValueParser
const ERROR_KVP_VALUE_HAS_NO_KEY = 1900;
......@@ -238,7 +241,8 @@ const SYSTEM_FORM = CLIENT_FORM; // '<formName> / <formId
const SYSTEM_FORM_ELEMENT = 'formElement'; // '<formElementName> / <formElementeId>'
const SYSTEM_FORM_ELEMENT_COLUMN = 'formElementColumn'; // '<columnname of current processed formElement>'
const SYSTEM_FORM_ELEMENT_MESSAGE = 'formElementMessage'; // '<columnname of current processed formElement>'
const SYSTEM_REPORT_COLUMN_KEY = 'reportColumnKey'; // Keyname of SQL-column processed at the moment.
const SYSTEM_REPORT_COLUMN_INDEX = 'reportColumnIndex'; // Keyname of SQL-column processed at the moment.
const SYSTEM_REPORT_COLUMN_NAME = 'reportColumnName'; // Keyname of SQL-column processed at the moment.
const SYSTEM_REPORT_COLUMN_VALUE = 'reportColumnValue'; // Keyname of SQL-column processed at the moment.
const SYSTEM_REPORT_FULL_LEVEL = 'reportFullLevel'; // Keyname of SQL-column processed at the moment.
......
......@@ -15,7 +15,7 @@ use qfq\UserFormException;
use qfq\Support;
use qfq\Store;
require_once(__DIR__ . '/exceptions/UserException.php');
require_once(__DIR__ . '/exceptions/UserFormException.php');
require_once(__DIR__ . '/exceptions/CodeException.php');
require_once(__DIR__ . '/exceptions/DbException.php');
......
......@@ -29,7 +29,7 @@ require_once(__DIR__ . '/../qfq/Constants.php');
require_once(__DIR__ . '/../qfq/Save.php');
require_once(__DIR__ . '/../qfq/helper/KeyValueStringParser.php');
require_once(__DIR__ . '/../qfq/helper/HelperFormElement.php');
require_once(__DIR__ . '/../qfq/exceptions/UserException.php');
require_once(__DIR__ . '/../qfq/exceptions/UserFormException.php');
require_once(__DIR__ . '/../qfq/exceptions/CodeException.php');
require_once(__DIR__ . '/../qfq/exceptions/DbException.php');
require_once(__DIR__ . '/../qfq/exceptions/ErrorHandler.php');
......
......@@ -17,8 +17,7 @@ require_once(__DIR__ . '/AbstractException.php');
*
* @package qfq\exceptions
*/
class UserFormException extends AbstractException {
class UserReportException extends AbstractException {
/*
* @return string HTML formatted error string
......@@ -26,10 +25,11 @@ class UserFormException extends AbstractException {
public function formatMessage() {
$this->messageArray['Type'] = 'User Report Exception';
$this->messageArray['SqlRaw'] = Store::getVar(SYSTEM_FORM, STORE_SYSTEM);
$this->messageArray['SqlFinal'] = Store::getVar(SYSTEM_SQL_FINAL, STORE_SYSTEM);
$this->messageArray['ColumnKey'] = Store::getVar(SYSTEM_REPORT_COLUMN_KEY, STORE_SYSTEM);
$this->messageArray['ColumnValue'] = Store::getVar(SYSTEM_REPORT_COLUMN_VALUE, STORE_SYSTEM);
$this->messageArray[SYSTEM_SQL_RAW] = htmlentities(Store::getVar(SYSTEM_SQL_RAW, STORE_SYSTEM));
$this->messageArray[SYSTEM_SQL_FINAL] = htmlentities(Store::getVar(SYSTEM_SQL_FINAL, STORE_SYSTEM));
$this->messageArray[SYSTEM_REPORT_COLUMN_INDEX] = htmlentities(Store::getVar(SYSTEM_REPORT_COLUMN_INDEX, STORE_SYSTEM));
$this->messageArray[SYSTEM_REPORT_COLUMN_NAME] = htmlentities(Store::getVar(SYSTEM_REPORT_COLUMN_NAME, STORE_SYSTEM));
$this->messageArray[SYSTEM_REPORT_COLUMN_VALUE] = htmlentities(Store::getVar(SYSTEM_REPORT_COLUMN_VALUE, STORE_SYSTEM));
return parent::formatException();
}
......
......@@ -15,7 +15,7 @@ use qfq\UserFormException;
require_once(__DIR__ . '/../../qfq/store/Store.php');
require_once(__DIR__ . '/../../qfq/Constants.php');
require_once(__DIR__ . '/../../qfq/helper/KeyValueStringParser.php');
require_once(__DIR__ . '/../../qfq/exceptions/UserException.php');
require_once(__DIR__ . '/../../qfq/exceptions/UserFormException.php');
class HelperFormElement
{
......
......@@ -13,7 +13,7 @@ namespace qfq;
use qfq;
use qfq\UserFormException;
require_once(__DIR__ . '/../exceptions/UserException.php');
require_once(__DIR__ . '/../exceptions/UserFormException.php');
require_once(__DIR__ . '/../../qfq/Constants.php');
/**
......
......@@ -9,7 +9,7 @@
namespace qfq;
require_once(__DIR__ . '/../Constants.php');
require_once(__DIR__ . '/../exceptions/UserException.php');
require_once(__DIR__ . '/../exceptions/UserFormException.php');
class Logger {
......
......@@ -188,7 +188,7 @@ class CodeReportException extends \Exception {
* @param string $file
* @param string $line
*/
class UserReportException extends \Exception {
class UserReportExceptionUnused extends \Exception {
protected $file;
protected $line;
......
......@@ -42,7 +42,7 @@ require_once(__DIR__ . '/../store/Sip.php');
*
* r:render
* g:target
* c:class [n|i|e]:<class>
* c:class [n|i|e|<class>]
* q:question <text>
* e:encryption 0|1
*
......@@ -92,11 +92,40 @@ class Link {
private $cssLinkClassInternal = '';
private $cssLinkClassExternal = '';
private $callTable = [
'u' => 'buildUrl',
'm' => 'buildMail',
'p' => 'buildPage',
't' => 'buildText',
'a' => 'buildAltText',
'o' => 'buildToolTip',
'P' => 'buildPicture',
'B' => 'buildBullet',
'C' => 'buildCheck',
'D' => 'buildDelete',
'E' => 'buildEdit',
'H' => 'buildHelp',
'I' => 'buildInfo',
'N' => 'buildNew',
'S' => 'buildShow',
'r' => 'buildRender',
'g' => 'buildTarget',
'c' => 'buildClass',
'q' => 'buildQuestion',
'e' => 'buildEncryption',
'h' => 'buildHash',
'U' => 'buildUrlParams',
'R' => 'buildRightOfText',
'G' => 'buildGrafic',
'A' => 'buildAnchor',
];
/**
* __construct
*
* @param $fr_error
* @param Sip $sip
* @param bool $phpUnit
*/
public function __construct($fr_error, Sip $sip, $phpUnit = false) {
$this->fr_error = $fr_error;
......@@ -165,9 +194,9 @@ class Link {
/**
* Build the whole link
*
* @param string $str : Qualifier with params. 'report'-syntax. F.e.: A:u:www.example.com|G:P:home.gif|t:Home"
*
* @return string The complete Link
* @param string $str Qualifier with params. 'report'-syntax. F.e.: A:u:www.example.com|G:P:home.gif|t:Home"
* @return string The complete HTML encoded Link like <a href='http://example.com' class='external'><img src='iconf.gif' title='help text'>Description</a>
* @throws SyntaxReportException
*/
public function renderLink($str) {
$link = '';
......@@ -181,23 +210,29 @@ class Link {
// Parse all parameter, fill variables
foreach ($param as $item) {
if ($item == '') {
continue;
}
// set class defaults
$this->parseItem($vars, $item);
}
// if there is no url or mailto definition: {{global.pageId}}
if ($vars['url'] == '' && $vars['mailto'] == '') {
$vars['url'] = "?" . $this->store->getVar(TYPO3_PAGE_ID, STORE_TYPO3);
}
// if ($vars['url'] == '' && $vars['mailto'] == '') {
// $vars['url'] = "?" . $this->store->getVar(TYPO3_PAGE_ID, STORE_TYPO3);
// }
$this->doCssClass($vars);
$htmlUrl = $this->doUrl($vars);
$htmlImage = $this->doImage($vars);
$htmlUrl = $this->doHtmlUrl($vars);
$htmlImage = $this->doHtmlImage($vars);
// Compose Image & Text
$distance = ' ';
$vars['text'] = ($vars['picturePosition'] == "l") ? $htmlImage . $distance . $vars['text'] : $vars['text'] . $distance . $htmlImage;
if ($htmlImage != '') {
$distance = ' ';
$vars['text'] = ($vars['picturePosition'] == "l") ? $htmlImage . $distance . $vars['text'] : $vars['text'] . $distance . $htmlImage;
}
// ToolTip
$extraSpan = ['', ''];
......@@ -218,7 +253,18 @@ class Link {
}
// Compose URL
// get Render Mode via Array renderControl
$mode = $prefix . $this->renderControl[$vars['modeRender']][$vars['url'] ? 1 : 0][$vars['text'] ? 1 : 0];
$modeRender = $vars['modeRender'];
$modeUrl = $vars['url'] ? 1 : 0;
$modeText = $vars['text'] ? 1 : 0;
if (isset($this->renderControl[$modeRender][$modeUrl][$modeText])) {
$mode = $prefix . $this->renderControl[$modeRender][$modeUrl][$modeText];
} else {
throw new SyntaxReportException ("Undefined combination of rendering mode / url given / text given: " .
$modeRender . ' / ' . $modeUrl . ' / ' . $modeText, "", null, __FILE__, __LINE__,
"Column: " . $this->fr_error["columnIndex"], $this->fr_error);
}
// 0-4 URL, plain email
// 10-14 encrypted email
switch ($mode) {
......@@ -274,7 +320,12 @@ class Link {
}
private function clearVars(&$vars) {
/**
* Cleans the standard vars used every time to render a link.
*
* @param array $vars
*/
private function clearVars(array &$vars) {
$vars['mailto'] = "";
$vars['url'] = "";
$vars['pageAlias'] = '';
......@@ -302,200 +353,39 @@ class Link {
/**
* Parse Item of link string, fill class global variables.
*
* @param string $key : F.e.: 'u'
* @param string $value : F.e.: 'http://www.nzz.ch'
* @param array $vars
* @param $item
* @throws CodeException
* @throws SyntaxReportException
*/
private
function parseItem(&$vars, $item) {
private function parseItem(array &$vars, $item) {
$key = '';
$value = '';
$arr = explode(":", $item, 2);
switch (count($arr)) {
case 0:
return;
break;
case 1:
$key = $arr[0];
break;
case 2:
$key = $arr[0];
$value = $arr[1];
break;
default:
throw new CodeException("This statement should never be reached", ERROR_CODE_SHOULD_NOT_HAPPEN);
$key = isset($arr[0]) ? $arr[0] : '';
$value = isset($arr[1]) ? $arr[1] : '';
// if($key == '') {
// return;
// }
//
if (!isset($this->callTable[$key])) {
throw new UserReportException ("Unknown link qualifier: '$key'", ERROR_UNKNOWN_LINK_QUALIFIER);
}
switch ($key) {
// URL
case "u":
if ($vars['url'] || $vars['mailto'])
throw new SyntaxReportException ("Multiple URL, PAGE or MAILTO defined : '$key'", "", null, __FILE__, __LINE__, "Column: " . $this->fr_error["columnIndex"], $this->fr_error);
$vars['url'] = $value;
$vars['defaultLinkClass'] = $this->cssLinkClassExternal;
break;
case "m":
if ($vars['url'] || $vars['mailto'])
throw new SyntaxReportException ("Multiple URL, PAGE or MAILTO defined : '$key'", "", null, __FILE__, __LINE__, "Column: " . $this->fr_error["columnIndex"], $this->fr_error);
$vars['mailto'] = $value;
$vars['defaultLinkClass'] = $this->cssLinkClassExternal;
break;
case "p":
if ($vars['url'] || $vars['mailto'])
throw new SyntaxReportException ("Multiple URL, PAGE or MAILTO defined : '$key'", "", null, __FILE__, __LINE__, "Column: " . $this->fr_error["columnIndex"], $this->fr_error);
$vars['pageAlias'] = $value ? $value : $this->store->getVar(TYPO3_PAGE_ID, STORE_TYPO3); // If no pageid|pagealias is defined, take current page
// $this->url = "?" . $this->pageAlias;
$vars['defaultLinkClass'] = $this->cssLinkClassInternal;
break;
// Text
case "t":
$vars['text'] = $value;
break;
case "a":
$vars['altText'] = $value;
break;
case "o":
$vars['toolTip'] = $this->utils->createToolTip($value);
break;
// Image
case "P":
if ($vars['image'])
throw new SyntaxReportException ("Multiple images defined: '$key'", "", null, __FILE__, __LINE__, "Column: " . $this->fr_error["columnIndex"], $this->fr_error);
$vars['image'] = $value;
$vars['AltText'] = "Grafic: " . $value;
$vars['imageTitle'] = $value;
break;
case "B":
if ($vars['image'])
throw new SyntaxReportException ("Multiple images defined: '$key'", "", null, __FILE__, __LINE__, "Column: " . $this->fr_error["columnIndex"], $this->fr_error);
$vars['image'] = PATH_ICONS . "bullet-" . ($value ? $value : "green") . '.gif';
$vars['defaultAltText'] = "Bullet: " . $value;
$vars['imageTitle'] = $value;
break;
case "C":
if ($vars['image'])
throw new SyntaxReportException ("Multiple images defined: '$key'", "", null, __FILE__, __LINE__, "Column: " . $this->fr_error["columnIndex"], $this->fr_error);
$vars['image'] = PATH_ICONS . "checked-" . ($value ? $value : "green") . '.gif';
$vars['defaultAltText'] = "Checked: " . $value;
$vars['imageTitle'] = $value;
break;
case "D":
if ($vars['image'])
throw new SyntaxReportException ("Multiple images defined: '$key'", "", null, __FILE__, __LINE__, "Column: " . $this->fr_error["columnIndex"], $this->fr_error);
$vars['image'] = PATH_ICONS . 'delete.gif';
$vars['defaultAltText'] = "Delete";
$vars['imageTitle'] = "Delete";
$vars['delete'] = true;
// Include Extjs library
$this->utils->loadJSlib($this->fr_error);
break;
case "E":
if ($vars['image'])
throw new SyntaxReportException ("Multiple images defined: '$key'", "", null, __FILE__, __LINE__, "Column: " . $this->fr_error["columnIndex"], $this->fr_error);
$vars['image'] = PATH_ICONS . 'edit.gif';
$vars['defaultAltText'] = "Edit";
$vars['imageTitle'] = "Edit";
break;
case "H":
if ($vars['image'])
throw new SyntaxReportException ("Multiple images defined: '$key'", "", null, __FILE__, __LINE__, "Column: " . $this->fr_error["columnIndex"], $this->fr_error);
$vars['image'] = PATH_ICONS . 'help.gif';
$vars['defaultAltText'] = "Help";
$vars['imageTitle'] = "Help";
break;
case "I":
if ($vars['image'])
throw new SyntaxReportException ("Multiple images defined: '$key'", "", null, __FILE__, __LINE__, "Column: " . $this->fr_error["columnIndex"], $this->fr_error);
$vars['image'] = PATH_ICONS . 'info.gif';
$vars['defaultAltText'] = "Information";
$vars['imageTitle'] = "Information";
break;
case "N":
if ($vars['image'])
throw new SyntaxReportException ("Multiple images defined: '$key'", "", null, __FILE__, __LINE__, "Column: " . $this->fr_error["columnIndex"], $this->fr_error);
$vars['image'] = PATH_ICONS . 'new.gif';
$vars['defaultAltText'] = "New";
$vars['imageTitle'] = "New";
break;
case "S":
if ($vars['image'])
throw new SyntaxReportException ("Multiple images defined: '$key'", "", null, __FILE__, __LINE__, "Column: " . $this->fr_error["columnIndex"], $this->fr_error);
$vars['image'] = PATH_ICONS . 'show.gif';
$vars['defaultAltText'] = "Details";
$vars['imageTitle'] = "Details";
break;
// Misc
case "r":
if ($vars['modeRender'])
throw new SyntaxReportException ("Multiple render modes defined: '$key'", "", null, __FILE__, __LINE__, "Column: " . $this->fr_error["columnIndex"], $this->fr_error);
$vars['modeRender'] = $value;
break;
case "g":
if ($vars['target'])
throw new SyntaxReportException ("Multiple 'target' defined: '$key'", "", null, __FILE__, __LINE__, "Column: " . $this->fr_error["columnIndex"], $this->fr_error);
$vars['target'] = $value;
break;
case "c":
if ($vars['linkClass'])
throw new SyntaxReportException ("Multiple linkClass defined: '$key'", "", null, __FILE__, __LINE__, "Column: " . $this->fr_error["columnIndex"], $this->fr_error);
$vars['linkClass'] = $value;
break;
case "q":
if ($vars['question'])
throw new SyntaxReportException ("Multiple question defined: '$key'", "", null, __FILE__, __LINE__, "Column: " . $this->fr_error["columnIndex"], $this->fr_error);
$vars['question'] = $value ? $value : "Please confirm";
break;
case "e":
if ($vars['encryption'] != 1)
throw new SyntaxReportException ("Multiple encryption defined: '$key'", "", null, __FILE__, __LINE__, "Column: " . $this->fr_error["columnIndex"], $this->fr_error);
$vars['encryption'] = $value ? $value : "1";
break;
case "h":
if ($vars['modeHash'])
throw new SyntaxReportException ("Multiple modeHash defined: '$key'", "", null, __FILE__, __LINE__, "Column: " . $this->fr_error["columnIndex"], $this->fr_error);
$vars['modeHash'] = TRUE;
break;
case "U": //if($this->additionalUrlParams) throw new syntaxException ( "Multiple additionalUrlParams defined: '$key'","",__FILE__,__LINE__, "Column: " . $fthis->r_error["columnIndex"], $this->fr_error);
$vars['additionalUrlParams'] = $value;
break;
case "R":
if ($vars['picturePosition'] != "l")
throw new SyntaxReportException ("Multiple picturePosition defined: '$key'", "", null, __FILE__, __LINE__, "Column: " . $this->fr_error["columnIndex"], $this->fr_error);
$vars['picturePosition'] = "r";
break;
// A,G
case "G":
case "A":
// set class defaults
$this->parseItem($vars, $value);
break;
case "" :
break;
default:
throw new SyntaxReportException ("Unknown link qualifier: '$key'", "", null, __FILE__, __LINE__, "Column: " . $this->fr_error["columnIndex"], $this->fr_error);
}
$call = $this->callTable[$key];
$this->$call($vars, $key, $value);
}
/**
* Parse CSS Class Settings
*
* @param void
*
* @param array $vars
* @return void
*/
private
function doCssClass(&$vars) {
private function doCssClass(array &$vars) {
$class = '';
switch ($vars['linkClass']) {
......@@ -518,11 +408,11 @@ class Link {
* - <a href="http://example.com:>http://example.com</a>
* - If $this->modeHash is set, create a
*
* @param array $vars
* @return string
* @throws SyntaxReportException
*/
private
function doUrl(&$vars) {
private function doHtmlUrl(array &$vars) {
$tags = '';
// build URL
$htmlUrl = "";
......@@ -574,8 +464,7 @@ class Link {
* @internal param $void
*
*/
private
function doImage($vars) {
private function doHtmlImage(array $vars) {
$tags = '';
// Build Image
......@@ -601,15 +490,11 @@ class Link {
* document.write("<a href=" + "mail" + "to:" + mm1 + mm2 + ... + ">" + tld + "</a>")
* //--></script>';
*
* @param string $mailto Email address to encrypt.
* @param string $text Text to wrap <a href..>, </a> around.
* @param string $class Optional class definition
* @param bool $href TRUE: create a '<a>', false: just encrypt or show the email, no link.
*
* @return string The complete Link
* @param array $vars
* @param bool|TRUE $href TRUE: create a '<a>', false: just encrypt or show the email, no link.
* @return string
*/
private
function encryptMailtoJS($vars, $href = TRUE) {
private function encryptMailtoJS(array $vars, $href = TRUE) {
// Split $mailto
$tmp = $this->splitAndAddDelimter($vars['mailto'], "@");
......@@ -659,8 +544,8 @@ class Link {
* @param $delimiter
* @return array
*/
private
function splitAndAddDelimter($mailto, $delimiter) {
private function splitAndAddDelimter($mailto, $delimiter) {
//TODO: Ich verstehe die Funktion nicht - funktioniert das hier wirklich?
$value = '';
$arr = explode($delimiter, $mailto); // split string
......@@ -674,4 +559,344 @@ class Link {
return ($arr);
}
/**
* @param $vars
* @param $key
* @param $value
* @throws SyntaxReportException
*/
private function buildUrl(&$vars, $key, $value) {
if ($vars['url'] || $vars['mailto']) {
throw new SyntaxReportException ("Multiple URL, PAGE or MAILTO defined : '$key'", "", null, __FILE__, __LINE__, "Column: " . $this->fr_error["columnIndex"], $this->fr_error);
}
$vars['url'] = $value;
$vars['defaultLinkClass'] = $this->cssLinkClassExternal;
}
/**
* @param $vars
* @param $key
* @param $value
* @throws SyntaxReportException
*/
private function buildMail(&$vars, $key, $value) {
if ($vars['url'] || $vars['mailto']) {
throw new SyntaxReportException ("Multiple URL, PAGE or MAILTO defined : '$key'", "", null, __FILE__, __LINE__, "Column: " . $this->fr_error["columnIndex"], $this->fr_error);
}
$vars['mailto'] = $value;
$vars['defaultLinkClass'] = $this->cssLinkClassExternal;
}
/**
* @param $vars
* @param $key
* @param $value
* @throws SyntaxReportException
*/
private function buildPage(&$vars, $key, $value) {
if ($vars['url'] || $vars['mailto']) {
throw new SyntaxReportException ("Multiple URL, PAGE or MAILTO defined : '$key'", "", null, __FILE__, __LINE__, "Column: " . $this->fr_error["columnIndex"], $this->fr_error);
}
$vars['pageAlias'] = $value ? $value : $this->store->getVar(TYPO3_PAGE_ID, STORE_TYPO3); // If no pageid|pagealias is defined, take current page
$vars['url'] = "?" . $vars['pageAlias'];
$vars['defaultLinkClass'] = $this->cssLinkClassInternal;
}
/**
* @param $vars
* @param $key
* @param $value
* @throws SyntaxReportException
*/
private function buildText(&$vars, $key, $value) {
$vars['text'] = $value;
}
/**
* @param $vars
* @param $key
* @param $value
* @throws SyntaxReportException
*/
private function buildAltText(&$vars, $key, $value) {
$vars['altText'] = $value;