<?php
	$uid = $this->session->userdata('usertype_id');
	$profile_id = $this->session->userdata('profile_id');
	if($uid==1)
		$data = array("Export");
	else
	{
		$data = array();
		$va1l = $this->db;
		$va1l->select("setting_name");
		$va1l->where("profile_id",$profile_id);
		$va1l->where("setting_name !=",'main');
		$va1l->where("menu_id",'117');
		$va1l ->where("del_date",NULL);
		$res_val = $va1l->get("mst_user_profile_setting");
		foreach($res_val ->result_array() as $row)
		{
			$data[] = $row['setting_name'];
			
		}
	
	}

	$date_format = $this->session->userdata('date_format');  
	$time_format = $this->session->userdata('time_format');  
	$js_date_format = $this->session->userdata('js_date_format');
        $js_time_format = $this->session->userdata('js_time_format');
	 $ampm="";
	 $js_time_format=str_replace ("tt", "TT" ,$js_time_format);
	 if(strpos($js_time_format, 'TT'))
	 {
		$ampm="ampm:true,";
	 }	
	 
?>
<style>
#load_bin_details_report_grid
{
	display:none !important; 
}

#bin_details_report_grid td {           
    word-wrap: break-word; /* IE 5.5+ and CSS3 */
    white-space: pre-wrap; /* CSS3 */
    white-space: -pre-wrap; /* Opera 4-6 */
    white-space: -o-pre-wrap; /* Opera 7 */
    white-space: normal !important;
    height: auto;
    vertical-align: text-top;
    padding-top: 2px;
    padding-bottom: 3px;
}
 #ui_tpicker_hour_label_all_points_sdate,#ui_tpicker_hour_label_all_points_edate
    {
        padding: 0px !important;
        margin-top: 4px !important;
        text-align: left !important;
        line-height:0px !important;
    }
    #ui_tpicker_minute_label_all_points_sdate,#ui_tpicker_minute_label_all_points_edate
    {
        padding: 0px !important;
        margin-top: 4px !important;
        text-align: left !important;
        line-height:0px !important;
    }
    #ui_tpicker_second_label_all_points_sdate,#ui_tpicker_second_label_all_points_edate
    {
        padding: 0px !important;
        margin-top: 4px !important;
        text-align: left !important;
        line-height:0px !important;
    }
</style>
<script type="text/javascript">
loadMultiSelectDropDown();
var assets_nm;
jQuery().ready(function (){
	
	jQuery("input:button, input:submit, input:reset").button();
	jQuery("#bin_details_report_grid").jqGrid({
		url:"<?php echo base_url(); ?>index.php/reports/bin_details_report/loadData",
		datatype: "json",
		//,'Device ID'
		colNames:["<?php echo $this->lang->line("ID"); ?>", '<?php echo "Date Time"; ?>', '<?php echo $this->lang->line("asset_id"); ?>','<?php echo "Location"; ?>','<?php echo $this->lang->line("photo"); ?>','<?php echo $this->lang->line("empty_or_full"); ?>','<?php echo $this->lang->line("note"); ?>'],
		colModel:[
			{name:"id",index:"id",hidden:true, width:15, jsonmap:"id"},
                        {name:"add_date", editable: true, index: "add_date", width: 150, align: "left", jsonmap: "add_date", formatter: 'date', formatoptions: {srcformat: "Y-m-d H:i:s", newformat: "<?php echo $date_format; ?> <?php echo $time_format; ?>"}},
			{name:"asset_id",editable:true, index:"asset_id", width:150, align:"left", jsonmap:"asset_id"},
                        {name:"address",editable:true, index:"address", width:150, align:"left", jsonmap:"address"},
			{name:"photo",editable:true, index:"photo", width:150, align:"center", jsonmap:"photo",formatter: imagePathFormatter},
                        {name:"empty_or_full",editable:true, index:"empty_or_full", width:150, align:"left", jsonmap:"empty_or_full"},
                        {name:"note",editable:true, index:"note", width:150, align:"left", jsonmap:"note"},
			
		],
		rowNum:100,
		height: 'auto',
		rownumbers: true,
		autowidth: true,
		shrinkToFit: true,
		rowList:[10,20,30,50,100],
		pager: jQuery("#bin_details_report_pager"),
		sortname: "id",
		loadComplete: function(){
			$("#loading_top").css("display","none");
			$("#bin_details_report_grid").setGridParam({datatype: 'json'}); 
		},	
		loadBeforeSend: function(){$("#loading_top").css("display","block");},
		viewrecords: true,
		multiselect: false, 
		sortorder: "desc",
		caption:"<?php echo $this->lang->line("Bin Details Report"); ?>",
		editurl:"users/deleteData",
		jsonReader: { repeatitems : false, id: "0" }
	});
 
	jQuery("#bin_details_report_grid").jqGrid("navGrid", "#bin_details_report_pager", {add:false, edit:false, del:false, search:false}, {}, {}, {}, {multipleSearch:false});
	<?php
	if(in_array('Export',$data)){
	?>
	jQuery("#bin_details_report_grid").jqGrid("navButtonAdd","#bin_details_report_pager",{caption:"<?php echo $this->lang->line("Export"); ?>",
		onClickButton:function(){
			
			//var device = $('#data_logs_device').val();
                        var sdate = $('#bin_details_sdate').val();
			var edate = $('#bin_details_edate').val();
                        var device="";
			for(i=0;i<=assets_count;i++){
				if($("#ddcl-bin_details_device-i"+i).is(':checked')){
					device+=$("#ddcl-bin_details_device-i"+i).val()+",";
				}
			}
			if(device == ''){
				$("#alert_dialog").html('<?php echo $this->lang->line("Please select device"); ?>');
				$("#alert_dialog").dialog("open");
				return false;
			}
			var qrystr ="?cmd=export&sdate="+sdate+"&edate="+edate+"&device="+device;
			document.location = "<?php echo base_url(); ?>index.php/reports/bin_details_report/loadData"+qrystr;
		}
	});
	<?php } ?>
                        $("#bin_details_sdate").datetimepicker({dateFormat: '<?php echo $js_date_format; ?>', timeFormat: '<?php echo $js_time_format; ?>',<?php echo $ampm; ?>changeMonth: true, showSecond: true, changeYear: true});
                        $("#bin_details_edate").datetimepicker({dateFormat: '<?php echo $js_date_format; ?>', timeFormat: '<?php echo $js_time_format; ?>',<?php echo $ampm; ?>changeMonth: true, showSecond: true, changeYear: true});

                        $("#bin_details_sdate").datetimepicker('setDate', new Date('<?php echo date("Y/m/d H:i:s", strtotime("12:00:00 am")); ?>'));
                        $("#bin_details_edate").datetimepicker('setDate', new Date('<?php echo date("Y/m/d H:i:s", strtotime("11:59:59 pm")); ?>'));
                        $("#bin_details_device").html(assets_combo_opt_report);
                        $("#bin_details_device").dropdownchecklist({ firstItemChecksAll: true, textFormatFunction: function(options) {
                        var selectedOptions = options.filter(":selected");
                        var countOfSelected = selectedOptions.size();
                        switch(countOfSelected) {
                            case 0: return "<i>Please Select<i>";
                            case 1: return selectedOptions.text();
                            case options.size(): return "<b>All Assets</b>";
                            default: return countOfSelected + " Assets";
                        }
                    }, icon: {}, width: 150});
                $("#ddcl-bin_details_device").css('vertical-align','middle');
                $("#ddcl-bin_details_device-ddw").css('overflow-x','hidden');
                $("#ddcl-bin_details_device-ddw").css('overflow-y','auto');
                $("#ddcl-bin_details_device-ddw").css('height','200px');
                $(".ui-dropdownchecklist-dropcontainer").css('overflow','visible');

}); 

function searchdata_logs(){
	
	
	//var dev=$('#bin_details_device').val();
        var sdate = $('#bin_details_sdate').val();
        var edate = $('#bin_details_edate').val();
	//console.log("dev:"+dev);
        var dev="";
	for(i=0;i<=assets_count;i++){
		if($("#ddcl-bin_details_device-i"+i).is(':checked')){
			dev+=$("#ddcl-bin_details_device-i"+i).val()+",";
		}
	}
        console.log("dev:"+dev);
	if(dev == ""){
		$("#alert_dialog").html('<?php echo $this->lang->line("Please select device"); ?>');
		$("#alert_dialog").dialog("open");
		return false;
	}
	$("#loading_top").css("display","block");
	assets_nm=$('#data_logs_device option:selected').val();
	jQuery("#bin_details_report_grid").jqGrid('setGridParam',{postData:{sdate: sdate, edate: edate, device:dev, page:1}}).trigger("reloadGrid");
	
	
	return false;	
}

function imagePathFormatter(cellvalue, options, rowObject){
	if(cellvalue != ""){
		return '<a href="http://63.142.252.191/vts//assets/photo/'+cellvalue+'" target="_blank"><img style="height:90px;width:120px;" src="<?php echo base_url(); ?>/assets/photo/'+cellvalue+'" border="0"></a>';
	}
	else
		return '';
}

</script>
<?php
	$timestamp=date("d.m.Y");
	$timestamp = strtotime("+2 day");
	$tomorrow=strftime( "%d.%m.%Y",$timestamp); 
?>
<div id="bin_details_report_div">
<form onsubmit="return searchdata_logs()">
	<table border="5" width="100%" class="formtable" style="margin-bottom: 5px;">
	<tr>
                <td width="15%"><?php echo $this->lang->line("Start"); ?> :<br> <input type="text" name="sdate" id="bin_details_sdate" class="date text ui-widget-content ui-corner-all" style="width:150px" value="" readonly="readonly"/></td>
                <td width="15%"><?php echo $this->lang->line("End"); ?> : <br><input type="text" name="edate" id="bin_details_edate" class="date text ui-widget-content ui-corner-all" style="width:150px" value="" readonly="readonly"/></td>
		<td width="15%"><?php echo $this->lang->line("Assets"); ?> : </br><select name="device_1" id="bin_details_device" class="select ui-widget-content ui-corner-all" style="width:70% !important" multiple='multiple'></select></td>
	<td align="center" width="15%"><br><input type="submit" value="<?php echo $this->lang->line("Search"); ?>"/></td>
        </tr>
	</table>
</form>
</div>
<table id="bin_details_report_grid" class="jqgrid"></table>

<div id="bin_details_report_pager"></div>
</div>
<script type="text/javascript">
	<?php /* google analytic code. */ ?>
	var _gaq = _gaq || [];
	_gaq.push(['_setAccount', 'UA-37380597-1']);
	_gaq.push(['_trackPageview']);

	(function() {
	var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
	ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
	var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
	})();
</script>