<!DOCTYPE HTML>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>DM建站系统</title>
<meta name="description" content="" />
<meta name="keywords" content="" />
<meta name="author" content="DM建站系统 www.demososo.com" />
<meta name="viewport" content="initial-scale=1.0, minimum-scale=1.0, maximum-scale=2.0, user-scalable=no, width=device-width">
<meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible" />
</head>
<body>

<?php 
//echo 'AAAAAAAAAA'.LANG;

if(!dmlogin()){
  echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
  echo '提示：没有登录后台 ';
    //fnoid();
  exit;
}

//编辑静态文本---一般是首页的。
//TPLCURROOT.'data/'.$file'.php'

 //  echo $pidname;
//jttextexist($type,$pidname)
 

  $datafile = jtdatafilexist($pidname,$pidname2);


    //$file_field = $datafile[0];
      $file_cur = $datafile[0];
      $filename_cur = $datafile[1];
      $hascurfile= $datafile[2];


      // if(!is_file($file_field)){
      //   echo '<p class="errorfont">字段文件：......'.substr($file_field,-60).'  not exist</p>';
      //   exit;
      // }
      if(!is_file($file_cur)){
        echo '<p class="errorfont">数据文件：......'.substr($file_cur,-60).'  not exist</p>';
        exit;
      }




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

      // $arr_field = require $file_field; 
            // pre($arr_field);

            
            $arr_data = require $file_cur;
           // pre($arr_data);

           
            if(count($arr_data)==0)  {
              echo 'array length is zero';
              exit;
          }


  

 
$jump = BASEURL.'dmpostform.php?type=editjtmbtext&pidname='.$pidname.'&pidname2='.$pidname2.'&lang='.LANGPATH;



?>



<?php 
   
  
  if($act=='update'){

  		//每年操作前，先备份下。
  	     // copy($file,$filebak);

 
  		 $postarr = $_POST;
  		 $str = '';
       pre($postarr);

       $newarr = [];

       foreach ($postarr as $k => $v) {
           $v = trim($v);

        //  if(substr($k,0,7)=='jttext_') {
        //     $str .= "'$k'=>'".addslashes($v)."',\n";
        //  }
        //  else{
        //     $str .= "'".addslashes($v)."',\n";
        //  }
        $str .= "'$k'=>'".dmjtinput1($v)."',\n";

         //  $str .= "'".dmjtinput1($v)."',\n";
         }
        

        //$str = "<?php return array (".substr($str,0,-1).");";

           $str = "<?php return [".substr($str,0,-1)."];";

 
       //echo $str;
       file_put_contents($file_cur,$str);
        jump($jump);


  		 

  }


  if($act=='copy'){
     // echo 'copy'; 

      $cfilename_cn = 'data_'.$pidname2.'_'.JTTEXTLANG.'.php';
      $cfilename_cur = 'data_'.$pidname2.'_'.LANG.'.php';


       $cfile_cn = BLOCKROOT.'jthome/'.$pidname.'data/'.$cfilename_cn;
       $cfile_cur = BLOCKROOT.'jthome/'.$pidname.'data/'.$cfilename_cur;
       copy($cfile_cn,$cfile_cur);


        jump($jump);

  }
?>



<div class="popeditjttext">
 <div class="hd">编辑文本：</div>
 <p style="color:gray;margin-bottom: 25px">文件：<?php echo $pidname?><?php echo $pidname2?>
 
    &nbsp; &nbsp; &nbsp; &nbsp;   数据： (<?php echo $filename_cur?>)
 &nbsp; &nbsp; &nbsp; &nbsp; 
    <?php 
    if(!$hascurfile){

      $linkcopy = BASEURL.'dmpostform.php?type=editjtmbtext&pidname='.$pidname.'&pidname2='.$pidname2.'&act=copy&lang='.LANGPATH;
 

      echo '<a href="'.$linkcopy.'">复制数据</a>';
    }
    ?>
 </p>
 
<form   action="<?php echo $jump?>&act=update" method="post">
	 
	<?php 
   $i = -1;
		foreach ($arr_data as $k => $v) {

       $i++;
    //  $value = $arr[$k];
		//	$v2 = dmjtinput2($arr[$k]);
      $value = '';

        $datav = '';
      // if(array_key_exists($i,$arr_data))  $datav = $arr_data[$i];
        $datav =  dmjtinput2($v);




      $hd = '';
      $hdstyle = '';

      if(substr($value,0,8)=='##:--##:'){

        $hd = str_replace('##:--##:', '', $value);
        $hd = '<strong>'.$hd.'</strong>';
        $hdstyle = ' style = "display:none"';

      }

       if(substr($value,0,8)=='#:line:#'){
      
        $hd = '<strong>分隔线</strong>';
        $hdstyle = ' style = "display:none"';

      }

      if(is_numeric($k)) {
        $k = $k+1;
        $tit = 'jttext'.$k;
        $namev = $tit;
      }
      else{
         $tit = $k;
         $namev = $k;
      }

      $namev = $k;
      //$namevlabel = $k;

      //if($v<>'') $namevlabel = $k.' <i style="color:gray">('.$v.')</i>';
       


			echo '<div class="popline"><span>'.$namev.' : </span>'.$hd.'<textarea '.$hdstyle.' name="'.$namev.'" cols="80" rows="2">'.$datav.'</textarea></div>';
		}
	?>
	<div class="submit">
    <?php 
        if($hascurfile){
    ?>
		 <button type="submit">编辑</button>
     <?php 
       }
       else{
          echo '<p style="font-size:20px;color:red">不可以编辑，因为这是其他语言的数据，请先点击上面的复制数据再修改。</p>';
       }
       ?>

	</div>


</form>
</div>

<style>
	body{background: #fff}
.popeditjttext {margin:0 auto;width:65%;padding:30px 0;font-size: 12px}
.popeditjttext textarea{width: 100%}
.popeditjttext .hd{font-weight: bold; font-size: 16px}
.popeditjttext .popline{ display: block;margin-bottom:15px;position: relative;padding-left: 120px }
.popeditjttext .popline span{ position: absolute;top:10px;left: 0; }
.popeditjttext .popline strong{font-size: 16px;color:#008ED6;}

.popeditjttext .submit{padding:20px;text-align: center;}
.popeditjttext .submit button{padding:10px 50px;font-size:16px; cursor: pointer;background: #008ED6;color:#fff;border:0;}
.popeditjttext .submit button:hover{background: #067db9}
</style>

</body></html>