GroupRights.php
[Pman.Admin] / GroupRights.php
1 <?php
2 /**
3  * 
4  * Part of Core..
5  * 
6  */
7 require_once 'Pman.php';
8
9 class Pman_Admin_GroupRights extends Pman
10 {
11     function getAuth() {
12         parent::getAuth(); // load company!
13         $au = $this->getAuthUser();
14         if (!$au) {
15             $this->jerr("Not authenticated", array('authFailure' => true));
16         }
17         $this->authUser = $au;
18         return true;
19     }
20     
21     // perms - any table that can be modified by the user should be listed here..
22     // without it, our perms manager should deny writing via the web interface...
23     
24     // FOR PERMS - SEE THE DATAOBJECT!
25     
26     function get()
27     {
28         // must recieve a group..
29         if (!isset($_GET['group_id']) || (int)$_GET['group_id'] < 0) {
30             $this->jerr("NO GROUP");
31         }
32         if (!$this->hasPerm( 'Core.Groups','S')) { // listing groups..
33             $this->jerr("PERMISSION DENIED");
34         }
35         
36         $g = DB_DataObject::Factory('groups');
37         if (!$g->get($_GET['group_id'])) {
38             $this->jerr("group is invalid");
39         }
40         
41          //   DB_DataObject::debugLevel(1);
42         $p = DB_DataObject::factory('group_rights');
43         $p->group_id = (int)$_GET['group_id'];
44         $p->find();
45         $cur = array();
46     
47         while ($p->fetch()) {
48             $cur[$p->rightname] = clone($p);
49         }
50         $e = -1;
51         $ar = array();
52         // echo "<PRE>"; print_r($p->defaultPermData() );
53         foreach($p->defaultPermData() as $k => $defdata) {
54             
55             if (empty($defdata[0])) { // no admin data available..
56                 continue;
57             }
58             if (!isset($cur[$k])) {
59                 // then there is no current access right for it..
60                 //DB_DataObject::debugLevel(1);
61                 $gr = DB_DataObject::factory('group_rights');
62                 $gr->group_id = (int)$_GET['group_id'];
63                 $gr->rightname = $k;
64                 $gr->accessmask = $defdata[1]; // set to defaults..
65                 $gr->insert();
66                 $cur[$k] = clone($gr);
67             }
68             
69             
70             $ar[] = array(
71                 'id' => $cur[$k]->id * 1, //
72                 'rightname' => $k,
73                 'descript' => isset($defdata[2]) ? $defdata[2] : '' ,
74                 'accessmask' => $cur[$k]->accessmask,
75                 'FullMask' => $defdata[0],
76                 'group_id' => (int)$_GET['group_id']
77             );
78                 
79         }
80         $this->jdata($ar);
81         
82          
83     }
84     
85     
86     // post.. 
87     function post()
88     {
89         if (!isset($_POST['group_id']) || (int)$_POST['group_id'] < 0) {
90             $this->jerr("NO GROUP");
91         }
92         if (!$this->hasPerm( 'Core.Groups','E')) { // editing groups..
93             $this->jerr("PERMISSION DENIED");
94         }
95         
96         
97             
98         
99         
100         // add or update..
101         if (!empty($_POST['dataUpdate'])) {
102             foreach($_POST['dataUpdate'] as $id => $ac) {
103                 $p = DB_DataObject::factory('group_rights');
104                 $p->group_id = (int)$_POST['group_id'];
105                 if (!$p->get($id)) {
106                     continue; // errro cond.
107                 }
108                 $po = clone($p);
109                 $p->accessmask = $ac;
110                 $p->validate(); // ensure that the basic perms can not be removed
111                 $p->update($po);
112             }
113         }
114         if (!empty($_POST['dataAdd'])) {
115             foreach($_POST['dataAdd'] as $perm => $ac) {
116                 $p = DB_DataObject::factory('group_rights');
117                 $p->group_id = (int)$_POST['group_id'];
118                 $p->rightname = $perm;
119                 $p->accessmask = $ac;
120                 $p->validate(); // ensure that the basic perms can not be removed
121                 $p->insert();
122             }
123         }
124         $this->jok("done");
125         
126         
127         
128     }
129      
130     
131     
132     
133     
134 }