This commit is contained in:
kindlm
2017-08-16 15:00:13 +02:00
45 changed files with 4521 additions and 1989 deletions
+11 -2
View File
@@ -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
+1
View File
@@ -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',
+71
View File
@@ -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"]
}
@@ -107,4 +107,29 @@ class Studiengang2 extends APIv1_Controller
$this->response();
}
}
/**
* @return void
*/
public function getAppliedStudiengangFromNow()
{
$person_id = $this->get('person_id');
$titel = $this->get('titel');
if (isset($person_id) && isset($titel))
{
$this->load->model('organisation/Studiengang_model', 'StudiengangModel');
$result = $this->StudiengangModel->getAppliedStudiengangFromNow(
$person_id,
$titel
);
$this->response($result, REST_Controller::HTTP_OK);
}
else
{
$this->response();
}
}
}
@@ -0,0 +1,133 @@
<?php
/**
* FH-Complete
*
* @package FHC-API
* @author FHC-Team
* @copyright Copyright (c) 2016, fhcomplete.org
* @license GPLv3
* @link http://fhcomplete.org
* @since Version 1.0
* @filesource
*/
// ------------------------------------------------------------------------
if (!defined('BASEPATH')) exit('No direct script access allowed');
class UDF extends APIv1_Controller
{
/**
* UDF API constructor.
*/
public function __construct()
{
parent::__construct();
// Load model UDF_model
$this->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);
}
}
}
}
+127
View File
@@ -0,0 +1,127 @@
<?php
if (! defined('BASEPATH')) exit('No direct script access allowed');
class UDF extends VileSci_Controller
{
public function __construct()
{
parent::__construct();
// Load session library
$this->load->library('session');
// Loads the UDF library
$this->load->library('UDFLib');
//
$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;
}
}
+482 -32
View File
@@ -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 dont 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,321 @@ 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, $udfValue)
{
$returnArrayValidation = array(); // returned value
// 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
// Loops through the UDFs values that should be stored
foreach ($this->UDFs as $key => $val)
{
$tmpValidate = success(true); // temporary variable used to store the returned value from _validateUDFs
// 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
{
// Checks if the given UDF is required and the result will be stored in $chkRequiredPassed
// If $chkRequiredPassed == true => required check passed
// If $chkRequiredPassed == false => required check NOT passed
$chkRequiredPassed = true;
// If required property is present in the UDF description and it is true
if (isset($decodedUDFDefinition->validation->{DB_Model::UDF_REQUIRED})
&& $decodedUDFDefinition->validation->{DB_Model::UDF_REQUIRED} === true)
{
// If this UDF is a checkbox and the given value is false
// OR
// if this UDF is NOT a checkbox and the given value is null
if (($decodedUDFDefinition->{DB_Model::UDF_TYPE_NAME} == DB_Model::UDF_CHKBOX_TYPE && $val === false)
|| ($decodedUDFDefinition->{DB_Model::UDF_TYPE_NAME} != DB_Model::UDF_CHKBOX_TYPE && $val == null))
{
$chkRequiredPassed = false; // not passed
// A new error is generated and added to array $requiredUDFsArray
$requiredUDFsArray[$decodedUDFDefinition->{DB_Model::UDF_ATTRIBUTE_NAME}] = error(
$decodedUDFDefinition->{DB_Model::UDF_ATTRIBUTE_NAME},
EXIT_VALIDATION_UDF_REQUIRED
);
}
}
// If the previous required check has failed then the validation is not performed
if ($chkRequiredPassed === true)
{
// Checks if the validation should be performed
// If $toBeValidated == true => validation is performed
// If $toBeValidated == false => validation is NOT performed
$toBeValidated = false;
// If this UDF is NOT a checkbox
if ($decodedUDFDefinition->{DB_Model::UDF_TYPE_NAME} != DB_Model::UDF_CHKBOX_TYPE)
{
// If required property is NOT present in the UDF description
if (!isset($decodedUDFDefinition->validation->{DB_Model::UDF_REQUIRED}))
{
$toBeValidated = true;
}
// If required property is present in the UDF description and it is true
if (isset($decodedUDFDefinition->validation->{DB_Model::UDF_REQUIRED})
&& $decodedUDFDefinition->validation->{DB_Model::UDF_REQUIRED} === true)
{
$toBeValidated = true;
}
// If required property is present in the UDF description and it is true and the given value is null
if (isset($decodedUDFDefinition->validation->{DB_Model::UDF_REQUIRED})
&& $decodedUDFDefinition->validation->{DB_Model::UDF_REQUIRED} === false
&& $val != null)
{
$toBeValidated = true;
}
}
if ($toBeValidated === true) // Checks if validation should be performed
{
$tmpValidate = $this->_validateUDFs(
$decodedUDFDefinition->validation, //
$decodedUDFDefinition->{DB_Model::UDF_ATTRIBUTE_NAME}, //
$val //
);
}
}
}
// If validation is ok copy the value that is to be stored into $toBeStoredUDFsArray
if (isSuccess($tmpValidate))
{
$toBeStoredUDFsArray[$key] = $val;
}
else // otherwise store the validation error in $notValidUDFsArray
{
$notValidUDFsArray[] = $tmpValidate;
}
}
}
}
// 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 +1177,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 +1201,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 +1211,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
}
}
}
+64 -3
View File
@@ -1,4 +1,5 @@
<?php
/**
* FH-Complete
*
@@ -10,8 +11,7 @@
* @since Version 1.0.0
* @filesource
*/
if (! defined('BASEPATH'))
exit('No direct script access allowed');
if (! defined('BASEPATH')) exit('No direct script access allowed');
/**
* FHC Helper
@@ -25,7 +25,6 @@ if (! defined('BASEPATH'))
// ------------------------------------------------------------------------
/**
* generateToken() - generates a new token for diffent use
* - reading Messages from external
@@ -75,4 +74,66 @@ function var_dump_to_error_log($parameter)
$ob_get_contents = ob_get_contents();
ob_end_clean();
error_log(str_replace("\n", '', $ob_get_contents));
}
/**
*
*/
function loadResource($path, $resources = null, $subdir = false)
{
$_ci = & get_instance();
//
if (strrpos($path, '/') < strlen($path) - 1)
{
$path .= '/';
}
//
$tmpResources = $resources;
if ($resources == null)
{
$tmpResources = array();
}
else if (!is_array($resources))
{
$tmpResources = array($resources);
}
//
$tmpPaths = array($path);
// NOTE: Used @ to prevent ugly error messages
if (is_dir($path) && ($dirHandler = @opendir($path)) !== false)
{
while (($entry = readdir($dirHandler)) !== false)
{
//
if ($subdir === true && $entry != '.' && $entry != '..' && is_dir($entry))
{
$tmpPaths[] = $entry;
}
//
if ($resources == null && is_file($path.$entry))
{
if ($entry != ($tmpName = str_replace('.php', '', $entry)))
{
$tmpResources[] = $tmpName;
}
}
}
closedir($dirHandler);
}
//
foreach($tmpResources as $tmpResource)
{
foreach($tmpPaths as $tmpPath)
{
$fileName = $tmpPath.$tmpResource.'.php';
if (file_exists($fileName))
{
include_once($fileName);
}
}
}
}
+14 -7
View File
@@ -1,9 +1,16 @@
<?php
if ( ! defined('BASEPATH'))
exit('No direct script access allowed');
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
// DB-Errormessages
$lang['fhc_'.FHC_MODEL_ERROR] = 'Fehler in Model';
$lang['fhc_'.FHC_NODBTABLE] = '"dbTable" ist nicht gesetzt!';
$lang['fhc_'.FHC_NORIGHT] = 'Rechte sind nicht ausreichend!';
$lang['fhc_'.FHC_MODEL_ERROR] = 'Fehler in Model';
$lang['fhc_'.FHC_NODBTABLE] = '"dbTable" ist nicht gesetzt!';
$lang['fhc_'.FHC_NORIGHT] = 'Rechte sind nicht ausreichend!';
$lang['fhc_'.EXIT_VALIDATION_UDF] = 'UDF validation has been failed';
$lang['fhc_'.EXIT_VALIDATION_UDF_MIN_VALUE] = 'UDF validation has been failed - MIN VALUE';
$lang['fhc_'.EXIT_VALIDATION_UDF_MAX_VALUE] = 'UDF validation has been failed - MAX VALUE';
$lang['fhc_'.EXIT_VALIDATION_UDF_MIN_LENGTH] = 'UDF validation has been failed - MIN LENGTH';
$lang['fhc_'.EXIT_VALIDATION_UDF_MAX_LENGTH] = 'UDF validation has been failed - MAX LENGTH';
$lang['fhc_'.EXIT_VALIDATION_UDF_REGEX] = 'UDF validation has been failed - REGEX';
$lang['fhc_'.EXIT_VALIDATION_UDF_REQUIRED] = 'UDF validation has been failed - REQUIRED';
$lang['fhc_'.EXIT_VALIDATION_UDF_NOT_VALID_VAL] = 'UDF validation has been failed - Not valid value, object or array given';
@@ -6,3 +6,11 @@ if ( ! defined('BASEPATH'))
$lang['fhc_'.FHC_MODEL_ERROR] = 'Error in Model';
$lang['fhc_'.FHC_NODBTABLE] = 'dbTable is not set!';
$lang['fhc_'.FHC_NORIGHT] = 'rights are missing!';
$lang['fhc_'.EXIT_VALIDATION_UDF] = 'UDF validation has been failed';
$lang['fhc_'.EXIT_VALIDATION_UDF_MIN_VALUE] = 'UDF validation has been failed - MIN VALUE';
$lang['fhc_'.EXIT_VALIDATION_UDF_MAX_VALUE] = 'UDF validation has been failed - MAX VALUE';
$lang['fhc_'.EXIT_VALIDATION_UDF_MIN_LENGTH] = 'UDF validation has been failed - MIN LENGTH';
$lang['fhc_'.EXIT_VALIDATION_UDF_MAX_LENGTH] = 'UDF validation has been failed - MAX LENGTH';
$lang['fhc_'.EXIT_VALIDATION_UDF_REGEX] = 'UDF validation has been failed - REGEX';
$lang['fhc_'.EXIT_VALIDATION_UDF_REQUIRED] = 'UDF validation has been failed - REQUIRED';
$lang['fhc_'.EXIT_VALIDATION_UDF_NOT_VALID_VAL] = 'UDF validation has been failed - Not valid value, object or array given';
+77
View File
@@ -0,0 +1,77 @@
<?php
if (! defined('BASEPATH')) exit('No direct script access allowed');
/**
* Library to manage UDF
*/
class UDFLib
{
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';
private $_ci;
public function __construct($config = array())
{
$this->_ci = & get_instance();
$this->_ci->load->helper('fhc');
// Loads the widget library
$this->_ci->load->library('WidgetLib');
// Loads widgets to render HTML elements
// NOTE: the first one to be loaded must be HTMLWidget
loadResource(APPPATH . 'widgets/udf');
}
/**
*
*/
public function UDFWidget($args, $htmlArgs = array())
{
if (!empty($args[UDFLib::SCHEMA_ARG_NAME]) && !empty($args[UDFLib::TABLE_ARG_NAME]))
{
//
if (empty($args[UDFLib::FIELD_ARG_NAME]) && !isset($htmlArgs[HTMLWidget::EXTERNAL_BLOCK]))
{
$htmlArgs[HTMLWidget::EXTERNAL_BLOCK] = true;
}
return $this->_ci->widgetlib->widget(
UDFLib::WIDGET_NAME,
$args,
$htmlArgs
);
}
else
{
if (empty($args[UDFLib::SCHEMA_ARG_NAME]))
{
show_error(UDFLib::SCHEMA_ARG_NAME.' parameter is missing!');
}
if (empty($args[UDFLib::TABLE_ARG_NAME]))
{
show_error(UDFLib::TABLE_ARG_NAME.' parameter is missing!');
}
}
}
}
File diff suppressed because it is too large Load Diff
@@ -225,6 +225,57 @@ class Studiengang_model extends DB_Model
return $result;
}
/**
*
*/
public function getAppliedStudiengangFromNow($person_id, $titel)
{
// Then join with table public.tbl_prestudent
$this->addJoin('public.tbl_prestudent', 'studiengang_kz');
// Join table public.tbl_prestudentstatus
$this->addJoin('public.tbl_prestudentstatus', 'prestudent_id');
// Then join with table lehre.tbl_studienplan
$this->addJoin('lehre.tbl_studienplan', 'studienplan_id');
// Then join with table public.tbl_notizzuordnung + public.tbl_notiz
$this->addJoin(
'(
SELECT public.tbl_notiz.*, public.tbl_notizzuordnung.prestudent_id
FROM public.tbl_notiz JOIN public.tbl_notizzuordnung USING(notiz_id)
WHERE titel = '.$this->escape($titel).
') tbl_notiz',
'prestudent_id',
'LEFT'
);
// Ordering by studiengang_kz and studienplan_id
$this->addOrder('public.tbl_studiengang.bezeichnung');
$result = $this->loadTree(
'public.tbl_studiengang',
array(
'public.tbl_prestudent',
'public.tbl_prestudentstatus',
'lehre.tbl_studienplan',
'public.tbl_notiz'
),
'public.tbl_prestudent.person_id = '.$this->escape($person_id).
' AND public.tbl_prestudentstatus.studiensemester_kurzbz IN (
SELECT studiensemester_kurzbz
FROM public.tbl_studiensemester
WHERE ende >= NOW()
)'.
' AND (public.tbl_prestudentstatus.status_kurzbz = \'Interessent\')',
array(
'prestudenten',
'prestudentstatus',
'studienplaene',
'notizen'
)
);
return $result;
}
/**
*
+197
View File
@@ -0,0 +1,197 @@
<?php
class UDF_model extends DB_Model
{
/**
* Constructor
*/
public function __construct()
{
parent::__construct();
$this->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;
}
}
+145
View File
@@ -0,0 +1,145 @@
<?php $this->load->view("templates/header", array("title" => "UDF", "widgetsCSS" => true)); ?>
<body style="background-color: #eff0f1;">
<?php
if ($result != null)
{
if (isSuccess($result))
{
?>
<div style="color: black;">
Saved!
</div>
<br>
<?php
}
else
{
?>
<div style="color: red;">
Error while saving!
</div>
<br>
<div style="color: red;">
<?php
$errors = $result->retval;
foreach ($errors as $error)
{
foreach ($error as $fieldError)
{
echo $fieldError->msg . ' -> ' . $fieldError->retval . '<br>';
}
}
?>
</div>
<br>
<br>
<br>
<?php
}
}
?>
<form action="<?php echo APP_ROOT; ?>index.ci.php/system/UDF/saveUDF" method="POST">
<div class="div-table">
<div class="div-row">
<div class="div-cell" style="font-size: 20px; font-weight: bold;">
Zusatzfelder
</div>
</div>
<div class="div-row">
<div class="div-cell">
&nbsp;
</div>
</div>
<div class="div-row">
<?php
if (isset($personUdfs))
{
?>
<div class="div-cell">
<?php
echo $this->udflib->UDFWidget(
array(
UDFLib::SCHEMA_ARG_NAME => 'public',
UDFLib::TABLE_ARG_NAME => 'tbl_person',
UDFLib::UDFS_ARG_NAME => $personUdfs
)
);
?>
</div>
<div class="div-cell" style="width: 40px;">
&nbsp;
</div>
<?php
}
?>
<?php
if (isset($prestudentUdfs))
{
?>
<div class="div-cell">
<?php
echo $this->udflib->UDFWidget(
array(
UDFLib::SCHEMA_ARG_NAME => 'public',
UDFLib::TABLE_ARG_NAME => 'tbl_prestudent',
UDFLib::UDFS_ARG_NAME => $prestudentUdfs
)
);
?>
</div>
<?php
}
?>
</div>
<div class="div-row">
<div class="div-cell">
&nbsp;
</div>
</div>
<div class="div-row halign-right">
<?php
if (isset($personUdfs) && isset($prestudentUdfs))
{
?>
<div class="div-cell">
&nbsp;
</div>
<div class="div-cell">
&nbsp;
</div>
<?php
}
?>
<div class="div-cell halign-right">
<input type="submit" value="&nbsp;Speichern&nbsp;">
</div>
</div>
</div>
<?php
if (isset($personUdfs))
{
?>
<input type="hidden" name="person_id" value="<?php echo $personUdfs['person_id']; ?>">
<?php
}
?>
<?php
if (isset($prestudentUdfs))
{
?>
<input type="hidden" name="prestudent_id" value="<?php echo $prestudentUdfs['prestudent_id']; ?>">
<?php
}
?>
</form>
</body>
<?php $this->load->view("templates/footer"); ?>
+4
View File
@@ -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)
<link rel="stylesheet" type="text/css" href="<?php echo base_url('vendor/json-forms/dist/css/brutusin-json-forms.min.css'); ?>" />
<script type="text/javascript" src="<?php echo base_url('vendor/json-forms/dist/js/brutusin-json-forms.min.js'); ?>"></script>
<?php endif ?>
<?php if($widgetsCSS) : ?>
<link rel="stylesheet" type="text/css" href="<?php echo base_url('skin/widgets.css'); ?>" />
<?php endif ?>
</head>
+42
View File
@@ -0,0 +1,42 @@
<?php HTMLWidget::printStartBlock(${HTMLWidget::HTML_ARG_NAME}); ?>
<div class="div-table">
<div class="div-row">
<?php
if (isset(${HTMLWidget::HTML_ARG_NAME}[HTMLWidget::LABEL]))
{
?>
<div class="div-cell-label valign-middle width-150px">
<label
for="<?php echo ${HTMLWidget::HTML_ARG_NAME}[HTMLWidget::HTML_ID]; ?>"
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, HTMLWidget::REQUIRED); ?>
>
<?php echo ${HTMLWidget::HTML_ARG_NAME}[HTMLWidget::LABEL]; ?>
</label>
</div>
<?php
}
?>
<div class="div-cell-data width-30px">
<input
type="checkbox"
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, HTMLWidget::HTML_ID); ?>
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, HTMLWidget::HTML_NAME); ?>
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, HTMLWidget::REQUIRED); ?>
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, HTMLWidget::REGEX); ?>
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, HTMLWidget::TITLE); ?>
<?php
$checked = '';
if (${CheckboxWidget::VALUE_FIELD} === true)
{
$checked = 'checked';
}
?>
<?php echo $checked; ?>
value="<?php echo CheckboxWidget::CHECKBOX_VALUE; ?>"
>
</div>
</div>
</div>
<?php HTMLWidget::printEndBlock(${HTMLWidget::HTML_ARG_NAME}); ?>
+74 -14
View File
@@ -1,14 +1,74 @@
<select id="<?php echo ${Widget::HTML_ARG_NAME}[Widget::HTML_ID]; ?>" name="<?php echo ${Widget::HTML_ARG_NAME}[Widget::HTML_NAME]; ?>">
<?php foreach(${DropdownWidget::WIDGET_DATA_ELEMENTS_ARRAY_NAME} as $element): ?>
<?php
$selected = '';
if ($element->{DropdownWidget::ID_FIELD} == ${DropdownWidget::SELECTED_ELEMENT})
{
$selected = 'selected';
}
?>
<option value="<?php echo $element->{DropdownWidget::ID_FIELD}; ?>" <?php echo $selected; ?>>
<?php echo $element->{DropdownWidget::DESCRIPTION_FIELD}; ?>
</option>
<?php endforeach; ?>
</select>
<?php HTMLWidget::printStartBlock(${HTMLWidget::HTML_ARG_NAME}); ?>
<div class="div-table">
<div class="div-row">
<?php
if (isset(${HTMLWidget::HTML_ARG_NAME}[HTMLWidget::LABEL]))
{
$align = "valign-middle";
if (isset(${HTMLWidget::HTML_ARG_NAME}[DropdownWidget::MULTIPLE]))
{
$align = "valign-top";
}
?>
<div class="div-cell width-150px <?php echo $align; ?>">
<label
for="<?php echo ${HTMLWidget::HTML_ARG_NAME}[HTMLWidget::HTML_ID]; ?>"
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, HTMLWidget::REQUIRED); ?>
>
<?php echo ${HTMLWidget::HTML_ARG_NAME}[HTMLWidget::LABEL]; ?>
</label>
</div>
<?php
}
?>
<div class="div-cell width-150px">
<select
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, HTMLWidget::HTML_ID); ?>
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, HTMLWidget::HTML_NAME); ?>
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, DropdownWidget::SIZE); ?>
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, DropdownWidget::MULTIPLE, false); ?>
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, HTMLWidget::REQUIRED); ?>
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, HTMLWidget::MAX_VALUE); ?>
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, HTMLWidget::MIN_VALUE); ?>
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, HTMLWidget::REGEX); ?>
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, HTMLWidget::TITLE); ?>
>
<?php
$elements = ${DropdownWidget::WIDGET_DATA_ELEMENTS_ARRAY_NAME};
$selectedElements = ${DropdownWidget::SELECTED_ELEMENT};
foreach($elements as $element)
{
$selected = '';
if (is_array($selectedElements))
{
foreach($selectedElements as $selectedElement)
{
if ($element->{DropdownWidget::ID_FIELD} == $selectedElement)
{
$selected = 'selected';
}
}
}
else
{
if ($element->{DropdownWidget::ID_FIELD} == $selectedElements)
{
$selected = 'selected';
}
}
?>
<option value="<?php echo $element->{DropdownWidget::ID_FIELD}; ?>" <?php echo $selected; ?>>
<?php echo $element->{DropdownWidget::DESCRIPTION_FIELD}; ?>
</option>
<?php
}
?>
</select>
</div>
</div>
</div>
<?php HTMLWidget::printEndBlock(${HTMLWidget::HTML_ARG_NAME}); ?>
+35
View File
@@ -0,0 +1,35 @@
<?php HTMLWidget::printStartBlock(${HTMLWidget::HTML_ARG_NAME}); ?>
<div class="div-table">
<div class="div-row">
<?php
if (isset(${HTMLWidget::HTML_ARG_NAME}[HTMLWidget::LABEL]))
{
?>
<div class="div-cell width-150px valign-top">
<label
for="<?php echo ${HTMLWidget::HTML_ARG_NAME}[HTMLWidget::HTML_ID]; ?>"
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, HTMLWidget::REQUIRED); ?>
>
<?php echo ${HTMLWidget::HTML_ARG_NAME}[HTMLWidget::LABEL]; ?>
</label>
</div>
<?php
}
?>
<div class="div-cell width-150px">
<textarea
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, HTMLWidget::HTML_ID); ?>
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, HTMLWidget::HTML_NAME); ?>
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, TextareaWidget::ROWS); ?>
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, TextareaWidget::COLS); ?>
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, HTMLWidget::REQUIRED); ?>
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, HTMLWidget::PLACEHOLDER); ?>
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, HTMLWidget::REGEX); ?>
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, HTMLWidget::TITLE); ?>
><?php echo ${TextareaWidget::TEXT}; ?></textarea>
</div>
</div>
</div>
<?php HTMLWidget::printEndBlock(${HTMLWidget::HTML_ARG_NAME}); ?>
+36
View File
@@ -0,0 +1,36 @@
<?php HTMLWidget::printStartBlock(${HTMLWidget::HTML_ARG_NAME}); ?>
<div class="div-table">
<div class="div-row">
<?php
if (isset(${HTMLWidget::HTML_ARG_NAME}[HTMLWidget::LABEL]))
{
?>
<div class="div-cell width-150px valign-middle">
<label
for="<?php echo ${HTMLWidget::HTML_ARG_NAME}[HTMLWidget::HTML_ID]; ?>"
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, HTMLWidget::REQUIRED); ?>
>
<?php echo ${HTMLWidget::HTML_ARG_NAME}[HTMLWidget::LABEL]; ?>
</label>
</div>
<?php
}
?>
<div class="div-cell width-150px">
<input
type="text"
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, HTMLWidget::HTML_ID); ?>
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, HTMLWidget::HTML_NAME); ?>
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, TextfieldWidget::SIZE); ?>
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, HTMLWidget::REQUIRED); ?>
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, HTMLWidget::PLACEHOLDER); ?>
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, HTMLWidget::REGEX); ?>
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, HTMLWidget::TITLE); ?>
value="<?php echo ${TextfieldWidget::VALUE}; ?>"
>
</div>
</div>
</div>
<?php HTMLWidget::printEndBlock(${HTMLWidget::HTML_ARG_NAME}); ?>
+1 -1
View File
@@ -17,6 +17,6 @@ class Studiengang_widget extends DropdownWidget
'No studiengaenge found'
);
$this->loadDropDownView($widgetData);
$this->loadDropDownView();
}
}
@@ -0,0 +1,22 @@
<?php
/**
* It exends the Widget class to represent an HTML dropdown
*/
class CheckboxWidget extends HTMLWidget
{
// 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);
}
}
+157
View File
@@ -0,0 +1,157 @@
<?php
/**
* It exends the Widget class to represent an HTML dropdown
*/
class DropdownWidget extends HTMLWidget
{
// 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[HTMLWidget::HTML_ARG_NAME][DropdownWidget::MULTIPLE] = DropdownWidget::MULTIPLE;
$this->_args[HTMLWidget::HTML_ARG_NAME][HTMLWidget::HTML_NAME] .= '[]';
}
/**
*
*/
public function isMultipleDropdown()
{
$isMultipleDropdown = false;
if (isset($this->_args[HTMLWidget::HTML_ARG_NAME][DropdownWidget::MULTIPLE])
&& $this->_args[HTMLWidget::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);
}
}
+117
View File
@@ -0,0 +1,117 @@
<?php
/**
* Represents a generic HTML element
*/
class HTMLWidget extends Widget
{
// 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 = '<div>'; //
const EXTERNAL_END_BLOCK_HTML_TAG = '</div>'; //
//
const LABEL = 'title';
const REGEX = 'regex';
const TITLE = 'description';
const REQUIRED = 'udf-required';
const MAX_VALUE = 'max-value';
const MIN_VALUE = 'min-value';
const MAX_LENGTH = 'max-length';
const MIN_LENGTH = 'min-length';
const PLACEHOLDER = 'placeholder';
/**
* 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');
}
/**
* 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[HTMLWidget::HTML_ARG_NAME]))
{
$this->_args[HTMLWidget::HTML_ARG_NAME] = array();
// Avoids that elements in a HTML page have the same name or id
$randomIdentifier = uniqid(rand(0, 1000));
$this->_args[HTMLWidget::HTML_ARG_NAME][HTMLWidget::HTML_ID] = $randomIdentifier;
$this->_args[HTMLWidget::HTML_ARG_NAME][HTMLWidget::HTML_NAME] = $randomIdentifier;
foreach($htmlArgs as $argName => $argValue)
{
$this->_args[HTMLWidget::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[HTMLWidget::EXTERNAL_BLOCK])
&& $htmlArgs[HTMLWidget::EXTERNAL_BLOCK] === true)
{
echo HTMLWidget::EXTERNAL_START_BLOCK_HTML_TAG;
}
}
/**
*
*/
public static function printEndBlock($htmlArgs)
{
if (isset($htmlArgs[HTMLWidget::EXTERNAL_BLOCK])
&& $htmlArgs[HTMLWidget::EXTERNAL_BLOCK] === true)
{
echo HTMLWidget::EXTERNAL_END_BLOCK_HTML_TAG;
}
}
}
@@ -0,0 +1,27 @@
<?php
/**
* It exends the Widget class to represent an HTML textarea
*/
class TextareaWidget extends HTMLWidget
{
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);
}
}
@@ -0,0 +1,26 @@
<?php
/**
* It exends the Widget class to represent an HTML textarea
*/
class TextfieldWidget extends HTMLWidget
{
const VALUE = 'text'; //
const SIZE = 'size'; //
/**
*
*/
protected function setValue($value)
{
$this->_args[TextfieldWidget::VALUE] = $value;
}
/**
*
*/
protected function loadTextfieldView()
{
$this->view('widgets/textfield', $this->_args);
}
}
@@ -0,0 +1,17 @@
<?php
/**
*
*/
class CheckboxWidgetUDF extends CheckboxWidget
{
/**
*
*/
public function render()
{
$this->loadCheckboxView();
echo $this->content();
}
}
@@ -0,0 +1,58 @@
<?php
/**
*
*/
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[HTMLWidget::HTML_ARG_NAME][HTMLWidget::PLACEHOLDER],
'No data found for this UDF'
);
$this->loadDropDownView();
echo $this->content();
}
}
@@ -0,0 +1,26 @@
<?php
/**
*
*/
class TextareaWidgetUDF extends TextareaWidget
{
/**
*
*/
public function render($parameters)
{
if ($parameters != null)
{
$this->setText($parameters);
}
else
{
$this->setText('');
}
$this->loadTextareaView();
echo $this->content();
}
}
@@ -0,0 +1,26 @@
<?php
/**
*
*/
class TextfieldWidgetUDF extends TextfieldWidget
{
/**
*
*/
public function render($parameters)
{
if ($parameters != null)
{
$this->setValue($parameters);
}
else
{
$this->setValue('');
}
$this->loadTextfieldView();
echo $this->content();
}
}
+421
View File
@@ -0,0 +1,421 @@
<?php
/**
*
*/
class UDFWidget extends HTMLWidget
{
const NAME = 'name';
const TYPE = 'type';
const VALIDATION = 'validation';
const LIST_VALUES = 'listValues';
const REGEX_LANGUAGE = 'js';
const PHRASES_APP_NAME = 'core';
public function display($widgetData)
{
$schema = $widgetData[UDFLib::SCHEMA_ARG_NAME];
$table = $widgetData[UDFLib::TABLE_ARG_NAME];
if (isset($widgetData[UDFLib::FIELD_ARG_NAME]))
{
$field = $widgetData[UDFLib::FIELD_ARG_NAME];
}
$udfResults = $this->_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[HTMLWidget::HTML_ARG_NAME][HTMLWidget::HTML_ID] = $jsonSchema->{UDFWidget::NAME};
$this->_args[HTMLWidget::HTML_ARG_NAME][HTMLWidget::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[UDFLib::UDFS_ARG_NAME])
&& isset($this->_args[UDFLib::UDFS_ARG_NAME][$jsonSchema->{UDFWidget::NAME}]))
{
$this->_args[DropdownWidget::SELECTED_ELEMENT] = $this->_args[UDFLib::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[UDFLib::UDFS_ARG_NAME])
&& isset($this->_args[UDFLib::UDFS_ARG_NAME][$jsonSchema->{UDFWidget::NAME}]))
{
$text = $this->_args[UDFLib::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[UDFLib::UDFS_ARG_NAME])
&& isset($this->_args[UDFLib::UDFS_ARG_NAME][$jsonSchema->{UDFWidget::NAME}]))
{
$text = $this->_args[UDFLib::UDFS_ARG_NAME][$jsonSchema->{UDFWidget::NAME}];
}
$textareaUDF->render($text);
}
/**
*
*/
private function _renderCheckbox($jsonSchema)
{
if (isset($this->_args[UDFLib::UDFS_ARG_NAME])
&& isset($this->_args[UDFLib::UDFS_ARG_NAME][$jsonSchema->{UDFWidget::NAME}]))
{
$this->_args[CheckboxWidget::VALUE_FIELD] = $this->_args[UDFLib::UDFS_ARG_NAME][$jsonSchema->{UDFWidget::NAME}];
}
else
{
$this->_args[CheckboxWidget::VALUE_FIELD] = HTMLWidget::HTML_DEFAULT_VALUE;
}
$checkboxWidgetUDF = new CheckboxWidgetUDF($this->_name, $this->_args);
$checkboxWidgetUDF->render();
}
/**
*
*/
private function _setAttributesWithPhrases($jsonSchema)
{
// Description, title and placeholder
if (isset($jsonSchema->{UDFLib::LABEL})
|| isset($jsonSchema->{UDFLib::TITLE})
|| isset($jsonSchema->{UDFLib::PLACEHOLDER}))
{
//
$this->_ci->load->library('PhrasesLib');
//
if (isset($jsonSchema->{UDFLib::LABEL}))
{
$tmpResult = $this->_ci->phraseslib->getPhrases(
UDFWidget::PHRASES_APP_NAME,
DEFAULT_LEHREINHEIT_SPRACHE,
$jsonSchema->{UDFLib::LABEL},
null,
null,
'no'
);
if (hasData($tmpResult))
{
$this->_args[HTMLWidget::HTML_ARG_NAME][UDFLib::LABEL] = $tmpResult->retval[0]->text;
}
else
{
$this->_args[HTMLWidget::HTML_ARG_NAME][UDFLib::LABEL] = null;
}
}
//
if (isset($jsonSchema->{UDFLib::TITLE}))
{
$tmpResult = $this->_ci->phraseslib->getPhrases(
UDFWidget::PHRASES_APP_NAME,
DEFAULT_LEHREINHEIT_SPRACHE,
$jsonSchema->{UDFLib::TITLE},
null,
null,
'no'
);
if (hasData($tmpResult))
{
$this->_args[HTMLWidget::HTML_ARG_NAME][UDFLib::TITLE] = $tmpResult->retval[0]->text;
}
else
{
$this->_args[HTMLWidget::HTML_ARG_NAME][UDFLib::TITLE] = null;
}
}
//
if (isset($jsonSchema->{UDFLib::PLACEHOLDER}))
{
$tmpResult = $this->_ci->phraseslib->getPhrases(
UDFWidget::PHRASES_APP_NAME,
DEFAULT_LEHREINHEIT_SPRACHE,
$jsonSchema->{UDFLib::PLACEHOLDER},
null,
null,
'no'
);
if (hasData($tmpResult))
{
$this->_args[HTMLWidget::HTML_ARG_NAME][UDFLib::PLACEHOLDER] = $tmpResult->retval[0]->text;
}
else
{
$this->_args[HTMLWidget::HTML_ARG_NAME][UDFLib::PLACEHOLDER] = null;
}
}
}
}
/**
*
*/
private function _setValidationAttributes($jsonSchema)
{
// Validation
$this->_args[HTMLWidget::HTML_ARG_NAME][UDFWidget::REQUIRED] = null;
$this->_args[HTMLWidget::HTML_ARG_NAME][UDFLib::REGEX] = null;
$this->_args[HTMLWidget::HTML_ARG_NAME][UDFLib::MAX_VALUE] = null;
$this->_args[HTMLWidget::HTML_ARG_NAME][UDFLib::MIN_VALUE] = null;
if (isset($jsonSchema->validation))
{
if (isset($jsonSchema->{UDFWidget::VALIDATION}->{UDFLib::REGEX})
&& is_array($jsonSchema->{UDFWidget::VALIDATION}->{UDFLib::REGEX}))
{
foreach($jsonSchema->{UDFWidget::VALIDATION}->{UDFLib::REGEX} as $regex)
{
if ($regex->language === UDFWidget::REGEX_LANGUAGE)
{
$this->_args[HTMLWidget::HTML_ARG_NAME][UDFLib::REGEX] = $regex->expression;
}
}
}
if (isset($jsonSchema->{UDFWidget::VALIDATION}->{UDFLib::REQUIRED}))
{
$this->_args[HTMLWidget::HTML_ARG_NAME][UDFWidget::REQUIRED] = $jsonSchema->{UDFWidget::VALIDATION}->{UDFLib::REQUIRED};
}
if (isset($jsonSchema->{UDFWidget::VALIDATION}->{UDFLib::MAX_VALUE}))
{
$this->_args[HTMLWidget::HTML_ARG_NAME][UDFLib::MAX_VALUE] = $jsonSchema->{UDFWidget::VALIDATION}->{UDFLib::MAX_VALUE};
}
if (isset($jsonSchema->{UDFWidget::VALIDATION}->{UDFLib::MIN_VALUE}))
{
$this->_args[HTMLWidget::HTML_ARG_NAME][UDFLib::MIN_VALUE] = $jsonSchema->{UDFWidget::VALIDATION}->{UDFLib::MIN_VALUE};
}
}
}
}
+3
View File
@@ -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);
@@ -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) {}
}
@@ -262,6 +262,10 @@ echo '<?xul-overlay href="'.APP_ROOT.'content/mitarbeiter/mitarbeitervertragover
?>
<tab id="mitarbeiter-tab-termine" label="Termine" onclick="MitarbeiterTermineIFrameLoad()" />
<tab id="mitarbeiter-tab-notizen" label="Notizen"/>
<?php
if (!defined('FAS_UDF') || FAS_UDF == true)
echo '<tab id="mitarbeiter-tab-udf" label="Zusatzfelder" onclick="MitarbeiterUDFIFrameLoad()"/>';
?>
</tabs>
<tabpanels id="mitarbeiter-tabpanels-main" flex="1">
<vbox id="mitarbeiter-detail-stammdaten" style="margin-top:10px;" />
@@ -279,6 +283,10 @@ echo '<?xul-overlay href="'.APP_ROOT.'content/mitarbeiter/mitarbeitervertragover
<vbox id="mitarbeiter-box-notiz">
<box class="Notiz" flex="1" id="mitarbeiter-box-notizen"/>
</vbox>
<?php
if (!defined('FAS_UDF') || FAS_UDF == true)
echo '<iframe id="mitarbeiter-udf" src="" style="margin-top:10px;" />';
?>
</tabpanels>
</tabbox>
</vbox>
+150 -84
View File
@@ -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();
?>
-585
View File
@@ -1,585 +0,0 @@
<?php
/* Copyright (C) 2006 Technikum-Wien
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* Authors: Christian Paminger <christian.paminger@technikum-wien.at>,
* Andreas Oesterreicher <andreas.oesterreicher@technikum-wien.at> and
* Rudolf Hangl <rudolf.hangl@technikum-wien.at>.
*/
/**
* 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();
?>
File diff suppressed because it is too large Load Diff
+11 -2
View File
@@ -484,6 +484,11 @@ else
if(!defined('FAS_MESSAGES') || FAS_MESSAGES==true)
echo '<tab id="student-tab-messages" label="Messages" onclick="StudentMessagesIFrameLoad();"/>';
?>
<?php
if (!defined('FAS_UDF') || FAS_UDF == true)
echo '<tab id="student-tab-udf" label="Zusatzfelder" onclick="StudentUDFIFrameLoad();"/>';
?>
</tabs>
<tabpanels id="student-tabpanels-main" flex="1">
@@ -516,9 +521,13 @@ else
?>
<iframe id="student-aufnahmetermine" style="margin: 0px;" src="" />
<?php
if(!defined('FAS_MESSAGES') || FAS_MESSAGES==true)
echo '<iframe id="student-messages" style="margin: 0px;" src="" />';
if(!defined('FAS_MESSAGES') || FAS_MESSAGES==true)
echo '<iframe id="student-messages" style="margin: 0px;" src="" />';
if (!defined('FAS_UDF') || FAS_UDF == true)
echo '<iframe id="student-udf" style="margin: 0px;" src="" />';
?>
</tabpanels>
</tabbox>
</vbox>
+28 -1
View File
@@ -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 = '<?php echo APP_ROOT; ?>content/statistik/studentenexport.xls.php?studiensemester_kurzbz='+stsem;
action = '<?php echo APP_ROOT; ?>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
// ****
+37
View File
@@ -0,0 +1,37 @@
<?php
/* Copyright (C) 2016 fhcomplete.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* Authors: Andreas Oesterreicher <andreas.oesterreicher@technikum-wien.at>
*/
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', '<?php echo APP_ROOT ?>index.ci.php/system/UDF?person_id='+person_id+'&prestudent_id='+prestudent_id);
}
}
+72
View File
@@ -0,0 +1,72 @@
<?php
/* Copyright (C) 2016 fhcomplete.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* Authors: Andreas Oesterreicher <andreas.oesterreicher@technikum-wien.at>
*/
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 '<?xml version="1.0" encoding="UTF-8"?>'."\n";
echo '<?xml-stylesheet href="'.APP_ROOT.'skin/tempus.css" type="text/css"?>';
echo '<?xml-stylesheet href="'.APP_ROOT.'content/bindings.css" type="text/css"?>';
echo '<?xml-stylesheet href="'.APP_ROOT.'content/datepicker/datepicker.css" type="text/css"?>';
$person_id = filter_input(INPUT_GET, 'person_id');
$prestudent_id= filter_input(INPUT_GET, 'prestudent_id');
echo '
<!DOCTYPE overlay [';
require('../locale/'.$variable->variable->locale.'/fas.dtd');
echo ']>
';
?>
<window id="udf-window" title="udf"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
onload="loadUDF(<?php echo "'".$person_id."','".$prestudent_id."'"; ?>);"
>
<script type="application/x-javascript" src="<?php echo APP_ROOT; ?>content/udf.js.php" />
<script type="application/x-javascript" src="<?php echo APP_ROOT; ?>content/functions.js.php" />
<script type="application/x-javascript" src="<?php echo APP_ROOT; ?>content/phpRequest.js.php" />
<vbox flex="1">
<hbox flex="1">
<iframe id="udfIFrame" editortype="html" src="about:blank" flex="1" type="content-primary" style="min-width: 100px; min-height: 100px; border: 0px; margin: 10px;"/>
</hbox>
</vbox>
</window>
+27 -2
View File
@@ -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;
+349
View File
@@ -0,0 +1,349 @@
<?php
/* Copyright (C) 2009 Technikum-Wien
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* Authors: Bison Paolo <bison@technikum-wien.at>
*/
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;
}
}
+46
View File
@@ -0,0 +1,46 @@
.div-table {
display: table;
}
.div-row {
display: table-row;
}
.div-cell {
display: table-cell;
}
.div-cell-label {
display: table-cell;
}
label[udf-required=true]::after {
content: "*";
}
.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;
}
+82 -2
View File
@@ -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 '<strong>system.tbl_udf: '.$db->db_last_error().'</strong><br>';
else
echo '<br>system.tbl_udf table created';
$qry = 'COMMENT ON COLUMN system.tbl_udf.schema IS \'Schema of the table\';';
if(!$db->db_query($qry))
echo '<strong>Adding comment to system.tbl_udf.schema: '.$db->db_last_error().'</strong><br>';
else
echo '<br>Added comment to system.tbl_udf.schema';
$qry = 'COMMENT ON COLUMN system.tbl_udf.table IS \'Table name\';';
if(!$db->db_query($qry))
echo '<strong>Adding comment to system.tbl_udf.table: '.$db->db_last_error().'</strong><br>';
else
echo '<br>Added comment to system.tbl_udf.table';
$qry = 'COMMENT ON COLUMN system.tbl_udf.jsons IS \'JSON schema\';';
if(!$db->db_query($qry))
echo '<strong>Adding comment to system.tbl_udf.jsons: '.$db->db_last_error().'</strong><br>';
else
echo '<br>Added comment to system.tbl_udf.jsons';
$qry = 'GRANT SELECT ON TABLE system.tbl_udf TO web;';
if(!$db->db_query($qry))
echo '<strong>system.tbl_udf: '.$db->db_last_error().'</strong><br>';
else
echo '<br>Granted privileges to <strong>web</strong> on system.tbl_udf';
$qry = 'GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE system.tbl_udf TO vilesci;';
if(!$db->db_query($qry))
echo '<strong>system.tbl_udf: '.$db->db_last_error().'</strong><br>';
else
echo '<br>Granted privileges to <strong>vilesci</strong> 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 '<strong>public.tbl_person: '.$db->db_last_error().'</strong><br>';
else
echo '<br>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 '<strong>public.tbl_prestudent: '.$db->db_last_error().'</strong><br>';
else
echo '<br>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 '<strong>system.tbl_berechtigung '.$db->db_last_error().'</strong><br>';
else
echo ' system.tbl_berechtigung: Added permission for UDF<br>';
}
}
// 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 '<br>Gegenpruefung fehlerfrei';
?>
?>