function createPermissions($meta, $moduleId) { $permData = $meta->permissions; if (empty($permData)) { return; } foreach ($permData as $key => $val) { if (!empty($val)) { foreach ($val as $permissionString => $defaultValue) { $permissionObj = new Permission(); $permissionObj->Load("user_level = ? and module_id = ? and permission = ?", array($key, $moduleId, $permissionString)); if (empty($permissionObj->id) && $permissionObj->module_id == $moduleId) { } else { $permissionObj = new Permission(); $permissionObj->user_level = $key; $permissionObj->module_id = $moduleId; $permissionObj->permission = $permissionString; $permissionObj->value = $defaultValue; $permissionObj->meta = '["value", {"label":"Value","type":"select","source":[["Yes","Yes"],["No","No"]]}]'; $permissionObj->Save(); } } } } }
<?php require_once "../../lib/init.php"; protectPage(9); @($id = DB::Safe($_GET['id'])); // Verify... if (!$id) { fail("Could not delete permission; please specify a valid ID."); } // Load the permission and make sure it belongs in the ward $p = Permission::Load($id); if (!$p->InWard($MEMBER->WardID)) { fail("That permission is not within your own ward..."); } // Delete this permission. $p->Delete(true); Response::Send(200);
public function Permissions($removeOverlap = false) { $permissions = array(); // Get permissions based on member ID... // Be careful changing this because we append later! $q = "SELECT ID FROM Permissions WHERE (ObjectID='{$this->ID}' AND ObjectType='Member') OR ("; // Now permissions based on callings for this member $callings = $this->Callings(); foreach ($callings as $calling) { $q .= "ObjectID=" . $calling->ID() . " OR "; } // Trim the trailing OR bit... if (strrpos('(', $q) == strlen($q) - 1) { $q = substr($q, 0, strlen($q) - 5); } else { $q = substr($q, 0, strlen($q) - 4); } if (count($callings) > 0) { $q .= " AND ObjectType='Calling')"; } // don't forget this $r = DB::Run($q); while ($row = mysql_fetch_array($r)) { $per = Permission::Load($row['ID']); // Prevent duplicates questions/overlap of permissions? if ($removeOverlap) { $found = false; foreach ($permissions as $p) { if ($p->QuestionID() == $per->QuestionID()) { $found = true; break; } } if ($found) { continue; } } $permissions[] = $per; } return $permissions; }