source: sandbox/2.3-MailArchiver/calendar/inc/class.uicustom_fields.inc.php @ 6779

Revision 6779, 6.7 KB checked in by rafaelraymundo, 12 years ago (diff)

Ticket #2946 - Liberado Expresso(branch 2.3) integrado ao MailArchiver?.

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                        if (!$GLOBALS['phpgw']->acl->check('run',1,'admin'))
43                        {
44                              $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/admin/index.php'));
45                        }
46                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
47                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
48                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['calendar']['title'].' - '.lang('Custom fields and sorting');
49                        $GLOBALS['phpgw']->common->phpgw_header();
50
51                        $this->tpl = $GLOBALS['phpgw']->template;
52
53                        $this->tpl->set_unknowns('remove');
54                        $this->tpl->set_file(array(
55                                'custom_fields_tpl'     => 'custom_fields.tpl'
56                        ));
57                        $this->tpl->set_block('custom_fields_tpl','custom_fields','custom_fields');
58                        $this->tpl->set_block('custom_fields_tpl','row','row');
59
60                        $n = 0;
61                        foreach($this->fields as $field => $data)
62                        {
63                                $data['order'] = ($n += 10);
64                                if (isset($this->stock_fields[$field]))
65                                {
66                                        $this->set_row($data,$field);
67                                }
68                                else
69                                {
70                                        $this->set_row($data,$field,'delete','Delete');
71                                }
72                        }
73                        $this->tpl->set_var(array(
74                                'hidden_vars'  => '',
75                                'lang_error'   => $error,
76                                'lang_name'    => lang('Name'),
77                                'lang_length'  => lang('Length<br>(<= 255)'),
78                                'lang_shown'   => lang('Length shown<br>(emtpy for full length)'),
79                                'lang_order'   => lang('Order'),
80                                'lang_title'   => lang('Title-row'),
81                                'lang_disabled'=> lang('Disabled'),
82                                'action_url'   => $GLOBALS['phpgw']->link('/index.php','menuaction=calendar.uicustom_fields.submited'),
83                                'save_button'  => $this->html->submit_button('save','Save'),
84                                'cancel_button'=> $this->html->submit_button('cancel','Cancel'),
85                        ));
86
87                        $this->set_row(array('order' => $n+10),'***new***','add','Add');
88
89                        $this->tpl->pfp('out','custom_fields');
90                }
91
92                function set_row($values,$id='',$name='',$label='')
93                {
94                        if ($id !== '')
95                        {
96                                $id = '['.htmlspecialchars($id).']';
97                        }
98                        $this->tpl->set_var(array(
99                                'name'    => $values['label'] ? lang($values['label']) : $this->html->input('name'.$id,$values['name'],'','SIZE="40" MAXLENGTH="40"'),
100                                'length'  => $values['label'] ? '&nbsp' : $this->html->input('length'.$id,$values['length'],'','SIZE="3"'),
101                                'shown'   => $values['label'] ? '&nbsp' : $this->html->input('shown'.$id,$values['shown'],'','SIZE="3"'),
102                                'order'   => $this->html->input('order'.$id,$values['order'],'','SIZE="3"'),
103                                'title'   => $this->html->checkbox('title'.$id,$values['title']),
104                                'disabled'=> $this->html->checkbox('disabled'.$id,$values['disabled']),
105                                'button'  => $name ? $this->html->submit_button($name.$id,$label) : '&nbsp'
106                        ));
107                        if ($name !== 'add')
108                        {
109                                $this->tpl->set_var('tr_color',$values['title'] ? $GLOBALS['phpgw_info']['theme']['th_bg'] : $GLOBALS['phpgw']->nextmatchs->alternate_row_color());
110                                $this->tpl->parse('rows','row',True);
111                        }
112                }
113
114                function submited()
115                {
116                        if ($_POST['cancel'])
117                        {
118                                $GLOBALS['phpgw']->redirect_link('/admin/');
119                        }
120                        //echo "<pre>"; print_r($_POST); echo "</pre>";
121
122                        foreach ($_POST['order'] as $field => $order)
123                        {
124                                if (isset($_POST['delete'][$field]) || $field == '***new***')
125                                {
126                                        continue;
127                                }
128                                while(isset($ordered[$order]))
129                                {
130                                        ++$order;
131                                }
132                                $ordered[$order] = array(
133                                        'field'     => $field,
134                                        'name'      => stripslashes($_POST['name'][$field]),
135                                        'length'    => (int)$_POST['length'][$field],
136                                        'shown'     => (int)$_POST['shown'][$field],
137                                        'title'     => !!$_POST['title'][$field],
138                                        'disabled'  => !!$_POST['disabled'][$field]
139                                );
140                                if (isset($this->stock_fields[$field]))
141                                {
142                                        $ordered[$order]['name']  = $this->fields[$field]['name'];
143                                        $ordered[$order]['label'] = $this->fields[$field]['label'];
144                                }
145                        }
146                        if (isset($_POST['add']) || strlen($_POST['name']['***new***']))
147                        {
148                                $name = stripslashes($_POST['name']['***new***']);
149
150                                if (!strlen($name) || array_search($name,$_POST['name']) != '***new***')
151                                {
152                                        $error .= lang('New name must not exist and not be empty!!!');
153                                }
154                                else
155                                {
156                                        $order = $_POST['order']['***new***'];
157                                        while(isset($_POST['order'][$order]))
158                                        {
159                                                ++$order;
160                                        }
161                                        $ordered[$order] = array(
162                                                'field'     => '#'.$name,
163                                                'name'      => $name,
164                                                'length'    => (int)$_POST['length']['***new***'],
165                                                'shown'     => (int)$_POST['shown']['***new***'],
166                                                'title'     => !!$_POST['title']['***new***'],
167                                                'disabled'  => !!$_POST['disabled']['***new***']
168                                        );
169                                }
170                        }
171                        //echo "<pre>"; print_r($ordered); echo "</pre>\n";
172                        ksort($ordered,SORT_NUMERIC);
173
174                        $this->fields = array();
175                        foreach($ordered as $order => $data)
176                        {
177                                if ($data['length'] > 255)
178                                {
179                                        $data['length'] = 255;
180                                }
181                                if ($data['length'] <= 0)
182                                {
183                                        unset($data['length']);
184                                }
185                                if ($data['shown'] >= $data['length'] || $data['shown'] <= 0)
186                                {
187                                        unset($data['shown']);
188                                }
189                                if (!$data['title'])
190                                {
191                                        unset($data['title']);
192                                }
193                                if (!$data['disabled'])
194                                {
195                                        unset($data['disabled']);
196                                }
197                                $field = $data['field'];
198                                unset($data['field']);
199                                $this->fields[$field] = $data;
200                        }
201                        if (!$error && isset($_POST['save']))
202                        {
203                                $this->save();
204                                $GLOBALS['phpgw']->redirect_link('/admin/');
205                        }
206                        $this->index($error);
207                }
208        }
209?>
Note: See TracBrowser for help on using the repository browser.