diff --git a/application/config/constants.php b/application/config/constants.php
index 1746157a9..68a5261e7 100755
--- a/application/config/constants.php
+++ b/application/config/constants.php
@@ -101,5 +101,14 @@ define('EXIT_UNKNOWN_CLASS', 5); // unknown class
define('EXIT_UNKNOWN_METHOD', 6); // unknown class member
define('EXIT_USER_INPUT', 7); // invalid user input
define('EXIT_DATABASE', 8); // database error
-define('EXIT__AUTO_MIN', 9); // lowest automatically-assigned error code
-define('EXIT__AUTO_MAX', 125); // highest automatically-assigned error code
+define('EXIT_VALIDATION_UDF', 10); // UDF validation has been failed
+define('EXIT_VALIDATION_UDF_MIN_VALUE', 11); // UDF validation has been failed -> MIN VALUE
+define('EXIT_VALIDATION_UDF_MAX_VALUE', 12); // UDF validation has been failed -> MAX VALUE
+define('EXIT_VALIDATION_UDF_MIN_LENGTH', 13); // UDF validation has been failed -> MIN LENGTH
+define('EXIT_VALIDATION_UDF_MAX_LENGTH', 14); // UDF validation has been failed -> MAX LENGTH
+define('EXIT_VALIDATION_UDF_REGEX', 15); // UDF validation has been failed -> REGEX
+define('EXIT_VALIDATION_UDF_REQUIRED', 16); // UDF validation has been failed -> REQUIRED
+define('EXIT_VALIDATION_UDF_NOT_VALID_VAL', 17); // UDF validation has been failed -> Not valid value, object or array
+
+define('EXIT_AUTO_MIN', 1000); // lowest automatically-assigned error code
+define('EXIT_AUTO_MAX', 2000); // highest automatically-assigned error code
\ No newline at end of file
diff --git a/application/config/fhcomplete.php b/application/config/fhcomplete.php
index 251887d5c..6ed5e93bd 100755
--- a/application/config/fhcomplete.php
+++ b/application/config/fhcomplete.php
@@ -207,6 +207,7 @@ $config['fhc_acl'] = array
'system.tbl_webservicelog' => 'basis/webservicelog',
'system.tbl_webservicerecht' => 'basis/webservicerecht',
'system.tbl_webservicetyp' => 'basis/webservicetyp',
+ 'system.tbl_udf' => 'system/udf',
'testtool.tbl_ablauf' => 'basis/ablauf',
'testtool.tbl_antwort' => 'basis/antwort',
'testtool.tbl_frage' => 'basis/frage',
diff --git a/application/config/udfmasterschema.json b/application/config/udfmasterschema.json
new file mode 100644
index 000000000..fa06dc80d
--- /dev/null
+++ b/application/config/udfmasterschema.json
@@ -0,0 +1,71 @@
+{
+ "title": "UDF",
+ "type": "object",
+ "tableswhitelist": {
+ "type": "string",
+ "enum": ["tbl_person", "tbl_prestudent", "tbl_mitarbeiter", "tbl_lehrveranstaltung", "tbl_lehreinheit"]
+ },
+ "properties": {
+ "name": {
+ "type": "string"
+ },
+ "description": {
+ "type": "array",
+ },
+ "placeholder": {
+ "type": "array",
+ },
+ "title": {
+ "type": "array",
+ },
+ "type": {
+ "type": "string",
+ "enum": ["checkbox", "textfield", "textarea", "date", "dropdown", "multipledropdown"]
+ },
+ "sort": {
+ "type": "integer"
+ },
+ "defaultValue": {
+ "type": "string"
+ },
+ "validation": {
+ "type": "object",
+ "properties": {
+ "required": {
+ "type": "boolean"
+ },
+ "min-length": {
+ "type": "integer"
+ },
+ "max-length": {
+ "type": "integer"
+ },
+ "min-value": {
+ "type": "integer"
+ },
+ "min-value": {
+ "type": "integer"
+ },
+ "regex": {
+ "type": "object",
+ "properties": {
+ "language": "string",
+ "expression": "string"
+ }
+ }
+ }
+ },
+ "listValues": {
+ "type": "object",
+ "properties": {
+ "sql": {
+ "type": "string"
+ },
+ "enum": {
+ "type": "array"
+ }
+ }
+ }
+ },
+ "required": ["type", "name"]
+}
\ No newline at end of file
diff --git a/application/controllers/api/v1/system/UDF.php b/application/controllers/api/v1/system/UDF.php
new file mode 100644
index 000000000..252332cce
--- /dev/null
+++ b/application/controllers/api/v1/system/UDF.php
@@ -0,0 +1,133 @@
+load->model('system/UDF_model', 'UDFModel');
+ }
+
+ /**
+ * @return void
+ */
+ public function getUDF()
+ {
+ $decode = $this->get('decode');
+ $schema = $this->get('schema');
+ $table = $this->get('table');
+
+ $result = error();
+
+ if (isset($schema) || isset($table))
+ {
+ $result = $this->UDFModel->loadWhere(
+ array(
+ 'schema' => $schema,
+ 'table' => $table
+ )
+ );
+ }
+ else
+ {
+ $result = $this->UDFModel->load();
+ }
+
+ if ($decode)
+ {
+ $this->_jsonDecodeResult($result);
+ }
+
+ $this->response($result, REST_Controller::HTTP_OK);
+ }
+
+ /**
+ *
+ */
+ public function postUDF()
+ {
+ $udfs = $this->post();
+ $validation = $this->_validate($udfs);
+
+ if (isSuccess($validation))
+ {
+ $caller = null;
+ if (isset($udfs['caller']))
+ {
+ $caller = $udfs['caller'];
+ unset($udfs['caller']);
+ }
+
+ $result = $this->UDFModel->saveUDFs($udfs);
+
+ if ($caller != null)
+ {
+ $res = 'ERR';
+ if (isSuccess($result))
+ {
+ $res = 'OK';
+ }
+
+ redirect($caller.'&res='.$res);
+ }
+ else
+ {
+ $this->response($result, REST_Controller::HTTP_OK);
+ }
+ }
+ else
+ {
+ $this->response($validation, REST_Controller::HTTP_OK);
+ }
+ }
+
+ /**
+ *
+ */
+ 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;
+ }
+
+ /**
+ * Decode to json the column jsons for every result set
+ */
+ private function _jsonDecodeResult(&$result)
+ {
+ if (hasData($result))
+ {
+ for($i = 0; $i < count($result->retval); $i++)
+ {
+ $obj = $result->retval[$i];
+ $obj->jsons = json_decode($obj->jsons);
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/application/controllers/system/UDF.php b/application/controllers/system/UDF.php
new file mode 100644
index 000000000..4f08ad576
--- /dev/null
+++ b/application/controllers/system/UDF.php
@@ -0,0 +1,127 @@
+load->library('session');
+
+ // Loads the widget library
+ $this->load->library('WidgetLib');
+
+ //
+ $this->load->model('person/Person_model', 'PersonModel');
+ $this->load->model('crm/Prestudent_model', 'PrestudentModel');
+ }
+
+ /**
+ *
+ */
+ public function index()
+ {
+ $person_id = $this->input->get('person_id');
+ if (isset($this->session->person_id))
+ {
+ if (!isset($person_id))
+ {
+ $person_id = $this->session->person_id;
+ }
+ unset($this->session->person_id);
+ }
+
+ $prestudent_id = $this->input->get('prestudent_id');
+ if (isset($this->session->prestudent_id))
+ {
+ if (!isset($prestudent_id))
+ {
+ $prestudent_id = $this->session->prestudent_id;
+ }
+ unset($this->session->prestudent_id);
+ }
+
+ $result = null;
+ if (isset($this->session->result))
+ {
+ $result = clone $this->session->result;
+ $this->session->set_userdata('result', null);
+ }
+
+ $data = array('result' => $result);
+
+ if (isset($person_id) && is_numeric($person_id))
+ {
+ if ($this->PersonModel->hasUDF())
+ {
+ $person = $this->PersonModel->load($person_id);
+ $personUdfs = $this->PersonModel->getUDFs();
+ $personUdfs['person_id'] = $person_id;
+ $data['personUdfs'] = $personUdfs;
+ }
+ }
+
+ if (isset($prestudent_id) && is_numeric($prestudent_id))
+ {
+ if ($this->PrestudentModel->hasUDF())
+ {
+ $prestudent = $this->PrestudentModel->load($prestudent_id);
+ $prestudentUdfs = $this->PrestudentModel->getUDFs();
+ $prestudentUdfs['prestudent_id'] = $prestudent_id;
+ $data['prestudentUdfs'] = $prestudentUdfs;
+ }
+ }
+
+ $this->load->view('system/udf', $data);
+ }
+
+ /**
+ *
+ */
+ public function saveUDF()
+ {
+ $udfs = $this->input->post();
+ $validation = $this->_validate($udfs);
+
+ $userdata = array(
+ 'person_id' => $udfs['person_id'],
+ 'prestudent_id' => $udfs['prestudent_id']
+ );
+
+ if (isSuccess($validation))
+ {
+ // Load model UDF_model
+ $this->load->model('system/UDF_model', 'UDFModel');
+
+ $result = $this->UDFModel->saveUDFs($udfs);
+
+ $userdata['result'] = $result;
+ }
+ else
+ {
+ $userdata['result'] = $validation;
+ }
+
+ $this->session->set_userdata($userdata);
+ redirect('system/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;
+ }
+}
\ No newline at end of file
diff --git a/application/core/DB_Model.php b/application/core/DB_Model.php
index 369d8bb46..cbc0ee637 100644
--- a/application/core/DB_Model.php
+++ b/application/core/DB_Model.php
@@ -2,29 +2,73 @@
class DB_Model extends FHC_Model
{
+ // Default schema used by the models
+ const DEFAULT_SCHEMA = 'public';
+
+ // Default model class name postfix
+ const MODEL_POSTFIX = '_model';
+
+ // Query used to get the list of columns from a table
+ const QUERY_LIST_FIELDS = 'SELECT * FROM %s WHERE 0 = 1';
+
+ // Constants used to convert postgresql arrays and booleans to the php equivalent
const PGSQL_ARRAY_TYPE = '_';
const PGSQL_BOOLEAN_TYPE = 'bool';
const PGSQL_BOOLEAN_ARRAY_TYPE = '_bool';
const PGSQL_BOOLEAN_TRUE = 't';
const PGSQL_BOOLEAN_FALSE = 'f';
- const MODEL_POSTFIX = '_model';
- const DEFAULT_SCHEMA = 'public';
+
+ // UDF constants
+ const UDF_FIELD_NAME = 'udf_values';
+ const UDF_FIELD_TYPE = 'jsonb';
+ const UDF_FIELD_PREFIX = 'udf_';
+ const UDF_ATTRIBUTE_NAME = 'name';
+ const UDF_TYPE_NAME = 'type';
+ const UDF_CHKBOX_TYPE = 'checkbox';
+ const UDF_DROPDOWN_TYPE = 'dropdown';
+ const UDF_MULTIPLEDROPDOWN_TYPE = 'multipledropdown';
+ const UDF_FIELD_JSON_DESCRIPTION = 'jsons';
+
+ // UDF validation attributes
+ const UDF_REGEX = 'regex';
+ const UDF_REQUIRED = 'required';
+ const UDF_MAX_VALUE = 'max-value';
+ const UDF_MIN_VALUE = 'min-value';
+ const UDF_REGEX_LANG = 'php';
+ const UDF_MAX_LENGTH = 'max-length';
+ const UDF_MIN_LENGTH = 'min-length';
+
+ // String values of booleans
+ const STRING_TRUE = 'true';
+ const STRING_FALSE = 'false';
+ const STRING_NULL = 'null';
protected $dbTable; // Name of the DB-Table for CI-Insert, -Update, ...
protected $pk; // Name of the PrimaryKey for DB-Update, Load, ...
protected $hasSequence; // False if this table has a composite primary key that is not using a sequence
// True if this table has a primary key that uses a sequence
+ protected $UDFs; // Contains the UDFs
+
+ /**
+ * Constructor
+ */
function __construct($dbTable = null, $pk = null, $hasSequence = true)
{
+ // Call parent constructor
parent::__construct();
- $this->dbTable = $dbTable;
+
+ // Set properties
$this->pk = $pk;
+ $this->UDFs = array();
+ $this->dbTable = $dbTable;
$this->hasSequence = $hasSequence;
+
+ // Loads DB conns and confs
$this->load->database();
}
- /** ---------------------------------------------------------------
+ /**
* Insert Data into DB-Table
*
* @param array $data DataArray for Insert
@@ -39,6 +83,9 @@ class DB_Model extends FHC_Model
// Checks rights
if ($isEntitled = $this->_isEntitled(PermissionLib::INSERT_RIGHT)) return $isEntitled;
+ // UDFs
+ if (isError($validate = $this->_manageUDFs($data))) return $validate;
+
// DB-INSERT
if ($this->db->insert($this->dbTable, $data))
{
@@ -68,11 +115,14 @@ class DB_Model extends FHC_Model
return error($this->db->error(), FHC_DB_ERROR);
}
- /** ---------------------------------------------------------------
+ /**
* Replace Data in DB-Table
*
* @param array $data DataArray for Replacement
* @return array
+ *
+ * DEPRECATED: to be updated, not maintained
+ *
*/
public function replace($data)
{
@@ -82,15 +132,15 @@ class DB_Model extends FHC_Model
// Checks rights
if ($isEntitled = $this->_isEntitled(PermissionLib::REPLACE_RIGHT)) return $isEntitled;
-
+
// DB-REPLACE
if ($this->db->replace($this->dbTable, $data))
return success($this->db->insert_id());
else
return error($this->db->error(), FHC_DB_ERROR);
}
-
- /** ---------------------------------------------------------------
+
+ /**
* Update Data in DB-Table
*
* @param string $id PK for DB-Table
@@ -107,7 +157,10 @@ class DB_Model extends FHC_Model
// Checks rights
if ($isEntitled = $this->_isEntitled(PermissionLib::UPDATE_RIGHT)) return $isEntitled;
-
+
+ // UDFs
+ if (isError($validate = $this->_manageUDFs($data, $id))) return $validate;
+
// DB-UPDATE
// Check for composite Primary Key
if (is_array($id))
@@ -125,7 +178,7 @@ class DB_Model extends FHC_Model
return error($this->db->error(), FHC_DB_ERROR);
}
- /** ---------------------------------------------------------------
+ /**
* Delete data from DB-Table
*
* @param string $id Primary Key for DELETE
@@ -159,7 +212,7 @@ class DB_Model extends FHC_Model
return error($this->db->error(), FHC_DB_ERROR);
}
- /** ---------------------------------------------------------------
+ /**
* Load single data from DB-Table
*
* @param string $id ID (Primary Key) for SELECT ... WHERE
@@ -196,7 +249,7 @@ class DB_Model extends FHC_Model
return error($this->db->error(), FHC_DB_ERROR);
}
- /** ---------------------------------------------------------------
+ /**
* Load data from DB-Table with a where clause
*
* @return array
@@ -219,7 +272,7 @@ class DB_Model extends FHC_Model
return error($this->db->error(), FHC_DB_ERROR);
}
- /** ---------------------------------------------------------------
+ /**
* Load data and convert a record into a list of data from the main table,
* and linked to every element, the data from the side tables
*
@@ -287,7 +340,7 @@ class DB_Model extends FHC_Model
{
// Converts the object that contains data, from the returned CI's object to an array
// with the postgresql array and boolean types converterd
- $resultArray = $this->toPhp($resultDB);//var_dump($resultArray);
+ $resultArray = $this->toPhp($resultDB);
// Array that will contain all the mainTable records, and to each record the linked data
// of a side table
$returnArray = array();
@@ -364,7 +417,7 @@ class DB_Model extends FHC_Model
return $result;
}
- /** ---------------------------------------------------------------
+ /**
* Add a table to join with
*
* @return void
@@ -380,7 +433,7 @@ class DB_Model extends FHC_Model
return success(true);
}
- /** ---------------------------------------------------------------
+ /**
* Add order clause
*
* @return void
@@ -396,7 +449,7 @@ class DB_Model extends FHC_Model
return success(true);
}
- /** ---------------------------------------------------------------
+ /**
* Add select clause
*
* @return void
@@ -412,7 +465,7 @@ class DB_Model extends FHC_Model
return success(true);
}
- /** ---------------------------------------------------------------
+ /**
* Add distinct clause
*
* @return void
@@ -422,7 +475,7 @@ class DB_Model extends FHC_Model
$this->db->distinct();
}
- /** ---------------------------------------------------------------
+ /**
* Add limit clause
*
* @return void
@@ -445,7 +498,7 @@ class DB_Model extends FHC_Model
return success(true);
}
- /** ---------------------------------------------------------------
+ /**
* Add a table in the from clause
*
* @return void
@@ -468,7 +521,7 @@ class DB_Model extends FHC_Model
return success(true);
}
- /** ---------------------------------------------------------------
+ /**
* Add one or more fields in the group by clause
*
* @return void
@@ -488,7 +541,7 @@ class DB_Model extends FHC_Model
return success(true);
}
- /** ---------------------------------------------------------------
+ /**
* Reset the query builder state
*
* @return void
@@ -498,7 +551,7 @@ class DB_Model extends FHC_Model
$this->db->reset_query();
}
- /** ---------------------------------------------------------------
+ /**
* This method call the method escape from class CI_DB_driver, therefore:
* this method determines the data type so that it can escape only string data.
* It also automatically adds single quotes around the data so you don’t have to
@@ -510,7 +563,7 @@ class DB_Model extends FHC_Model
return $this->db->escape($value);
}
- /** ---------------------------------------------------------------
+ /**
* Convert PG-Boolean to PHP-Boolean
*
* @param char $b PG-Char to convert
@@ -533,7 +586,7 @@ class DB_Model extends FHC_Model
return $val;
}
- /** ---------------------------------------------------------------
+ /**
* Convert PG-Array to PHP-Array
*
* @param string $s PG-String to convert
@@ -623,7 +676,72 @@ class DB_Model extends FHC_Model
return $result;
}
- /** ---------------------------------------------------------------
+ /**
+ * Return the property UDFs
+ */
+ public function getUDFs()
+ {
+ return $this->UDFs;
+ }
+
+ /**
+ * Return one selected element of UDFs
+ */
+ public function getUDF($udf)
+ {
+ if (isset($this->UDFs[$udf]))
+ {
+ return $this->UDFs[$udf];
+ }
+
+ return null;
+ }
+
+ /**
+ * Checks if this table has the field udf_values
+ */
+ public function hasUDF()
+ {
+ return $this->fieldExists(DB_Model::UDF_FIELD_NAME);
+ }
+
+ /**
+ * Returns an array that contains a list of columns names of this table
+ */
+ public function listFields()
+ {
+ $listFields = array();
+
+ // Workaround to get metadata from this table
+ $result = $this->db->query(sprintf(DB_Model::QUERY_LIST_FIELDS, $this->dbTable));
+
+ if (is_object($result))
+ {
+ $listFields = $result->list_fields();
+ }
+
+ return $listFields;
+ }
+
+ /**
+ * Checks if this table has a field == $field
+ */
+ public function fieldExists($field)
+ {
+ $exists = true;
+
+ // If $field is not found in the list of fields of this table
+ if (array_search($field, $this->listFields()) === false)
+ {
+ $exists = false;
+ }
+
+ return $exists;
+ }
+
+ // ----------------------------------------------------------------------------
+
+ /**
* Invalid ID
*
* @param array $i Array with indexes.
@@ -702,6 +820,301 @@ class DB_Model extends FHC_Model
return $result;
}
+ // ----------------------------------------------------------------------------
+
+ /**
+ * Returns all the UDF for this table
+ */
+ private function _getUDFsDefinitions()
+ {
+ $this->load->model('system/UDF_model', 'UDFModel');
+
+ $schema = DB_Model::DEFAULT_SCHEMA;
+ $table = $this->dbTable;
+ $dotPos = strpos($table, '.');
+
+ if (is_numeric($dotPos) && $dotPos > 0)
+ {
+ $tmpArray = explode('.', $table);
+ $schema = $tmpArray[0];
+ $table = $tmpArray[1];
+ }
+
+ $this->UDFModel->addSelect(DB_Model::UDF_FIELD_JSON_DESCRIPTION);
+ $udfResults = $this->UDFModel->loadWhere(
+ array(
+ 'schema' => $schema,
+ 'table' => $table
+ )
+ );
+
+ return $udfResults;
+ }
+
+ /**
+ * Move UDFs from $data to $UDFs
+ */
+ private function _popUDFParameters(&$data)
+ {
+ foreach($data as $key => $val)
+ {
+ if (substr($key, 0, 4) == DB_Model::UDF_FIELD_PREFIX)
+ {
+ $this->UDFs[$key] = $val; // stores UDF value into property UDFs
+ unset($data[$key]); // remove from data
+ }
+ }
+ }
+
+ /**
+ * Validates UDF value
+ */
+ private function _validateUDFs($decodedUDFValidation, $udfName, $udfType, $udfValue)
+ {
+ $returnArrayValidation = array(); // returned value
+
+ //
+ if ((((isset($decodedUDFValidation->validation->{DB_Model::UDF_REQUIRED})
+ && $decodedUDFValidation->validation->{DB_Model::UDF_REQUIRED} === false)
+ || !isset($decodedUDFValidation->validation->{DB_Model::UDF_REQUIRED}))
+ && $udfValue == null)
+ || $udfType == DB_Model::UDF_CHKBOX_TYPE)
+ {
+ // NOP
+ }
+ else
+ {
+ // If $udfValue is not an array, then store it inside a new array
+ $tmpUdfValues = $udfValue;
+ if (!is_array($udfValue))
+ {
+ $tmpUdfValues = array($udfValue);
+ }
+
+ // Loops through all the supplied UDFs values
+ foreach($tmpUdfValues as $udfValIndx => $udfVal)
+ {
+ // If the single UDF value is not an array or an object
+ if (!is_array($udfVal) && !is_object($udfVal))
+ {
+ // If the UDF value is numeric (integer, float, double...)
+ if (is_numeric($udfVal))
+ {
+ // 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->{DB_Model::UDF_MIN_VALUE})
+ && $udfVal < $decodedUDFValidation->{DB_Model::UDF_MIN_VALUE})
+ {
+ // validation is failed and the error is stored in $returnArrayValidation
+ $returnArrayValidation[] = error($udfName, EXIT_VALIDATION_UDF_MIN_VALUE);
+ }
+
+ // 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->{DB_Model::UDF_MAX_VALUE})
+ && $udfVal > $decodedUDFValidation->{DB_Model::UDF_MAX_VALUE})
+ {
+ // validation is failed and the error is stored in $returnArrayValidation
+ $returnArrayValidation[] = error($udfName, EXIT_VALIDATION_UDF_MAX_VALUE);
+ }
+ }
+
+ $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->{DB_Model::UDF_MIN_LENGTH}) && isset($strUdfVal)
+ && strlen($strUdfVal) < $decodedUDFValidation->{DB_Model::UDF_MIN_LENGTH})
+ {
+ // validation is failed and the error is stored in $returnArrayValidation
+ $returnArrayValidation[] = error($udfName, EXIT_VALIDATION_UDF_MIN_LENGTH);
+ }
+
+ // 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->{DB_Model::UDF_MAX_LENGTH}) && isset($strUdfVal)
+ && strlen($strUdfVal) > $decodedUDFValidation->{DB_Model::UDF_MAX_LENGTH})
+ {
+ // validation is failed and the error is stored in $returnArrayValidation
+ $returnArrayValidation[] = error($udfName, EXIT_VALIDATION_UDF_MAX_LENGTH);
+ }
+
+ // If $udfVal is a string
+ if (is_string($udfVal))
+ {
+ // 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->{DB_Model::UDF_REGEX})
+ && is_array($decodedUDFValidation->{DB_Model::UDF_REGEX}))
+ {
+ foreach($decodedUDFValidation->{DB_Model::UDF_REGEX} as $regexIndx => $regex)
+ {
+ if ($regex->language == DB_Model::UDF_REGEX_LANG)
+ {
+ if (preg_match($regex->expression, $udfVal) != 1)
+ {
+ // validation is failed and the error is stored in $returnArrayValidation
+ $returnArrayValidation[] = error($udfName, EXIT_VALIDATION_UDF_REGEX);
+ }
+ }
+ }
+ }
+ }
+ }
+ else // otherwise the validation is failed and the error is stored in $returnArrayValidation
+ {
+ $returnArrayValidation[] = error($udfName, EXIT_VALIDATION_UDF_NOT_VALID_VAL);
+ }
+ }
+ }
+
+ // If no UDF validation errors were raised, it's a success!!
+ if (count($returnArrayValidation) == 0)
+ {
+ $returnArrayValidation = success(true);
+ }
+
+ return $returnArrayValidation;
+ }
+
+ /**
+ * Manage UDFs
+ */
+ private function _manageUDFs(&$data, $id = null)
+ {
+ $validate = success(true); // returned value
+ // Contains a list of validation errors for the UDFs that have not passed the validation
+ $notValidUDFsArray = array();
+
+ if ($this->hasUDF()) // Checks if this table has UDFs
+ {
+ $resultUDFsDefinitions = $this->_getUDFsDefinitions(); // retrieves UDFs definitions for this table
+ if (hasData($resultUDFsDefinitions)) // standard check if everything is ok and data are present
+ {
+ // Get udf values from $data & clean udf values from $data
+ // NOTE: Must be performed here because the load method populates the property UDFs too
+ $this->_popUDFParameters($data);
+
+ $requiredUDFsArray = array(); // contains a list of required UDFs
+ // Contains the UDFs values to be stored
+ // NOTE: the UDFs supplied that are not present in the UDF definition of this table, will be discarded
+ $toBeStoredUDFsArray = array();
+
+ // Decodes json that define the UDFs for this table
+ $decodedUDFDefinitions = json_decode(
+ $resultUDFsDefinitions->retval[0]->{DB_Model::UDF_FIELD_JSON_DESCRIPTION}
+ );
+
+ // Loops through the UDFs definitions
+ for($i = 0; $i < count($decodedUDFDefinitions); $i++)
+ {
+ $decodedUDFDefinition = $decodedUDFDefinitions[$i]; // Definition of a single UDF
+
+ // If validation rules are present for this UDF description and the required attribute is === true
+ // then add this UDF into $requiredUDFsArray
+ if(isset($decodedUDFDefinition->validation)
+ && isset($decodedUDFDefinition->validation->{DB_Model::UDF_REQUIRED})
+ && $decodedUDFDefinition->validation->{DB_Model::UDF_REQUIRED} === true)
+ {
+ $requiredUDFsArray[$decodedUDFDefinition->{DB_Model::UDF_ATTRIBUTE_NAME}] = error(
+ $decodedUDFDefinition->{DB_Model::UDF_ATTRIBUTE_NAME},
+ EXIT_VALIDATION_UDF_REQUIRED
+ );
+ }
+
+ // Loops through the UDFs values that should be stored
+ foreach($this->UDFs as $key => $val)
+ {
+ // If this is the definition of this UDF
+ if ($decodedUDFDefinition->{DB_Model::UDF_ATTRIBUTE_NAME} == $key)
+ {
+ if (isset($decodedUDFDefinition->validation)) // If validation rules are present for this UDF
+ {
+ // Validation!!!
+ $validate = $this->_validateUDFs(
+ $decodedUDFDefinition->validation, //
+ $decodedUDFDefinition->{DB_Model::UDF_ATTRIBUTE_NAME}, //
+ $decodedUDFDefinition->{DB_Model::UDF_TYPE_NAME},
+ $val //
+ );
+
+ // If the validation attribute required is === true for this UDF
+ // and this UDF is present in the array $requiredUDFsArray
+ // then removes this UDF from the array $requiredUDFsArray
+ // because this UDF is present in the property UDFs (the list of UDFs that should be stored)
+ // therefore it was supplied
+ if (isset($decodedUDFDefinition->validation->{DB_Model::UDF_REQUIRED})
+ && $decodedUDFDefinition->validation->{DB_Model::UDF_REQUIRED} === true
+ && isset($requiredUDFsArray[$decodedUDFDefinition->{DB_Model::UDF_ATTRIBUTE_NAME}])
+ && $val != null)
+ {
+ unset($requiredUDFsArray[$decodedUDFDefinition->{DB_Model::UDF_ATTRIBUTE_NAME}]);
+ }
+ }
+
+ // If validation is ok copy the value that is to be stored into $toBeStoredUDFsArray
+ if (isSuccess($validate))
+ {
+ $toBeStoredUDFsArray[$key] = $val;
+ }
+ else // otherwise store the validation error in $notValidUDFsArray
+ {
+ $notValidUDFsArray[] = $validate;
+ }
+ }
+ }
+ }
+
+ // Copies the remaining required UDFs into $notValidUDFsArray
+ // because they were not supplied, therefore must be notified as error
+ foreach($requiredUDFsArray as $key => $val)
+ {
+ $notValidUDFsArray[] = array($val);
+ }
+
+ // If the validation of all the supplied UDFs is ok
+ if (count($notValidUDFsArray) == 0)
+ {
+ // An update is performed, then in this case it preserves the values
+ // of the UDF that are not updated
+ if ($id != null)
+ {
+ $record = $this->load($id); // retrive the DB record
+ // Checks that everything is ok and that there is only one record
+ if (isSuccess($record) && count($record->retval) == 1)
+ {
+ $recordFields = (array)$record->retval[0]; // convert to an array
+ foreach($recordFields as $fieldName => $fieldValue)
+ {
+ // If this field is an UDF
+ if (substr($fieldName, 0, 4) == DB_Model::UDF_FIELD_PREFIX)
+ {
+ // If this field is not present in the given parameters
+ // then copy it from the DB without changes
+ if (!array_key_exists($fieldName, $toBeStoredUDFsArray))
+ {
+ $toBeStoredUDFsArray[$fieldName] = $fieldValue;
+ }
+ }
+ }
+ }
+ }
+ $encodedToBeStoredUDFs = json_encode($toBeStoredUDFsArray); // encode to json
+ if ($encodedToBeStoredUDFs !== false) // if encode was ok
+ {
+ // Save the supplied UDFs values
+ $data[DB_Model::UDF_FIELD_NAME] = $encodedToBeStoredUDFs;
+ }
+ }
+ else // otherwise the returning value will be the list of UDFs validation errors
+ {
+ $validate = error($notValidUDFsArray, EXIT_VALIDATION_UDF);
+ }
+ }
+ }
+
+ return $validate;
+ }
+
/**
* Checks if the caller is entitled to perform this operation with this right
*/
@@ -744,8 +1157,9 @@ class DB_Model extends FHC_Model
for($i = 0; $i < count($metaDataArray); $i++) // Looking for booleans and arrays
{
// If array type or boolean type
- if (strpos($metaDataArray[$i]->type, DB_Model::PGSQL_ARRAY_TYPE) !== false ||
- $metaDataArray[$i]->type == DB_Model::PGSQL_BOOLEAN_TYPE)
+ if (strpos($metaDataArray[$i]->type, DB_Model::PGSQL_ARRAY_TYPE) !== false
+ || $metaDataArray[$i]->type == DB_Model::PGSQL_BOOLEAN_TYPE
+ || $metaDataArray[$i]->name == DB_Model::UDF_FIELD_NAME)
{
// Name and type of the field to be converted
$toBeConverted = new stdClass();
@@ -767,7 +1181,7 @@ class DB_Model extends FHC_Model
for($i = 0; $i < count($resultsArray); $i++)
{
// Single element
- $tmpResult = $resultsArray[$i];
+ $resultElement = $resultsArray[$i];
// Looping on fields to be converted
for($j = 0; $j < count($toBeConverterdArray); $j++)
{
@@ -777,15 +1191,31 @@ class DB_Model extends FHC_Model
// Array type
if (strpos($toBeConverted->type, DB_Model::PGSQL_ARRAY_TYPE) !== false)
{
- $tmpResult->{$toBeConverted->name} = $this->pgsqlArrayToPhpArray(
- $tmpResult->{$toBeConverted->name},
+ $resultElement->{$toBeConverted->name} = $this->pgsqlArrayToPhpArray(
+ $resultElement->{$toBeConverted->name},
$toBeConverted->type == DB_Model::PGSQL_BOOLEAN_ARRAY_TYPE
);
}
// Boolean type
else if ($toBeConverted->type == DB_Model::PGSQL_BOOLEAN_TYPE)
{
- $tmpResult->{$toBeConverted->name} = $this->pgBoolPhp($tmpResult->{$toBeConverted->name});
+ $resultElement->{$toBeConverted->name} = $this->pgBoolPhp($resultElement->{$toBeConverted->name});
+ }
+ // UDF
+ else if ($toBeConverted->type == DB_Model::UDF_FIELD_TYPE
+ && substr($toBeConverted->name, 0, 4) == DB_Model::UDF_FIELD_PREFIX)
+ {
+ $jsonValues = json_decode($resultElement->{$toBeConverted->name}); // decode UDFs values
+ if ($jsonValues != null) // if decode is ok
+ {
+ // For every UDF
+ foreach($jsonValues as $key => $value)
+ {
+ $resultElement->{$key} = $value; // create a new element called like the UDF
+ $this->UDFs[$key] = $value; // stores the UDF in the property UDFs
+ }
+ }
+ unset($resultElement->{$toBeConverted->name}); // remove udf_values from the response
}
}
}
diff --git a/application/language/de-AT/fhc_model_lang.php b/application/language/de-AT/fhc_model_lang.php
index 4acf23341..8d030c940 100644
--- a/application/language/de-AT/fhc_model_lang.php
+++ b/application/language/de-AT/fhc_model_lang.php
@@ -1,9 +1,16 @@
-_ci = & get_instance();
-
- // set the default widget path with APPPATH
- $this->_widget_path = APPPATH . 'widgets/';
-
- if (!empty($config))
- $this->initialize($config);
-
- log_message('debug', 'Template library initialized');
- }
-
- /**
- * Initialize with configuration array
- * @param array $config
- * @return Template
- */
- public function initialize($config = array())
- {
- foreach ($config as $key => $val)
- $this->{'_' . $key} = $val;
-
- if ($this->_widget_path == '')
- $this->_widget_path = APPPATH . 'widgets/';
-
- if ($this->_parser && !class_exists('CI_Parser'))
- $this->_ci->load->library('parser');
- }
-
- /**
- * Set a partial's content. This will create a new partial when not existing
- * @param string $index
- * @param mixed $value
- */
- public function __set($name, $value)
- {
- $this->partial($name)->set($value);
- }
-
- /**
- * Access to partials for method chaining
- * @param string $name
- * @return mixed
- */
- public function __get($name)
- {
- return $this->partial($name);
- }
-
- /**
- * Check if a partial exists
- * @param string $index
- * @return boolean
- */
- public function exists($index)
- {
- return array_key_exists($index, $this->_partials);
- }
-
- /**
- * Set the template file
- * @param string $template
- */
- public function set_template($template)
- {
- $this->_template = $template;
- }
-
- /**
- * Publish the template with the current partials
- * You can manually pass a template file with extra data, or use the default template from the config file
- * @param string $template
- * @param array $data
- */
- public function publish($template = FALSE, $data = array()) {
- if (is_array($template) || is_object($template)) {
- $data = $template;
- } else if ($template) {
- $this->_template = $template;
- }
-
- if (!$this->_template) {
- show_error('There was no template file selected for the current template');
- }
-
- if (is_array($data) || is_object($data)) {
- foreach ($data as $name => $content) {
- $this->partial($name)->set($content);
- }
- }
-
- unset($data);
-
- if ($this->_parser) {
- $this->_ci->parser->parse($this->_template, $this->_partials);
- } else {
- $this->_ci->load->view($this->_template, $this->_partials);
- }
- }
-
- /**
- * Create a partial object with an optional default content
- * Can be usefull to use straight from the template file
- * @param string $name
- * @param string $default
- * @return Partial
- */
- public function partial($name, $default = FALSE) {
- if ($this->exists($name)) {
- $partial = $this->_partials[$name];
- } else {
- // create new partial
- $partial = new Partial($name);
- if ($this->_cache_ttl) {
- $partial->cache($this->_cache_ttl);
- }
-
- // detect local triggers
- if (method_exists($this, 'trigger_' . $name)) {
- $partial->bind($this, 'trigger_' . $name);
- }
-
- $this->_partials[$name] = $partial;
- }
-
- if (!$partial->content() && $default) {
- $partial->set($default);
- }
-
- return $partial;
- }
-
- /**
- * Create a widget object with optional parameters
- * Can be usefull to use straight from the template file
- * @param string $name
- * @param array $data
- * @param array $htmlArgs
- * @return Widget
- */
- public function widget($name, $data = array(), $htmlArgs = array())
- {
- $class = str_replace('.php', '', trim($name, '/'));
-
- // determine path and widget class name
- $path = $this->_widget_path;
- if (($last_slash = strrpos($class, '/')) !== FALSE) {
- $path += substr($class, 0, $last_slash);
- $class = substr($class, $last_slash + 1);
- }
-
- // new widget
- if (!class_exists($class)) {
- // try both lowercase and capitalized versions
- foreach (array(ucfirst($class), strtolower($class)) as $class) {
- if (file_exists($path . $class . '.php')) {
- include_once ($path . $class . '.php');
-
- // found the file, stop looking
- break;
- }
- }
- }
-
- if (!class_exists($class)) {
- show_error("Widget '" . $class . "' was not found.");
- }
-
- return new $class($class, $data, $htmlArgs);
- }
-
- /**
- * Enable cache for all partials with TTL, default TTL is 60
- * @param int $ttl
- * @param mixed $identifier
- */
- public function cache($ttl = 60, $identifier = '') {
- foreach ($this->_partials as $partial) {
- $partial->cache($ttl, $identifier);
- }
-
- $this->_cache_ttl = $ttl;
- }
-
- // ---- TRIGGERS -----------------------------------------------------------------
-
- /**
- * Stylesheet trigger
- * @param string $source
- */
- public function trigger_stylesheet($url, $attributes = FALSE) {
- // array support
- if (is_array($url)) {
- $return = '';
- foreach ($url as $u) {
- $return .= $this->trigger_stylesheet($u, $attributes);
- }
- return $return;
- }
-
- if (!stristr($url, 'http://') && !stristr($url, 'https://') && substr($url, 0, 2) != '//') {
- $url = $this->_ci->config->item('base_url') . $url;
- }
-
- // legacy support for media
- if (is_string($attributes)) {
- $attributes = array('media' => $attributes);
- }
-
- if (is_array($attributes)) {
- $attributeString = "";
-
- foreach ($attributes as $key => $value) {
- $attributeString .= $key . '="' . $value . '" ';
- }
-
- return ' ' . "\n\t";
- } else {
- return ' ' . "\n\t";
- }
- }
-
- /**
- * Javascript trigger
- * @param string $source
- */
- public function trigger_javascript($url) {
- // array support
- if (is_array($url)) {
- $return = '';
- foreach ($url as $u) {
- $return .= $this->trigger_javascript($u);
- }
- return $return;
- }
-
- if (!stristr($url, 'http://') && !stristr($url, 'https://') && substr($url, 0, 2) != '//') {
- $url = $this->_ci->config->item('base_url') . $url;
- }
-
- return '' . "\n\t";
- }
-
- /**
- * Meta trigger
- * @param string $name
- * @param mixed $value
- * @param enum $type
- */
- public function trigger_meta($name, $value, $type = 'meta') {
- $name = htmlspecialchars(strip_tags($name));
- $value = htmlspecialchars(strip_tags($value));
-
- if ($name == 'keywords' and !strpos($value, ',')) {
- $content = preg_replace('/[\s]+/', ', ', trim($value));
- }
-
- switch ($type) {
- case 'meta' :
- $content = ' ' . "\n\t";
- break;
- case 'link' :
- $content = ' ' . "\n\t";
- break;
- }
-
- return $content;
- }
-
- /**
- * Title trigger, keeps it clean
- * @param string $name
- * @param mixed $value
- * @param enum $type
- */
- public function trigger_title($title) {
- return htmlspecialchars(strip_tags($title));
- }
-
- /**
- * Title trigger, keeps it clean
- * @param string $name
- * @param mixed $value
- * @param enum $type
- */
- public function trigger_description($description) {
- return htmlspecialchars(strip_tags($description));
- }
-
-}
-
-class Partial
-{
- protected $_ci, $_content, $_name, $_cache_ttl = 0, $_cached = false, $_identifier, $_trigger;
- protected $_args = array();
-
- /**
- * Construct with optional parameters
- * @param array $args
- */
- public function __construct($name, $args = array())
- {
- $this->_ci = &get_instance();
- $this->_args = $args;
- $this->_name = $name;
- }
-
- /**
- * Gives access to codeigniter's functions from this class if needed
- * This will be handy in extending classes
- * @param string $index
- */
- function __get($name) {
- return $this->_ci->$name;
- }
-
- /**
- * Alias methods
- */
- function __call($name, $args) {
- switch ($name) {
- case 'default' :
- return call_user_func_array(array($this, 'set_default'), $args);
- break;
- case 'add' :
- return call_user_func_array(array($this, 'append'), $args);
- break;
- }
- }
-
- /**
- * Returns the content when converted to a string
- * @return string
- */
- public function __toString() {
- return (string) $this->content();
- }
-
- /**
- * Returns the content
- * @return string
- */
- public function content() {
- if ($this->_cache_ttl && !$this->_cached) {
- $this->cache->save($this->cache_id(), $this->_content, $this->_cache_ttl);
- }
-
- return $this->_content;
- }
-
- /**
- * Overwrite the content
- * @param mixed $content
- * @return Partial
- */
- public function set() {
- if (!$this->_cached) {
- $this->_content = (string) $this->trigger(func_get_args());
- }
-
- return $this;
- }
-
- /**
- * Append something to the content
- * @param mixed $content
- * @return Partial
- */
- public function append() {
- if (!$this->_cached) {
- $this->_content .= (string) $this->trigger(func_get_args());
- }
-
- return $this;
- }
-
- /**
- * Prepend something to the content
- * @param mixed $content
- * @return Partial
- */
- public function prepend() {
- if (!$this->_cached) {
- $this->_content = (string) $this->trigger(func_get_args()) . $this->_content;
- }
-
- return $this;
- }
-
- /**
- * Set content if partial is empty
- * @param mixed $default
- * @return Partial
- */
- public function set_default($default) {
- if (!$this->_cached) {
- if (!$this->_content) {
- $this->_content = $default;
- }
- }
-
- return $this;
- }
-
- /**
- * Load a view inside this partial, overwrite if wanted
- * @param string $view
- * @param array $data
- * @param bool $overwrite
- * @return Partial
- */
- public function view($view, $data = array(), $overwrite = false) {
- if (!$this->_cached) {
-
- // better object to array
- if (is_object($data)) {
- $array = array();
- foreach ($data as $k => $v) {
- $array[$k] = $v;
- }
- $data = $array;
- }
-
- $content = $this->_ci->load->view($view, $data, true);
-
- if ($overwrite) {
- $this->set($content);
- } else {
- $this->append($content);
- }
- }
- return $this;
- }
-
- /**
- * Parses a view inside this partial, overwrite if wanted
- * @param string $view
- * @param array $data
- * @param bool $overwrite
- * @return Partial
- */
- public function parse($view, $data = array(), $overwrite = false) {
- if (!$this->_cached) {
- if (!class_exists('CI_Parser')) {
- $this->_ci->load->library('parser');
- }
-
- // better object to array
- if (is_object($data)) {
- $array = array();
- foreach ($data as $k => $v) {
- $array[$k] = $v;
- }
- $data = $array;
- }
-
- $content = $this->_ci->parser->parse($view, $data, true);
-
- if ($overwrite) {
- $this->set($content);
- } else {
- $this->append($content);
- }
- }
-
- return $this;
- }
-
- /**
- * Loads a widget inside this partial, overwrite if wanted
- * @param string $name
- * @param array $data
- * @param bool $overwrite
- * @return Partial
- */
- public function widget($name, $data = array(), $overwrite = false) {
- if (!$this->_cached) {
- $widget = $this->template->widget($name, $data);
-
- if ($overwrite) {
- $this->set($widget->content());
- } else {
- $this->append($widget->content());
- }
- }
- return $this;
- }
-
- /**
- * Enable cache with TTL, default TTL is 60
- * @param int $ttl
- * @param mixed $identifier
- */
- public function cache($ttl = 60, $identifier = '') {
- if (!class_exists('CI_Cache')) {
- $this->_ci->load->driver('cache', array('adapter' => 'file'));
- }
-
- $this->_cache_ttl = $ttl;
- $this->_identifier = $identifier;
-
- if ($cached = $this->_ci->cache->get($this->cache_id())) {
- $this->_cached = true;
- $this->_content = $cached;
- }
- return $this;
- }
-
- /**
- * Used for cache identification
- * @return string
- */
- private function cache_id() {
- if ($this->_identifier) {
- return $this->_name . '_' . $this->_identifier . '_' . md5(get_class($this) . implode('', $this->_args));
- } else {
- return $this->_name . '_' . md5(get_class($this) . implode('', $this->_args));
- }
- }
-
- /**
- * Trigger returns the result if a trigger is set
- * @param array $args
- * @return string
- */
- public function trigger($args) {
- if (!$this->_trigger) {
- return implode('', $args);
- } else {
- return call_user_func_array($this->_trigger, $args);
- }
- }
-
- /**
- * Bind a trigger function
- * Can be used like bind($this, "function") or bind("function")
- * @param mixed $arg
- */
- public function bind() {
- if ($count = func_num_args()) {
- if ($count >= 2) {
- $args = func_get_args();
- $obj = array_shift($args);
- $func = array_pop($args);
-
- foreach ($args as $trigger) {
- $obj = $obj->$trigger;
- }
-
- $this->_trigger = array($obj, $func);
- } else {
- $args = func_get_args();
- $this->_trigger = reset($args);
- }
- } else {
- $this->_trigger = FALSE;
- }
- }
-}
-
-/**
- * The mother of all widgets
- * it represent a generic HTML element
- */
-class Widget extends Partial
-{
- // The name of the array present in the data array given to the view that will render this widget
- const HTML_ARG_NAME = 'HTML';
- const HTML_DEFAULT_VALUE = ''; // Default value of the html element
- const HTML_NAME = 'name'; // HTML name attribute
- const HTML_ID = 'id'; // HTML id attribute
-
- /**
- * It gets also the htmlArgs array as parameter, it will be used to set the HTML properties
- */
- public function __construct($name, $args, $htmlArgs = array())
- {
- parent::__construct($name, $args);
-
- // Initialising HTML properties
- $this->_setHtmlProperties($htmlArgs);
-
- // Loads helper message to manage returning messages
- $this->load->helper('message');
- }
-
- /**
- * (non-PHPdoc)
- * @see Partial::content()
- */
- public function content()
- {
- if (!$this->_cached)
- {
- if (method_exists($this, 'display'))
- {
- // capture output
- ob_start();
- $this->display($this->_args);
- $buffer = ob_get_clean();
-
- // if no content is produced but there was direct ouput we set
- // that output as content
- if (!$this->_content && $buffer)
- {
- $this->set($buffer);
- }
- }
- }
-
- return parent::content();
- }
-
- /**
- * Initialising html properties, such as the id and name attributes of the HTML element
- */
- private function _setHtmlProperties($htmlArgs)
- {
- if (isset($htmlArgs) && is_array($htmlArgs))
- {
- $this->_args[Widget::HTML_ARG_NAME] = array();
-
- // Avoids that the elements of a same HTML page have the same name or id
- $randomIdentifier = uniqid(rand(0, 1000));
-
- if (isset($htmlArgs[Widget::HTML_ID]) && trim($htmlArgs[Widget::HTML_ID]) != '')
- {
- $this->_args[Widget::HTML_ARG_NAME][Widget::HTML_ID] = $htmlArgs[Widget::HTML_ID];
- }
- else
- {
- $this->_args[Widget::HTML_ARG_NAME][Widget::HTML_ID] = $randomIdentifier;
- }
-
- if (isset($htmlArgs[Widget::HTML_NAME]) && trim($htmlArgs[Widget::HTML_NAME]) != '')
- {
- $this->_args[Widget::HTML_ARG_NAME][Widget::HTML_NAME] = $htmlArgs[Widget::HTML_NAME];
- }
- else
- {
- $this->_args[Widget::HTML_ARG_NAME][Widget::HTML_NAME] = $randomIdentifier;
- }
- }
- }
-}
-
-/**
- * It exends the Widget class to represent an HTML dropdown
- */
-class DropdownWidget 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_ELEMENTS_ARRAY_NAME = 'ELEMENTS_ARRAY';
- // Name of the property that will be used to store the value attribute of the option tag
- const ID_FIELD = 'id';
- // Name of the property that will be used to store the value between the option tags
- const DESCRIPTION_FIELD = 'description'; //
- // 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 SELECTED_ELEMENT = 'selectedElement'; //
-
- private $elementsArray; // Array of elements to be place inside the dropdown
-
- /**
- * Loads the dropdown view with all the elements to be displayed
- */
- protected function loadDropDownView($widgetData)
- {
- $widgetData[DropdownWidget::WIDGET_DATA_ELEMENTS_ARRAY_NAME] = $this->elementsArray->retval;
-
- if (!isset($widgetData[DropdownWidget::SELECTED_ELEMENT]))
- {
- $widgetData[DropdownWidget::SELECTED_ELEMENT] = Widget::HTML_DEFAULT_VALUE;
- }
-
- $this->view('widgets/dropdown', $widgetData);
- }
-
- /**
- * Add the correct select to the model used to load a list of elemets for this dropdown
- * @param model $model the model used to load elements
- * @param string $idName the name of the field that will used to be the value of the option tag
- * @param string $descriptionName the name of the field that will used to be displayed in the dropdown
- */
- protected function addSelectToModel($model, $idName, $descriptionName)
- {
- $model->addSelect(
- sprintf(
- '%s AS %s, %s AS %s',
- $idName,
- DropdownWidget::ID_FIELD,
- $descriptionName,
- DropdownWidget::DESCRIPTION_FIELD
- )
- );
- }
-
- /**
- * Set the array used to populate the dropdown
- * @param array $elements list used to populate this dropdown
- * @param boolean $emptyElement if an empty element must be added at the beginning of the dropdown
- * @param string $stdDescription description of the empty element
- * @param string $noDataDescription description if no data are found
- * @param string $id value of the attribute value of the empty element
- */
- protected function setElementsArray(
- $elements, $emptyElement = false, $stdDescription = '' , $noDataDescription = '' , $id = Widget::HTML_DEFAULT_VALUE
- )
- {
- if (isError($elements))
- {
- if (is_object($elements) && isset($elements->retval))
- {
- show_error($elements->retval);
- }
- else if (is_string($elements))
- {
- show_error($elements);
- }
- else
- {
- show_error('Generic error occurred');
- }
- }
- else
- {
- $this->elementsArray = $elements;
-
- if ($emptyElement === true)
- {
- $this->addElementAtBeginning($stdDescription, $noDataDescription, $id);
- }
- }
- }
-
- /**
- * Adds an element to the beginning of the array
- */
- protected function addElementAtBeginning($stdDescription, $noDataDescription, $id)
- {
- $element = new stdClass();
- $element->id = $id;
- $element->description = $stdDescription;
-
- if (!hasData($this->elementsArray))
- {
- $element->description = $noDataDescription;
- }
-
- array_unshift($this->elementsArray->retval, $element);
- }
+_ci = & get_instance();
+
+ // set the default widget path with APPPATH
+ $this->_widget_path = APPPATH . 'widgets/';
+
+ if (!empty($config))
+ $this->initialize($config);
+
+ log_message('debug', 'Template library initialized');
+ }
+
+ /**
+ * Initialize with configuration array
+ * @param array $config
+ * @return Template
+ */
+ public function initialize($config = array())
+ {
+ foreach ($config as $key => $val)
+ $this->{'_' . $key} = $val;
+
+ if ($this->_widget_path == '')
+ $this->_widget_path = APPPATH . 'widgets/';
+
+ if ($this->_parser && !class_exists('CI_Parser'))
+ $this->_ci->load->library('parser');
+ }
+
+ /**
+ * Set a partial's content. This will create a new partial when not existing
+ * @param string $index
+ * @param mixed $value
+ */
+ public function __set($name, $value)
+ {
+ $this->partial($name)->set($value);
+ }
+
+ /**
+ * Access to partials for method chaining
+ * @param string $name
+ * @return mixed
+ */
+ public function __get($name)
+ {
+ return $this->partial($name);
+ }
+
+ /**
+ * Check if a partial exists
+ * @param string $index
+ * @return boolean
+ */
+ public function exists($index)
+ {
+ return array_key_exists($index, $this->_partials);
+ }
+
+ /**
+ * Set the template file
+ * @param string $template
+ */
+ public function set_template($template)
+ {
+ $this->_template = $template;
+ }
+
+ /**
+ * Publish the template with the current partials
+ * You can manually pass a template file with extra data, or use the default template from the config file
+ * @param string $template
+ * @param array $data
+ */
+ public function publish($template = FALSE, $data = array()) {
+ if (is_array($template) || is_object($template)) {
+ $data = $template;
+ } else if ($template) {
+ $this->_template = $template;
+ }
+
+ if (!$this->_template) {
+ show_error('There was no template file selected for the current template');
+ }
+
+ if (is_array($data) || is_object($data)) {
+ foreach ($data as $name => $content) {
+ $this->partial($name)->set($content);
+ }
+ }
+
+ unset($data);
+
+ if ($this->_parser) {
+ $this->_ci->parser->parse($this->_template, $this->_partials);
+ } else {
+ $this->_ci->load->view($this->_template, $this->_partials);
+ }
+ }
+
+ /**
+ * Create a partial object with an optional default content
+ * Can be usefull to use straight from the template file
+ * @param string $name
+ * @param string $default
+ * @return Partial
+ */
+ public function partial($name, $default = FALSE) {
+ if ($this->exists($name)) {
+ $partial = $this->_partials[$name];
+ } else {
+ // create new partial
+ $partial = new Partial($name);
+ if ($this->_cache_ttl) {
+ $partial->cache($this->_cache_ttl);
+ }
+
+ // detect local triggers
+ if (method_exists($this, 'trigger_' . $name)) {
+ $partial->bind($this, 'trigger_' . $name);
+ }
+
+ $this->_partials[$name] = $partial;
+ }
+
+ if (!$partial->content() && $default) {
+ $partial->set($default);
+ }
+
+ return $partial;
+ }
+
+ /**
+ * Create a widget object with optional parameters
+ * Can be usefull to use straight from the template file
+ * @param string $name
+ * @param array $data
+ * @param array $htmlArgs
+ * @return Widget
+ */
+ public function widget($name, $data = array(), $htmlArgs = array())
+ {
+ $class = str_replace('.php', '', trim($name, '/'));
+
+ // determine path and widget class name
+ $path = $this->_widget_path;
+ if (($last_slash = strrpos($class, '/')) !== FALSE) {
+ $path += substr($class, 0, $last_slash);
+ $class = substr($class, $last_slash + 1);
+ }
+
+ // new widget
+ if (!class_exists($class)) {
+ // try both lowercase and capitalized versions
+ foreach (array(ucfirst($class), strtolower($class)) as $class) {
+ if (file_exists($path . $class . '.php')) {
+ include_once ($path . $class . '.php');
+
+ // found the file, stop looking
+ break;
+ }
+ }
+ }
+
+ if (!class_exists($class)) {
+ show_error("Widget '" . $class . "' was not found.");
+ }
+
+ return new $class($class, $data, $htmlArgs);
+ }
+
+ /**
+ *
+ */
+ public function UDFWidget($args, $htmlArgs = array())
+ {
+ if (!empty($args[UDFWidgetTpl::SCHEMA_ARG_NAME]) && !empty($args[UDFWidgetTpl::TABLE_ARG_NAME]))
+ {
+ //
+ if (empty($args[UDFWidgetTpl::FIELD_ARG_NAME]) && !isset($htmlArgs[Widget::EXTERNAL_BLOCK]))
+ {
+ $htmlArgs[Widget::EXTERNAL_BLOCK] = true;
+ }
+
+ return $this->widget(
+ UDFWidgetTpl::WIDGET_NAME,
+ $args,
+ $htmlArgs
+ );
+ }
+ else
+ {
+ if (empty($args[UDFWidgetTpl::SCHEMA_ARG_NAME]))
+ {
+ show_error(UDFWidgetTpl::SCHEMA_ARG_NAME.' parameter is missing!');
+ }
+ if (empty($args[UDFWidgetTpl::TABLE_ARG_NAME]))
+ {
+ show_error(UDFWidgetTpl::TABLE_ARG_NAME.' parameter is missing!');
+ }
+ }
+ }
+
+ /**
+ * Enable cache for all partials with TTL, default TTL is 60
+ * @param int $ttl
+ * @param mixed $identifier
+ */
+ public function cache($ttl = 60, $identifier = '') {
+ foreach ($this->_partials as $partial) {
+ $partial->cache($ttl, $identifier);
+ }
+
+ $this->_cache_ttl = $ttl;
+ }
+
+ // ---- TRIGGERS -----------------------------------------------------------------
+
+ /**
+ * Stylesheet trigger
+ * @param string $source
+ */
+ public function trigger_stylesheet($url, $attributes = FALSE) {
+ // array support
+ if (is_array($url)) {
+ $return = '';
+ foreach ($url as $u) {
+ $return .= $this->trigger_stylesheet($u, $attributes);
+ }
+ return $return;
+ }
+
+ if (!stristr($url, 'http://') && !stristr($url, 'https://') && substr($url, 0, 2) != '//') {
+ $url = $this->_ci->config->item('base_url') . $url;
+ }
+
+ // legacy support for media
+ if (is_string($attributes)) {
+ $attributes = array('media' => $attributes);
+ }
+
+ if (is_array($attributes)) {
+ $attributeString = "";
+
+ foreach ($attributes as $key => $value) {
+ $attributeString .= $key . '="' . $value . '" ';
+ }
+
+ return ' ' . "\n\t";
+ } else {
+ return ' ' . "\n\t";
+ }
+ }
+
+ /**
+ * Javascript trigger
+ * @param string $source
+ */
+ public function trigger_javascript($url) {
+ // array support
+ if (is_array($url)) {
+ $return = '';
+ foreach ($url as $u) {
+ $return .= $this->trigger_javascript($u);
+ }
+ return $return;
+ }
+
+ if (!stristr($url, 'http://') && !stristr($url, 'https://') && substr($url, 0, 2) != '//') {
+ $url = $this->_ci->config->item('base_url') . $url;
+ }
+
+ return '' . "\n\t";
+ }
+
+ /**
+ * Meta trigger
+ * @param string $name
+ * @param mixed $value
+ * @param enum $type
+ */
+ public function trigger_meta($name, $value, $type = 'meta') {
+ $name = htmlspecialchars(strip_tags($name));
+ $value = htmlspecialchars(strip_tags($value));
+
+ if ($name == 'keywords' and !strpos($value, ',')) {
+ $content = preg_replace('/[\s]+/', ', ', trim($value));
+ }
+
+ switch ($type) {
+ case 'meta' :
+ $content = ' ' . "\n\t";
+ break;
+ case 'link' :
+ $content = ' ' . "\n\t";
+ break;
+ }
+
+ return $content;
+ }
+
+ /**
+ * Title trigger, keeps it clean
+ * @param string $name
+ * @param mixed $value
+ * @param enum $type
+ */
+ public function trigger_title($title) {
+ return htmlspecialchars(strip_tags($title));
+ }
+
+ /**
+ * Title trigger, keeps it clean
+ * @param string $name
+ * @param mixed $value
+ * @param enum $type
+ */
+ public function trigger_description($description) {
+ return htmlspecialchars(strip_tags($description));
+ }
+
+}
+
+class Partial
+{
+ protected $_ci, $_content, $_name, $_cache_ttl = 0, $_cached = false, $_identifier, $_trigger;
+ protected $_args = array();
+
+ /**
+ * Construct with optional parameters
+ * @param array $args
+ */
+ public function __construct($name, $args = array())
+ {
+ $this->_ci = &get_instance();
+ $this->_args = $args;
+ $this->_name = $name;
+ }
+
+ /**
+ * Gives access to codeigniter's functions from this class if needed
+ * This will be handy in extending classes
+ * @param string $index
+ */
+ function __get($name) {
+ return $this->_ci->$name;
+ }
+
+ /**
+ * Alias methods
+ */
+ function __call($name, $args) {
+ switch ($name) {
+ case 'default' :
+ return call_user_func_array(array($this, 'set_default'), $args);
+ break;
+ case 'add' :
+ return call_user_func_array(array($this, 'append'), $args);
+ break;
+ }
+ }
+
+ /**
+ * Returns the content when converted to a string
+ * @return string
+ */
+ public function __toString() {
+ return (string) $this->content();
+ }
+
+ /**
+ * Returns the content
+ * @return string
+ */
+ public function content() {
+ if ($this->_cache_ttl && !$this->_cached) {
+ $this->cache->save($this->cache_id(), $this->_content, $this->_cache_ttl);
+ }
+
+ return $this->_content;
+ }
+
+ /**
+ * Overwrite the content
+ * @param mixed $content
+ * @return Partial
+ */
+ public function set() {
+ if (!$this->_cached) {
+ $this->_content = (string) $this->trigger(func_get_args());
+ }
+
+ return $this;
+ }
+
+ /**
+ * Append something to the content
+ * @param mixed $content
+ * @return Partial
+ */
+ public function append() {
+ if (!$this->_cached) {
+ $this->_content .= (string) $this->trigger(func_get_args());
+ }
+
+ return $this;
+ }
+
+ /**
+ * Prepend something to the content
+ * @param mixed $content
+ * @return Partial
+ */
+ public function prepend() {
+ if (!$this->_cached) {
+ $this->_content = (string) $this->trigger(func_get_args()) . $this->_content;
+ }
+
+ return $this;
+ }
+
+ /**
+ * Set content if partial is empty
+ * @param mixed $default
+ * @return Partial
+ */
+ public function set_default($default) {
+ if (!$this->_cached) {
+ if (!$this->_content) {
+ $this->_content = $default;
+ }
+ }
+
+ return $this;
+ }
+
+ /**
+ * Load a view inside this partial, overwrite if wanted
+ * @param string $view
+ * @param array $data
+ * @param bool $overwrite
+ * @return Partial
+ */
+ public function view($view, $data = array(), $overwrite = false) {
+ if (!$this->_cached) {
+
+ // better object to array
+ if (is_object($data)) {
+ $array = array();
+ foreach ($data as $k => $v) {
+ $array[$k] = $v;
+ }
+ $data = $array;
+ }
+
+ $content = $this->_ci->load->view($view, $data, true);
+
+ if ($overwrite) {
+ $this->set($content);
+ } else {
+ $this->append($content);
+ }
+ }
+ return $this;
+ }
+
+ /**
+ * Parses a view inside this partial, overwrite if wanted
+ * @param string $view
+ * @param array $data
+ * @param bool $overwrite
+ * @return Partial
+ */
+ public function parse($view, $data = array(), $overwrite = false) {
+ if (!$this->_cached) {
+ if (!class_exists('CI_Parser')) {
+ $this->_ci->load->library('parser');
+ }
+
+ // better object to array
+ if (is_object($data)) {
+ $array = array();
+ foreach ($data as $k => $v) {
+ $array[$k] = $v;
+ }
+ $data = $array;
+ }
+
+ $content = $this->_ci->parser->parse($view, $data, true);
+
+ if ($overwrite) {
+ $this->set($content);
+ } else {
+ $this->append($content);
+ }
+ }
+
+ return $this;
+ }
+
+ /**
+ * Loads a widget inside this partial, overwrite if wanted
+ * @param string $name
+ * @param array $data
+ * @param bool $overwrite
+ * @return Partial
+ */
+ public function widget($name, $data = array(), $overwrite = false) {
+ if (!$this->_cached) {
+ $widget = $this->template->widget($name, $data);
+
+ if ($overwrite) {
+ $this->set($widget->content());
+ } else {
+ $this->append($widget->content());
+ }
+ }
+ return $this;
+ }
+
+ /**
+ * Enable cache with TTL, default TTL is 60
+ * @param int $ttl
+ * @param mixed $identifier
+ */
+ public function cache($ttl = 60, $identifier = '') {
+ if (!class_exists('CI_Cache')) {
+ $this->_ci->load->driver('cache', array('adapter' => 'file'));
+ }
+
+ $this->_cache_ttl = $ttl;
+ $this->_identifier = $identifier;
+
+ if ($cached = $this->_ci->cache->get($this->cache_id())) {
+ $this->_cached = true;
+ $this->_content = $cached;
+ }
+ return $this;
+ }
+
+ /**
+ * Used for cache identification
+ * @return string
+ */
+ private function cache_id() {
+ if ($this->_identifier) {
+ return $this->_name . '_' . $this->_identifier . '_' . md5(get_class($this) . implode('', $this->_args));
+ } else {
+ return $this->_name . '_' . md5(get_class($this) . implode('', $this->_args));
+ }
+ }
+
+ /**
+ * Trigger returns the result if a trigger is set
+ * @param array $args
+ * @return string
+ */
+ public function trigger($args) {
+ if (!$this->_trigger) {
+ return implode('', $args);
+ } else {
+ return call_user_func_array($this->_trigger, $args);
+ }
+ }
+
+ /**
+ * Bind a trigger function
+ * Can be used like bind($this, "function") or bind("function")
+ * @param mixed $arg
+ */
+ public function bind() {
+ if ($count = func_num_args()) {
+ if ($count >= 2) {
+ $args = func_get_args();
+ $obj = array_shift($args);
+ $func = array_pop($args);
+
+ foreach ($args as $trigger) {
+ $obj = $obj->$trigger;
+ }
+
+ $this->_trigger = array($obj, $func);
+ } else {
+ $args = func_get_args();
+ $this->_trigger = reset($args);
+ }
+ } else {
+ $this->_trigger = FALSE;
+ }
+ }
+}
+
+/**
+ * The mother of all widgets
+ * it represent a generic HTML element
+ */
+class Widget extends Partial
+{
+ // The name of the array present in the data array given to the view that will render this widget
+ const HTML_ARG_NAME = 'HTML';
+ const HTML_DEFAULT_VALUE = ''; // Default value of the html element
+ const HTML_NAME = 'name'; // HTML name attribute
+ const HTML_ID = 'id'; // HTML id attribute
+
+ const EXTERNAL_BLOCK = 'externalBlock'; //
+ const EXTERNAL_START_BLOCK_HTML_TAG = '
'; //
+ const EXTERNAL_END_BLOCK_HTML_TAG = '
'; //
+
+ /**
+ * It gets also the htmlArgs array as parameter, it will be used to set the HTML properties
+ */
+ public function __construct($name, $args = array(), $htmlArgs = array())
+ {
+ parent::__construct($name, $args);
+
+ // Initialising HTML properties
+ $this->_setHtmlProperties($htmlArgs);
+
+ // Loads helper message to manage returning messages
+ $this->load->helper('message');
+ }
+
+ /**
+ * (non-PHPdoc)
+ * @see Partial::content()
+ */
+ public function content()
+ {
+ if (!$this->_cached)
+ {
+ if (method_exists($this, 'display'))
+ {
+ // capture output
+ ob_start();
+ $this->display($this->_args);
+ $buffer = ob_get_clean();
+
+ // if no content is produced but there was direct ouput we set
+ // that output as content
+ if (!$this->_content && $buffer)
+ {
+ $this->set($buffer);
+ }
+ }
+ }
+
+ return parent::content();
+ }
+
+ /**
+ * Initialising html properties, such as the id and name attributes of the HTML element
+ */
+ private function _setHtmlProperties($htmlArgs)
+ {
+ // If $htmlArgs wasn't already stored in $this->_args
+ if (!isset($this->_args[Widget::HTML_ARG_NAME]))
+ {
+ $this->_args[Widget::HTML_ARG_NAME] = array();
+
+ // Avoids that elements in a HTML page have the same name or id
+ $randomIdentifier = uniqid(rand(0, 1000));
+ $this->_args[Widget::HTML_ARG_NAME][Widget::HTML_ID] = $randomIdentifier;
+ $this->_args[Widget::HTML_ARG_NAME][Widget::HTML_NAME] = $randomIdentifier;
+
+ foreach($htmlArgs as $argName => $argValue)
+ {
+ $this->_args[Widget::HTML_ARG_NAME][$argName] = $argValue;
+ }
+ }
+ }
+
+ /**
+ *
+ */
+ public static function printAttribute($htmlArgs, $attribute, $isValuePresent = true)
+ {
+ if ($attribute != null)
+ {
+ if (isset($htmlArgs[$attribute]))
+ {
+ if ($isValuePresent === true)
+ {
+ $value = $htmlArgs[$attribute];
+
+ if (is_bool($value))
+ {
+ $value = $value ? 'true' : 'false';
+ }
+
+ echo sprintf('%s="%s"', $attribute, $value);
+ }
+ else
+ {
+ echo $attribute;
+ }
+ }
+ }
+ }
+
+ /**
+ *
+ */
+ public static function printStartBlock($htmlArgs)
+ {
+ if (isset($htmlArgs[Widget::EXTERNAL_BLOCK])
+ && $htmlArgs[Widget::EXTERNAL_BLOCK] === true)
+ {
+ echo Widget::EXTERNAL_START_BLOCK_HTML_TAG;
+ }
+ }
+
+ /**
+ *
+ */
+ public static function printEndBlock($htmlArgs)
+ {
+ if (isset($htmlArgs[Widget::EXTERNAL_BLOCK])
+ && $htmlArgs[Widget::EXTERNAL_BLOCK] === true)
+ {
+ echo Widget::EXTERNAL_END_BLOCK_HTML_TAG;
+ }
+ }
+}
+
+/**
+ * It exends the Widget class to represent an HTML dropdown
+ */
+class DropdownWidget 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_ELEMENTS_ARRAY_NAME = 'ELEMENTS_ARRAY';
+ // Name of the property that will be used to store the value attribute of the option tag
+ const ID_FIELD = 'id';
+ // Name of the property that will be used to store the value between the option tags
+ const DESCRIPTION_FIELD = 'description';
+ // 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 SELECTED_ELEMENT = 'selectedElement';
+ //
+ const HTML_DEFAULT_VALUE = 'null';
+
+ const SIZE = 'size'; //
+ const MULTIPLE = 'multiple'; //
+
+ /**
+ *
+ */
+ public function __construct($name, $args = array(), $htmlArgs = array())
+ {
+ parent::__construct($name, $args, $htmlArgs);
+
+ //
+ if (!isset($this->_args[DropdownWidget::SELECTED_ELEMENT]))
+ {
+ $this->_args[DropdownWidget::SELECTED_ELEMENT] = DropdownWidget::HTML_DEFAULT_VALUE;
+ }
+ }
+
+ /**
+ *
+ */
+ public function setMultiple()
+ {
+ $this->_args[Widget::HTML_ARG_NAME][DropdownWidget::MULTIPLE] = DropdownWidget::MULTIPLE;
+ $this->_args[Widget::HTML_ARG_NAME][Widget::HTML_NAME] .= '[]';
+ }
+
+ /**
+ *
+ */
+ public function isMultipleDropdown()
+ {
+ $isMultipleDropdown = false;
+
+ if (isset($this->_args[Widget::HTML_ARG_NAME][DropdownWidget::MULTIPLE])
+ && $this->_args[Widget::HTML_ARG_NAME][DropdownWidget::MULTIPLE] == DropdownWidget::MULTIPLE)
+ {
+ $isMultipleDropdown = true;
+ }
+
+ return $isMultipleDropdown;
+ }
+
+ /**
+ * Add the correct select to the model used to load a list of elemets for this dropdown
+ * @param model $model the model used to load elements
+ * @param string $idName the name of the field that will used to be the value of the option tag
+ * @param string $descriptionName the name of the field that will used to be displayed in the dropdown
+ */
+ protected function addSelectToModel($model, $idName, $descriptionName)
+ {
+ $model->addSelect(
+ sprintf(
+ '%s AS %s, %s AS %s',
+ $idName,
+ DropdownWidget::ID_FIELD,
+ $descriptionName,
+ DropdownWidget::DESCRIPTION_FIELD
+ )
+ );
+ }
+
+ /**
+ * Set the array used to populate the dropdown
+ * @param array $elements list used to populate this dropdown
+ * @param boolean $emptyElement if an empty element must be added at the beginning of the dropdown
+ * @param string $stdDescription description of the empty element
+ * @param string $noDataDescription description if no data are found
+ * @param string $id value of the attribute value of the empty element
+ */
+ protected function setElementsArray(
+ $elements, $emptyElement = false, $stdDescription = '' , $noDataDescription = 'No data found' , $id = DropdownWidget::HTML_DEFAULT_VALUE
+ )
+ {
+ $tmpElements = array();
+
+ if (isError($elements))
+ {
+ if (is_object($elements) && isset($elements->retval))
+ {
+ show_error($elements->retval);
+ }
+ else if (is_string($elements))
+ {
+ show_error($elements);
+ }
+ else
+ {
+ show_error('Generic error occurred');
+ }
+ }
+ else
+ {
+ if ($emptyElement === true && $this->isMultipleDropdown() == false)
+ {
+ $tmpElements = $this->addElementAtBeginning(
+ $elements,
+ $stdDescription,
+ $noDataDescription,
+ $id
+ );
+ }
+ else
+ {
+ $tmpElements = $elements->retval;
+ }
+
+ $this->_args[DropdownWidget::WIDGET_DATA_ELEMENTS_ARRAY_NAME] = $tmpElements;
+ }
+ }
+
+ /**
+ * Adds an element to the beginning of the array
+ */
+ protected function addElementAtBeginning($elements, $stdDescription, $noDataDescription, $id)
+ {
+ $element = new stdClass();
+ $element->{DropdownWidget::ID_FIELD} = $id;
+ $element->{DropdownWidget::DESCRIPTION_FIELD} = $stdDescription;
+
+ if (!hasData($elements))
+ {
+ $element->{DropdownWidget::DESCRIPTION_FIELD} = $noDataDescription;
+ }
+
+ array_unshift($elements->retval, $element);
+
+ return $elements->retval;
+ }
+
+ /**
+ * Loads the dropdown view with all the elements to be displayed
+ */
+ protected function loadDropDownView()
+ {
+ $this->view('widgets/dropdown', $this->_args);
+ }
+}
+
+/**
+ *
+ */
+class DropdownWidgetUDF extends DropdownWidget
+{
+ /**
+ *
+ */
+ public function render($parameters)
+ {
+ $tmpElements = array();
+
+ //
+ foreach($parameters as $parameter)
+ {
+ //
+ 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(
+ success($tmpElements),
+ true,
+ $this->_args[Widget::HTML_ARG_NAME][UDFWidgetTpl::PLACEHOLDER],
+ 'No data found for this UDF'
+ );
+
+ $this->loadDropDownView();
+
+ echo $this->content();
+ }
+}
+
+/**
+ * It exends the Widget class to represent an HTML textarea
+ */
+class TextareaWidget extends Widget
+{
+ const TEXT = 'text'; //
+ const ROWS = 'rows'; //
+ const COLS = 'cols'; //
+
+ /**
+ *
+ */
+ protected function setText($text)
+ {
+ $this->_args[TextareaWidget::TEXT] = $text;
+ }
+
+ /**
+ *
+ */
+ protected function loadTextareaView()
+ {
+ $this->view('widgets/textarea', $this->_args);
+ }
+}
+
+/**
+ *
+ */
+class TextareaWidgetUDF extends TextareaWidget
+{
+ /**
+ *
+ */
+ public function render($parameters)
+ {
+ if ($parameters != null)
+ {
+ $this->setText($parameters);
+ }
+ else
+ {
+ $this->setText('');
+ }
+
+ $this->loadTextareaView();
+
+ echo $this->content();
+ }
+}
+
+/**
+ * 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
+{
+ // Name of the property that will be used to store the value attribute of the option tag
+ const VALUE_FIELD = 'value';
+ // Name of the property that will be used to store the value between the option tags
+ const DESCRIPTION_FIELD = 'description';
+ // Value of value attribute of the checkbox
+ const CHECKBOX_VALUE = 'true';
+
+ /**
+ *
+ */
+ protected function loadCheckboxView()
+ {
+ $this->view('widgets/checkbox', $this->_args);
+ }
+}
+
+/**
+ *
+ */
+class CheckboxWidgetUDF extends CheckboxWidget
+{
+ /**
+ *
+ */
+ public function render()
+ {
+ $this->loadCheckboxView();
+
+ echo $this->content();
+ }
+}
+
+/**
+ * Defined here because these constants can be used
+ * in the views also
+ */
+abstract class UDFWidgetTpl extends Widget
+{
+ const WIDGET_NAME = 'UDFWidget';
+ const SCHEMA_ARG_NAME = 'schema';
+ const TABLE_ARG_NAME = 'table';
+ const FIELD_ARG_NAME = 'field';
+ const UDFS_ARG_NAME = 'udfs';
+
+ // HTML components
+ const TITLE = 'description';
+ const LABEL = 'title';
+ const PLACEHOLDER = 'placeholder';
+ const DEFAULT_VALUE = 'defaultValue';
+
+ // Validation attributes
+ const REGEX = 'regex';
+ const REQUIRED = 'required';
+ const MAX_VALUE = 'max-value';
+ const MIN_VALUE = 'min-value';
+ const MAX_LENGTH = 'max-length';
+ const MIN_LENGTH = 'min-length';
}
\ No newline at end of file
diff --git a/application/models/system/UDF_model.php b/application/models/system/UDF_model.php
new file mode 100644
index 000000000..b1a673c25
--- /dev/null
+++ b/application/models/system/UDF_model.php
@@ -0,0 +1,197 @@
+dbTable = 'system.tbl_udf';
+ $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');
+ }
+ }
+
+ /**
+ *
+ */
+ public function saveUDFs($udfs)
+ {
+ $result = error('No way man!');
+ $resultPerson = success('person');
+ $resultPrestudent = success('prestudent');
+
+ $person_id = $udfs['person_id'];
+ unset($udfs['person_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->_fillMissingChkboxUDF($udfs, $jsons);
+ $udfs = $this->_fillMissingDropdownUDF($udfs, $jsons);
+ $udfs = $this->_fillMissingTextUDF($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->_fillMissingChkboxUDF($udfs, $jsons);
+ $udfs = $this->_fillMissingDropdownUDF($udfs, $jsons);
+ $udfs = $this->_fillMissingTextUDF($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->{DB_Model::UDF_TYPE_NAME} == DB_Model::UDF_CHKBOX_TYPE)
+ {
+ if (!isset($_fillMissingChkboxUDF[$udfDescription->{DB_Model::UDF_ATTRIBUTE_NAME}]))
+ {
+ $_fillMissingChkboxUDF[$udfDescription->{DB_Model::UDF_ATTRIBUTE_NAME}] = false;
+ }
+ else
+ {
+ if ($_fillMissingChkboxUDF[$udfDescription->{DB_Model::UDF_ATTRIBUTE_NAME}] == DB_Model::STRING_FALSE)
+ {
+ $_fillMissingChkboxUDF[$udfDescription->{DB_Model::UDF_ATTRIBUTE_NAME}] = false;
+ }
+ else if ($_fillMissingChkboxUDF[$udfDescription->{DB_Model::UDF_ATTRIBUTE_NAME}] == DB_Model::STRING_TRUE)
+ {
+ $_fillMissingChkboxUDF[$udfDescription->{DB_Model::UDF_ATTRIBUTE_NAME}] = true;
+ }
+ }
+ }
+ }
+
+ return $_fillMissingChkboxUDF;
+ }
+
+ /**
+ *
+ */
+ private function _fillMissingDropdownUDF($udfs, $jsons)
+ {
+ $_fillMissingDropdownUDF = $udfs;
+
+ foreach($jsons as $udfDescription)
+ {
+ if ($udfDescription->{DB_Model::UDF_TYPE_NAME} == DB_Model::UDF_DROPDOWN_TYPE
+ || $udfDescription->{DB_Model::UDF_TYPE_NAME} == DB_Model::UDF_MULTIPLEDROPDOWN_TYPE)
+ {
+ if (!isset($_fillMissingDropdownUDF[$udfDescription->{DB_Model::UDF_ATTRIBUTE_NAME}]))
+ {
+ $_fillMissingDropdownUDF[$udfDescription->{DB_Model::UDF_ATTRIBUTE_NAME}] = null;
+ }
+ else if($_fillMissingDropdownUDF[$udfDescription->{DB_Model::UDF_ATTRIBUTE_NAME}] == DB_Model::STRING_NULL)
+ {
+ $_fillMissingDropdownUDF[$udfDescription->{DB_Model::UDF_ATTRIBUTE_NAME}] = null;
+ }
+ }
+ }
+
+ return $_fillMissingDropdownUDF;
+ }
+
+ /**
+ *
+ */
+ private function _fillMissingTextUDF($udfs, $jsons)
+ {
+ $_fillMissingTextUDF = $udfs;
+
+ foreach($jsons as $udfDescription)
+ {
+ if ($udfDescription->{DB_Model::UDF_TYPE_NAME} == 'textarea'
+ || $udfDescription->{DB_Model::UDF_TYPE_NAME} == 'textfield')
+ {
+ if (!isset($_fillMissingTextUDF[$udfDescription->{DB_Model::UDF_ATTRIBUTE_NAME}]))
+ {
+ $_fillMissingTextUDF[$udfDescription->{DB_Model::UDF_ATTRIBUTE_NAME}] = null;
+ }
+ else if(trim($_fillMissingTextUDF[$udfDescription->{DB_Model::UDF_ATTRIBUTE_NAME}]) == '')
+ {
+ $_fillMissingTextUDF[$udfDescription->{DB_Model::UDF_ATTRIBUTE_NAME}] = null;
+ }
+ }
+ }
+
+ return $_fillMissingTextUDF;
+ }
+}
\ No newline at end of file
diff --git a/application/views/system/udf.php b/application/views/system/udf.php
new file mode 100644
index 000000000..5fd1bd6d9
--- /dev/null
+++ b/application/views/system/udf.php
@@ -0,0 +1,145 @@
+load->view("templates/header", array("title" => "UDF", "widgetsCSS" => true)); ?>
+
+
+
+
+
+ Saved!
+
+
+
+
+
+ Error while saving!
+
+
+
+retval;
+ foreach ($errors as $error)
+ {
+ foreach ($error as $fieldError)
+ {
+ echo $fieldError->msg . ' -> ' . $fieldError->retval . ' ';
+ }
+ }
+?>
+
+
+
+
+
+
+
+
+
+
+load->view("templates/footer"); ?>
\ No newline at end of file
diff --git a/application/views/templates/header.php b/application/views/templates/header.php
index b5bdda896..a1f042b7b 100644
--- a/application/views/templates/header.php
+++ b/application/views/templates/header.php
@@ -15,6 +15,7 @@ isset($title) ? $title = 'VileSci - '.$title : $title = 'VileSci';
!isset($jsoneditor) ? $jsoneditor = false : $jsoneditor = $jsoneditor;
!isset($jsonforms) ? $jsonforms = false : $jsonforms = $jsonforms;
!isset($textile) ? $textile = false : $textile = $textile;
+!isset($widgetsCSS) ? $widgetsCSS = false : $widgetsCSS = $widgetsCSS;
!isset($datepicker) ? $datepicker = false : $datepicker = $datepicker;
if ($tablesort || $jquery_checkboxes || $jquery_custom)
@@ -102,4 +103,7 @@ if($jquery && $jqueryComposer)
+
+
+
\ No newline at end of file
diff --git a/application/views/widgets/checkbox.php b/application/views/widgets/checkbox.php
new file mode 100644
index 000000000..3ce46d4b5
--- /dev/null
+++ b/application/views/widgets/checkbox.php
@@ -0,0 +1,39 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ value=""
+ >
+
+
+
+
+
\ No newline at end of file
diff --git a/application/views/widgets/dropdown.php b/application/views/widgets/dropdown.php
index d511ece11..0189f1b86 100644
--- a/application/views/widgets/dropdown.php
+++ b/application/views/widgets/dropdown.php
@@ -1,14 +1,71 @@
-
-
- {DropdownWidget::ID_FIELD} == ${DropdownWidget::SELECTED_ELEMENT})
- {
- $selected = 'selected';
- }
- ?>
- >
- {DropdownWidget::DESCRIPTION_FIELD}; ?>
-
-
-
\ No newline at end of file
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ >
+ {DropdownWidget::ID_FIELD} == $selectedElement)
+ {
+ $selected = 'selected';
+ }
+ }
+ }
+ else
+ {
+ if ($element->{DropdownWidget::ID_FIELD} == $selectedElements)
+ {
+ $selected = 'selected';
+ }
+ }
+ ?>
+ >
+ {DropdownWidget::DESCRIPTION_FIELD}; ?>
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/application/views/widgets/textarea.php b/application/views/widgets/textarea.php
new file mode 100644
index 000000000..114cd6ecc
--- /dev/null
+++ b/application/views/widgets/textarea.php
@@ -0,0 +1,32 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/application/views/widgets/textfield.php b/application/views/widgets/textfield.php
new file mode 100644
index 000000000..5bf1ec245
--- /dev/null
+++ b/application/views/widgets/textfield.php
@@ -0,0 +1,33 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ value=""
+ >
+
+
+
+
+
\ No newline at end of file
diff --git a/application/widgets/Studiengang_widget.php b/application/widgets/Studiengang_widget.php
index e87fa9cd1..a09c865f5 100644
--- a/application/widgets/Studiengang_widget.php
+++ b/application/widgets/Studiengang_widget.php
@@ -17,6 +17,6 @@ class Studiengang_widget extends DropdownWidget
'No studiengaenge found'
);
- $this->loadDropDownView($widgetData);
+ $this->loadDropDownView();
}
}
\ No newline at end of file
diff --git a/application/widgets/UDFWidget.php b/application/widgets/UDFWidget.php
new file mode 100644
index 000000000..4f847c023
--- /dev/null
+++ b/application/widgets/UDFWidget.php
@@ -0,0 +1,422 @@
+_loadUDF($schema, $table);
+ if (hasData($udfResults))
+ {
+ $udf = $udfResults->retval[0];
+ if (isset($udf->jsons))
+ {
+ $jsonSchemas = json_decode($udf->jsons);
+ if (is_object($jsonSchemas) || is_array($jsonSchemas))
+ {
+ //
+ if (is_object($jsonSchemas))
+ {
+ $jsonSchemasArray = array($jsonSchemas);
+ }
+ else
+ {
+ $jsonSchemasArray = $jsonSchemas;
+ }
+
+ $found = false; //
+
+ $this->_sortJsonSchemas($jsonSchemasArray); //
+
+ //
+ foreach($jsonSchemasArray as $jsonSchema)
+ {
+ //
+ if (!isset($jsonSchema->{UDFWidget::TYPE}))
+ {
+ show_error(sprintf('%s.%s: Attribute "type" not present in the json schema', $schema, $table));
+ break;
+ }
+ if (!isset($jsonSchema->{UDFWidget::NAME}))
+ {
+ show_error(sprintf('%s.%s: Attribute "name" not present in the json schema', $schema, $table));
+ break;
+ }
+
+ //
+ if ((isset($field) && $field == $jsonSchema->{UDFWidget::NAME}) || !isset($field))
+ {
+ $this->_setAttributesWithPhrases($jsonSchema);
+
+ $this->_setValidationAttributes($jsonSchema);
+
+ $this->_setNameAndId($jsonSchema);
+
+ $this->_render($jsonSchema);
+
+ //
+ if (isset($field) && $field == $jsonSchema->{UDFWidget::NAME})
+ {
+ $found = true;
+ break;
+ }
+ }
+ }
+
+ //
+ if (isset($field) && !$found)
+ {
+ show_error(sprintf('%s.%s: No schema present for field: %s', $schema, $table, $field));
+ }
+ }
+ else
+ {
+ show_error(sprintf('%s.%s: Not a valid json schema', $schema, $table));
+ }
+ }
+ else
+ {
+ show_error(sprintf('%s.%s: Does not contain "jsons" field', $schema, $table));
+ }
+ }
+ }
+
+ /**
+ *
+ */
+ private function _setNameAndId($jsonSchema)
+ {
+ $this->_args[Widget::HTML_ARG_NAME][Widget::HTML_ID] = $jsonSchema->{UDFWidget::NAME};
+ $this->_args[Widget::HTML_ARG_NAME][Widget::HTML_NAME] = $jsonSchema->{UDFWidget::NAME};
+ }
+
+ /**
+ *
+ */
+ private function _sortJsonSchemas(&$jsonSchemasArray)
+ {
+ //
+ usort($jsonSchemasArray, function ($a, $b) {
+ //
+ if (!isset($a->sort))
+ {
+ $a->sort = 9999;
+ }
+ if (!isset($b->sort))
+ {
+ $b->sort = 9999;
+ }
+
+ if ($a->sort == $b->sort)
+ {
+ return 0;
+ }
+
+ return ($a->sort < $b->sort) ? -1 : 1;
+ });
+ }
+
+ /**
+ *
+ */
+ private function _loadUDF($schema, $table)
+ {
+ // Loads UDF model
+ $this->_ci->load->model('system/UDF_model', 'UDFModel');
+
+ $udfResults = $this->_ci->UDFModel->loadWhere(
+ array(
+ 'schema' => $schema,
+ 'table' => $table
+ )
+ );
+
+ if (isError($udfResults))
+ {
+ if (is_object($udfResults) && isset($udfResults->retval))
+ {
+ show_error($udfResults->retval);
+ }
+ else if (is_string($udfResults))
+ {
+ show_error($udfResults);
+ }
+ else
+ {
+ show_error('UDFWidget: generic error occurred');
+ }
+ }
+ else if (!hasData($udfResults))
+ {
+ show_error(sprintf('%s.%s does not contain UDF', $schema, $table));
+ }
+
+ return $udfResults;
+ }
+
+ /**
+ *
+ */
+ private function _render($jsonSchema)
+ {
+ // Type
+ if ($jsonSchema->{UDFWidget::TYPE} == 'checkbox')
+ {
+ $this->_renderCheckbox($jsonSchema);
+ }
+ else if ($jsonSchema->{UDFWidget::TYPE} == 'textfield')
+ {
+ $this->_renderTextfield($jsonSchema);
+ }
+ else if ($jsonSchema->{UDFWidget::TYPE} == 'textarea')
+ {
+ $this->_renderTextarea($jsonSchema);
+ }
+ else if ($jsonSchema->{UDFWidget::TYPE} == 'date')
+ {
+
+ }
+ else if ($jsonSchema->{UDFWidget::TYPE} == 'dropdown')
+ {
+ $this->_renderDropdown($jsonSchema);
+ }
+ else if ($jsonSchema->{UDFWidget::TYPE} == 'multipledropdown')
+ {
+ $this->_renderDropdown($jsonSchema, true);
+ }
+ }
+
+ /**
+ *
+ */
+ private function _renderDropdown($jsonSchema, $multiple = false)
+ {
+ if (isset($this->_args[UDFWidgetTpl::UDFS_ARG_NAME])
+ && isset($this->_args[UDFWidgetTpl::UDFS_ARG_NAME][$jsonSchema->{UDFWidget::NAME}]))
+ {
+ $this->_args[DropdownWidget::SELECTED_ELEMENT] = $this->_args[UDFWidgetTpl::UDFS_ARG_NAME][$jsonSchema->{UDFWidget::NAME}];
+ }
+ else
+ {
+ $this->_args[DropdownWidget::SELECTED_ELEMENT] = null;
+ }
+
+ $dropdownWidgetUDF = new DropdownWidgetUDF($this->_name, $this->_args);
+ $parameters = array();
+
+ //
+ if (isset($jsonSchema->{UDFWidget::LIST_VALUES}->enum))
+ {
+ $parameters = $jsonSchema->{UDFWidget::LIST_VALUES}->enum;
+ }
+ //
+ else if (isset($jsonSchema->{UDFWidget::LIST_VALUES}->sql))
+ {
+ $queryResult = $this->UDFModel->execQuery($jsonSchema->{UDFWidget::LIST_VALUES}->sql);
+ if (hasData($queryResult))
+ {
+ $parameters = $queryResult->retval;
+ }
+ }
+
+ if ($multiple)
+ {
+ $dropdownWidgetUDF->setMultiple();
+ }
+
+ $dropdownWidgetUDF->render($parameters);
+ }
+
+ /**
+ *
+ */
+ private function _renderTextarea($jsonSchema)
+ {
+ $textareaUDF = new TextareaWidgetUDF($this->_name, $this->_args);
+ $text = null;
+
+ if (isset($this->_args[UDFWidgetTpl::UDFS_ARG_NAME])
+ && isset($this->_args[UDFWidgetTpl::UDFS_ARG_NAME][$jsonSchema->{UDFWidget::NAME}]))
+ {
+ $text = $this->_args[UDFWidgetTpl::UDFS_ARG_NAME][$jsonSchema->{UDFWidget::NAME}];
+ }
+
+ $textareaUDF->render($text);
+ }
+
+ /**
+ *
+ */
+ private function _renderTextfield($jsonSchema)
+ {
+ $textareaUDF = new TextfieldWidgetUDF($this->_name, $this->_args);
+ $text = null;
+
+ if (isset($this->_args[UDFWidgetTpl::UDFS_ARG_NAME])
+ && isset($this->_args[UDFWidgetTpl::UDFS_ARG_NAME][$jsonSchema->{UDFWidget::NAME}]))
+ {
+ $text = $this->_args[UDFWidgetTpl::UDFS_ARG_NAME][$jsonSchema->{UDFWidget::NAME}];
+ }
+
+ $textareaUDF->render($text);
+ }
+
+ /**
+ *
+ */
+ private function _renderCheckbox($jsonSchema)
+ {
+ if (isset($this->_args[UDFWidgetTpl::UDFS_ARG_NAME])
+ && isset($this->_args[UDFWidgetTpl::UDFS_ARG_NAME][$jsonSchema->{UDFWidget::NAME}]))
+ {
+ $this->_args[CheckboxWidget::VALUE_FIELD] = $this->_args[UDFWidgetTpl::UDFS_ARG_NAME][$jsonSchema->{UDFWidget::NAME}];
+ }
+ else
+ {
+ $this->_args[CheckboxWidget::VALUE_FIELD] = Widget::HTML_DEFAULT_VALUE;
+ }
+
+ $checkboxWidgetUDF = new CheckboxWidgetUDF($this->_name, $this->_args);
+
+ $checkboxWidgetUDF->render();
+ }
+
+ /**
+ *
+ */
+ private function _setAttributesWithPhrases($jsonSchema)
+ {
+ // Description, title and placeholder
+ if (isset($jsonSchema->{UDFWidgetTpl::LABEL})
+ || isset($jsonSchema->{UDFWidgetTpl::TITLE})
+ || isset($jsonSchema->{UDFWidgetTpl::PLACEHOLDER}))
+ {
+ //
+ $this->_ci->load->library('PhrasesLib');
+
+ //
+ if (isset($jsonSchema->{UDFWidgetTpl::LABEL}))
+ {
+ $tmpResult = $this->_ci->phraseslib->getPhrases(
+ UDFWidget::PHRASES_APP_NAME,
+ DEFAULT_LEHREINHEIT_SPRACHE,
+ $jsonSchema->{UDFWidgetTpl::LABEL},
+ null,
+ null,
+ 'no'
+ );
+ if (hasData($tmpResult))
+ {
+ $this->_args[Widget::HTML_ARG_NAME][UDFWidgetTpl::LABEL] = $tmpResult->retval[0]->text;
+ }
+ else
+ {
+ $this->_args[Widget::HTML_ARG_NAME][UDFWidgetTpl::LABEL] = null;
+ }
+ }
+
+ //
+ if (isset($jsonSchema->{UDFWidgetTpl::TITLE}))
+ {
+ $tmpResult = $this->_ci->phraseslib->getPhrases(
+ UDFWidget::PHRASES_APP_NAME,
+ DEFAULT_LEHREINHEIT_SPRACHE,
+ $jsonSchema->{UDFWidgetTpl::TITLE},
+ null,
+ null,
+ 'no'
+ );
+ if (hasData($tmpResult))
+ {
+ $this->_args[Widget::HTML_ARG_NAME][UDFWidgetTpl::TITLE] = $tmpResult->retval[0]->text;
+ }
+ else
+ {
+ $this->_args[Widget::HTML_ARG_NAME][UDFWidgetTpl::TITLE] = null;
+ }
+ }
+
+ //
+ if (isset($jsonSchema->{UDFWidgetTpl::PLACEHOLDER}))
+ {
+ $tmpResult = $this->_ci->phraseslib->getPhrases(
+ UDFWidget::PHRASES_APP_NAME,
+ DEFAULT_LEHREINHEIT_SPRACHE,
+ $jsonSchema->{UDFWidgetTpl::PLACEHOLDER},
+ null,
+ null,
+ 'no'
+ );
+ if (hasData($tmpResult))
+ {
+ $this->_args[Widget::HTML_ARG_NAME][UDFWidgetTpl::PLACEHOLDER] = $tmpResult->retval[0]->text;
+ }
+ else
+ {
+ $this->_args[Widget::HTML_ARG_NAME][UDFWidgetTpl::PLACEHOLDER] = null;
+ }
+ }
+ }
+ }
+
+ /**
+ *
+ */
+ private function _setValidationAttributes($jsonSchema)
+ {
+ // Validation
+ $this->_args[Widget::HTML_ARG_NAME][UDFWidget::REQUIRED] = null;
+ $this->_args[Widget::HTML_ARG_NAME][UDFWidgetTpl::REGEX] = null;
+ $this->_args[Widget::HTML_ARG_NAME][UDFWidgetTpl::MAX_VALUE] = null;
+ $this->_args[Widget::HTML_ARG_NAME][UDFWidgetTpl::MIN_VALUE] = null;
+
+ if (isset($jsonSchema->validation))
+ {
+ if (isset($jsonSchema->{UDFWidget::VALIDATION}->{UDFWidgetTpl::REGEX})
+ && is_array($jsonSchema->{UDFWidget::VALIDATION}->{UDFWidgetTpl::REGEX}))
+ {
+ foreach($jsonSchema->{UDFWidget::VALIDATION}->{UDFWidgetTpl::REGEX} as $regex)
+ {
+ if ($regex->language === UDFWidget::REGEX_LANGUAGE)
+ {
+ $this->_args[Widget::HTML_ARG_NAME][UDFWidgetTpl::REGEX] = $regex->expression;
+ }
+ }
+ }
+
+ if (isset($jsonSchema->{UDFWidget::VALIDATION}->{UDFWidgetTpl::REQUIRED}))
+ {
+ $this->_args[Widget::HTML_ARG_NAME][UDFWidget::REQUIRED] = $jsonSchema->{UDFWidget::VALIDATION}->{UDFWidgetTpl::REQUIRED};
+ }
+
+ if (isset($jsonSchema->{UDFWidget::VALIDATION}->{UDFWidgetTpl::MAX_VALUE}))
+ {
+ $this->_args[Widget::HTML_ARG_NAME][UDFWidgetTpl::MAX_VALUE] = $jsonSchema->{UDFWidget::VALIDATION}->{UDFWidgetTpl::MAX_VALUE};
+ }
+
+ if (isset($jsonSchema->{UDFWidget::VALIDATION}->{UDFWidgetTpl::MIN_VALUE}))
+ {
+ $this->_args[Widget::HTML_ARG_NAME][UDFWidgetTpl::MIN_VALUE] = $jsonSchema->{UDFWidget::VALIDATION}->{UDFWidgetTpl::MIN_VALUE};
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/config/global.config-default.inc.php b/config/global.config-default.inc.php
index 8c01b235b..7a12cc589 100644
--- a/config/global.config-default.inc.php
+++ b/config/global.config-default.inc.php
@@ -100,6 +100,9 @@ define('FAS_REIHUNGSTEST_PUNKTE', false);
// Legt fest ob Messages im FAS angezeigt werden true|false
define('FAS_MESSAGES',false);
+// Enable (true) or disable (false) the UDF tab
+define('FAS_UDF', true);
+
// Legt fest ob Aufnahmegruppen bei Reihungstests verwaltet werden true|false
define('FAS_REIHUNGSTEST_AUFNAHMEGRUPPEN',false);
diff --git a/content/mitarbeiter/mitarbeiteroverlay.js.php b/content/mitarbeiter/mitarbeiteroverlay.js.php
index 15a333dfd..ca5e07508 100644
--- a/content/mitarbeiter/mitarbeiteroverlay.js.php
+++ b/content/mitarbeiter/mitarbeiteroverlay.js.php
@@ -623,6 +623,12 @@ function MitarbeiterAuswahl()
// ***** Termine *****
document.getElementById('mitarbeiter-termine').setAttribute('src','termine.xul.php?mitarbeiter_uid='+uid);
}
+
+ // ***** UDF *****
+ if (document.getElementById('mitarbeiter-tabs').selectedItem == document.getElementById('mitarbeiter-tab-udf'))
+ {
+ document.getElementById('mitarbeiter-udf').setAttribute('src', 'udf.xul.php?person_id='+person_id);
+ }
// **** VERWENDUNG ****
verwendungtree = document.getElementById('mitarbeiter-tree-verwendung');
@@ -1972,3 +1978,23 @@ function MitarbeiterTermineIFrameLoad()
document.getElementById('mitarbeiter-termine').setAttribute('src',url);
}
}
+
+// ****
+// * Load UDF IFrame
+// ****
+function MitarbeiterUDFIFrameLoad()
+{
+ var tree = document.getElementById('mitarbeiter-tree');
+
+ if (tree.currentIndex == -1) return;
+
+ try
+ {
+ //Ausgewaehlte person_id holen
+ var person_id = getTreeCellText(tree, 'mitarbeiter-treecol-person_id', tree.currentIndex);
+
+ url = 'udf.xul.php?person_id='+person_id;
+ document.getElementById('mitarbeiter-udf').setAttribute('src', url);
+ }
+ catch(e) {}
+}
\ No newline at end of file
diff --git a/content/mitarbeiter/mitarbeiteroverlay.xul.php b/content/mitarbeiter/mitarbeiteroverlay.xul.php
index ee1c70c7a..2104471fe 100644
--- a/content/mitarbeiter/mitarbeiteroverlay.xul.php
+++ b/content/mitarbeiter/mitarbeiteroverlay.xul.php
@@ -262,6 +262,10 @@ echo '
+ ';
+ ?>
@@ -279,6 +283,10 @@ echo '
+ ';
+ ?>
diff --git a/content/statistik/mitarbeiterexport.xls.php b/content/statistik/mitarbeiterexport.xls.php
index 31463b29c..3c943cde8 100644
--- a/content/statistik/mitarbeiterexport.xls.php
+++ b/content/statistik/mitarbeiterexport.xls.php
@@ -30,6 +30,7 @@ require_once('../../include/person.class.php');
require_once('../../include/benutzer.class.php');
require_once('../../include/mitarbeiter.class.php');
require_once('../../include/Excel/excel.php');
+require_once('../../include/udf.class.php');
$db = new basis_db();
$user = get_uid();
@@ -43,7 +44,7 @@ else
$fix=null;
if (isset($_GET['stgl']))
- $stgl = ($_GET['stgl']=='true'?true:false);
+ $stgl = ($_GET['stgl'] == 'true' ? true : false);
else
$stgl=null;
@@ -72,20 +73,21 @@ if (isset($_GET['zustelladresse']))
else
$zustelladresse = null;
-//die Spalten die Exportiert werden sollen, werden per GET uebergeben
-//spalte1=nachname, spalte2=vorname, spalte3=gebdatum, ...
-$anzSpalten=0;
-$varname='spalte'.(string)$anzSpalten;
+// Die Spalten die Exportiert werden sollen, werden per GET uebergeben
+// spalte1=nachname, spalte2=vorname, spalte3=gebdatum, ...
+$anzSpalten = 0;
+$varname = 'spalte'.(string)$anzSpalten;
while (isset($_GET[$varname]))
{
- $spalte[$anzSpalten]=$_GET[$varname];
+ $spalte[$anzSpalten] = $_GET[$varname];
$anzSpalten++;
- $varname='spalte'.(string)$anzSpalten;
+ $varname = 'spalte'.(string)$anzSpalten;
}
-$zustelladresse=true;
+
+$zustelladresse = true;
// Mitarbeiter holen
-$mitarbeiterDAO=new mitarbeiter();
+$mitarbeiterDAO = new mitarbeiter();
$mitarbeiterDAO->getPersonal($fix, $stgl, $fbl, $aktiv, $karenziert, $ausgeschieden, $semester_aktuell);
//Sortieren der Eintraege nach Nachname, Vorname
@@ -96,105 +98,169 @@ $nachname=array();
$umlaute = array('ö','Ö','ü','Ü','ä','Ä');
$umlauterep = array('o','O','u','U','a','A');
-foreach ($mitarbeiterDAO->result as $key=>$foo)
+foreach ($mitarbeiterDAO->result as $key => $foo)
{
$vorname[$key]=str_replace($umlaute, $umlauterep, $foo->vorname);
$nachname[$key]=str_replace($umlaute, $umlauterep, $foo->nachname);
}
+
array_multisort($nachname, SORT_ASC, $vorname, SORT_ASC, $mitarbeiterDAO->result);
- // Creating a workbook
- $workbook = new Spreadsheet_Excel_Writer();
- $workbook->setVersion(8);
- // sending HTTP headers
- $workbook->send("Mitarbeiter". "_" . date("d_m_Y") . ".xls");
+// Creating a workbook
+$workbook = new Spreadsheet_Excel_Writer();
+$workbook->setVersion(8);
+// sending HTTP headers
+$workbook->send("Mitarbeiter". "_" . date("d_m_Y") . ".xls");
- // Creating a worksheet
- $worksheet =& $workbook->addWorksheet("Mitarbeiter");
- $worksheet->setInputEncoding('utf-8');
+// Creating a worksheet
+$worksheet =& $workbook->addWorksheet("Mitarbeiter");
+$worksheet->setInputEncoding('utf-8');
- $format_bold =& $workbook->addFormat();
- $format_bold->setBold();
+$format_bold =& $workbook->addFormat();
+$format_bold->setBold();
- $format_title =& $workbook->addFormat();
- $format_title->setBold();
- // let's merge
- $format_title->setAlign('merge');
+$format_title =& $workbook->addFormat();
+$format_title->setBold();
+// let's merge
+$format_title->setAlign('merge');
- //Zeilenueberschriften ausgeben
- for ($i=0;$i<$anzSpalten;$i++)
- $worksheet->write(0,$i,mb_strtoupper(str_replace('_bezeichnung','',$spalte[$i])), $format_bold);
- $worksheet->write(0,$i,"STRASSE", $format_bold);
- $worksheet->write(0,$i+1,"PLZ", $format_bold);
- $worksheet->write(0,$i+2,"ORT", $format_bold);
- $worksheet->write(0,$i+3,"FIRMENNAME", $format_bold);
+$zeile = 0;
- //Maximale Spaltenbreite ermitteln damit sie am Schluss gesetzt werden kann
- $j=1;
- $maxlength = array();
- for ($i=0;$i<$anzSpalten;$i++)
- $maxlength[$i]=mb_strlen(str_replace('_bezeichnung','',$spalte[$i]));
- $maxlength[$i]=mb_strlen('STRASSE');
- $maxlength[$i+1]=mb_strlen('PLZ');
- $maxlength[$i+2]=mb_strlen('ORT');
- $maxlength[$i+3]=mb_strlen('FIRMENNAME');
+// Zeilenueberschriften ausgeben
+$col = 0;
+for ($col = 0; $col < $anzSpalten; $col++)
+{
+ $worksheet->write($zeile, $col, mb_strtoupper(str_replace('_bezeichnung', '', $spalte[$col])), $format_bold);
+}
- //Zeilen (Mitarbeiter) ausgeben
- foreach ($mitarbeiterDAO->result as $mitarbeiter)
+$worksheet->write($zeile, $col, "STRASSE", $format_bold);
+$worksheet->write($zeile, ++$col, "PLZ", $format_bold);
+$worksheet->write($zeile, ++$col, "ORT", $format_bold);
+$worksheet->write($zeile, ++$col, "FIRMENNAME", $format_bold);
+
+// Maximale Spaltenbreite ermitteln damit sie am Schluss gesetzt werden kann
+$maxlength = array();
+for ($col = 0; $col < $anzSpalten; $col++)
+{
+ $maxlength[$col] = mb_strlen(str_replace('_bezeichnung','',$spalte[$col]));
+}
+
+$maxlength[$col] = mb_strlen('STRASSE');
+$maxlength[++$col] = mb_strlen('PLZ');
+$maxlength[++$col] = mb_strlen('ORT');
+$maxlength[++$col] = mb_strlen('FIRMENNAME');
+
+// UDF titles
+$udf = new UDF();
+$udfTitlesPerson = $udf->getTitlesPerson();
+
+foreach($udfTitlesPerson as $udfTitle)
+{
+ $worksheet->write($zeile, ++$col, $udfTitle['description'], $format_bold);
+ $maxlength[$col] = mb_strlen($udfTitle['description']);
+}
+
+$zeile++;
+
+// Zeilen (Mitarbeiter) ausgeben
+foreach ($mitarbeiterDAO->result as $mitarbeiter)
+{
+ //Spalten ausgeben
+ for ($col = 0; $col < $anzSpalten; $col++)
{
- //Spalten ausgeben
- for ($i=0;$i<$anzSpalten;$i++)
- {
- if(is_bool($mitarbeiter->{$spalte[$i]}))
- $mitarbeiter->{$spalte[$i]} = ($mitarbeiter->{$spalte[$i]}?'Ja':'Nein');
+ if (is_bool($mitarbeiter->{$spalte[$col]}))
+ $mitarbeiter->{$spalte[$col]} = ($mitarbeiter->{$spalte[$col]} ? 'Ja' : 'Nein');
- if(mb_strlen($mitarbeiter->{$spalte[$i]})>$maxlength[$i])
- $maxlength[$i] = mb_strlen($mitarbeiter->{$spalte[$i]});
- $worksheet->write($j,$i, $mitarbeiter->{$spalte[$i]});
- }
+ if (mb_strlen($mitarbeiter->{$spalte[$col]}) > $maxlength[$col])
+ $maxlength[$col] = mb_strlen($mitarbeiter->{$spalte[$col]});
+ $worksheet->write($zeile, $col, $mitarbeiter->{$spalte[$col]});
+ }
- //Zustelladresse aus der Datenbank holen und dazuhaengen
- $qry = "SELECT * FROM public.tbl_adresse WHERE person_id='$mitarbeiter->person_id' AND zustelladresse=true LIMIT 1";
- if($result = $db->db_query($qry))
+ //Zustelladresse aus der Datenbank holen und dazuhaengen
+ $qry = "SELECT * FROM public.tbl_adresse WHERE person_id = '$mitarbeiter->person_id' AND zustelladresse = true LIMIT 1";
+ if ($result = $db->db_query($qry))
+ {
+ if ($row = $db->db_fetch_object($result))
{
- if($row = $db->db_fetch_object($result))
+ if (mb_strlen($row->strasse) > $maxlength[$col])
+ $maxlength[$col] = mb_strlen($row->strasse);
+ $worksheet->write($zeile, $col, $row->strasse);
+ $col++;
+ if (mb_strlen($row->plz) > $maxlength[$col])
+ $maxlength[$col] = mb_strlen($row->plz);
+ $worksheet->write($zeile, $col, $row->plz);
+ $col++;
+ if (mb_strlen($row->ort) > $maxlength[$col])
+ $maxlength[$col] = mb_strlen($row->ort);
+ $worksheet->write($zeile, $col, $row->ort);
+
+ $col++;
+ if ($row->firma_id != '')
{
- if(mb_strlen($row->strasse)>$maxlength[$i])
- $maxlength[$i]=mb_strlen($row->strasse);
- $worksheet->write($j,$i, $row->strasse);
- if(mb_strlen($row->plz)>$maxlength[$i+1])
- $maxlength[$i+1]=mb_strlen($row->plz);
- $worksheet->write($j,$i+1, $row->plz);
- if(mb_strlen($row->ort)>$maxlength[$i+2])
- $maxlength[$i+2]=mb_strlen($row->ort);
- $worksheet->write($j,$i+2, $row->ort);
-
- if($row->firma_id!='')
+ $qry = "SELECT * FROM public.tbl_firma WHERE firma_id = '$row->firma_id'";
+ if ($result = $db->db_query($qry))
{
- $qry = "SELECT * FROM public.tbl_firma WHERE firma_id='$row->firma_id'";
- if($result = $db->db_query($qry))
+ if ($row = $db->db_fetch_object($result))
{
- if($row = $db->db_fetch_object($result))
- {
- if(mb_strlen($row->name)>$maxlength[$i+3])
- $maxlength[$i+3]=mb_strlen($row->name);
- $worksheet->write($j,$i+3, $row->name);
- }
+ if (mb_strlen($row->name) > $maxlength[$col])
+ $maxlength[$col] = mb_strlen($row->name);
+ $worksheet->write($zeile, $col, $row->name);
}
}
}
}
-
- $j++;
+ }
+
+ $col++;
+
+ // UDF
+ if (isset($mitarbeiter->p_udf_values))
+ {
+ $udfPerson = json_decode($mitarbeiter->p_udf_values);
+ if (is_object($udfPerson)) $udfPerson = (array)$udfPerson;
+
+ foreach($udfTitlesPerson as $udfTitle)
+ {
+ if (isset($udfPerson[$udfTitle['name']]))
+ {
+ if (is_string($udfPerson[$udfTitle['name']]) || is_numeric($udfPerson[$udfTitle['name']]))
+ {
+ if (mb_strlen($udfPerson[$udfTitle['name']]) > $maxlength[$col])
+ {
+ $maxlength[$col] = mb_strlen($udfPerson[$udfTitle['name']]);
+ }
+ $worksheet->write($zeile, $col, $udfPerson[$udfTitle['name']]);
+ }
+ else if(is_array($udfPerson[$udfTitle['name']]) && isset($udfTitle['enum']))
+ {
+ $toWrite = $udf->dropdownListValuesToString($udfPerson[$udfTitle['name']], $udfTitle['enum']);
+
+ if (mb_strlen($toWrite) > $maxlength[$col])
+ {
+ $maxlength[$col] = mb_strlen($toWrite);
+ }
+ $worksheet->write($zeile, $col, $toWrite);
+ }
+ }
+ $col++;
+ }
}
- //Die Breite der Spalten setzen
- for ($i=0;$i<$anzSpalten;$i++)
- $worksheet->setColumn($i, $i, $maxlength[$i]+2);
- $worksheet->setColumn($i, $i, $maxlength[$i]+2);
- $worksheet->setColumn($i+1, $i+1, $maxlength[$i+1]+2);
- $worksheet->setColumn($i+2, $i+2, $maxlength[$i+2]+2);
+ $zeile++;
+}
- $workbook->close();
+//Die Breite der Spalten setzen
+for ($col = 0; $col < $anzSpalten; $col++)
+{
+ $worksheet->setColumn($col, $col, $maxlength[$col] + 2);
+}
-?>
+$worksheet->setColumn($col, $col, $maxlength[$col] + 2);
+$col++;
+$worksheet->setColumn($col, $col, $maxlength[$col] + 2);
+$col++;
+$worksheet->setColumn($col, $col, $maxlength[$col] + 2);
+
+$workbook->close();
+
+?>
\ No newline at end of file
diff --git a/content/statistik/studentenexport.xls.php b/content/statistik/studentenexport.xls.php
deleted file mode 100755
index cec1f2f51..000000000
--- a/content/statistik/studentenexport.xls.php
+++ /dev/null
@@ -1,585 +0,0 @@
-,
- * Andreas Oesterreicher and
- * Rudolf Hangl .
- */
-/**
- * Exportiert die Studentendaten in ein Excel File.
- * Die zu exportierenden Spalten werden per GET uebergeben.
- * Die Adressen werden immer dazugehaengt
- */
-require_once('../../config/vilesci.config.inc.php');
-require_once('../../include/functions.inc.php');
-require_once('../../include/person.class.php');
-require_once('../../include/benutzer.class.php');
-require_once('../../include/student.class.php');
-require_once('../../include/prestudent.class.php');
-require_once('../../include/datum.class.php');
-require_once('../../include/Excel/excel.php');
-
-$db = new basis_db();
-$user = get_uid();
-$datum_obj = new datum();
-loadVariables($user);
-
- //Parameter holen
- $data = $_POST['data'];
- $studiensemester_kurzbz = $_GET['studiensemester_kurzbz'];
- //$typ = $_GET['typ'];
- $maxlength= array();
- $zeile=1;
- $zgv_arr=array();
- $zgvmas_arr=array();
-
- //ZGV laden
- $qry = "SELECT * FROM bis.tbl_zgv ORDER BY zgv_kurzbz";
- if($result = $db->db_query($qry))
- {
- while($row = $db->db_fetch_object($result))
- {
- $zgv_arr[$row->zgv_code]=$row->zgv_kurzbz;
- }
- }
-
- //ZGV Master laden
- $qry = "SELECT * FROM bis.tbl_zgvmaster ORDER BY zgvmas_kurzbz";
- if($result = $db->db_query($qry))
- {
- while($row = $db->db_fetch_object($result))
- {
- $zgvmas_arr[$row->zgvmas_code]=$row->zgvmas_kurzbz;
- }
- }
-
- // Creating a workbook
- $workbook = new Spreadsheet_Excel_Writer();
- $workbook->setVersion(8);
- // sending HTTP headers
- $workbook->send("Studenten". "_" . date("d_m_Y") . ".xls");
-
- // Creating a worksheet
- $worksheet =& $workbook->addWorksheet("Studenten");
- $worksheet->setInputEncoding('utf-8');
-
- $format_bold =& $workbook->addFormat();
- $format_bold->setBold();
-
- $format_title =& $workbook->addFormat();
- $format_title->setBold();
- // let's merge
- $format_title->setAlign('merge');
-
- //Zeilenueberschriften ausgeben
- $i=0;
- $zeile=1;
-
- $worksheet->write($zeile,$i,"ANREDE", $format_bold);
- $maxlength[$i]=6;
- $worksheet->write($zeile,++$i,"TITELPRE", $format_bold);
- $maxlength[$i]=8;
- $worksheet->write($zeile,++$i,"NACHNAME", $format_bold);
- $maxlength[$i]=8;
- $worksheet->write($zeile,++$i,"VORNAME", $format_bold);
- $maxlength[$i]=7;
- $worksheet->write($zeile,++$i,"TITELPOST", $format_bold);
- $maxlength[$i]=9;
- $worksheet->write($zeile,++$i,"EMail Privat", $format_bold);
- $maxlength[$i]=12;
- $maxlength[$i]=12;
- $worksheet->write($zeile,++$i,"STRASSE", $format_bold);
- $maxlength[$i]=7;
- $worksheet->write($zeile-1,$i,"Zustelladresse", $format_bold);
- $worksheet->write($zeile,++$i,"PLZ", $format_bold);
- $maxlength[$i]=3;
- $worksheet->write($zeile,++$i,"ORT", $format_bold);
- $maxlength[$i]=3;
- $worksheet->write($zeile,++$i,"GEMEINDE", $format_bold);
- $maxlength[$i]=9;
- $worksheet->write($zeile,++$i,"NATION", $format_bold);
- $maxlength[$i]=6;
- $worksheet->write($zeile,++$i,"GEBURTSDATUM", $format_bold);
- $maxlength[$i]=12;
- $worksheet->write($zeile,++$i,"GEBURTSORT", $format_bold);
- $maxlength[$i]=12;
- $worksheet->write($zeile,++$i,"GEBURTSNATION", $format_bold);
- $maxlength[$i]=12;
- $worksheet->write($zeile,++$i,"PERSONENKENNZEICHEN", $format_bold);
- $maxlength[$i]=19;
- $worksheet->write($zeile,++$i,"STAATSBÜRGERSCHAFT", $format_bold);
- $maxlength[$i]=16;
- $worksheet->write($zeile,++$i,"SVNR", $format_bold);
- $maxlength[$i]=4;
- $worksheet->write($zeile,++$i,"ERSATZKENNZEICHEN", $format_bold);
- $maxlength[$i]=17;
- $worksheet->write($zeile,++$i,"GESCHLECHT", $format_bold);
- $maxlength[$i]=10;
-
- $worksheet->write($zeile,++$i,"STUDIENGANG", $format_bold);
- $maxlength[$i]=11;
- $worksheet->write($zeile,++$i,"SEMESTER IM $studiensemester_kurzbz", $format_bold);
- $maxlength[$i]=19;
- $worksheet->write($zeile,++$i,"SEMESTER AKTUELL", $format_bold);
- $maxlength[$i]=17;
- $worksheet->write($zeile,++$i,"VERBAND", $format_bold);
- $maxlength[$i]=7;
- $worksheet->write($zeile,++$i,"GRUPPE", $format_bold);
- $maxlength[$i]=6;
-
- $worksheet->write($zeile,++$i,"ZGV", $format_bold);
- $maxlength[$i]=10;
- $worksheet->write($zeile,++$i,"ZGV Ort", $format_bold);
- $maxlength[$i]=14;
- $worksheet->write($zeile,++$i,"ZGV Datum", $format_bold);
- $maxlength[$i]=6;
- $worksheet->write($zeile,++$i,"ZGV Master", $format_bold);
- $maxlength[$i]=10;
- $worksheet->write($zeile,++$i,"ZGV Master Ort", $format_bold);
- $maxlength[$i]=14;
- $worksheet->write($zeile,++$i,"ZGV Master Datum", $format_bold);
- $maxlength[$i]=16;
-
- $worksheet->write($zeile,++$i,"STATUS", $format_bold);
- $maxlength[$i]=6;
- $worksheet->write($zeile,++$i,"EMail Intern", $format_bold);
- $maxlength[$i]=12;
- $worksheet->write($zeile,++$i,"STRASSE", $format_bold);
- $maxlength[$i]=7;
- $worksheet->write($zeile-1,$i,"Nebenwohnsitz", $format_bold);
- $worksheet->write($zeile,++$i,"PLZ", $format_bold);
- $maxlength[$i]=3;
- $worksheet->write($zeile,++$i,"ORT", $format_bold);
- $maxlength[$i]=3;
- $worksheet->write($zeile,++$i,"TELEFON", $format_bold);
- $maxlength[$i]=3;
- $worksheet->write($zeile,++$i,"GRUPPEN", $format_bold);
- $maxlength[$i]=3;
- $worksheet->write($zeile,++$i,"UID", $format_bold);
- $maxlength[$i]=3;
- $worksheet->write($zeile,++$i,"ORGFORM", $format_bold);
- $maxlength[$i]=7;
- $worksheet->write($zeile,++$i,"VORNAMEN", $format_bold);
- $maxlength[$i]=8;
- $worksheet->write($zeile,++$i,"PRESTUDENTID", $format_bold);
- $maxlength[$i]=12;
- $worksheet->write($zeile,++$i,"MATR_NR", $format_bold);
- $maxlength[$i]=12;
-
- $zeile++;
-
- $ids = explode(';',$data);
- $prestudent_ids = '';
-
- foreach ($ids as $id)
- {
- if($id!='')
- {
- if($prestudent_ids!='')
- $prestudent_ids .= ',';
- $prestudent_ids .= "'".addslashes($id)."'";
- }
- }
-
- if($prestudent_ids!='')
- {
- // Student holen
- $qry = "SELECT *, (SELECT UPPER(typ || kurzbz) FROM public.tbl_studiengang WHERE studiengang_kz=tbl_prestudent.studiengang_kz) as stgbez FROM public.tbl_prestudent JOIN public.tbl_person USING(person_id) LEFT JOIN public.tbl_student USING(prestudent_id) WHERE prestudent_id in($prestudent_ids) ORDER BY nachname, vorname";
-
- if($result = $db->db_query($qry))
- {
- while($row = $db->db_fetch_object($result))
- {
- draw_content($row);
- $zeile++;
- }
- }
- }
-
- function draw_content($row)
- {
- global $maxlength, $datum_obj;
- global $zeile, $worksheet;
- global $zgv_arr, $zgvmas_arr;
- global $studiensemester_kurzbz;
- $db = new basis_db();
-
- $prestudent = new prestudent();
- $prestudent->getLastStatus($row->prestudent_id);
- $status = $prestudent->status_kurzbz;
- $orgform = $prestudent->orgform_kurzbz;
-
- $i=0;
-
- //Anrede
- if(mb_strlen($row->anrede)>$maxlength[$i])
- $maxlength[$i] = mb_strlen($row->anrede);
- $worksheet->write($zeile,$i, $row->anrede);
- $i++;
-
- //Titelpre
- if(mb_strlen($row->titelpre)>$maxlength[$i])
- $maxlength[$i] = mb_strlen($row->titelpre);
- $worksheet->write($zeile,$i, $row->titelpre);
- $i++;
-
- //Nachname
- if(mb_strlen($row->nachname)>$maxlength[$i])
- $maxlength[$i] = mb_strlen($row->nachname);
- $worksheet->write($zeile,$i, $row->nachname);
- $i++;
-
- //Vorname
- if(mb_strlen($row->vorname)>$maxlength[$i])
- $maxlength[$i] = mb_strlen($row->vorname);
- $worksheet->write($zeile,$i, $row->vorname);
- $i++;
-
- //Titelpost
- if(mb_strlen($row->titelpost)>$maxlength[$i])
- $maxlength[$i] = mb_strlen($row->titelpost);
- $worksheet->write($zeile,$i, $row->titelpost);
- $i++;
-
- //Email Privat
- //ZustellEmailAdresse aus der Datenbank holen und dazuhaengen
- $qry_1 = "SELECT kontakt FROM public.tbl_kontakt WHERE kontakttyp='email' AND person_id='$row->person_id' AND zustellung=true ORDER BY kontakt_id DESC LIMIT 1";
- if($result_1 = $db->db_query($qry_1))
- {
- if($row_1 = $db->db_fetch_object($result_1))
- {
- if(mb_strlen($row_1->kontakt)>$maxlength[$i])
- $maxlength[$i]=mb_strlen($row_1->kontakt);
- $worksheet->write($zeile,$i, $row_1->kontakt);
- }
- }
- $i++;
-
- //Zustelladresse
- //Zustelladresse aus der Datenbank holen und dazuhaengen
- $qry_1 = "SELECT * FROM public.tbl_adresse WHERE person_id='$row->person_id' AND zustelladresse=true LIMIT 1";
- if($result_1 = $db->db_query($qry_1))
- {
- if($row_1 = $db->db_fetch_object($result_1))
- {
- if(mb_strlen($row_1->strasse)>$maxlength[$i])
- $maxlength[$i]=mb_strlen($row_1->strasse);
- $worksheet->write($zeile,$i, $row_1->strasse);
- $i++;
-
- if(mb_strlen($row_1->plz)>$maxlength[$i])
- $maxlength[$i]=mb_strlen($row_1->plz);
- $worksheet->writeString($zeile,$i, $row_1->plz);
- $i++;
-
- if(mb_strlen($row_1->ort)>$maxlength[$i])
- $maxlength[$i]=mb_strlen($row_1->ort);
- $worksheet->write($zeile,$i, $row_1->ort);
- $i++;
-
- if(mb_strlen($row_1->gemeinde)>$maxlength[$i])
- $maxlength[$i]=mb_strlen($row_1->gemeinde);
- $worksheet->write($zeile,$i, $row_1->gemeinde);
- $i++;
-
- if(mb_strlen($row_1->nation)>$maxlength[$i])
- $maxlength[$i]=mb_strlen($row_1->nation);
- $worksheet->write($zeile,$i, $row_1->nation);
- $i++;
- }
- else
- $i+=5;
- }
- else
- $i+=5;
-
- //Geburtsdatum
- if(mb_strlen($row->gebdatum)>$maxlength[$i])
- $maxlength[$i] = mb_strlen($row->gebdatum);
- $worksheet->write($zeile,$i, $datum_obj->convertISODate($row->gebdatum));
- $i++;
-
- //Geburtsort
- if(mb_strlen($row->gebort)>$maxlength[$i])
- $maxlength[$i] = mb_strlen($row->gebort);
- $worksheet->write($zeile,$i,$row->gebort);
- $i++;
-
- //Geburtsnation
- if(mb_strlen($row->geburtsnation)>$maxlength[$i])
- $maxlength[$i] = mb_strlen($row->geburtsnation);
- $worksheet->write($zeile,$i,$row->geburtsnation);
- $i++;
-
- //Personenkennzeichen
- if(isset($row->matrikelnr))
- {
- if(mb_strlen($row->matrikelnr)>$maxlength[$i])
- $maxlength[$i] = mb_strlen($row->matrikelnr);
- $worksheet->writeString($zeile,$i, $row->matrikelnr);
- }
- $i++;
-
- //Staatsbuergerschaft
- if(mb_strlen($row->staatsbuergerschaft)>$maxlength[$i])
- $maxlength[$i] = mb_strlen($row->staatsbuergerschaft);
- $worksheet->write($zeile,$i, $row->staatsbuergerschaft);
- $i++;
-
- //SVNR
- if(mb_strlen($row->svnr)>$maxlength[$i])
- $maxlength[$i] = mb_strlen($row->svnr);
- $worksheet->write($zeile,$i, $row->svnr);
- $i++;
-
- //Ersatzkennzeichen
- if(mb_strlen($row->ersatzkennzeichen)>$maxlength[$i])
- $maxlength[$i] = mb_strlen($row->ersatzkennzeichen);
- $worksheet->write($zeile,$i, $row->ersatzkennzeichen);
- $i++;
-
- //Geschlecht
- if(mb_strlen($row->geschlecht)>$maxlength[$i])
- $maxlength[$i] = mb_strlen($row->geschlecht);
- $worksheet->write($zeile,$i, $row->geschlecht);
- $i++;
-
- //Studiengang
- if(mb_strlen($row->stgbez)>$maxlength[$i])
- $maxlength[$i] = mb_strlen($row->stgbez);
- $worksheet->write($zeile,$i, $row->stgbez);
- $i++;
-
- $qry = "SELECT tbl_studentlehrverband.semester AS semester_studiensemester, tbl_student.semester AS semester_aktuell,* FROM public.tbl_studentlehrverband JOIN public.tbl_student USING(student_uid) WHERE prestudent_id='$row->prestudent_id' AND studiensemester_kurzbz='".addslashes($studiensemester_kurzbz)."'";
- if($result_sem = $db->db_query($qry))
- {
- if($row_sem = $db->db_fetch_object($result_sem))
- {
- $semester_aktuell = $row_sem->semester_aktuell;
- $semester_studiensemester = $row_sem->semester_studiensemester;
- $verband = $row_sem->verband;
- $gruppe = $row_sem->gruppe;
- }
- else
- {
- $qry = "SELECT public.tbl_prestudentstatus.ausbildungssemester FROM public.tbl_prestudentstatus WHERE prestudent_id='$row->prestudent_id' AND (status_kurzbz='Interessent' OR status_kurzbz='Bewerber') ORDER BY datum DESC LIMIT 1";
- if (($result_sem = $db->db_query($qry)) && ($row_sem = $db->db_fetch_object($result_sem)))
- {
- $semester_aktuell = $row_sem->ausbildungssemester;
- }
- else
- {
- $semester_aktuell = '';
- $verband = '';
- $gruppe = '';
- }
- }
- }
- //Semester im eingestellten Studiensemester
- if(isset($semester_studiensemester))
- {
- if(mb_strlen($semester_studiensemester)>$maxlength[$i])
- $maxlength[$i] = mb_strlen($semester_studiensemester);
- $worksheet->write($zeile,$i, $semester_studiensemester);
- }
- $i++;
-
- //Semester aktuell
- if(isset($semester_aktuell))
- {
- if(mb_strlen($semester_aktuell)>$maxlength[$i])
- $maxlength[$i] = mb_strlen($semester_aktuell);
- $worksheet->write($zeile,$i, $semester_aktuell);
- }
- $i++;
-
- //Verband
- if(isset($verband))
- {
- if(mb_strlen($verband)>$maxlength[$i])
- $maxlength[$i] = mb_strlen($verband);
- $worksheet->write($zeile,$i, $verband);
- }
- $i++;
-
- //Gruppe
- if(isset($gruppe))
- {
- if(mb_strlen($gruppe)>$maxlength[$i])
- $maxlength[$i] = mb_strlen($gruppe);
- $worksheet->write($zeile,$i, $gruppe);
- }
- $i++;
-
- //ZGV
- if($row->zgv_code!='' && isset($zgv_arr[$row->zgv_code]))
- {
- if(mb_strlen($zgv_arr[$row->zgv_code])>$maxlength[$i])
- $maxlength[$i] = mb_strlen($zgv_arr[$row->zgv_code]);
- $worksheet->write($zeile,$i, $zgv_arr[$row->zgv_code]);
- }
- $i++;
-
- //ZGV Ort
- if(mb_strlen($row->zgvort)>$maxlength[$i])
- $maxlength[$i] = mb_strlen($row->zgvort);
- $worksheet->write($zeile,$i, $row->zgvort);
- $i++;
-
- //ZGV Datum
- if(mb_strlen($row->zgvdatum)>$maxlength[$i])
- $maxlength[$i] = mb_strlen($row->zgvdatum);
- $worksheet->write($zeile,$i, $row->zgvdatum);
- $i++;
-
- //ZGV Master
- if($row->zgvmas_code!='' && isset($zgvmas_arr[$row->zgvmas_code]))
- {
- if(mb_strlen($zgvmas_arr[$row->zgvmas_code])>$maxlength[$i])
- $maxlength[$i] = mb_strlen($zgvmas_arr[$row->zgvmas_code]);
- $worksheet->write($zeile,$i, $zgvmas_arr[$row->zgvmas_code]);
- }
- $i++;
-
- //ZGV Master Ort
- if(mb_strlen($row->zgvmaort)>$maxlength[$i])
- $maxlength[$i] = mb_strlen($row->zgvmaort);
- $worksheet->write($zeile,$i, $row->zgvmaort);
- $i++;
-
- //ZGV Master Datum
- if(mb_strlen($row->zgvmadatum)>$maxlength[$i])
- $maxlength[$i] = mb_strlen($row->zgvmadatum);
- $worksheet->write($zeile,$i, $row->zgvmadatum);
- $i++;
-
- //Status
- if(mb_strlen($status)>$maxlength[$i])
- $maxlength[$i] = mb_strlen($status);
- $worksheet->write($zeile,$i, $status);
- $i++;
-
- //Email Intern
- if(isset($row->student_uid))
- {
- if(mb_strlen($row->student_uid.'@'.DOMAIN)>$maxlength[$i])
- $maxlength[$i] = mb_strlen($row->student_uid.'@'.DOMAIN);
- $worksheet->write($zeile,$i, $row->student_uid.'@'.DOMAIN);
- }
- $i++;
-
- //Nebenwohnsitz
- //Nebenwohnsitz aus der Datenbank holen und dazuhaengen
- $qry_1 = "SELECT * FROM public.tbl_adresse WHERE person_id='$row->person_id' AND typ='n' LIMIT 1";
- if($result_1 = $db->db_query($qry_1))
- {
- if($row_1 = $db->db_fetch_object($result_1))
- {
- if(mb_strlen($row_1->strasse)>$maxlength[$i])
- $maxlength[$i]=mb_strlen($row_1->strasse);
- $worksheet->write($zeile,$i, $row_1->strasse);
- $i++;
-
- if(mb_strlen($row_1->plz)>$maxlength[$i])
- $maxlength[$i]=mb_strlen($row_1->plz);
- $worksheet->writeString($zeile,$i, $row_1->plz);
- $i++;
-
- if(mb_strlen($row_1->ort)>$maxlength[$i])
- $maxlength[$i]=mb_strlen($row_1->ort);
- $worksheet->write($zeile,$i, $row_1->ort);
- $i++;
- }
- else
- $i+=3;
- }
- else
- $i+=3;
-
- //Telefon
- $qry_1 = "SELECT kontakt FROM public.tbl_kontakt WHERE kontakttyp in('mobil','telefon','so.tel') AND person_id='$row->person_id' AND zustellung=true LIMIT 1";
- if($result_1 = $db->db_query($qry_1))
- {
- if($row_1 = $db->db_fetch_object($result_1))
- {
- if(mb_strlen($row_1->kontakt)>$maxlength[$i])
- $maxlength[$i]=mb_strlen($row_1->kontakt);
- $worksheet->writeString($zeile,$i, $row_1->kontakt);
- }
- }
- $i++;
-
- //Spezialgruppen
- $grps='';
- $qry_1 = "SELECT gruppe_kurzbz FROM public.tbl_student JOIN public.tbl_benutzergruppe ON (student_uid=uid) WHERE tbl_student.prestudent_id='$row->prestudent_id' AND tbl_benutzergruppe.studiensemester_kurzbz='".addslashes($studiensemester_kurzbz)."'";
- if($result_1 = $db->db_query($qry_1))
- {
- while($row_1 = $db->db_fetch_object($result_1))
- {
- if($grps!='')
- $grps.=',';
-
- $grps.=$row_1->gruppe_kurzbz;
- }
- }
- if(mb_strlen($grps)>$maxlength[$i])
- $maxlength[$i]=mb_strlen($grps);
- $worksheet->write($zeile,$i, $grps);
- $i++;
-
- //UID
- if(isset($row->student_uid))
- {
- if(mb_strlen($row->student_uid)>$maxlength[$i])
- $maxlength[$i] = mb_strlen($row->student_uid);
- $worksheet->write($zeile,$i, $row->student_uid);
- }
- $i++;
-
- //Orgform
- if(mb_strlen($orgform)>$maxlength[$i])
- $maxlength[$i] = mb_strlen($orgform);
- $worksheet->write($zeile,$i, $orgform);
- $i++;
-
- //Vornamen
- if(mb_strlen($row->vornamen)>$maxlength[$i])
- $maxlength[$i] = mb_strlen($row->vornamen);
- $worksheet->write($zeile,$i, $row->vornamen);
- $i++;
-
- //PrestudentID
- if(mb_strlen($row->prestudent_id)>$maxlength[$i])
- $maxlength[$i] = mb_strlen($row->prestudent_id);
- $worksheet->write($zeile,$i, $row->prestudent_id);
- $i++;
-
- //Matrikelnummer (tbl_person)
- if(mb_strlen($row->matr_nr)>$maxlength[$i])
- $maxlength[$i] = mb_strlen($row->matr_nr);
- $worksheet->write($zeile,$i, $row->matr_nr);
- $i++;
- }
-
-
- //Die Breite der Spalten setzen
- foreach($maxlength as $i=>$breite)
- $worksheet->setColumn($i, $i, $breite+2);
-
- $workbook->close();
-
-?>
diff --git a/content/statistik/studentenexportextended.xls.php b/content/statistik/studentenexportextended.xls.php
index e5bf89af0..2a55601cf 100644
--- a/content/statistik/studentenexportextended.xls.php
+++ b/content/statistik/studentenexportextended.xls.php
@@ -37,485 +37,587 @@ require_once('../../include/student.class.php');
require_once('../../include/prestudent.class.php');
require_once('../../include/datum.class.php');
require_once('../../include/Excel/excel.php');
+require_once('../../include/udf.class.php');
$user = get_uid();
$datum_obj = new datum();
$db = new basis_db();
loadVariables($user);
- //Parameter holen
- $data = $_REQUEST['data'];
- $studiensemester_kurzbz = $_GET['studiensemester_kurzbz'];
-
- $maxlength= array();
- $zeile=1;
- $zgv_arr=array();
- $zgvmas_arr=array();
-
- //ZGV laden
- $qry = "SELECT * FROM bis.tbl_zgv ORDER BY zgv_kurzbz";
- if($result = $db->db_query($qry))
- {
- while($row = $db->db_fetch_object($result))
- {
- $zgv_arr[$row->zgv_code]=$row->zgv_kurzbz;
- }
- }
-
- //ZGV Master laden
- $qry = "SELECT * FROM bis.tbl_zgvmaster ORDER BY zgvmas_kurzbz";
- if($result = $db->db_query($qry))
- {
- while($row = $db->db_fetch_object($result))
- {
- $zgvmas_arr[$row->zgvmas_code]=$row->zgvmas_kurzbz;
- }
- }
-
- // Creating a workbook
- $workbook = new Spreadsheet_Excel_Writer();
- $workbook->setVersion(8);
-
- // sending HTTP headers
- $workbook->send("Studenten". "_" . date("d_m_Y") . ".xls");
+//Parameter holen
+$data = $_REQUEST['data'];
+$studiensemester_kurzbz = $_GET['studiensemester_kurzbz'];
- // Creating a worksheet
- $worksheet =& $workbook->addWorksheet("Studenten");
- $worksheet->setInputEncoding('utf-8');
-
- $format_bold =& $workbook->addFormat();
- $format_bold->setBold();
+$maxlength = array();
+$zeile = 1;
+$zgv_arr = array();
+$zgvmas_arr = array();
- $format_title =& $workbook->addFormat();
- $format_title->setBold();
- // let's merge
- $format_title->setAlign('merge');
-
- //Zeilenueberschriften ausgeben
- $i=0;
- $zeile=1;
-
- $worksheet->write($zeile,$i,"ANREDE", $format_bold);
- $maxlength[$i]=6;
- $worksheet->write($zeile,++$i,"TITELPRE", $format_bold);
- $maxlength[$i]=8;
- $worksheet->write($zeile,++$i,"NACHNAME", $format_bold);
- $maxlength[$i]=8;
- $worksheet->write($zeile,++$i,"VORNAME", $format_bold);
- $maxlength[$i]=7;
- $worksheet->write($zeile,++$i,"TITELPOST", $format_bold);
- $maxlength[$i]=9;
- $worksheet->write($zeile,++$i,"EMail Privat", $format_bold);
- $maxlength[$i]=12;
- $worksheet->write($zeile,++$i,"GEBURTSDATUM", $format_bold);
- $maxlength[$i]=12;
- $worksheet->write($zeile,++$i,"PERSONENKENNZEICHEN", $format_bold);
- $maxlength[$i]=19;
- $worksheet->write($zeile,++$i,"STAATSBÜRGERSCHAFT", $format_bold);
- $maxlength[$i]=16;
- $worksheet->write($zeile,++$i,"SVNR", $format_bold);
- $maxlength[$i]=4;
- $worksheet->write($zeile,++$i,"ERSATZKENNZEICHEN", $format_bold);
- $maxlength[$i]=17;
- $worksheet->write($zeile,++$i,"GESCHLECHT", $format_bold);
- $maxlength[$i]=10;
- $worksheet->write($zeile,++$i,"STUDIENGANG", $format_bold);
- $maxlength[$i]=11;
- $worksheet->write($zeile,++$i,"SEMESTER IM $studiensemester_kurzbz", $format_bold);
- $maxlength[$i]=19;
- $worksheet->write($zeile,++$i,"SEMESTER AKTUELL", $format_bold);
- $maxlength[$i]=17;
- $worksheet->write($zeile,++$i,"VERBAND", $format_bold);
- $maxlength[$i]=7;
- $worksheet->write($zeile,++$i,"GRUPPE", $format_bold);
- $maxlength[$i]=6;
-
- $worksheet->write($zeile,++$i,"ZGV", $format_bold);
- $maxlength[$i]=10;
- $worksheet->write($zeile,++$i,"ZGV Ort", $format_bold);
- $maxlength[$i]=14;
- $worksheet->write($zeile,++$i,"ZGV Datum", $format_bold);
- $maxlength[$i]=6;
- $worksheet->write($zeile,++$i,"ZGV Master", $format_bold);
- $maxlength[$i]=10;
- $worksheet->write($zeile,++$i,"ZGV Master Ort", $format_bold);
- $maxlength[$i]=14;
- $worksheet->write($zeile,++$i,"ZGV Master Datum", $format_bold);
- $maxlength[$i]=16;
-
- $worksheet->write($zeile,++$i,"STATUS", $format_bold);
- $maxlength[$i]=6;
- $worksheet->write($zeile,++$i,"STATI IN ANDEREN STUDIENGÄNGEN", $format_bold);
- $maxlength[$i]=8;
- $worksheet->write($zeile,++$i,"EMail Intern", $format_bold);
- $maxlength[$i]=12;
- $worksheet->write($zeile,++$i,"TELEFON", $format_bold);
- $maxlength[$i]=3;
- $worksheet->write($zeile,++$i,"GRUPPEN", $format_bold);
- $maxlength[$i]=3;
- $worksheet->write($zeile,++$i,"UID", $format_bold);
- $maxlength[$i]=3;
- $worksheet->write($zeile,++$i,"ORGFORM", $format_bold);
- $maxlength[$i]=7;
- $worksheet->write($zeile,++$i,"VORNAMEN", $format_bold);
- $maxlength[$i]=8;
- $worksheet->write($zeile,++$i,"RT_PUNKTE1", $format_bold);
- $maxlength[$i]=10;
- $worksheet->write($zeile,++$i,"RT_PUNKTE2", $format_bold);
- $maxlength[$i]=10;
- $worksheet->write($zeile,++$i,"RT_GESAMTPUNKTE", $format_bold);
- $maxlength[$i]=18;
-
- $zeile++;
-
- $ids = explode(';',$data);
- $prestudent_ids = '';
-
- foreach ($ids as $id)
+//ZGV laden
+$qry = "SELECT * FROM bis.tbl_zgv ORDER BY zgv_kurzbz";
+if ($result = $db->db_query($qry))
+{
+ while($row = $db->db_fetch_object($result))
{
- if($id!='')
- {
- if($prestudent_ids!='')
- $prestudent_ids .= ',';
- $prestudent_ids .= "'".addslashes($id)."'";
- }
+ $zgv_arr[$row->zgv_code] = $row->zgv_kurzbz;
+ }
+}
+
+//ZGV Master laden
+$qry = "SELECT * FROM bis.tbl_zgvmaster ORDER BY zgvmas_kurzbz";
+if ($result = $db->db_query($qry))
+{
+ while($row = $db->db_fetch_object($result))
+ {
+ $zgvmas_arr[$row->zgvmas_code] = $row->zgvmas_kurzbz;
+ }
+}
+
+// Creating a workbook
+$workbook = new Spreadsheet_Excel_Writer();
+$workbook->setVersion(8);
+
+// sending HTTP headers
+$workbook->send("Studenten". "_" . date("d_m_Y") . ".xls");
+
+// Creating a worksheet
+$worksheet =& $workbook->addWorksheet("Studenten");
+$worksheet->setInputEncoding('utf-8');
+
+$format_bold =& $workbook->addFormat();
+$format_bold->setBold();
+
+$format_title =& $workbook->addFormat();
+$format_title->setBold();
+// let's merge
+$format_title->setAlign('merge');
+
+//Zeilenueberschriften ausgeben
+$i = 0;
+$zeile = 1;
+
+$worksheet->write($zeile, $i, "ANREDE", $format_bold);
+$maxlength[$i] = 6;
+$worksheet->write($zeile, ++$i, "TITELPRE", $format_bold);
+$maxlength[$i] = 8;
+$worksheet->write($zeile, ++$i, "NACHNAME", $format_bold);
+$maxlength[$i] = 8;
+$worksheet->write($zeile, ++$i, "VORNAME", $format_bold);
+$maxlength[$i] = 7;
+$worksheet->write($zeile, ++$i, "TITELPOST", $format_bold);
+$maxlength[$i] = 9;
+$worksheet->write($zeile, ++$i, "EMail Privat", $format_bold);
+$maxlength[$i] = 12;
+$worksheet->write($zeile, ++$i, "GEBURTSDATUM", $format_bold);
+$maxlength[$i] = 12;
+$worksheet->write($zeile, ++$i, "PERSONENKENNZEICHEN", $format_bold);
+$maxlength[$i] = 19;
+$worksheet->write($zeile, ++$i, "STAATSBÜRGERSCHAFT", $format_bold);
+$maxlength[$i] = 16;
+$worksheet->write($zeile, ++$i, "SVNR", $format_bold);
+$maxlength[$i] = 4;
+$worksheet->write($zeile, ++$i, "ERSATZKENNZEICHEN", $format_bold);
+$maxlength[$i] = 17;
+$worksheet->write($zeile, ++$i, "GESCHLECHT", $format_bold);
+$maxlength[$i] = 10;
+$worksheet->write($zeile, ++$i, "STUDIENGANG", $format_bold);
+$maxlength[$i] = 11;
+$worksheet->write($zeile, ++$i, "SEMESTER IM $studiensemester_kurzbz", $format_bold);
+$maxlength[$i] = 19;
+$worksheet->write($zeile, ++$i, "SEMESTER AKTUELL", $format_bold);
+$maxlength[$i] = 17;
+$worksheet->write($zeile, ++$i, "VERBAND", $format_bold);
+$maxlength[$i] = 7;
+$worksheet->write($zeile, ++$i, "GRUPPE", $format_bold);
+$maxlength[$i] = 6;
+
+$worksheet->write($zeile, ++$i, "ZGV", $format_bold);
+$maxlength[$i] = 10;
+$worksheet->write($zeile, ++$i, "ZGV Ort", $format_bold);
+$maxlength[$i] = 14;
+$worksheet->write($zeile, ++$i, "ZGV Datum", $format_bold);
+$maxlength[$i] = 6;
+$worksheet->write($zeile, ++$i, "ZGV Master", $format_bold);
+$maxlength[$i] = 10;
+$worksheet->write($zeile, ++$i, "ZGV Master Ort", $format_bold);
+$maxlength[$i] = 14;
+$worksheet->write($zeile, ++$i, "ZGV Master Datum", $format_bold);
+$maxlength[$i] = 16;
+
+$worksheet->write($zeile, ++$i, "STATUS", $format_bold);
+$maxlength[$i] = 6;
+$worksheet->write($zeile, ++$i, "STATI IN ANDEREN STUDIENGÄNGEN", $format_bold);
+$maxlength[$i] = 8;
+$worksheet->write($zeile, ++$i, "EMail Intern", $format_bold);
+$maxlength[$i] = 12;
+$worksheet->write($zeile, ++$i, "TELEFON", $format_bold);
+$maxlength[$i] = 3;
+$worksheet->write($zeile, ++$i, "GRUPPEN", $format_bold);
+$maxlength[$i] = 3;
+$worksheet->write($zeile, ++$i, "UID", $format_bold);
+$maxlength[$i] = 3;
+$worksheet->write($zeile, ++$i, "ORGFORM", $format_bold);
+$maxlength[$i] = 7;
+$worksheet->write($zeile, ++$i, "VORNAMEN", $format_bold);
+$maxlength[$i] = 8;
+$worksheet->write($zeile, ++$i, "RT_PUNKTE1", $format_bold);
+$maxlength[$i] = 10;
+$worksheet->write($zeile, ++$i, "RT_PUNKTE2", $format_bold);
+$maxlength[$i] = 10;
+$worksheet->write($zeile, ++$i, "RT_GESAMTPUNKTE", $format_bold);
+$maxlength[$i] = 18;
+
+// UDF titles
+$udf = new UDF();
+$udfTitlesPerson = $udf->getTitlesPerson();
+$udfTitlesPrestudent = $udf->getTitlesPrestudent();
+
+foreach($udfTitlesPerson as $udfTitle)
+{
+ $worksheet->write($zeile, ++$i, $udfTitle['description'], $format_bold);
+ $maxlength[$i] = mb_strlen($udfTitle['description']);
+}
+
+foreach($udfTitlesPrestudent as $udfTitle)
+{
+ $worksheet->write($zeile, ++$i, $udfTitle['description'], $format_bold);
+ $maxlength[$i] = mb_strlen($udfTitle['description']);
+}
+
+$zeile++;
+
+$ids = explode(';',$data);
+$prestudent_ids = '';
+
+foreach ($ids as $id)
+{
+ if ($id!='')
+ {
+ if ($prestudent_ids!='')
+ $prestudent_ids .= ',';
+ $prestudent_ids .= "'".addslashes($id)."'";
+ }
+}
+
+if ($prestudent_ids!='')
+{
+ // Student holen
+ $qry = "SELECT *,";
+
+ if ($udf->personHasUDF())
+ {
+ $qry .= " p.udf_values AS p_udf_values,";
+ }
+ if ($udf->prestudentHasUDF())
+ {
+ $qry .= " ps.udf_values AS ps_udf_values,";
}
- if($prestudent_ids!='')
+ $qry .= " ps.studiengang_kz AS prestgkz,
+ (
+ SELECT UPPER(typ || kurzbz)
+ FROM public.tbl_studiengang s
+ WHERE studiengang_kz = ps.studiengang_kz
+ ) AS stgbez
+ FROM public.tbl_prestudent ps
+ JOIN public.tbl_person p USING(person_id)
+ LEFT JOIN public.tbl_student s USING(prestudent_id)
+ WHERE prestudent_id IN($prestudent_ids)
+ ORDER BY nachname, vorname";
+
+ if ($db->db_query($qry))
{
- // Student holen
- $qry = "SELECT *, tbl_prestudent.studiengang_kz as prestgkz, (SELECT UPPER(typ || kurzbz) FROM public.tbl_studiengang WHERE studiengang_kz=tbl_prestudent.studiengang_kz) as stgbez
- FROM public.tbl_prestudent JOIN public.tbl_person USING(person_id) LEFT JOIN public.tbl_student USING(prestudent_id)
- WHERE prestudent_id in($prestudent_ids) ORDER BY nachname, vorname";
-
- if($db->db_query($qry))
+ while($row = $db->db_fetch_object())
{
- while($row = $db->db_fetch_object())
- {
- draw_content($row);
- $zeile++;
- }
+ draw_content($row);
+ $zeile++;
}
}
+}
+
+function draw_content($row)
+{
+ global $maxlength, $datum_obj;
+ global $zeile, $worksheet;
+ global $zgv_arr, $zgvmas_arr;
+ global $studiensemester_kurzbz;
+ global $udfTitlesPerson, $udfTitlesPrestudent, $udf;
+ $db = new basis_db();
- function draw_content($row)
- {
- global $maxlength, $datum_obj;
- global $zeile, $worksheet;
- global $zgv_arr, $zgvmas_arr;
- global $studiensemester_kurzbz;
- $db = new basis_db();
+ $prestudent = new prestudent();
+ $prestudent->getLastStatus($row->prestudent_id);
+ $status = $prestudent->status_kurzbz;
+ $orgform = $prestudent->orgform_kurzbz;
- $prestudent = new prestudent();
- $prestudent->getLastStatus($row->prestudent_id);
- $status = $prestudent->status_kurzbz;
- $orgform = $prestudent->orgform_kurzbz;
+ $i = 0;
+
+ //Anrede
+ if (mb_strlen($row->anrede) > $maxlength[$i])
+ $maxlength[$i] = mb_strlen($row->anrede);
+ $worksheet->write($zeile, $i, $row->anrede);
+ $i++;
+
+ //Titelpre
+ if (mb_strlen($row->titelpre) > $maxlength[$i])
+ $maxlength[$i] = mb_strlen($row->titelpre);
+ $worksheet->write($zeile, $i, $row->titelpre);
+ $i++;
+
+ //Nachname
+ if (mb_strlen($row->nachname) > $maxlength[$i])
+ $maxlength[$i] = mb_strlen($row->nachname);
+ $worksheet->write($zeile, $i, $row->nachname);
+ $i++;
+
+ //Vorname
+ if (mb_strlen($row->vorname) > $maxlength[$i])
+ $maxlength[$i] = mb_strlen($row->vorname);
+ $worksheet->write($zeile, $i, $row->vorname);
+ $i++;
+
+ //Titelpost
+ if (mb_strlen($row->titelpost) > $maxlength[$i])
+ $maxlength[$i] = mb_strlen($row->titelpost);
+ $worksheet->write($zeile, $i, $row->titelpost);
+ $i++;
+
+ //Email Privat
+ //ZustellEmailAdresse aus der Datenbank holen und dazuhaengen
+ $qry_1 = "SELECT kontakt FROM public.tbl_kontakt
+ WHERE kontakttyp='email' AND person_id='".addslashes($row->person_id)."' AND zustellung=true
+ ORDER BY kontakt_id DESC LIMIT 1";
+ if ($db->db_query($qry_1))
+ {
+ if ($row_1 = $db->db_fetch_object())
+ {
+ if (mb_strlen($row_1->kontakt) > $maxlength[$i])
+ $maxlength[$i] = mb_strlen($row_1->kontakt);
+ $worksheet->write($zeile, $i, $row_1->kontakt);
+ }
+ }
+ $i++;
+
+ //Geburtsdatum
+ if (mb_strlen($row->gebdatum) > $maxlength[$i])
+ $maxlength[$i] = mb_strlen($row->gebdatum);
+ $worksheet->write($zeile, $i, $datum_obj->convertISODate($row->gebdatum));
+ $i++;
+
+ //Personenkennzeichen
+ if (isset($row->matrikelnr))
+ {
+ if (mb_strlen($row->matrikelnr) > $maxlength[$i])
+ $maxlength[$i] = mb_strlen($row->matrikelnr);
+ $worksheet->writeString($zeile, $i, $row->matrikelnr);
+ }
+ $i++;
+
+ //Staatsbuergerschaft
+ if (mb_strlen($row->staatsbuergerschaft) > $maxlength[$i])
+ $maxlength[$i] = mb_strlen($row->staatsbuergerschaft);
+ $worksheet->write($zeile, $i, $row->staatsbuergerschaft);
+ $i++;
+
+ //SVNR
+ if (mb_strlen($row->svnr) > $maxlength[$i])
+ $maxlength[$i] = mb_strlen($row->svnr);
+ $worksheet->write($zeile, $i, $row->svnr);
+ $i++;
+
+ //Ersatzkennzeichen
+ if (mb_strlen($row->ersatzkennzeichen) > $maxlength[$i])
+ $maxlength[$i] = mb_strlen($row->ersatzkennzeichen);
+ $worksheet->write($zeile, $i, $row->ersatzkennzeichen);
+ $i++;
+
+ //Geschlecht
+ if (mb_strlen($row->geschlecht) > $maxlength[$i])
+ $maxlength[$i] = mb_strlen($row->geschlecht);
+ $worksheet->write($zeile, $i, $row->geschlecht);
+ $i++;
+
+ //Studiengang
+ if (mb_strlen($row->stgbez) > $maxlength[$i])
+ $maxlength[$i] = mb_strlen($row->stgbez);
+ $worksheet->write($zeile, $i, $row->stgbez);
+ $i++;
+
+ $qry = "SELECT tbl_studentlehrverband.semester AS semester_studiensemester, tbl_student.semester AS semester_aktuell,* FROM public.tbl_studentlehrverband JOIN public.tbl_student USING(student_uid)
+ WHERE prestudent_id='".addslashes($row->prestudent_id)."'
+ AND studiensemester_kurzbz='".addslashes($studiensemester_kurzbz)."'";
+ if ($db->db_query($qry))
+ {
+ if ($row_sem = $db->db_fetch_object())
+ {
+ $semester_aktuell = $row_sem->semester_aktuell;
+ $semester_studiensemester = $row_sem->semester_studiensemester;
+ $verband = $row_sem->verband;
+ $gruppe = $row_sem->gruppe;
+ }
+ else
+ {
+ $semester_aktuell = '';
+ $verband = '';
+ $gruppe = '';
+ }
+ }
+ //Semester im eingestellten Studiensemester
+ if (isset($semester_studiensemester))
+ {
+ if (mb_strlen($semester_studiensemester) > $maxlength[$i])
+ $maxlength[$i] = mb_strlen($semester_studiensemester);
+ $worksheet->write($zeile, $i, $semester_studiensemester);
+ }
+ $i++;
+
+ //Semester aktuell
+ if (isset($semester_aktuell))
+ {
+ if (mb_strlen($semester_aktuell) > $maxlength[$i])
+ $maxlength[$i] = mb_strlen($semester_aktuell);
+ $worksheet->write($zeile, $i, $semester_aktuell);
+ }
+ $i++;
+
+ //Verband
+ if (isset($verband))
+ {
+ if (mb_strlen($verband) > $maxlength[$i])
+ $maxlength[$i] = mb_strlen($verband);
+ $worksheet->write($zeile, $i, $verband);
+ }
+ $i++;
+
+ //Gruppe
+ if (isset($gruppe))
+ {
+ if (mb_strlen($gruppe) > $maxlength[$i])
+ $maxlength[$i] = mb_strlen($gruppe);
+ $worksheet->write($zeile, $i, $gruppe);
+ }
+ $i++;
+
+ //ZGV
+ if ($row->zgv_code!='' && isset($zgv_arr[$row->zgv_code]))
+ {
+ if (mb_strlen($zgv_arr[$row->zgv_code]) > $maxlength[$i])
+ $maxlength[$i] = mb_strlen($zgv_arr[$row->zgv_code]);
+ $worksheet->write($zeile, $i, $zgv_arr[$row->zgv_code]);
+ }
+ $i++;
+
+ //ZGV Ort
+ if (mb_strlen($row->zgvort) > $maxlength[$i])
+ $maxlength[$i] = mb_strlen($row->zgvort);
+ $worksheet->write($zeile, $i, $row->zgvort);
+ $i++;
+
+ //ZGV Datum
+ if (mb_strlen($row->zgvdatum) > $maxlength[$i])
+ $maxlength[$i] = mb_strlen($row->zgvdatum);
+ $worksheet->write($zeile, $i, $row->zgvdatum);
+ $i++;
+
+ //ZGV Master
+ if ($row->zgvmas_code!='' && isset($zgvmas_arr[$row->zgvmas_code]))
+ {
+ if (mb_strlen($zgvmas_arr[$row->zgvmas_code]) > $maxlength[$i])
+ $maxlength[$i] = mb_strlen($zgvmas_arr[$row->zgvmas_code]);
+ $worksheet->write($zeile, $i, $zgvmas_arr[$row->zgvmas_code]);
+ }
+ $i++;
+
+ //ZGV Master Ort
+ if (mb_strlen($row->zgvmaort) > $maxlength[$i])
+ $maxlength[$i] = mb_strlen($row->zgvmaort);
+ $worksheet->write($zeile, $i, $row->zgvmaort);
+ $i++;
+
+ //ZGV Master Datum
+ if (mb_strlen($row->zgvmadatum) > $maxlength[$i])
+ $maxlength[$i] = mb_strlen($row->zgvmadatum);
+ $worksheet->write($zeile, $i, $row->zgvmadatum);
+ $i++;
+
+ //Status
+ if (mb_strlen($status) > $maxlength[$i])
+ $maxlength[$i] = mb_strlen($status);
+ $worksheet->write($zeile, $i, $status);
+ $i++;
+
+ //Stati in anderen Studiengaengen
+ $stati='';
+ $qry_1 = "SELECT UPPER(typ::varchar(1) || kurzbz) as stg, get_rolle_prestudent(prestudent_id, null) as status FROM
+ public.tbl_prestudent JOIN public.tbl_studiengang USING(studiengang_kz)
+ WHERE person_id='".addslashes($row->person_id)."' AND tbl_prestudent.studiengang_kz<>'".addslashes($row->prestgkz)."'";
+
+ if ($db->db_query($qry_1))
+ {
+ while($row_1 = $db->db_fetch_object())
+ {
+ if ($stati!='')
+ $stati.=', ';
+ $stati.= $row_1->status.' ('.$row_1->stg.')';
+ }
+ }
+ if (mb_strlen($stati) > $maxlength[$i])
+ $maxlength[$i] = mb_strlen($stati);
+ $worksheet->write($zeile, $i, $stati);
+ $i++;
+
+ //Email Intern
+ if (isset($row->student_uid))
+ {
+ if (mb_strlen($row->student_uid.'@'.DOMAIN) > $maxlength[$i])
+ $maxlength[$i] = mb_strlen($row->student_uid.'@'.DOMAIN);
+ $worksheet->write($zeile, $i, $row->student_uid.'@'.DOMAIN);
+ }
+ $i++;
- $i=0;
-
- //Anrede
- if(mb_strlen($row->anrede)>$maxlength[$i])
- $maxlength[$i] = mb_strlen($row->anrede);
- $worksheet->write($zeile,$i, $row->anrede);
- $i++;
-
- //Titelpre
- if(mb_strlen($row->titelpre)>$maxlength[$i])
- $maxlength[$i] = mb_strlen($row->titelpre);
- $worksheet->write($zeile,$i, $row->titelpre);
- $i++;
-
- //Nachname
- if(mb_strlen($row->nachname)>$maxlength[$i])
- $maxlength[$i] = mb_strlen($row->nachname);
- $worksheet->write($zeile,$i, $row->nachname);
- $i++;
-
- //Vorname
- if(mb_strlen($row->vorname)>$maxlength[$i])
- $maxlength[$i] = mb_strlen($row->vorname);
- $worksheet->write($zeile,$i, $row->vorname);
- $i++;
-
- //Titelpost
- if(mb_strlen($row->titelpost)>$maxlength[$i])
- $maxlength[$i] = mb_strlen($row->titelpost);
- $worksheet->write($zeile,$i, $row->titelpost);
- $i++;
-
- //Email Privat
- //ZustellEmailAdresse aus der Datenbank holen und dazuhaengen
- $qry_1 = "SELECT kontakt FROM public.tbl_kontakt
- WHERE kontakttyp='email' AND person_id='".addslashes($row->person_id)."' AND zustellung=true
- ORDER BY kontakt_id DESC LIMIT 1";
- if($db->db_query($qry_1))
+ //Telefon
+ $qry_1 = "SELECT kontakt FROM public.tbl_kontakt
+ WHERE kontakttyp in('mobil','telefon','so.tel') AND person_id='".addslashes($row->person_id)."' AND zustellung=true LIMIT 1";
+ if ($db->db_query($qry_1))
+ {
+ if ($row_1 = $db->db_fetch_object())
{
- if($row_1 = $db->db_fetch_object())
- {
- if(mb_strlen($row_1->kontakt)>$maxlength[$i])
- $maxlength[$i]=mb_strlen($row_1->kontakt);
- $worksheet->write($zeile,$i, $row_1->kontakt);
- }
+ if (mb_strlen($row_1->kontakt) > $maxlength[$i])
+ $maxlength[$i] = mb_strlen($row_1->kontakt);
+ $worksheet->writeString($zeile, $i, $row_1->kontakt);
}
- $i++;
-
- //Geburtsdatum
- if(mb_strlen($row->gebdatum)>$maxlength[$i])
- $maxlength[$i] = mb_strlen($row->gebdatum);
- $worksheet->write($zeile,$i, $datum_obj->convertISODate($row->gebdatum));
- $i++;
-
- //Personenkennzeichen
- if(isset($row->matrikelnr))
- {
- if(mb_strlen($row->matrikelnr)>$maxlength[$i])
- $maxlength[$i] = mb_strlen($row->matrikelnr);
- $worksheet->writeString($zeile,$i, $row->matrikelnr);
- }
- $i++;
-
- //Staatsbuergerschaft
- if(mb_strlen($row->staatsbuergerschaft)>$maxlength[$i])
- $maxlength[$i] = mb_strlen($row->staatsbuergerschaft);
- $worksheet->write($zeile,$i, $row->staatsbuergerschaft);
- $i++;
-
- //SVNR
- if(mb_strlen($row->svnr)>$maxlength[$i])
- $maxlength[$i] = mb_strlen($row->svnr);
- $worksheet->write($zeile,$i, $row->svnr);
- $i++;
-
- //Ersatzkennzeichen
- if(mb_strlen($row->ersatzkennzeichen)>$maxlength[$i])
- $maxlength[$i] = mb_strlen($row->ersatzkennzeichen);
- $worksheet->write($zeile,$i, $row->ersatzkennzeichen);
- $i++;
-
- //Geschlecht
- if(mb_strlen($row->geschlecht)>$maxlength[$i])
- $maxlength[$i] = mb_strlen($row->geschlecht);
- $worksheet->write($zeile,$i, $row->geschlecht);
- $i++;
-
- //Studiengang
- if(mb_strlen($row->stgbez)>$maxlength[$i])
- $maxlength[$i] = mb_strlen($row->stgbez);
- $worksheet->write($zeile,$i, $row->stgbez);
- $i++;
-
- $qry = "SELECT tbl_studentlehrverband.semester AS semester_studiensemester, tbl_student.semester AS semester_aktuell,* FROM public.tbl_studentlehrverband JOIN public.tbl_student USING(student_uid)
- WHERE prestudent_id='".addslashes($row->prestudent_id)."'
- AND studiensemester_kurzbz='".addslashes($studiensemester_kurzbz)."'";
- if($db->db_query($qry))
- {
- if($row_sem = $db->db_fetch_object())
- {
- $semester_aktuell = $row_sem->semester_aktuell;
- $semester_studiensemester = $row_sem->semester_studiensemester;
- $verband = $row_sem->verband;
- $gruppe = $row_sem->gruppe;
- }
- else
- {
- $semester_aktuell = '';
- $verband = '';
- $gruppe = '';
- }
- }
- //Semester im eingestellten Studiensemester
- if(isset($semester_studiensemester))
- {
- if(mb_strlen($semester_studiensemester)>$maxlength[$i])
- $maxlength[$i] = mb_strlen($semester_studiensemester);
- $worksheet->write($zeile,$i, $semester_studiensemester);
- }
- $i++;
-
- //Semester aktuell
- if(isset($semester_aktuell))
- {
- if(mb_strlen($semester_aktuell)>$maxlength[$i])
- $maxlength[$i] = mb_strlen($semester_aktuell);
- $worksheet->write($zeile,$i, $semester_aktuell);
- }
- $i++;
-
- //Verband
- if(isset($verband))
- {
- if(mb_strlen($verband)>$maxlength[$i])
- $maxlength[$i] = mb_strlen($verband);
- $worksheet->write($zeile,$i, $verband);
- }
- $i++;
-
- //Gruppe
- if(isset($gruppe))
- {
- if(mb_strlen($gruppe)>$maxlength[$i])
- $maxlength[$i] = mb_strlen($gruppe);
- $worksheet->write($zeile,$i, $gruppe);
- }
- $i++;
-
- //ZGV
- if($row->zgv_code!='' && isset($zgv_arr[$row->zgv_code]))
- {
- if(mb_strlen($zgv_arr[$row->zgv_code])>$maxlength[$i])
- $maxlength[$i] = mb_strlen($zgv_arr[$row->zgv_code]);
- $worksheet->write($zeile,$i, $zgv_arr[$row->zgv_code]);
- }
- $i++;
-
- //ZGV Ort
- if(mb_strlen($row->zgvort)>$maxlength[$i])
- $maxlength[$i] = mb_strlen($row->zgvort);
- $worksheet->write($zeile,$i, $row->zgvort);
- $i++;
-
- //ZGV Datum
- if(mb_strlen($row->zgvdatum)>$maxlength[$i])
- $maxlength[$i] = mb_strlen($row->zgvdatum);
- $worksheet->write($zeile,$i, $row->zgvdatum);
- $i++;
-
- //ZGV Master
- if($row->zgvmas_code!='' && isset($zgvmas_arr[$row->zgvmas_code]))
- {
- if(mb_strlen($zgvmas_arr[$row->zgvmas_code])>$maxlength[$i])
- $maxlength[$i] = mb_strlen($zgvmas_arr[$row->zgvmas_code]);
- $worksheet->write($zeile,$i, $zgvmas_arr[$row->zgvmas_code]);
- }
- $i++;
-
- //ZGV Master Ort
- if(mb_strlen($row->zgvmaort)>$maxlength[$i])
- $maxlength[$i] = mb_strlen($row->zgvmaort);
- $worksheet->write($zeile,$i, $row->zgvmaort);
- $i++;
-
- //ZGV Master Datum
- if(mb_strlen($row->zgvmadatum)>$maxlength[$i])
- $maxlength[$i] = mb_strlen($row->zgvmadatum);
- $worksheet->write($zeile,$i, $row->zgvmadatum);
- $i++;
-
- //Status
- if(mb_strlen($status)>$maxlength[$i])
- $maxlength[$i] = mb_strlen($status);
- $worksheet->write($zeile,$i, $status);
- $i++;
-
- //Stati in anderen Studiengaengen
- $stati='';
- $qry_1 = "SELECT UPPER(typ::varchar(1) || kurzbz) as stg, get_rolle_prestudent(prestudent_id, null) as status FROM
- public.tbl_prestudent JOIN public.tbl_studiengang USING(studiengang_kz)
- WHERE person_id='".addslashes($row->person_id)."' AND tbl_prestudent.studiengang_kz<>'".addslashes($row->prestgkz)."'";
-
- if($db->db_query($qry_1))
- {
- while($row_1 = $db->db_fetch_object())
- {
- if($stati!='')
- $stati.=', ';
- $stati.= $row_1->status.' ('.$row_1->stg.')';
- }
- }
- if(mb_strlen($stati)>$maxlength[$i])
- $maxlength[$i] = mb_strlen($stati);
- $worksheet->write($zeile,$i, $stati);
- $i++;
-
- //Email Intern
- if(isset($row->student_uid))
- {
- if(mb_strlen($row->student_uid.'@'.DOMAIN)>$maxlength[$i])
- $maxlength[$i] = mb_strlen($row->student_uid.'@'.DOMAIN);
- $worksheet->write($zeile,$i, $row->student_uid.'@'.DOMAIN);
- }
- $i++;
-
- //Telefon
- $qry_1 = "SELECT kontakt FROM public.tbl_kontakt
- WHERE kontakttyp in('mobil','telefon','so.tel') AND person_id='".addslashes($row->person_id)."' AND zustellung=true LIMIT 1";
- if($db->db_query($qry_1))
- {
- if($row_1 = $db->db_fetch_object())
- {
- if(mb_strlen($row_1->kontakt)>$maxlength[$i])
- $maxlength[$i]=mb_strlen($row_1->kontakt);
- $worksheet->writeString($zeile,$i, $row_1->kontakt);
- }
- }
- $i++;
-
- //Spezialgruppen
- $grps='';
- $qry_1 = "SELECT gruppe_kurzbz FROM public.tbl_student JOIN public.tbl_benutzergruppe ON (student_uid=uid)
- WHERE tbl_student.prestudent_id='".addslashes($row->prestudent_id)."'
- AND tbl_benutzergruppe.studiensemester_kurzbz='".addslashes($studiensemester_kurzbz)."'";
- if($db->db_query($qry_1))
- {
- while($row_1 = $db->db_fetch_object())
- {
- if($grps!='')
- $grps.=',';
-
- $grps.=$row_1->gruppe_kurzbz;
- }
- }
- if(mb_strlen($grps)>$maxlength[$i])
- $maxlength[$i]=mb_strlen($grps);
- $worksheet->write($zeile,$i, $grps);
- $i++;
-
- //UID
- if(isset($row->student_uid))
- {
- if(mb_strlen($row->student_uid)>$maxlength[$i])
- $maxlength[$i] = mb_strlen($row->student_uid);
- $worksheet->write($zeile,$i, $row->student_uid);
- }
- $i++;
-
- //Orgform
- if(mb_strlen($orgform)>$maxlength[$i])
- $maxlength[$i] = mb_strlen($orgform);
- $worksheet->write($zeile,$i, $orgform);
- $i++;
-
- //Vornamen
- if(mb_strlen($row->vornamen)>$maxlength[$i])
- $maxlength[$i] = mb_strlen($row->vornamen);
- $worksheet->write($zeile,$i, $row->vornamen);
- $i++;
-
-
- //RT_Punkte1
- if(mb_strlen($row->rt_punkte1)>$maxlength[$i])
- $maxlength[$i] = mb_strlen($row->rt_punkte1);
- $worksheet->write($zeile,$i, $row->rt_punkte1);
- $i++;
-
- //RT_Punkte2
- if(mb_strlen($row->rt_punkte2)>$maxlength[$i])
- $maxlength[$i] = mb_strlen($row->rt_punkte2);
- $worksheet->write($zeile,$i, $row->rt_punkte2);
- $i++;
-
- //RT_Gesamtpunkte
- if(mb_strlen($row->rt_gesamtpunkte)>$maxlength[$i])
- $maxlength[$i] = mb_strlen($row->rt_gesamtpunkte);
- $worksheet->write($zeile,$i, $row->rt_gesamtpunkte);
- $i++;
}
+ $i++;
+
+ //Spezialgruppen
+ $grps='';
+ $qry_1 = "SELECT gruppe_kurzbz FROM public.tbl_student JOIN public.tbl_benutzergruppe ON (student_uid=uid)
+ WHERE tbl_student.prestudent_id='".addslashes($row->prestudent_id)."'
+ AND tbl_benutzergruppe.studiensemester_kurzbz='".addslashes($studiensemester_kurzbz)."'";
+ if ($db->db_query($qry_1))
+ {
+ while($row_1 = $db->db_fetch_object())
+ {
+ if ($grps!='')
+ $grps.=',';
+
+ $grps.=$row_1->gruppe_kurzbz;
+ }
+ }
+ if (mb_strlen($grps) > $maxlength[$i])
+ $maxlength[$i] = mb_strlen($grps);
+ $worksheet->write($zeile, $i, $grps);
+ $i++;
+
+ //UID
+ if (isset($row->student_uid))
+ {
+ if (mb_strlen($row->student_uid) > $maxlength[$i])
+ $maxlength[$i] = mb_strlen($row->student_uid);
+ $worksheet->write($zeile, $i, $row->student_uid);
+ }
+ $i++;
+
+ //Orgform
+ if (mb_strlen($orgform) > $maxlength[$i])
+ $maxlength[$i] = mb_strlen($orgform);
+ $worksheet->write($zeile, $i, $orgform);
+ $i++;
+
+ //Vornamen
+ if (mb_strlen($row->vornamen) > $maxlength[$i])
+ $maxlength[$i] = mb_strlen($row->vornamen);
+ $worksheet->write($zeile, $i, $row->vornamen);
+ $i++;
+
+
+ //RT_Punkte1
+ if (mb_strlen($row->rt_punkte1) > $maxlength[$i])
+ $maxlength[$i] = mb_strlen($row->rt_punkte1);
+ $worksheet->write($zeile, $i, $row->rt_punkte1);
+ $i++;
+
+ //RT_Punkte2
+ if (mb_strlen($row->rt_punkte2) > $maxlength[$i])
+ $maxlength[$i] = mb_strlen($row->rt_punkte2);
+ $worksheet->write($zeile, $i, $row->rt_punkte2);
+ $i++;
+
+ //RT_Gesamtpunkte
+ if (mb_strlen($row->rt_gesamtpunkte) > $maxlength[$i])
+ $maxlength[$i] = mb_strlen($row->rt_gesamtpunkte);
+ $worksheet->write($zeile, $i, $row->rt_gesamtpunkte);
+ $i++;
+
+ // UDF
+ if (isset($row->p_udf_values))
+ {
+ $udfPerson = json_decode($row->p_udf_values);
+ if (is_object($udfPerson)) $udfPerson = (array)$udfPerson;
+ foreach($udfTitlesPerson as $udfTitle)
+ {
+ if (isset($udfPerson[$udfTitle['name']]))
+ {
+ if (is_string($udfPerson[$udfTitle['name']]) || is_numeric($udfPerson[$udfTitle['name']]))
+ {
+ if (mb_strlen($udfPerson[$udfTitle['name']]) > $maxlength[$i])
+ {
+ $maxlength[$i] = mb_strlen($udfPerson[$udfTitle['name']]);
+ }
+ $worksheet->write($zeile, $i, $udfPerson[$udfTitle['name']]);
+ }
+ else if(is_array($udfPerson[$udfTitle['name']]) && isset($udfTitle['enum']))
+ {
+ $toWrite = $udf->dropdownListValuesToString($udfPerson[$udfTitle['name']], $udfTitle['enum']);
+
+ if (mb_strlen($toWrite) > $maxlength[$i])
+ {
+ $maxlength[$i] = mb_strlen($toWrite);
+ }
+ $worksheet->write($zeile, $i, $toWrite);
+ }
+ }
+ $i++;
+ }
+ }
+
+ if (isset($row->ps_udf_values))
+ {
+ $udfPrestudent = json_decode($row->ps_udf_values);
+ if (is_object($udfPrestudent)) $udfPrestudent = (array)$udfPrestudent;
+
+ foreach($udfTitlesPrestudent as $udfTitle)
+ {
+ if (isset($udfPrestudent[$udfTitle['name']]))
+ {
+ if (is_string($udfPrestudent[$udfTitle['name']]) || is_numeric($udfPrestudent[$udfTitle['name']]))
+ {
+ if (mb_strlen($udfPrestudent[$udfTitle['name']]) > $maxlength[$i])
+ {
+ $maxlength[$i] = mb_strlen($udfPrestudent[$udfTitle['name']]);
+ }
+ $worksheet->write($zeile, $i, $udfPrestudent[$udfTitle['name']]);
+ }
+ else if(is_array($udfPrestudent[$udfTitle['name']]) && isset($udfTitle['enum']))
+ {
+ $toWrite = $udf->dropdownListValuesToString($udfPrestudent[$udfTitle['name']], $udfTitle['enum']);
+
+ if (mb_strlen($toWrite) > $maxlength[$i])
+ {
+ $maxlength[$i] = mb_strlen($toWrite);
+ }
+ $worksheet->write($zeile, $i, $toWrite);
+ }
+ }
+ $i++;
+ }
+ }
+}
- //Die Breite der Spalten setzen
- foreach($maxlength as $i=>$breite)
- $worksheet->setColumn($i, $i, $breite+2);
-
- $workbook->close();
+// Die Breite der Spalten setzen
+foreach($maxlength as $i => $breite)
+ $worksheet->setColumn($i, $i, $breite + 2);
-?>
+$workbook->close();
+
+?>
\ No newline at end of file
diff --git a/content/student/studentenoverlay.xul.php b/content/student/studentenoverlay.xul.php
index 0ef95958e..a68743814 100644
--- a/content/student/studentenoverlay.xul.php
+++ b/content/student/studentenoverlay.xul.php
@@ -484,6 +484,11 @@ else
if(!defined('FAS_MESSAGES') || FAS_MESSAGES==true)
echo ' ';
?>
+
+ ';
+ ?>
@@ -516,9 +521,13 @@ else
?>
';
+ if(!defined('FAS_MESSAGES') || FAS_MESSAGES==true)
+ echo '';
+
+ if (!defined('FAS_UDF') || FAS_UDF == true)
+ echo '';
?>
+
diff --git a/content/student/studentoverlay.js.php b/content/student/studentoverlay.js.php
index 43da64aa8..e8e7ee608 100644
--- a/content/student/studentoverlay.js.php
+++ b/content/student/studentoverlay.js.php
@@ -1539,6 +1539,12 @@ function StudentAuswahl()
{
document.getElementById('student-messages').setAttribute('src','messages.xul.php?person_id='+person_id);
}
+
+ // ***** UDF *****
+ if (document.getElementById('student-content-tabs').selectedItem == document.getElementById('student-tab-udf'))
+ {
+ document.getElementById('student-udf').setAttribute('src', 'udf.xul.php?person_id='+person_id+'&prestudent_id='+prestudent_id);
+ }
// Notizen laden
var studentnotiz = document.getElementById('student-box-notizen');
@@ -2172,7 +2178,7 @@ function StudentExport()
}
stsem = getStudiensemester();
- action = 'content/statistik/studentenexport.xls.php?studiensemester_kurzbz='+stsem;
+ action = 'content/statistik/studentenexportextended.xls.php?studiensemester_kurzbz='+stsem;
OpenWindowPost(action, data);
}
@@ -5432,6 +5438,27 @@ function StudentMessagesIFrameLoad()
}
}
+// ****
+// * Load UDF IFrame
+// ****
+function StudentUDFIFrameLoad()
+{
+ var tree = document.getElementById('student-tree');
+
+ if (tree.currentIndex == -1) return;
+
+ try
+ {
+ //Ausgewaehlte person_id holen
+ var person_id = getTreeCellText(tree, 'student-treecol-person_id', tree.currentIndex);
+ var prestudent_id = getTreeCellText(tree, 'student-treecol-prestudent_id', tree.currentIndex);
+
+ url = 'udf.xul.php?person_id='+person_id+'&prestudent_id='+prestudent_id;
+ document.getElementById('student-udf').setAttribute('src', url);
+ }
+ catch(e) {}
+}
+
// ****
// * Laedt den Anwesenheit IFrame
// ****
diff --git a/content/udf.js.php b/content/udf.js.php
new file mode 100644
index 000000000..2415476ae
--- /dev/null
+++ b/content/udf.js.php
@@ -0,0 +1,37 @@
+
+ */
+require_once('../config/vilesci.config.inc.php');
+?>
+// ********** FUNKTIONEN ********** //
+
+// ****
+// * Laedt die Trees
+// ****
+function loadUDF(person_id, prestudent_id)
+{
+ netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
+
+ var udfIFrame = document.getElementById('udfIFrame');
+
+ if (udfIFrame != null && udfIFrame.getAttribute('src') == 'about:blank')
+ {
+ udfIFrame.setAttribute('src', 'index.ci.php/system/UDF?person_id='+person_id+'&prestudent_id='+prestudent_id);
+ }
+}
\ No newline at end of file
diff --git a/content/udf.xul.php b/content/udf.xul.php
new file mode 100644
index 000000000..fec6eb1d9
--- /dev/null
+++ b/content/udf.xul.php
@@ -0,0 +1,72 @@
+
+ */
+header("Cache-Control: no-cache");
+header("Cache-Control: post-check=0, pre-check=0",false);
+header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
+header("Pragma: no-cache");
+header("Content-type: application/vnd.mozilla.xul+xml");
+
+require_once('../config/vilesci.config.inc.php');
+require_once('../include/functions.inc.php');
+require_once('../include/variable.class.php');
+require_once('../include/benutzer.class.php');
+
+$user=get_uid();
+$variable = new variable();
+if(!$variable->loadVariables($user))
+{
+ die('Fehler beim Laden der Variablen:'.$variable->errormsg);
+}
+
+$benutzer = new benutzer();
+$benutzer->load($user);
+
+echo ''."\n";
+
+echo '';
+echo '';
+echo '';
+
+$person_id = filter_input(INPUT_GET, 'person_id');
+$prestudent_id= filter_input(INPUT_GET, 'prestudent_id');
+
+echo '
+variable->locale.'/fas.dtd');
+echo ']>
+';
+?>
+
+);"
+ >
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/include/mitarbeiter.class.php b/include/mitarbeiter.class.php
index 3f1e3ca4f..77fbc5702 100644
--- a/include/mitarbeiter.class.php
+++ b/include/mitarbeiter.class.php
@@ -22,6 +22,7 @@
require_once(dirname(__FILE__).'/person.class.php');
require_once(dirname(__FILE__).'/benutzer.class.php');
require_once(dirname(__FILE__).'/functions.inc.php');
+require_once(dirname(__FILE__).'/udf.class.php');
class mitarbeiter extends benutzer
{
@@ -644,8 +645,27 @@ class mitarbeiter extends benutzer
*/
public function getPersonal($fix, $stgl, $fbl, $aktiv, $karenziert, $verwendung, $vertrag=null)
{
- $qry = "SELECT distinct on(mitarbeiter_uid) *, tbl_benutzer.aktiv as aktiv, tbl_mitarbeiter.insertamum, tbl_mitarbeiter.insertvon, tbl_mitarbeiter.updateamum, tbl_mitarbeiter.updatevon FROM ((public.tbl_mitarbeiter JOIN public.tbl_benutzer ON(mitarbeiter_uid=uid)) JOIN public.tbl_person USING(person_id)) LEFT JOIN public.tbl_benutzerfunktion USING(uid) LEFT JOIN campus.tbl_resturlaub USING(mitarbeiter_uid) WHERE true";
-
+ $hasUDF = false;
+ $udf = new UDF();
+
+ $qry = "SELECT DISTINCT ON(mitarbeiter_uid) *,
+ tbl_benutzer.aktiv as aktiv,
+ tbl_mitarbeiter.insertamum,
+ tbl_mitarbeiter.insertvon,
+ tbl_mitarbeiter.updateamum,
+ tbl_mitarbeiter.updatevon";
+
+ if ($hasUDF = $udf->personHasUDF())
+ {
+ $qry .= ", public.tbl_person.udf_values AS p_udf_values";
+ }
+
+ $qry .= " FROM ((public.tbl_mitarbeiter JOIN public.tbl_benutzer ON(mitarbeiter_uid=uid))
+ JOIN public.tbl_person USING(person_id))
+ LEFT JOIN public.tbl_benutzerfunktion USING(uid)
+ LEFT JOIN campus.tbl_resturlaub USING(mitarbeiter_uid)
+ WHERE true";
+
if($fix=='true')
$qry .= " AND fixangestellt=true";
if($fix=='false')
@@ -769,6 +789,11 @@ class mitarbeiter extends benutzer
$obj->urlaubstageprojahr = $row->urlaubstageprojahr;
$obj->resturlaubstage = $row->resturlaubstage;
+ if ($hasUDF)
+ {
+ $obj->p_udf_values = $row->p_udf_values;
+ }
+
$this->result[] = $obj;
}
return true;
diff --git a/include/udf.class.php b/include/udf.class.php
new file mode 100644
index 000000000..fff3e31f0
--- /dev/null
+++ b/include/udf.class.php
@@ -0,0 +1,349 @@
+
+ */
+
+require_once(dirname(__FILE__).'/basis_db.class.php');
+require_once(dirname(__FILE__).'/../config/global.config.inc.php');
+
+/**
+ * Used to export UDF in MS Excel format
+ */
+class UDF extends basis_db
+{
+ /**
+ * Construct
+ */
+ public function __construct()
+ {
+ parent::__construct();
+ }
+
+ /**
+ * Gets the titles (short description) of the UDF related to the table tbl_person
+ */
+ public function getTitlesPerson()
+ {
+ return $this->_loadTitles($this->_getUDFDefinition($this->loadPersonJsons()));
+ }
+
+ /**
+ * Gets the titles (short description) of the UDF related to the table tbl_prestudent
+ */
+ public function getTitlesPrestudent()
+ {
+ return $this->_loadTitles($this->_getUDFDefinition($this->loadPrestudentJsons()));
+ }
+
+ /**
+ * Loads the UDF definitions related to the table tbl_person
+ */
+ public function loadPersonJsons()
+ {
+ $jsons = null;
+
+ if ($this->existsUDF() && $this->prestudentHasUDF())
+ {
+ $jsons = $this->_loadJsons('public', 'tbl_person');
+ }
+
+ return $jsons;
+ }
+
+ /**
+ * Loads the UDF definitions related to the table tbl_prestudent
+ */
+ public function loadPrestudentJsons()
+ {
+ $jsons = null;
+
+ if ($this->existsUDF() && $this->prestudentHasUDF())
+ {
+ $jsons = $this->_loadJsons('public', 'tbl_prestudent');
+ }
+
+ return $jsons;
+ }
+
+ /**
+ * Checks if the table system.tbl_udf exists
+ */
+ public function existsUDF()
+ {
+ $existsUDF = false;
+
+ $query = 'SELECT COUNT(*) AS count
+ FROM information_schema.columns
+ WHERE table_schema = \'system\'
+ AND table_name = \'tbl_udf\'';
+
+ if (!$this->db_query($query))
+ {
+ $this->errormsg = 'Error!!!';
+ }
+ else
+ {
+ if ($row = $this->db_fetch_object())
+ {
+ if (isset($row->count) && $row->count > 0)
+ {
+ $existsUDF = true;
+ }
+ }
+ }
+
+ return $existsUDF;
+ }
+
+ /**
+ * Checks if the column udf_values exists in table tbl_person
+ */
+ public function personHasUDF()
+ {
+ $personHasUDF = false;
+
+ $query = 'SELECT COUNT(*) AS count
+ FROM information_schema.columns
+ WHERE table_schema = \'public\'
+ AND table_name = \'tbl_person\'
+ AND column_name = \'udf_values\'';
+
+ if (!$this->db_query($query))
+ {
+ $this->errormsg = 'Error!!!';
+ }
+ else
+ {
+ if ($row = $this->db_fetch_object())
+ {
+ if (isset($row->count) && $row->count > 0)
+ {
+ $personHasUDF = true;
+ }
+ }
+ }
+
+ return $personHasUDF;
+ }
+
+ /**
+ * Checks if the column udf_values exists in table tbl_prestudent
+ */
+ public function prestudentHasUDF()
+ {
+ $prestudentHasUDF = false;
+
+ $query = 'SELECT COUNT(*) AS count
+ FROM information_schema.columns
+ WHERE table_schema = \'public\'
+ AND table_name = \'tbl_prestudent\'
+ AND column_name = \'udf_values\'';
+
+ if (!$this->db_query($query))
+ {
+ $this->errormsg = 'Error!!!';
+ }
+ else
+ {
+ if ($row = $this->db_fetch_object())
+ {
+ if (isset($row->count) && $row->count > 0)
+ {
+ $prestudentHasUDF = true;
+ }
+ }
+ }
+
+ return $prestudentHasUDF;
+ }
+
+ /**
+ * Concatenates a list of values of a dropdown element to a string
+ */
+ public function dropdownListValuesToString($listValues, $enum)
+ {
+ $toWrite = '';
+
+ foreach ($listValues as $value)
+ {
+ foreach ($enum as $element)
+ {
+ if (is_object($element))
+ {
+ if ($element->id == $value)
+ {
+ $toWrite .= $element->description;
+ break;
+ }
+ }
+ else if (is_array($element))
+ {
+ if ($element[0] == $value)
+ {
+ $toWrite .= $element[1];
+ break;
+ }
+ }
+ else if ($element == $value)
+ {
+ $toWrite .= $element;
+ break;
+ }
+ }
+ $toWrite .= ' ';
+ }
+
+ return $toWrite;
+ }
+
+ /**
+ * Loads the UDF definitions related to the given schema and table
+ */
+ private function _loadJsons($schema, $table)
+ {
+ $jsons = null;
+ $query = 'SELECT jsons FROM system.tbl_udf WHERE schema = \''.$schema.'\' AND "table" = \''.$table.'\'';
+
+ if (!$this->db_query($query))
+ {
+ $this->errormsg = 'Error occurred while loading jsons';
+ }
+ else
+ {
+ if ($row = $this->db_fetch_object())
+ {
+ $jsons = $row->jsons;
+ }
+ }
+
+ return $jsons;
+ }
+
+ /**
+ * Sorts the UDF definitions using the proprierty "sort"
+ */
+ private function _sortJsonSchemas(&$jsonSchemasArray)
+ {
+ usort($jsonSchemasArray, function ($a, $b) {
+ //
+ if (!isset($a->sort))
+ {
+ $a->sort = 9999;
+ }
+ if (!isset($b->sort))
+ {
+ $b->sort = 9999;
+ }
+
+ if ($a->sort == $b->sort)
+ {
+ return 0;
+ }
+
+ return ($a->sort < $b->sort) ? -1 : 1;
+ });
+ }
+
+ /**
+ * Returns an array of associative arrays that contains the couple name and title related to an UDF
+ * These data are retrived from the UDF definitions given as parameter
+ */
+ private function _getUDFDefinition($jsons)
+ {
+ $names = array();
+
+ if ($jsons != null && ($jsonsDecoded = json_decode($jsons)) != null)
+ {
+ if (is_object($jsonsDecoded) || is_array($jsonsDecoded))
+ {
+ if (is_object($jsonsDecoded))
+ {
+ $jsonsDecoded = array($jsonsDecoded);
+ }
+
+ $this->_sortJsonSchemas($jsonsDecoded);
+
+ foreach($jsonsDecoded as $udfJsonShema)
+ {
+ if (isset($udfJsonShema->name) && isset($udfJsonShema->title))
+ {
+ $tmpArray = array('name' => $udfJsonShema->name, 'title' => $udfJsonShema->title);
+
+ if (isset($udfJsonShema->type)
+ && ($udfJsonShema->type == 'dropdown' || $udfJsonShema->type == 'multipledropdown')
+ && isset($udfJsonShema->listValues) && isset($udfJsonShema->listValues->enum))
+ {
+ $tmpArray['enum'] = $udfJsonShema->listValues->enum;
+ }
+
+ $names[] = $tmpArray;
+ }
+ }
+ }
+ }
+
+ return $names;
+ }
+
+ /**
+ * Loads UDf titles from phrases
+ */
+ private function _loadTitles($udfDefinitions)
+ {
+ $titles = array();
+ $in = '';
+
+ for($i = 0; $i < count($udfDefinitions); $i++)
+ {
+ $udfDefinition = $udfDefinitions[$i];
+ $in .= '\''.$udfDefinition['title'].'\'';
+
+ if ($i < count($udfDefinitions) - 1) $in .= ', ';
+ }
+
+ if ($in != '')
+ {
+ $query = 'SELECT pt.text AS title, p.phrase AS phrase
+ FROM system.tbl_phrase p INNER JOIN system.tbl_phrasentext pt USING(phrase_id)
+ WHERE pt.sprache = \''.DEFAULT_LEHREINHEIT_SPRACHE.'\'
+ AND p.phrase IN ('.$in.')';
+
+ if (!$this->db_query($query))
+ {
+ $this->errormsg = 'Error occurred while loading jsons';
+ }
+ else
+ {
+ while ($row = $this->db_fetch_assoc())
+ {
+ for($i = 0; $i < count($udfDefinitions); $i++)
+ {
+ $udfDefinition = $udfDefinitions[$i];
+ if ($udfDefinition['title'] == $row['phrase'])
+ {
+ $udfDefinition['description'] = $row['title'];
+ $titles[] = $udfDefinition;
+ }
+ }
+ }
+ }
+ }
+
+ return $titles;
+ }
+}
\ No newline at end of file
diff --git a/skin/widgets.css b/skin/widgets.css
new file mode 100644
index 000000000..636094fc3
--- /dev/null
+++ b/skin/widgets.css
@@ -0,0 +1,42 @@
+.div-table {
+ display: table;
+}
+
+.div-row {
+ display: table-row;
+}
+
+.div-cell {
+ display: table-cell;
+}
+
+.div-cell-label {
+ display: table-cell;
+}
+
+.div-cell-data {
+ display: table-cell;
+}
+
+.halign-right {
+ text-align: right;
+ margin-left: auto;
+ margin-right: 0;
+}
+
+.valign-middle {
+ vertical-align: middle;
+}
+
+.valign-top {
+ vertical-align: top;
+ padding-top: 1px;
+}
+
+.width-150px {
+ width: 150px;
+}
+
+.width-30px {
+ width: 30px;
+}
\ No newline at end of file
diff --git a/system/dbupdate_3.3.php b/system/dbupdate_3.3.php
index d2ec00b67..b87901e73 100644
--- a/system/dbupdate_3.3.php
+++ b/system/dbupdate_3.3.php
@@ -268,6 +268,86 @@ if($result = $db->db_query("SELECT view_definition FROM information_schema.views
}
}
+// Creates table system.tbl_udf if it doesn't exist and grants privileges
+if(!$result = @$db->db_query("SELECT 1 FROM system.tbl_udf LIMIT 1"))
+{
+ $qry = '
+ CREATE TABLE system.tbl_udf (
+ "schema" VARCHAR(32) NOT NULL,
+ "table" VARCHAR(128) NOT NULL,
+ "jsons" JSONB NOT NULL,
+ CONSTRAINT tbl_udf_pkey PRIMARY KEY("schema", "table")
+ );';
+ if(!$db->db_query($qry))
+ echo 'system.tbl_udf: '.$db->db_last_error().' ';
+ else
+ echo ' system.tbl_udf table created';
+
+ $qry = 'COMMENT ON COLUMN system.tbl_udf.schema IS \'Schema of the table\';';
+ if(!$db->db_query($qry))
+ echo 'Adding comment to system.tbl_udf.schema: '.$db->db_last_error().' ';
+ else
+ echo ' Added comment to system.tbl_udf.schema';
+
+ $qry = 'COMMENT ON COLUMN system.tbl_udf.table IS \'Table name\';';
+ if(!$db->db_query($qry))
+ echo 'Adding comment to system.tbl_udf.table: '.$db->db_last_error().' ';
+ else
+ echo ' Added comment to system.tbl_udf.table';
+
+ $qry = 'COMMENT ON COLUMN system.tbl_udf.jsons IS \'JSON schema\';';
+ if(!$db->db_query($qry))
+ echo 'Adding comment to system.tbl_udf.jsons: '.$db->db_last_error().' ';
+ else
+ echo ' Added comment to system.tbl_udf.jsons';
+
+ $qry = 'GRANT SELECT ON TABLE system.tbl_udf TO web;';
+ if(!$db->db_query($qry))
+ echo 'system.tbl_udf: '.$db->db_last_error().' ';
+ else
+ echo ' Granted privileges to web on system.tbl_udf';
+
+ $qry = 'GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE system.tbl_udf TO vilesci;';
+ if(!$db->db_query($qry))
+ echo 'system.tbl_udf: '.$db->db_last_error().' ';
+ else
+ echo ' Granted privileges to vilesci on system.tbl_udf';
+}
+
+// Add column udf_values to public.tbl_person
+if(!$result = @$db->db_query("SELECT udf_values FROM public.tbl_person LIMIT 1"))
+{
+ $qry = 'ALTER TABLE public.tbl_person ADD COLUMN udf_values JSONB;';
+ if(!$db->db_query($qry))
+ echo 'public.tbl_person: '.$db->db_last_error().' ';
+ else
+ echo ' Added column udf_values to table public.tbl_person';
+}
+
+// Add column udf_values to public.tbl_prestudent
+if(!$result = @$db->db_query("SELECT udf_values FROM public.tbl_prestudent LIMIT 1"))
+{
+ $qry = 'ALTER TABLE public.tbl_prestudent ADD COLUMN udf_values JSONB;';
+ if(!$db->db_query($qry))
+ echo 'public.tbl_prestudent: '.$db->db_last_error().' ';
+ else
+ echo ' Added column udf_values to table public.tbl_prestudent';
+}
+
+// Add permission for UDF
+if($result = @$db->db_query("SELECT 1 FROM system.tbl_berechtigung WHERE berechtigung_kurzbz = 'system/udf';"))
+{
+ if($db->db_num_rows($result) == 0)
+ {
+ $qry = "INSERT INTO system.tbl_berechtigung(berechtigung_kurzbz, beschreibung) VALUES('system/udf', 'UDF');";
+
+ if(!$db->db_query($qry))
+ echo 'system.tbl_berechtigung '.$db->db_last_error().' ';
+ else
+ echo ' system.tbl_berechtigung: Added permission for UDF ';
+ }
+}
+
// Spalten mailversand,teilnehmer_anonym,termine_anonym in campus.tbl_coodle
if(!$result = @$db->db_query("SELECT mailversand FROM campus.tbl_coodle LIMIT 1;"))
{
@@ -548,6 +628,7 @@ $tabellen=array(
"system.tbl_webservicerecht" => array("webservicerecht_id","berechtigung_kurzbz","methode","attribut","insertamum","insertvon","updateamum","updatevon","klasse"),
"system.tbl_webservicetyp" => array("webservicetyp_kurzbz","beschreibung"),
"system.tbl_server" => array("server_kurzbz","beschreibung"),
+ "system.tbl_udf" => array("schema", "tbl_udf.table", "jsons"),
"wawi.tbl_betriebsmittelperson" => array("betriebsmittelperson_id","betriebsmittel_id","person_id", "anmerkung", "kaution", "ausgegebenam", "retouram","insertamum", "insertvon","updateamum", "updatevon","ext_id","uid"),
"wawi.tbl_betriebsmittel" => array("betriebsmittel_id","betriebsmitteltyp","oe_kurzbz", "ort_kurzbz", "beschreibung", "nummer", "hersteller","seriennummer", "bestellung_id","bestelldetail_id", "afa","verwendung","anmerkung","reservieren","updateamum","updatevon","insertamum","insertvon","ext_id","inventarnummer","leasing_bis","inventuramum","inventurvon","anschaffungsdatum","anschaffungswert","hoehe","breite","tiefe","nummer2","verplanen"),
"wawi.tbl_betriebsmittel_betriebsmittelstatus" => array("betriebsmittelbetriebsmittelstatus_id","betriebsmittel_id","betriebsmittelstatus_kurzbz", "datum", "updateamum", "updatevon", "insertamum", "insertvon","anmerkung"),
@@ -629,5 +710,4 @@ if (!$result=@$db->db_query($sql_query))
}
if($error==false)
echo ' Gegenpruefung fehlerfrei';
-
-?>
+?>
\ No newline at end of file