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