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

Revision 588, 10.4 KB checked in by eduardoalex, 15 years ago (diff)

Ticket #386

  • 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 getMonths($name, $selected=0)
171                {
172                        $out = '';
173                        for($i=0;$i<=12;$i++)
174                        {
175                                $out .= '<option value="'.$i.'"'.($selected!=$i?'':' selected').'>'.($i?$i:'').'</option>'."\n";
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 getDays($name, $selected=0)
182                {
183                        $out = '';
184
185                        for($i=0;$i<32;$i++)
186                        {
187                                $out .= '<option value="'.($i?$i:'').'"'.($selected!=$i?'':' selected').'>'.($i?$i:'').'</option>'."\n";
188                        }
189                        return '<select name="'.$name.'">'."\n".$out.'</select>'."\n";
190                }
191
192                function getYears($name, $selected = 0, $startYear = 0, $endyear = 0)
193                {
194                        if (!$startYear)
195                        {
196                                $startYear = date('Y') - 5;
197                        }
198                        if ($selected && $startYear > $selected) $startYear = $selected;
199
200                        if (!$endyear)
201                        {
202                                $endyear = date('Y') + 6;
203                        }
204                        if ($selected && $endYear < $selected) $endYear = $selected;
205
206                        $out = '<select name="'.$name.'">'."\n";
207
208                        $out .= '<option value=""';
209                        if ($selected == 0 OR $selected == '')
210                        {
211                                $out .= ' SELECTED';
212                        }
213                        $out .= '></option>'."\n";
214
215                        // We need to add some good error checking here.
216                        for ($i=$startYear;$i<$endyear; $i++)
217                        {
218                                $out .= '<option value="'.$i.'"';
219                                if ($selected==$i)
220                                {
221                                        $out .= ' SELECTED';
222                                }
223                                $out .= '>'.$i.'</option>'."\n";
224                        }
225                        $out .= '</select>'."\n";
226
227                        return $out;
228                }
229
230                function getPercentage($name, $selected=0)
231                {
232                        $out = "<select name=\"$name\">\n";
233
234                        for($i=0;$i<101;$i=$i+10)
235                        {
236                                $out .= "<option value=\"$i\"";
237                                if($selected==$i)
238                                {
239                                        $out .= " SELECTED";
240                                }
241                                $out .= ">$i%</option>\n";
242                        }
243                        $out .= "</select>\n";
244                        // echo $out;
245                        return $out;
246                }
247
248                function getPriority($name, $selected=2)
249                {
250                        $arr = array('','low','normal','high');
251                        $out = '<select name="' . $name . '">';
252
253                        for($i=1;$i<count($arr);$i++)
254                        {
255                                $out .= "<option value=\"";
256                                $out .= $i;
257                                $out .= "\"";
258                                if ($selected==$i)
259                                {
260                                        $out .= ' SELECTED';
261                                }
262                                $out .= ">";
263                                $out .= lang($arr[$i]);
264                                $out .= "</option>\n";
265                        }
266                        $out .= "</select>\n";
267                        return $out;
268                }
269
270                function getAccessList($name, $selected="private")
271                {
272                        $arr = array(
273                                "private" => "Private",
274                                "public" => "Global public",
275                                "group" => "Group public"
276                        );
277
278                        if (ereg(",", $selected))
279                        {
280                                $selected = "group";
281                        }
282
283                        $out = "<select name=\"$name\">\n";
284
285                        for(reset($arr);current($arr);next($arr))
286                        {
287                                $out .= '<option value="' . key($arr) . '"';
288                                if($selected==key($arr))
289                                {
290                                        $out .= " SELECTED";
291                                }
292                                $out .= ">" . pos($arr) . "</option>\n";
293                        }
294                        $out .= "</select>\n";
295                        return $out;
296                }
297
298                function getGroups($groups, $selected="", $name="n_groups[]")
299                {
300                        $out = '<select name="' . $name . '" multiple>';
301                        while (list($null,$group) = each($groups))
302                        {
303                                $out .= '<option value="' . $group['account_id'] . '"';
304                                if(@is_array($selected))
305                                {
306                                        for($i=0;$i<count($selected);$i++)
307                                        {
308                                                if ($group['account_id'] == $selected[$i])
309                                                {
310                                                        $out .= " SELECTED";
311                                                        break;
312                                                }
313                                        }
314                                }
315                                elseif (ereg("," . $group['account_id'] . ",", $selected))
316                                {
317                                        $out .= " SELECTED";
318                                }
319                                $out .= ">" . $group['account_name'] . "</option>\n";
320                        }
321                        $out .= "</select>\n";
322
323                        return $out;
324                }
325
326                function list_states($name, $selected = '')
327                {
328                        $states = array(
329                                ''              => lang('Select one'),
330                                '--'    => 'non US',
331                                'AL'    =>      'Alabama',
332                                'AK'    =>      'Alaska',
333                                'AZ'    =>      'Arizona',
334                                'AR'    =>      'Arkansas',
335                                'CA'    =>      'California',
336                                'CO'    =>      'Colorado',
337                                'CT'    =>      'Connecticut',
338                                'DE'    =>      'Delaware',
339                                'DC'    =>      'District of Columbia',
340                                'FL'    =>      'Florida',
341                                'GA'    =>      'Georgia',
342                                'HI'    =>      'Hawaii',
343                                'ID'    =>      'Idaho',
344                                'IL'    =>      'Illinois',
345                                'IN'    =>      'Indiana',
346                                'IA'    =>      'Iowa',
347                                'KS'    =>      'Kansas',
348                                'KY'    =>      'Kentucky',
349                                'LA'    =>      'Louisiana',
350                                'ME'    =>      'Maine',
351                                'MD'    =>      'Maryland',
352                                'MA'    =>      'Massachusetts',
353                                'MI'    =>      'Michigan',
354                                'MN'    =>      'Minnesota',
355                                'MO'    =>      'Missouri',
356                                'MS'    =>      'Mississippi',
357                                'MT'    =>      'Montana',
358                                'NC'    =>      'North Carolina',
359                                'ND'    =>      'Noth Dakota',
360                                'NE'    =>      'Nebraska',
361                                'NH'    =>      'New Hampshire',
362                                'NJ'    =>      'New Jersey',
363                                'NM'    =>      'New Mexico',
364                                'NV'    =>      'Nevada',
365                                'NY'    =>      'New York',
366                                'OH'    =>      'Ohio',
367                                'OK'    =>      'Oklahoma',
368                                'OR'    =>      'Oregon',
369                                'PA'    =>      'Pennsylvania',
370                                'RI'    =>      'Rhode Island',
371                                'SC'    =>      'South Carolina',
372                                'SD'    =>      'South Dakota',
373                                'TN'    =>      'Tennessee',
374                                'TX'    =>      'Texas',
375                                'UT'    =>      'Utah',
376                                'VA'    =>      'Virginia',
377                                'VT'    =>      'Vermont',
378                                'WA'    =>      'Washington',
379                                'WI'    =>      'Wisconsin',
380                                'WV'    =>      'West Virginia',
381                                'WY'    =>      'Wyoming'
382                        );
383
384                        while (list($sn,$ln) = each($states))
385                        {
386                                $s .= '<option value="' . $sn . '"';
387                                if ($selected == $sn)
388                                {
389                                        $s .= ' selected';
390                                }
391                                $s .= '>' . $ln . '</option>';
392                        }
393                        return '<select name="' . $name . '">' . $s . '</select>';
394                }
395
396                function form_select($selected,$name='')
397                {
398                        if($name=='')
399                        {
400                                $name = 'country';
401                        }
402                        $str = '<select name="'.$name.'">'."\n"
403                                . ' <option value="  "'.($selected == '  '?' selected':'').'>'.lang('Select One').'</option>'."\n";
404                        foreach($this->country_array as $key => $value)
405                        {
406                                $str .= ' <option value="'.$key.'"'.($selected == $key?' selected':'') . '>'.$value.'</option>'."\n";
407                        }
408                        $str .= '</select>'."\n";
409                        return $str;
410                }
411
412                function get_full_name($selected)
413                {
414                        return($this->country_array[$selected]);
415                }
416        }
417?>
Note: See TracBrowser for help on using the repository browser.