-
Notifications
You must be signed in to change notification settings - Fork 16
/
index.php
224 lines (177 loc) · 7.1 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
<?php
/*Used to suppress Notices*/
//error_reporting(E_ALL & ~E_NOTICE);
error_reporting(E_ERROR);
// Added to eliminate special characters
header('Content-type: text/html; charset=utf-8');
/* check if lock file exists if not we need to install */
session_start();
require('conf.php');
//http_redirect("install2", array("name" => "value"), true, HTTP_REDIRECT_PERM);
$VAR = array_merge($_GET,$_POST);
$wo_id = $VAR['wo_id'];
$customer_id = $VAR['customer_id'];
$id = $login_id;
$smarty->assign('id', $id);
if(!is_file('cache/lock') ) {
echo("
<script type=\"text/javascript\">
<!--
window.location = \"install\"
//-->
</script>");
} else if(is_dir('install') ) {
echo("<a style=\"color:red;\">The install Directory Exists!! Please Rename or remove the install directory.</a>");
die;
}
$page_title = $VAR['page_title'];
$auth = new Auth($db, 'login.php', 'secret');
require(INCLUDE_URL.SEP.'acl.php');
require('modules/core/translate.php');
############################
# Debuging #
############################
function getMicroTime() {
list($usec, $sec) = explode(" ", microtime());
return (float)$usec + (float)$sec;
}
$start = getMicroTime();
// If log off is set then we log off
if (isset($VAR['action']) && $VAR['action'] == 'logout') {
$auth->logout('login.php');
}
/* get company info for defaults */
$q = 'SELECT * FROM '.PRFX.'TABLE_COMPANY, '.PRFX.'VERSION ORDER BY '.PRFX.'VERSION.`VERSION_INSTALLED` DESC LIMIT 1';
if(!$rs = $db->execute($q)) {
force_page('core', 'error&error_msg=MySQL Error: '.$db->ErrorMsg().'&menu=1&type=database');
exit;
}
$smarty->assign('version', $rs->fields['VERSION_NAME']);
$smarty->assign('company_name', $rs->fields['COMPANY_NAME']);
$smarty->assign('company_address', $rs->fields['COMPANY_ADDRESS']);
$smarty->assign('company_city', $rs->fields['COMPANY_CITY']);
$smarty->assign('company_state', $rs->fields['COMPANY_STATE']);
$smarty->assign('company_zip', $rs->fields['COMPANY_ZIP']);
$smarty->assign('company_country', $rs->fields['COMPANY_COUNTRY']);
$smarty->assign('company_phone',$rs->fields['COMPANY_PHONE']);
$smarty->assign('company_email',$rs->fields['COMPANY_EMAIL']);
$smarty->assign('company_mobile',$rs->fields['COMPANY_MOBILE']);
$smarty->assign('company_toll_free',$rs->fields['COMPANY_TOLL_FREE']);
$smarty->assign('company_logo',$rs->fields['COMPANY_LOGO']);
$smarty->assign('currency_sym',$rs->fields['COMPANY_CURRENCY_SYMBOL']);
$smarty->assign('currency_code',$rs->fields['COMPANY_CURRENCY_CODE']);
$smarty->assign('date_format',$rs->fields['COMPANY_DATE_FORMAT']);
$smarty->assign('company_email_from',$rs->fields['COMPANY_EMAIL_FROM']);
$smarty->assign('email_server',$rs->fields['COMPANY_EMAIL_SERVER']);
$smarty->assign('email_server_port',$rs->fields['COMPANY_EMAIL_PORT']);
$smarty->assign('email_username',$rs->fields['COMPANY_SMTP_USERNAME']);
$smarty->assign('email_password',$rs->fields['COMPANY_SMTP_PASSWORD']);
#############################################################
# Url Builder This grabs gets and post and builds the url #
# conection strings #
#############################################################
if(!isset($_POST['page'])) {
if ( $_GET['page']) {
// Explode the url so we can get the module and page
list($module, $page) = explode(":", $_GET['page']);
$the_page = 'modules'.SEP.$module.SEP.$page.'.php';
// remove page from the $_GET array we dont want it to pass the options
unset($_GET['page']);
// Define the global options for each page
foreach($_GET as $key=>$val){
@define($key, $val);
}
// Check to see if the page is real other wise send em a 404
if ( file_exists ($the_page) ) {
$the_page= 'modules'.SEP.$module.SEP.$page.'.php';
} else {
$the_page= 'modules'.SEP.'core'.SEP.'404.php';
}
} else {
// If no page is supplied then go to the main page
$the_page= 'modules'.SEP.'core'.SEP.'main.php';
}
} else {
// Explode the url so we can get the module and page
list($module, $page) = explode(":", $_POST['page']);
$the_page = $the_page= 'modules'.SEP.$module.SEP.$page.'.php';
// remove page from the $_GET array we dont want it to pass the options
unset($_POST['page']);
// Define the global options for each page
foreach($_POST as $key=>$val){
@define($key, $val);
}
// Check to see if the page is real other wise send em a 404
if ( file_exists ($the_page) ) {
$the_page= 'modules'.SEP.$module.SEP.$page.'.php';
} else {
$the_page= 'modules'.SEP.'core'.SEP.'404.php';
}
}
$tracker_page = "$module:$page";
#####################################
# Display the pages #
#####################################
if(isset($_GET['wo_id'])) {
$smarty->assign('wo_id', $_GET['wo_id']);
global $wo_id;
} else {
$smarty->assign('wo_id','0');
}
if(isset($_GET['customer_id'])) {
$smarty->assign('wo_id', $_GET['customer_id']);
global $customer_id;
} else {
$smarty->assign('customer','0');
}
require('modules'.SEP.'core'.SEP.'error.php');
if(isset($page_title)) {
$smarty->assign('page_title', $page_title);
} else {
$page_title ="Home";
$smarty->assign('page_title', $page_title);
}
if(isset($VAR['msg'])) {
$smarty->assign('msg', $VAR['msg']);
}
if($VAR['escape'] != 1 ) {
require('modules'.SEP.'core'.SEP.'header.php');
require('modules'.SEP.'core'.SEP.'navagation.php');
require('modules'.SEP.'core'.SEP.'company.php');
}
if($menu == 1 ) {
$smarty->assign('menu', '1');
$smarty->display('core'.SEP.'error.tpl');
} else {
/* check acl for page request */
if(!check_acl($db,$module,$page)) {
force_page('core','error&error_msg=You do not have permission to access this '.$module.':'.$page.'&menu=1');
} else {
require($the_page);
}
}
if($VAR['escape'] != 1 ) {
require('modules'.SEP.'core'.SEP.'footer.php');
}
/* Tracker code */
function getIP() {
// $ip;
if (getenv("HTTP_CLIENT_IP")) $ip = getenv("HTTP_CLIENT_IP");
else if(getenv("HTTP_X_FORWARDED_FOR")) $ip = getenv("HTTP_X_FORWARDED_FOR");
else if(getenv("REMOTE_ADDR")) $ip = getenv("REMOTE_ADDR");
else $ip = "UNKNOWN";
return $ip;
}
$logtime = time();
$q = 'INSERT into '.PRFX.'TRACKER SET
date ='. $db->qstr( $logtime ).',
ip ='. $db->qstr( getIP() ).',
uagent ='. $db->qstr( getenv(HTTP_USER_AGENT) ).',
full_page ='. $db->qstr( $the_page ).',
module ='. $db->qstr( $module ).',
page ='. $db->qstr( $page ).',
referer ='. $db->qstr( getenv(HTTP_REFERER) );
if(!$rs = $db->Execute($q)) {
echo 'Error inserting tracker :'. $db->ErrorMsg();
}
?>