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 -N --- openacs-4/packages/calendar/tcl/cal-item-2-procs-oracle.xql 11 Dec 2003 21:39:59 -0000 1.10 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,105 +0,0 @@ - - - - oracle8.1.6 - - - - - select CASE WHEN (to_date(:start_date,:date_format) - to_date(:end_date,:date_format)) <= 0 - THEN 1 - ELSE -1 - END - from dual - - - - - - - - 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 - 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 - - - - - - - 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 - 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 - - - - - -begin - :1 := recurrence.new(interval_type => :interval_type, - every_nth_interval => :every_n, - days_of_week => :days_of_week, - recur_until => :recur_until); -end; - - - - - -begin - acs_event.insert_instances(event_id => :cal_item_id); -end; - - - - 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 -N --- openacs-4/packages/calendar/tcl/cal-item-2-procs-postgresql.xql 11 Dec 2003 21:39:59 -0000 1.12 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,101 +0,0 @@ - - - - postgresql7.1 - - - - select CASE WHEN :start_date::timestamptz <= :end_date::timestamptz - THEN 1 - ELSE -1 - END - - - - - - 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 - 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 - - - - - - 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(a.name, e.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 - 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 - - - - - -select recurrence__new(:interval_type, - :every_n, - :days_of_week, - :recur_until, - NULL) - - - - - -select acs_event__insert_instances(:cal_item_id, NULL); - - - - 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 -N --- openacs-4/packages/calendar/tcl/cal-item-2-procs.tcl 11 Dec 2003 21:39:59 -0000 1.14 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,149 +0,0 @@ - -ad_library { - A beginning of an attempt to rewrite calendar by making - procs cleaner, etc... (ben) - - @author Ben Adida (ben@openforce.net) - @creation-date 2002-06-02 -} - -namespace eval calendar::item { - - ad_proc -private dates_valid_p { - {-start_date:required} - {-end_date:required} - } { - A sanity check that the start time is before the end time. - } { - # set the date_format for oracle - from cal_item_create - set date_format "YYYY-MM-DD HH24:MI" - - set dates_valid_p [db_string dates_valid_p_select {}] - - if {[string equal $dates_valid_p 1]} { - return 1 - } else { - return 0 - } - } - - ad_proc -public new { - {-start_date:required} - {-end_date:required} - {-name:required} - {-description:required} - {-calendar_id:required} - {-item_type_id ""} - } { - # if the dates are invalid, don't create the item - if {[dates_valid_p -start_date $start_date -end_date $end_date]} { - # For now we call the old nasty version - return [cal_item_create $start_date $end_date $name $description $calendar_id [ad_conn peeraddr] [ad_conn user_id] $item_type_id] - } else { - # FIXME: do this better - ad_return_complaint 1 [_ calendar.start_time_before_end_time] - ad_script_abort - } - - } - - ad_proc -public get { - {-cal_item_id:required} - {-array:required} - } { - Get the data for a calendar item - } { - upvar $array row - - if {[calendar::attachments_enabled_p]} { - set query_name select_item_data_with_attachment - } else { - set query_name select_item_data - } - - db_1row $query_name {} -column_array row - # Timezonize - set row(start_date_ansi) [lc_time_system_to_conn $row(start_date_ansi)] - set row(end_date_ansi) [lc_time_system_to_conn $row(end_date_ansi)] - - if { $row(start_date_ansi) == $row(end_date_ansi) && [string equal [lc_time_fmt $row(start_date_ansi) "%T"] "00:00:00"]} { - set row(time_p) 0 - } else { - set row(time_p) 1 - } - - # Localize - set row(start_time) [lc_time_fmt $row(start_date_ansi) "%X"] - - # Unfortunately, SQL has weekday starting at 1 = Sunday - set row(start_date) [lc_time_fmt $row(start_date_ansi) "%Y-%m-%d"] - set row(end_date) [lc_time_fmt $row(end_date_ansi) "%Y-%m-%d"] - - set row(day_of_week) [expr [lc_time_fmt $row(start_date_ansi) "%w"] + 1] - set row(pretty_day_of_week) [lc_time_fmt $row(start_date_ansi) "%A"] - set row(day_of_month) [lc_time_fmt $row(start_date_ansi) "%d"] - set row(pretty_short_start_date) [lc_time_fmt $row(start_date_ansi) "%x"] - set row(full_start_date) [lc_time_fmt $row(start_date_ansi) "%x"] - set row(full_end_date) [lc_time_fmt $row(end_date_ansi) "%x"] - - set row(end_time) [lc_time_fmt $row(end_date_ansi) "%X"] - } - - 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} - {-end_date:required} - {-name:required} - {-description:required} - {-item_type_id ""} - {-edit_all_p 0} - {-calendar_id ""} - } { - Edit the item - - } { - if {[dates_valid_p -start_date $start_date -end_date $end_date]} { - # For now we call the old nasty version - return [cal_item_update $cal_item_id $start_date $end_date $name $description $item_type_id $edit_all_p $calendar_id] - } else { - # FIXME: do this better - ad_return_complaint 1 "Start Time must be before End Time" - ad_script_abort - } - } - - ad_proc -public delete { - {-cal_item_id:required} - } { - delete the item - } { - cal_item_delete $cal_item_id - } - -} 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 -N --- openacs-4/packages/calendar/tcl/cal-item-2-procs.xql 22 Jul 2002 21:46:19 -0000 1.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,27 +0,0 @@ - - - - - - -update acs_events -set recurrence_id= :recurrence_id -where event_id= :cal_item_id - - - - - -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 - - - - 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 -N -r1.7 -r1.8 --- openacs-4/packages/calendar/tcl/cal-item-procs-oracle.xql 30 Sep 2003 12:10:04 -0000 1.7 +++ openacs-4/packages/calendar/tcl/cal-item-procs-oracle.xql 9 Jan 2004 22:55:52 -0000 1.8 @@ -3,7 +3,105 @@ oracle8.1.6 - + + + + 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 + + + + + + + + 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 + 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 + + + + + + + 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 + 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 + + + + + +begin + :1 := recurrence.new(interval_type => :interval_type, + every_nth_interval => :every_n, + days_of_week => :days_of_week, + recur_until => :recur_until); +end; + + + + + +begin + acs_event.insert_instances(event_id => :cal_item_id); +end; + + + begin @@ -19,67 +117,66 @@ - + begin :1 := timespan.new( - start_date => to_date(:start_date,:date_format), - end_date => to_date(:end_date,:date_format) + start_date => to_date(:start_date,'YYYY-MM-DD HH24:MI'), + end_date => to_date(:end_date,'YYYY-MM-DD HH24:MI') ); end; - + begin :1 := cal_item.new( - on_which_calendar => :on_which_calendar, + on_which_calendar => :calendar_id, activity_id => :activity_id, timespan_id => :timespan_id, item_type_id => :item_type_id, creation_user => :creation_user, creation_ip => :creation_ip, - context_id => :on_which_calendar + context_id => :calendar_id ); end; - - + begin - time_interval.edit ( - interval_id => :interval_id, - start_date => to_date(:start_date,:date_format), - end_date => to_date(:end_date,:date_format) + cal_item.del ( + cal_item_id => :cal_item_id ); end; - - + begin - cal_item.del ( - cal_item_id => :cal_item_id + time_interval.edit ( + interval_id => :interval_id, + start_date => to_date(:start_date,'YYYY-MM-DD HH24:MI'), + end_date => to_date(:end_date,'YYYY-MM-DD HH24:MI') ); end; - + + begin @@ -91,7 +188,7 @@ - + begin acs_event.recurrence_timespan_edit ( @@ -102,5 +199,4 @@ end; - 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 -N -r1.15 -r1.16 --- openacs-4/packages/calendar/tcl/cal-item-procs-postgresql.xql 13 Aug 2003 16:08:33 -0000 1.15 +++ openacs-4/packages/calendar/tcl/cal-item-procs-postgresql.xql 9 Jan 2004 22:55:52 -0000 1.16 @@ -2,9 +2,103 @@ postgresql7.1 + + + select CASE WHEN :start_date::timestamptz <= :end_date::timestamptz + THEN 1 + ELSE -1 + END + + - + + 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 + 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 + + + + + + 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(a.name, e.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 + 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 + + + + + +select recurrence__new(:interval_type, + :every_n, + :days_of_week, + :recur_until, + NULL) + + + + + +select acs_event__insert_instances(:cal_item_id, NULL); + + + + + select acs_activity__new ( null, :name, @@ -22,7 +116,7 @@ - + select timespan__new ( :start_date::timestamptz, @@ -33,11 +127,11 @@ - + select cal_item__new ( null, - :on_which_calendar, + :calendar_id, null, null, null, @@ -46,7 +140,7 @@ :activity_id, null, 'cal_item', - :on_which_calendar, + :calendar_id, now(), :creation_user, :creation_ip @@ -56,28 +150,28 @@ - + - select time_interval__edit ( - :interval_id, - :start_date::timestamptz, - :end_date::timestamptz + select cal_item__delete ( + :cal_item_id ) - - + - select cal_item__delete ( - :cal_item_id + select time_interval__edit ( + :interval_id, + :start_date::timestamptz, + :end_date::timestamptz ) - + + select cal_item__delete_all ( :recurrence_id @@ -86,7 +180,7 @@ - + select acs_event__recurrence_timespan_edit ( @@ -96,5 +190,5 @@ ) - + Index: openacs-4/packages/calendar/tcl/cal-item-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/calendar/tcl/cal-item-procs.tcl,v diff -u -N -r1.16 -r1.17 --- openacs-4/packages/calendar/tcl/cal-item-procs.tcl 11 Dec 2003 21:39:59 -0000 1.16 +++ openacs-4/packages/calendar/tcl/cal-item-procs.tcl 9 Jan 2004 22:55:52 -0000 1.17 @@ -4,251 +4,246 @@ Utility functions for Calendar Applications + @author Dirk Gomez (openacs@dirkgomez.de) @author Gary Jin (gjin@arsdigita.com) + @author Ben Adida (ben@openforce.net) @creation-date Jan 11, 2001 @cvs-id $Id$ } +namespace eval calendar {} +namespace eval calendar::item {} -#------------------------------------------------ -# update the permissions of the calendar -ad_proc cal_assign_item_permission { cal_item_id - party_id - permission - {revoke ""} +ad_proc -private calendar::item::dates_valid_p { + {-start_date:required} + {-end_date:required} } { - update the permission of the specific cal_item - if revoke is set to revoke, then we revoke all permissions + A sanity check that the start time is before the end time. } { - - # adding permission + set dates_valid_p [db_string dates_valid_p_select {}] - if { ![string equal $revoke "revoke"] } { + if {[string equal $dates_valid_p 1]} { + return 1 + } else { + return 0 + } +} - # we make the assumation that permission cal_read is - # by default granted to all users who needs write, delete - # and invite permission +ad_proc -public calendar::item::new { + {-start_date:required} + {-end_date:required} + {-name:required} + {-description:required} + {-calendar_id:required} + {-item_type_id ""} +} { + if {[dates_valid_p -start_date $start_date -end_date $end_date]} { + set creation_ip [ad_conn peeraddr] + set creation_user [ad_conn user_id] - if { ![string equal $permission "cal_item_read"] } { + set activity_id [db_exec_plsql insert_activity {} ] + + # Convert from user timezone to system timezone + set start_date [lc_time_conn_to_system $start_date] + set end_date [lc_time_conn_to_system $end_date] + + set timespan_id [db_exec_plsql insert_timespan {}] + + # create the cal_item + # we are leaving the name and description fields in acs_event + # blank to abide by the definition that an acs_event is an acs_activity + # with added on temperoal information + + # by default, the cal_item permissions + # are going to be inherited from the calendar permissions + set cal_item_id [db_exec_plsql cal_item_add {}] - # grant read permission first - permission::grant -object_id $cal_item_id -party_id $party_id -privilege cal_item_read - - } - - # grant other permission + assign_permission $cal_item_id $creation_user read + assign_permission $cal_item_id $creation_user write + assign_permission $cal_item_id $creation_user delete + assign_permission $cal_item_id $creation_user admin - permission::grant -object_id $cal_item_id -party_id $party_id -privilege $permission + return $cal_item_id - - } elseif { [string equal $revoke "revoke"] } { - - # revoke the permissions - - permission::revoke -object_id $cal_item_id -party_id $party_id -privilege $permission - + } else { + ad_return_complaint 1 [_ calendar.start_time_before_end_time] + ad_script_abort } } -#------------------------------------------------ -# adding a new calendar item -ad_proc cal_item_create { start_date - end_date - name - description - on_which_calendar - creation_ip - creation_user -{item_type_id ""} +ad_proc -public calendar::item::get { + {-cal_item_id:required} + {-array:required} } { - - create a new cal_item - for this version, i am omitting recurrence - + Get the data for a calendar item } { + upvar $array row - # find out the activity_id - set activity_id [db_exec_plsql insert_activity { - begin - :1 := acs_activity.new ( - name => :name, - description => :description, - creation_user => :creation_user, - creation_ip => :creation_ip - ); - end; + if {[calendar::attachments_enabled_p]} { + set query_name select_item_data_with_attachment + } else { + set query_name select_item_data } - ] + + db_1row $query_name {} -column_array row + # Timezonize + set row(start_date_ansi) [lc_time_system_to_conn $row(start_date_ansi)] + set row(end_date_ansi) [lc_time_system_to_conn $row(end_date_ansi)] - # set the date_format - set date_format "YYYY-MM-DD HH24:MI" - - # Convert from user timezone to system timezone - set start_date [lc_time_conn_to_system $start_date] - set end_date [lc_time_conn_to_system $end_date] - - # find out the timespan_id - set timespan_id [db_exec_plsql insert_timespan { - begin - :1 := timespan.new( - start_date => to_date(:start_date,:date_format), - end_date => to_date(:end_date,:date_format) - ); - end; + if { $row(start_date_ansi) == $row(end_date_ansi) && [string equal [lc_time_fmt $row(start_date_ansi) "%T"] "00:00:00"]} { + set row(time_p) 0 + } else { + set row(time_p) 1 } - ] - # create the cal_item - # we are leaving the name and description fields in acs_event - # blank to abide by the definition that an acs_event is an acs_activity - # with added on temperoal information + # Localize + set row(start_time) [lc_time_fmt $row(start_date_ansi) "%X"] - # by default, the cal_item permissions - # are going to be inherited from the calendar permissions + # Unfortunately, SQL has weekday starting at 1 = Sunday + set row(start_date) [lc_time_fmt $row(start_date_ansi) "%Y-%m-%d"] + set row(end_date) [lc_time_fmt $row(end_date_ansi) "%Y-%m-%d"] - set cal_item_id [db_exec_plsql cal_item_add { - begin - :1 := cal_item.new( - on_which_calendar => :on_which_calendar, - activity_id => :activity_id, - timespan_id => :timespan_id, - item_type_id => :item_type_id, - creation_user => :creation_user, - creation_ip => :creation_ip, - context_id => :on_which_calendar - ); - end; - } - ] + set row(day_of_week) [expr [lc_time_fmt $row(start_date_ansi) "%w"] + 1] + set row(pretty_day_of_week) [lc_time_fmt $row(start_date_ansi) "%A"] + set row(day_of_month) [lc_time_fmt $row(start_date_ansi) "%d"] + set row(pretty_short_start_date) [lc_time_fmt $row(start_date_ansi) "%x"] + set row(full_start_date) [lc_time_fmt $row(start_date_ansi) "%x"] + set row(full_end_date) [lc_time_fmt $row(end_date_ansi) "%x"] - cal_assign_item_permission $cal_item_id $creation_user read - cal_assign_item_permission $cal_item_id $creation_user write - cal_assign_item_permission $cal_item_id $creation_user delete - cal_assign_item_permission $cal_item_id $creation_user admin + set row(end_time) [lc_time_fmt $row(end_date_ansi) "%X"] +} - return $cal_item_id - +ad_proc -public calendar::item::add_recurrence { + {-cal_item_id:required} + {-interval_type:required} + {-every_n:required} + {-days_of_week ""} + {-recur_until ""} +} { + Adds a recurrence for a calendar item +} { + db_transaction { + set recurrence_id [db_exec_plsql create_recurrence {}] + + db_dml update_event {} + + db_exec_plsql insert_instances {} + + # Make sure they're all in the calendar! + db_dml insert_cal_items {} + } } -#------------------------------------------------ -# update an existing calendar item -ad_proc cal_item_update { - cal_item_id - start_date - end_date - name - description - {item_type_id ""} - {edit_all_p 0} - {calendar_id ""} +ad_proc -public calendar::item::edit { + {-cal_item_id:required} + {-start_date:required} + {-end_date:required} + {-name:required} + {-description:required} + {-item_type_id ""} + {-edit_all_p 0} + {-calendar_id ""} } { - Updating a cal_item + Edit the item + } { - - if {$edit_all_p} { - set recurrence_id [db_string select_recurrence_id {}] + if {[dates_valid_p -start_date $start_date -end_date $end_date]} { + if {$edit_all_p} { + set recurrence_id [db_string select_recurrence_id {}] - # If the recurrence id is NULL, then we stop here and just do the normal update - if {![empty_string_p $recurrence_id]} { - cal_item_edit_recurrence \ - -event_id $cal_item_id \ - -start_date $start_date \ - -end_date $end_date \ - -name $name \ - -description $description \ - -item_type_id $item_type_id \ - -calendar_id $calendar_id + # If the recurrence id is NULL, then we stop here and just do the normal update + if {![empty_string_p $recurrence_id]} { + calendar::item::edit_recurrence \ + -event_id $cal_item_id \ + -start_date $start_date \ + -end_date $end_date \ + -name $name \ + -description $description \ + -item_type_id $item_type_id \ + -calendar_id $calendar_id - return + return + } } - } - # set the date_format - set date_format "YYYY-MM-DD HH24:MI" + # Convert from user timezone to system timezone + set start_date [lc_time_conn_to_system $start_date] + set end_date [lc_time_conn_to_system $end_date] - # Convert from user timezone to system timezone - set start_date [lc_time_conn_to_system $start_date] - set end_date [lc_time_conn_to_system $end_date] + db_dml update_event {} - # update the events - db_dml update_event "" + # update the time interval based on the timespan id - # update the time interval based on the timespan id + db_1row get_interval_id {} - db_1row get_interval_id "" + db_transaction { + # call edit procedure + db_exec_plsql update_interval {} + + # Update the item_type_id and calendar_id + set colspecs [list] + lappend colspecs "item_type_id = :item_type_id" + if { ![empty_string_p $calendar_id] } { + lappend colspecs "on_which_calendar = :calendar_id" - db_transaction { - # call edit procedure - db_exec_plsql update_interval " - begin - time_interval.edit ( - interval_id => :interval_id, - start_date => to_date(:start_date,:date_format), - end_date => to_date(:end_date,:date_format) - ); - end; - " - - # Update the item_type_id and calendar_id - set colspecs [list] - lappend colspecs "item_type_id = :item_type_id" - if { ![empty_string_p $calendar_id] } { - lappend colspecs "on_which_calendar = :calendar_id" - - db_dml update_context_id { - update acs_objects - set context_id = :calendar_id - where object_id = :cal_item_id + db_dml update_context_id { + update acs_objects + set context_id = :calendar_id + where object_id = :cal_item_id + } } - } - - db_dml update_item_type_id " + + db_dml update_item_type_id " update cal_items set [join $colspecs ", "] where cal_item_id= :cal_item_id " - } + } + } else { + ad_return_complaint 1 "Start Time must be before End Time" + ad_script_abort + } } +ad_proc -public calendar::item::delete { + {-cal_item_id:required} +} { + Delete the calendar item +} { + db_exec_plsql delete_cal_item {} +} -#------------------------------------------------ -# delete an exiting cal_item -ad_proc cal_item_delete { cal_item_id } { - - delete an existing cal_item given a cal_item_id - +ad_proc calendar::item::assign_permission { cal_item_id + party_id + permission + {revoke ""} } { + update the permission of the specific cal_item + if revoke is set to revoke, then we revoke all permissions +} { + if { ![string equal $revoke "revoke"] } { + if { ![string equal $permission "cal_item_read"] } { + permission::grant -object_id $cal_item_id -party_id $party_id -privilege cal_item_read + } + permission::grant -object_id $cal_item_id -party_id $party_id -privilege $permission + } elseif { [string equal $revoke "revoke"] } { + permission::revoke -object_id $cal_item_id -party_id $party_id -privilege $permission - # call delete procedure - db_exec_plsql delete_cal_item " - begin - cal_item.delete ( - cal_item_id => :cal_item_id - ); - end; - " + } } - -# Recurrences -ad_proc -public cal_item_delete_recurrence { +ad_proc -public calendar::item::delete_recurrence { {-recurrence_id:required} } { - - # call delete procedure - db_exec_plsql delete_cal_item_recurrence " - begin - cal_item.delete_all ( - recurrence_id => :recurrence_id - ); - end; - " + delete a recurrence +} { + db_exec_plsql delete_cal_item_recurrence {} } -ad_proc -public cal_item_edit_recurrence { +ad_proc -public calendar::item::edit_recurrence { {-event_id:required} {-start_date:required} {-end_date:required} @@ -262,14 +257,8 @@ set recurrence_id [db_string select_recurrence_id {}] db_transaction { - # Update the recurrence start and end dates db_exec_plsql recurrence_timespan_update {} - # Update the activities table - # We shouldn't update activities, I don't think - # db_dml recurrence_activities_update {} - - # Update the events table db_dml recurrence_events_update {} set colspecs [list] @@ -299,30 +288,15 @@ } { # We do things in a transaction db_transaction { - # Create the recurrence - set recurrence_id [db_exec_plsql create_recurrence " - begin - :1 := recurrence.new(interval_type => :interval_type, - every_nth_interval => :every_n, - days_of_week => :days_of_week, - recur_until => :recur_until); - end; - "] + set recurrence_id [db_exec_plsql create_recurrence {}] - # Update the events table db_dml update_event "update acs_events set recurrence_id= :recurrence_id where event_id= :cal_item_id" - # Insert instances - db_exec_plsql insert_instances " - begin - acs_event.insert_instances(event_id => :cal_item_id); - end; - " + db_exec_plsql insert_instances {} # Make sure they're all in the calendar! db_dml insert_cal_items " 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" } } - 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 -N -r1.6 -r1.7 --- openacs-4/packages/calendar/tcl/cal-item-procs.xql 11 Dec 2003 21:39:59 -0000 1.6 +++ openacs-4/packages/calendar/tcl/cal-item-procs.xql 9 Jan 2004 22:55:52 -0000 1.7 @@ -1,24 +1,35 @@ - - - - select grantee_id, - privilege - from acs_permissions - where object_id = :on_which_calendar - - + + +update acs_events +set recurrence_id= :recurrence_id +where event_id= :cal_item_id + - + +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 + + + + + select recurrence_id from acs_events where event_id= :cal_item_id - + update acs_activities set name = :name, @@ -32,7 +43,7 @@ - + update acs_events set name = :name, @@ -41,7 +52,7 @@ - + select interval_id from timespans @@ -54,13 +65,13 @@ - + select recurrence_id from acs_events where event_id= :event_id - + update acs_activities set name = :name, @@ -74,7 +85,7 @@ - + update acs_events set name= :name, description= :description @@ -83,7 +94,7 @@ - + update cal_items set [join $colspecs ", "] Index: openacs-4/packages/calendar/www/cal-item-delete-all-occurrences.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/calendar/www/cal-item-delete-all-occurrences.tcl,v diff -u -N -r1.3 -r1.4 --- openacs-4/packages/calendar/www/cal-item-delete-all-occurrences.tcl 21 Jul 2003 19:21:36 -0000 1.3 +++ openacs-4/packages/calendar/www/cal-item-delete-all-occurrences.tcl 9 Jan 2004 22:55:52 -0000 1.4 @@ -9,6 +9,6 @@ {return_url "./"} } -cal_item_delete_recurrence -recurrence_id $recurrence_id +calendar::item::delete_recurrence -recurrence_id $recurrence_id ad_returnredirect $return_url