2 // Ensure that ../inc is in our included paths as early as possible
3 set_include_path( '../inc'. PATH_SEPARATOR
. get_include_path());
5 $c = (object) 'Configuration Data';
6 $c->started
= microtime();
7 $c->messages
= array();
8 $c->stylesheets
= array('css/menus.css','css/apms.css');
9 $c->local_styles
= array();
10 $c->print_styles
= array('css/print.css');
11 $c->scripts
= array('js/apms.js');
12 $c->page_title
= "APMS";
13 $c->total_query_time
= 0;
15 // Force some things to not be set...
18 error_log( "=============================================== Start $_SERVER[PHP_SELF] for $_SERVER[HTTP_HOST] on $_SERVER[SERVER_NAME]" );
19 if ( file_exists("/etc/apms/".$_SERVER['SERVER_NAME'].".conf") ) {
20 include_once("/etc/apms/".$_SERVER['SERVER_NAME'].".conf");
22 else if ( file_exists("../config/config.php") ) {
23 include_once("../config/config.php");
26 include_once("apms_configuration_missing.php");
31 * Work out our version
35 $c->version_string
= '1.7.0'; // The actual version # is replaced into that during the build /release process
36 if ( isset($c->version_string
) && preg_match( '/(\d+)\.(\d+)\.(\d+)(.*)/', $c->version_string
, $matches) ) {
37 $c->code_major
= $matches[1];
38 $c->code_minor
= $matches[2];
39 $c->code_patch
= $matches[3];
40 $c->code_version
= (($c->code_major
* 1000) +
$c->code_minor
).".".$c->code_patch
;
42 header( sprintf("X-APMS-Version: %s/%d.%d", $c->version_string
, $c->code_major
, $c->code_minor
) );
44 require_once("AWLUtilities.php");
45 require_once("AwlQuery.php");
46 require_once("APMSSession.php");
48 $session->LoginRequired();
51 * Rather laboriously we have to look in the database to get the current financial year, used frequently
53 $qry = new AwlQuery('SELECT financialyearcode FROM month WHERE startdate<=current_date AND enddate>=current_date LIMIT 1;');
54 if ( $qry->Exec("always") && $qry->rows() == 1 ) {
56 $c->current_financial_year
= $row->financialyearcode
;
58 if ( isset($year) && $year < 1950 ) unset($year);
59 param_to_global('year','#[0-9]{4,5}#'); // just in case my code lasts 7992 years... :-)
60 if ( !isset($year) ) $year = $c->current_financial_year
;
61 if ( $year < 1950 ) $year = $c->current_financial_year
;
63 param_to_global('et','#[ACTLPJ]+#i'); if (isset($et)) $et = strtoupper($et);
64 param_to_global('ec','#[0-9]+#');
65 param_to_global('ac','#[0-9.]+#');
67 $component = param_to_global('t','#[a-z0-9_-]+#');
69 param_to_global('id','#^[a-z, 0-9-]+$#i');
70 if ( isset($id) && preg_match( '#^([A-Z]+)[, -]?([0-9]+)$#', $id, $matches ) ) {
71 $id = strtoupper($id);
72 $id = intval($matches[2]);
73 switch( $matches[1] ) {
74 case 'T': $idtype = 'tenant'; if (!isset($et)) { $et = 'T'; $ec = $id; } break;
75 case 'C': $idtype = 'creditor'; if (!isset($et)) { $et = 'C'; $ec = $id; } break;
76 case 'P': $idtype = 'property'; if (!isset($et)) { $et = 'P'; $ec = $id; } break;
77 case 'L': $idtype = 'company'; if (!isset($et)) { $et = 'L'; $ec = $id; } break;
78 case 'J': $idtype = 'project'; if (!isset($et)) { $et = 'J'; $ec = $id; } break;
79 case 'A': $idtype = 'asset'; if (!isset($et)) { $et = 'A'; $ec = $id; } break;
81 case 'INV': $idtype = 'invoice'; break;
82 case 'VCHR': $idtype = 'voucher'; break;
83 case 'CHQ': $idtype = 'cheque'; break;
86 $idtype = $matches[1];
90 if ( !isset($id) ) $id = 0; else $id = intval($id); // Just to be certain
95 * Function to retrieve a list of office settings into the $office_settings
96 * array. If it's called a second time, only the new settings will be fetched
99 * @param strings $args A list of strings which are the names of office settings.
101 $office_settings = (object) array();
102 function get_office_settings( ) {
103 global $office_settings;
105 $args = func_get_args();
108 foreach( $args AS $k => $v ) {
109 if ( !isset($office_settings->{$v}) ) {
110 $sql .= ", get_office_setting('$v') AS \"$v\"";
117 if ( !$need_sql ) return;
119 $qry = new AwlQuery( "SELECT".substr($sql,1) );
120 if ( $qry->Exec('always') && $qry->rows() == 1 ) {
121 $row = $qry->Fetch();
122 foreach( $args AS $k => $v ) {
123 $office_settings->{$v} = $row->{$v};
128 get_office_settings('GST-Rate');
131 * Function to retrieve a office control accounts into the $office_accounts
132 * array. If it's called a second time, only the new accounts will be fetched
135 * @param strings $args A list of strings which are the names of office control accounts
137 $office_accounts = array();
138 function get_office_accounts( ) {
139 global $office_accounts;
141 $args = func_get_args();
144 foreach( $args AS $k => $v ) {
145 if ( !isset($office_accounts[$v]) ) {
146 $in_list .= ", ". qpg($v);
153 if ( !$need_sql ) return;
155 $in_list = substr($in_list,2); // skip first comma
156 $qry = new AwlQuery( "SELECT oca.* FROM officecontrolaccount oca JOIN office o USING (officecode) WHERE o.thisoffice AND oca.name IN ( $in_list )" );
157 if ( $qry->Exec('always') && $qry->rows() > 0 ) {
158 while( $row = $qry->Fetch() ) {
159 $office_accounts[$row->name
] = clone($row);
164 require_once("apms_menus.php");