Elxis CMS Forum

Support => General => Topic started by: perseas on June 21, 2020, 22:55:40

Title: Users will be able to send messages only to administrators
Post by: perseas on June 21, 2020, 22:55:40
With Elxis 5.1 , is it possible not to allow communication between users?

I found the following answer for Elxis 4.5 and i test it on Elxis 5.1 but it didn't work.

https://forum.elxis.org/index.php?topic=8675.msg55964#msg55964 (https://forum.elxis.org/index.php?topic=8675.msg55964#msg55964)

Do you have anything to suggest?
Title: Re: Users will be able to send messages only to administrators
Post by: perseas on June 29, 2020, 23:33:27
hi forum
The reason I ask for your help is the following.
Recently, a registered member of my website started sending unwanted messages (spam) to all other registered members through the personal messaging tool, resulting in complaints as well as suspicion and fear of violating the members' account.
Of course this member was deleted but the problem could be repeated in the future by another member.
That's why I decided to set up sending personal messages from registered members only to administrators and administrators to all registered members.
I chose the above solution given in the forum for elxis 4.5. and I applied it as follows:
In the file:
components/com_user/models/user.model.php
I changed the code of the following function:

Code: [Select]
/*****************/
/* GET ALL USERS */
/*****************/
public function getAllUsers($except_uid=0) {
$except_uid = (int)$except_uid;
/*******Users will be able to send messages only to administrators, administrators to all. *******/
/*$sql = "SELECT ".$this->db->quoteId('uid').", ".$this->db->quoteId('firstname').", ".$this->db->quoteId('lastname').", ".$this->db->quoteId('uname').", ".$this->db->quoteId('email')*/
$sql = "SELECT ".$this->db->quoteId('uid').", ".$this->db->quoteId('gid').", ".$this->db->quoteId('firstname').", ".$this->db->quoteId('lastname').", ".$this->db->quoteId('uname').", ".$this->db->quoteId('email')
."\n FROM ".$this->db->quoteId('#__users')
."\n WHERE ".$this->db->quoteId('block')." = 0";
if ($except_uid > 0) {
$sql .= " AND ".$this->db->quoteId('uid')." <> ".$except_uid;
}
$sql .= "\n ORDER BY ".$this->db->quoteId('firstname')." ASC";
$stmt = $this->db->prepare($sql);
$stmt->execute();
$rows = $stmt->fetchAllAssoc('uid', PDO::FETCH_OBJ);
/*******Users will be able to send messages only to administrators, administrators to all. *******/
if (!$rows) { return array(); }
$mygid = eFactory::getElxis()->user()->gid;
if ($mygid == 1) { return $rows; }
$newrows = array();
foreach ($rows as $uid => $row) {
if ($row->gid == 1) { $newrows[$uid] = $row; }
}
return $newrows;
}

}

The problem was not solved definitively since the registered member when sending a personal message saw in the list all the names of the other registered members.
With the above function, if a name is selected that is not an administrator to send a personal message then it displays the message that it was not found.
I proceeded to the next step for not appearing in the mailing list of all members but only the administrators as described in the forum:
https://forum.elxis.org/index.php?topic=8675.msg55992#msg55992 (https://forum.elxis.org/index.php?topic=8675.msg55992#msg55992)
in the file:
components / com_user / views / members.html.php
but the file in Elxis 5.1 ended up with a different code and the solution cannot be applied.

I believe that in the next version of Elxis  there should be a configuration for this issue.
Title: Re: Users will be able to send messages only to administrators
Post by: webgift on August 05, 2020, 16:30:53
A new extension with name mod_sidebar will be released soon to Elxis
community. Special thanks to @perseas for his support.
Title: Re: Users will be able to send messages only to administrators
Post by: perseas on August 06, 2020, 15:37:28
@webgift thank you. You did a good job. Problem solved.
Title: Re: Users will be able to send messages only to administrators
Post by: webgift on August 06, 2020, 20:57:36
You're always welcome @Perseas!