<?php
if (isset($posted['login']))
  {
  $loaded = $db->query_fetch_assoc('SELECT `id`,`ban` FROM `users` WHERE (`name`="'.$posted['login'].'" AND `password` = "'.sha1($posted['password']).'" AND `active`=1)');
  if (empty($loaded))
    {
    $tpl->output['name'] = $posted['login'];
    $tpl->output['error'] = '<span class="error">'.$text['wrong_pass'].'</span>';
    $tpl->output['botom'] = '';
    }
  else
    {
    if ($loaded['ban']==1)
      {
      $tpl->output['name'] = $posted['login'];
      $tpl->output['error'] = '<span class="error">'.$text['banned'].'</span>';
      $tpl->output['botom'] = '';
      }
    else
      {
      $_SESSION['id'] = $loaded['id'];
      $tpl->output['error'] = '<span class="success" style="margin-top: 10px">'.$text['loging_ok'].'</span>';
      $tpl->output['error'] .= '<script type="text/javascript"> opener.location.reload(); window.setTimeout("self.close()", 3000); </script><div style="display: none">';
      $tpl->output['botom'] = '</div>';
      }
    }
  }
else
  {
  $tpl->output['name']='Login';
  $tpl->output['error'] = '';
  $tpl->output['botom'] = '';
  }
?>
