+<?
+
+/************************************************************************
+$Id: functions.inc,v 1.1 2006/04/28 19:13:29 cscott Exp $
+ Gaslight Media Standard Function Library
+
+ Copyright (c) 2000-2004 by Gaslight Media Inc.
+
+ FILE: functions.inc
+ VERSION: 1.3
+
+ ---------------------------------------------------------
+ SEE functions_docs.txt FOR INFORMATION ON THESE FUNCTIONS
+ ---------------------------------------------------------
+
+
+************************************************************************/
+
+/*******LANGUAGE INIT*******/
+/*
+CREATE FUNCTION plpgsql_call_handler() RETURNS language_handler AS
+ '$libdir/plpgsql' LANGUAGE C;
+CREATE TRUSTED PROCEDURAL LANGUAGE plpgsql
+ HANDLER plpgsql_call_handler;
+*/
+
+
+ // Indicate that functions.inc is loaded
+
+define( "FUNCTIONS_LOADED", true );
+
+/***********************************************************************
+* *
+* DEBUG FUNCTIONS *
+* *
+***********************************************************************/
+
+ // Display E-Mail if debug level > 0
+
+function debug_mail( $to, $subject, $message, $headers = '', $parameters = '' )
+ {
+
+ if( SI_DEBUG_MAIL )
+ {
+ echo '<p>
+ <table border="1">
+ <tr><th align="center">MAIL DEBUG</th></tr>
+ <tr><td align="left"> Recipient(s): '.$to.'</td></tr>
+ <tr><td align="left"> Subject: '.$subject.'</td></tr>
+ <tr><td align="left"> Headers:<br><pre>'.$headers.'</pre></td></tr>
+ <tr><td align="left"> Parameters:<br><pre>'.$parameters.'</pre></td></tr>
+ <tr><td align="left"> <pre>'.$message.'</pre></td></tr>
+ </table>
+ <p>
+ ';
+ return( true );
+ }
+ else
+ return( mail( $to, $subject, $message, $headers, $parameters ) );
+
+ }
+
+
+/***********************************************************************
+* *
+* FUNCTIONS FROM SETUP.PHP *
+* *
+***********************************************************************/
+
+function cp1252_to_utf8($str)
+ {
+ global $cp1252_map;
+ return strtr(utf8_encode($str), $cp1252_map);
+ }
+
+/***********************************************************************
+* *
+* GENERAL FUNCTIONS *
+* *
+***********************************************************************/
+
+ // Check for a valid credit card number doing Luhn check
+
+function CreditVal( $Num, $Name = '', $Accepted='' )
+ {
+ $GoodCard = 1;
+ $Num = ereg_replace("[^[:digit:]]", "", $Num);
+ switch ($Name)
+ {
+ case "mastercard" :
+ $GoodCard = ereg("^5[1-5].{14}$", $Num);
+ break;
+
+ case "visa" :
+ $GoodCard = ereg("^4.{15}$|^4.{12}$", $Num);
+ break;
+
+ case "americanexpress" :
+ $GoodCard = ereg("^3[47].{13}$", $Num);
+ break;
+
+ case "discover" :
+ $GoodCard = ereg("^6011.{12}$", $Num);
+ break;
+
+ case "dinnerscard" :
+ $GoodCard = ereg("^30[0-5].{11}$|^3[68].{12}$", $Num);
+ break;
+
+ default:
+ if( ereg("^5[1-5].{14}$", $Num) ) $Name = "mastercard";
+ elseif( ereg("^4.{15}$|^4.{12}$", $Num) ) $Name = "visa";
+ elseif( ereg("^3[47].{13}$", $Num) ) $Name = "americanexpress";
+ elseif( ereg("^6011.{12}$", $Num) ) $Name = "discover";
+ elseif( ereg("^30[0-5].{11}$|^3[68].{12}$", $Num) ) $Name="dinerscard";
+ break;
+ }
+
+ // If there's a limit on card types we accept, check for it here.
+
+ if( $Accepted )
+ {
+ $type_verified = FALSE;
+ $brands = explode_trim( ",", $Accepted );
+ foreach( $brands as $brand )
+ if( $Name == $brand )
+ $type_verified = TRUE;
+
+ if( !$type_verified ) return(FALSE);
+ }
+
+ $Num = strrev($Num);
+ $Total = 0;
+
+ for ($x=0; $x<strlen($Num); $x++)
+ {
+ $digit = substr($Num,$x,1);
+ if ($x/2 != floor($x/2))
+ {
+ $digit *= 2;
+ if (strlen($digit) == 2)
+ $digit = substr($digit,0,1) + substr($digit,1,1);
+ }
+ $Total += $digit;
+ }
+ if( $GoodCard && $Total % 10 == 0 )
+ return( true );
+ else
+ return( false );
+}
+
+ // Alternative strong credit card check function.
+ // NOTE: The $si_cc_verify stuff SHOULD be passed rather than use a global to avoid issues with changes in the global values
+
+function credit_card_check( $Num, $accepted = SI_CC_ACCEPTS )
+{
+ global $si_cc_verify;
+
+ $Num = ereg_replace("[^[:digit:]]", "", $Num);
+
+ // Check for Accepted Card List
+
+ if( !is_int($accepted) || $accepted == 0 )
+ {
+ echo "<P>ERROR: credit_card_check() requires SI_CC_ACCCEPTS parameter!<P>";
+ exit;
+ }
+
+ // Permit secret test code
+
+ if( $Num == "0011001100110011" )
+ return( "Test" );
+ else
+ {
+ // Check each selected card type for a pattern match
+ $Name = "";
+ reset( $si_cc_verify );
+ $i = 0;
+ while( list($k, $v) = each($si_cc_verify) )
+ if( ( $accepted & pow(2,$i++) ) && ereg( $v, $Num ) )
+ {
+ $Name = $k;
+ break;
+ }
+ }
+
+ // Fail if nothing matched
+
+ if( $Name == "" )
+ return( FALSE );
+
+ // Now do strong test
+
+ $Num = strrev($Num);
+
+ $Total = 0;
+
+ for ($x=0; $x<strlen($Num); $x++)
+ {
+ $digit = substr($Num,$x,1);
+ if ($x/2 != floor($x/2))
+ {
+ $digit *= 2;
+ if (strlen($digit) == 2)
+ $digit = substr($digit,0,1) + substr($digit,1,1);
+ }
+ $Total += $digit;
+ }
+
+ if( $Total % 10 == 0 )
+ return( $Name );
+ else
+ return( FALSE );
+
+}
+
+/***********************************************************************
+* *
+* GEOGRAPHIC FUNCTIONS *
+* *
+***********************************************************************/
+
+
+ // Calculate the distance between a pair of lat/lon coordinates.
+
+function geo_distance( $lat1, $lon1, $lat2, $lon2, $units = 'Miles' )
+{
+
+ $d = 3963.0 * acos( sin($lat1/57.2958) * sin($lat2/57.2958) + cos($lat1/57.2958) * cos($lat2/57.2958) * cos($lon2/57.2958 -$lon1/57.2958) );
+
+ switch( $units )
+ {
+
+ // Add units conversions here
+
+ case "Inches":
+ $d = $d * 5280 * 12;
+ break;
+
+ case "Feet":
+ $d = $d * 5280;
+ break;
+
+ case "Yards":
+ $d = $d * ( 5280 / 3 );
+ break;
+
+ case "Miles":
+ default:
+ // This is the default calculated above
+ break;
+
+ case "Nautical Miles":
+ $d = $d / 1.15078;
+ break;
+
+ case "Meters":
+ $d = $d * 1609.344;
+ break;
+
+ case "Kilometers":
+ $d = $d * 1.609344;
+ break;
+
+ }
+
+ return( $d );
+}
+
+/***********************************************************************
+* *
+* DATABASE ABSTRACTION FUNCTIONS *
+* *
+***********************************************************************/
+
+ // Create a connection to database specified $conn_str,
+
+function db_connect( $conn_str, $fail_mode )
+{
+
+ static $last_connect = '';
+ static $ret = 0;
+
+ // If we're using static connections, check to see if this is trying to open the same connection again
+
+ if( SI_DB_STATIC )
+ {
+
+ // Check to see if this is trying to open the same connection again
+
+ if( $last_connect == $conn_str )
+ {
+ // If so just use the current connection
+
+ if( SI_DEBUG >= 3 ) echo "<PRE>db_connect() - Using existing connection - \$conn_str = ".$conn_str."</PRE><BR>";
+ return( $ret );
+ }
+
+ // If we need to open a different connection, close the current one first
+
+ if( $ret != 0 )
+ db_close( $ret );
+
+ $last_connect = $conn_str;
+
+ }
+
+ if( SI_DEBUG >= 3 ) echo "<PRE>db_connect()[".__LINE__."]: \$conn_str = ".$conn_str."</PRE><BR>";
+
+ switch( SI_DB_TYPE )
+ {
+ case "postgres":
+ $ret = pg_connect( $conn_str );
+ break;
+ default:
+ return( 0 );
+ }
+
+ if( !$ret && $fail_mode )
+ html_error( DB_ERROR_MSG, 1 );
+
+ return( $ret );
+
+}
+
+ // Close the connection to database specified by the handle dbd
+
+function db_close( $dbd )
+{
+
+ // IF we're using static connections, don't actually close it
+
+ if( SI_DB_STATIC == TRUE )
+ return( TRUE );
+
+ switch( SI_DB_TYPE )
+ {
+ case "postgres":
+ $ret = pg_close( $dbd );
+ break;
+ default:
+ return( 0 );
+ }
+
+ return( $ret );
+}
+
+ // Create a persistant connection to database specified in $conn_str
+
+function db_pconnect( $conn_str )
+{
+
+ if( SI_DEBUG >= 3 ) echo "<PRE>db_cponnect()[".__LINE__."]: \$conn_str = ".$conn_str."</PRE><BR>";
+
+ switch( SI_DB_TYPE )
+ {
+ case "postgres":
+ $ret = pg_pconnect( $conn_str );
+ break;
+ default:
+ return( 0 );
+ }
+
+ return( $ret );
+}
+
+
+ // Execute an SQL query
+
+function db_exec( $dbd, $qs )
+{
+
+ if( SI_DEBUG >= 3 ) echo "<PRE>db_exec()[".__LINE__."]: \$qs = ".$qs."</PRE><BR>";
+
+ switch( SI_DB_TYPE )
+ {
+ case "postgres":
+ $ret = pg_exec( $dbd, $qs );
+ break;
+
+ default:
+ return( 0 );
+ }
+
+ return( $ret );
+}
+
+ // Get data and store in associative indices, using the field names as keys.
+
+function db_fetch_row( $res, $i )
+{
+
+ if( SI_DEBUG >= 3 ) echo "<PRE>db_fetch()[".__LINE__."]: Row = ".$i."</PRE><BR>";
+
+ if( db_numrows($res) == 0 )
+ return( FALSE );
+
+ switch( SI_DB_TYPE )
+ {
+ case "postgres":
+ $row = pg_fetch_array( $res, $i, PGSQL_ASSOC );
+ break;
+
+ default:
+ return( FALSE );
+ }
+
+ return( $row );
+
+}
+
+ // Free result memory.
+
+function db_freeresult( $res )
+{
+
+ switch( SI_DB_TYPE )
+ {
+ case "postgres":
+ $ret = pg_freeresult( $res );
+ break;
+
+ default:
+ return( 0 );
+ }
+
+ return( $ret );
+}
+
+ // Determine number of rows in a result index
+
+function db_numrows( $res )
+{
+
+ switch( SI_DB_TYPE )
+ {
+ case "postgres":
+ $ret = pg_numrows( $res );
+ break;
+
+ default:
+ return( -1 );
+ }
+
+ return( $ret );
+}
+
+ // Additional Database functions from setup.php - Don't use for new code
+
+function db_fetch_array($res, $i, $type)
+{
+
+ switch (DB_TYPE)
+ {
+ case "postgres":
+ $row = pg_fetch_array($res, $i, $type);
+ break;
+
+ default:
+ return(0);
+ }
+
+ return($row);
+}
+
+function db_auto_array($qs, $i, $type)
+{
+
+ $dbd = db_connect();
+ if(!$dbd)
+ {
+ return(0);
+ }
+ $res = db_exec($dbd, $qs);
+ if(!$res)
+ {
+ return(0);
+ }
+
+ $row = db_fetch_array($res, $i, $type);
+
+ if(!db_freeresult($res))
+ {
+ return(0);
+ }
+
+ db_close($dbd);
+ return($row);
+}
+
+/***********************************************************************
+ *
+ * BEGIN Auto functions
+ *
+ ***********************************************************************/
+
+ // Retrieve a result as an array based soley on a query
+
+function db_auto_get_row( $qs, $i = 0, $conn_str = SI_CONN_STR, $fail_mode = 'FALSE' )
+{
+
+ if( SI_DEBUG >= 2 ) echo "<PRE>db_auto_get_row()[".__LINE__."]: \$qs = $qs, Row = $i</PRE><BR>";
+
+ if( !($dbd = db_connect( $conn_str, $fail_mode )) )
+ return( FALSE );
+
+ if( ($res = db_exec($dbd, SI_DB_SET_DATE_STYLE_STRING.$qs)) )
+ {
+ $row = db_fetch_row( $res, $i );
+ db_freeresult( $res );
+ }
+
+ db_close( $dbd );
+ return( $row );
+}
+
+
+ // Retrieve a set of results based soley on a query
+
+function db_auto_get_data( $qs, $conn_str = SI_CONN_STR, $fail_mode = FALSE, $rows = 500, $start = 0 )
+{
+
+ if( SI_DEBUG >= 2 ) echo "<PRE>db_auto_get_data()[".__LINE__."]: \$qs = $qs, \$rows = $rows, \$start = $start</PRE><BR>";
+
+ if( !($dbd = db_connect( $conn_str, $fail_mode)) )
+ return( FALSE );
+
+ if( ($res = db_exec($dbd, SI_DB_SET_DATE_STYLE_STRING.$qs)) )
+ {
+ $totalrows = pg_NumRows( $res );
+ $stop = $start + $rows;
+ if( $stop > $totalrows )
+ $stop = $totalrows;
+
+ for( $i=$start ; $i<$stop ; $i++ )
+ {
+ $data["$i|$totalrows"] = db_fetch_row( $res, $i );
+ }
+ }
+ db_close( $dbd );
+
+ return( $data );
+}
+
+ // Execute a query.
+
+function db_auto_exec( $qs, $conn_str = SI_CONN_STR, $fail_mode = 'FALSE' )
+{
+
+ if( SI_DEBUG >= 2 ) echo "<PRE>db_auto_exec()[".__LINE__."]: \$qs = $qs, \$conn_str = $conn_str</PRE><BR>";
+
+ $dbd = db_connect( $conn_str, $fail_mode );
+ if( !$dbd )
+ return( 0 );
+
+ if( !( $result = db_exec($dbd, $qs)) )
+ {
+ db_close( $dbd );
+ return( 0 );
+ }
+ else
+ {
+ $oid = pg_getlastoid( $result );
+ db_close( $dbd );
+ if( empty($oid) || $oid == -1 )
+ return( 1 );
+ else
+ return( $oid );
+ }
+}
+
+ // Get information on database fields
+
+function db_data_fields( $conn_str, $table )
+{
+ $dbd = db_connect( $conn_str, FALSE );
+ if( !$dbd )
+ return( 0 );
+
+ $qs = "SELECT * FROM $table LIMIT 1;";
+ $res = db_exec( $dbd, $qs );
+ for( $i=0 ; $i<pg_numfields($res) ; $i++ )
+ {
+ $n = pg_fieldname( $res, $i );
+ $f[$n]['size'] = pg_fieldsize( $res, $i );
+ $f[$n]['type'] = pg_fieldtype( $res, $i );
+ }
+
+ return $f;
+}
+
+
+/***********************************************************************
+* *
+* FILE FUNCTIONS *
+* *
+***********************************************************************/
+
+ // Store away an uploaded file
+
+function file_upload( $form_field, $file_name, $base_path = SI_BASE_FILE_PATH )
+{
+
+ if( $base_path == '' )
+ die( "Base file path not provided to file_upload() function or SI_BASE_FILE_PATH not set" );
+
+ if( SI_DEBUG > 0 )
+ echo "file_upload(): temp file = $form_field, file name = $file_name";
+
+ // Get rid of screwy characters in file names
+
+ if( ereg( '[!@#$%^&()+={};: ]', $file_name ) )
+ $file_name = ereg_replace( "[!@#$%^&()+={};: ]", "x", $file_name );
+
+ // Check if destination path is valid
+
+ if( !is_dir( $base_path ) )
+ die( $base_path." not a directory" );
+
+ // Check if file name is in use
+
+ $new_file_name = $file_name;
+ if( file_exists( $base_path."/".$file_name ) ) // If so
+ $new_file_name = mktime()."_".$file_name; // Prefix with timestamp
+
+ // Save file to destination directory
+
+ $new_file_location = $base_path."/".$new_file_name;
+
+ if( SI_DEBUG > 0 )
+ echo ", new file name = $new_file_location<br>";
+
+ copy( $form_field, $new_file_location );
+ chmod( $new_file_location, 0664 );
+
+ // Return where it was stored
+
+ return( $new_file_name );
+}
+
+ // Duplicate a file
+
+function file_duplicate( $file_name, $base_path = SI_BASE_FILE_PATH )
+{
+
+ if( empty($file_name) )
+ return( "" );
+
+ // Check to see if specified file exists
+
+ if( !is_file($base_path."/".$file_name) )
+ return( "" );
+
+ // Create new file name
+
+ for( $i=1 ; $i<1000 ; $i++ )
+ {
+ if( !is_file($base_path."/"."c".$i."_".$file_name) )
+ break;
+ }
+
+ if( $i == 1000 )
+ return( "" );
+
+ $new_file_name = "c".$i."_".$file_name;
+
+ copy( $base_path."/".$file_name, $base_path."/".$new_file_name );
+
+ return( $new_file_name );
+}
+
+
+
+ // Delete a stored File
+
+function file_delete( $file_name, $base_path = SI_BASE_FILE_PATH )
+{
+
+ if( !is_writable ( $base_path."/".$file_name ) )
+ return( FALSE );
+
+ if( !is_file($base_path."/".$file_name) || !unlink($base_path."/".$file_name) )
+ return( FALSE );
+
+ return( TRUE );
+}
+
+
+ // Read the specified file and return the results
+
+function file_get( $file_name, $max_size = 0, $base_path = SI_BASE_PATH )
+{
+
+ if( !is_readable ( $base_path."/".$file_name ) )
+ return( FALSE );
+
+ $f = fopen( $base_path."/".$file_name, "r" );
+ $s = filesize($base_path."/".$file_name);
+ if( $max_size == 0 || $s <= $max_size )
+ $file_contents = fread( $f, $s );
+ else
+ return( FALSE );
+
+ return( $file_contents );
+}
+
+
+function file_ouput_secure( $file_name, $md5, $path = '' )
+{
+
+ // Check for required secret string
+
+ if( !defined('SI_FILE_SECRET') || SI_FILE_SECRET == '' )
+ {
+ echo '<p><font color="red">ERROR: </font> SI_FILE_SECRET parameter required for <b>file_output_secure()</b><br>
+ SI_FILE_SECRET defined parameter not found or no contents! Please check siteinfo.inc file.<p>';
+ exit;
+ }
+
+ // Check sanity of parameters
+
+ if( empty($file_name) )
+ {
+ if( SI_DEBUG > 0 ) echo 'file_output_secure(): No file name supplied<br>';
+ return( false );
+ }
+
+ if( ereg( '\.\./', $file_name ) ) // Note that strpos function is defective so it's not used here
+ {
+ if( SI_DEBUG > 0 ) echo 'file_output_secure(): "../" not permitted in file name<br>';
+ return( false );
+ }
+
+ if( empty($md5) || $md5 != md5( $file_name.SI_FILE_SECRET ) )
+ {
+ if( SI_DEBUG > 0 ) echo 'file_output_secure(): md5 security parameter is not supplied or is not valid for $file_name<br>';
+ return( false );
+ }
+
+ // Assemble complete file path and name
+
+ if( empty($path) )
+ $pathname = SI_BASE_FILE_PATH.'/'.$file_name;
+ else
+ $pathname = SI_BASE_PATH.'/'.$path.'/'.$file_name;
+
+ // Make sure file exists and is readable
+
+ if( !is_readable( $pathname ) )
+ {
+ if( SI_DEBUG > 0 ) echo 'file_output_secure(): Specified file doesn\'t exist or is unreadable - '.$pathname.'<br>';
+ return( false );
+ }
+
+
+ // Get mime type for specified file
+
+ $mimetype = shell_exec( 'file -bi '.$pathname );
+ $length = filesize( $pathname );
+
+ // Output File
+
+ header( "Content-type: $mimetype" );
+ header( "Content-Length: $length" );
+ header( "Content-Disposition: inline; filename=$file_name" );
+ readfile( $pathname );
+
+ // Since output was successful, don't return, just quit
+
+ exit;
+
+}
+
+
+/***********************************************************************
+* *
+* GRAPHICS FUNCTIONS *
+* *
+***********************************************************************/
+
+ // Return information about an image
+
+function img_info( $path2image )
+{
+
+ $type = array
+ (
+ 1 => 'GIF',
+ 2 => 'JPG',
+ 3 => 'PNG',
+ 4 => 'SWF',
+ 5 => 'PSD',
+ 6 => 'BMP',
+ 7 => 'TIFF(intel byte order)',
+ 8 => 'TIFF(motorola byte order)',
+ 9 => 'JPC',
+ 10 => 'JP2',
+ 11 => 'JPX',
+ 12 => 'JB2',
+ 13 => 'SWC',
+ 14 => 'IFF',
+ 15 => 'WBMP',
+ 16 => 'XBM'
+ );
+
+ if( file_exists($path2image) )
+ {
+ $i = GetImageSize( $path2image );
+ $r['width'] = $i[0];
+ $r['height'] = $i[1];
+ $r['type_num'] = $i[2];
+ $r['type'] = $type[$i[2]];
+ $r['size'] = $i[3];
+ $r['bits'] = $i[4];
+ $r['channels'] = $i[5];
+
+ return( $r );
+ }
+ else
+ return( FALSE );
+}
+
+
+ // Create a thumbnail image based on a full scale jpeg or gif
+
+function graphic_thumb($img, $timg, $type)
+{
+ switch( $type )
+ {
+ case "image/gif":
+ $cmd = SI_GRPH_GIFTOPNM." $img | ".SI_GRPH_PNMSCALE." -height ".SI_THEIGHT." | ".SI_GRPH_PPMQUANT." 256 | ".SI_GRPH_PPMTOGIF." -interlace > $timg";
+ break;
+
+ case "image/jpeg":
+ $cmd = SI_GRPH_DJPEG." $img | ".SI_GRPH_PNMSCALE." -height ".SI_THEIGHT." | ".SI_GRPH_CJPEG." -outfile $timg";
+ break;
+
+ default:
+ echo "<h1>Graphic type not defined: type $type</h1>\n";
+
+ /* we can only do gifs and jpegs at this point.
+ * png would be a nice addition
+ */
+
+ return( 0 );
+ }
+ exec( $cmd );
+ return( 1 );
+}
+
+
+ // Creates a resized image based on a full scale jpeg or gif
+
+function graphic_resize( $img, $timg, $type, $w, $h )
+{
+ switch ( $type )
+ {
+ case "image/gif":
+ $cmd = SI_GRPH_GIFTOPNM." $img | ";
+
+ if( $w && $h )
+ $cmd .= SI_GRPH_PNMSCALE." -width $w -height $h |";
+ elseif( $h )
+ $cmd .= SI_GRPH_PNMSCALE." -height $h |";
+ elseif( $w )
+ $cmd .= SI_GRPH_PNMSCALE." -width $w |";
+ $cmd .= SI_GRPH_PPMQUANT." 256 | ".SI_GRPH_PPMTOGIF." -interlace > $timg";
+ break;
+
+ case "image/jpeg":
+ $cmd = DJPEG." $img | ";
+ if( $w && $h )
+ $cmd .= SI_GRPH_PNMSCALE." -width $w -height $h |";
+ elseif( $h )
+ $cmd .= SI_GRPH_PNMSCALE." -height $h |";
+ elseif( $w )
+ $cmd .= SI_GRPH_PNMSCALE." -width $w |";
+ $cmd .= CJPEG." -outfile $timg";
+
+ break;
+
+ case "image/pjpeg":
+ $cmd = DJPEG." $img | ";
+
+ if( $w && $h )
+ $cmd .= SI_GRPH_PNMSCALE." -width $w -height $h |";
+ elseif( $h )
+ $cmd .= SI_GRPH_PNMSCALE." -height $h |";
+ elseif( $w )
+ $cmd .= SI_GRPH_PNMSCALE." -width $w |";
+ $cmd .= CJPEG." -outfile $timg";
+
+ break;
+
+ default:
+ echo "<h1>Graphic type not defined: type $type</h1>\n";
+ /* we can only do gifs and jpegs at this point.
+ * png would be a nice addition
+ */
+ return( 0 );
+ }
+ exec( $cmd );
+ return( 1 );
+}
+
+
+ // Resize an image based on a full scale jpeg or gif
+
+function img_resize( $path2image, $path2thumb, $axis, $size )
+{
+ $imageName = basename( $path2image );
+ $thumbName = basename( $path2thumb );
+
+ if( TRUE ) // Not testing submitted file type at this time
+ {
+ $imageAttributes = GetImageSize( $path2image );
+ $imageWidth = $imageAttributes[0];
+ $imageHeight = $imageAttributes[1];
+ if( $imageWidth < $size && $imageHeight < $size )
+ {
+ exec( "cp $path2image $path2thumb" );
+ chmod( $path2thumb, 0664 );
+ }
+ else
+ {
+ if( ($axis == "h" || $axis == "a") && ($imageHeight > $imageWidth) )
+ exec( SI_GRPH_CONVERT." -geometry $size $path2image $path2thumb" );
+ if( ($axis == "w" || $axis == "a") && ($imageWidth >= $imageHeight) )
+ exec( SI_GRPH_CONVERT." -geometry $size $path2image $path2thumb");
+ }
+
+ $img_resize_array = array( "$imageName", "$path2image", "$thumbName", "$path2thumb" );
+ return( $img_resize_array );
+ }
+ else
+ {
+ echo '<FONT SIZE=4>'
+ .'Unable to complete Resize Function, The file being processed is not an acceptable image file. Please use only .GIF or .JPG files'
+ .'<BR CLEAR=ALL>'
+ .'</FONT>'
+ ."Hit your browser's back button to continue"
+ .'<P>';
+ $error[0] = "ERROR";
+ return( $error );
+ }
+}
+
+ // Upload an image
+
+function img_upload( $form_field,$img_name,$destination_path )
+{
+
+ if (ereg('[!@#$%^&()+={};:\'\\ ]', $img_name))
+ {
+ $img_name = ereg_replace("[!@#$%^&()+={};:'\\ ]", "x", $img_name);
+ $dumb = "dumber";
+ }
+
+ if( TRUE ) // Huh? - Oh, need to check for legal image type at some point
+ {
+ $i = "0";
+
+ // Check for valid destination path
+
+ if( !is_dir($destination_path) )
+ die( $destination_path." not a directory" ); // This is totally fatal
+
+ // Get entries in that directory and check if the supplied name is in use
+
+ $d = dir( $destination_path );
+ $img_name_in_use = "FALSE";
+ while ($entry = $d->read())
+ {
+ if ($entry == $img_name)
+ {
+ $img_name_in_use = "TRUE";
+ }
+ ++ $i;
+ }
+
+ $d->close();
+
+ // If the name is in use, give it a name that can't match anything
+
+ if( $img_name_in_use == "TRUE" )
+ {
+ $new_img_name = mktime().$img_name;
+ $new_img_location = $destination_path.'/'.$new_img_name;
+
+ // And store the image in the destination
+
+ copy( $form_field, $new_img_location );
+ chmod( $new_img_location, 0664 );
+ $img_upload_array = array( "$new_img_name", "$new_img_location" );
+ }
+ else
+ {
+ // Otherwise, supplied name is fine
+
+ $new_img_name = $img_name;
+ $new_img_location = $destination_path.'/'.$new_img_name;
+
+ copy( $form_field, $new_img_location );
+ chmod( $new_img_location, 0664 );
+ $img_upload_array = array( "$new_img_name", "$new_img_location" );
+ }
+ }
+ else // Can't get here right now
+ {
+ echo '<FONT SIZE=4>'.'The file you uploaded was of an incorrect type, please only upload .GIF or .JPG files'.'<BR CLEAR=ALL>'.'</FONT>'."Hit your browser's back button to continue".'<P>';
+ $error[0] = "ERROR";
+ return ($error);
+ }
+
+ return( $img_upload_array );
+}
+
+ // Main image processing function
+
+function process_image( $image, $image_name, $resized_size = SI_RESIZED_SIZE,
+ $midsized_size = SI_MIDSIZED_SIZE, $thumb_size = SI_THUMB_SIZE )
+{
+
+ // Check for paths
+
+ if( !defined("SI_IMG_ORIGINAL_PATH") )
+ html_error( "not defined SI_IMG_ORIGINAL_PATH", 1 );
+ if( !defined("SI_IMG_RESIZED_PATH") )
+ html_error( "not defined SI_IMG_RESIZED_PATH", 1 );
+ if( !defined("SI_IMG_MIDSIZED_PATH") )
+ html_error( "not defined SI_IMG_MIDSIZED_PATH", 1 );
+ if( !defined("SI_IMG_THUMB_PATH") )
+ html_error( "not defined SI_IMG_THUMB_PATH", 1 );
+
+ if( !defined("SI_RESIZED_SIZE") )
+ html_error( "not defined SI_RESIZED_SIZE",1 );
+ if( !defined("SI_MIDSIZED_SIZE") )
+ html_error( "not defined SI_MIDSIZED_SIZE",1 );
+ if( !defined("SI_RESIZED_SIZE") )
+ html_error( "not defined SI_THUMB_SIZE",1 );
+
+ if( !($image_upload_array = img_upload($image, $image_name, SI_IMG_ORIGINAL_PATH)) )
+ html_error( "image could not be uploaded", 1 );
+
+ // Resize image using progressively smaller images as the source to minimize work
+
+ img_resize( $image_upload_array[1], SI_IMG_RESIZED_PATH."/".$image_upload_array[0], 'a', SI_RESIZED_SIZE );
+ img_resize( SI_IMG_RESIZED_PATH."/".$image_upload_array[0], SI_IMG_MIDSIZED_PATH."/".$image_upload_array[0], 'a', SI_MIDSIZED_SIZE );
+ img_resize( SI_IMG_MIDSIZED_PATH."/".$image_upload_array[0], SI_IMG_THUMB_PATH."/".$image_upload_array[0], 'a', SI_THUMB_SIZE );
+ $image_name = $image_upload_array[0];
+
+ return( $image_name );
+}
+
+ // Delete an image
+
+function delete_image( $image_name )
+{
+ $ok = TRUE;
+ if( !is_file(SI_IMG_ORIGINAL_PATH."/".$image_name) || !unlink(SI_IMG_ORIGINAL_PATH."/".$image_name) )
+ $ok = FALSE;
+ if( !is_file(SI_IMG_RESIZED_PATH."/".$image_name) || !unlink(SI_IMG_RESIZED_PATH."/".$image_name) )
+ $ok = FALSE;
+ if( !is_file(SI_IMG_MIDSIZED_PATH."/".$image_name) || !unlink(SI_IMG_MIDSIZED_PATH."/".$image_name) )
+ $ok = FALSE;
+ if( !is_file(SI_IMG_THUMB_PATH."/".$image_name) || !unlink(SI_IMG_THUMB_PATH."/".$image_name) )
+ $ok = FALSE;
+
+ return( $ok );
+}
+
+ // Duplicate an image
+
+function duplicate_image( $image_name )
+{
+
+ if( empty($image_name) )
+ return( "" );
+
+ // Check to see if specified image exists
+
+ if( !is_file(SI_IMG_ORIGINAL_PATH."/".$image_name) )
+ return( "" );
+
+ // Create new file name using "copy_" and timestamp
+
+ for( $i=1 ; $i<100 ; $i++ )
+ {
+ if( !is_file(SI_IMG_ORIGINAL_PATH."/"."p".$i."_".$image_name) )
+ break;
+ }
+
+ if( $i == 100 )
+ return( "" );
+
+ $new_image_name = "p".$i."_".$image_name;
+
+ copy( SI_IMG_ORIGINAL_PATH."/".$image_name, SI_IMG_ORIGINAL_PATH."/".$new_image_name );
+ copy( SI_IMG_RESIZED_PATH."/".$image_name, SI_IMG_RESIZED_PATH."/".$new_image_name );
+ copy( SI_IMG_MIDSIZED_PATH."/".$image_name, SI_IMG_MIDSIZED_PATH."/".$new_image_name );
+ copy( SI_IMG_THUMB_PATH."/".$image_name, SI_IMG_THUMB_PATH."/".$new_image_name );
+
+ return( $new_image_name );
+}
+
+
+/***********************************************************************
+* *
+* GENERAL SUPPORT FUNCTIONS / CLASSES *
+* *
+***********************************************************************/
+
+class timestampfunc
+{
+
+ function newdate( $timestamp )
+ {
+ $z = date( "m:Y", $timestamp );
+ $z = split( ":", $z );
+ return $z;
+ }
+
+ function first_of_month( $timestamp )
+ {
+ $z = $this->newdate( $timestamp );
+ $first_of_month = $z[0]."/1/".$z[1];
+ return strtotime( $first_of_month );
+ }
+
+ function first_last_month( $timestamp )
+ {
+ $z = $this->newdate( $timestamp );
+ $z[0]--;
+ if( $z[0] <= 0 )
+ {
+ $z[0] = 12;
+ $z[1]--;
+ }
+ $first_of_month = ($z[0])."/1/".$z[1];
+ return strtotime( $first_of_month );
+ }
+
+ function first_next_month( $timestamp )
+ {
+ $z = $this->newdate( $timestamp );
+ $z[0]++;
+ if( $z[0] > 12 )
+ {
+ $z[0] = 1;
+ $z[1]++;
+ }
+ $first_of_month = ($z[0])."/1/".$z[1];
+ return strtotime( $first_of_month );
+ }
+
+ function first_of_Xmonth( $timestamp, $x )
+ {
+ $z = $this->newdate( $timestamp );
+ $r = mktime( 0,0,0, ($z[0]+$x), 1, $z[1] );
+ return $r;
+ }
+
+}
+
+
+ // Return Positive values only, otherwise 0
+
+function pos_value( $value )
+{
+
+ if( $value > 0 )
+ return( $value );
+ return( 0 );
+}
+
+
+ // Format a number as US Dollars
+
+function money( $value, $option = "" )
+{
+
+ if( $option == "NOPREFIX" )
+ $prefix = "";
+ else
+ $prefix = "$";
+
+ // Do value sanity check
+
+ if( !is_numeric( $value ) )
+ return( $prefix."0.00" );
+
+ return( $prefix.number_format($value, 2, ".", "," ) );
+}
+
+
+ // Convert "key^value~key^value" string to an array
+
+function strtoarray( $s )
+{
+
+ $a = array();
+
+ // Create array of entries - If there's less than 2 entries, fail
+
+ if( count($ea = explode( '~', $s )) < 2 )
+ return( FALSE );
+
+ foreach( $ea as $e )
+ {
+ // Each entry must have exactly 2 parts
+
+ if( count($d = explode( "^", $e )) != 2 )
+ return( FALSE );
+
+ $a[trim($d[0])] = trim($d[1]);
+ }
+
+ return( $a );
+}
+
+
+ // Convert array to a "key^value~key^value" string
+
+function arraytostr( $a )
+{
+
+ $s = '';
+
+ // Supplied value must be array of 2 or more entries
+
+ if( !is_array($a) || count($a) < 2 )
+ return( FALSE );
+
+ $sep = "";
+
+ while( list($k,$v) = each($a) )
+ {
+ $s .= $sep."$k^$v";
+ $sep = '~';
+ }
+
+ return( $s );
+}
+
+
+ // Replace {tokens}
+
+function replace_tokens( $s, $tokens )
+{
+
+ if( !is_array($tokens) )
+ {
+ echo '<P>ERROR: replace_tokens() - Parameter 2 ($tokens) is not an array<P>';
+ exit;
+ }
+
+ while( list($k,$v) = each($tokens) )
+ {
+ $s = str_replace( "{".$k."}", $v, $s ); // Non ereg version - faster, case must match
+// $s = eregi_replace( "\\{".$k."\\}", $v, $s ); // Ereg version
+ }
+
+ return( $s );
+
+}
+
+
+ // Conditionally replace tokens
+
+function cond_replace_tokens( $s, $tokens, $x="cond" )
+{
+
+ if( !is_array($tokens) )
+ {
+ echo '<P>ERROR: cond_replace_tokens() - Parameter 2 ($tokens) is not an array<P>';
+ exit;
+ }
+
+ while( list($k,$v) = each($tokens) )
+ {
+ $p0 = 0; // Reset starting pointer position
+
+ while( ($start = strpos( $s, "<!--{if:".$k, $p0 )) !== false )
+ {
+ if( strcspn( substr($s,$start+8+strlen($k)), "=!><}" ) == 0 ) // Check to make sure it's not a substring of another token
+ {
+
+ if( !($if_end = strpos( $s, "}-->", $start )) ) // Find end of {if:} tag
+ return( "ERROR: cond_replace_tokens() - Can't find end of {if:} tag at $start.<P><PRE>\n\n".htmlentities(substr($s,$start,500))."</PRE>" );
+
+ $p = $start + 8 + strlen($k); // Set position where "=" should be if it's used
+ $cond = substr($s,$p,1);
+ switch( $cond )
+ {
+ case "=":
+ case "!":
+ case ">":
+ case "<":
+ $if_val_test = TRUE; // If valid comparison character?
+ $if_val = substr( $s, $p+1, $if_end-$p-1 );
+ break;
+ default:
+ $if_val_test = FALSE;
+ break;
+ }
+
+ // Separate out strings for both yes and no conditions
+
+ $yes_start = $if_end + 4; // Point past tag
+ $ci = ""; // Closed {/if} take intro only if there's no {else}
+ $else_if = strpos( $s, "<!--{else:$k}", $yes_start );
+ $slash_if = strpos( $s, "<!--{/if:$k}-->", $yes_start );
+ if( $else_if && ( !$slash_if || ($else_if < $slash_if) ) ) // If there's an {else}
+ {
+ $yes_string = substr( $s, $yes_start, $else_if-$yes_start );
+ $no_start = $else_if + 11 + strlen($k); // Point past tag
+ if( !($no_end = strpos( $s, "{/if:$k}-->", $no_start )) ) // If there's no --> end of cond tag
+ return( "ERROR: cond_replace_tokens() - Matching {/if:} tag not found after {else:} at $start for \"$k\".<P><PRE>\n\n".htmlentities(substr($s,$start,500))."</PRE>" );
+
+ $end = $no_end + 9 + strlen($k);
+
+ $no_string = substr( $s, $no_start, $no_end-$no_start );
+ }
+ else
+ {
+ $no_string = "";
+ if( !($slash_if = strpos( $s, "<!--{/if:$k}-->", $yes_start )) ) // If there's no end of cond tag
+ return( "ERROR: cond_replace_tokens() - Matching {/if} tag not found at $start for \"$k\".<P><PRE>\n\n".htmlentities(substr($s,$start,500))."</PRE>" );
+ $end = $slash_if + 13 + strlen($k);
+ $yes_string = substr( $s, $yes_start, $slash_if-$yes_start );
+ }
+
+ if( $if_val_test != FALSE ) // If there's a compare value, test with that
+ switch( $cond )
+ {
+ case "=":
+ $t = ( trim($v) == trim($if_val) );
+ break;
+ case "!":
+ $t = ( trim($v) != trim($if_val) );
+ break;
+ case ">":
+ $t = ( trim($v) > trim($if_val) );
+ break;
+ case "<":
+ $t = ( trim($v) < trim($if_val) );
+ break;
+ default:
+ return( "ERROR: cond_replace_tokens() - Internal unknown conditional operator error ($cond)- Code Bad, fix code!" );
+ }
+ else // otherwise just use token value
+ $t = ( trim($v) != "" ); // if it's not empty use yes_string
+
+ if( $t ) // Replace with appropriate string
+ $s = substr_replace( $s, $yes_string, $start, $end-$start );
+ else
+ $s = substr_replace( $s, $no_string, $start, $end-$start );
+ }
+ else
+ $p0 = $start + 1;
+ }
+ $p0 = $start;
+ }
+
+ return( $s );
+
+}
+
+ // Replace {file:xxx} token with a file
+
+function replace_file_tokens( $s )
+{
+
+ $p0 = 0; // Reset starting pointer position
+
+ while( $p0 < strlen($s) && ($start = strpos( $s, "<!--{file:", $p0 )) )
+ {
+ if( !($file_end = strpos( $s, "}-->", $start )) ) // Find end of {file:} tag
+ return( "ERROR: replace_file_tokens() - Can't find end of {file:} tag at $start.<P><PRE>\n\n".htmlentities(substr($s,$start,500))."</PRE>" );
+
+ $filename = substr( $s, $start+10, $file_end-$start-10 ); // Get file name
+ // Check for a matching <!--{/file}--> tag
+
+ if( ($slash_file = strpos( $s, "<!--{/file}-->", $file_end)) // If there's a {/file} tag
+ && !($next_file = strpos( $s, "<!--{file:", $file_end)) // and there's not another {file:} tag
+ || ( $next_file && $slash_file < $next_file ) ) // or it's beyond our {/file} tag
+ {
+ $file_end = $slash_file + 10; // Point to "}-->"
+ }
+
+ $end = $file_end + 4;
+
+ // Check if file name is valid
+
+ if( ($file_contents = file_get( $filename )) == FALSE )
+ return( "ERROR: replace_file_tokens() - Can't load specified file '$filename' for {file:} tag.<P><PRE>\n\n".htmlentities(substr($s,$start,500))."</PRE>" );
+
+ $s = substr_replace( $s, $file_contents, $start, $end-$start );
+
+ $p0 = $end;
+ }
+
+ return( $s );
+
+}
+
+
+ // Convert an array of data to an HTML table
+
+function tableize_array($arr, $len=100 )
+{
+ // Verify that parameter is actually an array
+
+ if( !is_array($arr) )
+ {
+ $return = "Error: Variable not an array";
+ return $return;
+ }
+
+ // If everything's going fine so far, build out the table
+
+ $return = '<P><table width="100%" bordercolor="black" border="1">';
+
+ foreach( $arr as $key=>$val )
+ {
+ $return .= '<tr><td align="left" valign="top" width="10%" nowrap>'.$key.'</td> <td align="left" valign="top" width="90%">';
+ if( is_array($val) )
+ $return .= tableize_array( $val );
+ else
+ {
+ if( strlen($val) > $len )
+ $x = substr( $val, 0, $len ).".......";
+ else
+ $x = $val;
+ $return .= "<PRE>".htmlentities( $x )."</PRE>";
+ }
+
+ $return .= "</td></tr>\n";
+ }
+
+ $return .= "</table>";
+
+ return $return;
+}
+
+
+ // Select field data from an array based on which function it will be used for
+ // returning a string suitable for the admin_ functions
+
+function admin_field_select( $fields, $filter )
+{
+
+ $r = '';
+ $sep = '';
+
+ if( ! is_array($fields) || trim($filter) == '' )
+ {
+ echo "<P>ERROR: admin_field_select() - No Field or Filter data supplied!<P>";
+ return( FALSE );
+ }
+
+ foreach( $fields as $f )
+ {
+ $x = explode( ',', $f );
+ if( strstr( $x[5], $filter ) )
+ {
+ if( $filter == 'f' ) // List filters require slight difference in fields
+ $r .= $sep.$x[0].','.$x[1].','.$x[2].','.$x[4];
+ else
+ $r .= $sep.$x[0].','.$x[1].','.$x[2].','.$x[3].','.$x[4];
+ $sep = '|';
+ }
+ }
+
+ return( $r );
+}
+
+ // Select field data from an array based on which function it will be used for
+ // returning an array of arrays of data.
+
+function admin_fields_select_array( $fields, $filter )
+{
+
+ $r = array();
+
+ if( ! is_array($fields) || trim($filter) == '' )
+ {
+ echo "<P>ERROR: admin_field_select_array() - No Field or Filter data supplied!<P>";
+ return( FALSE );
+ }
+
+ while( list($key, $val) = each($fields) )
+ {
+ $x = explode( ',', $val );
+ if( strstr( $x[5], $filter ) )
+ {
+ $r[$key]['name'] = trim($x[0]);
+ $y = explode( '.', trim($x[1]) );
+ foreach( $y as $z )
+ $r[$key]['type'][] = trim($z);
+ $r[$key]['title'] = trim($x[2]);
+ $r[$key]['required'] = trim($x[3]);
+ $r[$key]['variable'] = trim($x[4]);
+ $r[$key]['sample'] = trim($x[6]);
+ }
+ }
+
+ return( $r );
+}
+
+ // Generate standard admin low-level menu
+
+ // New version using standard HTML (<div>'s) for admin sections
+function admin_menu_std( $action, $a_title, $id, $opt, $options = 'lveda', $add_menu = '', $params = '' )
+{
+
+ $m = '';
+ $nl = "\n";
+
+// if( $a_title != '' )
+// $m .= '<span class="submenu_title">'.$a_title.':</span>';
+
+ $link = SI_THIS_SCRIPT.'?Action='.urlencode($action);
+ if( trim($params) != '' )
+ $link .= '&'.$params;
+
+ if( strstr($options,'l') )
+ {
+ if( $opt == "List" )
+ $m .= '<li class="active">[List]</li>'.$nl;
+ else
+ $m .= '<li class="inactive" id="current"><a href="'.$link.'&Option=List">[List]</A></li>'.$nl;
+ }
+
+ if( strstr($options,'v') )
+ {
+ if( $opt == "View" )
+ $m .= '<li class="active">[View]</li>'.$nl;
+ elseif( empty($id) )
+ $m .= '<li class="unavailable">[View]</li>'.$nl;
+ else
+ $m .= '<li class="inactive"><a href="'.$link.'&Option=View&id='.$id.'">[View]</a></li>'.$nl;
+ }
+
+ if( strstr($options,'e') )
+ {
+ if( $opt == "Edit" )
+ $m .= '<li class="active">[Edit]</li>'.$nl;
+ elseif( empty($id) )
+ $m .= '<li class="unavailable">[Edit]</li>'.$nl;
+ else
+ $m .= '<li class="inactive"><a href="'.$link.'&Option=Edit&id='.$id.'">[Edit]</A></li>'.$nl;
+ }
+
+ if( strstr($options,'d') )
+ {
+ if( $opt == "Delete" )
+ $m .= '<li class="active">[Delete]<</li>'.$nl;
+ elseif( empty($id) )
+ $m .= '<li class="unavailable">[Delete]</li>'.$nl;
+ else
+ $m .= '<li class="inactive"><a href="'.$link.'&Option=Delete&id='.$id.'">[Delete]</a></li>'.$nl;
+ }
+
+ if( strstr($options,'a') )
+ {
+ if( $opt == "Add" )
+ $m .= '<li class="active">[Add]</li>'.$nl;
+ else
+ $m .= '<li class="inactive"><a href="'.$link.'&Option=Add">[Add]</A></li>'.$nl;
+ }
+
+ if( $add_menu != '' )
+ $m .= " - $add_menu".$nl;
+
+ return( $m );
+}
+ // Standard version
+function admin_menu( $action, $a_title, $id, $opt, $options = 'lveda', $add_menu = '', $params = '' )
+{
+
+ $m = '<SPAN CLASS="menu_title">'.$a_title.':</SPAN> </B>';
+
+ $link = SI_THIS_SCRIPT.'?Action='.urlencode($action);
+ if( trim($params) != '' )
+ $link .= '&'.$params;
+
+ if( strstr($options,'l') )
+ {
+ if( $opt == "List" )
+ $m .= '<SPAN CLASS="menu_active">[List]</SPAN> ';
+ else
+ $m .= '<A HREF="'.$link.'&Option=List">[List]</A> ';
+ }
+
+ if( strstr($options,'v') )
+ {
+ if( $opt == "View" )
+ $m .= '<SPAN CLASS="menu_active">[View]</SPAN> ';
+ elseif( empty($id) )
+ $m .= '[View] ';
+ else
+ $m .= '<A HREF="'.$link.'&Option=View&id='.$id.'">[View]</A> ';
+ }
+
+ if( strstr($options,'e') )
+ {
+ if( $opt == "Edit" )
+ $m .= '<SPAN CLASS="menu_active">[Edit]</SPAN> ';
+ elseif( empty($id) )
+ $m .= '[Edit] ';
+ else
+ $m .= '<A HREF="'.$link.'&Option=Edit&id='.$id.'">[Edit]</A> ';
+ }
+
+ if( strstr($options,'d') )
+ {
+ if( $opt == "Delete" )
+ $m .= '<SPAN CLASS="menu_active">[Delete]</SPAN> ';
+ elseif( empty($id) )
+ $m .= '[Delete] ';
+ else
+ $m .= '<A HREF="'.$link.'&Option=Delete&id='.$id.'">[Delete]</A> ';
+ }
+
+ if( strstr($options,'a') )
+ {
+ if( $opt == "Add" )
+ $m .= '<SPAN CLASS="menu_active">[Add]</SPAN> ';
+ else
+ $m .= '<A HREF="'.$link.'&Option=Add">[Add]</A> ';
+ }
+
+ if( $add_menu != '' )
+ $m .= " - $add_menu";
+
+ return( $m );
+}
+
+
+ // Clean up input parameters and test them for proper type of data
+
+function clean_input( $var_name, $type = 'text', $required = false )
+{
+
+ $reason = ''; // If problems, indicates reason here
+
+ // Trim whitespace, slashes, and stupid characters
+
+ $in = stripslashes( trim( $GLOBALS[$var_name] ) );
+
+ if( $in != '' )
+ {
+ switch( $type )
+ {
+
+ case 'int':
+ if( !is_numeric($in) )
+ $reason = 'not an integer';
+ else
+ $in = intval( $in );
+ break;
+
+ case 'float':
+ $in = preg_replace( "/^(\\$)?(.*)$/i", "\\2", $in );
+ if( !is_numeric( $in ) )
+ $reason = 'not a valid number';
+ else
+ $in = floatval( $in );
+ break;
+
+ case 'phone':
+ if( preg_match( "/^((\([0-9]{3}\))[ ]*|([0-9]{3}) *-* *)?[0-9]{3} *-* *[0-9]{4} *.{0,10}$/i", $in ) == 0 )
+ $reason = 'not a valid phone number';
+ else // Reformat as we want it
+ $in = preg_replace( "/^((\(([0-9]{3})\))[ ]*|(([0-9]{3}))[ -]*)?([0-9]{3}) *-* *([0-9]{4}) *(.{0,10})$/i", "\\3\\4-\\6-\\7 \\8", $in );
+ break;
+
+ case 'zip':
+ // Check if it's a US ZIP
+ if( preg_match( "/^(([0-9]{5})([ -+]?([0-9]{4}))?)$/i", $in ) != 0 )
+ {
+ $in = preg_replace( "/^([0-9]{5})[ -+]?([0-9]{4})$/i", "\\1-\\2", $in );
+ if( strlen($in) < 8 )
+ {
+ $in = preg_replace( "/^([0-9]{5}).*/i", "\\1", $in );
+ }
+ }
+ elseif( preg_match( "/^[a-zA-Z]\d[a-zA-Z][ -]?\d[a-zA-Z]\d$/i", $in ) != 0 )
+ {
+ $in = preg_replace( "/^([a-zA-Z]\d[a-zA-Z])[ -]?(\d[a-zA-Z]\d)$/i", "\\1 \\2" ,$in );
+ }
+ else
+ $reason = 'not a valid ZIP or Postal Code';
+ break;
+
+ case 'state':
+ global $si_states_array;
+ if( !isset($si_states_array[$in]) )
+ $reason = 'not a valid state code';
+ break;
+
+ case 'country':
+ global $si_countries_array;
+ if( !isset($si_countries_array[$in]) )
+ $reason = 'not a valid country code';
+ break;
+
+ case 'email':
+ if( preg_match( "/^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$/i", $in ) == 0 )
+ $reason = 'not a valid E-Mail address';
+ break;
+
+ case 'creditcard':
+ global $si_cc_verify;
+ $match = FALSE;
+ reset( $si_cc_verify );
+ while( list($k, $v) = each($si_cc_verify) )
+ {
+ if( preg_match( "/".$v."/i", $in ) != 0 )
+ {
+ $match = TRUE;
+ break;
+ }
+ }
+ if( !$match )
+ $reason = 'not a valid credit card number';
+ break;
+
+ case 'date':
+ if( ($t = strtotime($in)) === -1 )
+ $reason = 'not a valid date';
+ else
+ $in = date( 'n/j/Y', $t );
+ break;
+
+ case 'text':
+ break;
+
+ case 'inet':
+ if( preg_match( "/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/i", $in ) == 0 )
+ $reason = 'not a valid IP address or netmask';
+ break;
+
+ default:
+ break;
+
+ }
+ }
+
+ // Check for a required field
+
+ if( $required && $in == '' )
+ $reason .= ($reason != '' ? ' and is ':'' ).'required';
+
+ $GLOBALS[$var_name] = $in;
+ return( $reason );
+
+}
+
+ // Convert data to search engine friendly URL
+
+function data_to_url( $prefix = '' )
+{
+
+ $url = $prefix;
+
+ // Make sure we have at least a prefix and one parameter
+
+ if( ($args = func_get_args()) == 0 || count($args) < 2 )
+ return( false );
+
+ for( $i=1 ; $i<count($args) ; $i++ )
+ $url .= '/'.urlencode(trim($args[$i]));
+
+ return( $url );
+}
+
+
+ // Convert Search Engine Friendly URL to Data
+
+function url_to_data( $url, $start_key ) // Expects additional parameters that define the name of each url parameter
+{
+
+ // Make sure we have valid data
+
+ $args = func_get_args();
+ if( count($args) < 3 )
+ return( false );
+
+ if( ($url=trim($url)) == '' )
+ return( false );
+
+ // If start_key is null, assume key is found and start with first parameter in URL
+
+ $key_found = ( ($start_key=trim($start_key)) == '' );
+
+ // Break out incoming URL and search for start key
+
+ $in = explode( '/', $url );
+ for( $u=0 ; $u<=count($in) ; )
+ if( ($key_found = ( $in[$u++] == $start_key )) )
+ break;
+
+ if( !$key_found )
+ return( false );
+
+ // Stuff remaing data into return array
+
+ if( count($in) < $u )
+ return( false );
+
+ $data = array();
+ $data_found = false;
+ for( $i=2 ; $i<count($args) ; $i++, $u++ )
+ {
+ // Check to see if there's any data supplied at all - It's hard to check otherwise
+ if( $in[$u] != '' )
+ $data_found = true;
+ $data[$args[$i]] = urldecode($in[$u]);
+ }
+
+ if( $data_found )
+ return( $data );
+ else
+ return( false );
+
+}
+
+
+ // Returns Title text with QuickTip Pop-Up support
+
+function quick_tip( $title, $message )
+{
+
+ if( trim($title) == '' || trim($message) == '' )
+ return( false );
+
+ $t = strip_tags( $title ); // Get rid of any HTML tags in title
+
+ $key = md5($title); // Used as the ID of this QuickTip
+
+ return( '<div id="QuickTip_'.$key.'" class="quicktip">
+ <div class="quicktip-titlebar">
+ <a href="javascript:hide_QuickTip(\'QuickTip_'.$key.'\')"><span class="quicktip-close">Close</span></a>
+ <div class="quicktip-title">QuickTip</div>
+ </div>
+ <div class="quicktip-body">
+ <div class="quicktip-fieldname">'.$t.'</div>
+ '.$message.'
+ </div>
+ </div>
+ <iframe id="Shim_QuickTip_'.$key.'" src="javascript:false;" scrolling="no" frameborder="0" class="quickedit"></iframe>
+ <span onClick="show_QuickTip(\'QuickTip_'.$key.'\',event);" class="quicktip-prompt2">'.$title.'</span>' );
+
+}
+
+ // Returns Title text with QuickEdit Pop-Up support - Uses QuickTip Java functions
+
+function quick_edit( $key, $prompt, $form )
+{
+ if( trim($prompt) == '' || trim($form) == '' )
+ return( false );
+
+ $t = strip_tags( $prompt ); // Get rid of any HTML tags in title
+
+ return( '<div id="QuickEdit_'.$key.'" class="quickedit">
+ <div class="quicktip-titlebar">
+ <a href="javascript:hide_QuickTip(\'QuickEdit_'.$key.'\')"><span class="quickedit-close">Close</span></a>
+ <div class="quickedit-title">QuickEdit</div>
+ </div>
+ <div class="quickedit-body">
+ '.$form.'
+ </div>
+ </div>
+ <iframe id="Shim_QuickEdit_'.$key.'" src="javascript:false;" scrolling="no" frameborder="0" class="quickedit"></iframe>
+ <span onClick="show_QuickTip(\'QuickEdit_'.$key.'\',event);" class="quickedit-prompt2">'.$prompt.'</span>' );
+
+}
+
+
+/*=======================================================================
+
+ CATEGORY SUPPORT FUNCTIONS
+
+=======================================================================*/
+
+ // Returns PL/pgSQL category_path support function for specified data table
+
+function category_path_func( $table_name )
+{
+
+ // Stick table name in function
+
+ return( str_replace ( '{TABLE_NAME}', $table_name, "
+
+ /*
+ Function category_path( int )
+
+ Returns a ~ delimited string containing...
+ A string to use for sorting by category, sub-cat, sub-sub-cat, ...
+ A | delimited string of the names of the category hierarchy
+ A | delimited string of the id of each step in the category hierarchy
+
+ Use in a query like...
+
+ SELECT *, cateogory_path(id) FROM table_name;
+
+ */
+
+ CREATE OR REPLACE FUNCTION category_path( int ) RETURNS text AS '
+
+ DECLARE
+ this_node ALIAS FOR $1;
+ node RECORD;
+ sort text := '''';
+ path TEXT := '''';
+ ids TEXT := '''';
+ level INT := 0;
+ children RECORD;
+ child_count INT := 0;
+ sort_fix int := 100000; -- Added to sort numbers to make sure sort is pseudo-numeric
+
+ BEGIN
+ SELECT INTO node * FROM {TABLE_NAME} WHERE id = this_node;
+ sort := node.sort + sort_fix || ''_'' || this_node; -- Makes sure sort is numeric
+ path := node.name;
+ ids := node.id;
+ SELECT INTO children COUNT(id) FROM {TABLE_NAME} WHERE parent = this_node;
+ child_count := children.count;
+ IF FOUND THEN
+ WHILE node.parent > 0 LOOP
+ SELECT INTO node * FROM {TABLE_NAME} WHERE id = node.parent;
+ sort := node.sort + sort_fix || ''_'' || node.id || ''_'' || sort;
+ path := node.name || ''|'' || path;
+ ids := node.id || ''|'' || ids;
+ level := level + 1;
+ END LOOP;
+ END IF;
+
+ -- Note: 0 below is to enforce proper ordering by sort field
+ RETURN sort || ''_0~'' || path || ''~'' || ids || ''~'' || level || ''~'' || child_count;
+
+ END;
+
+ ' LANGUAGE plpgsql;
+
+ " ) );
+
+}
+
+ // Get category node
+
+function cat_get_node( $table, $qs = '' )
+{
+
+ // Get specified nodes list
+
+ $query = category_path_func( $table )
+ ."SELECT *, category_path(id) AS cat_path_data FROM $table ".(trim($qs)!=''?" WHERE $qs":"").";";
+
+ if( !($r = db_auto_get_row( $query, 0, SI_CONN_STR, FALSE ) ) )
+ return FALSE;
+
+ // Process node paths into useable arrays
+
+ $p = explode( "~", $r['cat_path_data'] );
+ $r['cat_fullpath'] = $p[1];
+ $r['cat_names'] = explode( "|", $p[1] );
+ $r['cat_id_path'] = $p[2];
+ $r['cat_ids'] = explode( "|", $p[2] );
+ $r['cat_level'] = $p[3];
+
+ return( $r );
+
+}
+
+ // Get array of selected category nodes
+
+function cat_get_nodes( $table, $qs = '', $order = 'cat_path_data' )
+{
+
+ // Get specified nodes list
+
+ $query = category_path_func( $table )
+ ."SELECT *, category_path(id) AS cat_path_data FROM $table ".($qs!=''?" WHERE $qs":"")." ORDER BY $order;";
+
+ if( !($r = db_auto_get_data( $query, SI_CONN_STR, FALSE) ) )
+ return( FALSE );
+
+ // Process node paths into useable arrays
+
+ $num = count( $r );
+
+ while( list($key, $val) = each($r) )
+ {
+ $p = explode( "~", $r[$key]['cat_path_data'] );
+ $r[$key]['cat_fullpath'] = $p[1];
+ $r[$key]['cat_names'] = explode( "|", $p[1] );
+ $r[$key]['cat_id_path'] = $p[2];
+ $r[$key]['cat_ids'] = explode( "|", $p[2] );
+ $r[$key]['cat_level'] = $p[3];
+ }
+
+
+ return( $r );
+
+}
+
+ // Get array of expanded node hierarchy for menus
+
+function cat_get_expanded_nodes( $table, $id )
+{
+
+ // Always get all top level nodes
+
+ $q = 'parent = 0';
+
+ // If target supplied, get siblings and siblings of all parents
+
+ $expanded = array();
+ if( $id > 0 )
+ {
+ $r = cat_get_node( $table, "id = $id" );
+
+ // For each level up, add to query to get all siblings
+
+ if( $r )
+ foreach( $r['cat_ids'] as $c )
+ {
+ $q .= " OR parent = $c";
+ $expanded[$c] = TRUE;
+ }
+ }
+
+ // Get all selected nodes
+
+ if( !($nodes = cat_get_nodes( $table, $q ) ) )
+ return( FALSE ); // If there's no top level nodes, then quit.
+
+ // Set expanded flags for nodes with expanded children
+
+ reset($nodes);
+ while( list($key, $val) = each($nodes) )
+ $nodes[$key]['expanded'] = $expanded[$val['id']] == TRUE;
+
+ // Make array keys the path data string to sort on
+
+ foreach( $nodes as $n )
+ $list[$n['cat_path_data']] = $n;
+
+ // Sort on those keys
+
+ ksort( $list );
+
+ return( $list );
+
+}
+
+
+ // Get array of an entire category tree from target down
+
+function cat_get_tree( $table, $id )
+{
+
+ // Not written
+
+}
+
+ // Resequence category node siblings
+
+function cat_resequence_siblings( $table, $parent )
+{
+
+ // Get all siblings
+
+ if( !($nodes = db_auto_get_data( "SELECT id, sort FROM $table WHERE parent = $parent ORDER BY sort;", SI_CONN_STR, FALSE ) ) )
+ return( FALSE );
+
+ $query = 'BEGIN;';
+
+ $sort = 10;
+
+ foreach( $nodes as $n )
+ {
+ $query .= "UPDATE $table SET sort = $sort WHERE id = ".$n['id'].";";
+ $sort += 10;
+ }
+
+ $query .= 'COMMIT;';
+
+ if( !db_auto_exec( $query, SI_CONN_STR, FALSE ) )
+ return( FALSE );
+
+ return( TRUE );
+
+}
+
+ // Move a category node
+
+/*
+function cat_move_node( $table, $parent )
+{
+
+ NOT WRITTEN YET
+
+}
+*/
+
+
+ // Delete a category node and optionally its children
+
+
+function cat_delete_node( $table, $id, $method = 'node' )
+{
+ // Check submitted data
+
+ if( empty($table) || empty($id) || $id < 1 )
+ return( FALSE );
+
+ // Get parent of node to be deleted
+
+ if( !($target = db_auto_get_row( "SELECT * FROM $table WHERE id = $id;", 0, SI_CONN_STR, FALSE )) )
+ return( FALSE );
+ $new_parent = $target['parent'];
+
+ // Delete target and reassign all children to parent
+
+ if( !db_auto_exec( "BEGIN;
+ DELETE FROM $table WHERE id = $id;
+ UPDATE $table SET parent = $new_parent WHERE parent = $id;
+ COMMIT;", SI_CONN_STR, FALSE ) )
+ return( FALSE );
+
+ return( TRUE );
+}
+
+
+
+/*=======================================================================
+
+ HIGH LEVEL FUNCTIONS
+
+=======================================================================*/
+
+ // Build a numeric picklist
+
+function build_numeric_picklist( $fieldname, $starting, $ending, $selected="", $option="", $class="" )
+{
+ if( $starting > $ending )
+ return( "*** Picklist generation error: build_numeric_piclist() ***" );
+
+ $r = '<SELECT NAME="'.$fieldname.'"'.($class!=''?'class="'.$class.'"':'').'>
+ ';
+
+ if( strstr( $option, 'blank') )
+ $r .= '<OPTION VALUE=""'.(trim($selected)==''?" SELECTED":"").'>';
+
+ for( $i=$starting ; $i<=$ending ; $i++ )
+ $r .= '<OPTION VALUE="'.$i.'"'
+ .( $i==$selected ? " selected" : "" )
+ .'> '.$i.'</OPTION>
+ ';
+
+ $r .= '</SELECT>';
+
+ return( $r );
+
+}
+
+ // Build a picklist
+
+function build_picklist( $fieldname, $data, $selected, $type = "standard", $options = "", $class="" )
+{
+
+ if( !is_array($data) )
+ return( "<FONT COLOR=\"red\">ERROR: build_picklist() data supplied is not an array for field $fieldname.</FONT>\n" );
+
+ // Set default option status
+
+ $option_blank = $option_order = $option_numeric = $option_descending = $option_multi = FALSE;
+
+ // Scan for supplied options
+
+ if( !empty($options) )
+ {
+ $opt_array = explode_trim( "~", $options );
+ foreach( $opt_array as $opt )
+ {
+ switch( $opt )
+ {
+ case "blank":
+ $option_blank = TRUE;
+ break;
+
+ case "numeric":
+ $option_numeric = TRUE;
+ $option_order = TRUE;
+ break;
+
+ case "alpha":
+ $option_numeric = FALSE; // If it's not numeric, it's alpha
+ $option_order = TRUE;
+ break;
+
+ case "descending":
+ $option_descending = TRUE;
+ break;
+
+ case "ascending":
+ $option_descending = FALSE; // If it's not descending, it's ascending
+ break;
+
+ case "multi":
+ $option_multi = TRUE; // Permit multiple select with CTRL or SHIFT
+ break;
+
+ default:
+ return( "<FONT COLOR=\"red\">Illegal build_picklist() option</FONT>\n" );
+ break;
+ }
+ }
+ }
+
+ if( $option_order )
+ {
+ if( $option_descending )
+ { // Sort Descending
+ if( $option_numeric )
+ arsort( $data, SORT_NUMERIC );
+ else
+ arsort( $data, SORT_STRING );
+ }
+ else
+ { // Sort Ascending
+ if( $option_numeric )
+ asort( $data, SORT_NUMERIC );
+ else
+ asort( $data, SORT_STRING );
+ }
+ }
+
+ if( $option_multi )
+ $str = '<SELECT NAME="'.$fieldname.'[]" MULTIPLE SIZE="4"'.($class!=''?'class="'.$class.'"':'').'>';
+ else
+ $str = '<SELECT NAME="'.$fieldname.'"'.($class!=''?'class="'.$class.'"':'').'>';
+
+ if( $option_blank )
+ $str .= " <OPTION VALUE=\"\">\n";
+
+ switch( $type )
+ {
+ case "simple":
+ for( $i=0 ; $i<count($data) ; $i++ )
+ {
+ if( $option_multi )
+ {
+ $sel = FALSE;
+ if( is_array($selected) )
+ {
+ reset( $selected );
+ foreach( $selected as $s )
+ if( $s == $data[$i] )
+ $sel = TRUE;
+ }
+ $str .= " <OPTION VALUE=\"".$data[$i]."\"".($sel?" SELECTED ":"").">".$data[$i]."\n";
+ }
+ else
+ $str .= " <OPTION VALUE=\"".$data[$i]."\"".($data[$i]==$selected?" SELECTED ":"").">".$data[$i]."\n";
+ }
+ break;
+
+ case "standard":
+ default:
+ while( list($key, $val) = each($data) )
+ if( $option_multi )
+ {
+ $sel = FALSE;
+ if( is_array($selected) )
+ {
+ reset( $selected );
+ foreach( $selected as $s )
+ if( $s == $key )
+ $sel = TRUE;
+ }
+ $str .= " <OPTION VALUE=\"$key\"".($sel?" SELECTED ":"").">$val\n";
+ }
+ else
+ $str .= " <OPTION VALUE=\"$key\"".($key==$selected?" SELECTED ":"").">$val\n";
+ break;
+ }
+ $str .= "</SELECT>";
+
+ return( $str );
+
+}
+
+function build_picklist_from_string( $fieldname, $data, $selected, $type = "standard", $options = "" )
+ {
+ $x = explode( '~', $data );
+ $array_data = array();
+ foreach( $x as $y )
+ {
+ $z = explode( '^', $y );
+ $array_data[trim($z[0])] = trim($z[1]);
+ }
+ return( build_picklist( $fieldname, $array_data, $selected, $type, $options ) );
+ }
+
+
+ // Build Radio Buttons
+
+function build_radio_buttons( $fieldname, $data, $selected, $separator = " ", $type = "standard", $options = "" )
+{
+
+ // if $data is neither proper array or data string
+
+ if( !is_array($data) )
+ if( ($data = strtoarray($data)) == FALSE )
+ return( "<FONT COLOR=\"red\">ERROR: build_radio_buttons() Improper data supplied for field \"$fieldname\".</FONT>\n" );
+
+ // Set default option status
+
+ $option_blank = $option_order = $option_numeric = $option_descending = $option_after = FALSE;
+
+ // Scan for supplied options
+
+ if( !empty($options) )
+ {
+ $opt_array = explode_trim( "~", $options );
+ foreach( $opt_array as $opt )
+ {
+ switch( $opt )
+ {
+ case 'numeric':
+ $option_numeric = TRUE;
+ $option_order = TRUE;
+ break;
+
+ case 'alpha':
+ $option_numeric = FALSE; // If it's not numeric, it's alpha
+ $option_order = TRUE;
+ break;
+
+ case 'descending':
+ $option_descending = TRUE;
+ break;
+
+ case 'ascending':
+ $option_descending = FALSE; // If it's not descending, it's ascending
+ break;
+
+ case 'after':
+ $option_after = TRUE;
+ break;
+
+ default:
+// return( "<FONT COLOR=\"red\">ERROR: build_radio_buttons() Illegal option \"$opt\".</FONT>\n" );
+ break;
+ }
+ }
+ }
+
+ if( $option_order )
+ {
+ if( $option_descending )
+ { // Sort Descending
+ if( $option_numeric )
+ arsort( $data, SORT_NUMERIC );
+ else
+ arsort( $data, SORT_STRING );
+ }
+ else
+ { // Sort Ascending
+ if( $option_numeric )
+ asort( $data, SORT_NUMERIC );
+ else
+ asort( $data, SORT_STRING );
+ }
+ }
+
+ $str = $sep = '';
+ while( list($key, $val) = each($data) )
+ {
+ $str .= $sep;
+
+ if( !$after )
+ $str .= $val.' ';
+
+ switch( $type )
+ {
+ case "simple":
+ $str .= '<INPUT TYPE="radio" NAME="'.$fieldname.'" VALUE="'.$val.'" '.($val==$selected?" CHECKED ":"").'>';
+ break;
+ case "standard":
+ $str .= '<INPUT TYPE="radio" NAME="'.$fieldname.'" VALUE="'.$key.'" '.($key==$selected?" CHECKED ":"").'>';
+ break;
+ default:
+ break;
+ }
+
+ if( $after )
+ $str .= ' '.$val;
+
+ $sep = $separator;
+ }
+ return( $str );
+}
+
+ // Create a date input form with a link to a pop-up calendar
+
+function calendar_date_select( $default_value, $selected_date, $start_date,
+ $end_date, $form_name, $field_name, $options = "",
+ $no_earlier = "", $class = "" )
+{
+
+ GLOBAL $si_month_array;
+
+ $months = array( 1=>"Jan",2=>"Feb",3=>"Mar",4=>"Apr",5=>"May",6=>"Jun",7=>"Jul",8=>"Aug",9=>"Sep",10=>"Oct",11=>"Nov",12=>"Dec" );
+
+ $start = getdate( $start_date );
+ $end = getdate( $end_date );
+
+ $form = "<script language=\"JavaScript1.2\">
+ <!--
+ // Detect if the browser is IE or not.
+ // If it is not IE, we assume that the browser is NS.
+
+ var IE = document.all?true:false
+
+ // If NS -- that is, !IE -- then set up for mouse capture
+
+// if (!IE) document.captureEvents(Event.MOUSEMOVE)
+
+ // Set-up to use getMouseXY function onMouseMove
+
+// document.onmousemove = getMouseXY;
+
+ // Temporary variables to hold mouse x-y pos.s
+
+ var tempX = 0
+ var tempY = 0
+
+ // Main function to retrieve mouse x-y pos.s
+
+ function getMouseXY(e)
+ {
+ if (IE)
+ { // grab the x-y pos.s if browser is IE
+ tempX = event.clientX //+ document.body.scrollLeft
+ tempY = event.clientY //+ document.body.scrollTop
+ }
+ else
+ { // grab the x-y pos.s if browser is NS
+ tempX = e.pageX
+ tempY = e.pageY
+ }
+
+ // catch possible negative values in NS4
+
+ if (tempX < 0){tempX = 0}
+ if (tempY < 0){tempY = 0}
+
+ // show the position values in the form named Show
+ // in the text fields named MouseX and MouseY
+ // document.Show.MouseX.value = tempX
+ // document.Show.MouseY.value = tempY
+
+ return true;
+ }
+
+ function calWin_".$field_name."()
+ {
+ // Pass values to the calendar
+
+ tempX = 400
+ tempY = 300
+ ";
+ if( ereg( "PICK", $options ) )
+ $form .= " sd = this.document.$form_name.".$field_name."_month.value + '/' + this.document.$form_name.".$field_name."_day.value + '/' + this.document.$form_name.".$field_name."_year.value;
+ ";
+ else
+ $form .= " sd = this.document.$form_name.$field_name.value;
+ ";
+
+ $form .= " var theUrl='".SI_BASE_URL."/glm_apps/calendar.phtml?selected_date=' + sd + '&start_date=$start_date&end_date=$end_date&form_name=$form_name&field_name=$field_name';
+ ";
+
+ // If a "no_earlier" field is specified, have the script check for a date from other specified field and pass it in the URL
+
+ if( $no_earlier != "" )
+ $form .= "
+ theUrl = theUrl + '&no_earlier=' + this.document.$form_name.$no_earlier.value
+ ";
+ $form .= "
+ tempX = tempX - 90;
+ //tempY = tempY - 170;
+
+ if (navigator.appName == 'Netscape')
+ {
+ calWind = window.open (theUrl, 'Calendar','scrollbars=no,toolbar=no,resizable=no,width=170,height=180,screenx=' + tempX +',screeny=' + tempY,1);
+ }
+ else
+ {
+ calWind = window.open (theUrl, 'Calendar','scrollbars=no,toolbar=no,resizable=no,width=170,height=180, top=' + tempY +', left=' + tempX,1);
+ }
+
+ calWind.focus();
+ }
+ -->
+ </script>
+ ";
+
+ // Handle default date whether it's a string date or a timestamp
+
+ if( is_numeric($default_value) )
+ {
+ $default_timestamp = $default_value;
+ $default_value = date( 'n/j/Y', $default_value );
+ }
+ else
+ $default_timestamp = strtotime( $default_value );
+
+ $default_month = date( "n", $default_timestamp );
+ $default_day = date( "j", $default_timestamp );
+ $default_year = date( "Y", $default_timestamp );
+
+ $class_tag = $class != '' ? 'CLASS="'.$class.'"' : '' ;
+
+ if( ereg( "PICK", $options ) )
+ {
+ $form .= build_picklist( $field_name."_month", $months, $default_month, '', '', $class );
+ $form .= build_numeric_picklist( $field_name."_day", 1, 31, $default_day, '', $class );
+ if( ereg( "HIDE_YEAR", $options ) )
+ $form .= '<INPUT TYPE="hidden" NAME="'.$field_name.'_year" VALUE="'.$default_year.'" '.$class_tag.'>';
+ else
+ $form .= build_numeric_picklist( $field_name."_year", date("Y"), date("Y",$end_date), $default_year, '', $class );
+ $form .= '<INPUT TYPE="hidden" NAME="'.$field_name.'" '.$class_tag.'>';
+ }
+ else
+ $form .= '<INPUT TYPE="text" NAME="'.$field_name.'" SIZE="10" VALUE="'.$default_value.'" '.$class_tag.'>';
+
+ if( !ereg( "NO_PROMPT", $options ) )
+ $form .= " (month/day/year) ";
+
+ $form .= ' <SCRIPT LANGUAGE="javascript">
+ <!--
+ document.write(\'<a href="javascript:calWin_'.$field_name.'()\"><IMG SRC="'.SI_BASE_URL.'/assets/calendar.gif" BORDER="0" ALT="Calendar"></A>\');
+ -->
+ </SCRIPT>
+ ';
+
+ return($form);
+}
+
+ // Build an HTML calendar with data from the array in each date
+
+function calendar_display( $month, $year, $date_data, $headerinfo='', $monthinfo='' )
+{
+ $MonthNames = array(1=>'January','February','March','April','May','June','July','August','September','October','November','December');
+
+/* This seems to be unnecessary
+
+ $calendar ='<script language="javascript">
+ <!--
+ function winMsger(msg)
+ {
+ calWind = window.open (\'\', \'Calendar\',\'scrollbars=no,toolbar=no,resizable=no,width=230,height=230\',1);
+ calWind.document.write("<HTML><TITLE>Calendar</TITLE></HTML>")
+ calWind.document.write("<body bgcolor=\'#FFFFFF\' leftmargin=\'0\' topmargin=\'0\' marginwidth=\'0\' marginheight=\'0\'>")
+ calWind.document.write(msg)
+ calWind.document.write("</BODY></HTML>")
+
+ calWind.focus()
+ }
+ -->
+ </script>
+*/
+
+ $calendar = '
+ <STYLE TYPE="text/css">
+ <!--
+ th { font-size: 12px; background-color: '. SI_CAL_DATE.'; font-weight: bold; }
+ td.h { font-size: 12px; background-color: '. SI_CAL_HEAD.'; }
+ td.n { font-size: 12px; background-color: '. SI_CAL_NODATE.'; }
+ td.d { font-size: 12px; background-color: '. SI_CAL_TODAY.'; }
+// td.t { font-size: 12px; background-color: '. SI_CAL_DATE .'; }
+ td.t { font-size: 12px; }
+ td.z { font-size: 16px; background-color: '. SI_CAL_TABLE .'; }
+ td.f {}
+ //-->
+ </STYLE>
+
+ <TABLE BORDER="1" CELLPADDING="1" CELLSPACING="0" ALIGN="center" BGCOLOR="'. SI_CAL_TABLE.'" WIDTH="98%" HEIGHT="40%">
+ <TR HEIGHT="20">
+ <TD CLASS="z" COLSPAN="7" ALIGN="center"><B>'.(empty($monthinfo)?$MonthNames[$month].' '.$year:$monthinfo).'</B><br>
+ </TD>
+ </TR>
+ ';
+
+ if( !empty($headerinfo) )
+ {
+ $calendar.= '<TR><TD COLSPAN="7">'.$headerinfo.'
+ </TD></TR>
+ ';
+ }
+
+ $calendar.='<TR ALIGN="center" HEIGHT="15">
+ <TH CLASS="h" width="14%">Sun</TH>
+ <TH CLASS="h" width="14%">Mon</TH>
+ <TH CLASS="h" width="14%">Tue</TH>
+ <TH CLASS="h" width="14%">Wed</TH>
+ <TH CLASS="h" width="14%">Thu</TH>
+ <TH CLASS="h" width="14%">Fri</TH>
+ <TH CLASS="h" width="14%">Sat</TH>
+ </TR>
+ <TR ALIGN="left">
+ ';
+
+ // Display blanks up to first day of the month
+
+ $offset = date( "w", mktime( 0, 0, 0, $month, 1, $year ) );
+ if( $offset > 0 )
+ $calendar .= str_repeat( "<TD CLASS=\"n\"> </TD>\n",$offset );
+
+ // For each day of the month
+
+ $NumberOfDays = date( "t", mktime( 0, 0, 0, $month, 1, $year ) );
+ for( $i=1 ; $i<=$NumberOfDays ; $i++ )
+ {
+ $this_date = mktime( 0, 0, 0, $month, $i, $year );
+ $DayOfWeek = date( "w", $this_date );
+
+ // Start a new row each Sunday, unless it's the 1st of the month
+
+ if( $DayOfWeek == 0 && $i != 1 )
+ {
+ $calendar .= '</TR><TR>';
+ }
+
+ if( !empty($date_data[$i]["color"]) )
+ $color = $date_data[$i]["color"];
+ else
+ $color = SI_CAL_DATE;
+
+ $calendar .= '<TD CLASS="t" ALIGN="left" VALIGN="top" BGCOLOR="'.$color.'">';
+
+ if( !empty($date_data[$i]["link"]) )
+ $calendar .= '<A HREF="'.$date_data[$i]["link"].'">'.$i.'</A>';
+ else
+ $calendar .= $i;
+
+ $calendar .= '<BR>';
+
+ if( !empty($date_data[$i]["cell"]) )
+ $calendar .= $date_data[$i]["cell"];
+
+ $calendar .= "</TD>\n";
+ }
+
+
+ if( ( ($offset == 5) && ($NumberOfDays > 30) ) || ( ($offset == 6) && ($NumberOfDays > 29) ) )
+ {
+ if( 42-$NumberOfDays-$offset > 0 )
+ {
+ $calendar .= str_repeat( "<TD CLASS=\"n\"> </TD>\n",42-$NumberOfDays-$offset );
+ }
+ $calendar .= "</TR>\n";
+ }
+ elseif( ($NumberOfDays != 28) || ($offset > 0) )
+ {
+ if (35-$NumberOfDays-$offset > 0)
+ {
+ $calendar .= str_repeat("<TD CLASS=\"n\"> </TD>\n",35-$NumberOfDays-$offset);
+ $calendar .= "</TR>\n";
+ }
+ }
+
+ $calendar .= "</TABLE>\n";
+ return $calendar;
+}
+
+
+ // Get list of counties in a state
+
+function get_us_counties( $state, $fail_mode, $include_any=FALSE )
+{
+
+ $data = db_auto_get_data( "SELECT county FROM county_state WHERE state_code = '$state' ORDER by county;",
+ "host=ds4.gaslightmedia.com dbname=county user=".SI_DB_USER,
+ $fail_mode, 500 );
+
+ if( isset($include_any) && $include_any == TRUE )
+ $counties[""] = "(Any)";
+
+ if( count($data) )
+ {
+ while( list($key, $val) = each($data) )
+ $counties[$val["county"]] = $val["county"];
+ }
+ else
+ $counties = array( "" => "(none)" );
+
+ return( $counties );
+
+}
+
+ // Parse a "view" file to merge in supplied data
+
+function parse_view( $file_name, $tokens, $show_unused = TRUE )
+ {
+ if( !($f = file_get( $file_name ) ) )
+ {
+ if( trim($file_name) == '' )
+ return( "ERROR: No view file name supplied." );
+ else
+ return( "ERROR: View file '$file_name' not found or unreadable." );
+ }
+ $out = parse_string_view( $f, $tokens, $show_unsued = TRUE );
+ return( $out );
+ }
+
+ // Process Lists
+
+function process_view_lists( $f, $tokens, $pvl_level = 0, $pvl_require_list_data = false )
+ {
+
+ // Process list sections
+
+ $out = "";
+
+ $p = 0;
+ while( !(($p2 = strpos( $f, "<!--{list:", $p )) === FALSE )) // While there are still lists
+ {
+ // Start of a list has been found
+
+ $out .= substr( $f, $p, $p2-$p ); // Add portion up to start of list to output
+ $p = $p2 + 10; // Get past list token
+ if( !($p2 = strpos( $f, "}-->", $p )) || $p2 == $p ) // If there's no }--> following it, then something's wrong
+ return( "ERROR: parse_view() - Missing name of {list:name} tag at $p.<P><PRE>".htmlentities(substr($f,$p,500))."</PRE>" );
+ $listname = substr( $f, $p, $p2-$p ); // Get name of this list
+
+ // If list data is required (no empty lists) and we don't have any
+
+ if( $pvl_require_list_data && ( !isset($tokens[$listname]) || !is_array($tokens[$listname]) ) )
+ {
+ $out = "ERROR: parse_view() - No data supplied for list name \"$listname\".";
+ if( SI_DEBUG_VIEW )
+ $out .= "<P> <P><HR><P>Tags supplied to parse_view() function<P>".tableize_array( $tokens );
+ return( $out );
+ }
+
+ $p = $p2 + 4; // Move pointer to start of list
+ if( !($end = strpos( $f, "<!--{/list:".$listname."}-->", $p )) ) // Find end of this list section
+ return( "ERROR: parse_view() - Matching {/list} tag not found at $p.<P><PRE>".htmlentities(substr($f,$p,500))."</PRE>" );
+
+ // Break up list
+
+ unset( $list );
+ $sections = 0;
+ $sep = "";
+ while( ($p2 = strpos( $f, "<!--{sep:".$listname."}-->", $p )) && $p2 < $end ) // While there's still separators in this list
+ {
+ $list[$sections] = substr( $f, $p, $p2-$p ); // Save this segment
+ $p = $p2 + 13 + strlen($listname); // Point past start of separator
+ if( !($p2 = strpos( $f, "<!--{/sep:".$listname."}-->", $p )) || $p2 > $end ) // Find matching {/sep} tag
+ return( "ERROR: parse_view() - Matching {/sep} tag not found at $p.<P><PRE>".htmlentities(substr($f,$p,500))."</PRE>" );
+ if( empty($sep) ) // Only use the first separator
+ $sep = substr( $f, $p, $p2-$p );
+ $p = $p2 + 14 + strlen($listname); // Point past end of {/sep} tag
+ $sections++; // Bump section count
+ }
+
+ $list[$sections] = substr( $f, $p, $end-$p ); // Store last section of list
+ $p = $end + 15 + strlen($listname); // Point past this list
+ $sections++; // Bump section count
+
+ // For each token expected in this list - Compile output
+
+ if( !empty( $tokens[$listname] ) ) // That is if there's any data for the list
+ {
+ $t = count($tokens[$listname]); // Get number of blocks of data
+ $j = 0;
+ foreach( $tokens[$listname] as $to ) // For each block of data supplied
+ {
+ if( !is_array($to) || count($to) == 0 )
+ {
+ $out = "ERROR: parse_view() - List data contains an empty token array for list $listname.";
+ if( SI_DEBUG_VIEW )
+ $out .= "<P> <P><HR><P>Tags supplied to parse_view() function<P>".tableize_array( $tokens );
+ return( $out );
+ }
+ $x = replace_tokens( $list[$j%$sections], $to ); // Replace tokens in appropriate section
+ $x = process_view_lists( $x, $to, $pvl_level+1, $pvl_require_list_data ); // Process any sub-lists
+ $out .= cond_replace_tokens( $x, $to ); // Do conditional replacements also
+
+ if( ++$j < $t ) // If there's more data, output sep
+ $out .= $sep;
+ }
+ }
+ }
+
+ $out .= substr( $f, $p ); // Now add remainder of page
+ return( $out );
+ }
+
+
+ // Parse a "view" string to mearge in supplied data
+
+function parse_string_view( $f, $tokens, $show_unused = TRUE )
+ {
+
+ if( empty($f) )
+ return( "ERROR: View string not provided." );
+
+ // Replace all {include:filename}
+
+ while( !( ($p2 = strpos( $f, '<!--{include:' )) == FALSE ) ) // While there's file includes
+ {
+
+ $p = $p2 + 13; // Save the position of the start of the filename
+
+ // Look for the end of this tag
+
+ if( !( $p2 = strpos($f, "}-->", $p)) || $p2 == $p ) // If there's no }--> following it, then something's wrong
+ return ("ERROR: parse_view() - Missing name of {include:filename} tag at $p.<P><PRE>".htmlentities(substr($f, $p, 500))."</PRE>");
+
+ // Read in the specified file
+
+ $filename = substr($f, $p, $p2 - $p); // Get name of the specified file
+ if( !($inc_file = file_get( SI_BASE_PATH.'/'.$filename)) )
+ return ("ERROR: parse_view() - Target of {include:filename} tag does not exist or is unreadable at $p.<P><PRE>".htmlentities(substr($f, $p-13, 500))."</PRE>");
+
+ // Replace the tag with the file contents
+
+ $f = str_replace( '<!--{include:'.$filename.'}-->', $inc_file, $f );
+
+ }
+
+ // Tear out {exclude} ... {/exclude} regions
+
+ $f = preg_replace( "/<!--\\{exclude\\}-->.*?<!--\\{\/exclude\\}-->/s", "", $f );
+
+ // Remove comments from around any {INCLUDE ... /INCLUDE} regions
+
+ $f = str_replace( "<!--{include}", "", $f );
+ $f = str_replace( "{/include}-->", "", $f );
+
+ // Insert any specified files
+ $f = replace_file_tokens( $f );
+
+ // Replace all global tokens
+ $f = replace_tokens( $f, $tokens["global"] );
+
+ // Do conditional replacements for global tokens
+
+ $f = cond_replace_tokens( $f, $tokens["global"] );
+
+ $out = process_view_lists( $f, $tokens );
+
+ if( $show_unused )
+ $out = preg_replace( "/(\\{\S*?\\})/", "<FONT COLOR=\"red\"><BLINK>\\1</BLINK></FONT>", $out );
+
+ if( SI_DEBUG_VIEW )
+ $out .= "<P> <P><HR><P>Tags supplied to parse_view() function<P>".tableize_array( $tokens );
+
+ return( $out );
+
+}
+
+
+ // MagicForm - Edit Form
+
+function magic_form_edit( $mf_id, $mf_format, $mf_level = 0 )
+ {
+
+//
+// Needed Enhancements
+//
+// Calculated fields - based on results from other fields
+//
+
+/* data1 field description
+ *
+ * {title}~{subform_id}~{misc_data}|{title}~{subform_id}~{misc_data}|...
+ *
+ */
+
+
+ global $mf_field_id, $mf_action, $mf_position, $mf_field_id, $mf_field_option, $mf_option_id, $mf_option_name, $mf_option_value, $mf_option_value_type, $mf_position, $mf_position_num,
+ $mf_field_text, $mf_field_image, $mf_field_image_name, $mf_field_image_delete, $mf_field_imagesize, $mf_field_title, $mf_field_descr, $form_data, $link_data, $mf_type, $mf_style, $mf_styles, $mf_action_id,
+ $mf_field_cols, $mf_field_rows, $mf_custom_id, $mf_field_file, $mf_field_file_name, $mf_field_file_delete,
+ $mf_formats, $mf_format_type, $mf_format_char, $mf_format_dec, $mf_format_min, $mf_format_max, $mf_def_val;
+
+ // Always pass along the current form/sub-form with any action requests
+
+ $mf_form_data = '<input type="hidden" name="mf_action_id" value="'.$mf_id.'">';
+ $mf_link_data = '&mf_action_id='.$mf_id;
+
+ $r['success'] = false; // Assume a failed return
+ $r['modified'] = false; // Assume we're not modifying the form - This is set to true for anything that changes the form in a way that old form results can't be used anymore.
+ $r['text'] = ''; // With no text
+
+ // If we have a field ID then get data for that too
+
+ if( !empty($mf_field_id) && ($mf_field_data = db_auto_get_row( "SELECT * FROM ".MF_TABLE." WHERE id = $mf_field_id;", 0, SI_CONN_STR, FALSE )) )
+ $mf_field_data1 = $mf_field_data['data1'];
+ else
+ $mf_field_data1 = '';
+
+ $mf_normalize = false;
+ $mf_custom_id_update_message = '';
+
+ //
+ // Process Actions
+ //
+
+ if( $mf_action_id == $mf_id )
+ switch( $mf_action )
+ {
+
+ case "Add Field":
+
+ // Add new field with default data
+
+ // $r['modified'] = true;
+ $oid = db_auto_exec( "INSERT INTO ".MF_TABLE." ( form_id, title, type, active, required, sort, expanded, style, format, file, cols, rows )
+ VALUES ( '$mf_id', '', 0, 't', 'f', $mf_position, 't', 'Default', '', '', 20, 4 );", SI_CONN_STR, FALSE );
+ $f = db_auto_get_row( "SELECT id FROM ".MF_TABLE." WHERE OID = $oid;", 0, SI_CONN_STR, FALSE ); // Get new field ID
+ $mf_field_id = $f['id'];
+ $mf_normalize = true;
+ break;
+
+ case "Set Type":
+
+ // $r['modified'] = true;
+
+ // Determine default style format for this type - First format that can be used for this type
+
+ reset( $mf_styles );
+ while( list($key, $val) = each($mf_styles) )
+ if( strstr( $val['types'], ' '.$mf_type.' ' ) )
+ {
+ $mf_style .= $key;
+ break;
+ }
+
+ db_auto_exec( "UPDATE ".MF_TABLE." SET type = $mf_type, style = '$mf_style' WHERE id = $mf_field_id;", SI_CONN_STR, FALSE );
+ if( $mf_type == 1 ) // IF checkbox
+ db_auto_exec( "UPDATE ".MF_TABLE." SET data1 = 'Yes~~~|No~~~' WHERE id = $mf_field_id;", SI_CONN_STR, FALSE );
+ break;
+
+ case "Set Style":
+
+ // $r['modified'] = true;
+ db_auto_exec( "UPDATE ".MF_TABLE." SET style = '$mf_style' WHERE id = $mf_field_id;", SI_CONN_STR, FALSE );
+ break;
+
+ case "Set Field Format":
+
+ // $r['modified'] = true;
+ $x = $mf_format_type.'~'.$mf_format_char.'~'.$mf_format_dec.'~'.$mf_format_min.'~'.$mf_format_max;
+ db_auto_exec( "UPDATE ".MF_TABLE." SET format = '$x' WHERE id = $mf_field_id;", SI_CONN_STR, FALSE );
+ break;
+
+ case "Add Option":
+
+ // $r['modified'] = true;
+ if( trim($mf_field_option) == '' )
+ break;
+
+ if( !empty($mf_field_data1) )
+ $x = $mf_field_data1."|".$mf_field_option."~~";
+ else
+ $x = $mf_field_option."~~";
+
+ db_auto_exec( "UPDATE ".MF_TABLE." SET data1 = '".addslashes($x)."' WHERE id = $mf_field_id;", SI_CONN_STR, FALSE );
+ break;
+
+ case "Add Subform":
+
+ // $r['modified'] = true;
+ $x = explode( "|", $mf_field_data1 );
+ $y = explode( "~", $x[$mf_option_id] );
+ $x[$mf_option_id-1] = $y[0]."~$mf_id.$mf_field_id.".time().'~'.$y[2];
+ $mf_field_data1 = implode( "|", $x );
+ db_auto_exec( "UPDATE ".MF_TABLE." SET data1 = '".addslashes($mf_field_data1)."' WHERE id = $mf_field_id;", SI_CONN_STR, FALSE );
+ break;
+
+ case "Delete Subform":
+
+ // $r['modified'] = true;
+ $x = explode( "|", $mf_field_data1 );
+ $y = explode( "~", $x[$mf_option_id-1] );
+ $x[$mf_option_id-1] = $y[0].'~~'.$y[2];
+ $mf_field_data1 = implode( "|", $x );
+
+ // Delete any Images or Files associated with these fields
+
+ if( ($del_fields = db_auto_get_data( "SELECT * FROM ".MF_TABLE." WHERE form_id LIKE '".$y[1]."%';" )) )
+ {
+ foreach( $del_fields as $d )
+ {
+ switch( $d['type'] )
+ {
+ case 24: // Image
+ delete_image( $d['file'] );
+ break;
+ case 25: // File
+ file_delete( $d['file'] );
+ break;
+ default:
+ break;
+ }
+ }
+ }
+
+ db_auto_exec( "DELETE FROM ".MF_TABLE." WHERE form_id LIKE '".$y[1]."%'; UPDATE ".MF_TABLE." SET data1 = '".addslashes($mf_field_data1)."' WHERE id = $mf_field_id;", SI_CONN_STR, FALSE );
+ break;
+
+ case "Edit Option Name":
+
+ // $r['modified'] = true;
+ $x = explode( "|", $mf_field_data1 );
+ $y = explode( "~", $x[$mf_option_id-1] );
+ $x[$mf_option_id-1] = $mf_option_name.'~'.$y[1].'~'.$y[2].'~'.$y[3];
+ $mf_field_data1 = implode( "|", $x );
+ db_auto_exec( "UPDATE ".MF_TABLE." SET data1 = '".addslashes($mf_field_data1)."' WHERE id = $mf_field_id;", SI_CONN_STR, FALSE );
+ break;
+
+ case "Edit Option Value":
+
+ // $r['modified'] = true;
+ $x = explode( "|", $mf_field_data1 );
+ $y = explode( "~", $x[$mf_option_id-1] );
+ $x[$mf_option_id-1] = $y[0].'~'.$y[1].'~'.$mf_option_value.'~'.$mf_option_value_type;
+ $mf_field_data1 = implode( "|", $x );
+ db_auto_exec( "UPDATE ".MF_TABLE." SET data1 = '".addslashes($mf_field_data1)."' WHERE id = $mf_field_id;", SI_CONN_STR, FALSE );
+ break;
+
+ case "Delete Option":
+
+ $r['modified'] = true;
+ $x = explode( "|", $mf_field_data1 );
+ $y = explode( "~", $x[$mf_option_id-1] );
+ array_splice( $x, $mf_option_id-1, 1 );
+ $mf_field_data1 = implode( "|", $x );
+
+ // Delete any Images or Files associated with these fields
+
+ if( ($del_fields = db_auto_get_data( "SELECT * FROM ".MF_TABLE." WHERE form_id LIKE '".$y[1].".%';" )) )
+ {
+ foreach( $del_fields as $d )
+ {
+ switch( $d['type'] )
+ {
+ case 24: // Image
+ delete_image( $d['file'] );
+ break;
+ case 25: // File
+ file_delete( $d['file'] );
+ break;
+ default:
+ break;
+ }
+ }
+ }
+
+ // Delete any sub-forms and update this field data
+
+ db_auto_exec( "DELETE FROM ".MF_TABLE." WHERE form_id LIKE '".$y[1].".%'; UPDATE ".MF_TABLE." SET data1 = '".addslashes($mf_field_data1)."' WHERE id = $mf_field_id;", SI_CONN_STR, FALSE );
+ break;
+
+ case "Move Option Up":
+
+ // If option position isn't already at the top
+ if( $mf_option_id-1 != 0 )
+ {
+ $r['modified'] = true;
+ $x = explode( "|", $mf_field_data1 );
+ $y = array();
+ for( $i=0 ; $i<count($x) ; $i++ )
+ {
+ if( $i == $mf_option_id-1 )
+ $y[$i*10-15] = $x[$i];
+ else
+ $y[$i*10] = $x[$i];
+ }
+ ksort($y);
+ $mf_field_data1 = implode( "|", $y );
+ db_auto_exec( "UPDATE ".MF_TABLE." SET data1 = '".addslashes($mf_field_data1)."' WHERE id = $mf_field_id;", SI_CONN_STR, FALSE );
+ }
+ break;
+
+ case "Move Option Down":
+ $x = explode( "|", $mf_field_data1 );
+ // If option position isn't already at the bottom
+ if( $$mf_option_id-1 != count($x)-1 )
+ {
+ $r['modified'] = true;
+ $y = array();
+ for( $i=0 ; $i<count($x) ; $i++ )
+ {
+ if( $i == $mf_option_id-1 )
+ $y[$i*10+15] = $x[$i];
+ else
+ $y[$i*10] = $x[$i];
+ }
+ ksort($y);
+ $mf_field_data1 = implode( "|", $y );
+ db_auto_exec( "UPDATE ".MF_TABLE." SET data1 = '".addslashes($mf_field_data1)."' WHERE id = $mf_field_id;", SI_CONN_STR, FALSE );
+ }
+ break;
+
+ case "Toggle Active":
+
+ // $r['modified'] = true;
+ db_auto_exec( "UPDATE ".MF_TABLE." SET active = '".($mf_field_data['active']=='t'?'f':'t')."' WHERE id = $mf_field_id;", SI_CONN_STR, FALSE );
+ break;
+
+ case "Toggle Required":
+
+ // $r['modified'] = true;
+ db_auto_exec( "UPDATE ".MF_TABLE." SET required = '".($mf_field_data['required']=='t'?'f':'t')."' WHERE id = $mf_field_id;", SI_CONN_STR, FALSE );
+ break;
+
+ case "Toggle Expanded":
+
+ db_auto_exec( "UPDATE ".MF_TABLE." SET expanded = '".($mf_field_data['expanded']=='t'?'f':'t')."' WHERE id = $mf_field_id;", SI_CONN_STR, FALSE );
+ break;
+
+ case "Expand All":
+
+ db_auto_exec( "UPDATE ".MF_TABLE." SET expanded = 't' WHERE form_id = '$mf_id';", SI_CONN_STR, FALSE );
+ break;
+
+ case "Contract All":
+
+ db_auto_exec( "UPDATE ".MF_TABLE." SET expanded = 'f' WHERE form_id = '$mf_id';", SI_CONN_STR, FALSE );
+ break;
+
+ case "Reposition":
+
+ if( !empty( $mf_position_num ) )
+ {
+ if( clean_input( 'mf_position_num', 'int', true ) == '' )
+ {
+ $mf_position = $mf_position_num * 10;
+ if( $mf_position > $mf_field_data['sort'] )
+ $mf_position += 1;
+ else
+ $mf_position -= 1;
+ }
+ else
+ break;
+ }
+
+ // $r['modified'] = true;
+ db_auto_exec( "UPDATE ".MF_TABLE." SET sort = $mf_position WHERE id = $mf_field_id;", SI_CONN_STR, FALSE );
+ $mf_normalize = true;
+ break;
+
+ case "Update Text":
+
+ // $r['modified'] = true;
+ db_auto_exec( "UPDATE ".MF_TABLE." SET data1 = '".addslashes($mf_field_text)."' WHERE id = $mf_field_id;", SI_CONN_STR, FALSE );
+ break;
+
+ case "Update Field":
+
+ // $r['modified'] = true;
+ $other_fields = '';
+ if( $mf_field_data['type'] >= 2 && $mf_field_data['type'] <= 4 ) $other_fields .= ', cols = '.$mf_field_cols;
+ if( $mf_field_data['type'] == 4 ) $other_fields .= ', rows = '.$mf_field_rows;
+ if( $mf_field_data['type'] == 2 || $mf_field_data['type'] == 3 ) $other_fields .= ", default_val = '$mf_def_val'";
+ db_auto_exec( "UPDATE ".MF_TABLE." SET title = '".addslashes($mf_field_title)."', descr = '".addslashes($mf_field_descr)."'$other_fields WHERE id = $mf_field_id;", SI_CONN_STR, FALSE );
+ break;
+
+ case "Update Image":
+
+ // $r['modified'] = true;
+ $new_image = '';
+ $image_update = false;
+
+ // if there's an existing image and we're either deleting or replacing it
+ if( $mf_field_data['file'] != '' && ( $mf_field_image_delete == 'on' || $mf_field_image_name != '' ) )
+ {
+ delete_image( $mf_field_data['file'] );
+ $image_update = true;
+ }
+
+ // If there's an image supplied
+ if( $mf_field_image_name != '' )
+ {
+ $new_image = process_image( $mf_field_image, $mf_field_image_name );
+ $image_update = true;
+ }
+
+ if( $image_update )
+ db_auto_exec( "UPDATE ".MF_TABLE." SET file = '".addslashes($new_image)."', size = '$mf_field_imagesize' WHERE id = $mf_field_id;", SI_CONN_STR, FALSE );
+ else
+ db_auto_exec( "UPDATE ".MF_TABLE." SET size = '$mf_field_imagesize' WHERE id = $mf_field_id;", SI_CONN_STR, FALSE );
+
+
+ break;
+
+ case "Update File":
+
+ $existing_filename = $mf_field_data['file'];
+
+ $new_filename = trim($mf_field_file_name);
+
+ // If delete is requested or there's a new file upload AND there's an existing file, then delete the old one
+
+ if( ( $mf_field_file_delete == 'on' || $new_filename != '' ) && $existing_filename != '' )
+ {
+ file_delete( $existing_filename );
+ $existing_filename ='';
+ }
+
+ if( $mf_field_file != '' )
+ {
+ if( !($new_filename = file_upload( $mf_field_file, $new_filename )) )
+ $new_filename = '';
+ }
+ else
+ $new_filename = $existing_filename;
+
+ db_auto_exec( "UPDATE ".MF_TABLE." SET file = '".addslashes($new_filename)."' WHERE id= $mf_field_id;" );
+
+ break;
+
+ case "Set Custom ID":
+
+ // $r['modified'] = true;
+ $mf_custom_id = trim($mf_custom_id);
+
+ if( $mf_custom_id != '' && db_auto_get_row( "SELECT id FROM ".MF_TABLE." WHERE form_id = '$mf_id' AND custom_id = '$mf_custom_id';" ) )
+ $mf_custom_id_update_message = 'ID in Use.';
+ else
+ db_auto_exec( "UPDATE ".MF_TABLE." SET custom_id = '".trim($mf_custom_id)."' WHERE id = $mf_field_id;" );
+
+ break;
+
+ case "Set Default":
+
+ db_auto_exec( "UPDATE ".MF_TABLE." SET default_val = '".$mf_def_val."' WHERE id = $mf_field_id;" );
+
+ break;
+
+ case "Delete":
+
+ // $r['modified'] = true;
+
+ // Delete any Images or Files associated with these fields
+
+ if( ($del_fields = db_auto_get_data( "SELECT * FROM ".MF_TABLE." WHERE form_id LIKE '$mf_id.%' OR id = $mf_field_id;" )) )
+ {
+ foreach( $del_fields as $d )
+ {
+ switch( $d['type'] )
+ {
+ case 24: // Image
+ delete_image( $d['file'] );
+ break;
+ case 25: // File
+ file_delete( $d['file'] );
+ break;
+ default:
+ break;
+ }
+ }
+ }
+
+ db_auto_exec( "DELETE FROM ".MF_TABLE." WHERE form_id LIKE '$mf_id.$mf_field_id.%' OR id = $mf_field_id;", SI_CONN_STR, FALSE );
+ break;
+
+ default:
+ break;
+ }
+
+ // If we need to normalize the sort numbers
+
+ if( $mf_normalize )
+ {
+ $mf_data = db_auto_get_data( "SELECT id, sort FROM ".MF_TABLE." WHERE form_id = '$mf_id' ORDER BY sort;", SI_CONN_STR, FALSE );
+ $qs = 'BEGIN;'.$nl;
+ $i = 10;
+ foreach( $mf_data as $mf )
+ {
+ $qs .= "UPDATE ".MF_TABLE." SET sort = ".$i." WHERE ID = ".$mf['id'].";\n";
+ $i += 10;
+ }
+ db_auto_exec( $qs."COMMIT;", SI_CONN_STR, FALSE );
+ }
+
+ //
+ // Display current form status
+ //
+
+ $font_size = '100%'; // Font size percentage to use for form elements
+
+ $mf_bgcolor = ($mf_level % 2);
+
+ $r['text'] .= '<TABLE BORDER="4" RULES="GROUPS" CELLPADDING="2" CELLSPACING="0" width="95%" BGCOLOR="'.($mf_bgcolor == 1?'#D1F1F1':'#ffffff').'">'.$nl;
+
+ if( ($mf_fields = db_auto_get_data( "SELECT * FROM ".MF_TABLE." WHERE form_id = '$mf_id' ORDER BY sort;", SI_CONN_STR, FALSE )) )
+ {
+
+ foreach( $mf_fields as $mf )
+ {
+
+ $base_form_data = '<FORM ACTION="'.SI_THIS_SCRIPT.'" ENCTYPE="multipart/form-data" METHOD="post" >
+ '.$form_data.$mf_form_data.'
+ <INPUT TYPE="hidden" NAME="mf_field_id" VALUE="'.$mf['id'].'">
+ ';
+
+ $mf_data = $mf_text = $mf_type_text = '';
+
+ $mf_title_req = false;
+
+ switch( $mf['type'] )
+ {
+ // Checkbox
+
+ case 1:
+ $mf_data .= '<BR>';
+ $mf_type_text = 'Checkbox';
+ $mf_data .= '<TABLE BORDER="0" WIDTH="100%" CELLPADDING="2" CELLSPACING="0" RULES="GROUPS">';
+ if( !empty($mf['data1']) )
+ {
+
+ $mf_data1 = explode( "|", $mf['data1'] );
+ for( $i=1 ; $i<=count($mf_data1) ; $i++ )
+ {
+
+ $x = explode( "~", $mf_data1[$i-1] );
+
+ // Set option value output format
+
+ if( trim($x[2]) != '' )
+ switch( $x[3] )
+ {
+ case 1: $xv = money($x[2]); break;
+ default: $xv = $x[2]; break;
+ }
+ else
+ $xv = '(no value)';
+
+ $mf_data .= '<TR>
+ <TD ALIGN="left" VALIGN="top" CLASS="standout">Option: '.$x[0].'</TD>
+ <TD ALIGN="right" VALIGN="top" CLASS="standout">Value: '
+ .quick_edit( $mf['id'].'.'.$i, $xv,
+ '<CENTER>'.$base_form_data.'
+ <INPUT TYPE="hidden" NAME="mf_option_id" VALUE="'.$i.'">
+ Option value: <INPUT TYPE="text" NAME="mf_option_value" STYLE="font-size: '.$font_size.';" VALUE="'.$x[2].'" SIZE="10">
+ Value Type: <SELECT NAME="mf_option_value_type"><OPTION VALUE="0"'.($x[3]==0?' SELECTED':'').'>Number</OPTION><OPTION VALUE="1"'.($x[3]==1?' SELECTED':'').'>Money</OPTION></SELECT><br>
+ <INPUT TYPE="submit" NAME="mf_action" VALUE="Edit Option Value" STYLE="font-size: '.$font_size.';">
+ </FORM></CENTER>' )
+ .'</TD>
+ <TD ALIGN="right">
+ '.( $x[1] == '' ?
+ '<A HREF="'.SI_THIS_SCRIPT.'?Action=Ref_Edi&'.$link_data.$mf_link_data.'&mf_action=Add+Subform&mf_field_id='.$mf['id'].'&mf_option_id='.$i.'">[Sub-Form]</A>'
+ :
+ '<A HREF="'.SI_THIS_SCRIPT.'?Action=Ref_Edi&'.$link_data.$mf_link_data.'&mf_action=Delete+Subform&mf_field_id='.$mf['id'].'&mf_option_id='.$i.'">[Delete Sub-Form]</A>'
+ ).'
+ <A HREF="'.SI_THIS_SCRIPT.'?Action=Ref_Edi&'.$link_data.$mf_link_data.'&mf_action=Move+Option+Up&mf_field_id='.$mf['id'].'&mf_option_id='.$i.'" ><b>↑</b></A>
+ <A HREF="'.SI_THIS_SCRIPT.'?Action=Ref_Edi&'.$link_data.$mf_link_data.'&mf_action=Move+Option+Down&mf_field_id='.$mf['id'].'&mf_option_id='.$i.'"><b>↓</b></A>
+ ';
+
+ $mf_data .= '</TD>
+ </TR>';
+ if( $i == $mf['default_val'] )
+ $mf_data .= '<TR><TD ALIGN="left" VALIGN="top" CLASS="standout_small" COLSPAN="3">Default Selection</TD></TR>';
+ else
+ $mf_data .= '<TR><TD ALIGN="left" VALIGN="top" CLASS="standout_small" COLSPAN="3"><A HREF="'.SI_THIS_SCRIPT.'?Action=Ref_Edi&'.$link_data.$mf_link_data.'&mf_action=Set+Default&mf_field_id='.$mf['id'].'&mf_def_val='.$i.'">Set as default selection</A></TD></TR>';
+
+ if( $x[1] != '' )
+ {
+ $rs = magic_form_edit( $x[1], $mf_format, $mf_level+1 );
+ if( $rs['success'] )
+ $mf_data .= '<TR><TD COLSPAN="3" ALIGN="right">'.$rs['text'].'</TD></TR>';
+ if( $rs['modified'] )
+ $r['modified'] = true;
+ }
+ $mf_data .= ''.$nl;
+ }
+ }
+ $mf_data .= '</TABLE>';
+ $mf_title_req = true;
+ break;
+
+ // Number
+
+ case 2:
+ $mf_type_text = 'Number';
+ $mf_title_req = true;
+ break;
+
+ // Text field
+
+ case 3:
+ $mf_type_text = 'Text';
+ $mf_title_req = true;
+ break;
+
+ // Text Box
+
+ case 4:
+ $mf_type_text = 'Text Box';
+ $mf_title_req = true;
+ break;
+
+ // Picklist
+
+ case 5:
+
+ // Radio Buttons
+
+ case 6:
+
+ switch( $mf['type'] )
+ {
+ case 5: $mf_type_text = 'Picklist'; break;
+ case 6: $mf_type_text = 'Radio Buttons'; break;
+ }
+
+ $mf_data .= '<TABLE BORDER="0" WIDTH="100%" CELLPADDING="2" CELLSPACING="0" RULES="GROUPS">';
+ if( !empty($mf['data1']) )
+ {
+ $mf_data1 = explode( "|", $mf['data1'] );
+ for( $i=1 ; $i<=count($mf_data1) ; $i++ )
+ {
+ $x = explode( "~", $mf_data1[$i-1] );
+
+ // Set option value output format
+
+ if( trim($x[2]) != '' )
+ switch( $x[3] )
+ {
+ case 1: $xv = money($x[2]); break;
+ default: $xv = $x[2]; break;
+ }
+ else
+ $xv = '(no value)';
+
+ $mf_data .= '<TR>
+ <TD ALIGN="left" VALIGN="top" CLASS="standout">'
+ .quick_edit( $mf['id'].'.'.$i, 'Option: '.stripslashes($x[0]),
+ '<CENTER>'.$base_form_data.'
+ <INPUT TYPE="hidden" NAME="mf_option_id" VALUE="'.$i.'">
+ <INPUT TYPE="text" NAME="mf_option_name" STYLE="font-size: '.$font_size.';" VALUE="'.stripslashes($x[0]).'" SIZE="50"><BR>
+ <INPUT TYPE="submit" NAME="mf_action" VALUE="Edit Option Name" STYLE="font-size: '.$font_size.';">
+ </FORM></CENTER>' )
+ .'</TD>
+ <TD ALIGN="right" VALIGN="top" CLASS="standout">Value: '
+ .quick_edit( $mf['id'].'.'.$i."_value", $xv,
+ '<CENTER>'.$base_form_data.'
+ <INPUT TYPE="hidden" NAME="mf_option_id" VALUE="'.$i.'">
+ Option value: <INPUT TYPE="text" NAME="mf_option_value" STYLE="font-size: '.$font_size.';" VALUE="'.$x[2].'" SIZE="10">
+ Value Type: <SELECT NAME="mf_option_value_type"><OPTION VALUE="0"'.($x[3]==0?' SELECTED':'').'>Number</OPTION><OPTION VALUE="1"'.($x[3]==1?' SELECTED':'').'>Money</OPTION></SELECT><br>
+ <INPUT TYPE="submit" NAME="mf_action" VALUE="Edit Option Value" STYLE="font-size: '.$font_size.';">
+ </FORM></CENTER>' )
+ .'</TD>
+ <TD ALIGN="right">
+ '.( $x[1] == '' ?
+ '<A HREF="'.SI_THIS_SCRIPT.'?Action=Ref_Edi&'.$link_data.$mf_link_data.'&mf_action=Add+Subform&mf_field_id='.$mf['id'].'&mf_option_id='.$i.'">[Sub-Form]</A>'
+ :
+ '<A HREF="'.SI_THIS_SCRIPT.'?Action=Ref_Edi&'.$link_data.$mf_link_data.'&mf_action=Delete+Subform&mf_field_id='.$mf['id'].'&mf_option_id='.$i.'">[Delete Sub-Form]</A>'
+ ).'
+ <A HREF="'.SI_THIS_SCRIPT.'?Action=Ref_Edi&'.$link_data.$mf_link_data.'&mf_action=Delete+Option&mf_field_id='.$mf['id'].'&mf_option_id='.$i.'">[delete]</A>
+ <A HREF="'.SI_THIS_SCRIPT.'?Action=Ref_Edi&'.$link_data.$mf_link_data.'&mf_action=Move+Option+Up&mf_field_id='.$mf['id'].'&mf_option_id='.$i.'" ><b>↑</b></A>
+ <A HREF="'.SI_THIS_SCRIPT.'?Action=Ref_Edi&'.$link_data.$mf_link_data.'&mf_action=Move+Option+Down&mf_field_id='.$mf['id'].'&mf_option_id='.$i.'"><b>↓</b></A>
+ ';
+
+ $mf_data .= '</TD>
+ </TR>';
+
+ if( $i == $mf['default_val'] )
+ $mf_data .= '<TR><TD ALIGN="left" VALIGN="top" CLASS="standout_small" COLSPAN="3">Default Selection</TD></TR>';
+ else
+ $mf_data .= '<TR><TD ALIGN="left" VALIGN="top" CLASS="standout_small" COLSPAN="3"><A HREF="'.SI_THIS_SCRIPT.'?Action=Ref_Edi&'.$link_data.$mf_link_data.'&mf_action=Set+Default&mf_field_id='.$mf['id'].'&mf_def_val='.$i.'">Set as default selection</A></TD></TR>';
+
+ if( $x[1] != '' )
+ {
+ $rs = magic_form_edit( $x[1], $mf_format, $mf_level+1 );
+ if( $rs['success'] )
+ $mf_data .= '<TR><TD COLSPAN="3" ALIGN="right">'.$rs['text'].'</TD></TR>';
+ if( $rs['modified'] )
+ $r['modified'] = true;
+
+ }
+ $mf_data .= ''.$nl;
+ }
+ }
+ else
+ $mf_data .= '<TR><TD COLSPAN="3" ALIGN="left"><FONT COLOR="red">No options selected yet.</FONT></TD></TR>'.$nl;
+
+ $mf_data .= '<TR>
+ <TD COLSPAN="3" ALIGN="right">'
+ .quick_edit( '_add_option_'.$mf['id'],
+ '<span class="pseudo_link">[Add Option]</a>',
+ '<CENTER>'.$base_form_data.'
+ <INPUT TYPE="text" NAME="mf_field_option" STYLE="font-size: '.$font_size.';">
+ <INPUT TYPE="submit" NAME="mf_action" VALUE="Add Option" STYLE="font-size: '.$font_size.';">
+ </FORM></CENTER>' )
+ .'</TD><TR>
+ </TABLE>';
+ $mf_title_req = true;
+ break;
+
+ // File Upload
+
+ case 7:
+ $mf_type_text = 'File Upload';
+ $mf_title_req = true;
+ break;
+
+
+ // Section Title
+
+ case 20:
+ $mf_type_text = 'Section Title';
+ $mf_text .= quick_edit( $mf['id'],
+ '<SPAN CLASS="standout">'.($mf['data1']!=''?stripslashes($mf['data1']):'(Section title not set)').'</span>',
+ $base_form_data.'<TABLE BORDER="0">
+ <TR>
+ <TD> </TD>
+ <TD ALIGN="right" VALIGN="top">Title:</TD>
+ <TD ALIGN="left" COLSPAN="3" VALIGN="top"><INPUT TYPE="text" NAME="mf_field_text" VALUE="'.$mf['data1'].'" STYLE="font-size: '.$font_size.';" SIZE="80"></TD>
+ </TR>
+ </TABLE>
+ <CENTER><INPUT TYPE="submit" NAME="mf_action" VALUE="Update Text" STYLE="font-size: '.$font_size.';"></CENTER>
+ </FORM>
+ ' );
+
+
+ break;
+
+ // Misc. Text
+
+ case 21:
+ $mf_type_text = 'Misc. Text';
+ $mf_text .= quick_edit( $mf['id'],
+ ( $mf['data1'] != '' ?
+ ( $mf['expanded'] == 't' ?
+ stripslashes($mf['data1'])
+ :
+ substr( stripslashes($mf['data1']), 0, 225 ).' ...'
+ )
+ :
+ '<SPAN CLASS="standout">(Misc. text not set)</SPAN>'
+ ),
+ $base_form_data.'<TABLE BORDER="0">
+ <TR>
+ <TD> </TD>
+ <TD ALIGN="right" VALIGN="top">Misc. Text:</TD>
+ <TD ALIGN="left" COLSPAN="3" VALIGN="top"><TEXTAREA NAME="mf_field_text" STYLE="font-size: '.$font_size.';" COLS="60" ROWS="4">'.$mf['data1'].'</TEXTAREA></TD>
+ </TR>
+ </TABLE>
+ <CENTER><INPUT TYPE="submit" NAME="mf_action" VALUE="Update Text" STYLE="font-size: '.$font_size.';"></CENTER>
+ </FORM>
+ ' );
+ break;
+
+ // Horizontal Line
+
+ case 22:
+ $mf_type_text = 'Horiz Line';
+ $mf_text = '<hr>';
+ break;
+
+ // Blank Line
+
+ case 23:
+ $mf_type_text = 'Blank Line';
+ $mf_text .= '(a blank line)';
+ break;
+
+ // Display Image
+
+ case 24:
+ $mf_type_text = 'Image';
+ switch( $mf['size'] )
+ {
+ case 'original': $image_size_url = SI_IMG_ORIGINAL_URL; break;
+ case 'resized': $image_size_url = SI_IMG_RESIZED_URL; break;
+ case 'midsized': $image_size_url = SI_IMG_MIDSIZED_URL; break;
+ default:
+ case 'thumb': $image_size_url = SI_IMG_THUMB_URL; break;
+ }
+
+ $mf_data .= quick_edit( $mf['id'].'_image',
+ ( $mf['file'] != '' ?
+ '<img src="'.$image_size_url.'/'.$mf['file'].'">'
+ :
+ '<SPAN CLASS="standout">(Image not set)</SPAN>'
+ ),
+ $base_form_data.'<TABLE BORDER="0" width="100%">
+ <TR>
+ <TD COLSPAN="2" align="center">'.( $mf['file'] != '' ? '<img src="'.SI_IMG_THUMB_URL.'/'.$mf['file'].'">':'(no image)').'</TD>
+ </TR>
+ <TR>
+ <TD ALIGN="right">Delete existing Image:</TD>
+ <TD ALIGN="left"><INPUT TYPE="checkbox" NAME="mf_field_image_delete"></TD>
+ </TR>
+ <TR>
+ <TD ALIGN="right">Image Size:</TD>
+ <TD ALIGN="left">
+ <SELECT NAME="mf_field_imagesize">
+ <OPTION VALUE="original"'.($mf['size']=='original'?' SELECTED':'').'>Original</OPTION>
+ <OPTION VALUE="resized"'.($mf['size']=='resized'?' SELECTED':'').'>Resized</OPTION>
+ <OPTION VALUE="midsized"'.($mf['size']=='midsized'?' SELECTED':'').'>Midsized</OPTION>
+ <OPTION VALUE="thumb"'.($mf['size']=='thumb'?' SELECTED':'').'>Thumbnail</OPTION>
+ </SELECT>
+ </TD>
+ </TR>
+ <TR>
+ <TD ALIGN="right">Select Image:</TD>
+ <TD ALIGN="left"><INPUT TYPE="file" NAME="mf_field_image"></TD>
+ </TR>
+ </TABLE>
+ <CENTER><INPUT TYPE="submit" NAME="mf_action" VALUE="Update Image" STYLE="font-size: '.$font_size.';"></CENTER>
+ </FORM>
+ ' );
+ break;
+
+ // File Download
+
+ case 25:
+
+ $mf_type_text = 'File Download';
+ $mf_data .= quick_edit( $mf['id']."_file",
+ ( $mf['file'] != '' ?
+ '<SPAN CLASS="standout">File: '.$mf['file'].'</SPAN>'
+ :
+ '<SPAN CLASS="standout">(File not provided)</SPAN>'
+ ),
+ $base_form_data.'<TABLE BORDER="0" width="100%">'
+ .( $mf['file'] != '' ?
+ '<TR>
+ <TD ALIGN="right" VALIGN="top">Current File:</TD>
+ <TD ALIGN="left" COLSPAN="2">
+ <a href="'.SI_BASE_FILE_URL.'/'.$mf['file'].'" target="file_page">'.$mf['file'].'</a>
+ <INPUT TYPE="checkbox" NAME="mf_field_file_delete"> Delete this file
+ </TD>
+ </TR>
+ <TR><TD COLSPAN="2"> </TD></TR>
+ ' : '' ).'
+ <TR>
+ <TD ALIGN="right" VALIGN="top">Upload/Replace File:</TD>
+ <TD ALIGN="left" COLSPAN="2" VALIGN="top"><INPUT TYPE="file" NAME="mf_field_file"></TD>
+ </TR>
+ </TABLE>
+ <CENTER><INPUT TYPE="submit" NAME="mf_action" VALUE="Update File" STYLE="font-size: '.$font_size.';"></CENTER>
+ </FORM>
+ ' );
+
+ break;
+
+ // Calculated field
+
+ case 31:
+ // Not yet implimented
+ break;
+
+ case 0:
+ default:
+ $mf_data = ' ';
+
+ break;
+ }
+
+ // Build list of available styles for this field
+
+ $mf_style_list = '';
+ reset( $mf_styles );
+ while( list($key, $val) = each($mf_styles) )
+ if( strstr( $val['types'], ' '.$mf['type'].' ' ) )
+ $mf_style_list .= '<option value="'.$key.'"'.($mf['style']==$key?' SELECTED':'').'>'.$key.'</option>';
+
+ // Extract current format info and build list of possible formats for this field
+
+ $mf_cf = explode( '~', $mf['format'] );
+ $mf_format_list = '';
+ reset( $mf_formats );
+ while( list($key, $val) = each($mf_formats) )
+ if( strstr( $val['types'], ' '.$mf['type'].' ' ) )
+ $mf_format_list .= '<option value="'.$key.'"'.($mf_cf[0]==$key?' SELECTED':'').'>'.$key.'</option>';
+
+ // Display Title, descr, and optionally size with QuickEdit pop-up
+
+ if( $mf['type'] > 0 && ( $mf['type'] < 20 || $mf['type'] == 24 || $mf['type'] == 25 ) )
+ $mf_text .= quick_edit( $mf['id'],
+ '<SPAN CLASS="standout">Title: '.stripslashes($mf['title']).'</SPAN>'
+ .( $mf['expanded'] == 't' ?
+ '<BR>
+ <SPAN CLASS="standout_small">Descr: '.stripslashes($mf['descr'])
+ .( $mf['type'] >= 2 && $mf['type'] <= 4 ?
+ '<BR>Columns: '.$mf['cols']
+ .( $mf['type'] == 4 ?
+ '<BR>Rows: '.$mf['rows']
+ : '' )
+ : '' )
+ .( $mf['type'] >= 2 && $mf['type'] <= 3 ?
+ '<BR>Default Value: '.$mf['default_val']
+ : '' )
+ : '' ),
+ $base_form_data.'<TABLE BORDER="0">
+ <TR>
+ <TD> </TD>
+ <TD ALIGN="right" VALIGN="top">Title:</TD>
+ <TD ALIGN="left" COLSPAN="3" VALIGN="top"><INPUT TYPE="text" NAME="mf_field_title" VALUE="'.stripslashes($mf['title']).'" STYLE="font-size: '.$font_size.';" SIZE="70"></TD>
+ </TR>
+ <TR>
+ <TD> </TD>
+ <TD ALIGN="right" VALIGN="top">Descr:</TD>
+ <TD ALIGN="left" COLSPAN="3" VALIGN="top"><TEXTAREA NAME="mf_field_descr" STYLE="font-size: '.$font_size.';" COLS="67" ROWS="3">'.stripslashes($mf['descr']).'</TEXTAREA></TD></TR>
+ </TR>
+ '.( $mf['type'] >= 2 && $mf['type'] <= 4 ? '
+ <TR>
+ <TD> </TD>
+ <TD ALIGN="right" VALIGN="top">Columns:</TD>
+ <TD ALIGN="left" COLSPAN="3" VALIGN="top"><INPUT TYPE="text" NAME="mf_field_cols" VALUE="'.$mf['cols'].'" STYLE="font-size: '.$font_size.';" SIZE="6"> </TD></TR>
+ </TR>
+ '.( $mf['type'] == 4 ? '
+ <TR>
+ <TD> </TD>
+ <TD ALIGN="right" VALIGN="top">Rows:</TD>
+ <TD ALIGN="left" COLSPAN="3" VALIGN="top"><INPUT TYPE="text" NAME="mf_field_rows" VALUE="'.$mf['rows'].'" STYLE="font-size: '.$font_size.';" SIZE="6"> </TD></TR>
+ </TR>
+ ' : '' ).'
+ ' : '' ).'
+ '.( $mf['type'] >= 2 && $mf['type'] <= 3 ? '
+ <TR>
+ <TD> </TD>
+ <TD ALIGN="right" VALIGN="top">Default Value:</TD>
+ <TD ALIGN="left" COLSPAN="3" VALIGN="top"><INPUT TYPE="text" NAME="mf_def_val" VALUE="'.$mf['default_val'].'" STYLE="font-size: '.$font_size.';" SIZE="30"> </TD></TR>
+ </TR>
+ ' : '' ).'
+ </TABLE>
+ <CENTER><INPUT TYPE="submit" NAME="mf_action" VALUE="Update Field" STYLE="font-size: '.$font_size.';"></CENTER>
+ </FORM>
+ ' );
+
+
+ $r['text'] .= '<TBODY>
+ <TR>
+ <TD VALIGN="top" WIDTH="100" ROWSPAN="2">'
+ .'<form action="'.SI_THIS_SCRIPT.'"'.$form_data.$mf_form_data.'
+ <input type="hidden" name="mf_action" value="Reposition">
+ <input type="hidden" name="mf_field_id" value="'.$mf['id'].'">
+ <INPUT TYPE="text" NAME="mf_position_num" ID="mf_field_'.$mf['id'].'" VALUE="'.($mf['sort']/10).'" SIZE="5" onChange="submit();" > '
+ .'<A HREF="'.SI_THIS_SCRIPT.'?'.$link_data.$mf_link_data.'&mf_action=Reposition&mf_field_id='.$mf['id'].'&mf_position='.( $mf['sort'] - 15 ).'">↑</A> '
+ .'<A HREF="'.SI_THIS_SCRIPT.'?'.$link_data.$mf_link_data.'&mf_action=Reposition&mf_field_id='.$mf['id'].'&mf_position='.( $mf['sort'] + 15 ).'">↓</A>
+ ';
+ if( $mf['expanded'] == 't' )
+ {
+ $r['text'] .= ' <BR>
+ <span class="standout_small">'
+ .( $mf_type_text != '' ?
+ $mf_type_text
+ .'</span><BR>
+ <span class="standout_small">'
+ .quick_edit( $mf['id']."_style",
+ $mf_styles[$mf['style']]['short_name'],
+ '<CENTER>
+ <FORM NAME="set_style" ACTION="'.SI_THIS_SCRIPT.'">
+ '.$form_data.$mf_form_data.'
+ Set style For this field:
+ <input type="hidden" name="mf_field_id" value="'.$mf['id'].'">
+ <SELECT NAME="mf_style">
+ '.$mf_style_list.'
+ </SELECT>
+ <INPUT TYPE="submit" NAME="mf_action" VALUE="Set Style">
+ </form>
+ </CENTER>' ).'
+ </span><BR>
+ '.( $mf_format_list != '' ? '
+ <span class="standout_small">'
+ .quick_edit( $mf['id']."_format",
+ ( $mf_cf[0] != '' ? $mf_formats[$mf_cf[0]]['short_name'] : 'Default Format' ),
+ '<CENTER>
+ <FORM NAME="set_format" ACTION="'.SI_THIS_SCRIPT.'">
+ '.$form_data.$mf_form_data.'
+ <table border="0">
+ <tr>
+ <td align="right">Format Type: </td>
+ <td align="left"><input type="hidden" name="mf_field_id" value="'.$mf['id'].'">
+ <SELECT NAME="mf_format_type">
+ '.$mf_format_list.'
+ </SELECT>
+ </td>
+ </tr>
+ <tr>
+ <td align="right">Maximum Characters/Digits to left of decimal point: </td>
+ <td align="left"><INPUT TYPE="text" NAME="mf_format_char" VALUE="'.$mf_cf[1].'" SIZE="6"></td>
+ </tr>
+ <tr>
+ <td align="right">Digits after Decimal Point: </td>
+ <td align="left"><INPUT TYPE="text" NAME="mf_format_dec" VALUE="'.$mf_cf[2].'" SIZE="6"></td>
+ </tr>
+ <tr>
+ <td align="right">Number Range: </td>
+ <td align="left"><INPUT TYPE="text" NAME="mf_format_min" VALUE="'.$mf_cf[3].'" SIZE="6"> Min <INPUT TYPE="text" NAME="mf_format_max" VALUE="'.$mf_cf[4].'" SIZE="6"> Max</td>
+ </tr>
+ <tr><td colspan="2" align="center">(Note: Not all fields used for all format types.)</td></tr>
+ <tr><td colspan="2" align="center"><INPUT TYPE="submit" NAME="mf_action" VALUE="Set Field Format"></td></tr>
+ </table>
+ </form>
+ </CENTER>' ).'
+ </span><BR>
+ ' : '' ).'
+ <span class="standout_small"><nobr>ID: '
+ .quick_edit( $mf['id']."_id",
+ ( $mf['custom_id'] != '' ? $mf['custom_id'] : 'mf_'.$mf['id'] ),
+ '<CENTER>
+ <FORM NAME="set_style" ACTION="'.SI_THIS_SCRIPT.'">
+ '.$form_data.$mf_form_data.'
+ Custom ID:
+ <input type="hidden" name="mf_field_id" value="'.$mf['id'].'">
+ <input type="text" name="mf_custom_id" value="'.$mf['custom_id'].'" size="15"><br>
+ Clear to reset to default ID.<P>
+ <INPUT TYPE="submit" NAME="mf_action" VALUE="Set Custom ID">
+ </form>
+ </CENTER>' ).'
+ </nobr></span><BR>'.( $mf_custom_id_update_message != '' ? '<font color="red">'.$mf_custom_id_update_message.'</font><br>' : '' ).'
+ ' :
+ quick_edit( $mf['id'],
+ '<font color="red">Type Not Set</font>',
+ '<CENTER>
+ <FORM NAME="add_field" ACTION="'.SI_THIS_SCRIPT.'">
+ '.$form_data.$mf_form_data.'
+ <font color="red">Set field type: </font>
+ <input type="hidden" name="mf_field_id" value="'.$mf['id'].'">
+ <SELECT NAME="mf_type">
+ <OPTION VALUE="1">Checkbox
+ <OPTION VALUE="2">Number
+ <OPTION VALUE="3">Text
+ <OPTION VALUE="4">Text Box
+ <OPTION VALUE="5">Picklist
+ <OPTION VALUE="6">Radio Buttons
+ <OPTION VALUE="7">File Upload
+ <OPTION VALUE="20">Section Title
+ <OPTION VALUE="21">Misc. Text
+ <OPTION VALUE="22">Horizontal Line
+ <OPTION VALUE="23">Blank Line
+ <OPTION VALUE="24">Display Image
+ <OPTION VALUE="25">Download File
+ <!-- <OPTION VALUE="31">Calculated Field (currently dissabled) -->
+ </SELECT>
+ <INPUT TYPE="submit" NAME="mf_action" VALUE="Set Type">
+ </form>
+ </CENTER>' ).'<br>
+ <font color="red">Field Style Not Set</font>'
+ ).'<br>
+
+ <A HREF="'.SI_THIS_SCRIPT.'?'.$link_data.$mf_link_data.'&mf_action=Toggle+Active&mf_field_id='.$mf['id'].'">'.( $mf['active'] == 't' ? 'Active' : '<FONT COLOR="#c0c0c0">Active</FONT>' ).' </A><br>
+ '.( $mf['type'] > 1 && $mf['type'] < 20 ? '<A HREF="'.SI_THIS_SCRIPT.'?'.$link_data.$mf_link_data.'&mf_action=Toggle+Required&mf_field_id='.$mf['id'].'">'.($mf['required']=='t'?'Required':'<FONT COLOR="#c0c0c0">Required</FONT>').'</A> ':' ').'
+
+ ';
+ }
+
+ $r['text'] .= '</TD>
+ ';
+
+ if( !empty($mf_text) )
+ $r['text'] .= ' <TD ALIGN="left" VALIGN="top">'.$mf_text.'</TD>';
+ else
+ $r['text'] .= ' <TD> </TD>';
+
+ $r['text'] .= ' <TD VALIGN="top" ALIGN="right">
+ '.( $mf['expanded'] == 't' ?
+ '<A HREF="'.SI_THIS_SCRIPT.'?'.$link_data.$mf_link_data.'&mf_action=Toggle+Expanded&mf_field_id='.$mf['id'].'">[Contract]</A><BR>
+ <A HREF="'.SI_THIS_SCRIPT.'?'.$link_data.$mf_link_data.'&mf_action=Delete&mf_field_id='.$mf['id'].'">[Delete]</A> <BR>
+ <A HREF="'.SI_THIS_SCRIPT.'?'.$link_data.$mf_link_data.'&mf_action=Add+Field&mf_position='.( $mf['sort'] - 5 ).'"><nobr>[Add Above]</nobr></A> '
+ :
+ '<A HREF="'.SI_THIS_SCRIPT.'?'.$link_data.$mf_link_data.'&mf_action=Toggle+Expanded&mf_field_id='.$mf['id'].'">[Expand]</A>'
+ ).'
+ </TD>
+ </TR>
+ '.( $mf['expanded'] == 't' ? '<TR><TD VALIGN="top" COLSPAN="3">'.$mf_data.'</TD></TR>' : '<TR><TD COLSPAN="3"></TD></TR>' ).'
+ </TBODY>
+ ';
+ }
+ }
+
+
+ $r['text'] .= '<TR><TD COLSPAN="3" ALIGN="right">
+ <A HREF="'.SI_THIS_SCRIPT.'?'.$link_data.$mf_link_data.'&mf_action=Add+Field&mf_position=9999">[Add New Field]</A>
+ <A HREF="'.SI_THIS_SCRIPT.'?'.$link_data.$mf_link_data.'&mf_action=Expand+All">[Expand All]</A>
+ <A HREF="'.SI_THIS_SCRIPT.'?'.$link_data.$mf_link_data.'&mf_action=Contract+All">[Contract All]</A>
+ </TD></TR></TABLE>
+ ';
+ $r['success'] = true;
+
+ return( $r );
+
+ }
+
+ // MagicForm - Display Form
+
+function magic_form_display( $mf_id, $mf_styles, $mf_fiid = null, $mf_def_data = array(), $mf_level = 0 )
+ {
+
+ global $mf_formats;
+
+ // Get the fields specifications for the specified form
+
+ $mf_fields = db_auto_get_data( "SELECT * FROM ".MF_TABLE." WHERE form_id = '$mf_id' ORDER BY sort;", SI_CONN_STR, FALSE );
+
+ // If this is level 0, get any data supplied from earlier form submissions, if level > 0 then use data we already have
+
+ if( $mf_fiid != null )
+ $mf_data = db_auto_get_data( "SELECT * FROM ".MF_DATA_TABLE." WHERE fiid = '$mf_fiid' ORDER BY sort;", SI_CONN_STR, FALSE );
+ else
+ $mf_data = &$mf_def_data;
+
+ // Initialize results array
+
+ $r = array( 'success' => true, 'text' => '', 'required' => false );
+
+ $mf_level++; // Incriment MagicForm recurse level (not shure why we're doing this though)
+ $problem = '';
+ $current_style = '';
+ $current_collumn = 1;
+
+ if( is_array($mf_fields) )
+ {
+
+ reset( $mf_fields );
+ foreach( $mf_fields as $mf )
+ {
+
+ if( $mf['active'] == 't' )
+ {
+
+ //
+ // Style/Layout Stuff
+ //
+
+ // Determine format spec
+
+ $f = $mf_styles[$mf['style']]; // just use default for now and assume 1 col/row
+
+ // Check if we're switching styles and handle accordingly
+
+ if( $current_style != $mf['style'] )
+ {
+ // If this is not the first style
+ if( $current_style != '' )
+ {
+ // If not at the last column, fill with blank cells
+ if( $current_column < $mf_styles[$current_style]['cols'] )
+ for( $i=$current_column ; $i<=$mf_styles[$current_style]['cols'] ; $i++ )
+ $r['text'] .= $mf_styles[$current_style]['col_empty'];
+ $r['text'] .= $mf_styles[$current_style]['row_end'].$mf_styles[$current_style]['end'];
+ }
+
+ // Set new style and output start and row headder
+ $current_style = $mf['style'];
+ $r['text'] .= $f['start'].$f['row_start'];
+ $current_collumn = 1;
+ }
+
+ // Check if we need to start a new row
+
+ if( $current_collumn++ > $f['cols'] )
+ {
+ $r['text'] .= $f['row_end'].$f['row_start'];
+ $current_collumn = 1;
+ }
+
+ //
+ // End of Style/Layout stuff
+ //
+
+ $view_tags = array ( "global" => array() );
+ $v = &$view_tags["global"];
+
+ $field_name = 'mf_'.$mf['id']; // Name we're going to use for this field
+ $v['title'] = stripslashes($mf['title']);
+ $v['descr'] = stripslashes($mf['descr']);
+ $v['required'] = '';
+ if( $mf['type'] > 1 && $mf['type'] < 20 && $mf['required'] == 't' ) // if field is required, display in red
+ {
+ $v['required'] = 'Yes';
+ $r['required'] = true;
+ }
+ $v['image'] = $v['file'] = $v['input'] = '';
+
+ $GLOBALS['mf_'.$mf['id']] = stripslashes($GLOBALS['mf_'.$mf['id']]); // get current field input data
+
+ $v['sub_forms'] = ''; // Start with no sub-forms
+
+ // Check for default data for this field and use either opt_num or value depending on type
+
+ if( is_array($x=$mf_def_data[$mf['id']]) )
+ switch( $mf['type'] )
+ {
+ case 1: // Checkbox
+ case 5: // Picklist
+ case 6: // Radio Buttons
+ $inp = $x['opt_num'];
+ break;
+ default:
+ $inp = $x['value'];
+ break;
+ }
+ else
+ $inp = $mf['default_val']; // Otherwise use defaut data
+
+ // Extract field format specs and replace occurances of {chars} and {prec}
+
+ $mf_cf = explode( '~', $mf['format'] );
+ $mf_cf_size = $mf_cf[1] + ($mf_cf[2]>0?1:0) + $mf_cf[2];
+ $mf_cf_out = str_replace( '{chars}', $mf_cf[1], $mf_formats[$mf_cf[0]]['format'] );
+ $mf_cf_out = str_replace( '{prec}', $mf_cf[2], $mf_cf_out );
+
+ if( $mf_cf_out == '' ) // If nothing specified, default to simple string out
+ $mf_cf_out = '%s';
+
+ switch( $mf['type'] )
+ {
+
+ case 1: // Checkbox
+
+ // Build most of checkbox input tag but leave open for rest of JAVAscript onChange text
+
+ $v['input'] = '<INPUT TYPE="checkbox" NAME="'.$field_name.'" id="'.$field_name.'" '.($inp=='1'?' CHECKED':'').' onClick="';
+ $ans = explode( "|", $mf['data1'] ); // Separate answers
+
+ if( $inp == '' ) $inp = 0; // Default to false
+ $xv = '';
+
+ // Check response for subform ($i=1 - Yes, $i=2 - No)
+ for( $i=1 ; $i<=2 ; $i++ )
+ {
+ $an = explode( '~', $ans[$i-1] );
+
+ // Check for a sub-form
+
+ if( !empty($an[1]) )
+ {
+ $sub = magic_form_display( $an[1], $mf_styles, null, $mf_def_data, $mf_level );
+ if( $sub['success'] )
+ {
+ $v['sub_forms'] .= '<div id="'.$field_name.'_'.$i.'" style="display: '.($inp==$i?'block':'none').';"> '.str_replace( "{sub_form}", $f['sub_form'], $sub['text'] ).'</div>';
+ $v['input'] .= "document.getElementById('".$field_name."_$i').style.display = document.getElementById('".$field_name."').checked == ".($i==1?'true':'false')." ? 'block' : 'none'; ";
+ }
+ else
+ $v['sub_forms'] .= '<p><font color="red">FORM ERROR</font>: Unable to process sub-form for checkbox: '.$mf['title'].'<p>';
+ }
+
+ // Optionally set value if this is the "Yes" option
+
+ if( $i==0 && $an[2] != '' )
+ switch( $an[3] )
+ {
+ case 1: $xv .= " ".money($an[2]); break;
+ default: $xv .= " ".$an[2]; break;
+ }
+
+ }
+
+ $v['input'] .= '"> '.$xv; // Close onChange string
+
+ break;
+
+ case 2: // Number
+ case 3: // Text
+ $inp = trim( str_replace( array( '|', '~' ), '', $inp ) );
+ $v['input'] = '<INPUT TYPE="text" NAME="mf_'.$mf['id'].'" VALUE="'.trim(sprintf( $mf_cf_out, $inp )).'" SIZE="'.$mf['cols'].'" '.($mf_cf_size>0?' maxlength="'.$mf_cf_size.'"':'').'>';
+ break;
+
+ case 4: // Text Box
+ $inp = trim( str_replace( array( '|', '~' ), '', $inp ) );
+ $v['input'] = '<TEXTAREA NAME="mf_'.$mf['id'].'" COLS="'.$mf['cols'].'" rows="'.$mf['rows'].'">'.$inp.'</TEXTAREA>';
+ break;
+
+ case 5: // Picklist
+ $opts = explode( "|", $mf['data1'] );
+ $sel = '<SELECT NAME="mf_'.$mf['id'].'" id="'.$field_name.'" onChange="';
+ $sel_opts = '<OPTION VALUE="" '.($inp==''?'SELECTED':'').'>';
+ $n = 1;
+ foreach( $opts as $opt )
+ {
+ $an = explode( "~", $opt );
+
+ $sel_opts .= '<OPTION VALUE="'.$n.'"';
+ if( $inp == $n )
+ $sel_opts .= ' SELECTED';
+ if( !empty($an[1]) )
+ {
+ $sub = magic_form_display( $an[1], $mf_styles, null, $mf_def_data, $mf_level );
+ if( $sub['success'] )
+ {
+ $v['sub_forms'] .= '<div id="'.$field_name.'_'.$n.'" style="display: '.($n==$inp?'block':'none').';"> '.str_replace( "{sub_form}", $f['sub_form'], $sub['text'] ).'</div>';
+ $sel .= "document.getElementById('".$field_name."_$n').style.display = document.getElementById('".$field_name."').value == '".$n."' ? 'block' : 'none'; ";
+ }
+ else
+ $v['sub_forms'] .= '<p><font color="red">FORM ERROR</font>: Unable to process sub-form for picklist: '.$mf['title'].'<p>';
+ }
+ $n++;
+ $sel_opts .= '> '.$an[0];
+
+ // Optionally set value if this is the "Yes" option
+
+ if( $an[2] != '' )
+ switch( $an[3] )
+ {
+ case 1: $sel_opts .= " - ".money($an[2]); break;
+ default: $sel_opts .= " - ".$an[2]; break;
+ }
+
+ }
+ $v['input'] .= $sel.'">'.$sel_opts.'</SELECT>';
+ break;
+
+ case 6: // Radio Buttons
+ $opts = explode( "|", $mf['data1'] );
+ $sel = '';
+ $n = 1;
+ $sub_func = ' <script language="JavaScript1.2"> function f_'.$field_name.'(v){ ';
+ foreach( $opts as $opt )
+ {
+ $an = explode( "~", $opt );
+ $sel .= '<NOBR><INPUT TYPE="radio" NAME="mf_'.$mf['id'].'" VALUE="'.$n.'"';
+ if( $inp == $n )
+ $sel .= ' CHECKED';
+ $sel .= ' onClick="f_'.$field_name."('".$n."'); \"";
+ if( !empty($an[1]) )
+ {
+ $sub_func .= " document.getElementById('".$field_name.'_'.$n."').style.display = v == '".$n."' ? 'block': 'none'; ";
+ $sub = magic_form_display( $an[1], $mf_styles, null, $mf_def_data, $mf_level );
+ if( $sub['success'] )
+ $v['sub_forms'] .= '<div id="'.$field_name.'_'.$n.'" style="display: '.($n==$inp?'block':'none').';"> '.str_replace( "{sub_form}", $f['sub_form'], $sub['text'] ).'</div>';
+ else
+ $v['sub_forms'] .= '<p><font color="red">FORM ERROR</font>: Unable to process sub-form for radio buttons: '.$mf['title'].'<p>';
+ }
+ $n++;
+ $sel .= '>'.$an[0];
+
+ // Optionally set value if this is the "Yes" option
+
+ if( $an[2] != '' )
+ switch( $an[3] )
+ {
+ case 1: $sel .= " - ".money($an[2]); break;
+ default: $sel .= " - ".$an[2]; break;
+ }
+
+ $sel .= '</nobr>';
+
+ }
+ $sub_func .= ' } </script>';
+ $v['input'] = $sub_func.$sel;
+ break;
+
+ case 7: // File Upload
+ $inp = trim( str_replace( array( '|', '~' ), '', $inp ) );
+ $v['input'] = '<INPUT TYPE="hidden" NAME="exist_mf_'.$mf['id'].'" value="'.$inp.'">
+ <table border="1">
+ ';
+ if( $inp != '' )
+ $v['input'] .= '<tr><td><a href="'.SI_BASE_FILE_URL.'/'.$inp.'" target="file_page">'.$inp.'</a></td><td><input type="checkbox" name="delete_mf_'.$mf['id'].'"> Delete</td></tr>
+ ';
+ $v['input'] .= '<tr><td colspan="2"><INPUT TYPE="file" NAME="mf_'.$mf['id'].'" VALUE="'.$inp.'" SIZE="'.$mf['cols'].'"></td></tr>
+ </table>';
+ break;
+
+ case 20: // Section Title
+ $v['title'] = stripslashes($mf['data1']);
+ $v['input'] = '';
+ break;
+
+ case 21: // Misc. Text
+ $v['title'] = '';
+ $v['input'] = stripslashes($mf['data1']);
+ break;
+
+ case 24: // Image
+ switch( $mf['size'] )
+ {
+ case 'original': $image_size_url = SI_IMG_ORIGINAL_URL; break;
+ case 'resized': $image_size_url = SI_IMG_RESIZED_URL; break;
+ case 'midsized': $image_size_url = SI_IMG_MIDSIZED_URL; break;
+ default:
+ case 'thumb': $image_size_url = SI_IMG_THUMB_URL; break;
+ }
+
+ $v['image'] = '<u><img src="'.$image_size_url.'/'.$mf['file'].'"></u>';
+ break;
+
+ case 25: // File
+ $v['title'] = '<a href="'.SI_BASE_FILE_URL.'/'.$mf['file'].'" target="file_page">'.(trim($mf['title'])!=''?$mf['title']:$mf['file']).'</a>';
+ break;
+
+ case 22: // Horizontal Line
+ case 23: // Blank Line (space)
+ default:
+ $v['title'] = '';
+ $v['input'] = '';
+ break;
+
+ } // Type
+
+ $r['text'] .= parse_string_view( $f['body'], $view_tags );
+
+ } // Active
+ } // Each field
+
+ // If not at the last column, fill with blank cells before closing
+ if( $current_column < $mf_styles[$current_style]['cols'] )
+ for( $i=$current_column ; $i<=$mf_styles[$current_style]['cols'] ; $i++ )
+ $r['text'] .= $mf_styles[$current_style]['col_empty'];
+ $r['text'] .= $mf_styles[$current_style]['row_end'].$mf_styles[$current_style]['end'];
+ }
+
+ if( !empty($problem) )
+ echo "Problems processing this form.<p>$problem<p>";
+
+ return( $r );
+
+ }
+
+ // MagicForm - Submit Form
+
+function magic_form_submit( $mf_id, $mf_fiid = null, $mf_def_data = null, $mf_level = 0 )
+ {
+
+ global $mf_formats;
+
+ $mf_level++; // Incriment MagicForm recurse level (not shure why we're doing this though)
+
+ // Get form field specifications
+
+ $mf_fields = db_auto_get_data( "SELECT * FROM ".MF_TABLE." WHERE form_id = '$mf_id' ORDER BY sort;", SI_CONN_STR, FALSE );
+
+ // Initialize result array
+
+ $mf_results = array( 'success' => true, 'data' => array(), 'total_value' => 0, 'html' => '', 'csv' => ($mf_level==1?'"ID","Sub Form Level","Title","Type","Data","Value","Valid","Required","Notes"'."\n":''), 'problem' => '' );
+
+ $problem = '';
+ $current_collumn = 1;
+
+ $mf_total_value = 0; // Accumulates a total of the optional value data for checkboxes, picklists, and radio buttons
+
+ if( is_array($mf_fields) )
+ {
+
+ reset( $mf_fields );
+ foreach( $mf_fields as $mf )
+ {
+
+ // If it's a supplied data field and it's active
+
+ if( $mf['type'] < 20 && $mf['active'] == 't' )
+ {
+
+ // Determine Field ID
+
+ $mf_field_id = ( $mf['custom_id'] != '' ? $mf['custom_id'] : 'mf_'.$mf['id'] );
+
+ // If we didn't get previously submitted data
+
+ if( $mf_def_data == null )
+ $inp = stripslashes(str_replace("\r",'',trim($GLOBALS['mf_'.$mf['id']]))); // Get form input value
+ else
+ $inp = $mf_def_data[$mf_field_id]; // Get value from supplied array
+
+ $res = array
+ (
+ 'id' => $mf_field_id,
+ 'level' => $mf_level,
+ 'title' => $mf['title'],
+ 'type' => $mf['type'],
+ 'txt_typ' => '',
+ 'value' => '',
+ 'txt_val' => '',
+ 'opt_num' => '',
+ 'valid' => true,
+ 'required' => false,
+ 'numb_val' => '',
+ 'failure' => ''
+ );
+
+ // Set text for field type
+
+ switch( $mf['type'] )
+ {
+ case 1: $res['txt_typ'] = 'Checkbox'; break;
+ case 2: $res['txt_typ'] = 'Number'; break;
+ case 3: $res['txt_typ'] = 'Text'; break;
+ case 4: $res['txt_typ'] = 'Text Box'; break;
+ case 5: $res['txt_typ'] = 'Pick List'; break;
+ case 6: $res['txt_typ'] = 'Radio Buttons'; break;
+ case 7: $res['txt_typ'] = 'File Upload'; break;
+ default: break;
+ }
+
+ $sub = ''; // Assume no sub-form
+
+ // *** SHOULD PROBABLY CHECK DATA INPUT INTEGRITY HERE
+
+ // Check if a required field is not populated
+
+ if( $mf['type'] > 1 && $mf['type'] < 20 && $mf['required'] == 't' )
+ {
+ $res['required'] = true;
+ if( $inp == '' || ($mf_type['type']==7 && $inp=='none') ) // if field is required and not provided
+ {
+ $res['valid'] = false;
+ $res['failure'] = 'Required response not provided.';
+ $mf_results['problem'] .= '<li>"'.$mf['title'].'" requires a response that was not provided.</li>'."\n";
+ }
+ }
+
+ switch( $mf['type'] )
+ {
+
+ case 1: // Checkbox
+
+ $ans = explode( "|", $mf['data1'] ); // Separate possible answers
+
+ $sub_id = '';
+
+ if( $inp == 'on' )
+ {
+ $res['value'] = 't';
+ $res['txt_val'] = 'Yes';
+ $res['opt_num'] = '1';
+ $an = explode( '~', $ans[0] );
+ $sub_id = $an[1];
+ if( $an[2] != '' )
+ $res['numb_val'] = $an[2];
+
+ }
+ else
+ {
+ $res['value'] = 'f';
+ $res['txt_val'] = 'No';
+ $res['opt_num'] = '2';
+ $an = explode( '~', $ans[1] );
+ $sub_id = $an[1];
+ if( $an[2] != '' )
+ $res['numb_val'] = $an[2];
+ }
+
+ if( $sub_id != '' )
+ {
+ $sub = magic_form_submit( $sub_id, $mf_fiid, $mf_def_data, $mf_level );
+ if( !$sub['success'] )
+ $mf_results['problem'] .= $sub['problem'];
+ else
+ $mf_total_value += $sub['total_value'];
+ }
+
+ break;
+
+ case 2: // Number
+
+ $inp = ereg_replace( "[\$,]", "", $inp );
+
+ case 3: // Text
+ case 4: // Text Box
+
+ // Extract field format specs
+
+ $mf_cf = explode( '~', $mf['format'] );
+ $mf_cf_size = $mf_cf[1] + ($mf_cf[2]>0?1:0) + $mf_cf[2];
+ $mf_cf_out = str_replace( '{chars}', $mf_cf[1], $mf_formats[$mf_cf[0]]['format'] );
+ $mf_cf_out = str_replace( '{prec}', $mf_cf[2], $mf_cf_out );
+
+ if( trim($inp) != '' )
+ {
+ if( $mf_cf[3] != '' && $inp < $mf_cf[3] )
+ {
+ $res['valid'] = false;
+ $res['failure'] .= 'Value not in range';
+ $mf_results['problem'] .= '<li>"'.$mf['title'].'" requires a value greater than or equal to '.$mf_cf[3].'.</li>'."\n";
+ }
+
+ if( $mf_cf[4] != '' && $inp > $mf_cf[4] )
+ {
+ $res['valid'] = false;
+ $res['failure'] .= 'Value not in range';
+ $mf_results['problem'] .= '<li>"'.$mf['title'].'" requires a value less than or equal to '.$mf_cf[4].'.</li>'."\n";
+ }
+
+ if( $mf_formats[$mf_cf[0]]['regex'] != '' && preg_match( '/^'.$mf_formats[$mf_cf[0]]['regex'].'$/', $inp ) == 0 )
+ {
+ $res['valid'] = false;
+ $res['failure'] .= 'Input format not valid';
+ $mf_results['problem'] .= '<li>"Value supplied to '.$mf['title'].'" was not valid. Must be '.$mf_cf['0'].' (i.e. '.$mf_formats[$mf_cf[0]]['sample'].').</li>'."\n";
+ }
+ }
+
+ $res['value'] = ( $mf_cf_out != '' ? sprintf( $mf_cf_out, $inp ) : $inp );
+
+ break;
+
+ case 5: // Picklist
+
+ $res['opt_num'] = $inp;
+ $opts = explode( "|", $mf['data1'] ); // Separate Options
+ if( $inp != '' ) // If an options is selected
+ {
+ $x = explode( "~", $opts[$inp-1] ); // Separate data for selected option
+ $res['value'] = $x[0]; // Use option name
+ if( $x[2] != '' )
+ $res['numb_val'] = $x[2];
+ }
+ else
+ $res['value'] = '';
+
+ // Check selected option for Sub-Form
+
+ $n = 1;
+ foreach( $opts as $opt )
+ {
+ $an = explode( "~", $opt );
+ if( $inp == $n && !empty($an[1]) )
+ {
+ $sub = magic_form_submit( $an[1], $mf_fiid, $mf_def_data, $mf_level );
+
+ if( !$sub['success'] )
+ $mf_results['problem'] .= $sub['problem'];
+ else
+ $mf_total_value += $sub['total_value'];
+ }
+ $n++;
+ }
+
+ break;
+
+ case 6: // Radio Buttons
+
+ $res['opt_num'] = $inp;
+ $opts = explode( "|", $mf['data1'] ); // Separate Options
+ if( $inp != '' ) // If an options is selected
+ {
+ $x = explode( "~", $opts[$inp-1] ); // Separate data for selected option
+ $res['value'] = $x[0]; // Use option name
+ if( $x[2] != '' )
+ $res['numb_val'] = $x[2];
+
+ }
+ else
+ $res['value'] = '';
+
+ $opts = explode( "|", $mf['data1'] );
+
+ // Check selected button for Sub-Form
+
+ $n = 1;
+ foreach( $opts as $opt )
+ {
+ $an = explode( "~", $opt );
+ if( $inp == $n && !empty($an[1]) )
+ {
+ $sub = magic_form_submit( $an[1], $mf_fiid, $mf_def_data, $mf_level );
+
+ if( !$sub['success'] )
+ $mf_results['problem'] .= $sub['problem'];
+ else
+ $mf_total_value += $sub['total_value'];
+ }
+ $n++;
+ }
+
+ break;
+
+ case 7: // File Upload
+
+ // Note that $inp is the /temp file name for the uploaded file
+
+ $existing_filename = $GLOBALS['exist_mf_'.$mf['id']];
+ $new_filename = trim($GLOBALS['mf_'.$mf['id'].'_name']);
+
+ // If delete is requested or there's a new file upload AND there's an existing file, then delete the old one
+
+ if( $mf_def_data != null )
+ {
+ // Note that $inp is the /temp file name for the uploaded file
+
+ $existing_filename = stripslashes($GLOBALS['exist_mf_'.$mf['id']]);
+ $new_filename = trim(stripslashes($GLOBALS['mf_'.$mf['id'].'_name']));
+
+ // If delete is requested or there's a new file upload AND there's an existing file, then delete the old one
+
+ if( ( $GLOBALS['delete_mf_'.$mf['id']] == 'on' || $new_filename != '' ) && $existing_filename != '' )
+ {
+ file_delete( $existing_filename );
+ $existing_filename ='';
+ }
+
+ if( trim($inp) != '' && $inp != 'none' )
+ {
+ if( !($new_filename = file_upload( $inp, $new_filename )) )
+ {
+ $mf_results['problem'] .= '<li>Unable to upload file for "'.$mf['title'].'".</li>'."\n";
+ $new_filename = '';
+ }
+ }
+ else
+ $new_filename = $existing_filename;
+ }
+ else
+ $new_filename = $mf_def_data[$mf_field_id]; // Previous data was supplied, so just use that
+
+ $res['value'] = $new_filename;
+ $res['txt_val'] = '<a href="'.SI_BASE_FILE_URL.'/'.$new_filename.'" target="file_page">'.$new_filename.'</a>';
+
+
+ break;
+
+ default:
+ break;
+
+ } // Type
+
+ // Push the current result and any sub-form results onto the end of the result array.
+
+ $mf_results['data'][$mf['id']] = $res;
+ $mf_results['csv'] .= '"'.$res['id'].'","'.$res['level'].'","'.$res['title'].'","'.$res['txt_typ'].'","'.$res['value'].'","'.$res['numb_val'].'","'.($res['valid']?'t':'f').'","'.($res['required']?'t':'f').'","'.$res['failure'].'"'."\n";
+ $x = ''; for( $i=0 ; $i<$mf_level ; $i++ ) $x .= ' ';
+ $mf_results['html'] .= '<tr><td align="left">'.$res['id'].'</td><td align="left">'.$x.$res['title'].' </td><td align="left">'.$res['txt_typ'].' </td><td align="left">'.( $res['txt_val'] != '' ? $res['txt_val'] : $res['value'] ).' </td><td align="left">'.$res['numb_val'].' </td><td align="left">'.($res['valid']?'Yes':'No').'</td><td align="left">'.($res['required']?'Yes':'No').'</td><td align="left">'.$res['failure'].' </td></tr>'."\n";
+
+ // If there's a sub-form
+
+ if( is_array($sub) )
+ {
+
+ // Add data from sub-form
+
+ $mf_results['html'] .= $sub['html'];
+ $mf_results['csv'] .= $sub['csv'];
+ while( list($key, $val) = each($sub['data']) )
+ $mf_results['data'][$key] = $val;
+ }
+
+ } // Active
+
+ } // Each field
+
+ }
+
+ if( $mf_level == 1 )
+ $mf_results['html'] = '<table border="1" cellpadding="2" cellspacing="0"><tr><th align="left">Field ID</th><th align="left">Title</th><th align="left">Type</th><th align="left">Data</th><th align="left">Value</th><th align="left">Data Valid</th><th align="left">Required</th><th align="left">Failure</th></tr>'."\n".$mf_results['html']."</table>\n";
+
+ if( $mf_results['problem'] != '' )
+ $mf_results['success'] = false;
+
+ $mf_results['total_value'] = $mf_total_value;
+
+ return( $mf_results );
+
+ }
+
+ // MagicForm - Store Data
+
+function magic_form_store_data( $mf_id, $mf_fiid, $mf_def_data )
+ {
+
+ // Delete any files associated with this data
+
+ if( ($pd = db_auto_get_data( "SELECT * FROM ".MF_DATA_TABLE." WHERE fiid = $mf_fiid;")) )
+ foreach( $pd as $p )
+ {
+ // For each field of data stored, check if there's a file associated with it
+
+ switch( $p['type'] )
+ {
+ case 7: // File Upload
+ file_delete( $p['value'] );
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ // Delete previous entries using the supplied form instance id ($mf_fiid)
+
+ $qs = "BEGIN;\nDELETE FROM ".MF_DATA_TABLE." WHERE fiid = $mf_fiid;\n";
+
+ // Store new data
+
+ foreach( $mf_def_data as $mf )
+ {
+ $qs .= "INSERT INTO ".MF_DATA_TABLE." ( fiid, form_id, field_id, level, title, type, txt_type, value, numb_val, txt_value, opt_num, valid, required, failure )
+ VALUES ( $mf_fiid, $mf_id, '".addslashes($mf['id'])."', ".$mf['level'].", '".addslashes($mf['title'])."', ".$mf['type'].", '".addslashes($mf['txt_type'])."', '".addslashes($mf['value'])."',
+ ".($mf['numb_val']!=''?$mf['numb_val']:0).", '".addslashes($mf['txt_value'])."', ".($mf['opt_num']>0?$mf['opt_num']:0).", '".($mf['valid']?'t':'f')."', '".($mf['required']?'t':'f')."', '".addslashes($mf['failure'])."' );\n";
+ }
+ $qs .= "COMMIT;\n";
+
+ if( !db_auto_exec($qs) )
+ return( false );
+ else
+ return( true );
+
+ }
+
+
+/***********************************************************************
+* *
+* Support funtions for High Level Admin Functions *
+* *
+***********************************************************************/
+
+
+ // Explode a string into pieces and trims whitespace from ends of each piece.
+
+function explode_trim( $separator, $string )
+{
+
+ $a = explode( $separator, $string );
+
+ foreach( $a as $key => $data )
+ $a[$key] = trim($data);
+
+ return( $a );
+
+}
+
+
+/***********************************************************************
+* *
+* High Level Admin Functions *
+* *
+***********************************************************************/
+
+ // The "JFDI" function - Fully process a data table
+
+function admin_process_records_r( $table, $where, $order, $conn_str, $id, $fields,
+ $options, $rows, $url, $action, $params, $a_title, $view, $Option, $start, $other_options = '', $a_title_view = '', $quick_tip = '', $id_field = '' )
+{
+
+ $a_title_view = ereg_replace( "\\{action\\}", $Option, $a_title_view );
+
+ switch( $Option )
+ {
+
+ case "Add":
+
+ return( admin_new_record_r
+ (
+ $table,
+ $conn_str,
+ admin_field_select( $fields, 'n' ),
+ $url,
+ $action,
+ $params,
+ (empty($a_title_view)?"<P><SPAN CLASS=\"title1\">New $a_title</SPAN><P>":$a_title_view),
+ $view['Add'],
+ $other_options,
+ $quick_tip
+ )
+ );
+
+ break;
+
+ case "Add New":
+
+ $r = admin_add_new_record_r
+ (
+ $table,
+ $conn_str,
+ admin_field_select( $fields, 'a' ),
+ $url,
+ $action,
+ $params,
+ (empty($a_title_view)?"<P><SPAN CLASS=\"title1\">Add New $a_title</SPAN><P>":$a_title_view),
+ $view['Add New'],
+ $quick_tip
+ );
+
+ // If successfull see if we can get the new record ID and view it
+/* Don't do this right now...
+ *
+ if( $r['status'] )
+ {
+ // On success Add New returns the OID of the new record - get ID for next call
+
+ if( ($d = db_auto_get_row( "SELECT id FROM $table WHERE oid = ".$r['status'].";" )) )
+ $id = $d['id'];
+ else
+ return( $r ); // If we can't get ID then just give up and return
+
+ // If all is OK, then call again to do a View
+
+ $r = admin_process_records_r( $table, $where, $order, $conn_str, $id, $fields, $options, $rows, $url, $action, $params, $a_title, $view, 'View', $start, $other_options, $a_title_view, $quick_tip );
+ }
+*/
+
+ return( $r );
+
+ break;
+
+ case "Edit":
+
+ return( admin_edit_record_r
+ (
+ $table,
+ $conn_str,
+ $id,
+ admin_field_select( $fields, 'e' ),
+ $url,
+ $action,
+ $params,
+ (empty($a_title_view)?"<P><SPAN CLASS=\"title1\">Edit $a_title</SPAN><P>":$a_title_view),
+ $view['Edit'],
+ $other_options,
+ $quick_tip
+ )
+ );
+
+ break;
+
+ case "Update":
+
+ $r = admin_update_record_r
+ (
+ $table,
+ $conn_str,
+ $id,
+ admin_field_select( $fields, 'u' ),
+ $url,
+ $action,
+ $params,
+ (empty($a_title_view)?"<P><SPAN CLASS=\"title1\">Update $a_title</SPAN><P>":$a_title_view),
+ $view['Update'],
+ $quick_tip
+ );
+
+ // If successful update then call again to do a View of the updated record
+
+ if( $r['status'] )
+ return( admin_process_records_r( $table, $where, $order, $conn_str, $id, $fields, $options, $rows, $url, $action, $params, $a_title, $view, 'View', $start, $other_options, $a_title_view, $quick_tip ) );
+
+ return( $r );
+
+ break;
+
+ case "Delete":
+
+ return( admin_delete_record_r
+ (
+ $table,
+ $conn_str,
+ $id,
+ admin_field_select( $fields, 'd' ),
+ $options,
+ $url,
+ $action,
+ $params,
+ (empty($a_title_view)?"<P><SPAN CLASS=\"title1\">Delete $a_title</SPAN><P>":$a_title_view),
+ $view['Delete'],
+ $quick_tip
+ )
+ );
+
+ break;
+
+ case "Confirm Delete":
+
+ $r = admin_confirm_delete_record_r
+ (
+ $table,
+ $conn_str,
+ $id,
+ admin_field_select( $fields, 'c' ),
+ $url,
+ $action,
+ $params,
+ (empty($a_title_view)?"<P><SPAN CLASS=\"title1\">Confirm Delete $a_title</SPAN><P>":$a_title_view),
+ $view['Confirm Delete'],
+ $quick_tip
+ );
+
+ // If successful delete then call again to do a List
+
+ if( $r['status'] )
+ return( admin_process_records_r( $table, $where, $order, $conn_str, $id, $fields, $options, $rows, $url, $action, $params, $a_title, $view, 'List', $start, $other_options, $a_title_view, $quick_tip ) );
+
+ return( $r );
+
+ break;
+
+ case "View":
+
+ return( admin_view_record_r
+ (
+ $table,
+ $conn_str,
+ $id,
+ admin_field_select( $fields, 'v' ),
+ $url,
+ $action,
+ $params,
+ (empty($a_title_view)?"<P><SPAN CLASS=\"title1\">View $a_title</SPAN><P>":$a_title_view),
+ $view['View'],
+ $other_options,
+ $quick_tip,
+ $id_field
+ )
+ );
+
+ break;
+
+ default:
+
+ return( admin_list_records_r
+ (
+ $table,
+ $where,
+ $order,
+ $conn_str,
+ admin_field_select( $fields, 'l' ),
+ $options,
+ FALSE,
+ $rows,
+ $start,
+ $url,
+ $action,
+ $params,
+ admin_field_select( $fields, 'f' ),
+ (empty($a_title_view)?"<P><SPAN CLASS=\"title1\">List $a_title</SPAN><P>":$a_title_view),
+ $view['List'],
+ $id_field,
+ $quick_tip
+ )
+ );
+
+ break;
+
+ } // switch( $Option )
+
+}
+
+function admin_process_records( $table, $where, $order, $conn_str, $id, $fields,
+ $options, $rows, $url, $action, $params, $a_title, $view, $Option, $start, $other_options = '', $a_title_view = '', $quick_tip = '' )
+{
+ $r = admin_process_records_r( $table, $where, $order, $conn_str, $id, $fields,
+ $options, $rows, $url, $action, $params, $a_title, $view, $Option, $start, $other_options, $a_title_view, $quick_tip );
+ echo $r['text'];
+ return( $r['status'] );
+}
+
+
+ // List records from a table
+
+function admin_list_records_r( $table, $where, $order, $conn_str, $fields,
+ $options, $fail_mode, $rows = 20, $start = 0,
+ $url, $action, $params, $filters, $a_title, $view = "", $id_field = "", $quick_tip = '' )
+{
+
+ $ret = '';
+
+ // Make all submitted parameters available
+
+// extract($GLOBALS[HTTP_GET_VARS]);
+// extract($GLOBALS[HTTP_POST_VARS]);
+
+ // Make sure we have something rational for rows and start
+
+ if( $rows == '' ) $rows = 20;
+ if( $start == '' ) $start = 0;
+
+ // Break out configuration data
+
+ $field_table = explode_trim( "|", $fields );
+
+ // Don't be surprised if last field is blank
+
+ if( trim($field_table[count($field_table)-1]) == "" )
+ array_pop( $field_table );
+
+ foreach( $field_table as $key => $r )
+ {
+ $field_table[$key] = explode_trim( ",", $r );
+ $hidden[$key] = ereg( "HIDDEN", $field_table[$key][3] );
+ }
+
+ $operation_column = $option_new = $option_view = $option_edit = $option_delete = $option_duplicate = $option_filter = $option_nopaging = $option_noborder = $option_opview = FALSE;
+
+ if( ! empty($options) )
+ {
+ $option_table = explode_trim( ",", $options );
+ foreach( $option_table as $option )
+ {
+
+ $op = explode_trim( ".", $option ); // Separate option name from option parameters
+
+ switch( $op[0] )
+ {
+ case "new":
+ $option_new = TRUE;
+ break;
+
+ case "view":
+ $option_view = TRUE;
+ $operation_column = TRUE;
+ break;
+
+ case "edit":
+ $option_edit = TRUE;
+ $operation_column = TRUE;
+ break;
+
+ case "delete":
+ $option_delete = TRUE;
+ $operation_column = TRUE;
+ break;
+
+ case "duplicate":
+ $option_duplicate = TRUE;
+ $operation_column = TRUE;
+ break;
+
+ case "filter":
+ $option_filter = TRUE;
+ break;
+
+ case "sortlinks":
+ $option_sortlinks = TRUE;
+ break;
+
+ case "nopaging":
+ $option_nopaging = TRUE;
+ break;
+
+ case "noborder":
+ $option_noborder = TRUE;
+ break;
+
+ case "opview":
+ $option_opview = TRUE;
+ $opview = $op[1]; // Get view for operation column
+ $operation_column = TRUE;
+ break;
+
+ default:
+// $ret .= '<H2><FONT COLOR="red">ERROR: Illegal Option Specified: -'.$option.'-</FONT></H2>';
+ break;
+ }
+ }
+ }
+
+ // Check for additional parameters that are passed
+
+ $link_params = $form_params = "";
+ if( !empty($params) )
+ {
+ $param = explode_trim( "|", $params ); // Separate parameters
+ foreach( $param as $p )
+ {
+ $x = explode_trim( ".", $p ); // Separate Names from Values
+ $link_params .= "&".$x[0]."=".urlencode($x[1]);
+ $form_params .= '<INPUT TYPE="hidden" NAME="'.$x[0].'" VALUE="'.$x[1].'">';
+ }
+ }
+
+ // Check if a column lable has been clicked to cause a sort of that column
+
+ if( !empty($GLOBALS['sortclicked_new']) )
+ {
+
+ // Clicking the same column title toggles between ascending and descending sort
+
+ if( $GLOBALS['list_sort_direction'] == 'Forward' )
+ $list_sort_direction = "Backward";
+ else
+ $list_sort_direction = 'Forward';
+
+ $sortclicked = $GLOBALS['sortclicked_new'];
+ $link_params .= '&sortclicked='.$sortclicked."&list_sort_direction=$list_sort_direction";
+ $form_params .= '<INPUT TYPE="hidden" NAME="sortclicked" VALUE="'.$sortclicked.'">';
+ $form_params .= '<INPUT TYPE="hidden" NAME="list_sort_direction" VALUE="'.$list_sort_direction.'">';
+ }
+ elseif( !empty($GLOBALS['sortclicked']) )
+ {
+ $sortclicked = $GLOBALS['sortclicked'];
+ $list_sort_direction = $GLOBALS['list_sort_direction'];
+ $link_params .= '&sortclicked='.$sortclicked."&list_sort_direction=$list_sort_direction";
+ $form_params .= '<INPUT TYPE="hidden" NAME="sortclicked" VALUE="'.$sortclicked.'">';
+ $form_params .= '<INPUT TYPE="hidden" NAME="list_sort_direction" VALUE="'.$list_sort_direction.'">';
+ }
+
+ // Display optional filter search fields and build query string
+
+ $qs = empty($where) ? "WHERE TRUE " : "WHERE ".$where ;
+
+ if( $option_filter )
+ {
+ $filter_out = '
+ <FORM ACTION="'.$url.'">
+ <INPUT TYPE="hidden" NAME="Option" VALUE="List">
+ <B>Select items to list</B><BR>
+ <TABLE BORDER="0">
+ ';
+
+ $filter_link = ""; // Added to link to pass on filter data
+ $filter = explode_trim( "|", $filters );
+ foreach( $filter as $filter_field )
+ {
+ $f = explode_trim( ",", $filter_field ); // Split field specs
+ $ft = explode_trim( "~", $f[2] ); // Separate QuickTips from titles
+ $w = explode_trim( "`", $f[1] ); // Separate out any format spec
+ $x = explode_trim( ".", $w[0] ); // Split type specs
+ $option = $x[1]!="" ? $x[1] : "none" ;
+ $filter_value = isset($f[3]) ? $GLOBALS[$f[3]] : $GLOBALS[$f[0]]; // if no value field specified, use field name
+
+ // Display Filter Title - With QuickTip if specified
+
+ if( count($ft) > 1 )
+ $filter_out .= '<TR><TH ALIGN="right" VALIGN="top">'.quick_tip( $ft[0], $ft[1] ).'</TH><TD ALIGN="left">';
+ else
+ $filter_out .= '<TR><TH ALIGN="right" VALIGN="top">'.$ft[0].'</TH><TD ALIGN="left">';
+
+ // Add any filter value to $filter_link
+
+ if( !empty($filter_value) )
+ {
+ if( is_array($filter_value) )
+ {
+ $fvc = 0;
+ foreach( $filter_value as $fv )
+ if( trim($fv) != '' )
+ {
+ $filter_link .= "&".$f[0]."[$fvc]=".$fv;
+ $fvc++;
+ }
+ }
+ else
+ $filter_link .= "&".$f[0]."=".$filter_value;
+ }
+
+ // Display filter field
+
+ switch( $x[0] ) // Handle different field types
+ {
+ case "password":
+ case "image":
+ $filter_out .= ' '; // No filters for these types
+ break;
+
+ case "url":
+ case "text":
+ case "textbox":
+ case "inet":
+ $filter_out .= '<INPUT TYPE="text" NAME="'.$f[0].'" VALUE="'.$filter_value.'">';
+ if( !empty($filter_value) ) // If a value is passed, add to query
+ switch( $option )
+ {
+ case "like":
+ $qs .= " AND ".$f[0]." LIKE '%".$filter_value."%'";
+ break;
+ case "begin":
+ $qs .= " AND ".$f[0]." ~* '^".$filter_value."'";
+ break;
+ case "any":
+ default:
+ $qs .= " AND ".$f[0]." ~* '".$filter_value."'";
+ break;
+ }
+ break;
+
+ case "state":
+ $filter_out .= build_picklist( $f[0], $GLOBALS['si_states_array'], $filter_value, 'standard', 'blank' );
+ if( $filter_value != '' )
+ $qs .= ' AND '.$f[0]." = '".$filter_value."'";
+ break;
+
+ case "country":
+ $filter_out .= build_picklist( $f[0], $GLOBALS['si_countries_array'], $filter_value, 'standard', 'blank' );
+ if( $filter_value != '' )
+ $qs .= ' AND '.$f[0]." = '".$filter_value."'";
+ break;
+
+ case "date":
+ $filter_out .= '<INPUT TYPE="text" NAME="'.$f[0].'" VALUE="'.$filter_value.'">';
+ if( !empty($filter_value) ) // If a value is passed, add to query
+ switch( $option )
+ {
+ default: // Options are not used for date at this time
+ $qs .= " AND ".$f[0]." = '".$filter_value."'";
+ break;
+ }
+ break;
+
+ case "daterange":
+ // Clean up dates
+ if( trim($GLOBALS[$f[3].'_FROM'] ) != '' ) $GLOBALS[$f[3].'_FROM'] = date( 'n/j/Y', strtotime($GLOBALS[$f[3].'_FROM']) );
+ if( trim($GLOBALS[$f[3].'_TO'] ) != '' ) $GLOBALS[$f[3].'_TO'] = date( 'n/j/Y', strtotime($GLOBALS[$f[3].'_TO']) );
+ $filter_out .= 'From <INPUT TYPE="text" NAME="'.$f[0].'_FROM" VALUE="'.$GLOBALS[$f[3].'_FROM'].'"> To <INPUT TYPE="text" NAME="'.$f[0].'_TO" VALUE="'.$GLOBALS[$f[3].'_TO'].'">';
+ // If Dates are not valid
+ if( ( trim($GLOBALS[$f[3].'_FROM']) != '' && strtotime($GLOBALS[$f[3].'_FROM']) === -1 ) ||
+ ( trim($GLOBALS[$f[3].'_TO']) != '' && strtotime($GLOBALS[$f[3].'_TO']) === -1 ) )
+ {
+ $filter_out .= '<BR>(<FONT COLOR="red">Note:</FONT> Invalid date specified)';
+ break;
+ }
+ else
+ {
+ // If we have both dates of a range
+ if( !empty($GLOBALS[$f[3].'_FROM']) && !empty($GLOBALS[$f[3].'_TO']) ) // If a value is passed, add to query
+ switch( $option )
+ {
+ default: // Options are not used for date at this time
+ $qs .= " AND ".$f[0]." BETWEEN '".$GLOBALS[$f[3].'_FROM']."' AND '".$GLOBALS[$f[3].'_TO']."'";
+ break;
+ }
+ else // Otherwise check if there's only one date submitted
+ if( !empty($GLOBALS[$f[3].'_FROM']) || !empty($GLOBALS[$f[3].'_TO']) )
+ $filter_out .= '<BR>(<FONT COLOR="red">Note:</FONT> both From and To required to specify date range)';
+ }
+ break;
+
+ case "order":
+ case "int":
+ case "float":
+ case "fixed":
+ $filter_out .= '<INPUT TYPE="text" NAME="'.$f[0].'" VALUE="'.$filter_value.'">
+ ';
+ if( !empty($filter_value) ) // Note: No filter options on type "int"
+ $qs .= " AND ".$f[0]." = ".$filter_value."";
+ break;
+
+ case "checkbox":
+ if( empty($filter_value) )
+ $x = 1;
+ else
+ $x = $filter_value;
+ $filter_out .= '
+ <SELECT NAME="'.$f[0].'">
+ <OPTION VALUE="1" '.($x==1?"SELECTED":"").'>Don\'t care
+ <OPTION VALUE="2" '.($x==2?"SELECTED":"").'>Yes
+ <OPTION VALUE="3" '.($x==3?"SELECTED":"").'>No
+ </SELECT>
+ ';
+ switch( $x )
+ {
+ case "2":
+ $qs .= " AND ".$f[0]." = 't'";
+ break;
+ case "3":
+ $qs .= " AND ".$f[0]." = 'f'";
+ break;
+ case "1":
+ default:
+ break;
+ }
+ break;
+
+ case "list" :
+ // If picklist options
+ $opts_table = array ();
+ $opts = explode_trim("~", $x[1]); // Separate list options
+ foreach ($opts as $opt)
+ {
+ $z = explode_trim("^", $opt); // Separate value from displayed text
+ $opts_table[$z[0]] = $z[1];
+ }
+ $opts_def = $GLOBALS[$f[3]] == '' ? '-1' : $GLOBALS[$f[3]];
+ $filter_out .= build_picklist($f[0], $opts_table, $opts_def, 'standard', $x[3].($x[3]!=''?'~':'')."blank");
+
+ // If there's any list options selected
+ if( is_array($GLOBALS[$f[3]]) )
+ {
+ $qss .= ' AND ( ';
+ $sep = '';
+ foreach( $GLOBALS[$f[3]] as $v ) // For each option specified
+ {
+ if( trim($v) != '' ) // If the option is something other than ''
+ {
+ $qss .= $sep.$f[0]." = ".$v."";
+ $sep = ' OR ';
+ }
+ }
+ if( $sep != '' ) // If there were options selected other than ''
+ $qs .= $qss.' )'; // add to the query
+ }
+ else
+ {
+ if( $GLOBALS[$f[3]] != '' )
+ $qs .= ' AND '.$f[3].' = '.$GLOBALS[$f[3]];
+ }
+
+ break;
+
+
+ case "category":
+
+ // If picklist is selected - use that for selection
+
+ if( strstr($x[3],'picklist') )
+ {
+ if( ($nodes = cat_get_nodes($x[1])) )
+ {
+ $filter_out .= '<SELECT NAME="'.$f[0].'"><OPTION VALUE="">';
+
+ reset($nodes);
+ while( list($key, $val) = each($nodes) )
+ {
+ $filter_out .= '<OPTION VALUE="'.$val['id'].'">';
+ if( strstr($x[3],'fullpath') )
+ $filter_out .= $val['cat_fullpath'];
+ else
+ {
+ for( $i=0 ; $i<$val['cat_level'] ; $i++ )
+ $filter_out .= " ";
+ $filter_out .= $val['name'];
+ }
+ }
+ $filter_out .= '</SELECT>';
+ }
+ else
+ $filter_out .= 'No categories listed.';
+ }
+ else // Otherwise use pop-up
+ {
+
+ // Check if a value for this field is supplied
+ if( !empty($filter_value) )
+ {
+ if( ($cval = cat_get_node( $x[1], "id = ".$filter_value ) ) )
+ {
+ $cat_id = $filter_value;
+ if( strstr($x[3],'fullpath') )
+ $cat_name = $cval['cat_fullpath'];
+ else
+ $cat_name = $cval['cat_name'];
+ }
+ }
+ else
+ {
+ $cat_id = 0;
+ $cat_name = " ";
+ }
+
+ $pop_width = !empty($x[4]) ? $x[4] : 200 ;
+ $pop_height = !empty($x[5]) ? $x[5] : 300 ;
+ $edit_width = !empty($x[6]) ? $x[6] : 400 ;
+ $edit_height = !empty($x[7]) ? $x[7] : 500 ;
+
+ $filter_out .= "
+ <script language=\"JavaScript1.2\">
+ <!--
+ function category_select_popup_".$f[0]."( target )
+ {
+ // Pass values to the calendar
+
+ tempX = 400;
+ tempY = 300;
+
+ node_id = this.document.getElementById( target ).value;
+ var theUrl='".SI_BASE_URL."/glm_apps/category_select_popup.phtml?id=' + node_id + '&field_name=".$f[0]."&table=".$x[1]."&options=".urlencode($x[3])."&edit_width=".$edit_width."&edit_height=".$edit_height."&pop_width=".$pop_width."&pop_height=".$pop_height."';
+
+ tempX = tempX - 90;
+ //tempY = tempY - 170;
+
+ if (navigator.appName == 'Netscape')
+ {
+ CategoryWind = window.open( theUrl, 'Calendar','scrollbars=yes,toolbar=no,resizable=yes,width=".$pop_width.",height=".$pop_height.",screenx=' + tempX + ',screeny=' + tempY,1 );
+ }
+ else
+ {
+ CategoryWind = window.open( theUrl, 'Calendar','scrollbars=no,toolbar=no,resizable=no,width=".$pop_width.",height=".$pop_height.", top=' + tempY + ', left=' + tempX,1 );
+ }
+
+ CategoryWind.focus();
+ }
+ -->
+ </script>
+ ";
+
+ $filter_out .= '<INPUT TYPE="text" NAME="'.$f[0].'_NAME" ID="'.$f[0].'_NAME" VALUE="'.$cat_name.'" SIZE="'.$x[2].'" READONLY="readonly" STYLE="background-color: #eeeeee;">
+ <INPUT TYPE="hidden" NAME="'.$f[0].'" ID="'.$f[0].'" VALUE="'.$cat_id.'">
+ <A HREF="javascript:category_select_popup_'.$f[0].'(\''.$f[0].'\')">[Change]</A>
+ ';
+ }
+
+ if( $filter_value != '' )
+ $qs .= ' AND '.$f[0]." = '".$filter_value."'";
+
+ break;
+
+ case "pointer":
+
+ // Get values from other table
+
+ $w = !empty($x[4]) ? " WHERE ".$x[4] : "" ;
+ $d = db_auto_get_data( "SELECT * FROM ".$x[1].$w." ORDER BY ".$x[2].";", $conn_str, FALSE, 500 );
+
+ $p_id_field = !empty($x[3]) ? $x[3] : 'id'; // If no id field supplied, assume "id"
+
+ // Build picklist data
+
+ unset( $da );
+ if( !empty($d) )
+ {
+ while( list($key, $val) = each($d) )
+ $da[$val[$p_id_field]] = $val[$x[2]];
+ $filter_out .= build_picklist( $f[0], $da, $filter_value, "standard", "blank" );
+ }
+ else
+ $filter_out .= '<FONT COLOR="red">No records from which to build picklist.</FONT>';
+
+ // If value supplied, add to query WHERE clause
+
+ if( !empty($filter_value) )
+ switch( $option )
+ {
+ case "like":
+ case "begin":
+ case "any":
+ $filter_out .= '<FONT COLOR="red">Filter option for type "pointer" not valid. Must use "exact" for type pointer.</FONT>';
+ break;
+ case "exact":
+ default:
+ $qs .= " AND ".$f[0]." = '".$filter_value."'";
+ break;
+ }
+ break;
+
+ default:
+ $filter_out .= '<FONT COLOR="red">UNKNOWN FILTER FIELD TYPE</FONT>';
+ break;
+
+ }
+ $filter_out .= '</TR>
+ ';
+ }
+ $filter_out .= '</TABLE>
+ <INPUT TYPE="hidden" NAME="Action" VALUE="'.$action.'">
+ <INPUT TYPE="submit" VALUE="Show Selected Results">
+ '.$form_params.'
+ </FORM>
+ ';
+ }
+
+ // If "new" option selected display link
+
+ if( $option_new )
+ $new_out = '<A HREF="'.$url.'?Action='.urlencode($action).$link_params.'&Option=Add">[Add New Entry]</A><BR>
+ ';
+ else
+ $new_out = "";
+
+
+ // Add in any ORDER BY clause (ignore anything after ".", which are nav options)
+
+ if( !empty($sortclicked) ) // Check if user clicked a column title
+ {
+ $qs .= ' ORDER BY '.$sortclicked;
+ if( $list_sort_direction == 'Backward' )
+ $qs .= " DESC";
+ }
+ else
+ if( !empty($order) )
+ {
+ $qs .= " ORDER BY ";
+ $ob_comma = "";
+ $order_array = explode_trim( ",", $order ); // Break out multiple order by field names
+ foreach( $order_array as $of )
+ {
+ $x = explode_trim( ".", $of ); // Break out field name from options
+ $qs .= $ob_comma.$x[0]; // Add field name to ORDER BY
+ if( ereg("order_descending", $of) ) // If order_descending use DESC order in ORDER BY for this field
+ $qs .= " DESC";
+ $ob_comma = ", "; // Next order by field will have a comma in front of it
+ }
+ }
+
+ // Get the data
+
+ $what_fields = "*";
+ if( $id_field != "" )
+ $what_fields = "*, ".$id_field." AS id";
+
+ $query_string = "SELECT ".$what_fields." FROM ".$table." ".$qs.";";
+
+ if( SI_DEBUG >= 1 ) $ret .= "<PRE>admin_list_records()[".__LINE__."]: Query String = $query_string</PRE><BR>";
+
+ $data = db_auto_get_data( $query_string, $conn_str, $fail_mode, $rows, $start );
+
+ if( $data )
+ {
+
+ // Determine how much data we got back
+
+ reset( $data );
+ $return_counts = explode( "|", key($data) );
+ $num = $return_counts[1];
+
+ // Calculate last entry on page
+
+ $end_list = $num>($start+$rows) ? $start+$rows : $num;
+
+
+ // Display page navigation
+
+ $nav_out = "";
+ if( $num > 0 && $option_nopaging == FALSE )
+ {
+ if( $start > 0 )
+ $nav_out .= '<A HREF="'.$url.'?Action='.urlencode($action).$link_params.$filter_link.'&start='.($start-$rows).'">previous</A>
+ ';
+ else
+ $nav_out .= "<I>previous</I> \n";
+
+ $nav_out .= ' <- <B>Results '.($start+1).' to '.($end_list).' of '.$num.'</B> ->
+ ';
+
+ if( $num > $end_list )
+ $nav_out .= '<A HREF="'.$url.'?Action='.urlencode($action).$link_params.$filter_link.'&start='.$end_list.'">next</A>
+ ';
+ else
+ $nav_out .= " <I>next</I>\n";
+ }
+
+
+ // Build field titles
+
+ $fieldcount = 0;
+ foreach( $field_table as $field )
+ {
+ $f2 = explode_trim( "~", $field[2] ); // Only use name, don't include QuickTip text.
+ $f2_name = $f2[0];
+ switch( $field[1] )
+ {
+ default:
+ if( $option_sortlinks )
+ {
+ $scd = '';
+
+ // Check if a column title has been clicked to cause a sort
+ if( $sortclicked == $field[0] )
+ {
+ // Indicate sort direction
+
+ if( $list_sort_direction == 'Forward' )
+ $scd = "v";
+ else
+ $scd = "^";
+ }
+ $outnames[$fieldcount++] = $scd.' <A HREF="'.$url.'?Action='.urlencode($action).'&Option=List'.$link_params.$filter_link.'&sortclicked_new='.$field[0].'">'
+ .$f2_name.'</A> '.$scd;
+ }
+ else
+ $outnames[$fieldcount++] = $f2_name;
+ break;
+ }
+ }
+
+ if( $operation_column )
+ $outnames[$fieldcount++] = 'Operation';
+
+
+ // For each result we're going to display
+
+ $reccount = 0;
+ foreach( $data as $key => $r )
+ {
+
+ // For each field in the result
+
+ $fieldcount = 0;
+ foreach( $field_table as $field )
+ {
+ $w = explode_trim( "`", $field[1] ); // Separate out any format spec
+ $f = explode_trim( ".", $w[0] ); // break out the field type specs
+
+ // If there's any field format spec, save that in our $outvals array
+
+ if( isset($w[1]) && trim($w[1]) != '' )
+ {
+ // Replace each {field_name} tag with {#} as needed to reference the correct $outvals[$reccount][#] entry
+
+ for( $i=0 ; $i<count($field_table) ; $i++ )
+ $w[1] = str_replace( '{'.$field_table[$i][0].'}', '{'.$i.'}', $w[1] );
+
+ // Save the new format spec
+ $outvals[$reccount][$fieldcount]['format'] = $w[1];
+ }
+
+ switch( $f[0] )
+ {
+
+ case "password":
+ $outvals[$reccount][$fieldcount]['data'] = '(hidden)';
+ break;
+
+ case "lat":
+ $fw = 2;
+ if( $f[1] > 0 )
+ $fw = $f[1];
+ $ns = 'N';
+ if( $r[$field[0]] < 0 )
+ {
+ $ns = 'S';
+ $r[$field[0]] = -1 * $r[$field[0]];
+ }
+ $dv = (int) $r[$field[0]];
+ $mv = ( $r[$field[0]] - $dv ) * 60;
+ $outvals[$reccount][$fieldcount]['data'] = sprintf( "<NOBR>%s %d° %01.".$fw."f'</NOBR>", $ns, $dv, $mv );
+ break;
+
+ case "lon":
+ $fw = 2;
+ if( $f[1] > 0 )
+ $fw = $f[1];
+ $ns = 'E';
+ if( $r[$field[0]] < 0 )
+ {
+ $ns = 'W';
+ $r[$field[0]] = -1 * $r[$field[0]];
+ }
+ $dv = (int) $r[$field[0]];
+ $mv = ( $r[$field[0]] - $dv ) * 60;
+ $outvals[$reccount][$fieldcount]['data'] = sprintf( "<NOBR>%s %d° %01.".$fw."f'</NOBR>", $ns, $dv, $mv );
+ break;
+
+ case "order":
+ case "int":
+ case "float":
+ $outvals[$reccount][$fieldcount]['data'] = $r[$field[0]];
+ break;
+
+ case "money":
+ $outvals[$reccount][$fieldcount]['data'] = "$".sprintf( "%01.2f", $r[$field[0]] );
+ break;
+
+ case "fixed":
+ $outvals[$reccount][$fieldcount]['data'] = sprintf( "%01.".$f[1]."f", $r[$field[0]] );
+ break;
+
+ case "date":
+ case "text":
+ case "textbox":
+ case "richtext":
+ case "inet":
+ $outvals[$reccount][$fieldcount]['data'] = $r[$field[0]];
+ break;
+
+ case "state":
+ $outvals[$reccount][$fieldcount]['data'] = $GLOBALS['si_states_array'][$r[$field[0]]];
+ break;
+
+ case "country":
+ $outvals[$reccount][$fieldcount]['data'] = $GLOBALS['si_countries_array'][$r[$field[0]]];
+ break;
+
+ case "url":
+ $outvals[$reccount][$fieldcount]['data'] = '<A HREF="'.$r[$field[0]].'">'.$r[$field[0]].'</A>';
+ break;
+
+ case "category":
+ // Get the category name for this field is supplied
+ if( !empty($r[$field[0]]) )
+ {
+ if( $cval = db_auto_get_row( "SELECT * FROM ".$f[1]." WHERE id = ".$r[$field[0]].";", 0, $conn_str, FALSE ) )
+ $outvals[$reccount][$fieldcount]['data'] = $cval['name'];
+ else
+ $outvals[$reccount][$fieldcount]['data'] = '<FONT COLOR="red">Unknown Category</FONT>';
+ }
+ else
+ {
+ $outvals[$reccount][$fieldcount]['data'] = " ";
+ }
+ break;
+
+ case "pointer":
+ // If {value_field} supplied use that, otherwise use id of record as value to match
+ $value_field = !empty($f[3]) ? $f[3] : "id" ;
+
+ // If {where} supplied use that, otherwise match {value_field} or "id" field
+ $w = '';
+ if( !empty($f[4]) )
+ $w = " WHERE ".$f[4];
+ elseif( trim($r[$field[0]]) != '' )
+ $w = " WHERE ".$value_field." = ".$r[$field[0]];
+
+ if( $w != '' )
+ {
+ $ref_fields = explode_trim( "~", $f[2] ); // Separate all fields to display
+ $ref_select = $sep = '';
+ foreach( $ref_fields as $ref_field ) // Build fields spec for SELECT
+ {
+ $ref_select .= $sep.$ref_field;
+ $sep = ',';
+ }
+ $pval = db_auto_get_row( "SELECT $ref_select FROM ".$f[1].$w.";", 0, $conn_str, $fail_mode );
+ $outvals[$reccount][$fieldcount]['data'] = '';
+ $ref_space = '';
+ foreach( $ref_fields as $ref_field ) // Put together all fields referenced as output
+ {
+ $outvals[$reccount][$fieldcount]['data'] .= $ref_space.$pval[$ref_field];
+ $ref_space = ' ';
+ }
+ }
+ else
+ $outvals[$reccount][$fieldcount]['data'] = '';
+ break;
+
+ case "checkbox":
+ $outvals[$reccount][$fieldcount]['data'] = $r[$field[0]] == "t" ? "Yes" : "No" ;
+ break;
+
+ case "image":
+ if( !empty($r[$field[0]]) )
+ {
+ switch( $f[1] )
+ {
+ case "o": $img_url = SI_IMG_ORIGINAL_URL; break;
+ case "r": $img_url = SI_IMG_RESIZED_URL; break;
+ case "m": $img_url = SI_IMG_MIDSIZED_URL; break;
+ case "t": $img_url = SI_IMG_THUMB_URL; break;
+ default: $img_url = "none"; break;
+ }
+ if( $img_url != "none" )
+ $outvals[$reccount][$fieldcount]['data'] = '<IMG SRC="'.$img_url."/".$r[$field[0]].'">';
+ else
+ $outvals[$reccount][$fieldcount]['data'] = '<FONT COLOR="RED">Invalid Image Size</FONT>';
+ }
+ else
+ $outvals[$reccount][$fieldcount]['data'] = '(no image)';
+ break;
+
+ case "file":
+ if( !empty($r[$field[0]]) )
+ {
+ if( ereg( 'secure', $f[2] ) )
+ {
+ if( !defined('SI_FILE_SECRET') || SI_FILE_SECRET == '' )
+ {
+ echo '<p><font color="red">ERROR: </font> SI_FILE_SECRET parameter required for <b>file_output_secure()</b><br>
+ SI_FILE_SECRET defined parameter not found or no contents! Please check siteinfo.inc file.<p>';
+ exit;
+ }
+ $file_md5 = md5( $r[$field[0]].SI_FILE_SECRET );
+ $outvals[$reccount][$fieldcount]['data'] = '<A HREF="'.SI_BASE_URL.'/glm_apps/file_output_secure.phtml?filename='.urlencode($r[$field[0]])
+ .'&md5='.$file_md5.'&path='.urlencode($f[1]).'">'.$r[$field[0]].'</A>';
+ }
+ else
+ $outvals[$reccount][$fieldcount]['data'] = '<A HREF="'.SI_BASE_FILE_URL.'/'.$r[$field[0]].'">'.$r[$field[0]].'</A>';
+ }
+ else
+ $outvals[$reccount][$fieldcount]['data'] = '(no file)';
+ break;
+
+ case "list":
+ $opts_table = array ();
+ $opts = explode_trim( "~", $f[1] ); // Separate list options
+ foreach( $opts as $opt )
+ {
+ $z = explode_trim("^", $opt); // Separate value from displayed text
+ $opts_table[$z[0]] = $z[1];
+ }
+
+ // In case there's multiple selected options, display results of all selected options with comma separators
+
+ $x = explode( '~', $r[$field[0]] );
+ $outvals[$reccount][$fieldcount]['data'] = $sep = '';
+ if( is_array($x) )
+ foreach( $x as $y )
+ {
+ $outvals[$reccount][$fieldcount]['data'] .= $sep.$opts_table[$y];
+ $sep = ', ';
+ }
+
+ break;
+
+ default:
+ $outvals[$reccount][$fieldcount]['data'] = '<FONT COLOR="red">UNKNOWN FIELD TYPE: '.$f[0].' for '.$field[0].'</FONT>';
+ break;
+
+ } // switch( field )
+ $fieldcount++;
+ } // foreach( field )
+
+ if( $operation_column )
+ {
+ $op_view = '<A HREF="'.$url.'?Action='.urlencode($action).'&Option=View'.$link_params.'&id='.$r["id"].'">[view] </A>';
+ $op_edit = '<A HREF="'.$url.'?Action='.urlencode($action).'&Option=Edit'.$link_params.'&id='.$r["id"].'">[edit] </A>';
+ $op_delete = '<A HREF="'.$url.'?Action='.urlencode($action).'&Option=Delete'.$link_params.'&id='.$r["id"].'">[delete] </A>';
+ $op_dupe = '<A HREF="'.$url.'?Action='.urlencode($action).'&Option=Duplicate'.$link_params.'&id='.$r["id"].'">[duplicate] </A>';
+
+ // If operation column view is specified, use that
+
+ if( $option_opview )
+ {
+
+ // Replace all parameters in Operation View
+
+ for( $i=0 ; $i<$fieldcount ; $i++ )
+ {
+ $opview = ereg_replace( "\\{".$i."\\}", $outnames[$i], $opview );
+ $opview = ereg_replace( "\\{encode:".$i."\\}", urlencode($outnames[$i]), $opview );
+ }
+ $opview = ereg_replace( "\\{link_params\}", $link_params, $opview );
+ $opview = ereg_replace( "\\{form_params\}", $form_params, $opview );
+ $opview = ereg_replace( "\\{op_view\}", $op_view, $opview );
+ $opview = ereg_replace( "\\{op_edit\}", $op_edit, $opview );
+ $opview = ereg_replace( "\\{op_delete\}", $op_delete, $opview );
+ $opview = ereg_replace( "\\{op_dupe\}", $op_dupe, $opview );
+ $opview = ereg_replace( "\\{op_url\}", $url, $opview );
+ $opview = ereg_replace( "\\{op_id\}", $r["id"], $opview );
+
+ $outvals[$reccount][$fieldcount]['data'] = $opview;
+ $fieldcount++;
+
+ }
+ else // Otherwise, include specified operations
+ {
+ $outvals[$reccount][$fieldcount]['data'] = "";
+ if( $option_view )
+ $outvals[$reccount][$fieldcount]['data'] .= $op_view;
+ if( $option_edit )
+ $outvals[$reccount][$fieldcount]['data'] .= $op_edit;
+ if( $option_delete )
+ $outvals[$reccount][$fieldcount]['data'] .= $op_delete;
+ if( $option_duplicate )
+ $outvals[$reccount][$fieldcount]['data'] .= $op_dupe;
+ $fieldcount++;
+ }
+ }
+
+ $reccount++;
+ } // foreach( record )
+
+ // Replace parameters in Title - {n} represents the field names in the page title
+
+ } // if( $data )
+
+ for( $i=0 ; $i<$fieldcount ; $i++ )
+ {
+ $a_title = ereg_replace( "\\{".$i."\\}", $outnames[$i], $a_title );
+ $a_title = ereg_replace( "\\{encode:".$i."\\}", urlencode($outnames[$i]), $a_title );
+ }
+ $a_title = ereg_replace( "\\{filter\}", $filter_out, $a_title );
+ $a_title = ereg_replace( "\\{link_params\}", $link_params, $a_title );
+ $a_title = ereg_replace( "\\{form_params\}", $form_params, $a_title );
+ $a_title = ereg_replace( "\\{new\}", $new_out, $a_title );
+ $a_title = ereg_replace( "\\{nav\}", $nav_out, $a_title );
+
+ $ret .= "<CENTER>\n";
+
+ if( empty($view) ) // If $view is not supplied
+ {
+
+ if( trim($quick_tip) != '' )
+ $a_title = quick_tip( $a_title, $quick_tip );
+
+ // Display title, filter, and optional "new" link
+
+ $ret .= $a_title.'
+ '.$filter_out.'
+ '.$new_out;
+
+ // If there were results listed, display the results
+
+ if( $data && ($fields != "") )
+ {
+ $ret .= $nav_out.'<BR>'.$nav_initials.'
+ <TABLE BORDER="'.($option_noborder==FALSE?'1':'0').'">
+ <TR>
+ ';
+
+ // Display the titles for all columns
+
+ for( $i=0 ; $i<$fieldcount ; $i++ )
+ {
+ if( !$hidden[$i] )
+ $ret .= "<TH>".$outnames[$i]." </TH>";
+ }
+
+ // Display the data for each result
+
+ for( $i=0 ; $i<$reccount ; $i++ )
+ {
+ $ret .= "<TR>";
+
+ for( $j=0 ; $j<$fieldcount ; $j++ )
+ {
+ // If the field is supposed to be seen
+
+ if( !$hidden[$j] )
+ {
+ // If there's a format spec, use that
+ if( $outvals[$i][$j]['format'] != '' )
+ {
+ $out = $outvals[$i][$j]['format'];
+ for( $k=0 ; $k<$fieldcount ; $k++ )
+ $out = str_replace( '{'.$k.'}', $outvals[$i][$k]['data'] , $out );
+ $ret .= "<td>$out</td>";
+ }
+ else // Otherwise just output the value
+ $ret .= "<TD>".$outvals[$i][$j]['data']." </TD>";
+ }
+ }
+ $ret .= "</TR>\n";
+
+ }
+ $ret .= ' </TABLE>
+ '.$nav_out;
+ }
+ else
+ $ret .= ' <CENTER>(No results found)</CENTER>
+ ';
+
+ }
+ else // IF$view is supplied
+ {
+
+ // Replace any reference to {filter}, {new}, and {nav} in $view
+
+ $view = ereg_replace( "\\{filter\\}", $filter_out, $view );
+ $view = ereg_replace( "\\{link_params\\}", $link_params, $view );
+ $view = ereg_replace( "\\{form_params\\}", $form_params, $view );
+ $view = ereg_replace( "\\{new\\}", $new_out, $view );
+ $view = ereg_replace( "\\{nav\\}", $nav_out, $view );
+
+ // Separate the header, body, and footer
+
+ $head = $body = $foot = "";
+ $x = explode( "{body}", $view );
+ if( count($x) == 2 ) // if {body} found then we have the head and the rest
+ {
+ $head = $x[0];
+ $view = $x[1];
+ }
+ $x = explode( "{/body}", $view );
+ if( count($x) == 2 ) // If {/body} found then we have the body and the foot
+ {
+ $body = $x[0];
+ $foot = $x[1];
+ }
+ else
+ $body = $view;
+
+ // Replace the values $head & $foot - {n} in Header and footer get names of fields
+
+ for( $i=0 ; $i<$fieldcount ; $i++ )
+ {
+ $head = ereg_replace( "\\{".$i."\\}", $outnames[$i], $head );
+ $foot = ereg_replace( "\\{".$i."\\}", $outnames[$i], $foot );
+ $head = ereg_replace( "\\{encode:".$i."\\}", urlencode($outnames[$i]), $head );
+ $foot = ereg_replace( "\\{encode:".$i."\\}", urlencode($outnames[$i]), $foot );
+ }
+
+ $ret .= $a_title.$head; // Output title & head sections
+
+ if( $data )
+ {
+ // Break up body into sections
+
+ $body_parts = explode( "{section}", $body ); // Did I really write it that way???
+
+ // For each body_part
+
+ $bp = 0;
+
+ for( $i=0 ; $i<$reccount ; $i++ ) // For each Record
+ {
+ $b = $body_parts[$bp++]; // Get body section and point to next
+ if( $bp == count($body_parts) ) // if last available body section, start back at first
+ $bp = 0;
+
+ for( $j=0 ; $j<$fieldcount ; $j++ ) // For each field
+ {
+ $b = ereg_replace( "\\{".$j."\\}", $outvals[$i][$j]['data'], $b ); // Replace value for that field
+ $b = ereg_replace( "\\{encode:".$j."\\}", urlencode($outvals[$i][$j]['data']), $b ); // Replace value for that field
+ }
+
+ $ret .= $b; // Output this body section
+ }
+ }
+ else
+ $ret .= "(No results found)\n";
+
+ // Output foot
+
+ $ret .= $foot;
+
+ }
+
+ $ret .= "</CENTER>\n";
+
+ return( array( 'text' => $ret, 'status' => true ) );
+
+}
+
+function admin_list_records( $table, $where, $order, $conn_str, $fields,
+ $options, $fail_mode, $rows = 20, $start = 0,
+ $url, $action, $params, $filters, $a_title, $view = "", $id_field = "", $quick_tip = "" )
+{
+ $r = admin_list_records_r( $table, $where, $order, $conn_str, $fields,
+ $options, $fail_mode, $rows, $start,
+ $url, $action, $params, $filters, $a_title, $view, $id_field, $quick_tip );
+
+ echo $r['text'];
+ return( $r['status'] );
+}
+
+
+
+
+ // Ask for a new record for a table
+
+function admin_new_record_r( $table, $conn_str, $fields, $url, $action, $params, $a_title,
+ $view = "", $options = "", $quick_tip = "" )
+{
+
+ $ret = '';
+
+ $form_name = "edit";
+ $richtext_used = FALSE; // Indicates whether richtext field type has been specified
+ $category_used = FALSE; // Indicates whether categroy field type has been specified
+
+ // Make all submitted parameters available
+
+// extract($GLOBALS[HTTP_GET_VARS]);
+// extract($GLOBALS[HTTP_POST_VARS]);
+
+ // Check for any options
+
+ $borders = strstr( $options, "borders" ) == FALSE ? 0 : 1;
+
+ // Break out configuration data
+
+ $field_table = explode_trim( "|", $fields );
+
+ // Don't be surprised if last field is blank
+
+ if( trim($field_table[count($field_table)-1]) == "" )
+ array_pop( $field_table );
+
+ foreach( $field_table as $key => $r )
+ $field_table[$key] = explode_trim( ",", $r );
+
+ // Check for additional parameters that are passed
+
+ if( !empty($params) )
+ {
+ $param = explode_trim( "|", $params ); // Separate parameters
+ $link_params = $form_params = "";
+ foreach( $param as $p )
+ {
+ $x = explode_trim( ".", $p ); // Separate Names from Values
+ $link_params .= "&".$x[0]."=".urlencode($x[1]);
+ $form_params .= '<INPUT TYPE="hidden" NAME="'.$x[0].'" VALUE="'.$x[1].'">';
+ }
+ }
+
+
+ // For each field in the result
+
+ $outcount = 0;
+ foreach( $field_table as $field )
+ {
+
+ $f = explode_trim( ".", $field[1] );
+
+ $out[$outcount]["display"] = TRUE;
+ $out[$outcount]["field"] = $field[0];
+
+ // Display title fields
+
+ $n = explode_trim( '~', $field[2] ); // Separate QuickTip from title
+ $field_name_color = 'black';
+ switch( $field[3] )
+ {
+ case "TRUE":
+ case "UNIQUE":
+ $field_name_color = 'red';
+ case "FALSE":
+ case "SUPPLIED":
+ case "DISPLAY":
+ case "UNIQUE_NOT_REQ":
+ // setup tip display - requires show_QuickTip() and hide_QuickTip() functions from java_functions.js
+
+ if( count($n) > 1 )
+ $out[$outcount]["name"] = quick_tip( '<font color="'.$field_name_color.'">'.$n[0].'</font>', $n[1] );
+ else
+ $out[$outcount]["name"] = '<FONT COLOR="'.$field_name_color.'">'.$field[2].'</FONT>';
+
+ break;
+
+ case "HIDDEN":
+ $out[$outcount]["name"] = '';
+ break;
+
+ default:
+ $out[$outcount]["name"] = '<FONT COLOR="red">Invalid {required} field specification</FONT>';
+ break;
+ }
+
+ // Display input fields
+
+ switch( $f[0] )
+ {
+ case "password":
+ case "money":
+ case "int":
+ case "order":
+ case "url":
+ case "text":
+ case "inet":
+ case "float":
+ case "fixed":
+ $v = "";
+ $prefix = "";
+ $s = $f[1]; // Field Input Size
+
+ if( $f[0] == "int" ) // If it's an integer, default to 0
+ $v = 0;
+
+ if( $f[0] == "order" ) // If it's an "order" field, default to 9999 - last in list
+ $v = 9999;
+
+ if( $f[0] == "money" ) // If it's money, default to 0.00
+ {
+ $prefix = "$";
+ $v = "0.00";
+ }
+
+ if( $f[0] == "fixed" ) // If it's fixed, default to specified precision
+ {
+ $prefix = "";
+ $v = "0";
+ if( $f[1] > 0 )
+ {
+ $v .= '.';
+ for( $i=0 ; $i<$f[1] ; $i++ )
+ $v .= '0';
+ $s = $f[1] + 4;
+ }
+ }
+
+ switch( $field[3] ) // {required} setting
+ {
+ case "TRUE":
+ case "UNIQUE":
+ case "UNIQUE_NOT_REQ":
+ case "FALSE":
+ if( $f[0] == 'password' )
+ {
+ $out[$outcount]["value"] = $prefix.'<INPUT TYPE="password" NAME="'.$field[0].'" VALUE="'.$v.'" SIZE="'.$s.'">';
+ $out[$outcount]["value"] .= '  enter again <INPUT TYPE="text" NAME="'.$field[0].'_verify" VALUE="'.$v.'" SIZE="'.$s.'">';
+ }
+ else
+ $out[$outcount]["value"] = $prefix.'<INPUT TYPE="text" NAME="'.$field[0].'" VALUE="'.$v.'" SIZE="'.$s.'">';
+ break;
+ case "SUPPLIED":
+ $out[$outcount]["value"] = $prefix.'<INPUT TYPE="text" NAME="'.$field[0].'" SIZE="'.$s.'" VALUE="'.$GLOBALS[$field[4]].'">';
+ break;
+ case "DISPLAY":
+ $out[$outcount]["value"] = $prefix.'<INPUT TYPE="hidden" NAME="'.$field[0].'" VALUE="'.$GLOBALS[$field[4]].'">'.$GLOBALS[$field[4]];
+ break;
+ case "HIDDEN":
+ $out[$outcount]["value"] = '<INPUT TYPE="hidden" NAME="'.$field[0].'" VALUE="'.$GLOBALS[$field[4]].'">';
+ break;
+ default:
+ $out[$outcount]["value"] = '<FONT COLOR="red">Invalid {required} field specification</FONT>';
+ break;
+ }
+ break;
+
+ case "lat":
+
+ $fw = 2;
+ if( $f[1] > 0 )
+ $fw = $f[1];
+
+ switch( $field[3] ) // {required} setting
+ {
+ case "TRUE":
+ case "UNIQUE":
+ case "UNIQUE_NOT_REQ":
+ case "FALSE":
+ $out[$outcount]["value"] = '<SELECT NAME="'.$field[0].'_NS"><OPTION VALUE="N" SELECTED>North<OPTION VALUE="S">South</SELECT>
+ <INPUT TYPE="text" NAME="'.$field[0].'_DEG" VALUE="0" SIZE="4" MAXLENGTH="2" ALIGN="right">°
+ <INPUT TYPE="text" NAME="'.$field[0].'_MIN" VALUE="'.sprintf( "%01.".$fw."f", 0 ).'" SIZE="'.(3+$fw).'" ALIGN="right">\'';
+ break;
+ case "SUPPLIED":
+ case "DISPLAY":
+ $ns = 'N';
+ if( $GLOBALS[$field[4]] < 0 )
+ {
+ $ns = 'S';
+ $GLOBALS[$field[4]] = -1 * $GLOBALS[$field[4]];
+ }
+ $dv = (int) $GLOBALS[$field[4]];
+ $mv = ( $GLOBALS[$field[4]] - $dv ) * 60;
+ if( $field[3] == "SUPPLIED" )
+ $out[$outcount]["value"] = '<SELECT NAME="'.$field[0].'_NS"><OPTION VALUE="N" '.($ns=='N'?'SELECTED':'').'>North<OPTION VALUE="S" '.($ns=='S'?'SELECTED':'').'>South</SELECT>
+ <INPUT TYPE="text" NAME="'.$field[0].'_DEG" VALUE="'.$dv.'" SIZE="4" MAXLENGTH="2" ALIGN="right">°
+ <INPUT TYPE="text" NAME="'.$field[0].'_MIN" VALUE="'.sprintf( "%01.".$fw."f", $mv ).'" SIZE="'.(3+$fw).'" ALIGN="right">\'';
+ else
+ $out[$outcount]["value"] = '<INPUT TYPE="hidden" NAME="'.$field[0].'" VALUE="'.$GLOBALS[$field[4]].'">'
+ .sprintf( "<NOBR>%s %d° %01.".$fw."f'</NOBR>", $ns, $dv, $mv );
+ break;
+ case "HIDDEN":
+ $out[$outcount]["value"] = '<INPUT TYPE="hidden" NAME="'.$field[0].'" VALUE="'.$GLOBALS[$field[4]].'">';
+ break;
+ default:
+ $out[$outcount]["value"] = '<FONT COLOR="red">Invalid {required} field specification</FONT>';
+ break;
+ }
+ break;
+
+ case "lon":
+
+ $fw = 2;
+ if( $f[1] > 0 )
+ $fw = $f[1];
+
+ switch( $field[3] ) // {required} setting
+ {
+ case "TRUE":
+ case "UNIQUE":
+ case "UNIQUE_NOT_REQ":
+ case "FALSE":
+ $out[$outcount]["value"] = '<SELECT NAME="'.$field[0].'_NS"><OPTION VALUE="W" SELECTED>West<OPTION VALUE="E">East</SELECT>
+ <INPUT TYPE="text" NAME="'.$field[0].'_DEG" VALUE="0" SIZE="4" MAXLENGTH="3" ALIGN="right">°
+ <INPUT TYPE="text" NAME="'.$field[0].'_MIN" VALUE="'.sprintf( "%01.".$fw."f", 0 ).'" SIZE="'.(3+$fw).'" ALIGN="right">\'';
+ break;
+ case "SUPPLIED":
+ case "DISPLAY":
+ $ns = 'E';
+ if( $GLOBALS[$field[4]] < 0 )
+ {
+ $ns = 'W';
+ $GLOBALS[$field[4]] = -1 * $GLOBALS[$field[4]];
+ }
+ $dv = (int) $GLOBALS[$field[4]];
+ $mv = ( $GLOBALS[$field[4]] - $dv ) * 60;
+ if( $field[3] == "SUPPLIED" )
+ $out[$outcount]["value"] = '<SELECT NAME="'.$field[0].'_NS"><OPTION VALUE="W" '.($ns=='W'?'SELECTED':'').'>West<OPTION VALUE="E" '.($ns=='E'?'SELECTED':'').'>East</SELECT>
+ <INPUT TYPE="text" NAME="'.$field[0].'_DEG" VALUE="'.$dv.'" SIZE="4" MAXLENGTH="3" ALIGN="right">°
+ <INPUT TYPE="text" NAME="'.$field[0].'_MIN" VALUE="'.sprintf( "%01.".$fw."f", $mv ).'" SIZE="'.(3+$fw).'" ALIGN="right">\'';
+ else
+ $out[$outcount]["value"] = '<INPUT TYPE="hidden" NAME="'.$field[0].'" VALUE="'.$GLOBALS[$field[4]].'">'
+ .sprintf( "<NOBR>%s %d° %01.".$fw."f'</NOBR>", $ns, $dv, $mv );
+ break;
+ case "HIDDEN":
+ $out[$outcount]["value"] = '<INPUT TYPE="hidden" NAME="'.$field[0].'" VALUE="'.$GLOBALS[$field[4]].'">';
+ break;
+ default:
+ $out[$outcount]["value"] = '<FONT COLOR="red">Invalid {required} field specification</FONT>';
+ break;
+ }
+ break;
+
+ case "date":
+
+ $date_f = !empty( $f[1] ) ? time()-$f[1]*86400 : time() ; // Set datestamp of first day to allow
+ $date_t = !empty( $f[2] ) ? time()+$f[2]*86400 : time() ; // Set datestamp of last day to allow
+
+ switch( $field[3] ) // {required} setting
+ {
+ case "TRUE":
+ case "FALSE":
+ $out[$outcount]["value"] = calendar_date_select( "", time(), $date_f, $date_t, $form_name, $field[0], $f[3], $f[4] );
+ break;
+ case "SUPPLIED":
+ $out[$outcount]["value"] = calendar_date_select( $GLOBALS[$field[4]], time(), $date_f, $date_t, $form_name, $field[0], $f[3], $f[4] );
+ break;
+ case "DISPLAY":
+ $out[$outcount]["value"] = $prefix.'<INPUT TYPE="hidden" NAME="'.$field[0].'" VALUE="'.$GLOBALS[$field[4]].'">'.$GLOBALS[$field[4]];
+ break;
+ case "HIDDEN":
+ $out[$outcount]["value"] = '<INPUT TYPE="hidden" NAME="'.$field[0].'" VALUE="'.$GLOBALS[$field[4]].'">';
+ break;
+ default:
+ $out[$outcount]["value"] = '<FONT COLOR="red">Invalid {required} field specification</FONT>';
+ break;
+ }
+ break;
+
+ case "textbox":
+ switch( $field[3] ) // {required} setting
+ {
+ case "TRUE";
+ case "FALSE";
+ $out[$outcount]["value"] = '<TEXTAREA NAME="'.$field[0].'" COLS="'.$f[1].'" ROWS="'.$f[2].'"></TEXTAREA>';
+ break;
+ case "SUPPLIED":
+ $out[$outcount]["value"] = '<TEXTAREA NAME="'.$field[0].'" COLS="'.$f[1].'" ROWS="'.$f[2].'">'
+ .$GLOBALS[$field[4]].'</TEXTAREA>';
+ break;
+ case "DISPLAY":
+ $out[$outcount]["value"] = '<INPUT TYPE="hidden" NAME="'.$field[0].'" VALUE="'.$GLOBALS[$field[4]].'">'.$GLOBALS[$field[4]];
+ break;
+ case "HIDDEN":
+ $out[$outcount]["value"] = '<INPUT TYPE="hidden" NAME="'.$field[0].'" VALUE="'.$GLOBALS[$field[4]].'">';
+ break;
+ default:
+ $out[$outcount]["value"] = '<FONT COLOR="red">Invalid {required} field specification</FONT>';
+ break;
+ }
+ break;
+
+ case "richtext":
+ $def_text = '';
+ switch( $field[3] ) // {required} setting
+ {
+ case "SUPPLIED":
+ $def_text = $GLOBALS[$field[4]];
+ // no break, dropps through
+ case "TRUE";
+ case "FALSE";
+ if( SI_RICHTEXT_TYPE_ENABLED )
+ {
+ if( !$richtext_used )
+ {
+ include_once( SI_BASE_PATH.'/glm_apps/HTMLArea/glm_functions_support.inc' );
+ $richtext_used = TRUE;
+ }
+ $ew = ( trim($f[1]) != "" ? $f[1] : SI_DEFAULT_RICHTEXT_WIDTH );
+ $eh = ( trim($f[2]) != "" ? $f[2] : SI_DEFAULT_RICHTEXT_HEIGHT );
+ htmlarea_add_field( $field[0], $ew, $eh );
+ $out[$outcount]["value"] = '<TABLE BORDER="1" WIDTH="'.$ew.'"><TR><TD><TEXTAREA ID="'.$field[0].'" NAME="'.$field[0].'" COLS="60" ROWS="5">'.$def_text.'</TEXTAREA></TD></TR></TABLE>';
+ }
+ else
+ $out[$outcount]["value"] = '<TEXTAREA ID="'.$field[0].'" NAME="'.$field[0].'" COLS="60" ROWS="5">'.$def_text.'</TEXTAREA>';
+ break;
+ case "DISPLAY":
+ $out[$outcount]["value"] = '<INPUT TYPE="hidden" NAME="'.$field[0].'" VALUE="'.$GLOBALS[$field[4]].'">'.$GLOBALS[$field[4]];
+ break;
+ case "HIDDEN":
+ $out[$outcount]["value"] = '<INPUT TYPE="hidden" NAME="'.$field[0].'" VALUE="'.$GLOBALS[$field[4]].'">';
+ break;
+ default:
+ $out[$outcount]["value"] = '<FONT COLOR="red">Invalid {required} field specification</FONT>';
+ break;
+ }
+ break;
+
+ case "multifield": // multitext.numb_fields.new_line_string
+
+ // THIS FIELD TYPE REQUIRES java_functions.js
+
+ switch( $field[3] )
+ {
+ case "TRUE":
+ case "FALSE":
+ $out[$outcount]["value"] = '<input type="hidden" name="'.$field[0].'_text" id="'.$field[0].'_text" value="'.$f[2].'">
+ <span id="'.$field[0].'_fields">';
+
+ // If there's data, then build existing input lines with data
+ if( ( $x = trim($data[$field[0]]) ) != '' )
+ {
+ $field_data = unserialize( $data[$field[0]] );
+
+ if( $field_data != false && is_array( $field_data ) )
+ {
+ // For each line of inputs
+ for( $i=1 ; $i<=count($field_data) ; $i++ )
+ {
+ $f_line = str_replace( '{line_numb}', $i, $f[2] ); // Set line number in output text
+ // For each input field on the line
+ for( $j=1 ; $j<=$f[1] ; $j++ )
+ $f_line = str_replace( '{field_'.$j.'}', '<input type="text" name="'.$field[0].'_'.$i.'_'.$j.'" id="'.$field[0].'_'.$i.'_'.$j.'" value="'.$field_data[$i-1][$j-1].'" onChange="multi_fields(\''.$field[0].'\',this,'.$f[1].');">', $f_line );
+
+ $out[$outcount]["value"] .= $f_line."\n";
+ }
+ }
+
+ }
+ else
+ $i = 1; // If no data blank line is #1
+
+ // Build 1 spare input line
+ $f_line = str_replace( '{line_numb}', $i, $f[2] ); // Set line number in output text
+ for( $j=1 ; $j<=$f[1] ; $j++ )
+ $f_line = str_replace( '{field_'.$j.'}', '<input type="text" name="'.$field[0].'_'.$i.'_'.$j.'" id="'.$field[0].'_'.$i.'_'.$j.'" value="" onChange="multi_fields(\''.$field[0].'\',this,'.$f[1].');">', $f_line );
+ $out[$outcount]["value"] .= $f_line."\n</span>";
+
+ break;
+
+ case "HIDDEN":
+ case "DISLPLAY":
+ case "SUPPLIED":
+ default:
+ $out[$outcount]["value"] = '<FONT COLOR="red">Invalid {required} field specification</FONT>';
+ break;
+
+ }
+ break;
+
+ case "image":
+ switch( $field[3] ) // {required} setting
+ {
+ case "TRUE":
+ case "FALSE":
+ $out[$outcount]["value"] = '<INPUT TYPE="file" NAME="'.$field[0].'">';
+ break;
+ case "SUPPLIED":
+ case "DISPLAY":
+ case "HIDDEN":
+ $out[$outcount]["value"] = '<FONT COLOR="red">SUPPLIED/DISPLAY/HIDDEN not allowed here for image</FONT>';
+ break;
+ default:
+ $out[$outcount]["value"] = '<FONT COLOR="red">Invalid {required} field specification</FONT>';
+ break;
+ }
+ break;
+
+ case "images":
+
+ switch( $field[3] )
+ {
+ case "TRUE":
+ case "FALSE":
+ $out[$outcount]["value"] = '';
+ $im_num = 0;
+
+ if( empty($f[1]) )
+ $spare = 2;
+ else
+ $spare = $f[1];
+
+ // Check for options
+
+ $im_des = strstr( $f[2], 'descr' );
+ $im_align = strstr( $f[2], 'align' );
+ $im_size = strstr( $f[2], 'size' );
+ if( !empty( $f[3] ) )
+ $im_des_s = $f[3];
+ else
+ $im_des_s = 40;
+ if( !empty( $f[4] ) )
+ $im_des_t = $f[4];
+ else
+ $im_des_t = "Text";
+
+ for( $i=0 ; $i<$spare ; $i++ )
+ {
+ $out[$outcount]["value"] .= '
+ Image #'.($im_num+1).'<BR>
+ <TABLE BORDER="1">
+ <TR>
+ <TD COLSPAN="2" VALIGN="middle"><INPUT TYPE="file" NAME="'.$field[0].'['.$im_num.']">
+ '.( $im_align ? '
+ Align image <SELECT NAME="'.$field[0].'_ALIGN['.$im_num.']">
+ <OPTION VALUE="Left"'.($im_data[$im_num]['align']=="Left"?" SELECTED":"").'>Left
+ <OPTION VALUE="Right"'.($im_data[$im_num]['align']=="Right"?" SELECTED":"").'>Right
+ <OPTION VALUE="Top"'.($im_data[$im_num]['align']=="Top"?" SELECTED":"").'>Top
+ <OPTION VALUE="Middle"'.($im_data[$im_num]['align']=="Middle"?" SELECTED":"").'>Middle
+ <OPTION VALUE="Bottom"'.($im_data[$im_num]['align']=="Bottom"?" SELECTED":"").'>Bottom
+ </SELECT>
+ ' : '<INPUT TYPE="hidden" NAME="align" VALUE="">' ).'
+ '.( $im_size ? '
+ Size
+ <SELECT NAME="'.$field[0].'_SIZE['.$im_num.']">
+ <OPTION VALUE="Original"'.($im_data[$im_num]['size']=="Original"?" SELECTED":"").'>Original
+ <OPTION VALUE="Resized"'.($im_data[$im_num]['size']=="Resized"?" SELECTED":"").'>Resized (width='.SI_RESIZED_SIZE.')
+ <OPTION VALUE="Midsized"'.($im_data[$im_num]['size']=="Midsized"?" SELECTED":"").'>Midsized (width='.SI_MIDSIZED_SIZE.')
+ <OPTION VALUE="Thumb"'.($im_data[$im_num]['size']=="Thumb"?" SELECTED":"").'>Thumb (width='.SI_THUMB_SIZE.')
+ </SELECT>
+ ' : '<INPUT TYPE="hidden" NAME="size" VALUE="">' ).'
+ </TD>
+ </TR>
+ '.( $im_des ? '<TR><TD COLSPAN="2">'.$im_des_t.' <INPUT TYPE="text" NAME="'.$field[0].'_DESCR['.$im_num.']" SIZE="'.$im_des_s.'"></TD>' : '' ).'
+ </TABLE>
+ <BR>';
+ $im_num++;
+ }
+ break;
+
+ case "HIDDEN":
+ case "DISLPLAY":
+ case "SUPPLIED":
+ default:
+ $out[$outcount]["value"] = '<FONT COLOR="red">Invalid {required} field specification</FONT>';
+ break;
+
+ }
+ break;
+
+
+ case "file":
+ switch( $field[3] ) // {required} setting
+ {
+ case "TRUE":
+ case "FALSE":
+ $out[$outcount]["value"] = '<INPUT TYPE="file" NAME="'.$field[0].'">';
+ break;
+ case "SUPPLIED":
+ case "DISPLAY":
+ case "HIDDEN":
+ $out[$outcount]["value"] = '<FONT COLOR="red">SUPPLIED/DISPLAY/HIDDEN not allowed here for file</FONT>';
+ break;
+ default:
+ $out[$outcount]["value"] = '<FONT COLOR="red">Invalid {required} field specification</FONT>';
+ break;
+ }
+ break;
+
+ case "category":
+
+ // If picklist is selected - use that for selection
+
+ if( strstr($f[3],'picklist') )
+ {
+ if( ($nodes = cat_get_nodes($f[1])) )
+ {
+ $out[$outcount]["value"] .= '<SELECT NAME="'.$field[0].'"><OPTION VALUE="">';
+
+ reset($nodes);
+ while( list($key, $val) = each($nodes) )
+ {
+ $out[$outcount]["value"] .= '<OPTION VALUE="'.$val['id'].'">';
+ if( strstr($f[3],'fullpath') )
+ $out[$outcount]["value"] .= $val['cat_fullpath'];
+ else
+ {
+ for( $i=0 ; $i<$val['cat_level'] ; $i++ )
+ $out[$outcount]["value"] .= " ";
+ $out[$outcount]["value"] .= $val['name'];
+ }
+ }
+ $out[$outcount]["value"] .= '</SELECT>';
+ }
+ else
+ $out[$outcount]["value"] .= 'No categories listed.';
+ }
+ else // Otherwise use pop-up
+ {
+
+ // Check if a value for this field is supplied
+ if( !empty($GLOBALS[$field[4]]) )
+ {
+ if( ($cval = cat_get_node( $f[1], "id = ".$GLOBALS[$field[4]] ) ) )
+ {
+ $cat_id = $GLOBALS[$field[4]];
+ if( strstr($f[3],'fullpath') )
+ $cat_name = $cval['cat_fullpath'];
+ else
+ $cat_name = $cval['cat_name'];
+ }
+ }
+ else
+ {
+ $cat_id = 0;
+ $cat_name = " ";
+ }
+
+ $pop_width = !empty($f[4]) ? $f[4] : 200 ;
+ $pop_height = !empty($f[5]) ? $f[5] : 300 ;
+ $edit_width = !empty($f[6]) ? $f[6] : 400 ;
+ $edit_height = !empty($f[7]) ? $f[7] : 500 ;
+
+ $out[$outcount]["value"] .= "
+ <script language=\"JavaScript1.2\">
+ <!--
+ function category_select_popup_".$field[0]."( target )
+ {
+ // Pass values to the calendar
+
+ tempX = 400;
+ tempY = 300;
+
+ node_id = this.document.getElementById( target ).value;
+ var theUrl='".SI_BASE_URL."/glm_apps/category_select_popup.phtml?id=' + node_id + '&field_name=".$field[0]."&table=".$f[1]."&options=".urlencode($f[3])."&edit_width=".$edit_width."&edit_height=".$edit_height."&pop_width=".$pop_width."&pop_height=".$pop_height."';
+
+ tempX = tempX - 90;
+ tempY = tempY - 170;
+
+ if (navigator.appName == 'Netscape')
+ {
+ CategoryWind = window.open( theUrl, 'Calendar','scrollbars=yes,toolbar=no,resizable=yes,width=".$pop_width.",height=".$pop_height.",screenx=' + tempX + ',screeny=' + tempY,1 );
+ }
+ else
+ {
+ CategoryWind = window.open( theUrl, 'Calendar','scrollbars=no,toolbar=no,resizable=yes,width=".$pop_width.",height=".$pop_height.", top=' + tempY + ', left=' + tempX,1 );
+ }
+
+ CategoryWind.focus();
+ }
+ -->
+ </script>
+ ";
+
+ $out[$outcount]["value"] .= '<INPUT TYPE="text" NAME="'.$field[0].'_NAME" ID="'.$field[0].'_NAME" VALUE="'.$cat_name.'" SIZE="'.$f[2].'" READONLY="readonly" STYLE="background-color: #eeeeee;">
+ <INPUT TYPE="hidden" NAME="'.$field[0].'" ID="'.$field[0].'" VALUE="'.$cat_id.'">
+ <A HREF="javascript:category_select_popup_'.$field[0].'(\''.$field[0].'\')">[Change]</A>
+ ';
+ }
+ break;
+
+ case "pointer":
+
+ // If {value_field} type option supplied use that, otherwise use id of record as VALUE
+ $value_field = !empty($f[3]) ? $f[3] : "id" ;
+
+ // If {where} type option supplied use that, otherwise get all possibilities from other table
+ $w = !empty($f[4]) ? " WHERE ".$f[4] : "" ;
+
+ // If picklist options
+ $p = !empty($f[5]) ? $f[5] : "" ;
+
+ // Sort field for query
+ $s = !empty($f[6]) ? $f[6] : "id" ;
+
+ // Pointer options
+
+ $pointer_option_add_field = FALSE;
+ if( ! empty($f[7]) )
+ {
+ $option_table = explode_trim( ",", $f[7] );
+ foreach( $option_table as $option )
+ {
+ switch( $option )
+ {
+ case "add_field": // Option to display a field for entering a new target
+ $pointer_option_add_field = TRUE;
+ break;
+
+ default:
+ break;
+ }
+ }
+ }
+
+
+ $s = !empty($f[6]) ? $f[6] : "id" ;
+
+ // Check if a value for this field is supplied
+ if( !empty($field[4]) )
+ $supplied = $GLOBALS[$field[4]];
+ else
+ $supplied = "";
+
+ switch( $field[3] )
+ {
+ // These require us to build a pick list
+ case "TRUE":
+ case "FALSE":
+ case "SUPPLIED":
+
+ $d = db_auto_get_data( "SELECT * FROM ".$f[1].$w." ORDER BY ".$s.";", $conn_str, FALSE, 500 );
+
+ if( !$d )
+ {
+ $out[$outcount]["value"] = '<FONT COLOR="red">No records from which to build picklist</FONT>';
+ }
+ else
+ {
+ // Create table of possibilities for pick list
+
+ unset( $da );
+ while( list($key, $val) = each($d) )
+ {
+ $da[$val[$value_field]] = $val[$f[2]];
+
+ // If {required} setting is "SUPPLIED"
+ if( $field[3] == "SUPPLIED" && $val[$value_field] == $GLOBALS[$field[4]] )
+ $dkey = $val[$value_field]; // Get id of record we're refering to
+ }
+
+ $out[$outcount]["value"] = build_picklist( $field[0], $da, $dkey, "standard", $p );
+ }
+
+ // Provide an additional input field to permit adding a new target value
+
+ if( $pointer_option_add_field )
+ $out[$outcount]["value"] .= '<NOBR> or add new value <INPUT TYPE="text" NAME="'.$field[0].'_add_field"></NOBR>';
+
+ break;
+
+ // These require us to just get the data for the specific index
+
+ case "DISPLAY":
+ case "HIDDEN":
+ if( empty($field[4]) )
+ {
+ $out[$outcount]["value"] = '<FONT COLOR="red">Missing value for DISPLAY & HIDDEN</FONT>';
+ break;
+ }
+ $d = db_auto_get_row( "SELECT * FROM ".$f[1]." WHERE ".$value_field." = ".$GLOBALS[$field[4]]." ORDER BY ".$s.";", 0, $conn_str, $fail_mode );
+ if( !$d )
+ {
+ $out[$outcount]["value"] = '<FONT COLOR="red">Specified value for DISPLAY/HIDDEN not found in table</FONT>';
+ break;
+ }
+ else
+ $out[$outcount]["value"] = '<INPUT TYPE="hidden" NAME="'.$field[0].'" VALUE="'.$d[$value_field].'">';
+
+ if( $field[3] == "DISPLAY" ) // If DISPLAY add the visible data after the hidden field
+ {
+ if( $f[5] == "checkbox" )
+ $out[$outcount]["value"] .= ($d[$f[2]]=='t'?"Yes":"No");
+ else
+ $out[$outcount]["value"] .= $d[$f[2]];
+ }
+
+ break;
+
+ default:
+ $out[$outcount]["value"] = '<FONT COLOR="red">Invalid {required} field specification</FONT>';
+ break;
+ }
+ break;
+
+ case "list":
+ // If picklist options
+ $p = !empty($f[3]) ? $f[3] : "" ;
+
+ $option_table = "";
+ $opts = explode_trim( "~", $f[1] ); // Separate list options
+ $def_value = !empty($f[2]) ? $f[2] : "" ;
+ foreach( $opts as $opt )
+ {
+ $os = explode_trim( "^", $opt ); // Separate value from displayed text
+ $option_table[$os[0]] = $os[1];
+ }
+ $out[$outcount]["value"] = build_picklist( $field[0], $option_table, $def_value, "standard", $p );
+ if( $out[$outcount]["value"] == '' )
+ $out[$outcount]["value"] = '(no options listed)';
+ break;
+
+ case "state": // Special case of list
+
+ $out[$outcount]["value"] = build_picklist( $field[0], $GLOBALS['si_states_array'], $f[1], "standard", $f[2] );
+ break;
+
+ case "country": // Special case of list
+
+ $out[$outcount]["value"] = build_picklist( $field[0], $GLOBALS['si_countries_array'], $f[1], "standard", $f[2] );
+ break;
+
+ case "checkbox":
+ switch( $field[3] ) // {required} setting
+ {
+ case "TRUE":
+ case "FALSE":
+ $out[$outcount]["value"] = '<INPUT TYPE="checkbox" NAME="'.$field[0].'">';
+ break;
+
+ case "SUPPLIED":
+ $out[$outcount]["value"] = '<INPUT TYPE="checkbox" NAME="'.$field[0].'" '.($GLOBALS[$field[4]]=="t"?"CHECKED":"").'>';
+ break;
+
+ case "HIDDEN":
+ $out[$outcount]["value"] = '<INPUT TYPE="hidden" NAME="'.$field[0].'" VALUE="'.$GLOBALS[$field[4]].'">';
+ break;
+
+ case "DISPLAY":
+ $out[$outcount]["value"] = '<FONT COLOR="red">DISPLAY/HIDDEN not available for type checkbox at this time</FONT>';
+ break;
+
+ default:
+ $out[$outcount]["value"] = '<FONT COLOR="red">Invalid {required} field specification</FONT>';
+ break;
+ }
+ break;
+
+ case "bitmap":
+
+ $bmap = explode_trim( "~", $f[1] );
+ $out[$outcount]["value"] = "";
+
+ switch( $field[3] ) // {required} setting
+ {
+ case "TRUE":
+ case "FALSE":
+ for( $i=0 ; $i<count($bmap) ; $i++ )
+ if( $bmap[$i] != '' )
+ $out[$outcount]["value"] .= '<INPUT TYPE="checkbox" NAME="'.$field[0]."[$i]".'">'.$bmap[$i].'<BR>';
+ break;
+
+ case "SUPPLIED":
+ case "DISPLAY":
+ case "HIDDEN":
+ for( $i=0 ; $i<count($bmap) ; $i++ )
+ if( $bmap[$i] != '' )
+ {
+ $x = $GLOBALS[$field[4]] & pow( 2, $i ) ? " CHECKED" : ""; // Check if this bit set in supplied value
+ $out[$outcount]["value"] .= '<INPUT TYPE="checkbox" NAME="'.$field[0]."[$i]".'"'.$x.'>'.$bmap[$i].'<BR>';
+ }
+ break;
+
+ default:
+ $out[$outcount]["value"] = '<FONT COLOR="red">Invalid {required} field specification</FONT>';
+ break;
+ }
+ if( $out[$outcount]["value"] == '' )
+ $out[$outcount]["value"] = '(no options listed)';
+ break;
+
+ case "break":
+ if( !empty($f[1]) ) // if {t1} is supplied
+ $out[$outcount]["value"] = $f[1];
+ else
+ $out[$outcount]["value"] = '<FONT COLOR="red">No {text} supplied for type "break"</FONT>';
+ break;
+
+ default:
+ $out[$outcount]["value"] = '<FONT COLOR="red">UNKNOWN FIELD TYPE: '.$f[0].' for '.$field[0].'</FONT>';
+ break;
+
+ } // switch( field )
+
+ $outcount++;
+ } // foreach( field )
+
+ // Build submit button and hidden action and put in {submit}
+
+ $submit = '
+ <INPUT TYPE="hidden" NAME="Action" VALUE="'.$action.'">
+ '.$form_params.'
+ <INPUT TYPE="submit" NAME="Option" VALUE="Add New">
+ ';
+
+ // Replace parameters in Title
+
+ for( $i=0 ; $i<$outcount ; $i++ )
+ {
+ $a_title = ereg_replace( "\\{".$i."\\}", $out[$i]["value"], $a_title );
+ $a_title = ereg_replace( "\\{encode:".$i."\\}", urlencode($out[$i]["value"]), $a_title );
+ }
+
+ $a_title = ereg_replace( "\\{link_params\\}", $link_params, $a_title );
+ $a_title = ereg_replace( "\\{form_params\\}", $form_params, $a_title );
+
+ // Add QuickTip if provided
+
+ if( trim($quick_tip) != '' )
+ $a_title = quick_tip( $a_title, $quick_tip );
+
+ // Output results
+
+ // Display top of page and open form
+
+ $ret .= '<CENTER>
+ <FORM ENCTYPE="multipart/form-data" ACTION="'.$url.'" METHOD="post" ID="'.$form_name.'" NAME="'.$form_name.'">
+ ';
+
+ $hidden_data = '';
+ if( empty($view) ) // If there's no format spec in $view
+ {
+
+ $ret .= $a_title.'
+ <FONT COLOR="red">(Required fields in red)</FONT><BR>
+ <TABLE BORDER="'.$borders.'" '.($borders>0?' CELLPADDING="5"':"").'>
+ ';
+
+ for( $i=0 ; $i<$outcount ; $i++ )
+ {
+ if( $out[$i]["name"] != '' )
+ $ret .= '<TR><TH ALIGN="right" VALIGN="top">'.$out[$i]["name"]
+ .' </TH><TD ALIGN="left">'.$out[$i]["value"].' </TD></TR>
+ ';
+ else
+ $hidden_data .= $out[$i]["value"];
+ }
+
+ $ret .= ' <P>
+ </TABLE>'.$hidden_data.$submit; // Output the Confirm field and submit button
+
+ }
+ else // Otherwise use $view to output data
+ {
+ reset( $out );
+ while( list ($k, $v) = each($out) )
+ {
+ $a_title = ereg_replace( "\\{".$v['field']."\\}", $v["value"], $a_title );
+ $view = ereg_replace( "\\{".$v['field']."\\}", $v["value"], $view );
+ $a_title = ereg_replace( "\\{encode:".$v['field']."\\}", urlencode($v["value"]), $a_title );
+ $view = ereg_replace( "\\{encode:".$v['field']."\\}", urlencode($v["value"]), $view );
+ }
+
+ for( $i=0 ; $i<$outcount ; $i++ )
+ {
+ $view = ereg_replace( "\\{".$i."\\}", $out[$i]["value"], $view );
+ $view = ereg_replace( "\\{encode:".$i."\\}", urlencode($out[$i]["value"]), $view );
+ }
+ $view = ereg_replace( "\\{submit\\}", $submit, $view );
+ $view = ereg_replace( "\\{link_params\\}", $link_params, $view );
+ $view = ereg_replace( "\\{form_params\\}", $form_params, $view );
+ $ret .= $a_title.$view;
+ }
+
+ // Display bottom of page and close form
+
+ // If HTMLArea is used, attach scripts to set that up to submit button tags
+
+ if( $richtext_used )
+ $ret .= htmlarea_setup_script();
+
+ $ret .= ' </FORM>
+ </CENTER>
+ ';
+
+ return( array( 'text' => $ret, 'status' => true ) );
+}
+
+function admin_new_record( $table, $conn_str, $fields, $url, $action, $params, $a_title, $view = "", $options = "", $quick_tip = "" )
+{
+ $r = admin_new_record_r( $table, $conn_str, $fields, $url, $action, $params, $a_title, $view, $options, $quick_tip );
+
+ echo $r['text'];
+ return( $r['status'] );
+
+}
+
+
+
+
+ // Add new record to a table
+
+function admin_add_new_record_r( $table, $conn_str, $fields, $url, $action, $params, $a_title, $view = "", $quick_tip = "" )
+{
+
+ $ret = '';
+
+ // Make all submitted parameters available
+
+// extract($GLOBALS[HTTP_POST_VARS]);
+// extract($GLOBALS[HTTP_GET_VARS]);
+// extract($GLOBALS[HTTP_POST_FILES]);
+
+ // Break out configuration data
+
+ $field_table = explode_trim( "|", $fields );
+
+ // Don't be surprised if last field is blank
+
+ if( trim($field_table[count($field_table)-1]) == "" )
+ array_pop( $field_table );
+
+ foreach( $field_table as $key => $r )
+ $field_table[$key] = explode_trim( ",", $r );
+
+ // Check for additional parameters that are passed
+
+ if( !empty($params) )
+ {
+ $param = explode_trim( "|", $params ); // Separate parameters
+ $link_params = $form_params = "";
+ foreach( $param as $p )
+ {
+ $x = explode_trim( ".", $p ); // Separate Names from Values
+ $link_params .= "&".$x[0]."=".urlencode($x[1]);
+ $form_params .= '<INPUT TYPE="hidden" NAME="'.$x[0].'" VALUE="'.$x[1].'">';
+ }
+ }
+
+ $names = $values = $not_supplied = $problem = "";
+
+ // For each field in the result
+
+ $comma = ""; // first parameter doesn't need a comma in front of it
+ $outcount = 0;
+ foreach( $field_table as $field )
+ {
+ $names .= $comma.$field[0]; // Add field name to $names for INSERT
+ $out[$outcount]["name"] = $field[0]; // Make name available to view
+ $f = explode_trim( ".", $field[1] ); // Break out optional parameters from field type
+ $fta = explode_trim( "~", $field[2] );
+ $field_title_only = $fta[0];
+
+ switch( $f[0] )
+ {
+ case "money":
+ case "order":
+ case "int":
+ case "float":
+ case "fixed":
+ case "pointer":
+ case "category":
+
+ // Handle special cases in this group of types
+
+ switch( $f[0] )
+ {
+
+ case "money":
+
+ // Get rid of "$" and "," from silly users
+
+ $GLOBALS[$field[4]] = ereg_replace( "[\$,]", "", $GLOBALS[$field[4]] );
+ break;
+
+ case "pointer":
+
+ // Check for add_field values - Add new value to pointer target record
+
+ if( ($add_value = trim($GLOBALS[$field[4].'_add_field'])) != '' )
+ {
+ // If value already exists warn user.
+
+ if( db_auto_get_row( "SELECT * FROM ".$f[1]." WHERE ".$f[2]." = '".trim($GLOBALS[$field[4].'_add_field'])."';", 0, $conn_str, $fail_mode ) )
+ $not_supplied .= $field_title_only.": Value already exists in pick list, don't try to add it again.<BR>";
+ else
+ {
+ // Otherwise, add new value and use pointer to that
+
+ $add_result = db_auto_get_row( "INSERT INTO ".$f[1]." ( ".$f[2]." ) VALUES ( '".trim($GLOBALS[$field[4].'_add_field'])."' );
+ SELECT currval( '".$f[1]."_id_seq' ) AS id;", 0, $conn_str, $fail_mode );
+ $GLOBALS[$field[4]] = $add_result['id'];
+ }
+ }
+
+ break;
+
+ default:
+ break;
+ }
+
+
+ $out[$outcount]["value"] = $GLOBALS[$field[4]];
+ if( !empty($GLOBALS[$field[4]]) && !is_numeric($GLOBALS[$field[4]]) )
+ $not_supplied .= $field_title_only.': "'.$GLOBALS[$field[4]].'" Is not an Integer Number<BR>';
+
+ switch( $field[3] )
+ {
+ case "SUPPLIED":
+ $values .= $comma.$GLOBALS[$field[4]];
+ break;
+
+ case "TRUE":
+ if( !is_numeric($GLOBALS[$field[4]]) )
+ $not_supplied .= $field_title_only.": Not Supplied<BR>";
+ else
+ $values .= $comma.$GLOBALS[$field[4]];
+ break;
+
+ case "FALSE":
+ if( is_numeric($GLOBALS[$field[4]]) )
+ $values .= $comma.$GLOBALS[$field[4]];
+ else
+ $values .= $comma."0"; // Default to 0
+ break;
+
+ case "UNIQUE":
+ if( empty($GLOBALS[$field[4]]) && $GLOBALS[$field[4]] != 0 )
+ $not_supplied .= $field_title_only.": Not Supplied<BR>";
+ else
+ $values .= $comma.$GLOBALS[$field[4]];
+
+ if( db_auto_get_row( "SELECT * FROM $table WHERE ".$field[0]." = ".trim($GLOBALS[$field[4]]).";", 0, $conn_str, $fail_mode ) )
+ $not_supplied .= $field_title_only.": Already exists, must be unique<BR>";
+ break;
+
+ case "UNIQUE_NOT_REQ":
+ if( is_numeric($GLOBALS[$field[4]]) )
+ $values .= $comma.$GLOBALS[$field[4]];
+ else
+ $values .= $comma."0"; // Default to 0
+
+ if( !empty($GLOBALS[$field[4]]) && $GLOBALS[$field[4]] != 0 && db_auto_get_row( "SELECT * FROM $table WHERE ".$field[0]." = ".trim($GLOBALS[$field[4]]).";", 0, $conn_str, $fail_mode ) )
+ $not_supplied .= $field_title_only.": Already exists, must be unique<BR>";
+
+ break;
+
+ default:
+ $problem .= '<FONT COLOR="red">ERROR: Invalid "Required" field name "'.$field[3].'" in function call</FONT><BR>';
+ break;
+ }
+ break;
+
+
+ case "lat":
+ // If we've been passed a decimal degree value
+ if( !empty($GLOBALS[$field[4]]) )
+ $v = $GLOBALS[$field[4]];
+ else // Otherwise compile from parts
+ {
+ if( $GLOBALS[$field[4].'_DEG'] > 90 || $GLOBALS[$field[4].'_DEG'] < 0 || $GLOBALS[$field[4].'_MIN'] >= 60 || $GLOBALS[$field[4].'_MIN'] < 0 )
+ {
+ $not_supplied .= $field_title_only.": Invalid entry. Degrees must be 0 to 90 and Minutes must be 0 to less than 60<BR>";
+ break;
+ }
+ $v = ( $GLOBALS[$field[4].'_NS'] == "N" ? 1 : -1 ) * ( $GLOBALS[$field[4].'_DEG'] + ( $GLOBALS[$field[4].'_MIN'] / 60 ) );
+ }
+ $fw = 2;
+ // Rebuild value for display
+ if( $f[1] > 0 )
+ $fw = $f[1];
+ $ns = 'N';
+ if( ($v2=$v) < 0 )
+ {
+ $ns = 'S';
+ $v2 = -1 * $v2;
+ }
+ $dv = (int) $v2;
+ $mv = ( $v2 - $dv ) * 60;
+ $out[$outcount]["value"] = sprintf( "%s %d° %01.".$fw."f'", $ns, $dv, $mv );
+ switch( $field[3] )
+ {
+ case "SUPPLIED":
+ $values .= $comma.$v;
+ break;
+
+ case "TRUE":
+ if( empty($v) )
+ $not_supplied .= $field_title_only.": Not Supplied<BR>";
+ else
+ $values .= $comma.$v;
+ break;
+
+ case "FALSE":
+ $values .= $comma.$v;
+ break;
+
+ case "UNIQUE":
+ if( db_auto_get_row( "SELECT * FROM $table WHERE ".$field[0]." = $v;", 0, $conn_str, $fail_mode ) )
+ $not_supplied .= $field_title_only.": Already exists, must be unique<BR>";
+ $values .= $comma.$v;
+ break;
+
+ case "UNIQUE_NOT_REQ":
+ if( !empty($GLOBALS[$field[4]]) && $GLOBALS[$field[4]] != 0 && db_auto_get_row( "SELECT * FROM $table WHERE ".$field[0]." = $v;", 0, $conn_str, $fail_mode ) )
+ $not_supplied .= $field_title_only.": Already exists, must be unique<BR>";
+ $values .= $comma.$v;
+ break;
+
+ default:
+ $problem .= '<FONT COLOR="red">ERROR: Invalid "Required" field name "'.$field[3].'" in function call</FONT><BR>';
+ break;
+ }
+ break;
+
+ case "lon":
+ // If we've been passed a decimal degree value
+ if( !empty($GLOBALS[$field[4]]) )
+ $v = $GLOBALS[$field[4]];
+ else // Otherwise compile from parts
+ {
+ if( $GLOBALS[$field[4].'_DEG'] > 180 || $GLOBALS[$field[4].'_DEG'] < 0 || $GLOBALS[$field[4].'_MIN'] >= 60 || $GLOBALS[$field[4].'_MIN'] < 0 )
+ {
+ $not_supplied .= $field_title_only.": Invalid entry. Degrees must be 0 to 180 and Minutes must be 0 to less than 60<BR>";
+ break;
+ }
+ $v = ( $GLOBALS[$field[4].'_NS'] == "E" ? 1 : -1 ) * ( $GLOBALS[$field[4].'_DEG'] + ( $GLOBALS[$field[4].'_MIN'] / 60 ) );
+ }
+ $fw = 2;
+ // Rebuild value for display
+ if( $f[1] > 0 )
+ $fw = $f[1];
+ $ns = 'E';
+ if( ($v2=$v) < 0 )
+ {
+ $ns = 'W';
+ $v2 = -1 * $v2;
+ }
+ $dv = (int) $v2;
+ $mv = ( $v2 - $dv ) * 60;
+ $out[$outcount]["value"] = sprintf( "%s %d° %01.".$fw."f'", $ns, $dv, $mv );
+ switch( $field[3] )
+ {
+ case "SUPPLIED":
+ $values .= $comma.$v;
+ break;
+
+ case "TRUE":
+ if( empty($v) )
+ $not_supplied .= $field_title_only.": Not Supplied<BR>";
+ else
+ $values .= $comma.$v;
+ break;
+
+ case "FALSE":
+ $values .= $comma.$v;
+ break;
+
+ case "UNIQUE":
+ if( db_auto_get_row( "SELECT * FROM $table WHERE ".$field[0]." = $v;", 0, $conn_str, $fail_mode ) )
+ $not_supplied .= $field_title_only.": Already exists, must be unique<BR>";
+ $values .= $comma.$v;
+ break;
+
+ case "UNIQUE_NOT_REQ":
+ if( !empty($GLOBALS[$field[4]]) && $GLOBALS[$field[4]] != 0 && db_auto_get_row( "SELECT * FROM $table WHERE ".$field[0]." = $v;", 0, $conn_str, $fail_mode ) )
+ $not_supplied .= $field_title_only.": Already exists, must be unique<BR>";
+ $values .= $comma.$v;
+ break;
+
+ default:
+ $problem .= '<FONT COLOR="red">ERROR: Invalid "Required" field name "'.$field[3].'" in function call</FONT><BR>';
+ break;
+ }
+
+ break;
+
+
+ case "password":
+ case "list":
+ case "text":
+ case "inet":
+ case "state":
+ case "country":
+ case "url":
+ case "richtext":
+ case "textbox":
+
+ // Check for special cases
+
+ switch( $f[0] )
+ {
+
+ case "password":
+ if( $GLOBALS[$field[4]] != $GLOBALS[$field[4].'_verify'] )
+ $not_supplied .= $field_title_only.': The two copies of this password do not match. <BR>';
+ break;
+
+ case "inet":
+ if( ($r = clean_input( $field[0], 'inet' )) != '' )
+ $problem .= '<FONT COLOR="red">'.$field_title_only.': Not a valid IP address or netmask.</FONT><BR>';
+ break;
+
+ case "list":
+ // If 'multi' is selected for picklist option, then compile results from array
+ if( strstr( $f[3], 'multi' ) )
+ {
+ $m_val = $sep = '';
+
+ // Place results in '~' separated string for storage.
+
+ if( is_array($GLOBALS[$field[4]]) )
+ foreach( $GLOBALS[$field[4]] as $m )
+ {
+ $m_val .= $sep.$m;
+ $sep = '~';
+ }
+ $GLOBALS[$field[4]] = $m_val;
+ }
+
+ break;
+
+ default:
+ break;
+ }
+
+ $v = str_replace( "%27", "\'", $GLOBALS[$field[4]] );
+ if( trim(strip_tags($v)) == '' )
+ $v = '';
+ $out[$outcount]["value"] = $v;
+ switch( $field[3] )
+ {
+ case "SUPPLIED":
+ $values .= $comma."'".$v."'";
+ break;
+
+ case "TRUE":
+ if( empty($v) )
+ $not_supplied .= $field_title_only.": Not Supplied<BR>";
+ else
+ $values .= $comma."'".$v."'";
+ break;
+
+ case "FALSE":
+ $values .= $comma."'".$v."'";
+ break;
+
+ case "UNIQUE":
+ if( empty($v) )
+ $not_supplied .= $field_title_only.": Not Supplied<BR>";
+ else
+ {
+ if( db_auto_get_row( "SELECT * FROM $table WHERE ".$field[0]." = '".trim($v)."';", 0, $conn_str, $fail_mode ) )
+ $not_supplied .= $field_title_only.": Already exists, must be unique<BR>";
+ }
+ $values .= $comma."'".$v."'";
+ break;
+
+ case "UNIQUE_NOT_REQ":
+ if( !empty($v) )
+ {
+ if( db_auto_get_row( "SELECT * FROM $table WHERE ".$field[0]." = '".trim($v)."';", 0, $conn_str, $fail_mode ) )
+ $not_supplied .= $field_title_only.": Already exists, must be unique<BR>";
+ }
+ $values .= $comma."'".$v."'";
+ break;
+
+ default:
+ $problem .= '<FONT COLOR="red">ERROR: Invalid "Required" field name "'.$field[3].'" in function call</FONT><BR>';
+ break;
+ }
+ break;
+
+ case "date":
+ $out[$outcount]["value"] = $GLOBALS[$field[4]];
+
+ if( trim($GLOBALS[$field[4]]) == "" ) // Blank dates must be "NULL"
+ $dval = "NULL";
+ else
+ $dval = "'".$GLOBALS[$field[4]]."'";
+
+ switch( $field[3] )
+ {
+ case "SUPPLIED":
+ $values .= $comma.$dval;
+ break;
+
+ case "TRUE":
+ if( empty($GLOBALS[$field[4]]) )
+ $not_supplied .= $field_title_only.": Not Supplied<BR>";
+ else
+ $values .= $comma.$dval;
+ break;
+
+ case "FALSE":
+ $values .= $comma.$dval;
+ break;
+
+ case "UNIQUE":
+ if( db_auto_get_row( "SELECT * FROM $table WHERE ".$field[0]." = '".trim($GLOBALS[$field[4]])."';", 0, $conn_str, $fail_mode ) )
+ $not_supplied .= $field_title_only.": Already exists, must be unique<BR>";
+ $values .= $comma.$dval;
+ break;
+
+ case "UNIQUE_NOT_REQ":
+ if( !empty($GLOBALS[$field[4]]) && db_auto_get_row( "SELECT * FROM $table WHERE ".$field[0]." = '".trim($GLOBALS[$field[4]])."';", 0, $conn_str, $fail_mode ) )
+ $not_supplied .= $field_title_only.": Already exists, must be unique<BR>";
+ $values .= $comma.$dval;
+ break;
+
+ default:
+ $problem .= '<FONT COLOR="red">ERROR: Invalid "Required" field name "'.$field[3].'" in function call</FONT><BR>';
+ break;
+ }
+ break;
+
+ case "multifield":
+
+ $line = 0;
+ $empty = TRUE;
+ $m_data = array();
+
+ // Build array of data to store
+ while( isset( $GLOBALS[$field[4].'_'.($line+1).'_1'] ) )
+ {
+ $line++;
+ if( trim($GLOBALS[$field[4].'_'.$line.'_1']) != '' )
+ {
+ $a = array();
+ for( $i=1 ; $i<=$f[1] ; $i++ )
+ {
+ $a[$i-1] = trim( str_replace("%27", "\'", $GLOBALS[$field[4].'_'.($line).'_'.$i] ) );
+ if( $a[$i-1] != '' )
+ $empty = FALSE;
+ }
+ array_push( $m_data, $a );
+ }
+ }
+
+ if( !$empty )
+ $v = serialize( $m_data );
+ else
+ $v = '';
+
+ $out[$outcount]["value"] = $v;
+
+ switch ($field[3])
+ {
+ case "TRUE" :
+ if( $empty )
+ $not_supplied .= $field_title_only.": Not Supplied<BR>";
+ else
+ $values .= $comma."'".$v."'";
+ break;
+
+ case "FALSE" :
+ $values .= $comma."'".$v."'";
+ break;
+
+ default :
+ $problem .= '<FONT COLOR="red">ERROR: Invalid "Required" field name "'.$field[3].'" in function call</FONT><BR>';
+ break;
+ }
+
+ break;
+
+ case "image":
+
+ $out[$outcount]["value"] = "IMAGES Not Available for View at this time";
+ switch( $field[3] )
+ {
+ case "SUPPLIED":
+ $problem .= '<FONT COLOR="red">ERROR: "SUPPLIED" not permitted as option for image input</FONT><BR>';
+ break;
+
+ case "TRUE":
+ if( $GLOBALS[$field[4]."_name"] == "" )
+ $not_supplied .= $field_title_only.": Not Supplied<BR>";
+ // no break; here - falls through to FALSE
+
+ case "FALSE":
+ if( $GLOBALS[$field[4]."_name"] != "" )
+ $values .= $comma."'".process_image( $GLOBALS[$field[4]], $GLOBALS[$field[4]."_name"] )."'";
+ else
+ $values .= $comma."''";
+ break;
+
+ default:
+ $problem .= '<FONT COLOR="red">ERROR: Invalid "Required" field name "'.$field[3].'" in function call</FONT><BR>';
+ break;
+ }
+ break;
+
+ case "images":
+
+ // Note that the image field is only updated when required so field name is set below along with value
+
+ $out[$outcount]["value"] = "IMAGES Not Available for View at this time";
+ switch( $field[3] )
+ {
+ case "FALSE":
+ if( is_array( ($im_data = $GLOBALS[$field[4]]) ) )
+ {
+ $im_cur = unserialize( $data[$field[0]] ); // Convert existing data to an array
+ $im_new = array();
+ $im_new_num = 0;
+ for( $im_num=0 ; $im_num<count($GLOBALS[$field[0]."_name"]) ; $im_num++ )
+ {
+ // If new image is supplied, store it
+ if( $GLOBALS[$field[0]."_name"][$im_num] != "" )
+ {
+// if( $im_cur[$im_num]['filename'] ) // If there's already an image, delete it before storing the new one
+// delete_image( $im_cur[$im_num]['filename'] );
+ $im_new[$im_new_num]['filename'] = process_image( $GLOBALS[$field[0]][$im_num], $GLOBALS[$field[0]."_name"][$im_num] );
+ $im_new[$im_new_num]['descr'] = $GLOBALS[$field[0].'_DESCR'][$im_num];
+ $im_new[$im_new_num]['align'] = $GLOBALS[$field[0].'_ALIGN'][$im_num];
+ $im_new[$im_new_num]['size'] = $GLOBALS[$field[0].'_SIZE'][$im_num];
+ $im_new_num++;
+ }
+
+
+// // Else, if there's an image in the database and we're deleting
+// elseif( $im_cur[$im_num]['filename'] != "" && isset( $GLOBALS[$field[0]."_DELETE"][$im_num] ) )
+// delete_image( $im_cur[$im_num]['filename'] );
+// elseif( $im_cur[$im_num]['filename'] != "" )
+// {
+// $im_new[$im_new_num]['filename'] = $im_cur[$im_num]['filename'];
+// $im_new[$im_new_num]['descr'] = $GLOBALS[$field[0].'_DESCR'][$im_num];
+// $im_new[$im_new_num]['align'] = $GLOBALS[$field[0].'_ALIGN'][$im_num];
+// $im_new[$im_new_num]['size'] = $GLOBALS[$field[0].'_SIZE'][$im_num];
+// $im_new_num++;
+// }
+
+
+ }
+ $values .= $comma."'".serialize( $im_new )."'";
+ }
+
+ break;
+
+ case "TRUE":
+ case "SUPPLIED":
+ default:
+ $problem .= '<FONT COLOR="red">ERROR: Invalid "Required" field name "'.$field[3].'" in function call</FONT><BR>';
+ break;
+ }
+ break;
+
+ case "file":
+
+ $out[$outcount]["value"] = "FILES Not Available for View at this time";
+ switch( $field[3] )
+ {
+ case "SUPPLIED":
+ $problem .= '<FONT COLOR="red">ERROR: "SUPPLIED" not permitted as option for file input</FONT><BR>';
+ break;
+
+ case "TRUE":
+ if( $GLOBALS[$field[4]."_name"] == "" )
+ $not_supplied .= $field_title_only.": Not Supplied<BR>";
+ // no break; here - falls through to FALSE
+
+ case "FALSE":
+ if( $GLOBALS[$field[4]."_name"] != "" )
+ {
+ if( isset( $f[1] ) && $f[1] != "" && !eregi( ".".$f[1]."$",$GLOBALS[$field[4]."_name"]) )
+ $not_supplied .= $field_title_only.': "'.$GLOBALS[$field[4]."_name"].'" is not correct file type. Must be: '.$f[1]."<BR>";
+ else
+ $values .= $comma."'". file_upload( $GLOBALS[$field[4]], $GLOBALS[$field[4]."_name"], SI_BASE_FILE_PATH )."'";
+ }
+ else
+ $values .= $comma."''";
+ break;
+
+ default:
+ $problem .= '<FONT COLOR="red">ERROR: Invalid "Required" field name "'.$field[3].'" in function call</FONT><BR>';
+ break;
+ }
+ break;
+
+ case "checkbox":
+ if( $GLOBALS[$field[4]] == "on" )
+ {
+ $out[$outcount]["value"] = "Yes";
+ $values .= $comma."'t'";
+ }
+ else
+ {
+ $out[$outcount]["value"] = "No";
+ $values .= $comma."'f'";
+ }
+ break;
+
+ case "bitmap":
+ $out[$outcount]["value"] = "Bitmaps not available for view at this time";
+ $b = 0; // Start with clear bitmap
+ for( $i=0 ; $i<SI_INT_SIZE ; $i++ ) // Bitmaps are based on the size of an integer
+ {
+ if( isset($GLOBALS[$field[4]][$i]) && $GLOBALS[$field[4]][$i] == "on" ) // If checked
+ $b = $b + pow(2,$i); // Set bit
+ }
+
+ $values .= $comma.$b;
+ break;
+
+ default:
+ $ret .= '<FONT COLOR="red">UNKNOWN FIELD TYPE: '.$field[1].' for '.$field[0].'</FONT><BR>';
+ break;
+
+ } // switch( field )
+
+ $comma = ", "; // All subsequent names/values must have a preceeding comma
+
+ $outcount++;
+ } // foreach( field )
+
+ // Replace parameters in Title
+
+ for( $i=0 ; $i<$outcount ; $i++ )
+ {
+ $a_title = ereg_replace( "\\{".$i."\\}", $out[$i]["value"], $a_title );
+ $a_title = ereg_replace( "\\{encode:".$i."\\}", urlencode($out[$i]["value"]), $a_title );
+ }
+
+ $a_title = ereg_replace( "\\{link_params\\}", $link_params, $a_title );
+ $a_title = ereg_replace( "\\{form_params\\}", $form_params, $a_title );
+
+ // Add QuickTip if provided
+
+ if( trim($quick_tip) != '' )
+ $a_title = quick_tip( $a_title, $quick_tip );
+
+ $oid = 0; // Assume we don't get anything
+
+ $ok_to_save = true;
+
+ if( !empty($not_supplied) )
+ {
+ $results .= '
+ <H2>Required fields not supplied</H2><P>
+ <FONT COLOR="red">'.$not_supplied.'</FONT><P>
+ Use "BACK" button on browser, add missing data and resubmit.<P>
+ ';
+ $ok_to_save = false;
+ }
+
+ if( !empty($problem) )
+ {
+ $results .= $problem.'<P>
+ Use "BACK" button on browser, correct problem field, and resubmit.<P>
+ ';
+ $ok_to_save = false;
+ }
+
+ if( $ok_to_save )
+ {
+ $results = ' <P><H2>New data saved.</H2><P>';
+ $qs = "INSERT INTO $table ($names) VALUES ($values);";
+ if( SI_DEBUG >= 1 ) $ret .= "<PRE>admin_add_new_record()[".__LINE__."]: Query String = $qs</PRE><BR>";
+ $oid = db_auto_exec( $qs, $conn_str, FALSE );
+ }
+
+ // Display top of page
+
+ $ret .= '<CENTER>
+ '.$a_title.'
+ ';
+
+ if( empty($view) ) // If there's no spec in $view
+ $ret .= $results;
+ else
+ {
+ for( $i=0 ; $i<$outcount ; $i++ )
+ {
+ $view = ereg_replace( "\\{".$i."\\}", $out[$i]["value"], $view );
+ $view = ereg_replace( "\\{encode:".$i."\\}", urlencode($out[$i]["value"]), $view );
+ }
+ $view = ereg_replace( "\\{results\\}", $results, $view );
+ $view = ereg_replace( "\\{link_params\\}", $link_params, $view );
+ $view = ereg_replace( "\\{form_params\\}", $form_params, $view );
+ $ret .= $view;
+ }
+
+ $ret .= '
+ </CENTER>
+ ';
+
+ if( $oid != 0 )
+ {
+ $d = db_auto_get_row( "SELECT id FROM $table WHERE oid = $oid;", 0, $conn_str );
+ $id = $d['id'];
+ }
+
+ return( array( 'text' => $ret, 'status' => $oid, 'id' => $id ) );
+}
+
+function admin_add_new_record( $table, $conn_str, $fields, $url, $action, $params, $a_title, $view = "", $quick_tip = "" )
+{
+ $r = admin_add_new_record_r( $table, $conn_str, $fields, $url, $action, $params, $a_title, $view, $quick_tip );
+ echo $r['text'];
+ return( $r['status'] );
+}
+
+
+
+
+ // Edit a record
+
+function admin_edit_record_r( $table, $conn_str, $id, $fields, $url, $action,
+ $params, $a_title, $view = "", $options = "", $quick_tip = "" )
+{
+
+ $ret = '';
+
+ $form_name = "admin_new_form";
+ $richtext_used = FALSE;
+
+ // Check for any options
+
+ $borders = strstr( $options, "borders" ) == FALSE ? 0 : 1;
+
+ // Check for additional parameters that are passed
+
+ if( !empty($params) )
+ {
+ $param = explode_trim( "|", $params ); // Separate parameters
+ $link_params = $form_params = "";
+ foreach( $param as $p )
+ {
+ $x = explode_trim( ".", $p ); // Separate Names from Values
+ $link_params .= "&".$x[0]."=".urlencode($x[1]);
+ $form_params .= '<INPUT TYPE="hidden" NAME="'.$x[0].'" VALUE="'.$x[1].'">';
+ }
+ }
+
+
+ // Get the data
+
+ $query_string = "SELECT * FROM ".$table." WHERE id = ".$id.";";
+ if( SI_DEBUG >= 1 ) $ret .= "<PRE>admin_edit_record()[".__LINE__."]: Query String = $query_string</PRE><BR>";
+ $data = db_auto_get_row( $query_string, 0, $conn_str, $fail_mode );
+
+ if( $data )
+ {
+
+ // Break out configuration data
+
+ $field_table = explode_trim( "|", $fields );
+
+ // Don't be surprised if last field is blank
+
+ if( trim($field_table[count($field_table)-1]) == "" )
+ array_pop( $field_table );
+
+ foreach( $field_table as $key => $r )
+ $field_table[$key] = explode_trim( ",", $r );
+
+ // For each field in the result
+
+ $outcount = 0;
+ foreach( $field_table as $field )
+ {
+
+ // Display title fields
+ $out[$outcount]["hidden"] = FALSE;
+
+ // Check for pop-up-tips
+
+ $n = explode_trim( '~', $field[2] );
+
+ $field_name_color = 'black';
+
+ switch( $field[3] )
+ {
+ case "TRUE":
+ case "UNIQUE":
+ $field_name_color = 'red';
+ case "FALSE":
+ case "DISPLAY":
+ case "UNIQUE_NOT_REQ":
+
+ // setup tip display - requires show_QuickTip() and hide_QuickTip() functions from java_functions.js
+
+ if( count($n) > 1 )
+ $out[$outcount]["name"] = quick_tip( '<font color="'.$field_name_color.'">'.$n[0].'</font>', $n[1] );
+ else
+ $out[$outcount]["name"] = '<FONT COLOR="'.$field_name_color.'">'.$field[2].'</FONT>';
+
+ break;
+ case "SUPPLIED":
+ $out[$outcount]["name"] = '<INPUT TYPE="hidden" NAME="'.$field[0].'" VALUE="'.$field[4].'">';
+ break;
+ case "HIDDEN":
+ $out[$outcount]["name"] = '';
+ $out[$outcount]["hidden"] = TRUE;
+ break;
+ default:
+ $out[$outcount]["name"] = '<FONT COLOR="red">Invalid {required} field specification</FONT>';
+ break;
+ }
+
+ // Display input fields
+ $f = explode_trim( ".", $field[1] );
+ switch( $f[0] )
+ {
+ case "password":
+ case "money":
+ case "int":
+ case "text":
+ case "inet":
+ case "url":
+ case "order":
+ case "float":
+ case "fixed":
+ $prefix = "";
+ $s = $f[1];
+ $v = $data[$field[0]];
+ $prefix = "";
+
+ if( $f[0] == "money" ) // If it's money, default to 0.00
+ {
+ $v = sprintf( "%01.2f", $data[$field[0]] );
+ $prefix = "$";
+ }
+
+ if( $f[0] == "fixed" ) // If it's fixed, set precision
+ {
+ $v = sprintf( "%01.".$f[1]."f", $data[$field[0]] );
+ $s = $f[1] + 4;
+ }
+
+ switch( $field[3] )
+ {
+ case "TRUE":
+ case "FALSE":
+ case "UNIQUE":
+ case "UNIQUE_NOT_REQ":
+ if( $f[0] == "password" )
+ {
+ $out[$outcount]["value"] = $prefix.'<INPUT TYPE="password" NAME="'.$field[0].'" SIZE="'.$s.'" VALUE="'.htmlentities($v).'">';
+ $out[$outcount]["value"] .= '  enter again <INPUT TYPE="password" NAME="'.$field[0].'_verify" SIZE="'.$s.'" VALUE="'.htmlentities($v).'">';
+ }
+ else
+ $out[$outcount]["value"] = $prefix.'<INPUT TYPE="text" NAME="'.$field[0].'" SIZE="'.$s.'" VALUE="'.htmlentities($v).'">';
+ break;
+
+ case "HIDDEN":
+ case "DISPLAY":
+ $out[$outcount]["value"] = $prefix.$v;
+ break;
+
+ case "SUPPLIED":
+ $out[$outcount]["value"] = "";
+ break;
+
+ default:
+ $out[$outcount]["value"] = '<FONT COLOR="red">Invalid {required} field specification</FONT>';
+ break;
+
+ }
+ break;
+
+ case "lat":
+ $fw = 2;
+ if( $f[1] > 0 )
+ $fw = $f[1];
+
+ switch( $field[3] ) // {required} setting
+ {
+ case "TRUE":
+ case "UNIQUE":
+ case "UNIQUE_NOT_REQ":
+ case "FALSE":
+ case "DISPLAY":
+ $ns = 'N';
+ if( $data[$field[0]] < 0 )
+ {
+ $ns = 'S';
+ $data[$field[0]] = -1 * $data[$field[0]];
+ }
+ $dv = (int) $data[$field[0]];
+ $mv = ( $data[$field[0]] - $dv ) * 60;
+ if( $field[3] != "DISPLAY" )
+ $out[$outcount]["value"] = '<SELECT NAME="'.$field[0].'_NS"><OPTION VALUE="N" '.($ns=='N'?'SELECTED':'').'>North<OPTION VALUE="S" '.($ns=='S'?'SELECTED':'').'>South</SELECT>
+ <INPUT TYPE="text" NAME="'.$field[0].'_DEG" VALUE="'.$dv.'" SIZE="4" MAXLENGTH="2" ALIGN="right">°
+ <INPUT TYPE="text" NAME="'.$field[0].'_MIN" VALUE="'.sprintf( "%01.".$fw."f", $mv ).'" SIZE="'.(3+$fw).'" ALIGN="right">\'';
+ else
+ $out[$outcount]["value"] = '<INPUT TYPE="hidden" NAME="'.$field[0].'" VALUE="'.$data[$field[0]].'">'
+ .sprintf( "<NOBR>%s %d° %01.".$fw."f'</NOBR>", $ns, $dv, $mv );
+ break;
+
+ case "HIDDEN":
+ $out[$outcount]["value"] = '<INPUT TYPE="hidden" NAME="'.$field[0].'" VALUE="'.$data[$field[0]].'">';
+ break;
+
+ case "SUPPLIED":
+ default:
+ $out[$outcount]["value"] = '<FONT COLOR="red">Invalid {required} field specification</FONT>';
+ break;
+ }
+ break;
+
+ case "lon":
+ $fw = 2;
+ if( $f[1] > 0 )
+ $fw = $f[1];
+
+ switch( $field[3] ) // {required} setting
+ {
+ case "TRUE":
+ case "UNIQUE":
+ case "UNIQUE_NOT_REQ":
+ case "FALSE":
+ case "DISPLAY":
+ $ns = 'E';
+ if( $data[$field[0]] < 0 )
+ {
+ $ns = 'W';
+ $data[$field[0]] = -1 * $data[$field[0]];
+ }
+ $dv = (int) $data[$field[0]];
+ $mv = ( $data[$field[0]] - $dv ) * 60;
+ if( $field[3] != "DISPLAY" )
+ $out[$outcount]["value"] = '<SELECT NAME="'.$field[0].'_NS"><OPTION VALUE="W" '.($ns=='W'?'SELECTED':'').'>West<OPTION VALUE="E" '.($ns=='E'?'SELECTED':'').'>East</SELECT>
+ <INPUT TYPE="text" NAME="'.$field[0].'_DEG" VALUE="'.$dv.'" SIZE="4" MAXLENGTH="3" ALIGN="right">°
+ <INPUT TYPE="text" NAME="'.$field[0].'_MIN" VALUE="'.sprintf( "%01.".$fw."f", $mv ).'" SIZE="'.(3+$fw).'" ALIGN="right">\'';
+ else
+ $out[$outcount]["value"] = '<INPUT TYPE="hidden" NAME="'.$field[0].'" VALUE="'.$data[$field[0]].'">'
+ .sprintf( "<NOBR>%s %d° %01.".$fw."f'</NOBR>", $ns, $dv, $mv );
+ break;
+
+ case "HIDDEN":
+ $out[$outcount]["value"] = '<INPUT TYPE="hidden" NAME="'.$field[0].'" VALUE="'.$data[$field[0]].'">';
+ break;
+
+ case "SUPPLIED":
+ default:
+ $out[$outcount]["value"] = '<FONT COLOR="red">Invalid {required} field specification</FONT>';
+ break;
+ }
+ break;
+
+ case "date":
+
+ $date_f = !empty( $f[1] ) ? time()-$f[1]*86400 : time() ; // Set datestamp of first day to allow
+ $date_t = !empty( $f[2] ) ? time()+$f[2]*86400 : time() ; // Set datestamp of last day to allow
+
+ switch( $field[3] )
+ {
+ case "TRUE":
+ case "FALSE":
+ $out[$outcount]["value"] = calendar_date_select( $data[$field[0]], strtotime($data[$field[0]]), $date_f, $date_t, $form_name, $field[0], $f[3], $f[4] );
+ break;
+
+ case "HIDDEN":
+ case "DISPLAY":
+ $out[$outcount]["value"] = $data[$field[0]];
+ break;
+
+ case "SUPPLIED":
+ $out[$outcount]["value"] = "";
+ break;
+
+ default:
+ $out[$outcount]["value"] = '<FONT COLOR="red">Invalid {required} field specification</FONT>';
+ break;
+ }
+ break;
+
+ case "richtext":
+ switch( $field[3] )
+ {
+ case "TRUE":
+ case "FALSE":
+ if( SI_RICHTEXT_TYPE_ENABLED )
+ {
+ if( !$richtext_used )
+ {
+ include_once( SI_BASE_PATH.'/glm_apps/HTMLArea/glm_functions_support.inc' );
+ $richtext_used = TRUE;
+ }
+ $ew = ( trim($f[1]) != "" ? $f[1] : SI_DEFAULT_RICHTEXT_WIDTH );
+ $eh = ( trim($f[2]) != "" ? $f[2] : SI_DEFAULT_RICHTEXT_HEIGHT );
+ htmlarea_add_field( $field[0], $ew, $eh );
+ $out[$outcount]["value"] = '<TABLE BORDER="1" WIDTH="'.$ew.'"><TR><TD><TEXTAREA ID="'.$field[0].'" NAME="'.$field[0].'" COLS="60" ROWS="5">'.rawurldecode( $data[$field[0]] ).'</TEXTAREA></TD></TR></TABLE>';
+ }
+ else
+ $out[$outcount]["value"] = '<TEXTAREA ID="'.$field[0].'" NAME="'.$field[0].'" COLS="60" ROWS="5">'.rawurldecode( $data[$field[0]] ).'</TEXTAREA>';
+ break;
+
+ case "HIDDEN":
+ case "DISPLAY":
+ $out[$outcount]["value"] = $data[$field[0]];
+ break;
+
+ case "SUPPLIED":
+ $out[$outcount]["value"] = "";
+ break;
+
+ default:
+ $out[$outcount]["value"] = '<FONT COLOR="red">Invalid {required} field specification</FONT>';
+ break;
+ }
+ break;
+
+ case "textbox":
+ switch( $field[3] )
+ {
+ case "TRUE":
+ case "FALSE":
+ if( isset($f[1]) )
+ {
+ $cols = $f[1];
+ $rows = $f[2];
+ }
+ else
+ {
+ $cols = SI_DEFAULT_TEXTBOX_COLS;
+ $rows = SI_DEFAULT_TEXTBOX_ROWS;
+ }
+ $out[$outcount]["value"] = '<TEXTAREA NAME="'.$field[0].'" COLS="'.$cols.'" ROWS="'.$rows.'">'.$data[$field[0]].'</TEXTAREA>';
+ break;
+
+ case "HIDDEN":
+ case "DISPLAY":
+ $out[$outcount]["value"] = rawurldecode( $data[$field[0]] );
+ break;
+
+ case "SUPPLIED":
+ $out[$outcount]["value"] = "";
+ break;
+
+ default:
+ $out[$outcount]["value"] = '<FONT COLOR="red">Invalid {required} field specification</FONT>';
+ break;
+ }
+ break;
+
+ case "multifield": // NOT TESTED multitext.numb_fields.new_line_string
+
+ // THIS FIELD TYPE REQUIRES java_functions.js
+
+ switch( $field[3] )
+ {
+ case "TRUE":
+ case "FALSE":
+ $out[$outcount]["value"] = '<input type="hidden" name="'.$field[0].'_text" id="'.$field[0].'_text" value="'.$f[2].'">
+ <span id="'.$field[0].'_fields">';
+
+ // If there's data, then build existing input lines with data
+ if( ( $x = trim($data[$field[0]]) ) != '' )
+ {
+ $field_data = unserialize( $data[$field[0]] );
+
+ if( $field_data != false && is_array( $field_data ) )
+ {
+ // For each line of inputs
+ for( $i=1 ; $i<=count($field_data) ; $i++ )
+ {
+ $f_line = str_replace( '{line_numb}', $i, $f[2] ); // Set line number in output text
+ // For each input field on the line
+ for( $j=1 ; $j<=$f[1] ; $j++ )
+ $f_line = str_replace( '{field_'.($j).'}', '<input type="text" name="'.$field[0].'_'.$i.'_'.$j.'" id="'.$field[0].'_'.$i.'_'.$j.'" value="'.$field_data[$i-1][$j-1].'" onChange="multi_fields(\''.$field[0].'\',this,'.$f[1].');">', $f_line );
+
+ $out[$outcount]["value"] .= $f_line."\n";
+ }
+ }
+
+ }
+ else
+ $i = 1; // If no data blank line is #1
+
+ // Build 1 spare input line
+ $f_line = str_replace( '{line_numb}', $i, $f[2] ); // Set line number in output text
+ for( $j=1 ; $j<=$f[1] ; $j++ )
+ $f_line = str_replace( '{field_'.$j.'}', '<input type="text" name="'.$field[0].'_'.$i.'_'.$j.'" id="'.$field[0].'_'.$i.'_'.$j.'" value="" onChange="multi_fields(\''.$field[0].'\',this,'.$f[1].');">', $f_line );
+ $out[$outcount]["value"] .= $f_line."\n</span>";
+
+ break;
+
+ case "HIDDEN":
+ case "DISLPLAY":
+ case "SUPPLIED":
+ default:
+ $out[$outcount]["value"] = '<FONT COLOR="red">Invalid {required} field specification</FONT>';
+ break;
+
+ }
+ break;
+
+ case "image":
+ switch( $field[3] )
+ {
+ case "TRUE":
+ case "FALSE":
+ $out[$outcount]["value"] = '<TABLE BORDER="1">';
+
+ if( $data[$field[0]] != "" ) // If an image already exists
+ {
+ $out[$outcount]["value"] .= ' <TR>
+ <TD VALIGN="middle"><IMG SRC="'.SI_IMG_THUMB_URL."/".$data[$field[0]].'"></TD>
+ <TD VALIGN="middle">';
+
+ if( $field[3] == "TRUE" ) // If this field is required
+ $out[$outcount]["value"] .= 'This image may be replaced using the input field below.';
+ else
+ $out[$outcount]["value"] .= '<INPUT TYPE="checkbox" NAME="'.$field[0].'_DELETE"> Delete this image';
+
+ $out[$outcount]["value"] .= ' </TD></TR>';
+ }
+
+ $out[$outcount]["value"] .= ' <TR>
+ <TD COLSPAN="2" VALIGN="middle"><INPUT TYPE="file" NAME="'.$field[0].'"></TD>
+ </TR>
+ </TABLE>';
+ break;
+
+ case "HIDDEN":
+ case "DISLPLAY":
+ $out[$outcount]["value"] = '<IMG SRC="'.SI_IMG_THUMB_URL."/".$data[$field[0]].'">';
+ break;
+
+ case "SUPPLIED":
+ $out[$outcount]["value"] = "";
+ break;
+
+ default:
+ $out[$outcount]["value"] = '<FONT COLOR="red">Invalid {required} field specification</FONT>';
+ break;
+
+ }
+ break;
+
+ case "multitext": // NOT TESTED multitext.{size}.{spares}
+
+ switch( $field[3] )
+ {
+ case "TRUE":
+ case "FALSE":
+ $out[$outcount]["value"] = '';
+ $txt_num = 0;
+
+ if( ( $x = trim($data[$field[0]]) ) != '' )
+ {
+ $txt_data = unserialize( $data[$field[0]] );
+
+ // Do existing images
+
+ foreach( $txt_data as $txt )
+ {
+ $out[$outcount]["value"] .= '#'.($txt_num+1).' <INPUT TYPE="text" NAME="'.$field[0].'_DESCR['.$im_num.']" SIZE="'.$f[1].'" VALUE="'.$txt_data[$txt_num].'"><BR>';
+ $im_num++;
+ }
+ }
+
+ if( empty($f[1]) )
+ $spare = 2;
+ else
+ $spare = $f[2];
+ for( $i=0 ; $i<$spare ; $i++ )
+ {
+ $out[$outcount]["value"] .= '#'.($txt_num+1).' <INPUT TYPE="text" NAME="'.$field[0].'_DESCR['.$im_num.']" SIZE="'.$f[1].'" VALUE="'.$txt_data[$txt_num].'"><BR>';
+ $im_num++;
+ }
+ break;
+
+ case "HIDDEN":
+ case "DISLPLAY":
+ case "SUPPLIED":
+ default:
+ $out[$outcount]["value"] = '<FONT COLOR="red">Invalid {required} field specification</FONT>';
+ break;
+
+ }
+ break;
+
+ case "images":
+
+ switch( $field[3] )
+ {
+ case "TRUE":
+ case "FALSE":
+ $out[$outcount]["value"] = '';
+ $im_num = 0;
+
+ if( ( $x = trim($data[$field[0]]) ) != '' )
+ {
+ $im_data = unserialize( $data[$field[0]] );
+ $im_des = strstr( $f[2], 'descr' );
+ $im_align = strstr( $f[2], 'align' );
+ $im_size = strstr( $f[2], 'size' );
+ if( !empty( $f[3] ) )
+ $im_des_s = $f[3];
+ else
+ $im_des_s = 40;
+ if( !empty( $f[4] ) )
+ $im_des_t = $f[4];
+ else
+ $im_des_t = "Text";
+
+ // Do existing images
+
+ foreach( $im_data as $im )
+ {
+ $out[$outcount]["value"] .= '
+ Image #'.($im_num+1).'<BR>
+ <TABLE BORDER="1">
+ <TR>
+ <TD VALIGN="middle"><IMG SRC="'.SI_IMG_THUMB_URL."/".$im_data[$im_num]['filename'].'"></TD>
+ <TD VALIGN="middle">
+ This image may be replaced using the input field below.<BR>
+ Or you may <INPUT TYPE="checkbox" NAME="'.$field[0].'_DELETE['.$im_num.']"> Delete this image.
+ <P>
+ '.( $im_align ? '
+ Align image
+ <SELECT NAME="'.$field[0].'_ALIGN['.$im_num.']">
+ <OPTION VALUE="Left"'.($im_data[$im_num]['align']=="Left"?" SELECTED":"").'>Left
+ <OPTION VALUE="Right"'.($im_data[$im_num]['align']=="Right"?" SELECTED":"").'>Right
+ <OPTION VALUE="Top"'.($im_data[$im_num]['align']=="Top"?" SELECTED":"").'>Top
+ <OPTION VALUE="Middle"'.($im_data[$im_num]['align']=="Middle"?" SELECTED":"").'>Middle
+ <OPTION VALUE="Bottom"'.($im_data[$im_num]['align']=="Bottom"?" SELECTED":"").'>Bottom
+ </SELECT>
+ ' : '<INPUT TYPE="hidden" NAME="align" VALUE="">' ).'
+ '.( $im_size ? '
+ Size
+ <SELECT NAME="'.$field[0].'_SIZE['.$im_num.']">
+ <OPTION VALUE="Original"'.($im_data[$im_num]['size']=="Original"?" SELECTED":"").'>Original
+ <OPTION VALUE="Resized"'.($im_data[$im_num]['size']=="Resized"?" SELECTED":"").'>Resized (width='.SI_RESIZED_SIZE.')
+ <OPTION VALUE="Midsized"'.($im_data[$im_num]['size']=="Midsized"?" SELECTED":"").'>Midsized (width='.SI_MIDSIZED_SIZE.')
+ <OPTION VALUE="Thumb"'.($im_data[$im_num]['size']=="Thumb"?" SELECTED":"").'>Thumb (width='.SI_THUMB_SIZE.')
+ </SELECT>
+ ' : '<INPUT TYPE="hidden" NAME="size" VALUE="">' ).'
+ </TD>
+ </TR>
+ <TR>
+ <TD COLSPAN="2" VALIGN="middle">Select Image <INPUT TYPE="file" NAME="'.$field[0].'['.$im_num.']"></TD>
+ </TR>
+ '.( $im_des ? '<TR><TD COLSPAN="2">'.$im_des_t.' <INPUT TYPE="text" NAME="'.$field[0].'_DESCR['.$im_num.']" SIZE="'.$im_des_s.'" VALUE="'.$im_data[$im_num]['descr'].'"></TD>' : '' ).'
+ </TABLE>
+ <BR>';
+ $im_num++;
+ }
+ }
+
+ if( empty($f[1]) )
+ $spare = 2;
+ else
+ $spare = $f[1];
+ for( $i=0 ; $i<$spare ; $i++ )
+ {
+ $out[$outcount]["value"] .= '
+ Image #'.($im_num+1).'<BR>
+ <TABLE BORDER="1">
+ <TR>
+ <TD COLSPAN="2" VALIGN="middle"><INPUT TYPE="file" NAME="'.$field[0].'['.$im_num.']">
+ '.( $im_align ? '
+ Align image <SELECT NAME="'.$field[0].'_ALIGN['.$im_num.']">
+ <OPTION VALUE="Left"'.($im_data[$im_num]['align']=="Left"?" SELECTED":"").'>Left
+ <OPTION VALUE="Right"'.($im_data[$im_num]['align']=="Right"?" SELECTED":"").'>Right
+ <OPTION VALUE="Top"'.($im_data[$im_num]['align']=="Top"?" SELECTED":"").'>Top
+ <OPTION VALUE="Middle"'.($im_data[$im_num]['align']=="Middle"?" SELECTED":"").'>Middle
+ <OPTION VALUE="Bottom"'.($im_data[$im_num]['align']=="Bottom"?" SELECTED":"").'>Bottom
+ </SELECT>
+ ' : '<INPUT TYPE="hidden" NAME="align" VALUE="">' ).'
+ '.( $im_align ? '
+ Size
+ <SELECT NAME="'.$field[0].'_SIZE['.$im_num.']">
+ <OPTION VALUE="Original"'.($im_data[$im_num]['size']=="Original"?" SELECTED":"").'>Original
+ <OPTION VALUE="Resized"'.($im_data[$im_num]['size']=="Resized"?" SELECTED":"").'>Resized (width='.SI_RESIZED_SIZE.')
+ <OPTION VALUE="Midsized"'.($im_data[$im_num]['size']=="Midsized"?" SELECTED":"").'>Midsized (width='.SI_MIDSIZED_SIZE.')
+ <OPTION VALUE="Thumb"'.($im_data[$im_num]['size']=="Thumb"?" SELECTED":"").'>Thumb (width='.SI_THUMB_SIZE.')
+ </SELECT>
+ ' : '<INPUT TYPE="hidden" NAME="size" VALUE="">' ).'
+ </TD>
+ </TR>
+ '.( $im_des ? '<TR><TD COLSPAN="2">'.$im_des_t.' <INPUT TYPE="text" NAME="'.$field[0].'_DESCR['.$im_num.']" SIZE="'.$im_des_s.'"></TD>' : '' ).'
+ </TABLE>
+ <BR>';
+ $im_num++;
+ }
+ break;
+
+ case "HIDDEN":
+ case "DISLPLAY":
+ case "SUPPLIED":
+ default:
+ $out[$outcount]["value"] = '<FONT COLOR="red">Invalid {required} field specification</FONT>';
+ break;
+
+ }
+ break;
+
+ case "file":
+ switch( $field[3] )
+ {
+ case "TRUE":
+ case "FALSE":
+ $out[$outcount]["value"] = '<TABLE BORDER="1">';
+
+ if( $data[$field[0]] != "" ) // If a file already exists
+ {
+ $out[$outcount]["value"] .= ' <TR>
+ <TD VALIGN="middle">
+ ';
+ if( ereg( 'secure', $f[2] ) )
+ {
+ if( !defined('SI_FILE_SECRET') || SI_FILE_SECRET == '' )
+ {
+ echo '<p><font color="red">ERROR: </font> SI_FILE_SECRET parameter required for <b>file_output_secure()</b><br>
+ SI_FILE_SECRET defined parameter not found or no contents! Please check siteinfo.inc file.<p>';
+ exit;
+ }
+ $file_md5 = md5( $data[$field[0]].SI_FILE_SECRET );
+ $out[$outcount]["value"] .= '<A HREF="'.SI_BASE_URL.'/glm_apps/file_output_secure.phtml?filename='.urlencode($data[$field[0]])
+ .'&md5='.$file_md5.'&path='.urlencode($f[1]).'">'.$data[$field[0]].'</A>';
+ }
+ else
+ $out[$outcount]["value"] .= '<A HREF="'.SI_BASE_FILE_URL.'/'.$data[$field[0]].'">'.$data[$field[0]].'</A>';
+
+ $out[$outcount]["value"] .= '</TD>
+ <TD VALIGN="middle">';
+
+ if( $field[3] == "TRUE" ) // If this field is required
+ $out[$outcount]["value"] .= 'This file may be replaced using the input field below.';
+ else
+ $out[$outcount]["value"] .= '<INPUT TYPE="checkbox" NAME="'.$field[0].'_DELETE"> Delete this file';
+
+ $out[$outcount]["value"] .= ' </TD></TR>';
+ }
+
+ $out[$outcount]["value"] .= ' <TR>
+ <TD COLSPAN="2" VALIGN="middle"><INPUT TYPE="file" NAME="'.$field[0].'"></TD>
+ </TR>
+ </TABLE>';
+ break;
+
+ case "HIDDEN":
+ case "DISLPLAY":
+ $out[$outcount]["value"] = '<A HREF="'.SI_BASE_FILE_URL.'/'.$data[$field[0]].'">'.$data[$field[0]].'</A>';
+ break;
+
+ case "SUPPLIED":
+ $out[$outcount]["value"] = "";
+ break;
+
+ default:
+ $out[$outcount]["value"] = '<FONT COLOR="red">Invalid {required} field specification</FONT>';
+ break;
+
+ }
+ break;
+
+ case "category":
+
+ // If picklist is selected - use that for selection
+
+ if( strstr($f[3],'picklist') )
+ {
+ if( ($nodes = cat_get_nodes($f[1])) )
+ {
+ $out[$outcount]["value"] .= '<SELECT NAME="'.$field[0].'"><OPTION VALUE="">';
+
+ reset($nodes);
+ while( list($key, $val) = each($nodes) )
+ {
+ $out[$outcount]["value"] .= '<OPTION VALUE="'.$val['id'].'"'.($data[$field[0]]==$val['id']?' SELECTED':'').'>';
+ if( strstr($f[3],'fullpath') )
+ $out[$outcount]["value"] .= $val['cat_fullpath'];
+ else
+ {
+ for( $i=0 ; $i<$val['cat_level'] ; $i++ )
+ $out[$outcount]["value"] .= " ";
+ $out[$outcount]["value"] .= $val['name'];
+ }
+ }
+ $out[$outcount]["value"] .= '</SELECT>';
+ }
+ else
+ $out[$outcount]["value"] .= 'No categories listed.';
+ }
+ else // Otherwise use pop-up
+ {
+
+ // Get the category name for this field is supplied
+ if( !empty($data[$field[0]]) )
+ {
+ if( ($cval = cat_get_node( $f[1], "id = ".$data[$field[0]] ) ) )
+ {
+ $cat_id = $data[$field[0]];
+ if( strstr($f[3],'fullpath') )
+ $cat_name = $cval['cat_fullpath'];
+ else
+ $cat_name = $cval['cat_name'];
+ }
+ }
+ else
+ {
+ $cat_id = 0;
+ $cat_name = " ";
+ }
+
+ $pop_width = !empty($f[4]) ? $f[4] : 200 ;
+ $pop_height = !empty($f[5]) ? $f[5] : 300 ;
+ $edit_width = !empty($f[6]) ? $f[6] : 400 ;
+ $edit_height = !empty($f[7]) ? $f[7] : 500 ;
+
+ $out[$outcount]["value"] .= "
+ <script language=\"JavaScript1.2\">
+ <!--
+ function category_select_popup_".$field[0]."( target )
+ {
+ // Pass values to the calendar
+
+ tempX = 400;
+ tempY = 300;
+
+ node_id = this.document.getElementById( target ).value;
+ var theUrl='".SI_BASE_URL."/glm_apps/category_select_popup.phtml?id=' + node_id + '&field_name=".$field[0]."&table=".$f[1]."&options=".urlencode($f[3])."&edit_width=".$edit_width."&edit_height=".$edit_height."&pop_width=".$pop_width."&pop_height=".$pop_height."&ref_id=".$id."';
+
+ tempX = tempX - 90;
+ //tempY = tempY - 170;
+
+ if (navigator.appName == 'Netscape')
+ {
+ CategoryWind = window.open( theUrl, 'Calendar','scrollbars=yes,toolbar=no,resizable=yes,width=".$pop_width.",height=".$pop_height.",screenx=' + tempX + ',screeny=' + tempY,1 );
+ }
+ else
+ {
+ CategoryWind = window.open( theUrl, 'Calendar','scrollbars=no,toolbar=no,resizable=no,width=".$pop_width.",height=".$pop_height.", top=' + tempY + ', left=' + tempX,1 );
+ }
+
+ CategoryWind.focus();
+ }
+ -->
+ </script>
+ ";
+
+ $out[$outcount]["value"] .= '<INPUT TYPE="text" NAME="'.$field[0].'_NAME" ID="'.$field[0].'_NAME" VALUE="'.$cat_name.'" READONLY="readonly" SIZE="'.$f[2].'" STYLE="background-color: #eeeeee;">
+ <INPUT TYPE="hidden" NAME="'.$field[0].'" ID="'.$field[0].'" VALUE="'.$cat_id.'">
+ <A HREF="javascript:category_select_popup_'.$field[0].'(\''.$field[0].'\')">[Change]</A>
+ ';
+ }
+
+ break;
+
+
+ case "pointer":
+
+ // If {value_field} supplied use that, otherwise use id of record as VALUE
+ $value_field = !empty($f[3]) ? $f[3] : "id" ;
+
+ // If {where} supplied use that, otherwise get all possibilities from other table
+ $w = !empty($f[4]) ? " WHERE ".$f[4] : "" ;
+
+ // If picklist options
+ $p = !empty($f[5]) ? $f[5] : "" ;
+
+ // Sort order
+
+ $s = !empty($f[6]) ? $f[6] : "id" ;
+
+ // Pointer options
+
+ $pointer_option_add_field = FALSE;
+ if( ! empty($f[7]) )
+ {
+ $option_table = explode_trim( ",", $f[7] );
+ foreach( $option_table as $option )
+ {
+ switch( $option )
+ {
+ case "add_field": // Option to display a field for entering a new target
+ $pointer_option_add_field = TRUE;
+ break;
+
+ default:
+ break;
+ }
+ }
+ }
+
+ switch( $field[3] )
+ {
+
+ case "TRUE":
+ case "FALSE":
+
+ $d = db_auto_get_data( "SELECT * FROM ".$f[1].$w." ORDER BY ".$s.";", $conn_str, FALSE, 500 );
+
+ if( is_array( $d ) )
+ {
+ unset( $da );
+ while( list($key, $val) = each($d) )
+ $da[$val[$value_field]] = $val[$f[2]];
+
+ // If there's a supplied value, use that to match for selected
+
+ if( !empty($field[4]) )
+ $z = $GLOBALS[$field[4]];
+ else
+ $z = $data[$field[0]];
+
+ $out[$outcount]["value"] = build_picklist( $field[0], $da, $data[$field[0]], "standard", $p );
+ }
+ else
+ $out[$outcount]["value"] = '(no values available)';
+
+ // Provide an additional input field to permit adding a new target value
+
+ if( $pointer_option_add_field )
+ $out[$outcount]["value"] .= '<NOBR> or add new value <INPUT TYPE="text" NAME="'.$field[0].'_add_field"></NOBR>';
+
+ break;
+
+ case "HIDDEN":
+ case "DISPLAY":
+
+ // Get specific data requested
+
+ if( !empty($data[$field[0]]) && ($d = db_auto_get_row( "SELECT * FROM ".$f[1]." WHERE id = ".$data[$field[0]]." ORDER BY ".$s.";", 0, $conn_str, $fail_mode )) )
+ $out[$outcount]["value"] = $d[$f[2]];
+
+ break;
+
+ case "SUPPLIED":
+ $out[$outcount]["value"] = "";
+ break;
+
+ default:
+ $out[$outcount]["value"] = '<FONT COLOR="red">Invalid {required} field specification</FONT>';
+ break;
+
+
+ }
+ break;
+
+ case "checkbox":
+
+ // Check for null value
+
+ if( empty($data[$field[0]]) )
+ $data[$field[0]] = "f";
+
+ switch( $field[3] ) // {required} setting
+ {
+
+ case "TRUE":
+ case "FALSE":
+ $x = $data[$field[0]] == "t" ? " CHECKED" : "";
+ $out[$outcount]["value"] = '<INPUT TYPE="checkbox" NAME="'.$field[0].'"'.$x.'>';
+ break;
+
+ case "HIDDEN":
+ case "DISPLAY":
+ $x = $data[$field[0]] == "t" ? "Yes" : "No";
+ $out[$outcount]["value"] = $x;
+ break;
+
+ case "SUPPLIED":
+ $out[$outcount]["value"] = "";
+ break;
+
+ default:
+ $out[$outcount]["value"] = '<FONT COLOR="red">Invalid {required} field specification</FONT>';
+ break;
+ }
+ break;
+
+ case "bitmap":
+ $bmap = explode_trim( "~", $f[1] );
+ $out[$outcount]["value"] = "";
+ switch( $field[3] ) // {required} setting
+ {
+ case "TRUE":
+ case "FALSE":
+ for( $i=0 ; $i<count($bmap) ; $i++ )
+ if( $bmap[$i] != '' )
+ {
+ $x = $data[$field[0]] & pow( 2, $i ) ? " CHECKED" : ""; // Check if this bit set
+ $out[$outcount]["value"] .= '<INPUT TYPE="checkbox" NAME="'.$field[0]."[$i]".'"'.$x.'>'.$bmap[$i].'<BR>';
+ }
+ break;
+
+ case "HIDDEN":
+ case "DISPLAY":
+ for( $i=0 ; $i<count($bmap) ; $i++ )
+ if( $bmap[$i] != ' ' )
+ {
+ $x = $data[$field[0]] & pow( 2, $i ) ? "Yes" : "No"; // Check if this bit set
+ $out[$outcount]["value"] .= $x.": ".$bmap[$i].'<BR>';
+ }
+ break;
+
+ case "SUPPLIED":
+ $out[$outcount]["value"] = "";
+ break;
+
+ default:
+ $out[$outcount]["value"] = '<FONT COLOR="red">Invalid {required} field specification</FONT>';
+ break;
+ }
+ if( $out[$outcount]["value"] == '' )
+ $out[$outcount]["value"] = '(no options listed)';
+ break;
+
+ case "list":
+
+ // If picklist options
+ $p = !empty($f[3]) ? $f[3] : "" ;
+
+ $option_table = "";
+ $opts = explode_trim( "~", $f[1] ); // Separate list options
+ $def_value = !empty($f[2]) ? $f[2] : "" ;
+
+ // If there's no current value, use default for current picklist option
+
+ if( trim($data[$field[0]]) == "" )
+ $current_value = $f[2];
+ else
+ $current_value = $data[$field[0]];
+
+ foreach( $opts as $opt )
+ {
+ $os = explode_trim( "^", $opt ); // Separate value from displayed text
+ $option_table[$os[0]] = $os[1];
+ }
+
+ switch( $field[3] ) // {required} setting
+ {
+ case "DISPLAY":
+ $out[$outcount]['value'] = $option_table[$data[$field[0]]];
+ break;
+ default:
+ if( strstr( 'multi', $f[3] ) )
+ $data[$field[0]] = explode( '~', $data[$field[0]] );
+ $out[$outcount]["value"] = build_picklist( $field[0], $option_table, $data[$field[0]], "standard", $p );
+ break;
+ }
+ break;
+
+ case "state":
+ switch( $field[3] ) // {required} setting
+ {
+ case "DISPLAY":
+ $out[$outcount]['value'] = $GLOBALS['si_states_array'][$data[$field[0]]];
+ break;
+ default:
+ $out[$outcount]["value"] = build_picklist( $field[0], $GLOBALS['si_states_array'], $data[$field[0]], "standard", $f[2] );
+ }
+ break;
+
+ case "country":
+ switch( $field[3] ) // {required} setting
+ {
+ case "DISPLAY":
+ $out[$outcount]['value'] = $GLOBALS['si_states_array'][$data[$field[0]]];
+ break;
+ default:
+ $out[$outcount]["value"] = build_picklist( $field[0], $GLOBALS['si_countries_array'], $data[$field[0]], "standard", $f[2] );
+ }
+ break;
+
+ case "break":
+ if( !empty($f[1]) ) // if {t1} is supplied
+ $out[$outcount]["value"] = $f[1];
+ else
+ $out[$outcount]["value"] = '<FONT COLOR="red">No {text} supplied for type "break"</FONT>';
+ break;
+
+ default:
+ $out[$outcount]["value"] = '<FONT COLOR="red">UNKNOWN FIELD TYPE: '.$f[0].' for '.$field[0].'</FONT>';
+ break;
+
+ } // switch( field )
+
+ $outcount++;
+ } // foreach( field )
+
+ }
+ else
+ {
+ $ret .= ' <CENTER>(No results found)</CENTER>
+ <P>
+ ';
+ return;
+ }
+
+ $submit = '
+ <INPUT TYPE="hidden" NAME="Action" VALUE="'.$action.'">
+ <INPUT TYPE="submit" NAME="Option" VALUE="Update">
+ ';
+
+ // Replace parameters in Title
+
+ for( $i=0 ; $i<$outcount ; $i++ )
+ {
+ $a_title = ereg_replace( "\\{".$i."\\}", $out[$i]["value"], $a_title );
+ $a_title = ereg_replace( "\\{encode:".$i."\\}", urlencode($out[$i]["value"]), $a_title );
+ }
+
+ $a_title = ereg_replace( "\\{link_params\\}", $link_params, $a_title );
+ $a_title = ereg_replace( "\\{form_params\\}", $form_params, $a_title );
+
+ // Add QuickTip if provided
+
+ if( trim($quick_tip) != '' )
+ $a_title = quick_tip( $a_title, $quick_tip );
+
+ // Output Results
+
+ // Display top of page
+
+ $ret .= '<CENTER>
+ <FORM ENCTYPE="multipart/form-data" ACTION="'.$url.'" METHOD="post" NAME="'.$form_name.'">
+ <INPUT TYPE="hidden" NAME="id" VALUE="'.$id.'">
+ ';
+
+ if( empty($view) ) // If there's no format spec in $view
+ {
+ $ret .= '<CENTER>'.$a_title.'
+ <FONT COLOR="red">(Required fields in red)</FONT><BR>
+ <TABLE BORDER="'.$borders.'"'.($borders>0?' CELLPADDING="5"':'').'>
+ ';
+
+ for( $i=0 ; $i<$outcount ; $i++ )
+ {
+ if( !$out[$i]["hidden"] )
+ $ret .= '<TR><TH ALIGN="right" VALIGN="top">'.$out[$i]["name"]
+ .' </TH><TD ALIGN="left">'.$out[$i]["value"].' </TD></TR>
+ ';
+ }
+ $ret .= ' <P>
+ </TABLE>'.$form_params.$submit; // Output the Update submit button
+
+ }
+ else // Otherwise use $view to output data
+ {
+ for( $i=0 ; $i<$outcount ; $i++ )
+ {
+ $view = ereg_replace( "\\{".$i."\\}", $out[$i]["value"], $view );
+ $view = ereg_replace( "\\{encode:".$i."\\}", urlencode($out[$i]["value"]), $view );
+ }
+ $view = ereg_replace( "\\{submit\\}", $submit, $view );
+ $view = ereg_replace( "\\{link_params\\}", $link_params, $view );
+ $view = ereg_replace( "\\{form_params\\}", $form_params, $view );
+ $ret .= '<CENTER>'.$a_title.$view;
+ }
+
+ // If HTMLArea is used, attach scripts to set that up to submit button tags
+
+ if( $richtext_used )
+ $ret .= htmlarea_setup_script();
+
+ $ret .= '
+ </FORM>
+ </CENTER>
+ ';
+
+ return( array( 'text' => $ret, 'status' => true ) );
+
+}
+
+
+function admin_edit_record( $table, $conn_str, $id, $fields, $url, $action,
+ $params, $a_title, $view = "", $options = "", $quick_tip = "" )
+{
+
+ $r = admin_edit_record_r( $table, $conn_str, $id, $fields, $url, $action,
+ $params, $a_title, $view, $options, $quick_tip );
+ echo $r['text'];
+ return( $f['status'] );
+}
+
+
+
+
+ // Update an edited record
+
+function admin_update_record_r( $table, $conn_str, $id, $fields, $url, $action, $params, $a_title, $view = "", $quick_tip = "" )
+{
+
+ $ret = '';
+
+ // Make all submitted parameters available
+
+// extract($GLOBALS[HTTP_POST_VARS]);
+// extract($GLOBALS[HTTP_GET_VARS]);
+// extract($GLOBALS[HTTP_POST_FILES]);
+
+ // Check for additional parameters that are passed
+
+ if( !empty($params) )
+ {
+ $param = explode_trim( "|", $params ); // Separate parameters
+ $link_params = $form_params = "";
+ foreach( $param as $p )
+ {
+ $x = explode_trim( ".", $p ); // Separate Names from Values
+ $link_params .= "&".$x[0]."=".urlencode($x[1]);
+ $form_params .= '<INPUT TYPE="hidden" NAME="'.$x[0].'" VALUE="'.$x[1].'">';
+ }
+ }
+
+ // Get the current data for reference and to make sure it exists
+
+ $query_string = "SELECT * FROM ".$table." WHERE id = ".$id.";";
+ if( SI_DEBUG >= 1 ) $ret .= "<PRE>admin_update_record()[".__LINE__."]: Get old record = $query_string</PRE><BR>";
+ $data = db_auto_get_row( $query_string, 0, $conn_str, $fail_mode );
+
+ $update_record = true; // Assume update is going to succeed.
+
+ if( $data )
+ {
+
+ // Break out configuration data
+
+ $field_table = explode_trim( "|", $fields );
+
+ // Don't be surprised if last field is blank
+
+ if( trim($field_table[count($field_table)-1]) == "" )
+ array_pop( $field_table );
+
+ foreach( $field_table as $key => $r )
+ $field_table[$key] = explode_trim( ",", $r );
+
+ $result = $problem = $not_supplied = "";
+ $qs = '';
+
+ // For each field in the result
+
+ $comma = ""; // first parameter doesn't need a comma in front of it
+
+ $outcount = 0;
+ foreach( $field_table as $field )
+ {
+ $f = explode_trim( ".", $field[1] );
+ $fta = explode_trim( "~", $field[2] );
+ $field_title_only = $fta[0];
+
+ if( $field[3] != 'DISPLAY' ) // Don't even try to process a DISPLAY only field. No point to it!
+ switch( $f[0] )
+ {
+
+ case "order":
+ case "int":
+ case "float":
+ case "fixed":
+ case "money":
+ case "pointer":
+ case "category":
+
+ // Handle special cases
+
+ switch( $f[0] )
+ {
+ case "money":
+ $GLOBALS[$field[4]] = ereg_replace( "[\$,]", "", $GLOBALS[$field[4]] ); // Get rid of "$" and "," from silly users
+ break;
+
+ case "pointer":
+
+ // Check for add_field values - Add new value to pointer target record
+
+ if( ($add_value = trim($GLOBALS[$field[4].'_add_field'])) != '' )
+ {
+ // If value already exists warn user.
+
+ if( db_auto_get_row( "SELECT * FROM ".$f[1]." WHERE ".$f[2]." = '".trim($GLOBALS[$field[4].'_add_field'])."';", 0, $conn_str, $fail_mode ) )
+ $not_supplied .= $field_title_only.": Value already exists in pick list, don't try to add it again.<BR>";
+ else
+ {
+ // Otherwise, add new value and use pointer to that
+
+ $add_result = db_auto_get_row( "INSERT INTO ".$f[1]." ( ".$f[2]." ) VALUES ( '".trim($GLOBALS[$field[4].'_add_field'])."' );
+ SELECT currval( '".$f[1]."_id_seq' ) AS id;", 0, $conn_str, $fail_mode );
+ $GLOBALS[$field[4]] = $add_result['id'];
+ }
+ }
+
+ break;
+ }
+
+ $qs .= $comma." ".$field[0]." = "; // Add field name to update to query string
+ $comma = ",";
+ $out[$outcount]["value"] = $GLOBALS[$field[4]];
+ switch( $field[3] )
+ {
+ case "SUPPLIED":
+ $qs .= $GLOBALS[$field[4]];
+ break;
+
+ case "TRUE":
+ if( !is_numeric($GLOBALS[$field[4]]) )
+ $not_supplied .= $field_title_only.": Not Supplied<BR>";
+ else
+ $qs .= $GLOBALS[$field[4]];
+ break;
+
+ case "FALSE":
+ if( is_numeric($GLOBALS[$field[4]]) )
+ $qs .= $GLOBALS[$field[4]];
+ else
+ $qs .= "0"; // Default to 0
+ break;
+
+ default:
+ $problem .= '<FONT COLOR="red">ERROR: Invalid "Required" field name "'.$field[3].'" in function call</FONT><BR>';
+ break;
+ }
+ break;
+
+ case "lat":
+ $qs .= $comma." ".$field[0]." = ";
+ $comma = ",";
+ // If we've been passed a decimal degree value
+ if( !empty($GLOBALS[$field[4]]) )
+ $v = $GLOBALS[$field[4]];
+ else // Otherwise compile from parts
+ {
+ if( $GLOBALS[$field[4].'_DEG'] > 90 || $GLOBALS[$field[4].'_DEG'] < 0 || $GLOBALS[$field[4].'_MIN'] >= 60 || $GLOBALS[$field[4].'_MIN'] < 0 )
+ {
+ $not_supplied .= $field_title_only.": Invalid entry. Degrees must be 0 to 90 and Minutes must be 0 to less than 60<BR>";
+ break;
+ }
+ $v = ( $GLOBALS[$field[4].'_NS'] == "N" ? 1 : -1 ) * ( $GLOBALS[$field[4].'_DEG'] + ( $GLOBALS[$field[4].'_MIN'] / 60 ) );
+ }
+ $fw = 2;
+ // Rebuild value for display
+ if( $f[1] > 0 )
+ $fw = $f[1];
+ $ns = 'N';
+ if( ($v2=$v) < 0 )
+ {
+ $ns = 'S';
+ $v2 = -1 * $v2;
+ }
+ $dv = (int) $v2;
+ $mv = ( $v2 - $dv ) * 60;
+ $out[$outcount]["value"] = sprintf( "%s %d° %01.".$fw."f'", $ns, $dv, $mv );
+ switch( $field[3] )
+ {
+ case "SUPPLIED":
+ case "FALSE":
+ $qs .= $v;
+ break;
+
+ case "TRUE":
+ if( empty($v) )
+ $not_supplied .= $field_title_only.": Not Supplied<BR>";
+ else
+ $qs .= $v;
+ break;
+
+ case "UNIQUE":
+ if( db_auto_get_row( "SELECT * FROM $table WHERE ".$field[0]." = $v;", 0, $conn_str, $fail_mode ) )
+ $not_supplied .= $field_title_only.": Already exists, must be unique<BR>";
+ $qs .= $v;
+ break;
+
+ case "UNIQUE_NOT_REQ":
+ if( !empty($v) && db_auto_get_row( "SELECT * FROM $table WHERE ".$field[0]." = $v;", 0, $conn_str, $fail_mode ) )
+ $not_supplied .= $field_title_only.": Already exists, must be unique<BR>";
+ $qs .= $v;
+ break;
+
+ default:
+ $problem .= '<FONT COLOR="red">ERROR: Invalid "Required" field name "'.$field[3].'" in function call</FONT><BR>';
+ break;
+ }
+ break;
+
+ case "lon":
+ $qs .= $comma." ".$field[0]." = ";
+ $comma = ",";
+ // If we've been passed a decimal degree value
+ if( !empty($GLOBALS[$field[4]]) )
+ $v = $GLOBALS[$field[4]];
+ else // Otherwise compile from parts
+ {
+ if( $GLOBALS[$field[4].'_DEG'] > 180 || $GLOBALS[$field[4].'_DEG'] < 0 || $GLOBALS[$field[4].'_MIN'] >= 60 || $GLOBALS[$field[4].'_MIN'] < 0 )
+ {
+ $not_supplied .= $field_title_only.": Invalid entry. Degrees must be 0 to 180 and Minutes must be 0 to less than 60<BR>";
+ break;
+ }
+ $v = ( $GLOBALS[$field[4].'_NS'] == "N" ? 1 : -1 ) * ( $GLOBALS[$field[4].'_DEG'] + ( $GLOBALS[$field[4].'_MIN'] / 60 ) );
+ }
+ $fw = 2;
+ // Rebuild value for display
+ if( $f[1] > 0 )
+ $fw = $f[1];
+ $ns = 'E';
+ if( ($v2=$v) < 0 )
+ {
+ $ns = 'W';
+ $v2 = -1 * $v2;
+ }
+ $dv = (int) $v2;
+ $mv = ( $v2 - $dv ) * 60;
+ $out[$outcount]["value"] = sprintf( "%s %d° %01.".$fw."f'", $ns, $dv, $mv );
+ switch( $field[3] )
+ {
+ case "SUPPLIED":
+ case "FALSE":
+ $qs .= $v;
+ break;
+
+ case "TRUE":
+ if( empty($v) )
+ $not_supplied .= $field_title_only.": Not Supplied<BR>";
+ else
+ $qs .= $v;
+ break;
+
+ case "UNIQUE":
+ if( db_auto_get_row( "SELECT * FROM $table WHERE ".$field[0]." = $v;", 0, $conn_str, $fail_mode ) )
+ $not_supplied .= $field_title_only.": Already exists, must be unique<BR>";
+ $qs .= $v;
+ break;
+
+ case "UNIQUE_NOT_REQ":
+ if( !empty($v) && db_auto_get_row( "SELECT * FROM $table WHERE ".$field[0]." = $v;", 0, $conn_str, $fail_mode ) )
+ $not_supplied .= $field_title_only.": Already exists, must be unique<BR>";
+ $qs .= $v;
+ break;
+
+ default:
+ $problem .= '<FONT COLOR="red">ERROR: Invalid "Required" field name "'.$field[3].'" in function call</FONT><BR>';
+ break;
+ }
+
+ break;
+
+ case "password":
+ case "text":
+ case "inet":
+ case "list":
+ case "state":
+ case "country":
+ case "url":
+ case "textbox":
+ case "richtext":
+
+ // Check for special cases
+
+ switch( $f[0] )
+ {
+
+ case "password":
+ if( $GLOBALS[$field[4]] != $GLOBALS[$field[4].'_verify'] )
+ $not_supplied .= $field_title_only.': The two copies of this password do not match. <BR>';
+ break;
+
+ case "inet":
+ if( ($r = clean_input( $field[0], 'inet' )) != '' )
+ $problem .= '<FONT COLOR="red">'.$field_title_only.': Not a valid IP address or netmask.</FONT><BR>';
+ break;
+
+ case "list":
+ // If 'multi' is selected for picklist option, then compile results from array
+ if( strstr( $f[3], 'multi' ) )
+ {
+ $m_val = $sep = '';
+
+ // Place results in '~' separated string for storage.
+
+ if( is_array($GLOBALS[$field[4]]) )
+ foreach( $GLOBALS[$field[4]] as $m )
+ {
+ $m_val .= $sep.$m;
+ $sep = '~';
+ }
+ $GLOBALS[$field[4]] = $m_val;
+ }
+
+ break;
+
+ default:
+ break;
+ }
+
+ $v = str_replace( "%27", "\'", $GLOBALS[$field[4]] );
+ if( trim(strip_tags($v)) == '' )
+ $v = '';
+ $qs .= $comma." ".$field[0]." = "; // Add field name to update to query string
+ $comma = ",";
+ $out[$outcount]["value"] = $v;
+
+ switch( $field[3] )
+ {
+ case "SUPPLIED":
+ $qs .= "'".rawurldecode( $v )."'";
+ break;
+
+ case "TRUE":
+ if( empty($v) )
+ $not_supplied .= $field_title_only.": Not Supplied<BR>";
+ else
+ $qs .= "'".rawurldecode( $v )."'";
+ break;
+
+
+ case "UNIQUE":
+ if( $f[0] != text )
+ {
+ $problem .= '<FONT COLOR="red">ERROR: UNIQUE only available for type "text"</FONT><BR>';
+ break;
+ }
+
+ if( empty($GLOBALS[$field[4]]) )
+ $not_supplied .= $field_title_only.": Not Supplied<BR>";
+ else
+ {
+ $qs .= "'".rawurldecode( $GLOBALS[$field[4]] )."'";
+
+ // Check if value is used anywhere other than current record
+
+ if( db_auto_get_row( "SELECT * FROM $table WHERE ".$field[0]." = '".rawurldecode( trim($v) )."' AND id != ".$id.";", 0, $conn_str, $fail_mode ) )
+ $not_supplied .= $field_title_only.": Already exists, must be unique<BR>";
+ }
+
+ break;
+
+ case "UNIQUE_NOT_REQ":
+ if( $f[0] != text )
+ {
+ $problem .= '<FONT COLOR="red">ERROR: UNIQUE only available for type "text"</FONT><BR>';
+ break;
+ }
+
+ if( !empty($GLOBALS[$field[4]]) )
+ {
+ $qs .= "'".rawurldecode( $GLOBALS[$field[4]] )."'";
+
+ // Check if value is used anywhere other than current record
+
+ if( db_auto_get_row( "SELECT * FROM $table WHERE ".$field[0]." = '".rawurldecode( trim($v) )."' AND id != ".$id.";", 0, $conn_str, $fail_mode ) )
+ $not_supplied .= $field_title_only.": Already exists, must be unique<BR>";
+ }
+ else
+ $qs .= "''";
+
+ break;
+
+
+ case "FALSE":
+ $qs .= "'".rawurldecode( $v )."'";
+ break;
+
+ default:
+ $problem .= '<FONT COLOR="red">ERROR: Invalid "Required" field name "'.$field[3].'" in function call</FONT><BR>';
+ break;
+ }
+
+ break;
+
+ case "date":
+ $qs .= $comma." ".$field[0]." = "; // Add field name to update to query string
+ $comma = ",";
+ $out[$outcount]["value"] = $GLOBALS[$field[4]];
+
+ if( trim($GLOBALS[$field[4]]) == "" ) // Empty dates must be "NULL"
+ $dval = "NULL";
+ else
+ $dval = "'".$GLOBALS[$field[4]]."'";
+
+ switch( $field[3] )
+ {
+ case "SUPPLIED":
+ $qs .= $dval;
+ break;
+
+ case "TRUE":
+ if( empty($GLOBALS[$field[4]]) )
+ $not_supplied .= $field_title_only.": Not Supplied<BR>";
+ else
+ $qs .= $dval;
+ break;
+
+
+ case "UNIQUE":
+ if( $field[1] != text )
+ {
+ $problem .= '<FONT COLOR="red">ERROR: UNIQUE only available for type "text"</FONT><BR>';
+ break;
+ }
+
+ if( empty($GLOBALS[$field[4]]) )
+ $not_supplied .= $field_title_only.": Not Supplied<BR>";
+ else
+ {
+ $qs .= $dval;
+
+ // Check if value is used anywhere other than current reccord
+
+ if( db_auto_get_row( "SELECT * FROM $table WHERE ".$field[0]." = '".trim($GLOBALS[$field[4]])."' AND id <> ".$id.";", 0, $conn_str, $fail_mode ) )
+ $not_supplied .= $field_title_only.": Already exists, must be unique<BR>";
+ }
+
+ break;
+
+ case "UNIQUE_NOT_REQ":
+ if( $field[1] != text )
+ {
+ $problem .= '<FONT COLOR="red">ERROR: UNIQUE only available for type "text"</FONT><BR>';
+ break;
+ }
+
+ if( !empty($GLOBALS[$field[4]]) )
+ {
+ $qs .= $dval;
+
+ // Check if value is used anywhere other than current reccord
+
+ if( db_auto_get_row( "SELECT * FROM $table WHERE ".$field[0]." = '".trim($GLOBALS[$field[4]])."' AND id <> ".$id.";", 0, $conn_str, $fail_mode ) )
+ $not_supplied .= $field_title_only.": Already exists, must be unique<BR>";
+ }
+ else
+ $qs .= $dval;
+
+ break;
+
+
+ case "FALSE":
+ $qs .= $dval;
+ break;
+
+ default:
+ $problem .= '<FONT COLOR="red">ERROR: Invalid "Required" field name "'.$field[3].'" in function call</FONT><BR>';
+ break;
+ }
+ break;
+
+ case "multifield":
+
+ $line = 0;
+ $empty = TRUE;
+ $m_data = array();
+
+ // Build array of data to store
+ while( isset( $GLOBALS[$field[4].'_'.($line+1).'_1'] ) )
+ {
+ $line++;
+ if( trim($GLOBALS[$field[4].'_'.$line.'_1']) != '' )
+ {
+ $a = array();
+ for( $i=1 ; $i<=$f[1] ; $i++ )
+ {
+ $a[$i-1] = trim( str_replace("%27", "\'", $GLOBALS[$field[4].'_'.($line).'_'.$i] ) );
+ if( $a[$i-1] != '' )
+ $empty = FALSE;
+ }
+ array_push( $m_data, $a );
+ }
+ }
+
+ if( !$empty )
+ $v = serialize( $m_data );
+ else
+ $v = '';
+
+ $qs .= $comma." ".$field[0]." = "; // Add field name to update to query string
+ $comma = ",";
+ $out[$outcount]["value"] = $v;
+
+ switch ($field[3])
+ {
+ case "TRUE" :
+ if (empty ($v))
+ $not_supplied .= $field_title_only.": Not Supplied<BR>";
+ else
+ $qs .= "'".rawurldecode($v)."'";
+ break;
+
+ case "FALSE" :
+ $qs .= "'".rawurldecode($v)."'";
+ break;
+
+ default :
+ $problem .= '<FONT COLOR="red">ERROR: Invalid "Required" field name "'.$field[3].'" in function call</FONT><BR>';
+ break;
+ }
+
+ break;
+
+ case "image":
+ // Note that the image field is only updated when required so field name is set below along with value
+ $out[$outcount]["value"] = "IMAGES Not Available for View at this time";
+ switch( $field[3] )
+ {
+ case "SUPPLIED":
+ $problem .= '<FONT COLOR="red">ERROR: "SUPPLIED" not permitted as option for image input</FONT>';
+ break;
+
+ case "TRUE":
+ // If no image is supplied and there's no image in the database
+ if( $GLOBALS[$field[4]."_name"] == "" && $data[$field[0]] == "" )
+ {
+ $not_supplied .= $field_title_only.": Not Supplied<BR>";
+ break;
+ }
+
+ // If new image is supplied, replace old one
+ if( $GLOBALS[$field[4]."_name"] != "" )
+ {
+ if( $data[$field[0]] != "" )
+ delete_image( $data[$field[0]] );
+ $qs .= $comma." ".$field[0]." = '".process_image( $GLOBALS[$field[4]], $GLOBALS[$field[4]."_name"] )."'";
+ $comma = ",";
+ }
+ break;
+
+ case "FALSE":
+ // If new image is supplied, store it
+ if( $GLOBALS[$field[4]."_name"] != "" )
+ {
+ if( $data[$field[0]] ) // If there's already an image, delete it before storing the new one
+ delete_image( $data[$field[0]] );
+ $qs .= $comma." ".$field[0]." = '".process_image( $GLOBALS[$field[4]], $GLOBALS[$field[4]."_name"] )."'";
+ $comma = ",";
+ }
+ // Else, if there's an image in the database and we're deleting
+ elseif( $data[$field[0]] != "" && isset($GLOBALS[$field[0]."_DELETE"]) )
+ {
+ delete_image( $data[$field[0]] );
+ $qs .= $comma." ".$field[0]." = ''"; // Clear image name in database
+ $comma = ",";
+ }
+
+ break;
+
+ default:
+ $problem .= '<FONT COLOR="red">ERROR: Invalid "Required" field name "'.$field[3].'" in function call</FONT><BR>';
+ break;
+ }
+ break;
+
+ case "images":
+
+ // Note that the image field is only updated when required so field name is set below along with value
+
+ $out[$outcount]["value"] = "IMAGES Not Available for View at this time";
+ switch( $field[3] )
+ {
+ case "FALSE":
+ if( is_array( ($im_data = $GLOBALS[$field[4]]) ) )
+ {
+ $im_cur = unserialize( $data[$field[0]] ); // Convert existing data to an array
+ $im_new = array();
+ $im_new_num = 0;
+ for( $im_num=0 ; $im_num<count($GLOBALS[$field[0]."_name"]) ; $im_num++ )
+ {
+ // If new image is supplied, store it
+ if( $GLOBALS[$field[0]."_name"][$im_num] != "" )
+ {
+ if( $im_cur[$im_num]['filename'] ) // If there's already an image, delete it before storing the new one
+ delete_image( $im_cur[$im_num]['filename'] );
+ $im_new[$im_new_num]['filename'] = process_image( $GLOBALS[$field[0]][$im_num], $GLOBALS[$field[0]."_name"][$im_num] );
+ $im_new[$im_new_num]['descr'] = $GLOBALS[$field[0].'_DESCR'][$im_num];
+ $im_new[$im_new_num]['align'] = $GLOBALS[$field[0].'_ALIGN'][$im_num];
+ $im_new[$im_new_num]['size'] = $GLOBALS[$field[0].'_SIZE'][$im_num];
+ $im_new_num++;
+ }
+ // Else, if there's an image in the database and we're deleting
+ elseif( $im_cur[$im_num]['filename'] != "" && isset( $GLOBALS[$field[0]."_DELETE"][$im_num] ) )
+ delete_image( $im_cur[$im_num]['filename'] );
+ elseif( $im_cur[$im_num]['filename'] != "" )
+ {
+ $im_new[$im_new_num]['filename'] = $im_cur[$im_num]['filename'];
+ $im_new[$im_new_num]['descr'] = $GLOBALS[$field[0].'_DESCR'][$im_num];
+ $im_new[$im_new_num]['align'] = $GLOBALS[$field[0].'_ALIGN'][$im_num];
+ $im_new[$im_new_num]['size'] = $GLOBALS[$field[0].'_SIZE'][$im_num];
+ $im_new_num++;
+ }
+ }
+ $qs .= $comma." ".$field[0]." = '".serialize( $im_new )."'";
+ $comma = ",";
+ }
+
+ break;
+
+ case "TRUE":
+ case "SUPPLIED":
+ default:
+ $problem .= '<FONT COLOR="red">ERROR: Invalid "Required" field name "'.$field[3].'" in function call</FONT><BR>';
+ break;
+ }
+ break;
+
+ case "file":
+
+ // Note that the file field is only updated when required so field name is set below along with value
+
+ $out[$outcount]["value"] = "FILES Not Available for View at this time";
+
+ // Check if file type is specified and if so does it match
+
+ if( isset( $f[1] ) && ($GLOBALS[$field[4]."_name"] != "") && !eregi( ".".$f[1]."$",$GLOBALS[$field[4]."_name"]) )
+ {
+ $not_supplied .= $field_title_only.': "'.$GLOBALS[$field[4]."_name"].'" is not correct file type. Must be: '.$f[1]."<BR>";
+ break;
+ }
+
+ switch( $field[3] )
+ {
+ case "SUPPLIED":
+ $problem .= '<FONT COLOR="red">ERROR: "SUPPLIED" not permitted as option for file input</FONT>';
+ break;
+
+ case "TRUE":
+
+ // If no file is supplied and there's no file in the database
+
+ if( $GLOBALS[$field[4]."_name"] == "" && $data[$field[0]] == "" )
+ {
+ $not_supplied .= $field_title_only.": Not Supplied<BR>";
+ break;
+ }
+
+ // If new file is supplied, replace old one
+ if( $GLOBALS[$field[4]."_name"] != "" )
+ {
+ if( $data[$field[0]] != "" )
+ file_delete( $data[$field[0]] );
+ $qs .= $comma." ".$field[0]." = '".file_upload( $GLOBALS[$field[4]], $GLOBALS[$field[4]."_name"] )."'";
+ $comma = ",";
+ }
+ break;
+
+ case "FALSE":
+
+ // If new file is supplied, store it
+
+ if( $GLOBALS[$field[4]."_name"] != "" )
+ {
+ if( $data[$field[0]] ) // If there's already a file, delete it before storing the new one
+ file_delete( $data[$field[0]] );
+ $qs .= $comma." ".$field[0]." = '".file_upload( $GLOBALS[$field[4]], $GLOBALS[$field[4]."_name"] )."'";
+ $comma = ",";
+ }
+ // Else, if there's a file in the database and we're deleting
+ elseif( $data[$field[0]] != "" && isset($GLOBALS[$field[0]."_DELETE"]) )
+ {
+ file_delete( $data[$field[0]] );
+ $qs .= $comma." ".$field[0]." = ''"; // Clear file name in database
+ $comma = ",";
+ }
+
+ break;
+
+ default:
+ $problem .= '<FONT COLOR="red">ERROR: Invalid "Required" field name "'.$field[3].'" in function call</FONT><BR>';
+ break;
+ }
+ break;
+
+
+ case "checkbox":
+ // Doesn't matter whether it's required or not, or whatever
+ $qs .= $comma." ".$field[0]." = "; // Add field name to update to query string
+ $comma = ",";
+ if( $GLOBALS[$field[4]] == "on" )
+ {
+ $out[$outcount]["value"] = "Yes";
+ $qs .= "TRUE";
+ }
+ else
+ {
+ $out[$outcount]["value"] = "No";
+ $qs .= "FALSE";
+ }
+ break;
+
+
+ case "bitmap":
+ $out[$outcount]["value"] = "Bitmaps not available for view at this time";
+ $qs .= $comma." ".$field[0]." = "; // Add field name to update to query string
+ $comma = ",";
+ $b = 0; // Start with clear bitmap
+ for( $i=0 ; $i<SI_INT_SIZE ; $i++ ) // Bitmaps are based on the size of an integer
+ {
+ if( isset($GLOBALS[$field[4]][$i]) && $GLOBALS[$field[4]][$i] == "on" ) // If checked
+ $b = $b + pow(2,$i); // Set bit
+ }
+
+ $qs .= $b;
+ break;
+
+ default:
+ $problem .= '<FONT COLOR="red">UNKNOWN FIELD TYPE: '.$field[1].' for '.$field[0].'</FONT><BR>';
+ break;
+
+ } // switch( field )
+
+ $outcount++;
+ } // foreach( field )
+
+ }
+ else
+ {
+ $ret .= ' <CENTER>(Record not found)</CENTER>
+ <P>
+ ';
+ return( array( 'text' => $ret, 'status' => false ) );
+ }
+
+ if( !empty($not_supplied) )
+ {
+ $result .= ' <H2>Required fields not supplied</H2><P>
+ <FONT COLOR="red">'.$not_supplied.'</FONT><P>
+ Use "BACK" button on browser, add missing data and resubmit.<P>
+ ';
+ $update_record = false;
+ }
+
+ if( !empty($problem) )
+ {
+ $result .= $problem.'<P>
+ Use "BACK" button on browser, correct problem field, and resubmit.<P>
+ ';
+ $update_record = false;
+ }
+
+ if( $update_record && $qs != '' )
+ {
+ $qs = "UPDATE $table SET $qs WHERE id = $id;";
+ if( SI_DEBUG >= 1 ) $ret .= "<PRE>admin_update_record()[".__LINE__."]: Update record = $qs</PRE><BR>";
+ db_auto_exec( $qs, $conn_str, FALSE );
+ $result .= '<P><H2>Data updated.</H2><P>';
+ }
+
+ // Replace parameters in Title
+
+ for( $i=0 ; $i<$outcount ; $i++ )
+ {
+ $a_title = ereg_replace( "\\{".$i."\\}", $out[$i]["value"], $a_title );
+ $a_title = ereg_replace( "\\{encode:".$i."\\}", urlencode($out[$i]["value"]), $a_title );
+ }
+
+ $a_title = ereg_replace( "\\{link_params\\}", $link_params, $a_title );
+ $a_title = ereg_replace( "\\{form_params\\}", $form_params, $a_title );
+ $a_title = ereg_replace( "\\{result\\}", $result, $a_title );
+
+ // Add QuickTip if provided
+
+ if( trim($quick_tip) != '' )
+ $a_title = quick_tip( $a_title, $quick_tip );
+
+ // Display top of page
+
+ $ret .= '<CENTER>
+ '.$a_title."\n";
+
+ if( empty($view) ) // If there's no spec in $view
+ $ret .= $result;
+ else
+ {
+ for( $i=0 ; $i<$outcount ; $i++ )
+ {
+ $view = ereg_replace( "\\{".$i."\\}", $out[$i]["value"], $view );
+ $view = ereg_replace( "\\{encode:".$i."\\}", urlencode($out[$i]["value"]), $view );
+ }
+ $view = ereg_replace( "\\{999\\}", $out[999]["value"], $view );
+ $view= ereg_replace( "\\{link_params\\}", $link_params, $view );
+ $view = ereg_replace( "\\{form_params\\}", $form_params, $view );
+ $view = ereg_replace( "\\{result\\}", $result, $view );
+ $ret .= $view;
+ }
+
+ $ret .= '
+ </CENTER>
+ ';
+
+ return( array( 'text' => $ret, 'status' => $update_record ) );
+
+}
+
+function admin_update_record( $table, $conn_str, $id, $fields, $url, $action, $params, $a_title, $view = "", $quick_tip = "" )
+{
+ $r = admin_update_record_r( $table, $conn_str, $id, $fields, $url, $action, $params, $a_title, $view, $quick_tip );
+ echo $r['text'];
+ return( $r['status'] );
+}
+
+
+
+
+ // Ask for the deletion of a record
+
+function admin_delete_record_r( $table, $conn_str, $id, $fields,
+ $options, $url, $action, $params, $a_title, $view="", $quick_tip="" )
+{
+
+ $ret = '';
+
+ // Break out configuration data
+
+ $field_table = explode_trim( "|", $fields );
+
+ // Don't be surprised if last field is blank
+
+ if( trim($field_table[count($field_table)-1]) == "" )
+ array_pop( $field_table );
+
+ foreach( $field_table as $key => $r )
+ $field_table[$key] = explode_trim( ",", $r );
+
+ // Check for additional parameters that are passed
+
+ if( !empty($params) )
+ {
+ $param = explode_trim( "|", $params ); // Separate parameters
+ $link_params = $form_params = "";
+ foreach( $param as $p )
+ {
+ $x = explode_trim( ".", $p ); // Separate Names from Values
+ $link_params .= "&".$x[0]."=".urlencode($x[1]);
+ $form_params .= '<INPUT TYPE="hidden" NAME="'.$x[0].'" VALUE="'.$x[1].'">';
+ }
+ }
+
+ // Scan options
+
+ $option_strong = FALSE;
+ if( !empty($options) )
+ {
+ $option_table = explode_trim( ",", $options );
+ foreach( $option_table as $option )
+ switch( $option )
+ {
+ case "strong":
+ $option_strong = TRUE;
+ break;
+
+ default:
+// $ret .= '<H2><FONT COLOR="red">ERROR: Illegal Option Specified</FONT></H2>';
+ break;
+ }
+ }
+
+
+ // Get the data
+
+ $query_string = "SELECT * FROM ".$table." WHERE id = $id;";
+ if( SI_DEBUG >= 1 ) $ret .= "<PRE>admin_delete_record()[".__LINE__."]: Record to delete = $query_string</PRE><BR>";
+ $data = db_auto_get_row( $query_string, 0, $conn_str, $fail_mode );
+ $problem = '';
+
+ if( $data )
+ {
+
+ // For each field in the result
+
+ $outcount = 0; // replaceable field data table pointer
+ foreach( $field_table as $field )
+ {
+ $f2 = explode_trim( "~", $field[2] );
+ $out[$outcount]["name"] = $f2[0];
+ $out[$outcount]["display"] = $field[3] != "HIDDEN" ? TRUE : FALSE;
+ $f = explode_trim( ".", $field[1] ); // Extract type options
+ switch( $f[0] )
+ {
+ // Check other tables for references to this record
+
+ case "check":
+ if( $f[1] == '' || $f[2] == '' )
+ {
+ $problem .= '<FONT COLOR="red">'.$field[0].': Table or Field name not supplied for reference check.</FONT><BR>';
+ break;
+ }
+ if( ($c = db_auto_get_row( "SELECT count(".$f[2].") FROM ".$f[1]." WHERE ".$f[2]." = $id;" )) && $c['count'] > 0 )
+ {
+ $problem .= '<FONT COLOR="red">This reccord is referenced '.$c['count'].' time(s) by "'.$f2[0].'". Delete References first.</FONT><BR>';
+ break;
+ }
+
+ break;
+
+ case "money":
+ $out[$outcount]["value"] = "$".sprintf( "%01.2f", $data[$field[0]] );
+ break;
+
+ case "order":
+ case "int":
+ case "float":
+ case "fixed":
+ $out[$outcount]["value"] = $data[$field[0]];
+ break;
+
+ case "checkbox":
+ $out[$outcount]["value"] = $data[$field[0]] == 't' ? 'Yes' : 'No';
+ break;
+
+ case "password":
+ $out[$outcount]["value"] = '(hidden)';
+ break;
+
+ case "text":
+ case "inet":
+ case "state":
+ case "country":
+ case "textbox":
+ case "richtext":
+ case "date":
+ $out[$outcount]["value"] = $data[$field[0]];
+ break;
+
+ case "checkbox":
+ $out[$outcount]["value"] = $data[$field[0]] == "t" ? "Yes" : "No" ;
+ break;
+ case "url":
+ $out[$outcount]["value"] = '<A HREF="'.$data[$field[0]].'">'.$data[$field[0]].'</A>';
+ break;
+
+ case "category":
+ // Get the category name for this field if supplied
+ if( !empty($data[$field[0]]) )
+ {
+ if( $cval = db_auto_get_row( "SELECT * FROM ".$f[1]." WHERE id = ".$data[$field[0]].";", 0, $conn_str, FALSE ) )
+ $out[$outcount]["value"] = $cval['name'];
+ else
+ $out[$outcount]["value"] = '<FONT COLOR="red">Unknown Category</FONT>';
+ }
+ else
+ {
+ $out[$outcount]["value"] = " ";
+ }
+ break;
+
+ case "pointer":
+ // If {value_field} supplied use that, otherwise use id of record as value to match
+ $value_field = !empty($f[3]) ? $f[3] : "id" ;
+
+ // If {where} supplied use that, otherwise get all possibilities from other table
+ $w = !empty($f[4]) ? " WHERE ".$f[4] : " WHERE ".$value_field." = ".$data[$field[0]] ;
+
+ $pval = db_auto_get_row(
+ "SELECT * FROM ".$f[1].$w.";",
+ 0, $conn_str, $fail_mode );
+ $out[$outcount]["value"] = $pval[$f[2]];
+ break;
+
+ default:
+ $out[$outcount]["value"] = '<FONT COLOR="red">UNKNOWN FIELD TYPE: '.$f[0].' for '.$field[0].'</FONT>';
+ break;
+
+ } // switch( field )
+ $outcount++;
+ } // foreach( field )
+
+ // Confirm field and Submit button go into {submit}
+
+ if( $option_strong )
+ $submit = '<BR>
+ To confirm, type "Delete" below.<BR>
+ <FORM ACTION="'.$url.'" METHOD="post">
+ <INPUT TYPE="hidden" NAME="id" VALUE="'.$id.'">
+ <INPUT TYPE="hidden" NAME="Action" VALUE="'.$action.'">
+ <INPUT TYPE="text" NAME="Confirm"><BR>
+ <INPUT TYPE="hidden" NAME="Option" VALUE="Confirm Delete">
+ <INPUT TYPE="submit" NAME="usingHiddenOption" VALUE="Confirm Delete">
+ '.$form_params.'
+ </FORM>
+ ';
+ else
+ $submit = '
+ <FORM ACTION="'.$url.'" METHOD="post">
+ <INPUT TYPE="hidden" NAME="id" VALUE="'.$id.'">
+ <INPUT TYPE="hidden" NAME="Action" VALUE="'.$action.'">
+ <INPUT TYPE="hidden" NAME="Confirm" VALUE="Delete"><BR>
+ <INPUT TYPE="hidden" NAME="Option" VALUE="Confirm Delete">
+ <INPUT TYPE="submit" NAME="usingHiddenOption" VALUE="Confirm Delete">
+ '.$form_params.'
+ </FORM>
+ ';
+
+ // Replace parameters in Title
+
+ for( $i=0 ; $i<$outcount ; $i++ )
+ {
+ $a_title = ereg_replace( "\\{".$i."\\}", $out[$i]["value"], $a_title );
+ $a_title = ereg_replace( "\\{encode:".$i."\\}", urlencode($out[$i]["value"]), $a_title );
+ }
+
+ $a_title = ereg_replace( "\\{link_params\\}", $link_params, $a_title );
+ $a_title = ereg_replace( "\\{form_params\\}", $form_params, $a_title );
+ $a_title = ereg_replace( "\\{submit\\}", $submit, $a_title );
+ $a_title = ereg_replace( "\\{result\\}", $result, $a_title );
+
+
+ // Add QuickTip if provided
+
+ if( trim($quick_tip) != '' )
+ $a_title = quick_tip( $a_title, $quick_tip );
+
+
+ // Output results
+
+ if( empty($view) ) // If there's no format spec in $view
+ {
+ $ret .= '<CENTER>'.$a_title.'
+ <P>
+ <H2>Are you sure you want to delete this information?</H2>
+ <TABLE BORDER="1">
+ ';
+ for( $i=0 ; $i<$outcount ; $i++ )
+ {
+ if( $out[$i]["display"] )
+ $ret .= '<TR><TH ALIGN="right" VALIGN="top">'.$out[$i]["name"]
+ .' </TH><TD ALIGN="left">'.$out[$i]["value"].' </TD></TR>
+ ';
+ }
+ $ret .= ' <P>
+ </TABLE>'.$submit; // Output the Confirm field and submit button
+
+ }
+ else // Otherwise use $view to output data
+ {
+ for( $i=0 ; $i<$i ; $i++ )
+ {
+ $view = ereg_replace( "\\{".$i."\\}", $out[$i]["value"], $view );
+ $view = ereg_replace( "\\{encode:".$i."\\}", urlencode($out[$i]["value"]), $view );
+ }
+ $view = ereg_replace( "\\{link_params\\}", $link_params, $view );
+ $view = ereg_replace( "\\{form_params\\}", $form_params, $view );
+ $view = ereg_replace( "\\{submit\\}", $submit, $view );
+ $view = ereg_replace( "\\{result\\}", $result, $view );
+ $ret .= '<CENTER>'.$a_title.$view;
+ }
+
+ if( $problem != '' )
+ {
+ $ret = '<CENTER>'.$a_title.$problem.'</CENTER>';
+ return( array( 'text' => $ret, 'status' => false ) );
+ }
+
+ } // if( $data )
+ else
+ $ret .= ' <CENTER>(No results found)</CENTER>
+ <P>
+ ';
+
+
+
+ $ret .= '</CENTER>
+ ';
+
+ return( array( 'text' => $ret, 'status' => true ) );
+
+}
+
+function admin_delete_record( $table, $conn_str, $id, $fields,
+ $options, $url, $action, $params, $a_title, $view="", $quick_tip="" )
+{
+ $r = admin_delete_record_r( $table, $conn_str, $id, $fields,
+ $options, $url, $action, $params, $a_title, $view, $quick_tip );
+ echo $r['text'];
+ return( $r['status'] );
+}
+
+
+ // Delete a record if confirmed
+
+function admin_confirm_delete_record_r( $table, $conn_str, $id, $fields, $url,
+ $action, $params, $a_title, $view = "", $quick_tip = "" )
+{
+
+ $ret = '';
+
+ // Make all submitted parameters available
+
+// extract($GLOBALS[HTTP_POST_VARS]);
+// extract($GLOBALS[HTTP_GET_VARS]);
+
+ // Check for additional parameters that are passed
+
+ if( !empty($params) )
+ {
+ $param = explode_trim( "|", $params ); // Separate parameters
+
+ $link_params = $form_params = "";
+ foreach( $param as $p )
+ {
+ $x = explode_trim( ".", $p ); // Separate Names from Values
+ $link_params .= "&".$x[0]."=".urlencode($x[1]);
+ $form_params .= '<INPUT TYPE="hidden" NAME="'.$x[0].'" VALUE="'.$x[1].'">';
+ }
+ }
+
+ // Check "Confirm" field for correct text
+
+ $result = "";
+ $delete_record = TRUE; // Assume that we're going to delete this record
+ if( $GLOBALS['Confirm'] == "Delete" )
+ {
+
+ // Get the current data for reference and to make sure it exists
+
+ $query_string = "SELECT * FROM $table WHERE id = $id;";
+ if( SI_DEBUG >= 1 ) $ret .= "<PRE>admin_confirm_delete_record()[".__LINE__."]: Record to delete = $query_string</PRE><BR>";
+ $data = db_auto_get_row( $query_string, 0, $conn_str, $fail_mode );
+
+ // Separate field title from QuickTip in case we need it
+ $fta = explode_trim( "~", $field[2] );
+ $field_title_only = $fta[0];
+
+
+ if( $data )
+ {
+
+ $not_delete_message = "";
+
+ if( trim($fields) != "" ) // If there's any check fields
+ {
+ // Break out configuration data
+
+ $field_table = explode_trim( "|", $fields );
+
+ // Don't be surprised if last field is blank
+
+ if( trim($field_table[count($field_table)-1]) == "" )
+ array_pop( $field_table );
+
+ foreach( $field_table as $key => $r )
+ $field_table[$key] = explode_trim( ",", $r );
+
+ // For each check field specified
+
+ foreach( $field_table as $field )
+ {
+ $f = explode_trim( ".", $field[1] );
+ switch( $f[0] )
+ {
+ case "reference": // Check to see if this record is referenced
+ if( db_auto_get_row( "SELECT id FROM ".$f[1]." WHERE ".$f[2]." = $id;", 0, $conn_str, $fail_mode ) )
+ {
+ $result .= '<FONT COLOR="red">Can\'t delete this information. You must delete '.$field[2].' first.</FONT><BR>';
+ $delete_record = FALSE;
+ }
+ break;
+
+ case "image":
+ delete_image( $data[$field[0]] );
+ break;
+
+ default:
+ $result .= '<FONT COLOR="red">UNKNOWN FIELD TYPE: '.$f[0].' for '.$field[0].'</FONT><BR>';
+ $delete_record = FALSE;
+ break;
+
+ } // switch( field )
+
+ } // foreach( field )
+ }
+ } // if data
+ else
+ {
+ $result .= '<H2><FONT COLOR="red">Record not found</FONT></H2><BR>';
+ $delete_record = FALSE;
+ }
+
+
+ } // if Confirm
+ else
+ {
+ $result .= '<H2>Delete <FONT COLOR="red">NOT</FONT> Confirmed.</H2>';
+ $delete_record = FALSE;
+ }
+
+
+ if( $delete_record )
+ {
+ $qs = "DELETE FROM ".$table." WHERE id = ".$id.";";
+ if( SI_DEBUG >= 1 ) $ret .= "<PRE>admin_confirm_delete_record()[".__LINE__."]: Delete Record = $qs</PRE><BR>";
+ db_auto_exec( $qs, $conn_str, FALSE );
+ $result .= '<P><H2>Record Deleted.</H2>';
+ }
+ else
+ $result .= '<P><H2>Not deleting this record</H2><P>
+ <FONT COLOR="red" SIZE="4">'.$not_delete_message.'</FONT><P>
+ ';
+
+ // Make replacements in $a_title
+
+ $a_title = ereg_replace( "\\{result\\}", $result, $a_title );
+ $a_title = ereg_replace( "\\{link_params\\}", $link_params, $a_title );
+ $a_title = ereg_replace( "\\{form_params\\}", $form_params, $a_title );
+
+ // Add QuickTip if provided
+
+ if( trim($quick_tip) != '' )
+ $a_title = quick_tip( $a_title, $quick_tip );
+
+ // Display top of page
+
+ $ret .= '<CENTER>
+ '.$a_title.'
+ ';
+
+ if( empty($view) )
+ $ret .= $result;
+ else
+ {
+ $view = ereg_replace( "\\{result\\}", $result, $view );
+ $view = ereg_replace( "\\{link_params\\}", $link_params, $view );
+ $view = ereg_replace( "\\{form_params\\}", $form_params, $view );
+ $ret .= $view;
+ }
+
+ $ret .= '
+ </CENTER>
+ ';
+
+
+ return( array( 'text' => $ret, 'status' => $delete_record ) );
+
+
+}
+
+function admin_confirm_delete_record( $table, $conn_str, $id, $fields, $url,
+ $action, $params, $a_title, $view = "", $quick_tip = "" )
+{
+ $r = admin_confirm_delete_record_r( $table, $conn_str, $id, $fields, $url,
+ $action, $params, $a_title, $view, $quick_tip );
+ echo $r['text'];
+ return( $r['status'] );
+}
+
+
+
+
+ // View the data in a record
+
+function admin_view_record_r( $table, $conn_str, $id, $fields,
+ $url, $action, $params, $a_title, $view="", $options = "", $quick_tip = "", $id_field = '' )
+{
+
+ $ret = '';
+
+ if( empty($id_field) )
+ $id_field = 'id';
+
+ // Check for any options
+
+ $borders = strstr( $options, "borders" ) ? 1 : 0; // Show table borders
+ $nocenter = strstr( $options, "nocenter" ) ? 1 : 0; // Don't output <center></center> tags around content
+
+ // Break out configuration data
+
+ $field_table = explode_trim( "|", $fields );
+
+ // Don't be surprised if last field is blank
+
+ if( trim($field_table[count($field_table)-1]) == "" )
+ array_pop( $field_table );
+
+ // Check for additional parameters that are passed
+
+ if( !empty($params) )
+ {
+ $param = explode_trim( "|", $params ); // Separate parameters
+ $link_params = $form_params = "";
+ foreach( $param as $p )
+ {
+ $x = explode_trim( ".", $p ); // Separate Names from Values
+ $link_params .= "&".$x[0]."=".urlencode($x[1]);
+ $form_params .= '<INPUT TYPE="hidden" NAME="'.$x[0].'" VALUE="'.$x[1].'">';
+ }
+ }
+
+ // Get the data
+
+ $qs = "SELECT * FROM $table WHERE ".$id_field." = $id;";
+ if( SI_DEBUG >= 1 ) $ret .= "<PRE>admin_view_record()[".__LINE__."]: View Record = $qs</PRE><BR>";
+ $data = db_auto_get_row( $qs, 0, $conn_str, $fail_mode );
+
+ if( $data )
+ {
+ // For each field in the result
+
+ for( $res_field=0 ; $res_field<count($field_table) ; $res_field++ )
+ {
+ $field = explode_trim( ",", $field_table[$res_field] );
+ $f = explode_trim( ".", $field[1] );
+ $out[$res_field]["hidden"] = ereg( "hidden", $field_table[$res_field] ); // Check for .hidden
+
+ // Check for pop-up-tips
+
+ $n = explode_trim( '~', $field[2] );
+ if( count($n) > 1 )
+ {
+ // setup tip display - requires show_QuickTip() and hide_QuickTip() functions from java_functions.js
+
+ $out[$res_field]["name"] = quick_tip( '<font color="'.$field_name_color.'">'.$n[0].'</font>', $n[1] );
+ }
+ else
+ $out[$res_field]["name"] = $field[2];
+
+ $out[$res_field]['field'] = $field[0];
+
+ switch( $f[0] )
+ {
+
+ case "lat":
+ $fw = 2;
+ if( $f[1] > 0 )
+ $fw = $f[1];
+ $ns = 'N';
+ if( $data[$field[0]] < 0 )
+ {
+ $ns = 'S';
+ $data[$field[0]] = -1 * $data[$field[0]];
+ }
+ $dv = (int) $data[$field[0]];
+ $mv = ( $data[$field[0]] - $dv ) * 60;
+ $out[$res_field]["value"] = sprintf( "%s %d° %01.".$fw."f'", $ns, $dv, $mv );
+ break;
+
+ case "lon":
+ $fw = 2;
+ if( $f[1] > 0 )
+ $fw = $f[1];
+ $ns = 'E';
+ if( $data[$field[0]] < 0 )
+ {
+ $ns = 'W';
+ $data[$field[0]] = -1 * $data[$field[0]];
+ }
+ $dv = (int) $data[$field[0]];
+ $mv = ( $data[$field[0]] - $dv ) * 60;
+ $out[$res_field]["value"] = sprintf( "%s %d° %01.".$fw."f'", $ns, $dv, $mv );
+ break;
+
+ case "money":
+ $out[$res_field]["value"] = "$".sprintf( "%01.2f", $data[$field[0]] );
+ break;
+
+ case "fixed":
+ $fw = 2;
+ if( $f[1] > 0 )
+ $fw = $f[1];
+ $out[$res_field]["value"] = sprintf( "%01.".$fw."f", $data[$field[0]] );
+ break;
+
+ case "password":
+ $out[$res_field]["value"] = '(hidden)';
+ break;
+
+ case "text":
+ case "inet":
+ case "textbox":
+ case "richtext":
+ $out[$res_field]["value"] = nl2br( $data[$field[0]] );
+ break;
+
+ case "rawtext":
+ $out[$res_field]["value"] = $data[$field[0]];
+ break;
+
+ case "order":
+ case "int":
+ case "date":
+ case "float":
+ $out[$res_field]["value"] = $data[$field[0]];
+ break;
+
+ case "url":
+ $out[$res_field]["value"] = '<A HREF="'.$data[$field[0]].'">'.$data[$field[0]].'</A>';
+ break;
+
+ case "category":
+ // Get the category name for this field is supplied
+ if( !empty($data[$field[0]]) )
+ {
+ if( $cval = db_auto_get_row( "SELECT * FROM ".$f[1]." WHERE id = ".$data[$field[0]].";", 0, $conn_str, FALSE ) )
+ $out[$res_field]["value"] = $cval['name'];
+ else
+ $out[$res_field]["value"] = '<FONT COLOR="red">Unknown Category</FONT>';
+ }
+ else
+ {
+ $out[$res_field]["value"] = " ";
+ }
+ break;
+
+ case "pointer":
+
+ if( !empty($data[$field[0]]) )
+ {
+ // If {where} supplied use that, otherwise match "id" field
+ $w = !empty($f[4]) ? " WHERE ".$f[4] : " WHERE id = ".$data[$field[0]] ;
+ $comma = '';
+ $ref_fields = explode_trim( "~", $f[2] ); // Separate all fields to display
+ $ref_select = $sep = '';
+ foreach( $ref_fields as $ref_field ) // Build fields spec for SELECT
+ {
+ $ref_select .= $sep.$ref_field;
+ $sep = ',';
+ }
+ $out[$res_field]["value"] = '';
+ if( ($pvals = db_auto_get_data( "SELECT $ref_select FROM ".$f[1].$w.";", $conn_str, $fail_mode )) )
+ {
+ foreach( $pvals as $pval )
+ {
+ $out[$res_field]["value"] .= $comma;
+ $ref_space = '';
+ foreach( $ref_fields as $ref_field ) // Put together all fields referenced as output
+ {
+ $out[$res_field]["value"] .= $ref_space.$pval[$ref_field];
+ $ref_space = ' ';
+ }
+ $comma = ', ';
+ }
+ }
+ else
+ $out[$res_field]["value"] = '';
+ }
+ else
+ $out[$res_field]["value"] = '';
+
+ break;
+
+ case "multifield": // NOT TESTED multitext.numb_fields.new_line_string
+
+ if( trim($f[2]) == '' )
+ {
+ $out[$res_field]["value"] = '<FONT COLOR="RED">Missing multifield line specification</FONT>';
+ break;
+ }
+
+ $v = '';
+
+
+ // If there's data, then build existing input lines with data
+ if( ( $x = trim($data[$field[0]]) ) != '' )
+ {
+ $field_data = unserialize( $data[$field[0]] );
+
+ if( $field_data != false && is_array( $field_data ) )
+ {
+
+ // For each line of inputs
+ for( $i=1 ; $i<=count($field_data) ; $i++ )
+ {
+ $f_line = str_replace( '{line_numb}', ($i), $f[2] ); // Set line number in output text
+ // For each input field on the line
+
+ for( $j=1 ; $j<=$f[1] ; $j++ )
+ $f_line = str_replace( '{field_'.($j).'}', $field_data[$i-1][$j-1], $f_line );
+
+ $v .= $f_line;
+
+ }
+ }
+ }
+
+ $out[$res_field]["value"] = $v;
+
+ break;
+
+
+ case "image":
+ if( !empty($data[$field[0]]) )
+ {
+ switch( $f[1] )
+ {
+ case "o": $img_url = SI_IMG_ORIGINAL_URL; break;
+ case "r": $img_url = SI_IMG_RESIZED_URL; break;
+ case "m": $img_url = SI_IMG_MIDSIZED_URL; break;
+ case "t": $img_url = SI_IMG_THUMB_URL; break;
+ default: $img_url = "none"; break;
+ }
+ if( $img_url != "none" )
+ $out[$res_field]["value"] = '<IMG SRC="'.$img_url."/".$data[$field[0]].'">';
+ else
+ $out[$res_field]["value"] = '<FONT COLOR="RED">Invalid Image Size</FONT>';
+ }
+ else
+ $out[$res_field]["value"] = '(no image)';
+ break;
+
+ case "images":
+ if( !empty($data[$field[0]]) )
+ {
+ if( $img_url != "none" )
+ {
+ $images = unserialize( $data[$field[0]] );
+ foreach( $images as $im )
+ {
+ switch( !empty($im['size']) ? $im['size'] : $f[1] )
+ {
+ case "o": $img_url = SI_IMG_ORIGINAL_URL; break;
+ case "r": $img_url = SI_IMG_RESIZED_URL; break;
+ case "m": $img_url = SI_IMG_MIDSIZED_URL; break;
+ case "t": $img_url = SI_IMG_THUMB_URL; break;
+ default: $img_url = "none"; break;
+ }
+ $out[$res_field]["value"] = '<IMG SRC="'.$img_url."/".$im['filename'].'"><BR>'.$im['descr'];
+ }
+ }
+ else
+ $out[$res_field]["value"] = '<FONT COLOR="RED">Invalid Image Size</FONT>';
+ }
+ else
+ $out[$res_field]["value"] = '(no image)';
+ break;
+
+ case "file":
+ if( ereg( 'secure', $f[2] ) )
+ {
+ if( !defined('SI_FILE_SECRET') || SI_FILE_SECRET == '' )
+ {
+ echo '<p><font color="red">ERROR: </font> SI_FILE_SECRET parameter required for <b>file_output_secure()</b><br>
+ SI_FILE_SECRET defined parameter not found or no contents! Please check siteinfo.inc file.<p>';
+ exit;
+ }
+ $file_md5 = md5( $data[$field[0]].SI_FILE_SECRET );
+ $out[$res_field]["value"] = '<A HREF="'.SI_BASE_URL.'/glm_apps/file_output_secure.phtml?filename='.urlencode($data[$field[0]])
+ .'&md5='.$file_md5.'&path='.urlencode($f[1]).'">'.$data[$field[0]].'</A>';
+ }
+ else
+ $out[$res_field]["value"] = '<A HREF="'.SI_BASE_FILE_URL.'/'.$data[$field[0]].'">'.$data[$field[0]].'</A>';
+ break;
+
+
+ case "checkbox":
+ $x = $data[$field[0]] == "t" ? "Yes" : "No";
+ $out[$res_field]["value"] = $x;
+ break;
+
+ case "bitmap":
+ $bmap = explode_trim( "~", $f[1] );
+ $out[$res_field]["value"] = '<TABLE BORDER="0">';
+ for( $j=0 ; $j<count($bmap) ; $j++ )
+ if( $bmap[$j] != ' ' )
+ {
+ $d = $data[$field[0]] & pow( 2, $j ) ? "Yes" : "No"; // Check if this bit set
+ $out[$res_field]["value"] .= '<TR><TD>'.$bmap[$j].'</TD><TD>'.$d.'</TD></TR>';
+ }
+ $out[$res_field]["value"] .= '</TABLE>';
+ break;
+
+ case "list":
+ $option_table = "";
+ $opts = explode_trim( "~", $f[1] ); // Separate list options
+ $def_value = !empty($f[2]) ? $f[2] : "" ;
+ foreach( $opts as $opt )
+ {
+ $os = explode_trim( "^", $opt ); // Separate value from displayed text
+ $option_table[$os[0]] = $os[1];
+ }
+ // In case there's multiple options, display results of all selected options with comma separators
+ $x = explode( '~', $data[$field[0]] );
+ $out[$res_field]["value"] = $sep = '';
+ if( is_array($x) )
+ foreach( $x as $y )
+ {
+ $out[$res_field]["value"] .= $sep.$option_table[$y];
+ $sep = ', ';
+ }
+ break;
+
+ case "state":
+ $out[$res_field]["value"] = $GLOBALS['si_states_array'][$data[$field[0]]];
+ break;
+
+ case "country":
+ $out[$res_field]["value"] = $GLOBALS['si_countries_array'][$data[$field[0]]];
+ break;
+
+ case "break":
+ if( !empty($f[1]) ) // if {t1} is supplied
+ $out[$res_field]["value"] = $f[1];
+ else
+ $out[$res_field]["value"] = '<FONT COLOR="red">No break name or {text} supplied for type "break"</FONT>';
+ break;
+
+ default:
+ $out[$res_field]["value"] = '<FONT COLOR="red">UNKNOWN FIELD TYPE: '.$x[0].' for '.$f[0].'</FONT>';
+ break;
+
+ } // switch( field type )
+ } // foreach( field )
+
+ } // if( $data )
+ else
+ {
+ return( array( 'text' => 'No Data Found', 'status' => false ) );
+ }
+
+ // Replace parameters in title and view
+
+ reset( $out );
+ while( list ($k, $v) = each($out) )
+ {
+ $a_title = ereg_replace( "\\{".$v['field']."\\}", $v["value"], $a_title );
+ $view = ereg_replace( "\\{".$v['field']."\\}", $v["value"], $view );
+ $a_title = ereg_replace( "\\{encode:".$v['field']."\\}", urlencode($v["value"]), $a_title );
+ $view = ereg_replace( "\\{encode:".$v['field']."\\}", urlencode($v["value"]), $view );
+ }
+
+ $a_title = ereg_replace( "\\{link_params\\}", $link_params, $a_title );
+ $a_title = ereg_replace( "\\{form_params\\}", $form_params, $a_title );
+ $view = ereg_replace( "\\{link_params\\}", $link_params, $view );
+ $view = ereg_replace( "\\{form_params\\}", $form_params, $view );
+
+ // Add QuickTip if provided
+
+ if( trim($quick_tip) != '' )
+ $a_title = quick_tip( $a_title, $quick_tip );
+
+ // Display top of page
+
+ if( !$nocenter )
+ $ret .= '<CENTER>';
+
+ $ret .= "$a_title\n";
+
+ if( $data )
+ {
+ // Output results
+
+ if( empty($view) ) // If there's no format spec in $view
+ {
+ $ret .= '<TABLE BORDER="'.$borders.'"'.($borders>0?' CELLPADDING="5"':'').'>
+ ';
+ reset( $out );
+ while( list( $k, $v ) = each($out) )
+ if( !$v["hidden"] )
+ $ret .= '<TR><TH ALIGN="right" VALIGN="top">'.$v["name"].' </TH><TD ALIGN="left">'.$v["value"].'</TD></TR>
+ ';
+
+ $ret .= '</TABLE>
+ ';
+ }
+ else // Otherwise use $view to output data
+ $ret .= $view;
+ }
+ else
+ $ret .= ' <CENTER>(No results found)</CENTER>
+ <P>
+ ';
+
+ if( !$nocenter )
+ $ret .= "</CENTER>\n";
+
+ return( array( 'text' => $ret, 'status' => true ) );
+
+}
+
+function admin_view_record( $table, $conn_str, $id, $fields,
+ $url, $action, $params, $a_title, $view="", $options = "", $quick_tip = "", $id_field = '' )
+{
+
+ $r = admin_view_record_r( $table, $conn_str, $id, $fields,
+ $url, $action, $params, $a_title, $view, $options, $quick_tip, $id_field );
+ echo $r['text'];
+ return( $r['status'] );
+}
+
+
+
+
+ // User login management
+
+function admin_user_login( $operation, $conn_str, $sess_code, $table, $id_field, $pw_field, $user_id = "", $password = "", $where = "" )
+{
+
+ $secret_code = "ApplesANDOranges"; // Secret code used to md5 encrypt everything
+
+ if( SI_DEBUG > 2 )
+ echo "<P>DEBUG: admin_user_login() - Request: $operation - ID: $user_id PW: $password SESSION: $sess_code\n";
+
+ switch( $operation )
+ {
+
+ case "create":
+
+ // Get user information and create a session
+
+ $d = db_auto_get_row( "SELECT * FROM $table WHERE id = '$sess_code';", 0, $conn_str, FALSE );
+ if( !$d )
+ return( FALSE );
+
+ // Build MD5 string from User ID, timestamp, "id" field value and secret
+
+ $t = time();
+ $md5_string = md5( $d[$id_field].$t.$d["id"].$secret_code );
+
+ // Build output data
+
+ $d["session_code"] = $md5_string."-".$t."-".$d["id"]; // Session Code
+ $d["session_link"] = "&session_code=".$d["session_code"]; // Link format
+ $d["session_form"] = '<INPUT TYPE="hidden" NAME="session_code" VALUE="'.$d["session_code"].'">'; // Form format
+
+ return $d;
+
+
+ break;
+
+ case "login":
+
+ // Do sanity check
+
+ if( empty($user_id) || empty($password) || ereg("[,*']", $user_id) || ereg("[,*']", $password) )
+ return( FALSE );
+
+ // Check ID and Password against specified table
+
+ $d = db_auto_get_row( "SELECT * FROM $table WHERE $id_field = '$user_id' AND $pw_field = '$password'".($where!=''?' AND '.$where:'').";",
+ 0, $conn_str, FALSE );
+ if( !$d )
+ return( FALSE );
+
+ // Build MD5 string from User ID, timestamp, "id" field value and secret
+
+ $t = time();
+ $md5_string = md5( $d[$id_field].$t.$d["id"].$secret_code );
+
+ // Build output data
+
+ $d["session_code"] = $md5_string."-".$t."-".$d["id"]; // Session Code
+ $d["session_link"] = "&session_code=".$d["session_code"]; // Link format
+ $d["session_form"] = '<INPUT TYPE="hidden" NAME="session_code" VALUE="'.$d["session_code"].'">'; // Form format
+
+ return $d;
+
+ break;
+
+ case "verify":
+
+ // Break apart session code - [0] = md5, [1] = timestamp, [2] = record id
+
+ $ses = explode_trim( "-", $sess_code );
+ if( count($ses) != 3 || !is_numeric($ses[2]) ) // If there's not 3 parts, or the id isn't numeric, then it's not a valid code
+ return( FALSE );
+
+ // Retrieve data record
+
+ $d = db_auto_get_row( "SELECT * FROM $table WHERE id = ".$ses[2].($where!=''?' AND '.$where:'').";", 0, $conn_str, FALSE );
+
+ if( !$d ) // If no results, then not a valid record id
+ return( FALSE );
+
+ // Check MD5 string for valid session
+
+ if( md5($d[$id_field].$ses[1].$d["id"].$secret_code) != $ses[0] )
+ return( FALSE );
+
+ // Check to see if session has timed out
+
+ if( $ses[1] + SI_SES_TIMEOUT < time() )
+ return( FALSE );
+
+ // Update Timestamp and MD5 string
+
+ $t = time();
+ $md5_string = md5( $d[$id_field].$t.$d["id"].$secret_code );
+
+ // Build output data
+
+ $d["session_code"] = $md5_string."-".$t."-".$d["id"]; // Session Code
+ $d["session_link"] = "&session_code=".$d["session_code"]; // Link format
+ $d["session_form"] = '<INPUT TYPE="hidden" NAME="session_code" VALUE="'.$d["session_code"].'">'; // Form format
+
+ return( $d );
+
+ break;
+
+ default:
+ echo '<FONT COLOR="red">UNKNOWN user login operation</FONT>';
+ return( FALSE );
+ break;
+ }
+
+}
+
+
+
+function authorize_net_aim
+ (
+ $login, $key, $test, $conf_email, $merch_email,
+ $amount, $card_num, $exp_date, $card_code, $currency = '',
+ $fname = '', $lname = '', $company = '', $address = '', $city = '', $state = '', $zip = '', $country = '', $phone = '', $fax = '', $id = '', $ip = '', $tax_id = '',
+ $email = '',
+ $invoice = '', $descr ='', $header = '', $footer = '',
+ $ship_fname = '', $ship_lname = '', $ship_company = '', $ship_address = '', $ship_city = '', $ship_state = '', $ship_zip = '', $ship_country = ''
+ )
+{
+
+ /*
+ Authorize.net processing
+
+ Test card #
+
+ TEST CARD CARD TYPE
+ NUMBER
+ 370000000000002 American Express
+ 6011000000000012 Discover
+ 5424000000000015 MasterCard
+ 4007000000027 Visa
+
+ */
+
+ // Make sure test is exactly 'FALSE' before conducting an actual transaction
+
+ switch( $test )
+ {
+ case 'LOCAL_TEST':
+ case 'TRUE':
+ case 'FALSE':
+ break;
+
+ default:
+ echo 'APPLICATION ERROR: Authorize.Net test mode not properly defined.';
+ exit;
+ break;
+ }
+
+ // Compile submitted data
+
+ $submit_data = array
+ (
+ // Base required information Required
+
+ 'x_version' => '3.1',
+ 'x_delim_data' => 'TRUE', // Yes
+ 'x_delim_char' => '|',
+ 'x_encap_char' => '',
+ 'x_relay_response' => 'FALSE', // Yes
+ 'x_test_request' => $test,
+
+ // Merchant Account Information
+
+ 'x_login' => $login, // Yes
+ 'x_tran_key' => $key, // Yes
+
+ // Transaction parameters
+
+ 'x_currency_code' => '',
+ 'x_method' => 'CC', // Yes Options: CC, ( ECHECK not implemented )
+ 'x_type' => 'AUTH_CAPTURE', // Yes Options: AUTH_CAPTURE, AUTH_ONLY, CAPTURE_ONLY, CREDIT, VOID, PRIOR_AUTH_CAPTURE
+ 'x_amount' => $amount, // Yes
+
+ // If x_method = 'CC'
+
+ 'x_card_num' => $card_num, // Yes
+ 'x_exp_date' => $exp_date, // Yes
+ 'x_card_code' => $card_code,
+
+ // Additional Customer information
+
+ 'x_first_name' => $fname,
+ 'x_last_name' => $lname,
+ 'x_company' => $company,
+ 'x_address' => $address,
+ 'x_city' => $city,
+ 'x_state' => $state, // Verified if supplied
+ 'x_zip' => $zip,
+ 'x_country' => $country, // Verified if supplied
+ 'x_phone' => $phone,
+ 'x_fax' => $fax,
+ 'x_cust_id' => $id,
+ 'x_customer_ip' => $ip,
+ 'x_customer_tax_id' => $tax_id,
+
+ // E-Mail info for confirmation
+
+ 'x_email' => $email, // Customer E-Mail
+ 'x_email_customer' => $conf_email, // IF TRUE customer will receive conf via E-Mail from Authorize.Net
+ 'x_header_email_receipt' => $header, // Header to be included in conf E-Mail
+ 'x_footer_email_receipt' => $footer, // Footer to be included in conf E-Mail
+ 'x_merchant_email' => $merch_email, // If supplied, merchant will receive conf via E-Mail
+
+ // Invoice
+
+ 'x_invoice_num' => $invoice,
+ 'x_description' => $descr,
+
+ // Shipping information
+
+ 'x_ship_to_first_name' => $ship_fname,
+ 'x_ship_to_last_name' => $ship_lname,
+ 'x_ship_to_company' => $ship_company,
+ 'x_ship_to_address' => $ship_address,
+ 'x_ship_to_city' => $ship_city,
+ 'x_ship_to_state' => $ship_state,
+ 'x_ship_to_zip' => $ship_zip,
+ 'x_ship_to_country' => $ship_country,
+
+
+ );
+
+ if( SI_DEBUG > 2 )
+ {
+ echo "<P>DEBUG: Authorize.Net Submit Array<BR><PRE>\n";
+ var_dump( $submit_data );
+ echo "\n</PRE><P>";
+ }
+
+ // Assemble above data into a string for posting
+
+ if( SI_DEBUG > 0 )
+ echo "<P>DEBUG: Authorize.Net Submit Array<BR><PRE><table><tr><th align=\"left\">Parameter</th><th align=\"left\">Value</th></tr>\n";
+
+ $postdata = $sep = '';
+ foreach($submit_data AS $key => $val)
+ {
+ $postdata .= $sep.urlencode( $key ).'='.urlencode( $val );
+ $sep = '&';
+ if( SI_DEBUG > 0 )
+ echo "<tr><td>$key</td><td>$val</td></tr>\n";
+ }
+
+ if( SI_DEBUG > 0 )
+ echo "</table></PRE><P>";
+
+ if( SI_DEBUG > 0 )
+ echo "<P>DEBUG: Authorize.Net Post String = $postdata<P>";
+
+ // If this is a local test, just return data, don't send to Authorize.Net
+
+ if( $test == 'LOCAL_TEST' || $card_num == '0011001100110011' )
+ {
+ return
+ (
+ array
+ (
+ 0 => 1, // Success
+ 4 => 'Local Test', // Approval Code
+ )
+ );
+ }
+
+ // Submit Request
+
+ $headers = "POST $path HTTP/1.1\r\nHost: $host\r\nContent-type: application/x-www-form-urlencoded\r\nContent-length: ".strlen($poststring)."\r\n";
+
+ exec( AUTH_CURL.' -d '.escapeshellarg($postdata)." -P 443 --url ".escapeshellarg(AUTH_URL), $results, $return );
+
+ // Check for failures
+
+ if( $return == 1 ) // Exec failed - Code 100
+ return( array(0=>100) );
+
+ if( trim($results[0]) == '' ) // No data returned - Code 101
+ return( array(0=>101) );
+
+ // Break results up into an array
+
+ $res = explode( "|", $results[0] );
+ if( SI_DEBUG > 0 )
+ {
+ echo "<P>DEBUG: Authorize.Net Response Array<BR><PRE><table><tr><th align=\"left\">Parameter</th><th align=\"left\">Value</th></tr>\n";
+ reset( $res );
+ foreach($res AS $key => $val)
+ echo "<tr><td>$key</td><td>$val</td></tr>\n";
+ echo "</table></PRE><P>";
+ }
+
+ if( !is_array($res) ) // No good data from Authorize.net - Code 102
+ {
+ return( array(0=>102) );
+ }
+
+ // If MD5 Hash secret is provided, authenticate response from Authorize.Net
+
+ if( SI_AUTH_SECRET != '' )
+ {
+ $hash = md5( SI_AUTH_SECRET.$login.$key.round($amount, 2) );
+ if( $res[37] != $hash )
+ $res[0] = 103; // Indicate MD5 Hash verification failure
+ }
+
+ // Return results
+
+ return( $res );
+
+}
+
+
+function build_nav( $nav_table, $menu_title, $current_item = '', $sub_menu = '', $link_data = '' )
+{
+ $nl = "\n";
+
+ $out = '<div id="navcontainer">'.$nl;
+
+ // If a title has been supplied - Add that
+
+ if( $menu_title != '' )
+ $out .= '<div id="navtitle">'.$menu_title.'</div>'.$nl;
+
+ $out .= '<ul id="Level1">'.$nl;
+
+ // If additional link_data passed, include ? and get rid of first "&"
+
+ if( strlen($link_data) > 1 )
+ $link_data = "?".substr($link_data, 1);
+
+ // Build nav from supplied table
+
+ reset( $nav_table );
+ while( list($key, $val) = each( $nav_table ) )
+ {
+ // If current item make it a non-link and include any supplied sub-menu
+
+ if( $current_item == $key )
+ $out .= '<li ><a href="#" class="inactive" onclick="return false;">'.$val['title'].'</a>'.$nl.$sub_menu.'</li>'.$nl;
+ else
+ $out .= '<li><a href="'.$val['url'].$link_data.'">'.$val['title'].'</a></li>'.$nl;
+ }
+
+ $out .= '</ul> <!-- level1 -->'.$nl.'</div> <!-- navcontainer -->'.$nl;
+
+ return( $out );
+}
+
+
+?>