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 = dirname(__FILE__).'/../../';
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));
123 // echo '<PRE>';print_r($ar);
124 foreach($ar as $k=> $perm) {
126 continue; // it's a comment..
128 if (in_array($module, $disabled) || in_array($module.'.'. $k, $disabled)) {
131 $ret[$module.'.'. $k ] = $perm;
135 $Pman_DataObjects_Group_Right = $ret;
137 return $Pman_DataObjects_Group_Right;
142 function adminRights() // get the admin rights - used when no accounts are available..
144 $defs = $this->defaultPermData();
146 foreach($defs as $k=>$v) {
156 // all groups must have the minimum privaligess..
157 // admin group must have all the privaliges
158 $g = DB_DataObject::Factory('Groups');
159 $g->get($this->group_id);
160 $defs = $this->defaultPermData();
162 case "Administrators";
163 $this->AccessMask = $this->mergeMask($this->AccessMask, $defs[$this->rightname][0]);
167 $this->AccessMask = $this->mergeMask($this->AccessMask, $defs[$this->rightname][1]);
173 function genDefault()
175 // need to create to special groups, admin & DEFAULT.
176 $g = DB_DataObject::Factory('Groups');
177 //$g->name = 'Default';
178 //if (!$g->find(true)) {
182 $this->applyDefs($g, 1);
184 $g = DB_DataObject::Factory('Groups');
185 $g->name = 'Administrators';
186 if (!$g->find(true)) {
189 $this->applyDefs($g, 0);
194 function applyDefs($g, $usecol) {
196 $defs = $this->defaultPermData();
198 foreach($defs as $rightname => $defdata) {
199 $gr = DB_DataObject::Factory('Group_Rights');
200 $gr->rightname = $rightname;
201 $gr->group_id = $g->id;
202 if (!$gr->find(true)) {
203 $gr->AccessMask = $defdata[$usecol];
208 $gr->AccessMask = $gr->mergeMask($gr->AccessMask, $defdata[$usecol]);
209 if ($gr->AccesMask == $oldgr->AccesMask) {
217 function checkPerm($lvl, $au)