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

Membuat Codeigniter PDF di CPANEL

1. Download FPDF dan copykan di folder application/thirdparty/pdf/ 2. Buat file Fpdf_gen.php di libraries. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Fpdf_gen { public function __construct() {  require_once APPPATH.'third_party/fpdf/fpdf-1.8.php'; define('FPDF_FONTPATH', APPPATH.'third_party/fpdf/font/'); $pdf = new FPDF(); $pdf->AddPage(); $CI =& get_instance(); $CI->fpdf = $pdf; } public function Footer() { $this->fpdf->SetY(-15); $this->fpdf->SetFont('Arial','I',8); $this->fpdf->SetTextColor(128); $this->fpdf->Cell(0,10,'Page ',0,0,'C'); } } 3. Buat file pdf.php di controller <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); defined('BASEPATH') OR exit('No direct script access allowed'); class Pdf extends CI_Controller {   public f...

Nusoap Web Service

hellowsdl.php ---> di server <?php // Pull in the NuSOAP code require_once('lib/nusoap.php'); // Create the server instance $server = new soap_server(); // Initialize WSDL support $server->configureWSDL('hellowsdl', 'urn:hellowsdl'); // Register the method to expose $server->register('hello',                // method name     array('name' => 'xsd:string'),        // input parameters     array('return' => 'xsd:string'),    // output parameters     'urn:hellowsdl',                    // namespace     'urn:hellowsdl#hello',                // soapaction     'rpc',       ...