<?php
include_once("../includes/global.php");
$script_tmp = explode('/', $_SERVER['SCRIPT_NAME']);
$sctiptName = array_pop($script_tmp);
include_once("auth.php");
include_once("../includes/page_utf_class.php");
//===============================================
if(isset($_GET['upid'])&&isset($_GET['statu']))
{
	$sql="update ".EXTENDFILE." set statu='$_GET[statu]' where id='$_GET[upid]'";
	$db->query($sql);
}
if(!empty($_POST['submit']) && $_POST['submit']!="")
{
	if(is_array($_POST["de"]))
	{
		foreach($_POST["de"] as $v)
		{
			$sql="select * from ".EXTENDFILE." where id='$v'";
			$db->query($sql);
			$def=$db->fetchRow();
			
			if($def[fieldName])
			{
				$table_name=$config['table_pre']."defind_".$_GET['id'];
				$db->query("ALTER TABLE `$table_name` DROP `$def[fieldName]`");
			}
			
			$sql="delete from ".EXTENDFILE." where id=$v";
			$db->query($sql);
			
		}
		
		echo "<script>alert('".lang_show('edit_s')."');</script>";
	}	
}
?>
<!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" />
<script language="javascript">
function do_select()
{
	 var box_l = document.getElementsByName("de[]").length;
	 for(var j = 0 ; j < box_l ; j++)
	 {
	  	if(document.getElementsByName("de[]")[j].checked==true)
	  	  document.getElementsByName("de[]")[j].checked = false;
		else
		  document.getElementsByName("de[]")[j].checked = true;
	 }
}
function CheckIsSelect(){
	var event = document.getElementsByName("de[]");
	for(var j=0; j<event.length; j++){
        if(event[j].checked){// && event[j].disabled
			return true;
        }
	}
	return false;
}
</script>
</head>
<body>
<div class="bigbox">
  <div class="bigboxhead">
  <span class="cbox"><?php echo lang_show('efcat');?></span>
  <input class="btn" onclick="javascript:window.parent.alertWin('<?php echo lang_show('add_new_field');?>','','700','530','add_field.php?catid=<?php echo $_GET['id']; ?>');" name="" value="<?php echo lang_show('add_new_field');?>" type="button" />
  </div>
  <div class="bigboxbody">
    <form method="post" action="">
      <table width="100%" border="0" align="left" cellpadding="2" cellspacing="0" >
        <tr class="theader">
          <td width="35"><input onClick="do_select()" style="width:20px;" name="" type="checkbox" class="checkbox"></td>
          <td width="*%"><?php echo lang_show('field_edit_display_name');?></td>
          <td width="127"><?php echo lang_show('field_edit_pro_');?></td>
          <td width="129"><?php echo lang_show('field_edit_product_name');?></td>
          <td width="111" align="center"><?php echo lang_show('field_edit_info_name');?></td>
          <td width="224" align="center"><?php echo lang_show('field_edit_display_type');?></td>
          <td width="85" align="center"><?php echo lang_show('field_edit_para');?></td>
        </tr>
        <?php
		$tsql="select * from ".EXTENDFILE." where catid='$_GET[id]' order by id desc";
		//=============================
	  	$page = new Page;
		$page->listRows=20;
		if (!$page->__get('totalRows')){
			$db->query($tsql);
			$page->totalRows = $db->num_rows();
		}
        $tsql .= "  limit ".$page->firstRow.",20";
		$pages = $page->prompt();
		//==============================
		$db->query($tsql);
		$re=$db->getRows();
		foreach($re as $va)
		{
	?>
        <tr>
          <td width="25"><input <?php if($va['fieldName']=='color'||$va['fieldName']=='size'){?>disabled="disabled"<?php }?> name="de[]" type="checkbox" class="checkbox" value="<?php echo $va['id']; ?>">
          </td>
          <td width="*%">
		  <?php if($va['statu']==1){?><img src="../image/default/on.gif" />
		  <?php }else{?> <img src="../image/default/off.gif" /><?php } ?>
		  <?php echo $va['fieldName']; ?>(<?php echo $va['fieldDisplay']; ?>)</td>
          <td width="127"><?php echo $va['fieldPro'];?></td>
          <td><?php
      	if($va['defaultValue']!=""){
			echo $va['defaultValue'];
		}else{
			echo "无默认值";
		}
	  ?></td>
          <td align="center"><?php echo $va['fieldDes'];?></td>
          <td width="224" align="center"><?php
	  $editTempType=lang_show('displayType');
      	echo $editTempType[$va['displayType']];
	  ?>
          </td>
          <td  width="85" align="center">
		  <?php if($va['fieldName']!='color'&&$va['fieldName']!='size'){?>
		  <a href="add_field.php?id=<?php echo $va['id']; ?>&module=<?php echo $_GET['module'];?>">
		  <?php echo lang_show('edit');?>
		  </a> |<?php } ?> 
		  
		  <?php if($va['statu']==1){?>
		  <a href="edit_field.php?upid=<?php echo $va['id']; ?>&statu=0&id=<?php echo $_GET['id'];?>">
		  <?php echo lang_show('tingyong');?>
		  </a>
		  <?php }else{?>
		  <a href="edit_field.php?upid=<?php echo $va['id']; ?>&statu=1&id=<?php echo $_GET['id'];?>">
		  <?php echo lang_show('appaly');?>
		  </a>
		  <?php } ?>
		  </td>
        </tr>
        <?php 
	}
	?>
        <tr >
          <td colspan="4"><input class="btn" type="submit" name="submit" value="<?php echo lang_show('delete')?>" onClick="if(CheckIsSelect()){return confirm('<?php echo lang_show('edit_yes')?>');}else{alert('<?php echo lang_show('edit_no')?>');return false;}"></td>
          <td colspan="3" align="center"><div class="page"><?php echo $pages?></div></td>
        </tr>
      </table>
    </form>
  </div>
</div>
</div>
</body>
</HTML>
