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...

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...

Instal font baru di FPDF.

1. buka url www.fpdf.org/makefont 2. pilih ttf yang akan dimasukkan. sebaiknya pindahkan file ttf dari c:/windows/font ke folder lain. karena C: adalah windows. 3. Upload dan generate. 4. Donwload nama font.php dan font.z copykan ke folder fpdf/font. <?php require( 'fpdf.php' ); $pdf = new FPDF (); $pdf -> AddFont ( 'Calligrapher' , '' , 'calligra.php' ); $pdf -> AddPage (); $pdf -> SetFont ( 'Calligrapher' , '' , 35 ); $pdf -> Write ( 10 , 'Enjoy new fonts with FPDF!' ); $pdf -> Output (); ?>