0

Всем привет. Возникла потребность сделать календать, а как это сделать, не могу понять. Нужно сделать так, чтобы выводилось 3 месяца (прошлый, который сейчас и будущий), и чтобы праздники были белыми.

alt text

1

2 ответа 2

3
public function getCalendar()
{
    $calendar = '';

    for($i = 1; $i <= 12; $i++)
    {
        $calendar .= $this->createCalendar($i);
    }

    return $calendar;
}

public function createCalendar($month)
{
    $count_day = 1;
    $countDayMonth = date('t', mktime(0, 0, 0, $month, $count_day, date('Y')));
    $nameDayWeek = array("Пн", "Вт", "Ср", "Чт", "Пт", "Сб", "Вс");
    $nameMonth = array(' ', 'Январь', 'Февраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', 'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь');
    $index = 0;
    $tbl = '';
    $class = 'class="we"';
    $c_month = date('m');
    $path = umiHierarchy::getInstance()->getPathById(4);
    $g_date = getRequest('date');

    for ($i = 0; $i < 7; $i++) 
    {
        $indexWeek = date('w', mktime(0, 0, 0, $month, $count_day, date('Y')));
        $indexWeek = $indexWeek - 1;

        if ($indexWeek == -1) {
            $indexWeek = 6;
        }
        if ($indexWeek == $i) {
            $mas[$index][$i] = $count_day;
            $count_day++;
        } else {
            $mas[$index][$i] = "";
        }
    }
    while (true) 
    {
        $index++;
        for ($i = 0; $i < 7; $i++) {
            $mas[$index][$i] = $count_day;
            $count_day++;

            if ($count_day > $countDayMonth) {
                break;
            }
        }
        if ($count_day > $countDayMonth) {
            break;
        }
    }

    $dateNow = date('d');

    $tbl = '
            <li class="jcarousel-item jcarousel-item-horizontal jcarousel-item-'.$month.' jcarousel-item-'.$month.'-horizontal" style="float: left; list-style: none; " jcarouselindex="'.$month.'">
                <div class="m-y">
                    <span class="month">'.$nameMonth[$month].'</span>
                    <span class="year">'.date('Y').'</span>
                </div>
                <div class="month-days">
            <table>
                <tr>';

    for ($i = 0; $i < 7; $i++) 
    {
        $tbl .= '<th '.(($i == 5 || $i == 6)?$class:'').'>'.$nameDayWeek[$i].'</th>';
    }
    $tbl .= '</tr>';

    for ($i = 0; $i < count($mas); $i++) 
    {
        echo "<tr>";
        for ($j = 0; $j < 7; $j++) 
        {
            if (!empty($mas[$i][$j])) 
            {
                if ($dateNow == $mas[$i][$j] && $c_month == $month) 
                {
                    if(empty($g_date) || $g_date == mktime(0, 0, 0, $month, $mas[$i][$j], date('Y')))
                    {
                        $tbl .= '<td '.$class.' style="color:red;">'.$mas[$i][$j].'</td>';
                    }
                    else
                    {
                        $tbl .= '<td style="color:red"><a href="'.$path.'?date='.mktime(0, 0, 0, $month, $mas[$i][$j], date('Y')).'" style="text-decoration:none; color:red">'.$mas[$i][$j].'</a></td>';
                    }
                } 
                elseif ($j == 5 || $j == 6) 
                {
                    if(!empty($g_date) && $g_date == mktime(0, 0, 0, $month, $mas[$i][$j], date('Y')))
                    {
                        $tbl .= '<td '.$class.' style="color:green;">'.$mas[$i][$j].'</td>';
                    }
                    else
                    {
                        $tbl .= '<td '.$class.'><a href="'.$path.'?date='.mktime(0, 0, 0, $month, $mas[$i][$j], date('Y')).'" style="text-decoration:none;">'.$mas[$i][$j].'</a></td>';
                    }
                } 
                else 
                {
                    if(!empty($g_date) && $g_date == mktime(0, 0, 0, $month, $mas[$i][$j], date('Y')))
                    {
                        $tbl .= '<td '.$class.' style="color:green;">'.$mas[$i][$j].'</td>';
                    }
                    else
                    {
                        $tbl .= '<td><a href="'.$path.'?date='.mktime(0, 0, 0, $month, $mas[$i][$j], date('Y')).'" style="color:#000; text-decoration:none;">'.$mas[$i][$j].'</a></td>';
                    }
                }
            } 
            else 
            {
                $tbl .= '<td>&nbsp;</td>';
            }
        }
        $tbl .= '</tr>';
    }
    $tbl .= '</table></div>';

    return $tbl;
}
0

Все гораздо проще: jqxCalendar.

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.