Location: PHPKode > projects > Mozart > Mozart-0.0.4/contactlist.php
<?
// called from: index.php and programs called by it
// description: displays CONTACTs by various inputs (type, UserID, etc.)
//
include("connect.inc");
include("reqlogin.inc");
include("userprefs.inc");
?>
<html>
<title>Mozart: Contact Listing</title>
<body bgcolor=<? echo $bgcolor ?> text=<? echo $txtcolor ?>>
<?
include("links.inc");
?>
<center>
<br>
<b>Contact Listing</b>
<br>
<? print("<font color=red>$Message</font>"); ?>
<form action="contactlist.php" method="post">
<?

$ContactTypeSQL = "SELECT type_id, type_name FROM types WHERE type_source = 'Contact' ORDER BY type_name";
$ContactType    = mysql_query($ContactTypeSQL);

if ($ChangeIt) {
	$SearchSys = $ChangeUser;
}
else {
	$SearchSys = $UserID;
}
?>
Show <select name=Type>
<option value=X>All
<?
while ($TypeData = mysql_fetch_array($ContactType)) {
	if ($Type == $TypeData["type_id"]) {
		$selected = " selected";
	}
	else {
		$selected = "";
	}
	printf("<option value=%s%s>%s", $TypeData["type_id"], $selected, $TypeData["type_name"]);
}
?>
</select>
Contacts for <select name=ChangeUser>");
<?
print("<option value=X>All");
include("getallusers.inc");
while ($ownerdata = mysql_fetch_array($OwnerData)) {
	if ($ownerdata["user_id"] == $SearchSys) {
		$selected = " selected";
	}
	else {
		$selected = "";
	}
	printf("<option value=%s%s>%s", $ownerdata["user_id"], $selected, $ownerdata["system_id"]);
}
print("</select>");
print("<input type=submit value=Find name=ChangeIt>");

// 'X' is the value of All
if ($ChangeIt) {
	if ($SearchSys == "X") {
	    if ($Type == "X") {
		$ListSQL = "SELECT contact_id, first, last, middle, xuser_id FROM contact, userxcont WHERE contact_id = xcont_id ORDER BY last, first, middle";
	    }
	    else {
		$ListSQL = "SELECT contact_id, first, last, middle, xuser_id FROM contact, userxcont WHERE contact_type = '$Type' AND contact_id = xcont_id ORDER BY last, first, middle";
	    }
	}
	else {
	   if ($Type == "X") {
		$ListSQL = "SELECT contact_id, first, last, middle, xuser_id FROM contact, userxcont WHERE xuser_id = '$SearchSys' AND contact_id = xcont_id ORDER BY last, first, middle";
	   }
	   else {
		$ListSQL = "SELECT contact_id, first, last, middle, xuser_id FROM contact, userxcont WHERE xuser_id = '$SearchSys' AND contact_id = xcont_id AND contact_type = '$Type' ORDER BY last, first, middle";
	   }
	}
}
elseif (!$beg AND !$Type) {
	$ListSQL = "SELECT contact_id, first, last, middle, xuser_id FROM contact, userxcont WHERE xuser_id = '$SearchSys' AND contact_id = xcont_id ORDER BY last, first, middle";
}
elseif (!$end AND !$Type) {
	$ListSQL = "SELECT contact_id, first, last, middle, xuser_id FROM contact, userxcont WHERE last >= '$beg' AND xuser_id = '$SearchSys' AND contact_id = xcont_id ORDER BY last, first, middle";
}
elseif ($Type) {
	if ($Type == "X") {
		$ListSQL = "SELECT contact_id, first, last, middle, xuser_id FROM contact, userxcont WHERE xuser_id = '$SearchSys' AND contact_id = xcont_id ORDER BY last, first, middle";
	}
	else {
        	$ListSQL = "SELECT contact_id, first, last, middle, xuser_id FROM contact, userxcont WHERE contact_type = '$Type' AND xuser_id = '$SearchSys' AND contact_id = xcont_id ORDER BY last, first ,middle";
	}
}
else {
	$ListSQL = "SELECT contact_id, first, last, middle, xuser_id FROM contact, userxcont WHERE last >= '$beg' AND last < '$end' AND xuser_id = '$SearchSys' AND contact_id = xcont_id ORDER BY last, first, middle";
}
?>

<table border=1 cellspacing=0 cellpadding=0>
<?
$List = mysql_query($ListSQL);
$errno = mysql_errno($db);
$error = mysql_error($db);
// OldContID is used to prevent printing duplicate entries
$OldContID = 0;
if ($errno != 0) {
   printf("<tr><td>No Contacts Found for Selected User(%s)</td></tr>", $errno);
}
else {
  while ($myrow = mysql_fetch_array($List)) {
    // if we haven't already printed this entry, proceed
    if (!($myrow["contact_id"] == $OldContactID)) {
       $OldContactID = $myrow["contact_id"];
       printf("<tr><td><a href=\"%sdisplay.php?id=%s\">%s, %s %s</a></td>", $PHPSELF, $myrow["contact_id"], $myrow["last"], $myrow["first"], $myrow["middle"]);
       printf("<td><a href=\"%supdcontact.php?id=%s\">Update</td>", $PHPSELF, $myrow["contact_id"]);
       printf("<td><a href=\"%sdelcontact.php?id=%s\">Delete</td>", $PHPSELF, $myrow["contact_id"]);
       if (!($UserID == $myrow["xuser_id"])) {
          $ContactID = $myrow["contact_id"];
          $CheckUserXContSQL = "SELECT xuser_id FROM userxcont WHERE xcont_id = '$ContactID' and xuser_id = '$UserID'";
          $CheckUserXCont    = mysql_query($CheckUserXContSQL);
          // kind of complicated, but if this entry exists for the current user, don't print the Add To My . . . option
          if (!($checkuserxcont = mysql_fetch_array($CheckUserXCont))) {
            printf("<td><a href=\"addtomylist.php?id=%s\">Add To My Contact List</td>", $myrow["contact_id"]);
          }
       }
       ?></tr><?
    }
  }
}
?>
</table>
<br>
</form>
</center>
<?
include("links.inc");
?>
</body>
</html>
Return current item: Mozart