<?php require_once(APPPATH.'/views/header.php'); ?>
<body>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
    <script type="text/javascript">

        var cc = {
                    data_start:'<?=(isset($start) && $start)?$start:'';?>',
                    data_stop:'<?=(isset($stop) && $stop)?$stop:'';?>'
                    };  

        var jsonDataStatus = $.ajax({
                  url: "<?=  base_url();?>admin/statusInfo",
                  dataType:"json",
                  type:"POST",
                  data: cc,
                  async: false
                  }).responseText;

        var jsonDataStare = $.ajax({
                  url: "<?=  base_url();?>admin/stareInfo",
                  dataType:"json",
                  type:"POST",
                  data: cc,
                  async: false
                  }).responseText;

        var jsonDataInreg = $.ajax({
                  url: "<?=  base_url();?>admin/inregInfo",
                  dataType:"json",
                  type:"POST",
                  data: cc,
                  async: false
                  }).responseText;

    google.charts.load('current', {'packages':['corechart']});  
    google.charts.setOnLoadCallback(drawChart);
 
    function drawChart() 
    {
        //console.log(jsonDataStatus);
        var data1 = new google.visualization.DataTable(jsonDataStatus);

        var options1 = {
          title: 'Documente grupate pe STATUS',
          is3D: true,
        };

        var chart1 = new google.visualization.PieChart(document.getElementById('pie_chart_status'));

        chart1.draw(data1, options1);
    
        //console.log(jsonDataStare);
        var data2 = new google.visualization.DataTable(jsonDataStare);

        var options2 = {
        title: 'Documente grupate pe STARE',
        is3D: true,
        };

        var chart2 = new google.visualization.PieChart(document.getElementById('pie_chart_stare'));

        chart2.draw(data2, options2);
    
        //console.log(jsonDataInreg);
        var data3 = new google.visualization.DataTable(jsonDataInreg);

        var options3 = {
            title: "Inregistrari in arhiva",
            legend: { position: "none" },
            vAxis: {format:'#,###'},
            hAxis: {
                slantedTextAngle:45 // here you can even use 180
            }
        };

        var chart3 = new google.visualization.ColumnChart(document.getElementById("bar_chart"));
        chart3.draw(data3, options3);
    }
    </script>
    <div id="wrapper">
        <?php require_once 'menu_user.php'; ?>
        <div id="page-wrapper">
            <div class="container">
            <div class="clearfix"></div><br/>
                <div class="row">
                    <div class="col-lg-3">
                        <a id="azi">Azi</a> /
                        <a id="7zile">Ultimele 7 zile</a> /
                        <a id="30zile">30 zile</a> /
                        <a id="60zile">60 zile</a> /
                        <a id="an">An</a>
                    </div>
                    <div class="col-lg-3">
                        <div class="input-group">
                            <div class="input-group-addon">
                                <span class="input-group-text" id="basic-data-in">Din data</span>
                            </div>
                            <input style="margin-bottom:0px;" type="text" class="form-control" id="start" name="start" placeholder="Data inceput" value="<?=(isset($start) && $start)?$start:'';?>" aria-describedby="basic-data-in"/>
                        </div>
                    </div>
                    <div class="col-lg-3">
                        <div class="input-group">
                            <div class="input-group-addon">
                                <span class="input-group-text" id="basic-data-in">Pana in</span>
                            </div>
                            <input style="margin-bottom:0px;" type="text" class="form-control" id="stop" name="stop" placeholder="Data sfarsit" value="<?=(isset($stop) && $stop)?$stop:'';?>" aria-describedby="basic-data-in"/>
                        </div>
                    </div>
                </div>
                <div class="clearfix"></div><br/>
                <div class="row">
                <div class="col-lg-6">
                <fieldset class="admin-border">
                    <fieldset class="scheduler-border">
                        <div id="pie_chart_status" ></div>
                    </fieldset>
                </fieldset>
                </div>
                <div class="col-lg-6">
                <fieldset class="admin-border">
                    <fieldset class="scheduler-border">
                    <div id="pie_chart_stare" ></div>
                    </fieldset>
                </fieldset>
                </div>
                <div class="col-lg-12">
                <fieldset class="admin-border">
                    <fieldset class="scheduler-border">
                    <div class="text-center" id="bar_chart" ></div>
                    </fieldset>
                </fieldset>
                </div>
                </div>
            </div>
        </div>
        <!-- /#page-wrapper -->
    </div>
    <!-- /#wrapper -->
</body>
</html>
<script>
            
        $(document).ready(function(){
            $("#start").datepicker({
                  changeMonth: true,
                  changeYear: true,
                  dateFormat: "yy-mm-dd"
            });
            $("#stop").datepicker({
                  changeMonth: true,
                  changeYear: true,
                  dateFormat: "yy-mm-dd"
            });

            $("#start").change(function() {
                var start = $("#start").val();
                var stop  = $("#stop").val();
                window.location.href='<?=base_url()?>'+'admin?start='+start+'&stop='+stop;
            });
            
            $("#stop").change(function() {
                var start = $("#start").val();
                var stop  = $("#stop").val();
                window.location.href='<?=base_url()?>'+'admin?start='+start+'&stop='+stop;
            });

            $("#azi").click(function() {
                var start = '<?=date('Y-m-d');?>';
                var stop  = '<?=date('Y-m-d');?>';
                window.location.href='<?=base_url()?>'+'admin?start='+start+'&stop='+stop;
            });

            $("#7zile").click(function() {
                var start = '<?=date('Y-m-d', strtotime('- 7 days'));?>';
                var stop  = '<?=date('Y-m-d');?>';
                window.location.href='<?=base_url()?>'+'admin?start='+start+'&stop='+stop;
            });

            $("#30zile").click(function() {
                var start = '<?=date('Y-m-d', strtotime('- 30 days'));?>';
                var stop  = '<?=date('Y-m-d');?>';
                window.location.href='<?=base_url()?>'+'admin?start='+start+'&stop='+stop;
            });
            $("#60zile").click(function() {
                var start = '<?=date('Y-m-d', strtotime('- 60 days'));?>';
                var stop  = '<?=date('Y-m-d');?>';
                window.location.href='<?=base_url()?>'+'admin?start='+start+'&stop='+stop;
            });
            $("#an").click(function() {
                var start = '<?=date('Y-m-d', strtotime('- 365 days'));?>';
                var stop  = '<?=date('Y-m-d');?>';
                window.location.href='<?=base_url()?>'+'admin?start='+start+'&stop='+stop;
            });
        });
        
</script>