fhiiqm/report/abt_raum_rt_report.php
changeset 28 8d8bce56918f
child 29 72f79dab938e
equal deleted inserted replaced
27:d92bbe898f32 28:8d8bce56918f
       
     1 <?php
       
     2 
       
     3 /**
       
     4  * @author Bettina Schwarzer, Fritz-Haber-Institut
       
     5  * @copyright 06/2012
       
     6  * 
       
     7  * Report Raeume, Raumtyp, Abteilung (Raum-Arb.-Gruppen)
       
     8  * $_GET['s']=2 - Aufruf aus adm-fhi-Seite ohne Anmeldung
       
     9  * 
       
    10  */
       
    11 
       
    12     error_reporting(E_ALL ^ E_NOTICE);
       
    13     
       
    14     if (!isset($_GET['s']) || $_GET['s'] != 2 )
       
    15     {
       
    16         session_start();
       
    17         if (! isset($_SESSION["userid"]))
       
    18         { 
       
    19             include_once ($_SERVER['DOCUMENT_ROOT'] ."/fhiiqm/inc/func_lib.inc.php");	
       
    20             login($_SERVER["PHP_SELF"]);
       
    21             exit;
       
    22         }
       
    23         
       
    24         if (is_null($_SESSION["recht"]) || (!is_null($_SESSION["recht"]) && !in_array("rr",$_SESSION["recht"]) && !in_array("re",$_SESSION["recht"])))
       
    25         {
       
    26             header("Location: start.php");
       
    27             exit;
       
    28         }
       
    29     }        
       
    30 	include_once($_SERVER['DOCUMENT_ROOT'] ."/fhiiqm/inc/dbconnect.inc.php");
       
    31 	if (!isset($dbc) || !$dbc) $dbc = new dbconnection();
       
    32     
       
    33 
       
    34 ?>
       
    35 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
       
    36 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
       
    37 
       
    38 <head>
       
    39 	<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
       
    40    	<link href="/fhiiqm/css/db.css" rel="STYLESHEET" type="TEXT/CSS"  media="screen"/> 
       
    41    	<link href="/fhiiqm/css/db_print.css" rel="STYLESHEET" type="TEXT/CSS"  media="print"/> 
       
    42 	<title>Report Abteilung - Raum, Raumtyp</title>
       
    43 </head>
       
    44 
       
    45 <body>
       
    46 
       
    47 <?php    
       
    48     echo "&nbsp;";  
       
    49     if (!isset($_GET['s']) || $_GET['s'] != 2 )
       
    50     {
       
    51         echo "<div class=\"float-br smaller\" valign='top'>";
       
    52         echo "&nbsp;&nbsp;&nbsp;user: " . $_SESSION["userid"];
       
    53         echo "&nbsp;&nbsp;&nbsp;<a class='sc' href='/fhiiqm/logout.php' title='Session beenden'>logout</a></div>\n";
       
    54     }
       
    55     echo "<div class=\"float-r\"><img src=\"/fhiiqm/img/role.png\" border=\"0\" alt=\"Raum\" title=\"Raum\"/></div>\n";
       
    56 
       
    57     $rag    = $_POST["rag"];    // Parameter aus Form
       
    58     $search = $_POST["search"];
       
    59     if (!$search) $search =  $_GET["s"];
       
    60 
       
    61     $zeil = $rag["z"];
       
    62     if (!$zeil) $zeil = $_GET["z"];
       
    63     if (!$zeil) $zeil = 9999; // Anzahl der gezeigten Zeilen
       
    64     $start = $_GET["st"];   // Start bei DS $start+1
       
    65     if (!$start) $start=0;
       
    66     
       
    67 
       
    68     if (!is_array($rag))
       
    69     {
       
    70         $rag["abt"]     = $_GET["a"];
       
    71         $rag["geb"]     = $_GET["g"];
       
    72         $rag["rtyp"]   = $_GET["t"];
       
    73         $rag["bind"]    = $_GET["b"];
       
    74         $rag["sort1"]   = $_GET["s1"];
       
    75         $rag["sort2"]   = $_GET["s2"];
       
    76         $rag["sort3"]   = $_GET["s3"];
       
    77     }
       
    78     $_GET["a"] = $rag["abt"];
       
    79     $_GET["g"] = $rag["geb"];
       
    80     $_GET["t"] = $rag["rtyp"];
       
    81     $_GET["b"] = $rag["bind"];
       
    82     $_GET["s1"] = $rag["sort1"];
       
    83     $_GET["s2"] = $rag["sort2"];
       
    84     $_GET["s3"] = $rag["sort3"];
       
    85     $_GET["z"]  = $zeil;
       
    86    
       
    87     if ($search && $_GET['s'] != 2)
       
    88     {    
       
    89         echo "<span class='sc'>";
       
    90         echo "<br />&nbsp;&nbsp;&nbsp;<a href=\"/fhiiqm/raum_report.php\" target=\"_self\" title=\"Berichte\" class='sc'>&laquo; zur Berichts&uuml;bersicht</a>";
       
    91         echo "&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;<a href=\"" . $_SERVER["PHP_SELF"] . "\" target=\"_self\" title=\"Raum-Typ\" class=\"sc\">neuer Abteilung - Raum, Raumtyp Bericht</a>\n";    
       
    92         echo "</span>";
       
    93     }
       
    94     echo "<div align='center'>\n";
       
    95     echo "<p><b>Bericht Abteilung - Raum, Raumtyp</b></p>\n";
       
    96     echo "</div>\n";
       
    97     
       
    98 
       
    99     if (!$search)
       
   100     {
       
   101 ?>
       
   102         <div align="center">
       
   103         <p>Bitte Kriterien f&uuml;r die Suche w&auml;hlen</p>
       
   104         <form action="<?php $_SERVER['PHP_SELF'] ?>" method="post" enctype="application/x-www-form-urlencoded" name="form_raum" target="_self">	
       
   105         <table width="50%" border="0" cellspacing="3" cellpadding="3">
       
   106             <tr>
       
   107                 <td>Abteilung</td>
       
   108                 <td>
       
   109                     <select name="rag[abt]" size="1">
       
   110                     <?php 
       
   111                         if ($rag["abt"] == -1) $select = " selected "; else $select = "";
       
   112                         echo "<option $select value=\"-1\"></option>\n";
       
   113                         $sql = "SELECT abt_ID, abt_name, abt_long FROM Abteilung ORDER BY 1";
       
   114                         if ($result = $dbc->queryObjectArray($sql))
       
   115                         {
       
   116                             foreach ($result as $row)
       
   117                             {
       
   118                                 if ($row->abt_ID == $rag['abt'])
       
   119             					   echo "<option selected value=\"$row->abt_ID\">$row->abt_name - $row->abt_long</option>\n";
       
   120             				    else
       
   121             					   echo "<option value=\"$row->abt_ID\">$row->abt_name - $row->abt_long</option>\n";
       
   122                             }
       
   123                         }
       
   124                     ?>
       
   125                     </select>
       
   126                 </td>
       
   127             </tr>
       
   128             <tr>
       
   129                 <td>Haus</td>
       
   130                 <td>
       
   131                     <select name="rag[geb]" size="1">
       
   132                     <?php 
       
   133                         if ($rag["geb"] == -1) $select = " selected "; else $select = "";
       
   134                         echo "<option $select value=\"-1\"></option>\n";
       
   135                         $sql = "SELECT geb_ID, geb_name FROM Haus ORDER BY 1";
       
   136                         if ($result = $dbc->queryObjectArray($sql))
       
   137                         {
       
   138                             foreach ($result as $row)
       
   139                             {
       
   140                                 if ($row->geb_ID == $rag['geb'])
       
   141             					   echo "<option selected value=\"$row->geb_ID\">$row->geb_ID - $row->geb_name</option>\n";
       
   142             				    else
       
   143             					   echo "<option value=\"$row->geb_ID\">$row->geb_ID - $row->geb_name</option>\n";
       
   144                             }
       
   145                         }
       
   146                     ?>
       
   147                     </select>
       
   148                 </td>
       
   149             </tr>
       
   150             <tr>
       
   151                 <td>Raumtyp</td>
       
   152                 <td><select name="rag[rtyp]">
       
   153                 <?php 
       
   154                     if ($rag["rtyp"] == -1) $select = " selected "; else $select = "";
       
   155                     echo "<option $select value=\"-1\"></option>\n";
       
   156                     $sql = "SELECT raumtyp_ID,raumtyp_bez FROM fhiiqm.Raum_Typ ORDER BY 1";
       
   157                     if ($result = $dbc->queryObjectArray($sql))
       
   158                     {
       
   159                         foreach ($result as $row)
       
   160                         {
       
   161                             if ($row->raumtyp_ID == $rag['rtyp'])
       
   162         					   echo "<option selected value=\"$row->raumtyp_ID\">$row->raumtyp_ID - $row->raumtyp_bez</option>\n";
       
   163         				    else
       
   164         					   echo "<option value=\"$row->raumtyp_ID\">$row->raumtyp_ID - $row->raumtyp_bez</option>\n";
       
   165                         }
       
   166                     }
       
   167                 ?>
       
   168                 </select></td>
       
   169             </tr>
       
   170             <tr> 
       
   171                   <td>Verkn&uuml;pfung</td>
       
   172                   <td>UND&nbsp;&nbsp;&nbsp;
       
   173                     <input type="radio" name="rag[bind]" value="AND" <?php if (isset($rag["bind"]) && $rag["bind"]=="AND") echo "checked"; else  echo "checked";?>>
       
   174                   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ODER&nbsp;&nbsp;&nbsp;
       
   175                     <input type="radio" name="rag[bind]" value="OR" <?php if (isset($rag["bind"]) && $rag["bind"]=="OR") echo "checked"; ?>></td>
       
   176             </tr>
       
   177             <tr>
       
   178                 <td>Sortierung nach<br />(in dieser Reihenfolge)</td><td>
       
   179             <?php
       
   180                 $sort = array("-1"=>"","1"=>"Geb&auml;ude","2"=>"Raum-Nr.","3"=>"Raum-Typ");
       
   181                 for ($i=1; $i<4; $i++)
       
   182                 { 
       
   183                   echo "$i.&nbsp;&nbsp;<select name='rag[sort$i]'>\n";
       
   184                   foreach ($sort as $key=>$val)
       
   185                   {
       
   186                     $rsort = $sort . $i;
       
   187                     if ($rag[$rsort] == $i) $select= " selected"; else $select = "";
       
   188                     echo "<option$select value='$key'>$val</option>\n";
       
   189                   }
       
   190                   echo "</select>&nbsp;&nbsp;&nbsp;&nbsp;\n";
       
   191                 } 
       
   192                 echo "</td></tr>\n";
       
   193         
       
   194                 $azeil = array(10=>'10',20=>'20',25=>'25',50=>'50',100=>'100',9999=>'alle'); // Anzahl gezeigter rows
       
   195                 echo "<tr><td>Zeilen/Seite?</td><td><select name='rag[z]'>\n";
       
   196                 if (!$rag['z']) $rag['z'] = 9999;
       
   197                 foreach ($azeil as $key=>$val)
       
   198                 {
       
   199                     if ($key == $rag['z']) $select = "selected"; else $select = "";
       
   200                     echo "<option $select value='$key'>$val</option>\n";
       
   201                 }
       
   202                 echo "</select></td></tr>\n";
       
   203         
       
   204             ?>
       
   205             <tr> 
       
   206                 <td>&nbsp;</td>
       
   207                 <td><input class="button" type="submit" name="search" value="Bericht erstellen"/></td>
       
   208             </tr> 
       
   209         </table>
       
   210         </div>
       
   211         </form>
       
   212 <?php
       
   213     }
       
   214     else
       
   215     {
       
   216         echo "<div align='center'>\n";
       
   217         
       
   218         $sql = "SELECT geb_ID,raum_nr,raum_name,r.raumtyp_ID,raumtyp_bez,rag_bez,abt_name,ra.rag_ID,ra.abt_ID
       
   219                 FROM RaumArb_Gruppe ra
       
   220                 LEFT OUTER JOIN Abteilung a ON ra.abt_ID=a.abt_ID
       
   221                 LEFT OUTER JOIN Raum_RaumArbGruppe rr ON ra.rag_ID=rr.rag_ID
       
   222                 LEFT OUTER JOIN Raum r ON rr.raum_ID=r.raum_ID
       
   223                 LEFT OUTER JOIN Raum_Typ t ON r.raumtyp_ID=t.raumtyp_ID";        
       
   224 
       
   225         $lim = " LIMIT $start,$zeil";
       
   226         
       
   227         if (!$rag["bind"]) $bind = " AND "; else $bind = $rag["bind"];
       
   228         
       
   229         if ($rag["geb"]> -1) $where = " geb_ID = '$rag[geb]' ";
       
   230         if ($rag["abt"]> -1) 
       
   231             if ($where) $where .= "$bind ra.abt_ID = '$rag[abt]' "; else $where = " ra.abt_ID = '$rag[abt]' ";
       
   232         if ($rag["rtyp"]> -1)
       
   233             if ($where) $where .= "$bind r.raumtyp_ID = '$rag[rtyp]' "; else $where = " r.raumtyp_ID = '$rag[rtyp]' ";
       
   234         if ($where) $where = " WHERE $where";
       
   235         
       
   236         if ($rag["sort1"]>0 || $rag["sort2"]>0 || $rag["sort3"]>0)
       
   237         {
       
   238             if ($rag["sort1"]>0) $ord  = $rag["sort1"];
       
   239             if ($rag["sort2"]>0) $ord .= ",".$rag["sort2"];
       
   240             if ($rag["sort3"]>0) $ord .= ",".$rag["sort3"];
       
   241         }
       
   242         
       
   243         $sql .= $where;
       
   244 //        $ianz = $dbc -> numrows($sql); 
       
   245         if ($ord) $ord = " ORDER BY 8, ".$ord; else $ord = " ORDER BY 8 ";
       
   246         $sql .= $ord . $lim;
       
   247 //        echo "sql = $sql<br />\n";
       
   248         $result = $dbc ->queryObjectArray($sql);
       
   249         
       
   250         if ($rag["abt"] > -1)
       
   251         { 
       
   252             $abtn = $dbc -> querySingleItem("SELECT abt_name FROM Abteilung WHERE abt_ID=".$rag["abt"]);
       
   253             $krit = " [Abteilung = '$abtn']";
       
   254         }
       
   255         if ($rag["geb"] > -1) 
       
   256         {
       
   257             if ($krit) $bd = " ".$bind; else $bd = "";
       
   258             $krit .= $bd." [Geb&auml;ude = '" . $rag["geb"] ."']";
       
   259         }
       
   260         if ($rag["rtyp"] > -1)
       
   261         { 
       
   262             if ($krit) $bd = " ".$bind; else $bd = "";
       
   263             $rtn = $dbc -> querySingleItem("SELECT raumtyp_bez FROM Raum_Typ WHERE raumtyp_ID='".$rag["rtyp"]."'");
       
   264             $krit .= $bd." [Raum-Typ = '$rtn']";
       
   265         }
       
   266         if ($krit )echo "Suchergebnis f&uuml;r $krit"; else echo "Suchergebnis\n";
       
   267         $ianz = $dbc -> querySingleItem("SELECT COUNT(*)
       
   268                                         FROM RaumArb_Gruppe ra
       
   269                                         LEFT OUTER JOIN Abteilung a ON ra.abt_ID=a.abt_ID
       
   270                                         LEFT OUTER JOIN Raum_RaumArbGruppe rr ON ra.rag_ID=rr.rag_ID
       
   271                                         LEFT OUTER JOIN Raum r ON rr.raum_ID=r.raum_ID
       
   272                                         LEFT OUTER JOIN Raum_Typ t ON r.raumtyp_ID=t.raumtyp_ID $where");
       
   273         printf ("<p>Anzahl gefundener R&auml;ume: %s</p>", $ianz);
       
   274 
       
   275         if ($result)
       
   276         {
       
   277             include ($_SERVER['DOCUMENT_ROOT'] ."/fhiiqm/inc/func_lib.inc.php");
       
   278             
       
   279     		$bg1 = "#F8F8F8";
       
   280     		$bg2 = "#DEDFE1";
       
   281     		$bg = "#FFFFFF";
       
   282             echo "<table border='1' cellspacing='0' cellpadding='2'>\n";
       
   283             // Listenkopf
       
   284             echo "<tr bgcolor='#68ACBF'>";
       
   285             if (!$rag['abt'] || $rag['abt'] == -1) echo "<th>Abteilung</th>";
       
   286             echo "<th>Arbeitsgruppe</th>";
       
   287             if (!$rag['geb'] || $rag['geb'] == -1) echo "<th>Geb&auml;ude</th>";
       
   288             echo "<th>Raum-Nr.</th>";
       
   289             echo "<th>Raum-Bezeichnung</th>";
       
   290             if (!$rag['rtyp'] || $rag['rtyp'] == -1) echo "<th>Raum-Typ</th>";
       
   291             echo "</tr>\n";
       
   292 
       
   293             foreach ($result as $row)
       
   294             {
       
   295                 if ($row->rag_ID != $rid)
       
   296                 {
       
   297                     if ($rid) echo "</td></tr>\n"; 
       
   298         			if ($bg == $bg1) $bg = $bg2; else $bg = $bg1;
       
   299                     echo "<tr bgcolor='" . $bg . "'>"; 
       
   300                     if (!$rag['abt'] || $rag['abt'] == -1) echo "<td>$row->abt_name";
       
   301                     echo "<td>$row->rag_bez";
       
   302                     if (!$rag['geb'] || $rag['geb'] == -1) echo "<td>$row->geb_ID</td>";
       
   303                     echo "<td>$row->raum_nr</td>";
       
   304                     echo "<td>$row->raum_name</td>";
       
   305                     if (!$rag['rtyp'] || $rag['rtyp'] == -1) echo "<td>$row->raumtyp_ID - $row->raumtyp_bez</td></tr>\n";
       
   306                 }
       
   307                 else
       
   308                 {
       
   309                     echo "<tr bgcolor='" . $bg . "'>";
       
   310                     if (!$rag['abt'] || $rag['abt'] == -1) echo "<td>&nbsp;</td><td>&nbsp;</td>"; else echo "<td>&nbsp;</td>";
       
   311                     if (!$rag['geb'] || $rag['geb'] == -1) echo "<td>$row->geb_ID</td>";
       
   312                     echo "<td>$row->raum_nr</td>";
       
   313                     echo "<td>$row->raum_name</td>";
       
   314                     if (!$rag['rtyp'] || $rag['rtyp'] == -1) echo "<td>$row->raumtyp_ID - $row->raumtyp_bez</td></tr>\n";
       
   315                 }    
       
   316                $rid = $row->rag_ID;          
       
   317             }
       
   318             echo "</table>\n";
       
   319             echo "<p></p><table width=60%><tr><td class='right'><a href=\"javascript:window.print()\" class='sc'>
       
   320                 <img src=\"/fhiiqm/img/printer.png\" alt=\"Bericht drucken\" border=\"0\" align=\"right\" title=\"Bericht drucken\"></a></td></tr></table>";
       
   321             echo "</div>\n";
       
   322         
       
   323             echo "<br />&nbsp;&nbsp;&nbsp;";
       
   324             if ($search != 2) // Aufruf aus fhiiqm
       
   325             {    
       
   326                 // Parameter aus $_GET fuer weitere Seiten
       
   327                 $_GET["s"] = 1; // bewirkt weitere Suche
       
   328                 foreach ($_GET as $key=>$val)
       
   329                 {
       
   330                     if ($key != "st") $liste .= "&" . $key ."=".$val;
       
   331                 }    
       
   332                 // Links auf andere Seiten generieren
       
   333                 liste_links($start,$zeil,$ianz,$liste);
       
   334             }
       
   335         }
       
   336         else
       
   337         {
       
   338             echo "<p class='red'>&nbsp;&nbsp;&nbsp;Leider gibt es kein Ergebnis für die von Ihnen gewählten Kriterien!</p>";
       
   339             echo "</div>\n";
       
   340             echo "<br />&nbsp;&nbsp;&nbsp;";
       
   341         }
       
   342         if ($search != 2)
       
   343         {    
       
   344             echo "<span class='sc'>";
       
   345             echo "<br /><br />&nbsp;&nbsp;&nbsp;<a href=\"/fhiiqm/raum_report.php\" target=\"_self\" title=\"Berichte\" class='sc'>&laquo; zur Berichts&uuml;bersicht</a>";
       
   346             echo "&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;<a href=\"" . $_SERVER["PHP_SELF"] . "\" target=\"_self\" title=\"Raum-Typ\" class=\"sc\">neuer Abteilung - Raum, Raumtyp Bericht</a>\n";    
       
   347             echo "</span>";
       
   348         }
       
   349         else
       
   350             echo "<a href='javascript:history.back();' onMouseOver=\"{window.status='Zur&uuml;ck'; return true;}\">&laquo; Zur&uuml;ck</a>";
       
   351     }
       
   352 
       
   353 ?>
       
   354 
       
   355 </body>
       
   356 </html>