Rev 36 | Rev 46 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
<?php
include_once( 'DatabaseDefinition.php' );
global $LOGFILE;
$LOGFILE='/tmp/camp.log';
define( 'VERSION', '2.0b' );
define( 'BUILD_DATE', '20130527');
function loadConfig() {
// Search through directories looking for a config file
$return = array(
'error' => '',
'path' => '',
'configuration' => array()
);
$configFileName = 'camp2_config.yaml';
$searchDirectories = array(
// one level up from document root
$_SERVER['DOCUMENT_ROOT'] . "/../$configFileName",
// directory private one level up from document root
$_SERVER['DOCUMENT_ROOT'] . "/../private/$configFileName",
// the current directory
"./$configFileName",
);
foreach ( $searchDirectories as $search ) {
if ( file_exists( realpath( $search ) ) ) {
$return['path'] = realpath( $search );
$return['configuration'] = yaml_parse_file( $return['path'] );
$return['error'] = '';
return $return;
} // if
} // for
$return['error'] = "No configuration found in<br />" . implode( '<br />', $searchDirectories );
return $return;
}
function insertValuesIntoQuery( $query, $values ) {
foreach ( $values as $name => $value ) {
$query = search_replace_string($query, "<$name>", $value );
}
return $query;
}
function search_replace_string($string, $searchFor, $replaceWith ) {
$string = str_replace ( $searchFor, $replaceWith, $string );
return $string;
}
/**
* uses $_REQUEST to decide what to display
*
* @param string[] $request The contents for $_REQUEST
*
* @returns string HTML to be inserted into page
*/
function displayHTML( $request ) {
global $connection;
if ( isset( $_REQUEST['doAdmin'] ) ) {
$return = $_SESSION['user']->admin($connection) . $_SESSION['user']->errors();
$_SESSION['user']->clearErrors();
} elseif ( isset( $_REQUEST['searchfor'] ) ) {
$return = print_r( doSearch( $_REQUEST['searchfor'] ), true );
} else { // default to this if nothing else works
$return = '<form method="POST" enctype="multipart/form-data" name="search">
<table border="1" cellpadding="2" align="center">
<tbody>
<tr>
<td align = "center" colspan="2">
Enter search phrase to find device<br />
Precede search phrase with <b>site:</b> or <b>client:</b><br />
to search for site or client<br />
This is a substring search!
</td>
</tr>
<tr>
<td>
Search
</td>
<td title="Enter substring to search for">
<input type="text" name="searchfor" value="">
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" name="search" value="Search">
</td>
</tr>
</tbody>
</table>
</form>';
} // else
return $return;
}
?>