<?php
include_once('../lib/allchar.php');
//=====================================
$cat_table=COMPANYCAT;
if(!empty($_POST["cc"])&&$_POST["cc"]==lang_show('edit_nums'))
{
	for($i=0;$i<count($_POST["nums"]);$i++)
	{
		if(empty($_POST["nums"][$i]))
			$_POST["nums"][$i]=0;
		$sql="update $cat_table set nums='".$_POST["nums"][$i]."' where catid='".$_POST["updateID"][$i]."'";
		$db->query($sql);
	}
	msg("module.php?m=company&s=cat_list.php&catid=$_GET[catid]");
}
if(!empty($_POST["catid"])&&$_POST["updateID"]&&$_POST["cc"]!=lang_show('edit_nums'))
{
	$catid=implode(",",$_POST["catid"]);
	$db->query("delete from $cat_table where catid in ($catid)");
}
?>
<!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>
<TITLE><?php echo lang_show('admin_system');?></TITLE>
<meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
<link href="main.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="bigbox">
  <div class="bigboxhead tab">
	  <span class="cbox"><a href="module.php?m=company&s=add_cat.php"><?php echo lang_show('pro_info_add_cat');?></a></span>
	  <span class="cbox on"><a href="#"><?php echo lang_show('pro_info_cat');?></a></span>
  </div>
  <div class="bigboxbody" style="margin-top:-1px;">
  <table width="100%" border="0" cellspacing="0" cellpadding="0">
  		<tr>
			<td colspan="9">
			<form action="" method="get">
			<?php echo lang_show('cat');?><input class="text" name="keyword" value="<?php echo $_GET['keyword'];?>" type="text" />
			<input class="btn" type="submit" value="<?php echo lang_show('search');?>" />
			<input name="m" type="hidden" value="company" />
			<input name="s" type="hidden" value="cat_list.php" />
			</form>
			</td>
		</tr>
        <tr>
          <td colspan="9">
		  	<div class="char_index">
              <?php
				echo "<a href='module.php?m=company&s=cat_list.php' >All</a>";
				for($i=ord("A");$i<=ord("Z");$i++)  
				echo "<a href='module.php?m=company&s=cat_list.php&char=".chr($i)."' >".chr($i)."</a>";
				?>
            </div>
			</td>
        </tr>
        <?php if(!empty($_GET['catid'])){?>
        <tr>
          <td colspan="9"><a href="javascript:history.back();">&lt;&lt;<?php echo lang_show('return');?></a></td>
        </tr>
        <?php } ?>
        <tr class="theader">
          <td width="20">&nbsp;</td>
          <td align="left" width="50"><?php echo lang_show('sequence');?></td>
          <td width="200"><?php echo lang_show('cat');?></td>
		  <td width="*"><?php echo lang_show('pinyin');?></td>
		  <td align="center" width="100"><?php echo lang_show('shows');?></td>
		  <td align="center" width="100"><?php echo lang_show('cat_pic');?></td>
          <td align="center" width="100"><?php echo lang_show('product_num');?></td>
		  <td align="center" width="110"><?php echo lang_show('binding_template');?></td>
          <td align="center" width="100"><?php echo lang_show('operation');?></td>
        </tr>
	<form action="" method="post">
	<?php
	if(empty($_GET['catid']))
		$tsql=" and catid<=9999";
	else
		$tsql=" and catid>$_GET[catid]00 and catid<$_GET[catid]99";
	
	if(!empty($_GET['char']))
		$tsql.=" and char_index='$_GET[char]'";
		
	if(!empty($_GET['keyword']))
		$tsql=" and cat like '%$_GET[keyword]%' ";
	
	$sql="select * from $cat_table where 1 $tsql order by nums asc,char_index asc";
	$db->query($sql);
	$re=$db->getRows();
	foreach($re as $v)
	{
	?>
		<tr>
          <td><input name="catid[]" type="checkbox" class="checkbox" value="<?php echo "$v[catid]"; ?>"></td>
          <td><input name="nums[]" type="text" id="nums[]2" value="<?php echo $v['nums']; ?>" size="3" /></td>
		  <td><?php echo "<a href=module.php?m=company&s=cat_list.php&catid=$v[catid]>$v[cat]</a>";?></td>
		  <td><?php echo "$v[all_char]";?></td>
		  <td align="center"><?php if($v['isindex'])echo "是";?></td>
          <td align="center"><?php 
			if($v['pic']) 
				echo "<img align='absmiddle' width='25' height='25' src='$v[pic]' >";
		  ?>
		  </td>
          <td align="center"><?php echo $v['rec_nums'];?></td>
		  <td align="center"><?php echo $v['template'];?></td>
          <td align="center">
		  <a href="module.php?m=company&s=add_cat.php&id=<?php echo $v["catid"]; ?>"><?php echo lang_show('modify');?></a> | 
		  <a href="module.php?m=company&s=add_cat.php&aid=<?php echo urlencode($v["catid"])?>"><?php echo lang_show('addsubcat');?></a>
          <input name="updateID[]" id="updateID[]" type="hidden" value="<?php echo "$v[catid]"; ?>">
		  </td>
		</tr>
		<?php
		} 
		if(count($re)>0)
		{
		?>
        <tr>
          <td colspan="7">
		    <input onClick="return confirm('<?php echo lang_show('are_you_sure')?>');" name="cc" class="btn" type="submit" value="<?php echo lang_show('delete');?>">
            <input name="cc" class="btn" type="submit" value="<?php echo lang_show('edit_nums');?>"></td>
        </tr>
        <?php } ?>
		</form>
	</table>
  </div>
</div>
</body>
</HTML>