$homeStr = translate('Home');
     $goto_link[] = '<a title="' . $homeStr . '" class="bold" href=" ' . "{$home}\">{$homeStr}" . '</a>';
 }
 $mycal = empty($GLOBALS['STARTVIEW']) ? 'index.php' : $GLOBALS['STARTVIEW'];
 $mycal .= strpos($mycal, '.php') ? '' : '.php';
 // Calc URL to today.
 $reqURI = 'month.php';
 if (!empty($GLOBALS['SCRIPT_NAME'])) {
     $reqURI = $GLOBALS['SCRIPT_NAME'];
 } else {
     if (!empty($_SERVER['SCRIPT_NAME'])) {
         $reqURI = $_SERVER['SCRIPT_NAME'];
     }
 }
 $todayURL = !strstr($reqURI, 'day.php') && !strstr($reqURI, 'month.php') && !strstr($reqURI, 'week.php') ? 'day.php' : $reqURI;
 if (!access_can_view_page($todayURL)) {
     $todayURL = '';
 }
 if ($single_user != 'Y') {
     $goto_link[] = '<a title="' . $myCalStr . '" class="bold" href="' . "{$mycal}\">" . (!empty($user) && $user != $login ? translate('Back to My Calendar') : $myCalStr) . '</a>';
     if (!empty($todayURL)) {
         if (!empty($user) && $user != $login) {
             $todayURL .= '?user='******'<a title="' . $todayStr . '" class="bold" href="' . "{$todayURL}\">{$todayStr}" . '</a>';
     }
     if ($login != '__public__') {
         if (!$is_nonuser && $readonly == 'N') {
             if (!access_is_enabled() || access_can_access_function(ACCESS_ADMIN_HOME) || access_can_access_function(ACCESS_PREFERENCES)) {
                 $goto_link[] = '<a title="' . $adminStr . '" class="bold" href="adminhome.php' . ($is_nonuser_admin ? '?user='******'') . "\">{$adminStr}" . '</a>';
             }
Example #2
0
<?php

/* $Id: index.php,v 1.16.2.2 2007/08/06 02:28:30 cknudsen Exp $ */
include_once 'includes/init.php';
// If not yet logged in, you will be redirected to login.php before
// we get to this point (by init.php included above).
if (!empty($STARTVIEW)) {
    $page = get_preferred_view();
    if (access_can_view_page($page)) {
        send_to_preferred_view();
    } else {
        // User's preferences need to be updated to their preferred view.
        if (access_can_access_function(ACCESS_PREFERENCES)) {
            do_redirect('pref.php');
        }
        // User does not have access to preferences...
        // So, we need to pick another page.
        if (access_can_access_function(ACCESS_WEEK)) {
            do_redirect('week.php');
        } elseif (access_can_access_function(ACCESS_MONTH)) {
            do_redirect('month.php');
        } elseif (access_can_access_function(ACCESS_DAY)) {
            do_redirect('day.php');
        } elseif (access_can_access_function(ACCESS_YEAR)) {
            do_redirect('year.php');
        }
        // At this point, this user cannot view the preferred view in their
        // preferences (and they cannot update their preferences), and they cannot
        // view any of the standard day/week/month/year pages. All that's left is a
        // custom view that is either created by them or a global view.
        if (count($views) > 0) {
function get_preferred_view($indate = '', $args = '')
{
    global $ALLOW_VIEW_OTHER, $is_admin, $STARTVIEW, $thisdate, $views;
    // We want user's to set  their pref on first login.
    if (empty($STARTVIEW)) {
        return false;
    }
    $url = $STARTVIEW;
    // We used to just store "month" in $STARTVIEW without the ".php".
    // This is just to prevent users from getting a "404 not found"
    // if they have not updated their preferences.
    $url .= !strpos($STARTVIEW, '.php') ? '.php' : '';
    // Prevent endless looping
    // if preferred view is custom and viewing others is not allowed.
    if (substr($url, 0, 5) == 'view_' && $ALLOW_VIEW_OTHER == 'N' && !$is_admin) {
        $url = 'month.php';
    }
    if (!access_can_view_page($url)) {
        if (access_can_access_function(ACCESS_DAY)) {
            $url = 'day.php';
        } else {
            if (access_can_access_function(ACCESS_MONTH)) {
                $url = 'month.php';
            } else {
                if (access_can_access_function(ACCESS_WEEK)) {
                    $url = 'week.php';
                }
            }
        }
        // At this point, this user cannot access the view set in their preferences
        // (and they cannot update their preferences), and they cannot view any of
        // the standard day/month/week/year pages. All that's left is either
        // a custom view that was created by them, or a global view.
        if (count($views) > 0) {
            $url = $views[0]['url'];
        }
    }
    $url = str_replace('&amp;', '&', $url);
    $url = str_replace('&', '&amp;', $url);
    $xdate = empty($indate) ? $thisdate : $indate;
    $url .= empty($xdate) ? '' : (strstr($url, '?') ? '&amp;' : '?') . 'date=' . $xdate;
    $url .= empty($args) ? '' : (strstr($url, '?') ? '&amp;' : '?') . $args;
    return $url;
}
function print_menu_dates($menu = false)
{
    global $cat_id, $CATEGORIES_ENABLED, $custom_view, $DATE_FORMAT_MD, $DATE_FORMAT_MY, $DISPLAY_WEEKENDS, $id, $login, $SCRIPT, $thisday, $thismonth, $thisyear, $user, $WEEK_START;
    $goStr = translate('Go');
    $ret = $urlArgs = $include_id = '';
    // TODO add this to admin and pref.
    // Change this value to 'Y' to enable staying in custom views.
    $STAY_IN_VIEW = 'N';
    $selected = ' selected="selected"';
    if ($STAY_IN_VIEW == 'Y' && !empty($custom_view)) {
        $include_id = true;
        $monthUrl = $SCRIPT;
    } else {
        if (access_can_view_page('month.php')) {
            $monthUrl = 'month.php';
        } else {
            $monthUrl = $GLOBALS['STARTVIEW'];
            if (preg_match('/[?&](\\S+)=(\\S+)/', $monthUrl, $match)) {
                $monthUrl = $match[0];
                $urlArgs = '
              <input type="hidden" name="' . $match[1] . '" value="' . $match[2] . '" />';
            }
        }
    }
    if (access_can_access_function(ACCESS_MONTH)) {
        $ret .= '
            <form action="' . $monthUrl . '" method="get" name="SelectMonth" id="month' . ($menu ? 'menu' : 'form') . '"> ' . $urlArgs . (!empty($user) && $user != $login ? '
              <input type="hidden" name="user" value="' . $user . '" />' : '') . (!empty($id) && $include_id ? '
              <input type="hidden" name="id" value="' . $id . '" />' : '') . (!empty($cat_id) && $CATEGORIES_ENABLED == 'Y' && (!$user || $user == $login) ? '
              <input type="hidden" name="cat_id" value="' . $cat_id . '" />' : '') . '
              <label for="monthselect"><a ' . 'href="javascript:document.SelectMonth.submit()">' . translate('Month') . '</a>:&nbsp;</label>
              <select name="date" id="monthselect" ' . 'onchange="document.SelectMonth.submit()">';
        if (!empty($thisyear) && !empty($thismonth)) {
            $m = $thismonth;
            $y = $thisyear;
        } else {
            $m = date('m');
            $y = date('Y');
        }
        $d_time = mktime(0, 0, 0, $m, 1, $y);
        $thisdate = date('Ymd', $d_time);
        // $y--;
        $m -= 7;
        for ($i = 0; $i < 25; $i++) {
            $m++;
            if ($m > 12) {
                $m = 1;
                $y++;
            }
            if ($y >= 1970 && $y < 2038) {
                $d = mktime(0, 0, 0, $m, 1, $y);
                $dateYmd = date('Ymd', $d);
                $ret .= '
                  <option value="' . $dateYmd . '"' . ($dateYmd == $thisdate ? $selected : '') . '>' . date_to_str($dateYmd, $DATE_FORMAT_MY, false, true, 0) . '</option>';
            }
        }
    }
    if (access_can_access_function(ACCESS_WEEK)) {
        $ret .= '
              </select>' . ($menu ? '' : '
              <input type="submit" value="' . $goStr . '" />') . '
            </form>' . ($menu ? '
          </td>
          <td class="ThemeMenubackgr ThemeMenu">' : '');
        if ($STAY_IN_VIEW == 'Y' && !empty($custom_view)) {
            $weekUrl = $SCRIPT;
        } else {
            if (access_can_view_page('week.php')) {
                $urlArgs = '';
                $weekUrl = 'week.php';
            } else {
                $weekUrl = $GLOBALS['STARTVIEW'];
                if (preg_match('/[?&](\\S+)=(\\S+)/', $weekUrl, $match)) {
                    $weekUrl = $match[0];
                    $urlArgs = '
                <input type="hidden" name="' . $match[1] . '" value="' . $match[2] . '" />';
                }
            }
        }
        $ret .= '
            <form action="' . $weekUrl . '" method="get" name="SelectWeek" id="week' . ($menu ? 'menu' : 'form') . '">' . $urlArgs . (!empty($user) && $user != $login ? '
              <input type="hidden" name="user" value="' . $user . '" />' : '') . (!empty($id) && $include_id ? '
              <input type="hidden" name="id" value="' . $id . '" />' : '') . (!empty($cat_id) && $CATEGORIES_ENABLED == 'Y' && (!$user || $user == $login) ? '
              <input type="hidden" name="cat_id" value="' . $cat_id . '" />' : '') . '
              <label for="weekselect"><a ' . 'href="javascript:document.SelectWeek.submit()">' . translate('Week') . '</a>:&nbsp;</label>
              <select name="date" id="weekselect" ' . 'onchange="document.SelectWeek.submit()">';
        if (!empty($thisyear) && !empty($thismonth)) {
            $m = $thismonth;
            $y = $thisyear;
        } else {
            $m = date('m');
            $y = date('Y');
        }
        $d = empty($thisday) ? date('d') : $thisday;
        $d_time = mktime(0, 0, 0, $m, $d, $y);
        $thisweek = date('W', $d_time);
        $wkstart = get_weekday_before($y, $m, $d);
        $lastDay = $DISPLAY_WEEKENDS == 'N' ? 4 : 6;
        for ($i = -5; $i <= 9; $i++) {
            $twkstart = $wkstart + 604800 * $i;
            $twkend = $twkstart + 86400 * $lastDay;
            $dateSYmd = date('Ymd', $twkstart);
            $dateEYmd = date('Ymd', $twkend);
            $dateW = date('W', $twkstart + 86400);
            if ($twkstart > 0 && $twkend < 2146021200) {
                $ret .= '
                <option value="' . $dateSYmd . '"' . ($dateW == $thisweek ? $selected : '') . '>' . (!empty($GLOBALS['PULLDOWN_WEEKNUMBER']) && $GLOBALS['PULLDOWN_WEEKNUMBER'] == 'Y' ? '( ' . $dateW . ' )&nbsp;&nbsp;' : '') . sprintf("%s - %s", date_to_str($dateSYmd, $DATE_FORMAT_MD, false, true, 0), date_to_str($dateEYmd, $DATE_FORMAT_MD, false, true, 0)) . '</option>';
            }
        }
    }
    if (access_can_access_function(ACCESS_YEAR)) {
        $ret .= '
                </select>' . ($menu ? '' : '
              <input type="submit" value="' . $goStr . '" />') . '
            </form>' . ($menu ? '
          </td>
          <td class="ThemeMenubackgr ThemeMenu" align="right">' : '');
        if ($STAY_IN_VIEW == 'Y' && !empty($custom_view)) {
            $yearUrl = $SCRIPT;
        } else {
            if (access_can_view_page('year.php')) {
                $urlArgs = '';
                $yearUrl = 'year.php';
            } else {
                $yearUrl = $GLOBALS['STARTVIEW'];
                if (preg_match('/[?&](\\S+)=(\\S+)/', $yearUrl, $match)) {
                    $yearUrl = $match[0];
                    $urlArgs = '
              <input type="hidden" name="' . $match[1] . '" value="' . $match[2] . '" />';
                }
            }
        }
        $ret .= '
            <form action="' . $yearUrl . '" method="get" name="SelectYear" id="year' . ($menu ? 'menu' : 'form') . '">' . $urlArgs . (!empty($user) && $user != $login ? '
              <input type="hidden" name="user" value="' . $user . '" />' : '') . (!empty($id) && $include_id ? '
              <input type="hidden" name="id" value="' . $id . '" />' : '') . (!empty($cat_id) && $CATEGORIES_ENABLED == 'Y' && (!$user || $user == $login) ? '
              <input type="hidden" name="cat_id" value="' . $cat_id . '" />' : '') . '
              <label for="yearselect"><a ' . 'href="javascript:document.SelectYear.submit()">' . translate('Year') . '</a>:&nbsp;</label>
              <select name="year" id="yearselect" ' . 'onchange="document.SelectYear.submit()">';
        $y = empty($thisyear) ? date('Y') : $thisyear;
        for ($i = $y - 2; $i < $y + 6; $i++) {
            if ($i >= 1970 && $i < 2038) {
                $ret .= '
                <option value="' . $i . '"' . ($i == $y ? $selected : '') . ">{$i}" . '</option>';
            }
        }
        $ret .= '
              </select>' . ($menu ? '' : '
              <input type="submit" value="' . $goStr . '" />') . '
            </form>';
    }
    return $ret;
}