Location: PHPKode > projects > Basic Announce > Basic Announce Version 4.0/system/menu_options_manager.php
<?php
################################################################################
##              -= YOU MAY NOT REMOVE OR CHANGE THIS NOTICE =-                 #
## --------------------------------------------------------------------------- #
##  ApPHP AdminPanel Pro                                                       #
##  Developed by:  ApPHP <hide@address.com>                                      #
##  License:       GNU LGPL v.3                                                #
##  Site:          http://www.apphp.com/php-adminpanel/                        #
##  Copyright:     ApPHP AdminPanel (c) 2006-2011. All rights reserved.        #
##                                                                             #
################################################################################

    header("content-type: text/html; charset=utf-8");
    
    // Initialize the session.
    session_start();
    
    require_once("../inc/classes/session.class.php");	
    require_once("../inc/checkAdminPagePermissions.php");

    require_once("../inc/config.inc.php");
    require_once("../inc/settings.inc.php");	
	require_once("../inc/functions.inc.php");
	require_once("../inc/languages/".$SETTINGS['site_language'].".php");

    if(!page_access_allowed($_SERVER['SCRIPT_NAME'])) redirect_to("access_denied.php");

    $unique_prefix = "meno_";    /* prevent overlays - must be started with a letter */
                                 
    $mode           = isset($_REQUEST[$unique_prefix.'mode']) ? $_REQUEST[$unique_prefix.'mode'] : "";
    $rid            = isset($_REQUEST[$unique_prefix.'rid']) ? (int)$_REQUEST[$unique_prefix.'rid'] : "";
    $msg            = isset($_GET['msg']) ? $_GET['msg'] : "";
    $mgid           = isset($_GET['mgid']) ? $_GET['mgid'] : "";
    $moid           = isset($_GET['moid']) ? $_GET['moid'] : "";
    $oid            = isset($_GET['oid']) ? $_GET['oid'] : "";
    $act            = isset($_GET['act']) ? $_GET['act'] : "";
	$name      	    = isset($_POST['ryyname']) ? $_POST['ryyname'] : "";
    $page_name      = isset($_POST['rtypage_name']) ? $_POST['rtypage_name'] : "";
	$parent_id      = isset($_POST['riyparent_id']) ? $_POST['riyparent_id'] : "";
    $file_type_id   = isset($_POST['riyfile_type_id']) ? $_POST['riyfile_type_id'] : "";
    $file_type      = "1"; // default - static
    $file_path      = "../pages/";
    $css_class      = isset($SETTINGS['datagrid_css_style']) ? $SETTINGS['datagrid_css_style'] : "default";
	$css_class_site = isset($SETTINGS['css_style']) ? $SETTINGS['css_style'] : "blue";
	$styis_create_file = isset($_POST['styis_create_file']) ? $_POST['styis_create_file'] : "";
	$refresh_panel  = false;
	$max_index 	    = "0";
	$menu_section_page = "";
	$dgpid          = "0"; // datagrid_page_id
	
	// Check if pages/ directory is writable
	if(!is_writable($file_path)){
		$msg = "6";
	}

    // Check for deleting non-removable menu groups
    if($mode == "delete"){
        $db->Query("SELECT * FROM ".TABLE_MENU." WHERE id=".(int)$rid);
        if($r__ = $db->FetchAssoc()){
            $page_name = $r__['page_name'];
            $file_type = $r__['file_type_id'];            
			if((int)$r__['file_type_id'] == (int)"0"){
				header("location: menu_options_manager.php?msg=7&moid=".$moid."&mgid=".$mgid);
				exit;
			}else if((int)$r__['is_removable'] == (int)"0"){
				header("location: menu_options_manager.php?msg=1&moid=".$moid."&mgid=".$mgid);
                exit;
            }
        }
		
		// get datagrid_page_id
		$sql = "SELECT
					".TABLE_DATAGRID_PAGES.".id
				FROM ".TABLE_MENU."
					LEFT OUTER JOIN ".TABLE_DATAGRID_PAGES." ON ".TABLE_MENU.".id = ".TABLE_DATAGRID_PAGES.".menu_id
				WHERE ".TABLE_MENU.".id = ".(int)$rid;
        $db->Query($sql);
		if($row = $db->FetchArray()){
			$dgpid = $row['id'];
		}
    }
    
    // Hide/Unhide Menu group
	if($act != "" && strtolower(_SITE_MODE) == "demo"){
		$msg = "2";			
	}else{
		// Up/Down menu item order
		if(($act == "up") || ($act == "down")){								
			$db->Query("SELECT id, order_index FROM ".TABLE_MENU." WHERE id=".(int)$oid);
			if($row_ = $db->FetchArray()){
				$first_id = $row_['id'];
				$first_order = $row_['order_index'];
				if($act == "up"){
					$sql = "SELECT id, order_index FROM ".TABLE_MENU." WHERE order_index <= ".$first_order." AND id != ".(int)$oid." AND parent_id = ".(int)$mgid." ORDER BY ABS(order_index) DESC LIMIT 0, 1";
					$db->Query($sql);					
				}else{
					$sql = "SELECT id, order_index FROM ".TABLE_MENU." WHERE order_index >= ".$first_order." AND id != ".(int)$oid." AND parent_id = ".(int)$mgid." ORDER BY ABS(order_index) ASC LIMIT 0, 1";
					$db->Query($sql);					
				}
				if($row_ = $db->FetchArray()){
					$second_id = $row_['id'];
					$second_order = $row_['order_index'];
					$sql = "UPDATE ".TABLE_MENU." SET order_index = ".$second_order." WHERE id = ".(int)$first_id;
					$db->Exec($sql);
					$sql = "UPDATE ".TABLE_MENU." SET order_index = ".$first_order." WHERE id = ".(int)$second_id;
					$db->Exec($sql);
					if($db->Error() == ""){
						$msg = "4";			
					}					
				}
			}
			if($db->Error() != ""){
				$msg = "3";			
			}
		}else if($act != ""){
			if($act == "Hide"){
				$hide_value = "1";
			}else{
				$hide_value = "0";
			}
			$db->Exec("UPDATE ".TABLE_MENU." SET is_hidden = ".(int)$hide_value." WHERE id=".(int)$moid);
			if($db->Error() == ""){
				$msg = "5";	
			}			
		}			
	}
	
	// Get Maximum order index
	if($mode == "add"){
		$sql = "SELECT MAX(order_index) as max_index FROM ".TABLE_MENU." WHERE parent_id = ".(int)$mgid;
		$db->Query($sql);
		if($row = $db->FetchAssoc()){
			$max_index = $row['max_index'];
		}		
	}
    
    $db->Query("SELECT * FROM ".TABLE_MENU." WHERE id=".(int)$mgid);
    if($r__ = $db->FetchAssoc()){
        $menu_section_page = $r__['name'];
    }
    
    if($page_name == ""){
        $db->Query("SELECT * FROM ".TABLE_MENU." WHERE id=".(int)$rid);
        if($r__ = $db->FetchAssoc()){
            $page_name = $r__['page_name'];
            $file_type = $r__['file_type_id'];            
        }        
    }    
  
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<head>
	<title><?php echo $SETTINGS['site_name']; ?> :: <?php echo lang('admin_panel'); ?></title>
    <meta http-equiv='Content-Type' content='text/html;charset=utf-8' />
    <link href="../styles/<?php echo $SETTINGS['css_style'];?>/style.css" type="text/css" rel="stylesheet">
	<style>
		.message_text { text-align:left; }
	</style>
    <script type="text/javascript">
		function ParentMenu(type){
            var lnkParentMenuEdit = (document.getElementById('lnkParentMenuEdit')) ? document.getElementById('lnkParentMenuEdit') : null;
            var lnkParentMenuCancel = (document.getElementById('lnkParentMenuCancel')) ? document.getElementById('lnkParentMenuCancel') : null;
            if(lnkParentMenuEdit && lnkParentMenuCancel){
                lnkParentMenuEdit.style.display = (type == 'edit') ? "none" : "";
                lnkParentMenuCancel.style.display = (type == 'edit') ? "" : "none";
                document.getElementById('riyparent_id').disabled = (type == 'edit') ? false : true;
            }
        }
	
		function fileTypeId_OnChange(val){
			if(val == ''){
				document.getElementById("lbl23").style.display = "none";
				document.getElementById("lbl4").style.display = "none";				
			}else if(val == 1){
				document.getElementById("styis_create_file").checked = false;
				document.getElementById("styis_create_file").disabled = true;
				if(document.getElementById("rtypage_name")) document.getElementById("rtypage_name").style.display = 'none';
				if(document.getElementById("lbl23")) document.getElementById("lbl23").style.display = "none";
				if(document.getElementById("lbl4")) document.getElementById("lbl4").style.display = "none";
			}else if(val == 4){
				document.getElementById("styis_create_file").checked = false;
				document.getElementById("styis_create_file").disabled = true;
				if(document.getElementById("rtypage_name")) document.getElementById("rtypage_name").style.display = '';
				if(document.getElementById("lbl23")) document.getElementById("lbl23").style.display = "none";
				if(document.getElementById("lbl4")) document.getElementById("lbl4").style.display = "";
			}else{
				document.getElementById("styis_create_file").checked = true;
				document.getElementById("styis_create_file").disabled = false;
				if(document.getElementById("rtypage_name")) document.getElementById("rtypage_name").style.display = '';
				if(document.getElementById("lbl23")) document.getElementById("lbl23").style.display = "";
				if(document.getElementById("lbl4")) document.getElementById("lbl4").style.display = "none";
			}
		}
	</script>
</head>

<!-- BEGIN MAIN CONTENT ARE -->
<body dir="<?php echo $SETTINGS['language_dir'];?>">
<?php echo page_breadcrumbs("menu_manager.php"); ?>
<br />

<?php

	################################################################################
	## +---------------------------------------------------------------------------+
	## | 1. Creating & Calling:                                                    | 
	## +---------------------------------------------------------------------------+
	##  *** define a relative (virtual) path to datagrid.class.php file and "pear" 
	##  *** directory (relatively to the current file)
	##  *** RELATIVE PATH ONLY ***
	
		define ("DATAGRID_DIR", "../modules/datagrid/");  /* Ex.: "datagrid/" */ 
		define ("PEAR_DIR", "../modules/datagrid/pear/"); /* Ex.: "datagrid/pear/" */
	  
		require_once(DATAGRID_DIR.'datagrid.class.php');
		require_once(PEAR_DIR.'PEAR.php');
		require_once(PEAR_DIR.'DB.php');
	
	ob_start();
	
	##  *** creating variables that we need for database connection
	  $config = new Config();
	  $DB_USER = $config->getUser();
	  $DB_PASS = $config->getPassword();
	  $DB_HOST = $config->getHost();
	  $DB_NAME = $config->getDatabase();
	  $DB_TYPE = $config->getDatabaseType();
	  
	  $db_conn = DB::factory($DB_TYPE);  /* don't forget to change on appropriate db type */
	  $result_conn = $db_conn->connect(DB::parseDSN($DB_TYPE.'://'.$DB_USER.':'.$DB_PASS.'@'.$DB_HOST.'/'.$DB_NAME));
	  if(DB::isError($result_conn)){ die($result_conn->getDebugInfo()); }  
	##  *** put a primary key on the first place 
	  $sql = "SELECT
			".TABLE_MENU.".id,
			CASE
				WHEN ".TABLE_MENU.".file_type_id = 0 THEN CONCAT('<a title=\"".lang("click_to_view")."\" class=\"".$css_class."_dg_a2\" href=\"', ".TABLE_MENU.".page_name, '\">', ".TABLE_MENU.".name, '</a>')
				WHEN ".TABLE_MENU.".file_type_id = 1 THEN CONCAT('<a title=\"".lang("click_to_view")."\" class=\"".$css_class."_dg_a2\" href=\"static_pages.php?page=', ".TABLE_MENU.".id, '\">', ".TABLE_MENU.".name, '</a>')
				WHEN ".TABLE_MENU.".file_type_id = 2 THEN CONCAT('<a title=\"".lang("click_to_view")."\" class=\"".$css_class."_dg_a2\" href=\"../pages/', ".TABLE_MENU.".page_name, '\">', ".TABLE_MENU.".name, '</a>')
				WHEN ".TABLE_MENU.".file_type_id = 3 THEN CONCAT('<a title=\"".lang("click_to_view")."\" class=\"".$css_class."_dg_a2\" href=\"../pages/', ".TABLE_MENU.".page_name, '\">', ".TABLE_MENU.".name, '</a>')
				WHEN ".TABLE_MENU.".file_type_id = 4 THEN CONCAT('<a title=\"".lang("click_to_view")."\" class=\"".$css_class."_dg_a2\" href=\"', ".TABLE_MENU.".page_name, '\">', ".TABLE_MENU.".name, '</a>')
				ELSE ".TABLE_MENU.".name
			END page_view_link,
			".TABLE_MENU.".page_name,
			".TABLE_MENU.".is_menu_group,
			".TABLE_MENU.".is_removable,
			".TABLE_MENU.".is_hidden,
			".TABLE_MENU.".icon,
			".TABLE_MENU.".parent_id,
			".TABLE_MENU.".order_index,
			CONCAT(".TABLE_MENU.".order_index, '&nbsp;&nbsp;[<a class=\"".$css_class."_dg_a\" title=\"Up\" href=\"menu_options_manager.php?act=up&oid=', ".TABLE_MENU.".id, '&mgid=".$mgid."\">&uarr;</a><a class=\"".$css_class."_dg_a\" title=\"Down\" href=\"menu_options_manager.php?act=down&oid=', ".TABLE_MENU.".id, '&mgid=".$mgid."\">&darr;</a>]') as link_order_index,
			CASE
				WHEN ".TABLE_MENU.".is_menu_item = 1 THEN 'Show'
				ELSE \"Don't Show\"
			END as my_is_menu_item,        
			CASE
				WHEN ".TABLE_MENU.".is_dashboard_icon = 1 THEN 'Show'
				ELSE \"Don't Show\"
			END as my_is_dashboard_icon,        
			CASE
				WHEN ".TABLE_MENU.".is_removable = 1 THEN 'Yes'
				ELSE 'No'
			END as my_removable,        
			CASE
				WHEN ".TABLE_MENU.".is_hidden = 1 THEN 'Unhide'
				ELSE 'Hide'
			END as hidden_link,
			CASE
				WHEN ".TABLE_MENU.".is_hidden = 1 THEN '<b>Yes</b> [Unhide]'
				ELSE '<b>No</b> [Hide]'
			END as hidden_link_view,
			CASE
				WHEN ".TABLE_MENU.".is_menu_group = 1 THEN ''
				ELSE page_name
			END as my_page_name,
			'Menu Options' as menu_options_link,
			CASE
				WHEN ".TABLE_MENU.".file_type_id = 1 THEN CONCAT('<a class=\"".$css_class."_dg_a2\" href=\"static_pages_manager.php?sp_mode=edit&sp_rid=', ".TABLE_STATIC_PAGES.".id, '\">[Edit Content]</a>')
				WHEN ".TABLE_MENU.".file_type_id = 2 THEN CONCAT('<a class=\"".$css_class."_dg_a2\" href=\"dynamic_pages_editor.php?dpid=', ".TABLE_DYNAMIC_PAGES.".id, '\">[Edit Content]</a>')
				WHEN ".TABLE_MENU.".file_type_id = 3 THEN CONCAT('<a class=\"".$css_class."_dg_a2\" href=\"datagrid_pages_editor.php?dpid=', ".TABLE_DATAGRID_PAGES.".id, '\" title=\"Edit Code\">[Code]</a>  <a class=\"".$css_class."_dg_a2\" href=\"datagrid_wizard.php?dpid=', ".TABLE_DATAGRID_PAGES.".id, '\" title=\"Edit by Wizard\">[Wizard]</a>')
				WHEN ".TABLE_MENU.".file_type_id = 4 THEN CONCAT('')
				ELSE 'Not Editable'
			END page_edit_link,
			".TABLE_MENU.".file_type_id,
			".TABLE_FILE_TYPES.".name as file_type_name
		FROM ".TABLE_MENU."
			LEFT OUTER JOIN ".TABLE_FILE_TYPES." ON ".TABLE_MENU.".file_type_id = ".TABLE_FILE_TYPES.".id
			LEFT OUTER JOIN ".TABLE_STATIC_PAGES." ON ".TABLE_MENU.".id = ".TABLE_STATIC_PAGES.".menu_id
			LEFT OUTER JOIN ".TABLE_DYNAMIC_PAGES." ON ".TABLE_MENU.".id = ".TABLE_DYNAMIC_PAGES.".menu_id
			LEFT OUTER JOIN ".TABLE_DATAGRID_PAGES." ON ".TABLE_MENU.".id = ".TABLE_DATAGRID_PAGES.".menu_id
		WHERE
			".TABLE_MENU.".is_menu_group = 0 AND
			".TABLE_MENU.".parent_id = ".(int)$mgid."";
		
	##  *** set needed options and create a new class instance 
	  $debug_mode = false;        /* display SQL statements while processing */    
	  $messaging = true;          /* display system messages on a screen */ 
	  $dgrid = new DataGrid($debug_mode, $messaging, $unique_prefix, DATAGRID_DIR);
	  if(strtolower(_SITE_MODE) == "demo") $dgrid->isDemo = true;
	  $dgrid->navigationBar = "<a class='".$css_class."_dg_a' href='menu_manager.php'>&laquo; Back to Menu Manager</a>";  
	
	##  *** set data source with needed options
	  $default_order_field = "order_index";
	  $default_order_type = "ASC";
	  $dgrid->DataSource($db_conn, $sql, $default_order_field, $default_order_type);
	  
	## +---------------------------------------------------------------------------+
	## | 2. General Settings:                                                      | 
	## +---------------------------------------------------------------------------+
	##  *** set encoding and collation (default: utf8/utf8_unicode_ci)
	/// $dg_encoding = "utf8";
	/// $dg_collation = "utf8_unicode_ci";
	/// $dgrid->SetEncoding($dg_encoding, $dg_collation);
	##  *** set interface language (default - English)
	 $dg_language = $SETTINGS['site_language'];  
	 $dgrid->SetInterfaceLang($dg_language);
	##  *** set direction: "ltr" or "rtr" (default - "ltr")
	 $direction = $SETTINGS['language_dir'];  
	 $dgrid->SetDirection($direction);
	##  *** set layouts: "0" - tabular(horizontal) - default, "1" - columnar(vertical), "2" - customized 
	/// $layouts = array("view"=>"0", "edit"=>"1", "details"=>"1", "filter"=>"1"); 
	/// $dgrid->setLayouts($layouts);
	/// $details_template = "<table><tr><td>{field_name_1}</td><td>{field_name_2}</td></tr>...</table>";
	/// $dgrid->setTemplates("","",$details_template);
	##  *** set modes for operations ("type" => "link|button|image") 
	##  *** "byFieldValue"=>"fieldName" - make the field to be a link to edit mode page
	 $modes = array(
		 "add"	=>array("view"=>true, "edit"=>false, "type"=>"link"),
		 "edit"	=>array("view"=>true, "edit"=>true,  "type"=>"link", "byFieldValue"=>""),
		 "cancel"   =>array("view"=>true, "edit"=>true,  "type"=>"link"),
		 "details"  =>array("view"=>false, "edit"=>false, "type"=>"link"),
		 "delete"   =>array("view"=>true, "edit"=>false,  "type"=>"image")
	 );
	 $dgrid->setModes($modes);
	##  *** allow scrolling on datagrid
	/// $scrolling_option = false;
	/// $dgrid->allowScrollingSettings($scrolling_option);  
	##  *** set scrolling settings (optional)
	/// $scrolling_width = "90%";
	/// $scrolling_height = "100%";
	/// $dgrid->setScrollingSettings($scrolling_width, $scrolling_height);
	##  *** allow mulirow operations
	  $multirow_option = false;
	  $dgrid->allowMultirowOperations($multirow_option);
	  $multirow_operations = array(
		 "delete"  => array("view"=>true),
		 "details" => array("view"=>false),
	 );
	 $dgrid->setMultirowOperations($multirow_operations);  
	##  *** set CSS class for datagrid
	##  *** "default" or "blue" or "gray" or "green" or "pink" or your own css file 
	 $dgrid->setCssClass($css_class);
	##  *** set variables that used to get access to the page (like: my_page.php?act=34&id=56 etc.) 
	 $http_get_vars = array("mgid");
	 $dgrid->setHttpGetVars($http_get_vars);
	##  *** set other datagrid/s unique prefixes (if you use few datagrids on one page)
	##  *** format (in which mode to allow processing of another datagrids)
	##  *** array("unique_prefix"=>array("view"=>true|false, "edit"=>true|false, "details"=>true|false));
	/// $anotherDatagrids = array("abcd_"=>array("view"=>true, "edit"=>true, "details"=>true));
	/// $dgrid->setAnotherDatagrids($anotherDatagrids);  
	##  *** set DataGrid caption
	 $dg_caption = "Menu Options Manager for ".$menu_section_page;
	 $dgrid->setCaption($dg_caption);

	## +---------------------------------------------------------------------------+
	## | 3. Printing & Exporting Settings:                                         | 
	## +---------------------------------------------------------------------------+
	##  *** set printing option: true(default) or false 
	 $printing_option = true;
	 $dgrid->allowPrinting($printing_option);
	##  *** set exporting option: true(default) or false and relative (virtual) path
	##  *** to export directory (relatively to datagrid.class.php file).
	##  *** Ex.: "" - if we use current datagrid folder
	 $exporting_option = false;
	 $exporting_directory = "../tmp/export/";               
	 $dgrid->allowExporting($exporting_option, $exporting_directory);

	## +---------------------------------------------------------------------------+
	## | 4. Sorting & Paging Settings:                                             | 
	## +---------------------------------------------------------------------------+
	##  *** set sorting option: true(default) or false 
	/// $sorting_option = true;
	/// $dgrid->allowSorting($sorting_option);               
	##  *** set paging option: true(default) or false 
	/// $paging_option = true;
	/// $rows_numeration = false;
	/// $numeration_sign = "N #";
	/// $dgrid->allowPaging($paging_option, $rows_numeration, $numeration_sign);
	##  *** set paging settings
	 #$bottom_paging = array("results"=>true, "results_align"=>"left", "pages"=>true, "pages_align"=>"center", "page_size"=>true, "page_size_align"=>"right");
	 #$top_paging = array();
	 #$pages_array = array("10"=>"10", "25"=>"25", "50"=>"50", "100"=>"100", "250"=>"250", "500"=>"500", "1000"=>"1000");
	 #$default_page_size = 10;
	 #$paging_arrows = array("first"=>"|&lt;&lt;", "previous"=>"&lt;&lt;", "next"=>"&gt;&gt;", "last"=>"&gt;&gt;|");
	 #$dgrid->setPagingSettings($bottom_paging, $top_paging, $pages_array, $default_page_size, $paging_arrows);

	## +---------------------------------------------------------------------------+
	## | 5. Filter Settings:                                                       | 
	## +---------------------------------------------------------------------------+
	##  *** set filtering option: true or false(default)
	# $filtering_option = true;
	# $show_search_type = true;
	# $dgrid->allowFiltering($filtering_option, $show_search_type);
	##  *** set aditional filtering settings
	# //$fill_from_array = array("0"=>"No", "1"=>"Yes");  /* as "value"=>"option" */
	# $filtering_fields = array(
	# );
	# $dgrid->setFieldsFiltering($filtering_fields);

	## +---------------------------------------------------------------------------+
	## | 6. View Mode Settings:                                                    | 
	## +---------------------------------------------------------------------------+
	##  *** set view mode table properties
	 $vm_table_properties = array("width"=>"85%");
	 $dgrid->setViewModeTableProperties($vm_table_properties);  
	##  *** set columns in view mode
	##  *** Ex.: "on_js_event"=>"onclick='alert(\"Yes!!!\");'"
	##  ***      "barchart" : number format in SELECT SQL must be equal with number format in max_value
	 $vm_colimns = array(
		"icon"              =>array("header"=>"Icon", "type"=>"image",      "align"=>"center", "width"=>"", "wrap"=>"nowrap", "text_length"=>"-1", "tooltip"=>"false", "tooltip_type"=>"floating|simple", "case"=>"normal|upper|lower|camel", "summarize"=>"false", "sort_type"=>"string|numeric", "sort_by"=>"", "visible"=>"true", "on_js_event"=>"", "target_path"=>"../images/icons/", "default"=>"", "image_width"=>"25px", "image_height"=>"25px", "magnify"=>"false", "magnify_type"=>"magnifier"),
		"page_view_link"    =>array("header"=>"Menu Option Name", "type"=>"label",  "align"=>"left", "width"=>"", "wrap"=>"nowrap", "text_length"=>"-1", "tooltip"=>false, "tooltip_type"=>"floating|simple", "case"=>"normal", "summarize"=>"true|false", "sort_by"=>"", "visible"=>"true", "on_js_event"=>""),
		//"type"=>"label",      "align"=>"left", "width"=>"", "wrap"=>"nowrap", "text_length"=>"-1", "tooltip"=>false, "tooltip_type"=>"floating|simple", "case"=>"normal|upper|lower", "summarize"=>"true|false", "sort_by"=>"", "visible"=>"true", "on_js_event"=>""),
		"file_type_name"    =>array("header"=>"File Type", "type"=>"label",      "align"=>"left", "width"=>"", "wrap"=>"nowrap", "text_length"=>"-1", "tooltip"=>false, "tooltip_type"=>"floating|simple", "case"=>"normal", "summarize"=>"true|false", "sort_by"=>"", "visible"=>"true", "on_js_event"=>""),    
		"my_is_menu_item"   =>array("header"=>" Menu ", "type"=>"label",      "align"=>"center", "width"=>"", "wrap"=>"nowrap", "text_length"=>"-1", "tooltip"=>false, "tooltip_type"=>"floating|simple", "case"=>"normal|upper|lower", "summarize"=>"true|false", "sort_by"=>"", "visible"=>"true", "on_js_event"=>""),
		"my_is_dashboard_icon" =>array("header"=>lang("dashboard"), "type"=>"label",      "align"=>"center", "width"=>"", "wrap"=>"nowrap", "text_length"=>"-1", "tooltip"=>false, "tooltip_type"=>"floating|simple", "case"=>"normal|upper|lower", "summarize"=>"true|false", "sort_by"=>"", "visible"=>"true", "on_js_event"=>""),    
		//"my_removable"      =>array("header"=>"Removable", "type"=>"label",      "align"=>"center", "width"=>"", "wrap"=>"nowrap", "text_length"=>"-1", "tooltip"=>false, "tooltip_type"=>"floating|simple", "case"=>"normal|upper|lower", "summarize"=>"true|false", "sort_by"=>"", "visible"=>"true", "on_js_event"=>""),
		"my_public"         =>array("header"=>"Public Access", "type"=>"label",      "align"=>"center", "width"=>"", "wrap"=>"nowrap", "text_length"=>"-1", "tooltip"=>false, "tooltip_type"=>"floating|simple", "case"=>"normal|upper|lower", "summarize"=>"true|false", "sort_by"=>"", "visible"=>"true", "on_js_event"=>""),
		"link_order_index"  =>array("header"=>lang("order"), "type"=>"label",      "align"=>"right", "width"=>"", "wrap"=>"nowrap", "text_length"=>"-1", "tooltip"=>false, "tooltip_type"=>"floating|simple", "case"=>"normal|upper|lower", "summarize"=>"true|false", "sort_type"=>"numeric", "sort_by"=>"order_index", "visible"=>"true", "on_js_event"=>"", "post_addition"=>"&nbsp;"),
		"hidden_link"       =>array("header"=>"Hidden", "type"=>"link",       "align"=>"center", "width"=>"", "wrap"=>"nowrap", "text_length"=>"-1", "tooltip"=>false, "tooltip_type"=>"floating|simple", "case"=>"normal|upper|lower", "summarize"=>"true|false", "sort_by"=>"", "visible"=>"true", "on_js_event"=>"", "field_key"=>"hidden_link", "field_key_1"=>"id", "field_data"=>"hidden_link_view", "rel"=>"", "title"=>"Hide/Unhide menu option", "target"=>"", "href"=>"menu_options_manager.php?act={0}&mgid=".$mgid."&moid={1}"),
		"page_edit_link"    =>array("header"=>" ", "type"=>"label",      "align"=>"center", "width"=>"", "wrap"=>"nowrap", "text_length"=>"-1", "tooltip"=>false, "tooltip_type"=>"floating|simple", "case"=>"normal", "summarize"=>"true|false", "sort_by"=>"", "visible"=>"true", "on_js_event"=>""),     
	 );
	 $dgrid->setColumnsInViewMode($vm_colimns);
	##  *** set auto-genereted columns in view mode
	//  $auto_column_in_view_mode = false;
	//  $dgrid->setAutoColumnsInViewMode($auto_column_in_view_mode);
	##
	##
	## +---------------------------------------------------------------------------+
	## | 7. Add/Edit/Details Mode Settings:                                        | 
	## +---------------------------------------------------------------------------+
	##  *** set add/edit mode table properties
	 $em_table_properties = array("width"=>"65%");
	 $dgrid->setEditModeTableProperties($em_table_properties);
	##  *** set details mode table properties
	/// $dm_table_properties = array("width"=>"70%");
	/// $dgrid->setDetailsModeTableProperties($dm_table_properties);
	##  ***  set settings for add/edit/details modes
	  $table_name  = TABLE_MENU;
	  $primary_key = "id";
	  $condition   = "";//"table_name.field = ".$_REQUEST['abc_rid'];
	  $dgrid->setTableEdit($table_name, $primary_key, $condition);
	##  *** set columns in edit mode
	 $fill_from_array_hidden = array("0"=>"No", "1"=>"Yes"); /* as "value"=>"option" */
	 $fill_from_array_removable = array("0"=>"No", "1"=>"Yes"); 
	 $fill_from_array_dashboard = array("0"=>"No", "1"=>"Yes"); 
	 $fill_from_array_menu      = array("0"=>"No", "1"=>"Yes");
	 
	 if(($file_type == "2" || $file_type == "3")){
		$page_name_post_addition = "<br />PHP pages will be placed in directory <b>pages/</b>";
	 }else if($file_type == "4"){	
		$page_name_post_addition = "<br />Ex.: http://www.domain.com or pages/my_page.php";
	 }else{
		$page_name_post_addition = "<br /><span id='lbl23' style='display:none;'>Use .php exention for PHP Simple and PHP Datagrid pages</span><span id='lbl4' style='display:none;'>Ex.: http://www.domain.com or pages/my_page.php</span>";
	 }
	 
	 if($file_type == "1" || $file_type == "2" || $file_type == "3"){
		$page_name_readonly = (($mode == "edit") ? "true" : "false");
	 }else if($file_type == "4"){
		$page_name_readonly = "false";
	 }else{
		$page_name_readonly = "true";
	 }
	 
	 if($file_type == "2" || $file_type == "3" || $file_type == "4"){
		$page_name_visible = "true";
	 }else if($file_type == "1"){
		$page_name_visible = (($mode == "edit") ? "false" : "true");
	 }else{	
		$page_name_visible = "false";
	 }
	 
	 $em_columns = array( 
		"name"           =>array("header"=>"Menu Option Name", "type"=>"textbox",   "req_type"=>"ry", "width"=>"210px", "title"=>"Menu Group Name", "readonly"=>false, "maxlength"=>"-1", "default"=>"", "unique"=>false, "unique_condition"=>"", "visible"=>"true", "on_js_event"=>""),
		"file_type_id"   =>array("header"=>"Page Type", "type"=>"foreign_key", "req_type"=>"ri", "width"=>"210px", "title"=>"", "readonly"=>(($mode == "edit") ? "true" : "false"), "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>(($file_type > "0") ? "true" : "false")),
		"page_name"      =>array("header"=>"Page Name", "type"=>"textbox",   "req_type"=>"rt", "width"=>"210px", "title"=>"Page Name", "readonly"=>$page_name_readonly, "maxlength"=>"-1", "default"=>"", "unique"=>true, "unique_condition"=>"(is_menu_group = 0 AND (file_type_id = 2 OR file_type_id = 3))", "visible"=>$page_name_visible, "on_js_event"=>"", "post_addition"=>$page_name_post_addition),
		"order_index"    =>array("header"=>"Order Index", "type"=>"textbox",   "req_type"=>"ri", "width"=>"50px", "title"=>"Order Index", "readonly"=>false, "maxlength"=>"3", "default"=>(($max_index < 999) ? $max_index + 1 : $max_index), "unique"=>false, "unique_condition"=>"", "visible"=>"true", "on_js_event"=>""),
		"is_removable"   =>array("header"=>"Removable",  "type"=>"enum",      "req_type"=>"st", "width"=>"210px", "title"=>"", "readonly"=>false, "maxlength"=>"-1", "default"=>"0", "unique"=>false, "unique_condition"=>"", "visible"=>(($file_type > "0") ? "true" : "false"), "on_js_event"=>"", "source"=>$fill_from_array_removable, "view_type"=>"dropdownlist", "radiobuttons_alignment"=>"horizontal|vertical", "multiple"=>false, "multiple_size"=>"4"),
		"is_hidden"      =>array("header"=>"Hidden",  "type"=>"enum",      "req_type"=>"st", "width"=>"210px", "title"=>"", "readonly"=>false, "maxlength"=>"-1", "default"=>"0", "unique"=>false, "unique_condition"=>"", "visible"=>"true", "on_js_event"=>"", "source"=>$fill_from_array_hidden, "view_type"=>"dropdownlist", "radiobuttons_alignment"=>"horizontal|vertical", "multiple"=>false, "multiple_size"=>"4"),
		"is_menu_item"   =>array("header"=>"Show in Menu?",  "type"=>"enum",      "req_type"=>"st", "width"=>"210px", "title"=>"", "readonly"=>false, "maxlength"=>"-1", "default"=>"1", "unique"=>false, "unique_condition"=>"", "visible"=>"true", "on_js_event"=>"", "source"=>$fill_from_array_menu, "view_type"=>"dropdownlist", "radiobuttons_alignment"=>"horizontal|vertical", "multiple"=>false, "multiple_size"=>"4"),
		"is_dashboard_icon" =>array("header"=>"Show in Dashboard?",  "type"=>"enum",      "req_type"=>"st", "width"=>"210px", "title"=>"", "readonly"=>false, "maxlength"=>"-1", "default"=>"1", "unique"=>false, "unique_condition"=>"", "visible"=>"true", "on_js_event"=>"", "source"=>$fill_from_array_dashboard, "view_type"=>"dropdownlist", "radiobuttons_alignment"=>"horizontal|vertical", "multiple"=>false, "multiple_size"=>"4"),
		"icon"           =>array("header"=>"Icon", "type"=>"image",     "req_type"=>"st", "width"=>"220px", "title"=>"", "readonly"=>"false", "maxlength"=>"-1", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true", "on_js_event"=>"", "target_path"=>"../images/icons/", "max_file_size"=>"100K", "image_width"=>"96px", "image_height"=>"96px", "magnify"=>"false", "file_name"=>"img_".((isset($_GET['meno_mode']) && ($_GET['meno_mode'] == "add")) ? $dgrid->GetRandomString("10") : $dgrid->GetCurrentId()), "host"=>"local", "magnify_type"=>"lightbox"),
		"is_create_file" =>array("header"=>"Create a File?", "type"=>"checkbox",          "req_type"=>"st", "width"=>"210px", "title"=>"", "readonly"=>false, "maxlength"=>"-1", "default"=>"1", "unique"=>false, "unique_condition"=>"", "visible"=>(($mode == "add") ? "true" : "false"), "on_js_event"=>"", "true_value"=>"1", "false_value"=>"0", "post_addition"=>"(for PHP Dynamic and PHP DataGrid pages)"),
		"is_menu_group"  =>array("header"=>"",       "type"=>"hidden",    "req_type"=>"st", "default"=>"0", "unique"=>false),
	 );
	
	 // handle parent dropdown list 
	 if($mode == "add"){
		$em_columns["parent_id"] = array("header"=>"", "type"=>"hidden", "req_type"=>"st", "default"=>(int)$mgid, "unique"=>false);
	 }else{
		$em_columns["parent_id"] = array("header"=>"Parent Menu", "type"=>"foreign_key", "req_type"=>"ri", "width"=>"210px", "title"=>"", "readonly"=>false, "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>true, "post_addition"=>" <a style='display:;' id='lnkParentMenuEdit' href='javascript:ParentMenu(\"edit\")'>[Edit]</a><a style='display:none;' id='lnkParentMenuCancel' href='javascript:ParentMenu(\"block\")'>[Block]</a>");
	 }
	 
	 $dgrid->setColumnsInEditMode($em_columns);
	##  *** set auto-genereted columns in edit mode
	//  $auto_column_in_edit_mode = false;
	//  $dgrid->setAutoColumnsInEditMode($auto_column_in_edit_mode);
	##  *** set foreign keys for add/edit/details modes (if there are linked tables)
	 $foreign_keys = array(
		"file_type_id" => array("table"=>TABLE_FILE_TYPES, "field_key"=>"id", "field_name"=>"name", "view_type"=>"dropdownlist", "radiobuttons_alignment"=>"horizontal|vertical", "condition"=>"", "order_by_field"=>"", "order_type"=>"ASC", "on_js_event"=>"onchange='fileTypeId_OnChange(this.value)'"),
		"parent_id"    =>array("table"=>TABLE_MENU, "field_key"=>"id", "field_name"=>"name", "view_type"=>"dropdownlist", "radiobuttons_alignment"=>"horizontal|vertical", "condition"=>"is_menu_group = 1 AND is_hidden = 0 AND parent_id = 0", "order_by_field"=>"order_index", "order_type"=>"ASC", "on_js_event"=>""),
	 ); 
	
	 $dgrid->setForeignKeysEdit($foreign_keys);
	##
	##
	################################################################################   

	if($msg == "1"){
		$default_msg = draw_message("error", "This menu option can not be removed, only hidden! <br>To remove it, please turn removable flag 'ON' before.", false, "85%", "../");
	}else if($msg == "2"){
		$default_msg = draw_message("error", "This operation is blocked in demo version.", false, "85%", "../");
	}else if($msg == "3"){
		$default_msg = draw_message("error", "An error occurred while changing order! Please tray again latter.", false, "85%", "../");
	}else if($msg == "4"){
		$default_msg = draw_message("success", "Menu option order was successfully changed.", false, "85%", "../");
		$refresh_panel = true;	
	}else if($msg == "5"){
		$default_msg = draw_message("success", "Menu option visibility was successfully changed.", false, "85%", "../");
		$refresh_panel = true;	
	}else if($msg == "6"){
		$default_msg = draw_message("error", "To create dynamic and/or datagrid pages you have to grant write permission to the 'pages/' directory.", false, "85%", "../");		
	}else if($msg == "7"){
		$default_msg = draw_message("error", "This menu option refers to the system and cannot be removed!", false, "85%", "../");		
	}

	if($msg != "" && $mode != "add" && $mode != "edit") $dgrid->actMsg = $default_msg;	
	
	$add_msg    = draw_message("success", "The adding operation was successfully completed! <br>To be sure that new changes will take effect, please <a href='javascript:parent.location.reload();'>refresh the site</a> or wait a few seconds.", false, "85%", "../");
	$update_msg = draw_message("success", "The updating operation was successfully completed! <br>To be sure that new changes will take effect, please <a href='javascript:parent.location.reload();'>refresh the site</a> or wait a few seconds.", false, "85%", "../");
	$delete_msg = draw_message("success", "The deleting operation was successfully completed! <br>To be sure that new changes will take effect, please <a href='javascript:parent.location.reload();'>refresh the site</a> or wait a few seconds.", false, "85%", "../");
	
	$dgrid->SetDgMessages($add_msg, $update_msg, $delete_msg); 

	## +---------------------------------------------------------------------------+
	## | 8. Bind the DataGrid:                                                     | 
	## +---------------------------------------------------------------------------+
	##  *** bind the DataGrid and draw it on the screen
	$dgrid->bind();
	ob_end_flush();
  

    //--------------------------------------------------------------------------
    // Menu item was deleted   
    //--------------------------------------------------------------------------
    if($mode == "delete" && $dgrid->IsOperationCompleted() && $rid != "")
	{        
		// delete if static page    
        if($file_type == "1"){
            $sql = "DELETE FROM ".TABLE_STATIC_PAGES." WHERE menu_id = ".(int)$rid;
            $db->Exec($sql);            
        }else
        // delete PHP Dynamic page        
        if($file_type == "2"){        
            // delete from table
            $sql = "DELETE FROM ".TABLE_DYNAMIC_PAGES." WHERE menu_id = ".(int)$rid;
            $db->Exec($sql);
            // delete file
            @chdir($file_path);
            @unlink($page_name);            
        }else
        // delete PHP DataGrid page        
        if($file_type == "3"){
            // delete from table
            $sql = "DELETE FROM ".TABLE_DATAGRID_PAGES." WHERE menu_id = ".(int)$rid;
            $db->Exec($sql);
            // delete file
            @chdir($file_path);
            @unlink($page_name);
			
			// delete all data from related tables
            $sql = "DELETE FROM ".TABLE_DG_WIZARD_FIELDS." WHERE datagrid_page_id = ".(int)$dgpid;
            $db->Exec($sql);			
			$sql = "DELETE FROM ".TABLE_DG_WIZARD_SETTINGS." WHERE datagrid_page_id = ".(int)$dgpid;
			$db->Exec($sql);
			$sql = "DELETE FROM ".TABLE_DG_WIZARD_FILTERING." WHERE datagrid_page_id = ".(int)$dgpid;
			$db->Exec($sql);			
			$sql = "DELETE FROM ".TABLE_DG_WIZARD_FOREIGN_KEYS." WHERE datagrid_page_id = ".(int)$dgpid;
			$db->Exec($sql);                    			
        }
    }

    //--------------------------------------------------------------------------
    // Menu item was created
    //--------------------------------------------------------------------------
    if($mode == "update" && $rid == "-1" && $dgrid->IsOperationCompleted())
	{
        // create static page
        if($file_type_id == "1"){
            $page_text = "This is HTML static page <br/>";
            $page_text .= "This page was created on: ".date("M d, Y g:i A")." <br/>";
            
            $sql = "INSERT INTO ".TABLE_STATIC_PAGES." (id, menu_id, page_header, page_text, created_at, updated_at)
                    VALUES (NULL, ".(int)$dgrid->GetCurrentId().", '".$name."', '".$page_text."', '".date("Y-m-d H:i:s")."', '0000-00-00 00:00:00')";
            $db->Exec($sql);
        }
        
        // create PHP Dynamic page
        if($file_type_id == "2")
        {
            // add missed .php extention
            if(!preg_match("/.php/i", $page_name)){
                $page_name .= ".php";
                $sql = "UPDATE ".TABLE_MENU." SET page_name = '".$page_name."' WHERE id = ".(int)$dgrid->GetCurrentId();                        
                $db->Exec($sql);               
            }

            $sql = "INSERT INTO ".TABLE_DYNAMIC_PAGES." (id, menu_id, page_header, created_at, updated_at)
                    VALUES (NULL, ".(int)$dgrid->GetCurrentId().", '', '".date("Y-m-d H:i:s")."', '0000-00-00 00:00:00')";
            $db->Exec($sql);
            
			if($styis_create_file == "1"){
				// create a file
				@chmod($file_path, 0777);
				$handle = fopen($file_path.$page_name,'w+');
				if($handle){
					$file_content = file_get_contents("templates/php_dynamic_file.tpl");					
					$file_content = str_replace("<CSS_STYLE>", $css_class_site, $file_content);
					$file_content = str_replace("<DATE_CREATED>", date("M d, Y g:i A"), $file_content);
					$file_content = str_replace("<FILE_NAME>", $page_name, $file_content);
					fwrite($handle, $file_content);
					fclose($handle);
				}else{
					//error
				}
				@chmod($file_path, 0755);
			}	
        }
        
        // create PHP DataGrid page
        if($file_type_id == "3")
        {
            // add missed .php extention
            if(!preg_match("/.php/i", $page_name)){
                $page_name .= ".php";
                $sql = "UPDATE ".TABLE_MENU." SET page_name = '".$page_name."' WHERE id = ".(int)$dgrid->GetCurrentId();                        
                $db->Exec($sql);               
            }

            $sql = "INSERT INTO ".TABLE_DATAGRID_PAGES." (id, menu_id, page_header, created_at, updated_at)
                    VALUES (NULL, ".(int)$dgrid->GetCurrentId().", '', '".date("Y-m-d H:i:s")."', '0000-00-00 00:00:00') ";
            $db->Exec($sql);
			$insertID = $db->InsertID();

			if($styis_create_file == "1"){
				// create a file
				@chmod($file_path, 0777);
				$handle = fopen($file_path.$page_name,'w+');
				if($handle){
					$file_content = file_get_contents("templates/php_datagrid_file.tpl");
					$file_content = str_replace("<DATE_CREATED>", date("M d, Y g:i A"), $file_content);
					$file_content = str_replace("<FILE_NAME>", $page_name, $file_content);
					fwrite($handle, $file_content);
					fclose($handle);
				}else{
					//error 
				}
				@chmod($file_path, 0755);
				$_SESSION['content_type'] = "datagrid";
				$_SESSION['dgpid'] = (int)$insertID;
				redirect_to("../index.php", "parent");
				exit;
			}
        }
    }
	
    //--------------------------------------------------------------------------
    // Module item was updated
    //--------------------------------------------------------------------------
    if($mode == "update" && $rid != "-1" && $dgrid->IsOperationCompleted())
	{
		$sql = "SELECT id, parent_menu_id FROM ".TABLE_MODULES." WHERE menu_id = ".(int)$rid;
		$db->Query($sql);
		if($row = $db->FetchArray()){
			$sql = "UPDATE ".TABLE_MODULES." SET parent_menu_id = ".(int)$parent_id." WHERE id = ".(int) $row['id'];
			$db->Exec($sql);                    
		}		
	}	
    
	if(strtolower(_SITE_MODE) != "demo"){		
		if($dgrid->IsOperationCompleted() || $refresh_panel){
			if($file_type_id == "1"){
				$_SESSION['content_type'] = "static";
				redirect_to("../index.php", "parent");
			}else if($file_type_id == "2"){
				$_SESSION['content_type'] = "dynamic";
				redirect_to("../index.php", "parent");
			}else{
				redirect_to("../index.php", "parent", 1000);
			}
			exit;
		}
	}    
 
?>
<br />
<script type="text/javascript">
    if(document.getElementById('riyparent_id')) document.getElementById('riyparent_id').disabled=true;
</script>
</body>
</html>	
Return current item: Basic Announce