13
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.phpAnything 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 " private messages that are "; echo "<input type="text" name="delete_day" value="30" size="3"> days old. "; 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"; ?>