Index: openacs-4/packages/acs-datetime/tcl/acs-calendar-2-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-datetime/tcl/acs-calendar-2-procs.tcl,v
diff -u -r1.28 -r1.29
--- openacs-4/packages/acs-datetime/tcl/acs-calendar-2-procs.tcl	19 Jun 2002 19:14:30 -0000	1.28
+++ openacs-4/packages/acs-datetime/tcl/acs-calendar-2-procs.tcl	22 Jul 2002 21:46:19 -0000	1.29
@@ -226,7 +226,7 @@
     for {set hour $start_hour} {$hour <= $end_hour} {incr hour} {
         if {$max_n_events < $n_events($hour)} {
             set max_n_events $n_events($hour)
-            #ns_log Notice "BMA-DEBUG-CAL: Setting max_n_events to $max_n_events"
+            ns_log Notice "BMA-DEBUG-CAL: Setting max_n_events to $max_n_events"
         }
     }
     
@@ -358,9 +358,15 @@
         }
 
         if {$n_processed_events == 0 || ($n_events($hour) < $max_n_events && $must_complete_p)} {
-            for {set i 0} {$i < [expr "$max_n_events - $n_events($hour)"]} {incr i} {
-                append return_html "<td colspan=\"1\" bgcolor=\"#dddddd\">&nbsp;</td>"
-            }
+            if {$n_events($hour) == 0 || $n_events($hour) == $n_processed_events} {
+		append return_html "<td colspan=\"[expr $max_n_events - $n_events($hour)]\" bgcolor=\"#dddddd\">&nbsp;</td>"
+	    } else {
+		for {set i 0} {$i < [expr "$max_n_events - $n_events($hour)"]} {incr i} {
+		    append return_html "<td colspan=\"1\" bgcolor=\"#dddddd\">&nbsp;</td>"
+		}
+	    }
+	    
+
         }
 
         append return_html "</tr>\n"
Index: openacs-4/packages/acs-events/sql/postgresql/oracle-compat-create.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-events/sql/postgresql/oracle-compat-create.sql,v
diff -u -r1.1 -r1.2
--- openacs-4/packages/acs-events/sql/postgresql/oracle-compat-create.sql	13 Jul 2001 02:48:51 -0000	1.1
+++ openacs-4/packages/acs-events/sql/postgresql/oracle-compat-create.sql	22 Jul 2002 21:46:19 -0000	1.2
@@ -78,14 +78,14 @@
        integer,
        varchar
 )
-returns interval as '	
+returns timespan as '	
 declare    
        interval__number	     alias for $1;
        interval__units	     alias for $2;
 begin
 
 	-- We should probably do unit checking at some point
-	return '''''''' || interval__number || '' '' || interval__units || '''''''' || ''::interval'';
+	return ('''''''' || interval__number || '' '' || interval__units || '''''''')::timespan;
 
 end;' language 'plpgsql';
 
Index: openacs-4/packages/calendar/calendar.info
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/calendar/calendar.info,v
diff -u -r1.11 -r1.12
--- openacs-4/packages/calendar/calendar.info	3 Jun 2002 04:08:17 -0000	1.11
+++ openacs-4/packages/calendar/calendar.info	22 Jul 2002 21:46:19 -0000	1.12
@@ -38,7 +38,9 @@
             <file type="data_model_create" db_type="postgresql" path="sql/postgresql/calendar-create.sql"/>
             <file type="data_model_drop" db_type="postgresql" path="sql/postgresql/calendar-drop.sql"/>
             <file type="query_file" db_type="oracle" path="tcl/cal-item-2-procs-oracle.xql"/>
+            <file type="query_file" db_type="postgresql" path="tcl/cal-item-2-procs-postgresql.xql"/>
             <file type="tcl_procs" path="tcl/cal-item-2-procs.tcl"/>
+            <file type="query_file" path="tcl/cal-item-2-procs.xql"/>
             <file type="query_file" db_type="oracle" path="tcl/cal-item-procs-oracle.xql"/>
             <file type="query_file" db_type="postgresql" path="tcl/cal-item-procs-postgresql.xql"/>
             <file type="tcl_procs" path="tcl/cal-item-procs.tcl"/>
@@ -96,6 +98,7 @@
             <file type="query_file" db_type="postgresql" path="www/cal-item-delete-confirm-postgresql.xql"/>
             <file type="content_page" path="www/cal-item-delete-confirm.adp"/>
             <file type="content_page" path="www/cal-item-delete-confirm.tcl"/>
+            <file type="content_page" path="www/cal-item-delete.tcl"/>
             <file type="content_page" path="www/cal-item-edit.adp"/>
             <file type="content_page" path="www/cal-item-edit.tcl"/>
             <file type="content_page" path="www/cal-item-new.adp"/>
@@ -133,6 +136,7 @@
             <file type="documentation" path="www/doc/regressionTest.htm"/>
             <file type="documentation" path="www/doc/requirements.html"/>
             <file type="documentation" path="www/doc/thesisUsabilityTest.htm"/>
+            <file type="content_page" path="www/ics/index.vuh"/>
             <file type="content_page" path="www/index.adp"/>
             <file type="content_page" path="www/index.tcl"/>
             <file type="content_page" path="www/item-type-delete.tcl"/>
Index: openacs-4/packages/calendar/sql/postgresql/cal-item-create.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/calendar/sql/postgresql/cal-item-create.sql,v
diff -u -r1.9 -r1.10
--- openacs-4/packages/calendar/sql/postgresql/cal-item-create.sql	18 Jun 2002 19:56:04 -0000	1.9
+++ openacs-4/packages/calendar/sql/postgresql/cal-item-create.sql	22 Jul 2002 21:46:19 -0000	1.10
@@ -194,12 +194,13 @@
 RETURNS integer AS '
 declare
     delete__recurrence_id		alias for $1;
-    v_event_id                          integer;
+    v_event                             RECORD;
 begin
-    for v_event_id in (select event_id from acs_events
-                      where recurrence_id= delete__recurrence_id)
+    for v_event in 
+	select event_id from acs_events
+        where recurrence_id= delete__recurrence_id
     LOOP
-        PERFORM cal_item__delete(v_event_id);
+        PERFORM cal_item__delete(v_event.event_id);
     END LOOP;
 
     PERFORM recurrence__delete(delete__recurrence_id);
Index: openacs-4/packages/calendar/tcl/cal-item-2-procs-oracle.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/calendar/tcl/Attic/cal-item-2-procs-oracle.xql,v
diff -u -r1.3 -r1.4
--- openacs-4/packages/calendar/tcl/cal-item-2-procs-oracle.xql	10 Jul 2002 14:58:25 -0000	1.3
+++ openacs-4/packages/calendar/tcl/cal-item-2-procs-oracle.xql	22 Jul 2002 21:46:19 -0000	1.4
@@ -10,6 +10,9 @@
             cal_items.cal_item_id,
             0 as n_attachments,
             to_char(start_date,'HH:MIpm')as start_time,
+            to_char(start_date,'D') as day_of_week,
+            to_char(start_date,'Day') as pretty_day_of_week,
+            to_char(start_date,'DD') as day_of_month,
             start_date as start_date,
             to_char(start_date, 'MM/DD/YYYY') as pretty_short_start_date,
             to_char(end_date, 'HH:MIpm') as end_time,
@@ -44,6 +47,9 @@
             cal_items.cal_item_id,
             (select count(*) from attachments where object_id = cal_item_id) as n_attachments,
             to_char(start_date,'HH:MIpm')as start_time,
+            to_char(start_date,'D') as day_of_week,
+            to_char(start_date,'Day') as pretty_day_of_week,
+            to_char(start_date,'DD') as day_of_month,
             start_date as start_date,
             to_char(start_date, 'MM/DD/YYYY') as pretty_short_start_date,
             to_char(end_date, 'HH:MIpm') as end_time,
@@ -71,4 +77,23 @@
 </querytext>
 </fullquery>
 
+<fullquery name="calendar::item::add_recurrence.create_recurrence">
+<querytext>
+begin
+   :1 := recurrence.new(interval_type => :interval_type,
+    	every_nth_interval => :every_n,
+    	days_of_week => :days_of_week,
+    	recur_until => :recur_until);
+end;
+</querytext>
+</fullquery>
+
+<fullquery name="calendar::item::add_recurrence.insert_instances">
+<querytext>
+begin
+   acs_event.insert_instances(event_id => :cal_item_id);
+end;
+</querytext>
+</fullquery>
+
 </queryset>
Index: openacs-4/packages/calendar/tcl/cal-item-2-procs-postgresql.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/calendar/tcl/Attic/cal-item-2-procs-postgresql.xql,v
diff -u -r1.1 -r1.2
--- openacs-4/packages/calendar/tcl/cal-item-2-procs-postgresql.xql	6 Jul 2002 14:15:20 -0000	1.1
+++ openacs-4/packages/calendar/tcl/cal-item-2-procs-postgresql.xql	22 Jul 2002 21:46:19 -0000	1.2
@@ -9,6 +9,9 @@
          i.cal_item_id,
          0 as n_attachments,
          to_char(start_date,'HH:MIpm') as start_time,
+	 to_char(start_date,'D') as day_of_week,
+         to_char(start_date,'Day') as pretty_day_of_week,
+         to_char(start_date,'DD') as day_of_month,
          to_char(start_date, 'YYYY-MM-DD HH:MI:SS') as start_date,
          to_char(start_date, 'MM/DD/YYYY') as pretty_short_start_date,
          to_char(end_date, 'HH:MIpm') as end_time,
@@ -40,6 +43,9 @@
          i.cal_item_id,
          (select count(*) from attachments where object_id = cal_item_id) as n_attachments,
          to_char(start_date,'HH:MIpm') as start_time,
+	 to_char(start_date,'D') as day_of_week,
+         to_char(start_date,'Day') as pretty_day_of_week,
+         to_char(start_date,'DD') as day_of_month,
          to_char(start_date, 'YYYY-MM-DD HH:MI:SS') as start_date,
          to_char(start_date, 'MM/DD/YYYY') as pretty_short_start_date,
          to_char(end_date, 'HH:MIpm') as end_time,
@@ -65,4 +71,20 @@
      </querytext>
    </fullquery>
 
+<fullquery name="calendar::item::add_recurrence.create_recurrence">
+<querytext>
+select recurrence__new(:interval_type,
+    	:every_n,
+    	:days_of_week,
+    	:recur_until,
+	NULL)
+</querytext>
+</fullquery>
+
+<fullquery name="calendar::item::add_recurrence.insert_instances">
+<querytext>
+select acs_event__insert_instances(:cal_item_id, NULL);
+</querytext>
+</fullquery>
+
 </queryset>
Index: openacs-4/packages/calendar/tcl/cal-item-2-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/calendar/tcl/Attic/cal-item-2-procs.tcl,v
diff -u -r1.2 -r1.3
--- openacs-4/packages/calendar/tcl/cal-item-2-procs.tcl	2 Jul 2002 21:17:07 -0000	1.2
+++ openacs-4/packages/calendar/tcl/cal-item-2-procs.tcl	22 Jul 2002 21:46:19 -0000	1.3
@@ -38,6 +38,32 @@
         db_1row $query_name {} -column_array row
     }
         
+    ad_proc -public add_recurrence {
+	{-cal_item_id:required}
+	{-interval_type:required}
+	{-every_n:required}
+	{-days_of_week ""}
+	{-recur_until ""}
+    } {
+	Adds a recurrence for a calendar item
+    } {
+	# We do things in a transaction
+	db_transaction {
+	    # Create the recurrence
+	    set recurrence_id [db_exec_plsql create_recurrence {}]
+	    
+	    # Update the events table
+	    db_dml update_event {}
+	    
+	    # Insert instances
+	    db_exec_plsql insert_instances {}
+	    
+	    # Make sure they're all in the calendar!
+	    db_dml insert_cal_items {}
+	}
+    }
+    
+
     ad_proc -public edit {
         {-cal_item_id:required}
         {-start_date:required}
Index: openacs-4/packages/calendar/tcl/cal-item-2-procs.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/calendar/tcl/Attic/cal-item-2-procs.xql,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/calendar/tcl/cal-item-2-procs.xql	22 Jul 2002 21:46:19 -0000	1.1
@@ -0,0 +1,27 @@
+<?xml version="1.0"?>
+
+<queryset>
+
+<fullquery name="calendar::item::add_recurrence.update_event">
+<querytext>
+update acs_events 
+set recurrence_id= :recurrence_id
+where event_id= :cal_item_id
+</querytext>
+</fullquery>
+
+<fullquery name="calendar::item::add_recurrence.insert_cal_items">
+<querytext>
+insert into cal_items 
+(cal_item_id, on_which_calendar)
+select
+event_id, 
+(select on_which_calendar 
+as calendar_id from cal_items 
+where cal_item_id = :cal_item_id)
+from acs_events where recurrence_id= :recurrence_id 
+and event_id <> :cal_item_id
+</querytext>
+</fullquery>
+
+</queryset>
Index: openacs-4/packages/calendar/www/cal-item-create-recurrence-2.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/calendar/www/Attic/cal-item-create-recurrence-2.tcl,v
diff -u -r1.3 -r1.4
--- openacs-4/packages/calendar/www/cal-item-create-recurrence-2.tcl	15 Mar 2002 06:37:26 -0000	1.3
+++ openacs-4/packages/calendar/www/cal-item-create-recurrence-2.tcl	22 Jul 2002 21:46:19 -0000	1.4
@@ -21,6 +21,6 @@
 ad_require_permission $cal_item_id cal_item_write
 
 # Set up the recurrence
-calendar_item_add_recurrence -cal_item_id $cal_item_id -interval_type $interval_type -every_n $every_n -days_of_week $days_of_week -recur_until [calendar_make_datetime [array get recur_until]]
+calendar::item::add_recurrence -cal_item_id $cal_item_id -interval_type $interval_type -every_n $every_n -days_of_week $days_of_week -recur_until [calendar_make_datetime [array get recur_until]]
 
 ad_returnredirect $return_url
Index: openacs-4/packages/calendar/www/cal-item-create-recurrence.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/calendar/www/cal-item-create-recurrence.adp,v
diff -u -r1.7 -r1.8
--- openacs-4/packages/calendar/www/cal-item-create-recurrence.adp	11 Jul 2002 18:18:25 -0000	1.7
+++ openacs-4/packages/calendar/www/cal-item-create-recurrence.adp	22 Jul 2002 21:46:19 -0000	1.8
@@ -14,21 +14,21 @@
 You are choosing to make this event recurrent, so that it appears more
 than once in your calendar. The event's details are:
 <p>
-<b>Date:</b> @start_date@<br>
-<b>Time:</b> @start_time@ - @end_time@<br>
-<b>Details:</b> @description@
+<b>Date:</b> @cal_item.start_date@<br>
+<b>Time:</b> @cal_item.start_time@ - @cal_item.end_time@<br>
+<b>Details:</b> @cal_item.description@
 <p>
 
 <FORM method=post action=cal-item-create-recurrence-2>
-<INPUT TYPE=hidden name=cal_item_id value=@cal_item_id@>
+<INPUT TYPE=hidden name=cal_item_id value=@cal_item.cal_item_id@>
 <INPUT TYPE=hidden name=return_url value="@return_url@">
 
 Repeat every <INPUT TYPE=text name=every_n value=1 size=3>:<br>
 <INPUT TYPE=radio name=interval_type value=day> day (s)<br>
 <INPUT TYPE=radio name=interval_type value=week> 
 <%
 foreach dow {{Sunday 0} {Monday 1} {Tuesday 2} {Wednesday 3} {Thursday 4} {Friday 5} {Saturday 6}} {
-        if {[lindex $dow 1] == [expr "$day_of_week -1"]} {
+        if {[lindex $dow 1] == [expr "$cal_item(day_of_week) -1"]} {
                 set checked_html "CHECKED"
         } else {
                 set checked_html ""
@@ -39,8 +39,8 @@
 %>
 of the week <br>
 <INPUT TYPE=radio name=interval_type value=month_by_date> day
-@day_of_month@ of the month <br>
-<INPUT TYPE=radio name=interval_type value=month_by_day> same @pretty_day_of_week@ of
+@cal_item.day_of_month@ of the month <br>
+<INPUT TYPE=radio name=interval_type value=month_by_day> same @cal_item.pretty_day_of_week@ of
 the month <br>
 <INPUT TYPE=radio name=interval_type value=year> year<br>
 Repeat this event until: <%= [dt_widget_datetime -default [dt_systime] recur_until] %>
Index: openacs-4/packages/calendar/www/cal-item-create-recurrence.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/calendar/www/cal-item-create-recurrence.tcl,v
diff -u -r1.3 -r1.4
--- openacs-4/packages/calendar/www/cal-item-create-recurrence.tcl	15 Mar 2002 06:37:26 -0000	1.3
+++ openacs-4/packages/calendar/www/cal-item-create-recurrence.tcl	22 Jul 2002 21:46:19 -0000	1.4
@@ -17,23 +17,7 @@
 ad_require_permission $cal_item_id cal_item_write
 
 # Select basic information about the event
-db_1row get_item_data { 
-    select   to_char(start_date,'HH24:MI')as start_time,
-    to_char(start_date, 'MM/DD/YYYY') as start_date,
-    to_char(end_date, 'HH24:MI') as end_time,
-    nvl(a. name, e.name) as name,
-    nvl(e.description, a.description) as description,
-    calendar_name,
-    to_char(start_date, 'D') as day_of_week,
-    to_char(start_date, 'Day') as pretty_day_of_week,
-    to_char(start_date, 'DD') as day_of_month
-    from     acs_activities a, acs_events e, timespans s, time_intervals t, calendars c, cal_items ci
-    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 = :cal_item_id
-    and      ci.cal_item_id= :cal_item_id
-    and      ci.on_which_calendar= c.calendar_id
-}
+calendar::item::get -cal_item_id $cal_item_id -array cal_item
 
-# Select information about which day of the week it is, etc...
+ad_return_template
+