<?php

/**
 * [BEGIN_COT_EXT]
 * Hooks=ajax
 * [END_COT_EXT]
 */

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

cot_sendheaders();

$a = cot_import('a', 'G', 'TXT');

$t = new XTemplate(cot_tplfile('banlist.ajax', 'plug'));

if($usr['id'] > 0) {
  if($a == 'check') {
   $id = cot_import('id', 'G', 'TXT');
   $urr = array();

   if($id > 0) {
     $urr = $db->query("SELECT * FROM $db_users WHERE user_id=".$id)->fetch();
   }
   if($urr['user_id'] > 0) {
    $t->assign(cot_generate_usertags($urr, 'BANLIST_USER_'));

    $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
    	{
      	$t->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)
      	));
        $t->parse("MAIN.BANS_ROW");
        $cntbns++;
    	}
    }

    $t->assign('BANS_COUNT', $cntbns);
   } else {
     exit;
   }
  }
}

