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


  if($curstyle<>$pidname) {
     // echo '<p style="color:red;padding:50px">出错，只有当前正在使用的模板，才可以编辑。</p>';
      //exit;

  }
 

 if(@$_POST['inputmust']=='') {echo $inputmusterror.$backlist;exit;}

 $jump_back = $jumpv_pf.'&act=edit';

  //  $cssdir = ASSETSROOT.$abc2;
     // if(!is_dir($cssdir)) {alert('出错，模板目录 '.$abc2.'不存在！');  jump($jump_back); }

    //$htmldir = WEB_ROOT.'component/html/'.$abc3;
    //  if(!is_dir($htmldir)) {alert('出错，html目录 '.$abc3.'不存在！');  jump($jump_back); }

  // $sql = "SELECT id from ".TABLE_STYLE." where htmldir='$abc2' and pidname<>'$pidname'  limit 1";
  // if(getnum($sql)>0){
    //  alert('出错，模板目录 '.$abc2.' 已使用。(包括其他语言)');
     //  jump($jump_back);

     // exit;
   //}





   $sql = "SELECT kv from ".TABLE_STYLE." where pidname='$pidname'  $andlangbh   limit 1";
                           $row = getrow($sql);
                           $imgsqlname =$row['kv'];

       $delimg = zbdesp_onlyinsert($_POST['delimg']);
    if($delimg=='y'){
        if($imgsqlname<>'') p2030_delimg($imgsqlname,'y','y');
        $kv_v = ",kv = ''";
    }
    else{

         $imgname = $_FILES["addr"]["name"];
       $imgsize = $_FILES["addr"]["size"];
       if (!empty($imgname)) {
           $imgtype = gl_imgtype($imgname);
           $up_small = 'n';
           $up_delbig = 'n';
           $up_water = 'n';
           $i = '';
           require_once('../plugin/upload_img.php'); //need get the return value,then upimg part turn to easy.
           $kv_v = ",kv = '$return_v'";
       }
       else  $kv_v = "";

    }

 $arrcanexcerpt =  array("title","htmldir", "addcss","addjs","delimg");  //move top line

    $bscnt22 = '';
    if(count($_POST)>1){
            foreach ($_POST as  $k=>$v) {
               if(strtolower($k)=='submit') break;if(strtolower($k)=='inputmust') break;
              if(in_array($k,$arrcanexcerpt))   continue;

              $bscnt22 .= $k.':##'.htmlentitdm(trim($v)).'==#==';

            }
        }
         $bscnt22 = substr($bscnt22,0,-5);

        // echo $bscnt22;exit;

 
    //$addDMcssjs =  htmlentitdm(@$_POST['addDMcssjs']); --no use
    $addcss =  htmlentitdm(@$_POST['addcss']);
    $addcss=str_replace("\\","/",$addcss);
    $addcss=str_replace(chr(13),"|",$addcss);
    $addcss=str_replace(chr(32),"",$addcss);

    $addjs =  htmlentitdm(@$_POST['addjs']);
    $addjs=str_replace("\\","/",$addjs);
    $addjs=str_replace(chr(13),"|",$addjs);
    $addjs=str_replace(chr(32),"",$addjs);

  //$ss = "update ".TABLE_STYLE." set title='$abc1',htmldir='$abc2',pidmenu='$abc3',pidregion='$abc4',pidregionmobile='$abc5',addcss='$addcss',addjs='$addjs',header_pc='$header_pc',header_mobile='$header_mobile',skincss='$skincss' $kv_v where pidname='$pidname' $andlangbh limit 1";
 $ss = "update ".TABLE_STYLE." set title='$abc1',htmldir='$abc2',style_blockid='$bscnt22',addcss='$addcss',addjs='$addjs' $kv_v where pidname='$pidname' $andlangbh limit 1";

   //echo $ss;exit;
   iquery($ss);


   jump($jump_back);


}
else{
  $sql = "SELECT * from ".TABLE_STYLE."  where  pidname='$pidname' $andlangbh   order by id limit 1";
$row = getrow($sql);
//pre($row);
$title=$row['title'];$htmldir=$row['htmldir'];
$kv=$row['kv'];
 
 //$imgsmall2 = p2030_imgyt($kv, 'y', 'n');
$imgsmall2 = '<img src='.get_img($kv, '', '').' alt=""  height="200" />';


$addcss=$row['addcss'];
$addcss=str_replace("|",chr(13),$addcss);
$addjs=$row['addjs'];
$addjs=str_replace("|",chr(13),$addjs);



$style_blockid=$row['style_blockid'];
 //pre($style_blockid);
$bsheaderlogomobi= $header_pc = $header_mobi = $color = $mbhome = $mbhomemob = $addcssjs_h = $addcssjs_f =  '';
$mbbannerhome = $mbbannerhome_img = $mbbannerhome_img = $mbbannercomm = $mbbannercomm_img = '';
$mbbzimg1 = $mbbzimg2 = $mbbzimg3 = $mbbzimg4 = $mbbzimg5 = '';
$mbbz1 = $mbbz2 = $mbbz3 = $mbbz4 = $mbbz5 = $mbbz6 = $mbbz7 = '';
$mbbz8 = $mbbz9 = $mbbz10 = $mbbz11 = $mbbz12 = $mbbz13 = $mbbz14 = $mbbz15 = '';
$bssidebar = '';
$bannerhidetitle = 'n';


    $bscntarr = explode('==#==',$style_blockid);

     if(count($bscntarr)>1){
        foreach ($bscntarr as   $bsvalue) {
           $bsvaluearr = explode(':##',$bsvalue);
           $bsccc = $bsvaluearr[0];
           $$bsccc=$bsvaluearr[1];
        }
    }


$jsname = jsdelname($title);

$jumpv_insert = $jumpv_pf.'&act=update';

?>


<?php 
//if($curstyle<>$pidname){?>
<div class="contenttop">
<a href="javascript:del('del','<?php echo $pidname;?>','mod_style.php?lang=<?php echo LANG;?>','<?php echo $jsname;?>')" class="fr but2"><i class="fa fa-trash-o"></i> 删除</a>
</div>
<?php
// }
 ?>


<form  onsubmit="javascript:return checkhere(this)" action="<?php echo $jumpv_insert;?>" method="post" enctype="multipart/form-data">
  <table class="formtab">

      <tr>
      <td width="20%"  class="tr">模板标题：</td>
      <td > <input name="title" type="text"  value="<?php echo $title;?>" class="form-control" /> </td>
    </tr>

   <tr>
      <td class="tr">模板目录：</td>
      <td>
   <select name="htmldir" class="form-control">
         <option value="">请选择</option>
<?php
$arrtpltemplateroot = dmgetDir(TEMPLATEROOT);
//pre($arrtpltemplateroot);
foreach ($arrtpltemplateroot as $k => $v) {
  if($v<>'base'){

   // $sql = "SELECT id from ".TABLE_STYLE." where  pidname<>'$pidname' and  htmldir='$v' limit 1";
   // if(getnum($sql)==0) {
      $htmldirv = '';
      if($v==$htmldir) $htmldirv ='selected="selected"';
      echo '<option '.$htmldirv.' value="'.$v.'">'.$v.'</option>';

   // }


}
}
     ?>
</select>
        </td>
    </tr>
 <tr>

  <tr>
      <td  width="20%" class="tr">网站LOGO ：
<br />
请先在右上角的<span  style="color:blue">媒体标识>名称附件</span>里上传图片。
      </td>
      <td  width="70%">


 <div class="c5"></div>

      pc端LOGO： <input name="bsheaderlogo" type="text"  value="<?php echo $bsheaderlogo;?>" size="30" />
       <?php echo $xz_must;?>
       <?php echo check_blockid($bsheaderlogo);?>
 <div class="c5"></div>
  移动端LOGO： <input name="bsheaderlogomobi" type="text"  value="<?php echo $bsheaderlogomobi;?>" size="30" />
       <?php echo $xz_maybe;?>
       <?php echo check_blockid($bsheaderlogomobi);?>
  <div class="c15"></div>
  </td>
    </tr>

 <tr>
      <td width="20%"  class="tr"><span class="strongtext"  style="background:#6b992f">首页内容：</span>
        <br />
        <a  target="_blank" href="../mod_region/mod_mainregion.php?lang=<?php echo LANG?>&ppid=common">页面区域</a>
        <br />
<span class="cgray">  
 参考： block/home
</span>

      </td>
      <td > 
      pc端：<input name="mbhome" type="text"  value="<?php echo $mbhome;?>" size="35"  />

      <?php  
      check_blockid_myprog($mbhome); 
      ?>
      <div class="c5"> </div>
      移动端：<input name="mbhomemob" type="text"  value="<?php echo $mbhomemob;?>" size="35"   />
     
      <div class="c5"></div> 
      <span class="cgray">如果移动端为空，则会使用pc端。</span>

       <?php  
      check_blockid_myprog($mbhomemob); 
      ?>
      
       </td>
    </tr>


<?php 
  require 'plugin_style_header.php';
?>

<?php 
  require 'plugin_style_menu.php';
?>
<?php 
  require 'plugin_style_banner.php';
?>


 <tr>
      <td  width="20%" class="tr">侧边栏内容：</td>
      <td style="padding: 15px 5px">

 <input name="bssidebar" type="text"  value="<?php echo $bssidebar;?>" size="30" />
<?php  
    echo    check_blockid($bssidebar); 
      ?>
   </td>
 </tr>


 <tr>
      <td  width="20%" class="tr">
       <span class="strongtext"> 底部内容：</span>
          <br />
<span class="cgray">参考： 
 block/footer
</span>
</td>
      <td style="padding: 15px 5px">

pc端：<input name="bsfooter" type="text"  value="<?php echo $bsfooter;?>" size="30" />
<?php  
     echo  check_blockid($bsfooter); 
      ?>
       
 <div class="c5"></div>

 移动端：<input name="bsfootermob" type="text"  value="<?php echo $bsfootermob;?>" size="30" />
       <?php echo $xz_maybe;?>
       <?php  
     echo  check_blockid($bsfootermob); 
      ?>
        

  </td>
</tr>
 




  <tr>
      <td  width="20%" class="tr">404区块的标识：</td>
      <td  width="70%">
      <input name="bsblock404" type="text"  value="<?php echo $bsblock404;?>" size="30" />
      <?php echo $xz_must;?>
       <?php echo check_blockid($bsblock404);?>

  </td>
    </tr>

      <tr>
      <td  width="20%" class="tr">网站浮动部分(FooterLast)：</td>
      <td  width="70%">

  <input name="bsfooterlast" type="text"  value="<?php echo $bsfooterlast;?>" size="30" />
      <?php echo $xz_maybe;?>
   <?php echo check_blockid($bsfooterlast);?>
    <br /> <span class="cgray">（比如浮窗咨询等）</span>
  </td>
    </tr>
    


 <tr>
  <td  class="tr">备注：</td>
    <td >
    
         文字1：<input name="mbbz1" type="text"  value="<?php echo $mbbz1; ?>" size="100" />(mbbz1) <?php echo $xz_maybe; ?>
            <div class="c5"></div>
         文字2：<input name="mbbz2" type="text"  value="<?php echo $mbbz2; ?>" size="100" />  <?php echo $xz_maybe; ?>
          <div class="c5"></div>
         文字3：<input name="mbbz3" type="text"  value="<?php echo $mbbz3; ?>" size="100" /> <?php echo $xz_maybe; ?>
            <div class="c5"></div>
         文字4：<input name="mbbz4" type="text"  value="<?php echo $mbbz4; ?>" size="100" /> <?php echo $xz_maybe; ?>
            <div class="c5"></div>
         文字5：<input name="mbbz5" type="text"  value="<?php echo $mbbz5; ?>" size="100" /> <?php echo $xz_maybe; ?>
            <div class="c5"></div>
         文字6：<input name="mbbz6" type="text"  value="<?php echo $mbbz6; ?>" size="100" /> <?php echo $xz_maybe; ?>
            <div class="c5"></div>
         文字7：<input name="mbbz7" type="text"  value="<?php echo $mbbz7; ?>" size="100" /> <?php echo $xz_maybe; ?>
            <div class="c5"></div>
         文字8：<input name="mbbz8" type="text"  value="<?php echo $mbbz8; ?>" size="100" /> <?php echo $xz_maybe; ?>
      
            <div class="c5"></div>
        </td>
   </tr>

<?php 
  require 'plugin_style_addcssjs.php';

  //plugin_style_addcssjs 会用在region里，所以下面的cssjs分开来。因为region里不要下面这个。
?>

    <tr>
  <td  class="tr">添加cssjs：
    <br />
     <span class="cgray">这里是php文件</span>
</td>
            <td  >
         放在头部：<input name="php_cssjs_h" type="text"  value="<?php echo $php_cssjs_h; ?>" size="50" />
          <?php echo $xz_maybe; ?>
          <?php 
            if($php_cssjs_h<>'') echo    check_blockid($php_cssjs_h);  
          ?>
            <div class="c5"></div>
         放在底部：<input name="php_cssjs_f" type="text"  value="<?php echo $php_cssjs_f; ?>" size="50" /> 
          <?php echo $xz_maybe; ?>
           <?php 
            if($php_cssjs_f<>'') echo    check_blockid($php_cssjs_f);  
          ?>
          <div class="c5"></div>
         
        </td>
   </tr>


 
    <tr>
            <td   class="tr">图片：</td>
            <td style="padding-top:25px"> <input name="addr" type="file" id="addr"  /><?php echo $xz_maybe;?>
<?php
echo '<br /><span class="cred">' . $format_t . '</span><br />';
// echo gl_showsmallimg($fo_bef,$imgsmall,'y');
   if($kv<>'')    echo $imgsmall2;
?>

    <?php  if($kv<>'')    {
              ?>
          <span class="cred"> <br />是否要删除图片？ </span>
          <select name="delimg">
    <?php select_from_arr($arr_yn,'n','');?>
     </select>
          <?php }
          else{ //use for : Undefined index: delimg
              ?>
          <select name="delimg" style="display:none" class="form-control">
              <option value=""></option>
     </select>
          <?php
          }?>

              <br />  <br />
</td></tr>



  <tr>
      <td></td>
      <td>
      <input  class="mysubmit" type="submit" name="Submit" value="提交" /></td>
    </tr>
    </table>
<?php echo $inputmust;?>

</form>
<?php }
?>

<style type="text/css">
  .strongtext { font-weight: 500; 
    display: inline-block;padding:5px 10px;background: #3f85b9;
    color:#fff } 

</style>


<script>
function checkhere(thisForm) { 

   if (thisForm.title.value=="")
  {
    alert("请输入标题。");
    thisForm.title.focus();
    return (false);
  }

     if (thisForm.htmldir.value=="")
  {
    alert("请选择模板目录。");
    thisForm.htmldir.focus();
    return (false);
  }

  
 



}

</script>

  <?php
        function check_blockid_myprog($biaoshi){
          global $htmldir;
          if($biaoshi<>'') {
          
                 if(substr($biaoshi,0,4)=='mypr') {

                      $htmldir2= TEMPLATEROOT.$htmldir.'/selfblock/myprog/'.$biaoshi.'.php';
                    // echo $htmldir2;
                      checkfile($htmldir2);
                 }  else  echo  check_blockid($biaoshi);
               }

        }

      ?>