3 * Table Definition for Group_Rights
16 require_once 'DB/DataObject.php';
19 class Pman_Core_DataObjects_Group_rights extends DB_DataObject
22 /* the code below is auto generated do not remove the above tag */
24 public $__table = 'group_rights'; // table name
25 public $rightname; // string(64) not_null
26 public $group_id; // int(11) not_null
27 public $accessmask; // string(10) not_null
28 public $id; // int(11) not_null primary_key auto_increment
31 /* the code above is auto generated do not remove the tag below */
35 var $fullRights = "ADESPIM";
37 function listPermsFromGroupIds($grps, $isAdmin=false, $isOwner = false) {
40 $t->whereAdd('group_id IN ('. implode(',', $grps).')');
50 if (isset($ret[$t->rightname])) {
51 $ret[$t->rightname] = $this->mergeMask($ret[$t->rightname], $t->accessmask);
54 $ret[$t->rightname] = $t->accessmask;
56 // blank out rights that are disabled by the system..
57 $defs = $this->defaultPermData();
61 //echo "<PRE>";print_r($defs);
63 foreach($defs as $k=>$v) {
67 if (empty($v[0])) { // delete right if not there..
73 if (isset($ret[$k])) {
74 if (empty($ret[$k]) && $isAdmin) {
75 $r[$k] = $v[0] ; // -- it's admin they get rights... can not be disabled..
78 // in theory non-owners could sneak in rights here..??
82 // not set contition...
88 $r[$k] = $isAdmin ? $v[0] : $v[1];
95 function mergeMask($a, $b)
99 for($i=0; $i< strlen($this->fullRights) ; $i++) {
100 if ((strpos($a, $this->fullRights[$i]) > -1) ||
101 (strpos($b, $this->fullRights[$i]) > -1)
103 $ret .= $this->fullRights[$i];
112 function defaultPermData()
115 // we should do better caching of this... really..
125 // P - print / export
130 $gid = empty($this->group_id) ? 0 : $this->group_id;
131 static $Pman_DataObjects_Group_Right = array();
134 if (!empty($Pman_DataObjects_Group_Right[$gid])) {
135 return $Pman_DataObjects_Group_Right[$gid];
137 $has_admin = true; ///?? not sure..
139 $g = DB_DataObject::factory('groups');
140 $g->get($this->group_id);
141 $has_admin = $g->type == 2 ? false : true;
146 $ff = HTML_FlexyFramework::get();
148 $enabled = array('Core') ;
149 $enabled = explode(',', $ff->enable);
150 $disabled = explode(',', $ff->disable? $ff->disable: '');
151 $pman = $ff->rootDir . '/Pman/';
153 //echo '<PRE>';print_r($enabled);
154 foreach($enabled as $module) {
156 if (($module == 'Admin') && !$has_admin) {
160 $fn = $pman. $module. '/'.$module. '.perms.json';
161 if (!file_exists($fn)) {
164 $ar = (array)json_decode(file_get_contents($fn));
166 // since these are critical files.. die'ing with error is ok.
167 die("invalid json file: " . $fn);
169 // echo '<PRE>';print_r($ar);
170 foreach($ar as $k=> $perm) {
172 continue; // it's a comment..
174 if (in_array($module, $disabled) || in_array($module.'.'. $k, $disabled)) {
177 $ret[$module.'.'. $k ] = $perm;
181 $Pman_DataObjects_Group_Right[$gid] = $ret;
183 return $Pman_DataObjects_Group_Right[$gid];
188 function adminRights() // get the admin rights - used when no accounts are available..
190 $defs = $this->defaultPermData();
192 foreach($defs as $k=>$v) {
202 // all groups must have the minimum privaligess..
203 // admin group must have all the privaliges
204 $g = DB_DataObject::Factory('groups');
205 $g->get($this->group_id);
206 $defs = $this->defaultPermData();
208 case "Administrators";
209 $this->accessmask = $this->mergeMask($this->accessmask, $defs[$this->rightname][0]);
213 //$this->accessmask = $this->mergeMask($this->accessmask, $defs[$this->rightname][1]);
220 * generates the default admin group.
223 function genDefault()
225 // need to create to special groups, admin & DEFAULT.
226 $g = DB_DataObject::Factory('Groups');
227 //$g->name = 'Default';
228 //if (!$g->find(true)) {
232 $this->applyDefs($g, 1);
234 $g = DB_DataObject::Factory('Groups');
235 $g->name = 'Administrators';
237 if (!$g->find(true)) {
240 $this->applyDefs($g, 0);
245 function applyDefs($g, $usecol) {
247 $defs = $this->defaultPermData();
248 //echo '<PRE>';print_r($defs);
250 foreach($defs as $rightname => $defdata) {
251 $gr = DB_DataObject::Factory('group_rights');
252 $gr->rightname = $rightname;
253 $gr->group_id = $g->id;
254 if (!$gr->find(true)) {
255 $gr->accessmask = $defdata[$usecol];
260 $gr->accessmask = $gr->mergeMask($gr->accessmask, $defdata[$usecol]);
261 if ($gr->accessmask == $oldgr->accessmask) {
269 function checkPerm($lvl, $au)