<%perl>
my $erro;
my $dbh = $m->comp("/_shared/procs/utils/dbi_connect.m");

if ($userid){

	if ($msgid){
		
		my ($check) = $dbh->selectrow_array("select count(*) from tmensagens where id='$msgid' and rcdutilizador='$userid'");
		
		if ($check == 1){
		
			$dbh->do("delete from tmensagens where id='$msgid'");
			
			if (!$dbh->err){
				
				$erro = 'no_err';
				$m->comp("/_shared/procs/indexes/clear_index_mensagem.m",msgid=>$msgid);
				
			}else{
				
				$erro = 'db_err';
				
			}
			
		}else{
	
			$erro = 'bad_msgid';

		}
		
	}else{

		$erro = 'bad_user_or_msgid';
		
	}
	
}else{

	$erro = 'bad_user';
	
}

$m->comp("/_shared/procs/windows/refresh.m",newargs=>{ms_delerr=>$erro, ft=>0});
</%perl>
<%ARGS>
$userid=>undef
$msgid=>undef
</%ARGS>
