/
tokenform.php
534 lines (510 loc) · 31.5 KB
/
tokenform.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
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
<?php
/**
* Add token entry
*/
$locale = convertLStoDateTimePickerLocale(Yii::app()->session['adminlang']);
?>
<div class='<?php if (!isset($ajax) || $ajax = false): ?>col-12 side-body <?php echo getSideBodyClass(false); ?> <?php endif; ?>'>
<?php if (!isset($ajax) || $ajax = false) { ?>
<h3>
<?php
if ($token_subaction == "edit") {
eT("Edit survey participant");
} else {
eT("Add survey participant");
}
?>
</h3>
<?php } ?>
<?php
foreach ($tokendata as $Key => $Value) {
$$Key = $Value;
}
?>
<div id="edittoken-error-container" class="row" style="display: none;">
<?php
$this->widget('ext.AlertWidget.AlertWidget', [
'text' => '<span class="alert-content"></span>',
'type' => 'danger',
]);
?>
</div>
<div class="row">
<div class="col-12 content-right">
<?php echo CHtml::form(array("admin/tokens/sa/{$token_subaction}/surveyid/{$surveyid}/tokenid/{$tokenid}"),
'post',
array(
'id' => 'edittoken',
'class' => '',
'data-additional-attributes-validation-error' => gT("Some mandatory additional attributes were left blank. Please review them."),
'data-expiration-validation-error' => gT('Participant expiration date can\'t be lower than the "Valid from" date'),
)
); ?>
<!-- Tabs -->
<?php if( count($attrfieldnames) > 0 ):?>
<ul class="nav nav-tabs" id="edit-survey-text-element-language-selection">
<!-- Common -->
<li role="presentation" class="nav-item">
<a class="nav-link active" data-bs-toggle="tab" href="#general" aria-expanded="true">
<?php eT('General'); ?>
</a>
</li>
<!-- Custom attibutes -->
<li role="presentation" class="nav-item">
<a class="nav-link" data-bs-toggle="tab" href="#custom" aria-expanded="false">
<?php eT('Additional attributes'); ?>
</a>
</li>
</ul>
<?php endif; ?>
<!-- Tabs content-->
<div class="tab-content">
<div id="general" class="tab-pane fade show active">
<div class="row">
<!-- General -->
<div class="ex-form-group mb-3 col-6">
<!-- ID -->
<label class="form-label">ID:</label>
<div class="">
<p class="form-control-static">
<?php
if ($token_subaction == "edit") {
echo $tokenid;
} else {
eT("Auto");
}
?>
</p>
</div>
</div>
<div class="ex-form-group mb-3 col-6">
<!--
TODO:
To take in account the anonomyzed survey case (completed field contain no date, but a {Y,N}), the code become more complexe
It will need a refactorisation .
maybe a widget? At least, a lot of variable should be set in the controller (classes etc)
-->
<?php $sCointainerClass = ($oSurvey->anonymized != 'Y') ? 'yes-no-date-container' : 'yes-no-container'; ?>
<!-- Completed -->
<div id="completed-container" class="">
<label class="form-label" for='completed'>
<?php eT("Completed?"); ?>
</label>
<div class="selector__yesNoContainer <?php echo $sCointainerClass; ?>"
id="completed-yes-no-date-container"
data-locale="<?php echo $locale ?>">
<div class="row">
<?php if ($oSurvey->anonymized != 'Y'): ?>
<?php $bCompletedValue = "0";
if (isset($completed) && $completed != 'N') {
$completedDBFormat = $completed;
$bCompletedValue = "1";
$completed = convertToGlobalSettingFormat($completed, true);
} ?>
<div>
<?php $this->widget('ext.ButtonGroupWidget.ButtonGroupWidget', [
'name' => "completed-switch",
'htmlOptions' => ['class' => "YesNoDateSwitch action_toggle_bootstrap_switch mb-1"],
'checkedOption' => $bCompletedValue,
'selectOptions' => [
'1' => gT('Yes'),
'0' => gT('No'),
],
]); ?>
</div>
<?php else: ?>
<div>
<?php $completedDBFormat = $completed;
$bCompletedValue = (isset($completed) && $completed != 'N') ? "1" : "0";
$completed = (isset($completed) && $completed != 'N') ? 'Y' : 'N'; ?>
<?php $this->widget('ext.ButtonGroupWidget.ButtonGroupWidget', [
'name' => "completed-switch",
'htmlOptions' => ['class' => "YesNoSwitch action_toggle_bootstrap_switch mb-1"],
'checkedOption' => $bCompletedValue,
'selectOptions' => [
'1' => gT('Yes'),
'0' => gT('No'),
],
]); ?>
</div>
<?php endif; ?>
<?php if ($oSurvey->anonymized !== 'Y'): ?>
<div class="">
<div id="sent-date-container" class="date-container <?= !$bCompletedValue ? "d-none" : "" ?>">
<div id="completed-date_datetimepicker" class="input-group date">
<input class="YesNoDatePicker form-control"
id="completed-date" type="text"
value="<?php echo isset($completed) ? $completed : '' ?>"
name="completed-date"
data-locale="<?php echo $locale ?>"
data-format="<?php echo $dateformatdetails['jsdate']; ?> HH:mm">
<span class="input-group-text datepicker-icon"><span class="ri-calendar-2-fill"></span></span>
</div>
</div>
</div>
<?php endif; ?>
</div>
<input class='form-control d-none YesNoDateHidden' type='text' size='20' id='completed' name='completed' value="<?php if (isset($completed)) {echo $completed; } else {echo "N"; }?>" />
</div>
</div>
</div>
<!-- First name, Last name -->
<div class="ex-form-group mb-3 col-6">
<label class="form-label" for='firstname'>
<?php eT("First name:"); ?>
</label>
<div class="">
<?= TbHtml::textField('firstname',
$firstname,
[
'class' => 'form-control',
'size' => '30',
]
); ?>
</div>
</div>
<div class="ex-form-group mb-3 col-6">
<label class="form-label" for='lastname'>
<?php eT("Last name:"); ?>
</label>
<div class="">
<?= TbHtml::textField('lastname',
$lastname,
[
'class' => 'form-control',
'size' => '30',
]
); ?>
</div>
</div>
<!-- Token, language -->
<div class="ex-form-group mb-3 col-6">
<label class="form-label" for='token'>
<?php eT("Access code:"); ?>
</label>
<div class="">
<?= TbHtml::textField('token',
(isset($token) ? $token : ""),
[
'class' => 'form-control',
'size' => '20',
'maxlength' => $iTokenLength
]
); ?>
<?php if ($token_subaction == "addnew") : ?>
<?php
$this->widget('ext.AlertWidget.AlertWidget', [
'text' => gT(
"You can leave this blank, and automatically generate access codes using 'Generate access codes'"
),
'type' => 'info',
'htmlOptions' => ['class' => 'mt-1'],
]);
?>
<?php endif; ?>
</div>
</div>
<div class="ex-form-group mb-3 col-6">
<label class="form-label" for='language'>
<?php eT("Language:"); ?>
</label>
<div class="">
<?php if (isset($language)) {
echo languageDropdownClean($surveyid, $language);
} else {
echo languageDropdownClean($surveyid, Survey::model()->findByPk($surveyid)->language);
} ?>
</div>
</div>
</div>
<div class="row">
<!-- Email, Email Status -->
<div class="ex-form-group mb-3 col-6">
<label class="form-label" for='email'>
<?php eT("Email:"); ?>
</label>
<div class="">
<?= TbHtml::emailField('email',
$email,
[
'class' => 'form-control',
'size' => '50',
'maxlength' => '320',
'multiple' => true
]
); ?>
</div>
</div>
<!-- Email Status -->
<div class="ex-form-group mb-3 col-6">
<label class="form-label" for='emailstatus'>
<?php eT("Email status:"); ?>
</label>
<div class="">
<?= TbHtml::textField('emailstatus',
$emailstatus,
[
'class' => 'form-control',
'size' => '50',
'maxlength' => '320',
'placeholder' => 'OK'
]
); ?>
</div>
</div>
<!-- Invitation sent, Reminder sent -->
<div class="ex-form-group mb-3 col-6">
<!-- Invitation sent -->
<label class="form-label" for='sent'>
<?php eT("Invitation sent?"); ?>
</label>
<div class="selector__yesNoContainer <?php echo $sCointainerClass; ?>" id="sent-yes-no-date-container"
data-locale="<?php echo $locale ?>">
<div class="row">
<div class="">
<?php if ($oSurvey->anonymized != 'Y'): ?>
<?php
// TODO: move to controller
$bSwitchValue = (isset($sent) && $sent != 'N') ? "1" : "0";
$bRemindSwitchValue = (isset($remindersent) && $remindersent != 'N') ? "1" : "0";
$bSwitchValue = "0";
if (isset($sent) && $sent != 'N') {
$bSwitchValue = "1";
$sentDBValue = $sent;
$sent = convertToGlobalSettingFormat($sent, true);
}
$bRemindSwitchValue = "0";
if (isset($remindersent) && $remindersent != 'N') {
$bRemindSwitchValue = "1";
$remindersentDBValue = $remindersent;
$remindersent = convertToGlobalSettingFormat($remindersent, true);
} ?>
<?php $this->widget('ext.ButtonGroupWidget.ButtonGroupWidget', [
'name' => "sent-switch",
'htmlOptions' => ['class' => "YesNoDateSwitch action_toggle_bootstrap_switch mb-1"],
'checkedOption' => $bSwitchValue,
'selectOptions' => [
'1' => gT('Yes'),
'0' => gT('No'),
],
]); ?>
<?php else: ?>
<?php
$sentDBValue = $sent;
$remindersentDBValue = $remindersent;
$bSwitchValue = (isset($sent) && $sent != 'N') ? "1" : "0";
$bRemindSwitchValue = (isset($remindersent) && $remindersent != 'N') ? "1" : "0";
?>
<?php $this->widget('ext.ButtonGroupWidget.ButtonGroupWidget', [
'name' => "sent-switch",
'htmlOptions' => ['class' => "YesNoSwitch action_toggle_bootstrap_switch mb-1"],
'checkedOption' => $bSwitchValue,
'selectOptions' => [
'1' => gT('Yes'),
'0' => gT('No'),
],
]); ?>
<?php endif; ?>
</div>
<div class="">
<div id="sent-date-container" data-parent="#sent-switch" class="selector__date-container_hidden date-container <?= !$bSwitchValue ? "d-none" : "" ?>">
<!-- Sent Date -->
<div id="sent-date_datetimepicker" class="input-group date">
<input class="YesNoDatePicker form-control"
id="sent-date"
type="text"
value="<?php echo isset($sent) && $sent != 'N' ? $sent : '' ?>"
name="sent-date"
data-locale="<?php echo $locale ?>"
data-format="<?php echo $dateformatdetails['jsdate']; ?> HH:mm">
<span class="input-group-text datepicker-icon"><span class="ri-calendar-2-fill"></span></span>
</div>
</div>
</div>
</div>
<input class='form-control d-none YesNoDateHidden' type='text' size='20' id='sent' name='sent' value="<?php if (isset($sent)) {echo $sent; } else {echo "N"; }?>" />
</div>
</div>
<div class="ex-form-group mb-3 col-6">
<!-- Reminder sent -->
<label class="form-label" for='remindersent'>
<?php eT("Reminder sent?"); ?>
</label>
<div class="selector__yesNoContainer <?php echo $sCointainerClass; ?>" id="remind-yes-no-date-container"
data-locale="<?php echo $locale ?>">
<div class="row">
<div>
<?php if ($oSurvey->anonymized !== 'Y'): ?>
<?php $this->widget('ext.ButtonGroupWidget.ButtonGroupWidget', [
'name' => "remind-switch",
'htmlOptions' => ['class' => "YesNoDateSwitch action_toggle_bootstrap_switch mb-1"],
'checkedOption' => $bRemindSwitchValue,
'selectOptions' => [
'1' => gT('Yes'),
'0' => gT('No'),
],
]); ?>
<?php else: ?>
<?php $this->widget('ext.ButtonGroupWidget.ButtonGroupWidget', [
'name' => "remind-switch",
'htmlOptions' => ['class' => "YesNoSwitch action_toggle_bootstrap_switch mb-1"],
'checkedOption' => $bRemindSwitchValue,
'selectOptions' => [
'1' => gT('Yes'),
'0' => gT('No'),
],
]); ?>
<?php endif; ?>
</div>
<div class="">
<div id="remind-date-container" data-parent="#remind-switch" class="selector__date-container_hidden date-container <?= !$bRemindSwitchValue ? "d-none" : "" ?>">
<div id="remind-date_datetimepicker" class="input-group date">
<input class="YesNoDatePicker form-control"
id="remind-date"
type="text"
value="<?php echo isset($remindersent) && $remindersent != 'N' ? $remindersent : '' ?>"
name="remind-date"
data-locale="<?php echo $locale ?>"
data-format="<?php echo $dateformatdetails['jsdate']; ?> HH:mm">
<span class="input-group-text datepicker-icon"><span class="ri-calendar-2-fill"></span></span>
</div>
</div>
</div>
</div>
<input class='form-control d-none YesNoDateHidden' type='text' size='20' id='remindersent' name='remindersent' value="<?php if (isset($remindersent) && $remindersent!='N') {echo $remindersent; } else {echo "N"; }?>" />
</div>
</div>
<!-- Reminder count -->
<?php if ($token_subaction == "edit"): ?>
<!-- Reminder count, Uses left -->
<div class="ex-form-group mb-3 col-6">
<label class="form-label" for='remindercount'>
<?php eT("Reminder count:"); ?>
</label>
<input class='form-control' type='number' size='6' id='remindercount' name='remindercount' value="<?php echo $remindercount; ?>"/>
</div>
<?php endif; ?>
<!-- Uses left -->
<div class="ex-form-group mb-3 col-6">
<label class="form-label" for='usesleft'>
<?php eT("Uses left:"); ?>
</label>
<input class='form-control' type='number' size='20' id='usesleft' name='usesleft' value="<?php if (isset($usesleft)) {
echo $usesleft;
} else {
echo " 1 ";
} ?>"/>
</div>
</div>
<div class="row">
<div class="col-6">
<!-- Valid from to -->
<div class="ex-form-group mb-3">
<?php
if (isset($validfrom) && $validfrom != 'N') {
$validfrom = convertToGlobalSettingFormat($validfrom, true);
}
if (isset($validuntil) && $validuntil != 'N') {
$validuntil = convertToGlobalSettingFormat($validuntil, true);
}
?>
<!-- From -->
<label class="form-label" for='validfrom'>
<?php eT("Valid from"); ?>:</label>
<div class=" has-feedback">
<div id="validfrom_datetimepicker" class="input-group date">
<input class="YesNoDatePicker form-control" id="validfrom" type="text" value="<?php echo isset($validfrom) ? $validfrom : '' ?>" name="validfrom"
data-format="<?php echo $dateformatdetails['jsdate']; ?> HH:mm"
data-locale="<?php echo convertLStoDateTimePickerLocale(Yii::app()->session['adminlang']); ?>">
<span class="input-group-text datepicker-icon"><span class="ri-calendar-2-fill"></span></span>
</div>
</div>
</div>
</div>
<div class="col-6">
<div class="ex-form-group mb-3">
<!-- To -->
<label class="form-label" for='validuntil'>
<?php eT('Until:'); ?>
</label>
<div class="has-feedback">
<div id="validuntil_datetimepicker" class="input-group date">
<input class="YesNoDatePicker form-control" id="validuntil" type="text" value="<?php echo isset($validuntil) ? $validuntil : '' ?>" name="validuntil"
data-format="<?php echo $dateformatdetails['jsdate']; ?> HH:mm"
data-locale="<?php echo convertLStoDateTimePickerLocale(Yii::app()->session['adminlang']); ?>">
<span class="input-group-text datepicker-icon"><span class="ri-calendar-2-fill"></span></span>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Custom attibutes -->
<div id="custom" class="tab-pane fade">
<!-- Attributes -->
<?php foreach ($attrfieldnames as $attr_name => $attr_description): ?>
<div class="ex-form-group mb-3 col-6">
<label class="form-label" for='<?php echo $attr_name; ?>'>
<?php echo $attr_description['description'] . ($attr_description['mandatory'] == 'Y' ? '*' : '') ?>:
</label>
<div class="">
<input
class='form-control<?= $attr_description['mandatory'] == 'Y' ? ' mandatory-attribute' : '' ?>'
type='text'
size='55'
id='<?php echo $attr_name; ?>'
name='<?php echo $attr_name; ?>'
value='<?php if (isset($$attr_name)) {
echo htmlspecialchars((string) $$attr_name, ENT_QUOTES, 'utf-8');
} ?>'
/>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
<!-- Buttons -->
<p>
<?php
switch ($token_subaction) {
case "edit":
?>
<input type='submit' class="d-none" value='<?php eT("Update participant entry"); ?>'/>
<input type='hidden' name='subaction' value='updatetoken'/>
<input type='hidden' name='tid' value='<?php echo $tokenid; ?>'/>
<?php break;
case "addnew": ?>
<input type='submit' class="d-none" value='<?php eT("Add participant entry"); ?>'/>
<input type='hidden' name='subaction' value='inserttoken'/>
<?php break;
} ?>
<input type='hidden' name='sid' value='<?php echo $surveyid; ?>'/>
</p>
<?php echo CHtml::endForm() ?>
</div>
</div>
</div>
<?php if ($token_subaction == "addnew"): ?>
<!-- Empty Token Confirmation Modal -->
<div class="modal fade" tabindex="-1" role="dialog" id="emptyTokenConfirmationModal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title"><?= gT('Create empty participant') ?></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<?= gT("You are about to create a participant without the basic details. Are you sure you want to proceed?") ?>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-cancel" data-bs-dismiss="modal">
<?php eT("Cancel");?>
</button>
<button role="button" type="button" class="btn btn-primary" id="save-empty-token">
<?php eT("Save");?>
</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<?php endif; ?>