one of the documented procedures in this installation of the ACS
edu_calendar_for_portal   db   { date "" }
What it does:
outputs a calendar for the portal
Defined in: /web/philip/tcl/education-calendar-widget.tcl

Source code:

    set class_prep_function {
	set user_id [ad_verify_and_get_user_id]
	# get class related events
	set selection [ns_db select $db "
	select to_char(due_date, 'J') as due_date, 
        task_type, task_name, task_id, min(subject_number) as subject_number
	from edu_student_tasks t, edu_classes c, users, user_group_map m,
             edu_subject_department_map map
	where t.class_id=c.class_id
	and users.user_id=m.user_id
        and c.subject_id = map.subject_id(+)
	and m.user_id=$user_id
	and m.group_id=c.class_id
	and due_date between to_date($first_julian_date, 'J') 
        and to_date($last_julian_date, 'J')
	and t.active_p='t'
	group by due_date, task_type, task_name, task_id
	array set event_for_days {}
	while {[ns_db getrow $db $selection]} {
	    if {![info exists event_for_days($due_date)] || $event_for_days($due_date)==""} {
		set event_for_days($due_date) "<font size=-2>"

	    append event_for_days($due_date) "<li><a href=[edu_url]class/task-info?task_id=$task_id>$subject_number $task_name"

	    if {$task_type!="exam"} {
		append event_for_days($due_date) " due"

	    append event_for_days($due_date) "</a>"

	# now get handouts/lecture notes
	set selection [ns_db select $db "
	select to_char(distribution_date, 'J') as distribution_date, handout_name, handout_id, min(subject_number) as subject_number 
	from edu_handouts h, user_group_map m, edu_classes,
             edu_subject_department_map map
	where m.user_id=$user_id 
	and h.class_id=m.group_id
        and h.class_id = edu_classes.class_id
        and edu_classes.subject_id = map.subject_id(+)
	and distribution_date between to_date($first_julian_date, 'J') 
        and to_date($last_julian_date, 'J') 
        group by distribution_date, handout_name, handout_id
	while {[ns_db getrow $db $selection]} {
	    if {![info exists event_for_days($distribution_date)] || $event_for_days($distribution_date)==""} {
		set event_for_days($distribution_date) "<font size=-2>"

	    append event_for_days($distribution_date) "<li><a href=[edu_url]class/admin/handouts/one?handout_id=$handout_id>$subject_number $handout_name</a>"

	# now get news events (both class and personal - in the future: departmental)
	set selection [ns_db select $db "
	select unique calendar_id, to_char(start_date, 'J') as start_date, 
               title, c.category_id, cc_group.scope as group_scope, 
               cc_user.scope as user_scope, cc_group.group_id, 
               cc_user.user_id as cc_user_id, cc_group.group_id as cc_group_id
	from (select cc.category_id, cc.user_id, cc.group_id, cc.scope
              from calendar_categories cc, user_group_map m
	      where m.group_id=cc.group_id
	      and m.user_id=$user_id) cc_group, 
	     (select cc.category_id, cc.user_id, cc.group_id, cc.scope
              from calendar_categories cc
	      where $user_id=cc.user_id) cc_user,
	     calendar c, user_group_map m
	where c.category_id=cc_user.category_id(+) 
	and c.category_id=cc_group.category_id(+)
	and start_date between to_date($first_julian_date, 'J') 
        and to_date($last_julian_date, 'J') 

	while {[ns_db getrow $db $selection]} {
	    if {![info exists event_for_days($start_date)] || $event_for_days($start_date)==""} {
		set event_for_days($start_date) "<font size=-2>"

	    if {$group_scope==""} {
		set scope user
	    } else {
		set scope group

	    # do not dispaly the event if it is a personal event and the
	    # event does not belong to the logged in user
	    if {!([empty_string_p $cc_user_id] && [empty_string_p $cc_group_id])} {
	    append event_for_days($start_date) "<li><a href=/calendar/item?calendar_id=$calendar_id&scope=$scope[ec_decode $scope "group" "&group_id=$group_id" ""]>$title</a>"
	set variables_to_pass [list]
    set day_number_template {
	if {$before_month_p || $after_month_p} {
	    set bg_color "#cccccc"
	} elseif {($day_of_week == 1) || ($day_of_week == 7)} {
	    set bg_color "#efefef"
	} else {
	    set bg_color "#efefef"

	if {$day_number<10} {
	    set day_number_part "0$day_number"
	} else {
	    set day_number_part "$day_number"

	if {$before_month_p} {
	    set month_token [split $prev_month "-"]
	    set prev_month_number [lindex $month_token 1]
	    set date_parts "$year-$prev_month_number-$day_number_part"
	} elseif {$after_month_p} {
	    set month_token [split $next_month "-"]
	    set next_month_number [lindex $month_token 1]
	    set date_parts "$year-$next_month_number-$day_number_part"
	} else {
	    set date_parts "$year-$month_number-$day_number_part"

	set square "<TD VALIGN=TOP WIDTH=14% BGCOLOR=$bg_color>"

	append square "
	<TR><TD ALIGN=RIGHT><FONT SIZE=-1 FACE=Arial>$day_number</FONT></TD></TR>
	if [info exists event_for_days($julian_date)] {
	    set event_for_today $event_for_days($julian_date) 
	    set linktext "$event_for_today"
	} else {
	    set linktext ""
	#append square "<TD ALIGN=RIGHT VALIGN=BOTTOM HEIGHT=30></TD></TR>\n"
	set hours_link "$linktext"
	append square "<TR>
	if ![empty_string_p $linktext] {
	    append square "<FONT SIZE=-1 FACE=Arial>$hours_link</FONT>"
	append square "</TD>
    return [edu_calendar_basic_month $db $day_number_template $class_prep_function $date]