TUTOS PHP Cross Reference Groupware Applications

Source: /php/timetrack/timetrack_overview.php - 869 lines - 33824 bytes - Summary - Text - Print

Description: Copyright 1999 - 2013 by Gero Kohnert This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License.

   1  <?php
   2  /**
   3   *  Copyright 1999 - 2013 by Gero Kohnert
   4   *
   5   *  This program is free software; you can redistribute it and/or modify it
   6   *  under the terms of the GNU General Public License as published by the
   7   *  Free Software Foundation; version 2 of the License.
   8   *
   9   *  SVN Info  $Id: timetrack_overview.php 1196 2013-12-11 08:26:45Z gokohnert $
  10   *  $Author: gokohnert $
  11   *
  12   * an overview of all booked times
  13   *
  14   * @modulegroup timetrack
  15   * @module timetrack_overview
  16   * @package timetrack
  17   */
  18  $tutos['files'][__FILE__] = '$Rev: 1196 $';
  19  
  20  $tutos['base'] = "../..";
  21  ini_set("include_path","..");
  22  require_once  'webelements.p3';
  23  require_once  'permission.p3';
  24  
  25  // Check if user is allowed to use it
  26  check_user();
  27  
  28  require_once  'graphs.pinc';
  29  
  30  loadmodules('timetrack','overview');
  31  loadmodule('timetrack');
  32  loadlayout();
  33  
  34  /**
  35   * show a overview of timetracks
  36   */
  37  class Timetrack_overview extends layout {
  38      /**
  39       * display the info
  40       */
  41      Function info() {
  42          global $lang,$tutos;
  43  
  44          $r = '';
  45          $n = $this->result->numrows();
  46  
  47          if ( $this->format == "xml" ) {
  48              if ( 0 != $n) {
  49                  $a = new timetrack($this->dbconn);
  50                  $r .= $a->exportXMLHeader();
  51                  $r .= $a->exportXML_head();
  52                  $r .= "<timetrack_set>\n";
  53                  $x = 0;
  54                  while ( $x < $n ) {
  55                      $a = new timetrack($this->dbconn);
  56                      $a->read_result($this->result,$x);
  57                      $r .= $a->exportXML(false);
  58                      $x++;
  59                  }
  60                  $r .= "</timetrack_set>\n";
  61              }
  62              return $r;
  63          } else if ($this->format == "excel") {
  64              require_once  '../../libs/excel/Worksheet.php';
  65              require_once  '../../libs/excel/Workbook.php';
  66              include_once  '../excel.pinc';
  67  
  68              $this->excel = new tutos_excel();
  69              $this->excel->open();
  70              $this->excel->add_formats();
  71  
  72              $ws = $this->excel->add_sheet(myiconv(substr($lang['TimetrackOverview'],0,30)));
  73  
  74              $x = 0;
  75              $c = 0;
  76  
  77              $this->excel->ws[$ws]->set_column($c,$c,5); // ID
  78              $this->excel->ws[$ws]->write_string($x,$c++, "#",$this->excel->format_header);
  79  
  80              $this->excel->ws[$ws]->set_column($c,$c,25);// Name
  81              $this->excel->ws[$ws]->write_string($x,$c++, myiconv($lang['TimetrackWorker']),$this->excel->format_header);
  82  
  83              $this->excel->ws[$ws]->set_column($c,$c,20);// Volume
  84              $this->excel->ws[$ws]->write_string($x,$c++, myiconv($lang['TimetrackBooked']),$this->excel->format_header);
  85  
  86              $this->excel->ws[$ws]->set_column($c,$c,20);// CPH
  87              $this->excel->ws[$ws]->write_string($x,$c++, myiconv($lang['TTcph']),$this->excel->format_header);
  88  
  89              $this->excel->ws[$ws]->set_column($c,$c,25);// Sum
  90              $this->excel->ws[$ws]->write_string($x,$c++, "Sum",$this->excel->format_header);
  91  
  92              $this->excel->ws[$ws]->set_column($c,$c,15);// Currency
  93              $this->excel->ws[$ws]->write_string($x,$c++, myiconv($lang['Currency']),$this->excel->format_header);
  94  
  95              $this->excel->ws[$ws]->set_column($c,$c,15);// Distance
  96              $this->excel->ws[$ws]->write_string($x,$c++, myiconv($lang['Distance']),$this->excel->format_header);
  97  
  98              $this->excel->ws[$ws]->set_column($c,$c,50);// DESC
  99              $this->excel->ws[$ws]->write_string($x,$c++, myiconv($lang['Description']),$this->excel->format_header);
 100  
 101              $this->excel->ws[$ws]->set_column($c,$c,25);// Day
 102              $this->excel->ws[$ws]->write_string($x,$c++, myiconv($lang['atDateTime']),$this->excel->format_header);
 103  
 104              $this->excel->ws[$ws]->set_column($c,$c,25);// State
 105              $this->excel->ws[$ws]->write_string($x,$c++, myiconv($lang['TTState']),$this->excel->format_header);
 106  
 107              $this->excel->ws[$ws]->set_column($c,$c,45);// Referenz
 108              $this->excel->ws[$ws]->write_string($x,$c++, myiconv($lang['TimetrackRef']),$this->excel->format_header);
 109  
 110              $this->excel->ws[$ws]->set_column($c,$c,45);// MainObject
 111              $this->excel->ws[$ws]->write_string($x,$c++, myiconv("0-".$lang['TimetrackRef']),$this->excel->format_header);
 112  
 113              $x++;
 114              $cnt = 0;
 115              while ( $cnt < $n ) {
 116                  $a = new timetrack($this->dbconn);
 117                  $a->read_result($this->result,$cnt);
 118  
 119                  $c = 0;
 120                  $this->excel->ws[$ws]->write_number($x,$c++, $a->id,$this->excel->format_default);
 121                  $this->excel->ws[$ws]->write_string($x,$c++, myiconv(is_object($a->worker) ? $a->worker->getFullName():$lang['HistoryDeleted']),$this->excel->format_default);
 122                  $this->excel->ws[$ws]->write_number($x,$c++, $a->volume,$this->excel->format_default);
 123                  $this->excel->ws[$ws]->write_number($x,$c++, $a->cph,$this->excel->format_default);
 124                  $this->excel->ws[$ws]->write_number($x,$c++, $a->cph * $a->volume,$this->excel->format_default);
 125                  $this->excel->ws[$ws]->write_string($x,$c++, myiconv($a->currency),$this->excel->format_default);
 126                  $this->excel->ws[$ws]->write_number($x,$c++, $a->distance,$this->excel->format_default);
 127                  $this->excel->ws[$ws]->write_string($x,$c++, myiconv($a->desc),$this->excel->format_default);
 128                  $this->excel->ws[$ws]->write_string($x,$c++, $a->wday->getDate(),$this->excel->format_default);
 129                  $this->excel->ws[$ws]->write_string($x,$c++, myiconv($a->getState('',false)),$this->excel->format_default);
 130                  if ( ! is_object($a->ref) ) {
 131                      $this->excel->ws[$ws]->write_string($x,$c++, myiconv($lang['HistoryDeleted']),$this->excel->format_default);
 132                      $this->excel->ws[$ws]->write_string($x,$c++, myiconv($lang['HistoryDeleted']),$this->excel->format_default);
 133                  } else {
 134                      $pre = "";
 135                      $name =  myiconv($a->ref->getFullName());
 136                      $this->excel->ws[$ws]->write_string($x,$c++, $name,$this->excel->format_default);
 137                      if ($a->ref->getType() == "task") {
 138                          $p = $a->ref->parent;
 139                          if( !is_object($p) ) unset($p);
 140                          while ( isset ( $p ) ) {
 141                              $name = myiconv($p->getFullName());
 142                              if (isset($p->parent) && is_object($p->parent)) {
 143                                  $p = $p->parent;
 144                              } else {
 145                                  unset($p);
 146                              }
 147                          }
 148                      }
 149                      $this->excel->ws[$ws]->write_string($x,$c++, $name,$this->excel->format_default);
 150                  }
 151  
 152  
 153                  $x++;
 154                  $cnt++;
 155              }
 156  
 157              $this->excel->send('TimetrackExport');
 158              return $r;
 159          } else if ($this->format == "stat") {
 160              $r .= $this->statinfo();
 161              $this->result->free();
 162              return $r;
 163          } else if ($this->format == "csv") {
 164              $r .= $this->exportinfo();
 165              $this->result->free();
 166              return $r;
 167          }
 168  
 169          $this->flds = 6;
 170          $r .= $this->actionformStart("timetrack_overview.php");
 171          $r .= $this->header;
 172          $r .= $this->OverviewTableStart();
 173          $r .= $this->OverviewHeadStart();
 174          $r .= $this->OverviewHeadLineStart();
 175          $r .= $this->orderHeader('',"#",$this->link2);
 176          if ($this->head['ref']) {
 177              $r .= $this->orderHeader('',$lang['TimetrackRef'],$this->link2);
 178              $this->flds++;
 179          }
 180          if ($this->head['worker']) {
 181              $r .= $this->orderHeader('',$lang['TimetrackWorker'],$this->link2);
 182              $this->flds++;
 183          }
 184          $r .= $this->orderHeader("volume",$lang['TaskVolumeDone'].'<br /><span class="smaller">('.$lang['hours'].')</span>',$this->link2);
 185          $r .= $this->orderHeader("volume_todo",$lang['TaskVolumeTodo'].'<br /><span class="smaller">('.$lang['hours'].')</span>',$this->link2);
 186          if ($this->head['distance'])  {
 187              $r .= $this->orderHeader("distance",$lang['Distance'],$this->link2);
 188              $this->flds++;
 189          }
 190          $r .= $this->orderHeader("vtime",$lang['TimetrackDate'],$this->link2);
 191          $r .= $this->orderHeader("description",$lang['Description'],$this->link2);
 192          if ($this->head['state']) {
 193              $r .= $this->orderHeader("state",$lang['TTState'],$this->link2);
 194              $this->flds++;
 195          }
 196          $r .= $this->orderHeader('',$lang['ProdCost'],$this->link2);
 197          $r .= show_custom_overview_headers($this,'timetrack',$this->link2);
 198          $r .= get_module_overview_header($this,'timetrack');
 199          $r .= $this->MassUpdateHeader();
 200          $r .= $this->OverviewHeadLineEnd();
 201          $r .= $this->OverviewHeadEnd();
 202  
 203          $sum['v'] = 0.0;
 204          $sum['d'] = 0.0;
 205          $sum[''] = 0.0;
 206          foreach($tutos[currencies] as $c) {
 207              $sum[$c] = 0.0;
 208          }
 209  
 210          if ( $this->format == "paper" ) {
 211              $a = 0;
 212              $end = $n;
 213          } else if ( $this->start == -1 ) {
 214              $a = $n - $tutos['maxshow'];
 215              $end = $n;
 216              $this->start = $a;
 217          } else {
 218              $a = $this->start;
 219              $end = $this->start + $tutos['maxshow'];
 220          }
 221  
 222          $np = array();
 223  
 224          // Fill the sum of time and distance
 225          $x = 0;
 226          while ( $x < $a ) {
 227              $sum['v'] += $this->result->get($x, "volume");
 228              $sum['d'] += $this->result->get($x, "distance");
 229              $curr = $this->result->get($x, "currency");
 230              if (!isset($sum[$curr])) $sum[$curr] = 0;
 231              $sum[$curr] += ( $this->result->get($x, "cph") * $this->result->get($x, "volume") );
 232              #            $np[] = $this->result->get($x, "id") ;
 233              $x++;
 234          }
 235  
 236          $nav = $this->getSubSession();
 237          $nav['link'] = $this->link1;
 238          #        $nav['list'] = $np;
 239          $ss = $this->putSubSession($nav);
 240  
 241          $line = 0;
 242          while ( ($a < $n) && ($a < $end) ) {
 243              $tt = new timetrack($this->dbconn);
 244              $tt->read_result($this->result,$a);
 245              #            $np[] = $tt->id;
 246              $r .= $this->OverviewRowStart($line);
 247  
 248              if ( $tt->mod_ok() ) {
 249                  $xx = makelink($tt->getModURL('ss='.$ss) ,sprintf("%03d",($a + 1)),$lang['TimetrackModify']);
 250              } else {
 251                  $xx = sprintf("%03d",($a + 1));
 252              }
 253              $r .= $this->OverviewRowBlock($xx,'over_l');
 254  
 255              if ($this->head['ref']) {
 256                  if ( ! is_object($tt->ref) ) {
 257                      $xx = '<i>'. makelink('history_show.php?id='. $tt->link_id ,$lang['HistoryDeleted']) .'</i>';
 258                  } else {
 259                      // Marks
 260                      $x = $this->mark_filter(myentities($tt->ref->getFullName()),'link_id');
 261                      $xx = $tt->ref->getLink($x);
 262                  }
 263                  $r .= $this->OverviewRowBlock($xx,'over_l');
 264              }
 265  
 266              if ($this->head['worker']) {
 267                  if ( ! is_object($tt->worker) ) {
 268                      $xx = '<i>'. makelink('history_show.php?id='. $tt->wid ,$lang['HistoryDeleted']) .'</i>';
 269                  } else {
 270                      $xx = $tt->worker->getLink();
 271                  }
 272                  $r .= $this->OverviewRowBlock($xx,'over_l');
 273              }
 274              $r .= $this->OverviewRowBlock(hour_format($tt->volume),'over_r');
 275  
 276              if ($tt->volume_todo != 0) {
 277                  $xx = hour_format($tt->volume_todo);
 278              } else {
 279                  $xx = "&nbsp;";
 280              }
 281              $r .= $this->OverviewRowBlock($xx,'over_r');
 282  
 283              if ($this->head['distance'])  {
 284                  $r .= $this->OverviewRowBlock(($tt->distance != 0 ? $tt->distance:'&nbsp;'),'over_r');
 285              }
 286              $sum['v'] += $tt->volume;
 287              $sum['d'] += $tt->distance;
 288              if (!isset($sum[$tt->currency])) $sum[$tt->currency] = 0;
 289              $sum[$tt->currency] += ( $tt->cph * $tt->volume );
 290  
 291              $xx = $tt->wday->getDate();
 292              if ( $tt->t_start->notime != 1) {
 293                  $xx .= '<br />'. $tt->t_start->getDateTimeShort() ." - ". $tt->t_end->getDateTimeShort();
 294              } else {
 295                  $xx .= "&#160;";
 296              }
 297              $r .= $this->OverviewRowBlock($xx,'over_l');
 298  
 299              $r .= $this->OverviewRowBlock($this->mark_filter(myentities($tt->desc),'description'),'over_r');
 300  
 301              if ($this->head['state']) {
 302                  $r .= $this->OverviewRowBlock($tt->getStateColorBlock().$tt->getState(),'over_l');
 303              }
 304  
 305              $x= array($tt->cph * $tt->volume,$tt->currency);
 306              $xx = handle('money',$x,my_number_format($tt->cph * $tt->volume,2) .' '. myentities($tt->currency));
 307              $r .= $this->OverviewRowBlock($xx,'over_r');
 308  
 309              $r .= show_custom_overview_data($this,'timetrack',$tt);
 310              $r .= get_module_overview_data($this,$tt);
 311              $r .= $this->MassUpdateField($tt);
 312              $r .= $this->OverviewRowEnd($line++);
 313              $a++;
 314              unset($tt);
 315          }
 316  
 317          $r .= $this->list_navigation($this->link1,$this->flds + $tutos[massupdate],$this->start,$a,$n);
 318  
 319          // Fill the sum of time and distance
 320          while ( $a < $n ) {
 321              $sum['v'] += $this->result->get($a, "volume");
 322              $sum['d'] += $this->result->get($a, "distance");
 323              $sum[$this->result->get($a, "currency")] += ( $this->result->get($a, "cph") * $this->result->get($a, "volume") );
 324              #            $np[] = $this->result->get($a, "id") ;
 325              $a++;
 326          }
 327  
 328          #        $nav['list'] = $np;
 329          #        $ss = $this->putSubSession($nav);
 330  
 331          $r .= "<tr>\n";
 332          $c = 1;
 333          if ($this->head['worker']) $c++;
 334          if ($this->head['ref']) $c++;
 335          $r .= ' <td colspan="'.$c."\">&nbsp;</td>\n";
 336          $r .= ' <td class="over_r"><b>'. hour_format($sum['v']) ."</b></td>\n";
 337          $r .= " <td>&nbsp;</td>\n"; //todo
 338          if ($this->head['distance'])  {
 339              $r .= ' <td align="right"><b>'. $sum['d'] ."</b></td>\n"; // distance
 340          }
 341          $c = 2;
 342          if ($this->head['state']) $c++;
 343          $r .= ' <td colspan="'.$c."\">&nbsp;</td>\n";
 344          $r .= " <td align=\"right\"><b>\n";
 345  
 346          foreach($sum as $s => $x) {
 347              if ($s == 'v') continue;
 348              if ($s == 'd') continue;
 349              if ( $x != 0.0 ) {
 350                  $z= array($x,$s);
 351                  $r .=  handle('money',$z,my_number_format($sum[$s],2) .' '. myentities($s)) ."<br />\n";
 352              } else {
 353                  $r .= '&nbsp;';
 354              }
 355          }
 356          $r .= "</b></td>\n";
 357  
 358          if ( $this->flds > 7 ) {
 359              $r .= ' <td colspan="'. ( $this->flds - 7 )."\">&nbsp;</td>\n";
 360          }
 361          $r .= "</tr>\n";
 362  
 363          if ( $tutos[massupdate] == 1 ) {
 364              $r .= $this->UpdateRowStart($this->flds-1);
 365              $r .= sprintf($lang['withmarked'],$lang['Timetracks']);
 366              $r .= "&nbsp;<select name=\"action\">\n";
 367              $r .= ' <option value="-1" selected="selected">'. $lang['ActionNil'] ."</option>\n";
 368              $r .= ' <option value="-2">'. $lang['Delete'] ."</option>\n";
 369              foreach($lang['TTStates'] as $f => $i) {
 370                  $r .= ' <option value="S'. $f .'">'. sprintf($lang['SetTo'],$lang['TTState'],$i) ."</option>\n";
 371              }
 372              $r .= "</select>\n";
 373              $r .= $this->UpdateRowEnd(2);
 374          }
 375  
 376          $r .= $this->DataTableEnd();
 377          $r .= $this->actionformEnd("timetrack_overview.php");
 378          $this->result->free();
 379          return $r;
 380      }
 381  
 382      /**
 383       * Statistical Timetrack Info
 384       */
 385      Function exportinfo() {
 386          global $lang,$tutos;
 387  
 388          $r = '';
 389          export_headers('TUTOS_timetrack_export','csv');
 390          $n = $this->result->numrows();
 391          $a = 0;
 392  
 393          $r .= timetrack::exportCSV_Header();
 394          while ( $a < $n ) {
 395              $tt = new timetrack($this->dbconn);
 396              $tt->read_result($this->result,$a);
 397              $r .= $tt->exportCSV();
 398              $a++;
 399              flush();
 400              unset($tt);
 401          }
 402          return $r;
 403      }
 404  
 405      /**
 406       * Statistical Timetrack Info
 407       */
 408      Function statinfo() {
 409          global $lang,$tutos;
 410  
 411          $r = '';
 412          $w = array();
 413          $s = array();
 414          $p = array();
 415  
 416          $n = $this->result->numrows();
 417          $a = 0;
 418          $v = 0; // total volume
 419          while ( $a < $n ) {
 420              $tt = new timetrack($this->dbconn);
 421              $tt->read_result($this->result,$a);
 422              if ( !isset($w[$tt->worker->id]) ) {
 423                  $w[$tt->worker->id] = 0;
 424              }
 425              if ( !isset($s[$tt->state]) ) {
 426                  $s[$tt->state] = 0;
 427              }
 428              if ( !isset($p[$tt->ref->id]) ) {
 429                  $p[$tt->ref->id] = 0;
 430              }
 431              $w[$tt->worker->id] += $tt->volume;
 432              $p[$tt->ref->id] += $tt->volume;
 433              $s[$tt->state] += $tt->volume;
 434              $v += $tt->volume;
 435              $a++;
 436              unset($tt);
 437          }
 438  
 439          // Header
 440          $r .= $this->DataTableStart();
 441          $r .= "<tr>\n";
 442          $r .= " <th colspan=\"5\">". $lang['TTStatsTitle'] ."</th>\n";
 443          $r .= "</tr>\n";
 444  
 445          // Worker distribution
 446          $r .= "<tr>\n";
 447          $r .= $this->showfield($lang['TimetrackWorker']);
 448          $r .= ' <td colspan="4" valign="top">';
 449          $spie = array();
 450          $spie['title'] =  $lang['TimetrackWorker'];
 451          foreach ($w as  $i => $f) {
 452              $worker = getObject($this->dbconn,$i);
 453              if (!is_object($worker)) continue;
 454  
 455              $e = array();
 456              $e['val']   = hour_format($f) ." ". $lang['hours'];
 457              $e['cnt']   = $f;
 458              if ($worker->gettype() == "address") {
 459                  $xx = $worker->getShortName();
 460              } else {
 461                  $xx = $worker->getFullName();
 462              }
 463              $e['title'] = $worker->getLink($xx);
 464  
 465              $spie['data'][] = $e;
 466          }
 467          $r .= pie($spie);
 468          $r .= ' </td>'."\n";
 469          $r .= "</tr>\n";
 470  
 471          // State distribution
 472          $r .= "<tr>\n";
 473          $r .= $this->showfield($lang['TTState']);
 474          $spie = array();
 475          $spie['title'] =  $lang['TTState'];
 476          $r .= ' <td colspan="4" valign="top">';
 477          foreach ($s as  $i => $f) {
 478              $e = array();
 479              $e['val']   = hour_format($f) ." ". $lang['hours'];
 480              $e['cnt']   = $f;
 481              $e['title'] = $this->stc->getState($i);
 482              if (isset($this->stc->states[$i]))
 483                  $e['color'] = $this->stc->states[$i]->color;
 484              else
 485                  $e['color'] = 'white';
 486  
 487              $spie['data'][] = $e;
 488          }
 489  
 490          $r .= pie($spie);
 491          $r .= ' </td>'."\n";
 492          $r .= "</tr>\n";
 493  
 494  
 495          // Reference distribution
 496          $c = 0;
 497          $spie = array();
 498          $spie['title'] =  $lang['TimetrackRef'];
 499          $spie['ytitle'] =  $lang['hours'];
 500          foreach ($p as $i => $f) {
 501              $e = array();
 502              $e['val']   = hour_format($f) ." ". $lang['hours'];
 503              $e['cnt']   = $f;
 504  
 505              $pp = getObject($this->dbconn,$i);
 506              if ( !is_object($pp) ) {
 507                  $e['title'] = $lang['HistoryDeleted'];
 508              } else {
 509                  $e['title'] = $pp->getFullName();
 510              }
 511              $spie['data'][] = $e;
 512              $c++;
 513              if ( $c == 12 ) {
 514                  $r .= "<tr>\n";
 515                  $r .= $this->showfield($lang['TimetrackRef']);
 516                  $r .= ' <td colspan="4" valign="top">';
 517                  $r .= bar($spie);
 518                  $r .= ' </td>'."\n";
 519  
 520                  $c = 0;
 521                  $spie = array();
 522                  $spie['title'] =  $lang['TimetrackRef'];
 523                  $spie['ytitle'] =  $lang['hours'];
 524              }
 525          }
 526          if ($c > 0) {
 527              // remainings
 528              $r .= "<tr>\n";
 529              $r .= $this->showfield($lang['TimetrackRef']);
 530              $r .= ' <td colspan="4" valign="top">';
 531              $r .= bar($spie);
 532              $r .= ' </td>'."\n";
 533  
 534              $c = 0;
 535              $spie = array();
 536          }
 537  
 538          $r .= $this->DataTableEnd();
 539          return $r;
 540      }
 541  
 542      /**
 543       * action
 544       */
 545      Function action() {
 546          global $msg,$info,$tutos,$lang;
 547  
 548          $this->stc = getObject($this->user->dbconn,$tutos['timetrack_state_stc']);
 549          if (!is_object($this->stc)) {
 550              $this->stc = new stc(null);
 551              $this->stc->initByArray('ProdStates',null);
 552          }
 553  
 554          if ( $_GET['action'] == -2 ) {
 555              $this->dbconn->Begin("WORK");
 556              foreach($_GET['mark'] as $val) {
 557                  $p = new timetrack($this->dbconn);
 558                  $p = $p->read($val,$p);
 559                  if ( !is_object($p) || ($p->id != $val) ) {
 560                      continue;
 561                  }
 562                  if ( $p->del_ok() ) {
 563                      $info = addLine($info,sprintf($lang['Delete']) .":". $p->getFullName());
 564                      $msg = addLine($msg,$p->delete());
 565                      $this->dropSubSession();
 566                  } else {
 567                      $msg = addLine($msg,$p->getLink() .': '. sprintf($lang['Err0023'],$lang[$p->getType()]));
 568                  }
 569                  unset($p);
 570              }
 571              $this->dbconn->Commit("WORK");
 572          } else if ( preg_match("#^([S])(.*)#",$_GET['action'],$a) ) {
 573              $this->dropSubSession();
 574              $this->dbconn->Begin("WORK");
 575              foreach($_GET['mark'] as $val) {
 576                  $p = new timetrack($this->dbconn);
 577                  $p = $p->read($val,$p);
 578                  if ( $p->id != $val ) {
 579                      continue;
 580                  }
 581                  if ( $p->mod_ok() ) {
 582                      $x = (integer)$a[2];
 583                      if (!$this->stc->check_trans($p->state,$x)) {
 584                          $msg = addLine($msg,$p->getLink() .': '. sprintf($lang['Err0024'],$lang[$p->getType()]).' ('.$lang['TTState'].')');
 585                          continue;
 586                      }
 587                      $p->setState($x);
 588                      $info = addLine($info,$p->getLink() .' '. sprintf($lang['SetTo'],$lang['TTState'],$lang['TTStates'][$x]));
 589                      $msg  = addLine($msg,$p->save());
 590                  } else {
 591                      $msg = addLine($msg,$p->getLink() .': '. sprintf($lang['Err0024'],$lang[$p->getType()]));
 592                  }
 593                  unset ($p);
 594              }
 595              $this->dbconn->Commit("WORK");
 596          }
 597      }
 598  
 599      /**
 600       * prepare
 601       */
 602      Function prepare() {
 603          global $msg,$tutos,$lang,$table;
 604  
 605          $this->layout_id        = usetimetrack;
 606          $this->name             = $lang['TimetrackOverview'];
 607          $this->css_class        = 'overviewbox';
 608          $this->header           = '';
 609          $this->head             = array();
 610          $this->head['ref']      = true;
 611          $this->head['worker']   = true;
 612          $this->head['state']    = true;
 613          $this->head['distance'] = true;
 614          if (isset($this->hide['distance']) && $this->hide['distance'] )  {
 615              $this->head['distance'] = false;
 616          }
 617  
 618  
 619          if ( ! $this->user->feature_ok(usetimetrack,PERM_SEE) ) {
 620              $msg = addLine($msg,sprintf($lang['Err0022'],"'". $this->name ."'"));
 621              $this->stop = true;
 622          }
 623          if (isset($_GET['ext'])) {
 624              $this->ext = $_GET['ext'];
 625          } else {
 626              $this->ext = 0;
 627          }
 628  
 629          $this->stc = getObject($this->dbconn,$tutos['timetrack_state_stc']);
 630          if (!is_object($this->stc)) {
 631              $this->stc = new Stc(null);
 632              $this->stc->initByArray('TTStates',timetrack::$c_state);
 633          }
 634  
 635          $this->link1 = 'timetrack/timetrack_overview.php';
 636          $this->link1 = addHiddenFields($this->link1);
 637  
 638          $this->q = 'SELECT * FROM '. $this->dbconn->prefix .$table['timetrack'][name];
 639          $this->qpre = ' WHERE ';
 640  
 641          if ( isset($_GET['id']) ) {
 642              if (false == is_numeric($_GET['id'])) {
 643                  $msg = addLine($msg,sprintf($lang['Err0012'],"id",$_GET['id']));
 644                  $this->stop = true;
 645              }
 646              $this->q .= $this->qpre . "id =" . $_GET['id'];
 647              $this->qpre = ' AND ';
 648              $this->link1 = addUrlParameter($this->link1,"id=".$_GET['id']);
 649              $this->addHidden("id", $_GET['id']);
 650          }
 651          if ( isset($_GET['link_id']) && is_numeric($_GET['link_id']) ) {
 652              loadmodule("bugtracking");
 653              if (false == is_numeric($_GET['link_id'])) {
 654                  $msg = addLine($msg,sprintf($lang['Err0012'],"link_id",$_GET['link_id']));
 655                  $this->stop = true;
 656              }
 657              $ref = getObject($this->dbconn,$_GET['link_id']);
 658              $this->header .= $lang['Reference'].' = '.$ref->getLink();
 659              $this->name .= " : ".$ref->getFullName();
 660              $this->q .= $this->qpre . "link_id in (";
 661              $sep = '';
 662              if ( ! isset($_GET['show']) ) {
 663                  $this->q .= $sep . $_GET['link_id'];
 664                  $sep = ",";
 665                  $this->head['ref'] = false;
 666              } else {
 667                  $this->link1 = addUrlParameter($this->link1,"show=". $_GET['show']);
 668                  $this->addHidden("show",$_GET['show']);
 669                  if ( $_GET['show'] == "Tasks" ) {
 670                      add_task_ids($ref,$this->q,$sep);
 671                      $sep = ",";
 672                      $this->header .= '('.$lang['Tasks'].')';
 673                  } else if ( $_GET['show'] == "Sprint" ) {
 674                      loadmodule("scrumsprint");
 675                      ScrumSprint::add_ids($ref,$this->q,$sep);
 676                      $sep = ",";
 677                      $this->header .= '('.$lang['ScrumLog'].')';
 678                  } else if ( $_GET['show'] == "Bugs" ) {
 679                      add_bugs_ids($ref,$this->q,$sep);
 680                      $sep = ",";
 681                      $this->header .= '('.$lang['Bugs'].')';
 682                  } else if ( $_GET['show'] == "Installations" ) {
 683                      add_inst_ids($ref,$this->q,$sep);
 684                      $sep = ",";
 685                      $this->header .= '('.$lang['Installations'].')';
 686                  } else if ( $_GET['show'] == "all" ) {
 687                      $this->q .= $sep . $_GET['link_id'];
 688                      $sep = ",";
 689                      add_task_ids($ref,$this->q,$sep);
 690                      add_bugs_ids($ref,$this->q,$sep);
 691                      add_inst_ids($ref,$this->q,$sep);
 692                      if (defined('USESCRUMSPRINT')) {
 693                          loadmodule("scrumsprint");
 694                          ScrumSprint::add_ids($ref,$this->q,$sep);
 695                      }
 696                  }
 697              }
 698              $this->q .= ')';
 699              $this->qpre = ' AND ';
 700              $this->link1 = addUrlParameter($this->link1,"link_id=". $_GET['link_id']);
 701              $this->addHidden("link_id",$_GET['link_id']);
 702              $this->header .= "<br />\n";
 703          }
 704  
 705          // Search in description
 706          overview_arg($this,'name',OVERVIEW_ARG_STRING,'timetrack',array('description'),'Description');
 707          // Start Date for search
 708          overview_arg($this,'f',OVERVIEW_ARG_D_FROM,'timetrack',array('vtime'),'TimetrackDate');
 709          // End Date for search
 710          overview_arg($this,'t',OVERVIEW_ARG_D_TO,'timetrack',array('vtime'),'TimetrackDate');
 711          // reference to display
 712          overview_arg($this,'reffn',OVERVIEW_ARG_FN,'timetrack',array('link_id'),'TimetrackRef','',array(useprojects,usebugtracking,usetaskmanagement));
 713          overview_arg($this,'refid',OVERVIEW_ARG_OBJID,'timetrack',array('link_id'),'TimetrackRef','',array(useprojects,usebugtracking,usetaskmanagement));
 714  
 715  
 716          // Search for state
 717          if ( isset($_GET['state']) && is_numeric($_GET['state'])) {
 718              $_GET['state'] = array($_GET['state']);
 719          }
 720          if ( isset($_GET['state']) && is_array($_GET['state']) && count($_GET['state']) > 0) {
 721              $skip = false;
 722              $q = '';
 723              $pre = '';
 724              $h = '';
 725              $hpre = '';
 726              $cnt = 0;
 727              foreach($_GET['state'] as $s) {
 728                  if (false == is_numeric($s)) {
 729                      $msg = addLine($msg,sprintf($lang['Err0012'],"state",$_GET['state']));
 730                      $this->stop = true;
 731                      continue;
 732                  }
 733                  $q .= $pre.$s;
 734                  if ($s == -2) $skip = true; // any
 735                  $this->link1 = addUrlParameter($this->link1,"state[]=".$s);
 736                  $this->addHidden("state[]",$s);
 737                  $_SESSION[usetimetrack.'__state'][] = $s;
 738                  $h .= $hpre.$this->stc->getState($s);
 739                  $cnt ++;
 740                  $pre = ',';
 741                  $hpre = ' / ';
 742              }
 743              if (!$skip) {
 744                  $this->q .= $this->qpre .'state in('. $q .')';
 745                  $this->qpre = ' AND ';
 746                  if ($cnt == 1) {
 747                      $this->head['state'] = false;
 748                      $this->header .= $this->hpre.$lang['TTState'].' = '.$h;
 749                  }
 750                  if ($cnt > 1) {
 751                      $this->head['state'] = true;
 752                      $this->header .= $this->hpre.$lang['TTState'].' = ('.$h.')';
 753                  }
 754                  $this->hpre = '<br />';
 755              }
 756          }
 757  
 758          // Search for worker
 759          if ( isset($_GET['worker']) && is_numeric($_GET['worker']) && ($_GET['worker'] != -1) ) {
 760              $this->head['worker'] = false;
 761              $x = getObject($this->dbconn,$_GET['worker']);
 762              if (!is_object($x)) {
 763                  $msg = addLine($msg,sprintf($lang['Err0012'],$lang['TimetrackWorker'],$_GET['worker']));
 764                  $this->stop = true;
 765                  return;
 766              } else if ( $x->getType() == "address" ) {
 767                  $this->q .= $this->qpre . "adr_id =" . $_GET['worker'];
 768              } else if ( $x->getType() == "user" ) {
 769                  $this->q .= $this->qpre . "adr_id =" . $_GET['worker'];
 770              } else if ( $x->getType() == "team" ) {
 771                  $this->q .= $this->qpre . "adr_id in (" . $_GET['worker'];
 772                  $x->read_member();
 773                  foreach ($x->member as $i1 => $f1) {
 774                      $this->q .= "," . $i1;
 775                  }
 776                  $this->q .= ")";
 777                  $this->head['worker'] = true; // in case of team filter show worker
 778              } else {
 779                  $this->q .= $this->qpre . "adr_id =" . $_GET['worker'];
 780              }
 781              $this->qpre = ' AND ';
 782              $this->link1 = addUrlParameter($this->link1,"worker=".$_GET['worker']);
 783              $this->addHidden("worker",$_GET['worker']);
 784              $this->header .= $this->hpre.$lang['TimetrackWorker'].' = '.$x->getLink();
 785              $this->hpre = '<br />';
 786          }
 787          $custom = get_custom_sql_select($this,'product','',$this->link1);
 788          foreach ($custom[0] as $s) {
 789              $this->q .= $this->qpre;
 790              $this->q .= $s[0];
 791              $this->qpre = " AND ";
 792              $this->header .= $this->hpre.$s[1];
 793              $this->hpre = '<br />';
 794          }
 795          foreach ($custom[1] as $s) {
 796              $this->q = preg_replace('# where#i',','.$s.' WHERE',$this->q);
 797          }
 798  
 799          check_dbacl($this->dbconn, $this->q, $this->user->id);
 800          // sorting
 801          $this->link2 = $this->link1;
 802          $xxx = "";
 803  
 804          order_parse($this->q,$this->link1,$xxx,$this,array('vtime',2));
 805          if ($this->stop) {
 806              return;
 807          }
 808  
 809          $this->result = $this->dbconn->Exec($this->q);
 810  
 811          if ( 0 == $this->result->numrows()) {
 812              $this->redirect = 'timetrack_select.php?msg='. UrlEncode($lang['Err0048']);
 813              if ($this->ext != 0) {
 814                  $this->redirect = addUrlParameter($this->redirect,'ext=1',true);
 815              }
 816              $this->result->free();
 817          }
 818  
 819          // menu
 820          $x = timetrack::getSelectLink($this->user);
 821          $x[category][] = "obj";
 822          $this->addmenu($x);
 823  
 824          if ( $this->format != "stat" ) {
 825              $l = addUrlParameter($this->link1,'format=stat');
 826              $x = array( url => $l,
 827                          text => $lang['BugStats'],
 828                          info => $lang['BugStatsInfo'],
 829                          category => array('graph','timtrack','view',usetimetrack)
 830                  );
 831              $this->addMenu($x);
 832          }
 833  
 834          $l = addUrlParameter($this->link1,'format=csv');
 835          $x = array( url => $l,
 836                      text => $lang['Export'] ."(CSV)",
 837                      info => $lang['ExportInfo'],
 838                      category => array('csv','timtrack','view',usetimetrack)
 839              );
 840          $this->addMenu($x);
 841  
 842          $l = addUrlParameter($this->link1,'format=excel');
 843          $x = array( url => $l,
 844                      text => $lang['Export'] ."(EXCEL)",
 845                      info => $lang['ExportInfo'],
 846                      category => array('excel','timtrack','view',usetimetrack)
 847              );
 848          $this->addMenu($x);
 849  
 850          if ( $this->format != "paper" ) {
 851              $ll = addUrlParameter($this->link1,'format=paper');
 852              $x = array( url => $ll,
 853                          text => $lang['Printable'],
 854                          info => $lang['PrintableInfo'],
 855                          category => array('print','timetrack','view',usetimetrack)
 856                  );
 857              $this->addMenu($x);
 858          }
 859  
 860          if (class_exists('url')) {
 861              $this->addMenu(url::getAddLinkPreset($this->user,$this));
 862          }
 863      }
 864  }
 865  
 866  $l = new Timetrack_overview($current_user);
 867  $l->display();
 868  $dbconn->Close();
 869  ?>

title

Description

title

Description

title

Description

title

title

Body