<?php
session_start();
require 'include/header.php';
?>
<style type="text/css">
<!--
.style1 {
	color: #666666;
	font-weight: bold;
}
.style3 {color: #666666; font-size: 11px; font-family:Arial, Helvetica, sans-serif}
-->
</style><?php
require 'include/configurations.php'; // ITECHBIDS Configuration File
$mode=trim($_GET['mode']);
$id=$_GET['id'];
$fsql="select * from member_details where user_type='bot'";
$fres=mysql_query($fsql);
if(($mode=='edit')||($mode=='stats'))
{
$eres=mysql_query("select * from member_details where user_id=$id");
$erow=mysql_fetch_array($eres);
}
$username=$_POST['username'];
$cansave=$_POST['cansave'];
if($cansave=='')
{
		$cansave=$_GET['cansave'];
}
if($cansave==1)
{
if($mode=='add'){

$sql="insert into member_details (user_name,date_of_registration,user_type) values('$username',now(),'bot')";
}else if($mode=='edit'){
$sql="update member_details set user_name='$username' where user_id=$id";
}else if($mode=='delete')
{
$sql="delete from member_details where user_id='$id'";
}
$res=mysql_query($sql);

if($res)
{
if($mode=='add')
	$message="User added sucessfully";
else if($mode=='edit')
	$message="User edited sucessfully";
else if($mode=='delete')
	$fres=mysql_query($fsql);
else
	$message="Please try later";

echo '<meta http-equiv="refresh" content="0;url=addbot.php">';	
	
}
}
if($mode=='' || $mode=='stats' || $mode=='delete' || ($mode=='add'&&$cansave==1))
		  {
?>
 <table align="center" width="80%" class="ft" cellpadding="2">
          <tr class="ct" height="25"> 
            <td height="24" colspan="7">Bot Users</td>
          </tr>
		        <?php
	$total_records=mysql_num_rows($fres);
	$curpage=$_GET['curpage'];
	if(strlen($_GET['curpage']) == 0) $curpage=1;
	$start=($curpage-1) * 10;
	$end=10;
	if($curpage==''|| $curpage==1)
	$i=1;
	else $i=$_GET['sno']+1;
	$fsql.=" limit $start,$end";
	$fres=mysql_query($fsql);
 ?>
        <tr> 
          <td align="right" colspan="2"> 
            <?php
	if($curpage!=1) {
?>
            <a href="addbot.php?curpage=<?=($curpage-1);?>&sno=<?=($curpage*10)-20; ?>" id="link2">Prev</a> 
            | 
            <?php
}
?>
            <?php
if($total_records > ($start + $end)) {
?>
            <a href="addbot.php?curpage=<?=($curpage+1);?>&sno=<?=$curpage*10; ?>" id="link2">Next</a> <?php
}
?>
          </td>
        </tr>
		
		  <?php
		   while($frow=mysql_fetch_array($fres))
		  {
		  ?>
		    <tr><td ><?=$i; ?>.&nbsp;<?=$frow['user_name']; ?></td>
<td ><a href="addbot.php?mode=edit&id=<?=$frow['user_id']; ?>" id="link2">Edit</a></td>
			<td ><a href="addbot.php?cansave=1&mode=delete&id=<?=$frow['user_id']; ?>" id="link2" onClick="javascript:return condelete();">Delete</a></td></tr>
 		<tr></td></tr>
		<?php 
		
		$i++;
		} 
		
		?>
 		<tr><td  colspan="3" align="center">
		<input onclick="location.href='addbot.php?mode=add'" type="button" name="btnadd" value=" add "/>
		</td></tr>		 
        </table>
		<?php } 
		else if($mode=='add' || $mode=='edit')
		{
		
		?>
		<form name="frm" method="post" onSubmit="return validate();">
		  <table align="center" width="80%" class="ft" cellpadding="2">
		  <tr><td colspan="2" align="center"><font face="Arial, Helvetica, sans-serif" style="font-weight:bold"><?=$message; ?></font></td></tr>
            <tr class="ct" height="25">
              <td width="20%" ><div align="right">Username</div></td>
              <td width="80%" ><input type="text" class="bluetext"name="username" size="48" value="<?=$erow['user_name']; ?>"></td>
            </tr>
            <tr >
              <td align="center" colspan="2"><input type="hidden" name="cansave" value="0"><input type="submit" class="button"   name="submit" value="Submit" ></td>
            </tr>
          </table>
		</form>
		<?php
		}
 		?><?php
require 'include/footer.php';
?>
<script language="JavaScript">
function condelete()
{
var confrm;
confrm=window.confirm("Are You sure you want to delete this User");
return confrm;
}
function validate()
{
form=document.frm;
if(form.username.value=="")
	{
	alert("Please enter the title");
	form.username.focus();
	return false;
	}
form.cansave.value=1;
return true;
}
</script>