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.13 -r1.14 --- openacs-4/contrib/packages/project-manager/tcl/project-manager-procs.tcl 14 Jul 2004 17:51:06 -0000 1.13 +++ openacs-4/contrib/packages/project-manager/tcl/project-manager-procs.tcl 13 Jan 2005 13:54:35 -0000 1.14 @@ -13,6 +13,93 @@ namespace eval pm::util {} +ad_proc -public pm::util::hours_day { +} { + Returns the number of hours in the workday + + @author (jader-ibr@bread.com) + @creation-date 2004-11-24 + + @return + + @error +} { + return [util_memoize [list pm::util::hours_day_not_cached]] +} + + +ad_proc -public pm::util::hours_day_not_cached { +} { + Returns the number of hours in the workday + + @author (jader-ibr@bread.com) + @creation-date 2004-11-24 + + @return + + @error +} { + return 8 +} + + +ad_proc -public pm::util::days_work { + {-hours_work:required} + {-pretty_p "f"} +} { + Returns the number of days work + + @author (jader-ibr@bread.com) + @creation-date 2004-11-24 + + @param hours_work + + @return + + @error +} { + set hours_day [pm::util::hours_day] + + if {![string equal $hours_day 0]} { + set number [expr double($hours_work) / $hours_day] + } + + set return_val [pm::util::trim_number -number $number] + + if {[string is true $pretty_p]} { + if {$return_val < 1} { + return "less than 1" + } + } + + return $return_val +} + + +ad_proc -public pm::util::trim_number { + {-number:required} + {-precision "4"} +} { + Trims zeros off the end of a number + + @author (jader-ibr@bread.com) + @creation-date 2004-11-24 + + @param precision + + @return + + @error +} { + set return_val [format "%0.${precision}f" $number] + set return_val [string trimright $return_val 0] + set return_val [string trimright $return_val .] + + return $return_val +} + + + ad_proc -public pm::util::datenvl { -value -value_if_null @@ -29,6 +116,36 @@ } +ad_proc -public pm::util::reformat_date { + the_date +} { + the end date comes in this format 2004 05 17 + we need to get it in the {2004} {05} {17} {} {} {} format + + @author Jade Rubick (jader@bread.com) + + @creation-date 2004-09-23 + + + @param the_date + + + @return + + @error +} { + + regexp {(.*) (.*) (.*)} $the_date match year month day + if {[exists_and_not_null year]} { + set return_val "$year $month $day {} {} {}" + } else { + set return_val "{} {} {} {} {} {}" + } + + return $return_val +} + + ad_proc -public pm::util::string_truncate_and_pad { -length {-ellipsis "..."} @@ -238,7 +355,7 @@ @param send_email_p Whether or not to send out an email notification t or f - @return + @return the comment_id of the new comment @error -1 if there is an error } { @@ -302,22 +419,18 @@ 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' - ); + if {![empty_string_p $user_id]} { + permission::grant \ + -object_id $comment_id \ + -party_id $user_id \ + -privilege "read" - perform acs_permission__grant_permission ( - /* object_id => */ :comment_id, - /* grantee_id => */ :user_id, - /* privilege => */ 'write' - ); - return 0; - end; + permission::grant \ + -object_id $comment_id \ + -party_id $user_id \ + -privilege "write" } + } # now send out email @@ -336,18 +449,22 @@ 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 task_url [pm::task::get_url $object_id] set subject "Task comment: $title" - set content "$task_url\n\n$comment" + # convert to HTML + set richtext_list [list $comment $mime_type] + set comment_html [template::util::richtext::get_property html_value $richtext_list] + + set content "$title

$comment_html" pm::util::email \ -to_addr $to_address \ -from_addr $from_address \ -subject $subject \ -body $content \ - -mime_type $mime_type + -mime_type "text/html" } } @@ -364,26 +481,32 @@ 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 project_url [pm::project::url \ + -project_item_id $object_id] set subject "Project comment: $title" + + # convert to HTML + set richtext_list [list $comment $mime_type] + set comment_html [template::util::richtext::get_property html_value $richtext_list] + + set content "$title

$comment_html" + - 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 + -mime_type "text/html" } } } - return 1 + return $comment_id } @@ -414,15 +537,41 @@ @error } { - set nice_text [ad_html_text_convert -from $mime_type -to "text/plain" -- $body] + # HTML portions of this copied from notification::email::send + if {[string equal $mime_type "text/plain"]} { + set body_text $body + set body_html [ad_html_text_convert -from $mime_type -to "text/html" -- $body] + } elseif {[string equal $mime_type "text/html"]} { + set body_text [ad_html_text_convert -from $mime_type -to "text/plain" -- $body] + set body_html $body + + } else { + set body_text [ad_html_text_convert -from $mime_type -to "text/plain" -- $body] + set body_html [ad_html_text_convert -from $mime_type -to "text/html" -- $body] + + } + + # Use this to build up extra mail headers + set extra_headers [ns_set new] + + # This should disable most auto-replies + ns_set put $extra_headers Precedence list + + set message_data [build_mime_message $body_text $body_html] + ns_set put $extra_headers MIME-Version [ns_set get $message_data MIME-Version] + ns_set put $extra_headers Content-ID [ns_set get $message_data Content-ID] + ns_set put $extra_headers Content-Type [ns_set get $message_data Content-Type] + set content [ns_set get $message_data body] + foreach to $to_addr { acs_mail_lite::send \ -to_addr "$to" \ -from_addr "$from_addr" \ -subject "$subject" \ - -body "$nice_text" + -body $content \ + -extraheaders $extra_headers } } @@ -515,3 +664,87 @@ } +ad_proc -public pm::util::package_id { +} { + Returns the package ID for the project manager. + + @author Jade Rubick (jader@bread.com) + @creation-date 2004-09-16 + + @return + + @error +} { + return [db_string get_package_id { + SELECT + package_id + FROM + cr_folders + WHERE + description = 'Project Repository' + LIMIT 1 + }] +} + + +ad_proc -public pm::util::url { + {-fully_qualified_p "t"} +} { + Returns the URL of where the project manager is located, + fully qualified + + @author Jade Rubick (jader@bread.com) + @creation-date 2004-09-16 + + @return + + @error +} { + set package_id [pm::util::package_id] + + if {[string is true $fully_qualified_p]} { + set return_val [ad_url] + } else { + set return_val "" + } + append return_val [site_node::get_url_from_object_id -object_id $package_id] + + return $return_val +} + + +ad_proc -public pm::util::subsite_assignees_list_of_lists { +} { + Returns a list of lists of possible assignees + + @author Jade Rubick (jader@bread.com) + @creation-date 2004-10-13 + + @return + + @error +} { + return [util_memoize [list pm::util::subsite_assignees_list_of_lists_not_cached] 6000] +} + + +ad_proc -public pm::util::subsite_assignees_list_of_lists_not_cached { +} { + Returns a list of lists of possible assignees + + @author Jade Rubick (jader@bread.com) + @creation-date 2004-10-13 + + @return + + @error +} { + + set subsite_id [ad_conn subsite_id] + set user_group_id [application_group::group_id_from_package_id \ + -package_id $subsite_id] + + set assignees [db_list_of_lists get_assignees { }] + + return $assignees +}