ACC SHELL

Path : /srv/www/vhosts/alfa-com/engine/
File Upload :
Current File : /srv/www/vhosts/alfa-com/engine/MonthCalendar.php

<?php
	// Author: Jakub Macek, CZ; Copyright: Poski.com s.r.o.; Code is 100% my work. Do not copy.
	
	class MonthCalendar
	{
		public					$empty_cell							= array('date' => null, 'text' => '', 'style' => ';', 'value' => null);

		public					$month								= null;
		public					$year								= null;
		public					$days								= null;

		public					$week_start							= 1; // monday

		public					$data								= array();
		public					$rows								= null;
		public					$previous							= '';
		public					$next								= '';

		public function __construct($month = null, $year = null, $empty_value = null)
		{
			$date = getdate();
			$this->month = (($month === null) ? $date['mon'] : $month);
			$this->year = (($year === null) ? $date['year'] : $year);

			$this->days = 31;
			while (!checkdate($this->month, $this->days, $this->year))
				$this->days--;
			$empty_value = serialize($empty_value);
			for ($day = 1; $day <= $this->days; $day++)
				$this->data[$day] = unserialize($empty_value);

			$m = $this->year * 12 + ($this->month - 1);
			$m--;
			$this->previous = ((int) ($m / 12)) . '-' . sprintf('%02d', (($m % 12) + 1));
			$m++; $m++;
			$this->next = ((int) ($m / 12)) . '-' . sprintf('%02d', (($m % 12) + 1));
		}

		public function prepare($callback = null)
		{
			$first = getdate(strtotime($this->year . '-' . $this->month . '-01'));
			$last = getdate(strtotime($this->year . '-' . $this->month . '-' . $this->days));

			$before = ($first['wday'] + 7 - $this->week_start) % 7;
			$after = 7 - (($this->days + $before) % 7);

			for ($r = 0; $r < 6; $r++)
			{
				$row = array();
				for ($d = 0; $d < 7; $d++)
				{
					$date = getdate(strtotime(sprintf('%+d days', $r * 7 + $d - $before), $first[0]));
					$cell = $this->empty_cell;
					$cell['date'] = $date;
					$cell['text'] = $date['mday'];
					if ($date['mon'] < $this->month)
						$cell['style'] .= 'before;gray;';
					elseif ($date['mon'] > $this->month)
						$cell['style'] .= 'after;gray;';
					else
					{
						$cell['style'] .= 'normal;';
						$cell['value'] = $this->data[$date['mday']];
					}
					$cell['style'] .= 'wday_' . $date['wday'] . ';';
					if ($callback)
						$cell = callback($callback, array('cell' => $cell, 'calendar' => $this));
					$row[] = $cell;
				}
				$this->rows[] = $row;
			}
		}

		public function render($callback = null, $type = 'table')
		{
			$this->prepare($callback);
			$weekdays = array();
			for ($i = 0; $i < 7; $i++)
				$weekdays[] = __('wday-short-'.$i, '@core');
			$weekdays = array_merge($weekdays, $weekdays);
			$weekdays = array_slice($weekdays, $this->week_start, 7, true);
			$row = array();
			foreach ($weekdays as $day)
			{
				$cell = $this->empty_cell;
				$cell['style'] .= 'header;wday_'.($i%7).';';
				$cell['text'] = $day;
				$row[] = $cell;
			}
			$rows = array_merge(array($row), $this->rows);

			ob_start();
			if ($type == 'table')
			{
				echo '<table class="calendar">';
				foreach ($rows as $row)
				{
					echo '<tr>';
					foreach ($row as $day)
						echo '<td class="'.strtr($day['style'], ';', ' ').'">' . $day['text'] . '</td>';
					echo '</tr>';
				}
				echo '</table>';
			}
			return ob_get_clean();
		}
	}
?>

ACC SHELL 2018