Benoit Lathiere <[EMAIL PROTECTED]> wrote:

> Hi pp !
> 
> Could U send me your class to manage pages access.
> 


<?php

class SecurePage
{
var $user;
var $groups;
var $css;
var $page;
var $uri;

function SecurePage()
        {
        global $midgard;
        $this->uri = $midgard->uri;
        }

function EditGroups()
        {
        if (! $this->page) $this->page = $midgard->page;
        $page = mgd_get_page($this->page);
        $page_params = $page->listparameters("_page_group");
        $tmp_array = array();
        while ($page_params  && $page_params->fetch())
          {
          $tmp_array[$page_params->name] = $page_params->name;
           }
        print "<FORM action=\"$this->uri\" method=\"POST\" class=\"$this->css\">\n";   
 
        print "<select name=\"groups[]\" multiple size=\"6\" class=\"$this->css\">";   
 
        
        $sg_groups = mgd_list_groups();
        while ($sg_groups && $sg_groups->fetch())
          {
          $guid = $sg_groups->guid();
          array_key_exists($guid,$tmp_array) ? $selected = "selected" : $selected = 
"";  
          print "<option value=\"$guid\" $selected>$sg_groups->name</option>\n";
          unset ($selected);
          }     
        print "</select><br>";
        print "<input type=\"submit\" value=\"change\" class=\"$this->css\"></FORM>\n";
        }
        

function AssignGroups($post)
        {       
        if (is_array($post) && array_key_exists("groups",$post))
                {
                if (! $this->page) $this->page = $midgard->page;
                $page = mgd_get_page($this->page);
                $page_params = $page->listparameters("_page_group"); 
                while ($page_params && $page_params->fetch())
                     {
                     $page->parameter("_page_group",$page_params->name,""); 
                     } 
                foreach ($post["groups"] as $key=>$val) 
                     {
                     $page->parameter("_page_group",$val,$val); 
                     }
                
                } 
        }


function Secure($user)
        {
        if (!$user) 
        {
        header("HTTP/1.0 404 Not Found");
        readfile("http://infoglob.pl/404.html";); 
        exit;
        } else {
        
                if (! $this->page) $this->page = $midgard->page;
                $page = mgd_get_page($this->page);
                $page_params = $page->listparameters("_page_group");
                while ($page_params  && $page_params->fetch())
                  {
                   $_gcount++;
                   $group = mgd_get_object_by_guid($page_params->name);
                   mgd_is_member($group->id, $user) ? $_mcount++ : $_mcount-- ;
                  }  
                if ($_gcount + $_mcount < 1) 
                        { 
                        header("HTTP/1.0 404 Not Found");
                        readfile("http://infoglob.pl/404.html";); 
                        exit;
                        }
                   }
        }



function SecureConfig()
        {
        global $midgard;
        $this->page = $midgard->page;
        $this->argv =  $midgard->argv[0];
        $this->uri = $midgard->uri;
        
        if (func_num_args() > 0)
            {
            $this->user = func_get_arg(0);
            $this->post = func_get_arg(1);
            }
        
        if ($this->argv == 'config')
        { 
        if  (!$this->user)   { ?><(login)><? exit; }
        if ($this->user)
            {
             if ($this->post["groups"])
                {
                SecurePage::AssignGroups($this->post);          
                }
             SecurePage::EditGroups();
             exit;
             }
        } else 
        {
        SecurePage::Secure($this->user);
        }

        }


        
}

?>



May be used on active page in code-init:
$test = new SecurePage();
$test->SecureConfig( $user->id, $_POST);
where argv[0] == config will display "login" style element if no user is logged in, 
or multiselect form if user is logged in.

Or just simply:
$test = new SecurePage();
$test->Secure($user->id);

Piotras


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to