[ PHPXref.com ] [ Generated: Sun Jul 20 19:53:39 2008 ] [ PHProjekt 5.0.1 ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/projects/ -> projects_stat.php (source)

   1  <?php
   2  
   3  // projects_stat.php - PHProjekt Version 5.0

   4  // copyright  ©  2000-2005 Albrecht Guenther  ag@phprojekt.com

   5  // www.phprojekt.com

   6  // Author: Albrecht Guenther, $Author: nina $

   7  // $Id: projects_stat.php,v 1.25 2005/07/26 12:26:29 nina Exp $

   8  
   9  // check whether the lib has been included - authentication!

  10  if (!defined("lib_included")) die("Please use index.php!");
  11  
  12  
  13  // show error messages

  14  if ($action == "calc") {
  15      if (!$userlist[0]) {
  16          $err    = "<b>".__('Please choose at least one person')."</b><br /><br />";
  17          $action = "";
  18      }
  19      if (!$projectlist[0]) {
  20          $err    = "<b>".__('Please choose at least one project')."</b><br /><br />";
  21          $action = "";
  22      }
  23  }
  24  
  25  // show input box only if the table shouldn't be shown ...

  26  if ($action <> "calc") {
  27      //if($projectlistsave[0]=='gesamt') $projectlist=$projectlistsave;

  28      $projectlist=$projectlistsave;
  29      //if($userlistsave[0]=='gesamt') $userlist=$userlistsave;

  30      $userlist=$userlistsave;
  31      // set default date

  32      if (!$day)   $day   = date("d");
  33      if (!$month) $month = date("m");
  34      if (!$year)  $year  = date("Y");
  35  
  36      //tabs

  37      $tabs = array();
  38      /**

  39      $tmp = get_export_link_data('project_stat', false);

  40       $tabs[] = array('href' => $tmp['href'], 'active' => $tmp['active'], 'id' => 'tab4', 'target' => '_self', 'text' => $tmp['text'], 'position' => 'right');*/
  41      $output .= get_tabs_area($tabs);
  42      // button bar

  43      $buttons = array();
  44      $buttons[] = array('type' => 'link', 'href' => 'projects.php?mode=forms&amp;action=new'.$sid, 'text' => __('New'), 'active' => false);
  45      $buttons[] = array('type' => 'link', 'href' => 'projects.php?mode=options'.$sid, 'text' => __('Options'), 'active' => false);
  46      $buttons[] = array('type' => 'link', 'href' => 'projects.php?mode=stat'.$sid, 'text' => __('Statistics'), 'active' => ((isset($mode2) && $mode2 == 'mystat')) ? false : true);
  47      $buttons[] = array('type' => 'link', 'href' => 'projects.php?mode=stat&amp;mode2=mystat'.$sid, 'text' => __('My Statistic'), 'active' => ((isset($mode2) && $mode2 == 'mystat')) ? true : false);
  48      $buttons[] = array('type' => 'link', 'href' => 'projects.php?mode=gantt'.$sid, 'text' => __('Gantt'), 'active' => false);
  49      $buttons[] = array('type' => 'link', 'href' => 'projects.php?type='.$type.'&amp;sort='.$sort.'&amp;mode=view&amp;up='.$up.'&amp;filter='.$filter.'&amp;keyword='.$keyword.'&amp;perpage='.$perpage.'&amp;page='.$page, 'text' => __('back'), 'active' => false);
  50      $output .= get_buttons_area($buttons);
  51      $output .= '<div class="hline"></div>';
  52  
  53  
  54      // start form for input

  55      $html .= $err;
  56      $html .= "<form action='projects.php' method='post' name='frm'>\n";
  57      if (SID) $html .="<input type='hidden' name='".session_name()."' value='".session_id()."' />\n";
  58      $html .= "<input type='hidden' name='mode' value='stat' />\n";
  59      $html .= "<input type='hidden' name='mode2' value='$mode2' />\n";
  60      $html .= "<input type='hidden' name='action' value='calc' />\n";
  61      $html .= "<div><br />".__(' Choose a combination Project/Person')."<br />\n";
  62      $html .= __('(multiple select with the Ctrl/Cmd-key)')."<br /><br /></div>\n";
  63      // begin input table

  64      // show boxes for start and end time

  65      // first time call: give default values

  66      if (!$start_day)   $start_day   = "01";
  67      if (!$start_month) $start_month = "01";
  68      if (!$start_year)  $start_year  = date("Y");
  69      if (!$end_day)     $end_day     = date("d");
  70      if (!$end_month)   $end_month   = date("m");
  71      if (!$end_year)    $end_year    = date("Y");
  72      $html .= datepicker();
  73      // start day value

  74      $html .= "<span class='lf'><label for='anfang'>".__('Begin:')."</label> <input type='text' name='anfang' id='anfang' value='$start_year-$start_month-$start_day' size='10' onblur=\"chkISODate('frm','anfang','".__('ISO-Format: yyyy-mm-dd')."');\" />";
  75      $html .= "&nbsp;<a href='javascript://' title='".__('This link opens a popup window')."' onclick='callPick(document.frm.anfang);'><img src='".$img_path."/cal.gif' border='0' alt='calendar' /></a>&nbsp;<br />\n";
  76  
  77  
  78      // display project list

  79      $html .= "<br /><label for='projectlist'>".__('Projects').":</label><br /> <select name='projectlist[]' id='projectlist' multiple='multiple' size='20'>\n";
  80      $html .= "<option value='gesamt'";
  81       if ($projectlist[0]=='gesamt')$html.= ' selected="selected"';
  82      $html.= ">".__('All')."</option>\n";
  83      show_projects("0");
  84      $html .= "</select></span>\n";
  85      // end day value

  86      $html .= "<span class='lf'><label for='ende'>".__('End:')."</label> <input type='text' name='ende' id='ende' value='$end_year-$end_month-$end_day' size='10' onblur=\"chkISODate('frm','ende','".__('ISO-Format: yyyy-mm-dd')."','".__('Begin > End')."!');\" />";
  87      $html .= "&nbsp;<a href='javascript://' title='".__('This link opens a popup window')."' onclick='callPick(document.frm.ende)'><img src='".$img_path."/cal.gif' border='0' alt='calendar' /></a><br />\n";
  88      // display user list

  89      $html .= "<br /> <label for='userlist'>".__('Persons').":</label><br />\n";
  90      // first case: show only my statistic

  91      if ($mode2 == "mystat") {
  92          $html .= "<input type='hidden' name='userlist[]' id='userlist' value='$user_ID' />\n";
  93          $html .= "$user_name, $user_firstname\n";
  94      }
  95      else {
  96          $html .=  "<select name='userlist[]' id='userlist' multiple='multiple' size='20'>\n";
  97          // option 'all users' only available for usrs with chief status

  98          if (ereg("c", $user_access)){
  99              $html .= "<option value='gesamt'";
 100              if ($userlist[0]=='gesamt')$html.= ' selected="selected"';
 101              $html.= ">".__('All')."</option>\n";
 102          }
 103  
 104          // fetch all users from this group

 105          $result2 = db_query("select ".DB_PREFIX."users.ID, nachname, vorname, kurz
 106                                 from ".DB_PREFIX."users, ".DB_PREFIX."grup_user
 107                                where ".DB_PREFIX."users.ID = user_ID
 108                                  and grup_ID = '$user_group'
 109                             order by nachname") or db_die();
 110          while ($row2 = db_fetch_row($result2)) {
 111              // list them only if 1. the user is yourself, 2. you are an user with chief status or 3. you are leader of at least one project :-)

 112              if ($user_kurz == $row2[3] or ereg("c", $user_access) or $leader) {
 113                  $html .= "<option value='$row2[0]'";
 114                  if ($userlist[0] > 0 and in_array($row2[0], $userlist)) $html .= " selected='selected'";
 115                  $html .= ">$row2[1], $row2[2]</option>\n";
 116              }
 117          }
 118          $html .= "</select>\n";
 119      }
 120      $html .= "</span><br class='clear' /><br />\n";
 121      // end list users

 122      // show check boxes for bookings

 123      // dates ...

 124       if ($showbookingdates == "on") $showbookingdatesflag = " checked='checked'";
 125      $html .= "<input type='checkbox' name='showbookingdates' $showbookingdatesflag /> ".__('Show bookings')."\n";
 126      // ... and additionally the notes

 127      if ($showbookingnotes == "on") $showbookingnotesflag = " checked='checked'";
 128      $html .= "<input type='checkbox' name='showbookingnotes' id='showbookingnotes' $showbookingnotesflag /> <label for='showbookingnotes'>".__('remark')."</label>";
 129      $html.="<br/><br/>";
 130      if(!$display)$display='normal';
 131      if ($display == "normal") $normalflag = " checked='checked'";
 132      elseif ($display == "date") $dateflag = " checked='checked'";
 133      $html .= "".__('sort by').": <input type='radio' name='display' value='normal' id='normal' $normalflag/> <label for='normal'>".__('Project')."</label>";
 134        $html .= " <input type='radio' name='display' value='date' id='date' $dateflag/> <label for='date'>".__('Date')."</label> <br />\n";
 135  
 136      $html .= "<br />".get_buttons(array(array('type' => 'submit', 'value' => __('go'), 'active' => false)))."\n";
 137      $html .= "</form>\n";
 138  
 139      $output .= '
 140      <br/>
 141      <div class="inner_content">
 142          <a name="content"></a>
 143          <div class="boxHeader">'.__('Project summary').'</div>
 144          <div class="boxContent">'.$html.'
 145          <br style="clear:both"/><br/><br/><br/>
 146  
 147      </div>
 148          <br style="clear:both"/><br/></div>
 149      ';
 150  
 151      // end of input table

 152      unreg_sess_var("projectlist");
 153      unreg_sess_var("userlist");
 154  }
 155  
 156  //******************

 157  //statistic list

 158  // *****************

 159  
 160  else if ($projectlist[0] and $userlist[0]) {
 161      $projectlistsave=$projectlist;
 162      $userlistsave=$userlist;
 163      $_SESSION['projectlistsave'] =& $projectlistsave;
 164      $_SESSION['userlistsave'] =& $userlistsave;
 165  
 166      //tabs

 167      $tabs = array();
 168      if($display=='normal')$tmp = get_export_link_data('project_stat', false);
 169      elseif($display=='date')$tmp = get_export_link_data('project_stat_date', false);
 170      $tabs[] = array('href' => $tmp['href'], 'active' => $tmp['active'], 'id' => 'tab4', 'target' => '_self', 'text' => $tmp['text'], 'position' => 'right');
 171      $output .= get_tabs_area($tabs);
 172  
 173      // button bar

 174      $buttons = array();
 175      $buttons[] = array('type' => 'link', 'href' => 'projects.php?mode=forms&amp;action=new'.$sid, 'text' => __('New'), 'active' => false);
 176      $buttons[] = array('type' => 'link', 'href' => 'projects.php?mode=options'.$sid, 'text' => __('Options'), 'active' => false);
 177      $buttons[] = array('type' => 'link', 'href' => 'projects.php?mode=stat'.$sid, 'text' => __('Statistics'), 'active' => false);
 178      $buttons[] = array('type' => 'link', 'href' => 'projects.php?mode=stat&amp;mode2=mystat'.$sid, 'text' => __('My Statistic'), 'active' => true);
 179      $buttons[] = array('type' => 'link', 'href' => 'projects.php?mode=gantt'.$sid, 'text' => __('Gantt'), 'active' => false);
 180      $buttons[] = array('type' => 'link', 'href' => 'projects.php?mode=stat&amp;mode2='.$mode2.'&amp;anfang='.$anfang.'&amp;ende='.$ende.'&amp;showbookingdates='.$showbookingdates.'&amp;showbookingnotes='.$showbookingnotes.$sid, 'text' => __('back'), 'active' => false);
 181  
 182      $output .= get_buttons_area($buttons);
 183      $output .= '<div class="hline"></div>';
 184  
 185  
 186  
 187      // title

 188      $html = $err;
 189      $html .="<br /> ".__('Begin').": $anfang, ".__('End').": $ende<br /><br />\n";
 190      // check whether the given values are valid dates

 191      if (!checkdate(substr($anfang,5,2), substr($anfang,8,2), substr($anfang,0,4))) die(__('Please check the date!')." <br />".__('back')." ...");
 192      if (!checkdate(substr($ende,5,2), substr($ende,8,2), substr($ende,0,4))) die(__('Please check the date!')." <br />".__('back')." ...");
 193      if ($ende < $anfang) die(__('Please check start and end time! '));
 194      // fetch all projects

 195      if($display=='normal'){
 196      if ($projectlist[0] == "gesamt") {
 197           unset($projectlist);
 198          if ($mode2 == "mystat") {
 199              $result = db_query("select ID
 200                                    from ".DB_PREFIX."projekte
 201                                order by name") or db_die();
 202          }
 203          else {
 204              $result = db_query("select ID
 205                                    from ".DB_PREFIX."projekte
 206                                   where $sql_user_group
 207                               order by name") or db_die();
 208          }
 209          while ($row = db_fetch_row($result)) $projectlist[] = $row[0];
 210      }
 211  
 212      }
 213  
 214  
 215      else{
 216      //where Klausel für Personen!

 217        $where_person='';
 218        if ($userlist[0] == "gesamt");     
 219        else{
 220            foreach ($userlist as $person) {
 221                $where_person.="t.users='$person' or ";
 222            }
 223            if($where_person<>'')$where_person.="1!=1";
 224        }
 225        if ($projectlist[0] == "gesamt") {
 226          unset($projectlist);
 227          if ($mode2 == "mystat") {
 228  
 229              $result = db_query("select datum, p.ID
 230                                    from ".DB_PREFIX."projekte as p , ".DB_PREFIX."timeproj as t
 231                                    WHERE p.ID=t.projekt AND datum >= '$anfang'
 232                             AND datum <= '$ende'  AND ($where_person) group by p.name,datum
 233                                order by datum, p.name") or db_die();
 234          }
 235          else {
 236              $result = db_query("select datum, p.ID
 237                                    from ".DB_PREFIX."projekte as p,".DB_PREFIX."timeproj as t
 238                                    WHERE p.ID=t.projekt
 239                                   AND datum >= '$anfang'
 240                             AND datum <= '$ende' AND $sql_user_group  AND ($where_person) group by p.name,datum
 241                               order by datum,  p.name") or db_die();
 242  
 243          }
 244          $i=0;
 245          while ($row = db_fetch_row($result)){
 246              $projectlist[$i][$row[0]] = $row[1];
 247              $i++;
 248          }
 249      }
 250      else {
 251          $where='';
 252          foreach($projectlist as $project) $where.= "projekt='$project' or ";
 253          if($where<>'')$where.="1!=1";
 254          unset($projectlist);
 255          $query= "select datum, p.ID
 256                             from ".DB_PREFIX."projekte as p,".DB_PREFIX."timeproj as t
 257                                    WHERE p.ID=t.projekt AND datum >= '$anfang'
 258                             AND datum <= '$ende'
 259                                   AND $sql_user_group AND ($where)  AND ($where_person) group by p.name,datum
 260                          order by datum, p.name";
 261          $result = db_query($query) or db_die();
 262          $i=0;
 263          while ($row = db_fetch_row($result)){
 264              $projectlist[$i][$row[0]] = $row[1];
 265              $i++;
 266          }
 267  
 268      }
 269  
 270    }
 271  
 272  
 273      // fetch all users from this group

 274      if ($userlist[0] == "gesamt") {
 275          unset($userlist);
 276          $result = db_query("select user_ID
 277                                from ".DB_PREFIX."grup_user, ".DB_PREFIX."users
 278                               where grup_ID = '$user_group' and
 279                                     ".DB_PREFIX."users.ID = user_ID
 280                            order by nachname") or db_die();
 281          while ($row = db_fetch_row($result)) $userlist[] = $row[0];
 282      }
 283      // begin output table

 284      $html .= " <table class='ruler'>";
 285  
 286      if($display=='normal')$html.= "<thead><tr><th><b>[h : m]</b></th>\n";
 287      else $html.= "<thead><tr><th><b>".__('Date')."</b></th><th><b>".__('Project Name')."</b>\n";
 288  
 289      // first row: the users!

 290      foreach ($userlist as $person) {
 291          $result = db_query("select kurz
 292                                from ".DB_PREFIX."users
 293                               where ID = '$person'") or db_die();
 294          $row = db_fetch_row($result);
 295          $html .= "<th>$row[0]</th>\n";
 296      }
 297      // end of the first row - display string 'sum'

 298      $html .= "<th><b>".__('Sum')."</b>\n";
 299      $html .= "</tr></thead><tbody>\n";
 300      $i=0;
 301      // now loop over project list

 302      foreach ($projectlist as $project) {
 303  
 304          // alternate tr colour

 305          if (($cnr/2) == round($cnr/2)) {
 306              $color = PHPR_BGCOLOR1;
 307              $cnr++;
 308          }
 309          else {
 310              $color = PHPR_BGCOLOR2;
 311              $cnr++;
 312          }
 313  
 314          // print project name

 315  
 316          if($display=='normal'){
 317              $result = db_query("select name
 318                                from ".DB_PREFIX."projekte
 319                               where ID = '$project'") or db_die();
 320              $row = db_fetch_row($result);
 321              $html .= "<tr bgcolor=$color><td>$row[0]</td>\n";
 322              // loop over list of persons and fetch the bookings

 323              foreach ($userlist as $person) { $html .=fetch_bookings($project, $person); }
 324  
 325           }
 326          else{
 327  
 328              foreach($project as $datum => $projID){
 329                  $i++;
 330  
 331              $result = db_query("select name
 332                                from ".DB_PREFIX."projekte
 333                               where ID = '$projID'") or db_die();
 334                 $row = db_fetch_row($result);
 335                  $html .= "<tr bgcolor=$color><td>$datum</td>\n";
 336                  $html .= "<td>$row[0]</td>\n";
 337                  foreach ($userlist as $person) {
 338                  $html .=fetch_date_bookings($projID, $person,$datum,$i);
 339  
 340                  }
 341                  $h = floor($sumdatum[$datum.$projID]/60);
 342                  $m = $sumdatum[$datum.$projID] - $h*60;
 343                  $html .= "<td valign='bottom'><b>$h : $m</b></td>\n";
 344                  $html .= "</tr>\n";
 345  
 346              }
 347          }
 348         if($display=='normal'){
 349              $h = floor($sumproject[$project]/60);
 350              $m = $sumproject[$project] - $h*60;
 351              $html .= "<td valign='bottom'><b>$h : $m</b></td>\n";
 352              $html .= "</tr>\n";
 353         }
 354      }
 355  
 356      // last row: show sums for the projects

 357      $html .= "</tbody><tfoot><tr><td><b>".__('Sum')."</b></td>\n";
 358      if($display!='normal') $html .='<td></td>';
 359      foreach ($userlist as $person) {
 360          $h = floor($sumperson[$person]/60);
 361          $m = $sumperson[$person] - $h*60;
 362          // sum up for totalsum

 363          $totalsum += $sumperson[$person];
 364          $html .= "<td><b>$h : $m</b></td>";
 365      }
 366  
 367  
 368  
 369      // display total sum in the last cell of the table and close the table

 370      $h = floor($totalsum/60);
 371      $m = $totalsum - $h*60;
 372      $html .= "<td><b>$h : $m</td></tr>\n";
 373      $html .= "</tfoot></table><br /><br />";
 374  
 375      $output .= '
 376      <br/>
 377      <div class="inner_content">
 378          <div class="boxHeader">'.__('Statistics').'</div>
 379          <div class="boxContent">'.$html.'</div>
 380          <br style="clear:both"/><br/>
 381      </div>
 382      <br style="clear:both"/><br/>
 383      ';
 384  
 385      // register the pojectlist and the participants so the user won't have to select them again

 386      $_SESSION['projectlist'] =& $projectlist;
 387      $_SESSION['userlist'] =& $userlist;
 388  
 389  }
 390  
 391  echo $output;
 392  
 393  
 394  function fetch_bookings($project, $person) {
 395      global $anfang, $ende, $show_bookings, $sumperson, $sumproject, $showbookingdates, $showbookingnotes;
 396  
 397      // start table cell

 398  
 399      // open the table of bookings if flag is set

 400      $out='<td valign="bottom"';
 401      // fetch values from time card bookings  the bookings are between start and end time

 402      $result = db_query("SELECT datum, h, m, note
 403                            FROM ".DB_PREFIX."timeproj
 404                           WHERE projekt = '$project'
 405                             AND users = '$person'
 406                             AND datum >= '$anfang'
 407                             AND datum <= '$ende'
 408                        ORDER BY datum");
 409      while ($row = db_fetch_row($result)) {
 410          // detailed booking display?

 411          if ($showbookingdates) {
 412              $out.= "<div style='float:left; padding-right:10px;'>$row[0] - $row[1] : $row[2]</div>";
 413              if ($showbookingnotes)$out.= "<div align='right'>$row[3]&nbsp;</div>";
 414              $out.= "<br style='clear:both;'/>\n";
 415          }
 416          // sum up

 417  
 418          $sum1  = $sum1 + $row[1]*60+$row[2];
 419          $datum = $row[0];
 420      }
 421  
 422      // close the table of bookings if flag is set

 423       // build hours and minutes of the sum and display it

 424      $h = floor($sum1/60);
 425      $m = $sum1 - $h*60;
 426       //if (!$showbookingdates)

 427       $out .= "<b>$h : $m</b>";
 428       $out.="</td>\n";
 429  
 430      // add sum to the overall sum of this person

 431      $sumperson[$person]   += $sum1;
 432      $sumproject[$project] += $sum1;
 433      return  $out;
 434  }
 435  
 436  function fetch_date_bookings($project, $person, $datum,$i) {
 437      global $anfang, $ende, $show_bookings, $sumperson, $sumdatum, $showbookingdates, $showbookingnotes;
 438  
 439      // start table cell

 440  
 441      // open the table of bookings if flag is set

 442      $out='<td valign="bottom"';
 443      // fetch values from time card bookings  the bookings are between start and end time

 444      $result = db_query("SELECT datum, h, m, note
 445                            FROM ".DB_PREFIX."timeproj
 446                           WHERE projekt = '$project'
 447                             AND datum='$datum'
 448                             AND users = '$person'
 449                             ORDER BY datum");
 450      while ($row = db_fetch_row($result)) {
 451          // detailed booking display?

 452          if ($showbookingdates) {
 453              $out.= "<div style='float:left; padding-right:10px;'>$row[0] - $row[1] : $row[2]</div>";
 454              if ($showbookingnotes)$out.= "<div align='right'>$row[3]&nbsp;</div>";
 455              $out.= "<br style='clear:both;'/>\n";
 456          }
 457          // sum up

 458  
 459          $sum1  = $sum1 + $row[1]*60+$row[2];
 460          $datum =