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).')');
48 switch($only_public) {
50 $only_public = $t->group_id_type == 2 ? 1 : 0;
53 $only_public = $t->group_id_type == 2 ? $only_public : 0;
61 if (isset($ret[$t->rightname])) {
62 $ret[$t->rightname] = $this->mergeMask($ret[$t->rightname], $t->accessmask);
65 $ret[$t->rightname] = $t->accessmask;
67 // blank out rights that are disabled by the system..
68 $defs = $this->defaultPermData();
70 //echo "<PRE>";print_r($defs);
72 foreach($defs as $k=>$v) {
76 if (empty($v[0])) { // delete right if not there..
82 if (isset($ret[$k])) {
83 if (empty($ret[$k]) && $isAdmin) {
84 $r[$k] = $only_public ? '' : $v[0]; // if it's public, the get no default rights
91 // not set contition...
93 $r[$k] = $isAdmin ? $v[0] : $v[1];
100 function mergeMask($a, $b)
104 for($i=0; $i< strlen($this->fullRights) ; $i++) {
105 if ((strpos($a, $this->fullRights[$i]) > -1) ||
106 (strpos($b, $this->fullRights[$i]) > -1)
108 $ret .= $this->fullRights[$i];
117 function defaultPermData()
120 // we should do better caching of this... really..
130 // P - print / export
135 $gid = empty($this->group_id) ? 0 : $this->group_id;
136 static $Pman_DataObjects_Group_Right = array();
139 if (!empty($Pman_DataObjects_Group_Right[$gid])) {
140 return $Pman_DataObjects_Group_Right[$gid];
142 $has_admin = true; ///?? not sure..
144 $g = DB_DataObject::factory('groups');
145 $g->get($this->group_id);
146 $has_admin = $g->type == 2 ? false : true;
151 $ff = HTML_FlexyFramework::get();
153 $enabled = array('Core') ;
154 $enabled = explode(',', $ff->enable);
155 $disabled = explode(',', $ff->disable? $ff->disable: '');
156 $pman = $ff->rootDir . '/Pman/';
158 //echo '<PRE>';print_r($enabled);
159 foreach($enabled as $module) {
161 if (($module == 'Admin') && !$has_admin) {
165 $fn = $pman. $module. '/'.$module. '.perms.json';
166 if (!file_exists($fn)) {
169 $ar = (array)json_decode(file_get_contents($fn));
171 // since these are critical files.. die'ing with error is ok.
172 die("invalid json file: " . $fn);
174 // echo '<PRE>';print_r($ar);
175 foreach($ar as $k=> $perm) {
177 continue; // it's a comment..
179 if (in_array($module, $disabled) || in_array($module.'.'. $k, $disabled)) {
182 $ret[$module.'.'. $k ] = $perm;
186 $Pman_DataObjects_Group_Right[$gid] = $ret;
188 return $Pman_DataObjects_Group_Right[$gid];
193 function adminRights() // get the admin rights - used when no accounts are available..
195 $defs = $this->defaultPermData();
197 foreach($defs as $k=>$v) {
207 // all groups must have the minimum privaligess..
208 // admin group must have all the privaliges
209 $g = DB_DataObject::Factory('groups');
210 $g->get($this->group_id);
211 $defs = $this->defaultPermData();
213 case "Administrators";
214 $this->accessmask = $this->mergeMask($this->accessmask, $defs[$this->rightname][0]);
218 //$this->accessmask = $this->mergeMask($this->accessmask, $defs[$this->rightname][1]);
225 * generates the default admin group.
228 function genDefault()
230 // need to create to special groups, admin & DEFAULT.
231 $g = DB_DataObject::Factory('Groups');
232 //$g->name = 'Default';
233 //if (!$g->find(true)) {
237 $this->applyDefs($g, 1);
239 $g = DB_DataObject::Factory('Groups');
240 $g->name = 'Administrators';
242 if (!$g->find(true)) {
245 $this->applyDefs($g, 0);
250 function applyDefs($g, $usecol) {
252 $defs = $this->defaultPermData();
253 //echo '<PRE>';print_r($defs);
255 foreach($defs as $rightname => $defdata) {
256 $gr = DB_DataObject::Factory('group_rights');
257 $gr->rightname = $rightname;
258 $gr->group_id = $g->id;
259 if (!$gr->find(true)) {
260 $gr->accessmask = $defdata[$usecol];
265 $gr->accessmask = $gr->mergeMask($gr->accessmask, $defdata[$usecol]);
266 if ($gr->accessmask == $oldgr->accessmask) {
274 function checkPerm($lvl, $au)