From ba6573b92157f095b29bd13884e2a938604bd9d5 Mon Sep 17 00:00:00 2001 From: Anders Lund <anders.lund@uninett.no> Date: Mon, 22 Dec 2008 14:18:39 +0000 Subject: [PATCH] Made it possible to group attributes. Implemented by Thomas G. git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@1073 44740490-163a-0410-bde0-09ae8108e29a --- .../consent/templates/default/consentform.php | 90 ++++++++++++++----- modules/consent/www/getconsent.php | 53 ++++++++++- 2 files changed, 120 insertions(+), 23 deletions(-) diff --git a/modules/consent/templates/default/consentform.php b/modules/consent/templates/default/consentform.php index d07690d1c..8b194a96c 100644 --- a/modules/consent/templates/default/consentform.php +++ b/modules/consent/templates/default/consentform.php @@ -154,8 +154,73 @@ foreach ($this->data['noData'] as $name => $value) { echo('<input type="hidden" name="' . htmlspecialchars($name) . '" value="' . htmlspecialchars($value) . '" />'); } ?> +<?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); + } + } + + function present_attributes($t, $attributes, $nameParent) { + $alternate = array('odd', 'even'); $i = 0; + + $parentStr = (strlen($nameParent) > 0)? strtolower($nameParent) . '_': ''; + + $str = '<table style="" id="table_with_attributes" class="attributes">'; + 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)) { + $parentName = preg_replace('/^child_/', '', $nameraw); + foreach($value AS $child) { + $str .= '<tr class="odd"><td colspan="2" style="padding: 2em">' . present_attributes($t, $child, $parentName) . '</td></tr>'; + } + } else { + if (sizeof($value) > 1) { + $str .= '<tr class="' . $alternate[($i++ % 2)] . '"><td class="attrname">' . htmlspecialchars($name) . '</td><td class="attrvalue"><ul>'; + foreach ($value AS $listitem) { + $str .= '<li>' . present_assoc($listitem) . '</li>'; + } + $str .= '</ul></td></tr>'; + } elseif(isset($value[0])) { + $str .= '<tr class="' . $alternate[($i++ % 2)] . '"><td class="attrname">' . htmlspecialchars($name) . '</td><td class="attrvalue">' . htmlspecialchars($value[0]) . '</td></tr>'; + } + } + $str .= "\n"; + } + $str .= '</table>'; + return $str; + } + + +?> + <!-- Show attributes that are sent to the service in a fieldset. This fieldset is not expanded by default, but can be shown by clicking on the legend. @@ -165,31 +230,14 @@ foreach ($this->data['noData'] as $name => $value) { <legend id="attribute_switch"> » <?php echo $this->t('{consent:consent_attributes_header}'); ?></legend> <div id="addattributes"><a id="addattributesb"><?php echo $this->t('{consent:show_attributes}'); ?></a></div> - <table id="table_with_attributes" class="attributes"> - <?php - $alternate = array('odd', 'even'); $i = 0; - - foreach ($attributes as $name => $value) { - $nameTag = '{attributes:attribute_' . str_replace(":", "_", strtolower($name) ) . '}'; - if ($this->getTag($nameTag) !== NULL) { - $name = $this->t($nameTag); - } + <?php - if (sizeof($value) > 1) { - echo '<tr class="' . $alternate[($i++ % 2)] . '"><td class="attrname">' . htmlspecialchars($name) . '</td><td class="attrvalue"><ul>'; - foreach ($value AS $v) { - echo '<li>' . htmlspecialchars($v) . '</li>'; - } - echo '</ul></td></tr>'; - } else { - echo '<tr class="' . $alternate[($i++ % 2)] . '"><td class="attrname">' . htmlspecialchars($name) . '</td><td class="attrvalue">' . htmlspecialchars($value[0]) . '</td></tr>'; - } - echo("\n"); - } + echo(present_attributes($this, $attributes, '')); + ?> - </table> + </fieldset> <!-- end attribute view --> diff --git a/modules/consent/www/getconsent.php b/modules/consent/www/getconsent.php index ec52c7644..31e4faa49 100644 --- a/modules/consent/www/getconsent.php +++ b/modules/consent/www/getconsent.php @@ -38,7 +38,56 @@ if (array_key_exists('yes', $_REQUEST)) { } -/* Show consent form. */ +/* Prepare attributes for presentation */ +$attribute_presentation = $state['Attributes']; +$para = array( + 'attributes' => &$attribute_presentation +); + +/* The callHooks function call below will call a attribute array reordering function if it exist. + * To create this function, you hawe to create a file with name: hook_attributepresentation.php and place + * it under a <module_dir>/hooks directory. To be found and called, the function hawe to + * be named : <module_name>_hook_attributepresentation(&$para). + * The parameter $para is an reference to the attribute array. By manipulating this array + * you change the way the attribute is presented to the user on the consent and status page. + * If you want to have the attributes listed in more than one level. You can make the function add + * a child_ prefix to the root node attribute name in a recursive attribute tree. + * In the array below is an example of this: + * + * Array + * ( + * [objectClass] => Array + * ( + * [0] => top <--- These values will be listed as an bullet list + * [1] => person + * ) + * [child_eduPersonOrgUnitDN] => Array <--- This array hawe two child array. These will be listed in + * ( two separate sub tables. + * [0] => Array + * ( + * [ou] => Array + * ( + * [0] => ET + * ) + * [cn] => Array + * ( + * [0] => Eksterne tjenester + * ) + * [1] => Array + * ( + * [ou] => Array + * ( + * [0] => TA + * ) + * [cn] => Array + * ( + * [0] => Tjenesteavdeling + * ) + * + */ +SimpleSAML_Module::callHooks('attributepresentation', $para); + +/* Make, populate and layout consent form. */ $globalConfig = SimpleSAML_Configuration::getInstance(); $t = new SimpleSAML_XHTML_Template($globalConfig, 'consent:consentform.php'); @@ -48,7 +97,7 @@ $t->data['yesTarget'] = SimpleSAML_Module::getModuleURL('consent/getconsent.php' $t->data['yesData'] = array('StateId' => $id); $t->data['noTarget'] = SimpleSAML_Module::getModuleURL('consent/noconsent.php'); $t->data['noData'] = array('StateId' => $id); -$t->data['attributes'] = $state['Attributes']; +$t->data['attributes'] = $attribute_presentation; $t->data['checked'] = $state['consent:checked']; -- GitLab