diff --git a/application/config/fhcomplete.php b/application/config/fhcomplete.php index 836112873..d82f90165 100644 --- a/application/config/fhcomplete.php +++ b/application/config/fhcomplete.php @@ -1,4 +1,6 @@ - 'basis/person', 'public.tbl_prestudent' => 'basis/person', - 'public.tbl_organisationseinheit' => 'basis/organisationseinheit' -, + 'public.tbl_prestudentstatus' => 'basis/person', + 'public.tbl_organisationseinheit' => 'basis/organisationseinheit', 'public.tbl_sprache' => 'admin' ); diff --git a/application/controllers/ModelTest.php b/application/controllers/ModelTest.php index 0eced1525..430021d26 100755 --- a/application/controllers/ModelTest.php +++ b/application/controllers/ModelTest.php @@ -22,7 +22,12 @@ class ModelTest extends FHC_Controller */ public function index() { - $this->session->uid='admin'; // Should normaly be set through auth + //$this->session->uid='admin'; // Should normaly be set through auth + $this->load->model('person/Person_model'); + $this->Person_model->setUID('admin'); // Should normaly be set through auth + $res = $this->Person_model->getPerson(null, 'asdf\' OR person_id=1; SELECT 1; --'); + var_dump($res->result_object()); + $this->load->model('person/Prestudent_model'); $id=null; @@ -35,7 +40,7 @@ class ModelTest extends FHC_Controller ); $res = $this->Prestudent_model->insert($data); if ($res->error) - echo 'Error: ',$res->error, ', Code: ',$res->code,' -> ',$res->msg,': ',$res->retval,'
'; + echo 'Error: ',$res->error, ', Code: ',$res->fhcCode,' -> ',$res->msg,': ',$res->retval,'
'; else $id=$res->retval; @@ -48,7 +53,7 @@ class ModelTest extends FHC_Controller ); $res = $this->Prestudent_model->update($id, $data); if ($res->error) - echo 'Error: ',$res->error, ', Code: ',$res->code,' -> ',$res->msg,': ',$res->retval,'
'; + echo 'Error: ',$res->error, ', Code: ',$res->fhcCode,' -> ',$res->msg,': ',$res->retval,'
'; else $id=$res->retval; @@ -62,21 +67,55 @@ class ModelTest extends FHC_Controller ); $res = $this->Prestudent_model->replace($data); if ($res->error) - echo 'Error: ',$res->error, ', Code: ',$res->code,' -> ',$res->msg,': ',$res->retval; + echo 'Error: ',$res->error, ', Code: ',$res->fhcCode,' -> ',$res->msg,': ',$res->retval; else - echo 'Error: ',$res->error, ', Code: ',$res->code,' -> ',$res->msg,': ',$res->retval;*/ + echo 'Error: ',$res->error, ', Code: ',$res->fhcCode,' -> ',$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,'
'; + echo 'Error: ',$res->error, ', Code: ',$res->fhcCode,' -> ',$res->msg,': ',$res->retval,'
'; else var_dump($res->retval); + // Insert PreStudentStatus + $this->load->model('person/Prestudentstatus_model'); + $data = array + ( + 'prestudent_id' => $id, + 'status_kurzbz' => 'Interessent', + 'studiensemester_kurzbz' => 'WS2001', + 'ausbildungssemester' => 1 + ); + $res = $this->Prestudentstatus_model->insert($data); + var_dump($res->retval); + + // Load PreStudentStatus + $res = $this->Prestudentstatus_model->load($data); + var_dump($res->retval->result_object()); + $res = $this->Prestudentstatus_model->load(array($id,'Interessent', 'WS2001', 1)); + var_dump($res->retval->result_object()); + + // Update PreStudentStatus + $res = $this->Prestudentstatus_model->update($data, array + ( + 'prestudent_id' => $id, + 'status_kurzbz' => 'Bewerber', + 'studiensemester_kurzbz' => 'WS2011', + 'ausbildungssemester' => 2 + )); + var_dump($res->retval); + $res = $this->Prestudentstatus_model->update(array($id,'Bewerber', 'WS2011', 2), $data ); + var_dump($res->retval); + + // Delete PreStudentStatus + $res = $this->Prestudentstatus_model->delete($data); + 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,'
'; + echo 'Error: ',$res->error, ', Code: ',$res->fhcCode,' -> ',$res->msg,': ',$res->retval,'
'; else var_dump($res->retval); @@ -91,12 +130,12 @@ class ModelTest extends FHC_Controller ); $res = $this->Organisationseinheit_model->insert($data); if ($res->error) - echo 'Error: ',$res->error, ', Code: ',$res->code,' -> ',$res->msg,': ',$res->retval,'
'; + echo 'Error: ',$res->error, ', Code: ',$res->fhcCode,' -> ',$res->msg,': ',$res->retval,'
'; else $id = $data['oe_kurzbz']; var_dump($res); - // Update PreStudent + // Update OE $data = array ( 'freigabegrenze' => 1234.56, @@ -105,14 +144,14 @@ class ModelTest extends FHC_Controller ); $res = $this->Organisationseinheit_model->update($id, $data); if ($res->error) - echo 'Error: ',$res->error, ', Code: ',$res->code,' -> ',$res->msg,': ',$res->retval,'
'; + echo 'Error: ',$res->error, ', Code: ',$res->fhcCode,' -> ',$res->msg,': ',$res->retval,'
'; else $id=$res->retval; - - // Delete PreStudent + + // Delete Organisationseinheit $res = $this->Organisationseinheit_model->delete($id); if ($res->error) - echo 'Error: ',$res->error, ', Code: ',$res->code,' -> ',$res->msg,': ',$res->retval,'
'; + echo 'Error: ',$res->error, ', Code: ',$res->fhcCode,' -> ',$res->msg,': ',$res->retval,'
'; else var_dump($res->retval); @@ -127,7 +166,7 @@ class ModelTest extends FHC_Controller ); $res = $this->Sprache_model->insert($data); if ($res->error) - echo 'Error: ',$res->error, ', Code: ',$res->code,' -> ',$res->msg,': ',$res->retval,'
'; + echo 'Error: ',$res->error, ', Code: ',$res->fhcCode,' -> ',$res->msg,': ',$res->retval,'
'; else $id = $data['sprache']; var_dump($res); @@ -141,24 +180,37 @@ class ModelTest extends FHC_Controller ); $res = $this->Sprache_model->update($id, $data); if ($res->error) - echo 'Error: ',$res->error, ', Code: ',$res->code,' -> ',$res->msg,': ',$res->retval,'
'; + echo 'Error: ',$res->error, ', Code: ',$res->fhcCode,' -> ',$res->msg,': ',$res->retval,'
'; 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,'
'; + echo 'Error: ',$res->error, ', Code: ',$res->fhcCode,' -> ',$res->msg,': ',$res->retval,'
'; else { $result = $res->retval->result_object(); + var_dump($result); var_dump($this->Sprache_model->pgArrayPhp($result[0]->bezeichnung)); + var_dump($this->Sprache_model->pgBoolPhp($result[0]->content)); + } + + // Load All Sprache + $res = $this->Sprache_model->loadWhere(); + if ($res->error) + echo 'Error: ',$res->error, ', Code: ',$res->fhcCode,' -> ',$res->msg,': ',$res->retval,'
'; + else + { + var_dump($res->retval); + $result = $res->retval->result_object(); + var_dump($result); } // Delete Sprache $res = $this->Sprache_model->delete($id); if ($res->error) - echo 'Error: ',$res->error, ', Code: ',$res->code,' -> ',$res->msg,': ',$res->retval,'
'; + echo 'Error: ',$res->error, ', Code: ',$res->fhcCode,' -> ',$res->msg,': ',$res->retval,'
'; else var_dump($res->retval); } diff --git a/application/core/DB_Model.php b/application/core/DB_Model.php index e8905c630..4bfc18752 100644 --- a/application/core/DB_Model.php +++ b/application/core/DB_Model.php @@ -31,7 +31,7 @@ class DB_Model extends FHC_Model return $this->_error(lang('fhc_'.FHC_NODBTABLE), FHC_MODEL_ERROR); // Check rights - if (! $this->fhc_db_acl->isBerechtigt((string)($this->acl[$this->dbTable]), 'i')) + if (! $this->fhc_db_acl->isBerechtigt($this->acl[$this->dbTable], 'i')) return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> '.$this->acl[$this->dbTable], FHC_MODEL_ERROR); // DB-INSERT @@ -54,7 +54,7 @@ class DB_Model extends FHC_Model return $this->_error(lang('fhc_'.FHC_NODBTABLE), FHC_MODEL_ERROR); // Check rights - if (! $this->fhc_db_acl->isBerechtigt((string)($this->acl[$this->dbTable]), 'ui')) + if (! $this->fhc_db_acl->isBerechtigt($this->acl[$this->dbTable], 'ui')) return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> '.$this->acl[$this->dbTable], FHC_MODEL_ERROR); // DB-REPLACE @@ -80,11 +80,20 @@ class DB_Model extends FHC_Model return $this->_error(lang('fhc_'.FHC_NOPK), FHC_MODEL_ERROR); // Check rights - if (! $this->fhc_db_acl->isBerechtigt((string)($this->acl[$this->dbTable]), 'u')) + if (! $this->fhc_db_acl->isBerechtigt($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); + // Check for composite Primary Key + if (is_array($id)) + { + if (isset($id[0])) + $this->db->where($this->_arrayMergeIndex($this->pk, $id)); + else + $this->db->where($id); + } + else + $this->db->where($this->pk, $id); if ($this->db->update($this->dbTable, $data)) return $this->_success($id); else @@ -92,9 +101,9 @@ class DB_Model extends FHC_Model } /** --------------------------------------------------------------- - * Load data from DB-Table + * Load single data from DB-Table * - * @param string $id Primary Key for SELECT + * @param string $id ID (Primary Key) for SELECT ... WHERE * @return array */ public function load($id) @@ -106,12 +115,46 @@ class DB_Model extends FHC_Model return $this->_error(lang('fhc_'.FHC_NOPK), FHC_MODEL_ERROR); // Check rights - if (! $this->fhc_db_acl->isBerechtigt((string)($this->acl[$this->dbTable]), 's')) + if (! $this->fhc_db_acl->isBerechtigt($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); + // Check for composite Primary Key + if (is_array($id)) + { + if (isset($id[0])) + $result = $this->db->get_where($this->dbTable, $this->_arrayMergeIndex($this->pk, $id)); + else + $result = $this->db->get_where($this->dbTable, $id); + } + else + $result = $this->db->get_where($this->dbTable, array($this->pk => $id)); + if ($result) + return $this->_success($result); + else + return $this->_error($this->db->error(), FHC_DB_ERROR); + } + + /** --------------------------------------------------------------- + * Load data from DB-Table + * + * @return array + */ + public function loadWhere($where = null) + { + // 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($this->acl[$this->dbTable], 's')) + return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> '.$this->acl[$this->dbTable], FHC_MODEL_ERROR); + + // DB-SELECT + if (is_null($where)) + $result = $this->db->get($this->dbTable); + else + $result = $this->db->get_where($this->dbTable, $where); if ($result) return $this->_success($result); else @@ -137,16 +180,44 @@ class DB_Model extends FHC_Model 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))) + // Check for composite Primary Key + if (is_array($id)) + { + if (isset($id[0])) + $result = $this->db->delete($this->dbTable, $this->_arrayMergeIndex($this->pk, $id)); + else + $result = $this->db->delete($this->dbTable, $id); + } + else + $result = $this->db->delete($this->dbTable, array($this->pk => $id)); + if ($result) return $this->_success($id); else return $this->_error($this->db->error(), FHC_DB_ERROR); } + /** --------------------------------------------------------------- + * Convert PG-Boolean to PHP-Boolean + * + * @param char $b PG-Char to convert + * @return bool + */ + public function pgBoolPhp($b) + { + if (is_null($b)) + return null; + elseif ($b==='t') + return true; + else + return false; + } + /** --------------------------------------------------------------- * Convert PG-Array to PHP-Array * - * @param integer config.php error code numbers + * @param string $s PG-String to convert + * @param string $start start-point for recursive iterations + * @param string $end end-point for recursive iterations * @return array */ public function pgArrayPhp($s,$start=0,&$end=NULL) @@ -195,6 +266,22 @@ class DB_Model extends FHC_Model return $return; } + /** --------------------------------------------------------------- + * Invalid ID + * + * @param array $i Array with indexes. + * @param array $v Array with values. + * @return array + */ + protected function _arrayMergeIndex($i,$v) + { + if (count($i) != count($v)) + return false; + for ($j=0; $j < count($i); $j++) + $a[$i[$j]] = $v[$j]; + return $a; + } + /** --------------------------------------------------------------- * Invalid ID * diff --git a/application/core/FHC_Model.php b/application/core/FHC_Model.php index d9d8c6690..82e966f6f 100644 --- a/application/core/FHC_Model.php +++ b/application/core/FHC_Model.php @@ -17,6 +17,17 @@ class FHC_Model extends CI_Model $this->load->library('FHC_DB_ACL',array('uid' => $uid)); } + /** --------------------------------------------------------------- + * Set UID + * + * @param string $uid + * @return bool + */ + public function setUID($uid) + { + return $this->fhc_db_acl->setUID($uid); + } + /** --------------------------------------------------------------- * Success * @@ -27,7 +38,7 @@ class FHC_Model extends CI_Model { $return = new stdClass(); $return->error = EXIT_SUCCESS; - $return->code = $message; + $return->fhcCode = $message; $return->msg = lang('fhc_' . $message); $return->retval = $retval; return $return; @@ -42,7 +53,7 @@ class FHC_Model extends CI_Model { $return = new stdClass(); $return->error = EXIT_MODEL; - $return->code = $message; + $return->fhcCode = $message; $return->msg = lang('fhc_' . $message); $return->retval = $retval; return $return; diff --git a/application/libraries/FHC_DB_ACL.php b/application/libraries/FHC_DB_ACL.php index 729f1d1f9..1e483683d 100644 --- a/application/libraries/FHC_DB_ACL.php +++ b/application/libraries/FHC_DB_ACL.php @@ -34,7 +34,7 @@ require_once(FCPATH.'include/benutzerberechtigung.class.php'); class FHC_DB_ACL { public $bb; - protected $uid; + protected $_uid; /** * Auth Username, Password over FH-Complete @@ -46,12 +46,23 @@ class FHC_DB_ACL function __construct($param) { $this->bb = new benutzerberechtigung(); - $this->uid = $param['uid']; + $this->_uid = $param['uid']; } function isBerechtigt($berechtigung_kurzbz, $art=null, $oe_kurzbz=null, $kostenstelle_id=null) { - $this->bb->getBerechtigungen($this->uid); + $this->bb->getBerechtigungen($this->_uid); return $this->bb->isBerechtigt($berechtigung_kurzbz, $oe_kurzbz=null, $art=null, $kostenstelle_id=null); } + + /** --------------------------------------------------------------- + * Set UID + * + * @param string $uid + * @return bool + */ + public function setUID($uid) + { + return $this->_uid = $uid; + } } diff --git a/application/models/person/Person_model.php b/application/models/person/Person_model.php index 73dab4b34..caf82aff5 100644 --- a/application/models/person/Person_model.php +++ b/application/models/person/Person_model.php @@ -19,8 +19,8 @@ class Person_model extends DB_Model // 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(isAllowed($this->getAddonID(), 'person')) + {*/ if((isset($code)) && (isset($email))) { $result = $this->_getPersonByCodeAndEmail($code, $email); @@ -33,7 +33,7 @@ class Person_model extends DB_Model { $result = $this->_getPersonByID($personId); } - } + //} return $result; } @@ -826,4 +826,4 @@ class Person_model extends DB_Model ->where("p.zugangscode", $code); return $this->db->get()->result_array(); } -} \ No newline at end of file +} diff --git a/application/models/person/Prestudent_model.php b/application/models/person/Prestudent_model.php index ac4ff8d3b..a459d036d 100644 --- a/application/models/person/Prestudent_model.php +++ b/application/models/person/Prestudent_model.php @@ -5,7 +5,7 @@ class Prestudent_model extends DB_Model /** - * + * Constructor */ public function __construct() { @@ -19,11 +19,23 @@ class Prestudent_model extends DB_Model */ public function loadPrestudentPerson($prestudentID) { + // Check the rights + if (! $this->fhc_db_acl->isBerechtigt('basis/person', 's')) + return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> basis/person', FHC_MODEL_ERROR); + + // Prepare SQL-Query $this->db->select('*') ->from('public.tbl_prestudent') ->join('public.tbl_person', 'person_id') ->where('prestudent_id', $prestudentID); - return $this->db->get()->result_array(); + // Do the query + $result = $this->db->get()->result_object(); + + // Return the result + if ($result) + return $this->_success($result); + else + return $this->_error($this->db->error(), FHC_DB_ERROR); }