<?php
    class HOME_KPIPRFDLY extends HOME
    {
        public function home_kpiprfdly_javainit()
        {

        }

        public function fn_kpiprfdly_init()
        {
            if(isset($_REQUEST['task'])){$task=trim(strtolower($_REQUEST['task']));}
            if(isset($_POST['task'])){$task=trim(strtolower($_POST['task']));}
            if($_REQUEST||$_POST){if($_REQUEST['sec']||$_POST['sec']){$task=$this->dec($task);}}

            switch($task)
            {
                case "default":
                    $this->fn_default_sum();
                break;

                case $task:
                    $task="fn_".$task;
                    if(method_exists($this,$task)){$this->$task();}
                break;

                default:
                    $this->fn_default_sum();
                break;
            }
        }
        
        public function fn_default_sum()
        {
            echo $this->FN_CREATEHEADER();

            echo "<style>
                       .besidebtnsave {margin-left:80px;margin-top:-6px;position:absolute;}
                  </style>";
            echo "<script>
                       var myForm,myFormsearch,dgtra;
                       function initObject()
                       {";
                            $dtnow=date("Y-m-d",strtotime("-1 days"));
                            $qry="select datasets,legend,series,startvalue,stepvalue,endvalue from ".DB_APORTIL.".tbl_chart_trendran
                                  where modules='netperf' and cast(chartname as date)=cast('$dtnow' as date) 
                                  and isdeleted=0 order by id desc limit 1";
                            //echo $qry;
                            $spval=$this->fn_get_fieldsvalues("datasets,legend,series,startvalue,stepvalue,endvalue",$qry);
                            $datasets=$spval[0];$legend=$spval[1];$series=$spval[2];$startvalue=$spval[3];$stepvalue=$spval[4];$endvalue=$spval[5];
            //echo "          var datasets=[{\"4GBETO\": \"6.91\", \"LENUH\": \"6.54\", \"times\": \"0\"},
//                                          {\"4GBETO\": \"5.46\", \"LENUH\": \"2.73\", \"times\": \"1\"},
//                                          {\"4GBETO\": \"1.46\", \"LENUH\": \"5.73\", \"times\": \"2\"}
//                                          ];
                            $j=json_decode($series,true);
                            $firstseries=$j[0];
                            //echo $firstseries["value"];
//            echo "          var datasets=$datasets;var legend=$legend;var series=$series;
            //echo "          var datasets=[{\"MANLEUANA_4G\":\"16.84\",\"nartuto\":\"1.79\",\"vilanova\":\"2.97\",\"times\":\"0\"},{\"MANLEUANA_4G\":\"12.15\",\"nartuto\":\"2.4\",\"vilanova\":\"1.95\",\"times\":\"1\"},{\"MANLEUANA_4G\":\"7.37\",\"nartuto\":\"1.41\",\"vilanova\":\"1.59\",\"times\":\"2\"}];
            echo "          var datasets=$datasets;
                            myLineChart =  new dhtmlXChart({
                                                view:\"spline\",
                                                container:\"div_kpiprfdlyline\",
                                                value:\"".$firstseries['value']."\",
                                                item:".json_encode($firstseries['item']).",
                                                line:".json_encode($firstseries['line']).",
                                                tooltip:".json_encode($firstseries['tooltip']).",                                                
                                                offset:0,
                                                xAxis:{
                                                    title:\"\",
                                                    template:\"#times#\"
                                                },
                                                yAxis:{
                                                    title:\"Gigabytes\",
                                                    start:$startvalue,
                                                    step:$stepvalue,
                                                    end:$endvalue,
                                                    template:function(value){
                                                        return value%$stepvalue?'':value
                                                    }
                                                },
                                                padding:{
                                                    left:35,
                                                    bottom: 130
                                                },
                                                origin:0,
                                                legend:{
                                                    values: $legend,
                                                    align:\"center\",
                                                    valign:\"bottom\",
                                                    layout:\"x\",
                                                    width: 200,
                                                    margin: 10                                                    
                                                }
                                            });";
                                            $x=0;
                                            foreach($j as $v)
                                            {
                                                if($x>0)
                                                {
                                                    echo "myLineChart.addSeries(".json_encode($v).");";    
                                                }
                                                $x+=1;
                                                
                                            }
            echo "                          myLineChart.parse(datasets,\"json\");";
            echo "     };
                  </script>";
            echo $this->FN_CLOSEHEADER();
            echo $this->FN_CREATEBODY("white");
            echo "<table width=\"98%\" height=\"100%\" border=\"0\">";
            echo "  <tr>
                        <td valign=\"top\" width=\"100%\">
                            <div style=\"width:100%;text-align:center;text-decoration:underline;font-size:24px;color:blue\">Payload Performance Period ".date("d M Y",strtotime('-1 days'))."</div>
                            <div style=\"width:100%;text-align:center;font-style:italic;font-size:18px;color:grey\">Today : ".date("d M Y")."</div>
                            <div id=\"div_kpiprfdlyline\" style=\"width:100%;height:430px;\"></div>
                        </td>                        
                    </tr>";
            echo "</table>";
            echo $this->FN_CREATEFOOTER();

        }
    }
?>