<?
/*
The Contacts tab provides a list of contacts ( Users with ProMan accounts) for the selected project. 
<P>You can send email to a project member by clicking on their email address in the listing. 
<P>You can send email to the entire project team by clicking on Contacts at the top of the listing. 
 Users in theÂ contact list may update their personal informationÂ via the MyProfile tab. 
<p>
<img src=../images/Contacts.jpg>
*/
global $rID;
global $rstring;

$mSubj=`Contacts`;

$rID=$_REQUEST[~RolesAvailable~];
if ($rID == ~~)
	$rID=999;

if ($rID==999)
	$rstring=~ ~;
else
	$rstring=~ and RoleId=~ . $rID . ~ ~;

//echo ~RolesAvailable=~ , $rID;

$NOSORT=1;

$sql=~select LastName, Firstname, UserName, Unit as Organization, TelePhone, ~ .
		~concat(`<a href=mailto:`,email,`>`,email,`</a>`) as EmailAddress ~ .
		~from Users where isDeleted=0 and UserID in ~ .
		~(select UserID from ProjectMembers ~ .
		~where projectid=~ . $_SESSION[~ProjectId~] . ~) ~ .
		$rstring .
		~order by LastName, FirstName~;

//echo ~sql:~ , $sql , ~~;

function ToAll()
{
	global $rstring;

	$sql = ~select email from Users where isDeleted=0 and UserID in ~ .
		~(select UserID from ProjectMembers ~ .
		~where projectid=~ . $_SESSION[~ProjectId~] . ~) ~ .
		$rstring .
		~order by LastName, FirstName~;

	$res=GetResultset($sql);

    if(!$row = mysql_fetch_assoc($res))
    {
        return false;
    }

	$tComma=~~;
    do
    {
 		$tList= $tList . $tComma . $row[~email~];
 		$tComma=~;~;
    }
    while ($row = mysql_fetch_assoc($res));

	DisConnect();

	return $tList;
}

function loadRoles()
{
	global $rID;

	echo ~<option value=999>All Roles</option>~;

	$sql = ~Select RoleId,RoleName from Roles where isDisabled=0 order by RoleName~;

	$res=GetResultset($sql);

    if(!$row = mysql_fetch_assoc($res))
    {
        return false;
    }

    do
    {
		if ($row[~RoleId~] == $rID)
			echo `<option selected=~yes~ value=~` , $row[~RoleId~] , `~>` ,   $row[~RoleName~], `</option>`;
		else
			echo `<option value=~` , $row[~RoleId~] , `~>` ,  $row[~RoleName~], `</option>`;
    }
    while ($row = mysql_fetch_assoc($res));

	DisConnect();
}
echo `<table class=tdblueS><tr><td>`;
echo `<table border=0 width=100%><tr><td align=middle>`;

echo `<a href=mailto:`, ToAll(), `><font size=5>Contacts</font></a>`;
echo `</td>`;
echo `<td align=right>`;
echo `<select name=~RolesAvailable~ class=~NormalTextBox~ style=~width:180px;~ onchange=~ReLoadPage();~>`;

loadRoles();

echo `</select>`;
echo `</td>`;
echo `</tr></table>`;
$CELLPADDING=10;
$CELLSPACING=0;
ShowQueryResult($sql);
echo `<br><font size=1>(Only portal account holders appear in the above list)</font>`;
echo `</td></tr></table>`;
echo `<p>`;

echo `</center>`;

?>