Location: PHPKode > projects > Prsaar Social Networking Platform > PrsaarColour-0.7.alpha.6.3/pr-admin/friend-new.php
<?php
	require_once('./admin.php');
	$Display->Title = 'Friends';
	$Display->Subtitle = 'Add a friend';
	if(empty($_GET['step'])) $Step = 1;
	else $Step = intval($_GET['step']);
	require_once('./admin-display-header.php');
	
	//step 1-------------------------------------------------------------------------
	if($Step === 1)
	{
		$ConnectURL = false;
		$Form = new AdminForm('friend-new.php?step=2');
		$Form->Input('text', 'connect_url', $ConnectURL, 'Connect URL', 'Enter the URL of prsaar-connect of your friend. <br /> Ex: http://your-friend.com/profile/connect/ <br /> http://social-networking.com/profile/username/connect/');
?>
	<h2> Add new friend &raquo;</h2>
	<p><code>Doesn't works properly :(</code></p>
	<strong>Enter the Prsaar-connect url of your friend</strong>
<?php _p($Form->Finish('Add friend &raquo;'));
	}
	
	//step 2----------------------------------------------------------------------------
	elseif($Step === 2)
	{
	/* The idea used here to retrive values from prsaar-connect url is taken without permission from the comment published by tim-the/lazy/coder[tim/alloutinteraction/com] on date/time 01-Oct-2005 02:29 at the page http://in2.php.net/
*/
		//check if the friend already exists.
		$FriendURL = $DC->Result("SELECT friend_connect_url, friend_name FROM ".PR_DATABASE_PREFIX."friend");
		if($FriendURL != false)
		{
			foreach($FriendURL as $KeyValue)
			{
				if($KeyValue['friend_connect_url'] === $_POST['connect_url'])
				{
?>
<p> Your friend <strong> <?php _p($KeyValue['friend_name']); ?> </strong> already exists in your added friends. <br /> You provided <a href='<?php _p($_POST['connect_url']); ?>'><?php _p($_POST['connect_url']); ?></a> </p>
<?php
				die(require_once('./admin-display-footer.php'));
				}
			}
		}
		$File = @file_get_contents($_POST['connect_url']);
		if($File == false) die("cannot resolve the <code>prsaar-connect</code> url, please check if you have given the right <code>prsaar-connect</code> url and you are connected to the internet <br /> You provided <a href='{$_POST['connect_url']}'>{$_POST['connect_url']}</a>");
		$Field = array("name", "description", "sex" , "email", "realName", "dateOfBirth", "country", "city", "platformID", "homepage" );
		foreach ($Field as $KeyValue) 
		{
   			if(strpos($File,$KeyValue)!== false)
			{
				$GetData[$KeyValue]=trim(substr( $File, strpos($File,"<$KeyValue>" )+strlen("<$KeyValue>"),strpos($File,"</$KeyValue>" )-strlen("<$KeyValue>")-strpos($File,"<$KeyValue>" )));
   			}
		}
		$Collect = " <table> <form method='post' action='friend.php?page=new&step=3'> ";
		foreach($GetData as $Key => $KeyValue)
		{
			$Piece = " <tr> <td> <strong> $Key </strong> </td> <td> <input type='hidden' name='{$Key}' value='{$KeyValue}' />$KeyValue </td> </tr> ";
			$Collect = $Collect.$Piece;
		}
		$Collect = $Collect." <tr> <td> <input type='hidden' name='connect_url' value='{$_POST['connect_url']}' /> </td> <td> <input type='submit' value='Yes, add him/her as my friend &raquo;' style='font-size:large' /> </td> </tr> </for> </table> ";
		print " <h2> Verify &raquo;&raquo; </h2> Prsaar has retrived following information from your friends prsaar-connect url, please verify if the following information is correct ".$Collect;
	}
	
	//step 3----------------------------------------------------------------------------
	elseif($Step === 3)
	{
		$FriendTime = date("YmdHis");
		/*
			The coloumn friend_label exists in the friend table, but presently prsaar doesnot labels friends (may in near future).
			friend_image coloumn tells the name of the image-file which is stored somewhere inside prsaar./not-yet-avaliable
		*/
		$DC->Result(" INSERT INTO ".PR_DATABASE_PREFIX."friend SET friend_name = '{$_POST['name']}', friend_description = '{$_POST['description']}', friend_sex = '{$_POST['sex']}', friend_email = '{$_POST['email']}', friend_realname = '{$_POST['realName']}', friend_dateofbirth = '{$_POST['dateOfBirth']}', friend_country = '{$_POST['country']}', friend_city = '{$_POST['city']}', friend_platform_id = '{$_POST['platformID']}', friend_homepage = '{$_POST['homepage']}', friend_label = 'friend', friend_connect_url = '{$_POST['connect_url']}', friend_time = '{$FriendTime}', friend_image = null");
		header("Location: friend.php?highlight=New_friend_added");
		exit();
	}
require_once('./admin-display-footer.php');
?>
Return current item: Prsaar Social Networking Platform