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) {
40 $t->whereAdd('group_id IN ('. implode(',', $grps).')');
44 if (isset($ret[$t->rightname])) {
45 $ret[$t->rightname] = $this->mergeMask($ret[$t->rightname], $t->accessmask);
48 $ret[$t->rightname] = $t->accessmask;
50 // blank out rights that are disabled by the system..
51 $defs = $this->defaultPermData();
52 //echo "<PRE>";print_r($defs);
54 foreach($defs as $k=>$v) {
55 if (empty($v[0])) { // delete right if not there..
61 if (isset($ret[$k])) {
62 if (empty($ret[$k]) && $isAdmin) {
70 // not set contition...
72 $r[$k] = $isAdmin ? $v[0] : $v[1];
79 function mergeMask($a, $b)
83 for($i=0; $i< strlen($this->fullRights) ; $i++) {
84 if ((strpos($a, $this->fullRights[$i]) > -1) ||
85 (strpos($b, $this->fullRights[$i]) > -1)
87 $ret .= $this->fullRights[$i];
96 function defaultPermData()
99 // we should do better caching of this... really..
109 // P - print / export
115 static $Pman_DataObjects_Group_Right = array();
116 if (!empty($Pman_DataObjects_Group_Right)) {
117 return $Pman_DataObjects_Group_Right;
120 $ff = HTML_FlexyFramework::get();
122 $enabled = array('Core') ;
123 $enabled = explode(',', $ff->enable);
124 $disabled = explode(',', $ff->disable? $ff->disable: '');
125 $pman = $ff->rootDir . '/Pman/';
127 //echo '<PRE>';print_r($enabled);
128 foreach($enabled as $module) {
129 $fn = $pman. $module. '/'.$module. '.perms.json';
130 if (!file_exists($fn)) {
133 $ar = (array)json_decode(file_get_contents($fn));
135 // since these are critical files.. die'ing with error is ok.
136 die("invalid json file: " . $fn);
138 // echo '<PRE>';print_r($ar);
139 foreach($ar as $k=> $perm) {
141 continue; // it's a comment..
143 if (in_array($module, $disabled) || in_array($module.'.'. $k, $disabled)) {
146 $ret[$module.'.'. $k ] = $perm;
150 $Pman_DataObjects_Group_Right = $ret;
152 return $Pman_DataObjects_Group_Right;
157 function adminRights() // get the admin rights - used when no accounts are available..
159 $defs = $this->defaultPermData();
161 foreach($defs as $k=>$v) {
171 // all groups must have the minimum privaligess..
172 // admin group must have all the privaliges
173 $g = DB_DataObject::Factory('Groups');
174 $g->get($this->group_id);
175 $defs = $this->defaultPermData();
177 case "Administrators";
178 $this->accessmask = $this->mergeMask($this->accessmask, $defs[$this->rightname][0]);
182 //$this->accessmask = $this->mergeMask($this->accessmask, $defs[$this->rightname][1]);
189 * generates the default admin group.
192 function genDefault()
194 // need to create to special groups, admin & DEFAULT.
195 $g = DB_DataObject::Factory('Groups');
196 //$g->name = 'Default';
197 //if (!$g->find(true)) {
201 $this->applyDefs($g, 1);
203 $g = DB_DataObject::Factory('Groups');
204 $g->name = 'Administrators';
206 if (!$g->find(true)) {
209 $this->applyDefs($g, 0);
214 function applyDefs($g, $usecol) {
216 $defs = $this->defaultPermData();
217 //echo '<PRE>';print_r($defs);
219 foreach($defs as $rightname => $defdata) {
220 $gr = DB_DataObject::Factory('Group_Rights');
221 $gr->rightname = $rightname;
222 $gr->group_id = $g->id;
223 if (!$gr->find(true)) {
224 $gr->accessmask = $defdata[$usecol];
229 $gr->accessmask = $gr->mergeMask($gr->accessmask, $defdata[$usecol]);
230 if ($gr->accessmask == $oldgr->accessmask) {
238 function checkPerm($lvl, $au)