<?php
    if(preg_match("/libconfig.php/i", $_SERVER['PHP_SELF'])){header("location: index.php");die;}

    require_once("lib/AES.class.php");
    class MY_LIBRARY
    {
        var $errquery;
        public function __construct()
        {
            //$return=true;
            $clhtml=new MY_HTML();
            //if(!isset($_SESSION['nik'])){$clhtml->mosRedirect("D.H.T.M.L.X");}
            
        }
        //private $ajax;private $option;private $obj;private $task;
        public function initiate_java_function()
        {
            echo "<script language=\"javascript\">
                    params='';                    
                    function loadObject(params,div_result,strinfo,withoutprogress)".$this->HANDLE_VIEWSOURCE(50)."
                    {    
                        try
                        {    
                            
                            if(!withoutprogress)
                            {
                                document.getElementById(div_result).innerHTML='';".$this->HANDLE_VIEWSOURCE(123)."                     
                                document.getElementById(div_result).innerHTML='<font color=\"#3C407E\"><b>'+strinfo+' ... </b></font><img src=\"".PATH_THEME."/finance/images/loader.gif\" />';
                            }
                            document.body.style.cursor='wait';
                            window.status='wait...';
                            if(window.XMLHttpRequest)
                            {// code for IE7+, Firefox, Chrome, Opera, Safari
                                xmlhttp=new XMLHttpRequest();
                            }
                            else
                            {// code for IE6, IE5
                                xmlhttp=new ActiveXObject(\"Microsoft.XMLHTTP\");
                            }                            
                            xmlhttp.onreadystatechange=function()".$this->HANDLE_VIEWSOURCE(46)."
                            {
                                if(xmlhttp.readyState==4 && xmlhttp.status==200)
                                {                                              
                                    var textresult=xmlhttp.responseText;
                                    var spresult=textresult.split('|');
                                    if(spresult.length>1)
                                    {
                                        document.getElementById(div_result).innerHTML=spresult[2];".$this->HANDLE_VIEWSOURCE(70)."                                        
                                        if(trim(spresult[0])=='msg'){alert(spresult[1]);}                                                                                
                                        if(trim(spresult[0])=='url'){window.location=spresult[1];}
                                    }
                                    else
                                    {                                           
                                        document.getElementById(div_result).innerHTML=textresult;                                        
                                    }
                                    document.body.style.cursor='default';
                                    window.status='Completed.';
                                }
                                if(xmlhttp.readyState==2||xmlhttp.readyState==3)
                                {
                                    if(!withoutprogress)
                                    {   ".$this->HANDLE_VIEWSOURCE(80)."
                                        document.getElementById(div_result).innerHTML='<font color=\"#3C407E\"><b>Load...</b></font><img src=\"".PATH_THEME."/finance/images/loader.gif\" />';
                                    }
                                }
                            }
                            xmlhttp.open('POST','index.php',true);".$this->HANDLE_VIEWSOURCE(80)."
                            xmlhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
                            xmlhttp.setRequestHeader('Content-length', params.length);
                            xmlhttp.setRequestHeader('connection', 'close');
                            xmlhttp.send(params);".$this->HANDLE_VIEWSOURCE(145)."
                            return true;
                        }
                        catch(e)
                        {
                            alert(e.message);
                            return false;            
                        }      
                    }
                    
                    function pagesymbolview(page,nameobjnext,nameobjprev,namepagecount,nameimgnext,nameimgprev) ".$this->HANDLE_VIEWSOURCE(123)."// for paging table function
                    {
                        var objnameprev='a_prev';
                        var objnamenext='a_next';
                        var objnamepagecount='txtpagecount';".$this->HANDLE_VIEWSOURCE(80)."
                        var objnameimgnext='imgnext';
                        var objnameimgprev='imgprev';
                        if(nameobjnext){objnamenext=nameobjnext;}".$this->HANDLE_VIEWSOURCE(80)."
                        if(nameobjprev){objnameprev=nameobjprev;}
                        if(namepagecount){objnamepagecount=namepagecount;}
                        if(nameimgnext){objnameimgnext=nameimgnext;".$this->HANDLE_VIEWSOURCE(80)."}
                        if(nameimgprev){objnameimgprev=nameimgprev;}
                        
                        var prev=document.getElementById(objnameprev);
                        var imgprev=document.getElementById(nameimgprev);".$this->HANDLE_VIEWSOURCE(80)."
                        var picprev='application_previous_disabled.png';
                        prev.disabled=true;prev.title='Disabled';".$this->HANDLE_VIEWSOURCE(80)."
                        var next=document.getElementById(objnamenext);
                        var imgnext=document.getElementById(nameimgnext);
                        var picnext='application_next_active.png';
                        next.disabled=false;next.title='Next';
                        
                        var pagecount=document.getElementById(objnamepagecount).value;".$this->HANDLE_VIEWSOURCE(180)."
                        if(page>1){prev.disabled=false;prev.title='Previous';picprev='application_previous_active.png';".$this->HANDLE_VIEWSOURCE(80)."}
                        if(page==pagecount){next.disabled=true;next.title='Disabled';picnext='application_next_disabled.png';}
                        
                        imgprev.src='".PATH_THEME."/images/'+picprev;".$this->HANDLE_VIEWSOURCE(80)."
                        imgnext.src='".PATH_THEME."/images/'+picnext;
                    }                    
                    
                    function loadNewWindow(url,pagewidth,pageheight,scrollbar)
                    {
                        document.body.style.cursor='wait';
                        if(!pagewidth){pagewidth=450;}
                        if(!pageheight){pageheight=550;}
                        if(!scrollbar&&scrollbar!=0){scrollbar=1;}
                        //scrollbar=1;
                        //parentwin=window.open(url,\"_blank\");//,\"top=0,left=0,width=\"+pagewidth+\",height=\"+pageheight+\",toolbar=0,menubar=0,statusbar=0,location=0,scrollbars=\"+scrollbar);
                        parentwin=window.open(url,\"_blank\",\"top=0,left=0,width=\"+pagewidth+\",height=\"+pageheight+\",toolbar=0,menubar=0,statusbar=0,location=0,scrollbars=\"+scrollbar);
                        if(pagewidth=='100%'){parentwin.resizeTo(screen.width-40,pageheight);}
                        document.body.style.cursor='default';
                    }
                    
                    function loadXLS(url,pagewidth,pageheight,scrollbar)
                    {
                        document.body.style.cursor='wait';
                        if(!pagewidth){pagewidth=450;}
                        if(!pageheight){pageheight=550;}
                        if(!scrollbar&&scrollbar!=0){scrollbar=1;}
                        //scrollbar=1;
                        //parentwin=window.open(url,\"_blank\");//,\"top=0,left=0,width=\"+pagewidth+\",height=\"+pageheight+\",toolbar=0,menubar=0,statusbar=0,location=0,scrollbars=\"+scrollbar);
                        parentwin=window.open(url,\"_blank\",\"top=0,left=0,width=\"+pagewidth+\",height=\"+pageheight+\",toolbar=0,menubar=0,statusbar=0,location=0,scrollbars=\"+scrollbar);
                        if(pagewidth=='100%'){parentwin.resizeTo(screen.width-40,pageheight);}
                        document.body.style.cursor='default';
                        parentwin.close();
                    }
               </script>";
        }
        
        public function module_under_construction($msg)
        {
            $message="<b>Your module is still <font color=\"red\">underconstruction.!</font></b>";
            if($msg){$message=$msg;}
            echo "<div style=\"margin-top:10px;margin-left:10px;font-size:14px;color:#48484a;\" align=\"left\">$message</div>";
            exit;    
        }

        public function under_construction($expnik=null)
        {
            if($_SESSION['nik']!=$expnik)
            {
                echo "<div style=\"margin-top:10px;margin-left:10px;font-size:14px;color:#48484a;\" align=\"left\">
                          <b>Your module is still <font color=\"red\">underconstruction.!</font></b>
                      </div>";
                exit;    
            }
        }
        
        
        public function ldap_auth($nikuser,$pass)
        {
            try{
                $ldap=ldap_connect(IP_LDAP) or die("Could not connect to LDAP server.");
                //$ldap=ldap_connect("103.30.115.1");
                $bind=@ldap_bind($ldap, $nikuser.'@telkomcel.tl', $pass);
                if($bind)
                {
                    //echo "ldap";//return false;
                
                    return true;
                }
                
                //echo "ldap_error: " . ldap_error($ldap);
                return false;
                
            }
            catch(Exception $e)
            {
                echo "FAILED";
            }
        }
        
        public function logout()
        {
            //global $mycn;
            session_start();
                    
//            session_unregister($_SESSION["nik"]);
//            session_unregister($_SESSION["employeename"]);
//            session_unregister($_SESSION["pass"]);
//            session_unregister($_SESSION["groupuser"]);
//            session_unregister($_SESSION["isactivated"]);
//            session_unregister($_SESSION["treemenuid"]);
//            session_unregister($_SESSION["menuid"]);
//            session_unregister($_SESSION["menuid_groupproject"]);
//            session_unregister($_SESSION["idlevel"]);
//            session_unregister($_SESSION["iddivisi"]);
//            session_unregister($_SESSION["idregion"]);
            
            $_SESSION["nik"]="";
            $_SESSION["employeename"]="";
            $_SESSION["msisdn"]="";
            $_SESSION["pass"]="";
            $_SESSION["maskpass"]="";
            $_SESSION["menuidgroupproject"]="";
            $_SESSION["menuid"]="";
            $_SESSION["treemenuid"]="";
            $_SESSION["idgroupuser"]="";
            $_SESSION["groupuser"]="";
            $_SESSION["isactivated"]="";

            //===== update visitor
            //$this->fn_my_visitor('out');
            // ==========================
            session_destroy();
            //mysql_close($mycn);
        }
        
        public function login()
        {    
            session_start();            
            $username=str_replace("'","",trim($_POST['txtuser']));
            $password=str_replace("'","",trim($_POST['txtpass']));
            if(!$username || !$password)
            {
                echo "<script>window.location.href='?option=err/400'; </script>";
                exit();
            }
            elseif($username==$password)
            {
                echo "<script>window.location.href='?option=err/402'; </script>";
                exit();
            }
            else
            {                                  
                if($this->ldap_auth($username,$password))
                {
                    $qry="select id, nik, employeename, msisdn, pass, maskpass, menuidgroupproject, menuid, treemenuid, idgroupuser, groupuser, isactivated
                          from ".DB_APORTIL.".tbl_employee_accessibility
                          where lower(nik)=lower('$username') and pass='".$this->enc($password)."' and isdeleted=0";
                    $qry="select id, nik, employeename, msisdn, pass, maskpass, menuidgroupproject, menuid, treemenuid, idgroupuser, groupuser, isactivated
                          from ".DB_APORTIL.".tbl_employee_accessibility
                          where lower(nik)=lower('$username') and isdeleted=0";
                    //echo $qry;return false;
                             
                    $rsuser=$this->selectquery($qry);
                    
                    if($this->REC_ROWS_COUNT($rsuser)<=0)
                    {
                        echo "<script>window.location.href='?option=err/401'; </script>";
                        exit();
                    }
                    else
                    {                
                        $rw=$this->data_row_array($rsuser);
                        if(!$rw['isactivated'])
                        {
                            echo "<script>window.location.href='?option=err/403'; </script>";
                            exit();
                        }

                        $qry="update ".DB_APORTIL.".tbl_employee_accessibility set pass='".$this->enc($password)."' where nik='".$rw['nik']."'";
                        //echo $qry;return false;
                        $this->executequery($qry);
                        
                        $_SESSION["nik"]=$rw['nik'];
                        $_SESSION["employeename"]=$rw['employeename'];
                        $_SESSION["msisdn"]=$this->$rw['msisdn'];
                        $_SESSION["pass"]=$password;
                        $_SESSION["maskpass"]=$rw['maskpass'];
                        $_SESSION["menuidgroupproject"]=$rw['menuidgroupproject'];
                        $_SESSION["menuid"]=$rw['menuid'];
                        $_SESSION["treemenuid"]=$rw['treemenuid'];
                        $_SESSION["idgroupuser"]=$rw['idgroupuser'];
                        $_SESSION["groupuser"]=$rw['groupuser'];
                        $_SESSION["isactivated"]=$rw['isactivated'];
                                           
                    }
                    $this->clearrecordset($rsuser);

                    //echo "LDAP SUCCESS";return false;
                }
                else
                {
                    echo "<script>window.location.href='?option=err/401'; </script>";
                    exit();
                    
                }
                    
            }
        }
        
        public function get_ajaxparam()
        {
            //return $this->ajax;
        }
        
        public function uri_parsing($myuri)
        {
            //ajax=1&sec=1&option=d5e637fc469313a4c29c29b2beae76a1&obj=5a7b86ecb3c4aef856eefd7002f6d58f&task=default
            //global $ajax;global $option;global $obj;global $task;
            
            $spuri=explode("&",$myuri);
            $spajax=explode("=",$spuri[0]);
            $ajax=$spajax[1];
            //echo $ajax;return false;
            $spsec=explode("=",$spuri[1]);
            $sec=$spsec[1];
            $spoption=explode("=",$spuri[2]);
            $option=$spoption[1];
            $spobj=explode("=",$spuri[3]);
            $obj=$spobj[1];
            $sptask=explode("=",$spuri[4]);
            $task=$sptask[1];

            return $ajax."|".$sec."|".$option."|".$obj."|".$task;
//            echo "<label style=\"color:white;margin-top:200px;\">".$option."</label>";
            
        }
        
        public function getFullNameOfMonth($monthnumber)
        {
            $monthnumber=(int)$monthnumber;
            $month[1]="Januari";$month[2]="Februari";$month[3]="Maret";
            $month[4]="April";$month[5]="Mei";$month[6]="Juni";$month[7]="Juli";
            $month[8]="Agustus";$month[9]="September";$month[10]="Oktober";$month[11]="November";
            $month[12]="Desember";
            return $month[$monthnumber];
        }
        
        public function HANDLE_VIEWSOURCE($spacing=null)
        {
            if(!$spacing){$spacing=343458;}
            $spacing=0;
            return str_repeat("\n",$spacing);
        }
        //public function fn_my_visitor($activity)
//        {
//            try
//            {
//                $increment="+1";
//                if($activity=='out'){$increment="-1";}
//                $qry="update ".DB_APORTIL.".tbl_visitor set visitor=visitor".$increment;
//                if($activity=='in'){$qry.=",user_last_login='".$_SESSION['nikx']."',last_date='".date("Y-m-d H:i:s")."'";}
//                if($this->executequery($qry))
//                {
//                    $qry="insert into ".DB_APORTIL.".tbl_visitor_log
//                          set visitor_id='".$_SESSION['nikx']."',ip_visitor='".$_SERVER['REMOTE_ADDR']."',
//                          date_login='".date("Y-m-d H:i:s")."'";
//                    if($activity=='out')
//                    {
//                        $qry="update ".DB_APORTIL.".tbl_visitor_log set date_logout='".date("Y-m-d H:i:s")."'
//                              where id='".$_SESSION["id_visitor"]."'";
//                    }
//                    if($this->executequery($qry))
//                    {
//                        $id_visitor=mysql_insert_id();
//                        if($id_visitor)
//                        {
//                            $_SESSION["id_visitor"]=$id_visitor;
//                            session_register($_SESSION["id_visitor"]);
//                        }
//                        else
//                        {
//                            session_unregister($_SESSION["id_visitor"]);
//                            $_SESSION["id_visitor"]="";
//                        }
//                    }
//                }
//                return true;
//            }
//            catch(Exception $e)
//            {
//                echo $e->getMessage();
//                return false;
//            }
//        }
                
        public function fn_toolbar()
        {
            $qry="select * from ".DB_APORTIL.".tbl_menumozi_toolbar where id in(".$_SESSION['toolbar_id'].") and isdisabled=0";            
            $rstoolbar=mysql_query($qry);
            if($rstoolbar)
            {
                if($this->REC_ROWS_COUNT($rstoolbar)>0)
                {
                    echo "<table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">
                              <tr>
                                  <td>
                                      <div id=\"div_toolbar\" style=\"background-color:#c9d9ed;width:100%;height:30px;\" >";
                                            echo "<table id=\"tb_toolbar\" name=\"tb_toolbar\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" height=\"25px\">
                                                      <tr>";
                                                          while($rw=$this->data_row_object($rstoolbar))
                                                          {
                                                              echo "<td align=\"left\">";
                                                                        echo $this->CREATE_LINK_IMG_HOVER($rw->url,$rw->event,$rw->imgactive,$rw->imghover,$rw->toolbar_title);   
                                                              echo "</td>";
                                                          }  
                                            echo "    </tr>
                                                  </table>";
                    echo "          </div>
                                 <td>               
                             <tr>                
                          </table>";              
                    
                }
            }
            $this->clearrecordset($rstoolbar);
        }
        
        public function loadtreeview($MODULENAME,$TREEVIEHEADER=null,$FOLDERTREECAPTION=null,$TARGETTYPE=null,$TARGETNAME=null)
        {
            echo "<STYLE>
                    td {
                      font-size: 10px; 
                      font-family: verdana,helvetica; 
                      text-decoration: none;
                      white-space:nowrap;height:94%;}
                    A {
                      text-decoration: none;
                      color: black;
                      font-size:11px;
                      }
                    .specialClass {
                      font-family:garamond; 
                      font-size:11pt;
                      color:green;
                      /*font-weight:bold;*/
                      text-decoration:underline}
                  </STYLE>
                  <!-- Code for browser detection. DO NOT REMOVE.              -->
                  <SCRIPT src=\"".PATH_MODULE."/treeview/ua.js\"></SCRIPT>
                  <SCRIPT src=\"".PATH_MODULE."/treeview/ftiens4.js\"></SCRIPT>

                  <!-- Infrastructure code for the TreeView. DO NOT REMOVE.    -->";
                  // =========== Check available menu
//                  $qry="select menuid from ".DB_FAS.".tbl_menuorder by menuid asc limit 1";
//                  $rsmnu=$this->selectquery($qry);
//                  if($rsmnu)
//                  {
//                      if($this->REC_ROWS_COUNT($rsmnu)<=0&&$_SESSION['nik']!=='9999') 
//                      {
//                          echo "<font color='gray'>
//                                    <i>Not available .</i><br/>
//                                    Please Contact your 
//                                    <a href=\"mailto:itsupport_mdn99@telkomsel.co.id\" title=\"Send email to admin\" style=\"color:blue;\">admin</a>
//                                    <br/><br/>
//                                    <a href=\"index.php?opt=sign_out\" title=\"Klik disini untuk exit\" style=\"color:red;\">Exit</a>
//                                </font>";
//                      }
//                      else
//                      {                          
                          echo "    <script language=\"javascript\">
                                    
                                        USETEXTLINKS = 1;
                                        STARTALLOPEN = 0;
                                        ICONPATH = '".PATH_MODULE."/treeview/';";
                          echo "        foldersTree = gFld(\"\",\"<b>$FOLDERTREECAPTION</b>\", \"javascript:void(0)\",\"return false;\");
                                        foldersTree.treeID = \"trvPORTAL\";";
                                        
                                        if($MODULENAME=='dbconfig')
                                        {
                                            echo "aux1 = insFld(foldersTree, gFld(\"\",\"Database Config\", \"javascript:void(0)\",\"return false;\"));
                                                         insDoc(aux1, gLnk(\"S\", \"ORG / Sub Dept\",\"javascript:void(0)\",\"fn_loadObjectTo$TARGETTYPE('$TARGETNAME','?ajax=1&init_java=1&option=com_fsconfig&obj=fsconfig_org')\"));
                                                         insDoc(aux1, gLnk(\"S\", \"Employee\", \"javascript:void(0)\",\"fn_loadObjectTo$TARGETTYPE('$TARGETNAME','?ajax=1&init_java=1&option=com_fsconfig&obj=fsconfig_employee')\"));
                                                         insDoc(aux1, gLnk(\"S\", \"Vendor\", \"javascript:void(0)\",\"fn_loadObjectTo$TARGETTYPE('$TARGETNAME','?ajax=1&init_java=1&option=com_fsconfig&obj=fsconfig_vendor')\"));
                                                         insDoc(aux1, gLnk(\"S\", \"Invoice Status\", \"javascript:void(0)\",\"fn_loadObjectTo$TARGETTYPE('$TARGETNAME','?ajax=1&init_java=1&option=com_fsconfig&obj=fsconfig_invstatus')\"));
                                                         insDoc(aux1, gLnk(\"S\", \"Menu Setting\", \"javascript:void(0)\",\"fn_loadObjectTo$TARGETTYPE('$TARGETNAME','?ajax=1&init_java=1&option=com_fsconfig&obj=fsconfig_menu')\"));";
                                            
                                        }
                                        if($MODULENAME=='bukubank')
                                        {
                                            echo "aux0 = insFld(foldersTree, gFld(\"\",\"Setting\", \"javascript:void(0)\",\"return false;\"));
                                                    //aux2 = insFld(aux1, gFld(\"\",\"Setting\", \"javascript:void(0)\",\"return false;\"));                                                         
                                                    //aux3 = insFld(aux2, gFld(\"\",\"Management R/K\", \"javascript:void(0)\",\"return false;\"));
                                                         insDoc(aux0, gLnk(\"S\", \"Daftar Nomor Giro/Cek\",\"javascript:void(0)\",\"fn_loadObjectTo$TARGETTYPE('$TARGETNAME','?ajax=1&init_java=1&option=com_fsbukubank&obj=fsbukubank_nmrgiro')\"));
                                                         insDoc(aux0, gLnk(\"S\", \"Register Bank\",\"javascript:void(0)\",\"fn_loadObjectTo$TARGETTYPE('$TARGETNAME','?ajax=1&init_java=1&option=com_fsbukubank&obj=fsbukubank_daftarbank')\"));
                                                         //insDoc(aux0, gLnk(\"S\", \"Tipe Transaksi\",\"javascript:void(0)\",\"fn_loadObjectTo$TARGETTYPE('$TARGETNAME','?ajax=1&init_java=1&option=com_fsbukubank&obj=fsbukubank_tipetransaksi')\"));
                                                         //insDoc(aux3, gLnk(\"S\", \"No Rekening\",\"javascript:void(0)\",\"fn_loadObjectTo$TARGETTYPE('$TARGETNAME','?ajax=1&init_java=1&option=com_fsbukubank&obj=fsbukubank_rekening')\"));
                                                         insDoc(aux0, gLnk(\"S\", \"Pejabat Ttd Cek/BG\",\"javascript:void(0)\",\"fn_loadObjectTo$TARGETTYPE('$TARGETNAME','?ajax=1&init_java=1&option=com_fsbukubank&obj=fsbukubank_pejabatttd')\"));                                                         
                                                         insDoc(aux0, gLnk(\"S\", \"Setting Periode\",\"javascript:void(0)\",\"fn_loadObjectTo$TARGETTYPE('$TARGETNAME','?ajax=1&init_java=1&option=com_fsbukubank&obj=fsbukubank_period')\"));                                                                                                           
                                                  aux1 = insFld(foldersTree, gFld(\"\",\"Buku Bank\", \"javascript:void(0)\",\"return false;\"));
                                                         insDoc(aux1, gLnk(\"S\", \"Saldo Awal\", \"javascript:void(0)\",\"fn_loadObjectTo$TARGETTYPE('$TARGETNAME','?ajax=1&init_java=1&option=com_fsbukubank&obj=fsbukubank_saldoawal')\")); 
                                                  aux4 = insFld(aux1, gFld(\"\",\"Transaksi\", \"javascript:void(0)\",\"return false;\"));                                                                
                                                  aux5 = insFld(aux4, gFld(\"\",\"Penerimaan\", \"javascript:void(0)\",\"return false;\"));
                                                         insDoc(aux5, gLnk(\"S\", \"Dropping Budget\", \"javascript:void(0)\",\"fn_loadObjectTo$TARGETTYPE('$TARGETNAME','?ajax=1&init_java=1&option=com_fsbukubank&obj=fsbukubank_dropping')\"));
                                                         insDoc(aux5, gLnk(\"S\", \"Jurnal Dropping\", \"javascript:void(0)\",\"fn_loadObjectTo$TARGETTYPE('$TARGETNAME','?ajax=1&init_java=1&option=com_fsbukubank&obj=fsbukubank_jurnaldropping')\"));
                                                         insDoc(aux5, gLnk(\"S\", \"Others(Jasa,giro) dll.\", \"javascript:void(0)\",\"fn_loadObjectTo$TARGETTYPE('$TARGETNAME','?ajax=1&init_java=1&option=com_fsbukubank&obj=fsbukubank_trxin')\"));
                                                  aux6 = insFld(aux4, gFld(\"\",\"Pengeluaran\", \"javascript:void(0)\",\"return false;\"));
                                                         insDoc(aux4, gLnk(\"S\", \"Untransfered GL\",\"javascript:void(0)\",\"fn_loadObjectTo$TARGETTYPE('$TARGETNAME','?ajax=1&init_java=1&option=com_fsbukubank&obj=fsbukubank_untransferedgl')\"));
                                                         insDoc(aux4, gLnk(\"S\", \"Check In Transit\",\"javascript:void(0)\",\"fn_loadObjectTo$TARGETTYPE('$TARGETNAME','?ajax=1&init_java=1&option=com_fsbukubank&obj=fsbukubank_checkintransit')\"));   
                                                         insDoc(aux6, gLnk(\"S\", \"Posting FPJP\", \"javascript:void(0)\",\"fn_loadObjectTo$TARGETTYPE('$TARGETNAME','?ajax=1&init_java=1&option=com_fsbukubank&obj=fsbukubank_postingfpjp')\"));
                                                         insDoc(aux6, gLnk(\"S\", \"Others(Biaya) dll.\", \"javascript:void(0)\",\"fn_loadObjectTo$TARGETTYPE('$TARGETNAME','?ajax=1&init_java=1&option=com_fsbukubank&obj=fsbukubank_trxout')\"));
                                                         //insDoc(aux1, gLnk(\"S\", \"Reposting/Unposting\", \"javascript:void(0)\",\"fn_loadObjectTo$TARGETTYPE('$TARGETNAME','?ajax=1&init_java=1&option=com_fsbukubank&obj=fsbukubank_reposting')\"));
                                                         insDoc(aux1, gLnk(\"S\", \"Buku Bank\", \"javascript:void(0)\",\"fn_loadObjectTo$TARGETTYPE('$TARGETNAME','?ajax=1&init_java=1&option=com_fsbukubank&obj=fsbukubank_bukubank')\"));
                                                         insDoc(aux1, gLnk(\"S\", \"Cash Flow\", \"javascript:void(0)\",\"fn_loadObjectTo$TARGETTYPE('$TARGETNAME','?ajax=1&init_java=1&option=com_fsbukubank&obj=fsbukubank_cashflow')\"));
                                                         insDoc(aux1, gLnk(\"S\", \"Bilyet Giro/Cheque\", \"javascript:void(0)\",\"fn_loadObjectTo$TARGETTYPE('$TARGETNAME','?ajax=1&init_java=1&option=com_fsbukubank&obj=fsbukubank_bilyetgiro')\"));
                                                         insDoc(aux1, gLnk(\"S\", \"Closing\", \"javascript:void(0)\",\"fn_loadObjectTo$TARGETTYPE('$TARGETNAME','?ajax=1&init_java=1&option=com_fsbukubank&obj=fsbukubank_closingbukubank')\"));
                                                  aux7 = insFld(foldersTree, gFld(\"\",\"Buku Kas\", \"javascript:void(0)\",\"return false;\"));                                                  
                                                         insDoc(aux7, gLnk(\"S\", \"Saldo Awal\", \"javascript:void(0)\",\"fn_loadObjectTo$TARGETTYPE('$TARGETNAME','?ajax=1&init_java=1&option=com_fsbukubank&obj=fsbukubank_saldoawalbukukas')\")); 
                                                         insDoc(aux7, gLnk(\"S\", \"Posting FPJP\",\"javascript:void(0)\",\"fn_loadObjectTo$TARGETTYPE('$TARGETNAME','?ajax=1&init_java=1&option=com_fsbukubank&obj=fsbukubank_postingfpjpbukukas')\"));
                                                         insDoc(aux7, gLnk(\"S\", \"Create FPJP\",\"javascript:void(0)\",\"fn_loadObjectTo$TARGETTYPE('$TARGETNAME','?ajax=1&init_java=1&option=com_fsbukubank&obj=fsbukubank_createfpjpbukukas')\"));                                                         
                                                         insDoc(aux7, gLnk(\"S\", \"Buku Kas\", \"javascript:void(0)\",\"fn_loadObjectTo$TARGETTYPE('$TARGETNAME','?ajax=1&init_java=1&option=com_fsbukubank&obj=fsbukubank_bukukas')\"));
                                                         insDoc(aux7, gLnk(\"S\", \"Adjustment\", \"javascript:void(0)\",\"fn_loadObjectTo$TARGETTYPE('$TARGETNAME','?ajax=1&init_java=1&option=com_fsbukubank&obj=fsbukubank_bukukasadjustment')\"));
                                                         insDoc(aux7, gLnk(\"S\", \"Closing\", \"javascript:void(0)\",\"fn_loadObjectTo$TARGETTYPE('$TARGETNAME','?ajax=1&init_java=1&option=com_fsbukubank&obj=fsbukubank_closingbukukas')\"));";
                                        }
                                        
                                        //$qry="select menuid from ".DB_FAS.".tbl_user_auth where nik='".$_SESSION['nik']."' order by id asc";
//                                        $rsmenuid=$this->selectquery($qry);
//                                        if($rsmenuid)
//                                        {
//                                            if($this->REC_ROWS_COUNT($rsmenuid)>0)
//                                            {
//                                                while($rw=$this->data_row_object($rsmenuid))
//                                                {
//                                                    $menuid=$rw->menuid;
//                                                    if($menuid)    
//                                                    {
//                                                        $qry="select mnu.* from tbl_menumnu inner join 
//                                                                                tbl_user_auth auth on mnu.root=auth.root                                                                    
//                                                              where auth.nik='".$_SESSION['nik']."' and mnu.menuid in($menuid)
//                                                              order by mnu.menuid asc "; 

//                                                        $rsauth=$this->selectquery($qry);
//                                                        if($rsauth)
//                                                        {
//                                                            if($this->REC_ROWS_COUNT($rsauth)>0)
//                                                            {
//                                                                while($rwauth=$this->data_row_object($rsauth))
//                                                                {
//                                                                    echo $rwauth->treeview.";";                                                    
//                                                                }                                            
//                                                            }
//                                                        }
//                                                        $this->clearrecordset($rsauth);                                        
//                                                    }
//                                                    else
//                                                    {
//                                                        if($_SESSION['nik']=='9999')  // just for user 9999
//                                                        {
//                                                        echo "config= insFld(foldersTree, gFld(\"\",\"Configuration\", \"javascript:void(0)\",\"return false;\"));
//                                                              insDoc(config, gLnk(\"_self\",\"Add root\",\"javascript:void(0)\", \"fn_loadObject(\'obj_root\',\'DIV_BODY\');return false;\"));
//                                                              insDoc(config, gLnk(\"_self\",\"User Accessibility\",\"javascript:void(0)\", \"fn_loadObject(\'obj_user\',\'DIV_BODY\');return false;\"));                                                            insDoc(config, gLnk(\"_self\",\"My Menu\",\"javascript:void(0)\", \"fn_mnuConfig();return false;\"));";
//                                                        }                                                  
//                                                    }
//                                                }   
//                                            }
//                                            else
//                                            {
//                                                if($_SESSION['nik']=='9999')  // just for user 9999
//                                                {
//                                                echo "config= insFld(foldersTree, gFld(\"\",\"Configuration\", \"javascript:void(0)\",\"return false;\"));
//                                                      insDoc(config, gLnk(\"_self\",\"Add root\",\"javascript:void(0)\", \"fn_loadObject(\'obj_root\',\'DIV_BODY\');return false;\"));
//                                                      insDoc(config, gLnk(\"_self\",\"User Accessibility\",\"javascript:void(0)\", \"fn_loadObject(\'obj_user\',\'DIV_BODY\');return false;\"));                                                            
//                                                      insDoc(config, gLnk(\"_self\",\"My Menu\",\"javascript:void(0)\", \"fn_mnuConfig();return false;\"));";
//                                                }
//                                            }
//                                        }
//                                        $this->clearrecordset($rsmenuid);
                           echo "       signout = insFld(foldersTree, gFld(\"\",\"Sign Out\", \"index.php?opt=sign_out\",\"return confirmsignout();\"));
                                        function fn_loadObjectToDiv(objname,url_target,root,task)
                                        {                                            
                                            params='ajax=1&opt='+objname;
                                            if(root){params=params+'&root='+root;}
                                            if(task){params=params+'&case='+task;}
                                            loadObject(params,url_target,'Wait');
                                            //alert(params);
                                        }
                                        
                                        function fn_loadObjectToFrame(iframename,url_target)
                                        {                                            
                                            var objFrame=document.getElementById(iframename);
                                            objFrame.src=url_target;
                                        }
                                        
                                        
                                        function confirmsignout()
                                        {
                                            if(confirm('Anda ingin keluar ?'))
                                            {return true;}
                                            else
                                            {return false;}
                                        }
                                        function fn_mnuConfig(msg)
                                        {
                                            if(msg){alert(msg);}
                                            params='ajax=1&opt=obj_menu';
                                            loadObject(params,'".DIV_BODY."','Wait');
                                        }                                        
                                    </script>                  
                                    <table border=0>
                                        <tr>
                                            <td>
                                                <a href=\"http://www.treem.com/\" target=\"_blank\" onClick=\"return false;\" style=\"color:blue;\">
                                                    &nbsp;<b><u>$TREEVIEHEADER</u></b>
                                                </a>
                                            </td>
                                        </tr>
                                    </table>                       
                                    <SCRIPT>initializeDocument();</SCRIPT>";
                   //   }
//                  }
//                  $this->clearrecordset($rsmnu);
                  // ========================================================
            
        }
        
        public function enc($stringvalues)
        {           
            $obj_enc= new AES(AES::AES128);
            $rtn=$obj_enc->stringToHex($stringvalues);
            $rtn=$obj_enc->encrypt($rtn,AES_128);
            
            return $rtn;
        }
        
        
        public function dec($stringvalues)
        {
            $obj_enc= new AES(AES::AES128); 
            $rtn=$obj_enc->decrypt($stringvalues,AES_128);
            $rtn=$obj_enc->hexToString($rtn);                
            
            return $rtn;
        }
        
        public function fn_loadnews()
        {
            echo "<div id=\"spage\" style=\"overflow:hidden;width:500px; height:24px; \"></div>
                  <script language=\"javascript\">
                        var text = new Array();
                        var header = new Array();
                        var linka = new Array();
                        var targa = new Array();
                        var paginationa = new Array();";
                       
                        $qry="select * from ".DB_APORTIL.".tbl_news where cast(tglupdate as date)=cast('".date("Y-m-d")."' as date) order by timeupdate desc";
                        $rsnews=$this->selectquery($qry);
                        if($rsnews)
                        {
                            if($this->REC_ROWS_COUNT($rsnews)>0)
                            {
                                $i=0;
                                while($rw=$this->data_row_object($rsnews))
                                {
                                    echo "header[".$i."]=\"".$rw->timeupdate."\";";
                                    echo "text[".$i."]=\"".$rw->title.". \";";
                                    echo "linka[".$i."]=\"".$rw->url.". \";";
                                    echo "targa[".$i."]=\"_parent\";";
                                    echo "paginationa[".$i."]=\"\";";
                                    $i+=1;
                                }                                                             
                            }
                            else
                            {
                                echo "header[0]=\"Version 2.0\";";
                                echo "text[0]=\"Finance Services Area Sumatera\";";
                                echo "linka[0]=\"#\";";
                                echo "targa[0]=\"_parent\";";
                                echo "paginationa[0]=\"\";";
                            }
                        }
                        $this->clearrecordset($rsnews);
                        //header[0] = \"15 Marc 2012 :\"; 
//                        text[0] = \"Kurs Rupiah Hari ini terhadap mata uang negara lain. \";
//                        linka[0] = \"http://kurs.dollar.web.id/\"; //?popup=1&option=com_news
//                        targa[0] = \"_parent\";
//                        paginationa[0] = \"\";

//                        header[1] = \"14 Marc 2012\";
//                        text[1] = \"Bakrie Tawarkan Saham Operator Esia ke Sampoerna.\";
//                        linka[1] = \"http://finance.detik.com/read/2012/03/14/180206/1867456/6/bakrie-tawarkan-saham-operator-esia-ke-sampoerna-incar-rp-900-miliar?f990101mainnews\";
//                        targa[1] = \"_parent\";
//                        paginationa[1] = \"\";

//                        header[2] = \"14 Marc 2012\";
//                        text[2] = \"Tolak Kenaikan BBM, Buruh Ancam Segel SPBU.\";
//                        linka[2] = \"http://www.tempo.co/read/news/2012/03/14/173390104/Tolak-Kenaikan-BBM-Buruh-Ancam-Segel-SPBU\";
//                        targa[2] = \"_parent\";
//                        paginationa[2] = \"\";
            echo "</script>
                  <script language=\"javascript\" charset=\"utf-8\" src=\"themes/finance/js/mynews.js\"></script>";
        }
        
        public function fn_checkmybrowser()
        {
            $nav=strtolower($_SERVER['HTTP_USER_AGENT']);
            //echo $nav;exit();
            if(ereg("msie",$nav))
            {
                //echo "<script>window.location.href='http://10.33.97.172/fast/';</script>";
                //exit();
                echo "You Browser <font color=\"red\">Doesn't Support</font>&nbsp;";
                echo "Please Open it from Firefox,Chrome or Etc<br/>";
                echo "THANK YOU.";
                
                exit();
            }
        }
        
        public function fn_getbrowserversion()
        {
            $spbrowser=explode(";",$_SERVER['HTTP_USER_AGENT']);
            return trim($spbrowser[1]);
        }
        
        public function SET_ERROR_LOG($logname,$modulename,$functionname,$logtime,$msglog)
        {
                 $filename= "log/".$logname.".txt";
                 $filehandle= fopen($filename, "a") or die("can't open file");
                 $log=$modulename." ".$functionname."   ".$logtime."    ".$msglog;
                 $log.="\r\n";
                 file_put_contents($filename,$log,FILE_APPEND);
                 fclose($filehandle);
        }
        
        public function fn_row_isexists($query)
        {
            $rtn=false;
            $rschk=mysql_query($query) or die(mysql_error());
            if($rschk)
            {
                if(mysql_num_rows($rschk)>0){$rtn=true;}
            }
            $this->clearrecordset($rschk);
            return $rtn;
        }
        
        // ===== Convert date to Mysql Format    
        public function fn_convdatetomysql($datevalue)
        {
            $dtsplit=explode("/",$datevalue);
            return $dtsplit[2]."-".$dtsplit[1]."-".$dtsplit[0]; //conversi date format d/m/Y ke YYYY-mm-dd
        }
        
        public function fn_get_fieldvalue($fieldname,$query)
        {
            $rtn='';
            $rsgetvalue=mysql_query($query) or die(mysql_error());
            if($rsgetvalue)
            {
                if(mysql_num_rows($rsgetvalue)>0)
                {
                    $rw=mysql_fetch_object($rsgetvalue);
                    $rtn=$rw->$fieldname;
                }
            }
            $this->clearrecordset($rsgetvalue);
            return $rtn;
        }
        
        function fn_token_load()
        {
            $keyword=$_POST['keyword'];
            $table=$_POST['table'];
            $spcol=explode(",",$_POST['col']);
            $col1=$spcol[0];$col2=$col1;$colwhere=$col1;$colorder=$col1;
            if(count($spcol)>1)
            {
                $col2=$spcol[1];$colwhere=$col2;$colorder=$col2;
                $spcol2=explode("|",$col2);
                if(count($spcol2)>1)
                {
                    //$col2="concat(".$spcol2[0].",' ( ',".$spcol2[1].",' ) ') fld1";    
                    $col2="concat(".$spcol2[0].",' ( ',".$spcol2[1].",' )') f";    
                    $colwhere=$spcol2[0];$colorder=$spcol2[0];
                }
                
            };
            
            $qry="select $col1,$col2 from ".DB_APORTIL.".$table where isdeleted=0 and lower($colwhere) like lower('%$keyword%') order by $colorder asc";
            $rs=$this->selectquery($qry);
            if($rs)
            {
                if($this->REC_ROWS_COUNT($rs)>0)
                {
                    $p="";
                    while($rw=$this->data_row_array($rs))
                    {
                        $p.="{\"id\":\"".$rw[0]."\",\"label\":\"".$rw[1]."\"},";
                    }
                    $p="[".substr($p,0,strlen($p)-1)."]";
                }
            }
            $this->clearrecordset($rs);
            echo $p;
            //echo json_encode($arr);
        }
        
        public function fn_get_fieldsvalues($fieldsname,$query)
        {
            $rtn='';
            $spfields=explode(",",trim($fieldsname));
            $rsgetvalue=$this->selectquery($query);
            if($rsgetvalue)
            {
                if(mysql_num_rows($rsgetvalue)>0)
                {
                    $rw=mysql_fetch_object($rsgetvalue);
                    for($i=0;$i<=count($spfields)-1;$i++)
                    {
                        $rtn.=$rw->$spfields[$i]."|";    
                    }
                    $rtn=substr($rtn,0,strlen($rtn)-1);
                }
            }
            $this->clearrecordset($rsgetvalue);            
            $rtn=explode("|",$rtn);
            
            return $rtn;
        }
        
        //public function selectquery($query,$mysql_error=null)
//        {
//            $rsqry=mysql_query($query);
//            if(!$mysql_error){$mysql_error=mysql_error();}
//            if(!$rsqry){$rsqry=$mysql_error;}
//            return $rsqry;
//        }
        
        public function selectquery($query,$mysql_error=null)
        {
            $rsqry=@mysql_query($query);
            if(!$mysql_error){$mysql_error=mysql_error();}
            if(!$rsqry){echo $mysql_error;return false;}
            return $rsqry;
        }
        
        public function data_row_object($recordset)
        {
             return mysql_fetch_object($recordset);
        }
        
        public function data_row_array($recordset)
        {
             return mysql_fetch_array($recordset);
        }
        
        public function field_length($recordset)
        {
            return mysql_num_fields($recordset);
        }
        
        public function getErrorQuery()
        {
            return $this->errquery;
        }
        public function executequery($query)
        {
            if(mysql_query($query))
            {return true;}
            else
            {$this->errquery=mysql_error(); die(mysql_error());return false;}
        }
        
        public function REC_ROWS_COUNT($recordset){return mysql_num_rows($recordset);}
        
        public function cdateDMY($datestring)
        {
            $rtn="";
            if($datestring){$rtn=date("d/m/Y",strtotime($datestring));}
            return $rtn;
        }
        
        public function fn_arrthnakademik()
        {
            $rtn=array();
            $dateserver=$this->fn_getserverinfodate("year").'-'.$this->fn_getserverinfodate('mon').'-'.$this->fn_getserverinfodate('mday');
            //echo $dateserver;return false;
            $qry="select thn,tipesemester from ".DB_APORTIL.".tbl_thnakademik 
                  where (cast('$dateserver' as date) between cast(startdate as date) and cast(enddate as date)) and isdeleted=0";//echo $kdkelas;
            //echo $qry;return false;
            if($this->fn_row_isexists($qry))
            {
                $rtn=$this->fn_get_fieldsvalues("thn,tipesemester",$qry);    
            }
            return $rtn;
        }
        
        public function cdateYMD($datestring)
        {
            $rtn="";
            if($datestring){$rtn=date("Y-m-d",strtotime($datestring));}
            return $rtn;
        }
        
        public function cdatetimeYMD($datestring)
        {
            return date("Y-m-d H:i:s",strtotime($datestring));
        }
        
        public function datediffday($startdatetonumber,$enddatetonumber)
        {
            return $enddatetonumber-$startdatetonumber;
        }
        
        public function datediff($startdate,$enddate)
        {
            $rtn='';
            if($startdate && $enddate)
            {
                $startdate=strtotime($startdate);$divided=1;
                if(!is_numeric(($enddate))){$enddate=strtotime($enddate);$divided=24;}
                $rtn=$enddate-$startdate;
                $rtn=floor(($rtn/(3600*24))/$divided); 
            }
            
            return $rtn;
        }

        public function clearrecordset($recordset){mysql_free_result($recordset);}
        
        public function en($paramsvalue)
        {
            $rtn='';
            for($i=0;$i<=strlen($paramsvalue);$i++){$rtn.=chr(floor(ord(substr($paramsvalue,$i,1))*0.99));}
            return $rtn;
        }
        
        public function de($paramsvalue)
        {
            $rtn='';
            for($i=0;$i<=strlen($paramsvalue);$i++){$rtn.=chr(ceil(ord(substr($paramsvalue,$i,1))/0.99));}
            return $rtn;
        }
        
        public function fn_convert_angkaTOHuruf($angka)
        {
            $rtn='';
            switch($angka)
            {
                case 1:$rtn='Satu';break;
                case 2:$rtn='Dua';break;
                case 3:$rtn='Tiga';break;
                case 4:$rtn='Empat';break;
                case 5:$rtn='Lima';break;
                case 6:$rtn='Enam';break;
                case 7:$rtn='Tujuh';break;
                case 8:$rtn='Delapan';break;
                case 9:$rtn='Sembilan';break;
                case 11:$rtn='Sebelas';break;
                case 12:$rtn='Dua Belas';break;
                case 13:$rtn='Tiga Belas';break;
                case 14:$rtn='Empat Belas';break;
                case 15:$rtn='Lima Belas';break;
                case 16:$rtn='Enam Belas';break;
                case 17:$rtn='Tujuh Belas';break;
                case 18:$rtn='Delapan Belas';break;
                case 19:$rtn='Sembilan Belas';break;
            }
            
            return $rtn;
        }
        
        public function fn_terbilang($bil)
        {
            $rtn='';         //2,810,000
            $arrbil=explode(',',$bil);
            for($i=0;$i<=count($arrbil)-1;$i++)
            {
                if(strlen($arrbil[$i])==1){$arrbil[$i]='00'.$arrbil[$i];}  //002
                if(strlen($arrbil[$i])==2){$arrbil[$i]='0'.$arrbil[$i];}
                
                for($j=0;$j<=strlen($arrbil[$i])-1;$j++)
                {                           
                    if(substr($arrbil[$i],$j,1)!=='0')
                    {
                        // ======== digit pertama
                        if($j==0)
                        {
                            
                            if(substr($arrbil[$i],$j,1)=='1')
                            {$rtn.='Seratus ';}
                            else
                            {$rtn.=$this->fn_convert_angkaTOHuruf(substr($arrbil[$i],$j,1)).' Ratus ';}
                        }
                        
                        // ======== digit kedua
                        if($j==1)
                        {
                            if(substr($arrbil[$i],$j,1)=='1')
                            {
                                if(substr($arrbil[$i],2,1)=='0')
                                {$rtn.=' Sepuluh ';}
                                else
                                {$rtn.=$this->fn_convert_angkaTOHuruf(substr($arrbil[$i],$j,2));}
                                break;
                            }
                            else
                            {$rtn.=$this->fn_convert_angkaTOHuruf(substr($arrbil[$i],$j,1)).' Puluh ';} 
                        }
                        
                        // ======== digit ketiga
                        if($j==2)
                        {
                            if(substr($arrbil[$i],$j,1)!=='0')
                            {    
                                if(count($arrbil)==2)
                                {
                                    if(substr($arrbil[0],0,1)=='0'&&substr($arrbil[0],1,1)=='0'&&substr($arrbil[0],2,1)=='1')
                                    {$rtn.=' ';}                            
                                    else
                                    {$rtn.=$this->fn_convert_angkaTOHuruf(substr($arrbil[$i],$j,1));}    
                                }
                                else
                                {$rtn.=$this->fn_convert_angkaTOHuruf(substr($arrbil[$i],$j,1));}
                            }
                        }
                    }
                }
                
                if($arrbil[$i]!=='000')
                {
                    // ======== satuan per milyar rupiah
                    if(count($arrbil)==4) 
                    {
                        if($i==0){$rtn.=' Milyar ';}
                        if($i==1){$rtn.=' Juta ';}
                        if($i==2){$rtn.=' Ribu ';}
                    }
                    
                    // ======== satuan per Ratusan Juta rupiah
                    if(count($arrbil)==3) 
                    {
                        if($i==0){$rtn.=' Juta ';}
                        if($i==1){$rtn.=' Ribu ';}
                    }
                    
                    //======== satuan per Ratus ribu rupiah
                    if(count($arrbil)==2) 
                    {
                        if($i==0)
                        {
                            if(substr($arrbil[0],0,1)=='0'&&substr($arrbil[0],1,1)=='0'&&substr($arrbil[0],2,1)=='1')
                            {$rtn.=' Seribu ';}
                            else
                            {$rtn.=' Ribu ';}
                            
                        }
                    }
                }
            }
            
            return $rtn.' Rupiah';
        }
        
        public function fn_sentTomail($SENDER,$ALIASSENDER,$TO=array(),$SUBJECT,$MSG,$SHOWREPORTING=true)
        {
            //print_r($SENDER);
            $rtn="";
            require_once "swift/lib/swift_required.php";
            // Create the Transport
            $transport = Swift_SmtpTransport::newInstance('smtprelay.telkomsel.co.id', 25);
            // Create the Mailer using your created Transport
            $mailer = Swift_Mailer::newInstance($transport);
            //$SENDER = array("Finance@telkomsel.co.id"=>"Finance Telkomsel");
            // Create a message
            $message = Swift_Message::newInstance($SUBJECT);
            $message->setFrom(array($SENDER=>$ALIASSENDER));
            if(!is_array($TO)){$TO=array($TO);}
            //echo $TO;
            //array_push($TO,"itnsr09@gmail.com");
            $message->setTo($TO);
            $message->setBody($MSG);

            // Send the message
            $result=$mailer->send($message);
            if($result)
            {
                if($SHOWREPORTING)
                {
                    $receipent="";
                    for($i=0;$i<count($TO);$i++)
                    {
                        $receipent.=$TO[$i].",";
                    }
                    $receipent=substr($receipent,0,strlen($receipent)-1);
                    echo "<table width=\"400px\" align=\"center\" border=\"0\">
                              <tr>
                                  <td align=\"left\"  valign=\"top\" width=\"2px;\">";
                                      echo "<img src=\"".PATH_THEME."/images/ok.gif\" />";
                    echo "        </td>
                                  <td valign=\"top\" align=\"left\">Message has been sent to $receipent</td>
                              </tr>
                          </table><br/>";                    
                }
                $rtn=true;
            }
            else
            {
                if($SHOWREPORTING)
                {
                    echo "<table width=\"400px\" align=\"center\" border=\"0\">
                              <tr>
                                  <td align=\"left\"  valign=\"top\" width=\"2px;\">";
                                      echo "<img src=\"".PATH_THEME."/finance/images/failed.png\" />";
                    echo "        </td>
                                  <td valign=\"top\" align=\"left\" style=\"color:red;\">Message not sent to <b>$receipent</b></td>
                              </tr>
                          </table><br/>";        
                }
                $rtn=false;
            }
            
            return $rtn;
        }
        
        public function fn_getserverinfodate($params)
        {
            //date_default_timezone_set('America/Chicago');
            $infodate=getdate();
            //$date = $infodate['mday'];
//            $month = $infodate['mon'];
//            $year = $infodate['year'];
//            $hour = $infodate['hours'];
//            $min = $infodate['minutes'];
//            $sec = $infodate['seconds'];
            return $infodate[$params];
        }
        
        public function fn_getdateserver()
        {
            date_default_timezone_set('Asia/Jakarta');
            $rtn="";
            $infodate=getdate();
            $rtn=date("Y-m-d",strtotime($infodate['year']."-".$infodate['mon']."-".$infodate['mday']));
            //$date = $infodate['mday'];
//            $month = $infodate['mon'];
//            $year = $infodate['year'];
//            $hour = $infodate['hours'];
//            $min = $infodate['minutes'];
//            $sec = $infodate['seconds'];
            return $rtn;
        }

        public function fn_getdatetimeserver()        
        {
            date_default_timezone_set('Asia/Jakarta');
            $rtn="";
            $infodate=getdate();
            $rtn=date("Y-m-d",strtotime($infodate['year']."-".$infodate['mon']."-".$infodate['mday']));
            $rtn.=" ".$infodate['hours'].":".$infodate['minutes'].":".$infodate['seconds'];
            //$rtn=$infodate['year']."-".$infodate['mon']."-".$infodate['mday']." ".$infodate['hours'].":".$infodate['minutes'].":".$infodate['seconds'];
            //$date = $infodate['mday'];
//            $month = $infodate['mon'];
//            $year = $infodate['year'];
//            $hour = $infodate['hours'];
//            $min = $infodate['minutes'];
//            $sec = $infodate['seconds'];
            return $rtn;
        }
        
        public function fn_sendSMS($msisdn,$message)
        {
            try
            {
                $host="10.xx.xx.xx:8800";
                $smscontent=urlencode($message);
                $fp=fsockopen($host,80,$errno, $errstr, 30);
                fputs($fp, "GET $path?PhoneNumber=".$msisdn."&Text=$smscontent&Submit=Submit&User=fast&Password=telkomsel HTTP/1.0\n\n");
                fclose($fp);
            }
            catch(Exception $e)
            {
                echo "<font color=\"red\">".$e->getMessage()."</font>";    
            }
        }        
        
    }
    
?>
