| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * calendar.php |
| 5 | * |
| 6 | * Originally contrubuted by Michal Szczotka <michal@tuxy.org> |
| 7 | * |
| 8 | * Displays the main calendar page (month view). |
| 9 | * |
| 10 | * @copyright © 2002-2005 The SquirrelMail Project Team |
| 11 | * @license http://opensource.org/licenses/gpl-license.php GNU Public License |
| 12 | * @version $Id$ |
| 13 | * @package plugins |
| 14 | * @subpackage calendar |
| 15 | */ |
| 16 | |
| 17 | /** |
| 18 | */ |
| 19 | define('SM_PATH','../../'); |
| 20 | |
| 21 | /* Calender plugin required files. */ |
| 22 | require_once(SM_PATH . 'plugins/calendar/calendar_data.php'); |
| 23 | require_once(SM_PATH . 'plugins/calendar/functions.php'); |
| 24 | |
| 25 | /* SquirrelMail required files. */ |
| 26 | require_once(SM_PATH . 'include/validate.php'); |
| 27 | require_once(SM_PATH . 'functions/strings.php'); |
| 28 | require_once(SM_PATH . 'functions/date.php'); |
| 29 | require_once(SM_PATH . 'config/config.php'); |
| 30 | require_once(SM_PATH . 'functions/page_header.php'); |
| 31 | require_once(SM_PATH . 'include/load_prefs.php'); |
| 32 | require_once(SM_PATH . 'functions/html.php'); |
| 33 | |
| 34 | /* get globals */ |
| 35 | |
| 36 | // undo rg = on effects |
| 37 | if (isset($month)) unset($month); |
| 38 | if (isset($year)) unset($year); |
| 39 | |
| 40 | if (isset($_GET['month']) && is_numeric($_GET['month'])) { |
| 41 | $month = $_GET['month']; |
| 42 | } |
| 43 | if (isset($_GET['year']) && is_numeric($_GET['year'])) { |
| 44 | $year = $_GET['year']; |
| 45 | } |
| 46 | if (isset($_POST['year']) && is_numeric($_POST['year'])) { |
| 47 | $year = $_POST['year']; |
| 48 | } |
| 49 | if (isset($_POST['month']) && is_numeric($_POST['month'])) { |
| 50 | $month = $_POST['month']; |
| 51 | } |
| 52 | /* got 'em */ |
| 53 | |
| 54 | //display upper part of month calendar view |
| 55 | function startcalendar() { |
| 56 | global $year, $month, $color; |
| 57 | |
| 58 | $prev_date = mktime(0, 0, 0, $month - 1, 1, $year); |
| 59 | $act_date = mktime(0, 0, 0, $month, 1, $year); |
| 60 | $next_date = mktime(0, 0, 0, $month + 1, 1, $year); |
| 61 | $prev_month = date( 'm', $prev_date ); |
| 62 | $next_month = date( 'm', $next_date); |
| 63 | $prev_year = date( 'Y', $prev_date); |
| 64 | $next_year = date( 'Y', $next_date ); |
| 65 | $self = 'calendar.php'; |
| 66 | |
| 67 | echo html_tag( 'tr', "\n". |
| 68 | html_tag( 'td', "\n". |
| 69 | html_tag( 'table', '', '', $color[0], 'width="100%" border="0" cellpadding="2" cellspacing="1"' ) . |
| 70 | html_tag( 'tr', "\n". |
| 71 | html_tag( 'th', |
| 72 | "<a href=\"$self?year=".($year-1)."&month=$month\"><< ".($year-1)."</a>" |
| 73 | ) . "\n". |
| 74 | html_tag( 'th', |
| 75 | "<a href=\"$self?year=$prev_year&month=$prev_month\">< " . |
| 76 | date_intl( 'M', $prev_date). "</a>" |
| 77 | ) . "\n". |
| 78 | html_tag( 'th', date_intl( 'F Y', $act_date ), '', $color[0], 'colspan="3"') . |
| 79 | html_tag( 'th', |
| 80 | "<a href=\"$self?year=$next_year&month=$next_month\">" . |
| 81 | date_intl( 'M', $next_date) . " ></a>" |
| 82 | ) . "\n". |
| 83 | html_tag( 'th', |
| 84 | "<a href=\"$self?year=".($year+1)."&month=$month\">".($year+1)." >></a>" |
| 85 | ) |
| 86 | ) . "\n". |
| 87 | html_tag( 'tr', |
| 88 | html_tag( 'th', _("Sunday"), '', $color[5], 'width="14%" width="90"' ) ."\n" . |
| 89 | html_tag( 'th', _("Monday"), '', $color[5], 'width="14%" width="90"' ) ."\n" . |
| 90 | html_tag( 'th', _("Tuesday"), '', $color[5], 'width="14%" width="90"' ) ."\n" . |
| 91 | html_tag( 'th', _("Wednesday"), '', $color[5], 'width="14%" width="90"' ) ."\n" . |
| 92 | html_tag( 'th', _("Thursday"), '', $color[5], 'width="14%" width="90"' ) ."\n" . |
| 93 | html_tag( 'th', _("Friday"), '', $color[5], 'width="14%" width="90"' ) ."\n" . |
| 94 | html_tag( 'th', _("Saturday"), '', $color[5], 'width="14%" width="90"' ) ."\n" |
| 95 | ) |
| 96 | ) , |
| 97 | '', $color[0] ) ."\n"; |
| 98 | } |
| 99 | |
| 100 | //main logic for month view of calendar |
| 101 | function drawmonthview() { |
| 102 | global $year, $month, $color, $calendardata, $todayis; |
| 103 | |
| 104 | $aday = 1 - date('w', mktime(0, 0, 0, $month, 1, $year)); |
| 105 | $days_in_month = date('t', mktime(0, 0, 0, $month, 1, $year)); |
| 106 | while ($aday <= $days_in_month) { |
| 107 | echo html_tag( 'tr' ); |
| 108 | for ($j=1; $j<=7; $j++) { |
| 109 | $cdate="$month"; |
| 110 | ($aday<10)?$cdate=$cdate."0$aday":$cdate=$cdate."$aday"; |
| 111 | $cdate=$cdate."$year"; |
| 112 | if ( $aday <= $days_in_month && $aday > 0){ |
| 113 | echo html_tag( 'td', '', 'left', $color[4], 'height="50" valign="top"' ) ."\n". |
| 114 | html_tag( 'div', '', 'right' ); |
| 115 | echo(($cdate==$todayis) ? '<font size="-1" color="'.$color[1].'">[ ' . _("TODAY") . " ] " : '<font size="-1">'); |
| 116 | echo "<a href=day.php?year=$year&month=$month&day="; |
| 117 | echo(($aday<10) ? "0" : ""); |
| 118 | echo "$aday>$aday</a></font></div>"; |
| 119 | } else { |
| 120 | echo html_tag( 'td', '', 'left', $color[0]) ."\n". |
| 121 | " "; |
| 122 | } |
| 123 | if (isset($calendardata[$cdate])){ |
| 124 | $i=0; |
| 125 | while ($calfoo = each($calendardata[$cdate])) { |
| 126 | $calbar = $calendardata[$cdate][$calfoo['key']]; |
| 127 | $title = '['. $calfoo['key']. '] ' .$calbar['message']; |
| 128 | echo ($calbar['priority']==1) ? "<a href=\"#\" style=\"text-decoration:none; color: $color[1]\" title=\"$title\">$calbar[title]</a><br />\n" : "<a href=\"#\" style=\"text-decoration:none; color: $color[6]\" title=\"$title\">$calbar[title]</a><br />\n"; |
| 129 | $i=$i+1; |
| 130 | if($i==2){ |
| 131 | break; |
| 132 | } |
| 133 | } |
| 134 | } |
| 135 | echo "\n</td>\n"; |
| 136 | $aday++; |
| 137 | } |
| 138 | echo '</tr>'; |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | //end of monthly view and form to jump to any month and year |
| 143 | function endcalendar() { |
| 144 | global $year, $month, $day, $color; |
| 145 | |
| 146 | echo html_tag( 'tr' ) ."\n" . |
| 147 | html_tag( 'td', '', 'left', '', 'colspan="7"' ) ."\n" . |
| 148 | " <form name=\"caljump\" action=\"calendar.php\" method=\"post\">\n". |
| 149 | " <select name=\"year\">\n"; |
| 150 | select_option_year($year); |
| 151 | echo " </select>\n". |
| 152 | " <select name=\"month\">\n"; |
| 153 | select_option_month($month); |
| 154 | echo " </select>\n". |
| 155 | ' <input type="submit" value="' . _("Go") . "\" />\n". |
| 156 | " </form>\n". |
| 157 | " </td></tr>\n". |
| 158 | "</table></td></tr></table>\n"; |
| 159 | } |
| 160 | |
| 161 | |
| 162 | if( !isset( $month ) || $month <= 0){ |
| 163 | $month = date( 'm' ); |
| 164 | } |
| 165 | if( !isset($year) || $year <= 0){ |
| 166 | $year = date( 'Y' ); |
| 167 | } |
| 168 | if( !isset($day) || $day <= 0){ |
| 169 | $day = date( 'd' ); |
| 170 | } |
| 171 | |
| 172 | $todayis = date( 'mdY' ); |
| 173 | $calself=basename($PHP_SELF); |
| 174 | |
| 175 | displayPageHeader($color, 'None'); |
| 176 | calendar_header(); |
| 177 | readcalendardata(); |
| 178 | startcalendar(); |
| 179 | drawmonthview(); |
| 180 | endcalendar(); |
| 181 | |
| 182 | ?> |
| 183 | </body></html> |