Login   Register  
PHP Classes
elePHPant
Icontem

File: example_extend.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of bill  >  Simple access layer  >  example_extend.php  >  Download  
File: example_extend.php
Role: Example script
Content type: text/plain
Description: example of class extend with db
Class: Simple access layer
Manage user resource access permissions
Author: By
Last change: more functional and understandable this way
Date: 6 years ago
Size: 1,225 bytes
 

Contents

Class file image Download
<?php
/**
 *
 * User access layer class.
 *
 * This is a simple user access layer resource.
 *
 *
 * @copyright  2008 Tal Cohen
 * @author     Tal Cohen MSN: tal7814@hotmail.com
 * @version    CVS: $Id:$
 *
 *
 */


/**
 * simple extend class for SimpleAcl
 *
 */

include_once("simple_acl.php");

class 
NotSoSimpleAcl extends SimpleAcl {

   
/**
    * make sure user can edit only his post in the blog
    *
    */
   
public function editPost($db,$postId){

      
//admin can edit everything
      
if ($this->isAdmin()) {
         return 
true;
      }

      
$postId = (int)$postId;

      
//let check user vs. db
      
$result $db->fetchRow(
       
" SELECT * "
      
." FROM posts "
      
." WHERE post_id = $postId "
      
." AND user_id = $this->userId "
      
);

      
//good user
      
if (!empty($result)) {
          return 
true;
      }
      
//bad user
      
else return false;
   }
}



/*

$userId = 127;
$userLevel = 4;

$acl = new NotSoSimpleAcl($userId,$userLevel);


$postId = 827;
$db="adodb or whatever";

if ($acl->editPost($db,$postId)) {
    echo "user can edit this post";
}
else {
   echo "user can't edit this post";
}

*/

?>