summaryrefslogtreecommitdiffstats
path: root/codebase/Dhtmlx/Connector/Tools/AccessMaster.php
blob: ce47c6f01e8ac96a52bd3eeff17e39803c7b820b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
namespace Dhtmlx\Connector\Tools;
/*! Class which handles access rules.
**/
class AccessMaster{
    private $rules,$local;
    /*! constructor

        Set next access right to "allowed" by default : read, insert, update, delete
        Basically - all common data operations allowed by default
    */
    function __construct(){
        $this->rules=array("read" => true, "insert" => true, "update" => true, "delete" => true);
        $this->local=true;
    }
    /*! change access rule to "allow"
        @param name
            name of access right
    */
    public function allow($name){
        $this->rules[$name]=true;
    }
    /*! change access rule to "deny"

        @param name
            name of access right
    */
    public function deny($name){
        $this->rules[$name]=false;
    }

    /*! change all access rules to "deny"
    */
    public function deny_all(){
        $this->rules=array();
    }

    /*! check access rule

        @param name
            name of access right
        @return
            true if access rule allowed, false otherwise
    */
    public function check($name){
        if ($this->local){
            /*!
            todo
                add referrer check, to prevent access from remote points
            */
        }
        if (!isset($this->rules[$name]) || !$this->rules[$name]){
            return false;
        }
        return true;
    }
}