<?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:114px;margin-top:-6px;position:absolute;}
                      .besidebtnupdate {margin-left:218px;margin-top:-6px;position:absolute;}
                      .besidebtnsubmit {margin-left:292px;margin-top:-6px;position:absolute;}
                      .besidebtndelete {margin-left:318px;margin-top:-6px;position:absolute;}
                      .besidelabel {margin-left:280px;margin-top:-5px;position:absolute;}
                      .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;}
                  </style>";
            
            echo "<script>
                       var myForm,myFormsearch,dgnewticket,dwins;
                       var mm,ss;
                       var tbooking;
                       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_picdata"),
                                                                      array("type"=>"combo","name"=>"cbo_idship","label"=>"Ship Name","required"=>"true","info"=>"true","inputWidth"=>"280","value"=>"0",
                                                                            "tooltip"=>"Pilih Ship Name terlebih dahulu. TERIMA KASIH","validate"=>"NotEmpty","maxLength"=>"11","className"=>"txtleft"),
                                                                      array("type"=>"input","name"=>"txt_tiketnumber","label"=>"Ticket Number","required"=>"true","info"=>"true","inputWidth"=>"280","value"=>"",
                                                                            "tooltip"=>"Masukkan Ticket Number terlebih dahulu. TERIMA KASIH","validate"=>"NotEmpty","maxLength"=>"40","className"=>"txtcenter txttiketnumber"),
                                                                      array("type"=>"input","name"=>"txt_voynumber","label"=>"Voyage Number","required"=>"true","info"=>"true","inputWidth"=>"280","value"=>"",
                                                                            "tooltip"=>"Masukkan Voyage Number terlebih dahulu. TERIMA KASIH","validate"=>"NotEmpty","maxLength"=>"100","className"=>"txtcenter"),

//                                                                      array("type"=>"input","name"=>"txt_inctiket","label"=>"No. Sequence","required"=>"true","info"=>"true","inputWidth"=>"90","value"=>"0",
//                                                                            "tooltip"=>"Masukkan No. Sequence terlebih dahulu. TERIMA KASIH","validate"=>"NotEmpty","maxLength"=>"11","className"=>"txtcenter"),
                                                                      //array("type"=>"input","name"=>"txt_shipnumber","label"=>"Ship Number","required"=>"true","info"=>"true","inputWidth"=>"280","value"=>"",
//                                                                            "tooltip"=>"Masukkan Ship Number terlebih dahulu. TERIMA KASIH","validate"=>"NotEmpty","maxLength"=>"100","className"=>"txtleft"),
                                                                      array("type"=>"input","name"=>"txt_passengername","label"=>"Name","required"=>"true","info"=>"true","inputWidth"=>"280","value"=>"",
                                                                            "tooltip"=>"Masukkan Nama terlebih dahulu. TERIMA KASIH","validate"=>"NotEmpty","maxLength"=>"100","className"=>"txtleft"),
                                                                      array("type"=>"combo","name"=>"cbo_idcardtype","label"=>"ID Card","required"=>"true","info"=>"true","inputWidth"=>"90","value"=>"0",
                                                                            "tooltip"=>"Pilih ID Card terlebih dahulu. TERIMA KASIH","validate"=>"NotEmpty","maxLength"=>"11","className"=>"txtleft"),
                                                                      array("type"=>"newColumn"),
                                                                      array("type"=>"input","name"=>"txt_cardnumber","label"=>"","required"=>"true","info"=>"true","inputWidth"=>"120","value"=>"",
                                                                            "tooltip"=>"Masukkan Picture terlebih dahulu. TERIMA KASIH","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"=>"hidden","name"=>"txt_picdata","label"=>"Picture","required"=>"true","info"=>"true","inputWidth"=>"280","value"=>"",
                                                                            "tooltip"=>"Masukkan Picture terlebih dahulu. TERIMA KASIH","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"=>"Masukkan Dates terlebih dahulu. TERIMA KASIH","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 terlebih dahulu. TERIMA KASIH","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 terlebih dahulu. TERIMA KASIH","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"=>"Masukkan Seat Number terlebih dahulu. TERIMA KASIH","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_quantity","label"=>"Quantity","required"=>"true","info"=>"true","inputWidth"=>"90","value"=>"0",
//                                                                            "tooltip"=>"Masukkan Quantity terlebih dahulu. TERIMA KASIH","validate"=>"NotEmpty","maxLength"=>"6","className"=>"txtcenter"),
                                                                      array("type"=>"input","name"=>"txt_price","label"=>"Price","required"=>"true","info"=>"true","inputWidth"=>"90","value"=>"0","readonly"=>"true",
                                                                            "tooltip"=>"Masukkan Price terlebih dahulu. TERIMA KASIH","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"=>"true","info"=>"true","inputWidth"=>"60","value"=>"0",
                                                                            "tooltip"=>"Masukkan Baggage terlebih dahulu. TERIMA KASIH","validate"=>"NotEmpty","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"=>"Masukkan Price terlebih dahulu. TERIMA KASIH","validate"=>"","maxLength"=>"","className"=>"txtright besidebaggage"),
                                                                      array("type"=>"column"),
                                                                      array("type"=>"input","name"=>"txt_overlimitbaggage","label"=>"","required"=>"false","info"=>"true","inputWidth"=>"70","value"=>"0","note"=>array("text"=>"Over Limit ( kg )"),
                                                                            "tooltip"=>"Masukkan Over limit baggage terlebih dahulu. TERIMA KASIH","validate"=>"","maxLength"=>"","className"=>"txtright besidelimitbaggage"),
                                                                      array("type"=>"column"),
                                                                      array("type"=>"input","name"=>"txt_pricelimitbaggage","label"=>"","required"=>"false","info"=>"true","inputWidth"=>"90","value"=>"0","note"=>array("text"=>"Price ( kg ) in \$"),
                                                                            "tooltip"=>"Masukkan Price terlebih dahulu. TERIMA KASIH","validate"=>"","maxLength"=>"","className"=>"txtright besidelimitkgbaggage"),
                                                                      array("type"=>"input","name"=>"txt_overprice","label"=>"Over Baggage","required"=>"true","info"=>"true","inputWidth"=>"90","value"=>"0",
                                                                            "tooltip"=>"Masukkan Over Price terlebih dahulu / beri nilai 0. TERIMA KASIH","validate"=>"NotEmpty","maxLength"=>"","className"=>"txtright"),
                                                                      array("type"=>"column"),
                                                                      array("type"=>"label","name"=>"lblmeter","label"=>"\$","className"=>"besidelabelprice"),
                                                                      
                                                                      array("type"=>"input","name"=>"txt_totalbiaya","label"=>"Total","required"=>"true","info"=>"true","inputWidth"=>"90","value"=>"0",
                                                                            "tooltip"=>"Masukkan total terlebih dahulu. TERIMA KASIH","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"=>"25"),
                                                                      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);

                            $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_passenger_identifycardtype|id,cardtype')";
                            $this->FN_COMBOVALIDATIONVALUENEW("myForm","cbo_idcardtype","tbl_passenger_identifycardtype","$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_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 : Harap Isikan <b>Ship Name</b> terlebih dahulu.TERIMA KASIH",
                                            "txt_tiketnumber"=>"Error Found : Harap Isikan <b>Ticket Number</b> terlebih dahulu.TERIMA KASIH",
                                            "txt_voynumber"=>"Error Found : Harap Isikan <b>Voyage Number</b> terlebih dahulu.TERIMA KASIH",
                                            //"txt_inctiket"=>"Error Found : Harap Isikan <b>No. Sequence</b> terlebih dahulu.TERIMA KASIH",
//                                            "txt_shipnumber"=>"Error Found : Harap Isikan <b>Ship Number</b> terlebih dahulu.TERIMA KASIH",
                                            "txt_passengername"=>"Error Found : Harap Isikan <b>Mrs/ Mr</b> terlebih dahulu.TERIMA KASIH",
                                            "cbo_idcardtype"=>"Error Found : Harap Masukin identity Card terlebih dahulu.TERIMA KASIH",
                                            "txt_picdata"=>"Error Found : Harap Isikan <b>Picture</b> terlebih dahulu.TERIMA KASIH",
                                            "txt_dates"=>"Error Found : Harap Isikan <b>Dates</b> terlebih dahulu.TERIMA KASIH",
                                            "cbo_idroutestart"=>"Error Found : Harap Isikan <b>From</b> terlebih dahulu.TERIMA KASIH",
                                            "cbo_idrouteend"=>"Error Found : Harap Isikan <b>To</b> terlebih dahulu.TERIMA KASIH",
                                            "txt_seatnumber"=>"Error Found : Harap Isikan <b>Seat Number</b> terlebih dahulu.TERIMA KASIH",
                                            "txt_quantity"=>"Error Found : Harap Isikan <b>Quantity</b> terlebih dahulu.TERIMA KASIH",
                                            "txt_price"=>"Error Found : Harap Isikan <b>Price</b> terlebih dahulu.TERIMA KASIH",
                                            "txt_baggageinkg"=>"Error Found : Harap Isikan <b>Baggage</b> terlebih dahulu.TERIMA KASIH",
                                            "txt_limitbaggage"=>"Error Found : Harap Isikan <b>Price</b> terlebih dahulu.TERIMA KASIH"
                                      );
                            $this->FN_DHTMLXFORMVALIDATIONERROR("myForm",$arrerror);

                            $arrayControls=array("txt_id"=>"","cbo_idship"=>"","txt_tiketnumber"=>"","txt_voynumber"=>"",
                                                 "txt_passengername"=>"","cbo_idcardtype"=>"","txt_picdata"=>"",
                                                 "txt_dates"=>date("Y-m-d"),"cbo_idroutestart"=>"","cbo_idrouteend"=>"",
                                                 "txt_seatnumber"=>"","txt_quantity"=>"","txt_price"=>0,"txt_baggageinkg"=>0,
                                                 "txt_limitbaggage"=>80,"txt_overlimitbaggage"=>0,"txt_pricelimitbaggage"=>0,
                                                 "txt_overlimitbaggage"=>0,"txt_totalbiaya"=>0
                                                 
                                          );

                            // === 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="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);";
                            $onkeypresscboshipname=$this->FN_DHTMLXWINDOWSHOWPROGESS($cboship);
                            $onkeypresscboshipname.=$this->FN_DHTMLXWINDOWSHIDEPROGRESS();

                            // === Cbo Route End Change
                            $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_pricelimitbaggage',sp[3]);";
                            
                            // === 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_pricelimitbaggage');";
                            $onchangetxtbaggage.="    }";
                            $onchangetxtbaggage.="    myForm.setItemValue('txt_overprice',priceoverbaggage);";
                            $onchangetxtbaggage.="    var totalbiaya=(parseFloat(myForm.getItemValue('txt_price')))+(parseFloat(myForm.getItemValue('txt_overprice')));";
                            //$onchangetxtbaggage.="    alert(totalbiaya);";
                            $onchangetxtbaggage.="    myForm.setItemValue('txt_totalbiaya',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('|');
                                                                          //alert(response);
                                                                          if(sp[0]=='ok')
                                                                          {
                                                                              fn_dhtmlxmessage('','Data <b>'+myForm.getItemValue('cbo_idship')+'</b> has been saved');";
                                                                              $onformsenddata.=$this->FN_DHTMLXFORMCLEAR2("myForm",$arrayControls,"cbo_idship");
                                                                              $onformsenddata.="fn_grid_loaddata();
                                                                          }
                                                                          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('','Data <b>'+myForm.getItemValue('cbo_idship')+'</b> has been update');";
                                                                           $onformsenddata.=$this->FN_DHTMLXFORMCLEAR2("myForm",$arrayControls,"cbo_idship");
                                                                           $onformsenddata.="myForm.enableItem('btnsave');";
                                                                           $onformsenddata.="myForm.disableItem('btnupdate');";
                                                                           $onformsenddata.="myForm.disableItem('btndelete');";
                                                                           $onformsenddata.="fn_grid_loaddata();
                                                                      }
                                                                      else if(sp[0]=='failed')
                                                                      {fn_dhtmlxmessage('error','Error Found : '+sp[1]);}
                                                                      else
                                                                      {fn_dhtmlxmessage('error','Error Found : '+response);}
                                                                   });";
                                                                   $onbuttonclickbtnupdt.=$this->FN_DHTMLXWINDOWSHOWPROGESS($onformsenddata);
                            $onbuttonclickbtnupdt.="            }
                                                             }
                                                        });
                                                   }";

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

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

                            
                            $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,val",
                                                          "switch"=>array(
                                                                            "cbo_idrouteend"=>"$onchangecboidrouteend $onchangetxtbaggage",
                                                                            
                                                          )
                                                )  

                            );


                            $this->FN_DHTMLXFORMEVENT("myForm",$arrevent);
                            echo "myForm.getCombo('cbo_idship').attachEvent('onKeyPressed',function(keycode){
                                      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",
                                                  "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",
                                                  "Dates"=>"center,ro,120,center,date,false",
                                                  "From"=>"center,ro,112,center,str,false",
                                                  "To"=>"center,ro,112,center,str,false",
                                                  "Seat Number"=>"center,ro,90,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()");
                            $arrfields=array("txt_id"=>"","cbo_idship"=>"","txt_tiketnumber"=>"","txt_inctiket"=>"","txt_shipnumber"=>"","txt_passengername"=>"","txt_picdata"=>"","txt_dates"=>"","cbo_idroutestart"=>"","cbo_idrouteend"=>"","txt_seatnumber"=>"","txt_quantity"=>"","txt_price"=>"","txt_baggageinkg"=>"","txt_limitbaggage"=>"");
                            $otherevent="";
                            $this->FN_DHTMLXGRIDVIEWTOFORMNEW("dgnewticket","myForm","tbl_passenger_tiket",0,$arrfields,"");
            echo "    }
                      
                      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 url='?ajax=1&sec=1&option=".$this->enc("obj_tra")."&obj=".$this->enc("tra_newticket")."&task=".$this->enc("getpic")."';";
                          $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){
                         //alert(filename);
                         myForm.setItemValue('txt_picdata',filename);
                         dwins.unload();
                         document.getElementById('imgtiket').src='uploads/temps/'+filename;
                         
                      }
                      
                      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>";
                              $url="location.reload();";
                              $myuri=array("<b>PASSENGER INFORMATION</b>"=>"$url|id='a_newticket'");
                              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,shipnumber,passengername,picdata,dates,idroutestart,idrouteend,seatnumber,quantity,price,baggageinkg,pricebaggage
                  from ".DB_APORTIL.".tbl_passenger_tiket
                  where idship like '%$keyword%' and isdeleted=0
                  order by id asc limit ".TBL_PAGE_LIMIT;

            $rs=$this->selectquery($qry);
            if($rs)
            {
               $i=1;
               while($row=$this->data_row_array($rs))
               {
                  echo ("<row id='".$row["id"]."'>");
                        print("<cell><![CDATA[".$row["id"]."]]></cell>");
                        print("<cell><![CDATA[".$i."]]></cell>");
                        print("<cell><![CDATA[".$row["idship"]."]]></cell>");
                        print("<cell><![CDATA[".$row["tiketnumber"]."]]></cell>");
                        print("<cell><![CDATA[".$row["inctiket"]."]]></cell>");
                        print("<cell><![CDATA[".$row["shipnumber"]."]]></cell>");
                        print("<cell><![CDATA[".$row["passengername"]."]]></cell>");
                        print("<cell><![CDATA[".$row["picdata"]."]]></cell>");
                        print("<cell><![CDATA[".date("Y-m-d",strtotime($row["dates"]))."]]></cell>");
                        print("<cell><![CDATA[".$row["idroutestart"]."]]></cell>");
                        print("<cell><![CDATA[".$row["idrouteend"]."]]></cell>");
                        print("<cell><![CDATA[".$row["seatnumber"]."]]></cell>");
                        print("<cell><![CDATA[".$row["quantity"]."]]></cell>");
                        print("<cell><![CDATA[".$row["price"]."]]></cell>");
                        print("<cell><![CDATA[".$row["baggageinkg"]."]]></cell>");
                        print("<cell><![CDATA[".$row["pricebaggage"]."]]></cell>");
                  echo ("</row>");
                  $i+=1;
               }
            }
            else
            {
                  echo mysql_errno().": ".mysql_error()." at ".__LINE__." line in ".__FILE__." file<br>";
            }
            echo "</rows>";

        }

        public function fn_saverecord($isupdate=null)
        {
            if($isupdate){$id=$_REQUEST['txt_id'];}
            $idship=$_REQUEST['cbo_idship'];
            $tiketnumber=$_REQUEST['txt_tiketnumber'];
            $inctiket=$_REQUEST['txt_inctiket'];
            $shipnumber=$_REQUEST['txt_shipnumber'];
            $passengername=$_REQUEST['txt_passengername'];
            $picdata=$_REQUEST['txt_picdata'];
            $dates=$_REQUEST['txt_dates'];
            $idroutestart=$_REQUEST['cbo_idroutestart'];
            $idrouteend=$_REQUEST['cbo_idrouteend'];
            $seatnumber=$_REQUEST['txt_seatnumber'];
            $quantity=$_REQUEST['txt_quantity'];
            $price=$_REQUEST['txt_price'];
            $baggageinkg=$_REQUEST['txt_baggageinkg'];
            $pricebaggage=$_REQUEST['txt_limitbaggage'];

            $qry="insert into ".DB_APORTIL.".tbl_passenger_tiket 
                  set idship='$idship',tiketnumber='$tiketnumber',inctiket='$inctiket',shipnumber='$shipnumber',passengername='$passengername',picdata='$picdata',
                      dates='$dates',idroutestart='$idroutestart',idrouteend='$idrouteend',seatnumber='$seatnumber',quantity='$quantity',price='$price',
                      baggageinkg='$baggageinkg',pricebaggage='$pricebaggage',iby='".$_SESSION['nik']."',idt=now()";
            if($isupdate)
            {
                $qry="update ".DB_APORTIL.".tbl_passenger_tiket
                      set idship='$idship',tiketnumber='$tiketnumber',inctiket='$inctiket',shipnumber='$shipnumber',passengername='$passengername',picdata='$picdata',
                          dates='$dates',idroutestart='$idroutestart',idrouteend='$idrouteend',seatnumber='$seatnumber',quantity='$quantity',price='$price',
                          baggageinkg='$baggageinkg',pricebaggage='$pricebaggage',uby='".$_SESSION['nik']."',udt=now()
                      where id='$id'";
            }

            if($this->executequery($qry)){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_getticket(){
            $valticket="";
            for($i=1;$i<=8;$i++){
                $valticket.=rand(0,9);
            }
            $sql="select tiketnumber from ".DB_APORTIL.".tbl_passenger_tiket where tiketnumber='".$tiketnumber."' 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";
            $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);
            }
            echo "$status|$statuserr|$price|$pricebaggagelimit";
        }
        
        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(){
            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();
            
            
        }
    }
?>