<?php require "_header.php"; ?>
<?php require "includeGridFilters.php";?> 
<style type="text/css">
.img-contact
{
	vertical-align: middle;
	margin: 0px 0px 0px 0px;
	width:75px;
	height:100px;
}
.x-fieldset
{
	border-style: solid none none none;
	border-width: 1px;
	border-color: #B5B8C8;
	padding: 10px;
	margin-bottom: 10px;
	margin-right: 20px;
	display: block;
}
label.myBold
{
   font-weight: bold;
   color:#666667;
   font-size: 12px;
}

    </style>
<?php 
$supportinquiry_id = Escape($_REQUEST["ID"]);
if ($supportinquiry_id !="" && isset($supportinquiry_id)) {
		$mode="edit";	
		$limit=1;
		$start=0;
		$condition=" and ls.supportinquiry_id = '$supportinquiry_id' ";
		$order_field="";
		$order_type="";
		    			
		$objSupportInquiryMgmt  = new SupportInquiryMgmt();
		
		$out =  $objSupportInquiryMgmt->getAllRecords(0,0,$condition,$order_field,$order_type) ;
		if (dbRows($out)){
			$row=dbArray($out);
			extract($row);			
		}    	   
}
else{
	$mode="add";
	$supportinquiry_id=0;
}
?>
<script type="text/javascript" language="javascript"> 
</script>
<script type="text/javascript" src="jquery/ux/CheckColumn.js"></script>
<script type="text/javascript" src="js/addedit-customer.js"></script>
<script type="text/javascript" language="javascript"> 

var formMode = '<?php echo $mode;?>';
var supportinquiry_id = '<?php  echo $supportinquiry_id; ?>';
//edit by nirav
var customerphonestore = new Ext.data.Store({
		url: 'data/getcustomer-phone.php',          
		reader: new Ext.data.JsonReader({			
			fields: ['customer_id','customer_orgname','customer_phone1','customer_phone2','customer_cpmobile1'],
			root: 'rows1'
		}),autoLoad:true
	});
//end 

  
var customersore = new Ext.data.Store({
		url: 'data/getcustomername.php',          
		reader: new Ext.data.JsonReader({			
			fields: ['customer_id','customer_orgname'],
			root: 'rows'
		}),autoLoad:true
	});

var labelArray;
	
	labelArray = [
		['Customer Name :<span class="comp">*</span>'],
		['Date :<span class="comp">*</span>'],
		['Time :<span class="comp">*</span>']
	];
	
	Ext.QuickTips.init();
	
Ext.onReady(function() {
	 
	 var xg = Ext.grid;
	 
	var encode = false;
	var local = false;

CustomerSupportInquirystore = new Ext.data.JsonStore({
       	autoDestroy: true,
        url:'data/customer-grid-filter.php',
        remoteSort: true,
        sortInfo: {
            field: 'customer_id',
            direction: 'ASC'
        },        
        idProperty: 'customer_id',
        root: 'data',
        totalProperty: 'total',
        fields: [{
            name: 'customer_id',
			type: 'int'
        }, {
            name: 'customer_orgname'
        }, {
            name: 'customer_cpname1'
        }, {
            name: 'customer_cpemail1'
        }, {
            name: 'customer_phone1',
			type: 'int'
        }, {
            name: 'customer_address',
			type: 'string'
        }
		] 
    });
	
var createColModel = function (finish, start) {
        var columns = [
	 	{
			width:40,
            dataIndex: 'customer_id',
			header: 'Customer ID',
			hidden:true
        }, {
			width:95,
            dataIndex: 'customer_orgname',
			header: 'Customer Name'
        },{
			width:150,
            dataIndex: 'customer_address',
			header: 'Address'
        }, {
			width:60,
            dataIndex: 'customer_phone1',
			header: 'Phone No'
			//renderer: rating
        },{
			width:95,
            dataIndex: 'customer_cpname1',
			header: 'Contact Person'
        },{
			width:60,
            dataIndex: 'customer_cpmobile1',
			header: 'contact Mobile'
        }];
		return new Ext.grid.ColumnModel({
            columns: columns.slice(start || 0, finish),
            defaults: {
                sortable: true
            }
        });
    };
	
	var grid1 = new Ext.grid.GridPanel({
    	store: CustomerSupportInquirystore,
        colModel: createColModel(40), 
        loadMask: true,
		frame: false,
		enableColLock:false,
		height: 150,    
        width: 600,
		style: 'padding:0px 10px',
       	//layout: 'fit',
		columnLines:true,
    	selModel: new Ext.grid.RowSelectionModel({singleSelect:false}),
       	tbar:[
         { 
		    	iconCls: 'icon-add',
           		text: 'Add/Edit Customer',
				ref: 'removeButton',
            	handler: function() {
               CustomerWindow.show();
			   //Ext.getCmp('btncustomerclose').hide();
			   }
		            
      		}
	  ]
    });
	
	var grid = {
		columnWidth: 1,
    	layout: 'form',
		labelWidth: 1,
    	items: [
			{
				height:10
			},
			{
				xtype: 'label',
				text:"Customer Detail",
				name: 'per',
				style: 'padding:0px 10px',
				cls: 'x-form-item myBold',											
				id:'per'
			},grid1				
			
		]
	}
	
	var comment = {
		columnWidth: 1,
    	layout: 'form',
		labelWidth: 1,
    	items: [
			{
				height:10
			},
			{
				xtype: 'label',
				text:"Problem Detail",
				name: 'per',
				style: 'padding:0px 10px',
				cls: 'x-form-item myBold',											
				id:'per'
			},{
				xtype: 'textarea',
				width:583,
				style:'padding 0px 0px 200px',
				height: 125, 
				name: 'supportinquiry_problem',
				id:'supportinquiry_problem'				
			}
		]
	}

var nameAndCompany = {
	 columnWidth: 1,
    layout: 'form',
	labelWidth: 110,
    style: 'padding:0px 10px',
    items: [
	//editaed by nirav//		
				{
				xtype: 'textfield',
				name: 'SearchByPhone',
				id: 'SearchByPhone',
				fieldLabel:'Search By Phone',
				hidden:false,
				 listeners:{
					
					blur: function() 
					{
						customersore.load({    					
							params: {phone:Ext.getCmp('SearchByPhone').getValue()}					
						});	
					}
				}
			},
			{
				xtype: 'combo',
			   	name: 'customer_cobmbo',
			   	id:'customer_cobmbo',
				hiddenName: 'customer_idhedden',
				tabIndex:3,
				labelSeparator:'',	
				fieldLabel :labelArray[0] ,
				displayField:'customer_orgname',
				tabIndex:3,
				valueField: 'customer_id',
				width: 170,
				blankText: '',
				emptyText:'',
				allowBlank:false,
				triggerAction:'all',
				mode:'local',			
				selectOnFocus: true,	
				store:customersore ,
				forceSelection:true,
				editable:true,
				listeners:{select:{fn:function(combo, value) 
				{										      
					custid=combo.getValue('customer_id'); 
					CustomerSupportInquirystore.load({
						params: {customer_id:custid}
					});
				}
			  }
	  	    }},{
				xtype: 'datefield',
				name: 'supportinquiry_date',
				labelSeparator:'',	
				fieldLabel :labelArray[1] 
				,width:100
				,allowBlank:false
				,id: 'supportinquiry_date'
				,vtype: 'daterange'
				 
			  },{
					xtype: 'timefield',
					name: 'supportinquiry_time',
					labelSeparator:'',	
					fieldLabel :labelArray[2] 
					,width:100
					,allowBlank:false
					,id: 'supportinquiry_time'
				 },{
					xtype: 'textfield',
					name: 'supportinquiry_id',
					id: 'supportinquiry_id',
					hidden:true,
					value:supportinquiry_id
					
				 }]
}
var supportinquiryForm = new Ext.FormPanel({
        frame: true,
		url:'save-support_inquiry.php',
        bodyStyle: 'padding:5px',
		autoHeight: true,
        width: 700,
			
			defaults: {
            border: false
           },	
            items: [nameAndCompany,grid,comment]
    });
	

var supportinquiryWindow = new Ext.Window({
		title: 'Customer Support',
		width:625,		
		//height:650,
		modal:true,
		scrollable:true,
		autoHeight: true,
		shadow: false,
		border: false,
		layout: 'fit',
		closeAction:'close',
		collapsible:true,
		items: supportinquiryForm,
		buttonAlign: 'center',
	    buttons: [{
            text: 'Save',	
			iconCls: 'icon-save',
			id:'siSavebtn',	
			handler: function () {	
										 
								supportinquiryForm.getForm().submit({
										  waitMsg: 'Saving...',
										  	success: function () {
											Ext.MessageBox.show({
															   title: 'Message',
															   msg: 'Data has been saved..',
															   buttons: Ext.MessageBox.OK,
															   icon:Ext.MessageBox.INFO
															  });
															 supportinquiryForm.getForm().reset();
															 CustomerSupportInquirystore.removeAll();
															  if(formMode=='edit'){
																location.href="view-support-inquiry.php";
															 }
													
											},
											failure: function () {	
												
														Ext.MessageBox.show({
															   title: 'Error',
															   msg: 'Please fill complete form!',
															   buttons: Ext.MessageBox.OK,
															   icon:Ext.MessageBox.ERROR
															  });
									
												 
											}
										});
					
				}
			   	
			},
		   {
            text: 'Reset',
			iconCls: 'icon-reset',
			id:'siResetbtn',	
			handler: function () {
			supportinquiryForm.getForm().reset();
			CustomerSupportInquirystore.removeAll();
			}
        },
	 	   {
            text: 'Close',
			iconCls: 'icon-close',
			id:'siClosebtn',	
			handler: function () {
				supportinquiryWindow.close();
			
			}
        }
	 ]

	});
	
	var varWidth =  (screen.width - supportinquiryWindow.width)/2;
	supportinquiryWindow.setPosition(varWidth,((screen.height/4)-110));
	
	supportinquiryWindow.show();
	
	CustomerWindow.on('hide',function(){
		customersore.load();
	});
	
	/*if(formMode=='edit'){
	<?php
	
	//$supportinquiry_problem 		= replaceSpecial($supportinquiry_problem);
	
	?>
		supportinquiryForm.getForm().findField('supportinquiry_date').setValue('<?php //print $supportinquiry_date; ?>');
		supportinquiryForm.getForm().findField('supportinquiry_time').setValue('<?php //print $supportinquiry_time; ?>');
		customersore.on({'load':{
			fn: function(store, options){
				supportinquiryForm.getForm().findField('customer_cobmbo').setRawValue('<?php //print $customer_id; ?>');
				supportinquiryForm.getForm().findField('customer_cobmbo').setValue('<?php //print $customer_id; ?>');	
			}
		}});
		
		supportinquiryForm.getForm().findField('supportinquiry_problem').setValue('<?php //print $supportinquiry_problem; ?>');
		CustomerSupportInquirystore.load({
						params: {customer_id:'<?php //print $customer_id; ?>'}
					});
		
	}*/
});
</script>
<div align="center"><div id="main-content" align="center"></div></div> 
<?php require "_footer.php";?>