Keystone PHP Cross Reference Customer Relationship Management

Source: /utils.php - 438 lines - 15427 bytes - Summary - Text - Print

   1  <?
   2  
   3      #---------------------------------------------------------------------#
   4      # This source code is (c)2004 Stonekeep Consulting, Inc               #
   5      # see http://www.stonekeep.com/license.html for licensing information #
   6      #---------------------------------------------------------------------#
   7  
   8      #----------------------------------------------------------------------
   9      # $Id: utils.php 260 2006-12-18 18:12:10Z dbs $
  10      #----------------------------------------------------------------------
  11      
  12      # Contains the normal function library used all over the place.
  13  
  14      #----------------------------------------------------------------------
  15      # Message tools.
  16      #        dumps out text to the inside frame of the main screen.  Table
  17      #        formatting and all.
  18  
  19      Function Message($whattosay) {
  20          OpenMessage();
  21          echo "<h2>";
  22          echo "$whattosay";
  23          echo "</h2>";
  24          CloseMessage();
  25      }
  26  
  27      Function OpenMessage() {
  28          echo "<tr><td>&nbsp;</td></tr>";
  29          echo "<tr><td>&nbsp;</td><td align=center fgcolor=\"#FFFFFF\" bgcolor=\"#A0A0A0\">";
  30          echo "<font color=#ffffff>";
  31      }
  32  
  33      Function CloseMessage() {
  34          echo "</td><td>&nbsp</td></tr>";
  35      }
  36  
  37      Function Dialog() {
  38          OpenMessage();
  39          echo "Moo!<br><font size=2> Are you sure?</font>";
  40          CloseMessage();
  41      }
  42  
  43      #----------------------------------------------------------------------
  44      # Framing tools
  45      
  46      Function FrameTop() {
  47          Global $curruser, $sys_version, $sys_graphics, $sys_server,$state,$sys_col;
  48          $zslip=0;
  49          if (is_array($state)) {
  50              $zslip = $state[slipzoom];
  51          } 
  52          echo "<table width=\"100%\" cellspacing=0 cellpadding=0 border=0 class=alert_body>\n";
  53          echo "<tr bgcolor=\"$sys_col[bordbg]\">\n";
  54          echo '<td colspan="2">';
  55          echo '<table width="100%" class="frametop">';
  56          echo '<td width="50%" class="collapsed">\n';
  57          echo "<font size=2 color=\"$sys_col[bordfg]\">\n";
  58          echo "Keystone2 $sys_version &copy;2004 Stonekeep Consulting, Inc.";
  59          echo "</td>\n";
  60          if (! ("$curruser" == "visitor")) {
  61              echo "<form action=\"nbrowse.php\">\n";
  62              echo "<td width=\"50%\" align=right nowrap>\n";
  63              echo "<font size=2 color=\"$sys_col[bordfg]\">QuickSlip: \n";
  64              echo "<select name=\"f_slipzoom\" ONCHANGE=\"form.submit(this)\">\n";
  65              $qstring = "select "
  66                  . "members.id,members.element,slips.sid,slips.problem "
  67                  . "from slips,members " ;
  68              if ($sys_server == "postgresql") {
  69                  $qstring .= "where int4(members.element) = slips.sid AND ";
  70              } else {
  71                  $qstring .= "where members.element = slips.sid AND ";
  72              }
  73              $qstring .= "members.id = 'quickslips' order by slips.sid";
  74              $qsq = db_query("$qstring");
  75              if (db_numrows($qsq)) {
  76                  echo "<option value=\"0\">None selected\n";
  77                  while ($qsqdata = db_fetch_array($qsq)) {
  78                      $sel = ($qsqdata[sid] == $state[slipzoom]) ? "selected" : "";
  79                      # LogIt("DEBUG","FrameTop()","sel for $qsqdata[sid] (compared to $state[slipzoom]) is $sel");
  80                      echo "<option value=\"$qsqdata[sid]\" $sel>";
  81                      echo "$qsqdata[sid] - $qsqdata[problem]\n";
  82                  }
  83              } else {
  84                  echo "<option value=\"0\">No quickslips defined.\n";
  85              }
  86              echo "</select>\n";
  87              echo "<input type=image src=\"$sys_graphics/circle.gif\" border=0 alt=\"\">\n";
  88              echo "</td>\n";
  89              echo "</form>\n";
  90          } else {
  91              echo "<td align=right>&nbsp;</td>\n";
  92          }
  93          echo "</tr></table>";
  94          echo "</td></tr>";
  95  #        echo "<table width=\"100%\" cellspacing=0 cellpadding=0 border=0>\n";
  96      }
  97      
  98      Function FrameFoot() {
  99          Global $lastresult, $curruser, $sys_col;
 100          echo '<tr><td colspan="2">';
 101          $footBox = new Box("Last Result: $lastresult[1]");
 102          echo $footBox->dump();
 103          echo '</td></tr>';
 104      }
 105  
 106      #----------------------------------------------------------------------
 107      # some misc db stuff.
 108  
 109      Function LoadStatus() {
 110          Global $stnames;
 111          
 112          $sth = db_query("select * from status order by flag");
 113          while ($strow = db_fetch_array($sth)) {
 114              $stnames[$strow[flag]] = "$strow[label]";
 115          }
 116      }
 117      
 118      Function RecalcSlip($whichslip) {
 119          if ($whichslip > 0) {
 120              # how many children do I have?
 121              $ch_dbh = db_query("select sid from slips where spid=$whichslip");
 122              $chcount = db_numrows($ch_dbh);
 123          
 124              # how many followups do I have?
 125              $fo_dbh = db_query("select f_sid from followups where f_sid=$whichslip");
 126              $focount = db_numrows($fo_dbh);
 127          
 128              $chupd = db_query("update slips set num_children=$chcount where sid=$whichslip");
 129              $foupd = db_query("update slips set num_follows=$focount where sid=$whichslip");
 130          }
 131      }
 132          
 133      #----------------------------------------------------------------------
 134      # funstuff
 135  
 136      Function ShowPolicies() {
 137          Global $currow;
 138          $ph = db_query("select * from policy");
 139          while ($prow = db_fetch_array($ph)) {
 140  #            echo "<option value=\"$prow[pid]\"> $prow[pid] - $prow[fullname]\n";
 141              $sel = ($currow[spolicy] == $prow[pid]) ? "selected" : "" ;
 142              echo "<option value=\"$prow[pid]\" $sel > $prow[pid] - $prow[fullname]\n";
 143          }
 144      }
 145  
 146      Function Send_Mail($to,$subject,$message) {
 147          Global $sys_m_from, $sys_f_from, $sys_website;
 148          LogIt('DEBUG','Send_Mail','Sending mail to ' . $to);
 149          $footer    =        "---------------------------------------------------------------------------\n";
 150          $footer .=    "This message was generated automatically by Keystone at $sys_website\n";
 151          mail("$to", "$subject", "$message\n$footer","From: $sys_f_from\nPrecedence: bulk");
 152      }
 153  
 154      Function Member($user,$group) {
 155          $mq = db_query("select * from members where element='$user' and id='$group'");
 156          if (db_numrows($mq)) {
 157              return 1;
 158          } else {
 159              return 0;
 160          }
 161      }
 162  
 163      Function LogIt($type,$module,$message) {
 164          Global $sys_logfile,$sys_datefmt,$curruser,$sys_loginfo,$sys_logdebug,$sys_logerr,$REMOTE_HOST;
 165  
 166          # 'type' is INFO, ERR, DEBUG, 
 167          # 'module' is the function or file that generated the call
 168          # 'message' is, well, the message. duh.
 169  
 170          if ((("$type"=="INFO") AND ($sys_loginfo)) OR (("$type"=="ERR") AND ($sys_logerr)) OR (("$type"=="DEBUG") AND ($sys_logdebug))) {
 171              $now=time();
 172              $us = $curruser . '@' . $_SERVER['REMOTE_ADDR'];
 173              $dstring = "[".date("$sys_datefmt",$now) . ']' . $us ;
 174              $ostring = sprintf("%-40s",$dstring);
 175              error_log("$ostring:$type:$module:$message\n",3,"$sys_logfile");
 176          }
 177      }
 178  
 179      Function PostBar($buttontext) {
 180          Global $sys_selfont;
 181          echo "<table width=100% bgcolor=#808080 cellpadding=2 cellspacing=1 border=0>\n";
 182          echo "<tr>\n";
 183          echo "<td width=33% align=center>\n";
 184          # FIXME: needs maxsize based on database query
 185          echo "<font size=$sys_selfont><input type=reset value=\"Reset\"></font>\n";
 186          echo "</td>\n";
 187          echo "<td width=33% align=center bgcolor=#202020>\n";
 188          echo "<font color=#cccccc>";
 189          echo "<font size=$sys_selfont><input type=submit value=\"$buttontext\"></font>\n";
 190          echo "</td>\n";
 191          echo "<td width=33% align=center>";
 192          echo "<font size=$sys_selfont><input type=submit name=f_cancel value=\"Cancel\"></font>";
 193          echo "</td>";
 194          echo "</tr>\n";
 195          echo "</table>\n";
 196          echo "</form>";
 197      }
 198  
 199      Function ShowStatusBar($whatsid) {
 200          Global $sys_col;
 201          echo "<table width=100% bgcolor=$sys_col[detailbg] cellspacing=2 border=0>\n";
 202          echo "<tr bgcolor=$sys_col[detailbg] valign=top>\n";
 203          $fq = db_query("select * from slips where sid=$whatsid");
 204          $finfo = db_fetch_array($fq);
 205          echo "<td bgcolor=$sys_col[detailbg]>";
 206          echo "<font fgcolor=$sys_col[detailfg]><i>Slip number</i><br><b>$finfo[sid]</b></td>";
 207          echo "<td bgcolor=$sys_col[detailbg]>";
 208          echo "<font fgcolor=$sys_col[detailfg]><i>Problem</i><br><b>".stripslashes(htmlspecialchars($finfo[problem]))."</b></td>";
 209          echo "<td bgcolor=$sys_col[detailbg]>";
 210          echo "<font fgcolor=$sys_col[detailfg]><i>Open Tech</i><br><b>$finfo[o_tech]</b></td>";
 211          echo "<td bgcolor=$sys_col[detailbg]>";
 212          echo "<font fgcolor=$sys_col[detailfg]><i>Contact</i><br><b>$finfo[ctag]</b></td>";
 213          echo "<td bgcolor=$sys_col[detailbg]>";
 214          echo "<font fgcolor=$sys_col[detailfg]><i>Current tech</i><br><b>$finfo[currtech]</b></td>";
 215          echo "</tr>";
 216          echo "</table>";
 217      }
 218  
 219      Function MailOptions() {
 220          Global $prefs,$sys_justrecent,$sys_selfont;
 221          echo "<i>Send email update to...</i><br>";
 222          $sel = ($prefs[opt_mopen]) ? "checked" : "";
 223          echo "<input type=checkbox name=m_open value=Y $sel>Opened by<br>\n";    
 224          $sel = ($prefs[opt_mcontact]) ? "checked" : "";
 225          echo "<input type=checkbox name=m_contact value=Y $sel>Contact Email<br>\n";
 226          $sel = ($prefs[opt_mtech]) ? "checked" : "";
 227          echo "<input type=checkbox name=m_currtech value=Y $sel>Current tech<p>\n";
 228          echo "<i>Or type in an address...</i><Br>";
 229          echo "<font size=$sys_selfont><input type=text name=m_other size=25 value=$prefs[opt_mother]></font><p>";
 230          $vstring = ($sys_justrecent) ? "value=\"Y\"" : "";
 231          echo "<input type=checkbox name=m_justlast $vstring>Send only most recent followup?";
 232      }
 233  
 234      Function MailOptionsBox() {
 235          Global $prefs,$sys_justrecent,$sys_selfont;
 236          $mailBox = new Box('Send email update to...');
 237          $sel = ($prefs[opt_mopen]) ? "checked" : "";
 238          $mailBox->addRow("<input type=checkbox name=m_open value=Y $sel>Opened by");    
 239          $sel = ($prefs[opt_mcontact]) ? "checked" : "";
 240          $mailBox->addRow("<input type=checkbox name=m_contact value=Y $sel>Contact Email");
 241          $sel = ($prefs[opt_mtech]) ? "checked" : "";
 242          $mailBox->addRow("<input type=checkbox name=m_currtech value=Y $sel>Current tech");
 243          $mailBox->addRow('Or type in an address...');
 244          $mailBox->addRow("<input type=text name=m_other size=25 value=$prefs[opt_mother]>");
 245          $vstring = ($sys_justrecent) ? "value=\"Y\"" : "";
 246          $mailBox->addRow("<input type=checkbox name=m_justlast $vstring>Send only most recent followup?");
 247          return $mailBox->dump();
 248      }
 249      
 250      Function CalcHighSeq($whatsid) {
 251          $ck = db_query("select f_seq from followups where f_sid=$whatsid") ;
 252          $highseq = 0;
 253          if (db_numrows($ck)) {
 254              while ($rows = db_fetch_array($ck)) {
 255                  if ($rows[f_seq] > $highseq) {
 256                      $highseq = $rows[f_seq];
 257                  }
 258              }
 259          }
 260          return $highseq;
 261      }
 262      
 263      Function ShowExtras ($table,$edata) {
 264          $squery=db_query("select * from eschema where etable='$table' order by element asc, esequence asc");
 265          $pending = 0;
 266          while ($pending || ($s = db_fetch_array($squery))) {
 267              $pending = 0;
 268              if (strchr($s[eflags],"O")) {
 269                  echo "<i>$s[elabel]</i><br>";
 270                  $element = $s[element];
 271                  $numselected = $edata[$element];
 272                  echo "<select name=\"a_$s[element]\">\n";
 273                  echo "<option value=0>None\n";
 274                  $count=0;
 275                  while (($s = db_fetch_array($squery)) && ($s[element] == $element)) {
 276                      ++$count;
 277                      echo  "<option value=$s[esequence] ";
 278                      if ($count == $numselected) {
 279                          echo "selected";
 280                      }
 281                      echo ">$s[elabel]\n";
 282                      $pending=1;
 283                  }
 284                  echo "</select><br>\n";
 285                  if (!$s) {
 286                      break;
 287                  }
 288              } else {
 289                  echo "<i>$s[elabel]</i><br>";
 290                  # FIXME: needs maxsize based on database query
 291                   echo "<input name=\"a_$s[element]\" ";
 292                  $element = $s[element] ;
 293                  echo "size=$s[elength]";
 294                  if (IsSet($edata[$element])) {
 295                      echo "value=\"$edata[$element]\"";
 296                  }
 297                  echo "> <br>";
 298              }
 299          }
 300      }
 301  
 302      # This is used only by slips and followups.  The value so $sid is
 303      # either the slip ID or the followup slip ID.
 304      Function InsertExtras ($table,$keyref) {
 305          $counter = 0;
 306          $eflist = db_query("select distinct element, etype from eschema where etable='$table'");
 307          while ($eres = db_fetch_array($eflist)) {
 308              $varname="a_$eres[element]}";
 309              global $$varname;
 310              eval("\$val=\"\$$varname\";");
 311  #            if (Is_String($keyref)) {
 312              if (Is_String($keyref) && (strcmp(strval(intval($keyref)),$keyref) != 0)) { 
 313  
 314                  LogIt("DEBUG","utils.php","query=insert into ebulk (btable,belement,bvalue,bkeyref) values ('$table','$eres[element]','$val','$keyref')");
 315                  $r=db_query("insert into ebulk (btable,belement,bvalue,bkeyref) values ('$table','$eres[element]','$val','$keyref')");
 316  
 317              } else {
 318                  LogIt("DEBUG","utils.php","query=insert into ebulk (btable,belement,bvalue,browref) values ('$table','$eres[element]','$val',$browref)");
 319  #                $r=db_query("insert into ebulk (btable,belement,bvalue,browref) values ('$table','$eres[element]','$val',$browref)");
 320                  $r=db_query("insert into ebulk (btable,belement,bvalue,browref) values ('$table','$eres[element]','$val','$keyref')");
 321              }
 322              $counter++;
 323          }
 324          return $counter;
 325      }
 326  
 327      #--------------------------------------------------------
 328      # These two functions are used for prompting for dates
 329      # within Keystone.;  The first shows the date in various
 330      #    pulldown menus... the second takes that entry after a post
 331      #    operation and turns it back into a Unix datestamp.
 332  
 333      Function PromptDate($vname,$default) {
 334          # Year Month Day Hour Minute
 335          LogIt("DEBUG","promptdate","Variable name is $vname, default value is $default");
 336          $defmonth = date("M",$default);
 337          LogIt("DEBUG","promptdate","Month name of default is $defmonth");
 338          $r = '';
 339          $r     =    "<select name=$vname}_month>\n";
 340          $sel = ($defmonth=='Jan') ? "selected" : "";
 341          $r    .=    "<option value=1 $sel>Jan\n";
 342          $sel = ($defmonth=='Feb') ? "selected" : "";
 343          $r    .=    "<option value=2 $sel>Feb\n";
 344          $sel = ($defmonth=='Mar') ? "selected" : "";
 345          $r    .=    "<option value=3 $sel>Mar\n";
 346          $sel = ($defmonth=='Apr') ? "selected" : "";
 347          $r    .=    "<option value=4 $sel>Apr\n";
 348          $sel = ($defmonth=='May') ? "selected" : "";
 349          $r    .=    "<option value=5 $sel>May\n";
 350          $sel = ($defmonth=='Jun') ? "selected" : "";
 351          $r    .=    "<option value=6 $sel>Jun\n";
 352          $sel = ($defmonth=='Jul') ? "selected" : "";
 353          $r    .=    "<option value=7 $sel>Jul\n";
 354          $sel = ($defmonth=='Aug') ? "selected" : "";
 355          $r    .=    "<option value=8 $sel>Aug\n";
 356          $sel = ($defmonth=='Sep') ? "selected" : "";
 357          $r    .=    "<option value=9 $sel>Sep\n";
 358          $sel = ($defmonth=='Oct') ? "selected" : "";
 359          $r    .=    "<option value=10 $sel>Oct\n";
 360          $sel = ($defmonth=='Nov') ? "selected" : "";
 361          $r    .=    "<option value=11 $sel>Nov\n";
 362          $sel = ($defmonth=='Dec') ? "selected" : "";
 363          $r    .=    "<option value=12 $sel>Dec\n";
 364          $r    .=    "</select>";
 365          $r    .=    "<select name=$vname}_day>\n";
 366          for ($i=1;$i<=31;$i++) {
 367              $sel = ($i==date("d",$default)) ? "selected" : "";
 368              $r    .=    "<option value=$i $sel>$i\n";
 369          }
 370          $r    .=    "</select>";
 371          $r    .=    "<select name=$vname}_year>\n";
 372          LogIt("DEBUG","promptdate","Year tag for default is " . date("Y",$default));
 373          for ($i=1969;$i<=date("Y");$i++) {
 374              $sel = ($i==date("Y",$default)) ? "selected" : "";
 375              $r    .=    "<option value=$i $sel>$i\n";
 376          }
 377          $r    .=    "</select>";
 378          $r    .=    "<select name=$vname}_hour>\n";
 379          for ($i=0;$i<=23;$i++) {
 380              $sel = ($i==date("H",$default)) ? "selected" : "";
 381              $r    .=    "<option value=$i $sel>$i\n";
 382          }
 383          $r    .=    "</select>";
 384          $r    .-    ": <select name=$vname}_minute>\n";
 385          for ($i=-15;$i<50;$i+=15) {
 386              $sel = ($i==date("i",$default)) ? "selected" : "";
 387              $r    .=    "<option value=$i $sel>$i\n";
 388          }
 389          $r    .=    "</select>";
 390          return $r;
 391      }
 392  
 393      Function InterpretDate($mi,$hr,$da,$mo,$yr) {
 394          $retval = mktime($hr,$mi,0,$mo,$da,$yr);
 395          return $retval;
 396      }
 397  
 398      #----------------------------------------------------------------------
 399  
 400      Function GenOrder($currscreen) {
 401          Global $prefs;
 402  
 403          #
 404          # Figure out what the 'order' clause should be for the current
 405          # slip view.
 406          #
 407  
 408          if ($prefs[opt_prisort]) {
 409              $otxt = "order by $prefs[opt_prisort]";
 410              if ($prefs[opt_pridesc]) {
 411                  $otxt = "$otxt desc";
 412              }
 413              if ($prefs[opt_secsort]) {
 414                  $otxt = "$otxt,$prefs[opt_secsort]";
 415                  if ($prefs[opt_secdesc]) {
 416                      $otxt = "$otxt desc";
 417                  }
 418              }
 419          } else {
 420              if ($currscreen == 'contacts') {
 421                  $otxt = 'order by tag';
 422              } elseif ($currscreen == 'slips') {
 423                  $otxt = '';
 424              }
 425          }
 426          return $otxt;
 427      }
 428  
 429      Function CheckEmpty($field, $replacement) {
 430  
 431          if (empty($field)) {
 432              return $replacement;
 433          } else {
 434              return $field;
 435          }
 436      }
 437  
 438      

title

Description

title

Description

title

Description

title

title

Body