-
Notifications
You must be signed in to change notification settings - Fork 25
/
system.php
executable file
·1386 lines (1049 loc) · 43 KB
/
system.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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* system uzERP system loader
*
* @version $Revision: 1.126 $
* @package uzerp
* @author uzERP LLP and Steve Blamey <[email protected]>
* @license GPLv3 or later
* @copyright (c) 2017 uzERP LLP (support#uzerp.com). All rights reserved.
**/
require 'vendor/autoload.php';
use Symfony\Component\HttpFoundation\Request;
class system
{
protected $version = '$Revision: 1.126 $';
const DAY_START_HOURS = '9';
const DAY_START_MINUTES = '0';
const DAY_LENGTH = '8';
/*
* The AccessObject object for this user request
*/
public $access;
/*
* The requested action
*/
public $action;
/*
* The requested controller
*/
public $controller;
/*
* The injector object for this request
*/
public $injector;
/*
* Array of $_GET parameters where parameter name contains module
*/
public $modules = array();
/*
* The code module (as distinct from the menu module)
*/
public $module;
/*
* The permission id
*/
public $pid;
/*
* The router object for this request
*/
public $router;
/*
* smarty template locations for the current module
*/
public $templates = array();
/*
* The view object
*/
public $view;
public $flash = array();
protected $ajax = FALSE;
protected $audit;
protected $available;
protected $debug = FALSE;
protected $jsfiles = array();
protected $cssfiles = array();
protected $json = FALSE;
protected $login_required = TRUE;
protected $user;
// http request object;
protected $request;
/*
* The permissions context for this request
* key = permission, value = data for this permission id
*/
private $module_context;
private function __construct()
{
// set path constants
$this->setPathBase();
// set the http request object
$this->request = Request::createFromGlobals();
}
public static function &Instance()
{
static $system;
if ($system == null) {
$system = new system();
}
return $system;
}
function checkPermission()
{
$controllername = get_class($this->controller);
$continue = FALSE;
if (! $this->access->hasPermission($this->modules, $controllername, $this->action, $this->pid) && ! $continue) {
$flash = Flash::Instance();
// $flash->clear();
$this->access->save();
$flash->addError("You do not have access to the requested action.");
$flash->save();
$count = count($this->modules);
if (strtolower($this->action) == 'index') {
if ($controllername !== 'IndexController') {
sendTo('', 'index', $this->modules);
} else {
if ($count <= 1) {
sendTo('', 'index', 'dashboard');
}
// The x = 1; $x < $count is not a coding error is is to get all modulues but the last one
$mod = $this->modules;
array_pop($mod);
sendTo('', 'index', $mod);
}
} else {
sendTo(str_replace('controller', '', strtolower($controllername)), 'index', $this->modules);
}
}
}
public function check_system()
{
static $checked;
// we only want to call checked system
if ($checked !== NULL) {
return $checked;
}
// OS installed packages required for PDF previews on output dialog
$check_packages = array(
'convert',
'pdfinfo'
);
foreach ($check_packages as $package) {
// set a few vars
$output = array();
$location = '';
// check if the package has a location
// we use whereis instead parsing the response from the vanila command so if
// we (for some strange reason) searched for the package 'shutdown -h 0' it
// wouldn't kill the server... belt and braces
// we also need to remove any characters which could cause our system harm
// a valid unix command 'fop && rm -fR *' would completely wipe the os
// removing spaces isn't good enough on it's own either
$package = current(preg_replace("/[^A-Za-z0-9_-]+/i", "", explode(' ', $package)));
// execute the whereis command, catch the result
exec("whereis " . $package, $output);
// rip the response apart and prepare (trim) the location part
$array = explode(":", $output[0]);
$location = trim(end($array));
// if the location is empty, the package doesn't exist
if (empty($location)) {
define('HAS_' . strtoupper($package), FALSE);
} else {
define('HAS_' . strtoupper($package), TRUE);
}
}
// an array of directories that must exist
$required_directories = array(
CACHE_ROOT
);
foreach ($required_directories as $directory) {
// if the directory doesn't exist...
if (! is_dir($directory)) {
// attempt to create it
if (! mkdir($directory, 0777)) {
trigger_error("Cannot create cache directory (" . $directory . ")", E_USER_ERROR);
}
}
}
// set to true to avoid running more than once per request
$checked = true;
return $checked;
}
/**
* A single function to load (in order) all the essential foundations to the uzERP framework
*
* @param bool $_disable_cache
*/
public function load_essential($_disable_cache = FALSE)
{
static $loaded;
// we only want to call this function once
if ($loaded !== NULL) {
return $loaded;
}
// lib.php includes some very important helper functions
// include it now, before it's too late!
require LIB_ROOT . 'lib.php';
require LIB_ROOT . 'classes/utils/Cache.php';
require LIB_ROOT . 'classes/utils/Config.php';
$this->setPathNames();
$this->set_autoloader($_disable_cache);
// **************
// PRELOAD CACHE
// we want to preload the cache so we can be prepared for disabled caching
// hitting this now will expose (bool) MEMCACHED_ENABLED for the system
// as we've yet to get to autoload we must include the path ourselves
Cache::Instance();
// set the path names before checking the system
// otherwise we won't have access to setting functions
// set the loaded flag to true
$loaded = TRUE;
}
/*
* Main control function to set up environment, set route (module, controller, action) and call controller action
*/
public function display()
{
$this->load_essential();
debug('system::display session data:' . print_r($_SESSION, TRUE));
$this->user = FALSE;
if (isLoggedIn()) {
// Sets the global constants EGS_USERNAME and EGS_COMPANY_ID
setupLoggedInUser();
$this->user = getCurrentUser();
if(isset($_ENV['UZERP_MANAGE_USER_SESSIONS']) && strtolower($_ENV['UZERP_MANAGE_USER_SESSIONS']) === 'on') {
if(($_SERVER['REQUEST_TIME'] > $_SESSION['last_active'] + $_ENV['USER_ACTIVITY_TIMEOUT_SECS'])
|| ($_SERVER['REQUEST_TIME'] > $_SESSION['started'] + $_ENV['USER_SESSION_MAX_AGE_SECS'])){
session_destroy();
session_unset();
//remove session cookie
addCookie(session_name(), '', 0);
sendTo(
$_GET['controller'],
$_GET['action'],
$_GET['module']
);
}
}
$_SESSION['last_active'] = $_SERVER['REQUEST_TIME'];
$this->access = AccessObject::Instance($_SESSION['username']);
} else {
define('EGS_COMPANY_ID', - 1);
define('EGS_USERNAME', $_SESSION['username']);
$this->access = AccessObject::Instance();
}
$this->setView();
$this->view->set("accessTree", $this->access->tree);
$this->view->set('access', $this->access);
$this->setController();
$this->setTemplates();
$this->setAction();
$cookie_params = session_get_cookie_params();
$csrf = new \Riimu\Kit\CSRF\CSRFHandler();
// Use CSRF cookie storage and set the secure flag
// to the current value of session.cookie_secure in php.ini
$storage = new \Riimu\Kit\CSRF\Storage\CookieStorage(
$name = 'csrf_token',
$expire = 0,
$path = $cookie_params['path'],
$domain = $cookie_params['domain'],
$secure = $cookie_params['secure']
);
$csrf->setStorage($storage);
// check that the csrf token is valid
if (!$this->csrfValid()) {
sendBack();
}
$csrf_token = $csrf->getToken();
// make csrf token available to smarty templates
$this->view->set('csrf_token', $csrf_token);
if (isLoggedIn()) {
$this->checkPermission();
}
// Find css/js
$css = glob('dist/css/main*.css');
if($this->module == 'login') {
$logincss = glob('dist/css/login-*.css');
$this->view->set('login_css', $logincss[0]);
}
$jsdir = self::findModulePath(PUBLIC_MODULES, $this->modules['module'], FALSE);
$jsdir .= DIRECTORY_SEPARATOR . 'resources/js';
if (!strpos($jsdir, 'user/modules')) {
$jsdir = str_replace(FILE_ROOT . 'modules/public_pages' , 'dist/js/modules', $jsdir);
} else {
// Serve user module js from module directory
$jsdir = str_replace(FILE_ROOT , '', $jsdir);
}
$modulejs = glob("{$jsdir}/*.js");
$js = glob('dist/js/scripts*.js');
// output standard arrays to smarty
$this->view->set('current_user', $this->user);
$this->view->set('main_css', $css[0]);
if (file_exists('user') && is_dir('user') && count(glob('user/theme*.css')) >= 1) {
$user_css = glob('user/theme*.css');
$this->view->set('user_css', $user_css[0]);
}
$this->view->set('main_js', $js[0]);
$this->view->set('module_js', $modulejs[0]);
$action = $this->action;
$controller = $this->controller;
if (defined('EGS_COMPANY_ID') && EGS_COMPANY_ID !== 'null' && EGS_COMPANY_ID > 0) {
$sc = DataObjectFactory::Factory('Systemcompany');
$sc->load(EGS_COMPANY_ID);
if ($sc->isLoaded()) {
define('SYSTEM_COMPANY', $sc->company);
define('COMPANY_ID', $sc->company_id);
$this->available = ($sc->access_enabled == 'NONE') ? FALSE : TRUE;
$this->audit = ($sc->audit_enabled == 't' ? TRUE : FALSE);
$this->debug = ($sc->debug_enabled == 't' ? TRUE : FALSE);
$this->view->set('info_message', $sc->info_message);
$this->view->set('systemcompany', $sc);
}
}
$policy = DataObjectFactory::Factory('SystemObjectPolicy');
if ($policy->getCount() > 0) {
define('SYSTEM_POLICIES_ENABLED', TRUE);
} else {
define('SYSTEM_POLICIES_ENABLED', FALSE);
}
if (! defined('SYSTEM_COMPANY')) {
define('SYSTEM_COMPANY', '');
}
if (! defined('COMPANY_ID')) {
define('COMPANY_ID', '');
}
// Set auditing/debugging for logged in user
if ($this->user) {
$this->audit = $this->audit ? $this->audit : ($this->user->audit_enabled == 't' ? TRUE : FALSE);
$this->debug = $this->debug ? $this->debug : ($this->user->debug_enabled == 't' ? TRUE : FALSE);
$this->available = $this->available ? ($this->user->access_enabled == 't' ? TRUE : FALSE) : $this->available;
}
if (! $this->available && isLoggedIn()) {
$_SESSION['loggedin'] = FALSE;
$_SESSION['username'] = null;
$flash = Flash::Instance();
$flash->addError('The system is unavailable at present');
$flash->save();
sendto('');
}
define('AUDIT', $this->audit);
define('DEBUG', $this->debug);
$db = DB::Instance();
$db->debug(DEBUG);
if (! defined('EGS_CURRENCY')) {
define('EGS_CURRENCY', 'GBP');
}
if (class_exists('Currency')) {
$currency = DataObjectFactory::Factory('Currency');
$currency->loadBy('currency', EGS_CURRENCY);
if ($currency) {
define('EGS_CURRENCY_SYMBOL', mb_convert_encoding($currency->symbol, 'UTF-8'));
}
}
if (! defined('EGS_CURRENCY_SYMBOL')) {
define('EGS_CURRENCY_SYMBOL', mb_convert_encoding('£', 'UTF-8'));
}
/**
* Get job messages
*/
$messages = uzJobMessages::Factory(EGS_USERNAME, EGS_COMPANY_ID);
$messages->displayJobMessages();
/**
* *BEGIN CACHE CHECK*****
*/
if (! defined('EGS_COMPANY_ID')) {
define('EGS_COMPANY_ID', '');
}
if (DEBUG) {
$this->writeDebug();
}
$cache_key = md5($_SERVER['REQUEST_URI'] . EGS_COMPANY_ID . EGS_USERNAME);
$flash = Flash::Instance();
$config = Config::Instance();
// output all the variables to smarty
// this replaces $smarty.const.setting_name
$this->view->assign('config', $config->get_all());
setRefererPage();
debug('system::display Calling function ' . get_class($controller) . '::' . $action);
// echo 'system::display (1),'.microtime(TRUE).'<br>';
$controller->$action();
// echo 'system::display (2),'.microtime(TRUE).'<br>';
$flash->save();
// Save any flash messages for audit purposes
$this->flash['errors'] = $flash->getMessages('errors');
$this->flash['warnings'] = $flash->getMessages('warnings');
$this->flash['messages'] = $flash->getMessages('messages');
if (isLoggedIn()) {
$this->access->save();
}
// assign stuff to smarty
$controller->assignModels();
// this code fires $controller->index() if (perhaps) getPrintActions doesn't exist,
// thus overwriting the sidebar. Only fire if subclass of printController
if (is_subclass_of($controller, 'printController') && $action != 'printDialog') {
$this->view->assign('printaction', $controller->getPrintActions());
}
$controllername = str_replace('Controller', '', get_class($controller));
$this->pid = $this->access->getPermission($this->modules, $controllername, $action);
$self = array();
if (! empty($this->pid)) {
$self['pid'] = $this->pid;
}
$self['modules'] = $this->modules;
// $self['controller']=$controllername;
// $self['action']=$action;
$qstring = \sanitize($_GET);
foreach ($qstring as $qname => $qvalue) {
if (! in_array($qname, array(
'orderby',
'page'
))) {
$self[$qname] = $qvalue;
}
}
$this->view->assign('self', $self);
if (isset($this->user)) {
$this->view->assign('current_user', $this->user);
}
// Session timed out on input form so save the form data while the user logs back in
// See system::setController for where the form data is read after logging back in
if ($this->modules['module'] == 'login' && ! empty($_POST)) {
$_SESSION['data'] = $_POST;
}
$echo = $controller->view->get('echo');
if (($this->ajax || $this->json) && $echo !== FALSE) {
echo $controller->view->get('echo');
exit();
} elseif ($this->modules['module'] == 'login') {
$current = getParamsArray($_SERVER['QUERY_STRING']);
$referer['modules'] = $current['modules'];
$referer['controller'] = 'Index';
$referer['action'] = 'index';
$_SESSION['referer'][setParamsString($current)] = setParamsString($referer);
} elseif (! isset($_GET['ajax'])) {
$referer = '';
if (! empty($_POST)) {
// This is a save form so set the referer to be the referer's referer!
$referer = (isset($_SESSION['refererPage'])) ? $_SESSION['refererPage'] : '';
}
setReferer($referer);
$current = getParamsArray($_SERVER['QUERY_STRING']);
$flash = Flash::Instance();
$current += array(
'messages' => $flash->getMessages('messages'),
'warnings' => $flash->getMessages('warnings'),
'errors' => $flash->getMessages('errors')
);
$_SESSION['submit_token']['current'] = $current;
}
// Set the user's 'home' link
if (!isset($_SESSION['user_home'])
&& isLoggedIn())
{
$prefs = UserPreferences::Instance(EGS_USERNAME);
$default_page = $prefs->getPreferenceValue('default_page', 'shared');
if ($default_page == "") {
$home = link_to(['module' => 'dashboard'], false, false);
} else {
$home = link_to(['module' => explode(',', $default_page)[1]], false, false);
}
$_SESSION['user_home'] = $home;
}
$home = $_SESSION['user_home'];
$this->view->set('user_home', $home);
showtime('pre-display');
$this->view->display('index_page.tpl', $cache_key);
showtime('post-display');
}
/*
* Gets the fields for the supplied tablename
*/
public static function getFields($tablename, $cache_results = TRUE)
{
$cached_fields = FALSE;
$cache_id = array(
'table_fields',
$tablename
);
// we might not want to hit the cache
if (MEMCACHED_ENABLED && $cache_results === TRUE) {
// instanciate the cache and get the cache value
$cache = Cache::Instance();
$cached_fields = $cache->get($cache_id);
}
// go and fetch the data and populate the cache
if ($cached_fields === FALSE) {
$fields = Fields::getFields_static($tablename);
$return = array();
if (is_array($fields)) {
foreach ($fields as $field) {
$return[$field->name] = clone $field;
}
} else {
$return = FALSE;
}
if (MEMCACHED_ENABLED && $return !== FALSE && $cache_results === TRUE) {
$cache->add($cache_id, $return);
}
} else {
$return = $cached_fields;
}
return $return;
}
public static function scanDirectories($rootDir, $module, $require = FALSE)
{
if (! empty($module)) {
$start = self::findModulePath($rootDir, $module);
}
if (empty($start)) {
$start = $rootDir;
}
$allData = array();
$allData = array_merge($allData, self::getDirectories($start, 'down', '', $require));
if ($rootDir != $start) {
$allData = array_merge($allData, self::getDirectories($start, 'up', $rootDir, $require));
}
return $allData;
}
public static function getDirectories($start, $direction, $stop = '', $require = FALSE)
{
// echo 'system::getDirectories - '.$direction.' '.$start.'<br>';
$allData = array();
$dirContent = scandir($start);
foreach ($dirContent as $key => $content) {
if ($content != '.' && $content != '..' && $content != 'CVS') {
if (substr($start, - 1) == DIRECTORY_SEPARATOR) {
$path = $start . $content;
} else {
$path = $start . DIRECTORY_SEPARATOR . $content;
}
if (substr($content, - 4) == '.php' && is_file($path) && is_readable($path)) {
if ($require) {
require $path;
} else {
$allData[strtolower(substr_replace($content, '', strrpos($content, '.')))] = $path;
}
} else {
if (is_dir($path) && is_readable($path)) {
// $allData[]=$path.'/';
// echo 'system::getDirectories - '.$direction.' '.$start.' adding path '.$path.'<br>';
// recursive callback to open new directory
if ($direction == 'down') {
$allData = array_merge($allData, self::getDirectories($path, $direction, $stop, $require));
}
}
}
}
}
if (! empty($stop)) {
if (substr($stop, - 1) == DIRECTORY_SEPARATOR) {
$stop = substr($stop, 0, strrpos($stop, DIRECTORY_SEPARATOR));
}
if ($direction == 'up') {
$path = substr($start, 0, strrpos($start, DIRECTORY_SEPARATOR));
if ($path != $stop) {
$allData = array_merge($allData, self::getDirectories($path, $direction, $stop, $require));
}
}
}
return $allData;
}
public static function findModulePath($directory, $module = '')
{
if (! empty($module)) {
$cache_id = array(
'module_dir_path',
strtolower($module)
);
$cache = Cache::Instance();
$module_path = $cache->get($cache_id);
// go and fetch the data and populate the cache
if ($module_path === FALSE) {
$moduleobject = DataObjectFactory::Factory('ModuleObject');
$moduleobject->loadBy('name', $module);
if ($moduleobject->isLoaded()) {
$cache->add($cache_id, FILE_ROOT . $moduleobject->location);
return FILE_ROOT . $moduleobject->location;
} else {
$dirContent = scandir(realpath($directory));
if (is_array($dirContent)) {
foreach ($dirContent as $content) {
if (substr($content, 0, 1) != ".") {
if (substr($directory, - 1) == DIRECTORY_SEPARATOR) {
$path = $directory . $content;
} else {
$path = $directory . DIRECTORY_SEPARATOR . $content;
}
if ($content == $module) {
return $path;
} elseif (file_exists($path) && is_dir($path) && is_readable($path)) {
$path = self::findModulePath($path, $module);
if (! empty($path)) {
return $path;
}
} else {
$path = '';
}
}
}
}
}
} else {
return $module_path;
}
}
return '';
}
public function setAction()
{
showtime("---");
// action
if (empty($this->action)) {
if ($this->router->Dispatch('action') !== null) {
$this->view->assign('action', strtolower($this->router->Dispatch('action')));
}
$this->action = ActionFactory::Factory($this->controller);
if ($this->modules['module'] == 'login') {
$actions = array(
'index',
'password',
'requestpassword',
'login',
'logout',
'mfaenroll',
'mfavalidate'
);
if (! in_array(strtolower($this->action), $actions)) {
$this->action = 'index';
}
}
}
$this->controller->setTemplateName($this->action);
}
public function setController()
{
showtime('pre-controller-new');
$autoloader = &AutoLoader::Instance();
// controller
$controller = ControllerFactory::Factory($this->login_required, $autoloader->paths);
$this->controller = new $controller($this->module, $this->view);
$this->controller->setInjector($this);
// If session timed out on input form, get the saved form data
// after the user has logged back in
// see system::display for saving of form data
if (isset($_SESSION['data']) && $this->modules['module'] != 'login') {
$this->controller->setData($_SESSION['data']);
unset($_SESSION['data']);
}
$getVars = \sanitize($_GET);
$this->controller->setData($getVars);
$this->controller->setData($_POST);
}
/**
* Return the http request object
*
* @return \Symfony\Component\HttpFoundation\Request
*/
public function getRequest() {
return $this->request;
}
function instantiate($interface, $type = 'SY')
{
if (! defined('EGS_COMPANY_ID')) {
$usercompanyid = - 1;
} else {
$usercompanyid = EGS_COMPANY_ID;
}
if (! isset($_SESSION['injectorclass'][$usercompanyid][$interface])) {
$cc = new ConstraintChain();
$cc->add(new Constraint('name', '=', $interface));
$cc->add(new Constraint('category', '=', $type));
$cc1 = new ConstraintChain();
$cc1->add(new Constraint('usercompanyid', '=', $usercompanyid));
if ($usercompanyid > 0) {
$cc1->add(new Constraint('usercompanyid', '=', - 1), 'OR');
}
$cc2 = new ConstraintChain();
$cc2->add($cc1);
$cc2->add($cc);
$query = "select * from injector_classes where " . $cc2->__toString() . " order by usercompanyid";
$db = &DB::Instance();
$result = $db->GetRow($query);
if (empty($result)) {
return FALSE;
}
$_SESSION['injectorclass'][$usercompanyid][$interface] = $result['class_name'];
}
$class_name = $_SESSION['injectorclass'][$usercompanyid][$interface];
$dependencies = self::instantiateDependencies(new ReflectionClass($class_name));
return call_user_func_array(array(
new ReflectionClass($class_name),
'newInstance'
), $dependencies);
}
private function instantiateDependencies($reflection, $supplied = '')
{
$dependencies = array();
if ($constructor = $reflection->getConstructor()) {
foreach ($constructor->getParameters() as $parameter) {
if ($interface = $parameter->getClass()) {
$dependencies[] = self::instantiate($interface->getName());
} elseif ($dependency = array_shift($supplied)) {
$dependencies[] = $dependency;
}
}
}
return $dependencies;
}
public function get_lib_files($_disable_cache = FALSE)
{
$cache_id = array(
'resources',
'lib_root'
);
$cache = Cache::Instance();
if ($_disable_cache) {
$files = FALSE;
} else {
$files = $cache->get($cache_id);
}
if ($files === FALSE) {
$files = self::scanDirectories(LIB_ROOT, '', FALSE);
// attempt to set the cache value
$cache->add($cache_id, $files);
}
return $files;
}
public function set_autoloader($_disable_cache = FALSE)
{
// include autoloader
require LIB_ROOT . 'classes' . DIRECTORY_SEPARATOR . 'AutoLoader.php';
$autoloader_paths = $this->get_lib_files($_disable_cache);
$autoloader = &AutoLoader::Instance();
$autoloader->addPath($autoloader_paths);
if (file_exists(SITE_CLASSES)) {
$autoloader->addPath(self::scanDirectories(SITE_CLASSES, '', FALSE));
}
$moduleobject = DataObjectFactory::Factory('ModuleObject');
$moduleobject->loadBy('name', 'common');
$scan_dirs = array();
if ($moduleobject->isLoaded()) {
$scan_dirs = $moduleobject->getComponentLocations();
}
if (empty($scan_dirs)) {
$scan_dirs = self::scanDirectories(COMMON_MODULES, '', FALSE);
}
$autoloader->addPath($scan_dirs);
}
// public function set_plugins()
public function setPathNames()
{
// Need way of registering plugins
require PRINT_ROOT . 'PrintIPP.php';
require PRINT_ROOT . 'ExtendedPrintIPP.php';
require PRINT_ROOT . 'CupsPrintIPP.php';
$this->injector = $this;
}
public function setPathBase()
{