This is a clean up script for uddeIM 0.5+.
When you delete a user in Jommla the corresponding messages are still stored in the uddeIM tables. This script deletes uddeIM table entires which are not longer required.
Run this script before you delete a user in Joomla. After executing the script you can remove the user in Joomla.
Messages
- to the deleted user which have not been deleted by the sender, and
- from the deleted user which have not been deleted by the receiver
are kept of course.
[code:1]
delete_user.php
<?php
$hostname = "localhost";
$database = "xxxx";
$username = "xxxx";
$password = "xxxx";
$link = mysql_pconnect($hostname, $username, $password) or trigger_error(mysql_error(),E_USER_ERROR);
session_start();
mysql_select_db($database, $link);
$query = "SELECT * FROM jos_users ORDER BY username ASC";
$result = mysql_query($query, $link) or die(mysql_error());
$users = mysql_fetch_assoc($result);
?>
<html>
<head>
<title>Delete user messages</title>
</head>
<body>
<h2>Delete user messages:</h2>
<form action="<?php echo $_SERVER;?>" method="post" enctype="multipart/form-data">
<p>Username: <select name="user" size=1>
<?php
while ($row = mysql_fetch_assoc($result)) {
echo "<option value=".$row["username"].">".$row["username"]."</option>";
}
mysql_free_result($result);
?>
</select><br/>
<input type="submit" name="delete" value="delete" /><br/>
</p>
</form>
<?php
if (!isset($_POST["delete"])) {
exit;
}
$user=$_POST;
$query = "SELECT * FROM jos_users WHERE username = '".$user."'";
$result = mysql_query($query, $link) or die(mysql_error());
$id = mysql_fetch_assoc($result);
$userid = $id["id"];
mysql_free_result($result);
$query = "UPDATE `jos_comprofiler` SET `avatar` = '".$filename."' WHERE `user_id` = ".$userid;
$query = 'DELETE FROM `jos_uddeim` WHERE '
. ' (`fromid` ='.$userid.' AND `totrashoutbox` =1)'
. ' OR'
. ' (`toid` ='.$userid.' AND `totrash` =1)'
. ' ';
echo $query."<br />";
$result = mysql_query($query, $link) or die(mysql_error());
$deletetime=time();
$query = "UPDATE `jos_uddeim` SET totrashoutbox=1, totrashdateoutbox=".$deletetime." WHERE toid=".$userid;
echo $query."<br />";
$result = mysql_query($query, $link) or die(mysql_error());
$query = "UPDATE `jos_uddeim` SET totrash=1, totrashdate=".$deletetime." WHERE fromid=".$userid;
echo $query."<br />";
$result = mysql_query($query, $link) or die(mysql_error());
echo "<br/>User messages from ".$user." have been deleted.";
?>
</body>
</html>
[/code:1]
uddeIM & uddePF Development
CB Language Workgroup
CB 3rd Party Developer