<?
error_reporting(E_ALL);
$r=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select filename from ecmfiles_versions where id='".$_REQUEST['record']."'"));
$filename=$r['filename'];
unlink($filename);
$GLOBALS['db']->query("delete from ecmfiles_versions where id='".$_REQUEST['record']."'");
$z="select id from ecmfiles_versions where file_id='".$_REQUEST['file_id']."' and deleted='0' order by date_entered asc";
$w=$GLOBALS['db']->query($z);
$j=0;
while($r=$GLOBALS['db']->fetchByAssoc($w))
{
	$ids[$j]=$r['id'];
	$j++;
}
$v=1.0;
for($i=0;$i<count($ids);$i++)
{
	$GLOBALS['db']->query("update ecmfiles_versions set version='".$v."' where id='".$ids[$i]."'");
	$v+=0.1;
}
header("Location: index.php?module=".$_REQUEST['return_module']."&action=DetailView&record=".$_REQUEST['return_id']);
?>