3 * Table Definition for Group_Rights
5 require_once 'DB/DataObject.php';
8 class Pman_Core_DataObjects_Group_Rights extends DB_DataObject
11 /* the code below is auto generated do not remove the above tag */
13 public $__table = 'Group_Rights'; // table name
14 public $rightname; // string(64) not_null
15 public $group_id; // int(11) not_null
16 public $AccessMask; // string(10) not_null
17 public $id; // int(11) not_null primary_key auto_increment
20 /* the code above is auto generated do not remove the tag below */
24 var $fullRights = "ADESPIM";
26 function listPermsFromGroupIds($grps, $isAdmin=false) {
29 $t->whereAdd('group_id IN ('. implode(',', $grps).')');
33 if (isset($ret[$t->rightname])) {
34 $ret[$t->rightname] = $this->mergeMask($ret[$t->rightname], $t->AccessMask);
37 $ret[$t->rightname] = $t->AccessMask;
39 // blank out rights that are disabled by the system..
40 $defs = $this->defaultPermData();
41 //echo "<PRE>";print_r($defs);
43 foreach($defs as $k=>$v) {
44 if (empty($v[0])) { // delete right if not there..
50 if (isset($ret[$k])) {
51 if (empty($ret[$k]) && $isAdmin) {
59 // not set contition...
61 $r[$k] = $isAdmin ? $v[0] : $v[1];
68 function mergeMask($a, $b)
72 for($i=0; $i< strlen($this->fullRights) ; $i++) {
73 if ((strpos($a, $this->fullRights[$i]) > -1) ||
74 (strpos($b, $this->fullRights[$i]) > -1)
76 $ret .= $this->fullRights[$i];
85 function defaultPermData()
88 // we should do better caching of this... really..
104 static $Pman_DataObjects_Group_Right = array();
105 if (!empty($Pman_DataObjects_Group_Right)) {
106 return $Pman_DataObjects_Group_Right;
109 $ff = HTML_FlexyFramework::get();
111 $enabled = array('Core') ;
112 $enabled = explode(',', $ff->enable);
113 $disabled = explode(',', $ff->disable? $ff->disable: '');
114 $pman = $ff->rootDir . '/Pman/';
116 //echo '<PRE>';print_r($enabled);
117 foreach($enabled as $module) {
118 $fn = $pman. $module. '/'.$module. '.perms.json';
119 if (!file_exists($fn)) {
122 $ar = (array)json_decode(file_get_contents($fn));
124 // since these are critical files.. die'ing with error is ok.
125 die("invalid json file: " . $fn);
127 // echo '<PRE>';print_r($ar);
128 foreach($ar as $k=> $perm) {
130 continue; // it's a comment..
132 if (in_array($module, $disabled) || in_array($module.'.'. $k, $disabled)) {
135 $ret[$module.'.'. $k ] = $perm;
139 $Pman_DataObjects_Group_Right = $ret;
141 return $Pman_DataObjects_Group_Right;
146 function adminRights() // get the admin rights - used when no accounts are available..
148 $defs = $this->defaultPermData();
150 foreach($defs as $k=>$v) {
160 // all groups must have the minimum privaligess..
161 // admin group must have all the privaliges
162 $g = DB_DataObject::Factory('Groups');
163 $g->get($this->group_id);
164 $defs = $this->defaultPermData();
166 case "Administrators";
167 $this->AccessMask = $this->mergeMask($this->AccessMask, $defs[$this->rightname][0]);
171 $this->AccessMask = $this->mergeMask($this->AccessMask, $defs[$this->rightname][1]);
177 function genDefault()
179 // need to create to special groups, admin & DEFAULT.
180 $g = DB_DataObject::Factory('Groups');
181 //$g->name = 'Default';
182 //if (!$g->find(true)) {
186 $this->applyDefs($g, 1);
188 $g = DB_DataObject::Factory('Groups');
189 $g->name = 'Administrators';
190 if (!$g->find(true)) {
193 $this->applyDefs($g, 0);
198 function applyDefs($g, $usecol) {
200 $defs = $this->defaultPermData();
202 foreach($defs as $rightname => $defdata) {
203 $gr = DB_DataObject::Factory('Group_Rights');
204 $gr->rightname = $rightname;
205 $gr->group_id = $g->id;
206 if (!$gr->find(true)) {
207 $gr->AccessMask = $defdata[$usecol];
212 $gr->AccessMask = $gr->mergeMask($gr->AccessMask, $defdata[$usecol]);
213 if ($gr->AccesMask == $oldgr->AccesMask) {
221 function checkPerm($lvl, $au)