<?php
/*
+- Q Tree Menu -------------------------------------------------+
|                                                               |
| File        : q_tree_menu/menu_var.php                        |
| Coding      : Rijk van Wel, aka Ridge                         |
| Description : Build menu's javascript file from database      |
|                                                               |
| ************************************************************* |
| For the e107 website system © Steve Dunstan 2001-2005         |
| http://e107.org - jalist@e107.org                             |
|                                                               |
| Released under the terms and conditions of the                |
| GNU General Public License (http://gnu.org).                  |
+---------------------------------------------------------------+
*/
define('e_SELF', $_GET['e_SELF']);
require_once("../../class2.php");

// Functions :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
   echo "
   function BeforeStart()
      {// Size div element
       document.getElementById('q_tree').style.width = DivWidth+\"px\";
       document.getElementById('q_tree').style.height = DivHeight+\"px\";
      }

   function BeforeFirstOpen(){return}
   function AfterCloseAll(){return}
   
   function AfterBuild(){return}";

// General preferences :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
   echo "
   var LowBgColor=\"".($pref['Q_Tree_lowbgcolor'] != 'TTTTTT' ? "#".$pref['Q_Tree_lowbgcolor'] : "")."\";  
   var HighBgColor=\"".($pref['Q_Tree_highbgcolor'] != 'TTTTTT' ? "#".$pref['Q_Tree_highbgcolor'] : "")."\";  
   var FontLowColor=\"".($pref['Q_Tree_fontlowcolor'] != 'TTTTTT' ? "#".$pref['Q_Tree_fontlowcolor'] : "")."\";  
   var FontHighColor=\"".($pref['Q_Tree_fonthighcolor'] != 'TTTTTT' ? "#".$pref['Q_Tree_fonthighcolor'] : "")."\";   
   var BorderColor=\"".($pref['Q_Tree_bordercolor'] != 'TTTTTT' ? "#".$pref['Q_Tree_bordercolor'] : "")."\"; 

   var BorderWidthMain=".$pref['Q_Tree_borderwidthmain'].";   // Border width main items
   var BorderWidthSub=".$pref['Q_Tree_borderwidthsub'].";   // Border width sub items
   var BorderBtwnMain=".$pref['Q_Tree_borderbtwnmain'].";   // Border width between elements main items
   var BorderBtwnSub=".$pref['Q_Tree_borderbtwnsub'].";   // Border width between elements sub items

   var FontBold=".($pref['Q_Tree_fontbold'] == '' ? '0' : $pref['Q_Tree_fontbold']).";    // Bold menu items 1 or 0
   var FontItalic=".($pref['Q_Tree_fontitalic'] == '' ? '0' : $pref['Q_Tree_fontitalic']).";    // Italic menu items 1 or 0
   var MenuTextCentered=\"".$pref['Q_Tree_textalign']."\";  // Item text position left, center or right\n";
   
   if ($pref['Q_Tree_arw'])
   		echo "var Arrws=[\"".SITEURL.$PLUGINS_DIRECTORY."q_tree_menu/images/arrow-right.gif\",15,7,\"".SITEURL.$PLUGINS_DIRECTORY."q_tree_menu/images/arrow-down.gif\",15,15,\"".SITEURL.$PLUGINS_DIRECTORY."q_tree_menu/images/arrow-left.gif\",15,7,\"".SITEURL.$PLUGINS_DIRECTORY."q_tree_menu/images/arrow-up.gif\",15,15];";
   else 
   		echo "var Arrws=new Array();";


// Advanced settings :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
   echo "
   var UnfoldsOnClick=".($pref['Q_Tree_uoc'] == '' ? '0' : $pref['Q_Tree_uoc']).";           // Level 1 unfolds onclick/onmouseover
   var FirstLineHorizontal=".($pref['Q_Tree_flh'] == '' ? '0' : $pref['Q_Tree_flh']).";      // Horizontal/vertical menu 
   var ChildOverlap=".str_replace(',','.',$pref['Q_Tree_co']).";            // horizontal overlap child/ parent
   var ChildVerticalOverlap=".str_replace(',','.',$pref['Q_Tree_cvo']).";    // vertical overlap child/ parent
   var StartTop=".$pref['Q_Tree_st'].";                 // Menu offset x coordinate
   var StartLeft=".$pref['Q_Tree_sl'].";                // Menu offset y coordinate
   var LeftPaddng=".$pref['Q_Tree_lp'].";              // Left padding
   var TopPaddng=".$pref['Q_Tree_tp'].";                // Top padding. If set to -1 text is vertically centered
   var DissapearDelay=".$pref['Q_Tree_dd'].";        // Delay before menu folds in
   var UnfoldDelay=".$pref['Q_Tree_ud'].";            // Delay before sub unfolds
   var RightToLeft=".($pref['Q_Tree_rtl'] == '' ? '0' : $pref['Q_Tree_rtl']).";              // Enables/disables right to left unfold 1 or 0
   var BottomUp=".($pref['Q_Tree_bu'] == '' ? '0' : $pref['Q_Tree_bu']).";                 // Enables/disables bottom up unfold 1 or 0
   var HooverBold=".($pref['Q_Tree_hb'] == '' ? '0' : $pref['Q_Tree_hb']).";               // Text of menu item bold when mouse is over
   var HooverItalic=".($pref['Q_Tree_hi'] == '' ? '0' : $pref['Q_Tree_hi']).";             // Text of menu item italic when mouse is over
   var HooverUnderLine=".($pref['Q_Tree_hul'] == '' ? '0' : $pref['Q_Tree_hul']).";          // Text of menu item underlined when mouse is over
   var HooverTextSize=".($pref['Q_Tree_hts'] == '' ? '0' : $pref['Q_Tree_hts']).";           // 0=off, number is font size difference on mouse over
   var HooverVariant=".($pref['Q_Tree_hv'] == '' ? '0' : $pref['Q_Tree_hv']).";            // Text of menu item in caps when mouse is over
   var MenuVerticalCentered=\"".$pref['Q_Tree_mvc']."\"; // ´static´ for sliding menu
   var BuildOnDemand=".($pref['Q_Tree_bod'] == '' ? '0' : $pref['Q_Tree_bod']).";            // Submenu's are built when mouse is over
   var BuildPause=".($pref['Q_Tree_bp'] == '' || $pref['Q_Tree_bp'] == 0 ? '1' : $pref['Q_Tree_bp']).";

   ".($pref['Q_Tree_slide'] == 1 ? "
        var MenuSlide=\"progid:DXImageTransform.Microsoft.RevealTrans(duration=.5, transition=19)\"; 
        var MenuSlide=\"progid:DXImageTransform.Microsoft.GradientWipe(duration=.5, wipeStyle=1)\";
   " : "var MenuSlide=\"\";")."
   ".($pref['Q_Tree_shadow'] == 1 ? "
        var MenuShadow=\"progid:DXImageTransform.Microsoft.DropShadow(color=#888888, offX=2, offY=2, positive=1)\"; 
        var MenuShadow=\"progid:DXImageTransform.Microsoft.Shadow(color=#888888, direction=135, strength=3)\"; 
   " : "var MenuShadow=\"\";")."
   ".($pref['Q_Tree_opacity'] == 1 ? "
        var MenuOpacity=\"progid:DXImageTransform.Microsoft.Alpha(opacity=90)\";
   " : "var MenuOpacity=\"\";")."

   "; ?>

// :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::































var FontFamily="";
var FontSize=12;
var MenuCentered="left";
var MenuWrap=1;
var BaseHref="";
var TargetLoc="q_tree";
var VerCorrect=0;
var HorCorrect=0;
var TakeOverBgColor=1;
var OverFormElements=1;

var MenuUsesFrames=0;
var DistFrmFrameBrdr=0;
var MenuFramesVertical=1;
var FirstLineFrame="";
var SecLineFrame="";
var DocTargetFrame="";

var RememberStatus=0;
var BgImgLeftOffset=0;
var ScaleMenu=0;


<?php
function q_create_link($link_id=0, $level=0, $item_id=0, $prefix='') {
	
	global $pref;
	
	if ($level == 1) 
		$prefix = '';
	
	$child_num = 0;

	/* Fetch link's childs */
	$db = new db;
	$db->db_Select("links", "*", "link_category='".($pref['Q_Tree_cat'] ? $pref['Q_Tree_cat'] : '1')."' AND link_parent=".$link_id." ORDER BY link_order ASC");
	while ($child = $db->db_Fetch()) {
		if (check_class($child['link_class'])) {
			$child_num ++;
			q_create_link($child['link_id'], $level+1, $child_num, $prefix.$item_id.'_');
		}
	}

	/* Build link */
	$db = new db;
	$db->db_Select("links", "*", "link_id = ".$link_id);
	if ($link = $db->db_Fetch()) {

		$bgimage	= ($level == 1 ? $pref['Q_Tree_mainbgimage'] : $pref['Q_Tree_subbgimage']);
		$height		= ($level == 1 ? $pref['Q_Tree_mainheight'] : $pref['Q_Tree_subheight']);
		$width		= ($level == 1 ? $pref['Q_Tree_mainwidth'] : $pref['Q_Tree_mainwidth']);
		$fontfamily	= ($level == 1 ? $pref['Q_Tree_mainfontfamily'] : $pref['Q_Tree_subfontfamily']);
		$fontsize	= ($level == 1 ? $pref['Q_Tree_mainfontsize'] : $pref['Q_Tree_subfontsize']);
		$bold		= ($level == 1 ? ($pref['Q_Tree_mainbold'] ? $pref['Q_Tree_mainbold'] : "-1") : ($pref['Q_Tree_subbold'] ? $pref['Q_Tree_subbold'] : "-1"));
		$page		= q_link_url($link['link_url'], $link['link_open']);
		$name		= q_link_name($link);
		
		if ($pref['Q_Tree_act'] && $page == e_SELF)
			$bold = 1;
		
		echo 'Menu'.$prefix.$item_id.'=new Array("'.$name.'","'.$page.'","'.$bgimage.'",'.$child_num.',"'.$height.'","'.$width.'","","","","","","'.$fontfamily.'","'.$fontsize.'",'.$bold.',-1,"","'.$link['link_description']."\");\n";
	}
	
	/* Return for no. of main items */
	return $child_num;
}

$main_num = q_create_link();
echo "var NoOffFirstLineMenus=".$main_num.";\n";

// Calculate width and height of menu's div element ::::::::::::::::::::::::::::::::
if ($pref['Q_Tree_flh'] == 1)
   {$divwidth  = $main_num * $pref['Q_Tree_mainwidth'] + 
                 ($main_num-1) * $pref['Q_Tree_borderbtwnmain'] +
                 2 * $pref['Q_Tree_borderwidthmain'];
    $divheight = 2 * $pref['Q_Tree_borderwidthmain'] +
                 $pref['Q_Tree_mainheight'];
   }
else
   {$divheight = $main_num * $pref['Q_Tree_mainheight'] + 
                 ($main_num-1) * $pref['Q_Tree_borderbtwnmain'] +
                 2 * $pref['Q_Tree_borderwidthmain'];
    $divwidth  = 2 * $pref['Q_Tree_borderwidthmain'] +
                 $pref['Q_Tree_mainwidth'];
   }
echo "var DivHeight=".$divheight.";\n
      var DivWidth =".$divwidth.";\n";

function q_link_url($link_url, $link_open)
   {if ($link_url != "" )
       {if (!strstr($link_url, "http:")) 
           $link_url = e_HTTP.$link_url;
        switch ($link_open)
           {case 1:
             $link = "javascript:NewWin=window.open(\'".(strstr($link_url, "http:") ? $link_url : e_HTTP.$link_url)."\');window[\\\"NewWin\\\"].focus()";
            break;
            case 4:
             $link = "javascript:open_window(\'".$link_url."\')";
            break;
            default:
             $link = $link_url;
           }
       }
    else
       $link = "";

    /* Since v0.7.6 */
    global $tp;
    $link = $tp->replaceConstants($link,TRUE);
       
    return $link;
   }

function q_link_name($link)
   {$string = $link['link_name'];
   	$icon = $link['link_button'];
   	$page = q_link_url($link['link_url'], $link['link_open']);
   	
   	$string = preg_replace("/(\r\n|\n|\r)/", "", $string);
    $string = str_replace ( '&#039;', '\'', $string );
    $string = str_replace ( '&#39;', '\'', $string );
    $string = str_replace ( '&quot;', '\"', $string );
    $string = str_replace ( '&lt;', '<', $string );
    $string = str_replace ( '&gt;', '>', $string );
    $string = str_replace ( '&amp;', '&', $string );
    
    // Temporary for phasing out
    if (substr($string,0,8) == "submenu.")
       {$tmp = explode(".",$string);
        $no = count($tmp);
        $string = $tmp[($no-1)];
       }

    global $pref;
	if ($pref['Q_Tree_ico'] && $icon) {
		$string = "<div style='padding-top:".$pref['Q_Tree_tp']."px; padding-left:".$pref['Q_Tree_lp']."px;'><img src='".e_IMAGE_ABS."icons/".$icon."' style='float:left; margin-top:-1px;' />&nbsp;".$string."</div>";
	}
	
    return $string;
   }
   
?>