<?php

//----------------------------------------------------------------------------
// This class will check the "visibility" of content
// blocks based on the following conditions
// 1) Logged in status of viewer
// 2) Viewers relationship with content (i.e. owner or guest)
// 3) Type of content
// More methods can be added and also additional vars to existing comps
//----------------------------------------------------------------------------

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

class Visibility {


    //___Set initial assumed states_____________________

    var $viewer_loggedin = 0; //not logged in
    var $viewer_username = NULL; //no user name
    var $viewer_is_admin = 0;
    var $content; //com_text etc
    var $content_owner = 0; //not owner
    var $stream = NULL; //no stream
    var $stream_exists = 0; //stream does not exist
    var $stream_type = '';
    






    //__Set up enviroment_______________________________
    function Visibility($content) {

        //Globals
        GLOBAL $incoming_stream, $stream_type; //set in calling component
        
        $this->stream_type = $stream_type;

        //set incoming stream
        if($incoming_stream == '' || $incoming_stream == 'public') {
            $this->stream = 'public';
        } else {
            $sql = "SELECT user_id FROM member_profile WHERE user_name = '$incoming_stream'"; //TODO - maybe check if active memeber
            if(mysql_num_rows(mysql_query($sql)) > 0) {
                $this->stream = $incoming_stream;
                $this->stream_exists = 1;
            } else {
                $this->stream = 'public';
            }
        }


        //Set Content type
        $this->content = $content;


        //admin viewer
        $this->viewer_is_admin = $_SESSION['admin'];
        
        //Is viewer logged
        if(isset($_SESSION["env_user_name"])) {
            $this->viewer_loggedin = 1;
            $this->viewer_username = $_SESSION["env_user_name"];
        }

        //Is viewer owner of the stream
        if($this->stream == $this->viewer_username) {
            $this->content_owner = 1;
        }

    }


    //___Updates Visibility Method (also for ComImages)__________________________________________
    function ComText() {

        global $stream;

        $loggedin_quicklinks = 0; // my favs, my stream etc
        $general_welcome_message = 0; //standard welcome
        $memebers_welcome_message = 0; //members welcome
        $members_dashboard = 0; //summary of members pub data
        $public_dashboard = 0; // signup today etc
        $followings_submenu = 0; // "following updates | following images"
        $favorites_submenu = 0; // "following updates | following images"
        $submenu = 1;
        $follow_me = 0; //follow me link
        $my_replies = 0; //replies link
        $delete_content = 0;




        //____While I am NOT logged in_____________________________________
        if($this->viewer_loggedin != 1) {
            $public_dashboard = 1;
        }


        //____Delete Links_____________________________________
            
            //I am admin
            if($this->viewer_is_admin == 1) {
                $delete_content = 1;
            }
            
            //I am owner
            if($this->content_owner == 1) {
             $delete_content = 1;
            }
            
            //remove delete links on all others sections (favs, replies, following) for none admin
            if($this->viewer_is_admin == 0) {
             if($this->stream_type == 'following_updates' || $this->stream_type == 'favorite_updates' || $this->stream_type == 'replies' || $this->stream_type == 'following_images' || $this->stream_type == 'favorite_images'){
			 $delete_content = 0;			 
              }
			}
			           
            
        //____While I am logged in_____________________________________
        if($this->viewer_loggedin == 1) {

            // general logged in links
            $loggedin_quicklinks = 1;

            //my replies links
            if($this->viewer_username == $this->stream) {
                $my_replies = 1;
            }

            //others follow links
            if($this->viewer_username != $this->stream) {
                $follow_me = 1;
            }

        }

        //________Public stream______________________________________________
        if($this->stream == 'public') {

            //general welcome
            $general_welcome_message = 1;
        }

        //____Specific stream_____________________________________
        if($this->stream_exists == 1) {

            //members dashboard
            $members_dashboard = 1;

            //members welcome
            $memebers_welcome_message = 1;

            //advanced sub-menu links
            $followings_submenu = 1;
            $favorites_submenu = 1;
        }





        //___________________Visibility array_____________________
        $com_text_visibility = array(
            'loggedin_quicklinks' => $loggedin_quicklinks,
            'general_welcome_message' => $general_welcome_message,
            'memebers_welcome_message' => $memebers_welcome_message,
            'members_dashboard' => $members_dashboard,
            'submenu' => $submenu,
            'followings_submenu' => $followings_submenu,
            'favorites_submenu' => $followings_submenu,
            'follow_me' => $follow_me,
            'my_replies' => $my_replies,
            'delete_content' => $delete_content,
            'public_dashboard' => $public_dashboard);

        return $com_text_visibility;

    }


    //___Followings Visibility Method__________________________________________
    function ComFollowings() {

        global $stream;
        global $stream_type; //following or followers

        $followings = 1; //main following html block in template
        $loggedin_quicklinks = 0; // my favs, my stream etc
        $general_page_header = 0; // e.g. "People following Fred"
        $followings_actions_follow = 0; // follow button/link
        $followings_actions_delete = 0; // delete button/link
        $submenu = 0; // the main submenu "updates | images | etc"
        $follow_me = 0; //follow me link
        $my_replies = 0; //replies link


        //____While I am NOT logged in_____________________________________
        if($this->viewer_loggedin != 1) {
            $public_dashboard = 1;
        }



        //___________The stream_____________________
        if($this->stream_exists == 1) {
            $members_dashboard = 1;
            $followings_submenu = 1;
            $general_page_header = 1;

            //____viewing own following
            if($this->viewer_username == $this->stream) {
                $followings_actions_delete = 1;
            }

            //____viewing own followers
            if($this->viewer_username == $this->stream && $stream_type == 2) {
                $followings_actions_follow = 1;
            }



        //____While I am logged in_____________________________________
        if($this->viewer_loggedin == 1) {

            //general logged in links
            $loggedin_quicklinks = 1;

            //others follow links
            if($this->viewer_username != $this->stream) {
                $follow_me = 1;
            }

            //my replies links
            if($this->viewer_username == $this->stream) {
                $my_replies = 1;
            }

             //actions on "followers"        
              if($this->viewer_username != $this->stream) {
                $followings_actions_follow = 1;
            }

           }

        }

        //count stream array
        if(count($stream) <= 0) {
            $followings = 0;
        }

        //___________________Visibility array_____________________
        $com_followings_visibility = array(
           'loggedin_quicklinks' => $loggedin_quicklinks,
           'members_dashboard' => $members_dashboard,
           'submenu' => $submenu,
           'followings' => $followings,
           'followings_actions_follow' => $followings_actions_follow,
           'followings_actions_delete' => $followings_actions_delete,
           'follow_me' => $follow_me,
           'my_replies' => $my_replies,
           'public_dashboard' => $public_dashboard);

        return $com_followings_visibility;

    }


}

?>