<?php 

//$_SESSION['county']; 

//$county=$_SESSION['county']; 

 ?>

<?php



include 'config.php';



$sql = mysqli_query($conDB,"SELECT * FROM doctor_absentism where county='Baringo'");



if (!$sql) {

    echo 'Could not run query: ' . mysqli_error();

    exit;

	}

$row = mysqli_fetch_assoc($sql);



$county=$row['county'];

 

$maternity_or_sick_leave=$row['maternity_or_sick_leave'];

$in_training=$row['in_training'];

$official_mission=$row['official_mission']; 

$approved_absence=$row['approved_absence'];

$gone_to_retrieve_salary=$row['gone_to_retrieve_salary'];

$not_approved_absence=$row['not_approved_absence'];

$not_on_shift=$row['not_on_shift'];

$all_others=$row['all_others'];     



//give variables to the labels

$countylabel='county';

$maternity_or_sick_leave_label='maternity_or_sick_leave';

$in_training_label='in_training';

$official_mission_label='official_mission';

$approved_absence_label='approved_absence';

$gone_to_retrieve_salary_label='gone_to_retrieve_salary';

$not_approved_absence_label='not_approved_absence';

$not_on_shift_label='not_on_shift';

$all_others_label='all_others';





$countylabel='"'.$countylabel.'"';

$maternity_or_sick_leave_label='"'.$maternity_or_sick_leave_label.'"';

$in_training_label='"'.$in_training_label.'"';

$official_mission_label='"'.$official_mission_label.'"';

$approved_absence_label='"'.$approved_absence_label.'"';

$gone_to_retrieve_salary_label='"'.$gone_to_retrieve_salary_label.'"';

$not_approved_absence_label='"'.$not_approved_absence_label.'"';

$not_on_shift_label='"'.$not_on_shift.'"';

$all_others_label='"'.$all_others.'"';



$county='"'.$county.'"';



$label='"label"';

$type='"type"';

$string='"string"';

$number='"number"';

$cols='"cols"';

$rows='"rows"';

$c='"c"';

$v='"v"';

$maternity_or_sick_leave_col='"Maternity or sick leave"';

$in_training_col='"In training"';

$official_mission_col='"Official mission"';

$approved_absence_col='"Approved absence"';

$gone_to_retrieve_salary_col='"Gone to retrieve salary"';

$not_approved_absence_col='"Not approved absence"';

$not_on_shift_col='"Not on shift"';

$all_others_col='"All others"';



//generate json columns

 $group1="{".$label.":".$countylabel.",".$type.":".$string."}".",";

 $group2="{".$label.":".$maternity_or_sick_leave_label.",".$type.":".$number."}".",";

 $group3="{".$label.":".$in_training_label.",".$type.":".$number."}".",";

 $group4="{".$label.":".$official_mission_label.",".$type.":".$number."}".",";

 $group5="{".$label.":".$approved_absence_label.",".$type.":".$number."}".",";

 $group6="{".$label.":".$gone_to_retrieve_salary_label.",".$type.":".$number."}".",";

 $group7="{".$label.":".$not_approved_absence_label.",".$type.":".$number."}".",";

 $group8="{".$label.":".$not_on_shift_label.",".$type.":".$number."}".",";

 $group9="{".$label.":".$all_others_label.",".$type.":".$number."}";



 

 //generate rows 

 $row1="{".$c.":"."["."{".$v.":".$maternity_or_sick_leave_col."}".","."{".$v.":".$maternity_or_sick_leave."}"."]"."}".",";

 $row2="{".$c.":"."["."{".$v.":".$in_training_col."}".","."{".$v.":".$in_training."}"."]"."}".",";

 $row3="{".$c.":"."["."{".$v.":".$official_mission_col."}".","."{".$v.":".$official_mission."}"."]"."}".",";

 $row4="{".$c.":"."["."{".$v.":".$approved_absence_col."}".","."{".$v.":".$approved_absence."}"."]"."}".",";

 $row5="{".$c.":"."["."{".$v.":".$gone_to_retrieve_salary_col."}".","."{".$v.":".$gone_to_retrieve_salary."}"."]"."}".",";

 $row6="{".$c.":"."["."{".$v.":".$not_approved_absence_col."}".","."{".$v.":".$not_approved_absence."}"."]"."}".",";

 $row7="{".$c.":"."["."{".$v.":".$not_on_shift_col."}".","."{".$v.":".$not_on_shift."}"."]"."}".",";

 $row8="{".$c.":"."["."{".$v.":".$all_others_col."}".","."{".$v.":".$all_others."}"."]"."}";

 

 $myjsonrows='"rows"'.":"."[".$row1.$row2.$row3.$row4.$row5.$row6.$row7.$row8."]";

 $myjsoncols=$cols.":"."[".$group1.$group2.$group3.$group4.$group5.$group6.$group7.$group8.$group9."]".",";

 $jsonTable="{".$myjsoncols.$myjsonrows."}";





// convert data into JSON format

$jsonTable = json_encode($jsonTable);

//echo $jsonTable;

?>





<html>

  <head>

    <!--Load the Ajax API-->

    <script type="text/javascript" src="https://www.google.com/jsapi"></script>

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>

    <script type="text/javascript">



    // Load the Visualization API and the piechart package.

    google.load('visualization', '1', {'packages':['corechart']});



    // Set a callback to run when the Google Visualization API is loaded.

    google.setOnLoadCallback(drawChart);



    function drawChart() {



      // Create our data table out of JSON data loaded from server.

      var data = new google.visualization.DataTable(<?=$jsonTable?>);

      var options = {

           title: 'Reasons for absentism',

          is3D: 'false',

          width: 600,

          height: 300

        };

      // Instantiate and draw our chart, passing in some options.

      // Do not forget to check your div ID

	  var formatter = new google.visualization.NumberFormat({pattern:'###,###'} );

  formatter.format(data,1);

  

  var formatter = new google.visualization.NumberFormat({pattern:'###,###'} );

  formatter.format(data,2);

  

 var chart = new google.visualization.PieChart(document.getElementById('chart_div'));

      chart.draw(data, {chartArea:{left:20,top:60,width:"100%",height:"100%"},title:"Reasons for absenteeism",hAxis: {titleTextStyle: {color: '#000'}},width: 260, height: 300,fontName:'Roboto'});

    }

    </script>

  </head>



  <body>

    <!--this is the div that will hold the pie chart-->

    <div id="chart_div"></div>

  </body>

</html>