<?
/*
水印全部生成，水印清除
水印生成界面,测试水印生成在  watermarkstr.php
ls_watermark 至少有一条记录吗，且其ID=1
$GLOBALS['wPic']   constant文件 $waterMarkPic定义的 路径，在ls_syscode addWatermark函数加上了扩展名
*/
session_start(); 

	ob_clean();
	require_once('../ls_admin/inc/conn.php');
	require_once('../ls_admin/inc/constant.php');
	require_once('../ls_admin/inc/ls_syscode.php');
	require_once('../ls_admin/inc/ls_inccode.php');

	$opendb=new mydb();

	require_once('../ls_admin/inc/char_set.php');

    //检查字段存在，否则增加
	$openck=new cktb();
	if($openck->checkfield("ls_watermark","wtOperate","ALTER TABLE `ls_watermark` ADD `wtOperate` VARCHAR( 4 ) NOT NULL COMMENT '水印操作类型：测试，生成，null' AFTER `date` "))	$ls_msg = $ls_msg .$openck->ls_msg;
	if($openck->checkfield("ls_watermark","wtTestfile","ALTER TABLE `ls_watermark` ADD `wtTestfile` VARCHAR( 255 ) NOT NULL COMMENT '上次测试图片文件' AFTER `wtOperate` "))	$ls_msg = $ls_msg .$openck->ls_msg;
	
	$wt_sql="select * from ls_watermark where ID= 1";
	$wt_query=$opendb->query($wt_sql);
	$wt_rows=mysql_fetch_assoc($wt_query);
	$mynum=mysql_num_rows($wt_query);
	if($mynum==0)//没有水印记录则添加
	{
		$wt_insert="insert into ls_watermark (ID) value (1)";
		$wt_query=$opendb->query($wt_insert);
	}
	$submit2=$_POST['submit2'];
	$selectpic=$_POST['selectpic'];
	
	//没有选择测试，使用上次的
//$testfile=($_POST['testfile']!=''&&file_exists($_POST['testfile']))?$_POST['testfile']:$wt_rows['wtTestfile'];

	include "widget/watermark_createwtpic.php";
	
	$checkstring="checked";		//default string
	if($_GET['desPic'])
	{$desPic=urldecode($_GET['desPic']);}  // flash this page then get desPic
	//没有选择水印，使用上次的
	$picFile=$_FILES['picFile']['tmp_name']==''?$wt_rows['wtImage']:$_FILES['picFile']['tmp_name'];
	
	$test_sql="select * from ls_products where productID is not null and productName is not null and productPic is not null and enable=1 limit 0,15 ";
	//$test_sql="select * from ls_products";
	$test_query=$opendb->query($test_sql);
	$test_rows=mysql_fetch_assoc($test_query);
	$testfilefolder="../".getproductfolder($test_rows['productID'])."/".$BigFoldersProducts."/";
	if($testfile=="")
	{
		$testfile=$testfilefolder.$test_rows['productPic'];
	}
	if($submit2=="测试水印")
	{
		$wtString=$_POST['wtString'];
		$wtFont=$_POST['wtFont'];
		$wtSize=$_POST['wtSize'];
		$wtColor=$_POST['wtColor'];
		$wtPosition=$_POST['wtPosition'];
		$allPic=$_POST['allPic'];
		$wtType=$_POST['wtType'];
		$srcPic=$testfile;
		$localpicFile=$_POST['localpicFile'];

		if($picFile!='' && $testfile!='' && file_exists($testfile) && file_exists($picFile))  //如果没有测试图片或者水印图片，不执行
		{
			//echo $picFile."----".$testfile;

			list($srcwidth, $srcheight, $srctype, $srcattr) = getimagesize($testfile);//获取文件类型
			if($srctype==1)
			{
				$desPic="images/testwtk.gif";
			}
			if($srctype==2)
			{ 
				$desPic="images/testwtk.jpg";
			}
			if($srctype==3)
			{
				$desPic="images/testwtk.png";
			}
			
			addWatermark($srcPic,$desPic,$wtString,$wtFont,$wtSize,$wtColor,$wtPosition,$wtType,$picFile);
			//更新水印操作记录 13-9-29
			//$waterMarkFile  global var from ls_syscode
			$modi_sql="update ls_watermark set wtImage='".$waterMarkFile."', wtString='".$wtString."', wtFont='".$wtFont."', wtSize='".$wtSize."', wtColor='".$wtColor."', wtPosition='".$wtPosition."',date='".date('Y-m-d H:i:s')."' , wtOperate='测试', wtTestfile='".$srcPic."' where ID=1  ";
			//echo $modi_sql;
			$modi_query=$opendb->query($modi_sql);

			
			$ls_msg= " 测试水印已生成： ".$desPic." <a href='watermarkstr.php?desPic=".urlencode($desPic)."'> 请刷新本页查看</a>";
		}
		else
		{
			$ls_msg= "没有选择水印图片或者测试图片";	
		}

			
	}
	else
	{
		$wtString=$wt_rows['wtString'];
		$wtFont=$wt_rows['wtFont'];
		$wtSize=$wt_rows['wtSize'];
		$wtColor=$wt_rows['wtColor'];
		$wtPosition=$wt_rows['wtPosition'];
		$date=$wt_rows['date'];
		$wtImage=$wt_rows['wtImage']; 
		if($wtString==NULL&&$wtImage!=NULL)
		{$wtType="pic";}

	}
	
	if($wtType=="pic")
	{$checkpic="checked";}
	else
	{$checkstring="checked";}
	//echo 		$localpicFile;

?>
<!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" />
<link href="css/admin.css" rel="stylesheet" type="text/css">
<title>无标题文档</title>
<script type="text/javascript" src="js/ls.js"></script>

</head>

<body>
<table width="96%" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#6396d6">
  <tr>
	<td height="18" background="../images/admin_bg.gif"><div align="center"><strong><font color="#ffffff">设置水印属性并生成</font></strong></div></td>
  </tr>
  <tr>
	<td height="213" valign="top" bgcolor="#dee7ff"><table border="0" width="90%" align="center">
      <tr>
			<td><?=$ls_msg?> </td>
		  </tr>
		</table>
		<form name="watermark" id="watermark" action="watermark.php" method="post" enctype="multipart/form-data"  > 
		  <table width="90%" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#FFFFFF">
			<tr align="center" bgcolor="#B9DAFF">
			  <td rowspan="2" >产品图</td>
			  <td height="29" colspan="2" >
			  <? 
			  //echo $desPic;
			  if($desPic!="") 
			  {	 				  
			  	  if(file_exists($desPic))
				  //."?".date('Y-m-d H:i:s')." 水印刷新
				  { echo  "<img src=\"".$desPic."?".date('Y-m-d H:i:s')."\" name=\"testpic\"  border=\"0\" style='margin:15;'  />"; }
				  else
				  {	  echo  "<img src=\"images/noimage.png\" name=\"testpic\"  border=\"0\" style='margin:15;' />" ;}
				}
			  else
			  {  
				  if(file_exists($testfile))
				  { echo  "<img src=\"".$testfile."\" name=\"testpic\"  border=\"0\" style='margin:15;'  />"; }
				  else
				  {	 echo  "<img src=\"images/noimage.png\" name=\"testpic\"  border=\"0\" style='margin:15;'  />";}
			  } 
			  ?></td>
		    </tr>
			<tr align="center" bgcolor="#B9DAFF">
			  <td height="38" colspan="2" ><span style="padding-left:20px;">
			    <select name="selectpic" id="select"  onchange="javascript:document.testpic.src=watermark.selectpic.value;watermark.testfile.value=watermark.selectpic.value;">
			      <? while($test_rows=mysql_fetch_assoc($test_query))
			  {
			  		$testfilefolder="../".getproductfolder($test_rows['productID'])."/".$BigFoldersProducts."/";
				   echo " <option value=\"".$testfilefolder.$test_rows['productPic']."\">".$test_rows['productName']."</option>\n";
			   }
			  ?>
		      </select>
可以选择一个图片进行水印生成测试
<input name="submit2" type="submit" value="测试水印" onclick="javascript:watermark.action='watermarkstr.php';"/>
<input type="hidden" name="testfile" id="hiddenField4" value="<? echo $testfile ?>"/>
              </span></td>
		    </tr>
			<tr align="center" bgcolor="#B9DAFF">
			  <td  width="9%" rowspan="3" >水印</td>
			  <td  width="38%" height="77" rowspan="2" ><img src="<?=$wt_rows['wtImage']!=''?($wt_rows['wtImage']."?".date('Y-m-d H:i:s')):'images/noimage.png'?>" name="pic"  border="0" id="pic"  />
           <!--   <?=$wt_rows['wtImage']!=''?('<br/>上次'.$wt_rows['wtOperate'].'水印 ('.$wt_rows['date'].')'):''?>  -->
              </td>
			  <td width="53%" height="65"  align="left" valign="top"  style="padding-left:70px;"> 
		        <br />
		        <input name="radio3" type="radio" id="radio8" onclick="javascript:document.watermark.wtType.value='pic';document.watermark.picFile.enabled;" value="radio3" checked="checked"    />
			    图片 :
			    <input name="picFile" type="file" id="fileField" onblur="document.getElementById('pic').src=(this.value+'?time=' + new Date()) ;document.watermark.localpicFile.value=this.value;" value="<?=$localpicFile?>"  >
			  </td>
		    </tr>
			<tr align="center" bgcolor="#B9DAFF">
			  <td  align="left" valign="top"  style="padding-left:70px;"><br />
			    <input name="radio3" type="radio" id="radio7" value="radio3" onclick="javascript:document.watermark.wtType.value='string';" />
文字 :&nbsp; 
  <input type="text" name="wtString" value="<? echo $wtString; ?>"/>
  <input name="wtType" type="hidden" id="hiddenField3" value="pic" />
  <input type="hidden" name="localpicFile" id="localpicFile"  value="<?=$localpicFile?>"/>
  <br />
  <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;字 体 :&nbsp;
<input type="text" name="wtFont" value="<? echo $wtFont; ?>" />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;颜 色 :&nbsp;
<input type="text" name="wtColor" value="<? echo $wtColor; ?>"/>
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;大 小 :&nbsp;
<input type="text" name="wtSize" value="<? echo $wtSize;?>" />
<br />
<br /></td>
		    </tr>
			<tr   bgcolor="#B9DAFF">
			  <td colspan="2"  align="center" style="padding-left:20px;">位置:&nbsp;
                <input name="position" type="radio" id="radio4" value="1" checked="checked" onclick="javascript:document.watermark.wtPosition.value=1;"/>
偏下
<input type="radio" name="position" id="radio5" value="2" onclick="javascript:document.watermark.wtPosition.value=2;"/>
居中
<input type="radio" name="position" id="radio6" value="3" onclick="javascript:document.watermark.wtPosition.value=3;"/>
偏上&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="hidden" name="wtPosition" id="hiddenField2" value="1" />
<input name="all" type="radio" id="radio2" value="1" checked="checked" onclick="javascript:document.watermark.allPic.value=0;"/>
新增图片
<input name="all" type="radio" id="radio" value="1" onclick="javascript:document.watermark.allPic.value=1;"/>
全部图片
<input type="hidden" name="allPic" id="hiddenField" value="0" /></td>
		    </tr>
			<tr bgcolor="#B9DAFF">
			  <td   align="center">生成</td>
			  
			<td height="28" colspan="2" align="center" style='padding-left:20px;'>上次<? echo $wt_rows['wtOperate']; ?>日期:&nbsp;
              <input type="text" name="date" value="<? echo $wt_rows['date']; ?>" />               
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
              <input name="submit" type="submit" id="submit3" value="生成水印" />
                <input name="submit3" type="submit" id="submit" value="清除全部水印"  onclick="javascript:document.watermark.clearallWatermark.value=1;"/>
                <input type="hidden" name="clearallWatermark" id="clearallWatermark" value="0" />
                <br />
              </td>
			</tr>
			<tr bgcolor="#B9DAFF">
			  <td height="56" colspan="3" style='padding-left:30px;'><div  >		      1、“全部图片”指重新全部生成一遍水印；“新增图片”是指只生成上次日期以后新增图片的水印生成。<br />
		      2、没选择水印图片、没选择测试图片，将使用上次的。
			      <br />
			      3、如果给小图加水印，请使用png的水印图片。
			  </div></td>
			</tr>
		  </table>
		  <br />
		<br />
		  <br />
	  </form></td>
  </tr>
</table>
<p>&nbsp;</p>
</body>
</html>
