Index: openacs-4/contrib/packages/project-manager/www/task-add-edit-2.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/project-manager/www/Attic/task-add-edit-2.tcl,v diff -u -r1.1.2.17 -r1.1.2.18 --- openacs-4/contrib/packages/project-manager/www/task-add-edit-2.tcl 21 Jun 2005 16:19:19 -0000 1.1.2.17 +++ openacs-4/contrib/packages/project-manager/www/task-add-edit-2.tcl 5 Jul 2005 21:43:31 -0000 1.1.2.18 @@ -67,8 +67,20 @@ set use_days_p [parameter::get -parameter "UseDayInsteadOfHour" -default "t"] foreach i $number { + + #validate date field + if {![regexp {^(--)|\d{4}(\-|/)\d{2}(\-|/)\d{2}?} [lindex $date [expr $i-1]]] && [lindex $date [expr $i-1]] != ""} { + set date [lindex $date [expr $i-1]] + ad_return_error "[_ project-manager.Error]" "[_ project-manager.Date_error]" + } + + if {[regexp {^\d{4}/\d{2}/\d{2}?} [lindex $date [expr $i-1]]]} { + set delim "/" + } else { + set delim "-" + } - set date_$i [split [lindex $date [expr $i-1]] "-"] + set date_$i [split [lindex $date [expr $i-1]] $delim] set end_date_${i}(day) [lindex [set date_$i] 2] set end_date_${i}(month) [lindex [set date_$i] 1] set end_date_${i}(year) [lindex [set date_$i] 0] @@ -155,60 +167,10 @@ -project_item_id_array old_project_item_id \ -priority_array old_priority \ -set_client_properties_p t - foreach num $number { - # -------------------------- - # figure out estimated hours - # -------------------------- + db_transaction { + foreach num $number { - if {[string is true $use_uncertain_completion_times_p]} { - set estimated_hours_work($num) \ - [expr .5 * \ - ($estimated_hours_work_max($num) - \ - $estimated_hours_work_min($num)) + \ - $estimated_hours_work_min($num)] - } else { - set estimated_hours_work_min($num) $estimated_hours_work($num) - set estimated_hours_work_max($num) $estimated_hours_work($num) - } - - # ------------------------------------- - # Log hours and other variables to task - # ------------------------------------- - - set logger_project [pm::project::get_logger_project \ - -project_item_id $project_item_id($num)] - - - if {[exists_and_not_null hours($num)]} { - - pm::project::log_hours \ - -logger_project_id $logger_project \ - -variable_id $logger_variable($num) \ - -value $hours($num) \ - -description $log($num) \ - -task_item_id $task_item_id($num) \ - -project_item_id $project_item_id($num) \ - -update_status_p f \ - -party_id $user_id \ - -timestamp_ansi [set log_date_${num}] - } - - # --------- - # edit task - # --------- - - permission::require_permission -party_id $user_id -object_id $task_item_id($num) -privilege write - - - set dead_line "[set end_date_${num}(year)]-[set end_date_${num}(month)]-[set end_date_${num}(day)]" - set task_revision \ - [pm::task::edit \ - -task_item_id $task_item_id($num) \ - -project_item_id $project_item_id($num) \ - -title $task_title($num) \ - -description $description($num) \ - -mime_type $description_mime_type($num) \ -end_date [set end_date_${num}(date)] \ -percent_complete $percent_complete($num) \ -estimated_hours_work $estimated_hours_work($num) \ @@ -218,50 +180,104 @@ -update_ip $peeraddr \ -package_id $package_id \ -priority $priority($num) + $estimated_hours_work_min($num)] + } else { + set estimated_hours_work_min($num) $estimated_hours_work($num) + set estimated_hours_work_max($num) $estimated_hours_work($num) + } + + # ------------------------------------- + # Log hours and other variables to task + # ------------------------------------- + + set logger_project [pm::project::get_logger_project \ + -project_item_id $project_item_id($num)] + + + if {[exists_and_not_null hours($num)]} { + + pm::project::log_hours \ + -logger_project_id $logger_project \ + -variable_id $logger_variable($num) \ + -value $hours($num) \ + -description $log($num) \ + -task_item_id $task_item_id($num) \ + -project_item_id $project_item_id($num) \ + -update_status_p f \ + -party_id $user_id \ + -timestamp_ansi [set log_date_${num}] + } + + # --------- + # edit task + # --------- + + permission::require_permission -party_id $user_id -object_id $task_item_id($num) -privilege write + + + set dead_line "[set end_date_${num}(year)]-[set end_date_${num}(month)]-[set end_date_${num}(day)]" + set task_revision \ + [pm::task::edit \ + -task_item_id $task_item_id($num) \ + -project_item_id $project_item_id($num) \ + -title $task_title($num) \ + -description $description($num) \ + -mime_type $description_mime_type($num) \ + -end_date [set end_date_${num}(date)]\ + -percent_complete $percent_complete($num) \ + -estimated_hours_work $estimated_hours_work($num) \ + -estimated_hours_work_min $estimated_hours_work_min($num) \ + -estimated_hours_work_max $estimated_hours_work_max($num) \ + -update_user $user_id \ + -update_ip $peeraddr \ + -package_id $package_id \ + -priority $priority($num) ] - # -------------------------- - # remove all old assignments - # -------------------------- - pm::task::assign_remove_everyone \ - -task_item_id $task_item_id($num) + # -------------------------- + # remove all old assignments + # -------------------------- + pm::task::assign_remove_everyone \ + -task_item_id $task_item_id($num) + # ----------------------- + # remove all dependencies + # ----------------------- + pm::task::dependency_delete_all \ + -task_item_id $task_item_id($num) + + } + # ----------------------- - # remove all dependencies + # add back in assignments # ----------------------- - pm::task::dependency_delete_all \ - -task_item_id $task_item_id($num) - } + foreach ass $assignee { + regexp {(\d+)-(\d+)-(\d+)} $ass match num person role - # ----------------------- - # add back in assignments - # ----------------------- + set task $task_item_id($num) - foreach ass $assignee { - regexp {(\d+)-(\d+)-(\d+)} $ass match num person role + pm::task::assign \ + -task_item_id $task \ + -party_id $person \ + -role_id $role + } - set task $task_item_id($num) - - pm::task::assign \ - -task_item_id $task \ - -party_id $person \ - -role_id $role - } - - # ----------------------- - # add in the dependencies - # ----------------------- - foreach num $number { - if {[exists_and_not_null dependency($num)]} { - pm::task::dependency_add \ - -task_item_id $task_item_id($num) \ - -parent_id $dependency($num) \ - -dependency_type finish_before_start \ - -project_item_id $project_item_id($num) + # ----------------------- + # add in the dependencies + # ----------------------- + foreach num $number { + if {[exists_and_not_null dependency($num)]} { + pm::task::dependency_add \ + -task_item_id $task_item_id($num) \ + -parent_id $dependency($num) \ + -dependency_type finish_before_start \ + -project_item_id $project_item_id($num) + } } + } on_error { + ad_return_error "[_ project-manager.Error]" "[_ project-manager.There_was_an_error]" } - } else { # ----------------------------------- @@ -278,89 +294,92 @@ set process_instance_id "" } - foreach num $number { + db_transaction { + foreach num $number { - # -------------------------- - # figure out estimated hours - # -------------------------- + # -------------------------- + # figure out estimated hours + # -------------------------- - if {[string is true $use_uncertain_completion_times_p]} { - set estimated_hours_work($num) \ - [expr .5 * \ - ($estimated_hours_work_max($num) - \ - $estimated_hours_work_min($num)) + \ - $estimated_hours_work_min($num)] - } else { - set estimated_hours_work_min($num) $estimated_hours_work($num) - set estimated_hours_work_max($num) $estimated_hours_work($num) - } + if {[string is true $use_uncertain_completion_times_p]} { + set estimated_hours_work($num) \ + [expr .5 * \ + ($estimated_hours_work_max($num) - \ + $estimated_hours_work_min($num)) + \ + $estimated_hours_work_min($num)] + } else { + set estimated_hours_work_min($num) $estimated_hours_work($num) + set estimated_hours_work_max($num) $estimated_hours_work($num) + } - # ----------- - # create task - # ----------- + # ----------- + # create task + # ----------- - permission::require_permission -party_id $user_id -object_id $project_item_id($num) -privilege create + permission::require_permission -party_id $user_id -object_id $project_item_id($num) -privilege create - set task_item \ - [pm::task::new \ - -project_id $project_item_id($num) \ - -title $task_title($num) \ - -description $description($num) \ - -mime_type $description_mime_type($num) \ - -end_date [set end_date_${num}(date)]\ - -percent_complete $percent_complete($num) \ - -estimated_hours_work $estimated_hours_work($num) \ - -estimated_hours_work_min $estimated_hours_work_min($num) \ - -estimated_hours_work_max $estimated_hours_work_max($num) \ - -process_instance_id $process_instance_id \ - -creation_user $user_id \ - -creation_ip $peeraddr \ - -package_id $package_id \ - -priority $priority($num) + set task_item \ + [pm::task::new \ + -project_id $project_item_id($num) \ + -title $task_title($num) \ + -description $description($num) \ + -mime_type $description_mime_type($num) \ + -end_date [set end_date_${num}(date)]\ + -percent_complete $percent_complete($num) \ + -estimated_hours_work $estimated_hours_work($num) \ + -estimated_hours_work_min $estimated_hours_work_min($num) \ + -estimated_hours_work_max $estimated_hours_work_max($num) \ + -process_instance_id $process_instance_id \ + -creation_user $user_id \ + -creation_ip $peeraddr \ + -package_id $package_id \ + -priority $priority($num) ] - set task_item_id($num) $task_item - } + set task_item_id($num) $task_item + } - # ---------------- - # add in assignees - # ---------------- + # ---------------- + # add in assignees + # ---------------- - foreach ass $assignee { - regexp {(\d+)-(\d+)-(\d+)} $ass match num person role + foreach ass $assignee { + regexp {(\d+)-(\d+)-(\d+)} $ass match num person role - set task $task_item_id($num) + set task $task_item_id($num) - pm::task::assign \ - -task_item_id $task \ - -party_id $person \ - -role_id $role - } + pm::task::assign \ + -task_item_id $task \ + -party_id $person \ + -role_id $role + } - # ------------------- - # add in dependencies - # ------------------- - foreach num $number { + # ------------------- + # add in dependencies + # ------------------- + foreach num $number { - # if there is a numXX as the dependency, then we are relying - # on new tasks that had not been created yet. So we match them - # up with the new tasks we've just created. - if {[regexp {num(.*)} $dependency($num) match parent]} { - set dependency($num) $task_item_id($parent) - } + # if there is a numXX as the dependency, then we are relying + # on new tasks that had not been created yet. So we match them + # up with the new tasks we've just created. + if {[regexp {num(.*)} $dependency($num) match parent]} { + set dependency($num) $task_item_id($parent) + } - if {[exists_and_not_null dependency($num)]} { + if {[exists_and_not_null dependency($num)]} { - pm::task::dependency_add \ - -task_item_id $task_item_id($num) \ - -parent_id $dependency($num) \ - -dependency_type finish_before_start \ - -project_item_id $project_item_id($num) + pm::task::dependency_add \ + -task_item_id $task_item_id($num) \ + -parent_id $dependency($num) \ + -dependency_type finish_before_start \ + -project_item_id $project_item_id($num) + } } - } + } on_error { + ad_return_error "[_ project-manager.Error]" "[_ project-manager.There_was_an_error]" + } } - # -------------------------------------------------------------------- # Internet Explorer sucks. It really really does. Due to length limits # on URLs for IE, we have to pass these variables through