Skip to main content

Membuat Kalender Akademik dengan SimpeCalendar

Berikut kode simple calendar modifikasi bahasa Indonesia:

<?php

namespace donatj_2017;

/**
 * Simple Calendar
 *
 * @author Jesse G. Donat <donatj@gmail.com>
 * @link http://donatstudios.com
 * @license http://opensource.org/licenses/mit-license.php
 * Modified by Edi Haryono energipositif@gmail.com 

*/
 

class SimpleCalendar {

    /**
     * Array of Week Day Names
     *
     * @var array
     */
    public $wday_names = false;

    private $now;
    private $dailyHtml = array();
    private $offset = 0;

    /**
     * Constructor - Calls the setDate function
     *
     * @see setDate
     * @param null|string $date_string
     */
    function __construct( $date_string = null ) {
        $this->setDate($date_string);
    }

    /**
     * Sets the date for the calendar
     *
     * @param null|string $date_string Date string parsed by strtotime for the calendar date. If null set to current timestamp.
     */
    public function setDate( $date_string = null ) {
        if( $date_string ) {
            $this->now = getdate(strtotime($date_string));
        } else {
            $this->now = getdate();
        }
    }

    /**
     * Add a daily event to the calendar
     *
     * @param string      $html The raw HTML to place on the calendar for this event
     * @param string      $start_date_string Date string for when the event starts
     * @param null|string $end_date_string Date string for when the event ends. Defaults to start date
     */
    public function addDailyHtml( $html, $start_date_string, $end_date_string = null ) {
        static $htmlCount = 0;
        $start_date = strtotime($start_date_string);
        if( $end_date_string ) {
            $end_date = strtotime($end_date_string);
        } else {
            $end_date = $start_date;
        }

        $working_date = $start_date;
        do {
            $tDate = getdate($working_date);
            $working_date += 86400;
            $this->dailyHtml[$tDate['year']][$tDate['mon']][$tDate['mday']][$htmlCount] = $html;
        } while( $working_date < $end_date + 1 );

        $htmlCount++;
    }

    /**
     * Clear all daily events for the calendar
     */
    public function clearDailyHtml() { $this->dailyHtml = array(); }

    /**
     * Sets the first day of the week
     *
     * @param int|string $offset Day to start on, ex: "Monday" or 0-6 where 0 is Sunday
     */
    public function setStartOfWeek( $offset ) {
        if( is_int($offset) ) {
            $this->offset = $offset % 7;
        } else {
            $this->offset = date('N', strtotime($offset)) % 7;
        }
    }

    /**
     * Returns/Outputs the Calendar
     *
     * @param bool $echo Whether to echo resulting calendar
     * @return string HTML of the Calendar
     */
    public function show( $echo = true ) {
        if( $this->wday_names ) {
            $wdays = $this->wday_names;
        } else {
            $today = (86400 * (date("N")));
            $wdays = array();
            for( $i = 0; $i < 7; $i++ ) {
                $wdays[] = strftime('%a', time() - $today + ($i * 86400));
            }
        }

        $this->arrayRotate($wdays, $this->offset);
        $wday    = date('N', mktime(0, 0, 1, $this->now['mon'], 1, $this->now['year'])) - $this->offset;
        $no_days = cal_days_in_month(CAL_GREGORIAN, $this->now['mon'], $this->now['year']);

        $out = '<table cellpadding="0" cellspacing="0" class="SimpleCalendar"><thead><tr>';

        //Hari disini
        $dayList = array(
            'Sun' => 'Min',
            'Mon' => 'Sen',
            'Tue' => 'Sel',
            'Wed' => 'Rab',
            'Thu' => 'Kam',
            'Fri' => 'Jum',
            'Sat' => 'Sab'
            );
        for( $i = 0; $i < 7; $i++ ) {
            $out .= '<th> ' . $dayList[$wdays[$i]] . '</th>';
        }

        $out .= "</tr></thead>\n<tbody>\n<tr>";

        $wday = ($wday + 7) % 7;

        if( $wday == 7 ) {
            $wday = 0;
        } else {
            $out .= str_repeat('<td class="SCprefix">&nbsp;</td>', $wday);
        }

        $count = $wday + 1;
        for( $i = 1; $i <= $no_days; $i++ ) {
            $out .= '<td' . ($i == $this->now['mday'] && $this->now['mon'] == date('n') && $this->now['year'] == date('Y') ? ' class="today"' : '') . '>';

            $datetime = mktime(0, 0, 1, $this->now['mon'], $i, $this->now['year']);
 

        //membuat tanggal merah minggu
/*               if ( date('D', $datetime) == 'Sun' )
            {$warna = 'red';}else{$warna = '#0e2f44';}  */
           
        //membuat tanggal merah libur
              $link_merah = mysqli_connect("localhost", "root", "", "kalender");
            $tanggal_merah = date('Y-m-d', $datetime);
            $query_merah = "SELECT * FROM kegiatan WHERE jenis = 'libur' AND mulai = '$tanggal_merah'";
            $result_tanggal_merah = mysqli_query($link_merah, $query_merah);
             $jumlah=mysqli_num_rows($result_tanggal_merah);
           
              if($jumlah==1) {$warna = 'red';}
            else if ( date('D', $datetime) == 'Sun' )
            {$warna = 'red';}
            else{$warna = '#0e2f44';}
           
           
            $out .= '<time datetime="' . date('Y-m-d', $datetime) . '">
                       
            <a href="#modal_edit1" class="modalButton1" style="color:'.$warna.';"
                    data-day="'.date('Y-m-d', $datetime).'" 
                    data-toggle="modal" data-target="#modal_edit1" data-popup="tooltip" title="'.date('d M Y', $datetime).'" data-container="body">
                    '.date('d', $datetime).'
            </a>
               
            </time>';

            $dHtml_arr = false;
            if( isset($this->dailyHtml[$this->now['year']][$this->now['mon']][$i]) ) {
                $dHtml_arr = $this->dailyHtml[$this->now['year']][$this->now['mon']][$i];
            }

            if( is_array($dHtml_arr) ) {
                foreach( $dHtml_arr as $dHtml ) {
                    $out .= '<div class="event">' . $dHtml . '</div>';
                }
            }

            $out .= "</td>";

            if( $count > 6 ) {
                $out .= "</tr>\n" . ($i != $count ? '<tr>' : '');
                $count = 0;
            }
            $count++;
        }
        $out .= ($count != 1 ? str_repeat('<td class="SCsuffix">&nbsp;</td>', 8 - $count) : '') . "</tr>\n</tbody></table>\n";
        if( $echo ) {
            echo $out;
        }

        return $out;
    }

    private function arrayRotate( &$data, $steps ) {
        $count = count($data);
        if( $steps < 0 ) {
            $steps = $count + $steps;
        }
        $steps = $steps % $count;
        for( $i = 0; $i < $steps; $i++ ) {
            array_push($data, array_shift($data));
        }
    }
}


Rubah bootstrap.min.css pada class modal:


Menjadi:
.modal-backdrop{position:fixed;top:0;right:0;bottom:0;left:0;z-index:1040;background-color:#000}
 .modal-backdrop.fade{opacity:0}.modal-backdrop,.modal-backdrop.fade.in{opacity:.8;filter:alpha(opacity=80)}.modal{position:fixed;top:10%;left:50%;z-index:50%;width:50%;margin-left:-280px;


File lengkap disini:

Download Source

Comments

Popular posts from this blog

FPDF dengan CodeIgniter

Cetak Surat Keputusan Controller: <?php //File in controller named surat_keputusan.php defined('BASEPATH') OR exit('No direct script access allowed'); class Cetak_surat_keputusan extends CI_Controller { public function __construct()     {         parent::__construct();         $this->load->helper('url');         $this->load->database();                $this->db->select();         $this->db->from('surat.config_sk');                $query = $this->db->get();                 return $query->result();             } public function index() {      ...

Preview PDF di Modal Bootstrap dengan Ajax

//preview pdf in line function preview_surat_keputusan(no) { $('#form')[0].reset(); $('.form-group').removeClass('has-error'); $('.help-block').empty(); $.ajax({ url : "<?php echo site_url('surat_keputusan/ajax_preview/')?>/" + no, type: "GET", dataType: "JSON",     success: function(data)     {     //paramater yang akan ditampilkan di modal         $('[name="no"]').val(data.no);         $('[name="ns"]').val(data.ns);         $('[name="thts"]').val(data.thts);         $('[name="pdf"]').val("http://localhost/dosdm/document/sm/pdf/"+data.thts+"-SK-"+data.ns+".pdf");         var link_base =  "http://localhost/dosdm/document/sm/pdf/"+data.thts+"-SK-"+data.ns+".pdf" ;             $('#pdf_view').attr('src', link_base);      ...

Hack File .xlsb

For first you must create a backup copy of your Workbook!!! Then you have to rename the XLSB file with ZIP extension. Test.XLSB => Test.ZIP             Opening your ZIP file using a compression software (e.g. WinRar) I can see the content of the file, structured in folders Inside the folder xl you can find a binary file named vbaProject.bin. Extract it on your desktop and edit it using a text editor. In my case I used Notepad++. Using the Find function of your editor, you must search the text DPB And replace the DPB string with DPx Then save the vbaProject.bin and replace this file inside the .ZIP File, renaming then .ZIP file in XLSB. Reopening the XLSB file using Excel, you will get an error message: you have to answer Yes to this error message. Then  Save , Close and Reopen your XLSB file. Now, if you go to VBA Editor (ALT + F11), you ca...