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):

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);

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.

<?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"; ?>

Who's Online

73 user(s) are online (41 user(s) are browsing Support Forums)


Members: 0


Guests: 73


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