-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkeys_delete.php
144 lines (114 loc) · 5.25 KB
/
keys_delete.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
<?php
/**
***********************************************************************************************
* Delete a key or make a key to the former
*
* @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 : 1 - Menu and preview of the key who should be deleted or made to the former
* 2 - Delete a key
* 3 - Make the key to the former
* key_id : ID of the key who should be deleted or made to the former
* key_former : 0 - Key is activ
* 1 - Key is already made to the former
*
*****************************************************************************/
require_once(__DIR__ . '/../../adm_program/system/common.php');
require_once(__DIR__ . '/common_function.php');
require_once(__DIR__ . '/classes/keys.php');
require_once(__DIR__ . '/classes/configtable.php');
// Initialize and check the parameters
$getMode = admFuncVariableIsValid($_GET, 'mode', 'numeric', array('defaultValue' => 1));
$getKeyId = admFuncVariableIsValid($_GET, 'key_id', 'int');
$getKeyFormer = admFuncVariableIsValid($_GET, 'key_former', 'bool');
$pPreferences = new ConfigTablePKM();
$pPreferences->read();
// only authorized user are allowed to start this module
if (!isUserAuthorizedForPreferences())
{
$gMessage->show($gL10n->get('SYS_NO_RIGHTS'));
}
$keys = new Keys($gDb, $gCurrentOrgId);
$keys->readKeyData($getKeyId, $gCurrentOrgId);
$user = new User($gDb, $gProfileFields);
switch ($getMode)
{
case 1:
$headline = $gL10n->get('PLG_KEYMANAGER_KEY_DELETE');
// create html page object
$page = new HtmlPage('plg-keymanager-keys-delete', $headline);
// add current url to navigation stack
$gNavigation->addUrl(CURRENT_URL, $headline);
$page->addHtml('<p class="lead">'.$gL10n->get('PLG_KEYMANAGER_KEY_DELETE_DESC').'</p>');
// show form
$form = new HtmlForm('key_delete_form', null, $page);
foreach ($keys->mKeyFields as $keyField)
{
$kmfNameIntern = $keyField->getValue('kmf_name_intern');
$content = $keys->getValue($kmfNameIntern, 'database');
if ($kmfNameIntern === 'RECEIVER' && strlen($content) > 0)
{
$user->readDataById($content);
$content = $user->getValue('LAST_NAME').', '.$user->getValue('FIRST_NAME');
}
elseif ($keys->getProperty($kmfNameIntern, 'kmf_type') === 'DATE')
{
$content = $keys->getHtmlValue($kmfNameIntern, $content);
}
elseif ( $keys->getProperty($kmfNameIntern, 'kmf_type') === 'DROPDOWN'
|| $keys->getProperty($kmfNameIntern, 'kmf_type') === 'RADIO_BUTTON')
{
$arrListValues = $keys->getProperty($kmfNameIntern, 'kmf_value_list', 'text');
$content = $arrListValues[$content];
}
$form->addInput(
'kmf-'. $keys->getProperty($kmfNameIntern, 'kmf_id'),
convlanguagePKM($keys->getProperty($kmfNameIntern, 'kmf_name')),
$content,
array('property' => HtmlForm::FIELD_DISABLED)
);
}
$form->addButton('btn_delete', $gL10n->get('SYS_DELETE'), array('icon' => 'fa-trash-alt', 'link' => SecurityUtils::encodeUrl(ADMIDIO_URL . FOLDER_PLUGINS . PLUGIN_FOLDER .'/keys_delete.php', array('key_id' => $getKeyId, 'mode' => 2)), 'class' => 'btn-primary offset-sm-3'));
if (!$getKeyFormer)
{
$form->addButton('btn_former', $gL10n->get('PLG_KEYMANAGER_FORMER'), array('icon' => 'fa-eye-slash', 'link' => SecurityUtils::encodeUrl(ADMIDIO_URL . FOLDER_PLUGINS . PLUGIN_FOLDER .'/keys_delete.php', array('key_id' => $getKeyId, 'mode' => 3)), 'class' => 'btn-primary offset-sm-3'));
$form->addCustomContent('', '<br />'.$gL10n->get('PLG_KEYMANAGER_KEY_MAKE_TO_FORMER'));
}
// add form to html page and show page
$page->addHtml($form->show(false));
$page->show();
break;
case 2:
$sql = 'DELETE FROM '.TBL_KEYMANAGER_LOG.'
WHERE kml_kmk_id = ? ';
$gDb->queryPrepared($sql, array($getKeyId));
$sql = 'DELETE FROM '.TBL_KEYMANAGER_DATA.'
WHERE kmd_kmk_id = ? ';
$gDb->queryPrepared($sql, array($getKeyId));
$sql = 'DELETE FROM '.TBL_KEYMANAGER_KEYS.'
WHERE kmk_id = ? -- $getKeyId
AND ( kmk_org_id = ? -- $gCurrentOrgId
OR kmk_org_id IS NULL ) ';
$gDb->queryPrepared($sql, array($getKeyId, $gCurrentOrgId));
// go back to key view
$gMessage->setForwardUrl($gNavigation->getPreviousUrl(), 1000);
$gMessage->show($gL10n->get('PLG_KEYMANAGER_KEY_DELETED'));
break;
// => EXIT
case 3:
$sql = 'UPDATE '.TBL_KEYMANAGER_KEYS.'
SET kmk_former = 1
WHERE kmk_id = ? ';
$gDb->queryPrepared($sql, array($getKeyId));
// go back to key view
$gMessage->setForwardUrl($gNavigation->getPreviousUrl(), 1000);
$gMessage->show($gL10n->get('PLG_KEYMANAGER_KEY_MADE_TO_FORMER'));
break;
// => EXIT
}