<?php

/*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*\
<< ******************************************************************** >>
<< * ---------------------------------------------------------------- * >>
<< * Copyright ©2011-2012 Ozzy47                                      * >>
<< * All Rights Reserved. 											  * >>
<< * This file may not be redistributed in whole or significant part. * >>
<< * ---------------------------------------------------------------- * >>
<< * You are not allowed to use this on your server unless the files  * >>
<< * you downloaded were done so with permission.					  * >>
<< * ---------------------------------------------------------------- * >>
<< ******************************************************************** >>
\*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*/

// ############################# LOG ACTION ##############################
log_admin_action();
// ############################# END LOG ACTION ##########################

print_cp_header();

if ( $_REQUEST['do'] == 'sublink') 
{
	{
		$type = 'submenu' ;
		$form= 'ordersublink';
		$plusurl= "&type=submenu";
		$headtitle = $vbphrase['dbtech_vbnavtabs_manage_submenu'];
	}
	
	print_form_header('vbnavtabs', $form, 0, 1, 'sublink');
	print_table_header($headtitle,6);
	$sql = "SELECT IF(isnull(tab.title),'".$vbphrase['dbtech_vbnavtabs_no_asigned']."',tab.title) 
    as parent, child.childid, child.tabid, child.title, child.url, child.target, child.allowedusergroup, child.blockedusergroup, child.enable, child.displayorder  
	FROM " . TABLE_PREFIX . "dbtech_vbnavtabs_childs as child 
	LEFT JOIN " . TABLE_PREFIX . "dbtech_vbnavtabs as tab on child.tabid=tab.tabid
	WHERE child.type='$type'
	ORDER BY tab.tabid,displayorder
	";
	$result = $db->query_read($sql);

	if ($db->num_rows($result))
	{
		$newtitle = '';
		while( $sourceitem = $db->fetch_array( $result ) ) 
		{
			if ($newtitle!=$sourceitem['parent'])
			{
				print_table_header($sourceitem['parent'].construct_link_code($vbphrase['dbtech_vbnavtabs_edit'], "vbnavtabs.php?$session[sessionurl]do=edittab&amp;tabid=$sourceitem[tabid]"),6,false,'','center');
				$newtitle=$sourceitem['parent'];

    if ($vbulletin->options['dbtech_vbnavtabs_displayusergroups'])
    {                        
	print_cells_row(array($vbphrase['dbtech_vbnavtabs_sublink_cell'],
			$vbphrase['dbtech_vbnavtabs_sublinks_url'],
			$vbphrase['dbtech_vbnavtabs_ug_title'],
			$vbphrase['dbtech_vbnavtabs_active'],
			$vbphrase['dbtech_vbnavtabs_display_order'],
			$vbphrase['dbtech_vbnavtabs_controls']
			), 1, '', -1);
    } else
    {	
            print_cells_row(array($vbphrase['dbtech_vbnavtabs_sublink_cell'],
			$vbphrase['dbtech_vbnavtabs_sublinks_url'],
			$vbphrase['dbtech_vbnavtabs_active'],
			$vbphrase['dbtech_vbnavtabs_display_order'],
			$vbphrase['dbtech_vbnavtabs_controls']
			), 1, '', -1);
    }                
                
			}
			$cell = array();
			$cell[1] = $sourceitem['title'] . '<input name="idmasschange['.$sourceitem['childid'].']" type="hidden" value="'.$sourceitem['childid'].'">';
			$cell[2] = $sourceitem['url'] . "<dfn>target = ".$sourceitem['target']."</dfn>";
            
   if ($vbulletin->options['dbtech_vbnavtabs_displayusergroups'])
			$cell[3] = "<div>".construct_phrase($vbphrase['dbtech_vbnavtabs_ug_allowed'],$sourceitem['allowedusergroup'])."</div> <div>".construct_phrase($vbphrase['dbtech_vbnavtabs_ug_not_allowed'],$sourceitem['blockedusergroup'])."</div>";
            
			if ($sourceitem['enable']==1)
			{
				$check = 'checked="checked"';
			}
			else
			{
				$check = "";
			}
			
			$cell[4] = '<input name="active['.$sourceitem['childid'].']" '.$check.' type="checkbox">';
			$cell[5] = "
						<input style=\"text-align: center\" type=\"text\" class=\"bginput\" name=\"order[" . $sourceitem['childid'] . "]\" tabindex=\"1\" value=\"$sourceitem[displayorder]\" size=\"4\" title=\"".$vbphrase['dbtech_vbnavtabs_order_display']."\" class=\"smallfont\" />
			";
			$cell[6] = "" .
					construct_link_code($vbphrase['dbtech_vbnavtabs_edit'], "vbnavtabs.php?$session[sessionurl]do=editsublink&amp;childid=$sourceitem[childid]$plusurl") .
					construct_link_code($vbphrase['dbtech_vbnavtabs_delete'], "vbnavtabs.php?$session[sessionurl]do=deletesublink&childid=$sourceitem[childid]$plusurl");
			print_cells_row($cell, 0, '', 1);
		}
	}
	else
	{
		print_description_row('<center>'.$vbphrase['dbtech_vbnavtabs_no_item_menu'].'</center>',0,6);
	}
        print_submit_row($vbphrase['dbtech_vbnavtabs_save_changes'], false, count($headings), false, "<input type=\"button\" id=\"addnew\" class=\"button\" value=\"" . str_pad($vbphrase['dbtech_vbnavtabs_add_new_sublink_item'], 8, ' ', STR_PAD_BOTH) . "\" tabindex=\"1\" onclick=\"window.location = 'vbnavtabs.php?do=newsublink$plusurl'\" />");
}

print_cp_footer();

/*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*\
<< ********************************************************************* >>
<< * Created: 19:30, Fri Nov 25th 2011                                 * >>
<< * VER: 1.0.1                                                        * >>
<< ********************************************************************* >>
\*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*/

?>