[ Index ]
 

Code source de Horde 3.1.3

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

title

Body

[fermer]

/lib/Horde/UI/VarRenderer/ -> html.php (source)

   1  <?php
   2  /**
   3   * The Horde_UI_VarRenderer_html:: class renders variables to HTML.
   4   *
   5   * $Horde: framework/UI/UI/VarRenderer/html.php,v 1.98.2.28 2006/08/16 12:17:22 jan Exp $
   6   *
   7   * Copyright 2003-2006 Jason M. Felice <jfelice@cronosys.com>
   8   *
   9   * See the enclosed file LICENSE for license information (LGPL).
  10   *
  11   * @since   Horde_UI 0.0.1
  12   * @package Horde_UI
  13   */
  14  class Horde_UI_VarRenderer_html extends Horde_UI_VarRenderer {
  15  
  16      var $_onLoadJS = array();
  17  
  18      function _renderVarInputDefault(&$form, &$var, &$vars)
  19      {
  20          return '<strong>Warning:</strong> Unknown variable type ' .
  21              @htmlspecialchars($var->getTypeName(), ENT_QUOTES, $this->_charset);
  22      }
  23  
  24      function _renderVarInput_number(&$form, &$var, &$vars)
  25      {
  26          $value = $var->getValue($vars);
  27          if (isset($var->type->_fraction)) {
  28              $value = sprintf('%01.' . $var->type->_fraction . 'f', $value);
  29          }
  30          $linfo = NLS::getLocaleInfo();
  31          /* Only if there is a mon_decimal_point do the
  32           * substitution. */
  33          if (!empty($linfo['mon_decimal_point'])) {
  34              $value = str_replace('.', $linfo['mon_decimal_point'], $value);
  35          }
  36          $varname = @htmlspecialchars($var->getVarName(), ENT_QUOTES, $this->_charset);
  37          return sprintf('<input type="text" size="5" name="%s" id="%s" value="%s"%s />',
  38                         $varname,
  39                         $varname,
  40                         $value,
  41                         $this->_getActionScripts($form, $var)
  42                 );
  43      }
  44  
  45      function _renderVarInput_int(&$form, &$var, &$vars)
  46      {
  47          $varname = @htmlspecialchars($var->getVarName(), ENT_QUOTES, $this->_charset);
  48          return sprintf('<input type="text" size="5" name="%s" id="%s" value="%s"%s />',
  49                         $varname,
  50                         $varname,
  51                         @htmlspecialchars($var->getValue($vars), ENT_QUOTES, $this->_charset),
  52                         $this->_getActionScripts($form, $var)
  53                 );
  54      }
  55  
  56      function _renderVarInput_octal(&$form, &$var, &$vars)
  57      {
  58          $varname = @htmlspecialchars($var->getVarName(), ENT_QUOTES, $this->_charset);
  59          return sprintf('<input type="text" size="5" name="%s" id="%s" value="%s"%s />',
  60                         $varname,
  61                         $varname,
  62                         sprintf('0%o', octdec($var->getValue($vars))),
  63                         $this->_getActionScripts($form, $var)
  64                 );
  65      }
  66  
  67      function _renderVarInput_intlist(&$form, &$var, &$vars)
  68      {
  69          $varname = @htmlspecialchars($var->getVarName(), ENT_QUOTES, $this->_charset);
  70          return sprintf('<input type="text" name="%s" id="%s" value="%s"%s />',
  71                         $varname,
  72                         $varname,
  73                         @htmlspecialchars($var->getValue($vars), ENT_QUOTES, $this->_charset),
  74                         $this->_getActionScripts($form, $var)
  75                 );
  76      }
  77  
  78      function _renderVarInput_text(&$form, &$var, &$vars)
  79      {
  80          $maxlength = $var->type->getMaxLength();
  81          $varname = @htmlspecialchars($var->getVarName(), ENT_QUOTES, $this->_charset);
  82          return sprintf('<input type="text" name="%s" id="%s" size="%s" value="%s" %s%s%s />',
  83                         $varname,
  84                         $varname,
  85                         $var->type->getSize(),
  86                         @htmlspecialchars($var->getValue($vars), ENT_QUOTES, $this->_charset),
  87                         $var->isDisabled() ? ' disabled="disabled" ' : '',
  88                         empty($maxlength) ? '' : ' maxlength="' . $maxlength . '"',
  89                         $this->_getActionScripts($form, $var)
  90                 );
  91      }
  92  
  93      function _renderVarInput_weatherdotcom(&$form, &$var, &$vars)
  94      {
  95          return $this->_renderVarInput_text($form, $var, $vars);
  96      }
  97  
  98      function _renderVarInput_stringlist(&$form, &$var, &$vars)
  99      {
 100          $varname = @htmlspecialchars($var->getVarName(), ENT_QUOTES, $this->_charset);
 101          return sprintf('<input type="text" size="60" name="%s" id="%s" value="%s"%s />',
 102                         $varname,
 103                         $varname,
 104                         @htmlspecialchars($var->getValue($vars), ENT_QUOTES, $this->_charset),
 105                         $this->_getActionScripts($form, $var)
 106                 );
 107      }
 108  
 109      function _renderVarInput_cellphone(&$form, &$var, &$vars)
 110      {
 111          $varname = @htmlspecialchars($var->getVarName(), ENT_QUOTES, $this->_charset);
 112          return sprintf('<input type="text" name="%s" id="%s" size="15" value="%s" %s%s />',
 113                         $varname,
 114                         $varname,
 115                         @htmlspecialchars($var->getValue($vars), ENT_QUOTES, $this->_charset),
 116                         $var->isDisabled() ? ' disabled="disabled" ' : '',
 117                         $this->_getActionScripts($form, $var)
 118                 );
 119      }
 120  
 121      function _renderVarInput_ipaddress(&$form, &$var, &$vars)
 122      {
 123          $varname = @htmlspecialchars($var->getVarName(), ENT_QUOTES, $this->_charset);
 124          return sprintf('<input type="text" name="%s" id="%s" size="16" value="%s" %s%s />',
 125                         $varname,
 126                         $varname,
 127                         @htmlspecialchars($var->getValue($vars), ENT_QUOTES, $this->_charset),
 128                         $var->isDisabled() ? ' disabled="disabled" ' : '',
 129                         $this->_getActionScripts($form, $var)
 130                 );
 131      }
 132  
 133      function _renderVarInput_file(&$form, &$var, &$vars)
 134      {
 135          $varname = @htmlspecialchars($var->getVarName(), ENT_QUOTES, $this->_charset);
 136          return sprintf('<input type="file" size="30" name="%s" id="%s"%s />',
 137                         $varname,
 138                         $varname,
 139                         $this->_getActionScripts($form, $var));
 140      }
 141  
 142      /**
 143       * @todo Show image dimensions in the width/height boxes.
 144       */
 145      function _renderVarInput_image(&$form, &$var, &$vars)
 146      {
 147          $varname = htmlspecialchars($var->getVarName());
 148          $image = $var->getValue($vars);
 149  
 150          /* Check if existing image data is being loaded. */
 151          $var->type->_loadImageData($image);
 152  
 153          Horde::addScriptFile('image.js', 'horde', true);
 154          $graphics_dir = $GLOBALS['registry']->getImageDir('horde');
 155          $img_dir = $graphics_dir . '/image';
 156  
 157          $html = '';
 158  
 159          /* Check if there is existing img information stored. */
 160          if (isset($image['img'])) {
 161              /* Hidden tag to store the preview image filename. */
 162              $html = sprintf('<input type="hidden" name="%s" id="%s" value="%s" />',
 163                              $varname . '[img]',
 164                              $varname . '[img]',
 165                              @htmlspecialchars($image['img'], ENT_QUOTES, $this->_charset));
 166              /* Unserialize the img information to get the full array. */
 167              $image['img'] = @unserialize($image['img']);
 168          }
 169  
 170          /* Output the input tag. */
 171          if (empty($image['img'])) {
 172              $js = "var p = document.getElementById('" . $varname . "[preview]'); o = '\\\\'; a = '/'; tmp = '' + document.getElementById('" . $varname . "[new]').value; if (tmp) { while (tmp.indexOf(o) > -1) { pos = tmp.indexOf(o); tmp = '' + (tmp.substring(0, pos) + a + tmp.substring((pos + o.length), tmp.length));}; p.src = 'file:///' + tmp; p.alt = '" . addslashes(_("If you see this message but no image, the image you want to upload can't be displayed by your browser.")) . "'; };";
 173              $browser = &Browser::singleton();
 174              if ($browser->isBrowser('msie')) {
 175                  $html .= sprintf('<input type="file" size="30" name="%s" id="%s" onchange="%s" />',
 176                                   $varname . '[new]',
 177                                   $varname . '[new]',
 178                                   $js);
 179              } else {
 180                  $html .= sprintf('<input type="file" size="30" name="%s" id="%s" onclick="window.setTimeout(\'document.getElementById(\\\'%s\\\').blur();\', 5);" onblur="%s" />',
 181                                   $varname . '[new]',
 182                                   $varname . '[new]',
 183                                   $varname . '[new]',
 184                                   $js);
 185              }
 186          } else {
 187              $html .= sprintf('<input type="file" size="30" name="%s" id="%s" />',
 188                               $varname . '[new]',
 189                               $varname . '[new]');
 190          }
 191  
 192          /* Output the button to upload/reset the image. */
 193          if ($var->type->_show_upload) {
 194              $html .= '&nbsp;';
 195              $html .= sprintf('<input class="button" name="%s" id="%s" type="submit" value="%s" /> ',
 196                               '_do_' . $varname,
 197                               '_do_' . $varname,
 198                               _("Upload"));
 199          }
 200  
 201          if (empty($image['img'])) {
 202              /* No image information stored yet, show a blank preview. */
 203              $html .= Horde::img('tree/blank.png', _("Preview"), 'width="50" height="40" id="' . $varname . '[preview]"', $graphics_dir);
 204          } else {
 205              /* Image information stored, show preview, add buttons for image
 206               * manipulation. */
 207              $html .= '<br />';
 208              $img = Horde::url($GLOBALS['registry']->get('webroot', 'horde') . '/services/images/view.php');
 209              if (isset($image['img']['vfs_id'])) {
 210                  /* Calling an image from VFS. */
 211                  $img = Util::addParameter($img, array('f' => $image['img']['vfs_id'],
 212                                                        's' => 'vfs',
 213                                                        'p' => $image['img']['vfs_path']));
 214              } else {
 215                  /* Calling an image from a tmp directory (uploads). */
 216                  $img = Util::addParameter($img, 'f', $image['img']['file']);
 217              }
 218  
 219              /* Reset. */
 220              $html .= Horde::link('#', _("Reset"), '', '', 'showImage(\'' . $img . '\', \'_p_' . $varname . '\', true);') . Horde::img('refresh.png', _("Reset"), 'align="middle"', $img_dir) . '</a>';
 221  
 222              /* Rotate 270. */
 223              $html .= Horde::link('#', _("Rotate Left"), '', '', 'showImage(\'' . Util::addParameter($img, array('a' => 'rotate', 'v' => '270')) . '\', \'_p_' . $varname . '\', true);') . Horde::img('rotate-270.png', _("Rotate Left"), 'align="middle"', $img_dir) . '</a>';
 224  
 225              /* Rotate 180. */
 226              $html .= Horde::link('#', _("Rotate 180"), '', '', 'showImage(\'' . Util::addParameter($img, array('a' => 'rotate', 'v' => '180')) . '\', \'_p_' . $varname . '\', true);') . Horde::img('rotate-180.png', _("Rotate 180"), 'align="middle"', $img_dir) . '</a>';
 227  
 228              /* Rotate 90. */
 229              $html .= Horde::link('#', _("Rotate Right"), '', '', 'showImage(\'' . Util::addParameter($img, array('a' => 'rotate', 'v' => '90')) . '\', \'_p_' . $varname . '\', true);') . Horde::img('rotate-90.png', _("Rotate Right"), 'align="middle"', $img_dir) . '</a>';
 230  
 231              /* Flip image. */
 232              $html .= Horde::link('#', _("Flip"), '', '', 'showImage(\'' . Util::addParameter($img, 'a', 'flip') . '\', \'_p_' . $varname . '\', true);') . Horde::img('flip.png', _("Flip"), 'align="middle"', $img_dir) . '</a>';
 233  
 234              /* Mirror image. */
 235              $html .= Horde::link('#', _("Mirror"), '', '', 'showImage(\'' . Util::addParameter($img, 'a', 'mirror') . '\', \'_p_' . $varname . '\', true);') . Horde::img('mirror.png', _("Mirror"), 'align="middle"', $img_dir) . '</a>';
 236  
 237              /* Apply grayscale. */
 238              $html .= Horde::link('#', _("Grayscale"), '', '', 'showImage(\'' . Util::addParameter($img, 'a', 'grayscale') . '\', \'_p_' . $varname . '\', true);') . Horde::img('grayscale.png', _("Grayscale"), 'align="middle"', $img_dir) . '</a>';
 239  
 240              /* Resize width. */
 241              $html .= sprintf('%s<input type="text" size="4" onchange="src=getResizeSrc(\'%s\', \'%s\');showImage(src, \'_p_%s\', true);" %s />',
 242                     _("w:"),
 243                     Util::addParameter($img, 'a', 'resize'),
 244                     $varname,
 245                     $varname,
 246                     $this->_genID('_w_' . $varname));
 247  
 248              /* Resize height. */
 249              $html .= sprintf('%s<input type="text" size="4" onchange="src=getResizeSrc(\'%s\', \'%s\');showImage(src, \'_p_%s\', true);" %s />',
 250                     _("h:"),
 251                     Util::addParameter($img, 'a', 'resize'),
 252                     $varname,
 253                     $varname,
 254                     $this->_genID('_h_' . $varname));
 255  
 256              /* Apply fixed ratio resize. */
 257              $html .= Horde::link('#', _("Fix ratio"), '', '', 'src=getResizeSrc(\'' . Util::addParameter($img, 'a', 'resize') . '\', \'' . $varname . '\', \'1\');showImage(src, \'_p_' . $varname . '\', true);') . Horde::img('ratio.png', _("Fix ratio"), 'align="middle"', $img_dir) . '</a>';
 258  
 259              /* Keep also original if it has been requested. */
 260              if ($var->type->_show_keeporig) {
 261                  $html .= sprintf('<input type="checkbox" class="checkbox" name="%s" id="%s"%s />%s' . "\n",
 262                                   $varname . '[keep_orig]',
 263                                   $varname . '[keep_orig]',
 264                                   !empty($image['keep_orig']) ? ' checked="checked"' : '',
 265                                   _("Keep original?"));
 266              }
 267  
 268              /* The preview image element. */
 269              $html .= '<br /><img src="' . $img . '" ' . $this->_genID('_p_' . $varname) . ">\n";
 270          }
 271  
 272          return $html;
 273      }
 274  
 275      function _renderVarInput_longtext(&$form, &$var, &$vars)
 276      {
 277          global $browser;
 278  
 279          $varname = @htmlspecialchars($var->getVarName(), ENT_QUOTES, $this->_charset);
 280          $html = sprintf('<textarea id="%s" name="%s" cols="%s" rows="%s"%s%s>%s</textarea>',
 281                          $varname,
 282                          $varname,
 283                          (int)$var->type->getCols(),
 284                          (int)$var->type->getRows(),
 285                          $this->_getActionScripts($form, $var),
 286                          $var->isDisabled() ? ' disabled="disabled"' : '',
 287                          @htmlspecialchars($var->getValue($vars), ENT_QUOTES, $this->_charset));
 288  
 289          if ($var->type->hasHelper('rte') && $browser->hasFeature('rte')) {
 290              require_once 'Horde/Editor.php';
 291              $editor = &Horde_Editor::singleton('htmlarea', array('id' => $varname));
 292          }
 293  
 294          if ($var->type->hasHelper() && $browser->hasFeature('javascript')) {
 295              $html .= '<br /><table cellspacing="0"><tr><td>';
 296              Horde::addScriptFile('open_html_helper.js', 'horde');
 297              $imgId = $this->_genID($var->getVarName(), false) . 'ehelper';
 298              if ($var->type->hasHelper('emoticons')) {
 299                  $html .= Horde::link('#', _("Emoticons"), '', '', 'openHtmlHelper(\'emoticons\', \'' . $var->getVarName() . '\'); return false;') . Horde::img('smile.png', _("Emoticons"), 'id="' . $imgId . '" align="middle"', $GLOBALS['registry']->getImageDir('horde') . '/emoticons') . '</a>';
 300              }
 301              $html .= '</td></tr><tr><td><div ' . $this->_genID('htmlhelper_' . $var->getVarName()) . ' class="control"></div></td></tr></table>' . "\n";
 302          }
 303  
 304          return $html;
 305      }
 306  
 307      function _renderVarInput_countedtext(&$form, &$var, &$vars)
 308      {
 309          $varname = @htmlspecialchars($var->getVarName(), ENT_QUOTES, $this->_charset);
 310          return sprintf('<textarea name="%s" id="%s" cols="%s" rows="%s"%s%s>%s</textarea>',
 311                         $varname,
 312                         $varname,
 313                         (int)$var->type->getCols(),
 314                         (int)$var->type->getRows(),
 315                         $this->_getActionScripts($form, $var),
 316                         $var->isDisabled() ? ' disabled="disabled"' : '',
 317                         @htmlspecialchars($var->getValue($vars), ENT_QUOTES, $this->_charset));
 318      }
 319  
 320      function _renderVarInput_address(&$form, &$var, &$vars)
 321      {
 322          $varname = @htmlspecialchars($var->getVarName(), ENT_QUOTES, $this->_charset);
 323          return sprintf('<textarea name="%s" id="%s" cols="%s" rows="%s"%s%s>%s</textarea>',
 324                         $varname,
 325                         $varname,
 326                         (int)$var->type->getCols(),
 327                         (int)$var->type->getRows(),
 328                         $this->_getActionScripts($form, $var),
 329                         $var->isDisabled() ? ' disabled="disabled"' : '',
 330                         @htmlspecialchars($var->getValue($vars), ENT_QUOTES, $this->_charset));
 331      }
 332  
 333      function _renderVarInput_date(&$form, &$var, &$vars)
 334      {
 335          $varname = @htmlspecialchars($var->getVarName(), ENT_QUOTES, $this->_charset);
 336          return sprintf('<input type="text" name="%s" id="%s" value="%s"%s />',
 337                         $varname,
 338                         $varname,
 339                         @htmlspecialchars($var->getValue($vars), ENT_QUOTES, $this->_charset),
 340                         $this->_getActionScripts($form, $var));
 341      }
 342  
 343      function _renderVarInput_time(&$form, &$var, &$vars)
 344      {
 345          $varname = @htmlspecialchars($var->getVarName(), ENT_QUOTES, $this->_charset);
 346          return sprintf('<input type="text" size="5" name="%s" id="%s" value="%s"%s />',
 347                         $varname,
 348                         $varname,
 349                         @htmlspecialchars($var->getValue($vars), ENT_QUOTES, $this->_charset),
 350                         $this->_getActionScripts($form, $var));
 351      }
 352  
 353      function _renderVarInput_hourminutesecond(&$form, &$var, &$vars)
 354      {
 355          $varname = @htmlspecialchars($var->getVarName(), ENT_QUOTES, $this->_charset);
 356          $time = $var->type->getTimeParts($var->getValue($vars));
 357  
 358          /* Output hours. */
 359          $hours = array('' => _("hh"));
 360          for ($i = 0; $i <= 23; $i++) {
 361              $hours[$i] = $i;
 362          }
 363          $html = sprintf('<select name="%s[hour]" id="%s[hour]"%s>%s</select>',
 364                          $varname,
 365                          $varname,
 366                          $this->_getActionScripts($form, $var),
 367                          $this->_selectOptions($hours, ($time['hour'] === '') ? '' : $time['hour']));
 368  
 369          /* Output minutes. */
 370          $minutes = array('' => _("mm"));
 371          for ($i = 0; $i <= 59; $i++) {
 372              $m = sprintf('%02d', $i);
 373              $minutes[$m] = $m;
 374          }
 375          $html .= sprintf('<select name="%s[minute]" id="%s[minute]"%s>%s</select>',
 376                           $varname,
 377                           $varname,
 378                           $this->_getActionScripts($form, $var),
 379                           $this->_selectOptions($minutes, ($time['minute'] === '') ? '' : sprintf('%02d', $time['minute'])));
 380  
 381          /* Return if seconds are not required. */
 382          if (!$var->type->_show_seconds) {
 383              return $html;
 384          }
 385  
 386          /* Output seconds. */
 387          $seconds = array('' => _("ss"));
 388          for ($i = 0; $i <= 59; $i++) {
 389              $seconds[$i] = sprintf('%02d', $i);
 390          }
 391          return $html . sprintf('<select name="%s[second]" id="%s[second]"%s>%s</select>',
 392                                 $varname,
 393                                 $varname,
 394                                 $this->_getActionScripts($form, $var),
 395                                 $this->_selectOptions($seconds, ($time['second'] === '') ? '' : sprintf('%02d', $time['second'])));
 396      }
 397  
 398      function _renderVarInput_monthyear(&$form, &$var, &$vars)
 399      {
 400          $dates = array();
 401          $dates['month'] = array('' => _("MM"),
 402                                  1 => _("January"),
 403                                  2 => _("February"),
 404                                  3 => _("March"),
 405                                  4 => _("April"),
 406                                  5 => _("May"),
 407                                  6 => _("June"),
 408                                  7 => _("July"),
 409                                  8 => _("August"),
 410                                  9 => _("September"),
 411                                  10 => _("October"),
 412                                  11 => _("November"),
 413                                  12 => _("December"));
 414          $dates['year'] = array('' => _("YYYY"));
 415          if ($var->type->_start_year > $var->type->_end_year) {
 416              for ($i = $var->type->_start_year; $i >= $var->type->_end_year; $i--) {
 417                  $dates['year'][$i] = $i;
 418              }
 419          } else {
 420              for ($i = $var->type->_start_year; $i <= $var->type->_end_year; $i++) {
 421                  $dates['year'][$i] = $i;
 422              }
 423          }
 424          return sprintf('<select name="%s" id="%s"%s>%s</select>',
 425                         $var->type->getMonthVar($var),
 426                         $var->type->getMonthVar($var),
 427                         $this->_getActionScripts($form, $var),
 428                         $this->_selectOptions($dates['month'], $vars->get($var->type->getMonthVar($var)))) .
 429              sprintf('<select name="%s" id="%s"%s>%s</select>',
 430                      $var->type->getYearVar($var),
 431                      $var->type->getYearVar($var),
 432                      $this->_getActionScripts($form, $var),
 433                      $this->_selectOptions($dates['year'], $vars->get($var->type->getYearVar($var))));
 434      }
 435  
 436      function _renderVarInput_monthdayyear(&$form, &$var, &$vars)
 437      {
 438          $dates = array();
 439          $dates['month'] = array(''   => _("MM"),
 440                                  '1'  => _("January"),
 441                                  '2'  => _("February"),
 442                                  '3'  => _("March"),
 443                                  '4'  => _("April"),
 444                                  '5'  => _("May"),
 445                                  '6'  => _("June"),
 446                                  '7'  => _("July"),
 447                                  '8'  => _("August"),
 448                                  '9'  => _("September"),
 449                                  '10' => _("October"),
 450                                  '11' => _("November"),
 451                                  '12' => _("December"));
 452          $dates['day'] = array('' => _("DD"));
 453          for ($i = 1; $i <= 31; $i++) {
 454              $dates['day'][$i] = $i;
 455          }
 456          $dates['year'] = array('' => _("YYYY"));
 457          if ($var->type->_start_year > $var->type->_end_year) {
 458              for ($i = $var->type->_start_year; $i >= $var->type->_end_year; $i--) {
 459                  $dates['year'][$i] = $i;
 460              }
 461          } else {
 462              for ($i = $var->type->_start_year; $i <= $var->type->_end_year; $i++) {
 463                  $dates['year'][$i] = $i;
 464              }
 465          }
 466          $date = $var->type->getDateParts($var->getValue($vars));
 467  
 468          // TODO: use NLS to get the order right for the Rest Of The
 469          // World.
 470          $html = '';
 471          $date_parts = array('month', 'day', 'year');
 472          foreach ($date_parts as $part) {
 473              $varname = @htmlspecialchars($var->getVarName() . '[' . $part . ']', ENT_QUOTES, $this->_charset);
 474              $html .= sprintf('<select name="%s" id="%s"%s>%s</select>',
 475                               $varname,
 476                               $varname,
 477                               $this->_getActionScripts($form, $var),
 478                               $this->_selectOptions($dates[$part], $date[$part]));
 479          }
 480  
 481          if ($var->type->_picker && $GLOBALS['browser']->hasFeature('javascript')) {
 482              Horde::addScriptFile('open_calendar.js', 'horde');
 483              $imgId = $this->_genID($var->getVarName(), false) . 'goto';
 484              $html .= '<div id="goto" class="headerbox" style="position:absolute;visibility:hidden;padding:0"></div>' .
 485                  Horde::link('#', _("Select a date"), '', '', 'openCalendar(\'' . $imgId . '\', \'' . $var->getVarName() . '\'); return false;') . Horde::img('calendar.png', _("Calendar"), 'id="' . $imgId . '" align="middle"', $GLOBALS['registry']->getImageDir('horde')) . "</a>\n";
 486          }
 487  
 488          return $html;
 489      }
 490  
 491      function _renderVarInput_colorpicker(&$form, &$var, &$vars)
 492      {
 493          global $registry, $browser;
 494  
 495          $varname = @htmlspecialchars($var->getVarName(), ENT_QUOTES, $this->_charset);
 496          $html = '<table cellspacing="0"><tr><td>' .
 497              '<input type="text" size="10" maxlength="7" name="' .
 498              $varname . '" id="' . $varname .
 499              '" value="' . @htmlspecialchars($var->getValue($vars), ENT_QUOTES, $this->_charset) . '" /></td>';
 500          if ($browser->hasFeature('javascript')) {
 501              Horde::addScriptFile('open_colorpicker.js', 'horde', true);
 502              $html .= '<td width="20" id="colordemo_' . $varname . '" style="background:' . @htmlspecialchars($var->getValue($vars), ENT_QUOTES, $this->_charset) . '"> </td>' .
 503                  '<td>' . Horde::link('#', _("Color Picker"), 'widget', '', 'openColorPicker(\'' . $varname . '\'); return false;') . Horde::img('colorpicker.png', _("Color Picker"), 'height="16"', $registry->getImageDir('horde')) . '</a></td>' .
 504                  '<td><div id="colorpicker_' . $varname . '" class="control"></div></td>';
 505          }
 506          return $html . '</tr></table>';
 507      }
 508  
 509      function _renderVarInput_sorter(&$form, &$var, &$vars)
 510      {
 511          global $registry;
 512  
 513          $varname = @htmlspecialchars($var->getVarName(), ENT_QUOTES, $this->_charset);
 514          $instance = $var->type->_instance;
 515  
 516          Horde::addScriptFile('sorter.js', 'horde', true);
 517  
 518          return '<input type="hidden" name="' . $varname .
 519              '[array]" value="" ' . $this->_genID($varname . '[array]') . '/>' .
 520              '<select class="leftFloat" multiple="multiple" size="' .
 521              (int)$var->type->getSize() . '" name="' . $varname .
 522              '[list]" onchange="' . $instance . '.deselectHeader();" ' .
 523              $this->_genID($varname . '[list]') . '>' .
 524              $var->type->getOptions($var->getValue($vars)) . '</select><div class="leftFloat">' .
 525              Horde::link('#', _("Move up"), '', '', $instance . '.moveColumnUp(); return false;') . Horde::img('nav/up.png', _("Move up"), '', $registry->getImageDir('horde')) . '</a><br />' .
 526              Horde::link('#', _("Move up"), '', '', $instance . '.moveColumnDown(); return false;') . Horde::img('nav/down.png', _("Move down"), '', $registry->getImageDir('horde')) . '</a></div>' .
 527              '<script type="text/javascript">' . "\n" .
 528              sprintf('%1$s = new Horde_Form_Sorter(\'%1$s\', \'%2$s\', \'%3$s\');' . "\n",
 529                      $instance, $varname, $var->type->getHeader()) .
 530              sprintf("%s.setHidden();\n</script>\n", $instance);
 531      }
 532  
 533      function _renderVarInput_assign(&$form, &$var, &$vars)
 534      {
 535          global $registry;
 536  
 537          Horde::addScriptFile('form_assign.js', 'horde', true);
 538  
 539          $name = @htmlspecialchars($var->getVarName(), ENT_QUOTES, $this->_charset);
 540          $fname = $form->getName() . '.' . $var->getVarName();
 541          $size = $var->type->getSize();
 542          $width = $var->type->getWidth();
 543          $lhdr = (bool)$var->type->getHeader(0);
 544          $rhdr = (bool)$var->type->getHeader(1);
 545          $this->_addOnLoadJavascript('Horde_Form_Assign.setField(\'' . $fname . '\');');
 546  
 547          return '<table><tr><td>' .
 548              '<input type="hidden" name="' . $name . '__values" />' .
 549              sprintf('<select name="%s__left" multiple="multiple" size="%d" style="width:%s"%s>',
 550                      $name, $size, $width,
 551                      $lhdr ? ' onchange="Horde_Form_Assign.deselectHeaders(\'' . $fname . '\', 0);"' : '') .
 552              $var->type->getOptions(0, $fname) .
 553              '</select></td><td>' .
 554              '<a href="" onclick="Horde_Form_Assign.move(\'' . $fname .
 555              '\', 0); return false;">' .
 556              Horde::img('rhand.png', _("Add column"), null, $registry->getImageDir('horde')) .
 557              '</a><br /><a href="" onclick="Horde_Form_Assign.move(\'' .
 558              $fname . '\', 1); return false;">' .
 559              Horde::img('lhand.png', _("Remove column"), null, $registry->getImageDir('horde')) .
 560              '</a></td><td>' .
 561              sprintf('<select name="%s__right" multiple="multiple" size="%d" style="width:%s"%s>',
 562                      $name, $size, $width,
 563                      $rhdr ? ' onchange="Horde_Form_Assign.deselectHeaders(\'' . $fname . '\', 1);"' : '') .
 564              $var->type->getOptions(1, $fname) .
 565              '</select></td></tr></table>';
 566      }
 567  
 568      function _renderVarInput_invalid(&$form, &$var, &$vars)
 569      {
 570          return $this->_renderVarDisplay_invalid($form, $var, $vars);
 571      }
 572  
 573      function _renderVarInput_enum(&$form, &$var, &$vars)
 574      {
 575          $values = $var->getValues();
 576          $prompt = $var->type->getPrompt();
 577          $htmlchars = $var->getOption('htmlchars');
 578          if (!empty($prompt)) {
 579              $prompt = '<option value="">' . ($htmlchars ? $prompt : @htmlspecialchars($prompt, ENT_QUOTES, $this->_charset)) . '</option>';
 580          }
 581          $varname = @htmlspecialchars($var->getVarName(), ENT_QUOTES, $this->_charset);
 582          return sprintf('<select name="%s" id="%s" %s>%s%s</select>',
 583                         $varname,
 584                         $varname,
 585                         $this->_getActionScripts($form, $var),
 586                         $prompt,
 587                         $this->_selectOptions($values, $var->getValue($vars), $htmlchars));
 588      }
 589  
 590      function _renderVarInput_mlenum(&$form, &$var, &$vars)
 591      {
 592          $varname = $var->getVarName();
 593          $hvarname = @htmlspecialchars($varname, ENT_QUOTES, $this->_charset);
 594          $values = $var->getValues();
 595          $prompts = $var->type->getPrompts();
 596          $selected = $var->getValue($vars);
 597          /* If passing a non-array value need to get the keys. */
 598          if (!is_array($selected)) {
 599              foreach ($values as $key_1 => $values_2) {
 600                  if (isset($values_2[$selected])) {
 601                      $selected = array('1' => $key_1, '2' => $selected);
 602                      break;
 603                  }
 604              }
 605          }
 606  
 607          /* Hidden tag to store the current first level. */
 608          $html = sprintf('<input type="hidden" name="%s[old]" value="%s" %s />',
 609                          $hvarname,
 610                          @htmlspecialchars($selected['1'], ENT_QUOTES, $this->_charset),
 611                          $this->_genID($varname . '[old]'));
 612  
 613          /* First level. */
 614          require_once  'Horde/Array.php';
 615          $values_1 = Horde_Array::valuesToKeys(array_keys($values));
 616          $html .= sprintf('<select %s name="%s[1]" onchange="%s"%s>',
 617                           $this->_genID($varname . '[1]'),
 618                           $hvarname,
 619                           'if (this.value) { document.' . $form->getName() . '.formname.value=\'\';' . 'document.' . $form->getName() . '.submit() }',
 620                           ($var->hasAction() ? ' ' . $this->_genActionScript($form, $var->_action, $varname) : ''));
 621          if (!empty($prompts)) {
 622              $html .= '<option value="">' . @htmlspecialchars($prompts[0], ENT_QUOTES, $this->_charset) . '</option>';
 623          }
 624          $html .= $this->_selectOptions($values_1, $selected['1']);
 625          $html .= '</select>';
 626  
 627          /* Second level. */
 628          $html .= sprintf('<select %s name="%s[2]"%s>',
 629                           $this->_genID($varname . '[2]'),
 630                           $hvarname,
 631                           ($var->hasAction() ? ' ' . $this->_genActionScript($form, $var->_action, $varname) : ''));
 632          if (!empty($prompts)) {
 633              $html .= '<option value="">' . @htmlspecialchars($prompts[1], ENT_QUOTES, $this->_charset) . '</option>';
 634          }
 635          $values_2 = array();
 636          if (!empty($selected['1'])) {
 637              $values_2 = &$values[$selected['1']];
 638          }
 639          return $html . $this->_selectOptions($values_2, $selected['2']) . '</select>';
 640      }
 641  
 642      function _renderVarInput_multienum(&$form, &$var, &$vars)
 643      {
 644          $values = $var->getValues();
 645          $selected = $vars->getExists($var->getVarName(), $wasset);
 646          if (!$wasset) {
 647              $selected = $var->getDefault();
 648          }
 649          return sprintf('<select multiple="multiple" size="%s" name="%s[]" %s>%s</select>',
 650                         (int)$var->type->size,
 651                         @htmlspecialchars($var->getVarName(), ENT_QUOTES, $this->_charset),
 652                         $this->_getActionScripts($form, $var),
 653                         $this->_multiSelectOptions($values, $selected)) .
 654              "<br />\n" . _("To select multiple items, hold down the Control (PC) or Command (Mac) key while clicking.") . "\n";
 655      }
 656  
 657      function _renderVarInput_radio(&$form, &$var, &$vars)
 658      {
 659          return $this->_radioButtons($var->getVarName(),
 660                                      $var->getValues(),
 661                                      $var->getValue($vars),
 662                                      $this->_getActionScripts($form, $var));
 663      }
 664  
 665      function _renderVarInput_set(&$form, &$var, &$vars)
 666      {
 667          $html = $this->_checkBoxes($var->getVarName(),
 668                                     $var->getValues(),
 669                                     $var->getValue($vars),
 670                                     $this->_getActionScripts($form, $var));
 671  
 672          if ($var->type->_checkAll) {
 673              $form_name = $form->getName();
 674              $var_name = $var->getVarName() . '[]';
 675              $function_name = 'select'  . $form_name . $var->getVarName();
 676              $enable = _("Select all");
 677              $disable = _("Select none");
 678              $invert = _("Invert selection");
 679              $html .= <<<EOT
 680  <script type="text/javascript">
 681  function $function_name()
 682  {
 683      for (var i = 0; i < document.$form_name.elements.length; i++) {
 684          f = document.$form_name.elements[i];
 685          if (f.name != '$var_name') {
 686              continue;
 687          }
 688          if (arguments.length) {
 689              f.checked = arguments[0];
 690          } else {
 691              f.checked = !f.checked;
 692          }
 693      }
 694  }
 695  </script>
 696  <a href="#" onclick="$function_name(true); return false;">$enable</a>,
 697  <a href="#" onclick="$function_name(false); return false;">$disable</a>,
 698  <a href="#" onclick="$function_name(); return false;">$invert</a>
 699  EOT;
 700          }
 701  
 702          return $html;
 703      }
 704  
 705      function _renderVarInput_link(&$form, &$var, &$vars)
 706      {
 707          return $this->_renderVarDisplay_link($form, $var, $vars);
 708      }
 709  
 710      function _renderVarInput_html(&$form, &$var, &$vars)
 711      {
 712          return $this->_renderVarDisplay_html($form, $var, $vars);
 713      }
 714  
 715      function _renderVarInput_email(&$form, &$var, &$vars)
 716      {
 717          return sprintf('<input type="text" name="%s" id="%s" value="%s"%s />',
 718                         $var->getVarName(),
 719                         $var->getVarName(),
 720                         $var->getValue($vars),
 721                         $this->_getActionScripts($form, $var));
 722      }
 723  
 724      function _renderVarInput_matrix(&$form, &$var, &$vars)
 725      {
 726          $varname   = $var->getVarName();
 727          $var_array = $var->getValue($vars);
 728          $cols      = $var->type->getCols();
 729          $rows      = $var->type->getRows();
 730          $matrix    = $var->type->getMatrix();
 731          $new_input = $var->type->getNewInput();
 732  
 733          $html = '<table cellspacing="0"><tr>';
 734  
 735          $html .= '<td align="right" width="20%"></td>';
 736          foreach ($cols as $col_title) {
 737              $html .= sprintf('<td align="center" width="1%%">%s</td>', $col_title);
 738          }
 739          $html .= '<td align="right" width="60%"></td></tr>';
 740  
 741          /* Offer a new row of data to be added to the matrix? */
 742          if ($new_input) {
 743              $html .= '<tr><td>';
 744              if (is_array($new_input)) {
 745                  $html .= sprintf('<select %s name="%s[n][r]"><option value="">%s</option>%s</select><br />',
 746                         $this->_genID($varname . '[n][r]'),
 747                         $varname,
 748                         _("-- select --"),
 749                         $this->_selectOptions($new_input, $var_array['n']['r']));
 750              } elseif ($new_input == true) {
 751                  $html .= sprintf('<input %s type="text" name="%s[n][r]" value="%s" />',
 752                         $this->_genID($varname . '[n][r]'),
 753                         $varname,
 754                         $var_array['n']['r']);
 755              }
 756              $html .= ' </td>';
 757              foreach ($cols as $col_id => $col_title) {
 758                  $html .= sprintf('<td align="center"><input type="checkbox" class="checkbox" name="%s[n][v][%s]" /></td>', $varname, $col_id);
 759              }
 760              $html .= '<td> </td></tr>';
 761          }
 762  
 763          /* Loop through the rows and create checkboxes for each column. */
 764          foreach ($rows as $row_id => $row_title) {
 765              $html .= sprintf('<tr><td>%s</td>', $row_title);
 766              foreach ($cols as $col_id => $col_title) {
 767                  $html .= sprintf('<td align="center"><input type="checkbox" class="checkbox" name="%s[r][%s][%s]"%s /></td>', $varname, $row_id, $col_id, (!empty($matrix[$row_id][$col_id]) ? ' checked="checked"' : ''));
 768              }
 769              $html .= '<td> </td></tr>';
 770          }
 771  
 772          return $html . '</table>';
 773      }
 774  
 775      function _renderVarInput_password(&$form, &$var, &$vars)
 776      {
 777          $varname = @htmlspecialchars($var->getVarName(), ENT_QUOTES, $this->_charset);
 778          return sprintf('<input type="password" name="%s" id="%s" value="%s"%s />',
 779                         $varname,
 780                         $varname,
 781                         @htmlspecialchars($var->getValue($vars), ENT_QUOTES, $this->_charset),
 782                         $this->_getActionScripts($form, $var));
 783      }
 784  
 785      function _renderVarInput_emailconfirm(&$form, &$var, &$vars)
 786      {
 787          $email = $var->getValue($vars);
 788          $varname = @htmlspecialchars($var->getVarName(), ENT_QUOTES, $this->_charset);
 789          return sprintf('<input type="text" name="%s[original]" id="%s[original]" value="%s"%s />',
 790                         $varname,
 791                         $varname,
 792                         @htmlspecialchars($email['original'], ENT_QUOTES, $this->_charset),
 793                         $this->_getActionScripts($form, $var)) .
 794              ' ' . sprintf('<input type="text" name="%s[confirm]" id="%s[confirm]" value="%s"%s />',
 795                            $varname,
 796                            $varname,
 797                            @htmlspecialchars($email['confirm'], ENT_QUOTES, $this->_charset),
 798                            $this->_getActionScripts($form, $var));
 799      }
 800  
 801      function _renderVarInput_passwordconfirm(&$form, &$var, &$vars)
 802      {
 803          $password = $var->getValue($vars);
 804          $varname = @htmlspecialchars($var->getVarName(), ENT_QUOTES, $this->_charset);
 805          return sprintf('<input type="password" name="%s[original]" id="%s[original]" value="%s"%s />',
 806                         $varname,
 807                         $varname,
 808                         @htmlspecialchars($password['original'], ENT_QUOTES, $this->_charset),
 809                         $this->_getActionScripts($form, $var)) .
 810              ' ' . sprintf('<input type="password" name="%s[confirm]" id="%s[confirm]" value="%s"%s />',
 811                            $varname,
 812                            $varname,
 813                            @htmlspecialchars($password['confirm'], ENT_QUOTES, $this->_charset),
 814                            $this->_getActionScripts($form, $var));
 815      }
 816  
 817      function _renderVarInput_boolean(&$form, &$var, &$vars)
 818      {
 819          $varname = @htmlspecialchars($var->getVarName(), ENT_QUOTES, $this->_charset);
 820          $html = '<input type="checkbox" class="checkbox" name="' .  $varname . '"' .
 821              ' id="' . $varname . '"' . ($var->getValue($vars) ? ' checked="checked"' : '');
 822          if ($var->hasAction()) {
 823              $html .= $this->_genActionScript($form, $var->_action,
 824                                               $var->getVarName());
 825          }
 826          return $html . ' />';
 827      }
 828  
 829      function _renderVarInput_creditcard(&$form, &$var, &$vars)
 830      {
 831          $varname = @htmlspecialchars($var->getVarName(), ENT_QUOTES, $this->_charset);
 832          $html = '<input type="text" name="' . $varname . '" id="' . $varname . '" value="' .
 833              @htmlspecialchars($var->getValue($vars), ENT_QUOTES, $this->_charset) . '"';
 834          if ($var->hasAction()) {
 835              $html .= $this->_genActionScript($form, $var->_action,
 836                                               $var->getVarName());
 837          }
 838          return $html . ' />';
 839      }
 840  
 841      function _renderVarInput_obrowser(&$form, &$var, &$vars)
 842      {
 843          $varname = $var->getVarName();
 844          $varvalue = $vars->get($varname);
 845          $fieldId = $this->_genID(md5(uniqid(rand(), true)), false) . 'id';
 846          $html = '
 847              <script type="text/javascript">
 848              var obrowserWindowName;
 849              function obrowserCallback(name, oid)
 850              {
 851                  if (name == obrowserWindowName) {
 852                      document.getElementById(\'' . $fieldId . '\').value = oid;
 853                      return false;
 854                  } else {
 855                      return "Invalid window name supplied";
 856                  }
 857              }
 858              </script>
 859              ';
 860          $html .= sprintf('<input type="hidden" name="%s" id="%s"%s value="%s">',
 861                           @htmlspecialchars($varname, ENT_QUOTES, $this->_charset),
 862                           $fieldId,
 863                           $this->_getActionScripts($form, $var),
 864                           @htmlspecialchars($varvalue, ENT_QUOTES, $this->_charset));
 865          if (!empty($varvalue)) {
 866              $html .= $varvalue;
 867          }
 868  
 869          if ($GLOBALS['browser']->hasFeature('javascript')) {
 870              Horde::addScriptFile('popup.js', 'horde', true);
 871              $imgId = $this->_genID($varname, false) . 'goto';
 872              $html .= '<div id="goto" class="headerbox" style="position:absolute;visibility:hidden;padding:0"></div>' .
 873                  Horde::link('#', _("Select an object"), '', '', 'obrowserWindow = popup(\'' . $GLOBALS['registry']->get('webroot', 'horde') . '/services/obrowser/' . '\'); obrowserWindowName = obrowserWindow.name; return false;') . Horde::img('tree/leaf.png', _("Object"), 'id="' . $imgId . '" align="middle"', $GLOBALS['registry']->getImageDir('horde')) . "</a>\n";
 874          }
 875  
 876          return $html;
 877      }
 878  
 879      function _renderVarInput_dblookup(&$form, &$var, &$vars)
 880      {
 881          return $this->_renderVarInput_enum($form, $var, $vars);
 882      }
 883  
 884      function _renderVarInput_figlet(&$form, &$var, &$vars)
 885      {
 886          $varname = @htmlspecialchars($var->getVarName(), ENT_QUOTES, $this->_charset);
 887          return sprintf('<input type="text" name="%s" id="%s" size="%s" value="%s" />',
 888                         $varname,
 889                         $varname,
 890                         strlen($var->type->getText()),
 891                         @htmlspecialchars($var->getValue($vars), ENT_QUOTES, $this->_charset)) .
 892              '<br />' . _("Enter the letters below:") . '<br />' .
 893              $this->_renderVarDisplay_figlet($form, $var, $vars);
 894      }
 895  
 896      function _renderVarDisplayDefault(&$form, &$var, &$vars)
 897      {
 898          return nl2br(@htmlspecialchars($var->getValue($vars), ENT_QUOTES, $this->_charset));
 899      }
 900  
 901      function _renderVarDisplay_html(&$form, &$var, &$vars)
 902      {
 903          // Since this is an HTML type we explicitly don't escape
 904          // it. User beware.
 905          return $var->getValue($vars);
 906      }
 907  
 908      function _renderVarDisplay_email(&$form, &$var, &$vars)
 909      {
 910          $display_email = $email = $var->getValue($vars);
 911  
 912          if ($var->type->_strip_domain && strpos($email, '@') !== false) {
 913              $display_email = str_replace(array('@', '.'),
 914                                           array(' (at) ', ' (dot) '),
 915                                           $email);
 916          }
 917  
 918          if ($var->type->_link_compose) {
 919              $email_val = trim($email);
 920  
 921              // Format the address according to RFC822.
 922              $mailbox_host = explode('@', $email_val);
 923              if (!isset($mailbox_host[1])) {
 924                  $mailbox_host[1] = '';
 925              }
 926  
 927              $name = null;
 928              if ($var->type->_link_name) {
 929                  $name = $var->type->_link_name;
 930              }
 931  
 932              require_once 'Horde/MIME.php';
 933              $address = MIME::rfc822WriteAddress($mailbox_host[0], $mailbox_host[1], $name);
 934  
 935              // Get rid of the trailing @ (when no host is included in
 936              // the email address).
 937              $address = str_replace('@>', '>', $address);
 938              $mail_link = $GLOBALS['registry']->call('mail/compose', array(array('to' => addslashes($address))));
 939              if (is_a($mail_link, 'PEAR_Error')) {
 940                  $mail_link = 'mailto:' . urlencode($address);
 941              }
 942  
 943              return Horde::link($mail_link, $email_val) . @htmlspecialchars($display_email, ENT_QUOTES, $this->_charset) . '</a>';
 944          } else {
 945              return nl2br(@htmlspecialchars($display_email, ENT_QUOTES, $this->_charset));
 946          }
 947      }
 948  
 949      function _renderVarDisplay_password(&$form, &$var, &$vars)
 950      {
 951          return '********';
 952      }
 953  
 954      function _renderVarDisplay_passwordconfirm(&$form, &$var, &$vars)
 955      {
 956          return '********';
 957      }
 958  
 959      function _renderVarDisplay_octal(&$form, &$var, &$vars)
 960      {
 961          return sprintf('0%o', octdec($var->getValue($vars)));
 962      }
 963  
 964      function _renderVarDisplay_boolean(&$form, &$var, &$vars)
 965      {
 966          return $var->getValue($vars) ? _("Yes") : _("No");
 967      }
 968  
 969      function _renderVarDisplay_enum(&$form, &$var, &$vars)
 970      {
 971          $values = $var->getValues();
 972          $value = $var->getValue($vars);
 973          if (count($values) == 0) {
 974              return _("No values");
 975          } elseif (isset($values[$value]) && $value != '') {
 976              return @htmlspecialchars($values[$value], ENT_QUOTES, $this->_charset);
 977          }
 978      }
 979  
 980      function _renderVarDisplay_radio(&$form, &$var, &$vars)
 981      {
 982          $values = $var->getValues();
 983          if (count($values) == 0) {
 984              return _("No values");
 985          } elseif (isset($values[$var->getValue($vars)])) {
 986              return @htmlspecialchars($values[$var->getValue($vars)], ENT_QUOTES, $this->_charset);
 987          }
 988      }
 989  
 990      function _renderVarDisplay_multienum(&$form, &$var, &$vars)
 991      {
 992          $values = $var->getValues();
 993          $on = $var->getValue($vars);
 994          if (!count($values) || !count($on)) {
 995              return _("No values");
 996          } else {
 997              $display = array();
 998              foreach ($values as $value => $name) {
 999                  if (in_array($value, $on)) {
1000                      $display[] = $name;
1001                  }
1002              }
1003              return @htmlspecialchars(implode(', ', $display), ENT_QUOTES, $this->_charset);
1004          }
1005      }
1006  
1007      function _renderVarDisplay_set(&$form, &$var, &$vars)
1008      {
1009          $values = $var->getValues();
1010          $on = $var->getValue($vars);
1011          if (!count($values) || !count($on)) {
1012              return _("No values");
1013          } else {
1014              $display = array();
1015              foreach ($values as $value => $name) {
1016                  if (in_array($value, $on)) {
1017                      $display[] = $name;
1018                  }
1019              }
1020              return @htmlspecialchars(implode(', ', $display), ENT_QUOTES, $this->_charset);
1021          }
1022      }
1023  
1024      function _renderVarDisplay_image(&$form, &$var, &$vars)
1025      {
1026          $img_params = $var->getValue($vars);
1027          $img_url = Horde::url($GLOBALS['registry']->get('webroot', 'horde') . '/services/images/view.php');
1028          $img_url = Util::addParameter($img_url, $img_params);
1029  
1030          return Horde::img($img_url, isset($img_params['f']) ? $img_params['f'] : '', '', '');
1031      }
1032  
1033      function _renderVarDisplay_cellphone(&$form, &$var, &$vars)
1034      {
1035          global $registry;
1036  
1037          $number = $var->getValue($vars);
1038          $html = @htmlspecialchars($number, ENT_QUOTES, $this->_charset);
1039  
1040          if ($number && $registry->hasMethod('sms/compose')) {
1041              $url = $registry->link('sms/compose', array('to' => $number));
1042              $html .= ' ' . Horde::link($url, _("Send SMS")) . Horde::img('mobile.png', _("Send SMS"), '', $registry->getImageDir('horde')) . '</a>';
1043          }
1044  
1045          return $html;
1046      }
1047  
1048      function _renderVarDisplay_address(&$form, &$var, &$vars)
1049      {
1050          global $registry;
1051  
1052          $address = $var->getValue($vars);
1053          $aus_state_regex = '(?:ACT|NSW|NT|QLD|SA|TAS|VIC|WA)';
1054  
1055          if (preg_match('/((?:A[BL]|B[ABDHLNRST]?|C[ABFHMORTVW]|D[ADEGHLNTY]|E[CHNX]?|F[KY]|G[LUY]?|H[ADGPRSUX]|I[GMPV]|JE|K[ATWY]|L[ADELNSU]?|M[EKL]?|N[EGNPRW]?|O[LX]|P[AEHLOR]|R[GHM]|S[AEGKLMNOPRSTWY]?|T[ADFNQRSW]|UB|W[ACDFNRSV]?|YO|ZE)\d(?:\d|[A-Z])? \d[A-Z]{2})/', $address, $postcode)) {
1056              /* UK postcode detected. */
1057              /* Multimap.co.uk generated map */
1058              $mapurl = 'http://www.multimap.com/map/browse.cgi?pc=' . urlencode($postcode[1]);
1059              $desc = _("Multimap UK map");
1060              $icon = 'map.png';
1061          } elseif (preg_match('/\b' . $aus_state_regex . '\b/', $address)) {
1062              /* Australian state detected. */
1063              /* Whereis.com.au generated map */
1064              $mapurl = 'http://www.whereis.com.au/whereis/mapping/geocodeAddress.do?';
1065              $desc = _("Whereis Australia map");
1066              $icon = 'map.png';
1067              /* Split out the address, line-by-line. */
1068              $addressLines = explode("\n", $address);
1069              for ($i = 0; $i < count($addressLines); $i++) {
1070                  /* See if it's the street number & name. */
1071                  if (preg_match('/(\d+\s*\/\s*)?(\d+|\d+[a-zA-Z])\s+([a-zA-Z ]*)/', $addressLines[$i], $lineParts)) {
1072                      $mapurl .= '&streetNumber=' . urlencode($lineParts[2]) . '&streetName=' . urlencode($lineParts[3]);
1073                  }
1074                  /* Look for "Suburb, State". */
1075                  if (preg_match('/([a-zA-Z ]*),?\s+' . $aus_state_regex . '/', $addressLines[$i], $lineParts)) {
1076                      $mapurl .= '&suburb=' . urlencode($lineParts[1]);
1077                  }
1078                  /* Look for "State <4 digit postcode>". */
1079                  if (preg_match('/(' . $aus_state_regex . ')\s+(\d{4})/', $addressLines[$i], $lineParts)) {
1080                      $mapurl .= '&state=' . urlencode($lineParts[1]);
1081                  }
1082              }
1083          } elseif (preg_match('/(.*)\n(.*)\s*,\s*(\w+)\.?\s+(\d+|[a-zA-Z]\d[a-zA-Z]\s?\d[a-zA-Z]\d)/', $address, $addressParts)) {
1084              /* American/Canadian address style. */
1085              /* Mapquest generated map */
1086              $mapurl = 'http://www.mapquest.com/maps/map.adp?size=big&zoom=7';
1087              $desc = _("MapQuest map");
1088              $icon = 'map.png';
1089              $country = null;
1090              if (!empty($addressParts[4]) && preg_match('|[a-zA-Z]\d[a-zA-Z]\s?\d[a-zA-Z]\d|', $addressParts[4])) {
1091                  $country = 'CA';
1092              }
1093              if (!empty($addressParts[1])) {
1094                  $mapurl .= '&address=' . urlencode($addressParts[1]);
1095              }
1096              if (!empty($addressParts[2])) {
1097                  $mapurl .= '&city=' . urlencode($addressParts[2]);
1098              }
1099              if (!empty($addressParts[3])) {
1100                  $mapurl .= '&state=' . urlencode($addressParts[3]);
1101              }
1102              if (!empty($addressParts[4])) {
1103                  if ($country == 'CA') {
1104                      $mapurl .= '&country=CA';
1105                  }
1106                  $mapurl .= '&zipcode=' . urlencode($addressParts[4]);
1107              }
1108  
1109              /* Yahoo! generated map. */
1110              $mapurl2 = 'http://us.rd.yahoo.com/maps/home/submit_a/*-http://maps.yahoo.com/maps?srchtype=a&getmap=Get+Map&';
1111              $desc2 = _("Yahoo! map");
1112              $icon2 = 'map.png';
1113              if (!empty($addressParts[1])) {
1114                  $mapurl2 .= '&addr=' . urlencode($addressParts[1]);
1115              }
1116              /* Give precedence to zipcode over city/state */
1117              if (empty($addressParts[4]) && !empty($addressParts[2]) && !empty($addressParts[3])) {
1118                  $mapurl2 .= '&csz=' . urlencode($addressParts[2] . ' ' . $addressParts[3]);
1119              }
1120              if (!empty($addressParts[4])) {
1121                  if (preg_match('|([a-zA-Z]\d[a-zA-Z])\s?(\d[a-zA-Z]\d)|', $addressParts[4], $pcParts)) {
1122                      $mapurl2 .= '&country=ca';
1123                      /* make sure the postal-code has a space */
1124                      $addressParts[4] = $pcParts[1] . ' ' . $pcParts[2];
1125                  }
1126                  $mapurl2 .= '&csz=' . urlencode($addressParts[4]);
1127              }
1128  
1129              /* Google generated map. */
1130              $mapurl3 = 'http://maps.google.com/maps?q=' . urlencode($addressParts[0]) . '&hl=en';
1131              $desc3 = _("Google Maps");
1132              $icon3 = 'map.png';
1133  
1134          } elseif (preg_match('/(.*?)\r?\n([A-Z]{1,3})-(\d{5})\s+(.*)/i', $address, $addressParts)) {
1135              /* European address style. */
1136              include 'Horde/NLS/carsigns.php';
1137              $country = array_search(String::upper($addressParts[2]), $carsigns);
1138  
1139              /* Map24 generated map. */
1140              if (in_array($country, array('al', 'ad', 'am', 'az', 'be', 'ba',
1141                                           'bg', 'de', 'dk', 'ee', 'fo', 'fi',
1142                                           'fr', 'ge', 'gr', 'gb', 'ie', 'is',
1143                                           'it', 'hr', 'lv', 'li', 'lt', 'lu',
1144                                           'mt', 'mk', 'md', 'mc', 'nl', 'no',
1145                                           'pl', 'pt', 'ro', 'ru', 'se', 'ch',
1146                                           'cs', 'sk', 'si', 'es', 'cz', 'tr',
1147                                           'ua', 'hu', 'by', 'cy', 'at'))) {
1148                  if (in_array($country, array('at', 'be', 'ch', 'de', 'dk',
1149                                               'es', 'fi', 'fr', 'it', 'nl',
1150                                               'no', 'se'))) {
1151                      $mirror = $country;
1152                  } else {
1153                      $mirror = 'uk';
1154                  }
1155                  $mapurl = 'http://www.' . $mirror . '.map24.com/source/address/v2.0.0/cnt_nav_maplet.php?cid=validateaddr&country=' . $country;
1156                  $desc = _("Map24 map");
1157                  $icon = 'map_eu.png';
1158                  if (!empty($addressParts[1])) {
1159                      $mapurl .= '&street=' . urlencode($addressParts[1]);
1160                  }
1161                  if (!empty($addressParts[3])) {
1162                      $mapurl .= '&zip=' . urlencode($addressParts[3]);
1163                  }
1164                  if (!empty($addressParts[4])) {
1165                      $mapurl .= '&city=' . urlencode($addressParts[4]);
1166                  }
1167              }
1168  
1169              /* Mapquest generated map. */
1170              $mapurl2 = 'http://www.mapquest.com/maps/map.adp?country=' . String::upper($country);
1171              $desc2 = _("MapQuest map");
1172              $icon2 = 'map_eu.png';
1173              if (!empty($addressParts[1])) {
1174                  $mapurl2 .= '&address=' . urlencode($addressParts[1]);
1175              }
1176              if (!empty($addressParts[3])) {
1177                  $mapurl2 .= '&zipcode=' . urlencode($addressParts[3]);
1178              }
1179              if (!empty($addressParts[4])) {
1180                  $mapurl2 .= '&city=' . urlencode($addressParts[4]);
1181              }
1182          }
1183  
1184          $html = nl2br(@htmlspecialchars($address, ENT_QUOTES, $this->_charset));
1185          if (!empty($mapurl)) {
1186              $html .= '&nbsp;&nbsp;' . Horde::link(Horde::externalUrl($mapurl), $desc, null, '_blank') . Horde::img($icon, $desc, 'align="middle"', $registry->getImageDir('horde')) . '</a>';
1187          }
1188          if (!empty($mapurl2)) {
1189              $html .= '&nbsp;' . Horde::link(Horde::externalUrl($mapurl2), $desc2, null, '_blank') . Horde::img($icon2, $desc2, 'align="middle"', $registry->getImageDir('horde')) . '</a>';
1190          }
1191          if (!empty($mapurl3)) {
1192              $html .= '&nbsp;' . Horde::link(Horde::externalUrl($mapurl3), $desc3, null, '_blank') . Horde::img($icon3, $desc3, 'align="middle"', $registry->getImageDir('horde')) . '</a>';
1193          }
1194  
1195          return $html;
1196      }
1197  
1198      function _renderVarDisplay_date(&$form, &$var, &$vars)
1199      {
1200          return htmlspecialchars($var->type->getFormattedTime($var->getValue($vars)));
1201      }
1202  
1203      function _renderVarDisplay_hourminutesecond(&$form, &$var, &$vars)
1204      {
1205          $time = $var->type->getTimeParts($var->getValue($vars));
1206          if (!$var->type->_show_seconds) {
1207              return (int)$time['hour'] . ':' . sprintf('%02d', (int)$time['minute']);
1208          } else {
1209              return (int)$time['hour'] . ':' . sprintf('%02d', (int)$time['minute']) . ':' . sprintf('%02d', (int)$time['second']);
1210          }
1211      }
1212  
1213      function _renderVarDisplay_monthyear(&$form, &$var, &$vars)
1214      {
1215          return (int)$vars->get($var->getVarName() . '[month]') . ', ' . (int)$vars->get($var->getVarName() . '[year]');
1216      }
1217  
1218      function _renderVarDisplay_monthdayyear(&$form, &$var, &$vars)
1219      {
1220          $date = $var->getValue($vars);
1221          if ((is_array($date) && !empty($date['year']) &&
1222               !empty($date['month']) && !empty($date['day']))
1223              || (!is_array($date) && !empty($date))) {
1224              return $var->type->formatDate($date);
1225          }
1226          return '';
1227      }
1228  
1229      function _renderVarDisplay_invalid(&$form, &$var, &$vars)
1230      {
1231          return '<span class="form-error">' . @htmlspecialchars($var->type->message, ENT_QUOTES, $this->_charset) . '</span>';
1232      }
1233  
1234      function _renderVarDisplay_link(&$form, &$var, &$vars)
1235      {
1236          $values = $var->type->values;
1237          if (!isset($values[0])) {
1238              $values = array($values);
1239          }
1240  
1241          $count = count($values);
1242          $html = '';
1243          for ($i = 0; $i < $count; $i++) {
1244              if (empty($values[$i]['url']) || empty($values[$i]['text'])) {
1245                  continue;
1246              }
1247              if (!isset($values[$i]['target'])) {
1248                  $values[$i]['target'] = '';
1249              }
1250              if (!isset($values[$i]['onclick'])) {
1251                  $values[$i]['onclick'] = '';
1252              }
1253              if (!isset($values[$i]['title'])) {
1254                  $values[$i]['title'] = '';
1255              }
1256              if (!isset($values[$i]['accesskey'])) {
1257                  $values[$i]['accesskey'] = '';
1258              }
1259              if ($i > 0) {
1260                  $html .= ' | ';
1261              }
1262              $html .= Horde::link($values[$i]['url'], $values[$i]['text'], 'widget', $values[$i]['target'], $values[$i]['onclick'], $values[$i]['title'], $values[$i]['accesskey']) . @htmlspecialchars($values[$i]['text'], ENT_QUOTES, $this->_charset) . '</a>';
1263          }
1264  
1265          return $html;
1266      }
1267  
1268      function _renderVarDisplay_dblookup(&$form, &$var, &$vars)
1269      {
1270          return $this->_renderVarDisplay_enum($form, $var, $vars);
1271      }
1272  
1273      function _renderVarDisplay_figlet(&$form, &$var, &$vars)
1274      {
1275          static $figlet;
1276  
1277          if (!isset($figlet)) {
1278              require_once 'Text/Figlet.php';
1279              $figlet = &new Text_Figlet();
1280          }
1281  
1282          $result = $figlet->loadFont($var->type->getFont());
1283          if (is_a($result, 'PEAR_Error')) {
1284              return $result->getMessage();
1285          }
1286  
1287          return '<pre>' . $figlet->lineEcho($var->type->getText()) . '</pre>';
1288      }
1289  
1290      function _renderVarInput_selectFiles(&$form, &$var, &$vars)
1291      {
1292          /* Needed for gollem js calls */
1293          $varname = @htmlspecialchars($var->getVarName(), ENT_QUOTES, $this->_charset);
1294          $html = sprintf('<input type="hidden" name="%s" id="%s" value="%s" />',
1295                          'selectlist_selectid',
1296                          'selectlist_selectid',
1297                          $var->type->_selectid) .
1298              sprintf('<input type="hidden" name="%s" id="%s" />', 'actionID', 'actionID') .
1299  
1300              /* Form field. */
1301              sprintf('<input type="hidden" name="%s" id="%s" value="%s" />',
1302                      $varname,
1303                      $varname,
1304                      $var->type->_selectid);
1305  
1306          /* Open window link. */
1307          $param = array($var->type->_link_text,
1308                         $var->type->_link_style,
1309                         $form->getName(),
1310                         $var->type->_icon,
1311                         $var->type->_selectid);
1312          $html .= $GLOBALS['registry']->call('files/selectlistLink', $param) . "<br />\n";
1313  
1314          if ($var->type->_selectid) {
1315              $param = array($var->type->_selectid);
1316              $files = $GLOBALS['registry']->call('files/selectlistResults', $param);
1317              if ($files) {
1318                  foreach ($files as $id => $file) {
1319                      $dir = key($file);
1320                      $filename = current($file);
1321                      $html .= ($id + 1) . '. ';
1322                      if (!empty($dir) && ($dir != '.')) {
1323                          $filename = $dir . '/' . $filename;
1324                      }
1325                      $html .= @htmlspecialchars($filename, ENT_QUOTES, $this->_charset) . "<br />\n";
1326                  }
1327              }
1328          }
1329  
1330          return $html;
1331      }
1332  
1333      function _selectOptions(&$values, $selectedValue = false,
1334                              $htmlchars = false)
1335      {
1336          $result = '';
1337          $sel = false;
1338          foreach ($values as $value => $display) {
1339              if (!is_null($selectedValue) && !$sel &&
1340                  $value == $selectedValue &&
1341                  strlen($value) == strlen($selectedValue)) {
1342                  $selected = ' selected="selected"';
1343                  $sel = true;
1344              } else {
1345                  $selected = '';
1346              }
1347              $result .= ' <option value="';
1348              $result .= $htmlchars
1349                  ? $value
1350                  : @htmlspecialchars($value, ENT_QUOTES, $this->_charset);
1351              $result .= '"' . $selected . '>';
1352              $result .= $htmlchars
1353                  ? $display
1354                  : @htmlspecialchars($display, ENT_QUOTES, $this->_charset);
1355              $result .= "</option>\n";
1356          }
1357  
1358          return $result;
1359      }
1360  
1361      function _multiSelectOptions(&$values, $selectedValues)
1362      {
1363          $result = '';
1364          $sel = false;
1365          foreach ($values as $value => $display) {
1366              if (@in_array($value, $selectedValues)) {
1367                  $selected = ' selected="selected"';
1368              } else {
1369                  $selected = '';
1370              }
1371              $result .= " <option value=\"" . @htmlspecialchars($value, ENT_QUOTES, $this->_charset) . "\"$selected>" . @htmlspecialchars($display, ENT_QUOTES, $this->_charset) . "</option>\n";
1372          }
1373  
1374          return $result;
1375      }
1376  
1377      function _checkBoxes($name, $values, $checkedValues, $actions = '')
1378      {
1379          $result = '';
1380          if (!is_array($checkedValues)) {
1381              $checkedValues = array();
1382          }
1383          $i = 0;
1384          foreach ($values as $value => $display) {
1385              $checked = (in_array($value, $checkedValues)) ? ' checked="checked"' : '';
1386              $result .= sprintf('<input id="%s%s" type="checkbox" class="checkbox" name="%s[]" value="%s"%s%s /><label for="%s%s">&nbsp;%s</label><br />',
1387                                 @htmlspecialchars($name, ENT_QUOTES, $this->_charset),
1388                                 $i,
1389                                 @htmlspecialchars($name, ENT_QUOTES, $this->_charset),
1390                                 @htmlspecialchars($value, ENT_QUOTES, $this->_charset),
1391                                 $checked,
1392                                 $actions,
1393                                 @htmlspecialchars($name, ENT_QUOTES, $this->_charset),
1394                                 $i,
1395                                 @htmlspecialchars($display, ENT_QUOTES, $this->_charset));
1396              $i++;
1397          }
1398  
1399          return $result;
1400      }
1401  
1402      function _radioButtons($name, $values, $checkedValue = null, $actions = '')
1403      {
1404          $result = '';
1405          $i = 0;
1406          foreach ($values as $value => $display) {
1407              $checked = (!is_null($checkedValue) && $value == $checkedValue) ? ' checked="checked"' : '';
1408              $result .= sprintf('<input id="%s%s" type="radio" class="checkbox" name="%s" value="%s"%s%s /><label for="%s%s">&nbsp;%s</label><br />',
1409                                 @htmlspecialchars($name, ENT_QUOTES, $this->_charset),
1410                                 $i,
1411                                 @htmlspecialchars($name, ENT_QUOTES, $this->_charset),
1412                                 @htmlspecialchars($value, ENT_QUOTES, $this->_charset),
1413                                 $checked,
1414                                 $actions,
1415                                 @htmlspecialchars($name, ENT_QUOTES, $this->_charset),
1416                                 $i,
1417                                 @htmlspecialchars($display, ENT_QUOTES, $this->_charset));
1418              $i++;
1419          }
1420  
1421          return $result;
1422      }
1423  
1424      function _genID($name, $fulltag = true)
1425      {
1426          $name = @htmlspecialchars($name, ENT_QUOTES, $this->_charset);
1427          return $fulltag ? 'id="' . $name . '"' : $name;
1428      }
1429  
1430      function _genActionScript(&$form, $action, $varname)
1431      {
1432          $html = '';
1433          $triggers = $action->getTrigger();
1434          if (!is_array($triggers)) {
1435              $triggers = array($triggers);
1436          }
1437          $js = $action->getActionScript($form, $this, $varname);
1438          foreach ($triggers as $trigger) {
1439              if ($trigger == 'onload') {
1440                  $this->_addOnLoadJavascript($js);
1441              } else {
1442                  $html .= ' ' . $trigger . '="' . $js . '"';
1443              }
1444          }
1445          return $html;
1446      }
1447  
1448      function _getActionScripts(&$form, &$var)
1449      {
1450          $actions = '';
1451          if ($var->hasAction()) {
1452              $varname = $var->getVarName();
1453              $action =& $var->_action;
1454              $triggers = $action->getTrigger();
1455              if (!is_array($triggers)) {
1456                  $triggers = array($triggers);
1457              }
1458              $js = $action->getActionScript($form, $this, $varname);
1459              foreach ($triggers as $trigger) {
1460                  if ($trigger == 'onload') {
1461                      $this->_addOnLoadJavascript($js);
1462                  } else {
1463                      $actions .= ' ' . $trigger . '="' . $js . '"';
1464                  }
1465              }
1466          }
1467          return $actions;
1468      }
1469  
1470      function _addOnLoadJavascript($script)
1471      {
1472          $this->_onLoadJS[] = $script;
1473      }
1474  
1475      function renderEnd()
1476      {
1477          if (count($this->_onLoadJS)) {
1478              return "<script type=\"text/javascript\">" .
1479                  "<!--\n" .  implode("\n", $this->_onLoadJS) . "\n// -->\n" .
1480                  "</script>";
1481          } else {
1482              return '';
1483          }
1484      }
1485  
1486  }


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