1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
<?php
/**
***********************************************************************************************
* @copyright 2004-2016 The Admidio Team
* @see http://www.admidio.org/
* @license https://www.gnu.org/licenses/gpl-2.0.html GNU General Public License v2.0 only
***********************************************************************************************
*/
/**
* @class modulemessages
* @brief some functions for the messages module
*
* This class adds some functions that are used in the messages module to keep the
* code easy to read and short
*
* @par Examples
* @code // check the given Array for charecter and split it.
* $gMessage->show($gL10n->get('SYS_MESSAGE_TEXT_ID'));
*
* // show a message and set a link to a page that should be shown after user click ok
* $gMessage->setForwardUrl('http://www.example.de/mypage.php');
* $gMessage->show($gL10n->get('SYS_MESSAGE_TEXT_ID'));
*
* // show a message with yes and no button and set a link to a page that should be shown after user click yes
* $gMessage->setForwardYesNo('http://www.example.de/mypage.php');
* $gMessage->show($gL10n->get('SYS_MESSAGE_TEXT_ID')); @endcode
*/
class ModuleMessages
{
/**
* Constructor that initialize the class member parameters
*/
public function __construct()
{
}
/**
* Check for roles and give back a string with rolename. If former members or activa and former
* members were selected than an additional string will be shown after the rolename.
* @param string $roleIdsString A string with several role ids.
* @return string Returns the rolename and the status if former members were selected.
*/
public function msgGroupNameSplit($roleIdsString)
{
global $gCurrentOrganization, $gL10n, $gDb;
$group = $this->msgGroupSplit($roleIdsString);
$sql = 'SELECT rol_name
FROM '.TBL_ROLES.'
INNER JOIN '.TBL_CATEGORIES.'
ON cat_id = rol_cat_id
WHERE rol_id = '.$group[0].'
AND ( cat_org_id = '. $gCurrentOrganization->getValue('org_id').'
OR cat_org_id IS NULL)';
$statement = $gDb->query($sql);
$roleName = $statement->fetchColumn();
if($group[1] == 1)
{
// only former members
$receiverNameLong = $roleName . ' (' .$gL10n->get('LST_FORMER_MEMBERS') . ')';
}
elseif($group[1] == 2)
{
// former members and active members
$receiverNameLong = $roleName . ' (' . $gL10n->get('LST_ACTIVE_FORMER_MEMBERS') . ')';
}
else
{
// only active members then only show rolename and not the status
$receiverNameLong = $roleName;
//$receiverNameLong = $roleName . ' (' .$gL10n->get('LST_ACTIVE_MEMBERS') . ')';
}
return $receiverNameLong;
}
/**
* check for Group and give back a array with group ID[0] and if it is active, inactive or both [1].
* @param string $groupString
* @return array
*/
public function msgGroupSplit($groupString)
{
$groupSplit = explode(':', $groupString);
if (strpos($groupSplit[1], '-') > 0)
{
$group = explode('-', $groupSplit[1]);
}
else
{
$group = array();
$group[] = $groupSplit[1];
$group[] = 0;
}
return $group;
}
/**
* return an array with all Email-Messages of the given user.
* @param int $userId
* @return \PDOStatement
*/
public function msgGetUserEmails($userId)
{
global $gDb;
$sql = 'SELECT msg_id, msg_usr_id_receiver AS user
FROM '. TBL_MESSAGES. '
WHERE msg_type = \'EMAIL\' AND msg_usr_id_sender = '. $userId .'
ORDER BY msg_id DESC';
return $gDb->query($sql);
}
/**
* return an array with all unread Messages of the given user.
* @param int $userId
* @return \PDOStatement
*/
public function msgGetUserUnread($userId)
{
global $gDb;
$sql = 'SELECT msg_id, msg_usr_id_sender, msg_usr_id_receiver
FROM '. TBL_MESSAGES. '
WHERE msg_type = \'PM\'
AND msg_usr_id_receiver LIKE \''. $userId .'\' AND msg_read = 1
ORDER BY msg_id DESC';
return $gDb->query($sql);
}
/**
* return an array with all unread Messages of the given user.
* @param int $userId
* @return \PDOStatement
*/
public function msgGetUser($userId)
{
global $gDb;
$sql = 'SELECT msg_id, msg_usr_id_sender, msg_usr_id_receiver
FROM '. TBL_MESSAGES. '
WHERE msg_type = \'PM\'
AND ( (msg_usr_id_receiver LIKE \''. $userId .'\' AND msg_read <> 1)
OR (msg_usr_id_sender = '. $userId .' AND msg_read < 2))
ORDER BY msg_id DESC';
return $gDb->query($sql);
}
/**
* return the message ID of the admidio chat.
* @return int
*/
public function msgGetChatId()
{
global $gDb;
$sql = 'SELECT msg_id
FROM '. TBL_MESSAGES. '
WHERE msg_type = \'CHAT\'';
$statement = $gDb->query($sql);
$msgId = $statement->fetchColumn();
return (int) $msgId;
}
}