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          //   DB_DataObject::debugLevel(1);
36         $p = DB_DataObject::factory('Group_Rights');
37         $p->group_id = (int)$_GET['group_id'];
38         $p->find();
39         $cur = array();
40     
41         while ($p->fetch()) {
42             $cur[$p->rightname] = clone($p);
43         }
44         $e = -1;
45         $ar = array();
46         // echo "<PRE>"; print_r($p->defaultPermData() );
47         foreach($p->defaultPermData() as $k => $defdata) {
48             
49             if (empty($defdata[0])) { // no admin data available..
50                 continue;
51             }
52             if (!isset($cur[$k])) {
53                 // then there is no current access right for it..
54                 //DB_DataObject::debugLevel(1);
55                 $gr = DB_DataObject::factory('Group_Rights');
56                 $gr->group_id = (int)$_GET['group_id'];
57                 $gr->rightname = $k;
58                 $gr->accessmask = $defdata[1]; // set to defaults..
59                 $gr->insert();
60                 $cur[$k] = clone($gr);
61             }
62             
63             
64             $ar[] = array(
65                 'id' => $cur[$k]->id * 1, //
66                 'rightname' => $k,
67                 'descript' => isset($defdata[2]) ? $defdata[2] : '' ,
68                 'accessmask' => $cur[$k]->accessmask,
69                 'FullMask' => $defdata[0],
70                 'group_id' => (int)$_GET['group_id']
71             );
72                 
73         }
74         $this->jdata($ar);
75         
76          
77     }
78     
79     
80     // post.. 
81     function post()
82     {
83         if (!isset($_POST['group_id']) || (int)$_POST['group_id'] < 0) {
84             $this->jerr("NO GROUP");
85         }
86         if (!$this->hasPerm( 'Core.Groups','E')) { // editing groups..
87             $this->jerr("PERMISSION DENIED");
88         }
89         
90         
91             
92         
93         
94         // add or update..
95         if (!empty($_POST['dataUpdate'])) {
96             foreach($_POST['dataUpdate'] as $id => $ac) {
97                 $p = DB_DataObject::factory('Group_Rights');
98                 $p->group_id = (int)$_POST['group_id'];
99                 if (!$p->get($id)) {
100                     continue; // errro cond.
101                 }
102                 $po = clone($p);
103                 $p->accessmask = $ac;
104                 $p->validate(); // ensure that the basic perms can not be removed
105                 $p->update($po);
106             }
107         }
108         if (!empty($_POST['dataAdd'])) {
109             foreach($_POST['dataAdd'] as $perm => $ac) {
110                 $p = DB_DataObject::factory('Group_Rights');
111                 $p->group_id = (int)$_POST['group_id'];
112                 $p->rightname = $perm;
113                 $p->accessmask = $ac;
114                 $p->validate(); // ensure that the basic perms can not be removed
115                 $p->insert();
116             }
117         }
118         $this->jok("done");
119         
120         
121         
122     }
123      
124     
125     
126     
127     
128 }