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

$idField = "id";

$tableName = $_POST['tableName'];
$questionId = $_POST['questionId'];
$pluginDir = $_POST['pluginDir'];
$projectId = $_POST['projectId'];

$gridName = "settingsGrid_" . $tableName;

$ajax = $pluginDir . "/_forms/_ajax/ajax.settings.php";

$windowName = "default_images_" . $tableName;

$sql = "SELECT * FROM " .  DB_WARPIT_WEBCATI_BASE . "._Plugin_label
       WHERE id_plugin = 6 AND name LIKE '%button_image%'";
       
       //print $sql;
        $res= $db->SQLexecute($sql);

while ($dat = $db->fetchAssoc($res)) {
  $tmpField[] = 
  "{ 
      fieldLabel: '" . $dat['label'] . "',
      name: '" . $dat['name'] . "',
      xtype:'checkbox'
      
    }";
    }
   ?>

var <?php echo $windowName; ?> = new Ext.Window({
                        width:500,
                        id: '<?php echo $windowName; ?>',
                        height:400,
                        title: 'Set default images',
                        items:[{
                            xtype:'form',
                            labelWidth: 200,
                            height: 380,
                            id: '<?php echo $windowName; ?>_form',
                            autoScroll: true,
//                            autoHeight: true,
                            items:[
                             <?php echo implode(',', $tmpField); ?>
                            ]
                            
                        }],
                        buttons: [{
                            text: 'Update',
                            handler: function(){
                                Ext.getCmp('<?php echo $windowName; ?>_form').getForm().submit({
                                   url: '<?php echo $ajax; ?>',
                                   params: {
                                       action: 'defaultButtons',
                                       projectId: <?php echo $projectId; ?>,
                                       questionId: <?php echo $questionId; ?>,
                                   },
                                   success : function()
                                   {
                                       Ext.getCmp('<?php echo "settingsGrid_" . $tableName; ?>').loadData();
                                       <?php echo $windowName; ?>.close();
                                   }
                                });
                            }
                        }]
            }).show();