Index: openacs-4/packages/static-portlet/www/element.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/static-portlet/www/element.tcl,v diff -u -r1.10.2.1.4.2 -r1.10.2.1.4.3 --- openacs-4/packages/static-portlet/www/element.tcl 28 Jul 2004 00:35:06 -0000 1.10.2.1.4.2 +++ openacs-4/packages/static-portlet/www/element.tcl 10 Aug 2004 16:44:18 -0000 1.10.2.1.4.3 @@ -45,10 +45,26 @@ set file_content_id $content_id } + +set type [db_string get_type { select type from dotlrn_portal_types_map where portal_id = :portal_id } -default ""] +set templates [list user dotlrn_class_instance dotlrn_club dotlrn_community] + ad_form -name static_element -form { element_content_id:key {pretty_name:text(text) {label "[_ static-portlet.Name]"} {html {size 60}}} {content:text(textarea) {label "[_ static-portlet.Content]"} {html {rows 15 cols 80 wrap soft}}} +} + +if {[lsearch $templates $type] >= 0} { + set elements [list \ + [list {enforce_portlet:text(select)} [list label [_ static-portlet.lt_Enforce_this_applet_t]] \ + [list help_text [_ static-portlet.lt_Enforce_True_means_th]] \ + [list options [list [_ static-portlet.True] 1] [list [_ static-portlet.False_0]]] \ + [list value 0]]] + ad_form -extend -name static_element -form $elements +} + +ad_form -extend -name static_element -form { {portal_id:text(hidden) {value $portal_id}} {package_id:text(hidden) {value $package_id}} {referer:text(hidden) {value $referer}} @@ -63,34 +79,138 @@ -pretty_name $pretty_name ] - static_portal_content::add_to_portal \ - -portal_id $portal_id \ - -package_id $package_id \ - -content_id $item_id + set old_element_id [static_portal_content::add_to_portal \ + -portal_id $portal_id \ + -package_id $package_id \ + -content_id $item_id] + + + } + # support for templates & already created portals for users, + # classes, etc. (roc) + + switch $type { + user { + set query "select portal_id as target_portal_id from dotlrn_users" + set community_id $package_id + set new_content_id $item_id + } + dotlrn_class_instance { set query "select portal_id as target_portal_id, community_id from dotlrn_class_instances_full" } + dotlrn_club { set query "select portal_id as target_portal_id, community_id from dotlrn_clubs_full" } + dotlrn_community { set query "select portal_id as target_portal_id, community_id from dotlrn_communities_full" } + default { + ad_returnredirect $referer + ad_script_abort + } + } + + + db_foreach dotlrn_type_portals "$query" { + + if {$type != "user" } { + # clone the template's content + set new_content_id [static_portal_content::new \ + -package_id $community_id \ + -content $content \ + -pretty_name $pretty_name ] + } + + + set new_element_id [ static_portal_content::add_to_portal \ + -portal_id $target_portal_id \ + -package_id $community_id \ + -content_id $new_content_id] + + portal::set_element_param $new_element_id "package_id" $community_id + portal::set_element_param $new_element_id "content_id" $new_content_id + + if {$enforce_portlet == 0} { + db_dml hide_portlet { update portal_element_map set state = 'hidden' where element_id = :new_element_id } + } + + } + + # redirect and abort ad_returnredirect $referer ad_script_abort } -edit_data { + db_transaction { + static_portal_content::update \ -portal_id $portal_id \ -content_id $element_content_id \ -pretty_name $pretty_name \ -content $content + } + + switch $type { + user { set query "select portal_id as target_portal_id from dotlrn_users" } + dotlrn_class_instance { set query "select portal_id as target_portal_id, community_id from dotlrn_class_instances_full" } + dotlrn_club { set query "select portal_id as target_portal_id, community_id from dotlrn_clubs_full" } + dotlrn_community { set query "select portal_id as target_portal_id, community_id from dotlrn_communities_full" } + default { + ad_returnredirect $referer + ad_script_abort + } + } + + db_foreach dotlrn_type_portals "$query" { + + if {$type != "user" } { + set element_content_id [db_string get_content_id { + select content_id + from static_portal_content + where package_id = :community_id + and pretty_name = :pretty_name + }] + } + + + static_portal_content::update \ + -portal_id $target_portal_id \ + -content_id $element_content_id \ + -pretty_name $pretty_name \ + -content $content + + set element_id [portal::get_element_id_from_unique_param -portal_id $target_portal_id -key content_id -value $element_content_id] + if {$enforce_portlet == 0} { + db_dml hide_portlet { update portal_element_map set state = 'hidden' where element_id = :element_id } + } else { + db_dml hide_portlet { update portal_element_map set state = 'full' where element_id = :element_id } + } + + } + + # redirect and abort ad_returnredirect $referer ad_script_abort } + ad_form -name static_file -html {enctype multipart/form-data} -form { file_content_id:key {pretty_name:text(text) {label "[_ static-portlet.Name]"} {html {size 60}}} {upload_file:file {label "[_ static-portlet.File]"}} +} + +if {[lsearch $templates $type] >= 0} { + set elements [list \ + [list {enforce_portlet:text(select)} [list label [_ static-portlet.lt_Enforce_this_applet_t]] \ + [list help_text [_ static-portlet.lt_Enforce_True_means_th]] \ + [list options [list [_ static-portlet.True] 1] [list [_ static-portlet.False_0]]] \ + [list value 0]]] + ad_form -extend -name static_file -form $elements +} + +ad_form -extend -name static_file -form { {portal_id:text(hidden) {value $portal_id}} {package_id:text(hidden) {value $package_id}} {referer:text(hidden) {value $referer}} @@ -117,12 +237,59 @@ -content $content \ -pretty_name $pretty_name ] + static_portal_content::add_to_portal \ -portal_id $portal_id \ -package_id $package_id \ -content_id $item_id + } + # support for templates & already created portals for users, + # classes, etc. (roc) + + switch $type { + user { + set query "select portal_id as target_portal_id from dotlrn_users" + set community_id $package_id + set new_content_id $item_id + } + dotlrn_class_instance { set query "select portal_id as target_portal_id, community_id from dotlrn_class_instances_full" } + dotlrn_club { set query "select portal_id as target_portal_id, community_id from dotlrn_clubs_full" } + dotlrn_community { set query "select portal_id as target_portal_id, community_id from dotlrn_communities_full" } + default { + ad_returnredirect $referer + ad_script_abort + } + } + + + db_foreach dotlrn_type_portals "$query" { + + if {$type != "user" } { + # clone the template's content + set new_content_id [static_portal_content::new \ + -package_id $community_id \ + -content $content \ + -pretty_name $pretty_name ] + } + + + set new_element_id [ static_portal_content::add_to_portal \ + -portal_id $target_portal_id \ + -package_id $community_id \ + -content_id $new_content_id] + + portal::set_element_param $new_element_id "package_id" $community_id + portal::set_element_param $new_element_id "content_id" $new_content_id + + if {$enforce_portlet == 0} { + db_dml hide_portlet { update portal_element_map set state = 'hidden' where element_id = :new_element_id } + } + + } + + # redirect and abort ad_returnredirect $referer ad_script_abort @@ -147,6 +314,44 @@ -content $content } + switch $type { + user { set query "select portal_id as target_portal_id from dotlrn_users" } + dotlrn_class_instance { set query "select portal_id as target_portal_id, community_id from dotlrn_class_instances_full" } + dotlrn_club { set query "select portal_id as target_portal_id, community_id from dotlrn_clubs_full" } + dotlrn_community { set query "select portal_id as target_portal_id, community_id from dotlrn_communities_full" } + default { + ad_returnredirect $referer + ad_script_abort + } + } + + db_foreach dotlrn_type_portals "$query" { + + if {$type != "user" } { + set file_content_id [db_string get_content_id { + select content_id + from static_portal_content + where package_id = :community_id + and pretty_name = :pretty_name + }] + } + + + static_portal_content::update \ + -portal_id $target_portal_id \ + -content_id $file_content_id \ + -pretty_name $pretty_name \ + -content $content + + set element_id [portal::get_element_id_from_unique_param -portal_id $target_portal_id -key content_id -value $file_content_id] + if {$enforce_portlet == 0} { + db_dml hide_portlet { update portal_element_map set state = 'hidden' where element_id = :element_id } + } else { + db_dml hide_portlet { update portal_element_map set state = 'full' where element_id = :element_id } + } + + } + # redirect and abort ad_returnredirect $referer ad_script_abort