-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgdpr.php
474 lines (435 loc) · 13.9 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
<?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() {
_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() {
_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);
$entities[] = [
'module' => 'uk.co.vedaconsulting.gdpr',
'name' => 'contributionpagecustomdata',
'update' => 'never',
'entity' => 'OptionValue',
'params' => [
'label' => ts('Contribution Page'),
'name' => 'civicrm_contribution_page',
'value' => 'ContributionPage',
'option_group_id' => 'cg_extend_objects',
'is_active' => 1,
'version' => 3,
],
];
}
/**
* 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_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);
}
}
}
/**
* Implements hook_civicrm_postProcess().
*/
function gdpr_civicrm_postProcess($formName, $form) {
if ($formName == 'CRM_Contribute_Form_Contribution_Confirm') {
$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);
}
}
}
}
/**
* 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::getUrlPath();
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']);
}
}
/**
* Add a Terms & Conditions tab for Event or Contribution Page.
*/
function _gdpr_addTermsConditionsTab(&$tabs, $entityType, $id) {
switch ($entityType) {
case 'event' :
$urlParams = array(
'path' => 'civicrm/event/manage/terms_conditions',
'qs' => 'reset=1&id=' . $id,
);
break;
case 'contribution_page' :
$urlParams = array(
'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'] = array(
'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[] = array( '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 $params associated array of navigation menus
*/
function gdpr_civicrm_navigationMenu( &$params ) {
// get the id of Contacts Menu
$contactsMenuId = CRM_Core_DAO::getFieldValue('CRM_Core_BAO_Navigation', 'Contacts', 'id', 'name');
// skip adding menu if there is no contacts menu
if ($contactsMenuId) {
// get the maximum key under contacts menu
$maxKey = max( array_keys($params[$contactsMenuId]['child']));
$params[$contactsMenuId]['child'][$maxKey+1] = array (
'attributes' => array (
'label' => 'GDPR Dashboard',
'name' => 'GDPR Dashboard',
'url' => 'civicrm/gdpr/dashboard?reset=1',
'permission' => 'access GDPR',
'operator' => NULL,
'separator' => FALSE,
'parentID' => $contactsMenuId,
'navID' => $maxKey+1,
'active' => 1
)
);
}
}
/**
* implementation of hook_civicrm_token
*/
function gdpr_civicrm_tokens( &$tokens ){
$tokens['contact'] = array(
'contact.comm_pref_supporter_url' => E::ts("Communication Preferences URL"),
'contact.comm_pref_supporter_link' => E::ts("Communication Preferences Link"),
);
}
/**
* implementation of hook_civicrm_tokenValues
*/
function gdpr_civicrm_tokenValues(&$values, $cids, $job = null, $tokens = array(), $context = null) {
if (!empty($tokens['contact'])) {
foreach ($cids as $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);
}
}
}
/**
* implementation of hook_civicrm_summaryActions
*/
function gdpr_civicrm_summaryActions( &$actions, $contactID ) {
$actions['comm_pref'] = array(
'title' => 'Communication Preferences Link',
'weight' => 999,
'ref' => 'comm_pref',
'key' => 'comm_pref',
'href' => CRM_Gdpr_CommunicationsPreferences_Utils::getCommPreferenceURLForContact($contactID, TRUE),
);
}
function gdpr_civicrm_permission(&$permissions) {
$prefix = E::ts('GDPR') . ': ';
$version = CRM_Utils_System::version();
if (version_compare($version, '4.6.1') >= 0) {
$permissions += array(
'access GDPR' => array(
$prefix . E::ts('access GDPR'),
E::ts('View GDPR related information'),
),
'forget contact' => array(
$prefix . E::ts('forget contact'),
E::ts('Anonymize contacts'),
),
'administer GDPR' => array(
$prefix . E::ts('administer GDPR'),
E::ts('Manage GDPR settings'),
),
);
}
else {
$permissions += array(
'access GDPR' => $prefix . E::ts('access GDPR'),
'forget contact' => $prefix . E::ts('forget contact'),
'administer GDPR' => $prefix . E::ts('administer GDPR'),
);
}
}
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(
array(
'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);
}
}
}