im_force_user_to_log_hours

one of the documented procedures in this installation of the ACS
Usage:
im_force_user_to_log_hours   conn   args   why
What it does:
If a user is not on vacation and has not logged hours since yesterday midnight, we ask them to log hours before using the intranet. Sets state in session so user is only asked once per session.
Defined in: /web/philip/tcl/intranet-defs.tcl

Source code:


    if { ![im_enabled_p] || ![ad_parameter TrackHours intranet 0] } {
	# intranet or hours-logging not turned on. Do nothing
	return filter_ok
    } 
    
    set last_prompted_time [ad_get_client_property intranet user_asked_to_log_hours_p]

    if { ![empty_string_p $last_prompted_time] &&  $last_prompted_time > [expr [ns_time] - 60*60*24] } {
	# We have already asked the user in this session, within the last 24 hours, 
	# to log their hours
	return filter_ok
    }
    # Let's see if the user has logged hours since 
    # yesterday midnight. 
    # 

    set user_id [ad_get_user_id]
    if { $user_id == 0 } {
	# This can't happen on standard acs installs since intranet is protected
	# But we check any way to prevent bugs on other installations
	return filter_ok
    }

    set db [ns_db gethandle]
    set selection [ns_db 1row $db  "select decode(count(1),0,0,1) as logged_hours_p, 
                    to_char(sysdate - 1,'J') as julian_date
	       from im_hours h, users u
	      where h.user_id = '$user_id'
	        and h.user_id = u.user_id
	        and h.hours > 0
	        and h.day <= sysdate
	        and (u.on_vacation_until >= sysdate
    	             or h.day >= trunc(u.second_to_last_visit-1))"]
    set_variables_after_query
    ns_db releasehandle $db

    # Let's make a note that the user has been prompted 
    # to update hours or is okay. This saves us the database 
    # hit next time. 
    ad_set_client_property -persistent f intranet user_asked_to_log_hours_p [ns_time]

    if { $logged_hours_p } {
	# The user has either logged their hours or
	# is on vacation right now
	return filter_ok
    }

    # Pull up the screen to log hours for yesterday
    set return_url [im_url_with_query]
    ad_returnredirect "[im_url_stub]/hours/ae?[export_url_vars return_url julian_date]"
    return filter_return


philg@mit.edu