<div id="tabalatkantor_upload" style="height:400px">
	<ul>
		<li><a id="idtabalatkantor_upload" href="#divtabalatkantor_upload">Upload Data</a></li>
		<li><a id="idtabalatkantor_proses_upload" href="#divtabalatkantor_proses_upload">Proses Data</a></li>
				
	</ul>
	
	<div id="divtabalatkantor_upload" >
		Upload Alat Kantor
	   <form method="post" action="" id="upload_file_alatkantor">
		  <label for="userfile_alatkantor">File</label>
		  <input type="file" name="userfile_alatkantor" id="userfile_alatkantor" size="40" />
		  <input type="submit" name="submit" id="submit" value="Upload" /><button id="btn_alatkantordelet">Delete</button>
	   </form><span id="files_alatkantor" style="font-weight:bold;font-size:10px;"></span>
	   <table id="tbluploaalatkantor"></table> <div id="ptbluploaalatkantor"></div>
	</div>
	<div id="divtabalatkantor_proses_upload" >
		<button id="btnviewalatkantor_proses_upload" >View Data</button>
		<button id="btnproses_alatkantor_upload" >Proses Data</button>
		<hr>
		<div id="dividres" >
	</div>
	
	
</div>


</div>
<script type="text/javascript">
    
    $(document).ready(function(){
		$("#tabalatkantor_upload").tabs();
		
		$('#userfile_alatkantor').live('change', function(){
			$('#userfile_alatkantor').html('Files: '+ $('#userfile_alatkantor').val() +' '); 
		});
		
		
		jQuery.extend({
			handleError: function( s, xhr, status, e ) {
			// If a local callback was specified, fire it
				if ( s.error )
					s.error( xhr, status, e );
				// If we have some XML response text (e.g. from an AJAX call) then log it in the console
				else if(xhr.responseText)
					console.log(xhr.responseText);
			}
		});
		
		
		$(function() {
			$('#upload_file_alatkantor').submit(function(e) {
				e.preventDefault();
				$.ajaxFileUpload({
				 url         :'./settings/ct_barangmesin/upload_file_alatkantor/',
				 secureuri      :false,
				 fileElementId  :'userfile_alatkantor',
				 dataType    : 'json',
				 data        : {
					'userfile_alatkantor'  : $('#userfile_alatkantor').val()
				 },
				 success  : function (data, status)
				 {
					if(data.status != 'error')
					{
					   $('#files_stockopnamebahanbaku').html('Upload File Sukses...'+ $('#userfile_alatkantor').val() +' ;p'); 
					   $('#tbluploaalatkantor').trigger('reloadGrid');
								
					   
					 
					}
					alert(data.msg);
										
				 }
		  });
		  return false;
		   });
		});
		
		
		jQuery("#tbluploaalatkantor").jqGrid({
			url:'<?php echo base_url().'settings/ct_barangmesin/data_uploadalatkantor'; ?>',
			mtype : "post",
			postData:{'q':'1'},
			datatype: "json",
			colNames:['ID','filename', 'date upload','status upload', 'tipe', 'create date', 'create by','path'],
			colModel:[
				{name:'id_uploadalatkantor_upload',index:'id_uploadalatkantor_upload', width:60, hidden:true},
				{name:'filename',index:'filename', width:160},
				{name:'date_upload',index:'date_upload', width:166,stype:"text",searchoptions:{sopt:['eq','cn','gt','lt'],dataInit:function(el){$(el).datepicker({changeYear: true,showButtonPanel: true,changeMonth: true,dateFormat:'dd/mm/yy'});} }},
				{name:'status_upload',index:'status_upload', width:106},
				{name:'tipe',index:'tipe', width:106},
				{name:'create_date',index:'create_date', width:166, hidden:false,stype:"text",searchoptions:{sopt:['eq','cn','gt','lt'],dataInit:function(el){$(el).datepicker({changeYear: true,showButtonPanel: true,changeMonth: true,dateFormat:'yy-mm-dd'});} }},
				{name:'create_by',index:'create_by', width:106, hidden:false},
				{name:'filepath',index:'filepath', width:106, hidden:true}
			
				],
			rowNum:10,
			rowList:[10,20,30],
			pager: '#ptbluploaalatkantor',
			sortname: 'id_uploadalatkantor_upload',
			viewrecords: true,
			sortorder: "desc",
			width: 790,
			height:220,
			jsonReader: { repeatitems : false },
			caption:"List of Files Upload",
			rownumbers: true,
			shrinkToFit: false,
			afterInsertRow: function(){
				
				
			},			
			gridComplete: function(){
				var rowIDs = jQuery("#tbluploaalatkantor").getDataIDs(); 
				var rowData = $("#tbluploaalatkantor").getRowData();
			
				for (var i = 0; i < rowData.length; i++) 
				{
				   var trElement = jQuery("#"+ rowIDs[i],jQuery('#tbluploaalatkantor'));
				   
					switch (rowData[i].status_upload) {
						
						case 'cancel':
						   trElement.css({"color":"green"});
						break;
						case 'Deleted':
						   trElement.css({"color":"red", "text-decoration": "line-through"});
						break;
						case 'DATA PROCESSED':
						   trElement.css({"color":"blue"});
						break;
						
						
					}
				}
			},
		}); 
		
		jQuery("#tbluploaalatkantor").jqGrid('navGrid','#ptbluploaalatkantor',{del:false,add:false,edit:false},{},{},{},{multipleSearch:false});
		jQuery("#tbluploaalatkantor").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : true, defaultSearch: 'cn', ignoreCase: true});
		
		$("#btnviewalatkantor_proses_upload").button().click(function(){
			
			var id = jQuery("#tbluploaalatkantor").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tbluploaalatkantor").jqGrid('getRowData',id);
				
			} else {
				alert("Please Select Row dari tab upload data");
				$("#tabalatkantor_upload").tabs("select", 0);
				return false;
			};	
			
			var form_data = {
				id_uploadalatkantor_upload:ret.id_uploadalatkantor_upload,
				filename:ret.filename,
				filepath:ret.filepath
			
			};
			
			$.ajax({
				url : "<?php echo base_url().'settings/ct_barangmesin/viewdatauploadalatkantor'; ?>",
				type : 'POST',
				//dataType: 'json',
				data : form_data,
				success: function(msg){
					 $("#dividres").html(msg); 
					
				}
			});
			
			
		
		} );	
		
		$("#btnproses_alatkantor_upload").button().click(function(){
			var id = jQuery("#tbluploaalatkantor").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tbluploaalatkantor").jqGrid('getRowData',id);
				
			} else {
				alert("Please Select Row dari tab upload data");
				$("#tabalatkantor_upload").tabs("select", 0);
				return false;
			};	
			
			var form_data = {
				id_uploadalatkantor_upload:ret.id_uploadalatkantor_upload,
				filename:ret.filename,
				
			
			};
			
			$("#dlguploaduploadalatkantor_proses_").dialog( "destroy" );
			$(".dlguploaduploadalatkantor_proses_cl").remove();
			$(".dlguploaduploadalatkantor_proses_cl").html('');
			$("body").append('<div id="dlguploaduploadalatkantor_proses_" title="Warning" class="dlguploaduploadalatkantor_proses_cl"><p>Apakah anda akan memproses file ini?!?</p><br /> file = '+ ret.filename +'</div>');
			$("#dlguploaduploadalatkantor_proses_").dialog({
				height: 200,
				width: 250,
				modal: true,
				hide: 'Slide',
				autoOpen: 'false',
				buttons: {
					"CONFIRM": function() {
					$.ajax({
						url : "<?php echo base_url().'settings/ct_barangmesin/proses_uploadalatkantor'; ?>",
						type : 'POST',
						dataType: 'json',
						data : form_data,
						success: function(msg){
							if (msg.sts == '00'){
								alert(msg.desc);
								$("#dlguploaduploadalatkantor_proses_").dialog("close");
								$('#dlguploaduploadalatkantor_proses_').dialog("destroy"); 
								$(".dlguploaduploadalatkantor_proses_cl").remove(); 
								$('#tbluploaduploadalatkantor').trigger('reloadGrid');
								$('#tbl_alatkantor').trigger('reloadGrid');
								$('#tbluploaalatkantor').trigger('reloadGrid');
								$("#tabalatkantor_upload").tabs("select", 0);
							} else { 
								alert(msg.sts+' '+msg.desc); 
								$("#dlguploaduploadalatkantor_proses_").dialog("close");
								$('#dlguploaduploadalatkantor_proses_').dialog("destroy"); 
								$(".dlguploaduploadalatkantor_proses_cl").remove(); 

							}
						}
					});
				},
					"CANCEL": function() {
						$( "#dlguploaduploadalatkantor_proses_" ).dialog( "close" );

					}
				},
				close : function(){
					$('#dlguploaduploadalatkantor_proses_').dialog("destroy"); 
					$(".dlguploaduploadalatkantor_proses_cl").remove(); 
					$("body").append('<div id="dlguploaduploadalatkantor_proses_" title="Warning" class="dlguploaduploadalatkantor_proses_cl"><p>Apakah anda akan memproses file ini?!?</p></div>');     
					
				},
				open: function(){
					$("body").unblock();
					
				}
			});	
			
			
			
		} );	
		
		$("#btn_alatkantordelet").click(function(){
		
			var id = jQuery("#tbluploaalatkantor").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tbluploaalatkantor").jqGrid('getRowData',id);
				
			} else {
				alert("Please Select Row dari tab upload data");
				$("#tabalatkantor_upload").tabs("select", 0);
				return false;
			};	
			
			var form_data = {
				id_uploadalatkantor_upload:ret.id_uploadalatkantor_upload,
				filename:ret.filename,
				
			
			};
			
			$("#dlguploaduploadalatkantor_delete_").dialog( "destroy" );
			$(".dlguploaduploadalatkantor_delete_cl").remove();
			$(".dlguploaduploadalatkantor_delete_cl").html('');
			$("body").append('<div id="dlguploaduploadalatkantor_delete_" title="Warning" class="dlguploaduploadalatkantor_delete_cl"><p>Apakah anda akan memdelete file ini?!?</p><br /> file = '+ ret.filename +'</div>');
			$("#dlguploaduploadalatkantor_delete_").dialog({
				height: 200,
				width: 250,
				modal: true,
				hide: 'Slide',
				autoOpen: 'false',
				buttons: {
					"CONFIRM": function() {
					$.ajax({
						url : "<?php echo base_url().'settings/ct_barangmesin/delete_uploadalatkantor'; ?>",
						type : 'POST',
						dataType: 'json',
						data : form_data,
						success: function(msg){
							if (msg.sts == '00'){
								alert(msg.desc);
								$("#dlguploaduploadalatkantor_delete_").dialog("close");
								$('#dlguploaduploadalatkantor_delete_').dialog("destroy"); 
								$(".dlguploaduploadalatkantor_delete_cl").remove(); 
								$('#tbluploaduploadalatkantor').trigger('reloadGrid');
								$('#tbl_alatkantor').trigger('reloadGrid');
								$('#tbluploaalatkantor').trigger('reloadGrid');
								$("#tabalatkantor_upload").tabs("select", 0);
							} else { 
								alert(msg.sts+' '+msg.desc); 
								$("#dlguploaduploadalatkantor_delete_").dialog("close");
								$('#dlguploaduploadalatkantor_delete_').dialog("destroy"); 
								$(".dlguploaduploadalatkantor_delete_cl").remove(); 

							}
						}
					});
				},
					"CANCEL": function() {
						$( "#dlguploaduploadalatkantor_delete_" ).dialog( "close" );

					}
				},
				close : function(){
					$('#dlguploaduploadalatkantor_delete_').dialog("destroy"); 
					$(".dlguploaduploadalatkantor_delete_cl").remove(); 
					$("body").append('<div id="dlguploaduploadalatkantor_delete_" title="Warning" class="dlguploaduploadalatkantor_delete_cl"><p>Apakah anda akan memdelete file ini?!?</p></div>');     
					
				},
				open: function(){
					$("body").unblock();
					
				}
			});	
						
		
		});
	
	});
		  	
</script>



	
	