Index: openacs-4/contrib/packages/project-manager/www/log.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/project-manager/www/Attic/log.tcl,v diff -u -r1.2.2.1 -r1.2.2.2 --- openacs-4/contrib/packages/project-manager/www/log.tcl 20 May 2004 17:30:05 -0000 1.2.2.1 +++ openacs-4/contrib/packages/project-manager/www/log.tcl 2 Jul 2004 23:13:49 -0000 1.2.2.2 @@ -1,477 +1,11 @@ ad_page_contract { - Add/edit/display a log entry for project manager + Stub that tells people to set up logger/project-manager integration - @author Peter Marklund (peter@collaboraid.biz) @author Jade Rubick (jader@bread.com) stolen from Peter @creation-date 2003-04-16 @cvs-id $Id$ -} { - entry_id:integer,optional - project_id:integer,optional - pm_project_id:integer - {pm_task_id:integer ""} - variable_id:integer,optional - {edit:boolean "f"} - {return_url "."} -} -validate { - #project_id_required_in_add_mode { - # For the sake of simplicity of the form - # we are requiring a project_id to be provided in add mode - #if { ![exists_and_not_null entry_id] && ![exists_and_not_null project_id] } { - # ad_complain "When adding a log entry a project_id must be provided (either entry_id or project_id must be present)." - #} - #} } -if { ![exists_and_not_null project_id] } { - - if {[exists_and_not_null entry_id]} { - # do nothing - } else { - set project_id [pm::project::get_logger_project \ - -project_item_id $pm_project_id] - - } -} - -set package_id [ad_conn package_id] -set current_user_id [ad_maybe_redirect_for_registration] - -if { [exists_and_not_null entry_id] } { - set entry_exists_p [db_string entry_exists_p {}] -} else { - set entry_exists_p 0 -} - -if { [string equal [form get_action log_entry_form] "done"] } { - # User is done editing - redirect back to index page - ad_returnredirect $return_url - ad_script_abort -} - -########### -# -# Get project and variable info -# -########### - -# Get project and variable id -if { $entry_exists_p } { - permission::require_permission -object_id $entry_id -privilege read - - # We have the entry_id so try to get project and variable_id from - # the database for that entry - logger::entry::get -entry_id $entry_id -array entry_array - set project_id $entry_array(project_id) - set variable_id $entry_array(variable_id) -} - -# Get project_id if it's not provided -if { [exists_and_not_null entry_id] && ![exists_and_not_null project_id] } { - logger::entry::get -entry_id $entry_id -array entry - set project_id $entry(project_id) -} - -# Default the variable we are logging in to the primary variable of the project -if { ![exists_and_not_null variable_id] } { - set variable_id [logger::project::get_primary_variable -project_id $project_id] - - if { [empty_string_p $variable_id] } { - ad_return_error "Project has no variable" "An administrator needs to associate a variable, such as time or expense, to this project before any logging can be done." - ad_script_abort - } -} - -# We need project and variable names -logger::project::get -project_id $project_id -array project_array -logger::variable::get -variable_id $variable_id -array variable_array - -########### -# -# Build the form -# -########### - -# The creator of a log entry can always edit it -if { $entry_exists_p } { - set edit_p [expr [permission::permission_p -object_id $entry_id -privilege write] || \ - $current_user_id == $entry_array(creation_user)] -} else { - set edit_p 0 -} - -# Different page title and form mode when adding a log entry -# versus displaying/editing one -if { [exists_and_not_null entry_id] } { - # Initial request in display or edit mode or a submit of the form - set page_title "Edit Log Entry" - if { [string equal $edit "t"] && $edit_p } { - set ad_form_mode edit - } else { - set ad_form_mode display - } -} else { - # Initial request in add mode - set page_title "Add Log Entry" - set ad_form_mode edit -} - - -# Build the log entry form elements -set actions [list] -if { $edit_p } { - lappend actions { Edit edit } -} -lappend actions { Done done } - -ad_form -name log_entry_form -cancel_url $return_url -mode $ad_form_mode \ - -actions $actions -form { - entry_id:key(acs_object_id_seq) - } - -# On various occasions we need to know if we are dealing with a submit with the -# form or an initial request (could also be with error message after unaccepted submit) -set submit_p [form is_valid log_entry_form] - -ad_form -extend -name log_entry_form -form { - {project:text(inform) - {label Project} - {section "Hour log"} - {value $project_array(name)} - } - - {project_id:integer(hidden) - {value $project_id} - } - - {variable_id:integer(hidden) - {value $variable_id} - } - - {return_url:text(hidden) {value $return_url}} -} - -# Add form elements common to all modes -# The form builder date datatype doesn't take ANSI format date strings -# but wants dates in list format -set default_date [clock format [clock seconds] -format "%Y %m %d"] -ad_form -extend -name log_entry_form -form { - {value:float - {label $variable_array(name)} - {after_html $variable_array(unit)} - {html {size 9 maxlength 9}} - } - - {pm_project_id:text(hidden) - {value $pm_project_id} - } - - {pm_task_id:text(hidden) - {value $pm_task_id} - } - - {description:text,optional - {label Description} - {html {size 50}} - } - - {time_stamp:date - {label Date} - {value $default_date} - } -} - -# allow the user to edit the percentage complete when necessary -if {[exists_and_not_null pm_task_id]} { - - set use_uncertain_completion_times_p [parameter::get -parameter "UseUncertainCompletionTimesP" -default "1"] - - db_1row get_task_values " - SELECT - title as task_title, - case when percent_complete is null then 0 - else percent_complete end as percent_complete, - estimated_hours_work, - estimated_hours_work_min, - estimated_hours_work_max, - s.description as status_description - FROM - pm_tasks_revisionsx p, - cr_items i, - pm_task_status s, - pm_tasks t - WHERE i.item_id = p.item_id and - p.item_id = :pm_task_id and - i.item_id = t.task_id and - t.status = s.status_id and - p.revision_id = i.live_revision" - - ad_form -extend -name log_entry_form -form { - - {task_title:text(inform) - {section "Task"} - {label "Subject"} - {value $task_title} - } - - {status_description:text(inform) - {label "Status"} - {value $status_description} - } - - } - - if {[string equal $use_uncertain_completion_times_p 1]} { - - set display_value "$estimated_hours_work_min - $estimated_hours_work_max" - ad_form -extend -name log_entry_form -form { - - {estimated_hours_work:text(inform) - {label "Estimated work"} - {value $display_value} - {after_html "hours"} - } - - - } - - } else { - - ad_form -extend -name log_entry_form -form { - - {estimated_hours_work:text(inform) - {label "Estimated work"} - {value $estimated_hours_work} - {after_html "hours"} - } - - } - - } - - - ad_form -extend -name log_entry_form -form { - - {percent_complete:float - {label "Complete"} - {after_html "%"} - {html {size 9 maxlength 9}} - {value $percent_complete} - } - - } - -} - - -if { [exists_and_not_null pm_task_id] } { - set context [list [list "[ad_conn package_url]task-one?task_id=$pm_task_id" "$task_title"] $page_title] -} else { - - set context [list [list "[ad_conn package_url]one?project_item_id=$pm_project_id" "$project_array(name)"] $page_title] -} - - -########### -# -# Execute the form -# -########### - -ad_form -extend -name log_entry_form -select_query_name select_logger_entries -validate { - {value - { [regexp {^([0-9]{1,6}|[0-9]{0,6}\.[0-9]{0,2})$} $value] } - {The value may not contain more than two decimals and must be between 0 and 999999.99} - } - -} -new_data { - set time_stamp_ansi "[lindex $time_stamp 0]-[lindex $time_stamp 1]-[lindex $time_stamp 2]" - - # jarkko: check to see if user has already added this entry and has come - # back with her back button. If the entry exists, we give the user a complaint - # and a link to edit this particular entry. - if { [string match [db_string check_if_exists " - select 1 - from logger_entries - where entry_id = :entry_id - " -default "0"] "0"]} { - - pm::project::log_hours \ - -entry_id $entry_id \ - -logger_project_id $project_id \ - -variable_id $variable_id \ - -value $value \ - -timestamp_ansi $time_stamp_ansi \ - -description $description \ - -task_item_id $pm_task_id \ - -project_item_id $pm_project_id - - - if {[exists_and_not_null pm_task_id]} { - db_dml update_percent " - UPDATE - pm_tasks_revisions - SET - percent_complete = :percent_complete - WHERE - task_revision_id = (select - live_revision - from - cr_items - where - item_id = :pm_task_id)" - - if {$percent_complete >= 100} { - - pm::task::close -task_item_id $pm_task_id - - } else { - - pm::task::open -task_item_id $pm_task_id - - } - - } - - } else { - - doc_return 200 text/html "[ad_header_with_extra_stuff "Problem with Your Input" "" ""] -

Problem with Your Input

- -to [ad_system_name] - -
- -You have already added this entry once. If you want to edit this entry, click here. - -[ad_footer] - " - } - - # Present the user with an add form again for quick logging - ad_returnredirect "[ad_conn url]?[export_vars {project_id variable_id pm_project_id pm_task_id}]" - ad_script_abort - -} -edit_data { - set time_stamp_ansi "[lindex $time_stamp 0]-[lindex $time_stamp 1]-[lindex $time_stamp 2]" - logger::entry::edit -entry_id $entry_id \ - -value $value \ - -time_stamp $time_stamp_ansi \ - -description $description - - set old_pm_task_id $pm_task_id - - set pm_task_id [db_string task_entry_p "select task_item_id from pm_task_logger_proj_map where logger_entry = :entry_id" -default "-1"] - - if {![string equal $pm_task_id -1] && [exists_and_not_null percent_complete]} { - - db_dml update_percent " - UPDATE - pm_tasks_revisions - SET - percent_complete = :percent_complete - WHERE - task_revision_id = (select - live_revision - from - cr_items - where - item_id = :pm_task_id)" - - pm::task::update_hours \ - -task_item_id $pm_task_id - - if {$percent_complete >= 100} { - set status_code [pm::task::default_status_closed] - } else { - set status_code [pm::task::default_status_open] - } - - db_dml update_percent " - UPDATE - pm_tasks - SET - status = :status_code - WHERE - task_id = :pm_task_id" - - - } - - set pm_task_id $old_pm_task_id - -} -after_submit { - ad_returnredirect "[ad_conn url]?[export_vars { project_id variable_id return_url pm_project_id pm_task_id}]" - # ad_returnredirect $return_url - - if {![string equal $pm_task_id -1]} { - pm::project::compute_status $pm_project_id - } - - ad_script_abort -} - -########### -# -# Log history -# -########### - -# Show the log history if the user is looking at /editing his own entry or if -# the user is adding a new entry -if { $entry_exists_p && [string equal $current_user_id $entry_array(creation_user)] } { - set entry_edited_by_owner_p 1 -} else { - set entry_edited_by_owner_p 0 -} - -set show_log_history_p [expr $entry_edited_by_owner_p || ! $entry_exists_p] - -if { $show_log_history_p } { - # Show N number of days previous to the last logged entry by the user - set ansi_format_string "%Y-%m-%d" - set last_logged_date [db_string last_logged_date { - select max(to_char(le.time_stamp, 'YYYY-MM-DD')) - from logger_entries le, - acs_objects ao - where le.entry_id = ao.object_id - and le.variable_id = :variable_id - and le.project_id = :project_id - and ao.creation_user = :current_user_id - } -default ""] - - if { ![empty_string_p $last_logged_date] } { - set end_date_ansi $last_logged_date - set end_date_seconds [clock scan $end_date_ansi] - } else { - # Default end date to now - set end_date_seconds [clock seconds] - set end_date_ansi [clock format $end_date_seconds -format $ansi_format_string] - } - set log_history_n_days 31 - set seconds_per_day [expr 60*60*24] - set start_date_seconds [expr $end_date_seconds - $log_history_n_days * $seconds_per_day] - set start_date_ansi [clock format $start_date_seconds \ - -format $ansi_format_string] -} - -set add_entry_url "log?[export_vars { project_id variable_id pm_project_id pm_task_id}]" - -if { [info exists entry_id] } { - set entry_id_or_blank $entry_id -} else { - set entry_id_or_blank {} -} - - -##### -# -# Change variable -# -##### - -db_multirow -extend { url selected_p } variables select_variables {} { - set url "log?[export_vars -override { {variable_id $unique_id} } { project_id pm_project_id pm_task_id}]" - set selected_p [string equal $variable_id $unique_id] -} +set title "Set up logger integration" +set context [list]