<?php
include_once("_dirinfo.php");
include_once(PATH_TO_ROOT."init.php");
include_once(PATH_TO_ROOT."_class/class.Extjs_grid.php");

	
$db->ChangeDatabase(DB_WARPIT_WEBCATI_BASE);


$grid = new MakeGrid('wupSMTP_accounts');
$grid->setMainTable('_SMTP_accounts',DB_WARPIT_USERSPOOL)->setTitle("Mail Accounts");

$grid->activateAdd('Add')
	->activateRemove()
	->setCheckBoxSelectionModel()
	->setReqUrl("webuserspool/_ajax/mails/ajax.SMTP_accounts.php");

$grid->addColumn('id')->header('ID')->hidden(true);
$grid->addColumn('name')->header('Name')->editor('new Ext.form.TextField()');
$grid->addColumn('local')->header('local')->type('checkColumn');
$grid->addColumn('host')->header('Host')->editor('new Ext.form.TextField()');
$grid->addColumn('port')->header('Port')->editor('new Ext.form.TextField()');
$grid->addColumn('helo_message')->header('Helo message')->editor('new Ext.form.TextField()');
$grid->addColumn('username')->header('Username')->editor('new Ext.form.TextField()');
$grid->addColumn('password')->header('Password')->editor('new Ext.form.TextField({inputType:"password"})')
		->renderer("function(val){ var p='';if(val) for(var i=0;i<val.length;i++) p+='*'; return p; }");
$grid->addColumn('mail_from','From')->editor('new Ext.form.TextField()')
	->afterEditHandler("function(e){
		var upt = Ext.getCmp('wupMailOptionsPanel');
		
		if(upt) upt.getForm().findField('id_account').getStore().reload();
	}");
$grid->addColumn('mail_from_label','Label')->editor('new Ext.form.TextField()')->afterEditHandler("function(e){
		var upt = Ext.getCmp('wupMailOptionsPanel');
		
		if(upt) upt.getForm().findField('id_account').getStore().reload();
	}");
$grid->addColumn('userDefault')->header('default')->type('checkColumn')
	->setProperty('aftereditHandler',"function(e){
			e.grid.store.each(function(item){
				if(item.id != e.record.id)
					item.data.userDefault = false;
			} );
			e.grid.getView().refresh();
	}");
?>

	
<?php
/*
    $grid->activateRemove('Delete')
		->setPaging(15)
		->setAutoExpand('email')
		->setCheckBoxSelectionModel(true)
		->setFiltering(true)
		->addtBarItem('comboImported')
		->setSearchField('Search')
		;
	*/
	// $grid->addTbarItem ("{ text:'Copy to group', handler: function() { CallScript('webuserspool/_forms/window.fileUpload.php',{}); }   }  ");
	
	//$grid->addTbarItem ("{ text:'Copy to group', handler: function() { alert(comboImported.getValue()); }   }");
/*	$grid->addTbarItem ("{ text:'Copy All to group', 
							handler: function() { 
								Ext.Ajax.request({
									url:'webuserspool/_ajax/ajax.showImportedGroup.php',
									params:{ 
											tableName: '".$ImportTable."',
											datatype: comboImported.getValue(), 
										 	group_id: Ext.getCmp('PoolMenu_1').getSelectionModel().getSelectedNode().attributes.id 
									}, 
									success: function ( result, request ) {
											//console.log(result);
										   var respStatus = Ext.decode(result.responseText);
										   if (!respStatus.success) Ext.Msg.alert('Error', respStatus.error);
										   	 else  Ext.Msg.alert('Group action', respStatus.msg);
										   
									}
								}); 
							}   
						}");
	
	$grid->addTbarItem ("{ text:'Copy checked to group', 
							handler: function() { 
								var tmp = ".$grid->getGridName().".getSelectionModel().getSelections()
								var arr = new Array();
								
								for(var i=0;i<tmp.length;i++)
								{
									arr.push( tmp[i].id); 
								}
								console.log()
								Ext.Ajax.request({
									url:'webuserspool/_ajax/ajax.showImportedGroup.php',
									params:{  
											tableName: '".$ImportTable."',
										 	group_id: Ext.getCmp('PoolMenu_1').getSelectionModel().getSelectedNode().attributes.id,
										 	ids :Ext.encode(arr)
									}, 
									success: function ( result, request ) {
											//console.log(result);
										   var respStatus = Ext.decode(result.responseText);
										   alert(respStatus.error);
									}
								}); 
							}   
						}");
	*/
	
	echo $grid->createGrid();
	
	echo "mainTabPanel.add(".$grid->getGridName().").show();"; ?>