fhiiqm/report/keytyp_dep_history_report.php
author Bettina Schwarzer <schwarzer@fhi-berlin.mpg.de>
Wed, 31 Jul 2013 15:10:48 +0200
changeset 39 4ce411ed28b6
child 41 9c668cd391fa
permissions -rw-r--r--
+ Keytyp: delDepot, userVW; Korrekturen

<?php

/**
 * @author Bettina Schwarzer, Fritz-Haber-Institut
 * @copyright 07/2013
 * 
 * Report Historie Keytyp in Depots
 */

    error_reporting(E_ALL ^ E_NOTICE);
    
    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("kr",$_SESSION["recht"]) && !in_array("ke",$_SESSION["recht"])))
    {
        header("Location: start.php");
        exit;
    }    

	include_once($_SERVER['DOCUMENT_ROOT'] ."/fhiiqm/inc/dbconnect.inc.php");
	if (!isset($dbc) || !$dbc) $dbc = new dbconnection();
    
    // zulaessige Depots
    $uid = $_SESSION["userid"];
    $sql = "SELECT depot_ID FROM KeyDepot_userweb WHERE userid = '$uid'";
    $res = $dbc -> queryObjectArray($sql);
    foreach ($res as $row)
        $adep[] = $row->depot_ID;

?>
<!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 Historie Schl&uuml;sseltypen</title>
</head>

<body>

<?php    
    echo "&nbsp;";  
    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/key.png\" border=\"0\" alt=\"Keytyp &Uuml:bersicht\" title=\"Schl&uuml;sseltypen im Depot\"/></div>\n";

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

    $zeil = $ky["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($ky))
    {
        $ky["dep"] = $_GET["d"];
        $ky["kt"] = $_GET["k"];
        $ky["bind"]    = $_GET["b"];
        $ky["sort1"]   = $_GET["s1"];
        $ky["sort2"]   = $_GET["s2"];
    }
    $_GET["d"] = $ky["dep"];
    $_GET["k"] = $ky["kt"];
    $_GET["b"] = $ky["bind"];
    $_GET["s1"]= $ky["sort1"];
    $_GET["s2"]= $ky["sort2"];
    $_GET["z"]  = $zeil;
    
    if ($search)
    {    
        echo "<span class='sc'>";
        echo "<br />&nbsp;&nbsp;&nbsp;<a href=\"/fhiiqm/keytyp_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=\"Historie Keytyp\" class=\"sc\">neuer Bericht Historie Schl&uuml;sseltypen</a>\n";    
        echo "</span>";
    }

    echo "<div align='center'>\n";
    echo "<p><b>Bericht Historie Schl&uuml;sseltypen </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_raum" target="_self">	
        <table width="50%" border="0" cellspacing="3" cellpadding="3">
            <tr>
                <td>Depot</td>
                <td><select name="ky[dep]">
                    <?php
                        if ($ky["dep"] == -1) $select = "selected='selected'"; else $select = "";
                        echo "<option $select value=\"-1\"></option>\n";
                        $strdep = "'". implode("','",$adep) ."'";
                        $sql = "SELECT * FROM fhiiqm.KeyDepot WHERE depot_ID IN ($strdep)";
                        if ($res = $dbc -> queryObjectArray($sql))
                            foreach ($res as $row)
                            {
                               if ($row->depot_ID == $ky['dep']) $select = "selected='selected'"; else $select = "";
    					       echo "<option $select value=\"$row->depot_ID\">$row->depot_ID: $row->depot_bez</option>\n";
                            }
                        $beg=0;
                    ?>
                </select>
                </td>
            </tr>
            <tr>
                <td>Schl&uuml;sseltyp</td>
                <td><select name="ky[kt]">
                    <?php
                        if ($ky["kt"] == -1) $select = "selected='selected'"; else $select = "";
                        echo "<option $select value=\"-1\"></option>\n";
                        $sql = "SELECT key_level,keytyp_ID,keytyp_bez
                                        FROM Keytyp 
                                        ORDER BY key_level";
                        if ($res = $dbc -> queryObjectArray($sql))
                            foreach ($res as $row)
                            {
                               if ($row->keytyp_ID == $ky['kt']) $select = "selected='selected'"; else $select = "";
    					       echo "<option $select value=\"$row->keytyp_ID\">$row->key_level - $row->keytyp_ID [$row->keytyp_bez]</option>\n";
                            }
                        $beg=0;
                    ?>
                </select>
            </tr>
            <tr> 
                  <td>Verkn&uuml;pfung</td>
                  <td>UND&nbsp;&nbsp;&nbsp;
                    <input type="radio" name="ky[bind]" value="AND" <?php if (isset($ky["bind"]) && $ky["bind"]=="AND") echo "checked='checked'"; else  echo "checked='checked'";?>>
                  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ODER&nbsp;&nbsp;&nbsp;
                    <input type="radio" name="ky[bind]" value="OR" <?php if (isset($ky["bind"]) && $ky["bind"]=="OR") echo "checked='checked'"; ?>></td>
            </tr>
            <tr>
                <td>Sortierung nach<br />(in dieser Reihenfolge)</td><td>
            <?php
                $sort = array("-1"=>"","4"=>"Depot","1,2"=>"Schl&uuml;sseltyp", "5"=>"Datum");
                for ($i=1; $i<4; $i++)
                { 
                  echo "$i.&nbsp;&nbsp;<select name='ky[sort$i]'>\n";
                  foreach ($sort as $key=>$val)
                  {
                    $rsort = "sort" . $i;
                    if ($ky[$rsort] == $val) $select = "selected='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='ky[z]'>\n";
                if (!$ky['z']) $ky['z'] = 9999;
                foreach ($azeil as $key=>$val)
                {
                    if ($key == $ky['z']) $select = "selected='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 key_level, d.keytyp_ID,keytyp_bez,depot_ID,depot_date,depot_action,depot_anz,depot_bem 
                FROM fhiiqm.Keytyp_Depot d INNER JOIN Keytyp k ON d.keytyp_ID=k.keytyp_ID";

        $lim = " LIMIT $start,$zeil";
        
        if (!$ky["bind"]) $bind = " AND "; else $bind = $ky["bind"];
        
        if ($ky["dep"]> -1) $where = " depot_ID = '$ky[dep]' ";
        if ($ky["kt"]> -1)
            if ($where) $where .= "$bind d.keytyp_ID = '$ky[kt]' "; else $where = " d.keytyp_ID = '$ky[kt]' ";
        if ($where) $where = " WHERE ($where)";
        
        if ($ky["sort1"]>0 || $ky["sort2"]>0)
        {
            if ($ky["sort1"]>0) $ord  = " ORDER BY " . $ky["sort1"];
            if ($ky["sort2"]>0) $ord .= ",".$ky["sort2"];
        }
        
        $sql .= $where;
        $ianz = $dbc -> numrows($sql); 
        $sql .= $ord . $lim;
        $result = $dbc ->queryObjectArray($sql);
        if ($dbc -> error)
        {
            echo "error SELECT: " . $dbc -> error . "<br /><br />";
            echo "sql = $sql<br />\n";
        }
        if ($ky["dep"]> -1) $krit = " [Depot = <b>'" . $ky["dep"] ."'</b>]";
        if ($ky["kt"] > -1)
        { 
            if ($krit) $bd = " ".$bind; else $bd = "";
            $krit .= $bd." [Schl&uuml;sseltyp = <b>'".$ky["kt"]."'</b>]";
        }
        if ($krit )echo "Suchergebnis f&uuml;r $krit"; else echo "Suchergebnis\n";
        printf ("<p>Anzahl Transaktionen: %s</p>", $ianz);

        if ($result)
        {
            include ($_SERVER['DOCUMENT_ROOT'] ."/fhiiqm/inc/func_lib.inc.php");
            $aaction = array("get" => "erhalten", "out" => "ausgegeben", "lost" => "verloren");
            
    		$bg1 = "#F8F8F8";
    		$bg2 = "#DEDFE1";
    		$bg = "#FFFFFF";
            echo "<table border='1' cellspacing='0' cellpadding='2'>\n";
            // Listenkopf
            echo "<tr bgcolor='#68ACBF'>";
            echo "<th>Schl&uuml;sseltyp</th><th>Schl&uuml;sseltyp-Bezeichnung</th>";
            if ($ky["dep"] == -1) echo "<th>Depot</th>";
            echo "<th>Datum</th><th>Aktion</th><th>Anzahl</th><th>Bemerkung</th>";
            foreach ($result as $row)
            {
        		if ($bg == $bg1) $bg = $bg2; else $bg = $bg1;
                echo "<tr bgcolor='" . $bg . "'>";
                echo "<td>$row->key_level - $row->keytyp_ID</td><td>$row->keytyp_bez</td>";
                if ($ky["dep"] == -1) echo "<td>$row->depot_ID</td>";
                $ddate = new DateTime($row->depot_date);
                echo "<td>".$ddate->format("d.m.Y")."</td><td>".$aaction["$row->depot_action"]."</td><td class='right'>$row->depot_anz</td><td>$row->depot_bem</td>"; 
                echo "</tr>";
            }
            echo "</table>\n";
            echo "<p></p><table width=40%><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";
            echo "<br />&nbsp;&nbsp;&nbsp;";
        }
        echo "<span class='sc'>";
        echo "<br /><br />&nbsp;&nbsp;&nbsp;<a href=\"/fhiiqm/keytyp_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=\"Historie Keytyp\" class=\"sc\">neuer Bericht Historie Schl&uuml;sseltypen</a>\n";    
        echo "</span>";
    }        
?>
</body>
</html>