diff --git a/addons/template/dbcheck.php b/addons/template/dbcheck.php
index 46fc9dc22..a5f9e8b30 100644
--- a/addons/template/dbcheck.php
+++ b/addons/template/dbcheck.php
@@ -45,7 +45,7 @@ $uid = get_uid();
$rechte = new benutzerberechtigung();
$rechte->getBerechtigungen($uid);
-if(!$rechte->isBerechtigt('basis/addon'))
+if(!$rechte->isBerechtigt('basis/addon', null, 'suid'))
{
exit('Sie haben keine Berechtigung für die Verwaltung von Addons');
}
@@ -66,7 +66,7 @@ if(!$result = @$db->db_query("SELECT 1 FROM addon.tbl_template_items"))
if(!$db->db_query($qry))
echo 'addon.tbl_template_items: '.$db->db_last_error().'
';
- else
+ else
echo ' addon.tbl_template_items: Tabelle addon.template_items hinzugefuegt!
';
}
diff --git a/addons/template/install.php b/addons/template/install.php
index e0b328291..d9644bd3e 100644
--- a/addons/template/install.php
+++ b/addons/template/install.php
@@ -43,7 +43,7 @@ $uid = get_uid();
$rechte = new benutzerberechtigung();
$rechte->getBerechtigungen($uid);
-if(!$rechte->isBerechtigt('basis/addon'))
+if(!$rechte->isBerechtigt('basis/addon', null, 'suid'))
{
exit('Sie haben keine Berechtigung für die Verwaltung von Addons');
}
diff --git a/application/config/message.php b/application/config/message.php
index 18e4e997e..687922f70 100644
--- a/application/config/message.php
+++ b/application/config/message.php
@@ -2,8 +2,10 @@
if (! defined('BASEPATH')) exit('No direct script access allowed');
+// ONLY FOR DEBUGGING - If you are unsure, don't change it. If the message should be sent immediately. Default false
+$config['send_immediately'] = false;
+
$config['msg_delivery'] = true; // Default true
-$config['send_immediately'] = false; // If the message should be sent immediately. Default false
$config['system_person_id'] = 1; // Dummy sender, used for sending messages from the system
$config['redirect_view_message_url'] = 'index.ci.php/Redirect/redirectByToken/'; //
$config['message_html_view_url'] = 'index.ci.php/ViewMessage/toHTML/';
diff --git a/application/controllers/system/Messages.php b/application/controllers/system/Messages.php
index 0fdd6b8ec..bdfa946ac 100755
--- a/application/controllers/system/Messages.php
+++ b/application/controllers/system/Messages.php
@@ -103,42 +103,80 @@ class Messages extends VileSci_Controller
redirect('/system/Messages/view/' . $msg->retval . '/' . $originMsg->retval[0]->person_id);
}
- public function write($sender_id, $receiver_id)
+ public function write($sender_id)
{
- $person = $this->PersonModel->load($receiver_id);
- if ($person->error)
+ $prestudent_id = $this->input->post('prestudent_id');
+
+ $this->load->model('crm/Prestudent_model', 'PrestudentModel');
+ $prestudent = $this->MessageModel->getMsgVarsData($prestudent_id);
+ if ($prestudent->error)
{
- show_error($person->retval);
+ show_error($prestudent->retval);
}
+ $this->load->model('system/Message_model', 'MessageModel');
+ if (!hasData($variables = $this->MessageModel->getMessageVars()))
+ {
+ unset($variables);
+ }
+ else
+ {
+ $variablesArray = array();
+ // Skip person_id and prestudent_id
+ for($i = 2; $i < count($variables->retval); $i++)
+ {
+ $variablesArray['{'.str_replace(" ", "_", strtolower($variables->retval[$i])).'}'] = $variables->retval[$i];
+ }
+ }
+
+ array_shift($variables->retval); // Remove person_id
+ array_shift($variables->retval); // Remove prestudent_id
+
$data = array (
'sender_id' => $sender_id,
- 'receiver_id' => $receiver_id,
- 'receiver' => $person->retval[0]
+ 'receivers' => $prestudent->retval,
+ 'variables' => $variablesArray
);
$v = $this->load->view('system/messageWrite', $data);
}
- public function send($sender_id, $receiver_id)
+ public function send($sender_id)
{
+ $error = false;
+
$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)
+ $prestudents = $this->input->post('prestudents');
+ $data = $this->MessageModel->getMsgVarsData($prestudents);
+ if (hasData($data))
{
- show_error($originMsg->retval);
+ for ($i = 0; $i < count($data->retval); $i++)
+ {
+ $parsedText = "";
+ $dataArray = (array)$data->retval[$i];
+ foreach($dataArray as $key => $val)
+ {
+ $newKey = str_replace(" ", "_", strtolower($key));
+ $dataArray[$newKey] = $dataArray[$key];
+ }
+
+ $parsedText = $this->messagelib->parseMessageText($body, $dataArray);
+
+ $msg = $this->messagelib->sendMessage($sender_id, $dataArray['person_id'], $subject, $parsedText, PRIORITY_NORMAL);
+ if ($msg->error)
+ {
+ show_error($msg->retval);
+ $error = true;
+ break;
+ }
+ }
}
- $msg = $this->messagelib->sendMessage($sender_id, $receiver_id, $subject, $body, PRIORITY_NORMAL);
- if ($msg->error)
+ if (!$error)
{
- show_error($msg->retval);
+ echo "Messages sent successfully";
}
-
- redirect('/system/Messages/view/' . $msg->retval . '/' . $receiver_id);
}
private function getPersonId()
@@ -176,4 +214,32 @@ class Messages extends VileSci_Controller
->set_output(json_encode($result));
}
}
-}
+
+ public function parseMessageText()
+ {
+ $prestudent_id = $this->input->get('prestudent_id');
+ $text = $this->input->get('text');
+
+ if (isset($prestudent_id))
+ {
+ $data = $this->MessageModel->getMsgVarsData($prestudent_id);
+
+ $parsedText = "";
+ if (hasData($data))
+ {
+ $dataArray = (array)$data->retval[0];
+ foreach($dataArray as $key => $val)
+ {
+ $newKey = str_replace(" ", "_", strtolower($key));
+ $dataArray[$newKey] = $dataArray[$key];
+ }
+
+ $parsedText = $this->messagelib->parseMessageText($text, $dataArray);
+ }
+
+ $this->output
+ ->set_content_type('application/json')
+ ->set_output(json_encode($parsedText));
+ }
+ }
+}
\ No newline at end of file
diff --git a/application/libraries/MessageLib.php b/application/libraries/MessageLib.php
index 1e683f857..fa302abc1 100644
--- a/application/libraries/MessageLib.php
+++ b/application/libraries/MessageLib.php
@@ -265,12 +265,12 @@ class MessageLib
}
else
{
- if (!empty($subject))
+ if (empty($subject))
{
$result = $this->_error('', MSG_ERR_SUBJECT_EMPTY);
break;
}
- else if (!empty($body))
+ else if (empty($body))
{
$result = $this->_error('', MSG_ERR_BODY_EMPTY);
break;
@@ -884,4 +884,12 @@ class MessageLib
{
return success($retval, $code, MessageLib::MSG_INDX_PREFIX);
}
-}
+
+ /**
+ *
+ */
+ public function parseMessageText($text, $data = array())
+ {
+ return $this->ci->parser->parse_string($text, $data, true);
+ }
+}
\ No newline at end of file
diff --git a/application/models/system/Message_model.php b/application/models/system/Message_model.php
index 4748f9448..bc59bb24a 100644
--- a/application/models/system/Message_model.php
+++ b/application/models/system/Message_model.php
@@ -66,4 +66,31 @@ class Message_model extends DB_Model
return $this->execQuery($sql, $parametersArray);
}
+
+ /**
+ *
+ */
+ public function getMessageVars()
+ {
+ $result = $this->db->query('SELECT * FROM public.vw_msg_vars WHERE 0 = 1');
+
+ if ($result)
+ {
+ return success($result->list_fields());
+ }
+ else
+ {
+ return error($this->db->error(), FHC_DB_ERROR);
+ }
+ }
+
+ /**
+ *
+ */
+ public function getMsgVarsData($prestudent_id)
+ {
+ $query = 'SELECT * FROM public.vw_msg_vars WHERE prestudent_id %s ?';
+
+ return $this->execQuery(sprintf($query, is_array($prestudent_id) ? 'IN' : '='), array($prestudent_id));
+ }
}
\ No newline at end of file
diff --git a/application/models/system/message_model_old.php b/application/models/system/message_model_old.php
deleted file mode 100644
index 8b564ed4e..000000000
--- a/application/models/system/message_model_old.php
+++ /dev/null
@@ -1,511 +0,0 @@
-db->trans_start();
-
- $thread_id = $this->_insert_thread($subject);
- $msg_id = $this->_insert_message($thread_id, $sender_id, $body, $priority);
-
- // Create batch inserts
- $participants[] = array('thread_id' => $thread_id,'user_id' => $sender_id);
- $statuses[] = array('message_id' => $msg_id, 'user_id' => $sender_id,'status' => MSG_STATUS_READ);
-
- if ( ! is_array($recipients))
- {
- $participants[] = array('thread_id' => $thread_id,'user_id' => $recipients);
- $statuses[] = array('message_id' => $msg_id, 'user_id' => $recipients, 'status' => MSG_STATUS_UNREAD);
- }
- else
- {
- foreach ($recipients as $recipient)
- {
- $participants[] = array('thread_id' => $thread_id,'user_id' => $recipient);
- $statuses[] = array('message_id' => $msg_id, 'user_id' => $recipient, 'status' => MSG_STATUS_UNREAD);
- }
- }
-
- $this->_insert_participants($participants);
- $this->_insert_statuses($statuses);
-
- $this->db->trans_complete();
-
- if ($this->db->trans_status() === FALSE)
- {
- $this->db->trans_rollback();
- return FALSE;
- }
-
- return $thread_id;
- }
-
- // ------------------------------------------------------------------------
-
- /**
- * Reply to Message
- *
- * @param integer $reply_msg_id
- * @param integer $sender_id
- * @param string $body
- * @param integer $priority
- * @return integer $new_msg_id
- */
- function reply_to_message($reply_msg_id, $sender_id, $body, $priority)
- {
- $this->db->trans_start();
-
- // Get the thread id to keep messages together
- if ( ! $thread_id = $this->_get_thread_id_from_message($reply_msg_id))
- {
- return FALSE;
- }
-
- // Add this message
- $msg_id = $this->_insert_message($thread_id, $sender_id, $body, $priority);
-
- if ($recipients = $this->_get_thread_participants($thread_id, $sender_id))
- {
- $statuses[] = array('message_id' => $msg_id, 'user_id' => $sender_id,'status' => MSG_STATUS_READ);
-
- foreach ($recipients as $recipient)
- {
- $statuses[] = array('message_id' => $msg_id, 'user_id' => $recipient['user_id'], 'status' => MSG_STATUS_UNREAD);
- }
-
- $this->_insert_statuses($statuses);
- }
-
- $this->db->trans_complete();
-
- if ($this->db->trans_status() === FALSE)
- {
- $this->db->trans_rollback();
- return FALSE;
- }
-
- return $msg_id;
- }
-
- // ------------------------------------------------------------------------
-
- /**
- * Get a Single Message
- *
- * @param integer $msg_id
- * @param integer $user_id
- * @return array
- */
- function get_message($msg_id, $user_id)
- {
- $sql = 'SELECT m.*, s.status, t.subject, ' . USER_TABLE_USERNAME .
- ' FROM ' . $this->db->dbprefix . 'msg_messages m ' .
- ' JOIN ' . $this->db->dbprefix . 'msg_threads t ON (m.thread_id = t.id) ' .
- ' JOIN ' . $this->db->dbprefix . USER_TABLE_TABLENAME . ' ON (' . USER_TABLE_ID . ' = m.sender_id) '.
- ' JOIN ' . $this->db->dbprefix . 'msg_status s ON (s.message_id = m.id AND s.user_id = ? ) ' .
- ' WHERE m.id = ? ' ;
-
- $query = $this->db->query($sql, array($user_id, $msg_id));
-
- return $query->result_array();
- }
-
- // ------------------------------------------------------------------------
-
- /**
- * Get a Full Thread
- *
- * @param integer $thread_id
- * @param integer $user_id
- * @param boolean $full_thread
- * @param string $order_by
- * @return array
- */
- function get_full_thread($thread_id, $user_id, $full_thread = FALSE, $order_by = 'asc')
- {
- $sql = 'SELECT m.*, s.status, t.subject, '.USER_TABLE_USERNAME .
- ' FROM ' . $this->db->dbprefix . 'msg_participants p ' .
- ' JOIN ' . $this->db->dbprefix . 'msg_threads t ON (t.id = p.thread_id) ' .
- ' JOIN ' . $this->db->dbprefix . 'msg_messages m ON (m.thread_id = t.id) ' .
- ' JOIN ' . $this->db->dbprefix . USER_TABLE_TABLENAME . ' ON (' . USER_TABLE_ID . ' = m.sender_id) '.
- ' JOIN ' . $this->db->dbprefix . 'msg_status s ON (s.message_id = m.id AND s.user_id = ? ) ' .
- ' WHERE p.user_id = ? ' .
- ' AND p.thread_id = ? ';
-
- if ( ! $full_thread)
- {
- $sql .= ' AND m.cdate >= p.cdate';
- }
-
- $sql .= ' ORDER BY m.cdate ' . $order_by;
-
- $query = $this->db->query($sql, array($user_id, $user_id, $thread_id));
-
- return $query->result_array();
- }
-
- // ------------------------------------------------------------------------
-
- /**
- * Get All Threads
- *
- * @param integer $user_id
- * @param boolean $full_thread
- * @param string $order_by
- * @return array
- */
- function get_all_threads($user_id, $full_thread = FALSE, $order_by = 'asc')
- {
- $sql = 'SELECT m.*, s.status, t.subject, '.USER_TABLE_USERNAME .
- ' FROM ' . $this->db->dbprefix . 'msg_participants p ' .
- ' JOIN ' . $this->db->dbprefix . 'msg_threads t ON (t.id = p.thread_id) ' .
- ' JOIN ' . $this->db->dbprefix . 'msg_messages m ON (m.thread_id = t.id) ' .
- ' JOIN ' . $this->db->dbprefix . USER_TABLE_TABLENAME . ' ON (' . USER_TABLE_ID . ' = m.sender_id) '.
- ' JOIN ' . $this->db->dbprefix . 'msg_status s ON (s.message_id = m.id AND s.user_id = ? ) ' .
- ' WHERE p.user_id = ? ' ;
-
- if (!$full_thread)
- {
- $sql .= ' AND m.cdate >= p.cdate';
- }
-
- $sql .= ' ORDER BY t.id ' . $order_by. ', m.cdate '. $order_by;
-
- $query = $this->db->query($sql, array($user_id, $user_id));
-
- return $query->result_array();
- }
-
- // ------------------------------------------------------------------------
-
- /**
- * Change Message Status
- *
- * @param integer $msg_id
- * @param integer $user_id
- * @param integer $status_id
- * @return integer
- */
- function update_message_status($msg_id, $user_id, $status_id)
- {
- $this->db->where(array('message_id' => $msg_id, 'user_id' => $user_id ));
- $this->db->update('msg_status', array('status' => $status_id ));
-
- return $this->db->affected_rows();
- }
-
- // ------------------------------------------------------------------------
-
- /**
- * Add a Participant
- *
- * @param integer $thread_id
- * @param integer $user_id
- * @return boolean
- */
- function add_participant($thread_id, $user_id)
- {
- $this->db->trans_start();
-
- $participants[] = array('thread_id' => $thread_id,'user_id' => $user_id);
-
- $this->_insert_participants($participants);
-
- // Get Messages by Thread
- $messages = $this->_get_messages_by_thread_id($thread_id);
-
- foreach ($messages as $message)
- {
- $statuses[] = array('message_id' => $message['id'], 'user_id' => $user_id, 'status' => MSG_STATUS_UNREAD);
- }
-
- $this->_insert_statuses($statuses);
-
- $this->db->trans_complete();
-
- if ($this->db->trans_status() === FALSE)
- {
- $this->db->trans_rollback();
- return FALSE;
- }
-
- return TRUE;
- }
-
- // ------------------------------------------------------------------------
-
- /**
- * Remove a Participant
- *
- * @param integer $thread_id
- * @param integer $user_id
- * @return boolean
- */
- function remove_participant($thread_id, $user_id)
- {
- $this->db->trans_start();
-
- $this->_delete_participant($thread_id, $user_id);
- $this->_delete_statuses($thread_id, $user_id);
-
- $this->db->trans_complete();
-
- if ($this->db->trans_status() === FALSE)
- {
- $this->db->trans_rollback();
- return FALSE;
- }
-
- return TRUE;
- }
-
- // ------------------------------------------------------------------------
-
- /**
- * Valid New Participant - because of CodeIgniter's DB Class return style,
- * it is safer to check for uniqueness first
- *
- * @param integer $thread_id
- * @param integer $user_id
- * @return boolean
- */
- function valid_new_participant($thread_id, $user_id)
- {
- $sql = 'SELECT COUNT(*) AS count ' .
- ' FROM ' . $this->db->dbprefix . 'msg_participants p ' .
- ' WHERE p.thread_id = ? ' .
- ' AND p.user_id = ? ';
-
- $query = $this->db->query($sql, array($thread_id, $user_id));
-
- if ($query->row()->count)
- {
- return FALSE;
- }
-
- return TRUE;
- }
-
- // ------------------------------------------------------------------------
-
- /**
- * Application User
- *
- * @param integer $user_id`
- * @return boolean
- */
- function application_user($user_id)
- {
- $sql = 'SELECT COUNT(*) AS count ' .
- ' FROM ' . $this->db->dbprefix . USER_TABLE_TABLENAME .
- ' WHERE ' . USER_TABLE_ID . ' = ?' ;
-
- $query = $this->db->query($sql, array($user_id));
-
- if ($query->row()->count)
- {
- return TRUE;
- }
-
- return FALSE;
- }
-
- // ------------------------------------------------------------------------
-
- /**
- * Get Participant List
- *
- * @param integer $thread_id
- * @param integer $sender_id
- * @return mixed
- */
- function get_participant_list($thread_id, $sender_id = 0)
- {
- if ($results = $this->_get_thread_participants($thread_id, $sender_id))
- {
- return $results;
- }
- return FALSE;
- }
-
- // ------------------------------------------------------------------------
-
- /**
- * Get Message Count
- *
- * @param integer $user_id
- * @param integer $status_id
- * @return integer
- */
- function get_msg_count($user_id, $status_id = MSG_STATUS_UNREAD)
- {
- $query = $this->db->select('COUNT(*) AS msg_count')->where(array('user_id' => $user_id, 'status' => $status_id ))->get('msg_status');
-
- return $query->row()->msg_count;
- }
-
- // ------------------------------------------------------------------------
- // Private Functions from here out!
- // ------------------------------------------------------------------------
-
- /**
- * Insert Thread
- *
- * @param string $subject
- * @return integer
- */
- private function _insert_thread($subject)
- {
- $insert_id = $this->db->insert('msg_threads', array('subject' => $subject));
-
- return $this->db->insert_id();
- }
-
- /**
- * Insert Message
- *
- * @param integer $thread_id
- * @param integer $sender_id
- * @param string $body
- * @param integer $priority
- * @return integer
- */
- private function _insert_message($thread_id, $sender_id, $body, $priority)
- {
- $insert['thread_id'] = $thread_id;
- $insert['sender_id'] = $sender_id;
- $insert['body'] = $body;
- $insert['priority'] = $priority;
-
- $insert_id = $this->db->insert('msg_messages', $insert);
-
- return $this->db->insert_id();
- }
-
- /**
- * Insert Participants
- *
- * @param array $participants
- * @return bool
- */
- private function _insert_participants($participants)
- {
- return $this->db->insert_batch('msg_participants', $participants);
- }
-
- /**
- * Insert Statuses
- *
- * @param array $statuses
- * @return bool
- */
- private function _insert_statuses($statuses)
- {
- return $this->db->insert_batch('msg_status', $statuses);
- }
-
- /**
- * Get Thread ID from Message
- *
- * @param integer $msg_id
- * @return integer
- */
- private function _get_thread_id_from_message($msg_id)
- {
- $query = $this->db->select('thread_id')->get_where('msg_messages', array('id' => $msg_id));
-
- if ($query->num_rows())
- {
- return $query->row()->thread_id;
- }
- return 0;
- }
-
- /**
- * Get Messages by Thread
- *
- * @param integer $thread_id
- * @return array
- */
- private function _get_messages_by_thread_id($thread_id)
- {
- $query = $this->db->get_where('msg_messages', array('thread_id' => $thread_id));
-
- return $query->result_array();
- }
-
-
- /**
- * Get Thread Particpiants
- *
- * @param integer $thread_id
- * @param integer $sender_id
- * @return array
- */
- private function _get_thread_participants($thread_id, $sender_id = 0)
- {
- $array['thread_id'] = $thread_id;
-
- if ($sender_id) // If $sender_id 0, no one to exclude
- {
- $array['msg_participants.user_id != '] = $sender_id;
- }
-
- $this->db->select('msg_participants.user_id, '.USER_TABLE_USERNAME, FALSE);
- $this->db->join(USER_TABLE_TABLENAME, 'msg_participants.user_id = ' . USER_TABLE_ID);
-
- $query = $this->db->get_where('msg_participants', $array);
-
- return $query->result_array();
- }
-
- /**
- * Delete Participant
- *
- * @param integer $thread_id
- * @param integer $user_id
- * @return boolean
- */
- private function _delete_participant($thread_id, $user_id)
- {
- $this->db->delete('msg_participants', array('thread_id' => $thread_id, 'user_id' => $user_id));
-
- if ($this->db->affected_rows() > 0)
- {
- return TRUE;
- }
- return FALSE;
- }
-
- /**
- * Delete Statuses
- *
- * @param integer $thread_id
- * @param integer $user_id
- * @return boolean
- */
- private function _delete_statuses($thread_id, $user_id)
- {
- $sql = 'DELETE s FROM msg_status s ' .
- ' JOIN ' . $this->db->dbprefix . 'msg_messages m ON (m.id = s.message_id) ' .
- ' WHERE m.thread_id = ? ' .
- ' AND s.user_id = ? ';
-
- $query = $this->db->query($sql, array($thread_id, $user_id));
-
- return TRUE;
- }
-}
-
-/* end of file mahana_model.php */
diff --git a/application/views/system/messageWrite.php b/application/views/system/messageWrite.php
index f0d22070a..69b37589c 100644
--- a/application/views/system/messageWrite.php
+++ b/application/views/system/messageWrite.php
@@ -3,14 +3,47 @@