1919 * Template form for giving consent.
2020 *
2121 * Parameters:
22- * - 'srcMetadata': Metadata/configuration for the source.
23- * - 'dstMetadata': Metadata/configuration for the destination.
2422 * - 'yesTarget': Target URL for the yes-button. This URL will receive a POST request.
25- * - 'yesData': Parameters which should be included in the yes-request.
2623 * - 'noTarget': Target URL for the no-button. This URL will receive a GET request.
27- * - 'noData': Parameters which should be included in the no-request.
28- * - 'attributes': The attributes which are about to be released.
2924 * - 'sppp': URL to the privacy policy of the destination, or FALSE.
3025 *
3126 * @package SimpleSAMLphp
3227 */
33- assert ('is_array($this->data["srcMetadata"]) ' );
34- assert ('is_array($this->data["dstMetadata"]) ' );
35- assert ('is_string($this->data["yesTarget"]) ' );
36- assert ('is_array($this->data["yesData"]) ' );
37- assert ('is_string($this->data["noTarget"]) ' );
38- assert ('is_array($this->data["noData"]) ' );
39- assert ('is_array($this->data["attributes"]) ' );
40- assert ('is_array($this->data["hiddenAttributes"]) ' );
41- assert ('$this->data["sppp"] === false || is_string($this->data["sppp"]) ' );
28+ assert (is_string ($ this ->data ['yesTarget ' ]));
29+ assert (is_string ($ this ->data ['noTarget ' ]));
30+ assert ($ this ->data ['sppp ' ] === false || is_string ($ this ->data ['sppp ' ]));
31+
32+ // Needed for present_attributes_ssp()
33+ $ globalConfig = \SimpleSAML \Configuration::getInstance ();
34+ $ t = new \SimpleSAML \XHTML \Template ($ globalConfig , 'consent:consentform.php ' );
4235
4336// Parse parameters
44- if (array_key_exists ('name ' , $ this ->data ['srcMetadata ' ])) {
45- $ srcName = $ this ->data ['srcMetadata ' ]['name ' ];
46- } elseif (array_key_exists ('OrganizationDisplayName ' , $ this ->data ['srcMetadata ' ])) {
47- $ srcName = $ this ->data ['srcMetadata ' ]['OrganizationDisplayName ' ];
48- } else {
49- $ srcName = $ this ->data ['srcMetadata ' ]['entityid ' ];
50- }
37+ $ dstName = $ this ->data ['dstName ' ];
38+ $ srcName = $ this ->data ['srcName ' ];
5139
52- if (is_array ($ srcName )) {
53- $ srcName = $ this ->t ($ srcName );
54- }
40+ $ id = $ _REQUEST ['StateId ' ];
41+ $ state = \SimpleSAML \Auth \State::loadState ($ id , 'consent:request ' );
5542
56- if (array_key_exists ('name ' , $ this ->data ['dstMetadata ' ])) {
57- $ dstName = $ this ->data ['dstMetadata ' ]['name ' ];
58- } elseif (array_key_exists ('OrganizationDisplayName ' , $ this ->data ['dstMetadata ' ])) {
59- $ dstName = $ this ->data ['dstMetadata ' ]['OrganizationDisplayName ' ];
43+ if (array_key_exists ('consent:hiddenAttributes ' , $ state )) {
44+ $ t ->data ['hiddenAttributes ' ] = $ state ['consent:hiddenAttributes ' ];
6045} else {
61- $ dstName = $ this ->data ['dstMetadata ' ]['entityid ' ];
62- }
63-
64- if (is_array ($ dstName )) {
65- $ dstName = $ this ->t ($ dstName );
46+ $ t ->data ['hiddenAttributes ' ] = [];
6647}
6748
68- $ srcName = htmlspecialchars ($ srcName );
69- $ dstName = htmlspecialchars ($ dstName );
70-
7149$ attributes = $ this ->data ['attributes ' ];
7250
7351$ this ->data ['header ' ] = $ this ->t ('{consent:consent:consent_header} ' );
7452$ this ->data ['jquery ' ] = array ('core ' => TRUE );
7553
7654$ this ->includeAtTemplateBase ('includes/header.php ' );
7755?>
56+ <h2 class="text-center"><?php echo $ this ->data ['consent_accept ' ]; ?> </h2>
57+ <div class="row js-spread">
58+ <div class="col-sm-12 ssp-content-group js-spread">
59+
60+ <?php
61+ echo $ this ->data ['attributes_html ' ] = present_attributes_ssp ($ t , $ attributes , '' );
7862
79- <?php
80- if ($ this ->data ['sppp ' ] !== false ) {
81- echo "<p> " . htmlspecialchars ($ this ->t ('{consent:consent:consent_privacypolicy} ' )) . " " ;
82- echo "<a target='_blank' href=' " . htmlspecialchars ($ this ->data ['sppp ' ]) . "'> " . $ dstName . "</a> " ;
83- echo "</p> " ;
84- }
8563
8664/**
8765 * Recursive attribute array listing function
8866 *
89- * @param SimpleSAML_XHTML_Template $t Template object
67+ * @param \SimpleSAML\XHTML\Template $t Template object
9068 * @param array $attributes Attributes to be presented
9169 * @param string $nameParent Name of parent element
9270 *
9371 * @return string HTML representation of the attributes
9472 */
95- function present_attributes ($ t , $ attributes , $ nameParent )
73+ function present_attributes_ssp ($ t , $ attributes , $ nameParent )
9674{
97- $ alternate = array ('ssp-table--tr__odd ' , 'ssp-table--tr__even ' );
75+ $ translator = $ t ->getTranslator ();
76+
77+ $ alternate = ['ssp-table--tr__odd ' , 'ssp-table--tr__even ' ];
9878 $ i = 0 ;
99- $ summary = 'summary=" ' . $ t ->t ('{consent:consent:table_summary} ' ) . '" ' ;
79+ $ summary = 'summary=" ' . $ translator ->t ('{consent:consent:table_summary} ' ). '" ' ;
10080
10181 if (strlen ($ nameParent ) > 0 ) {
10282 $ parentStr = strtolower ($ nameParent ) . '_ ' ;
@@ -108,49 +88,48 @@ function present_attributes($t, $attributes, $nameParent)
10888
10989 foreach ($ attributes as $ name => $ value ) {
11090 $ nameraw = $ name ;
111- $ name = $ t ->getAttributeTranslation ($ parentStr . $ nameraw );
91+ $ name = $ translator ->getAttributeTranslation ($ parentStr. $ nameraw );
11292
11393 if (preg_match ('/^child_/ ' , $ nameraw )) {
11494 // insert child table
11595 $ parentName = preg_replace ('/^child_/ ' , '' , $ nameraw );
11696 foreach ($ value as $ child ) {
117- $ str .= "\n" . '<tr class="odd ssp--table--tr__odd"><td> ' .
118- present_attributes ($ t , $ child , $ parentName ) . '</td></tr> ' ;
97+ $ str .= "\n" . '<tr class="odd ssp--table--tr__odd"><td> ' .
98+ present_attributes_ssp ($ t , $ child , $ parentName ) . '</td></tr> ' ;
11999 }
120100 } else {
121101 // insert values directly
122102
123103 $ str .= "\n" . '<tr class=" ' . $ alternate [($ i ++ % 2 )] .
124104 '"><td><div class="attrname ssp-table--attrname"> ' . htmlspecialchars ($ name ) . '</div> ' ;
125105
106+
126107 $ isHidden = in_array ($ nameraw , $ t ->data ['hiddenAttributes ' ], true );
127108 if ($ isHidden ) {
128- $ hiddenId = SimpleSAML \Utils \Random::generateID ();
129-
109+ $ hiddenId = \SimpleSAML \Utils \Random::generateID ();
130110 $ str .= '<div class="attrvalue ssp-table--attrvalue" style="display: none;" id="hidden_ ' . $ hiddenId . '"> ' ;
131111 } else {
132112 $ str .= '<div class="attrvalue ssp-table--attrvalue"> ' ;
133113 }
134114
135115 if (sizeof ($ value ) > 1 ) {
136- // we hawe several values
116+ // we have several values
137117 $ str .= '<ul class="list-unstyled ssp-table--attrvalue--list"> ' ;
138118 foreach ($ value as $ listitem ) {
139119 if ($ nameraw === 'jpegPhoto ' ) {
140120 $ str .= '<li class="ssp-table--attrvalue--list--item"><img src="data:image/jpeg;base64, ' .
141- htmlspecialchars ($ listitem ) .
142- '" alt="User photo" /></li> ' ;
121+ htmlspecialchars ($ listitem ).'" alt="User photo" /></li> ' ;
143122 } else {
144123 $ str .= '<li class="ssp-table--attrvalue--list--item"> ' . htmlspecialchars ($ listitem ) . '</li> ' ;
145124 }
146125 }
147126 $ str .= '</ul> ' ;
127+
148128 } elseif (isset ($ value [0 ])) {
149- // we hawe only one value
129+ // we have only one value
150130 if ($ nameraw === 'jpegPhoto ' ) {
151- $ str .= '<img src="data:image/jpeg;base64, ' .
152- htmlspecialchars ($ value [0 ]) .
153- '" alt="User photo" /> ' ;
131+ $ str .= '<img src="data:image/jpeg;base64, ' .
132+ htmlspecialchars ($ value [0 ]).'" alt="User photo" /> ' ;
154133 } else {
155134 $ str .= htmlspecialchars ($ value [0 ]);
156135 }
@@ -168,64 +147,55 @@ function present_attributes($t, $attributes, $nameParent)
168147 }
169148
170149 $ str .= '</td></tr> ' ;
171- } // end else: not child table
172- } // end foreach
150+ } // end else: not child table
151+ } // end foreach
173152 $ str .= isset ($ attributes )? '</table></div> ' :'' ;
174153 return $ str ;
175154}
176-
177- echo '<h2 class="text-center"> ' .
178- $ this ->t (
179- '{consent:consent:consent_accept} ' ,
180- array ( 'SPNAME ' => $ dstName , 'IDPNAME ' => $ srcName )).
181- '</h2>
182- <div class="row js-spread">
183- <div class="col-sm-12 ssp-content-group js-spread"> ' ;
184155?>
185156
186- <?php
187- echo present_attributes ($ this , $ attributes , '' );
188- ?>
189- <div class="ssp-btns-container">
190- <form style="display: inline-block"
191- action="<?php echo htmlspecialchars ($ this ->data ['yesTarget ' ]); ?> ">
192- <p class"ssp-btns-container--checkbox>
193157
194158<?php
195- if ($ this ->data ['usestorage ' ]) {
196- $ checked = ($ this ->data ['checked ' ] ? 'checked="checked" ' : '' );
197- echo '<input type="checkbox" name="saveconsent" ' . $ checked .
198- ' value="1" /> ' . $ this ->t ('{consent:consent:remember} ' );
199- }
200-
201- // Embed hidden fields...
202- foreach ($ this ->data ['yesData ' ] as $ name => $ value ) {
203- echo '<input type="hidden" name=" ' . htmlspecialchars ($ name ) .
204- '" value=" ' . htmlspecialchars ($ value ) . '" /> ' ;
159+ if (isset ($ this ->data ['consent_purpose ' ])) {
160+ echo '<p> ' .$ this ->data ['consent_purpose ' ].'</p> ' ;
205161}
206162?>
207- </p>
208- <button type="submit" name="yes" class=" ssp-btn btn ssp-btn__action ssp-btns-container--btn__left text-uppercase" id="yesbutton">
209- <?php echo htmlspecialchars ($ this ->t ('{consent:consent:yes} ' )) ?>
210- </button>
211- </form>
212163
213- <form style="display: inline-block;" action="<?php echo htmlspecialchars ($ this ->data ['noTarget ' ]); ?> "
214- method="get">
215164
165+ <div class="ssp-btns-container">
166+ <form id="consent_yes" action="<?php echo htmlspecialchars ($ this ->data ['yesTarget ' ]); ?> " style="display:inline-block;">
167+ <p class="ssp-btns-container--checkbox">
216168<?php
217- foreach ($ this ->data ['noData ' ] as $ name => $ value ) {
218- echo ('<input type="hidden" name=" ' . htmlspecialchars ($ name ) .
219- '" value=" ' . htmlspecialchars ($ value ) . '" /> ' );
220- }
169+ if ($ this ->data ['usestorage ' ]) {
170+ $ checked = ($ this ->data ['checked ' ] ? 'checked="checked" ' : '' );
171+ echo '<input type="checkbox" name="saveconsent" ' .$ checked .
172+ ' value="1" /> ' .$ this ->t ('{consent:consent:remember} ' );
173+ } // Embed hidden fields...
221174?>
222- <button type="submit" class="ssp-btn ssp-btn__secondary btn ssp-btns-container--btn__right text-uppercase" name="no" id="nobutton">
223- <?php echo htmlspecialchars ($ this ->t ('{consent:consent:no} ' )) ?>
224- </button>
175+ <input type="hidden" name="StateId" value="<?php echo htmlspecialchars ($ this ->data ['stateId ' ]); ?> " />
176+ </p>
177+ <button type="submit" name="yes" class="ssp-btn btn ssp-btn__action ssp-btns-container--btn__left text-uppercase" id="yesbutton">
178+ <?php echo htmlspecialchars ($ this ->t ('{consent:consent:yes} ' )) ?>
179+ </button>
180+ </form>
181+
182+ <form id="consent_no" action="<?php echo htmlspecialchars ($ this ->data ['noTarget ' ]); ?> " style="display:inline-block;">
183+ <input type="hidden" name="StateId" value="<?php echo htmlspecialchars ($ this ->data ['stateId ' ]); ?> " />
184+ <button type="submit" class="ssp-btn ssp-btn__secondary btn ssp-btns-container--btn__right text-uppercase" name="no" id="nobutton">
185+ <?php echo htmlspecialchars ($ this ->t ('{consent:consent:no} ' )) ?>
186+ </button>
225187</form>
226- </div> <!-- /ssp-btns-container -->
188+ </div> <!--/ssp-btns-container-->
227189</div> <!-- /ssp-content-group -->
228190</div> <!-- /row -->
191+
229192<?php
193+ if ($ this ->data ['sppp ' ] !== false ) {
194+ echo "<p> " .htmlspecialchars ($ this ->t ('{consent:consent:consent_privacypolicy} ' ))." " ;
195+ echo '<a target="_blank" href=" ' .htmlspecialchars ($ this ->data ['sppp ' ]).'"> ' .$ dstName ."</a> " ;
196+ echo "</p> " ;
197+ }
198+
199+
200+
230201$ this ->includeAtTemplateBase ('includes/footer.php ' );
231- ?>
0 commit comments