11
mouacy
Re:Admin's right to delete unread PM of inactive members
  • 2004/11/1 0:54

  • mouacy

  • Not too shy to talk

  • Posts: 138

  • Since: 2002/11/2


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

What are other alternatives?

12
Dave_L
Re:Admin's right to delete unread PM of inactive members
  • 2004/11/1 1:51

  • Dave_L

  • XOOPS is my life!

  • Posts: 2277

  • Since: 2003/11/7


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

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:

$is_system_admin is_object($xoopsUser) && $xoopUser->isAdmin(1);

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

  • mouacy

  • Not too shy to talk

  • Posts: 138

  • Since: 2002/11/2


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.

//======================================================//
//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_USERXOOPS_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 
"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="30" size="3"> days old.  ";
        echo 
"submit" name="delete" value="delete" />";
        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";
?>

Login

Who's Online

351 user(s) are online (253 user(s) are browsing Support Forums)


Members: 0


Guests: 351


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