diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 21938116ce..8b2949b245 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,12 @@ +2007-02-06 Sancho Lerena + + * include/functions.php: Pagination function now works fine. + + * operation/incidents/incident.php, indicent_detail.: Incident + update/inser goes to main incident view. More usable + interface. Pagination works fine, needs to adjust SQL to use LIMIT + syntax for more optimized code. + 2007-02-05 Sancho Lerena * include/functions_db.php: Added function to get diff --git a/pandora_console/include/config.php b/pandora_console/include/config.php index d9dc01ebce..2f6f4864c9 100644 --- a/pandora_console/include/config.php +++ b/pandora_console/include/config.php @@ -2,13 +2,12 @@ // Pandora - the Free monitoring system // ==================================== -// Copyright (c) 2004-2006 Sancho Lerena, slerena@gmail.com -// Copyright (c) 2005-2006 Artica Soluciones Tecnologicas, info@artica.es -// Copyright (c) 2004-2006 Raul Mateos Martin, raulofpandora@gmail.com +// Copyright (c) 2004-2007 Sancho Lerena, slerena@gmail.com +// Copyright (c) 2005-2007 Artica Soluciones Tecnologicas, info@artica.es +// Copyright (c) 2004-2007 Raul Mateos Martin, raulofpandora@gmail.com // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. +// as published by the Free Software Foundation; version 2. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index 7253ce86fa..51e23af2ee 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -408,7 +408,7 @@ function pagination ($count, $url, $offset ) { // This calculate index_limit, block limit for this search. if (($index_page + $block_limit) > $index_counter) - $index_limit = $index_counter - 1; + $index_limit = $index_counter; else $index_limit = $index_page + $block_limit; @@ -435,13 +435,14 @@ function pagination ($count, $url, $offset ) { echo " "; // Show PREVIOUS button if ($index_page > 0){ - $index_page_prev= ($index_page-$block_limit)*$block_size; + $index_page_prev= ($index_page-(floor($block_limit/2)))*$block_size; if ($index_page_prev < 0) $index_page_prev = 0; echo ' '; } // Draw blocks markers + // $i stores number of page for ($i = $inicio_pag; $i < $index_limit; $i++) { $inicio_bloque = ($i * $block_size); $final_bloque = $inicio_bloque + $block_size; @@ -449,33 +450,40 @@ function pagination ($count, $url, $offset ) { $final_bloque = ($i-1)*$block_size + $count-(($i-1) * $block_size); } echo ""; - echo ''; + $inicio_bloque_fake = $inicio_bloque + 1; - // Show NEXT PAGE - if (($i >= $inicio_pag + $block_limit) AND ($paginacion_maxima == 1)){ + // To Calculate last block (doesnt end with round data, + // it must be shown if not round to block limit) + echo ''; + if ($inicio_bloque == $offset) + echo "[ $i ]"; + else + echo "[ $i ]"; + echo ' '; + echo ""; + } + // Show NEXT PAGE (fast forward) + // Index_counter stores max of blocks + if (($paginacion_maxima == 1) AND (($index_counter - $i) > 0)) { + $prox_bloque = ($i+ceil($block_limit/2))*$block_size; + if ($prox_bloque > $count) + $prox_bloque = ($count -1) - $block_size; + echo ''; echo " "; $i = $index_counter; - } - else { // Calculate last block (doesnt end with round data, it must be shown if not round to block limit) - if ($inicio_bloque == $offset) - echo "[ $i ]"; - else - echo "[ $i ]"; - echo ' '; - } - echo ""; } // if exists more registers than i can put in a page (defined by $block_size config parameter) // get offset for index calculation - - } - // Draw "last" block link - if (($count - $block_size) > 0){ - echo ' '; - echo ""; - echo ""; - } + // Draw "last" block link, ajust for last block will be the same + // as painted in last block (last integer block). + if (($count - $block_size) > 0){ + $myoffset = floor(($count-1)/ $block_size)* $block_size; + echo ' '; + echo ""; + echo ""; + } // End div and layout + } echo ""; } diff --git a/pandora_console/operation/incidents/incident.php b/pandora_console/operation/incidents/incident.php index 69146859f4..634a2210f4 100644 --- a/pandora_console/operation/incidents/incident.php +++ b/pandora_console/operation/incidents/incident.php @@ -18,21 +18,22 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // Load global vars - +$accion = ""; require("include/config.php"); if (comprueba_login() != 0) { audit_db("Noauth",$REMOTE_ADDR, "No authenticated acces","Trying to access incident viewer"); require ("general/noaccess.php"); exit; } + $id_usuario =$_SESSION["id_usuario"]; -$accion = ""; if (give_acl($id_usuario, 0, "IR")!=1) { audit_db($id_usuario,$REMOTE_ADDR, "ACL Violation","Trying to access incident viewer"); require ("general/noaccess.php"); exit; } +// Delete incident if (isset($_GET["quick_delete"])){ $id_inc = $_GET["quick_delete"]; $sql2="SELECT * FROM tincidencia WHERE id_incidencia=".$id_inc; @@ -52,6 +53,54 @@ if (isset($_GET["quick_delete"])){ } } +// UPDATE incident +if ((isset($_GET["action"])) AND ($_GET["action"]=="update")){ + $id_inc = $_POST["id_inc"]; + $grupo = entrada_limpia($_POST['grupo_form']); + $usuario= entrada_limpia($_POST["usuario_form"]); + if ((give_acl($id_usuario, $grupo, "IM")==1) OR ($usuario == $id_usuario)) { // Only admins (manage incident) or owners can modify incidents + $id_author_inc = give_incident_author($id_inc); + $titulo = entrada_limpia($_POST["titulo"]); + $descripcion = entrada_limpia($_POST['descripcion']); + $origen = entrada_limpia($_POST['origen_form']); + $prioridad = entrada_limpia($_POST['prioridad_form']); + $estado = entrada_limpia($_POST["estado_form"]); + $ahora=date("Y/m/d H:i:s"); + $sql = "UPDATE tincidencia SET actualizacion = '".$ahora."', titulo = '".$titulo."', origen= '".$origen."', estado = '".$estado."', id_grupo = '".$grupo."', id_usuario = '".$usuario."', prioridad = '".$prioridad."', descripcion = '".$descripcion."' WHERE id_incidencia = ".$id_inc; + $result=mysql_query($sql); + if ($result) + echo "

".$lang_label["upd_incid_ok"]."

"; + } else { + audit_db($id_usuario,$REMOTE_ADDR,"ACL Forbidden","User ".$_SESSION["id_usuario"]." try to update incident"); + echo "

".$lang_label["upd_incid_no"]."

"; + no_permission(); + } +} +// INSERT incident +if ((isset($_GET["action"])) AND ($_GET["action"]=="insert")){ + $grupo = entrada_limpia($_POST['grupo_form']); + $usuario= entrada_limpia($_POST["usuario_form"]); + if ((give_acl($id_usuario, $grupo, "IM") == 1) OR ($usuario == $id_usuario)) { // Only admins (manage + // Read input variables + $titulo = entrada_limpia($_POST['titulo']); + $inicio = date("Y/m/d H:i:s"); + $descripcion = entrada_limpia($_POST['descripcion']); + $texto = $descripcion; // to view in textarea after insert + $origen = entrada_limpia($_POST['origen_form']); + $prioridad = entrada_limpia($_POST['prioridad_form']); + $actualizacion = $inicio; + $id_creator = $id_usuario; + $estado = entrada_limpia($_POST["estado_form"]); + $sql = " INSERT INTO tincidencia (inicio,actualizacion,titulo,descripcion,id_usuario,origen,estado,prioridad,id_grupo, id_creator) VALUES ('".$inicio."','".$actualizacion."','".$titulo."','".$descripcion."','".$usuario."','".$origen."','".$estado."','".$prioridad."','".$grupo."','".$id_creator."') "; + if (mysql_query($sql)) + echo "

".$lang_label["create_incid_ok"]."

"; + $id_inc=mysql_insert_id(); + } else { + audit_db($id_usuario,$REMOTE_ADDR,"ACL Forbidden","User ".$_SESSION["id_usuario"]." try to create incident"); + no_permission(); + } +} + // Search $busqueda=""; if (isset($_POST["texto"]) OR (isset($_GET["texto"]))){ @@ -259,8 +308,7 @@ if (!mysql_num_rows($result2)) { // Fill array with data // TOTAL incidents - $total_incidentes = sizeof($incident_list); - + $total_incidentes = sizeof($incident_list) - 1; $url = "index.php?sec=incidencias&sec2=operation/incidents/incident"; // add form filter values for group, priority, state, and search fields: user and text diff --git a/pandora_console/operation/incidents/incident_detail.php b/pandora_console/operation/incidents/incident_detail.php index 810d27fb83..15c5444f64 100644 --- a/pandora_console/operation/incidents/incident_detail.php +++ b/pandora_console/operation/incidents/incident_detail.php @@ -89,49 +89,6 @@ if (isset($_GET["id"])){ $res4 = mysql_query($sql4); } - // Modify incident - if (isset($_POST["accion"])){ - $id_inc = $_POST["id_inc"]; - if ((give_acl($iduser_temp, $id_grupo, "IM")==1) OR ($usuario == $iduser_temp)) { // Only admins (manage incident) or owners can modify incidents - // Edicion !! - if ($_POST["accion"] == $lang_label["in_modinc"]){ // Modify Incident - $id_author_inc = give_incident_author($id_inc); - $titulo = entrada_limpia($_POST["titulo"]); - $descripcion = entrada_limpia($_POST['descripcion']); - $origen = entrada_limpia($_POST['origen']); - $prioridad = entrada_limpia($_POST['prioridad']); - $grupo = entrada_limpia($_POST['grupo']); - $usuario= entrada_limpia($_POST["usuario"]); - $estado = entrada_limpia($_POST["estado"]); - $ahora=date("Y/m/d H:i:s"); - $sql = "UPDATE tincidencia SET actualizacion = '".$ahora."', titulo = '".$titulo."', origen= '".$origen."', estado = '".$estado."', id_grupo = '".$grupo."', id_usuario = '".$usuario."', prioridad = '".$prioridad."', descripcion = '".$descripcion."' WHERE id_incidencia = ".$id_inc; - $result=mysql_query($sql); - if ($result) echo "

".$lang_label["upd_incid_ok"]."

"; - // Re-read data for correct presentation - // Obtain group of this incident - $sql1='SELECT * FROM tincidencia WHERE id_incidencia = '.$id_inc; - $result=mysql_query($sql1); - $row=mysql_fetch_array($result); - // Get values - $titulo = $row["titulo"]; - $texto = $row["descripcion"]; - $inicio = $row["inicio"]; - $actualizacion = $row["actualizacion"]; - $estado = $row["estado"]; - $prioridad = $row["prioridad"]; - $origen = $row["origen"]; - $usuario = $row["id_usuario"]; - $nombre_real = dame_nombre_real($usuario); - $id_grupo = $row["id_grupo"]; - $grupo = dame_nombre_grupo($id_grupo); - } - } else { - audit_db($id_author_inc,$REMOTE_ADDR,"ACL Forbidden","User ".$_SESSION["id_usuario"]." try to update incident"); - echo "

".$lang_label["upd_incid_no"]."

"; - no_permission(); - } - } - // Delete note if (isset($_GET["id_nota"])){ $note_user = give_note_author ($_GET["id_nota"]); @@ -190,30 +147,10 @@ if (isset($_GET["id"])){ } } } -} else { // Not given id - // Insert data ! - if (isset($_POST["accion"]) and ($_POST["accion"] == $lang_label["create"])) { - $iduser_temp=$_SESSION['id_usuario']; - // Read input variables - $titulo = entrada_limpia($_POST['titulo']); - $inicio = date("Y/m/d H:i:s"); - $descripcion = entrada_limpia($_POST['descripcion']); - $texto = $descripcion; // to view in textarea after insert - $origen = entrada_limpia($_POST['origen']); - $prioridad = entrada_limpia($_POST['prioridad']); - $grupo = entrada_limpia($_POST['grupo']); - $usuario= entrada_limpia($_SESSION["id_usuario"]); - $actualizacion = $inicio; - $id_creator = $iduser_temp; - $estado = 0; // if the indicent is new, state (estado) is 0 - $sql = " INSERT INTO tincidencia (inicio,actualizacion,titulo,descripcion,id_usuario,origen,estado,prioridad,id_grupo, id_creator) VALUES ('".$inicio."','".$actualizacion."','".$titulo."','".$descripcion."','".$usuario."','".$origen."','".$estado."','".$prioridad."','".$grupo."','".$id_creator."') "; - if (give_acl($iduser_temp, $grupo, "IW")==1){ - if (mysql_query($sql)) echo "

".$lang_label["create_incid_ok"]."

"; - $id_inc=mysql_insert_id(); - } else - no_permission(); - // INSERT FORM. - } elseif (isset($_GET["insert_form"])){ +} // else Not given id +// Create incident from event... read event data +elseif (isset($_GET["insert_form"])){ + $iduser_temp=$_SESSION['id_usuario']; $titulo = ""; if (isset($_GET["from_event"])){ @@ -235,22 +172,23 @@ if (isset($_GET["id"])){ $inicio = $actualizacion; $id_creator = $iduser_temp; $creacion_incidente = 1; - } else { - audit_db($id_user,$REMOTE_ADDR, "HACK","Trying to create incident in a unusual way"); - no_permission(); - - } +} else { + audit_db($id_user,$REMOTE_ADDR, "HACK","Trying to create incident in a unusual way"); + no_permission(); + } + + // ******************************************************************************************************** // ******************************************************************************************************** // Show the form // ******************************************************************************************************** if ($creacion_incidente == 0) - echo "
"; + echo ""; else - echo ""; + echo ""; if (isset($id_inc)) { echo ""; @@ -272,7 +210,7 @@ echo ''.$lang_label["updated_at"].''; echo "".$actualizacion.""; echo ''.$lang_label["in_openedby"].''; if ((give_acl($id_user, $id_grupo, "IM")==1) OR ($usuario == $id_user)) { - echo ""; echo "