Index: openacs-4/packages/new-portal/tcl/portal-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/new-portal/tcl/portal-procs.tcl,v diff -u -r1.110 -r1.111 --- openacs-4/packages/new-portal/tcl/portal-procs.tcl 28 Jan 2002 19:12:03 -0000 1.110 +++ openacs-4/packages/new-portal/tcl/portal-procs.tcl 30 Jan 2002 22:11:22 -0000 1.111 @@ -2,7 +2,7 @@ ad_library { Portal. - + @author Arjun Sanyal (arjun@openforce.net) @creation-date Sept 2001 @cvs-id $Id$ @@ -15,42 +15,42 @@ # ad_proc -public datasource_call { - ds_id - op - list_args + ds_id + op + list_args } { - Call a particular ds op + Call a particular ds op } { - ns_log notice "portal::datasource_call op= $op ds_id = $ds_id" - return [acs_sc_call \ + ns_log notice "portal::datasource_call op= $op ds_id = $ds_id" + return [acs_sc_call \ portal_datasource $op $list_args [get_datasource_name $ds_id]] } ad_proc -public list_datasources { - {portal_id ""} + {portal_id ""} } { - Lists the datasources available to a portal or in general + Lists the datasources available to a portal or in general } { - if {[empty_string_p $portal_id]} { - # List all applets - return [db_list select_all_datasources {}] - } else { - # List from the DB - return [db_list select_datasources {}] - } + if {[empty_string_p $portal_id]} { + # List all applets + return [db_list select_all_datasources {}] + } else { + # List from the DB + return [db_list select_datasources {}] + } } ad_proc -public datasource_dispatch { - portal_id - op - list_args + portal_id + op + list_args } { - Dispatch an operation to every datasource + Dispatch an operation to every datasource } { - foreach datasource [list_datasources $portal_id] { - # Callback on datasource - datasource_call $datasource $op $list_args - } + foreach datasource [list_datasources $portal_id] { + # Callback on datasource + datasource_call $datasource $op $list_args + } } @@ -61,7 +61,7 @@ # The mangement is not responsible for the results of multi-mounting ad_proc -private package_key {} { - Returns the package_key + Returns the package_key } { return "new-portal" } @@ -74,14 +74,14 @@ # Work around for template::util::url_to_file ad_proc -private www_path {} { - Returns the path of the www dir of the portal package. We + Returns the path of the www dir of the portal package. We need this for stupid template tricks. } { return "/packages/[package_key]/www" } ad_proc -public mount_point {} { - Returns the mount point of the portal package. + Returns the mount point of the portal package. Sometimes we need to know this for like ing templates from tcl } { @@ -93,26 +93,26 @@ ad_proc -public automount_point {} { packages such as dotlrn can automount the portal here } { return "/portal" } - + # # Main portal procs # ad_proc -public create { - {-name "Untitled"} - {-template_id ""} - {-portal_template_p "f"} - {-layout_name ""} + {-name "Untitled"} + {-template_id ""} + {-portal_template_p "f"} + {-layout_name ""} {-theme_name ""} - {-default_page_name ""} - {-context_id ""} - user_id + {-default_page_name ""} + {-context_id ""} + user_id } { - Create a new portal for the passed in user id. - - @return The newly created portal's id - @param user_id - @param layout_name optional + Create a new portal for the passed in user id. + + @return The newly created portal's id + @param user_id + @param layout_name optional } { # get the default layout_id - simple2 if {![empty_string_p $layout_name]} { @@ -129,39 +129,39 @@ set theme_id [get_theme_id_from_name -theme_name $theme_name] - return [db_exec_plsql create_new_portal_and_perms {}] + return [db_exec_plsql create_new_portal_and_perms {}] } - + ad_proc -public delete { portal_id } { - Destroy the portal - @param portal_id + Destroy the portal + @param portal_id } { - # XXX todo permissions should be portal_delete_portal - # XXX remove permissions (this sucks - ben) - db_dml delete_perms {} - - return [db_exec_plsql delete_portal {}] + # XXX todo permissions should be portal_delete_portal + # XXX remove permissions (this sucks - ben) + db_dml delete_perms {} + + return [db_exec_plsql delete_portal {}] } - + ad_proc -public get_name { portal_id } { - Get the name of this portal - - @param portal_id - @return the name of the portal or null string + Get the name of this portal + + @param portal_id + @return the name of the portal or null string } { - ad_require_permission $portal_id portal_read_portal - - if {[portal::exists_p $portal_id]} { - return [db_1row get_name_select {}] - } else { - return "" - } + ad_require_permission $portal_id portal_read_portal + + if {[portal::exists_p $portal_id]} { + return [db_1row get_name_select {}] + } else { + return "" + } } - + ad_proc -public render { {-page_id ""} {-page_num ""} @@ -170,48 +170,48 @@ portal_id {theme_id ""} } { - Get a portal by id. If it's not found, say so. - FIXME: right now the render style is totally ignored (ben) + Get a portal by id. If it's not found, say so. + FIXME: right now the render style is totally ignored (ben) - @return Fully rendered portal as an html string - @param portal_id + @return Fully rendered portal as an html string + @param portal_id } { - ad_require_permission $portal_id portal_read_portal + ad_require_permission $portal_id portal_read_portal - set edit_p [ad_permission_p $portal_id portal_edit_portal] - set master_template [ad_parameter master_template] - set css_path [ad_parameter css_path] - + set edit_p [ad_permission_p $portal_id portal_edit_portal] + set master_template [ad_parameter master_template] + set css_path [ad_parameter css_path] + # if no page_num set, render page 0 if {[empty_string_p $page_id] && [empty_string_p $page_num]} { set page_id [get_page_id -portal_id $portal_id -sort_key 0] } elseif {![empty_string_p $page_num]} { set page_id [get_page_id -portal_id $portal_id -sort_key $page_num] } - # get the portal and layout - db_1row portal_select {} -column_array portal + # get the portal and layout + db_1row portal_select {} -column_array portal - # theme_id override - if { $theme_id != "" } { set portal(theme_id) $theme_id } + # theme_id override + if { $theme_id != "" } { set portal(theme_id) $theme_id } - db_foreach element_select {} -column_array entry { - # put the element IDs into buckets by region... - lappend element_ids($entry(region)) $entry(element_id) - } if_no_rows { - set element_ids {} - } + db_foreach element_select {} -column_array entry { + # put the element IDs into buckets by region... + lappend element_ids($entry(region)) $entry(element_id) + } if_no_rows { + set element_ids {} + } - set element_list [array get element_ids] + set element_list [array get element_ids] - # set up the template, it includes the layout template, - # which in turn includes the theme, then elements - if { [empty_string_p $element_list] } { - # The portal has no elements, show anyway (they can configure) - set template " - @portal.name@" - } else { + # set up the template, it includes the layout template, + # which in turn includes the theme, then elements + if { [empty_string_p $element_list] } { + # The portal has no elements, show anyway (they can configure) + set template " + @portal.name@" + } else { set element_src "[www_path]/render_styles/${render_style}/render-element" set template " @portal.name@ @@ -222,46 +222,46 @@ portal_id=@portal.portal_id@ hide_links_p=@hide_links_p@ page_id=@page_id@ layout_id=@portal.layout_id@>" - } - - # Necessary hack to work around the acs-templating system - set __adp_stub "[get_server_root][www_path]/." - set {master_template} \"master\" - - # Compile and evaluate the template - set code [template::adp_compile -string $template] - set output [template::adp_eval code] - - return $output + } + + # Necessary hack to work around the acs-templating system + set __adp_stub "[get_server_root][www_path]/." + set {master_template} \"master\" + + # Compile and evaluate the template + set code [template::adp_compile -string $template] + set output [template::adp_eval code] + + return $output } ad_proc -private layout_elements { - element_list - {var_stub "element_ids"} + element_list + {var_stub "element_ids"} } { - Split a list up into a bunch of variables for inserting into a - layout template. This seems pretty kludgy (probably because it is), - but a template::multirow isn't really well suited to data of this - shape. It'll setup a set of variables, $var_stub_1 - $var_stub_8 - and $var_stub_i1- $var_stub_i8, each contining the portal_ids that - belong in that region. - Ian Baker + Split a list up into a bunch of variables for inserting into a + layout template. This seems pretty kludgy (probably because it is), + but a template::multirow isn't really well suited to data of this + shape. It'll setup a set of variables, $var_stub_1 - $var_stub_8 + and $var_stub_i1- $var_stub_i8, each contining the portal_ids that + belong in that region. - Ian Baker - @param element_id_list An [array get]'d array, keys are regions, \ - values are lists of element_ids. - @param var_stub A name upon which to graft the bits that will be \ - passed to the template. + @param element_id_list An [array get]'d array, keys are regions, \ + values are lists of element_ids. + @param var_stub A name upon which to graft the bits that will be \ + passed to the template. } { - array set elements $element_list - - foreach idx [list 1 2 3 4 5 6 7 8 9 i1 i2 i3 i4 i5 i6 i7 i8 i9 ] { - upvar [join [list $var_stub "_" $idx] ""] group - if { [info exists elements($idx) ] } { - set group $elements($idx) - } else { - set group {} - } - } + array set elements $element_list + + foreach idx [list 1 2 3 4 5 6 7 8 9 i1 i2 i3 i4 i5 i6 i7 i8 i9 ] { + upvar [join [list $var_stub "_" $idx] ""] group + if { [info exists elements($idx) ] } { + set group $elements($idx) + } else { + set group {} + } + } } # @@ -271,54 +271,54 @@ ad_proc -private update_name { portal_id new_name } { - Update the name of this portal - - @param portal_id - @param new_name + Update the name of this portal + + @param portal_id + @param new_name } { - - ad_require_permission $portal_id portal_read_portal - ad_require_permission $portal_id portal_edit_portal - - db_dml update {} + + ad_require_permission $portal_id portal_read_portal + ad_require_permission $portal_id portal_edit_portal + + db_dml update {} } - + ad_proc -public configure { {-page_id ""} {-template_p "f"} portal_id return_url } { - Return a portal or portal template configuration page. - All form targets point to file_stub-2. + Return a portal or portal template configuration page. + All form targets point to file_stub-2. XXX BRUTALLY REFACTOR ME - - @param page_num the page of the portal to config, def 0 - @param template_p is this portal a template? - @param portal_id - @return_url - @return A portal configuration page + + @param page_num the page of the portal to config, def 0 + @param template_p is this portal a template? + @param portal_id + @return_url + @return A portal configuration page } { - if { $template_p == "f" } { + if { $template_p == "f" } { ad_require_permission $portal_id portal_read_portal ad_require_permission $portal_id portal_edit_portal } else { ad_require_permission $portal_id portal_admin_portal } - - # Set up some template vars, including the form target - set master_template [ad_parameter master_template] - set target_stub [lindex [ns_conn urlv] [expr [ns_conn urlc] - 1]] - set action_string [append target_stub "-2"] - set name [get_name $portal_id] + # Set up some template vars, including the form target + set master_template [ad_parameter master_template] + set target_stub [lindex [ns_conn urlv] [expr [ns_conn urlc] - 1]] + set action_string [append target_stub "-2"] + set name [get_name $portal_id] + # get the themes, template::multirow is not working here set theme_count 0 set theme_data "
" - + db_1row current_theme_select {} db_foreach all_theme_select {} { @@ -331,7 +331,7 @@ value=$theme_id>$name - $description
" } } - + append theme_data "" # set up the page creation stuff @@ -341,18 +341,18 @@ "
" - + # XXXX page support if { $template_p == "f" } { set element_src "[portal::www_path]/place-element" } else { set element_src "[portal::www_path]/template-place-element" } - + set portal_name [get_name $portal_id] - set template " + set template " Configuring @portal_name@

@@ -383,25 +383,25 @@ foreach page_id $list_of_page_ids { - # get the portal. + # get the portal. db_1row portal_select {} -column_array portal # get the numer of elements in this region set element_count [db_string portal_element_count_select " select count(*) from portal_element_map where page_id = :page_id"] - + # fake some elements for the in the template set layout_id [get_layout_id -page_id $page_id $portal_id] - + db_foreach get_regions {} { lappend fake_element_ids($region) $portal_id } - + set element_list [array get fake_element_ids] - + if {$element_count == 0} { append template "

Page $portal(page_name) has no Elements" @@ -414,70 +414,70 @@ hide_links_p=f page_id=$page_id layout_id=$layout_id> " } - + # clear out the region array array unset fake_element_ids } - # This hack is to work around the acs-templating system - set __adp_stub "[get_server_root][www_path]/." - set {master_template} \"master\" - - set code [template::adp_compile -string $template] - set output [template::adp_eval code] - - return $output + # This hack is to work around the acs-templating system + set __adp_stub "[get_server_root][www_path]/." + set {master_template} \"master\" + + set code [template::adp_compile -string $template] + set output [template::adp_eval code] + + return $output } - + ad_proc -public configure_dispatch { {-template_p "f"} portal_id form } { - Dispatches the configuration operation. - We get the target region number from the op. - - @param portal_id - @param formdata an ns_set with all the formdata + Dispatches the configuration operation. + We get the target region number from the op. + + @param portal_id + @param formdata an ns_set with all the formdata } { - - ad_require_permission $portal_id portal_read_portal - ad_require_permission $portal_id portal_edit_portal - - set op [ns_set get $form op] - switch $op { - "Rename" { - portal::update_name $portal_id [ns_set get $form new_name] - } - "swap" { - portal::swap_element $portal_id \ - [ns_set get $form element_id] \ - [ns_set get $form sort_key] \ - [ns_set get $form region] \ - [ns_set get $form direction] - } - "move" { - portal::move_element $portal_id \ - [ns_set get $form element_id] \ - [ns_set get $form region] \ - [ns_set get $form direction] - } - "Show Here" { - set region [ns_set get $form region] - set element_id [ns_set get $form element_id] - set page_id [ns_set get $form page_id] - - db_transaction { - # The new element's sk will be the last in the region - db_dml show_here_update_sk {} - db_dml show_here_update_state {} - } - } + ad_require_permission $portal_id portal_read_portal + ad_require_permission $portal_id portal_edit_portal + + set op [ns_set get $form op] + + switch $op { + "Rename" { + portal::update_name $portal_id [ns_set get $form new_name] + } + "swap" { + portal::swap_element $portal_id \ + [ns_set get $form element_id] \ + [ns_set get $form sort_key] \ + [ns_set get $form region] \ + [ns_set get $form direction] + } + "move" { + portal::move_element $portal_id \ + [ns_set get $form element_id] \ + [ns_set get $form region] \ + [ns_set get $form direction] + } + "Show Here" { + set region [ns_set get $form region] + set element_id [ns_set get $form element_id] + set page_id [ns_set get $form page_id] + + db_transaction { + # The new element's sk will be the last in the region + db_dml show_here_update_sk {} + db_dml show_here_update_state {} + } + } "move_to_page" { - set page_id [ns_set get $form page_id] - set element_id [ns_set get $form element_id] + set page_id [ns_set get $form page_id] + set element_id [ns_set get $form element_id] set curr_reg [db_string move_to_page_curr_select {}] set target_reg_num [db_string move_to_page_target_select {}] @@ -489,70 +489,70 @@ } db_dml move_to_page_update {} - } - "hide" { - set element_id_list [list] - - # iterate through the set, destructive! - while { [expr [ns_set find $form "element_id"] + 1 ] } { - lappend element_id_list [ns_set get $form "element_id"] - ns_set delkey $form "element_id" - } - - if {! [empty_string_p $element_id_list] } { - foreach element_id $element_id_list { - db_dml hide_update {} - } - } - } - "Change Theme" { - set theme_id [ns_set get $form theme_id] - - db_dml update_theme {} - } - "Add Page" { - set pretty_name [ns_set get $form pretty_name] + } + "hide" { + set element_id_list [list] + + # iterate through the set, destructive! + while { [expr [ns_set find $form "element_id"] + 1 ] } { + lappend element_id_list [ns_set get $form "element_id"] + ns_set delkey $form "element_id" + } + + if {! [empty_string_p $element_id_list] } { + foreach element_id $element_id_list { + db_dml hide_update {} + } + } + } + "Change Theme" { + set theme_id [ns_set get $form theme_id] + + db_dml update_theme {} + } + "Add Page" { + set pretty_name [ns_set get $form pretty_name] if {[empty_string_p $pretty_name]} { ad_return_complaint 1 "You must enter a name for the new page." } page_create -pretty_name $pretty_name -portal_id $portal_id - } - "toggle_pinned" { - set element_id [ns_set get $form element_id] + } + "toggle_pinned" { + set element_id [ns_set get $form element_id] - if {[db_string toggle_pinned_select {}] == "full"} { - + if {[db_string toggle_pinned_select {}] == "full"} { + db_dml toggle_pinned_update_pin {} # "pinned" implies not user hideable, shadable - set_element_param $element_id "hideable_p" "f" - set_element_param $element_id "shadeable_p" "f" - - } else { - db_dml toggle_pinned_update_unpin {} - } - } - "toggle_hideable" { - set element_id [ns_set get $form element_id] + set_element_param $element_id "hideable_p" "f" + set_element_param $element_id "shadeable_p" "f" + + } else { + db_dml toggle_pinned_update_unpin {} + } + } + "toggle_hideable" { + set element_id [ns_set get $form element_id] toggle_element_param -element_id $element_id -key "hideable_p" - } - "toggle_shadeable" { - set element_id [ns_set get $form element_id] + } + "toggle_shadeable" { + set element_id [ns_set get $form element_id] toggle_element_param -element_id $element_id -key "shadeable_p" } - "update_layout" { - ns_log Error \ - "portal::config_dispatch: Bad op = $op!" - ad_return_complaint 1 \ - "portal::config_dispatch: Not implimented op = $op" - } - default { - ns_log Error \ - "portal::config_dispatch: Bad op = $op!" - ad_return_complaint 1 \ - "portal::config_dispatch: Bad Op! \n op $op" - } - } + "update_layout" { + ns_log Error \ + "portal::config_dispatch: Bad op = $op!" + ad_return_complaint 1 \ + "portal::config_dispatch: Not implimented op = $op" + } + default { + ns_log Error \ + "portal::config_dispatch: Bad op = $op!" + ad_return_complaint 1 \ + "portal::config_dispatch: Bad Op! \n op $op" + } + } } @@ -562,41 +562,41 @@ ad_proc -private template_p { portal_id } { - Check if a portal is a portal template and not a user poral + Check if a portal is a portal template and not a user poral } { return [db_0or1row select {}] } ad_proc -private get_portal_template_id { portal_id } { - Returns this portal's template_id or the null string if it + Returns this portal's template_id or the null string if it doesn't have a portal template } { - if { [db_0or1row select {}] } { - return $template_id - } else { - return "" - } + if { [db_0or1row select {}] } { + return $template_id + } else { + return "" + } } ad_proc -public template_configure { portal_id return_url } { Just a wrapper for the configure proc - - @param portal_id - @return A portal configuration page + + @param portal_id + @return A portal configuration page } { - if { ! [template_p $portal_id] } { + if { ! [template_p $portal_id] } { ns_log error "portal::template_configure called with portal_id $portal_id!" - ad_return_complaint 1 "There is an error in our code. + ad_return_complaint 1 "There is an error in our code. Please inform your system administrator of the following error: portal::template_configure called with portal_id $portal_id" - } - + } + portal::configure -template_p "t" $portal_id $return_url } @@ -605,14 +605,14 @@ form } { Just a wrapper for the configure_dispatch proc - - @param portal_id - @param formdata an ns_set with all the formdata + + @param portal_id + @param formdata an ns_set with all the formdata } { configure_dispatch -template_p "t" $portal_id $form } - - + + # # Page Procs # @@ -626,9 +626,9 @@ if no sort_key is given returns the first page of the portal which is always there. - @return the id of the page - @param portal_id - @param sort_key - optional, defaults to page 0 + @return the id of the page + @param portal_id + @param sort_key - optional, defaults to page 0 } { if {![empty_string_p $page_name]} { return [db_string get_page_id_from_name {} -default ""] @@ -640,10 +640,10 @@ ad_proc -public page_count { {-portal_id:required} } { - 1 when there's only one page + 1 when there's only one page - @param portal_id - @param page_id + @param portal_id + @param page_id } { return [db_string page_count_select {}] } @@ -663,8 +663,8 @@ } { Appends a new blank page for the given portal_id. - @return the id of the page - @param portal_id + @return the id of the page + @param portal_id } { # get the layout_id if {![empty_string_p $layout_name]} { @@ -681,11 +681,11 @@ } { Returns a tcl list of the page_ids for the given portal_id - @return tcl list of the pages - @param portal_id + @return tcl list of the pages + @param portal_id } { set foo [list] - + db_foreach list_pages_tcl_list_select {} { lappend foo $page_id } @@ -704,13 +704,13 @@ } { Wraps portal::dimensional to create a dotlrn navbar - @return the id of the page - @param portal_id - @param link the relative link to set for hrefs + @return the id of the page + @param portal_id + @param link the relative link to set for hrefs @param current_page_link f means that there is no link for the current page } { set ad_dim_struct [list] - + db_foreach list_page_nums_select { select pretty_name, sort_key as page_num from portal_pages where portal_id = :portal_id @@ -744,49 +744,49 @@ portal_id ds_name } { - Add an element to a portal given a datasource name. Used for procs - that have no knowledge of regions - - @return the id of the new element - @param portal_id - @param page_num the number of the portal page to add to, def 0 - @param ds_name + Add an element to a portal given a datasource name. Used for procs + that have no knowledge of regions + + @return the id of the new element + @param portal_id + @param page_num the number of the portal page to add to, def 0 + @param ds_name } { if { [empty_string_p $page_num] && [empty_string_p $page_id] } { # neither page_num or page_id given, default to 0 set page_id [portal::get_page_id -portal_id $portal_id -sort_key 0] } - # Balance the portal by adding the new element to the region - # with the fewest number of elements, the first region w/ 0 elts, - # or, if all else fails, the first region - set min_num 99999 - set min_region 0 + # Balance the portal by adding the new element to the region + # with the fewest number of elements, the first region w/ 0 elts, + # or, if all else fails, the first region + set min_num 99999 + set min_region 0 # get the layout for some page set layout_id [get_layout_id -page_id $page_id $portal_id] - + # get the regions in this layout db_foreach get_regions {} { lappend region_list $region } - - if {[empty_string_p $force_region]} { + + if {[empty_string_p $force_region]} { # find the "best" region to put it in foreach region $region_list { db_1row region_count {} - + if { $count == 0 } { set min_region $region break } - + if { $min_num > $count } { set min_num $count set min_region $region } } - + if { $min_region == 0 } { set min_region 1 } @@ -800,7 +800,7 @@ break } } - + if {$min_region == 0} { # the region asked for was not in the list ns_log error "portal::add_element region $force_region not in layout $layout_id" @@ -817,7 +817,7 @@ ad_proc -public remove_element { element_id } { - Remove an element from a portal + Remove an element from a portal } { db_dml delete {} } @@ -829,19 +829,19 @@ ds_name region } { - Add an element to a portal in a region, given a datasource name - - @return the id of the new element - @param portal_id - @param ds_name + Add an element to a portal in a region, given a datasource name + + @return the id of the new element + @param portal_id + @param ds_name } { - set ds_id [get_datasource_id $ds_name] + set ds_id [get_datasource_id $ds_name] - # First, check if this portal 1) has a portal template and - # 2) that that template has an element of this DS in it. If - # so, copy stuff. If not, just insert normally. - if { [db_0or1row get_template_info_select {}] == 1 } { + # First, check if this portal 1) has a portal template and + # 2) that that template has an element of this DS in it. If + # so, copy stuff. If not, just insert normally. + if { [db_0or1row get_template_info_select {}] == 1 } { db_transaction { set new_element_id [db_nextval acs_object_id_seq] @@ -850,19 +850,19 @@ db_dml template_params_insert {} } - } else { - # no template, or the template dosen't have this DS, + } else { + # no template, or the template dosen't have this DS, # or I'm a template! - + db_transaction { set new_element_id [db_nextval acs_object_id_seq] db_dml insert {} db_dml params_insert {} } - } + } - # The caller must now set the necessary params or else! - return $new_element_id + # The caller must now set the necessary params or else! + return $new_element_id } ad_proc -private swap_element { @@ -872,49 +872,49 @@ region dir } { - Moves a PE in the up or down by swapping its sk with its neighbor's - - @param portal_id - @param element_id - @param sort_key of the element to be moved - @param region - @param dir either up or down + Moves a PE in the up or down by swapping its sk with its neighbor's + + @param portal_id + @param element_id + @param sort_key of the element to be moved + @param region + @param dir either up or down } { - ad_require_permission $portal_id portal_read_portal - ad_require_permission $portal_id portal_edit_portal - - if { $dir == "up" } { - # get the sort_key and id of the element above - if {[db_0or1row get_prev_sort_key {}] == 0} { + ad_require_permission $portal_id portal_read_portal + ad_require_permission $portal_id portal_edit_portal + + if { $dir == "up" } { + # get the sort_key and id of the element above + if {[db_0or1row get_prev_sort_key {}] == 0} { return } - } elseif { $dir == "down"} { - # get the sort_key and id of the element below - if {[db_0or1row get_next_sort_key {}] == 0} { + } elseif { $dir == "down"} { + # get the sort_key and id of the element below + if {[db_0or1row get_next_sort_key {}] == 0} { return } - } else { - ad_return_complaint 1 \ - "portal::swap_element: Bad direction: $dir" - } + } else { + ad_return_complaint 1 \ + "portal::swap_element: Bad direction: $dir" + } - db_transaction { - # because of the uniqueness constraint on sort_keys we - # need to set a dummy key, then do the swap. + db_transaction { + # because of the uniqueness constraint on sort_keys we + # need to set a dummy key, then do the swap. set dummy_sort_key [db_nextval portal_element_map_sk_seq] - # Set the element to be moved to the dummy key - db_dml swap_sort_keys_1 {} - - # Set the other_element's sort_key to the correct value - db_dml swap_sort_keys_2 {} + # Set the element to be moved to the dummy key + db_dml swap_sort_keys_1 {} - # Set the element to be moved's sort_key to the right value - db_dml swap_sort_keys_3 {} + # Set the other_element's sort_key to the correct value + db_dml swap_sort_keys_2 {} + + # Set the element to be moved's sort_key to the right value + db_dml swap_sort_keys_3 {} } on_error { - ad_return_complaint 1 "portal::swap_element: transaction failed" - } + ad_return_complaint 1 "portal::swap_element: transaction failed" + } } ad_proc -private move_element { @@ -923,397 +923,397 @@ region direction } { - Moves a PE to a neighboring region + Moves a PE to a neighboring region - @param portal_id - @param element_id - @param region the PEs current region - @param direction up or down + @param portal_id + @param element_id + @param region the PEs current region + @param direction up or down } { - - ad_require_permission $portal_id portal_read_portal - ad_require_permission $portal_id portal_edit_portal - - if { $direction == "right" } { - set target_region [expr $region + 1] - } elseif { $direction == "left" } { - set target_region [expr $region - 1] - } else { - ad_return_complaint 1 "portal::move_element Bad direction!" - } - - # just move the element to the bottom of the region - db_dml update {} + + ad_require_permission $portal_id portal_read_portal + ad_require_permission $portal_id portal_edit_portal + + if { $direction == "right" } { + set target_region [expr $region + 1] + } elseif { $direction == "left" } { + set target_region [expr $region - 1] + } else { + ad_return_complaint 1 "portal::move_element Bad direction!" + } + + # just move the element to the bottom of the region + db_dml update {} } - + ad_proc -private set_element_param { element_id key value } { - Set an element param named key to value + Set an element param named key to value - @param element_id - @param key - @param value - } { - db_dml update {} - return 1 + @param element_id + @param key + @param value + } { + db_dml update {} + return 1 } ad_proc -private toggle_element_param { {-element_id:required} {-key:required} } { toggles a boolean (t or f) element_param - - @param element_id - @param key + + @param element_id + @param key } { if { [get_element_param $element_id $key] == "t" } { set_element_param $element_id $key "f" } else { set_element_param $element_id $key "t" } } - + ad_proc -private get_element_param_list { - {-element_id:required} - {-key:required} + {-element_id:required} + {-key:required} } { - Get the list of parameter values for a particular element + Get the list of parameter values for a particular element - @author ben@openforce + @author ben@openforce } { - return [db_list select {}] + return [db_list select {}] } - + ad_proc -private add_element_param_value { - {-element_id:required} - {-key:required} - {-value:required} + {-element_id:required} + {-key:required} + {-value:required} } { - This adds a value for a param (instead of resetting a single value) - - @author ben@openforce + This adds a value for a param (instead of resetting a single value) + + @author ben@openforce } { - db_dml insert {} + db_dml insert {} } ad_proc -private remove_element_param_value { - {-element_id:required} - {-key:required} - {-value:required} + {-element_id:required} + {-key:required} + {-value:required} } { - removes a value for a param + removes a value for a param } { - db_dml delete {} + db_dml delete {} } ad_proc -private remove_all_element_param_values { - {-element_id:required} - {-key:required} + {-element_id:required} + {-key:required} } { - removes a value for a param + removes a value for a param } { - db_dml delete {} + db_dml delete {} } ad_proc -private get_element_param { element_id key } { - Get an element param. Returns the value of the param. + Get an element param. Returns the value of the param. - @return the value of the param - @param element_id - @param key + @return the value of the param + @param element_id + @param key } { - - if { [db_0or1row select {}] } { - return $value - } else { - ad_return_complaint \ - 1 "get_element_param: Invalid element_id ($element_id) and/or key ($key) given." - ad_script_abort - } + + if { [db_0or1row select {}] } { + return $value + } else { + ad_return_complaint \ + 1 "get_element_param: Invalid element_id ($element_id) and/or key ($key) given." + ad_script_abort + } } ad_proc -private evaluate_element { element_id theme_id } { - Combine the datasource, template, etc. Return a chunk of HTML. - - @param element_id - @param theme_id - @return A string containing the fully-rendered content for $element_id. - @param element_id + Combine the datasource, template, etc. Return a chunk of HTML. + + @param element_id + @param theme_id + @return A string containing the fully-rendered content for $element_id. + @param element_id } { - # get the element data and theme - db_1row element_select {} -column_array element + # get the element data and theme + db_1row element_select {} -column_array element - # get the element's params - db_foreach params_select {} { - lappend config($key) $value - } if_no_rows { - # this element has no config, set up some defaults - set config(shaded_p) "f" - set config(shadeable_p) "f" - set config(hideable_p) "f" - set config(user_editable_p) "f" - set config(link_hideable_p) "f" - } - - # do the callback for the ::show proc - # evaulate the datasource. - if { [catch { set element(content) \ - [datasource_call \ - $element(datasource_id) "Show" [list [array get config] ]] } \ - errmsg ] } { - ns_log error "*** portal::render_element show callback Error! ***\n\n $errmsg\n\n" + # get the element's params + db_foreach params_select {} { + lappend config($key) $value + } if_no_rows { + # this element has no config, set up some defaults + set config(shaded_p) "f" + set config(shadeable_p) "f" + set config(hideable_p) "f" + set config(user_editable_p) "f" + set config(link_hideable_p) "f" + } + + # do the callback for the ::show proc + # evaulate the datasource. + if { [catch { set element(content) \ + [datasource_call \ + $element(datasource_id) "Show" [list [array get config] ]] } \ + errmsg ] } { + ns_log error "*** portal::render_element show callback Error! ***\n\n $errmsg\n\n" ad_return_complaint 1 "*** portal::render_element show callback Error! ***

$errmsg\n\n" - } + } - set element(name) \ - [datasource_call \ - $element(datasource_id) "GetPrettyName" [list]] + set element(name) \ + [datasource_call \ + $element(datasource_id) "GetPrettyName" [list]] - set element(link) \ + set element(link) \ [datasource_call $element(datasource_id) "Link" [list]] - # done with callbacks, now set config params - set element(shadeable_p) $config(shadeable_p) - set element(shaded_p) $config(shaded_p) - set element(hideable_p) $config(hideable_p) - set element(user_editable_p) $config(user_editable_p) - set element(link_hideable_p) $config(link_hideable_p) + # done with callbacks, now set config params + set element(shadeable_p) $config(shadeable_p) + set element(shaded_p) $config(shaded_p) + set element(hideable_p) $config(hideable_p) + set element(user_editable_p) $config(user_editable_p) + set element(link_hideable_p) $config(link_hideable_p) - # apply the path hack to the filename and the resourcedir - set element(filename) "[www_path]/$element(filename)" + # apply the path hack to the filename and the resourcedir + set element(filename) "[www_path]/$element(filename)" # notice no "/" after mount point - set element(resource_dir) "[mount_point]$element(resource_dir)" + set element(resource_dir) "[mount_point]$element(resource_dir)" - return [array get element] + return [array get element] } ad_proc -private evaluate_element_raw { element_id } { Just call show on the element - - @param element_id - @return A string containing the fully-rendered content for $element_id. + + @param element_id + @return A string containing the fully-rendered content for $element_id. } { - # get the element data and theme - db_1row element_select {} -column_array element + # get the element data and theme + db_1row element_select {} -column_array element - # get the element's params - db_foreach params_select {} { - lappend config($key) $value - } if_no_rows { - # this element has no config, set up some defaults - set config(shaded_p) "f" - set config(shadeable_p) "f" - set config(hideable_p) "f" - set config(user_editable_p) "f" - set config(link_hideable_p) "f" - } - - # do the callback for the ::show proc - # evaulate the datasource. - if { [catch { set element(content) \ - [datasource_call \ - $element(datasource_id) "Show" [list [array get config] ]] } \ - errmsg ] } { - ns_log error "*** portal::render_element show callback Error! ***\n\n $errmsg\n\n" + # get the element's params + db_foreach params_select {} { + lappend config($key) $value + } if_no_rows { + # this element has no config, set up some defaults + set config(shaded_p) "f" + set config(shadeable_p) "f" + set config(hideable_p) "f" + set config(user_editable_p) "f" + set config(link_hideable_p) "f" + } + + # do the callback for the ::show proc + # evaulate the datasource. + if { [catch { set element(content) \ + [datasource_call \ + $element(datasource_id) "Show" [list [array get config] ]] } \ + errmsg ] } { + ns_log error "*** portal::render_element show callback Error! ***\n\n $errmsg\n\n" ad_return_complaint 1 "*** portal::render_element show callback Error! ***

$errmsg\n\n" - } + } - set element(name) \ - [datasource_call \ - $element(datasource_id) "GetPrettyName" [list]] + set element(name) \ + [datasource_call \ + $element(datasource_id) "GetPrettyName" [list]] - set element(link) \ + set element(link) \ [datasource_call $element(datasource_id) "Link" [list]] - # done with callbacks, now set config params - set element(shadeable_p) $config(shadeable_p) - set element(shaded_p) $config(shaded_p) - set element(hideable_p) $config(hideable_p) - set element(user_editable_p) $config(user_editable_p) - set element(link_hideable_p) $config(link_hideable_p) + # done with callbacks, now set config params + set element(shadeable_p) $config(shadeable_p) + set element(shaded_p) $config(shaded_p) + set element(hideable_p) $config(hideable_p) + set element(user_editable_p) $config(user_editable_p) + set element(link_hideable_p) $config(link_hideable_p) # THE HACK - BEN OVERRIDES TO RAW set element(filename) "themes/raw-theme" - # apply the path hack to the filename and the resourcedir - set element(filename) "[www_path]/$element(filename)" + # apply the path hack to the filename and the resourcedir + set element(filename) "[www_path]/$element(filename)" # notice no "/" after mount point - # set element(resource_dir) "[mount_point]$element(resource_dir)" + # set element(resource_dir) "[mount_point]$element(resource_dir)" - return [array get element] + return [array get element] } - + ad_proc -public configure_element { element_id op return_url } { - Dispatch on the element_id and op requested + Dispatch on the element_id and op requested - @param element_id - @param op - @param return_url + @param element_id + @param op + @param return_url } { - - if { [db_0or1row select {}] } { - # passed in element_id is good, do they have perms? - ad_require_permission $portal_id portal_read_portal - ad_require_permission $portal_id portal_edit_portal - } else { - ad_returnredirect $return_url - } - - switch $op { - "edit" { - # Get the edit html by callback - # Notice that the "edit" proc takes only the element_id - set html_string [datasource_call $datasource_id "Edit" \ - [list $element_id]] - if { $html_string == "" } { - ns_log Error "portal::configure_element op = edit, but - portlet's edit proc returned null string" - - ad_returnredirect $return_url - } - - # Set up some template vars, including the form target - set master_template [ad_parameter master_template] - set target_stub \ - [lindex [ns_conn urlv] [expr [ns_conn urlc] - 1]] - set action_string [append target_stub "-2"] + if { [db_0or1row select {}] } { + # passed in element_id is good, do they have perms? + ad_require_permission $portal_id portal_read_portal + ad_require_permission $portal_id portal_edit_portal + } else { + ad_returnredirect $return_url + } - # the sources /www/place-element.tcl - set template " - - Return to your portal -

-

- Edit this element's parameters: -

- @html_string@ -

-

- " - set __adp_stub "[get_server_root][www_path]/." - set {master_template} \"master\" - - set code [template::adp_compile -string $template] - set output [template::adp_eval code] - - return $output - - } - "shade" { - set shaded_p [get_element_param $element_id "shaded_p"] - - if { $shaded_p == "f" } { - set_element_param $element_id "shaded_p" "t" - } else { - set_element_param $element_id "shaded_p" "f" - } - ad_returnredirect $return_url - } - "hide" { - db_dml hide_update {} - ad_returnredirect $return_url - } - } + switch $op { + "edit" { + # Get the edit html by callback + # Notice that the "edit" proc takes only the element_id + set html_string [datasource_call $datasource_id "Edit" \ + [list $element_id]] + + if { $html_string == "" } { + ns_log Error "portal::configure_element op = edit, but + portlet's edit proc returned null string" + + ad_returnredirect $return_url + } + + # Set up some template vars, including the form target + set master_template [ad_parameter master_template] + set target_stub \ + [lindex [ns_conn urlv] [expr [ns_conn urlc] - 1]] + set action_string [append target_stub "-2"] + + # the sources /www/place-element.tcl + set template " + + Return to your portal +

+

+ Edit this element's parameters: +

+ @html_string@ +

+

+ " + set __adp_stub "[get_server_root][www_path]/." + set {master_template} \"master\" + + set code [template::adp_compile -string $template] + set output [template::adp_eval code] + + return $output + + } + "shade" { + set shaded_p [get_element_param $element_id "shaded_p"] + + if { $shaded_p == "f" } { + set_element_param $element_id "shaded_p" "t" + } else { + set_element_param $element_id "shaded_p" "f" + } + ad_returnredirect $return_url + } + "hide" { + db_dml hide_update {} + ad_returnredirect $return_url + } + } } - + # # Datasource helper procs # - + ad_proc -private get_datasource_name { ds_id } { - Get the ds name from the id or the null string if not found. - - @param ds_id - @return ds_name + Get the ds name from the id or the null string if not found. + + @param ds_id + @return ds_name } { - if {[db_0or1row select {}]} { - return $name - } else { - return "" - } + if {[db_0or1row select {}]} { + return $name + } else { + return "" + } } - + ad_proc -private get_datasource_id { ds_name } { - Get the ds id from the name or the null string if not found. + Get the ds id from the name or the null string if not found. - @param ds_name - @return ds_id + @param ds_name + @return ds_id } { - if {[db_0or1row select {}]} { - return $datasource_id - } else { - return "" - } + if {[db_0or1row select {}]} { + return $datasource_id + } else { + return "" + } } - + ad_proc -private make_datasource_available {portal_id ds_id} { - Make the datasource available to the given portal. - - @param portal_id - @param ds_id + Make the datasource available to the given portal. + + @param portal_id + @param ds_id } { - # XXX todo permissions on availabliliy procs - # ad_require_permission $portal_id portal_admin_portal - set new_p_ds_id [db_nextval acs_object_id_seq] - db_dml insert {} + # XXX todo permissions on availabliliy procs + # ad_require_permission $portal_id portal_admin_portal + set new_p_ds_id [db_nextval acs_object_id_seq] + db_dml insert {} } - + ad_proc -private make_datasource_unavailable {portal_id ds_id} { - Make the datasource unavailable to the given portal. - - @param portal_id - @param ds_id + Make the datasource unavailable to the given portal. + + @param portal_id + @param ds_id } { - # ad_require_permission $portal_id portal_admin_portal - db_dml delete {} + # ad_require_permission $portal_id portal_admin_portal + db_dml delete {} } - + ad_proc -private toggle_datasource_availability {portal_id ds_id} { - Toggle - - @param portal_id - @param ds_id + Toggle + + @param portal_id + @param ds_id } { - ad_require_permission $portal_id portal_admin_portal - - if { [db_0or1row select {}] } { - [make_datasource_unavailable $portal_id $ds_id] - } else { - [make_datasource_available $portal_id $ds_id] - } + ad_require_permission $portal_id portal_admin_portal + + if { [db_0or1row select {}] } { + [make_datasource_unavailable $portal_id $ds_id] + } else { + [make_datasource_available $portal_id $ds_id] + } } # # Misc procs # ad_proc -private get_element_ids_by_ds {portal_id ds_name} { - Get element IDs for a particular portal and a datasource name + Get element IDs for a particular portal and a datasource name } { - set ds_id [get_datasource_id $ds_name] - return [db_list select {}] + set ds_id [get_datasource_id $ds_name] + return [db_list select {}] } - + ad_proc -private get_layout_id { {-page_num ""} {-page_id ""} {-layout_name "Simple 2-Column"} {portal_id ""} } { - Get the layout_id of a layout template for a portal page. - - @param page_num the page of the portal to look at, def page 0 - @param portal_id The portal_id. - @return A layout_id. + Get the layout_id of a layout template for a portal page. + + @param page_num the page of the portal to look at, def page 0 + @param portal_id The portal_id. + @return A layout_id. } { if { ![empty_string_p $page_num] } { db_1row get_layout_id_num_select {} @@ -1325,21 +1325,21 @@ ad_return_complaint 1 "portal::get_layout_id bad params!" ns_log error "portal::get_layout_id bad params!" } - - return $layout_id + + return $layout_id } - + ad_proc -private exists_p { portal_id } { - Check if a portal by that id exists. - - @return 1 on success, 0 on failure - @param a portal_id + Check if a portal by that id exists. + + @return 1 on success, 0 on failure + @param a portal_id } { - if { [db_0or1row select {} ]} { - return 1 - } else { - return 0 - } + if { [db_0or1row select {} ]} { + return 1 + } else { + return 0 + } } ad_proc -public add_element_or_append_id { @@ -1355,27 +1355,27 @@ page. If the portlet is already in the given portal page, it appends the value_id to the element's parameters with the given key. Returns the element_id used. - - @return element_id The new element's id - @param portal_id The page to add the portlet to - @param portlet_name The name of the portlet to add + + @return element_id The new element's id + @param portal_id The page to add the portlet to + @param portlet_name The name of the portlet to add @param key the key for the value_id (defaults to instance_id) - @param value_id the value of the key + @param value_id the value of the key @param extra_params a list of extra key/value pairs to insert or append } { - # Find out if this portlet already exists in this page - set element_id_list [get_element_ids_by_ds $portal_id $portlet_name] + # Find out if this portlet already exists in this page + set element_id_list [get_element_ids_by_ds $portal_id $portlet_name] - if {[llength $element_id_list] == 0} { - db_transaction { + if {[llength $element_id_list] == 0} { + db_transaction { # Tell portal to add this element to the page set element_id [add_element -page_id $page_id $portal_id $portlet_name] # There is already a value for the param which is overwritten set_element_param $element_id $key $value_id - + if {![empty_string_p $extra_params]} { check_key_value_list $extra_params @@ -1386,15 +1386,15 @@ } } } - } else { + } else { db_transaction { set element_id [lindex $element_id_list 0] # There are existing values which should NOT be overwritten add_element_param_value -element_id $element_id \ -key $key \ -value $value_id - + if {![empty_string_p $extra_params]} { check_key_value_list $extra_params @@ -1425,20 +1425,20 @@ there are no more params (say instace_id's) of this type, that means that the portlet has become empty and can be - @param portal_id The portal page to act on - @param portlet_name The name of the portlet to (maybe) remove + @param portal_id The portal page to act on + @param portlet_name The name of the portlet to (maybe) remove @param key the key for the value_id (defaults to instance_id) - @param value_id the value of the key + @param value_id the value of the key @param extra_params a list of extra key/value pairs to remove } { - # get the element IDs (could be more than one!) - set element_ids [get_element_ids_by_ds $portal_id $portlet_name] + # get the element IDs (could be more than one!) + set element_ids [get_element_ids_by_ds $portal_id $portlet_name] - # step 1: remove all the given param(s) from all of the pe's - db_transaction { - foreach element_id $element_ids { + # step 1: remove all the given param(s) from all of the pe's + db_transaction { + foreach element_id $element_ids { - remove_element_param_value -element_id $element_id \ + remove_element_param_value -element_id $element_id \ -key $key \ -value $value_id @@ -1485,7 +1485,7 @@ } { hides ugly templating calls for portlet "show" procs } { - + if { $template_src == ""} { set template_src $package_key } @@ -1503,7 +1503,7 @@ uplevel 1 { set template "" set __adp_stub "[get_server_root]/packages/$__pk/www/." - set code [template::adp_compile -string $template] + set code [template::adp_compile -string $template] set output [template::adp_eval code] return $output } @@ -1514,13 +1514,13 @@ } { self explanatory } { - if { [db_0or1row get_theme_id_from_name_select {} ]} { - return $theme_id - } else { + if { [db_0or1row get_theme_id_from_name_select {} ]} { + return $theme_id + } else { ns_log error "portal::get_theme_id_from_name_select bad theme_id!" ad_return_complaint 1 "portal::get_theme_id_from_name_select bad theme_id!" - } - + } + } ad_proc dimensional { @@ -1540,79 +1540,76 @@ } { An enhanced ad_dimensional. see that proc for usage details } { - - set html {} - if {[empty_string_p $option_list]} { return } - + if {[empty_string_p $options_set]} { set options_set [ns_getform] } - + if {[empty_string_p $url]} { set url [ad_conn url] } - - append html "\n\n" - + + set html "\n
\n \n" + if {!$no_header_p} { foreach option $option_list { - append html " \n" + append html " \n" } } - - append html "\n" - - append html "\n" - + + append html " \n \n" + foreach option $option_list { - append html " \n " + + append html "$extra_td_html\n" } - append html "\n
[lindex $option 1][lindex $option 1]
" - + append html " " + if {!$no_bars_p} { append html "\[" } - + # find out what the current option value is. # check if a default is set otherwise the first value is used set option_key [lindex $option 0] - set option_val {} - if { ! [empty_string_p $options_set]} { + set option_val [lindex $option 2] + if {![empty_string_p $options_set]} { set option_val [ns_set get $options_set $option_key] } - if { [empty_string_p $option_val] } { - set option_val [lindex $option 2] - } - set first_p 1 foreach option_value [lindex $option 3] { - set thisoption [lindex $option_value 0] - if { $first_p } { + set thisoption_name [lindex $option_value 0] + set thisoption_value [lindex $option_value 1] + set thisoption_link_p 1 + if {[llength $option_value] > 3} { + set thisoption_link_p [lindex $option_value 3] + } + + if {$first_p} { set first_p 0 } else { if {!$no_bars_p} { append html " | " } else { - append html " " + append html "   " } } - - if {[string compare $option_val $thisoption] == 0 && !$link_all} { - append html "$pre_html[lindex $option_value 1]$post_html" + + if {([string equal $option_val $thisoption_name] == 1 && !$link_all) || !$thisoption_link_p} { + append html "${pre_html}${thisoption_value}${post_html}" } else { - append html "$pre_html[lindex $option_value 1]$post_html" + append html "${pre_html}${thisoption_value}${post_html}" } } - + if {!$no_bars_p} { append html "\]" } - - append html "$extra_td_html
\n" - } + append html " \n\n" + } }