<?php

$pageSequence = $_SESSION['sequence'];
$toDiv = "contentZone" . $pageSequence;
$resultZoneDiv = "resultZone" . $pageSequence;
$tableZone = "#tableZone" . $pageSequence;
$tblName = "tblReport" . $pageSequence;
$btAdd = "btnAdd" . $pageSequence;
$btDel = "btnDel" . $pageSequence;
$btDelObj = "btnDelObj" . $pageSequence;
$dataSection = "dataSection" . $pageSequence;
$_SESSION['sequence']++;
//echo  dirname(__FILE__);  
//echo $_SERVER['DOCUMENT_ROOT'] . "   ".dirname(__FILE__)."  ".str_replace($_SERVER['DOCUMENT_ROOT'],"",dirname(__FILE__)) ;

$currentBaseDir = dirname($_SERVER['PHP_SELF']);
include_once($_SESSION['basedir'] . "core.php");


$chart_data = '';
$totalTicketRes = $dba->getCRMTicketCountByUser($_SESSION['right'], $_SESSION['login']);
$openTicketRes = $dba->getCRMTicketStatusCountByUser($_SESSION['right'], $_SESSION['login'], 2);
$closeTicketRes = $dba->getCRMTicketStatusCountByUser($_SESSION['right'], $_SESSION['login'], 3);
$initiatedTicketRes = $dba->getCRMTicketStatusCountByUser($_SESSION['right'], $_SESSION['login'], -1);

$campaignDatadts = "";
$res = $dba->getCRMWeeklyStats($_SESSION['right'], $_SESSION['ownerId']) ;

for ($i = 0; $i < count($res); $i++) {

$campaignDatadts .= "{ y: '".$res[$i]['EventDate']."', a: ".$res[$i]['Initiated']." , b: ".$res[$i]['Opened']." , c: ".$res[$i]['Closed']."}, ";

}
$campaignDatadts = substr($campaignDatadts, 0, -2);

//echo $campaignDatadts;

$res = $dba->getCRMMonthlyStats($_SESSION['right'], $_SESSION['ownerId']) ;

for ($i = 0; $i < count($res); $i++) {

$chart_data .= "{ Mois:'".$res[$i]['eventdatetime']."', Total:".$res[$i]['total']."}, ";

}
$chart_data = substr($chart_data, 0, -2);



// Daily Ticket trend 
$totalTicketDaily = $dba->getCRMTotalDailyTicket();
$totalUnAswer = $dba->getCRMTotalDailyTicketByStatus(7);
$totalInitiated = $dba->getCRMTotalDailyTicketByStatus(-1);
$totalOpened = $dba->getCRMTotalDailyTicketByStatus(2);
$totalClosed = $dba->getCRMTotalDailyTicketByStatus(3);


$unAnswerRatio = round(($totalUnAswer/$totalTicketDaily)*100);
$initiatedRatio = round(($totalInitiated/ $totalTicketDaily)*100);
$openedRatio = round(($totalOpened/ $totalTicketDaily)*100);
$closedRatio = round(($totalClosed/ $totalTicketDaily)*100);




?>

<link href="assets/plugins/jquery-ui-1.12.1/jquery-ui.min.css" rel="stylesheet" type="text/css"/>
<link href="assets/plugins/morris/morris.css" rel="stylesheet" type="text/css"/>

<!-- Content Header (Page header) -->
            <section class="content-header">
               <div class="header-icon">
                  <i class="fa fa-dashboard"></i>
               </div>
               <div class="header-title">
                  <h1>Tableau de bord</h1>
                  <small>Vue synthétique </small>
               </div>
            </section>
            <!-- Main content -->
            <section class="content">
               <div class="row">
                  <div class="col-xs-12 col-sm-6 col-md-6 col-lg-3">
                     <div id="cardbox1">
                        <div class="statistic-box">
                           <i class="fa fa-ticket fa-3x"></i>
                           <div class="counter-number pull-right">
                              <span class="count-number"><?php echo $initiatedTicketRes['total'] ; ?></span> 
                              <span class="slight"><i class="fa fa-play fa-rotate-270"> </i>
                              </span>
                           </div>
                           <h3> Tickets initialisés</h3>
                        </div>
                     </div>
                  </div>
                  <div class="col-xs-12 col-sm-6 col-md-6 col-lg-3">
                     <div id="cardbox2">
                        <div class="statistic-box">
                           <i class="fa fa-folder-open-o fa-3x"></i>
                           <div class="counter-number pull-right">
                              <span class="count-number"><?php echo $openTicketRes['total'] ; ?></span> 
                              <span class="slight"><i class="fa fa-play fa-rotate-270"> </i>
                              </span>
                           </div>
                           <h3>Tickets ouverts</h3>
                        </div>
                     </div>
                  </div>
                  <div class="col-xs-12 col-sm-6 col-md-6 col-lg-3">
                     <div id="cardbox3">
                        <div class="statistic-box">
                           <i class="fa fa-user-o fa-3x"></i>
                           <div class="counter-number pull-right">
                              <i></i><span class="count-number">0</span> 
                              <span class="slight"><i class="fa fa-play fa-rotate-270"> </i>
                              </span>
                           </div>
                           <h3>File d'attente</h3>
                        </div>
                     </div>
                  </div>
                  <div class="col-xs-12 col-sm-6 col-md-6 col-lg-3">
                     <div id="cardbox4">
                        <div class="statistic-box">
                           <i class="fa fa-bar-chart-o fa-3x"></i>
                           <div class="counter-number pull-right">
                              <span class="count-number"><?php if($totalTicketRes['total']>0) {echo round(($closeTicketRes['total']/$totalTicketRes['total'])*100,2) ; } else echo 0;?>%</span> 
                              <span class="slight"><i class="fa fa-play fa-rotate-270"> </i>
                              </span>
                           </div>
                           <h3> Performance</h3>
                        </div>
                     </div>
                  </div>
               </div>
               <div class="row">
                  <div class="col-xs-12 col-sm-6 col-md-6 col-lg-6">
                     <div class="panel panel-bd lobidisable">
                        <div class="panel-heading">
                           <div class="panel-title">
                              <h4>Derniers tickets ouverts</h4>
                           </div>
                        </div>
                        <div class="panel-body">
                           <div class="work-touchpoint">
                              <div class="work-touchpoint-date">
                                 <span class="day">28</span>
                                 <span class="month">Av</span>
                              </div>
                           </div>
                           <div class="detailswork">
                              <span class="label-custom label label-default pull-right">En cours..</span>
                              <a href="#" title="headings">Campagne test 1</a> <br>
                              <p>Cmapagne test pour...</p>
                           </div>
                           <div class="work-touchpoint">
                              <div class="work-touchpoint-date">
                                 <span class="day">2</span>
                                 <span class="month">Av</span>
                              </div>
                           </div>
                           <div class="detailswork">
                              <span class="label-custom label label-default pull-right">Terminé</span>
                              <a href="#" title="headings">Cmapgne test 3..</a> <br>
                              <p>Cmapagne test pour...</p>
                           </div>
                           <div class="work-touchpoint">
                              <div class="work-touchpoint-date2">
                                 <span class="day">17</span>
                                 <span class="month">Mrc</span>
                              </div>
                           </div>
                           <div class="detailswork">
                              <span class="label-custom label label-default pull-right">phone</span>
                              <a href="#" title="headings">Marketing policy</a> <br>
                              <p>Madrid  - spain</p>
                           </div>
                           <div class="work-touchpoint">
                              <div class="work-touchpoint-date2">
                                 <span class="day">3</span>
                                 <span class="month">jan</span>
                              </div>
                           </div>
                           <div class="detailswork">
                              <span class="label-custom label label-default pull-right">Mobile</span>
                              <a href="#" title="headings">Finance policy</a> <br>
                              <p>south Australia  - Australia</p>
                           </div>
                        </div>
                     </div>
                  </div>
                  <div class="col-xs-12 col-sm-6 col-md-6 col-lg-6">
                     <div class="panel panel-bd lobidisable">
                        <div class="panel-heading">
                           <div class="panel-title">
                              <h4>Statistiques du jour</h4>
                           </div>
                        </div>
                        <div class="panel-body">
                           <div class="runnigwork">
                              <span class="label-danger label label-default pull-right"><?php echo $totalUnAswer; ?></span>
                              <i class="fa fa-dot-circle-o"></i>        
                              <a href="#">Appels non répondus</a><br>                          
                              <div class="progress runningprogress">
                                 <div class="progress-bar progress-bar-striped" role="progressbar" style="width: <?php echo $unAnswerRatio; ?>%" aria-valuenow="<?php echo $unAnswerRatio; ?>" aria-valuemin="0" aria-valuemax="100" data-toggle="tooltip" data-placement="top" title="" data-original-title="25%"></div>
                              </div>
                           </div>
                           <div class="runnigwork">
                              <span class="label-warning label label-default pull-right"><?php echo $totalInitiated; ?></span>
                              <i class="fa fa-dot-circle-o"></i>        
                              <a href="#">Tickets initialisés</a><br>                          
                              <div class="progress runningprogress">
                                 <div class="progress-bar progress-bar-striped" role="progressbar" style="width: <?php echo $initiatedRatio; ?>%" aria-valuenow="<?php echo $initiatedRatio; ?>" aria-valuemin="0" aria-valuemax="100" data-toggle="tooltip" data-placement="top" title="" data-original-title="15%"></div>
                              </div>
                           </div>
                           <div class="runnigwork">
                              <span class="label-success label label-default pull-right"><?php echo $totalOpened; ?></span>
                              <i class="fa fa-dot-circle-o"></i>        
                              <a href="#">Tickets ouverts</a><br>                          
                              <div class="progress runningprogress">
                                 <div class="progress-bar progress-bar-striped" role="progressbar" style="width: <?php echo $openedRatio; ?>%" aria-valuenow="<?php echo $openedRatio; ?>" aria-valuemin="0" aria-valuemax="100" data-toggle="tooltip" data-placement="top" title="" data-original-title="45%"></div>
                              </div>
                           </div>
                           <div class="runnigwork">
                              <span class="label-info label label-default pull-right"><?php echo $totalClosed; ?></span>
                              <i class="fa fa-dot-circle-o"></i>        
                              <a href="#">Tickets Clos</a><br>                          
                              <div class="progress runningprogress">
                                 <div class="progress-bar progress-bar-striped" role="progressbar" style="width: <?php echo $closedRatio; ?>%" aria-valuenow="<?php echo $closedRatio; ?>" aria-valuemin="0" aria-valuemax="100" data-toggle="tooltip" data-placement="top" title="" data-original-title="75%"></div>
                              </div>
                           </div>
                           <div class="runnigwork">
                              <span class="label-success label label-default pull-right"><?php echo $closedRatio; ?></span>
                              <i class="fa fa-dot-circle-o"></i>        
                              <a href="#">Performance</a><br>                          
                              <div class="progress runningprogress">
                                 <div class="progress-bar progress-bar-striped" role="progressbar" style="width: <?php echo $closedRatio; ?>%" aria-valuenow="<?php echo $closedRatio; ?>" aria-valuemin="0" aria-valuemax="100" data-toggle="tooltip" data-placement="top" title="" data-original-title="50%"></div>
                              </div>
                           </div>
                        </div>
                     </div>
                  </div>
               </div>

            
               <div class="row">
                  <!-- Barchart -->
                  <div class="col-xs-12 col-sm-12 col-md-8 col-lg-8">
                     <div class="panel panel-bd lobidisable">
                        <div class="panel-heading">
                           <div class="panel-title">
                              <h4>Evolution des campagnes de la semaine</h4>
                           </div>
                        </div>
                        <div class="panel-body">
                           <div id="camp" style="height: 250px; width: 100%;"></div>
                        </div>
                     </div>
                  </div>
                  <!-- bar chart -->
                  <div class="col-xs-12 col-sm-12 col-md-4 col-lg-4">
                     <div class="panel panel-bd lobidisable">
                        <div class="panel-heading">
                           <div class="panel-title">
                              <h4>Appels mensuels</h4>
                           </div>
                        </div>
                        <div class="panel-body">
                            <div class="tab-content no-padding">
              <!-- Morris chart - Sales -->
              <div class="chart tab-pane active" id="revenue-chart" style="position: relative; height: 300px;"></div>
              <div class="chart tab-pane" id="sales-chart" style="position: relative; height: 300px;"></div>
            </div>
                        </div>
                     </div>
                  </div>
               </div>
               <!-- /.row -->
              
            </section>
            <!-- /.content -->




<script src="assets/plugins/jQuery/jquery-1.12.4.min.js" type="text/javascript"></script>
<!-- jquery-ui --> 
<script src="assets/plugins/jquery-ui-1.12.1/jquery-ui.min.js" type="text/javascript"></script>
<script src="assets/plugins/morris/raphael.min.js" type="text/javascript"></script>
<script src="assets/plugins/morris/morris.min.js" type="text/javascript"></script>

 <script type="text/javascript" >
 /*
var Area_chart = Morris.Area({
 	element: 'revenue-chart', 
 	behaveLikeLine: true,
 	parseTime : false, 
	data: [<?php echo $campaignDatadts; ?>],
 	xkey: 'y',
 	ykeys: ['a','b'],
 	labels: ['Statut','Total'],
 	pointFillColors: ['#707f9b'],
 	pointStrokeColors: ['#ffaaab'],
 	lineColors: ['#f26c4f', '#00a651', '#00bff3'],
 	redraw: true, 
 });*/
 
 var Area_chart = Morris.Area({
 	element: 'camp', 
 	behaveLikeLine: true,
 	parseTime : false, 
	data: [<?php echo $campaignDatadts; ?>],
 	xkey: 'y',
 	ykeys: ['a','b','c'],
 	labels: ['Initié','Ouvert', 'Clos'],
 	pointFillColors: ['#707f9b'],
 	pointStrokeColors: ['#ffaaab'],
 	lineColors: ['#f26c4f', '#00a651', '#00bff3'],
 	redraw: true, 
 });  
 /*
 var data = [
     { <?php echo $campaignDatadts; ?>}
    ],
    config = {
      data: data,
      xkey: 'y',
      ykeys: ['a', 'b', 'c'],
      labels: ['Initié', 'Ouvert','Clos'],
      fillOpacity: 0.6,
      hideHover: 'auto',
      behaveLikeLine: true,
      resize: true,
      pointFillColors:['#ffffff'],
      pointStrokeColors: ['black'],
      lineColors:['gray','red']
  };
config.element = 'revenue-chart';
Morris.Area(config);
*/
</script>


<script>
Morris.Bar({
 element : 'revenue-chart',
 data:[<?php echo $chart_data; ?>],
 xkey:'Mois',
 ykeys:['Total'],
 labels:['Total'],
 hideHover:'auto',
 stacked:true
});




	 
	 
</script>