<?php session_start();
$pageSequence = $_SESSION['sequence'];
$toDiv = "contentZone" . $pageSequence;
$resultZoneDiv = "resultZone" . $pageSequence;
$tableZone ="#tableZone".$pageSequence;
$dataResultZone = "dataResult".$pageSequence;
$tableStats = "tableStats".$pageSequence ;
$chartStats = "chartStats".$pageSequence ;
$frmName = "form".$pageSequence ;
$_SESSION['sequence']++;
//echo  dirname(__FILE__);  
//echo $_SERVER['DOCUMENT_ROOT'] . "   ".dirname(__FILE__)."  ".str_replace($_SERVER['DOCUMENT_ROOT'],"",dirname(__FILE__)) ;

$currentBaseDir = dirname($_SERVER['PHP_SELF']);
//echo $currentBaseDir ;
include($_SESSION['basedir']."core.php");
$res = $dba->getSCCCustomerDetails(0); 
$callres = $dba->getSCCCCompanyList(0);
// getUserDetailByRight($_SESSION['right'], $_SESSION['ownerId'],0 ,false, 0,0);

//$dba->getProfileListByRight($_SESSION['right']);


?>

<div id="<?php echo $toDiv; ?>" class="tab-content"  >
  <div id="search-container">
  
<fieldset>
      <legend>Critère de recherche</legend>
    <form class="form-inline" action="<?php echo $currentBaseDir; ?>/get_company_stats.php" method="post" enctype="multipart/form-data"  id="<?php echo $frmName; ?>" tableStats="<?php echo $tableStats;?>" chartStats="<?php echo $chartStats; ?>"   onsubmit="return false;">
    <table width="100%" border="0" cellpadding="0" cellspacing="2">
  <tr>
    <td width="3%">&nbsp;</td>
    <td width="19%" align="right">Date de début : </td>
    <td colspan="3"><div class="form-group">
                            <div class='input-group date' id='datetimepicker50'>
                                <input name="startDateTime" type='text' class="form-control" id="startDateTime"  value="<?php echo date('Y-m-d')." 00:00:00" ; ?>" size="30"/>
                                <span class="input-group-addon">
                                    <span class="glyphicon glyphicon-calendar"></span>
                                </span>
                            </div>
                        </div>      <!--Mode--><!--<select id="statsMode" name="statsMode" class="form-control">
      <option value="0" selected="selected">Diagramme</option>
      <option value="1" >Table</option>                                               
    </select> --> </td>
    </tr>
  <tr>
    <td height="32">&nbsp;</td>
    <td align="right">Date de fin : </td>
    <td colspan="3"><div class="form-group">
                            <div class='input-group date' id='datetimepicker51'>
                                <input name="endDateTime" type='text' class="form-control" size="30" id="endDateTime" value="<?php echo date('Y-m-d')." 23:59:59" ; ?>" />
                                <span class="input-group-addon">
                                    <span class="glyphicon glyphicon-calendar"></span>
                                </span>
                            </div>
                        </div></td>
    </tr>
  <tr>
    <td height="32">&nbsp;</td>
    <td align="right">Soci&eacute;t&eacute; : </td>
    <td colspan="3"><select id="companyId" name="companyId" class="form-control" >
      <option value="-1" selected="selected"> -- Tout -- </option>
      <?php
                  for ($i = 0; $i < count($callres); $i++) {
               ?>
      <option value="<?php echo $callres[$i]['company_id_n']; ?>"> <?php echo $callres[$i]['company_name_v']; ?></option>
      <?php
                                                        }
                                                        ?>
    </select></td>
    </tr>
  <tr>
    <td height="32">&nbsp;</td>
    <td colspan="2" align="center"><input type="submit" value="Afficher"   /></td>
    <td width="37%" align="center">&nbsp;</td>
    <td width="16%" align="center" valign="middle">&nbsp;</td>
  </tr>
  <tr>

    <td height="19" colspan="5">&nbsp; <input type="hidden" name="tableStats" value="<?php echo $tableStats;?>" /><input type="hidden" name="chartStats" value="<?php echo $chartStats;?>" /></td>
  </tr>
    </table>

    
   </form>
   </fieldset>
  </div>
  
  <div id="result-container" >
  <fieldset>
      <legend>R&eacute;sultats</legend>
     <table width="100%" border="0">
  <tr>
    <td align="center" valign="middle">
    <table width="98%" height="100%">
      <tr>
        <td height="142" valign="top">
        <div id="<?php echo $tableStats;?>" style="overflow:auto; max-height:inherit">
            <table id="tblCompanyStats"  width="100%" height="25%" class="table table-striped table-bordered" >
                <thead>
                    <tr>
                        <th width="17%" >Date</th>
                        <th width="31%">Soci&eacute;t&eacute;</th>
                        <th width="27%">Motif d'appel</th>
                        <th width="25%">Total</th>
                    </tr>
                </thead>
                </table>
        </div></td>
        </tr>
      </table>
    </td>
  </tr>
  </table>
   </fieldset>
  </div>

 
</div>
<div id="loader" ></div>
<script src="plugins/datatables/jquery.dataTables.min.js"></script>
<script src="plugins/datatables/dataTables.bootstrap.min.js"></script>
<script src="plugins/datatables/dataTables.buttons.min.js"></script>
<script src="plugins/datatables/buttons.html5.min.js"></script>
<script type="text/javascript" src="js/jquery.loading.min.js"></script>

<script type="text/javascript">

$( document ).ready(function() {
	var dataUrl = "<?php echo $currentBaseDir; ?>/return_json_default.php?json=[]"  ; 
	sttable = $('#tblCompanyStats').DataTable( {
		               ajax: {
								url: dataUrl,
								method: "POST",
								dataSrc: '' 
							  },
						columns : [
									{ data: "Date" },
									{ data: "Company" },
									{ data: "CallReason" },
									{ data: "Total" }
								]
				         ,
						 processing : true
						 ,
						 dom: 'Bfrtip',
								buttons: [
									 'csv', 'excel', 'pdf'
								],
				        "language": {
						"search": "Filtrer:",
						"emptyTable" : "Table vide",
						"zeroRecords":    "Table vide",
						"lengthMenu":     "Nombre de lignes  _MENU_ ",
					
						"info":           "Affichage de  _START_ &aacute; _END_ sur  _TOTAL_ entr&eacute;es",
						"paginate": {
							"first":      "D&eacute;but",
							"last":       "Fin",
							"next":       "Suivant",
							"previous":   "Pr&eacute;c&eacute;dent"
						},
						"infoEmpty":      "Affichage de  0 &agrave; 0 sur  0 entr&eacute;es"
					  }
					});
   
});


                        $(function () {
                            $('#datetimepicker50').datetimepicker({format: 'yyyy-mm-dd hh:ii:ss'});
                        });
</script>
                    
                    
<script type="text/javascript">
                        $(function () {
                            $('#datetimepicker51').datetimepicker({format: 'yyyy-mm-dd hh:ii:ss'});
                        });
                    </script>
                    
                    
<script type="text/javascript">

$('#<?php echo $frmName; ?>').on("submit", function(event) {
	$('#loader').loading({
		  message : "Chargement...",
		  theme : 'dark'
		  
		});
	var tableStats =  $( "form" ).attr('tableStats');
    var chartStats =  $( "form" ).attr('chartStats') ;
	/* var startDateTime = document.getElementById('startDateTime').value;
	var endDateTime = document.getElementById('endDateTime').value;
	var userId = document.getElementById('userId').value;
	var status = document.getElementById('status').value;
	var statsMode = document.getElementById('statsMode').value;
	*/
	
	///alert(tableStats + "   " + chartStats );
	
	 $.post($(this).attr("action"), $(this).serialize(), function(data) {
		sttable.clear();
		sttable.rows.add(JSON.parse(data)); 
		sttable.draw();
		 
		 
		  $('#loader').loading('stop');
		/*
		 if ( $.fn.dataTable.fnIsDataTable( '#tblGlobalStats' ) ){
		//alert("Alload");
		// reload instead
     	
				
			}
			else {
				
				
				
			} */
		 
	 });
	
	
	
	  
	
	
	
       // return false; // prevent normal submit
  event.preventDefault();
	 
    });

</script>