mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-20 00:12:15 +00:00
Merge branch 'feature-7434/Messages_Neue_Felder_zu_eingeloggtem_User_ergaenzen'
This commit is contained in:
@@ -215,6 +215,31 @@ class MessageLib
|
||||
|
||||
return $messageVars; // otherwise returns the error
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves message vars of the logged in user from view vw_msg_vars_user
|
||||
*/
|
||||
public function getMessageVarsLoggedInUser()
|
||||
{
|
||||
// Retrieves message vars from view vw_msg_vars
|
||||
$messageVars = $this->_ci->MessageModel->getMsgVarsLoggedInUser();
|
||||
if (isSuccess($messageVars)) // if everything is ok
|
||||
{
|
||||
$variablesArray = array();
|
||||
$tmpVariablesArray = getData($messageVars);
|
||||
|
||||
// Starts from 1 to skip the first element which is uid
|
||||
for ($i = 1; $i < count($tmpVariablesArray); $i++)
|
||||
{
|
||||
$variablesArray['{'.str_replace(' ', '_', strtolower($tmpVariablesArray[$i])).'}']
|
||||
= strtoupper($tmpVariablesArray[$i]);
|
||||
}
|
||||
|
||||
return success($variablesArray);
|
||||
}
|
||||
|
||||
return $messageVars; // otherwise returns the error
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves organisation units for each role that a user plays inside that organisation unit
|
||||
|
||||
@@ -48,6 +48,9 @@ class Messages_model extends CI_Model
|
||||
$this->load->model('system/Benutzerrolle_model', 'BenutzerrolleModel');
|
||||
// Loads model Prestudent_model
|
||||
$this->load->model('crm/Prestudent_model', 'PrestudentModel');
|
||||
// Loads model Benutzer_model
|
||||
$this->load->model('person/Benutzer_model', 'BenutzerModel');
|
||||
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
@@ -402,7 +405,10 @@ class Messages_model extends CI_Model
|
||||
// Looping on receivers data
|
||||
foreach (getData($msgVarsData) as $receiver)
|
||||
{
|
||||
$msgVarsDataArray = $this->_lowerReplaceSpaceArrayKeys((array)$receiver); // replaces array keys
|
||||
// Merge receivers data with logged in user data
|
||||
$msgVarsDataArray = $this->_addMsgVarsDataOfLoggedInUser($receiver);
|
||||
|
||||
$msgVarsDataArray = $this->_lowerReplaceSpaceArrayKeys((array)getData($msgVarsDataArray)[0]); // replaces array keys
|
||||
$parsedSubject = parseText($subject, $msgVarsDataArray);
|
||||
$parsedBody = parseText($body, $msgVarsDataArray);
|
||||
|
||||
@@ -466,6 +472,15 @@ 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)))
|
||||
{
|
||||
show_error('No sender_uid found');
|
||||
}
|
||||
$sender_uid = $result[0]->uid;
|
||||
|
||||
// Adds the organisation unit to each prestudent
|
||||
if (isEmptyString($oe_kurzbz) && hasData($msgVarsData) && hasData($prestudentsData))
|
||||
@@ -475,7 +490,15 @@ class Messages_model extends CI_Model
|
||||
|
||||
foreach (getData($msgVarsData) as $receiver)
|
||||
{
|
||||
$msgVarsDataArray = $this->_lowerReplaceSpaceArrayKeys((array)$receiver); // replaces array keys
|
||||
/**
|
||||
* Merge receivers data with senders data
|
||||
* NOTE: _addMsgVarsDataOfLoggedInUser usually retrieves data of the logged in user that is set in the
|
||||
* templates user fields. As sendExplicitTemplateSenderId is run by a job, a sender uid is passed to be used
|
||||
* instead the logged in user.
|
||||
*/
|
||||
$msgVarsDataArray = $this->_addMsgVarsDataOfLoggedInUser($receiver, $sender_uid);
|
||||
|
||||
$msgVarsDataArray = $this->_lowerReplaceSpaceArrayKeys((array)getData($msgVarsDataArray)[0]); // replaces array keys
|
||||
|
||||
// Additional message variables
|
||||
if (is_array($msgVars)) $msgVarsDataArray = array_merge($msgVarsDataArray, $msgVars);
|
||||
@@ -606,6 +629,9 @@ class Messages_model extends CI_Model
|
||||
$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);
|
||||
|
||||
if (hasData($parseMessageText))
|
||||
{
|
||||
@@ -629,7 +655,10 @@ class Messages_model extends CI_Model
|
||||
$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);
|
||||
|
||||
if (hasData($parseMessageText))
|
||||
{
|
||||
$parseMessageText = success(
|
||||
@@ -839,6 +868,26 @@ class Messages_model extends CI_Model
|
||||
|
||||
$variables[] = $tmpVar;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------
|
||||
// Retrieves message vars of logged in user from database view vw_msg_vars_person
|
||||
$result = null;
|
||||
|
||||
// If data contains a prestudent id
|
||||
$result = $this->messagelib->getMessageVarsLoggedInUser();
|
||||
|
||||
if (isError($result)) show_error(getError($result));
|
||||
|
||||
// Then builds an array that contains objects with field name and field description of logged in user data
|
||||
$user_fields = array();
|
||||
foreach (getData($result) as $id => $description)
|
||||
{
|
||||
$obj = new stdClass();
|
||||
$obj->id = $id;
|
||||
$obj->description = $description;
|
||||
|
||||
$user_fields[] = $obj;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------
|
||||
// Retrieves the sender id
|
||||
@@ -859,6 +908,7 @@ class Messages_model extends CI_Model
|
||||
'subject' => $replySubject,
|
||||
'body' => $replyBody,
|
||||
'variables' => $variables,
|
||||
'user_fields' => $user_fields,
|
||||
'organisationUnits' => getData($organisationUnits),
|
||||
'senderIsAdmin' => getData($senderIsAdmin),
|
||||
'recipientsArray' => $recipientsArray,
|
||||
@@ -867,4 +917,30 @@ class Messages_model extends CI_Model
|
||||
'type' => $type
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds message vars data of the logged in user to the given object (that should also have message vars data)
|
||||
* @param object $otherMsgVarsDataObj Can be success object or simple object.
|
||||
* @return object Returns success object.
|
||||
*/
|
||||
public function _addMsgVarsDataOfLoggedInUser($otherMsgVarsDataObj, $uid = null)
|
||||
{
|
||||
// First check if param type is object
|
||||
if (!is_object($otherMsgVarsDataObj)) show_error('Must pass an object to merge with data of logged in user');
|
||||
|
||||
// If it is a return object, extract the simple data object
|
||||
if (isSuccess($otherMsgVarsDataObj))
|
||||
{
|
||||
$otherMsgVarsDataObj = getData($otherMsgVarsDataObj)[0];
|
||||
}
|
||||
|
||||
// Retrieve message vars data of the logged in user
|
||||
if (!$msgVarsDataLoggedInUser = getData($this->MessageModel->getMsgVarsDataByLoggedInUser($uid))[0])
|
||||
{
|
||||
return success($otherMsgVarsDataObj); // If failed, return at least given object as expected success object
|
||||
}
|
||||
|
||||
return success(array((object)(array_merge((array) $otherMsgVarsDataObj, (array) $msgVarsDataLoggedInUser))));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,6 +171,23 @@ class Message_model extends DB_Model
|
||||
return error($this->db->error(), FHC_DB_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get message variables for logged in user
|
||||
*/
|
||||
public function getMsgVarsLoggedInUser()
|
||||
{
|
||||
$result = $this->db->query('SELECT * FROM public.vw_msg_vars_user WHERE 0 = 1');
|
||||
|
||||
if ($result)
|
||||
{
|
||||
return success($result->list_fields());
|
||||
}
|
||||
else
|
||||
{
|
||||
return error($this->db->error(), FHC_DB_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* getMsgVarsDataByPrestudentId
|
||||
@@ -191,4 +208,26 @@ class Message_model extends DB_Model
|
||||
|
||||
return $this->execQuery(sprintf($query, is_array($person_id) ? 'IN' : '='), array($person_id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get message vars data for logged in user
|
||||
* @param string uid The UID should ONLY be passed if this method is called by a cronjob.
|
||||
* This is to enable jobs to use templates which use logged-in-user fields ('Eigene Felder').
|
||||
* @return array|null
|
||||
*/
|
||||
public function getMsgVarsDataByLoggedInUser($uid = null)
|
||||
{
|
||||
if (is_string($uid))
|
||||
{
|
||||
$params = array($uid);
|
||||
}
|
||||
else
|
||||
{
|
||||
$params = array(getAuthUID());
|
||||
}
|
||||
|
||||
$query = 'SELECT * FROM public.vw_msg_vars_user WHERE my_uid = ?';
|
||||
|
||||
return $this->execQuery($query, $params);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,19 +83,41 @@
|
||||
</label>
|
||||
|
||||
<?php
|
||||
$size = count($variables) > 19 ? 19 : count($variables);
|
||||
echo $this->widgetlib->widget(
|
||||
'MultipleDropdown_widget',
|
||||
array('elements' => success($variables)),
|
||||
array(
|
||||
'name' => 'variables[]',
|
||||
'id' => 'variables',
|
||||
'size' => count($variables),
|
||||
'size' => $size,
|
||||
'multiple' => true
|
||||
)
|
||||
);
|
||||
?>
|
||||
|
||||
</div>
|
||||
<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(
|
||||
'MultipleDropdown_widget',
|
||||
array('elements' => success($user_fields)),
|
||||
array(
|
||||
'name' => 'user_fields[]',
|
||||
'id' => 'user_fields',
|
||||
'size' => $size,
|
||||
'multiple' => true
|
||||
)
|
||||
);
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<br>
|
||||
@@ -111,14 +133,15 @@
|
||||
?>
|
||||
|
||||
</div>
|
||||
<div class="col-lg-7 col-xs-9 text-right">
|
||||
<button id="sendButton" class="btn btn-default" type="button">
|
||||
<div class="col-xs-6">
|
||||
<button id="sendButton" class="btn btn-default pull-right" type="button">
|
||||
|
||||
<?php echo $this->p->t('ui', 'senden'); ?>
|
||||
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<br>
|
||||
<hr>
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
|
||||
@@ -46,7 +46,12 @@ $(document).ready(function ()
|
||||
{
|
||||
tinymce.init({
|
||||
selector: "#bodyTextArea",
|
||||
plugins: "autoresize"
|
||||
plugins: "autoresize",
|
||||
autoresize_on_init: false,
|
||||
autoresize_min_height: 400,
|
||||
autoresize_max_height: 400,
|
||||
autoresize_bottom_margin: 10,
|
||||
auto_focus: "bodyTextArea"
|
||||
});
|
||||
|
||||
tinymce.init({
|
||||
@@ -73,6 +78,21 @@ $(document).ready(function ()
|
||||
});
|
||||
}
|
||||
|
||||
if ($("#user_fields"))
|
||||
{
|
||||
$("#user_fields").dblclick(function ()
|
||||
{
|
||||
if ($("#bodyTextArea"))
|
||||
{
|
||||
//if editor active add at cursor position, otherwise at end
|
||||
if (tinymce.activeEditor.id === "bodyTextArea")
|
||||
tinymce.activeEditor.execCommand('mceInsertContent', false, $(this).children(":selected").val());
|
||||
else
|
||||
tinyMCE.get("bodyTextArea").setContent(tinyMCE.get("bodyTextArea").getContent() + $(this).children(":selected").val());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if ($("#recipients"))
|
||||
{
|
||||
$("#recipients").change(tinymcePreviewSetContent);
|
||||
|
||||
@@ -196,6 +196,43 @@ if(!$result = @$db->db_query("SELECT 1 FROM public.vw_msg_vars_person LIMIT 1"))
|
||||
echo '<br>Granted privileges to <strong>vilesci</strong> on public.vw_msg_vars_person';
|
||||
}
|
||||
|
||||
// CREATE OR REPLACE VIEW public.vw_msg_vars_user and grants privileges
|
||||
if(!$result = @$db->db_query("SELECT 1 FROM public.vw_msg_vars_user LIMIT 1"))
|
||||
{
|
||||
$qry = '
|
||||
CREATE OR REPLACE VIEW public.vw_msg_vars_user AS (
|
||||
SELECT DISTINCT ON
|
||||
(b.uid) b.uid AS "my_uid",
|
||||
p.vorname AS "my_vorname",
|
||||
p.nachname AS "my_nachname",
|
||||
COALESCE(b.alias, b.uid) AS "my_alias",
|
||||
ma.telefonklappe AS "my_durchwahl"
|
||||
FROM public.tbl_person p
|
||||
JOIN public.tbl_benutzer b USING (person_id)
|
||||
JOIN public.tbl_mitarbeiter ma ON ma.mitarbeiter_uid = b.uid
|
||||
WHERE ma.personalnummer > 0
|
||||
);';
|
||||
|
||||
if(!$db->db_query($qry))
|
||||
echo '<strong>public.vw_msg_vars_user: '.$db->db_last_error().'</strong><br>';
|
||||
else
|
||||
echo '<br>public.vw_msg_vars_user view created';
|
||||
|
||||
$qry = 'GRANT SELECT ON TABLE public.vw_msg_vars_user TO web;';
|
||||
|
||||
if(!$db->db_query($qry))
|
||||
echo '<strong>public.vw_msg_vars_user: '.$db->db_last_error().'</strong><br>';
|
||||
else
|
||||
echo '<br>Granted privileges to <strong>web</strong> on public.vw_msg_vars_user';
|
||||
|
||||
$qry = 'GRANT SELECT ON TABLE public.vw_msg_vars_user TO vilesci;';
|
||||
|
||||
if(!$db->db_query($qry))
|
||||
echo '<strong>public.vw_msg_vars_user: '.$db->db_last_error().'</strong><br>';
|
||||
else
|
||||
echo '<br>Granted privileges to <strong>vilesci</strong> on public.vw_msg_vars_user';
|
||||
}
|
||||
|
||||
//Spalte anmerkung und rechnungsadresse in tbl_adresse
|
||||
if(!$result = @$db->db_query("SELECT rechnungsadresse FROM public.tbl_adresse LIMIT 1"))
|
||||
{
|
||||
|
||||
@@ -7949,6 +7949,26 @@ Any unusual occurrences
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
'app' => 'core',
|
||||
'category' => 'ui',
|
||||
'phrase' => 'meineFelder',
|
||||
'insertvon' => 'system',
|
||||
'phrases' => array(
|
||||
array(
|
||||
'sprache' => 'German',
|
||||
'text' => 'Meine Felder',
|
||||
'description' => '',
|
||||
'insertvon' => 'system'
|
||||
),
|
||||
array(
|
||||
'sprache' => 'English',
|
||||
'text' => 'My fields',
|
||||
'description' => '',
|
||||
'insertvon' => 'system'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
'app' => 'core',
|
||||
'category' => 'ui',
|
||||
|
||||
Reference in New Issue
Block a user