<?php
require '../../../zb_system/function/c_system_base.php';

if ($_POST && isset($_POST)) {	 		 
	if ($_GET && isset($_GET['type'])) {    			   		
		if ($_GET['type'] == 'add') {      	  			
			if($zbp->Config('bluecms')->HasKey('NavArray')){    	  				 
				$NavArray = json_decode($zbp->Config('bluecms')->NavArray,true);    			  	  
			}    					 	 
			$NavArray[] = $_POST;     		  		 
			foreach ($NavArray as $key => $row) {		   	
			    $navname[$key] = $row['navname'];    	 					 
			    $navurl[$key]  = $row['navurl']; 
				$navico[$key]  = $row['navico']; 
				$twomenu[$key]  = $row['twomenu']; 
				$paixu[$key]  = $row['paixu'];     	  		 
			}    	  	 			
			array_multisort($paixu, SORT_ASC, $navname, SORT_DESC, $NavArray);     		  	 	
			$zbp->Config('bluecms')->NavArray = json_encode($NavArray);      			 		
			$zbp->SaveConfig('bluecms');
	        Redirect('main.php?act=nav');			  
		} elseif ($_GET['type'] == 'edit') {    		  	   
			$NavArray = json_decode($zbp->Config('bluecms')->NavArray,true);    			 		  
			$editid = $_POST['editid'];    			 			 
			unset($_POST['editid']);    	  	 	 	
			$NavArray[$editid] =$_POST;    		      
			foreach ($NavArray as $key => $row) {    				 		 
			    $navname[$key] = $row['navname'];    	 					 
			    $navurl[$key]  = $row['navurl']; 
				$navico[$key]  = $row['navico']; 
				$twomenu[$key]  = $row['twomenu']; 
				$paixu[$key]  = $row['paixu'];   		 	  		
			}      					 
			array_multisort($paixu, SORT_ASC, $navname, SORT_DESC, $NavArray);    			 	 	 
			$zbp->Config('bluecms')->NavArray = json_encode($NavArray);    	   	 	 
			$zbp->SaveConfig('bluecms');  
			Redirect('main.php?act=nav');		   		
		}    				 			
	}    		   		 
} elseif ($_GET && isset($_GET)) {    		  		  
	if ($_GET['type'] == 'del') {    			  			
		$NavArray = json_decode($zbp->Config('bluecms')->NavArray,true);    			 	 		
		$editid = $_GET['id'];      					 
		unset($NavArray[$editid]);    	 			  	
		$zbp->Config('bluecms')->NavArray = json_encode($NavArray);    	   	   
		$zbp->SaveConfig('bluecms');
	    Redirect('main.php?act=nav');	  	
	}    	 	 	 	 
}
?>