Location: PHPKode > projects > LDAP contact manager > ldapmgr/dustuff.php
<?php
//script to process requests from form and return output to browser

require_once("functions.php");

$task = $HTTP_GET_VARS["toDo"];
print '<strong>Results for </strong>'.$task."<br>\n";
Switch ($task) {
	Case "search" :
		$sr = find_objects($HTTP_GET_VARS);
		if ($sr) {
			//print result here with cname as lookup anchor
			print "search returned ".count($sr)." matches to your search<br>\n" ;
			print "<p><strong>Search Results:</strong></p>";
			for ($item=0;$item < count($sr);$item++) {
				print $item.": <a href=\"dowork.php?toDo=getInfo&cn=".$sr[$item]."\">".$sr[$item]."</a><br>\n";
				}	
		} else {
			print ("Search Failed to return any matches.") ;
		}
		break ;
	Case "new" :
		$sr = create_entry($HTTP_GET_VARS) ;
		print ($sr) ;
		break ;
	Case "delete" :
		if (isset($HTTP_GET_VARS["oCN"]) && ! empty($HTTP_GET_VARS["oCN"])) {
			print "Deleting contact...<br>\n" ;
			$delRS = delete_object($HTTP_GET_VARS["oCN"]) ;
			print "Result: ".$delRS."<br>\n" ;
		} else {
			$sr = find_objects ($HTTP_GET_VARS) ;
			if ($sr) {
				if (count($sr) == 1 ) {
					print "Deleting contact...<br>\n" ;
					$delRS = delete_object($sr[0]) ;
					print "Result: ".$delSR."<br>\n" ;
				} elseif (count($sr) > 1) {
					print "Select entry to delete: <br>\n" ;
					for ($item=0;$item<count($sr);$item++) {
						print "<a href=\"dustuff.php?toDo=delete&oCN=".$sr[$item]."\">".$sr[$item]."</a><br>\n" ;
					}
				}
			}
		}
		break;
	Case "getInfo" :
			$rs = get_object($HTTP_GET_VARS["cn"]) ; //returns array with object details.
			if (count($rs)>0) {
				print "<center><strong>Contact Details</strong></center><br>\n" ;
				print "<form method=\"GET\" action=\"dowork.php\">\n" ;
				print "<input type=hidden name=oCn value=\"".$HTTP_GET_VARS["cn"]."\"><br>\n" ;
				print "<input type=hidden name=toDo value=update><br>\n" ;
				print "<table border=0 align=center>\n" ;
				print "<tr><td align=right>First Name</td><td><input type=text name=fname size=20 maxlength=20 value=".$rs[0]."></td><td><font color=red>Required Field</font></td></tr>\n";
                		print "<tr><td align=right>Surname</td><td><input type=text name=sname size=20 maxlength=20 value=\"".$rs[1]."\"></td><td><font color=red>Required Field</font></td></tr>\n";
                		print "<tr><td align=right>Company</td><td><input type=text name=company size=20 maxlength=20 value=\"".$rs[2]."\"></td><td><font color=red>Required Field</font></td></tr>\n";
		                print "<tr><td align=right>Email Address</td><td><input type=text name=email size=30 value=".$rs[3]."></td></tr>\n";
	        	        print "<tr><td align=right>Cell Number</td><td><input type=text name=cellnum size=20 maxlength=20 value=\"".$rs[4]."\"></td></tr>\n";
				print "<tr><td><input type=submit value=\"Update Entry\"></td></tr>\n" ;
				print "</table>\n" ;
				print "</form>\n" ;
				
			}
			break;

	Case "update" :
		$oCn = $HTTP_GET_VARS["oCn"] ;
		$info["givenname"] = $HTTP_GET_VARS["fname"] ;
		$info["cn"] = $oCn ;
		$info["sn"] = $HTTP_GET_VARS["sname"] ;
		$info["mail"] = $HTTP_GET_VARS["email"] ;
		$info["description"] = $HTTP_GET_VARS["company"] ;
		$info["telephoneNumber"] = $HTTP_GET_VARS["cellnum"] ;
		$rslt = update_info($oCn,$info) ;
		if ($rslt) {
			print "Contact ".$oCn." details updated successfully." ;
		} else {
			print "Failed to update details for contact ".$oCn ;
		}
		break ;

}




?>
Return current item: LDAP contact manager