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.2.2.2 -r1.2.2.3 --- openacs-4/contrib/packages/project-manager/tcl/project-manager-procs.tcl 20 May 2004 17:35:19 -0000 1.2.2.2 +++ openacs-4/contrib/packages/project-manager/tcl/project-manager-procs.tcl 2 Jul 2004 23:13:48 -0000 1.2.2.3 @@ -181,4 +181,335 @@ return $res } ->>>>>>> 1.4 + + +ad_proc -public pm::util::logger_url {} { + Returns the URL for the primary logger URL + + @author Jade Rubick (jader@bread.com) + @creation-date 2004-05-24 + + @return + + @error +} { + set return_val [parameter::get -parameter "LoggerPrimaryURL" -default ""] + + if {[empty_string_p $return_val]} { + ns_log Error "Project-manager: need to set up LoggerPrimaryURL in parameters" + util_user_message -message "Administrator needs to set up logger integration" + } + + 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 $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]} { + + set assignees [pm::project::assignee_email_list -project_item_id $object_id] + + if {[llength $assignees] > 0} { + + set to_address $assignees + + set from_address [db_string get_from_email "select email from parties where party_id = :user_id" -default "nobody@nowhere.com"] + + set project_url "[parameter::get_from_package_key -package_key acs-kernel -parameter SystemURL][ad_conn package_url]one?project_item_id=$object_id" + + set subject "Project comment: $title" + + set content "$project_url\n\n$comment" + + pm::util::email \ + -to_addr $to_address \ + -from_addr $from_address \ + -subject $subject \ + -body $content \ + -mime_type $mime_type + } + + + } + } + + + 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 list of email addresses to send to + + @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] + + foreach to $to_addr { + + acs_mail_lite::send \ + -to_addr "$to" \ + -from_addr "$from_addr" \ + -subject "$subject" \ + -body "$nice_text" + } +} + + +ad_proc -public pm::util::category_selects { + {-export_vars ""} + {-category_id ""} + {-package_id ""} +} { + Returns an HTML fragment of forms, one for each + category tree, suitable for use on a page. + + @author Jade Rubick (jader@bread.com) + @creation-date 2004-06-11 + + @param export_vars Variables already exported with export_vars -form + + @param category_id If set, the currently selected category + + @return + + @error +} { + if {[empty_string_p $package_id]} { + set package_id [ad_conn package_id] + } + + # caches results for 2.5 minutes. + return [util_memoize [list pm::util::category_selects_not_cached -export_vars $export_vars -category_id $category_id -package_id $package_id] 300] +} + + + +ad_proc -private pm::util::category_selects_not_cached { + {-export_vars ""} + {-category_id ""} + -package_id:required +} { + Returns an HTML fragment of category choices, suitable + for use on a page. This proc + is used so that pm::util::category_selects can cache + the categories + + @author Jade Rubick (jader@bread.com) + @creation-date 2004-06-11 + + @param export_vars Variables already exported with export_vars -form + + @param category_id If set, the currently selected category + + @return + + @error +} { + # Categories are arranged into category trees. + # Set up an array for each tree. The array contains the category for each tree + + set category_select "" + set number_of_categories 0 + set last_tree "" + set category_select "" + + db_foreach get_categories { } { + + if {![string equal $tree_name $last_tree] } { + append category_select "" + } + + if {[string equal $cat_id $category_id]} { + set select "selected" + } else { + set select "" + } + + append category_select "" + + set last_tree $tree_name + incr number_of_categories + } + + if {$number_of_categories < 1} { + return "" + } + + set return_val "
$export_vars
" + + return $return_val +}