forked from rmbinder/Mitgliedsbeitrag
-
Notifications
You must be signed in to change notification settings - Fork 0
/
copy.php
248 lines (212 loc) · 10.5 KB
/
copy.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
<?php
/**
***********************************************************************************************
* Kopieren von Profildaten fuer das Admidio-Plugin Mitgliedsbeitrag
*
* @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 : html - Standardmodus zun Anzeigen einer html-Liste
* assign - Kopieren der Daten
* source_userid : die UserID des Quelle-Mitglieds
* target_userid : die UserID des Ziel-Mitglieds
* source_usfid : die UsfID der Quelle
* target_usfid : die UsfID des Ziels
***********************************************************************************************
*/
require_once(__DIR__ . '/../../adm_program/system/common.php');
require_once(__DIR__ . '/common_function.php');
require_once(__DIR__ . '/classes/configtable.php');
// only authorized user are allowed to start this module
if (!isUserAuthorized($_SESSION['pMembershipFee']['script_name']))
{
$gMessage->show($gL10n->get('SYS_NO_RIGHTS'));
}
$pPreferences = new ConfigTablePMB();
$pPreferences->read();
if(isset($_GET['mode']) && $_GET['mode'] == 'assign')
{
// ajax mode then only show text if error occurs
$gMessage->showTextOnly(true);
}
// Initialize and check the parameters
$getMode = admFuncVariableIsValid($_GET, 'mode', 'string', array('defaultValue' => 'html', 'validValues' => array('html', 'assign')));
$getSourceUserid = admFuncVariableIsValid($_GET, 'source_userid', 'numeric', array('defaultValue' => 0));
$getTargetUserid = admFuncVariableIsValid($_GET, 'target_userid', 'numeric', array('defaultValue' => 0));
$getSourceUsfid = admFuncVariableIsValid($_GET, 'source_usfid', 'numeric');
$getTargetUsfid = admFuncVariableIsValid($_GET, 'target_usfid', 'numeric');
$userSource = new User($gDb, $gProfileFields, $getSourceUserid);
$userTarget = new User($gDb, $gProfileFields, $getTargetUserid);
if($getMode == 'assign')
{
$ret_text = 'ERROR';
try
{
if($gProfileFields->getPropertyById($getSourceUsfid, 'usf_type') != $gProfileFields->getPropertyById($getTargetUsfid, 'usf_type'))
{
$ret_text = 'unequal_datatype';
}
else
{
$userTarget->setValue($gProfileFields->getPropertyById($getTargetUsfid, 'usf_name_intern'), $userSource->getValue($gProfileFields->getPropertyById($getSourceUsfid, 'usf_name_intern')));
$userTarget->save();
$ret_text = 'success';
}
}
catch(AdmException $e)
{
$e->showText();
}
echo $ret_text;
}
else
{
// set headline of the script
$headline = $gL10n->get('PLG_MITGLIEDSBEITRAG_COPY');
$gNavigation->addUrl(CURRENT_URL, $headline);
$page = new HtmlPage('plg-mitgliedsbeitrag-copy', $headline);
$javascriptCode = '
// pulldown Quelle is clicked
$("#quelle").change(function () {
if($(this).val().length > 0) {
window.location.replace("'. SecurityUtils::encodeUrl(ADMIDIO_URL . FOLDER_PLUGINS . PLUGIN_FOLDER .'/copy.php', array('target_userid' => $getTargetUserid)) . '&source_userid=" + $(this).val());
}
});
// pulldown Ziel is clicked
$("#ziel").change(function () {
if($(this).val().length > 0) {
window.location.replace("'. SecurityUtils::encodeUrl(ADMIDIO_URL . FOLDER_PLUGINS . PLUGIN_FOLDER .'/copy.php', array('source_userid' => $getSourceUserid)).' &target_userid=" + $(this).val());
}
});
// source-checkbox of user is clicked
$("input[type=checkbox].sourcelist_checkbox").click(function(){
var checkbox = $(this);
var row_id = $(this).attr("id");
var pos = row_id.search("_");
var source_usfid = row_id.substring(pos+1);
$("input[type=checkbox].sourcelist_checkbox").prop("checked", false);
$("input[type=checkbox]#sourcefield_"+source_usfid).prop("checked", true);
});
// target-checkbox of user is clicked --> change data
$("input[type=checkbox].targetlist_checkbox").click(function(){
var targetcheckbox = $(this);
var row_id = targetcheckbox.attr("id");
var pos = row_id.search("_");
var target_usfid = row_id.substring(pos+1);
var sourcecheckbox = $("input[type=checkbox].sourcelist_checkbox:checked");
if(sourcecheckbox.length == 1) {
var row_id = sourcecheckbox.attr("id");
var pos = row_id.search("_");
var source_usfid = row_id.substring(pos+1);
$.post("'. SecurityUtils::encodeUrl(ADMIDIO_URL . FOLDER_PLUGINS . PLUGIN_FOLDER .'/copy.php', array('mode' => 'assign', 'target_userid' => $getTargetUserid, 'source_userid' => $getSourceUserid)) .'&source_usfid=" + source_usfid + "&target_usfid=" + target_usfid,
function(data){
// check if error occurs
if(data == "success") {
//$("#targetval_"+target_usfid).fadeOut(3000);
$("#targetval_"+target_usfid).hide();
$("#targetval_"+target_usfid).text($("#sourceval_"+source_usfid).text());
$("#targetval_"+target_usfid).fadeIn(1200);
}
else if(data == "unequal_datatype"){
alert("'.$gL10n->get('PLG_MITGLIEDSBEITRAG_UNEQUAL_DATATYPE').'");
return false;
}
else {
alert(data);
return false;
}
return true;
}
);
$("input[type=checkbox].sourcelist_checkbox").prop("checked", false);
}
$("input[type=checkbox].targetlist_checkbox").prop("checked", false);
});
';
$page->addJavascript($javascriptCode, true);
$membersSelectString = '';
$members = list_members(array('FIRST_NAME', 'LAST_NAME', 'BIRTHDAY'), 0);
foreach ($members as $member => $memberdata)
{
$birthday = '';
$objBirthday = \DateTime::createFromFormat('Y-m-d', $memberdata['BIRTHDAY']);
if ($objBirthday !== false)
{
$birthday = ', '.$objBirthday->format($gSettingsManager->getString('system_date'));
}
$members[$member] = $memberdata['LAST_NAME'].', '.$memberdata['FIRST_NAME'].$birthday;
$membersSelectString = $membersSelectString.'<option value='.$member.'>'.$memberdata['LAST_NAME'].', '.$memberdata['FIRST_NAME'].$birthday.'</option>';
}
asort($members);
$page->addHtml($gL10n->get('PLG_MITGLIEDSBEITRAG_COPY_HEADERINFO'));
$form = new HtmlForm('copy_selection_form', '', $page, array('type' => 'navbar', 'setFocus' => false));
$form->addSelectBox('quelle', $gL10n->get('PLG_MITGLIEDSBEITRAG_SOURCE'), $members, array('defaultValue' => $getSourceUserid, 'helpTextIdLabel' => 'PLG_MITGLIEDSBEITRAG_SOURCE_DESC', 'showContextDependentFirstEntry' => true, 'property' => HtmlForm::FIELD_REQUIRED));
$form->addSelectBox('ziel', $gL10n->get('PLG_MITGLIEDSBEITRAG_TARGET'), $members, array('defaultValue' => $getTargetUserid, 'helpTextIdLabel' => 'PLG_MITGLIEDSBEITRAG_TARGET_DESC', 'showContextDependentFirstEntry' => true, 'property' => HtmlForm::FIELD_REQUIRED));
$page->addHtml($form->show(false));
// create table object
$table = new HtmlTable('tbl_copy', $page, true, true, 'table table-condensed');
$table->setMessageIfNoRowsFound('SYS_NO_ENTRIES');
// create array with all column heading values
$columnHeading = array(
$gL10n->get('PLG_MITGLIEDSBEITRAG_SOURCE'),
$gL10n->get('PLG_MITGLIEDSBEITRAG_CHOICE'),
$gL10n->get('SYS_PROFILE_FIELD'),
$gL10n->get('PLG_MITGLIEDSBEITRAG_CHOICE'),
$gL10n->get('PLG_MITGLIEDSBEITRAG_TARGET')
);
$table->setColumnAlignByArray(array('center', 'center', 'center', 'center', 'center'));
$table->addRowHeadingByArray($columnHeading);
if($getSourceUserid == 0)
{
$table->setDatatablesColumnsHide(array(2));
}
if($getTargetUserid == 0)
{
$table->setDatatablesColumnsHide(array(4));
}
// show rows
foreach($gProfileFields->getProfileFields() as $field)
{
$htmlSourceMarker = ' ';
$htmlProfileField = ' ';
$htmlTargetMarker = ' ';
//1. Spalte
if(strlen($userSource->getValue($field->getValue('usf_name_intern'))) > 0)
{
$htmlSource = '<div class="sourceval_'.$field->getValue('usf_id').'" id="sourceval_'.$field->getValue('usf_id').'">'.$userSource->getValue($field->getValue('usf_name_intern')).'</div>';
}
else
{
$htmlSource = '<div class="sourceval_'.$field->getValue('usf_id').'" id="sourceval_'.$field->getValue('usf_id').'">'.' '.'</div>';
}
//2. Spalte
$htmlSourceMarker = '<input type="checkbox" id="sourcefield_'.$field->getValue('usf_id').'" name="sourcefield_'.$field->getValue('usf_id').'" class="sourcelist_checkbox" /><b id="loadindicator_sourcefield_'.$field->getValue('usf_id').'"></b>';
//3. Spalte
$htmlProfileField = addslashes($field->getValue('usf_name'));
//4. Spalte
$htmlTargetMarker = '<input type="checkbox" id="targetfield_'.$field->getValue('usf_id').'" name="targetfield_'.$field->getValue('usf_id').'" class="targetlist_checkbox" /><b id="loadindicator_targetfield_'.$field->getValue('usf_id').'"></b>';
//5. Spalte
if(strlen($userTarget->getValue($field->getValue('usf_name_intern'))) > 0)
{
$htmlTarget = '<div class="targetval_'.$field->getValue('usf_id').'" id="targetval_'.$field->getValue('usf_id').'">'.$userTarget->getValue($field->getValue('usf_name_intern')).'</div>';
}
else
{
$htmlTarget = '<div class="targetval_'.$field->getValue('usf_id').'" id="targetval_'.$field->getValue('usf_id').'">'.' '.'</div>';
}
// create array with all column values
$columnValues = array(
$htmlSource,
$htmlSourceMarker,
$htmlProfileField,
$htmlTargetMarker,
$htmlTarget
);
$table->addRowByArray($columnValues);
}//End Foreach
$page->addHtml($table->show(false));
$page->show();
}