-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgs_ui_user.cpp
2054 lines (1647 loc) · 60.6 KB
/
gs_ui_user.cpp
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
// Class_login.cpp : implementation file
//
#include "stdafx.h"
#define INITGUID
#import "msado15.dll" no_namespace rename ("EOF", "EndOfFile") rename ("EOS", "ADOEOS")
#include "resource.h"
#include "afxdialogex.h"
#include "gs_error.h"
#include "gs_utily.h"
#include "gs_init.h"
#include "gs_user.h"
#include "GEOUIAppl.h"
#include "gs_ui_user.h"
#include "gs_ui_utily.h"
#include "ValuesListDlg.h"
#include "d2hMap.h" // doc to help
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/*********************************************************/
/*.doc gsc_ui_copyFromUserToUser <internal> */
/*+
Questa funzione copia le abilitazioni da un utnete all'altro.
Parametri:
int SourceUserCode; codice utente sorgente
int DestUserCode; codice utente destinazione
Restituisce GS_GOOD in caso di successo altrimenti GS_BAD.
-*/
/*********************************************************/
int gsc_ui_copyFromUserToUser(int SourceUserCode, int DestUserCode)
{
C_INT_LIST Commands;
C_INT_INT_LIST ProjectsPermissionList, ClassesPermissionList;
C_4INT_STR_LIST SecTabsPermissionList;
C_INT_INT *pPrj;
if (gsc_getusrcomm(SourceUserCode, &Commands) == GS_BAD ||
gsc_setusrcomm(DestUserCode, &Commands) == GS_BAD)
{
gsui_alert(_T("Abilitazione ai comandi non copiata."));
return GS_BAD;
}
if (gsc_getPersonalPrjPermissions(SourceUserCode, &ProjectsPermissionList) == GS_BAD ||
gsc_setPersonalPrjPermissions(DestUserCode, ProjectsPermissionList) == GS_BAD)
{
gsui_alert(_T("Abilitazione ai progetti non copiata."));
return GS_BAD;
}
pPrj = (C_INT_INT *) ProjectsPermissionList.get_head();
while (pPrj)
{
if (gsc_getPersonalClassPermissions(SourceUserCode, pPrj->get_key(), &ClassesPermissionList) == GS_BAD ||
gsc_setPersonalClassPermissions(DestUserCode, pPrj->get_key(), ClassesPermissionList) == GS_BAD)
{
gsui_alert(_T("Abilitazione alle classi non copiata."));
return GS_BAD;
}
pPrj = (C_INT_INT *) ProjectsPermissionList.get_next();
}
pPrj = (C_INT_INT *) ProjectsPermissionList.get_head();
while (pPrj)
{
if (gsc_getPersonalSecPermissions(SourceUserCode, pPrj->get_key(), &SecTabsPermissionList) == GS_BAD ||
gsc_setPersonalSecPermissions(DestUserCode, pPrj->get_key(), SecTabsPermissionList) == GS_BAD)
{
gsui_alert(_T("Abilitazione alle tabelle secondarie non copiata."));
return GS_BAD;
}
pPrj = (C_INT_INT *) ProjectsPermissionList.get_next();
}
return GS_GOOD;
}
/////////////////////////////////////////////////////////////////////////////
// CClass_login dialog
CClass_login::CClass_login(CWnd* pParent /*=NULL*/)
: CDialog(CClass_login::IDD, pParent)
{
//{{AFX_DATA_INIT(CClass_login)
//}}AFX_DATA_INIT
DefID = 0;
}
void CClass_login::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CClass_login)
DDX_Control(pDX, IDC_IMAGE, m_image);
DDX_Control(pDX, IDC_STATIC_MSG, m_label_msg);
DDX_Control(pDX, IDC_STATIC_LOGIN, m_label_login);
DDX_Control(pDX, IDC_PASSWORD, m_password);
DDX_Control(pDX, IDC_LOGIN, m_login);
DDX_Control(pDX, IDC_ANIMATE1, m_animate);
DDX_Control(pDX, IDC_CHECK_SESSION, m_check_session);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CClass_login, CDialog)
//{{AFX_MSG_MAP(CClass_login)
ON_BN_CLICKED(IDHELP, OnHelp)
ON_WM_SHOWWINDOW()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CClass_login message handlers
BOOL CClass_login::OnInitDialog()
{
C_STRING Path(get_WORKDIR());
CDialog::OnInitDialog();
if (m_msg_for_password_only.GetLength() > 0)
{ // Richiesta di conferma tramite autentificazione
m_label_msg.ShowWindow(SW_SHOWNORMAL);
m_login.ShowWindow(SW_HIDE);
m_label_login.ShowWindow(SW_HIDE);
m_label_msg.SetWindowText(m_msg_for_password_only);
m_check_session.ShowWindow(SW_HIDE);
if (GetDlgItem(IDHELP))
((CButton *) GetDlgItem(IDHELP))->EnableWindow(FALSE);
}
else
{ // Login a GEOsim
TCHAR LastLogin[MAX_LEN_LOGIN] = _T("");
int Value = GS_GOOD;
if (gsc_getLastLogin(LastLogin) == GS_GOOD && wcslen(LastLogin) > 0)
m_login.SetWindowText(LastLogin);
gsc_getCheckSessionOnLogin(&Value);
m_check_session.SetCheck((Value == GS_GOOD) ? BST_CHECKED : BST_UNCHECKED);
}
Path += _T("\\");
Path += GEOUI_PATH;
Path += _T("\\WORLD.AVI");
m_animate.Open(Path.get_name());
if (DefID != 0) SetDefID(DefID);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CClass_login::OnHelp()
{
gsc_help(IDH_ACCESSOALLEFUNZIONALITDIGEOSIM);
}
void CClass_login::OnOK()
{
HCURSOR PrevCrs;
m_password.GetWindowText(_password);
if (m_msg_for_password_only.GetLength() > 0)
{
// verifico che la password sia corretta
if (get_CURRENT_USER() &&
gsc_strcmp(_password, get_CURRENT_USER()->pwd) == 0)
CDialog::OnOK();
else
gsui_alert(_T("Identificazione utente fallita."), m_hWnd);
return;
}
PrevCrs = GetCursor();
SetCursor(LoadCursor(NULL, IDC_WAIT));
try
{
CString _login;
int FlagCheckSession;
m_login.GetWindowText(_login);
FlagCheckSession = (m_check_session.GetCheck() == 0) ? GS_BAD : GS_GOOD;
if (gsc_login(LPCTSTR(_login), LPCTSTR(_password), FlagCheckSession) == GS_BAD)
{
gsui_alert(_T("Identificazione utente fallita."), m_hWnd);
AfxThrowUserException();
}
CDialog::OnOK();
}
catch (...) // any type of exception
{}
SetCursor(PrevCrs);
}
void CClass_login::OnShowWindow(BOOL bShow, UINT nStatus)
{
CDialog::OnShowWindow(bShow, nStatus);
if (m_msg_for_password_only.GetLength() == 0)
{
CString _login;
m_login.GetWindowText(_login);
if (_login.GetLength() > 0) // login già impostata
m_password.SetFocus();
}
/////////////////////////////////////////////////////
HBITMAP hBmp;
COLORREF crFrom;
HINSTANCE Instance;
crFrom = RGB(255, 0, 0); // rosso
// determine location of the bitmap in resource fork
Instance = AfxFindResourceHandle(MAKEINTRESOURCE(IDB_KEYS), RT_BITMAP);
hBmp = LoadBitmap(Instance, MAKEINTRESOURCE(IDB_KEYS));
if (gsui_SetBmpColorToDlgBkColor(hBmp, crFrom))
m_image.SetBitmap(hBmp);
}
/*************************************************************************/
/*.doc gsui_login */
/*+
Comando per identificazione utente GEOsim.
La funzione restituisce GS_GOOD in caso di successo altrimenti GS_BAD.
-*/
/*************************************************************************/
int gsui_login(void)
{
// When resource from this ARX app is needed, just
// instantiate a local CAcModuleResourceOverride
CAcModuleResourceOverride myResources;
CClass_login class_login_dialog;
acedRetVoid();
if (get_GS_CURRENT_WRK_SESSION())
{ set_GS_ERR_COD(eGSSessionsFound); return GS_BAD; }
//class_login_dialog.m_msg_for_password_only = "Inserire la propria password per confermare l'operazione.";
class_login_dialog.DoModal();
return GS_GOOD;
}
///////////////////////////////////////////////////////////////////////////////
// FINE LOGIN
// INIZIO CREAZIONE UTENTE
///////////////////////////////////////////////////////////////////////////////
// finestra di dialogo C_CreateUsrDlg
IMPLEMENT_DYNAMIC(C_CreateUsrDlg, CDialog)
C_CreateUsrDlg::C_CreateUsrDlg(CWnd* pParent /*=NULL*/)
: CDialog(C_CreateUsrDlg::IDD, pParent)
, m_UsrLevel(NORMALUSR)
{
}
C_CreateUsrDlg::~C_CreateUsrDlg()
{
}
void C_CreateUsrDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_USR_NAME, m_UsrName);
DDX_Control(pDX, IDC_USR_PWD1, m_UsrPwd);
DDX_Control(pDX, IDC_USR_PWD2, m_ConfirmUsrPwd);
DDX_Control(pDX, IDC_PERMISSION_FROM_USR_CHECK, m_CopyFromUsr);
DDX_Control(pDX, IDC_USRLIST, m_UsrList);
DDX_Radio(pDX, IDC_SUPERUSER_RADIO, m_UsrLevel);
DDX_Control(pDX, IDC_IMAGE, m_image);
}
BEGIN_MESSAGE_MAP(C_CreateUsrDlg, CDialog)
ON_BN_CLICKED(IDC_SUPERUSER_RADIO, &C_CreateUsrDlg::OnBnClickedSuperuserRadio)
ON_BN_CLICKED(IDC_USER_RADIO, &C_CreateUsrDlg::OnBnClickeduserRadio)
ON_BN_CLICKED(IDC_PERMISSION_FROM_USR_CHECK, &C_CreateUsrDlg::OnBnClickedPermissionFromUsrCheck)
ON_BN_CLICKED(IDOK, &C_CreateUsrDlg::OnBnClickedOk)
ON_BN_CLICKED(IDHELP, &C_CreateUsrDlg::OnBnClickedHelp)
END_MESSAGE_MAP()
// gestori di messaggi C_CreateUsrDlg
BOOL C_CreateUsrDlg::OnInitDialog()
{
CDialog::OnInitDialog();
if (gsc_getusrlist(&UsrList) == GS_GOOD)
{
C_INT_INT_STR *pUsr = (C_INT_INT_STR *) UsrList.get_head();
while (pUsr)
{
if (pUsr->get_type() == 1) m_UsrList.AddString(pUsr->get_name()); // solo utenti normali
pUsr = (C_INT_INT_STR *) UsrList.get_next();
}
}
m_UsrLevel = NORMALUSR; // utente normale
UpdateData(FALSE); // per aggiornare i radio button
/////////////////////////////////////////////////////
HBITMAP hBmp;
COLORREF crFrom;
HINSTANCE Instance;
crFrom = RGB(255, 0, 0); // rosso
// determine location of the bitmap in resource fork
Instance = AfxFindResourceHandle(MAKEINTRESOURCE(IDB_KEYS), RT_BITMAP);
hBmp = LoadBitmap(Instance, MAKEINTRESOURCE(IDB_KEYS));
if (gsui_SetBmpColorToDlgBkColor(hBmp, crFrom))
m_image.SetBitmap(hBmp);
m_UsrList.EnableWindow(FALSE);
m_UsrName.SetFocus();
//Specifies whether the application has set the input focus to one of the controls in the dialog box.
//If OnInitDialog returns nonzero, Windows sets the input focus to the first control in the dialog box.
//The application can return 0 only if it has explicitly set the input focus to one of the controls
//in the dialog box.
return FALSE;
}
void C_CreateUsrDlg::OnBnClickedSuperuserRadio()
{
m_CopyFromUsr.EnableWindow(FALSE);
m_UsrList.EnableWindow(FALSE);
m_UsrLevel = SUPERUSR;
}
void C_CreateUsrDlg::OnBnClickeduserRadio()
{
m_CopyFromUsr.EnableWindow(TRUE);
if (m_CopyFromUsr.GetCheck() == BST_CHECKED)
m_UsrList.EnableWindow(TRUE);
m_UsrLevel = NORMALUSR;
}
void C_CreateUsrDlg::OnBnClickedPermissionFromUsrCheck()
{
if (m_CopyFromUsr.GetCheck() == BST_CHECKED)
m_UsrList.EnableWindow(TRUE);
else
m_UsrList.EnableWindow(FALSE);
}
void C_CreateUsrDlg::OnBnClickedOk()
{
CString _Login, _Pwd, _Pwd2;
int NewUserID;
m_UsrName.GetWindowText(_Login);
_Login.Trim();
if (_Login.GetLength() == 0)
{
gsui_alert(_T("Nome utente non valido."));
return;
}
m_UsrPwd.GetWindowText(_Pwd);
if (_Pwd.GetLength() == 0)
{
gsui_alert(_T("Password non valida."));
return;
}
m_ConfirmUsrPwd.GetWindowText(_Pwd2);
if (_Pwd.Compare(_Pwd2) != 0)
{
gsui_alert(_T("Password di conferma non valida."));
return;
}
if ((NewUserID = gsc_creausr(LPCTSTR(_Login), LPCTSTR(_Pwd), m_UsrLevel)) == 0)
{
gsui_alert(_T("Creazione utente fallita."));
return;
}
if (m_CopyFromUsr.GetCheck() == BST_CHECKED)
{
m_UsrList.GetWindowText(_Login);
if (_Login.GetLength() > 0)
{
C_INT_INT_STR *pUsr = (C_INT_INT_STR *) UsrList.search_name(LPCTSTR(_Login));
if (!pUsr)
{
gsui_alert(_T("Utente da cui copiare le abilitazioni non trovato."));
return;
}
if (gsc_ui_copyFromUserToUser(pUsr->get_key(), NewUserID) != GS_GOOD)
return;
}
}
CDialog::OnOK();
}
void C_CreateUsrDlg::OnBnClickedHelp()
{
gsc_help(IDH_Creazioneutente);
}
/*************************************************************************/
/*.doc gsui_createusr */
/*+
Comando per creare un utente GEOsim.
La funzione restituisce GS_GOOD in caso di successo altrimenti GS_BAD.
-*/
/*************************************************************************/
int gsui_createusr(void)
{
// When resource from this ARX app is needed, just
// instantiate a local CAcModuleResourceOverride
CAcModuleResourceOverride myResources;
C_CreateUsrDlg CreateUsrDlg;
acedRetVoid();
if (gsc_superuser() == GS_BAD)
{
gsui_alert(_T("Comando disponibile solo a superutente"));
return GS_BAD;
}
if (CreateUsrDlg.DoModal() != IDOK) return GS_CAN;
return GS_GOOD;
}
///////////////////////////////////////////////////////////////////////////////
// FINE CREAZIONE UTENTE
// INIZIO MODIFICA PASSWORD UTENTE
///////////////////////////////////////////////////////////////////////////////
// finestra di dialogo C_ModiPwdUsrDlg
IMPLEMENT_DYNAMIC(C_ModiPwdUsrDlg, CDialog)
C_ModiPwdUsrDlg::C_ModiPwdUsrDlg(CWnd* pParent /*=NULL*/)
: CDialog(C_ModiPwdUsrDlg::IDD, pParent)
{
}
C_ModiPwdUsrDlg::~C_ModiPwdUsrDlg()
{
}
void C_ModiPwdUsrDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_USR_PWD1, m_UsrPwd);
DDX_Control(pDX, IDC_USR_PWD2, m_ConfirmUsrPwd);
DDX_Control(pDX, IDC_OLD_USR_PWD, m_OldUsrPwd);
DDX_Control(pDX, IDC_USR_NAME, m_UsrNameStatic);
DDX_Control(pDX, IDC_IMAGE, m_image);
}
BEGIN_MESSAGE_MAP(C_ModiPwdUsrDlg, CDialog)
ON_BN_CLICKED(IDOK, &C_ModiPwdUsrDlg::OnBnClickedOk)
ON_BN_CLICKED(IDHELP, &C_ModiPwdUsrDlg::OnBnClickedHelp)
END_MESSAGE_MAP()
// gestori di messaggi C_ModiPwdUsrDlg
BOOL C_ModiPwdUsrDlg::OnInitDialog()
{
C_INT_INT_STR Usr;
if (gsc_whoami(&Usr) == GS_BAD)
{
gsui_alert(_T("Utente corrente non esistente."));
return FALSE;
}
CDialog::OnInitDialog();
m_UsrNameStatic.SetWindowText(Usr.get_name());
/////////////////////////////////////////////////////
HBITMAP hBmp;
COLORREF crFrom;
HINSTANCE Instance;
crFrom = RGB(255, 0, 0); // rosso
// determine location of the bitmap in resource fork
Instance = AfxFindResourceHandle(MAKEINTRESOURCE(IDB_KEYS), RT_BITMAP);
hBmp = LoadBitmap(Instance, MAKEINTRESOURCE(IDB_KEYS));
if (gsui_SetBmpColorToDlgBkColor(hBmp, crFrom))
m_image.SetBitmap(hBmp);
return TRUE;
}
void C_ModiPwdUsrDlg::OnBnClickedOk()
{
CString _OldPwd, _Pwd, _Pwd2;
m_OldUsrPwd.GetWindowText(_OldPwd);
if (_OldPwd.GetLength() == 0)
{
gsui_alert(_T("Password non valida."));
return;
}
m_UsrPwd.GetWindowText(_Pwd);
if (_Pwd.GetLength() == 0)
{
gsui_alert(_T("Nuova password non valida."));
return;
}
m_ConfirmUsrPwd.GetWindowText(_Pwd2);
if (_Pwd.Compare(_Pwd2) != 0)
{
gsui_alert(_T("Password di conferma non valida."));
return;
}
if (gsc_modpwd(LPCTSTR(_OldPwd), LPCTSTR(_Pwd)) == GS_BAD)
{
gsui_alert(_T("Modifica password fallita."));
return;
}
CDialog::OnOK();
}
void C_ModiPwdUsrDlg::OnBnClickedHelp()
{
gsc_help(IDH_Modificapassword);
}
/*************************************************************************/
/*.doc gsui_modipwdcurrusr */
/*+
Comando per modificare la password dell'utente corrente GEOsim.
La funzione restituisce GS_GOOD in caso di successo altrimenti GS_BAD.
-*/
/*************************************************************************/
int gsui_modipwdcurrusr(void)
{
// When resource from this ARX app is needed, just
// instantiate a local CAcModuleResourceOverride
CAcModuleResourceOverride myResources;
C_ModiPwdUsrDlg ModiPwdUsrDlg;
acedRetVoid();
if (ModiPwdUsrDlg.DoModal() != IDOK) return GS_CAN;
return GS_GOOD;
}
///////////////////////////////////////////////////////////////////////////////
// FINE MODIFICA PASSWORD UTENTE
// INIZIO CANCELLAZIONE UTENTE
///////////////////////////////////////////////////////////////////////////////
/*************************************************************************/
/*.doc gsui_delusr */
/*+
Comando per cancellare un utente GEOsim.
La funzione restituisce GS_GOOD in caso di successo altrimenti GS_BAD.
-*/
/*************************************************************************/
int gsui_delusr(void)
{
// When resource from this ARX app is needed, just
// instantiate a local CAcModuleResourceOverride
CAcModuleResourceOverride myResources;
acedRetVoid();
CValuesListDlg ListDlg;
C_INT_INT_STR_LIST UsrList;
C_INT_INT_STR *pUsr;
C_STRING Msg;
int i;
if (gsc_superuser() == GS_BAD)
{
gsui_alert(_T("Comando disponibile solo a superutente"));
return GS_BAD;
}
ListDlg.m_Title = _T("GEOsim - Cancellazione utente");
ListDlg.m_Msg = _T("Scegli l'utente da cancellare:");
ListDlg.m_ColsHeader = _T("Nome utente");
ListDlg.m_SingleSel = TRUE;
ListDlg.m_OriginType = CValuesListDlg::RESBUF_LIST;
ListDlg.RbList << acutBuildList(RTLB, 0);
if (gsc_getusrlist(&UsrList) == GS_BAD) return GS_BAD;
UsrList.sort_name();
pUsr = (C_INT_INT_STR *) UsrList.get_head();
while (pUsr)
{
// non considero l'utente corrente
if (get_CURRENT_USER()->code != pUsr->get_key())
ListDlg.RbList += acutBuildList(RTLB, RTSTR, pUsr->get_name(), RTLE, 0);
pUsr = (C_INT_INT_STR *) UsrList.get_next();
}
ListDlg.RbList += acutBuildList(RTLE, 0);
if (ListDlg.DoModal() != IDOK || ListDlg.m_ValueList.get_count() != 1) return GS_CAN;
pUsr = (C_INT_INT_STR *) UsrList.get_head();
i = 0;
while (pUsr)
{
// non considero l'utente corrente
if (get_CURRENT_USER()->code != pUsr->get_key())
{
if (ListDlg.m_ValueList.get_head()->get_key() == i) break;
i++;
}
pUsr = (C_INT_INT_STR *) UsrList.get_next();
}
Msg = _T("Confermare la cancellazione dell'utente ");
Msg += pUsr->get_name();
Msg += _T(".");
if (gsui_confirm(Msg.get_name(), GS_BAD, TRUE , FALSE) == GS_GOOD)
if (gsc_delusr(pUsr->get_key(), get_CURRENT_USER()->pwd) != GS_GOOD)
{
gsui_alert(_T("Cancellazione utente fallita."));
return GS_BAD;
}
return GS_GOOD;
}
///////////////////////////////////////////////////////////////////////////////
// FINE CANCELLAZIONE UTENTE
// INIZIO MODIFICA PASSWORD UTENTE
///////////////////////////////////////////////////////////////////////////////
// finestra di dialogo C_ModUsrDlg
IMPLEMENT_DYNAMIC(C_ModUsrDlg, CDialogEx)
C_ModUsrDlg::C_ModUsrDlg(CWnd* pParent /*=NULL*/)
: CDialogEx(C_ModUsrDlg::IDD, pParent)
{
gsc_getusrlist(&UsrList);
m_CurrUsrId = 0;
Update = false;
}
C_ModUsrDlg::~C_ModUsrDlg()
{
C_INT_VOIDPTR *p;
p = (C_INT_VOIDPTR *) ClassesPermissionList.get_head();
while (p)
{
if (p->get_VoidPtr()) delete p->get_VoidPtr();
p = (C_INT_VOIDPTR *) ClassesPermissionList.get_next();
}
p = (C_INT_VOIDPTR *) SecTabsPermissionList.get_head();
while (p)
{
if (p->get_VoidPtr()) delete p->get_VoidPtr();
p = (C_INT_VOIDPTR *) SecTabsPermissionList.get_next();
}
}
int C_ModUsrDlg::set_Usr(C_STRING &UsrName)
{
C_INT_INT_STR *pUsr = (C_INT_INT_STR *) UsrList.search_name(UsrName.get_name());
if (!pUsr) return GS_BAD;
return set_Usr(pUsr->get_key());
}
int C_ModUsrDlg::set_Usr(int UsrId)
{
C_INT_INT_STR *pUsr = (C_INT_INT_STR *) UsrList.search_key(UsrId);
if (!pUsr || pUsr->get_type() != NORMALUSR) return GS_BAD;
m_PrevUsrId = m_CurrUsrId;
m_CurrUsrId = pUsr->get_key();
return GS_GOOD;
}
void C_ModUsrDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Control(pDX, IDC_USRLIST, m_UsrName);
DDX_Control(pDX, IDC_CMD_LIST, m_Command_Button);
DDX_Control(pDX, IDC_DATA_LIST, m_Data_Button);
DDX_Control(pDX, IDC_PERMISSION_FROM_USR_CHECK, m_CopyFromUsr);
DDX_Control(pDX, IDC_USRLIST_COPYFROM, m_UsrList_CopyFrom);
DDX_Control(pDX, IDOK, m_OK);
DDX_Control(pDX, IDC_USERCODE, m_UsrCodeLbl);
}
BEGIN_MESSAGE_MAP(C_ModUsrDlg, CDialogEx)
ON_BN_CLICKED(IDOK, &C_ModUsrDlg::OnBnClickedOk)
ON_BN_CLICKED(IDHELP, &C_ModUsrDlg::OnBnClickedHelp)
ON_CBN_SELCHANGE(IDC_USRLIST, &C_ModUsrDlg::OnCbnSelchangeUsrlist)
ON_BN_CLICKED(IDC_PERMISSION_FROM_USR_CHECK, &C_ModUsrDlg::OnBnClickedPermissionFromUsrCheck)
ON_BN_CLICKED(IDC_CMD_LIST, &C_ModUsrDlg::OnBnClickedCmdList)
ON_BN_CLICKED(IDC_DATA_LIST, &C_ModUsrDlg::OnBnClickedDataList)
END_MESSAGE_MAP()
// gestori di messaggi C_ModUsrDlg
BOOL C_ModUsrDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
C_INT_INT_STR *pUsr = (C_INT_INT_STR *) UsrList.get_head();
int i = 0;
while (pUsr)
{
if (pUsr->get_type() == 1)
{
m_UsrName.AddString(pUsr->get_name()); // solo utenti normali
m_UsrName.SetItemDataPtr(m_UsrName.FindStringExact(-1, pUsr->get_name()), pUsr);
// m_UsrName.SetItemDataPtr(i++, pUsr);
}
pUsr = (C_INT_INT_STR *) UsrList.get_next();
}
m_UsrList_CopyFrom.EnableWindow(FALSE);
if (m_CurrUsrId > 0)
{
if ((pUsr = (C_INT_INT_STR *) UsrList.search_key(m_CurrUsrId)))
m_UsrName.SetCurSel(m_UsrName.FindStringExact(-1, pUsr->get_name()));
OnCbnSelchangeUsrlist();
}
else
{
m_UsrName.SetFocus();
m_Command_Button.EnableWindow(FALSE);
m_Data_Button.EnableWindow(FALSE);
m_CopyFromUsr.EnableWindow(FALSE);
m_OK.EnableWindow(FALSE);
}
return TRUE;
}
void C_ModUsrDlg::OnCbnSelchangeUsrlist()
{
C_INT_INT_STR *pUsr;
int CurSel, i = 0;
if (Update)
if (gsui_confirm(_T("Cambiando utente saranno annullate le impostazioni correnti. Continuare ?")) != GS_GOOD)
{
pUsr = (C_INT_INT_STR *) UsrList.search_key(m_CurrUsrId);
m_UsrName.SetCurSel(m_UsrName.FindStringExact(-1, pUsr->get_name()));
return;
}
m_PrevUsrId = m_CurrUsrId;
if ((CurSel = m_UsrName.GetCurSel()) == CB_ERR) return;
pUsr = (C_INT_INT_STR *) m_UsrName.GetItemDataPtr(CurSel);
m_CurrUsrId = pUsr->get_key();
while (m_UsrList_CopyFrom.DeleteString(0) != CB_ERR); // svuoto la combobox
pUsr = (C_INT_INT_STR *) UsrList.get_head();
while (pUsr)
{
// solo utenti normali scartando quello corrente
if (pUsr->get_type() == 1 && m_CurrUsrId != pUsr->get_key())
{
m_UsrList_CopyFrom.AddString(pUsr->get_name());
m_UsrList_CopyFrom.SetItemDataPtr(m_UsrList_CopyFrom.FindStringExact(-1, pUsr->get_name()), pUsr);
}
pUsr = (C_INT_INT_STR *) UsrList.get_next();
}
m_UsrList_CopyFrom.SetCurSel(0);
// carico abilitazioni
if (LoadUsrPermission(m_CurrUsrId) == GS_BAD)
{
gsui_alert(_T("Abilitazioni dell'utente non caricate."));
return;
}
C_STRING Msg(_T("Codice utente: "));
Msg += m_CurrUsrId;
m_UsrCodeLbl.SetWindowText(Msg.get_name());
Update = false;
m_CopyFromUsr.EnableWindow(TRUE);
OnBnClickedPermissionFromUsrCheck();
m_OK.EnableWindow(TRUE);
}
int C_ModUsrDlg::LoadUsrPermission(int UserId)
{
C_INT_INT *pPrj;
C_INT_INT_LIST *pClasses;
C_4INT_STR_LIST *pSecTabs;
C_INT_VOIDPTR *p;
// svuoto la lista dei permessi alle classi e alle tabelle secondarie
p = (C_INT_VOIDPTR *) ClassesPermissionList.get_head();
while (p)
{
if (p->get_VoidPtr()) delete p->get_VoidPtr();
p = (C_INT_VOIDPTR *) ClassesPermissionList.get_next();
}
ClassesPermissionList.remove_all();
p = (C_INT_VOIDPTR *) SecTabsPermissionList.get_head();
while (p)
{
if (p->get_VoidPtr()) delete p->get_VoidPtr();
p = (C_INT_VOIDPTR *) SecTabsPermissionList.get_next();
}
SecTabsPermissionList.remove_all();
// carico abilitazione a comandi
if (gsc_getusrcomm(UserId, &Commands) == GS_BAD) return GS_BAD;
// carico abilitazione personale a progetti
if (gsc_getPersonalPrjPermissions(UserId, &ProjectsPermissionList) == GS_BAD) return GS_BAD;
// carico abilitazione personale a classi
pPrj = (C_INT_INT *) ProjectsPermissionList.get_head();
while (pPrj)
{
if ((pClasses = new C_INT_INT_LIST()) == NULL) return GS_BAD;
if (gsc_getPersonalClassPermissions(UserId, pPrj->get_key(), pClasses) == GS_BAD)
{ delete pClasses; return GS_BAD; }
ClassesPermissionList.add_tail_int_voidptr(pPrj->get_key(), pClasses);
pPrj = (C_INT_INT *) ProjectsPermissionList.get_next();
}
// carico abilitazione personale alle tabelle secondarie
pPrj = (C_INT_INT *) ProjectsPermissionList.get_head();
while (pPrj)
{
if ((pSecTabs = new C_4INT_STR_LIST()) == NULL) return GS_BAD;
if (gsc_getPersonalSecPermissions(UserId, pPrj->get_key(), pSecTabs) == GS_BAD)
{ delete pSecTabs; return GS_BAD; }
SecTabsPermissionList.add_tail_int_voidptr(pPrj->get_key(), pSecTabs);
pPrj = (C_INT_INT *) ProjectsPermissionList.get_next();
}
// carico i nomi degli utenti da cui ereditare le abilitazioni
if (gsc_loadInheritanceUsers(UserId, InheritanceUserNames) == GS_BAD) return GS_BAD;
return GS_GOOD;
}
int C_ModUsrDlg::SaveUsrPermission(int UserId)
{
C_INT_VOIDPTR *p;
// salvo abilitazione a comandi
if (gsc_setusrcomm(UserId, &Commands) == GS_BAD) return GS_BAD;
// salvo abilitazione personale a progetti
if (gsc_setPersonalPrjPermissions(UserId, ProjectsPermissionList) == GS_BAD) return GS_BAD;
// salvo abilitazione personale a classi
p = (C_INT_VOIDPTR *) ClassesPermissionList.get_head();
while (p)
{
if (gsc_setPersonalClassPermissions(UserId, p->get_key(), *((C_INT_INT_LIST *) p->get_VoidPtr())) == GS_BAD)
return GS_BAD;
p = (C_INT_VOIDPTR *) ClassesPermissionList.get_next();
}
// salvo abilitazione personale a tabelle secondarie
p = (C_INT_VOIDPTR *) SecTabsPermissionList.get_head();
while (p)
{
if (gsc_setPersonalSecPermissions(UserId, p->get_key(), *((C_4INT_STR_LIST *) p->get_VoidPtr())) == GS_BAD)
return GS_BAD;
p = (C_INT_VOIDPTR *) SecTabsPermissionList.get_next();
}
// salvo i nomi degli utenti da cui ereditare le abilitazioni
if (gsc_saveInheritanceUsers(UserId, InheritanceUserNames) == GS_BAD)
return GS_BAD;
return GS_GOOD;
}
void C_ModUsrDlg::OnBnClickedOk()
{
if (m_CopyFromUsr.GetCheck() == BST_CHECKED)
{
C_INT_INT_STR *pSourceUsr;
int CurSel;
if ((CurSel = m_UsrList_CopyFrom.GetCurSel()) == CB_ERR)
{
gsui_alert(_T("Utente da cui copiare le abilitazioni non trovato."));
return;
}
pSourceUsr = (C_INT_INT_STR *) m_UsrList_CopyFrom.GetItemDataPtr(CurSel);
if (gsc_ui_copyFromUserToUser(pSourceUsr->get_key(), m_CurrUsrId) != GS_GOOD)
return;
}
else
if (Update)
{
if (SaveUsrPermission(m_CurrUsrId) == GS_BAD)
{
gsui_alert(_T("Salvataggio impostazioni correnti non riuscito."));
return;
}
}
Update = false;
CDialogEx::OnOK();
}
void C_ModUsrDlg::OnBnClickedHelp()
{
gsc_help(IDH_Modificautente);
}
void C_ModUsrDlg::OnBnClickedPermissionFromUsrCheck()
{
if (m_CopyFromUsr.GetCheck() == BST_CHECKED)
{
m_UsrList_CopyFrom.EnableWindow(TRUE);
m_Command_Button.EnableWindow(FALSE);
m_Data_Button.EnableWindow(FALSE);
}