Index: openacs-4/packages/dotlrn-ecommerce/dotlrn-ecommerce.info
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/dotlrn-ecommerce.info,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/dotlrn-ecommerce/dotlrn-ecommerce.info	31 May 2005 22:04:53 -0000	1.1
@@ -0,0 +1,29 @@
+<?xml version="1.0"?>
+<!-- Generated by the OpenACS Package Manager -->
+
+<package key="dotlrn-ecommerce" url="http://openacs.org/repository/apm/packages/dotlrn-ecommerce" type="apm_application">
+    <package-name>dotLRN - Ecommerce</package-name>
+    <pretty-plural>dotLRN - Ecommerce</pretty-plural>
+    <initial-install-p>f</initial-install-p>
+    <singleton-p>t</singleton-p>
+    
+    <version name="0.1d" url="http://openacs.org/repository/download/apm/dotlrn-ecommerce-0.1d.apm">
+        <owner url="mailto:roelmc@solutiongrove.com">Roel Canicula</owner>
+        <summary>Package to tie the dotLRN, Ecommerce, Assessments and dotLRN Catalog packages together</summary>
+        <vendor url="http://www.solutiongrove.com">Solution Grove</vendor>
+        <description format="text/html">Package to tie the dotLRN, Ecommerce, Assessments and dotLRN Catalog packages together.  Initially intended for the MOS and MGH projects, the goal is to create a reusable module for similar projects.</description>
+
+        <provides url="dotlrn-ecommerce" version="0.1d"/>
+
+        <callbacks>
+            <callback type="after-install"  proc="dotlrn_ecommerce::install"/>
+        </callbacks>
+        <parameters>
+            <parameter datatype="number"  min_n_values="1"  max_n_values="1"  name="AssistantCommunityId"  description="Specify the community id whose members we will use in the Assistant field in the add section form."/>
+            <parameter datatype="number"  min_n_values="1"  max_n_values="1"  name="InstructorCommunityId"  description="Specify the community id whose members we will use in the Instructors field in Add Section."/>
+            <parameter datatype="number"  min_n_values="1"  max_n_values="1"  name="MemberPriceP"  default="0" description="Whether we give special sale price to members."/>
+            <parameter datatype="number"  min_n_values="1"  max_n_values="1"  name="PatronRelationshipCategoryTree"  description="Category tree to use when adding participant-patron relationships."/>
+        </parameters>
+
+    </version>
+</package>
Index: openacs-4/packages/dotlrn-ecommerce/lib/tree-chunk.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/lib/tree-chunk.adp,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/dotlrn-ecommerce/lib/tree-chunk.adp	31 May 2005 22:04:53 -0000	1.1
@@ -0,0 +1,20 @@
+<br>
+
+<STYLE TYPE="text/css">
+table.list {
+  font-family: tahoma, verdana, helvetica; 
+  border-collapse: collapse;
+  font-size: 11px;
+}
+</STYLE>
+
+<table cellpadding="3" cellspacing="3">
+  <tr>
+    <td class="list-filter-pane-big" valign="top" width=20%>
+        <listfilters name="course_list" style="course-filters"></listfilters>
+    </td>
+    <td valign="top">
+	<listtemplate name=course_list style="courses"></listtemplate>
+    </td>
+  </tr>
+</table>
Index: openacs-4/packages/dotlrn-ecommerce/lib/tree-chunk.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/lib/tree-chunk.tcl,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/dotlrn-ecommerce/lib/tree-chunk.tcl	31 May 2005 22:04:53 -0000	1.1
@@ -0,0 +1,381 @@
+ad_page_contract {
+    Display an ident tree of categories and courses.
+    @author          Miguel Marin (miguelmarin@viaro.net)
+    @author          Viaro Networks www.viaro.net
+    @creation-date   11-02-2005
+
+} {
+    category_f:optional
+    uncat_f:optional
+
+    { level "" }
+
+    { orderby course_name }
+    { groupby course_name }
+}
+
+set package_id [ad_conn package_id]
+set user_id [ad_conn user_id]
+
+# Generate filters based on categories
+set filters {
+    category_f {
+	label "[_ dotlrn-catalog.categories]"
+	values { ${Course Type} }
+	where_clause { ${Course Type_where_query} }
+    }
+    uncat_f {
+	label "[_ dotlrn-catalog.uncat]"
+	values { "Watch" }
+	where_clause { dc.course_id not in ( select object_id from category_object_map where category_id in \
+						 ( select category_id from categories where tree_id =:tree_id ))
+	}
+    }
+}
+
+set filter_list [list category_f]
+
+set form [ns_getform]
+
+foreach tree [category_tree::get_mapped_trees $package_id] {
+    set tree_name [lindex $tree 1]
+    regsub -all { } $tree_name _ f
+    set f [string tolower $f]_f
+
+    ns_log notice "DEBUG:: CATEGORY:: $tree_name"
+
+    lappend filter_list $f
+    set ff [ns_set get $form $f]
+
+    if { ! [empty_string_p $ff] } {
+	set $f $ff
+    }
+}
+
+ns_log notice "DEBUG:: FILTER:: $filter_list"
+
+foreach f $filter_list {
+    if { [info exists $f] } {
+	set var_list [split [set $f] "&"]
+	set ${f}_category_v [lindex $var_list 0]
+	set ${f}_level [lindex [split [lindex $var_list 1] "="] 1]
+    } else {
+	set ${f}_category_v ""
+	set ${f}_level ""
+    }
+
+    ns_log notice "DEBUG:: VARS:: category_v [set ${f}_category_v], level [set ${f}_level]"
+}
+
+if { ! [empty_string_p $level] } {
+    set category_f_level $level
+}
+
+# Get all tree categories
+set category_trees [linsert [category_tree::get_mapped_trees $package_id] 0 $tree_id]
+
+set count 0
+foreach tree_id $category_trees {
+
+    set tree_id [lindex $tree_id 0]
+
+    set tree_list [category_tree::get_tree -all $tree_id]
+    set tree_length [llength $tree_list]
+
+    db_1row get_tree_name {
+	select name
+	from category_trees t, category_tree_translations tt
+	where t.tree_id = tt.tree_id
+	and t.tree_id = :tree_id
+    }
+
+    # Create a list of values for the list filter
+    set $name [list]
+
+    foreach element $tree_list {
+	set ident [lindex $element 3]
+	set spacer ""
+	for { set i 1 } { $i < $ident } { incr i } {
+	    append spacer ". . "
+	}
+	lappend $name [list "${spacer}[lindex "$element" 1]" "[lindex $element 0]&level=[lindex $element 3]" ]
+    }
+
+    if { $count == 0 } {
+	set f category_f
+    } else {
+	regsub -all { } $name _ f
+	set f [string tolower $f]_f
+    }
+
+    # Get all sub categories
+    set map_tree "("
+    if { ![string equal [set ${f}_level] ""] } {
+	ns_log notice "DEBUG:: SUBCATEGORIES:: $f, $tree_length"
+	
+	set j 0
+	set i 0
+	while { $i < $tree_length } {
+	    set element [lindex $tree_list $i]
+	    if {[string equal [set ${f}_category_v] [lindex $element 0]] } {
+		append map_tree "[lindex $element 0],"
+		set pos $i
+		set i $tree_length
+	    }
+	    incr i
+	}
+	set j 0
+	set i [expr $pos + 1]
+	while { $i < $tree_length } {
+	    set element [lindex $tree_list $i]
+	    if { [set ${f}_level] < [lindex $element 3] } {
+		append map_tree "[lindex $element 0],"
+		incr i
+	    } else {
+		set i $tree_length
+	    }
+	}
+	append map_tree "0)"
+    }
+    
+    if { $count == 0 } {
+	if { [string equal $[set ${f}_category_v] ""] } {
+	    set ${name}_where_query "dc.course_id in ( select object_id from category_object_map_tree where tree_id = $tree_id )" 
+	} else {
+	    set ${name}_where_query "dc.course_id in ( select object_id from category_object_map_tree where tree_id = $tree_id and category_id in $map_tree )"
+	}
+    } else {
+	if { [string equal $[set ${f}_category_v] ""] } {
+	    set ${name}_where_query "dec.community_id in ( select object_id from category_object_map_tree where tree_id = $tree_id )" 
+	} else {
+	    set ${name}_where_query "dec.community_id in ( select object_id from category_object_map_tree where tree_id = $tree_id and category_id in $map_tree )"
+	}
+    }
+    incr count
+}
+
+foreach tree [category_tree::get_mapped_trees $package_id] {
+    set tree_name [lindex $tree 1]
+    regsub -all { } $tree_name _ f
+    set f [string tolower $f]_f
+
+    lappend filters "$f" \
+	[list \
+	     label "$tree_name" \
+	     values "[set $tree_name]" \
+	     where_clause "[set ${tree_name}_where_query]"
+	]
+}
+
+# Section categories
+#foreach section_tree [category_tree::get_mapped_trees $package_id] {
+#    set tree_list [category_tree::get_tree -all $section_tree]
+#}
+
+# 	age_description_f {
+# 	    label "Age Description"
+# 	    values { ${Age Description} }
+# 	    where_clause { ${Age Description_where_query} }
+# 	}
+
+set cc_package_id [apm_package_id_from_key "dotlrn-catalog"]
+set admin_p [permission::permission_p -object_id $cc_package_id -privilege "admin"]
+template::list::create \
+    -name course_list \
+    -multirow course_list \
+    -key course_id \
+    -pass_properties { admin_p } \
+    -actions {"View All" ? "View All"} \
+    -filters $filters \
+    -bulk_action_method post \
+    -bulk_action_export_vars {
+    }\
+    -row_pretty_plural "[_ dotlrn-catalog.courses]" \
+    -elements {
+	course_key  {
+	    label "[_ dotlrn-catalog.course_key]"
+	    display_template {
+		<div align=left>
+		<a href="sections?course_id=@course_list.course_id@">@course_list.course_key@</a>
+		</div>
+	    }
+	    hide_p 1
+	}
+	name  {
+	    label "[_ dotlrn-catalog.course_name]"
+	    display_template {
+		<div align=left>
+		@course_list.course_name@
+		</div>
+	    }
+	    hide_p 1
+	}
+	section_name {
+	    label ""
+	    display_template {
+		<if @course_list.section_id@ not nil>
+		<if @admin_p@ eq 1 or @course_list.member_p@ eq 1>
+		<b>Section <a href="@course_list.community_url;noquote@">@course_list.section_name@</a></b>
+		</if>
+		<else>
+		<b>Section @course_list.section_name@</b>
+		</else>
+		<if @course_list.section_grades@ not nil> (@course_list.section_grades@)</if>
+		<if @course_list.sessions@ not nil><br />@course_list.sessions;noquote@</if>
+		<if @course_list.instructors@ not nil><br />@course_list.instructors;noquote@</if>
+		<if @course_list.prices@ not nil><br />@course_list.prices;noquote@</if>
+	    }
+	    html { width 50% }
+	}
+	category {
+	    label "[_ dotlrn-catalog.category]"
+	    display_template {
+		<div align=center>
+		<if @course_list.category_name@ not eq "">
+		@course_list.category_name@
+		</if>
+		<else>
+		#dotlrn-catalog.uncat#
+		</else>
+		</div>
+	    }
+	    hide_p 1
+	}
+	actions {
+	    label ""
+	    display_template {
+		<if @course_list.member_p@ eq 0>
+		(<a href="/ecommerce/shopping-cart-add?product_id=@course_list.product_id@">add to cart</a>)
+		</if>
+
+		<if @admin_p@ eq 1>
+		(<a href="@course_list.section_edit_url;noquote@">edit</a>)
+		</if>
+		</if>
+	    }
+	    html { width 50% }
+	}
+    } -orderby {
+	course_name {
+	    orderby course_name
+	}
+    } -groupby {
+	label "Group by"
+	type multivar
+	values {
+	    { { <if @admin_p@ eq 1>(<a href="admin/course-info?course_id=@course_list.course_id@">info</a>) (<a href="@course_list.course_edit_url;noquote@">edit</a>) (<a href="admin/section-add-edit?course_id=@course_list.course_id@&return_url=/dotlrn-ecommerce/index">add section</a>)</if>
+		<br />@course_list.course_grades@
+		<blockquote>
+		@course_list.course_info;noquote@
+		</blockquote>}
+		{ {groupby course_name} {orderby course_name} } }
+	}
+    }
+
+
+set instructor_community_id [parameter::get -package_id [ad_conn package_id] -parameter InstructorCommunityId -default 0 ]
+set _instructors [dotlrn_community::list_users $instructor_community_id]
+if { [llength $_instructors] == 0 } {
+    set _instructors 0
+} else {
+    foreach instructor $_instructors {
+	lappend __instructors [ns_set get $instructor user_id]
+    }
+}
+set grade_tree_id [db_string grade_tree {
+    select tree_id
+    from category_tree_translations 
+    where name = 'Grade'
+} -default 0]
+
+db_multirow -extend { category_name community_url course_edit_url section_edit_url course_grades section_grades sections_url member_p sessions instructors prices } course_list get_courses { } {
+#     set mapped [category::get_mapped_categories $course_id]
+
+#     foreach element $mapped {
+# 	append category_name "[category::get_name $element], "
+#     }
+
+    set category_name [string range $category_name 0 [expr [string length $category_name] - 3]]
+    set community_url [dotlrn_community::get_community_url $community_id]
+    set return_url [ad_return_url]
+    set course_edit_url [export_vars -base admin/course-add-edit { course_id return_url }]
+    set section_edit_url [export_vars -base admin/section-add-edit { course_id section_id return_url }]
+    set sections_url [export_vars -base sections { course_id }]
+
+    set member_p [dotlrn_community::member_p $community_id $user_id]
+    
+    set section_grades ""
+    set course_grades ""
+    set sessions ""
+    set instructors ""
+    set prices ""
+
+    array unset arr_sessions
+
+    if { ! [empty_string_p $community_id] } {
+
+	# List grades
+	set locale [ad_conn locale]
+	set section_grades [util_memoize [list dotlrn_ecommerce::section::section_grades $community_id $grade_tree_id]]
+
+	if { [llength $section_grades] == 1 } {
+	    set section_grades "Grade [join $section_grades ", "]"
+	} elseif { [llength $section_grades] > 1 } {
+	    set section_grades "Grades [join $section_grades ", "]"
+	} else {
+	    set section_grades ""
+	}
+
+	set course_grades [util_memoize [list dotlrn_ecommerce::section::course_grades $item_id $grade_tree_id]]
+
+	set letters [lsearch -all -inline -regexp $course_grades {[[:alpha:]]+}]
+	set numbers [lsearch -all -inline -regexp $course_grades {\d+}]
+	set numbers [lsort -integer $numbers]
+	set course_grades [concat $letters $numbers]
+
+	if { [llength $course_grades] == 1 } {
+	    set course_grades "Grade [join $course_grades ", "]"
+	} elseif { [llength $course_grades] > 1 } {
+	    set course_grades "Grades [join $course_grades ", "]"
+	} else {
+	    set course_grades ""
+	}
+
+	# Build sessions
+	set calendar_id [dotlrn_calendar::get_group_calendar_id -community_id $community_id]
+
+	set sessions [util_memoize [list dotlrn_ecommerce::section::sessions $calendar_id]]
+
+	set instructors [util_memoize [list dotlrn_ecommerce::section::instructors $community_id $__instructors]]
+
+	if { [llength $instructors] == 1 } {
+	    set instructors "Instructor: [join $instructors ", "] (<a href=\"${community_url}facilitator-bio\">view bio</a>)"
+	} elseif { [llength $instructors] > 1 } {
+	    set instructors "Instructors: [join $instructors ", "] (<a href=\"${community_url}facilitator-bio\">view bios</a>)"
+	} else {
+	    set instructors ""
+	}
+    }
+
+    if { ! [empty_string_p $product_id] } {
+	db_1row price {
+	    select price as prices
+	    from ec_products
+	    where product_id = :product_id
+	}
+	if { [parameter::get -package_id [ad_conn package_id] -parameter MemberPriceP -default 0 ] } {
+	    if { [db_0or1row member_price {
+		select sale_price as member_price
+		from ec_sale_prices
+		where product_id = :product_id
+		limit 1
+	    }] } {
+		if { ! [empty_string_p $member_price] } {
+		    append prices " / $member_price"
+		}
+	    }
+	}
+	
+	set prices \$$prices
+    }
+}
\ No newline at end of file
Index: openacs-4/packages/dotlrn-ecommerce/lib/tree-chunk.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/lib/Attic/tree-chunk.xql,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/dotlrn-ecommerce/lib/tree-chunk.xql	31 May 2005 22:04:53 -0000	1.1
@@ -0,0 +1,22 @@
+<?xml version="1.0"?>
+<queryset>
+
+<fullquery name="get_courses">
+      <querytext>
+            select dc.course_id, dc.course_key, dc.course_name,
+	      	   dc.assessment_id, dec.section_id, dec.section_name,
+		   dec.product_id, dec.community_id, dc.course_info,
+      		   ci.item_id
+            from dotlrn_catalog dc,
+	    cr_items ci
+	    left join dotlrn_ecommerce_section dec
+	    on (ci.item_id = dec.course_id)
+		 
+            where dc.course_id = ci.live_revision
+            [template::list::filter_where_clauses -and -name course_list]
+
+	    order by lower(dc.course_name), lower(dec.section_name)
+        </querytext>
+</fullquery>
+
+</queryset>
Index: openacs-4/packages/dotlrn-ecommerce/sql/postgresql/dotlrn-ecommerce-create.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/sql/postgresql/dotlrn-ecommerce-create.sql,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/dotlrn-ecommerce/sql/postgresql/dotlrn-ecommerce-create.sql	31 May 2005 22:04:53 -0000	1.1
@@ -0,0 +1,44 @@
+-- 
+-- packages/dotlrn-ecommerce/sql/postgresql/dotlrn-ecommerce-create.sql
+-- 
+-- @author Roel Canicula (roelmc@pldtdsl.net)
+-- @creation-date 2005-05-14
+-- @arch-tag: 8371aa52-3001-45da-9391-e181130bbedf
+-- @cvs-id $Id: dotlrn-ecommerce-create.sql,v 1.1 2005/05/31 22:04:53 hamiltonc Exp $
+--
+
+--- creating table to add section
+
+create table dotlrn_ecommerce_section (
+	section_id      integer primary key,
+	course_id 	integer references cr_items(item_id),
+	community_id    integer references dotlrn_communities_all(community_id),
+	product_id	integer references  ec_products,
+	section_name	varchar(2000),
+	age		varchar(2000),
+	date_time_start timestamptz,  	   
+	date_time_end	timestamptz,
+	daily_p		char(1) check (daily_p in ('t','f')),
+	weekly_p        char(1) check (weekly_p in ('t','f')),	
+	qualified_age_low   integer,
+	qualified_age_high  integer,
+	account_code_revenue varchar(100),
+	account_code_expense varchar(100),
+	max_participants     integer,
+	waiting_list_p       char(1) check (daily_p in ('t','f')),
+	notify_waiting_number integer,
+	member_price_number   numeric,
+	non_member_price      numeric
+);
+
+create index dotlrn_ecommerce_community_id_idx ON dotlrn_ecommerce_section (community_id);
+create index dotlrn_ecommerce_product_id_idx ON dotlrn_ecommerce_section (product_id);
+create index dotlrn_ecommerce_course_id_idx ON dotlrn_ecommerce_section (course_id);
+
+-- Term - comes from site-wide categories
+-- instructors - come from from instructors group
+-- asssistants - come from assistants group
+-- actual dates - comes from the calendar items in the community
+
+select acs_rel_type__create_role('as_session_role', 'Assessment Sessions Role', 'Assessment Sessions Role');
+select acs_rel_type__create_role('ec_product_role', 'Ecommerce Product Role', 'Ecommerce Product Role');
\ No newline at end of file
Index: openacs-4/packages/dotlrn-ecommerce/sql/postgresql/dotlrn-ecommerce-drop.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/sql/postgresql/dotlrn-ecommerce-drop.sql,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/dotlrn-ecommerce/sql/postgresql/dotlrn-ecommerce-drop.sql	31 May 2005 22:04:53 -0000	1.1
@@ -0,0 +1,13 @@
+-- 
+-- packages/dotlrn-ecommerce/sql/postgresql/dotlrn-ecommerce-drop.sql
+-- 
+-- @author Roel Canicula (roelmc@pldtdsl.net)
+-- @creation-date 2005-05-14
+-- @arch-tag: 6aff811d-34fc-46ac-bf89-4c26378075bc
+-- @cvs-id $Id: dotlrn-ecommerce-drop.sql,v 1.1 2005/05/31 22:04:53 hamiltonc Exp $
+--
+
+drop table dotlrn_ecommerce_section;
+
+select acs_rel_type__drop_role('as_session_role');
+select acs_rel_type__drop_role('ec_product_role');
\ No newline at end of file
Index: openacs-4/packages/dotlrn-ecommerce/sql/postgresql/dotlrn-ecommerce-memberships-create.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/sql/postgresql/dotlrn-ecommerce-memberships-create.sql,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/dotlrn-ecommerce/sql/postgresql/dotlrn-ecommerce-memberships-create.sql	31 May 2005 22:04:53 -0000	1.1
@@ -0,0 +1,172 @@
+-- plpgsql procedures for dotlrn catalog
+
+-- create new rel types for club/student
+
+
+create table dotlrn_club_student_rels (
+    rel_id                      integer
+                                constraint dotlrn_club_student_rels_rel_id_fk
+                                references membership_rels (rel_id)
+                                constraint dotlrn_club_student_rels_rel_id_pk
+                                primary key
+);                                          
+
+create view dotlrn_club_student_rels_full
+as
+    select acs_rels.rel_id as rel_id,
+           acs_rels.object_id_one as community_id,
+           acs_rels.object_id_two as user_id,
+           acs_rels.rel_type,
+           (select acs_rel_types.role_two
+            from acs_rel_types
+            where acs_rel_types.rel_type = acs_rels.rel_type) as role,
+           membership_rels.member_state
+    from dotlrn_club_student_rels,
+         acs_rels,
+         membership_rels
+    where dotlrn_club_student_rels.rel_id = acs_rels.rel_id
+    and acs_rels.rel_id = membership_rels.rel_id;
+
+create view dotlrn_club_student_rels_approved
+as
+    select *
+    from dotlrn_club_student_rels_full
+    where member_state = 'approved';
+ 
+select define_function_args('dotlrn_club_student_rel__new','rel_id,rel_type;dotlrn_club_student_rel,portal_id,community_id,user_id,member_state;approved,creation_user,creation_ip');
+
+create or replace function dotlrn_club_student_rel__new(integer,varchar,integer,integer,integer,varchar,integer,varchar)
+returns integer as '
+DECLARE
+        p_rel_id                alias for $1;
+        p_rel_type              alias for $2;
+        p_portal_id             alias for $3;
+        p_community_id          alias for $4;
+        p_user_id               alias for $5;
+        p_member_state          alias for $6;
+        p_creation_user         alias for $7;
+        p_creation_ip           alias for $8;
+        v_rel_id                integer;
+BEGIN
+        v_rel_id:= dotlrn_member_rel__new(
+            p_rel_id,
+            p_rel_type,
+            p_portal_id,
+            p_community_id,
+            p_user_id,
+            p_member_state,
+            p_creation_user,
+            p_creation_ip
+        );
+
+        insert
+        into dotlrn_club_student_rels
+        (rel_id)
+        values
+        (v_rel_id);
+
+        return v_rel_id;
+END;
+' language 'plpgsql';
+
+
+select define_function_args('dotlrn_club_student_rel__delete','rel_id');
+
+create function dotlrn_club_student_rel__delete(integer)
+returns integer as '
+DECLARE
+        p_rel_id                alias for $1;
+BEGIN
+        delete from dotlrn_club_student_rels where rel_id = p_rel_id; 
+
+        PERFORM membership_rel__delete(p_rel_id);
+
+        return 0;
+END;
+' language 'plpgsql';
+
+
+
+
+create table dotlrn_club_instructor_rels (
+    rel_id                      integer
+                                constraint dotlrn_club_instructor_rels_rel_id_fk
+                                references membership_rels (rel_id)
+                                constraint dotlrn_club_instructor_rels_rel_id_pk
+                                primary key
+);                                          
+
+create view dotlrn_club_instructor_rels_full
+as
+    select acs_rels.rel_id as rel_id,
+           acs_rels.object_id_one as community_id,
+           acs_rels.object_id_two as user_id,
+           acs_rels.rel_type,
+           (select acs_rel_types.role_two
+            from acs_rel_types
+            where acs_rel_types.rel_type = acs_rels.rel_type) as role,
+           membership_rels.member_state
+    from dotlrn_club_instructor_rels,
+         acs_rels,
+         membership_rels
+    where dotlrn_club_instructor_rels.rel_id = acs_rels.rel_id
+    and acs_rels.rel_id = membership_rels.rel_id;
+
+create view dotlrn_club_instructor_rels_approved
+as
+    select *
+    from dotlrn_club_instructor_rels_full
+    where member_state = 'approved';
+ 
+select define_function_args('dotlrn_club_instructor_rel__new','rel_id,rel_type;dotlrn_club_instructor_rel,portal_id,community_id,user_id,member_state;approved,creation_user,creation_ip');
+
+create or replace function dotlrn_club_instructor_rel__new(integer,varchar,integer,integer,integer,varchar,integer,varchar)
+returns integer as '
+DECLARE
+        p_rel_id                alias for $1;
+        p_rel_type              alias for $2;
+        p_portal_id             alias for $3;
+        p_community_id          alias for $4;
+        p_user_id               alias for $5;
+        p_member_state          alias for $6;
+        p_creation_user         alias for $7;
+        p_creation_ip           alias for $8;
+        v_rel_id                integer;
+BEGIN
+        v_rel_id:= dotlrn_member_rel__new(
+            p_rel_id,
+            p_rel_type,
+            p_portal_id,
+            p_community_id,
+            p_user_id,
+            p_member_state,
+            p_creation_user,
+            p_creation_ip
+        );
+
+        insert
+        into dotlrn_club_instructor_rels
+        (rel_id)
+        values
+        (v_rel_id);
+
+        return v_rel_id;
+END;
+' language 'plpgsql';
+
+
+select define_function_args('dotlrn_club_instructor_rel__delete','rel_id');
+
+create function dotlrn_club_instructor_rel__delete(integer)
+returns integer as '
+DECLARE
+        p_rel_id                alias for $1;
+BEGIN
+        delete from dotlrn_club_instructor_rels where rel_id = p_rel_id; 
+
+        PERFORM membership_rel__delete(p_rel_id);
+
+        return 0;
+END;
+' language 'plpgsql';
+
Index: openacs-4/packages/dotlrn-ecommerce/tcl/apm-callback-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/tcl/apm-callback-procs.tcl,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/dotlrn-ecommerce/tcl/apm-callback-procs.tcl	31 May 2005 22:04:53 -0000	1.1
@@ -0,0 +1,50 @@
+# packages/dotlrn-ecommerce/tcl/apm-callback-procs.tcl
+
+ad_library {
+    
+    APM Callbacks
+    
+    @author Roel Canicula (roelmc@pldtdsl.net)
+    @creation-date 2005-05-15
+    @arch-tag: 14c74f81-76d3-4891-af33-8b63166ae80f
+    @cvs-id $Id: apm-callback-procs.tcl,v 1.1 2005/05/31 22:04:53 hamiltonc Exp $
+}
+
+namespace eval dotlrn_ecommerce {}
+
+ad_proc -private dotlrn_ecommerce::install {
+} {
+    After install callback
+    
+    @author Roel Canicula (roelmc@pldtdsl.net)
+    @creation-date 2005-05-15
+    
+    @return 
+    
+    @error 
+} {
+
+    # add new rel types for student and instructors
+    rel_types::new -supertype dotlrn_member_rel -role_two student dotlrn_club_student_rel "dotLRN Club Student" "dotLRN Club Students" dotlrn_club 0 "" user 0 ""
+    rel_types::new -supertype dotlrn_member_rel -role_two instructor "dotLRN Club Instructor" "dotLRN Club Instructors" dotlrn_club 0 ""D user 0 ""
+
+    rel_types::new -role_one user -role_two user patron_rel "Patron" "Patrons" user 0 65535 user 0 65535
+
+    # Associate a dotlrn_catalog course to an assessment session result
+    rel_types::new -role_one d_catalog_role -role_two as_session_role d_catalog_as_session_rel "dotLRN Catalog Course to Assessment Session" "dotLRN Catalog Courses to Assessment Sessions" dotlrn_catalog 0 1 as_sessions 0 1
+
+    # Associate an ecommerce product to an assessment session result
+    rel_types::new -role_one as_session_role -role_two ec_product_role as_session_ec_product_rel "Assessment Session to ECommerce Product" "Assessment Sessions to ECommerce Products" as_sessions 0 1 ec_product 0 1
+}
+
+ad_proc -private dotlrn-catalog::package_mount {
+    -package_id
+    -node_id
+} {
+    create the category tree for terms
+    
+} {
+    # To categorize courses
+    set tree_id [category_tree::add -name "dotlrn-section-terms"]
+    category_tree::map -tree_id $tree_id -object_id $package_id
+}
Index: openacs-4/packages/dotlrn-ecommerce/tcl/course-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/tcl/course-procs.tcl,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/dotlrn-ecommerce/tcl/course-procs.tcl	31 May 2005 22:04:53 -0000	1.1
@@ -0,0 +1,53 @@
+# packages/dotlrn-ecommerce/tcl/course-procs.tcl
+
+ad_library {
+    
+    Library procs for courses
+    
+    @author Roel Canicula (roelmc@pldtdsl.net)
+    @creation-date 2005-05-12
+    @arch-tag: 5389d524-92b4-4b90-a6f9-f9585134a8d0
+    @cvs-id $Id: course-procs.tcl,v 1.1 2005/05/31 22:04:53 hamiltonc Exp $
+}
+
+namespace eval dotlrn_ecommerce::course {}
+
+ad_proc -public dotlrn_ecommerce::course::new {
+    -name
+    {-description ""}
+} {
+    Create a dotlrn-catalog course
+    
+    @author Roel Canicula (roelmc@pldtdsl.net)
+    @creation-date 2005-05-12
+    
+    @param user_id
+
+    @param name
+
+    @param description
+
+    @return 
+    
+    @error 
+} {
+    set folder_id [dotlrn_catalog::get_folder_id]
+    set course_key [dotlrn_community::generate_key -name $name]
+
+    set assessment_id [dotlrn_ecommerce::section::get_assessment]
+
+    lappend attributes [list course_key $course_key]
+    lappend attributes [list course_name $name]
+    lappend attributes [list course_info $description]
+    lappend attributes [list assessment_id $assessment_id]
+    
+    set item_id [content::item::new \
+		     -name $course_key \
+		     -parent_id $folder_id \
+		     -content_type "dotlrn_catalog" \
+		     -attributes $attributes \
+		     -is_live t \
+		     -title $name]
+
+    return [content::item::get_live_revision -item_id $item_id]
+}
\ No newline at end of file
Index: openacs-4/packages/dotlrn-ecommerce/tcl/implementation-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/tcl/implementation-procs.tcl,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/dotlrn-ecommerce/tcl/implementation-procs.tcl	31 May 2005 22:04:53 -0000	1.1
@@ -0,0 +1,30 @@
+# packages/dotlrn-ecommerce/tcl/implementation-procs.tcl
+
+ad_library {
+    
+    
+    
+    @author Roel Canicula (roelmc@pldtdsl.net)
+    @creation-date 2005-05-19
+    @arch-tag: 776140e1-a8e8-4d30-84a7-46d8bf054187
+    @cvs-id $Id: implementation-procs.tcl,v 1.1 2005/05/31 22:04:53 hamiltonc Exp $
+}
+
+ad_proc -callback ecommerce::after-checkout -impl dotlrn-ecommerce {
+    -user_id
+    -product_id
+    -price
+} {
+    Add user to community
+} {
+    # Get community mapped to product
+    db_foreach communities {
+	select community_id
+	from dotlrn_ecommerce_section
+	where product_id = :product_id
+    } {
+	ns_log notice "dotlrn-ecommerce callback: Adding user $user_id to community $community_id"
+
+	dotlrn_community::add_user $community_id $user_id
+    }
+}
\ No newline at end of file
Index: openacs-4/packages/dotlrn-ecommerce/tcl/section-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/tcl/section-procs.tcl,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/dotlrn-ecommerce/tcl/section-procs.tcl	31 May 2005 22:04:53 -0000	1.1
@@ -0,0 +1,188 @@
+# packages/dotlrn-ecommerce/tcl/section-procs.tcl
+
+ad_library {
+    
+    Library procs for sections
+    
+    @author Roel Canicula (roelmc@pldtdsl.net)
+    @creation-date 2005-05-12
+    @arch-tag: 049a1d42-ebfc-4c90-98ae-11381703dc6d
+    @cvs-id $Id: section-procs.tcl,v 1.1 2005/05/31 22:04:53 hamiltonc Exp $
+}
+
+namespace eval dotlrn_ecommerce::section {}
+
+ad_proc -public dotlrn_ecommerce::section::instructors {
+    community_id
+    instructors
+} {
+    
+    
+    @author Roel Canicula (roelmc@pldtdsl.net)
+    @creation-date 2005-05-20
+    
+    @param community_id
+
+    @param instructors
+
+    @return 
+    
+    @error 
+} {
+    return [db_list instructors [subst {
+	select u.first_names||' '||u.last_name
+	from dotlrn_users u, dotlrn_member_rels_approved r
+	where u.user_id = r.user_id
+	and r.community_id = :community_id
+	and r.rel_type = 'dotlrn_admin_rel'
+	and r.user_id in ([join $instructors ,])
+    }]]
+}
+
+ad_proc -public dotlrn_ecommerce::section::section_grades {
+    community_id
+    grade_tree_id
+    {locale en_US}
+} {
+    
+    
+    @author Roel Canicula (roelmc@pldtdsl.net)
+    @creation-date 2005-05-20
+    
+    @return 
+    
+    @error 
+} {
+    return [db_list section_grades {
+	select t.name
+	from category_object_map_tree m, category_translations t
+	where t.category_id = m.category_id
+	and t.locale = coalesce(:locale, 'en_US')
+	and m.object_id = :community_id
+	and m.tree_id = :grade_tree_id
+    }]
+}
+
+ad_proc -public dotlrn_ecommerce::section::course_grades {
+    item_id
+    grade_tree_id
+    {locale en_US}
+} {
+    
+    
+    @author Roel Canicula (roelmc@pldtdsl.net)
+    @creation-date 2005-05-20
+    
+    @return 
+    
+    @error 
+} {
+    return [db_list course_grades {
+	select distinct t.name
+	from category_object_map_tree m, category_translations t
+	where t.category_id = m.category_id
+	and t.locale = coalesce(:locale, 'en_US')
+	and m.object_id in (select community_id
+			    from dotlrn_ecommerce_section
+			    where course_id = :item_id)
+	and m.tree_id = :grade_tree_id
+    }]
+}
+
+ad_proc -public dotlrn_ecommerce::section::sessions {
+    calendar_id
+} {
+    
+    
+    @author Roel Canicula (roelmc@pldtdsl.net)
+    @creation-date 2005-05-20
+    
+    @return 
+    
+    @error 
+} {
+    if { ! [db_0or1row session_type {
+	select item_type_id from cal_item_types where type='Session' and  calendar_id = :calendar_id limit 1
+    }] } {
+	set item_type_id [calendar::item_type_new -calendar_id $calendar_id -type "Session"]
+    }
+    set text_sessions [list]
+    array set arr_sessions [list]
+    db_foreach sessions {
+	select distinct to_char(start_date, 'Mon') as month, to_char(start_date, 'dd') as day, to_char(start_date, 'hh:mi') as start, to_char(end_date, 'hh:mi') as end, to_char(start_date, 'am') as startampm, to_char(end_date, 'am') as endampm
+	from cal_items ci, acs_events e, acs_activities a, timespans s, time_intervals t
+	where e.timespan_id = s.timespan_id
+	and s.interval_id = t.interval_id
+	and e.activity_id = a.activity_id
+	and e.event_id = ci.cal_item_id
+	and start_date >= current_date
+
+	and ci.on_which_calendar = :calendar_id
+	and ci.item_type_id = :item_type_id
+    } {
+	lappend arr_sessions($month) [list $day $start $end $startampm $endampm]
+    }
+
+    set days [list]
+    foreach month [array names arr_sessions] {
+	set _sessions $arr_sessions($month)
+
+	foreach day $_sessions {
+	    # if there's a better way to do this please tell me :)
+	    lappend days [expr 1[lindex $day 0] - 100]
+	}
+	if { [lindex $day 3] == [lindex $day 4] } {
+	    set time "[lindex $day 1]-[lindex $day 2][lindex $day 3]"
+	} else {
+	    set time "[lindex $day 1][lindex $day 3]-[lindex $day 2][lindex $day 4]"
+	}
+	lappend text_sessions "$month [join [lsort -integer $days] ,] $time"
+    }
+
+    set sessions [join $text_sessions ",<br />"]
+
+    return $sessions
+}
+
+ad_proc -public dotlrn_ecommerce::section::flush_cache {
+    section_id
+} {
+    
+    
+    @author Roel Canicula (roelmc@pldtdsl.net)
+    @creation-date 2005-05-20
+    
+    @param section_id
+
+    @return 
+    
+    @error 
+} {
+    db_1row section_info {
+	select community_id, course_id as item_id
+	from dotlrn_ecommerce_section
+	where section_id = :section_id
+    }
+    set instructor_community_id [parameter::get -package_id [ad_conn package_id] -parameter InstructorCommunityId -default 0 ]
+    set _instructors [dotlrn_community::list_users $instructor_community_id]
+    set __instructors [list]
+    if { [llength $_instructors] == 0 } {
+	set _instructors 0
+    } else {
+	foreach instructor $_instructors {
+	    lappend __instructors [ns_set get $instructor user_id]
+	}
+    }
+    set grade_tree_id [db_string grade_tree {
+	select tree_id
+	from category_tree_translations 
+	where name = 'Grade'
+    } -default 0]
+    set calendar_id [dotlrn_calendar::get_group_calendar_id -community_id $community_id]
+
+    # Start flushing
+    set section_grades [util_memoize_flush [list dotlrn_ecommerce::section::section_grades $community_id $grade_tree_id]]
+    set course_grades [util_memoize_flush [list dotlrn_ecommerce::section::course_grades $item_id $grade_tree_id]]
+    set sessions [util_memoize_flush [list dotlrn_ecommerce::section::sessions $calendar_id]]
+    set instructors [util_memoize_flush [list dotlrn_ecommerce::section::instructors $community_id $__instructors]]
+}
Index: openacs-4/packages/dotlrn-ecommerce/tcl/subject-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/tcl/subject-procs.tcl,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/dotlrn-ecommerce/tcl/subject-procs.tcl	31 May 2005 22:04:53 -0000	1.1
@@ -0,0 +1,14 @@
+# packages/dotlrn-ecommerce/tcl/subject-procs.tcl
+
+ad_library {
+    
+    Library procs for subjects
+    
+    @author Roel Canicula (roelmc@pldtdsl.net)
+    @creation-date 2005-05-12
+    @arch-tag: 4f658b5a-5fe8-47bf-8f44-fe9e4200311d
+    @cvs-id $Id: subject-procs.tcl,v 1.1 2005/05/31 22:04:53 hamiltonc Exp $
+}
+
+namespace eval dotlrn_ecommerce::subject {}
+
Index: openacs-4/packages/dotlrn-ecommerce/www/index.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/index.adp,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/dotlrn-ecommerce/www/index.adp	31 May 2005 22:04:53 -0000	1.1
@@ -0,0 +1,17 @@
+<master>
+<property name=title>@page_title@</property>
+<property name="context">@context;noquote@</property>
+
+<STYLE TYPE="text/css">
+td.list-filter-pane-big {
+  background-color: #ddddff;
+  vertical-align: top;
+  font-size: 14px;
+}
+</STYLE>
+
+<if @admin_p@ eq 1>
+    <div align="right"><a href="admin"><img border=0 src=/dotlrn-catalog/images/admin.gif></a></div>
+</if>
+
+<include src="/packages/dotlrn-ecommerce/lib/tree-chunk" tree_id=@tree_id@>
\ No newline at end of file
Index: openacs-4/packages/dotlrn-ecommerce/www/index.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/index.tcl,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/dotlrn-ecommerce/www/index.tcl	31 May 2005 22:04:53 -0000	1.1
@@ -0,0 +1,26 @@
+ad_page_contract {
+    Index for course administration
+    @author          Miguel Marin (miguelmarin@viaro.net) 
+    @author          Viaro Networks www.viaro.net
+    @creation-date   31-01-2005
+
+} {
+
+}
+set page_title "[_ dotlrn-catalog.course_catalog]"
+set context ""
+set return_url "dt-admin/course-list"
+
+set cc_package_id [apm_package_id_from_key "dotlrn-catalog"]
+
+set user_id [ad_conn user_id]
+
+if {[permission::permission_p -party_id $user_id -object_id $cc_package_id -privilege "create"]} {
+    set create_p 1
+} else {
+    set create_p 0
+}
+
+set tree_id [db_string get_tree_id { } -default "-1"]
+set add_course_url [export_vars -base admin/course-add-edit { return_url }]
+set admin_p [permission::permission_p -object_id $cc_package_id -privilege "admin"]
\ No newline at end of file
Index: openacs-4/packages/dotlrn-ecommerce/www/index.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/index.xql,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/dotlrn-ecommerce/www/index.xql	31 May 2005 22:04:53 -0000	1.1
@@ -0,0 +1,11 @@
+<?xml version="1.0"?>
+<queryset>
+
+<fullquery name="get_tree_id">      
+      <querytext>
+      	    select tree_id from category_tree_map where object_id = :cc_package_id
+      </querytext>
+</fullquery>
+
+
+</queryset>
\ No newline at end of file
Index: openacs-4/packages/dotlrn-ecommerce/www/sections.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/sections.adp,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/dotlrn-ecommerce/www/sections.adp	31 May 2005 22:04:53 -0000	1.1
@@ -0,0 +1,5 @@
+<master>
+
+  <listtemplate name="section_list"></listtemplate>
+  <p />
+  <a href="@return_url;noquote@" class="button">Back</a>
\ No newline at end of file
Index: openacs-4/packages/dotlrn-ecommerce/www/sections.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/sections.tcl,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/dotlrn-ecommerce/www/sections.tcl	31 May 2005 22:04:53 -0000	1.1
@@ -0,0 +1,85 @@
+# packages/dotlrn-ecommerce/www/sections.tcl
+
+ad_page_contract {
+    
+    
+    
+    @author Roel Canicula (roelmc@pldtdsl.net)
+    @creation-date 2005-05-17
+    @arch-tag: ebe33d91-6940-42d6-9ca9-2e4d280f0233
+    @cvs-id $Id: sections.tcl,v 1.1 2005/05/31 22:04:53 hamiltonc Exp $
+} {
+    course_id:integer,notnull
+    {return_url index}
+} -properties {
+} -validate {
+} -errors {
+}
+
+db_multirow -extend {community_url sessions member_price} section_list section_list { 
+    select des.*, p.price 
+    from dotlrn_ecommerce_section des, ec_products p, dotlrn_catalogi c
+    where des.product_id = p.product_id
+    and des.course_id = c.item_id
+    and c.course_id = :course_id
+} {
+    set community_url [dotlrn_community::get_community_url $community_id]
+
+    set calendar_id [dotlrn_calendar::get_group_calendar_id -community_id $community_id]
+    set calendar_url [calendar_portlet_display::get_url_stub $calendar_id]
+    set item_type_id [db_string item_type_id "select item_type_id from cal_item_types where type='Session' and  calendar_id = :calendar_id"]
+
+    set sessions [join [db_list sessions {
+	select to_char(start_date, 'Mon dd, yyyy hh:miam')
+	from cal_items ci, acs_events e, acs_activities a, timespans s, time_intervals t
+	where e.timespan_id = s.timespan_id
+	and s.interval_id = t.interval_id
+	and e.activity_id = a.activity_id
+	and e.event_id = ci.cal_item_id
+	and start_date >= current_date
+
+	and ci.on_which_calendar = :calendar_id
+	and ci.item_type_id = :item_type_id
+    }] {<br />}]
+    
+    if { [parameter::get -package_id [ad_conn package_id] -parameter MemberPriceP -default 0 ] } {
+	db_0or1row member_price {
+	    select sale_price as member_price
+	    from ec_sale_prices
+	    where product_id = :product_id
+	    limit 1
+	}
+    }
+}
+
+template::list::create \
+    -name section_list \
+    -multirow section_list \
+    -key section_id \
+    -bulk_action_method post \
+    -no_data "No Sections" \
+    -elements {
+	section_name {
+	    label "Section Title"
+	}
+	sessions {
+	    label "Sessions"
+	    display_template {
+		@section_list.sessions;noquote@
+	    }
+	}
+	price {
+	    label "Normal Price / Member Price"
+	    html { align center }
+	    display_template {
+		$@section_list.price@<if @section_list.member_price@ not nil> / $@section_list.member_price@</if>
+	    }
+	}
+	actions {
+	    label Actions
+	    html { align center }
+	    display_template {
+		<a href="/ecommerce/shopping-cart-add?product_id=@section_list.product_id@" class="button">add to cart</a>
+	    }
+	}
+    }
\ No newline at end of file
Index: openacs-4/packages/dotlrn-ecommerce/www/admin/course-add-edit.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/admin/course-add-edit.adp,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/dotlrn-ecommerce/www/admin/course-add-edit.adp	31 May 2005 22:04:53 -0000	1.1
@@ -0,0 +1,6 @@
+<master>
+<property name=title>@page_title@</property>
+<property name="context">@context;noquote@</property>
+
+<formtemplate id="add_course"></formtemplate>
+
Index: openacs-4/packages/dotlrn-ecommerce/www/admin/course-add-edit.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/admin/course-add-edit.tcl,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/dotlrn-ecommerce/www/admin/course-add-edit.tcl	31 May 2005 22:04:54 -0000	1.1
@@ -0,0 +1,192 @@
+ad_page_contract {
+    Displays a form to add a course or add a new revision of a course (edit)
+
+    @author          Miguel Marin (miguelmarin@viaro.net) 
+    @author          Viaro Networks www.viaro.net
+    @creation-date   27-01-2005
+
+} {
+    course_id:optional
+    mode:optional
+    { return_url "" }
+    { index "" }
+}
+
+set page_title ""
+set context ""
+
+set user_id [ad_conn user_id]
+set cc_package_id [apm_package_id_from_key "dotlrn-catalog"]
+if {[info exists course_id]} {
+    set revision_id $course_id
+} else {
+    set revision_id -1
+}
+
+# Check for create permissions over dotlrn-catalog package
+permission::require_permission -party_id $user_id -object_id $cc_package_id -privilege "create"
+
+if { [info exist mode] } {
+    if { [string equal $mode 1] } {
+	permission::require_permission -object_id $course_id -privilege "admin"
+    } 
+    set mode_p edit
+} else {
+    set mode_p edit
+}
+
+# Get assessments
+set asm_list [list [list "[_ dotlrn-catalog.not_associate]" "-1"]]
+db_foreach assessment { } {
+    if { [permission::permission_p -object_id $assessment_id -privilege "admin"] == 1 } {
+	lappend asm_list [list $title $assessment_id] 
+    }
+}
+
+# Get a list of all the attributes asociated to dotlrn_catalog
+set attribute_list [package_object_attribute_list -start_with dotlrn_catalog dotlrn_catalog]
+set elements ""
+
+# Creates the elements to show with ad_form
+set count 1
+foreach attribute $attribute_list {
+    switch [lindex $attribute 2] {
+	assessment_id { continue }
+	community_id { continue }
+    }
+    set element_mode ""
+    set aditional_type ""
+    set aditional_elements ""
+    switch [lindex $attribute 4] {
+	string {
+	    if { [string equal [lindex $attribute 2] "assessment_id"]} {
+                set aditional_type "(select)"
+                set aditional_elements [list options $asm_list]
+            } else {
+                if { [string equal [lindex $attribute 2] "course_key"]} {
+                    set element_mode [list mode $mode_p]
+                }
+            }
+	}
+	text {
+	    set aditional_type "(textarea)"
+	    # html element needs to be a list not in curly braces
+	    set aditional_elements [list html  {rows 10 cols 55}]
+	}
+	integer {
+	    if { [string equal [lindex $attribute 2] "assessment_id"]} {
+		set aditional_type "(select)"
+		set aditional_elements [list options $asm_list]
+	    }
+	}
+    }
+    if { $count > 3 } {
+	append aditional_type ",optional"
+    }
+    set element [list [lindex $attribute 2]:text${aditional_type} [list label [lindex $attribute 3]] $aditional_elements $element_mode]
+    lappend elements $element
+
+    incr count
+}
+
+# Create the form
+ad_form -name add_course -export {mode $mode} -form {
+    course_id:key
+    {return_url:text(hidden),optional}
+}
+
+
+ad_form -extend -name add_course -form $elements
+
+
+
+ad_form -extend -name add_course -form {
+    {category_ids:text(category),multiple,optional
+	{label "[_ dotlrn-catalog.categories]"}
+	{html {size 4}}
+	{value "$revision_id $cc_package_id"}
+    }
+}
+
+ad_form -extend -name add_course -on_submit {
+    if { $category_ids == [list [list $revision_id $cc_package_id]] } {
+	set category_ids ""
+    }
+} -new_data {
+    # New item and revision in the CR
+    set folder_id [dotlrn_catalog::get_folder_id]
+    set attribute_list [package_object_attribute_list -start_with dotlrn_catalog dotlrn_catalog]
+    set form_attributes [list]
+
+    # Create master community
+    set community_id [dotlrn_club::new -pretty_name "$course_name Section Template"]
+    # add the calendar item type "session"
+    set calendar_id [dotlrn_calendar::get_group_calendar_id -community_id $community_id]
+    set item_type_id [calendar::item_type_new -calendar_id $calendar_id -type "Session"]
+
+    foreach attribute $attribute_list {
+	set attr_name [lindex $attribute 2]
+	if { [info exists $attr_name] } {
+	    lappend form_attributes [list $attr_name [set $attr_name]]
+	}
+    }
+    if { [dotlrn_catalog::check_name -name $course_key] } {
+	set item_id [content::item::new -name $course_key -parent_id $folder_id \
+			 -content_type "dotlrn_catalog" -creation_user $user_id \
+			 -attributes $form_attributes -is_live t -title $course_key]
+    } else {
+	ad_return_complaint 1 "\#dotlrn-catalog.name_already\#"
+	ad_script_abort
+    }
+    # Grant admin privileges to the user over the item in the CR
+    permission::grant -party_id $user_id -object_id $item_id  -privilege "admin"
+    
+    set revision_id [db_string get_revision_id { } -default "-1"]
+    if { ![string equal $category_ids "-1"] } {
+	category::map_object -object_id $revision_id $category_ids
+    }
+} -edit_data {
+    # New revision in the CR
+    catch {
+	db_1row template_community {
+	    select community_id
+	    from dotlrn_catalogi
+	    where course_id = :course_id
+	}
+    }
+	
+    set folder_id [dotlrn_catalog::get_folder_id]
+    set item_id [dotlrn_catalog::get_item_id -revision_id $course_id]
+    set attribute_list [package_object_attribute_list -start_with dotlrn_catalog dotlrn_catalog]
+    set form_attributes [list]
+    foreach attribute $attribute_list {
+	set attr_name [lindex $attribute 2]
+	if { [info exists $attr_name] } {
+	    lappend form_attributes [list $attr_name [set $attr_name]]
+	}
+    }
+
+    set revision_id [content::revision::new -item_id $item_id -attributes $form_attributes -content_type "dotlrn_catalog"]
+
+    # Set the new revision live  
+    dotlrn_catalog::set_live -revision_id $revision_id
+    if { ![string equal $category_ids "-1"] } {
+	category::map_object -object_id $revision_id $category_ids
+    }
+
+} -new_request {
+    set context [list [list course-list "[_ dotlrn-catalog.course_list]"] "[_ dotlrn-catalog.new_course]"]
+    set page_title "[_ dotlrn-catalog.new_course]"
+    set revision_id "-1"
+} -edit_request {
+    set context [list [list course-list "[_ dotlrn-catalog.course_list]"] "[_ dotlrn-catalog.edit_course]"]
+    set page_title "[_ dotlrn-catalog.edit_course]"
+    db_1row get_course_info { }
+    db_string get_course_assessment { } -default "[_ dotlrn-catalog.not_associated]"
+} -after_submit {
+    if { $return_url == "" } {
+	# set return_url [export_vars -base course-info {course_id course_name course_key} ]
+	set return_url "course-info?course_id=$revision_id&course_name=$course_name&course_key=$course_key"
+    }
+    ad_returnredirect "$return_url"
+}
\ No newline at end of file
Index: openacs-4/packages/dotlrn-ecommerce/www/admin/course-add-edit.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/admin/course-add-edit.xql,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/dotlrn-ecommerce/www/admin/course-add-edit.xql	31 May 2005 22:04:54 -0000	1.1
@@ -0,0 +1,35 @@
+<?xml version="1.0"?>
+<queryset>
+
+<fullquery name="assessment">
+      <querytext>
+      	    select cr.title ,ci.item_id as assessment_id from 
+            cr_folders cf, cr_items ci, cr_revisions cr, as_assessments a 
+            where cr.revision_id = ci.latest_revision and a.assessment_id = cr.revision_id and 
+            ci.parent_id = cf.folder_id order by cr.title
+      </querytext>
+</fullquery>
+
+<fullquery name="get_course_info">      
+      <querytext>
+            select * from dotlrn_catalog where course_id = :course_id
+      </querytext>
+</fullquery>
+
+<fullquery name="get_course_assessment">
+      <querytext>
+      	    select cr.title from 
+            cr_folders cf, cr_items ci, cr_revisions cr, as_assessments a 
+            where cr.revision_id = ci.latest_revision and a.assessment_id = cr.revision_id and 
+            ci.parent_id = cf.folder_id and ci.item_id = :assessment_id order by cr.title
+      </querytext>
+</fullquery>
+
+<fullquery name="get_revision_id">      
+      <querytext>
+            select revision_id from cr_revisions where item_id = :item_id
+      </querytext>
+</fullquery>
+
+
+</queryset>
Index: openacs-4/packages/dotlrn-ecommerce/www/admin/course-attribute-add.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/admin/course-attribute-add.adp,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/dotlrn-ecommerce/www/admin/course-attribute-add.adp	31 May 2005 22:04:54 -0000	1.1
@@ -0,0 +1,6 @@
+<master>
+  <property name="title">Add Attribute</property>
+  <property name="context">{course-attributes {Course Attributes}}
+  {Add Attribute}</property>
+
+  <formtemplate id="attribute"></formtemplate>
\ No newline at end of file
Index: openacs-4/packages/dotlrn-ecommerce/www/admin/course-attribute-add.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/admin/course-attribute-add.tcl,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/dotlrn-ecommerce/www/admin/course-attribute-add.tcl	31 May 2005 22:04:54 -0000	1.1
@@ -0,0 +1,45 @@
+# packages/dotlrn-ecommerce/www/admin/course-attribute-add.tcl
+
+ad_page_contract {
+    
+    
+    
+    @author Roel Canicula (roelmc@pldtdsl.net)
+    @creation-date 2005-05-24
+    @arch-tag: 95d276e0-dd4f-4ab1-bf84-02369541f50d
+    @cvs-id $Id: course-attribute-add.tcl,v 1.1 2005/05/31 22:04:54 hamiltonc Exp $
+} {
+    
+} -properties {
+} -validate {
+} -errors {
+}
+
+set attribute_list [package_object_attribute_list -start_with dotlrn_catalog dotlrn_catalog]
+set sort_order [expr [llength $attribute_list] + 1]
+
+ad_form -name attribute -export {sort_order} -form {
+    name:text
+    title:text
+    {widget:text(select) {options {
+	{"String (textfield)" string} \
+	    {"Text (textbox)" text} \
+	    {Integer integer}
+    }}}
+} -on_submit {
+    array set spec [list string text text text integer integer]
+
+    content::type::attribute::new \
+	-content_type "dotlrn_catalog" \
+	-attribute_name $name \
+	-datatype $widget \
+	-pretty_name $title \
+	-sort_order $sort_order \
+	-column_spec $spec($widget)
+    
+    util_memoize_flush [list package_object_attribute_list_cached -start_with dotlrn_catalog -include_storage_types type_specific dotlrn_catalog]
+    util_memoize_flush [list package_object_attribute_list_cached -start_with acs_object -include_storage_types type_specific dotlrn_catalog]
+
+    ad_returnredirect course-attributes
+    ad_script_abort
+}
\ No newline at end of file
Index: openacs-4/packages/dotlrn-ecommerce/www/admin/course-attributes-delete.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/admin/course-attributes-delete.tcl,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/dotlrn-ecommerce/www/admin/course-attributes-delete.tcl	31 May 2005 22:04:54 -0000	1.1
@@ -0,0 +1,27 @@
+# packages/dotlrn-ecommerce/www/admin/course-attributes-delete.tcl
+
+ad_page_contract {
+    
+    
+    
+    @author Roel Canicula (roelmc@pldtdsl.net)
+    @creation-date 2005-05-24
+    @arch-tag: 3531c32e-3d16-4e9c-a58b-0b4c6651f82f
+    @cvs-id $Id: course-attributes-delete.tcl,v 1.1 2005/05/31 22:04:54 hamiltonc Exp $
+} {
+    name:multiple
+} -properties {
+} -validate {
+} -errors {
+}
+
+foreach attribute $name {
+    content::type::attribute::delete \
+	-content_type dotlrn_catalog \
+	-attribute_name $attribute \
+	-drop_column 1
+}
+
+util_memoize_flush [list package_object_attribute_list_cached -start_with dotlrn_catalog -include_storage_types type_specific dotlrn_catalog]
+
+ad_returnredirect course-attributes
\ No newline at end of file
Index: openacs-4/packages/dotlrn-ecommerce/www/admin/course-attributes.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/admin/course-attributes.adp,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/dotlrn-ecommerce/www/admin/course-attributes.adp	31 May 2005 22:04:54 -0000	1.1
@@ -0,0 +1,5 @@
+<master>
+  <property name="title">Course Attributes</property>
+  <property name="context">{Course Attributes}</property>
+
+  <listtemplate name="attributes"></listtemplate>
\ No newline at end of file
Index: openacs-4/packages/dotlrn-ecommerce/www/admin/course-attributes.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/admin/course-attributes.tcl,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/dotlrn-ecommerce/www/admin/course-attributes.tcl	31 May 2005 22:04:54 -0000	1.1
@@ -0,0 +1,52 @@
+# packages/dotlrn-ecommerce/www/admin/course-attributes.tcl
+
+ad_page_contract {
+    
+    
+    
+    @author Roel Canicula (roelmc@pldtdsl.net)
+    @creation-date 2005-05-24
+    @arch-tag: 787e3cbd-2eb2-4e8e-8ba6-8fde9a2643de
+    @cvs-id $Id: course-attributes.tcl,v 1.1 2005/05/31 22:04:54 hamiltonc Exp $
+} {
+    
+} -properties {
+} -validate {
+} -errors {
+}
+
+set attribute_list [package_object_attribute_list -start_with dotlrn_catalog dotlrn_catalog]
+
+ns_log notice "DEBUG:: ATTRIBUTES:: $attribute_list"
+
+template::multirow create attributes attribute_id name title sort_order widget
+
+set count 1
+foreach attribute $attribute_list {
+    template::multirow append attributes \
+	[lindex $attribute 0] \
+	[lindex $attribute 2] \
+	[lindex $attribute 3] \
+	$count \
+	[lindex $attribute 4]
+
+    incr count
+}
+
+template::list::create \
+    -name attributes \
+    -key name \
+    -elements {
+	name {
+	    label Name
+	}
+	title {
+	    label Title
+	}
+	widget {
+	    label Datatype
+	}
+    } \
+    -multirow attributes \
+    -actions {Add course-attribute-add Add} \
+    -bulk_actions {Delete course-attributes-delete Delete}
\ No newline at end of file
Index: openacs-4/packages/dotlrn-ecommerce/www/admin/course-delete.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/admin/course-delete.adp,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/dotlrn-ecommerce/www/admin/course-delete.adp	31 May 2005 22:04:54 -0000	1.1
@@ -0,0 +1,33 @@
+<master>
+<property name=title>@page_title@</property>
+<property name="context">@context;noquote@</property>
+<br>
+#dotlrn-catalog.this_course# <b>@rev_num@</b> 
+<if @assoc_num@ eq 1>
+    #dotlrn-catalog.version#
+</if>
+<else>
+    #dotlrn-catalog.versions#
+</else>
+
+<if @assoc_num@ eq 0>
+   #dotlrn-catalog.has_no#
+</if>
+<else>
+   <if @assoc_num@ eq 1>
+       #dotlrn-catalog.and_has_one#
+   </if>
+   <else>
+       #dotlrn-catalog.and_has# <b>@assoc_num@</b> #dotlrn-catalog.to_dotlrn#
+   </else>
+</else>
+<br>
+<if @sections@ eq 0>
+<b>#dotlrn-catalog.do_you_still#</b>
+<br><br>
+	    <formtemplate id="delete_course"></formtemplate>
+</if>
+<else>
+	    There are <b>@sections@</b> section(s) under this course
+	    and it cannot be deleted.
+</else>
\ No newline at end of file
Index: openacs-4/packages/dotlrn-ecommerce/www/admin/course-delete.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/admin/course-delete.tcl,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/dotlrn-ecommerce/www/admin/course-delete.tcl	31 May 2005 22:04:54 -0000	1.1
@@ -0,0 +1,43 @@
+ad_page_contract {
+    Displays a delete confirmation message and deletes the course
+    @author          Miguel Marin (miguelmarin@viaro.net) 
+    @author          Viaro Networks www.viaro.net
+    @creation-date   09-02-2005
+} {
+    object_id:notnull
+    course_key:notnull
+    creation_user:notnull
+}
+
+set page_title "[_ dotlrn-catalog.confirm_delete] $course_key"
+set context [list [list course-list "[_ dotlrn-catalog.course_list]"] "[_ dotlrn-catalog.delete_course]"]
+
+# Check for create permissions over dotlrn-catalog
+set user_id [ad_conn user_id]
+set cc_package_id [apm_package_id_from_key "dotlrn-catalog"]
+permission::require_permission -party_id $user_id -object_id $cc_package_id -privilege "create"
+
+
+set rev_assoc [dotlrn_catalog::check_rev_assoc -item_id $object_id]
+set rev_num [lindex $rev_assoc 0]
+set assoc_num [lindex $rev_assoc 1]
+
+db_1row sections {
+    select count(*) as sections
+    from dotlrn_ecommerce_section
+    where course_id = :object_id
+}
+
+if { ! $sections } {
+
+    ad_form -name delete_course -export {course_key $course_key creation_user $creation_user } -cancel_url "course-list" -form {
+	{object_id:text(hidden) 
+	    { value $object_id }
+	}
+    } -on_submit {
+	dotlrn_catalog::course_delete -item_id $object_id
+    } -after_submit {
+	ad_returnredirect "course-list"
+    }
+
+}
\ No newline at end of file
Index: openacs-4/packages/dotlrn-ecommerce/www/admin/course-info.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/admin/course-info.adp,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/dotlrn-ecommerce/www/admin/course-info.adp	31 May 2005 22:04:54 -0000	1.1
@@ -0,0 +1,122 @@
+<master>
+<property name=title>@page_title@</property>
+<property name="context">@context;noquote@</property>
+<br>
+
+
+<table>
+<if @index@ eq "yes">
+   <if @admin_p@ eq 1>
+   <div align="left">
+        <a href="dt-admin/course-info?course_id=@course_id@&course_name=@name@&course_key=@course_key@&index=yes" title="#dotlrn-catalog.admin_this#"><img border=0 src=images/admin.gif></a> 
+   </div>
+   </if>
+</if>
+<h3>#dotlrn-catalog.info#:</h3>
+<tr>
+   <td>
+   <if @edit@ eq yes>
+   <div align="right">
+	<a href=course-add-edit?course_id=@course_id@&mode=1&index=@to_index@ title="#dotlrn-catalog.new_ver#"><img border=0 src=/resources/Edit16.gif></a>
+   </div>
+   </if>
+   </td>
+  <td>
+    <b>#dotlrn-catalog.course_key#</b>
+  </td>
+  <td>
+    
+    @course_key@
+   </td>
+</tr>
+<tr><td></td>
+    <td><b>#dotlrn-catalog.course_name#</b></td><td>@name@</td>
+</tr>
+<tr><td></td>
+    <td valign=top><b>#dotlrn-catalog.course_info#</b></td><td>@info;noquote@</td>
+</tr>
+<if @revision@ eq yes>
+<tr><td></td>
+    <td>
+	<b>#dotlrn-catalog.dotlrn#:</b>
+    </td>
+    <td>
+	<if @rel@ eq 0>
+	   #dotlrn-catalog.no# 
+	  <if @edit@ eq "yes">
+	     <if @dotlrn_url@ eq "/dotlrn">
+             (<a href="dotlrn-list?course_id=@course_id@&course_key=@course_key@&course_name=@name@&return_url=@return_url@" title="#dotlrn-catalog.associate_this#"><i>#dotlrn-catalog.associate#</i></a>)</if>
+          </if>
+	</if>
+	<else>
+	   <if @index@ eq "yes">
+	       #dotlrn-catalog.yes# (<a href="dt-admin/course-details?course_id=@course_id@&course_key=@course_key@&return_url=@return_url@&course_name=@name@" title="#dotlrn-catalog.course_details#"><i>#dotlrn-catalog.watch#</i></a>)
+	   </if>
+	   <else>
+	       #dotlrn-catalog.yes# (<a href="course-details?course_id=@course_id@&course_key=@course_key@&return_url=@return_url@&course_name=@name@" title="#dotlrn-catalog.course_details#"><i>#dotlrn-catalog.watch#</i></a>)
+	   </else>
+	</else>
+    </td>
+</tr>
+</if>
+<if @asm@ not eq #dotlrn-catalog.not_associated#>
+    <tr><td></td>
+        <td><b>#dotlrn-catalog.asm#:</b></td><td>@asm@</td>
+    </tr>
+</if>
+<if @category_p@ eq "1">
+    <if @index@ not eq "yes">
+        <tr><td></td>
+	   <td>
+	       <b>#dotlrn-catalog.categorize#:</b>
+	   </td>
+    	   <td>#dotlrn-catalog.yes# (@category_name@)</td>
+        </tr>
+    </if>
+</if>
+<tr><td></td><td></td>
+<td>
+   <if @edit@ eq no>
+      <if @index@ eq "yes">
+	<if @asmid@ not eq "-1">
+	    <a class="button" href="/assessment/assessment?assessment_id=@asmid@">#dotlrn-catalog.enroll#</a>
+	</if>
+	<else>
+	   <br>
+	   <b>#dotlrn-catalog.enroll_not#</b>
+	</else>
+      </if>
+      <else>
+         <if @course_id@ eq @live_revision@>
+	     <img border=0 src="/dotlrn-catalog/images/live.gif">   
+         </if>
+         <else>
+	     <a href="go-live?course_key=@course_key@&revision_id=@course_id@" title="#dotlrn-catalog.make_live#"><img border=0 src="/dotlrn-catalog/images/golive.gif"></a>
+         </else>
+      </else>
+   </if>
+   <else>
+	<a class=button href=section-add-edit?course_id=@course_id@&return_url=@return_url@>Add a section</a>
+	<a class=button href=course-add-edit?course_id=@course_id@&mode=1>Edit</a>
+         <a class=button href="course-delete?object_id=@item_id@&creation_user=@creation_user@&course_key=@course_key@" title="#dotlrn-catalog.delete_this#">#dotlrn-catalog.delete#</a>
+	<if @category_p@ eq "-1">
+	   <a class=button href="course-categorize?course_id=@course_id@&name=@name@">#dotlrn-catalog.categorize#</a>
+	</if>
+   </td>
+   </else>
+</tr>
+
+<if @template_community_id@ defined>
+<tr>
+      <td></td>
+      <td><b>Template Community:</b></td>
+      <td><a href="@template_community_url;noquote@"
+	class="button">User</a> <a href="@template_community_url;noquote@one-community-admin" class="button">Admin</a> <a href="@template_calendar_url;noquote@" class="button">Add Session</a></td>
+</tr>
+</if>
+
+</table>
+
+<h3>Sections</h3>
+
+<listtemplate name=section_list></listtemplate>
\ No newline at end of file
Index: openacs-4/packages/dotlrn-ecommerce/www/admin/course-info.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/admin/course-info.tcl,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/dotlrn-ecommerce/www/admin/course-info.tcl	31 May 2005 22:04:54 -0000	1.1
@@ -0,0 +1,341 @@
+ad_page_contract {
+    Displays information of one course
+    @author          Miguel Marin (miguelmarin@viaro.net) 
+    @author          Viaro Networks www.viaro.net
+    @creation-date   15-02-2005
+} {
+    course_id:notnull
+    { index "" }
+    { return_url "" }
+} -validate {
+    course_exists {
+	# check if the course exists and set course_name and course_key
+	if {![db_0or1row get_course "select course_name, course_key from dotlrn_catalog where course_id=:course_id"]} {
+	    ad_return notfound
+	}
+    }
+}
+
+# TODO DaveB is there a Tcl proc for course info?
+
+if { [string equal $index ""] } {
+    set context [list [list "course-list" "[_ dotlrn-catalog.course_list]"] "[_ dotlrn-catalog.one_course_info]"]
+} else {
+    set context [list [list "../course-info?course_id=$course_id" "[_ dotlrn-catalog.one_course_info]"] "$course_name [_ dotlrn-catalog.course_info]"]
+    set return_url "${return_url}&index=yes"
+}
+
+# Check permission over course_id
+permission::require_permission -object_id $course_id -privilege "admin"
+
+db_1row get_course_info { } 
+set page_title "$course_key [_ dotlrn-catalog.course_info]"
+
+set asm_name [db_string get_asm_name { } -default "[_ dotlrn-catalog.not_associated]"]
+set item_id [dotlrn_catalog::get_item_id -revision_id $course_id]
+set creation_user [dotlrn_catalog::get_creation_user -object_id $item_id]
+set rel [dotlrn_catalog::has_relation -course_id $course_id]
+
+
+set dotlrn_url [dotlrn::get_url]
+if { ![info exists index] } {
+    set index ""
+}
+
+if { ![info exists to_index] } {
+    set to_index ""
+}
+
+if { [info exist return_url] } {
+    set return_url $return_url
+} else {
+    set return_url "course-info?course_id=$course_id&course_name=$name&course_key=$course_key"
+}
+
+if { ![info exists asmid] } {
+    set asmid "-1"
+}
+
+if { ![info exists revision] } {
+    set revision "no"
+}
+
+set category_p [db_string get_category { } -default -1]
+
+set info $course_info
+set name $course_name
+set edit "yes"
+set asm $asm_name
+set info [ad_html_text_convert -from text/enhanced -to text/plain $info]
+
+set cc_package_id [apm_package_id_from_key "dotlrn-catalog"]
+set tree_id [db_string get_tree_id { } -default "-1"]
+
+# Get the category name
+set category_name "[category::get_name [category::get_mapped_categories $course_id]]"
+
+# Check if user has admin permission over course_id
+set admin_p 0
+if { [permission::permission_p -object_id $cc_package_id -privilege "create"] } { 
+    set item_id [dotlrn_catalog::get_item_id -revision_id $course_id]
+    if { [permission::permission_p -object_id $course_id -privilege "admin"] } { 
+	set admin_p 1
+    } else {
+	set admin_p 0
+    }
+}
+
+
+set obj_n 0
+set dotlrn_class "("
+set dotlrn_com "("
+
+# For dotlrn associations
+db_multirow -extend { obj_n admin_p } relations relation { } {
+    set obj_n 1
+    if { [string equal $type "dotlrn_catalog_class_rel" ]} {
+	append dotlrn_class "'$object_id'"
+	append dotlrn_class ","
+    } else {
+	append dotlrn_com "'$object_id'"
+	append dotlrn_com ","
+    }
+}
+append dotlrn_class "0)"
+append dotlrn_com "0)"
+
+db_multirow classes_list get_dotlrn_classes { }
+
+template::list::create \
+    -name dotlrn_classes \
+    -multirow classes_list \
+    -key object_id \
+    -row_pretty_plural "[_ dotlrn-catalog.dotlrn_classes]" \
+    -elements {
+        class  {
+            label "[_ dotlrn-catalog.class_name]"
+            display_template {
+		<if $index not eq "">
+                   <a href="dotlrn-info?object_id=@classes_list.object_id@&type=class&course_id=$course_id&course_name=$name&course_key=$course_key">@classes_list.pretty_name@</a> 
+                </if> 
+		<else>
+		   <a href="../dotlrn-info?object_id=@classes_list.object_id@&type=class&course_id=$course_id&course_name=$name&course_key=$course_key">@classes_list.pretty_name@</a> 
+		</else>
+            }
+        }
+        dep_name {
+            label "[_ dotlrn-catalog.dep_name]"
+            display_template {
+                @classes_list.department_name@
+            }
+        }
+        term_name  {
+            label "[_ dotlrn-catalog.term_name]"
+            display_template {
+                    @classes_list.term_name@
+            }
+        }
+        subject  {
+            label "[_ dotlrn-catalog.subject_name]"
+            display_template {
+                    @classes_list.class_name@
+            }
+        }
+    }
+
+
+db_multirow com_list get_dotlrn_communities { }
+
+
+template::list::create \
+    -name dotlrn_communities \
+    -multirow com_list \
+    -key object_id \
+    -row_pretty_plural "[_ dotlrn-catalog.dotlrn_com]" \
+    -elements {
+        community  {
+            label "[_ dotlrn-catalog.com_name]"
+            display_template {
+		<if $index not eq "">
+                    <a href="dotlrn-info?object_id=@com_list.object_id@&type=community&course_id=$course_id&course_name=$name&course_key=$course_key">@com_list.pretty_name@</a>
+		</if>
+		<else>
+                    <a href="../dotlrn-info?object_id=@com_list.object_id@&type=community&course_id=$course_id&course_name=$name&course_key=$course_key">@com_list.pretty_name@</a>
+		</else>
+            }
+        }
+    }
+
+
+set return_url [ns_urlencode "course-info?course_id=$course_id&course_key=$course_key&course_name=$course_name"]
+
+
+set community_url ""
+
+db_multirow -extend {community_url calendar_url num_sessions attendees available_slots} section_list section_list { 
+    select s.section_id, s.section_name, s.product_id, s.community_id, v.maxparticipants
+    from dotlrn_ecommerce_section s, dotlrn_catalogi c, ec_custom_product_field_values v
+    where s.course_id = c.item_id
+    and c.course_id = :course_id
+    and s.product_id = v.product_id
+
+    order by lower(s.section_name)
+} {
+    ns_log notice "DEBUG:: $section_name, $community_id"
+
+    set community_url [dotlrn_community::get_community_url $community_id]
+
+    set calendar_id [dotlrn_calendar::get_group_calendar_id -community_id $community_id]
+
+    set calendar_url [calendar_portlet_display::get_url_stub $calendar_id]
+
+    set item_type_id [db_string item_type_id "select item_type_id from cal_item_types where type='Session' and  calendar_id = :calendar_id limit 1" -default 0]
+
+    set num_sessions [db_string num_sessions "select count(cal_item_id) from cal_items where on_which_calendar = :calendar_id and item_type_id = :item_type_id"]
+
+    db_1row attendees {
+	select count(*) as attendees
+	from dotlrn_member_rels_approved
+	where community_id = :community_id
+	and (rel_type = 'dotlrn_member_rel'
+        or rel_type = 'dotlrn_club_student_rel')
+    }
+
+    if { ! [empty_string_p $maxparticipants] } {
+	set available_slots [expr $maxparticipants - $attendees]
+    }
+}
+
+template::list::create \
+    -name section_list \
+    -multirow section_list \
+    -key section_id \
+    -bulk_action_method post \
+    -elements {
+	name {
+	    label "Name"
+	    display_template {
+		<a href=section-add-edit?course_id=$course_id&section_id=@section_list.section_id@&return_url=$return_url>@section_list.section_name@</a>
+	    }
+	}
+	community {
+	    label "Community"
+	    display_template {
+		<a href="@section_list.community_url;noquote@">User</a>-<a href="@section_list.community_url;noquote@/one-community-admin">Admin</a>
+	    }
+	}
+	product {
+	    label "Product"
+	    display_template {
+		<a href=/ecommerce/admin/products/one?product_id=@section_list.product_id@>Product</a>
+	    }
+	}
+	registration {
+	    label "Registration"
+	    display_template {
+		<a href=$community_url/members>Registrants</a><br>
+		@section_list.attendees@ participant<if @section_list.attendees@ ne 1>s</if><if @section_list.available_slots@ not nil>,<br />@section_list.available_slots@ available</if>
+	    }
+	}
+	num_sessions {
+	    label "Sessions"
+	    display_template {
+		<a href=\"@section_list.calendar_url@/view?[export_vars -url {{view list} {period_days 365}}]\" target=new>@section_list.num_sessions@ Sessions</a> Scheduled.<br> <a href=\"@section_list.calendar_url@/cal-item-new?[export_vars -url {calendar_id item_type_id {view day}}]\" target=new>Add Session</a>
+	    }
+	}
+	attendance {
+	    label "Attendance"
+	    display_template {
+		<a href=@section_list.community_url@attendance/admin/>Attendance</a>
+	    }
+	}
+	expenses {
+	    label "Expenses"
+	    display_template {
+		<a href=@section_list.community_url@expense-tracking/admin/>Expenses</a>
+	    }
+	}
+	members {
+	    label "Purchases"
+	    html { align center }
+	    display_template {
+		<a href="patrons?section_id=@section_list.section_id@">Patron</a><br>
+		<a href="process-purchase?section_id=@section_list.section_id@">Participant</a><br>
+		<a href="process-group-purchase?section_id=@section_list.section_id@">Group</a>
+	    }
+	}
+	actions {
+	    label "Actions"
+	    display_template { <a href="section-delete?section_id=@section_list.section_id@&return_url=$return_url">Remove</a> }
+
+         }
+    }
+
+# ad_form -name session -export { course_id return_url } -form {
+#     {session_name:text {label "Session Name"}}
+#     {session_description:text(textarea) {label "Section Description"} {html {cols 50 rows 5}}}
+#     {typical_start_time:date {label "Typical Start Time"} {format {[lc_get formbuilder_time_format]}}}
+#     {typical_end_time:date {label "Typical End Time"} {format {[lc_get formbuilder_time_format]}}}
+#     original_url:text(hidden)
+# } -on_request {
+#     set original_url [ad_return_url]
+# } -on_submit {
+
+#     set typical_start_time [lindex $typical_start_time 3]:[lindex $typical_start_time 4]
+#     set typical_end_time [lindex $typical_end_time 3]:[lindex $typical_end_time 4]
+
+#     db_dml new_session {
+# 	insert into dotlrn_ecommerce_predefined_sessions
+# 	(course_item_id, session_name, session_description, typical_start_time, typical_end_time)
+# 	values
+# 	(:item_id, :session_name, :session_description, :typical_start_time, :typical_end_time)
+#     }
+
+# } -after_submit {
+#     ad_returnredirect "$original_url#Sessions"
+#     ad_script_abort
+# }
+
+# template::list::create \
+#     -name sessions \
+#     -multirow sessions \
+#     -key session_id \
+#     -bulk_actions {Delete predefined-session-delete Delete} \
+#     -bulk_action_export_vars { {return_url "[ad_return_url]#Sessions"} } \
+#     -elements {
+# 	session_name {
+# 	    label "Session Name"
+# 	}
+# 	session_description {
+# 	    label "Session Description"
+# 	}
+# 	typical_start_time {
+# 	    label "Typical Start Time"
+# 	}
+# 	typical_end_time {
+# 	    label "Typical End Time"
+# 	}
+#     }
+
+# db_multirow sessions sessions {
+#     select session_id, session_name, session_description, to_char(typical_start_time, 'HH:MIAM') as typical_start_time, to_char(typical_end_time, 'HH:MIAM') as typical_end_time
+#     from dotlrn_ecommerce_predefined_sessions
+#     where course_item_id = :item_id
+# }
+
+catch {
+    db_1row template_community {
+	select c.community_id as template_community_id
+	from dotlrn_catalogi c
+	where c.course_id = :course_id
+    }
+
+    if { [empty_string_p $template_community_id] } {
+	unset template_community_id
+    } else {
+	set template_community_url [dotlrn_community::get_community_url $template_community_id]
+	set template_calendar_id [dotlrn_calendar::get_group_calendar_id -community_id $template_community_id]
+	set template_item_type_id [db_string item_type_id "select item_type_id from cal_item_types where type='Session' and  calendar_id = :template_calendar_id limit 1" -default 0]
+	set template_calendar_url [export_vars -base ${template_community_url}calendar/cal-item-new { {item_type_id $template_item_type_id} {calendar_id $template_calendar_id} {view day} }]
+    }
+}
\ No newline at end of file
Index: openacs-4/packages/dotlrn-ecommerce/www/admin/course-info.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/admin/course-info.xql,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/dotlrn-ecommerce/www/admin/course-info.xql	31 May 2005 22:04:54 -0000	1.1
@@ -0,0 +1,56 @@
+<?xml version="1.0"?>
+<queryset>
+
+<fullquery name="get_course_info">      
+      <querytext>
+            select dc.course_info, dc.assessment_id, cr.item_id
+	    from dotlrn_catalog dc, cr_revisions cr
+ 	    where cr.revision_id = :course_id and dc.course_id = :course_id
+      </querytext>
+</fullquery>
+
+<fullquery name="get_asm_name">
+      <querytext>
+            select cr.title from
+            cr_folders cf, cr_items ci, cr_revisions cr, as_assessments a
+            where cr.revision_id = ci.latest_revision and a.assessment_id = cr.revision_id and
+            ci.parent_id = cf.folder_id and ci.item_id = :assessment_id order by cr.title
+      </querytext>
+</fullquery>
+
+	
+<fullquery name="get_category">        
+	<querytext>
+	     select count(object_id) from category_object_map where object_id = :course_id
+        </querytext>
+</fullquery>
+
+<fullquery name="get_tree_id">      
+    <querytext>
+    	 select tree_id from category_tree_map where object_id = :cc_package_id
+     </querytext>
+</fullquery>
+
+<fullquery name="relation">
+    <querytext>
+            select object_id_two as object_id, rel_type as type from acs_rels
+	    where object_id_one = :course_id  order by type 
+     </querytext>
+</fullquery>
+
+<fullquery name="get_dotlrn_classes">
+        <querytext>
+            select class_instance_id as object_id, department_name, term_name, class_name, pretty_name, url
+            from dotlrn_class_instances_full where class_instance_id in $dotlrn_class
+            order by department_name, term_name, class_name, pretty_name
+        </querytext>
+</fullquery>
+
+<fullquery name="get_dotlrn_communities">
+        <querytext>
+            select community_id as object_id, pretty_name, url from dotlrn_clubs_full 
+	    where community_id in $dotlrn_com order by pretty_name
+        </querytext>
+</fullquery>
+
+</queryset>
\ No newline at end of file
Index: openacs-4/packages/dotlrn-ecommerce/www/admin/course-list.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/admin/course-list.adp,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/dotlrn-ecommerce/www/admin/course-list.adp	31 May 2005 22:04:54 -0000	1.1
@@ -0,0 +1,27 @@
+<master>
+<property name=title>@page_title@</property>
+<property name="context">@context;noquote@</property>
+
+<STYLE TYPE="text/css">
+table.list {
+  font-family: tahoma, verdana, helvetica; 
+  border-collapse: collapse;
+  font-size: 12px;
+}
+</STYLE>
+<p>
+
+
+<form action="course-list" method="GET">
+    #dotlrn-catalog.search_courses# 
+    <input name="keyword" onfocus="if(this.value=='Please type a keyword')this.value='';" onblur="if(this.value=='')this.value='#dotlrn-catalog.please_type#';" value="#dotlrn-catalog.please_type#" />
+    <input type="submit" value="#dotlrn-catalog.search#" />
+</form>
+<br>
+<listtemplate name=course_list></listtemplate>
+
+<br>
+<a class=button href="course-add-edit">#dotlrn-catalog.new_course#</a>
+<p>
+
+
Index: openacs-4/packages/dotlrn-ecommerce/www/admin/course-list.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/admin/course-list.tcl,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/dotlrn-ecommerce/www/admin/course-list.tcl	31 May 2005 22:04:54 -0000	1.1
@@ -0,0 +1,126 @@
+ad_page_contract {
+    Displays a list of all courses
+    @author          Miguel Marin (miguelmarin@viaro.net) 
+    @author          Viaro Networks www.viaro.net
+    @creation-date   28-01-2005
+} {
+    page:optional
+    keyword:optional
+}
+
+
+set return_url [ad_return_url]
+set user_id [ad_conn user_id]
+set context [list "[_ dotlrn-catalog.course_list]"]
+set page_title "[_ dotlrn-catalog.course_list]"
+
+set cc_package_id [apm_package_id_from_key "dotlrn-catalog"]
+
+permission::require_permission -party_id $user_id -object_id $cc_package_id -privilege "create"
+
+if {[permission::permission_p -party_id $user_id -object_id $cc_package_id -privilege "admin"]} {
+    set admin_p 1
+} else {
+    set admin_p 0
+}
+
+# The tree id from categories
+set tree_list [category_tree::get_mapped_trees $cc_package_id]
+if { [string equal [lindex [lindex $tree_list 0] 1] "dotlrn-course-catalog"] } {
+    set tree_id [lindex [lindex $tree_list 0] 0]
+} else {
+    set tree_id ""
+}
+
+if { [acs_user::site_wide_admin_p] } {
+    if { [info exist keyword] } {
+	set query get_course_info_site_wide_keyword
+	set paginator_query site_wide_paginator_keyword
+    } else {
+	set query get_course_info_site_wide
+	set paginator_query site_wide_paginator
+    }
+} else {
+    if { [info exist keyword] } {
+	set query get_course_info_keyword
+	set paginator_query site_wide_paginator_keyword
+    } else {
+	set query get_course_info
+	set paginator_query paginator
+    }
+}
+
+template::list::create \
+    -name course_list \
+    -multirow course_list \
+    -key course_id \
+    -page_groupsize 5 \
+    -page_flush_p t \
+    -page_query_name $query \
+    -bulk_action_method post \
+    -bulk_action_export_vars {
+    }\
+    -row_pretty_plural "[_ dotlrn-catalog.courses]" \
+    -elements {
+	name  {
+	    label "Course Name (Key)"
+	    display_template {
+		<div align=left>
+		<a href="course-info?course_id=@course_list.course_id@&course_name=@course_list.course_name@&course_key=@course_list.course_key@">@course_list.course_name@</a> (@course_list.course_key@) 
+		</div>
+	    }
+	}
+	category {
+	    label "Categories"
+	    display_template {
+		<div align=center>
+		<if @course_list.category_name@ not eq "">
+		    @course_list.category_name@
+		</if>
+		<else>
+		   #dotlrn-catalog.uncat#
+		</else>
+		</div>
+	    }
+	}
+	sections {
+	    label Sections
+	    html { align center }
+	    display_template {
+		
+		<a href="course-info?course_id=@course_list.course_id@&course_name=@course_list.course_name@&course_key=@course_list.course_key@">@course_list.sections@</a>
+		
+	    }
+	}
+	actions {
+
+	    label "[_ dotlrn-catalog.admin] [_ dotlrn-catalog.Actions]"
+	    display_template {
+	    <div align=center>
+       	    <a href=course-add-edit?course_id=@course_list.course_id@&mode=1
+	    title="[_ dotlrn-catalog.edit_ver]"><img border=0 src=/resources/Edit16.gif></a>
+            <a href="course-delete?object_id=@course_list.item_id@&creation_user=@course_list.creation_user@&course_key=@course_list.course_key@" title="\#dotlrn-catalog.delete\#"><img border=0 src=/resources/Delete16.gif></a>
+		</div>
+	    }
+	}
+    }
+
+db_multirow -extend { asm_name rel item_id creation_user category_name sections } course_list $query {} {
+    set asm_name [db_string get_asm_name { } -default "[_ dotlrn-catalog.not_associated]"]
+    set item_id [dotlrn_catalog::get_item_id -revision_id $course_id]
+    set creation_user [dotlrn_catalog::get_creation_user -object_id $item_id]
+    set rel [dotlrn_catalog::has_relation -course_id $course_id]
+    set category_name ""
+    set mapped [category::get_mapped_categories $course_id]
+    foreach element $mapped {
+	append category_name "[category::get_name $element], "
+    }
+    set category_name [string range $category_name 0 [expr [string length $category_name] - 3]]
+
+    db_1row sections {
+	select count(*) as sections
+	from dotlrn_ecommerce_section
+	where course_id = :item_id
+    }
+}
+
Index: openacs-4/packages/dotlrn-ecommerce/www/admin/course-list.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/admin/course-list.xql,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/dotlrn-ecommerce/www/admin/course-list.xql	31 May 2005 22:04:54 -0000	1.1
@@ -0,0 +1,91 @@
+<?xml version="1.0"?>
+<queryset>
+
+<fullquery name="get_course_info">      
+      <querytext>
+            select cc.course_id, cc.course_key, cc.course_name, cc.course_info, cc.assessment_id, ci.item_id
+	    from dotlrn_catalog cc, cr_items ci
+ 	    where cc.course_id = ci.live_revision and  
+	    ci.item_id in (
+		select object_id from acs_permissions where grantee_id = :user_id and
+		privilege = 'admin')
+      </querytext>
+</fullquery>
+
+<fullquery name="get_course_info_site_wide">      
+      <querytext>
+            select cc.course_id, cc.course_key, cc.course_name, cc.course_info, cc.assessment_id, ci.item_id
+	    from dotlrn_catalog cc, cr_items ci
+ 	    where cc.course_id = ci.live_revision
+	    order by lower(cc.course_name)
+      </querytext>
+</fullquery>
+
+<fullquery name="get_course_info_keyword">      
+      <querytext>
+            select cc.course_id, cc.course_key, cc.course_name, cc.course_info, cc.assessment_id, ci.item_id
+	    from dotlrn_catalog cc, cr_items ci
+ 	    where cc.course_id = ci.live_revision and  
+	    lower(cc.course_name) like lower('%$keyword%') and
+	    ci.item_id in (
+		select object_id from acs_permissions where grantee_id = :user_id and
+		privilege = 'admin')
+      </querytext>
+</fullquery>
+
+<fullquery name="get_course_info_site_wide_keyword">      
+      <querytext>
+            select cc.course_id, cc.course_key, cc.course_name, cc.course_info, cc.assessment_id, ci.item_id
+	    from dotlrn_catalog cc, cr_items ci
+ 	    where cc.course_id = ci.live_revision and lower(cc.course_name) like lower('%$keyword%')
+      </querytext>
+</fullquery>
+
+<fullquery name="get_asm_name">
+      <querytext>
+            select cr.title from
+            cr_folders cf, cr_items ci, cr_revisions cr, as_assessments a
+            where cr.revision_id = ci.latest_revision and a.assessment_id = cr.revision_id and
+            ci.parent_id = cf.folder_id and ci.item_id = :assessment_id order by cr.title
+      </querytext>
+</fullquery>
+
+<fullquery name="paginator">      
+      <querytext>
+	    select cc.course_id, cc.course_key, cc.course_name, cc.course_info, cc.assessment_id, ci.item_id
+	    from dotlrn_catalog cc, cr_items ci
+ 	    where cc.course_id = ci.live_revision and 
+	    ci.item_id in (
+		select object_id from acs_permissions where grantee_id = :user_id and
+		privilege = 'admin')
+      </querytext>
+</fullquery>
+
+<fullquery name="site_wide_paginator">      
+      <querytext>
+            select cc.course_id, cc.course_key, cc.course_name, cc.course_info, cc.assessment_id, ci.item_id
+	    from dotlrn_catalog cc, cr_items ci
+ 	    where cc.course_id = ci.live_revision
+      </querytext>
+</fullquery>
+
+<fullquery name="paginator_keyword">      
+      <querytext>
+	    select cc.course_id, cc.course_key, cc.course_name, cc.course_info, cc.assessment_id, ci.item_id
+	    from dotlrn_catalog cc, cr_items ci
+ 	    where cc.course_id = ci.live_revision and lower(cc.course_name) like lower('%$keyword%') and 
+	    ci.item_id in (
+		select object_id from acs_permissions where grantee_id = :user_id and
+		privilege = 'admin')
+      </querytext>
+</fullquery>
+
+<fullquery name="site_wide_paginator_keyword">      
+      <querytext>
+            select cc.course_id, cc.course_key, cc.course_name, cc.course_info, cc.assessment_id, ci.item_id
+	    from dotlrn_catalog cc, cr_items ci
+ 	    where cc.course_id = ci.live_revision lower(cc.course_name) like lower('%$keyword%') and
+      </querytext>
+</fullquery>
+
+</queryset>
Index: openacs-4/packages/dotlrn-ecommerce/www/admin/gwu-section-new.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/admin/gwu-section-new.adp,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/dotlrn-ecommerce/www/admin/gwu-section-new.adp	31 May 2005 22:04:54 -0000	1.1
@@ -0,0 +1,8 @@
+<master>
+<property name="title">@page_title@</property>
+<property name="context">@context@</property>
+<property name="focus">add_class_instance.term</property>
+
+<formtemplate id="add_section"></formtemplate>
+
+
Index: openacs-4/packages/dotlrn-ecommerce/www/admin/gwu-section-new.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/admin/gwu-section-new.tcl,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/dotlrn-ecommerce/www/admin/gwu-section-new.tcl	31 May 2005 22:04:54 -0000	1.1
@@ -0,0 +1,353 @@
+ad_page_contract {
+    custom for GWU. creates a class instance,
+    a corresponding ecommerce product and necessary calendar items
+
+    @author Deds Castillo
+    @creation-date 2004-05-01
+    @version $Id: gwu-section-new.tcl,v 1.1 2005/05/31 22:04:54 hamiltonc Exp $
+} {
+    course_id:notnull
+    section_id:optional
+    {return_url "" }
+}
+
+dotlrn_catalog::get_course_data -course_id $course_id
+
+set package_id [ad_conn package_id]
+
+ad_form -name add_section -form {
+    section_id:key
+    {product_id:integer(hidden)}
+    {return_url:text(hidden) {value $return_url}}
+    {course_id:text(hidden) {value $course_id}}
+    {section_name:text {label "Section Name"}}     
+    {price:text(text) {label "Regular Price"} {html {size 6}} {section "Product Info"}} 
+}
+
+
+# HAM : Let's check if we have MemberPriceP enabled and set
+# if it is let's add Member Price text
+if { [parameter::get -package_id [ad_conn package_id] -parameter MemberPriceP -default 0 ] } {
+	ad_form -extend -name add_section -form {
+		{ member_price:text(text),optional {label "Member Price"} {html {size 6}} }
+	}
+}
+
+# HAM : Let's get the community id's for both Instructors and Assistants
+
+set instructor_community_id [parameter::get -package_id [ad_conn package_id] -parameter InstructorCommunityId -default 0 ]
+set assistant_community_id [parameter::get -package_id [ad_conn package_id] -parameter AssistantCommunityId -default 0 ]
+
+# HAM : Let's check if we have InstructorCommunityId enabled and set
+if { $instructor_community_id == 0 && ![db_0or1row "checkinstructorcommunity" "select community_id from dotlrn_communities where community_id = :instructor_community_id"] } {
+	ad_return_complaint 1 "Parameter InstructorCommunityId is not set or Community Id does not exist."
+} else {
+	# community_id is valid
+	# list users
+	set instructors [dotlrn_community::list_users  $instructor_community_id]
+	set instructors_list [list]
+	foreach instructor $instructors {
+		set instructor_user_id [ns_set get $instructor user_id]
+		set instructor_name "[ns_set get $instructor first_names] [ns_set get $instructor last_name]"
+		lappend instructors_list [list $instructor_name $instructor_user_id ]
+	}
+	
+	ad_form -extend -name add_section -form {
+		{ instructors:string(multiselect),multiple {label "Instructors"} {options { $instructors_list } }	}
+	}
+}
+
+# HAM : Let's check if we have AssistantCommunityId enabled and set
+if { $assistant_community_id == 0 && ![db_0or1row "checkassistantcommunity" "select community_id from dotlrn_communities where community_id = :assistant_community_id"] } {
+	ad_return_complaint 1 "Parameter AssistantCommunityId is not set or Community Id does not exist."
+} else {
+	# community_id is valid
+	set assistants [dotlrn_community::list_users  $assistant_community_id]
+	set assistants_list [list]
+	foreach assistant $assistants {
+		set assistant_user_id [ns_set get $assistant user_id]
+		set assistant_name "[ns_set get $assistant first_names] [ns_set get $assistant last_name]"
+		lappend assistants_list [list $assistant_name $assistant_user_id ]
+	}
+	
+	ad_form -extend -name add_section -form {
+		{ assistants:string(multiselect),multiple {label "Assistants"} {options { $assistants_list } }	}
+	}
+
+}
+
+
+if { ! [ad_form_new_p -key section_id] } {
+    db_1row community {
+	select community_id
+	from dotlrn_ecommerce_section
+	where section_id = :section_id
+    }
+    ad_form -extend -name add_section -form {
+	{categories:integer(category),multiple,optional
+	    {label "Categories"}
+	    {html {size 4}}
+	    {value "$community_id $package_id"}
+	}
+    }
+} else {
+    ad_form -extend -name add_section -form {
+	{categories:integer(category),multiple,optional
+	    {label "Categories"}
+	    {html {size 4}}
+	}
+    }
+}
+
+
+# ecommerce stuff
+
+set exclude_list [list "'classid'"]
+
+db_foreach custom_fields_select "
+    select field_identifier,
+           field_name,
+           default_value,
+           column_type
+    from ec_custom_product_fields
+    where active_p='t'
+          and field_identifier not in ([join $exclude_list ", "])
+    order by creation_date" {
+    # date
+    if {[string equal $column_type date] || [string equal $column_type timestamp]} {
+        if {[string equal $field_identifier enddate]} {
+            ad_form -extend -name add_section -form [list \
+							 [list "${field_identifier}:date,optional" {label $field_name} {value $default_value} {help_text "Not required for Distance Learning Courses"}]]
+	} else {
+	    ad_form -extend -name add_section -form [list \
+							 [list "${field_identifier}:date,optional" {label $field_name} {value $default_value}] \
+							]
+	}
+    } elseif {[string equal $column_type integer] || [string equal $column_type number]} {
+	ad_form -extend -name add_section -form [list \
+						     [list "${field_identifier}:text(text),optional" {label $field_name} {value $default_value} {html {size 5}}] \
+						    ]
+    } elseif {[string equal $column_type "varchar(200)"]} {
+	ad_form -extend -name add_section -form [list \
+						     [list "${field_identifier}:text(text),optional" {label $field_name} {value $default_value} {html {size 50 maxlength 200}}] \
+						    ]
+    } elseif {[string equal $column_type "varchar(4000)"]} {
+	ad_form -extend -name add_section -form [list \
+						     [list "${field_identifier}:text(textarea),optional" {label $field_name} {value $default_value} {html {rows 4 cols 60}}] \
+						    ]
+    } else {
+	ad_form -extend -name add_section -form [list \
+						     [list "${field_identifier}:text(radio),optional" {label $field_name} {value $default_value} {options {{t t} {f f}}}] \
+						    ]
+    }
+}
+
+
+ad_form -extend -name add_section -new_request {
+    set product_id 0
+} -edit_request {
+    db_1row community {
+	select des.*, p.price
+	from dotlrn_ecommerce_section des, ec_products p
+	where des.product_id = p.product_id
+	and des.section_id = :section_id
+    }
+
+    db_1row custom_fields {
+	select * from ec_custom_product_field_values where product_id = :product_id
+    }
+} -new_data {
+    db_transaction {
+        # create the class instance
+	set community_id [dotlrn_club::new  -pretty_name "$course_data(name): Section $section_name"] 
+
+	# HAM : Let's add chosen instructors in the role of instructors 
+	# and assistants in the role of assistants
+	foreach instructor $instructors {
+		dotlrn_club::add_user -rel_type "dotlrn_club_instructor_rel" -community_id $community_id -user_id $instructor -member_state "approved"
+	}
+	foreach assistant $assistants {
+		dotlrn_club::add_user -rel_type "dotlrn_member_rel" -community_id $community_id -user_id $assistant -member_state "approved"
+	}
+	
+       
+	# add the calendar item type "session"
+	set calendar_id [dotlrn_calendar::get_group_calendar_id -community_id $community_id]
+	calendar::item_type_new -calendar_id $calendar_id -type "Session"
+
+
+	# create an ecommerce product
+	set product_id [db_nextval acs_object_id_seq]
+
+	set user_id [ad_conn user_id]
+	set context_id [ad_conn package_id]
+        set product_name "$section_name"
+        set sku ""
+        set one_line_description "$section_name"
+        set detailed_description ""
+        set search_keywords ""
+        set present_p "t"
+        set stock_status ""
+        # let's have dirname be the first four letters (lowercase) of the product_name
+        # followed by the product_id (for uniqueness)
+	regsub -all {[^a-zA-Z]} $product_name "" letters_in_product_name
+	set letters_in_product_name [string tolower $letters_in_product_name]
+	if [catch {set dirname "[string range $letters_in_product_name 0 3]$product_id"}] {
+            #maybe there aren't 4 letters in the product name
+            set dirname "$letters_in_product_name$product_id"
+        }
+	set color_list ""
+        set size_list ""
+	set peeraddr [ad_conn peeraddr]
+	set product_id [db_exec_plsql product_insert {
+            select ec_product__new(
+				   :product_id,
+				   :user_id,
+				   :context_id,
+				   :product_name,
+				   :price,
+				   :sku,
+				   :one_line_description,
+				   :detailed_description,
+				   :search_keywords,
+				   :present_p,
+				   :stock_status,
+				   :dirname,
+				   to_date(now(), 'YYYY-MM-DD'),
+				   :color_list,
+				   :size_list,
+				   :peeraddr
+				   )
+	}]
+
+	db_dml product_update {
+	    update ec_products
+	    set active_p = 't'
+	    where product_id = :product_id
+	}
+	# take care of custom fields
+        # we have to generate audit information
+        set audit_fields "last_modified, last_modifying_user, modified_ip_address"
+        set audit_info "now(), :user_id, :peeraddr"
+	
+        # things to insert into ec_custom_product_field_values if they exist
+	set custom_columns_to_insert [list product_id]
+	set custom_column_values_to_insert [list ":product_id"]
+	set bind_set [ns_set create]
+        ns_set put $bind_set product_id $product_id
+        ns_set put $bind_set user_id $user_id
+        ns_set put $bind_set peeraddr $peeraddr
+	
+	db_foreach custom_columns_select {
+            select field_identifier, column_type
+            from ec_custom_product_fields
+            where active_p='t'
+	} {
+	    if {[info exists $field_identifier] } {
+                lappend custom_columns_to_insert $field_identifier
+                lappend custom_column_values_to_insert ":$field_identifier"
+		if {[string equal $column_type date] || [string equal $column_type timestamp]} {
+		    set one_date [template::util::date::get_property linear_date_no_time [subst $$field_identifier]]
+                    ns_set put $bind_set $field_identifier $one_date
+		} else {
+		    ns_set put $bind_set $field_identifier [subst $$field_identifier]
+		}
+	    }
+	}
+	db_dml custom_fields_insert "
+        insert into ec_custom_product_field_values
+        ([join $custom_columns_to_insert ", "], $audit_fields)
+        values
+        ([join $custom_column_values_to_insert ","], $audit_info)
+        " -bind $bind_set
+
+	#HAM: create a sale item from the member price
+	# do so only if member price is provided
+	# and MemberPriceP is 1
+	if { [parameter::get -package_id [ad_conn package_id] -parameter MemberPriceP -default 0 ] && [exists_and_not_null member_price]} {
+
+		# HAM : FIXME
+
+		# not sure if these values are correct
+		# comment out when properly tested
+
+		set sale_price_id [db_nextval ec_sale_price_id_sequence]
+		set sale_price $member_price
+		set offer_code ""
+	
+		db_dml sale_insert "
+		insert into ec_sale_prices
+		(sale_price_id, product_id, sale_price, sale_begins, sale_ends, sale_name, offer_code, last_modified, last_modifying_user, modified_ip_address)
+		values
+		(:sale_price_id, :product_id, :sale_price, to_date(now() - '1 day':: interval,'YYYY-MM-DD HH24:MI:SS'), to_date(now() + '99 years':: interval,'YYYY-MM-DD HH24:MI:SS'), 'MemberPrice', :offer_code, now(), :user_id, :peeraddr)"
+	}
+
+	#CM: We should probably add ecomerce_product_id to ecommerce_Section and insert it here.
+	db_dml add_section {
+	    insert into dotlrn_ecommerce_section(section_id, course_id, section_name, community_id,product_id) values
+	    (:section_id, :course_id, :section_name, :community_id, :product_id)
+	}
+
+	# for this to work, dotlrn_eccomerce_section must be an object 
+	# just use community_id DAVEB
+	# where do the terms options come from?! DAVEB
+	
+	category::map_object -object_id $community_id $categories
+    }
+
+} -edit_data {
+    db_dml update_section {
+	update dotlrn_ecommerce_section set
+	section_name = :section_name
+	where section_id = :section_id
+    }
+
+    # Change the community's name
+    dotlrn_community::set_community_name \
+        -community_id $community_id \
+        -pretty_name $section_name
+
+    # Update price
+    db_dml update_price {
+	update ec_products set price = :price where product_id = :product_id
+    }
+
+    # things to insert into ec_custom_product_field_values if they exist
+    set user_id [ad_conn user_id]
+    set peeraddr [ad_conn peeraddr]
+    set custom_columns_to_insert [list product_id]
+    set custom_column_values_to_insert [list ":product_id"]
+    set bind_set [ns_set create]
+    ns_set put $bind_set product_id $product_id
+    ns_set put $bind_set user_id $user_id
+    ns_set put $bind_set peeraddr $peeraddr
+
+    db_foreach custom_columns_select {
+	select field_identifier, column_type
+	from ec_custom_product_fields
+	where active_p='t'
+    } {
+	if {[info exists $field_identifier] } {
+	    lappend custom_columns_to_update "$field_identifier = :$field_identifier"
+	    if {[string equal $column_type date] || [string equal $column_type timestamp]} {
+		set one_date [template::util::date::get_property linear_date_no_time [subst $$field_identifier]]
+		ns_set put $bind_set $field_identifier $one_date
+	    } else {
+		ns_set put $bind_set $field_identifier [subst $$field_identifier]
+	    }
+	}
+    }
+    db_dml custom_fields_insert "
+        update ec_custom_product_field_values set [join $custom_columns_to_update ,] where product_id = :product_id
+        " -bind $bind_set
+
+    category::map_object -remove_old -object_id $community_id $categories
+} -after_submit {
+    ad_returnredirect $return_url
+}
+
+
+# Used by en_US version of new_class_instance message
+set class_instances_pretty_name [parameter::get -localize -parameter class_instances_pretty_name]
+set page_title "Add Section"
+set context [list $page_title]
\ No newline at end of file
Index: openacs-4/packages/dotlrn-ecommerce/www/admin/index.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/admin/index.adp,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/dotlrn-ecommerce/www/admin/index.adp	31 May 2005 22:04:54 -0000	1.1
@@ -0,0 +1,13 @@
+<master>
+<property name=title>@page_title@</property>
+<property name="context">@context;noquote@</property>
+
+<ul>
+<li><a href=course-list>Course List</a>
+<li><a href=course-attributes>Course Attributes</a>
+<li><a href="/categories/cadmin">#dotlrn-catalog.admin_categories#</a>
+<li>Instructors - <a href=@instructor_community_url@>Community</a> <a href=@instructor_community_url@/members>List</a>
+<li>Assistant Instuctors - <a href=@assistant_community_url@>Community</a> <a href=@assistant_community_url@/members>List</a>
+<li><a href=/sf>Scholarship Funds</a>
+<li><a href="/expenses/admin/">Expenses</a>
+</ul>
\ No newline at end of file
Index: openacs-4/packages/dotlrn-ecommerce/www/admin/index.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/admin/index.tcl,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/dotlrn-ecommerce/www/admin/index.tcl	31 May 2005 22:04:54 -0000	1.1
@@ -0,0 +1,27 @@
+# packages/dotlrn-ecommerce/www/admin/index.tcl
+
+ad_page_contract {
+    
+    
+    
+    @author Roel Canicula (roelmc@pldtdsl.net)
+    @creation-date 2005-05-18
+    @arch-tag: 92819343-73fc-4fea-a823-3e62f6c145bc
+    @cvs-id $Id: index.tcl,v 1.1 2005/05/31 22:04:54 hamiltonc Exp $
+} {
+    
+} -properties {
+} -validate {
+} -errors {
+}
+
+set context ""
+set page_title "Course/eCommerce Administration"
+
+set instructor_community_id [parameter::get -package_id [ad_conn package_id] -parameter InstructorCommunityId -default 0 ]
+
+set instructor_community_url [dotlrn_community::get_community_url $instructor_community_id]
+
+set assistant_community_id [parameter::get -package_id [ad_conn package_id] -parameter AssistantCommunityId -default 0 ]
+
+set assistant_community_url [dotlrn_community::get_community_url $assistant_community_id]
\ No newline at end of file
Index: openacs-4/packages/dotlrn-ecommerce/www/admin/membership-add.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/admin/membership-add.adp,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/dotlrn-ecommerce/www/admin/membership-add.adp	31 May 2005 22:04:54 -0000	1.1
@@ -0,0 +1,14 @@
+<master>
+  <property name="title">@title@</property>
+  <property name="context">@context;noquote@</property>
+
+  You are about to add user <b>@user.first_names@ @user.last_name@ (@user.email@)</b> to section <b>@section_name@</b>
+
+  <p />
+  <a href="@confirm_url;noquote@" class="button">Add Participant</a> &nbsp; <a
+  href="@referer;noquote@" class="button">Cancel</a>
+
+  <p />
+  <b>You may also select a patron for this participant</b>
+
+  <formtemplate id="patron"></formtemplate>
\ No newline at end of file
Index: openacs-4/packages/dotlrn-ecommerce/www/admin/membership-add.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/admin/membership-add.tcl,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/dotlrn-ecommerce/www/admin/membership-add.tcl	31 May 2005 22:04:54 -0000	1.1
@@ -0,0 +1,173 @@
+# packages/dotlrn-ecommerce/www/admin/membership-add.tcl
+
+ad_page_contract {
+    
+    
+    
+    @author Roel Canicula (roelmc@pldtdsl.net)
+    @creation-date 2005-05-19
+    @arch-tag: 147cb277-9537-4e94-aac5-c2c2e8c26adf
+    @cvs-id $Id: membership-add.tcl,v 1.1 2005/05/31 22:04:54 hamiltonc Exp $
+} {
+    user_id:integer,notnull
+    {confirmed_p:integer,notnull 0}
+    community_id:integer,notnull
+    section_id:integer,notnull
+
+    {patron ""}
+    {patron_id 0}
+
+    referer:notnull
+
+    participant_id:optional
+} -properties {
+} -validate {
+} -errors {
+}
+
+if { ! [dotlrn::user_p -user_id $user_id] } {
+    dotlrn::user_add -user_id $user_id
+}
+    
+if { [info exists participant_id] } {
+    set patron_id $user_id
+    set user_id $participant_id
+}
+
+set next_url [export_vars -base membership-add { section_id community_id referer patron patron_id {participant_id $user_id} }]
+db_1row get_section_info "select c.course_id, s.section_name
+    from dotlrn_ecommerce_section s, dotlrn_catalogi c, cr_items ci
+    where s.course_id = c.item_id
+    and ci.live_revision=c.revision_id
+    and s.section_id = :section_id"
+
+set context [list [list [export_vars -base course-info { course_id }] $section_name] "Process Purchase"]
+
+if { $confirmed_p } {
+    set community_url [dotlrn_community::get_community_url $community_id]
+    set add_member_url [export_vars -base ${community_url}member-add-3 { user_id { rel_type dotlrn_member_rel } referer }]
+
+    ad_returnredirect $add_member_url
+    ad_script_abort
+} else {
+    set title "Confirm Purchase"
+    db_1row section_name {
+	select section_name
+	from dotlrn_ecommerce_section
+	where section_id = :section_id
+    }
+
+    acs_user::get -user_id $user_id -array user
+
+    set confirm_url [export_vars -base membership-add { user_id {confirmed_p 1} community_id section_id referer }]
+
+    set patron_list [linsert [db_list_of_lists patrons {
+	select first_names||' '||last_name||' ('||email||')', user_id
+	from dotlrn_users
+	where user_id != :user_id
+	and (case when :patron = ''
+	     then true
+	     else lower(first_names||' '||last_name||' '||email) like '%'||lower(:patron)||'%' end)
+    }] 0 {{} 0}]
+
+    if { [llength $patron_list] == 1 } {
+	set form [rp_getform]
+	ns_set delkey $form __refreshing_p
+	ns_set put $form __refreshing_p 0
+    }
+    
+    set validate [list]
+
+    if { ( [empty_string_p $patron] || [llength $patron_list] == 1 ) && ! $patron_id } {
+	ad_form -name "patron" -export { {patron_id 0} } -form {
+	    {patron:text,optional {label "Search Patron"} {html {onchange "if (this.value != '') { this.form.__refreshing_p.value = 1; } else { this.form.__refreshing_p.value = 0 ; }"}}
+		{help_text "Enter a string to search names and email addresses. <br />Or <a href=\"[export_vars -base patron-create { next_url }]\">Create an account</a> and return to this form"}
+	    }
+	}
+
+	lappend validate {patron
+	    { ! [empty_string_p $patron] }
+	    "Please enter a search string"
+	}
+	lappend validate {patron
+	    { [llength $patron_list] > 1 }
+	    "No users found. Please try again"
+	}
+    } elseif { $patron_id } {
+	acs_user::get -user_id $patron_id -array patron_user
+
+	ad_form -name "patron" -export { patron patron_id } -form {
+	    {patron_name:text(inform) {label "Patron"} {value "$patron_user(first_names) $patron_user(last_name) ($patron_user(email))"}}
+	}
+
+	lappend validate {relationship
+	    { $relationship != [list [list 0 $community_id]] || ![empty_string_p [template::element::get_value patron relationship_new]] }
+	    "Please select a relationship or enter a new one"
+	}
+    } else {
+	ad_form -name "patron" -export { patron } -form {
+	    {patron_id:integer(select),optional {label "Patron"} {options {$patron_list}}
+		{help_text "Select a patron from the list. Can't find the patron?<br /><a href=\"[export_vars -base patron-create { next_url }]]\">Create an account</a> and return to this form"}
+	    }
+	}
+
+	lappend validate {patron_id
+	    { $patron_id }
+	    "Please select a patron from the list"
+	}
+
+	lappend validate {relationship
+	    { $relationship != [list [list 0 $community_id]] || ![empty_string_p [template::element::get_value patron relationship_new]] }
+	    "Please select a relationship or enter a new one"
+	}
+    }
+
+    ad_form -extend -name "patron" -export { user_id {confirmed_p 0} community_id section_id referer } \
+	-validate $validate \
+	-form {
+	    {relationship:text(category),optional,multiple {label "Relationship"} {value {0 $community_id}} {html {size 4}}
+		{help_text "Please select one or enter one below if not in the list"}
+		{assign_single_p t}
+	    }
+	    {relationship_new:text,optional {label "Other Relationship"}
+		{help_text "This field is ignored if a relationship is selected from the list above"}
+	    }
+	    {proceed:text(submit) {label "Add Participant with Patron"}}
+	} -on_submit {
+	    set rel_id [relation::get_id -object_id_one $user_id -object_id_two $patron_id -rel_type "patron_rel"]
+
+	    if { [empty_string_p $rel_id] } {
+		# Create patron relationship
+		set rel_id [db_exec_plsql relate_patron {
+		    select acs_rel__new (null,
+			     'patron_rel',
+			     :user_id,
+			     :patron_id,
+			     null,
+			     null,
+			     null)
+		}]
+		ns_log notice "DEBUG:: Created relationship $rel_id: $user_id - $patron_id"
+	    } else {
+		ns_log notice "DEBUG:: Existing relationship $rel_id: $user_id - $patron_id"
+	    }
+
+	    # Check if no categories were selected
+	    if { $relationship == [list [list 0 $community_id]] } {
+		set relationship ""
+
+		# See if user entered a new relationship and add that
+		if { ! [empty_string_p $relationship_new] } {
+		    set tree_id [parameter::get -package_id [ad_conn package_id] -parameter PatronRelationshipCategoryTree -default 0]
+		    set relationship [list [category::add -name $relationship_new -tree_id $tree_id -parent_id ""]]
+		}
+	    }
+
+	    # Set relationships from categories
+	    ns_log notice "DEBUG:: Categories $relationship rel_id $rel_id"
+	    category::map_object -remove_old -object_id $rel_id $relationship
+
+	    ad_returnredirect [export_vars -base membership-add { user_id { confirmed_p 1 } community_id section_id referer }]
+	    ad_script_abort
+	}
+}
\ No newline at end of file
Index: openacs-4/packages/dotlrn-ecommerce/www/admin/membership-remove.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/admin/membership-remove.tcl,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/dotlrn-ecommerce/www/admin/membership-remove.tcl	31 May 2005 22:04:54 -0000	1.1
@@ -0,0 +1,24 @@
+# packages/dotlrn-ecommerce/www/admin/remove-membership.tcl
+
+ad_page_contract {
+    
+    
+    
+    @author Roel Canicula (roelmc@pldtdsl.net)
+    @creation-date 2005-05-19
+    @arch-tag: fe075f24-ed9a-4701-8a6d-1f90676ff5b1
+    @cvs-id $Id: membership-remove.tcl,v 1.1 2005/05/31 22:04:54 hamiltonc Exp $
+} {
+    {user_id:integer,multiple {}}
+    community_id:integer,notnull
+    return_url
+} -properties {
+} -validate {
+} -errors {
+}
+
+foreach one_user_id $user_id {
+    catch {dotlrn_community::remove_user $community_id $one_user_id}
+}
+
+ad_returnredirect $return_url
\ No newline at end of file
Index: openacs-4/packages/dotlrn-ecommerce/www/admin/patron-create.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/admin/patron-create.adp,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/dotlrn-ecommerce/www/admin/patron-create.adp	31 May 2005 22:04:54 -0000	1.1
@@ -0,0 +1,6 @@
+<master>
+  <property name="title">Create a Patron Account</property>
+  <property name="context">{Create a Patron Account}</property>  
+
+  <include src="/packages/acs-subsite/lib/user-new"
+    next_url="@next_url;noquote@" self_register_p="0"/>
\ No newline at end of file
Index: openacs-4/packages/dotlrn-ecommerce/www/admin/patron-create.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/admin/patron-create.tcl,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/dotlrn-ecommerce/www/admin/patron-create.tcl	31 May 2005 22:04:54 -0000	1.1
@@ -0,0 +1,17 @@
+# packages/dotlrn-ecommerce/www/admin/patron-create.tcl
+
+ad_page_contract {
+    
+    
+    
+    @author Roel Canicula (roelmc@pldtdsl.net)
+    @creation-date 2005-05-28
+    @arch-tag: 2671f04d-3d9b-4e86-aa34-2dbf0dea6c35
+    @cvs-id $Id: patron-create.tcl,v 1.1 2005/05/31 22:04:54 hamiltonc Exp $
+} {
+    next_url:trim,notnull
+} -properties {
+} -validate {
+} -errors {
+}
+
Index: openacs-4/packages/dotlrn-ecommerce/www/admin/patrons.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/admin/patrons.adp,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/dotlrn-ecommerce/www/admin/patrons.adp	31 May 2005 22:04:54 -0000	1.1
@@ -0,0 +1,5 @@
+<master>
+  <property name="title">Participants and Patrons</property>
+  <property name="context">@context;noquote@</property>
+
+  <listtemplate name="patrons"></listtemplate>
\ No newline at end of file
Index: openacs-4/packages/dotlrn-ecommerce/www/admin/patrons.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/admin/patrons.tcl,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/dotlrn-ecommerce/www/admin/patrons.tcl	31 May 2005 22:04:54 -0000	1.1
@@ -0,0 +1,55 @@
+# packages/dotlrn-ecommerce/www/admin/patrons.tcl
+
+ad_page_contract {
+    
+    
+    
+    @author Roel Canicula (roelmc@pldtdsl.net)
+    @creation-date 2005-05-28
+    @arch-tag: cfc996c0-7de4-40d1-88a3-f0eadf2a3fdc
+    @cvs-id $Id: patrons.tcl,v 1.1 2005/05/31 22:04:54 hamiltonc Exp $
+} {
+    section_id:integer,notnull
+} -properties {
+} -validate {
+} -errors {
+}
+
+template::list::create \
+    -name "patrons" \
+    -multirow "patrons" \
+    -elements {
+	participant {
+	    label Participant
+	}
+	patron {
+	    label Patron
+	}
+	relationship {
+	    label Relationship
+	}
+    }
+
+db_multirow -extend { relationship } patrons patrons {
+    select r.rel_id, person__name(d.user_id) as participant, person__name(r.object_id_two) as patron
+    from acs_rels r, dotlrn_member_rels_full d
+    where r.object_id_one = d.user_id
+    and r.rel_type = 'patron_rel'
+    and d.community_id = (select community_id
+			  from dotlrn_ecommerce_section
+			  where section_id = :section_id)
+} {
+    foreach category [category::get_mapped_categories $rel_id] {
+	lappend relationship [category::get_name $category]
+    }
+
+    set relationship [join $relationship ", "]
+}
+
+db_1row get_section_info "select c.course_id, s.section_name
+    from dotlrn_ecommerce_section s, dotlrn_catalogi c, cr_items ci
+    where s.course_id = c.item_id
+    and ci.live_revision=c.revision_id
+    and s.section_id = :section_id"
+
+set context [list [list [export_vars -base course-info { course_id }] $section_name] "Participants and Patrons"]
Index: openacs-4/packages/dotlrn-ecommerce/www/admin/predefined-session-delete.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/admin/predefined-session-delete.tcl,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/dotlrn-ecommerce/www/admin/predefined-session-delete.tcl	31 May 2005 22:04:54 -0000	1.1
@@ -0,0 +1,26 @@
+# packages/dotlrn-ecommerce/www/admin/predefined-session-delete.tcl
+
+ad_page_contract {
+    
+    
+    
+    @author Roel Canicula (roelmc@pldtdsl.net)
+    @creation-date 2005-05-25
+    @arch-tag: d8338236-fc0a-4804-8fc8-39648e9554e6
+    @cvs-id $Id: predefined-session-delete.tcl,v 1.1 2005/05/31 22:04:54 hamiltonc Exp $
+} {
+    {session_id:integer,multiple {}}
+    return_url
+} -properties {
+} -validate {
+} -errors {
+}
+
+if { [llength $session_id] } {
+    db_dml delete_sesions [subst {
+	delete from dotlrn_ecommerce_predefined_sessions
+	where session_id in ([join $session_id ,])
+    }]
+}
+
+ad_returnredirect $return_url
\ No newline at end of file
Index: openacs-4/packages/dotlrn-ecommerce/www/admin/process-group-purchase.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/admin/process-group-purchase.adp,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/dotlrn-ecommerce/www/admin/process-group-purchase.adp	31 May 2005 22:04:54 -0000	1.1
@@ -0,0 +1,5 @@
+<master>
+<property name="title">@page_title@</property>
+<property name="context">@context@</property>
+
+<formtemplate id="process-group"></formtemplate>
\ No newline at end of file
Index: openacs-4/packages/dotlrn-ecommerce/www/admin/process-group-purchase.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/admin/process-group-purchase.tcl,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/dotlrn-ecommerce/www/admin/process-group-purchase.tcl	31 May 2005 22:04:54 -0000	1.1
@@ -0,0 +1,61 @@
+# packages/dotlrn-ecommerce/www/admin/process-group-puchase.tcl
+
+ad_page_contract {
+    Process registration of a group
+
+    @author Dave Bauer (dave@solutiongrove.com)
+    @creation-date 2005-05-19
+} -query {
+    section_id:integer,notnull
+} -properties {
+    page_title
+    context
+}
+
+set user_id [ad_conn user_id]
+
+ad_form -name process-group \
+    -export { section_id } \
+    -form {
+	group_id:key
+	{name:text {label "Group Name"}}
+	{num_members:integer(text) {label "Number of attendees"}}
+    } -new_data {
+	# FIXME do checking of max attendees etc here
+# FIXME figure out why this doesn't work in a transaction
+#	db_transaction {
+	set unique_group_name "${name}_${group_id}"
+	    group::new -group_id $group_id -group_name $unique_group_name
+	    set section_community_id [db_string get_community_id "select community_id from dotlrn_ecommerce_section where section_id=:section_id" -default ""]
+	    if {[string equal "" $section_community_id]} {
+		# FIXME error, do something clever here
+	    }
+	    for { set i 1 } { $i <= $num_members } { incr i } {
+		array set new_user [auth::create_user \
+				     -username "${name} Attendee $i" \
+					-email "[util_text_to_url -text ${name}-attendee-${i}]@example.com" \
+				     -first_names "$name" \
+				     -last_name "Attendee $i" \
+				     -nologin]
+#		ad_return_complaint 1 "new_user '[array get new_user]' section_community_id '${section_community_id}'"
+#		if {[info exists new_user(user_id)]} {
+#		    relation_add -member_state approved dotlrn_club_student_rel $section_community_id $new_user(user_id)
+		    relation_add relationship $group_id $section_community_id	    
+		package_exec_plsql -var_list [list [list community_id $section_community_id] [list rel_type "dotlrn_club_student_rel"] [list user_id $new_user(user_id)] [list member_state approved]] dotlrn_club_student_rel new
+		relation_add -member_state approved membership_rel $group_id $new_user(user_id)
+
+	#	}
+	    }
+#	}
+    } -after_submit {
+	set course_id [db_string get_course_id "    select c.course_id
+    from dotlrn_ecommerce_section s, dotlrn_catalogi c, cr_items ci
+    where s.course_id = c.item_id
+    and ci.live_revision=c.revision_id
+    and s.section_id = :section_id" -default ""]
+	ad_returnredirect -message "Added $num_members from $name" [export_vars -base course-info {course_id}]
+    }
+
+set page_title "Add Group"
+set context [list $page_title]
+ad_return_template
\ No newline at end of file
Index: openacs-4/packages/dotlrn-ecommerce/www/admin/process-purchase.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/admin/process-purchase.adp,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/dotlrn-ecommerce/www/admin/process-purchase.adp	31 May 2005 22:04:54 -0000	1.1
@@ -0,0 +1,28 @@
+<master>
+  <property name="title">Process Purchase</property>
+  <property name="context">@context;noquote@</property>
+
+  <if @section_id@ defined and @section_id@ not nil>
+
+    <formtemplate id="search"></formtemplate>
+    <p />
+    <if @search@ not nil>
+      <listtemplate name="users"></listtemplate>
+    </if>
+    
+  </if>
+
+  <p />
+  <b>Or create an account for the participant</b>
+  
+  <include src="/packages/acs-subsite/lib/user-new"
+    next_url="@next_url;noquote@" self_register_p="0"/>
+  
+  <if @section_id@ defined and @section_id@ not nil>
+    <if @members:rowcount@ gt 0>
+      <p />
+      <h3>Members</h3>
+      <p />
+      <listtemplate name="members"></listtemplate>
+    </if>
+  </if>
\ No newline at end of file
Index: openacs-4/packages/dotlrn-ecommerce/www/admin/process-purchase.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/admin/process-purchase.tcl,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/dotlrn-ecommerce/www/admin/process-purchase.tcl	31 May 2005 22:04:54 -0000	1.1
@@ -0,0 +1,138 @@
+# packages/dotlrn-ecommerce/www/admin/process-purchase.tcl
+
+ad_page_contract {
+    
+    
+    
+    @author Roel Canicula (roelmc@pldtdsl.net)
+    @creation-date 2005-05-19
+    @arch-tag: d78f1eb7-313d-4c1a-8f1c-6be5c4f0765a
+    @cvs-id $Id: process-purchase.tcl,v 1.1 2005/05/31 22:04:54 hamiltonc Exp $
+} {
+    {orderby email_address}
+    {page 1}    
+    {search:trim ""}
+    section_id:integer,optional
+    {return_url ""}
+} -properties {
+} -validate {
+} -errors {
+}
+
+if { [exists_and_not_null section_id] } {
+
+    db_1row get_section_info "select c.course_id, s.section_name
+    from dotlrn_ecommerce_section s, dotlrn_catalogi c, cr_items ci
+    where s.course_id = c.item_id
+    and ci.live_revision=c.revision_id
+    and s.section_id = :section_id"
+
+    set context [list [list [export_vars -base course-info { course_id }] $section_name] "Process Purchase"]
+
+    db_1row get_community {
+	select community_id
+	from dotlrn_ecommerce_section
+	where section_id = :section_id
+    }
+
+    set return_url [export_vars -base [ad_conn package_url]admin/course-info {course_id}]
+
+    ad_form -name "search" -export { section_id patron return_url } -form {
+	{search:text {label "Search existing users"}}
+    }
+
+    set add_action "Choose Participant"
+
+    if { ! [empty_string_p $search] } {
+
+	set page_query {
+	    select user_id, email, first_names, last_name
+	    from dotlrn_users
+	    where lower(first_names||' '||last_name||' '||email) like '%'||lower(:search)||'%'
+
+	    and not user_id
+	    in (select user_id
+		from dotlrn_member_rels_full
+		where community_id = :community_id)}
+	
+
+	template::list::create \
+	    -name "users" \
+	    -multirow "users" \
+	    -no_data "No users found" \
+	    -key user_id \
+	    -page_query $page_query \
+	    -page_size 50 \
+	    -page_flush_p 1 \
+	    -elements {
+		user_id {
+		    label "User ID"
+		}
+		email {
+		    label "Email Address"
+		}
+		first_names {
+		    label "First Name"
+		}
+		last_name {
+		    label "Last Name"
+		}
+		action {
+		    html { nowrap }
+		    display_template {
+			<a href="@users.add_member_url;noquote@" class="button">$add_action</a>
+		    }
+		}
+	    } \
+	    -filters {
+		search {}
+		section_id {}
+	    }
+
+	db_multirow -extend { add_member_url } users users [subst {
+	    $page_query
+	    [template::list::page_where_clause -name users -key user_id -and]
+	}] {
+	    set add_member_url [export_vars -base membership-add { user_id {referer $return_url} section_id community_id }]
+	}
+    }
+
+    template::list::create \
+	-name members \
+	-multirow members \
+	-no_data "No users has purchased this section" \
+	-page_flush_p 1 \
+	-key user_id \
+	-bulk_actions { "Remove Membership" membership-remove "Remove Membership" } \
+	-bulk_action_export_vars { community_id return_url patron } \
+	-elements {
+	    user_id {
+		label "User ID"
+	    }
+	    email {
+		label "Email Address"
+	    }
+	    first_names {
+		label "First Name"
+	    }
+	    last_name {
+		label "Last Name"
+	    }
+	} \
+	-filters {
+	    search {}
+	    section_id {}
+	}
+
+    db_multirow members members {
+	select r.user_id, r.rel_id, r.role, u.first_names, u.last_name, u.email
+	from dotlrn_member_rels_full r, dotlrn_users u
+	where r.member_state = 'approved'
+	and r.rel_type = 'dotlrn_member_rel'
+	and r.user_id = u.user_id
+	and r.community_id = :community_id
+    }
+
+}
+
+set next_url [export_vars -base membership-add { section_id community_id { referer $return_url} }]
\ No newline at end of file
Index: openacs-4/packages/dotlrn-ecommerce/www/admin/section-add-edit.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/admin/section-add-edit.adp,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/dotlrn-ecommerce/www/admin/section-add-edit.adp	31 May 2005 22:04:54 -0000	1.1
@@ -0,0 +1,8 @@
+<master>
+<property name="title">@page_title@</property>
+<property name="context">@context@</property>
+<property name="focus">add_class_instance.term</property>
+
+<formtemplate id="add_section"></formtemplate>
+
+
Index: openacs-4/packages/dotlrn-ecommerce/www/admin/section-add-edit.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/admin/section-add-edit.tcl,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/dotlrn-ecommerce/www/admin/section-add-edit.tcl	31 May 2005 22:04:54 -0000	1.1
@@ -0,0 +1,653 @@
+ad_page_contract {
+
+    @author Deds Castillo
+    @creation-date 2004-05-01
+    @version $Id: section-add-edit.tcl,v 1.1 2005/05/31 22:04:54 hamiltonc Exp $
+} {
+    course_id:notnull
+    section_id:optional
+    {return_url "" }
+
+    {sessions:integer,multiple {}}
+}
+
+dotlrn_catalog::get_course_data -course_id $course_id
+set item_id [dotlrn_catalog::get_item_id -revision_id $course_id]
+
+set package_id [ad_conn package_id]
+
+catch {
+    db_1row template_community {
+	select community_id as template_community_id
+	from dotlrn_catalogi
+	where course_id = :course_id
+    }
+    set template_calendar_id [dotlrn_calendar::get_group_calendar_id -community_id $template_community_id]
+    set template_item_type_id [db_string item_type_id "select item_type_id from cal_item_types where type='Session' and  calendar_id = :template_calendar_id limit 1" -default 0]
+}
+	
+ad_form -name add_section -form {
+    section_id:key
+    {product_id:integer(hidden)}
+    {return_url:text(hidden) {value $return_url}}
+    {course_id:text(hidden) {value $course_id}}
+    {section_name:text {label "Section Name"}}     
+    {price:currency,to_sql(sql_number) {label "Regular Price"} {html {size 6}} {section "Product Info"}} 
+}
+
+
+# HAM : Let's check if we have MemberPriceP enabled and set
+# if it is let's add Member Price text
+if { [parameter::get -package_id [ad_conn package_id] -parameter MemberPriceP -default 0 ] } {
+	ad_form -extend -name add_section -form {
+		{ member_price:currency,to_sql(sql_number),optional {label "Member Price"} {html {size 6}} }
+	}
+}
+
+# HAM : Let's get the community id's for both Instructors and Assistants
+
+set instructor_community_id [parameter::get -package_id [ad_conn package_id] -parameter InstructorCommunityId -default 0 ]
+set assistant_community_id [parameter::get -package_id [ad_conn package_id] -parameter AssistantCommunityId -default 0 ]
+
+
+# HAM : Let's check if we have InstructorCommunityId enabled and set
+if { $instructor_community_id == 0 && ![db_0or1row "checkinstructorcommunity" "select community_id from dotlrn_communities where community_id = :instructor_community_id"] } {
+	ad_return_complaint 1 "Parameter InstructorCommunityId is not set or Community Id does not exist."
+} else {
+	# community_id is valid
+	# list users
+	set _instructors [dotlrn_community::list_users  $instructor_community_id]
+	set instructors_list [list]
+	foreach instructor $_instructors {
+		set instructor_user_id [ns_set get $instructor user_id]
+		set instructor_name "[ns_set get $instructor first_names] [ns_set get $instructor last_name]"
+		lappend instructors_list [list $instructor_name $instructor_user_id ]
+	}
+	
+	ad_form -extend -name add_section -form {
+		{ instructors:string(multiselect),multiple,optional {label "Instructors"} {options { $instructors_list } }	}
+	}
+}
+
+# HAM : Let's check if we have AssistantCommunityId enabled and set
+if { $assistant_community_id == 0 && ![db_0or1row "checkassistantcommunity" "select community_id from dotlrn_communities where community_id = :assistant_community_id"] } {
+	ad_return_complaint 1 "Parameter AssistantCommunityId is not set or Community Id does not exist."
+} else {
+	# community_id is valid
+	set _assistants [dotlrn_community::list_users  $assistant_community_id]
+	set assistants_list [list]
+	foreach assistant $_assistants {
+		set assistant_user_id [ns_set get $assistant user_id]
+		set assistant_name "[ns_set get $assistant first_names] [ns_set get $assistant last_name]"
+		lappend assistants_list [list $assistant_name $assistant_user_id ]
+	}
+	
+	ad_form -extend -name add_section -form {
+		{ assistants:string(multiselect),multiple,optional {label "Assistants"} {options { $assistants_list } }	}
+	}
+
+}
+
+
+if { ! [ad_form_new_p -key section_id] } {
+    db_1row community {
+	select community_id
+	from dotlrn_ecommerce_section
+	where section_id = :section_id
+    }
+    ad_form -extend -name add_section -form {
+	{categories:text(category),multiple,optional
+	    {label "Categories"}
+	    {html {size 4}}
+	    {value "$community_id $package_id"}
+	}
+    }
+} else {
+    ad_form -extend -name add_section -form {
+	{categories:text(category),multiple,optional
+	    {label "Categories"}
+	    {html {size 4}}
+	}
+    }
+}
+
+
+# ecommerce stuff
+
+set exclude_list [list "'classid'"]
+
+db_foreach custom_fields_select "
+    select field_identifier,
+           field_name,
+           default_value,
+           column_type
+    from ec_custom_product_fields
+    where active_p='t'
+          and field_identifier not in ([join $exclude_list ", "])
+    order by creation_date" {
+    # date
+    if {[string equal $column_type date] || [string equal $column_type timestamp]} {
+        if {[string equal $field_identifier enddate]} {
+            ad_form -extend -name add_section -form [list \
+							 [list "${field_identifier}:date,optional" {label $field_name} {value $default_value} {help_text "Not required for Distance Learning Courses"}]]
+	} else {
+	    ad_form -extend -name add_section -form [list \
+							 [list "${field_identifier}:date,optional" {label $field_name} {value $default_value}] \
+							]
+	}
+    } elseif {[string equal $column_type integer] || [string equal $column_type number]} {
+	ad_form -extend -name add_section -form [list \
+						     [list "${field_identifier}:float,optional" {label $field_name} {value $default_value} {html {size 5}}] \
+						    ]
+    } elseif {[string equal $column_type "varchar(200)"]} {
+	ad_form -extend -name add_section -form [list \
+						     [list "${field_identifier}:text(text),optional" {label $field_name} {value $default_value} {html {size 50 maxlength 200}}] \
+						    ]
+    } elseif {[string equal $column_type "varchar(4000)"]} {
+	ad_form -extend -name add_section -form [list \
+						     [list "${field_identifier}:text(textarea),optional" {label $field_name} {value $default_value} {html {rows 4 cols 60}}] \
+						    ]
+    } else {
+	ad_form -extend -name add_section -form [list \
+						     [list "${field_identifier}:text(radio),optional" {label $field_name} {value $default_value} {options {{t t} {f f}}}] \
+						    ]
+    }
+}
+
+# Create the section for predefined sessions
+set validate [list]
+
+if { [info exists template_calendar_id] } {
+    set sessions_list [db_list_of_lists sessions {
+	select   'cal_item_id',
+	ci.cal_item_id,
+	'typical_start_time',
+	to_char(start_date,'HH24:MI') as typical_start_time,
+	'typical_end_time',
+	to_char(end_date,'HH24:MI') as typical_end_time,
+	'session_name',
+	coalesce(e.name, a.name) as session_name,
+	'session_description',
+	coalesce(e.status_summary, a.status_summary) as session_description,
+	'start_date',
+	to_char(start_date, 'yyyy-mm-dd'),
+	'end_date',
+	to_char(end_date, 'yyyy-mm-dd')
+	from     acs_activities a,
+	acs_events e,
+	timespans s,
+	time_intervals t,
+	calendars cals,
+	cal_items ci left join
+	cal_item_types cit on cit.item_type_id = ci.item_type_id
+	where    e.timespan_id = s.timespan_id
+	and      s.interval_id = t.interval_id
+	and      e.activity_id = a.activity_id
+	and      ci.cal_item_id= e.event_id
+	and      cals.calendar_id = ci.on_which_calendar
+	and      e.event_id = ci.cal_item_id
+	and	 ci.on_which_calendar = :template_calendar_id
+	and      ci.item_type_id = :template_item_type_id
+    }]
+} else {
+    set sessions_list [list]
+}
+
+if { [llength $sessions_list] } {
+    ad_form -extend -name add_section -form {
+	{-section "Predefined Sessions"}
+    }
+}
+
+foreach s $sessions_list {
+    array set session $s
+    template::util::array_to_vars session
+
+    # Roel: It might be better to create a widget for all these
+    set checked " checked"
+    if { [llength $sessions] } {
+	if { [lsearch $sessions $cal_item_id] == -1 } {
+	    set checked ""
+	}
+    }
+
+    ad_form -extend -name add_section -form [subst -nobackslashes -nocommands {
+	{$cal_item_id:text(text),optional
+	    {label {$session_name}}
+	    {html {id sel$cal_item_id}}
+	    {before_html {<input type=checkbox name='sessions' value='$cal_item_id'$checked> Create this session<br />}}
+	    {after_html {<input type='reset' value=' ... ' onclick=\"return showCalendar('sel$cal_item_id', 'y-m-d');\"> \[<b>y-m-d </b>\]}}
+	}
+	{${cal_item_id}_start_time:date,optional {label "From"} {format {[lc_get formbuilder_time_format]}}}
+	{${cal_item_id}_end_time:date,optional {label "To"} {format {[lc_get formbuilder_time_format]}}}
+    }]
+
+    lappend validate [subst -nobackslashes -nocommands {$cal_item_id
+	{ [lsearch {$sessions} $cal_item_id] == -1 || ! [empty_string_p "[set $cal_item_id]"] }
+	"You must enter a date for \"$session_name\""
+    }]
+}
+
+ad_form -extend -name add_section -validate $validate -on_request {
+    # Set session times
+    foreach s $sessions_list {
+	array set session $s
+	template::util::array_to_vars session
+
+	set start_time [split $typical_start_time :]
+	set ${cal_item_id}_start_time [list {} {} {} [lindex $start_time 0] [lindex $start_time 1] {} {HH24:MI}]
+	set end_time [split $typical_end_time :]
+	set ${cal_item_id}_end_time [list {} {} {} [lindex $end_time 0] [lindex $end_time 1] {} {HH24:MI}]
+	
+	set ${cal_item_id} $start_date
+    }
+} -new_request {
+    set product_id 0
+} -edit_request {
+    set course_item_id $course_id
+    db_1row community {
+	select des.*, p.price
+	from dotlrn_ecommerce_section des, ec_products p
+	where des.product_id = p.product_id
+	and des.section_id = :section_id
+    }
+    set course_id $course_item_id
+
+	# HAM
+	# price is using currency_widget
+	set price_split [split $price .]
+	set price [template::util::currency::create "$" [lindex $price_split 0] [lindex $price_split 1] ]
+
+    db_1row custom_fields {
+	select * from ec_custom_product_field_values where product_id = :product_id
+    }
+
+    # Get instructors and assistants
+    set instructors [db_list instructors {
+	select user_id
+	from dotlrn_member_rels_approved
+	where community_id = :community_id
+	and rel_type = 'dotlrn_admin_rel'
+	and user_id in (select user_id
+			from dotlrn_member_rels_approved
+			where community_id = :instructor_community_id)
+    }]
+
+    set assistants [db_list assistants {
+	select user_id
+	from dotlrn_member_rels_approved
+	where community_id = :community_id
+	and rel_type = 'dotlrn_club_instructor_rel'
+	and user_id in (select user_id
+			from dotlrn_member_rels_approved
+			where community_id = :assistant_community_id)
+    }]
+
+    if { [parameter::get -package_id [ad_conn package_id] -parameter MemberPriceP -default 0 ] } {
+	if { [db_0or1row member_price {
+	    select sale_price as member_price
+	    from ec_sale_prices
+	    where product_id = :product_id
+	    limit 1
+	}] } {
+	    # HAM
+	    # member_price is using currency_widget
+	    set member_price_split [split $member_price .]
+	    set member_price [template::util::currency::create "$" [lindex $member_price_split 0] [lindex $member_price_split 1] ]
+	}
+    }
+} -new_data {
+    db_transaction {
+        # create the class instance
+	# See if we have a template community
+	# If yes, clone it
+	if { [exists_and_not_null template_community_id] } {
+	    set community_id [dotlrn_community::clone \
+				  -community_id $template_community_id \
+				  -key [dotlrn_community::generate_key -name $section_name] \
+				  -pretty_name "$course_data(name): Section $section_name"]
+
+	    ns_log notice "DEBUG:: Cloned $community_id from $template_community_id"
+	} else {
+	    set community_id [dotlrn_club::new -pretty_name "$course_data(name): Section $section_name"] 
+
+	    ns_log notice "DEBUG:: New community created"
+	}
+
+	# HAM : Let's add chosen instructors in the role of instructors 
+	# and assistants in the role of assistants
+	foreach instructor $instructors {
+		dotlrn_club::add_user -rel_type "dotlrn_admin_rel" -community_id $community_id -user_id $instructor -member_state "approved"
+	}
+	foreach assistant $assistants {
+		dotlrn_club::add_user -rel_type "dotlrn_club_instructor_rel" -community_id $community_id -user_id $assistant -member_state "approved"
+	}
+	
+       
+	# add the calendar item type "session"
+	set calendar_id [dotlrn_calendar::get_group_calendar_id -community_id $community_id]
+	if { ! [db_0or1row session_type {
+	    select item_type_id from cal_item_types where type='Session' and  calendar_id = :calendar_id limit 1
+	}] } {
+	    set item_type_id [calendar::item_type_new -calendar_id $calendar_id -type "Session"]
+	}
+
+
+ 	# create an ecommerce product
+	set product_id [db_nextval acs_object_id_seq]
+
+	set user_id [ad_conn user_id]
+	set context_id [ad_conn package_id]
+        set product_name "$section_name"
+        set sku ""
+        set one_line_description "$section_name"
+        set detailed_description ""
+        set search_keywords ""
+        set present_p "t"
+        set stock_status ""
+        # let's have dirname be the first four letters (lowercase) of the product_name
+        # followed by the product_id (for uniqueness)
+	regsub -all {[^a-zA-Z]} $product_name "" letters_in_product_name
+	set letters_in_product_name [string tolower $letters_in_product_name]
+	if [catch {set dirname "[string range $letters_in_product_name 0 3]$product_id"}] {
+            #maybe there aren't 4 letters in the product name
+            set dirname "$letters_in_product_name$product_id"
+        }
+	set color_list ""
+        set size_list ""
+	set peeraddr [ad_conn peeraddr]
+	set product_id [db_exec_plsql product_insert {
+            select ec_product__new(
+				   :product_id,
+				   :user_id,
+				   :context_id,
+				   :product_name,
+				   :price,
+				   :sku,
+				   :one_line_description,
+				   :detailed_description,
+				   :search_keywords,
+				   :present_p,
+				   :stock_status,
+				   :dirname,
+				   to_date(now(), 'YYYY-MM-DD'),
+				   :color_list,
+				   :size_list,
+				   :peeraddr
+				   )
+	}]
+
+	db_dml product_update {
+	    update ec_products
+	    set active_p = 't'
+	    where product_id = :product_id
+	}
+	# take care of custom fields
+        # we have to generate audit information
+        set audit_fields "last_modified, last_modifying_user, modified_ip_address"
+        set audit_info "now(), :user_id, :peeraddr"
+	
+        # things to insert into ec_custom_product_field_values if they exist
+	set custom_columns_to_insert [list product_id]
+	set custom_column_values_to_insert [list ":product_id"]
+	set bind_set [ns_set create]
+        ns_set put $bind_set product_id $product_id
+        ns_set put $bind_set user_id $user_id
+        ns_set put $bind_set peeraddr $peeraddr
+	
+	db_foreach custom_columns_select {
+            select field_identifier, column_type
+            from ec_custom_product_fields
+            where active_p='t'
+	} {
+	    if {[info exists $field_identifier] } {
+                lappend custom_columns_to_insert $field_identifier
+                lappend custom_column_values_to_insert ":$field_identifier"
+		if {[string equal $column_type date] || [string equal $column_type timestamp]} {
+		    set one_date [template::util::date::get_property linear_date_no_time [subst $$field_identifier]]
+                    ns_set put $bind_set $field_identifier $one_date
+		} else {
+		    ns_set put $bind_set $field_identifier [subst $$field_identifier]
+		}
+	    }
+	}
+	db_dml custom_fields_insert "
+        insert into ec_custom_product_field_values
+        ([join $custom_columns_to_insert ", "], $audit_fields)
+        values
+        ([join $custom_column_values_to_insert ","], $audit_info)
+        " -bind $bind_set
+
+	#HAM: create a sale item from the member price
+	# do so only if member price is provided
+	# and MemberPriceP is 1
+	if { [parameter::get -package_id [ad_conn package_id] -parameter MemberPriceP -default 0 ] && [exists_and_not_null member_price]} {
+
+		# HAM : FIXME
+
+		# not sure if these values are correct
+		# comment out when properly tested
+
+		set sale_price_id [db_nextval ec_sale_price_id_sequence]
+		set sale_price $member_price
+		set offer_code ""
+	
+		db_dml sale_insert "
+		insert into ec_sale_prices
+		(sale_price_id, product_id, sale_price, sale_begins, sale_ends, sale_name, offer_code, last_modified, last_modifying_user, modified_ip_address)
+		values
+		(:sale_price_id, :product_id, :sale_price, to_date(now() - '1 day':: interval,'YYYY-MM-DD HH24:MI:SS'), to_date(now() + '99 years':: interval,'YYYY-MM-DD HH24:MI:SS'), 'MemberPrice', :offer_code, now(), :user_id, :peeraddr)"
+	}
+
+	#CM: We should probably add ecomerce_product_id to ecommerce_Section and insert it here.
+
+	# Use item_id as course_id coz course_id is the revision and
+	# its easier to keep track of the item_id
+	db_dml add_section {
+	    insert into dotlrn_ecommerce_section(section_id, course_id, section_name, community_id,product_id) values
+	    (:section_id, :item_id, :section_name, :community_id, :product_id)
+	}
+
+	# for this to work, dotlrn_eccomerce_section must be an object 
+	# just use community_id DAVEB
+	# where do the terms options come from?! DAVEB
+	
+	category::map_object -object_id $community_id $categories
+
+	# Map patron relationships
+	set tree_id [parameter::get -package_id [ad_conn package_id] -parameter PatronRelationshipCategoryTree -default 0]
+	category_tree::map -tree_id $tree_id -object_id $community_id
+    }
+
+    if { [info exists calendar_id] } {
+	# Set predefined categories
+	# Unfortunately this seems to hang when inside the transaction
+	foreach s $sessions_list {	
+	    array set session $s
+    	    template::util::array_to_vars session
+					
+	    if { [lsearch $sessions $cal_item_id] != -1 } {
+		set date [set $cal_item_id]
+		set date [split $date "-"]
+		lappend date "" "" "" "YYYY MM DD"
+
+		set start_time [set ${cal_item_id}_start_time]
+		set end_time [set ${cal_item_id}_end_time]
+		set start_date [calendar::to_sql_datetime -date $date -time $start_time -time_p 1]
+		set end_date [calendar::to_sql_datetime -date $date -time $end_time -time_p 1]
+
+		set cal_item_id [calendar::item::new \
+				     -start_date $start_date \
+				     -end_date $end_date \
+				     -name $session_name \
+				     -description "$session_description" \
+				     -calendar_id $calendar_id \
+				     -item_type_id $item_type_id]
+	    }
+	}
+    }
+
+} -edit_data {
+
+    if { $categories == [list [list $community_id $package_id]] } {
+	set categories ""
+    }
+
+    db_transaction {
+	db_dml update_section {
+	    update dotlrn_ecommerce_section set
+	    section_name = :section_name
+	    where section_id = :section_id
+	}
+
+	# Change the community's name
+	dotlrn_community::set_community_name \
+	    -community_id $community_id \
+	    -pretty_name $section_name
+
+	# Update price
+	db_dml update_price {
+	    update ec_products set price = :price where product_id = :product_id
+	}
+
+	# things to insert into ec_custom_product_field_values if they exist
+	set user_id [ad_conn user_id]
+	set peeraddr [ad_conn peeraddr]
+	set custom_columns_to_insert [list product_id]
+	set custom_column_values_to_insert [list ":product_id"]
+	set bind_set [ns_set create]
+	ns_set put $bind_set product_id $product_id
+	ns_set put $bind_set user_id $user_id
+	ns_set put $bind_set peeraddr $peeraddr
+
+	db_foreach custom_columns_select {
+	    select field_identifier, column_type
+	    from ec_custom_product_fields
+	    where active_p='t'
+	} {
+	    if {[info exists $field_identifier] } {
+		lappend custom_columns_to_update "$field_identifier = :$field_identifier"
+		if {[string equal $column_type date] || [string equal $column_type timestamp]} {
+		    set one_date [template::util::date::get_property linear_date_no_time [subst $$field_identifier]]
+		    ns_set put $bind_set $field_identifier $one_date
+		} else {
+		    ns_set put $bind_set $field_identifier [subst $$field_identifier]
+		}
+	    }
+	}
+	db_dml custom_fields_insert "
+        update ec_custom_product_field_values set [join $custom_columns_to_update ,] where product_id = :product_id
+        " -bind $bind_set
+
+	category::map_object -remove_old -object_id $community_id $categories
+	
+	# Set instructors
+	set original_instructors [db_list instructors {
+	    select user_id
+	    from dotlrn_member_rels_approved
+	    where community_id = :community_id
+	    and user_id in (select user_id
+			    from dotlrn_member_rels_approved
+			    where community_id = :instructor_community_id)
+	}]
+
+	set original_assistants [db_list assistants {
+	    select user_id
+	    from dotlrn_member_rels_approved
+	    where community_id = :community_id
+	    and user_id in (select user_id
+			    from dotlrn_member_rels_approved
+			    where community_id = :assistant_community_id)
+	}]
+	
+	# Remove unwanted instructors and assistants from community
+	foreach instructor $original_instructors {
+	    if { [lsearch $instructors $instructor] == -1 } {
+		catch {dotlrn_community::remove_user $community_id $instructor}
+	    }
+	}
+	
+	foreach assistant $original_assistants {
+	    if { [lsearch $assistants $assistant] == -1 } {
+		catch {dotlrn_community::remove_user $community_id $assistant}
+	    }
+	}
+
+	# Add new instructors and assistants 
+	foreach instructor $instructors {
+	    if { [lsearch $original_instructors $instructor] == -1 } {
+		catch {dotlrn_community::add_user -rel_type dotlrn_admin_rel $community_id $instructor}
+	    }
+	}
+	
+	foreach assistant $assistants {
+	    if { [lsearch $original_assistants $assistant] == -1 } {
+		catch {dotlrn_community::add_user -rel_type dotlrn_club_instructor_rel $community_id $assistant}
+	    }
+	}
+
+	# Set member price, this can be 1 to n but ignore for now
+	if { [parameter::get -package_id [ad_conn package_id] -parameter MemberPriceP -default 0 ] && [exists_and_not_null member_price]} {
+	    if { [db_0or1row sale_price {
+		select sale_price
+		from ec_sale_prices
+		where product_id = :product_id
+		limit 1
+	    }] } {
+		db_dml set_member_price {
+		    update ec_sale_prices
+		    set sale_price = :member_price
+		    where product_id = :product_id
+		}	
+	    } else {
+		set sale_price_id [db_nextval ec_sale_price_id_sequence]
+		set sale_price $member_price
+		set offer_code ""
+		
+		db_dml sale_insert "
+		insert into ec_sale_prices
+		(sale_price_id, product_id, sale_price, sale_begins, sale_ends, sale_name, offer_code, last_modified, last_modifying_user, modified_ip_address)
+		values
+		(:sale_price_id, :product_id, :sale_price, to_date(now() - '1 day':: interval,'YYYY-MM-DD HH24:MI:SS'), to_date(now() + '99 years':: interval,'YYYY-MM-DD HH24:MI:SS'), 'MemberPrice', :offer_code, now(), :user_id, :peeraddr)"
+	    }
+	}
+
+	dotlrn_ecommerce::section::flush_cache $section_id
+    }
+
+    set calendar_id [dotlrn_calendar::get_group_calendar_id -community_id $community_id]
+    set item_type_id [db_string item_type_id "select item_type_id from cal_item_types where type='Session' and  calendar_id = :calendar_id"]
+
+    foreach s $sessions_list {	
+	array set session $s
+	template::util::array_to_vars session
+	
+	if { [lsearch $sessions $cal_item_id] != -1 } {
+	    set date [set $cal_item_id]
+	    set date [split $date "-"]
+	    lappend date "" "" "" "YYYY MM DD"
+
+	    set start_time [set ${cal_item_id}_start_time]
+	    set end_time [set ${cal_item_id}_end_time]
+	    set start_date [calendar::to_sql_datetime -date $date -time $start_time -time_p 1]
+	    set end_date [calendar::to_sql_datetime -date $date -time $end_time -time_p 1]
+
+	    set cal_item_id [calendar::item::new \
+				 -start_date $start_date \
+				 -end_date $end_date \
+				 -name $session_name \
+				 -description "$session_description" \
+				 -calendar_id $calendar_id \
+				 -item_type_id $item_type_id]
+	}
+    }
+
+} -after_submit {
+    ad_returnredirect $return_url
+}
+
+
+# Used by en_US version of new_class_instance message
+set class_instances_pretty_name [parameter::get -localize -parameter class_instances_pretty_name]
+set page_title "Add Section"
+set context [list $page_title]
\ No newline at end of file
Index: openacs-4/packages/dotlrn-ecommerce/www/admin/section-add-sessions.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/admin/section-add-sessions.tcl,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/dotlrn-ecommerce/www/admin/section-add-sessions.tcl	31 May 2005 22:04:54 -0000	1.1
@@ -0,0 +1,21 @@
+ad_page_contract {
+    Redirects to the calendar to add sessions
+    @author          Caroline@meekshome.com
+} {
+    community_id
+    {return_url "" }
+}
+
+#Expected usage. you have just created a dotlrn_community and now you want to add sessions.
+
+
+
+set calendar_id [dotlrn_calendar::get_group_calendar_id -community_id $community_id]
+
+set url [calendar_portlet_display::get_url_stub $calendar_id]
+
+set item_type_id [db_string item_type_id "select item_type_id from cal_item_types where type = 'Session' and calendar_id = :calendar_id"]
+
+set num_sessions [db_string num_sessions "select count(cal_item_id) from cal_items where on_which_calendar = :calendar_id and item_type_id = :item_type_id"]
+
+ns_write "<a href=\"$url/view?[export_vars -url {{view list}}]\" target=new>$num_sessions Sessions</a> Scheduled. <a href=\"$url/cal-item-new?[export_vars -url {calendar_id item_type_id {view day}}]\" target=new>Add Sessions</a>"
Index: openacs-4/packages/dotlrn-ecommerce/www/admin/section-add.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/admin/section-add.adp,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/dotlrn-ecommerce/www/admin/section-add.adp	31 May 2005 22:04:54 -0000	1.1
@@ -0,0 +1,6 @@
+<master>
+<property name=title></property>
+<property name="context"></property>
+
+<formtemplate id="add_section"></formtemplate>
+
Index: openacs-4/packages/dotlrn-ecommerce/www/admin/section-add.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/admin/section-add.tcl,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/dotlrn-ecommerce/www/admin/section-add.tcl	31 May 2005 22:04:54 -0000	1.1
@@ -0,0 +1,67 @@
+ad_page_contract {
+    Displays information of one course
+    @author          Tracy Adams (teadams@alum.mit.edu)
+} {
+    course_id:notnull
+    section_id:optional
+    {return_url "" }
+}
+
+
+
+ad_form -name add_section -form {
+    section_id:key
+    {return_url:text(hidden) {value $return_url}}
+    {course_id:text(hidden) {value $course_id}}
+    {section_name:text}     
+
+} -new_data {
+
+    db_transaction {
+
+	set community_id [dotlrn_club::new  -pretty_name $section_name] 
+
+
+	db_dml add_section {
+	    insert into dotlrn_ecommerce_section(section_id, course_id, section_name, community_id) values
+	    (:section_id, :course_id, :section_name, :community_id)
+	}
+
+
+    }
+
+    ad_returnredirect $return_url
+
+
+} -edit_data {
+
+
+} -new_request {
+
+} -edit_request {
+
+}
+
+
+#create table dotlrn_ecommerce_section (
+#	section_id      integer primary key,
+#	community_id    integer references dotlrn_communities_all(community_id),
+#	section_name	varchar(2000),
+#	age		varchar(2000),
+#	date_time_start timestamptz,  	   
+#	date_time_end	timestamptz,
+#	daily_p		char(1) check (daily_p in ('t','f')),
+#	weekly_p        char(1) check (weekly_p in ('t','f')),	
+#	qualified_age_low   integer,
+#	qualified_age_high  integer,
+#	account_code_revenue varchar(100),
+#	account_code_expense varchar(100),
+#	max_participants     integer,
+#	waiting_list_p       char(1) check (daily_p in ('t','f')),
+#	notify_waiting_number integer,
+#	member_price_number   numeric,
+#	non_member_price      numeric
+#);
+
+
+
Index: openacs-4/packages/dotlrn-ecommerce/www/admin/section-delete.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/admin/section-delete.adp,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/dotlrn-ecommerce/www/admin/section-delete.adp	31 May 2005 22:04:54 -0000	1.1
@@ -0,0 +1,6 @@
+<master>
+<property name="title">@page_title@</property>
+<property name="context">@context@</property>
+
+@content;noquote@
+<formtemplate id="delete_section"></formtemplate>
\ No newline at end of file
Index: openacs-4/packages/dotlrn-ecommerce/www/admin/section-delete.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/admin/section-delete.tcl,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/dotlrn-ecommerce/www/admin/section-delete.tcl	31 May 2005 22:04:54 -0000	1.1
@@ -0,0 +1,42 @@
+ad_page_contract {
+
+	Delete a section
+
+    @author Hamilton Chua
+    @creation-date 2004-05-01
+    @version $Id: section-delete.tcl,v 1.1 2005/05/31 22:04:54 hamiltonc Exp $
+} {
+    section_id:notnull
+    {return_url "" }
+}
+
+set page_title "Delete Section"
+set context $page_title
+
+# create confirmation form
+set content "Are you sure you want to remove this section ? "
+
+ ad_form -name delete_section  \
+	-cancel_url $return_url  \
+	-form {
+		{return_url:text(hidden) { value $return_url } }
+		{section_id:text(hidden)  { value $section_id } }
+	} -on_submit {
+
+	# HAM : 
+	# for now just delete from dotlrn_ecommerce_sections and then archive
+	# discuss what else needs to be done for delete
+	
+	set community_id [db_string "getcomid" "select community_id from dotlrn_ecommerce_section where section_id=:section_id"]
+	
+	# delete from section table
+	db_dml "delete section"  "delete from dotlrn_ecommerce_section where section_id=:section_id "
+	
+	# archive community
+	dotlrn_community::archive -community_id $community_id
+
+
+
+    } -after_submit {
+	ad_returnredirect $return_url
+    }
Index: openacs-4/packages/dotlrn-ecommerce/www/admin/section-edit.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/admin/section-edit.adp,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/dotlrn-ecommerce/www/admin/section-edit.adp	31 May 2005 22:04:54 -0000	1.1
@@ -0,0 +1,5 @@
+<master>
+<property name="title">@page_title@</property>
+<property name="context">@context@</property>
+
+<formtemplate id="section-edit"></formtemplate>
\ No newline at end of file
Index: openacs-4/packages/dotlrn-ecommerce/www/admin/section-edit.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/admin/section-edit.tcl,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/dotlrn-ecommerce/www/admin/section-edit.tcl	31 May 2005 22:04:54 -0000	1.1
@@ -0,0 +1,144 @@
+# packages/dotlrn-ecommerce/www/admin/section-edit.tcl
+
+ad_page_contract {
+
+    Edit a section
+
+    @author Dave Bauer (dave@solutiongrove.com)
+    @creation-date 2005-05-16
+    
+} -query {
+    section_id:integer,notnull
+    {return_url ""}
+} -properties {
+    page_title
+    context
+}
+
+set package_id [ad_conn package_id]
+set user_id [ad_conn user_id]
+
+#permission::require_permission \
+    -party_id $user_id \
+    -object_id $section_id \
+    -privilege "write"
+
+ad_form -name section-edit \
+    -export { return_url } \
+    -form {
+    section_id:key
+	{product_id:text(hidden)}
+	{course_id:text(hidden)}
+	{community_id:text(hidden)}
+    {section_name:text {label "Section Name"}}     
+    {price:text(text) {label "Regular Price"} {html {size 6}} {section "Product Info"}} 
+    {terms:integer(category),multiple,optional
+	{label "Terms"}
+	{html {size 4}}
+    }
+}
+# ecommerce stuff
+
+set exclude_list [list "'classid'"]
+
+db_foreach custom_fields_select "
+    select field_identifier,
+           field_name,
+           default_value,
+           column_type
+    from ec_custom_product_fields
+    where active_p='t'
+          and field_identifier not in ([join $exclude_list ", "])
+    order by creation_date" {
+    # date
+    if {[string equal $column_type date] || [string equal $column_type timestamp]} {
+        if {[string equal $field_identifier enddate]} {
+            ad_form -extend -name section-edit -form [list \
+							 [list "${field_identifier}:date,optional" {label $field_name} {value $default_value} {help_text "Not required for Distance Learning Courses"}]]
+	} else {
+	    ad_form -extend -name section-edit -form [list \
+							 [list "${field_identifier}:date,optional" {label $field_name} {value $default_value}] \
+							]
+	}
+    } elseif {[string equal $column_type integer] || [string equal $column_type number]} {
+	ad_form -extend -name section-edit -form [list \
+						     [list "${field_identifier}:text(text),optional" {label $field_name} {value $default_value} {html {size 5}}] \
+						    ]
+    } elseif {[string equal $column_type "varchar(200)"]} {
+	ad_form -extend -name section-edit -form [list \
+						     [list "${field_identifier}:text(text),optional" {label $field_name} {value $default_value} {html {size 50 maxlength 200}}] \
+						    ]
+    } elseif {[string equal $column_type "varchar(4000)"]} {
+	ad_form -extend -name section-edit -form [list \
+						     [list "${field_identifier}:text(textarea),optional" {label $field_name} {value $default_value} {html {rows 4 cols 60}}] \
+						    ]
+    } else {
+	ad_form -extend -name section-edit -form [list \
+						     [list "${field_identifier}:text(radio),optional" {label $field_name} {value $default_value} {options {{t t} {f f}}}] \
+						    ]
+    }
+}
+
+
+ad_form -extend -name section-edit \
+    -edit_request {
+	# fill in the form
+	db_1row get_section "select * from dotlrn_ecommerce_section where section_id=:section_id"
+	# get price from product
+	db_1row get_product "select price from ec_products where product_id=:product_id"
+	# get custom fields
+	db_1row get_custom_values "select * from ec_custom_product_field_values where product_id=:product_id"
+	# get categoriees
+	element set_properties section-edit terms -category_object_id $community_id
+    } -edit_data {
+	db_transaction {
+	    set bind_set [ns_set create]
+	    ns_set put $bind_set product_id $product_id
+	    ns_set put $bind_set user_id $user_id
+	    ns_set put $bind_set peeraddr [ad_conn peeraddr]
+
+	    db_foreach custom_columns_select {
+		select field_identifier, column_type
+		from ec_custom_product_fields
+		where active_p='t'
+	    } {
+		if {[info exists $field_identifier] } {
+		    lappend custom_columns  "${field_identifier}=:${field_identifier}"
+		    if {[string equal $column_type date] || [string equal $column_type timestamp]} {
+			set one_date [template::util::date::get_property linear_date_no_time [subst $$field_identifier]]
+			ns_set put $bind_set $field_identifier $one_date
+		    } else {
+			ns_set put $bind_set $field_identifier [subst $$field_identifier]
+		    }
+		}
+	    }
+	    db_dml custom_fields_update "
+                update ec_custom_product_field_values set [join $custom_columns ","] where product_id=:product_id
+            " -bind $bind_set
+
+
+	    db_dml update_product {
+		update ec_products set price=:price where product_id=:product_id
+	    }
+	db_dml update_section {
+	   update dotlrn_ecommerce_section set section_name=:section_name where section_id=:section_id
+	}
+	    # attach categories to the community_id or product_id, we have plenty of objects to work with!
+	    # it works, but I can't get the terms values to display as selected.
+	    # where is the options for the terms form element set!? DAVEB
+	    if { ![string equal $terms "-1"] } {
+		category::map_object -remove_old -object_id $community_id $terms
+	    }
+
+	}
+    } -after_submit {
+	if {[string equal "" $return_url]} {
+	    set return_url [export_vars -base "course-info" {course_id}]
+	}
+	ad_returnredirect $return_url
+    }
+
+set page_title "Edit Section"
+set context [list $page_title]
+
+ad_return_template
\ No newline at end of file