possible to answer to messages with token without login

This commit is contained in:
alex
2018-05-18 19:28:27 +02:00
parent 4f993b06f4
commit 95e18e1ef1
11 changed files with 374 additions and 102 deletions
+1
View File
@@ -5,4 +5,5 @@ if (! defined('BASEPATH')) exit('No direct script access allowed');
$config['fhc_version'] = '3.3';
$config['addons_aufnahme_url'] = array();
$config['addons_aufnahme_url']['fallback'] = 'https://localhost/fhcomplete/index.ci.php/ViewMessage/writeReply/';
$config['addons_aufnahme_url']['OE_ROOT'] = 'https://SERVER-NAME/addons/aufnahme/OE_ROOT/cis/index.php';
+11
View File
@@ -75,5 +75,16 @@ class Redirect extends CI_Controller
redirect($addonAufnahmeUrls[$organisationRoot] . '?token=' . $token);
}
}
else
{
$addonAufnahmeUrls = $this->config->item('addons_aufnahme_url');
if (isset($token)
&& hasData($msg)
&& is_array($addonAufnahmeUrls)
&& isset($addonAufnahmeUrls['fallback']))
{
redirect($addonAufnahmeUrls['fallback'] . '?token=' . $token);
}
}
}
}
+127
View File
@@ -15,6 +15,7 @@
if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
* Handles sending messages with token
* NOTE: in this controller is not possible to include/call everything
* that automatically call the authentication system, like the most of models or libraries
*/
@@ -83,4 +84,130 @@ class ViewMessage extends CI_Controller
$this->load->view('system/messageHTML.php', $data);
}
}
/**
* write the reply
*/
public function writeReply()
{
$token = $this->input->get('token');
if (empty($token))
{
show_error('no token supplied');
}
$msg = null;
// Get message data if possible
$msg = $this->MessageTokenModel->getMessageByToken($token);
if (!hasData($msg))
{
show_error('no message found');
}
$msg = $msg->retval[0];
// Get variables
$receiverData = $this->MessageTokenModel->getPersonData($msg->sender_id);
if (!hasData($receiverData))
{
show_error('no sender found');
}
$data = array (
'receivers' => $receiverData->retval,
'message' => $msg,
'token' => $token
);
$v = $this->load->view('system/messageWriteReply', $data);
}
/**
* send reply
*/
public function sendReply()
{
$this->load->model('system/Message_model', 'MessageModel');
$this->load->library('MessageLib');
$error = false;
$subject = $this->input->post('subject');
$body = $this->input->post('body');
$persons = $this->input->post('persons');
$relationmessage_id = $this->input->post('relationmessage_id');
$token = $this->input->post('token');
if (!isset($relationmessage_id) || $relationmessage_id == '' || !isset($token) || $token == '')
{
show_error('Error while sending reply');
$error = true;
}
$relationmsg = $this->MessageTokenModel->getMessageByToken($token);
// check if correct message
if (!hasData($relationmsg) || $relationmessage_id !== $relationmsg->retval[0]->message_id)
{
show_error('Error while sending reply');
$error = true;
}
// get sender (receiver of previous msg)
$sender_id = $relationmsg->retval[0]->receiver_id;
// get message data of persons
$data = $this->MessageTokenModel->getPersonData($persons);
// send message(s)
if (hasData($data))
{
for ($i = 0; $i < count($data->retval); $i++)
{
$dataArray = (array)$data->retval[$i];
$msg = $this->messagelib->sendMessage($sender_id, $dataArray['person_id'], $subject, $body, PRIORITY_NORMAL, $relationmessage_id, null);
if ($msg->error)
{
show_error($msg->retval);
$error = true;
break;
}
// Loads the person log library
$this->load->library('PersonLogLib');
// Write log entry for sender
$logtype_kurzbz = 'Action';
$logdata = array(
'name' => 'Message sent',
'message' => 'Message sent from person '.$sender_id.' to '.$dataArray['person_id'].', messageid '.$msg->retval,
'success' => 'true'
);
$taetigkeit_kurzbz = 'kommunikation';
$app = 'core';
$oe_kurzbz = null;
$insertvon = 'online';
$this->personloglib->log(
$sender_id,
$logtype_kurzbz,
$logdata,
$taetigkeit_kurzbz,
$app,
$oe_kurzbz,
$insertvon
);
}
}
if (!$error)
{
echo "Messages sent successfully";
}
}
}
+2 -2
View File
@@ -185,9 +185,9 @@ class Messages extends FHC_Controller
{
$user_person = $this->PersonModel->getByUid($this->uid);
if (isError($user_person))
if (!hasData($user_person))
{
show_error($user_person->retval);
show_error('no sender');
}
$sender_id = $user_person->retval[0]->person_id;
}
@@ -31,6 +31,7 @@ class MessageToken_model extends CI_Model
$sql = 'SELECT r.message_id,
m.person_id as sender_id,
r.person_id as receiver_id,
r.sent,
m.subject,
m.body,
m.insertamum,
@@ -174,6 +175,34 @@ class MessageToken_model extends CI_Model
}
}
/**
* Get data of a person
*/
public function getPersonData($person_id)
{
$sql = 'SELECT person_id,
vorname as "Vorname",
nachname as "Nachname",
anrede as "Anrede",
titelpost as "TitelPost",
titelpre as "TitelPre",
vornamen as "Vornamen"
FROM public.tbl_person
WHERE person_id %s ?';
$result = $this->db->query(sprintf($sql, is_array($person_id) ? 'IN' : '='), array($person_id));
// If no errors occurred
if ($result)
{
return success($result->result());
}
else
{
return error($this->db->error());
}
}
/**
*
*/
@@ -48,6 +48,7 @@ class Recipient_model extends DB_Model
$sql = 'SELECT r.message_id,
m.person_id as sender_id,
r.person_id as receiver_id,
r.sent,
m.subject,
m.body,
m.insertamum,
+81
View File
@@ -0,0 +1,81 @@
<div class="row">
<div class="form-group">
<div class="col-lg-1">
<label>To:</label>
</div>
<div class="col-lg-11">
<?php
for ($i = 0; $i < count($receivers); $i++)
{
$receiver = $receivers[$i];
// Every 10 recipients a new line
if ($i > 1 && $i % 10 == 0)
{
echo '<br>';
}
echo $receiver->Vorname." ".$receiver->Nachname."; ";
}
?>
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<div class="col-lg-1 msgfield">
<label>Subject:</label>
</div>&nbsp;
<?php
$subject = '';
if (isset($message))
{
$subject = 'Re: '.$message->subject;
}
?>
<div class="col-lg-7">
<input id="subject" class="form-control col-lg-10" type="text" value="<?php echo $subject; ?>"
name="subject">
</div>
</div>
</div>
<br>
<div class="row">
<div class="col-lg-<?php echo isset($variables) ? 10 : 12 ?>">
<label>Message:</label>
<?php
$body = '';
if (isset($message) )
{
if (isset($receivers[0]))
$body .= '<br><br><br><!--<hr style="color: #e6e6e6">--><blockquote><i>On '.date_format(date_create($message->sent), 'd.m.Y H:i').' '.$receivers[0]->Vorname.' '.$receivers[0]->Nachname.' wrote:'.'</i></blockquote>';
$body .= '<blockquote style="border-left:2px solid; padding-left: 8px">';
$body .= $message->body.'</blockquote>';
}
?>
<textarea id="bodyTextArea" name="body"><?php echo $body; ?></textarea>
</div>
<?php
if (isset($variables)):
?>
<div class="col-lg-2">
<div class="form-group">
<label>Variables:</label>
<select id="variables" class="form-control" size="14" multiple="multiple">
<?php
foreach ($variables as $key => $val)
{
?>
<option value="<?php echo $key; ?>"><?php echo $val; ?></option>
<?php
}
?>
</select>
</div>
</div>
<?php endif; ?>
</div>
<br>
<div class="row">
<div class="col-lg-<?php echo isset($variables) ? 10 : 12 ?> text-right">
<button id="sendButton" class="btn btn-default" type="button">Send</button>
</div>
</div>
+2
View File
@@ -42,6 +42,8 @@
if ($isEmployee === false && $href != '')
{
?>
<tr><td>&nbsp;</td></tr>
<tr><td>&nbsp;</td></tr>
<tr>
<td colspan="3" align="center" style="background-color:#dddddd; padding:5px;">
<a href="<?php echo $href; ?>">Reply</a>
+19 -100
View File
@@ -8,24 +8,14 @@ $this->load->view(
'fontawesome' => true,
'tinymce' => true,
'sbadmintemplate' => true,
'customCSSs' => 'public/css/sbadmin2/admintemplate_contentonly.css',
'customJSs' => 'public/js/bootstrapper.js'
'customCSSs' => array('public/css/sbadmin2/admintemplate_contentonly.css', 'public/css/messageWrite.css'),
'customJSs' => array('public/js/bootstrapper.js')
)
);
?>
<body>
<style>
input[type=text] {
height: 28px;
padding: 0px;
}
.msgfield label {
margin-bottom: 0px !important;
margin-top: 3px;
}
</style>
<?php
$href = str_replace("/system/Messages/write", "/system/Messages/send", $_SERVER["REQUEST_URI"]);
$href = site_url().'/system/Messages/send/';
?>
<div id="wrapper">
<div id="page-wrapper">
@@ -36,78 +26,7 @@ $href = str_replace("/system/Messages/write", "/system/Messages/send", $_SERVER[
</div>
</div>
<form id="sendForm" method="post" action="<?php echo $href; ?>">
<div class="row">
<div class="form-group">
<div class="col-lg-1">
<label>To:</label>
</div>
<div class="col-lg-11">
<?php
for ($i = 0; $i < count($receivers); $i++)
{
$receiver = $receivers[$i];
// Every 10 recipients a new line
if ($i > 1 && $i % 10 == 0)
{
echo '<br>';
}
echo $receiver->Vorname." ".$receiver->Nachname."; ";
}
?>
</div>
</div>
</div>
<div class="row">
<div class="form-group form-inline">
<div class="col-lg-1 msgfield">
<label>Subject:</label>
</div>&nbsp;
<?php
$subject = '';
if (isset($message))
{
$subject = 'Re: '.$message->subject;
}
?>
<div class="col-lg-10">
<input id="subject" class="form-control" type="text" value="<?php echo $subject; ?>"
name="subject" size="70">
</div>
</div>
</div>
<br>
<div class="row">
<div class="col-lg-10">
<label>Message:</label>
<?php
$body = '';
if (isset($message))
{
$body = $message->body;
}
?>
<textarea id="bodyTextArea" name="body"><?php echo $body; ?></textarea>
</div>
<?php
if (isset($variables)):
?>
<div class="col-lg-2">
<div class="form-group">
<label>Variables:</label>
<select id="variables" class="form-control" size="14" multiple="multiple">
<?php
foreach ($variables as $key => $val)
{
?>
<option value="<?php echo $key; ?>"><?php echo $val; ?></option>
<?php
}
?>
</select>
</div>
</div>
<?php endif; ?>
</div>
<?php $this->load->view('system/messageForm.php'); ?>
<br>
<div class="row">
<div class="col-lg-3 text-right">
@@ -119,9 +38,6 @@ $href = str_replace("/system/Messages/write", "/system/Messages/send", $_SERVER[
);
?>
</div>
<div class="col-lg-offset-6 col-lg-1 text-right">
<button id="sendButton" class="btn btn-default" type="button">Send</button>
</div>
</div>
<?php if (isset($receivers) && count($receivers) > 0): ?>
<hr>
@@ -196,18 +112,25 @@ $href = str_replace("/system/Messages/write", "/system/Messages/send", $_SERVER[
</div>
</div>
<script>
const CONTROLLER_URL = FHC_JS_DATA_STORAGE_OBJECT.app_root + FHC_JS_DATA_STORAGE_OBJECT.ci_router + "/"+FHC_JS_DATA_STORAGE_OBJECT.called_path;
tinymce.init({
selector: "#bodyTextArea",
height: 155
plugins: "autoresize",
autoresize_min_height: 150,
autoresize_max_height: 600,
autoresize_bottom_margin: 10
});
tinymce.init({
menubar: false,
toolbar: false,
statusbar: false,
readonly: 1,
selector: "#tinymcePreview",
statusbar: true,
plugins: "autoresize"
plugins: "autoresize",
autoresize_min_height: 150,
autoresize_bottom_margin: 10
});
$(document).ready(function ()
@@ -258,13 +181,9 @@ $href = str_replace("/system/Messages/write", "/system/Messages/send", $_SERVER[
{
if (this.value != '')
{
<?php
$url = str_replace("/system/Messages/write", "/system/Messages/getVorlage", $_SERVER["REQUEST_URI"]);
?>
$.ajax({
dataType: "json",
url: "<?php echo $url; ?>",
url: CONTROLLER_URL+"/getVorlage",
data: {"vorlage_kurzbz": this.value},
success: function (data, textStatus, jqXHR)
{
@@ -279,6 +198,9 @@ $href = str_replace("/system/Messages/write", "/system/Messages/send", $_SERVER[
}
});
}
$("#subject").focus();
});
function tinymcePreviewSetContent()
@@ -299,15 +221,12 @@ $href = str_replace("/system/Messages/write", "/system/Messages/send", $_SERVER[
function parseMessageText(receiver_id, text)
{
<?php
//replacing url (can have sender id at end)
$url = preg_replace("/\/system\/Messages\/write(\/.*)?/", "/system/Messages/parseMessageText", $_SERVER["REQUEST_URI"]);
$idtype = $personOnly === true ? 'person_id' : 'prestudent_id';
?>
$.ajax({
dataType: "json",
url: "<?php echo $url; ?>",
url: CONTROLLER_URL+"/parseMessageText",
data: {"<?php echo $idtype ?>": receiver_id, "text": text},
success: function (data, textStatus, jqXHR)
{
@@ -0,0 +1,91 @@
<?php
$this->load->view(
'templates/FHC-Header',
array(
'title' => 'MessageReply',
'jquery' => true,
'bootstrap' => true,
'fontawesome' => true,
'tinymce' => true,
'sbadmintemplate' => true,
'customCSSs' => array('public/css/sbadmin2/admintemplate_contentonly.css', 'public/css/messageWrite.css'),
'customJSs' => array('public/js/bootstrapper.js')
)
);
?>
<body>
<?php
$href = site_url().'/ViewMessage/sendReply';
?>
<div id="wrapper">
<div id="page-wrapper">
<div class="container-fluid">
<div class="row">
<div class="col-lg-12">
<h3 class="page-header">Send Message</h3>
</div>
</div>
<form id="sendForm" method="post" action="<?php echo $href; ?>">
<?php $this->load->view('system/messageForm.php'); ?>
<?php
for ($i = 0; $i < count($receivers); $i++)
{
$receiver = $receivers[$i];
$receiverid = $receiver->person_id;
$fieldname = 'persons[]';
echo '<input type="hidden" name="'.$fieldname.'" value="'.$receiverid.'">'."\n";
}
?>
<?php
if (isset($message))
{
?>
<input type="hidden" name="relationmessage_id" value="<?php echo $message->message_id; ?>">
<?php
}
if (isset($token))
{
?>
<input type="hidden" name="token" value="<?php echo $token; ?>">
<?php
}
?>
</form>
</div>
</div>
</div>
<script>
tinymce.init({
selector: "#bodyTextArea",
plugins: "autoresize",
autoresize_min_height: 150,
autoresize_max_height: 600,
autoresize_bottom_margin: 10,
auto_focus: "bodyTextArea"
});
$(document).ready(function ()
{
if ($("#sendButton") && $("#sendForm"))
{
$("#sendButton").click(function ()
{
if ($("#subject") && $("#subject").val() != '' && tinyMCE.get("bodyTextArea").getContent() != '')
{
$("#sendForm").submit();
}
else
{
alert("Subject and text are required fields!");
}
});
}
});
</script>
</body>
<?php $this->load->view("templates/FHC-Footer"); ?>
+10
View File
@@ -0,0 +1,10 @@
/*smaller subject field*/
input[type=text] {
height: 28px;
padding: 0px;
}
.msgfield label {
margin-bottom: 0px !important;
margin-top: 3px;
}