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();
118 if (!empty($Pman_DataObjects_Group_Right[$this->group_id])) {
119 return $Pman_DataObjects_Group_Right[$this->group_id];
122 $g = DB_DataObject::factory('groups');
123 $g->get($this->group_id);
124 $has_admin = $g->type == 2 ? false : true;
127 $ff = HTML_FlexyFramework::get();
129 $enabled = array('Core') ;
130 $enabled = explode(',', $ff->enable);
131 $disabled = explode(',', $ff->disable? $ff->disable: '');
132 $pman = $ff->rootDir . '/Pman/';
134 //echo '<PRE>';print_r($enabled);
135 foreach($enabled as $module) {
137 if (($module == 'Admin') && !$has_admin) {
141 $fn = $pman. $module. '/'.$module. '.perms.json';
142 if (!file_exists($fn)) {
145 $ar = (array)json_decode(file_get_contents($fn));
147 // since these are critical files.. die'ing with error is ok.
148 die("invalid json file: " . $fn);
150 // echo '<PRE>';print_r($ar);
151 foreach($ar as $k=> $perm) {
153 continue; // it's a comment..
155 if (in_array($module, $disabled) || in_array($module.'.'. $k, $disabled)) {
158 $ret[$module.'.'. $k ] = $perm;
162 $Pman_DataObjects_Group_Right[$this->group_id] = $ret;
164 return $Pman_DataObjects_Group_Right[$this->group_id];
169 function adminRights() // get the admin rights - used when no accounts are available..
171 $defs = $this->defaultPermData();
173 foreach($defs as $k=>$v) {
183 // all groups must have the minimum privaligess..
184 // admin group must have all the privaliges
185 $g = DB_DataObject::Factory('groups');
186 $g->get($this->group_id);
187 $defs = $this->defaultPermData();
189 case "Administrators";
190 $this->accessmask = $this->mergeMask($this->accessmask, $defs[$this->rightname][0]);
194 //$this->accessmask = $this->mergeMask($this->accessmask, $defs[$this->rightname][1]);
201 * generates the default admin group.
204 function genDefault()
206 // need to create to special groups, admin & DEFAULT.
207 $g = DB_DataObject::Factory('Groups');
208 //$g->name = 'Default';
209 //if (!$g->find(true)) {
213 $this->applyDefs($g, 1);
215 $g = DB_DataObject::Factory('Groups');
216 $g->name = 'Administrators';
218 if (!$g->find(true)) {
221 $this->applyDefs($g, 0);
226 function applyDefs($g, $usecol) {
228 $defs = $this->defaultPermData();
229 //echo '<PRE>';print_r($defs);
231 foreach($defs as $rightname => $defdata) {
232 $gr = DB_DataObject::Factory('group_rights');
233 $gr->rightname = $rightname;
234 $gr->group_id = $g->id;
235 if (!$gr->find(true)) {
236 $gr->accessmask = $defdata[$usecol];
241 $gr->accessmask = $gr->mergeMask($gr->accessmask, $defdata[$usecol]);
242 if ($gr->accessmask == $oldgr->accessmask) {
250 function checkPerm($lvl, $au)