~ubuntu-branches/ubuntu/trusty/ldap-account-manager/trusty-proposed

« back to all changes in this revision

Viewing changes to lib/html.inc

  • Committer: Package Import Robot
  • Author(s): Roland Gruber
  • Date: 2013-07-21 11:15:58 UTC
  • mfrom: (1.2.21)
  • Revision ID: package-import@ubuntu.com-20130721111558-ex49xgcpo71fh0xg
Tags: 4.2.1-2
* Apache 2.4 support
* Fix "transition towards Apache 2.4" 
  support conf-enabled (Closes: #669824)
* Fix "[ldap-account-manager] Can't install ldap-account-manager"
  support conf-enabled (Closes: #711778)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
<?php
2
2
/*
3
 
$Id: html.inc 4813 2013-03-16 14:35:41Z gruberroland $
 
3
$Id: html.inc 4932 2013-05-24 18:31:20Z gruberroland $
4
4
 
5
5
  This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
6
6
  Copyright (C) 2010 - 2013  Roland Gruber
634
634
         * 
635
635
         * @param array $values list of values to suggest
636
636
         * @param int $minLength autocompletion starts after this number of caracters entered (default 1; 0 means immediate start)
637
 
         * @param boolean $multiValue allow multiple autocompletion values in the same fields
 
637
         * @param boolean $multiValue allow multiple autocompletion values in the same fields (default: false)
638
638
         * @param String $multiSeparator separator expression if multiple autocompletion values are allowed (default ",\s*")
639
639
         * @param String $multiSeparator separator for two values (default ", ")
640
640
         */
641
641
        public function enableAutocompletion($values, $minLength = 1, $multiValue = false, $multiSeparatorExp = ',\s*', $multiSeparator = ', ') {
642
642
                for ($i = 0; $i < sizeof($values); $i++) {
643
 
                        $values[$i] = '"' . htmlspecialchars($values[$i]) . '"';
 
643
                        $values[$i] = '"' . htmlspecialchars(str_replace(array('"', "\r", "\n"), array('', '', ''), $values[$i])) . '"';
644
644
                }
645
645
                $this->autocomplete = true;
646
646
                $this->autocompleteValues = $values;
2837
2837
}
2838
2838
 
2839
2839
/**
 
2840
 * Sets all given elements to the same height.
 
2841
 * 
 
2842
 * @package metaHTML
 
2843
 */
 
2844
class htmlEqualHeight extends htmlElement {
 
2845
        
 
2846
        /** list of element IDs */
 
2847
        private $elements = array();
 
2848
        
 
2849
        /**
 
2850
         * Constructor.
 
2851
         * 
 
2852
         * @param array $elements list of element IDs
 
2853
         */
 
2854
        function __construct($elements) {
 
2855
                foreach ($elements as $element) {
 
2856
                        $this->elements[] = htmlspecialchars($element);
 
2857
                }
 
2858
        }
 
2859
        
 
2860
        /**
 
2861
         * Prints the HTML code for this element.
 
2862
         * 
 
2863
         * @param string $module Name of account module
 
2864
         * @param array $input List of meta-HTML elements
 
2865
         * @param array $values List of values which override the defaults in $input (name => value)
 
2866
         * @param boolean $restricted If true then no buttons will be displayed
 
2867
         * @param integer $tabindex Start value of tabulator index for input fields
 
2868
         * @param string $scope Account type
 
2869
         * @return array List of input field names and their type (name => type)
 
2870
         */
 
2871
        function generateHTML($module, $input, $values, $restricted, &$tabindex, $scope) {
 
2872
                if (sizeof($this->elements) == 0) {
 
2873
                        return array();
 
2874
                }
 
2875
                $return = array();
 
2876
                $listContent = "'#" . $this->elements[0] . "'";
 
2877
                for ($i = 1; $i < sizeof($this->elements); $i++) {
 
2878
                        $listContent .= ", '#" . $this->elements[$i] . "'";
 
2879
                }
 
2880
                echo '<script type="text/javascript">';
 
2881
                echo ' jQuery(document).ready(function() {';
 
2882
                echo '  var equalHeightElements = new Array(' . $listContent . ');';
 
2883
                echo '  equalHeight(equalHeightElements);';
 
2884
                echo ' });';
 
2885
                echo '</script>';
 
2886
                return $return;
 
2887
        }
 
2888
        
 
2889
}
 
2890
 
 
2891
/**
2840
2892
 * Creates a list of elements that can be sorted by the user via drag'n'drop.
2841
2893
 * 
2842
2894
 * @package metaHTML
2921
2973
 
2922
2974
}
2923
2975
 
 
2976
/**
 
2977
 * Creates a list of content elements in accordion style.
 
2978
 * HTML special characters must be escaped before providing to htmlAccordion.
 
2979
 */
 
2980
class htmlAccordion extends htmlElement {
 
2981
 
 
2982
        private $id = null;
 
2983
        private $elements = null;
 
2984
        private $openInitial = '1';
 
2985
        private $collapsible = false;
 
2986
        
 
2987
        /**
 
2988
         * Constructor.
 
2989
         * 
 
2990
         * @param String $id HTML ID
 
2991
         * @param array $elements list of content elements array('title' => htmlElement)
 
2992
         * @param String $openInitial index of element that is initially opened (default: 0), set to 'false' to close all
 
2993
         * @param boolean $collapsible specifies if all elements may be closed at the same time (default: false, true if $openInitial is false)
 
2994
         */
 
2995
        function __construct($id, $elements, $openInitial = '0', $collapsible = false) {
 
2996
                $this->id = $id;
 
2997
                $this->elements = $elements;
 
2998
                $this->openInitial = $openInitial;
 
2999
                if (($openInitial === 'false') || ($openInitial === false)) {
 
3000
                        $this->collapsible = true;
 
3001
                }
 
3002
                else {
 
3003
                        $this->collapsible = $collapsible;
 
3004
                }
 
3005
        }
 
3006
        
 
3007
        /**
 
3008
         * Prints the HTML code for this element.
 
3009
         * 
 
3010
         * @param string $module Name of account module
 
3011
         * @param array $input List of meta-HTML elements
 
3012
         * @param array $values List of values which override the defaults in $input (name => value)
 
3013
         * @param boolean $restricted If true then no buttons will be displayed
 
3014
         * @param integer $tabindex Start value of tabulator index for input fields
 
3015
         * @param string $scope Account type
 
3016
         * @return array List of input field names and their type (name => type)
 
3017
         */
 
3018
        function generateHTML($module, $input, $values, $restricted, &$tabindex, $scope) {
 
3019
                $result = array();
 
3020
                $collapsible = 'false';
 
3021
                if ($this->collapsible) {
 
3022
                        $collapsible = 'true';
 
3023
                }
 
3024
                $active = 'false';
 
3025
                if ($this->openInitial !== false) {
 
3026
                        $active = $this->openInitial;
 
3027
                }
 
3028
                echo '<div id="' . $this->id . '">';
 
3029
                foreach ($this->elements as $label => $content) {
 
3030
                        echo '<h3>' . $label . '</h3>';
 
3031
                        echo '<div>';
 
3032
                        $result = array_merge($result, $content->generateHTML($module, $input, $values, $restricted, $tabindex, $scope));
 
3033
                        echo '</div>';
 
3034
                }
 
3035
                echo '</div>';
 
3036
                $script = 'jQuery(function() {
 
3037
                                                $( "#' . $this->id . '" ).accordion({
 
3038
                                                collapsible: ' . $collapsible . ',
 
3039
                                                active: ' . $active . '
 
3040
                                                });
 
3041
                                        });';
 
3042
                $js = new htmlJavaScript($script);
 
3043
                $js->generateHTML($module, $input, $values, $restricted, $tabindex, $scope);
 
3044
                return $result;
 
3045
        }
 
3046
 
 
3047
        
 
3048
}
 
3049
 
2924
3050
?>