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.
 //======================================================// 
//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 "
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"; 
        $result = mysql_query($sql, $cxn); 
        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"; 
        $result = mysql_query($sql, $cxn); 
        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"; 
        $result = mysql_query($sql, $cxn); 
        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. 
"; 
        echo "User ID 1 or Primary Admin's private messages will not be deleted. 
";  
        echo "IF YOU ENTER NOTHING, ALL SELECT UP-TO-DATE MESSAGES will be deleted!
"; 
        echo "Use this script at your own risk.
"; 
        echo ""; 
    } 
}    else { 
    redirect_header("index.php",0, _NOPERM); 
    exit(); 
} 
 
//Print information about the process 
echo "
"; 
echo "SQL Command: $sql 
"; 
echo "SQL Result: $result 
"; 
echo "CXN: $cxn 
"; 
echo "Affected rows: ";  
print $xoopsDB->getAffectedRows(); 
echo "
"; 
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"; 
?>