<?php
include_once("_dirinfo.php");
include_once(PATH_TO_ROOT."init.php");

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


$ajax = CRM_RPATH."_forms/kartoteka/_ajax/ajax.kartoteka.php";
$activityAjax = CRM_RPATH."_forms/kartoteka/_ajax/ajax.activites.php";
$cmpName = "KartotekaPanel_" . $_POST['id'];
$LangPack = new LanguagePack($db, $aLanguage);

$id = StringChecker::Check($_POST['id']);
include('forms.userForm.php');
include('grid.userOrders.php');
include('grid.companions.php');
include('forms.activities.php');

?>

if(!Ext.getCmp('<?php echo $cmpName; ?>'))
{
    

var <?php echo $cmpName;?> = new Ext.Panel({
    id:'<?php echo $cmpName;?>',
    title:'<?php echo $LangPack->GetLabel("kartoteka_person_form", "tab_title","Kartoteka");?>',
    defaults:{split:true,border:false},
    layout:'border',
    border: false,
    closable:true,
    items:[
    {
        layout:{
        	type: 'vbox',
        	align: 'stretch'
        },
        region:'west',
        items:[ userForm_<?php echo $id; ?>,
	        new Ext.TabPanel({
	        	flex:1,
	        	activeTab: 0,
	        	id: 'tabPanel_<?php echo $id;?>'
	        })
	    ],
        width: 300,
        minWidth:300
    },
    new Ext.Panel({
        layout:'fit',
        border: false,
        region:'center',
        items:[ ActivitiesGrid_<?php echo $id; ?> ]
    })
    ]
});
Ext.getCmp('FormPerson_<?php echo $id; ?>').load({
    url: '<?php echo $ajax; ?>',
    params: {
        action: 'getPerson',
        personId: '<?php echo $id; ?>'
        
    },success: function(form, res)
    {
        var data = Ext.decode(res.response.responseText);
        Ext.getCmp('<?php echo $cmpName; ?>').setTitle('Kartoteka (' + data.data.firstname + ' ' + data.data.surname +')');
    }
});
Ext.getCmp('tabPanel_<?php echo $id;?>').add(userGrid_<?php echo $id;?>);
Ext.getCmp('tabPanel_<?php echo $id;?>').add(compainonsGrid_<?php echo $id;?>);
Ext.getCmp('mainTabPanel').add(<?php echo $cmpName;?>).show();
Ext.getCmp('userGrid_<?php echo $id;?>').getStore().load();
}