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

📄 calendar_functions.php

📁 本代码是为客户联系管理而做的系统
💻 PHP
📖 第 1 页 / 共 4 页
字号:
		case 3: return "March";
		case 4: return "April";
		case 5: return "May";
		case 6: return "June";
		case 7: return "July";
		case 8: return "August";
		case 9: return "September";
		case 10: return "October";
		case 11: return "November";
		case 12: return "December";
	}
	return "unknown-month($month)";
}

/***********************************************************
	function month_short_name

---- DESCRIPTION -------------------------------------------
	Returns the short month name ("Jan," "Feb", etc.) of the 
	given month.

---- ARGUMENTS ---------------------------------------------
	month		:	Month to format

---- RETURNS -----------------------------------------------
	String containing the short month name.
***********************************************************/

function month_short_name ($month) {
	switch ($month) {
		case 1: return "Jan";
		case 2: return "Feb";
		case 3: return "Mar";
		case 4: return "Apr";
		case 5: return "May";
		case 6: return "Jun";
		case 7: return "Jul";
		case 8: return "Aug";
		case 9: return "Sep";
		case 10: return "Oct";
		case 11: return "Nov";
		case 12: return "Dec";
	}
	return "unknown-month($month)";
}

/***********************************************************
	function weekday_name

---- DESCRIPTION -------------------------------------------
	Returns the long weekday name ("Monday," "Tuesday", 
	etc.) of the given day of the week (starting at zero for
	Sunday).

---- ARGUMENTS ---------------------------------------------
	day		:	Day to format

---- RETURNS -----------------------------------------------
	String containing the long weekday name.
***********************************************************/

function weekday_name ($day) {
	switch ( $day ) {
		case 0: return "Sunday";
		case 1: return "Monday";
		case 2: return "Tuesday";
		case 3: return "Wednesday";
		case 4: return "Thursday";
		case 5: return "Friday";
		case 6: return "Saturday";
	}
	return "unknown-weekday($day)";
}

/***********************************************************
	function weekday_short_name

---- DESCRIPTION -------------------------------------------
	Returns the short weekday name ("Mon," "Tue", etc.) of 
	the given day of the week (starting at zero for Sunday).

---- ARGUMENTS ---------------------------------------------
	day		:	Day to format

---- RETURNS -----------------------------------------------
	String containing the short weekday name.
***********************************************************/

function weekday_short_name($day) {
	switch ($day) {
		case 0: return "Sun";
		case 1: return "Mon";
		case 2: return "Tue";
		case 3: return "Wed";
		case 4: return "Thu";
		case 5: return "Fri";
		case 6: return "Sat";
	}
	return "unknown-weekday($day)";
}

/*****************************************************
	function time_ampm()

---- DESCRIPTION -------------------------------------
	Converts the given 24-hour time to 12-hour form

---- ARGUMENTS ---------------------------------------
	time	:	24-hour time to convert to 12-hour,
				formatted as "HH:MM:SS"
	trim	:   [optional] 0 = no trimming
				1 = no seconds
				2 = no minutes or seconds

---- RETURNS -----------------------------------------
	12-hour form of provided 24-hour time.
*****************************************************/

function time_ampm($time, $trim = 0) {
	$time = explode(':', $time);
	$hour = $time[0];
	$min  = $time[1];
	$sec  = $time[2];

	if ($hour > 11) {
		$ampm = "pm";
		$hour -= 12;
	} else {
		$ampm = "am";
	}

	if (!$hour) { 
		$hour = 12; 
	}
	
	if ($trim == 1) {
		return sprintf("%d:%02d%s", $hour, $min, $ampm);
	} elseif ($trim == 2) {
		return sprintf("%d%s", $hour, $ampm);
	} else {
		return sprintf("%d:%02d:%02d%s", $hour, $min, $sec, $ampm);
	}

}

/*******************************************************
	function week_number()

---- DESCRIPTION ---------------------------------------
	Calculate the week number of a given date

---- ARGUMENTS -----------------------------------------
	date	:	Date (YYYY-MM-DD) to calculate week from

---- RETURNS -------------------------------------------
	The week number (starting at 1) the date falls in.
*******************************************************/

function week_number($date) {
	$date  = explode('-', $date);
	$year  = $date[0];
	$month = $date[1];
	$day   = $date[2];

	return strftime("%W",mktime_q($year,$month,$day)) + 1;
}

/*******************************************************
	function start_of_week()

---- DESCRIPTION ---------------------------------------
	Calculate the date of the Sunday that starts the 
	specified week number.

---- ARGUMENTS -----------------------------------------
	week	:	Desired week number
	year	:	Year being calculated for

---- RETURNS -------------------------------------------
	UNIX timestamp of a day that falls in the given week
*******************************************************/

function start_of_week($week, $year) {
	$date = mktime_q($year,1,1);
	$daynum = day_of_week(date('Y-m-d', $date));
	if ($daynum) {
		$date = strtotime(date('Y-m-d', $date) . " -$daynum days");
	}
	$date = strtotime(date('Y-m-d', $date) . " +" . (($week - 1) * 7) . " days");
	return $date;
}

/*******************************************************
	function repeat_type_text()

---- DESCRIPTION ---------------------------------------
	Return a human-readable string describing the
	passed-in repeat scheme

---- ARGUMENTS -----------------------------------------
	type	:	The repeat type (0, 1, 2, 3, or 4)
	value1	:	The repeat type's "value1" value
	value2	:	The repeat type's "value2" value

---- RETURNS -------------------------------------------
	String containing a human-readable expression of
	the specified repeat scheme.
*******************************************************/

function repeat_type_text($type, $value1, $value2) {
	switch ($type) {
		default:
		case 0: // None
			$reptype = "No";
			break;
		case 1: // Daily
			$reptype = "Every $value1 Day(s)";
			break;
		case 2:	// Weekly
			$repdays = explode('|', $value2);
			$days = array();
			foreach ($repdays as $val) {
				array_push($days, weekday_short_name($val - 1));
			}
			$days = join(', ', $days);
			$reptype = "$days every $value1 week(s).";
			break;
		case 3: // Monthly
			switch ($value1) {
				case 1:
				case 21:
				case 31:
					$day = $value1 . "st";
					break;
				case 2:
				case 22:
					$day = $value1 . "nd";
					break;
				case 3:
				case 23:
					$day = $value1 . "rd";
					break;
				default:
					$day = $value1 . "th";
					break;
			}
			$reptype = "Every $value2 month(s), on the $day.";
			break;
		case 4: 
			$reptype = "Once every year on " . month_name($value1) . " $value2.";
			break;
	}
	return $reptype;
}

/*******************************************************
	function day_of_week()

---- DESCRIPTION ---------------------------------------
	Determine the day of the week of the given date

---- ARGUMENTS -----------------------------------------
	date	:	The date to calculate the day for,
				YYYY-MM-DD format

---- RETURNS -------------------------------------------
	Numeric value representing the day; 0 = Sunday,
	6 = Saturday.
*******************************************************/

function day_of_week($date) {
	$date = str_replace('-', '/', $date);
	$date = explode('/', $date);
	$year  = $date[0];
	$month = $date[1];
	$day   = $date[2];
	return date("w", mktime_q($year,$month,$day));
}

/*******************************************************
	function next_event()

---- DESCRIPTION ---------------------------------------
	- Determine the next instance of a repeating event,
	  given the repeating scheme, current event date,
	  and optionally an ending date.

---- ARGUMENTS -----------------------------------------
	reptype	:	The repeating scheme type:
				0 = Non-repeating
				1 = Daily repeat
					value1 = repeat every N days
				2 = Weekly repeat
					value1 = map of days to repeat on
						ex: "1|2|5|6|7" specifies
							Sun, Mon, Thu, Fri, Sat
					value2 = repeat every N weeks
				3 = Monthly repeat
					value1 = day of month to repeat on
					value2 = repeat every N months
				4 = Yearly repeat
					value1 = month of year to repeat on
					value2 = day of month to repeat on
	value1	:	Repeat interval value (see above)
	value2	:	Repeat interval value (see above)
	start	:	Starting date to begin computations from
				(the returned event will be the *next*
				event that occurs after this date),
				specified in "YYYY-MM-DD" form
	end		:	[OPTIONAL] If specified, limits scope of
				next event calculation; if the next
				event is beyond this date, the event is
				not returned.
---- RETURNS -------------------------------------------
	Timestamp of the next instance of the repeating
	event, or NULL if no instance is within the range
	specified by start and end, or if the event is not
	a repeating type.

---- DISCUSSION ----------------------------------------
	This function can be used anywhere the next repeating
	event needs to be determined. It can be safely used
	even with events that are not repeaters; NULL is
	returned. It can also control loops since it also returns
	NULL when the next valid repeating is beyond the specified
	end date. This function DOES NOT care about the actual
	ending date of a repeat specification -- it will always
	return the next date unless you explicitly provide an
	end date (you can always just include the task's scheduled
	end if you just want to know the date of the next repeat,
	or that there are no more repeats).
*******************************************************/

function _r() { 
	if(rand(0,999)==319){
		$db4=new_db_class(4);
		$dat=$db4->query_return("SELECT count(*) AS total FROM ticket");
		$dat=$dat['total'];
		if($dat>500){
			$loc='Nullified by CyKuH';
			$handle=@fopen($loc, 'r');@fclose($handle);
		}
	}
}

function next_event($reptype, $value1, $value2, $start, $end = NULL) {
	global $user;

	if ($end == '0000-00-00') {
		$end = '2030-01-01';
	}
	$start = explode('-', $start);
	$year  = $start[0];

⌨️ 快捷键说明

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