<?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 =  '';

    $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 = getDir(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>
      <td width="20%"  class="tr">首页内容：
<br />
<a  target="_blank" href="../mod_region/mod_mainregion.php?lang=<?php echo LANG?>&ppid=common">页面区域</a>
      </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"   />
      <p class="cgray">移动端为空，则会使用pc端。</p>
       <?php  
      check_blockid_myprog($mbhomemob); 
      ?>
      
       </td>
    </tr>



 <?php
 require_once HERE_ROOT.'mod_style/plugin_layout_hf.php'; 
  
?>

 

<tr>
  <td  class="tr">备注：</td>
            <td  >
         备注1：<input name="mbbz1" type="text"  value="<?php echo $mbbz1; ?>" size="50" /> <?php echo $xz_maybe; ?>
            <div class="c5"></div>
         备注2：<input name="mbbz2" type="text"  value="<?php echo $mbbz2; ?>" size="50" />  <?php echo $xz_maybe; ?>
          <div class="c5"></div>
         备注3：<input name="mbbz3" type="text"  value="<?php echo $mbbz3; ?>" size="50" /> <?php echo $xz_maybe; ?>
        </td>
   </tr>
 <?php
  require_once HERE_ROOT.'mod_style/plugin_style_blockid.php';

   require_once HERE_ROOT.'mod_style/plugin_style_addcssjs_file.php'; //plugin_style_addcssjs use in region
?>
    <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 }
?>
<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);
               }

        }

      ?>