private function handleAddModify() { $perm = get_checkbox('perm'); $perm_user = get_checkbox('perm_user'); $show_dialog = false; // Modification/Creation? // The object_id is known on modification. When it is not known 'type' is set // to create new objects if ($this->object_id !== null) { // The handler has been called in "view_params" mode. In this case the user has // less options and the options to // 1. modify these parameters only for the current open view // 2. Save the changes for himselfs // 3. Save the changes to the map config (-> Use default code below) if ($this->mode == 'view_params' && !$perm && !$perm_user) { // This is the 1. case -> redirect the user to a well formated url $attrs = array_merge($this->attrs, $this->attrs_filtered); unset($attrs['object_id']); js('document.getElementById("_submit").disabled = true;' . 'window.location.href = makeuri(' . json_encode($attrs) . ');'); $show_dialog = true; } elseif ($this->mode == 'view_params' && !$perm && $perm_user) { // This is the 2. case -> saving the options only for the user $USERCFG = new CoreUserCfg(); $attrs = $this->attrs; unset($attrs['object_id']); $USERCFG->doSet(array('params-' . $this->MAPCFG->getName() => $attrs)); scroll_up(); // On success, always scroll to top of page success(l('Personal settings saved.')); js('document.getElementById("_submit").disabled = true;' . 'window.setTimeout(function() { window.location.reload(); }, 2000);'); $show_dialog = true; } else { if (!$this->MAPCFG->objExists($this->object_id)) { throw new NagVisException(l('The object does not exist.')); } $this->validateAttributes(); // Update the map configuration if ($this->mode == 'view_params') { // Only modify/add the given attributes. Don't remove any // set options in the array foreach ($this->attrs as $key => $val) { $this->MAPCFG->setValue($this->object_id, $key, $val); } $this->MAPCFG->storeUpdateElement($this->object_id); } else { // add/modify case: Rewrite whole object with the given attributes $this->MAPCFG->updateElement($this->object_id, $this->attrs, true); } $t = $this->object_type == 'global' ? l('map configuration') : $this->object_type; $result = array(2, null, l('The [TYPE] has been modified. Reloading in 2 seconds.', array('TYPE' => $t))); js('popupWindowClose();' . 'refreshMapObject(null, "' . $this->object_id . '", false);'); } } else { // Create the new object $this->validateAttributes(); // append a new object definition to the map configuration $obj_id = $this->MAPCFG->addElement($this->object_type, $this->attrs, true); js('popupWindowClose();' . 'refreshMapObject(null, "' . $obj_id . '", false);'); } // delete map lock if (!$this->MAPCFG->deleteMapLock()) { throw new NagVisException(l('mapLockNotDeleted')); } return $show_dialog; }
private function modifyForm() { global $AUTHORISATION; echo '<h2>' . l('Modify Role') . '</h2>'; $role_id = submitted('edit') ? post('role_id') : null; if (is_action() && post('mode') == 'edit') { try { if ($role_id === null || $role_id === '') { throw new FieldInputError('role_id', l('Please choose a role to edit.')); } if (!is_numeric($role_id)) { throw new FieldInputError('role_id', l('Invalid value provided.')); } $role_id = intval($role_id); $found = false; foreach ($AUTHORISATION->getAllRoles() as $role) { if ($role['roleId'] == $role_id) { $found = true; } } if (!$found) { throw new NagVisException('Invalid role id provided'); } // Load permissions from parameters $perms = array(); foreach (array_keys($_POST) as $key) { if (strpos($key, 'perm_') !== false) { $key_parts = explode('_', $key); $perm_id = $key_parts[1]; $perms[$perm_id] = get_checkbox($key); } } scroll_up(); // On success, always scroll to top of page if ($AUTHORISATION->updateRolePerms($role_id, $perms)) { success(l('The permissions for this role have been updated.')); } else { throw new NagVisException(l('Problem while updating role permissions.')); } } catch (FieldInputError $e) { form_error($e->field, $e->msg); } catch (NagVisException $e) { form_error(null, $e->message()); } catch (Exception $e) { if (isset($e->msg)) { form_error(null, $e->msg); } else { throw $e; } } } echo $this->error; js_form_start('edit'); hidden('mode', 'edit'); echo '<table class="mytable">'; echo '<tr><td class="tdlabel">' . l('Select Role') . '</td>'; echo '<td class="tdfield">'; $choices = array('' => l('Please choose')); foreach ($AUTHORISATION->getAllRoles() as $role) { $choices[$role['roleId']] = $role['name']; } select('role_id', $choices, '', 'updateForm(this.form)'); echo '</td></tr>'; echo '</table>'; $this->renderPermissions($role_id); submit(l('Save')); form_end(); }