public static function getRolesPermissionsXml() { $localeCatalog = new \Innomatic\Locale\LocaleCatalog('innomatic::domain_profiles', \Innomatic\Core\InnomaticContainer::instance('\\Innomatic\\Core\\InnomaticContainer')->getCurrentUser()->getLanguage()); $rolesList = \Innomatic\Domain\User\Role::getAllRoles(); $rolesCount = count($rolesList); // Build roles/permissions matrix $rolesPermissions = array(); foreach ($rolesList as $roleId => $roleData) { $role = new \Innomatic\Domain\User\Role($roleId); $rolesPermissions[$roleId] = $role->getPermissions(); } $permissionsList = \Innomatic\Domain\User\Permission::getAllPermissions(); // Build table headers $headers = array(); $headerCounter = 1; foreach ($rolesList as $roleId => $roleData) { $headers[$headerCounter++]['label'] = $roleData['title']; } $xml = '<vertgroup><children> <table> <args> <headers type="array">' . WuiXml::encode($headers) . '</headers> </args> <children>'; $row = 0; $prevApplication = ''; foreach ($permissionsList as $permId => $permData) { if ($permData['application'] != $prevApplication) { $xml .= '<label row="' . $row++ . '" col="0" halign="left" valign="middle" nowrap="false" width="" colspan="' . ($rolesCount + 1) . '"><args><label>' . WuiXml::cdata($permData['application']) . '</label><bold>true</bold></args></label>'; } $xml .= '<label row="' . $row . '" col="0" halign="left" valign="middle"><args><label>' . WuiXml::cdata($permData['title']) . '</label><nowrap>false</nowrap></args></label>'; $col = 1; foreach ($rolesList as $roleId => $roleData) { if (isset($rolesPermissions[$roleId][$permId])) { $checked = 'true'; } else { $checked = 'false'; } $xml .= '<checkbox row="' . $row . '" col="' . $col++ . '" halign="center" valign="middle"><name>rolepermissioncb</name><args><id>cbrole_' . $roleId . '-' . $permId . '</id><checked>' . $checked . '</checked></args></checkbox>'; } $prevApplication = $permData['application']; $row++; } $xml .= '</children> </table> <horizbar/> <button><name>save</name> <args><themeimage>buttonok</themeimage><label>' . WuiXml::cdata($localeCatalog->getStr('save_roles_permissions_button')) . '</label><action>javascript:void(0)</action><horiz>true</horiz><frame>false</frame></args> <events> <click>' . WuiXml::cdata("\nvar checkboxes = document.getElementsByName('wui[][evd][rolepermissioncb]');\nvar vals = '';\nfor (var i=0, n=checkboxes.length;i<n;i++) {\n if (checkboxes[i].checked) vals += ','+checkboxes[i].id;\n}\nif (vals) vals = vals.substring(1);\n \t\t\t\nxajax_SaveRolesPermissions(vals);") . '</click> </events></button> </children></vertgroup>'; return $xml; }
public function doUpdateDomainAction($domainid, $params) { $role = new \Innomatic\Domain\User\Role(\Innomatic\Domain\User\Role::getIdFromName($params['name'])); return $role->setTitle($params['title'])->setDescription($params['description'])->setCatalog($params['catalog'])->setApplication($this->appname)->store(); }
public static function ajaxSaveRolesPermissions($permissions) { // Build list of checked roles/permissions $permissions = explode(',', $permissions); $checkedPermissions = array(); foreach ($permissions as $id => $permission) { $permission = str_replace('cbrole_', '', $permission); list($roleId, $permissionId) = explode('-', $permission); $checkedPermissions[$roleId][$permissionId] = true; } // Get list of all roles and permissions $rolesList = \Innomatic\Domain\User\Role::getAllRoles(); $permissionsList = \Innomatic\Domain\User\Permission::getAllPermissions(); // Check which permissions have been checked foreach ($rolesList as $roleId => $roleData) { $role = new \Innomatic\Domain\User\Role($roleId); foreach ($permissionsList as $permissionId => $permissionData) { if (isset($checkedPermissions[$roleId][$permissionId])) { $role->assignPermission($permissionId); } else { $role->unassignPermission($permissionId); } } } $html = WuiXml::getContentFromXml('', \ProfilesPanelController::getRolesPermissionsXml()); $objResponse = new XajaxResponse(); $objResponse->addAssign("roleslist", "innerHTML", $html); return $objResponse; }
public function viewRoles($eventData) { $roles = \Innomatic\Domain\User\Role::getAllRoles(); $row = 0; $headers[0]['label'] = $this->localeCatalog->getStr('rolename_header'); $headers[1]['label'] = $this->localeCatalog->getStr('roledescription_header'); $xml = '<table><args><headers type="array">' . WuiXml::encode($headers) . '</headers></args><children>'; foreach ($roles as $roleId => $roleData) { $toolsArray = array(); // Roles defined by applications are not editable if (!strlen($roleData['application'])) { $toolsArray['edit'] = array('label' => $this->localeCatalog->getStr('editrole_button'), 'themeimage' => 'pencil', 'horiz' => 'true', 'action' => \Innomatic\Wui\Dispatch\WuiEventsCall::buildEventsCallString('', array(array('view', 'editrole', array('id' => $roleId))))); } $toolsArray['trash'] = array('label' => $this->localeCatalog->getStr('removerole_button'), 'themeimage' => 'trash', 'horiz' => 'true', 'needconfirm' => 'true', 'confirmmessage' => $this->localeCatalog->getStr('removerole_confirm'), 'action' => \Innomatic\Wui\Dispatch\WuiEventsCall::buildEventsCallString('', array(array('view', 'roles'), array('action', 'removerole', array('id' => $roleId))))); $xml .= '<label row="' . $row . '" col="0"><args><label>' . WuiXml::cdata($roleData['title']) . '</label></args></label> <label row="' . $row . '" col="1"><args><label>' . WuiXml::cdata($roleData['description']) . '</label><nowrap>false</nowrap></args></label> <innomatictoolbar row="' . $row . '" col="2"><name>tools</name> <args> <frame>false</frame> <toolbars type="array">' . WuiXml::encode(array('view' => $toolsArray)) . '</toolbars> </args> </innomatictoolbar>'; $row++; } $xml .= '</children></table>'; $this->wuiMainframe->addChild(new WuiXml('newrole', array('definition' => $xml))); }
/** * Removes a previously assigned role. * * @param integer|string $role Role identifier number or string, * it gets automatically decoded to the identifier number. * @access public * @return boolean */ public function unassignRole($role) { if (!is_int($this->id)) { return false; } // If the role has been given by name, get its id if (!is_int($role)) { $role = Role::getIdFromName($role); if ($role === false) { return false; } } return $this->dataAccess->execute("DELETE\n FROM domain_roles_permissions\n WHERE roleid={$role} and permissionid={$this->id}"); }