<?php require "_header.php"; 

$db_list = mysql_list_dbs();
$str1="";
$str2="";
while ($row = dbArray($db_list)) {
		$str1 .= "['".$row['Database']."'],";	
		$result =mysql_list_tables($row['Database']);
		$num_rows = dbNumRows($result);
		for ($i = 0; $i < $num_rows; $i++) {
			$str2 .= "['".$row['Database']."','".mysql_tablename($result, $i)."'],";	
		}
}

$str1 = substr($str1, 0, strlen($str1)-1);
$str2 = substr($str2, 0, strlen($str2)-1);


?>
<script type="text/javascript" language="javascript">
	Ext.namespace('Ext.combo');
	Ext.combo.db = [<?php echo $str1; ?>];
	Ext.combo.table = [<?php echo $str2; ?>];
</script>

<script type="text/javascript">
Ext.onReady(function(){
Ext.QuickTips.init();
	
var dbstore = new Ext.data.ArrayStore({
	fields: ['db_name'],
	data: Ext.combo.db
}); 

var dbCombo = new Ext.form.ComboBox({
	name: 'db_name',
	id:'db_name',
	labelSeparator:'',	
	fieldLabel : 'DataBase:',
	displayField:'db_name',
	valueField: 'db_name',
	editable:true,
	forceSelection:true,
	triggerAction:'all',
	mode:'local',
	allowBlank:false,
	width:200,
	store: dbstore,
    listeners: {'select': function(cmb, rec, idx){
		var tablecombo = Ext.getCmp('table_name'); 
		tablecombo.clearValue();											
		tablecombo.store.filter('db_name',cmb.getValue());	
	}}
});


var tablestore = new Ext.data.ArrayStore({
	fields: ['db_name','table_name'],
	data: Ext.combo.table
}); 

var tablecombo = new Ext.form.ComboBox({
	name: 'table_name',
	id:'table_name',
	labelSeparator:'',	
	fieldLabel :'Table Name:',
	displayField:'table_name',
	valueField: 'table_name',
	editable:false,
	forceSelection:true,
	triggerAction:'all',
	mode:'local',
	allowBlank:false,
	width:200,
	store: tablestore,
	lastQuery:''
});


var chapterform = new Ext.FormPanel({	
		id: 'chapterform',
		frame: true,
		url: 'save-classfile.php',
    	labelAlign: 'left',
		standardSubmit:true,     
  		bodyStyle:'padding:5px',
    	items: [dbCombo,tablecombo]
			
    });
	

	var ChapterWindow = new Ext.Window({
		title: 'Create Class File',
		width:350,		
		height:150,	
		frame: true,
		border: false,
		modal:true,
		layout: 'fit',
		closeAction:'close',
		collapsible:true,
		items: chapterform,
		buttons:[{
				text: 'Create', 
				name:'btnSave',
				tabIndex:2,
				iconCls:'icon-save',
				id:'btnSave',
				handler: function(){
				chapterform.getForm().submit({
										waitMsg: 'Saving...',
										success: function () {								
										},
										failure: function () {
											Ext.MessageBox.show({
												title: 'Error',
												msg: 'Please fill up complete form.',
												buttons: Ext.MessageBox.OK,
												icon:Ext.MessageBox.ERROR
											});									
										}
									});		
				
				}	
			},
			{
				text: 'Reset', 
				name:'btnreset',
				tabIndex:4,
				iconCls:'icon-reset',
				id:'btnreset',
				handler: function (){
					chapterform.getForm().reset();
				}
			},
			{
				text:'Close', 
				name:'btnclose',
				tabIndex:5,
				iconCls:'icon-close',
				id:'btnclose',
				handler: function (){
					ChapterWindow.close();
				}
			}
		]
	});
	
	
	var varWidth =  (screen.width - ChapterWindow.width)/2;
	ChapterWindow.setPosition(varWidth,((screen.height/4)-85));
	ChapterWindow.show();
});

</script>
<?php require "_footer.php"; ?>