<?


  include_once '../../config.inc.php';
  if (!include '../autorization.php')
  {
    echo 'Access denied!';
    exit ();
  }

  if (!($result_proper = mysql_query ('select * from properties')))
  {
    exit ('<b>Error:</b>' . mysql_error ());
    ;
  }

  $proper = mysql_fetch_array ($result_proper);
  include '../lang/' . $proper['admin_language'];
  include '../../lang/' . $proper['language'];
  echo '
<HTML><BODY STYLE="color: Navy;"><LINK HREF="../style.css" REL="stylesheet" TYPE="text/css"><TABLE WIDTH="600" BORDER=0 CELLSPACING=0 CELLPADDING=1><TR><TD style="background-color:#505090;"><TABLE WIDTH="100%" BORDER=0 CELLSPACING=0 CELLPADDING=5 BGCOLOR="#EFEFF8">
<TR><TD VALIGN=top BGCOLOR="#BFBFDF" STYLE="border-bottom: 1px solid #505090;"><FONT COLOR="navy"><B>';
  echo $admin_Add_Edit_Delete_Visitors;
  echo '</B></FONT></TD></TR><TR><TD VALIGN=top>

';
  echo '<S';
  echo 'CRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--
function confirmSubmit(record) 
{
if (confirm("Are you sure you wish to delete user \\"" + record + "\\"?"))
	return true ;
else
	return false ;
}
//-->
</SCRIPT>


';
  if (!include '../autorization.php')
  {
    echo 'Access denied!';
    exit ();
  }

  echo '



';
  if ($_GET['delete'])
  {
    if (!(mysql_query ('' . 'DELETE FROM visitors WHERE id=\'' . $_GET['delete'] . '\'')))
    {
      exit ('Query failed');
      ;
    }
  }

  echo '





';
  if ($_POST['useradd'])
  {
    if (($_POST['user'] AND $_POST['pass'] == $_POST['repass']))
    {
      if (!($result = mysql_query ('' . 'SELECT * FROM visitors WHERE username=\'' . $_POST['user'] . '\'')))
      {
        exit ('Query failed4');
        ;
      }

      $row = mysql_fetch_array ($result);
      if (!$row)
      {
        $valid = mktime (23, 59, 59, $_POST['post_month'], $_POST['post_day'], $_POST['post_year']);
        if ($_POST['post_allow'])
        {
          $separated = join ('
', $_POST['post_allow']) . '
';
        }

        $SQL = '' . 'INSERT INTO visitors VALUES(\'\',\'' . $_POST['user'] . '\',\'' . md5 ($_POST['pass']) . ('' . '\',\'' . $separated . '\',\'' . $_POST['status'] . '\',\'' . $valid . '\')');
        if (!(mysql_query ($SQL)))
        {
          exit ('Query failed');
          ;
        }
      }
      else
      {
        echo '<S';
        echo 'CRIPT LANGUAGE="JavaScript" TYPE="text/javascript">alert("User already exist!!")</SCRIPT>';
      }
    }
    else
    {
      echo '<S';
      echo 'CRIPT LANGUAGE="JavaScript" TYPE="text/javascript">alert("Passwords does not match or username is empty!")</SCRIPT>';
    }
  }

  echo '



<FORM ACTION="';
  echo $php_self;
  echo '" METHOD="post">

<TABLE>
<TR>
	<TD ALIGN=right>';
  echo $admin_Username;
  echo '</TD>
	<TD><INPUT TYPE=text NAME="user"></TD>
</TR>
<TR>
	<TD ALIGN=right>';
  echo $admin_Password;
  echo '</TD>
	<TD><INPUT TYPE=password NAME="pass"></TD>
</TR>
<TR>
	<TD ALIGN=right>';
  echo $admin_Repeat_Password;
  echo '</TD>
	<TD><INPUT TYPE=password NAME="repass"></TD>
</TR>
<TR>
	<TD ALIGN=right>';
  echo $admin_Allowed_Categories;
  echo '</TD>
	<TD>
		';
  echo '<S';
  echo 'ELECT NAME="post_allow[]" SIZE="10" MULTIPLE>
		';
  if (!($result = mysql_query ('SELECT * FROM categories')))
  {
    exit ('Query failed4');
    ;
  }

  while ($row = mysql_fetch_array ($result))
  {
    echo '				<option value="';
    echo $row['id'];
    echo '">';
    echo $row['name'];
    echo '</option>
		';
  }

  echo '		</select>		
	</TD>
</TR>
<TR>
	<TD ALIGN=right>';
  echo $admin_Validto;
  echo '</TD>
	<TD>
		';
  echo '<S';
  echo 'ELECT NAME="post_day">';
  for ($i = 1; $i < 32; ++$i)
  {
    echo '<OPTION VALUE="';
    echo $i;
    echo '" ';
    if ($i == date ('j', $curtime[0]))
    {
      echo 'SELECTED';
    }

    echo '>';
    echo $i;
    echo '</OPTION>';
  }

  echo '</SELECT>
		';
  echo '<S';
  echo 'ELECT NAME="post_month">';
  for ($i = 0; $i < 12; ++$i)
  {
    echo '<OPTION VALUE="';
    echo $i + 1;
    echo '" ';
    if ($i == date ('n', $curtime[0]) - 1)
    {
      echo 'SELECTED';
    }

    echo '>';
    echo $month[$i];
    echo '</OPTION>';
  }

  echo '</SELECT>
		';
  echo '<S';
  echo 'ELECT NAME="post_year">';
  for ($i = date ('Y', $curtime[0]); $i <= 2020; ++$i)
  {
    echo '<OPTION VALUE="';
    echo $i;
    echo '" ';
    if ($i == date ('Y', $curtime[0]))
    {
      echo 'SELECTED';
    }

    echo '>';
    echo $i;
    echo '</OPTION>';
  }

  echo '</SELECT>
</TD>
</TR>
<TR>
	<TD ALIGN=right>';
  echo $admin_Status;
  echo '</TD>
	<TD>
		<INPUT TYPE="radio" NAME="status" value="enabled" checked>Enabled
		<INPUT TYPE="radio" NAME="status" value="disabled" ';
  if ($row['status'] == 'disabled')
  {
    echo 'checked';
  }

  echo '>Disabled
	</TD>
</TR>
</TABLE>
<INPUT TYPE=submit NAME="useradd" VALUE="';
  echo $admin_Add_Visitor;
  echo '">
</FORM>






<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=3>
<TR BGCOLOR="#505090">
<TD><FONT COLOR="#FFFFFF">';
  echo $admin_table3[0];
  echo '</FONT></TD>
<td><FONT COLOR="#FFFFFF">';
  echo $admin_table3[2];
  echo '</FONT></td>
<td><FONT COLOR="#FFFFFF">';
  echo $admin_table3[3];
  echo '</FONT></td>
<td align="center"><FONT COLOR="#FFFFFF">';
  echo $admin_table3[4];
  echo '</FONT></td>
</tr>

';
  $SQL = 'SELECT * FROM visitors';
  if (!($result = mysql_query ($SQL)))
  {
    exit ('Query failed4');
    ;
  }

  while ($row = mysql_fetch_array ($result))
  {
    echo '<TR bgcolor="';
    if ($i++ % 2)
    {
      echo '#BFBFDF';
    }
    else
    {
      echo '#DCDCED';
    }

    echo '">
					<TD width=200>';
    echo $row['username'];
    echo '</TD>
					<TD ALIGN=center>
						<A HREF="visitor_edit.php?id=';
    echo $row['id'];
    echo ';"><IMG SRC="../images/edit.gif" ALT="Edit" BORDER=0></A>
						<A onclick="return confirmSubmit(\'';
    echo urlencode ($row['username']);
    echo '\')" HREF="visitor.php?delete=';
    echo $row['id'];
    echo '"><IMG SRC="../images/delete.gif" ALT="Delete" BORDER=0></A>
					</TD>
					<TD ALIGN=center>
						';
    if ($row['status'] == 'enabled')
    {
      echo '<IMG SRC="../images/green.gif" ALT="Enabled" BORDER=0>';
    }
    else
    {
      echo '<IMG SRC="../images/red.gif" ALT="Disabled" BORDER=0>';
    }

    echo '						
					</TD>
					<TD><font style="color:';
    if ($row['valid'] < $curtime[0])
    {
      echo 'red';
    }
    else
    {
      if ($row['valid'] - $curtime[0] < 2592000)
      {
        echo 'yellow';
      }
      else
      {
        echo 'green';
      }
    }

    echo '; font-family: Tahoma; font-size: 11px;">';
    echo date ('d', $row['valid']);
    echo '/';
    echo $month[date ('n', $row['valid']) - 1];
    echo '/';
    echo date ('Y', $row['valid']);
    echo '</font></TD>
			</TR>
			';
  }

  echo '</TABLE>









</TD></TR></TABLE></TD></TR></TABLE></BODY></HTML>';
?>
