Keystone PHP Cross Reference Customer Relationship Management

Source: /sliputils.php - 540 lines - 17518 bytes - Summary - Text - Print

   1  <?
   2      #---------------------------------------------------------------------#
   3      # This source code is (c)2003 Stonekeep Consulting, Inc               #
   4      # see http://www.stonekeep.com/license.html for licensing information #
   5      #---------------------------------------------------------------------#
   6  
   7      #----------------------------------------------------------------------
   8      # $Id: sliputils.php 224 2006-05-22 17:41:41Z twp $
   9      #----------------------------------------------------------------------
  10      
  11  
  12      Function GenWhere() {
  13          Global $state, $sys_justparents, $prefs;
  14  
  15          #
  16          # This function generates the necessary 'where' clause when viewing
  17          # slips.  It takes into acounts system settings and user preferences.
  18          #
  19  
  20          #if ($sys_justparents) {
  21          #    $wclause = "where spid=0";
  22          #}
  23  
  24          if (sizeof($prefs)) {
  25              while (list($vname,$value) = each($prefs)) {
  26                  if ((substr($vname,0,6) == 'opt_v_') && ($value)) {
  27                      $cname = ereg_replace("opt_v_","","$vname");
  28                      $c = $prefs["opt_r_$cname"];
  29                      $v = $prefs["opt_v_$cname"];
  30                      if ("$c" && "$v") {
  31                          $wstring = ("$wclause") ? "and " : "where ";
  32                          if (($prefs["opt_t_$cname"] == 'C') && (substr($v,0,1) != '(')) {
  33                              $wclause = "$wclause $wstring $cname $c '$v'";
  34                          } else {
  35                              $wclause = "$wclause $wstring $cname $c $v";
  36                          }
  37                      }
  38                  }
  39              }
  40          }
  41          return $wclause;
  42      }
  43  
  44      #----------------------------------------------------------------------
  45      class ColumnHeader
  46      {
  47          # Collect the data necessary to build a column header for a 
  48          # slip view.
  49  
  50          var $hsql    =    '';
  51          var $numcolumns = 0;
  52          var $numslips = 0;
  53          var $cscol    =     array();
  54          var $csflag    =    array();
  55          var $cswidth = array();
  56  
  57  		function ColumnHeader () {
  58              Global $curruser,$sys_logfile ;
  59              $hsql = 'SELECT '.
  60                                  'p_column,p_active,p_flags,dcolumn,dheading,p_order,p_subtable '.
  61                                  'FROM '.
  62                                  'propdisp,dictionary '.
  63                                  'WHERE '.
  64                                  '(dtable=p_dataset or dtable=p_subtable) '.
  65                                  'AND p_column=dcolumn '.
  66                                  'AND p_uid="' . $curruser . '" '.
  67                                  'AND p_active=1 '.
  68                                  'ORDER BY p_order';
  69              LogIt('DEBUG','ColumnHeader',$hsql);
  70              $hq = db_query($hsql);
  71              if (db_numrows($hq)) {
  72                  LogIt('DEBUG','ColumnHeader','Found settings in properties, loading.');
  73                  while ($hinfo = db_fetch_array($hq)) {
  74                      //LogIt('DEBUG','ColumnHeader','Setting ' . $hinfo[p_column]);
  75                      $this->cscol[]         = $hinfo[p_column];
  76                      $this->csflags[]    = $hinfo[p_flags];
  77                      $this->cslabel[]    =    $hinfo[dheading];
  78                      switch($hinfo[p_column]) {
  79                          case 'problem' : { $w = '25%'; break;; }
  80                          case 'priority' : { $w = '5%'; break;; }
  81                          case 'status' : { $w = '5%'; break;; }
  82                          case 'sid' : { $w = '5%'; break;; }
  83                          case 'spid' : { $w = '5%'; break;; }
  84                          default : { $w = '10%'; break;; }
  85                      }
  86                      $this->cswidth[]    =    $w;
  87                  }
  88              } else {
  89                  LogIt('DEBUG','ColumnHeader','Using defauls');
  90                  $this->setDefaults();
  91              }
  92          }
  93  
  94  		function setDefaults () {
  95              # this is the default display.
  96              $this->cscol[1]    =    'problem';        $this->cslabel[1]    =    'Problem';
  97              $this->cscol[2]    =    'ctag';            $this->cslabel[2]    =    'Contact';
  98              $this->cscol[3]    =    'o_date';        $this->cslabel[3]    =    'OpenDate';    
  99              $this->cscol[4]    =    'o_tech';        $this->cslabel[4]    =    'OpenTech';
 100              $this->cscol[5]    =    'c_date';        $this->cslabel[5]    =    'CloseDate';
 101              $this->cscol[6]    =    'c_tech';        $this->cslabel[6]    =    'Closetech';
 102              $this->cscol[7]    =    'status';        $this->cslabel[7]    =    'Status';
 103  
 104              $this->csflags[3]='D';
 105              $this->csflags[5]='D';
 106          }
 107  
 108  		function getColumn($whichcol) {
 109              return $this->cscol[$whichcol] ;
 110          }
 111  
 112  		function getFlags($whichcol) {
 113              return $this->csflags[$whichcol] ;
 114          }
 115  
 116  		function getLabel($whichcol) {
 117              return $this->cslabel[$whichcol] ;
 118          }
 119  
 120  		function getCount() {
 121              return count($this->cscol);
 122          }
 123  
 124  		function getWidth($whichcol) {
 125              return $this->cswidth[$whichcol] ;
 126          }
 127      }
 128  
 129      #----------------------------------------------------------------------
 130  
 131  
 132      Function LoadColInfo () {
 133          Global $Colheader,$curruser,$cscol,$csflags,$prefs;
 134  
 135          # cscol - column name from the database table
 136          # csflags - 'D' for a date column
 137          # $ColHeader = the HTML for displaying the column header
 138  
 139          $hq = db_query("select ".
 140              "p_column,p_active,p_flags,dcolumn,dheading,p_order,p_subtable ".
 141              "from propdisp,dictionary ".
 142              "where ".
 143              "(dtable=p_dataset or dtable=p_subtable) ".
 144              "and ".
 145              "p_column=dcolumn and p_uid='$curruser' and p_active=1 ".
 146              "order by p_order");
 147  
 148          if (db_numrows($hq)) {
 149              while ($hinfo = db_fetch_array($hq)) {
 150                  $stname = ($hinfo[p_subtable]) ? $hinfo[p_subtable] : "";
 151                  $cscol[] = "$hinfo[p_column]";
 152                  $csflags[] = "$hinfo[p_flags]";
 153                  $Colheader.="<td bgcolor=\"#bbbbbb\"><b><font size=2><a href=\"nbrowse.php?f_process=flyprops&amp;opt_prisort=$hinfo[p_column]\">$hinfo[dheading]";
 154                if ($prefs[opt_prisort] == "$hinfo[p_column]") {
 155                  if ($prefs[opt_pridesc] == "on") {
 156                    $Colheader .="<img src=\"graphics/active-up.gif\" />";
 157                  } else {
 158                    $Colheader .= "<img src=\"graphics/active-down.gif\" />";
 159                  }
 160                }
 161                $Colheader .="</a></font></td>\n";
 162              }
 163          } else {
 164  
 165              # There are no rows in the preferences table describing how things should
 166              # be shown.  Here are the defaults.
 167  
 168              $cscol[]="problem";    $csflags[]="";    $Colheader="$Colheader <td bgcolor=\"#bbbbbb\"><b><font size=2>Problem</td>";
 169              $cscol[]="ctag";        $csflags[]="";    $Colheader="$Colheader <td bgcolor=\"#bbbbbb\"><b><font size=2>Contact</td>";
 170              $cscol[]="o_date";        $csflags[]="D";    $Colheader="$Colheader <td bgcolor=\"#bbbbbb\"><b><font size=2>OpenDate</td>";
 171              $cscol[]="o_tech";        $csflags[]="";    $Colheader="$Colheader <td bgcolor=\"#bbbbbb\"><b><font size=2>OpenTech</td>";
 172              $cscol[]="c_date";        $csflags[]="D";    $Colheader="$Colheader <td bgcolor=\"#bbbbbb\"><b><font size=2>CloseDate</td>";
 173              $cscol[]="c_tech";        $csflags[]="";    $Colheader="$Colheader <td bgcolor=\"#bbbbbb\"><b><font size=2>CloseTech</td>";
 174              $cscol[]="status";        $csflags[]="";    $Colheader="$Colheader <td bgcolor=\"#bbbbbb\"><b><font size=2>Status</td>";
 175  
 176              LogIt('DEBUG','Using default preferences.');
 177  
 178          }
 179      }
 180  
 181      #----------------------------------------------------------------------
 182  
 183      Function ChooseParent($varname="a_spid",$selval="") {
 184          Global $f_func, $sys_selall, $currow, $sys_selfont, $sys_groupstatus;
 185          $t    =        '<select name="' . $varname . '">';
 186          $t    .=    '<option value="0">None</option>';
 187  
 188  #        if ($selval) {
 189  #            $pslip = new Slip();
 190  #            $pslip->loadSlip($selval);
 191  #            $t    .=    '<option selected value="' . $selval . '">';
 192  #            $t    .=    $selval . ' - ' . $pslip->getValue('problem') . '</option>';
 193  #            $t    .=    '<option value=0> --------------------';
 194  #        }
 195          
 196          if ($sys_groupstatus) {
 197              $wclause = "where status='$sys_groupstatus'";
 198          } else {
 199              $wclause = ($sys_selall) ? "" : "where spid=0" ;
 200              $wclause .= ($f_func == 'addchild') ? " or sid=$selval" : "" ;
 201              # we can't be a child of ourself, try not to loop either
 202              if ($currow[sid] != 0) {
 203                  $wclause .= " and sid<>" . $currow[sid];
 204                  $wclause .= " and spid<>" . $currow[sid];
 205              }
 206          }
 207                  
 208          # Query 
 209          $q = db_query("select sid,problem from slips $wclause order by slips.sid");
 210          while ($row=db_fetch_array($q)) {
 211              $txt = substr($row[problem],0,20);
 212              if (strlen($row[problem]) > 20) {
 213                  $txt="$txt...";
 214              }
 215              $sel="";
 216              if ( ($row[sid] == $currow[spid]) || ($row[sid] == $selval) ) {
 217                  $sel = "selected";
 218              }
 219              $t    .=     "<option $sel value=\"$row[sid]\"> $row[sid] - $txt\n";
 220          }
 221  
 222          $t    .=    '</select>';
 223          return $t;
 224      }
 225  
 226      #----------------------------------------------------------------------
 227  
 228      Function ChooseDependent() {
 229          Global $sys_selall, $currow, $sys_selfont, $sys_groupstatus;
 230          $t     =        '<select name="a_depend">';
 231          $t    .=    '<option value="0">None.</option>';
 232                  
 233          # dummy where clause
 234          $wclause = "where sid<>0";
 235          if ($currow[sid] != 0) {
 236              # we can't be a dependent of ourself
 237              $wclause .= " and sid<>" . $currow[sid];
 238              # we can't have matching  dependents 
 239              $wclause .= " and depend<>" . $currow[sid];
 240          }
 241          if ($sys_groupstatus) {
 242              $wclause .= " and status<>'$sys_groupstatus'";
 243          }
 244          $wclause .= ($sys_selall) ? "" : " and spid=0" ;
 245          $q = db_query("select sid,problem from slips $wclause order by slips.sid");
 246          while ($row=db_fetch_array($q)) {
 247              $txt = substr($row[problem],0,20);
 248              if (strlen($row[problem]) > 20) {
 249                  $txt="$txt...";
 250              }
 251              if ($row[sid] == $currow[depend]) {
 252                  $sel = "selected";
 253          } else {
 254                  $sel = "";
 255              }
 256              $t    .=    '<option value="' . $row[sid] . '" ' . $sel . '> ' . $row[sid] - $txt . '</option>';
 257          }
 258          $t    .=    '</select>';
 259          return $t;
 260      }
 261  
 262      #----------------------------------------------------------------------
 263  
 264      Function ChooseResource() {
 265          Global $currow, $parentinfo, $prefs, $sys_selfont;
 266  
 267          echo "<font size=$sys_selfont>";
 268          echo "<i>Resource...</i><br>";
 269          echo "<select name=\"a_resource\">";
 270          echo "<option value=\"\">None.";
 271          $orderclause = "order by r_tag";
 272          $q = db_query("select r_tag from resources $orderclause");
 273          while ($row=db_fetch_array($q)) {
 274              if ( ($row[r_tag] == $parentinfo[resource]) || ($row[r_tag] == $currow[resource]) ) {
 275                  $sel = "selected";
 276              } else {
 277                  $sel = "";
 278              }
 279              echo "<option value=\"$row[r_tag]\" $sel> $row[r_tag]\n";
 280          }
 281          echo "</select>";
 282      }
 283  
 284      #----------------------------------------------------------------------
 285  
 286      Function ChooseContact() {
 287          Global $currow, $parentinfo, $prefs, $sys_selfont;
 288  
 289          if ($prefs[opt_cwritein]) {
 290              $t    =     '<input name="a_ctag" size=15 value="' . $currow[ctag] . '">';
 291          } else {
 292              $t    =     '<select name="a_ctag">';
 293              $t    .=    '<option value="">&nbsp;';
 294              $orderclause = "order by name";
 295              $q = db_query("select tag,name from contacts $orderclause");
 296              while ($row=db_fetch_array($q)) {
 297                  if ( ($row[tag] == $parentinfo[ctag]) || ($row[tag] == $currow[ctag]) ) {
 298                      $sel = "selected";
 299                  } else {
 300                      $sel = "";
 301                  }
 302                  $t    .=     "<option value=\"$row[tag]\" $sel> $row[name] ($row[tag])\n";
 303              }
 304              $t    .=    '</select>';
 305          }
 306          return $t;
 307      }
 308  
 309      #----------------------------------------------------------------------
 310  
 311      Function ChooseCadd() {
 312          Global $currow, $parentinfo, $sys_selfont;
 313          $t    =    '<select name="a_cadd">';
 314          $t    .=    '<option value="">Use default';
 315          $q = db_query("select label from addresses group by label");
 316          while ($row=db_fetch_array($q)) {
 317              if ($row[label] == $currow[caddlabel]) {
 318                  $sel = "selected";
 319              } else {
 320                  $sel = "";
 321              }
 322              $t    .=     "<option value=\"$row[label]\" $sel> $row[label]\n";
 323          }
 324          $t    .=    '</select>';
 325          return $t;
 326      }
 327      
 328      #----------------------------------------------------------------------
 329  
 330      Function ChooseCphone() {
 331          Global $currow, $parentinfo, $sys_selfont;
 332          $t    =    '<select name="a_cphone">';
 333          $t    .=    '<option value="">Use default';
 334          $q = db_query("select label from phones group by label");
 335          while ($row=db_fetch_array($q)) {
 336              if ($row[label] == $currow[cphonelabel]) {
 337                  $sel = "selected";
 338              } else {
 339                  $sel = "";
 340              }
 341              $t    .= "<option value=\"$row[label]\" $sel> $row[label]\n";
 342          }
 343          $t    .=    '</select>';
 344          return $t;
 345      }
 346  
 347      #----------------------------------------------------------------------
 348  
 349      Function ChooseGroup() {
 350          Global $currow, $sys_selfont;
 351  
 352          $t    =    '<select name="a_grp">';
 353          $gq=db_query("select g_id from groups where g_assign='1' or g_assign='Y'");
 354          if (db_numrows($gq) != 0) {
 355              $t    .=    "<option value=\"\" $sel> None.\n";
 356              while ($ginfo = db_fetch_array($gq)) {
 357                  $sel = ($currow[grp] == $ginfo[g_id]) ? "selected" : "" ;
 358                  $t    .=     "<option value=\"$ginfo[g_id]\" $sel> $ginfo[g_id]\n";
 359              }
 360          } else {
 361              $t    .=     "<option value=\"\">None available.";
 362          }
 363          $t    .=    '</select>';
 364          return $t;
 365      }
 366      
 367      #----------------------------------------------------------------------
 368  
 369      Function ChoosePolicy() {
 370  
 371          echo "<i>Policy</i><br>\n";
 372          echo "<select name=\"a_spolicy\">";
 373          ShowPolicies();
 374          echo "</select>\n";
 375      }
 376  
 377  
 378      #----------------------------------------------------------------------
 379  
 380      Function ChooseCurrtech($label=false,$varname=false,$defval=false) {
 381          Global $currow, $parentinfo, $parent, $f_func, $curruser, $sys_selfont;
 382  
 383          $vtext = ($varname) ? "$varname" : "a_currtech" ;
 384          $t    =    '<select name="' . $vtext . '">';
 385          $t    .=    '<option value=""> None.';
 386          $wclause = "members.element=people.login and members.id='tech'";
 387          $oclause = "members.element";
 388          $mq = db_query("select ".
 389              "members.id,members.element,people.login,people.fullname ".
 390              "from members,people ".
 391              "where $wclause ".
 392              "order by $oclause ");
 393          if (db_numrows($mq)) {
 394              if ($f_func == "addslip" || $f_func == "addchild" || $f_func == "addlslip" || $f_func == "addres" ) {
 395                  $seltarget = $curruser;
 396                  if (IsSet($parent)) {
 397                      $seltarget = $parentinfo[currtech];
 398                  }
 399              }                                            
 400                      
 401              while ($mdata = db_fetch_array($mq)) {
 402                  if ($mdata[login] == $currow[currtech]) {
 403                      $seltarget = $currow[currtech];
 404                  }
 405                  if ($mdata[login] == $currow[r_currtech]) {
 406                      $seltarget = $currow[r_currtech];
 407                  }
 408                  $sel = ($mdata[login] == $seltarget) ? "selected" : "";
 409                  $t    .=     "<option value=\"$mdata[login]\" $sel> $mdata[login] = $mdata[fullname]\n";
 410              }
 411          } else {
 412              $t    .=     "<option value=\"\"> No users in the 'tech' group.";
 413          }
 414          $t    .=    '</select>';
 415          return $t;
 416      }
 417          
 418      #----------------------------------------------------------------------
 419  
 420      Function ChooseStatus($varname="a_status",$selval=false) {
 421          Global $sys_lstatus, $f_func, $currow, $sys_selfont;
 422  
 423          $t    = '<select name="' . $varname . '">';
 424          $stq = db_query("select flag,label from status");
 425          while ($row=db_fetch_array($stq)) {
 426              $sel = "";
 427              if (($selval) && ($row[flag] == $selval)) {
 428                  $sel = "selected"; 
 429              } else {
 430                  if ((($row[flag] == $sys_lstatus) && ($f_func != 'modslip')) || ($row[flag] == $currow[status])) {
 431                      $sel = "selected";
 432                  }
 433              }
 434              $t    .=    "<option value=\"$row[flag]\" $sel>$row[label]\n";
 435          }
 436          $t    .=    '</select>';
 437          return $t;
 438      }
 439  
 440      #----------------------------------------------------------------------
 441  
 442      Function ChoosePriority($varname="a_priority",$selval=0) {
 443          Global    $f_func, $currow, $sys_selfont, $sys_lowprio, $sys_highprio, $sys_defprio, $sys_prio_name;
 444          $t    =    '<select name="' . $varname . '">';
 445          for ($pri=$sys_highprio; $pri < $sys_lowprio + 1; $pri++) {
 446              $tag = "";
 447              $sel = "";
 448              if ($sys_prio_name[$pri]) { 
 449                  $tag = " - " . $sys_prio_name[$pri]; 
 450              }
 451              $sel = ($pri == $selval) ? "selected" : "";
 452              $t    .=     "<option value=\"$pri\" $sel> $pri $tag\n";
 453          }
 454          $t    .=    '</select>';
 455          return $t;
 456      }
 457  
 458      #----------------------------------------------------------------------
 459  
 460      Function ChoosePublic() {
 461          Global $f_func, $currow, $sys_defpublic;
 462  
 463          if (IsSet($currow[is_public])) {
 464              $pubcheck =  ($currow[is_public] == "1") ? "checked" : "" ;
 465              $privcheck = ($currow[is_public] == "0") ? "checked" : "" ;
 466          } else {
 467              if ("$sys_defpublic" == "1") {
 468                  $pubcheck = "checked"; 
 469              } else {
 470                  $privcheck = "checked";
 471              }
 472          }
 473          $t    =        '<input type="radio" name="a_public" value="1" ' . $pubcheck . '> Public ';
 474          $t    .=    '<input type="radio" name="a_public" value="0" ' . $privcheck. '> Private';
 475          return $t;
 476      }
 477  
 478      #----------------------------------------------------------------------
 479  
 480      Function TimeSpent() {
 481          
 482          Global $currow;
 483  
 484          ?>
 485  
 486              <i>Time Spent...</a><br>
 487              <input name="a_timespent" maxlength=4 size=5 value="<? echo ($currow[timespent]) ? $currow[timespent] : "0" ?>">
 488  
 489          <?
 490      }
 491  
 492      #----------------------------------------------------------------------
 493      Function ShowAttachRow($rowdata) {
 494          Global $sys_datefmt, $sys_attachdir;
 495  
 496          # Link in the info from the Library
 497  
 498          $lq = db_query("select * from library where li_fname='$rowdata[at_fname]'");
 499          $linfo = db_fetch_array($lq);
 500          echo "<tr bgcolor=#bbbbbb valign=top>";
 501          echo "<td align=center><a href=\"$sys_attachdir/$rowdata[at_fname]\">";
 502          echo "<img src=\"graphics/generic.gif\" border=0><br>$linfo[li_oname]</a></td>";
 503          echo "<td><i>Upload information</i><br>";
 504          echo "U/L on ".date("$sys_datefmt",$rowdata[at_date]);
 505          echo "<br>";
 506          echo "by ".$rowdata[at_tech]."</td>";
 507          echo "<td><i>Library information</i><br>";
 508          echo "$linfo[li_fsize] bytes</td>";
 509          echo "</tr>\n";
 510      }
 511  
 512      #----------------------------------------------------------------------
 513      Function ShowLibRow($rowdata) {
 514          Global $sys_datefmt, $sys_attachdir;
 515  
 516          echo "<tr bgcolor=#bbbbbb valign=top>";
 517                  # 
 518                  # 02 Nov 1999  [ROM]  changed from li_oname to li_title to be more informative for the user
 519                  # 02 Nov 1999  [ROM]  Added description lines to display
 520                  # 11 Nov 1999  [ROM]  moved upload info to far right cell, leaving only description in the center cell
 521          #
 522          # file download cell
 523          # FIXME: rename file @ upload to retain filename (and thus web server MIME typing) while avoiding name collision.  Yes, not handled in this function...
 524          echo "<td align=center><a href=\"attachments/$rowdata[li_fname]\">";
 525                  echo "<img src=\"graphics/generic.gif\" border=0><br>$rowdata[li_title]</a><br>";
 526                  echo "<font size=-1>[$rowdata[li_oname]]</font></td>";
 527          # description cell
 528                  echo "<td><i>Description</i><br> ".$rowdata[li_descrip]."</td>";
 529          # upload info cell
 530                  echo "<td><font size=-1><i>Upload information</i><br>";
 531                  echo "U/L on ".date("$sys_datefmt",$rowdata[li_update]);
 532                  echo "<br>";
 533                  echo "by ".$rowdata[li_uptech]."<br>";
 534                  echo "<i>Library information</i><br>";
 535                  echo "$rowdata[li_fsize] bytes</font></td>";
 536                  echo "</tr>\n";
 537      }
 538  
 539  
 540  ?>

title

Description

title

Description

title

Description

title

title

Body