|
[ Index ]
|
Source Code Reference for V1.00
|
[Summary view]
[Print]
[Text view]
1 <?php
2
3
4
5
6
7
8 if (!defined('W2P_BASE_DIR')) {
9 die('This file should not be called directly.');
10 }
11
12
13 define('UI_MSG_OK', 1);
14 define('UI_MSG_ALERT', 2);
15 define('UI_MSG_WARNING', 3);
16 define('UI_MSG_ERROR', 4);
17
18
19 $GLOBALS['translate'] = array();
20
21 define('UI_CASE_MASK', 0x0F);
22 define('UI_CASE_UPPER', 1);
23 define('UI_CASE_LOWER', 2);
24 define('UI_CASE_UPPERFIRST', 3);
25
26 define('UI_OUTPUT_MASK', 0xF0);
27 define('UI_OUTPUT_HTML', 0);
28 define('UI_OUTPUT_JS', 0x10);
29 define('UI_OUTPUT_RAW', 0x20);
30
31
32
33 require_once W2P_BASE_DIR . '/classes/permissions.class.php';
34
35
36
37
38
39
40 class CAppUI {
41
42
43 var $state = null;
44
45
46 var $user_id = null;
47
48
49 var $user_first_name = null;
50
51
52 var $user_last_name = null;
53
54
55 var $user_company = null;
56
57
58 var $user_department = null;
59
60
61 var $user_email = null;
62
63
64 var $user_type = null;
65
66
67 var $user_prefs = null;
68
69
70 var $day_selected = null;
71
72
73
74
75 var $user_locale = null;
76
77
78 var $user_lang = null;
79
80
81 var $base_locale = 'en';
82
83
84
85 var $msg = '';
86
87
88 var $msgNo = '';
89
90
91 var $defaultRedirect = '';
92
93
94
95 var $cfg = null;
96
97
98
99 var $version_major = null;
100
101
102
103 var $version_minor = null;
104
105
106
107 var $version_patch = null;
108
109
110
111 var $version_string = null;
112
113
114
115 var $last_insert_id = null;
116
117
118
119 var $user_style = null;
120
121
122
123
124
125 function CAppUI() {
126 $this->state = array();
127
128 $this->user_id = -1;
129 $this->user_first_name = '';
130 $this->user_last_name = '';
131 $this->user_company = 0;
132 $this->user_department = 0;
133 $this->user_type = 0;
134
135
136
137 $this->cfg['locale_warn'] = w2PgetConfig('locale_warn');
138
139 $this->project_id = 0;
140
141 $this->defaultRedirect = '';
142
143 $this->setUserLocale($this->base_locale);
144 $this->user_prefs = array();
145 }
146
147
148
149
150
151 function getSystemClass($name = null) {
152 if ($name) {
153 return W2P_BASE_DIR . '/classes/' . $name . '.class.php';
154 }
155 }
156
157
158
159
160
161
162
163 function getLibraryClass($name = null) {
164 if ($name) {
165 return W2P_BASE_DIR . '/lib/' . $name . '.php';
166 }
167 }
168
169
170
171
172
173
174 function getModuleClass($name = null) {
175 if ($name) {
176 return W2P_BASE_DIR . '/modules/' . $name . '/' . $name . '.class.php';
177 }
178 }
179
180
181
182
183
184
185 function getModuleAjax( $name=null ) {
186 if ($name) {
187 return W2P_BASE_DIR . '/modules/' . $name . '/' . $name . '.ajax.php';
188 }
189 }
190
191
192
193
194
195 function getVersion() {
196 global $w2Pconfig;
197 if (!isset($this->version_major)) {
198 include_once W2P_BASE_DIR . '/includes/version.php';
199 $this->version_major = $w2p_version_major;
200 $this->version_minor = $w2p_version_minor;
201 $this->version_patch = $w2p_version_patch;
202 $this->version_string = $this->version_major . '.' . $this->version_minor;
203 if (isset($this->version_patch)) {
204 $this->version_string .= '.' . $this->version_patch;
205 }
206 if (isset($w2p_version_prepatch)) {
207 $this->version_string .= '-' . $w2p_version_prepatch;
208 }
209 }
210 return $this->version_string;
211 }
212
213
214
215
216 function checkStyle() {
217
218 $uistyle = $this->getPref('UISTYLE');
219
220 if ($uistyle && !is_dir(W2P_BASE_DIR . '/style/' . $uistyle)) {
221
222 $this->setPref('UISTYLE', w2PgetConfig('host_style'));
223 }
224 }
225
226
227
228
229
230
231
232
233 function readDirs($path) {
234 $dirs = array();
235 $d = dir(W2P_BASE_DIR . '/' . $path);
236 while (false !== ($name = $d->read())) {
237 if (is_dir(W2P_BASE_DIR . '/' . $path . '/' . $name) && $name != '.' && $name != '..' && $name != 'CVS' && $name != '.svn') {
238 $dirs[$name] = $name;
239 }
240 }
241 $d->close();
242 return $dirs;
243 }
244
245
246
247
248
249
250
251 function readFiles($path, $filter = '.') {
252 $files = array();
253
254 if (is_dir($path) && ($handle = opendir($path))) {
255 while (false !== ($file = readdir($handle))) {
256 if ($file != '.' && $file != '..' && preg_match('/' . $filter . '/', $file)) {
257 $files[$file] = $file;
258 }
259 }
260 closedir($handle);
261 }
262 return $files;
263 }
264
265
266
267
268
269
270
271
272 function checkFileName($file) {
273 global $AppUI;
274
275
276 $bad_chars = ";/\\";
277 $bad_replace = '....';
278
279
280 if (strpos(strtr($file, $bad_chars, $bad_replace), '.') !== false) {
281 $AppUI->redirect('m=public&a=access_denied');
282 } else {
283 return $file;
284 }
285
286 }
287
288
289
290
291
292
293
294
295 function makeFileNameSafe($file) {
296 $file = str_replace('../', '', $file);
297 $file = str_replace('..\\', '', $file);
298 return $file;
299 }
300
301
302
303
304
305
306
307 function setUserLocale($loc = '', $set = true) {
308 global $locale_char_set;
309
310 $LANGUAGES = $this->loadLanguages();
311
312 if (!$loc) {
313 $loc = $this->user_prefs['LOCALE'] ? $this->user_prefs['LOCALE'] : w2PgetConfig('host_locale');
314 }
315
316 if (isset($LANGUAGES[$loc]))
317 $lang = $LANGUAGES[$loc];
318 else {
319
320
321 if (strlen($loc) > 2) {
322 list($l, $c) = explode('_', $loc);
323 $loc = $this->findLanguage($l, $c);
324 } else {
325 $loc = $this->findLanguage($loc);
326 }
327 $lang = $LANGUAGES[$loc];
328 }
329 list($base_locale, $english_string, $native_string, $default_language, $lcs) = $lang;
330 if (!isset($lcs))
331 $lcs = (isset($locale_char_set)) ? $locale_char_set : 'utf-8';
332
333 if (version_compare(phpversion(), '4.3.0', 'ge')) {
334 $user_lang = array($loc . '.' . $lcs, $default_language, $loc, $base_locale);
335 } else {
336 if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
337 $user_lang = $default_language;
338 } else {
339 $user_lang = $loc . '.' . $lcs;
340 }
341 }
342 if ($set) {
343 $this->user_locale = $base_locale;
344 $this->user_lang = $user_lang;
345 $locale_char_set = $lcs;
346 } else {
347 return $user_lang;
348 }
349 }
350
351 function findLanguage($language, $country = false) {
352 $LANGUAGES = $this->loadLanguages();
353 $language = strtolower($language);
354 if ($country) {
355 $country = strtoupper($country);
356
357 $code = $language . '_' . $country;
358 if (isset($LANGUAGES[$code])) {
359 return $code;
360 }
361 }
362
363
364
365 $first_entry = null;
366 foreach ($LANGUAGES as $lang => $info) {
367 list($l, $c) = explode('_', $lang);
368 if ($l == $language) {
369 if (!$first_entry) {
370 $first_entry = $lang;
371 }
372 if ($country && $c == $country) {
373 return $lang;
374 }
375 }
376 }
377 return $first_entry;
378 }
379
380
381
382
383
384 function loadLanguages() {
385
386 if (isset($_SESSION['LANGUAGES'])) {
387 $LANGUAGES = &$_SESSION['LANGUAGES'];
388 } else {
389 $LANGUAGES = array();
390 $langs = $this->readDirs('locales');
391 foreach ($langs as $lang) {
392 if (file_exists(W2P_BASE_DIR . '/locales/' . $lang . '/lang.php')) {
393 include_once W2P_BASE_DIR . '/locales/' . $lang . '/lang.php';
394 }
395 }
396 $_SESSION['LANGUAGES'] = &$LANGUAGES;
397 }
398 return $LANGUAGES;
399 }
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415 function _($str, $flags = 0) {
416 if (is_array($str)) {
417 $translated = array();
418 foreach ($str as $s) {
419 $translated[] = $this->__($s, $flags);
420 }
421 return implode(' ', $translated);
422 } else {
423 return $this->__($str, $flags);
424 }
425 }
426
427 function __($str, $flags = 0) {
428 $str = trim($str);
429 if (empty($str)) {
430 return '';
431 }
432 $x = $GLOBALS['translate'][$str];
433
434 if ($x) {
435 $str = $x;
436 } elseif (w2PgetConfig('locale_warn')) {
437 if ($this->base_locale != $this->user_locale || ($this->base_locale == $this->user_locale && !in_array($str, $GLOBALS['translate']))) {
438 $str .= w2PgetConfig('locale_alert');
439 }
440 }
441 switch ($flags & UI_CASE_MASK) {
442 case UI_CASE_UPPER:
443 $str = strtoupper($str);
444 break;
445 case UI_CASE_LOWER:
446 $str = strtolower($str);
447 break;
448 case UI_CASE_UPPERFIRST:
449 $str = ucwords($str);
450 break;
451 }
452
453
454
455
456
457
458
459
460
461
462
463
464 global $locale_char_set;
465
466 if (!$locale_char_set) {
467 $locale_char_set = 'utf-8';
468 }
469
470 switch ($flags & UI_OUTPUT_MASK) {
471 case UI_OUTPUT_HTML:
472 $str = htmlentities(stripslashes($str), ENT_COMPAT, $locale_char_set);
473 break;
474 case UI_OUTPUT_JS:
475 $str = addslashes(stripslashes($str));
476 break;
477 case UI_OUTPUT_RAW:
478 $str = stripslashes($str);
479 break;
480 }
481 return $str;
482 }
483
484
485
486
487 function setWarning($state = true) {
488 $temp = $this->cfg['locale_warn'];
489 $this->cfg['locale_warn'] = $state;
490 return $temp;
491 }
492
493
494
495
496
497
498
499
500 function savePlace($query = '') {
501 if (!$query) {
502 $query = $_SERVER['QUERY_STRING'];
503 }
504 if ($query != $this->state['SAVEDPLACE']) {
505 $this->state['SAVEDPLACE-1'] = $this->state['SAVEDPLACE'];
506 $this->state['SAVEDPLACE'] = $query;
507 }
508 }
509
510
511
512 function resetPlace() {
513 $this->state['SAVEDPLACE'] = '';
514 }
515
516
517
518
519 function getPlace() {
520 return $this->state['SAVEDPLACE'];
521 }
522
523
524
525
526
527
528
529
530
531
532 function redirect($params = '', $hist = '') {
533 $session_id = SID;
534
535 session_write_close();
536
537 if (!$params) {
538
539 $params = !empty($this->state['SAVEDPLACE' . $hist]) ? $this->state['SAVEDPLACE' . $hist] : $this->defaultRedirect;
540 }
541
542 if ($session_id != '') {
543 if (!$params) {
544 $params = $session_id;
545 } else {
546 $params .= '&' . $session_id;
547 }
548 }
549 ob_implicit_flush();
550 header('Location: index.php?' . $params);
551 exit();
552 }
553
554
555
556
557
558
559
560
561
562
563
564
565