<?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/class/class.checkString.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);

if(isset($_POST['id']))
    $orderId = StringChecker::Check($_POST['id']);

if(isset($_SESSION['UserInfo']['id']))
    $userId = $_SESSION['UserInfo']['id'];

if(isset($_POST['gridName']))
    $gridName = StringChecker::Check($_POST['gridName']);

$ajax = CRM_RPATH."_forms/financial/_ajax/ajax.Financial.php";
$windowId = "windowReclamation";
$formPanelId = "windowReclamationForm";
?>
var <?php echo $formPanelId; ?> = new Ext.form.FormPanel({
    id:'<?php echo $formPanelId;?>',
    bodyStyle:'padding: 20px',
    border: false,
    region: 'center',
    labelAlign: 'left',
    autoScroll: true,
    labelWidth: 100,
    items:[{
            xtype:'datefield',
            name: 'date',
            format: 'd.m.Y',
            fieldLabel:  '<?php echo $LangPack->GetLabel("window_addpayment", "payment_date_text","Datum plačil");?>',
            anchor: '100%'
       },{
       		xtype: 'textarea',
       		name: 'comment',
       		fieldLabel: '<?php echo $LangPack->GetLabel("window_addpayment", "comment_text","Komentar");?>',
       		anchor: '100%'
       }]
});

var <?php echo $windowId;?> = new Ext.Window({
    title:'<?php echo $LangPack->GetLabel("window_addpayment", "window_title","Dodaj plačilo");?>',
    id      : '<?php echo $windowId;?>',
    width   : 500,
    height  : 200,
    plain   : true,
    layout  : 'border',
    frame: true,
    modal: true,
    items   : [
        <?php echo $formPanelId; ?>
    ],
    listeners: {
    },
    buttons:[{
        text:'<?php echo $LangPack->GetLabel("window_addpayment", "window_cancle_button","Prekliči"); ?>',
        handler: function(){
            <?php echo $windowId;?>.close();
        }
    },{
        text: '<?php echo $LangPack->GetLabel("window_addpayment","window_save_button","Shrani");?>',
        id: 'save_button',
        handler: function(){
			<?php echo $formPanelId;?>.getForm().submit({
                url: '<?php echo $ajax;?>', 
                params: { 
                    action: 'submit',
                     id : '<?php echo $orderId; ?>'
                },
                clientValidation: true,
                success: function(form, action) {
                    if(Ext.getCmp('<?php echo $gridName; ?>'))
                        Ext.getCmp('<?php echo $gridName; ?>').getStore().reload();
                    <?php echo $windowId; ?>.close();
                }
            });
        }
    }]
}).show();