source: trunk/phpgwapi/inc/class.sbox.inc.php @ 2

Revision 2, 10.0 KB checked in by niltonneto, 17 years ago (diff)

Removida todas as tags usadas pelo CVS ($Id, $Source).
Primeira versão no CVS externo.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1<?php
2        /**************************************************************************\
3        * eGroupWare API - Select Box                                              *
4        * This file written by Marc Logemann <loge@phpgroupware.org>               *
5        * Class for creating predefines select boxes                               *
6        * Copyright (C) 2000, 2001 Dan Kuykendall                                  *
7        * -------------------------------------------------------------------------*
8        * This library is part of the eGroupWare API                               *
9        * ------------------------------------------------------------------------ *
10        * This library is free software; you can redistribute it and/or modify it  *
11        * under the terms of the GNU Lesser General Public License as published by *
12        * the Free Software Foundation; either version 2.1 of the License,         *
13        * or any later version.                                                    *
14        * This library is distributed in the hope that it will be useful, but      *
15        * WITHOUT ANY WARRANTY; without even the implied warranty of               *
16        * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                     *
17        * See the GNU Lesser General Public License for more details.              *
18        * You should have received a copy of the GNU Lesser General Public License *
19        * along with this library; if not, write to the Free Software Foundation,  *
20        * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA            *
21        \**************************************************************************/
22
23        class sbox
24        {
25                var $monthnames = array(
26                        '',
27                        'January',
28                        'February',
29                        'March',
30                        'April',
31                        'May',
32                        'June',
33                        'July',
34                        'August',
35                        'September',
36                        'October',
37                        'November',
38                        'December'
39                );
40
41                var $weekdays = array(
42                        '',
43                        'Monday',
44                        'Tuesday',
45                        'Wednesday',
46                        'Thursday',
47                        'Friday',
48                        'Saturday',
49                        'Sunday'
50                );
51
52                function sbox()
53                {
54                        if (!$this->country_array)
55                        {
56                                $country = CreateObject('phpgwapi.country');
57                                $this->country_array = &$country->country_array;
58                                unset($country);
59                                unset($this->country_array['  ']);
60                                // try to translate them and sort alphabetic
61                                foreach($this->country_array as $k => $name)
62                                {
63                                        if (($translated = lang($name)) != $name.'*')
64                                        {
65                                                $this->country_array[$k] = $translated;
66                                        }
67                                }
68                                asort($this->country_array);
69                        }
70                }
71
72                function hour_formated_text($name, $selected = 0)
73                {
74                        $s = '<select name="' . $name . '">';
75                        $t_s[$selected] = ' selected';
76
77                        for ($i=0; $i<24; $i++)
78                        {
79                                $s .= '<option value="' . $i . '"' . $t_s[$i] . '>'
80                                        . $GLOBALS['phpgw']->common->formattime($i+1,"00") . '</option>' . "\n";
81                        }
82                        $s .= "</select>";
83
84                        return $s;
85                }
86
87                function hour_text($name, $selected = 0)
88                {
89                        $s = '<select name="' . $name . '">';
90                        $t_s[$selected] = " selected";
91                        for ($i=1; $i<13; $i++)
92                        {
93                                $s .= '<option value="' . $i . '"' . $t_s[$i] . '>'
94                                        . $i . '</option>';
95                                $s .= "\n";
96                        }
97                        $s .= "</select>";
98
99                        return $s;
100                }
101
102                // I would like to add a increment feature
103                function sec_minute_text($name, $selected = 0)
104                {
105                        $s = '<select name="' . $name . '">';
106                        $t_s[$selected] = " selected";
107
108                        for ($i=0; $i<60; $i++)
109                        {
110                                $s .= '<option value="' . $i . '"' . $t_s[sprintf("%02d",$i)] . '>' . sprintf("%02d",$i) . '</option>';
111                                $s .= "\n";
112                        }
113                        $s .= "</select>";
114                        return $s;
115                }
116
117                function ap_text($name,$selected)
118                {
119                        $selected = strtolower($selected);
120                        $t[$selected] = " selected";
121                        $s = '<select name="' . $name . '">'
122                                . ' <option value="am"' . $t['am'] . '>am</option>'
123                                . ' <option value="pm"' . $t['pm'] . '>pm</option>';
124                        $s .= '</select>';
125                        return $s;
126                }
127
128                function full_time($hour_name,$hour_selected,$min_name,$min_selected,$sec_name,$sec_selected,$ap_name,$ap_selected)
129                {
130                        // This needs to be changed to support there time format preferences
131                        $s = $this->hour_text($hour_name,$hour_selected)
132                                . $this->sec_minute_text($min_name,$min_selected)
133                                . $this->sec_minute_text($sec_name,$sec_selected)
134                                . $this->ap_text($ap_name,$ap_selected);
135                        return $s;
136                }
137
138                function getWeekdays($name, $selected=0)
139                {
140                        $out = '';
141                        for($i=0;$i<count($this->weekdays);$i++)
142                        {
143                                $out .= '<option value="'.$i.'"'.($selected!=$i?'':' selected').'>'.($this->weekdays[$i]!=''?lang($this->weekdays[$i]):'').'</option>'."\n";
144                        }
145                        return '<select name="'.$name.'">'."\n".$out.'</select>'."\n";
146                }
147
148                function nr2weekday($selected = 0)
149                {
150                        for($i=0;$i<count($this->weekdays);$i++)
151                        {
152                                if ($selected > 0 && $selected == $i)
153                                {
154                                        return lang($this->weekdays[$i]);
155                                }
156                        }
157                }
158
159                function getMonthText($name, $selected=0)
160                {
161                        $out = '';
162                        $c_monthnames = count($this->monthnames);
163                        for($i=0;$i<$c_monthnames;$i++)
164                        {
165                                $out .= '<option value="'.$i.'"'.($selected!=$i?'':' selected').'>'.($this->monthnames[$i]!=''?lang($this->monthnames[$i]):'').'</option>'."\n";
166                        }
167                        return '<select name="'.$name.'">'."\n".$out.'</select>'."\n";
168                }
169
170                function getDays($name, $selected=0)
171                {
172                        $out = '';
173
174                        for($i=0;$i<32;$i++)
175                        {
176                                $out .= '<option value="'.($i?$i:'').'"'.($selected!=$i?'':' selected').'>'.($i?$i:'').'</option>'."\n";
177                        }
178                        return '<select name="'.$name.'">'."\n".$out.'</select>'."\n";
179                }
180
181                function getYears($name, $selected = 0, $startYear = 0, $endyear = 0)
182                {
183                        if (!$startYear)
184                        {
185                                $startYear = date('Y') - 5;
186                        }
187                        if ($selected && $startYear > $selected) $startYear = $selected;
188
189                        if (!$endyear)
190                        {
191                                $endyear = date('Y') + 6;
192                        }
193                        if ($selected && $endYear < $selected) $endYear = $selected;
194
195                        $out = '<select name="'.$name.'">'."\n";
196
197                        $out .= '<option value=""';
198                        if ($selected == 0 OR $selected == '')
199                        {
200                                $out .= ' SELECTED';
201                        }
202                        $out .= '></option>'."\n";
203
204                        // We need to add some good error checking here.
205                        for ($i=$startYear;$i<$endyear; $i++)
206                        {
207                                $out .= '<option value="'.$i.'"';
208                                if ($selected==$i)
209                                {
210                                        $out .= ' SELECTED';
211                                }
212                                $out .= '>'.$i.'</option>'."\n";
213                        }
214                        $out .= '</select>'."\n";
215
216                        return $out;
217                }
218
219                function getPercentage($name, $selected=0)
220                {
221                        $out = "<select name=\"$name\">\n";
222
223                        for($i=0;$i<101;$i=$i+10)
224                        {
225                                $out .= "<option value=\"$i\"";
226                                if($selected==$i)
227                                {
228                                        $out .= " SELECTED";
229                                }
230                                $out .= ">$i%</option>\n";
231                        }
232                        $out .= "</select>\n";
233                        // echo $out;
234                        return $out;
235                }
236
237                function getPriority($name, $selected=2)
238                {
239                        $arr = array('','low','normal','high');
240                        $out = '<select name="' . $name . '">';
241
242                        for($i=1;$i<count($arr);$i++)
243                        {
244                                $out .= "<option value=\"";
245                                $out .= $i;
246                                $out .= "\"";
247                                if ($selected==$i)
248                                {
249                                        $out .= ' SELECTED';
250                                }
251                                $out .= ">";
252                                $out .= lang($arr[$i]);
253                                $out .= "</option>\n";
254                        }
255                        $out .= "</select>\n";
256                        return $out;
257                }
258
259                function getAccessList($name, $selected="private")
260                {
261                        $arr = array(
262                                "private" => "Private",
263                                "public" => "Global public",
264                                "group" => "Group public"
265                        );
266
267                        if (ereg(",", $selected))
268                        {
269                                $selected = "group";
270                        }
271
272                        $out = "<select name=\"$name\">\n";
273
274                        for(reset($arr);current($arr);next($arr))
275                        {
276                                $out .= '<option value="' . key($arr) . '"';
277                                if($selected==key($arr))
278                                {
279                                        $out .= " SELECTED";
280                                }
281                                $out .= ">" . pos($arr) . "</option>\n";
282                        }
283                        $out .= "</select>\n";
284                        return $out;
285                }
286
287                function getGroups($groups, $selected="", $name="n_groups[]")
288                {
289                        $out = '<select name="' . $name . '" multiple>';
290                        while (list($null,$group) = each($groups))
291                        {
292                                $out .= '<option value="' . $group['account_id'] . '"';
293                                if(@is_array($selected))
294                                {
295                                        for($i=0;$i<count($selected);$i++)
296                                        {
297                                                if ($group['account_id'] == $selected[$i])
298                                                {
299                                                        $out .= " SELECTED";
300                                                        break;
301                                                }
302                                        }
303                                }
304                                elseif (ereg("," . $group['account_id'] . ",", $selected))
305                                {
306                                        $out .= " SELECTED";
307                                }
308                                $out .= ">" . $group['account_name'] . "</option>\n";
309                        }
310                        $out .= "</select>\n";
311
312                        return $out;
313                }
314
315                function list_states($name, $selected = '')
316                {
317                        $states = array(
318                                ''              => lang('Select one'),
319                                '--'    => 'non US',
320                                'AL'    =>      'Alabama',
321                                'AK'    =>      'Alaska',
322                                'AZ'    =>      'Arizona',
323                                'AR'    =>      'Arkansas',
324                                'CA'    =>      'California',
325                                'CO'    =>      'Colorado',
326                                'CT'    =>      'Connecticut',
327                                'DE'    =>      'Delaware',
328                                'DC'    =>      'District of Columbia',
329                                'FL'    =>      'Florida',
330                                'GA'    =>      'Georgia',
331                                'HI'    =>      'Hawaii',
332                                'ID'    =>      'Idaho',
333                                'IL'    =>      'Illinois',
334                                'IN'    =>      'Indiana',
335                                'IA'    =>      'Iowa',
336                                'KS'    =>      'Kansas',
337                                'KY'    =>      'Kentucky',
338                                'LA'    =>      'Louisiana',
339                                'ME'    =>      'Maine',
340                                'MD'    =>      'Maryland',
341                                'MA'    =>      'Massachusetts',
342                                'MI'    =>      'Michigan',
343                                'MN'    =>      'Minnesota',
344                                'MO'    =>      'Missouri',
345                                'MS'    =>      'Mississippi',
346                                'MT'    =>      'Montana',
347                                'NC'    =>      'North Carolina',
348                                'ND'    =>      'Noth Dakota',
349                                'NE'    =>      'Nebraska',
350                                'NH'    =>      'New Hampshire',
351                                'NJ'    =>      'New Jersey',
352                                'NM'    =>      'New Mexico',
353                                'NV'    =>      'Nevada',
354                                'NY'    =>      'New York',
355                                'OH'    =>      'Ohio',
356                                'OK'    =>      'Oklahoma',
357                                'OR'    =>      'Oregon',
358                                'PA'    =>      'Pennsylvania',
359                                'RI'    =>      'Rhode Island',
360                                'SC'    =>      'South Carolina',
361                                'SD'    =>      'South Dakota',
362                                'TN'    =>      'Tennessee',
363                                'TX'    =>      'Texas',
364                                'UT'    =>      'Utah',
365                                'VA'    =>      'Virginia',
366                                'VT'    =>      'Vermont',
367                                'WA'    =>      'Washington',
368                                'WI'    =>      'Wisconsin',
369                                'WV'    =>      'West Virginia',
370                                'WY'    =>      'Wyoming'
371                        );
372
373                        while (list($sn,$ln) = each($states))
374                        {
375                                $s .= '<option value="' . $sn . '"';
376                                if ($selected == $sn)
377                                {
378                                        $s .= ' selected';
379                                }
380                                $s .= '>' . $ln . '</option>';
381                        }
382                        return '<select name="' . $name . '">' . $s . '</select>';
383                }
384
385                function form_select($selected,$name='')
386                {
387                        if($name=='')
388                        {
389                                $name = 'country';
390                        }
391                        $str = '<select name="'.$name.'">'."\n"
392                                . ' <option value="  "'.($selected == '  '?' selected':'').'>'.lang('Select One').'</option>'."\n";
393                        foreach($this->country_array as $key => $value)
394                        {
395                                $str .= ' <option value="'.$key.'"'.($selected == $key?' selected':'') . '>'.$value.'</option>'."\n";
396                        }
397                        $str .= '</select>'."\n";
398                        return $str;
399                }
400
401                function get_full_name($selected)
402                {
403                        return($this->country_array[$selected]);
404                }
405        }
406?>
Note: See TracBrowser for help on using the repository browser.