Index: openacs-4/contrib/packages/project-manager/tcl/task-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/project-manager/tcl/Attic/task-procs.tcl,v diff -u -r1.6 -r1.7 --- openacs-4/contrib/packages/project-manager/tcl/task-procs.tcl 3 May 2004 16:22:59 -0000 1.6 +++ openacs-4/contrib/packages/project-manager/tcl/task-procs.tcl 5 May 2004 19:04:54 -0000 1.7 @@ -1211,3 +1211,217 @@ ns_log Notice "Scheduling daily email notifications for project manager to 5:00 am" ad_schedule_proc -thread t -debug t -schedule_proc ns_schedule_daily "5 0" pm::task::email_status } + + + +ad_proc -public pm::task::email_alert { + -task_item_id:required + {-user_id ""} + {-assignee_id ""} + {-assignee_role_name ""} + {-edit_p "t"} + {-comment ""} + {-description ""} + {-old_description ""} + {-subject ""} + {-work ""} + {-work_min ""} + {-work_max ""} + {-project_name ""} + {-earliest_start ""} + {-earliest_finish ""} + {-latest_start ""} + {-latest_finish ""} + {-url ""} +} { + Sends out an email notification when changes have been made to a task + +

+ + If any of the following are missing, fills in from the database: + subject, work, work_min, work_max, project_name, earliest_start, + earliest_finish, latest_start, latest_finish + + @author Jade Rubick (jader@bread.com) + @creation-date 2004-05-03 + + @param task_item_id + + @param user_id The user making the change + + @param assignee_id The party_id of the user assigned to the task. + + @param assignee_role_name The role name for what the party is + assigned to do + + @param edit_p Is this an edited task, or a new one? t for edited, + f otherwise. + + @param description + + @param old_description + + @param subject The one line description of the task + + @param work Estimated hours work + + @param work_min Estimated minimimum hours work + + @param work_max Estimated maximum hours work + + @param project_name + + @param earliest_start + + @param earliest_finish + + @param latest_start + + @param latest_finish + + @param url Optionally, a URL that the user is directed to + + @return + + @error +} { + + set task_term [parameter::get -parameter "Taskname" -default "Task"] + set task_term_lower [parameter::get -parameter "taskname" -default "task"] + set use_uncertain_completion_times_p [parameter::get -parameter "UseUncertainCompletionTimesP" -default "0"] + + # from address + + if {![exists_and_not_null $user_id]} { + set user_id [ad_conn user_id] + } + + db_1row get_from_address_and_more { + SELECT + p.email as from_address, + p2.first_names || ' ' || p2.last_name as mod_username + FROM + parties p, + persons p2 + WHERE + p.party_id = :user_id and + p.party_id = p2.person_id + } + + # to address + + if {![exists_and_not_null assignee_id]} { + + # bug: we should get the list of assignees here. + ns_log Error "the proc pm::task::email_alert is not complete: assignee" + + } + + set to_address [db_string get_email "select email from parties where party_id = :assignee_id"] + + + # if they left out any of the task info, then we get it from the database + if { \ + ![exists_and_not_null subject] || \ + ![exists_and_not_null work] || \ + ![exists_and_not_null work_min] || \ + ![exists_and_not_null work_max] || \ + ![exists_and_not_null project_name] || \ + ![exists_and_not_null earliest_start] || \ + ![exists_and_not_null earliest_finish] || \ + ![exists_and_not_null latest_start] || \ + ![exists_and_not_null latest_finish] \ + } { + + db_1row get_task_info { + SELECT + t.title as subject, + to_char(t.earliest_start,'MM-DD-YYYY') as earliest_start, + to_char(t.earliest_finish,'MM-DD-YYYY') as earliest_finish, + to_char(t.latest_start,'MM-DD-YYYY') as latest_start, + to_char(t.latest_finish,'MM-DD-YYYY') as latest_finish, + t.estimated_hours_work as work, + t.estimated_hours_work_min as work_min, + t.estimated_hours_work_max as work_max, + t.percent_complete, + p.title as project_name + FROM + pm_tasks_revisionsx t, + cr_items i, + cr_items project, + pm_projectsx p + WHERE + t.item_id = :task_item_id and + t.revision_id = i.live_revision and + t.item_id = i.item_id and + t.parent_id = project.item_id and + project.item_id = p.item_id and + project.live_revision = p.revision_id + } + + } + + + if {[string equal $edit_p "t"]} { + set subject_out "Edited $task_term \#$task_item_id: $subject" + set intro_text "$mod_username edited this $task_term_lower" + } else { + set subject_out "New $task_term \#$task_item_id: $subject" + set intro_text "$mod_username assigned you to a new $task_term_lower" + } + + if {[empty_string_p $comment]} { + set comment_text "" + } else { + set comment_text "--------\nCOMMENT:\n--------\n$comment\n\n" + } + + if {[exists_and_not_null url]} { + set task_url $url + } else { + set task_url "unavailable" + } + + + + if {![string equal $description $old_description] && [string equal $edit_p t]} { + set description_out "$description \n\n-------\nOld description:\n-------\n\n[ad_html_to_text $old_description]" + + append intro_text "\nSee below to see the changes in the description" + + } else { + set description_out [ad_html_to_text $description] + } + + if {[string equal $use_uncertain_completion_times_p 1]} { + set estimated_work "\nHrs work (min): $work_min" + append estimated_work "\nHrs work (max): $work_max" + } else { + set estimated_work "\nHrs work: $work" + } + + set notification_text "$intro_text\n\n$comment_text-------------" + append notification_text "\nTask overview\n-------------" + append notification_text "\nTask ID: \#$task_item_id" + append notification_text "\nSubject: $subject" + append notification_text "\nProject: $project_name" + append notification_text "\nYour role: $assignee_role_name" + append notification_text "\nLink: $task_url" + append notification_text "\n\n\n\n---------------" + append notification_text "\nEstimated work:\n---------------$estimated_work" + append notification_text "\n\n------\nDates:" + append notification_text "\n------\nEarliest start: $earliest_start" + append notification_text "\nEarliest finish: $earliest_finish" + append notification_text "\nLatest start: $latest_start" + append notification_text "\nLatest finish *$latest_finish" + append notification_text "\n\n-----------\nDescription\n-----------" + append notification_text "\n$description_out" + + acs_mail_lite::send \ + -to_addr $to_address \ + -from_addr $from_address \ + -subject $subject_out \ + -body $notification_text + + +}