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 viewEditrole($eventData) { $role = new \Innomatic\Domain\User\Role((int) $eventData['id']); $formEventsCall = new WuiEventsCall(); $formEventsCall->addEvent(new WuiEvent('action', 'editrole', array('id' => $eventData['id']))); $formEventsCall->addEvent(new WuiEvent('view', 'roles', '')); $xml = '<vertgroup><children> <form><name>roledata</name> <args> <action>' . WuiXml::cdata($formEventsCall->getEventsCallString()) . '</action> </args> <children> <vertgroup><children> <vertgroup><children> <grid> <children> <label row="0" col="0"><args><label>' . WuiXml::cdata($this->localeCatalog->getStr('rolename_label')) . '</label></args></label> <string row="0" col="1"><name>name</name><args><disp>action</disp><value>' . WuiXml::cdata($role->getName()) . '</value><size>25</size></args></string> <label row="1" col="0"><args><label>' . WuiXml::cdata($this->localeCatalog->getStr('roledescription_label')) . '</label></args></label> <text row="1" col="1"><name>description</name><args><disp>action</disp><value>' . WuiXml::cdata($role->getDescription()) . '</value><rows>5</rows><cols>40</cols></args></text> </children> </grid> </children></vertgroup> </children></vertgroup> <horizbar /> <horizgroup><children> <button><name>save</name> <args> <themeimage>buttonok</themeimage> <label>' . WuiXml::cdata($this->localeCatalog->getStr('saverole_button')) . '</label> <action>' . WuiXml::cdata($formEventsCall->getEventsCallString()) . '</action> <formsubmit>roledata</formsubmit> <horiz>true</horiz> <frame>false</frame> </args> </button> </children></horizgroup> </children> </form> </children></vertgroup>'; $this->wuiMainframe->addChild(new WuiXml('user', array('definition' => $xml))); $this->wuiTitlebar->mTitle .= ' - ' . $userData['username'] . ' - ' . $this->localeCatalog->getStr('edituser_title'); }