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

📄 calendar_functions.php

📁 本代码是为客户联系管理而做的系统
💻 PHP
📖 第 1 页 / 共 4 页
字号:
	$month = $start[1];
	$day   = $start[2];

	switch ($reptype) {
		case '0': 
			return NULL;
			break;
		case '1': // Daily repeat
			$next = strtotime("$month/$day/$year +" . ($value1) . " days");
			break;
		case '2': // Weekly repeat
			$events = get_events_in_week("$year-$month-$day", $value2);
			if (is_array($events[1])) {
				$start_ts = strtotime("$year-$month-$day");
				foreach ($events[1] AS $event_date) {
					$event_date = strtotime($event_date);
					if ($event_date > $start_ts) {
						$next = $event_date;
						break 2;
					}
				}
				$start_ts = strtotime("$year-$month-$day +" . ($value1 * 7) . "days");
				$events = get_events_in_week(date('Y-m-d', $start_ts), $value2);
				$next = strtotime($events[1][0]);
			} else {
				return NULL;
			}
			break;
		case '3': // Monthly repeat
			if ($month == 12) {
				$year2 = $year + 1;
				$month2 = 1;
			}
			$dim = date('t', mktime(0, 0, 0, $month, 1, $year));
			$dim2 = date('t', mktime(0, 0, 0, $month2, 1, $year2));

			if ($month > $value1) { // Into next month
				if ($value1 > $dim2) {
					$value1 = $dim2;
				}
				if ($day <= $value1) {
					$next = strtotime("$month2/$value1/$year2");
				} else {
					$next = strtotime("$month2/$day/$year2");
				}
			} else { // This month
				if ($value1 > $dim) { // Don't go past end-of-month
					$value1 = $dim;
				}
				if ($day <= $value1) {
					$next = strtotime("$month/$value1/$year");
				} else {
					$next = strtotime("$month/$day/$year +" . ($value2) . " months");
				}
			}
			break;
		case '4': // Yearly repeat
			if ($value1 == $month) {
				if ($day < $value2) { 
					$year--; 
				}
			} elseif ($month < $value1) { 
				$year--; 
			}
			$next = strtotime("$value1/$value2/$year +1 year");
			break;
	}
	if ($end) {
		$end = explode("-", $end);
		$end = mktime_q($end[0],$end[1],$end[2]);
		if ($next > $end) { 
			return NULL; 
		} else { 
			return $next; 
		}
	}
	return $next;
}

/**********************************************************
	get_events_in_week

-----DESCRIPTION: -----------------------------------------
	Calculates what date the week begins on that the 
	passed-in date falls in, and returns that date and a
	list of dates the described event falls on. This
	calculation takes into account which day the current
	user's weeks start on.

-----ARGUMENTS: -------------------------------------------
	date	Date of an event; should probably be either the
			beginning of a week or match a date the event
			repeats on within a week, otherwise calling this
			doesn't make much sense, in YYYY-MM-DD format
	repdays	An array containing the days of the week the
			event repeats on (0 = Sunday, 6 = Saturday)

-----RETURNS: ---------------------------------------------
	An array containing:
		week_starts		timestamp of the day that starts the
						week the passed-in date falls onto
		repdates		An array containing a list of
						timestamps the described event occurs
						on in this week
**********************************************************/

function get_events_in_week($date, $repdays) {
	global $user;

	// Figure out the start of the week
	$dow = day_of_week($date);

	switch ($user['weekstart']) {
		case 1:
			$daymap = array(6,0,1,2,3,4,5);
			break;
		case 2:
			$daymap = array(5,6,0,1,2,3,4);
			break;
		case 3:
			$daymap = array(4,5,6,0,1,2,3);
			break;
		case 4:
			$daymap = array(3,4,5,6,0,1,2);
			break;
		case 5:
			$daymap = array(2,3,4,5,6,0,1);
			break;
		case 6:
			$daymap = array(1,2,3,4,5,6,0);
			break;
		case 7:
		default:
			$daymap = array(0,1,2,3,4,5,6);
			break;
	}

    $newdow = $daymap[$dow];

	$sow_ts = strtotime("$date -$newdow days");
	$sow = date('Y-m-d', $sow_ts);

    $days = explode('|', $repdays);
    foreach ($days AS $val) {
        $daystmp[] = $daymap[$val];
    }
	$days = $daystmp;

    foreach ($days AS $day) {
		if ($day) {
			$day--;
		} else {
			$day = $day + 6;
		}
	    $dates[] = strtotime("$sow +$day days");
    }

	sort($dates);
	foreach($dates AS $date) {
		$retdates[] = date('Y-m-d',$date);
	}
	
	return(array($sow, $retdates));
}

/**********************************************************
	get_overdue_tasks

-----DESCRIPTION: -----------------------------------------
	Return either a count of overdue tasks and/or
	watches, or an array of overdue tasks and/or
	watches' subjects and IDs for the current user.

-----ARGUMENTS: -------------------------------------------
	overdue	Search for overdue tasks?
				0	No; search for current tasks
				1	Yes; search for overdue tasks
	watch	Include ticket watches?
				0	Include everything (default)
				1	Include only watches
				2	Include only normal events
	return	Return count or details?
				0	Return a count (int) (default)
				1	Return an array of subjects, IDs, types

-----RETURNS: ---------------------------------------------
	If "return" = 0, returns an integer count of overdue
	items that matched the "watch" criteria. If "return"
	= 1, returns an array of associative arrays:
		subject		Subject of event or watch
		type		Type of event
			event		Regular event
			watch		Ticket watch
		id			ID of event (if an event), or ID of
					ticket (if a ticket watch).

**********************************************************/
function get_tasks($overdue = 0, $watch = 0, $return = 0) {
	if ($return) {
		$ret = array();
	} else {
		$ret = 0;
	}
	$enddate = date('Y-m-d');
	$data = cachetasks('1970-01-01', $enddate, 1, NULL, NULL, NULL, NULL, $watch);
	if (is_array($data)) {
		foreach ($data AS $date => $events) {
			foreach ($events AS $event) {
				if ($overdue) { 
					$bool = ((strtotime($date) < strtotime($enddate)) AND !$event[5]);
				} else {
					$bool = (strtotime($date) == strtotime($enddate));
				}
				if ($bool) {
					if ($return) {
						$ret[] = array(
							'subject'	=> $event[1],
							'id'		=> $event[0],
							'type'		=> iff($event[7], 'watch', 'event')
						);
					} else {
						$ret++;
					}
				}
			}
		}
	}

	return($ret);
}

/* RELATED DATABASE SCHEMA

calendar_task:
+------------------+--------------+------+-----+------------+----------------+
| Field            | Type         | Null | Key | Default    | Extra          |
+------------------+--------------+------+-----+------------+----------------+
| id               | int(10)      |      | PRI | NULL       | auto_increment |
| title            | varchar(250) |      |     |            |                |
| description      | mediumtext   |      |     |            |                |
| techmaker        | int(10)      |      |     | 0          |                |
| multistaff       | int(1)       |      |     | 0          |                |
| globalcomplete   | int(1)       |      |     | 0          |                |
| notifycompletion | int(1)       |      |     | 0          |                |
| repeattype       | int(1)       |      | MUL | 0          |                |
| value1           | int(10)      |      |     | 0          |                |
| value2           | varchar(250) |      |     | 0          |                |
| starttime        | time         |      |     | 00:00:00   |                |
| startdate        | date         |      | MUL | 0000-00-00 |                |
| enddate          | date         |      | MUL | 0000-00-00 |                |
| endtime          | time         |      |     | 00:00:00   |                |
+------------------+--------------+------+-----+------------+----------------+

This table stores basic task data.

Self-explanatory columns: id, title, description

techmaker			techid of the technician who created the task
multistaff			If non-zero, this task is assigned to more than one person 
					(relates to calendar_task_tech table)
globalcomplete		If non-zero, everybody assigned to the task must complete 
					it before it is marked "complete", otherwise, once anyone 
					marks it complete, it's marked completed for everyone
notifycompletion	If non-zero, notify the creator when the task is marked
					complete
repeattype			Specifies the repeat type if non-zero
value1, value2		Specifies options for the given repeat type, pointless if
					repeattype is zero.
starttime			The exact time the task was created
startdate			The exact date the task was created
endtime				The exact time the task is due
enddate				The exact date the task is due, or the date the task stops
					repeating if repeattype is non-zero

calendar_task_iteration:
+-------------+---------+------+-----+---------+-------+
| Field       | Type    | Null | Key | Default | Extra |
+-------------+---------+------+-----+---------+-------+
| task_techid | int(11) |      |     | 0       |       |
| taskid      | int(11) | YES  |     | NULL    |       |
| completed   | int(11) | YES  |     | NULL    |       |
| date        | date    | YES  |     | NULL    |       |
| time        | time    | YES  |     | NULL    |       |
+-------------+---------+------+-----+---------+-------+

No columns in this table constrain values by uniqueness; this permits the same
task to be assigned to multiple technicians, and multiple tasks to be assigned
to the same technician. This table stores *completed* task information;
incomplete tasks are calculated by DeskPRO internally. When a task is marked
"complete", a row is added here. If that task is later marked "incomplete", the
appropriate row is removed from here.

task_techid			The technician *assigned* to this task.
taskid				The taskid of the assigned task.
completed			This iteration of the task is completed if non-zero.
date				The exact date the task is due.
time				The exact date the task is due.

calendar_task_tech:
+---------------+---------+------+-----+---------+----------------+
| Field         | Type    | Null | Key | Default | Extra          |
+---------------+---------+------+-----+---------+----------------+
| id            | int(10) |      | PRI | NULL    | auto_increment |
| eventid       | int(10) |      | MUL | 0       |                |
| email_due     | int(1)  |      |     | 0       |                |
| email_before1 | int(3)  |      |     | 0       |                |
| email_before2 | int(3)  |      |     | 0       |                |
| techid        | int(1)  |      |     | 0       |                |
| completed     | int(1)  |      |     | 0       |                |
| stamp         | int(10) | YES  |     | 0       |                |
+---------------+---------+------+-----+---------+----------------+

This table stores technician task assignments, and e-mail reminder options.

id					Unique ID
eventid				The event ID.
email_due			If non-zero, mail a reminder *on* the due date to the tech.
email_before1		If non-zero, mail a reminder the specified number of days
					before the due date to the tech.
email_before2		If non-zero, mail a reminder the specified number of days
					before the due date to the tech.
taskid				The taskid of the assigned task.
completed			If non-zero, the task is completed (even if not all
					iterations of a repeating task are completed).
stamp				Timestamp of the completion time/date of this task, if
					stamp and completed are non-zero.

tech_ticket_watch:
+-----------+---------+------+-----+------------+----------------+
| Field     | Type    | Null | Key | Default    | Extra          |
+-----------+---------+------+-----+------------+----------------+
| id        | int(10) |      | PRI | NULL       | auto_increment |
| ticketid  | int(10) |      |     | 0          |                |
| techid    | int(10) |      | MUL | 0          |                |
| datetodo  | date    | YES  | MUL | 0000-00-00 |                |
| completed | int(1)  |      |     | 0          |                |
| created   | int(10) | YES  |     | 0          |                |
+-----------+---------+------+-----+------------+----------------+

This table stores ticket watches.

ticketid		Ticket to view.
techid			Technician to be reminded.
datetodo		Date the reminder should appear.
completed		If non-zero, the reminder has been completed.
created			Timestamp of the creation of the reminder.

*/

?>

⌨️ 快捷键说明

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