<?php 
	require "_header.php";
	require "combo_subject.php";

?>
<script type="text/javascript" language="javascript"> 
Ext.onReady(function(){
Ext.QuickTips.init(); 	

  
var subjectstore = new Ext.data.ArrayStore({
		fields: ['subject_id', 'subject_name'],
		data: Ext.student.subject
 	}); 
	

var reader = new Ext.data.JsonReader({
		root: 'data',
		idProperty: 'upload_id',
		fields: [{name:'upload_id',type: 'int'},
					{name:'branch_id',type: 'int'},
					{name:'branch_name',type: 'string'},
					{name:'semester_id',type: 'int'},
					{name:'semester_name',type: 'string'},
					{name:'subject_id',type: 'int'},
					{name:'subject_name',type: 'string'},
					{name:'title'},
					{name:'description'},
					{name:'active'},
					{name:'file_title'},
					{name:'file_name'},
					{name:'upload_file_id'},
					{name:'assignment_date'},
					{name:'submission_date'},
					{name:'user_name'}				 
				 ]

    });

var UploadStore =new Ext.data.GroupingStore({
    url: 'upload-files-grid-data.php',
   	reader: reader,
	autoLoad:true,
	successProperty: 'success',
	sortInfo: { field: 'subject_id', direction: 'ASC' },
	groupField: 'subject_name'
});

var colModel = new Ext.grid.ColumnModel([
	{ 
		header: "Branch",
		width: 100,
		dataIndex: 'branch_name',
		sortable: true
  	},{ 
		header: "Semester",
		width: 70,
		dataIndex: 'semester_name',
		sortable: true
  	},
	{ 
		header: "Subject",
		width:215,
		dataIndex: 'subject_name',
		sortable: true,
		hidden:true
  	},
	{ 
		header: "Chapter",
		width:150,
		dataIndex: 'title',
		sortable: true
  	},
	{ 
		header: "Chapter Description",
		width:150,
		dataIndex: 'description',
		sortable: true
  	},
	{ 
		header: "FileName",
		width:132,
		dataIndex: 'file_name',
		sortable: true
  	},
	{ 
		header: "Ass. Date",
		width:90,
		dataIndex: 'assignment_date',
		sortable: true
  	},
	{ 
		header: "Sub. Date",
		width:90,
		dataIndex: 'submission_date',
		sortable: true
  	},
	{ 
		header: "Download",	
			width:75,
			dataIndex: 'file_name',
		    renderer: function(value, metaData, record, rowIndex, colIndex, store) 
			{
				if(value!=""){
    	   		return '<a taget="_blank" href="download-material.php?file_name='+ record.get('file_name') +'">Download</a>';
				}else{
				return '';
				}
			}
  	},{ 
		header: "Upload by",
		width:80,
		dataIndex: 'user_name'
  	},
	]);

	
	var grid = new Ext.grid.GridPanel({
   		store: UploadStore,
        cm: colModel,
		columnLines:true,
		stripeRows:true,
		loadMask:true,
		view: new Ext.grid.GroupingView({
					forceFit: true,
					showGroupName: false,
					enableNoGroups: false,
					enableGroupingMenu: false,
					//hideGroupedColumn: true
				}),
        sm: new Ext.grid.RowSelectionModel({
        	singleSelect: true,
            listeners: {
            	rowselect: function(sm, row, rec) {
                //Ext.getCmp('downloadform').getForm().loadRecord(rec);
				Ext.getCmp('upload_file_id').setValue(rec.data.upload_file_id);
				Ext.getCmp('subject_id').setValue(rec.data.subject_id);
				//alert("hello");
				
				}
         	}
   		}),
		height: 380,
		border: true
 	});
	
	grid.on('render', function(){
		grid.tip = new Ext.ToolTip({
    		view: grid.getView(),
    		target: grid.getView().mainBody,
    		delegate: '.x-grid3-row',
    		trackMouse: true,
    		renderTo: document.body,
    		listeners: {
     			beforeshow: function updateTipBody(tip) {
      				tip.body.dom.innerHTML = "Please click here to edit record.";
     			}
    		}
   		});
  	});



	
	
   var downloadform = new Ext.FormPanel({
		frame:true,
		autoHeight:true,   
		url:'report-student-search-result.php',
		frame:true,
		standardSubmit:true,     
      	layout:'column',
		labelWidth:70,
		items:[{columnWidth: 0.50,
                            layout:'form',	
							items:[{
								xtype:'textfield',
								id:'upload_file_id',
								name:'upload_file_id',
								hidden:true
								},{		
										xtype: 'combo',
										name: 'subject_id',
										hiddenName: 'subject_hidden',
										id:'subject_id',
										labelSeparator:'',	
										fieldLabel :'Subject :<span class="comp"></span>' ,
										forceSelection:true,				
										displayField:'subject_name',
										valueField: 'subject_id'
										,triggerAction:'all'
										,mode:'local'
										,store: subjectstore
										,width:300
										,selectOnFocus: true,
										listeners: {'select': function(cmb, rec, idx) {
													 //Ext.getCmp('division_id').reset();
											}
										}
								   }
								   ]
			    },{columnWidth: 0.10,
									labelWidth:1,	
                            		layout:'form',
									items:[{
											xtype:'button',
											text:'Search',
											iconCls:'icon-search',
											handler: function() {
												var subject=Ext.getCmp('subject_id').getValue();
												
													if(subject!="" )
													{
														UploadStore.reload({
															params: {
																subject:subject
															}
														});	
													}
													else
													{
															alert("Select Subject");													
													}
											}
										  }] 
								  },
								   {columnWidth: 0.10,
									labelWidth:1,	
                            		layout:'form',
									items:[{
											xtype:'button',
											text:'Reset',
											iconCls:'icon-reset',
											handler: function() {
											UploadStore.load();
											downloadform.getForm().reset();
											Ext.getCmp('subject_id').focus(true,500);
												
											}
										  }] 
								  }
								   
						]
	
	 });	 
	 
	var StudentWindow = new Ext.Window({
        title: 'Download',
		width:870,		
		height:460,
		modal:true,
		autoHeight:true,
		shadow: false,
		border: false,
		layout: 'fit',
		closeAction:'close',
		collapsible:true,
		items:[downloadform,grid]

	});
	
	var varWidth =  (screen.width - StudentWindow.width)/2;
	StudentWindow.setPosition(varWidth,((screen.height/4)-160));
	StudentWindow.show();
	Ext.getCmp('subject_id').focus(true,500);

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