diff --git a/application/controllers/system/TestUDF.php b/application/controllers/system/TestUDF.php
index 087d916b6..08ad72e1b 100644
--- a/application/controllers/system/TestUDF.php
+++ b/application/controllers/system/TestUDF.php
@@ -17,12 +17,7 @@ class TestUDF extends VileSci_Controller
*/
public function index()
{
- $data = array (
- 'schema' => 'public',
- 'table' => 'tbl_person',
- 'field' => 'schuhgroesse',
- 'selected' => array(1, 2)
- );
+ $data = array();
$this->load->view('system/testudf', $data);
}
diff --git a/application/libraries/WidgetLib.php b/application/libraries/WidgetLib.php
index 15c90cfbd..bb4a46566 100644
--- a/application/libraries/WidgetLib.php
+++ b/application/libraries/WidgetLib.php
@@ -853,12 +853,12 @@ class DropdownWidget extends Widget
protected function addElementAtBeginning($elements, $stdDescription, $noDataDescription, $id)
{
$element = new stdClass();
- $element->id = $id;
- $element->description = $stdDescription;
+ $element->{DropdownWidget::ID_FIELD} = $id;
+ $element->{DropdownWidget::DESCRIPTION_FIELD} = $stdDescription;
if (!hasData($elements))
{
- $element->description = $noDataDescription;
+ $element->{DropdownWidget::DESCRIPTION_FIELD} = $noDataDescription;
}
array_unshift($elements->retval, $element);
@@ -888,13 +888,35 @@ class DropdownWidgetUDF extends DropdownWidget
$tmpElements = array();
//
- foreach($parameters as $key => $val)
+ foreach($parameters as $parameter)
{
- $element = new stdClass();
- $element->id = $key;
- $element->description = $val;
-
- array_push($tmpElements, $element);
+ //
+ if ((is_array($parameter) && count($parameter) == 2)
+ || (is_string($parameter) || is_numeric($parameter))
+ || (is_object($parameter) && isset($parameter->{PARENT::ID_FIELD}) && isset($parameter->{PARENT::DESCRIPTION_FIELD})))
+ {
+ $element = new stdClass(); //
+ //
+ if (is_array($parameter) && count($parameter) == 2)
+ {
+ $element->{PARENT::ID_FIELD} = $parameter[0]; //
+ $element->{PARENT::DESCRIPTION_FIELD} = $parameter[1]; //
+ }
+ //
+ else if (is_string($parameter) || is_numeric($parameter))
+ {
+ $element->{PARENT::ID_FIELD} = $parameter; //
+ $element->{PARENT::DESCRIPTION_FIELD} = $parameter; //
+ }
+ //
+ else if (is_object($parameter) && isset($parameter->{PARENT::ID_FIELD}) && isset($parameter->{PARENT::DESCRIPTION_FIELD}))
+ {
+ $element->{PARENT::ID_FIELD} = $parameter->{PARENT::ID_FIELD}; //
+ $element->{PARENT::DESCRIPTION_FIELD} = $parameter->{PARENT::DESCRIPTION_FIELD}; //
+ }
+
+ array_push($tmpElements, $element); //
+ }
}
$this->setElementsArray(
@@ -924,7 +946,7 @@ class TextareaWidget extends Widget
*/
protected function setText($text)
{
- $this->_args[DropdownWidget::TEXT] = $text;
+ $this->_args[TextareaWidget::TEXT] = $text;
}
/**
@@ -946,7 +968,14 @@ class TextareaWidgetUDF extends TextareaWidget
*/
public function render($parameters)
{
- $this->setText($parameters);
+ if ($parameters != null)
+ {
+ $this->setText($parameters);
+ }
+ else
+ {
+ $this->setText('');
+ }
$this->loadTextareaView();
@@ -954,6 +983,147 @@ class TextareaWidgetUDF extends TextareaWidget
}
}
+/**
+ * It exends the Widget class to represent an HTML textarea
+ */
+class TextfieldWidget extends Widget
+{
+ const VALUE = 'text'; //
+ const SIZE = 'size'; //
+
+ /**
+ *
+ */
+ protected function setValue($value)
+ {
+ $this->_args[TextfieldWidget::VALUE] = $value;
+ }
+
+ /**
+ *
+ */
+ protected function loadTextfieldView()
+ {
+ $this->view('widgets/textfield', $this->_args);
+ }
+}
+
+/**
+ *
+ */
+class TextfieldWidgetUDF extends TextfieldWidget
+{
+ /**
+ *
+ */
+ public function render($parameters)
+ {
+ if ($parameters != null)
+ {
+ $this->setValue($parameters);
+ }
+ else
+ {
+ $this->setValue('');
+ }
+
+ $this->loadTextfieldView();
+
+ echo $this->content();
+ }
+}
+
+/**
+ * It exends the Widget class to represent an HTML dropdown
+ */
+class CheckboxWidget extends Widget
+{
+ // The name of the element of the data array given to the view
+ // this element is an array of elements to be place inside the dropdown
+ const WIDGET_DATA_VALUES_ARRAY_NAME = 'VALUES_ARRAY';
+ // The name of the element of the data array given to the view
+ // this element is used to tell what element of the dropdown is selected
+ const CHECKED_VALUE = 'checkedValue';
+
+ /**
+ *
+ */
+ public function __construct($name, $args, $htmlArgs = array())
+ {
+ parent::__construct($name, $args, $htmlArgs);
+
+ //
+ if (!isset($this->_args[CheckboxWidget::CHECKED_VALUE]))
+ {
+ $this->_args[CheckboxWidget::CHECKED_VALUE] = Widget::HTML_DEFAULT_VALUE;
+ }
+ }
+
+ /**
+ *
+ */
+ protected function setValuesArray($values)
+ {
+ if (isError($values))
+ {
+ if (is_object($values) && isset($values->retval))
+ {
+ show_error($values->retval);
+ }
+ else if (is_string($values))
+ {
+ show_error($values);
+ }
+ else
+ {
+ show_error('Generic error occurred');
+ }
+ }
+ else
+ {
+ $this->_args[CheckboxWidget::WIDGET_DATA_VALUES_ARRAY_NAME] = $values->retval;
+ }
+ }
+
+ /**
+ *
+ */
+ protected function loadCheckboxView()
+ {
+ $this->view('widgets/checkbox', $this->_args);
+ }
+}
+
+/**
+ *
+ */
+class CheckboxWidgetUDF extends CheckboxWidget
+{
+ /**
+ *
+ */
+ public function render($parameters)
+ {
+ $tmpValues = array();
+
+ //
+ foreach($parameters as $parameter)
+ {
+ //
+ if (is_string($parameter) || is_numeric($parameter))
+ {
+ array_push($tmpValues, $parameter); //
+ }
+ }
+
+ $this->setValuesArray(success($tmpValues));
+
+ $this->loadCheckboxView();
+
+ echo $this->content();
+ }
+}
+
/**
*
*/
diff --git a/application/models/system/UDF_model.php b/application/models/system/UDF_model.php
index 85bfec8bd..e33cdd275 100644
--- a/application/models/system/UDF_model.php
+++ b/application/models/system/UDF_model.php
@@ -12,4 +12,31 @@ class UDF_model extends DB_Model
$this->pk = array('schema', 'table');
$this->hasSequence = false;
}
+
+ /**
+ *
+ */
+ public function execQuery($query, $parametersArray = null)
+ {
+ //
+ if (
+ (
+ substr($query, 0, 6) == 'SELECT'
+ || substr($query, 0, 4) == 'WITH'
+ )
+ &&
+ (
+ !stripos($query, 'INSERT')
+ && !stripos($query, 'UPDATE')
+ && !stripos($query, 'DELETE')
+ )
+ )
+ {
+ return parent::execQuery($query, $parametersArray);
+ }
+ else
+ {
+ return error('You are allowed to run only query for reading data');
+ }
+ }
}
\ No newline at end of file
diff --git a/application/views/system/testudf.php b/application/views/system/testudf.php
index d8f3439d4..1d5815446 100644
--- a/application/views/system/testudf.php
+++ b/application/views/system/testudf.php
@@ -6,12 +6,87 @@
widgetlib->UDFWidget(
array(
- UDFWidgetTpl::SCHEMA_ARG_NAME => $schema,
- UDFWidgetTpl::TABLE_ARG_NAME => $table,
- UDFWidgetTpl::FIELD_ARG_NAME => $field,
- DropdownWidget::SELECTED_ELEMENT => $selected
+ UDFWidgetTpl::SCHEMA_ARG_NAME => 'public',
+ UDFWidgetTpl::TABLE_ARG_NAME => 'tbl_person',
+ UDFWidgetTpl::FIELD_ARG_NAME => 'schuhgroesse',
+ DropdownWidget::SELECTED_ELEMENT => array(42, 44)
),
- array('id' => 'schuhgroesseID', 'name' => 'schuhgroesseName', 'size' => '6')
+ array('id' => 'schuhgroesseID', 'name' => 'schuhgroesseName', 'size' => '9')
+ );
+ ?>
+
+
+
+
+