ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
getconsent.php
Go to the documentation of this file.
1 <?php
20 session_cache_limiter('nocache');
21 
23 
24 SimpleSAML\Logger::info('Consent - getconsent: Accessing consent interface');
25 
26 if (!array_key_exists('StateId', $_REQUEST)) {
28  'Missing required StateId query parameter.'
29  );
30 }
31 
32 $id = $_REQUEST['StateId'];
34 
35 if (array_key_exists('core:SP', $state)) {
36  $spentityid = $state['core:SP'];
37 } else if (array_key_exists('saml:sp:State', $state)) {
38  $spentityid = $state['saml:sp:State']['core:SP'];
39 } else {
40  $spentityid = 'UNKNOWN';
41 }
42 
43 
44 // The user has pressed the yes-button
45 if (array_key_exists('yes', $_REQUEST)) {
46  if (array_key_exists('saveconsent', $_REQUEST)) {
47  SimpleSAML\Logger::stats('consentResponse remember');
48  } else {
49  SimpleSAML\Logger::stats('consentResponse rememberNot');
50  }
51 
52  $statsInfo = array(
53  'remember' => array_key_exists('saveconsent', $_REQUEST),
54  );
55  if (isset($state['Destination']['entityid'])) {
56  $statsInfo['spEntityID'] = $state['Destination']['entityid'];
57  }
58  SimpleSAML_Stats::log('consent:accept', $statsInfo);
59 
60  if ( array_key_exists('consent:store', $state)
61  && array_key_exists('saveconsent', $_REQUEST)
62  && $_REQUEST['saveconsent'] === '1'
63  ) {
64  // Save consent
65  $store = $state['consent:store'];
66  $userId = $state['consent:store.userId'];
67  $targetedId = $state['consent:store.destination'];
68  $attributeSet = $state['consent:store.attributeSet'];
69 
71  'Consent - saveConsent() : [' . $userId . '|' .
72  $targetedId . '|' . $attributeSet . ']'
73  );
74  try {
75  $store->saveConsent($userId, $targetedId, $attributeSet);
76  } catch (Exception $e) {
77  SimpleSAML\Logger::error('Consent: Error writing to storage: ' . $e->getMessage());
78  }
79  }
80 
82 }
83 
84 // Prepare attributes for presentation
85 $attributes = $state['Attributes'];
86 $noconsentattributes = $state['consent:noconsentattributes'];
87 
88 // Remove attributes that do not require consent
89 foreach ($attributes AS $attrkey => $attrval) {
90  if (in_array($attrkey, $noconsentattributes, true)) {
91  unset($attributes[$attrkey]);
92  }
93 }
95  'attributes' => &$attributes
96 );
97 
98 // Reorder attributes according to attributepresentation hooks
99 SimpleSAML\Module::callHooks('attributepresentation', $para);
100 
101 // Make, populate and layout consent form
102 $t = new SimpleSAML_XHTML_Template($globalConfig, 'consent:consentform.php');
103 $t->data['srcMetadata'] = $state['Source'];
104 $t->data['dstMetadata'] = $state['Destination'];
105 $t->data['yesTarget'] = SimpleSAML\Module::getModuleURL('consent/getconsent.php');
106 $t->data['yesData'] = array('StateId' => $id);
107 $t->data['noTarget'] = SimpleSAML\Module::getModuleURL('consent/noconsent.php');
108 $t->data['noData'] = array('StateId' => $id);
109 $t->data['attributes'] = $attributes;
110 $t->data['checked'] = $state['consent:checked'];
111 
112 // Fetch privacypolicy
113 if (array_key_exists('privacypolicy', $state['Destination'])) {
114  $privacypolicy = $state['Destination']['privacypolicy'];
115 } elseif (array_key_exists('privacypolicy', $state['Source'])) {
116  $privacypolicy = $state['Source']['privacypolicy'];
117 } else {
118  $privacypolicy = false;
119 }
120 if ($privacypolicy !== false) {
121  $privacypolicy = str_replace(
122  '%SPENTITYID%',
123  urlencode($spentityid),
124  $privacypolicy
125  );
126 }
127 $t->data['sppp'] = $privacypolicy;
128 
129 // Set focus element
130 switch ($state['consent:focus']) {
131 case 'yes':
132  $t->data['autofocus'] = 'yesbutton';
133  break;
134 case 'no':
135  $t->data['autofocus'] = 'nobutton';
136  break;
137 case null:
138 default:
139  break;
140 }
141 
142 if (array_key_exists('consent:store', $state)) {
143  $t->data['usestorage'] = true;
144 } else {
145  $t->data['usestorage'] = false;
146 }
147 
148 if (array_key_exists('consent:hiddenAttributes', $state)) {
149  $t->data['hiddenAttributes'] = $state['consent:hiddenAttributes'];
150 } else {
151  $t->data['hiddenAttributes'] = array();
152 }
153 
154 $t->show();
static debug($string)
Definition: Logger.php:213
if(!isset($state['consent:showNoConsentAboutService'])|| $state['consent:showNoConsentAboutService']) $statsInfo
Definition: noconsent.php:34
$t
Definition: getconsent.php:102
static callHooks($hook, &$data=null)
Call a hook in all enabled modules.
Definition: Module.php:364
static resumeProcessing($state)
Continues processing of the state.
$noconsentattributes
Definition: getconsent.php:86
if(! $oauthconfig->getBoolean('getUserInfo.enable', FALSE)) $store
Definition: getUserInfo.php:11
static getModuleURL($resource, array $parameters=array())
Get absolute URL to a specified module resource.
Definition: Module.php:303
static stats($string)
Definition: Logger.php:224
static info($string)
Definition: Logger.php:201
foreach($attributes AS $attrkey=> $attrval) $para
Definition: getconsent.php:94
static error($string)
Definition: Logger.php:168
static loadState($id, $stage, $allowMissing=false)
Retrieve saved state.
Definition: State.php:259
if(array_key_exists('yes', $_REQUEST)) $attributes
Definition: getconsent.php:85
Create styles array
The data for the language used.
$globalConfig
Definition: getconsent.php:22
$state
Definition: getconsent.php:33
if(!array_key_exists('StateId', $_REQUEST)) $id
Definition: getconsent.php:32
static getInstance($instancename='simplesaml')
Get a configuration file by its instance name.
static log($event, array $data=array())
Notify about an event.
Definition: Stats.php:71