<?php
/*  欢迎使用DM企业建站系统，本系统由www.demososo.com开发。
*/
$mod_previ = 'normal';
require_once '../config_a/common.inc2010.php';
//
 if($act <> "pos") zb_insert($_POST);


ifhave_lang(LANG);//TEST if have lang,if no ,then jump

$jumpv = '../mod_module/mod_uploadkv.php?lang='.LANG.'&pidname='.$pidname.'&type='.$type;
 $title='上传图片';

if($type=='nodekv'){
   $table = TABLE_NODE;
     $title='上传kv图片';
     $field='kv';
}
elseif($type=='cate'){
   $table = TABLE_CATE;
    $title='分类描述图片';
   $field='kv';
}

elseif($type=='blockimg'){
   $table = TABLE_BLOCK;
   $field='blockimg';
}
elseif($type=='blockimg2'){
   $table = TABLE_BLOCK;
   $field='blockimg2';
}
elseif($type=='blockimg3'){
   $table = TABLE_BLOCK;
   $field='blockimg3';
}
elseif($type=='blockimg4'){
   $table = TABLE_BLOCK;
   $field='blockimg4';
}
elseif($type=='imgtextkv'){
  $table = TABLE_IMGTEXT;
  $field='kv';
}
elseif($type=='sregion'){ //regionbg not use upload.use namefj.
  $table = TABLE_REGION;
  $field='kv';
}
elseif($type=='menukv'){
	 $table = TABLE_MENU;
}
else{
  echo 'type error';
  exit;
}


$imgsqlname = $imgv2 = $delimg = '';
$sql = "SELECT $field from " . $table . "  where pidname='$pidname' $andlangbh order by id limit 1";
$row =getrow($sql);
if($row<>'no'){
  $addr_cus = $imgsqlname  = $row[$field];

$delimg = '';
$imgv2 = '';

  if($imgsqlname<>''){
      
      $imgv2   = p2030_imgyt($imgsqlname,'y','n'); //p2030_imgyt($addr,$w_h='y',$linkbig='n')
    //del(actgo2,pidname,backpage,title)
      $delimg= "<br /> <a href=javascript:del('delimg','$pidname','$jumpv','')  class='but2'>删除图片</a><br /> <br /> ";
   }





}
else {
  echo 'record error';
  exit;
}




if($act=="update"){

      $imgcus = 'n'; 

      
          $ifwater=@htmlentitdm($_POST['water']);
          if($ifwater=='y') $up_water='y';
          else $up_water='n';
          //-------------


            $imgname=$_FILES["addr"]["name"] ;
            $imgsize=$_FILES["addr"]["size"] ;

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

             //upload img
             $up_small='n';
             $up_add_s='n';//also in common.inc

             $up_delbig='n';
             $i='';


            require('../plugin/upload_img.php');//need get the return value,then upimg part turn to easy.
             // $updateimgaddr=" kv='$return_v'";

                    $ss = "update ".$table." set  $field='$return_v'   where pidname='$pidname'  $andlangbh limit 1";
                    //echo $ss;
                     iquery($ss);

            }//empty($imgname)
            else{

                $imgcus='y';
             // alert('没有上传图片。');
            

            }
         
    
     //if not uplad img,then below step

          if($imgcus=='y'){
                $addr_cus=@htmlentitdm($_POST['addr_cus']);
               $short_add_cus = substr($addr_cus, 0,4);

               $where2 = '';
              if($short_add_cus=='http' || $short_add_cus == 'stat' || $short_add_cus == 'comm' || $short_add_cus == 'uplo') { 
                
                    //begin custom img 
                     $ss = "update ".$table." set  $field='$addr_cus'   where pidname='$pidname'  $andlangbh limit 1";
                      //echo $ss;
                        iquery($ss);

                  }

            
          }

         jump($jumpv);
}

else if($act=='delimg'){

       if(substr($imgsqlname,0,6)<>'common'){
           if($imgsqlname<>'') p2030_delimg($imgsqlname,'y','n');//p2030_delimg($addr,$delbig,$delsmall)

        }
          


       $ss = "update ".$table." set  $field=''   where pidname='$pidname' $andlangbh limit 1";
      iquery($ss);
      jump($jumpv);
    }

  else{
//-----------

require_once HERE_ROOT.'mod_common/tpl_header_iframe.php';

?>




<form   action="<?php echo $jumpv; ?>&act=update" method="post" enctype="multipart/form-data">
  <table class="formtab">
<tr><td class="tr" >
<?php
echo $title;

echo  '<br />'.$delimg;

?>

</td>
      <td>
      <input name="addr" type="file" class="form-control"  />

      <br />
      <?php
      $addr_cus_2 = substr($addr_cus,0,4);
     
      if($addr_cus_2=='http' || $addr_cus_2=='stat' || $addr_cus_2=='comm' || $addr_cus_2=='uplo'){ }
        else{
          echo '<br /><span class="cred">'.$format_t.'</span><br />';
       echo $imgv2;
        }
       
      ?>

      </td>
    </tr>



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

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

 
           $short_add_cus = substr($imgsqlname, 0,4);
          if($short_add_cus=='http' || $short_add_cus == 'stat' ||$short_add_cus == 'comm' || $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 == 'stat' || $short_add_cus == 'comm' || $short_add_cus == 'uplo') { 
        text_cusimg($addr_cus); 
         } 
        ?>
      </td>
    </tr>



<tr>
      <td></td>
      <td>
      <input class="mysubmit" type="submit" name="Submit" value="提交" /></td>
    </tr>



  </table>
</form>





 <?php
require_once HERE_ROOT.'mod_common/tpl_footer_iframe.php';

?>

<?php
  }
?>
