source: branches/1.2/workflow/inc/smarty/wf_plugins/function.wf_select_duplex.php @ 1349

Revision 1349, 4.0 KB checked in by niltonneto, 15 years ago (diff)

Ticket #561 - Inclusão do módulo Workflow faltante nessa versão.

Line 
1<?php
2/**
3 * Este plugin insere dois select boxes de seleções múltiplas que permitem ao usuário cadastrar vários ítens de uma lista dada. O primeiro select é utilizado para mostrar todos os ítens "cadastráveis". Pode-se selecionar um ou mais ítens que são transferidos para o segundo select através do botão ">>".
4 * O mesmo pode ser feito do segundo select para o primeiro através do botão ""
5 * A idéia é realizar o cadastro de todos os ítens contidos no segundo select ao final das operações. 
6 * @package Smarty
7 * @subpackage wf_plugins
8 * @param array $params Array de parametros
9 * - nameLeft: o nome que o select da esquerda irá receber.
10 * - nameRight: o nome que o select da direita irá receber.
11 * - arrayLeft: lista dos ítens a serem carregados no select da esquerda.
12 * - arrayRight: lista dos ítens a serem carregados no select da direita.
13 * - size: tamanho dos select boxes.
14 * - diffEnable: valor indicando se deve-se executar o diff entre os select boxes.
15 * - style: para definir os estilos dos select boxes
16 * @param object &$smarty Instância do objeto smarty em uso
17 * @return string $output codigo que insere os select boxes.
18 * @access public
19 */
20function smarty_function_wf_select_duplex($params, &$smarty)
21{
22    require_once $smarty->_get_plugin_filepath('function','html_options');
23
24        $requiredParams = array(
25                'nameLeft',
26                'nameRight');
27        $defaultValues = array(
28                'size'       => 8,
29                'style'      => "width:200px",
30                'nameLeft'   => "_disponiveis_" . rand(),
31                'nameRight'  => "_cadastrados_" . rand(),
32                'diffEnable' => true);
33        $extractParams = array(
34                'nameLeft',
35                'nameRight',
36                'arrayLeft',
37                'arrayRight',
38                'size',
39                'diffEnable',
40                'style');
41       
42        /* verifica se todos os parâmetros obrigatórios foram passados */
43        foreach ($requiredParams as $required)
44                if (!array_key_exists($required, $params) || (empty($params[$required])))
45                        $smarty->trigger_error("[wf_select_duplex] missing required parameter(s): $required", E_USER_ERROR);
46       
47        /* atribui valores default para os parâmetros não passados */
48        foreach ($defaultValues as $key => $value)
49                if (!isset($params[$key]))
50                        $params[$key] = $value;
51       
52        /* extrai alguns parâmetros da matriz de parâmetros */
53        foreach ($extractParams as $extract)
54                $$extract = $params[$extract];
55       
56        /* parâmetros extras são "acumulados" em uma única variável */
57        $extraParams = array();
58        foreach ($params as $key => $value_params)
59                if (!in_array($key, $extractParams))
60                        $extraParams[$key] = $value_params;
61
62        $output = <<<EOF
63                                <table><tr>
64                                        <td valign=bottom>
65EOF;
66
67        $nameLeftLabel = ucwords( str_replace("_", " ", $nameLeft) );
68        $output .= $nameLeftLabel;
69
70        $output .= <<<EOF
71                                <br>
72EOF;
73
74        $output .= smarty_function_html_options(array_merge(array(
75                                                                                        'multiple' => 'true',
76                                                                                        'name'     => $nameLeft . "[]",
77                                                                                        'id'       => $nameLeft,
78                                                                                        'size'     => $size,
79                                                                                        'style'    => $style,
80                                                                                        'options'  => $arrayLeft), $extraParams),
81                                                                                $smarty);
82        $output .= <<<EOF
83                                        </td>
84                                        <td valign=middle>
85EOF;
86
87        $output .= <<<EOF
88                        <input type="hidden" name="$name" id="$name" value="$id_value"/>
89                        <input class="form_botao" type="button" value=">>" onclick="moveOptions('$nameLeft','$nameRight')">
90                        <br>
91                        <input class="form_botao" type="button" value="<<" onclick="moveOptions('$nameRight','$nameLeft')">
92EOF;
93
94        $output .= <<<EOF
95                                        </td>
96                                        <td valign=bottom>
97EOF;
98
99        $nameRightLabel = ucwords( str_replace("_", " ", $nameRight) );
100        $output .= $nameRightLabel;
101
102        $output .= <<<EOF
103                                <br>
104EOF;
105
106        $output .= smarty_function_html_options(array_merge(array(
107                                                                                        'multiple' => 'true',
108                                                                                        'name'     => $nameRight . "[]",
109                                                                                        'id'       => $nameRight,
110                                                                                        'size'     => $size,
111                                                                                        'style'    => $style,
112                                                                                        'options'  => $arrayRight), $extraParams),
113                                                                                $smarty);
114
115        $output .= <<<EOF
116                                        </td>
117                                </tr></table>
118EOF;
119
120        if($diffEnable)
121        {
122        $output .= <<<EOF
123                                <script>selectDiff('$nameRight','$nameLeft');</script>                                 
124EOF;
125        }
126
127        return $output;
128}
129?>
Note: See TracBrowser for help on using the repository browser.