<?php
include_once("../includes/tag_inc.php");
//=========================================================
$sql="select a.*,b.detail from ".INFO." a left join ".OFFERDETAIL." b on a.id=b.offerid where a.id='$_GET[id]'";
$db->query($sql);
if($db->next_record())
{
	$id=$db->f('id');
	$type=$db->f('type');
	$userid=$db->f('userid');
	$user=$db->f('user');
	$title=$db->f('title');
	$con=$db->f('con');
	$detail=$db->f('detail');
	$rank=$db->f('rank');
	$valid_time=$db->f('valid_time');
	$offer_type=$db->f('offer_type');
	$keyword=$db->f('keywords');
	$catid=$db->f('catid');
	$pp=$db->f('pp');
	$price=$db->f('price');
	$uptime=$db->f('uptime');

	$pic=$db->f('pic');
	if(!empty($pic))
	{
		$pic=explode(',',$pic);	
		foreach($pic as $key=>$val)
		{
			if(!empty($val))
				$pic[$key]=substr_replace($val,'/big_',strripos($val,'/'),1);
		}
	}
		
}
$sql="select ext_table from ".OCAT." where catid='$catid'";
$db->query($sql);
$ext_table=$db->fetchField('ext_table');
//----------------------------------------------------------
if(!empty($_POST["submit"]))
{
	if(empty($_POST['rank']))
		$mrank=0;
	else
		$mrank=$_POST["rank"];

	$sql="update ".INFO." set 
	title='$_POST[title]', con='$_POST[con]',rank='$mrank', valid_time='$_POST[valid_time]' where id='$_GET[id]'";
	$db->query($sql);
	
	$db->query("update ".OFFERDETAIL." set detail='$_POST[detail]' where offerid='$_GET[id]'");
	edit_tags($_POST['keyword'],2,$_GET['id']);
	
	include_once("$config[webroot]/includes/plugin_add_field_class.php");
	$addfield = new AddField('offer');
	$addfield->update_con($_GET['id'],$cat_name['ext_table']);//填加自定义字段
	admin_msg("module.php?m=offer&s=offermod.php&id=$_GET[id]","编辑成功");
}
?>
<!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="bigboxbody">
	<form name="form1" method="post" action="" enctype="multipart/form-data">
      <table width="100%" border="0" cellpadding="4" cellspacing="0" >
        <tr>
          <td width="84"><strong><?php echo lang_show('info_title');?></strong></td>
          <td width="587"><input class="text" name="title" type="text" id="goods" value="<?php echo "$title";?>" size="30">
          </td>
        </tr>
        <tr>
          <td><strong><?php echo lang_show('valid_time');?></strong></td>
          <td><select class="select" name="valid_time">
              <?php
					$valid_times=explode('|',$config['valid_time']);
					foreach ($valid_times as $key=>$value)
					{
						if($key==$valid_time) 
							 echo "<option value='$key' selected >$value</option>"; 
						else
							 echo "<option value='$key'>$value</option>";
					}
				?>
            </select>
          </td>
        </tr>
        <tr>
          <td><strong><?php echo lang_show('kword');?></strong></td>
          <td><input class="text" name="keyword" type="text" id="keyword" value="<?php echo $keyword;?>"></td>
        </tr>
        <?php
			include_once("$config[webroot]/includes/plugin_add_field_class.php");
			$addfield = new AddField('offer');
			$filed=$addfield->addfieldinput($id,$ext_table);
			if($filed)
			{
				foreach($filed as $v)
					echo $v;
			}
			?>
        <tr>
          <td><strong><?php echo lang_show('summary');?></strong></td>
          <td><textarea class="text" name="con" id="con" cols="45" rows="5"><?php echo $con;?></textarea></td>
        </tr>
        <tr>
          <td width="84"><strong><?php echo lang_show('detail');?></strong></td>
          <td>
            <script charset="utf-8" src="../lib/kindeditor/kindeditor-min.js"></script>             
<script>
var editor;
KindEditor.ready(function(K) {
editor = K.create('textarea[name="detail"]', {
});
});
</script>
     <textarea name="detail" style="width:90%; height:400px;"><?php echo $detail ?></textarea>
     
            
            </td>
        </tr>
        <tr>
          <td><strong><?php echo lang_show('rank');?></strong></td>
          <td><input class="text" name="rank" type="text" id="rank" value="<?php echo $rank;?>"></td>
        </tr>
        <tr >
          <td align="center">&nbsp;</td>
          <td align="left"><input name="submit" class="btn" type="submit" id="cc" value="<?php echo lang_show('submit');?>"></td>
        </tr>
      </table>
    </form>
  </div>
</div>
</body>
</html>
