<?php
    class TRA_NEWTICKET extends TRA
    {
        public function tra_newticket_javainit()
        {

        }

        public function fn_newticket_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_newticket();
                break;

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

                default:
                    $this->fn_default_newticket();
                break;
            }
        }
        public function fn_default_newticket()
        {
            //for($i=1;$i<=30;$i++){
//                 for($j=1;$j<=10;$j++)
//                 {
//                    $seat="$i.".chr(64+$j);
//                    $qry="insert into ".DB_APORTIL.".tbl_ship_seatnumber set idship=1,shipnumber='NAC-151',seatnumber='".$seat."',iby='82010',idt=now()";
//                    $this->executequery($qry);
//                 }
//            }
            echo $this->FN_CREATEHEADER();

            echo "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no\" />";
            echo "<style>
                      .besidebtnsave {margin-left:118px;margin-top:-6px;position:absolute;}
                      .besidebtnupdate {margin-left:230px;margin-top:-6px;position:absolute;}
                      .besidebtnsubmit {margin-left:292px;margin-top:-6px;position:absolute;}
                      .besidebtndelete {margin-left:340px;margin-top:-6px;position:absolute;}
                      .besidelabel {margin-left:280px;margin-top:-5px;position:absolute;}
                      .underpassengername {margin-left:180px;margin-top:-10px;position:static;}
                      .besidelabelbaggage {margin-left:250px;margin-top:-5px;position:absolute;}
                      .besidelabelprice {margin-left:275px;margin-top:-6px;position:absolute;}
                      .besideseatnumber {margin-left:275px;margin-top:-6px;position:absolute;}
                      .besidecbofrom {margin-left:305px;margin-top:-5px;position:absolute;}
                      .besidecboidcard {margin-left:280px;margin-top:-5px;position:absolute;}
                      .besidebaggage {margin-left:280px;margin-top:-5px;position:absolute;}
                      .besidelimitkgbaggage {margin-left:430px;margin-top:-5px;position:absolute;}
                      .besidelimitbaggage {margin-left:350px;margin-top:-5px;position:absolute;}
                      .besidebtnbook {margin-left:360px;margin-top:-5px;position:absolute;}
                      .txttiketnumber {font-size:18pt;}
                      .txtseatnumber {font-size:10pt;}
                      .txttotalbiaya {font-size:14pt;}
                      .containerpicture {margin-left:0px;margin-top:0px;}
                      .besidetxtyears {margin-left:280px;margin-top:-45px;}
                      .besidecbobodmonth {margin-left:380px;margin-top:-45px;}
                  </style>";
            
            echo "<script>
                       var myForm,myFormsearch,dgnewticket,dwins;
                       var mm,ss;
                       var tbooking;
                       var monthNames = [\"January\", \"February\", \"March\", \"April\", \"May\", \"June\",
                                            \"July\", \"August\", \"September\", \"October\", \"November\", \"December\"
                       ];
                       function initObject()
                       {
                            mm=5;ss=0;";
                            $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"=>"hidden","name"=>"txt_childspassenger"),
                                                                      array("type"=>"hidden","name"=>"txt_modifcount"),
                                                                      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"=>"input","name"=>"txt_tiketnumber","label"=>"Ticket Number","required"=>"true","info"=>"true","inputWidth"=>"280","value"=>"","readonly"=>"true",
                                                                            "tooltip"=>"Insert Ticket Number first. Thank You","validate"=>"NotEmpty","maxLength"=>"40","className"=>"txtcenter txttiketnumber"),
                                                                      array("type"=>"input","name"=>"txt_voynumber","label"=>"Voyage Number","required"=>"true","info"=>"true","inputWidth"=>"280","value"=>"",
                                                                            "tooltip"=>"Insert Voyage Number first. Thank You","validate"=>"NotEmpty","maxLength"=>"100","className"=>"txtcenter"),
//                                                                      array("type"=>"input","name"=>"txt_inctiket","label"=>"No. Sequence","required"=>"true","info"=>"true","inputWidth"=>"90","value"=>"0",
//                                                                            "tooltip"=>"Insert No. Sequence first. Thank You","validate"=>"NotEmpty","maxLength"=>"11","className"=>"txtcenter"),
                                                                      //array("type"=>"input","name"=>"txt_shipnumber","label"=>"Ship Number","required"=>"true","info"=>"true","inputWidth"=>"280","value"=>"",
//                                                                            "tooltip"=>"Insert Ship Number first. Thank You","validate"=>"NotEmpty","maxLength"=>"100","className"=>"txtleft"),
                                                                      array("type"=>"input","name"=>"txt_passengername","label"=>"Name","required"=>"true","info"=>"true","inputWidth"=>"280","value"=>"",
                                                                            "tooltip"=>"Insert Nama first. Thank You","validate"=>"NotEmpty","maxLength"=>"100","className"=>"txtleft"),

                                                                      array("type"=>"label","name"=>"lbllookuphist","label"=>"<a id='achilds' href='javascript:void(0)' onClick='fn_showchildren()'><span id='spchild'>0</span> Children</a>","className"=>"underpassengername","offsetLeft"=>"0","offsetTop"=>"15"),
                                                                      array("type"=>"combo","name"=>"cbo_idgender","label"=>"Gender","required"=>"true","info"=>"true","inputWidth"=>"140","value"=>"0",
                                                                            "tooltip"=>"Please Choice gender first. Thank You","validate"=>"NotEmpty","maxLength"=>"11","className"=>"txtleft","note"=>array("text"=>"Ex : Female or Male")),
                                                                      array("type"=>"calendar","name"=>"txt_bod","label"=>"Birth Of Dates","required"=>"false","info"=>"true","inputWidth"=>"90","readonly"=>"true","value"=>"",
                                                                            "tooltip"=>"Insert Dates first. Thank You","maxLength"=>"","className"=>"txtcenter","dateFormat"=>"%Y-%m-%d","hidden"=>true),                                                                                                                                                   
                                                                      
                                                                      array("type"=>"input","name"=>"txt_bodyears","label"=>"Birth Of Dates","required"=>"true","info"=>"true","inputWidth"=>"90","readonly"=>"false","value"=>"",
                                                                            "tooltip"=>"Insert Years Of Birthdate . Thank You","validate"=>"NotEmpty","maxLength"=>"4","className"=>"txtcenter","note"=>array("text"=>"ex : 1987")),
                                                                      array("type"=>"newcolumn"),
                                                                      array("type"=>"combo","name"=>"cbo_bodmonth","label"=>"","required"=>"true","info"=>"true","inputWidth"=>"90","value"=>"",
                                                                            "tooltip"=>"Pilih ID Card first. Thank You","validate"=>"NotEmpty","maxLength"=>"","className"=>"besidetxtyears txtcenter","note"=>array("text"=>"ex : January")),
                                                                      array("type"=>"newcolumn"),
                                                                      array("type"=>"combo","name"=>"cbo_bodday","label"=>"","required"=>"true","info"=>"true","inputWidth"=>"60","value"=>"",
                                                                            "tooltip"=>"Pilih ID Card first. Thank You","validate"=>"NotEmpty","maxLength"=>"","className"=>"besidecbobodmonth txtcenter","note"=>array("text"=>"ex : 31")),
                                                                      
                                                                      array("type"=>"combo","name"=>"cbo_idcardtype","label"=>"ID Card","required"=>"true","info"=>"true","inputWidth"=>"90","value"=>"0",
                                                                            "tooltip"=>"Pilih ID Card first. Thank You","validate"=>"NotEmpty","maxLength"=>"11","className"=>"txtleft"),
                                                                      array("type"=>"newColumn"),
                                                                      array("type"=>"input","name"=>"txt_cardnumber","label"=>"","required"=>"true","info"=>"true","inputWidth"=>"160","value"=>"",
                                                                            "tooltip"=>"Insert Picture first. Thank You","validate"=>"NotEmpty","maxLength"=>"100","className"=>"txtleft besidecboidcard",
                                                                            "note"=>array("text"=>"Insert ID card Number")),
                                                                      
//                                                                      array("type"=>"container","name"=>"containerpicture","label"=>"Take Picture","className"=>"containerpicture","offsetTop"=>"20"),
                                                                      array("type"=>"input","name"=>"txt_nationality","label"=>"Nationality","required"=>"true","info"=>"true","inputWidth"=>"280","value"=>"Timor Leste",
                                                                            "tooltip"=>"Insert Nationality. Thank You","validate"=>"NotEmpty","maxLength"=>"100","className"=>"txtleft","offsetTop"=>"20"),                                                                      
                                                                      array("type"=>"hidden","name"=>"txt_picdata","label"=>"Picture","required"=>"true","info"=>"true","inputWidth"=>"280","value"=>"aportildefault.png",
                                                                            "tooltip"=>"Insert Picture first. Thank You","validate"=>"NotEmpty","maxLength"=>"100","className"=>"txtleft"),
                                                                      array("type"=>"calendar","name"=>"txt_dates","label"=>"Dates","required"=>"true","info"=>"true","inputWidth"=>"90","readonly"=>"true","value"=>date("Y-m-d"),
                                                                            "tooltip"=>"Insert Dates first. Thank You","validate"=>"NotEmpty","maxLength"=>"","className"=>"txtcenter","dateFormat"=>"%Y-%m-%d"),
                                                                      array("type"=>"combo","name"=>"cbo_idroutestart","label"=>"From","required"=>"true","info"=>"true","inputWidth"=>"90","value"=>"0",
                                                                            "tooltip"=>"Pilih From first. Thank You","validate"=>"NotEmpty","maxLength"=>"6","className"=>"txtcenter"),
                                                                      array("type"=>"newColumn"),
                                                                      array("type"=>"label","name"=>"lblmeter","label"=>"to","className"=>"besidelabel"),
                                                                      array("type"=>"combo","name"=>"cbo_idrouteend","label"=>"","required"=>"true","info"=>"true","inputWidth"=>"90","value"=>"0",
                                                                            "tooltip"=>"Pilih To first. Thank You","validate"=>"NotEmpty","maxLength"=>"6","className"=>"txtcenter besidecbofrom"),
//                                                                      array("type"=>"input","name"=>"txt_seatnumber","label"=>"Seat Number","required"=>"true","info"=>"true","inputWidth"=>"90","value"=>"","readonly"=>"true",
//                                                                            "tooltip"=>"Insert Seat Number first. Thank You","validate"=>"NotEmpty","maxLength"=>"30","className"=>"txtcenter txtseatnumber"),
//                                                                      array("type"=>"newColumn"),
//                                                                      array("type"=>"button","name"=>"btnbookseat","label"=>"Booking","className"=>"besideseatnumber","value"=>"Booking"),
//                                                                      array("type"=>"newColumn"),
//                                                                      array("type"=>"label","name"=>"lbllimitbook","label"=>"Limit Booking in 5 Minutes","className"=>"besidebtnbook"),
                                                                      array("type"=>"input","name"=>"txt_timeschedule","label"=>"Time","required"=>"true","info"=>"true","inputWidth"=>"90","value"=>"00:00:00","readonly"=>"true",
                                                                            "tooltip"=>"Insert TimeSchedule first. Thank You","validate"=>"NotEmpty","maxLength"=>"","className"=>"txtcenter"),
                                                                      array("type"=>"newColumn"),
                                                                      array("type"=>"label","name"=>"lblmeter","label"=>"OTL","className"=>"besidelabelprice"),
                                                                      
                                                                      array("type"=>"input","name"=>"txt_price","label"=>"Price","required"=>"true","info"=>"true","inputWidth"=>"90","value"=>"0","readonly"=>"true",
                                                                            "tooltip"=>"Insert Price first. Thank You","validate"=>"NotEmpty","maxLength"=>"","className"=>"txtright"),
                                                                      array("type"=>"newColumn"),
                                                                      array("type"=>"label","name"=>"lblmeter","label"=>"\$","className"=>"besidelabelprice"),
                                                                      
                                                                      array("type"=>"input","name"=>"txt_baggageinkg","label"=>"Baggage","required"=>"false","info"=>"true","inputWidth"=>"60","value"=>"0",
                                                                            "tooltip"=>"Insert Baggage first. Thank You","maxLength"=>"11","className"=>"txtright"),
                                                                      array("type"=>"newColumn"),
                                                                      array("type"=>"label","name"=>"lblmeter","label"=>"Kg","className"=>"besidelabelbaggage"),
                                                                      array("type"=>"input","name"=>"txt_limitbaggage","label"=>"","required"=>"false","info"=>"true","inputWidth"=>"60","value"=>"80","note"=>array("text"=>"Limit (kg)"),
                                                                            "readonly"=>"true","tooltip"=>"Insert Price first. Thank You","validate"=>"","maxLength"=>"","className"=>"txtright besidebaggage"),
                                                                      array("type"=>"column"),
                                                                      array("type"=>"input","name"=>"txt_overlimitbaggage","label"=>"","info"=>"true","inputWidth"=>"73","value"=>"0","note"=>array("text"=>"Overload"),
                                                                            "tooltip"=>"Insert Over limit baggage first. Thank You","validate"=>"","maxLength"=>"","className"=>"txtright besidelimitbaggage"),
                                                                      array("type"=>"column"),
                                                                      array("type"=>"input","name"=>"txt_priceoverinkg","label"=>"","required"=>"false","info"=>"true","inputWidth"=>"90","value"=>"0","note"=>array("text"=>"Price (kg) in \$"),
                                                                            "tooltip"=>"Insert Price first. Thank You","validate"=>"","maxLength"=>"","className"=>"txtright besidelimitkgbaggage"),
                                                                      array("type"=>"input","name"=>"txt_pricebaggage","label"=>"Over Baggage","required"=>"false","info"=>"true","inputWidth"=>"90","value"=>"0",
                                                                            "tooltip"=>"Insert Over Price first / beri nilai 0. Thank You","maxLength"=>"","className"=>"txtright"),
                                                                      array("type"=>"column"),
                                                                      array("type"=>"label","name"=>"lblmeter","label"=>"\$","className"=>"besidelabelprice"),
                                                                      
                                                                      array("type"=>"input","name"=>"txt_totalprice","label"=>"Total","required"=>"true","info"=>"true","inputWidth"=>"90","value"=>"0",
                                                                            "tooltip"=>"Insert total first. Thank You","validate"=>"NotEmpty","maxLength"=>"11","className"=>"txtright txttotalbiaya"),
                                                                      array("type"=>"newColumn"),
                                                                      array("type"=>"label","name"=>"lblmeter","label"=>"\$","className"=>"besidelabelprice"),
                                                                      
                                                                      array("type"=>"button","name"=>"btnsave","value"=>"Save","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","divnewticketnew",$formdata);
                            echo "myForm.setFontSize('12pt');";

                            //==== Add Months
                            $arrval=array();
                            array_push($arrval,array("value"=>"","text"=>""));
                            for($i=1;$i<=12;$i++)
                            {
                                $monthname=$this->FN_GETMONTHNAME($i);
                                array_push($arrval,array("value"=>$i,"text"=>$monthname));
                            }
                            $this->FN_COMBOVALIDATIONVALUEARRAY("myForm","cbo_bodmonth",$arrval);
                            
                            $arrval=array();
                            array_push($arrval,array("value"=>"","text"=>""));
                            for($i=1;$i<=31;$i++)
                            {
                                array_push($arrval,array("value"=>$i,"text"=>"$i"));
                            }
                            $this->FN_COMBOVALIDATIONVALUEARRAY("myForm","cbo_bodday",$arrval);

                            $mycontainerpic="var divpicture=document.createElement('DIV');";
                            $mycontainerpic.="divpicture.id='divpicture';divpicture.style.height='100%';";
                            $mycontainerpic.="var divpicturecontent='<table id=\"tbfindinvoice\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" style=\"margin-top:0px;margin-left:-5px;\">';";
                            $mycontainerpic.="divpicturecontent=divpicturecontent+'<tbody>';";
                            $mycontainerpic.="divpicturecontent=divpicturecontent+'    <tr>';";
                            $mycontainerpic.="divpicturecontent=divpicturecontent+'        <td>';";
                            $mycontainerpic.="divpicturecontent=divpicturecontent+'            <div id=\"divimage\" style=\"height:180px;width:280px;background-color:#2c3e50;margin-left:5px;\">';";
                            $mycontainerpic.="divpicturecontent=divpicturecontent+'                <image id=\"imgtiket\" style=\"height:180px;width:280px;\" />';";
                            $mycontainerpic.="divpicturecontent=divpicturecontent+'            </div>';";
                            $mycontainerpic.="divpicturecontent=divpicturecontent+'            <div style=\"position:absolute;z-index:100;margin-top:-50px;margin-left:10px\">';";
                            $mycontainerpic.="divpicturecontent=divpicturecontent+'                <button id=\"btntake\" onClick=\"fn_showCamera()\"><i class=\"fa fa-camera\" style=\"font-size:30pt\"></i></button>';";
                            $mycontainerpic.="divpicturecontent=divpicturecontent+'            </div>';";                                                            
                            $mycontainerpic.="divpicturecontent=divpicturecontent+'        </td>';";
                            $mycontainerpic.="divpicturecontent=divpicturecontent+'    </tr>';";
                            $mycontainerpic.="divpicturecontent=divpicturecontent+'</tbody>';";
                            $mycontainerpic.="divpicturecontent=divpicturecontent+'</table>';";

                            $mycontainerpic.="divpicture.innerHTML=divpicturecontent;";
                            $mycontainerpic.="myForm.getContainer('containerpicture').appendChild(divpicture);";
                            //$mycontainerpic.="myForm.setItemValue('txtsearch',objidposition);";

                            //echo $mycontainerpic;
                           
                            $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","");

                            $urlcbo="fn_dhtmlxloadobject('".$this->enc("obj_controller")."','obj=".$this->enc("-")."&task=".$this->enc("dhtmlxcbofilter")."&tableobj=tbl_gender|id,gender')";
                            $this->FN_COMBOVALIDATIONVALUENEW("myForm","cbo_idgender","tbl_gender","$urlcbo","");

                            $urlcbo="fn_dhtmlxloadobject('".$this->enc("obj_controller")."','obj=".$this->enc("-")."&task=".$this->enc("dhtmlxcbofilter")."&tableobj=tbl_passenger_identifycardtype|id,cardtype')";
                            $otherevent="var nationality='Timor Leste';";
                            $otherevent.="if(val==3){nationality='';}";
                            $otherevent.="myForm.setItemValue('txt_nationality',nationality);";
                            $this->FN_COMBOVALIDATIONVALUENEW("myForm","cbo_idcardtype","tbl_passenger_identifycardtype","$urlcbo","$otherevent");

                            $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","");

                            $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","");

                            $arrerror=array("cbo_idship"=>"Error Found : Please Insert <b>Ship Name</b> first. Thank You",
                                            "txt_tiketnumber"=>"Error Found : Please Insert <b>Ticket Number</b> first. Thank You",
                                            "txt_voynumber"=>"Error Found : Please Insert <b>Voyage Number</b> first. Thank You",
                                            //"txt_inctiket"=>"Error Found : Please Insert <b>No. Sequence</b> first. Thank You",
//                                            "txt_shipnumber"=>"Error Found : Please Insert <b>Ship Number</b> first. Thank You",
                                            "txt_passengername"=>"Error Found : Please Insert <b>Mrs/ Mr</b> first. Thank You",
                                            "cbo_idgender"=>"Error Found : Please Choice <b>Female / Male</b> First. Thank You",
                                            "txt_bod"=>"Error Found : Please Insert <b>Birth Of Date</b> First. Thank You",
                                            "txt_bodyears"=>"Error Found : Please Insert <b>Years of birthdate</b> First. Thank You",
                                            "cbo_bodmonth"=>"Error Found : Please Insert <b>Month of birthdate</b> First. Thank You",
                                            "cbo_bodday"=>"Error Found : Please Insert <b>day of birthdate</b> First. Thank You",
                                            "cbo_idcardtype"=>"Error Found : Please Insert identity Card first. Thank You",
                                            "txt_nationality"=>"Error Found : Please Insert Nationality first. Thank You",
                                            //"txt_picdata"=>"Error Found : Please Insert <b>Picture</b> first. Thank You",
                                            "txt_dates"=>"Error Found : Please Insert <b>Dates</b> first. Thank You",
                                            "cbo_idroutestart"=>"Error Found : Please Insert <b>From</b> first. Thank You",
                                            "cbo_idrouteend"=>"Error Found : Please Insert <b>To</b> first. Thank You",
                                            //"txt_seatnumber"=>"Error Found : Please Insert <b>Seat Number</b> first. Thank You",
                                            //"txt_quantity"=>"Error Found : Please Insert <b>Quantity</b> first. Thank You",
                                            "txt_timeschedule"=>"Error Found : Please Insert <b>Time</b> first. Thank You",
                                            "txt_price"=>"Error Found : Please Insert <b>Price</b> first. Thank You",
                                            "txt_baggageinkg"=>"Error Found : Please Insert <b>Baggage</b> first. Thank You",
                                            "txt_limitbaggage"=>"Error Found : Please Insert <b>Price</b> first. Thank You"
                                      );
                            $this->FN_DHTMLXFORMVALIDATIONERROR("myForm",$arrerror);

                            $arrayControls=array("txt_id"=>"","cbo_idship"=>"","txt_tiketnumber"=>"","txt_voynumber"=>"",
                                                 "txt_passengername"=>"","cbo_idgender"=>"","txt_bod"=>"","txt_bodyears"=>"",
                                                 "cbo_idcardtype"=>"","txt_nationality"=>"Timor Leste","txt_childspassenger"=>"",
                                                 "txt_cardnumber"=>"","txt_picdata"=>"aportildefault.png","txt_dates"=>date("Y-m-d"),"txt_price"=>0,
                                                 "txt_timeschedule"=>"00:00:00","txt_baggageinkg"=>0,"txt_limitbaggage"=>80,"txt_overlimitbaggage"=>0,
                                                 "txt_priceoverinkg"=>0,"txt_pricebaggage"=>0,"txt_totalprice"=>0,"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;}";

                            // === Cbo Ship Change
                            $cboship="if(myForm.getItemValue('cbo_idship')!='')";
                            $cboship.="{";
                            $cboship.="   var sp=ajaxuridhtmlx('".$this->enc("obj_tra")."','obj=".$this->enc("tra_newticket")."&task=".$this->enc("getheaderinfo")."&idship='+myForm.getItemValue('cbo_idship')).split('|');";
                            $cboship.="   if(trim(sp[0])=='failed'){fn_dhtmlxmessage('error',sp[1]);".$this->FN_DHTMLXWINDOWSHIDEPROGRESS().";return false;}";
                            $cboship.="   var tiketnumber=sp[1];";
                            $cboship.="   myForm.setItemValue('txt_tiketnumber',tiketnumber);";
                            $cboship.="}";
                            $onkeypresscboshipname=$this->FN_DHTMLXWINDOWSHOWPROGESS($cboship);
                            $onkeypresscboshipname.=$this->FN_DHTMLXWINDOWSHIDEPROGRESS();

                            // === Cbo Route End Change
                            $onchangecboidrouteend="if(myForm.getItemValue('cbo_idrouteend')!='')";
                            $onchangecboidrouteend.="{";
                            //$onchangecboidrouteend.="   alert('f');";
                            $onchangecboidrouteend.="   var sp=ajaxuridhtmlx('".$this->enc("obj_tra")."','obj=".$this->enc("tra_newticket")."&task=".$this->enc("getprice")."&idroutestart='+myForm.getItemValue('cbo_idroutestart')+'&idrouteend='+myForm.getItemValue('cbo_idrouteend')).split('|');";
                            $onchangecboidrouteend.="   if(trim(sp[0])=='failed'){fn_dhtmlxmessage('error',sp[1]);".$this->FN_DHTMLXWINDOWSHIDEPROGRESS().";return false;}";
                            $onchangecboidrouteend.="   myForm.setItemValue('txt_price',sp[2]);";
                            $onchangecboidrouteend.="   myForm.setItemValue('txt_totalprice',sp[2]);";
                            $onchangecboidrouteend.="   myForm.setItemValue('txt_priceoverinkg',sp[3]);";
                            $onchangecboidrouteend.="   myForm.setItemValue('txt_timeschedule',sp[4]);";
                            $onchangecboidrouteend.="}";
                            
                            // === Text baggage Change
                            $onchangetxtbaggage="if(ev.keyCode==13)";
                            $onchangetxtbaggage.="{";
                            $onchangetxtbaggage.="    var baggage=parseInt(myForm.getItemValue('txt_baggageinkg'));";
                            $onchangetxtbaggage.="    var limitbaggage=parseInt(myForm.getItemValue('txt_limitbaggage'));";
                            $onchangetxtbaggage.="    var priceoverbaggage=0;";
                            $onchangetxtbaggage.="    myForm.setItemValue('txt_overlimitbaggage',0);";
                            $onchangetxtbaggage.="    if(baggage>limitbaggage)";
                            $onchangetxtbaggage.="    {";
                            $onchangetxtbaggage.="        var overbaggage=(myForm.getItemValue('txt_baggageinkg')-myForm.getItemValue('txt_limitbaggage')).toFixed(2);";
                            $onchangetxtbaggage.="        myForm.setItemValue('txt_overlimitbaggage',overbaggage);";
                            $onchangetxtbaggage.="        priceoverbaggage=parseInt(overbaggage)*myForm.getItemValue('txt_priceoverinkg');";
                            $onchangetxtbaggage.="    }";
                            $onchangetxtbaggage.="    myForm.setItemValue('txt_pricebaggage',priceoverbaggage);";
                            $onchangetxtbaggage.="    var totalbiaya=(parseFloat(myForm.getItemValue('txt_price')))+(parseFloat(myForm.getItemValue('txt_pricebaggage')));";
                            //$onchangetxtbaggage.="    alert(totalbiaya);";
                            $onchangetxtbaggage.="    myForm.setItemValue('txt_totalprice',totalbiaya.toFixed(2));";
                            $onchangetxtbaggage.="}";
                            
                            $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("tra_newticket")."&task=".$this->enc("saverecord")."'";
                                                                      $onformsenddata="url=fn_dhtmlxsenddata('".$this->enc("obj_tra")."',$params);
                                                                      myForm.send(url,\"get\",function(loader, response){";
                                                                          $onformsenddata.=$this->FN_DHTMLXWINDOWSHIDEPROGRESS();
                                                                          $onformsenddata.="var sp=trim(response).split('|');
                                                                          if(sp[0]=='ok')
                                                                          {
                                                                              fn_dhtmlxmessage('','Ticket Number <b>'+myForm.getItemValue('txt_tiketnumber')+'</b> has been saved');";
                                                                              //$onformsenddata.="document.getElementById('imgtiket').src='';";
                                                                              $onformsenddata.="fn_childspassengerdefault();";
                                                                              $onformsenddata.="fn_grid_loaddata();myForm.setItemFocus('cbo_idship');";
                                                                              $onformsenddata.="myForm.setItemValue('cbo_bodmonth','');myForm.setItemValue('cbo_bodday','');";
                                                                              $onformsenddata.=$this->FN_DHTMLXFORMCLEAR2("myForm",$arrayControls,"cbo_idship")."                                                                              
                                                                          }
                                                                          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("tra_newticket")."&task=".$this->enc("updrecord")."'";
                                                                   $onformsenddata="url=fn_dhtmlxsenddata('".$this->enc("obj_tra")."',$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('','Ticket Number <b>'+myForm.getItemValue('txt_tiketnumber')+'</b> has been update');";
                                                                           $onformsenddata.="fn_childspassengerdefault();";
                                                                           $onformsenddata.="myForm.enableItem('btnsave');";
                                                                           //$onformsenddata.="document.getElementById('imgtiket').src='';";
                                                                           $onformsenddata.="myForm.disableItem('btndelete');";
                                                                           $onformsenddata.="fn_grid_loaddata();";
                                                                           $onformsenddata.="myForm.enableItem('cbo_idship');";
                                                                           $onformsenddata.="myForm.enableItem('txt_tiketnumber');";
                                                                           //$onformsenddata.="myForm.disableItem('cbo_idship');";
//                                                                           $onformsenddata.="myForm.disableItem('txt_tiketnumber');";
                                                                           $onformsenddata.="myForm.setItemFocus('cbo_idship');";
                                                                           $onformsenddata.="myForm.disableItem('btnupdate');";
                                                                           $onformsenddata.="myForm.setItemValue('cbo_bodmonth','');myForm.setItemValue('cbo_bodday','');";
                                                                           $onformsenddata.=$this->FN_DHTMLXFORMCLEAR2("myForm",$arrayControls,"cbo_idship")."                                                                           
                                                                      }
                                                                      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,"cbo_idship");
                            $eventafterdeleted.="myForm.setItemValue('cbo_bodmonth','');myForm.setItemValue('cbo_bodday','');";
                            $eventafterdeleted.="myForm.enableItem('btnsave');";
                            $eventafterdeleted.="myForm.disableItem('btnupdate');";
                            $eventafterdeleted.="myForm.disableItem('btndelete');";
                            $eventafterdeleted.="fn_grid_loaddata();fn_childspassengerdefault();";
                            $onbuttonclickbtndeleted=$this->FN_DHTMLXREMARKFORDELETED2("obj_tra","tra_newticket","myForm.getItemValue('txt_id')","myForm.getItemValue('txt_tiketnumber')",$eventafterdeleted);

                            //$onbuttonclickbtncancel="document.getElementById('imgtiket').src='';";
                            $onbuttonclickbtncancel="myForm.enableItem('btnsave');";
                            $onbuttonclickbtncancel.="myForm.disableItem('btnupdate');";
                            $onbuttonclickbtncancel.="myForm.enableItem('cbo_idship');";
                            $onbuttonclickbtncancel.="myForm.enableItem('txt_tiketnumber');";
                            $onbuttonclickbtncancel.="myForm.disableItem('btndelete');";
                            $onbuttonclickbtncancel.="myForm.setItemFocus('cbo_idship');";
                            $onbuttonclickbtncancel.="fn_grid_loaddata();fn_childspassengerdefault();";
                            $onbuttonclickbtncancel.=$this->FN_DHTMLXFORMCLEAR2("myForm",$arrayControls);
                            $onbuttonclickbtncancel.="myForm.setItemValue('cbo_bodmonth','');myForm.setItemValue('cbo_bodday','');";
                            

                            
                            $arrevent=array(
                                                array("eventname"=>"onbuttonclick","eventparam"=>"id,val",
                                                          "switch"=>array(
                                                                            "btnbookseat"=>"fn_showBookingSeat()",
                                                                            "btnsave"=>"$onbuttonclickbtnsave",
                                                                            "btnupdate"=>"$onbuttonclickbtnupdt",
                                                                            "btndelete"=>"$onbuttonclickbtndeleted",
                                                                            "btncancel"=>"$onbuttonclickbtncancel"
                                                          )
                                                ),
                                                array("eventname"=>"onkeydown","eventparam"=>"inp,ev,id,val",
                                                          "switch"=>array(
                                                                            "txt_limitbaggage"=>"$onobjkeydown",
                                                                            "txt_baggageinkg"=>"$onchangetxtbaggage"
                                                          )
                                                ),
                                                array("eventname"=>"onchange","eventparam"=>"id,ev,val",
                                                          "switch"=>array(
                                                                            "cbo_idrouteend"=>"$onchangecboidrouteend $onchangetxtbaggage",
                                                                            
                                                          )
                                                )  

                            );


                            $this->FN_DHTMLXFORMEVENT("myForm",$arrevent);
                            echo "myForm.getCombo('cbo_idship').attachEvent('onKeyPressed',function(keycode){
                                      if(keycode==null){return false;}
                                      if(keycode==13){".$onkeypresscboshipname."}
                                  });";

                            // === 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","divnewticketsearch",$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"=>"dgnewticket","divtarget"=>"div_dgnewticket","divpaging"=>"div_dgnewticketpaging","paginglimit"=>PAGE_LIMIT,
                                           "showloader"=>"true");
                            $gridproperties=array("id"=>"right,ro,96,right,int,false,true",
                                                  "P.&nbsp;&nbsp;"=>"center,ro,35,center,str,false",
                                                  "No.&nbsp;"=>"right,ro,35,center,int,false",
                                                  "Ship Name"=>"left,ro,152,left,int,false",
                                                  "Ticket Number"=>"center,ro,194,center,str,false",
                                                  "No. Sequence&nbsp;"=>"right,ro,110,right,int,false",
                                                  "Ship Number"=>"left,ro,238,left,str,false",
                                                  "Mrs/ Mr"=>"left,ro,206,left,str,false",
                                                  "Picture"=>"left,ro,206,left,str,false,true",
                                                  "Dates"=>"center,ro,120,center,date,false",
                                                  "From"=>"center,ro,112,center,str,false",
                                                  "To"=>"center,ro,112,center,str,false",
                                                  "Nationality"=>"center,ro,120,center,str,false",
                                                  "Quantity&nbsp;"=>"right,ro,110,right,int,false",
                                                  "Price&nbsp;"=>"right,ro,120,right,int,false",
                                                  "Baggage&nbsp;"=>"right,ro,136,right,int,false",
                                                  "Price&nbsp;"=>"right,ro,120,right,int,false");
                            $this->FN_DHTMLXGRIDVIEW($grdinit,$gridproperties,"bricks","","fn_grid_loaddata()");
                            echo "dgnewticket.setStyle('font-size:14px','font-size:14px','');";

                            $arrfields=array("txt_id"=>"","cbo_idship"=>"idship|shipname","txt_tiketnumber"=>"","txt_inctiket"=>"","txt_shipnumber"=>"",
                                             "txt_passengername"=>"","cbo_idgender"=>"","txt_bod"=>"","cbo_idcardtype"=>"idcardtype|cardtype","txt_cardnumber"=>"",
                                             "txt_nationality"=>"","txt_voynumber"=>"","txt_picdata"=>"","txt_dates"=>"","cbo_idroutestart"=>"idroutestart|routenamestart",
                                             "cbo_idrouteend"=>"idrouteend|routenameend","txt_price"=>"","txt_baggageinkg"=>"","txt_limitbaggage"=>"","txt_overlimitbaggage"=>"",
                                             "txt_priceoverinkg"=>"","txt_pricebaggage"=>"","txt_totalprice"=>"","txt_modifcount"=>""
                            );
                            $otherevent="if(spres[23]>1)";
                            $otherevent.="{";
                            $otherevent.="    fn_dhtmlxmessage('error','I\'m sorry you cannot edit this record, only one for editing! or Cancel this request to your administrator');return false;";
                            $otherevent.="}";
                            $otherevent.="var bod=spres[7].toString().split('-');";
                            $otherevent.="var bodyears=bod[0];var bodmonth=bod[1];var bodday=bod[2];";
                            $otherevent.="var dates=spres[13].toString().split(' ');";
                            $otherevent.="myForm.setItemValue('txt_timeschedule',dates[1]);";
                            $otherevent.="myForm.setItemValue('txt_bodyears',bodyears);";
                            $otherevent.="myForm.setItemValue('cbo_bodmonth',bodmonth);";
                            $otherevent.="myForm.setItemValue('cbo_bodday',bodday.split(' ')[0]);";
                            $otherevent.="myForm.disableItem('cbo_idship');";
                            $otherevent.="myForm.disableItem('txt_tiketnumber');";
                            $otherevent.="myForm.setItemFocus('txt_voynumber');";
                            $otherevent.="var childspassenger=ajaxuridhtmlx('".$this->enc("obj_tra")."','obj=".$this->enc("tra_newticket")."&task=".$this->enc("getchilds")."&idtiketpassenger='+spres[0]);";
                            $otherevent.="if(trim(childspassenger)!=''){";
                            $otherevent.="  myForm.setItemValue('txt_childspassenger',childspassenger);fn_recalchilds();";
                            $otherevent.="}";
                            //$otherevent.="document.getElementById('imgtiket').src='uploads/temps/'+spres[11];";
                            $this->FN_DHTMLXGRIDVIEWTOFORMNEW("dgnewticket","myForm","tbl_passenger_tiket",0,$arrfields,"",$otherevent);


            echo "    }
                      
                      function fn_showchildren(){
                            // fn_dhtmlxmessage('error','Your module still underconstruction');return false;
                            var tiketnumber=myForm.getItemValue('txt_tiketnumber');
                            var childspassenger=myForm.getItemValue('txt_childspassenger');
                            if(!tiketnumber){
                                fn_dhtmlxmessage('error','Please Insert passenger first!');return false;                            
                            }
                            var url='?ajax=1&sec=1&option=".$this->enc("obj_tra")."&obj=".$this->enc("tra_newticketc")."&task=".$this->enc("default")."&tiketnumber='+tiketnumber+'&childspassenger='+childspassenger;
                            dwins=new dhtmlXWindows();
                            dwins.createWindow(\"winchild\",0,0,screen.width-500,screen.height-350);
                            dwins.window('winchild').progressOn();
                            dwins.window(\"winchild\").setText(\"Children Setting\");
                            dwins.window(\"winchild\").attachURL(url);
                            dwins.window('winchild').setModal(true);
                            dwins.window('winchild').progressOff();
                      }
                    
                      function fn_closechildren(data){
                            myForm.setItemValue('txt_childspassenger',data);
                            dwins.window('winchild').close();
                            fn_recalchilds();
                      }
                      
                      function fn_recalchilds(){
                            var datachilds=myForm.getItemValue('txt_childspassenger');
                            var sp=datachilds.split(';');
                            var labelchilds='<a id=\'achilds\' href=\'javascript:void(0)\' onClick=\'fn_showchildren()\'><span id=\'spchild\'>'+sp.length+'</span> Children</a>';
                            myForm.setItemLabel('lbllookuphist',labelchilds);
                            // console.log(document.getElementbyId('spchild'));
                            // document.getElementbyId('spchild').innerHTML = sp.length;
                      }
                      
                      function fn_printtraold(tiketnumber,idtransaction){
                         var sp=ajaxuridhtmlx('".$this->enc("obj_tra")."','obj=".$this->enc("tra_newticket")."&task=".$this->enc("printtra")."&idtransaction='+idtransaction+'&txt_tiketnumber='+tiketnumber).split('|');
                         //alert(sp);
                         //alert(sp[0]);
                         if(sp[0]=='ok'){
                            fn_dhtmlxmessage('','Tiket Number '+tiketnumber+' has been printed');
                         }
                      }                      
                      
                      function fn_printtra(tiketnumber,idtransaction){
                        if(!tiketnumber){
                            fn_dhtmlxmessage('error','Mohon maaf Nomor Tiket tidak terdaftar!');return false;
                        }
                        // alert(sepnumber);
                        var url='?ajax=1&sec=1&option=".$this->enc("obj_tra")."&obj=".$this->enc("tra_newticket")."&task=".$this->enc("printtra")."&idtransaction='+idtransaction+'&tiketnumber='+tiketnumber;
                        dwins=new dhtmlXWindows();
                        dwins.createWindow(\"winchild\",0,0,screen.width-400,screen.height-350);
                        dwins.window('winchild').progressOn();
                        dwins.window(\"winchild\").setText(\"PRINT TICKETING\");
                        dwins.window(\"winchild\").attachURL(url);
                        dwins.window('winchild').setModal(true);
                        dwins.window('winchild').progressOff();
                      }                     
                      
                      function fn_seattimelimit(){
                         var textm,texts;
                         if(ss==0){mm=mm-1;}
                         
                         textm='0000'+mm.toString();
                         textm=textm.substring(textm.length-2,textm.length);
                         texts='0000'+ss.toString();
                         texts=texts.substring(texts.length-2,texts.length);
                         
                         myForm.setItemLabel('lbllimitbook','Limit in 5 min = '+textm+':'+texts);
                         if(ss==0){ss=60;}
                         
                         if(mm<0&&ss==60){
                            myForm.setItemLabel('lbllimitbook','Limit in 5 min = 00:00');
                            clearTimeout(tbooking);
                         }
                         else
                         {
                            ss=ss-1;
                            if(myForm.getItemValue('txt_seatnumber')=='')
                            {
                                clearTimeout(tbooking);
                                myForm.setItemLabel('lbllimitbook','Limit Booking in 5 Minutes');
                          
                            }
                            else
                            {
                                setTimeout(function(){
                                    fn_seattimelimit();
                                },1000);  
                            }
                            
                            
                         }
                         
                      }
                      
                      function fn_showCamera()
                      {
                          dwins=new dhtmlXWindows();dwins.attachViewportTo(\"winVP\");
                          var picdata=myForm.getItemValue('txt_picdata');
                          var url='?ajax=1&sec=1&option=".$this->enc("obj_tra")."&obj=".$this->enc("tra_newticket")."&task=".$this->enc("getpic")."&picdata='+picdata;";
                          $url="?ajax=1&sec=1&option=".$this->enc("obj_tra")."&obj=".$this->enc("tra_newticket")."&task=".$this->enc("getpic");
                          $this->FN_DHTMLXWINDOWSURL("dwins","winpic","Get Picture","50","50","560","400",$url,false,true);
                          
            echo "    }

                      function fn_getPicName(filename){
                         myForm.setItemValue('txt_picdata',filename);
                         myForm.setItemFocus('txt_dates');
                         dwins.unload();
                         document.getElementById('imgtiket').src='uploads/temps/'+filename;                         
                      }
                      
                      function fn_childspassengerdefault(){
                           var datachilds='<a id=\'achilds\' href=\'javascript:void(0)\' onClick=\'fn_showchildren()\'><span id=\'spchild\'>0</span> Children</a>';
                           myForm.setItemLabel('lbllookuphist', datachilds);
                      }
                      
                      function fn_showBookingSeat()
                      {
                          dwins=new dhtmlXWindows();dwins.attachViewportTo(\"winVP\");
                          if(myForm.getItemValue('cbo_idship')==''){
                             fn_dhtmlxmessage('error','Please Insert your ship first!');
                             myForm.setItemFocus('cbo_idship');
                             return false;
                          }
                          if(myForm.getItemValue('cbo_idroutestart')==''){
                             fn_dhtmlxmessage('error','Please Insert your port arrival!');
                             myForm.setItemFocus('cbo_idroutestart');
                             return false; 
                          }
                          if(myForm.getItemValue('cbo_idrouteend')==''){
                             fn_dhtmlxmessage('error','Please Insert your port destination!');
                             myForm.setItemFocus('cbo_idrouteend');
                             return false; 
                          }
                          
                          var url='?ajax=1&sec=1&option=".$this->enc("obj_tra")."&obj=".$this->enc("tra_newticket")."&task=".$this->enc("getseatnum")."&bookingdate='+myForm.getCalendar('txt_dates').getDate(true);
                              url=url+'&idship='+myForm.getItemValue('cbo_idship')+'&shipname='+myForm.getCombo('cbo_idship').getComboText()+'&seatnumber='+myForm.getItemValue('txt_seatnumber');
                              url=url+'&idroutestart='+myForm.getItemValue('cbo_idroutestart')+'&idrouteend='+myForm.getItemValue('cbo_idrouteend')+'&routestart='+myForm.getCombo('cbo_idroutestart').getComboText();
                              url=url+'&routeend='+myForm.getCombo('cbo_idrouteend').getComboText();";
                          //$url="?ajax=1&sec=1&option=".$this->enc("obj_tra")."&obj=".$this->enc("tra_newticket")."&task=".$this->enc("getseatnum");
                          //$this->FN_DHTMLXWINDOWSURL("dwins","winpic","Booking Seat Number","0","0","580","650",$url,false,true);
                          $rtn="dwins.createWindow(\"winbook\",0,0,580,650);";
                          $rtn.="dwins.window('winbook').denyResize();";
                          $rtn.="dwins.window('winbook').progressOn();";
                          $rtn.="dwins.window(\"winbook\").setText(\"Booking Seat Number\");";
                          $rtn.="dwins.window(\"winbook\").attachURL(url);";
                          $rtn.="dwins.window('winbook').setModal(true);";
                          $rtn.="dwins.window('winbook').progressOff();";
                          echo $rtn;
                          
            echo "    }
                      
                      function fn_cancelbookseat(){
                          myForm.setItemValue('txt_seatnumber','');
                          clearTimeout(tbooking);
                          myForm.setItemLabel('lbllimitbook','Limit Booking in 5 Minutes');
                          mm=5;ss=0;
                          setTimeout(function(){
                            dwins.unload();                            
                          },400);
                          
                      }
                      
                      function fn_getbookseat(seatnumber){
                         //alert(seatnumber);
                         myForm.setItemValue('txt_seatnumber',seatnumber);
                         dwins.unload();
                         
                         tbooking=setTimeout(function(){
                            fn_seattimelimit();
                         },1000);
                      }
                      
                        
                      function fn_grid_loaddata()
                      {
                          var keyword=myFormsearch.getItemValue('txtsearch');
                          url=fn_dhtmlxloadobject('".$this->enc("obj_tra")."','obj=".$this->enc("tra_newticket")."&task=".$this->enc("grdrecord")."&keyword='+keyword);
                          dgnewticket.clearAndLoad(url);";
            echo "    }
            
                   </script>";
            echo $this->FN_CLOSEHEADER();
            echo $this->FN_CREATEBODY("e8f1ff");

            
            echo "<div id=\"winVP\" style=\"height:1020px;\">";
            echo "<table width=\"98%\" border=\"0\">
                      <tr>
                          <td>";
                              $qry="select filepdf from ".DB_APORTIL.".tbl_manualbook where isdeleted=0 and filepdf='passengerbooking_ticket.pdf'";
                              $filepdf=$this->fn_get_fieldvalue("filepdf",$qry);  
                              $urlmanualbook="<a href='".UPLOAD_DIR."/manualbook/$filepdf"."' target='_blank'><img src='".PATH_THEME."/images/pdf.png' />&nbsp;<b>MANUAL BOOK</b></a>";
                              $url="location.reload();";
                              $myuri=array("<b>PASSENGER INFORMATION</b>"=>"$url|id='a_newticket'","$urlmanualbook"=>"|id='a_manualbook'");
                              echo $this->MULTIPLE_LINK($myuri);
            echo "       </td>
                      </tr>
                      <tr>
                          <td>
                              <div id=\"divnewticketcontent\" style=\"margin-left:0px;\">
                                  <table width=\"98%\" border=\"0\">
                                      <tr>
                                          <td width=\"45%\" valign=\"top\">
                                              <div id=\"divnewticketnew\" style=\"\"></div>
                                          </td>
                                          <td valign=\"top\">
                                              <table width=\"98%\" cellpadding=\"0\" cellspacing=\"0\">
                                                  <tr>
                                                      <td valign=\"top\">
                                                          <div id=\"divnewticketsearch\" style=\"width:560px;margin-top:-6px;\"></div>
                                                      </td>
                                                  </tr>
                                                  <tr>
                                                      <td>
                                                          <div id=\"div_dgnewticket\" style=\"height:380px;width:580px;overflow:hidden\"></div>
                                                      </td>
                                                  </tr>
                                                  <tr>
                                                      <td>
                                                          <div id=\"div_dgnewticketpaging\" style=\"width:598px;margin-top:1px\"></div>
                                                      </td>
                                                  </tr>
                                                  <tr><td valign=\"top\"><div id=\"loadergrid\" style=\"z-index:100;position:absolute;margin-top:-220px;margin-left:287px;display:visibility;\">".$this->CREATE_IMAGE("loadergrid.gif")."</div></td></tr>
                                                  <tr>
                                                      <td valign=\"top\">
                                                          <table>
                                                              <tr>
                                                                  <td style='color:red;font-weight:bold;'>Notes</td>
                                                                  <td>:</td>
                                                                  <td>- Click Row For Edit</td>
                                                              </tr>
                                                          </table>
                                                      </td>
                                                  </tr>
                                              </table>
                                          </td>
                                      </tr>
                                  </table>
                              </div>
                          </td>
                      </tr>
                  </table>
                  </div>";
            echo $this->FN_CREATEFOOTER();

        }

        public function fn_grdrecord()
        {
            $keyword=$_REQUEST["keyword"];
            header("Content-type: text/xml");
            echo('<?xml version="1.0" encoding="utf-8"?>');
            echo "<rows id='0'>";

            $qry="select id,idship,tiketnumber,inctiket,shipname,shipnumber,passengername,picdata,dates,idroutestart,nationality,
                         routenamestart,idrouteend,routenameend,seatnumber,quantity,price,baggageinkg,pricebaggage,modifcount
                  from ".DB_APORTIL.".tbl_passenger_tiket
                  where (tiketnumber like '%$keyword%' or passengername like '%$keyword%') and isdeleted=0 and status=0 and iby='".$_SESSION['nik']."'
                  order by id desc limit ".TBL_PAGE_LIMIT;

            $rs=$this->selectquery($qry);
            if($rs)
            {
               $i=1;
               while($row=$this->data_row_array($rs))
               {
                   $color='black';
                   if($row["modifcount"]>=2){$color='grey';}
                  echo ("<row id='".$row["id"]."'>");
                        //$print="&lt;a href=\"javascript:void(0)\" title=\"Reprint Ticket Number ".$row["tiketnumber"]."\" style=\"text-decoration:none\" onClick=\"fn_printso('".$row["id"]."')\"/&gt;";
                        $print="&lt;a href=\"javascript:void(0)\" title=\"Reprint Ticket Number ".$row["tiketnumber"]."\" style=\"text-decoration:none\" onClick=\"fn_printtra('".$row['tiketnumber']."','".$row['id']."')\"/&gt;";
                        $print.="&lt;img src='themes/images/print.gif' /&gt;";
                        $print.="&lt;a/&gt;";
                        print("<cell><![CDATA[".$row["id"]."]]></cell>");
                        print("<cell>$print</cell>");
                        print("<cell><![CDATA["."<span style='color:$color'>".$i."</span>"."]]></cell>");
                        print("<cell><![CDATA["."<span style='color:$color'>".$row["shipname"]."</span>"."]]></cell>");
                        print("<cell><![CDATA["."<span style='color:$color'>".$row["tiketnumber"]."</span>"."]]></cell>");
                        print("<cell><![CDATA["."<span style='color:$color'>".$row["inctiket"]."</span>"."]]></cell>");
                        print("<cell><![CDATA["."<span style='color:$color'>".$row["shipnumber"]."</span>"."]]></cell>");
                        print("<cell><![CDATA["."<span style='color:$color'>".$row["passengername"]."</span>"."]]></cell>");
                        print("<cell><![CDATA["."<span style='color:$color'>".$row["picdata"]."</span>"."]]></cell>");
                        print("<cell><![CDATA["."<span style='color:$color'>".date("Y-m-d H:i:s",strtotime($row["dates"]))."</span>"."]]></cell>");
                        print("<cell><![CDATA["."<span style='color:$color'>".$row["routenamestart"]."</span>"."]]></cell>");
                        print("<cell><![CDATA["."<span style='color:$color'>".$row["routenameend"]."</span>"."]]></cell>");
                        print("<cell><![CDATA["."<span style='color:$color'>".$row["nationality"]."</span>"."]]></cell>");
                        print("<cell><![CDATA["."<span style='color:$color'>".$row["quantity"]."</span>"."]]></cell>");
                        print("<cell><![CDATA["."<span style='color:$color'>"."\$".$row["price"]."</span>"."]]></cell>");
                        print("<cell><![CDATA["."<span style='color:$color'>".$row["baggageinkg"]." kg"."</span>"."]]></cell>");
                        print("<cell><![CDATA["."<span style='color:$color'>"."\$".$row["pricebaggage"]."</span>"."]]></cell>");
                  echo ("</row>");
                  $i+=1;
               }
            }
            else
            {
                //   echo mysql_errno().": ".mysql_error()." at ".__LINE__." line in ".__FILE__." file<br>";
                  echo "error at ".__LINE__." line in ".__FILE__." file<br>";
            }
            echo "</rows>";

        }

        public function fn_saverecord($isupdate=null)
        {
            $year=date("Y");
            if($isupdate){$id=$_REQUEST['txt_id'];}
            $ipprintclient=$this->get_client_ip();
            $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];            
            $tiketnumber=$_REQUEST['txt_tiketnumber'];
            $childspassenger=$_REQUEST['txt_childspassenger'];
            $voynumber=$_REQUEST['txt_voynumber'];
            $passengername=$_REQUEST['txt_passengername'];
            $idgender=$_REQUEST['cbo_idgender'];
            $gender=$this->fn_get_fieldvalue("gender","select gender from ".DB_APORTIL.".tbl_gender where id='$idgender'");
            $bod=$_REQUEST['txt_bod'];
            $bodyears=$_REQUEST['txt_bodyears'];
            $bodmonth=$_REQUEST['cbo_bodmonth'];
            $bodday=$_REQUEST['cbo_bodday'];
            $bod=$bodyears."-".$bodmonth."-".$bodday;
            $idcardtype=$_REQUEST['cbo_idcardtype'];
            $cardtype=$this->fn_get_fieldvalue("cardtype","select cardtype from ".DB_APORTIL.".tbl_passenger_identifycardtype where id='$idcardtype'");
            $cardnumber=$_REQUEST['txt_cardnumber'];
            $nationality=$_REQUEST['txt_nationality'];
            $picdata="aportildefault.png";//$_REQUEST['txt_picdata'];
            $dates=$_REQUEST['txt_dates'];
            $timeschedule=$_REQUEST['txt_timeschedule'];
            $dates.=" ".$timeschedule;
            $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'");
            $spseat=explode("|",$this->fn_getseatnumber());
            $seatnumber=$spseat[1];
            //$seatnumber=$this->fn_getseatnumber();
            //echo "failed|".$spseat[0]." ".$spseat[1];
            //return false;
            if((int)$spseat[1]>(int)$spseat[0]){
                echo "failed|Total Seat Exceded only ".$spseat[0]." Available";
                return false;    
            }
            
            $inctiket=0;$inctiketyear=0;
            if(!$isupdate){
                $qry="select count(id) incnumber from ".DB_APORTIL.".tbl_passenger_tiket 
                      where isdeleted=0 and years='$year' and status>=0";
                $inctiketyear=$this->fn_get_fieldvalue("incnumber",$qry);            
                $inctiketyear+=1;
                
                $qry="select count(id) incnumber from ".DB_APORTIL.".tbl_passenger_tiket 
                      where idship='$idship' and isdeleted=0 and cast(dates as date)=cast(now() as date) and idroutestart='$idroutestart' and idrouteend='$idrouteend' and status>=0";
                $inctiket=$this->fn_get_fieldvalue("incnumber",$qry);            
                $inctiket+=1;
            }
            $quantity=$_REQUEST['txt_quantity'];
            $price=$_REQUEST['txt_price'];
            $baggageinkg=$_REQUEST['txt_baggageinkg'];
            $limitbaggage=$_REQUEST['txt_limitbaggage'];
            $overlimitbaggage=$_REQUEST['txt_overlimitbaggage'];
            $priceoverinkg=$_REQUEST['txt_priceoverinkg'];
            $pricebaggage=$_REQUEST['txt_pricebaggage'];
            $totalprice=$_REQUEST['txt_totalprice'];
            
            $qry="insert into ".DB_APORTIL.".tbl_passenger_tiket 
                  set idship='$idship',tiketnumber='$tiketnumber',voynumber='$voynumber',inctiket='$inctiket',inctiketyear='$inctiketyear',shipname='$shipname',shipnumber='$shipnumber',passengername='$passengername',
                      bod='$bod',idgender='$idgender',gender='$gender',idcardtype='$idcardtype',cardtype='$cardtype',cardnumber='$cardnumber',nationality='$nationality',picdata='$picdata',dates='$dates',idroutestart='$idroutestart',
                      routenamestart='$routenamestart',idrouteend='$idrouteend',routenameend='$routenameend',seatnumber='$seatnumber',quantity='1',price='$price',baggageinkg='$baggageinkg',
                      limitbaggage='$limitbaggage',overlimitbaggage='$overlimitbaggage',priceoverinkg='$priceoverinkg',pricebaggage='$pricebaggage',totalprice='$totalprice',years='$year',ipclient='$ipprintclient',
                      modifcount=0,status=0,iby='".$_SESSION['nik']."',idt=now()";
            if($isupdate)
            {
                $qry="update ".DB_APORTIL.".tbl_passenger_tiket
                      set idship='$idship',tiketnumber='$tiketnumber',voynumber='$voynumber',shipname='$shipname',shipnumber='$shipnumber',passengername='$passengername',
                          bod='$bod',idgender='$idgender',gender='$gender',idcardtype='$idcardtype',cardtype='$cardtype',cardnumber='$cardnumber',nationality='$nationality',
                          picdata='$picdata',dates='$dates',idroutestart='$idroutestart',routenamestart='$routenamestart',idrouteend='$idrouteend',
                          routenameend='$routenameend',quantity='1',price='$price',baggageinkg='$baggageinkg',limitbaggage='$limitbaggage',overlimitbaggage='$overlimitbaggage',
                          priceoverinkg='$priceoverinkg',pricebaggage='$pricebaggage',totalprice='$totalprice',years='$year',modifcount=modifcount+1,ipclient='$ipprintclient',uby='".$_SESSION['nik']."',udt=now()
                      where id='$id'";
            }

            if($this->executequery($qry))
            {
                if(!$id){$id=mysql_insert_id();}
                // === Childs passenger
                if($childspassenger){
                    $spchilds=explode(";", $childspassenger);
                    for($j=0;$j<count($spchilds);$j++){
                        $spdata=explode("|", $spchilds[$j]);
                        $idchilds=$spdata[0];
                        $names=$spdata[1];
                        $birthofdate=$spdata[2];
                        $ages=$spdata[3];
                        $notes=$spdata[4];
                        $qryins="insert into ".DB_APORTIL.".tbl_passenger_childs 
                                 set idtiketpassenger='$id',tiketnumber='$tiketnumber',names='$names',birthofdate='$birthofdate',
                                     ages='$ages',notes='$notes',iby='".$_SESSION['nik']."',idt=now()";
                        if($this->fn_row_isexists("select id from ".DB_APORTIL.".tbl_passenger_childs where id='$idchilds' order by id asc limit 1")){
                            $qryins="update ".DB_APORTIL.".tbl_passenger_childs 
                                     set names='$names',birthofdate='$birthofdate',ages='$ages',notes='$notes',
                                         uby='".$_SESSION['nik']."',udt=now()
                                     where id='$idchilds'";
                        }
                        $this->executequery($qryins);
                    }
                }
                
                if(!$isupdate){
                    // $idpassengerticket=mysql_insert_id();
                    // $qry="insert into ".DB_APORTIL.".tbl_passenger_tiket_log 
                    //       set idpassengerticket='$idpassengerticket',dates='".date("Y-m-d")."',status=0,remarkstatus='Submitted',
                    //           iby='".$_SESSION['nik']."',idt=now()";
                    // if($this->executequery($qry)){
                        
                        // $rtn=$this->fn_printtra($idpassengerticket);
                        echo 'ok|';
                    // }
                }
                else
                {
                    echo "ok|";return true;    
                }
                
            }
        }

        public function fn_updrecord(){$this->fn_saverecord(true);}

        public function fn_delrecord()
        {
            $id=$_REQUEST['txt_id'];
            $remark=$_REQUEST['txtremark'];
            $qry="update ".DB_APORTIL.".tbl_passenger_tiket
                  set isdeleted=1,remark='$remark',dby='".$_SESSION['nik']."',ddt=now()
                  where id='$id'";
            if($this->executequery($qry)){echo "ok|";return true;}
            else
            {
              echo "failed|".$this->getErrorQuery();
            }
        }

        public function fn_getchilds(){
            $idtiketpassenger=$_REQUEST['idtiketpassenger'];
            $qry="select * from ".DB_APORTIL.".tbl_passenger_childs where idtiketpassenger='$idtiketpassenger' and isdeleted=0 order by id asc";
            $rs=$this->selectquery($qry);
            if($rs)
            {
                $i=1;$data="";
                while($row=$this->data_row_array($rs))
                {
                    $id=$row['id'];
                    $names=$row['names'];
                    $birthofdate=$row['birthofdate'];
                    $ages=$row['ages'];
                    $notes=$row['notes'];
                    $data.=$id."|".$names."|".$birthofdate."|".$ages."|".$notes.";";
                    $i+=1;
                }
                if($data){
                    $data=substr($data,0,strlen($data)-1);
                    
                }
                echo $data;
            }
        }

        public function fn_printtra($idtransaction=''){
            date_default_timezone_set("Asia/Bangkok");
            include("lib/mpdf/mpdf.php");        
            $top=10;
            // $mpdf = new mPDF('c', 'A4', '', '', 5, 5, $top, 10, 3, 3, 'P');
            $mpdf = new mPDF('utf-8', array(200,100) ,'', '', 2, 2, 2);
            $mpdf->SetDisplayMode('fullpage');
            $tiketnumber=$_REQUEST['tiketnumber'];
            
            // LOAD a stylesheet
            $stylesheet = file_get_contents('lib/mpdf/css/mpdfstyleA4.css');

            $html="<div style=\"position: fixed; left: 0mm; middle: -100mm; rotate: -90;\">";
            // $html.="    <div style=\"font-size:12pt;font-weight:bold\">".str_repeat("&nbsp;",6)."$tiketnumber</div>";
            // $html.="    <div><barcode code=\"$tiketnumber\" type=\"C39\" class=\"barcode\" size=\"1.2\"/></div>";
            $html.="     TICKET ".$rw['shipname'];
            $html.="</div>";
            
            $qry="select * from ".DB_APORTIL.".tbl_passenger_tiket where id='".$_REQUEST['idtransaction']."' and isdeleted=0";
            $rs=$this->selectquery($qry);
            $rw=$this->data_row_array($rs);
            $html.="<table width=\"80%\" style=\"margin-left:30px;padding-top:6px\" align=\"center\" border=\"0\">";
            $html.="<tr><td colspan=\"6\">";        
            $html.="    <div style=\"font-size:12pt;font-weight:bold\">".str_repeat("&nbsp;",6)."$tiketnumber</div>";
            $html.="    <div><barcode code=\"$tiketnumber\" type=\"C39\" class=\"barcode\" size=\"1.8\"/></div>";
            // $html.="     <td style=\"font-size:12pt\" colspan=\"6\">TICKET ".$rw['shipname']."</td>";
            $html.="</td></tr>";
            $html.="<tr>";        
            $html.="     <td style=\"font-size:10pt;padding-top:10px\" width=\"110\">Nome</td>";
            $html.="     <td style=\"font-size:10pt;padding-top:10px\" width=\"2\">:</td>";
            $html.="     <td style=\"font-size:10pt;padding-top:10px\">".$rw['passengername']."</td>";
            $html.="     <td style=\"font-size:10pt;padding-top:10px\"></td>";
            $html.="     <td style=\"font-size:10pt;padding-top:10px\"></td>";
            $html.="     <td style=\"font-size:10pt;padding-top:10px\"></td>";
            $html.="</tr>";
            $html.="<tr>";        
            $html.="     <td style=\"font-size:10pt;padding-top:10px\" width=\"110\">Voy</td>";
            $html.="     <td style=\"font-size:10pt;padding-top:10px\" width=\"2\">:</td>";
            $html.="     <td style=\"font-size:10pt;padding-top:10px\">".$rw['voynumber']."</td>";

            $html.="     <td style=\"font-size:10pt;padding-top:10px\" width=\"110\">Destino</td>";
            $html.="     <td style=\"font-size:10pt;padding-top:10px\" width=\"2\">:</td>";
                        $destination=$rw['routenamestart']."-".$rw['routenameend'];
            $html.="     <td style=\"font-size:10pt;padding-top:10px\">".$destination."</td>";
            
            $html.="</tr>";
            $html.="<tr>";        
            $html.="     <td style=\"font-size:10pt;padding-top:10px\" width=\"110\">Data</td>";
            $html.="     <td style=\"font-size:10pt;padding-top:10px\" width=\"2\">:</td>";
            $html.="     <td style=\"font-size:10pt;padding-top:10px\">".date("d/m/Y H:i:s a",strtotime($rw['dates']))."</td>";
            $html.="     <td style=\"font-size:10pt;padding-top:10px\" width=\"110\">No. Cadeira</td>";
            $html.="     <td style=\"font-size:10pt;padding-top:10px\" width=\"2\">:</td>";
            $html.="     <td style=\"font-size:10pt;padding-top:10px\">".$rw['seatnumber']."</td>";
            
            $html.="</tr>";
            $html.="<tr>";        
            $html.="     <td style=\"font-size:10pt;padding-top:10px\" width=\"110\">Preco</td>";
            $html.="     <td style=\"font-size:10pt;padding-top:10px\" width=\"2\">:</td>";
            $html.="     <td style=\"font-size:10pt;padding-top:10px\">US$ ".$rw['totalprice']."</td>";
            $html.="     <td style=\"font-size:10pt;padding-top:10px\"></td>";
            $html.="     <td style=\"font-size:10pt;padding-top:10px\"></td>";
            $html.="     <td style=\"font-size:10pt;padding-top:10px\"></td>";
            
            $html.="</tr>";
            $html.="<tr>";
            $html.="    <td colspan=\"6\" align=\"center\" style=\"padding-top:0\">-- BOARDING PASS --</td>";
            $html.="</tr>";
            $html.="<tr>";
            $html.="    <td colspan=\"6\" align=\"left\" style=\"padding-top:0\">Nota  : O bilhete que já foram comprados não podem ser cancelados</td>";
            $html.="</tr>";
            $html.="</table>";


            $mpdf->WriteHTML($html);

            // $secureofletter=$this->enc("ticket_".$tiketnumber."_".date("His"));
            // $mpdf->setFooter('{PAGENO} of {nbpg} pages || Secure ID : '.$secureofletter) ;

            $mpdf->output();
        }

        public function fn_printtraold($idtransaction='')
        {
            $tiketnumber=$_REQUEST['txt_tiketnumber'];
            if(!$idtransaction){
                $idtransaction=$_REQUEST['idtransaction'];
            }
            $ipprintclient=$this->get_client_ip();
            $qry="insert into ".DB_APORTIL.".tbl_printjob 
                  set idtransaction='$idtransaction',ipprintclient='$ipprintclient',idemployee='".$_SESSION['idemployee']."',nik='".$_SESSION['nik']."',
                      employeename='".$_SESSION['employeename']."',jobgroup='TIC',jobremark='$tiketnumber',iby='".$_SESSION['nik']."',idt=now()";
            $qrychk="select id from ".DB_APORTIL.".tbl_printjob where ipprintclient='$ipprintclient' order by id desc limit 1";
            //echo $qry;
            if($this->fn_row_isexists($qrychk))
            {
                $id=$this->fn_get_fieldvalue("id",$qrychk);
                $qry="update ".DB_APORTIL.".tbl_printjob 
                      set idtransaction='$idtransaction',ipprintclient='$ipprintclient',idemployee='".$_SESSION['idemployee']."',nik='".$_SESSION['nik']."',
                          employeename='".$_SESSION['employeename']."',jobgroup='TIC',jobremark='$tiketnumber',uby='".$_SESSION['nik']."',udt=now()
                      where id='$id'";
            }
            
            $rtn="failed|Print Tiket $tiketnumber failed, please contact your administrator. Thank you";
            if($this->executequery($qry))
            {
                $qry="update ".DB_APORTIL.".tbl_passenger_tiket set isprint=1,printeddate=now() where id='$idtransaction'";
                if($this->executequery($qry)){
                    $rtn="ok|";    
                }
                
            }
            echo $rtn;
            return $rtn;
        }

                
        public function fn_getseatnumber(){
            $idship=$_REQUEST['cbo_idship'];
            $dates=$_REQUEST['txt_dates'];
            $idroutestart=$_REQUEST['cbo_idroutestart'];
            $idrouteend=$_REQUEST['cbo_idrouteend'];
            
            $qry="select totalseat from ".DB_APORTIL.".tbl_ship_information where id='$idship'";
            $totalseat=$this->fn_get_fieldvalue("totalseat",$qry);
            $qry="select count(id) total from ".DB_APORTIL.".tbl_passenger_tiket ";
            $qry.="where idship='$idship' and idroutestart='$idroutestart' and idrouteend='$idrouteend' ";
            $qry.="and cast(dates as date)=cast('$dates' as date) and isdeleted=0 ";
            
            $lasttiket=0;
            if($this->fn_row_isexists($qry))
            {
                $lasttiket=$this->fn_get_fieldvalue("total",$qry);    
            }
            $lasttiket+=1;
            
            return $totalseat."|".$lasttiket;
        }
        
        public function fn_getticket(){
            // $valticket="";
            // for($i=1;$i<=8;$i++){
            //     $valticket.=rand(0,9);
            // }
            $valticket=date("YmdHis");
            $sql="select tiketnumber from ".DB_APORTIL.".tbl_passenger_tiket where tiketnumber='".$valticket."' order by id desc limit 1";
            if($this->fn_row_isexists($sql)){
                $this->fn_getticket();   
            }
            return $valticket;
        }
        public function fn_getheaderinfo(){
            $idship=$_REQUEST['idship'];
            $tiketnumber=$this->fn_getticket();
            echo "ok|".$tiketnumber;
        }
        
        public function fn_getprice(){
            $idroutestart=$_REQUEST['idroutestart'];
            $idrouteend=$_REQUEST['idrouteend'];
            $qry="select prices from ".DB_APORTIL.".tbl_price_information 
                  where idroutestart='".$idroutestart."' and idrouteend='".$idrouteend."' and isdeleted=0
                  order by id desc limit 1";
            //echo "failed|".$qry;
            $price=0;$status="failed";$statuserr="Price not Found, Please contact your administrator";
            if($this->fn_row_isexists($qry)){
                $price=$this->fn_get_fieldvalue("prices",$qry);
                $status="ok";$statuserr="";
            }
            // === Price limit baggage
            $qry="select prices from ".DB_APORTIL.".tbl_cargoprice_information 
                  where idcategory=2 and idroutestart='$idroutestart' and idrouteend='$idrouteend' and isdeleted=0
                  order by id desc limit 1";
            $pricebaggagelimit=0;
            if($this->fn_row_isexists($qry)){
                $pricebaggagelimit=$this->fn_get_fieldvalue("prices",$qry);
            }
            // ==== Get Time Schedule
            $qry="select scheduletime from ".DB_APORTIL.".tbl_routetime_information 
                  where idroutestart='$idroutestart' and idrouteend='$idrouteend' and isdeleted=0
                  order by id desc limit 1";
            $timeschedule="";
            if($this->fn_row_isexists($qry)){
                $timeschedule=$this->fn_get_fieldvalue("scheduletime",$qry);
            }
            echo "$status|$statuserr|$price|$pricebaggagelimit|$timeschedule";
        }
        
        public function fn_setbookseat(){
            $idship=$_REQUEST['idship'];
            $bookingdate=$_REQUEST['bookingdate'];
            $spship=$this->fn_get_fieldsvalues("shipnumber,shipname","select shipnumber,shipname from ".DB_APORTIL.".tbl_ship_information where id='$idship'");
            $shipnumber=$spship[0];$shipname=$spship[1];
            $seatnumber=$_REQUEST['seatnumber'];
            $idroutestart=$_REQUEST['idroutestart'];
            $routestart=$this->fn_get_fieldvalue("routename","select routename from ".DB_APORTIL.".tbl_route_information where id='$idroutestart'");
            $idrouteend=$_REQUEST['idrouteend'];
            $routeend=$this->fn_get_fieldvalue("routename","select routename from ".DB_APORTIL.".tbl_route_information where id='$idrouteend'");
            $bookingdateend=date("Y-m-d H:i:s",strtotime("+15 minutes"));
            
            $qry="insert into ".DB_APORTIL.".tbl_ship_seatbooking
                  set idship='$idship',shipnumber='$shipnumber',shipname='$shipname',bookingdate='$bookingdate',bookingdateend='$bookingdateend',
                      seatnumber='$seatnumber',idroutestart='$idroutestart',routestart='$routestart',idrouteend='$idrouteend',routeend='$routeend',
                      status=0,iby='".$_SESSION['nik']."',idt=now()";
            $rtn="failed|Booking Failed please contact administrator!.";
            if($this->executequery($qry)){
                $rtn="ok|";
            }
            echo $rtn;
        } 
        
        public function fn_cancelseat(){
            $seatnumber=$_REQUEST['seatnumber'];
            $bookingdate=$_REQUEST['bookingdate'];
            $qry="update ".DB_APORTIL.".tbl_ship_seatbooking set status=-2,remark='Cancel Booking by ".$_SESSION['nik']."',uby='".$_SESSION['nik']."',udt=now()
                  where seatnumber='$seatnumber' and cast(bookingdate as date)=cast('$bookingdate' as date) and isdeleted=0";
            //echo "failed|$qry";
            if($this->executequery($qry)){
                echo "ok|success";   
            };
        }                                                                                                            
        
        public function fn_getseatnum(){
            $bookingdate=$_REQUEST['bookingdate'];
            $idship=$_REQUEST['idship'];
            $shipname=$_REQUEST['shipname'];
            $seatnumber=$_REQUEST['seatnumber'];
            $idroutestart=$_REQUEST['idroutestart'];
            $routestart=$_REQUEST['routestart'];
            $routeend=$_REQUEST['routeend'];
            $idrouteend=$_REQUEST['idrouteend'];
            echo $this->FN_CREATEHEADER();
            echo "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no\" />";
            echo "<script>
                      function initObject()
                      {}   
                      function fn_setbookseat(seatnumber){
                          var tempseatnumber='$seatnumber';
                          if(tempseatnumber){
                            fn_dhtmlxmessage('error','Please Cancel your booking Seat Number $seatnumber');
                            return false;
                          }";
                          //window.parent.fn_getbookseat(seatnumber);
                          $setbookseat="var sp=ajaxuridhtmlx('".$this->enc("obj_tra")."','obj=".$this->enc("tra_newticket")."&task=".$this->enc("setbookseat")."&bookingdate=$bookingdate&idship=$idship&seatnumber='+seatnumber+'&idroutestart=$idroutestart&idrouteend=$idrouteend').split('|');";
                          $setbookseat.="if(trim(sp[0])=='failed'){fn_dhtmlxmessage('error',sp[1]);".$this->FN_DHTMLXWINDOWSHIDEPROGRESS().";return false;}";
                          //$setbookseat.="var tiketnumber=sp[1];";
                          $setbookseat.="window.parent.fn_getbookseat(seatnumber);";
                          //$setbookseat="";
                          $fn_setbookseat=$this->FN_DHTMLXWINDOWSHOWPROGESS($setbookseat);
                          $fn_setbookseat.=$this->FN_DHTMLXWINDOWSHIDEPROGRESS();
                          
                          echo $fn_setbookseat;
                          
            echo "    }
            
                      function fn_cancelbooking(seatnumber){
                          dhtmlx.confirm({
                             title:'Confirmation',
                             text:'Are sure to cancel the seat Number '+seatnumber+' ?',
                             callback:function(res){
                                if(res)
                                {";
                                    $cancel="var sp=ajaxuridhtmlx('".$this->enc("obj_tra")."','obj=".$this->enc("tra_newticket")."&task=".$this->enc("cancelseat")."&seatnumber='+seatnumber+'&bookingdate=$bookingdate').split('|');";
                                    //$cancel.="if(trim(sp[0])=='failed'){fn_dhtmlxmessage('error',sp[1]);".$this->FN_DHTMLXWINDOWSHIDEPROGRESS().";return false;}";
                                    $cancel.="if(trim(sp[0])=='failed'){alert(sp[1]);".$this->FN_DHTMLXWINDOWSHIDEPROGRESS().";return false;}";
                                    $cancel.="window.parent.fn_cancelbookseat(seatnumber);";
                                    $eventcancel=$this->FN_DHTMLXWINDOWSHOWPROGESS($cancel);
                                    $eventcancel.=$this->FN_DHTMLXWINDOWSHIDEPROGRESS();
                                    echo $eventcancel;
            echo "              }
                             }
                          }) 
                      }";
            echo "</script>
                  <style>
                     html, body {
                        width: 100%;
                        height: 100%;
                        overflow: hidden;
                        margin: 0px;
                        /*background-color: #EBEBEB;*/
                    }
                  </style>";
            echo $this->FN_CLOSEHEADER();
            echo $this->FN_CREATEBODY("e8f1ff");
            echo "<div style=\"margin-left:25px\">
                      <table>
                          <tr>
                              <td>Ship Name</td>
                              <td>:</td>
                              <td>".$shipname."</td>
                          </tr>
                          <tr>
                              <td>Route</td>
                              <td>:</td>
                              <td>".$routestart." to ".$routeend."</td>
                          </tr>
                          <tr>
                              <td>Booking Date</td>
                              <td>:</td>
                              <td>".$bookingdate."</td>
                          </tr>
                      </table>  
                  </div>";
            echo "<div style=\"height:575px;overflow-y:scroll\">";
            echo "<table width=\"98%\" height=\"100%\" style=\"margin-left:20px;\">";
            echo "  <tr>
                        <td valign=\"top\">
                            <div style=\"height:140\">
                                <table width=\"100%\">";
                                    // === SEAT Number
                                    for($i=1;$i<=30;$i++){
                                        echo "<tr>";
                                                 for($j=1;$j<=10;$j++)
                                                 {
                                                     $colors="#ecf0f1";                                        
                                                     echo "<td width=\"10px\" height=\"8px\" style=\"height:8px;background-color:none\">";
                                                              $qry="select id,status,iby from ".DB_APORTIL.".tbl_ship_seatbooking ";
                                                              $qry.="where seatnumber='".$i.".".chr(64+$j)."' and status>=0 and isdeleted=0 ";
                                                              $qry.="and cast(bookingdate as date)=cast('$bookingdate' as date) ";
                                                              $qry.="and idroutestart='$idroutestart' and idrouteend='$idrouteend' ";
                                                              $qry.="order by id asc limit 1";
                                                              
                                                              $bookingidle="<a href=\"javascript:void(0)\" style=\"text-decoration:none\" onClick=\"fn_setbookseat('".$i.".".chr(64+$j)."')\">$i.".chr(64+$j)."</a>";
                                                              if($this->fn_row_isexists($qry)){
                                                                  $bookingidle="<span style=\"color:white\">".$i.".".chr(64+$j)."</span>";
                                                                  $colors="red";
                                                                  $sp=$this->fn_get_fieldsvalues("id,status,iby",$qry);
                                                                  $id=$sp[0];$status=$sp[1];$iby=$sp[2];
                                                                  if($_SESSION['nik']==$iby){
                                                                      $bookingidle="<a href=\"javascript:void(0)\" style=\"text-decoration:none\" onClick=\"fn_cancelbooking('".$i.".".chr(64+$j)."')\"><span style=\"color:white\">".$i.".".chr(64+$j)."</span></a>";
                                                                      if($status==1){
                                                                          $bookingidle="<span style=\"color:white\">".$i.".".chr(64+$j)."</span>";
                                                                          $colors="blue";
                                                                      }
                                                                      else
                                                                      {
                                                                          if(($i.".".chr(64+$j)!=$seatnumber)){
                                                                              $bookingidle="<span style=\"color:white\">".$i.".".chr(64+$j)."</span>";
                                                                              $colors="#e74c3c";
                                                                              
                                                                          }      
                                                                      }
                                                                  }
                                                              }
                                                              echo "<div style=\"border: 1px solid transparent;border-radius: 2px;background-color:$colors;width:30px;height:23px;font-size:12px;text-align:center;vertical-align:middle;line-height: 25px;\">
                                                                       $bookingidle
                                                                    </div>";
                                                     echo "</td>";
                                                     if($j==5){
                                                         echo "<td width=\"20px\">&nbsp</td>";
                                                     }
                                                 }
                                        echo "</tr>";
                                    }    
            echo "              </table>
                            </div>                            
                        </td>
                    </tr>";
            echo "</table>
                  </div>";

            echo $this->FN_CREATEFOOTER();
        }
        
        public function fn_getpic(){
            $picdata=$_REQUEST['picdata'];
            if($picdata){unlink('uploads/temps/'.$picdata);}
            
            echo $this->FN_CREATEHEADER();
            echo "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no\" />";
            echo "<script src=\"".PATH_THEME."/js/camupload.js\"></script>";
            echo "<script>
                      function initObject()
                      {}
                      
                      function fn_setImage(filename){
                          //window.opener.document.getElementById(\"blah_ReturnValue\").value = rv;
                          window.parent.fn_getPicName(filename);
                          
                      }";
            echo "</script>
                  <style>
                     html, body {
                        width: 100%;
                        height: 100%;
                        overflow: hidden;
                        margin: 0px;
                        /*background-color: #EBEBEB;*/
                    }
                  </style>";
            echo $this->FN_CLOSEHEADER();
            echo $this->FN_CREATEBODY("e8f1ff");
//            echo "<div id=\"vid-controls\" style=\"margin-left:-80px\">
//                    
//                  </div>";
            echo "<video id=\"vid-show\" autoplay height=\"400\"></video>
                  <div style=\"position:absolute;z-index:999;margin-top:-18%;margin-left:90%\">
                      <a href=\"javascript:void(0)\" id=\"vid-take\" style=\"color:white\"><i class=\"fa fa-camera\" style=\"font-size:26pt;\"></i></a>
                  </div>
                  <div id=\"vid-canvas\" style=\"\"></div>";
            //echo "<button onClick='fn_setImage()'>Show Parent</button>";
            echo $this->FN_CREATEFOOTER();
            
            
        }
    }
?>