diff --git a/application/controllers/system/Messages.php b/application/controllers/system/Messages.php index d11eed4e1..4be3a0e78 100755 --- a/application/controllers/system/Messages.php +++ b/application/controllers/system/Messages.php @@ -16,105 +16,32 @@ class Messages extends VileSci_Controller $this->load->model('person/Person_model', 'PersonModel'); } - - public function index() - { - $this->load->view('system/messages.php', array('person_id' => $this->getPersonId())); - } - - public function inbox($person_id) - { - $msg = $this->messagelib->getMessagesByPerson($person_id); - if ($msg->error) - { - show_error($msg->retval); - } - - $person = $this->PersonModel->load($person_id); - if ($person->error) - { - show_error($person->retval); - } - - $data = array ( - 'messages' => $msg->retval, - 'person' => $person->retval[0] - ); - - $this->load->view('system/messagesInbox.php', $data); - } - - public function outbox($person_id) - { - $msg = $this->messagelib->getSentMessagesByPerson($person_id); - if ($msg->error) - { - show_error($msg->retval); - } - - $person = $this->PersonModel->load($person_id); - if ($person->error) - { - show_error($person->retval); - } - - $data = array ( - 'messages' => $msg->retval, - 'person' => $person->retval[0] - ); - - $this->load->view('system/messagesOutbox.php', $data); - } - public function view($msg_id, $person_id) - { - $msg = $this->messagelib->getMessage($msg_id, $person_id); - if ($msg->error) - { - show_error($msg->retval); - } - - $v = $this->load->view('system/messageView', array('message' => $msg->retval[0])); - } - - public function reply($msg_id, $person_id) - { - $msg = $this->messagelib->getMessage($msg_id, $person_id); - if ($msg->error) - { - show_error($msg->retval); - } - - $v = $this->load->view('system/messageReply', array('message' => $msg->retval[0])); - } - - public function sendReply($msg_id, $person_id) - { - $subject = $this->input->post('subject'); - $body = $this->input->post('body'); - - $this->load->model('system/Message_model', 'MessageModel'); - $originMsg = $this->MessageModel->load($msg_id); - if ($originMsg->error) - { - show_error($originMsg->retval); - } - - $msg = $this->messagelib->sendMessage($person_id, $originMsg->retval[0]->person_id, $subject, $body, PRIORITY_NORMAL, $msg_id); - if ($msg->error) - { - show_error($msg->retval); - } - - redirect('/system/Messages/view/' . $msg->retval . '/' . $originMsg->retval[0]->person_id); - } - - public function write($sender_id) + /** + * + */ + public function write($sender_id, $msg_id = null, $receiver_id = null) { $prestudent_id = $this->input->post('prestudent_id'); + $msg = null; + // Get message data if possible + if (is_numeric($msg_id) && is_numeric($receiver_id)) + { + $msg = $this->messagelib->getMessage($msg_id, $receiver_id); + if ($msg->error) + { + show_error($msg->retval); + } + else + { + $msg = $msg->retval[0]; + } + } + + // Get variables $this->load->model('crm/Prestudent_model', 'PrestudentModel'); - $prestudent = $this->MessageModel->getMsgVarsData($prestudent_id); + $prestudent = $this->MessageModel->getMsgVarsDataByPrestudentId($prestudent_id); if ($prestudent->error) { show_error($prestudent->retval); @@ -141,12 +68,16 @@ class Messages extends VileSci_Controller $data = array ( 'sender_id' => $sender_id, 'receivers' => $prestudent->retval, + 'message' => $msg, 'variables' => $variablesArray ); $v = $this->load->view('system/messageWrite', $data); } + /** + * + */ public function send($sender_id) { $error = false; @@ -154,7 +85,14 @@ class Messages extends VileSci_Controller $subject = $this->input->post('subject'); $body = $this->input->post('body'); $prestudents = $this->input->post('prestudents'); - $data = $this->MessageModel->getMsgVarsData($prestudents); + $relationmessage_id = $this->input->post('relationmessage_id'); + + if (!isset($relationmessage_id) || $relationmessage_id == '') + { + $relationmessage_id = null; + } + + $data = $this->MessageModel->getMsgVarsDataByPrestudentId($prestudents); if (hasData($data)) { for ($i = 0; $i < count($data->retval); $i++) @@ -169,7 +107,7 @@ class Messages extends VileSci_Controller $parsedText = $this->messagelib->parseMessageText($body, $dataArray); - $msg = $this->messagelib->sendMessage($sender_id, $dataArray['person_id'], $subject, $parsedText, PRIORITY_NORMAL); + $msg = $this->messagelib->sendMessage($sender_id, $dataArray['person_id'], $subject, $parsedText, PRIORITY_NORMAL, $relationmessage_id); if ($msg->error) { show_error($msg->retval); @@ -185,6 +123,9 @@ class Messages extends VileSci_Controller } } + /** + * + */ private function getPersonId() { $person_id = null; @@ -206,6 +147,9 @@ class Messages extends VileSci_Controller return $person_id; } + /** + * + */ public function getVorlage() { $vorlage_kurzbz = $this->input->get('vorlage_kurzbz'); @@ -221,6 +165,9 @@ class Messages extends VileSci_Controller } } + /** + * + */ public function parseMessageText() { $prestudent_id = $this->input->get('prestudent_id'); @@ -228,7 +175,7 @@ class Messages extends VileSci_Controller if (isset($prestudent_id)) { - $data = $this->MessageModel->getMsgVarsData($prestudent_id); + $data = $this->MessageModel->getMsgVarsDataByPrestudentId($prestudent_id); $parsedText = ""; if (hasData($data)) diff --git a/application/helpers/fhc_helper.php b/application/helpers/fhc_helper.php index b76e2041d..c2832d55d 100644 --- a/application/helpers/fhc_helper.php +++ b/application/helpers/fhc_helper.php @@ -62,3 +62,17 @@ function generateToken($length = 64) $token .= $characters[mt_rand(0, $charactersLength)]; return $token; } + +/** + * var_dump_to_error_log() + * Gets the output of the var_dump function and print it out + * via the error log. It also removes the end line characters + */ +function var_dump_to_error_log($parameter) +{ + ob_start(); + var_dump($parameter); + $ob_get_contents = ob_get_contents(); + ob_end_clean(); + error_log(str_replace("\n", '', $ob_get_contents)); +} \ No newline at end of file diff --git a/application/libraries/PermissionLib.php b/application/libraries/PermissionLib.php index dd0b2242a..662130c42 100644 --- a/application/libraries/PermissionLib.php +++ b/application/libraries/PermissionLib.php @@ -29,34 +29,34 @@ class PermissionLib const INSERT_RIGHT = 'i'; const DELETE_RIGHT = 'd'; const REPLACE_RIGHT = 'ui'; - + private $bb; // benutzerberechtigung private $acl; // conversion array from a source to a permission - + /** - * + * */ function __construct() { // Loads CI instance $this->ci =& get_instance(); - + // Loads the library to manage the rights system //$this->ci->load->library('FHC_DB_ACL'); - + // Loads the auth helper $this->ci->load->helper('fhcauth'); - + // Loads the array of resources $this->acl = $this->ci->config->item('fhc_acl'); - - // + + // $this->bb = new benutzerberechtigung(); } - + /** * Check if the user is entitled to get access to a source with the given access type - * + * * @return bool true if a user has the right to access to the specified * resource with a specified permission type, false otherwise */ @@ -74,7 +74,7 @@ class PermissionLib return false; } } - + /** * Get a permission by a given source */ @@ -89,16 +89,25 @@ class PermissionLib return null; } } - + /** - * + * */ private function isBerechtigt($berechtigung_kurzbz, $art = null, $oe_kurzbz = null, $kostenstelle_id = null) { if (!is_null($berechtigung_kurzbz)) { $this->bb->getBerechtigungen(getAuthUID()); - return $this->bb->isBerechtigt($berechtigung_kurzbz, $oe_kurzbz, $art, $kostenstelle_id); + if($this->bb->isBerechtigt($berechtigung_kurzbz, $oe_kurzbz, $art, $kostenstelle_id)) + { + log_message('debug','Permission '.$berechtigung_kurzbz.' granted'); + return true; + } + else + { + log_message('debug','Permission '.$berechtigung_kurzbz.' failed'); + return false; + } } else { diff --git a/application/libraries/ReihungstestLib.php b/application/libraries/ReihungstestLib.php index 6d6960240..4030e50c3 100644 --- a/application/libraries/ReihungstestLib.php +++ b/application/libraries/ReihungstestLib.php @@ -23,7 +23,14 @@ class ReihungstestLib */ public function insertPersonReihungstest($ddReihungstest) { - return $this->ci->RtPersonModel->insert($ddReihungstest); + if (isset($ddReihungstest['rt_id']) && $this->checkAvailability($ddReihungstest['rt_id'])) + { + return $this->ci->RtPersonModel->insert($ddReihungstest); + } + else + { + return error('This test is not more available'); + } } /** @@ -62,4 +69,19 @@ class ReihungstestLib return $this->ci->ReihungstestModel->loadWhere($parametersArray); } + + /** + * It checks if the test is available + */ + public function checkAvailability($reihungstest_id) + { + $result = $this->ci->ReihungstestModel->checkAvailability($reihungstest_id); + + if (hasData($result)) + { + return true; + } + + return false; + } } \ No newline at end of file diff --git a/application/models/crm/Reihungstest_model.php b/application/models/crm/Reihungstest_model.php index 46e8702cc..a8d048463 100644 --- a/application/models/crm/Reihungstest_model.php +++ b/application/models/crm/Reihungstest_model.php @@ -11,4 +11,31 @@ class Reihungstest_model extends DB_Model $this->dbTable = 'public.tbl_reihungstest'; $this->pk = 'reihungstest_id'; } + + /** + * Gets a test from a test id only if it is available + */ + public function checkAvailability($reihungstest_id) + { + $query = 'SELECT public.tbl_reihungstest.* + FROM public.tbl_reihungstest LEFT JOIN public.tbl_rt_studienplan USING(reihungstest_id) + WHERE tbl_reihungstest.oeffentlich = TRUE + AND tbl_reihungstest.datum > NOW() + AND tbl_reihungstest.anmeldefrist >= NOW() + AND COALESCE ( + tbl_reihungstest.max_teilnehmer, + ( + SELECT SUM(arbeitsplaetze) + FROM public.tbl_ort JOIN public.tbl_rt_ort USING(ort_kurzbz) + WHERE rt_id = tbl_reihungstest.reihungstest_id + ) + ) - ( + SELECT COUNT(*) + FROM public.tbl_rt_person + WHERE rt_id = tbl_reihungstest.reihungstest_id + ) > 0 + AND reihungstest_id = ?'; + + return $this->execQuery($query, array($reihungstest_id)); + } } \ No newline at end of file diff --git a/application/models/system/Message_model.php b/application/models/system/Message_model.php index bc59bb24a..0cb3162c2 100644 --- a/application/models/system/Message_model.php +++ b/application/models/system/Message_model.php @@ -87,7 +87,7 @@ class Message_model extends DB_Model /** * */ - public function getMsgVarsData($prestudent_id) + public function getMsgVarsDataByPrestudentId($prestudent_id) { $query = 'SELECT * FROM public.vw_msg_vars WHERE prestudent_id %s ?'; diff --git a/application/views/system/messageReply.php b/application/views/system/messageReply.php deleted file mode 100644 index ea98f56fd..000000000 --- a/application/views/system/messageReply.php +++ /dev/null @@ -1,65 +0,0 @@ -load->view("templates/header", array("title" => "MessageReply", "jquery" => true, "tinymce" => true)); ?> - -
- - - - - -