im_user_information

one of the documented procedures in this installation of the ACS
Usage:
im_user_information   db   user_id
What it does:
Returns an html string of all the intranet applicable information for one user. This information can be used in the shared community member page, for example, to give intranet users a better understanding of what other people are doing in the site.
Defined in: /web/philip/tcl/intranet-defs.tcl

Source code:



    set caller_id [ad_get_user_id]
    
    # is this user an employee?
    set user_employee_p [database_to_tcl_string $db  "select decode ( ad_group_member_p ( $user_id, [im_employee_group_id $db] ), 'f', 0, 1 ) from dual"]

    set return_url [im_url_with_query]

    # we need a backup copy
    set user_id_copy $user_id

    # If we're looking at our own entry, we can modify some information
    if {$caller_id == $user_id} {
	set looking_at_self_p 1
    } else {
	set looking_at_self_p 0
    }

    # can the user make administrative changes to this page
    set user_admin_p [im_is_user_site_wide_or_intranet_admin $db $caller_id]

    set selection [ns_db 0or1row $db " select u.*, uc.*, info.*,
    ((sysdate - info.first_experience)/365) as years_experience
    from users u, users_contact uc, im_employee_info info
    where u.user_id = $user_id 
    and u.user_id = uc.user_id(+)
    and u.user_id = info.user_id(+)"]

    if [empty_string_p $selection] {
	ad_return_error "Error" "User doesn't exist"
	ad_script_abort
    }
    set_variables_after_query

    # just in case user_id was set to null in the last query
    set user_id $user_id_copy

    set selection [ns_db select $db  "select ug.group_name, ug.group_id
    from user_groups ug, im_offices o
    where ad_group_member_p ( $user_id, ug.group_id ) = 't'
    and o.group_id=ug.group_id
    and ug.parent_group_id=[im_office_group_id $db]
    order by lower(ug.group_name)"]

    set offices ""
    set number_offices 0
    while { [ns_db getrow $db $selection] } {
	set_variables_after_query
	incr number_offices
	if { ![empty_string_p $offices] } {
	    append offices ", "
	}
	append offices "  <a href=[im_url_stub]/offices/view?[export_url_vars group_id]>$group_name</A>"
    }

    set page_content "<ul>\n"

    if [exists_and_not_null job_title] {
	append page_content "<LI>Job title: $job_title\n"
    }

    if { $number_offices > 0 } {
	append page_content "  <li>[util_decode $number_offices 1 Office Offices]: $offices\n"
	if { $looking_at_self_p } {
	    append page_content "(<a href=[im_url_stub]/users/office-update?[export_url_vars user_id]>manage</a>)\n"
	}
    } elseif { $user_employee_p } {
	if { $looking_at_self_p } {
	    append page_content "  <li>Office: <a href=[im_url_stub]/users/add-to-office?[export_url_vars user_id return_url]>Add yourself to an office</a>\n"
	} elseif { $user_admin_p } {
	    append page_content "  <li>Office: <a href=[im_url_stub]/users/add-to-office?[export_url_vars user_id return_url]>Add this user to an office</a>\n"
	}
    }

    if [exists_and_not_null years_experience] {
	append page_content "<LI>Job experience: [format %3.1f $years_experience] years\n"
    }

    if { $user_employee_p } {
	# Let's offer a link to the people this person manages, if s/he manages somebody
	set number_subordinates [database_to_tcl_string $db  "select decode(count(1),0,0,1) from im_employees_active where supervisor_id='$user_id'"]
	if { $number_subordinates == 0 } {
	    append page_content "  <li> <a href=[im_url_stub]/employees/org-chart>Org chart</a>: This user does not supervise any employees.\n"
	} else {
	    append page_content "  <li> <a href=[im_url_stub]/employees/org-chart>Org chart</a>: <a href=[im_url_stub]/employees/org-chart?starting_user_id=$user_id>View the org chart</a> starting with this employee\n"
	}

	set number_superiors [database_to_tcl_string $db  "select max(level)-1 
                   from im_employee_info
                  start with user_id = '$user_id'
                connect by user_id = PRIOR supervisor_id"]

	# Let's also offer a link to see to whom this person reports
	if { $number_superiors > 0 } {
	    append page_content "  <li> <a href=[im_url_stub]/employees/org-chart-chain?[export_url_vars user_id]>View chain of command</a> starting with this employee\n"
	}
    }	

    if { [exists_and_not_null portrait_upload_date] } {
	if { $looking_at_self_p } {
	    append page_content "<p><li><a href=/pvt/portrait/index?[export_url_vars return_url]>Portrait</A>\n"
	} else {
	    append page_content "<p><li><a href=/shared/portrait?[export_url_vars user_id]>Portrait</A>\n"
	}
    } elseif { $looking_at_self_p } {
	append page_content "<p><li>Show everyone else at [ad_system_name] how great looking you are:  <a href=/pvt/portrait/upload?[export_url_vars return_url]>upload a portrait</a>"
    }

    append page_content "<p>"

    if [exists_and_not_null email] {
	append page_content "<LI>Email: <A HREF=mailto:$email>$email</A>\n";
    }
    if [exists_and_not_null url] {
	append page_content "<LI>Homepage: <A HREF=[im_maybe_prepend_http $url]>[im_maybe_prepend_http $url]</A>\n";
    }
    if [exists_and_not_null aim_screen_name] {
	append page_content "<LI>AIM name: $aim_screen_name\n";
    }
    if [exists_and_not_null icq_number] {
	append page_content "<LI>ICQ number: $icq_number\n";
    }
    if [exists_and_not_null work_phone] {
	append page_content "<LI>Work phone: $work_phone\n";
    }
    if [exists_and_not_null home_phone] {
	append page_content "<LI>Home phone: $home_phone\n";
    }
    if [exists_and_not_null cell_phone] {
	append page_content "<LI>Cell phone: $cell_phone\n";
    }


    set address [im_format_address [value_if_exists ha_line1] [value_if_exists ha_line2] [value_if_exists ha_city] [value_if_exists ha_state] [value_if_exists ha_postal_code]]

    if { ![empty_string_p $address] } {
	append page_content "
	<p><table cellpadding=0 border=0 cellspacing=0>
	<tr>
	<td valign=top><em>Home address: </em></td>
	<td>$address</td>
	</tr>
	</table>

	"
    }

    if [exists_and_not_null skills] {
	append page_content "<p><em>Special skills:</em> $skills\n";
    }

    if [exists_and_not_null educational_history] {
	append page_content "<p><em>Degrees/Schools:</em> $educational_history\n";
    }

    if [exists_and_not_null last_degree_completed] {
	append page_content "<p><em>Last Degree Completed:</em> $last_degree_completed\n";
    }

    if [exists_and_not_null bio] {
	append page_content "<p><em>Biography:</em> $bio\n";
    }

    if [exists_and_not_null note] {
	append page_content "<p><em>Other information:</em> $note\n";
    }

    if {$looking_at_self_p} {
	append page_content "<p>(<A HREF=[im_url_stub]/users/info-update>edit</A>)\n"
    }


    if { $user_employee_p } {
	append page_content "
    <p><i>Current projects:</i><ul>\n"

	set projects_html ""

	set selection [ns_db select $db  "select user_group_name_from_id(group_id) as project_name, parent_id,
                    decode(parent_id,null,null,user_group_name_from_id(parent_id)) as parent_project_name,
                    group_id as project_id
               from im_projects p
              where p.project_status_id in (select project_status_id
                                              from im_project_status 
                                             where project_status='Open' 
                                                or project_status='Future')
                and ad_group_member_p ( $user_id, p.group_id ) = 't'
            connect by prior group_id=parent_id
              start with parent_id is null"]

	set projects_html ""
	while { [ns_db getrow $db $selection] } {
	    set_variables_after_query
	    append projects_html "  <li> "
	    if { ![empty_string_p $parent_id] } {
		append projects_html "<a href=[im_url_stub]/projects/view?group_id=$parent_id>$parent_project_name</a> : "
	    }
	    append projects_html "<a href=[im_url_stub]/projects/view?group_id=$project_id>$project_name</a>\n"
	}
	if { [empty_string_p $projects_html] } {
	    set projects_html "  <li><i>None</i>\n"
	}

	append page_content "
	$projects_html
    </ul>
    "

	set selection [ns_db select $db "select to_char(start_date, 'Mon DD, YYYY') as start_date, to_char(end_date,'Mon DD, YYYY') as end_date, contact_info, initcap(vacation_type) as vacation_type, vacation_id,
    description from user_vacations where user_id = $user_id 
    and (start_date >= to_date(sysdate,'YYYY-MM-DD') or
    (start_date <= to_date(sysdate,'YYYY-MM-DD') and end_date >= to_date(sysdate,'YYYY-MM-DD')))
    order by start_date asc"]

	set office_absences ""
	while {[ns_db getrow $db $selection]} {
	    set_variables_after_query
	    if { [empty_string_p $vacation_type] } {
		set vacation_type "Vacation"
	    }
	    append office_absences "  <li><b>$vacation_type</b>: $start_date - $end_date, <br>$description<br>
	    Contact info: $contact_info"
	    
	    if { $looking_at_self_p || $user_admin_p } {
		append office_absences "<br><a href=[im_url]/absences/edit?[export_url_vars vacation_id]>edit</a>"
	    }
	}
	
	if { ![empty_string_p $office_absences] } {
	    append page_content "
	<p>
	<i>Office Absences:</i>
	<ul>
	$office_absences
	</ul>
	"
        }

	if { [ad_parameter TrackHours intranet 0] && [im_user_is_employee_p $db $user_id] } {
	    append page_content "
	<p><a href=[im_url]/hours/index?on_which_table=im_projects&[export_url_vars user_id]>View this person's work log</a>
	</ul>
	"
        }

    }

    append page_content "</ul>\n"

    # Append a list of all the user's groups
    set selection [ns_db select $db  "select ug.group_id, ug.group_name 
               from user_groups ug
              where ad_group_member_p ( $user_id, ug.group_id ) = 't'
              order by lower(group_name)"]
    set groups ""
    while { [ns_db getrow $db $selection] } {
	set_variables_after_query
	append groups "  <li> $group_name\n"
    }
    if { ![empty_string_p $groups] } {
	append page_content "<p><b>Groups to which this user belongs</b><ul>\n$groups</ul>\n"
    }

    # don't sign it with the publisher's email address!
    return $page_content


philg@mit.edu