fhiiqm/inc/func_lib.inc.php
changeset 1 6288d5685bff
child 10 f538f73ebc37
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/fhiiqm/inc/func_lib.inc.php	Wed Aug 31 14:22:19 2011 +0200
@@ -0,0 +1,175 @@
+<?php
+
+/**
+ * @author Bettina Schwarzer,  Fritz-Haber-Institut
+ * @copyright 06/2011
+ * 
+ * 
+ */
+
+    function tab_column($colnum=2,$bez,$sort,$dir,$fcol=0,$fanr=0,$filtb="",$start="",$anzds="20")
+    {
+      /** beliebige Tabellenspalte mit Sortier-/Filtersymbolen und Links generieren
+        * Parameter
+        * $colnum   SpaltenNr. 
+        * $bez      Spaltenbezeichnung
+        * $sort     aktuelle SortspaltenNr.
+        * $dir      Sortrichtung (ASC/DESC)
+        * $fcol     SpaltenNr. Filter (=0, wenn nicht gefiltert werden soll)
+        * $fanr     aktuelle FilterspaltenNr.
+        * $filtb    Filterbegriff
+        * $start    ab Datensatz $start+1
+        * $anzds    Anzahl angezeigter Datensaetze
+        */
+        
+        if ($colnum == $sort)
+            if ($dir == 'DESC')
+            {
+                $auf = "auf";
+                $ab = "ab_activ";
+            }
+            else
+            {
+                $auf = "auf_activ";
+                $ab = "ab";
+            }
+        else
+        {
+                $auf = "auf";
+                $ab = "ab";
+        }
+        
+        if ($bez == "Haus") $tip = "Haus: A, B, C, D, E, F, FAB, HAR, K, L, M, N, P, Q, R, S, T, U"; else $tip = "Filter";
+        if ($fcol>0 && $fanr>0) // Filtern nach Spalte moeglich
+        {
+            if ($fcol == $fanr) $filt = "filter_activ"; else $filt = "filter"; 
+            $filt = "&nbsp;&nbsp;<a href='".$_SERVER['PHP_SELF']."?f=$fcol&s=$sort&d=$dir&st=$start&z=$anzds'><img src='/fhiiqm/img/$filt.gif' border='0' width='14' hight='11' alt='$tip' title='$tip'></a>";;
+        }
+        else
+            $filt="";
+        if ($filtb>'!') $where = "&f=$fanr&b=$filtb"; else $where="";
+        echo "<th>$bez&nbsp;<a href='".$_SERVER['PHP_SELF']."?s=$colnum$where&st=$start&z=$anzds'><img src='/fhiiqm/img/$auf.gif' border='0' width='11' hight='11' alt='sort aufsteigend' title='sort aufsteigend'></a>            
+                  <a href='".$_SERVER['PHP_SELF']."?s=$colnum&d=DESC$where&st=$start&z=$anzds'><img src='/fhiiqm/img/$ab.gif' border='0' width='11' hight='11' alt='sort absteigend' title='sort absteigend'></a>$filt</th>\n";
+    }
+    
+    function date_obj($jahr,$mon,$tag)
+    {
+       /** prueft auf valides Datum und erstellt DateTime-Objekt, wenn o.k.
+        *  Voraussetzung: Klasse 'DateTime_s' ist included
+        */  
+        include_once ($_SERVER['DOCUMENT_ROOT'] ."/fhiiqm/inc/dbconnect.inc.php");
+        if ($jahr && $mon && $tag)
+        {
+            $dat = $jahr."-".$mon."-".$tag;
+            // Datum valid?
+            if (!$dat = new DateTime_s($dat)) $dat = null;
+        }    
+        else
+            $dat = null;
+        return $dat;
+        
+    }
+    
+    function liste_links($start,$zeil,$anz,$liste)
+    {
+       /** erstellt links zu Seiten einer Liste
+         * Parameter
+         * $start   Beginn bei DS $start+1 (1.DS -> $start=0)
+         * $zeil    Anzahl Zeilen pro Seite
+         * $anz     Anzahl DS gesamt
+         * $liste   weitere Inhalte fuer $_GET-Array
+         */
+        $page = 1;
+        while (($page-1)*$zeil < $anz)
+        {
+            $be = ($page-1)*$zeil+1;
+            if (($page-1)*$zeil+$zeil < $anz) $en = ($page-1)*$zeil+$zeil; else $en = $anz;
+            $st = ($page-1)*$zeil;
+            if ($start == $be-1)
+                echo "$be - $en";
+            else
+                echo "<a href=\"" . $_SERVER['PHP_SELF'] . "?st=$st$liste\"  class=\"sc\">$be - $en</a>";
+            if (($page-1)*$zeil+$zeil < $anz) echo "<span class=\"sc\"> | </span>";
+            $page++;
+        }
+
+    }
+    
+    function login($target,$rechtw=0, $headl="")
+    {
+       /** zeigt Login-Form, prueft userid und passwort, leitet zu gewuenschter Seite weiter
+        *   Parameter
+        *   $target     Zieladresse
+        *   recht       Recht fuer Bearbeitung
+        *   headl       Ueberschrift Loginform
+        */
+          
+       session_start();
+       if ($_SESSION["userid"]) 
+        	{
+        	header("Location: $target");
+        	exit;
+        	}
+        
+        
+        
+        $login  = $_POST["eintragen"];
+        $log    = $_POST["log"];
+        
+        if ($login)
+        {
+        	include_once($_SERVER['DOCUMENT_ROOT'] ."/fhiiqm/inc/dbconnect.inc.php");
+        	if (!isset($dbc) || !$dbc) $dbc = new dbconnection();
+            
+            $stmt = $dbc -> stmtinit();
+            if (is_object($stmt))
+            {
+                $stmt -> prepare("SELECT userid, pwd FROM userweb WHERE userid = ?");
+                $stmt -> bind_param('s',$log["user"]);
+                $result = $stmt -> execute();
+            }
+            if ($result)
+            {
+                $stmt->bind_result($userid, $pwdmd5);
+                if ($stmt->fetch()) 
+                {
+                    if ($pwdmd5 == md5($log["pass"]))
+                    {
+                        // hier fehlt noch Recht!
+                        if ( ! isset($_SESSION["userid"]) ) $_SESSION["userid"] = "";
+                        $_SESSION["userid"] = $userid;
+                		header("Location: $target");
+                		exit;
+                    }
+                    else
+                        $err2 = "<br /><span class=\"red\">Passwort ist nicht korrekt</span>\n";
+                }
+                else
+                    $err1 = "<br /><span class=\"red\">Username ist nicht korrekt</span>\n";
+       
+            }
+        }
+        if ($err1 || $err2 || !$log)
+        {
+            ?>
+            <!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" /> 
+            
+            	<title>Login fhiiqm</title>
+            </head>
+            
+            <body onload="document.flogin.user.focus();">
+            <!--    <div class="float-r"><img src="img/document_mark_as_final.png" border="0" alt="Vertr&auml;ge" title="Vertr&auml;ge"/></div> -->
+            
+            <?php
+                include ($_SERVER['DOCUMENT_ROOT'] ."/fhiiqm/form/login_form.inc.php");
+            echo "</body>
+            </html>\n";
+        }    
+    }
+       
+?>
\ No newline at end of file