-
Notifications
You must be signed in to change notification settings - Fork 0
/
gdpr.php
707 lines (646 loc) · 21.7 KB
/
gdpr.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
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
<?php
require_once 'gdpr.civix.php';
use CRM_Gdpr_ExtensionUtil as E;
/**
* Implements hook_civicrm_config().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_config
*/
function gdpr_civicrm_config(&$config) {
_gdpr_civix_civicrm_config($config);
}
/**
* Implements hook_civicrm_xmlMenu().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_xmlMenu
*/
function gdpr_civicrm_xmlMenu(&$files) {
_gdpr_civix_civicrm_xmlMenu($files);
}
/**
* Implements hook_civicrm_install().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_install
*/
function gdpr_civicrm_install() {
// #188 - use install instead of managed entities hook to avoid fatal
$result = civicrm_api3('OptionValue', 'get', [
'sequential' => 1,
'option_group_id' => "cg_extend_objects",
'value' => "ContributionPage",
]);
if (empty($result['id'])) {
civicrm_api3('OptionValue', 'create', [
'label' => E::ts('Contribution Page'),
'name' => 'civicrm_contribution_page',
'value' => 'ContributionPage',
'option_group_id' => 'cg_extend_objects',
'is_active' => 1,
]);
}
_gdpr_civix_civicrm_install();
}
/**
* Implements hook_civicrm_postInstall().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_postInstall
*/
function gdpr_civicrm_postInstall() {
_gdpr_civix_civicrm_postInstall();
}
/**
* Implements hook_civicrm_uninstall().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_uninstall
*/
function gdpr_civicrm_uninstall() {
$result = civicrm_api3('CustomGroup', 'get', [
'sequential' => 1,
'extends' => "ContributionPage",
]);
if (!$result['is_error'] && $result['count'] <= 0) {
$result = civicrm_api3('OptionValue', 'get', [
'sequential' => 1,
'option_group_id' => "cg_extend_objects",
'value' => "ContributionPage",
]);
if (!empty($result['id'])) {
civicrm_api3('OptionValue', 'delete', [
'id' => $result['id'],
]);
}
}
_gdpr_civix_civicrm_uninstall();
}
/**
* Implements hook_civicrm_enable().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_enable
*/
function gdpr_civicrm_enable() {
_gdpr_civix_civicrm_enable();
}
/**
* Implements hook_civicrm_disable().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_disable
*/
function gdpr_civicrm_disable() {
_gdpr_civix_civicrm_disable();
}
/**
* Implements hook_civicrm_upgrade().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_upgrade
*/
function gdpr_civicrm_upgrade($op, CRM_Queue_Queue $queue = NULL) {
return _gdpr_civix_civicrm_upgrade($op, $queue);
}
/**
* Implements hook_civicrm_managed().
*
* Generate a list of entities to create/deactivate/delete when this module
* is installed, disabled, uninstalled.
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_managed
*/
function gdpr_civicrm_managed(&$entities) {
_gdpr_civix_civicrm_managed($entities);
}
/**
* Implements hook_civicrm_caseTypes().
*
* Generate a list of case-types.
*
* Note: This hook only runs in CiviCRM 4.4+.
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_caseTypes
*/
function gdpr_civicrm_caseTypes(&$caseTypes) {
_gdpr_civix_civicrm_caseTypes($caseTypes);
}
/**
* Implements hook_civicrm_angularModules().
*
* Generate a list of Angular modules.
*
* Note: This hook only runs in CiviCRM 4.5+. It may
* use features only available in v4.6+.
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_angularModules
*/
function gdpr_civicrm_angularModules(&$angularModules) {
_gdpr_civix_civicrm_angularModules($angularModules);
}
/**
* Implements hook_civicrm_alterSettingsFolders().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_alterSettingsFolders
*/
function gdpr_civicrm_alterSettingsFolders(&$metaDataFolders = NULL) {
_gdpr_civix_civicrm_alterSettingsFolders($metaDataFolders);
}
/**
* Implementation of hook_civicrm_alterContent
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_alterContent
*/
function gdpr_civicrm_alterContent(&$content, $context, $tplName, &$object) {
if ($context == 'page' && $tplName == 'CRM/Contact/Page/View/Summary.tpl') {
// Do not add content in AJAX generated page/form
// as they be inline page/form
if (isset($_GET['snippet'])) {
return;
}
// Get Contact Id
$contactId = $object->getVar('_contactId');
if (empty($contactId)) {
return;
}
require_once "CRM/Logging/Schema.php";
$config = CRM_Core_Config::singleton();
if ($config->logging) {
$addressHistoryAjaxUrl = CRM_Utils_System::url('civicrm/ajax/rest', 'className=CRM_Gdpr_Page_AJAX&fnName=getAddressHistory&json=1');
$addressHistoryContent = <<<EOD
<script type="text/javascript">
cj(document).ready(function(){
var contactId = "{$contactId}";
var getAddressHistoryUrl = "{$addressHistoryAjaxUrl}";
if (contactId)
{
cj.ajax({
type: "POST",
url: getAddressHistoryUrl,
data: { contactId : contactId },
success: function (data) {
var split = data.split('|');
if( split[0] != 0 ){
var linkHtml = '<div class="crm-content" align="right"><a href="javascript:void(0);" id="address_history_dialog_link"> Address History ('+split[0]+') </a></div>';
cj(linkHtml).insertAfter('#website-block');
cj(linkHtml).wrap('<div class="contact_panel"></div>');
cj('#address_history_dialog_link').click(function(){
var oTable = cj(split[1]).dataTable({
"bSort": true,
"bJQueryUI": true,
"bAutoWidth": false,
"bSortClasses": false
});
cj(oTable).wrap('<div id="address_history"></div>');
cj(oTable).parent('div').dialog({title: "Address History",
modal: true,
resizable: true,
bgiframe: true,
width: 675,
height: 400,
overlay: {
opacity: 0.5,
background: "black"
},
buttons: {
"Done": function() {
cj(this).dialog("destroy");
}
}
});//end dialog
});//end click
}//end if
}//end success
});//end ajax
}
});
</script>
EOD;
$addressHistoryContent = str_replace('&', '&', $addressHistoryContent);
$content = $content.$addressHistoryContent;
}
}
}
/**
* Implements hook_civicrm_buildForm().
*/
function gdpr_civicrm_buildForm($formName, $form) {
if ($formName == 'CRM_Event_Form_ManageEvent_EventInfo') {
CRM_Core_Resources::singleton()->addStyleFile('uk.co.vedaconsulting.gdpr', 'css/gdpr.css');
}
if ($formName == 'CRM_Event_Form_Registration_Register') {
CRM_Core_Resources::singleton()->addStyleFile('uk.co.vedaconsulting.gdpr', 'css/gdpr.css');
$tc = new CRM_Gdpr_SLA_Event($form->_eventId);
if ($tc->isEnabled(TRUE)) {
$tc->addField($form);
}
}
if ($formName == 'CRM_Event_Form_Registration_ThankYou') {
$cid = $form->_values['participant']['contact_id'];
if (!empty($cid)) {
$templatePath = realpath(dirname(__FILE__).'/templates');
CRM_Core_Region::instance('page-body')->add(
[
'template' => "{$templatePath}/CRM/Gdpr/Event/ThankYou.tpl"
]
);
//amend communication preference link/embed form in thank you page
CRM_Gdpr_CommunicationsPreferences_Utils::commsPreferenceInThankyouPage($cid, $form, 'Event');
}
}
if ($formName == 'CRM_Contribute_Form_Contribution_Main') {
CRM_Core_Resources::singleton()->addStyleFile('uk.co.vedaconsulting.gdpr', 'css/gdpr.css');
$tc = new CRM_Gdpr_SLA_ContributionPage($form->_id);
if ($tc->isEnabled(TRUE)) {
$tc->addField($form);
}
}
if ($formName == 'CRM_Contribute_Form_Contribution_ThankYou') {
// Contact id for logged in user.
$cid = $form->_contactID;
if ($cid) {
$templatePath = realpath(dirname(__FILE__) . '/templates');
CRM_Core_Region::instance('page-body')->add(
[
'template' => "{$templatePath}/CRM/Gdpr/Event/ThankYou.tpl"
]
);
//amend communication preference link/embed form in thank you page
CRM_Gdpr_CommunicationsPreferences_Utils::commsPreferenceInThankyouPage($cid, $form, 'ContributionPage');
}
}
if ($formName == 'CRM_Mailing_Form_Subscribe') {
$settings = CRM_Gdpr_CommunicationsPreferences_Utils::getSettings();
$settings = $settings[CRM_Gdpr_CommunicationsPreferences_Utils::SETTING_NAME];
if (!empty($settings['use_as_mailing_subscribe'])) {
$nullRef = NULL;
$cs = CRM_Utils_Request::retrieve('cs', 'String', $nullRef, FALSE, NULL, 'GET');
$cid = CRM_Utils_Request::retrieve('cid', 'Int', $nullRef, FALSE, NULL, 'GET');
$urlParams = ['reset' => 1];
if ($cid && $cs) {
$urlParams['cid'] = $cid;
$urlParams['cs'] = $cs;
}
$path = 'civicrm/gdpr/comms-prefs/update';
$commsPrefsUrl = CRM_Utils_System::url($path, $urlParams, TRUE, NULL, TRUE, TRUE);
CRM_Utils_System::redirect($commsPrefsUrl);
}
}
gdpr_includeShoreditchStylingIfEnabled();
}
/**
* Implements hook_civicrm_postProcess().
*/
function gdpr_civicrm_postProcess($formName, $form) {
//When Membership and Monetary is enabled on contribution page, then expecting the hook should be called twice on submission.
//we should not duplicate the data policy and T&C acceptance.
//it might be core bug, but incase we should avoid duplication
if ($formName == 'CRM_Contribute_Form_Contribution_Confirm' && empty($form->_params['gdprAccepted'])) {
$contact_id = $form->_contactID;
$contribution_page_id = $form->_id;
if ($contact_id && $contribution_page_id) {
$tc = new CRM_Gdpr_SLA_ContributionPage($contribution_page_id);
if ($tc->isEnabled(TRUE)) {
$tc->recordAcceptance($contact_id);
CRM_Gdpr_SLA_Utils::recordSLAAcceptance($contact_id);
$form->_params['gdprAccepted'] = TRUE;
}
}
}
}
/**
* Implements hook_civicrm_post().
*/
function gdpr_civicrm_post($op, $objectName, $objectId, &$objectRef) {
// Create activity for event Terms and Conditions.
if ($op == 'create' && $objectName == 'Participant') {
if (!empty($objectRef->event_id) && !empty($objectRef->contact_id)) {
// Acceptance not made on behalf of another.
if (empty($objectRef->registered_by_id)) {
$tc = new CRM_Gdpr_SLA_Event($objectRef->event_id);
$isRegisterForm = 'civicrm/event/register' == CRM_Utils_System::currentPath();
if ($isRegisterForm && $tc->isEnabled(TRUE)) {
CRM_Gdpr_SLA_Utils::recordSLAAcceptance($objectRef->contact_id);
$tc->recordAcceptance($objectRef->contact_id);
}
}
}
}
}
/*
* Implements hook_civicrm_tabset().
*/
function gdpr_civicrm_tabset($tabsetName, &$tabs, $context) {
//check if the tabset is Contact Summary Page
if ($tabsetName == 'civicrm/contact/view') {
$contactId = $context['contact_id'];
_gdpr_addGDPRTab($tabs, $contactId);
}
elseif ($tabsetName == 'civicrm/event/manage' && !empty($context['event_id'])) {
_gdpr_addTermsConditionsTab($tabs, 'event', $context['event_id']);
}
elseif ($tabsetName == 'civicrm/admin/contribute' && !empty($context['contribution_page_id'])) {
_gdpr_addTermsConditionsTab($tabs, 'contribution_page', $context['contribution_page_id']);
}
}
/**
* Implements hook_civicrm_export().
*/
function gdpr_civicrm_export($exportTempTable, $headerRows, $sqlColumns, $exportMode, $componentTable = '', $ids = []) {
$trackExports = CRM_Core_BAO_Setting::getItem(CRM_Gdpr_Constants::GDPR_SETTING_GROUP,'track_exports',NULL, FALSE);
if (version_compare(CRM_Utils_System::version(), '5.8.0', '>=') && $trackExports) {
switch ($exportMode) {
case CRM_Export_Form_Select::CONTACT_EXPORT:
CRM_Gdpr_Export::contact($ids);
break;
case CRM_Export_Form_Select::ACTIVITY_EXPORT:
CRM_Gdpr_Export::activity($ids);
break;
case CRM_Export_Form_Select::CONTRIBUTE_EXPORT:
CRM_Gdpr_Export::contribution($ids);
break;
}
}
}
/**
* Add a Terms & Conditions tab for Event or Contribution Page.
*/
function _gdpr_addTermsConditionsTab(&$tabs, $entityType, $id) {
switch ($entityType) {
case 'event' :
$urlParams = [
'path' => 'civicrm/event/manage/terms_conditions',
'qs' => 'reset=1&id=' . $id,
];
break;
case 'contribution_page' :
$urlParams = [
'path' => 'civicrm/admin/contribute/terms_conditions',
'qs' => 'reset=1&action=update&id=' . $id,
];
break;
default:
return;
}
$url = CRM_Utils_System::url($urlParams['path'], $urlParams['qs']);
$tabs['terms_conditions'] = [
'title' => E::ts('Terms & Conditions'),
'url' => $url,
'active' => TRUE,
'class' => 'ajaxForm',
];
}
/*
* Add a tab to show group subscription
*/
function gdpr_civicrm_tabs(&$tabs, $contactID) {
if (_gdpr_isCiviCRMVersion47()) {
return;
}
if (CRM_Core_Permission::check('access GDPR')) {
_gdpr_addGDPRTab($tabs, $contactID);
}
}
function _gdpr_addGDPRTab(&$tabs, $contactID) {
$url = CRM_Utils_System::url('civicrm/gdpr/view/tab', "reset=1&cid={$contactID}");
$tabs[] = [
'id' => 'gdprTab',
'url' => $url,
'title' => E::ts('GDPR'),
'weight' => 300,
'class' => 'livePage',
];
}
/**
* Checks if civicrm version is 4.7
*
* @return mixed
*/
function _gdpr_isCiviCRMVersion47(){
return version_compare(CRM_Utils_System::version(), '4.7', '>');
}
/**
* Add navigation for GDPR Dashboard
*
* @param array $menu associated array of navigation menus
*/
function gdpr_civicrm_navigationMenu(&$menu) {
_gdpr_civix_insert_navigation_menu($menu, 'Contacts', [
'label' => E::ts('GDPR Dashboard'),
'name' => 'GDPR Dashboard',
'url' => 'civicrm/gdpr/dashboard',
'permission' => 'access GDPR',
'operator' => 'OR',
'separator' => 0,
]);
_gdpr_civix_insert_navigation_menu($menu, 'Administer', [
'label' => E::ts('GDPR'),
'name' => 'gdpr_admin',
'url' => NULL,
'permission' => 'administer GDPR',
'operator' => NULL,
'separator' => NULL,
]);
_gdpr_civix_insert_navigation_menu($menu, 'Administer/gdpr_admin', [
'label' => E::ts('GDPR Settings'),
'name' => 'gdpr_admin_settings',
'url' => 'civicrm/gdpr/settings',
'permission' => 'administer GDPR',
'operator' => NULL,
'separator' => NULL,
]);
_gdpr_civix_insert_navigation_menu($menu, 'Administer/gdpr_admin', [
'label' => E::ts('Communication Preferences Settings'),
'name' => 'gdpr_admin_commsprefs',
'url' => 'civicrm/gdpr/comms-prefs/settings',
'permission' => 'administer GDPR',
'operator' => NULL,
'separator' => NULL,
]);
_gdpr_civix_navigationMenu($menu);
}
/**
* implementation of hook_civicrm_token
*/
function gdpr_civicrm_tokens(&$tokens) {
// Keeping this token only to sustain the old tokens otherwise,
// the token 'CommunicationPreferences' can be used in all places
$tokens['contact']['contact.comm_pref_supporter_url'] = E::ts("Communication Preferences URL");
$tokens['contact']['contact.comm_pref_supporter_link'] = E::ts("Communication Preferences Link");
$tokens['CommunicationPreferences'] = [
'CommunicationPreferences.comm_pref_supporter_url' => E::ts("Communication Preferences URL (Bulk Mailing)"),
'CommunicationPreferences.comm_pref_supporter_link' => E::ts("Communication Preferences Link (Bulk Mailing)"),
];
}
/**
* implementation of hook_civicrm_tokenValues
*/
function gdpr_civicrm_tokenValues(&$values, $cids, $job = null, $tokens = [], $context = null) {
if (!empty($tokens['contact']) OR !empty($tokens['CommunicationPreferences'])) {
/*
THIS CHANGE IS ONLY FOR ACTIONSCHEDULE (SEND EMAIL USING SCHEDULE REMINDER)
we have mentioned the contact custom tokens in token hook.
so whenever replaceHookToken called its trying replace Category 'Contact' tokens
(which cause null values in template result).
This is not happening when send email via contact summary or mailing,
because all other work flow to send emails are builds the contact details array
before replaceHookToken fired using this function CRM_Utils_Token::getTokenDetails().
When Action schedule send email, Contact Details get from BAO API Query
which doesn't return some default contact values ex: email_greetings,
postal greetings etc. So build the contact details array with all default values.
This changes is needed only when we have $tokens['contact']. Keeping this oly to sustain
the old token.
IN FUTURE or V3.0, WE CAN REMOVE THIS CHANGE ALONG WITH CONTACT CUSTOM TOKEN ABOVE.
*/
$tokenValues = [];
$cids = isset($cids) ? $cids : [];
if ($context == 'CRM_Core_BAO_ActionSchedule') {
list($tokenValues) = CRM_Utils_Token::getTokenDetails($cids, [], FALSE, FALSE);
}
foreach ($cids as $cid) {
if (!empty($tokenValues[$cid])) {
$values[$cid] = array_merge($values[$cid], $tokenValues[$cid]);
}
$commPrefURL = CRM_Gdpr_CommunicationsPreferences_Utils::getCommPreferenceURLForContact($cid);
$link = sprintf("<a href='%s' target='_blank'>%s</a>",$commPrefURL, E::ts('Communication Preferences'));
$values[$cid]['contact.comm_pref_supporter_url'] = $commPrefURL;
$values[$cid]['contact.comm_pref_supporter_link'] = html_entity_decode($link);
//For Bulk Mailing
$values[$cid]['CommunicationPreferences.comm_pref_supporter_url'] = $commPrefURL;
$values[$cid]['CommunicationPreferences.comm_pref_supporter_link'] = html_entity_decode($link);
}
}
}
/**
* implementation of hook_civicrm_summaryActions
*/
function gdpr_civicrm_summaryActions(&$actions, $contactID) {
$actions['comm_pref'] = [
'title' => E::ts('Communication Preferences Link'),
//need a weight parameter here, Contact BAO looking for weight key and returning notice message.
'weight' => 60,
'ref' => 'comm_pref',
'key' => 'comm_pref',
'href' => CRM_Gdpr_CommunicationsPreferences_Utils::getCommPreferenceURLForContact($contactID, TRUE),
];
}
function gdpr_civicrm_permission(&$permissions) {
$prefix = E::ts('CiviGDPR') . ': ';
$permissions += [
'access GDPR' => [
$prefix . E::ts('access GDPR'),
E::ts('View GDPR related information'),
],
'forget contact' => [
$prefix . E::ts('forget contact'),
E::ts('Anonymize contacts'),
],
'administer GDPR' => [
$prefix . E::ts('administer GDPR'),
E::ts('Manage GDPR settings'),
],
];
}
function gdpr_civicrm_searchTasks($objectName, &$tasks) {
if($objectName == 'contact'){
if(CRM_Core_Permission::check('forget contact')) {
$tasks[] = [
'title' => 'GDPR forget',
'class' => 'CRM_Gdpr_Form_Task_Contact'
];
}
}
}
/**
* Implements hook_civicrm_pageRun()
*/
function gdpr_civicrm_pageRun(&$page) {
$pageName = $page->getVar('_name');
if($pageName == 'CRM_Contact_Page_View_Summary') {
$cid = $page->getVar('_contactId');
$templatePath = realpath(dirname(__FILE__).'/templates');
CRM_Core_Region::instance('page-body')->add(
[
'template' => "{$templatePath}/CRM/Gdpr/Page/ContactSummary.tpl"
]
);
$accept_activity = CRM_Gdpr_SLA_Utils::getContactLastAcceptance($cid);
$accept_date = NULL;
if (!empty($accept_activity['activity_date_time'])) {
$accept_date = date('d/m/Y', strtotime($accept_activity['activity_date_time']));
$page->assign('lastAcceptanceDate', $accept_date);
}
}
if ($pageName == 'CRM_Event_Page_EventInfo') {
CRM_Core_Resources::singleton()->addStyleFile('uk.co.vedaconsulting.gdpr', 'css/gdpr.css');
}
gdpr_includeShoreditchStylingIfEnabled();
}
/**
* Checks if an extension is enabled
*
* @param string $key
* extension key
*
* @return bool
*/
function gdpr_isExtensionEnabled($key) {
$isEnabled = CRM_Core_DAO::getFieldValue(
'CRM_Core_DAO_Extension',
$key,
'is_active',
'full_name'
);
return !empty($isEnabled);
}
/**
* Includes Shoreditch styling for the extension, if Shoreditch is enabled
*
* @return void
*/
function gdpr_includeShoreditchStylingIfEnabled() {
if (!gdpr_isExtensionEnabled('org.civicrm.shoreditch')) {
return;
}
CRM_Core_Resources::singleton()->
addStyleFile('uk.co.vedaconsulting.gdpr', 'css/shoreditch-only.min.css', 10);
}
/**
* Wordpress filters to expose GDPR pages as shortcode.
*/
if (function_exists('add_filter')) {
add_filter('civicrm_shortcode_preprocess_atts', 'gdpr_amend_args', 10, 2);
}
/**
* Modify attributes of GDPR shortcodes for CiviCRM.
*
* @param $args
* @param $shortcode_atts
* @return mixed
*/
function gdpr_amend_args($args, $shortcode_atts) {
if ($shortcode_atts['component'] == 'gdpr') {
if ($shortcode_atts['action'] == 'update-preferences') {
$args['q'] = 'civicrm/gdpr/comms-prefs/update';
}
}
return $args;
}
/**
* Implements hook_civicrm_preProcess().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_preProcess
*
*/
function gdpr_civicrm_preProcess($formName, &$form) {
if ($formName == 'CRM_Contribute_Form_Contribution_ThankYou') {
$form->setVar('_contactID', $form->get('contactID'));
}
if ($formName == 'CRM_Core_Form_ShortCode') {
$form->components['gdpr'] = [
'label' => 'GDPR',
'select' => [],
];
$form->options[] = [
'key' => 'action',
'components' => ['gdpr'],
'options' => [
'update-preferences' => 'Update preferences',
],
];
}
}