Hi,
I have a site that allows profiles etc.
I want to take a function off of one page and add it to another. Sounds easy enough?
I now have it set so the person logged in can add buddies but only that person can view them. Now, I want everyone to be able to see each others buddies from the persons profile page.
Here is the profile pages SQLs and function
function show_profile($user_id)
{
global $tb_users, $tb_comments, $tb_sessions, $tb_user_types;
global $base_url, $tpl;
$i=$user_id;
$rate_sql = "
select
$tb_users.id as id,
$tb_users.username as user_name,
$tb_users.realname as realname,
$tb_users.description as description,
$tb_users.video as video,
$tb_users.age as age,
$tb_users.user_type as user_type,
$tb_users.state as state,
$tb_users.country as country,
$tb_users.url as url,
$tb_users.quote as quote,
$tb_users.average_rating as average_rating,
$tb_users.total_points as total_points,
$tb_users.total_ratings as total_ratings,
$tb_users.last_logged as last_logged,
$tb_users.user_type as usertype,
$tb_users.email as useremail
from
$tb_users
where
id = '$user_id' ";
$rate_query = mysql_query($rate_sql) or die(mysql_error());
if(mysql_num_rows($rate_query) > 0)
{
while($array = mysql_fetch_array($rate_query))
{
$image_src = get_image($array["id"]);
$qry = "select now() from $tb_users";
$res= mysql_query($qry);
$result = mysql_fetch_row($res) or die(mysql_error());
$now = $result[0];
$then = $array[last_logged];
$then1=$array[last_logged];
//--------------------------
$now = strtotime ("$now");
$then = strtotime ("$then");
$difference = $now - $then ;
$num = $difference/86400;
$days = intval($num);
$num2 = ($num - $days)*24;
$hours = intval($num2);
$num3 = ($num2 - $hours)*60;
$mins = intval($num3);
$num4 = ($num3 - $mins)*60;
$secs = intval($num4);
// $temp = split(" ",$array['last_logged']);
// $temp1 = split("-",$temp[0]);
// $temp2 = split(":",$temp[1]);
// $array[last_logged] = $temp1[1]."-".$temp1[2]."-".$temp1[0]." ".$temp2[0].":".$temp2[1].":".$temp2[2];
if ($then1 == "0000-00-00 00:00:00")
$last_logged_text="";
else
$last_logged_text="$days days $hours hours and $mins mins ago";
$link_field_size = strlen($base_url . "/?i=" . $user_id);
$favouritelink = "<td align='right'><a href=\"$base_url/add_to_favourites.php?i=$i\"><img align=\"top\" border=\"0\" src=\"$base_url/images/addfavourite.jpg\" alt=\"Add to Favourites\" title=\"Add to Favourites\"></a> </td>";
$favouritelink1 = "<td > </td>";
$favouritelink = isset($_SESSION['userid']) ? $favouritelink : $favouritelink1;
$short_entry = eregi_replace(".gif", "", $array["country"]);
$country = eregi_replace("_", " ", $short_entry);
$desc1 = array();
$desc2 = array();
$desc1 = split(" ",$array[description]);
$tot_desc = count($desc1);
$mylength = 0;
$index = 0;
for($i=0;$i<$tot_desc;$i++)
{
$length = strlen($desc1[$i]);
if (($mylength + $length)>80)
{
$req_len = 50 - $mylength;
$desc2[$index] = substr($desc1[$i],0,$req_len);
$desc1[$i] = substr($desc1[$i],$req_len);
$mylength = strlen($desc1[$i]);
$index++;
}
if ($mylength > 80) { $desc2 = mysplit($desc1[$i],$desc2); }
else
{
$mylength += strlen($desc1[$i]);
$desc2[$index] = $desc1[$i];
$index++;
}
}
$array[description] = implode(" ",$desc2);
$array[description]=nl2br($array[description]);
$title = "About";
$extra_photos = get_image($array["id"], 2);
if (strpos($extra_photos,"notfound_image"))
$extra_photos="";
$users = "";
$gu_sql = "select data from $tb_sessions";
$gu_query = mysql_query($gu_sql) or die(mysql_error());
$total_user_sessions = mysql_num_rows($gu_query);
if($total_user_sessions)
{
$username_array = array();
$userid_array = array();
while($gu_array = mysql_fetch_array($gu_query))
{
if(strlen(trim($gu_array["data"])))
{
$strings = split(";", $gu_array["data"]);
for($x = 0; $x < sizeof($strings); $x++)
{
if(strlen($strings[$x]))
{
if((eregi("^username", $strings[$x])) ||(eregi("^}username", $strings[$x])))
{
$parts = split(":", $strings[$x]);
$username_array[] = eregi_replace("\"", "", $parts[2]);
}
}
}
}
}
$status="<img align=\"absmiddle\" src=\"$base_url/images/user_offline.gif\" hspace=\"3\" vspace=\"1\" alt=\"Offline\" title=\"Offline\">";
$user_status="Offline";
if(sizeof($username_array))
{
$un = array_unique($username_array);
for($z = 0; $z < sizeof($un); $z++)
{
if($un[$z] == $array[user_name])
{
$status="<img src=\"$base_url/images/user_online.gif\" hspace=\"3\" vspace=\"1\" alt=\"Online\" title=\"Online\" align=\"absmiddle\">";
$user_status="Online";
break;
}
}
}
} // if
$usql = "
select
user_type
from
$tb_user_types
where id=$array[usertype] ";
$ures=mysql_query($usql);
$urs = mysql_fetch_array($ures);
$user_types=$urs[0];
$uid=$user_id;
$uid=$user_id;
$site_url = $array['url'];
$site_url = str_replace("http://","",$site_url);
$site_url = str_replace("HTTP://","",$site_url);
$site_url = "http://" . "$site_url" ;
$tpl->assign(array('EXTRA_PHOTOS' => !empty($extra_photos) ? table('Extra Images', $extra_photos) : '',
'STATUS' => $status,
'USER_STATUS' => $user_status,
'FAVOURITELINK' => $favouritelink,
'AVERAGE_RATING' => $array['average_rating'],
'TOTAL_POINTS' => $array['total_points'],
'TOTAL_RATINGS' => $array['total_ratings'],
'USER_NAME' => $array['user_name'],
'REAL_NAME' => $array['realname'],
'AGE' => $array['age'],
'DESCRIPTION' => $array['description'],
'VIDEO' => $array['video'],
'STATE' => $array['state'],
'COUNTRY' => '<img align="top" border="1" src="' . $base_url . '/images/flags/' . $array['country'] . '" hspace="5" alt="' . $country . '" title=" ' . $country . '">' . $country,
'URL' => '<a class=link01 href="' . $site_url . '" target="_blank">' . $site_url . '</a>',
'QUOTE' => '<i>"' . $array['quote'] . '"</i>',
'LAST_LOGGED_TEXT' => $last_logged_text,
'UID' => $uid,
'ADDITIONAL_FIELDS' => view_additional_fields($uid)));
$tpl->parse('SHOW_PROFILE_CONTENT', 'show_profile');
$content = $tpl->fetch('SHOW_PROFILE_CONTENT');
$final_output = $content;
//$final_output .= table('<img src="images/description.gif">', $content);
// $content = "";
}// while
}
return $final_output;
}
See below post for rest