<?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 ##########################

if ( $_REQUEST['do'] == 'updatesublink' ) 
{

$vbulletin->input->clean_array_gpc('p', array(
	'childid'=> TYPE_INT, 
	'tabid'=> TYPE_INT, 
	'title'=> TYPE_STR,
	'vbphrase'=> TYPE_STR,
	'url'=> TYPE_STR,
    'image'=> TYPE_STR, 
	'target'=> TYPE_STR,
	'allowedusergroup'=> TYPE_ARRAY,
	'blockedusergroup'=> TYPE_ARRAY,
	'enable'=> TYPE_INT,
	'displayorder'=> TYPE_INT,
    'notes'=> TYPE_STR,
	'type'=> TYPE_STR,
	));
	
	$childid = intval($vbulletin->GPC['childid']);
	$tabid = intval($vbulletin->GPC['tabid']);
	$title = str_replace ("'", "''", $vbulletin->GPC['title']);
	$phrase = str_replace ("'", "''", $vbulletin->GPC['vbphrase']);
	$url = str_replace ("'", "''", $vbulletin->GPC['url']);
    $image = $vbulletin->GPC['image'];
	$target = $vbulletin->GPC['target'];
	$allowedusergroup = implode(",", $vbulletin->GPC['allowedusergroup']);
	$blockedusergroup = implode(",", $vbulletin->GPC['blockedusergroup']);
	$enable = $vbulletin->GPC['enable'];
	$displayorder = $vbulletin->GPC['displayorder'];
    $notes = $vbulletin->GPC['notes'];
	
	
	if ($vbulletin->GPC['type']!='submenu')
	{
		$type = 'menuitem';
	}
	else
	{
		$type = 'submenu';
	}
	
	if (empty($vbulletin->GPC['childid']))
	{
		$db->query_write("INSERT INTO " . TABLE_PREFIX . "dbtech_vbnavtabs_childs(tabid,title,vbphrase,url,image,target,allowedusergroup,blockedusergroup,enable,type,displayorder,notes)
				VALUES (
				'".$tabid."',
				'".$title."',
				'".$phrase."',
				'".$url."',
                '".$image."',
				'".$target."',
				'".$allowedusergroup."',
				'".$blockedusergroup."',
				'".$enable."',
				'".$type."',
				'".$displayorder."',
                '".$notes."'
				)");
	}
	else
	{
		$db->query_write("UPDATE " . TABLE_PREFIX . "dbtech_vbnavtabs_childs SET 
		tabid = '".$tabid."',
		title = '".$title."',
		vbphrase = '".$phrase."',
		url = '".$url."',
        image = '".$image."',
		target = '".$target."',
		allowedusergroup = '".$allowedusergroup."',
		blockedusergroup = '".$blockedusergroup."',
		enable = '".$enable."',
		displayorder = '".$displayorder."',
        notes = '".$notes."' 
		WHERE childid =$childid");
	}

	$tab_query = $vbulletin->db->query_read("
		SELECT 
			t.tabid,
            t.type_of_tab, 
			t.title, 
			t.vbphrase, 
			t.url, 
			t.tabmode, 
			t.image, 
			t.script, 
			t.target, 
			t.allowedusergroup, 
			t.blockedusergroup, 
			t.position, 
			t.enable, 
			c.childid, 
			c.title as ctitle, 
			c.vbphrase as cvbphrase, 
			c.url as curl,
            c.image as cimage, 
			c.target as ctarget, 
			c.allowedusergroup as callowedusergroup, 
			c.blockedusergroup as cblockedusergroup, 
			c.type, 
			c.enable as cenable
		FROM " . TABLE_PREFIX . "dbtech_vbnavtabs as t 
		LEFT JOIN " . TABLE_PREFIX . "dbtech_vbnavtabs_childs as c ON t.tabid=c.tabid 
		WHERE 
			t.enable=1 
		ORDER BY 
			t.displayorder, 
			c.type, 
			c.displayorder
	");

	while ($tabs = $vbulletin->db->fetch_array($tab_query))
	{
		$tab_cache[$tabs['tabid'] . '_' . $tabs['childid']] = $tabs;
	}

	build_datastore('dbtech_vbnavtabs_tabs', serialize($tab_cache), true);

}		

define('CP_REDIRECT', 'vbnavtabs.php?do=sublink');
print_stop_message('dbtech_vbnavtabs_sublink_update');

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

?>