Code: Alles auswählen
<?php
#################################################################
## Mod Title: mycalendar+ Mod w/selected forum integration
## (based on mycalendar Mod by marksten)
## Mod Version: 0.8
## Author: flashdagger
## Description: Enables users to add events to the calendar
## through a chosen forum.
#################################################################
define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
include($phpbb_root_path . 'includes/bbcode.'.$phpEx);
// Start session management
$userdata = session_pagestart($user_ip, PAGE_MYCALENDAR);
init_userprefs($userdata);
// determine the information for the current date
list($today['year'], $today['month'], $today['day']) = explode('-', create_date('Y-m-d', time(), $board_config['board_timezone']));
// get the month/year offset from the get variables, or else use first day of this month
if ( checkdate($HTTP_POST_VARS['month'], 1, $HTTP_POST_VARS['year']) ) {
$month = $HTTP_POST_VARS['month'];
$year = $HTTP_POST_VARS['year'];
}
elseif ( checkdate($HTTP_GET_VARS['month'], 1, $HTTP_GET_VARS['year']) ) {
$month = $HTTP_GET_VARS['month'];
$year = $HTTP_GET_VARS['year'];
}
else {
$month = $today['month'];
$year = $today['year'];
}
$year = $year % 100 < 50 ? min($year % 100, 37) + 2000 : max($year % 100, 71) + 1900;
if ( $HTTP_POST_VARS['f'] > 0 ) {
$forum_id = $HTTP_POST_VARS['f'];
} elseif ( $HTTP_GET_VARS['f'] > 0 ) {
$forum_id = $HTTP_GET_VARS['f'];
} else $forum_id = '';
$page_title = $lang['View_calendar'];
include ($phpbb_root_path . 'includes/page_header.'.$phpEx);
$template->set_filenames(array(
'body' => 'mycalendar_mod/mycalendar_body.tpl')
);
// For the Birthday Mod
unset($birthdays);
// these aren't really dates, so the hard-coded 31 isn't a problem
$date_start = (strlen($month)==1) ? '0':''. $month.'01';
$date_end = (strlen($month)==1) ? '0':''. $month.'31';
// load only the birthdays for this month
$sql = "SELECT user_id, username, user_birthday FROM " . USERS_TABLE. " WHERE user_birthday!=999999 AND
(DATE_FORMAT(addDate('1970-01-01', INTERVAL user_birthday DAY),'%m%d') BETWEEN '$date_start' AND '$date_end') ORDER BY username";
if (!$result = $db->sql_query($sql)){
message_die(GENERAL_ERROR, 'Error querying birthdays for mycalendar.');
}
while ($birthdayrow = $db->sql_fetchrow($result)){
$user_birthday = realdate("Ymd",$birthdayrow['user_birthday']);
// since we loaded the birthdays for this month, save the b-day in the array indexed by day
$birthdays[intval($user_birthday[6].$user_birthday[7])][] = (
array(
'user_id' => $birthdayrow['user_id'],
'username' => $birthdayrow['username'],
'display_date' => realdate($lang['DATE_FORMAT'],$birthdayrow['user_birthday']),
'birthday_year' => $user_birthday[0].$user_birthday[1].$user_birthday[2].$user_birthday[3])
);
}
list($monthName, $numDays, $offset) = explode('-', date('F-t-w', mktime(0,0,0,$month,1,$year)));
if ($lang['Calendar_start_monday']) $offset = ($offset + 6) % 7;
$monthName = $lang['datetime'][$monthName];
$forum_limit = !empty($forum_id) ? " AND f.forum_id = $forum_id " : '';
$is_auth_ary = array();
$is_auth_ary = auth(AUTH_ALL, AUTH_LIST_ALL, $userdata, $forum_data);
$forums_id = (array_keys ($is_auth_ary));
foreach ($forums_id as $forum) {
if ($is_auth_ary[$forum]['auth_read'] && $is_auth_ary[$forum]['auth_view']) {
$forums_to_read .= empty($forums_to_read) ? $forum : ", $forum";
}
if ($is_auth_ary[$forum]['auth_post'] && $is_auth_ary[$forum]['auth_calendar']) {
$forums_to_post .= empty($forums_to_post) ? $forum : ", $forum";
}
}
$sql_date = sprintf('%04d', $year) . sprintf('%02d', $month);
if (!empty($forums_to_read)) {
$in_forums = " AND f.forum_id IN ($forums_to_read) ";
$sql = "SELECT d.day, d.fday, UNIX_TIMESTAMP(c.cal_date) as cal_date, c.cal_interval_units, c.cal_interval, c.cal_repeat, u.username,
UNIX_TIMESTAMP(CONCAT(DATE_FORMAT(
(CASE c.cal_interval_units
WHEN 'DAY' THEN INTERVAL (c.cal_repeat - 1) * cal_interval DAY + c.cal_date
WHEN 'WEEK' THEN INTERVAL (c.cal_repeat - 1) * cal_interval * 7 DAY + c.cal_date
WHEN 'MONTH' THEN INTERVAL (c.cal_repeat - 1) * cal_interval MONTH + c.cal_date
WHEN 'YEAR' THEN INTERVAL (c.cal_repeat - 1) * cal_interval YEAR + c.cal_date
ELSE INTERVAL 1 DAY + c.cal_date END), '%Y-%m-%d '), c.cal_time_end)) as cal_date_end,
t.topic_id, t.topic_title, t.topic_poster, f.forum_id, f.forum_name
FROM " . MYCALENDAR_TABLE . " as c, " . MYCAL_DATE_TABLE . " as d, " . FORUMS_TABLE . " as f, " . TOPICS_TABLE . " as t, " . USERS_TABLE . " as u
WHERE t.topic_id = c.topic_id AND t.forum_id = f.forum_id $in_forums $forum_limit AND t.topic_poster = u.user_id AND
((CASE c.cal_interval_units
WHEN 'DAY' THEN (TO_DAYS(CONCAT('$sql_date',d.fday)) - TO_DAYS(c.cal_date)) / c.cal_interval + 1
WHEN 'WEEK' THEN (TO_DAYS(CONCAT('$sql_date',d.fday)) - TO_DAYS(c.cal_date)) / (c.cal_interval * 7) + 1
WHEN 'MONTH' THEN PERIOD_DIFF('$sql_date', DATE_FORMAT(c.cal_date, '%Y%m')) / c.cal_interval + 1
WHEN 'YEAR' THEN PERIOD_DIFF('$sql_date', DATE_FORMAT(c.cal_date, '%Y%m')) / (c.cal_interval * 12) + 1
END) BETWEEN 1 AND c.cal_repeat OR (c.cal_repeat = 0 AND UNIX_TIMESTAMP(CONCAT('$sql_date', d.fday)) + 86400 > UNIX_TIMESTAMP(c.cal_date)) ) AND
(CASE c.cal_interval_units
WHEN 'DAY' THEN MOD(TO_DAYS(CONCAT('$sql_date',d.fday)) - TO_DAYS(cal_date), cal_interval)
WHEN 'WEEK' THEN MOD(TO_DAYS(CONCAT('$sql_date',d.fday)) - TO_DAYS(cal_date), (cal_interval * 7))
WHEN 'MONTH' THEN MOD(PERIOD_DIFF('$sql_date', DATE_FORMAT(c.cal_date, '%Y%m')), c.cal_interval)
WHEN 'YEAR' THEN MOD(PERIOD_DIFF('$sql_date', DATE_FORMAT(c.cal_date, '%Y%m')), (c.cal_interval * 12))
END) = 0 AND
UNIX_TIMESTAMP(CONCAT('$sql_date', " . $numDays . ")) + 86400 > UNIX_TIMESTAMP(c.cal_date) AND d.day <= " . $numDays . " AND
((c.cal_interval_units = 'DAY' OR c.cal_interval_units = 'WEEK') OR ((c.cal_interval_units = 'MONTH' OR c.cal_interval_units = 'YEAR') AND d.fday = DATE_FORMAT(c.cal_date, '%d')))
ORDER BY d.day ASC, IF((c.cal_repeat = 0 AND c.cal_interval = 1 AND c.cal_interval_units = 'DAY'), 1, 0) DESC, IF((c.cal_repeat > 1 AND c.cal_interval = 1 AND c.cal_interval_units = 'DAY'), c.cal_repeat, 0) DESC, c.cal_date ASC";
if ( !($result = $db->sql_query($sql)) ) {
message_die(GENERAL_ERROR, 'Error querying dates for calendar.');
}
$event = $db->sql_fetchrow($result);
}
// prepare the loops for running through the calendar for the current month
$numRows = ceil(($numDays + $offset) / 7);
$day = 1;
$lastline = 0;
$topicCache = array();
$eventStack = array();
$mycal_length_max = 20;
$forumstyle = mycal_get_forumstyle();
$format = str_replace(array('m', 'd', 'y'), array('m', 'd', 'Y'), strtolower($lang['DATE_INPUT_FORMAT']));
$js_arraydata = "";
$used_topics = "#";
foreach(range(1, $numRows) as $row) {
$template->assign_block_vars('date_row', array());
foreach (range(1, 7) as $weekIndex) {
// we are before the first date
if ( ($row == 1 && $weekIndex <= $offset) ) {
if ( $weekIndex == 1 ) {
$template->assign_block_vars('date_row.date_cell', array(
'BLANK_COLSPAN' => $offset)
);
$template->assign_block_vars('date_row.date_cell.switch_blank_cells', array());
}
}
// we are after the last date
elseif ($day > $numDays) {
if ($day == ($numDays + 1)) {
$template->assign_block_vars('date_row.date_cell', array(
'BLANK_COLSPAN' => ($row * 7) - ($numDays + $offset))
);
$template->assign_block_vars('date_row.date_cell.switch_blank_cells', array());
// We have to now increment the day so that we don't repeat this cell
$day++;
}
}
// we are on a date
else {
$image_add_event = !empty($forums_to_post) ? "<input type=\"image\" name=\"cal_date($day)\" src=\"" . $images['add_event'] . "\" align=\"middle\" width=\"13\" height=\"13\" border=\"0\" title=\"{$lang['Submit_event']}\" alt=\"" . $lang['Submit_event'] . "\" />" : " ";
$template->assign_block_vars('date_row.date_cell', array(
'TODAY_STYLE' => $today_style,
'DATE_CLASS' => ($row % 2) ? 'row2' : 'row3',
'DATE' => $day,
'I_ADD_EVENT' => $image_add_event)
);
$template->assign_block_vars('date_row.date_cell.switch_date_cells', array());
// allow the template to handle how to treat the day
if ($today['day'] == $day && $today['month'] == $month && $today['year'] == $year) {
$template->assign_block_vars('date_row.date_cell.switch_date_cells.switch_date_today', array());
}
else {
$template->assign_block_vars('date_row.date_cell.switch_date_cells.switch_date_otherday', array());
}
// list birthdays first
if (isset($birthdays[$day])) // see if there is a birthday on this day
foreach ($birthdays[$day] as $users){
$topic_title = '{NAME}';
// $link_text is how the birthday will appear on the calendar (notice the link break <BR>)
$link_text = str_replace('{TITLE}', $lang['Birthday'], $topic_title);
$link_text = str_replace('{NAME}', $users['username'], $link_text);
// $title_text is how the title of the popup will appear
$title_text = str_replace('{TITLE}', $lang['Birthday'], $topic_title);
$title_text = str_replace('{NAME}', $users['username'], $title_text);
// prepare the popup text, escaping quotes for java*script
$u_user = append_sid('profile.' . $phpEx . '?mode=viewprofile&u='.$users['user_id']);
// calculate the user's age (as of the calendar year)
$user_age = intval($year)-intval($users['birthday_year']);
$style = 'style="height:14px;margin:1px 0px;padding-left:2px;';
$caption = "";
// configure the details section of the popup
// line 1:
$line1 = "<center><b>". $users['username']." (".$user_age. ")</b>";
//line 2:
$line2 = "<center>".$users['display_date']. "</center>";
$tiptext = "<div style=\\\"white-space:nowrap;\\\">{LINE1}<br>{LINE2}</div>";
$tiptext = str_replace("{LINE1}", $line1, $tiptext);
$tiptext = str_replace("{LINE2}", $line2, $tiptext);
$tiptext = str_replace("'", "\\'", $tiptext);
// we need to generate a unique topic ID for the js array, so user the
// userid. To avoid conflicts with Topic IDs, also make it negative
$ol_topic_id = -1 * intval($users['user_id']);
$js_arraydata .= "\nol_caps[$ol_topic_id] = \"$caption\";\nol_texts[$ol_topic_id] = \"$tiptext\";";
$overlib = "onmouseover=\"return overlib(INARRAY, $ol_topic_id, CAPARRAY, $ol_topic_id, CSSCLASS, FGCLASS, 'ol_fg', BGCLASS, 'ol_bg', CAPTIONFONTCLASS, 'ol_caption', TEXTFONTCLASS, 'ol_text', STICKY, AUTOCLOSE, NOCLOSE, HAUTO, VAUTO, DELAY, 400);\" onmouseout=\"return nd();\"";
// in order to separate events from birthdays, make the birthdays look different
// this will display the birthday in a table with a border and white background
//$entry = "<div $style ><span class=\"gensmall\"></span><table cellpadding=1 cellspacing=0 style='background-color: white; border: 1px solid black;' width='100%'><tr><td><a href=\"$u_user\" class=\"gensmall\" style=\"$style\" $overlib >$link_text</a></td></tr></table></div>";
// to dispay birthdays as events, uncomment the following line:
$entry = "<div $style ><span class=\"gensmall\"></span><a href=\"$u_user\" class=\"gensmall\" style=\"$style\" $overlib >". str_replace('<br>', '', $link_text)."</a></div>";
$template->assign_block_vars('date_row.date_cell.switch_date_cells.date_event', array(
'U_EVENT' => $entry));
}
while ( $day == $event['day'] )
{
$act_date = "$year-$month-" . sprintf('%02d', $day);
$cal_date_end = date('Y-m-d', $event['cal_date_end']);
$cal_date = date('Y-m-d', $event['cal_date']);
// prepare the popup text, escaping quotes for javascript
$title_text = '<b>' . $lang['Topic'] . ':</b> ' . $event['topic_title'] . '<br /><b>' . $lang['Forum'] . ':</b> <i>' . $event['forum_name'] . '</i>';
// tack on the interval and repeat if this is a repeated event
if ($event['cal_repeat'] != 1) {
$title_text .= '<br /><b>' . $lang['Calendar_interval'] . ':</b> ' . $event['cal_interval'] . ' ' . (($event['cal_interval'] == 1) ? $lang['interval'][strtolower($event['cal_interval_units'])] : $lang['interval'][strtolower($event['cal_interval_units']) . 's']). '<br /><b>' . $lang['Calendar_repeat'] . ':</b> ' . ($topic['cal_repeat'] ? $event['cal_repeat'] . 'x' : $lang['Event_always']);
}
$title_text .= '<br />' . $post_text;
$title_text = str_replace('\'', '\\\'', htmlspecialchars($title_text));
// make the url for the topic
$topic_url = append_sid('viewtopic.' . $phpEx . '?' . POST_TOPIC_URL . '=' . $event['topic_id']);
// if we have a block event running (interval = 1 day) with this topic ID, then output our line
if ($event['cal_repeat'] != 1 && $event['cal_interval'] == 1 && $event['cal_interval_units'] == 'DAY' && $cal_date != $act_date && $day != 1 ) {
$pos = array_search($event['topic_id'], $topicCache);
if ( $cal_date_end == $act_date ) {
//$arrowEnd = '<img src="' . $images['event_block_end'] . '" border="0" height="12" width="12" />';
$topic_text = '>>|';
if ($pos) unset($topicCache[$pos]);
} else {
//$arrowEnd = '<img src="' . $images['event_block_arrow'] . '" border="0" height="12" width="12" />';
$topic_text = '>>';
}
$block_style = 'text-align:center;';
//'<div style="background: url(' . $images['event_block_bar'] . ') repeat-x center center; text-align: right;">' . $arrowEnd . '</div>';
$bullet = '';
} else {
for ($pos = 1; $topicCache[$pos] || $eventStack[$pos]; $pos++);
if ($event['cal_repeat'] != 1 && $event['cal_interval'] == 1 && $event['cal_interval_units'] == 'DAY' && ($cal_date == $act_date || $day == 1) ) $topicCache[$pos] = $event['topic_id'];
$topic_text = strlen($event['topic_title']) > $mycal_length_max ? substr($event['topic_title'], 0, $mycal_length_max) . '...' : $event['topic_title'];
$block_style = '';
$bullet = '';
}
if ($pos > $lastline) $lastline = $pos;
$style_forum_id = $event['forum_id'];
$style = 'style="height:14px;margin:1px 0px;padding-left:2px;' . $block_style;;
$fstyle = $forumstyle[$style_forum_id] ? $forumstyle[$style_forum_id] . ';' : '';
$style .= $fstyle . '"';
$ol_topic_id = $event['topic_id'];
if (!strpos($used_topics, $ol_topic_id . "#")) {
$used_topics .= $ol_topic_id . "#";
$caption = "<div class=\\\"ol_caption\\\">" . $event['topic_title'] . "</div>";
$repeat = ($event['cal_interval'] != 1 || $event['cal_interval_units'] != 'DAY') ? mycal_repeattext($event['cal_interval_units'], $event['cal_interval']) . '<br>' : '';
$tiptext = "<div style=\\\"white-space:nowrap;\\\"><b>" . $lang['Date'] . ": </b>" . mycal_format_span($event['cal_date'], $event['cal_date_end']) . "</div>";
$tiptext .= "<div>$repeat<b>" . $lang['Forum'] . ": </b>" . $event['forum_name'] . "</div>";
$tiptext .= "<div><b>" . $lang['Author'] . ": </b>" . $event['username'] . "</div>";
$tiptext = str_replace("'", "\\'", $tiptext);
$js_arraydata .= "\nol_caps[$ol_topic_id] = \"$caption\";\nol_texts[$ol_topic_id] = \"$tiptext\";";
}
$overlib = "onmouseover=\"return overlib(INARRAY, $ol_topic_id, CAPARRAY, $ol_topic_id, CSSCLASS, FGCLASS, 'ol_fg', BGCLASS, 'ol_bg', CAPTIONFONTCLASS, 'ol_caption', TEXTFONTCLASS, 'ol_text', STICKY, AUTOCLOSE, NOCLOSE, HAUTO, VAUTO, DELAY, 400);\" onmouseout=\"return nd();\"";
$eventStack[$pos]['event'] = "<div $style ><span class=\"gensmall\">$bullet</span><a href=\"$topic_url\" class=\"gensmall\" style=\"$fstyle\" $overlib >$topic_text</a></div>";
$event = $db->sql_fetchrow($result);
}
for ($pos = 1; $pos <= $lastline; $pos++) {
$entry = $eventStack[$pos] ? $eventStack[$pos]['event'] : '<br>';
$template->assign_block_vars('date_row.date_cell.switch_date_cells.date_event', array(
'U_EVENT' => $entry)
);
}
$eventStack = array();
$day++;
}
}
}
list($previousmonth, $previousyear) = explode('-', date('m-Y', mktime(0,0,0,$month - 1, 1, $year)));
list($nextmonth, $nextyear) = explode('-', date('m-Y', mktime(0,0,0,$month + 1, 1, $year)));
// prepare images and links for month navigation
$f_url = !empty($forum_id) ? "&f=$forum_id" : "";
$image_prev_month = "<img src=\"" . $images['icon_left_arrow'] . "\" align=\"middle\" border=\"0\" title=\"{$lang['View_previous_month']}\" alt=\"" . $lang['View_previous_month'] . "\" />";
$image_next_month = "<img src=\"" . $images['icon_right_arrow'] . "\" align=\"middle\" border=\"0\" title=\"{$lang['View_next_month']}\" alt=\"" . $lang['View_next_month'] . "\" />";
$url_prev_month = append_sid('mycalendar.' . $phpEx . "?month=$previousmonth&year=$previousyear$f_url");
$url_next_month = append_sid('mycalendar.' . $phpEx . "?month=$nextmonth&year=$nextyear$f_url");
$image_prev_year = "<img src=\"" . $images['icon_double_left_arrow'] . "\" align=\"middle\" border=\"0\" title=\"{$lang['View_previous_year']}\" alt=\"" . $lang['View_previous_year'] . "\" />";
$image_next_year = "<img src=\"" . $images['icon_double_right_arrow'] . "\" align=\"middle\" border=\"0\" title=\"{$lang['View_next_year']}\" alt=\"" . $lang['View_next_year'] . "\" />";
$url_prev_year = append_sid('mycalendar.' . $phpEx . '?month=' . $month . '&year=' . ($year - 1) . $f_url);
$url_next_year = append_sid('mycalendar.' . $phpEx . '?month=' . $month . '&year=' . ($year + 1) . $f_url);
if ($lang['Calendar_start_monday']) {
$template->assign_block_vars('switch_sunday_end', array());
} else {
$template->assign_block_vars('switch_sunday_beginning', array());
}
if (!empty($forums_to_read)) {
$select_forums_read = mycal_forum_dropdown('read', $forums_to_read, $forum_id);
$template->assign_block_vars('switch_forum_filter', array());
}
if (!empty($forums_to_post)) {
$select_forums_post = mycal_forum_dropdown('post', $forums_to_post, $forum_id);
$template->assign_block_vars('switch_add_event', array());
}
$template->assign_vars(array(
'JS_ARRAYDATA' => $js_arraydata,
'L_SUNDAY' => $lang['datetime']['Sunday'],
'L_MONDAY' => $lang['datetime']['Monday'],
'L_TUESDAY' => $lang['datetime']['Tuesday'],
'L_WEDNESDAY' => $lang['datetime']['Wednesday'],
'L_THURSDAY' => $lang['datetime']['Thursday'],
'L_FRIDAY' => $lang['datetime']['Friday'],
'L_SATURDAY' => $lang['datetime']['Saturday'],
'L_CURRENT_MONTH' => $monthName,
'L_CURRENT_YEAR' => $year,
'L_JUMPTO' => $lang['Jump_to'],
'L_SUBMIT' => $lang['Go'],
'L_SUBMIT_EVENT' => $lang['Submit_event'],
'L_SELECT_POST_FORUM' => $lang['Select_post_forum'],
'I_PREV_MONTH' => $image_prev_month,
'I_NEXT_MONTH' => $image_next_month,
'U_PREV_MONTH' => $url_prev_month,
'U_NEXT_MONTH' => $url_next_month,
'I_PREV_YEAR' => $image_prev_year,
'I_NEXT_YEAR' => $image_next_year,
'U_PREV_YEAR' => $url_prev_year,
'U_NEXT_YEAR' => $url_next_year,
'U_ADD_EVENT' => append_sid('posting.php'),
'I_ADD_EVENT' => $image_add_event,
'CAL_MONTH' => $month,
'CAL_YEAR' => $year,
'S_MONTH_SELECT' => mycal_month_dropdown($month),
'S_YEAR_SELECT' => mycal_make_dropdown($year - 2, $year + 5, $year),
'S_FORUM_SELECT' => $select_forums_read,
'S_FORUM_POST' => $select_forums_post,
'S_CAL_DATE' => $cal_date_submit,
));
$template->pparse('body');
include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
?>