Location: PHPKode > projects > Limph > limph-1.9.7/groups_man.php
<?php
 /*
   Limph Is Monitoring Pingable Hosts
   Copyright (C) 2005 Jonathan Ciesla
   
   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.
   
   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
   GNU General Public License for more details.
   
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
  */
require_once("config.php");
require_once("functionlib.php");
session_start();
favicon();

$link = dbms_connect($dbhost, $dbuser, $dbpass, $dbname);

$admin_level =$_SESSION['limphadmin'];
authentication($admin_level,1);

echo "<link rel=stylesheet href=css.php>";
echo "<title>Limph: $sitetitle</title>";
echo "<h3>Limph: $sitetitle</h3>";

$deletegroup=$_POST['deletegroup'];
if($deletegroup=="yes"){
  $number = $_POST['number'];
  $query = "SELECT COUNT(number) FROM hosts WHERE hostgroup = '$number';";
  $result = dbms_query($query);
  $line = dbms_fetch_array($result);
  dbms_free_result($result);
  if($line[0]<=0){
    $query = "DELETE FROM groups WHERE number = '$number';";
    $result = dbms_query($query);
  } else {
    echo "Group not empty.";
  };
 };

$groupedit=$_POST['groupedit'];
if($groupedit=="yes"){
  $number = $_POST['number'];
  $name = dbms_escape_string($_POST['name']);
  $col = $_POST['col'];
  $priority = dbms_escape_string($_POST['priority']);
  $collapse = $_POST['collapse'];
  if($collapse=="on"){$collapse="1";}else{$collapse="0";};
  
  $query = "UPDATE groups SET name='$name',col='$col',priority='$priority',collapse='$collapse' WHERE number = '$number';";
  $result = dbms_query($query);
 };

$groupadd=$_POST['groupadd'];
  if($groupadd=="yes"){
    $name = dbms_escape_string($_POST['name']);
    $col = $_POST['col'];
    $priority = dbms_escape_string($_POST['priority']);
    $collapse = $_POST['collapse'];
    if($collapse=="on"){$collapse="1";}else{$collapse="0";};
    
    $query = "SELECT number FROM groups ORDER BY number DESC LIMIT 1;";
    $result1 = dbms_query($query);
    $line1 = dbms_fetch_array($result1, "NUM");
    $value = $line1[0];
    $value++;
    dbms_free_result($result1);

    $query = "INSERT INTO groups (number,name,col,priority,collapse) VALUES ('$value','$name','$col','$priority','$collapse');";
    $result = dbms_query($query);
  };

echo "<table border=1 cellpadding=5 align=center>";
echo "<tr><th colspan=3>Add Group</th></tr>";
echo "<form action=groups_man.php method=post>";
echo "<tr><td align=right colspan=2>Name:<input type=text name=name></td></tr>";
echo "<tr><td>Column:</td><td>";
$query2 = "SELECT number,width FROM layout ORDER BY number ASC;";
$result2 = dbms_query($query2);
while($line2 = dbms_fetch_array($result2, "NUM")){
  if($line2[0]==1){$flag = "checked";}else{$flag="";};
  echo "{$line2['0']}:<input type=radio name=col value={$line2['0']} $flag>";
 };
dbms_free_result($result2);
echo "</td></tr>";
echo "<tr><td colspan=3>Priority:<input type=text name=priority></td></tr>";
echo "<tr><td align=right colspan=2>Collapse<input type=checkbox name=collapse></td></tr>";
echo "<tr><td colspan=3 align=center><input type=submit value=\"Add Group\"/></td></tr>";
echo "<input type=hidden name=number value=$number>";
echo "<input type=hidden name=groupadd value=yes>";
echo "</form>";
echo "</table>";

echo "<br />";

echo "<table align=center>";
echo "<tr>";

$query = "SELECT number,width FROM layout ORDER BY number ASC;";
$result3 = dbms_query($query);
$num = $_POST['num'];
while($line3 = dbms_fetch_array($result3, "NUM")){
  $pos = $line3[0];
  echo "<td valign=top>";
  $query = "SELECT number,name,priority FROM groups WHERE col = '$pos' ORDER BY priority ASC;";
  $result = dbms_query($query);
  echo "<table border=1 cellpadding=5 align=center>";
  echo "<tr><th colspan=2>Groups</th></tr>";
  while($line=dbms_fetch_array($result, "NUM")){
    echo "<tr>";
    echo "<td>{$line['1']}</td>";
    echo "<td>";
    echo "<form action=groups_edit.php method=post>";
    echo "<input type=hidden name=number value={$line['0']}>";
    echo "<input type=submit value=\"{$line['2']}\">";
    echo "</form>";
    echo "</td></tr>";
  };
  
  echo "</table>";
  
  dbms_free_result($result);
  echo "</td>";
};
dbms_free_result($result3);
dbms_close($link);
echo "</tr></table>";

echo "<br />";
echo "<form action=index.php method=post>";
echo "<input type=submit value=Back />";
echo "</form>";
?>
Return current item: Limph