Subject:*
<
Name/Email:*
<
Message Icon:*
<
Select*
<
Message:*
<



Click the Preview to see the content in action.
Options:*
<
Confirmation Code*
<
8 - 4 = ?  
Input the result from the expression
Maximum attempts you can try: 10
*
<
     

Re: Admin's right to delete unread PM of inactive members
by mouacy on 2004/11/1 5:14:25

OK. Here is the truly working version of this script. It's been tested extensively and it worked fine. I hope you guys have some luck with it.

1. user_id is hardcoded as '1' (my lack of XOOPS knowledge)
2. $xoopsUserIsAdmin is still a question
3. And more work to be done.

Installation: just save the code as deletepm.php file place it in your XOOPS home directory. You can call the file using http://www.yoursite.com/deletepm.php

Anything else, please feel free to add and share with me.

<?php //======================================================// //Author: Chao Moua //Date: October 29, 2004 //Version: 1.0.1 //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"; //Check for xoopsUser if (empty($xoopsModuleConfig['anonpost']) && !is_object($xoopsUser)) { redirect_header("index.php", 0, _NOPERM); exit(); } else{ $user_id = $xoopsUser->getVar("uid"); //Get Admin user_id $user_name = $xoopsUser->getVar("uname"); //Get Admin username } //Security check for Admin only if ($xoopsUserIsAdmin && $user_id == '1' ) { if (isset($_POST['delete'])) { $cxn = mysql_connect(XOOPS_DB_HOST , XOOPS_DB_USER, XOOPS_DB_PASS); mysql_select_db(db); $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; //Reassigning value to $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'; } //Condition to delete selected private messages if ( empty($delete_day) && $msg_status == 'all' ) { $sql = "DELETE FROM xoops_priv_msgs WHERE msg_time < '$delete_time' AND to_userid != 1"; $result = mysql_query($sql, $cxn); echo "<br />All <b>$delete_status</b> Private Messages have been Deleted.<br />"; } 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"; $result = mysql_query($sql, $cxn); echo "<br />All <b>$delete_status</b> Private Messages have been Deleted.<br />"; } elseif ( $delete_day >= '1' && $msg_status == 'all' ) { $sql = "DELETE FROM xoops_priv_msgs WHERE msg_time < '$delete_time' AND to_userid != 1"; $result = mysql_query($sql, $cxn); echo "<br />All <b>$delete_status $delete_day</b> days old Private Messages have been Deleted.<br />"; } else { $sql = "DELETE FROM xoops_priv_msgs WHERE read_msg = '$msg_status' AND msg_time < '$delete_time' AND to_userid != 1"; $result = mysql_query($sql, $cxn); echo "<br />All <b>$delete_status $delete_day</b> days old Private Messages have been Deleted.<br />"; } } else { //Admin form to delete private messages echo "Welcome, <b>$user_name</b>.<br /><br />"; echo "<b>Warning:</b> You are about to delete private messages that are X days old.<br /> "; echo "Deleted messages cannot be recovered. <br />"; echo "User ID 1 or Primary Admin's private messages will not be deleted. <br />"; echo "IF YOU ENTER NOTHING, ALL SELECT UP-TO-DATE MESSAGES will be deleted!<br />"; echo "<b>Use this script at your own risk.</b><br />"; echo "<form enctype="multipart/form-data" method="post" action="deletepm.php">"; echo "Delete "; echo "<select size="1" name="msg_status" value="$msg_status"><option>unread</option><option>read</option><option>all</option></select>"; echo "&nbsp;private messages that are "; echo "<input type="text" name="delete_day" value="30" size="3"> days old.&nbsp;&nbsp;"; echo "<input type="submit" name="delete" value="delete" />"; echo "</form>"; } } else { redirect_header("index.php",0, _NOPERM); exit(); } //Print information about the process echo "<br />"; echo "SQL Command: <b>$sql</b> <br />"; echo "SQL Result: <b>$result </b><br />"; echo "CXN: <b>$cxn</b> <br />"; echo "Affected rows: <b>"; print $xoopsDB->getAffectedRows(); echo "</b><br />"; echo "Output msg_status: <b>$msg_status</b><br />"; echo "Output delete_status: <b>$delete_status</b><br />"; echo "<br />Your admin ID is: <b>$xoopsUserIsAdmin : $user_name </b><br />"; //Show admin ID echo "<br /><br /><br />"; echo ">><a href="deletepm.php">Delete more messages</a>"; //author Chao Moua echo "<br /><br /><br />"; echo "<hr />"; echo "Script written by Chao Moua 10-29-2004"; //include footer.php include "footer.php"; ?>
Re:Admin's right to delete unread PM of inactive members
by Dave_L on 2004/11/1 1:51:29

There may be an easier way, but I think this will work (untested):

le="color: #000000"><?php if (is_object($xoopsUser)) { $module_handler =& xoops_gethandler('module'); $system_module =& $module_handler->getByDirname('system'); $system_module_id = $system_module->getVar('id'); $is_system_admin = $xoopUser->isAdmin($system_module_id); } else { $is_system_admin = false; }


Or if you're willing to assume that the ID of the system module is 1, which it probably always is, you could shorten that to:

le="color: #000000"><?php $is_system_admin = is_object($xoopsUser) && $xoopUser->isAdmin(1);
Re:Admin's right to delete unread PM of inactive members
by mouacy on 2004/11/1 0:54:19

Dave_L, you are right. $xoopsUserIsAdmin is for anyone who has admin right to access any module.

What are other alternatives?
Re:Admin's right to delete unread PM of inactive members
by Dave_L on 2004/10/30 5:27:31

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)
le="color: #000000"><?php "DELETE FROM `xoops_priv_msgs` WHERE `msg_time` < '$delete_time' AND `to_userid` != '1";


should be

le="color: #000000"><?php "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.
Re: Admin's right to delete unread PM of inactive members
by mouacy on 2004/10/30 4:03:25

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.

<?php //=======================================================================// //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 "<br />All <b>$delete_status</b> Private Messages have been Deleted.<br />"; } 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 "<br />All <b>$delete_status</b> Private Messages have been Deleted.<br />"; } elseif ( $delete_day >= '1' && $msg_status == 'all' ) { //$sql = "DELETE FROM `xoops_priv_msgs` WHERE `msg_time` < '$delete_time' AND `to_userid` != '1"; echo "<br />All <b>$delete_status $delete_day</b> days old Private Messages have been Deleted.<br />"; } else { //$sql = "DELETE FROM `xoops_priv_msgs` WHERE `read_msg` = '$msg_status' AND `msg_time` < '$delete_time' AND `to_userid` != '1"; echo "<br />All <b>$delete_status $delete_day</b> days old Private Messages have been Deleted.<br />"; } } else { //Admin form to delete private messages echo "Welcome, <b>$user_name</b>.<br />"; echo "<b>Warning:</b> You are about to delete private messages that are X days old.<br /> "; echo "Deleted messages cannot be recovered. Please make a backup of your database. <br />"; echo "IF YOU ENTER NOTHING, ALL SELECT UP-TO-DATE MESSAGES will be deleted!<br /><br />"; echo "<form enctype="multipart/form-data" method="post" action="deletepm.php">"; echo "Delete "; echo "<select size="1" name="msg_status" value="$msg_status"><option>unread</option><option>read</option><option>all</option></select>"; echo "&nbsp;private messages that are "; echo "<input type="text" name="delete_day" value="$delete_day" size="3"> days old."; echo "<input type="submit" name="delete" value="delete" />"; echo "</form>"; } } else { redirect_header("index.php",0, _NOPERM); exit(); } //navigation echo "Output msg_status: <b>$msg_status</b><br />"; echo "Output delete_status: <b>$delete_status</b><br />"; echo "<br />Your admin ID is: $xoopsUserIsAdmin : $user_name <br />"; //Show admin ID echo "<br /><br /><br />"; echo ">>><a href="deletepm.php">Delete more messages</a>"; //author Chao Moua echo "<br /><br /><br />"; echo "<hr />"; echo "Script written by Chao Moua 10-29-2004"; //include footer.php include "footer.php"; ?>

Who's Online

72 user(s) are online (38 user(s) are browsing Support Forums)


Members: 0


Guests: 72


more...

Donat-O-Meter

Stats
Goal: $15.00
Due Date: Jul 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $15.00
Make donations with PayPal!

Latest GitHub Commits