<?php
//+-----------------------------------------------+//
//+ Copyright Floopo.com
//+ following.php
//+ Display and adding people following a member
//+-----------------------------------------------+//

defined('BASEPATH') or die('You can not directly access this file');//check its within this framework


//____DEFAULT TEMPLATE_____
$inner_template = TEMPLATES.'tpl_index.htm';


//____MYSQL CONNECTION____
//$quickmysql_debug = 1;
$dbase = new QuickMysql(DB_NAME,DB_USER,DB_PASS,DB_HOST);


//____DETERMINE THE STREAM________
$incoming_stream = GetStream();


//____IF STREAM IS VALID MEMBER________
if(MemberExists($incoming_stream)) {

$stream_type = Sanatize($_GET['type']); //following or followers. following = 1

switch($stream_type){

case 1:

//________People this member is following (following)________

//Pagination
$paginate = array($config['following_list'], Sanatize($_GET['page']), '  >>', '<<  '); //limit, page, next, previous
$pagi_addurl_pre = $env_base_url."/index.php?option=com_following&stream=$incoming_stream&type=1&"; //Optional - added in paginated list e.g. 'http://xyz.com?option=asa&'
$stream = $dbase->PaginatedRecordLoop("SELECT following.user_name, member_profile.avatar, member_profile.user_id
        							   FROM following
        							   JOIN member_profile
        							   ON following.user_name = member_profile.user_name
        							   WHERE following.followers_user_name = '$incoming_stream'
                                       AND approved = 'yes'");
        							   
$pagination = $dbase->pagination_simple_html;
//Page title
$general_title = (($env_user_name == $incoming_stream)? 'People you are following' : 'People being followed by'.' '.$incoming_stream);
break;


default:
//__________People following this member (followers)_________

//Pagination
$paginate = array($config['following_list'], Sanatize($_GET['page']), '  >>', '<<  '); //limit, page, next, previous
$pagi_addurl_pre = $env_base_url."/index.php?option=com_following&stream=$incoming_stream&type=2&"; //Optional - added in paginated list e.g. 'http://xyz.com?option=asa&'
$stream = $dbase->PaginatedRecordLoop("SELECT following.followers_user_name as user_name, member_profile.avatar, member_profile.user_id
        							   FROM following
        							   JOIN member_profile
        							   ON following.followers_user_name = member_profile.user_name
        							   WHERE following.user_name = '$incoming_stream'
                                       AND approved = 'yes'");

$pagination = $dbase->pagination_simple_html;
//Page title
$general_title = (($env_user_name == $incoming_stream)? 'People following you' : 'People following'.' '.$incoming_stream);
break;

}

    //_______________MEMBERS GLOBAL DATA______________________________________
    $membersdata = new MembersGlobalData($incoming_stream);

    $web_profiles_array = $membersdata->WebProfiles();// web profile

    $following_array = $membersdata->GetFollowing();// people I am followings
    $count_following = @count($following_array);

    $followers_array = $membersdata->GetFollowers();// people following me
    $count_followers = @count($followers_array);

    $count_updates = $membersdata->CountMembersUpdates();//count updates

    $members_profile = $membersdata->MembersProfile();//welcome message

    //--------------------------------------------------------------------------



}
else {
    //____SHOW NO INFO FOUND_____________
    $notification_large = $lang['invalid_member'];
}


//____VISIBILITY_____________
$visibility = new Visibility('null');
$visible = $visibility->ComFollowings();
//print_r($visible);

foreach($visible as $key => $value) {
    $$key = $value;
}




//____DISPLAY ANY OUTPUT_________________________
$TBS = new clsTinyButStrong;
$TBS->NoErr = true;
$TBS->LoadTemplate(TPL_WRAPPER);
$TBS->MergeField('config',$config);
$TBS->MergeField('profile',$members_profile);
$TBS->MergeField('lang',$lang);
$TBS->MergeBlock('blk1',$stream);
$TBS->MergeBlock('blk2',$web_profiles_array);
$TBS->MergeBlock('blk3',$following_array);
$TBS->Render = TBS_OUTPUT;
$TBS->Show();
@mysql_close();
?>