<?
	include("head.php");
	include("../include/db.inc.php");
	include("../include/pager.php");		
	require_once("../include/bit_functions.inc.php");
	$db1=new db;
    $db1->open();mysql_query("SET NAMES 'utf8'");
if($_SESSION['uname']=='' || $_SESSION['pwd']=='')
		{
			header("location:login.php");
		}
		
if(isset($_POST['submit']))
{
if($_POST['edit'] != 1) {

	if(mysql_num_rows(mysql_query("select * from t123go_category where cname='".$_POST['name']."'"))==0)
	 {
	 if($_FILES['image']['tmp_name']!='' && is_uploaded_file($_FILES['image']['tmp_name']))
							{
								copy($_FILES['image']['tmp_name'],"../images/category/".$_FILES['image']['name']);
								$cimage=$_FILES['image']['name'];
	 
	 
		$name = $_POST['name'];
		$ins="Insert into t123go_category set cname='$name',image='$cimage'";
		mysql_query($ins);
		header("location:category.php");
	    exit();
		}
	 }
	 else
	 {	
		$errmsg="Duplicate category. Please try again with new category.....";
		header("location:category.php?errmsg=".$errmsg);
		exit();
	 }
}
else
{
if($_FILES['image']['tmp_name']!='' && is_uploaded_file($_FILES['image']['tmp_name']))
							{
								copy($_FILES['image']['tmp_name'],"../images/category/".$_FILES['image']['name']);
								$cimage=$_FILES['image']['name'];
							
				}else{
					$cimage=$_POST['image1'];
				}

$name = $_POST['name'];
$id = $_POST[id];
mysql_query("Update t123go_category set cname='$name',image='$cimage' where cid='$id'") or die(mysql_error());
header("location:category.php");
exit();
}
}

if(!empty($_GET['dele']))
{
$id = $_GET['dele'];
mysql_query("delete from t123go_category where cid='$id'") or die(mysql_error());
header("location:category.php");
//exit();
}
if(!empty($_GET['edit']))
{
$id = $_GET['edit'];
$query = ("select cid, cname,image from t123go_category where cid='$id'") or die(mysql_error());
if (!($res=@mysql_query($query))) {error(mysql_error(),__LINE__,__FILE__);}
list($id,$name,$image) = mysql_fetch_array($res);
$edit = 1;
$text = "Edit";
}
else
{
$edit = 0;
$text = "Add";
}
if(!empty($_GET['activate'])) {
$id = $_GET['activate'];
mysql_query("Update t123go_category set status='1' where cid='$id'") or die(mysql_error());
header("location:category.php");
exit();
}
if(!empty($_GET['block'])) {
$id = $_GET['block'];
mysql_query("Update t123go_category set status='0' where cid='$id'") or die(mysql_error());
header("location:category.php");
exit();
}
	

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Money Auctions | Admin Controls</title>
<link href="index.css" rel="stylesheet" type="text/css" />
<script src="../include/validation.js"></script>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}
//-->
</script>
</head>
<body>
<div class="admin_wrapper">
<div class="logo_show"><? include("minorlogout.php");?></div>
<div style="float:left; width:200px">
<div class="topg_links_show"><? include("left.php");	?></div>
<div class="top_links_show"><? include("belowleft1.php");	?></div></div>
<div style="float:left; width:800px">
<div class="maximum"><br />
<br />
          


        <table width="100%" border="0" cellpadding="0" cellspacing="0" class="bodytxt">
    <tr> 
	
    <td width="33" valign="top"><img src="img/03.gif" width="33" height="23"></td>
    <td background="img/bg01.gif"><strong>MAIN CATEGORY LIST</strong></td>
    <td width="35"><img src="img/04.gif" width="35" height="23"></td>
    </tr>
    </table>
		 <table cellpadding="0" cellspacing="0" width="100%" align="center" >
		 
		 <tr>
		 <td width="22" valign="top" background="img/tbl-left04.gif"><img src="img/tbl-left04.gif" width="22" height="13"></td>
		  <td valign="top" >



	  <form action="" method="post" name="form1" enctype="multipart/form-data" onSubmit="MM_validateForm('name','','R');return document.MM_returnValue">
	    <table width="90%" align="center" border="0" cellspacing="0" cellpadding="0">
         <tr>
             <td colspan="2" align="center"><h3>
            	<? if($_GET['errmsg']!='') 
					echo $_GET['errmsg'];
				?> 
                </h3>
             </td>
         </tr> 
          <tr>
            <th width="29%" scope="row" align="center"><div align="right" class="normaltextblackbold">Name:</div></th>
            <td width="71%"><input name="name" type="text" class="whiteselect" id="name" value="<?=$name?>" />
            </td>
          </tr>
		   <tr>
            <th width="29%" scope="row" align="center"><div align="right" class="normaltextblackbold">Image:</div></th>
            <td width="71%"><input name="image" type="file" class="whiteselect" id="name"  />
            	<input name="submit" type="submit" class="inputsubmit" value="<?=$text?>" />
                <input name="id" type="hidden" id="id" value="<?=$id?>" />
				 <input name="image1" type="hidden" value="<?=$image?>" />
                <input name="edit" type="hidden" id="edit" value="<?=$edit?>" />            
            </td>
          </tr>
        </table>
        </form><br />

<table width="95%" border="1" cellspacing="1" cellpadding="1" bgcolor="#FFFFFF" style="border-collapse:collapse; border-color:#FED267">
        <tr bgcolor="#FED267">
          <th width="16%" height="17"   scope="col"><strong><font color="#FFFFFF" size="+1">S . No </font></strong></th>
          <th width="39%" align="left" scope="col"><strong><font color="#FFFFFF" size="+1">Name</font></strong></th>
          <th width="15%" align="center" scope="col"><strong><font color="#FFFFFF" size="+1">Action </font></strong></th>
        </tr>
		
		<?php
		$query = mysql_query(dopaging("select cid,cname,image from t123go_category order by cname",20)) or die(mysql_error());
		$num = 1;
		while($row= mysql_fetch_array($query)) 
		{ ?>
		
		
		<tr  onMouseOver="this.style.backgroundColor='#FFECBF'" onMouseOut="this.style.backgroundColor='#ffffff'">
		<td align="center"  ><?=$num?></td>
			  <td align="left"><?=$row[1]?></td>
			  <td align="center">
			    <a href="category.php?edit=<?=$row[0]?>" >EDIT</a> | 
				<a href="category.php?dele=<?=$row[0]?>" onClick="return confirm('Are you sure to delete this Category ?');" >DELETE</a> 
			  </td>
			  </tr>		
		<?	
		$num +=1;	
		}
		if(rightpaging())?>
				<tr><td colspan=3 align=center><br /><?=rightpaging()?></td></tr>
		
      </table>
	 
	  	</td>
		 <td width="19" valign="top" background="img/tbl-right04.gif"><img src="img/tbl-right04.gif" width="19" height="9"></td>
		 </tr>
		 </table>
     <table width="100%" border="0" cellpadding="0" cellspacing="0" class="bodytxt">
              <tr> 
                <td width="33"><img src="img/tbl-bot01.gif" width="33" height="12"></td>
                <td  width="709" align="right" background="img/tbl-bg.gif"></td>
                <td width="33"><img src="img/tbl-right05.gif" width="35" height="12"></td>
              </tr>
            </table>
	 
	    <!--End Main Body-->
		</td>
  </tr>
</table>
</div>


      
            <br />
<br />

</div></div>
<div class="bottom_links_show"><? include("footer.php");	?></div>

</html>
</div>
</body>
</html>
