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

Menggenerate nomor id

<?php //config $database = "dopo"; $tabel = "po"; $kolom_generate ="id"; $kolom_referensi = "id"; /* Database connection start */ $servername = "localhost"; $username = "root"; $password = ""; $dbname = $database; $mysqli = mysqli_connect($servername, $username, $password, $dbname) or die("Connection failed: " . mysqli_connect_error()); $q1 = "select * from $tabel order by $kolom_referensi DESC"; /* Database connection end */ echo '<table>'; // connect to the database // number of results to show per page $per_page = 10000; // figure out the total pages in the database if ($result = $mysqli->query($q1)) { if ($result->num_rows != 0) { $total_results = $result->num_rows; // ceil() returns the next highest integer value by rounding up value if necessary $total_pages = ceil($total_results / $per_page); // check if the 'page' variab...

CRUD dengan vue.js

pada tutorial kali ini kita akan belajar cara menampilkan data mengunakan  Vue JS  di framework  Codeigniter,  di dutorial sebelumnya kita sudah mempelajari cara Crud mengunakan Vue JS dan Codeigniter, kalian bisa lihat tutorialnya disini  CRUD CODEIGNITER DAN VUE JS  . kali ini kita akan mencoba menampilkan data yang ada pada database dengan framwork codeigniter dan vue js, untuk koneksi database di codeigniter adalah : <?php defined('BASEPATH') OR exit('No direct script access allowed'); $active_group = 'default'; $query_builder = TRUE; $db['default'] = array(     'dsn'    => '',     'hostname' => 'localhost',     'username' => 'root',     'password' => 'root',     'database' => 'civue',     'dbdriver' => 'mysqli',     'dbprefix' => '',     'pconnect' => FALSE,     ...