<?php 
function productparam(){
	$sql="select * from trade_param order by id";
	$result=mysql_query($sql);
	while($rs=mysql_fetch_array($result)){  ?>
            <input type="text"  name="param[]" value="<?php echo $rs['param'];?>" class="input1" />:<input type="text" name="value[]" value="<?php echo $rs['value'];?>" class="input" /><br />
<?php 	}
}?>

<?php function fob_moneystyle($style=""){?>
		<option value="" <?php if($style=="") echo "selected=\"selected\"";?>>货币种类</option>
                                <option value="USD" <?php if($style=="USD") {echo "selected=\"selected\"";} ?>>USD</option>
                                <option value="GBP" <?php if($style=="GBP") {echo "selected=\"selected\"";} ?>>GBP</option>
                                <option value="RMB" <?php if($style=="RMB") {echo "selected=\"selected\"";} ?>>RMB</option>
                                <option value="EUR" <?php if($style=="EUR") {echo "selected=\"selected\"";} ?>>EUR</option>
                                <option value="AUD" <?php if($style=="AUD") {echo "selected=\"selected\"";} ?>>AUD</option>
                                <option value="CAD" <?php if($style=="CAD") {echo "selected=\"selected\"";} ?>>CAD</option>
                                <option value="CHF" <?php if($style=="CHF") {echo "selected=\"selected\"";} ?>>CHF</option>
                                <option value="JPY" <?php if($style=="JPY") {echo "selected=\"selected\"";} ?>>JPY</option>
                                <option value="HKD" <?php if($style=="HKD") {echo "selected=\"selected\"";} ?>>HKD</option>
                                <option value="NZD" <?php if($style=="NZD") {echo "selected=\"selected\"";} ?>>NZD</option>
                                <option value="SGD" <?php if($style=="SGD") {echo "selected=\"selected\"";} ?>>SGD</option>
                                <option value="NTD" <?php if($style=="NTD") {echo "selected=\"selected\"";} ?>>NTD</option>
                                <option value="Other" <?php if($style=="Other") {echo "selected=\"selected\"";} ?>>Other</option>

<?php }?>
<?php function paymentmethod($str=""){?>
<input type="checkbox" name="payment[]"  value="L/C" <?php if($str<>""){ echo strpos($str,"L/C",0)?"checked":"";} ?>/> L/C&nbsp;
<input type="checkbox" name="payment[]" value="D/A" <?php if($str<>""){ echo strpos($str,"D/A",0)?"checked":"";} ?>/> D/A &nbsp;
<input type="checkbox" name="payment[]" value=" D/P" <?php if($str<>""){ echo strpos($str,"D/P",0)?"checked":"";} ?> /> D/P &nbsp;
<input type="checkbox" name="payment[]" value="T/T" <?php if($str<>""){ echo strpos($str,"T/T",0)?"checked":"";} ?>/> T/T &nbsp;
<input type="checkbox" name="payment[]" value="Western Union" <?php if($str<>""){ echo strpos($str,"Western Union",0)?"checked":"";} ?>/> Western Union&nbsp;
<input type="checkbox" name="payment[]" value=" MoneyGram" <?php if($str<>""){ echo strpos($str,"MoneyGram",0)?"checked":"";} ?>/> MoneyGram
 <?php
 
 } ?>                      
 <?php function unit($unit=""){ ?>
 <option value="" <?php echo $unit==""?"selected":""; ?>>计量单位</option>
 	<option value="Bag/Bags" <?php echo $unit=="Bag/Bags"?"selected":""; ?>>Bag/Bags</option>
    <option value="Barrel/Barrels" <?php echo $unit=="Barrel/Barrels"?"selected":""; ?>>Barrel/Barrels</option>
    <option value="Bushel/Bushels" <?php echo $unit=="Bushel/Bushels"?"selected":""; ?>>Bushel/Bushels</option>
    <option value="Cubic Meter" <?php echo $unit=="Cubic Meter"?"selected":""; ?>>Cubic Meter</option>
    <option value="Dozen" <?php echo $unit=="Dozen"?"selected":""; ?>>Dozen</option>
    <option value="Gallon" <?php echo $unit=="Gallon"?"selected":""; ?>>Gallon</option>
    <option value="Gram" <?php echo $unit=="Gram"?"selected":""; ?>>Gram</option>
    <option value="Kilogram" <?php echo $unit=="Kilogram"?"selected":""; ?>>Kilogram</option>
    <option value="Kilometer" <?php echo $unit=="Kilometer"?"selected":""; ?>>Kilometer</option>
    <option value="Liter/Liters" <?php echo $unit=="Liter/Liters"?"selected":""; ?>>Liter/Liters</option>
    <option value="Long Ton" <?php echo $unit=="Long Ton"?"selected":""; ?>>Long Ton</option>
    <option value="Meter" <?php echo $unit=="Meter"?"selected":""; ?>>Meter</option>
    <option value="Metric Ton" <?php echo $unit=="Metric Ton"?"selected":""; ?>>Metric Ton</option>
    <option value="Milligram" <?php echo $unit=="Milligram"?"selected":""; ?>>Milligram</option>
    <option value="Ounce" <?php echo $unit=="Ounce"?"selected":""; ?>>Ounce</option>
    <option value="Pair" <?php echo $unit=="Pair"?"selected":""; ?>>Pair</option>
    <option value="Pack/Packs" <?php echo $unit=="Pack/Packs"?"selected":""; ?>>Pack/Packs</option>
    <option value="Piece/Pieces" <?php echo $unit=="Piece/Pieces"?"selected":""; ?>>Piece/Pieces</option>
    <option value="Pound" <?php echo $unit=="Pound"?"selected":""; ?>>Pound</option>
    <option value="Set/Sets" <?php echo $unit=="Set/Sets"?"selected":""; ?>>Set/Sets</option>
    <option value="Short Ton" <?php echo $unit=="Short Ton"?"selected":""; ?>>Short Ton</option>
    <option value="Square Meter" <?php echo $unit=="Square Meter"?"selected":""; ?>>Square Meter</option>
    <option value="Ton" <?php echo $unit=="Ton"?"selected":""; ?>>Ton</option>
    <option value="Unit/Units" <?php echo $unit=="Unit/Units"?"selected":""; ?>>Unit/Units</option>
    <option value="Yard/Yards" <?php echo $unit=="Yard/Yards"?"selected":""; ?>>Yard/Yards</option>
<?php  }?>                      

<?php function supply_times($every=""){ ?>
	<option value="Day" <?php $unit=="Day"?"selected":""; ?>>Day</option>
	<option value="Week" <?php $unit=="Week"?"selected":""; ?>>Week</option>
    <option value="Quarter" <?php $unit=="Quarter"?"selected":""; ?>>Quarter</option>
    <option value="Month" <?php $unit=="Month"?"selected":""; ?>>Month</option>
    <option value="Year" <?php $unit=="Year"?"selected":""; ?>>Year</option>
<?php }?>                       
  
<?php function productparambyid($userid,$proid){
		$sql="select * from trade_pro_param where userId=$userid and proId=$proid";
		$result=mysql_query($sql);
		while($rs=mysql_fetch_array($result)){?>
		<tr class=""><td><input type="text"  name="param[]" value="<?php echo $rs['parameter']?>" class="input1" />: <input type="text" name="value[]" value="<?php echo $rs['paramvalue'];?>" class="input" /></td></tr>
		<?php }
}?>  
                       
<?php 
function getWeblist($userid,$website=''){
	$sql="select * from etw_web where usernameid=$userid and istrade=1";
	$result=mysql_query($sql);
	while($rs=mysql_fetch_array($result)){
		$select=$website==$rs['website']?" selected=selected ":"";
		echo "<option value=".$rs['langId']."|".$rs['website']." $select>".$rs['website']."</option>";
	}
}
function stringtoarray($str){
	$list=explode(",",$str);
	for($i=0;$i<count($list)-1;$i++){
		$arr[$i]=$list[$i];
	}
	return $arr;
}

function keywords($str){
		//if(!empty($str)){ $temp=explode(",",$str);}
		return $str;
}
function getproid($userid){
	$sql="select proId from trade_product where userid=$userid order by proId desc";
	$result=mysql_query($sql);
	$num=mysql_num_rows($result);
	if($num==0){$proid=1;}else{
		$proid=mysql_result($result,0,"proId")+1;
	}
	mysql_free_result($result);
	return $proid;
}
function getparms($userid,$proid){
	$sql="select id from trade_pro_param where userId=$userid and proId=$proid";
	$result=mysql_query($sql);
	$num=mysql_num_rows($result);
	mysql_free_result($result);
	return $num;
}

/*function cleartablestyle($content){
	$content=preg_replace('/<!--\[if gte mso [0-9]\]>(.+?)<!\[endif\]-->/is','',$content); 
	$content=preg_replace('/<!--\[if !mso]>(.+?)<!\[endif\]-->/is','',$content); 
	$content=preg_replace('/<o:[^>]+>([^<]*+)<\/o:[^>]+>/is','\\1',$content); 
	$content=preg_replace('/<st1:[^>]+>([^<]*+)<\/st1:[^>]+>/is','\\1',$content); 
	//$content=preg_replace('/<div[^>]+>(.+?)<\/div>/is','\\1',$content); 
	$content=preg_replace('/<style[^>]+>/is','',$content); 
	$content=preg_replace('/<img(.+?)\/>/is','',$content); 
	$content=preg_replace('/<!--(.+?)-->/is','',$content); 
	$content=preg_replace('/<table[^>]+>/is','<table border=1>',$content); 
	$content=preg_replace('/ (style|width|height|valign|nowrap)=\"[^\"]*+\"/is','',$content); 
	$content=preg_replace('/<meta [^>]+>/is','',$content); 
	$content=preg_replace('/<link [^>]+>/is','',$content); 
	$content=preg_replace('/<o:p>([^<]*+)<\/o:p>/is','\\1',$content); 
	$content=preg_replace('/<(span|a|b)[^>]*+>/is','\\2',$content); 
	$content=preg_replace('/<\/(span|a|b)>/is','',$content); 
	//$content=preg_replace('/\n\r/','',$content); 
	return $content;
}*/

function issubmit($userid){
	$result=mysql_query("select count(*) as counts from trade_trans_list where userId=$userid and finishtime=0");
	$num=mysql_result($result,0,"counts");
	mysql_free_result($result);
	if($num>0){ return true;}else{ return false;}
}
function getmodifyproids($userid){
	$result=mysql_query("select proId from trade_product where userId=$userid and istranslated=0");
	$str="";
	while($rs=mysql_fetch_array($result)){
		$str=$str.$rs['proId'].",";
	}
	if(strlen($str)>0){ return substr($str,0,(strlen($str)-1));}else{ return $str;}
}
function uploadpic($file,$savePath,$str=UPPICNAME){          //上传文件
	$file_name='nopic.gif';
	if(@$_FILES[$file]['name']!='')
	{
	  if($_FILES[$file]['size']<='10242880'){
			$tmp_file=$_FILES[$file]['tmp_name'];
			$file_types=explode(".",$_FILES[$file]['name']);
			$file_type=$file_types[count($file_types)-1];
			if(strtolower($file_type)=="php" || strtolower($file_type)=="exe"){
				  return false;
				  exit;
			}
			$file_name=$str.".".$file_type;
			if(!copy($tmp_file,$savePath.$file_name)){
				 return false;
			}else{			
	 			return $file_name; 
			}
		}else{
		  return false;
		}	
	}else{
	  return $file_name; 
	}
}

function decreasephoto($o_photo,$d_photo,$width,$height){
	$temp_img = imagecreatefromjpeg($o_photo);
	$o_width  = imagesx($temp_img);                                //取得原图宽
	$o_height = imagesy($temp_img);                                //取得原图高
//判断处理方法
	if($width>$o_width || $height>$o_height){        //原图宽或高比规定的尺寸小,进行压缩
		$newwidth=$o_width;
		$newheight=$o_height;
		
		if($o_width>$width){
			$newwidth=$width;
			$newheight=$o_height*$width/$o_width;
		}
		
		if($newheight>$height){
			$newwidth=$newwidth*$height/$newheight;
			$newheight=$height;
		}
		
		//缩略图片
		$new_img = imagecreatetruecolor($newwidth, $newheight);
		imagecopyresampled($new_img, $temp_img, 0, 0, 0, 0, $newwidth, $newheight, $o_width, $o_height);
		imagejpeg($new_img , $d_photo);               
		imagedestroy($new_img);
	}else{                                                                                //原图宽与高都比规定尺寸大,进行压缩后裁剪

		if($o_height*$width/$o_width<$height){        //先确定width与规定相同,如果height比规定大,则ok
			$newwidth=$width;
			$newheight=ceil($o_height*$width/$o_width);
			$x=0;
			$y=ceil(($newheight-$height)/2);
		}else{                                                                        //否则确定height与规定相同,width自适应
			$newwidth=ceil($o_width*$height/$o_height);
			$newheight=$height;
			$x=ceil(($newwidth-$width)/2);
			$y=0;
		}

		//缩略图片
		$new_img = imagecreatetruecolor($newwidth, $newheight);
		imagecopyresampled($new_img, $temp_img, 0, 0, 0, 0, $newwidth, $newheight, $o_width, $o_height);
		imagejpeg($new_img , $d_photo);               
		imagedestroy($new_img);
	
		/*$temp_img = imagecreatefromjpeg($d_photo);
		$o_width  = imagesx($temp_img);                                //取得缩略图宽
		$o_height = imagesy($temp_img);                                //取得缩略图高

		//裁剪图片
		$new_imgx = imagecreatetruecolor($width,$height);
		$bgcolor = imagecolorallocate($new_imgx, 255, 255, 255);
		echo "imagecopyresampled($new_imgx,$temp_img,0,0,$x,$y,$width,$height,$o_width,$o_height);";
		imagecopyresampled($new_imgx,$temp_img,0,0,$x,$y,$width,$height,$o_width,$o_height);
		//imagefill($new_imgx, 0,0, $bgcolor);
		imagejpeg($new_imgx , $d_photo);
		imagedestroy($new_imgx);*/
	}
}
?>                       
                       