function edit_process($form_data) { global $conn, $id; $resp = new xajaxResponse(); ossim_valid($form_data['bp_name'], OSS_INPUT, 'illegal:' . _("Name")); ossim_valid($form_data['bp_desc'], OSS_TEXT, 'illegal:' . _("Description")); if (ossim_error()) { $resp->AddAssign("form_errors", "innerHTML", ossim_error()); } else { // Check if there is already a BP with that name $sql = "SELECT name FROM bp_process WHERE name=?"; if ($id != 0) { $sql .= " AND id <> {$id}"; } $params = array($form_data['bp_name']); if (!($rs = $conn->Execute($sql, $params))) { $resp->AddAssign("form_errors", "innerHTML", $conn->ErrorMsg()); return $resp; } elseif (!$rs->EOF) { $resp->AddAssign("form_errors", "innerHTML", ossim_error(_("There is already a process with that name"))); return $resp; } if ($id == 0) { $sql = "INSERT INTO bp_process (id, name, description) VALUES (?, ?, ?)"; $id = $conn->GenID('bp_seq'); $params = array($id, $form_data['bp_name'], $form_data['bp_desc']); if (!$conn->Execute($sql, $params)) { $resp->AddAssign("form_errors", "innerHTML", $conn->ErrorMsg()); } else { $resp->addRedirect($_SERVER['SCRIPT_NAME'] . "?id={$id}"); } } else { $sql = "UPDATE bp_process SET name=?, description=? WHERE id=?"; $params = array($form_data['bp_name'], $form_data['bp_desc'], $id); if (!$conn->Execute($sql, $params)) { $resp->AddAssign("form_errors", "innerHTML", $conn->ErrorMsg()); } else { $resp->addRedirect("./bp_list.php"); } } } return $resp; }
function search_assets($form_data) { global $conn, $can_edit; $resp = new xajaxResponse(); //xajax_debug($form_data, $resp); // Build SQL from Form data $proc_id = $form_data['proc_id']; $asset_name = $form_data['asset_name']; $where = array(); if ($proc_id == 'none') { $where[] = "proc.id IS NULL"; } elseif ($proc_id != 'all') { $where[] = "proc.id=" . $conn->qstr($proc_id, get_magic_quotes_gpc()); } if ($asset_name) { // qstr doesn't seem to quote right if you introduce "\" in the search form //$esc = substr($conn->qstr($asset_name, get_magic_quotes_gpc()), 1, -1); // XXX too mysql dependant (maybe not so important as Ossim already if very mysql dependant) $esc = mysql_real_escape_string($asset_name); $where[] = "asset.name LIKE '%{$esc}%'"; } if (count($where)) { $w = 'WHERE ' . implode(' AND ', $where); } else { $w = ''; } $sql = "\n SELECT \n asset.id as asset_id,\n asset.name as asset_name,\n asset.description as asset_description,\n proc.id as proc_id,\n proc.name as proc_name,\n proc.description AS proc_description\n FROM\n bp_asset AS asset\n LEFT JOIN bp_process_asset_reference AS ref ON asset.id = ref.asset_id\n LEFT JOIN bp_process AS proc ON ref.process_id = proc.id\n {$w}\n ORDER BY asset.name"; if (!($rs = $conn->Execute($sql))) { die($conn->ErrorMsg()); } $assets = $procs = $asset_ref = array(); while (!$rs->EOF) { $aid = $rs->fields['asset_id']; $pid = $rs->fields['proc_id']; if (!empty($pid)) { $asset_ref[$aid][] = $pid; $procs[$rs->fields['proc_id']] = $rs->fields['proc_name']; } if (!isset($assets[$aid])) { $assets[$aid] = $rs->fields; } $rs->MoveNext(); } // No results found if (!count($assets)) { $resp->AddAssign("search-results", "innerHTML", '<center><i>' . _("No results found") . '</i></center>'); return $resp; } // Print the results in HTML $html = '<table width="60%" align="center"> <tr> <th>' . _("Asset Name") . '</th> <th>' . _("Belongs to") . '</th>'; if ($can_edit) { $html .= '<th>' . _("Actions") . '</th>'; } $html .= '</tr>'; foreach ($assets as $aid => $a) { $html .= '<tr> <td>' . $a['asset_name'] . '</td> <td style="text-align: left">'; if (isset($asset_ref[$aid])) { $html .= '<ul>'; foreach ($asset_ref[$aid] as $pid) { $html .= '<li>' . $procs[$pid] . '</li>'; } $html .= '</ul>'; } else { $html .= ' '; } $html .= '</td>'; if ($can_edit) { $html .= '<td><a href="./asset_edit.php?id=' . $a['asset_id'] . '">(' . _("edit") . ')</a> '; $html .= '<a href="#" onClick="javascript: xajax_delete_asset(' . $a['asset_id'] . ', xajax.getFormValues(\'search\')); return false;">(' . _("delete") . ')</a></td>'; } $html .= '</tr>'; } $html .= '</table>'; $resp->AddAssign("search-results", "innerHTML", $html); return $resp; }
function draw_members_select($form_data) { global $conn, $id; $resp = new xajaxResponse(); $type = $form_data['member_type']; // The user selected the empty type if (!$type) { $resp->AddAssign("members_select", "innerHTML", _("Please select a type")); return $resp; } // // Get the list of members of the given type // $options = array(); switch ($type) { case 'host': include_once 'classes/Host.inc'; $list = Host::get_list($conn, "", 'ORDER BY hostname'); print_r($list); foreach ($list as $obj) { $descr = $obj->get_descr(); if (strlen($descr) > 50) { $descr = substr($descr, 0, 47) . '...'; } $options[$obj->get_ip()] = $obj->get_hostname() . ' ' . $obj->get_ip() . ' - ' . $descr; } break; case 'net': include_once 'classes/Net.inc'; $list = Net::get_list($conn, "", 'ORDER BY name'); foreach ($list as $obj) { $descr = $obj->get_descr(); if (strlen($descr) > 50) { $descr = substr($descr, 0, 47) . '...'; } $options[$obj->get_name()] = $obj->get_name() . ' ' . $obj->get_ips() . ' - ' . $descr; } break; case 'host_group': include_once 'classes/Host_group.inc'; $list = Host_group::get_list($conn, "", 'ORDER BY name'); foreach ($list as $obj) { $descr = $obj->get_descr(); if (strlen($descr) > 50) { $descr = substr($descr, 0, 47) . '...'; } $options[$obj->get_name()] = $obj->get_name() . ' - ' . $descr; } break; case 'net_group': include_once 'classes/Net_group.inc'; $list = Net_group::get_list($conn, '', 'ORDER BY name'); foreach ($list as $obj) { $descr = $obj->get_descr(); if (strlen($descr) > 50) { $descr = substr($descr, 0, 47) . '...'; } $options[$obj->get_name()] = $obj->get_name() . ' - ' . $descr; } break; } // // Build the SELECT tag // $html = '<select name="member_name">'; foreach ($options as $name => $description) { $html .= "<option value='{$name}'>{$description}</option>"; } $html .= '</select>'; $resp->AddAssign("members_select", "innerHTML", $html); return $resp; }
function draw_asset_details($asset_id, $show_all_members = false) { global $conn; $resp = new xajaxResponse(); $asset = BP_Asset::get($conn, $asset_id); $html = ' <h2>' . _("Asset Details") . ': <u>' . $asset->get_name() . '</u></h2> <table width="70%" align="center"> <tr> <th width="20%">' . _("Asset Name") . '</th> <td style="text-align: left;"><b>' . $asset->get_name() . '</b></td> </tr> <tr> <th>' . _("Description") . '</th> <td style="text-align: left;">' . $asset->get_description() . '</td> </tr> <tr> <th>' . _("Responsibles") . '</th> <td class="noborder"> <table width="100%" class="noborder">'; $times = 0; foreach ($asset->get_responsibles() as $responsible) { $str = ''; if ($responsible['email']) { $str = '<a href="mailto:' . $responsible['email'] . '?subject=' . $asset->get_name() . '"><img border="0" src="../pixmaps/email_icon.gif"></a> '; } $str .= $responsible['name'] . ' (' . $responsible['login'] . ')'; $html .= '<tr><td style="text-align: left">' . $str . '</td></tr>'; $times++; } if (!$times) { $html .= '<tr><td style="text-align: left"><i>' . _("None set") . '</i></td></tr>'; } $html .= ' </table> </tr> <tr> <th width="30%" colspan="2">' . _("Status of Members"); if ($show_all_members) { $html .= ' <a href="#" onClick="javascript: xajax_draw_asset_details(' . $asset_id . ',0); return false;">(' . _("Click to show only members with problems") . ')</a> '; } else { $html .= ' <a href="#" onClick="javascript: xajax_draw_asset_details(' . $asset_id . ',1); return false;">(' . _("Click to show all members") . ')</a> '; } $html .= ' </th> </tr> <tr> <td colspan="2"> <table width="100%"> <tr> <th>Member type</th> <th>Member</th> <th>Measure type</th> <th>Severity</th> <th>Problem</th> <th>History</th> </tr> '; $all_members = $asset->get_members(); $members = array(); // // list only members with "problems" // foreach ($all_members as $mem) { $mem_id = $mem['name'] . '-' . $mem['type']; if ($show_all_members) { $members[$mem_id][] = $mem; } elseif ($mem['severity'] != 0 || $mem['measure_type'] === null) { $members[$mem_id][] = $mem; } } /* // // if all the measures from a member were OK, consolidate the data // as "All measures" "OK" // $all_member_ids = array_unique($all_member_ids); $listed_member_ids = array_keys($members); $all_ok_members = ($show_all_members)? $all_member_ids : array_diff($all_member_ids, $listed_member_ids); foreach ($all_ok_members as $mem_id) { list($name, $type) = explode('-', $mem_id); $members[$mem_id][] = array( 'name' => $name, 'type' => $type, 'measure_type' => 'all', 'severity' => "0" ); } */ // // Display members // foreach ($members as $mem_id => $member) { foreach ($member as $mem) { if ($mem['measure_type'] === null) { $link = _('n/a'); } else { $link = "../control_panel/" . Util::graph_image_link($mem['measure_type'] . "-" . $mem['name'], "bp", "bp", "N-1D", "N", 1, "all"); } //xajax_debug($mem, $resp); $error_msg = " "; if ($mem['severity'] >= LOW_PRIORITY) { $error_msg = BP_Asset::get_measure_link($mem); } $html .= '<tr valign="center"> <td>' . $mem['type'] . '</td> <td>' . $mem['name'] . '</td> <td>' . BP_Asset::get_measure_type_str($mem['measure_type']) . '</td> <td><b>' . bp_member_status_html($mem['severity']) . '</b></td> <td>' . $error_msg . '</td> <td><a href="' . $link . '"><img src="../pixmaps/graph.gif" border="0"/></a></td> </tr>'; } } $html .= '</table></td></tr></table>'; $resp->addAssign("asset-info", "style.display", ''); $resp->AddAssign("asset-info", "innerHTML", $html); return $resp; }