ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
consentform.php
Go to the documentation of this file.
1<?php
17assert('is_array($this->data["srcMetadata"])');
18assert('is_array($this->data["dstMetadata"])');
19assert('is_string($this->data["yesTarget"])');
20assert('is_array($this->data["yesData"])');
21assert('is_string($this->data["noTarget"])');
22assert('is_array($this->data["noData"])');
23assert('is_array($this->data["attributes"])');
24assert('is_array($this->data["hiddenAttributes"])');
25assert('$this->data["sppp"] === false || is_string($this->data["sppp"])');
26
27// Parse parameters
28if (array_key_exists('name', $this->data['srcMetadata'])) {
29 $srcName = $this->data['srcMetadata']['name'];
30} elseif (array_key_exists('OrganizationDisplayName', $this->data['srcMetadata'])) {
31 $srcName = $this->data['srcMetadata']['OrganizationDisplayName'];
32} else {
33 $srcName = $this->data['srcMetadata']['entityid'];
34}
35
36if (is_array($srcName)) {
37 $srcName = $this->t($srcName);
38}
39
40if (array_key_exists('name', $this->data['dstMetadata'])) {
41 $dstName = $this->data['dstMetadata']['name'];
42} elseif (array_key_exists('OrganizationDisplayName', $this->data['dstMetadata'])) {
43 $dstName = $this->data['dstMetadata']['OrganizationDisplayName'];
44} else {
45 $dstName = $this->data['dstMetadata']['entityid'];
46}
47
48if (is_array($dstName)) {
49 $dstName = $this->t($dstName);
50}
51
52$srcName = htmlspecialchars($srcName);
53$dstName = htmlspecialchars($dstName);
54
55$attributes = $this->data['attributes'];
56
57$this->data['header'] = $this->t('{consent:consent:consent_header}');
58$this->data['head'] = '<link rel="stylesheet" type="text/css" href="/' .
59 $this->data['baseurlpath'] . 'module.php/consent/style.css" />' . "\n";
60
61$this->includeAtTemplateBase('includes/header.php');
62?>
63<p>
64<?php
65echo $this->t(
66 '{consent:consent:consent_accept}',
67 array( 'SPNAME' => $dstName, 'IDPNAME' => $srcName)
68);
69
70if (array_key_exists('descr_purpose', $this->data['dstMetadata'])) {
71 echo '</p><p>' . $this->t(
72 '{consent:consent:consent_purpose}',
73 array(
74 'SPNAME' => $dstName,
75 'SPDESC' => $this->getTranslator()->getPreferredTranslation(
76 SimpleSAML\Utils\Arrays::arrayize(
77 $this->data['dstMetadata']['descr_purpose'],
78 'en'
79 )
80 ),
81 )
82 );
83}
84?>
85</p>
86
87<form style="display: inline; margin: 0px; padding: 0px"
88 action="<?php echo htmlspecialchars($this->data['yesTarget']); ?>">
89<p style="margin: 1em">
90
91<?php
92if ($this->data['usestorage']) {
93 $checked = ($this->data['checked'] ? 'checked="checked"' : '');
94 echo '<input type="checkbox" name="saveconsent" ' . $checked .
95 ' value="1" /> ' . $this->t('{consent:consent:remember}');
96}
97
98// Embed hidden fields...
99foreach ($this->data['yesData'] as $name => $value) {
100 echo '<input type="hidden" name="' . htmlspecialchars($name) .
101 '" value="' . htmlspecialchars($value) . '" />';
102}
103?>
104 </p>
105 <button type="submit" name="yes" class="btn" id="yesbutton">
106 <?php echo htmlspecialchars($this->t('{consent:consent:yes}')) ?>
107 </button>
108</form>
109
110<form style="display: inline; margin-left: .5em;" action="<?php echo htmlspecialchars($this->data['noTarget']); ?>"
111 method="get">
112
113<?php
114foreach ($this->data['noData'] as $name => $value) {
115 echo('<input type="hidden" name="' . htmlspecialchars($name) .
116 '" value="' . htmlspecialchars($value) . '" />');
117}
118?>
119 <button type="submit" class="btn" name="no" id="nobutton">
120 <?php echo htmlspecialchars($this->t('{consent:consent:no}')) ?>
121 </button>
122</form>
123
124<?php
125if ($this->data['sppp'] !== false) {
126 echo "<p>" . htmlspecialchars($this->t('{consent:consent:consent_privacypolicy}')) . " ";
127 echo '<a target="_blank" href="' . htmlspecialchars($this->data['sppp']) . '">' . $dstName . "</a>";
128 echo "</p>";
129}
130
140function present_attributes($t, $attributes, $nameParent)
141{
142 $translator = $t->getTranslator();
143
144 $alternate = array('odd', 'even');
145 $i = 0;
146 $summary = 'summary="' . $t->t('{consent:consent:table_summary}') . '"';
147
148 if (strlen($nameParent) > 0) {
149 $parentStr = strtolower($nameParent) . '_';
150 $str = '<table class="attributes" ' . $summary . '>';
151 } else {
152 $parentStr = '';
153 $str = '<table id="table_with_attributes" class="attributes" '. $summary .'>';
154 $str .= "\n" . '<caption>' . $t->t('{consent:consent:table_caption}') .
155 '</caption>';
156 }
157
158 foreach ($attributes as $name => $value) {
159 $nameraw = $name;
160 $name = $translator->getAttributeTranslation($parentStr . $nameraw);
161
162 if (preg_match('/^child_/', $nameraw)) {
163 // insert child table
164 $parentName = preg_replace('/^child_/', '', $nameraw);
165 foreach ($value as $child) {
166 $str .= "\n" . '<tr class="odd"><td style="padding: 2em">' .
167 present_attributes($t, $child, $parentName) . '</td></tr>';
168 }
169 } else {
170 // insert values directly
171
172 $str .= "\n" . '<tr class="' . $alternate[($i++ % 2)] .
173 '"><td><span class="attrname">' . htmlspecialchars($name) . '</span>';
174
175 $isHidden = in_array($nameraw, $t->data['hiddenAttributes'], true);
176 if ($isHidden) {
178
179 $str .= '<div class="attrvalue" style="display: none;" id="hidden_' . $hiddenId . '">';
180 } else {
181 $str .= '<div class="attrvalue">';
182 }
183
184 if (sizeof($value) > 1) {
185 // we hawe several values
186 $str .= '<ul>';
187 foreach ($value as $listitem) {
188 if ($nameraw === 'jpegPhoto') {
189 $str .= '<li><img src="data:image/jpeg;base64,' .
190 htmlspecialchars($listitem) .
191 '" alt="User photo" /></li>';
192 } else {
193 $str .= '<li>' . htmlspecialchars($listitem) . '</li>';
194 }
195 }
196 $str .= '</ul>';
197 } elseif (isset($value[0])) {
198 // we hawe only one value
199 if ($nameraw === 'jpegPhoto') {
200 $str .= '<img src="data:image/jpeg;base64,' .
201 htmlspecialchars($value[0]) .
202 '" alt="User photo" />';
203 } else {
204 $str .= htmlspecialchars($value[0]);
205 }
206 } // end of if multivalue
207 $str .= '</div>';
208
209 if ($isHidden) {
210 $str .= '<div class="attrvalue consent_showattribute" id="visible_' . $hiddenId . '">';
211 $str .= '... ';
212 $str .= '<a class="consent_showattributelink" href="javascript:SimpleSAML_show(\'hidden_' . $hiddenId;
213 $str .= '\'); SimpleSAML_hide(\'visible_' . $hiddenId . '\');">';
214 $str .= $t->t('{consent:consent:show_attribute}');
215 $str .= '</a>';
216 $str .= '</div>';
217 }
218
219 $str .= '</td></tr>';
220 } // end else: not child table
221 } // end foreach
222 $str .= isset($attributes)? '</table>':'';
223 return $str;
224}
225
226echo '<h3 id="attributeheader">' .
227 $this->t(
228 '{consent:consent:consent_attributes_header}',
229 array( 'SPNAME' => $dstName, 'IDPNAME' => $srcName)
230 ) .
231 '</h3>';
232
233echo present_attributes($this, $attributes, '');
234
235$this->includeAtTemplateBase('includes/footer.php');
An exception for terminatinating execution or to throw for unit testing.
static generateID()
Generate a random identifier, ID_LENGTH bytes long.
Definition: Random.php:26
$translator
if(is_array($dstName)) $srcName
Definition: consentform.php:52
$this data['header']
Definition: consentform.php:57
$attributes
Definition: consentform.php:55
$dstName
Definition: consentform.php:53
$i
Definition: disco.tpl.php:19
$summary
Definition: cron.php:24
if($format !==null) $name
Definition: metadata.php:146
Attribute-related utility methods.