<?php
/*
  欢迎使用DM企业建站系统，本系统由www.demososo.com开发。
*/
if(!defined('IN_DEMOSOSO')) {
  exit('this is wrong page,please back to homepage');
}
?>
<?php
function seo($arr,$type){
  if(is_array($arr)){
  //pre($arr);
   global $websitename;global $alias;
   $seov='';
  //  echo '<pre>aaaa'.count($arr).'aaa'.print_r($arr,1).'</pre>';
    if(count($arr)>0){

       foreach($arr as $i=>$v){
                $v= dmstrip_tags($v);//not use decode in seo,but in select option is ok
          if($i==0)  $seov= $v;
          else  $seov= $seov.' '.$v;

       }
    }



         if($type=='seo1' and $alias<>'index')  {   
            echo $seov.' - '.$websitename;
        }
         else  echo $seov;
   }
   else  echo 'seo must be array';
}



function fnoid() { //global $var404;
//alert("sorry, id is not exist! 对不起，此ID不存在！");
//jump($var404);
require(PAGE404);
exit;

}

function fnoaccess() { //global $var404;
// alert("sorry,prohabit access! 对不起，禁止访问！");
// //jump($var404);
// jump('index.html');
require(PAGE404);
exit;
}




/*-----------about category -------------------------  */

 function get_sqlwhile($curcatepidname,$pid,$cate_level,$cate_last){
 //Global $curcatepidname;  //not use pidname,conflict to sidebar pidname
 //Global $pid;
 // Global $cate_level;
  // Global $cate_last;
 if($pid=='0')  {
 $sqlin=' '; //main cate,then use ppid
 }
 else{
     if($cate_level==2){
    $sqlin=" and pid='$curcatepidname' ";
   }
   else if($cate_level==1){
      if($cate_last=='y')$sqlin=" and pid='$curcatepidname' ";
      else{
       $sqlin=get_sqlwhile2($curcatepidname);
      }
   }

 }
 return $sqlin;
}//end func
 function get_sqlwhile2($curcatepidname){
 Global $andlangbh;
 // Global $curcatepidname;

    $sql_sub = "SELECT  pidname  from ".TABLE_CATE." where  pid='$curcatepidname' and  sta_visible='y' and sta_noaccess='n' $andlangbh order by pos desc,id";
   $nums = getnum($sql_sub);
      if($nums==0)     $sqlin=" and pid='$curcatepidname' ";
    else if($nums==1) {
                             $row_sub = getrow($sql_sub);
                              $vpidname = $row_sub['pidname'];
                             $sqlin=" and pid in('$curcatepidname','$vpidname') ";
                           }
    elseif($nums>1) {
                                $rowall_sub = getall($sql_sub);
                $vpidname2='';
                                 foreach($rowall_sub as $vcat_sub){// in('a','b')
                                    $vpidname = $vcat_sub['pidname'];
                                    $vpidname2=$vpidname2." '$vpidname',";

                                 }//end foreach
                                    $vpidname2=substr($vpidname2,0,-1);
                                    $sqlin=" and pid in ('$curcatepidname',$vpidname2 )";
                           } //end nums;
  return $sqlin;

}//end func

/*-----------end  about category -------------------------  */



//------------
function field_value_front($mainpidname,$pidname){
Global $andlangbh;
 $sqlfield = "SELECT * from ".TABLE_FIELD." where  pid='$mainpidname' and sta_visible='y' $andlangbh order by pos desc,id";
 $rowlistfield = getall($sqlfield);
    if($rowlistfield<>'no') {
 echo '<ul class="fieldlist">';
      foreach($rowlistfield as $vfield){
        $pidnamefield=$vfield['pidname'];
        $namefield=$vfield['name'];
         $typefield=$vfield['typeinput'];
         $cssnamefield=$vfield['cssname'];

      $sqlfievalue = "SELECT value from ".TABLE_FIELDVALUE." where  pid='$pidnamefield' and pidnode='$pidname' $andlangbh order by id limit 1";
       $rowfiev = getrow($sqlfievalue);
      // echo $sqlfievalue.'<Br>';
      if($rowfiev<>'no')  {
        $value=$rowfiev['value'];
        if($typefield=='text' or $typefield=='textarea') $value2=$value;
        else {

          $optv_arr = explode('|', $value);
          // ksort($optv_arr);
           // pre($optv_arr);
          $value2 = '';
          $i=0;
          foreach($optv_arr as $optv_arr_v){
                 $optv_arr_v_s = get_field(TABLE_FIELDOPTION,'name',$optv_arr_v,'pidname');
               if($i==0) $value2 =  $optv_arr_v_s;
               else $value2 =  $value2.' , '.$optv_arr_v_s;
               $i++;

                 //get_field($table,$field,$v,$type)
          }
          //$value2 = substr($value2, 0,-2);
        }
       if($value2=='') $value2 = '&nbsp; ';

      }
      else {
        $value2 ='&nbsp; ';

      }
       echo '<li class="'.$cssnamefield.'"><span class="name">'.$namefield.'</span><span class="value">'.web_despdecode($value2).'</span></li>';


       }
       echo '</ul>';
    }


}
//---------------
/*
function breadtitled(){//refer b_bread.php

 global $breadarr;
pre($breadarr);
               $divi = '<span class="breaddivi">></span>';
                //echo '<pre>aaaaaaa'.print_r($arr,1).'</pre>';
                if(count($breadarr)>0){
                   foreach($breadarr as $i=>$v){
                      if($i==0)  $bread_v= $v;
                      else  $bread_v= $bread_v.$divi .$v;

                   }
                }
             //   echo $bread_home.$divi.strip_tags($bread_v);
                 echo  $bread_v;


}*/
//---------------

function publishtext(){

 global $authorcate;global $authorcompanycate;global $authordatecate;global $authorhitcate;
 global $author;global $authorcompany;global $dateedit;global $hit;
     $authorv = $author<>''?$author:$authorcate;
      $authorcompanyv = $authorcompany<>''?$authorcompany:$authorcompanycate;

if($authorcate=='hide' && $authorcompanycate=='hide' && $authordatecate=='hide' && $authorhitcate=='hide') { }
  else {
echo '<div class="publishtext">';
if($authorcate<>'hide')  echo '<span class="author">作者：'.$authorv.'</span>';
if($authorcompanycate<>'hide')  echo '<span class="authorcompany">来源：'.$authorcompanyv.'</span>';
if($authordatecate<>'hide')  echo '<span class="authordate">发布日期：'.substr($dateedit,0,10).'</span>';
if($authorhitcate<>'hide')  echo '<span class="authorhit">阅读数：'.$hit.'</span>';

echo '</div>';
}

//-------------
}

function detail_linkmore($linkmore){
   global $news_moretitle;
 //echo $linkmoretitle.'---'.$linkmore;
 $linkmoretitlev = $news_moretitle==''?'查看全文>':$news_moretitle;

 if($linkmore<>''){
    echo '<div class="newslinkmore ptb10 dmbtn moresm"><a class="more" '.linktarget($linkmore).' href="'.$linkmore.'">'.$linkmoretitlev.'</a></div>';
 }

//-------------
}

function detail_downloadurl($downloadurl){
  global $download_title;
//echo $linkmoretitle.'---'.$linkmore;
$linkmoretitlev = $download_title==''?'资料下载>':$download_title;
 if($downloadurl<>'') echo '<div class="downloadurl ptb10 dmbtn moresm"><a class="more" '.linktarget($downloadurl).' href="'.$downloadurl.'">'.$linkmoretitlev.'</a></div>';

//-------------
}


function detail_fontsize(){
  global $sta_fontsize;
  if($sta_fontsize=='y'){
   echo '<div class="detailfontsize" data-size="14"><a href="javascript:void(0);" >A<sup class="fz-small">-</sup></a><a href="javascript:void(0);">A<sup class="fz-big">+</sup></a></div>';
 }
  //-------------
}

function detail_sharebtn(){
  global $sta_sharebtn;
     if($sta_sharebtn=='y')
      {echo '<div class="ptb20 detailsharebtn">';
     require(SYSBLOCKROOT.'other/btnshare.php');
     echo '</div>';
   }

  }


//用来在前台编辑后台。
function edit_fenode($fecateid){
  if(dmlogin()){
        $urlhere = BASEURL.ADMINDIR;
        $firststring = substr($fecateid, 0,4);
        if($firststring=='vblo') echo 'error fecateid...';
        $pcate='';
      if($firststring=='csub') {
          $pcate = get_field(TABLE_CATE,'pid',$fecateid,'pidname');

           $secstring = substr($pcate, 0,4);
           if($secstring=='csub')   $pcate = get_field(TABLE_CATE,'pid',$pcate,'pidname');
      }

       $modtype = get_field(TABLE_CATE,'modtype',$fecateid,'pidname');


    //  if($modtype=='blockdh'){
         //mod_node/mod_blockdh.php?lang=cn&pid=csub20171215_1731334710
        //mod_block/mod_effectnode.php?lang=trade&pid=vblock20170706_1855588249
      // $linkv = $urlhere.'/mod_block/mod_effectnode.php?lang='.LANG.'&pid='.$fecateid;
     // }
     // else{
        ///mod_node/mod_node.php?lang=cn&catpid=cate20150805_1125344029
        //mod_node.php?lang=cn&catpid=cate20150805_1125344029&page=0&catid=csub20150805_1127356368
          if($firststring=='cate')  $linkv = $urlhere.'/mod_node/mod_node.php?lang='.LANG.'&catpid='.$fecateid;
          else  $linkv = $urlhere.'/mod_node/mod_node.php?lang='.LANG.'&catpid='.$pcate.'&page=0&catid='.$fecateid;

     // }

      if(!is_int(strpos($fecateid,'|')))  echo  '<div style="position:relative"><a style="display:block" target="_blank" href="'.$linkv.'" class="dmedit dmeditfenode">编辑内容</a></div>';
  }

}

function edit_fenode_blockdh($pidname){
  if(dmlogin()){
        $urlhere = BASEURL.ADMINDIR;

         //mod_node/mod_blockdh.php?lang=cn&pid=csub20171215_1731334710   -- old
        //mod_block/mod_effectnode.php?lang=trade&pid=vblock20170706_1855588249
        $linkv = $urlhere.'/mod_cateeffect/mod_blockdh.php?lang='.LANG.'&pid='.$pidname;
        echo  '<div style="position:relative"><a style="display:block" target="_blank" href="'.$linkv.'" class="dmedit dmeditfenode">编辑内容</a></div>';
  }

}


function edit_node_inblock($pidname,$file){
   if(dmlogin()){  
      if($file<>''){
        $v = dm_dirarr($file);
        $file = $v['f1'].'/'.$v['f2'];
          dmeditlink($file,'','inblock');
      }


          $pid4 = substr($pidname,0,4);
           if($pid4=='cate' || $pid4=='csub'){
            //$modtype = get_field(TABLE_CATE,'modtype',$pidname,'pidname');
            //echo $modtype;
             edit_fenode($pidname);
          }
           elseif ($pid4=='dsub') {
             edit_fenode_blockdh($pidname);
          }
          elseif ($pid4=='vblo') {
            dmeditlink($pidname,'','vblock');
          }


    }
       
}



//---输出node的一些信息
/*
function get_nodekv($kv){
   if($kv<>'') $imgv = UPLOADPATHIMAGE.$kv;
    else $imgv = DEFAULTIMG;
    return $imgv;
}

function get_nodekvsm($kvsm){
   if($kvsm=='') $imgvsm = DEFAULTIMG;
   else $imgvsm =  get_img($kvsm,'','nodiv');//not use get_thumb
  return $imgvsm;
}
*/
function get_nodedespjj($despjj,$desp,$desptext,$num){ //despjj = 内容简介
  if($despjj==''){
      if($desptext<>'') $despv = $desptext;
      else  $despv = $desp;
  }
  else  $despv = $despjj;

      if($num>0){
    $despv = strip_tags(web_despdecode($despv));
        if(strlen($despv)>$num)   $despv = mb_substr($despv,0,$num,'UTF-8').'...';
    return $despv;
      }
    else return '';//if 0,then not display
   // else   return web_despdecode($despv); //为0时，不截取，同时不strip_tags
}

function get_nodedesp($desp,$desptext){
      if($desptext<>'') $despv = $desptext;
      else  $despv = $desp;
      return web_despdecode($despv);
}

function get_nodelinkurl($linkurl){
          $linkurlarr = array();
         if($linkurl<>'') {
           $linkurlarr[0] = ' <a '.linkhref($linkurl).'>';
          $linkurlarr[1]   = '</a>';
         }
         else{
          $linkurlarr[0] = $linkurlarr[1] = '';
        }
        return $linkurlarr;
  }


function cus_columnsfun($cus_columns){ //block判断列数
    $css_gridcol = 'colfull';
    if($cus_columns==2) $css_gridcol = 'colhalf';
    else if($cus_columns==3) $css_gridcol = 'col_1f3';
    else if($cus_columns==4)   $css_gridcol = 'col_1f4';
    else if($cus_columns==5)   $css_gridcol = 'col_1f5';
    else if($cus_columns==6)   $css_gridcol = 'col_1f6';
    return $css_gridcol;

  }

  function cus_columnsfun_bt($cus_columns){ //block判断列数
  $css_gridcol = 'col-md-12 col-sm-12';
  if($cus_columns==2) $css_gridcol = 'col-md-6 col-sm-6  col-xs-6';
      else if($cus_columns==3) $css_gridcol = 'col-md-4 col-sm-4  col-xs-6';
     else if($cus_columns==4)   $css_gridcol = 'col-md-3 col-sm-4 col-xs-6';
     else if($cus_columns==5)   $css_gridcol = 'col-md-d5 col-sm-d5  col-xs-6';
     else if($cus_columns==6)   $css_gridcol = 'col-md-2 col-sm-3  col-xs-6';
     return $css_gridcol;

  }



//---输出css js调用----

function getcssjs($arr,$type=''){
    if(is_array($arr)){
         foreach ($arr as $v) {
          getcssjs2(trim($v),$type);
        }
  }
  elseif(is_int(strpos($arr,'|'))){
     $arr = explode('|', $arr);
      foreach ($arr as $v) {
          getcssjs2(trim($v),$type);
        //  echo "\r\n";
      }
 }
 else {
          getcssjs2(trim($arr),$type);
 }

 }
function getcssjs2($v,$type){
   $vbefore = substr($v,0,5);
   $vlast = substr($v,-4);
  $v2 = $v.'?v='.CSSVERSION;
          if(is_int(strpos($v,'://'))) $vhere = $v2;
      else if($vbefore=='asset') $vhere = STAPATH.$v2;
      else if($vbefore=='jthom') $vhere = BLOCKPATH.'jthome/'.$v2;
      else if($vbefore=='jtblo') $vhere = BLOCKPATH.'jtblock/'.$v2;
      else if($vbefore=='mbhom') $vhere = TPLCURPATH.'mbhome/'.$v2;
      else if($vbefore=='heade') $vhere = BLOCKPATH.$v2;
          else $vhere = TPLCURPATH.'assets/'.$v2;

    if($vlast=='.css') echo '<link href="'.$vhere.'" rel="stylesheet" type="text/css" />';
    else echo '<script src="'.$vhere.'" type="text/javascript"></script>';
    echo "\n";

}
 function getcssjsv($v){
   $vbefore = substr($v,0,5);
 $v2 = $v.'?v='.CSSVERSION;
          if(is_int(strpos($v,'://'))) $vhere = $v2;
      else if($vbefore=='asset') $vhere = STAPATH.$v2;
      else if($vbefore=='jthom') $vhere = BLOCKPATH.'jthome/'.$v2;
      else if($vbefore=='jtblo') $vhere = BLOCKPATH.'jtblock/'.$v2;
          else $vhere = TPLCURPATH.'assets/'.$v2;
          echo   $vhere;


}

//----
function taglink($pidname,$tagtitle){

     // echo $pidname;
       $ss="select tag from  ".TABLE_TAGNODE."  where node='$pidname'  ".ANDLANGBH." order by id desc";
  // echo $ss;exit;
      if(getnum($ss)>0){
          echo '<div class="taglinkindetail"><strong>'.$tagtitle.':</strong>';

        $res = getall($ss);
          foreach ($res as $v) {
              $tag = $v['tag'];
              $ss2="select name,id,alias_jump,pidname  from  ".TABLE_TAG."  where pidname='$tag'  ".ANDLANGBH." order by pos desc,id desc";
              $row = getrow($ss2);
              $name = $row['name'];
               $id = $row['id'];

              //$link = 'tag-'.$id.'-1.html';
                $link =get_url($row);
               echo '<a href="'.$link.'">'.$name.'</a>';



          }//end foreach
echo '</div>';
      }


   }

function dmblockid($desp){
   //[DMblockid]
  $find1 = '[DMblockid]';  $find2 = '[/DMblockid]'; $num = 12;
  //strpos(string,find,start)   substr(string,start,length)    =str_replace($find1, "", $str1begin_true);
  //mb_substr($despv,0,$num,'UTF-8').'...';
    $str1 = $desp;
    $num1_begin = strpos($str1,$find1);
    $num1_end = strpos($str1,$find2);
    if(is_int($num1_begin) && is_int($num1_end) ){

          $str1_begin = substr($str1, 0,$num1_begin);
          $str1_end = substr($str1, $num1_end+$num);

          $blockid1_str = substr($str1, 0,$num1_end);
          $blockid1 =substr($blockid1_str, $num1_begin);
          $blockid1 =str_replace($find1, "", $blockid1);
          $blockid1 = trim(decode($blockid1));

           echo $str1_begin.'<div class="blockidwrap">';
           block($blockid1);
           echo '</div>';

           if(!is_int(strpos($str1_end,$find2)))  echo  $str1_end;
           else dmblockid($str1_end);

   }
   else {
    echo $desp;
    return;
   }

}
//--------------------


/*
function  testimgfunc($k,$testimgfolder){
    if($testimgfolder<>''){
        $i = $k+1;
        $ext = strtolower(substr($testimgfolder,0,3));
        if($ext=='gif' || $ext=='png')  $ext = '.'.$ext;
        else $ext = '.jpg';
        $imgroot = TPLCURROOT.'media/'.$testimgfolder.'/'.$i.$ext;
         //echo $imgroot;
        if(is_file($imgroot)) {
          $imgv = TPLCURPATH.'media/'.$testimgfolder.'/'.$i.$ext;
          return $imgv;
        } else return 'no';
  } else return 'no';
}
*/



function detail_nodetext($type,$type2,$pidname){
     Global $andlangbh;
 $ss = "select desp,desptext from ".TABLE_NODETEXT." where type= '$type' and type2= '$type2' and pid= '$pidname' $andlangbh order by id limit 1";
  //echo $ss;
 if(getnum($ss)>0) {
    $row = getrow($ss);
     $desptext= web_despdecode($row['desptext']);
     $desp= web_despdecode($row['desp']);
     $despv = $desptext<>''?$desptext:$desp;
    return $despv;

 }
 else  return false;
}

function detail_album($type,$pidname,$lang=''){ //$lang for multlang use album  -- no need lang
  //   $andlangbh=" and lang='$lang'  and pbh='".USERBH."' ";
  // $andlangbh ---- no need add lang,just judge by pidname.
 $ss = "select * from ".TABLE_ALBUM." where  pid= '$pidname' order by pos desc,id desc limit 1";//get first record
    //echo $ss;
 if(getnum($ss)>0) {
    $row_abm = getrow($ss);
    $albumpidname = $row_abm['pidname'];
  //--------
     $ss = "select * from ".TABLE_ALBUM." where  pid= '$albumpidname'  order by pos desc,id desc";
   //  echo $ss;
     if(getnum($ss)>0) {

         $row_abm = getall($ss);
         // pre($row_abm);
          return $row_abm;


     }
     else   return false;



    //------------------
    return $row_abm;
 }
 else  return false;
}
function detail_music($type,$pidname){
     Global $andlangbh;
 $ss = "select * from ".TABLE_MUSIC." where type= '$type'   and pid= '$pidname' $andlangbh order by pos desc,id desc";
  // echo $ss;
 if(getnum($ss)>0) {
    $row_abm = getall($ss);
    return $row_abm;
 }
 else  return false;
}
function detail_video($type,$pidname){
     Global $andlangbh;
 $ss = "select pidname from ".TABLE_VIDEO." where type= '$type'   and pid= '$pidname' $andlangbh order by pos desc,id desc limit 1";
  // echo $ss;
 if(getnum($ss)>0) {
    $row_abm = getrow($ss);
    return $row_abm['pidname'];
 }
 else  return false;
}







function getgriddata($pidcate,$maxline,$modtype,$orderby=''){   //----no use
 Global $andlangbh;Global $page;
 if($orderby=='') $orderby = 'order by pos desc,id desc';
  $v= array();$page_total2 = 0;   //use page_total2, bec confict to some block,and affect block_view.php
  $sqlwhere = get_node_sqlv($pidcate);
$sqlnode="select * from ".TABLE_NODE." where  sta_visible='y' $andlangbh  $sqlwhere  $orderby";
// echo $sqlnode;exit;
$fenum = getnum($sqlnode);
if($fenum==0) {echo '没有记录。 --'.$pidcate;
$result = array();
}
else {
   if($modtype=='node'){
    $page_total2=ceil($fenum/$maxline);
    if($page>$page_total2) $page=$page_total2;
        $start=($page-1)*$maxline;
    if($start<0) $start=0;
        $sqllist33="$sqlnode  limit $start,$maxline";
       //echo $sqllist33;exit;

        $result = getall($sqllist33);

   }
   else{
    $sqllist33="$sqlnode  limit 0,$maxline";
     $result = getall($sqllist33);

   }
}

$v[0] = $result;
$v[1] = $page_total2;
$v[2] = $fenum;
return $v;


}

function regionbg($bgcolor,$bgimg,$bgrepeat,$bgposi,$bgsize,$bgattach){
  $bgcolorv = $bgcolor==''?'':"background-color:$bgcolor;";
  $bgattachv = $bgattach==''?'':"background-attachment:$bgattach;";
  $bgsizev = $bgsize==''?'':"background-size:$bgsize;";
  $bgrepeatv = $bgrepeat==''?'':"background-repeat:no-repeat;";
  $bgposiv = $bgposi==''?'':"background-position:center center;";

  $bgimgv='';
  if($bgimg<>'') {
    $bgimgroot = UPLOADROOTIMAGE.$bgimg;
    $bgimgpath = UPLOADPATHIMAGE.$bgimg;
    if(is_file($bgimgroot)){
    $bgimgv  = "background-image: url('$bgimgpath');";
    }
    $v =  $bgcolorv.$bgimgv.$bgrepeatv.$bgposiv.$bgsizev.$bgattachv;
  }
  else $v =  $bgcolorv;
  return $v;
}
//field
function fieldvalue($fiepidname,$type,$value22){// echo $value22;  echo '<br />';
  Global $andlangbh;

  // echo $fiepidname.'----'.$type.'-----'.$value22.'---- <br />';
  $i=1;

  if($type=='text'){
    // $value22=zbdespedit($value22);
  echo '<input type="text" value="" name="'.$fiepidname.'" class="value form-control" />';
  }
  if($type=='textarea'){
    // $value22=zbdespedit($value22);
  echo '<textarea name="'.$fiepidname.'" class="value form-control" rows="8"></textarea>';
  }


  if($type=='radio' or $type=='checkbox' or  $type=='select'){
     $sqlsub = "SELECT id,name,pidname from ".TABLE_FIELDOPTION." where  pid='$fiepidname' and sta_visible='y'  $andlangbh order by pos desc,id";
      //echo $sqlsub;exit;
     $rowlistsub = getall($sqlsub);
     if($rowlistsub=='no') {
      echo '<p>&nbsp;&nbsp;还没有选项，请在后台添加...</p>';
      }
      else{
        if($type=='select') {
          echo '<select class="value" name="'.$fiepidname.'"><option value="">请选择</option>';

        }

        foreach($rowlistsub as $vv){
          $id = $vv['id'];//id is for input name
          $namev = $vv['name'];
          $pidname = $vv['pidname'];

          if($type=='radio'){
            $nameid='rid'.$id.$i;
            //if($pidname==$value22){    $checked='checked="checked"';$class='class="cur"';}
           // else{   $checked='';$class='';}

                 echo '<input type="radio" value="'.$namev.'" name="'.$fiepidname.'" id="'.$nameid.'" size="80" />';
           echo '<label style="padding-right:20px" for="'.$nameid.'">'.$namev.'</label> ';

          }
          if($type=='checkbox'){
            $nameid='cid'.$id.$i;
             $strpos = strpos($value22,$pidname); /*只有checkbox会有连接字符串*/
            //if(in_array($pidname,$value22)){    $checked='checked="checked"';$class='class="cur"';}
             // if(is_int($strpos)){ $checked='checked="checked"';$class='class="cur"';}
          //  else{ $checked='';$class='';}
                 echo '<input type="checkbox"    value="'.$namev.'" name="'.$fiepidname.'[]" id="'.$nameid.'" size="80" />';
           echo '<label style="padding-right:20px" for="'.$nameid.'">'.$namev.'</label> ';
          }
          if($type=='select'){
            // if($pidname==$value22) $selected=' selected="selected"'; else $selected='';
                 echo '<option   value="'.$namev.'">'.$namev.'</option>';
          }

        $i++;
        }//end foreach
      if($type=='select') echo '</select>';
      }//end else




  }//edn $type=='radio' or $type=='checkbox' or  $type=='select'



}//end func

function textformat($v,$cssname){
if(is_int(strpos($cssname, 'wowtrue'))){
      $wowleft = ' wow fadeInLeft';
      $wowright = ' wow fadeInRight';
   }
   else{
      $wowleft =  $wowright  = '';
   }
//--------------------
 
  foreach ($v['arrcan'] as   $key=>$value) { 
                 $bsccc = $key;
                 $$bsccc=$value;
             }

 
$blockid  = $dhblockid; 
$format  = $textformat; 
   
$title =  $v['title']; $img =  $v['kv'];
$titlev = '<h3>'.$title.'</h3>';
$despv =   $v['desp'];


$dhlinkurlv = '';
if($dhlinktitle<>'' && $dhlinkurl<>'') $dhlinkurlv = '<div class="dmbtn moresm mtb10"><a class="more" '.linkhref($dhlinkurl).'>'.$dhlinktitle.'</a></div>';
$despv = $despv.$dhlinkurlv;


 $imgv = '';
 if($img<>'')  $imgv = '<div class="img tc"><img class="maximg" src="'.get_img($img).'" alt="'.$title.'" /></div>';

 if(is_int(strpos($cssname,'titlefalse'))) $titlev = '';

 $despjj = $v['despjj'];
if($despjj<>'') $titlev = $titlev.'<div class="despjj">'.$despjj.'</div>';

//begin content
   if($format=='textleft' || $format=='textright')  {  $colw_L = 'colhalf ';$colw_R = 'colhalf '; }
   if($format=='textleft13')  {  $colw_L = 'col_1f3 ';$colw_R = 'col_2f3 '; }
   if($format=='textleft23')  {  $colw_L = 'col_2f3 ';$colw_R = 'col_1f3 '; }

   if($format=='textright13')  {  $colw_L = 'col_2f3 ';$colw_R = 'col_1f3 '; }
   if($format=='textright23')  {  $colw_L = 'col_1f3 ';$colw_R = 'col_2f3 '; }


  if($format=='default') {
       echo $imgv;
       if($blockid<>'') block($blockid);
       echo '<div class="desp">';
       dmblockid($despv);
       echo '</div>';
  }

 else if($format=='textleft' || $format=='textleft13' || $format=='textleft23') {
     echo '<div class="'.$colw_L.$wowleft.'">'.$titlev.'<div class="desp">';
       dmblockid($despv);
       echo '</div></div>';
       echo '<div class="'.$colw_R.$wowright.'">'.$imgv;
       if($blockid<>'') block($blockid);
       echo '</div>';
       echo '<div class="c"> </div>';


  }
 else  if($format=='textright' || $format=='textright13' || $format=='textright23') {
       echo '<div class="'.$colw_L.$wowleft.'">'.$imgv;
       if($blockid<>'') block($blockid);
       echo '</div>';
       echo '<div class="'.$colw_R.$wowright.'">'.$titlev.'<div class="desp">';
       dmblockid($despv);
       echo '</div></div>';
       echo '<div class="c"> </div>';

  }

   else  if($format=='onlyedit') {
        echo ' <div class="desp">';
         dmblockid($despv);
        echo '</div>';
      // echo $despv;

  }


 else if($format=='onlybs') {
       block($blockid);

  }


//-------------------------------------
}  //end func




function imgtext_echocnt($v,$haswow){



$titlefg = 'titlecenter';
$blockid = $linktitle= $linkurl = $cssname = $sta_width_cnt= '';

$arr_cfg=$v['arr_cfg'];  $format = $v['format'];

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

$title=$v['name'];$pidnamehere=$v['pidname'];
 $kv= $v['kv'];

 $imgv ='';
 if($kv<>'')   $imgv = '<div class="img tc"><img class="maximg" src="'.get_img($kv).'" alt="'.$title.'" /></div>';


//$despjj=web_despdecode($v['despjj']);
 $despjj = '';
 $desptext= web_despdecode($v['desptext']);
$desp= web_despdecode($v['desp']);
$despv = $desptext<>''?$desptext:$desp;

  if($linktitle=='') $linkimgtextv = '';
 else $linkimgtextv = '<div class="dmbtn mt10"><a class="more" '.linkhref($linkurl).'>'.$linktitle.'</a></div>';
$despv =  $despv.$linkimgtextv;

//------------------------
  $titleimgv = $title;
  $titlev = '<h3>'.$title.'</h3>';
   if(is_int(strpos($cssname,'titlefalse'))) $titlev = '';

$titlelinelongv = $titlelineshortv  = '';
//--------------------
 $sta_width_titlev= $titlestylev = $titlestylesubv = '';
 //$sta_width_cntv = $sta_width_cnt=='n'?' container ':'';

//begion title header
//echo $titlefg;
   if($titlefg<>'notitle'){
        $regionhdleftv =  $titlefg=='titleleft'?' regionhdleft ':'';

            echo '<div class="regionhd '.$regionhdleftv.'"><h3 class="hd" '.$titlestylev.'>'.$titleimgv.'</h3>';
            echo '<div class="titleline  titlelinelong"> <span class="titlelineshort" '.$titlelineshortv.'></span></div>';
            echo '</div>';
            //if($despjj<>'') echo '<div class="regsubtitle" '.$titlestylesubv.'>'.$despjj.'</div></div>';
   }

 //end title header

//begin content
   if($format=='textleft' || $format=='textright')  {  $colw_L = 'colhalf ';$colw_R = 'colhalf '; }
   if($format=='textleft13')  {  $colw_L = 'col_1f3 ';$colw_R = 'col_2f3 '; }
   if($format=='textleft23')  {  $colw_L = 'col_2f3 ';$colw_R = 'col_1f3 '; }

   if($format=='textright13')  {  $colw_L = 'col_2f3 ';$colw_R = 'col_1f3 '; }
   if($format=='textright23')  {  $colw_L = 'col_1f3 ';$colw_R = 'col_2f3 '; }

 echo '<div class="regioncnt">';
if($haswow=='y') {
      $wowleft = ' wow fadeInLeft';
      $wowright = ' wow fadeInRight';
   }else{
         $wowleft =  $wowright  = '';
   }

      if($format=='default') {
       echo $imgv;
       if($blockid<>'') block($blockid);
       echo '<div class="desp">';
       dmblockid($despv);
       echo '</div>';
  }

 else if($format=='textleft' || $format=='textleft13' || $format=='textleft23') {
     echo '<div class="'.$colw_L.$wowleft.'">'.$titlev.'<div class="desp">';
       dmblockid($despv);
       echo '</div></div>';
       echo '<div class="'.$colw_R.$wowright.'">'.$imgv;
       if($blockid<>'') block($blockid);
       echo '</div>';
       echo '<div class="c"> </div>';


  }
 else  if($format=='textright' || $format=='textright13' || $format=='textright23') {
       echo '<div class="'.$colw_L.$wowleft.'">'.$imgv;
       if($blockid<>'') block($blockid);
       echo '</div>';
       echo '<div class="'.$colw_R.$wowright.'">'.$titlev.'<div class="desp">';
       dmblockid($despv);
       echo '</div></div>';
       echo '<div class="c"> </div>';

  }

   else  if($format=='onlyedit') {
        echo ' <div class="desp">';
         dmblockid($despv);
        echo '</div>';
      // echo $despv;

  }


 else if($format=='onlybs') {
       block($blockid);
       echo $linkimgtextv;
       echo $imgv;
  }
   else if($format=='column') {   ;
         columnecho($pidnamehere);

  }
echo '</div>';
// end content

//-------------------------------------
}  //end func

//---------------
function bujublock($blockid,$div){
    if($blockid<>''){
      echo '<div class="'.$div.'">';
      block($blockid);
      echo '</div>';
    }
}

function subreg_echocnt($v,$haswow){

$titlefg = 'titlecenter';
$blockid = $linktitle= $linkurl = '';
$blockid=$v['blockid']; $despjj=web_despdecode($v['despjj']);


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

$title=$v['name'];
$pidnamehere=$v['pidname'];
if($linktitle=='') $linkregionv = '';
else $linkregionv = '<div class="dmbtn mt10 tc"><a class="more" '.linkhref($linkurl).'>'.$linktitle.'</a></div>';


//--------------------
$titlestylev = $titlestyle<>''?' style="'.$titlestyle.'"':'';
$titlestylesubv = $titlestylesub<>''?' style="'.$titlestylesub.'"':'';

$titlelinelongv = $titlelineshortv = '';
 if($titlelinelong<>''){
     if($titlelinelong=='hide') $titlelinelongv =  ' style="border:0;height:0"';
     else $titlelinelongv =  ' style="border-bottom:1px solid '.$titlelinelong.'"';
 }
 if($titlelineshort<>''){
     if($titlelineshort=='hide') $titlelineshortv =  ' style="display:none"';
     else $titlelineshortv =  ' style=" background:'.$titlelineshort.'"';
 }


 $sta_width_titlev = $sta_width_title=='n'?' container ':'';
 $sta_width_cntv = $sta_width_cnt=='n'?' container ':'';


//------------------------
  if($titleimg<>'')   $titleimgv = '<img src="'.UPLOADPATHIMAGE.$titleimg.'" alt="" />';
   else   $titleimgv ='<h3 class="hd" '.$titlestylev.'>'.$title.'</h3>';

   if($titlefg<>'notitle'){
        $regionhdleftv =  $titlefg=='titleleft'?' regionhdleft ':'';

            echo '<div class="regionhd '.$regionhdleftv.$sta_width_titlev.'">'.$titleimgv;
            echo '<div class="titleline  titlelinelong " '.$titlelinelongv.'> <span class="titlelineshort" '.$titlelineshortv.'></span></div>';
            if($despjj<>'') echo '<div class="regsubtitle" '.$titlestylesubv.'>'.$despjj.'</div>';
            echo '</div>';
   }

 //end title header



 echo '<div class="regioncnt '.$sta_width_cntv.'">';
  if($blockid<>'') {
        block($blockid);
       echo $linkregionv;
  }
   else   {
         columnecho($pidnamehere);

  }
echo '</div>';
// end content

//-------------------------------------
}
//-------------------------------


function echoarrhtml_menu($tree,$level,$multicate='')
{
global $jumpv; global $catid; //catid is catpid.
global  $curcatepidname;global $curcate_pid;
$html = '';

$dotV = '';
if($level==1)  $dotV = '<span></span>';


  $levelV = 'sdlevel_'.$level;
  $liV = 'sdli_'.$level;

  $level++;


foreach($tree as $k=>$vsub) {
 //pre($tree);

     $name = $vsub['name'];
     $tid=$vsub['id'];
     //$level=$vsub['level'];$last=$vsub['last'];

     $pidname=$vsub['pidname'];
     $pidhere=$vsub['pid'];  
      $ppidhere=$vsub['ppid'];  
     //$sta_visiblevv=$vsub['sta_visible'];

     $url_subcc = get_url($vsub);


     //$url_subcc=l($url_sub_httpcc,$texturl.$aliasjumpv,'','');
    $classv = ($pidname == $curcatepidname )?'  active  ':'';

    $classv_li = ($pidname == $curcatepidname || $pidname == $curcate_pid)?' class="'.$liV.' mainactive" ':'';

     //$name = '<a   '.$classv.'href="'.$url_subcc.'">vv'.$name.'</a>';
    $name = '<a class="'.$levelV.$classv.'" '.linkhref($url_subcc).'>'.$name.$dotV.'</a>';

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

     

     if(@$vsub['son'] == '')
     {
     $html .= '<li '.$classv_li.'>'.$name.'</li>';
     }
     else
     {
     $html .= '<li '.$classv_li.'>'.$name.'<ul class="sub">';
        if(MULTICATE=='y' || $multicate=='')  $html .= echoarrhtml_menu($vsub['son'],$level,MULTICATE);
     $html = $html."</ul></li>";
     }


}

return $html ;
// return $html;
}

//-------------------------------
function select_from_arr($arr,$curpid,$pls){//select_from_arr($arr_yn,0,'',$status);
    if($pls=='pls')  echo '<option  value="">请选择...</option>' ;
   foreach ($arr as $k=>$v){
     // if((int)$curpid==(int)$k) $select=' selected '; else $select='';
        if($curpid==$k) $select=' selected '; else $select='';
 echo '<option '.$select.'value="'.$k.'">'.$v.'</option>' ;
   }
}//end func


//-----------excerpt,$start,$maxline,$order,$where
function getarr_node($pidname,$sqlarr){

$excerpt=$start=$maxline=$order='';

$excerpt = $sqlarr['excerpt'];
$start = $sqlarr['start'];
$maxline = $sqlarr['maxline'];
$order = $sqlarr['order'];
$where = $sqlarr['where'];
 
if(substr($pidname,0,4)=='dsub') $modtype='blockdh';
else $modtype='node';
//echo $modtype;
 $maincate = $pidname;
if($modtype=='node')  {   
    if(substr($pidname,0,4)=='csub')   $maincate = get_field(TABLE_CATE,'ppid',$pidname,'pidname');
    
    $sqlwhere = wherecatev($maincate,$pidname);
    // $defimg = DEFAULTIMG;
    $catename = get_field(TABLE_CATE,'name',$maincate,'pidname');
    $catename_cur = get_field(TABLE_CATE,'name',$pidname,'pidname');
     $order = $order==''?' pos desc,dateedit desc':$order;
} 
else{
   $sqlwhere = " pid='$pidname' and modtype='blockdh' ";
  // $defimg = '';
  $catename = get_field(TABLE_CATE,'name',$pidname,'pidname');
  $catename_cur  = $catename ;  
   $order = $order==''?' pos desc,id':$order;

}
  $res = array(); 
  $res['catename'] = $catename;
  $res['catename_cur'] = $catename_cur;

if($pidname=='search') {
  $sqlwhere = $where;
  $where = '';
}

$sql="select *  from ".TABLE_NODE." where  $sqlwhere $where and sta_visible='y' and sta_noaccess='n'  ".ANDLANGBH." order by $order  limit $start,$maxline";
// echo $sql;
  $num_rows = get_numrows($sql);
     if($num_rows>0){

        $mainmenu = getrow($sql);
        

       $result = getall($sql);

       
       
       $res['datares'] = 'yes';

        foreach( $result as  $k=>$v){
         // pre($v);
          if($modtype=='node')  $desp =  get_nodedespjj($v['despjj'],$v['desp'],$v['desptext'],$excerpt); 
          else   $desp =  get_nodedesp($v['desp'],$v['desptext']); 
           //pre($v);
          $url = get_url($v);
          //$target = linktarget($url);
 
           $arrcanv = explode('==#==',$v['arr_can']);

           $albumid = $v['albumid'];
           $kvsm = $v['kvsm'];

           if($albumid<>'' && $kvsm==''){
             // echo $albumid;
              $sqllang2 = "SELECT kvsm,lang from ".TABLE_NODE." where  pidname='$albumid'  order by  id desc limit 1";
          // echo $sqllang2;
              if(getnum($sqllang2)>0) {
                 $rowlang2 = getrow($sqllang2);
                  $kvsm = UPLOADPATH.'image/'.$rowlang2['lang'].'/'.$rowlang2['kvsm'];
              } 

           } 


              $res['data'][$k]['id'] =  $v['id'];
              $res['data'][$k]['pid'] =  $v['pid'];
              $res['data'][$k]['ppid'] =  $v['ppid'];
              $res['data'][$k]['title'] =  $v['title'];

        if($modtype=='node') {
              $res['data'][$k]['titlestyle'] =  $v['titlestyle'];
              $res['data'][$k]['alias_jump'] =  $v['alias_jump'];
              $res['data'][$k]['sta_tj'] =  $v['sta_tj'];
              $res['data'][$k]['sta_new'] =  $v['sta_new'];          
              
             // $res['data'][$k]['link_target'] =  $target;
              $res['data'][$k]['link'] =  $url;
              $dateday  = substr($v['dateedit'],0,10);
              $res['data'][$k]['dateday'] = $dateday;
              $res['data'][$k]['dateedit'] = $v['dateedit'];
              $res['data'][$k]['hit'] =  $v['hit'];
              
        } 
               $res['data'][$k]['kv'] =  $v['kv'];            
              $res['data'][$k]['kvsm'] =  $kvsm;      //maybe use multilang nodeid       
              $res['data'][$k]['kvsm2'] =  $v['kvsm2']; 

              //$res['data'][$k]['kvsm_cus'] =  $v['kvsm_cus']; //no use..... 
              $res['data'][$k]['kvsm_cus'] = '';

              $res['data'][$k]['desp'] = $desp;
             
              if($modtype=='blockdh') {
                $res['data'][$k]['despjj'] = web_despdecode($v['despjj']);
                 $res['data'][$k]['despall'] = ' - no despall when type is blockdh in list(excerpt), use desp';
              }
              else{
                $res['data'][$k]['despjj'] = ' - no despjj when type is node in list(excerpt), use desp';
                 $res['data'][$k]['despall'] = get_nodedesp($v['desp'],$v['desptext']);  //use for te hr page when use node not blockdh.
                  
              }
             
             

              $arrcantemp = array();  
                 if(count($arrcanv)>1){
                    foreach ($arrcanv as   $bsvalue) {
                      if(strpos($bsvalue, ':##')){
                      $bsvaluearr = explode(':##',$bsvalue);
                      $bsccc = $bsvaluearr[0];
                      //$$bsccc=$bsvaluearr[1];
                      $arrcantemp[$bsccc] =$bsvaluearr[1];
                      }
                    } 
                }
                //---end arrcan
                $res['data'][$k]['arrcan'] = $arrcantemp;

        }
            


     }
     else{
          $res['datares'] = 'no';
           $res['data'] = 'there is no content in category:'.$pidname;
     }
    // pre($res);
     return $res;
}
//----------------

function getarr_cate($pidname,$maxline=0){

  $res = array(); 
 $catearr = get_fieldarr(TABLE_CATE,$pidname,'pidname');

 $cur_pidname = $catearr['pidname'];
 $catename = $cur_name = $catearr['name'];
 $catelink = $cur_link = get_url($catearr);

  if(substr($pidname,0,4)=='csub') {
      

      $mainidhere = get_field(TABLE_CATE,'ppid',$pidname,'pidname');

      $maincatearr = get_fieldarr(TABLE_CATE,$mainidhere,'pidname');

       $catename =  $maincatearr['name'];
       $catelink =   get_url($maincatearr);
 

       $where = "  pid='$pidname' ";
  } 
  else $where = "  ppid='$pidname' ";
 
    $res['catename'] = $catename;
    $res['catelink'] = $catelink;
    $res['catename_cur'] = $cur_name;
    $res['catename_curlink'] = $cur_link;

    $limitv = $maxline>0?" limit 0,$maxline ":"";

//----------------
$sql = "SELECT * from ".TABLE_CATE." where $where  ".ANDLANGBH." and sta_visible='y' and sta_noaccess='n' order by pos desc,id $limitv"; // echo getnum($sql);
if(getnum($sql)>0){

    $res['datares'] = 'yes';

$result = getall($sql);
$res2 = array(); 
foreach( $result as  $k=>$v){
  
  $res2[$k]['id'] = $v['id'];
  $res2[$k]['name'] = $v['name'];
  $res2[$k]['pidname'] = $v['pidname'];
  $res2[$k]['pid'] = $v['pid'];
  $res2[$k]['ppid'] = $v['ppid'];
  $res2[$k]['link'] =get_url($v);

}
 
$indexarr = indexingarr($res2);
$getnewarr = getnewtreearr($indexarr);
 
 $res['data'] = $getnewarr;

//pre($res);
} 
 else{
          $res['datares'] = 'no';
          $res['data'] = 'there is no sub category in : '.$pidname;
     }
       
   return $res;
}
//----------------
function getarr_block($pidname){

  $res = array(); 
 $sql="select * from ".TABLE_BLOCK." where pidname='$pidname'   ".ANDLANGBH."  order by id desc limit 1";

  $num_rows = get_numrows($sql);
     if($num_rows>0){
       $result = getall($sql);
       //pre($result);
     
       $res['datares'] = 'yes';

        foreach( $result as  $k=>$v){
         // pre($v);
          $desp =  get_nodedesp($v['desp'],$v['desptext']); 
          
           $arrcanv = explode('==#==',$v['blockcan']);

              $res['data']['id'] =  $v['id'];
              $res['data']['pid'] =  $v['pid'];
              $res['data']['pidstylebh'] =  $v['pidstylebh'];
               $res['data']['pidcate'] =  $v['pidcate'];
              $res['data']['name'] =  $v['name'];
             // $res['data']['namefront'] =  $v['namefront'];  namefront is in can
               $res['data']['pidcolumn'] =  $v['pidcolumn'];
              $res['data']['typecolumn'] =  $v['typecolumn'];
              
               $res['data']['template'] =  $v['template'];
              
               $res['data']['img'] =  $v['blockimg']; 
               $res['data']['blockimg'] =  $v['blockimg']; 
               $res['data']['blockimg2'] =  $v['blockimg2']; 
               $res['data']['blockimg3'] =  $v['blockimg3'];  

               


              $res['data']['desp'] = $desp;
              $res['data']['despjj'] = web_despdecode($v['despjj']);


              $arrcantemp = array();  
                 if(count($arrcanv)>1){
                    foreach ($arrcanv as   $bsvalue) {
                      if(strpos($bsvalue, ':##')){
                      $bsvaluearr = explode(':##',$bsvalue);
                      $bsccc = $bsvaluearr[0];
                      //$$bsccc=$bsvaluearr[1];
                      $arrcantemp[$bsccc] =$bsvaluearr[1];
                      }
                    } 
                }
                //---end arrcan
                $res['data']['arrcan'] = $arrcantemp;

        }
            


     }
     else{
          $res['datares'] = 'no';
           $res['data'] = $pidname.'的自定义区块内容不存在。确定前台和后台的语言是否不一致。';
     }
     return $res;
}
//----------------
 

function getarr_dmmenu($pidmenu){
 
 $res = array(); 

$cusmenuarr = get_fieldarr(TABLE_MENU,$pidmenu,'pidname');
//pre($cusmenuarr);
$sta_cusmenu = $cusmenuarr['sta_cusmenu'];  
$cusmenudesp= $cusmenuarr['cusmenudesp'];
$menulevel= $cusmenuarr['menulevel'];
 if($sta_cusmenu=='y')  {
    if($cusmenudesp=='') {
          $res['datares'] = 'no';
          $res['data'] =  '你在后台选择了自定义菜单内容，但内容为空。';
    }     
  else {
          $res['datares'] = 'no';
          $res['data'] = web_despdecode($cusmenudesp);
 
  } 
 }
else{
//------------------------------------------

 
$sqlmenu = "SELECT * from ".TABLE_MENU." where   ppid='$pidmenu' and pid='0' and sta_visible='y'  ".ANDLANGBH." order by pos desc,id";
 //echo $sqlmenu;
if(getnum($sqlmenu)>0){
//------------
    $result = getall($sqlmenu);
   // pre($result);
        foreach( $result as  $k=>$v){
             $typepidname = $v['type']; $linkurl = $v['linkurl'];

            $type4 = substr($typepidname,0,4);

            if($type4=='cusm') {                
                if(strpos($linkurl,':/'))  $linkurl = $linkurl;
                else $linkurl = BASEURLPATH.$linkurl;
                $name = decode($v['name']);

            }
            else if($type4=='page'){
                   $pagearr = get_fieldarr(TABLE_PAGE,$typepidname,'pidname');
                   // pre($pagearr);
                   if($pagearr=='no'){$name='单页面不存在';$linkurl='';}
                   else {
                       $name=decode($pagearr['name']);     
                       $linkurl = get_url($pagearr);             
                    }
             }
             else{
              $pagearr = get_fieldarr(TABLE_CATE,$typepidname,'pidname');
                   // pre($pagearr);
                   if($pagearr=='no'){$name='分类不存在';$linkurl='';}
                   else {
                       $name=decode($pagearr['name']);     
                       $linkurl = get_url($pagearr);             
                    }

                    

             }



            //----------------
             $pidname = $v['pidname'];
             $menu_xiala = $v['menu_xiala'];
        
            $res2[$k]['id'] = $v['id'];
            $res2[$k]['name'] = $name;            
            $res2[$k]['linkurl'] = $linkurl;
            $res2[$k]['menu_xiala'] = web_despdecode($menu_xiala);

            $res2[$k]['ppid'] = $v['ppid'];
            $res2[$k]['pid'] = $v['pid']; 
            $res2[$k]['pidname'] = $pidname;
         
            $res2[$k]['type'] = $typepidname;
            $res2[$k]['sta_cusmenu'] = $v['sta_cusmenu'];
            $res2[$k]['cusmenudesp'] = $v['cusmenudesp'];
            

            //-----
          if($menulevel<>1){  
            if($type4=='cate') $res2[$k]['son'] = getarr_cate($typepidname);
            else{
                 if($type4=='cusm' && $menu_xiala<>''){  
                        $res2[$k]['son'] = '已自定义下拉内容。';
 
                  }else{
             
                 $sqlsub = "SELECT * from ".TABLE_MENU." where pid='$pidname' and ppid='$pidmenu'  and sta_visible='y'  ".ANDLANGBH."  order by pos desc,id";
           //  echo $sqlsub.'<br />';
                    if(getnum($sqlsub)>0){
                    //------------
                        $resultsub = getall($sqlsub);
                     // pre($resultsub);
                      $res2sub = array();
                          foreach( $resultsub as  $ksub=>$vsub){
                                   $typepidnamesub = $vsub['type']; 
                                   $linkurlsub = $vsub['linkurl'];

                                  $type4sub = substr($typepidnamesub,0,4);

                                  if($type4sub=='cusm') {                
                                      if(strpos($linkurlsub,':/'))  $linkurlsub = $linkurlsub;
                                      else $linkurlsub = BASEURLPATH.$linkurlsub;

                                      $namesub = decode($vsub['name']);

                                  }
                                  else if($type4sub=='page'){
                                         $pagearrsub = get_fieldarr(TABLE_PAGE,$typepidnamesub,'pidname');
                                         // pre($pagearr);
                                         if($pagearrsub=='no'){
                                              $namesub='单页面不存在';
                                              $linkurlsub='';
                                        }
                                         else {
                                             $namesub=decode($pagearrsub['name']);     
                                             $linkurlsub = get_url($pagearrsub);             
                                          }
                                   }

                        //----------------
                                    $res2sub[$ksub]['id'] = $vsub['id'];
                                    $res2sub[$ksub]['name'] = $namesub;                                     
                                    $res2sub[$ksub]['linkurl'] = $linkurlsub;
                                    $res2sub[$ksub]['menu_xiala'] = $vsub['menu_xiala'];
                                    
                                    $res2sub[$ksub]['ppid'] = $vsub['ppid'];
                                    $res2sub[$ksub]['pid'] = $vsub['pid']; 
                                    $res2sub[$ksub]['pidname'] = $vsub['pidname'];
                                    
                                    $res2sub[$ksub]['type'] = $typepidnamesub;
                                    $res2sub[$ksub]['sta_cusmenu'] = $vsub['sta_cusmenu'];
                                    $res2sub[$ksub]['cusmenudesp'] = $vsub['cusmenudesp'];
                                    




                      }//end foreach
                      //pre($res2sub);
                          $res2[$k]['son'] = $res2sub;
                         // pre($res2[$k]['son']);
                        // pre($res2[$k]['son'] );


            }
            //----------
          }

            //----------
         
            }

            //-------
         }//end menulevel 


      } 


        $res['datares'] = 'yes';
         $res['data'] = $res2;

     }
     else{
         $res['datares'] = 'no';
         $res['data'] = '没有找到内容';
     }
//-------------- 
} //end no record
 //pre($res);
return $res;
 //-----------------
}


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


