Index: openacs-4/packages/calendar/tcl/cal-item-procs-oracle.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/calendar/tcl/cal-item-procs-oracle.xql,v
diff -u -r1.14 -r1.15
--- openacs-4/packages/calendar/tcl/cal-item-procs-oracle.xql	9 Mar 2009 20:20:55 -0000	1.14
+++ openacs-4/packages/calendar/tcl/cal-item-procs-oracle.xql	23 Nov 2017 08:43:16 -0000	1.15
@@ -3,94 +3,6 @@
 <queryset>
    <rdbms><type>oracle</type><version>8.1.6</version></rdbms>
 
-<fullquery name="calendar::item::dates_valid_p.dates_valid_p_select">      
-<querytext>
-          
-            select CASE WHEN (to_date(:start_date,'YYYY-MM-DD HH24:MI') - to_date(:end_date,'YYYY-MM-DD HH24:MI')) <= 0 
-                        THEN 1
-                        ELSE -1
-                   END 
-            from dual
-
-</querytext>
-</fullquery>
-
-<fullquery name="calendar::item::get.select_item_data">      
-<querytext>
-            
-            select cal_items.cal_item_id,
-                   0 as n_attachments,
-                   to_char(start_date, 'YYYY-MM-DD HH24:MI:SS') as start_date_ansi,
-                   to_char(end_date, 'YYYY-MM-DD HH24:MI:SS') as end_date_ansi,
-                   nvl(e.name, a.name) as name,
-                   nvl(e.description, a.description) as description,
-                   recurrence_id,
-                   cal_items.item_type_id,
-                   cal_item_types.type as item_type,
-                   on_which_calendar as calendar_id,
-                   c.calendar_name,
-                   o.creation_user,
-                   c.package_id as calendar_package_id,
-                   e.related_link_url,
-                   e.related_link_text,
-                   e.redirect_to_rel_link_p
-            from   acs_activities a,
-                   acs_events e,
-                   timespans s,
-                   time_intervals t,
-                   cal_items,
-                   cal_item_types,
-                   calendars c,
-                   acs_objects o
-            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    cal_items.cal_item_id= :cal_item_id
-            and    cal_item_types.item_type_id(+)= cal_items.item_type_id
-            and    c.calendar_id = on_which_calendar
-            and    o.object_id = cal_items.cal_item_id
-</querytext>
-</fullquery>
-
-<fullquery name="calendar::item::get.select_item_data_with_attachment">      
-<querytext>
-            
-            select cal_items.cal_item_id,
-                   (select count(*) from attachments where object_id = cal_item_id) as n_attachments,
-                   to_char(start_date, 'YYYY-MM-DD HH24:MI:SS') as start_date_ansi,
-                   to_char(end_date, 'YYYY-MM-DD HH24:MI:SS') as end_date_ansi,
-                   nvl(e.name, a.name) as name,
-                   nvl(e.description, a.description) as description,
-                   recurrence_id,
-                   cal_items.item_type_id,
-                   cal_item_types.type as item_type,
-                   on_which_calendar as calendar_id,
-                   c.calendar_name,
-                   o.creation_user,
-                   c.package_id as calendar_package_id,
-                   e.related_link_url,
-                   e.related_link_text,
-                   e.redirect_to_rel_link_p
-            from   acs_activities a,
-                   acs_events e,
-                   timespans s,
-                   time_intervals t,
-                   cal_items,
-                   cal_item_types,
-                   calendars c,
-                   acs_objects o
-            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    cal_items.cal_item_id= :cal_item_id
-            and    cal_item_types.item_type_id(+)= cal_items.item_type_id
-            and    c.calendar_id = on_which_calendar
-            and    o.object_id = cal_items.cal_item_id
-</querytext>
-</fullquery>
-
 <fullquery name="calendar::item::add_recurrence.create_recurrence">
 <querytext>
 begin
@@ -123,7 +35,6 @@
     
       </querytext>
 </fullquery>
-
  
 <fullquery name="calendar::item::new.insert_timespan">      
       <querytext>
@@ -137,7 +48,6 @@
     
       </querytext>
 </fullquery>
-
  
 <fullquery name="calendar::item::new.cal_item_add">      
       <querytext>
@@ -158,7 +68,7 @@
       </querytext>
 </fullquery>
 
- <fullquery name="calendar::item::delete.delete_cal_item">      
+<fullquery name="calendar::item::delete.delete_cal_item">      
       <querytext>
       
 	begin
@@ -209,52 +119,4 @@
 </querytext>
 </fullquery>
 
-<fullquery name="calendar::item::edit_recurrence.recurrence_events_update">
-    <querytext>
-    update acs_events set
-    [join $colspecs ", "]
-    where recurrence_id= :recurrence_id
-    and event_id in
-            (select e.event_id
-            from acs_events e, timespans t, time_intervals i
-            where e.recurrence_id = :recurrence_id
-            and t.timespan_id = e.timespan_id
-            and i.interval_id = t.interval_id
-            and (:edit_past_events_p = 't'
-                 or i.start_date >= :start_date)
-            )
-    </querytext>
-</fullquery>
-
-<fullquery name="calendar::item::edit_recurrence.recurrence_items_update">
-    <querytext>
-            update cal_items
-            set    [join $colspecs ", "]
-            where  cal_item_id in (select e.event_id
-            from acs_events e, timespans t, time_intervals i
-            where e.recurrence_id = :recurrence_id
-            and t.timespan_id = e.timespan_id
-            and i.interval_id = t.interval_id
-            and (:edit_past_events_p = 't'
-                 or i.start_date >= :start_date)
-            )
-    </querytext>
-</fullquery>
-
-<fullquery name="calendar::item::edit_recurrence.update_context_id">
-    <querytext>
-        update acs_objects
-        set    context_id = :calendar_id
-        where  object_id in
-            (select e.event_id
-            from acs_events e, timespans t, time_intervals i
-            where e.recurrence_id = :recurrence_id
-            and t.timespan_id = e.timespan_id
-            and i.interval_id = t.interval_id
-            and (:edit_past_events_p = 't'
-                 or i.start_date >= :start_date)
-            )
-    </querytext>
-</fullquery>
-
 </queryset>
Index: openacs-4/packages/calendar/tcl/cal-item-procs-postgresql.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/calendar/tcl/cal-item-procs-postgresql.xql,v
diff -u -r1.22 -r1.23
--- openacs-4/packages/calendar/tcl/cal-item-procs-postgresql.xql	9 Mar 2009 20:20:55 -0000	1.22
+++ openacs-4/packages/calendar/tcl/cal-item-procs-postgresql.xql	23 Nov 2017 08:43:16 -0000	1.23
@@ -2,93 +2,7 @@
 
 <queryset>
    <rdbms><type>postgresql</type><version>7.1</version></rdbms>
-    <fullquery name="calendar::item::dates_valid_p.dates_valid_p_select">
-      <querytext>
-        select CASE WHEN :start_date::timestamptz <= :end_date::timestamptz
-                    THEN 1
-                    ELSE -1
-               END 
-      </querytext>
-    </fullquery>
 
-    <fullquery name="calendar::item::get.select_item_data">      
-      <querytext>
-      select
-         i.cal_item_id,
-         0 as n_attachments,
-         to_char(start_date, 'YYYY-MM-DD HH24:MI:SS') as start_date_ansi,
-         to_char(end_date, 'YYYY-MM-DD HH24:MI:SS') as end_date_ansi,
-         coalesce(e.name, a.name) as name,
-         coalesce(e.description, a.description) as description,
-         recurrence_id,
-         i.item_type_id,
-         it.type as item_type,
-         on_which_calendar as calendar_id,
-         c.calendar_name,
-         o.creation_user,
-         c.package_id as calendar_package_id,
-         e.related_link_url,
-         e.related_link_text,
-         e.redirect_to_rel_link_p
-       from
-         acs_events e join timespans s
-           on (e.timespan_id = s.timespan_id)
-         join time_intervals t
-           on (s.interval_id = t.interval_id)
-         join acs_activities a
-           on (e.activity_id = a.activity_id)
-         join cal_items i
-           on (e.event_id = i.cal_item_id)
-         left join cal_item_types it
-           on (it.item_type_id = i.item_type_id)
-         left join calendars c
-           on (c.calendar_id = i.on_which_calendar)
-         left join acs_objects o
-           on (o.object_id = i.cal_item_id)
-       where
-         e.event_id = :cal_item_id
-      </querytext>
-    </fullquery>
-
-    <fullquery name="calendar::item::get.select_item_data_with_attachment">      
-      <querytext>
-       select
-         i.cal_item_id,
-         (select count(*) from attachments where object_id = cal_item_id) as n_attachments,
-         to_char(start_date, 'YYYY-MM-DD HH24:MI:SS') as start_date_ansi,
-         to_char(end_date, 'YYYY-MM-DD HH24:MI:SS') as end_date_ansi,
-         coalesce(e.name, a.name) as name,
-         coalesce(e.description, a.description) as description,
-         recurrence_id,
-         i.item_type_id,
-         it.type as item_type,
-         on_which_calendar as calendar_id,
-         c.calendar_name,
-         o.creation_user,
-         c.package_id as calendar_package_id,
-         e.related_link_url,
-         e.related_link_text,
-         e.redirect_to_rel_link_p
-       from
-         acs_events e join timespans s
-           on (e.timespan_id = s.timespan_id)
-         join time_intervals t
-           on (s.interval_id = t.interval_id)
-         join acs_activities a
-           on (e.activity_id = a.activity_id)
-         join cal_items i
-           on (e.event_id = i.cal_item_id)
-         left join cal_item_types it
-           on (it.item_type_id = i.item_type_id)
-         left join calendars c
-           on (c.calendar_id = i.on_which_calendar)
-         left join acs_objects o
-           on (o.object_id = i.cal_item_id)
-       where
-         e.event_id = :cal_item_id
-     </querytext>
-   </fullquery>
-
 <fullquery name="calendar::item::add_recurrence.create_recurrence">
 <querytext>
 select recurrence__new(:interval_type,
@@ -199,52 +113,4 @@
 </querytext>
 </fullquery>
 
-<fullquery name="calendar::item::edit_recurrence.recurrence_events_update">
-    <querytext>
-    update acs_events set
-    [join $colspecs ", "]
-    where recurrence_id= :recurrence_id
-    and event_id in
-            (select e.event_id
-            from acs_events e, timespans t, time_intervals i
-            where e.recurrence_id = :recurrence_id
-            and t.timespan_id = e.timespan_id
-            and i.interval_id = t.interval_id
-            and (:edit_past_events_p = 't'
-                 or i.start_date >= :start_date)
-            )
-    </querytext>
-</fullquery>
-
-<fullquery name="calendar::item::edit_recurrence.recurrence_items_update">
-    <querytext>
-            update cal_items
-            set    [join $colspecs ", "]
-            where  cal_item_id in (select e.event_id
-            from acs_events e, timespans t, time_intervals i
-            where e.recurrence_id = :recurrence_id
-            and t.timespan_id = e.timespan_id
-            and i.interval_id = t.interval_id
-            and (:edit_past_events_p = 't'
-                 or i.start_date >= :start_date)
-            )
-    </querytext>
-</fullquery>
-
-<fullquery name="calendar::item::edit_recurrence.update_context_id">
-    <querytext>
-        update acs_objects
-        set    context_id = :calendar_id
-        where  object_id in
-            (select e.event_id
-            from acs_events e, timespans t, time_intervals i
-            where e.recurrence_id = :recurrence_id
-            and t.timespan_id = e.timespan_id
-            and i.interval_id = t.interval_id
-            and (:edit_past_events_p = 't'
-                 or i.start_date >= :start_date)
-            )
-    </querytext>
-</fullquery>
-
 </queryset>
Index: openacs-4/packages/calendar/tcl/cal-item-procs.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/calendar/tcl/cal-item-procs.xql,v
diff -u -r1.8 -r1.9
--- openacs-4/packages/calendar/tcl/cal-item-procs.xql	8 Aug 2006 21:26:17 -0000	1.8
+++ openacs-4/packages/calendar/tcl/cal-item-procs.xql	23 Nov 2017 08:43:16 -0000	1.9
@@ -1,6 +1,141 @@
 <?xml version="1.0"?>
 <queryset>
 
+<fullquery name="calendar::item::dates_valid_p.dates_valid_p_select">      
+<querytext>          
+  select CASE
+    WHEN cast(:start_date as timestamp with time zone) <= cast(:end_date as timestamp with time zone) THEN 1
+    ELSE -1
+  END from dual
+</querytext>
+</fullquery>
+
+<fullquery name="calendar::item::get.select_item_data">      
+<querytext>
+      select
+         i.cal_item_id,
+         0 as n_attachments,
+         to_char(start_date, 'YYYY-MM-DD HH24:MI:SS') as start_date_ansi,
+         to_char(end_date, 'YYYY-MM-DD HH24:MI:SS') as end_date_ansi,
+         coalesce(e.name, a.name) as name,
+         coalesce(e.description, a.description) as description,
+         recurrence_id,
+         i.item_type_id,
+         it.type as item_type,
+         on_which_calendar as calendar_id,
+         c.calendar_name,
+         o.creation_user,
+         c.package_id as calendar_package_id,
+         e.related_link_url,
+         e.related_link_text,
+         e.redirect_to_rel_link_p
+       from
+         acs_events e join timespans s
+           on (e.timespan_id = s.timespan_id)
+         join time_intervals t
+           on (s.interval_id = t.interval_id)
+         join acs_activities a
+           on (e.activity_id = a.activity_id)
+         join cal_items i
+           on (e.event_id = i.cal_item_id)
+         left join cal_item_types it
+           on (it.item_type_id = i.item_type_id)
+         left join calendars c
+           on (c.calendar_id = i.on_which_calendar)
+         left join acs_objects o
+           on (o.object_id = i.cal_item_id)
+       where
+         e.event_id = :cal_item_id
+</querytext>
+</fullquery>
+
+<fullquery name="calendar::item::get.select_item_data_with_attachment">      
+<querytext>
+       select
+         i.cal_item_id,
+         (select count(*) from attachments where object_id = cal_item_id) as n_attachments,
+         to_char(start_date, 'YYYY-MM-DD HH24:MI:SS') as start_date_ansi,
+         to_char(end_date, 'YYYY-MM-DD HH24:MI:SS') as end_date_ansi,
+         coalesce(e.name, a.name) as name,
+         coalesce(e.description, a.description) as description,
+         recurrence_id,
+         i.item_type_id,
+         it.type as item_type,
+         on_which_calendar as calendar_id,
+         c.calendar_name,
+         o.creation_user,
+         c.package_id as calendar_package_id,
+         e.related_link_url,
+         e.related_link_text,
+         e.redirect_to_rel_link_p
+       from
+         acs_events e join timespans s
+           on (e.timespan_id = s.timespan_id)
+         join time_intervals t
+           on (s.interval_id = t.interval_id)
+         join acs_activities a
+           on (e.activity_id = a.activity_id)
+         join cal_items i
+           on (e.event_id = i.cal_item_id)
+         left join cal_item_types it
+           on (it.item_type_id = i.item_type_id)
+         left join calendars c
+           on (c.calendar_id = i.on_which_calendar)
+         left join acs_objects o
+           on (o.object_id = i.cal_item_id)
+       where
+         e.event_id = :cal_item_id
+</querytext>
+</fullquery>
+
+<fullquery name="calendar::item::edit_recurrence.recurrence_events_update">
+    <querytext>
+    update acs_events set
+    [join $colspecs ", "]
+    where recurrence_id= :recurrence_id
+    and event_id in
+            (select e.event_id
+            from acs_events e, timespans t, time_intervals i
+            where e.recurrence_id = :recurrence_id
+            and t.timespan_id = e.timespan_id
+            and i.interval_id = t.interval_id
+            and (:edit_past_events_p = 't'
+                 or i.start_date >= :start_date)
+            )
+    </querytext>
+</fullquery>
+
+<fullquery name="calendar::item::edit_recurrence.recurrence_items_update">
+    <querytext>
+            update cal_items
+            set    [join $colspecs ", "]
+            where  cal_item_id in (select e.event_id
+            from acs_events e, timespans t, time_intervals i
+            where e.recurrence_id = :recurrence_id
+            and t.timespan_id = e.timespan_id
+            and i.interval_id = t.interval_id
+            and (:edit_past_events_p = 't'
+                 or i.start_date >= :start_date)
+            )
+    </querytext>
+</fullquery>
+
+<fullquery name="calendar::item::edit_recurrence.update_context_id">
+    <querytext>
+        update acs_objects
+        set    context_id = :calendar_id
+        where  object_id in
+            (select e.event_id
+            from acs_events e, timespans t, time_intervals i
+            where e.recurrence_id = :recurrence_id
+            and t.timespan_id = e.timespan_id
+            and i.interval_id = t.interval_id
+            and (:edit_past_events_p = 't'
+                 or i.start_date >= :start_date)
+            )
+    </querytext>
+</fullquery>
+
 <fullquery name="calendar::item::add_recurrence.update_event">
 <querytext>
 update acs_events