Month: August 2013

FPDF Snippet

Yeah… just like my others wrote, I don’t speak much. I just run into code. Here is the snippet;

<?php
require('fpdf17.php');

include "libConnect.php";

class PDF extends FPDF {

    //*START* FOR HTML EXTEND 
    var $B;
    var $I;
    var $U;
    var $HREF;

    function PDF($orientation = 'P', $unit = 'mm', $size = 'A4') {
    // Call parent constructor
    $this->FPDF($orientation, $unit, $size);
    // Initialization
    $this->B = 0;
    $this->I = 0;
    $this->U = 0;
    $this->HREF = '';
    }

    function WriteHTML($html) {
    // HTML parser
    $html = str_replace("\n", ' ', $html);
    $a = preg_split('/<(.*)>/U', $html, -1, PREG_SPLIT_DELIM_CAPTURE);
    foreach ($a as $i => $e) {
        if ($i % 2 == 0) {
        // Text
        if ($this->HREF)
            $this->PutLink($this->HREF, $e);
        else
            $this->Write(5, $e);
        }
        else {
        // Tag
        if ($e[0] == '/')
            $this->CloseTag(strtoupper(substr($e, 1)));
        else {
            // Extract attributes
            $a2 = explode(' ', $e);
            $tag = strtoupper(array_shift($a2));
            $attr = array();
            foreach ($a2 as $v) {
            if (preg_match('/([^=]*)=["\']?([^"\']*)/', $v, $a3))
                $attr[strtoupper($a3[1])] = $a3[2];
            }
            $this->OpenTag($tag, $attr);
        }
        }
    }
    }

    function OpenTag($tag, $attr) {
    // Opening tag
    if ($tag == 'B' || $tag == 'I' || $tag == 'U')
        $this->SetStyle($tag, true);
    if ($tag == 'A')
        $this->HREF = $attr['HREF'];
    if ($tag == 'BR')
        $this->Ln(5);
    }

    function CloseTag($tag) {
    // Closing tag
    if ($tag == 'B' || $tag == 'I' || $tag == 'U')
        $this->SetStyle($tag, false);
    if ($tag == 'A')
        $this->HREF = '';
    }

    function SetStyle($tag, $enable) {
    // Modify style and select corresponding font
    $this->$tag += ($enable ? 1 : -1);
    $style = '';
    foreach (array('B', 'I', 'U') as $s) {
        if ($this->$s > 0)
        $style .= $s;
    }
    $this->SetFont('', $style);
    }

    function PutLink($URL, $txt) {
    // Put a hyperlink
    $this->SetTextColor(0, 0, 255);
    $this->SetStyle('U', true);
    $this->Write(5, $txt, $URL);
    $this->SetStyle('U', false);
    $this->SetTextColor(0);
    }
    //*END* FOR HTML EXTEND 

}

$pdf = new PDF();

// First page
$pdf->AddPage();
$pdf->SetFont('Arial','',20);
$pdf->WriteHTML("<b>Detail Pelabuhan ".$data['nama_pelabuhan']."</b>");
$pdf->ln(21);
$pdf->SetFont('Arial','',11);
$pdf->Write(5,"Provinsi: ".$data['nm_prov']);
$pdf->ln(7);
$pdf->Write(5,"Kabupaten/Kota: ".$data['nm_kabkota']);
$pdf->ln(7);
$pdf->Write(5,"Koordinat Geografis: ".$data['latitude'].", ".$data['longitude']);
$pdf->ln(15);

$pdf->Image('http://sikhubla.net/images/pelabuhan_sample.png');

$pdf->ln(15);

//*START* INFORMATION CONTENT
    $pdf->SetFont('Arial','',16);
    $pdf->WriteHTML("<b>Informasi Umum</b>");
    $pdf->ln(10);
    $pdf->SetFont('Arial','',11);
    $pdf->SetFillColor(230,230,230);

    $ihigh = 7;

    // row 1
    $pdf->Cell(60,$ihigh,'Hierarki:',T,0,'L',true);
    $pdf->Cell(30,$ihigh,$data['hierarki'],T,1,'T',true);

    //row 2
    $pdf->Cell(60,$ihigh,'Penyelenggara:',T,0,'L');
    $pdf->Cell(30,$ihigh,$data['penyelenggara'],T,1,'L');

    //row 3
    $pdf->Cell(60,$ihigh,'Operator:',T,0,'L',true);
    $pdf->Cell(30,$ihigh,$data['operator'],T,1,'L',true);

    //row 4
    $pdf->Cell(30,$ihigh,'Kedalaman:',T,0,'L');
    $pdf->Cell(30,$ihigh,'Alur',T,0,'L');
    $pdf->Cell(30,$ihigh,$data['kedalaman_alur']." m",T,1,'R');

    //row 5
    $pdf->Cell(30,$ihigh,'',0,0,'L');
    $pdf->Cell(30,$ihigh,'Kolam',T,0,'L',true);
    $pdf->Cell(30,$ihigh,$data['kedalaman_kolam']." m",T,1,'R',true);

    //row 6
    $pdf->Cell(60,$ihigh,'Kapasitas',TB,0,'L');
    $pdf->Cell(30,$ihigh,$data['kap_tot']." ton",TB,1,'R');
//*END* INFORMATION CONTENT

$pdf->Output();

FPDF Website: http://www.fpdf.org/

And you can find another script here:

PHP Connection Snippet

Yeah… I often forget about php connection code, because it only set once in making an application 😀
Here it is

<?php
$my['host']    = "localhost";
$my['user']    = "root";
$my['pass']    = "password";
$my['dbs']    = "database_name";

$connect    = mysql_connect($my['host'], $my['user'], $my['pass']);
if (! $connect) {
  echo "Connection Fail..!";
  mysql_error();
}

// CHOOSE THE DATABASE
mysql_select_db($my['dbs'])
     or die ("Can't find the database ".mysql_error());
?>

Jquery Mobile Popup Window Snippet

This is code snippet for jquery mobile popup window.

<a href="#popupDialog{{ $acc->ID }}" data-rel="popup" data-position-to="window" data-inline="true" data-transition="pop" data-theme="b">Delete</a>
<!-- dialog -->
<div data-role="popup" id="popupDialog{{ $acc->ID }}" data-overlay-theme="a" data-theme="a" data-dismissible="false" style="max-width:400px;">
    <div data-role="header" data-theme="a">
        <h1>Confirm</h1>
    </div>
    <div data-role="content" data-theme="d">
        <p>This action cannot be undone.</p><p>Are you sure want to delete {{ $acc->ID }}?</p>
        <a href="#" data-role="button" data-inline="true" data-rel="back" data-theme="c">Cancel</a>
        <a href="#" data-role="button" data-inline="true" data-rel="back" data-transition="flow" data-theme="b" id="yesConfirm" onclick="alert('test {{ $acc->ID }}');">Yes</a>
    </div>
</div>
<!-- dialog -->

Jquery Ajax POST Snippet

This is how to do with jquery ajax with post method snippet;

<div>
    <input type="text" id="one" name="one">
    <input type="text" id="two" name="two">
    <div id="btnSubmit">Submit</div>
</div>
<script>
    $("#btnSubmit").click(function(){
        var data = "one="+$("#one").val()+"&two="+$("#two").val();
       $.post("/url_to_save_data",data).done(function(){
           window.location.href="/url_to_redirect";
       });
    });
</script>

And the other one is:

<form id="nu_form">
    <input type="text" name="a_name" />
    <input type="text" name="something" />
 <input type="submit" value="save" id="btn_save" />
</form>
<script>
$("#btn_save").click(function(){ 
    $.ajax({ 
        data: $("#nu_form").serialize(), 
        type: 'POST',  
        url: '/save_data', 
        success: function(response) { 
            alert(response); } 
    }); 
    return false; 
});
</script>

Step by Step Installing Unity 3D on Ubuntu 12.04

If your working OS just an Ubuntu like me, You have some trouble because Unity 3d just create for Windows and Mac.
If you want to make it work on your Ubuntu, I will guide you step by step:

1. Run Winetricks

unity01

Select the default wineprefix and press OK

2. You will be asking help wineprefix, just press no

3. Install a font

4. Select all of them just like picture below

02

5. Run wineprefix again

6. Install DLL or component

7. Select d3dx9

8. Run wineprefix again

9. Change settings

10. Forcemono

11. Choose run regedit

HKEY_LOCAL_MACHINE

– Software

– Microsoft

– Windows NT

– CurrentVersion [select]

03

10.