3636
3737class app {
3838
39- private $ _language_inc = 0 ;
40- private $ _wb ;
41- private $ _loaded_classes = array ();
39+ private $ _language_inc = 0 ;
40+ private $ _wb ;
41+ private $ _loaded_classes = array ();
4242 private $ _conf ;
4343
44- public function __construct ()
45- {
46- global $ conf ;
47- $ this ->_conf = $ conf ;
48-
49- if ($ this ->_conf ["start_db " ] == true ) {
50- $ this ->load ('db_ ' .$ this ->_conf ["db_type " ]);
51- $ this ->db = new db ;
52-
53- /*
54- Initialize the connection to the master DB,
55- if we are in a multiserver setup
56- */
57- if ($ this ->_conf ["dbmaster_host " ] != '' && $ this ->_conf ["dbmaster_host " ] != $ this ->_conf ["db_host " ]) {
58- $ this ->dbmaster = new db ;
59- if ($ this ->dbmaster ->linkId ) $ this ->dbmaster ->closeConn ();
60- $ this ->dbmaster ->dbHost = $ this ->_conf ["dbmaster_host " ];
61- $ this ->dbmaster ->dbName = $ this ->_conf ["dbmaster_database " ];
62- $ this ->dbmaster ->dbUser = $ this ->_conf ["dbmaster_user " ];
63- $ this ->dbmaster ->dbPass = $ this ->_conf ["dbmaster_password " ];
64- } else {
65- $ this ->dbmaster = $ this ->db ;
66- }
67- }
68-
69- //* Start the session
70- if ($ this ->_conf ['start_session ' ] == true ) {
71- session_start ();
72-
73- //* Initialize session variables
74- if (!isset ($ _SESSION ['s ' ]['id ' ]) ) $ _SESSION ['s ' ]['id ' ] = session_id ();
75- if (empty ($ _SESSION ['s ' ]['theme ' ])) $ _SESSION ['s ' ]['theme ' ] = $ conf ['theme ' ];
76- if (empty ($ _SESSION ['s ' ]['language ' ])) $ _SESSION ['s ' ]['language ' ] = $ conf ['language ' ];
77- }
78-
79- $ this ->uses ('auth ' );
80- }
81-
82- public function uses ($ classes )
44+ public function __construct ()
8345 {
46+ global $ conf ;
47+ $ this ->_conf = $ conf ;
48+ if ($ this ->_conf ['start_db ' ] == true ) {
49+ $ this ->load ('db_ ' .$ this ->_conf ['db_type ' ]);
50+ $ this ->db = new db ;
51+ }
52+
53+ //* Start the session
54+ if ($ this ->_conf ['start_session ' ] == true ) {
55+ session_start ();
56+
57+ //* Initialize session variables
58+ if (!isset ($ _SESSION ['s ' ]['id ' ]) ) $ _SESSION ['s ' ]['id ' ] = session_id ();
59+ if (empty ($ _SESSION ['s ' ]['theme ' ])) $ _SESSION ['s ' ]['theme ' ] = $ conf ['theme ' ];
60+ if (empty ($ _SESSION ['s ' ]['language ' ])) $ _SESSION ['s ' ]['language ' ] = $ conf ['language ' ];
61+ }
62+
63+ $ this ->uses ('auth ' );
64+ }
65+
66+ public function uses ($ classes )
67+ {
8468 $ cl = explode (', ' , $ classes );
85- if (is_array ($ cl )) {
86- foreach ($ cl as $ classname ){
87- $ classname = trim ($ classname );
69+ if (is_array ($ cl )) {
70+ foreach ($ cl as $ classname ){
71+ $ classname = trim ($ classname );
8872 //* Class is not loaded so load it
89- if (!array_key_exists ($ classname , $ this ->_loaded_classes )){
90- include_once (ISPC_CLASS_PATH ."/ $ classname.inc.php " );
91- $ this ->$ classname = new $ classname ();
92- $ this ->_loaded_classes [$ classname ] = true ;
93- }
94- }
95- }
96- }
97-
98- public function load ($ files )
99- {
100- $ fl = explode (', ' , $ files );
101- if (is_array ($ fl )) {
102- foreach ($ fl as $ file ){
103- $ file = trim ($ file );
104- include_once (ISPC_CLASS_PATH ."/ $ file.inc.php " );
105- }
106- }
107- }
108-
109- /** Priority values are: 0 = DEBUG, 1 = WARNING, 2 = ERROR */
110- public function log ($ msg , $ priority = 0 )
111- {
112- if ($ priority >= $ this ->_conf ['log_priority ' ]) {
113- if (is_writable ($ this ->_conf ['log_file ' ])) {
114- if (!$ fp = fopen ($ this ->_conf ['log_file ' ], 'a ' )) {
115- $ this ->error ('Unable to open logfile. ' );
116- }
117- if (!fwrite ($ fp , date ('d.m.Y-H:i ' ).' - ' . $ msg ."\r\n" )) {
118- $ this ->error ('Unable to write to logfile. ' );
119- }
120- fclose ($ fp );
121- } else {
122- $ this ->error ('Unable to write to logfile. ' );
123- }
124- }
125- }
73+ if (!array_key_exists ($ classname , $ this ->_loaded_classes )){
74+ include_once (ISPC_CLASS_PATH ."/ $ classname.inc.php " );
75+ $ this ->$ classname = new $ classname ();
76+ $ this ->_loaded_classes [$ classname ] = true ;
77+ }
78+ }
79+ }
80+ }
81+
82+ public function load ($ files )
83+ {
84+ $ fl = explode (', ' , $ files );
85+ if (is_array ($ fl )) {
86+ foreach ($ fl as $ file ){
87+ $ file = trim ($ file );
88+ include_once (ISPC_CLASS_PATH ."/ $ file.inc.php " );
89+ }
90+ }
91+ }
92+
93+ /** Priority values are: 0 = DEBUG, 1 = WARNING, 2 = ERROR */
94+ public function log ($ msg , $ priority = 0 )
95+ {
96+ if ($ priority >= $ this ->_conf ['log_priority ' ]) {
97+ if (is_writable ($ this ->_conf ['log_file ' ])) {
98+ if (!$ fp = fopen ($ this ->_conf ['log_file ' ], 'a ' )) {
99+ $ this ->error ('Unable to open logfile. ' );
100+ }
101+ if (!fwrite ($ fp , date ('d.m.Y-H:i ' ).' - ' . $ msg ."\r\n" )) {
102+ $ this ->error ('Unable to write to logfile. ' );
103+ }
104+ fclose ($ fp );
105+ } else {
106+ $ this ->error ('Unable to write to logfile. ' );
107+ }
108+ }
109+ }
126110
127111 /** Priority values are: 0 = DEBUG, 1 = WARNING, 2 = ERROR */
128- public function error ($ msg , $ next_link = '' , $ stop = true , $ priority = 1 )
112+ public function error ($ msg , $ next_link = '' , $ stop = true , $ priority = 1 )
129113 {
130- //$this->uses("error");
131- //$this->error->message($msg, $priority);
132- if ($ stop == true ){
133- $ msg = '<html>
114+ //$this->uses("error");
115+ //$this->error->message($msg, $priority);
116+ if ($ stop == true ){
117+ $ msg = '<html>
134118<head>
135119<title>Error</title>
136120<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
@@ -141,65 +125,65 @@ public function error($msg, $next_link = '', $stop = true, $priority = 1)
141125<table width="100%" border="0" cellspacing="0" cellpadding="2">
142126<tr>
143127<td class="error"><b>Error:</b><br> ' .$ msg ;
144- if ($ next_link != '' ) $ msg .= '<a href=" ' .$ next_link .'">Next</a><br> ' ;
145- $ msg .= '</td>
128+ if ($ next_link != '' ) $ msg .= '<a href=" ' .$ next_link .'">Next</a><br> ' ;
129+ $ msg .= '</td>
146130</tr>
147131</table>
148132</body>
149133</html> ' ;
150- die ($ msg );
151- } else {
152- echo $ msg ;
153- if ($ next_link != '' ) echo "<a href=' $ next_link'>Next</a> " ;
154- }
155- }
134+ die ($ msg );
135+ } else {
136+ echo $ msg ;
137+ if ($ next_link != '' ) echo "<a href=' $ next_link'>Next</a> " ;
138+ }
139+ }
156140
157141 /** Loads language */
158142 public function lng ($ text )
159143 {
160- if ($ this ->_language_inc != 1 ) {
161- //* loading global and module Wordbook
144+ if ($ this ->_language_inc != 1 ) {
145+ //* loading global and module Wordbook
162146 // TODO: this need to be made clearer somehow - pedro
163- @include_once (ISPC_ROOT_PATH .'/lib/lang/ ' .$ _SESSION ['s ' ]['language ' ].'.lng ' );
164- @include_once (ISPC_ROOT_PATH .'/web/ ' .$ _SESSION ['s ' ]['module ' ]['name ' ].'/lib/lang/ ' .$ _SESSION ['s ' ]['language ' ].'.lng ' );
165- $ this ->_wb = $ wb ;
166- $ this ->_language_inc = 1 ;
167- }
168- if (!empty ($ this ->_wb [$ text ])) {
169- $ text = $ this ->_wb [$ text ];
170- }
171- return $ text ;
172- }
147+ @include_once (ISPC_ROOT_PATH .'/lib/lang/ ' .$ _SESSION ['s ' ]['language ' ].'.lng ' );
148+ @include_once (ISPC_ROOT_PATH .'/web/ ' .$ _SESSION ['s ' ]['module ' ]['name ' ].'/lib/lang/ ' .$ _SESSION ['s ' ]['language ' ].'.lng ' );
149+ $ this ->_wb = $ wb ;
150+ $ this ->_language_inc = 1 ;
151+ }
152+ if (!empty ($ this ->_wb [$ text ])) {
153+ $ text = $ this ->_wb [$ text ];
154+ }
155+ return $ text ;
156+ }
173157
174158 public function tpl_defaults ()
175- {
176- $ this ->tpl ->setVar ('app_title ' , $ this ->_conf ['app_title ' ]);
177- $ this ->tpl ->setVar ('app_version ' , $ this ->_conf ['app_version ' ]);
178- $ this ->tpl ->setVar ('app_link ' , $ this ->_conf ['app_link ' ]);
179- if (isset ($ this ->_conf ['app_logo ' ]) && $ this ->_conf ['app_logo ' ] != '' && @is_file ($ this ->_conf ['app_logo ' ])){
180- $ this ->tpl ->setVar ('app_logo ' , '<img src=" ' .$ this ->_conf ['app_logo ' ].'"> ' );
181- } else {
182- $ this ->tpl ->setVar ('app_logo ' , ' ' );
183- }
184-
185- $ this ->tpl ->setVar ('phpsessid ' , session_id ());
186-
187- $ this ->tpl ->setVar ('theme ' , $ _SESSION ['s ' ]['theme ' ]);
188- $ this ->tpl ->setVar ('html_content_encoding ' , $ this ->_conf ['html_content_encoding ' ]);
189-
190- $ this ->tpl ->setVar ('delete_confirmation ' , $ this ->lng ('delete_confirmation ' ));
159+ {
160+ $ this ->tpl ->setVar ('app_title ' , $ this ->_conf ['app_title ' ]);
161+ $ this ->tpl ->setVar ('app_version ' , $ this ->_conf ['app_version ' ]);
162+ $ this ->tpl ->setVar ('app_link ' , $ this ->_conf ['app_link ' ]);
163+ if (isset ($ this ->_conf ['app_logo ' ]) && $ this ->_conf ['app_logo ' ] != '' && @is_file ($ this ->_conf ['app_logo ' ])){
164+ $ this ->tpl ->setVar ('app_logo ' , '<img src=" ' .$ this ->_conf ['app_logo ' ].'"> ' );
165+ } else {
166+ $ this ->tpl ->setVar ('app_logo ' , ' ' );
167+ }
168+
169+ $ this ->tpl ->setVar ('phpsessid ' , session_id ());
170+
171+ $ this ->tpl ->setVar ('theme ' , $ _SESSION ['s ' ]['theme ' ]);
172+ $ this ->tpl ->setVar ('html_content_encoding ' , $ this ->_conf ['html_content_encoding ' ]);
173+
174+ $ this ->tpl ->setVar ('delete_confirmation ' , $ this ->lng ('delete_confirmation ' ));
191175 //print_r($_SESSION);
192- if (isset ($ _SESSION ['s ' ]['module ' ]['name ' ])) {
193- $ this ->tpl ->setVar ('app_module ' , $ _SESSION ['s ' ]['module ' ]['name ' ]);
194- }
195- if (isset ($ _SESSION ['s ' ]['user ' ]) && $ _SESSION ['s ' ]['user ' ]['typ ' ] == 'admin ' ) {
196- $ this ->tpl ->setVar ('is_admin ' , 1 );
197- }
198- if (isset ($ _SESSION ['s ' ]['user ' ]) && $ this ->auth ->has_clients ($ _SESSION ['s ' ]['user ' ]['userid ' ])) {
199- $ this ->tpl ->setVar ('is_reseller ' , 1 );
200- }
176+ if (isset ($ _SESSION ['s ' ]['module ' ]['name ' ])) {
177+ $ this ->tpl ->setVar ('app_module ' , $ _SESSION ['s ' ]['module ' ]['name ' ]);
178+ }
179+ if (isset ($ _SESSION ['s ' ]['user ' ]) && $ _SESSION ['s ' ]['user ' ]['typ ' ] == 'admin ' ) {
180+ $ this ->tpl ->setVar ('is_admin ' , 1 );
181+ }
182+ if (isset ($ _SESSION ['s ' ]['user ' ]) && $ this ->auth ->has_clients ($ _SESSION ['s ' ]['user ' ]['userid ' ])) {
183+ $ this ->tpl ->setVar ('is_reseller ' , 1 );
184+ }
201185 }
202-
186+
203187} // end class
204188
205189//** Initialize application (app) object
0 commit comments