-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheditusers.cpp
337 lines (314 loc) · 13.3 KB
/
editusers.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
#include <QtGui>
#include <QStringList>
#include <string.h>
#include <windows.h>
#include <stdlib.h>
#include "editUsers.h"
#include "adprog.h"
#include "userattrib.h"
/*
* EditUsers Class: This class implements the editing layout for the user interface.
*/
EditUsers::EditUsers(ImportUsers * prog, QWidget *parent):UserViewGUI(prog, parent){
/* This Object calls the super class, so that the user database displays users
* to be edited.
*/
setWindowTitle("View and Edit users...");
/* Build the navigation layout */
/* Build the previous record button */
prevRecord = new QPushButton("Previous");
prevRecord->show();
/* Build the next record button */
nextRecord = new QPushButton("Next");
nextRecord->show();
/* Build the delete record button */
delUser = new QPushButton("Delete User");
delUser->show();
/* Build the edit record button */
editUser = new QPushButton("Edit User");
editUser->show();
/* Build the submitEdit and cancelEdit Buttons, but hide these */
cancelEdit = new QPushButton("Cancel/Finish Edit");
cancelEdit->hide();
submitEdit = new QPushButton("Submit Edit");
submitEdit->hide();
/* navigation layout for submitEdit and cancelEdit buttons to reside */
navLayout = new QHBoxLayout;
navLayout->addWidget(prevRecord);
navLayout->addWidget(nextRecord);
navLayout->addWidget(delUser);
navLayout->addWidget(editUser);
navLayout->addWidget(submitEdit);
navLayout->addWidget(cancelEdit);
navLayout->setGeometry(QRect(200, 610, 161, 51));
navLayout->setContentsMargins(0, 0, 0, 0);
/* End navigation Layout */
mainLayout->addLayout(navLayout, 5, 0, 1, 3);
/* Connect some functions to the buttons on the GUI */
connect(nextRecord, SIGNAL(clicked()), this, SLOT(nextPerson()));
connect(prevRecord, SIGNAL(clicked()), this, SLOT(prevPerson()));
connect(delUser, SIGNAL(clicked()), this, SLOT(deletePerson()));
connect(editUser, SIGNAL(clicked()), this, SLOT(editPerson()));
connect(submitEdit, SIGNAL(clicked()), this, SLOT(submitChange()));
connect(cancelEdit, SIGNAL(clicked()), this, SLOT(cancelChange()));
/* Let users know that display name is generated on Export*/
dispNameView->setText("Available on Export.");
/* Populate the GUI on end of construction */
displayEdits(calling_prog->dispPersonList());
}
/****************** EDITUSER MEMBER FUNCTIONS *******************************/
void EditUsers::nextPerson(){
if(current_person->next) {
displayEdits(current_person->next);
}
else {
while(current_person->prev){
current_person = current_person->prev;
}
displayEdits(current_person);
}
}
void EditUsers::prevPerson(){
if(current_person->prev){
displayEdits(current_person->prev);
}
else {
while(current_person->next){
current_person = current_person->next;
}
displayEdits(current_person);
}
}
void EditUsers::deletePerson(){
int ret;
ret = QMessageBox::warning(this,"Delete this User", "Are you sure you want to delete this user?",
QMessageBox::Cancel, QMessageBox::Ok);
switch(ret){
case QMessageBox::Ok:
current_person = deleteOneUser(current_person);
QMessageBox::information(this, "Deletion Successful!", "User was deleted.");
if (current_person) displayEdits(current_person);
else {
this->close();
QMessageBox::information(this, "Deleted all users...", "All users in database were deleted.");
}
break;
case QMessageBox::Cancel:
return;
default:
break;
}
}
void EditUsers::editPerson(){
updateInterface(EDIT_MODE_BUTTONS);
}
void EditUsers::submitChange() {
updateInterface(NAVIGATION_MODE);
processChanges();
displayEdits(current_person);
updateInterface(EDIT_MODE);
}
void EditUsers::cancelChange() {
updateInterface(NAVIGATION_MODE_BUTTONS);
}
void EditUsers::processChanges() {
char * place = NULL;
// char * streetAddr = NULL;
// char * city = NULL;
// char * state = NULL;
// char * zip = NULL;
// char * country = NULL;
char * firstName = NULL;
char * middleName = NULL;
char * lastName = NULL;
char * prefName = NULL;
char * initials = NULL;
char * userName = NULL;
char * email = NULL;
char * title = NULL;
char * dept = NULL;
char * password = NULL;
char * mod = NULL;
// char * manager = NULL;
// char * desc = NULL;
// char * scriptPath = NULL;
// char * homeDrive = NULL;
char * profilePath = NULL;
char * homeDir = NULL;
// char * UPN = NULL;
// char * coName = NULL;
/* person's office info */
place = dispOfficeName(current_person->user);
/* person's AD attributes */
profilePath = dispProfilePath(current_person->user);
homeDir = dispHomeDir(current_person->user);
/* Person's name */
firstName = dispFirstName(current_person->user);
middleName = dispMiddleName(current_person->user);
lastName = dispLastName(current_person->user);
prefName = dispPrefferedName(current_person->user);
initials = dispInitials(current_person->user);
userName = dispUserName(current_person->user);
email = dispEmail(current_person->user);
title = dispTitle(current_person->user);
dept = dispDept(current_person->user);
password = dispPassword(current_person->user);
mod = dispMod(current_person->user);
/* first compare the contents of the text box with the field,
If there is no string already, create one and assign it.
else, if there are no changes, don't do anything,
else, if there is a change -> make it into a c string
and add it to the field, then trash the original.
done.
*
*/
if (uNameEdit->isModified()) {
char * retval = NULL;
retval = changeUserName(uNameEdit->text().toStdString().c_str(), current_person->user);
changeProfilePath(uNameEdit->text().toStdString().c_str(), current_person->user);
changeHomeDirectory(uNameEdit->text().toStdString().c_str(), current_person->user);
if (retval) QMessageBox::information(this, "User Name changed!", "Username has been changed.");
else QMessageBox::information(this, "User Name not changed!", "Username has not been changed.");
}
if (FNameEdit->isModified()) {
char * retval = NULL;
retval = changeFirstName(FNameEdit->text().toStdString().c_str(), current_person->user);
if (retval) QMessageBox::information(this, "First Name changed!", "First name has been changed.");
else QMessageBox::information(this, "First Name not changed!", "First name has not been changed.");
}
if (MNameEdit->isModified()) {
char * retval = NULL;
retval = changeMiddleName(MNameEdit->text().toStdString().c_str(), current_person->user);
if (retval) QMessageBox::information(this, "Middle Name changed!", "Middle name has been changed.");
else QMessageBox::information(this, "Middle Name not changed!", "Middle name has not been changed.");
}
if (LNameEdit->isModified()) {
char * retval = NULL;
retval = changeLastName(LNameEdit->text().toStdString().c_str(), current_person->user);
if (retval) QMessageBox::information(this, "Last Name changed!", "Last name has been changed.");
else QMessageBox::information(this, "Last Name not changed!", "Last name has not been changed.");
}
if (deptEdit->isModified()) {
char * retval = NULL;
retval = changeDepartment(deptEdit->text().toStdString().c_str(), current_person->user);
if (retval) QMessageBox::information(this, "Department changed!", "Department has been changed.");
else QMessageBox::information(this, "Department not changed!", "Department has not been changed.");
}
if (InitEdit->isModified()) {
char * retval = NULL;
retval = changeInitials(InitEdit->text().toStdString().c_str(), current_person->user);
if (retval) QMessageBox::information(this, "Initials changed!", "Initials have been changed.");
else QMessageBox::information(this, "Initials not changed!", "Initials have not been changed.");
}
if (titleEdit->isModified()) {
char * retval = NULL;
retval = changeTitle(titleEdit->text().toStdString().c_str(), current_person->user);
if (retval) QMessageBox::information(this, "Title changed!", "Title has been changed.");
else QMessageBox::information(this, "Title not changed!", "Title has not been changed.");
}
if (pNameEdit->isModified()) {
char * retval = NULL;
retval = changePreferredName(pNameEdit->text().toStdString().c_str(), current_person->user);
if (retval) QMessageBox::information(this, "Preferred Name changed!", "Preferred Name has been changed.");
else QMessageBox::information(this, "Preferred Name not changed!", "Preferred Name has not been changed.");
}
if (officeNameView->isModified()) {
// special case, needs to be carefully debugged
Location retval = NULL;
retval = changeOfficeName(officeNameView->text().toStdString().c_str(), current_person->user);
if (retval) QMessageBox::information(this, "Office Name changed!", "Office Name has been changed.");
else QMessageBox::information(this, "Office Name not changed!", "Office Name has not been changed.");
}
// if (ppathview->isModified()) {
// //(strcmp(uNameEdit->text().toStdString().c_str(), userName))
// }
// if (homeDirView->isModified()) {
// //(strcmp(uNameEdit->text().toStdString().c_str(), userName))
// }
if (ModCheck->isEnabled()) {
if (ModCheck->isChecked()) changeMod("true", current_person->user);
else changeMod("false", current_person->user);
//(strcmp(uNameEdit->text().toStdString().c_str(), userName))
}
if (EmailEdit->isModified()) {
char * retval = NULL;
retval = changeEmail(EmailEdit->text().toStdString().c_str(), current_person->user);
if (retval) QMessageBox::information(this, "Email address changed!", "Email has been changed.");
else QMessageBox::information(this, "Email address not changed!", "Email has not been changed.");
}
if (passwordView->isModified()) {
char * retval = NULL;
retval = changePassword(passwordView->text().toStdString().c_str(), current_person->user);
if (retval) QMessageBox::information(this, "Password changed!", "Password has been changed.");
else QMessageBox::information(this, "Password not changed!", "Password has not been changed.");
}
}
void EditUsers::updateInterface(int mode) {
/* Decide which GUI attributes are active */
switch (mode) {
case EDIT_MODE_BUTTONS:
/* Change the state of the buttons */
nextRecord->hide();
prevRecord->hide();
editUser->hide();
submitEdit->show();
cancelEdit->show();
case EDIT_MODE: // falls through from Edit mode buttons
/* Make everything editable */
uNameEdit->setEnabled(true);
FNameEdit->setEnabled(true);
MNameEdit->setEnabled(true);
LNameEdit->setEnabled(true);
deptEdit->setEnabled(true);
InitEdit->setEnabled(true);
titleEdit->setEnabled(true);
pNameEdit->setEnabled(true);
officeNameView->setEnabled(true);
// ppathview->setEnabled(true);
// homeDirView->setEnabled(true);
//coView->setEnabled(true);
//scriptPathView->setEnabled(true);
//officeAddrDisp->setEnabled(true);
ModCheck->setEnabled(true);
//managerEdit->setEnabled(true);
EmailEdit->setEnabled(true);
//descView->setEnabled(true);
passwordView->setEnabled(true);
//hDriveView->setEnabled(true);
//dispNameView->setEnabled(true);
break;
case NAVIGATION_MODE_BUTTONS:
/* change the state of the buttons */
nextRecord->show();
prevRecord->show();
editUser->show();
submitEdit->hide();
cancelEdit->hide();
case NAVIGATION_MODE: // Falls through from Navigation Mode
/* make everything uneditable */
uNameEdit->setEnabled(false);
FNameEdit->setEnabled(false);
MNameEdit->setEnabled(false);
LNameEdit->setEnabled(false);
deptEdit->setEnabled(false);
InitEdit->setEnabled(false);
titleEdit->setEnabled(false);
pNameEdit->setEnabled(false);
officeNameView->setEnabled(false);
ppathview->setEnabled(false);
homeDirView->setEnabled(false);
coView->setEnabled(false);
scriptPathView->setEnabled(false);
officeAddrDisp->setEnabled(false);
ModCheck->setEnabled(false);
managerEdit->setEnabled(false);
EmailEdit->setEnabled(false);
descView->setEnabled(false);
passwordView->setEnabled(false);
hDriveView->setEnabled(false);
dispNameView->setEnabled(false);
break;
default:
break;
}
}