Error: No Files Found\n"; return $result; } if ($ftitle) { rsort($file_names); reset($file_names); } else { sort($file_names); } while (list($key, $file) = each($file_names)) { $selected = ""; $title = $file; // If desired, check the title tag of the files if ($ftitle) { $text = ""; // Check if the first line is a title tag $fp = fopen("$directory/$file", "r"); if (!$fp) { echo("File Open Error: $directory/$file"); return; } while (! feof($fp)) { $record = fgets($fp, 1000); $text .= $record; if (stristr("","",$text); $text = str_ireplace(".*$","",$text); $text = str_ireplace("amp;","",$text); $title = trim($text); } // Build option list $file = htmlentities($file); $title = htmlentities($title); if ($file == $current) $selected = " selected=\"selected\""; $result .= "\n"; } } else { $result .= "\n"; } // Return the result string return $result; } // End of GetDirList() function // // Function to get a file list and display the results // function BuildFileList($file, $current="", $separator="", $date_format = 'N') { // Get the actual file list $result = GetFileList($file, $current, $separator, $date_format); // Display the result string printf("$result"); } // End of BuildFileList() function // // Function to get the file list and return the option statements // function GetFileList($file, $current="", $separator="", $date_format = 'N') { // Define the character to split on $splitChar = ":"; if (isset($GLOBALS['splitChar']) && strlen($GLOBALS['splitChar']) > 0) $splitChar = $GLOBALS['splitChar']; if (isset($separator) && strlen($separator) > 0) $splitChar = $separator; $result = ""; if (is_file($file)) { $source = fopen($file, "r"); if (!$source) { echo("File Open Error: $file"); return; } while (! feof($source)) { // Read a record $record = trim(fgets($source, 1000)); $fields = explode("$splitChar", $record, 2); // Check how many fields are in record if (count($fields) == 2) { $code = $fields[0]; $value = $fields[1]; } else { $code = $fields[0]; $value = $fields[0]; } if (strlen($value) > 0) { // Handle language lookups $lvalue = ""; if (strpos($value,"TEXT-") !== FALSE) $lvalue = getLanguageText($value); if (strlen($lvalue) == 0) { $lcode = "CODE-" . strtoupper(str_replace(' ','-',$value)); $lvalue = getLanguageText($lcode); } if (strlen($lvalue) == 0) { $lcode = "TEXT-" . strtoupper(str_replace(' ','-',$value)); $lvalue = getLanguageText($lcode); } if (strlen($lvalue)) $value = $lvalue; // Add additional info if required if ($date_format != "") { if ($date_format == 'Y') $value = date($code,time()); if ($date_format == 'A') $value .= " - " . date($code,time()); } $selected = ""; if ($code == $current) $selected = " selected=\"selected\""; $result .= "\n"; } } } else { $result .= "\n"; } // Return the result string return $result; } // End of GetFileList() function // // Function to get the file list and return the options in an array // function GetFileListArray($file, $current="", $separator="", $date_format = 'N') { // Define the character to split on $splitChar = ":"; if (isset($GLOBALS['splitChar']) && strlen($GLOBALS['splitChar']) > 0) $splitChar = $GLOBALS['splitChar']; if (isset($separator) && strlen($separator) > 0) $splitChar = $separator; $result = array(); if (is_file($file)) { $source = fopen($file, "r"); if (!$source) { echo("File Open Error: $file"); return; } while (! feof($source)) { // Read a record $record = trim(fgets($source, 1000)); $fields = explode("$splitChar", $record, 2); // Check how many fields are in record if (count($fields) == 2) { $code = $fields[0]; $value = $fields[1]; } else { $code = $fields[0]; $value = $fields[0]; } if (strlen($value) > 0) { // Handle language lookups $lvalue = ""; if (strpos($value,"TEXT-") !== FALSE) $lvalue = getLanguageText($value); if (strlen($lvalue) == 0) { $lcode = "CODE-" . strtoupper(str_replace(' ','-',$value)); $lvalue = getLanguageText($lcode); } if (strlen($lvalue) == 0) { $lcode = "TEXT-" . strtoupper(str_replace(' ','-',$value)); $lvalue = getLanguageText($lcode); } if (strlen($lvalue)) $value = $lvalue; // Add additional info if required if ($date_format != "") { if ($date_format == 'Y') $value = date($code,time()); if ($date_format == 'A') $value .= " - " . date($code,time()); } $result[$code] = $value; } } } else { $result[] = "Error: File Not Found: $file"; } // Return the result string return $result; } // End of GetFileList() function // // Build a simple checkbox display field and display it // function BuildCheckBox($name, $value, $current="") { printf("\n"); } // End of BuildCheckBox() function // // Build a checkbox field based on a text file of options & display it // function BuildFileCheckbox($file, $name, $current="", $separator="", $spanid="") { $result = ""; if (is_file($file)) { $source = fopen($file, "r"); if (!$source) { echo("File Open Error: $file"); return; } while (! feof($source)) { // Read a record $record = trim(fgets($source, 1000)); $fields = explode(":", $record); // Check how many fields are in record if (count($fields) == 2) { $code = $fields[0]; $value = $fields[1]; } else { $code = $fields[0]; $value = $fields[0]; } if ($code) { // Handle language lookups $lvalue = ""; if (strpos($value,"TEXT-") !== FALSE) $lvalue = getLanguageText($value); if (strlen($lvalue) == 0) { $lcode = "CODE-" . strtoupper(str_replace(' ','-',$value)); $lvalue = getLanguageText($lcode); } if (strlen($lvalue) == 0) { $lcode = "TEXT-" . strtoupper(str_replace(' ','-',$value)); $lvalue = getLanguageText($lcode); } if (strlen($lvalue)) $value = $lvalue; $sspan = ""; $espan = ""; if (strlen($spanid)) { $sspan = ""; $espan = ""; } $checked = ""; if (!is_array($current) && $code == $current) $checked = " checked=\"checked\""; if (is_array($current) && in_array($code,$current)) $checked = " checked=\"checked\""; $result .= "$sspan$value$espan $separator "; } } } else { $result .= "Error: File Not Found: $file"; } // Display the result string printf("$result");; } // End of BuildFileCheckbox() function // // Build a radio selection field based on a text file of options & display it // function BuildFileRadio($file, $name, $current="", $separator="", $class="") { $result = GetFileRadio($file, $name, $current, $separator, $class); // Display the result string printf("$result");; } // End of BuildFileRadio() function function GetFileRadio($file, $name, $current="", $separator="", $class="") { global $currLanguage; $result = ""; if (is_file($file)) { $source = fopen($file, "r"); if (!$source) { echo("File Open Error: $file"); return; } while (! feof($source)) { // Read a record $record = trim(fgets($source, 1000)); $fields = explode(":", $record); // Check how many fields are in record if (count($fields) == 2) { $code = $fields[0]; $value = $fields[1]; } else { $code = $fields[0]; $value = $fields[0]; } if (strlen($value) > 0) { // Handle language lookups $lvalue = ""; if (strpos($value,"TEXT-") !== FALSE) $lvalue = getLanguageText($value); if (strlen($lvalue) == 0) { $lcode = "CODE-" . strtoupper(str_replace(' ','-',$value)); $lvalue = getLanguageText($lcode); } if (strlen($lvalue) == 0) { $lcode = "TEXT-" . strtoupper(str_replace(' ','-',$value)); $lvalue = getLanguageText($lcode); } if (strlen($lvalue)) $value = $lvalue; $id = $name . "_" . str_replace(' ','_',$code); $checked = ""; if ($code == $current) $checked = " checked='checked'"; $rclass = ""; if (strlen($class)) $rclass = " class='$class'"; $result .= "$value $separator"; // $result .= "$value "; } } } else { $result .= "Error: File Not Found: $file"; } return($result); } // End of GetFileRadio() function // // Build a selection list from a code table in the database and display it // function BuildDBList($table,$code_field,$display_field,$sort_field, $current="",$sort="ASC",$where="",$errmsg=""){ // Get the actual list from the database $result = GetDBList($table,$code_field,$display_field,$sort_field, $current,$sort,$where,$errmsg); // Print the result string printf("%s",$result); } // End of BuildDBList() function // // Build a selection list from a code table in the database and return it // function GetDBList($table,$code_field,$display_field,$sort_field, $current="",$sort="ASC",$where="",$errmsg=""){ // Define the separator for the display fields $separator = " - "; if (array_key_exists('field_separator',$GLOBALS)) $separator = $GLOBALS["field_separator"]; // Split display_fields as there may be more than one field to display $display_fields = explode(",", $display_field); $query = "select distinct $code_field, $display_field, $sort_field " . "from $table " . "where $code_field is not null "; // Process the display fields to ensure they are not null for ($j = 0; $j < count($display_fields); $j++) { $d_field = $display_fields[$j]; $query .= "and $d_field is not null "; } // Add special where clauses if there is one if (strlen($where) > 0) { if (stripos($where, "and ") !== 0 && stripos($where, " and ") !== 0) $where = "and $where"; } $query .= $where . " order by $sort_field $sort"; writeLog($query); $results = array(); $results = db_query($query); // or error_log("/usr/lib/php/optionlist.php - cannot connect to db from {$_SERVER['HTTP_HOST']} {$_SERVER['PHP_SELF']}"); if (!$results) { $now = date("Y-m-d H:i:s",time()); $fp = fopen("/usr/lib/php/optionlist.log","a"); fputs($fp,"$now - GetDBList: $GLOBALS[SCRIPT_FILENAME]\n"); $result = "ERROR: Unable to access MySQL Database"; return $result; } $num_rows = db_num_rows($results); $result = ""; if (!$num_rows) { if ($errmsg == "N") { $result = ""; } else { $result .= "\n"; } } else { $current = str_replace(""","\"",$current); while ($row = db_fetch_assoc($results)) { $code = $row[$code_field]; $value = ""; for ($j = 0; $j < count($display_fields); $j++) { $d_field = $display_fields[$j]; $c_value = $row[$d_field]; if (strlen($value)) $value .= $separator; $value .= "$c_value"; } $selected = ""; if ($code == $current) $selected = " selected=\"selected\""; $result .= "\n"; } } // Return the result string return $result; } // End of GetDBList() function // // Build and display a simple selection menu from a code table // - Built for justladiesfitness.com // function BuildDBMenu($table,$code_field,$display_field,$sort_field, $base="",$where="") { // Get the actual list from the database $result = GetDBMenu($table,$code_field,$display_field,$sort_field, $base,$where); // Print the result string printf("$result"); } // // Function to get the DB Menu and return a string // function GetDBMenu($table,$code_field,$display_field,$sort_field, $base="",$where="") { $query = "select $code_field, $display_field, $sort_field " . "from $table " . "where $code_field is not null " . "and $display_field is not null $where " . "order by $sort_field"; $results = array(); $results = db_query($query); if (!$results) { $now = date("Y-m-d H:i:s",time()); $fp = fopen("/usr/lib/php/optionlist.log","a"); fputs($fp,"$now - GetDBMenu: $GLOBALS[SCRIPT_FILENAME]\n"); $result = "ERROR: Unable to access MySQL Database"; return $result; } $num_rows = db_num_rows($results); $result = ""; if (!$num_rows) { $result .= "Error: No Records Found: $table"; } else { while ($row = db_fetch_assoc($results)) { $code = $row[$code_field]; $value = $row[$display_field]; if ($i) { $result .= "| "; } // Convert spaces to '+' $code = str_replace(" ","+",$code); $result .= "" . $value . " "; } } // Return the result string return $result; } // End of BuildDBMenu() function } if (!function_exists('getLanguageText')) { function getLanguageText($code) { return(''); } } ?>