Login   Register  
PHP Classes

File: page1.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Michael Rubinsky  >  IMSP Client Classes  >  page1.php  >  Download  
File: page1.php
Role: ???
Content type: text/plain
Description: Demonstration Files
Class: IMSP Client Classes
Deprecated classes for dealing with IMSP servers.
Author: By
Last change:
Date: 12 years ago
Size: 4,907 bytes


Class file image Download
session_start();																			//Start the session
require("cIMSPABook.php");																	//Include the IMSPABook class definition	

//Make sure we are at this page because of a login.
/*if (!isset($_REQUEST["uname"])) {
	header("Location: http://www.yourdomain.com/imsp/login.html");
//Get the passed in stuff from the login form.
$username = $_REQUEST["uname"];
$pass = $_REQUEST["passwd"];

//HTML Strings to help in builing the table.
$abookstringone = "<TR><TD><A HREF='page2.php?entry=";
$abookstringtwo = "</TD></TR>";

/* In this example, the name of the address book we will search is the same as the username.
 * Of course, in a real implementation, you would allow the user to choose the addressbook to use with
 * a HTML form.
$abookname = $username;

	<title>Address Book Sample</title>

//This section demonstrates how to use the IMSPAddressBook Class.
	$imsp = new IMSPAddressBook();								//Create the instance
	if($imsp->login($username,$pass)) {							//Try to login to the server
		$_SESSION["loggedin"] = TRUE;							//Set some session variables (you can implement this however you choose...it is not important to the class functionality)
		$_SESSION["username"] = $username;
		$_SESSION["pass"] = $pass;								//We should probably at least binhex this since this will probably be sitting in a session file on the server.
	} else {
		//If we are here, then the login failed.
		echo "Could not log you in!";
	/* Retrieve an array of all names in the addressbook. 
	 * Note the use of only the wildcard "*" to return all names
	 * You can also perform more restricted searches:
	 * $imsp->searchAddressBook($abookname,"John S*");  //Would return all names starting with "John S" such as "John Smith" and "John Samuels"
	$entries = $imsp->searchAddressBook($abookname,"*");

	//Build a table for the addressbook results.

	echo("<Table border=1>\n");
	for($i=0 ; $i < count($entries) ; $i++) {
		//encode the name if needed so it be placed in a query string
		$entryName = rawurlencode($entries[$i]);
		//Build the table
		echo($abookstringone . $entryName . "'>$entries[$i]</A>" . $abookstringtwo);
	echo ("</TABLE>");

	//The following sections are commented out but demonstrate different methods

	/* Get a listing of all the addressbooks viewable by this user.
	 * $abooks will be an array of the addressbook names
	$abooks = $imspd->getAddressBookList();
	for($i=0 ; $i < count($abooks) ; $i++){

	/* Shows how to retrieve a complete addressbook entry
	 * $myAddy is an associative array containg KEY/VALUE pairs
	 * for each addressbook field. (See also page2.php for a more complete example of this)
	if ($myAddy = $imsp->getAddressBookEntry($abookname,"John Doe")) {
		while (list($key,$value) = each($myAddy)){
			echo "Element $key equals $value<BR>\n";
	/* Shows how to add an entry to a addressbook
	 * The $addressInfo variable is an associative array
	 * containing the KEY/VALUE pairs for each field you are
	 * filling in.  If you call this mehtod on an existing entry (using an existing "name" KEY)
	 * then that entry is updated with the new information.
	$addressInfo = array ("name" => "John Doe", 
					"email" => "testing@there.com", 
					"companyname" => "some  company");
	//The following line will delete an addressbook entry in the specified addressbook.
	//$imspd->deleteAddress($abookname,"John Doe");
	/* The following demonstrates the procedure for locking and unlocking addressbook entries */
	$myAddy = $imspd->lockABook($abookname,"John Doe");
	if(!$myAddy) {
		echo("Could not lock");
	} else {
		echo("Lock Successfull");
		while (list($key,$value) = each($myAddy)){
			echo "Element $key equals $value<BR>\n";
	if(!$imspd->unlockABook($abookname,"John Doe")) {
		echo("Could not release lock");
	} else {
		echo("Unlock successfull");
	//To rename an addressbook:
	//To change/create an ACL:
	/*$acl = "lrp";
	/*$acl = $imsp->getACL("bookname");
	while (list($key,$value) = each($acl)) {
		echo "User $key has the following ACL: $value";
	//To get the current user's rights on any abook.
	/*$acl = $imsp->myRights("bookname");
	echo "The current user has the following ACL: $acl";
	//Log out of the IMSP server (this does NOT kill the current PHP session)