7 require_once 'Pman.php';
9 class Pman_Admin_GroupRights extends Pman
12 parent::getAuth(); // load company!
13 $au = $this->getAuthUser();
15 $this->jerr("Not authenticated", array('authFailure' => true));
18 if ($au->company()->comptype !='OWNER') {
19 $this->jerr("Error", "only company owners can manage groups");
22 $this->authUser = $au;
26 // perms - any table that can be modified by the user should be listed here..
27 // without it, our perms manager should deny writing via the web interface...
29 // FOR PERMS - SEE THE DATAOBJECT!
31 function get($v, $opts = Array())
33 // must recieve a group..
34 if (!isset($_GET['group_id']) || (int)$_GET['group_id'] < 0) {
35 $this->jerr("NO GROUP");
38 if (!$this->checkPerm('E')) { // editing groups..
39 $this->jerr("PERMISSION DENIED");
42 $g = DB_DataObject::Factory('core_group');
43 if (!$g->get($_GET['group_id'])) {
44 $this->jerr("group is invalid");
47 // DB_DataObject::debugLevel(1);
48 $p = DB_DataObject::factory('core_group_right');
49 $p->group_id = (int)$_GET['group_id'];
54 $cur[$p->rightname] = clone($p);
57 // print_r($cur);exit;
61 // echo "<PRE>"; print_r($p->defaultPermData() );
62 foreach($p->defaultPermData() as $k => $defdata) {
64 if (empty($defdata[0])) { // no admin data available..
67 if (!isset($cur[$k])) {
68 // then there is no current access right for it..
69 //DB_DataObject::debugLevel(1);
70 $gr = DB_DataObject::factory('core_group_right');
71 $gr->group_id = (int)$_GET['group_id'];
73 $gr->accessmask = $g->type == 2 ? '' : $defdata[1]; // set to defaults.. unless it's a contact group.
75 $cur[$k] = clone($gr);
80 'id' => $cur[$k]->id * 1, //
82 'descript' => isset($defdata[2]) ? $defdata[2] : '' ,
83 'accessmask' => $cur[$k]->accessmask,
84 'FullMask' => $defdata[0],
85 'group_id' => (int)$_GET['group_id']
90 usort($ar, function($a, $b) {
91 $rdiff = $a['rightname'] - $b['rightname'];
92 if ($rdiff) return $rdiff;
93 return $a['descript'] - $b['descript'];
105 if (!isset($_POST['group_id']) || (int)$_POST['group_id'] < 0) {
106 $this->jerr("NO GROUP");
109 if (!$this->checkPerm('E')) { // editing groups..
110 $this->jerr("PERMISSION DENIED");
114 if (!empty($_POST['dataUpdate'])) {
115 foreach($_POST['dataUpdate'] as $id => $ac) {
117 $p = DB_DataObject::factory('core_group_right');
118 $p->group_id = (int)$_POST['group_id'];
120 $this->jerr("could not find gid:{$p->group_id} and $id");
121 continue; // errro cond.
124 $p->accessmask = $ac;
125 $p->validate(); // ensure that the basic perms can not be removed
129 if (!empty($_POST['dataAdd'])) {
130 foreach($_POST['dataAdd'] as $perm => $ac) {
131 $p = DB_DataObject::factory('core_group_right');
132 $p->group_id = (int)$_POST['group_id'];
133 $p->rightname = $perm;
134 $p->accessmask = $ac;
135 $p->validate(); // ensure that the basic perms can not be removed
145 function checkPerm($lvl)
147 return $this->hasPerm('Core.Groups', $lvl);