<?php

/* 
 *	W-AGORA 4.0
 *	-----------
 *	$Id: purge.php,v 1.1 2001/08/23 13:06:37 mdruilhe Exp $
 *	Usage:		Delete messages in forum $bn older than $ndays days
 *	syntax:		purge.php?bn=forum_name&ndays=value
 *
 *	Author:		Marc Druilhe <mdruilhe@w-agora.com>
 *
 */

	## $bn = "forum_name";		# set here the name of the forum (ie: configuration filename)
	$wa_dir = ".."			# define the w-agora installation directory

	define("no_auth_required", 1);

	$ext = "php";		# PHP script extension
	$inc_dir = "include";	# include directory

	if (empty($bn)) {
		die ("Forum must be defined");
	}

	if (!empty ($wa_dir)) {
		chdir ($wa_dir);
	}

	$ndays = (isset($ndays)) ? $ndays : 60;			# purge messages older than 60 days

# Include the configuration file
# ------------------------------
	require ("init_admin.$ext");

# Call before access script
# -------------------------
	if (!empty($bn_before_access)) {
 		$bn_action="delete";
		include "$bn_dir/$bn_before_access";
	}

# do deleting messages
# -----------------------
	$from_date=2;		# skip administrative notes (0 & 1)
	$to_date = time() - (24*3600*$ndays);
	$ret = $db->mDeleteDate ($bn_db, $from_date, $to_date, $bn_dir_notes);

	if ($ret < 0) {
		die ("Error during deleting old messages, return code : $ret");
	} else {
		echo "$ret notes were deleted";
	}

# Start search indexation
# -----------------------
	if ($bn_search && ($bn_doc_type == "static") && ($bn_search_engine != "none") ) {
		include "include/$bn_search_engine.php";
		$search->indexNotes();
	}
?>
