Fisheye: Tag 1.4 refers to a dead (removed) revision in file `openacs-4/packages/calendar/tcl/calendar-2-procs-oracle.xql'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 1.4 refers to a dead (removed) revision in file `openacs-4/packages/calendar/tcl/calendar-2-procs-postgresql.xql'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 1.15 refers to a dead (removed) revision in file `openacs-4/packages/calendar/tcl/calendar-2-procs.tcl'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 1.8 refers to a dead (removed) revision in file `openacs-4/packages/calendar/tcl/calendar-2-procs.xql'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 1.3 refers to a dead (removed) revision in file `openacs-4/packages/calendar/tcl/calendar-procs-oracle.xql'. Fisheye: No comparison available. Pass `N' to diff? Index: openacs-4/packages/calendar/tcl/calendar-procs-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/calendar/tcl/calendar-procs-postgresql.xql,v diff -u -r1.5 -r1.6 --- openacs-4/packages/calendar/tcl/calendar-procs-postgresql.xql 30 Nov 2002 17:27:51 -0000 1.5 +++ openacs-4/packages/calendar/tcl/calendar-procs-postgresql.xql 9 Jan 2004 20:36:13 -0000 1.6 @@ -68,4 +68,28 @@ + + + select calendar_name, + calendar_id, + acs_permission__permission_p(calendar_id, :user_id, 'calendar_admin') as calendar_admin_p + from calendars + where (private_p = 'f' and package_id = :package_id $permissions_clause) or + (private_p = 't' and owner_id = :user_id) + order by private_p asc, upper(calendar_name) + + + + + + and acs_permission__permission_p(calendar_id, :user_id, :privilege) = 't' + + + + + + select calendar__delete(:calendar_id) + + + Index: openacs-4/packages/calendar/tcl/calendar-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/calendar/tcl/calendar-procs.tcl,v diff -u -r1.17 -r1.18 --- openacs-4/packages/calendar/tcl/calendar-procs.tcl 3 Sep 2003 13:48:31 -0000 1.17 +++ openacs-4/packages/calendar/tcl/calendar-procs.tcl 9 Jan 2004 20:36:13 -0000 1.18 @@ -4,7 +4,9 @@ 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 Dec 14, 2000 @cvs-id $Id$ @@ -78,31 +80,6 @@ #------------------------------------------------ -# datetime info extraction - -ad_proc calendar_make_date { event_date } { - given a date, construct the proper date string - to be imported into oracle (yyyy-mm-dd format) -} { - - # extract from even-date - set year [lindex $event_date 5] - set day [lindex $event_date 7] - set month [lindex $event_date 9] - - if {$month < 10} { - set month "0$month" - } - - if {$day < 10} { - set day "0$day" - } - return "$year-$month-$day" - -} - - -#------------------------------------------------ # figure out if user have a private calendar or not # again, best suited to be rolled into the pl/sql @@ -233,50 +210,6 @@ #------------------------------------------------ -# add a new private calendar to a user - -ad_proc calendar_create_private { private_id } { - - create a private calendar - -} { - # set the private calendar name - set calendar_name "private calendar for [db_string get_user_name { - select acs_object.name(:private_id) - from dual - } -default ""]" - - set calendar_id [calendar_create $private_id "t" $calendar_name] - - return $calendar_id -} - - -#------------------------------------------------ -# update a calendar - -ad_proc calendar_update { calendar_id - party_id - calendar_name - cal_privilege -} { - update the basic info of a calendar - does not pretain to the audience of - the calendar -} { - - #update the calendar table - db_dml update_calendar { - update calendars - set calendar_name = :calendar_name - where calendar_id = :calendar_id - } - - #reassign the permission - calendar_assign_permissions $calendar_id $party_id $cal_privilege -} - -#------------------------------------------------ # find out the name of a calendar # NOTE: calendar.name() @@ -313,15 +246,290 @@ } -ad_proc dt_valid_date_p { - date + +namespace eval calendar {} + +ad_proc -public calendar::get_month_multirow_information { + {-current_day:required} + {-today_julian_date:required} + {-first_julian_date_of_month:required} } { - Returns 1 if "date" is a valid date specification, 0 otherwise. + @author Dirk Gomez (openacs@dirkgomez.de) + @creation-date 20-July-2003 } { - if [catch { clock scan $date }] { - return 0 + set first_day_of_week [lc_get firstdayofweek] + set last_day_of_week [expr [expr $first_day_of_week + 6] % 7] + + if {$current_day == $today_julian_date} { + set today_p t } else { + set today_p f + } + set day_number [expr $current_day - $first_julian_date_of_month +1] + set weekday [expr [expr $current_day % 7] +1] + + set beginning_of_week_p f + set end_of_week_p f + if {$weekday == $last_day_of_week} { + set end_of_week_p t + } elseif {$weekday == $first_day_of_week} { + set beginning_of_week_p t + } + return [list day_number $day_number \ + today_p $today_p \ + beginning_of_week_p $beginning_of_week_p \ + end_of_week_p $end_of_week_p] +} + +ad_proc -public calendar::from_sql_datetime { + {-sql_date:required} + {-format:required} +} { + +} { + # for now, we recognize only "YYYY-MM-DD" "HH12:MIam" and "HH24:MI". + set date [template::util::date::create] + + switch -exact -- $format { + {YYYY-MM-DD} { + regexp {([0-9]*)-([0-9]*)-([0-9]*)} $sql_date all year month day + + set date [template::util::date::set_property format $date {DD MONTH YYYY}] + set date [template::util::date::set_property year $date $year] + set date [template::util::date::set_property month $date $month] + set date [template::util::date::set_property day $date $day] + } + + {HH12:MIam} { + regexp {([0-9]*):([0-9]*) *([aApP][mM])} $sql_date all hours minutes ampm + + set date [template::util::date::set_property format $date {HH12:MI am}] + set date [template::util::date::set_property hours $date $hours] + set date [template::util::date::set_property minutes $date $minutes] + set date [template::util::date::set_property ampm $date [string tolower $ampm]] + } + + {HH24:MI} { + regexp {([0-9]*):([0-9]*)} $sql_date all hours minutes + + set date [template::util::date::set_property format $date {HH24:MI}] + set date [template::util::date::set_property hours $date $hours] + set date [template::util::date::set_property minutes $date $minutes] + } + + {HH24} { + set date [template::util::date::set_property format $date {HH24:MI}] + set date [template::util::date::set_property hours $date $sql_date] + set date [template::util::date::set_property minutes $date 0] + } + default { + set date [template::util::date::set_property ansi $date $sql_date] + } + } + + return $date +} + +ad_proc -public calendar::to_sql_datetime { + {-date:required} + {-time:required} + {-time_p 1} +} { + This takes two date chunks, one for date one for time, + and combines them correctly. + + The issue here is the incoming format. + date: ANSI SQL YYYY-MM-DD + time: we return HH24. +} { + # Set the time to 0 if necessary + if {!$time_p} { + set hours 0 + set minutes 0 + } else { + set hours [template::util::date::get_property hours $time] + set minutes [template::util::date::get_property minutes $time] + } + + set year [template::util::date::get_property year $date] + set month [template::util::date::get_property month $date] + set day [template::util::date::get_property day $date] + + # put together the timestamp + return "$year-$month-$day $hours:$minutes" +} + +ad_proc -public calendar::calendar_list { + {-package_id ""} + {-user_id ""} + {-privilege ""} +} { + # If no user_id + if {[empty_string_p $user_id]} { + set user_id [ad_conn user_id] + } + + if {[empty_string_p $package_id]} { + set package_id [ad_conn package_id] + } + + set permissions_clause {} + if { ![empty_string_p $privilege] } { + set permissions_clause [db_map permissions_clause] + } + + set new_list [db_list_of_lists select_calendar_list {}] +} + +ad_proc -public calendar::adjust_date { + {-date ""} + {-julian_date ""} +} { + if {[empty_string_p $date]} { + if {![empty_string_p $julian_date]} { + set date [dt_julian_to_ansi $julian_date] + } else { + set date [dt_sysdate] + } + } + + return $date +} + +ad_proc -public calendar::new { + {-owner_id:required} + {-private_p "f"} + {-calendar_name:required} + {-package_id ""} +} { + if { [empty_string_p $package_id] } { + set package_id [ad_conn package_id] + } + set extra_vars [ns_set create] + set context_id $package_id + oacs_util::vars_to_ns_set -ns_set $extra_vars -var_list {owner_id private_p calendar_name package_id context_id} + + set calendar_id [package_instantiate_object -extra_vars $extra_vars calendar] + + return $calendar_id +} + +ad_proc -public calendar::personal_p { + {-calendar_id:required} + {-user_id ""} +} { + Returns true (1) if this is the user's personal calendar, false (0) otherwise. + + @param user_id The user whose calendar you want to check +} { + if { [empty_string_p $user_id] } { + set user_id [ad_conn user_id] + } + calendar::get -calendar_id $calendar_id -array calendar + if { [template::util::is_true $calendar(private_p)] && $calendar(owner_id) == $user_id } { return 1 + } else { + return 0 + } +} + +ad_proc -public calendar::update { + {-calendar_id:required} + {-calendar_name:required} +} { + Edit calendar +} { + + # Update the calendar table + db_dml update_calendar { + update calendars + set calendar_name = :calendar_name + where calendar_id = :calendar_id } } +ad_proc -public calendar::get { + {-calendar_id:required} + {-array:required} +} { + Get calendar info +} { + upvar 1 $array row + db_1row select_calendar {} -column_array row +} + + +ad_proc -public calendar::delete { + {-calendar_id:required} +} { + Delete a calendar +} { + db_exec_plsql delete_calendar {} +} + +ad_proc -public calendar::get_item_types { + {-calendar_id:required} +} { + return the item types +} { + return [concat [list [list {--} {}]] \ + [db_list_of_lists select_item_types {}]] +} + +ad_proc -public calendar::item_type_new { + {-calendar_id:required} + {-item_type_id ""} + {-type:required} +} { + creates a new item type +} { + if {[empty_string_p $item_type_id]} { + set item_type_id [db_nextval cal_item_type_seq] + } + + db_dml insert_item_type {} + + return $item_type_id +} + +ad_proc -public calendar::item_type_delete { + {-calendar_id:required} + {-item_type_id:required} +} { + db_transaction { + # Remove the mappings for all events + db_dml reset_item_types {} + + # Remove the item type + db_dml delete_item_type {} + } +} + +ad_proc -public calendar::attachments_enabled_p {} { + set package_id [site_node_apm_integration::child_package_exists_p \ + -package_key attachments + ] +} + +ad_proc -public calendar::rename { + {-calendar_id:required} + {-name:required} +} { + rename a calendar +} { + db_dml rename_calendar {} +} + +ad_proc -private calendar::compare_day_items_by_current_hour {a b} { + Compare a day item by the current hour (field 0) +} { + set a_criterium [lindex $a 0] + set b_criterium [lindex $b 0] + if {$a_criterium > $b_criterium} { + return 1 + } elseif {$a_criterium < $b_criterium} { + return -1 + } + return 0 +} + Index: openacs-4/packages/calendar/tcl/calendar-procs.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/calendar/tcl/calendar-procs.xql,v diff -u -r1.3 -r1.4 --- openacs-4/packages/calendar/tcl/calendar-procs.xql 17 May 2003 10:20:50 -0000 1.3 +++ openacs-4/packages/calendar/tcl/calendar-procs.xql 9 Jan 2004 20:36:13 -0000 1.4 @@ -38,4 +38,56 @@ + + +select type, item_type_id from cal_item_types +where calendar_id= :calendar_id + + + + + +insert into cal_item_types +(item_type_id, calendar_id, type) +values +(:item_type_id, :calendar_id, :type) + + + + + +update cal_items +set item_type_id= NULL +where item_type_id = :item_type_id +and on_which_calendar= :calendar_id + + + + + +delete from cal_item_types where item_type_id= :item_type_id +and calendar_id= :calendar_id + + + + + + update calendars + set calendar_name = :name + where calendar_id = :calendar_id + + + + + + select calendar_id, + calendar_name, + private_p, + owner_id, + package_id + from calendars + where calendar_id = :calendar_id + + +