<style>
    textarea, input[type="text"], input[type="password"], input[type="datetime"], input[type="datetime-local"], input[type="date"], input[type="month"], input[type="time"], input[type="week"], input[type="number"], input[type="email"], input[type="url"], input[type="search"], input[type="tel"], input[type="color"] {
    background-color: #ffffff;
    border: 1px solid #4c8fbd;
    border-radius: 5px !important;
    box-shadow: none !important;
    color: #858585;
    font-family: inherit;
    font-size: 14px;
    padding: 5px 4px 6px;
    transition-duration: 0.1s;
}
    </style>


<div class="col-sm-12 col-md-12">
<?php 
$allow=1;
if(!diaadmin()){
    $allow=GetValue('view','users_permission_sf',array('menu_id'=>'where/134','user_id'=>'where/'.$this->session->userdata('webmaster_marketing')));//lastq();
}?>
<?php if($allow==1){?>
    <div style="z-index:999999999;position: relative;float:right;margin-left:20px;"> 
    <button onclick="filter()">FILTER</button></div>
&nbsp;&nbsp;&nbsp;&nbsp;<div style="z-index:999999999;position: relative;float:right;margin-left:20px;" id="grupingnya">Group :  
<?php echo form_dropdown('group',GetOptAll('ref_group','-All-'),$this->session->userdata('groups'),'onchange="" id="grupnya"');?></div>&nbsp;&nbsp;
<div style="z-index:999999999;position: relative;float:right">Divisi :  
<?php echo form_dropdown('filter',GetOptAll('ref_divisi','-All-'),$this->session->userdata('divisi'),'onchange="gantiindivisi(this.value)" id="divisinya"');?></div>
<?php }?>
    <button data-toggle="collapse" data-target="#demo" class="btn-danger btn">Search</button>
<fieldset style="border:1px solid #D4011B; padding-bottom:10px; border-radius:5px;" class="col-md-12 collapse <?php if(isset($_POST['search'])) echo "in"?>" id="demo">
	
	<form enctype="multipart/form-data" method="post" action="<?php echo base_url() ?>activity_sales">
            <div class="col-sm-12 col-md-12" style="margin-top:10px">
                           <div class="col-sm-6 col-md-6"  style="float:none!important;margin:0 auto;"><?php echo form_dropdown('marketing',$opt_search,$_POST['marketing'],'class="select2"')?> &nbsp; &nbsp; &nbsp;
                           <?php echo form_dropdown('activity',$opt_activity,$_POST['activity'],'class="select2"')?>  &nbsp; &nbsp; &nbsp;
                           <?php echo form_dropdown('customer',$opt_customer,$_POST['customer'],'class="select2"')?></div>
            </div>
            <div class="col-sm-12 col-md-12" style="margin-top:12px;"> 
			   <div class="col-sm-6 col-md-6" style="float:none!important;margin:0 auto;"><label>Periode</label>
                           &nbsp; 
                               <?php $nm_f='from';?><input type="text" name="from" id="from" class="datepicker" data-provide="datepicker" data-date-format="yyyy-mm-dd" value="<?php echo (isset($_POST['from']) ? $_POST['from'] : '')?>">
                           <?php $nm_f='to'?>
                            - &nbsp;<input type="text" name="to" id="to" class="datepicker" data-provide="datepicker" data-date-format="yyyy-mm-dd" value="<?php echo (isset($_POST['to']) ? $_POST['to'] : '')?>"></div>
            </div>
			<?php echo form_hidden('lastq',$lastq);?>
            <div class="col-sm-12 col-md-12"><div class="col-sm-12 col-md-12"><input type="submit" value="Search" name="search">&nbsp;<input type="submit" value="Export" name="export"></div></div>
	<div class="col-sm-12" style="margin-top:10px"></div>
	
	</form>

</fieldset></div><?php // }?><br/><?php if($this->session->flashdata('message')){?>
<div class="col-sm-12" style="padding-left:0px!important; margin-top: 20px;">  <div class="alert alert-info"><?php echo $this->session->flashdata('message');?></div></div><?php  }?>
<?php
error_reporting(0);
 echo $js_grid; ?>
<!--input type="button" value="Tambah" onclick="window.location = '<?//= base_url() ?>index.php/ms_con/add'"/-->
<script type="text/javascript">
var _base_url = '<?php echo  base_url() ?>';
var controller = '<?php echo $this->utama?>/';
function del(id) { 
  i = confirm('Hapus : ' + id + ' ?');
  if (i) {
    window.location = _base_url + controller + 'delete/' + id;
  }
}
//$('.flex1').flexigrid({height:'auto',width:'auto',striped:false});

function edit(id) {
  window.location = _base_url + controller + 'input/' + id;
}

function detail(id) {
  window.location = _base_url + controller + 'form/' + id;
}
function btn(com,grid)
{
    if (com == 'add' ) {
		window.location = _base_url + controller + 'form/';
    }
	
    if (com == 'select' )
    {
		$('.bDiv tbody tr',grid).addClass('trSelected');
    }

    if (com == 'deselect')
    {
		$('.bDiv tbody tr',grid).removeClass('trSelected');
    }
	if(com=='edit'){
		if($('.trSelected',grid).length==1){ 
    			var abbr = [];
    				$('.hDiv th', flex).each( function(index){
       			 abbr[index] = $(this).attr('abbr');
  				  });
		//var items = $('.trSelected',grid);
 		 window.location = _base_url + controller + 'form/' + $('td:nth-child('+ (1+$.inArray('idnya',abbr)) +')>div', '.trSelected',grid).text();
			} else {
				return false;
			} 
	}
	if (com=='delete')
    {
           if($('.trSelected',grid).length>0){
			   if(confirm('Delete ' + $('.trSelected',grid).length + ' items?')){
		        var flex = $(grid).closest('.flexigrid');
    			var abbr = [];
    				$('.hDiv th', flex).each( function(index){
       			 abbr[index] = $(this).attr('abbr');
  				  });
    	
   				 $('.res').html('');//div.res - area for display result
		            var items = $('.trSelected',grid);
		            var itemlist ='';
		        	for(i=0;i<items.length;i++){
					//itemlist+=items[i].id+",";
					//var iteming=$('td:"no_reg" >div', items[i]).text();
					itemlist+=$('td:nth-child('+ (1+$.inArray('idnya',abbr)) +')>div', items[i]).text()+",";
					}
					  	
					$.ajax({
					   type: "POST",
					   url: "<?php echo site_url($this->utama."/deletec");?>",
					   data: "items="+itemlist,
					   success: function(data){
					   	$('#flex1').flexReload();
						//alert(data);
						if(data=='ok'){
						alert('Sukses!');}
						else{
							alert('Failed to Delete Data');
						}
					   }
					});
				}
			} else {
				return false;
			} 
      }       
	if (com=='export to xls')
    {
           if($('.trSelected',grid).length>0){
			   if(confirm('Export ' + $('.trSelected',grid).length + ' items?')){
		        var flex = $(grid).closest('.flexigrid');
    			var abbr = [];
    				$('.hDiv th', flex).each( function(index){
       			 abbr[index] = $(this).attr('abbr');
  				  });
    	
   				 $('.res').html('');//div.res - area for display result
		            var items = $('.trSelected',grid);
		            var itemlist ='';
		        	for(i=0;i<items.length;i++){
					//itemlist+=items[i].id+",";
					//var iteming=$('td:"no_reg" >div', items[i]).text();
                                        var maxxx=items.length-1;
                                        if(i==maxxx){ var azz='';}
					else{
                                        var azz='%';
                                        }
                                           itemlist+=$('td:nth-child('+ (1+$.inArray('idnya',abbr)) +')>div', items[i]).text()+azz;
					}
					  window.location = '<?php echo site_url($this->utama."/render_xls");?>/'+itemlist;	
					$.ajax({
					   type: "POST",
					   url: "<?php echo site_url($this->utama."/to_xls");?>",
					   data: "items="+itemlist,
					   success: function(data){
                                               
                                $("body").append("<iframe src='<?php echo site_url($this->utama."/to_xls");?>' style='display: none;' ></iframe>");
					   	//$('#flex1').flexReload(); 
						//alert(data);
//						if(data=='ok'){
//						alert('Sukses!');}
//						else{
//							alert('Failed to Delete Data');
//						}
					   }
					});
				}
			} else {
				return false;
			} 
      }  
      if (com=='export to pdf')
    {
           if($('.trSelected',grid).length>0){
			   if(confirm('Export ' + $('.trSelected',grid).length + ' items?')){
		        var flex = $(grid).closest('.flexigrid');
    			var abbr = [];
    				$('.hDiv th', flex).each( function(index){
       			 abbr[index] = $(this).attr('abbr');
  				  });
    	
   				 $('.res').html('');//div.res - area for display result
		            var items = $('.trSelected',grid);
		            var itemlist ='';
		        	for(i=0;i<items.length;i++){ 
					//itemlist+=items[i].id+",";
					//var iteming=$('td:"no_reg" >div', items[i]).text();
                                        var maxxx=items.length-1;
                                        if(i==maxxx){ var azz='';}
					else{
                                        var azz='%';
                                        }
                                           itemlist+=$('td:nth-child('+ (1+$.inArray('idnya',abbr)) +')>div', items[i]).text()+azz;
					}
					  window.location = '<?php echo site_url($this->utama."/render_pdf");?>/'+itemlist;	
					$.ajax({
					   type: "POST",
					   url: "<?php echo site_url($this->utama."/to_xls");?>",
					   data: "items="+itemlist,
					   success: function(data){
                                               
                                $("body").append("<iframe src='<?php echo site_url($this->utama."/to_xls");?>' style='display: none;' ></iframe>");
					   	//$('#flex1').flexReload(); 
						//alert(data);
//						if(data=='ok'){
//						alert('Sukses!');}
//						else{
//							alert('Failed to Delete Data');
//						}
					   }
					});
				}
			} else {
				return false;
			} 
      }    
}
setInterval("$('#flex1').flexReload()",50000 );

function removeParam(key, sourceURL) {
    var rtn = sourceURL.split("?")[0],
        param,
        params_arr = [],
        queryString = (sourceURL.indexOf("?") !== -1) ? sourceURL.split("?")[1] : "";
    if (queryString !== "") {
        params_arr = queryString.split("&");
        for (var i = params_arr.length - 1; i >= 0; i -= 1) {
            param = params_arr[i].split("=")[0];
            if (param === key) {
                params_arr.splice(i, 1);
            }
        }
        rtn = rtn + "" + params_arr.join("&");
    }
    return rtn;
} 
function filter(){
    var divisi=$('#divisinya').val();
    var grup=$('#grupnya').val();
    $.post('<?php echo base_url()?>load/gantidivisidashboard',{d:divisi,g:grup},function(e){
                var abc = $(".tab-pane.fade.in.active").attr("id");
                var winz=window.location.href;
                var res=removeParam('activer',winz);
   window.location.href = res + "?activer="+abc;

    });
}
function gantiindivisi(){
    
    var dz=$('#divisinya').val();
    $('#grupingnya').load('<?php echo base_url()?>load/grup/',{dz:dz});
    
    }
function gantidivisi(val){
    $.post('<?php echo base_url()?>load/gantidivisidashboard',{d:val},function(e){
                var abc = $(".tab-pane.fade.in.active").attr("id");
                var winz=window.location.href;
                var res=removeParam('activer',winz);
   window.location.href = res + "?activer="+abc;

    });
}
</script>
<div class="col-sm-12" style="padding-left:0px!important; margin-top: 20px;">
<div class="layout-grid">
	<table id="flex1" style="display:none; "></table>
</div>
</div>