<?php
include_once("_dirinfo.php");
include_once(PATH_TO_ROOT."init.php");
include_once (PATH_TO_ROOT."config.php");
include_once (PATH_TO_ROOT."CRM/_CRM_config.php");
include_once(PATH_TO_ROOT."CRM/class/class.Permissions.php");
	
$db->ChangeDatabase(DB_WARPIT_WEBCATI_BASE);
$ajax = CRM_RPATH."_forms/visitStatistic/_ajax/ajax.statistic.php";

include_once (PATH_TO_ROOT."CRM/_CRM_config.php");
include_once(PATH_TO_ROOT."CRM/class/class.Language-Pack.php");

$LangPack = new LanguagePack($db, $aLanguage);
$p = new Permissions($db);
$windowId = "SettingsWindow";
$gridName = "SettingsForm";
$sql = "SELECT * FROM ".WARPIT_CRM."._CRMConfig WHERE prefix = 'VisitorStatistic' GROUP BY cName ASC";
$res = $db->SQLexecute($sql);
while($row = $db->fetchAssoc($res))
	$config[$row['cName']] = $row['cValue'];

?>

var <?php echo $windowId;?> = new Ext.Window({
	title: '<?php echo $LangPack->GetLabel("statistic_settings_grid", "window_title","Nastavitve"); ?>',
    id		: '<?php echo $windowId;?>',
    width	:330,
    height	: 270,
    plain	: true,
    layout	: 'border',
    frame: true,
    modal: true,
    items:[new Ext.form.FormPanel({
    	id:'<?php echo $gridName;?>',
	    bodyStyle:'padding: 20px',
	    border: false,
	    region: 'center',
	    labelAlign: 'left',
	    autoScroll: true,
	    labelWidth: 120,
	    items:[{
	    	xtype: 'button',
	    	id:'color1',
	    	color: '<?php echo $config['color1_value'];?>',
	    	name: 'b_color_1',
	    	fieldLabel: '<?php echo $LangPack->GetLabel("statistic_settings_grid", "color_1_label","Barva 1"); ?>',
	    	text:'<?php echo $LangPack->GetLabel("statistic_settings_grid", "color_button_text","Barva");?> #<?php echo $config['color1_value'];?>',
	    	menu:{
	    		xtype: 'colormenu',
	    		value: '000000',
	    		handler: function(comp, rgb){
	    			var comp = Ext.getCmp('color1');
	    			comp.setText('<?php echo $LangPack->GetLabel("statistic_settings_grid", "color_button_text","Barva");?> #' + rgb);
	    			comp.color = rgb;
	    		}
	    	}
	    },{
	    	xtype:'textfield',
	    	name: 't_color_1',
	    	value: '<?php echo $config['color1'];?>',
	    	fieldLabel:'<?php echo $LangPack->GetLabel("statistic_settings_grid", "color_1_number_label","Barva 1 vrednost");?> >'
	    },{
	    	xtype: 'button',
	    	id:'color2',
	    	color: '<?php echo $config['color2_value'];?>',
	    	name: 'b_color_2',
	    	fieldLabel: '<?php echo $LangPack->GetLabel("statistic_settings_grid", "color_2_label","Barva 2"); ?>',
	    	text:'<?php echo $LangPack->GetLabel("statistic_settings_grid", "color_button_text","Barva");?>  #<?php echo $config['color2_value'];?>',
	    	menu:{
	    		xtype: 'colormenu',
	    		value: '000000',
	    		handler: function(comp, rgb){
	    			var comp = Ext.getCmp('color2');
	    			comp.setText('<?php echo $LangPack->GetLabel("statistic_settings_grid", "color_button_text","Barva");?> #' + rgb);
	    			comp.color = rgb;
	    		}
	    	}
	    },{
	    	xtype:'textfield',
	    	name: 't_color_2',
	    	value: '<?php echo $config['color2'];?>',
	    	fieldLabel:'<?php echo $LangPack->GetLabel("statistic_settings_grid", "color_2_number_label","Barva 2 vrednost");?> >'
	    },{
	    	xtype: 'button',
	    	id:'color3',
	    	color: '<?php echo $config['color3_value'];?>',
	    	name: 'b_color_3',
	    	fieldLabel: '<?php echo $LangPack->GetLabel("statistic_settings_grid", "color_3_label","Barva 3"); ?>',
	    	text:'<?php echo $LangPack->GetLabel("statistic_settings_grid", "color_button_text","Barva");?> #<?php echo $config['color3_value'];?>',
	    	menu:{
	    		xtype: 'colormenu',
	    		value: '000000',
	    		handler: function(comp, rgb){
	    			var comp = Ext.getCmp('color3');
	    			comp.setText('<?php echo $LangPack->GetLabel("statistic_settings_grid", "color_button_text","Barva");?> #' + rgb);
	    			comp.color = rgb;
	    		}
	    	}
	    },{
	    	xtype:'textfield',
	    	name: 't_color_3',
	    	value: '<?php echo $config['color3'];?>',
	    	fieldLabel:'<?php echo $LangPack->GetLabel("statistic_settings_grid", "color_3_number_label","Barva 3 vrednost");?> >'
	    }]
    })],
    buttons:[{
    	text:'save',
    	handler: function(){
    		Ext.getCmp('<?php echo $gridName;?>').getForm().submit({
    			url: '<?php echo $ajax;?>',
    			params:{
    				action: 'changeColors',
    				color1: Ext.getCmp('color1').color,
    				color2: Ext.getCmp('color2').color,
    				color3: Ext.getCmp('color3').color
    			},
    			success: function(resp,opt){
    				var res = Ext.decode(opt.response.responseText);
    				if(res.success){
    					Ext.getCmp('visitorStatisticGrid').getStore().reload();
    					Ext.getCmp('<?php echo $windowId;?>').close();
    				}
    			}
    		})
    	}
    }]
}).show();