Index: openacs-4/packages/logger/tcl/package-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/logger/tcl/package-procs.tcl,v diff -u -r1.3 -r1.4 --- openacs-4/packages/logger/tcl/package-procs.tcl 25 Apr 2003 09:47:11 -0000 1.3 +++ openacs-4/packages/logger/tcl/package-procs.tcl 1 May 2003 14:14:33 -0000 1.4 @@ -51,7 +51,7 @@ } ad_proc -public logger::package::variables_multirow { - {not_in_project_id ""} + {-not_in_project_id ""} } { Executes a db_multirow that returns all variables created in the current package and all variables mapped to projects @@ -64,6 +64,7 @@ @author Peter Marklund } { set package_id [ad_conn package_id] + set user_id [ad_conn user_id] if { ![empty_string_p $not_in_project_id] } { set extra_where_clause \ Index: openacs-4/packages/logger/tcl/package-procs.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/logger/tcl/package-procs.xql,v diff -u -r1.2 -r1.3 --- openacs-4/packages/logger/tcl/package-procs.xql 22 Apr 2003 09:25:40 -0000 1.2 +++ openacs-4/packages/logger/tcl/package-procs.xql 1 May 2003 14:14:33 -0000 1.3 @@ -25,24 +25,4 @@ - - - select lv.variable_id, - lv.name, - lv.unit, - lv.type - from logger_variables lv - where (exists (select 1 - from logger_project_var_map lpvm, - logger_project_pkg_map lppm - where lv.variable_id = lpvm.variable_id - and lpvm.project_id = lppm.project_id - and lppm.package_id = :package_id - ) - or lv.package_id = :package_id - or lv.package_id is null) - $extra_where_clause - - - Index: openacs-4/packages/logger/tcl/project-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/logger/tcl/project-procs.tcl,v diff -u -r1.5 -r1.6 --- openacs-4/packages/logger/tcl/project-procs.tcl 1 May 2003 10:00:24 -0000 1.5 +++ openacs-4/packages/logger/tcl/project-procs.tcl 1 May 2003 14:14:33 -0000 1.6 @@ -138,7 +138,7 @@ db_1row select_project {} -column_array project_array } -ad_proc -public logger::project::add_variable { +ad_proc -public logger::project::map_variable { {-project_id:required} {-variable_id:required} {-primary_p ""} @@ -169,14 +169,14 @@ if { $exists_primary_p } { # There is already a primary_p variable so the new one can't be if { [string equal $primary_p "t"] } { - error "logger::project::add_variable - invoked with primary_p argument set to t but project $project_id already has a primary_p variable" + error "logger::project::map_variable - invoked with primary_p argument set to t but project $project_id already has a primary_p variable" } set primary_p f } else { # There is no primary_p variable so the new one must be if { [string equal $primary_p "f"] } { - error "logger::project::add_variable - invoked with primary_p argument set to f but project $project_id has no primary_p variable and must have one" + error "logger::project::map_variable - invoked with primary_p argument set to f but project $project_id has no primary_p variable and must have one" } set primary_p t @@ -185,6 +185,52 @@ db_dml insert_mapping {} } +ad_proc -public logger::project::unmap_variable { + {-project_id:required} + {-variable_id:required} +} { + Disable logging in a certain variable for a project. Unmapping a primary + variable is not a permissible operation and this proc will throw an error + in that case. + + @param project_id The id of the project we are mapping the variable with + @param variable_id The id of the variable to map + + @return The return value of db_dml + + @author Peter Marklund +} { + # Check that this is not an attempt to delete the primary variable + set primary_variable_id [logger::project::get_primary_variable -project_id $project_id] + if { [string equal $primary_variable_id $variable_id] } { + error "logger::project::unmap_variable - Cannot unmap variable $variable_id as it is primary to project $project_id" + } + + db_dml delete_mapping {} +} + +ad_proc -public logger::project::set_primary_variable { + {-project_id:required} + {-variable_id:required} +} { + Change primary variable of a project. Every project has one primary variable + (if it has any at all) and this is by default the first variable associated + with the project. The administrator of the project is offered the possibility + of changing primary variable through this proc. + + @param project_id The id of the project to change primary variable for + @param variable_id The id of the variable that is to be the new + primary variable of the project. + + @return The return value of db_dml + + @author Peter Marklund +} { + db_dml clear_old {} + + db_dml update_new {} +} + ad_proc -public logger::project::get_variables { {-project_id:required} } { Index: openacs-4/packages/logger/tcl/project-procs.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/logger/tcl/project-procs.xql,v diff -u -r1.4 -r1.5 --- openacs-4/packages/logger/tcl/project-procs.xql 22 Apr 2003 09:25:40 -0000 1.4 +++ openacs-4/packages/logger/tcl/project-procs.xql 1 May 2003 14:14:33 -0000 1.5 @@ -14,15 +14,40 @@ - + insert into logger_project_var_map (project_id, variable_id, primary_p) values (:project_id, :variable_id, :primary_p) - + + delete from logger_project_var_map + where project_id = :project_id + and variable_id = :variable_id + + + + + + update logger_project_var_map + set primary_p = 'f' + where project_id = :project_id + + + + + + update logger_project_var_map + set primary_p = 't' + where project_id = :project_id + and variable_id = :variable_id + + + + + select count(*) from logger_project_var_map where project_id = :project_id Index: openacs-4/packages/logger/tcl/ui-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/logger/tcl/ui-procs.tcl,v diff -u -r1.2 -r1.3 --- openacs-4/packages/logger/tcl/ui-procs.tcl 1 May 2003 07:19:41 -0000 1.2 +++ openacs-4/packages/logger/tcl/ui-procs.tcl 1 May 2003 14:14:33 -0000 1.3 @@ -21,9 +21,17 @@

A link is considered selected if the current page url starts with the url of the link - and each HTML parameter in the param_list has the specified value. + and each HTML parameter in the param_list has the specified value. If the param_list + is empty then the query string of the request must be empty for the link to be + considered selected.

+ @param navbar_url The url relative page root of the link + @param param_list A list of URL parameters and their values on the format + [list [list param_name1 param_value1] [list param_name2 param_value2]] + + @return 1 if the navbar link should be selected and 0 otherwise + @author Peter Marklund } { # Let's remove any trailing slash and make it optional in our pattern Index: openacs-4/packages/logger/tcl/variable-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/logger/tcl/variable-procs.tcl,v diff -u -r1.5 -r1.6 --- openacs-4/packages/logger/tcl/variable-procs.tcl 1 May 2003 10:00:24 -0000 1.5 +++ openacs-4/packages/logger/tcl/variable-procs.tcl 1 May 2003 14:14:33 -0000 1.6 @@ -18,7 +18,7 @@ } { Create a new variable to use for logger entries. The variable can be tied to logger projects through the - logger::project::add_variable proc. + logger::project::map_variable proc. @param variable_id Any pre-generated id of the variable. Optional. @param name The name of the new variable. Required. @@ -44,6 +44,14 @@ set variable_id [db_exec_plsql insert_variable {}] + if { $pre_installed_p } { + # Registered users should have read privilege on pre-installed variables + permission::grant \ + -party_id [acs_magic_object registered_users] \ + -object_id $variable_id \ + -privilege read + } + return $variable_id } Index: openacs-4/packages/logger/tcl/test/logger-test-init.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/logger/tcl/test/logger-test-init.tcl,v diff -u -r1.6 -r1.7 --- openacs-4/packages/logger/tcl/test/logger-test-init.tcl 1 May 2003 10:00:47 -0000 1.6 +++ openacs-4/packages/logger/tcl/test/logger-test-init.tcl 1 May 2003 14:15:28 -0000 1.7 @@ -78,22 +78,22 @@ set hours_var_id [logger::variable::new -name $hours_var(name) \ -unit $hours_var(unit) \ -type $hours_var(type)] - logger::project::add_variable -project_id $project_id \ + logger::project::map_variable -project_id $project_id \ -variable_id $hours_var_id # Create and map the minutes variable # (variate by pre-generating the variable id this time) set minutes_var_id [logger::variable::new -name $minutes_var(name) \ -unit $minutes_var(unit) \ -type $minutes_var(type)] - logger::project::add_variable -project_id $project_id \ + logger::project::map_variable -project_id $project_id \ -variable_id $minutes_var_id # Create and map the expense variable (euros) set expense_var_id [logger::variable::new -name $expense_var(name) \ -unit $expense_var(unit) \ -type $expense_var(type)] - logger::project::add_variable -project_id $project_id \ + logger::project::map_variable -project_id $project_id \ -variable_id $expense_var_id # Assert that variables are retrievable Index: openacs-4/packages/logger/www/admin/index.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/logger/www/admin/index.adp,v diff -u -r1.2 -r1.3 --- openacs-4/packages/logger/www/admin/index.adp 1 May 2003 07:20:58 -0000 1.2 +++ openacs-4/packages/logger/www/admin/index.adp 1 May 2003 14:16:18 -0000 1.3 @@ -21,7 +21,8 @@ [ delete ] + onclick="return confirm('Are you sure you want to delete project @projects.name@?');">delete | + permissions ] @projects.name@ @@ -49,13 +50,20 @@ + + @@ -72,4 +80,9 @@

Add new variable

- \ No newline at end of file + +

Package

+

+ Set permissions of this package +

+ Index: openacs-4/packages/logger/www/admin/index.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/logger/www/admin/index.tcl,v diff -u -r1.2 -r1.3 --- openacs-4/packages/logger/www/admin/index.tcl 1 May 2003 07:20:58 -0000 1.2 +++ openacs-4/packages/logger/www/admin/index.tcl 1 May 2003 14:16:18 -0000 1.3 @@ -12,10 +12,34 @@ set home_url [ad_parameter -package_id [ad_acs_kernel_id] HomeURL] -db_multirow projects select_projects {} { +set application_url [ad_conn url] +set permissions_uri "/permissions/one" + +db_multirow -extend { permissions_url } projects select_projects {} { set description [string_truncate -len 50 $description] + set permissions_url "${permissions_uri}?[export_vars {{object_id $project_id} application_url}]" } -logger::package::variables_multirow +db_multirow -extend { permissions_url } variables select_variables { + select lv.variable_id, + lv.name, + lv.unit, + lv.type, + acs_permission.permission_p(lv.variable_id, :user_id, 'admin') as admin_p + from logger_variables lv + where (exists (select 1 + from logger_project_var_map lpvm, + logger_project_pkg_map lppm + where lv.variable_id = lpvm.variable_id + and lpvm.project_id = lppm.project_id + and lppm.package_id = :package_id + ) + or lv.package_id = :package_id + or lv.package_id is null) +} { + set permissions_url "${permissions_uri}?[export_vars {{object_id $variable_id} application_url}]" +} +set package_permissions_url "${permissions_uri}?[export_vars {{object_id $package_id} application_url}]" + ad_return_template Index: openacs-4/packages/logger/www/admin/map-variable-to-project-2.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/logger/www/admin/map-variable-to-project-2.tcl,v diff -u -r1.1 -r1.2 --- openacs-4/packages/logger/www/admin/map-variable-to-project-2.tcl 22 Apr 2003 09:27:03 -0000 1.1 +++ openacs-4/packages/logger/www/admin/map-variable-to-project-2.tcl 1 May 2003 14:16:18 -0000 1.2 @@ -9,6 +9,6 @@ variable_id:integer } -logger::project::add_variable -project_id $project_id -variable_id $variable_id +logger::project::map_variable -project_id $project_id -variable_id $variable_id ad_returnredirect "project?project_id=$project_id" Index: openacs-4/packages/logger/www/admin/map-variable-to-project.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/logger/www/admin/map-variable-to-project.adp,v diff -u -r1.1 -r1.2 --- openacs-4/packages/logger/www/admin/map-variable-to-project.adp 22 Apr 2003 09:27:03 -0000 1.1 +++ openacs-4/packages/logger/www/admin/map-variable-to-project.adp 1 May 2003 14:16:18 -0000 1.2 @@ -11,5 +11,7 @@ - There are no variables in this package that are not already added to the project +

+ You do not have access to any variables that are not already added to the project +

Index: openacs-4/packages/logger/www/admin/map-variable-to-project.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/logger/www/admin/map-variable-to-project.tcl,v diff -u -r1.1 -r1.2 --- openacs-4/packages/logger/www/admin/map-variable-to-project.tcl 22 Apr 2003 09:27:03 -0000 1.1 +++ openacs-4/packages/logger/www/admin/map-variable-to-project.tcl 1 May 2003 14:16:18 -0000 1.2 @@ -14,17 +14,4 @@ set context [list $page_title] # List all variables not already mapped to the project -logger::package::variables_multirow $project_id - -db_multirow variables variables_to_map { - select variable_id, - name, - unit, - type - from logger_variables lv - where not exists (select 1 - from logger_project_var_map - where project_id = :project_id - and variable_id = lv.variable_id - ) -} +logger::package::variables_multirow -not_in_project_id $project_id Index: openacs-4/packages/logger/www/admin/project.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/logger/www/admin/project.tcl,v diff -u -r1.3 -r1.4 --- openacs-4/packages/logger/www/admin/project.tcl 30 Apr 2003 12:21:16 -0000 1.3 +++ openacs-4/packages/logger/www/admin/project.tcl 1 May 2003 14:16:18 -0000 1.4 @@ -9,26 +9,33 @@ } set package_id [ad_conn package_id] +set user_id [ad_conn user_id] -if { ![empty_string_p [ns_set iget [rp_getform] formbutton:done_button]] } { +if { [string equal [form get_action project_form] "done"] } { # User is done editing - redirect back to index page - ad_returnredirect index + ad_returnredirect . ad_script_abort } if { [exists_and_not_null project_id] } { # Initial request in display or edit mode or a submit of the form set page_title "One Project" set ad_form_mode display + set project_exists_p [db_string project_exists_p { + select count(*) + from logger_projects + where project_id = :project_id + }] } else { # Initial request in add mode set page_title "Add a Project" set ad_form_mode edit + set project_exists_p 0 } set context [list $page_title] -set actions_list [list [list Edit "formbuilder::edit"] [list Done done_button]] +set actions_list [list [list Edit "formbuilder::edit"] [list Done done]] ad_form -name project_form \ -cancel_url index \ -mode $ad_form_mode \ @@ -46,30 +53,60 @@ } } -if { [exists_and_not_null project_id] } { +if { $project_exists_p } { # We are in edit or display mode # Display the variables linked to this project set variables_list [list] set variables_text "" db_foreach variables_in_project { select lv.variable_id, - lv.name + lv.name, + lpvm.primary_p from logger_project_var_map lpvm, logger_variables lv where lpvm.variable_id = lv.variable_id and lpvm.project_id = :project_id } { - lappend variables_list "$name" + set variable_link "$name" + if { [string equal $primary_p "f"] } { + append variable_link "   \[ unmap | make primary \]" + } else { + append variable_link " (primary)" + } + + lappend variables_list $variable_link } if { [llength $variables_list] != 0 } { - set variables_text [join $variables_list ", "] + set variables_text "
  • [join $variables_list "

  • "]

" } else { set variables_text "no variables" } - append variables_text "  \[add variable\]" + set n_can_be_mapped [db_string n_can_be_mapped { + select count(*) + from logger_variables lv + where (exists (select 1 + from logger_project_var_map lpvm, + logger_project_pkg_map lppm + where lv.variable_id = lpvm.variable_id + and lpvm.project_id = lppm.project_id + and lppm.package_id = :package_id + ) + or lv.package_id = :package_id + or lv.package_id is null) + and not exists (select 1 + from logger_project_var_map lpvm + where lpvm.project_id = :project_id + and lpvm.variable_id = lv.variable_id + ) + and acs_permission.permission_p(lv.variable_id, :user_id, 'read') = 't' + }] + if { $n_can_be_mapped > 0 } { + append variables_text "

\[add variable\]

" + } + ad_form -extend -name project_form -form { {variables:text(inform) {label Variables} Index: openacs-4/packages/logger/www/admin/variable.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/logger/www/admin/variable.tcl,v diff -u -r1.2 -r1.3 --- openacs-4/packages/logger/www/admin/variable.tcl 30 Apr 2003 12:21:16 -0000 1.2 +++ openacs-4/packages/logger/www/admin/variable.tcl 1 May 2003 14:16:18 -0000 1.3 @@ -10,6 +10,12 @@ set package_id [ad_conn package_id] +if { [string equal [form get_action variable_form] "done"] } { + # User is done editing - redirect back to index page + ad_returnredirect . + ad_script_abort +} + if { [exists_and_not_null variable_id] } { # Initial request in display or edit mode or a submit of the form set page_title "One variable" @@ -22,7 +28,8 @@ set context [list $page_title] -ad_form -name variable_form -cancel_url index -mode $ad_form_mode -form { +set actions_list [list [list Edit "formbuilder::edit"] [list Done done]] +ad_form -name variable_form -cancel_url index -mode $ad_form_mode -actions $actions_list -form { variable_id:key(acs_object_id_seq) {name:text
  Name Unit Additive
+ [ delete | + permissions ] + + @variables.name@ @variables.unit@ yesno