forked from hernad/F18
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathF18.prg
426 lines (310 loc) · 11.5 KB
/
F18.prg
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
/*
* This file is part of the bring.out knowhow ERP, a free and open source
* Enterprise Resource Planning software suite,
* Copyright (c) 1994-2018 by bring.out doo Sarajevo.
* It is licensed to you under the Common Public Attribution License
* version 1.0, the full text of which (including FMK specific Exhibits)
* is available in the file LICENSE_CPAL_bring.out_knowhow.md located at the
* root directory of this source code archive.
* By using this software, you agree to be bound by its terms.
*/
#include "f18.ch"
#include "f18_color.ch"
STATIC __relogin_opt := .F.
STATIC s_hF18Params := NIL
FUNCTION set_f18_param( cKey, xValue )
s_hF18Params[ cKey ] := xValue
RETURN s_hF18Params[ cKey ]
FUNCTION get_f18_param( cKey )
IF s_hF18Params == NIL
return "<undefined>"
ENDIF
IF !hb_hHasKey( s_hF18Params, cKey)
return "<undefined>"
ENDIF
RETURN s_hF18Params[ cKey ]
FUNCTION is_f18_db_params_set()
RETURN hb_hHasKey( s_hF18Params, "password" ) .AND. hb_hHasKey( s_hF18Params, "user" ) .AND. hb_hHasKey( s_hF18Params, "port" ) .AND. hb_hHasKey( s_hF18Params, "database" ) .AND. ;
hb_hHasKey( s_hF18Params, "host" )
STATIC FUNCTION to_run_f18_module()
RETURN hb_hHasKey( s_hF18Params, "run" )
#ifndef TEST
FUNCTION Main(...)
IF s_hF18Params == NIL
s_hF18Params := init_f18_params(...)
ENDIF
//set_f18_params( p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11 )
set_f18_params(...)
IF to_run_f18_module()
run_module()
ELSE
harbour_init()
init_parameters_cache()
set_f18_current_directory()
set_f18_home_root()
set_global_vars_0()
f18_error_block()
set_screen_dimensions()
naslovni_ekran_splash_screen( "F18", f18_ver() )
IF no_sql_mode()
set_f18_home( "f18_test" )
RETURN .T.
ENDIF
f18_login_loop(NIL)
ENDIF
RETURN .T.
#endif
FUNCTION f18_login_loop(lAutoConnect)
LOCAL oLogin
IF lAutoConnect == NIL
lAutoConnect := .T.
ENDIF
oLogin := my_login()
DO WHILE .T.
oLogin:postgres_db_login( lAutoConnect )
IF !oLogin:lPostgresDbSpojena
QUIT_1
ELSE
lAutoConnect := .T.
ENDIF
IF !oLogin:odabir_organizacije()
IF fetch_metric_error() > 0
MsgBeep( "fetch metric error ?! : Cnt: " + AllTrim( Str( fetch_metric_error() ) ) )
RETURN .F.
ENDIF
IF LastKey() == K_ESC
RETURN .F.
ENDIF
ELSE
// IF oLogin:lOrganizacijaSpojena
// show_sacekaj()
// oLogin:disconnect_postgresql()
oLogin:disconnect_user_database()
IF oLogin:connect_user_database()
f18_programski_moduli_meni()
ELSE
MsgBeep( "Spajanje na bazu traženog preduzeća/organizacije neuspješno !?" )
ENDIF
// ENDIF
ENDIF
ENDDO
RETURN .T.
PROCEDURE f18_http_server()
LOCAL oLogAccess, oLogError, nPort, oServer
DO WHILE !open_thread( "f18_http_server" )
?E "ERRO open_thread f18_http_server"
ENDDO
oLogAccess := UHttpdLog():New( "f18_access.log" )
IF ! oLogAccess:Add( "" )
oLogAccess:Close()
? "Access log file open error", hb_ntos( FError() )
RETURN
ENDIF
oLogError := UHttpdLog():New( "f18_error.log" )
IF ! oLogError:Add( "" )
oLogError:Close()
oLogAccess:Close()
? "Error log file open error", hb_ntos( FError() )
RETURN
ENDIF
? "Listening on port:", nPort := 8080
oServer := UHttpdNew()
// "PrivateKeyFilename" => _FN_PKEY, ;
// "CertificateFilename" => _FN_CERT, ;
// "SSL" => .T., ;
IF ! oServer:Run( { ;
"FirewallFilter" => "", ;
"LogAccess" => {| m | oLogAccess:Add( m + hb_eol() ) }, ;
"LogError" => {| m | oLogError:Add( m + hb_eol() ) }, ;
"Trace" => {| ... | QOut( ... ) }, ;
"Port" => nPort, ;
"Idle" => {| o | iif( hb_vfExists( ".uhttpd.stop" ), ( hb_vfErase( ".uhttpd.stop" ), o:Stop() ), NIL ) }, ;
"Mount" => { ;
"/hello" => {|| UWrite( "Hello!" ) }, ;
"/info" => {|| UProcInfo() }, ;
"/files/*" => {| x | QOut( hb_DirBase() + "files/" + X ), UProcFiles( hb_DirBase() + "files/" + X, .F. ) }, ;
"/" => {|| URedirect( "/hello" ) } ;
} ;
} )
oLogError:Close()
oLogAccess:Close()
? "Server error:", oServer:cError
ErrorLevel( 1 )
RETURN
ENDIF
oLogError:Close()
oLogAccess:Close()
close_thread( "f18_http_server" )
RETURN
/*
vraca hash matricu sa parametrima
*/
STATIC FUNCTION init_f18_params(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11)
LOCAL nI := 2
LOCAL xParam
LOCAL nCount := 0
hParams := hb_Hash()
hParams[ "p1" ] := NIL
hParams[ "p2" ] := NIL
hParams[ "p3" ] := NIL
hParams[ "p4" ] := NIL
hParams[ "p5" ] := NIL
hParams[ "p6" ] := NIL
hParams[ "p7" ] := NIL
hParams[ "p8" ] := NIL
hParams[ "p9" ] := NIL
hParams[ "p10" ] := NIL
hParams[ "p11" ] := NIL
DO WHILE nI <= PCount()
xParam := hb_PValue( nI++ ) // ucitaj parametar
hParams[ "p" + AllTrim( Str( ++nCount ) ) ] := xParam // p1, p2, p3...
ENDDO
RETURN hParams
FUNCTION f18_programski_moduli_meni()
LOCAL aMeniOpcije := {}
LOCAL aMeniExec := {}
LOCAL nMeniIzbor
LOCAL mnu_left := 2
LOCAL mnu_top := 5
LOCAL mnu_bottom := 23
LOCAL mnu_right := 65
LOCAL nX := 1
LOCAL hDbParams
LOCAL _count := 0
// LOCAL oBackup := F18Backup():New()
LOCAL _user_roles := f18_user_roles_info()
LOCAL cServerDbVersion
LOCAL _tmp
LOCAL cOldColors
// info_bar( "init", "gen f18_programski_moduli_meni start" )
// IF hProgramArgumenti == NIL
// cre_arg_v_hash( @hProgramArgumenti ) // napravi NIL parametre
//ENDIF
DO WHILE .T.
cOldColors := SetColor( F18_COLOR_ORGANIZACIJA )
cServerDbVersion := get_version_str( server_db_version( .T. ) )
++_count
CLEAR SCREEN
hDbParams := my_server_params()
nX := 1
@ nX, mnu_left + 1 SAY8 "Tekuća baza: " + AllTrim( hDbParams[ "database" ] ) + " / db ver: " + cServerDbVersion + " / nivo log: " + AllTrim( Str( log_level() ) )
++nX
@ nX, mnu_left + 1 SAY " Korisnik: " + AllTrim( hDbParams[ "user" ] ) + " gr: " + _user_roles + " VER: " + f18_ver()
++nX
@ nX, mnu_left SAY Replicate( "-", 55 )
// IF _count == 1 .OR. __relogin_opt // backup okidamo samo na prvom ulasku ili na opciji relogina
// IF oBackup:locked( .F. ) // provjera da li je backup locked ?
// oBackup:unlock()
// ENDIF
// f18_auto_backup_data( 1 ) // automatski backup podataka preduzeca
// __relogin_opt := .F.
// ENDIF
aMeniOpcije := {}
aMeniExec := {}
set_program_module_menu( @aMeniOpcije, @aMeniExec, get_f18_param("p3"), get_f18_param("p4"), get_f18_param("p5"), get_f18_param("p6"), get_f18_param("p7") )
// info_bar( "init", "gen f18_programski_moduli_meni end" )
nMeniIzbor := meni_0_inkey( mnu_top, mnu_left, mnu_bottom, mnu_right, aMeniOpcije, 1 )
SetColor( cOldColors )
DO CASE
CASE nMeniIzbor == 0
// IF !oBackup:locked
EXIT
// ELSE
// MsgBeep( oBackup:backup_in_progress_info() )
// ENDIF
CASE nMeniIzbor > 0
IF nMeniIzbor <= Len( aMeniExec )
Eval( aMeniExec[ nMeniIzbor ] )
ENDIF
ENDCASE
LOOP
ENDDO
// info_bar( hDbParams[ "database" ], "f18_programski_moduli_meni end" )
RETURN .T.
STATIC FUNCTION set_program_module_menu( aMeniOpcije, aMeniExec, p3, p4, p5, p6, p7 )
LOCAL _count := 0
LOCAL cMenuBrojac
LOCAL cVersion
#ifndef F18_DEBUG
IF f18_preporuci_upgrade( @cVersion )
AAdd( aMeniOpcije, " U. F18 upgrade -> " + cVersion )
AAdd( aMeniExec, {|| F18Admin():update_app(), .T. } )
AAdd( aMeniOpcije, "---------------------------------------------" )
AAdd( aMeniExec, {|| NIL } )
ENDIF
#endif
IF f18_use_module( "fin" )
cMenuBrojac := PadL( AllTrim( Str( ++_count ) ), 2 )
AAdd( aMeniOpcije, cMenuBrojac + ". FIN # finansijsko poslovanje " )
AAdd( aMeniExec, {|| MainFin( my_user(), "dummy", p3, p4, p5, p6, p7 ) } )
ENDIF
IF f18_use_module( "kalk" )
cMenuBrojac := PadL( AllTrim( Str( ++_count ) ), 2 )
AAdd( aMeniOpcije, cMenuBrojac + ". KALK # robno-materijalno poslovanje" )
AAdd( aMeniExec, {|| MainKalk( my_user(), "dummy", p3, p4, p5, p6, p7 ) } )
ENDIF
IF f18_use_module( "fakt" )
cMenuBrojac := PadL( AllTrim( Str( ++_count ) ), 2 )
AAdd( aMeniOpcije, cMenuBrojac + ". FAKT # fakturisanje" )
AAdd( aMeniExec, {|| MainFakt( my_user(), "dummy", p3, p4, p5, p6, p7 ) } )
ENDIF
IF f18_use_module( "epdv" )
cMenuBrojac := PadL( AllTrim( Str( ++_count ) ), 2 )
AAdd( aMeniOpcije, cMenuBrojac + ". ePDV # elektronska evidencija PDV-a" )
AAdd( aMeniExec, {|| MainEpdv( my_user(), "dummy", p3, p4, p5, p6, p7 ) } )
ENDIF
IF f18_use_module( "ld" )
cMenuBrojac := PadL( AllTrim( Str( ++_count ) ), 2 )
AAdd( aMeniOpcije, cMenuBrojac + ". LD # obračun plata" )
AAdd( aMeniExec, {|| MainLd( my_user(), "dummy", p3, p4, p5, p6, p7 ) } )
ENDIF
IF f18_use_module( "os" )
cMenuBrojac := PadL( AllTrim( Str( ++_count ) ), 2 )
AAdd( aMeniOpcije, cMenuBrojac + ". OS/SII# osnovna sredstva i sitan inventar" )
AAdd( aMeniExec, {|| MainOs( my_user(), "dummy", p3, p4, p5, p6, p7 ) } )
ENDIF
IF f18_use_module( "virm" )
cMenuBrojac := PadL( AllTrim( Str( ++_count ) ), 2 )
AAdd( aMeniOpcije, cMenuBrojac + ". VIRM # virmani" )
AAdd( aMeniExec, {|| MainVirm( my_user(), "dummy", p3, p4, p5, p6, p7 ) } )
ENDIF
#ifdef F18_RNAL
IF f18_use_module( "rnal" )
cMenuBrojac := PadL( AllTrim( Str( ++_count ) ), 2 )
AAdd( aMeniOpcije, cMenuBrojac + ". RNAL # radni nalozi" )
AAdd( aMeniExec, {|| MainRnal( my_user(), "dummy", p3, p4, p5, p6, p7 ) } )
ENDIF
#endif
#ifdef F18_POS
IF f18_use_module( "pos" )
cMenuBrojac := PadL( AllTrim( Str( ++_count ) ), 2 )
AAdd( aMeniOpcije, cMenuBrojac + ". POS # maloprodajna kasa" )
AAdd( aMeniExec, {|| MainPos( my_user(), "dummy", p3, p4, p5, p6, p7 ) } )
ENDIF
#endif
#ifdef F18_MAT
IF f18_use_module( "mat" )
cMenuBrojac := PadL( AllTrim( Str( ++_count ) ), 2 )
AAdd( aMeniOpcije, cMenuBrojac + ". MAT # materijalno" )
AAdd( aMeniExec, {|| MainMat( my_user(), "dummy", p3, p4, p5, p6, p7 ) } )
ENDIF
#endif
AAdd( aMeniOpcije, "---------------------------------------------" )
AAdd( aMeniExec, {|| NIL } )
AAdd( aMeniOpcije, " S. promjena sezone" )
AAdd( aMeniExec, {|| f18_promjena_sezone() } )
AAdd( aMeniOpcije, " B. backup podataka" )
AAdd( aMeniExec, {|| f18_backup_now() } )
// AAdd( aMeniOpcije, " U. upgrade (nadogradnja) aplikacije" )
// AAdd( aMeniExec, {|| f18_update_available_version(), F18Admin():update_app() } )
AAdd( aMeniOpcije, " P. parametri aplikacije" )
AAdd( aMeniExec, {|| set_parametre_f18_aplikacije() } )
AAdd( aMeniOpcije, " W. pregled log-a" )
AAdd( aMeniExec, {|| f18_view_log() } )
// AAdd( aMeniOpcije, " V. vpn podrška" )
// AAdd( aMeniExec, {|| vpn_support() } )
AAdd( aMeniOpcije, " X. diag info" )
AAdd( aMeniExec, {|| diag_info() } )
RETURN .T.
FUNCTION hb_SendMail( ... )
RETURN tip_MailSend( ... )