<?php 
include_once("_dirinfo.php");
include_once(PATH_TO_ROOT."init.php");
include_once(PATH_TO_ROOT."_class/class.Extjs_tree.php");
include (PATH_TO_ROOT."webcati/init.php");

$proj_name = mysql_real_escape_string($_POST['project']);

$reqUrl = "webcati/_ajax/buildQuestionare/randomDataFile/ajax.customFillScript.php";
$tabId = $_POST['uniqueTabId'];

$tree = new MakeTree($tabId.'_tree');

$tree->SetTable($proj_name,DB_WARPIT_WEBCATI);
$tree->SetRootVisible('true','Questions')
    ->setWidth('180');
$tree
    ->addConfig('region',"'west'")
    ->setTextPadding('1px');
    
$tree->addtBarItem("'->'");
$tree->addtBarItem("{
    iconCls: 'x-tbar-loading',
    xtype: 'button',
    handler: function()
    {
        $tree.getLoader().load($tree.getRootNode());
        $tree.getRootNode().expand();
    }
}");
    /*->activateDD()*/
  $tree->setReqUrl($reqUrl);
    /*->afterAddItem = "if(r.warning) Ext.Msg.alert('Warning',r.warning);
    CallScript('webuserspool/_forms/incentiveSystem/forms.incentiveGroup.php',{id_group: r.insertId,projName:text});";*/
  //  $tree->setContAddItem('Add project','false','icon-add-record',null,2)
    
    /*->setContAddGroup('Add folder','false','icon-add-folder',2)
    ->setContRename()
    ->setContDelete('Delete','node.hasChildNodes()','icon-delete-record',2)*/
    //$tree->addConfig('collapseMode', "'mini'")
;    


echo $tree->CreateTree();

echo "
    $tree.on('click',function(node) {
        if(node.attributes.leaf)
        {
            var tmp = Ext.getCmp('scriptEditor_'+node.id );
            if( tmp )
            {
                tmp.show();
                return;
            }
            
            CallScript('webcati/_forms/buildQuestionare/randomDataFill/forms.customFileScriptEditor.php',
            {
                idQuestion: node.id,
                projName:'" . $proj_name . "',
                q_name: node.attributes.strText,
                uniqueTabId: '" . $_POST['uniqueTabId'] . "',
                treeName: " . $tree->getName() .".id
            });
        }
     });
    
    var $tabId = new Ext.Panel({
        id:'$tabId',
        title:'Custom script - " . $_POST['project'] . "' ,
        //iconCls:'RMicon_incentive',
        defaults:{split:true,border:false},
        iconCls: 'icon_build_questionnare',
        layout:'border',
        border: false,
        closable:true,
        items:[$tree, { xtype:'tabpanel',id:'" . $tabId . "_tab',region:'center'  }   ]
    });
mainTabPanel.add( $tabId ).show();  ";

?>
