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


if($tid<>'') {ifhasid(TABLE_BLOCK,$tid);}
$typecur = $type;
if($act=='add') {

    if($ppid=='') {
      echo 'must have ppid.';exit;
    }
    
   $typearr =  array("bkcustom", "bknode", "bkblockdh");   
     if(!in_array($type,$typearr))   {echo 'type is error.';exit;}
   
}

if($ppid=='all' || $ppid=='alledit'){

}else { 
          if($act=='edit' || $act=='update'){
                $sqlsub = "SELECT * from ".TABLE_BLOCK."  where pidname='$pidname' $andlangbh order by id limit 1";
                //echo $sqlsub;exit;
              $rowsub = getrow($sqlsub);
              if($rowsub=='no')  { echo 'no block id by pidname'; exit; }
              else{
                $ppid = $rowsub['pidstylebh'];
                $typecur = $rowsub['pid'];
              }
          }
  }        

  $iscurstyle = 'n';
 
  if(ifhaspidname2(TABLE_STYLE,$ppid))  $iscurstyle = 'y';

 
$ppid7 = substr($ppid,0,7);
  if($ppid7 =='jtblock'){ 
  $dir = BLOCKROOT.'jtblock/'.$ppid;
      if(!is_dir($dir)) {
        echo 'ppid folder is wrong...';exit;    
      }  
}
else if($ppid7 =='jthome_'){ 
  $dir = BLOCKROOT.'jthome/'.$ppid;
      if(!is_dir($dir)) {
        echo 'ppid folder is wrong...';exit;    
      }  
}
else if($ppid7 =='mbhome_'){ 
  $dir = TPLCURROOT.'selfblock/mbhome/'.$ppid;
      if(!is_dir($dir)) {
        echo 'ppid folder is wrong...';exit;    
      }  
}
else if($ppid =='all' || $ppid =='alledit' || $iscurstyle=='y'){  }
else {
  echo 'ppid is wrong...';exit;

}




/*
if (!in_array($type,$arr_group_type))
  {
  echo "error,type:".$type.' not exist...... in array:arr_group_type' ;
  exit;
  }
*/

 
//ifhaspidname(TABLE_NODE,$pid);
//ifhaspidname(TABLE_CATE,$catpid);
ifhave_lang(LANG);//TEST if have lang,if no ,then jump
 $menuactive_block = 'nav-active';

$jumpv='mod_block.php?lang='.LANG;
$jumpvp=$jumpv.'&pidname='.$pidname;
$jumpvppid=$jumpv.'&ppid='.$ppid; 
$jumpvpt=$jumpvppid.'&type='.$type;  
 

 $title = '区块管理 - '.$ppid;

$title2= $title ;

if($ppid=='all' || $ppid=='alledit')  $title = $ppid ;
 

/* 
if($type=='bkcustom')  $title2 = '自定义区块';
else if($type=='bknode')  $title2 = '内容区块';
else if($type=='bkblockdh')  $title2 = '效果区块';
else { echo 'type is error.';exit;}
 */ 

if($act=='add' || $act=='edit')  $title2 = '<a class="breadtitle" href="'.$jumpvppid.'">返回区块列表</a> - '.$ppid;
 
//----------
if($act == "sta_block")
{
   
 dmnode_sta($v,$tid,TABLE_BLOCK);
 
    jump($jumpvppid); 
}



if($act == "pos")
{
      dmnodepos($_POST,TABLE_BLOCK);

       jump($jumpvppid); 
}
 
 
 
 
 
 
if($act == "movecommon")
{ 
     $ss = "update ".TABLE_BLOCK." set pidstylebh='common' where pidname='$pidname' $andlangbh limit 1";   
     iquery($ss);
    jump($jumpv.'&ppid=common'); 
}
if($act == "move")
{ 
   //$v = htmlentitdm($v);
    // $ss = "update ".TABLE_BLOCK." set pidstylebh='$curstyle' where  pidname='$pidname' $andlangbh limit 1";   
     // echo $ss;exit;
    // iquery($ss); 
     //jump($jumpv.'&ppid='.$curstyle); 
}


if($act == "del_block")
{ 
  


  $sqlsub = "SELECT * from ".TABLE_BLOCK."  where id='$tid' $andlangbh order by id limit 1";
  // echo $sqlsub;exit;
$rowsub = getrow($sqlsub); 
$blockimg = $rowsub['blockimg'];
$blockimg2 = $rowsub['blockimg2'];
$blockimg3 = $rowsub['blockimg3'];
$pidname = $rowsub['pidname'];

$ifdel1 =  ifcandel_field(TABLE_NODE,'pid',$pidname,'equal','出错，有效果区块内容，请先删除！',$jumpvppid);

if($ifdel1 ){
    if($blockimg<>'')  p2030_delimg($blockimg,'y','n');
    if($blockimg2<>'')  p2030_delimg($blockimg2,'y','n');
    if($blockimg3<>'')  p2030_delimg($blockimg3,'y','n');
    ifsuredel_field(TABLE_BLOCK,'pidname',$pidname,'eq',$jumpvppid);
}
     
     
 
  
}

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

require_once HERE_ROOT.'mod_common/tpl_header.php';
 
?>

 <div class="page-title-box">
  <h4 class="page-title"><?php echo $title2;?>   </h4>
                   
                    <div class="clearfix"></div>
                 </div>
                  <!--End Page Title-->          
           
           
                  <!--Start row-->
                  <div class="row">
                    <div class="col-md-12">
                       <div class="white-box">


 
<?php 
 
 
if($typecur=='bkcustom') $file = 'bkcustom';
else $file = 'bknode';

if($ppid=='all') {
 
  require_once HERE_ROOT.'mod_block/tpl_block_z_all_list.php';
}
else if($ppid=='alledit') {
 
   require_once HERE_ROOT.'mod_block/tpl_block_z_all_edit.php';
 }
else {
  if($act=='list')  require_once HERE_ROOT.'mod_block/tpl_block_list.php'; 
    else if($act=='edit')   { 
    echo '<div class="layoutsidebar fl col-xs-12 col-sm-12  col-md-2">';
    require_once HERE_ROOT.'mod_block/plugin_block_sidebar.php';
    echo  '</div><!--end left-->';
    echo  '<div class="fl col-xs-12 col-sm-12  col-md-10">';
    require_once HERE_ROOT.'mod_block/tpl_block_m_'.$file.'.php';
    echo  '</div><!--end right-->';
    echo  '<div class="c"></div>';
  }
  else require_once HERE_ROOT.'mod_block/tpl_block_m_'.$file.'.php'; // when add.
}
   ?>
  
 </div> </div> </div>
<?php
require_once HERE_ROOT.'mod_common/tpl_footer.php';
?>

 