<?php
if(!defined('IN_DEMOSOSO')) {
exit('this is wrong page,please back to homepage');
}

?>
<?php //get menu
//先判断菜单是否可以自定义。
$cusmenuarr = get_fieldarr(TABLE_MENU,$sidebar,'pidname');
//pre($cusmenuarr);
$sta_cusmenu = $cusmenuarr['sta_cusmenu'];
$cusmenudesp= $cusmenuarr['cusmenudesp'];
$menulevel= $cusmenuarr['menulevel'];
 if($sta_cusmenu=='y')  {
    if($cusmenudesp=='') echo 'no text in menu.  pls edit.';
 	else echo web_despdecode($cusmenudesp);
 }
else{
//------------------------------------------
//$liclass = ' drop-down m ';
//$ulclass = ' drop-down-content sub';
//$ulclassaddv = ' w';
$liclass = $ulclass = $ulclassaddv = '';
$liclass = ' m ';
$ulclass = '  sub';

$classarr = array('');

$menufirstv = ' first';
$menulastv = ' last';
//------------

//echo $sta_havesubmenu;
echo '<ul class="m">';
//----------------------
global $andlangbh;
$sqlmenu = "SELECT * from ".TABLE_MENU." where   ppid='$sidebar' and pid='0' and sta_visible='y'  $andlangbh order by pos desc,id";
 //echo $sqlmenu;
if(getnum($sqlmenu)>0){
//------------
$menulist = getall($sqlmenu);
  // pre($menulist);
		foreach($menulist as $k=>$v){
			$pidname=$v['pidname'];
			$menuid=$v['id'];
			$menu_xiala=$v['menu_xiala'];
			$linkurl=$v['linkurl'];
			 $name=decode($v['name']);
			$typepidname=$v['type'];
			$type = substr($typepidname,0,4);
		// echo $type;
			$aliascc=$menuclass='';


			if (in_array($pidname, $classarr)) { $ulclassadd = $ulclassaddv; }
		    else  $ulclassadd = '';
			$k++;
           $menufirst = $k==1?$menufirstv:'';
		   $menucount = count($menulist);

		   $menulast = $k==$menucount?$menulastv:'';


		  if($type=='cusm' or $type=='page') {

		  	if($type=='cusm') {
		  		$menuclass=' menucus'.$menuid;
		  		if(strpos($linkurl,':/'))  $linkurl = $linkurl;
				 else $linkurl = BASEURLPATH.$linkurl;
		  	}
              if($type=='page'){
							 $pagearr = get_fieldarr(TABLE_PAGE,$typepidname,'pidname');
							// pre($pagearr);
							 if($pagearr=='no'){$name='单页面不存在';$linkurl='0';}
							 else {
								 	 $name=decode($pagearr['name']);
									 $tid = $pagearr['id'];	
								 	 $linkurl = get_url($pagearr);
								 	 $menuclass=' menupage'.$tid;
							 	}
				 }
  
			 		//if($pidname==$main_menuid) $activemenu = ' active'; 
			 		if($typepidname==$curpidname) $activemenu = ' active'; // -- diff from main menu.
			 		else $activemenu = '';
                    // echo '----'.$typepidname;

                    echo '<li class="'.$liclass.$menuclass.$menufirst.$menulast.'"><a class="m'.$activemenu.'" '.linkhref($linkurl).'">'.$name.'</a>';
                    //-----sub menu----------------
                   if($menulevel<>1){
                    if($menu_xiala<>'') echo web_despdecode($menu_xiala);
                    else{
						$sql22 = "SELECT * from ".TABLE_MENU." where pid='$pidname' and ppid='$pidmenu' and type<>'cate' and sta_visible='y' $andlangbh order by pos desc,id";
						//echo $sql22;
						$alias_jump2 ='';
						if(getnum($sql22)>0){
							$rowall22 = getall($sql22);
							//pre($rowall22);
								echo '<ul class="'.$ulclass.'">';
								foreach($rowall22 as $k2=>$v2){

									$pidname2=$v2['pidname'];
									$name2=decode($v2['name']);
									$linkurl2=$v2['linkurl'];
									$type2=$v2['type'];
									$type2four=substr($type2,0,4);


									if($type2four=='cusm') {
										 if(strpos($linkurl2,':/'))  $linkurl2 = $linkurl2;
								  		  else $linkurl2 = BASEURLPATH.$linkurl2;
								  	}

									if($type2four=='page'){
												$pagearr2 = get_fieldarr(TABLE_PAGE,$type2,'pidname');
												if($pagearr2=='no' ){
													$name2='单页面不存在';$linkurl2='0';
													$alias_jump2='';
												}
													else{
														$name2 = decode($pagearr2['name']);
								 						$linkurl2 = get_url($pagearr2);
								 					}

			 						}
					                echo '<li><a '. linkhref($linkurl2).'">'.$name2.'</a></li>';

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

						}//end if(getnum($sql22)>0)
					 }//end menu_xiala
					}
                    //-----------
                    echo '</li>';
			}//end page

			 else{//cate menu part
			 		$sqlmenu = "SELECT * from ".TABLE_CATE." where pidname='$typepidname' and sta_visible='y' $andlangbh order by pos desc,id limit 1";
			 		//echo $sqlmenu;
					$row = getrow($sqlmenu);
					if($row<>'no'){
						$name = decode($row['name']);
						$tid = $row['id'];	
	   					$url = get_url($row);

	   					if($typepidname==$mainpidname) $activemenu = ' active';
				 		else $activemenu = '';
				 		$menuclass = ' menucate'.$tid;

			  			 echo '<li class=" '.$liclass.$menuclass.'"><a class="m'.$activemenu.'" '.linkhref($url).'">'.$name.'</a>';

			  			 if($menulevel<>1){
			  			 	//begin cate level 1
						$sql = "SELECT * from ".TABLE_CATE." where ppid='$typepidname' and sta_visible='y' $andlangbh order by pos desc,id";
						if(getnum($sql)>0){
								$rowall = getall($sql);

									$indexarr = indexingarr($rowall);
										$getnewarr = getnewtreearr($indexarr);
								echo '<ul class="'.$ulclass.$ulclassadd.'">';
								 echo   echoarrhtml_menu($getnewarr);
								echo '</ul>';
						}//end 	if(getnum($sql)>0)
					}
			  			//---------
			  			 echo '</li>';
		  			}

			 }//end cate

			}//end main foreach

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

}//end if(getnum($sqlmenu)>0)
else {
	echo '<li>no menu</li>';
}

//----------------------
        echo '</ul>';

 }
?>