Friday, 29 January 2016

Full Calender Using Codeignter Which is Came from Database

Well this is my screen shot for you , please see the url so you can goes to file later on will be upload to dropbox












then in controller i use select data using where clause please see in controller
 public function date()  
   {  
     $this->db->select('*');  
     $this->db->from('cu_date_cuti');  
     $this->db->where('cu_date_cuti_id','1');  
     $query = $this->db->get();  
     foreach ($query->result_array() as $row)  
       {  
          $new_row['title']=htmlentities(stripslashes($row['cu_date_id']));  
          $new_row['start']=htmlentities(stripslashes($row['cu_date_date']));  
          $row_set[] = $new_row;   
       }  
     echo json_encode($row_set);  
   }  


when you need to echo date in full calender you need to convert data to be json, for more information fullcalender is here

file you can grab here

Note : This is bassically configuration and you need to be familiar with codeignter


Saturday, 23 January 2016

Load All Varibales in every Controller Using Codeignter

This post for people know Codeignter been one year lah especially for me. This is about load same varibale each controller, please see script bellow

 <?php  
 defined('BASEPATH') OR exit('No direct script access allowed');  
 class Welcome extends CI_Controller {  
 public function read1()  
   {  
  $data['notif']=$this->Notif_model->get_all_notif(); //same varibale  
  }  
 public function read2()  
   {  
  $data['notif']=$this->Notif_model->get_all_notif(); //same varibale  
  }  
 public function read3()  
   {  
  $data['notif']=$this->Notif_model->get_all_notif(); //same varibale  
  }  
 }  

as you can see there are same varibale in every function, that's not clean code i guess !
so idecide to search about this issue then i found it
  1. GLOBAL VARIBALE
  2. EXTENDS CONTROLLER
after few hours digging on global varibale hard to learn then i leave it, focus on extends controller from stackoverflow here, yes stackoverflow is the best place to throw fuckin stress.

Then i make extends controller 
 <?php  
 defined('BASEPATH') OR exit('No direct script access allowed');  
 class AppKaryawan extends CI_Controller  
 {  
  /**  
  * @return void  
  **/  
  function __construct()  
  {  
  parent::__construct();  
  //load variable global  
  $this->data = array(  
       'notif' => $this->Notif_model->get_all_notif()  
     );  
  if (($this->session->userdata('cu_level') === 'Pegawai') or ($this->session->userdata('cu_level') === 'Manajer'))   
  {  
   return TRUE;  
  }  
  else  
  {  
   //show_404(); // OR   
   redirect('login');  
   return FALSE;  
  }  
  }  
 }  


Please see my extends above only for level Manajer, but ignore it lah it doesn't important. then let see the controller after extends controller this is will change like this
 public function read1()  
   {  
  $data = $this->data;   
  }  
 public function read2()  
   {  
  $data = $this->data;   
  }  
 public function read3()  
   {  
  $data = $this->data;   
  }   

Please compare the controller, yes the second controller is really lite bite clean but after think and quit some minute it tottally same, wtf ! cause each function should write the $data, how can i make it more clean, i'm open disscuss guys !

if you any trick please throw the code so people will understanding, so i will reblog it again to make more clean, Thanks for visiting me !

Happy Weekend 

Thursday, 21 January 2016

Validations Input Type File Using Jquery

well honestly this is my simple demo about validations in modal bootsrap, but this very bassic for validations input type file in modal bootsrap using jquery.

You can adapot this style to yours !


  1. I give value in input type file by giving id 
  2. Then check it using if then execute every condition
Here is simple demo made for you out there

See the Pen Check input type file empty por not by Freddy Sidauruk (@sidaurukfreddy) on CodePen.


Thanks for visiting Me !

Get One Field in Codeignter

Get one field in Codeignter when we need to extract it in view or controller

here is controller
and here is model
Thanks for visiting me !

you can grab database is here

Tuesday, 19 January 2016

COUNT DIFFRENT 2 DATE IN MYSQL USING CODEIGNTER

now i'm working on about date and time and will give you short tutorial about count diffrent date between two dates, well i'm fun using codeignter then spend some hours i found some blog intresting and help me a lot

check this out the authtoor tell how to count 2 date, so i change it to CODEIGNTER

first go to your and create datediff_helper.php
 <?php  
 // Set timezone  
  date_default_timezone_set("UTC");  
  // Time format is UNIX timestamp or  
  // PHP strtotime compatible strings  
  function dateDiff($time1, $time2, $precision = 6) {  
   // If not numeric then convert texts to unix timestamps  
   if (!is_int($time1)) {  
    $time1 = strtotime($time1);  
   }  
   if (!is_int($time2)) {  
    $time2 = strtotime($time2);  
   }  
   // If time1 is bigger than time2  
   // Then swap time1 and time2  
   if ($time1 > $time2) {  
    $ttime = $time1;  
    $time1 = $time2;  
    $time2 = $ttime;  
   }  
   // Set up intervals and diffs arrays  
   $intervals = array('year','month','day','hour','minute','second');  
   $diffs = array();  
   // Loop thru all intervals  
   foreach ($intervals as $interval) {  
    // Create temp time from time1 and interval  
    $ttime = strtotime('+1 ' . $interval, $time1);  
    // Set initial values  
    $add = 1;  
    $looped = 0;  
    // Loop until temp time is smaller than time2  
    while ($time2 >= $ttime) {  
     // Create new temp time from time1 and interval  
     $add++;  
     $ttime = strtotime("+" . $add . " " . $interval, $time1);  
     $looped++;  
    }  
    $time1 = strtotime("+" . $looped . " " . $interval, $time1);  
    $diffs[$interval] = $looped;  
   }  
   $count = 0;  
   $times = array();  
   // Loop thru all diffs  
   foreach ($diffs as $interval => $value) {  
    // Break if we have needed precission  
    if ($count >= $precision) {  
     break;  
    }  
    // Add value and interval  
    // if value is bigger than 0  
    if ($value > 0) {  
     // Add s if value is not 1  
     if ($value != 1) {  
      $interval .= "s";  
     }  
     // Add value and interval to times array  
     $times[] = $value . " " . $interval;  
     $count++;  
    }  
   }  
   // Return string with times  
   return implode(", ", $times);  
  }  
 ?>  




Then goes to autoload.php
 $autoload['helper'] = array('datediff');  


Then this is the controller
 <?php  
 if (!defined('BASEPATH'))  
   exit('No direct script access allowed');  
 class Login extends CI_Controller  
 {  
   function __construct()  
   {  
     parent::__construct();  
    }  
   public function index()  
   {  
      $this->template->load('template', 'login');  
   }  
 public function diffdate()  
   {  
     echo dateDiff('00:57:42','07:30:00');  
   }  
 }  
 </textare>  


The results here








You can grab helper is here




Change date MySQL to indonesia date using moment.js

as long as you develop cms you need to modif everything you need based on your requirements, locale and languange to make your users know why and how it came be,

Last posting about change date from database to view using codeignter, now i'm going to give tutorial about change date from database to view using moment.js  

Here is simple demo

See the Pen OMOGXg by Freddy Sidauruk (@sidaurukfreddy) on CodePen.

Thanks for visiting me, please feel free to comment !

Sunday, 17 January 2016

Change format date in mysql to indonesian format

 well quick tutorial about change date mysql to indonesia date using codeignter, well copy paste this script bellow, give it name tgl_indonesia_helper.php put inside helper folder

 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');  
 if ( ! function_exists('tgl_indo'))  
 {  
  function tgl_indo($tgl)  
  {  
  $ubah = gmdate($tgl, time()+60*60*8);  
  $pecah = explode("-",$ubah);  
  $tanggal = $pecah[2];  
  $bulan = bulan($pecah[1]);  
  $tahun = $pecah[0];  
  return $tanggal.'-'.$bulan.'-'.$tahun;  
  }  
 }  
 if ( ! function_exists('bulan'))  
 {  
  function bulan($bln)  
  {  
  switch ($bln)  
  {  
   case 1:  
   return "Januari";  
   break;  
   case 2:  
   return "Februari";  
   break;  
   case 3:  
   return "Maret";  
   break;  
   case 4:  
   return "April";  
   break;  
   case 5:  
   return "Mei";  
   break;  
   case 6:  
   return "Juni";  
   break;  
   case 7:  
   return "Juli";  
   break;  
   case 8:  
   return "Agustus";  
   break;  
   case 9:  
   return "September";  
   break;  
   case 10:  
   return "October";  
   break;  
   case 11:  
   return "November";  
   break;  
   case 12:  
   return "Desember";  
   break;  
  }  
  }  
 }  


then don't forget to load in load helper in autoload.php like this

 $autoload['helper'] = array('tgl_indonesia');  


Then goes to your controller welcome copy and paste this
 <?php  
 defined('BASEPATH') OR exit('No direct script access allowed');  
 class Welcome extends CI_Controller {  
  public function index()  
  {  
   echo tgl_indo ('2016-02-11');   
  //$this->load->view('welcome_message');  
  }  
 }  


 then this the results,


Thanks for reading me !