1 |
rodolico |
1 |
<?php
|
20 |
rodolico |
2 |
include_once( 'DatabaseDefinition.php' );
|
1 |
rodolico |
3 |
global $LOGFILE;
|
|
|
4 |
$LOGFILE='/tmp/camp.log';
|
|
|
5 |
define( 'VERSION', '2.0b' );
|
|
|
6 |
define( 'BUILD_DATE', '20130527');
|
|
|
7 |
|
45 |
rodolico |
8 |
function loadConfig() {
|
|
|
9 |
// Search through directories looking for a config file
|
|
|
10 |
$return = array(
|
|
|
11 |
'error' => '',
|
|
|
12 |
'path' => '',
|
|
|
13 |
'configuration' => array()
|
|
|
14 |
);
|
|
|
15 |
$configFileName = 'camp2_config.yaml';
|
|
|
16 |
$searchDirectories = array(
|
|
|
17 |
// one level up from document root
|
|
|
18 |
$_SERVER['DOCUMENT_ROOT'] . "/../$configFileName",
|
|
|
19 |
// directory private one level up from document root
|
|
|
20 |
$_SERVER['DOCUMENT_ROOT'] . "/../private/$configFileName",
|
|
|
21 |
// the current directory
|
|
|
22 |
"./$configFileName",
|
|
|
23 |
);
|
|
|
24 |
foreach ( $searchDirectories as $search ) {
|
|
|
25 |
if ( file_exists( realpath( $search ) ) ) {
|
|
|
26 |
$return['path'] = realpath( $search );
|
|
|
27 |
$return['configuration'] = yaml_parse_file( $return['path'] );
|
|
|
28 |
$return['error'] = '';
|
|
|
29 |
return $return;
|
|
|
30 |
} // if
|
|
|
31 |
} // for
|
|
|
32 |
$return['error'] = "No configuration found in<br />" . implode( '<br />', $searchDirectories );
|
|
|
33 |
return $return;
|
|
|
34 |
}
|
|
|
35 |
|
46 |
rodolico |
36 |
function saveConfig( $filename, $configuration ) {
|
|
|
37 |
return yaml_emit_file( $filename, $configuration );
|
|
|
38 |
}
|
|
|
39 |
|
1 |
rodolico |
40 |
function insertValuesIntoQuery( $query, $values ) {
|
|
|
41 |
foreach ( $values as $name => $value ) {
|
|
|
42 |
$query = search_replace_string($query, "<$name>", $value );
|
|
|
43 |
}
|
|
|
44 |
return $query;
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
function search_replace_string($string, $searchFor, $replaceWith ) {
|
|
|
48 |
$string = str_replace ( $searchFor, $replaceWith, $string );
|
|
|
49 |
return $string;
|
|
|
50 |
}
|
45 |
rodolico |
51 |
|
|
|
52 |
/**
|
|
|
53 |
* uses $_REQUEST to decide what to display
|
|
|
54 |
*
|
|
|
55 |
* @param string[] $request The contents for $_REQUEST
|
|
|
56 |
*
|
|
|
57 |
* @returns string HTML to be inserted into page
|
|
|
58 |
*/
|
|
|
59 |
function displayHTML( $request ) {
|
|
|
60 |
global $connection;
|
20 |
rodolico |
61 |
|
45 |
rodolico |
62 |
if ( isset( $_REQUEST['doAdmin'] ) ) {
|
|
|
63 |
$return = $_SESSION['user']->admin($connection) . $_SESSION['user']->errors();
|
|
|
64 |
$_SESSION['user']->clearErrors();
|
|
|
65 |
} elseif ( isset( $_REQUEST['searchfor'] ) ) {
|
|
|
66 |
$return = print_r( doSearch( $_REQUEST['searchfor'] ), true );
|
|
|
67 |
} else { // default to this if nothing else works
|
46 |
rodolico |
68 |
//$return = '<pre>' . print_r( $_SESSION, true ) . '</pre>';
|
|
|
69 |
$return = "<h3 align='center'>Content goes here</h3>";
|
45 |
rodolico |
70 |
} // else
|
|
|
71 |
return $return;
|
|
|
72 |
}
|
46 |
rodolico |
73 |
|
|
|
74 |
function buildRestrictions() {
|
|
|
75 |
global $dbConnection;
|
|
|
76 |
if ( empty( $_SESSION['user']->restrictions ) || $_SESSION['user']->restrictions == '1=1' ) {
|
|
|
77 |
// give full access
|
51 |
rodolico |
78 |
$_SESSION['restrictions']['owner'] = '1=1';
|
|
|
79 |
$_SESSION['restrictions']['location'] = '1=1';
|
|
|
80 |
$_SESSION['restrictions']['device'] = '1=1';
|
46 |
rodolico |
81 |
} else {
|
|
|
82 |
$rules = explode( "\n", $_SESSION['user']->restrictions );
|
|
|
83 |
//print '<pre>' . print_r( $rules, true ) . '</pre>' ; die;
|
|
|
84 |
$temp = array();
|
|
|
85 |
$workingOn = '';
|
|
|
86 |
foreach ( $rules as $thisOne ) {
|
|
|
87 |
//print "<pre>Working on $thisOne\n</pre>";
|
|
|
88 |
if ( preg_match( '/\[([^\[\]]+)\]/', $thisOne, $match ) ) {
|
|
|
89 |
//print "Adding as category\n<br />";
|
|
|
90 |
$workingOn = $match[1];
|
|
|
91 |
} else {
|
|
|
92 |
//print "Adding as a value in $workingOn\n<br />";
|
|
|
93 |
$temp[$workingOn][] = "'" . $dbConnection->real_escape_string(trim($thisOne)) . "'";
|
|
|
94 |
}
|
|
|
95 |
} // foreach
|
|
|
96 |
//print '<pre>' . print_r( $temp, true ) . '</pre>' ; die;
|
|
|
97 |
$_SESSION['restrictions']['owner'] = implode( ',', $temp['owner'] );
|
|
|
98 |
$_SESSION['restrictions']['location'] = implode( ',', $temp['location'] );
|
|
|
99 |
$_SESSION['restrictions']['device'] = implode( ',', $temp['device'] );
|
|
|
100 |
} // else
|
|
|
101 |
}
|
45 |
rodolico |
102 |
|
|
|
103 |
|
22 |
rodolico |
104 |
|
45 |
rodolico |
105 |
|
|
|
106 |
|
1 |
rodolico |
107 |
|
|
|
108 |
?>
|