⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 calendar.php

📁 泛微协同办公系统标准版E-office V5.5的源代码内含泛微办公系统V5.5自动注册文件。
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php

class calendar
{

	var $output = "";
	var $base_url = "";
	var $html = "";
	var $page_title = "";
	var $nav;
	var $chosen_month = "";
	var $chosen_year = "";
	var $now_date = "";
	var $our_datestamp = "";
	var $offset = "";
	var $start_date = "";
	var $first_day_array = "";
	var $month_words = array( );
	var $day_words = array( );

	function calendar( )
	{
		global $ibforums;
		global $DB;
		global $std;
		global $print;
		global $skin_universal;
		$ibforums->lang = $std->load_words( $ibforums->lang, "lang_calendar", $ibforums->lang_id );
		$ibforums->lang = $std->load_words( $ibforums->lang, "lang_post", $ibforums->lang_id );
		$this->html = $std->load_template( "skin_calendar" );
		$this->post_html = $std->load_template( "skin_post" );
		$this->offset = ( $ibforums->member['time_offset'] != "" ? $ibforums->member['time_offset'] : $ibforums->vars['time_offset'] ) * 3600;
		if ( $ibforums->vars['time_adjust'] != "" && $ibforums->vars['time_adjust'] != 0 )
		{
			$this->offset += $ibforums->vars['time_adjust'] * 60;
		}
		$this->now_date = getdate( time( ) + $this->offset );
		$this->chosen_month = intval( $ibforums->input['m'] ) == "" ? $this->now_date['mon'] : $ibforums->input['m'];
		$this->chosen_year = intval( $ibforums->input['y'] ) == "" ? $this->now_date['year'] : $ibforums->input['y'];
		if ( !checkdate( $this->chosen_month, 1, $this->chosen_year ) )
		{
			$this->chosen_month = $this->now_date['mon'];
			$this->chosen_year = $this->now_date['year'];
		}
		$this->our_datestamp = mktime( 0, 0, 0, $this->chosen_month, 1, $this->chosen_year );
		$this->first_day_array = getdate( $this->our_datestamp );
		$this->month_words = array(
			$ibforums->lang['M_1'],
			$ibforums->lang['M_2'],
			$ibforums->lang['M_3'],
			$ibforums->lang['M_4'],
			$ibforums->lang['M_5'],
			$ibforums->lang['M_6'],
			$ibforums->lang['M_7'],
			$ibforums->lang['M_8'],
			$ibforums->lang['M_9'],
			$ibforums->lang['M_10'],
			$ibforums->lang['M_11'],
			$ibforums->lang['M_12']
		);
		$this->day_words = array(
			$ibforums->lang['D_0'],
			$ibforums->lang['D_1'],
			$ibforums->lang['D_2'],
			$ibforums->lang['D_3'],
			$ibforums->lang['D_4'],
			$ibforums->lang['D_5'],
			$ibforums->lang['D_6']
		);
		switch ( $ibforums->input['code'] )
		{
		case "newevent" :
			$this->new_event( );
			break;
		case "showday" :
			$this->show_day( );
			break;
		case "showevent" :
			$this->show_event( );
			break;
		case "addnewevent" :
			$this->add_new_event( );
			break;
		case "birthdays" :
			$this->show_birthdays( );
			break;
		case "edit" :
			$this->edit( );
			break;
		case "doedit" :
			$this->do_edit( );
			break;
		default :
			$this->show_month( );
			break;
		}
		if ( $this->page_title == "" )
		{
			$this->page_title = $ibforums->vars['board_name']." ".$ibforums->lang['page_title'];
		}
		if ( !is_array( $this->nav ) )
		{
			$this->nav[] = "<a href='{$ibforums->base_url}&act=calendar'>{$ibforums->lang['page_title']}</a>";
		}
		$print->add_output( "{$this->output}" );
		$print->do_output( array(
			"TITLE" => $this->page_title,
			"JS" => 0,
			NAV => $this->nav
		) );
	}

	function edit( )
	{
		global $ibforums;
		global $DB;
		global $std;
		global $print;
		if ( $ibforums->member['g_calendar_post'] != 1 )
		{
			$std->error( array( "LEVEL" => 1, "MSG" => "no_permission" ) );
		}
		if ( !$ibforums->member['id'] )
		{
			$std->error( array( "LEVEL" => 1, "MSG" => "no_permission" ) );
		}
		$eventid = intval( $ibforums->input['eventid'] );
		if ( $eventid == "" )
		{
			$std->error( array( "LEVEL" => 1, "MSG" => "cal_no_events" ) );
		}
		$DB->query( "SELECT * FROM ibf_calendar_events WHERE eventid='{$eventid}'" );
		if ( !( $event = $DB->fetch_row( ) ) )
		{
			$std->error( array( "LEVEL" => 1, "MSG" => "cal_no_events" ) );
		}
		$can_edit = 0;
		if ( $ibforums->member['id'] == $event['userid'] )
		{
			$can_edit = 1;
		}
		else if ( $ibforums->member['g_is_supmod'] == 1 )
		{
			$can_edit = 1;
		}
		else
		{
			$can_edit = 0;
		}
		if ( $can_edit != 1 )
		{
			$std->error( array( "LEVEL" => 1, "MSG" => "cal_no_events" ) );
		}
		if ( $event['read_perms'] != "*" && !preg_match( "/(^|,)".$ibforums->member['mgroup']."(,|\$)/", $event['read_perms'] ) )
		{
			$std->error( array( "LEVEL" => 1, "MSG" => "cal_no_events" ) );
		}
		$ibforums->lang['the_max_length'] = $ibforums->vars['max_post_length'] ? $ibforums->vars['max_post_length'] * 1024 : 2140000;
		$this->nav[] = "<a href='{$ibforums->base_url}&act=calendar'>{$ibforums->lang['page_title']}</a>";
		$this->nav[] = $ibforums->lang['edit_event']." ".$event['title'];
		$this->output .= $this->post_html->calendar_start_edit_form( $event['eventid'] );
		$this->output .= $this->post_html->table_top( $ibforums->lang['edit_event'] );
		$this->output .= $this->post_html->calendar_delete_box( );
		$this->output .= $this->post_html->calendar_event_title( $event['title'] );
		$this->output .= $this->post_html->calendar_choose_date( $this->get_day_dropdown( $event['mday'] ), $this->get_month_dropdown( $event['month'] ), $this->get_year_dropdown( $event['year'] ) );
		$public = "";
		$private = "";
		if ( $event['priv_event'] == 1 )
		{
			$private = " selected";
		}
		else
		{
			$public = " selected";
		}
		$this->output .= $this->post_html->calendar_event_type( $public, $private );
		if ( $ibforums->member['mgroup'] == $ibforums->vars['admin_group'] )
		{
			$group_choices = "";
			$DB->query( "SELECT g_id, g_title FROM ibf_groups ORDER BY g_title" );
			while ( $r = $DB->fetch_row( ) )
			{
				$selected = "";
				if ( preg_match( "/(^|,)".$r['g_id']."(,|\$)/", $event['read_perms'] ) )
				{
					$selected = " selected";
				}
				$group_choices .= "<option value='".$r['g_id']."'".$selected.">".$r['g_title']."</option>\n";
			}
			$this->output .= $this->post_html->calendar_admin_group_box( $group_choices );
		}
		$this->output .= $this->post_html->postbox_buttons( str_replace( "<br>", "\n", $event['event_text'] ) );
		$this->output .= $this->post_html->calendar_end_form( $ibforums->lang['calendar_edit_submit'] );
		$show_table = 0;
		$count = 0;
		$smilies = "<tr align='center'>\n";
		$DB->query( "SELECT * FROM ibf_emoticons WHERE clickable='1'" );
		while ( $elmo = $DB->fetch_row( ) )
		{
			++$show_table;
			++$count;
			$smilies .= "<td><a href=\"javascript:emoticon('".$elmo['typed']."')\"><img src=\"".$ibforums->vars['EMOTICONS_URL']."/".$elmo['image']."\" alt='smilie' border='0'></a>&nbsp;</td>\n";
			if ( $count == $ibforums->vars['emo_per_row'] )
			{
				$smilies .= "</tr>\n\n<tr align='center'>";
				$count = 0;
			}
		}
		if ( $count != $ibforums->vars['emo_per_row'] )
		{
			$i = $count;
			for ( ;	$i < $ibforums->vars['emo_per_row'];	++$i	)
			{
				$smilies .= "<td>&nbsp;</td>\n";
			}
			$smilies .= "</tr>";
		}
		$table = $this->post_html->smilie_table( );
		if ( $show_table != 0 )
		{
			$table = preg_replace( "/<!--THE SMILIES-->/", $smilies, $table );
			$this->output = preg_replace( "/<!--SMILIE TABLE-->/", $table, $this->output );
		}
		$this->output = preg_replace( "/<!--IBF\\.SIG_CLICK-->.+?<!--IBF\\.END_SIG_CLICK-->/s", "", $this->output );
	}

	function do_edit( )
	{
		global $ibforums;
		global $DB;
		global $std;
		global $print;
		global $HTTP_POST_VARS;
		if ( $ibforums->member['g_calendar_post'] != 1 )
		{
			$std->error( array( "LEVEL" => 1, "MSG" => "no_permission" ) );
		}
		if ( !$ibforums->member['id'] )
		{
			$std->error( array( "LEVEL" => 1, "MSG" => "no_permission" ) );
		}
		$eventid = intval( $ibforums->input['eventid'] );
		if ( $eventid == "" )
		{
			$std->error( array( "LEVEL" => 1, "MSG" => "cal_no_events" ) );
		}
		$DB->query( "SELECT * FROM ibf_calendar_events WHERE eventid='{$eventid}'" );
		if ( !( $event = $DB->fetch_row( ) ) )
		{
			$std->error( array( "LEVEL" => 1, "MSG" => "cal_no_events" ) );
		}
		$can_edit = 0;
		if ( $ibforums->member['id'] == $event['userid'] )
		{
			$can_edit = 1;
		}
		else if ( $ibforums->member['g_is_supmod'] == 1 )
		{
			$can_edit = 1;
		}
		else
		{
			$can_edit = 0;
		}
		if ( $can_edit != 1 )
		{
			$std->error( array( "LEVEL" => 1, "MSG" => "cal_no_events" ) );
		}
		if ( $HTTP_POST_VARS['event_delete'] == 1 )
		{
			$DB->query( "DELETE FROM ibf_calendar_events WHERE eventid='{$eventid}'" );
			$print->redirect_screen( $ibforums->lang['delete_event_redirect'], "&act=calendar" );
		}
		else
		{
			$ibforums->vars['max_post_length'] = $ibforums->vars['max_post_length'] ? $ibforums->vars['max_post_length'] : 2140000;
			$allow_emoticons = $ibforums->input['enableemo'] == "yes" ? 1 : 0;
			$private_event = $ibforums->input['e_type'] == "private" ? 1 : 0;
			if ( strlen( trim( $HTTP_POST_VARS['Post'] ) ) < 1 )
			{
				$std->error( array( "LEVE" => 1, "MSG" => "no_post" ) );
			}
			if ( $ibforums->vars['max_post_length'] * 1024 < strlen( $HTTP_POST_VARS['Post'] ) )
			{
				$std->error( array( "LEVEL" => 1, "MSG" => "post_too_long" ) );
			}
			$ibforums->input['event_title'] = str_replace( "<br>", "", $ibforums->input['event_title'] );
			$ibforums->input['event_title'] = trim( stripslashes( $ibforums->input['event_title'] ) );
			if ( strlen( $ibforums->input['event_title'] ) < 2 || !$ibforums->input['event_title'] )
			{
				$std->error( array( "LEVEL" => 1, "MSG" => "cal_title_none" ) );
			}
			if ( 64 < strlen( $ibforums->input['event_title'] ) )
			{
				$std->error( array( "LEVEL" => 1, "MSG" => "cal_title_long" ) );
			}
			$read_perms = "*";
			if ( $ibforums->member['mgroup'] == $ibforums->vars['admin_group'] )
			{
				if ( is_array( $HTTP_POST_VARS['e_groups'] ) )
				{
					$read_perms = implode( ",", $HTTP_POST_VARS['e_groups'] );
					$read_perms .= ",".$ibforums->vars['admin_group'];
				}
				if ( $read_perms == "" )
				{
					$read_perms = "*";
				}
			}
			$day = intval( $ibforums->input['e_day'] );
			$month = intval( $ibforums->input['e_month'] );
			$year = intval( $ibforums->input['e_year'] );
			if ( !checkdate( $month, $day, $year ) )
			{
				$std->error( array( "LEVEL" => 1, "MSG" => "cal_date_oor" ) );
			}
			$db_string = $DB->compile_db_update_string( array(
				"year" => $year,
				"month" => $month,
				"mday" => $day,
				"title" => $ibforums->input['event_title'],
				"event_text" => $ibforums->input['Post'],
				"read_perms" => $read_perms,
				"priv_event" => $private_event,
				"unix_stamp" => mktime( 23, 59, 59, $month, $day, $year ),
				"show_emoticons" => $allow_emoticons
			) );
			$DB->query( "UPDATE ibf_calendar_events SET {$db_string} WHERE eventid='{$eventid}'" );
			$print->redirect_screen( $ibforums->lang['edit_event_redirect'], "&act=calendar&code=showevent&eventid={$eventid}" );
		}
	}

	function show_month( )
	{
		global $ibforums;
		global $DB;
		global $std;
		global $print;
		$birthdays = array( );
		$DB->query( "SELECT bday_day from ibf_members WHERE bday_month='".$this->chosen_month."'" );
		while ( $user = $DB->fetch_row( ) )
		{
			++$birthdays[$user['bday_day']];
		}
		$events = array( );
		$DB->query( "SELECT eventid, title, userid, priv_event, read_perms, mday from ibf_calendar_events WHERE month='".$this->chosen_month."' AND year='".$this->chosen_year."'" );
		while ( $event = $DB->fetch_row( ) )
		{
			if ( $event['priv_event'] == 1 && $ibforums->member['id'] != $event['userid'] )
			{
				continue;
			}
			if ( $event['read_perms'] != "*" && !preg_match( "/(^|,)".$ibforums->member['mgroup']."(,|\$)/", $event['read_perms'] ) )
			{
				continue;
			}
			$events[$event['mday']][] = $event;
		}
		$prev_month = array( );
		$next_month = array( );
		$prev_month['year_id'] = $this->chosen_year;
		$next_month['year_id'] = $this->chosen_year;
		$prev_month['month_id'] = $this->chosen_month - 1;
		$prev_month['month_name'] = $this->month_words[$this->chosen_month - 2];
		$next_month['month_name'] = $this->month_words[$this->chosen_month];
		$next_month['month_id'] = $this->chosen_month + 1;
		if ( $this->chosen_month == 1 )
		{
			$prev_month['month_name'] = $this->month_words[11];
			$prev_month['month_id'] = 12;
			$prev_month['year_id'] = $this->chosen_year - 1;
		}
		else if ( $this->chosen_month == 12 )
		{
			$next_month['month_name'] = $this->month_words[0];
			$next_month['month_id'] = 1;
			$next_month['year_id'] = $this->chosen_year + 1;
		}
		$this->output .= $this->html->cal_main_content( $this->month_words[$this->chosen_month - 1], $this->chosen_year, $prev_month, $next_month );
		$day_output = "";
		$cal_output = "";
		foreach ( $this->day_words as $day )
		{
			$day_output .= $this->html->cal_day_bit( $day );
		}
		$seen_days = array( );
		$c = 0;
		for ( ;	$c < 42;	++$c	)
		{
			$day_array = getdate( $this->our_datestamp );
			if ( $c % 7 == 0 )
			{
				if ( $day_array['mon'] != $this->chosen_month )
				{
					break;
				}
				else
				{
					$cal_output .= $this->html->cal_new_row( );
				}
			}
			if ( $c < $this->first_day_array['wday'] || $day_array['mon'] != $this->chosen_month )
			{
				$cal_output .= $this->html->cal_blank_cell( );
			}
			else
			{
				$this->our_datestamp += 86400;
				if ( $seen_days[$day_array['yday']] == 1 )
				{
					--$c;
				}
				else
				{
					$seen_days[$day_array['yday']] = 1;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -