TUTOS PHP Cross Reference Groupware Applications

Source: /php/product_overview.php - 1021 lines - 38011 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: product_overview.php 1184 2013-11-24 09:01:08Z gokohnert $
  10   *  $Author: gokohnert $
  11   *
  12   * @modulegroup product
  13   * @module product_overview
  14   * @package product
  15   */
  16  $tutos['files'][__FILE__] = '$Rev: 1184 $';
  17  
  18  require_once  'webelements.p3';
  19  require_once  'permission.p3';
  20  
  21  /* Check if user is allowed to use it */
  22  check_user();
  23  
  24  require_once  'appointment.pinc';
  25  require_once  'product.pinc';
  26  require_once  'task.pinc';
  27  require_once  'graphs.pinc';
  28  
  29  loadmodules('product','overview');
  30  loadlayout();
  31  
  32  /**
  33   * show a overview of projects
  34   */
  35  class Product_overview extends layout {
  36      /**
  37       * CSV Export Info
  38       */
  39      Function exportinfo() {
  40          global $lang,$tutos;
  41  
  42          $r = '';
  43          export_headers('TUTOS_product_export','csv');
  44          $a = 0;
  45  
  46          $r .= product::exportCSV_Header($this->pshow);
  47          foreach($this->plist as $p) {
  48              if (!is_object($p)) {
  49                  $id = $p;
  50                  $p = new product($this->dbconn);
  51                  $p = $p->read($id,$p);
  52              }
  53              $r .= $p->exportCSV($this->pshow);
  54              unset($p);
  55          }
  56          return $r;
  57      }
  58  
  59      /**
  60       * display the info
  61       */
  62      Function info() {
  63          global $lang,$tutos,$table;
  64  
  65          $r = '';
  66  
  67          if ($this->format == "xml" ) {
  68              $p = new product($this->dbconn);
  69              $r .= $p->exportXMLHeader();
  70              $r .= $p->exportXML_Head();
  71              $r .= "<product_set>\n";
  72              foreach($this->plist as $x) {
  73                  $r .= $x->exportXML_start();
  74                  $r .= $x->exportXML_body();
  75                  $r .= $x->exportXML_end();
  76              }
  77              $r .= "</product_set>\n";
  78              return $r;
  79          }
  80  
  81          if ($this->format == "stat" ) {
  82              $r = $this->statinfo();
  83              return $r;
  84          }
  85          if ($this->format == "csv" ) {
  86              $r = $this->exportinfo();
  87              return $r;
  88          }
  89  
  90          $this->flds = 0;
  91          $pf = 0;
  92  
  93          $n = count($this->plist);
  94          if ( 0 == $n) {
  95              $r .= $this->error($lang['Err0048']);
  96              return;
  97          }
  98          if ( $this->pshow['checkbox'] ) {
  99              $r .= $this->actionformStart("product_overview.php");
 100          }
 101          $sum = $this->nav['sum'];
 102  
 103          $r .= $this->header;
 104          $r .= $this->OverviewTableStart();
 105          $r .= $this->OverviewHeadStart();
 106          $r .= $this->OverviewHeadLineStart();
 107  
 108          foreach ($tutos[prodfields] as $c) {
 109              if ( ($c == 'name') && $this->pshow[$c] ) {
 110                  $r .= $this->orderHeader('name',$lang['ProdName'],$this->link2);
 111                  $this->flds++;
 112              }
 113              if ( ($c == 'version') && $this->pshow[$c] ) {
 114                  $r .= $this->orderHeader('version',$lang['ProdVersion'],$this->link2);
 115                  $this->flds++;
 116              }
 117              if ( preg_match('#role_#',$c) && $this->pshow[$c] ) {
 118                  foreach ( $lang['ProdRole'] as $ti => $tx) {
 119                      if ( $c == 'role_'.$ti ) {
 120                          $r .= $this->orderHeader('',$lang['ProdRole'][$ti],$this->link2);
 121                          $this->flds++;
 122                      }
 123                  }
 124              }
 125              if ( ($c == 'desc') && $this->pshow[$c] ) {
 126                  $r .= $this->orderHeader('description',$lang['ProdDesc'],$this->link2);
 127                  $this->flds++;
 128              }
 129              if ( ($c == 'desc1') && $this->pshow[$c] ) {
 130                  $r .= $this->orderHeader('desc1',$lang['ProdDesc1'],$this->link2);
 131                  $this->flds++;
 132              }
 133              if ( ($c == 'desc2') && $this->pshow[$c] ) {
 134                  $r .= $this->orderHeader('desc2',$lang['ProdDesc2'],$this->link2);
 135                  $this->flds++;
 136              }
 137              if ( ($c == 'cl1') && $this->pshow[$c] ) {
 138                  $r .= $this->orderHeader('',$lang['ProdClass1'],$this->link2);
 139                  $this->flds++;
 140              }
 141              if ( ($c == 'cl2') && $this->pshow[$c] ) {
 142                  $r .= $this->orderHeader('',$lang['ProdClass2'],$this->link2);
 143                  $this->flds++;
 144              }
 145              if ( ($c == 'state') && $this->pshow[$c] ) {
 146                  $r .=$this-> orderHeader('state',$lang['ProdState'],$this->link2);
 147                  $this->flds++;
 148              }
 149              if ( ($c == 'probability') && $this->pshow[$c] ) {
 150                  $r .= $this->orderHeader('probability',$lang['ProdProb'],$this->link2);
 151                  $this->flds++;
 152              }
 153              if ( ($c == 'price') && $this->pshow[$c] ) {
 154                  $r .= $this->orderHeader('currency,price',$lang['ProdPrice'],$this->link2);
 155                  $this->flds++;
 156                  $pf = $this->flds;
 157              }
 158              if ( ($c == 'cost') && $this->pshow[$c] ) {
 159                  $r .= $this->orderHeader('currency,cost',$lang['ProdCost'],$this->link2);
 160                  $this->flds++;
 161                  $cf = $this->flds;
 162              }
 163              if ( ($c == 'creator') && $this->pshow[$c] ) {
 164                  $r .= $this->orderHeader('',$lang['ProdCreator'],$this->link2);
 165                  $this->flds++;
 166              }
 167              if ( ($c == 'creation') && $this->pshow[$c] ) {
 168                  $r .= $this->orderHeader('creation',$lang['ProdCreationS'],$this->link2);
 169                  $this->flds++;
 170              }
 171              if ( ($c == 'p_start') && $this->pshow[$c] ) {
 172                  $r .= $this->orderHeader('p_start',$lang['ProdStart'],$this->link2);
 173                  $this->flds++;
 174              }
 175              if ( ($c == 'p_end') && $this->pshow[$c] ) {
 176                  $r .= $this->orderHeader('p_end',$lang['ProdEnd'],$this->link2);
 177                  $this->flds++;
 178              }
 179              if ( $this->user->feature_ok(usebugtracking,PERM_SEE) ) {
 180                  if ( ($c == 'pbugs') && $this->pshow[$c] ) {
 181                      $r .= $this->orderHeader('',$lang['Bugs'],$this->link2);
 182                      $this->flds++;
 183                  }
 184              }
 185              if ( $this->user->feature_ok(usedocmanagement,PERM_SEE) ) {
 186                  if ( ($c == 'pfile') && $this->pshow[$c] ) {
 187                      $r .= $this->orderHeader('',$lang['Files'],$this->link2);
 188                      $this->flds++;
 189                  }
 190              }
 191              if ( $this->user->feature_ok(usetaskmanagement,PERM_SEE) ) {
 192                  if ( ($c == 'ptask') && $this->pshow[$c] ) {
 193                      $r .= $this->orderHeader('',$lang['Tasks'],$this->link2);
 194                      $this->flds++;
 195                  }
 196              }
 197              // Custom fields
 198              foreach(get_custom_overview_fields($this,'product') as $ti => $tx) {
 199                  if ( ($c == 'p_c_'.$ti) && $this->pshow[$c] ) {
 200                      if (isset($tx['sortable']) && ($tx['sortable'] == true) ) {
 201                          $sortby = $ti;
 202                      } else {
 203                          $sortby = '';
 204                      }
 205                      $r .= $this->orderHeader($sortby,myentities(isset($lang[$tx['lang']]) ? $lang[$tx['lang']]:$tx['lang']),$this->link2);
 206                      $this->flds++;
 207                  }
 208              }
 209  
 210              if ( ($c == 'checkbox') && $this->pshow[$c] ) {
 211                  // Column for checkboxes
 212                  $r .= $this->MassupdateHeader();
 213                  $this->flds++;
 214              }
 215          }
 216          $r .= $this->OverviewHeadLineEnd();
 217          $r .= $this->OverviewHeadEnd();
 218          $r .= $this->OverviewBodyStart();
 219  
 220          if ( $this->format == 'paper' ) {
 221              $a = 0;
 222              $end = $n;
 223          } else if ( $this->start == -1 ) {
 224              $a = $n - $tutos['maxshow'];
 225              $end = $n;
 226              $this->start = $a;
 227          } else {
 228              $a = $this->start;
 229              $end = $this->start + $tutos['maxshow'];
 230          }
 231          $line = 0;
 232  
 233  
 234          while ( ($a < $n) && ($a < $end) ) {
 235              $p = &$this->plist[$a];
 236              if (!is_object($p)) {
 237                  $id = $p;
 238                  $p = new product($this->dbconn);
 239                  $p = $p->read($id,$p);
 240              }
 241              $p->readroles();
 242  
 243              $r .= $this->OverviewRowStart($line,$lang[$p->getType()] .': '. $p->getFullName());
 244              foreach ($tutos[prodfields] as $c) {
 245                  if (! $this->pshow[$c]) {
 246                      continue;
 247                  }
 248                  $xx = '';
 249  
 250                  if ( $c == 'name' ) {
 251                      $xx .= makelink($p->getUrl('ss='.$this->ss),$this->mark_filter(myentities($p->name),'name'));
 252                  } else if ( $c == 'version' ) {
 253                      $xx .= $this->mark_filter(myentities($p->version),'name');
 254                  } else if ( preg_match('#role_#',$c) ) {
 255                      foreach ( $lang['ProdRole'] as $ti => $tx) {
 256                          if ( ($c == 'role_'.$ti) && isset($p->role[$ti]) && (count($p->role[$ti]) > 0) ) {
 257                              $x = 0;
 258                              foreach ($p->role[$ti] as $i => $rx ) {
 259                                  if ( $x > 0 ) {
 260                                      $xx .= "<br />\n";
 261                                  }
 262                                  $xx .=  $rx->getLink($rx->getShortname());
 263                                  $x++;
 264                              }
 265                          }
 266                      }
 267                  } else if ( $c == 'desc' ) {
 268                      $xx .= $this->mark_filter(myentities($p->description),'name');
 269                  } else if ( $c == 'desc1' ) {
 270                      $xx .= $this->mark_filter(myentities($p->desc1),'name');
 271                  } else if ( $c == 'desc2' ) {
 272                      $xx .= $this->mark_filter(myentities($p->desc2),'name');
 273                  } else if ( $c == 'state' ) {
 274                      $xx .= $p->getStateColorBlock().$p->getState();
 275                  } else if ( $c == 'probability' ) {
 276                      $xx .= '<div align="right">'. $p->probability .'%</div>';
 277                  } else if ( $c == 'price' ) {
 278                      $b =  array($p->price,$p->currency);
 279                      $xx .= '<div align="right">'. handle('money',$b,my_number_format($p->price,2) .' '. myentities($p->currency)) .'</div>';
 280                  } else if ( $c == 'cost' ) {
 281                      $b =  array($p->cost,$p->currency);
 282                      $xx .= '<div align="right">'. handle('money',$b,my_number_format($p->cost,2) .' '. myentities($p->currency)) .'</div>';
 283                  } else if ( $c == 'creator' ) {
 284                      $xx .= (is_object($p->creator) ? $p->creator->getLink($p->creator->getShortname()):$lang['HistoryDeleted']);
 285                  } else if ( $c == 'creation' ) {
 286                      $xx .= $p->creation->getLinkDate();
 287                  } else if ( $c == 'p_start' ) {
 288                      $xx .= $p->p_start->getLinkDate();
 289                  } else if ( $c == 'p_end' ) {
 290                      $xx .= $p->p_end->getLinkDate();
 291                  } else if ( $c == 'pbugs' ) {
 292                      if ( $this->user->feature_ok(usebugtracking,PERM_SEE) ) {
 293                          bug::obj_read($p);
 294                          $xx .= bug::summary($p);
 295                      }
 296                  } else if ( $c == 'pfile' ) {
 297                      if ( $this->user->feature_ok(usedocmanagement,PERM_SEE) ) {
 298                          tutos_file::obj_read($p);
 299                          $xx .= tutos_file::summary($p);
 300                      }
 301                  } else if ( $c == 'ptask' ) {
 302                      if ( $this->user->feature_ok(usetaskmanagement,PERM_SEE) ) {
 303                          task::obj_read($p);
 304                          $xx .= task::summary($p);
 305                      }
 306                  } else if ( $c == 'checkbox' ) {
 307                      $xx .= '<div align="center">';
 308                      // Column for checkboxes
 309                      if ( $p->mod_ok() ) {
 310                          $xx .= '<input class="m_field" name="mark[]" type="checkbox" value="'. $p->id ."\" />\n";
 311                      } else {
 312                          $xx .= "-\n";
 313                      }
 314                      $xx .= "</div>";
 315                  } else if( preg_match('#cl#',$c) ) {
 316                      for ( $cl = 1;$cl <= $p->classes; $cl++) {
 317                          if ( $c == 'cl'.$cl ) {
 318                              $sep = '';
 319                              @reset($p->cl[$cl]);
 320                              while ( list ($i,$f) = @each ($p->cl[$cl]) ) {
 321                                  if ( isset ($lang['ProdClasses'.$cl][$f]) ) {
 322                                      $xx .= $sep . $lang['ProdClasses'.$cl][$f] ;
 323                                  } else {
 324                                      $xx .= $sep . $f ;
 325                                  }
 326                                  $sep = "<br />\n";
 327                              }
 328                          }
 329                      }
 330                  } else if( preg_match('#p_c_#',$c) ) {
 331                      $c = preg_replace('#^p_c_#','',$c);
 332                      $x = $table['product'][$c];
 333                      $f = '_fld_'.$c;
 334                      $xx .= get_custom_field($x,$p->$f,$p,$this,'product',$c);
 335                  } else {
 336                      $xx .= '??????';
 337                  }
 338  
 339                  $r .= $this->OverviewRowBlock($xx,'over_l');
 340              }
 341              $r .= $this->OverviewRowEnd($line++);
 342              unset($this->plist[$a]);
 343              unset($p);
 344              $a++;
 345          }
 346          $r .= $this->OverviewBodyEnd();
 347          $r .= $this->OverviewFootStart();
 348  
 349          $r .= $this->list_navigation(addUrlParameter($this->link1,'ss='.$this->ss),$this->flds,$this->start,$a,$n);
 350  
 351          // Sum of Prices
 352          if ( ($this->pshow['price'] == 1) || ($this->pshow['cost'] == 1) ) {
 353              $r .= "<tr>\n";
 354              $fill = 0;
 355              foreach ($tutos[prodfields] as $i => $c) {
 356                  if (  $this->pshow[$c] == 0 ) {
 357                      continue;
 358                  }
 359                  if ( $c == 'price' ) {
 360                      if ( $fill > 0 ) {
 361                          $r .= ' <td colspan="'. $fill ."\">&#160;</td>\n";
 362                          $fill = 0;
 363                      }
 364                      $r .= " <td align=\"right\">\n";
 365                      $pre = '';
 366                      foreach ($sum[1] as $i1 => $f1) {
 367                          if ( $f1 ) {
 368                              $r .= $pre . my_number_format($f1,2) .' '. $i1;
 369                              $pre = "<br />\n";
 370                          }
 371                      }
 372                      $r .= " </td>\n";
 373                  } else if ( $c == 'cost' ) {
 374                      if ( $fill > 0 ) {
 375                          $r .= " <td colspan=\"". $fill ."\">&#160;</td>\n";
 376                          $fill = 0;
 377                      }
 378                      $r .= " <td align=\"right\">\n";
 379                      $pre = '';
 380                      foreach ($sum[2] as $i1 => $f1) {
 381                          if ( $f1 ) {
 382                              $r .= $pre . my_number_format($f1,2) .' '. $i1;
 383                              $pre = "<br />\n";
 384                          }
 385                      }
 386                      $r .= " </td>\n";
 387                  } else {
 388                      $fill++;
 389                  }
 390              }
 391              if ( $fill > 0 ) {
 392                  $r .= " <td colspan=\"". $fill ."\">&#160;</td>\n";
 393              }
 394              $r .= "</tr>\n";
 395          }
 396  
 397          if ( $this->pshow['checkbox'] ) {
 398              if (isset($_REQUEST['name'])) {
 399                  $this->addHidden('name',$_REQUEST['name']);
 400              } else {
 401                  $this->addHidden('name','');
 402              }
 403              // Mass Update
 404              $r .= $this->UpdateRowStart($this->flds -1);
 405              $r .= sprintf($lang['withmarked'],$lang['ProductPs']);
 406              $r .= "&#160;<select name=\"action\">\n";
 407              $r .= " <option value=\"-1\" selected=\"selected\">". $lang['ActionNil'] ."</option>\n";
 408              $r .= " <option value=\"-2\">". $lang['Delete'] ."</option>\n";
 409  
 410              foreach ($this->stc->states as $f) {
 411                  if ($f->stc_state == STC_NOT_EXISTANT) continue;
 412                  if ($f->stc_state == -2) continue;
 413                  $r .= ' <option value="S'. $f->stc_state .'">'. sprintf($lang['SetTo'],$lang['ProdState'],$f->getFullName()) ."</option>\n";
 414              }
 415              $r .= get_custom_massupdate_options($this,'product');
 416              $r .= " <option value=\"-4\">". $lang['AclModify'] ."</option>\n";
 417              if (class_exists('watchlist')) {
 418                  $r .= watchlist::action_options();
 419              }
 420              $r .= " <option value=\"-5\">". $lang['TaskOverview'] ."</option>\n";
 421              $r .= "</select>\n";
 422              $r .= $this->UpdateRowEnd(1);
 423          }
 424  
 425          $r .= $this->OverviewFootEnd();
 426          $r .= $this->OverviewTableEnd();
 427          if ( $this->pshow['checkbox'] ) {
 428              $r .= $this->actionformEnd("product_overview.php");
 429          }
 430          return $r;
 431      }
 432  
 433      /**
 434       * some graphs that show staistics
 435       */
 436      Function statinfo() {
 437          global $lang,$tutos;
 438  
 439          $r = '';
 440          $a = 0;
 441          $n = count($this->plist);
 442          $cnt = 0;
 443          for ( $c = 1;$c <= 2; $c++) {
 444              $cl[$c] = array();
 445          }
 446          foreach($this->plist as $p) {
 447              if (!is_object($p)) {
 448                  $id = $p;
 449                  $p = new product($this->dbconn);
 450                  $p = $p->read($id,$p);
 451              }
 452              $p->readroles();
 453              $cnt++;
 454  
 455              // Manager
 456              if (isset($p->role[1]) && (count($p->role[1]) > 0) ) {
 457                  @reset ($p->role[1]) ;
 458                  $x = 0;
 459                  while ( list ($i,$rx) = @each ($p->role[1]) ) {
 460                      if ( !isset($manager[$rx->id]) ) {
 461                          $manager[$rx->id] = 0;
 462                      }
 463                      $manager[$rx->id]++;
 464                  }
 465              }
 466              if (isset($p->role[3]) && (count($p->role[3]) > 0) ) {
 467                  @reset ($p->role[3]) ;
 468                  $x = 0;
 469                  while ( list ($i,$rx) = @each ($p->role[3]) ) {
 470                      if ( !isset($manager[$rx->id]) ) {
 471                          $manager[$rx->id] = 0;
 472                      }
 473                      $manager[$rx->id]++;
 474                  }
 475              }
 476  
 477              // States
 478              if ( !isset($states[$p->state]) ) {
 479                  $states[$p->state] = 0;
 480              }
 481              $states[$p->state]++;
 482  
 483              // Classifications
 484              for ( $c = 1;$c <= 2; $c++) {
 485                  @reset($p->cl[$c]);
 486                  while ( list ($i,$f) = @each ($p->cl[$c]) ) {
 487                      if ( !isset($cl[$c][$i]) ) {
 488                          $cl[$c][$i] = 0;
 489                      }
 490                      $cl[$c][$i]++;
 491                  }
 492              }
 493              unset($p);
 494          }
 495  
 496          $r .= $this->DataTableStart();
 497          $r .= "<tr>\n";
 498          $r .= " <th colspan=\"6\">". $lang['ProdStatsTitle'] ."</th>\n";
 499          $r .= "</tr>\n";
 500  
 501          $r .= "<tr>\n";
 502          $r .= $this->showfield($lang['Count']);
 503          $r .= "<td colspan=\"5\">". $cnt ."\n";
 504          $pre = "filtered by ";
 505          while ( list ($i,$f) = @each ($this->filter) ) {
 506              if ( $f == "" ) {
 507                  continue;
 508              }
 509              if ( $i == 'state' ) {
 510                  $f = $f + 0;
 511                  $r .= $pre . $lang['ProdState'];
 512                  $r .= " ". $lang['ProdStates'][$f];
 513              } else if ( $i == 'cl1' ) {
 514                  $r .= $pre . $lang['ProdClass1'];
 515                  $r .= " ". $lang['ProdClasses1'][$f];
 516              } else if ( $i == 'cl2' ) {
 517                  $r .= $pre . $lang['ProdClass2'];
 518                  $r .= " ". $lang['ProdClasses2'][$f];
 519              } else if ( $i == 'name' ) {
 520                  $r .= $pre . $lang['ProdDesc'];
 521                  $r .= " ". $f;
 522              } else if ( $i == 'from' ) {
 523                  $r .= $pre . $lang['DateTimeFrom'];
 524                  $r .= " ". $f->getDateTime();
 525              } else if ( $i == 'to' ) {
 526                  $r .= $pre . $lang['DateTimeTill'];
 527                  $r .= " ". $f->getDateTime();
 528              } else {
 529                  $r .= $pre . $i;
 530                  $r .= " ". $f;
 531              }
 532              $pre = " and ";
 533          }
 534          $r .= " </td>\n";
 535          $r .= "</tr>\n";
 536  
 537          // State distribution
 538          $r .= "<tr>\n";
 539          $r .= $this->showfield($lang['ProdState']);
 540          $r .= ' <td colspan="5" valign="top">';
 541          $spie = array();
 542          $spie['title'] = $lang['ProdState'];
 543          foreach ($states as $i => $f) {
 544              $e = array();
 545              $e['val']   = $f;
 546              $e['cnt']   = $f;
 547              $e['title'] = $i;
 548              if (isset($this->stc->states[$i])) {
 549                  $e['title'] = $this->stc->states[$i]->getFullName();
 550                  $e['color'] = $this->stc->states[$i]->color;
 551              }
 552              $spie['data'][] = $e;
 553          }
 554          $r .= pie($spie);
 555          $r .= ' </td>'."\n";
 556          $r .= "</tr>\n";
 557  
 558          // Classifications
 559          for ( $c = 1;$c <= 2; $c++) {
 560              $r .= "<tr>\n";
 561              $r .= $this->showfield($lang['ProdClass'.$c]);
 562              $r .= ' <td colspan="5" valign="top">';
 563              $spie = array();
 564              $spie['title'] = $lang['ProdClass'.$c];
 565              foreach ($cl[$c] as $i => $f) {
 566                  $e = array();
 567                  $e['val']   = $f;
 568                  $e['cnt']   = $f;
 569                  $e['title'] = $i;
 570                  if ( isset($lang['ProdClasses'.$c][$i]) ) {
 571                      $e['title'] = $lang['ProdClasses'.$c][$i];
 572                  }
 573                  $spie['data'][] = $e;
 574              }
 575              $r .= pie($spie);
 576              $r .= ' </td>'."\n";
 577              $r .= "</tr>\n";
 578          }
 579  
 580          // Manager distribution
 581          $r .= "<tr>\n";
 582          $r .= $this->showfield($lang['ProdRole'][1]);
 583          $r .= ' <td colspan="5" valign="top">';
 584          $spie = array();
 585          $spie['title'] = $lang['ProdRole'][1];
 586          $c = 0;
 587          foreach ($manager as $i => $f) {
 588              $m = new tutos_address($this->dbconn);
 589              $m = $m->read($i,$m);
 590              if ( !is_object($m) ) {
 591                  $m = new team($this->dbconn);
 592                  $m = $m->read($i,$m);
 593              }
 594              if ( !is_object($m) ) continue;
 595  
 596              $e = array();
 597              $e['val']   = $f;
 598              $e['cnt']   = $f;
 599              $e['title'] = $m->getLink();
 600              $e['tobj']  = $m;
 601              $c++;
 602              $spie['data'][] = $e;
 603          }
 604          $r .= pie($spie);
 605          $r .= ' </td>'."\n";
 606          $r .= "</tr>\n";
 607  
 608          $r .= $this->DataTableEnd();
 609          return $r;
 610      }
 611  
 612      /**
 613       * navigate
 614       */
 615      Function navigate() {
 616          global $lang,$tutos;
 617  
 618          $r = '';
 619          if ( $this->format != "stat" ) {
 620              foreach ($this->pshow as $i => $f) {
 621                  if ( $f == 0 ) {
 622                      $schecked[$i] = "";
 623                  } else {
 624                      $schecked[$i] = " checked=\"checked\"";
 625                  }
 626              }
 627              $r .= "<tr><td>";
 628              $r .= "<form id=\"ProdFields\" action=\"product_overview.php\" method=\"get\">";
 629              $r .= "<script type=\"text/javascript\" language=\"JavaScript\">\n";
 630              $r .= "//<![CDATA[\n";
 631              $r .= "function CheckAll() {\n";
 632              $r .= "  for (var i=0; i < document.forms['ProdFields'].elements.length; i++) {\n";
 633              $r .= "   var e = document.forms['ProdFields'].elements[i];\n";
 634              $r .= "   if (e.name != 'checkit')\n";
 635              $r .= "     e.checked = document.forms['ProdFields'].checkit.checked;\n";
 636              $r .= "  }\n";
 637              $r .= "}\n";
 638              $r .= "//]]>\n";
 639              $r .= "</script>\n";
 640              $r .= DoubleTableStart(0,0);
 641              $r .= "<tr><th>". $lang['ProdFields'] ."</th></tr>\n";
 642              foreach ($tutos[prodfields] as $i => $c) {
 643                  if ( ! isset($this->flds[$c]) ) {
 644                      continue;
 645                  }
 646                  if ( $this->flds[$c] == '' ) {
 647                      continue;
 648                  }
 649                  $r .= "<tr><td class=\"over_l\">\n";
 650                  $r .= " <input type=\"checkbox\" id=\"ps_".$c."\" name=\"ps[]\"". $schecked[$c] ." value=\"". $c ."\" /><label for=\"ps_".$c."\">". myentities(isset($lang[$this->flds[$c]]) ? $lang[$this->flds[$c]] : $this->flds[$c]) ."</label>\n";
 651                  $r .= "</td></tr>\n";
 652              }
 653              $r .= "<tr><td class=\"over_r\"><hr noshade=\"noshade\" /></td></tr>\n";
 654              $r .= "<tr><td class=\"over_l\">\n";
 655              $r .= " <input type=\"checkbox\" id=\"all\" name=\"checkit\" onclick=\"CheckAll();\" /><label for=\"all\">". $lang['all'] ."</label>\n";
 656              $r .= "</td></tr>\n";
 657  
 658              $r .= "<tr><td><input type=\"submit\" value=\"". $lang['show'] ."\" /></td></tr>\n";
 659              $r .= DoubleTableEnd();
 660              $r .= hiddenFormElements();
 661              // save the hidden stuff for the other form
 662              $x = $this->hidden;
 663              $r .= $this->getHidden();
 664              $this->hidden = $x;
 665              $r .= "</form>\n";
 666              $r .= "</td></tr>";
 667          }
 668          return $r;
 669      }
 670  
 671      /**
 672       * action
 673       */
 674      Function action() {
 675          global $tutos,$msg,$lang,$info;
 676  
 677          $this->stc = getObject($this->user->dbconn,$tutos['prod_state_stc']);
 678          if (!is_object($this->stc)) {
 679              $this->stc = new stc(null);
 680              $x = new Product($this->user->dbconn);
 681              $this->stc->initByArray('ProdStates',$x->c_state);
 682          }
 683  
 684          if ( $_GET['action'] == -2 ) {
 685              $this->dbconn->Begin("WORK");
 686              foreach ($_GET['mark'] as $key => $val) {
 687                  $p = new product($this->dbconn);
 688                  $p = $p->read($val,$p);
 689                  if ( $p->id != $val ) {
 690                      continue;
 691                  }
 692                  $p->readroles();
 693                  if ( $p->del_ok() ) {
 694                      $info = addLine($info,sprintf($lang['ProdDelInfo'], $p->getFullName()));
 695                      $msg = addLine($msg,$p->delete());
 696                      $this->dropSubSession();
 697                  } else {
 698                      $msg = addLine($msg,$p->getLink() .": ". sprintf($lang['Err0023'],$lang[$p->getType()]));
 699                  }
 700                  unset($p);
 701              }
 702              $this->dbconn->Commit("WORK");
 703              return;
 704          }
 705          if ( preg_match("#^(S)(.*)#",$_GET['action'],$a) ) {
 706              $this->dropSubSession();
 707              $this->dbconn->Begin("WORK");
 708              foreach ($_GET['mark'] as $key => $val) {
 709                  $p = new product($this->dbconn);
 710                  $p = $p->read($val,$p);
 711                  if ( $p->id != $val ) {
 712                      continue;
 713                  }
 714                  $p->readroles();
 715                  if ( $p->mod_ok() ) {
 716                      $this->stc->stateowner = $p;
 717                      if ($a[2] == $p->state) continue;  // keep
 718                      if (!$this->stc->check_trans($p->state,$a[2])) {
 719                          $msg = addLine($msg,$p->getLink() .': '. sprintf($lang['Err0024'],$lang[$p->getType()]).' ('.$lang['ProdState'].')');
 720                          continue;
 721                      }
 722                      $info = addLine($info,$p->getLink() ." ". $lang['ProdState'] ." = ". $lang['ProdStates'][$a[2]]);
 723                      $p->setState($a[2]);
 724                      $msg = addLine($msg,$p->save());
 725                  } else {
 726                      $msg = addLine($msg,$p->getLink() .": ". sprintf($lang['Err0024'],$lang[$p->getType()]));
 727                  }
 728                  unset ($p);
 729              }
 730              $this->dbconn->Commit("WORK");
 731              return;
 732          }
 733  
 734          if ( $_GET['action'] == -4 ) {
 735              $this->redirect = acl_action();
 736              return;
 737          }
 738          // redirect to Task Overview
 739          if ( $_GET['action'] == -5 ) {
 740              $url = 'task_overview.php';
 741              foreach ($_GET['mark'] as $key => $val) {
 742                  $url = addUrlParameter($url,'id[]='.$val,true);
 743              }
 744              // clean msg and info
 745              $msg  = '';
 746              $info = '';
 747              $this->redirect = $url;
 748              return;
 749          }
 750  
 751          foreach ($_GET['mark'] as $key => $val) {
 752              $p = new product($this->dbconn);
 753              $p = $p->read($val,$p);
 754              if ( $p->id != $val ) {
 755                  continue;
 756              }
 757              if (set_custom_massupdate_object($this,'product',$p,$_REQUEST['action'])) {
 758                  $msg = addLine($msg,$p->save());
 759              }
 760          }
 761  
 762          if (class_exists('watchlist')) {
 763              watchlist::parse_action($this->user);
 764          }
 765  
 766      }
 767  
 768      /**
 769       * prepare
 770       */
 771      Function prepare() {
 772          global $msg,$lang,$tutos,$table;
 773  
 774          $this->layout_id = useprojects;
 775          $this->name = $lang['ProductsOverview'];
 776          $this->css_class = 'overviewbox';
 777  
 778          if ( ! $this->user->feature_ok(useprojects,PERM_SEE) ) {
 779              $msg = addLine($msg,sprintf($lang['Err0022'],"'". $this->name ."'"));
 780              $this->stop = true;
 781          }
 782  
 783  
 784          $this->link1 = 'product_overview.php';
 785          $this->link3 = 'sales_forecast.php';
 786  
 787          $this->flds = array();
 788          $this->flds['name']         = 'ProdName';
 789          $this->flds['version']      = 'ProdVersion';
 790          foreach ( $lang['ProdRole'] as $ti => $tx) {
 791              $this->flds['role_'.$ti]  = $tx;
 792          }
 793          $this->flds['desc']         = 'ProdDesc';
 794          $this->flds['desc1']        = 'ProdDesc1';
 795          $this->flds['desc2']        = 'ProdDesc2';
 796          $this->flds['cost']         = 'ProdCost';
 797          $this->flds['price']        = 'ProdPrice';
 798          $this->flds['probability']  = 'ProdProb';
 799          $this->flds['state']        = 'ProdState';
 800          $this->flds['creator']      = 'ProdCreator';
 801          $this->flds['creation']     = 'ProdCreationS';
 802          $this->flds['p_start']      = 'ProdStart';
 803          $this->flds['p_end']        = 'ProdEnd';
 804          // Custom fields
 805          foreach(get_custom_overview_fields($this,'product') as $ti => $tx) {
 806              $this->flds['p_c_'.$ti]    = $tx['lang'];
 807              $tutos[prodfields][]  = 'p_c_'.$ti;
 808          }
 809  
 810          if ( $this->user->feature_ok(usebugtracking,PERM_SEE) && class_exists('bug') ) {
 811              $this->flds['pbugs']        = 'Bugs';
 812          }
 813          if ( $this->user->feature_ok(usedocmanagement,PERM_SEE) && class_exists('tutos_file') ) {
 814              $this->flds['pfile']        = 'Files';
 815          }
 816          if ( $this->user->feature_ok(usetaskmanagement,PERM_SEE) && class_exists('task') ) {
 817              $this->flds['ptask']        = 'Tasks';
 818          }
 819          $p = new product($this->dbconn);
 820          for ( $cl = 1;$cl <= $p->classes; $cl++) {
 821              $x = sprintf("cl%d",$cl);
 822              $this->flds['cl'.$cl]     = 'ProdClass'.$cl;
 823          }
 824          $this->flds['checkbox'] = '';
 825          $tutos[prodfields][]    = 'checkbox';
 826          foreach($tutos[prodfields] as $c) {
 827              $this->pshow[$c] = 0;
 828          }
 829  
 830          if (isset($_GET['ext'])) {
 831              $this->ext = $_GET['ext'];
 832              $this->link1 = addUrlParameter($this->link1,"ext=".$this->ext);
 833              $this->link3 = addUrlParameter($this->link3,"ext=".$this->ext);
 834          } else {
 835              $this->ext = 2;
 836          }
 837  
 838          /* Fields to show */
 839          $pscnt = 0;
 840          if ( isset($_GET['ps']) ) {
 841              // New Set Default
 842              foreach ($_GET['ps'] as $i1 => $f1) {
 843                  $this->pshow[$f1] = 1;
 844                  $pscnt++;
 845                  $this->link1 = addUrlParameter($this->link1,"ps[]=".$f1);
 846                  $this->link3 = addUrlParameter($this->link3,"ps[]=".$f1);
 847              }
 848              // remember this
 849              $_SESSION['prodshow'] = $this->pshow;
 850          } else if ( isset($_SESSION['prodshow']) ) {
 851              // Session Default
 852              foreach($_SESSION['prodshow'] as $i1 => $f1) {
 853                  if ( $f1 != 0 ) {
 854                      $this->pshow[$i1] = $f1;
 855                      $pscnt++;
 856                      $this->link1 = addUrlParameter($this->link1,"ps[]=".$i1);
 857                      $this->link3 = addUrlParameter($this->link3,"ps[]=".$i1);
 858                  }
 859              }
 860          }
 861          if ( $pscnt == 0 ) {
 862              // Default
 863              foreach ($tutos['proddefaultcolumns'] as $i => $f) {
 864                  $this->pshow[$f] = 1;
 865              }
 866          }
 867          if ( $tutos[massupdate] == 1 ) {
 868              $this->pshow['checkbox'] = 1;
 869          }
 870  
 871          prepare_product_overview($this);
 872  
 873          // custom selectors
 874          // get customized non textual search fields
 875          if ($this->ext != 0) {
 876              $custom = get_custom_sql_select($this,'product','',$this->link1);
 877              foreach ($custom[0] as $s) {
 878                  $this->q .= $this->qpre;
 879                  $this->q .= $s[0];
 880                  $this->qpre = " AND ";
 881                  $this->header .= $this->hpre.$s[1];
 882                  $this->hpre = '<br />';
 883              }
 884              foreach ($custom[1] as $s) {
 885                  $this->q = preg_replace('# where#i',','.$s.' WHERE',$this->q);
 886              }
 887          }
 888          //        $msg = addLine($msg,$this->q);
 889          check_dbacl($this->dbconn, $this->q, $this->user->id);
 890  
 891          // Order of output
 892          $this->link2 = $this->link1;
 893          $this->link2 = addUrlParameter($this->link2,"format=".UrlEncode($this->format));
 894          $xxx = "";
 895  
 896          order_parse($this->q,$this->link1,$xxx,$this,array('id',2));
 897  
 898          if ($this->stop) {
 899              return;
 900          }
 901  
 902          $this->nav         = $this->getSubSession();
 903          $this->nav['link'] = $this->link1;
 904          $this->plist       = array();
 905          if (!isset($this->nav['list'])) {
 906              foreach($tutos[currencies] as $c) {
 907                  $sum[1][$c] = 0;
 908                  $sum[2][$c] = 0;
 909              }
 910              $sum[1][''] = 0;
 911              $sum[2][''] = 0;
 912  
 913              $res = $this->dbconn->Exec($this->q);
 914              $np  = array();
 915              $x   = 0;
 916              $n   = $res->numrows();
 917              while ( $x < $n ) {
 918                  $p = new product($this->dbconn);
 919                  $p->read_result($res,$x);
 920                  $x++;
 921                  if ( ! $p->see_ok() ) {
 922                      continue;
 923                  }
 924                  $this->plist[] = &$p;
 925                  $this->nav['list'][] = $p->id;
 926  
 927                  if ( ($this->pshow['price'] == 1) || ($this->pshow['cost'] == 1) ) {
 928                      if (! isset ($sum[1][$p->currency])) {
 929                          $sum[1][$p->currency] = 0;
 930                          $sum[2][$p->currency] = 0;
 931                      }
 932                      $sum[1][$p->currency] += $p->price;
 933                      $sum[2][$p->currency] += $p->cost;
 934                  }
 935  
 936                  unset($p);
 937              }
 938              $this->nav['sum'] = $sum;
 939              $res->free();
 940          } else {
 941              // subsession found
 942              foreach ($this->nav['list'] as $i) {
 943                  $this->plist[] = $i;
 944              }
 945          }
 946          $this->ss = $this->putSubSession($this->nav);
 947  
 948          if ( 0 == count($this->plist)) {
 949              $this->redirect = "product_select.php?msg=". UrlEncode($lang['Err0048']);
 950              if ($this->ext != 0) {
 951                  $this->redirect = addUrlParameter($this->redirect,'ext=1',true);
 952              }
 953          }
 954  
 955          // menu
 956          $x = product::getSelectLink($this->user,$lang['Search']);
 957          $x[category][] = 'obj';
 958          $this->addMenu($x);
 959  
 960          $x = task::getSelectLink($this->user,$lang['TaskSearch']);
 961          $this->addMenu($x);
 962  
 963          if ( $this->user->feature_ok(useprojects,PERM_NEW) ) {
 964              $x = array( url => 'product_new.php',
 965                          text => $lang['NewEntry'],
 966                          info => $lang['ProdCreateInfo'],
 967                          category => array('product','new','obj',useprojects)
 968                  );
 969              $this->addMenu($x);
 970          }
 971          if ( $this->format != "stat" ) {
 972              $ll = addUrlParameter($this->link1,'format=stat');
 973              $ll = addUrlParameter($ll,'ss='.$this->ss);
 974              $x = array( url => $ll,
 975                          text => $lang['ProdStats'],
 976                          info => $lang['ProdStatsInfo'],
 977                          category => array('graph','product','view',useprojects)
 978                  );
 979              $this->addMenu($x);
 980          }
 981  
 982          if ( $this->format != "paper" ) {
 983              $ll = addUrlParameter($this->link1,'format=paper');
 984              $ll = addUrlParameter($ll,'ss='.$this->ss);
 985              $x = array( url => $ll,
 986                          text => $lang['Printable'],
 987                          info => $lang['PrintableInfo'],
 988                          category => array('print','product','view',useprojects)
 989                  );
 990              $this->addMenu($x);
 991          }
 992  
 993          if ( $this->format != "paper" ) {
 994              $ll = addUrlParameter($this->link1,'format=csv');
 995              $ll = addUrlParameter($ll,'ss='.$this->ss);
 996              $x = array( url => $ll,
 997                          text => $lang['Export'].' (CSV)',
 998                          info => $lang['ExportInfo'],
 999                          category => array('csv','product','view',useprojects)
1000                  );
1001              $this->addMenu($x);
1002          }
1003  
1004          $x = array( url => $this->link3,
1005                      text => $lang['SalesForecastRep'],
1006                      info => $lang['SalesForecastRep'],
1007                      category => array('product','view',useprojects)
1008              );
1009          $this->addMenu($x);
1010  
1011          if (class_exists('url')) {
1012              $this->addMenu(url::getAddLinkPreset($this->user,$this));
1013          }
1014  
1015      }
1016  }
1017  
1018  $l = new Product_overview($current_user);
1019  $l->display();
1020  $dbconn->Close();
1021  ?>

title

Description

title

Description

title

Description

title

title

Body