<?php
if(!empty($_POST['submit']))
{
	$time=time();
	$money=$_POST['money']*1;
	
	$sql="select b.id,a.company_id from ".COMPANY." a left join ".EAR." b on a.company_id=b.company_id 
		  where b.company='$_POST[company]'";
	$db->query($sql);
	$re=$db->fetchRow();
	$id=$re['id'];
	$company_id=$re['company_id'];
	
	if(!empty($id))
	{
		if(empty($company_id))
		{
			$sql="insert into ".EAR." (company_id,money,con,admin,time) 
				 values ('$company_id','$money','$_POST[con]','$_SESSION[ADMIN_USER]','$time')";
			$re=$db->query($sql);
		}
		else
		{
			$sql="update ".EAR." set money='$money',con='$_POST[con]',admin='$_SESSION[ADMIN_USER]',time='$time' 
				 where id='$id'";
			$re=$db->query($sql);
		}
		
		if($re)
		{
			$sql="update ".COMPANY." set earnest='$money' where company_id='$company_id'";
			$db->query($sql);
			admin_msg('module.php?m=company&s=earnest_list.php','操作成功');
		}
	}
}
?>
<!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 type="text/javascript" src="../script/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="main.js"></script>
</HEAD>
<body>

<div class="bigbox">
	<div class="bigboxhead tb">
		<span class="cbox"><a href="module.php?m=company&s=earnest_list.php"><?php echo lang_show('man_cash');?></a></span>
		<span class="cbox on"><a href="module.php?m=company&s=earnest_add.php"><?php echo lang_show('add_cash');?></a></span>
	</div>
	<div class="bigboxbody">
	<form id="form1" name="form1" method="post" action="">
  <table width="100%" border="0" cellpadding="2" cellspacing="0" >
    <tr> 
      <td width="126"><?php echo lang_show('username');?>  </td>
      <td width="816"><input name="user" type="text" value="<?php echo $_GET['name'];?>" class="text" id="user" /></td>
      </tr>
      <tr> 
        <td><?php echo lang_show('money');?></td>
        <td align="left"><input name="money" type="text" class="text" id="money" /></td>
      </tr>
      <tr>
        <td><?php echo lang_show('remark');?></td>
        <td align="left"><textarea name="con" class="text" id="con"></textarea></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td align="left"><input class="btn" type="submit" name="submit" value="<?php echo lang_show('submit');?>" /></td>
      </tr>
  </table>
  </form>
  </div>
</div>
</body>
</html>
