From d19907bbb8e8f1644d03e7915b8fd333fb98cc27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=C3=85kre=20Solberg?= <andreas.solberg@uninett.no> Date: Thu, 30 Apr 2009 19:48:48 +0000 Subject: [PATCH] Patch from Thomas Graff, consent presentation UI. git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@1483 44740490-163a-0410-bde0-09ae8108e29a --- modules/consent/templates/consentform.php | 119 +++++++++------------- 1 file changed, 48 insertions(+), 71 deletions(-) diff --git a/modules/consent/templates/consentform.php b/modules/consent/templates/consentform.php index 41ac281a3..1de9a1300 100644 --- a/modules/consent/templates/consentform.php +++ b/modules/consent/templates/consentform.php @@ -111,86 +111,63 @@ if ($this->data['sppp'] !== FALSE) { ?> <?php - function present_list($attr) { - if (is_array($attr) && count($attr) > 1) { - $str = '<ul><li>' . join('</li><li>', $attr) . '</li></ul>'; - return $str; - } else { - return htmlspecialchars($attr[0]); - } - } - function present_assoc($attr) { - if (is_array($attr)) { - - $str = '<dl>'; - foreach ($attr AS $key => $value) { - $str .= "\n" . '<dt>' . htmlspecialchars($key) . '</dt><dd>' . present_list($value) . '</dd>'; - } - $str .= '</dl>'; - return $str; - } else { - return htmlspecialchars($attr); - } +// Recursiv attribute array listing function +function present_attributes($t, $attributes, $nameParent) { + $alternate = array('odd', 'even'); $i = 0; + $summary = 'summary="' . $t->t('{consent:consent:table_summary}') . '"'; + + if(strlen($nameParent) > 0){ + $parentStr = strtolower($nameParent) . '_'; + $str = '<table class="attributes"' . $summary . ' >'; + }else{ + $parentStr = ''; + $str = '<table id="table_with_attributes" class="attributes" '. $summary .'>'; + $str .= "\n" . '<caption>' . $t->t('{consent:consent:table_caption}') . '</caption>'; } - - - function present_attributes($t, $attributes, $nameParent) { - $alternate = array('odd', 'even'); $i = 0; - $summary = 'summary="' . $t->t('{consent:consent:table_summary}') . '"'; - - if(strlen($nameParent) > 0){ - $parentStr = strtolower($nameParent) . '_'; - $str = '<table class="attributes"' . $summary . ' >'; - }else{ - $parentStr = ''; - $str = '<table id="table_with_attributes" class="attributes" '. $summary .'>'; - $str .= "\n" . '<caption>' . $t->t('{consent:consent:table_caption}') . '</caption>'; + foreach ($attributes as $name => $value) { + $nameraw = $name; + $nameTag = '{attributes:attribute_' . $parentStr . str_replace(":", "_", strtolower($name) ) . '}'; + if ($t->getTag($nameTag) !== NULL) { + $name = $t->t($nameTag); } - - foreach ($attributes as $name => $value) { - $nameraw = $name; - $nameTag = '{attributes:attribute_' . $parentStr . str_replace(":", "_", strtolower($name) ) . '}'; - if ($t->getTag($nameTag) !== NULL) { - $name = $t->t($nameTag); + + if (preg_match('/^child_/', $nameraw)) { + // Insert child table + $parentName = preg_replace('/^child_/', '', $nameraw); + foreach($value AS $child) { + $str .= "\n" . '<tr class="odd"><td style="padding: 2em">' . present_attributes($t, $child, $parentName) . '</td></tr>'; } - - if (preg_match('/^child_/', $nameraw)) { - // Insert child table - $parentName = preg_replace('/^child_/', '', $nameraw); - foreach($value AS $child) { - $str .= "\n" . '<tr class="odd"><td style="padding: 2em">' . present_attributes($t, $child, $parentName) . '</td></tr>'; - } - } else { - // Insert values directly - $str .= "\n" . '<tr class="' . $alternate[($i++ % 2)] . '"><td><span class="attrname">' . htmlspecialchars($name) . '</span><div class="attrvalue">'; - if (sizeof($value) > 1) { - // We hawe several values - $str .= '<ul>'; - foreach ($value AS $listitem) { - if ($nameraw === 'jpegPhoto') { - $str .= '<li><img src="data:image/jpeg;base64,' . $listitem . '" alt="User photo" /></li>'; - } else { - $str .= '<li>' . present_assoc($listitem) . '</li>'; - } - } - $str .= '</ul>'; - } elseif(isset($value[0])) { - // We hawe only one value + } else { + // Insert values directly + $str .= "\n" . '<tr class="' . $alternate[($i++ % 2)] . '"><td><span class="attrname">' . htmlspecialchars($name) . '</span><div class="attrvalue">'; + if (sizeof($value) > 1) { + // We hawe several values + $str .= '<ul>'; + foreach ($value AS $listitem) { if ($nameraw === 'jpegPhoto') { - $str .= '<img src="data:image/jpeg;base64,' . htmlspecialchars($value[0]) . '" alt="User photo" />'; + $str .= '<li><img src="data:image/jpeg;base64,' . $listitem . '" alt="User photo" /></li>'; } else { - $str .= htmlspecialchars($value[0]); + $str .= '<li>' . htmlspecialchars($listitem) . '</li>'; } - } // end of if multivalue - $str .= '</div></td></tr>'; - } // end else: not child table - } // end foreach - $str .= count($attributes)>1? '</table>':''; - return $str; - } + } + $str .= '</ul>'; + } elseif(isset($value[0])) { + // We hawe only one value + if ($nameraw === 'jpegPhoto') { + $str .= '<img src="data:image/jpeg;base64,' . htmlspecialchars($value[0]) . '" alt="User photo" />'; + } else { + $str .= htmlspecialchars($value[0]); + } + } // end of if multivalue + $str .= '</div></td></tr>'; + } // end else: not child table + } // end foreach + $str .= isset($attributes)? '</table>':''; + return $str; +} ?> <h3 id="attributeheader"><?php echo $this->t('{consent:consent:consent_attributes_header}',array( 'SPNAME' => $dstName, 'IDPNAME' => $srcName )); ?></h3> <?php echo(present_attributes($this, $attributes, '')); ?> -- GitLab