<?php
session_start();
if(isset($_SESSION['username'])){

    ?>
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
        <meta charset="utf-8" />
        <?php include('includes/styles.php'); ?>
        <title>Dashboard | <?php echo $church_name; ?></title>

        <?php
        $sql =  "SELECT DISTINCT(districtID) FROM members";
        $conn->query($sql);
        $chart_data = '';
        $result_set = $conn->fetchMultiple();

        foreach ($result_set as $member_details){
      //fetch class names
      $sql = "SELECT name FROM districts WHERE id =:districtID";
      $conn->query($sql);
      $conn->bind(":districtID", $member_details->districtID);
      $branch_name = $conn->fetchColumn();

        

      //total number of students per class
      $sql = "SELECT COUNT(districtID) FROM members WHERE districtID =:districtID";
      $conn->query($sql);
      $conn->bind(":districtID", $member_details->districtID);
      $total_members = $conn->fetchColumn();
      $chart_data .= "{branch:'".$branch_name."', members:".$total_members.",}, ";
    }

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


   
        
    ?>

<style>
    /* width */
::-webkit-scrollbar {
  width: 5px;
}

/* Track */
::-webkit-scrollbar-track {
  background: #f1f1f1;
}

/* Handle */
::-webkit-scrollbar-thumb {
  background: #afaaaa;
}

/* Handle on hover */
::-webkit-scrollbar-thumb:hover {
  background: #697686;
}

</style>
    </head>
    <body class="fixed-header dashboard">
   
<?php include('includes/sidebar.php'); ?>
    <!-- START PAGE-CONTAINER -->
    <div class="page-container ">
        <?php include('includes/header.php'); ?>
        <!-- START PAGE CONTENT WRAPPER -->
        <div class="page-content-wrapper ">
            <!-- START PAGE CONTENT -->
            <div class="content sm-gutter">
                <!-- START CONTAINER FLUID -->
                <div class="container-fluid padding-25 sm-padding-10">
                    <div class="row">
                        <div class="col-lg-12 sm-p-t-50" style="margin-top: 40px">
                            <div class="alert alert-danger" style="color: white; height: 120px;background: linear-gradient( 60deg, #f1ad83 0%, #4358d0 100% );" role="alert">
                                <img src="<?php echo $base_url; ?>assets/img/admin-avatar.jpg" width="80" height="80" style="border-radius: 50%; border: 3px solid #fff; margin-left: 50px;margin: 0;position: absolute;top: 50%;-ms-transform: translateY(-50%);transform: translateY(-50%);">
                                <?php
                                $sql = "SELECT name FROM admin";
                                $conn->query($sql);
                                $dasboard = $conn->fetchSingle();
                                $username = $dasboard->name;
                                ?>

                                <span style="left: 110px;margin: 0;position: absolute;top: 50%;-ms-transform: translateY(-50%);transform: translateY(-50%);"> <strong>Welcome <?php echo $username; ?>,</strong>
                            <br>It's nice to see you again. Here is your overview</span>
                            </div></div>
                    </div>

                    <!-- START ROW -->
                    <div class="row">
                    <div class="col-lg-3">
                    <a href="<?php echo $base_url; ?>member">
                        <div id="card-linear" class="card card-default bg-primary">
                            <div class="card-header  ">
                                <div class="card-title">Members
                                </div>
                            </div>
                            <div class="card-body" id="total">
                                <h3>
                                <?php
                                $sql = "SELECT COUNT(id) FROM members";
                                $conn->query($sql);
                                $result = $conn->fetchColumn();
                                $num = $result;
                                $total = number_format($num);
                                ?>
                                    <span class="semi-bold"></span>

                                    <?php echo $total; ?><br></h3>

                            </div>
                        </div></a>
                    </div>
                    <div class="col-lg-3">
                    <a href="<?php echo $base_url; ?>clergy">
                        <div id="card-linear" class="card card-default bg-complete">
                            <div class="card-header  ">
                                <div class="card-title">Clergies
                                </div>
                            </div>
                            <div class="card-body" id="total">
                                <h3>
                                <?php
                                $sql = "SELECT COUNT(id) FROM clergy";
                                $conn->query($sql);
                                $all_pastors = $conn->fetchColumn();

                                ?>
                                    <span class="semi-bold"></span>

                                    <?php echo $all_pastors; ?><br></h3>

                            </div>
                        </div></a>
                    </div>
                    <div class="col-lg-3">
                    <a href="<?php echo $base_url; ?>district">
                        <div id="card-linear" class="card card-default bg-success">
                            <div class="card-header  ">
                                <div class="card-title">Districts
                                </div>
                            </div>
                            <div class="card-body" id="total">
                                <h3>
                                <?php
                                $sql = "SELECT COUNT(id) FROM districts";
                                $conn->query($sql);
                                $all_districts = $conn->fetchColumn();

                                ?>
                                    <span class="semi-bold"></span>

                                    <?php echo $all_districts; ?><br></h3>

                            </div>
                        </div></a>
                    </div>
                    <div class="col-lg-3">
                        <div id="card-linear" class="card card-default bg-danger">
                            <div class="card-header  ">
                                <div class="card-title">Total Amount (<?php echo date('Y'); ?> Conference)
                                </div>
                            </div>
                            <div class="card-body" id="total">
                                <h3>
                                <?php
                                $conyear = date('Y');
                                $sql = "SELECT SUM(amount) FROM members WHERE conyear=:conyear";
                                $conn->query($sql);
                                $conn->bind(":conyear", $conyear);
                                $mamount = $conn->fetchColumn();
                                
                                
                                $sql = "SELECT SUM(amount) FROM clergy WHERE conyear=:conyear";
                                $conn->query($sql);
                                $conn->bind(":conyear", $conyear);
                                $camount = $conn->fetchColumn();
                                
                                $all_amount = number_format($mamount + $camount);

                                ?>
                                    <span class="semi-bold"></span>

                                    ₦ <?php echo $all_amount; ?><br></h3>

                            </div>
                        </div>
                    </div>
                </div>
                    <!-- END ROW -->


                    <!-- START ROW -->
                    
                    <!-- END ROW -->

                    

                


                    <div class="row">
          <!-- Left col -->
          <section class="col-lg-12 connectedSortable">
            <div class="card">
              <div class="card-header">
                Showing Total Number of Registered Members in All Districts
              </div>
              <div class="card-body">
                    <div id="chart">

                    </div>
              </div>
            </div>
            <!-- Custom tabs (Charts with tabs)-->

            <!-- /.card -->
          </section>
          <!-- /.Left col -->
          <!-- right col (We are only adding the ID to make the widgets sortable)-->
          
          <!-- right col -->
        </div>

                </div>
                <!-- END CONTAINER FLUID -->
            </div>
            <!-- END PAGE CONTENT -->
            <?php include('includes/foot.php'); ?>
        </div>
        <!-- END PAGE CONTENT WRAPPER -->
    </div>
    <!-- END PAGE CONTAINER -->
<?php include('includes/footer.php'); ?>

     <!--        Podcast Modal Start-->
     <div class="modal fade slide-up disable-scroll" id="podcast" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
        <div class="modal-dialog" role="document">
            <div class="modal-content-wrapper">
                <div class="modal-content text-center">
                    <div class="modal-header clearfix" style="display: block">
                        <button aria-label="" type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="pg-icon">close</i>
                        </button>
                        <h5 style="margin-bottom: -6px"><span class="semi-bold">Listen to Our Podcasts</span></h5>
                    </div>
                    <div class="modal-body clearfix" style="margin: 0 auto">
                        <a href="https://anchor.fm/nkcnigeria"> <div class="pgn push-on-sidebar-open pgn-circle m-t-20"><div class="alert alert-success"><div>
                                        <div class="pgn-thumbnail"><div><img width="40" height="40" style="display: inline-block;" src="<?php echo $base_url; ?>assets/img/anchor.png" data-src="assets/img/anchor.pnp" data-src-retina="assets/img/anchor.pnp" alt=""></div></div>
                                        <div class="pgn-message"><div><p class="bold">Anchor FM Podcast</p><p>Weekly Podcasts on Anchor!</p></div></div></div>
                                </div></div></a>

                        <a href="https://open.spotify.com/show/7d9HX8g8VYlcDaog0SZIa4?si=30447d271af84cd5"> <div class="pgn push-on-sidebar-open pgn-circle m-t-20"><div class="alert alert-success"><div>
                                        <div class="pgn-thumbnail"><div><img width="40" height="40" style="display: inline-block;" src="<?php echo $base_url; ?>assets/img/spotify.gif" data-src="assets/img/anchor.pnp" data-src-retina="assets/img/anchor.pnp" alt=""></div></div>
                                        <div class="pgn-message"><div><p class="bold">Spotify Podcast</p><p>Weekly Podcasts on Spotify!</p></div></div></div>
                                </div></div></a>

                        <a href="https://podcasts.google.com/feed/aHR0cHM6Ly9hbmNob3IuZm0vcy85NTMyYWFjNC9wb2RjYXN0L3Jzcw?sa=X&ved=2ahUKEwjk8pXj-bT6AhUugc4BHSVgC9EQ9sEGegQIARAC"> <div class="pgn push-on-sidebar-open pgn-circle m-t-20"><div class="alert alert-success"><div>
                                        <div class="pgn-thumbnail"><div><img width="40" height="40" style="display: inline-block;" src="<?php echo $base_url; ?>assets/img/google-podcasts.png" data-src="assets/img/anchor.pnp" data-src-retina="assets/img/anchor.pnp" alt=""></div></div>
                                        <div class="pgn-message"><div><p class="bold">Google Podcast</p><p>Weekly Podcasts on Google!</p></div></div></div>
                                </div></div></a>

                    </div>
                </div>
            </div>
        </div>
    </div>
    <!--        Podcast Modal End-->


    <!--        Big Blog Modal Start-->
    <div class="modal fade slide-up disable-scroll" id="bigblog" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
        <div class="modal-dialog modal-lg">
            <div class="modal-content-wrapper">
                <div class="modal-content">
                    <div class="modal-header" style="display: block">
                        <button aria-label="" type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="pg-icon">close</i>
                        </button>
                        <h5 style="margin-bottom: -6px"><span class="semi-bold"><?php echo $big1; ?></span></h5>
                    </div>
                    <div class="modal-body clearfix m-t-10" style="text-align:justify;white-space: pre-line;height: 350px;overflow-y: overlay;">
                    <?php echo $note1; ?>

                    </div>
                </div>
            </div>
        </div>
    </div>
    <!--        Big Blog Modal End-->


    <!--        Small Blog Modal Start-->
    <div class="modal fade slide-up disable-scroll" id="smallblog" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
        <div class="modal-dialog modal-lg">
            <div class="modal-content-wrapper">
                <div class="modal-content">
                    <div class="modal-header" style="display: block">
                        <button aria-label="" type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="pg-icon">close</i>
                        </button>
                        <h5 style="margin-bottom: -6px"><span class="semi-bold"><?php echo $big2; ?></span></h5>
                    </div>
                    <div class="modal-body clearfix m-t-10" style="text-align:justify;white-space: pre-line;height: 350px;overflow-y: overlay;">
                    <?php echo $note2; ?>

                    </div>
                </div>
            </div>
        </div>
    </div>
    <!--        Small Blog Modal End-->

    <!--<div id="notify" class="pgn-wrapper" data-position="top" style="top: 59px;"><div class="pgn push-on-sidebar-open pgn-bar"><div class="alert alert-success"><button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>Welcome back <b>John4peace!</b></div></div></div>-->


    <script>
        setTimeout(function() {
            $('#notify').fadeOut('fast');
        }, 3000); // <-- time in milliseconds
    </script>

<script>
  var barColorsArray = ['#3498DB', '#34495E', '#26B99A', '#DE8244', '#DE4244', '#12B0E8', '#02B290', '#E07C24', '#3FBDD0', '#8D3DAF'];
  var colorIndex = 0;
  Morris.Bar ({
    element: 'chart',
    data: [<?php echo $chart_data; ?>],
    xkey: 'branch',
    ykeys: ['members'],
    labels: ['Members'],
    barColors: function(){
      if (colorIndex < 8)
        return barColorsArray[++colorIndex];
        else {
          colorIndex = 0;
          return barColorsArray[++colorIndex];
        
      }
    },
    xLabelAngle: 35,
    hideHover: 'auto',
    resize: true,


  });

  $('[data-toggle = "tooltip"]').tooltip();

 </script>
 <script>
    $.widget.bridge('uibutton', $.ui.button)
</script>



   

    <script>
        setTimeout(function() {
            $('#notify').fadeOut('fast');
        }, 3000); // <-- time in milliseconds
    </script>
  
<?php
}else{
    ?>
    
  <?php include('session.php'); ?>

    <?php

}

?>