Index: openacs-4/packages/new-portal/www/element-add-2.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/new-portal/www/Attic/element-add-2.tcl,v diff -u -r1.6 -r1.7 --- openacs-4/packages/new-portal/www/element-add-2.tcl 1 Oct 2001 19:17:05 -0000 1.6 +++ openacs-4/packages/new-portal/www/element-add-2.tcl 2 Oct 2001 16:12:36 -0000 1.7 @@ -5,40 +5,13 @@ portal_id:naturalnum,notnull,permission(write) name:trim,notnull,nohtml region:notnull - ds_ids:naturalnum,multiple,notnull + datasource_id:naturalnum,notnull } -# XXX fix me themes -# XXX check for name constraint violations +# XXX fix me portal_element_themes +# XXX permisson read filter on ds_id? -# AKS: most of the references to "element" here are really -# to DS - -# Check if any of the PEs need to be configured -# i.e. "config_required_p = t" and "configured_p = f" for this DS in -# the portal_datasource_def_params table. If so, redirect to configure -# it, then remove it from the PE list and come back here. - -foreach ds_id $ds_ids { - # can the user read this element? - if { ! [ad_permission_p $ds_id read] } { - continue - } - - if { ! [db_0or1row check_config_select " - select 1 - from portal_datasource_def_params - where datasource_id = :ds_id and - config_required_p = 't' and - configured_p = 'f'"] } { - # needs to be configured, redirect to config page - # everything that this page needs along the way - set ds_to_configure $ds_id - ad_returnredirect "element-config?[export_url_vars portal_id name region ds_ids ds_to_configure]" - } -} - - +set ds_id $datasource_id set layout_id [portal_get_layout_id $portal_id] # this is required to execute the query that initializes the @@ -53,31 +26,67 @@ set master_template [ad_parameter master_template] # shouldn't it be possible to do this with one query? Hmmm. -foreach ds_id $ds_ids { - # can the user read this element? - if { ! [ad_permission_p $ds_id read] } { - continue - } - set new_element_id [db_nextval acs_object_id_seq] +# can the user read this element? +if { ! [ad_permission_p $ds_id read] } { + # XXX complain loudly + continue +} +# Bind the DS to the PE by inserting into the map +set new_element_id [db_nextval acs_object_id_seq] + + +db_transaction { db_dml insert_into_map " insert into portal_element_map - (element_id, - name, - portal_id, - datasource_id, - theme_id, - region, - sort_key) + (element_id, name, portal_id, datasource_id, theme_id, region, sort_key) values - (:new_element_id, - :name, - :portal_id, - :ds_id, - nvl((select max(theme_id) from portal_element_themes), 1), - :region, - nvl((select max(sort_key) + 1 from portal_element_map where region = :region), 1))" + (:new_element_id, + :name, + :portal_id, + :ds_id, + nvl((select max(theme_id) from portal_element_themes), 1), + :region, + nvl((select max(sort_key) + 1 from portal_element_map where region = :region), 1))" + + db_foreach get_def_params " + select config_required_p, configured_p, key, value + from portal_datasource_def_params + where datasource_id = :ds_id" { + set new_param_id [db_nextval acs_object_id_seq] + db_dml insert_into_params " + insert into partal_element_parameters + (parameter_id, element_id, config_required_p, configured_p) + values + (:new_param_id, :new_element_id, :config_required_p, :configured_p)" + } + +} on_error { + ad_return_complaint "The DML failed." } + +# Check if the PE needs to be configured i.e. "config_required_p = t" +# and "configured_p = f" for this DS in the +# portal_datasource_def_params table. If so, redirect to configure it + +# can the user read this element? +if { ! [ad_permission_p $ds_id read] } { + continue +} + +if { [db_0or1row check_config_select " + select config_path + from portal_datasource_def_params dsdp, portal_datasources ds + where dsdp.datasource_id = :ds_id and + dsdp.datasource_id = ds.datasource_id and + dsdp.config_required_p = 't' and + dsdp.configured_p = 'f'"] } { + # This PE needs to be configured, redirect to config page + ad_returnredirect "$config_path?[export_url_vars new_element_id]" +} + ad_returnredirect "element-layout?[export_url_vars portal_id]" + +