im_hours_for_user

one of the documented procedures in this installation of the ACS
Usage:
im_hours_for_user   db   user_id   { html_p "t" }   { number_days "7" }
What it does:
Returns a string in html or text format describing the number of hours the specified user logged and what s/he noted as work done in those hours.
Defined in: /web/philip/tcl/intranet-defs.tcl

Source code:


    validate_integer "user id" $user_id

    set selection [ns_db select $db  "select g.group_id, g.group_name, nvl(h.note,'no notes') as note, 
		    to_char( day, 'Dy, MM/DD/YYYY' ) as nice_day, h.hours
               from im_hours h, user_groups g
	      where g.group_id = h.on_what_id
     	        and h.on_which_table = 'im_projects'
                and h.day >= sysdate - $number_days
                and user_id=$user_id
              order by lower(g.group_name), day"]
    
    set last_id -1
    set pcount 0
    set num_hours 0
    set html_string ""
    set text_string ""

    while {[ns_db getrow $db $selection]} {
	set_variables_after_query
	if { $last_id != $group_id } {
	    set last_id $group_id
	    if { $pcount > 0 } {
		append html_string "</ul>\n"
		append text_string "\n"
	    }
	    append html_string " <li><b>$group_name</b>\n<ul>\n"
	    append text_string "$group_name\n"
	    set pcount 1
	}
	append html_string "   <li>$nice_day ($hours [util_decode $hours 1 "hour" "hours"]): &nbsp; <i>$note</i>\n"
	append text_string "  * $nice_day ($hours [util_decode $hours 1 "hour" "hours"]): $note\n"
	set num_hours [expr $num_hours + $hours]
    }

    # Let's get the punctuation right on days
    set number_days_string "$number_days [util_decode $number_days 1 "day" "days"]"

    if { $num_hours == 0 } {
	set text_string "No hours logged in the last $number_days_string."
	set html_string "<b>$text_string</b>"
    } else {
	if { $pcount > 0 } {
	    append html_string "</ul>\n"
	    append text_string "\n"
	}
        set html_string "<b>$num_hours [util_decode $num_hours 1 hour hours] logged in the last $number_days_string:</b>
<ul>$html_string</ul>"
        set text_string "$num_hours [util_decode $num_hours 1 hour hours] logged in the last $number_days_string:
$text_string"
    }
        
    return [util_decode $html_p "t" $html_string $text_string]


philg@mit.edu