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

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

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

  • Property svn:executable set to *
Line 
1<?php
2/**
3 * Abre uma nova janela de browser
4 * @package Smarty
5 * @subpackage wf_plugins
6 * @author Mauricio Luiz Viani
7 * @param array $params Array de parametros
8 * - url: (obrigatório) Endereço completo de uma página a ser aberta na nova janela
9 * - name: (opcional) Nome do objeto janela a ser criado. Default 'win'
10 * - width: (opcional) Largura, em pixels, da janela. Default 450.
11 * - height: (opcional) Comprimento, em pixels, da janela. Default 550
12 * - features: (opcional) Sequência de parâmetros de configuração da janela. Default: "scrollbars = yes, menubar=yes"
13 * - text (opcional) Texto sobre o qual será montado o link de abertura. Default 'Abrir'
14 * - img: (opcional) Nome de um arquivo de imagem (com extensão) sobre o qual será montado o link. Se informado, inibe o uso de parâmetro text
15 * - button: (opcional) Indica se o link para abrir a nova janela deve ser um botão. Default false. Se informado inibe o parâmetro img.   
16 * @param object &$smarty Instância do objeto smarty em uso
17 * @return string $output código
18 * @access public
19 */
20function smarty_function_wf_window_open($params, &$smarty)
21{               
22        $requiredParams = array(
23                'url');
24        $defaultValues = array(
25                'name' => 'win',
26                'width' => '450',
27                'height' => '550',
28                'position' => 'right',
29                'features' => "toolbar=no, scrollbars=yes, menubar=yes",
30                'text' => 'Abrir',
31                'img' => '',
32                'button' => false);
33        $extractParams = array(
34                'url',
35                'name',
36                'width',
37                'height',
38                'position',
39                'features',
40                'text',
41                'img',
42                'button');
43
44        /* verifica se todos os parâmetros obrigatórios foram passados */
45        foreach ($requiredParams as $required)
46                if (!array_key_exists($required, $params) || (empty($params[$required])))
47                        $smarty->trigger_error("[wf_window_open] missing required parameter(s): $required", E_USER_ERROR);
48               
49        /* atribui valores default para os parâmetros não passados */
50        foreach ($defaultValues as $key => $value)
51                if (!isset($params[$key]))
52                        $params[$key] = $value;
53                       
54        /* extrai alguns parâmetros da matriz de parâmetros */
55        foreach ($extractParams as $extract)
56                $$extract = $params[$extract];
57
58        /* parâmetros extras são "acumulados" em uma única matriz */
59        $extraParams = array();
60        foreach ($params as $key => $value)
61                if (!in_array($key, $extractParams))
62                        $extraParams[] = $key . ' = "' . $value . '"';
63               
64        $click_command = "wf_open_window('$url', '$name', '$width', '$height', '$position', '$features');";
65       
66        if ($button) {
67                $output = "<input type=\"button\" onclick=\"$click_command\" value=\"$text\" name=\"$text\" " . implode(' ', $extraParams) . "/>";
68        }
69        else {
70                        if ($img) {
71                                $text = '<img src="' . $smarty->get_template_vars('wf_resources_path') . '/' . $img . '" border="0">';
72                        }
73                        $output = "<a href=\"javascript:void(0)\" onclick=\"$click_command\" " . implode(' ', $extraParams) . ">$text</a>";
74        }
75               
76        return $output;
77}
78?>
Note: See TracBrowser for help on using the repository browser.