mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-24 02:12:17 +00:00
Merge branch 'ci' of https://github.com/FH-Complete/FHC-Core into ci
This commit is contained in:
@@ -508,14 +508,10 @@ $config['proxy_ips'] = '';
|
||||
| Autoload Custom Controllers
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
Don't work so sometime delete this*/
|
||||
function __autoload($class)
|
||||
{
|
||||
| It's working, so don't delete this :D
|
||||
*/
|
||||
spl_autoload_register(function ($class) {
|
||||
if (substr($class,0,3) !== 'CI_' && substr($class,0,4) !== 'FHC_')
|
||||
{
|
||||
if (file_exists($file = APPPATH . 'core/' . $class . '.php'))
|
||||
{
|
||||
require_once $file;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (file_exists($file = APPPATH . 'core/' . $class . '.php'))
|
||||
require_once $file;
|
||||
});
|
||||
|
||||
@@ -1,6 +1,24 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| FH-Complete Constants
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| These constants are used for internal messages. It are also be used
|
||||
| and translated in the language files.
|
||||
|
|
||||
*/
|
||||
define('FHC_SUCCESS', 0); // General Success Message
|
||||
define('FHC_ERROR', 1); // General Error Message
|
||||
define('FHC_MODEL_ERROR', 2); // Model Error
|
||||
define('FHC_DB_ERROR', 3); // Database Error
|
||||
define('FHC_NODBTABLE', 4); // No DB-Table is set
|
||||
define('FHC_NORIGHT', 5); // No rights
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| File and Directory Modes
|
||||
@@ -75,6 +93,7 @@ define('SHOW_DEBUG_BACKTRACE', TRUE);
|
||||
*/
|
||||
define('EXIT_SUCCESS', 0); // no errors
|
||||
define('EXIT_ERROR', 1); // generic error
|
||||
define('EXIT_MODEL', 2); // model error
|
||||
define('EXIT_CONFIG', 3); // configuration error
|
||||
define('EXIT_UNKNOWN_FILE', 4); // file not found
|
||||
define('EXIT_UNKNOWN_CLASS', 5); // unknown class
|
||||
|
||||
@@ -2,7 +2,11 @@
|
||||
|
||||
$config['fhc_version'] = '3.2';
|
||||
|
||||
|
||||
// status return message codes
|
||||
define('FHC_SUCCESS', 0);
|
||||
define('FHC_ERR_GENERAL', 1);
|
||||
$config['fhc_acl'] = array
|
||||
(
|
||||
'public.tbl_person' => 'basis/person',
|
||||
'public.tbl_prestudent' => 'basis/person',
|
||||
'public.tbl_organisationseinheit' => 'basis/organisationseinheit'
|
||||
,
|
||||
'public.tbl_sprache' => 'admin'
|
||||
);
|
||||
|
||||
@@ -119,7 +119,8 @@ $config['rest_auth'] = 'basic';
|
||||
|
|
||||
| Is login required and if so, the user store to use
|
||||
|
|
||||
| '' Use config based users or wildcard testing
|
||||
| '' Use config based users or wildcard testing, only for testing purpose
|
||||
| it would be very unsecure to let unset in a production environment
|
||||
| 'ldap' Use LDAP authentication
|
||||
| 'library' Use a authentication library
|
||||
|
|
||||
@@ -139,13 +140,16 @@ $config['auth_source'] = 'library';
|
||||
| In other cases override the function _perform_library_auth in your controller
|
||||
|
|
||||
| For digest authentication the library function should return already a stored
|
||||
| md5(username:restrealm:password) for that username
|
||||
|
|
||||
| e.g: md5('admin:REST API:1234') = '1e957ebc35631ab22d5bd6526bd14ea2'
|
||||
| password for that username, even if it is hashed
|
||||
|
|
||||
*/
|
||||
$config['auth_library_class'] = 'FHC_Auth';
|
||||
$config['auth_library_function'] = 'auth';
|
||||
|
||||
// rest_auth is basic
|
||||
$config['auth_library_function'] = 'basicAuthentication';
|
||||
|
||||
// rest_auth is digest
|
||||
//$config['auth_library_function'] = 'digestAuthentication';
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
@@ -211,7 +215,7 @@ $config['auth_override_class_method_http']['Kontakt']['kontaktPerson']['get'] =
|
||||
| Array of usernames and passwords for login, if ldap (even library) is configured this is ignored
|
||||
|
|
||||
*/
|
||||
$config['rest_valid_logins'] = ['admin' => '1234', 'test' => 'test'];
|
||||
//$config['rest_valid_logins'] = ['admin' => '1234', 'test' => 'test'];
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
@@ -228,7 +232,7 @@ $config['rest_valid_logins'] = ['admin' => '1234', 'test' => 'test'];
|
||||
| restrict certain methods to IPs in your whitelist
|
||||
|
|
||||
*/
|
||||
$config['rest_ip_whitelist_enabled'] = TRUE;
|
||||
$config['rest_ip_whitelist_enabled'] = FALSE;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Template configuration
|
||||
|--------------------------------------------------------------------------
|
||||
| This file will contain the settings for the template library.
|
||||
|
|
||||
| 'parser' = if you want your main template file to be parsed, set to TRUE
|
||||
| 'template' = the filename of the default template file
|
||||
| 'cache_ttl' = the time all partials should be cache in seconds, 0 means no global caching
|
||||
*/
|
||||
|
||||
$config['parser'] = FALSE;
|
||||
$config['template'] = 'template';
|
||||
$config['cache_ttl'] = 0;
|
||||
Executable
+165
@@ -0,0 +1,165 @@
|
||||
<?php
|
||||
defined('BASEPATH') || exit('No direct script access allowed');
|
||||
|
||||
class ModelTest extends FHC_Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* Index Page for this controller.
|
||||
*
|
||||
* Maps to the following URL
|
||||
* http://example.com/index.php/welcome
|
||||
* - or -
|
||||
* http://example.com/index.php/welcome/index
|
||||
* - or -
|
||||
* Since this controller is set as the default controller in
|
||||
* config/routes.php, it's displayed at http://example.com/
|
||||
*
|
||||
* So any other public methods not prefixed with an underscore will
|
||||
* map to /index.php/welcome/<method_name>
|
||||
* @see http://codeigniter.com/user_guide/general/urls.html
|
||||
* @return void
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$this->session->uid='admin'; // Should normaly be set through auth
|
||||
$this->load->model('person/Prestudent_model');
|
||||
$id=null;
|
||||
|
||||
// Insert PreStudent
|
||||
$data = array
|
||||
(
|
||||
'aufmerksamdurch_kurzbz' => 'k.A.',
|
||||
'person_id' => 1,
|
||||
'studiengang_kz' => 0
|
||||
);
|
||||
$res = $this->Prestudent_model->insert($data);
|
||||
if ($res->error)
|
||||
echo 'Error: ',$res->error, ', Code: ',$res->code,' -> ',$res->msg,': ',$res->retval,'<br/>';
|
||||
else
|
||||
$id=$res->retval;
|
||||
|
||||
// Update PreStudent
|
||||
$data = array
|
||||
(
|
||||
'zgvort' => 'Wien',
|
||||
'zgvdatum' => '2012-12-12',
|
||||
'facheinschlberuf' => true
|
||||
);
|
||||
$res = $this->Prestudent_model->update($id, $data);
|
||||
if ($res->error)
|
||||
echo 'Error: ',$res->error, ', Code: ',$res->code,' -> ',$res->msg,': ',$res->retval,'<br/>';
|
||||
else
|
||||
$id=$res->retval;
|
||||
|
||||
// Replace PreStudent
|
||||
/*$data = array
|
||||
(
|
||||
'prestudent_id' => $id,
|
||||
'zgvmaort' => 'Linz',
|
||||
'zgvmadatum' => '2011-11-11',
|
||||
'facheinschlberuf' => false
|
||||
);
|
||||
$res = $this->Prestudent_model->replace($data);
|
||||
if ($res->error)
|
||||
echo 'Error: ',$res->error, ', Code: ',$res->code,' -> ',$res->msg,': ',$res->retval;
|
||||
else
|
||||
echo 'Error: ',$res->error, ', Code: ',$res->code,' -> ',$res->msg,': ',$res->retval;*/
|
||||
|
||||
// Load PreStudent
|
||||
$res = $this->Prestudent_model->load($id);
|
||||
if ($res->error)
|
||||
echo 'Error: ',$res->error, ', Code: ',$res->code,' -> ',$res->msg,': ',$res->retval,'<br/>';
|
||||
else
|
||||
var_dump($res->retval);
|
||||
|
||||
// Delete PreStudent
|
||||
$res = $this->Prestudent_model->delete($id);
|
||||
if ($res->error)
|
||||
echo 'Error: ',$res->error, ', Code: ',$res->code,' -> ',$res->msg,': ',$res->retval,'<br/>';
|
||||
else
|
||||
var_dump($res->retval);
|
||||
|
||||
$this->load->model('organisation/Organisationseinheit_model');
|
||||
// Insert OE
|
||||
$data = array
|
||||
(
|
||||
'oe_kurzbz' => 'testoe',
|
||||
'bezeichnung' => 'testoe',
|
||||
'organisationseinheittyp_kurzbz' => 'Institut',
|
||||
'standort_id' => null
|
||||
);
|
||||
$res = $this->Organisationseinheit_model->insert($data);
|
||||
if ($res->error)
|
||||
echo 'Error: ',$res->error, ', Code: ',$res->code,' -> ',$res->msg,': ',$res->retval,'<br/>';
|
||||
else
|
||||
$id = $data['oe_kurzbz'];
|
||||
var_dump($res);
|
||||
|
||||
// Update PreStudent
|
||||
$data = array
|
||||
(
|
||||
'freigabegrenze' => 1234.56,
|
||||
'kurzzeichen' => 'TestOE',
|
||||
'lehre' => false
|
||||
);
|
||||
$res = $this->Organisationseinheit_model->update($id, $data);
|
||||
if ($res->error)
|
||||
echo 'Error: ',$res->error, ', Code: ',$res->code,' -> ',$res->msg,': ',$res->retval,'<br/>';
|
||||
else
|
||||
$id=$res->retval;
|
||||
|
||||
// Delete PreStudent
|
||||
$res = $this->Organisationseinheit_model->delete($id);
|
||||
if ($res->error)
|
||||
echo 'Error: ',$res->error, ', Code: ',$res->code,' -> ',$res->msg,': ',$res->retval,'<br/>';
|
||||
else
|
||||
var_dump($res->retval);
|
||||
|
||||
$this->load->model('core/Sprache_model');
|
||||
// Insert Sprache
|
||||
$data = array
|
||||
(
|
||||
'sprache' => 'test',
|
||||
'bezeichnung' => "{'testsprache'}",
|
||||
'locale' => 'te_TE',
|
||||
'content' => false
|
||||
);
|
||||
$res = $this->Sprache_model->insert($data);
|
||||
if ($res->error)
|
||||
echo 'Error: ',$res->error, ', Code: ',$res->code,' -> ',$res->msg,': ',$res->retval,'<br/>';
|
||||
else
|
||||
$id = $data['sprache'];
|
||||
var_dump($res);
|
||||
|
||||
// Update Sprache
|
||||
$data = array
|
||||
(
|
||||
'index' => 4,
|
||||
'bezeichnung' => "{'TestSprache', 'TestLanguage', 'TestSpanisch'}",
|
||||
'content' => true
|
||||
);
|
||||
$res = $this->Sprache_model->update($id, $data);
|
||||
if ($res->error)
|
||||
echo 'Error: ',$res->error, ', Code: ',$res->code,' -> ',$res->msg,': ',$res->retval,'<br/>';
|
||||
else
|
||||
$id=$res->retval; //echo $id;
|
||||
|
||||
// Load Sprache
|
||||
$res = $this->Sprache_model->load($id);
|
||||
if ($res->error)
|
||||
echo 'Error: ',$res->error, ', Code: ',$res->code,' -> ',$res->msg,': ',$res->retval,'<br/>';
|
||||
else
|
||||
{
|
||||
$result = $res->retval->result_object();
|
||||
var_dump($this->Sprache_model->pgArrayPhp($result[0]->bezeichnung));
|
||||
}
|
||||
|
||||
// Delete Sprache
|
||||
$res = $this->Sprache_model->delete($id);
|
||||
if ($res->error)
|
||||
echo 'Error: ',$res->error, ', Code: ',$res->code,' -> ',$res->msg,': ',$res->retval,'<br/>';
|
||||
else
|
||||
var_dump($res->retval);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
defined('BASEPATH') || exit('No direct script access allowed');
|
||||
|
||||
class Vilesci extends CI_Controller
|
||||
class Vilesci extends FHC_Controller
|
||||
{
|
||||
|
||||
/**
|
||||
@@ -22,30 +22,8 @@ class Vilesci extends CI_Controller
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
// ToDo: check if update is needed
|
||||
if (false && $this->dbupdate())
|
||||
echo 'System-DB needs update!';
|
||||
else
|
||||
{
|
||||
$this->load->view('templates/header');
|
||||
$this->load->view('vilesci_frameset');
|
||||
$this->load->view('templates/footer');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function __dbupdate()
|
||||
{
|
||||
// Check for update (codeigniter migration)
|
||||
$this->load->library('migration');
|
||||
if ($this->migration->current() === false)
|
||||
show_error($this->migration->error_string());
|
||||
if ($this->migration->current() != $this->migration->latest())
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
$this->load->view('templates/header');
|
||||
$this->load->view('vilesci_frameset');
|
||||
$this->load->view('templates/footer');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,133 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Whisperocity
|
||||
*
|
||||
* @package Whisperocity
|
||||
* @author WSP-Team
|
||||
* @copyright Copyright (c) 2015, Whisperocity
|
||||
* @license proprietary
|
||||
* @link http://whisperocity.com/
|
||||
* @since Version 1.0
|
||||
* @filesource
|
||||
* @example curl -H "FHC-API-Key: testapikey@fhcomplete.org" http://localhost/fhcomplete/index.ci.php/api/v1/APIAuth/login?code=aladsfasdf
|
||||
*/
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if (! defined('BASEPATH'))
|
||||
exit('No direct script access allowed');
|
||||
|
||||
// This can be removed if you use __autoload() in config.php OR use Modular Extensions
|
||||
//require APPPATH . '/libraries/REST_Controller.php';
|
||||
|
||||
/**
|
||||
* Handles user authentication and registration process
|
||||
*/
|
||||
class APIAuth extends APIv1_Controller
|
||||
{
|
||||
/**
|
||||
* Userauth-Controller constructor.
|
||||
* A more elaborate description of the constructor.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
// Construct the parent class
|
||||
parent::__construct();
|
||||
|
||||
// Configure limits on our controller methods
|
||||
// Ensure you have created the 'limits' table and enabled 'limits' within application/config/rest.php
|
||||
$this->methods['login_get']['limit'] = 500; // 500 requests per hour per user/key
|
||||
|
||||
// Load helper
|
||||
//$this->load->helper('fhcauth');
|
||||
$this->load->library('session');
|
||||
$this->load->library('FHC_Auth');
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks user credentials and creates a new session
|
||||
*
|
||||
* @example normal account: http://wsp.fortyseeds.at/backend/api/userauth/login/username/foo%40bar.at/password/secret/device_id/abcdef123
|
||||
* @example OAuth Google: http://wsp.fortyseeds.at/backend/api/userauth/login/username/foo%40bar.at/device_id/abcdef123/google_token/qwert321
|
||||
* @example OAuth Facebook: http://wsp.fortyseeds.at/backend/api/userauth/login/username/foo%40bar.at/device_id/abcdef123/fb_token/qwert321
|
||||
* @return void JSON that indicates success/failure of login.
|
||||
*/
|
||||
public function login_get()
|
||||
{
|
||||
$payload = array();
|
||||
$errormsg = "";
|
||||
$httpstatus = null;
|
||||
$username = urldecode($this->get('username'));
|
||||
$password = urldecode($this->get('password'));
|
||||
|
||||
$account = $this->fhc_auth->auth($username, $password);
|
||||
|
||||
// perform login checks
|
||||
if (!$account)
|
||||
$errormsg = "Auth not accepted!";
|
||||
|
||||
if (empty($errormsg))
|
||||
{
|
||||
// generate new session
|
||||
$this->session->sess_regenerate();
|
||||
$token = session_id();
|
||||
|
||||
$payload = [
|
||||
'success' => true,
|
||||
'message' => 'User successfully logged in',
|
||||
'session_id' => $token
|
||||
];
|
||||
$httpstatus = REST_Controller::HTTP_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
$payload = [
|
||||
'success' => false,
|
||||
'message' => $errormsg
|
||||
];
|
||||
$httpstatus = REST_Controller::HTTP_UNAUTHORIZED;
|
||||
}
|
||||
|
||||
// Set the response and exit
|
||||
$this->response($payload, $httpstatus);
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs out user by destroying session
|
||||
*
|
||||
* @example http://wsp.fortyseeds.at/backend/api/userauth/logout/username/foo%40bar.at/session_id/55afab8ba6f1b/device_id/abcdef123
|
||||
* @return void JSON that indicates success/failure of logout
|
||||
*/
|
||||
public function logout_get()
|
||||
{
|
||||
$payload = array();
|
||||
$httpstatus = null;
|
||||
$token = $this->get('session_id');
|
||||
$username = urldecode($this->get('username'));
|
||||
$deviceid = $this->get('device_id');
|
||||
$account = $this->user_model->load($username);
|
||||
|
||||
// destroy session
|
||||
if ($this->session_model->destroy($account, $token, $deviceid))
|
||||
{
|
||||
$payload = [
|
||||
'success' => true,
|
||||
'message' => 'user successfully logged out'
|
||||
];
|
||||
$httpstatus = REST_Controller::HTTP_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
$payload = [
|
||||
'success' => false,
|
||||
'message' => 'user could not be logged out'
|
||||
];
|
||||
$httpstatus = REST_Controller::HTTP_BAD_REQUEST;
|
||||
}
|
||||
|
||||
// Set the response and exit
|
||||
$this->response($payload, $httpstatus);
|
||||
}
|
||||
}
|
||||
@@ -1,316 +0,0 @@
|
||||
<?php
|
||||
|
||||
if (! defined('BASEPATH'))
|
||||
exit('No direct script access allowed');
|
||||
|
||||
// This can be removed if you use __autoload() in config.php OR use Modular Extensions
|
||||
require APPPATH.'/libraries/REST_Controller.php';
|
||||
|
||||
/**
|
||||
* Keys Controller
|
||||
* This is a basic Key Management REST controller to make and delete keys
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Rest Server
|
||||
* @category Controller
|
||||
* @author Phil Sturgeon, Chris Kacerguis
|
||||
* @license MIT
|
||||
* @link https://github.com/chriskacerguis/codeigniter-restserver
|
||||
*/
|
||||
class APIKey extends REST_Controller
|
||||
{
|
||||
protected $methods = [
|
||||
'index_put' => ['level' => 10, 'limit' => 10],
|
||||
'index_delete' => ['level' => 10],
|
||||
'level_post' => ['level' => 10],
|
||||
'regenerate_post' => ['level' => 10],
|
||||
];
|
||||
|
||||
/**
|
||||
* Insert a key into the database
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function index_put()
|
||||
{
|
||||
// Build a new key
|
||||
$key = $this->__generateKey();
|
||||
|
||||
// If no key level provided, provide a generic key
|
||||
$level = $this->put('level') ? $this->put('level') : 1;
|
||||
$ignore_limits = ctype_digit($this->put('ignore_limits')) ? (int)$this->put('ignore_limits') : 1;
|
||||
|
||||
// Insert the new key
|
||||
if ($this->_insert_key($key, ['level' => $level, 'ignore_limits' => $ignore_limits]))
|
||||
{
|
||||
$this->response([
|
||||
'status' => true,
|
||||
'key' => $key
|
||||
], REST_Controller::HTTP_CREATED); // CREATED (201) being the HTTP response code
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->response([
|
||||
'status' => false,
|
||||
'message' => 'Could not save the key'
|
||||
], REST_Controller::HTTP_INTERNAL_SERVER_ERROR); // INTERNAL_SERVER_ERROR (500) being the HTTP response code
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a key from the database to stop it working
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function index_delete()
|
||||
{
|
||||
$key = $this->delete('key');
|
||||
|
||||
// Does this key exist?
|
||||
if (!$this->_key_exists($key))
|
||||
{
|
||||
// It doesn't appear the key exists
|
||||
$this->response([
|
||||
'status' => false,
|
||||
'message' => 'Invalid API key'
|
||||
], REST_Controller::HTTP_BAD_REQUEST); // BAD_REQUEST (400) being the HTTP response code
|
||||
}
|
||||
|
||||
// Destroy it
|
||||
$this->_delete_key($key);
|
||||
|
||||
// Respond that the key was destroyed
|
||||
$this->response([
|
||||
'status' => true,
|
||||
'message' => 'API key was deleted'
|
||||
], REST_Controller::HTTP_NO_CONTENT); // NO_CONTENT (204) being the HTTP response code
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the level
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function level_post()
|
||||
{
|
||||
$key = $this->post('key');
|
||||
$new_level = $this->post('level');
|
||||
|
||||
// Does this key exist?
|
||||
if (!$this->_key_exists($key))
|
||||
{
|
||||
// It doesn't appear the key exists
|
||||
$this->response([
|
||||
'status' => false,
|
||||
'message' => 'Invalid API key'
|
||||
], REST_Controller::HTTP_BAD_REQUEST); // BAD_REQUEST (400) being the HTTP response code
|
||||
}
|
||||
|
||||
// Update the key level
|
||||
if ($this->_update_key($key, ['level' => $new_level]))
|
||||
{
|
||||
$this->response([
|
||||
'status' => true,
|
||||
'message' => 'API key was updated'
|
||||
], REST_Controller::HTTP_OK); // OK (200) being the HTTP response code
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->response([
|
||||
'status' => false,
|
||||
'message' => 'Could not update the key level'
|
||||
], REST_Controller::HTTP_INTERNAL_SERVER_ERROR); // INTERNAL_SERVER_ERROR (500) being the HTTP response code
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Suspend a key
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function suspend_post()
|
||||
{
|
||||
$key = $this->post('key');
|
||||
|
||||
// Does this key exist?
|
||||
if (!$this->_key_exists($key))
|
||||
{
|
||||
// It doesn't appear the key exists
|
||||
$this->response([
|
||||
'status' => false,
|
||||
'message' => 'Invalid API key'
|
||||
], REST_Controller::HTTP_BAD_REQUEST); // BAD_REQUEST (400) being the HTTP response code
|
||||
}
|
||||
|
||||
// Update the key level
|
||||
if ($this->_update_key($key, ['level' => 0]))
|
||||
{
|
||||
$this->response([
|
||||
'status' => true,
|
||||
'message' => 'Key was suspended'
|
||||
], REST_Controller::HTTP_OK); // OK (200) being the HTTP response code
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->response([
|
||||
'status' => false,
|
||||
'message' => 'Could not suspend the user'
|
||||
], REST_Controller::HTTP_INTERNAL_SERVER_ERROR); // INTERNAL_SERVER_ERROR (500) being the HTTP response code
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Regenerate a key
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function regenerate_post()
|
||||
{
|
||||
$old_key = $this->post('key');
|
||||
$key_details = $this->__getKey($old_key);
|
||||
|
||||
// Does this key exist?
|
||||
if (!$key_details)
|
||||
{
|
||||
// It doesn't appear the key exists
|
||||
$this->response([
|
||||
'status' => false,
|
||||
'message' => 'Invalid API key'
|
||||
], REST_Controller::HTTP_BAD_REQUEST); // BAD_REQUEST (400) being the HTTP response code
|
||||
}
|
||||
|
||||
// Build a new key
|
||||
$new_key = $this->__generateKey();
|
||||
|
||||
// Insert the new key
|
||||
if ($this->_insert_key($new_key, ['level' => $key_details->level, 'ignore_limits' => $key_details->ignore_limits]))
|
||||
{
|
||||
// Suspend old key
|
||||
$this->_update_key($old_key, ['level' => 0]);
|
||||
|
||||
$this->response([
|
||||
'status' => true,
|
||||
'key' => $new_key
|
||||
], REST_Controller::HTTP_CREATED); // CREATED (201) being the HTTP response code
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->response([
|
||||
'status' => false,
|
||||
'message' => 'Could not save the key'
|
||||
], REST_Controller::HTTP_INTERNAL_SERVER_ERROR); // INTERNAL_SERVER_ERROR (500) being the HTTP response code
|
||||
}
|
||||
}
|
||||
|
||||
/* Helper Methods */
|
||||
|
||||
/**
|
||||
* Generate a key
|
||||
*
|
||||
* @access private
|
||||
* @return void
|
||||
*/
|
||||
private function __generateKey()
|
||||
{
|
||||
do
|
||||
{
|
||||
// Generate a random salt
|
||||
$salt = base_convert(bin2hex($this->security->get_random_bytes(64)), 16, 36);
|
||||
|
||||
// If an error occurred, then fall back to the previous method
|
||||
if ($salt === false)
|
||||
{
|
||||
$salt = hash('sha256', time().mt_rand());
|
||||
}
|
||||
|
||||
$new_key = substr($salt, 0, config_item('rest_key_length'));
|
||||
}
|
||||
while ($this->_key_exists($new_key));
|
||||
|
||||
return $new_key;
|
||||
}
|
||||
|
||||
/* Private Data Methods */
|
||||
|
||||
/**
|
||||
* Get a key
|
||||
*
|
||||
* @access private
|
||||
* @param string $key The API-Key.
|
||||
* @return array
|
||||
*/
|
||||
private function __getKey($key)
|
||||
{
|
||||
return $this->db
|
||||
->where(config_item('rest_key_column'), $key)
|
||||
->get(config_item('rest_keys_table'))
|
||||
->row();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if key exists
|
||||
*
|
||||
* @access private
|
||||
* @param string $key The API-Key.
|
||||
* @return bool
|
||||
*/
|
||||
private function _key_exists($key)
|
||||
{
|
||||
return $this->db
|
||||
->where(config_item('rest_key_column'), $key)
|
||||
->count_all_results(config_item('rest_keys_table')) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert a key
|
||||
*
|
||||
* @access private
|
||||
* @param string $key The API-Key.
|
||||
* @param array $data The API-Key-Data.
|
||||
* @return bool
|
||||
*/
|
||||
private function _insert_key($key, $data)
|
||||
{
|
||||
$data[config_item('rest_key_column')] = $key;
|
||||
$data['date_created'] = function_exists('now') ? now() : time();
|
||||
|
||||
return $this->db
|
||||
->set($data)
|
||||
->insert(config_item('rest_keys_table'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a key
|
||||
*
|
||||
* @access private
|
||||
* @param string $key The API-Key.
|
||||
* @param array $data The API-Key-Data.
|
||||
* @return bool
|
||||
*/
|
||||
private function _update_key($key, $data)
|
||||
{
|
||||
return $this->db
|
||||
->where(config_item('rest_key_column'), $key)
|
||||
->update(config_item('rest_keys_table'), $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a key
|
||||
*
|
||||
* @access private
|
||||
* @param string $key The API-Key.
|
||||
* @return bool
|
||||
*/
|
||||
private function _delete_key($key)
|
||||
{
|
||||
return $this->db
|
||||
->where(config_item('rest_key_column'), $key)
|
||||
->delete(config_item('rest_keys_table'));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
defined('BASEPATH') || exit('No direct script access allowed');
|
||||
|
||||
class Kontakt extends REST_Controller
|
||||
class Kontakt extends APIv1_Controller
|
||||
{
|
||||
|
||||
//public $session;
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
<?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 Nation extends APIv1_Controller
|
||||
{
|
||||
/**
|
||||
* Course API constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
// Load model PersonModel
|
||||
$this->load->model('nation_model', 'NationModel');
|
||||
// Load set the addonID of the model to let to check the permissions
|
||||
$this->NationModel->setAddonID($this->_getAddonID());
|
||||
}
|
||||
|
||||
public function getAll()
|
||||
{
|
||||
$result = $this->NationModel->getAll($this->get('ohnesperre'), $this->get('orderEnglish'));
|
||||
|
||||
if(is_object($result))
|
||||
{
|
||||
$payload = [
|
||||
'success' => TRUE,
|
||||
'message' => 'Nation found',
|
||||
'data' => $result->result()
|
||||
];
|
||||
$httpstatus = REST_Controller::HTTP_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
$payload = [
|
||||
'success' => FALSE,
|
||||
'message' => 'Nation not found'
|
||||
];
|
||||
$httpstatus = REST_Controller::HTTP_OK;
|
||||
}
|
||||
|
||||
$this->response($payload, $httpstatus);
|
||||
}
|
||||
|
||||
public function getBundesland()
|
||||
{
|
||||
$result = $this->NationModel->getBundesland();
|
||||
|
||||
if(is_object($result))
|
||||
{
|
||||
$payload = [
|
||||
'success' => TRUE,
|
||||
'message' => 'Bundesland found',
|
||||
'data' => $result->result()
|
||||
];
|
||||
$httpstatus = REST_Controller::HTTP_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
$payload = [
|
||||
'success' => FALSE,
|
||||
'message' => 'Bundesland not found'
|
||||
];
|
||||
$httpstatus = REST_Controller::HTTP_OK;
|
||||
}
|
||||
|
||||
$this->response($payload, $httpstatus);
|
||||
}
|
||||
}
|
||||
@@ -1,207 +0,0 @@
|
||||
<?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
|
||||
*/
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
defined('BASEPATH') || exit('No direct script access allowed');
|
||||
|
||||
class Person extends APIv1_Controller
|
||||
{
|
||||
|
||||
//public $session;
|
||||
/**
|
||||
* Person API constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->load->model('person/person_model');
|
||||
}
|
||||
|
||||
public function person_get()
|
||||
{
|
||||
//if (!$this->session_model->validate($this->get('session_id'), $this->get('device_id')))
|
||||
// $this->response(array(['success' => false, 'message' => 'access denied']), REST_Controller::HTTP_UNAUTHORIZED);
|
||||
|
||||
$code = $this->get('code');
|
||||
$email = $this->get('email');
|
||||
$person_id = $this->get('person_id');
|
||||
|
||||
if ((!is_null($code)) && (!is_null($email)))
|
||||
{
|
||||
$result = $this->person_model->getPersonByCodeAndEmail($code, $email);
|
||||
}
|
||||
elseif (! is_null($code))
|
||||
{
|
||||
$result = $this->person_model->getPersonByCode($code, $email);
|
||||
}
|
||||
elseif (!is_null($person_id))
|
||||
{
|
||||
$result = $this->person_model->getPerson($person_id);
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = $this->person_model->getPerson();
|
||||
}
|
||||
|
||||
if (empty($result))
|
||||
{
|
||||
$payload = [
|
||||
'success' => false,
|
||||
'message' => 'Person not found'
|
||||
];
|
||||
$httpstatus = REST_Controller::HTTP_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
// return all available persons
|
||||
$payload = [
|
||||
'success' => true,
|
||||
'message' => 'Persons found'
|
||||
];
|
||||
$payload['data'] = $result;
|
||||
$httpstatus = REST_Controller::HTTP_OK;
|
||||
}
|
||||
|
||||
// Set the response and exit
|
||||
$this->response($payload, $httpstatus);
|
||||
}
|
||||
|
||||
public function personFromCode_post()
|
||||
{
|
||||
$code = $this->post('code');
|
||||
$email = $this->post('email');
|
||||
$person_id = $this->post('person_id');
|
||||
|
||||
if ((!is_null($code)) && (!is_null($email)))
|
||||
{
|
||||
$result = $this->person_model->getPersonByCodeAndEmail($code, $email);
|
||||
}
|
||||
elseif (!is_null($person_id))
|
||||
{
|
||||
$result = $this->person_model->getPerson($person_id);
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = $this->person_model->getPerson();
|
||||
}
|
||||
|
||||
if (empty($result))
|
||||
{
|
||||
$payload = [
|
||||
'success' => false,
|
||||
'message' => 'Person not found'
|
||||
];
|
||||
$httpstatus = REST_Controller::HTTP_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
// return all available persons
|
||||
$payload = [
|
||||
'success' => true,
|
||||
'message' => 'Persons found'
|
||||
];
|
||||
$payload['data'] = $result;
|
||||
$httpstatus = REST_Controller::HTTP_OK;
|
||||
}
|
||||
|
||||
// Set the response and exit
|
||||
$this->response($payload, $httpstatus);
|
||||
}
|
||||
|
||||
public function person_post()
|
||||
{
|
||||
$result = $this->person_model->savePerson($this->post());
|
||||
if($result != FALSE)
|
||||
{
|
||||
$httpstatus = REST_Controller::HTTP_OK;
|
||||
$payload = [
|
||||
'success' => true,
|
||||
'message' => 'Person saved.'
|
||||
];
|
||||
$payload['data'] = $result;
|
||||
}
|
||||
else
|
||||
{
|
||||
$payload = [
|
||||
'success' => false,
|
||||
'message' => 'Could not save person.'
|
||||
];
|
||||
$httpstatus = REST_Controller::HTTP_OK;
|
||||
}
|
||||
|
||||
$this->response($payload, $httpstatus);
|
||||
}
|
||||
|
||||
public function personUpdate_post()
|
||||
{
|
||||
$result = $this->person_model->updatePerson($this->post());
|
||||
if($result != FALSE)
|
||||
{
|
||||
$httpstatus = REST_Controller::HTTP_OK;
|
||||
$payload = [
|
||||
'success' => true,
|
||||
'message' => 'Person updated.'
|
||||
];
|
||||
$payload['data'] = $result;
|
||||
}
|
||||
else
|
||||
{
|
||||
$payload = [
|
||||
'success' => false,
|
||||
'message' => 'Could not update person.'
|
||||
];
|
||||
$httpstatus = REST_Controller::HTTP_OK;
|
||||
}
|
||||
//
|
||||
$this->response($payload, $httpstatus);
|
||||
}
|
||||
|
||||
public function checkBewerbung_get()
|
||||
{
|
||||
$result = $this->person_model->checkBewerbung($this->get("email"),$this->get("studiensemester_kurzbz"));
|
||||
$httpstatus = REST_Controller::HTTP_OK;
|
||||
$payload = [
|
||||
'success' => true,
|
||||
'message' => 'Bewerbung exists.'
|
||||
];
|
||||
$payload['data'] = $result;
|
||||
|
||||
$this->response($payload, $httpstatus);
|
||||
}
|
||||
|
||||
public function checkZugangscodePerson_get()
|
||||
{
|
||||
$result = $this->person_model->checkZugangscodePerson($this->get("code"));
|
||||
$httpstatus = REST_Controller::HTTP_OK;
|
||||
if(!empty($result))
|
||||
{
|
||||
$payload = [
|
||||
'success' => true,
|
||||
'message' => 'Zugangscode exists.'
|
||||
];
|
||||
$payload['data'] = $result;
|
||||
}
|
||||
else
|
||||
{
|
||||
$payload = [
|
||||
'success' => false,
|
||||
'message' => 'Zugangscode does not exist.'
|
||||
];
|
||||
$httpstatus = REST_Controller::HTTP_OK;
|
||||
}
|
||||
|
||||
$this->response($payload, $httpstatus);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
defined('BASEPATH') || exit('No direct script access allowed');
|
||||
|
||||
//require_once APPPATH . '/libraries/REST_Controller.php';
|
||||
|
||||
/**
|
||||
* Testing class for REST calls and authentication
|
||||
*/
|
||||
class Test extends APIv1_Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test HTTP GET method
|
||||
* It responses whith the HTTP status 200 and prints this JSON string
|
||||
* {"success":true,"message":"API HTTP GET call test succeed"}
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getTest()
|
||||
{
|
||||
$payload = [
|
||||
'success' => TRUE,
|
||||
'message' => 'API HTTP GET call test succeed'
|
||||
];
|
||||
$httpstatus = REST_Controller::HTTP_OK;
|
||||
$this->response($payload, $httpstatus);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test HTTP POST method
|
||||
* * It responses whith the HTTP status 200 and prints this JSON string
|
||||
* {"success":true,"message":"API HTTP POST call test succeed"}
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function postTest()
|
||||
{
|
||||
$payload = [
|
||||
'success' => TRUE,
|
||||
'message' => 'API HTTP POST call test succeed'
|
||||
];
|
||||
$httpstatus = REST_Controller::HTTP_OK;
|
||||
$this->response($payload, $httpstatus);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?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 Studiengang extends APIv1_Controller
|
||||
{
|
||||
/**
|
||||
* Course API constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
// Load model PersonModel
|
||||
$this->load->model('lehre/studiengang_model', 'StudiengangModel');
|
||||
// Load set the addonID of the model to let to check the permissions
|
||||
$this->StudiengangModel->setAddonID($this->_getAddonID());
|
||||
}
|
||||
|
||||
public function getAllForBewerbung()
|
||||
{
|
||||
$result = $this->StudiengangModel->getAllForBewerbung();
|
||||
|
||||
if(is_object($result) && $result->num_rows() > 0)
|
||||
{
|
||||
$payload = [
|
||||
'success' => TRUE,
|
||||
'message' => 'Courses found',
|
||||
'data' => $result->result()
|
||||
];
|
||||
$httpstatus = REST_Controller::HTTP_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
$payload = [
|
||||
'success' => FALSE,
|
||||
'message' => 'No courses found'
|
||||
];
|
||||
$httpstatus = REST_Controller::HTTP_OK;
|
||||
}
|
||||
|
||||
$this->response($payload, $httpstatus);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?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 Studienplan extends APIv1_Controller
|
||||
{
|
||||
/**
|
||||
* Course API constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
// Load model PersonModel
|
||||
$this->load->model('lehre/studienplan_model', 'StudienplanModel');
|
||||
// Load set the addonID of the model to let to check the permissions
|
||||
$this->StudienplanModel->setAddonID($this->_getAddonID());
|
||||
}
|
||||
|
||||
public function getStudienplaene()
|
||||
{
|
||||
$result = $this->StudienplanModel->getStudienplaene($this->get('studiengang_kz'));
|
||||
|
||||
if(is_object($result) && $result->num_rows() > 0)
|
||||
{
|
||||
$payload = [
|
||||
'success' => TRUE,
|
||||
'message' => 'Plan found',
|
||||
'data' => $result->result()
|
||||
];
|
||||
$httpstatus = REST_Controller::HTTP_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
$payload = [
|
||||
'success' => FALSE,
|
||||
'message' => 'Plan not found'
|
||||
];
|
||||
$httpstatus = REST_Controller::HTTP_OK;
|
||||
}
|
||||
|
||||
$this->response($payload, $httpstatus);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* FH-Complete
|
||||
*
|
||||
@@ -13,97 +12,62 @@
|
||||
*/
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if (! defined('BASEPATH'))
|
||||
exit('No direct script access allowed');
|
||||
if(!defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
class Person extends APIv1_Controller
|
||||
{
|
||||
/**
|
||||
* Person API constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
/**
|
||||
* Person API constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->model('person/person_model');
|
||||
}
|
||||
// Load model PersonModel
|
||||
$this->load->model('person/person_model', 'PersonModel');
|
||||
// Load set the addonID of the model to let to check the permissions
|
||||
$this->PersonModel->setAddonID($this->_getAddonID());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function person_get()
|
||||
{
|
||||
//if(!$this->session_model->validate($this->get('session_id'), $this->get('device_id')))
|
||||
// $this->response(array(['success' => false, 'message' => 'access denied']), REST_Controller::HTTP_UNAUTHORIZED);
|
||||
|
||||
public function getPerson()
|
||||
{
|
||||
$personID = $this->get('person_id');
|
||||
$code = $this->get('code');
|
||||
$email = $this->get('email');
|
||||
$person_id = $this->get('person_id');
|
||||
|
||||
if ((!is_null($code)) && (!is_null($email)))
|
||||
{
|
||||
$result = $this->person_model->getPersonByCodeAndEmail($code, $email);
|
||||
}
|
||||
elseif (! is_null($code))
|
||||
{
|
||||
$result = $this->person_model->getPersonByCode($code);
|
||||
}
|
||||
elseif (! is_null($person_id))
|
||||
{
|
||||
$result = $this->person_model->getPerson($person_id);
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = $this->person_model->getPerson();
|
||||
}
|
||||
$result = $this->PersonModel->getPerson($personID, $code, $email);
|
||||
|
||||
if ($result['err'])
|
||||
{
|
||||
$payload = [
|
||||
'success' => false,
|
||||
'message' => $result['msg'].': '.$result['retval']
|
||||
];
|
||||
$httpstatus = REST_Controller::HTTP_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
// return all available persons
|
||||
$payload = [
|
||||
'success' => true,
|
||||
'message' => 'Persons found'
|
||||
];
|
||||
$payload['data'] = $result;
|
||||
$httpstatus = REST_Controller::HTTP_OK;
|
||||
}
|
||||
|
||||
if (empty($result))
|
||||
if(is_object($result) && $result->num_rows() > 0)
|
||||
{
|
||||
$payload = [
|
||||
'success' => false,
|
||||
'message' => 'Person not found'
|
||||
'success' => TRUE,
|
||||
'message' => 'Person found',
|
||||
'data' => $result->result()
|
||||
];
|
||||
$httpstatus = REST_Controller::HTTP_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
// return all available persons
|
||||
$payload = [
|
||||
'success' => true,
|
||||
'message' => 'Persons found'
|
||||
'success' => FALSE,
|
||||
'message' => 'Person not found'
|
||||
];
|
||||
$payload['data'] = $result;
|
||||
$httpstatus = REST_Controller::HTTP_OK;
|
||||
}
|
||||
// Set the response and exit
|
||||
|
||||
$this->response($payload, $httpstatus);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function person_post()
|
||||
{
|
||||
$result = $this->person_model->savePerson($this->post());
|
||||
if ($result != false)
|
||||
public function postPerson()
|
||||
{
|
||||
$result = $this->PersonModel->savePerson($this->post());
|
||||
|
||||
if($result === TRUE)
|
||||
{
|
||||
$httpstatus = REST_Controller::HTTP_OK;
|
||||
$payload = [
|
||||
@@ -121,40 +85,40 @@ class Person extends APIv1_Controller
|
||||
$httpstatus = REST_Controller::HTTP_OK;
|
||||
}
|
||||
$this->response($payload, $httpstatus);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function personUpdate_post()
|
||||
{
|
||||
$result = $this->person_model->updatePerson($this->post());
|
||||
if ($result != false)
|
||||
public function postPrestudent()
|
||||
{
|
||||
$result = $this->PersonModel->savePrestudent($this->post());
|
||||
|
||||
if($result === TRUE)
|
||||
{
|
||||
$httpstatus = REST_Controller::HTTP_OK;
|
||||
$payload = [
|
||||
'success' => true,
|
||||
'message' => 'Person updated.'
|
||||
'message' => 'Interested student saved.'
|
||||
];
|
||||
$payload['data'] = $result;
|
||||
}
|
||||
else
|
||||
{
|
||||
$payload = [
|
||||
'success' => false,
|
||||
'message' => 'Could not update person.'
|
||||
'message' => 'Could not save interested student.'
|
||||
];
|
||||
$httpstatus = REST_Controller::HTTP_OK;
|
||||
}
|
||||
$this->response($payload, $httpstatus);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function checkBewerbung_get()
|
||||
{
|
||||
$result = $this->person_model->checkBewerbung($this->get("email"), $this->get("studiensemester_kurzbz"));
|
||||
public function getCheckBewerbung()
|
||||
{
|
||||
$result = $this->PersonModel->checkBewerbung($this->get("email"), $this->get("studiensemester_kurzbz"));
|
||||
$httpstatus = REST_Controller::HTTP_OK;
|
||||
$payload = [
|
||||
'success' => true,
|
||||
@@ -162,16 +126,16 @@ class Person extends APIv1_Controller
|
||||
];
|
||||
$payload['data'] = $result;
|
||||
$this->response($payload, $httpstatus);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function checkZugangscodePerson_get()
|
||||
{
|
||||
$result = $this->person_model->checkZugangscodePerson($this->get("code"));
|
||||
public function getCheckZugangscodePerson()
|
||||
{
|
||||
$result = $this->PersonModel->checkZugangscodePerson($this->get("code"));
|
||||
$httpstatus = REST_Controller::HTTP_OK;
|
||||
if (!empty($result))
|
||||
if(!empty($result))
|
||||
{
|
||||
$payload = [
|
||||
'success' => true,
|
||||
@@ -189,5 +153,5 @@ class Person extends APIv1_Controller
|
||||
}
|
||||
|
||||
$this->response($payload, $httpstatus);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
<?php
|
||||
class Kontakt extends FHC_Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->model('kontakt/kontakt_model');
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$data['person'] = $this->person_model->getPersonen();
|
||||
$data['title'] = 'Personen Archiv';
|
||||
|
||||
$this->load->view('templates/header', $data);
|
||||
$this->load->view('kontakt/index', $data);
|
||||
$this->load->view('templates/footer');
|
||||
}
|
||||
|
||||
public function view($slug = null)
|
||||
{
|
||||
$data['person_item'] = $this->person_model->getPersonen($slug);
|
||||
if (empty($data['person_item']))
|
||||
show_404();
|
||||
|
||||
$data['title'] = $data['person_item']->titelpre;
|
||||
|
||||
$this->load->view('templates/header', $data);
|
||||
$this->load->view('kontakt/view', $data);
|
||||
$this->load->view('templates/footer');
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
<?php
|
||||
class Person extends FHC_Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->model('person/person_model');
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$data['person'] = $this->person_model->getPersonen();
|
||||
$data['title'] = 'Personen Archiv';
|
||||
|
||||
$this->load->view('templates/header', $data);
|
||||
$this->load->view('person/index', $data);
|
||||
$this->load->view('templates/footer');
|
||||
}
|
||||
|
||||
public function view($slug = null)
|
||||
{
|
||||
$data['person_item'] = $this->person_model->getPersonen($slug);
|
||||
if (empty($data['person_item']))
|
||||
show_404();
|
||||
|
||||
$data['title'] = $data['person_item']->titelpre;
|
||||
|
||||
$this->load->view('templates/header', $data);
|
||||
$this->load->view('person/view', $data);
|
||||
$this->load->view('templates/footer');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
require_once APPPATH . '/libraries/REST_Controller.php';
|
||||
|
||||
class APIv1_Controller extends REST_Controller
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
//$this->load->library('session'); // -> autoload
|
||||
//$this->load->library('database'); -> autoload
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,233 @@
|
||||
<?php
|
||||
|
||||
class DB_Model extends FHC_Model
|
||||
{
|
||||
protected $dbTable; // Name of the DB-Table for CI-Insert, -Update, ...
|
||||
protected $pk; // Name of the PrimaryKey for DB-Update, Load, ...
|
||||
protected $acl; // Name of the PrimaryKey for DB-Update, Load, ...
|
||||
|
||||
// Addon ID, stored to let to check the permissions
|
||||
private $_addonID;
|
||||
|
||||
function __construct($dbTable = null, $pk = null)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->dbTable = $dbTable;
|
||||
$this->pk = $pk;
|
||||
$this->load->database();
|
||||
$this->acl = $this->config->item('fhc_acl');
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------------------
|
||||
* Insert Data into DB-Table
|
||||
*
|
||||
* @param array $data DataArray for Insert
|
||||
* @return array
|
||||
*/
|
||||
public function insert($data)
|
||||
{
|
||||
// Check Class-Attributes
|
||||
if(is_null($this->dbTable))
|
||||
return $this->_error(lang('fhc_'.FHC_NODBTABLE), FHC_MODEL_ERROR);
|
||||
|
||||
// Check rights
|
||||
if (! $this->fhc_db_acl->isBerechtigt((string)($this->acl[$this->dbTable]), 'i'))
|
||||
return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> '.$this->acl[$this->dbTable], FHC_MODEL_ERROR);
|
||||
|
||||
// DB-INSERT
|
||||
if ($this->db->insert($this->dbTable, $data))
|
||||
return $this->_success($this->db->insert_id());
|
||||
else
|
||||
return $this->_error($this->db->error(), FHC_DB_ERROR);
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------------------
|
||||
* Replace Data in DB-Table
|
||||
*
|
||||
* @param array $data DataArray for Replacement
|
||||
* @return array
|
||||
*/
|
||||
public function replace($data)
|
||||
{
|
||||
// Check Class-Attributes
|
||||
if(is_null($this->dbTable))
|
||||
return $this->_error(lang('fhc_'.FHC_NODBTABLE), FHC_MODEL_ERROR);
|
||||
|
||||
// Check rights
|
||||
if (! $this->fhc_db_acl->isBerechtigt((string)($this->acl[$this->dbTable]), 'ui'))
|
||||
return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> '.$this->acl[$this->dbTable], FHC_MODEL_ERROR);
|
||||
|
||||
// DB-REPLACE
|
||||
if ($this->db->replace($this->dbTable, $data))
|
||||
return $this->_success($this->db->insert_id());
|
||||
else
|
||||
return $this->_error($this->db->error(), FHC_DB_ERROR);
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------------------
|
||||
* Update Data in DB-Table
|
||||
*
|
||||
* @param string $id PK for DB-Table
|
||||
* @param array $data DataArray for Insert
|
||||
* @return array
|
||||
*/
|
||||
public function update($id, $data)
|
||||
{
|
||||
// Check Class-Attributes
|
||||
if(is_null($this->dbTable))
|
||||
return $this->_error(lang('fhc_'.FHC_NODBTABLE), FHC_MODEL_ERROR);
|
||||
if(is_null($this->pk))
|
||||
return $this->_error(lang('fhc_'.FHC_NOPK), FHC_MODEL_ERROR);
|
||||
|
||||
// Check rights
|
||||
if (! $this->fhc_db_acl->isBerechtigt((string)($this->acl[$this->dbTable]), 'u'))
|
||||
return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> '.$this->acl[$this->dbTable], FHC_MODEL_ERROR);
|
||||
|
||||
// DB-UPDATE
|
||||
$this->db->where($this->pk, $id);
|
||||
if ($this->db->update($this->dbTable, $data))
|
||||
return $this->_success($id);
|
||||
else
|
||||
return $this->_error($this->db->error(), FHC_DB_ERROR);
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------------------
|
||||
* Load data from DB-Table
|
||||
*
|
||||
* @param string $id Primary Key for SELECT
|
||||
* @return array
|
||||
*/
|
||||
public function load($id)
|
||||
{
|
||||
// Check Class-Attributes
|
||||
if(is_null($this->dbTable))
|
||||
return $this->_error(lang('fhc_'.FHC_NODBTABLE), FHC_MODEL_ERROR);
|
||||
if(is_null($this->pk))
|
||||
return $this->_error(lang('fhc_'.FHC_NOPK), FHC_MODEL_ERROR);
|
||||
|
||||
// Check rights
|
||||
if (! $this->fhc_db_acl->isBerechtigt((string)($this->acl[$this->dbTable]), 's'))
|
||||
return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> '.$this->acl[$this->dbTable], FHC_MODEL_ERROR);
|
||||
|
||||
// DB-SELECT
|
||||
$result = $this->db->get_where($this->dbTable, array($this->pk => $id));
|
||||
//var_dump($result);
|
||||
if ($result)
|
||||
return $this->_success($result);
|
||||
else
|
||||
return $this->_error($this->db->error(), FHC_DB_ERROR);
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------------------
|
||||
* Delete data from DB-Table
|
||||
*
|
||||
* @param string $id Primary Key for DELETE
|
||||
* @return array
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
// Check Class-Attributes
|
||||
if(is_null($this->dbTable))
|
||||
return $this->_error(lang('fhc_'.FHC_NODBTABLE), FHC_MODEL_ERROR);
|
||||
if(is_null($this->pk))
|
||||
return $this->_error(lang('fhc_'.FHC_NOPK), FHC_MODEL_ERROR);
|
||||
|
||||
// Check rights
|
||||
if (! $this->fhc_db_acl->isBerechtigt($this->acl[$this->dbTable], 'd'))
|
||||
return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> '.$this->acl[$this->dbTable], FHC_MODEL_ERROR);
|
||||
|
||||
// DB-DELETE
|
||||
if ($this->db->delete($this->dbTable, array($this->pk => $id)))
|
||||
return $this->_success($id);
|
||||
else
|
||||
return $this->_error($this->db->error(), FHC_DB_ERROR);
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------------------
|
||||
* Convert PG-Array to PHP-Array
|
||||
*
|
||||
* @param integer config.php error code numbers
|
||||
* @return array
|
||||
*/
|
||||
public function pgArrayPhp($s,$start=0,&$end=NULL)
|
||||
{
|
||||
if (empty($s) || $s[0]!='{') return NULL;
|
||||
$return = array();
|
||||
$br = 0;
|
||||
$string = false;
|
||||
$quote='';
|
||||
$len = strlen($s);
|
||||
$v = '';
|
||||
for($i=$start+1; $i<$len;$i++)
|
||||
{
|
||||
$ch = $s[$i];
|
||||
if (!$string && $ch=='}')
|
||||
{
|
||||
if ($v!=='' || !empty($return))
|
||||
$return[] = $v;
|
||||
$end = $i;
|
||||
break;
|
||||
}
|
||||
else
|
||||
if (!$string && $ch=='{')
|
||||
$v = $this->pgArrayPhp($s,$i,$i);
|
||||
else
|
||||
if (!$string && $ch==',')
|
||||
{
|
||||
$return[] = $v;
|
||||
$v = '';
|
||||
}
|
||||
else
|
||||
if (!$string && ($ch=='"' || $ch=="'"))
|
||||
{
|
||||
$string = TRUE;
|
||||
$quote = $ch;
|
||||
}
|
||||
else
|
||||
if ($string && $ch==$quote && $s[$i-1]=="\\")
|
||||
$v = substr($v,0,-1).$ch;
|
||||
else
|
||||
if ($string && $ch==$quote && $s[$i-1]!="\\")
|
||||
$string = FALSE;
|
||||
else
|
||||
$v .= $ch;
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------------------
|
||||
* Invalid ID
|
||||
*
|
||||
* @param integer config.php error code numbers
|
||||
* @return array
|
||||
*/
|
||||
protected function _invalid_id($error = '')
|
||||
{
|
||||
return array(
|
||||
'err' => 1,
|
||||
'code' => $error,
|
||||
'msg' => lang('fhc_' . $error)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method setAddonID
|
||||
*
|
||||
* @param $addonID
|
||||
* @return void
|
||||
*/
|
||||
public function setAddonID($addonID)
|
||||
{
|
||||
$this->_addonID = $addonID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method getAddonID
|
||||
*
|
||||
* @return string _addonID
|
||||
*/
|
||||
public function getAddonID()
|
||||
{
|
||||
return $this->_addonID;
|
||||
}
|
||||
}
|
||||
@@ -8,17 +8,4 @@ class FHC_Controller extends CI_Controller
|
||||
parent::__construct();
|
||||
//$this->load->helper('language');
|
||||
}
|
||||
}
|
||||
|
||||
require_once APPPATH . '/libraries/REST_Controller.php';
|
||||
|
||||
class APIv1_Controller extends REST_Controller
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
//$this->load->library('session'); -> autoload
|
||||
//$this->load->library('database'); -> autoload
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,93 +1,50 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
class FHC_Model extends CI_Model
|
||||
class FHC_Model extends CI_Model
|
||||
{
|
||||
//protected errormsg;
|
||||
function __construct()
|
||||
function __construct($uid = null)
|
||||
{
|
||||
parent::__construct();
|
||||
parent::__construct();
|
||||
$this->load->helper('language');
|
||||
$this->lang->load('fhcomplete');
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------------------
|
||||
* Success
|
||||
*
|
||||
* @param mixed $retval
|
||||
* @return array
|
||||
*/
|
||||
protected function _success($retval = '', $message = FHC_SUCCESS)
|
||||
{
|
||||
return array(
|
||||
'err' => 0,
|
||||
'code' => FHC_SUCCESS,
|
||||
'msg' => lang('fhc_' . $message),
|
||||
'retval' => $retval
|
||||
);
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------------------
|
||||
* General Error
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function _general_error($retval = '', $message = FHC_ERR_GENERAL)
|
||||
{
|
||||
return array(
|
||||
'err' => 1,
|
||||
'code' => FHC_ERR_GENERAL,
|
||||
'msg' => lang('fhc_'.$message),
|
||||
'retval' => $retval
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class DB_Model extends FHC_Model
|
||||
{
|
||||
|
||||
protected $dbTable=null; // Name of the DB-Table for CI-Insert, -Update, ...
|
||||
|
||||
function __construct($uid=null)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->database();
|
||||
$this->load->helper('language');
|
||||
$this->lang->load('fhc_db');
|
||||
|
||||
// UID must be set in Production Mode
|
||||
if (ENVIRONMENT=='production' && is_null($uid))
|
||||
log_message('error', 'UID must be set in Production Mode.');
|
||||
elseif (is_null($uid))
|
||||
log_message('info', 'UID is not set.');
|
||||
|
||||
// Loading Tools for Access Control (Benutzerberechtigungen)
|
||||
$this->lang->load('fhc_model');
|
||||
//$this->load->helper('fhc_db_acl');
|
||||
$this->lang->load('fhcomplete');
|
||||
//$this->load->library('session');
|
||||
if (is_null($uid))
|
||||
$uid = $this->session->uid;
|
||||
$this->load->library('FHC_DB_ACL',array('uid' => $uid));
|
||||
}
|
||||
|
||||
public function insert($data)
|
||||
{
|
||||
if (! is_null($this->dbTable))
|
||||
{
|
||||
$this->db->insert($this->dbTable, $data);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------------------
|
||||
* Invalid ID
|
||||
*
|
||||
* @param integer config.php error code numbers
|
||||
* @return array
|
||||
*/
|
||||
protected function _invalid_id($error = '')
|
||||
{
|
||||
return array(
|
||||
'err' => 1,
|
||||
'code' => $error,
|
||||
'msg' => lang('fhc_'.$error)
|
||||
);
|
||||
}
|
||||
* Success
|
||||
*
|
||||
* @param mixed $retval
|
||||
* @return array
|
||||
*/
|
||||
protected function _success($retval, $message = FHC_SUCCESS)
|
||||
{
|
||||
$return = new stdClass();
|
||||
$return->error = EXIT_SUCCESS;
|
||||
$return->code = $message;
|
||||
$return->msg = lang('fhc_' . $message);
|
||||
$return->retval = $retval;
|
||||
return $return;
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------------------
|
||||
* General Error
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function _error($retval = '', $message = FHC_MODEL_ERROR)
|
||||
{
|
||||
$return = new stdClass();
|
||||
$return->error = EXIT_MODEL;
|
||||
$return->code = $message;
|
||||
$return->msg = lang('fhc_' . $message);
|
||||
$return->retval = $retval;
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
//require_once(FCPATH.'include/benutzerberechtigung.class.php');
|
||||
|
||||
function isAllowed($uid, $berechtigung_kurzbz, $art = NULL, $oe_kurzbz = NULL, $kostenstelle_id = NULL)
|
||||
{
|
||||
/*$bb = benutzerberechtigung();
|
||||
$bb->getBerechtigungen($uid);
|
||||
return $bb->isBerechtigt($berechtigung_kurzbz, $art, $oe_kurzbz, $kostenstelle_id);*/
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@@ -428,3 +428,23 @@ function indexSort($a, $b)
|
||||
{
|
||||
return strcmp($a->index, $b->index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Bereitet ein Array von Elementen auf, damit es in der IN-Klausel eines
|
||||
* Select Befehls verwendet werden kann.
|
||||
*/
|
||||
function dbImplode4SQL($array)
|
||||
{
|
||||
$string = '';
|
||||
|
||||
foreach($array as $row)
|
||||
{
|
||||
if($string != '')
|
||||
{
|
||||
$string.=',';
|
||||
}
|
||||
$string.=$this->db_add_param($row);
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
<?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!';
|
||||
|
||||
@@ -2,4 +2,4 @@
|
||||
|
||||
// Account Creation
|
||||
$lang['fhc_'.FHC_SUCCESS] = 'Erfolgreich';
|
||||
$lang['fhc_'.FHC_ERR_GENERAL] = 'Fehler';
|
||||
$lang['fhc_'.FHC_ERROR] = 'Fehler';
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
if ( ! defined('BASEPATH'))
|
||||
exit('No direct script access allowed');
|
||||
|
||||
// DB-Errormessages
|
||||
$lang['fhc_'.FHC_MODEL_ERROR] = 'Error in Model';
|
||||
$lang['fhc_'.FHC_NODBTABLE] = 'dbTable is not set!';
|
||||
$lang['fhc_'.FHC_NORIGHT] = 'rights are missing!';
|
||||
@@ -2,4 +2,4 @@
|
||||
|
||||
// Account Creation
|
||||
$lang['fhc_'.FHC_SUCCESS] = 'Success';
|
||||
$lang['fhc_'.FHC_ERR_GENERAL] = 'Error';
|
||||
$lang['fhc_'.FHC_ERROR] = 'Error';
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
require_once FCPATH.'include/authentication.class.php';
|
||||
require_once FCPATH.'include/AddonAuthentication.php';
|
||||
|
||||
/**
|
||||
* FHC-Auth Helpers
|
||||
@@ -32,20 +33,31 @@ class FHC_Auth
|
||||
*
|
||||
* @param string $username
|
||||
* @param string $password
|
||||
* @return bool
|
||||
* @return bool
|
||||
*/
|
||||
function auth($username, $password)
|
||||
public function basicAuthentication($username, $password)
|
||||
{
|
||||
$auth = new authentication();
|
||||
if ($auth->checkpassword($username, $password))
|
||||
if($auth->checkpassword($username, $password))
|
||||
{
|
||||
//echo 'Auth-Method-True';
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
//echo 'Auth-Method-False';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the md5 hashed password by the addon username
|
||||
*
|
||||
* @param string $username addon username
|
||||
* @return string md5 hashed string
|
||||
*/
|
||||
public function digestAuthentication($username)
|
||||
{
|
||||
$aam = new AddonAuthentication();
|
||||
|
||||
return md5($aam->getPasswordByUsername($username));
|
||||
}
|
||||
}
|
||||
@@ -43,10 +43,10 @@ class FHC_DB_ACL
|
||||
* @param string $password
|
||||
* @return bool
|
||||
*/
|
||||
function __construct($uid)
|
||||
function __construct($param)
|
||||
{
|
||||
$this->bb = new benutzerberechtigung();
|
||||
$this->uid = $uid;
|
||||
$this->uid = $param['uid'];
|
||||
}
|
||||
|
||||
function isBerechtigt($berechtigung_kurzbz, $art=null, $oe_kurzbz=null, $kostenstelle_id=null)
|
||||
|
||||
@@ -351,8 +351,13 @@ abstract class REST_Controller extends CI_Controller {
|
||||
self::HTTP_INTERNAL_SERVER_ERROR => 'INTERNAL SERVER ERROR',
|
||||
self::HTTP_NOT_IMPLEMENTED => 'NOT IMPLEMENTED'
|
||||
];
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected $_addonID = NULL;
|
||||
|
||||
/**
|
||||
/**
|
||||
* Extend this function to apply additional checking early on in the process
|
||||
*
|
||||
* @access protected
|
||||
@@ -361,7 +366,7 @@ abstract class REST_Controller extends CI_Controller {
|
||||
protected function early_checks()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constructor for the REST API
|
||||
*
|
||||
@@ -528,7 +533,7 @@ abstract class REST_Controller extends CI_Controller {
|
||||
{
|
||||
$this->_allow = $this->_detect_api_key();
|
||||
}
|
||||
|
||||
|
||||
// Only allow ajax requests
|
||||
if ($this->input->is_ajax_request() === FALSE && $this->config->item('rest_ajax_only'))
|
||||
{
|
||||
@@ -540,7 +545,7 @@ abstract class REST_Controller extends CI_Controller {
|
||||
}
|
||||
|
||||
// When there is no specific override for the current class/method, use the default auth value set in the config
|
||||
if ($this->auth_override === FALSE && !($this->config->item('rest_enable_keys') && $this->_allow === TRUE))
|
||||
if ($this->auth_override === FALSE && ($this->config->item('rest_enable_keys') && $this->_allow === TRUE))
|
||||
{
|
||||
$rest_auth = strtolower($this->config->item('rest_auth'));
|
||||
switch ($rest_auth)
|
||||
@@ -604,8 +609,10 @@ abstract class REST_Controller extends CI_Controller {
|
||||
// Remove the supported format from the function name e.g. index.json => index
|
||||
$object_called = preg_replace('/^(.*)\.(?:' . implode('|', array_keys($this->_supported_formats)) . ')$/', '$1', $object_called);
|
||||
|
||||
$controller_method = $object_called . '_' . $this->request->method;
|
||||
|
||||
//$controller_method = $object_called . '_' . $this->request->method;
|
||||
// CamelCase compliant
|
||||
$controller_method = $this->request->method.ucfirst($object_called);
|
||||
|
||||
// Do we want to log this method (if allowed by config)?
|
||||
$log_method = !(isset($this->methods[$controller_method]['log']) && $this->methods[$controller_method]['log'] === FALSE);
|
||||
|
||||
@@ -1900,6 +1907,25 @@ abstract class REST_Controller extends CI_Controller {
|
||||
], self::HTTP_UNAUTHORIZED);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TO BE COMMENTED
|
||||
*/
|
||||
private function _setAddonID($username)
|
||||
{
|
||||
if(!isset($this->_addonID) && isset($username))
|
||||
{
|
||||
$this->_addonID = $username;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int ID of the authenticated addon
|
||||
*/
|
||||
protected function _getAddonID()
|
||||
{
|
||||
return $this->_addonID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares for basic authentication
|
||||
@@ -1940,6 +1966,10 @@ abstract class REST_Controller extends CI_Controller {
|
||||
{
|
||||
$this->_force_login();
|
||||
}
|
||||
else // If logged
|
||||
{
|
||||
$this->_setAddonID($username);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1978,12 +2008,19 @@ abstract class REST_Controller extends CI_Controller {
|
||||
preg_match_all('@(username|nonce|uri|nc|cnonce|qop|response)=[\'"]?([^\'",]+)@', $digest_string, $matches);
|
||||
$digest = (empty($matches[1]) || empty($matches[2])) ? [] : array_combine($matches[1], $matches[2]);
|
||||
|
||||
// For digest authentication the library function should return already stored md5(username:restrealm:password) for that username @see rest.php::auth_library_function config
|
||||
// For digest authentication the library function should return
|
||||
// already stored password for that username, even if it is hashed
|
||||
$username = $this->_check_login($digest['username'], TRUE);
|
||||
if (array_key_exists('username', $digest) === FALSE || $username === FALSE)
|
||||
// If there no password
|
||||
if (array_key_exists('username', $digest) === FALSE || $username === FALSE || $username === NULL)
|
||||
{
|
||||
$this->_force_login($unique_id);
|
||||
}
|
||||
// If the password was found for this username, generete the string md5('USERNAME:REALM:PASSWORD')
|
||||
else
|
||||
{
|
||||
$username = md5($digest['username'].":".$this->config->item('rest_realm').":".$username);
|
||||
}
|
||||
|
||||
$md5 = md5(strtoupper($this->request->method) . ':' . $digest['uri']);
|
||||
$valid_response = md5($username . ':' . $digest['nonce'] . ':' . $digest['nc'] . ':' . $digest['cnonce'] . ':' . $digest['qop'] . ':' . $md5);
|
||||
@@ -2148,5 +2185,4 @@ abstract class REST_Controller extends CI_Controller {
|
||||
->get($this->config->item('rest_access_table'))
|
||||
->num_rows() > 0;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,629 @@
|
||||
<?php
|
||||
/**
|
||||
* @name CodeIgniter Template Library
|
||||
* @author Jens Segers
|
||||
* @link http://www.jenssegers.be
|
||||
* @license MIT License Copyright (c) 2012 Jens Segers
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
if (!defined("BASEPATH"))
|
||||
exit("No direct script access allowed");
|
||||
|
||||
class Template
|
||||
{
|
||||
|
||||
/* default values */
|
||||
private $_template = 'template';
|
||||
private $_parser = FALSE;
|
||||
private $_cache_ttl = 0;
|
||||
private $_widget_path = '';
|
||||
|
||||
private $_ci;
|
||||
private $_partials = array();
|
||||
|
||||
/**
|
||||
* Construct with configuration array. Codeigniter will use the config file otherwise
|
||||
* @param array $config
|
||||
*/
|
||||
public function __construct($config = array())
|
||||
{
|
||||
$this->_ci = & get_instance();
|
||||
|
||||
// set the default widget path with APPPATH
|
||||
$this->_widget_path = APPPATH . 'widgets/';
|
||||
|
||||
if (!empty($config))
|
||||
$this->initialize($config);
|
||||
|
||||
log_message('debug', 'Template library initialized');
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize with configuration array
|
||||
* @param array $config
|
||||
* @return Template
|
||||
*/
|
||||
public function initialize($config = array())
|
||||
{
|
||||
foreach ($config as $key => $val)
|
||||
$this->{'_' . $key} = $val;
|
||||
|
||||
if ($this->_widget_path == '')
|
||||
$this->_widget_path = APPPATH . 'widgets/';
|
||||
|
||||
if ($this->_parser && !class_exists('CI_Parser'))
|
||||
$this->_ci->load->library('parser');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a partial's content. This will create a new partial when not existing
|
||||
* @param string $index
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function __set($name, $value)
|
||||
{
|
||||
$this->partial($name)->set($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Access to partials for method chaining
|
||||
* @param string $name
|
||||
* @return mixed
|
||||
*/
|
||||
public function __get($name)
|
||||
{
|
||||
return $this->partial($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a partial exists
|
||||
* @param string $index
|
||||
* @return boolean
|
||||
*/
|
||||
public function exists($index)
|
||||
{
|
||||
return array_key_exists($index, $this->_partials);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the template file
|
||||
* @param string $template
|
||||
*/
|
||||
public function set_template($template)
|
||||
{
|
||||
$this->_template = $template;
|
||||
}
|
||||
|
||||
/**
|
||||
* Publish the template with the current partials
|
||||
* You can manually pass a template file with extra data, or use the default template from the config file
|
||||
* @param string $template
|
||||
* @param array $data
|
||||
*/
|
||||
public function publish($template = FALSE, $data = array()) {
|
||||
if (is_array($template) || is_object($template)) {
|
||||
$data = $template;
|
||||
} else if ($template) {
|
||||
$this->_template = $template;
|
||||
}
|
||||
|
||||
if (!$this->_template) {
|
||||
show_error('There was no template file selected for the current template');
|
||||
}
|
||||
|
||||
if (is_array($data) || is_object($data)) {
|
||||
foreach ($data as $name => $content) {
|
||||
$this->partial($name)->set($content);
|
||||
}
|
||||
}
|
||||
|
||||
unset($data);
|
||||
|
||||
if ($this->_parser) {
|
||||
$this->_ci->parser->parse($this->_template, $this->_partials);
|
||||
} else {
|
||||
$this->_ci->load->view($this->_template, $this->_partials);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a partial object with an optional default content
|
||||
* Can be usefull to use straight from the template file
|
||||
* @param string $name
|
||||
* @param string $default
|
||||
* @return Partial
|
||||
*/
|
||||
public function partial($name, $default = FALSE) {
|
||||
if ($this->exists($name)) {
|
||||
$partial = $this->_partials[$name];
|
||||
} else {
|
||||
// create new partial
|
||||
$partial = new Partial($name);
|
||||
if ($this->_cache_ttl) {
|
||||
$partial->cache($this->_cache_ttl);
|
||||
}
|
||||
|
||||
// detect local triggers
|
||||
if (method_exists($this, 'trigger_' . $name)) {
|
||||
$partial->bind($this, 'trigger_' . $name);
|
||||
}
|
||||
|
||||
$this->_partials[$name] = $partial;
|
||||
}
|
||||
|
||||
if (!$partial->content() && $default) {
|
||||
$partial->set($default);
|
||||
}
|
||||
|
||||
return $partial;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a widget object with optional parameters
|
||||
* Can be usefull to use straight from the template file
|
||||
* @param string $name
|
||||
* @param array $data
|
||||
* @return Widget
|
||||
*/
|
||||
public function widget($name, $data = array()) {
|
||||
$class = str_replace('.php', '', trim($name, '/'));
|
||||
|
||||
// determine path and widget class name
|
||||
$path = $this->_widget_path;
|
||||
if (($last_slash = strrpos($class, '/')) !== FALSE) {
|
||||
$path += substr($class, 0, $last_slash);
|
||||
$class = substr($class, $last_slash + 1);
|
||||
}
|
||||
|
||||
// new widget
|
||||
if(!class_exists($class)) {
|
||||
// try both lowercase and capitalized versions
|
||||
foreach (array(ucfirst($class), strtolower($class)) as $class) {
|
||||
if (file_exists($path . $class . '.php')) {
|
||||
include_once ($path . $class . '.php');
|
||||
|
||||
// found the file, stop looking
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!class_exists($class)) {
|
||||
show_error("Widget '" . $class . "' was not found.");
|
||||
}
|
||||
|
||||
return new $class($class, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable cache for all partials with TTL, default TTL is 60
|
||||
* @param int $ttl
|
||||
* @param mixed $identifier
|
||||
*/
|
||||
public function cache($ttl = 60, $identifier = '') {
|
||||
foreach ($this->_partials as $partial) {
|
||||
$partial->cache($ttl, $identifier);
|
||||
}
|
||||
|
||||
$this->_cache_ttl = $ttl;
|
||||
}
|
||||
|
||||
// ---- TRIGGERS -----------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Stylesheet trigger
|
||||
* @param string $source
|
||||
*/
|
||||
public function trigger_stylesheet($url, $attributes = FALSE) {
|
||||
// array support
|
||||
if (is_array($url)) {
|
||||
$return = '';
|
||||
foreach ($url as $u) {
|
||||
$return .= $this->trigger_stylesheet($u, $attributes);
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
if (!stristr($url, 'http://') && !stristr($url, 'https://') && substr($url, 0, 2) != '//') {
|
||||
$url = $this->_ci->config->item('base_url') . $url;
|
||||
}
|
||||
|
||||
// legacy support for media
|
||||
if (is_string($attributes)) {
|
||||
$attributes = array('media' => $attributes);
|
||||
}
|
||||
|
||||
if (is_array($attributes)) {
|
||||
$attributeString = "";
|
||||
|
||||
foreach ($attributes as $key => $value) {
|
||||
$attributeString .= $key . '="' . $value . '" ';
|
||||
}
|
||||
|
||||
return '<link rel="stylesheet" href="' . htmlspecialchars(strip_tags($url)) . '" ' . $attributeString . '>' . "\n\t";
|
||||
} else {
|
||||
return '<link rel="stylesheet" href="' . htmlspecialchars(strip_tags($url)) . '">' . "\n\t";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Javascript trigger
|
||||
* @param string $source
|
||||
*/
|
||||
public function trigger_javascript($url) {
|
||||
// array support
|
||||
if (is_array($url)) {
|
||||
$return = '';
|
||||
foreach ($url as $u) {
|
||||
$return .= $this->trigger_javascript($u);
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
if (!stristr($url, 'http://') && !stristr($url, 'https://') && substr($url, 0, 2) != '//') {
|
||||
$url = $this->_ci->config->item('base_url') . $url;
|
||||
}
|
||||
|
||||
return '<script src="' . htmlspecialchars(strip_tags($url)) . '"></script>' . "\n\t";
|
||||
}
|
||||
|
||||
/**
|
||||
* Meta trigger
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
* @param enum $type
|
||||
*/
|
||||
public function trigger_meta($name, $value, $type = 'meta') {
|
||||
$name = htmlspecialchars(strip_tags($name));
|
||||
$value = htmlspecialchars(strip_tags($value));
|
||||
|
||||
if ($name == 'keywords' and !strpos($value, ',')) {
|
||||
$content = preg_replace('/[\s]+/', ', ', trim($value));
|
||||
}
|
||||
|
||||
switch ($type) {
|
||||
case 'meta' :
|
||||
$content = '<meta name="' . $name . '" content="' . $value . '">' . "\n\t";
|
||||
break;
|
||||
case 'link' :
|
||||
$content = '<link rel="' . $name . '" href="' . $value . '">' . "\n\t";
|
||||
break;
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Title trigger, keeps it clean
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
* @param enum $type
|
||||
*/
|
||||
public function trigger_title($title) {
|
||||
return htmlspecialchars(strip_tags($title));
|
||||
}
|
||||
|
||||
/**
|
||||
* Title trigger, keeps it clean
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
* @param enum $type
|
||||
*/
|
||||
public function trigger_description($description) {
|
||||
return htmlspecialchars(strip_tags($description));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Partial
|
||||
{
|
||||
|
||||
protected $_ci, $_content, $_name, $_cache_ttl = 0, $_cached = false, $_identifier, $_trigger;
|
||||
protected $_args = array();
|
||||
|
||||
/**
|
||||
* Construct with optional parameters
|
||||
* @param array $args
|
||||
*/
|
||||
public function __construct($name, $args = array()) {
|
||||
$this->_ci = &get_instance();
|
||||
$this->_args = $args;
|
||||
$this->_name = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gives access to codeigniter's functions from this class if needed
|
||||
* This will be handy in extending classes
|
||||
* @param string $index
|
||||
*/
|
||||
function __get($name) {
|
||||
return $this->_ci->$name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias methods
|
||||
*/
|
||||
function __call($name, $args) {
|
||||
switch ($name) {
|
||||
case 'default' :
|
||||
return call_user_func_array(array($this, 'set_default'), $args);
|
||||
break;
|
||||
case 'add' :
|
||||
return call_user_func_array(array($this, 'append'), $args);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the content when converted to a string
|
||||
* @return string
|
||||
*/
|
||||
public function __toString() {
|
||||
return (string) $this->content();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the content
|
||||
* @return string
|
||||
*/
|
||||
public function content() {
|
||||
if ($this->_cache_ttl && !$this->_cached) {
|
||||
$this->cache->save($this->cache_id(), $this->_content, $this->_cache_ttl);
|
||||
}
|
||||
|
||||
return $this->_content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overwrite the content
|
||||
* @param mixed $content
|
||||
* @return Partial
|
||||
*/
|
||||
public function set() {
|
||||
if (!$this->_cached) {
|
||||
$this->_content = (string) $this->trigger(func_get_args());
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Append something to the content
|
||||
* @param mixed $content
|
||||
* @return Partial
|
||||
*/
|
||||
public function append() {
|
||||
if (!$this->_cached) {
|
||||
$this->_content .= (string) $this->trigger(func_get_args());
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepend something to the content
|
||||
* @param mixed $content
|
||||
* @return Partial
|
||||
*/
|
||||
public function prepend() {
|
||||
if (!$this->_cached) {
|
||||
$this->_content = (string) $this->trigger(func_get_args()) . $this->_content;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set content if partial is empty
|
||||
* @param mixed $default
|
||||
* @return Partial
|
||||
*/
|
||||
public function set_default($default) {
|
||||
if (!$this->_cached) {
|
||||
if (!$this->_content) {
|
||||
$this->_content = $default;
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a view inside this partial, overwrite if wanted
|
||||
* @param string $view
|
||||
* @param array $data
|
||||
* @param bool $overwrite
|
||||
* @return Partial
|
||||
*/
|
||||
public function view($view, $data = array(), $overwrite = false) {
|
||||
if (!$this->_cached) {
|
||||
|
||||
// better object to array
|
||||
if (is_object($data)) {
|
||||
$array = array();
|
||||
foreach ($data as $k => $v) {
|
||||
$array[$k] = $v;
|
||||
}
|
||||
$data = $array;
|
||||
}
|
||||
|
||||
$content = $this->_ci->load->view($view, $data, true);
|
||||
|
||||
if ($overwrite) {
|
||||
$this->set($content);
|
||||
} else {
|
||||
$this->append($content);
|
||||
}
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a view inside this partial, overwrite if wanted
|
||||
* @param string $view
|
||||
* @param array $data
|
||||
* @param bool $overwrite
|
||||
* @return Partial
|
||||
*/
|
||||
public function parse($view, $data = array(), $overwrite = false) {
|
||||
if (!$this->_cached) {
|
||||
if (!class_exists('CI_Parser')) {
|
||||
$this->_ci->load->library('parser');
|
||||
}
|
||||
|
||||
// better object to array
|
||||
if (is_object($data)) {
|
||||
$array = array();
|
||||
foreach ($data as $k => $v) {
|
||||
$array[$k] = $v;
|
||||
}
|
||||
$data = $array;
|
||||
}
|
||||
|
||||
$content = $this->_ci->parser->parse($view, $data, true);
|
||||
|
||||
if ($overwrite) {
|
||||
$this->set($content);
|
||||
} else {
|
||||
$this->append($content);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a widget inside this partial, overwrite if wanted
|
||||
* @param string $name
|
||||
* @param array $data
|
||||
* @param bool $overwrite
|
||||
* @return Partial
|
||||
*/
|
||||
public function widget($name, $data = array(), $overwrite = false) {
|
||||
if (!$this->_cached) {
|
||||
$widget = $this->template->widget($name, $data);
|
||||
|
||||
if ($overwrite) {
|
||||
$this->set($widget->content());
|
||||
} else {
|
||||
$this->append($widget->content());
|
||||
}
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable cache with TTL, default TTL is 60
|
||||
* @param int $ttl
|
||||
* @param mixed $identifier
|
||||
*/
|
||||
public function cache($ttl = 60, $identifier = '') {
|
||||
if (!class_exists('CI_Cache')) {
|
||||
$this->_ci->load->driver('cache', array('adapter' => 'file'));
|
||||
}
|
||||
|
||||
$this->_cache_ttl = $ttl;
|
||||
$this->_identifier = $identifier;
|
||||
|
||||
if ($cached = $this->_ci->cache->get($this->cache_id())) {
|
||||
$this->_cached = true;
|
||||
$this->_content = $cached;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used for cache identification
|
||||
* @return string
|
||||
*/
|
||||
private function cache_id() {
|
||||
if ($this->_identifier) {
|
||||
return $this->_name . '_' . $this->_identifier . '_' . md5(get_class($this) . implode('', $this->_args));
|
||||
} else {
|
||||
return $this->_name . '_' . md5(get_class($this) . implode('', $this->_args));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger returns the result if a trigger is set
|
||||
* @param array $args
|
||||
* @return string
|
||||
*/
|
||||
public function trigger($args) {
|
||||
if (!$this->_trigger) {
|
||||
return implode('', $args);
|
||||
} else {
|
||||
return call_user_func_array($this->_trigger, $args);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Bind a trigger function
|
||||
* Can be used like bind($this, "function") or bind("function")
|
||||
* @param mixed $arg
|
||||
*/
|
||||
public function bind() {
|
||||
if ($count = func_num_args()) {
|
||||
if ($count >= 2) {
|
||||
$args = func_get_args();
|
||||
$obj = array_shift($args);
|
||||
$func = array_pop($args);
|
||||
|
||||
foreach ($args as $trigger) {
|
||||
$obj = $obj->$trigger;
|
||||
}
|
||||
|
||||
$this->_trigger = array($obj, $func);
|
||||
} else {
|
||||
$args = func_get_args();
|
||||
$this->_trigger = reset($args);
|
||||
}
|
||||
} else {
|
||||
$this->_trigger = FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Widget extends Partial
|
||||
{
|
||||
|
||||
/* (non-PHPdoc)
|
||||
* @see Partial::content()
|
||||
*/
|
||||
public function content() {
|
||||
if (!$this->_cached) {
|
||||
if (method_exists($this, 'display')) {
|
||||
// capture output
|
||||
ob_start();
|
||||
$this->display($this->_args);
|
||||
$buffer = ob_get_clean();
|
||||
|
||||
// if no content is produced but there was direct ouput we set
|
||||
// that output as content
|
||||
if (!$this->_content && $buffer) {
|
||||
$this->set($buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return parent::content();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
class Nation_model extends DB_Model
|
||||
{
|
||||
protected $_bundeslandQuery = "SELECT * FROM bis.tbl_bundesland";
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function getAll($notLocked = FALSE, $orderEnglish = FALSE)
|
||||
{
|
||||
$result = NULL;
|
||||
|
||||
// Checks if the operation is permitted by the API caller
|
||||
// All the code should be put inside this if statement
|
||||
if(isAllowed($this->getAddonID(), 'nation'))
|
||||
{
|
||||
$result = $this->db->query($this->_getNationQuery($notLocked, $orderEnglish));
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected function _getNationQuery($notLocked = FALSE, $orderEnglish = FALSE)
|
||||
{
|
||||
$qry = "SELECT * FROM bis.tbl_nation";
|
||||
|
||||
if($notLocked)
|
||||
{
|
||||
$qry .= " WHERE sperre IS NULL";
|
||||
}
|
||||
if(!$orderEnglish)
|
||||
{
|
||||
$qry .= " ORDER BY kurztext";
|
||||
}
|
||||
else
|
||||
{
|
||||
$qry .= " ORDER BY engltext";
|
||||
}
|
||||
|
||||
return $qry;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function getBundesland()
|
||||
{
|
||||
$result = NULL;
|
||||
|
||||
// Checks if the operation is permitted by the API caller
|
||||
// All the code should be put inside this if statement
|
||||
if(isAllowed($this->getAddonID(), 'nation'))
|
||||
{
|
||||
$result = $this->db->query($this->_bundeslandQuery);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
class Sprache_model extends DB_Model
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->dbTable='public.tbl_sprache';
|
||||
$this->pk='sprache';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
class Studiengang_model extends DB_Model
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function getAllForBewerbung()
|
||||
{
|
||||
$result = NULL;
|
||||
$allForBewerbungQuery = "SELECT DISTINCT studiengang_kz,
|
||||
typ,
|
||||
organisationseinheittyp_kurzbz,
|
||||
studiengangbezeichnung,
|
||||
standort,
|
||||
studiengangbezeichnung_englisch,
|
||||
lgartcode,
|
||||
tbl_lgartcode.bezeichnung
|
||||
FROM lehre.vw_studienplan LEFT JOIN bis.tbl_lgartcode USING (lgartcode)
|
||||
WHERE onlinebewerbung IS TRUE
|
||||
AND aktiv IS TRUE
|
||||
ORDER BY typ, studiengangbezeichnung, tbl_lgartcode.bezeichnung ASC";
|
||||
|
||||
// Checks if the operation is permitted by the API caller
|
||||
// All the code should be put inside this if statement
|
||||
if(isAllowed($this->getAddonID(), 'course'))
|
||||
{
|
||||
$result = $this->db->query($allForBewerbungQuery);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
class Studienplan_model extends DB_Model
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function getStudienplaene($studiengang_kz)
|
||||
{
|
||||
$result = NULL;
|
||||
$studienplaeneQuery = "SELECT DISTINCT tbl_studienplan.*
|
||||
FROM lehre.tbl_studienplan JOIN lehre.tbl_studienordnung USING(studienordnung_id)
|
||||
WHERE tbl_studienordnung.studiengang_kz = ?";
|
||||
|
||||
// Checks if the operation is permitted by the API caller
|
||||
// All the code should be put inside this if statement
|
||||
if(isAllowed($this->getAddonID(), 'plan'))
|
||||
{
|
||||
$result = $this->db->query($studienplaeneQuery, array($studiengang_kz));
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
class Organisationseinheit_model extends DB_Model
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->dbTable='public.tbl_organisationseinheit';
|
||||
$this->pk='oe_kurzbz';
|
||||
}
|
||||
}
|
||||
@@ -2,157 +2,828 @@
|
||||
|
||||
class Person_model extends DB_Model
|
||||
{
|
||||
public function __construct($uid = null)
|
||||
{
|
||||
parent::__construct($uid);
|
||||
$this->dbTable = 'public.tbl_person';
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function getPerson($person_id = null)
|
||||
{
|
||||
if (is_null($person_id))
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function getPerson($personId = NULL, $code = NULL, $email = NULL)
|
||||
{
|
||||
$result = NULL;
|
||||
|
||||
// Checks if the operation is permitted by the API caller
|
||||
// All the code should be put inside this if statement
|
||||
if(isAllowed($this->getAddonID(), 'person'))
|
||||
{
|
||||
$query = $this->db->get_where('public.tbl_person', array());
|
||||
return $query->result_object();
|
||||
if((isset($code)) && (isset($email)))
|
||||
{
|
||||
$result = $this->_getPersonByCodeAndEmail($code, $email);
|
||||
}
|
||||
elseif(isset($code))
|
||||
{
|
||||
$result = $this->_getPersonByCode($code);
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = $this->_getPersonByID($personId);
|
||||
}
|
||||
}
|
||||
$query = $this->db->get_where('public.tbl_person', array('person_id' => $person_id));
|
||||
return $query->row_object();
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $personId Person ID
|
||||
* @return object
|
||||
*/
|
||||
private function _getPersonByID($personId = NULL)
|
||||
{
|
||||
$result = NULL;
|
||||
$loadQuery = "SELECT person_id,
|
||||
sprache,
|
||||
anrede,
|
||||
titelpost,
|
||||
titelpre,
|
||||
nachname,
|
||||
vorname,
|
||||
vornamen,
|
||||
gebdatum,
|
||||
gebort,
|
||||
gebzeit,
|
||||
foto,
|
||||
anmerkung,
|
||||
homepage,
|
||||
svnr,
|
||||
ersatzkennzeichen,
|
||||
familienstand,
|
||||
anzahlkinder,
|
||||
aktiv,
|
||||
insertamum,
|
||||
insertvon,
|
||||
updateamum,
|
||||
updatevon,
|
||||
ext_id,
|
||||
geschlecht,
|
||||
staatsbuergerschaft,
|
||||
geburtsnation,
|
||||
kurzbeschreibung,
|
||||
zugangscode,
|
||||
foto_sperre,
|
||||
matr_nr
|
||||
FROM public.tbl_person
|
||||
WHERE person_id = ?";
|
||||
|
||||
if(isset($personId))
|
||||
{
|
||||
$result = $this->db->query($loadQuery, array($personId));
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getPersonByCodeAndEmail($code, $email)
|
||||
{
|
||||
// if ($this->fhc_db_acl->bb->isBerechtigt('person', 'suid'))
|
||||
// {
|
||||
$this->db->select("*")
|
||||
->from('public.tbl_person p')
|
||||
->join("public.tbl_kontakt k", "k.person_id=p.person_id")
|
||||
->where("p.zugangscode", $code)
|
||||
->where("k.kontakt", $email);
|
||||
|
||||
return $this->db->get()->result_object();
|
||||
// }
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function _getPersonByCodeAndEmail($code = NULL, $email = NULL)
|
||||
{
|
||||
$result = NULL;
|
||||
$query = "SELECT *
|
||||
FROM public.tbl_person p JOIN public.tbl_kontakt k USING (person_id)
|
||||
WHERE p.zugangscode = ?
|
||||
AND k.kontakt = ?";
|
||||
|
||||
if((isset($code)) && (isset($email)))
|
||||
{
|
||||
$result = $this->db->query($query, array($code, $email));
|
||||
}
|
||||
|
||||
public function getPersonByCode($code)
|
||||
{
|
||||
// if ($this->fhc_db_acl->bb->isBerechtigt('person', 'suid'))
|
||||
// {
|
||||
$query = $this->db->get_where('public.tbl_person', array('zugangscode' => $code));
|
||||
return $query->result_object();
|
||||
// }
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Laedt Personendaten eine BenutzerUID
|
||||
* @param string $uid DB-Attr: tbl_benutzer.uid .
|
||||
* @return bool
|
||||
*/
|
||||
public function getPersonFromBenutzerUID($uid)
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function _getPersonByCode($code = NULL)
|
||||
{
|
||||
$result = NULL;
|
||||
$query = "SELECT *
|
||||
FROM public.tbl_person p
|
||||
WHERE p.zugangscode = ?";
|
||||
|
||||
if(isset($code))
|
||||
{
|
||||
$result = $this->db->query($query, array($code));
|
||||
}
|
||||
|
||||
if (!$this->fhc_db_acl->bb->isBerechtigt('person', 's'))
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function savePerson($person = NULL)
|
||||
{
|
||||
$result = FALSE;
|
||||
|
||||
// Checks if the operation is permitted by the API caller
|
||||
// All the code should be put inside this if statement
|
||||
if(isAllowed($this->getAddonID(), 'person'))
|
||||
{
|
||||
if($this->_validate($person))
|
||||
{
|
||||
if(isset($person['person_id']))
|
||||
{
|
||||
$result = $this->_updatePerson($person);
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = $this->_insertPerson($person);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function _insertPerson($person)
|
||||
{
|
||||
$this->db->trans_begin(); // Start DB transaction
|
||||
|
||||
$insertQuery = "INSERT INTO public.tbl_person (
|
||||
sprache,
|
||||
anrede,
|
||||
titelpost,
|
||||
titelpre,
|
||||
nachname,
|
||||
vorname,
|
||||
vornamen,
|
||||
gebdatum,
|
||||
gebort,
|
||||
gebzeit,
|
||||
foto,
|
||||
anmerkung,
|
||||
homepage,
|
||||
svnr,
|
||||
ersatzkennzeichen,
|
||||
familienstand,
|
||||
anzahlkinder,
|
||||
aktiv,
|
||||
insertamum,
|
||||
insertvon,
|
||||
updateamum,
|
||||
updatevon,
|
||||
geschlecht,
|
||||
geburtsnation,
|
||||
staatsbuergerschaft,
|
||||
kurzbeschreibung,
|
||||
zugangscode,
|
||||
foto_sperre,
|
||||
matr_nr
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
|
||||
?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
|
||||
?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
|
||||
$sqlParametersArray = array($person['sprache'],
|
||||
$person['anrede'],
|
||||
$person['titelpost'],
|
||||
$person['titelpre'],
|
||||
$person['nachname'],
|
||||
$person['vorname'],
|
||||
$person['vornamen'],
|
||||
$person['gebdatum'],
|
||||
$person['gebort'],
|
||||
$person['gebzeit'],
|
||||
$person['foto'],
|
||||
$person['anmerkung'],
|
||||
$person['homepage'],
|
||||
$person['svnr'],
|
||||
$person['ersatzkennzeichen'],
|
||||
$person['familienstand'],
|
||||
$person['anzahlkinder'],
|
||||
$person['aktiv'],
|
||||
"now()",
|
||||
$person['insertvon'],
|
||||
"now()",
|
||||
$person['updatevon'],
|
||||
$person['geschlecht'],
|
||||
$person['geburtsnation'],
|
||||
$person['staatsbuergerschaft'],
|
||||
$person['kurzbeschreibung'],
|
||||
$person['zugangscode'],
|
||||
$person['foto_sperre'],
|
||||
$person['matr_nr']);
|
||||
|
||||
$result = $this->db->query($insertQuery, $sqlParametersArray);
|
||||
|
||||
// Check DB transaction result
|
||||
if($this->db->trans_status() === FALSE)
|
||||
{
|
||||
$this->db->trans_rollback();
|
||||
$result = FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->trans_commit();
|
||||
$result = TRUE;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function _updatePerson($person)
|
||||
{
|
||||
$this->db->trans_begin(); // Start DB transaction
|
||||
|
||||
$updateQuery = "UPDATE public.tbl_person SET
|
||||
sprache = ?,
|
||||
anrede = ?,
|
||||
titelpost = ?,
|
||||
titelpre = ?,
|
||||
nachname = ?,
|
||||
vorname = ?,
|
||||
vornamen = ?,
|
||||
gebdatum = ?,
|
||||
gebort = ?,
|
||||
gebzeit = ?,
|
||||
foto = ?,
|
||||
anmerkung = ?,
|
||||
homepage = ?,
|
||||
svnr = ?,
|
||||
ersatzkennzeichen = ?,
|
||||
familienstand = ?,
|
||||
anzahlkinder = ?,
|
||||
aktiv = ?,
|
||||
updateamum = ?,
|
||||
updatevon = ?,
|
||||
geschlecht = ?,
|
||||
geburtsnation = ?,
|
||||
staatsbuergerschaft = ?,
|
||||
kurzbeschreibung = ?,
|
||||
foto_sperre = ?,
|
||||
zugangscode = ?,
|
||||
matr_nr = ?
|
||||
WHERE person_id = ?";
|
||||
|
||||
$sqlParametersArray = array($person['sprache'],
|
||||
$person['anrede'],
|
||||
$person['titelpost'],
|
||||
$person['titelpre'],
|
||||
$person['nachname'],
|
||||
$person['vorname'],
|
||||
$person['vornamen'],
|
||||
$person['gebdatum'],
|
||||
$person['gebort'],
|
||||
$person['gebzeit'],
|
||||
$person['foto'],
|
||||
$person['anmerkung'],
|
||||
$person['homepage'],
|
||||
$person['svnr'],
|
||||
$person['ersatzkennzeichen'],
|
||||
$person['familienstand'],
|
||||
$person['anzahlkinder'],
|
||||
$person['aktiv'],
|
||||
"now()",
|
||||
$person['updatevon'],
|
||||
$person['geschlecht'],
|
||||
$person['geburtsnation'],
|
||||
$person['staatsbuergerschaft'],
|
||||
$person['kurzbeschreibung'],
|
||||
$person['foto_sperre'],
|
||||
$person['zugangscode'],
|
||||
$person['matr_nr'],
|
||||
$person['person_id']);
|
||||
|
||||
$result = $this->db->query($updateQuery, $sqlParametersArray);
|
||||
|
||||
// Check DB transaction result
|
||||
if($this->db->trans_status() === FALSE)
|
||||
{
|
||||
$this->db->trans_rollback();
|
||||
$result = FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->trans_commit();
|
||||
$result = TRUE;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function savePrestudent($interestedStudent = NULL)
|
||||
{
|
||||
// Checks if the operation is permitted by the API caller
|
||||
// All the code should be put inside this if statement
|
||||
if(isAllowed($this->getAddonID(), 'person'))
|
||||
{
|
||||
return $this->_savePrestudent($interestedStudent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method saveInterestedStudent
|
||||
*
|
||||
* @return bool true when everything goes right, otherwise false
|
||||
*/
|
||||
private function _savePrestudent($interestedStudent = NULL)
|
||||
{
|
||||
if(!isset($interestedStudent))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if($interestedStudent['zgvmas_code'] && $interestedStudent['zgvmanation'])
|
||||
{
|
||||
$interestedStudent['ausstellungsstaat'] = $interestedStudent['zgvmanation'];
|
||||
}
|
||||
elseif($interestedStudent['zgv_code'] && $interestedStudent['zgvnation'])
|
||||
{
|
||||
$interestedStudent['ausstellungsstaat'] = $interestedStudent['zgvnation'];
|
||||
}
|
||||
|
||||
//Variablen auf Gueltigkeit pruefen
|
||||
if(isset($interestedStudent['prestudent_id']) && $interestedStudent['punkte'] > 9999.9999)
|
||||
{
|
||||
//$this->errormsg = 'Reihungstestgesamtpunkte should be no bigger than 9999.9999';
|
||||
return FALSE;
|
||||
}
|
||||
if($interestedStudent['rt_punkte1'] > 9999.9999)
|
||||
{
|
||||
//$this->errormsg = 'Reihungstestpunkte1 should be no bigger than 9999.9999';
|
||||
return FALSE;
|
||||
}
|
||||
if($interestedStudent['rt_punkte2'] > 9999.9999)
|
||||
{
|
||||
//$this->errormsg = 'Reihungstestpunkte2 should be no bigger than 9999.9999';
|
||||
return FALSE;
|
||||
}
|
||||
if($interestedStudent['rt_punkte3'] > 9999.9999)
|
||||
{
|
||||
//$this->errormsg = 'Reihungstestpunkte3 should be no bigger than 9999.9999';
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$this->db->trans_begin(); // Start DB transaction
|
||||
|
||||
// If prestudent_id is NOT set it's an insert
|
||||
if(!isset($interestedStudent['prestudent_id']))
|
||||
{
|
||||
$insertQuery = "INSERT INTO public.tbl_prestudent (
|
||||
aufmerksamdurch_kurzbz,
|
||||
person_id,
|
||||
studiengang_kz,
|
||||
berufstaetigkeit_code,
|
||||
ausbildungcode,
|
||||
zgv_code,
|
||||
zgvort,
|
||||
zgvdatum,
|
||||
zgvnation,
|
||||
zgvmas_code,
|
||||
zgvmaort,
|
||||
zgvmadatum,
|
||||
zgvmanation,
|
||||
aufnahmeschluessel,
|
||||
facheinschlberuf,
|
||||
reihungstest_id,
|
||||
anmeldungreihungstest,
|
||||
reihungstestangetreten,
|
||||
rt_gesamtpunkte,
|
||||
rt_punkte1,
|
||||
rt_punkte2,
|
||||
rt_punkte3,
|
||||
bismelden,
|
||||
insertamum,
|
||||
insertvon,
|
||||
updateamum,
|
||||
updatevon,
|
||||
anmerkung,
|
||||
dual,
|
||||
ausstellungsstaat,
|
||||
mentor
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
|
||||
?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
|
||||
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
|
||||
$sqlParametersArray = array($interestedStudent['aufmerksamdurch_kurzbz'],
|
||||
$interestedStudent['person_id'],
|
||||
$interestedStudent['studiengang_kz'],
|
||||
$interestedStudent['berufstaetigkeit_code'],
|
||||
$interestedStudent['ausbildungcode'],
|
||||
$interestedStudent['zgv_code'],
|
||||
$interestedStudent['zgvort'],
|
||||
$interestedStudent['zgvdatum'],
|
||||
$interestedStudent['zgvnation'],
|
||||
$interestedStudent['zgvmas_code'],
|
||||
$interestedStudent['zgvmaort'],
|
||||
$interestedStudent['zgvmadatum'],
|
||||
$interestedStudent['zgvmanation'],
|
||||
$interestedStudent['aufnahmeschluessel'],
|
||||
$interestedStudent['facheinschlberuf'],
|
||||
$interestedStudent['reihungstest_id'],
|
||||
$interestedStudent['anmeldungreihungstest'],
|
||||
$interestedStudent['reihungstestangetreten'],
|
||||
$interestedStudent['rt_gesamtpunkte'],
|
||||
$interestedStudent['rt_punkte1'],
|
||||
$interestedStudent['rt_punkte2'],
|
||||
$interestedStudent['rt_punkte3'],
|
||||
$interestedStudent['bismelden'],
|
||||
$interestedStudent['insertamum'],
|
||||
$interestedStudent['insertvon'],
|
||||
$interestedStudent['updateamum'],
|
||||
$interestedStudent['updatevon'],
|
||||
$interestedStudent['anmerkung'],
|
||||
$interestedStudent['dual'],
|
||||
$interestedStudent['ausstellungsstaat'],
|
||||
$interestedStudent['mentor']);
|
||||
|
||||
$result = $this->db->query($insertQuery, $sqlParametersArray);
|
||||
}
|
||||
// otherwise it's an update
|
||||
else
|
||||
{
|
||||
$updateQuery = "UPDATE public.tbl_prestudent SET
|
||||
aufmerksamdurch_kurzbz = ?,
|
||||
person_id = ?,
|
||||
studiengang_kz = ?,
|
||||
berufstaetigkeit_code = ?,
|
||||
ausbildungcode = ?,
|
||||
zgv_code = ?,
|
||||
zgvort = ?,
|
||||
zgvdatum = ?,
|
||||
zgvnation = ?,
|
||||
zgvmas_code = ?,
|
||||
zgvmaort = ?,
|
||||
zgvmadatum = ?,
|
||||
zgvmanation = ?,
|
||||
aufnahmeschluessel = ?,
|
||||
facheinschlberuf = ?,
|
||||
reihungstest_id = ?,
|
||||
anmeldungreihungstest = ?,
|
||||
reihungstestangetreten = ?,
|
||||
rt_gesamtpunkte = ?,
|
||||
rt_punkte1 = ?,
|
||||
rt_punkte2 = ?,
|
||||
rt_punkte3 = ?,
|
||||
bismelden = ?,
|
||||
updateamum = ?,
|
||||
updatevon = ?,
|
||||
anmerkung = ?,
|
||||
mentor = ?,
|
||||
dual = ?,
|
||||
ausstellungsstaat = ?
|
||||
WHERE prestudent_id = ?";
|
||||
|
||||
$sqlParametersArray = array($interestedStudent['aufmerksamdurch_kurzbz'],
|
||||
$interestedStudent['person_id'],
|
||||
$interestedStudent['studiengang_kz'],
|
||||
$interestedStudent['berufstaetigkeit_code'],
|
||||
$interestedStudent['ausbildungcode'],
|
||||
$interestedStudent['zgv_code'],
|
||||
$interestedStudent['zgvort'],
|
||||
$interestedStudent['zgvdatum'],
|
||||
$interestedStudent['zgvnation'],
|
||||
$interestedStudent['zgvmas_code'],
|
||||
$interestedStudent['zgvmaort'],
|
||||
$interestedStudent['zgvmadatum'],
|
||||
$interestedStudent['zgvmanation'],
|
||||
$interestedStudent['aufnahmeschluessel'],
|
||||
$interestedStudent['facheinschlberuf'],
|
||||
$interestedStudent['reihungstest_id'],
|
||||
$interestedStudent['anmeldungreihungstest'],
|
||||
$interestedStudent['reihungstestangetreten'],
|
||||
$interestedStudent['punkte'],
|
||||
$interestedStudent['rt_punkte1'],
|
||||
$interestedStudent['rt_punkte2'],
|
||||
$interestedStudent['rt_punkte3'],
|
||||
$interestedStudent['bismelden'],
|
||||
$interestedStudent['updateamum'],
|
||||
$interestedStudent['updatevon'],
|
||||
$interestedStudent['anmerkung'],
|
||||
$interestedStudent['mentor'],
|
||||
$interestedStudent['dual'],
|
||||
$interestedStudent['ausstellungsstaat'],
|
||||
$interestedStudent['prestudent_id']);
|
||||
|
||||
$result = $this->db->query($updateQuery, $sqlParametersArray);
|
||||
}
|
||||
|
||||
// Check DB transaction result
|
||||
if($this->db->trans_status() === FALSE)
|
||||
{
|
||||
$this->db->trans_rollback();
|
||||
$result = FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->trans_commit();
|
||||
$result = TRUE;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function _validate($person = NULL)
|
||||
{
|
||||
if(!isset($person))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$person['nachname'] = trim($person['nachname']);
|
||||
$person['vorname'] = trim($person['vorname']);
|
||||
$person['vornamen'] = trim($person['vornamen']);
|
||||
$person['anrede'] = trim($person['anrede']);
|
||||
$person['titelpost'] = trim($person['titelpost']);
|
||||
$person['titelpre'] = trim($person['titelpre']);
|
||||
|
||||
if(mb_strlen($person['sprache']) > 16)
|
||||
{
|
||||
//$this->errormsg = 'Sprache darf nicht laenger als 16 Zeichen sein';
|
||||
return false;
|
||||
}
|
||||
if(mb_strlen($person['anrede']) > 16)
|
||||
{
|
||||
//$this->errormsg = 'Anrede darf nicht laenger als 16 Zeichen sein';
|
||||
return false;
|
||||
}
|
||||
if(mb_strlen($person['titelpost']) > 32)
|
||||
{
|
||||
//$this->errormsg = 'Titelpost darf nicht laenger als 32 Zeichen sein';
|
||||
return false;
|
||||
}
|
||||
if(mb_strlen($person['titelpre']) > 64)
|
||||
{
|
||||
//$this->errormsg = 'Titelpre darf nicht laenger als 64 Zeichen sein';
|
||||
return false;
|
||||
}
|
||||
if(mb_strlen($person['nachname']) > 64)
|
||||
{
|
||||
//$this->errormsg = 'Nachname darf nicht laenger als 64 Zeichen sein';
|
||||
return false;
|
||||
}
|
||||
if($person['nachname'] == '' || is_null($person['nachname']))
|
||||
{
|
||||
//$this->errormsg = 'Nachname muss eingegeben werden';
|
||||
return false;
|
||||
}
|
||||
|
||||
if(mb_strlen($person['vorname']) > 32)
|
||||
{
|
||||
//$this->errormsg = 'Vorname darf nicht laenger als 32 Zeichen sein';
|
||||
return false;
|
||||
}
|
||||
if(mb_strlen($person['vornamen']) > 128)
|
||||
{
|
||||
//$this->errormsg = 'Vornamen darf nicht laenger als 128 Zeichen sein';
|
||||
return false;
|
||||
}
|
||||
//ToDo Gebdatum pruefen -> laut bis muss student aelter als 10 Jahre sein
|
||||
/* if (strlen($person['gebdatum) == 0 || is_null($person['gebdatum))
|
||||
{
|
||||
//$this->errormsg = "Geburtsdatum muss eingegeben werden\n";
|
||||
return false;
|
||||
} */
|
||||
if(mb_strlen($person['gebort']) > 128)
|
||||
{
|
||||
//$this->errormsg = 'Geburtsort darf nicht laenger als 128 Zeichen sein';
|
||||
return false;
|
||||
}
|
||||
|
||||
if(mb_strlen($person['homepage']) > 256)
|
||||
{
|
||||
//$this->errormsg = 'Homepage darf nicht laenger als 256 Zeichen sein';
|
||||
return false;
|
||||
}
|
||||
if(mb_strlen($person['svnr']) > 16)
|
||||
{
|
||||
//$this->errormsg = 'SVNR darf nicht laenger als 16 Zeichen sein';
|
||||
return false;
|
||||
}
|
||||
|
||||
if(mb_strlen($person['matr_nr']) > 32)
|
||||
{
|
||||
//$this->errormsg = 'Matrikelnummer darf nicht laenger als 32 Zeichen sein';
|
||||
return false;
|
||||
}
|
||||
|
||||
if($person['svnr'] != '' && mb_strlen($person['svnr']) != 16 && mb_strlen($person['svnr']) != 10)
|
||||
{
|
||||
//$this->errormsg = 'SVNR muss 10 oder 16 Zeichen lang sein';
|
||||
return false;
|
||||
}
|
||||
|
||||
if($person['svnr'] != '' && mb_strlen($person['svnr']) == 10)
|
||||
{
|
||||
//SVNR mit Pruefziffer pruefen
|
||||
//Die 4. Stelle in der SVNR ist die Pruefziffer
|
||||
//(Summe von (gewichtung[i]*svnr[i])) modulo 11 ergibt diese Pruefziffer
|
||||
//Falls nicht, ist die SVNR ungueltig
|
||||
$gewichtung = array(3, 7, 9, 0, 5, 8, 4, 2, 1, 6);
|
||||
$erg = 0;
|
||||
//Quersumme bilden
|
||||
for($i = 0; $i < 10; $i++)
|
||||
{
|
||||
$erg += $gewichtung[$i] * $person['svnr']{$i};
|
||||
}
|
||||
|
||||
if($person['svnr']{3} != ($erg % 11)) //Vergleichen der Pruefziffer mit Quersumme Modulo 11
|
||||
{
|
||||
//$this->errormsg = 'SVNR ist ungueltig';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if($person['svnr'] != '')
|
||||
{
|
||||
//Pruefen ob bereits ein Eintrag mit dieser SVNR vorhanden ist
|
||||
$qry = "SELECT person_id FROM public.tbl_person WHERE svnr=" . $person['svnr'];
|
||||
if(db_query($qry))
|
||||
{
|
||||
if($row = db_fetch_object())
|
||||
{
|
||||
if($row->person_id != $person['person_id'])
|
||||
{
|
||||
//$this->errormsg = 'Es existiert bereits eine Person mit dieser SVNR! Daten wurden NICHT gepeichert.';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(mb_strlen($person['ersatzkennzeichen']) > 10)
|
||||
{
|
||||
//$this->errormsg = 'Ersatzkennzeichen darf nicht laenger als 10 Zeichen sein';
|
||||
return false;
|
||||
}
|
||||
if(mb_strlen($person['familienstand']) > 1)
|
||||
{
|
||||
//$this->errormsg = 'Familienstand ist ungueltig';
|
||||
return false;
|
||||
}
|
||||
if($person['anzahlkinder'] != '' && !is_numeric($person['anzahlkinder']))
|
||||
{
|
||||
//$this->errormsg = 'Anzahl der Kinder ist ungueltig';
|
||||
return false;
|
||||
}
|
||||
if($person['aktiv'] != "t" && $person['aktiv'] != "f")
|
||||
{
|
||||
//$this->errormsg = 'Aktiv ist ungueltig';
|
||||
return false;
|
||||
}
|
||||
if(!isset($person['person_id']) && mb_strlen($person['insertvon']) > 32)
|
||||
{
|
||||
//$this->errormsg = 'Insertvon darf nicht laenger als 32 Zeichen sein';
|
||||
return false;
|
||||
}
|
||||
if(mb_strlen($person['updatevon']) > 32)
|
||||
{
|
||||
//$this->errormsg = 'Updatevon darf nicht laenger als 32 Zeichen sein';
|
||||
return false;
|
||||
}
|
||||
/*if($person['ext_id'] != '' && !is_numeric($person['ext_id']))
|
||||
{
|
||||
//$this->errormsg = 'Ext_ID ist keine gueltige Zahl';
|
||||
return false;
|
||||
}*/
|
||||
if(mb_strlen($person['geschlecht']) > 1)
|
||||
{
|
||||
//$this->errormsg = 'Geschlecht darf nicht laenger als 1 Zeichen sein';
|
||||
return false;
|
||||
}
|
||||
if(mb_strlen($person['geburtsnation']) > 3)
|
||||
{
|
||||
//$this->errormsg = 'Geburtsnation darf nicht laenger als 3 Zeichen sein';
|
||||
return false;
|
||||
}
|
||||
if(mb_strlen($person['staatsbuergerschaft']) > 3)
|
||||
{
|
||||
//$this->errormsg = 'Staatsbuergerschaft darf nicht laenger als 3 Zeichen sein';
|
||||
return false;
|
||||
}
|
||||
if($person['geschlecht'] != 'm' && $person['geschlecht'] != 'w' && $person['geschlecht'] != 'u')
|
||||
{
|
||||
//$this->errormsg = 'Geschlecht muss w, m oder u sein!';
|
||||
return false;
|
||||
}
|
||||
|
||||
//Pruefen ob das Geburtsdatum mit der SVNR uebereinstimmt.
|
||||
if($person['svnr'] != '' && $person['gebdatum'] != '')
|
||||
{
|
||||
if(mb_ereg("([0-9]{1,2}).([0-9]{1,2}).([0-9]{4})", $person['gebdatum'], $regs))
|
||||
{
|
||||
//$day = sprintf('%02s',$regs[1]);
|
||||
//$month = sprintf('%02s',$regs[2]);
|
||||
//$year = mb_substr($regs[3],2,2);
|
||||
}
|
||||
elseif(mb_ereg("([0-9]{4})-([0-9]{2})-([0-9]{2})", $person['gebdatum'], $regs))
|
||||
{
|
||||
//$day = sprintf('%02s',$regs[3]);
|
||||
//$month = sprintf('%02s',$regs[2]);
|
||||
//$year = mb_substr($regs[1],2,2);
|
||||
}
|
||||
else
|
||||
{
|
||||
//$this->errormsg = 'Format des Geburtsdatums ist ungueltig';
|
||||
return false;
|
||||
}
|
||||
|
||||
/* das muss nicht immer so sein
|
||||
$day_svnr = mb_substr($person['svnr, 4, 2);
|
||||
$month_svnr = mb_substr($person['svnr, 6, 2);
|
||||
$year_svnr = mb_substr($person['svnr, 8, 2);
|
||||
|
||||
if ($day_svnr!=$day || $month_svnr!=$month || $year_svnr!=$year)
|
||||
{
|
||||
//$this->errormsg = 'SVNR und Geburtsdatum passen nicht zusammen';
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Laedt Personendaten eine BenutzerUID
|
||||
* @param string $uid DB-Attr: tbl_benutzer.uid .
|
||||
* @return bool
|
||||
*/
|
||||
public function getPersonFromBenutzerUID($uid)
|
||||
{
|
||||
|
||||
if(!$this->fhc_db_acl->bb->isBerechtigt('person', 's'))
|
||||
{
|
||||
$this->db->select('tbl_person.*');
|
||||
$this->db->from('public.tbl_person JOIN public.tbl_benutzer USING (person_id)');
|
||||
$query = $this->db->get_where(null, array('uid' => $uid));
|
||||
return $query->result_object();
|
||||
}
|
||||
}
|
||||
|
||||
public function savePerson($person)
|
||||
{
|
||||
//TODO check berechtigung
|
||||
// if($this->fhc_db_acl->bb->isBerechtigt('person', 'sui'))
|
||||
// {
|
||||
$data = array(
|
||||
"vorname"=>$person["vorname"],
|
||||
"nachname"=>$person["nachname"],
|
||||
"gebdatum"=>$person["gebdatum"],
|
||||
"aktiv" => true,
|
||||
"zugangscode"=>$person["zugangscode"],
|
||||
"zugangscode_timestamp"=>date('Y-m-d H:i:s'),
|
||||
"insertamum"=>date('Y-m-d H:i:s'),
|
||||
"insertvon"=>$person["insertvon"],
|
||||
);
|
||||
if($this->db->insert("public.tbl_person", $data)){
|
||||
return $this->db->insert_id();
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// return "Nicht berechtigt";
|
||||
// }
|
||||
}
|
||||
|
||||
public function checkBewerbung($email, $studiensemester_kurzbz=NULL)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function checkBewerbung($email, $studiensemester_kurzbz = NULL)
|
||||
{
|
||||
$this->db->distinct();
|
||||
|
||||
if(is_null($studiensemester_kurzbz))
|
||||
{
|
||||
$this->db->select("p.person_id, p.zugangscode, p.insertamum")
|
||||
->from("public.tbl_person p")
|
||||
->join("public.tbl_kontakt k", "p.person_id=k.person_id")
|
||||
->join("public.tbl_benutzer b", "p.person_id=b.person_id", "left")
|
||||
->where("k.kontakttyp", 'email')
|
||||
->where("(kontakt='".$email."'".
|
||||
" OR alias ||'@technikum-wien.at'='".$email."'".
|
||||
" OR uid ||'@technikum-wien.at'='".$email."')")
|
||||
->order_by("p.insertamum", "DESC")
|
||||
->limit(1)
|
||||
->from("public.tbl_person p")
|
||||
->join("public.tbl_kontakt k", "p.person_id=k.person_id")
|
||||
->join("public.tbl_benutzer b", "p.person_id=b.person_id", "left")
|
||||
->where("k.kontakttyp", 'email')
|
||||
->where("(kontakt='" . $email . "'" .
|
||||
" OR alias ||'@technikum-wien.at'='" . $email . "'" .
|
||||
" OR uid ||'@technikum-wien.at'='" . $email . "')")
|
||||
->order_by("p.insertamum", "DESC")
|
||||
->limit(1)
|
||||
;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->select("p.person_id,p.zugangscode,p.insertamum")
|
||||
->from("public.tbl_person p")
|
||||
->join("public.tbl_kontakt k", "p.person_id=k.person_id")
|
||||
->join("public.tbl_benutzer b", "p.person_id=b.person_id", "left")
|
||||
->join("public.tbl_prestudent ps", "p.person_id=ps.person_id")
|
||||
->join("public.tbl_prestudentstatus pst", "pst.prestudent_id=ps.prestudent_id")
|
||||
->where("k.kontakttyp", 'email')
|
||||
->where("(kontakt='".$email."'".
|
||||
" OR alias ||'@technikum-wien.at'='".$email."'".
|
||||
" OR uid ||'@technikum-wien.at'='".$email."')")
|
||||
->where("studiensemester_kurzbz='".$studiensemester_kurzbz."'")
|
||||
->order_by("p.insertamum", "DESC")
|
||||
->limit(1)
|
||||
->from("public.tbl_person p")
|
||||
->join("public.tbl_kontakt k", "p.person_id=k.person_id")
|
||||
->join("public.tbl_benutzer b", "p.person_id=b.person_id", "left")
|
||||
->join("public.tbl_prestudent ps", "p.person_id=ps.person_id")
|
||||
->join("public.tbl_prestudentstatus pst", "pst.prestudent_id=ps.prestudent_id")
|
||||
->where("k.kontakttyp", 'email')
|
||||
->where("(kontakt='" . $email . "'" .
|
||||
" OR alias ||'@technikum-wien.at'='" . $email . "'" .
|
||||
" OR uid ||'@technikum-wien.at'='" . $email . "')")
|
||||
->where("studiensemester_kurzbz='" . $studiensemester_kurzbz . "'")
|
||||
->order_by("p.insertamum", "DESC")
|
||||
->limit(1)
|
||||
;
|
||||
}
|
||||
return $this->db->get()->result_array();
|
||||
}
|
||||
}
|
||||
|
||||
public function checkZugangscodePerson($code)
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function checkZugangscodePerson($code)
|
||||
{
|
||||
$this->db->select("p.person_id")
|
||||
->from("public.tbl_person p")
|
||||
->where("p.zugangscode", $code);
|
||||
->from("public.tbl_person p")
|
||||
->where("p.zugangscode", $code);
|
||||
return $this->db->get()->result_array();
|
||||
}
|
||||
|
||||
public function updatePerson($person)
|
||||
{
|
||||
//TODO check berechtigung
|
||||
// if($this->fhc_db_acl->bb->isBerechtigt('person', 'sui'))
|
||||
// {
|
||||
//TODO set other columns to be updated
|
||||
$this->db->set("zugangscode", $person["zugangscode"]);
|
||||
$this->db->where("person_id", $person["person_id"]);
|
||||
if($this->db->update("public.tbl_person")){
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// return "Nicht berechtigt";
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
class Prestudent_model extends DB_Model
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->dbTable='public.tbl_prestudent';
|
||||
$this->pk='prestudent_id';
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function loadPrestudentPerson($prestudentID)
|
||||
{
|
||||
$this->db->select('*')
|
||||
->from('public.tbl_prestudent')
|
||||
->join('public.tbl_person', 'person_id')
|
||||
->where('prestudent_id', $prestudentID);
|
||||
return $this->db->get()->result_array();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user