Remove call to debug logging before the function was defined.
[capital-apms.git] / inc / always.php.in
blob23b0e2e7dde974e46d903628831a4521a8bb9326
1 <?php
2 $c = (object) 'Configuration Data';
3 $c->started = microtime();
4 $c->messages = array();
5 $c->stylesheets = array('css/apms.css');
6 $c->local_styles = array();
7 $c->scripts = array('js/apms.js');
8 $c->page_title = "APMS";
10 // Force some things to not be set...
11 unset($session);
13 error_log( "=============================================== Start $PHP_SELF for $HTTP_HOST on $_SERVER[SERVER_NAME]" );
14 if ( file_exists("/etc/apms/".$_SERVER['SERVER_NAME'].".conf") ) {
15 include_once("/etc/apms/".$_SERVER['SERVER_NAME'].".conf");
17 else if ( file_exists("../config/config.php") ) {
18 include_once("../config/config.php");
20 else {
21 include_once("apms_configuration_missing.php");
22 exit;
25 /**
26 * Work out our version
29 $c->code_version = 0;
30 $c->version_string = 'x.y.z'; // The actual version # is replaced into that during the build /release process
31 if ( isset($c->version_string) && preg_match( '/(\d+)\.(\d+)\.(\d+)(.*)/', $c->version_string, $matches) ) {
32 $c->code_major = $matches[1];
33 $c->code_minor = $matches[2];
34 $c->code_patch = $matches[3];
35 $c->code_version = (($c->code_major * 1000) + $c->code_minor).".".$c->code_patch;
37 header( sprintf("X-APMS-Version: %s/%d.%d", $c->code_pkgver, $c->code_major, $c->code_minor) );
39 require_once("PgQuery.php");
40 require_once("MenuSet.php");
41 $main_menu = new MenuSet('menu', 'menu', 'menu_active');
42 require_once("APMSSession.php");
44 $session->LoginRequired();
46 /**
47 * Rather laboriously we have to look in the database to get the current financial year, used frequently
49 $qry = new PgQuery('SELECT financialyearcode FROM month WHERE startdate<=current_date AND enddate>=current_date LIMIT 1;');
50 if ( $qry->Exec("always") && $qry->rows == 1 ) {
51 $row = $qry->Fetch();
52 $c->current_financial_year = $row->financialyearcode;
54 if ( isset( $_REQUEST['year'] ) ) $year = intval($_REQUEST['year']);
55 if ( !isset($year) ) $year = $c->current_financial_year;
56 if ( $year < 1950 && isset( $_REQUEST['year'] ) ) $year = intval($_REQUEST['year']);
57 if ( $year < 1950 ) $year = $c->current_financial_year;
60 function log_array( $name, $arr ) {
61 global $session;
63 foreach( $arr AS $k => $v ) {
64 if ( is_array($v) ) {
65 log_array( "$name"."[$k]", $v );
67 else if ( is_object($v) ) {
68 $session->Log("DBG: %s[%s] = is an object", $name, $k, $v );
70 else {
71 $session->Log("DBG: %s[%s] = <<%s>>", $name, $k, $v );
76 function replace_uri_params( $uri, $replacements ) {
77 global $session;
79 $replaced = $uri;
80 foreach( $replacements AS $param => $new_value ) {
81 $regex = "/([&?])($param)=([^?]+)/";
82 if ( preg_match( $regex, $replaced ) )
83 $replaced = preg_replace( $regex, "\$1$param=$new_value", $replaced);
84 else
85 $replaced .= "&$param=$new_value";
87 if ( ! preg_match( '/\?/', $replaced ) ) {
88 $replaced = preg_replace("/&(.+)$/", "?\$1", $replaced);
90 $session->Log("DBG: URI <<$uri>> morphed to <<$replaced>>");
91 return $replaced;