Index: openacs-4/packages/calendar-portlet/tcl/calendar-portlet-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/calendar-portlet/tcl/calendar-portlet-procs.tcl,v diff -u -r1.17 -r1.18 --- openacs-4/packages/calendar-portlet/tcl/calendar-portlet-procs.tcl 10 Dec 2001 02:48:38 -0000 1.17 +++ openacs-4/packages/calendar-portlet/tcl/calendar-portlet-procs.tcl 17 Jan 2002 22:14:27 -0000 1.18 @@ -15,14 +15,21 @@ namespace eval calendar_portlet { + ad_proc -private my_package_key { + } { + return "calendar-portlet" + } + ad_proc -private my_name { } { - return "calendar_portlet" + return "calendar_portlet" } ad_proc -public get_pretty_name { } { - return "Calendar" + return [ad_parameter \ + -package_id [apm_package_id_from_key [my_package_key]] \ + "pretty_name"] } ad_proc -public link { @@ -31,355 +38,113 @@ } ad_proc -public add_self_to_page { - page_id + portal_id calendar_id } { Adds a calendar PE to the given page with the community_id. @return element_id The new element's id - @param page_id The page to add self to - @param community_id The community with the folder + @param portal_id The page to add self to + @param calendar_id The new calendar_id to add @author arjun@openforce.net @creation-date Sept 2001 } { - # Find out if this calendar already exists - set element_id_list [portal::get_element_ids_by_ds $page_id [my_name]] - - if {[llength $element_id_list] == 0} { - set element_id [portal::add_element $page_id [my_name]] - - # Set the single calendar_id as a param - portal::set_element_param $element_id "calendar_id" $calendar_id - } else { - set element_id [lindex $element_id_list 0] - # There are existing calendar_id's which should NOT be overwritten - portal::add_element_param_value \ - -element_id $element_id -key calendar_id -value $calendar_id - } - - return $element_id + return [portal::add_element_or_append_id -portal_id $portal_id \ + -portlet_name [my_name] \ + -value_id $calendar_id \ + -key calendar_id] } - ad_proc -public show { - cf + ad_proc -public remove_self_from_page { + portal_id + community_id } { - Display the PE + Removes a calendar PE from the given page - @return HTML string - @param cf A config array - @author arjun@openforce.net - @creation-date Sept 2001 + @param portal_id The page to remove self from + @param community_id + @author arjun@openforce.net + @creation-date Sept 2001 } { + # it's more simple not to use portal::remove_element_or_remove_id here - # carries "calendar_id" - array set config $cf - set calendar_id $config(calendar_id) + # get the element IDs (could be more than one!) + set element_ids [portal::get_element_ids_by_ds $portal_id \ + [my_name]] - set date [dt_sysdate] - set current_date $date - set date_format "YYYY-MM-DD HH24:MI" - set num_hour_rows 24 - set i 0 - set bgcolor_html "border=1 color=blue" - set view day + # remove all elements + db_transaction { + foreach element_id $element_ids { - set mlist "" - set set_id [ns_set new day_items] - - # otherwise, get the calendar_name for the give_id - set view $config(default_view) - - set list_of_calendar_ids $config(calendar_id) - - if { $view == "day" } { - - foreach calendar_id $list_of_calendar_ids { - - set calendar_name "" - # [calendar_get_name $calendar_id] - - ns_log notice "aks11: the current calendar_id os $calendar_id, $calendar_name list is $list_of_calendar_ids, cf $cf" + set calendar_id \ + [portal::get_element_param $element_id "calendar_id"] - # big non-ported query, i'm bad - db_foreach get_day_items " - select to_char(start_date, 'HH24') as start_hour, - to_char(start_date, 'HH24:MI') as pretty_start_date, - to_char(end_date, 'HH24:MI') as pretty_end_date, - nvl(e.name, a.name) as name, - e.event_id as item_id - from acs_activities a, - acs_events e, - 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 start_date between - to_date(:current_date,:date_format) and - to_date(:current_date,:date_format) + (24 - 1/3600)/24 - and e.event_id - in ( - select cal_item_id - from cal_items - where on_which_calendar = :calendar_id - )" { - ns_set put $set_id $start_hour \ - " - $pretty_start_date - $pretty_end_date $name ($calendar_name) -
" - } + set g_cal_id \ + [portal::get_element_param $element_id "group_calendar_id"] - } - - # shaded_p support version 1 - - set row_html " - $calendar_name -

-
- - - - \n" - - while {$i < $num_hour_rows} { - set filled_cell_count 0 - - # making hours before 10 looks prettier - if {$i < 10} { set cal_hour "0$i" } else { set cal_hour "$i" } - - # am or pm determination logic - if {$i < 12} { - if {$i == 0} { - set time "12:00 am" - } else { - set time "$cal_hour:00 am" - } - } else { - if {$i == 12} { - set time "12:00 pm" - } else { - set fm_hour [expr $i - 12] - if {$fm_hour < 10} { - set fm_hour "0$fm_hour" - } - set time "$fm_hour:00 pm" - } - } - - set cal_item_index [ns_set find $set_id $cal_hour] - - append row_html " - - - - \n" - - incr i - } - - append row_html "
TimeTitle
- $time - " - - if {$cal_item_index == -1} { - append row_html " " - } - - while {$cal_item_index > -1} { - append row_html "[ns_set value $set_id $cal_item_index]" - ns_set delete $set_id $cal_item_index - set cal_item_index [ns_set find $set_id $cal_hour] - } - - append row_html "
" - - # aks - week support - } elseif { $view == "week" } { - - db_1row get_weekday_info " - select to_char(to_date(:current_date, 'yyyy-mm-dd'), 'D') - as day_of_the_week, - to_char(next_day(to_date(:current_date, 'yyyy-mm-dd')-7, 'SUNDAY')) - as sunday_of_the_week, - to_char(next_day(to_date(:current_date, 'yyyy-mm-dd'), 'Saturday')) - as saturday_of_the_week - from dual - " - - set mlist "" - set set_id [ns_set new week_items] - - db_foreach get_day_items { - select to_char(start_date, 'J') as start_date, - to_char(start_date, 'HH24:MI') as pretty_start_date, - to_char(end_date, 'HH24:MI') as pretty_end_date, - nvl(e.name, a.name) as name, - e.event_id as item_id - from acs_activities a, - acs_events e, - 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 start_date between - to_date(:sunday_of_the_week,'YYYY-MM-DD') and - to_date(:saturday_of_the_week,'YYYY-MM-DD') - and e.event_id - in ( - select cal_item_id - from cal_items - where on_which_calendar = :calendar_id - ) - } { - ns_set put $set_id $start_date \ - "

  • - $pretty_start_date - $pretty_end_date $name ($calendar_name) - " - append items "
  • - $pretty_start_date - $pretty_end_date $name ($calendar_name) -
    " - } - - set num_hour_rows 7 - set i 0 - - set bgcolor_html "bgcolor=DCDCDC" - - set row_html " - " - - while {$i < $num_hour_rows} { - - set sql " - select - to_char(next_day(to_date(:current_date, 'yyyy-mm-dd')-7, - 'SUNDAY')+$i, 'DAY') - as weekday, - to_char(next_day(to_date(:current_date, - 'yyyy-mm-dd')-7, 'SUNDAY')+$i, 'YYYY-MM-DD') - as pretty_date, - to_char(next_day(to_date(:current_date, 'yyyy-mm-dd')-7, - 'SUNDAY')+$i, 'J') - as start_date - from dual - " - db_1row week_data $sql - append row_html " - - - - - - - - " - - incr i + # get rid of this portal element + portal::remove_element $element_id } + } - append row_html "
    $weekday - $pretty_date -
    " + # don't delete the public calendar! + if {[calendar_public_p $calendar_id] == "f"} { - set cal_item_index [ns_set find $set_id $start_date] + ns_log notice "aks15 in calendar_portlet remove_self_from_page $calendar_id/$element_id/$g_cal_id" - if {$cal_item_index == -1} { append row_html " " } - - while {$cal_item_index > -1} { - - append row_html [ns_set value $set_id $cal_item_index] - - ns_set delete $set_id $cal_item_index - set cal_item_index [ns_set find $set_id $start_date] + # delete the personal calendar associated with this element + db_exec_plsql delete_calendar { + begin + calendar.delete( + calendar_id => :calendar_id + ); + end; + } } - - append row_html " -
    " - } elseif { $view == "month" } { - - set set_id [ns_set new month_items] - - db_foreach get_monthly_items " - select to_char(start_date, 'j') as start_date, - nvl(e.name, a.name) as name, - nvl(e.description, a.description) as description, - e.event_id as item_id - from acs_activities a, - acs_events e, - 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 - in ( - select cal_item_id - from cal_items - where on_which_calendar = :calendar_id - ) " { - ns_set put $set_id $start_date \ - " - $name ($calendar_name) -
    " - } + } - set row_html \ - [dt_widget_month -header_text_size "+0" \ - -calendar_details $set_id -date $date] - - } elseif { $view == "list"} { - set items "" + ad_proc -public make_self_available { + page_id + } { + Wrapper for the portal:: proc + + @param page_id + @author arjun@openforce.net + @creation-date Nov 2001 + } { + portal::make_datasource_available \ + $page_id [portal::get_datasource_id [my_name]] + } - db_foreach get_day_items " - select to_char(start_date, 'j') as start_date, - to_char(start_date, 'HH24:MI') as pretty_start_date, - to_char(end_date, 'HH24:MI') as pretty_end_date, - nvl(e.name, a.name) as name, - e.event_id as item_id - from acs_activities a, - acs_events e, - 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 start_date between - to_date(:current_date,:date_format) and - to_date(:current_date,:date_format) + (24 - 1/3600)/24 - and e.event_id - in ( - select cal_item_id - from cal_items - where on_which_calendar = :calendar_id - )" { - ns_set put $set_id $start_date \ - " - $pretty_start_date - $pretty_end_date $name ($calendar_name) -
    " - append items "
  • - $pretty_start_date - $pretty_end_date $name ($calendar_name) -
    " - } - - set date [dt_systime] - - set row_html "For $date: $items" - } + ad_proc -public make_self_unavailable { + page_id + } { + Wrapper for the portal:: proc - if { $config(shaded_p) == "t" } { - # shaded_p - set row_html "" - } - - set template "$row_html" + @param page_id + @author arjun@openforce.net + @creation-date Nov 2001 + } { + portal::make_datasource_unavailable \ + $page_id [portal::get_datasource_id [my_name]] + } - set code [template::adp_compile -string $template] - - set output [template::adp_eval code] - return $output + + ad_proc -public show { + cf + } { + Display the PE + + @return HTML string + @param cf A config array + @author arjun@openforce.net + @creation-date Sept 2001 + } { + # no return call required with the helper proc + portal::show_proc_helper \ + -package_key [my_package_key] \ + -config_list $cf } ad_proc -public edit { @@ -443,70 +208,6 @@ } } + - ad_proc -public remove_self_from_page { - portal_id - community_id - } { - Removes a calendar PE from the given page - - @param page_id The page to remove self from - @param community_id - @author arjun@openforce.net - @creation-date Sept 2001 - } { - - # get the element IDs (could be more than one!) - set element_ids [portal::get_element_ids_by_ds $portal_id \ - [my_name]] - - # remove all elements - db_transaction { - foreach element_id $element_ids { - - set calendar_id \ - [portal::get_element_param $element_id "calendar_id"] - - # don't delete the public calendar! - if {[calendar_public_p $calendar_id] == "f"} { - # delete the personal calendar associated with this element - db_exec_plsql delete_calendar { - begin - calendar.delete( - calendar_id => :calendar_id - ); - end; - } - } - # get rid of this portal element - portal::remove_element $element_id - } - } - } - - ad_proc -public make_self_available { - page_id - } { - Wrapper for the portal:: proc - - @param page_id - @author arjun@openforce.net - @creation-date Nov 2001 - } { - portal::make_datasource_available \ - $page_id [portal::get_datasource_id [my_name]] - } - - ad_proc -public make_self_unavailable { - page_id - } { - Wrapper for the portal:: proc - - @param page_id - @author arjun@openforce.net - @creation-date Nov 2001 - } { - portal::make_datasource_unavailable \ - $page_id [portal::get_datasource_id [my_name]] - } }