[ PHPXref.com ] [ Generated: Sun Jul 20 20:47:44 2008 ] [ TUTOS 1.2 ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/php/ -> product_overview.php (source)

   1  <?php
   2  /**
   3   * Copyright 1999 - 2004 by Gero Kohnert
   4   *
   5   *  CVS Info:  $Id: product_overview.php,v 1.102.2.6 2005/05/21 16:43:58 gokohnert Exp $
   6   *  $Author: gokohnert $
   7   *
   8   * @modulegroup product
   9   * @module product_overview
  10   * @package product
  11   */
  12   include_once  'webelements.p3';
  13   include_once  'permission.p3';
  14   include_once  'appointment.pinc';
  15   include_once  'timetrack.pinc';
  16   include_once  'product.pinc';
  17   include_once  'task.pinc';
  18  
  19   /* Check if user is allowed to use it */
  20   check_user();
  21   loadmodules('product','overview');
  22   loadlayout();
  23  
  24   /**
  25    * show a overview of projects
  26    */
  27   class product_overview extends layout {
  28     /**
  29      * display the info
  30      */
  31     Function info() {
  32       global $lang,$tutos;
  33  
  34       $plist = array();
  35       $n = $this->result->numrows();
  36  
  37       if ($this->format == "xml" ) { 
  38         $x = 0;
  39         $p = new product($this->dbconn);
  40         echo $p->exportXMLHeader();
  41         echo $p->exportXML_Head();
  42         echo "<product_set>\n";
  43         while ( $x < $n ) {
  44           $p->read_result($this->result,$x);
  45           $x++;
  46           if ( $p->see_ok() ) {
  47             echo $p->exportXML_start();
  48             echo $p->exportXML_body();
  49             echo $p->exportXML_end();
  50           }
  51         }
  52         echo "</product_set>\n";
  53         return;
  54       }
  55       
  56       if ($this->format == "stat" ) {
  57         $this->statinfo();
  58         $this->result->free();
  59         return;
  60       }
  61  
  62       $flds = 0;
  63       $pf = 0;
  64  
  65       foreach($tutos[currencies] as $c) {
  66         $sum[1][$c] = 0;
  67         $sum[2][$c] = 0;
  68       }
  69       $sum[1][""] = 0;
  70       $sum[2][""] = 0;
  71  
  72       # Make a big array of all visible products
  73       $x = 0;
  74       while ( $x < $n ) {
  75         $p = new product($this->dbconn);
  76         $p->read_result($this->result,$x);
  77         $x++;
  78         if ( ! $p->see_ok() ) {
  79           unset($p);
  80           continue;
  81         }
  82         if ( ($this->pshow['price'] == 1) || ($this->pshow['cost'] == 1) ) {
  83           $sum[1][$p->currency] += $p->price;
  84           $sum[2][$p->currency] += $p->cost;
  85         }
  86         $plist[] = &$p;
  87         unset($p);
  88       }
  89       $n = count($plist);
  90       if ( 0 == $n) {
  91         echo $this->error($lang['Err0048']);
  92         $this->result->free();
  93         return;
  94       }
  95       if ( $this->pshow['checkbox'] ) {
  96         echo $this->actionformStart("product_overview.php");
  97       }
  98       echo $this->OverviewTableStart();
  99       echo "<thead>\n";
 100       echo "<tr>\n";
 101  
 102       foreach ($tutos[prodfields] as $c) {
 103         if ( ($c == "name") && $this->pshow[$c] ) {
 104           echo $this->orderHeader("name",$lang['ProdName'],$this->link2);
 105           $flds++;
 106         }
 107         if ( ($c == "version") && $this->pshow[$c] ) {
 108           echo $this->orderHeader("version",$lang['ProdVersion'],$this->link2);
 109           $flds++;
 110         }
 111         if ( ($c == "seller") && $this->pshow[$c] ) {
 112           echo $this->orderHeader("",$lang['ProdRole'][4],$this->link2);
 113           $flds++;
 114         }
 115         if ( ($c == "manager") && $this->pshow[$c] ) {
 116           echo $this->orderHeader("",$lang['ProdRole'][1],$this->link2);
 117           $flds++;
 118         }
 119         if ( ($c == "customer") && $this->pshow[$c] ) {
 120           echo $this->orderHeader("",$lang['ProdRole'][6],$this->link2);
 121           $flds++;
 122         }
 123         if ( ($c == "supplier") && $this->pshow[$c] ) {
 124           echo $this->orderHeader("",$lang['ProdRole'][7],$this->link2);
 125           $flds++;
 126         }
 127         if ( ($c == "reseller") && $this->pshow[$c] ) {
 128           echo $this->orderHeader("",$lang['ProdRole'][8],$this->link2);
 129           $flds++;
 130         }
 131         if ( ($c == "partner") && $this->pshow[$c] ) {
 132           echo $this->orderHeader("",$lang['ProdRole'][9],$this->link2);
 133           $flds++;
 134         }
 135         if ( ($c == "desc") && $this->pshow[$c] ) {
 136           echo $this->orderHeader("description",$lang['ProdDesc'],$this->link2);
 137           $flds++;
 138         }
 139         if ( ($c == "desc1") && $this->pshow[$c] ) {
 140           echo $this->orderHeader("desc1",$lang['ProdDesc1'],$this->link2);
 141           $flds++;
 142         }
 143         if ( ($c == "desc2") && $this->pshow[$c] ) {
 144           echo $this->orderHeader("desc2",$lang['ProdDesc2'],$this->link2);
 145           $flds++;
 146         }
 147         if ( ($c == "cl1") && $this->pshow[$c] ) {
 148           echo $this->orderHeader("",$lang['ProdClass1'],$this->link2);
 149           $flds++;
 150         }
 151         if ( ($c == "cl2") && $this->pshow[$c] ) {
 152           echo $this->orderHeader("",$lang['ProdClass2'],$this->link2);
 153           $flds++;
 154         }
 155         if ( ($c == "state") && $this->pshow[$c] ) {
 156           echo$this-> orderHeader("state",$lang['ProdState'],$this->link2);
 157           $flds++;
 158         }
 159         if ( ($c == "probability") && $this->pshow[$c] ) {
 160           echo $this->orderHeader("probability",$lang['ProdProb'],$this->link2);
 161           $flds++;
 162         }
 163         if ( ($c == "price") && $this->pshow[$c] ) {
 164           echo $this->orderHeader("currency,price",$lang['ProdPrice'],$this->link2);
 165           $flds++;
 166           $pf = $flds;
 167         }
 168         if ( ($c == "cost") && $this->pshow[$c] ) {
 169           echo $this->orderHeader("currency,cost",$lang['ProdCost'],$this->link2);
 170           $flds++;
 171           $cf = $flds;
 172         }
 173         if ( ($c == "creator") && $this->pshow[$c] ) {
 174           echo $this->orderHeader("",$lang['ProdCreator'],$this->link2);
 175           $flds++;
 176         }
 177         if ( ($c == "creation") && $this->pshow[$c] ) {
 178           echo $this->orderHeader("creation",$lang['ProdCreationS'],$this->link2);
 179           $flds++;
 180         }
 181         if ( ($c == "p_start") && $this->pshow[$c] ) {
 182           echo $this->orderHeader("p_start",$lang['ProdStart'],$this->link2);
 183           $flds++;
 184         }
 185         if ( ($c == "p_end") && $this->pshow[$c] ) {
 186           echo $this->orderHeader("p_end",$lang['ProdEnd'],$this->link2);
 187           $flds++;
 188         }
 189         if ( $this->user->feature_ok(usebugtracking,PERM_SEE) ) {
 190           if ( ($c == "pbugs") && $this->pshow[$c] ) {
 191             echo $this->orderHeader("",$lang['Bugs'],$this->link2);
 192             $flds++;
 193           }
 194         }
 195         if ( ($c == "checkbox") && $this->pshow[$c] ) {
 196           # Column for checkboxes
 197           echo "<th>&nbsp;";
 198           echo " <input type=\"checkbox\" name=\"checkit\" onclick=\"CheckAll2();\" />\n";
 199           echo "&nbsp;</th>";
 200           $flds++;
 201         }
 202       }
 203       echo "</tr>\n";
 204       echo "</thead>\n";
 205  
 206       if ( $this->format == "paper" ) {
 207         $a = 0;
 208         $end = $n;
 209       } else if ( $this->start == -1 ) {
 210         $a = $n - $tutos[maxshow];
 211         $end = $n;
 212         $this->start = $a;
 213       } else {
 214         $a = $this->start;
 215         $end = $this->start + $tutos[maxshow];
 216       }
 217       $line = 0;
 218  
 219       $this->filter['name'] = prepare_regpattern($this->filter['name']);
 220  
 221       while ( ($a < $n) && ($a < $end) ) {
 222         $p = &$plist[$a];
 223         $p->readroles();
 224  
 225         echo $this->OverviewRowStart($line,$lang[$p->getType()] .": ". $p->getFullName());
 226         foreach ($tutos[prodfields] as $c) {
 227           if (! $this->pshow[$c]) {
 228             continue;
 229           }
 230           echo "  <td valign=\"top\" nowrap=\"nowrap\">&nbsp;";
 231  
 232           if ( $c == "name" ) {
 233             $b = myentities($p->name);
 234             if ( $this->filter['name'] != "" ) {
 235               $b = eregi_replace("(". $this->filter['name'] .")","<span class=\"found\">\\1</span>",$b);
 236             }
 237             echo makelink($p->getUrl(),$b);
 238           } else if ( $c == "version" ) {
 239             $b = myentities($p->version);
 240             if ( $this->filter['name'] != "" ) {
 241               $b = eregi_replace("(". $this->filter['name'] .")","<span class=\"found\">\\1</span>",$b);
 242             }
 243             echo $b;
 244           } else if ( $c == "seller" ) {
 245             # Show all seller roles
 246             if (isset($p->role[4]) && (count($p->role[4]) > 0) ) {
 247               @reset ($p->role[4]);
 248               $x = 0;
 249               while ( list ($i,$r) = @each ($p->role[4]) ) {
 250                 if ( $x > 0 ) {
 251                   echo "<br />\n &nbsp;";
 252                 }
 253                 echo  $r->getLink($r->getShortname());
 254                 $x++;
 255               }
 256             }
 257           } else if ( $c == "manager" ) {
 258             # Show all manager roles
 259             if (isset($p->role[1]) && (count($p->role[1]) > 0) ) {
 260               @reset ($p->role[1]) ;
 261               $x = 0;
 262               while ( list ($i,$r) = @each ($p->role[1]) ) {
 263                 if ( $x > 0 ) {
 264                   echo "<br />\n &nbsp;";
 265                 }
 266                 echo  $r->getLink($r->getShortname());
 267                 $x++;
 268               }
 269             }
 270             # Show all manager 3 roles
 271             if (isset($p->role[3]) && (count($p->role[3]) > 0) ) {
 272               @reset ($p->role[3]) ;
 273               while ( list ($i,$r) = @each ($p->role[3]) ) {
 274                 if ( $x > 0 ) {
 275                   echo "<br />\n &nbsp;";
 276                 }
 277                 echo  $r->getLink($r->getShortname());
 278                 $x++;
 279               }
 280             }
 281           } else if ( $c == "customer" ) {
 282             # Customer
 283             if (isset($p->role[6]) && (count($p->role[6]) > 0) ) {
 284               @reset ($p->role[6]) ;
 285               $x = 0;
 286               while ( list ($i,$r) = @each ($p->role[6]) ) {
 287                 if ( $x > 0 ) {
 288                   echo "<br />\n &nbsp;";
 289                 }
 290                 echo  $r->getLink();
 291                 $x++;
 292               }
 293             }
 294           } else if ( $c == "supplier" ) {
 295             # Supplier
 296             if (isset($p->role[7]) && (count($p->role[7]) > 0) ) {
 297               @reset ($p->role[7]) ;
 298               $x = 0;
 299               while ( list ($i,$r) = @each ($p->role[7]) ) {
 300                 if ( $x > 0 ) {
 301                   echo "<br />\n &nbsp;";
 302                 }
 303                 echo  $r->getLink();
 304                 $x++;
 305               }
 306             }
 307           } else if ( $c == "reseller") {
 308             # Reseller
 309             if (isset($p->role[8]) && (count($p->role[8]) > 0) ) {
 310               @reset ($p->role[8]) ;
 311               $x = 0;
 312               while ( list ($i,$r) = @each ($p->role[8]) ) {
 313                 if ( $x > 0 ) {
 314                   echo "<br />\n &nbsp;";
 315                 }
 316                 echo  $r->getLink();
 317                 $x++;
 318               }
 319             }
 320           } else if ( $c == "partner" ) {
 321             # Partner
 322             if (isset($p->role[9]) && (count($p->role[9]) > 0) ) {
 323               @reset ($p->role[9]) ;
 324               $x = 0;
 325               while ( list ($i,$r) = @each ($p->role[9]) ) {
 326                 if ( $x > 0 ) {
 327                   echo "<br />\n &nbsp;";
 328                 }
 329                 echo  $r->getLink();
 330                 $x++;
 331               }
 332             }
 333           } else if ( $c == "desc" ) {
 334             $b = myentities($p->description);
 335             if ( $this->filter['name'] != "" ) {
 336               $b = eregi_replace("(". $this->filter['name'] .")","<span class=\"found\">\\1</span>",$b);
 337             }
 338             echo $b;
 339           } else if ( $c == "desc1" ) {
 340             $b = myentities($p->desc1);
 341             if ( $this->filter['name'] != "" ) {
 342               $b = eregi_replace("(". $this->filter['name'] .")","<span class=\"found\">\\1</span>",$b);
 343             }
 344             echo $b;
 345           } else if ( $c == "desc2" ) {
 346             $b = myentities($p->desc2);
 347             if ( $this->filter['name'] != "" ) {
 348               $b = eregi_replace("(". $this->filter['name'] .")","<span class=\"found\">\\1</span>",$b);
 349             }
 350             echo $b;
 351           } else if ( $c == "state" ) {
 352             echo $lang['ProdStates'][$p->state];
 353           } else if ( $c == "probability" ) {
 354             echo "<div align=\"right\">". $p->probability ."%</div>";
 355           } else if ( $c == "price" ) {
 356             $b =  array($p->price,$p->currency);
 357             echo "<div align=\"right\">". handle('money',$b,number_format($p->price,2,$lang['DecPoint'],$lang['ThousandPoint']) ." ". myentities($p->currency)) ."</div>";
 358           } else if ( $c == "cost" ) {
 359             $b =  array($p->cost,$p->currency);
 360             echo "<div align=\"right\">". handle('money',$b,number_format($p->cost,2,$lang['DecPoint'],$lang['ThousandPoint']) ." ". myentities($p->currency)) ."</div>";
 361           } else if ( $c == "creator" ) {
 362             echo ($p->creator != -1 ? $p->creator->getLink($p->creator->getShortname()):$lang['HistoryDeleted']);
 363           } else if ( $c == "creation" ) {
 364             echo $p->creation->getLinkDate();
 365           } else if ( $c == "p_start" ) {
 366             echo $p->p_start->getLinkDate();
 367           } else if ( $c == "p_end" ) {
 368             echo $p->p_end->getLinkDate();
 369           } else if ( $c == "pbugs" ) {
 370             if ( $this->user->feature_ok(usebugtracking,PERM_SEE) ) {
 371               bug::obj_read($p);
 372               echo $p->bugSum();
 373             }
 374           } else if ( $c == "checkbox" ) {
 375             echo "<div align=\"center\">";
 376             # Column for checkboxes
 377             if ( $p->mod_ok() ) {
 378               echo "<input name=\"mark[]\" type=\"checkbox\" value=\"". $p->id ."\" />\n";
 379             } else {
 380               echo "-\n";
 381             }
 382             echo "</div>";
 383           }
 384  
 385           for ( $cl = 1;$cl <= $p->classes; $cl++) {
 386             if ( $c == "cl".$cl ) {
 387               $sep = "";
 388               @reset($p->cl[$cl]);
 389               while ( list ($i,$f) = @each ($p->cl[$cl]) ) {
 390                 if ( isset ($lang['ProdClasses'.$cl][$f]) ) {
 391                   echo $sep . $lang['ProdClasses'.$cl][$f] ;
 392                 } else {
 393                   echo $sep . $f ;
 394                 }
 395                 $sep = "<br />\n";
 396               }
 397             }
 398           }
 399  
 400           echo "</td>\n";
 401         }
 402         echo $this->OverviewRowEnd($line++);
 403         unset($plist[$a]);
 404         unset($p);
 405         $a++;
 406       }
 407  
 408       echo $this->list_navigation($this->link1,$flds,$this->start,$a,$n);
 409  
 410       # Sum of Prices
 411       if ( ($this->pshow['price'] == 1) || ($this->pshow['cost'] == 1) ) {
 412         echo "<tr>\n";
 413         $fill = 0;
 414         @reset($tutos[prodfields]);
 415         while( list ($i,$c) = @each ($tutos[prodfields])) {
 416           if (  $this->pshow[$c] == 0 ) {
 417             continue;
 418           }
 419           if ( $c == "price" ) {
 420             if ( $fill > 0 ) {
 421               echo " <td colspan=\"". $fill ."\">&nbsp;</td>\n";
 422               $fill = 0;
 423             }
 424             echo " <td align=\"right\">\n";
 425             @reset($sum[1]);
 426             $pre = "";
 427             while( list ($i1,$f1) = @each ($sum[1])) {
 428               if ( $f1 ) {
 429                 echo $pre . number_format($f1,2,$lang['DecPoint'],$lang['ThousandPoint']) ." ". $i1;
 430                 $pre = "<br />\n";
 431               }
 432             }
 433             echo " </td>\n";
 434           } else if ( $c == "cost" ) {
 435             if ( $fill > 0 ) {
 436               echo " <td colspan=\"". $fill ."\">&nbsp;</td>\n";
 437               $fill = 0;
 438             }
 439             echo " <td align=\"right\">\n";
 440             @reset($sum[2]);
 441             $pre = "";
 442             while( list ($i1,$f1) = @each ($sum[2])) {
 443               if ( $f1 ) {
 444                 echo $pre . number_format($f1,2,$lang['DecPoint'],$lang['ThousandPoint']) ." ". $i1;
 445                 $pre = "<br />\n";
 446               }
 447             }
 448             echo " </td>\n";
 449           } else {
 450             $fill++;
 451           }
 452         }
 453         if ( $fill > 0 ) {
 454           echo " <td colspan=\"". $fill ."\">&nbsp;</td>\n";
 455         }
 456         echo "</tr>\n";
 457       }
 458  
 459       if ( $this->pshow['checkbox'] ) {
 460         # Mass Update
 461         echo $this->UpdateRowStart($flds-1);
 462         echo sprintf($lang['withmarked'],$lang['ProductPs']);
 463         echo "&nbsp;<select name=\"action\">\n";
 464         echo " <option value=\"-1\" selected=\"selected\">". $lang['ActionNil'] ."</option>\n";
 465         echo " <option value=\"-2\">". $lang['Delete'] ."</option>\n";
 466         $ar = array (PROD_STATE_AQ,PROD_STATE_QRUN,PROD_STATE_QCANCEL,PROD_STATE_RUN,PROD_STATE_FINISH,PROD_STATE_CANCEL);
 467         while ( list ($f,$i) = @each ($ar) ) {
 468           echo " <option value=\"S". $i ."\">". sprintf($lang['SetTo'],$lang['ProdState'],$lang['ProdStates'][$i]) ."</option>\n";
 469         }
 470         echo " <option value=\"-4\">". $lang['AclModify'] ."</option>\n";
 471         if (class_exists('watchlist')) {
 472           echo " <option value=\"WatchAdd\">". $lang['WatchAdd'] ."</option>\n";
 473           echo " <option value=\"WatchDel\">". $lang['WatchDel'] ."</option>\n";
 474         }
 475         echo "</select>\n";
 476         echo $this->UpdateRowEnd(1);
 477       }
 478  
 479       echo $this->OverviewTableEnd();
 480       if ( $this->pshow['checkbox'] ) {
 481         echo $this->actionformEnd("product_overview.php");
 482       }
 483   }
 484  
 485   /* ---------------------------------------------------------------------------
 486    *
 487    */
 488   Function statinfo() {
 489     global $lang,$tutos;
 490  
 491     $a = 0;
 492     $n = $this->result->numrows();
 493     $cnt = 0;
 494     while ( $a < $n ) {
 495       $p = new product($this->dbconn);
 496       $p->read_result($this->result,$a);
 497       $p->readroles();
 498       $a++;
 499       if ( ! $p->see_ok() ) {
 500         continue;
 501       }
 502       $cnt++;
 503  
 504       # Manager
 505       if (isset($p->role[1]) && (count($p->role[1]) > 0) ) {
 506         @reset ($p->role[1]) ;
 507         $x = 0;
 508         while ( list ($i,$r) = @each ($p->role[1]) ) {
 509           if ( !isset($manager[$r->id]) ) {
 510             $manager[$r->id] = 0;
 511           }
 512           $manager[$r->id]++;
 513         }
 514       }
 515       if (isset($p->role[3]) && (count($p->role[3]) > 0) ) {
 516         @reset ($p->role[3]) ;
 517         $x = 0;
 518         while ( list ($i,$r) = @each ($p->role[3]) ) {
 519           if ( !isset($manager[$r->id]) ) {
 520             $manager[$r->id] = 0;
 521           }
 522           $manager[$r->id]++;
 523         }
 524       }
 525  
 526       # States
 527       if ( !isset($states[$p->state]) ) {
 528         $states[$p->state] = 0;
 529       }
 530       $states[$p->state]++;
 531  
 532       # Classifications
 533       for ( $c = 1;$c <= 2; $c++) {
 534         @reset($p->cl[$c]);
 535         while ( list ($i,$f) = @each ($p->cl[$c]) ) {
 536           if ( !isset($cl[$c][$i]) ) {
 537             $cl[$c][$i] = 0;
 538           }
 539           $cl[$c][$i]++;
 540         }
 541       }
 542       unset($p);
 543     }
 544  
 545     echo $this->DataTableStart();
 546     echo "<tr>\n";
 547     echo " <th colspan=\"6\">". $lang['ProdStatsTitle'] ."</th>\n";
 548     echo "</tr>\n";
 549  
 550     echo "<tr>\n";
 551     echo $this->showfield($lang['Count']);
 552     echo "<td colspan=\"5\">". $cnt ."\n";
 553     $pre = "filtered by ";
 554     while ( list ($i,$f) = @each ($this->filter) ) {
 555       if ( $f == "" ) {
 556         continue;
 557       }
 558       if ( $i == 'state' ) {
 559         $f = $f + 0;
 560         echo $pre . $lang['ProdState'];
 561         echo " ". $lang['ProdStates'][$f];
 562       } else if ( $i == 'cl1' ) {
 563         echo $pre . $lang['ProdClass1'];
 564         echo " ". $lang['ProdClasses1'][$f];
 565       } else if ( $i == 'cl2' ) {
 566         echo $pre . $lang['ProdClass2'];
 567         echo " ". $lang['ProdClasses2'][$f];
 568       } else if ( $i == 'name' ) {
 569         echo $pre . $lang['ProdDesc'];
 570         echo " ". $f;
 571       } else if ( $i == 'from' ) {
 572         echo $pre . $lang['DateTimeFrom'];
 573         echo " ". $f->getDateTime();
 574       } else if ( $i == 'to' ) {
 575         echo $pre . $lang['DateTimeTill'];
 576         echo " ". $f->getDateTime();
 577       } else {
 578         echo $pre . $i;
 579         echo " ". $f;
 580       }
 581       $pre = " and ";
 582     }
 583     echo " </td>\n";
 584     echo "</tr>\n";
 585  
 586     # State distribution
 587     echo "<tr>\n";
 588     $link = "graph_bars.php";
 589     $link = addSessionKey($link);
 590     $link = addUrlParameter($link,"type=pie");
 591     @reset($states);
 592     if ( !function_exists('ImageCreate') ) {
 593       echo " <td valign=\"top\" rowspan=\"". count($states) ."\"><b>". $lang['ProdState'] ."</b></td>";
 594     } else {
 595       echo $this->showfield($lang['ProdState']);
 596     }
 597     $c = 0;
 598     while ( list ($i,$f) = @each ($states) ) {
 599       $val = number_format($f * 100.0 / $cnt ,2);
 600       if ( !function_exists('ImageCreate') ) {
 601         echo " <td>". $lang['ProdStates'][$i] ."</td>\n";
 602         echo " <td align=\"right\">". $f ."</td>\n";
 603         echo " <td align=\"right\">". $val ."%</td>\n";
 604       }
 605       $link = addUrlParameter($link,"f[". $c ."]=".$val);
 606       $link = addUrlParameter($link,"t0[". $c ."]=". UrlEncode($lang['ProdStates'][$i]));
 607       $link = addUrlParameter($link,"t1[". $c ."]=".$f);
 608       $c++;
 609     }
 610     if ( function_exists('ImageCreate') ) {
 611       echo " <td colspan=\"5\" valign=\"top\"><img src=\"". $link ."\" alt=\"". $lang['ProdState'] ."\" /></td>\n";
 612     }
 613     echo "</tr>\n";
 614  
 615     # Classifications
 616     for ( $c = 1;$c <= 2; $c++) {
 617       echo "<tr>\n";
 618       $link = "graph_bars.php";
 619       $link = addSessionKey($link);
 620       $link = addUrlParameter($link,"type=pie");
 621       @reset($cl[$c]);
 622       if ( !function_exists('ImageCreate') ) {
 623         echo " <td valign=\"top\" rowspan=\"". count($cl[$c]) ."\"><b>". $lang['ProdClass'.$c] ."</b></td>";
 624       } else {
 625           echo $this->showfield($lang['ProdClass'.$c]);
 626      }
 627         $x = 0;
 628         while ( list ($i,$f) = @each ($cl[$c]) ) {
 629           $val = number_format($f * 100.0 / $cnt ,2);
 630           if ( !function_exists('ImageCreate') ) {
 631             if ( isset($lang['ProdClasses'.$c][$i]) ) {
 632               echo " <td>". $lang['ProdClasses'.$c][$i] ."</td>\n";
 633             } else {
 634               echo " <td>". $i ."</td>\n";
 635             }
 636             echo " <td align=\"right\">". $f ."</td>\n";
 637             echo " <td align=\"right\">". $val ."%</td>\n";
 638           }
 639           $link = addUrlParameter($link,"f[". $x ."]=".$val);
 640           if ( isset($lang['ProdClasses'.$c][$i]) ) {
 641             $link = addUrlParameter($link,"t0[". $x ."]=". UrlEncode($lang['ProdClasses'.$c][$i]));
 642           } else {
 643             $link = addUrlParameter($link,"t0[". $x ."]=". $i);
 644           }
 645           $link = addUrlParameter($link,"t1[". $x ."]=". $f );
 646           $x++;
 647         }
 648       if ( function_exists('ImageCreate') ) {
 649         echo " <td colspan=\"5\" valign=\"top\"><img src=\"". $link ."\" alt=\"". $lang['ProdClass'.$c] ."\" /></td>\n";
 650       }
 651         echo "</tr>\n";
 652       }
 653  
 654       # Manager distribution
 655       echo "<tr>\n";
 656       $link = "graph_bars.php";
 657       $link = addSessionKey($link);
 658       $link = addUrlParameter($link,"type=pie");
 659       @reset($manager);
 660       if ( !function_exists('ImageCreate') ) {
 661         echo " <td valign=\"top\" rowspan=". count($manager) ."><b>". $lang['ProdRole'][1] ."</b></td>";
 662       } else {
 663         echo $this->showfield($lang['ProdRole'][1]);
 664       }
 665       $c = 0;
 666       while ( list ($i,$f) = @each ($manager) ) {
 667         $m = new tutos_address($this->dbconn);
 668         $m = $m->read($i,$m);
 669         if ( $m->id == -1 ) {
 670           $m = new team($this->dbconn);
 671           $m = $m->read($i,$m);
 672         }
 673         $val = number_format($f * 100.0 / $cnt ,2);
 674         if ( !function_exists('ImageCreate') ) {
 675           echo " <td>". $m->getLink() ."</td>\n";
 676           echo " <td align=\"right\">". $f ."</td>\n";
 677           echo " <td align=\"right\">". $val ."%</td>\n";
 678         }
 679         $link = addUrlParameter($link,"f[". $c ."]=". $val);
 680         $link = addUrlParameter($link,"t0[". $c ."]=". UrlEncode($m->getShortName()));
 681         $link = addUrlParameter($link,"t1[". $c ."]=". $f);
 682         $c++;
 683       }
 684       if ( function_exists('ImageCreate') ) {
 685         echo " <td colspan=\"5\" valign=\"top\"><img src=\"". $link ."\" alt=\"". $lang['ProdRole'][1] ."\" /></td>\n";
 686       }
 687       echo "</tr>\n";
 688  
 689       echo $this->DataTableEnd();
 690     }
 691     /**
 692      * navigate
 693      */
 694     Function navigate() {
 695       global $lang,$tutos;
 696  
 697    
 698       if ( $this->format != "stat" ) {
 699         foreach ($this->pshow as $i => $f) {
 700           if ( $f == 0 ) {
 701             $schecked[$i] = "";
 702           } else {
 703             $schecked[$i] = " checked=\"checked\"";
 704           }
 705         }
 706         echo "<tr><td>";
 707         echo "<form name=\"ProdFields\" action=\"product_overview.php\" method=\"get\">";
 708         echo "<script type=\"text/javascript\" language=\"JavaScript\">\n";
 709         echo "<!--\n";
 710         echo "function CheckAll() {\n";
 711         echo "  for (var i=0; i < document.forms['ProdFields'].elements.length; i++) {\n";
 712         echo "   var e = document.forms['ProdFields'].elements[i];\n";
 713         echo "   if (e.name != 'checkit')\n";
 714         echo "     e.checked = document.forms['ProdFields'].checkit.checked;\n";
 715         echo "  }\n";
 716         echo "}\n";
 717         echo "//-->\n";
 718         echo "</script>\n";
 719         DoubleTableStart(0,0);
 720         echo "<tr><th>". $lang['ProdFields'] ."</th></tr>\n";
 721         foreach ($tutos[prodfields] as $i => $c) {
 722           if ( ! isset($this->flds[$c]) ) {
 723             continue;
 724           }
 725           if ( $this->flds[$c] == '' ) {
 726             continue;
 727           }
 728           echo "<tr><td nowrap=\"nowrap\">\n";
 729           echo " <input type=\"checkbox\" name=\"ps[]\"". $schecked[$c] ." value=\"". $c ."\" />&nbsp;". $lang[$this->flds[$c]] ."\n";
 730           echo "</td></tr>\n";
 731         }
 732  
 733         echo "<tr><td nowrap=\"nowrap\"><hr noshade=\"noshade\" /></td></tr>\n";
 734         echo "<tr><td nowrap=\"nowrap\">\n";
 735         echo " <input type=\"checkbox\" name=\"checkit\" onclick=\"CheckAll();\" />&nbsp;". $lang['all'] ."\n";
 736         echo "</td></tr>\n";
 737  
 738         echo "<tr><td><input type=\"submit\" value=\"". $lang['show'] ."\" /></td></tr>\n";
 739         DoubleTableEnd();
 740         hiddenFormElements();
 741         echo $this->getHidden();
 742         echo "</form>\n";
 743         echo "</td></tr>";
 744       }
 745     }
 746     /**
 747      * action
 748      */
 749     Function action() {
 750       global $msg,$lang;
 751  
 752       if ( $_GET['action'] == -2 ) {
 753         $this->dbconn->Begin("WORK");
 754         foreach ($_GET['mark'] as $key => $val) {
 755           $p = new product($this->dbconn);
 756           $p = $p->read($val,$p);
 757           if ( $p->id != $val ) {
 758             continue;
 759           }
 760           $p->readroles();
 761           if ( $p->del_ok() ) {
 762             $msg .= sprintf($lang['ProdDelInfo'], $p->getFullName()) ."<br />";
 763             $msg .= $p->delete();
 764           } else {
 765             $msg .= $p->getLink() .": ". sprintf($lang['Err0023'],$lang[$p->getType()]);
 766           }
 767           unset($p);
 768         }
 769         $this->dbconn->Commit("WORK");
 770         return;
 771       }
 772       if ( ereg("^(S)(.*)",$_GET['action'],$a) ) {
 773         $this->dbconn->Begin("WORK");
 774         foreach ($_GET['mark'] as $key => $val) {
 775           $p = new product($this->dbconn);
 776           $p = $p->read($val,$p);
 777           $p->readroles();
 778           if ( $p->id != $val ) {
 779             continue;
 780           }
 781           if ( $p->mod_ok() ) {
 782             $msg .= $p->getLink() ." ". $lang['ProdState'] ." = ". $lang['ProdStates'][$a[2]] ."<br />";
 783             $msg .= $p->setState($a[2]);
 784             $msg .= $p->save();
 785           } else {
 786             $msg .= $p->getLink() .": ". sprintf($lang['Err0024'],$lang[$p->getType()]);
 787           }
 788           unset ($p);
 789         }
 790         $this->dbconn->Commit("WORK");
 791         return;
 792       }
 793  
 794       if ( $_GET['action'] == -4 ) {
 795         $this->redirect = acl_action();
 796         return;
 797       } 
 798  
 799       if (class_exists('watchlist')) {
 800         watchlist::parse_action($this->user);
 801       }
 802  
 803     }
 804     /**
 805      * prepare
 806      */
 807     Function prepare() {
 808       global $msg,$lang,$tutos;
 809  
 810       $this->name = $lang['ProductsOverview'];
 811  
 812       if ( ! $this->user->feature_ok(useprojects,PERM_SEE) ) {
 813         $msg .= sprintf($lang['Err0022'],"'". $this->name ."'");
 814         $this->stop = true;
 815       }
 816  
 817       $this->link1 = "product_overview.php";
 818       $this->flds = array();
 819       $this->filter = array();
 820  
 821       $this->flds['name']         = 'ProdName';
 822       $this->flds['version']      = 'ProdVersion';
 823       $this->flds['seller']       = 'ProdRole4';
 824       $this->flds['manager']      = 'ProdRole1';
 825       $this->flds['customer']     = 'ProdRole6';
 826       $this->flds['supplier']     = 'ProdRole7';
 827       $this->flds['reseller']     = 'ProdRole8';
 828       $this->flds['partner']      = 'ProdRole9';
 829       $this->flds['desc']         = 'ProdDesc';
 830       $this->flds['desc1']        = 'ProdDesc1';
 831       $this->flds['desc2']        = 'ProdDesc2';
 832       $this->flds['cost']         = 'ProdCost';
 833       $this->flds['price']        = 'ProdPrice';
 834       $this->flds['probability']  = 'ProdProb';
 835       $this->flds['state']        = 'ProdState';
 836       $this->flds['creator']      = 'ProdCreator';
 837       $this->flds['creation']     = 'ProdCreationS';
 838       $this->flds['p_start']      = 'ProdStart';
 839       $this->flds['p_end']        = 'ProdEnd';
 840       if ( $this->user->feature_ok(usebugtracking,PERM_SEE) && class_exists('bug') ) {
 841         $this->flds['pbugs']        = 'Bugs';
 842       }
 843       $p = new product($this->dbconn);
 844       for ( $cl = 1;$cl <= $p->classes; $cl++) {
 845         $x = sprintf("cl%d",$cl);
 846         $this->flds['cl'.$cl]     = 'ProdClass'.$cl;
 847       }
 848       $this->flds['checkbox']     = '';
 849       $tutos[prodfields][]  = 'checkbox';
 850       foreach($tutos[prodfields] as $c) {
 851         $this->pshow[$c] = 0;
 852       }
 853       if ( isset($_GET['name']) ) {
 854         $name = $_GET['name'];
 855       } else {
 856         $name = "";
 857       }
 858       if ( isset($_GET['state']) ) {
 859         if (false == is_numeric($_GET['state'])) {
 860           $msg .= sprintf($lang['Err0012'],"state",$_GET['state']);
 861           $this->stop = true;
 862         }
 863         $state = $_GET['state'];
 864         # remember this
 865  #       session_register('prodsearchstate');
 866         $_SESSION['prodsearchstate'] = $state;
 867       } else {
 868         $state = "";
 869       }
 870       if ( isset($_GET['role']) ) {
 871         $role = $_GET['role'];
 872       } else {
 873         $role = "";
 874       }
 875       $rid = array();
 876       if ( isset($_GET['rid']) ) {
 877         $rid = $_GET['rid'];
 878       }
 879       /* Fields to show */
 880       $pscnt = 0;
 881       if ( isset($_GET['ps']) ) {
 882         # New Set Default
 883         @reset($_GET['ps']);
 884         while ( list ($i1,$f1) = @each ($_GET['ps']) ) {
 885           $this->pshow[$f1] = 1;
 886           $pscnt++;
 887           $this->link1 = addUrlParameter($this->link1,"ps[]=".$f1);
 888         }
 889         # remember this
 890  #       session_register('prodshow');
 891         $_SESSION['prodshow'] = $this->pshow;
 892       } else if ( isset($_SESSION['prodshow']) ) {
 893         # Session Default
 894         foreach($_SESSION['prodshow'] as $i1 => $f1) {
 895           if ( $f1 != 0 ) {
 896             $this->pshow[$i1] = $f1;
 897             $pscnt++;
 898             $this->link1 = addUrlParameter($this->link1,"ps[]=".$i1);
 899           }
 900         }
 901       }
 902       if ( $pscnt == 0 ) {
 903         # Default
 904        $this->pshow['name'] = 1;
 905        $this->pshow['version'] = 1;
 906        $this->pshow['manager'] = 1;
 907        $this->pshow['state'] = 1;
 908       }
 909       if ( $tutos[massupdate] == 1 ) {
 910         $this->pshow['checkbox'] = 1;
 911       }
 912  
 913       $this->q = "SELECT * FROM ". $p->tablename;
 914       $pre = " WHERE ";
 915       if ( ($name != "*") && ($name != "") ) {
 916         $name = StripSlashes($name);
 917         $this->q .= $pre ."(".  $this->dbconn->Like("name",$name);
 918         $this->q .= " OR ". $this->dbconn->Like("description",$name);
 919         $this->q .= " OR ". $this->dbconn->Like("desc1",$name);
 920         $this->q .= " OR ". $this->dbconn->Like("desc2",$name);
 921         $this->q .= " OR ". $this->dbconn->Like("version",$name);
 922         $this->q .= ")";
 923         $pre = " AND ";
 924         $this->link1 = addUrlParameter($this->link1,"name=".UrlEncode($name));
 925         $this->addHidden("name",$name);
 926         $this->filter['name'] = $name;
 927       } else {
 928         $this->filter['name'] = "";
 929       }
 930       # Start Date for search
 931       $from = new DateTime(0);
 932       if ( isset($_GET['fd']) ) {
 933         $from->setDateTime($_GET['fd']);
 934       } else {
 935         $from->setDateTimeF("f");
 936         # remember this
 937  #       session_register('prodsearchfrom');
 938         $_SESSION['prodsearchfrom'] = $from->getYYYYMMDD();
 939       }
 940       if ( $from->notime != 1 ) {
 941         $this->q .= $pre ."(creation >= ". $this->dbconn->Date($from) .")";
 942         $pre = " AND ";
 943         $this->link1 = addUrlParameter($this->link1,"fd=".$from->getYYYYMMDD());
 944         $this->addHidden("fd",$from->getYYYYMMDD());
 945         $this->filter['from'] = $from;
 946       }
 947       # End Date for search
 948       $to = new DateTime(0);
 949       if ( isset($_GET['td']) ) {
 950         $to->setDateTime($_GET['td']);
 951       } else {
 952         $to->setDateTimeF("t");
 953         # remember this
 954  #       session_register('prodsearchto');
 955         $_SESSION['prodsearchto'] = $to->getYYYYMMDD();
 956       }
 957       if ( $to->notime != 1 ) {
 958         $this->q .= $pre ."(creation <= ". $this->dbconn->Date($to) .")";
 959         $pre = " AND ";
 960         $this->link1 = addUrlParameter($this->link1,"td=".$to->getYYYYMMDD());
 961         $this->addHidden("td",$to->getYYYYMMDD());
 962         $this->filter['to'] = $to;
 963       }
 964       #
 965       # State to display
 966       #
 967       if ( ($state != -1) && ($state != "") ) {
 968         if ( $state < 0 ) {
 969           $this->q .= $pre . " ( state != 2 AND state != 3 and state != 5 ) " ;
 970         } else {
 971           $this->q .= $pre . " state = " . $state ;
 972         }
 973         $pre = " AND ";
 974         $this->link1 = addUrlParameter($this->link1,"state=".$state);
 975         $this->addHidden("state",$state);
 976         $this->filter['state'] = $state;
 977       }
 978       #
 979       # Classifications to display
 980       #
 981       for ( $cl = 1;$cl <= $p->classes; $cl++) {
 982         $x = sprintf("cl%d",$cl);
 983         if ( isset($_GET[$x]) && ($_GET[$x] != -1) ) {
 984           if (false == is_numeric($_GET[$x])) {
 985             $msg .= sprintf($lang['Err0012'],$x,$_GET[$x]);
 986             $this->stop = true;
 987             return;
 988           }
 989           # Get all project with classification
 990           $q1 =  "SELECT * from ". $this->dbconn->prefix ."projectclass". $cl ." WHERE class_id = ". $_GET[$x];
 991           $r = $this->dbconn->Exec($q1);
 992           $n = $r->numrows();
 993           $a = 0;
 994           $pre1 = "";
 995           $z = "";
 996           while ($a < $n) {
 997             $z .= $pre1 . $r->get($a, "pro_id");
 998             $pre1 = ",";
 999             $a++;
1000           }
1001           $r->free();
1002           if ( $z != "" ) {
1003             $this->q .= $pre ." id in (". $z .")";
1004             $pre = " AND ";
1005           }
1006  
1007           $this->link1 = addUrlParameter($this->link1,"cl". $cl ."=".$_GET[$x]);
1008           $this->addHidden("cl". $cl, $_GET[$x]);
1009           $this->filter['cl'.$cl] = $_GET[$x];
1010         }
1011         if ( isset($_GET[$x]) ) {
1012           $y = sprintf("prodsearchcl%d",$cl);
1013           # remember this
1014  #         session_register($y);
1015           $_SESSION[$y] = $_GET[$x];
1016         }
1017       }
1018       # Role Specific Selection
1019       if ( count($rid) > 0 ) {
1020         # Get all managed product ids
1021         @reset ($rid);
1022         $ml = "";
1023         $mpre = "";
1024         foreach( $rid as $f1) {
1025           $ml .= $mpre . $f1;
1026           $mpre = ",";
1027           $this->link1 = addUrlParameter($this->link1,"rid[]=".$f1);
1028           $this->addHidden("rid[]",$f1);
1029           if ( count($rid) == 1 ) {
1030             $x = getObject($this->dbconn,$f1);
1031             if ($x != -1) {
1032               $this->name .= " (".$x->getFullName() .")";
1033             }
1034           }
1035         }
1036         if ( isset($role) ) {
1037           $q1 = "SELECT pro_id FROM ". $this->dbconn->prefix ."projectroles WHERE role_id in (". $role .") AND adr_id in (". $ml .")";
1038           $this->link1 = addUrlParameter($this->link1,"role=".$role);
1039           $this->addHidden("role",$role);
1040         } else {
1041           $q1 = "SELECT pro_id FROM ". $this->dbconn->prefix ."projectroles WHERE adr_id in (". $ml .")";
1042         }
1043         $r = $this->dbconn->Exec($q1);
1044         $n = $r->numrows();
1045         $a = 0;
1046         $pre1 = "";
1047         $x = "";
1048         while ($a < $n) {
1049           $x .= $pre1 . $r->get($a, "pro_id");
1050           $pre1 = ",";
1051          $a++;
1052         }
1053         $r->free();
1054         if ( $x != "" ) {
1055           $this->q .= $pre ." id in (". $x .")";
1056         }
1057         $pre = " AND ";
1058       }
1059  
1060       check_dbacl( $this->q, $this->user->id);
1061  
1062       # Order of output
1063       $this->link2 = $this->link1;
1064       $this->link2 = addUrlParameter($this->link2,"format=".UrlEncode($this->format));
1065       $xxx = "";
1066       order_parse($this->q,$this->link1,$xxx,$xxx,"creation DESC");
1067       # display default sortorder
1068       if (!isset($_GET['xf'])) {
1069         $_GET['xf'] = "creation";
1070         $_GET['xo'] = 2;
1071       }
1072  
1073       if ($this->stop) {
1074         return;
1075       }
1076       $this->result = $this->dbconn->Exec($this->q);
1077       if ( 0 == $this->result->numrows()) {
1078         $this->redirect = "product_select.php?msg=". UrlEncode($lang['Err0048']);
1079         $this->result->free();
1080       }
1081  
1082       # menu
1083       $x = product::getSelectLink($this->user,$lang['Search']);
1084       $x[category][] = "obj";
1085       $this->addMenu($x);
1086  
1087       if ( $this->user->feature_ok(useprojects,PERM_NEW) ) {
1088         $x = array( url => "product_new.php",
1089                     text => $lang['NewEntry'],
1090                     info => $lang['ProdCreateInfo'],
1091                     category => array("product","new","obj")
1092                   );
1093         $this->addMenu($x);
1094       }
1095       if ( $this->format != "stat" ) {
1096         $ll = addUrlParameter($this->link1,"format=stat");
1097         $x = array( url => $ll,
1098                     text => $lang['ProdStats'],
1099                     info => $lang['ProdStatsInfo'],
1100                     category => array("product","view")
1101                   );
1102         $this->addMenu($x);
1103       }
1104  
1105       if ( $this->format != "paper" ) {
1106         $ll = addUrlParameter($this->link1,"format=paper");
1107         $x = array( url => $ll,
1108                     text => $lang['Printable'],
1109                     info => $lang['PrintableInfo'],
1110                     category => array("product","view")
1111                   );
1112         $this->addMenu($x);
1113       }
1114  
1115       $x = array( url => "sales_forecast.php",
1116                   text => $lang['SalesForecastRep'],
1117                   info => $lang['SalesForecastRep'],
1118                   category => array("product","view")
1119                 );
1120       $this->addMenu($x);
1121       
1122       web_StackStartLayout($this,"product_overview.php","product_overview.php");
1123  
1124     }
1125   }
1126  
1127   $l = new product_overview($current_user);
1128   $l->display();
1129   $dbconn->Close();
1130  ?>


[ Powered by PHPXref - Served by Debian GNU/Linux ]