Index: openacs-4/contrib/packages/cop-base/www/admin/community-new.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/cop-base/www/admin/community-new.tcl,v
diff -u -r1.3 -r1.4
--- openacs-4/contrib/packages/cop-base/www/admin/community-new.tcl 27 Apr 2004 10:41:28 -0000 1.3
+++ openacs-4/contrib/packages/cop-base/www/admin/community-new.tcl 25 Jan 2005 23:33:44 -0000 1.4
@@ -4,8 +4,13 @@
@author Jeff Davis (davis@xarg.net)
@creation-date 2004-03-04
@cvs-id $Id$
+} {
+ {request_id:integer {}}
}
+set user_id [ad_conn user_id]
+set peeraddr [ad_conn peeraddr]
+
ad_form -name copnew -form {
{name:text
{label {Community name}}
@@ -17,6 +22,7 @@
{help_text "This is the last part of the url. It should not have any spaces or characters other
than -, _, a-z, A-Z, and 0-9.
Your community will be created at [ad_url]/url_stub/"}
}
+ {request_id:text(hidden),optional}
{description:richtext(richtext),optional
{html {cols 60 rows 10}}
{label "Description"}
@@ -26,45 +32,74 @@
set category_ids {}
-category::ad_form::add_widgets -help_text {
- Choose a root category for the community. If you do not choose one an empty
- category tree will be created which you can add to later
-} \
+category::ad_form::add_widgets \
+ -form_name copnew \
+ -help_text {
+ Choose a root category for the community. If you do not choose one an empty
+ category tree will be created which you can add to later
+ } \
-container_object_id [subsite::main_site_id] \
- -form_name copnew
+ -excluded_trees [list [parameter::get -parameter KMCategoryTreeID]] \
-ad_form -extend -name copnew -validate {
- { name {![string is space $name]} {You must enter a name.} }
- { stub {![string is space $stub]} {You must enter a URL stub.} }
- { stub {[regexp {^[-A-Za-z0-9_]*$} [string trim $stub]]} {Your URL stub contains invalid characters} }
- { stub {![db_string stub_exists "select count(*) from site_nodes where parent_id = (select node_id from site_nodes where object_id = [subsite::main_site_id]) and lower(name) = lower(:stub)"]} {A community with this url already exists} }
-} -on_submit {
- set Description [template::util::richtext::get_property contents $description]
- set DescriptionFormat [template::util::richtext::get_property format $description]
+ns_log Debug "JCD: [list [parameter::get -parameter KMCategoryTreeID]] "
- set out [cop::install /packages/cop-base/lib/install.xml \
- [list \
- base_url /$stub \
- name $name \
- Description $Description \
- DescriptionFormat $DescriptionFormat \
- ] ]
+ad_form -extend -name copnew \
+ -validate {
+ { name {![string is space $name]} {You must enter a name.} }
+ { stub {![string is space $stub]} {You must enter a URL stub.} }
+ { stub {[regexp {^[-A-Za-z0-9_]*$} [string trim $stub]]} {Your URL stub contains invalid characters} }
+ { stub {![db_string stub_exists "select count(*) from site_nodes where parent_id = (select node_id from site_nodes where object_id = [subsite::main_site_id]) and lower(name) = lower(:stub)"]} {A community with this url already exists} }
+ } -on_request {
+ if {![string is space $request_id]} {
+ db_1row request_data {
+ select title as name, description as desc_text, desc_format from cop_requests where request_id = :request_id
+ }
+ set description [template::util::richtext::create $desc_text $desc_format]
+ }
- set category_ids [category::ad_form::get_categories -container_object_id [subsite::main_site_id]]
- set cop_subsite_id [site_node::get_element -url /$stub -element package_id]
- if {![empty_string_p $category_ids]} {
- # map a subtree to the CoP...
- category_tree::map -tree_id [category::get_tree [lindex $category_ids 0]] \
- -object_id $cop_subsite_id \
- -subtree_category_id [lindex $category_ids 0]
- } else {
- # create a new tree...
- set tree_id [category_tree::add -name Categories \
- -description "$name Categories" \
- -context_id $cop_subsite_id]
- category::add -name "$name" -description "$name root" -tree_id $tree_id -parent_id {}
- category_tree::map -tree_id $tree_id -object_id $cop_subsite_id
+ } -on_submit {
+ set Description [template::util::richtext::get_property contents $description]
+ set DescriptionFormat [template::util::richtext::get_property format $description]
+
+ set out [apm::process_install_xml /packages/cop-base/lib/install.xml \
+ [list \
+ base_url /$stub \
+ name $name \
+ Description $Description \
+ DescriptionFormat $DescriptionFormat \
+ ] ]
+
+ set category_ids [category::ad_form::get_categories -container_object_id [subsite::main_site_id]]
+ set cop_subsite_id [site_node::get_element -url /$stub -element package_id]
+ if {![empty_string_p $category_ids]} {
+ # map a subtree to the CoP...
+ category_tree::map -tree_id [category::get_tree [lindex $category_ids 0]] \
+ -object_id $cop_subsite_id \
+ -subtree_category_id [lindex $category_ids 0]
+ } else {
+ # create a new tree for the community.
+ set tree_id [category_tree::add -name Categories \
+ -description "$name Categories" \
+ -context_id $cop_subsite_id]
+ category::add -name "$name" -description "$name root" -tree_id $tree_id -parent_id {}
+ category_tree::map -tree_id $tree_id -object_id $cop_subsite_id
+ }
+
+ if {![string is space $request_id]
+ && [db_0or1row request {select user_id as req_user_id from cop_requests where request_id = :request_id}]} {
+ db_dml update_req_state {
+ update cop_requests set req_user_id = :user_id, req_ip = :peeraddr, req_action = now(), url_stub = :stub, req_state='approved'
+ where request_id = :request_id
+ }
+ acs_user::get -user_id $user_id -array user
+ acs_user::get -user_id $req_user_id -array req_user
+
+ ns_sendmail \
+ $req_user(email) \
+ $user(email) \
+ "Created $name" \
+ "Your community \"$name\" has been created\nGo to [ad_url]/$stub to see it."
+ }
+ } -after_submit {
+ ad_returnredirect -message "Created community \"$name\"" "/$stub"
}
-} -after_submit {
- ad_returnredirect -message "Created community \"$name\"" "/$stub"
-}