<?php

/**
 * [BEGIN_COT_EXT]
 * Hooks=users.details.tags
 * [END_COT_EXT]
 */

defined('COT_CODE') or die('Wrong URL.');

$tab = cot_import('tab', 'G', 'ALP');

$t1 = new XTemplate(cot_tplfile('banlist.userdetails', 'plug'));

cot::$db->registerTable('banlist');

$sqlbans = $db->query("SELECT *
	FROM $db_banlist WHERE banlist_active=1 AND
	banlist_email='".$db->prep($urr['user_name'])."'")->fetchAll();

$cntbns = 0;
foreach($sqlbans as $row) {
	if ($row['banlist_iswarning'] == 0 && $sys['now'] > $row['banlist_expire'] && $row['banlist_expire'] > 0)
	{
		$sql = $db->update($db_banlist, array('banlist_active' => 0), "banlist_id='".$row['banlist_id']."'");
	}
	else
	{
  	$t1->assign(array(
  		'BANLIST_ROW_ID' => $row['banlist_id'],
      'BANLIST_ROW_DATE' => $row['banlist_date'],
  		'BANLIST_ROW_EXPIRE' => ($row['banlist_iswarning'] == 0 ? (($row['banlist_expire'] > 0) ? cot_date('datetime_medium', $row['banlist_expire']) : $L['banlist_neverexpire']) : ''),
  		'BANLIST_ROW_EXPIRE_STAMP' => ($row['banlist_expire'] > 0) ? $row['banlist_expire'] : '',
  		'BANLIST_ROW_REASON' => $row['banlist_reason'],
      'BANLIST_ROW_ISWARNING' => ($row['banlist_iswarning'] == 1 ? 1 : 0)
  	));
    $t1->parse("MAIN.BANS_ROW");
    $cntbns++;
	}
}

$t1->assign('BANS_COUNT', $cntbns);
$t1->parse("MAIN");

$t->assign(array(
  'BANS' => $t1->text("MAIN"),
  'USERS_DETAILS_BANS_COUNT' => $cntbns
));

?>