public function parse() { global $CORE, $_BACKEND, $AUTH; ob_start(); $map = req('map'); if (!$map || count($CORE->getAvailableMaps('/^' . $map . '$/')) == 0) { throw new NagVisException(l('Please provide a valid map name.')); } $object_id = req('object_id'); if (!$object_id || !preg_match(MATCH_OBJECTID, $object_id)) { throw new NagVisException(l('Please provide a valid object id.')); } $MAPCFG = new GlobalMapCfg($map); $MAPCFG->skipSourceErrors(); $MAPCFG->readMapConfig(); if (!$MAPCFG->objExists($object_id)) { throw new NagVisException(l('The object does not exist.')); } $backendIds = $MAPCFG->getValue($object_id, 'backend_id'); foreach ($backendIds as $backendId) { if (!$_BACKEND->checkBackendFeature($backendId, 'actionAcknowledge', false)) { return '<div class=err>' . l('The requested feature is not available for this backend. ' . 'The MKLivestatus backend supports this feature.') . '</div>'; } } if (is_action()) { try { $type = $MAPCFG->getValue($object_id, 'type'); if ($type == 'host') { $spec = $MAPCFG->getValue($object_id, 'host_name'); } else { $spec = $MAPCFG->getValue($object_id, 'host_name') . ';' . $MAPCFG->getValue($object_id, 'service_description'); } $comment = post('comment'); if (!$comment) { throw new FieldInputError('comment', l('You need to provide a comment.')); } $sticky = get_checkbox('sticky'); $notify = get_checkbox('notify'); $persist = get_checkbox('persist'); // Now send the acknowledgement foreach ($backendIds as $backendId) { $BACKEND = $_BACKEND->getBackend($backendId); $BACKEND->actionAcknowledge($type, $spec, $comment, $sticky, $notify, $persist, $AUTH->getUser()); } success(l('The problem has been acknowledged.')); js('window.setTimeout(function() {' . 'popupWindowClose(); refreshMapObject(null, \'' . $object_id . '\');}, 2000);'); } 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('acknowledge'); echo '<label>' . l('Comment'); input('comment'); echo '</label>'; echo '<label>'; checkbox('sticky', cfg('global', 'dialog_ack_sticky')); echo l('Sticky') . '</label>'; echo '<label>'; checkbox('notify', cfg('global', 'dialog_ack_notify')); echo l('Notify contacts') . '</label>'; echo '<label>'; checkbox('persist', cfg('global', 'dialog_ack_persist')); echo l('Persist comment') . '</label>'; submit(l('Acknowledge')); form_end(); focus('comment'); return ob_get_clean(); }
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; }
function sql_format_options_table($export) { global $dt_strings; return ' <table class="table table-bordered"> <tr> <th align="left" colspan="2">' . $dt_strings['SqlOpts'] . '</th> </tr> <tr> <td> <table class="table table-bordered"> <tr> <td> ' . $dt_strings['SqlCNames'] . ' </td> <td> ' . get_checkbox('dt_export_sql_cnames', '1', $export['sql']['cnames']) . ' </td> </tr> <tr> <td> ' . $dt_strings['SqlQNames'] . ' </td> <td> ' . get_checkbox('dt_export_sql_qnames', '1', $export['sql']['qnames']) . ' </td> </tr> <tr> <td> ' . $dt_strings['SqlCField'] . ' </td> <td> ' . get_checkbox('dt_export_sql_cfields', '1', $export['sql']['cfields']) . ' </td> </tr> <tr> <td> ' . $dt_strings['SqlInfo'] . ' </td> <td> ' . get_checkbox('dt_export_sql_info', '1', $export['sql']['info']) . ' </td> </tr> <tr> <td> ' . $dt_strings['SqlLE'] . ' </td> <td> ' . get_textfield('dt_export_sql_lineend', 2, 5, $export['sql']['lineend']) . ' </td> </tr> <tr> <td> ' . $dt_strings['SqlTTab'] . ' </td> <td> ' . get_textfield('dt_export_sql_ttable', 15, 31, $export['sql']['ttable']) . ' </td> </tr> </table> </td> </tr> </table>'; }
function field($type, $name, $default = '', $class = '', $onclick = '', $style = '', $id = null) { global $form_errors, $form_keys, $form_name; $form_keys[$name] = true; if (submitted($form_name) && isset($form_errors[$name])) { $class .= ' err'; } if (trim($class)) { $class = ' class="' . trim($class) . '"'; } if (submitted($form_name)) { if ($type == 'checkbox') { $default = get_checkbox($name, $default); } else { $default = post($name, $default); } } $value = ''; if ($default != '') { if ($type == 'checkbox') { if ($default === true) { $value = ' value="1" checked="yes"'; } else { $value = ' value="1"'; } } else { $value = ' value="' . escape_html($default) . '"'; } } if ($onclick != '') { $onclick = ' onclick="' . $onclick . '"'; } if ($style != '') { $style = ' style="' . $style . '"'; } if ($id === null) { $id = $name; } echo '<input id="' . $id . '" type="' . $type . '" name="' . $name . '"' . $value . $class . $onclick . $style . ' />' . N; }
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(); }
// published under the terms of the GNU General Public Licence v.2, // see file LICENCE for details $tcnt = 0; if ($s_connected == TRUE && is_array($s_tables)) { foreach ($s_tables as $tablename => $properties) { if ($properties['is_view'] == TRUE) { continue; } $tcnt++; $title = $tablename; if ($s_tables_counts == TRUE && isset($properties['count'])) { $title .= ' [' . $properties['count'] . ']'; } $fold_url = fold_detail_url('table', $properties['status'], $tablename, $title); $comment_url = "javascript:requestCommentArea('table', '" . $tablename . "');"; echo ' <div id="' . 't_' . $tablename . "\" class=\"det\">\n"; if ($properties['status'] == 'open') { echo get_opened_table($tablename, $title, $fold_url, $comment_url, 'tc_' . $tablename); } else { // $properties['status'] == 'close' echo get_closed_detail($title, $fold_url, $comment_url, 'tc_' . $tablename); } echo " </div>\n"; } // foreach $s_tables echo '<form method="post" action="' . url_session($_SERVER['PHP_SELF']) . "#tb_show\" name=\"tb_show_form\">\n" . get_checkbox('tb_show_counts', '1', $s_tables_counts) . ' ' . $tb_strings['DispCounts'] . " \n" . get_checkbox('tb_show_cnames', '1', $s_tables_cnames) . ' ' . $tb_strings['DispCNames'] . " \n" . get_checkbox('tb_show_def', '1', $s_tables_def) . ' ' . $tb_strings['DispDef'] . " \n" . get_checkbox('tb_show_comp', '1', $s_tables_comp) . ' ' . $tb_strings['DispComp'] . " \n" . get_checkbox('tb_show_comments', '1', $s_tables_comment) . ' ' . $tb_strings['DispComm'] . "<br />\n" . ' <input type="submit" name="tb_show_reload" value="' . $button_strings['Reload'] . "\" class=\"bgrp\">\n"; if ($tcnt > 1) { echo ' <input type="submit" name="tb_table_open" value="' . $button_strings['OpenAll'] . "\" class=\"bgrp\">\n" . ' <input type="submit" name="tb_table_close" value="' . $button_strings['CloseAll'] . "\" class=\"bgrp\">\n"; } echo "</form>\n"; }
/** * <pre>skip_checkbox( $name, $value, $elements, $args );</pre> * * Adding a checkbox field. * * <b>Default Usage</b> * <code> * skip_checkbox( 'overeighteen', 'yes' ); * </code> * This will create an automated saved checkbox field. * * <b>Parameters</b> * * <code> * $name // (string) (required) The name of the field. * $value // (string) (required) The value of the checkbox element which will be saved if box is checked. * $args // (array/string) (optional) Values for further settings. * </code> * * <b>$args Settings</b> * * <ul> * <li>id (string) ID if the HTML Element.</li> * <li>label (string) Label for Element.</li> * <li>default (string) Default Value if no Value is set before ('checked' if value have to be checked on default).</li> * <li>classes (string) Name of CSS Classes which will be inserted into HTML seperated by empty space.</li> * <li>before_element (string) Content before the element.</li> * <li>after_element (string) Content after the element.</li> * <li>save (boolean) TRUE if value of field have to be saved in Database, FALSE if not (default TRUE).</li> * </ul> * * <b>Example</b> * * Creating a labeled Checkbox in an automatic saved form. * <code> * skip_form_start( 'myformname' ); * * $args = array( * 'id' = 'myelementid', * 'label' => 'City' * ); * skip_autocomplete( 'overeighteen', 'yes', $args ); * * skip_form_end(); * </code> * * Getting back the saved data. * <code> * $city = skip_value( 'myformname', 'overeighteen' ); * </code> * @package Skip\Forms * @since 1.0 * @param string $name The name of the checkbox field. * @param string $value The value of the checkbox element which will be saved if box is checked. * @param array/string $args List of Arguments. */ function checkbox($name, $value, $label = FALSE, $args = array()) { echo get_checkbox($name, $value, $label, $args); }