<?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'] == 'updatetab' ) 
{
$vbulletin->input->clean_array_gpc('p', array(
	'tabid'=> TYPE_INT,
    'type_of_tab'=>TYPE_STR,
    'tab'=>TYPE_STR,
	'title'=> TYPE_STR, 
	'vbphrase'=> TYPE_STR, 
	'url'=> TYPE_STR, 
	'image'=> TYPE_STR,
    'tabtype'=>TYPE_STR,
	'tabmode'=>TYPE_STR,
	'script'=> TYPE_STR, 
	'target'=> TYPE_STR,
	'allowedusergroup'=> TYPE_ARRAY,
	'blockedusergroup'=> TYPE_ARRAY,
	'enable'=> TYPE_INT,
	'position'=> TYPE_STR,
	'displayorder'=> TYPE_INT,
    'notes'=> TYPE_STR,
	'istabmenu'=> TYPE_INT,
	));
	
	$tabid = intval($vbulletin->GPC['tabid']);
    $type_of_tab = $vbulletin->GPC['type_of_tab'];
	$title = str_replace ("'", "''", $vbulletin->GPC['title']);
	$phrase = str_replace ("'", "''", $vbulletin->GPC['vbphrase']);
	$script = str_replace ("'", "''", $vbulletin->GPC['script']);
	$target = $vbulletin->GPC['target'];
	$image = $vbulletin->GPC['image'];
    $tabtype = $vbulletin->GPC['tabtype'];
	$tabmode = $vbulletin->GPC['tabmode'];
	$allowedusergroup = implode(",", $vbulletin->GPC['allowedusergroup']);
	$blockedusergroup = implode(",", $vbulletin->GPC['blockedusergroup']);
	$enable = $vbulletin->GPC['enable'];
	$position = $vbulletin->GPC['position'];
	$displayorder = $vbulletin->GPC['displayorder'];
    $notes = $vbulletin->GPC['notes'];
	
	if (empty($vbulletin->GPC['istabmenu']))
	{
		if ($vbulletin->GPC['url']=='[DROPDOWN TAB]')
		{
			$url='';
		}
		else
		{
		$url = str_replace ("'", "''", $vbulletin->GPC['url']);
		}
	}
	else
	{
		$url = '[DROPDOWN TAB]';
	}
		
	if (empty($vbulletin->GPC['tabid']))
	{
		$db->query_write("INSERT INTO " . TABLE_PREFIX . "dbtech_vbnavtabs(title,type_of_tab,vbphrase,url,tabmode,image,script,target,allowedusergroup,blockedusergroup,`enable`,position,displayorder,notes)
				VALUES (
				'".$title."',
                '".$type_of_tab."',
				'".$phrase."',
				'".$url."',
				'".$tabmode."',
				'".$image."',
				'".$script."',
				'".$target."',
				'".$allowedusergroup."',
				'".$blockedusergroup."',
				'".$enable."',
				'".$position."',
				'".$displayorder."',
                '".$notes."'
				)");
	}
	else
	{
		$db->query_write("UPDATE " . TABLE_PREFIX . "dbtech_vbnavtabs SET 
		title = '".$title."',
        type_of_tab = '".$type_of_tab."',
		vbphrase = '".$phrase."',
		url = '".$url."',
		tabmode = '".$tabmode."',
		image='".$image."',
		script = '".$script."',
		target = '".$target."',
		allowedusergroup = '".$allowedusergroup."',
		blockedusergroup = '".$blockedusergroup."',
		enable = '".$enable."',
		position = '".$position."',
		displayorder = '".$displayorder."',
        notes = '".$notes."'
		WHERE tabid =$tabid");
	}

	$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=tabs');
	print_stop_message('dbtech_vbnavtabs_tab_update');
}
	
/*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*\
<< ********************************************************************* >>
<< * Created: 19:30, Fri Nov 25th 2011                                 * >>
<< * VER: 1.0.1                                                        * >>
<< ********************************************************************* >>
\*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*/

?>