gustafn
committed
on 29 May 07
fixing incorrect paranthesis
openacs-4/.../templates/project-ae.tcl (+315)
  1 # --------------------------------------------------------------- #
  2 # the unique identifier for this package
  3 set package_id [ad_conn package_id]
  4 set user_id    [ad_maybe_redirect_for_registration]
  5 set include_url [parameter::get -parameter "ProjectAdd"]
  6
  7 # permissions. Check that user has write permission on the package.
  8 permission::require_permission -party_id $user_id -object_id $package_id -privilege write
  9
  10 # terminology
  11 set project_term    [_ project-manager.Project]
  12 set project_term_lower  [_ project-manager.project]
  13 set use_goal_p  [parameter::get -parameter "UseGoalP" -default "1"]
  14 set use_project_code_p  [parameter::get -parameter "UseUserProjectCodesP" -default "1"]
  15 set ongoing_by_default_p [parameter::get -parameter "OngoingByDefaultP" -default "f"]
  16
  17 # daily?
  18 set daily_p [parameter::get -parameter "UseDayInsteadOfHour" -default "f"]
  19
  20 if {[exists_and_not_null project_item_id] && ![exists_and_not_null project_id]} {
  21     set project_id [pm::project::get_project_id -project_item_id $project_item_id]
  22 }
  23
  24
  25 if {[exists_and_not_null project_id]} {
  26     set title "[_ project-manager.lt_Edit_a_project_term_l]"
  27     set context_bar [ad_context_bar "[_ project-manager.Edit_project_term]"]
  28
  29     # permissions
  30     permission::require_permission -party_id $user_id -object_id $package_id -privilege write
  31
  32 } else {
  33     set title "[_ project-manager.lt_Add_a_project_term_lo]"
  34     set context_bar [ad_context_bar "[_ project-manager.New_project_term]"]
  35
  36     # permissions
  37     permission::require_permission -party_id $user_id -object_id $package_id -privilege create
  38 }
  39
  40
  41 if {[ad_form_new_p -key project_item_id]} {
  42     set logger_project ""
  43     set logger_values ""
  44 } else {
  45    
  46     set logger_project [lindex [application_data_link::get_linked -from_object_id $project_item_id -to_object_type logger_project] 0]
  47     set logger_values [logger::project::get_variables -project_id $logger_project]
  48
  49 }
  50
  51 ad_form -name add_edit \
  52     -form {
  53         project_id:key
  54        
  55         {parent_id:text(hidden)
  56             {value $parent_id}
  57         }
  58         
  59         {project_item_id:text(hidden)
  60             {value $project_item_id}
  61         }
  62
  63         {dform:text(hidden)}
  64         {extra_data:text(hidden),optional}
  65
  66         {project_name:text
  67             {label "[_ project-manager.lt_set_project_term_name]"}
  68             {value $project_name}
  69             {html {size 50}}
  70         }
  71         {ongoing_p:text(hidden)
  72             {value "f"}
  73         }
  74     }
  75
  76
  77 if {$use_project_code_p} {
  78     ad_form -extend -name add_edit \
  79         -form {
  80             {project_code:text,optional
  81                 {label "[_ project-manager.lt_set_project_term_code]"}
  82                 {value $project_code}
  83             }
  84         }
  85 }
  86
  87 ad_form -extend -name add_edit \
  88     -form {
  89         {description:text(textarea),optional
  90             {label "[_ project-manager.Description]"}
  91             {value $description}
  92             {html { rows 5 cols 40 wrap soft}}}
  93        
  94     }
  95
  96
  97 if {[exists_and_not_null customer_id]} {
  98     set customer_name [organizations::name -organization_id $customer_id]
  99     ad_form -extend -name add_edit \
  100         -form {
  101             {customer_id:text(hidden)
  102                 {value $customer_id}
  103             }
  104             {customer_name:text(inform)
  105                 {label "[_ project-manager.Customer]"}
  106                 {values "$customer_name"}
  107             }
  108         }
  109 } else {
  110     ad_form -extend -name add_edit \
  111         -form {
  112             {customer_id:text(select),optional
  113                 {label "[_ project-manager.Customer]"}
  114                 {options {{"[_ project-manager.---_TBD_---]" ""} [lang::util::localize_list_of_lists -list [db_list_of_lists get_customer "select o.name, o.organization_id from organizations o order by o.name"]]}}
  115             }
  116         }
  117 }
  118
  119 ad_form -extend -name add_edit \
  120     -form {
  121         {planned_start_date:text(text)
  122             {label "[_ project-manager.Starts]"}
  123             {html {id sel1}}
  124             {after_html {<input type='reset' value=' ... ' onclick=\"return showCalendar('sel1', 'y-m-d');\"> \[<b>d.m.y </b>\]
  125             }}
  126         }
  127    
  128
  129         {planned_end_date:text(text)
  130             {label "[_ project-manager.Deadline_1]"}
  131             {html {id sel2}}
  132             {after_html {<input type='reset' value=' ... ' onclick=\"return showCalendar('sel2', 'y-m-d');\"> \[<b>d.m.y </b>\]
  133             }}
  134         }
  135     }
  136
  137 #------------------------
  138 # Check if the project will be handled on daily basis or will request hours and minutes
  139 #------------------------
  140
  141 if { $daily_p == "t"} {
  142     ad_form -extend -name add_edit -form {
  143         {planned_end_time:text(hidden)
  144             {value ""}
  145         }
  146     }
  147 } else {
  148     ad_form -extend -name add_edit -form {
  149         {planned_end_time:date
  150             {label "[_ project-manager.Deadline_Time]"}
  151             {value {[template::util::date::now]}}
  152             {format {[lc_get formbuilder_time_format]}}
  153         }
  154     }
  155 }
  156
  157
  158 if {[exists_and_not_null project_id]} {
  159     if {![empty_string_p [category_tree::get_mapped_trees $package_id]]} {
  160         ad_form -extend -name add_edit -form {
  161             {category_ids:integer(category),multiple {label "[_ project-manager.Categories]"}
  162                 {html {size 7}} {value {$project_id $package_id}}
  163             }
  164         }
  165     }
  166 } else {
  167     if {![empty_string_p [category_tree::get_mapped_trees $package_id]]} {
  168         ad_form -extend -name add_edit -form {
  169             {category_ids:integer(category),multiple,optional {label "[_ project-manager.Categories]"}
  170                 {html {size 7}} {value {}}
  171             }
  172         }
  173     }
  174 }
  175
  176 if {[exists_and_not_null customer_id]} {
  177     set dynamic_params(customer_id) $customer_id
  178 } elseif {[exists_and_not_null project_item_id]} {
  179     set dynamic_params(customer_id) [db_string get_customer_id {}]
  180 } else {
  181     set dynamic_params(customer_id) ""
  182 }
  183
  184 dtype::form::add_elements -dform $dform -prefix pm -object_type pm_project -object_id [value_if_exists project_id] -form add_edit -exclude_static -cr_widget none -variables [array get dynamic_params]
  185
  186 ad_form -extend -name add_edit \
  187     -new_request {
  188        
  189         if {[string equal $ongoing_by_default_p t]} {
  190             set ongoing_p t
  191         }
  192         
  193         set planned_end_date [dt_sysdate]
  194         set planned_start_date [dt_sysdate]
  195
  196     } -edit_request {
  197
  198         db_1row project_query {}
  199         set planned_end_time [template::util::date::from_ansi $planned_end_date [lc_get frombuilder_time_format]]
  200         set planned_end_date [lindex $planned_end_date 0]
  201
  202     } -on_submit {
  203        
  204         set user_id [ad_conn user_id]
  205         set peeraddr [ad_conn peeraddr]
  206         set folder_id [pm::util::get_root_folder -package_id $package_id]
  207         set callback_data(organization_id) $customer_id
  208         if {[exists_and_not_null variables]} {
  209             set callback_data(variables) $variables
  210         }
  211         foreach {key value} $extra_data {
  212             set callback_data($key) $value
  213         }
  214
  215         set customer_name [organizations::name -organization_id $customer_id]
  216         if {![empty_string_p $customer_name]} {
  217             append customer_name " - "
  218         }
  219         if {[empty_string_p $parent_id]} {
  220             set parent_id $folder_id
  221         }
  222         set planned_end_date_list [split $planned_end_date "-"]
  223         append planned_end_date_list " [lrange $planned_end_time 3 5]"
  224
  225         set planned_start_date_sql "to_timestamp('$planned_start_date','YYYY MM DD HH24 MI SS')"
  226         set planned_end_date_sql "to_timestamp('$planned_end_date_list','YYYY MM DD HH24 MI SS')"
  227
  228     } -new_data {
  229
  230         db_transaction {
  231             # if the project is ongoing, there is no end date
  232             # we set it to null to signify that. Technically, this
  233             # is bad data model design -- we should just get rid of
  234             # ongoing_p
  235             if {[string equal $ongoing_p t]} {
  236                 set actual_end_date ""
  237                 set planned_end_date ""
  238             }
  239
  240             # create a project manager project
  241             set project_id [dtype::form::process \
  242                                 -dform $dform \
  243                                 -prefix pm \
  244                                 -object_type pm_project \
  245                                 -object_id $project_id \
  246                                 -form add_edit \
  247                                 -cr_widget none \
  248                                 -defaults [list title $project_name description $description mime_type "text/plain" context_id $parent_id parent_id $parent_id object_type pm_project] \
  249                                 -default_fields {project_code goal {planned_start_date $planned_start_date_sql} {planned_end_date $planned_end_date_sql} actual_start_date actual_end_date ongoing_p status_id customer_id dform} \
  250                                 -exclude_static]
  251
  252             set project_item_id [pm::project::get_project_item_id -project_id $project_id]
  253             set project_role [pm::role::default]
  254
  255             pm::project::assign \
  256                 -project_item_id $project_item_id \
  257                 -role_id $project_role \
  258                 -party_id $user_id \
  259                 -send_email_p "f"
  260
  261             if {[exists_and_not_null category_ids]} {
  262                 category::map_object -object_id $project_id $category_ids
  263             }
  264
  265             # We need to check if the group exists before trying to
  266             # give the group privileges
  267             set employees_group_id [group::get_id -group_name "Employees"]
  268             if { ![empty_string_p $employees_group_id] } {
  269                 permission::grant -object_id $project_item_id -party_id $employees_group_id -privilege admin
  270             }
  271
  272             callback pm::project_new -package_id $package_id -project_id $project_item_id -data [array get callback_data]
  273         }
  274
  275     } -edit_data {
  276
  277         db_transaction {
  278             # we need to pass the old_project_id to add-edit-2.tcl because
  279             # the new revision will not have any of the custom values in
  280             # it until it is edited. So we need to pull in these values
  281             set old_project_id $project_id
  282
  283             set project_id [dtype::form::process \
  284                                 -dform $dform \
  285                                 -prefix pm \
  286                                 -object_type pm_project \
  287                                 -object_id $project_id \
  288                                 -form add_edit \
  289                                 -cr_widget none \
  290                                 -defaults [list title $project_name description $description mime_type "text/plain" context_id $parent_id parent_id $parent_id object_type pm_project] \
  291                                 -default_fields {project_code goal {planned_start_date $planned_start_date_sql} {planned_end_date $planned_end_date_sql} actual_start_date actual_end_date ongoing_p status_id customer_id dform} \
  292                                 -exclude_static]
  293
  294             set project_item_id [pm::project::get_project_item_id -project_id $project_id]
  295
  296             if {[exists_and_not_null category_ids]} {
  297                 category::map_object -object_id $project_id $category_ids
  298             }
  299             callback pm::project_edit -package_id $package_id -project_id $project_item_id -data [array get callback_data]
  300         }
  301
  302     } -after_submit {
  303
  304         ad_returnredirect -message "[_ project-manager.lt_Changes_to_project_sa]" "one?[export_url_vars project_id]"
  305         # to add back in subproject support, should use
  306         # compute_parent_status
  307         if { [parameter::get -parameter  UseDayInsteadOfHour -default f]} {
  308             pm::project::compute_status $project_item_id
  309         } else {
  310             pm::project::compute_status_mins $project_item_id
  311         }
  312         ad_script_abort
  313 }
  314
  315 ad_return_template "../templates/project-ae"