我在哪里可以从星期一将日历开始日期更改为星期日

时间:2015-05-30 18:30:21

标签: date calendar

我试图让这个日历在星期日而不是星期一开始。我查看了所有关于此主题的Google帮助文件&找不到任何我可以参考的代码行。我错过了一些吗?或者有人能指出我需要改变的地方,以便让它在星期日而不是星期一开始?

<?php
/**
 * Copyright (C) 2006-2014 Center Stage Software
 * 1191 Luxton Street, Seaside, California 93955
 * All Rights Reserved
 */

// ensure that this file is called up by another file
defined('_VALID_ACCESS') or die('Direct access of this file is prohibited.');

/**
 * renderEventCalendar - Creates a calendar display of events for one month.
 *
 * @global (Array) $cstage
 */
function renderEventCalendar() {
    global $cstage, $path;

    // Result variable.
    $calendar = '';

    // Calculate first and last day of the month.
    $firstDayTimestamp = strtotime($_SESSION[SYS_USER]['search']['Month'].'-01 07:00:00');
    list($year,$month) = explode("-",$_SESSION[SYS_USER]['search']['Month']);
    if( $month == 12 ) {
        $month = 00;
        $year += 1;
    }
    $lastDayTimestamp = strtotime("$year-".($month+1).'-01 08:00:00') - 86400; // minus 24 hours and add 1-day-light-savings-hour
    // TODO: Remove the following calendar debugging code.
    // print "<h1>first=$firstDayTimestamp; last=$lastDayTimestamp</h1>";

    // Build query to retrieve entries for that month.
    $aryEvents = array();
    $extraSqlFields = '';
    $extraSqlJoins = '';
    $extraSqlConditions = '';
    if( !empty($_SESSION[SYS_USER]['domain']) ) {
        $extraSqlJoins .= 'LEFT JOIN "domainlist" AS "domain2" ON "domain2"."master_id" = "master"."master_id" ';
        $extraSqlConditions .= sprintf('AND "domain2"."domain"=\'%s\' '
            ,$_SESSION[SYS_USER]['domain']
        );
    }
    if( !empty($_SESSION[SYS_USER]['search']['Theatre']) ) {
        $extraSqlConditions .= sprintf('AND "master"."theatre"=\'%s\' '
            ,$_SESSION[SYS_USER]['search']['Theatre']
        );
    }
    if( !empty($_SESSION[SYS_USER]['search']['Location']) ) {
        $extraSqlConditions .= sprintf('AND "master"."location"=\'%s\' '
            ,$_SESSION[SYS_USER]['search']['Location']
        );
    }
    if( !empty($_SESSION[SYS_USER]['search']['EventType']) ) {
        $extraSqlConditions .= sprintf('AND "master"."event_types_id"=\'%s\' '
            ,$_SESSION[SYS_USER]['search']['EventType']
        );
    }
    if( !empty($_SESSION[SYS_USER]['search']['Month']) ) {
        $extraSqlConditions .= sprintf('AND "shows"."show_date" >= \'%s\' AND "shows"."show_date" <= \'%s\' '
            ,date('Y-m-d',$firstDayTimestamp)
            ,date('Y-m-d',$lastDayTimestamp)
        );
    }
    if( $cstage['rttEnable'] ) {
        $extraSqlFields .= ', "rtt"."label" AS "rtt_label"';
        $extraSqlJoins .= 'LEFT JOIN "rtt" ON "master"."rtt_id" = "rtt"."rtt_id" ';
    } else {
        $extraSqlConditions .= 'AND "master"."rtt_id"=0 ';
    }
    if( $cstage['enableEventPriceListTest'] ) {
        $aryGroups = array($cstage['tixDomain']);
        if( !empty($_SESSION[SYS_USER]['info']) && count($_SESSION[SYS_USER]['info']['groupDomains']) > 0 ) {
            $aryGroups = array_merge($aryGroups, $_SESSION[SYS_USER]['info']['groupDomains']);
        }
        $extraSqlFields .= ', GROUP_CONCAT(DISTINCT "prices"."prices_id" SEPARATOR \';\') AS "priceidlist"';
        $extraSqlFields .= ', GROUP_CONCAT(DISTINCT CONCAT("price_category"."label",\' \', "prices"."printed_as") SEPARATOR \', \') AS "pricelist"';
        $extraSqlJoins .= ' INNER JOIN "price_category" ON "price_category"."master_id" = "master"."master_id" OR "price_category"."master_id"=0 INNER JOIN "prices" ON "price_category"."price_category_id" = "prices"."price_category_id" INNER JOIN "price_category_domain" ON "price_category_domain"."price_category_id" = "price_category"."price_category_id"';
        $extraSqlConditions .= sprintf('AND ("price_category"."master_id"="shows"."master_id" OR "price_category"."master_id"=0) AND ("prices"."shows_id"="shows"."shows_id" OR "prices"."shows_id"=0) AND "prices"."onsale"<=CONCAT("shows"."show_date", \' 00:00:00\') AND ("prices"."offsale">=CONCAT("shows"."show_date", \' 23:59:59\') OR "prices"."offsale" IS NULL) AND "price_category_domain"."domain" IN (\'%s\') '
            ,implode('\',\'', $aryGroups)
        );
    }

    $now = date('Y-m-d H:i:s');
    $query = sprintf('SELECT "master".*, "shows"."show_date", "shows"."show_time", "shows"."onsale" AS "min_onsale"%s FROM "shows" INNER JOIN "master" ON "master"."master_id" = "shows"."master_id" INNER JOIN "domainlist" ON "domainlist"."master_id" = "master"."master_id" %s WHERE "shows"."offsale" >= \'%s\' AND ("shows"."wt_offsale"=\'\' OR "shows"."wt_offsale"=0) AND "domainlist"."domain"=\'%s\' %s GROUP BY "shows"."shows_id"'
        ,$extraSqlFields
        ,$extraSqlJoins
        ,$now
        ,$cstage['tixDomain']
        ,$extraSqlConditions
    );

    $keyEventCalendar = 'eventCalendar_'.$cstage['dbDatabase'].sha1($query);
    if( !empty($cstage['cache']) ) {
        // Is the record cached to save on slow database connections?
        $calendar = $cstage['cache']->load($keyEventCalendar);
    }

    if( !$calendar ) {
        $result = $cstage['pdo']->query( $query );
        while( $show = $result->fetch( PDO::FETCH_ASSOC ) ) {
            $show['domainlist'] = $cstage['tixDomain'].';'.$_SESSION[SYS_USER]['domain'];
            $show['comingSoon'] = false;
            if( $now < $show['min_onsale'] ) {
                $show['comingSoon'] = true;
            }
            if( $show['rtt_id'] > 0 ) {
                $show['master_id'] = trim($show['rtt_label']).trim($show[]);
                if( !$cstage['rttEnable'] ) {
                    $show = array();
                }
            }
            $path->inc_once('_includes/libf_okEvent.php');
            if( okEvent($show) ) {
                // Save data into array for usage later
                $extraSort = $cstage['useEventSortOrder'] === true ? sprintf('%05d',$show['sortorder']) : '';
                $aryEvents[$show['show_date']][date('H:i',strtotime($show['show_time'])).$extraSort.$show['showname'].$show['master_id']] = $show;
            }
        }

        // Start rendering calendar.
        $calendar = "\r\n".'<table class="EventCalendar ui-widget-content ui-corner-all"><thead '._HEAD.'><tr><th colspan="7">'.lang('Calendar of events for').' '.date('Y F',strtotime($_SESSION[SYS_USER]['search']['Month'].'-02')).'</th></tr>'
          . "\r\n".'<tr><th>'.lang('Sunday').'</th><th>'.lang('Monday').'</th><th>'.lang('Tuesday').'</th><th>'.lang('Wednesday').'</th><th>'.lang('Thursday').'</th><th>'.lang('Friday').'</th><th>'.lang('Saturday').'</th></tr></thead>'
          . '<tbody>';

        $dayOfWeekPadding = date('w',$firstDayTimestamp);
        if( $dayOfWeekPadding == 0 ) {
            $dayOfWeekPadding = 6;
        } else {
            $dayOfWeekPadding -= 0;
        }
        if( $dayOfWeekPadding > 0 ) {
            $calendar .= "\r\n<tr>";
        }
        for($day=7; $day < $dayOfWeekPadding; $day++) {
            $calendar .= "\r\n<td class='EventCalendar_EmptyDate'>&nbsp;</td>";
        }
        $timeStamp = $firstDayTimestamp;
        while( $timeStamp <= $lastDayTimestamp ) {  
            if( date('w',$timeStamp) == 0 ) {
                $calendar .= "\r\n<tr>";
            }
            $dateKey = date('Y-m-d',$timeStamp);
            $calendar .= "\r\n".'<td class="EventCalendar_Date" id="date'.$dateKey.'" onmouseover="tbl_colorchange(\'date'.$dateKey.'\', \'highlight\');" onmouseout="tbl_colorchange(\'date'.$dateKey.'\', \'normal\');"><span>'.date('d',$timeStamp).'</span>';
            if( !empty($aryEvents[$dateKey]) ) {
                ksort($aryEvents[$dateKey]);
                $count = 0;
                foreach( $aryEvents[$dateKey] as $key=>$show ) {
                    $cssClass = $count++ % 2 ? _ODD : _EVEN;
                    $rttUrl = ( $show['rtt_id'] > 0 ) ? '&amp;rtt='.$show['rtt_id'] : '';
                    $strPriceList = (empty($show['pricelist']) ? '' : ' title="'.lang('Prices available').': '.$show['pricelist'].'"');
                    $calendar .= "\r\n<div {$cssClass}{$strPriceList}><a href='event-details.php?e={$show['master_id']}&amp;date={$dateKey}{$rttUrl}'>{$show['']} @ {$show['show_time']}</a></div>";
                }
            }
            $calendar .= '</td>';
            if( date('w',$timeStamp) == 0 ) { 
                $calendar .= "\r\n</tr>";
            }
            $timeStamp += 86400; // Get the next day (in seconds).
        }
        $dayOfWeekPadding = date('w',$timeStamp);
        if( $dayOfWeekPadding == 0 ) {
            $dayOfWeekPadding = 6;
        } else if( $dayOfWeekPadding == 0 ) {
            $dayOfWeekPadding = 0; // do not have an empty week of padding
        } else {
            $dayOfWeekPadding = 6 - $dayOfWeekPadding;
        }
        for($day=0; $day < $dayOfWeekPadding; $day++) {     
            $calendar .= "\r\n<td class='EventCalendar_EmptyDate'>&nbsp;</td>";
        }
        if( $dayOfWeekPadding > 0 ) {
            $calendar .= "\r\n</tr>";
        }
        $calendar .= "\r\n</tbody></table>";

        if( !empty($cstage['cache']) ) {
            $cstage['cache']->save($calendar, $keyEventCalendar);
        }
    }
    return $calendar;
}

0 个答案:

没有答案