emprit

jadwal_piket

Jun 29th, 2014
396
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.24 KB | None | 0 0
  1. -- app_helper --
  2. function draw_calendar($month,$year,$data)
  3. {
  4.     /* select kelompok */
  5.     $selectbox = '<select name=kelompok><option value="-"> -- </option>';
  6.     foreach($data->result() as $row){
  7.         $selectbox .= '<option value='.$row->kelompok.'>'.$row->kelompok.'</option>';
  8.     }              
  9.     $selectbox .= '</select>';
  10.  
  11.     /* draw table */
  12.     $calendar = '<table cellpadding="0" cellspacing="0" class="calendar">';
  13.    
  14.     /* table headings */
  15.     $headings = array('Minggu','Senin','Selasa','Rabu','Kamis','Jum\'at','Sabtu');
  16.     $calendar.= '<tr class="calendar-row"><td class="calendar-day-head">'.implode('</td><td class="calendar-day-head">',$headings).'</td></tr>';
  17.    
  18.     /* days and weeks vars now ... */
  19.     $running_day = date('w',mktime(0,0,0,$month,1,$year));
  20.     $days_in_month = date('t',mktime(0,0,0,$month,1,$year));
  21.     $days_in_this_week = 1;
  22.     $day_counter = 0;
  23.     $dates_array = array();
  24.    
  25.     /* row for week one */
  26.     $calendar.= '<tr class="calendar-row">';
  27.    
  28.     /* print "blank" days until the first of the current week */
  29.     for($x = 0; $x < $running_day; $x++):
  30.     $calendar.= '<td class="calendar-day-np"></td>';
  31.     $days_in_this_week++;
  32.     endfor;
  33.    
  34.     /* keep going with days.... */
  35.     $cur_day   = date('d');
  36.     $cur_month = date('m');
  37.     $cur_year  = date('Y');
  38.     for($list_day = 1; $list_day <= $days_in_month; $list_day++):
  39.     $calendar.= '<td class="calendar-day" style="text-align:center">';
  40.    
  41.       /* add in the day number */
  42.       if(($cur_day == $list_day) && ($month == $cur_month) && ($cur_year == $year))
  43.         $calendar.= '<div class="day-number-today">'.$list_day.'</div>';
  44.       else
  45.         $calendar.= '<div class="day-number">'.$list_day.' '.$selectbox.'</div>';
  46.    
  47.     /** QUERY THE DATABASE FOR AN ENTRY FOR THIS DAY !!  IF MATCHES FOUND, PRINT THEM !! **/
  48.       if(array_key_exists($list_day,$data))
  49.         {
  50.             $calendar.= '<p>'.$data[$list_day].'</p>';
  51.         }
  52.       else
  53.         $calendar.= str_repeat('</br>',2);
  54.     $calendar.= '</td>';
  55.     if($running_day == 6):
  56.       $calendar.= '</tr>';
  57.       if(($day_counter+1) != $days_in_month):
  58.         $calendar.= '<tr class="calendar-row">';
  59.       endif;
  60.       $running_day = -1;
  61.       $days_in_this_week = 0;
  62.     endif;
  63.     $days_in_this_week++; $running_day++; $day_counter++;
  64.     endfor;
  65.    
  66.     /* finish the rest of the days in the week */
  67.     if($days_in_this_week < 8):
  68.     for($x = 1; $x <= (8 - $days_in_this_week); $x++):
  69.       $calendar.= '<td class="calendar-day-np"></td>';
  70.     endfor;
  71.     endif;
  72.    
  73.     /* final row */
  74.     $calendar.= '</tr>';
  75.    
  76.     /* end the table */
  77.     $calendar.= '</table>';
  78.    
  79.     /* all done, return result */
  80.     return $calendar;
  81. }
  82.  
  83. -- model --
  84. /* mengambil data kelompok */
  85.     function get_kelompok(){
  86.         $this->db->select('kelompok');
  87.         $this->db->from('kelompok');
  88.         return $this->db->get();
  89.     }
  90.  
  91. -- controller --
  92. public function ex_jadwal_bln()
  93.     {
  94.         $this->fungsi->check_previleges('jadwal');
  95.         $month = $this->input->post('bulan');
  96.         $year  = date('Y');
  97.         $kelompok = $this->m_manage->get_kelompok($month, $year);
  98.         $dataisi['tabel'] = draw_calendar($month,$year,$kelompok);
  99.         $this->load->view('cms/manage/form_ex_jadwal_ex',$dataisi);
  100.         }
Advertisement
Add Comment
Please, Sign In to add comment