[ Index ]
 

Code source de eGroupWare 1.2.106-2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/phpgwapi/inc/ -> class.sbox.inc.php (source)

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


Généré le : Sun Feb 25 17:20:01 2007 par Balluche grâce à PHPXref 0.7