<html>
    <head><link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:300,400"> 
<style>
  
  body, #ddlViewBy{
    font-family: 'Open Sans';font-size: 15px;
    } 
select
{
    width:300px;
}
</style></head><body>
<?php
function select_pacients_for_year($year)
{
     $conn = mysqli_connect("localhost","tagstudi_aldina","aldina1234567","tagstudi_ehealth");
   if (!mysqli_connect_errno())
   {
       
  $sql = "SELECT count(*) as broj FROM `morbili_new2` where `datum_pruzene_usluga` like '".$year."%'";
  $result= $conn->query($sql);  
  if ($result->num_rows > 0) {
   
    while($row = $result->fetch_assoc()) {
      $rezultat=$row["broj"];
     
    }
    return $rezultat;
  }
   else
      {
          echo "Zero rows!";
      }}
  else
  {
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
      
  }
   
}
function select_pacients_by_location($lok)
{
     $conn = mysqli_connect("localhost","tagstudi_aldina","aldina1234567","tagstudi_ehealth");
   if (!mysqli_connect_errno())
   {
       
  $sql = "SELECT count(*) as broj FROM `morbili_new2` where `lokacija_pruzanja_usluga` like '".$lok."%' and  `datum_pruzene_usluga` like '2018%'";
  $result= $conn->query($sql);  
  if ($result->num_rows > 0) {
   
    while($row = $result->fetch_assoc()) {
      $rezultat=$row["broj"];
     
    }
    return $rezultat;
  }
   else
      {
          echo "Zero rows!";
      }}
  else
  {
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
      
  }
   
}

function select_pacients_by_symptom($sym)
{
     $conn = mysqli_connect("localhost","tagstudi_aldina","aldina1234567","tagstudi_ehealth");
   if (!mysqli_connect_errno())
   {
       
  $sql = "SELECT count(*) as broj FROM `norm_anamneza` where `ngram` like '".$sym."%'";
  $result= $conn->query($sql);  
  if ($result->num_rows > 0) {
   
    while($row = $result->fetch_assoc()) {
      $rezultat=$row["broj"];
     
    }
    return $rezultat;
  }
   else
      {
          echo "Zero rows!";
      }}
  else
  {
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
      
  }
   
}

function select_pacients_by_age_f($ages)
{
     $conn = mysqli_connect("localhost","tagstudi_aldina","aldina1234567","tagstudi_ehealth");
   if (!mysqli_connect_errno())
   {
       if($ages==1)
       {
  $sql = "SELECT count(*) as broj from morbili_new2 where `datum_rodjena` like '192%' or `datum_rodjena` like '193%' or `datum_rodjena` like '194%' or `datum_rodjena` like '195%' or `datum_rodjena` like '196%' and `naziv_usluga` not LIKE 'ponovni%'";
       }
       else if($ages==2)
       {
        $sql="SELECT count(*) as broj from morbili_new2 where `datum_rodjena` like '197%' or `datum_rodjena` like '198%' and `naziv_usluga` not LIKE 'ponovni%'";   
       }
       else if($ages==3)
       {
            $sql="SELECT count(*) as broj from morbili_new2 where `datum_rodjena` like '199%' and `naziv_usluga` not LIKE 'ponovni%'";
       }
        else if($ages==4)
       {
        $sql="SELECT count(*) as broj from morbili_new2 where `datum_rodjena` like '200%' and `naziv_usluga` not LIKE 'ponovni%'";   
       }
       else if($ages==5)
       {
            $sql="SELECT count(*) as broj from morbili_new2 where `datum_rodjena` like '201%' and `naziv_usluga` not LIKE 'ponovni%'";
       }
       
  $result= $conn->query($sql);  
  if ($result->num_rows > 0) {
   
    while($row = $result->fetch_assoc()) {
      $rezultat=$row["broj"];
     
    }
    return $rezultat;
  }
   else
      {
          echo "Zero rows!";
      }}
  else
  {
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
      
  }
   
}

function select_pacients_by_age_c($ages)
{
     $conn = mysqli_connect("localhost","tagstudi_aldina","aldina1234567","tagstudi_ehealth");
   if (!mysqli_connect_errno())
   {
       if($ages==1)
       {
  $sql = "SELECT count(*) as broj from morbili_new2 where `datum_rodjena` like '192%' or `datum_rodjena` like '193%' or `datum_rodjena` like '194%' or `datum_rodjena` like '195%' or `datum_rodjena` like '196%' and `naziv_usluga` LIKE 'ponovni%'";
       }
       else if($ages==2)
       {
        $sql="SELECT count(*) as broj from morbili_new2 where `datum_rodjena` like '197%' or `datum_rodjena` like '198%' and `naziv_usluga`  LIKE 'ponovni%'";   
       }
       else if($ages==3)
       {
            $sql="SELECT count(*) as broj from morbili_new2 where `datum_rodjena` like '199%' and `naziv_usluga` LIKE 'ponovni%'";
       }
        else if($ages==4)
       {
        $sql="SELECT count(*) as broj from morbili_new2 where `datum_rodjena` like '200%' and `naziv_usluga`  LIKE 'ponovni%'";   
       }
       else if($ages==5)
       {
            $sql="SELECT count(*) as broj from morbili_new2 where `datum_rodjena` like '201%' and `naziv_usluga` LIKE 'ponovni%'";
       }
       
  $result= $conn->query($sql);  
  if ($result->num_rows > 0) {
   
    while($row = $result->fetch_assoc()) {
      $rezultat=$row["broj"];
     
    }
    return $rezultat;
  }
   else
      {
          echo "Zero rows!";
      }}
  else
  {
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
      
  }
   
}
?>

     <select id="ddlViewBy" onchange="run();" style="height:30px">
    <option value="1">Pregled obolelih po mesecima</option>
    <option value="2">Pregled obolelih po zdravstvenim stanicama</option>
    <option value="3">Pregled obolelih prema godinama starosti</option>
    <option value="4">Najzastupljeniji simptomi</option>
  </select>
                                   <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
    <script type="text/javascript">

      
     
      var e = document.getElementById("ddlViewBy");
var strUser = e.options[e.selectedIndex].value;
function run()
      {
          strUser = e.options[e.selectedIndex].value;
          google.charts.load("current", {packages:["corechart"]});
      google.charts.setOnLoadCallback(drawChart);
      }
    google.charts.load("current", {packages:["corechart"]});
    google.charts.load('current', {'packages':['bar']});
      google.charts.setOnLoadCallback(drawChart);
      function drawChart() {
          if(strUser==1)
          {document.getElementById('columnchart_material').style.display="none";
          document.getElementById('donutchart').style.display="block";
        var data = google.visualization.arrayToDataTable([
          ['Task', 'Pregled broja pacijenata obolelih od morbila po mesecima za 2018. godinu'],
          ['Januar',     <?php echo select_pacients_for_year('2018-01');?>],
          ['Februar',      <?php echo select_pacients_for_year('2018-02');?>],
          ['Mart',      <?php echo select_pacients_for_year('2018-03');?>],
          ['April',      <?php echo select_pacients_for_year('2018-04');?>],
          ['Maj',      <?php echo select_pacients_for_year('2018-05');?>],
          ['Jun',      <?php echo select_pacients_for_year('2018-06');?>],
          ['Jul',      <?php echo select_pacients_for_year('2018-07');?>],
          ['Avgust',      <?php echo select_pacients_for_year('2018-08');?>],
          ['Septembar',      <?php echo select_pacients_for_year('2018-09');?>],
          ['Oktobar',      <?php echo select_pacients_for_year('2018-10');?>],
          ['Novembar',      <?php echo select_pacients_for_year('2018-11');?>],
          ['Decembar',      <?php echo select_pacients_for_year('2018-12');?>]
        ]);
     var options = {
          title: 'Pregled broja pacijenata obolelih od morbila po godinama po mesecima za 2018. godinu',
          pieHole: 0.0591,
        };

        var chart = new google.visualization.PieChart(document.getElementById('donutchart'));
        chart.draw(data, options);
}
else if(strUser==2)
{
     document.getElementById('columnchart_material').style.display="none";
     document.getElementById('donutchart').style.display="block";
        var data = google.visualization.arrayToDataTable([
          ['Task', 'Pregled broja pacijenata obolelih od morbila po zdravstvenim stanicama'],
          ['Centralna zgrada',     <?php echo select_pacients_by_location('Centralna zgrada');?>],
          ['Ledena Stena',      <?php echo select_pacients_by_location('Ledena stena');?>],
          ['Delijski vis',      <?php echo select_pacients_by_location('Delijski vis');?>],
          ['Duvanište',      <?php echo select_pacients_by_location('Duvanisxte');?>],
          ['Ratko Pavlović',     <?php echo select_pacients_by_location('Ratko Pavlovicy');?>],
          ['Branko Bjegović',      <?php echo select_pacients_by_location('Branko Bjegovicy');?>],
          ['Donja Vrežina',      <?php echo select_pacients_by_location('Donja Vrezxina');?>],
          ['Lira',      <?php echo select_pacients_by_location('Lira');?>],
          ['Novo selo',     <?php echo select_pacients_by_location('Novo selo');?>],
          ['Nikola Tesla',      <?php echo select_pacients_by_location('Nikola Tesla');?>],
          ['Niška Banja',      <?php echo select_pacients_by_location('Nisxka Banja');?>],
          ['12. februar',      <?php echo select_pacients_by_location('12. februar');?>]
          
        ]);
    var options = {
          title: 'Pregled broja pacijenata obolelih od morbila po zdravstvenim ustanovama',
          pieHole: 0.1,
        };

        var chart = new google.visualization.PieChart(document.getElementById('donutchart'));
        chart.draw(data, options);
 }
          else if(strUser==3)
          { 
              document.getElementById('donutchart').style.display="none";
              document.getElementById('columnchart_material').style.display="block";
             
               var data = google.visualization.arrayToDataTable([
          ['Godine starosti', 'Prvi pregled', 'Kontrola'],
          ['0-10', <?php echo select_pacients_by_age_f(5);?>, <?php echo select_pacients_by_age_c(5);?>],
          ['10-20',  <?php echo select_pacients_by_age_f(4);?>, <?php echo select_pacients_by_age_c(4);?>],
          ['20-30', <?php echo select_pacients_by_age_f(3);?>, <?php echo select_pacients_by_age_c(3);?>],
          ['30-50',  <?php echo select_pacients_by_age_f(2);?>, <?php echo select_pacients_by_age_c(2);?>],
          ['50+',  <?php echo select_pacients_by_age_f(1);?>, <?php echo select_pacients_by_age_c(1);?>]
        ]);

        var options = {
          chart: {
            title: ' ',
            subtitle: '',
          }
        };

        var chart = new google.charts.Bar(document.getElementById('columnchart_material'));

        chart.draw(data, google.charts.Bar.convertOptions(options));
          }
          else if(strUser==4)
          { 
              document.getElementById('donutchart').style.display="none";
              document.getElementById('columnchart_material').style.display="block";
             
               var data = google.visualization.arrayToDataTable([
          ['Simptomi', 'Broj pacijenata'],
          ['Temperatura', <?php echo select_pacients_by_symptom('temp');?>],
          ['Hiperemija ždrela',  <?php echo select_pacients_by_symptom('hipe');?>],
          ['Osip', <?php echo select_pacients_by_symptom('os');?>],
          ['Kašalj',  <?php echo select_pacients_by_symptom('kasx');?>]
         
        ]);

        var options = {
          chart: {
            title: ' ',
            subtitle: '',
          }
        };

        var chart = new google.charts.Bar(document.getElementById('columnchart_material'));

        chart.draw(data, google.charts.Bar.convertOptions(options));
          }
      }

    </script><br/>
                                    <div id="donutchart" style="width: 100%; height: 600px;"></div>
                                    <div id="columnchart_material" style="display:none; width: 100%; height: 500px;"></div>
       </body></html>