mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-23 09:52:22 +00:00
- Changed controller system/FAS_UDF, less busy now
- Method execReadOnlyQuery of DB_Model less strict check against SQL statements - Added new public method setup to DB_Model to setup the model after initialization - Added new constants to UDFLib - Added new private method _printEndUDFBlock and _printEndUDFBlock to UDFLib - Added new public methods setUDFUniqueId, getSession, getSessionElement, setSession, setSessionElement, saveUDFs and isAllowed to UDFLib - Removed model system/FAS_UDF_model - View views/system/fas_udf now uses the view templates/FHC-Header - Added new parameter udfs to view templates/FHC-Header - Added new properties to UDFWidget - Added new private methods _initUDFWidget, _checkParameters and _startUDFWidget to UDFWidget
This commit is contained in:
@@ -24,43 +24,15 @@ class FAS_UDF extends Auth_Controller
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$fasUdfSession = getSession(self::FAS_UDF_SESSION_NAME);
|
||||
|
||||
$person_id = $this->input->get('person_id');
|
||||
if (isset($fasUdfSession['person_id']))
|
||||
{
|
||||
if (!isset($person_id))
|
||||
{
|
||||
$person_id = $fasUdfSession['person_id'];
|
||||
}
|
||||
unset($fasUdfSession['person_id']);
|
||||
}
|
||||
|
||||
$prestudent_id = $this->input->get('prestudent_id');
|
||||
if (isset($fasUdfSession['prestudent_id']))
|
||||
{
|
||||
if (!isset($prestudent_id))
|
||||
{
|
||||
$prestudent_id = $fasUdfSession['prestudent_id'];
|
||||
}
|
||||
unset($fasUdfSession['prestudent_id']);
|
||||
}
|
||||
|
||||
$result = null;
|
||||
if (isset($fasUdfSession['result']))
|
||||
{
|
||||
$result = clone $fasUdfSession['result'];
|
||||
setSessionElement(self::FAS_UDF_SESSION_NAME, 'result', null);
|
||||
}
|
||||
|
||||
$data = array('result' => $result);
|
||||
|
||||
if (isset($person_id) && is_numeric($person_id))
|
||||
{
|
||||
if ($this->PersonModel->hasUDF())
|
||||
{
|
||||
$personUdfs = $this->PersonModel->getUDFs($person_id);
|
||||
$personUdfs['person_id'] = $person_id;
|
||||
$data['person_id'] = $person_id;
|
||||
$data['personUdfs'] = $personUdfs;
|
||||
}
|
||||
}
|
||||
@@ -70,61 +42,11 @@ class FAS_UDF extends Auth_Controller
|
||||
if ($this->PrestudentModel->hasUDF())
|
||||
{
|
||||
$prestudentUdfs = $this->PrestudentModel->getUDFs($prestudent_id);
|
||||
$prestudentUdfs['prestudent_id'] = $prestudent_id;
|
||||
$data['prestudent_id'] = $prestudent_id;
|
||||
$data['prestudentUdfs'] = $prestudentUdfs;
|
||||
}
|
||||
}
|
||||
|
||||
$this->load->view('system/fas_udf', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function saveUDF()
|
||||
{
|
||||
$udfs = $this->input->post();
|
||||
$validation = $this->_validate($udfs);
|
||||
|
||||
$userdata = array(
|
||||
'person_id' => $this->input->post('person_id'),
|
||||
'prestudent_id' => $this->input->post('prestudent_id')
|
||||
);
|
||||
|
||||
if (isSuccess($validation))
|
||||
{
|
||||
// Load model UDF_model
|
||||
$this->load->model('system/FAS_UDF_model', 'FASUDFModel');
|
||||
|
||||
$result = $this->FASUDFModel->saveUDFs($udfs);
|
||||
|
||||
$userdata['result'] = $result;
|
||||
}
|
||||
else
|
||||
{
|
||||
$userdata['result'] = $validation;
|
||||
}
|
||||
|
||||
setSessionElement(self::FAS_UDF_SESSION_NAME, 'person_id', $userdata['person_id']);
|
||||
setSessionElement(self::FAS_UDF_SESSION_NAME, 'prestudent_id', $userdata['prestudent_id']);
|
||||
setSessionElement(self::FAS_UDF_SESSION_NAME, 'result', $userdata['result']);
|
||||
|
||||
redirect('system/FAS_UDF');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function _validate($udfs)
|
||||
{
|
||||
$validation = error('person_id or prestudent_id is missing');
|
||||
|
||||
if((isset($udfs['person_id']) && !(is_null($udfs['person_id'])) && ($udfs['person_id'] != ''))
|
||||
|| (isset($udfs['prestudent_id']) && !(is_null($udfs['prestudent_id'])) && ($udfs['prestudent_id'] != '')))
|
||||
{
|
||||
$validation = success(true);
|
||||
}
|
||||
|
||||
return $validation;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
if (! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* This controller...
|
||||
*/
|
||||
class UDF extends FHC_Controller
|
||||
{
|
||||
const UDF_UNIQUE_ID = 'udfUniqueId';
|
||||
|
||||
/**
|
||||
* Calls the parent's constructor and loads the
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
// Loads authentication library and starts authentication
|
||||
$this->load->library('AuthLib');
|
||||
|
||||
// Loads the UDFLib with HTTP GET/POST parameters
|
||||
$this->_loadUDFLib();
|
||||
|
||||
// Checks if the caller is allow to read this data
|
||||
$this->_isAllowed();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
// Public methods
|
||||
|
||||
/**
|
||||
* Retrieves data about the current filter from the session and will be written on the output in JSON format
|
||||
*/
|
||||
public function saveUDFs()
|
||||
{
|
||||
$udfUniqueId = $this->input->post(self::UDF_UNIQUE_ID);
|
||||
$udfs = $this->input->post(UDFLib::UDFS_ARG_NAME);
|
||||
|
||||
if (!isEmptyString($udfs))
|
||||
{
|
||||
$jsonDecodedUDF = json_decode($udfs);
|
||||
if ($jsonDecodedUDF != null)
|
||||
{
|
||||
$this->outputJson($this->udflib->saveUDFs($udfUniqueId, $jsonDecodedUDF));
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->outputJsonError('No valid JSON format for UDF values');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->outputJsonError('UDFUniqueId, schema, table name, primary key name and primary key value are mandatory paramenters');
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
// Private methods
|
||||
|
||||
/**
|
||||
* Checks if the user is allowed to use this filter
|
||||
*/
|
||||
private function _isAllowed()
|
||||
{
|
||||
if (!$this->udflib->isAllowed())
|
||||
{
|
||||
$this->terminateWithJsonError('You are not allowed to access to this content');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the tablewidgetlib with the UDF_UNIQUE_ID parameter
|
||||
* If the parameter UDF_UNIQUE_ID is not given then the execution of the controller is terminated and
|
||||
* an error message is printed
|
||||
*/
|
||||
private function _loadUDFLib()
|
||||
{
|
||||
// If the parameter UDF_UNIQUE_ID is present in the HTTP GET or POST
|
||||
if (isset($_GET[self::UDF_UNIQUE_ID]) || isset($_POST[self::UDF_UNIQUE_ID]))
|
||||
{
|
||||
// If it is present in the HTTP GET
|
||||
if (isset($_GET[self::UDF_UNIQUE_ID]))
|
||||
{
|
||||
$udfUniqueId = $this->input->get(self::UDF_UNIQUE_ID); // is retrieved from the HTTP GET
|
||||
}
|
||||
elseif (isset($_POST[self::UDF_UNIQUE_ID])) // Else if it is present in the HTTP POST
|
||||
{
|
||||
$udfUniqueId = $this->input->post(self::UDF_UNIQUE_ID); // is retrieved from the HTTP POST
|
||||
}
|
||||
|
||||
// Loads the tablewidgetlib that contains all the used logic
|
||||
$this->load->library('UDFLib');
|
||||
|
||||
$this->udflib->setUDFUniqueId($udfUniqueId);
|
||||
}
|
||||
else // Otherwise an error will be written in the output
|
||||
{
|
||||
$this->terminateWithJsonError('Parameter "'.self::UDF_UNIQUE_ID.'" not provided!');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user