function mecontexttt()
{
    global $topmenu;
    global $lifestylelid;
    global $lifestart;
    global $newlifestyleid;
    //  public logic and signed in
    if ($_SESSION[pubuser] == 44) {
        //echo 'START';
        if ($_SESSION[pubuser] == 44 && $_SESSION[user_id]) {
            //echo 'user unclear';
            unset($_SESSION[user_id]);
            unset($_SESSION[username]);
            unset($_SESSION[logged_in]);
            //first time at url then set metext to 4
            if (!$_SESSION[metext]) {
                $_SESSION[metext] = 4;
            }
            if (!$_GET['lifestyleid'] || !$_SESSION[mecid]) {
                $lifestylelid = 1;
            } else {
                $idlifestart = $_SESSION[mecid];
                //echo $idlifestart;
                idstartconvert($idlifestart);
                $lifestylelid = $newlifestyleid;
            }
        }
        // closes if user id info. exists, delete it
        //  if lifestyle activity has been clicked, set next context with it.
        if ($_GET['lifestyleid']) {
            //echo 'AAA';
            $lifestylelid = escapeinteger($_GET['lifestyleid']);
            $topmenu = $_SESSION[topmenu];
            if (!$topmenu) {
                $topmenu['me'] = $lifestyleid;
            }
            memenucode($topmenu, $lifestylelid);
            idconvert($lifestylelid);
            $_SESSION[mecid] = $lifestart;
        } elseif ($_POST['lifestylesid']) {
            // echo 'BBB';
            // need a set of function that will take existing lifestyle menu and add/delete activities and then disply the new lifestyle menu
            $humaddlist = escapeinteger($_POST['lifestylesid']);
            humanaddpublic($humaddlist);
            $idlifestart = $_SESSION[mecid];
            //echo $idlifestart;
            idstartconvert($idlifestart);
            $lifestylelid = $newlifestyleid;
            memenucode($topmenu, $lifestylelid);
            $_SESSION[metext] = 4;
        } elseif ($_GET['mags']) {
            // echo 'DDD';
            $getmag = escapeinteger($_GET['mags']);
            maggroupsel($getmag);
            memenucode($topmenu, $lifestylelid);
            $_SESSION[metext] = 4;
        } else {
            //echo 'CCC';
            if ($_GET['metext'] || $_SESSION[metext]) {
                // need to set a session variable to use to redisplay right context
                $_SESSION[chartreturn] = 1;
                // need to find what lifestlye activity is current and set lifestylelid for it and build menu, if first logged skip
                if ($_GET['metext']) {
                    $_SESSION[metext] = escapeinteger($_GET['metext']);
                } else {
                    $_SESSION[metext] = 4;
                }
            }
            // closes if
            if ($_SESSION[mecid]) {
                $idlifestart = $_SESSION[mecid];
                //echo $idlifestart;
                idstartconvert($idlifestart);
                $lifestylelid = $newlifestyleid;
                //echo $lifestylelid;
            } else {
                $lifestylelid = 1;
                //echo$lifestylelid;
            }
            // if topmenu empty then make it me
            $topmenu = $_SESSION[topmenu];
            if (!$topmenu) {
                $topmenu['me'] = 46;
            }
            memenucode($topmenu, $lifestylelid);
        }
        // closes else
    } else {
        //  if lifestyle activity has been clicked, set next context with it.
        if ($_GET['lifestyleid']) {
            $lifestylelid = escapeinteger($_GET['lifestyleid']);
            $_SESSION[filtext] = 2;
            $topmenu = $_SESSION[topmenu];
            if (!$topmenu) {
                $topmenu['me'] = $lifestyleid;
            }
            memenucode($topmenu, $lifestylelid);
            idconvert($lifestylelid);
            $_SESSION[mecid] = $lifestart;
        } elseif ($_GET['filtext']) {
            $setfiltext = escapeinteger($_GET['filext']);
            $_SESSION[filtext] = $setfiltext;
            if ($setfiltext == 1) {
                $filtext = 1;
            } else {
                $filtext = 2;
            }
            // get current lifestyleid from session to keep its context
            $idlifestart = $_SESSION[mecid];
            //echo $idlifestart;
            idstartconvert($idlifestart);
            $lifestylelid = $newlifestyleid;
            $topmenu = $_SESSION[topmenu];
            if (!$topmenu) {
                $topmenu['me'] = $lifestyleid;
            }
            memenucode($topmenu, $lifestylelid);
        } elseif ($_POST['lifestylesid']) {
            // need a set of function that will take existing lifestyle menu and add/delete activities and then disply the new lifestyle menu
            $humaddlist = escapeinteger($_POST['lifestylesid']);
            humanadd($humaddlist);
            formmenuin();
            memenucode($topmenu, $lifestylelid);
            // if logged in to this
            //header("Location: /lifestylelinking/me/mein.php");
            $_SESSION[metext] = 1;
        } else {
            if ($_GET['metext'] && $_SESSION[mecid]) {
                // need to set a session variable to use to redisplay right context
                $_SESSION[chartreturn] = 1;
                // need to find what lifestlye activity is current and set lifestylelid for it and build menu, if first logged skip
                $_SESSION[metext] = escapeinteger($_GET['metext']);
                $idlifestart = $_SESSION[mecid];
                //echo $idlifestart;
                idstartconvert($idlifestart);
                $lifestylelid = $newlifestyleid;
                //echo $lifestylelid;
                // if topmenu empty then make it me
                $topmenu = $_SESSION[topmenu];
                if (!$topmenu) {
                    $topmenu['me'] = 46;
                }
                memenucode($topmenu, $lifestylelid);
            } else {
                unset($_SESSION[mefid]);
                formmenuin();
                if ($topmenu) {
                    memenucode($topmenu, $lifestylelid);
                    $_SESSION[metext] = 1;
                    $_SESSION[filtext] = 2;
                } else {
                    $_SESSION[metext] = 3;
                }
                //  first time need to match user id to feedsid
                if (!$_SESSION[mefid]) {
                    // need to find out feedid from login userid
                    $db->query = "SELECT * FROM " . RSSDATA . ".rssjoin WHERE " . RSSDATA . ".rssjoin.userid = '{$_SESSION['user_id']}' ";
                    $resultmefid = mysql_query($db->query) or die("Error in query: {$db->query}. " . mysql_error());
                    //echo $db->query;
                    if (mysql_num_rows($resultmefid) == 1) {
                        $row = mysql_fetch_object($resultmefid);
                        $feedmeid = $row->feedsid;
                        $_SESSION[mefid] = $feedmeid;
                    } else {
                        $_SESSION[mefid] = 598;
                    }
                }
                // closes if feedid set
            }
        }
        // closes else
    }
    // closes open else
}
function feedexistadd($meurlfeedid, $entryurl)
{
    global $lifemenu;
    global $lifequalify;
    $lmenuexist = $_SESSION['topmenu'];
    unset($_SESSION[topmenu]);
    //print_r($lmenuexist);
    //print_r($_SESSION['topmenu']);
    //echo 'pastexisting';
    // find out the number of top level lifestyles, first form arrary of all possible lifestyle options
    standardtopmenutwo();
    // find out if this url qualifies for any lifestyle?
    memenu($meurlfeedid);
    $_SESSION[lifemenu] = $lifemenu;
    $_SESSION[lifequalify] = $lifequalify;
    // find lifestyles that qualify
    compareusermenutwo($lifemenu, $lifequalify);
    // builds menus  /////////////////////////////////////////////////////////////////////////////////////////////////////////////
    memenucode($topmenu, $lifestylelid);
    $_SESSION[me_url] = $entryurl;
    $_SESSION[mefid] = $newfeedid;
    $topfivem = $_SESSION[topmenu];
    //print_r($topfivem);
    //echo 'pasttopfive';
    // now need to add manually added back lifestlye menu items not included by mepath in the individuals users top5. (obviously mepath would not want this outcome if they blog out the lifestlye in question ie. mepath has got it wrong).
    // compare topmenubefore with current menu.
    comptop5man($lmenuexist, $topfivem);
    $db->query = "INSERT INTO " . RSSDATA . ".rssjoin (userid, feedsid) VALUES ('{$_SESSION['user_id']}', '{$meurlfeedid}')";
    // execute query grouped words
    $savejoinrss = mysql_query($db->query) or die("Error in query: {$db->query}. " . mysql_error());
    //echo $db->query;
    // need array to contain top lifesytle and save so on return personalized lifestyle menu is presented
    // need to differenciate between man add items and autotop5
    $toplifestle = $_SESSION[newtopm];
    $db->query = "INSERT INTO " . RSSDATA . ".userlife (userid, lifestyleid, humadd) VALUES ";
    foreach ($toplifestle as $toplsi => $mortf) {
        $db->query .= " ('{$_SESSION['user_id']}', '{$toplsi}', '{$mortf}'), ";
    }
    $db->query = substr($db->query, 0, strLen($db->query) - 2);
    //this will eat the last comma
    $resultlmenu = mysql_query($db->query) or die("Error in query: {$db->query}. " . mysql_error());
    //echo $db->query;
}