<?php
    //authenticate.php
    /******************************************/
     
     
    if (array_key_exists('cookieusername' , $_REQUEST ) == TRUE )
        $cookieusername = $_REQUEST['cookieusername'];
     
     
    if (isset($cookieusername))
    {
        $usr = mysql_fetch_array(mysql_query("select password from users where username = '$cookieusername'"));
        if ($_REQUEST['cookiepassword'] == $usr['password'])
        {
            $CURRENTUSER = $cookieusername;
        }
        else
        {
            $CURRENTUSER = 'anonymous';
        }
    }
    else
    {
        $CURRENTUSER = 'anonymous';
    }
     
     
     
     
    function isInGroup($username, $group)
    {
         
         
        $checkGrp = mysql_query("select ID from permissionGroups where username='$username' and pGroup='$group'") or die(mysql_error());
         
        if ($row = mysql_fetch_array($checkGrp))
        {
             
            return true;
             
        }
        else
        {
             
            return false;
             
        }
         
    }
     
    function verify($username, $ID, $action)
    {
        //print "verifying...";
        $group = mysql_query("select permission from blog where ID=$ID") or die(mysql_error());
        $group = mysql_fetch_array($group);
        // check if post's visibility matches a user's group membership
        if (isInGroup($username, $group["permission"]))
        {
            // check for individual restriction actions
            $denies = mysql_query("select count(ID) as Expr1 from permissions where objectID=$ID and username='$username' and action='$action'") or die(mysql_error());
            $denies = mysql_fetch_array($denies);
            if ($denies["Expr1"] == 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        else
        {
            return false;
        }
    }
     
     
     
     
     
?>
