2008-10-21 Esteban Sanchez <estebans@artica.es>

* godmode/profiles/profile_list.php: Rewritten be more consistent and 
        use generic functions for HTML output. Also a bug when creating a 
        profile is fixed.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1178 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
esanchezm 2008-10-21 09:48:11 +00:00
parent 8fad28d946
commit 25b26d9fe2
2 changed files with 233 additions and 193 deletions

View File

@ -1,3 +1,9 @@
2008-10-21 Esteban Sanchez <estebans@artica.es>
* godmode/profiles/profile_list.php: Rewritten be more consistent and
use generic functions for HTML output. Also a bug when creating a
profile is fixed.
2008-10-20 Evi Vanoost <vanooste@rcbi.rochester.edu>
* pandoradb_data.sql, pandora_db.sql: id_npc was rendered unnecessary

View File

@ -32,13 +32,17 @@ if (! give_acl ($config['id_user'], 0, "PM")) {
//Page title definitation. Will be overridden by Edit and Create Profile
$page_title = __('Profiles defined in Pandora');
// Profile deletion
if (isset ($_GET["delete_profile"])){ // if any parameter is modified
$id_profile = safe_input ($_GET["delete_profile"]);
$new_profile = (bool) get_parameter ('new_profile');
$create_profile = (bool) get_parameter ('create_profile');
$delete_profile = (bool) get_parameter ('delete_profile');
$update_profile = (bool) get_parameter ('update_profile');
$id_profile = (int) get_parameter ('id');
// Profile deletion
if ($delete_profile) {
// Delete profile
$query = "DELETE FROM tperfil WHERE id_perfil = '".$id_profile."'";
$ret = process_sql ($query);
$sql = sprintf ('DELETE FROM tperfil WHERE id_perfil = %d', $id_profile);
$ret = process_sql ($sql);
if ($ret === false) {
echo '<h3 class="error">'.__('There was a problem deleting the profile').'</h3>';
} else {
@ -46,208 +50,238 @@ if (isset ($_GET["delete_profile"])){ // if any parameter is modified
}
//Delete profile from user data
$query = "DELETE FROM tusuario_perfil WHERE id_perfil = '".$id_profile."'";
process_sql ($query);
$sql = sprintf ('DELETE FROM tusuario_perfil WHERE id_perfil = %d', $id_profile);
process_sql ($sql);
unset($id_profile); // forget it to show list
} elseif (isset ($_GET["new_profile"])) { // create a new profile
$id_perfil = -1;
$name = "";
$incident_view = 0;
$incident_edit = 0;
$incident_management = 0;
$agent_view = 0;
$agent_edit = 0;
$alert_edit = 0;
$user_management = 0;
$db_management = 0;
$alert_management = 0;
$pandora_management = 0;
$page_title = __('Create profile');
} elseif (isset ($_GET["edit_profile"])) { // Edit profile (read data to show in form)
$id_perfil = safe_input ($_GET["edit_profile"]);
$row = get_db_row_sql("SELECT * FROM tperfil WHERE id_perfil = '".$id_perfil."'");
$id_profile = 0;
}
if ($row === false) {
echo '<h3 class="error">'.__('There was a problem loading profile').'</h3></table>'; //Error and close open table
include ("general/footer.php");
exit;
// Update profile
if ($update_profile) {
$name = get_parameter ("name");
$incident_view = (bool) get_parameter ("incident_view");
$incident_edit = (bool) get_parameter ("incident_edit");
$incident_management = (bool) get_parameter ("incident_management");
$agent_view = (bool) get_parameter ("agent_view");
$agent_edit = (bool) get_parameter ("agent_edit");
$alert_edit = (bool) get_parameter ("alert_edit");
$user_management = (bool) get_parameter ("user_management");
$db_management = (bool) get_parameter ("db_management");
$alert_management = (bool) get_parameter ("alert_management");
$pandora_management = (bool) get_parameter ("pandora_management");
$sql = sprintf ('UPDATE tperfil SET
name = "%s", incident_view = %d, incident_edit = %d,
incident_management = %d, agent_view = %d, agent_edit = %d,
alert_edit = %d, user_management = %d, db_management = %d,
alert_management = %d, pandora_management = %d WHERE id_perfil = %d',
$name, $incident_view, $incident_edit, $incident_management,
$agent_view, $agent_edit, $alert_edit, $user_management,
$db_management, $alert_management, $pandora_management,
$id_profile);
$ret = process_sql ($sql);
if ($ret !== false) {
echo '<h3 class="suc">'.__('Profile successfully updated').'</h3>';
} else {
$name = $row["name"];
$incident_view = $row["incident_view"];
$incident_edit = $row["incident_edit"];
$incident_management = $row["incident_management"];
$agent_view = $row["agent_view"];
$agent_edit =$row["agent_edit"];
$alert_edit = $row["alert_edit"];
$user_management = $row["user_management"];
$db_management = $row["db_management"];
$alert_management = $row["alert_management"];
$pandora_management = $row["pandora_management"];
unset ($row); //clean up variables
echo '<h3 class="error"'.__('There was a problem updating this profile').'</h3>';
}
$id_profile = 0;
}
$page_title = __('Update profile');
// Create profile
if ($create_profile) {
$name = get_parameter ("name");
$incident_view = (bool) get_parameter ("incident_view");
$incident_edit = (bool) get_parameter ("incident_edit");
$incident_management = (bool) get_parameter ("incident_management");
$agent_view = (bool) get_parameter ("agent_view");
$agent_edit = (bool) get_parameter ("agent_edit");
$alert_edit = (bool) get_parameter ("alert_edit");
$user_management = (bool) get_parameter ("user_management");
$db_management = (bool) get_parameter ("db_management");
$alert_management = (bool) get_parameter ("alert_management");
$pandora_management = (bool) get_parameter ("pandora_management");
} elseif (isset ($_GET["update_data"])) { // Update or Create a new record (writes on DB)
// Profile edit
$id_profile = (int) get_parameter_post ("id_perfil",-1);
$name = get_parameter_post ("name");
$sql = sprintf ('INSERT INTO tperfil
(name, incident_view, incident_edit, incident_management, agent_view,
agent_edit, alert_edit, user_management, db_management,
alert_management, pandora_management)
VALUES ("%s", %d, %d, %d, %d, %d, %d, %d, %d, %d, %d)',
$name, $incident_view, $incident_edit, $incident_management,
$agent_view, $agent_edit, $alert_edit, $user_management,
$db_management, $alert_management, $pandora_management);
$incident_view = (bool) get_parameter_post ("incident_view",0);
$incident_edit = (bool) get_parameter_post ("incident_edit",0);
$incident_management = (bool) get_parameter_post ("incident_management",0);
$agent_view = (bool) get_parameter_post ("agent_view",0);
$agent_edit = (bool) get_parameter_post ("agent_edit",0);
$alert_edit = (bool) get_parameter_post ("alert_edit",0);
$user_management = (bool) get_parameter_post ("user_management",0);
$db_management = (bool) get_parameter_post ("db_management",0);
$alert_management = (bool) get_parameter_post ("alert_management",0);
$pandora_management = (bool) get_parameter_post ("pandora_management",0);
// update or insert ??
if ($id_profile == -1) { // INSERT
$query = "INSERT INTO tperfil
(name,incident_view,incident_edit,incident_management,agent_view,agent_edit,alert_edit,user_management,db_management,alert_management,pandora_management)
VALUES
('".$name."','".$incident_view."','".$incident_edit."','".$incident_management."','".$agent_view."','".$agent_edit."','".$alert_edit."','".$user_management."','".$db_management."','".$alert_management."','".$pandora_management."')";
// echo "DEBUG: ".$query;
$ret = process_sql ($query);
if ($ret !== false) {
echo '<h3 class="suc">'.__('Profile successfully created').'</h3>';
} else {
echo '<h3 class="error">'.__('There was a problem creating this profile').'</h3>';
}
} else { // UPDATE
$query = "UPDATE tperfil SET
name = '".$name."',
incident_view = '".$incident_view."',
incident_edit = '".$incident_edit."',
incident_management = '".$incident_management."',
agent_view = '".$agent_view."',
agent_edit = '".$agent_edit."',
alert_edit = '".$alert_edit."',
user_management = '".$user_management."',
db_management = '".$db_management."',
alert_management = '".$alert_management."',
pandora_management = '".$pandora_management."'
WHERE id_perfil = '".$id_profile."'";
// echo "DEBUG: ".$query;
$ret = process_sql ($query);
if ($ret !== false) {
echo '<h3 class="suc">'.__('Profile successfully updated').'</h3>';
} else {
echo '<h3 class="error"'.__('There was a problem updating this profile').'</h3>';
}
$ret = process_sql ($sql, 'insert_id');
if ($ret !== false) {
echo '<h3 class="suc">'.__('Profile successfully created').'</h3>';
} else {
echo '<h3 class="error">'.__('There was a problem creating this profile').'</h3>';
}
unset ($id_profile);
$id_profile = 0;
}
echo '<h2>'.__('Profile management').' &gt; '.$page_title.'</h2>';
// Form to manage date
if (isset ($id_perfil)){ // There are values defined, let's show form with data for INSERT or UPDATE
echo '<table width="400" cellpadding="4" cellspacing="4" class="databox">
<form method="POST" action="index.php?sec=gperfiles&sec2=godmode/profiles/profile_list&update_data">
<input type="hidden" name="id_perfil" value="'.$id_perfil.'" />
<tr>
<td class="datos">'.__('Profile name').'</td>
<td class="datos"><input name="name" type="text" size="27" value="'.$name.'" /></td>
</tr>
<tr>
<td class="datos2">'.__('View incidents').'</td>
<td class="datos2"><input name="incident_view" type="checkbox" class="chk" value="1" '.(($incident_view == 1) ? 'checked' : '').' /></td>
</tr>
<tr>
<td class="datos">'.__('Edit incidents').'</td>
<td class="datos"><input name="incident_edit" type="checkbox" class="chk" value="1" '.(($incident_edit == 1) ? 'checked' : '').' /></td>
</tr>
<tr>
<td class="datos2">'.__('Manage incidents').'</td>
<td class="datos2"><input name="incident_management" type="checkbox" class="chk" value="1" '.(($incident_management == 1) ? 'checked' : '').'/></td>
</tr>
<tr>
<td class="datos">'.__('View agents').'</td>
<td class="datos"><input name="agent_view" type="checkbox" class="chk" value="1" '.(($agent_view == 1) ? 'checked' : '').' /></td>
</tr>
<tr>
<td class="datos2">'.__('Edit agents').'</td>
<td class="datos2"><input name="agent_edit" type="checkbox" class="chk" value="1" '.(($agent_edit == 1) ? 'checked' : '').' /></td>
</tr>
<tr>
<td class="datos">'.__('Edit alerts').'</td>
<td class="datos"><input name="alert_edit" type="checkbox" class="chk" value="1" '.(($alert_edit == 1) ? 'checked' : '').' /></td>
</tr>
<tr>
<td class="datos2">'.__('Manage users').'</td>
<td class="datos2"><input name="user_management" class="chk" type="checkbox" value="1" '.(($user_management == 1) ? 'checked' : '').' /></td>
</tr>
<tr>
<td class="datos">'.__('Manage Database').'</td>
<td class="datos"><input name="db_management" class="chk" type="checkbox" value="1" '.(($db_management == 1) ? 'checked' : '').' /></td>
</tr>
<tr>
<td class="datos2">'.__('Manage alerts').'</td>
<td class="datos2"><input name="alert_management" class="chk" type="checkbox" value="1" '.(($alert_management == 1) ? 'checked' : '').' /></td>
</tr>
<tr>
<td class="datos">'.__('Pandora management').'</td>
<td class="datos"><input name="pandora_management" class="chk" type="checkbox" value="1" '.(($pandora_management == 1) ? 'checked' : '').' /></td>
</tr>
</form>
</table>';
// Edit profile
if ($id_profile || $new_profile) {
if ($new_profile) {
$name = '';
$incident_view = 0;
$incident_edit = 0;
$incident_management = 0;
$agent_view = 0;
$agent_edit = 0;
$alert_edit = 0;
$user_management = 0;
$db_management = 0;
$alert_management = 0;
$pandora_management = 0;
$page_title = __('Create profile');
} else {
$profile = get_db_row ('tperfil', 'id_perfil', $id_profile);
if ($profile === false) {
echo '<h3 class="error">'.__('There was a problem loading profile').'</h3></table>';
include ("general/footer.php");
exit;
}
$name = $profile["name"];
$incident_view = (bool) $profile["incident_view"];
$incident_edit = (bool) $profile["incident_edit"];
$incident_management = (bool) $profile["incident_management"];
$agent_view = (bool) $profile["agent_view"];
$agent_edit = (bool) $profile["agent_edit"];
$alert_edit = (bool) $profile["alert_edit"];
$user_management = (bool) $profile["user_management"];
$db_management = (bool) $profile["db_management"];
$alert_management = (bool) $profile["alert_management"];
$pandora_management = (bool) $profile["pandora_management"];
$page_title = __('Update profile');
}
$table->width = '400px';
$table->class = 'databox';
$table->size = array ();
$table->style = array ();
$table->style[0] = 'font-weight: bold';
$table->data = array ();
$table->data[0][0] = __('Profile name');
$table->data[0][1] = print_input_text ('name', $name, '', 30, 60, true);
$table->data[1][0] = __('View incidents');
$table->data[1][1] = print_checkbox ('incident_view', 1, $incident_view, true);
$table->data[2][0] = __('Edit incidents');
$table->data[2][1] = print_checkbox ('incident_edit', 1, $incident_edit, true);
$table->data[3][0] = __('Manage incidents');
$table->data[3][1] = print_checkbox ('incident_management', 1, $incident_management, true);
$table->data[4][0] = __('View agents');
$table->data[4][1] = print_checkbox ('agent_view', 1, $agent_view, true);
$table->data[5][0] = __('Edit agents');
$table->data[5][1] = print_checkbox ('agent_edit', 1, $agent_edit, true);
$table->data[6][0] = __('Edit alerts');
$table->data[6][1] = print_checkbox ('alert_edit', 1, $alert_edit, true);
$table->data[7][0] = __('Manage alerts');
$table->data[7][1] = print_checkbox ('alert_management', 1, $alert_management, true);
$table->data[8][0] = __('Manage users');
$table->data[8][1] = print_checkbox ('user_management', 1, $user_management, true);
$table->data[9][0] = __('Manage Database');
$table->data[9][1] = print_checkbox ('db_management', 1, $db_management, true);
$table->data[10][0] = __('Pandora management');
$table->data[10][1] = print_checkbox ('pandora_management', 1, $pandora_management, true);
echo '<form method="post" action="index.php?sec=gperfiles&sec2=godmode/profiles/profile_list">';
print_table ($table);
echo '<div class="action-buttons" style="width: 400px">';
if (isset ($_GET["new_profile"])) {
echo '<input name="crtbutton" type="submit" class="sub wand" value="'.__('Create').'" />';
} elseif (isset ($_GET["edit_profile"])) {
echo '<input name="uptbutton" type="submit" class="sub upd" value="'.__('Update').'" />';
if ($new_profile) {
print_submit_button (__('Create'), "crt", false, 'class="sub next"');
print_input_hidden ('create_profile', 1);
} else {
print_input_hidden ('id', $id_profile);
print_input_hidden ('update_profile', 1);
print_submit_button (__('Update'), "upd", false, 'class="sub upd"');
}
echo "</div>";
echo "</div></form>";
} else { // View list data
$result = get_db_all_rows_in_table ("tperfil");
$table->cellpadding = 4;
$table->cellspacing = 4;
} else {
// View list data
$table->class = "databox";
$table->width = 750;
$table->size = array (180,40,40,40,40,40,40,40,40,40,40);
$table->head = array (
__('Profiles'),
'IR'.print_help_tip (__('Read Incidents'),true),
'IW'.print_help_tip (__('Create Incidents'),true),
'IM'.print_help_tip (__('Manage Incidents'),true),
'AR'.print_help_tip (__('Read Agent Information'),true),
'AW'.print_help_tip (__('Manage Agents'),true),
'LW'.print_help_tip (__('Edit Alerts'),true),
'UM'.print_help_tip (__('Manage User Rights'),true),
'DM'.print_help_tip (__('Database Management'),true),
'LM'.print_help_tip (__('Alerts Management'),true),
'PM'.print_help_tip (__('Pandora System Management'),true),
__('Delete')
);
$table->align = array ('',"center","center","center","center","center","center","center","center","center","center","center");
foreach ($result as $row) {
$table->data[] = array (
'<a href="index.php?sec=gperfiles&amp;sec2=godmode/profiles/profile_list&amp;edit_profile='.$row["id_perfil"].'"><b>'.$row["name"].'</b></a>',
(($row["incident_view"] == 1) ? '<img src="images/ok.png" border="0">' : ''),
(($row["incident_edit"] == 1) ? '<img src="images/ok.png" border="0">' : ''),
(($row["incident_management"] == 1) ? '<img src="images/ok.png" border="0">' : ''),
(($row["agent_view"] == 1) ? '<img src="images/ok.png" border="0">' : ''),
(($row["agent_edit"] == 1) ? '<img src="images/ok.png" border="0">' : ''),
(($row["alert_edit"] == 1) ? '<img src="images/ok.png" border="0">' : ''),
(($row["user_management"] == 1) ? '<img src="images/ok.png" border="0">' : ''),
(($row["db_management"] == 1) ? '<img src="images/ok.png" border="0">' : ''),
(($row["alert_management"] == 1) ? '<img src="images/ok.png" border="0">' : ''),
(($row["pandora_management"] == 1) ? '<img src="images/ok.png" border="0">' : ''),
'<a href="index.php?sec=gagente&sec2=godmode/profiles/profile_list&delete_profile='.$row["id_perfil"].'" onClick="if (!confirm(\' '.__('Are you sure?').'\')) return false;"><img border="0" src="images/cross.png"></a>'
);
$table->width = '750px';
$table->data = array ();
$table->size = array ();
$table->size[0] = '180px';
$table->size[1] = '40px';
$table->size[2] = '40px';
$table->size[3] = '40px';
$table->size[4] = '40px';
$table->size[5] = '40px';
$table->size[6] = '40px';
$table->size[7] = '40px';
$table->size[8] = '40px';
$table->size[9] = '40px';
$table->size[10] = '40px';
$table->size[11] = '40px';
$table->head = array ();
$table->head[0] = __('Profiles');
$table->head[1] = 'IR'.print_help_tip (__('Read Incidents'), true);
$table->head[2] = 'IW'.print_help_tip (__('Create Incidents'), true);
$table->head[3] = 'IM'.print_help_tip (__('Manage Incidents'), true);
$table->head[4] = 'AR'.print_help_tip (__('Read Agent Information'), true);
$table->head[5] = 'AW'.print_help_tip (__('Manage Agents'), true);
$table->head[6] = 'LW'.print_help_tip (__('Edit Alerts'), true);
$table->head[7] = 'UM'.print_help_tip (__('Manage User Rights'), true);
$table->head[8] = 'DM'.print_help_tip (__('Database Management'), true);
$table->head[9] = 'LM'.print_help_tip (__('Alerts Management'), true);
$table->head[10] = 'PM'.print_help_tip (__('Pandora System Management'), true);
$table->head[11] = __('Delete');
$table->align = array ();
$table->align[1] = 'center';
$table->align[2] = 'center';
$table->align[3] = 'center';
$table->align[4] = 'center';
$table->align[5] = 'center';
$table->align[6] = 'center';
$table->align[7] = 'center';
$table->align[8] = 'center';
$table->align[9] = 'center';
$table->align[10] = 'center';
$table->align[11] = 'center';
$profiles = get_db_all_rows_in_table ('tperfil');
if ($profiles === false)
$profiles = array ();
foreach ($profiles as $profile) {
$data = array ();
$data[0] = '<a href="index.php?sec=gperfiles&amp;sec2=godmode/profiles/profile_list&id='.$profile["id_perfil"].'"><b>'.$profile["name"].'</b></a>';
$data[1] = $profile["incident_view"] ? '<img src="images/ok.png">' : '';
$data[2] = $profile["incident_edit"] ? '<img src="images/ok.png">' : '';
$data[3] = $profile["incident_management"] ? '<img src="images/ok.png">' : '';
$data[4] = $profile["agent_view"] ? '<img src="images/ok.png">' : '';
$data[5] = $profile["agent_edit"] ? '<img src="images/ok.png">' : '';
$data[6] = $profile["alert_edit"] ? '<img src="images/ok.png">' : '';
$data[7] = $profile["user_management"] ? '<img src="images/ok.png">' : '';
$data[8] = $profile["db_management"] ? '<img src="images/ok.png">' : '';
$data[9] = $profile["alert_management"] ? '<img src="images/ok.png">' : '';
$data[10] = $profile["pandora_management"] ? '<img src="images/ok.png">' : '';
$data[11] = '<a href="index.php?sec=gagente&sec2=godmode/profiles/profile_list&delete_profile=1&id='.$profile["id_perfil"].'" onClick="if (!confirm(\' '.__('Are you sure?').'\')) return false;"><img src="images/cross.png"></a>';
array_push ($table->data, $data);
}
echo '<form method="post" action="index.php?sec=gperfiles&sec2=godmode/profiles/profile_list">';
print_table ($table);
echo '<div class="action-buttons" style="width: 750px">';
echo '<form method="POST" action="index.php?sec=gperfiles&sec2=godmode/profiles/profile_list&new_profile=1">'.print_submit_button(__('Create profile'),"crt",false,'class="sub next"',true).'</form>';
echo '<div class="action-buttons" style="width: '.$table->width.'">';
print_input_hidden ('new_profile', 1);
print_submit_button (__('Create profile'), "crt", false, 'class="sub next"');
echo '</form>';
echo "</div>";
}
?>