Index: trunk/www/dch/shifteval.php
===================================================================
--- trunk/www/dch/shifteval.php	(revision 17598)
+++ trunk/www/dch/shifteval.php	(revision 17599)
@@ -18,7 +18,11 @@
     else
     {
-        $stopdate="20130209";
+        //$stopdate="20130209";
         $stopdate=date("Ymd");
     }
+    $starttimestamp = new DateTime($startdate);
+    date_add($starttimestamp, date_interval_create_from_date_string("12 hours"));
+    $stoptimestamp = new DateTime($stopdate);
+    date_add($stoptimestamp, date_interval_create_from_date_string("12 hours"));
 
     echo "<body>\n";
@@ -33,4 +37,26 @@
     $db_id = mysql_connect($host, $user, $pw);
 
+    //some parameters for the evaluation
+    $institutesum= array ("1" => 0, "2" => 0, "3" => 0, "4" => 0, "5" => 0 );
+    $users=array();
+    $affiliation=array();
+    $shifthours=array();
+    $shifthourstotal=0;
+
+    //get affiliation of users
+    $queryaffiliation="SELECT userid, Min(instituteid) FROM memberlist.members GROUP BY userid";
+    $resultaffiliation  = mysql_query($queryaffiliation);
+    while ($rowaffiliation = mysql_fetch_row($resultaffiliation))
+        $affiliation[$rowaffiliation[0]]=$rowaffiliation[1];
+    mysql_free_result($resultaffiliation);
+
+    //get username-id connection
+    $queryusers="SELECT username, uid FROM logbook.users ";
+    $resultusers  = mysql_query($queryusers);
+    while ($rowusers = mysql_fetch_row($resultusers))
+        $users[$rowusers[0]]=$rowusers[1];
+    mysql_free_result($resultusers);
+
+    //calculate shift hours
     $querynames="SELECT count(*), u FROM calendar.Data ";
     $querynames.=" WHERE u NOT IN ('ETHZ', 'ISDC', 'UNIDO', 'UNIWUE') ";
@@ -60,5 +86,9 @@
             }
         }
-        echo "<tr>\n<td>".$rownames[1]."</td>\n<td>".$sum."</td>\n</tr>";
+        if ($sum>0)
+        {
+            echo "<tr>\n<td>".$rownames[1]."</td>\n<td>".$sum."</td>\n</tr>";
+            $shifthours[$users[$rownames[1]]]+=$sum;
+        }
     mysql_free_result($resultnights);
     }
@@ -99,4 +129,5 @@
         }
         echo "<tr>\n<td>".$rownames[1]."</td>\n<td>".$sum."</td>\n</tr>";
+        $shifthours[$users[$rownames[1]]]+=$sum;
         mysql_free_result($resultnights);
     }
@@ -150,4 +181,8 @@
         $sumexpert+=$rowexpert[1]/$devide;
     }
+    $shifthours[2]+=$sumdani;
+    $shifthours[3]+=$sumthomas;
+    $shifthours[7]+=$sumjens;
+    $shifthours[11]+=$sumdom;
 
     //echo $sumexpert;
@@ -164,4 +199,57 @@
     echo "</table>\n";
 
+
+    //calculating the shares of the institutes according to the member list
+    $counter=0;
+    $institutes2= array ("1" => 0, "2" => 0, "3" => 0, "4" => 0, "5" => 0 );
+    print_r($institutes);
+
+    while ($starttimestamp<$stoptimestamp)
+    {
+        $queryshare="SELECT instituteid, COUNT(*) FROM memberlist.members ";
+        $queryshare.=" WHERE start < '".$starttimestamp->format('Y-m-d H:i:s')."'";
+        $queryshare.=" AND stop > '".$stoptimestamp->format('Y-m-d H:i:s')."'";
+        $queryshare.=" GROUP BY instituteid";
+        //echo $queryshare." ";
+        //echo $starttimestamp->format('Y-m-d H:i:s');
+        $resultshare  = mysql_query($queryshare);
+        $sumpeople=0;
+        $institutes= array ("1" => 0, "2" => 0, "3" => 0, "4" => 0, "5" => 0 );
+        while ($rowshare = mysql_fetch_row($resultshare))
+        {
+            $institutes[$rowshare[0]]+=$rowshare[1];///mysql_num_rows($resultshare);
+            $sumpeople+=$rowshare[1];
+            //echo $rowshare[0]."..".$rowshare[1]." ";
+        }
+        foreach ($institutes as $key=>$value)
+            $institutes2[$key]+=$value/$sumpeople;
+        //print_r($institutes2);
+        date_add($starttimestamp, date_interval_create_from_date_string("1 days"));
+        $counter++;
+    }
+    //$institutes = array_map( function($val,$factor) { return $val / $factor; }, $institutes, array_fill(0, count($institutes), $counter));
+    foreach ($institutes2 as $key=>$value)
+        $institutes2[$key]=$value/$counter;
+    //print_r($institutes2);
+    mysql_free_result($resultshare);
+    //print_r($affiliation);
+    //print_r($users);
+    //print_r($shifthours);
+
+    foreach ($shifthours as $user=>$hours)
+    {
+        $shifthourstotal+=$hours;
+        $institutesum[$affiliation[$user]]+=$hours;
+    }
+    foreach ($institutesum as $key=>$value)
+        $institutesum[$key]=$value/$shifthourstotal;
+    //print_r($institutesum);
+    echo "<br>\n First Evaluation:<br>\n Institute: duty - done<br>\n";
+    foreach ($institutes2 as $key=>$value)
+        echo $key.": ".$value." - ".$institutesum[$key]."=> ".$institutesum[$key]*100/$value."% <br>";
+    echo "remark: does not yet take into account institute changes, i.e. only valid from 1.9.2012<br>";
+
+
+
     mysql_close($db_id);
 
