Enkelt gratis open source AJAX PHP kalender script
0,00$
- Ajax daterer navigationen
- Kan tilpasses start på ugedagen
- Lav vægt og høj ydeevne
- Dette script er gratis til kommerciel og ikke-kommerciel brug.
- Kalenderdemosiden
- Ajax daterer navigationen
- Kan tilpasses start på ugedagen
- Lav vægt og høj ydeevne
- Dette script er gratis til kommerciel og ikke-kommerciel brug.
- Kalenderdemosiden
KØB mere avanceret AJAX-kalender på Codecanyon.Net, som er baseret på dette script
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 | <?php class PN_Calendar { public $first_day_of_week = 0; //0 - sunday, 1 - monday public $current_year = null; public $current_month = null; public $current_day = null; public $show_year_selector = true; public $min_select_year = 1991; public $max_select_year = 2045; public $show_month_selector = true; public function __construct($atts = array()) { if (isset($atts['first_day_of_week'])) { $this->first_day_of_week = $atts['first_day_of_week']; } if (!isset($atts['year'])) { $this->current_year = date('Y'); } else { $this->current_year = $atts['year']; } if (!isset($atts['month'])) { $this->current_month = date('m'); } else { $this->current_month = $atts['month']; } if (!isset($atts['day'])) { $this->current_day = date('d'); } else { $this->current_day = $atts['day']; } //*** if (isset($atts['show_year_selector'])) { $this->show_year_selector = $atts['show_year_selector']; } if (isset($atts['show_month_selector'])) { $this->show_month_selector = $atts['show_month_selector']; } if (isset($atts['min_select_year'])) { $this->min_select_year = $atts['min_select_year']; } if (isset($atts['max_select_year'])) { $this->max_select_year = $atts['max_select_year']; } } /* * Month calendar drawing */ public function draw($data = array(), $y = 0, $m = 0) { //*** if ($m == 0 AND $m == 0) { $y = $this->current_year; $m = $this->current_month; } //*** $data['week_days_names'] = $this->get_week_days_names(true); $data['cells'] = $this->generate_calendar_cells($y, $m); $data['month_name'] = $this->get_month_name($m); $data['year'] = $y; $data['month'] = $m; $data['events'] = array();//here you can transmit events from database (look PN_CalendarCell::draw($events)) return $this->draw_html('calendar', $data); } private function generate_calendar_cells($y, $m) { $y = intval($y); $m = intval($m); //*** $first_week_day_in_month = date('w', mktime(0, 0, 0, $m, 1, $y)); //from 0 (sunday) to 6 (saturday) $days_count = $this->get_days_count_in_month($y, $m); $cells = array(); //*** if ($this->first_day_of_week == $first_week_day_in_month) { for ($d = 1; $d <= $days_count; $d++) { $cells[] = new PN_CalendarCell($y, $m, $d); } //*** $cal_cells_left = 5 * 7 - $days_count; $next_month_data = $this->get_next_month($y, $m); for ($d = 1; $d <= $cal_cells_left; $d++) { $cells[] = new PN_CalendarCell($next_month_data['y'], $next_month_data['m'], $d, false); } } else { //*** if ($this->first_day_of_week == 0) { $cal_cells_prev = 6 - (7 - $first_week_day_in_month); //checked, is right } else { if ($first_week_day_in_month == 1) { $cal_cells_prev = 0; } else { if ($first_week_day_in_month == 0) { $cal_cells_prev = 6 - 1; } else { $cal_cells_prev = 6 - (7 - $first_week_day_in_month) - 1; } } } //*** $prev_month_data = $this->get_prev_month($y, $m); $prev_month_days_count = $this->get_days_count_in_month($prev_month_data['y'], $prev_month_data['m']); for ($d = $prev_month_days_count - $cal_cells_prev; $d <= $prev_month_days_count; $d++) { $cells[] = new PN_CalendarCell($prev_month_data['y'], $prev_month_data['m'], $d, false); } //*** for ($d = 1; $d <= $days_count; $d++) { $cells[] = new PN_CalendarCell($y, $m, $d); } //*** //35(7*5) or 42(7*6) cells $busy_cells = $cal_cells_prev + $days_count; $cal_cells_left = 0; if ($busy_cells < 35) { $cal_cells_left = 35 - $busy_cells - 1; } else { $cal_cells_left = 42 - $busy_cells - 1; } //*** if ($cal_cells_left > 0) { $next_month_data = $this->get_next_month($y, $m); for ($d = 1; $d <= $cal_cells_left; $d++) { $cells[] = new PN_CalendarCell($next_month_data['y'], $next_month_data['m'], $d, false); } } } //*** return $cells; } public function get_next_month($y, $m) { $y = intval($y); $m = intval($m); //*** $m++; if ($m % 13 == 0 OR $m > 12) { $y++; $m = 1; } return array('y' => $y, 'm' => $m); } public function get_prev_month($y, $m) { $y = intval($y); $m = intval($m); //*** $m--; if ($m <= 0) { $y--; $m = 12; } return array('y' => $y, 'm' => $m); } public function get_days_count_in_month($year, $month) { return $month == 2 ? ($year % 4 ? 28 : ($year % 100 ? 29 : ($year % 400 ? 28 : 29))) : (($month - 1) % 7 % 2 ? 30 : 31); } public static function get_month_name($m) { $names = self::get_monthes_names(); return $names[intval($m)]; } public function get_week_day_name($num, $shortly = false) { $names = $this->get_week_days_names($shortly); return $names[intval($num)]; } public function get_week_days_names($shortly = false) { if ($this->first_day_of_week == 1) { if ($shortly) { return array( 1 => 'Mo', 2 => 'Tu', 3 => 'We', 4 => 'Th', 5 => 'Fr', 6 => 'Sa', 7 => 'Su' ); } return array( 1 => 'Monday', 2 => 'Tuesday', 3 => 'Wednesday', 4 => 'Thursday', 5 => 'Friday', 6 => 'Saturday', 7 => 'Sunday' ); } else { if ($shortly) { return array( 0 => 'Su', 1 => 'Mo', 2 => 'Tu', 3 => 'We', 4 => 'Th', 5 => 'Fr', 6 => 'Sa' ); } return array( 0 => 'Sunday', 1 => 'Monday', 2 => 'Tuesday', 3 => 'Wednesday', 4 => 'Thursday', 5 => 'Friday', 6 => 'Saturday' ); } } public static function get_monthes_names() { return array( 1 => 'January', 2 => 'February', 3 => 'March', 4 => 'April', 5 => 'May', 6 => 'June', 7 => 'July', 8 => 'August', 9 => 'September', 10 => 'October', 11 => 'November', 12 => 'December' ); } public function draw_html($view, $data = array()) { @extract($data); ob_start(); include('views/' . $view . '.php' ); return ob_get_clean(); } } //--------------------------------------------------------------------------------------- class PN_CalendarCell { public $cell_year = null; public $cell_month = null; public $cell_day = null; public $in_current_month = true; public function __construct($y, $m, $d, $in_current_month = true) { $this->cell_year = $y; $this->cell_month = $m; $this->cell_day = $d; $this->in_current_month = $in_current_month; } public function get_week_day_num() { return date('w', mktime(0, 0, 0, $this->cell_month, $this->cell_day, $this->cell_year)); //from 0 (sunday) to 6 (saturday); } public function draw($events) { $this_day_events = 0; if (is_array($events)) { if (isset($events[$this->cell_year][$this->cell_month][$this->cell_day])) { $this_day_events = count($events[$this->cell_year][$this->cell_month][$this->cell_day]); } } else { $events = array(); } ?> <span class="pn_cal_cell_ev_counter" <?php if ($this_day_events <= 0): ?>style="display: none;"<?php endif; ?>><?php echo $this_day_events ?></span> <a data-year="<?php echo $this->cell_year ?>" data-month="<?php echo $this->cell_month ?>" data-day="<?php echo $this->cell_day ?>" data-week-day-num="<?php echo $this->get_week_day_num() ?>" href="javascript:void(0);" class="<?php if ($this->in_current_month): ?>pn_this_month<?php else: ?>other_month<?php endif; ?>"><?php echo $this->cell_day ?></a> <?php } } |
Ring til scriptet på den næste måde:
1 2 3 | include_once 'classes/calendar.php'; $calendar = new PN_Calendar(); echo $calendar->draw(); |
Her er mere simpelt PHP-script i kalenderen, hvis du har brug for det:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | <?php $days_count = date('t'); $current_day = date('d'); $week_day_first = date('N', mktime(0, 0, 0, date('m'), 1, date('Y'))); ?> <table> <tr> <th>MO</th> <th>TU</th> <th>WE</th> <th>TH</th> <th>FR</th> <th style="color: red;">SU</th> <th style="color: red;">SA</th> </tr> <?php for ($w = 1 - $week_day_first + 1; $w <= $days_count; $w = $w + 7): ?> <tr> <?php $counter = 0; ?> <?php for ($d = $w; $d <= $w + 6; $d++): ?> <td style="<?php if ($counter > 4): ?>color: red;<?php endif; ?><?php if ($current_day == $d): ?>background-color:yellow; color:green;font-weight:bold;<?php endif; ?>"> <?php echo($d > 0 ? ($d > $days_count ? '' : $d) : '') ?> </td> <?php $counter++; ?> <?php endfor; ?> </tr> <?php endfor; ?> </table> |