<?php
    class HOME_TICKET extends HOME
    {
        public function home_ticket_javainit()
        {

        }

        public function fn_ticket_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();
            // === Init Route information dashboard
            $idship=1;
            $idroutestart=1;
            $routestartname="Dili";
            $idrouteend=3;
            $routeendname="Atauro";
            $shipname="Nakroma";
            $route="Dili-Atauro";
            $qry="select idship,shipname,idroutestart,routestartname,idrouteend,routeendname from ".DB_APORTIL.".tbl_dashboard_setting_rute ";
            $qry.="where idemployee='".$_SESSION['idemployee']."' and isdeleted=0 order by id asc limit 1";
            if($this->fn_row_isexists($qry)){
                $sp=$this->fn_get_fieldsvalues("idship,idroutestart,idrouteend,routestartname,routeendname,shipname",$qry);
                $idship=$sp[0];$idroutestart=$sp[1];$idrouteend=$sp[2];$routestartname=$sp[3];$routeendname=$sp[4];
                $route=$routestartname."-".$routeendname;
                $shipname=$sp[5];
            }
            
            echo "<style>
                       .besidebtnsave {margin-left:80px;margin-top:-6px;position:absolute;}
                  </style>";
            echo "<script>
                       var myForm,myFormsearch,dgtra,dwins;
                       var t1;
                       function initObject()
                       {
                            t1=setTimeout(function(){
                                fn_getStatusInfo();
                            },5000);";
                            // === Get Info Trend Chart Bar
                            $qry="select modules,typechart,datasets,startvalue,stepvalue,endvalue from ".DB_APORTIL.".tbl_chart_trendsum  where modules='hometicketbarchart'";
                            $sp=$this->fn_get_fieldsvalues("modules,typechart,datasets,startvalue,stepvalue,endvalue",$qry);
                            $datasets=$sp[2];$startvalue=$sp[3];$stepvalue=$sp[4];$endvalue=$sp[5];
                            echo "var multiple_dataset = $datasets;";
                            //echo "var multiple_dataset = [
//                                        { sales:\"20\", sales2:\"35\",  year:\"02\" },
//                                        { sales:\"40\", sales2:\"24\",  year:\"03\" },
//                                        { sales:\"44\", sales2:\"20\",  year:\"04\" },
//                                        { sales:\"23\", sales2:\"50\",  year:\"05\" },
//                                        { sales:\"21\", sales2:\"36\",  year:\"06\" },
//                                        { sales:\"50\", sales2:\"40\",  year:\"07\" },
//                                        { sales:\"30\", sales2:\"65\",  year:\"08\" },
//                                        { sales:\"90\", sales2:\"62\",  year:\"09\" },
//                                        { sales:\"55\", sales2:\"40\",  year:\"10\" },
//                                        { sales:\"72\", sales2:\"45\",  year:\"11\" }
//                                    ];";
                            echo "var myBarChart =  new dhtmlXChart({
                                                    view:\"bar\",
                                                    container:\"div_ticketbaralarm\",
                                                    value:\"#atauro#\",
                                                    color: \"#58dccd\",
                                                    gradient:\"rising\",
                                                    tooltip:{
                                                        template:\"#atauro#\"
                                                    },
                                                    width:60,
                                                    xAxis:{
                                                        template:\"'#months#\"
                                                    },
                                                    yAxis:{
                                                        start:0,
                                                        step:10,
                                                        end:100
                                                    },
                                                    legend:{
                                                        values:[{text:\"Atauro\",color:\"#58dccd\"},{text:\"Oecusse\",color:\"#a7ee70\"}],
                                                        valign:\"middle\",
                                                        align:\"bottom\",
                                                        width:190,
                                                        layout:\"x\"
                                                    }
                                                });
                                                myBarChart.addSeries({
                                                    value:\"#oecusse#\",
                                                    color:\"#a7ee70\",
                                                    tooltip:{
                                                        template:\"#oecusse#\"
                                                    }
                                                });
                                                myBarChart.parse(multiple_dataset,\"json\");";
                            
                            
                            
                            // === Get Info Trend Chart Bar
                            $qry="select modules,typechart,datasets,startvalue,stepvalue,endvalue from ".DB_APORTIL.".tbl_chart_trendsum where modules='hometicketpie1'";
                            $sp=$this->fn_get_fieldsvalues("modules,typechart,datasets,startvalue,stepvalue,endvalue",$qry);
                            $datasets=$sp[2];$startvalue=$sp[3];$stepvalue=$sp[4];$endvalue=$sp[5];
                            
           echo "           var destination = $datasets;
                            myPieChart = new dhtmlXChart({
                                            view:\"pie\",
                                            container:\"div_pieshippasstrend\",
                                            value:\"#percent#\",
                                            color:\"#color#\",
                                            labelLines: true,
                                            label:\"#dest#: #percent# %\",
                                            shadow:0
                                        });
                            myPieChart.parse(destination,\"json\");
                            ";

            echo "     }
     
                       function fn_getStatusInfo(){
                                
                            var idship=document.getElementById('txt_idship').value;
                            var idroutestart=document.getElementById('txt_idroutestart').value;
                            var idrouteend=document.getElementById('txt_idrouteend').value;
                            //alert(idship+' '+idroutestart+' '+idrouteend);
                            var data=ajaxuridhtmlx('".$this->enc("obj_home")."','obj=".$this->enc("home_ticket")."&task=".$this->enc("getstinfo")."&idship='+idship+'&idroutestart='+idroutestart+'&idrouteend='+idrouteend);
                            data=JSON.parse(data);
                            //alert(data);
                            
                            //alert(data);
                            for(var i in data){
                                var div=document.getElementById('div'+data[i]['ndx']);
                                div.style.color=data[i]['colorfont'];
                                div.style.backgroundColor=data[i]['colors'];
                            }
                            t1=setTimeout(function(){
                                fn_getStatusInfo();
                            },10000);
                       }
                       
                       function fn_showsettings()
                       {
                          var idship=document.getElementById('txt_idship').value; 
                          var shipname=document.getElementById('spshipname').innerHTML; 
                          var idroutestart=document.getElementById('txt_idroutestart').value; 
                          var routestartname=document.getElementById('txt_routestartname').value; 
                          var idrouteend=document.getElementById('txt_idrouteend').value; 
                          var routeendname=document.getElementById('txt_routeendname').value; 
                          
                          dwins=new dhtmlXWindows();dwins.attachViewportTo(\"winVP\");
                          var url='?ajax=1&sec=1&option=".$this->enc("obj_home")."&obj=".$this->enc("home_ticket")."&task=".$this->enc("settings")."&idship='+idship+'&shipname='+shipname+'&idroutestart='+idroutestart;
                              url=url+'&routestartname='+routestartname+'&idrouteend='+idrouteend+'&routeendname='+routeendname;
                          dwins.createWindow(\"winpic\",350,150,600,250);
                          dwins.window('winpic').progressOn();
                          dwins.window('winpic').setText(\"SETTINGS\");
                          dwins.window('winpic').attachURL(url);
                          dwins.window('winpic').setModal(true);
                          dwins.window('winpic').progressOff();";
                          //$url="?ajax=1&sec=1&option=".$this->enc("obj_home")."&obj=".$this->enc("home_ticket")."&task=".$this->enc("settings")."&idship='";
                          //$this->FN_DHTMLXWINDOWSURL("dwins","winpic","Settings","350","150","560","250",$url,false,true);
                          
            echo "     }
                       
                       function fn_setdashboard(idship,idroutestart,routenamestart,idrouteend,routenameend,shipname,routename)
                       {
                          //alert(idship+' '+idroutestart+' '+idrouteend);
                          document.getElementById('txt_idship').value=idship; 
                          document.getElementById('txt_idroutestart').value=idroutestart; 
                          document.getElementById('txt_routestartname').value=routenamestart; 
                          document.getElementById('txt_idrouteend').value=idrouteend; 
                          document.getElementById('txt_routeendname').value=routenameend; 
                          document.getElementById('spshipname').innerHTML=shipname; 
                          document.getElementById('sproutename').innerHTML=routename; 
                          dwins.unload(); 
                       } 
                  </script>";
            echo $this->FN_CLOSEHEADER();
            echo $this->FN_CREATEBODY("white");
            echo "<div id=\"winVP\" style=\"height:1020px;\">";
            echo "<table width=\"98%\" height=\"100%\">";
            echo "  <tr>
                        <td valign=\"top\" width=\"70%\" style=\"background-color:none;height:380px\">
                            <div style=\"width:100%;text-align:center;text-decoration:underline;font-size:24px;color:blue\">Nakroma Passenger Performance Period ".date("Y")."</div>
                            <div id=\"div_ticketbaralarm\" style=\"width:100%;height:330px;\"></div>
                        </td>
                        <td valign=\"top\" rowspan=\"2\">
                            <div>
                                <table width=\"100%\">
                                    <tr>
                                        <td colspan=\"11\">
                                            <table width=\"100%\" style=\"background-Color:transparent\">
                                                <tr>
                                                    <td>Ship</td>
                                                    <td>:</td>
                                                    <td width=\"400px\">
                                                        <span id=\"spshipname\">$shipname</span>
                                                        <input type=\"hidden\" id=\"txt_idship\" value=\"$idship\" />
                                                    </td>
                                                    <td>,</td>
                                                    <td>Rute</td>
                                                    <td>:</td>
                                                    <td width=\"160px\">
                                                        <span id=\"sproutename\">$route</span>
                                                        <input type=\"hidden\" id=\"txt_idroutestart\" value=\"$idroutestart\" />
                                                        <input type=\"hidden\" id=\"txt_routestartname\" value=\"$routestartname\" />
                                                        <input type=\"hidden\" id=\"txt_idrouteend\" value=\"$idrouteend\" />
                                                        <input type=\"hidden\" id=\"txt_routeendname\" value=\"$routeendname\" />
                                                    </td>
                                                    <td><a href=\"javascript:void(0)\" onClick=\"fn_showsettings()\"><i class=\"fa fa-cog\" style=\"font-size:14pt;\"></i></a></td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>";
                                    $qry="select totalseat from ".DB_APORTIL.".tbl_ship_information where id=1";
                                    if($this->fn_row_isexists($qry)){
                                        $totalseat=$this->fn_get_fieldvalue("totalseat",$qry);
                                        $j=10;$s=5;
                                        for($i=1;$i<=$totalseat;$i++){
                                            $colors="#ecf0f1";$colorfont="black";
                                            if($i==1||$i==($j+1)){
                                                echo "<tr>";
                                            }
                                            // Content
                                            // === Dili atauro
                                            $qrycheckin="select inctiket,status from ".DB_APORTIL.".tbl_passenger_tiket 
                                                         where inctiket='$i' and idship=$idship and idroutestart=$idroutestart and idrouteend=$idrouteend and cast(dates as date)=cast(now() as date) and isdeleted=0";
                                            if($this->fn_row_isexists($qrycheckin)){
                                                $colorfont="white";
                                                $status=$this->fn_get_fieldvalue("status",$qrycheckin);
                                                $colors="#f1c40f";
                                                if($status==1){$colors="#3498db";}
                                                if($status==-2){$colors="#ecf0f1";$colorfont="black";}
                                            }
                                            echo "<td width=\"10px\" height=\"8px\" style=\"height:8px;background-color:transparent\">
                                                       <div id=\"div$i\" style=\"color:$colorfont;padding-top:1px;font-size:8pt;text-align:center;border: 1px solid transparent;border-radius: 2px;background-color:$colors;width:25px;height:15px\">
                                                           $i
                                                       </div>
                                                  </td>";
                                            if($i==$s){
                                                echo "<td width=\"20px\">&nbsp</td>";
                                            }
                                            
                                            if($i%10==0){
                                                $j+=10;$s+=10;
                                                echo "</tr>";
                                            }
                                        }
                                    }
                                    //$arr=array("4-H"=>"#f1c40f","5-C"=>"#f1c40f","5-F"=>"#f1c40f","5-G"=>"#f1c40f","5-H"=>"#f1c40f","20-C"=>"#2980b9","20-D"=>"#2980b9","30-D"=>"#2980b9");
                                    // === Seat Code
//                                    echo "<tr>";
//                                    for($h=1;$h<=10;$h++){
//                                        if($h==1){
//                                            echo "<td width=\"1px\">&nbsp</td>";
//                                        }                                        
//                                        echo "<td width=\"10\" style=\"font-size:8pt;\">&nbsp;".chr(64+$h)."</td>";
//                                        if($h==5){
//                                            echo "<td width=\"20px\">&nbsp</td>";
//                                        }                            
//                                    }
//                                    echo "</tr>";
//                                    
                                    // === SEAT Number
//                                    for($i=1;$i<=30;$i++){
//                                        echo "<tr>";
//                                                 for($j=1;$j<=10;$j++)
//                                                 {
//                                                     $colors="#ecf0f1";
                                                     //if($i==4&&$j==8){$colors="#f1c40f";}
//                                                     if(array_key_exists("$i-".chr(64+$j),$arr)){
//                                                        $colors=$arr["$i-".chr(64+$j)];
//                                                     }
//                                                     if($j==1){
//                                                        echo "<td width=\"1px\" style=\"font-size:10pt;color:black\">$i.</td>";
//                                                     }
//                                                     echo "<td width=\"10px\" height=\"8px\" style=\"height:8px;background-color:none\">
//                                                                <div style=\"border: 1px solid transparent;border-radius: 2px;background-color:$colors;width:15px;height:8px\">
//                                                                    &nbsp;
//                                                                </div>
//                                                           </td>";
//                                                     if($j==5){
//                                                         echo "<td width=\"20px\">&nbsp</td>";
//                                                     }
//                                                 }
//                                        echo "</tr>";
//                                    }    
            echo "              </table>
                            </div>
                            
                        </td>
                    </tr>
                    <tr>
                        <td valign=\"top\" style=\"background-color:none\">
                            <table width=\"100%\">
                                <tr>
                                    <td>
                                        <div class=\"preview_tpl\" id=\"previewData\" style=\"\">
                                            <div class=\"header_tpl\"  style=\"font-weight:bold\">Nakroma Passenger</div>
                                            <table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" style=\"width:400px\">
                                                <tr>
                                                    <td>
                                                        <div style=\"text-align:center;text-decoration:underline;font-size:20px;color:blue;margin-top:10px\">
                                                            Period ".date("Y")."
                                                        </div>
                                                        <div id=\"div_pieshippasstrend\" style=\"height:250px;margin-top:0px;\"></div>
                                                    </td>
                                                </tr>
                                                <!--<tr>
                                                    <td>
                                                        <table>
                                                            <tr>
                                                                <td>Atauro</td>
                                                                <td>: 55% (1.5K)</td>
                                                                <td>Oekuse</td>
                                                                <td>: 45% (800)</td>
                                                            </tr>
                                                        </table>
                                                    </td>
                                                </tr>-->
                                            </table>                                    
                                        </div>
                                    </td>
                                    <td valign=\"top\">
                                        <div class=\"preview_tpl\" id=\"previewData\" style=\"margin-left:20px\">
                                            <div class=\"header_tpl\" style=\"font-weight:bold\">Nakroma Manifest</div>                                        
                                            <table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" style=\"width:450px\">
                                                <thead>
                                                    <tr>
                                                        <td colspan=\"5\">
                                                            <table>
                                                                <tr>
                                                                    <td>Nacroma Tonase</td>
                                                                    <td>:</td>
                                                                    <td><span style=\"font-size:19px\">200</span> ton</td>
                                                                </tr>
                                                                <tr>
                                                                    <td>Threshold</td>
                                                                    <td>:</td>
                                                                    <td><span style=\"font-size:19px\">180</span> ton</td>
                                                                </tr>
                                                            </table>
                                                        </td>
                                                    </tr>
                                                </thead>
                                                <tr>
                                                    <td style=\"border-bottom:1px solid black;border-right:1px solid black\"></td>
                                                    <td style=\"border-bottom:1px solid black;\">Unit</td>
                                                    <td align=\"right\" style=\"border-bottom:1px solid black\">Qty</td>                                                    
                                                    <td align=\"right\" style=\"border-bottom:1px solid black\">( \$ )</td>
                                                    <td align=\"right\" style=\"border-bottom:1px solid black\">( ton )</td>
                                                </tr>
                                                <tr>
                                                    <td style=\"border-right:1px solid black\">Passenger</td>
                                                    <td>Person</td>
                                                    <td align=\"right\">300</td>
                                                    <td align=\"right\">\$1.800</td>                                                                                                        
                                                    <td align=\"right\">15.0</td>
                                                </tr>
                                                <tr>
                                                    <td style=\"border-right:1px solid black\">Vehichle</td>
                                                    <td>unit</td>
                                                    <td align=\"right\">10</td>                                                    
                                                    <td align=\"right\">\$6.800</td>
                                                    <td align=\"right\">20.0</td>
                                                </tr>
                                                <tr>
                                                    <td style=\"border-right:1px solid black\">Non Vehichle</td>
                                                    <td>unit</td>                                                    
                                                    <td align=\"right\">10</td>
                                                    <td align=\"right\">\$4.700</td>
                                                    <td align=\"right\">18.0</td>
                                                </tr>
                                                <tr>
                                                    <td style=\"border-top:1px dashed black;border-right:1px solid black\">Total</td>
                                                    <td style=\"border-top:1px dashed black\"></td>
                                                    <td  align=\"right\" style=\"border-top:1px dashed black;color:blue;\">330</td>
                                                    <td align=\"right\" style=\"border-top:1px dashed black;color:blue;\">\$13.300</td>
                                                    <td align=\"right\" style=\"border-top:1px dashed black;color:blue;\">54.0</td>
                                                </tr>
                                                <tfoot>
                                                    <tr>
                                                        <td colspan=\"5\">
                                                            <table width=\"100%\" style=\"background-color:none\">
                                                                <tr>
                                                                    <td width=\"220px\" style=\"font-Size:12pt;\">GAP ( Ton )</td>
                                                                    <td width=\"1px\" style=\"font-Size:12pt;\">-></td>
                                                                    <td width=\"220px\" style=\"font-Size:12pt;\">180.0 - 54.0</td>
                                                                    <td width=\"1px\" style=\"font-Size:12pt;\">=</td>
                                                                    <td style=\"font-Size:14pt;\">
                                                                        <div style=\"background-color:green;color:white;padding:5px;border: 2px solid green;border-radius: 5px 2px;\">
                                                                            126.0
                                                                        </div>
                                                                    </td>
                                                                </tr>
                                                                <tr>
                                                                    <td colspan=\"5\" style=\"font-Size:14pt;\">
                                                                        <span>Tonase Status</span>&nbsp;
                                                                        <span>:</span>&nbsp;
                                                                        <span style=\"color:green;font-size:16pt;font-weight:bold\">GOOD</span>
                                                                    </td>                                                                    
                                                                </tr>
                                                            </table>
                                                        </td>
                                                    </tr>
                                                </tfoot>
                                            </table>                                    
                                        </div>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>";
            echo "</table>";
            echo "</div>";
            echo $this->FN_CREATEFOOTER();

        }

        public function fn_getstinfo(){
            $idship=$_REQUEST['idship'];
//            $shipname=$_REQUEST['shipname'];
            $idroutestart=$_REQUEST['idroutestart'];
//            $routestartname=$_REQUEST['routestartname'];
            $idrouteend=$_REQUEST['idrouteend'];
//            $routeendname=$_REQUEST['routeendname'];
            $arr=array();
            $qry="select totalseat from ".DB_APORTIL.".tbl_ship_information where id=$idship";
            //echo $qry;return false;
            if($this->fn_row_isexists($qry)){
                $totalseat=$this->fn_get_fieldvalue("totalseat",$qry);
                for($i=1;$i<=$totalseat;$i++){
                    $colors="#ecf0f1";$colorfont="black";
                    // === Dili atauro
                    $qrycheckin="select inctiket,status from ".DB_APORTIL.".tbl_passenger_tiket 
                                 where inctiket='$i' and (idship=$idship and idroutestart=$idroutestart and idrouteend=$idrouteend)
                                       and cast(dates as date)=cast(now() as date) and isdeleted=0";
                    //echo $qrycheckin;return false;
                    if($this->fn_row_isexists($qrycheckin)){
                        $status=$this->fn_get_fieldvalue("status",$qrycheckin);
                        $colors="#f1c40f";$colorfont="white";
                        if($status==1){$colors="#3498db";}
                        if($status==-2){$colors="#ecf0f1";$colorfont="black";}
//                        array_push($arr,array("$i"=>$colors));
                        
                    }
                    array_push($arr,array("ndx"=>$i,"colors"=>$colors,"colorfont"=>$colorfont));
                }
            }
            echo json_encode($arr);
        }
        
        public function fn_settings()
        {
            $idship=$_REQUEST['idship'];
            $shipname=$_REQUEST['shipname'];
            $idroutestart=$_REQUEST['idroutestart'];
            $routestartname=$_REQUEST['routestartname'];
            $idrouteend=$_REQUEST['idrouteend'];
            $routeendname=$_REQUEST['routeendname'];
            echo $this->FN_CREATEHEADER();
            echo "<style>
                      .besidebtnsave {margin-left:108px;margin-top:-6px;position:absolute;}
                      .besidebtnupdate {margin-left:210px;margin-top:-6px;position:absolute;}
                      .besidebtnsubmit {margin-left:292px;margin-top:-6px;position:absolute;}
                      .besidebtndelete {margin-left:306px;margin-top:-6px;position:absolute;}
                  </style>";
            echo "<script>
                       var myForm,myFormsearch,dgroute;
                       function initObject()
                       {";
                            $formdata=array(
                                              array("type"=>"settings","position"=>"label-left","labelWidth"=>"180","inputWidth"=>"120"),
                                              array("type"=>"block","width"=>"500",
                                                     "list"=>array(
                                                                      array("type"=>"hidden","name"=>"txt_id"),
                                                                      array("type"=>"combo","name"=>"cbo_idship","label"=>"Ship Name","required"=>"true","info"=>"true","inputWidth"=>"280","value"=>"0",
                                                                            "tooltip"=>"Pilih Ship Name first. Thank You","validate"=>"NotEmpty","maxLength"=>"11","className"=>"txtleft"),
                                                                      
                                                                      array("type"=>"combo","name"=>"cbo_idroutestart","label"=>"Rute From","required"=>"true","info"=>"true","inputWidth"=>"150","value"=>"",
                                                                            "tooltip"=>"Pilih From terlebih dahulu. TERIMA KASIH","validate"=>"NotEmpty","maxLength"=>"11","className"=>"txtleft"),
                                                                      array("type"=>"combo","name"=>"cbo_idrouteend","label"=>"Rute To","required"=>"true","info"=>"true","inputWidth"=>"150","value"=>"",
                                                                            "tooltip"=>"Pilih To terlebih dahulu. TERIMA KASIH","validate"=>"NotEmpty","maxLength"=>"11","className"=>"txtleft"),
                                                                      
                                                                      array("type"=>"button","name"=>"btnsave","value"=>"Set","className"=>"button_update","offsetLeft"=>"20","offsetTop"=>"15"),
                                                                      //array("type"=>"button","name"=>"btnupdate","value"=>"Update","className"=>"button_saveas besidebtnsave","offsetLeft"=>"0","disabled"=>"1"),
                                                                      //array("type"=>"button","name"=>"btnsubmit","value"=>"Submit","className"=>"button_submit besidebtnupdate","offsetLeft"=>"0","disabled"=>"1"),
                                                                      //array("type"=>"button","name"=>"btndelete","value"=>"Delete","className"=>"button_delete besidebtnupdate","offsetLeft"=>"0","disabled"=>"1"),
                                                                      //array("type"=>"button","name"=>"btncancel","value"=>"Cancel","className"=>"button_cancel besidebtndelete","offsetLeft"=>"0","disabled"=>"0")
                                                     )
                                              )
                                       );

                            $this->FN_DHTMLXFORM("myForm","divroutenew",$formdata);
                            
                            $urlcbo="fn_dhtmlxloadobject('".$this->enc("obj_controller")."','obj=".$this->enc("-")."&task=".$this->enc("dhtmlxcbofilter")."&tableobj=tbl_ship_information|id,shipname')";
                            $this->FN_COMBOVALIDATIONVALUENEW("myForm","cbo_idship","tbl_ship_information","$urlcbo","");
                            echo "myForm.getCombo('cbo_idship').addOption($idship,'$shipname', null, null, true);";
                            
                            $urlcbo="fn_dhtmlxloadobject('".$this->enc("obj_controller")."','obj=".$this->enc("-")."&task=".$this->enc("dhtmlxcbofilter")."&tableobj=tbl_route_information|id,routename')";
                            $this->FN_COMBOVALIDATIONVALUENEW("myForm","cbo_idroutestart","tbl_route_information","$urlcbo","");
                            echo "myForm.getCombo('cbo_idroutestart').addOption($idroutestart,'$routestartname', null, null, true);";
                            
                            $urlcbo="fn_dhtmlxloadobject('".$this->enc("obj_controller")."','obj=".$this->enc("-")."&task=".$this->enc("dhtmlxcbofilter")."&tableobj=tbl_route_information|id,routename')";
                            $this->FN_COMBOVALIDATIONVALUENEW("myForm","cbo_idrouteend","tbl_route_information","$urlcbo","");
                            echo "myForm.getCombo('cbo_idrouteend').addOption($idrouteend,'$routeendname', null, null, true);";
                            
                            $arrerror=array("cbo_idroutestart"=>"Error Found : Harap Isikan <b>Rute Start</b> terlebih dahulu.TERIMA KASIH",
                                            "cbo_idrouteend"=>"Error Found : Harap Isikan <b>Rute Tiba</b> terlebih dahulu.TERIMA KASIH"
                                      );
                            $this->FN_DHTMLXFORMVALIDATIONERROR("myForm",$arrerror);

                            $arrayControls=array("txt_id"=>"",
                                                 "cbo_idship"=>"",
                                                 "cbo_idroutestart"=>"",
                                                 "cbo_idrouteend"=>""
                                          );

                            // === Form Event
                            $onobjkeydown="if(ev.keyCode==13){ev.stopPropagation();ev.preventDefault();if(myForm.isItemEnabled('btnupdate')){myForm.setItemFocus('btnupdate');dhtmlXclickButton('btnupdate');}else{myForm.setItemFocus('btnsave');}return false;}";

                            $onbuttonclickbtnsave="if(myForm.validate())
                                                   {
                                                        dhtmlx.confirm({
                                                              title:'Confirmation',text:'Are you will be saved and data is correctly?',type:'confirm',
                                                              callback:function(result){
                                                                  if(result)
                                                                  {";
                                                                      $params="'obj=".$this->enc("home_ticket")."&task=".$this->enc("setdashboard")."'";
                                                                      $onformsenddata="url=fn_dhtmlxsenddata('".$this->enc("obj_home")."',$params);
                                                                      myForm.send(url,\"get\",function(loader, response){";
                                                                          $onformsenddata.=$this->FN_DHTMLXWINDOWSHIDEPROGRESS();
                                                                          $onformsenddata.="var sp=trim(response).split('|');
                                                                          //alert(response);
                                                                          if(sp[0]=='ok')
                                                                          {
                                                                              fn_dhtmlxmessage('','Data <b>'+myForm.getCombo('cbo_idroutestart').getComboText()+'</b> has been saved');";
                                                                              //$onformsenddata.=$this->FN_DHTMLXFORMCLEAR2("myForm",$arrayControls,"txt_routename");
                                                                              //$onformsenddata.="fn_grid_loaddata();
                                                                              $onformsenddata.="var idship=myForm.getItemValue('cbo_idship');";
                                                                              $onformsenddata.="var idroutestart=myForm.getItemValue('cbo_idroutestart');";
                                                                              $onformsenddata.="var routenamestart=myForm.getCombo('cbo_idroutestart').getComboText();";
                                                                              $onformsenddata.="var idrouteend=myForm.getItemValue('cbo_idrouteend');";
                                                                              $onformsenddata.="var routenameend=myForm.getCombo('cbo_idrouteend').getComboText();";
                                                                              $onformsenddata.="var route=myForm.getCombo('cbo_idroutestart').getComboText()+'-'+myForm.getCombo('cbo_idrouteend').getComboText();";
                                                                              $onformsenddata.="var shipname=myForm.getCombo('cbo_idship').getComboText();";
                                                                              $onformsenddata.="window.parent.fn_setdashboard(idship,idroutestart,routenamestart,idrouteend,routenameend,shipname,route);
                                                                          }
                                                                          else if(sp[0]=='failed')
                                                                          {fn_dhtmlxmessage('error','Error Found : '+sp[1]);}
                                                                          else
                                                                          {fn_dhtmlxmessage('error','Error Found : '+response);}
                                                                      });";
                                                                      $onbuttonclickbtnsave.=$this->FN_DHTMLXWINDOWSHOWPROGESS($onformsenddata);
                            $onbuttonclickbtnsave.="              }
                                                              }
                                                        });
                                                    }";

                            $onbuttonclickbtnupdt="if(myForm.validate())
                                                   {
                                                        dhtmlx.confirm({
                                                             title:'Confirmation',text:'Are you will be updated and data is correctly?',type:'confirm',
                                                             callback:function(result){
                                                                if(result)
                                                                {";
                                                                   $params="'obj=".$this->enc("data_route")."&task=".$this->enc("updrecord")."'";
                                                                   $onformsenddata="url=fn_dhtmlxsenddata('".$this->enc("obj_data")."',$params);
                                                                   myForm.send(url,\"get\",function(loader, response){";
                                                                      $onformsenddata.=$this->FN_DHTMLXWINDOWSHIDEPROGRESS();
                                                                      $onformsenddata.="var sp=trim(response).split('|');
                                                                      //alert(response);
                                                                      if(sp[0]=='ok')
                                                                      {
                                                                           fn_dhtmlxmessage('','Data <b>'+myForm.getItemValue('txt_routename')+'</b> has been update');";
                                                                           $onformsenddata.=$this->FN_DHTMLXFORMCLEAR2("myForm",$arrayControls,"txt_routename");
                                                                           $onformsenddata.="myForm.enableItem('btnsave');";
                                                                           $onformsenddata.="myForm.disableItem('btnupdate');";
                                                                           $onformsenddata.="myForm.disableItem('btndelete');";
                                                                           $onformsenddata.="fn_grid_loaddata();
                                                                      }
                                                                      else if(sp[0]=='failed')
                                                                      {fn_dhtmlxmessage('error','Error Found : '+sp[1]);}
                                                                      else
                                                                      {fn_dhtmlxmessage('error','Error Found : '+response);}
                                                                   });";
                                                                   $onbuttonclickbtnupdt.=$this->FN_DHTMLXWINDOWSHOWPROGESS($onformsenddata);
                            $onbuttonclickbtnupdt.="            }
                                                             }
                                                        });
                                                   }";

                            $eventafterdeleted=$this->FN_DHTMLXFORMCLEAR2("myForm",$arrayControls,"txt_routename");
                            $eventafterdeleted.="myForm.enableItem('btnsave');";
                            $eventafterdeleted.="myForm.disableItem('btnupdate');";
                            $eventafterdeleted.="myForm.disableItem('btndelete');";
                            $eventafterdeleted.="fn_grid_loaddata();";
                            $onbuttonclickbtndeleted=$this->FN_DHTMLXREMARKFORDELETED2("obj_data","data_route","myForm.getItemValue('txt_id')","myForm.getItemValue('txt_routename')",$eventafterdeleted);

                            $onbuttonclickbtncancel=$this->FN_DHTMLXFORMCLEAR2("myForm",$arrayControls);
                            $onbuttonclickbtncancel.="myForm.enableItem('btnsave');";
                            $onbuttonclickbtncancel.="myForm.disableItem('btnupdate');";
                            $onbuttonclickbtncancel.="myForm.disableItem('btndelete');";
                            $onbuttonclickbtncancel.="myForm.setItemFocus('txt_routename');";
                            $onbuttonclickbtncancel.="fn_grid_loaddata();";

                            $arrevent=array(
                                                array("eventname"=>"onbuttonclick","eventparam"=>"id,val",
                                                          "switch"=>array(
                                                                                "btnsave"=>"$onbuttonclickbtnsave",
                                                                                "btnupdate"=>"$onbuttonclickbtnupdt",
                                                                                "btndelete"=>"$onbuttonclickbtndeleted",
                                                                                "btncancel"=>"$onbuttonclickbtncancel"
                                                          )
                                                ),
                                                array("eventname"=>"onkeydown","eventparam"=>"inp,ev,id,val",
                                                          "switch"=>array(
                                                                                "txt_description"=>"$onobjkeydown"
                                                          )
                                                )
                            );


                            $this->FN_DHTMLXFORMEVENT("myForm",$arrevent);

                            // === FORM SEARCH AND GRID
         //                   $formdata=array(
//                                              array("type"=>"settings","position"=>"label-left","labelWidth"=>"180","inputWidth"=>"120"),
//                                              array("type"=>"fieldset","width"=>"580","label"=>"Search",
//                                                     "list"=>array(
//                                                                      array("type"=>"input","name"=>"txtsearch","label"=>"Insert Your Keyword","info"=>"true","inputWidth"=>"240",
//                                                                            "tooltip"=>"Insert Your Keyword","maxLength"=>"","className"=>"txtleft","labelWidth"=>"210"),
//                                                                      array("type"=>"newcolumn"),
//                                                                      array("type"=>"button","name"=>"btnfind","value"=>"","className"=>"button_find","offsetLeft"=>"10","offsetTop"=>"0")
//                                                     )
//                                              )
//                            );

//                            $this->FN_DHTMLXFORM("myFormsearch","divroutesearch",$formdata,true);
//                            $ontxtsearchkeydown="if(ev.keyCode==13){ev.stopPropagation();ev.preventDefault();myFormsearch.setItemFocus('btnfind');}";
//                            $arrevent=array(
//                                                array("eventname"=>"onbuttonclick","eventparam"=>"id,val",
//                                                          "switch"=>array(
//                                                                                "btnfind"=>"fn_grid_loaddata()"
//                                                          )
//                                                ),
//                                                array("eventname"=>"onkeydown","eventparam"=>"inp,ev,id,val",
//                                                          "switch"=>array(
//                                                                                "txtsearch"=>"$ontxtsearchkeydown"
//                                                          )
//                                                )
//                            );
//                            $this->FN_DHTMLXFORMEVENT("myFormsearch",$arrevent);

//                            $grdinit=array("gridname"=>"dgroute","divtarget"=>"div_dgroute","divpaging"=>"div_dgroutepaging","paginglimit"=>PAGE_LIMIT,
//                                           "showloader"=>"true");
//                            $gridproperties=array("id"=>"right,ro,96,right,int,false,true",
//                                                  "No.&nbsp;"=>"right,ro,35,center,int,false",
//                                                  "Route Name"=>"left,ro,230,left,str,false",
//                                                  "Description"=>"left,ro,238,left,str,false");
//                            $this->FN_DHTMLXGRIDVIEW($grdinit,$gridproperties,"bricks","","fn_grid_loaddata()");
//                            $arrfields=array("txt_id"=>"","txt_routename"=>"","txt_description"=>"");
//                            $otherevent="";
//                            $this->FN_DHTMLXGRIDVIEWTOFORMNEW("dgroute","myForm","tbl_route_information",0,$arrfields,"");
            echo "    }

                      
                   </script>";
            echo $this->FN_CLOSEHEADER();
            echo $this->FN_CREATEBODY("e8f1ff");

            echo "<table width=\"98%\" border=\"0\">
                      <tr>
                          <td>";
                              $url="location.reload();";
                              $myuri=array("<b>DASHBOARD CONFIGURATION</b>"=>"$url|id='a_route'");
                              echo $this->MULTIPLE_LINK($myuri);
            echo "       </td>
                      </tr>
                      <tr>
                          <td>
                              <div id=\"divroutecontent\" style=\"margin-left:0px;\">
                                  <table width=\"98%\" border=\"0\">
                                      <tr>
                                          <td width=\"45%\" valign=\"top\">
                                              <div id=\"divroutenew\" style=\"\"></div>
                                          </td>
                                      </tr>
                                  </table>
                              </div>
                          </td>
                      </tr>
                  </table>";
            echo $this->FN_CREATEFOOTER();

        }
        
        public function fn_setdashboard($isupdate=null)
        {
            $year=date("Y");
//            if($isupdate){$id=$_REQUEST['txt_id'];}
            $idemployee=$_SESSION['idemployee'];
            $nik=$_SESSION['nik'];
            $idship=$_REQUEST['cbo_idship'];
            $sp=$this->fn_get_fieldsvalues("shipname,shipnumber","select shipname,shipnumber from ".DB_APORTIL.".tbl_ship_information where id='$idship'");
            $shipnumber=$sp[1];$shipname=$sp[0];
            $idroutestart=$_REQUEST['cbo_idroutestart'];
            $routenamestart=$this->fn_get_fieldvalue("routename","select routename from ".DB_APORTIL.".tbl_route_information where id='$idroutestart'");
            $idrouteend=$_REQUEST['cbo_idrouteend'];
            $routenameend=$this->fn_get_fieldvalue("routename","select routename from ".DB_APORTIL.".tbl_route_information where id='$idrouteend'");
            
            $qry="insert into ".DB_APORTIL.".tbl_dashboard_setting_rute 
                  set idemployee='$idemployee',nik='$nik',idship='$idship',shipname='$shipname',idroutestart='$idroutestart',
                      routestartname='$routenamestart',idrouteend='$idrouteend',routeendname='$routenameend',iby='".$_SESSION['nik']."',idt=now()";
            if($this->fn_row_isexists("select id from ".DB_APORTIL.".tbl_dashboard_setting_rute where idemployee='$idemployee'"))
            {
                $qry="update ".DB_APORTIL.".tbl_dashboard_setting_rute
                      set idemployee='$idemployee',nik='$nik',idship='$idship',shipname='$shipname',idroutestart='$idroutestart',
                          routestartname='$routenamestart',idrouteend='$idrouteend',routeendname='$routenameend',uby='".$_SESSION['nik']."',udt=now()
                      where idemployee='$idemployee'";
            }

            if($this->executequery($qry))
            {
                echo 'ok|';
            }
        }
    }
?>