fhiiqm/report/gefgr_gefahr_pic_report.php
author Bettina Schwarzer
Fri, 20 Dec 2013 15:19:32 +0100
changeset 41 9c668cd391fa
parent 38 45c139f74ea4
permissions -rw-r--r--
+ Gast als MA-Typ, Erweiterungen Projekt, Key, Telefonliste

<?php

/**
 * @author Bettina Schwarzer, Fritz-Haber-Institut
 * @copyright 05/2013
 * 
 * Report Gefahrgruppe - Gefaehrdung - Pictogramm
 */

    error_reporting(E_ALL ^ E_NOTICE);
    
    if (!isset($_GET['s']) || $_GET['s'] != 2 )
    {
        session_start();
        if (! isset($_SESSION["userid"]))
        { 
            include_once ($_SERVER['DOCUMENT_ROOT'] ."/fhiiqm/inc/func_lib.inc.php");	
            login($_SERVER["PHP_SELF"]);
            exit;
        }
        
        if (is_null($_SESSION["recht"]) || (!is_null($_SESSION["recht"]) && !in_array("asr",$_SESSION["recht"]) && !in_array("ase",$_SESSION["recht"])))
        {
            header("Location: start.php");
            exit;
        }
    }    
	include_once($_SERVER['DOCUMENT_ROOT'] ."/fhiiqm/inc/dbconnect.inc.php");
	if (!isset($dbc) || !$dbc) $dbc = new dbconnection();
    

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
	<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
   	<link href="/fhiiqm/css/db.css" rel="STYLESHEET" type="TEXT/CSS"  media="screen"/> 
   	<link href="/fhiiqm/css/db_print.css" rel="STYLESHEET" type="TEXT/CSS"  media="print"/> 
	<title>Report Gef&auml;hrdungsgruppe-Gef&auml;hrdung-Piktogramm</title>
</head>

<body>

<?php    
    echo "&nbsp;";  
    if (!isset($_GET['s']) || $_GET['s'] != 2 )
    {
        echo "<div class=\"float-br smaller\" valign='top'>";
        echo "&nbsp;&nbsp;&nbsp;user: " . $_SESSION["userid"];
        echo "&nbsp;&nbsp;&nbsp;<a class='sc' href='/fhiiqm/logout.php' title='Session beenden'>logout</a></div>\n";
    }
    echo "<div class=\"float-r\"><img src=\"/fhiiqm/img/role.png\" border=\"0\" alt=\"Arbeitssicherheit\" title=\"Arbeitssicherheit\"/></div>\n";

    $rag    = $_POST["rag"];    // Parameter aus Form
    $search = $_POST["search"];
    if (!$search) $search =  $_GET["s"];

    $zeil = $rag["z"];
    if (!$zeil) $zeil = $_GET["z"];
    if (!$zeil) $zeil = 9999; // Anzahl der gezeigten Zeilen
    $start = $_GET["st"];   // Start bei DS $start+1
    if (!$start) $start=0;
    
    if (!is_array($rag))
    {
        $rag["gef"]     = $_GET["g"];
        $rag["gru"]   = $_GET["u"];
        $rag["bind"]    = $_GET["b"];
        $rag["sort1"]   = $_GET["s1"];
        $rag["sort2"]   = $_GET["s2"];
        $rag["sort3"]   = $_GET["s3"];
    }
    $_GET["g"] = $rag["gef"];
    $_GET["u"] = $rag["gru"];
    $_GET["b"] = $rag["bind"];
    $_GET["s1"] = $rag["sort1"];
    $_GET["s2"] = $rag["sort2"];
    $_GET["s3"] = $rag["sort3"];
    $_GET["z"]  = $zeil;
   
    if ($search && $_GET['s'] != 2)
    {    
        echo "<span class='sc'>";
        echo "<br />&nbsp;&nbsp;&nbsp;<a href=\"/fhiiqm/as_report.php\" target=\"_self\" title=\"Berichte\" class='sc'>&laquo; zur Berichts&uuml;bersicht</a>";
        echo "&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;<a href=\"" . $_SERVER["PHP_SELF"] . "\" target=\"_self\" title=\"Gefgruppe-Gef.-Pic\" class=\"sc\">neuer Bericht Gef&auml;hrdungsgruppe - Gef&auml;hrdung - Piktogramm</a>\n";    
        echo "</span>";
    }
    echo "<div align='center'>\n";
    echo "<p><b>(5b) Bericht Gef&auml;hrdungsgruppe - Gef&auml;hrdung - Piktogramm</b></p>\n";
    echo "</div>\n";
    

    if (!$search)
    {
?>
        <div align="center">
        <p>Bitte Kriterien f&uuml;r die Suche w&auml;hlen</p>
        <form action="<?php $_SERVER['PHP_SELF'] ?>" method="post" enctype="application/x-www-form-urlencoded" name="form_as_report.php" target="_self">	
        <table width="50%" border="0" cellspacing="3" cellpadding="3">
            <tr>
                <td>Gef&auml;hrdungs-Gruppe</td>
                <td><select name="rag[gru]" onchange="this.form.submit();">
                    <?php 
                        if ($rag["atyp"] == -1) $select = " selected='selected' "; else $select = "";
                        echo "<option $select value=\"-1\"></option>\n";
                        $sql = "SELECT gefahrgr_ID,gefahrgr_bez FROM fhiiqm.Gefahr_Gruppe ORDER BY 1";
                        if ($result = $dbc->queryObjectArray($sql))
                        {
                            foreach ($result as $row)
                            {
                                $select = ($row->gefahrgr_ID == $rag['gru'])? " selected='selected'" : ""; 
                                echo "<option$select value=\"$row->gefahrgr_ID\">$row->gefahrgr_ID - $row->gefahrgr_bez</option>\n";
                            }
                        }
                    ?>
                    </select>
                </td>
            </tr>
            <tr>
                <td>Gef&auml;hrdung</td>
                <td><select name="rag[gef]">
                    <?php 
                        if ($rag["gru"] && $rag["gru"]>0) $wher = " WHERE gefahrgr_ID = " . $rag["gru"]; else $wher = "";
                        if ($rag["gef"] == -1) $select = " selected='selected' "; else $select = "";
                        echo "<option $select value=\"-1\"></option>\n";
                        $sql = "SELECT gefahr_ID,gefahrgr_ID,gefahr_bez FROM fhiiqm.Gefahr $wher
                                ORDER BY CONVERT(substring(gefahr_ID,1,INSTR(gefahr_ID,'.')-1),DECIMAL),CONVERT(SUBSTRING(gefahr_ID,INSTR(gefahr_ID,'.')+1),DECIMAL);";
                        if ($result = $dbc->queryObjectArray($sql))
                        {
                            foreach ($result as $row)
                            {
                                $select = ($row->gefahr_ID == $rag['gef'])? " selected='selected'" : ""; 
                                echo "<option$select value=\"$row->gefahr_ID\">$row->gefahr_ID - $row->gefahr_bez</option>\n";
                            }
                        }
                    ?>
                    </select>
                </td>
            </tr>
            <tr> 
                  <td>Verkn&uuml;pfung</td>
                  <td>UND&nbsp;&nbsp;&nbsp;
                    <input type="radio" name="rag[bind]" value="AND" <?php if (isset($rag["bind"]) && $rag["bind"]=="AND") echo "checked"; else  echo "checked";?>>
                  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ODER&nbsp;&nbsp;&nbsp;
                    <input type="radio" name="rag[bind]" value="OR" <?php if (isset($rag["bind"]) && $rag["bind"]=="OR") echo "checked"; ?>></td>
            </tr>
            <tr>
                <td>Sortierung nach<br />(in dieser Reihenfolge)</td><td>
            <?php
                $sort = array("-1"=>"","1"=>"Gefährdungsgruppe","2"=>"Gef&auml;hrdung");
                for ($i=1; $i<3; $i++)
                { 
                  echo "$i.&nbsp;&nbsp;<select name='rag[sort$i]'>\n";
                  foreach ($sort as $key=>$val)
                  {
                    $rsort = "sort" . $i;
                    if ($rag[$rsort] == $val) $select= " selected"; else $select = "";
                    echo "<option$select value='$key'>$val</option>\n";
                  }
                  echo "</select>&nbsp;&nbsp;&nbsp;&nbsp;\n";
                } 
                echo "</td></tr>\n";
        
                $azeil = array(10=>'10',20=>'20',25=>'25',50=>'50',100=>'100',9999=>'alle'); // Anzahl gezeigter rows
                echo "<tr><td>Zeilen/Seite?</td><td><select name='rag[z]'>\n";
                if (!$rag['z']) $rag['z'] = 9999;
                foreach ($azeil as $key=>$val)
                {
                    if ($key == $rag['z']) $select = "selected"; else $select = "";
                    echo "<option $select value='$key'>$val</option>\n";
                }
                echo "</select></td></tr>\n";
        
            ?>
            <tr> 
                <td>&nbsp;</td>
                <td><input class="button" type="submit" name="search" value="Bericht erstellen"/></td>
            </tr> 
        </table>
        </div>
        </form>

<?php        
    }
    else
    {
        echo "<div align='center'>\n";
        $sql = "SELECT gg.gefahrgr_ID,g.gefahr_ID,gefahrgr_bez,gefahr_bez,gefahr_pic,gefahr_pic_bez
                FROM Gefahr_Gruppe gg LEFT OUTER JOIN Gefahr g ON gg.gefahrgr_ID=g.gefahrgr_ID ";
        
        $lim = " LIMIT $start,$zeil";
        
        if (!$rag["bind"]) $bind = " AND "; else $bind = $rag["bind"];
        
        if ($rag["gru"]> -1)
        { 
            if ($where) $where .= "$bind g.gefahrgr_ID = '$rag[gru]' "; else $where = " g.gefahrgr_ID = '$rag[gru]' ";
            $krit = " [Gef&auml;hrdungsgruppe = '" . $dbc -> querySingleItem("SELECT gefahrgr_bez FROM Gefahr_Gruppe WHERE gefahrgr_ID='".$rag['gru'] ."'")."']";
        }    
        if ($rag["gef"]> -1)
        { 
            $where = " g.gefahr_ID = '$rag[gef]' ";
            if ($krit) $bd = " ".$bind; else $bd = "";
            $krit .= "$bd [Gef&auml;hrdung = '" . $dbc -> querySingleItem("SELECT gefahr_bez FROM Gefahr WHERE gefahr_ID='".$rag['gef'] ."'")."']";
        }   
        if ($where) $where = " WHERE ($where)";

        if ($rag["sort1"]>0 || $rag["sort2"]>0 || $rag["sort3"]>0)
        {
            if ($rag["sort1"]>0) $ord  = " ORDER BY " . $rag["sort1"];
            if ($rag["sort2"]>0) $ord .= ",".$rag["sort2"];
            if ($rag["sort3"]>0) $ord .= ",".$rag["sort3"];
        }
        $sql .= $where;
        if ($ord && strpos($ord,'2')>0) $ord = str_replace("2","CONVERT(substring(g.gefahr_ID,1,INSTR(g.gefahr_ID,'.')-1),DECIMAL),CONVERT(SUBSTRING(g.gefahr_ID,INSTR(g.gefahr_ID,'.')+1),DECIMAL)",$ord);
        $sql .= $ord . $lim;
//        echo "sql = $sql<br />\n";
        $result = $dbc ->queryObjectArray($sql);
        
        if ($krit )echo "Suchergebnis f&uuml;r $krit"; else echo "Suchergebnis\n";
        $ianz = $dbc -> querySingleItem("SELECT COUNT(*) 
                                            FROM Gefahr_Gruppe gg LEFT OUTER JOIN Gefahr g 
                                            ON gg.gefahrgr_ID=g.gefahrgr_ID $where");
        printf ("<p>Anzahl: %s</p>", $ianz);

        if ($result)
        {
            include ($_SERVER['DOCUMENT_ROOT'] ."/fhiiqm/inc/func_lib.inc.php");
            
    		$bg1 = "#F8F8F8";
    		$bg2 = "#DEDFE1";
    		$bg = "#FFFFFF";
            echo "<table border='1' width='50%' cellspacing='0' cellpadding='2'>\n";
            // Listenkopf
            echo "<tr bgcolor='#68ACBF'>";
            echo "<th>Gef&auml;hrdungsgruppe</th>";
            echo "<th>Gef&auml;hrdung</th>";
            echo "<th>pic</th>";
            echo "<th>pic_bez</th>";
            echo "</tr>\n";

            foreach ($result as $row)
            {
                $gid   = $row->gefahr_ID;
                if ($gru != $row->gefahrgr_ID)
                {
        			if ($bg == $bg1) $bg = $bg2; else $bg = $bg1;
                    echo "<tr bgcolor='" . $bg . "'>";
                    echo "<td>$row->gefahrgr_ID - $row->gefahrgr_bez</td>";
                    echo "<td nowrap='1'>$row->gefahr_ID - $row->gefahr_bez</td>";
                    $gid = urlencode(trim($gid));
                    echo "<td><img name='gefahr' width='30px' src=" . "'/fhiiqm/inc/show_img_gef.inc.php?gid=$gid' alt='$gef' title='$gef'></td>";
                    echo "<td>$row->gefahr_pic_bez</td></tr>\n";
                }
                elseif ($gru == $row->gefahrgr_ID && $gfid != $row->gefahr_ID)
                {
        			if ($bg == $bg1) $bg = $bg2; else $bg = $bg1;
                    echo "<tr bgcolor='" . $bg . "'>";
                    echo "<td>&nbsp;</td>";
                    echo "<td nowrap='1'>$row->gefahr_ID - $row->gefahr_bez</td>";
                    $gid = urlencode(trim($gid));
                    echo "<td><img name='gefahr' width='30px' src=" . "'/fhiiqm/inc/show_img_gef.inc.php?gid=$gid' alt='$gef' title='$gef'></td>";
                    echo "<td>$row->gefahr_pic_bez</td></tr>\n";
                }
                $gfid   = $row->gefahr_ID;
                $gru    = $row->gefahrgr_ID;
            }
            echo "</table>\n";
            echo "<p></p><table width=60%><tr><td class='right'><a href=\"javascript:window.print()\" class='sc'>
                <img src=\"/fhiiqm/img/printer.png\" alt=\"Bericht drucken\" border=\"0\" align=\"right\" title=\"Bericht drucken\"></a></td></tr></table>";
            echo "</div>\n";
        
            echo "<br />&nbsp;&nbsp;&nbsp;";
            if ($search != 2) // Aufruf aus fhiiqm
            {    
                // Parameter aus $_GET fuer weitere Seiten
                $_GET["s"] = 1; // bewirkt weitere Suche
                foreach ($_GET as $key=>$val)
                {
                    if ($key != "st") $liste .= "&" . $key ."=".$val;
                }    
                // Links auf andere Seiten generieren
                liste_links($start,$zeil,$ianz,$liste);
            }
        }
        else
        {
            echo "<p class='red'>&nbsp;&nbsp;&nbsp;Leider gibt es kein Ergebnis für die von Ihnen gewählten Kriterien!</p>";
            echo "</div>\n";
        }
        if ($search != 2)
        {    
            echo "<span class='sc'>";
            echo "<br /><br />&nbsp;&nbsp;&nbsp;<a href=\"/fhiiqm/as_report.php\" target=\"_self\" title=\"Berichte\" class='sc'>&laquo; zur Berichts&uuml;bersicht</a>";
            echo "&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;<a href=\"" . $_SERVER["PHP_SELF"] . "\" target=\"_self\" title=\"Gefgruppe-Gef.-Pic\" class=\"sc\">neuer Bericht Gef&auml;hrdungsgruppe - Gef&auml;hrdung - Piktogramm</a>\n";    
            echo "</span>";
        }
        else
            echo "<a href='javascript:history.back();' onMouseOver=\"{window.status='Zur&uuml;ck'; return true;}\">&laquo; Zur&uuml;ck</a>";

    }
?>
</body>
</html>