mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-06-01 20:29:29 +00:00
messages kann als systemuser geschickt werden
This commit is contained in:
@@ -58,9 +58,10 @@ class Messages extends Auth_Controller
|
||||
$body = $this->input->post('body');
|
||||
$recipients_ids = $this->input->post('recipients_ids');
|
||||
$relationmessage_id = $this->input->post('relationmessage_id');
|
||||
$systemuser = $this->input->post('systemuser');
|
||||
$type = $this->input->post('type');
|
||||
|
||||
$sendImplicitTemplate = $this->CLMessagesModel->sendImplicitTemplate($type, $recipients_ids, $subject, $body, $relationmessage_id);
|
||||
$sendImplicitTemplate = $this->CLMessagesModel->sendImplicitTemplate($type, $recipients_ids, $subject, $body, $relationmessage_id, isset($systemuser));
|
||||
if (isSuccess($sendImplicitTemplate))
|
||||
{
|
||||
$this->load->view('system/messages/htmlMessageSentSuccess');
|
||||
@@ -93,16 +94,29 @@ class Messages extends Auth_Controller
|
||||
public function parseMessageText()
|
||||
{
|
||||
$receiver_id = $this->input->post('receiver_id');
|
||||
$systemuser = $this->input->post('systemuser');
|
||||
$text = $this->input->post('text');
|
||||
$type = $this->input->post('type');
|
||||
|
||||
$sender_uid = null;
|
||||
|
||||
if ($systemuser === "true")
|
||||
{
|
||||
$this->BenutzerModel->addSelect('uid');
|
||||
if (!$result = getData($this->BenutzerModel->getFromPersonId($this->config->item(MessageLib::CFG_SYSTEM_PERSON_ID))))
|
||||
{
|
||||
show_error('No sender_uid found');
|
||||
}
|
||||
$sender_uid = $result[0]->uid;
|
||||
}
|
||||
if ($type == Messages_model::TYPE_PERSONS)
|
||||
{
|
||||
$this->outputJson($this->CLMessagesModel->parseMessageTextPerson($receiver_id, $text));
|
||||
$this->outputJson($this->CLMessagesModel->parseMessageTextPerson($receiver_id, $text, $sender_uid));
|
||||
|
||||
}
|
||||
elseif ($type == Messages_model::TYPE_PRESTUDENTS)
|
||||
{
|
||||
$this->outputJson($this->CLMessagesModel->parseMessageTextPrestudent($receiver_id, $text));
|
||||
$this->outputJson($this->CLMessagesModel->parseMessageTextPrestudent($receiver_id, $text, $sender_uid));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -468,7 +468,8 @@ class MessageLib
|
||||
'body' => $body,
|
||||
'priority' => $priority,
|
||||
'relationmessage_id' => $relationmessage_id,
|
||||
'oe_kurzbz' => $senderOU
|
||||
'oe_kurzbz' => $senderOU,
|
||||
'insertvon' => isLogged() ? getAuthUID() : null
|
||||
);
|
||||
|
||||
$saveMessageResult = $this->_ci->MessageModel->insert($messageData);
|
||||
@@ -481,7 +482,8 @@ class MessageLib
|
||||
'person_id' => $receiver_id,
|
||||
'message_id' => $messageId,
|
||||
'token' => generateToken(),
|
||||
'oe_kurzbz' => $receiverOU
|
||||
'oe_kurzbz' => $receiverOU,
|
||||
'insertvon' => isLogged() ? getAuthUID() : null
|
||||
);
|
||||
|
||||
$saveMessageResult = $this->_ci->RecipientModel->insert($recipientData);
|
||||
|
||||
@@ -37,6 +37,7 @@ class Messages_model extends CI_Model
|
||||
|
||||
// Loads the message library
|
||||
$this->load->library('MessageLib'); // MessageModel loaded here!
|
||||
$this->load->library('PermissionLib');
|
||||
// Loads the person log library
|
||||
$this->load->library('PersonLogLib');
|
||||
// Loads the widget library
|
||||
@@ -375,11 +376,25 @@ class Messages_model extends CI_Model
|
||||
* Sends a new message or a reply to a message (if $relationmessage_id is given)
|
||||
* using the template stored in the subject and body
|
||||
*/
|
||||
public function sendImplicitTemplate($type, $recipients_ids, $subject, $body, $relationmessage_id = null)
|
||||
public function sendImplicitTemplate($type, $recipients_ids, $subject, $body, $relationmessage_id = null, $systemuser = false)
|
||||
{
|
||||
// Retrieves the sender id
|
||||
$sender_id = getAuthPersonId();
|
||||
if (!is_numeric($sender_id)) show_error('The current logged user person_id is not defined');
|
||||
if (!($systemuser))
|
||||
{
|
||||
$sender_uid = null;
|
||||
// Retrieves the sender id
|
||||
$sender_id = getAuthPersonId();
|
||||
if (!is_numeric($sender_id)) show_error('The current logged user person_id is not defined');
|
||||
}
|
||||
else
|
||||
{
|
||||
$sender_id = $this->config->item(MessageLib::CFG_SYSTEM_PERSON_ID);
|
||||
$this->BenutzerModel->addSelect('uid');
|
||||
if (!$result = getData($this->BenutzerModel->getFromPersonId($this->config->item(MessageLib::CFG_SYSTEM_PERSON_ID))))
|
||||
{
|
||||
show_error('No sender_uid found');
|
||||
}
|
||||
$sender_uid = $result[0]->uid;
|
||||
}
|
||||
|
||||
$msgVarsData = error('No persons nor prestudents were provided');
|
||||
// Retrieves message vars data for the given user/s
|
||||
@@ -406,7 +421,7 @@ class Messages_model extends CI_Model
|
||||
foreach (getData($msgVarsData) as $receiver)
|
||||
{
|
||||
// Merge receivers data with logged in user data
|
||||
$msgVarsDataArray = $this->_addMsgVarsDataOfLoggedInUser($receiver);
|
||||
$msgVarsDataArray = $this->_addMsgVarsDataOfLoggedInUser($receiver, $sender_uid);
|
||||
|
||||
$msgVarsDataArray = $this->_lowerReplaceSpaceArrayKeys((array)getData($msgVarsDataArray)[0]); // replaces array keys
|
||||
$parsedSubject = parseText($subject, $msgVarsDataArray);
|
||||
@@ -464,7 +479,7 @@ class Messages_model extends CI_Model
|
||||
* Sends a new message using the given template and information present in parameter prestudents
|
||||
* Extra variables can be added using parameter $msgVars
|
||||
*/
|
||||
public function sendExplicitTemplateSenderId($sender_id, $prestudents, $oe_kurzbz, $vorlage_kurzbz, $msgVars)
|
||||
public function sendExplicitTemplateSenderId($sender_id, $prestudents, $oe_kurzbz, $vorlage_kurzbz, $msgVars, $systemuser = false)
|
||||
{
|
||||
// Retrieves message vars data for the given user/s
|
||||
$msgVarsData = $this->MessageModel->getMsgVarsDataByPrestudentId($prestudents);
|
||||
@@ -472,15 +487,28 @@ class Messages_model extends CI_Model
|
||||
if (!hasData($msgVarsData)) show_error('No recipients were given');
|
||||
|
||||
$prestudentsData = $this->PrestudentModel->getOrganisationunits($prestudents);
|
||||
|
||||
// Get the senders uid (if user is an active employee)
|
||||
$this->BenutzerModel->addSelect('uid');
|
||||
$this->BenutzerModel->addJoin('public.tbl_mitarbeiter ma', 'ma.mitarbeiter_uid = uid');
|
||||
if (!$result = getData($this->BenutzerModel->getFromPersonId($sender_id)))
|
||||
|
||||
if (!($systemuser))
|
||||
{
|
||||
show_error('No sender_uid found');
|
||||
// Get the senders uid (if user is an active employee)
|
||||
$this->BenutzerModel->addSelect('uid');
|
||||
$this->BenutzerModel->addJoin('public.tbl_mitarbeiter ma', 'ma.mitarbeiter_uid = uid');
|
||||
if (!$result = getData($this->BenutzerModel->getFromPersonId($sender_id)))
|
||||
{
|
||||
show_error('No sender_uid found');
|
||||
}
|
||||
$sender_uid = $result[0]->uid;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->BenutzerModel->addSelect('uid');
|
||||
if (!$result = getData($this->BenutzerModel->getFromPersonId($this->config->item(MessageLib::CFG_SYSTEM_PERSON_ID))))
|
||||
{
|
||||
show_error('No sender_uid found');
|
||||
}
|
||||
$sender_uid = $result[0]->uid;
|
||||
$sender_id = $this->config->item(MessageLib::CFG_SYSTEM_PERSON_ID);
|
||||
}
|
||||
$sender_uid = $result[0]->uid;
|
||||
|
||||
// Adds the organisation unit to each prestudent
|
||||
if (isEmptyString($oe_kurzbz) && hasData($msgVarsData) && hasData($prestudentsData))
|
||||
@@ -631,14 +659,14 @@ class Messages_model extends CI_Model
|
||||
* Parse the given given text using data from the given user
|
||||
* Use the CI parser which performs simple text substitution for pseudo-variable
|
||||
*/
|
||||
public function parseMessageTextPerson($person_id, $text)
|
||||
public function parseMessageTextPerson($person_id, $text, $sender_uid = null)
|
||||
{
|
||||
$parseMessageText = error('The given person_id is not a valid number');
|
||||
|
||||
if (is_numeric($person_id)) $parseMessageText = $this->MessageModel->getMsgVarsDataByPersonId($person_id);
|
||||
|
||||
// Add message vars data of the logged in user
|
||||
$parseMessageText = $this->_addMsgVarsDataOfLoggedInUser($parseMessageText);
|
||||
$parseMessageText = $this->_addMsgVarsDataOfLoggedInUser($parseMessageText, $sender_uid);
|
||||
|
||||
if (hasData($parseMessageText))
|
||||
{
|
||||
@@ -657,14 +685,14 @@ class Messages_model extends CI_Model
|
||||
* Parse the given given text using data from the given user
|
||||
* Use the CI parser which performs simple text substitution for pseudo-variable
|
||||
*/
|
||||
public function parseMessageTextPrestudent($prestudent_id, $text)
|
||||
public function parseMessageTextPrestudent($prestudent_id, $text, $sender_uid = null)
|
||||
{
|
||||
$parseMessageText = error('The given prestudent_id is not a valid number');
|
||||
|
||||
if (is_numeric($prestudent_id)) $parseMessageText = $this->MessageModel->getMsgVarsDataByPrestudentId($prestudent_id);
|
||||
|
||||
// Add message vars data of the logged in user
|
||||
$parseMessageText = $this->_addMsgVarsDataOfLoggedInUser($parseMessageText);
|
||||
$parseMessageText = $this->_addMsgVarsDataOfLoggedInUser($parseMessageText, $sender_uid);
|
||||
|
||||
if (hasData($parseMessageText))
|
||||
{
|
||||
@@ -908,6 +936,8 @@ class Messages_model extends CI_Model
|
||||
$senderIsAdmin = $this->BenutzerrolleModel->isAdminByPersonId($sender_id);
|
||||
if (isError($senderIsAdmin)) show_error(getError($senderIsAdmin));
|
||||
|
||||
$allowSenderChange = $this->permissionlib->isBerechtigt('infocenter');
|
||||
|
||||
// ---------------------------------------------------------------------------------------
|
||||
// Returns data as an array
|
||||
return array (
|
||||
@@ -921,7 +951,8 @@ class Messages_model extends CI_Model
|
||||
'recipientsArray' => $recipientsArray,
|
||||
'recipients_ids' => $recipients_ids,
|
||||
'relationmessage_id' => $relationmessage,
|
||||
'type' => $type
|
||||
'type' => $type,
|
||||
'allowSenderChange' => $allowSenderChange
|
||||
);
|
||||
}
|
||||
|
||||
@@ -940,7 +971,9 @@ class Messages_model extends CI_Model
|
||||
{
|
||||
$otherMsgVarsDataObj = getData($otherMsgVarsDataObj)[0];
|
||||
}
|
||||
|
||||
|
||||
if (isEmptyString($uid))
|
||||
$uid = null;
|
||||
// Retrieve message vars data of the logged in user
|
||||
if (!$msgVarsDataLoggedInUser = getData($this->MessageModel->getMsgVarsDataByLoggedInUser($uid))[0])
|
||||
{
|
||||
|
||||
@@ -109,11 +109,16 @@ class Message_model extends DB_Model
|
||||
re.vornamen AS revornamen,
|
||||
s.status,
|
||||
s.statusinfo,
|
||||
s.insertamum AS statusamum
|
||||
s.insertamum AS statusamum,
|
||||
mp.vorname as insertvorname,
|
||||
mp.nachname as insertnachname
|
||||
FROM public.tbl_msg_message m
|
||||
JOIN public.tbl_msg_recipient r ON m.message_id = r.message_id
|
||||
JOIN public.tbl_person se ON (m.person_id = se.person_id)
|
||||
JOIN public.tbl_person re ON (r.person_id = re.person_id)
|
||||
|
||||
LEFT JOIN public.tbl_benutzer mb ON (mb.uid = m.insertvon)
|
||||
LEFT JOIN public.tbl_person mp ON (mp.person_id = mb.person_id)
|
||||
LEFT JOIN (
|
||||
SELECT message_id, person_id, status, statusinfo, insertamum
|
||||
FROM public.tbl_msg_status
|
||||
|
||||
@@ -11,6 +11,7 @@ $widthColumn = $msgExists === true ? 8 : 12;
|
||||
<th><?php echo ucfirst($this->p->t('global','empfaenger')) ?></th>
|
||||
<th><?php echo ucfirst($this->p->t('global','betreff')) ?></th>
|
||||
<th><?php echo ucfirst($this->p->t('global','gelesenAm')) ?></th>
|
||||
<th><?php echo ucfirst($this->p->t('lehre','insert_von')) ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -21,6 +22,7 @@ $widthColumn = $msgExists === true ? 8 : 12;
|
||||
<td><?php echo $message->revorname.' '.$message->renachname ?></td>
|
||||
<td><?php echo $message->subject ?></td>
|
||||
<td><?php echo isset($message->statusamum) ? date_format(date_create($message->statusamum), 'd.m.Y H:i:s') : '' ?></td>
|
||||
<td><?php echo $message->insertvorname.' '.$message->insertnachname ?></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
|
||||
@@ -30,13 +30,29 @@
|
||||
</div>
|
||||
</div>
|
||||
<form id="sendForm" method="post" action="<?php echo site_url('/system/messages/Messages/sendImplicitTemplate'); ?>">
|
||||
<?php if($allowSenderChange) : ?>
|
||||
<div class="row">
|
||||
<div class="form-group">
|
||||
<div class="col-lg-1 msgfield msgfieldcol-left">
|
||||
<label>
|
||||
<?php echo ucfirst($this->p->t('global', 'sender')); ?>:
|
||||
</label>
|
||||
</div>
|
||||
<div class="col-lg-6 msgfieldcol-right">
|
||||
<div class="checkbox-inline">
|
||||
<input type="checkbox" name="systemuser" id="systemuser" />
|
||||
<?php echo "Systemuser?" ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif;?>
|
||||
|
||||
<div class="row">
|
||||
<div class="form-group">
|
||||
<div class="col-lg-1 msgfieldcol-left">
|
||||
<label>
|
||||
|
||||
<?php echo ucfirst($this->p->t('global', 'empfaenger')); ?>:
|
||||
|
||||
</label>
|
||||
</div>
|
||||
<div class="col-lg-11 msgfieldcol-right">
|
||||
|
||||
@@ -30,6 +30,24 @@
|
||||
</div>
|
||||
</div>
|
||||
<form id="sendForm" method="post" action="<?php echo site_url('/system/messages/Messages/sendImplicitTemplate'); ?>">
|
||||
<?php if($allowSenderChange) : ?>
|
||||
<div class="row">
|
||||
<div class="form-group">
|
||||
<div class="col-lg-1 msgfieldcol-left">
|
||||
<label>
|
||||
<?php echo ucfirst($this->p->t('global', 'sender')); ?>:
|
||||
</label>
|
||||
</div>
|
||||
<div class="col-lg-6 msgfieldcol-right">
|
||||
<div class="checkbox-inline">
|
||||
<input type="checkbox" name="systemuser" id="systemuser">
|
||||
<?php echo "Systemuser?" ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="row">
|
||||
<div class="form-group">
|
||||
<div class="col-lg-1 msgfieldcol-left">
|
||||
@@ -98,11 +116,11 @@
|
||||
<br>
|
||||
<div class="form-group">
|
||||
<label>
|
||||
|
||||
|
||||
<?php echo ucfirst($this->p->t('ui', 'meineFelder')); ?>:
|
||||
|
||||
</label>
|
||||
|
||||
|
||||
<?php
|
||||
$size = count($user_fields) > 5 ? 5 : count($user_fields);
|
||||
echo $this->widgetlib->widget(
|
||||
|
||||
@@ -126,6 +126,10 @@ echo ']>
|
||||
class="sortDirectionIndicator"
|
||||
sort="rdf:http://www.technikum-wien.at/messages/rdf#statusdatum"/>
|
||||
<splitter class="tree-splitter"/>
|
||||
<treecol id="messages-tree-status" label="Hinzugefügt von" flex="2" hidden="false"
|
||||
class="sortDirectionIndicator"
|
||||
sort="rdf:http://www.technikum-wien.at/messages/rdf#insertvon"/>
|
||||
<splitter class="tree-splitter"/>
|
||||
</treecols>
|
||||
|
||||
<template>
|
||||
@@ -142,6 +146,7 @@ echo ']>
|
||||
<treecell label="rdf:http://www.technikum-wien.at/messages/rdf#recipient_id"/>
|
||||
<treecell label="rdf:http://www.technikum-wien.at/messages/rdf#status"/>
|
||||
<treecell label="rdf:http://www.technikum-wien.at/messages/rdf#statusdatum"/>
|
||||
<treecell label="rdf:http://www.technikum-wien.at/messages/rdf#insertvon"/>
|
||||
</treerow>
|
||||
</treeitem>
|
||||
</treechildren>
|
||||
|
||||
@@ -8,7 +8,7 @@ function tinymcePreviewSetContent()
|
||||
{
|
||||
if ($("#recipients").children(":selected").val() > -1)
|
||||
{
|
||||
parseMessageText($("#recipients").children(":selected").val(), tinyMCE.get("bodyTextArea").getContent());
|
||||
parseMessageText($("#recipients").children(":selected").val(),$("#sender").val(), tinyMCE.get("bodyTextArea").getContent(), $("#systemuser").prop("checked"));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -17,13 +17,14 @@ function tinymcePreviewSetContent()
|
||||
}
|
||||
}
|
||||
|
||||
function parseMessageText(receiver_id, text)
|
||||
function parseMessageText(receiver_id, sender_id, text, systemuser)
|
||||
{
|
||||
FHC_AjaxClient.ajaxCallPost(
|
||||
"system/messages/Messages/parseMessageText",
|
||||
{
|
||||
receiver_id: receiver_id,
|
||||
text: text,
|
||||
systemuser: systemuser,
|
||||
type: $("#type").val()
|
||||
},
|
||||
{
|
||||
|
||||
@@ -8,7 +8,7 @@ function tinymcePreviewSetContent()
|
||||
{
|
||||
if ($("#recipients").children(":selected").val() > -1)
|
||||
{
|
||||
parseMessageText($("#recipients").children(":selected").val(), tinyMCE.get("bodyTextArea").getContent());
|
||||
parseMessageText($("#recipients").children(":selected").val(), tinyMCE.get("bodyTextArea").getContent(), $("#systemuser").prop("checked"));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -17,13 +17,16 @@ function tinymcePreviewSetContent()
|
||||
}
|
||||
}
|
||||
|
||||
function parseMessageText(receiver_id, text)
|
||||
function parseMessageText(receiver_id, text, systemuser)
|
||||
{
|
||||
console.log($("#sender").val());
|
||||
|
||||
FHC_AjaxClient.ajaxCallPost(
|
||||
"system/messages/Messages/parseMessageText",
|
||||
{
|
||||
receiver_id: receiver_id,
|
||||
text: text,
|
||||
systemuser: systemuser,
|
||||
type: $("#type").val()
|
||||
},
|
||||
{
|
||||
|
||||
@@ -53,7 +53,8 @@ SELECT
|
||||
m.person_id as sender_id,
|
||||
r.person_id as recipient_id,
|
||||
MAX(ss.status) as status,
|
||||
MAX(ss.insertamum) as statusdatum
|
||||
MAX(ss.insertamum) as statusdatum,
|
||||
CASE WHEN m.insertvon IS NOT NULL THEN (SELECT COALESCE(titelpre,'') || ' ' || COALESCE(vorname,'') || ' ' || COALESCE(nachname,'') || ' ' || COALESCE(titelpost,'') FROM public.tbl_person JOIN public.tbl_benutzer ON tbl_person.person_id = tbl_benutzer.person_id WHERE tbl_benutzer.uid = m.insertvon) END as insertvon
|
||||
FROM public.tbl_msg_message m
|
||||
JOIN public.tbl_msg_recipient r USING(message_id)
|
||||
JOIN public.tbl_msg_status ss ON(r.message_id = ss.message_id AND ss.person_id = r.person_id)
|
||||
@@ -71,7 +72,8 @@ SELECT
|
||||
m.person_id as sender_id,
|
||||
r.person_id as recipient_id,
|
||||
MAX(ss.status) as status,
|
||||
MAX(ss.insertamum) as statusdatum
|
||||
MAX(ss.insertamum) as statusdatum,
|
||||
CASE WHEN m.insertvon IS NOT NULL THEN (SELECT COALESCE(titelpre,'') || ' ' || COALESCE(vorname,'') || ' ' || COALESCE(nachname,'') || ' ' || COALESCE(titelpost,'') FROM public.tbl_person JOIN public.tbl_benutzer ON tbl_person.person_id = tbl_benutzer.person_id WHERE tbl_benutzer.uid = m.insertvon) END as insertvon
|
||||
FROM public.tbl_msg_recipient r
|
||||
JOIN public.tbl_msg_status ss USING(message_id, person_id)
|
||||
JOIN public.tbl_msg_message m USING(message_id)
|
||||
@@ -113,6 +115,7 @@ if($db->db_query($qry))
|
||||
$oRdf->obj[$i]->setAttribut('recipient',$row->recipient,true);
|
||||
$oRdf->obj[$i]->setAttribut('sender_id',$row->sender_id,true);
|
||||
$oRdf->obj[$i]->setAttribut('recipient_id',$row->recipient_id,true);
|
||||
$oRdf->obj[$i]->setAttribut('insertvon',$row->insertvon,true);
|
||||
|
||||
if($row->relationmessage_id!='')
|
||||
$oRdf->addSequence($row->message_id, $row->relationmessage_id);
|
||||
|
||||
Reference in New Issue
Block a user