To all cometchat admins :D

thekingfofa

New Member
Hii all
i am new at php and i did this script to get all messages from cometchat tables and be able to empty the table because it is getting bigger and bigger with time
here is the code it is very simple
sorry i have no time to improve it i just wanna share my work with u
PHP:
<title>Cometchat show and delete</title>
<form name="fcicafe.com" method="post" action="<?php echo $PHP_SELF;?>">
  <input type="submit" name="delete" id="delete" value="delete">
</form>
<?php

$conn = mysql_connect("localhost", "username", "password");

if (!$conn) {
    echo "Unable to connect to DB: " . mysql_error();
    exit;
}
  
if (!mysql_select_db("database")) {
    echo "Unable to select mydbname: " . mysql_error();
    exit;
}

if(!isset($_POST['delete'])) 
{
$sql = "SELECT fromuser.username, touser.username, cometchat.message
FROM cometchat
LEFT JOIN user AS fromuser ON ( fromuser.userid = cometchat.from )
LEFT JOIN user AS touser ON ( touser.userid = cometchat.to ) ";

$result = mysql_query($sql);

if (!$result) {
    echo "Could not successfully run query ($sql) from DB: " . mysql_error();
    exit;
}

if (mysql_num_rows($result) == 0) {
    echo "No rows found, nothing to print so am exiting";
    exit;
}

echo "<table border=\"1\">
<td scope=\"col\" >From</td>
<td scope=\"col\">To</td>
<td scope=\"col\">Message</td>";
while ($row = mysql_fetch_array($result)) {
echo"<tr>";
    echo "<td>".$row[0]."</td>";
    echo "<td>".$row[1]."</td>";
    echo "<td>".$row[2]."</td>";
echo"</tr>";
}
echo "</table>";


mysql_free_result($result);
}
else
{
$sql = "TRUNCATE `cometchat`;";
$result = mysql_query($sql);
	if($result)
		echo "Deleted Successfully :)";
	else
		echo "Error :(";
}

?>
Go vbteam ur are the best site
 

h@ck3r

New Member
can you explain this a bit more please?

This code should be added where?

Will this AUTO-Empty the tables (chat history)?
 

lxndr

New Member
h@ck3r said:
can you explain this a bit more please?

This code should be added where?

Will this AUTO-Empty the tables (chat history)?

Yes, this will delete ALL the stored chat records (which are held in the 'cometchat' table). I do it slightly differently based on how many days ago the messages were sent, i.e. delete all chat messages which are over 'x' days old. The script runs automatically once every day and is built into my site which isn't based on vbulletin though.
 

thekingfofa

New Member
lxndr said:
Yes, this will delete ALL the stored chat records (which are held in the 'cometchat' table). I do it slightly differently based on how many days ago the messages were sent, i.e. delete all chat messages which are over 'x' days old. The script runs automatically once every day and is built into my site which isn't based on vbulletin though.

as you said
you can add the delete part to run as Cornjob every X hours
sorry i am not very good Vb programmer so i do it in old fashion way
just upload the file to your server and edit the variables named "username ,password and database" and point the browser to it
 

h@ck3r

New Member
lxndr said:
Yes, this will delete ALL the stored chat records (which are held in the 'cometchat' table). I do it slightly differently based on how many days ago the messages were sent, i.e. delete all chat messages which are over 'x' days old. The script runs automatically once every day and is built into my site which isn't based on vbulletin though.

So basically, you've given us a working script, but needs to somehow be coded ito the VBulletin system? :)
 

Hoxxy

New Member
Would
Admincp >> Maintenance >> Execute SQL Query
Code:
TRUNCATE TABLE cometchat;

Not do the same thing...?
 

iHasvB

New Member
Here's a vBulletin page code, but it will not output anything, it will just display "OKAY" when done.

Code:
<?php
require_once("./global.php");
$vbulletin->db->query_write("TRUNCATE " . TABLE_PREFIX . "cometchat");
print_output("OKAY");

Simple code, but very useful. Enjoy.
Could make a admincp option, but I will leave that to releasers on vB.org such as others and myself.
 
Top