1
mouacy
Admin's right to delete unread PM of inactive members
  • 2004/10/29 7:03

  • mouacy

  • Not too shy to talk

  • Posts: 138

  • Since: 2002/11/2


I have over 1600 members and half of them are not frequent visitors but their inbox is filling up with notifications and PMs. I manually did the clean up by going to the database and query to delete their PMs. It's very time consuming and painful.

I would like to see an Admin option in the Admin Control Panel to delete PMs and Notifications that are not read over a certain time period.

Can XOOPS implement this into the Admin panel?

2
jctsup1
Re: Admin's right to delete unread PM of inactive members
  • 2004/10/29 8:21

  • jctsup1

  • Not too shy to talk

  • Posts: 146

  • Since: 2002/5/23


This is a very good idea & I would like to see this feature as well.

3
indream
Re:Admin's right to delete unread PM of inactive members
  • 2004/10/29 12:59

  • indream

  • Not too shy to talk

  • Posts: 170

  • Since: 2004/9/21


nice idea i have 4000 member and this a problem for database

4
Shine
Re:Admin's right to delete unread PM of inactive members
  • 2004/10/29 15:55

  • Shine

  • Just can't stay away

  • Posts: 822

  • Since: 2002/7/22


As a matter of fact for over a year ago I've already asked to apply an admin feature considering the Pm's. I would love to see an admin setting: Maximum Pm's per user:...
I am still surprised that the notification option is standard by PM. Why not by Email?
By giving a max. for Pm's you can keep automatic control of the Mb space that users use. As soon as the memberuser inbox is full he/she needs to clean it up themselve, otherwise he/she won't receive any Pm's anymore. It is like regular cleaning up your postinbox, otherwise the postman cannot deliver his post to you anymore.
The extra feature of cleaning up none readed Pm's (after a certain time) would also be nice.

Grtz., Shine

5
irmtfan
Re: Admin's right to delete unread PM of inactive members
  • 2004/10/29 16:17

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


in my site some users dont check the inbox for ages and the pms reach to 1000 or higher.
so this is a big problem in the site and i write ( with very help from others ) a php script to delete old unread pms . and that's it :

define("user""user_db");  // write user of your database here
define("pass""password"); // write password here
define("host""localhost"); // change it if your localhost is different
define("db""database_name"); //write name of your database here


$cxn mysql_connect(host ,userpass);
mysql_select_db(db);

$delete_time time() - ( 30 24 60 60 );  // 30 days/month * 24 hrs/day
// * 60 minutes/hour * 60 seconds/min.

$sql "DELETE from `xoops_priv_msgs` WHERE `read_msg` = '0' AND `msg_time` < '$delete_time'";
//This script would delete everything older than 30 days that has been not read.
//note: if your perfix is different plz notice that change the 'xoops' with your perfix at 'xoops_priv_msgs' table
$result mysql_query($sql$cxn);
?>

put this script in a php file for example delete_pm.php and save it then upload it everywhere u want and run it every time u want.
even u can put this at a chron job and run it every day automatically ( recommended)
you can change the delete time to your favorite.
plz get me some feedback about this and some help to put other fields to script.
for example i want choose a part of "pm subject" so every pm has that part delete and others left. how can do it?
regards

6
mouacy
Re: Admin's right to delete unread PM of inactive members
  • 2004/10/29 20:15

  • mouacy

  • Not too shy to talk

  • Posts: 138

  • Since: 2002/11/2


Quote:

irmtfan wrote:
in my site some users dont check the inbox for ages and the pms reach to 1000 or higher.
so this is a big problem in the site and i write ( with very help from others ) a php script to delete old unread pms . and that's it :

define("user""user_db");  // write user of your database here
define("pass""password"); // write password here
define("host""localhost"); // change it if your localhost is different
define("db""database_name"); //write name of your database here


$cxn mysql_connect(host ,userpass);
mysql_select_db(db);

$delete_time time() - ( 30 24 60 60 );  // 30 days/month * 24 hrs/day
// * 60 minutes/hour * 60 seconds/min.

$sql "DELETE from `xoops_priv_msgs` WHERE `read_msg` = '0' AND `msg_time` < '$delete_time'";
//This script would delete everything older than 30 days that has been not read.
//note: if your perfix is different plz notice that change the 'xoops' with your perfix at 'xoops_priv_msgs' table
$result mysql_query($sql$cxn);
?>


Good start. It doesn't seem to work for me... but thank you and I will do some more work on it. I hope it get it to work.

Anyway, how does XOOPs encode the msg_time? I cannot interpret the numbers. Can anyone tell me what they represent.

7
ackbarr
Re:Admin's right to delete unread PM of inactive members

its not encoded, but stored in the unix_timestamp format, which is defined as the number of seconds since Jan 1, 1970, 12:00a

MySQL has several functions that can work with a date entered in Julian calendar format to convert it into the unix time format (see unix_timestamp)

8
mouacy
Re:Admin's right to delete unread PM of inactive members
  • 2004/10/29 21:53

  • mouacy

  • Not too shy to talk

  • Posts: 138

  • Since: 2002/11/2


This is what I did to modify irmtfan's script to use the main configuration of XOOPS. It works to some extend because of my poor php knowledge.

1. I need to display the Admin name to be sure that the user has the proper permission to delete old PMs.

2. I would like to have a dropdown box to select number of days to delete such as 5, 10, 15, 30, 60 etc...

3. I would like to see a result of how many messages were deleted.

4. I DO NOT KNOW how to implement all of the above features. If anyone can help, please share your script.

5. THIS SCRIPT HAS NO WARRANTY.

Quote:


include "mainfile.php";
include "header.php";

/*
define("XOOPS_DB_USER", "username"); // write user of your database here
define("XOOPS_DB_PASS", "password"); // write password here
define("XOOPS_DB_HOST", "localhost"); // change it if your localhost is different
define("XOOPS_DB_NAME", "xoops"); //write name of your database here

$cxn = mysql_connect(XOOPS_DB_HOST , XOOPS_DB_USER, XOOPS_DB_PASS);
mysql_select_db(XOOPS_DB_NAME);
*/

if ($xoopsUserIsAdmin){

$delete_day = "30"; //Plan to use a drop-box to select day: 5, 10, 15, 30, 60, 90 etc...

echo "
Delete Days: $delete_day";
//$delete_time = time() - ( 30 * 24 * 60 * 60 ); // 30 days/month * 24 hrs/day
// * 60 minutes/hour * 60 seconds/min.
$delete_time = time() - ( ("$delete_day") * 24 * 60 * 60 );

echo "
Delete time is: $delete_time"; //Show delete time
echo "
The admin is: $xoopsUserIsAdmin"; //Show admin ID

$sql = "DELETE FROM `xoops_priv_msgs` WHERE `read_msg` = '0' AND `msg_time` < '$delete_time'";
//This script would delete everything older than 30 days that has been not read.
//note: if your perfix is different plz notice that change the 'xoops' with your perfix at 'xoops_priv_msgs' table
//$result = mysql_query($sql, $cxn);

echo "
Old Unread Private Messages Deleted: $delete_count"; //Need to count, but don't know how yet.
}else{
redirect_header("index.php",0);
exit();
}

include "footer.php";
?>

9
mouacy
Re: Admin's right to delete unread PM of inactive members
  • 2004/10/30 4:03

  • mouacy

  • Not too shy to talk

  • Posts: 138

  • Since: 2002/11/2


OK. Guys! Finally I got this baby working. I have test it and it works for me.... I'm not a PHP guy, so if you guys find any thing that needs change, please feel free to edit and post me a copy too.

To use the feature, you will have to uncomment the line that has //sql... NO warranty! Do not use in production site.

//=======================================================================//
//Author: Chao Moua
//Date: October 29, 2004
//Version: 1.0 beta
//CMS Version: XOOPS 2.0.X
//Description: This script will give admin the option to delete select messages that are X days old excluding admin's inbox messages.
//=======================================================================//

//$xoopsOption['pagetype'] = "admin";
include "mainfile.php";
include 
"header.php";

//Security check for Admin only
if ($xoopsUserIsAdmin)
{
    
$user_name $xoopsUser->getVar("uname");        //Get Admin username

    
if (isset($_POST['delete']))     
    {
        
$delete_time time() - ( ($delete_day) * 24 60 60 );        
        
//Credit for the delete_time formula goes to irmtfan at https://xoops.org
        
$delete_status $msg_status;

        if ( 
$msg_status == 'unread' ) {
            
$msg_status '0';
        }
        elseif (
$msg_status == 'read' ) {
            
$msg_status '1';
        }
        elseif (
$msg_status == 'all') {
            
$delete_status 'read and unread';
        }

        if ( empty(
$delete_day) && $msg_status == 'all' )    {
        
//$sql = "DELETE FROM `xoops_priv_msgs` WHERE `msg_time` < '$delete_time' AND `to_userid` != '1";
        
echo "All $delete_status Private Messages have been Deleted."
;
        }
        elseif ( empty(
$delete_day) && $msg_status != 'all' ) {
        
//$sql = "DELETE FROM `xoops_priv_msgs` WHERE `read_msg` = '$msg_status' AND `msg_time` < '$delete_time' AND `to_userid` != '1";
        
echo "All $delete_status Private Messages have been Deleted.";
        }
        elseif ( 
$delete_day >= '1' && $msg_status == 'all' ) {
        
//$sql = "DELETE FROM `xoops_priv_msgs` WHERE `msg_time` < '$delete_time' AND `to_userid` != '1";
        
echo "All $delete_status $delete_day  days old Private Messages have been Deleted.";
        }
        else {
        
//$sql = "DELETE FROM `xoops_priv_msgs` WHERE `read_msg` = '$msg_status' AND `msg_time` < '$delete_time' AND `to_userid` != '1";
        
echo "All $delete_status $delete_day  days old Private Messages have been Deleted.";
        }
    }
    else {
        
//Admin form to delete private messages
        
echo "Welcome, $user_name.";
        echo 
"Warning: You are about to delete private messages that are X days old. ";
        echo 
"Deleted messages cannot be recovered. Please make a backup of your database. "
        echo 
"IF YOU ENTER NOTHING, ALL SELECT UP-TO-DATE MESSAGES will be deleted!";
        echo 
"multipart/form-data" method="post" action="deletepm.php">";
        echo 
"Delete ";
        echo 
"1" name="msg_status" value="$msg_status">";
        echo 
" private messages that are ";
        echo 
"text" name="delete_day" value="$delete_day" size="3"> days old.";
        echo 
"submit" name="delete" value="delete" />";
        echo 
"";
    }
}    else {
    
redirect_header("index.php",0_NOPERM);
    exit();
}
//navigation
echo "Output msg_status: $msg_status"
;
echo 
"Output delete_status: $delete_status"
;
echo 
"Your admin ID is: $xoopsUserIsAdmin : $user_name "//Show admin ID
echo "";
echo 
">>>deletepm.php">Delete more messages";

//author Chao Moua
echo "";
echo 
"";
echo 
"Script written by Chao Moua 10-29-2004";

//include footer.php
include "footer.php";
?>

10
Dave_L
Re:Admin's right to delete unread PM of inactive members
  • 2004/10/30 5:27

  • Dave_L

  • XOOPS is my life!

  • Posts: 2277

  • Since: 2003/11/7


I didn't check everything, but I noticed a couple of items:

1) $xoopsUserIsAdmin - I think that indicates whether the current user is the admin of any module. I could be wrong. But you probably want to ensure that the current user has system module admin rights. I don't recall offhand how to check for that.

2)
"DELETE FROM `xoops_priv_msgs` WHERE `msg_time` < '$delete_time' AND `to_userid` != '1";


should be

"DELETE FROM xoops_priv_msgs WHERE msg_time < '$delete_time' AND to_userid != '1'";


I took out the unneeded backquotes, and added a missing quote at the end. The other queries need similar changes.

Login

Who's Online

382 user(s) are online (251 user(s) are browsing Support Forums)


Members: 0


Guests: 382


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits