PhpLabware PHP Cross Reference Learning Management Systems

Source: /includes/general_inc.php - 1425 lines - 66993 bytes - Summary - Text - Print

Description: functions used by general.php, user-defined tabels

   1  <?php
   2  
   3  // general_inc.php - functions used by general.php, user-defined tabels
   4  // general.php - author: Ethan Garner, Nico Stuurman <nicost@sf.net>
   5    /***************************************************************************
   6    * Copyright (c) 2002 by Ethan Garner, Nico Stuurman                        *
   7    * ------------------------------------------------------------------------ *
   8    *  Part of phplabware, a web-driven groupware suite for research labs      *
   9    *  This file contains classes and functions needed in general.php.         *
  10    *                                                                          *
  11    *  This program is free software; you can redistribute it and/or modify it *
  12    *  under the terms of the GNU General Public License as published by the   *
  13    *  Free Software Foundation; either version 2 of the License, or (at your  *
  14    *  option) any later version.                                              *
  15    \**************************************************************************/
  16  
  17  /**
  18   *  Displays information on the record's owner
  19   *
  20   * needs to be called within a table
  21   */
  22  function user_entry($id,$real_tablename) {
  23     global $db;
  24     $ownerid=get_cell($db,$real_tablename,'ownerid','id',$id);
  25     $r=$db->Execute("SELECT firstname,lastname,email FROM users WHERE id=$ownerid");
  26     if ($r->fields['email'])  {
  27        echo "<tr><th>Submitted by: </th><td><a href='mailto:".$r->fields["email"]."'>";
  28        echo $r->fields['firstname']." ".$r->fields['lastname']."</a></td>\n";
  29     }
  30     else {
  31        echo "<tr><th>Submitted by: </th><td>".$r->fields['firstname']." ";
  32        echo $r->fields["lastname"] ."</td>\n";
  33     }
  34     echo "<td>&nbsp;</td>";
  35  }
  36  
  37  
  38  
  39  /**
  40   * * 
  41   *  Prints name and date
  42   *
  43   * Needs to be called within a table
  44   */
  45  function date_entry($id,$real_tablename) {
  46     global $db,$system_settings;
  47  
  48     $date=get_cell($db,$real_tablename,"date","id","$id");
  49     $dateformat=get_cell($db,"dateformats","dateformat","id",$system_settings["dateformat"]);
  50     $date=date($dateformat,$date);
  51     echo "<th>Date entered: </th><td colspan=3>$date</td></tr>\n";
  52     if ($lastmodby && $lastmoddate)  {
  53        echo "<tr>";
  54        $r=$db->Execute("SELECT firstname,lastname,email FROM users WHERE id=$lastmodby");
  55        if ($r->fields["email"])  {
  56           echo "<tr><th>Last modified by: </th><td><a href='mailto:".$r->fields["email"]."'>";
  57           echo $r->fields["firstname"]." ".$r->fields["lastname"]."</a></td>\n";
  58        }
  59        else { 
  60        echo "<tr><th>Last modified by: </th><td>".$r->fields["firstname"]." ";
  61           echo $r->fields["lastname"] ."</td>\n";
  62        }
  63        echo "<td>&nbsp;</td>";
  64        $lastmoddate=date($dateformat,$lastmoddate);
  65        echo "<th>Date modified: </th><td colspan=3>$lastmoddate</td></tr>\n";
  66     }   
  67  }
  68  
  69  
  70  /**
  71   *  Displays searchbar in table view
  72   *
  73   * For data of type table, recursive calls are used
  74   * The ugly stuff with _POST could be done better
  75   * it would also be nicer if a string was returned instead of writing directly
  76   */
  77  function searchfield ($db,$tableinfo,$nowfield,$_POST,$jscript) {
  78     global $USER;
  79  
  80     $LAYOUT=16;
  81     $column=strtok($tableinfo->fields,",");
  82     while ($column) {
  83        ${$column}=$_POST[$column];
  84        $column=strtok(",");
  85     }
  86     if ($nowfield['datatype']== 'link')
  87        echo "<td style='width: 10%'>&nbsp;</td>\n";
  88     // datatype of column ownerid is text (historical oversight...)
  89     elseif ($nowfield['name']=='ownerid') {
  90         //if ($list) {
  91        $rowners=$db->Execute("SELECT ownerid FROM $tableinfo->realname");
  92        while ($rowners && !$rowners->EOF) {
  93           $ownerids[]=$rowners->fields[0];
  94           $rowners->MoveNext();
  95        }
  96        if ($ownerids) {
  97            $ownerlist=implode(',',$ownerids);
  98        }
  99        if ($ownerlist) {   
 100           $rowners2=$db->Execute("SELECT lastname,id FROM users WHERE id IN ($ownerlist)");
 101            $text=$rowners2->GetMenu2("$nowfield[name]",${$nowfield[name]},true,false,0,"style='width: 80%' $jscript");
 102           echo "<td style='width:10%'>$text</td>\n";
 103        }   
 104        else
 105           echo "<td style='width:10%'>&nbsp;</td>\n";
 106      }
 107      elseif ($nowfield['datatype']=='int' || $nowfield['datatype']=='float' || $nowfield['datatype']=='sequence' || $nowfield['datatype']=='date') {
 108            echo  " <td style='width: 10%'><input type='text' name='$nowfield[name]' value='".${$nowfield[name]}."'size=5 align='middle'></td>\n";
 109      }
 110      elseif ($nowfield['datatype']== 'text' || $nowfield['datatype']=='file')
 111         echo  " <td style='width: 25%'><input type='text' name='$nowfield[name]' value='".${$nowfield[name]}."'size=7></td>\n";
 112      elseif ($nowfield['datatype']== 'textlong')
 113         echo  " <td style='width: 10%'><input type='text' name='$nowfield[name]' value='".${$nowfield[name]}."'size=8></td>\n";
 114      elseif ($nowfield['datatype']== 'pulldown' || $nowfield['datatype']=='mpulldown') {
 115        echo "<td style='width: 10%'>";
 116        $rpull=$db->Execute("SELECT typeshort,id from $nowfield[ass_t] ORDER by sortkey,type");
 117        if ($rpull)
 118           if ($nowfield['datatype']=='mpulldown')
 119              $text=$rpull->GetMenu2("$nowfield[name]",${$nowfield[name]},false,true,10,"style='width: 100%' align='left'");   
 120           else 
 121              $text=$rpull->GetMenu2("$nowfield[name]",${$nowfield[name]},true,false,0,"style='width: 80%' $jscript");   
 122        else
 123            $text="&nbsp;";
 124        echo "$text\n";
 125        // Draw a modify icon to let qualified users change the pulldown menus
 126        if ( ($USER['permissions'] & $LAYOUT) && $_SESSION['javascript_enabled'])  {
 127            $jscript2=" onclick='MyWindow=window.open (\"general.php?tablename=".$tableinfo->name."&amp;edit_type=$nowfield[ass_t]&amp;jsnewwindow=true&amp;formname=$formname&amp;selectname=$nowfield[name]".SID."\",\"type\",\"scrollbars,resizable,toolbar,status,menubar,width=600,height=400\");MyWindow.focus()'";
 128             echo "<A href=\"javascript:void(0)\" $jscript2> <img src=\"icons/edit_modify.png\" alt=\"modify {$nowfield['name']}\" title=\"modify {$nowfield['label']}\" border=\"0\"/></A>\n";
 129            //echo "<input type='button' name='edit_button' value='Edit $nowfield[label]' $jscript2><br>\n";
 130        }                          
 131        echo "</td>\n";
 132     }
 133     elseif ($nowfield['datatype']== 'table') {
 134         $ass_tableinfo=new tableinfo ($db,$nowfield['ass_table_name'],false);
 135         $rasslk=$db->Execute("SELECT columnname FROM {$ass_tableinfo->desname} WHERE id={$nowfield['ass_column']}");
 136         $ass_Allfields=getvalues($db,$ass_tableinfo,$rasslk->fields[0]);
 137         // scary acks, their ugliness shows that we need to reorganize some stuff
 138         $ass_Allfields[0]['name']=$nowfield['name']; 
 139         $ass_tableinfo->fields="{$nowfield['name']}";
 140         searchfield($db,$ass_tableinfo,$ass_Allfields[0],$_POST,$jscript);
 141      }
 142      elseif ($nowfield["datatype"]=="image")
 143         echo "<td style='width: 10%'>&nbsp;</td>";
 144  }
 145  
 146  /**
 147   * *
 148   *  Generated comma separated list of columns based on view prefs
 149   *
 150   */
 151  function viewlist($db,$tableinfo,$viewid) {
 152     global $USER;
 153     $r=$db->Execute("SELECT columnid FROM tableviews WHERE viewnameid=$viewid AND viewmode=1");
 154     while ($r && !$r->EOF) {
 155        $rb=$db->Execute("SELECT columnname,sortkey FROM {$tableinfo->desname} WHERE id={$r->fields[0]}");
 156        $list[$rb->fields[1]]=$rb->fields[0];
 157        $r->MoveNext();
 158     }
 159     //$r=$db->Execute("SELECT columnid FROM tableviews WHERE viewnameid=$viewid");
 160     ksort($list);
 161     reset($list);
 162     return implode (",",$list);
 163  }
 164  
 165        
 166  /**
 167   * *
 168   *  Generated menu with user-defined views
 169   *
 170   */
 171  function viewmenu($db, $tableinfo,$viewid,$useronly=1,$jscript='OnChange="document.g_form.submit()"') {
 172     global $USER, $db_type;
 173     
 174     if ($useronly)
 175        $userreq="tableviews.userid={$USER['id']} AND";
 176     // first find views accessible to user
 177     if ($db_type=='mysql') 
 178        $r=$db->Execute("SELECT DISTINCT viewname,viewnames.viewnameid FROM viewnames LEFT JOIN tableviews ON viewnames.viewnameid=tableviews.viewnameid WHERE $userreq tableviews.tableid={$tableinfo->id} AND tableviews.viewmode=1");
 179     else
 180        $r=$db->Execute("SELECT viewname,viewnameid FROM viewnames WHERE viewnameid IN (SELECT viewnameid FROM tableviews WHERE $userreq tableid={$tableinfo->id} AND viewmode=1)"); 
 181     if ($r) {
 182        $viewname.= 'View: '.$r->GetMenu2('viewid',$viewid,true,false,0,$jscript);
 183     }
 184     if ($viewid)
 185        $viewidtext="&amp;viewid=$viewid";
 186     include  ('./includes/defines_inc.php');
 187     if ($USER['permissions'] >= $WRITE) {
 188        $viewname.="<a href='views.php?tablename={$tableinfo->name}$viewidtext'>Edit views</a>";
 189     }
 190  
 191     return $viewname;
 192  }
 193  
 194  
 195  
 196  /**
 197   * * 
 198   *  Displays information in table in edit mode
 199   *
 200   */
 201  function display_table_change($db,$tableinfo,$Fieldscomma,$pr_query,$num_p_r,$pr_curr_page,$page_array,$r=false) {
 202     global $nr_records,$max_menu_length,$USER,$LAYOUT,$_SESSION;
 203  
 204     $first_record=($pr_curr_page - 1) * $num_p_r;
 205     $current_record=$first_record;
 206     $last_record=$pr_curr_page * $num_p_r;
 207     if (!$r)
 208        $r=$db->Execute($pr_query);
 209     $r->Move($first_record);
 210     // print all entries
 211     while (!($r->EOF) && $r && $current_record < $last_record)  {
 212        // Get required ID and title
 213        $id=$r->fields['id'];
 214        $title=get_cell($db, $tableinfo->realname,'title','id',$r->fields['id']);        
 215        $Allfields=getvalues($db,$tableinfo,$Fieldscomma,id,$id);
 216        $may_write=may_write($db,$tableinfo->id,$id,$USER);
 217  
 218        // print start of row of selected record
 219        if ($current_record % 2) {
 220           echo "<tr class='row_even' align='center'>\n";
 221        } else {
 222           echo "<tr class='row_odd' align='center'>\n";
 223        }
 224        foreach($Allfields as $nowfield) {
 225           // Javascript code that uses XMLHTTPRequest to send requests to the server asynchronously
 226           $js="tellServer(\"actionMode.php\",$tableinfo->id,$id,\"{$nowfield['name']}\",\"{$nowfield['datatype']}\",this.value)";
 227           if ($nowfield['required']=='Y')
 228              $thestar="<sup style='color:red'>&nbsp;*</sup>";
 229           else
 230              $thestar=false;
 231  
 232           if ( ($nowfield['modifiable']!='Y') || !$may_write) {
 233              echo "<td><input type='hidden' name='{$nowfield['name']}_$id' value=\"" . str_replace('"','&quot;',$nowfield['values']) ."\">\n";
 234              echo "{$nowfield['text']}</td>\n";
 235           } elseif ($nowfield['datatype']=='text') {
 236              // for comfortable input calculate size and present accordingly
 237              $maxwidth=40;
 238              if (strlen($nowfield['values'])) {
 239                  $rows=floor (strlen($nowfield['values']) / $maxwidth) + 1;
 240                  if ($rows <= 1) {
 241                     $columns=(strlen($nowfield['values']) % $maxwidth) + 1;
 242                  } else {
 243                     $columns = $maxwidth;
 244                  }
 245              } else { // no pre-exsisting value 
 246                 $rows = 1;
 247                 $columns = 10;
 248              }
 249              // since textareas with row==1 do not display nicely:
 250              if ($rows == 1) {    
 251                 echo "<td><input type='text' name='{$nowfield['name']}_$id' value=\"".str_replace('"','&quot;',$nowfield['values'])."\" size=$columns onchange='$js'>$thestar</td>\n";    
 252               } else {   
 253                 echo "<td>$thestar<textarea name='{$nowfield['name']}_$id' cols=$columns rows=$rows onchange='$js'>{$nowfield['values']}</textarea></td>\n";                   
 254               }
 255           } elseif ($nowfield['datatype']=='date') {
 256               echo "<td><input type='text' name='{$nowfield['name']}_$id' value='{$nowfield['text']}' size=12 onchange='$js'>$thestar</td>\n";
 257           } elseif ($nowfield['datatype']=='int' || $nowfield['datatype']=='sequence') {
 258              $js="if (isAnInt(this.value)) { $js } else {this.value=\"\"; this.focus(); return false;}";
 259               echo "<td>$thestar<input type='text' name='{$nowfield['name']}_$id' value='{$nowfield['values']}' size=6 onchange='$js'></td>\n";
 260           } elseif ($nowfield['datatype']=='float') {
 261              $js="if (isAFloat(this.value)) { $js } else {this.value=\"\"; return false;}";
 262               echo "<td><input type='text' name='{$nowfield['name']}_$id' value='{$nowfield['values']}' size=8 onchange='$js'>$thestar</td>\n";
 263           } elseif ($nowfield['datatype']=='textlong') {
 264               echo "<td><textarea name='$nowfield[name]_$id' cols=45 rows=3 onchange='$js'>$thestar{$nowfield['values']}</textarea></td>\n"; 
 265           }
 266           elseif ($nowfield['datatype']=='link') {
 267              echo "<td><input type='text' name='$nowfield[name]_$id' value='$nowfield[values]' size=15 onchange='$js'>$thestar</td>\n";
 268           }
 269           elseif ($nowfield['datatype']=='pulldown') {
 270              // get previous value    
 271              $rp=$db->Execute("SELECT typeshort,id FROM {$nowfield['ass_t']} ORDER BY sortkey,typeshort");
 272              $text=$rp->GetMenu2("$nowfield[name]_$id",$nowfield['values'],true,false,0,"onchange='$js'");
 273              echo "\n<td>$text $thestar </td>\n";
 274           }
 275           elseif ($nowfield['datatype']=='mpulldown') {
 276              $js="onchange='submit_changes($tableinfo->id,$id,\"{$nowfield['name']}\",\"{$nowfield['datatype']}\",this)'";
 277              // get previous values
 278              unset ($rp);
 279              $rp=$db->Execute("SELECT typeshort,id FROM {$nowfield['ass_t']} ORDER BY sortkey,typeshort");
 280              unset ($rbv);
 281              unset ($valueArray);
 282              $rbv=$db->Execute("SELECT typeid FROM {$nowfield['key_t']} WHERE recordid=$id");
 283              while ($rbv && !$rbv->EOF) {
 284                 $valueArray[]=$rbv->fields[0];
 285                 $rbv->MoveNext();
 286              }
 287              $text=$rp->GetMenu2($nowfield['name']."_$id",$valueArray,true,true,4,$js);
 288              echo "\n<td>$text $thestar</td>\n";
 289           }
 290           elseif ($nowfield['datatype']=='table') {
 291              // only display primary key here
 292              if (!$nowfield['ass_local_key']) { 
 293                 $text=false;
 294                 // get previous value    
 295                 if ($nowfield['ass_column_name'] && $nowfield['ass_table_name']) { 
 296                    $rcount=$db->Execute("SELECT COUNT(id) FROM {$nowfield['ass_table_name']}");
 297                    if ($rcount && ($rcount->fields[0] < $max_menu_length)) 
 298                       $text=GetValuesMenu($db,"{$nowfield['name']}_$id",$nowfield['values'],$nowfield['ass_table_name'],$nowfield['ass_column_name'],false,$js);
 299                    else {
 300                       $text="<input type='hidden' name='max_{$nowfield['name']}_$id' value='true'>\n";
 301                       $text.="<input type='text' name='{$nowfield['name']}_$id' value='{$nowfield['text']}'>\n<br>";
 302                    }
 303                 }
 304                 echo "<td>$text $thestar</td>\n";
 305              }
 306              else
 307                 echo "<td>{$nowfield['text']} $thestar</td>\n";
 308           }
 309       elseif ($nowfield['datatype']=='textlarge') {
 310           echo "<td colspan=6><textarea name='{$nowfield['name']}_$id' rows='5' cols='100%' $js>{$nowfield['values']}</textarea>$thestar</td>\n";
 311        } else {
 312              echo "<td>{$nowfield['text']}</td>\n";
 313        }
 314        }
 315  
 316        // View, Change and Delete buttons
 317        echo "<td align='center'>&nbsp;\n";  
 318        // Hidden variables should go here
 319        // This one is used by Javascript
 320        echo "<input type='hidden' name='chgj_".$id."' value=''>\n";
 321        // Access rights
 322        $ra=$db->Execute("SELECT gr,gw,er,ew FROM {$tableinfo->realname} WHERE id={$r->fields['id']}");
 323        echo "<input type='hidden' name='grr_$id' value='{$ra->fields['gr']}'>\n";
 324        echo "<input type='hidden' name='evr_$id' value='{$ra->fields['er']}'>\n";
 325        echo "<input type='hidden' name='grw_$id' value='{$ra->fields['gw']}'>\n";
 326        echo "<input type='hidden' name='evw_$id' value='{$ra->fields['er']}'>\n";
 327  
 328        // Action column - icons and javascript to enable these by Michael Muller
 329        // View action
 330        if ($_SESSION['javascript_enabled']) {
 331           $jscript=" onclick='MyWindow=window.open (\"general.php?tablename=".$tableinfo->name."&amp;showid=$id&amp;jsnewwindow=true&amp;viewid=$viewid\",\"view\",\"status,menubar,toolbar,scrollbars,resizable,titlebar,width=700,height=500\");MyWindow.focus()'";
 332           echo "<A href=\"javascript:void(0)\" $jscript> <img src=\"icons/detail.png\" alt=\"detail\" title=\"detail\" border=\"0\"/></A>\n";
 333        } else {
 334           echo "<input type=\"submit\" name=\"view_" . $id . "\" value=\"View\">\n";
 335        }
 336        if (may_write($db,$tableinfo->id,$id,$USER)) {
 337           // Change action
 338           // this works, but how do you go back from the modify window to this one???
 339           if ($_SESSION['javascript_enabled']) {
 340              echo "<input type=\"hidden\" name=\"chg_" . $id . "\">\n";
 341              $jscript="Onclick=\"document.g_form.chg_$id.value='Change'; document.g_form.submit();\"";
 342              echo "<A href=\"javascript:void(0)\" $jscript> <img src=\"icons/edit_modify.png\" alt=\"modify\" title=\"modify\" border=\"0\"/></A>\n";
 343           } else {
 344              echo "<input type=\"submit\" name=\"chg_" . $id . "\" value=\"Change\">\n";
 345           }
 346           // Delete action
 347           if (! $_SESSION['javascript_enabled']) {
 348              $delstring = "<input type=\"submit\" name=\"del_" . $id . "\" value=\"Remove\">\n";
 349           } else {
 350               $jstitle=str_replace("'"," ",$title);
 351              $delstring = "Onclick=\"if(confirm('Are you sure that you want to remove record $jstitle?'))";
 352              $delstring .= "{document.g_form.del_$id.value='Remove';document.g_form.submit();return true;}return false;\""; 
 353              $delstring = "<input type='hidden' name='del_$id'>\n<A href=\"javascript:void(0)\" $delstring> <img src=\"icons/delete.png\" alt=\"delete\" title=\"delete\" border=\"0\"/></A>";
 354           }
 355           echo "$delstring\n";
 356        }
 357        /*
 358        if ($_SESSION['javascript_enabled']) {
 359           $jscript=" onclick='MyWindow=window.open (\"general.php?tablename=".$tableinfo->name."&amp;showid=$id&amp;jsnewwindow=true\",\"view\",\"scrollbars,resizable,toolbar,status,menubar,width=700,height=500\");MyWindow.focus()'";
 360           echo "<input type=\"button\" name=\"view_" . $id . "\" value=\"View\" $jscript>\n";
 361        }
 362        else
 363           echo "<input type=\"submit\" name=\"view_" . $id . "\" value=\"View\">\n";
 364        if ($may_write) {
 365           echo "<input type=\"submit\" name=\"chg_" . $id . "\" value=\"Change\">\n";
 366           $delstring = "<input type=\"submit\" name=\"del_" . $id . "\" value=\"Remove\" ";
 367           $delstring .= "Onclick=\"if(confirm('Are you sure that you want to remove record $title?'))";
 368           $delstring .= "{return true;}return false;\">"; 
 369           echo "$delstring\n";
 370        }
 371        */
 372        echo "</td>\n";
 373        echo "</tr>\n";
 374        $r->MoveNext();
 375        $current_record++;
 376     }
 377  
 378     // Add Record button
 379     if (may_write($db,$tableinfo->id,false,$USER)) {
 380        echo "<tr><td colspan=20 align='center'>";
 381        echo "<input type=\"submit\" name=\"add\" value=\"Add Record\">";
 382        echo "</td></tr>\n";
 383     }
 384  
 385     echo "</table>\n";
 386     next_previous_buttons($page_array);
 387     echo "</form>\n";
 388  }
 389  
 390  
 391  /**
 392   * * 
 393   *  Displays all information within the table
 394   *
 395   */
 396  function display_table_info($db,$tableinfo,$Fieldscomma,$pr_query,$num_p_r,$pr_curr_page,$page_array,$r=false,$viewid=false) {
 397     global $nr_records,$USER,$LAYOUT,$_SESSION;
 398  
 399     $first_record=($pr_curr_page - 1) * $num_p_r;
 400     $current_record=$first_record;
 401     $last_record=$pr_curr_page * $num_p_r;
 402     if (!$r)
 403        $r=$db->Execute($pr_query);
 404     $r->Move($first_record);
 405  
 406     // we keep a list with fileids in the user settings
 407     // these files can be seen without checking the database
 408     // to be sure that only the current files can be seen, unset the entry first
 409     unset($USER['settings']['fileids']);
 410     
 411     // print all entries
 412     while (!($r->EOF) && $r && ($current_record < $last_record) )  {
 413        // Get required ID and title
 414        $id=$r->fields['id'];
 415        $title=get_cell($db, $tableinfo->realname,'title','id',$r->fields['id']);        
 416        $Allfields=getvalues($db,$tableinfo,$Fieldscomma,id,$id);
 417        // print start of row of selected group
 418        if ($current_record % 2) echo "<tr class='row_odd' align='center'>\n";
 419           else echo "<tr class='row_even' align='center'>\n";
 420    
 421        foreach($Allfields as $nowfield) {
 422           // nested table links to the current world:
 423           if (isset($nowfield['nested'])) {
 424              $nowfield['text']=$nowfield['nested']['text'];
 425              $nowfield['values']=$nowfield['nested']['values'];
 426              $nowfield['datatype']=$nowfield['nested']['datatype'];
 427              $nowfield['fileids']=$nowfield['nested']['fileids'];
 428           }
 429           // display the contents 
 430           if ($nowfield['link'])
 431              echo "<td>{$nowfield['link']}</td>\n";
 432           elseif ($nowfield['datatype']=='mpulldown')
 433              echo "<td align='left' cellpadding='5%'>{$nowfield['text']}</td>\n"; 
 434           elseif ( $nowfield['datatype'] == 'textlong' && (strlen($nowfield['text'])>59) && $_SESSION['javascript_enabled'] && (substr($nowfield['text'],0,7) !='<a href') ) {
 435              // provide long text by mouseover -- by MM
 436              $startofText = substr($nowfield['text'],0,60);
 437              echo "<td><a class='Tooltip' href=\"javascript:void(0);\" ";
 438              // single quotes causes javascript problems even when 'htmled'
 439              $escapedText = str_replace("'",'"',$escapedText);
 440              echo "onmouseover=\"this.T_WIDTH=400;return escape";
 441              $escapedText = htmlspecialchars($nowfield['text'], ENT_QUOTES);
 442              // returns spoil the party
 443              $escapedText = preg_replace("/\r\n|\n|\r/", "<br>", $escapedText);
 444              // Even when converted to HTML characters, the following kill tooltips.  Remove
 445              $escapedText = str_replace('&quot;',' ',$escapedText);
 446              $escapedText = str_replace('&#039;',' ',$escapedText);
 447              echo '(\''.$escapedText.'\')">'.$startofText."...</a></td>\n";
 448           } else {
 449              echo "<td>{$nowfield['text']}</td>\n"; 
 450           }
 451  
 452           // write file ids to user settings so that we do not need to check them again when downloading thumbnails
 453           if (isset($nowfield['fileids'])) {
 454              foreach ($nowfield['fileids'] as $fileid)
 455                 $USER['settings']['fileids'][]=$fileid;
 456           }
 457        }
 458  
 459        // Action column - icons and javascript to enable these by Michael Muller
 460        echo "<td align='center'>&nbsp;\n";  
 461        // View action
 462        if ($_SESSION['javascript_enabled']) {
 463           $jscript=" onclick='MyWindow=window.open (\"general.php?tablename=".$tableinfo->name."&amp;showid=$id&amp;jsnewwindow=true&amp;viewid=$viewid\",\"view\",\"status,menubar,toolbar,scrollbars,resizable,titlebar,width=700,height=500\");MyWindow.focus()'";
 464           echo "<A href=\"javascript:void(0)\" $jscript> <img src=\"icons/detail.png\" alt=\"detail\" title=\"detail\" border=\"0\"/></A>\n";
 465        } else {
 466           echo "<input type=\"submit\" name=\"view_" . $id . "\" value=\"View\">\n";
 467        }
 468        if (may_write($db,$tableinfo->id,$id,$USER)) {
 469           // Modify action
 470           // this works, but how do you go back from the modify window to this one???
 471           if ($_SESSION['javascript_enabled']) {
 472              $jscript="onclick='MyWindow=window.open (\"general.php?tablename=".$tableinfo->name."&amp;jsnewwindow=true&amp;modify=true&amp;mod_".$id."=Modify\",\"modify\",\"scrollbars,resizable,status,menubar,toolbar,width=700,height=500\");MyWindow.focus()'";
 473              echo "<A href=\"javascript:void(0)\" $jscript> <img src=\"icons/edit_modify.png\" alt=\"modify\" title=\"modify\" border=\"0\"/></A>\n";
 474           } else {
 475              echo "<input type=\"submit\" name=\"mod_" . $id . "\" value=\"Modify\">\n";
 476           }
 477           // Delete action
 478           if (! $_SESSION['javascript_enabled']) {
 479              $delstring = "<input type=\"submit\" name=\"del_" . $id . "\" value=\"Remove\">\n";
 480           } else {
 481               $jstitle=str_replace("'"," ",$title);
 482              $delstring = "Onclick=\"if(confirm('Are you sure that you want to remove record $jstitle?'))";
 483              $delstring .= "{document.g_form.del_$id.value='Remove';document.g_form.submit();return true;}return false;\""; 
 484              $delstring = "<input type='hidden' name='del_$id'>\n<A href=\"javascript:void(0)\" $delstring> <img src=\"icons/delete.png\" alt=\"delete\" title=\"delete\" border=\"0\"/></A>";
 485           }
 486           echo "$delstring\n";
 487        }
 488        echo "</td>\n";
 489        echo "</tr>\n";
 490        $r->MoveNext();
 491        $current_record++;
 492     }
 493     // Add Record button
 494     if (may_write($db,$tableinfo->id,false,$USER)) {
 495        echo "<tr><td colspan=20 align='center'>";
 496        if ($_SESSION['javascript_enabled']) {
 497           $jscript=" onclick='MyWindow=window.open (\"general.php?tablename=".$tableinfo->name."&amp;add=Add&amp;jsnewwindow=true\",\"view\",\"scrollbars,resizable,toolbar,status,menubar,width=700,height=500\");MyWindow.focus()'";
 498           echo "<input type=\"button\" name=\"add\" value=\"Add Record\" $jscript>";
 499        }
 500        else {
 501           echo "<input type=\"submit\" name=\"add\" value=\"Add Record\">";
 502        }
 503        echo "</td></tr>";
 504     }
 505  
 506     echo "</table>\n";
 507     next_previous_buttons($page_array);
 508     echo "</form>\n";
 509     echo "<script language='JavaScript' type='text/javascript' src='includes/js/wz_tooltip.js'></script>";
 510  }
 511  
 512  /**
 513   * *
 514   *  Display a record in a nice format
 515   *
 516   */
 517  function display_record($db,$Allfields,$id,$tableinfo,$backbutton=true,$previousid=false,$nextid=false,$viewid=false) 
 518  {
 519     global $PHP_SELF, $md,$USER;
 520  
 521     if (!$Allfields[1]['recordid']) {
 522        echo "<table border=0 align='center'>\n";
 523        echo "<tr>\n<td align='center'><h3>Record not found</h3>\n</td>\n</tr>";
 524        echo "<tr>\n<td align='center'>\n<button onclick='self.close();window.opener.focus();' name='Close' value='close'>Close</button></td></tr>\n";
 525        echo "</table>\n";
 526        exit;
 527     }
 528     echo "&nbsp;<br>\n";
 529     echo "<table border=0 align='center'>\n";
 530     $count=0;
 531     echo "<tr>\n";
 532     // if viewid is defined we will over-ride display record with values from the view settings
 533     if ($viewid) {
 534        $r=$db->Execute("SELECT columnid FROM tableviews WHERE viewnameid=$viewid AND viewmode=2");
 535        while ($r && !$r->EOF) {
 536           $viewlist[]=$r->fields[0];
 537           $r->MoveNext();
 538        }
 539     }
 540     //print_r($Allfields);
 541  
 542     foreach ($Allfields as $nowfield) {
 543  
 544        // decide whether this field will be shown
 545        unset ($thisfield);
 546        // if we have a viewid, check the list
 547        if ($viewlist){
 548           $thisfield=in_array($nowfield['columnid'],$viewlist);
 549        }
 550        else {
 551           //Only show the entry when display_record is set
 552           $thisfield= ($nowfield['display_record']==='Y');
 553        }
 554        if ($thisfield && is_array($nowfield)) {
 555           // explode nested table links to the current world:
 556           if (isset($nowfield['nested'])) {
 557              $nowfield['text']=$nowfield['nested']['text'];
 558              $nowfield['values']=$nowfield['nested']['values'];
 559              $nowfield['datatype']=$nowfield['nested']['datatype'];
 560              $nowfield['fileids']=$nowfield['nested']['fileids'];
 561           }
 562           // display the fields in two columns
 563           if ($count && !($count % 2))
 564              echo "</tr>\n<tr>\n";
 565           if ($nowfield['datatype']=='textlong') {
 566              $textlarge=nl2br(htmlentities($nowfield['values']));
 567              echo "<th>$nowfield[label]</th><td colspan=2>$textlarge</td>\n";
 568           }
 569           elseif ($nowfield['datatype']=='file' || $nowfield['datatype']=='image') {
 570              // if this came through a associated table:
 571              if ($nowfield['nested']['nested_tbname'] && $nowfield['nested']['nested_columnid'])
 572                 $files=get_files($db,$nowfield['nested']['nested_tbname'],$nowfield['nested']['nested_id'],$nowfield['nested']['nested_columnid'],0,'big');
 573              // the normal/direct way
 574              else
 575                 $files=get_files($db,$tableinfo->name,$id,$nowfield['columnid'],0,'big');
 576              if ($files) { 
 577                 echo "<th>$nowfield[label]:</th>\n<td colspan=5>";
 578                 for ($i=0;$i<sizeof($files);$i++)  {
 579                    echo $files[$i]['link']."&nbsp;&nbsp;(<i>".$files[$i]['name']."</i>, ".$files[$i]['type'];
 580                    echo " file, ".$files[$i]['size'].")<br>\n";
 581                 }
 582                 echo "<td>\n";
 583              }
 584              // to keep odd and even fields right
 585              else
 586                 $count--;
 587           }
 588           // most datatypes are handled in getvalues
 589           else {
 590              echo "<th>$nowfield[label]</th>\n";
 591          if ($nowfield['link'])
 592                 echo "<td colspan=2>{$nowfield['link']}</td>\n";
 593              else       
 594                 echo "<td colspan=2>{$nowfield['text']}</td>\n";
 595           }
 596           $count++;
 597        }
 598     }
 599     echo "</tr>\n";
 600     make_link($id,$tableinfo->name);
 601     show_reports($db,$tableinfo,$id,$viewid);
 602     if (function_exists ("plugin_display_show")){
 603        plugin_display_show ($db,$Allfields,$id);
 604        return $Allfields;
 605     } 
 606     echo "</table>\n";
 607  
 608     echo "<form method='post' name='g_form' action='$PHP_SELF?tablename=".$tableinfo->name."&".SID."'>\n";
 609     echo "<input type='hidden' name='md' value='$md'>\n";
 610     echo "<input type='hidden' name='showid' value='$id'>\n";
 611     //echo "<input type='hidden' name='jsnewwindow' value='false'>\n";
 612  
 613     // for organizational purpose, define buttons here:
 614     // next and previous buttons
 615     if ($previousid)
 616        $previousbutton="<input type=\"button\" name=\"view_".$previousid."\" value=\"Previous\" onClick='MyWindow=window.open(\"general.php?tablename={$tableinfo->name}&amp;showid=$previousid&amp;jsnewwindow=true&amp;viewid=$viewid\",\"view\",\"scrollbars,resizable,toolbar,width=600,height=400\")'>\n";
 617     if ($nextid)
 618        $nextbutton="<input type=\"button\" name=\"view_".$nextid."\" value=\"Next\" onClick='MyWindow=window.open(\"general.php?tablename={$tableinfo->name}&amp;showid=$nextid&amp;jsnewwindow=true&amp;viewid=$viewid\",\"view\",\"scrollbars,resizable,toolbar,width=600,height=400\")'>\n";
 619     // closebutton
 620     $closebutton="<input type=\"button\" onclick='self.close();window.opener.focus();' name='Close' value='Close'>\n";
 621     if ($backbutton) {
 622        $backbutton="<input type='submit' name='submit' value='Back'>\n";
 623     }
 624     // modify button 
 625     if (may_write($db,$tableinfo->id,$id,$USER)) {
 626        $modifybutton= "<input type=\"submit\" name=\"mod_" . $id . "\" value=\"Modify\">\n";
 627     }
 628     // viewmenu:
 629     $viewmenu=viewmenu($db,$tableinfo,$viewid,false);
 630  
 631     // and now display the buttons
 632     echo "<table border=0 align='center' width='100%'>\n";
 633     if ($backbutton) {
 634        echo "<tr>\n<td align='left'>";
 635        echo " $previousbutton</td><td align='center'>$modifybutton $backbutton $viewmenu</td><td align='right'>$nextbutton </td>\n</tr>\n";
 636     }
 637     else
 638        echo "<tr><td align='left'>$previousbutton &nbsp;</td><td align='center'> $modifybutton $closebutton </td><td>$viewmenu</td><td align='right'>$nextbutton &nbsp;</td></tr>\n";
 639     echo "</table>\n\n";
 640     echo "</form>\n";
 641  }
 642  
 643  /**
 644   * *
 645   *  make a nice link to the record
 646   *
 647   */
 648  function make_link($id,$DBNAME) {
 649     global $PHP_SELF,$system_settings;
 650     echo "<tr><th>Link:</th><td colspan=7><a href='$PHP_SELF?tablename=$DBNAME&amp;showid=$id&amp;".SID;
 651     //echo "'>".$system_settings["baseURL"].getenv("SCRIPT_NAME")."?tablename=$DBNAME&showid=$id</a></td></tr>\n";
 652     echo "'>".$system_settings['baseURL'].$PHP_SELF."?tablename=$DBNAME&amp;showid=$id</a></td></tr>\n";
 653  }
 654  
 655  
 656  /**
 657   * *
 658   *   Make dropdown menu with available templates
 659   *
 660   * When one is chosen, open the formatted record in a new window
 661   */
 662  function show_reports($db,$tableinfo,$recordid=false,$viewid=false) {
 663     global $USER, $WRITE;
 664  
 665     $r=$db->Execute("SELECT id,label FROM reports WHERE tableid=".$tableinfo->id);
 666     if ($r) {
 667        if ($recordid) {
 668           $menu="<tr><th>Report:</th>\n";
 669           $menu.="<td><select name='reportlinks' onchange='linkmenu(this)'>\n";
 670           $url="target "."report.php?tablename=".$tableinfo->htmlname."&amp;recordid=$recordid";
 671       if ($viewid) {
 672          $url.="&amp;viewid=$viewid";
 673       }
 674       $url.='&amp;reportid';
 675           $menu.="<option value=''>---Reports---</option>\n";
 676           $menu.="<option value='$url-1'>xml</option>\n";
 677           $menu.="<option value='$url-2'>tab</option>\n";
 678           $menu.="<option value='$url-3'>csv</option>\n";
 679           while (!$r->EOF) {
 680              $url="target "."report.php?tablename=".$tableinfo->htmlname."&amp;reportid=".$r->fields["id"]."&amp;recordid=$recordid";
 681          if ($viewid)
 682             $url.="&amp;viewid=$viewid";
 683              $menu.="<option value='$url'>".$r->fields['label']."</option>\n";
 684              $r->MoveNext();
 685           }
 686           $menu.="</select>\n";
 687           $menu.="</td></tr>\n";
 688        } else { // for tableview reports
 689           $menu="<td>Report: \n";
 690           $menu.="<select name='reportlinks' onchange='linkmenu(this)'>\n";
 691           $menu.="<option value=''>---Reports---</option>\n";
 692           $url="target "."report.php?tablename=".$tableinfo->htmlname."&amp;tableview=true";
 693       if ($viewid) {
 694          $url.="&amp;viewid=$viewid";
 695       }
 696       $url.='&amp;reportid';
 697           $menu.="<option value='$url=-1'>xml</option>\n";
 698           $menu.="<option value='$url=-2'>text</option>\n";
 699           $menu.="<option value='$url=-3'>csv</option>\n";
 700           while (!$r->EOF) {
 701              $url="target "."report.php?tablename=".$tableinfo->htmlname."&amp;reportid=".$r->fields["id"]."&amp;tableview=true";
 702          if ($viewid) {
 703             $url.="&amp;viewid=$viewid";
 704          }
 705              $menu.="<option value='$url'>".$r->fields['label']."</option>\n";
 706              $r->MoveNext();
 707           }
 708           $menu.="</select>\n";
 709           // add radio buttons for output options:
 710           $menu.="Send to:\n";
 711           if (!(isset($USER['settings']['reportoutput'])) || $USER['settings']['reportoutput']==1)
 712               $checked='checked';
 713           $menu.="<input type='radio' name='reportoutput' $checked value='1' onClick='document.g_form.submit();'>screen\n";
 714           if ($USER['settings']['reportoutput']==2)
 715               $checked2='checked';
 716           $menu.="<input type='radio' name='reportoutput' $checked2 value='2' onClick='document.g_form.submit();'>file\n";
 717  
 718           if ($USER['permissions'] >= $WRITE) {
 719              $menu.= "<a href='editreports.php?tablename={$tableinfo->htmlname}'>Edit reports</a>\n";
 720           }
 721  
 722           $menu.="</td>\n";
 723        }
 724        echo $menu;
 725     }
 726  }
 727  
 728  /**
 729   * *
 730   *  display addition and modification form
 731   *
 732   */
 733  function display_add($db,$tableinfo,$Allfields,$id,$namein,$system_settings) { 
 734     global $PHP_SELF,$md,$max_menu_length,$USER,$LAYOUT,$_POST,$_SESSION;
 735     
 736     $dbstring=$PHP_SELF;$dbstring.="?";$dbstring.="tablename=".$tableinfo->name."&";
 737     echo "<form method='post' id='protocolform' enctype='multipart/form-data' name='subform' action='$dbstring";
 738      ?><?=SID?>'><?php
 739  
 740     if (!$magic)
 741        $magic=time();
 742     echo "<input type='hidden' name='magic' value='$magic'>\n";
 743     echo "<input type='hidden' name='md' value='$md'>\n";
 744     echo "<table border=0 align='center'>\n";   
 745     if ($id) {
 746        echo "<tr><td align='center'><h3>Modify ".$tableinfo->label." entry <i>$namein</i></h3>\n";
 747        echo "<input type='hidden' name='id' value='$id'></td></tr>\n";
 748     }
 749     else {
 750        echo "<tr><td align='center'><h3>New ".$tableinfo->label." entry</h3></td></tr>\n";
 751     }
 752     echo "<tr><td>\n<table border=0 align='center'>\n";
 753     
 754     foreach ($Allfields as $nowfield) {
 755        // give plugin a chance to modify data
 756        if (function_exists('plugin_display_add_pre'))
 757           plugin_display_add_pre($db,$tableinfo->id,$nowfield);
 758       
 759        // see if display_record is set
 760        if ( (($nowfield['display_record']=='Y') || ($nowfield['display_table']=='Y')) ) {
 761           // To persist between multiple invocation, grab POST vars 
 762           if ($nowfield['modifiable']=='Y' && isset($_POST[$nowfield['name']]) && $_POST[$nowfield['name']] && isset($_POST['submit'])) {
 763              $nowfield['values']=$_POST[$nowfield['name']];
 764              $nowfield['text']=$_POST[$nowfield['name']];
 765           }
 766           if ($nowfield['modifiable']!='Y' && $nowfield['datatype']!='sequence') {
 767              echo "<input type='hidden' name='$nowfield[name]' value='$nowfield[values]'>\n";
 768              if (function_exists('plugin_modify_seq')) {
 769                 $nowfield['text'] = plugin_modify_seq($db,$tableinfo->id,$nowfield);
 770              }
 771              if ($nowfield['text'] && $nowfield['text']!='' && $nowfield['text']!=' ') {
 772                 echo "<tr><th>{$nowfield['label']}:</th>"; 
 773                 echo "<td>{$nowfield['text']}";
 774              }
 775           } elseif ($nowfield['modifiable']=='Y' && ($nowfield['datatype']=='text' || $nowfield['datatype']=='int' || $nowfield['datatype']=='float' || $nowfield['datatype']=='date')) {
 776              echo "<tr><th>$nowfield[label]:"; 
 777              if ($nowfield['required']=='Y') {
 778                 echo "<sup style='color:red'>&nbsp;*</sup>";
 779              }
 780              echo "</th>\n";
 781              if ($nowfield['datatype']=='text') {
 782                 //$size=60;
 783                 // mike likes this to be a textlong field, let's try
 784                  echo "<td><textarea name='{$nowfield['name']}' rows='2'cols=80>{$nowfield['values']}</textarea>";
 785              }
 786              // for dates we have to dsiplay the test and not the value
 787              elseif ($nowfield['datatype']=='date') {
 788                 $size=10;
 789                  echo "<td><input type='text' name='{$nowfield['name']}' value='{$nowfield['text']}' size='$size'>";
 790              }
 791              else {
 792                 $size=10;
 793                  echo "<td><input type='text' name='{$nowfield['name']}' value='{$nowfield['values']}' size='$size'>";
 794              }
 795          } elseif ($nowfield['datatype']=='sequence') {
 796            if (!$nowfield['text']) {
 797               // find the highest sequence and return that plus one
 798               $rmax=$db->Execute("SELECT MAX($nowfield['name']}) AS $nowfield['name']} FROM ".$tableinfo->realname);
 799               $newseq=$rmax->fields[0]+1;
 800               if (function_exists('plugin_modify_seq')) {
 801                    $newseq = plugin_modify_seq($db,$tableinfo->id,$nowfield);
 802               }
 803            }
 804            else
 805               $newseq=$nowfield['text'];
 806                 echo "<input type='hidden' name='$nowfield[name]' value='$newseq'>\n";
 807                 echo "<tr><th>$nowfield[label]:"; 
 808                 if ($nowfield['required']=='Y') {
 809                    echo "<sup style='color:red'>&nbsp;*</sup>";
 810            }
 811            echo "</th>\n";
 812            if ($nowfield['modifiable']=='N') {
 813               echo "<td>$newseq";
 814            } else {
 815               echo "<td><input type='text' name='$nowfield[name]' value='$newseq' size='10'>";
 816            }
 817         } elseif ($nowfield['datatype']=='textlong') {
 818            echo "<tr><th>{$nowfield['label']}:";
 819            if ($nowfield['required']=='Y')  {
 820               echo "<sup style='color:red'>&nbsp;*</sup>";
 821            }
 822               echo "<td><textarea name='{$nowfield['name']}' rows='5' cols='80' value='{$nowfield['values']}'>{$nowfield['values']}</textarea>";
 823         } elseif ($nowfield['datatype']=='link') {
 824           echo "<tr><th>$nowfield[label] (http link):";
 825           if ($nowfield['required']=='Y') {
 826              echo "<sup style='color:red'>&nbsp;*</sup>";
 827           }
 828           echo "<td><input type='text' name='$nowfield[name]' value='$nowfield[values]' size='60'>";
 829        } elseif ($nowfield['datatype']=='pulldown') {
 830           // get previous value    
 831           $r=$db->Execute("SELECT typeshort,id FROM {$nowfield['ass_t']} ORDER BY sortkey,typeshort");
 832           if ($nowfield['datatype']=='pulldown')
 833              $text=$r->GetMenu2("$nowfield[name]",$nowfield['values'],true,false);
 834           else
 835              $text=$r->GetMenu2("$nowfield[name]",$nowfield['values'],true,true);
 836           echo "<tr><th>$nowfield[label]:";
 837           if ($nowfield['required']=='Y')
 838              echo"<sup style='color:red'>&nbsp;*</sup>";
 839           echo "</th>\n<td>";
 840           if ($USER['permissions'] & $LAYOUT) {
 841              $jscript=" onclick='MyWindow=window.open (\"general.php?tablename=".$tableinfo->name."&amp;edit_type=$nowfield[ass_t]&amp;jsnewwindow=true&amp;formname=subform&amp;selectname=$nowfield[name]".SID."\",\"type\",\"scrollbars,resizable,toolbar,status,width=700,height=500\");MyWindow.focus()'";
 842              echo "<input type='button' name='edit_button' value='Edit $nowfield[label]' $jscript><br>\n";
 843           }
 844           echo "$text<br>";
 845        } elseif ($nowfield['datatype']=='table') {
 846           // only display primary key here
 847           if (!$nowfield['ass_local_key']) { 
 848              // get previous value    
 849              $r=$db->Execute("SELECT COUNT(id) FROM {$nowfield['ass_table_name']}");
 850              if ($r->fields[0] > $max_menu_length) {
 851                 $text="<input type='hidden' name='max_{$nowfield['name']}' value='true'>\n";
 852                 $text.="<input type='text' name='{$nowfield['name']}' value='{$nowfield['nested']['values']}'>";
 853              } else {
 854                 $text=GetValuesMenu($db,$nowfield['name'],$nowfield['values'],$nowfield['ass_table_name'],$nowfield['ass_column_name'],false);
 855              }
 856              echo "<tr><th>$nowfield[label]:";
 857              if ($nowfield[required]=="Y")
 858                 echo"<sup style='color:red'>&nbsp;*</sup>";
 859              echo "</th>\n<td>$text<br>";
 860           }
 861        }
 862        if ($nowfield['datatype']=='textlarge') {
 863           echo "<tr><th>$nowfield[name]:";
 864           if ($nowfield['required']=='Y')
 865            echo"<sup style='color:red'>&nbsp;*</sup>";
 866            echo "</th><td colspan=6><textarea name='$nowfield[name]' rows='5' cols='100%'>$nowfield[values]</textarea>";
 867         }
 868         if ($nowfield['datatype']=='file' || $nowfield['datatype']=='image') {
 869            $files=get_files($db,$tableinfo->name,$id,$nowfield['columnid'],0,'big');
 870            echo '<tr>';
 871            echo "<th>$nowfield[label]:</th>\n";
 872            echo "</th>\n";
 873            echo '<td colspan=4> <table border=0>';
 874            for ($i=0;$i<sizeof($files);$i++)  {
 875               echo "<tr><td colspan=2>".$files[$i]['link'];
 876               echo "&nbsp;&nbsp;(<i>".$files[$i]['name']."</i>, ".$files[$i]['type']." file)</td>\n";
 877               echo "<td><input type='submit' name='def_".$files[$i]["id"]."' value='Delete' Onclick=\"if(confirm('Are you sure the file ".$files[$i]["name"]." should be removed?')){return true;}return false;\"></td></tr>\n";
 878            }
 879            echo '<tr><th>Upload '.$nowfield['datatype']."</th>\n";
 880             echo "<td>&nbsp;</td><td><input type='file' name='".$nowfield[name]."[]' value='$filename'></td>\n";
 881             echo "</tr></table><br>\n\n";
 882         }  elseif ($nowfield['datatype']=='mpulldown') {
 883             unset ($valueArray);
 884             // get previous value    
 885             $r=$db->Execute("SELECT typeshort,id FROM {$nowfield['ass_t']} ORDER BY sortkey,type");
 886             $rbv=$db->Execute("SELECT typeid FROM {$nowfield['key_t']} WHERE recordid=$id");
 887             while ($rbv && !$rbv->EOF) {
 888                $valueArray[]=$rbv->fields[0];
 889                $rbv->MoveNext();
 890             }
 891             $text=$r->GetMenu2($nowfield['name'].'[]',$valueArray,true,true);
 892             echo "<tr><th>{$nowfield['label']}:";
 893             if ($nowfield['required']=='Y')
 894                echo"<sup style='color:red'>&nbsp;*</sup>";
 895             echo "</th>\n<td>";
 896             if ($USER['permissions'] & $LAYOUT) {
 897                $jscript=" onclick='MyWindow=window.open (\"general.php?tablename=".$tableinfo->name."&edit_type=$nowfield[ass_t]&amp;jsnewwindow=true&amp;formname=subform&amp;selectname=$nowfield[name]".SID."\",\"type\",\"scrollbars,resizable,toolbar,status,width=700,height=500\");MyWindow.focus()'";
 898                echo "<input type='button' name='edit_button' value='Edit $nowfield[label]' $jscript><br>\n";
 899             }
 900             echo "$text<br>";
 901          }
 902       }
 903       if (function_exists('plugin_display_add'))
 904          plugin_display_add($db,$tableinfo->id,$nowfield);
 905     } // end of foreach ($Allfields)    
 906  
 907     echo "</table>\n</td>\n</tr>\n";
 908  
 909     /* Call to a function that runs at the end when adding a new record*/   
 910     if ((function_exists("plugin_display_add_post")) && (!($id))){
 911        plugin_display_add_post($db,$tableinfo->id);
 912     }
 913           
 914     echo '<tr><td colspan=4>';
 915     show_access($db,$tableinfo->id,$id,$USER,$system_settings);
 916     echo "</td></tr>\n"; echo "<tr>";
 917     if ($id) {
 918        $value="Modify Record"; 
 919     } else {
 920        $value="Add Record";
 921     }
 922  
 923     // submit and clear buttons
 924     echo "<td align='center'>\n";
 925     if ($_SESSION['javascript_enabled']) {
 926        echo "<input type='hidden' name='subm' value=''>\n";
 927        // echo "<input type='button' name='sub' value='$value' onclick='document.subform.subm.value=\"$value\"; document.subform.submit(); window.opener.document.g_form.search.value=\"Search\"; window.opener.document.g_form.submit(); window.opener.focus(); self.close();'>\n";
 928        echo "<input type='button' name='sub' value='$value' onclick='document.subform.subm.value=\"$value\"; document.subform.submit();'>\n";
 929        //echo "<input type='button' name='Close' onclick='self.close(); window.opener.focus();' value='Cancel'>\n";
 930        echo "<input type='button' name='Close' onclick='document.subform.submit();' value='Cancel'>\n";
 931     }
 932     else {
 933        echo "<input type='submit' name='submit' value='$value'>\n";
 934        echo "&nbsp;&nbsp;";
 935        echo "<input type='submit' name='submit' value='Cancel'></td>\n";
 936     }
 937     echo "</tr>\n</table>\n</form>\n";
 938  }
 939  
 940  
 941  /**
 942   * *
 943   *  Get all description table values out for a display
 944   *
 945   * Returns an array with lots of information on every column
 946   * If qfield is set, database values for that record will be returned as well
 947   */
 948  function getvalues($db,$tableinfo,$fields,$qfield=false,$field=false) 
 949  {
 950     global $system_settings;
 951  
 952     if ($qfield) {
 953        $r=$db->Execute("SELECT $fields FROM $tableinfo->realname WHERE $qfield=$field"); 
 954        if ($qfield=='id') {
 955           $id=$field;
 956        } else {
 957           $rid=$db->Execute("SELECT id FROM $tableinfo->realname WHERE $qfield=$field");
 958           $id=$rid->fields['id'];
 959        }
 960     }
 961  
 962     $columns=preg_split('/,/',$fields);
 963     $Allfields=array();
 964     foreach ($columns as $column) {
 965        if($column!='id') {
 966           if ($r)
 967              // Take slashes out that were put in to be able to enter stuff into the database
 968              ${$column}['values']= stripslashes($r->fields[$column]);
 969           $rb=$db->CacheExecute(2,"SELECT id,label,datatype,display_table,display_record,associated_table,key_table,associated_column,associated_local_key,required,link_first,link_last,modifiable FROM $tableinfo->desname WHERE columnname='$column'");
 970           ${$column}['name']=$column;
 971           ${$column}['columnid']=$rb->fields['id'];
 972           ${$column}['label']=$rb->fields['label'];
 973           ${$column}['datatype']=$rb->fields['datatype'];
 974           ${$column}['display_table']=$rb->fields['display_table'];
 975           ${$column}['display_record']=$rb->fields['display_record'];
 976           ${$column}['ass_t']=$rb->fields['associated_table'];
 977           ${$column}['key_t']=$rb->fields['key_table'];
 978           ${$column}['ass_column']=$rb->fields['associated_column'];
 979           ${$column}['ass_local_key']=$rb->fields['associated_local_key'];
 980           ${$column}['required']=$rb->fields['required'];
 981           ${$column}['modifiable']=$rb->fields['modifiable'];
 982           if ($rb->fields['datatype']=='table') {
 983              ${$column}['ass_table_desc_name']=get_cell($db,'tableoftables','table_desc_name','id',$rb->fields['associated_table']);
 984              ${$column}['ass_table_name']=get_cell($db,'tableoftables','real_tablename','id',$rb->fields['associated_table']);
 985              ${$column}['ass_column_name']=get_cell($db,${$column}['ass_table_desc_name'],'columnname','id',$rb->fields['associated_column']);
 986       }
 987           if ($id) {
 988              ${$column}['recordid']=$id;
 989  
 990              // datatype table (the toughest of all)
 991              if ($rb->fields['datatype']=='table') {
 992                 // if there is an associated local key, we'll need to get the actual value from there
 993                 if ($rb->fields['associated_local_key']) {
 994                    ${$column}['ass_local_column_name']=get_cell($db,$tableinfo->desname,'columnname','id',$rb->fields['associated_local_key']);
 995                    ${$column}['values']=get_cell($db,$tableinfo->realname,${$column}['ass_local_column_name'],'id',$id); 
 996                 }
 997                 $text=false;
 998                 $values=false;
 999                 // if there is a value, we'll dig into the associated table to find out what our associated value and text are
1000                 if (${$column}['values']) {
1001                    $asstableinfo=new tableinfo($db,${$column}['ass_table_name']);
1002                    // we always link to the id column of the associated table
1003                    $tmpvalue=getvalues($db,$asstableinfo,${$column}['ass_column_name'],'id',${$column}['values']);
1004                    if (is_array($tmpvalue[0])) {
1005                       if (isset($tmpvalue[0]['nested']))
1006                          ${$column}['nested']=$tmpvalue[0]['nested'];
1007                       else {
1008                          ${$column}['nested']['text']=$tmpvalue[0]['text']; 
1009                          ${$column}['nested']['values']=$tmpvalue[0]['values']; 
1010                          ${$column}['nested']['datatype']=$tmpvalue[0]['datatype']; 
1011                          ${$column}['nested']['fileids']=$tmpvalue[0]['fileids']; 
1012                          //the following are needed to get files and images right
1013                          ${$column}['nested']['nested_id']=$tmpvalue[0]['nested_id'];
1014                          ${$column}['nested']['nested_tbname']=$tmpvalue[0]['nested_tbname'];
1015                          ${$column}['nested']['nested_columnid']=$tmpvalue[0]['nested_columnid'];
1016                       }
1017                    }
1018                    else {
1019                       $text=$tmpvalue[0];
1020                       $values=$text;
1021                    }
1022                    ${$column}['link']="<a target=_ href=\"general.php?tablename={$asstableinfo->name}&amp;showid=".${$column}['values']."\">{${$column}['nested']['text']}</a>\n";
1023                 }
1024                 $text=${$column}['nested']['text'];
1025                 if (!$text)
1026                    $text="&nbsp;";
1027                 ${$column}['text']=$text;
1028              }
1029  
1030              // datatype link
1031              elseif ($rb->fields['datatype']=='link') {
1032                 if (${$column}['values'])
1033                    ${$column}['text']="<a href='".${$column}["values"]."' target='_blank'>link</a>";
1034              }
1035              // datatype pulldown
1036              elseif ($rb->fields['datatype']=='pulldown') {
1037                 ${$column}['text']=get_cell($db,${$column}['ass_t'],'type','id',${$column}['values']); 
1038              }
1039              // datatype mpulldown
1040              elseif ($rb->fields['datatype']=='mpulldown') {
1041                 unset($rasst);
1042                 unset($rasst2);
1043                 unset ($typeids);
1044                 $rasst=$db->Execute("SELECT typeid FROM {${$column}['key_t']} WHERE recordid='$id'");
1045                 while ($rasst && !$rasst->EOF){
1046                    $typeids.=$rasst->fields[0].',';
1047                    $rasst->MoveNext();
1048                 }
1049                 if ($typeids){
1050                    $typeids=substr($typeids,0,-1);
1051                    $rasst2=$db->Execute("SELECT type from {${$column}['ass_t']} where id IN ($typeids) ORDER BY sortkey");
1052                    while ($rasst2 && !$rasst2->EOF) {
1053                       ${$column}['text'].=$rasst2->fields[0].'<br>'; 
1054                       $rasst2->MoveNext();
1055                    }
1056                 }
1057              }
1058              // datatype textlong
1059              elseif ($rb->fields['datatype']=='textlong') {
1060                 if (${$column}['values']=='') {
1061                    ${$column}['text']='';
1062                 }
1063                 else {
1064                    if ($_SESSION['javascript_enabled']) {
1065                       // with javascript the tooltip stuff will take care of long text fields
1066                       ${$column}['text']=${$column}['values'];
1067                    } else {
1068                       ${$column}['text']="<input type=\"button\" name=\"view_$id\" value=\"View\" onclick='MyWIndow=window.open(\"general.php?tablename={$tableinfo->name}&amp;showid=$id&amp;jsnewwindow=true\",\"view\",\"scrollbars,resizable,width=600,height=400\")'>\n";
1069                    }
1070                 }
1071              }
1072              // datatypes file and image
1073              elseif ($rb->fields['datatype']=='file' || $rb->fields['datatype']=='image') {
1074                 $tbname=get_cell($db,'tableoftables','tablename','id',$tableinfo->id);
1075                 // we can get naming conflicts here. Use a really weird name
1076                 $fzsk=get_files($db,$tbname,$id,${$column}['columnid'],3);
1077                 if ($fzsk) {
1078                    ${$column}['nested_id']=$id;
1079                    ${$column}['nested_tbname']=$tbname;
1080                    ${$column}['nested_columnid']=${$column}['columnid'];
1081                    for ($i=0;$i<sizeof($fzsk);$i++) {
1082                       ${$column}['text'].=$fzsk[$i]['link'];
1083                       ${$column}['fileids'][]=$fzsk[$i]['id'];
1084                    }
1085                 }
1086              }
1087              elseif ($rb->fields['datatype']=='user') {
1088                 $rname=$db->Execute("SELECT firstname,lastname,email FROM users WHERE id=".${$column}["values"]);
1089                 if ($rname && $rname->fields) {
1090                    if ($rname->fields['email'])
1091                       ${$column}['text']="<a href='mailto:".$rname->fields['email']."'>".$rname->fields['firstname']." ".$rname->fields['lastname']."</a>\n";
1092                    else
1093                       ${$column}['text']=$rname->fields['firstname']." ".$rname->fields['lastname']."\n";
1094                 }
1095              }
1096              elseif ($rb->fields['datatype']=='date' && ${$column}['values']>0) {
1097                 $dateformat=get_cell($db,'dateformats','dateformat','id',$system_settings['dateformat']);
1098                 ${$column}['text']=date($dateformat,${$column}['values']);
1099              }
1100              else
1101                 ${$column}['text']=${$column}['values'];
1102  
1103              if ($rb->fields['link_first'] && ${$column}['values']) {
1104                 ${$column}['text']="<a href='".$rb->fields['link_first'].${$column}['text'].$rb->fields['link_last']."'>".${$column}['text']."</a>\n";
1105              }
1106   
1107              if (! isset(${$column}['text']) || strlen(${$column}['text'])<1 )
1108                 ${$column}['text']='&nbsp;';
1109           }
1110        }
1111        $Allfields[]= ${$column};
1112        //$Allfields[${$column}['name']]=${$column};
1113     }
1114     if (function_exists("plugin_getvalues")) {
1115        plugin_getvalues($db,$Allfields,$id,$tableinfo->id);
1116     }
1117     return $Allfields;
1118  }
1119  
1120  
1121  /**
1122   * *  general functions
1123   */
1124  /****************************FUNCTIONS***************************/
1125  /**
1126   *  Checks input data before they are entered in the database
1127   *
1128   * returns false if something can not be fixed     
1129   */
1130  function check_g_data ($db,&$field_values,$tableinfo,$modify=false) {
1131     global $max_menu_length, $system_settings;
1132  
1133     // make sure all the required fields are there 
1134     $rs = $db->Execute("SELECT columnname,datatype,label FROM {$tableinfo->desname} where required='Y' and (datatype != 'file')");
1135     while (!$rs->EOF) {
1136        $fieldA=$rs->fields[0];
1137        if (!$field_values["$fieldA"]) {
1138           echo "<h3 color='red' align='middle'>Please enter all fields marked with a <sup style='color:red'>&nbsp;*</sup>. Currently, a value for field: <i>{$rs->fields[2]}</i> is missing.</h3>";
1139       return false;
1140        }
1141        $rs->MoveNext();
1142     }
1143  
1144     // make sure ints and floats are correct, try to set the UNIX date
1145     $rs = $db->Execute("SELECT columnname,datatype,label,associated_table,associated_column FROM {$tableinfo->desname} WHERE datatype IN ('int','float','table','date','sequence', 'textlong')");
1146     while ($rs && !$rs->EOF) {
1147        $fieldA=$rs->fields[0];
1148        if (isset($field_values["$fieldA"]) && (strlen($field_values[$fieldA]) >0)) {
1149           if ($rs->fields[1]=='int') {
1150              if ($field_values[$fieldA]==' ')
1151                 $field_values[$fieldA]='';
1152              else
1153                 $field_values[$fieldA]=(int)$field_values[$fieldA];
1154           }
1155           elseif ($rs->fields[1]=='float') {
1156              if ($field_values[$fieldA]==' ')
1157                 $field_values[$fieldA]='';
1158              else
1159                 $field_values[$fieldA]=(float)$field_values[$fieldA];
1160           }
1161           elseif ($rs->fields[1]=='table') {
1162               $field_values[$fieldA]=(int)$field_values[$fieldA];
1163           }
1164           elseif ($rs->fields[1]=='date') {
1165              if ($system_settings['dateformat']<3) {
1166                 // we have a US date, change dashes to slashes
1167                 $field_values[$fieldA]=strtr($field_values[$fieldA],'-','/');
1168              }
1169              $field_values[$fieldA]=strtotime($field_values[$fieldA]);
1170              if ($field_values[$fieldA] < 0)
1171                 $field_values[$fieldA]="";
1172           }
1173           // Firefox on the Mac has issues with very long words
1174           // cut off words at 80 characters and insert a line break
1175           elseif ($rs->fields[1]=='textlong') {
1176               $longtxts = explode(' ',$field_values[$fieldA]);
1177               unset($field_values[$fieldA]);
1178               foreach ($longtxts  as $longtxt) {
1179                  $field_values[$fieldA].=wordwrap($longtxt, 80, ' ',1) . ' ';
1180               }
1181           }
1182           elseif ($rs->fields[1]=='sequence') {
1183              $field_values[$fieldA]=(int)$field_values[$fieldA];
1184          if ($field_values[$fieldA]<1)
1185             unset($field_values[$fieldA]);
1186              // for new additions, check if this number was given out before:
1187          if (!$modify) {
1188                 if (get_cell($db,$tableinfo->realname,$rs->fields[0],$rs->fields[0],$field_values[$fieldA])) {
1189                    $rmax=$db->Execute("SELECT max({$rs->fields[0]}) FROM {$tableinfo->realname}");
1190                    if ($rmax->fields[0])
1191                       $nextmax=$rmax->fields[0]+1;
1192                    echo "<h3 color='red' align='middle'>The number <i>{$field_values[$fieldA]}</i> has already been used in field <i>{$rs->fields[2]}</i>. ";
1193                    if ($nextmax) {
1194                       echo "Try <i>$nextmax</i> instead.";
1195                       $field_values[$fieldA]=$nextmax;
1196                    }
1197                    echo "</h3>\n";
1198                return false;
1199             }
1200              }
1201           }   
1202  
1203        }
1204        $rs->MoveNext();
1205     }
1206  
1207     // Hooray, the first call to a plugin function!!
1208     if (function_exists('plugin_check_data')) {
1209        if (!plugin_check_data($db,$field_values,$tableinfo->desname,$modify))
1210           return false;
1211     }
1212  
1213     return true;
1214  }
1215  
1216  /**
1217   * Go through the comma-separated list $Fieldscomma, and retrun an array ($fields) with every field that needs a value set to a default
1218   *
1219   * 
1220   */
1221  function set_default($db,$tableinfo,$Fieldscomma,$USER,$system_settings) {
1222     if (!may_write($db,$tableinfo->id,false,$USER)) {
1223        return false;
1224     }
1225     $Allfields=getvalues($db,$tableinfo,$Fieldscomma);
1226     foreach ($Allfields as $nowfield) {
1227        // give plugin a chance to modify data
1228        if (function_exists('plugin_display_add_pre')) {
1229           plugin_display_add_pre($db,$tableinfo->id,$nowfield);
1230        }
1231        // For sequences, provide the next available number
1232        if ($nowfield['datatype']=='sequence') {
1233           $rmax=$db->Execute("SELECT MAX($nowfield['name']}) AS $nowfield['name']} FROM ".$tableinfo->realname);
1234           $fields[$nowfield['name']]=$rmax->fields[0]+1;
1235           if (function_exists('plugin_modify_seq')) {
1236              $fields[$nowfield['name']] = plugin_modify_seq($db,$tableinfo->id,$nowfield);
1237           }
1238        } elseif (in_array($nowfield['name'], array('gr','gw','er','ew'))) {
1239           $fields[$nowfield['name']]=get_access(false,$nowfield['name']);
1240        } else {
1241           // here we pick up values we got from the plugin code
1242           $fields[$nowfield['name']]=$nowfield['values'];
1243        }
1244  
1245        // For required fields, we simply enter the field name, or 0 for numerics
1246        if ($nowfield['required']=='Y' && !isset($nowfield['values'])) {
1247        
1248           if ($nowfield['datatype']=='text' || $nowfield['datatype']=='textlong') {
1249              $fields[$nowfield['name']]=$nowfield['label'];
1250           } elseif ($nowfield['datatype']=='int' || $nowfield['datatype']=='float') {
1251              $fields[$nowfield['name']]=0;
1252           } elseif ($nowfield['datatype']=='date') {
1253              // assign current date
1254          $fields[$nowfield['name']]=time();
1255           } elseif ($nowfield['datatype']=='link') {
1256              $fields[$nowfield['name']]=$nowfield['label'];
1257           } elseif ($nowfield['datatype']=='pulldown') {
1258              $fields[$nowfield['name']]=0;
1259           } elseif ($nowfield['datatype']=='table') {
1260              $fields[$nowfield['name']]=0;
1261       } if ($nowfield['datatype']=='file' || $nowfield['datatype']=='image') {
1262              $fields[$nowfield['name']]=0;
1263           } elseif ($nowfield['datatype']=='mpulldown') {
1264              $fields[$nowfield['name']]=0;
1265           }
1266        }
1267     }
1268     return ($fields);
1269  }
1270  
1271  
1272  /**
1273   *  Prints a form with addition stuff
1274   *
1275   * $fields is a comma-delimited string with column names
1276   * $field_values is hash with column names as keys
1277   * $id=0 for a new entry, otherwise it is the id
1278   */
1279  function add_g_form ($db,$tableinfo,$field_values,$id,$USER,$PHP_SELF,$system_settings) {
1280     if (!may_write($db,$tableinfo->id,$id,$USER)) 
1281        return false; 
1282     if ($id) {
1283      $Allfields=getvalues($db,$tableinfo,$tableinfo->fields,id,$id);
1284      $namein=get_cell($db,$tableinfo->desname,"title","id",$id);        
1285      display_add($db,$tableinfo,$Allfields,$id,$namein,$system_settings);
1286     }    
1287     else {
1288      $Allfields=getvalues($db,$tableinfo,$tableinfo->fields);
1289      display_add($db,$tableinfo,$Allfields,$id,"",$system_settings);
1290     }
1291  }
1292  
1293  /**
1294   *  Shows a page with nice information on the record
1295   *
1296   */
1297  function show_g($db,$tableinfo,$id,$USER,$system_settings,$backbutton=true,$previousid=false,$nextid=false,$viewid=false)  {
1298     if (!may_read($db,$tableinfo,$id,$USER))
1299         return false;
1300     $Allfields=getvalues($db,$tableinfo,$tableinfo->fields,id,$id);
1301     display_record($db,$Allfields,$id,$tableinfo,$backbutton,$previousid,$nextid,$viewid);
1302  }
1303      
1304  /**
1305   *  Tries to convert a MsWord file into html 
1306   *
1307   * It calls wvHtml.  
1308   * When succesfull, the file is added to the database
1309   * Returns id of uploaded file
1310   */
1311  function process_file($db,$fileid,$system_settings) {
1312     global $_FILES,$_POST;
1313     $mimetype=get_cell($db,'files','mime','id',$fileid);
1314     if (!strstr($mimetype,'html')) {
1315        $word2html=$system_settings['word2html'];
1316        $wv_version=$system_settings['wvHtml_version'];
1317        $filepath=file_path($db,$fileid);
1318        if (!$filepath)
1319           return false;
1320        if ($wv_version<0.7) {
1321           $temp=$system_settings["tmpdir"]."/".uniqid("file");
1322           $command= "$word2html $filepath $temp";
1323           $result=exec($command);
1324        }
1325        // version of wvHtml >= 0.7 have to be called differently:
1326        //if (@is_readable($temp) || @filesize($temp) < 1) {
1327        else {
1328           $converted_file=uniqid("file");
1329           $command="$word2html --targetdir=".$system_settings["tmpdir"]." \"$filepath\" $converted_file";
1330           $result=exec($command);
1331       $temp=$system_settings["tmpdir"]."/".$converted_file;
1332        } 
1333        if (@is_readable($temp) && filesize($temp)) {
1334           // we now know this was an MSword file, so lets make sure the mime type is OK
1335           $db->query("UPDATE files SET mime='application/msword',type='msword' WHERE id=$fileid");
1336           unset ($_FILES);
1337           $r=$db->query ("SELECT filename,mime,title,tablesfk,ftableid,ftablecolumnid FROM files WHERE id=$fileid");
1338           if ($r && !$r->EOF) {
1339              $filename=$r->fields("filename");
1340              // change .doc to .html in a lousy way
1341              $filename=str_replace(".doc",".htm",$filename); 
1342              $mime="text/html";
1343              $type=substr(strrchr($mime,"/"),1);
1344              $size=filesize($temp);
1345              $id=$db->GenID("files_id_seq");
1346              $query="INSERT INTO files (id,filename,mime,size,title,tablesfk,ftableid,ftablecolumnid,type) VALUES ($id,'$filename','$mime','$size','".$r->fields("title")."','".$r->fields("tablesfk")."','".$r->fields("ftableid")."','".$r->fields("ftablecolumnid")."','$type')";
1347             if ($db->execute($query)) {
1348                  $newloc=file_path($db,$id);
1349                 `mv $temp '$newloc'`;
1350                  return $id;
1351              }
1352              else
1353                 unlink($temp); 
1354           }    
1355        }
1356        else
1357           @unlink($temp);
1358     }
1359     return false;
1360  }
1361  
1362  
1363  /**
1364   *  Indexes the content of the given file
1365   *
1366   * The file is converted to a text file (pdfs with ghost script,
1367   * word files were already converted to html,html characters are stripped),
1368   * all words are lowercased, it is checked whether an entry in the table words
1369   * already exists, if not, it is added.  A relation to the word is made in 
1370   * the table associated with the given column
1371   */
1372  function indexfile ($db,$tableinfo,$indextable,$recordid,$fileid,$htmlfileid) 
1373  {
1374     return false;
1375     if (!$indextable)
1376        return false;
1377     // if the html file exists, we'll work with that one
1378     if ($htmlfileid) {
1379        $fp=fopen(file_path($db,$htmlfileid),"r");
1380        if ($fp) {
1381           while (!feof($fp)) {
1382              $filetext.=fgetss($fp,64000);
1383           }
1384           fclose($fp);
1385        }
1386        $filetext=strtolower($filetext);
1387        doindexfile ($db,$filetext,$htmlfileid,$indextable,$recordid,$pagenr);
1388     }
1389  }
1390  
1391  /**
1392   *  Searches (nested) for a match with $value 
1393   *
1394   * returns the id of the record in the associated value by searching recursively
1395   * that can be used in a SQL search
1396   */
1397  function find_nested_match($db,$tableinfo,$field,$value,$first=true) {
1398     $info=getvalues($db,$tableinfo,$field);
1399  
1400     if ($info[0]['datatype']=='table') {
1401        $ass_tableinfo=new tableinfo($db,$info[0]['ass_table_name']);
1402        $value=find_nested_match($db,$ass_tableinfo,$info[0]['ass_column_name'],$value,false);
1403     } elseif ($info[0]['datatype']=='int') {
1404        $value= trim($value);
1405        // I am getting desperate, but the browser inserts junk in the first postions, test if it is a number, if not, delete it. 
1406        if (!is_numeric($value{0})) {
1407           $value=substr($value,1);
1408        }
1409        return get_cell($db,$tableinfo->realname,'id',$field,(int) $value);
1410     } elseif ($info[0]['datatype']=='float') {
1411        $value= trim($value);
1412        if (!is_numeric($value{0})) {
1413           $value=substr($value,1);
1414        }
1415        return get_cell($db,$tableinfo->realname,'id',$field,(float) $value);
1416     } elseif ($info[0]['datatype']=='pulldown') {
1417        $value=get_cell($db,$info[0]['ass_t'],'id','typeshort',$value);
1418        return get_cell($db,$tableinfo->realname,'id',$field,$value);
1419     }
1420     elseif (!$first) {
1421        return get_cell($db,$tableinfo->realname,'id',$field,$value);
1422     }
1423     return $value;
1424  }
1425  ?>

title

Description

title

Description

title

Description

title

title

Body