Index: openacs-4/contrib/packages/project-manager/tcl/project-manager-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/project-manager/tcl/Attic/project-manager-procs.tcl,v diff -u -r1.5 -r1.6 --- openacs-4/contrib/packages/project-manager/tcl/project-manager-procs.tcl 3 Jun 2004 21:32:01 -0000 1.5 +++ openacs-4/contrib/packages/project-manager/tcl/project-manager-procs.tcl 10 Jun 2004 20:23:11 -0000 1.6 @@ -202,3 +202,203 @@ return $return_val } + + +ad_proc -public pm::util::general_comment_add { + {-object_id:required} + {-title:required} + {-comment ""} + {-mime_type:required} + {-user_id ""} + {-peeraddr ""} + {-type "task"} + {-send_email_p "f"} +} { + Adds a general comment to a task or project + + @author Jade Rubick (jader@bread.com) + @creation-date 2004-06-10 + + @param object_id The item_id for the task or project + + @param title The title for the comment + + @param comment The body of the comment + + @param mime_type The mime_type for the comment + + @param user_id Optional, the user_id making the comment. If left + empty, set to the ad_conn user_id + + @param peeraddr The IP address of the user making the comment. + If empty, set to the ad_conn peeraddr + + @param type Either task or project. + + @param send_email_p Whether or not to send out an email + notification t or f + + @return + + @error -1 if there is an error +} { + if {[empty_string_p $user_id]} { + set user_id [ad_conn user_id] + } + + if {[empty_string_p $peeraddr]} { + set peeraddr [ad_conn peeraddr] + } + + if {![string equal $type task] && ![string equal $type project]} { + return -1 + } + + # insert the comment into the database + set is_live [ad_parameter AutoApproveCommentsP {general-comments} {t}] + + set comment_id [db_nextval acs_object_id_seq] + + db_transaction { + db_exec_plsql insert_comment { + select acs_message__new ( + :comment_id, -- 1 p_message_id + NULL, -- 2 p_reply_to + current_timestamp, -- 3 p_sent_date + NULL, -- 4 p_sender + NULL, -- 5 p_rfc822_id + :title, -- 6 p_title + NULL, -- 7 p_description + :mime_type, -- 8 p_mime_type + NULL, -- 9 p_text + NULL, -- empty_blob() -- 10 p_data + 0, -- 11 p_parent_id + :object_id, -- 12 p_context_id + :user_id, -- 13 p_creation_user + :peeraddr, -- 14 p_creation_ip + 'acs_message', -- 15 p_object_type + :is_live -- 16 p_is_live + ) + } + + db_dml add_entry { + insert into general_comments + (comment_id, + object_id, + category) + values + (:comment_id, + :object_id, + null) + } + + db_1row get_revision { + select content_item__get_latest_revision(:comment_id) as revision_id + } + + db_dml set_content { + update cr_revisions + set content = :comment + where revision_id = :revision_id + } + + db_exec_plsql grant_permission { + begin + perform acs_permission__grant_permission ( + /* object_id => */ :comment_id, + /* grantee_id => */ :user_id, + /* privilege => */ 'read' + ); + + perform acs_permission__grant_permission ( + /* object_id => */ :comment_id, + /* grantee_id => */ :user_id, + /* privilege => */ 'write' + ); + return 0; + end; + } + } + + # now send out email + + if {[string equal $send_email_p t]} { + + # task + + if {[string equal $type task]} { + + set assignees [pm::task::assignee_email_list -task_item_id $object_id] + + if {[llength $assignees] > 0} { + + set to_address [join $assignees ", "] + + set from_address [db_string get_from_email "select email from parties where party_id = :user_id" -default "nobody@nowhere.com"] + + set task_url "[parameter::get_from_package_key -package_key acs-kernel -parameter SystemURL][ad_conn package_url]task-one?task_id=$object_id" + + set subject "Task comment: $title" + + set content "$task_url\n\n$comment" + + pm::util::email \ + -to_addr $to_address \ + -from_addr $from_address \ + -subject $subject \ + -body $content \ + -mime_type $mime_type + } + + } + + # project + if {[string equal $type project]} { + + # send out email + ns_log Notice "send project email" + + } + } + + + return 1 +} + + +ad_proc -public pm::util::email { + {-to_addr:required} + {-from_addr:required} + {-subject:required} + {-body ""} + {-mime_type "text/plain"} +} { + Wrapper to send out email, also converts body to text/plain format + + @author Jade Rubick (jader@bread.com) + @creation-date 2004-06-10 + + @param to_addr + + @param from_addr + + @param subject + + @param body + + @param mime_type + + @return + + @error +} { + + set nice_text [ad_html_text_convert -from $mime_type -to "text/plain" $body] + + acs_mail_lite::send \ + -to_addr "$to_addr" \ + -from_addr "$from_addr" \ + -subject "$subject" \ + -body "$nice_text" + +}