This is default featured post 1 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

This is default featured post 2 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

This is default featured post 3 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

This is default featured post 4 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

This is default featured post 5 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

Friday, January 28, 2011

Simple General Helper on Code Igniter

  1. Create general_helper.php on /sytem/application/helpers.
  2. <?php
    
    /**
     * change date format from dd/mm/yyyy become yyyy-mm-dd
     * @param <type> $date
     * @return string
     */
    function encode_date($date) {
        list($day, $month, $year) = explode('/', $date);
        $new_date = $year . "-" . $month . "-" . $day;
        return $new_date;
    }
    
    /**
     * change date format from yyyy-mm-dd become dd/mm/yyyy
     * @param <type> $date
     * @return string
     */
    function decode_date($date) {
        list($year, $month, $day) = explode('-', $date);
        $new_date = $day . "/" . $month . "/" . $year;
        return $new_date;
    }
    
    /**
     * create money value in Rupiah
     * @param <type> $uang
     * @return <type>
     */
    function format_rupiah($uang) {
        return "Rp. ". number_format($uang, 0, ",", ".");
    }
    
    function format_dana($uang) {
        return number_format($uang, 0, ".", "");
    }
            
    function indonesian_month($month) {
        switch ($month) {
            case "01" : $imonth = "Januari"; break;
            case "02" : $imonth = "Februari"; break;
            case "03" : $imonth = "Maret"; break;
            case "04" : $imonth = "April"; break;
            case "05" : $imonth = "Mei"; break;
            case "06" : $imonth = "Juni"; break;
            case "07" : $imonth = "Juli"; break;
            case "08" : $imonth = "Agustus"; break;
            case "09" : $imonth = "September"; break;
            case "10" : $imonth = "Oktober"; break;
            case "11" : $imonth = "November"; break;
            case "12" : $imonth = "Desember"; break;
            default  : $imonth = "-"; break;
        }
        return $imonth;
    }
    
    /**
     * change date format to indonesia
     * @param <type> $month
     * @return string
     */
    function indonesian_date($date) {
        list($year, $month, $day) = explode('-', $date);
        $new_date = $day ." ". indonesian_month($month) . " ". $year;
        return $new_date;
    }
    
    function indonesian_yearmonth($yearmonth) {
        list($month,$year) = explode(' ', $yearmonth);
        $new_yearmonth =  indonesian_month($month) . " ". $year;
        return $new_yearmonth;
    }
    
    function bulan_hari($day) {
        $tahun = floor($day/365);
        $bulan=floor(($day - ($tahun * 365))/30);
        $hari=$day - $bulan * 30;
        if($day=="30"){return $bulan." Bulan ";}
        elseif($day >= "30"){return $bulan." Bulan, ".$hari." Hari";}
        else{return $hari." Hari";}
    
    }
    ?>
  3. Controller script
  4. <?php
    
    /**
     * @property CI_DB_active_record $db
     */
    class tryhelper extends MY_Controller {
    
        function cobapdf() {
            parent::MY_Controller();
      $this->load->helper('general_helper');
        }
    
        function index() {
            echo indonesia_month('01');
        }
    }
    ?>
    

Exsport to PDF with dompdf in Code Igniter

  1. cDownload dompf from here and exstract the file.
  2. Then put to the directory ./system/application/plugins/.
  3. After that then create new file on ./system/application/plugins/dompdf_pi.php like this
  4. <?php
    
    if (!defined('BASEPATH'))
        exit('No direct script access allowed');
    
    /**
     * Try increasing memory available, mostly for PDF generation
     */
    ini_set("memory_limit", "32M");
    
    function pdf_create($html, $filename, $stream=TRUE, $orientation="portrait") {
        require_once(BASEPATH . "application/plugins/dompdf/dompdf_config.inc.php");
    
        $dompdf = new DOMPDF();
        $dompdf->set_paper("a4", $orientation);
        $dompdf->load_html($html);
        $dompdf->render();
        if ($stream) { //open only
            $dompdf->stream($filename . ".pdf");
        } else { // save to file only, your going to load the file helper for this one
            write_file("pdf/$filename.pdf", $dompdf->output());
        }
    }
    
    ?>
  5. Create controler mypdf.php
  6. <?php
    
    /**
     * @property CI_DB_active_record $db
     */
    class mypdf extends MY_Controller {
    
        function mypdf() {
            parent::MY_Controller();
      $this->load->plugins('dompdf_pi');
        }
    
        function index() {
         $html="Hello Word";
      $filename="Mypdf";
            pdf_create($html, $filename, $stream=TRUE, $orientation='portrait');
        }
    
     }
    ?>

Count day, month and year from two date

$tgl1 = "2009-10-01";  // 1 October 2009
$tgl2 = "2009-11-10";  // 10 October 2009

// break dates to get the date, month and year
// from the first date

$pecah1 = explode("-", $tgl1);
$date1 = $pecah1[2];
$month1 = $pecah1[1];
$year1 = $pecah1[0];

// break dates to get the date, month and year
// from the second date

$pecah2 = explode("-", $tgl2);
$date2 = $pecah2[2];
$month2 = $pecah2[1];
$year2 =  $pecah2[0];

// count JDN from each of the dates

$jd1 = GregorianToJD($month1, $date1, $year1);
$jd2 = GregorianToJD($month2, $date2, $year2);

// compute difference the second day date

$selisih = $jd2 - $jd1;
$month=floor(($selisih - ($tahun * 365))/30);
$day=$selisih - $bulan * 30;

echo "difference the both of the day date is ".$month." month ".$day." day";
This Source is originaly from www.ms-room.com

Simple Script Exsport Excel With PHP

First example
<?
header("Content-Type: application/vnd.ms-excel");
echo "<table border=1>
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
</tr>
</table>";
?>

Implementation
$header = "Header1" . "\t";
$header .= "Header2" . "\t";

//Reading the data thro' POST
$data= $_POST['header1']. "\t";
$data .= $_POST['header2'] . "\t";

header("Content-type: application/x-msdownload");
header("Content-Disposition: attachment; filename=xyz.xls");
header("Pragma: no-cache");
header("Expires: 0");
print "$header\n$data";

Recovering Ubuntu GRUB After Installing Windows

There are two method that I often use to fix the grub on ubuntu, on time after installing windows including,
First Method
  1. Boot into a LiveCD (recomanded Ubuntu 9.04)
  2. Open a terminal
  3. Open the GRUB Command-line utility by typing
  4. sudo grub
  5. Find where Grub is. If this gives a few different answers then you will need to find the correct one, perhaps by trial-and-error.
  6. find /boot/grub/stage1
  7. Tell GRUB which partition to tell the MBR your Grub is on by entering
  8. root (hdA,B)
  9. The coordinates A,B are where 'A' is the hard-drive number, starting at 0, and 'B' is the partition number, starting at 0. For example, if Ubuntu was installed on the second partition of the first hard-drive, the command should be
  10. root (hd0,1)
  11. Tell GRUB which drive's MBR to fix
  12. setup (hd0)
  13. Replace 0 only in the extremely unlikely event that your bios does not use the first hard-drive as the boot device. Typically Ubuntu might be on any drive but the bios will almost always go to the first drive's MBR to find out where to find the boot-loader.
  14. Leave the GRUB Command line
  15. quit
  16. And reboot.

If that method still dont work, you should try
Second Method
  1. Insert the Ubuntu CD (for recomanded Ubuntu 9.04) select live CD
  2. Once inside the desktop, open Terminal
  3. Check the Linux root partition is where the command
  4. sudo fdisk-l
  5. Once the device is known Linux root partition, suppose I have a /dev/sda6 and then type
  6. sudo mount-t ext4 /dev/sda6 /mnt/
    sudo mount-t proc proc /mnt/proc/ 
    sudo mount-t sysfs sys /mnt/sys/ 
    sudo mount-o bind /dev/ /mnt/dev/ 
    sudo chroot /mnt/bin/bash
  7. Install Grub on MBR command
  8. grub-install /dev/sda
  9. Install grub on linux partition
  10. grub-install /dev/sda7
  11. after all is finished please restart.