Location: PHPKode > scripts > Permissions > permissions/example.php
<?php
/****************************************************************
*****************************************************************
Copyright (C) 2003  Keith Ganger

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

You can find more information about GPL licence at:
http://www.gnu.org/licenses/gpl.html

****************************************************************
****************************************************************/

//this code is used to provide an example of how 
//a programmer would use the permissions class. 
//include the file
require_once("permissions.class.php");
//instanciate the class. 
$perms = new permissions();


//the first example shows how you would use the class to set permissions for a user
$perms->permissions["read"]=true;
$perms->permissions["delete"]=true;
$bitmask=$perms->toBitmask(); 
//echo "bitmask for read and delete= ". $bitmask ."<br>";
$sql ="insert into user_permissions (userid,docid,permission) values($userid,$docid,$bitmask)";
//you would then execute code to insert your sql. 


//the second example shows you how to use the bitmask to get the users permissions. 
//you would execute some sql to retrieve the bitmask from the database like
//select bitmask from user_permissions where docid=$docid and userid=$userid
//$bitmask = $row["bitmask"];
//I will just set this to a hardcoded value of 5 (as used in all the examples
$bitmask=5;
$permarr=$perms->getPermissions($bitmask);
if($permarr["read"]){
	echo "read permissions<br>";
}
//print array to show values
print_r($permarr);

?>
Return current item: Permissions