source: companies/celepar/calendar/inc/class.uicustom_fields.inc.php @ 763

Revision 763, 6.5 KB checked in by niltonneto, 15 years ago (diff)

Importação inicial do Expresso da Celepar

Line 
1<?php
2  /**************************************************************************\
3  * eGroupWare - Calendar - Custom fields and sorting                        *
4  * http://www.egroupware.org                                                *
5  * Written by Ralf Becker <RalfBecker@outdoor-training.de>                  *
6  * --------------------------------------------                             *
7  *  This program is free software; you can redistribute it and/or modify it *
8  *  under the terms of the GNU General Public License as published by the   *
9  *  Free Software Foundation; either version 2 of the License, or (at your  *
10  *  option) any later version.                                              *
11  \**************************************************************************/
12
13
14        require_once(PHPGW_INCLUDE_ROOT.'/calendar/inc/class.bocustom_fields.inc.php');
15        $GLOBALS['phpgw_info']['flags']['included_classes']['bocustom_fields'] = True; // for 0.9.14
16
17        class uicustom_fields extends bocustom_fields
18        {
19                var $public_functions = array(
20                        'index' => True,
21                        'submited'  => True
22                );
23
24                function uicustom_fields()
25                {
26                        $this->bocustom_fields();       // call constructor of extended class
27
28                        $this->tpl = $GLOBALS['phpgw']->template;
29                        if (!is_object($GLOBALS['phpgw']->nextmatchs))
30                        {
31                                $GLOBALS['phpgw']->nextmatchs = CreateObject('phpgwapi.nextmatchs');
32                        }
33                        if (!is_object($GLOBALS['phpgw']->html))
34                        {
35                                $GLOBALS['phpgw']->html = CreateObject('phpgwapi.html');
36                        }
37                        $this->html = &$GLOBALS['phpgw']->html;
38                }
39
40                function index($error='')
41                {
42                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
43                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
44                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['calendar']['title'].' - '.lang('Custom fields and sorting');
45                        $GLOBALS['phpgw']->common->phpgw_header();
46
47                        $this->tpl = $GLOBALS['phpgw']->template;
48
49                        $this->tpl->set_unknowns('remove');
50                        $this->tpl->set_file(array(
51                                'custom_fields_tpl'     => 'custom_fields.tpl'
52                        ));
53                        $this->tpl->set_block('custom_fields_tpl','custom_fields','custom_fields');
54                        $this->tpl->set_block('custom_fields_tpl','row','row');
55
56                        $n = 0;
57                        foreach($this->fields as $field => $data)
58                        {
59                                $data['order'] = ($n += 10);
60                                if (isset($this->stock_fields[$field]))
61                                {
62                                        $this->set_row($data,$field);
63                                }
64                                else
65                                {
66                                        $this->set_row($data,$field,'delete','Delete');
67                                }
68                        }
69                        $this->tpl->set_var(array(
70                                'hidden_vars'  => '',
71                                'lang_error'   => $error,
72                                'lang_name'    => lang('Name'),
73                                'lang_length'  => lang('Length<br>(<= 255)'),
74                                'lang_shown'   => lang('Length shown<br>(emtpy for full length)'),
75                                'lang_order'   => lang('Order'),
76                                'lang_title'   => lang('Title-row'),
77                                'lang_disabled'=> lang('Disabled'),
78                                'action_url'   => $GLOBALS['phpgw']->link('/index.php','menuaction=calendar.uicustom_fields.submited'),
79                                'save_button'  => $this->html->submit_button('save','Save'),
80                                'cancel_button'=> $this->html->submit_button('cancel','Cancel'),
81                        ));
82
83                        $this->set_row(array('order' => $n+10),'***new***','add','Add');
84
85                        $this->tpl->pfp('out','custom_fields');
86                }
87
88                function set_row($values,$id='',$name='',$label='')
89                {
90                        if ($id !== '')
91                        {
92                                $id = '['.htmlspecialchars($id).']';
93                        }
94                        $this->tpl->set_var(array(
95                                'name'    => $values['label'] ? lang($values['label']) : $this->html->input('name'.$id,$values['name'],'','SIZE="40" MAXLENGTH="40"'),
96                                'length'  => $values['label'] ? '&nbsp' : $this->html->input('length'.$id,$values['length'],'','SIZE="3"'),
97                                'shown'   => $values['label'] ? '&nbsp' : $this->html->input('shown'.$id,$values['shown'],'','SIZE="3"'),
98                                'order'   => $this->html->input('order'.$id,$values['order'],'','SIZE="3"'),
99                                'title'   => $this->html->checkbox('title'.$id,$values['title']),
100                                'disabled'=> $this->html->checkbox('disabled'.$id,$values['disabled']),
101                                'button'  => $name ? $this->html->submit_button($name.$id,$label) : '&nbsp'
102                        ));
103                        if ($name !== 'add')
104                        {
105                                $this->tpl->set_var('tr_color',$values['title'] ? $GLOBALS['phpgw_info']['theme']['th_bg'] : $GLOBALS['phpgw']->nextmatchs->alternate_row_color());
106                                $this->tpl->parse('rows','row',True);
107                        }
108                }
109
110                function submited()
111                {
112                        if ($_POST['cancel'])
113                        {
114                                $GLOBALS['phpgw']->redirect_link('/admin/');
115                        }
116                        //echo "<pre>"; print_r($_POST); echo "</pre>";
117
118                        foreach ($_POST['order'] as $field => $order)
119                        {
120                                if (isset($_POST['delete'][$field]) || $field == '***new***')
121                                {
122                                        continue;
123                                }
124                                while(isset($ordered[$order]))
125                                {
126                                        ++$order;
127                                }
128                                $ordered[$order] = array(
129                                        'field'     => $field,
130                                        'name'      => stripslashes($_POST['name'][$field]),
131                                        'length'    => (int)$_POST['length'][$field],
132                                        'shown'     => (int)$_POST['shown'][$field],
133                                        'title'     => !!$_POST['title'][$field],
134                                        'disabled'  => !!$_POST['disabled'][$field]
135                                );
136                                if (isset($this->stock_fields[$field]))
137                                {
138                                        $ordered[$order]['name']  = $this->fields[$field]['name'];
139                                        $ordered[$order]['label'] = $this->fields[$field]['label'];
140                                }
141                        }
142                        if (isset($_POST['add']) || strlen($_POST['name']['***new***']))
143                        {
144                                $name = stripslashes($_POST['name']['***new***']);
145
146                                if (!strlen($name) || array_search($name,$_POST['name']) != '***new***')
147                                {
148                                        $error .= lang('New name must not exist and not be empty!!!');
149                                }
150                                else
151                                {
152                                        $order = $_POST['order']['***new***'];
153                                        while(isset($_POST['order'][$order]))
154                                        {
155                                                ++$order;
156                                        }
157                                        $ordered[$order] = array(
158                                                'field'     => '#'.$name,
159                                                'name'      => $name,
160                                                'length'    => (int)$_POST['length']['***new***'],
161                                                'shown'     => (int)$_POST['shown']['***new***'],
162                                                'title'     => !!$_POST['title']['***new***'],
163                                                'disabled'  => !!$_POST['disabled']['***new***']
164                                        );
165                                }
166                        }
167                        //echo "<pre>"; print_r($ordered); echo "</pre>\n";
168                        ksort($ordered,SORT_NUMERIC);
169
170                        $this->fields = array();
171                        foreach($ordered as $order => $data)
172                        {
173                                if ($data['length'] > 255)
174                                {
175                                        $data['length'] = 255;
176                                }
177                                if ($data['length'] <= 0)
178                                {
179                                        unset($data['length']);
180                                }
181                                if ($data['shown'] >= $data['length'] || $data['shown'] <= 0)
182                                {
183                                        unset($data['shown']);
184                                }
185                                if (!$data['title'])
186                                {
187                                        unset($data['title']);
188                                }
189                                if (!$data['disabled'])
190                                {
191                                        unset($data['disabled']);
192                                }
193                                $field = $data['field'];
194                                unset($data['field']);
195                                $this->fields[$field] = $data;
196                        }
197                        if (!$error && isset($_POST['save']))
198                        {
199                                $this->save();
200                                $GLOBALS['phpgw']->redirect_link('/admin/');
201                        }
202                        $this->index($error);
203                }
204        }
205?>
Note: See TracBrowser for help on using the repository browser.