fhiiqm/inc/func_lib.inc.php
changeset 1 6288d5685bff
child 10 f538f73ebc37
equal deleted inserted replaced
0:ef68113ff309 1:6288d5685bff
       
     1 <?php
       
     2 
       
     3 /**
       
     4  * @author Bettina Schwarzer,  Fritz-Haber-Institut
       
     5  * @copyright 06/2011
       
     6  * 
       
     7  * 
       
     8  */
       
     9 
       
    10     function tab_column($colnum=2,$bez,$sort,$dir,$fcol=0,$fanr=0,$filtb="",$start="",$anzds="20")
       
    11     {
       
    12       /** beliebige Tabellenspalte mit Sortier-/Filtersymbolen und Links generieren
       
    13         * Parameter
       
    14         * $colnum   SpaltenNr. 
       
    15         * $bez      Spaltenbezeichnung
       
    16         * $sort     aktuelle SortspaltenNr.
       
    17         * $dir      Sortrichtung (ASC/DESC)
       
    18         * $fcol     SpaltenNr. Filter (=0, wenn nicht gefiltert werden soll)
       
    19         * $fanr     aktuelle FilterspaltenNr.
       
    20         * $filtb    Filterbegriff
       
    21         * $start    ab Datensatz $start+1
       
    22         * $anzds    Anzahl angezeigter Datensaetze
       
    23         */
       
    24         
       
    25         if ($colnum == $sort)
       
    26             if ($dir == 'DESC')
       
    27             {
       
    28                 $auf = "auf";
       
    29                 $ab = "ab_activ";
       
    30             }
       
    31             else
       
    32             {
       
    33                 $auf = "auf_activ";
       
    34                 $ab = "ab";
       
    35             }
       
    36         else
       
    37         {
       
    38                 $auf = "auf";
       
    39                 $ab = "ab";
       
    40         }
       
    41         
       
    42         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";
       
    43         if ($fcol>0 && $fanr>0) // Filtern nach Spalte moeglich
       
    44         {
       
    45             if ($fcol == $fanr) $filt = "filter_activ"; else $filt = "filter"; 
       
    46             $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>";;
       
    47         }
       
    48         else
       
    49             $filt="";
       
    50         if ($filtb>'!') $where = "&f=$fanr&b=$filtb"; else $where="";
       
    51         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>            
       
    52                   <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";
       
    53     }
       
    54     
       
    55     function date_obj($jahr,$mon,$tag)
       
    56     {
       
    57        /** prueft auf valides Datum und erstellt DateTime-Objekt, wenn o.k.
       
    58         *  Voraussetzung: Klasse 'DateTime_s' ist included
       
    59         */  
       
    60         include_once ($_SERVER['DOCUMENT_ROOT'] ."/fhiiqm/inc/dbconnect.inc.php");
       
    61         if ($jahr && $mon && $tag)
       
    62         {
       
    63             $dat = $jahr."-".$mon."-".$tag;
       
    64             // Datum valid?
       
    65             if (!$dat = new DateTime_s($dat)) $dat = null;
       
    66         }    
       
    67         else
       
    68             $dat = null;
       
    69         return $dat;
       
    70         
       
    71     }
       
    72     
       
    73     function liste_links($start,$zeil,$anz,$liste)
       
    74     {
       
    75        /** erstellt links zu Seiten einer Liste
       
    76          * Parameter
       
    77          * $start   Beginn bei DS $start+1 (1.DS -> $start=0)
       
    78          * $zeil    Anzahl Zeilen pro Seite
       
    79          * $anz     Anzahl DS gesamt
       
    80          * $liste   weitere Inhalte fuer $_GET-Array
       
    81          */
       
    82         $page = 1;
       
    83         while (($page-1)*$zeil < $anz)
       
    84         {
       
    85             $be = ($page-1)*$zeil+1;
       
    86             if (($page-1)*$zeil+$zeil < $anz) $en = ($page-1)*$zeil+$zeil; else $en = $anz;
       
    87             $st = ($page-1)*$zeil;
       
    88             if ($start == $be-1)
       
    89                 echo "$be - $en";
       
    90             else
       
    91                 echo "<a href=\"" . $_SERVER['PHP_SELF'] . "?st=$st$liste\"  class=\"sc\">$be - $en</a>";
       
    92             if (($page-1)*$zeil+$zeil < $anz) echo "<span class=\"sc\"> | </span>";
       
    93             $page++;
       
    94         }
       
    95 
       
    96     }
       
    97     
       
    98     function login($target,$rechtw=0, $headl="")
       
    99     {
       
   100        /** zeigt Login-Form, prueft userid und passwort, leitet zu gewuenschter Seite weiter
       
   101         *   Parameter
       
   102         *   $target     Zieladresse
       
   103         *   recht       Recht fuer Bearbeitung
       
   104         *   headl       Ueberschrift Loginform
       
   105         */
       
   106           
       
   107        session_start();
       
   108        if ($_SESSION["userid"]) 
       
   109         	{
       
   110         	header("Location: $target");
       
   111         	exit;
       
   112         	}
       
   113         
       
   114         
       
   115         
       
   116         $login  = $_POST["eintragen"];
       
   117         $log    = $_POST["log"];
       
   118         
       
   119         if ($login)
       
   120         {
       
   121         	include_once($_SERVER['DOCUMENT_ROOT'] ."/fhiiqm/inc/dbconnect.inc.php");
       
   122         	if (!isset($dbc) || !$dbc) $dbc = new dbconnection();
       
   123             
       
   124             $stmt = $dbc -> stmtinit();
       
   125             if (is_object($stmt))
       
   126             {
       
   127                 $stmt -> prepare("SELECT userid, pwd FROM userweb WHERE userid = ?");
       
   128                 $stmt -> bind_param('s',$log["user"]);
       
   129                 $result = $stmt -> execute();
       
   130             }
       
   131             if ($result)
       
   132             {
       
   133                 $stmt->bind_result($userid, $pwdmd5);
       
   134                 if ($stmt->fetch()) 
       
   135                 {
       
   136                     if ($pwdmd5 == md5($log["pass"]))
       
   137                     {
       
   138                         // hier fehlt noch Recht!
       
   139                         if ( ! isset($_SESSION["userid"]) ) $_SESSION["userid"] = "";
       
   140                         $_SESSION["userid"] = $userid;
       
   141                 		header("Location: $target");
       
   142                 		exit;
       
   143                     }
       
   144                     else
       
   145                         $err2 = "<br /><span class=\"red\">Passwort ist nicht korrekt</span>\n";
       
   146                 }
       
   147                 else
       
   148                     $err1 = "<br /><span class=\"red\">Username ist nicht korrekt</span>\n";
       
   149        
       
   150             }
       
   151         }
       
   152         if ($err1 || $err2 || !$log)
       
   153         {
       
   154             ?>
       
   155             <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
       
   156             <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
       
   157             
       
   158             <head>
       
   159             	<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
       
   160                	<link href="/fhiiqm/css/db.css" rel="STYLESHEET" type="TEXT/CSS" /> 
       
   161             
       
   162             	<title>Login fhiiqm</title>
       
   163             </head>
       
   164             
       
   165             <body onload="document.flogin.user.focus();">
       
   166             <!--    <div class="float-r"><img src="img/document_mark_as_final.png" border="0" alt="Vertr&auml;ge" title="Vertr&auml;ge"/></div> -->
       
   167             
       
   168             <?php
       
   169                 include ($_SERVER['DOCUMENT_ROOT'] ."/fhiiqm/form/login_form.inc.php");
       
   170             echo "</body>
       
   171             </html>\n";
       
   172         }    
       
   173     }
       
   174        
       
   175 ?>