-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsynchronize.php
293 lines (246 loc) · 11.9 KB
/
synchronize.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
<?php
/**
***********************************************************************************************
* Makes a user to a former if he does not have a key.
*
* @copyright The Admidio Team
* @see https://www.admidio.org/
* @license https://www.gnu.org/licenses/gpl-2.0.html GNU General Public License v2.0 only
*
***********************************************************************************************
*/
/******************************************************************************
* Parameters:
*
* mode : preview - preview
* write - make user to former
* print - preview for printing
*
*****************************************************************************/
require_once(__DIR__ . '/../../adm_program/system/common.php');
require_once(__DIR__ . '/common_function.php');
require_once(__DIR__ . '/classes/configtable.php');
// Initialize and check the parameters
$getMode = admFuncVariableIsValid($_GET, 'mode', 'string', array('defaultValue' => 'preview', 'validValues' => array('preview', 'write', 'print')));
$pPreferences = new ConfigTablePKM();
$pPreferences->read();
// only authorized user are allowed to start this module
if (!isUserAuthorizedForPreferences())
{
$gMessage->show($gL10n->get('SYS_NO_RIGHTS'));
}
$user = new User($gDb, $gProfileFields);
$icon = array();
$icon['member'] = array('image' => 'fa-user', 'text' => $gL10n->get('SYS_MEMBER_OF_ORGANIZATION', array($gCurrentOrganization->getValue('org_longname'))));
$icon['not_member'] = array('image' => 'fa-user-slash', 'text' => $gL10n->get('SYS_NOT_MEMBER_OF_ORGANIZATION', array($gCurrentOrganization->getValue('org_longname'))));
$icon['error'] = array('image' => 'fa-times', 'text' => $gL10n->get('SYS_ERROR'));
// set headline of the script
$headline = $gL10n->get('PLG_KEYMANAGER_SYNCHRONIZE');
if (!StringUtils::strContains($gNavigation->getUrl(), 'synchronize.php'))
{
$gNavigation->addUrl(CURRENT_URL, $headline);
}
// create html page object
$page = new HtmlPage('plg-keymanager-synchronize', $headline);
if ($getMode == 'preview') //Default
{
$members = array();
// read in all members
$sql = 'SELECT usr_id, last_name.usd_value AS last_name, first_name.usd_value AS first_name
FROM '.TBL_USERS.'
LEFT JOIN '.TBL_USER_DATA.' AS last_name
ON last_name.usd_usr_id = usr_id
AND last_name.usd_usf_id = ? -- $gProfileFields->getProperty(\'LAST_NAME\', \'usf_id\')
LEFT JOIN '.TBL_USER_DATA.' AS first_name
ON first_name.usd_usr_id = usr_id
AND first_name.usd_usf_id = ? -- $gProfileFields->getProperty(\'FIRST_NAME\', \'usf_id\')
WHERE usr_valid = 1
AND EXISTS (SELECT 1
FROM '. TBL_MEMBERS. ', '. TBL_ROLES. ', '. TBL_CATEGORIES. ','. TBL_USER_DATA. '
WHERE mem_usr_id = usr_id
AND mem_rol_id = rol_id
AND mem_begin <= ? -- DATE_NOW
AND mem_end > ? -- DATE_NOW
AND rol_valid = 1
AND rol_cat_id = cat_id
AND cat_org_id = '.$gCurrentOrgId. ') ';
$userStatement = $gDb->queryPrepared($sql, array($gProfileFields->getProperty('LAST_NAME', 'usf_id'), $gProfileFields->getProperty('FIRST_NAME', 'usf_id'), DATE_NOW, DATE_NOW));
while ($row = $userStatement->fetch())
{
$members[$row['usr_id']] = array(
'last_name' => $row['last_name'],
'first_name' => $row['first_name'],
'count' => 0,
'delete_marker' => true,
'info' => '<i class="fas '.$icon['member']['image'].'" data-toggle="tooltip" title="'.$icon['member']['text'].'"></i> -> <i class="fas '.$icon['not_member']['image'].'" data-toggle="tooltip" title="'.$icon['not_member']['text'].'"></i>');
$user->readDataById($row['usr_id']);
if ($user->isAdministrator() || $gCurrentUser->getValue('usr_id') == $row['usr_id'])
{
$members[$row['usr_id']]['info'] = $gL10n->get('PLG_KEYMANAGER_SPECIAL_CASE_CURUSER_OR_ADMIN');
$members[$row['usr_id']]['delete_marker'] = false;
}
}
// read in all receiver
$sql = 'SELECT kmd_value, last_name.usd_value as last_name , first_name.usd_value as first_name
FROM '.TBL_KEYMANAGER_DATA.'
INNER JOIN '.TBL_KEYMANAGER_FIELDS.'
ON kmf_id = kmd_kmf_id
LEFT JOIN '. TBL_USER_DATA. ' as last_name
ON last_name.usd_usr_id = kmd_value
AND last_name.usd_usf_id = ? -- $gProfileFields->getProperty(\'LAST_NAME\', \'usf_id\')
LEFT JOIN '. TBL_USER_DATA. ' as first_name
ON first_name.usd_usr_id = kmd_value
AND first_name.usd_usf_id = ? -- $gProfileFields->getProperty(\'FIRST_NAME\', \'usf_id\')
WHERE kmf_name_intern = \'RECEIVER\'
AND ( kmf_org_id = ? -- $gCurrentOrgId
OR kmf_org_id IS NULL )
ORDER BY last_name.usd_value, first_name.usd_value ASC';
$receiverStatement = $gDb->queryPrepared($sql, array($gProfileFields->getProperty('LAST_NAME', 'usf_id'), $gProfileFields->getProperty('FIRST_NAME', 'usf_id'), $gCurrentOrgId));
while ($row = $receiverStatement->fetch())
{
$members[$row['kmd_value']]['info'] = '';
$members[$row['kmd_value']]['delete_marker'] = false;
$members[$row['kmd_value']]['count']++;
}
$form = new HtmlForm('synchronize_preview_form', SecurityUtils::encodeUrl(ADMIDIO_URL . FOLDER_PLUGINS . PLUGIN_FOLDER .'/synchronize.php', array('mode' => 'write')), $page);
if (sizeof($members) > 0)
{
// save members in session (for mode write and mode print)
$_SESSION['pKeyManager']['synchronize'] = $members;
$datatable = true;
$hoverRows = true;
$classTable = 'table table-condensed';
$table = new HtmlTable('table_new_synchronize', $page, $hoverRows, $datatable, $classTable);
$table->setColumnAlignByArray(array('left', 'center', 'center'));
$columnValues = array();
$columnValues[] = $gL10n->get('SYS_NAME');
$columnValues[] = '<i class="fas fa-key" data-toggle="tooltip" title="'.$gL10n->get('PLG_KEYMANAGER_NUMBER_OF_KEYS').'"></i>';
$columnValues[] = '<i class="fas fa-info-circle" data-toggle="tooltip" title="'.$gL10n->get('SYS_INFORMATIONS').'"></i>';
$table->addRowHeadingByArray($columnValues);
foreach ($members as $memberId => $data)
{
$user->readDataById($memberId);
$columnValues = array();
$columnValues[] = '<a href="'.SecurityUtils::encodeUrl(ADMIDIO_URL.FOLDER_MODULES.'/profile/profile.php', array('user_uuid' => $user->getValue('usr_uuid'))).'">'.$data['last_name'].', '.$data['first_name'].'</a>';
$columnValues[] = $data['count'];
$columnValues[] = $data['info'];
$table->addRowByArray($columnValues);
}
$page->addHtml($table->show(false));
if (array_search(true, array_column($members, 'delete_marker')))
{
$form->addSubmitButton('btn_next_page', $gL10n->get('SYS_SAVE'), array('icon' => 'fa-check', 'class' => ' btn-primary'));
}
$form->addDescription('<br/>'.$gL10n->get('PLG_KEYMANAGER_SYNCHRONIZE_PREVIEW'));
//seltsamerweise wird in diesem Abschnitt nichts angezeigt wenn diese Anweisung fehlt
$form->addStaticControl('', '', '');
}
else
{
$form->addDescription($gL10n->get('PLG_KEYMANAGER_SYNCHRONIZE_NO_ASSIGN'));
//seltsamerweise wird in diesem Abschnitt nichts angezeigt wenn diese Anweisung fehlt
$form->addStaticControl('', '', '');
}
$page->addHtml($form->show(false));
}
elseif ($getMode == 'write')
{
$page->addJavascript('
$("#menu_item_print_view").click(function() {
window.open("'.SecurityUtils::encodeUrl(ADMIDIO_URL. FOLDER_PLUGINS . PLUGIN_FOLDER .'/synchronize.php', array('mode' => 'print')).'", "_blank");
});',
true
);
// links to print and exports
$page->addPageFunctionsMenuItem('menu_item_print_view', $gL10n->get('SYS_PRINT_PREVIEW'), 'javascript:void(0);', 'fa-print');
$form = new HtmlForm('synchronize_saved_form', null, $page);
$datatable = true;
$hoverRows = true;
$classTable = 'table table-condensed';
$table = new HtmlTable('table_saved_synchronize', $page, $hoverRows, $datatable, $classTable);
$table->setColumnAlignByArray(array('left', 'center'));
$columnValues = array($gL10n->get('SYS_NAME'), '<i class="fas fa-info-circle" data-toggle="tooltip" title="'.$gL10n->get('SYS_INFORMATIONS').'"></i>');
$table->addRowHeadingByArray($columnValues);
$member = new TableMembers($gDb);
$errorMessage = '';
foreach ($_SESSION['pKeyManager']['synchronize'] as $memberId => $data)
{
if ($data['delete_marker'] == true)
{
$user->readDataById($memberId);
$delete_marker = true;
$columnValues = array();
$columnValues[] = '<a href="'.SecurityUtils::encodeUrl(ADMIDIO_URL.FOLDER_MODULES.'/profile/profile.php', array('user_uuid' => $user->getValue('usr_uuid'))).'">'.$data['last_name'].', '.$data['first_name'].'</a>';
$sql = 'SELECT mem_id, mem_rol_id, mem_usr_id, mem_begin, mem_end, mem_leader
FROM '.TBL_MEMBERS.'
INNER JOIN '.TBL_ROLES.'
ON rol_id = mem_rol_id
INNER JOIN '.TBL_CATEGORIES.'
ON cat_id = rol_cat_id
WHERE rol_valid = 1
AND ( cat_org_id = ? -- $gCurrentOrgId
OR cat_org_id IS NULL )
AND mem_begin <= ? -- DATE_NOW
AND mem_end > ? -- DATE_NOW
AND mem_usr_id = ? -- $memberId ';
$membersStatement = $gDb->queryPrepared($sql, array($gCurrentOrgId, DATE_NOW, DATE_NOW, $memberId));
try {
while ($row = $membersStatement->fetch()) {
// stop all role memberships of this organization
$role = new TableRoles($gDb, $row['mem_rol_id']);
$role->stopMembership($memberId);
}
}
catch (AdmException $e)
{
$delete_marker = false;
}
if ($delete_marker)
{
$columnValues[] = '<i class="fas '.$icon['not_member']['image'].'" data-toggle="tooltip" title="'.$icon['not_member']['text'].'"></i>';
}
else
{
$columnValues[] = '<i class="fas '.$icon['error']['image'].'" data-toggle="tooltip" title="'.$icon['error']['text'].'"></i>';
$errorMessage .= '<br/>-'.$data['last_name'].', '.$data['first_name'];
$_SESSION['pKeyManager']['synchronize'][$memberId]['delete_marker'] = false;
}
$table->addRowByArray($columnValues);
}
}
$page->addHtml($table->show(false));
$form->addDescription('<strong>'.$gL10n->get('PLG_KEYMANAGER_SYNCHRONIZE_SAVED').'</strong>');
if ($errorMessage != '')
{
$form->addDescription($gL10n->get('PLG_KEYMANAGER_SYNCHRONIZE_ERROR', array('<i class="fas '.$icon['error']['image'].'" ></i>')).$errorMessage);
}
//seltsamerweise wird in diesem Abschnitt nichts angezeigt wenn diese Anweisung fehlt
$form->addStaticControl('', '', '');
$page->addHtml($form->show(false));
}
elseif ($getMode == 'print')
{
$gNavigation->clear();
// create html page object without the custom theme files
$hoverRows = false;
$datatable = false;
$classTable = 'table table-condensed table-striped';
$page->setPrintMode();
$page->setHeadline($gL10n->get('PLG_KEYMANAGER_SYNCHRONIZE'));
$table = new HtmlTable('table_print_synchronize', $page, $hoverRows, $datatable, $classTable);
$table->setColumnAlignByArray(array('left', 'center'));
$columnValues = array($gL10n->get('SYS_NAME'), '<i class="fas fa-info-circle" data-toggle="tooltip" title="'.$gL10n->get('SYS_INFORMATIONS').'"></i>');
$table->addRowHeadingByArray($columnValues);
foreach ($_SESSION['pKeyManager']['synchronize'] as $member => $data)
{
if ($data['delete_marker'] == true)
{
$columnValues = array();
$columnValues[] = $data['last_name'].', '. $data['first_name'];
$columnValues[] = '<i class="fas '.$icon['not_member']['image'].'" data-toggle="tooltip" title="'.$icon['not_member']['text'].'"></i>';
$table->addRowByArray($columnValues);
}
}
$page->addHtml($table->show(false));
}
$page->show();