fhiiqm/test/date_mod.php
changeset 1 6288d5685bff
equal deleted inserted replaced
0:ef68113ff309 1:6288d5685bff
       
     1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
       
     2 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
       
     3 
       
     4 <head>
       
     5 	<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
       
     6    	<link href="../css/db.css" rel="STYLESHEET" type="TEXT/CSS" /> 
       
     7 	<meta name="author" content="Bettina Schwarzer" />
       
     8 
       
     9 	<title>Test Vertragsablauf</title>
       
    10 </head>
       
    11 
       
    12 <body>
       
    13 <h3>&nbsp;&nbsp;&nbsp;&Uuml;bersicht Vertragsende</h3>
       
    14 <?php
       
    15 
       
    16 /**
       
    17  * @author Bettina Schwarzer
       
    18  * @copyright 2011
       
    19  *
       
    20  * Berechnung von Datum-Werten
       
    21  * SQL: SELECT *,DATEDIFF(contract_end,DATE_ADD(CURDATE(),INTERVAL 7 DAY)) AS days FROM `fhiiqm`.`Vertrag`
       
    22 
       
    23  */
       
    24 
       
    25 
       
    26 	include_once($_SERVER['DOCUMENT_ROOT'] ."/fhiiqm/inc/dbconnect.inc.php");
       
    27 	if (!isset($dbc) || !$dbc) $dbc = new dbconnection();
       
    28 
       
    29     $sql = "SELECT contract_ID, contract_name, contract_begin, contract_end FROM Vertrag ORDER BY 2"; 
       
    30     if ($result = $dbc ->queryObjectArray($sql))
       
    31     {
       
    32         $now = new DateTime; // heute
       
    33         $now = $now->add(new DateInterval('P7D')); //7 Tage zu heute addieren
       
    34         echo "&nbsp;&nbsp;&nbsp;'heute' + 7 Tage = " . $now->format('d.m.Y') ."<br />";
       
    35         
       
    36         foreach ($result as $row)
       
    37         {
       
    38             if (isset($row->contract_end) && $row->contract_end)
       
    39             {
       
    40                 $cend = new DateTime($row->contract_end);
       
    41     //            list($year,$month,$day) = explode($row->contract_end,"-");
       
    42     //            $cend = $cend -> setDate($year,$month,$day);
       
    43                 $diff = $cend -> diff($now);
       
    44     //            $diff1 = $now -> diff($cend); // $diff = $diff1
       
    45     //            print_r($diff);
       
    46                 if ($cend <= $now && $diff->format('%a') < 8)
       
    47                     echo "<p class='red'>&nbsp;&nbsp;&nbsp;Vertrag <b>$row->contract_name</b> endet in <b> ". (7 - $diff->format('%a')) . "</b> Tagen!</p>\n";
       
    48                 elseif ($cend > $now && $diff->format('%a') < 8)
       
    49                     echo "<p class='red'>&nbsp;&nbsp;&nbsp;Vertrag <b>$row->contract_name</b> endet in <b> ". $diff->format('%a') . "</b> Tagen!</p>\n";
       
    50                 elseif ($cend > $now)
       
    51                 {
       
    52                     if ($diff->format('%a') > 365-7) 
       
    53                         echo "<p>&nbsp;&nbsp;&nbsp;Vertrag <b>$row->contract_name</b> läuft noch länger als ein Jahr. </p>\n";
       
    54                     else
       
    55                         echo "<p>&nbsp;&nbsp;&nbsp;Vertrag <b>$row->contract_name</b> endet erst in " . ($diff->format('%a') + 7) . " Tagen.</p>\n";
       
    56                 }
       
    57                 else
       
    58                     echo "<p>&nbsp;&nbsp;&nbsp;Vertrag <b>$row->contract_name</b> ist bereits ausgelaufen.</p>\n";
       
    59             }
       
    60             else
       
    61                 echo "<p>&nbsp;&nbsp;&nbsp;kein Endedatum für <b>$row->contract_name</b> angegeben!</p>\n";
       
    62                  
       
    63         }
       
    64     }
       
    65 ?>
       
    66 </body>
       
    67 </html>