mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-06-01 20:29:29 +00:00
- Changed controller system/FAS_UDF, less busy now
- Method execReadOnlyQuery of DB_Model less strict check against SQL statements - Added new public method setup to DB_Model to setup the model after initialization - Added new constants to UDFLib - Added new private method _printEndUDFBlock and _printEndUDFBlock to UDFLib - Added new public methods setUDFUniqueId, getSession, getSessionElement, setSession, setSessionElement, saveUDFs and isAllowed to UDFLib - Removed model system/FAS_UDF_model - View views/system/fas_udf now uses the view templates/FHC-Header - Added new parameter udfs to view templates/FHC-Header - Added new properties to UDFWidget - Added new private methods _initUDFWidget, _checkParameters and _startUDFWidget to UDFWidget
This commit is contained in:
@@ -24,43 +24,15 @@ class FAS_UDF extends Auth_Controller
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$fasUdfSession = getSession(self::FAS_UDF_SESSION_NAME);
|
||||
|
||||
$person_id = $this->input->get('person_id');
|
||||
if (isset($fasUdfSession['person_id']))
|
||||
{
|
||||
if (!isset($person_id))
|
||||
{
|
||||
$person_id = $fasUdfSession['person_id'];
|
||||
}
|
||||
unset($fasUdfSession['person_id']);
|
||||
}
|
||||
|
||||
$prestudent_id = $this->input->get('prestudent_id');
|
||||
if (isset($fasUdfSession['prestudent_id']))
|
||||
{
|
||||
if (!isset($prestudent_id))
|
||||
{
|
||||
$prestudent_id = $fasUdfSession['prestudent_id'];
|
||||
}
|
||||
unset($fasUdfSession['prestudent_id']);
|
||||
}
|
||||
|
||||
$result = null;
|
||||
if (isset($fasUdfSession['result']))
|
||||
{
|
||||
$result = clone $fasUdfSession['result'];
|
||||
setSessionElement(self::FAS_UDF_SESSION_NAME, 'result', null);
|
||||
}
|
||||
|
||||
$data = array('result' => $result);
|
||||
|
||||
if (isset($person_id) && is_numeric($person_id))
|
||||
{
|
||||
if ($this->PersonModel->hasUDF())
|
||||
{
|
||||
$personUdfs = $this->PersonModel->getUDFs($person_id);
|
||||
$personUdfs['person_id'] = $person_id;
|
||||
$data['person_id'] = $person_id;
|
||||
$data['personUdfs'] = $personUdfs;
|
||||
}
|
||||
}
|
||||
@@ -70,61 +42,11 @@ class FAS_UDF extends Auth_Controller
|
||||
if ($this->PrestudentModel->hasUDF())
|
||||
{
|
||||
$prestudentUdfs = $this->PrestudentModel->getUDFs($prestudent_id);
|
||||
$prestudentUdfs['prestudent_id'] = $prestudent_id;
|
||||
$data['prestudent_id'] = $prestudent_id;
|
||||
$data['prestudentUdfs'] = $prestudentUdfs;
|
||||
}
|
||||
}
|
||||
|
||||
$this->load->view('system/fas_udf', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function saveUDF()
|
||||
{
|
||||
$udfs = $this->input->post();
|
||||
$validation = $this->_validate($udfs);
|
||||
|
||||
$userdata = array(
|
||||
'person_id' => $this->input->post('person_id'),
|
||||
'prestudent_id' => $this->input->post('prestudent_id')
|
||||
);
|
||||
|
||||
if (isSuccess($validation))
|
||||
{
|
||||
// Load model UDF_model
|
||||
$this->load->model('system/FAS_UDF_model', 'FASUDFModel');
|
||||
|
||||
$result = $this->FASUDFModel->saveUDFs($udfs);
|
||||
|
||||
$userdata['result'] = $result;
|
||||
}
|
||||
else
|
||||
{
|
||||
$userdata['result'] = $validation;
|
||||
}
|
||||
|
||||
setSessionElement(self::FAS_UDF_SESSION_NAME, 'person_id', $userdata['person_id']);
|
||||
setSessionElement(self::FAS_UDF_SESSION_NAME, 'prestudent_id', $userdata['prestudent_id']);
|
||||
setSessionElement(self::FAS_UDF_SESSION_NAME, 'result', $userdata['result']);
|
||||
|
||||
redirect('system/FAS_UDF');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function _validate($udfs)
|
||||
{
|
||||
$validation = error('person_id or prestudent_id is missing');
|
||||
|
||||
if((isset($udfs['person_id']) && !(is_null($udfs['person_id'])) && ($udfs['person_id'] != ''))
|
||||
|| (isset($udfs['prestudent_id']) && !(is_null($udfs['prestudent_id'])) && ($udfs['prestudent_id'] != '')))
|
||||
{
|
||||
$validation = success(true);
|
||||
}
|
||||
|
||||
return $validation;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
if (! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* This controller...
|
||||
*/
|
||||
class UDF extends FHC_Controller
|
||||
{
|
||||
const UDF_UNIQUE_ID = 'udfUniqueId';
|
||||
|
||||
/**
|
||||
* Calls the parent's constructor and loads the
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
// Loads authentication library and starts authentication
|
||||
$this->load->library('AuthLib');
|
||||
|
||||
// Loads the UDFLib with HTTP GET/POST parameters
|
||||
$this->_loadUDFLib();
|
||||
|
||||
// Checks if the caller is allow to read this data
|
||||
$this->_isAllowed();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
// Public methods
|
||||
|
||||
/**
|
||||
* Retrieves data about the current filter from the session and will be written on the output in JSON format
|
||||
*/
|
||||
public function saveUDFs()
|
||||
{
|
||||
$udfUniqueId = $this->input->post(self::UDF_UNIQUE_ID);
|
||||
$udfs = $this->input->post(UDFLib::UDFS_ARG_NAME);
|
||||
|
||||
if (!isEmptyString($udfs))
|
||||
{
|
||||
$jsonDecodedUDF = json_decode($udfs);
|
||||
if ($jsonDecodedUDF != null)
|
||||
{
|
||||
$this->outputJson($this->udflib->saveUDFs($udfUniqueId, $jsonDecodedUDF));
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->outputJsonError('No valid JSON format for UDF values');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->outputJsonError('UDFUniqueId, schema, table name, primary key name and primary key value are mandatory paramenters');
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
// Private methods
|
||||
|
||||
/**
|
||||
* Checks if the user is allowed to use this filter
|
||||
*/
|
||||
private function _isAllowed()
|
||||
{
|
||||
if (!$this->udflib->isAllowed())
|
||||
{
|
||||
$this->terminateWithJsonError('You are not allowed to access to this content');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the tablewidgetlib with the UDF_UNIQUE_ID parameter
|
||||
* If the parameter UDF_UNIQUE_ID is not given then the execution of the controller is terminated and
|
||||
* an error message is printed
|
||||
*/
|
||||
private function _loadUDFLib()
|
||||
{
|
||||
// If the parameter UDF_UNIQUE_ID is present in the HTTP GET or POST
|
||||
if (isset($_GET[self::UDF_UNIQUE_ID]) || isset($_POST[self::UDF_UNIQUE_ID]))
|
||||
{
|
||||
// If it is present in the HTTP GET
|
||||
if (isset($_GET[self::UDF_UNIQUE_ID]))
|
||||
{
|
||||
$udfUniqueId = $this->input->get(self::UDF_UNIQUE_ID); // is retrieved from the HTTP GET
|
||||
}
|
||||
elseif (isset($_POST[self::UDF_UNIQUE_ID])) // Else if it is present in the HTTP POST
|
||||
{
|
||||
$udfUniqueId = $this->input->post(self::UDF_UNIQUE_ID); // is retrieved from the HTTP POST
|
||||
}
|
||||
|
||||
// Loads the tablewidgetlib that contains all the used logic
|
||||
$this->load->library('UDFLib');
|
||||
|
||||
$this->udflib->setUDFUniqueId($udfUniqueId);
|
||||
}
|
||||
else // Otherwise an error will be written in the output
|
||||
{
|
||||
$this->terminateWithJsonError('Parameter "'.self::UDF_UNIQUE_ID.'" not provided!');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -60,6 +60,20 @@ class DB_Model extends CI_Model
|
||||
// ------------------------------------------------------------------------------------------
|
||||
// Public methods
|
||||
|
||||
/**
|
||||
* This method provides a way to setup a database model without declaring one
|
||||
*/
|
||||
public function setup($schema, $table, $primaryKey, $hasSequence = true)
|
||||
{
|
||||
//
|
||||
if (!isEmptyString($schema) && !isEmptyString($table) && !isEmptyString($primaryKey) && is_bool($hasSequence))
|
||||
{
|
||||
$this->dbTable = $schema.'.'.$table;
|
||||
$this->pk = $primaryKey;
|
||||
$this->hasSequence = $hasSequence;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert Data into DB-Table
|
||||
*
|
||||
@@ -690,7 +704,7 @@ class DB_Model extends CI_Model
|
||||
*/
|
||||
public function hasUDF()
|
||||
{
|
||||
if($this->fieldExists(UDFLib::COLUMN_NAME))
|
||||
if ($this->fieldExists(UDFLib::COLUMN_NAME))
|
||||
{
|
||||
$resultUDFsDefinitions = $this->UDFModel->getUDFsDefinitions($this->dbTable);
|
||||
if (hasData($resultUDFsDefinitions))
|
||||
@@ -727,8 +741,8 @@ class DB_Model extends CI_Model
|
||||
$cleanedQuery = trim(preg_replace('/\t|\n|\r|;/', '', $query)); //
|
||||
|
||||
//
|
||||
if (stripos($cleanedQuery, 'SELECT') == 0
|
||||
&& (stripos($cleanedQuery, 'INSERT') > 0 || stripos($cleanedQuery, 'INSERT') == false)
|
||||
if (
|
||||
(stripos($cleanedQuery, 'INSERT') > 0 || stripos($cleanedQuery, 'INSERT') == false)
|
||||
&& (stripos($cleanedQuery, 'UPDATE') > 0 || stripos($cleanedQuery, 'UPDATE') == false)
|
||||
&& (stripos($cleanedQuery, 'CREATE') > 0 || stripos($cleanedQuery, 'CREATE') == false)
|
||||
&& (stripos($cleanedQuery, 'DELETE') > 0 || stripos($cleanedQuery, 'DELETE') == false)
|
||||
|
||||
+273
-112
@@ -7,6 +7,10 @@ if (! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
*/
|
||||
class UDFLib
|
||||
{
|
||||
const UDF_UNIQUE_ID = 'udfUniqueId';
|
||||
|
||||
const SESSION_NAME = 'FHC_UDF_WIDGET';
|
||||
|
||||
const WIDGET_NAME = 'UDFWidget';
|
||||
const SCHEMA_ARG_NAME = 'schema';
|
||||
const TABLE_ARG_NAME = 'table';
|
||||
@@ -22,6 +26,16 @@ class UDFLib
|
||||
const FE_REGEX_LANGUAGE = 'js'; // UDF javascript regex language attribute (front end)
|
||||
const BE_REGEX_LANGUAGE = 'php'; // UDF php regex language attribute (back end)
|
||||
|
||||
// ...to specify permissions that are needed to use this TableWidget
|
||||
const REQUIRED_PERMISSIONS_PARAMETER = 'requiredPermissions';
|
||||
|
||||
// ...
|
||||
const PRIMARY_KEY_NAME = 'primaryKeyName';
|
||||
const PRIMARY_KEY_VALUE = 'primaryKeyValue';
|
||||
|
||||
const PERMISSION_TABLE_METHOD = 'UDFWidget'; // Name for fake method to be checked by the PermissionLib
|
||||
const PERMISSION_TYPE = 'rw';
|
||||
|
||||
// HTML components
|
||||
const LABEL = 'title';
|
||||
const TITLE = 'description';
|
||||
@@ -47,6 +61,8 @@ class UDFLib
|
||||
|
||||
private $_ci; // Code igniter instance
|
||||
|
||||
private $_udfUniqueId; //
|
||||
|
||||
/**
|
||||
* Loads fhc helper
|
||||
*/
|
||||
@@ -63,8 +79,8 @@ class UDFLib
|
||||
*/
|
||||
public function UDFWidget($args, $htmlArgs = array())
|
||||
{
|
||||
if ((isset($args[UDFLib::SCHEMA_ARG_NAME]) && !isEmptyString($args[UDFLib::SCHEMA_ARG_NAME]))
|
||||
&& (isset($args[UDFLib::TABLE_ARG_NAME]) && !isEmptyString($args[UDFLib::TABLE_ARG_NAME])))
|
||||
if ((isset($args[self::SCHEMA_ARG_NAME]) && !isEmptyString($args[self::SCHEMA_ARG_NAME]))
|
||||
&& (isset($args[self::TABLE_ARG_NAME]) && !isEmptyString($args[self::TABLE_ARG_NAME])))
|
||||
{
|
||||
// Loads the widget library
|
||||
$this->_ci->load->library('WidgetLib');
|
||||
@@ -73,26 +89,26 @@ class UDFLib
|
||||
loadResource(APPPATH.'widgets/udf');
|
||||
|
||||
// Default external block is true
|
||||
if (!isset($args[UDFLib::FIELD_ARG_NAME]) && !isset($htmlArgs[HTMLWidget::EXTERNAL_BLOCK]))
|
||||
if (!isset($args[self::FIELD_ARG_NAME]) && !isset($htmlArgs[HTMLWidget::EXTERNAL_BLOCK]))
|
||||
{
|
||||
$htmlArgs[HTMLWidget::EXTERNAL_BLOCK] = true;
|
||||
}
|
||||
|
||||
return $this->_ci->widgetlib->widget(
|
||||
UDFLib::WIDGET_NAME,
|
||||
self::WIDGET_NAME,
|
||||
$args,
|
||||
$htmlArgs
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!isset($args[UDFLib::SCHEMA_ARG_NAME]) || isEmptyString($args[UDFLib::SCHEMA_ARG_NAME]))
|
||||
if (!isset($args[self::SCHEMA_ARG_NAME]) || isEmptyString($args[self::SCHEMA_ARG_NAME]))
|
||||
{
|
||||
show_error(UDFLib::SCHEMA_ARG_NAME.' parameter is missing!');
|
||||
show_error(self::SCHEMA_ARG_NAME.' parameter is missing!');
|
||||
}
|
||||
if (!isset($args[UDFLib::TABLE_ARG_NAME]) || isEmptyString($args[UDFLib::TABLE_ARG_NAME]))
|
||||
if (!isset($args[self::TABLE_ARG_NAME]) || isEmptyString($args[self::TABLE_ARG_NAME]))
|
||||
{
|
||||
show_error(UDFLib::TABLE_ARG_NAME.' parameter is missing!');
|
||||
show_error(self::TABLE_ARG_NAME.' parameter is missing!');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -105,12 +121,12 @@ class UDFLib
|
||||
*/
|
||||
public function displayUDFWidget(&$widgetData)
|
||||
{
|
||||
$schema = $widgetData[UDFLib::SCHEMA_ARG_NAME]; // schema attribute
|
||||
$table = $widgetData[UDFLib::TABLE_ARG_NAME]; // table attribute
|
||||
$schema = $widgetData[self::SCHEMA_ARG_NAME]; // schema attribute
|
||||
$table = $widgetData[self::TABLE_ARG_NAME]; // table attribute
|
||||
|
||||
if (isset($widgetData[UDFLib::FIELD_ARG_NAME]))
|
||||
if (isset($widgetData[self::FIELD_ARG_NAME]))
|
||||
{
|
||||
$field = $widgetData[UDFLib::FIELD_ARG_NAME]; // UDF name
|
||||
$field = $widgetData[self::FIELD_ARG_NAME]; // UDF name
|
||||
}
|
||||
|
||||
$udfResults = $this->_loadUDF($schema, $table); // loads UDF definition
|
||||
@@ -122,6 +138,9 @@ class UDFLib
|
||||
$jsonSchemas = json_decode($udf->jsons); // decode the json schema
|
||||
if (is_object($jsonSchemas) || is_array($jsonSchemas))
|
||||
{
|
||||
//
|
||||
$this->_printStartUDFBlock($widgetData);
|
||||
|
||||
// If the schema is an object then convert it into an array
|
||||
if (is_object($jsonSchemas))
|
||||
{
|
||||
@@ -140,18 +159,18 @@ class UDFLib
|
||||
foreach ($jsonSchemasArray as $jsonSchema)
|
||||
{
|
||||
// If the type property is not present then show an error
|
||||
if (!isset($jsonSchema->{UDFLib::TYPE}))
|
||||
if (!isset($jsonSchema->{self::TYPE}))
|
||||
{
|
||||
show_error(sprintf('%s.%s: Attribute "type" not present in the json schema', $schema, $table));
|
||||
}
|
||||
// If the name property is not present then show an error
|
||||
if (!isset($jsonSchema->{UDFLib::NAME}))
|
||||
if (!isset($jsonSchema->{self::NAME}))
|
||||
{
|
||||
show_error(sprintf('%s.%s: Attribute "name" not present in the json schema', $schema, $table));
|
||||
}
|
||||
|
||||
// If a UDF is specified and is present in the json schemas list or no UDF is specified
|
||||
if ((isset($field) && $field == $jsonSchema->{UDFLib::NAME}) || !isset($field))
|
||||
if ((isset($field) && $field == $jsonSchema->{self::NAME}) || !isset($field))
|
||||
{
|
||||
// Set attributes using phrases
|
||||
$this->_setAttributesWithPhrases($jsonSchema, $widgetData[HTMLWidget::HTML_ARG_NAME]);
|
||||
@@ -166,7 +185,7 @@ class UDFLib
|
||||
$this->_render($jsonSchema, $widgetData);
|
||||
|
||||
// If a UDf is specified and it was found then stop looking through this list
|
||||
if (isset($field) && $field == $jsonSchema->{UDFLib::NAME})
|
||||
if (isset($field) && $field == $jsonSchema->{self::NAME})
|
||||
{
|
||||
$found = true;
|
||||
break;
|
||||
@@ -179,6 +198,9 @@ class UDFLib
|
||||
{
|
||||
show_error(sprintf('%s.%s: No schema present for field: %s', $schema, $table, $field));
|
||||
}
|
||||
|
||||
//
|
||||
$this->_printEndUDFBlock();
|
||||
}
|
||||
else // not a valid schema
|
||||
{
|
||||
@@ -218,7 +240,7 @@ class UDFLib
|
||||
|
||||
// Decodes json that define the UDFs for this table
|
||||
$decodedUDFDefinitions = json_decode(
|
||||
$resultUDFsDefinitions->retval[0]->{UDFLib::COLUMN_JSON_DESCRIPTION}
|
||||
$resultUDFsDefinitions->retval[0]->{self::COLUMN_JSON_DESCRIPTION}
|
||||
);
|
||||
|
||||
// Loops through the UDFs definitions
|
||||
@@ -232,28 +254,28 @@ class UDFLib
|
||||
$tmpValidate = success(true); // temporary variable used to store the returned value from _validateUDFs
|
||||
|
||||
// If this is the definition of this UDF
|
||||
if ($decodedUDFDefinition->{UDFLib::NAME} == $key)
|
||||
if ($decodedUDFDefinition->{self::NAME} == $key)
|
||||
{
|
||||
if (isset($decodedUDFDefinition->{UDFLib::VALIDATION})) // If validation rules are present for this UDF
|
||||
if (isset($decodedUDFDefinition->{self::VALIDATION})) // If validation rules are present for this UDF
|
||||
{
|
||||
// Checks if the given UDF is required and the result will be stored in $chkRequiredPassed
|
||||
// If $chkRequiredPassed == true => required check passed
|
||||
// If $chkRequiredPassed == false => required check NOT passed
|
||||
$chkRequiredPassed = true;
|
||||
// If required property is present in the UDF description and it is true
|
||||
if (isset($decodedUDFDefinition->{UDFLib::VALIDATION}->{UDFLib::REQUIRED})
|
||||
&& $decodedUDFDefinition->{UDFLib::VALIDATION}->{UDFLib::REQUIRED} === true)
|
||||
if (isset($decodedUDFDefinition->{self::VALIDATION}->{self::REQUIRED})
|
||||
&& $decodedUDFDefinition->{self::VALIDATION}->{self::REQUIRED} === true)
|
||||
{
|
||||
// If this UDF is a checkbox and the given value is false
|
||||
// OR
|
||||
// if this UDF is NOT a checkbox and the given value is null
|
||||
if (($decodedUDFDefinition->{UDFLib::TYPE} == UDFLib::CHKBOX_TYPE && $val === false)
|
||||
|| ($decodedUDFDefinition->{UDFLib::TYPE} != UDFLib::CHKBOX_TYPE && $val == null))
|
||||
// if this UD7F is NOT a checkbox and the given value is null
|
||||
if (($decodedUDFDefinition->{self::TYPE} == self::CHKBOX_TYPE && $val === false)
|
||||
|| ($decodedUDFDefinition->{self::TYPE} != self::CHKBOX_TYPE && $val == null))
|
||||
{
|
||||
$chkRequiredPassed = false; // not passed
|
||||
// A new error is generated and added to array $requiredUDFsArray
|
||||
$requiredUDFsArray[$decodedUDFDefinition->{UDFLib::NAME}] = error(
|
||||
$decodedUDFDefinition->{UDFLib::NAME},
|
||||
$requiredUDFsArray[$decodedUDFDefinition->{self::NAME}] = error(
|
||||
$decodedUDFDefinition->{self::NAME},
|
||||
EXIT_VALIDATION_UDF_REQUIRED
|
||||
);
|
||||
}
|
||||
@@ -267,22 +289,22 @@ class UDFLib
|
||||
// If $toBeValidated == false => validation is NOT performed
|
||||
$toBeValidated = false;
|
||||
// If this UDF is NOT a checkbox
|
||||
if ($decodedUDFDefinition->{UDFLib::TYPE} != UDFLib::CHKBOX_TYPE)
|
||||
if ($decodedUDFDefinition->{self::TYPE} != self::CHKBOX_TYPE)
|
||||
{
|
||||
// If required property is NOT present in the UDF description
|
||||
if (!isset($decodedUDFDefinition->{UDFLib::VALIDATION}->{UDFLib::REQUIRED}))
|
||||
if (!isset($decodedUDFDefinition->{self::VALIDATION}->{self::REQUIRED}))
|
||||
{
|
||||
$toBeValidated = true;
|
||||
}
|
||||
// If required property is present in the UDF description and it is true
|
||||
if (isset($decodedUDFDefinition->{UDFLib::VALIDATION}->{UDFLib::REQUIRED})
|
||||
&& $decodedUDFDefinition->{UDFLib::VALIDATION}->{UDFLib::REQUIRED} === true)
|
||||
if (isset($decodedUDFDefinition->{self::VALIDATION}->{self::REQUIRED})
|
||||
&& $decodedUDFDefinition->{self::VALIDATION}->{self::REQUIRED} === true)
|
||||
{
|
||||
$toBeValidated = true;
|
||||
}
|
||||
// If required property is present in the UDF description and it is true and the given value is null
|
||||
if (isset($decodedUDFDefinition->{UDFLib::VALIDATION}->{UDFLib::REQUIRED})
|
||||
&& $decodedUDFDefinition->{UDFLib::VALIDATION}->{UDFLib::REQUIRED} === false
|
||||
if (isset($decodedUDFDefinition->{self::VALIDATION}->{self::REQUIRED})
|
||||
&& $decodedUDFDefinition->{self::VALIDATION}->{self::REQUIRED} === false
|
||||
&& $val != null)
|
||||
{
|
||||
$toBeValidated = true;
|
||||
@@ -292,8 +314,8 @@ class UDFLib
|
||||
if ($toBeValidated === true) // Checks if validation should be performed
|
||||
{
|
||||
$tmpValidate = $this->_validateUDFs(
|
||||
$decodedUDFDefinition->{UDFLib::VALIDATION},
|
||||
$decodedUDFDefinition->{UDFLib::NAME},
|
||||
$decodedUDFDefinition->{self::VALIDATION},
|
||||
$decodedUDFDefinition->{self::NAME},
|
||||
$val
|
||||
);
|
||||
}
|
||||
@@ -341,7 +363,7 @@ class UDFLib
|
||||
if ($encodedToBeStoredUDFs !== false) // if encode was ok
|
||||
{
|
||||
// Save the supplied UDFs values
|
||||
$data[UDFLib::COLUMN_NAME] = $encodedToBeStoredUDFs;
|
||||
$data[self::COLUMN_NAME] = $encodedToBeStoredUDFs;
|
||||
}
|
||||
}
|
||||
else // otherwise the returning value will be the list of UDFs validation errors
|
||||
@@ -360,8 +382,8 @@ class UDFLib
|
||||
{
|
||||
$isUDFColumn = false;
|
||||
|
||||
if (substr($columnName, 0, strlen(UDFLib::COLUMN_PREFIX)) == UDFLib::COLUMN_PREFIX
|
||||
&& $columnType == UDFLib::COLUMN_TYPE)
|
||||
if (substr($columnName, 0, strlen(self::COLUMN_PREFIX)) == self::COLUMN_PREFIX
|
||||
&& $columnType == self::COLUMN_TYPE)
|
||||
{
|
||||
$isUDFColumn = true;
|
||||
}
|
||||
@@ -369,9 +391,148 @@ class UDFLib
|
||||
return $isUDFColumn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the _udfUniqueId property
|
||||
*/
|
||||
public function setUDFUniqueId($udfUniqueId)
|
||||
{
|
||||
$this->_udfUniqueId = $udfUniqueId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an unique string that identify this filter widget
|
||||
* NOTE: The default value is the URI where the FilterWidget is called
|
||||
* If the fhc_controller_id is present then is also used
|
||||
*/
|
||||
public function setUDFUniqueIdByParams($params)
|
||||
{
|
||||
if ($params != null
|
||||
&& is_array($params)
|
||||
&& isset($params[self::UDF_UNIQUE_ID])
|
||||
&& !isEmptyString($params[self::UDF_UNIQUE_ID]))
|
||||
{
|
||||
$udfUniqueId = $this->_ci->router->directory.$this->_ci->router->class.'/'.
|
||||
$this->_ci->router->method.'/'.
|
||||
$params[self::UDF_UNIQUE_ID];
|
||||
|
||||
$this->setUDFUniqueId($udfUniqueId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper method to the session helper funtions to retrieve the whole session for this filter
|
||||
*/
|
||||
public function getSession()
|
||||
{
|
||||
return getSessionElement(self::SESSION_NAME, $this->_udfUniqueId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper method to the session helper funtions to retrieve one element from the session of this filter
|
||||
*/
|
||||
public function getSessionElement($name)
|
||||
{
|
||||
$session = getSessionElement(self::SESSION_NAME, $this->_udfUniqueId);
|
||||
|
||||
if (isset($session[$name]))
|
||||
{
|
||||
return $session[$name];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper method to the session helper funtions to set the whole session for this filter
|
||||
*/
|
||||
public function setSession($data)
|
||||
{
|
||||
setSessionElement(self::SESSION_NAME, $this->_udfUniqueId, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper method to the session helper funtions to set one element in the session for this filter
|
||||
*/
|
||||
public function setSessionElement($name, $value)
|
||||
{
|
||||
$session = getSessionElement(self::SESSION_NAME, $this->_udfUniqueId);
|
||||
|
||||
$session[$name] = $value;
|
||||
|
||||
setSessionElement(self::SESSION_NAME, $this->_udfUniqueId, $session); // stores the single value
|
||||
}
|
||||
|
||||
/**
|
||||
* Save UDFs
|
||||
*/
|
||||
public function saveUDFs($udfUniqueId, $udfs)
|
||||
{
|
||||
// Read the all session for this udf widget
|
||||
$session = $this->getSession();
|
||||
|
||||
if ($session == null) return error('No UDFWidget loaded');
|
||||
|
||||
// Workaround
|
||||
$this->_ci->load->model('system/UDF_model', 'UDFModel');
|
||||
|
||||
//
|
||||
$dbModel = new DB_Model();
|
||||
|
||||
$dbModel->setup(
|
||||
$session[self::SCHEMA_ARG_NAME], //
|
||||
$session[self::TABLE_ARG_NAME], //
|
||||
$session[self::PRIMARY_KEY_NAME] //
|
||||
);
|
||||
|
||||
return $dbModel->update(
|
||||
array($session[self::PRIMARY_KEY_NAME] => $session[self::PRIMARY_KEY_VALUE]),
|
||||
(array)$udfs
|
||||
);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------
|
||||
// Private methods
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function _printStartUDFBlock($widgetData)
|
||||
{
|
||||
$startBlock = '<div type="%s" udfUniqueId="%s">'."\n";
|
||||
|
||||
echo sprintf(
|
||||
$startBlock,
|
||||
self::WIDGET_NAME,
|
||||
$widgetData[self::UDF_UNIQUE_ID]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function _printEndUDFBlock()
|
||||
{
|
||||
echo '</div>'."\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if at least one of the permissions given as parameter (requiredPermissions) belongs
|
||||
* to the authenticated user, if confirmed then is allowed to use this FilterWidget.
|
||||
* If the parameter requiredPermissions is NOT given or is not present in the session,
|
||||
* then NO one is allow to use this FilterWidget
|
||||
* Wrapper method to permissionlib->hasAtLeastOne
|
||||
*/
|
||||
public function isAllowed($requiredPermissions = null)
|
||||
{
|
||||
$this->_ci->load->library('PermissionLib'); // Load permission library
|
||||
|
||||
// Gets the required permissions from the session if they are not provided as parameter
|
||||
$rq = $requiredPermissions;
|
||||
if ($rq == null) $rq = $this->getSessionElement(self::REQUIRED_PERMISSIONS_PARAMETER);
|
||||
|
||||
return $this->_ci->permissionlib->hasAtLeastOne($rq, self::PERMISSION_TABLE_METHOD, self::PERMISSION_TYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move UDFs from $data to $UDFs
|
||||
*/
|
||||
@@ -381,7 +542,7 @@ class UDFLib
|
||||
|
||||
foreach ($data as $key => $val)
|
||||
{
|
||||
if (substr($key, 0, 4) == UDFLib::COLUMN_PREFIX)
|
||||
if (substr($key, 0, 4) == self::COLUMN_PREFIX)
|
||||
{
|
||||
$udfsParameters[$key] = $val; // stores UDF value into property UDFs
|
||||
unset($data[$key]); // remove from data
|
||||
@@ -416,8 +577,8 @@ class UDFLib
|
||||
{
|
||||
// If min value attribute is present in the validation for this UDF,
|
||||
// then checks if the value of this UDF is compliant to this attribute
|
||||
if (isset($decodedUDFValidation->{UDFLib::MIN_VALUE})
|
||||
&& $udfVal < $decodedUDFValidation->{UDFLib::MIN_VALUE})
|
||||
if (isset($decodedUDFValidation->{self::MIN_VALUE})
|
||||
&& $udfVal < $decodedUDFValidation->{self::MIN_VALUE})
|
||||
{
|
||||
// validation is failed and the error is stored in $returnArrayValidation
|
||||
$returnArrayValidation[] = error($udfName, EXIT_VALIDATION_UDF_MIN_VALUE);
|
||||
@@ -425,8 +586,8 @@ class UDFLib
|
||||
|
||||
// If max value attribute is present in the validation for this UDF,
|
||||
// then checks if the value of this UDF is compliant to this attribute
|
||||
if (isset($decodedUDFValidation->{UDFLib::MAX_VALUE})
|
||||
&& $udfVal > $decodedUDFValidation->{UDFLib::MAX_VALUE})
|
||||
if (isset($decodedUDFValidation->{self::MAX_VALUE})
|
||||
&& $udfVal > $decodedUDFValidation->{self::MAX_VALUE})
|
||||
{
|
||||
// validation is failed and the error is stored in $returnArrayValidation
|
||||
$returnArrayValidation[] = error($udfName, EXIT_VALIDATION_UDF_MAX_VALUE);
|
||||
@@ -436,8 +597,8 @@ class UDFLib
|
||||
$strUdfVal = strval($udfVal); // store in $strUdfVal the string conversion of $udfVal
|
||||
// If min length attribute is present in the validation for this UDF,
|
||||
// then checks if the value of this UDF is compliant to this attribute
|
||||
if (isset($decodedUDFValidation->{UDFLib::MIN_LENGTH}) && isset($strUdfVal)
|
||||
&& strlen($strUdfVal) < $decodedUDFValidation->{UDFLib::MIN_LENGTH})
|
||||
if (isset($decodedUDFValidation->{self::MIN_LENGTH}) && isset($strUdfVal)
|
||||
&& strlen($strUdfVal) < $decodedUDFValidation->{self::MIN_LENGTH})
|
||||
{
|
||||
// validation is failed and the error is stored in $returnArrayValidation
|
||||
$returnArrayValidation[] = error($udfName, EXIT_VALIDATION_UDF_MIN_LENGTH);
|
||||
@@ -445,8 +606,8 @@ class UDFLib
|
||||
|
||||
// If max length attribute is present in the validation for this UDF,
|
||||
// then checks if the value of this UDF is compliant to this attribute
|
||||
if (isset($decodedUDFValidation->{UDFLib::MAX_LENGTH}) && isset($strUdfVal)
|
||||
&& strlen($strUdfVal) > $decodedUDFValidation->{UDFLib::MAX_LENGTH})
|
||||
if (isset($decodedUDFValidation->{self::MAX_LENGTH}) && isset($strUdfVal)
|
||||
&& strlen($strUdfVal) > $decodedUDFValidation->{self::MAX_LENGTH})
|
||||
{
|
||||
// validation is failed and the error is stored in $returnArrayValidation
|
||||
$returnArrayValidation[] = error($udfName, EXIT_VALIDATION_UDF_MAX_LENGTH);
|
||||
@@ -457,12 +618,12 @@ class UDFLib
|
||||
{
|
||||
// Search for a php regular expression in the validation of this UDF, if one is found
|
||||
// then checks if the value of this UDF is compliant to this attribute
|
||||
if (isset($decodedUDFValidation->{UDFLib::REGEX})
|
||||
&& is_array($decodedUDFValidation->{UDFLib::REGEX}))
|
||||
if (isset($decodedUDFValidation->{self::REGEX})
|
||||
&& is_array($decodedUDFValidation->{self::REGEX}))
|
||||
{
|
||||
foreach ($decodedUDFValidation->{UDFLib::REGEX} as $regexIndx => $regex)
|
||||
foreach ($decodedUDFValidation->{self::REGEX} as $regexIndx => $regex)
|
||||
{
|
||||
if ($regex->language == UDFLib::BE_REGEX_LANGUAGE)
|
||||
if ($regex->language == self::BE_REGEX_LANGUAGE)
|
||||
{
|
||||
if (preg_match($regex->expression, $udfVal) != 1)
|
||||
{
|
||||
@@ -494,8 +655,8 @@ class UDFLib
|
||||
*/
|
||||
private function _setNameAndId($jsonSchema, &$htmlParameters)
|
||||
{
|
||||
$htmlParameters[HTMLWidget::HTML_ID] = $jsonSchema->{UDFLib::NAME};
|
||||
$htmlParameters[HTMLWidget::HTML_NAME] = $jsonSchema->{UDFLib::NAME};
|
||||
$htmlParameters[HTMLWidget::HTML_ID] = $jsonSchema->{self::NAME};
|
||||
$htmlParameters[HTMLWidget::HTML_NAME] = $jsonSchema->{self::NAME};
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -504,20 +665,20 @@ class UDFLib
|
||||
private function _sortJsonSchemas(&$jsonSchemasArray)
|
||||
{
|
||||
usort($jsonSchemasArray, function ($a, $b) {
|
||||
if (!isset($a->{UDFLib::SORT}))
|
||||
if (!isset($a->{self::SORT}))
|
||||
{
|
||||
$a->{UDFLib::SORT} = 9999;
|
||||
$a->{self::SORT} = 9999;
|
||||
}
|
||||
if (!isset($b->{UDFLib::SORT}))
|
||||
if (!isset($b->{self::SORT}))
|
||||
{
|
||||
$b->{UDFLib::SORT} = 9999;
|
||||
$b->{self::SORT} = 9999;
|
||||
}
|
||||
if ($a->{UDFLib::SORT} == $b->{UDFLib::SORT})
|
||||
if ($a->{self::SORT} == $b->{self::SORT})
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return ($a->{UDFLib::SORT} < $b->{UDFLib::SORT}) ? -1 : 1;
|
||||
return ($a->{self::SORT} < $b->{self::SORT}) ? -1 : 1;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -565,32 +726,32 @@ class UDFLib
|
||||
private function _render($jsonSchema, &$widgetData)
|
||||
{
|
||||
// Checkbox
|
||||
if ($jsonSchema->{UDFLib::TYPE} == 'checkbox')
|
||||
if ($jsonSchema->{self::TYPE} == 'checkbox')
|
||||
{
|
||||
$this->_renderCheckbox($jsonSchema, $widgetData);
|
||||
}
|
||||
// Textfield
|
||||
elseif ($jsonSchema->{UDFLib::TYPE} == 'textfield')
|
||||
elseif ($jsonSchema->{self::TYPE} == 'textfield')
|
||||
{
|
||||
$this->_renderTextfield($jsonSchema, $widgetData);
|
||||
}
|
||||
// Textarea
|
||||
elseif ($jsonSchema->{UDFLib::TYPE} == 'textarea')
|
||||
elseif ($jsonSchema->{self::TYPE} == 'textarea')
|
||||
{
|
||||
$this->_renderTextarea($jsonSchema, $widgetData);
|
||||
}
|
||||
// Date
|
||||
elseif ($jsonSchema->{UDFLib::TYPE} == 'date')
|
||||
elseif ($jsonSchema->{self::TYPE} == 'date')
|
||||
{
|
||||
// To be done
|
||||
}
|
||||
// Dropdown
|
||||
elseif ($jsonSchema->{UDFLib::TYPE} == 'dropdown')
|
||||
elseif ($jsonSchema->{self::TYPE} == 'dropdown')
|
||||
{
|
||||
$this->_renderDropdown($jsonSchema, $widgetData);
|
||||
}
|
||||
// Multiple dropdown
|
||||
elseif ($jsonSchema->{UDFLib::TYPE} == 'multipledropdown')
|
||||
elseif ($jsonSchema->{self::TYPE} == 'multipledropdown')
|
||||
{
|
||||
$this->_renderDropdown($jsonSchema, $widgetData, true);
|
||||
}
|
||||
@@ -602,29 +763,29 @@ class UDFLib
|
||||
private function _renderDropdown($jsonSchema, &$widgetData, $multiple = false)
|
||||
{
|
||||
// Selected element/s
|
||||
if (isset($widgetData[UDFLib::UDFS_ARG_NAME])
|
||||
&& isset($widgetData[UDFLib::UDFS_ARG_NAME][$jsonSchema->{UDFLib::NAME}]))
|
||||
if (isset($widgetData[self::UDFS_ARG_NAME])
|
||||
&& isset($widgetData[self::UDFS_ARG_NAME][$jsonSchema->{self::NAME}]))
|
||||
{
|
||||
$widgetData[DropdownWidget::SELECTED_ELEMENT] = $widgetData[UDFLib::UDFS_ARG_NAME][$jsonSchema->{UDFLib::NAME}];
|
||||
$widgetData[DropdownWidget::SELECTED_ELEMENT] = $widgetData[self::UDFS_ARG_NAME][$jsonSchema->{self::NAME}];
|
||||
}
|
||||
else
|
||||
{
|
||||
$widgetData[DropdownWidget::SELECTED_ELEMENT] = null;
|
||||
}
|
||||
|
||||
$dropdownWidgetUDF = new DropdownWidgetUDF(UDFLib::WIDGET_NAME, $widgetData);
|
||||
$dropdownWidgetUDF = new DropdownWidgetUDF(self::WIDGET_NAME, $widgetData);
|
||||
$parameters = array();
|
||||
|
||||
// If the list of values to show is an array
|
||||
if (isset($jsonSchema->{UDFLib::LIST_VALUES}->enum))
|
||||
if (isset($jsonSchema->{self::LIST_VALUES}->enum))
|
||||
{
|
||||
$parameters = $jsonSchema->{UDFLib::LIST_VALUES}->enum;
|
||||
$parameters = $jsonSchema->{self::LIST_VALUES}->enum;
|
||||
}
|
||||
// If the list of values to show should be retrieved with a SQL statement
|
||||
elseif (isset($jsonSchema->{UDFLib::LIST_VALUES}->sql))
|
||||
elseif (isset($jsonSchema->{self::LIST_VALUES}->sql))
|
||||
{
|
||||
// UDFModel is loaded in method _loadUDF that is called before the current method
|
||||
$queryResult = $this->_ci->UDFModel->execReadOnlyQuery($jsonSchema->{UDFLib::LIST_VALUES}->sql);
|
||||
$queryResult = $this->_ci->UDFModel->execReadOnlyQuery($jsonSchema->{self::LIST_VALUES}->sql);
|
||||
if (hasData($queryResult))
|
||||
{
|
||||
$parameters = $queryResult->retval;
|
||||
@@ -645,13 +806,13 @@ class UDFLib
|
||||
private function _renderTextarea($jsonSchema, &$widgetData)
|
||||
{
|
||||
$text = null; // text value
|
||||
$textareaUDF = new TextareaWidgetUDF(UDFLib::WIDGET_NAME, $widgetData);
|
||||
$textareaUDF = new TextareaWidgetUDF(self::WIDGET_NAME, $widgetData);
|
||||
|
||||
// Set text value if present in the DB
|
||||
if (isset($widgetData[UDFLib::UDFS_ARG_NAME])
|
||||
&& isset($widgetData[UDFLib::UDFS_ARG_NAME][$jsonSchema->{UDFLib::NAME}]))
|
||||
if (isset($widgetData[self::UDFS_ARG_NAME])
|
||||
&& isset($widgetData[self::UDFS_ARG_NAME][$jsonSchema->{self::NAME}]))
|
||||
{
|
||||
$text = $widgetData[UDFLib::UDFS_ARG_NAME][$jsonSchema->{UDFLib::NAME}];
|
||||
$text = $widgetData[self::UDFS_ARG_NAME][$jsonSchema->{self::NAME}];
|
||||
}
|
||||
|
||||
$textareaUDF->render($text);
|
||||
@@ -663,13 +824,13 @@ class UDFLib
|
||||
private function _renderTextfield($jsonSchema, &$widgetData)
|
||||
{
|
||||
$text = null; // text value
|
||||
$textareaUDF = new TextfieldWidgetUDF(UDFLib::WIDGET_NAME, $widgetData);
|
||||
$textareaUDF = new TextfieldWidgetUDF(self::WIDGET_NAME, $widgetData);
|
||||
|
||||
// Set text value if present in the DB
|
||||
if (isset($widgetData[UDFLib::UDFS_ARG_NAME])
|
||||
&& isset($widgetData[UDFLib::UDFS_ARG_NAME][$jsonSchema->{UDFLib::NAME}]))
|
||||
if (isset($widgetData[self::UDFS_ARG_NAME])
|
||||
&& isset($widgetData[self::UDFS_ARG_NAME][$jsonSchema->{self::NAME}]))
|
||||
{
|
||||
$text = $widgetData[UDFLib::UDFS_ARG_NAME][$jsonSchema->{UDFLib::NAME}];
|
||||
$text = $widgetData[self::UDFS_ARG_NAME][$jsonSchema->{self::NAME}];
|
||||
}
|
||||
|
||||
$textareaUDF->render($text);
|
||||
@@ -681,17 +842,17 @@ class UDFLib
|
||||
private function _renderCheckbox($jsonSchema, &$widgetData)
|
||||
{
|
||||
// Set checkbox value if present in the DB
|
||||
if (isset($widgetData[UDFLib::UDFS_ARG_NAME])
|
||||
&& isset($widgetData[UDFLib::UDFS_ARG_NAME][$jsonSchema->{UDFLib::NAME}]))
|
||||
if (isset($widgetData[self::UDFS_ARG_NAME])
|
||||
&& isset($widgetData[self::UDFS_ARG_NAME][$jsonSchema->{self::NAME}]))
|
||||
{
|
||||
$widgetData[CheckboxWidget::VALUE_FIELD] = $widgetData[UDFLib::UDFS_ARG_NAME][$jsonSchema->{UDFLib::NAME}];
|
||||
$widgetData[CheckboxWidget::VALUE_FIELD] = $widgetData[self::UDFS_ARG_NAME][$jsonSchema->{self::NAME}];
|
||||
}
|
||||
else
|
||||
{
|
||||
$widgetData[CheckboxWidget::VALUE_FIELD] = CheckboxWidget::HTML_DEFAULT_VALUE;
|
||||
}
|
||||
|
||||
$checkboxWidgetUDF = new CheckboxWidgetUDF(UDFLib::WIDGET_NAME, $widgetData);
|
||||
$checkboxWidgetUDF = new CheckboxWidgetUDF(self::WIDGET_NAME, $widgetData);
|
||||
|
||||
$checkboxWidgetUDF->render();
|
||||
}
|
||||
@@ -707,21 +868,21 @@ class UDFLib
|
||||
$htmlParameters[HTMLWidget::PLACEHOLDER] = null;
|
||||
|
||||
// Description, title and placeholder
|
||||
if (isset($jsonSchema->{UDFLib::LABEL})
|
||||
|| isset($jsonSchema->{UDFLib::TITLE})
|
||||
|| isset($jsonSchema->{UDFLib::PLACEHOLDER}))
|
||||
if (isset($jsonSchema->{self::LABEL})
|
||||
|| isset($jsonSchema->{self::TITLE})
|
||||
|| isset($jsonSchema->{self::PLACEHOLDER}))
|
||||
{
|
||||
// Loads phrases library
|
||||
$this->_ci->load->library('PhrasesLib');
|
||||
|
||||
// If is set the label property in the json schema
|
||||
if (isset($jsonSchema->{UDFLib::LABEL}))
|
||||
if (isset($jsonSchema->{self::LABEL}))
|
||||
{
|
||||
// Load the related phrase
|
||||
$tmpResult = $this->_ci->phraseslib->getPhrases(
|
||||
UDFLib::PHRASES_APP_NAME,
|
||||
self::PHRASES_APP_NAME,
|
||||
getUserLanguage(),
|
||||
$jsonSchema->{UDFLib::LABEL},
|
||||
$jsonSchema->{self::LABEL},
|
||||
null,
|
||||
null,
|
||||
'no'
|
||||
@@ -733,13 +894,13 @@ class UDFLib
|
||||
}
|
||||
|
||||
// If is set the title property in the json schema
|
||||
if (isset($jsonSchema->{UDFLib::TITLE}))
|
||||
if (isset($jsonSchema->{self::TITLE}))
|
||||
{
|
||||
// Load the related phrase
|
||||
$tmpResult = $this->_ci->phraseslib->getPhrases(
|
||||
UDFLib::PHRASES_APP_NAME,
|
||||
self::PHRASES_APP_NAME,
|
||||
getUserLanguage(),
|
||||
$jsonSchema->{UDFLib::TITLE},
|
||||
$jsonSchema->{self::TITLE},
|
||||
null,
|
||||
null,
|
||||
'no'
|
||||
@@ -751,13 +912,13 @@ class UDFLib
|
||||
}
|
||||
|
||||
// If is set the placeholder property in the json schema
|
||||
if (isset($jsonSchema->{UDFLib::PLACEHOLDER}))
|
||||
if (isset($jsonSchema->{self::PLACEHOLDER}))
|
||||
{
|
||||
// Load the related phrase
|
||||
$tmpResult = $this->_ci->phraseslib->getPhrases(
|
||||
UDFLib::PHRASES_APP_NAME,
|
||||
self::PHRASES_APP_NAME,
|
||||
getUserLanguage(),
|
||||
$jsonSchema->{UDFLib::PLACEHOLDER},
|
||||
$jsonSchema->{self::PLACEHOLDER},
|
||||
null,
|
||||
null,
|
||||
'no'
|
||||
@@ -784,17 +945,17 @@ class UDFLib
|
||||
$htmlParameters[HTMLWidget::MAX_LENGTH] = null;
|
||||
|
||||
// If validation property is present in the json schema
|
||||
if (isset($jsonSchema->{UDFLib::VALIDATION}))
|
||||
if (isset($jsonSchema->{self::VALIDATION}))
|
||||
{
|
||||
$jsonSchemaValidation =& $jsonSchema->{UDFLib::VALIDATION}; // Reference for a better code readability
|
||||
$jsonSchemaValidation =& $jsonSchema->{self::VALIDATION}; // Reference for a better code readability
|
||||
|
||||
// Front-end regex
|
||||
if (isset($jsonSchemaValidation->{UDFLib::REGEX})
|
||||
&& is_array($jsonSchemaValidation->{UDFLib::REGEX}))
|
||||
if (isset($jsonSchemaValidation->{self::REGEX})
|
||||
&& is_array($jsonSchemaValidation->{self::REGEX}))
|
||||
{
|
||||
foreach ($jsonSchemaValidation->{UDFLib::REGEX} as $regex)
|
||||
foreach ($jsonSchemaValidation->{self::REGEX} as $regex)
|
||||
{
|
||||
if ($regex->language === UDFLib::FE_REGEX_LANGUAGE)
|
||||
if ($regex->language === self::FE_REGEX_LANGUAGE)
|
||||
{
|
||||
$htmlParameters[HTMLWidget::REGEX] = $regex->expression;
|
||||
}
|
||||
@@ -802,33 +963,33 @@ class UDFLib
|
||||
}
|
||||
|
||||
// Required
|
||||
if (isset($jsonSchemaValidation->{UDFLib::REQUIRED}))
|
||||
if (isset($jsonSchemaValidation->{self::REQUIRED}))
|
||||
{
|
||||
$htmlParameters[HTMLWidget::REQUIRED] = $jsonSchemaValidation->{UDFLib::REQUIRED};
|
||||
$htmlParameters[HTMLWidget::REQUIRED] = $jsonSchemaValidation->{self::REQUIRED};
|
||||
}
|
||||
|
||||
// Min value
|
||||
if (isset($jsonSchemaValidation->{UDFLib::MIN_VALUE}))
|
||||
if (isset($jsonSchemaValidation->{self::MIN_VALUE}))
|
||||
{
|
||||
$htmlParameters[HTMLWidget::MIN_VALUE] = $jsonSchemaValidation->{UDFLib::MIN_VALUE};
|
||||
$htmlParameters[HTMLWidget::MIN_VALUE] = $jsonSchemaValidation->{self::MIN_VALUE};
|
||||
}
|
||||
|
||||
// Max value
|
||||
if (isset($jsonSchemaValidation->{UDFLib::MAX_VALUE}))
|
||||
if (isset($jsonSchemaValidation->{self::MAX_VALUE}))
|
||||
{
|
||||
$htmlParameters[HTMLWidget::MAX_VALUE] = $jsonSchemaValidation->{UDFLib::MAX_VALUE};
|
||||
$htmlParameters[HTMLWidget::MAX_VALUE] = $jsonSchemaValidation->{self::MAX_VALUE};
|
||||
}
|
||||
|
||||
// Min length
|
||||
if (isset($jsonSchemaValidation->{UDFLib::MIN_LENGTH}))
|
||||
if (isset($jsonSchemaValidation->{self::MIN_LENGTH}))
|
||||
{
|
||||
$htmlParameters[HTMLWidget::MIN_LENGTH] = $jsonSchemaValidation->{UDFLib::MIN_LENGTH};
|
||||
$htmlParameters[HTMLWidget::MIN_LENGTH] = $jsonSchemaValidation->{self::MIN_LENGTH};
|
||||
}
|
||||
|
||||
// Max length
|
||||
if (isset($jsonSchemaValidation->{UDFLib::MAX_LENGTH}))
|
||||
if (isset($jsonSchemaValidation->{self::MAX_LENGTH}))
|
||||
{
|
||||
$htmlParameters[HTMLWidget::MAX_LENGTH] = $jsonSchemaValidation->{UDFLib::MAX_LENGTH};
|
||||
$htmlParameters[HTMLWidget::MAX_LENGTH] = $jsonSchemaValidation->{self::MAX_LENGTH};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,169 +0,0 @@
|
||||
<?php
|
||||
|
||||
class FAS_UDF_model extends DB_Model
|
||||
{
|
||||
// String values of booleans
|
||||
const STRING_NULL = 'null';
|
||||
const STRING_TRUE = 'true';
|
||||
const STRING_FALSE = 'false';
|
||||
|
||||
const UDF_DROPDOWN_TYPE = 'dropdown';
|
||||
const UDF_MULTIPLEDROPDOWN_TYPE = 'multipledropdown';
|
||||
|
||||
/**
|
||||
* Methods to save data from FAS
|
||||
*/
|
||||
public function saveUDFs($udfs)
|
||||
{
|
||||
$result = error('No way man!');
|
||||
$resultPerson = success('person');
|
||||
$resultPrestudent = success('prestudent');
|
||||
|
||||
$person_id = null;
|
||||
if (isset($udfs['person_id'])) $person_id = $udfs['person_id'];
|
||||
unset($udfs['person_id']);
|
||||
|
||||
$prestudent_id = null;
|
||||
if (isset($udfs['prestudent_id'])) $prestudent_id = $udfs['prestudent_id'];
|
||||
unset($udfs['prestudent_id']);
|
||||
|
||||
$jsons = array();
|
||||
|
||||
//
|
||||
if (isset($person_id))
|
||||
{
|
||||
// Load model Person_model
|
||||
$this->load->model('person/Person_model', 'PersonModel');
|
||||
|
||||
$result = $this->load(array('public', 'tbl_person'));
|
||||
if (isSuccess($result) && count($result->retval) == 1)
|
||||
{
|
||||
$jsons = json_decode($result->retval[0]->jsons);
|
||||
}
|
||||
|
||||
$udfs = $this->_fillMissingTextUDF($udfs, $jsons);
|
||||
$udfs = $this->_fillMissingChkboxUDF($udfs, $jsons);
|
||||
$udfs = $this->_fillMissingDropdownUDF($udfs, $jsons);
|
||||
|
||||
$resultPerson = $this->PersonModel->update($person_id, $udfs);
|
||||
}
|
||||
|
||||
//
|
||||
if (isset($prestudent_id))
|
||||
{
|
||||
// Load model Prestudent_model
|
||||
$this->load->model('crm/Prestudent_model', 'PrestudentModel');
|
||||
|
||||
$result = $this->load(array('public', 'tbl_prestudent'));
|
||||
if (isSuccess($result) && count($result->retval) == 1)
|
||||
{
|
||||
$jsons = json_decode($result->retval[0]->jsons);
|
||||
}
|
||||
|
||||
$udfs = $this->_fillMissingTextUDF($udfs, $jsons);
|
||||
$udfs = $this->_fillMissingChkboxUDF($udfs, $jsons);
|
||||
$udfs = $this->_fillMissingDropdownUDF($udfs, $jsons);
|
||||
|
||||
$resultPrestudent = $this->PrestudentModel->update($prestudent_id, $udfs);
|
||||
}
|
||||
|
||||
if (isSuccess($resultPerson) && isSuccess($resultPrestudent))
|
||||
{
|
||||
$result = success(array($resultPerson->retval, $resultPrestudent->retval));
|
||||
}
|
||||
else if(isError($resultPerson))
|
||||
{
|
||||
$result = $resultPerson;
|
||||
}
|
||||
else if(isError($resultPrestudent))
|
||||
{
|
||||
$result = $resultPrestudent;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function _fillMissingChkboxUDF($udfs, $jsons)
|
||||
{
|
||||
$_fillMissingChkboxUDF = $udfs;
|
||||
|
||||
foreach($jsons as $udfDescription)
|
||||
{
|
||||
if ($udfDescription->{UDFLib::TYPE} == UDFLib::CHKBOX_TYPE)
|
||||
{
|
||||
if (!isset($_fillMissingChkboxUDF[$udfDescription->{UDFLib::NAME}]))
|
||||
{
|
||||
$_fillMissingChkboxUDF[$udfDescription->{UDFLib::NAME}] = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($_fillMissingChkboxUDF[$udfDescription->{UDFLib::NAME}] == UDF_model::STRING_FALSE)
|
||||
{
|
||||
$_fillMissingChkboxUDF[$udfDescription->{UDFLib::NAME}] = false;
|
||||
}
|
||||
else if ($_fillMissingChkboxUDF[$udfDescription->{UDFLib::NAME}] == UDF_model::STRING_TRUE)
|
||||
{
|
||||
$_fillMissingChkboxUDF[$udfDescription->{UDFLib::NAME}] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $_fillMissingChkboxUDF;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function _fillMissingDropdownUDF($udfs, $jsons)
|
||||
{
|
||||
$_fillMissingDropdownUDF = $udfs;
|
||||
|
||||
foreach($jsons as $udfDescription)
|
||||
{
|
||||
if ($udfDescription->{UDFLib::TYPE} == UDF_model::UDF_DROPDOWN_TYPE
|
||||
|| $udfDescription->{UDFLib::TYPE} == UDF_model::UDF_MULTIPLEDROPDOWN_TYPE)
|
||||
{
|
||||
if (!isset($_fillMissingDropdownUDF[$udfDescription->{UDFLib::NAME}]))
|
||||
{
|
||||
$_fillMissingDropdownUDF[$udfDescription->{UDFLib::NAME}] = null;
|
||||
}
|
||||
else if($_fillMissingDropdownUDF[$udfDescription->{UDFLib::NAME}] == UDF_model::STRING_NULL)
|
||||
{
|
||||
$_fillMissingDropdownUDF[$udfDescription->{UDFLib::NAME}] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $_fillMissingDropdownUDF;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function _fillMissingTextUDF($udfs, $jsons)
|
||||
{
|
||||
$_fillMissingTextUDF = $udfs;
|
||||
|
||||
foreach($jsons as $udfDescription)
|
||||
{
|
||||
if ($udfDescription->{UDFLib::TYPE} == 'textarea'
|
||||
|| $udfDescription->{UDFLib::TYPE} == 'textfield')
|
||||
{
|
||||
if (!isset($_fillMissingTextUDF[$udfDescription->{UDFLib::NAME}]))
|
||||
{
|
||||
$_fillMissingTextUDF[$udfDescription->{UDFLib::NAME}] = null;
|
||||
}
|
||||
else if(trim($_fillMissingTextUDF[$udfDescription->{UDFLib::NAME}]) == '')
|
||||
{
|
||||
$_fillMissingTextUDF[$udfDescription->{UDFLib::NAME}] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $_fillMissingTextUDF;
|
||||
}
|
||||
}
|
||||
@@ -1,54 +1,28 @@
|
||||
<?php $this->load->view("templates/header", array("title" => "UDF", "widgetsCSS" => true)); ?>
|
||||
<?php
|
||||
$this->load->view(
|
||||
'templates/FHC-Header',
|
||||
array(
|
||||
'title' => 'InfocenterDetails',
|
||||
'jquery' => true,
|
||||
'bootstrap' => true,
|
||||
'fontawesome' => true,
|
||||
'jqueryui' => true,
|
||||
'dialoglib' => true,
|
||||
'ajaxlib' => true,
|
||||
'udfs' => true,
|
||||
'sbadmintemplate' => true,
|
||||
'customCSSs' => array(
|
||||
'public/css/sbadmin2/admintemplate.css'
|
||||
),
|
||||
'customJSs' => array(
|
||||
'public/js/bootstrapper.js'
|
||||
)
|
||||
)
|
||||
);
|
||||
?>
|
||||
|
||||
<body style="background-color: #eff0f1;">
|
||||
|
||||
<?php
|
||||
if ($result != null)
|
||||
{
|
||||
if (isSuccess($result))
|
||||
{
|
||||
?>
|
||||
<div style="color: black;">
|
||||
Saved!
|
||||
</div>
|
||||
|
||||
<br>
|
||||
<?php
|
||||
}
|
||||
else
|
||||
{
|
||||
?>
|
||||
<div style="color: red;">
|
||||
Error while saving!
|
||||
</div>
|
||||
<br>
|
||||
<div style="color: red;">
|
||||
<?php
|
||||
$errors = $result->retval;
|
||||
if(is_array($errors))
|
||||
{
|
||||
foreach ($errors as $error)
|
||||
{
|
||||
foreach ($error as $fieldError)
|
||||
{
|
||||
echo $fieldError->code . ': ' . $fieldError->retval . '<br>';
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
echo $result->retval;
|
||||
?>
|
||||
</div>
|
||||
|
||||
<br>
|
||||
<br>
|
||||
<br>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
?>
|
||||
<form action="<?php echo site_url('system/FAS_UDF/saveUDF'); ?>" method="POST">
|
||||
|
||||
<div class="div-table">
|
||||
<div class="div-row">
|
||||
<div class="div-cell" style="font-size: 20px; font-weight: bold;">
|
||||
@@ -69,8 +43,12 @@
|
||||
<?php
|
||||
echo $this->udflib->UDFWidget(
|
||||
array(
|
||||
UDFLib::UDF_UNIQUE_ID => 'fasPersonUDFs',
|
||||
UDFLib::REQUIRED_PERMISSIONS_PARAMETER => 'basis/person',
|
||||
UDFLib::SCHEMA_ARG_NAME => 'public',
|
||||
UDFLib::TABLE_ARG_NAME => 'tbl_person',
|
||||
UDFLib::PRIMARY_KEY_NAME => 'person_id',
|
||||
UDFLib::PRIMARY_KEY_VALUE => $person_id,
|
||||
UDFLib::UDFS_ARG_NAME => $personUdfs
|
||||
)
|
||||
);
|
||||
@@ -90,8 +68,12 @@
|
||||
<?php
|
||||
echo $this->udflib->UDFWidget(
|
||||
array(
|
||||
UDFLib::UDF_UNIQUE_ID => 'fasPrestudentUDFs',
|
||||
UDFLib::REQUIRED_PERMISSIONS_PARAMETER => 'basis/person',
|
||||
UDFLib::SCHEMA_ARG_NAME => 'public',
|
||||
UDFLib::TABLE_ARG_NAME => 'tbl_prestudent',
|
||||
UDFLib::PRIMARY_KEY_NAME => 'prestudent_id',
|
||||
UDFLib::PRIMARY_KEY_VALUE => $prestudent_id,
|
||||
UDFLib::UDFS_ARG_NAME => $prestudentUdfs
|
||||
)
|
||||
);
|
||||
@@ -120,31 +102,9 @@
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<div class="div-cell halign-right">
|
||||
<input type="submit" value=" Speichern ">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
if (isset($personUdfs))
|
||||
{
|
||||
?>
|
||||
<input type="hidden" name="person_id" value="<?php echo $personUdfs['person_id']; ?>">
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<?php
|
||||
if (isset($prestudentUdfs))
|
||||
{
|
||||
?>
|
||||
<input type="hidden" name="prestudent_id" value="<?php echo $prestudentUdfs['prestudent_id']; ?>">
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
|
||||
</form>
|
||||
|
||||
</body>
|
||||
|
||||
<?php $this->load->view("templates/footer"); ?>
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
$tablewidget = isset($tablewidget) ? $tablewidget : false;
|
||||
$tabulator = isset($tabulator) ? $tabulator : false;
|
||||
$tinymce = isset($tinymce) ? $tinymce : false;
|
||||
$udfs = isset($udfs) ? $udfs : false;
|
||||
?>
|
||||
|
||||
<!-- Header start -->
|
||||
@@ -176,6 +177,9 @@
|
||||
// Tinymce JS
|
||||
if ($tinymce === true) generateJSsInclude('vendor/tinymce/tinymce/tinymce.min.js');
|
||||
|
||||
// Tinymce JS
|
||||
if ($udfs === true) generateJSsInclude('public/js/UDFWidget.js');
|
||||
|
||||
// SB Admin 2 template JS
|
||||
if ($sbadmintemplate === true)
|
||||
{
|
||||
|
||||
@@ -12,7 +12,7 @@ class DropdownWidgetUDF extends DropdownWidget
|
||||
{
|
||||
// Array that will contains the elements to be displayed in the dropdown
|
||||
$tmpNewElements = array();
|
||||
|
||||
|
||||
// Loops through the given parameters
|
||||
foreach($parameters as $parameter)
|
||||
{
|
||||
@@ -29,27 +29,27 @@ class DropdownWidgetUDF extends DropdownWidget
|
||||
// If the single element is an array of two element
|
||||
if (is_array($parameter) && count($parameter) == 2)
|
||||
{
|
||||
$newElement->{DropdownWidget::ID_FIELD} = $parameter[0]; //
|
||||
$newElement->{DropdownWidget::DESCRIPTION_FIELD} = $parameter[1]; //
|
||||
$newElement->{DropdownWidget::ID_FIELD} = $parameter[0]; //
|
||||
$newElement->{DropdownWidget::DESCRIPTION_FIELD} = $parameter[1]; //
|
||||
}
|
||||
// If the single element is a string or a number
|
||||
else if (is_string($parameter) || is_numeric($parameter))
|
||||
{
|
||||
$newElement->{DropdownWidget::ID_FIELD} = $parameter; //
|
||||
$newElement->{DropdownWidget::DESCRIPTION_FIELD} = $parameter; //
|
||||
$newElement->{DropdownWidget::ID_FIELD} = $parameter; //
|
||||
$newElement->{DropdownWidget::DESCRIPTION_FIELD} = $parameter; //
|
||||
}
|
||||
// If the single element is an object with two properties: id and description
|
||||
else if (is_object($parameter) && isset($parameter->{DropdownWidget::ID_FIELD})
|
||||
&& isset($parameter->{DropdownWidget::DESCRIPTION_FIELD}))
|
||||
{
|
||||
$newElement->{DropdownWidget::ID_FIELD} = $parameter->{DropdownWidget::ID_FIELD}; //
|
||||
$newElement->{DropdownWidget::DESCRIPTION_FIELD} = $parameter->{DropdownWidget::DESCRIPTION_FIELD}; //
|
||||
$newElement->{DropdownWidget::ID_FIELD} = $parameter->{DropdownWidget::ID_FIELD}; //
|
||||
$newElement->{DropdownWidget::DESCRIPTION_FIELD} = $parameter->{DropdownWidget::DESCRIPTION_FIELD}; //
|
||||
}
|
||||
|
||||
|
||||
array_push($tmpNewElements, $newElement); // Add $newElement into $tmpNewElements
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Set the list of elements
|
||||
$this->setElementsArray(
|
||||
success($tmpNewElements),
|
||||
@@ -57,9 +57,9 @@ class DropdownWidgetUDF extends DropdownWidget
|
||||
$this->htmlParameters[HTMLWidget::PLACEHOLDER],
|
||||
'No data found for this UDF'
|
||||
);
|
||||
|
||||
|
||||
$this->loadDropDownView();
|
||||
|
||||
|
||||
echo $this->content();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,14 +6,155 @@
|
||||
*/
|
||||
class UDFWidget extends HTMLWidget
|
||||
{
|
||||
private $_requiredPermissions; //
|
||||
|
||||
private $_schema;
|
||||
private $_table;
|
||||
private $_primaryKeyName;
|
||||
private $_primaryKeyValue;
|
||||
|
||||
/**
|
||||
* Initialize the UDFWidget and starts the execution of the logic
|
||||
*/
|
||||
public function __construct($name, $args = array())
|
||||
{
|
||||
parent::__construct($name, $args); // calls the parent's constructor
|
||||
|
||||
$this->load->library('UDFLib'); // Loads the UDFLib that contains all the used logic
|
||||
|
||||
$this->udflib->setUDFUniqueIdByParams($args);
|
||||
|
||||
$this->_initUDFWidget($args); // checks parameters and initialize properties
|
||||
|
||||
// Let's start if it's allowed
|
||||
// NOTE: If it is NOT allowed then no data are loaded
|
||||
if ($this->udflib->isAllowed($this->_requiredPermissions))
|
||||
{
|
||||
$this->_startUDFWidget($args[UDFLib::UDF_UNIQUE_ID]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the WidgetLib, it renders the HTML of the UDF
|
||||
*/
|
||||
public function display($widgetData)
|
||||
{
|
||||
// _ci is the instance of Code Igniter and the library UDFLib was previously loaded,
|
||||
// so now is it possibile to call the method displayUDFWidget of UDFLib
|
||||
// to render the HTML of this UDF
|
||||
$this->_ci->udflib->displayUDFWidget($widgetData);
|
||||
// Let's start if it's allowed
|
||||
// NOTE: If it is NOT allowed then no data are loaded
|
||||
if ($this->_ci->udflib->isAllowed($this->_requiredPermissions))
|
||||
{
|
||||
$this->_ci->udflib->displayUDFWidget($widgetData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
// Private methods
|
||||
|
||||
/**
|
||||
* Checks parameters and initialize all the properties of this UDFWidget
|
||||
*/
|
||||
private function _initUDFWidget($args)
|
||||
{
|
||||
$this->_checkParameters($args);
|
||||
|
||||
// If here then everything is ok
|
||||
|
||||
// Initialize class properties
|
||||
$this->_requiredPermissions = null;
|
||||
$this->_schema = null;
|
||||
$this->_table = null;
|
||||
$this->_primaryKeyName = null;
|
||||
$this->_primaryKeyValue = null;
|
||||
|
||||
// Retrieved the required permissions parameter if present
|
||||
if (isset($args[UDFLib::REQUIRED_PERMISSIONS_PARAMETER]))
|
||||
{
|
||||
$this->_requiredPermissions = $args[UDFLib::REQUIRED_PERMISSIONS_PARAMETER];
|
||||
}
|
||||
|
||||
// Retrieved the
|
||||
if (isset($args[UDFLib::SCHEMA_ARG_NAME]))
|
||||
{
|
||||
$this->_schema = $args[UDFLib::SCHEMA_ARG_NAME];
|
||||
}
|
||||
|
||||
// Retrieved the
|
||||
if (isset($args[UDFLib::TABLE_ARG_NAME]))
|
||||
{
|
||||
$this->_table = $args[UDFLib::TABLE_ARG_NAME];
|
||||
}
|
||||
|
||||
// Retrieved the
|
||||
if (isset($args[UDFLib::PRIMARY_KEY_NAME]))
|
||||
{
|
||||
$this->_primaryKeyName = $args[UDFLib::PRIMARY_KEY_NAME];
|
||||
}
|
||||
|
||||
// Retrieved the
|
||||
if (isset($args[UDFLib::PRIMARY_KEY_VALUE]))
|
||||
{
|
||||
$this->_primaryKeyValue = $args[UDFLib::PRIMARY_KEY_VALUE];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the required parameters used to call this UDFWidget
|
||||
*/
|
||||
private function _checkParameters($args)
|
||||
{
|
||||
if (!is_array($args) || (is_array($args) && count($args) == 0))
|
||||
{
|
||||
show_error('Second parameter of the widget call must be a NOT empty associative array');
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!isset($args[UDFLib::UDF_UNIQUE_ID]))
|
||||
{
|
||||
show_error('The parameter "'.UDFLib::UDF_UNIQUE_ID.'" must be specified');
|
||||
}
|
||||
|
||||
if (!isset($args[UDFLib::REQUIRED_PERMISSIONS_PARAMETER]))
|
||||
{
|
||||
show_error('The parameter "'.UDFLib::REQUIRED_PERMISSIONS_PARAMETER.'" must be specified');
|
||||
}
|
||||
|
||||
if (!isset($args[UDFLib::SCHEMA_ARG_NAME]))
|
||||
{
|
||||
show_error('The parameter "'.UDFLib::SCHEMA_ARG_NAME.'" must be specified');
|
||||
}
|
||||
|
||||
if (!isset($args[UDFLib::TABLE_ARG_NAME]))
|
||||
{
|
||||
show_error('The parameter "'.UDFLib::TABLE_ARG_NAME.'" must be specified');
|
||||
}
|
||||
|
||||
if (!isset($args[UDFLib::PRIMARY_KEY_NAME]))
|
||||
{
|
||||
show_error('The parameter "'.UDFLib::PRIMARY_KEY_NAME.'" must be specified');
|
||||
}
|
||||
|
||||
if (!isset($args[UDFLib::PRIMARY_KEY_VALUE]))
|
||||
{
|
||||
show_error('The parameter "'.UDFLib::PRIMARY_KEY_VALUE.'" must be specified');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Contains all the logic used to load all the data needed to the UDFWidget
|
||||
*/
|
||||
private function _startUDFWidget($udfUniqueId)
|
||||
{
|
||||
// Stores an array that contains all the data useful for
|
||||
$this->udflib->setSession(
|
||||
array(
|
||||
UDFLib::UDF_UNIQUE_ID => $udfUniqueId, // table unique id
|
||||
UDFLib::REQUIRED_PERMISSIONS_PARAMETER => $this->_requiredPermissions, //
|
||||
UDFLib::SCHEMA_ARG_NAME => $this->_schema, //
|
||||
UDFLib::TABLE_ARG_NAME => $this->_table, //
|
||||
UDFLib::PRIMARY_KEY_NAME => $this->_primaryKeyName, //
|
||||
UDFLib::PRIMARY_KEY_VALUE => $this->_primaryKeyValue //
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
/**
|
||||
* UDFWidget JS magic
|
||||
*/
|
||||
|
||||
/**
|
||||
* FHC_UDFWidget this object is used to render the GUI of a table widget and to operate with it
|
||||
*/
|
||||
var FHC_UDFWidget = {
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
// Public methods
|
||||
|
||||
/**
|
||||
* To display the TableWidget using the loaded data prenset in the session
|
||||
*/
|
||||
display: function() {
|
||||
|
||||
$("div[type*='UDFWidget']").each(function(i, udfWidgetDiv) {
|
||||
|
||||
var saveButton = $('<input type="button" value="Save UDFs">');
|
||||
|
||||
saveButton.on('click', function() {
|
||||
|
||||
var udfs = {};
|
||||
|
||||
$("div[udfUniqueId*='" + udfWidgetDiv.attributes["udfUniqueId"].nodeValue + "']").find("[name^='udf_']").each(function(i, udf) {
|
||||
|
||||
if (udf.type == 'checkbox')
|
||||
{
|
||||
udfs[udf.id] = udf.checked == true;
|
||||
}
|
||||
else if (udf.type == 'select-one' || udf.type == 'select-multiple')
|
||||
{
|
||||
udfs[udf.id] = null;
|
||||
|
||||
if (!isNaN(udf.value) && udf.value.trim() != '')
|
||||
{
|
||||
udfs[udf.id] = Number(udf.value);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
udfs[udf.id] = udf.value;
|
||||
}
|
||||
});
|
||||
|
||||
FHC_AjaxClient.ajaxCallPost(
|
||||
"widgets/UDF/saveUDFs",
|
||||
{
|
||||
udfUniqueId: FHC_UDFWidget._getUDFUniqueIdPrefix() + "/" + udfWidgetDiv.attributes["udfUniqueId"].nodeValue,
|
||||
udfs: JSON.stringify(udfs)
|
||||
},
|
||||
{
|
||||
successCallback: function(data, textStatus, jqXHR) {
|
||||
|
||||
if (FHC_AjaxClient.hasData(data))
|
||||
{
|
||||
FHC_DialogLib.alertSuccess('Done!');
|
||||
}
|
||||
else
|
||||
{
|
||||
console.log(FHC_AjaxClient.getError(data));
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
errorCallback: function(data, textStatus, jqXHR) {
|
||||
console.log('Contact the administrator');
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
});
|
||||
|
||||
saveButton.appendTo(udfWidgetDiv);
|
||||
|
||||
});
|
||||
|
||||
},
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
// Private methods
|
||||
|
||||
/**
|
||||
* To retrive the page where the TableWidget is used, using the FHC_JS_DATA_STORAGE_OBJECT
|
||||
*/
|
||||
_getUDFUniqueIdPrefix: function() {
|
||||
|
||||
return FHC_JS_DATA_STORAGE_OBJECT.called_path + "/" + FHC_JS_DATA_STORAGE_OBJECT.called_method;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* When JQuery is up
|
||||
*/
|
||||
$(document).ready(function() {
|
||||
|
||||
FHC_UDFWidget.display();
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user