<?php
/*
	power by JASON.ZHANG  DM建站  www.demososo.com
*/
if(!defined('IN_DEMOSOSO')) {
	exit('this is wrong page,please back to homepage');
}
?>
 <?php
 //设置一次可以拖上传图片的个数
 $imgnum = 20; 
 
 $jumpv = 'mod_imgmanager.php?'.$_SERVER['QUERY_STRING'];
$jumpvdel = 'mod_imgmanager_ajax.php?'.$_SERVER['QUERY_STRING'].'&act=del';
 
 //$storeFolder = UPLOADROOTIMAGE;
   //if(!is_dir($storeFolder)) mkdir($storeFolder);
						//{
							// alert('出错，保存文件的目录不存在。');
							// exit;
						//}
 
 
 if($act=='insert'){ 
		if (!empty($_FILES)) {
			
			$imgname=$_FILES["file"]["name"] ;
	        $imgsize=$_FILES["file"]["size"] ; 
			$imgtype = gl_imgtype($imgname);
			
			$ifwater=@htmlentitdm($_POST['water']);

			 if($ifwater=='y') $up_water='y'; 
			  else $up_water='n';
			
			  if(!in_array($imgtype,$attach_img))  $up_water='n';//docx,ppt not water
				//-------------------
			 
			   if(!in_array($imgtype,$attach_type)) 
					  {
					     alert('出错，格式不支持。');echo $backlist;exit;
					  }
			  if($attach_size<$imgsize)
					   {
					    alert('出错，文件超出允许的大小。');echo $backlist;exit;
					   }
					  //echo UPLOADROOTIMAGE;
					 
			
	
			 $tempFile = $_FILES['file']['tmp_name'];  
			
			 $targetFile = date("Ymd_His").'_'.rand(1000,9999).'.'.$imgtype; 
		 	$targetFile2 = UPLOADROOTIMAGE.$targetFile; 
		 	move_uploaded_file($tempFile,$targetFile2);  
			 
			$ss = "insert into ".TABLE_IMGFJ." (pbh,pid,lang,title,kv) values ('$user2510','$pid','".LANG."','','$targetFile')";//no pos,because pos is auto,is to next and prev page
			//echo $ss;exit;

			iquery($ss);

		//	$waterimgv= UPLOADROOTIMAGE.$waterimg; //move to inc.php
			if($up_water=='y') {  
				$imgdate2 = $targetFile2;
				 if($waterimg<>'')  {     
					require("../plugin/upload_water.php");   
					//if(is_file($waterimgv))  require("../plugin/upload_water.php");
					///else { echo '水印图片不存在';exit;}
				 }
				}  

			//----------------------	

		 
		}
	 

 }

 else if($act=='pos') {
 
    dmnodepos($_POST,TABLE_IMGFJ);
    $jumpv=str_replace("&act=pos",'',$jumpv);	
	  
	  jump($jumpv);



 }
 else if($act=='del') {
	 //move to ajax.php
   // pre($_POST);
  //  exit;
	 
	   
	 if(isset($_POST['content']))  {
		 
		  $content = $_POST['content'];
		  $arr = explode('===', $content);
		  unset($arr[0]);
		  pre($arr);
		  foreach($arr as $v){
		  	$v  = htmlentitdm($v);
			   $postarr = explode('=',$v);
			   $tid = $postarr[0];
			   $img = $postarr[1];
			 $imgv = UPLOADROOTIMAGE.$img;
		//	 echo $imgv.'<br>';
				
			//unlinkdm($imgv);

			 $ss = "delete from ".TABLE_IMGFJ." where id=$tid  ". ANDLANGBH ." limit 1";
			// echo $ss.'<br>';
		 //	iquery($ss);
				
		  }
		  
	 }
	 else {
		 alert('请先勾选要删除的图片。');
		  
	 }

    
     //$jumpv=str_replace("&act=del",'',$jumpv);	
	  
	//  jump($jumpv);
	 
 }
 
 
 else {
	 
	 

 ?>
 

<link href="<?php echo STAPATH?>assets/vendor/dropzone/dropzone.css" rel="stylesheet">
<style>
	.wrapuploadimg {margin-bottom: 10px}
.dropzone{text-align:center} .wrapuploadimg .sending{text-align:center;padding:20px;font-size:18px;color:blue}
.dropzone .dz-message{text-align: center;width:500px;height: 100px; line-height:100px;border:3px dashed #0088cc;background: white; margin:20px auto;}
.dropzone .dz-message h3{font-size:20px;}
.upimglist .img{width:120px;height:150px;float:left;margin:15px;position:relative;border:1px solid #e2e2e2}
.upimglist .img img{width:100px;height:100px}
.upimglist .checkbox{ position:absolute;width:20px;height:20px;top:-5px;left:0}
.upimglist .view{ position:absolute; top:-5px;right:0;color:#fff }
.upimglist .view i{font-size:25px}
.checkbutton  {margin-bottom:30px;border-top:1px solid #ccc;padding:10px}
.checkbutton span{display:inline-block;padding:5px 15px;cursor:pointer;margin:0 10px;background:#0088cc;border-radius:10px;color:#fff}
.checktrash{position:absolute;font-size:22px;color:red;left:2px;top:20px;display:none}


@media screen and (max-width:600px) {
	.dropzone .dz-message{  width:90% }
		
}

</style>
 <div class="wrapuploadimg">
  <form id="imageDropzone" method="post" action="<?php echo $jumpv?>&act=insert" enctype="multipart/form-data" class="dropzone">
        <div class="dz-message">
        
        <h3>拖动文件或图片到这里......		 
		<p class="cred">(<?php
 echo $format_t;
?>)</p>
        </div>

		<input type="checkbox" id="water"   name="water"   value="y"  checked="checked"   size="10"> <label for="water">加上水印</label>
		<!--
		 <input type="file"   name="file" />
		 
		 <input type="submit" value="add" />
		 -->
    </form>
	<h1 class="sending dn">上传中......</h1>
</div>	

<div class="upimglist">
<form  method="post" action="<?php echo $jumpv?>&act=pos" class="dropzone">
	<div class="imglist">
 <?php 
     
	  $sqlall = "SELECT * from ".TABLE_IMGFJ." where pid='$pid'  $andlangbh order by pos desc,id desc";
	  
	  $sqlnum = getnum($sqlall);

	  if($sqlnum>0) {
		$rowall = getall($sqlall);
		  foreach ($rowall as $v){
			  
			  $addr_cus = $imgname = $v['kv'];

			$img = UPLOADPATHIMAGE.$imgname;  

		  $imgroot = UPLOADROOTIMAGE.$v['kv'];  

		  $tid= $v['id'];

		  $tidv= $tid.'='.$imgname;


		  $imgtype = gl_imgtype($imgname);
		 

		  ?>
		  
		  <div class="img">
  
		 
		  <input type="checkbox" class="checkbox" value="<?php echo $tidv?>" name="checkimg[]"  />
		   <i class="fa fa-trash-o checktrash" aria-hidden="true"></i>
		 
		   <a class="view  needpopup" href="mod_imgshow.php?act=show&lang=<?php echo LANG?>&tid=<?php echo $tid?>" ><i class="fa fa-edit" aria-hidden="true" style="color:#0088cc;"></i></a>

		  <?php

		      if(substr($addr_cus,0,7)== 'upload/'){
              $bgimgroot = STAROOT.$addr_cus;
              $bgimgpath = STAPATH.$addr_cus;
              if(is_file($bgimgroot)){
               echo p2030_imgyt($bgimgpath,'y','n');
              }       
          }   
                          
          else if(substr($addr_cus,0,4)== 'http'){
             // echo 'http站内或站外图片';
            echo p2030_imgyt($addr_cus,'y','n');                    
          } 

          else if(is_file($imgroot)){
              //old img ,then not each.    
              echo p2030_imgyt($addr_cus,'y','n');                          
          }  
           else{
            
            echo '<p class="cred"> 自定义图片的内容不对。</p>';
          }
?>

    <p>
		  <input type="text" name="<?php echo $tid;?>"  value="<?php echo $v['pos'];?>" size="5" />
		</p>  

		  </div>
		  
	<?php	  
	  }

	 
	}
 ?>
 <div class="c"> </div>
</div>
 <div class="c" style="padding:15px;text-align:left"> 

 <?php 
  if($sqlnum>0) {
 ?>


<p style="padding:10px 0">
<input type="submit"  class="mysubmit" value="排序" />
</p>


  <div class="c checkbutton"> 
  
  <span class="checkall">全选</span>
  <span class="checkallfan">反选</span>
   <span class="imgdel" style="background: #FF9935">删除</span>
  </div>

 

 <div class="imgeditcode">
   <p class="cgray">以下代码用于复制到编辑器：</p>
 	<textarea cols="111" rows="6"><?php

			foreach ($rowall as   $v) {

					 $imgname = $v['kv'];

					 if(substr($imgname,0,4)=='http') {
					 	$img = $imgname;
					 }
					 else if(substr($imgname,0,4)=='uplo') {
					 	$img = STAPATH.$imgname;
					 }
					 else{
					 	$img = UPLOADPATHIMAGE.$imgname; 
					 } 

				echo '<p><img src="'.$img.'" alt="img" /></p>';
				 
			}
	?>
 </textarea>
</div>



  <?php 
 }
 else {
	 echo '<p class="tc">暂无图片</p>';
 }
 ?>
 </div>
</form>







</div>
	 <script src="<?php echo STAPATH?>assets/vendor/dropzone/dropzone.js" type="text/javascript"></script>
<script type="text/javascript">
  Dropzone.autoDiscover = false;
  var dropzone1 = new Dropzone('#imageDropzone', {
          maxFiles:<?php echo $imgnum;?>,
          forceFallbacks:true,
          autoDiscover:false,
          createImageThumbnails:false,
	 
			      
			   
          init:function(){
              this.on("sending",function (file,response){
                $('.sending').show();
             });
			  this.on("success",function (file,response){
                $('.sending').hide();
				 
				setTimeout(function(){ 
                		//alert(2);
					    window.location.href='<?php echo $jumpv;?>';
					 }, 2000);


             });
          }
     });
	 
	 
	  
	 
	   // Helper function to get parameters from the query string.
        function getUrlParam( paramName ) {
            var reParam = new RegExp( '(?:[\?&]|&)' + paramName + '=([^&]+)', 'i' );
            var match = window.location.search.match( reParam );

            return ( match && match.length > 1 ) ? match[1] : null;
        }
        // Simulate user action of selecting a file to be returned to CKEditor.
        function returnFileUrl(v) {

            var funcNum = getUrlParam( 'CKEditorFuncNum' );
            var fileUrl = v;
            window.opener.CKEDITOR.tools.callFunction( funcNum, fileUrl );
            window.close();
        }
		
	$('.upimglist img').click(function(){
		  $src = $(this).attr('src');
		  returnFileUrl($src);
		
		
	});	
</script>

<script>
$(function(){


//----------------------------------
$('.imglist .checkbox').click(function(){	 	 
	if($(this).is(':checked'))  $(this).next().show();
	else $(this).next().hide();
		
});	

	$('.checkall').click(function(){		 
			$(".imglist input[type='checkbox']").each(function(){
				$(this).prop('checked',true);
				$(this).next().show();

			});		
	});	
//-----------------------------
$('.checkallfan').click(function(){		 
		 $(".imglist input[type='checkbox']").each(function(){
			 if($(this).is(':checked')) {
				 $(this).removeAttr('checked',false);
				 $(this).next().hide();
			 }
			 else {
				 $(this).prop('checked',true);
				 $(this).next().show();
			 }
			
		 }); 
 });	
//-----------------------------
 //-----------------------------
$('.pop_jsdo').click(function(){		 
		 var delvalue = '';
    	$(".imglist input[type='checkbox']:checked").each(function(){
            delvalue = delvalue + '===' + $(this).val(); 
		 });

    	//alert(delvalue)
    	//------------ajax----
    	 jQuery.ajax({
				type: 'POST',
				url: '<?php echo $jumpvdel?>',
				dataType: "json",
				data: {
					content: delvalue 
				},
				success: function(data) {
					//console.log(data);
					window.location.reload();
		 
				}
			});
 });	


//-----------------------------
$('.imgdel').click(function(){	
	 var len =  $(".imglist input[type='checkbox']:checked").length;
    if(len>0){
    	popupconfirm2('','jsdo');
    	return false;
    	

    	//-------------
    }else{
    	popupconfirm2('请先勾选要删除的图片。',''); 
    }
    
		  
 });	
//-----------------------------
 
 


})//end ready.......
 </script>
 
 

<?php
 }
 
?>


 