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

📄 reminder.php

📁 Internet Task Management System可以让用户分配和管理一个组织内的任务。ITMS可以发送任务管理通知
💻 PHP
字号:
<?php/* * ITMS ValleyData source file version 1.0 May 11, 2001 * * This file is run by lynx daily * For every ITMS user this file must: * send an email reminder to this person about tasks which are overdue * or tasks which are due before the next reminder this person has set in * his/her preferences if he/she is supposed to get a reminder today. * * * * Internet Task Management System: An online system used for recording information about and assigning tasks and processes. * Copyright (C) 2001  ValleyData Programming Group * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA * * See file named "gpl.txt" included with source code or * visit http://www.gnu.org/copyleft/gpl.txt on the internet. */include("config.php");include("error_handler.php");include("db_tools.php");include("toolbox.php");if(isset($save)) //to delete tasks for those html emailers{    db_open();    db_use();    $query = "SELECT PT.date_assigned, PT.period, PT.period_unit, PT.due_date, ".			 "PT.tid, PT.title, PT.notify, PT.info, ".		     "U1.name AS assigner, U2.name AS assignedTo, U1.email, U1.html FROM pending_tasks PT, ".		     "users U1, users U2 WHERE PT.user_id = '$user_id' AND PT.assigner = U1.user_id AND PT.user_id = U2.user_id";    $result = db_query($query); // Get all details of user's pending tasks 	$assignedTo_email = get_user_email($user_id);    while($row = db_fetch_row($result))    {        $tid = $row["TID"];        $cbdone = "done$tid";        if(isset($$cbdone))        {            if($row["NOTIFY"] == 1)            {                //send notification				if(isset($row["EMAIL"]))				{					notifyComplete(							$row["TITLE"], 							$row["EMAIL"], 							$row["ASSIGNEDTO"],							$assignedTo_email,							$row["INFO"],                            $row["DUE_DATE"],						    get_priority_string($row["PRIORITY"]),							$row["HTML"]);				}            }			if($row["PERIOD"] != "0" && $row["PERIOD"] != "") // If this is a periodic task...			{				$due_date = $row["DUE_DATE"];//sample: 2001-03-11 18:59:56 				$due_year = substr($due_date, 0, 4);				$due_month = substr($due_date, 5, 2);				$due_day = substr($due_date, 8, 2);				$due_hour = substr($due_date, 11, 2);				$due_min = substr($due_date, 14, 2);				$assigned_day = substr($row["DATE_ASSIGNED"], 8, 2);								switch($row["PERIOD_UNIT"])				{					case "0"://days						$due_day += $row["PERIOD"];						break;					case "1"://weeks						$due_day += ($row["PERIOD"] * 7);						break;					case "2"://months						$month_num = $due_month + $row["PERIOD"];						$days_to_add = get_days_in_month(mktime($due_hour, $due_min, 0, $due_month, $due_day, $due_year));						/*						$next_month_days = get_days_in_month(mktime($due_hour, $due_min, 0, $due_month + 1, 1, $due_year));						if($days_to_add > $next_month_days)							$days_to_add = $next_month_days;						*/						($assigned_day > $due_day) ? $max_day = $assigned_day : $max_day = $due_day;						for($i = $due_month+1; $i <= $month_num; $i++)						{							$curr_day = date('d', mktime($due_hour, $due_min, 0, $month_num-1, $days_to_add, $due_year));							$next_month_days = get_days_in_month(mktime($due_hour, $due_min, 0, $i, 1, $due_year));							if($max_day > $curr_day)							{								$curr_day = $max_day;							}							if($curr_day > $next_month_days)							{								$curr_day = $next_month_days;							}							$days_to_add += $curr_day;						}						$due_day = $days_to_add;						break;				}				$new_due = mktime($due_hour, $due_min, 0, $due_month, $due_day, $due_year);				$new_due = date('Y-m-d H:i:s', $new_due);				$query = "UPDATE pending_tasks SET date_assigned = '$due_date', due_date='$new_due'  WHERE tid = '$tid'"; // Sets the new due date			}			else			{				$query = "DELETE FROM pending_tasks WHERE tid = '$tid'";            }            db_open();            db_use();            $task_name = get_pending_task_name($tid);			if(db_query($query)) // Update or delete pending task            {                message_box("$task_name completed.");            }        }// end if(isset($$cbdone))    }// end while($row = db_fetch_row($result))    print("<form method=\"post\">\n");    print("<input type=\"button\" value=\"Close\" onclick=\"parent.window.close()\"></form>\n");}else if($key != $EXECUTE_KEY) // This is an aribtrary number defined in config.php that matches reminder.cron{    die("Bad key supplied for reminder.php");}else // If the key is correct{    $time = time();    //first: get the date and time    $date_array = getdate($time);    $weekday = $date_array["WEEKDAY"];    $wday = $date_array["WDAY"];    $date_string = date('Y-m-d H:i:s');    //second: get a list of all the users    $all_users_array = get_all_users();    //foreach user:    foreach($all_users_array as $user)    {        $user_num = $user["USER_ID"];        $reads_html = $user["HTML"];        // check to see if this user is supposed to get reminders today        if(is_reminder_day($wday, $user_num))        {            // get his/her next reminder day            $days_until_next_reminder = get_days_until_next_reminder($wday, $user_num);            //construct a date based on the next_reminder_day            $newtime_stamp = add_days($days_until_next_reminder, $time);            $next_reminder_date = date('Y-m-d H:i:s', $newtime_stamp);            // get all overdue tasks            db_open();            db_use();            $query_tasks = "SELECT * FROM pending_tasks WHERE user_id = '$user_num' AND due_date < '$date_string' ORDER BY due_date";            $result = db_query($query_tasks);            while($row = db_fetch_row($result))            {                $overdue = "true";                $OTS = "Overdue Tasks:\n" .                    "<form name=\"save\" METHOD=\"POST\" ACTION=\"" . $ITMS_ROOT . "reminder.php\">" .                    "<table border=\"1\">\n<tr><td>Task Name</td>\n<td>Due Date</td>\n<td>Assigned " .                    "By</td>\n<td>Description</td>\n<td>Priority</td>\n<td>Task Done?</td></tr>\n";                $title = $row["TITLE"];                $due_date = convert_date($row["DUE_DATE"]);                $assigner = $row["ASSIGNER"];                $assigner = get_user_name($assigner);                $info = nl2br($row["INFO"]);                $priority = get_priority_string($row["PRIORITY"]);                                $overdue_html .= "<tr><td>$title</td>\n<td>$due_date</td>\n".                    "<td>$assigner</td>\n<td>$info</td>\n<td>$priority</td>\n".                    "<td><INPUT TYPE=\"checkbox\" NAME=\"done" . $row["TID"] . "\">Task Done</td></tr>\n";                $OTE = "<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>" .                       "<td><INPUT TYPE=\"hidden\" name=\"save\" value=\"save\">".                       "<INPUT TYPE=\"hidden\" name=\"user_id\" value=\"$user_num\">".                       "<INPUT TYPE=\"submit\" value=\"Complete Selected Tasks\" name=\"save\">".                       "</td></tr></table></form>\n";                $overdue_text .= "$title, assigned by: $assigner is due: $due_date, with priority: $priority, $info.\n";            }            // get all tasks due before the next reminder day                        db_open();            db_use();            $query_tasks = "SELECT * FROM pending_tasks WHERE user_id = '$user_num'" .                            "AND due_date BETWEEN '$date_string' AND '$next_reminder_date' ORDER BY due_date";            $result = db_query($query_tasks);            while($row = db_fetch_row($result))            {                $remind = "true";                $RTS = "Tasks Due before next Reminder:\n" .                    "<form name=\"save\" METHOD=\"POST\" ACTION=\"" . $ITMS_ROOT . "reminder.php\">" .                    "<table border=\"1\">\n<tr>\n<td>Task Name</td>\n<td>Due Date</td>\n<td>Assigned " . "By</td>\n<td>Description</td>\n<td>Priority</td>\n<td>Task Done?</td>\n</tr>\n";                $title = $row["TITLE"];                $due_date = convert_date($row["DUE_DATE"]);                $assigner = $row["ASSIGNER"];                $assigner = get_user_name($assigner);                $info = nl2br($row["INFO"]);                $priority = get_priority_string($row["PRIORITY"]);                $reminder_html .= "<tr>\n<td>$title</td>\n<td>$due_date</td>\n" .                    "<td>$assigner</td>\n<td>$info</td>\n<td>$priority</td>\n".                    "<td><INPUT TYPE=\"checkbox\" NAME=\"done" . $row["TID"] . "\">Task Done</td></tr>\n";                $RTE = "<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>" .                       "<td><INPUT TYPE=\"hidden\" name=\"save\" value=\"save\">".                       "<INPUT TYPE=\"hidden\" name=\"user_id\" value=\"$user_num\">".                       "<INPUT TYPE=\"submit\" value=\"Complete Selected Tasks\" name=\"save\">".                       "</td></tr></table></form>\n";                $reminder_text .= "$title, assigned by: $assigner is due: $due_date, with priority: $priority, $info.\n";            }                        $html = "<html>\n<body>\n$OTS $overdue_html $OTE $RTS $reminder_html $RTE\n</body>\n<html>";                        if(isset($overdue) || isset($remind))            {                $to = get_user_email($user_num);                $subject = "ITMS Task Reminder";                $headers = "Content-Type: text/html;";                // send an email reminder to this person if there are overdue or reminder-needing tasks                if($reads_html == "1")                {                    $body = $html;                    mail(stripslashes($to), stripslashes($subject), stripslashes($body), stripslashes($headers));                }                else                {                    if(isset($overdue))                        $text = "Overdue Tasks:\n$overdue_text\n";                    if(isset($remind))                        $text .= "Tasks Due before next Reminder:\n$reminder_text";                    $body = $text;                    mail(stripslashes($to), stripslashes($subject), stripslashes($body), stripslashes($headers));                }            }        }//end if(reminder day)        unset($overdue);        unset($remind);        unset($overdue_html);        unset($reminder_html);        unset($overdue_text);        unset($reminder_text);    }//end foreach user}//end else// Returns true if the specified day is one of the user's preferred reminder days.function is_reminder_day($wday, $user_num){    $ret = false;    $pref_array = array();    db_open();    db_use();    $query_prefs = "SELECT * FROM users WHERE user_id = '$user_num'";    $result = db_query($query_prefs);    $row = db_fetch_row($result);    array_push($pref_array, $row["REMINDS"]);    array_push($pref_array, $row["REMINDM"]);    array_push($pref_array, $row["REMINDT"]);    array_push($pref_array, $row["REMINDW"]);    array_push($pref_array, $row["REMINDR"]);    array_push($pref_array, $row["REMINDF"]);    array_push($pref_array, $row["REMINDA"]);    if($pref_array[$wday] == 1)    {        $ret = true;    }    return $ret;}// Returns the number of days until the user's next reminderfunction get_days_until_next_reminder($wday, $user_num){    $wday++;    if($wday >= 7)        $wday = 0;    $pref_array = array();    db_open();    db_use();    $query_prefs = "SELECT * FROM users WHERE user_id = '$user_num'";    $result = db_query($query_prefs);    $row = db_fetch_row($result);    array_push($pref_array, $row["REMINDS"]);    array_push($pref_array, $row["REMINDM"]);    array_push($pref_array, $row["REMINDT"]);    array_push($pref_array, $row["REMINDW"]);    array_push($pref_array, $row["REMINDR"]);    array_push($pref_array, $row["REMINDF"]);    array_push($pref_array, $row["REMINDA"]);    $max = 1;    $ret = 1;    while($pref_array[$wday] == 0)    {        $ret++;        $max++;        $wday++;        if($wday >= 7) //need to wrap        {            $wday = 0;        }        if($max >= 7) //they haven't set any email preferences        {            $ret = $max;            break;        }    }    return $ret;}// Returns a time stamp corresponding to a date in the future - doesn't really add days to your life :(function add_days ($days, $date) {    $date_time_array  = getdate($date);            $hours =  $date_time_array["HOURS"];    $minutes =  $date_time_array["MINUTES"];    $seconds =  $date_time_array["SECONDS"];    $month =  $date_time_array["MON"];    $day =  $date_time_array["MDAY"];    $year =  $date_time_array["YEAR"];    $day+=$days;    $timestamp =  mktime($hours ,$minutes, $seconds,$month ,$day, $year);    return $timestamp;}?>

⌨️ 快捷键说明

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