[ Index ] [ Index ]     [ Classes ]     [ Functions ]     [ Variables ]     [ Constants ]

PHP Cross Reference of TXP stable 4.0.6

title

Body

[close]

/textpattern/lib/ -> txplib_forms.php (source)

   1  <?php
   2  
   3  /*
   4  $HeadURL: http://svn.textpattern.com/releases/4.0.6/source/textpattern/lib/txplib_forms.php $
   5  $LastChangedRevision: 2759 $
   6  */
   7  
   8  //-------------------------------------------------------------
   9  
  10  	function yesnoRadio($field, $var, $tabindex = '', $id = '')
  11      {
  12          $id = ($id) ? $id.'-'.$field : $field;
  13  
  14          $vals = array(
  15              '0' => gTxt('no'),
  16              '1' => gTxt('yes')
  17          );
  18  
  19          foreach ($vals as $a => $b)
  20          {
  21              $out[] = '<input type="radio" id="'.$id.'-'.$a.'" name="'.$field.'" value="'.$a.'" class="radio"';
  22              $out[] = ($a == $var) ? ' checked="checked"' : '';
  23              $out[] = ($tabindex) ? ' tabindex="'.$tabindex.'"' : '';
  24              $out[] = ' /><label for="'.$id.'-'.$a.'">'.$b.'</label> ';
  25          }
  26  
  27          return join('', $out);
  28      }
  29  
  30  //-------------------------------------------------------------
  31  
  32  	function onoffRadio($field, $var, $tabindex = '', $id = '')
  33      {
  34          $id = ($id) ? $id.'-'.$field : $field;
  35  
  36          $vals = array(
  37              '0' => gTxt('off'),
  38              '1' => gTxt('on')
  39          );
  40  
  41          foreach ($vals as $a => $b)
  42          {
  43              $out[] = '<input type="radio" id="'.$id.'-'.$a.'" name="'.$field.'" value="'.$a.'" class="radio"';
  44              $out[] = ($a == $var) ? ' checked="checked"' : '';
  45              $out[] = ($tabindex) ? ' tabindex="'.$tabindex.'"' : '';
  46              $out[] = ' /><label for="'.$id.'-'.$a.'">'.$b.'</label> ';
  47          }
  48  
  49          return join('', $out);
  50      }
  51  
  52  //-------------------------------------------------------------
  53  
  54  	function selectInput($name = '', $array = '', $value = '', $blank_first = '', $onchange = '', $select_id = '', $check_type = false)
  55      {
  56          $out = array();
  57  
  58          $selected = false;
  59  
  60          foreach ($array as $avalue => $alabel)
  61          {
  62              if ($check_type) {
  63                  if ($avalue === $value || $alabel === $value) {
  64                      $sel = ' selected="selected"';
  65                      $selected = true;
  66                  } else {
  67                      $sel = '';
  68                  }
  69              }
  70  
  71              else {
  72                  if ($avalue == $value || $alabel == $value) {
  73                      $sel = ' selected="selected"';
  74                      $selected = true;
  75                  } else {
  76                      $sel = '';
  77                  }
  78              }
  79  
  80              $out[] = n.t.'<option value="'.htmlspecialchars($avalue).'"'.$sel.'>'.htmlspecialchars($alabel).'</option>';
  81          }
  82  
  83          return '<select'.( $select_id ? ' id="'.$select_id.'"' : '' ).' name="'.$name.'" class="list"'.
  84              ($onchange == 1 ? ' onchange="submit(this.form);"' : $onchange).
  85              '>'.
  86              ($blank_first ? n.t.'<option value=""'.($selected == false ? ' selected="selected"' : '').'></option>' : '').
  87              ( $out ? join('', $out) : '').
  88              n.'</select>';
  89      }
  90  
  91  //-------------------------------------------------------------
  92  
  93  	function treeSelectInput($select_name = '', $array = '', $value = '', $select_id = '', $truncate = 0)
  94      {
  95          $out = array();
  96  
  97          $selected = false;
  98  
  99          foreach ($array as $a)
 100          {
 101              if ($a['name'] == 'root')
 102              {
 103                  continue;
 104              }
 105  
 106              extract($a);
 107  
 108              if ($name == $value)
 109              {
 110                  $sel = ' selected="selected"';
 111                  $selected = true;
 112              }
 113  
 114              else
 115              {
 116                  $sel = '';
 117              }
 118  
 119              $sp = str_repeat(sp.sp, $level);
 120  
 121              if (($truncate > 3) && (strlen(utf8_decode($title)) > $truncate)) {
 122                  $htmltitle = ' title="'.htmlspecialchars($title).'"';
 123                  $title = preg_replace('/^(.{0,'.($truncate - 3).'}).*$/su','$1',$title);
 124                  $hellip = '&#8230;';
 125              } else {
 126                  $htmltitle = $hellip = '';
 127              }
 128  
 129              $out[] = n.t.'<option value="'.htmlspecialchars($name).'"'.$htmltitle.$sel.'>'.$sp.htmlspecialchars($title).$hellip.'</option>';
 130          }
 131  
 132          return n.'<select'.( $select_id ? ' id="'.$select_id.'" ' : '' ).' name="'.$select_name.'" class="list">'.
 133              n.t.'<option value=""'.($selected == false ? ' selected="selected"' : '').'>&nbsp;</option>'.
 134              ( $out ? join('', $out) : '').
 135              n.'</select>';
 136      }
 137  
 138  //-------------------------------------------------------------
 139  	function fInput($type,                   // generic form input
 140                      $name,
 141                      $value,
 142                      $class='',
 143                      $title='',
 144                      $onClick='',
 145                      $size='',
 146                      $tab='',
 147                      $id='',
 148                      $disabled = false)
 149      {
 150          $o  = '<input type="'.$type.'" name="'.$name.'"';
 151          $o .= ' value="'.cleanfInput($value).'"';
 152          $o .= ($size)     ? ' size="'.$size.'"' : '';
 153          $o .= ($class)    ? ' class="'.$class.'"' : '';
 154          $o .= ($title)    ? ' title="'.$title.'"' : '';
 155          $o .= ($onClick)  ? ' onclick="'.$onClick.'"' : '';
 156          $o .= ($tab)      ? ' tabindex="'.$tab.'"' : '';
 157          $o .= ($id)       ? ' id="'.$id.'"' : '';
 158          $o .= ($disabled) ? ' disabled="disabled"' : '';
 159          $o .= " />";
 160          return $o;
 161      }
 162  
 163  // -------------------------------------------------------------
 164  	function cleanfInput($text)
 165      {
 166          return str_replace(
 167              array('"',"'","<",">"),
 168              array("&#34;","&#39;","&#60;","&#62;"),
 169              $text
 170          );
 171      }
 172  
 173  //-------------------------------------------------------------
 174  	function hInput($name,$value)        // hidden form input
 175      {
 176          return fInput('hidden',$name,$value);
 177      }
 178  
 179  //-------------------------------------------------------------
 180  	function sInput($step)                // hidden step input
 181      {
 182          return hInput('step',$step);
 183      }
 184  
 185  //-------------------------------------------------------------
 186  	function eInput($event)                // hidden event input
 187      {
 188          return hInput('event',$event);
 189      }
 190  
 191  //-------------------------------------------------------------
 192  
 193  	function checkbox($name, $value, $checked = '1', $tabindex = '', $id = '')
 194      {
 195          $o[] = '<input type="checkbox" name="'.$name.'" value="'.$value.'"';
 196          $o[] = ($id) ? ' id="'.$id.'"' : '';
 197          $o[] = ($checked == '1') ? ' checked="checked"' : '';
 198          $o[] = ($tabindex) ? ' tabindex="'.$tabindex.'"' : '';
 199          $o[] = ' class="checkbox" />';
 200  
 201          return join('', $o);
 202      }
 203  
 204  //-------------------------------------------------------------
 205  
 206  	function checkbox2($name, $value, $tabindex = '', $id = '')
 207      {
 208          $o[] = '<input type="checkbox" name="'.$name.'" value="1"';
 209          $o[] = ($id) ? ' id="'.$id.'"' : '';
 210          $o[] = ($value == '1') ? ' checked="checked"' : '';
 211          $o[] = ($tabindex) ? ' tabindex="'.$tabindex.'"' : '';
 212          $o[] = ' class="checkbox" />';
 213  
 214          return join('', $o);
 215      }
 216  
 217  //-------------------------------------------------------------
 218  
 219  	function radio($name, $value, $checked = '1', $id = '', $tabindex = '')
 220      {
 221          $o[] = '<input type="radio" name="'.$name.'" value="'.$value.'"';
 222          $o[] = ($id) ? ' id="'.$id.'"' : '';
 223          $o[] = ($checked == '1') ? ' checked="checked"' : '';
 224          $o[] = ($tabindex) ? ' tabindex="'.$tabindex.'"' : '';
 225          $o[] = ' class="radio" />';
 226  
 227          return join('', $o);
 228      }
 229  
 230  //-------------------------------------------------------------
 231  
 232  	function form($contents, $style = '', $onsubmit = '', $method = 'post', $class = '', $fragment = '')
 233      {
 234          return n.'<form method="'.$method.'" action="index.php'.($fragment ? '#'.$fragment.'"' : '"').
 235              ($class ? ' class="'.$class.'"' : '').
 236              ($style ? ' style="'.$style.'"' : '').
 237              ($onsubmit ? ' onsubmit="return '.$onsubmit.'"' : '').
 238              '>'.$contents.'</form>'.n;
 239      }
 240  
 241  // -------------------------------------------------------------
 242  	function fetch_editable($name,$event,$identifier,$id)
 243      {
 244          $q = fetch($name,'txp_'.$event,$identifier,$id);
 245          return htmlspecialchars($q);
 246      }
 247  
 248  //-------------------------------------------------------------
 249  
 250  	function text_area($name, $h, $w, $thing = '', $id = '')
 251      {
 252          $id = ($id) ? ' id="'.$id.'"' : '';
 253          return '<textarea'.$id.' name="'.$name.'" cols="40" rows="5" style="width:'.$w.'px; height:'.$h.'px;">'.htmlspecialchars($thing).'</textarea>';
 254      }
 255  
 256  //-------------------------------------------------------------
 257  	function type_select($options)
 258      {
 259          return '<select name="type">'.n.type_options($options).'</select>'.n;
 260      }
 261  
 262  //-------------------------------------------------------------
 263  	function type_options($array)
 264      {
 265          foreach($array as $a=>$b) {
 266              $out[] = t.'<option value="'.$a.'">'.gTxt($b).'</option>'.n;
 267          }
 268          return join('',$out);
 269      }
 270  
 271  
 272  //-------------------------------------------------------------
 273  	function radio_list($name, $values, $current_val='', $hilight_val='')
 274      {
 275          // $values is an array of value => label pairs
 276          foreach ($values as $k => $v)
 277          {
 278              $id = $name.'-'.$k;
 279              $out[] = n.t.'<li>'.radio($name, $k, ($current_val == $k) ? 1 : 0, $id).
 280                  '<label for="'.$id.'">'.($hilight_val == $k ? strong($v) : $v).'</label></li>';
 281          }
 282  
 283          return '<ul class="plain-list">'.join('', $out).n.'</ul>';
 284      }
 285  
 286  //--------------------------------------------------------------
 287  	function tsi($name,$datevar,$time,$tab='')
 288      {
 289          $size = ($name=='year') ? 4 : 2;
 290  
 291          return n.'<input type="text" name="'.$name.'" value="'.
 292              safe_strftime($datevar, $time)
 293          .'" size="'.$size.'" maxlength="'.$size.'" class="edit"'.(empty($tab) ? '' : ' tabindex="'.$tab.'"').' title="'.gTxt('article_'.$name).'" />';
 294      }
 295  
 296  ?>


Generated: Mon Feb 18 03:42:45 2008 Cross-referenced by PHPXref 0.7