<?php
/*
	power by JASON.ZHANG  DM建站  www.demososo.com
*/
if(!defined('IN_DEMOSOSO')) {
	exit('this is wrong page,please back to homepage');
}

?>
<h2 style="font-size: 14px">私有编辑器附件</h2>
<?
if($act=='update'){
	 $imgcus = 'n'; 

	 $upcommonimg = 'y';


    $imgname=$_FILES["addr"]["name"] ;
			$imgsize=$_FILES["addr"]["size"] ;
			   $ifwater=@htmlentitdm($_POST['water']);
			    $titlehere=@htmlentitdm($_POST['title']);

			   // pre($_POST); 
 
		if(!empty($imgname)){
			$imgtype = gl_imgtype($imgname);

			$oldimgtype = 	gl_imgtype($imgsqlname);	

			if(in_array($imgtype,$attach_img) && in_array($oldimgtype,$attach_img) ) { }
		    else {
		    	if($imgtype<>$oldimgtype){
		    		alert('出错，文件扩展名不同');
					jump($jumpv.'&act=show');
		    	}
		    }		
			//
			//$up_water='y';	
			//$up_water='y';	//water value is in inc_logcheck.php of lang talbe

		 
				
				if($ifwater=='y') $up_water='y';
				else $up_water='n';

		  if(!in_array($imgtype,$attach_img))  $up_water='n';//docx,ppt not water
			
			//-------------
			$up_small='n';
			$up_delbig='n'; 
			$i='';		

			//$imgsqlname='';//alway change img name,because the kv img
			//echo $imgsqlname;
			require_once('../plugin/upload_img.php');//need get the return value,then upimg part turn to easy.

			  $andlangbh="  and pbh='".USERBH."' ";
			 // $return_v = 'common/'.$return_v;  // common is added in upload_img.php
			 $ss = "update ".TABLE_IMGFJ." set kv='$return_v' where   id='$tid' $andlangbh  limit 1";  
             iquery($ss);  
            //echo '<br />'.$ss; 
		 
		
	}//end not empty
	 else{
         $imgcus='y';
             // alert('没有上传图片。');

	            $addr_cus=@htmlentitdm($_POST['addr_cus']);
	               $short_add_cus = substr($addr_cus, 0,4);
	              if($short_add_cus=='http' || $short_add_cus == 'uplo') {  } 
	                else {
	                  alert('自定义图片格式不对'.$short_add_cus);
	                  jump($jumpv);
	                } 

       }



         if($imgcus=='y'){

                $imgcusok = 'n';
                $editsql = 'n';
                //$addr_cus=@htmlentitdm($_POST['addr_cus']);
                $addr_old=@htmlentitdm($_POST['addr_old']);
                $addr_cus_2 = substr($addr_cus,0,4);
                 
                if($addr_cus_2=='http' || $addr_cus_2=='zsta' || $addr_cus_2=='uplo'){
                   $imgcusok = 'y';
                 }

                  $imgtype = gl_imgtype($addr_cus); 
                 if(!in_array($imgtype,$attach_type))    { 
                       alert('扩展名不符合格式。');  
                        $imgcusok = 'n';
                                  
                 }

   
                   
                  if($imgcusok == 'y' && $addr_cus<>$addr_old){ 

                    $imgsmallroot=UPLOADROOT.'image/'.$addr_old; 
                    echo $imgsmallroot;

                     if(is_file($imgsmallroot))   unlinkdm($imgsmallroot);

                    //begin custom img  
                     $andlangbh="  and pbh='".USERBH."' ";
                     $ss = "update ".TABLE_IMGFJ." set kv='$addr_cus' where   id='$tid' $andlangbh  limit 1";  
                     iquery($ss);   
                  }
                  //echo $ss;
                 
            
          } 
 
	  jump($jumpv.'&act=show');


    
}

 
if($act=='show'){


 
 echo '<div class="tc">';

  $addr_cus = $imgsqlname;
 
 $v=UPLOADPATH.'image/'.$imgsqlname;

 $vrand = $v.'?v='.rand(1111,9999);

 $vroot = UPLOADROOT.'image/'.$imgsqlname;
 if(!is_file($vroot)) {
 //echo '文件不存在 - '.$imgsqlname;
 //exit;
}

 $imgtype = gl_imgtype($imgsqlname);


 //echo '<div style="padding:10px;margin:10px;border:1px dashed #e2e2e2">'.$v.'</div>';

?>
<div class="tc" style="padding:10px;margin:10px;border:1px dashed #e2e2e2">
<form action="<?php echo $jumpv; ?>&act=update" method="post" enctype="multipart/form-data">
  <table class="formtab">
  	<tr>
      <td class="tr" width="25%">  上传图片和附件：</td>
		<td  width="70%">
			<input name="addr" size="35" style="display:inline-block" type="file"  />
			<p class="cred">(<?php
					echo $format_t;
					?>)</p>
				 
				 <?php 
				  echo p2030_imgyt($imgsqlname,'y','n');  

				  ?>
		   <input type="checkbox" name="water" id="water"  value="y" checked="checked"   size="10"> <label for="water">加上水印</label>
	       <div class="c5"> </div>
	  </td> 
	</tr> 

	  <tr>
      <td class="tr">  自定义图片和附件：</td>
      <td>
      <?php 
 
$disable =  '';
$custext = '';
  //echo $imgsqlname;
if($imgsqlname<>'') {

 
           $short_add_cus = substr($imgsqlname, 0,4);
          if($short_add_cus=='http' || $short_add_cus == 'uplo') {  } 
            else {
                $disable = "disabled";
                 $custext = '如果要自定义图片，请先删除上面上传的图片。<br />';
            } 

  

}

?>
<input name="addr_cus" <?php echo $disable?> type="text" value="<?php echo $addr_cus?>" class="form-control"  />
     
        <p><?php echo $custext;?>自定义图片的格式：http或https或upload开头 </p>
        <?php 

        if($short_add_cus=='http' || $short_add_cus == 'uplo') { 
        text_cusimg($addr_cus); 
         } 
        
        ?>
      </td>
    </tr>

  <tr>
      <td class="tr">   </td>
      <td> 
	   <input  class="mysubmit" type="submit" name="Submit" value="<?php echo '修改';?>">
	    </td>
    </tr>
</table>

</form>
</div>
<?php
 
 
 echo '</div>';

}
 
?>