[ Index ]

PHP Cross Reference of MyBB

title

Body

[close]

/admin/inc/ -> class_form.php (source)

   1  <?php
   2  /**
   3   * MyBB 1.6
   4   * Copyright 2010 MyBB Group, All Rights Reserved
   5   *
   6   * Website: http://mybb.com
   7   * License: http://mybb.com/about/license
   8   *
   9   * $Id$
  10   */
  11  
  12  /**
  13   * Generate a form on the page.
  14   */
  15  class DefaultForm
  16  {
  17      /**
  18       * @var boolean Should this form be returned instead of output to the browser?
  19       */
  20      private $_return = false;
  21      
  22      /**
  23       * @var string Contents of the form if $_return is true from __construct
  24       */
  25      public $construct_return = "";
  26  
  27      /**
  28       * Constructor. Outputs the form tag with the specified options.
  29       *
  30       * @param string The action for the form.
  31       * @param string The method (get or post) for this form.
  32       * @param string The ID of the form.
  33       * @param boolean Should file uploads be allowed for this form?
  34       * @param boolean The name of the form
  35       * @param boolean Should this form be returned instead of output to the browser?
  36       * @param boolean The onsubmit action of the form
  37       */
  38  	function __construct($script='', $method='', $id="", $allow_uploads=0, $name="", $return=false, $onsubmit="")
  39      {
  40          global $mybb;
  41          $form = "<form action=\"{$script}\" method=\"{$method}\"";
  42          if($allow_uploads != 0)
  43          {
  44              $form .= " enctype=\"multipart/form-data\"";
  45          }
  46          
  47          if($name != "")
  48          {
  49              $form .= " name=\"{$name}\"";
  50          }
  51          
  52          if($id != "")
  53          {
  54              $form .= " id=\"{$id}\"";
  55          }
  56          
  57          if($onsubmit != "")
  58          {
  59              $form .= " onsubmit=\"{$onsubmit}\"";
  60          }
  61          $form .= ">\n";
  62          $form .= $this->generate_hidden_field("my_post_key", $mybb->post_code)."\n";
  63          if($return == false)
  64          {
  65              echo $form;
  66          }
  67          else
  68          {
  69              $this->_return = true;
  70              $this->construct_return = $form;
  71          }
  72      }
  73  
  74      /**
  75       * Generate and return a hidden field.
  76       *
  77       * @param string The name of the hidden field.
  78       * @param string The value of the hidden field.
  79       * @param array Optional array of options (id)
  80       * @return string The generated hidden
  81       */
  82  	function generate_hidden_field($name, $value, $options=array())
  83      {
  84          $input = "<input type=\"hidden\" name=\"{$name}\" value=\"".htmlspecialchars_uni($value)."\"";
  85          if(isset($options['id']))
  86          {
  87              $input .= " id=\"".$options['id']."\"";
  88          }
  89          $input .= " />";
  90          return $input;
  91      }
  92      
  93      /**
  94       * Generate a text box field.
  95       *
  96       * @param string The name of the text box.
  97       * @param string The value of the text box.
  98       * @param array Array of options for the text box (class, style, id)
  99       * @return string The generated text box.
 100       */
 101  	function generate_text_box($name, $value="", $options=array())
 102      {
 103          $input = "<input type=\"text\" name=\"".$name."\" value=\"".htmlspecialchars_uni($value)."\"";
 104          if(isset($options['class']))
 105          {
 106              $input .= " class=\"text_input ".$options['class']."\"";
 107          }
 108          else
 109          {
 110              $input .= " class=\"text_input\"";
 111          }
 112          if(isset($options['style']))
 113          {
 114              $input .= " style=\"".$options['style']."\"";
 115          }
 116          if(isset($options['id']))
 117          {
 118              $input .= " id=\"".$options['id']."\"";
 119          }
 120          $input .= " />";
 121          return $input;
 122      }
 123      
 124      /**
 125       * Generate a password input box.
 126       *
 127       * @param string The name of the password box.
 128       * @param string The value of the password box.
 129       * @param array Array of options for the password box (class, id)
 130       * @return string The generated password input box.
 131       */
 132  	function generate_password_box($name, $value="", $options=array())
 133      {
 134          $input = "<input type=\"password\" name=\"".$name."\" value=\"".htmlspecialchars_uni($value)."\"";
 135          if(isset($options['class']))
 136          {
 137              $input .= " class=\"text_input ".$options['class']."\"";
 138          }
 139          else
 140          {
 141              $input .= " class=\"text_input\"";
 142          }
 143          if(isset($options['id']))
 144          {
 145              $input .= " id=\"".$options['id']."\"";
 146          }
 147          if(isset($options['autocomplete']))
 148          {
 149              $input .= " autocomplete=\"".$options['autocomplete']."\"";
 150          }
 151          $input .= " />";
 152          return $input;
 153      }
 154  
 155      /**
 156       * Generate a file upload field.
 157       *
 158       * @param string The name of the file upload field.
 159       * @param array Array of options for the file upload field (class, id)
 160       * @return string The generated file upload field.
 161       */
 162  	function generate_file_upload_box($name, $options=array())
 163      {
 164          $input = "<input type=\"file\" name=\"".$name."\"";
 165          if(isset($options['class']))
 166          {
 167              $input .= " class=\"text_input ".$options['class']."\"";
 168          }
 169          else
 170          {
 171              $input .= " class=\"text_input\"";
 172          }
 173          if(isset($options['style']))
 174          {
 175              $input .= " style=\"".$options['style']."\"";
 176          }
 177          if(isset($options['id']))
 178          {
 179              $input .= " id=\"".$options['id']."\"";
 180          }
 181          $input .= " />";
 182          return $input;
 183          
 184      }
 185  
 186      /**
 187       * Generate a text area.
 188       *
 189       * @param string The name of of the text area.
 190       * @param string The value of the text area field.
 191       * @param array Array of options for text area (class, id, rows, cols, style, disabled)
 192       * @return string The generated text area field.
 193       */
 194  	function generate_text_area($name, $value="", $options=array())
 195      {
 196          $textarea = "<textarea";
 197          if(!empty($name))
 198          {
 199              $textarea .= " name=\"{$name}\"";
 200          }
 201          if(isset($options['class']))
 202          {
 203              $textarea .= " class=\"{$options['class']}\"";
 204          }
 205          if(isset($options['id']))
 206          {
 207              $textarea .= " id=\"{$options['id']}\"";
 208          }
 209          if(isset($options['style']))
 210          {
 211              $textarea .= " style=\"{$options['style']}\"";
 212          }
 213          if(isset($options['disabled']))
 214          {
 215              $textarea .= " disabled=\"disabled\"";
 216          }
 217          if(!isset($options['rows']))
 218          {
 219              $options['rows'] = 5;
 220          }
 221          if(!isset($options['cols']))
 222          {
 223              $options['cols'] = 45;
 224          }
 225          $textarea .= " rows=\"{$options['rows']}\" cols=\"{$options['cols']}\">";
 226          $textarea .= htmlspecialchars_uni($value);
 227          $textarea .= "</textarea>";
 228          return $textarea;
 229      }
 230  
 231      /**
 232       * Generate a radio button.
 233       *
 234       * @param string The name of the radio button.
 235       * @param string The value of the radio button
 236       * @param string The label of the radio button if there is one.
 237       * @param array Array of options for the radio button (id, class, checked)
 238       * @return string The generated radio button.
 239       */
 240  	function generate_radio_button($name, $value="", $label="", $options=array())
 241      {
 242          $input = "<label";
 243          if(isset($options['id']))
 244          {
 245              $input .= " for=\"{$options['id']}\"";
 246          }
 247          if(isset($options['class']))
 248          {
 249              $input .= " class=\"label_{$options['class']}\"";
 250          }
 251          $input .= "><input type=\"radio\" name=\"{$name}\" value=\"".htmlspecialchars_uni($value)."\"";
 252          if(isset($options['class']))
 253          {
 254              $input .= " class=\"radio_input ".$options['class']."\"";
 255          }
 256          else
 257          {
 258              $input .= " class=\"radio_input\"";
 259          }
 260          if(isset($options['id']))
 261          {
 262              $input .= " id=\"".$options['id']."\"";
 263          }
 264          if(isset($options['checked']) && $options['checked'] != 0)
 265          {
 266              $input .= " checked=\"checked\"";
 267          }
 268          $input .= " />";
 269          if($label != "")
 270          {
 271              $input .= $label;
 272          }
 273          $input .= "</label>";
 274          return $input;
 275      }
 276  
 277      /**
 278       * Generate a checkbox.
 279       *
 280       * @param string The name of the check box.
 281       * @param string The value of the check box.
 282       * @param string The label of the check box if there is one.
 283       * @param array Array of options for the check box (id, class, checked)
 284       * @return string The generated check box.
 285       */
 286  	function generate_check_box($name, $value="", $label="", $options=array())
 287      {
 288          $input = "<label";
 289          if(isset($options['id']))
 290          {
 291              $input .= " for=\"{$options['id']}\"";
 292          }
 293          if(isset($options['class']))
 294          {
 295              $input .= " class=\"label_{$options['class']}\"";
 296          }
 297          $input .= "><input type=\"checkbox\" name=\"{$name}\" value=\"".htmlspecialchars_uni($value)."\"";
 298          if(isset($options['class']))
 299          {
 300              $input .= " class=\"checkbox_input ".$options['class']."\"";
 301          }
 302          else
 303          {
 304              $input .= " class=\"checkbox_input\"";
 305          }
 306          if(isset($options['id']))
 307          {
 308              $input .= " id=\"".$options['id']."\"";
 309          }
 310          if(isset($options['checked']) && ($options['checked'] === true || $options['checked'] == 1))
 311          {
 312              $input .= " checked=\"checked\"";
 313          }
 314          if(isset($options['onclick']))
 315          {
 316              $input .= " onclick=\"{$options['onclick']}\"";
 317          }
 318          $input .= " /> ";
 319          if($label != "")
 320          {
 321              $input .= $label;
 322          }
 323          $input .= "</label>";
 324          return $input;
 325      }
 326      
 327      /**
 328       * Generate a select box.
 329       *
 330       * @param string The name of the select box.
 331       * @param array Array of options in key => val format.
 332       * @param mixed Either a string containing the selected item or an array containing multiple selected items (options['multiple'] must be true)
 333       * @param array Array of options for the select box (multiple, class, id, size)
 334       * @return string The select box.
 335       */
 336  	function generate_select_box($name, $option_list, $selected=array(), $options=array())
 337      {
 338          if(!isset($options['multiple']))
 339          {
 340              $select = "<select name=\"{$name}\"";
 341          }
 342          else
 343          {
 344              $select = "<select name=\"{$name}\" multiple=\"multiple\"";
 345              if(!isset($options['size']))
 346              {
 347                  $options['size'] = count($option_list);
 348              }
 349          }
 350          if(isset($options['class']))
 351          {
 352              $select .= " class=\"{$options['class']}\"";
 353          }
 354          if(isset($options['id']))
 355          {
 356              $select .= " id=\"{$options['id']}\"";
 357          }
 358          if(isset($options['size']))
 359          {
 360              $select .= " size=\"{$options['size']}\"";
 361          }
 362          $select .= ">\n";
 363          foreach($option_list as $value => $option)
 364          {
 365              $select_add = '';
 366              if(!empty($selected) && ((string)$value == (string)$selected || (is_array($selected) && in_array((string)$value, $selected))))
 367              {
 368                  $select_add = " selected=\"selected\"";
 369              }
 370              $select .= "<option value=\"{$value}\"{$select_add}>{$option}</option>\n";
 371          }
 372          $select .= "</select>\n";
 373          return $select;
 374      }
 375      
 376      /**
 377       * Generate a forum selection box.
 378       *
 379       * @param string The name of the selection box.
 380       * @param mixed Array/string of the selected items.
 381       * @param array Array of options (pid, main_option, multiple)
 382       * @param boolean Is this our first iteration of this function?
 383       * @return string The built select box.
 384       */
 385  	function generate_forum_select($name, $selected, $options=array(), $is_first=1)
 386      {
 387          global $fselectcache, $forum_cache, $selectoptions;
 388          
 389          if(!$selectoptions)
 390          {
 391              $selectoptions = '';
 392          }
 393          
 394          if(!isset($options['depth']))
 395          {
 396              $options['depth'] = 0;
 397          }
 398          
 399          $options['depth'] = intval($options['depth']);
 400          
 401          if(!isset($options['pid']))
 402          {
 403              $options['pid'] = 0;
 404          }
 405          
 406          $pid = intval($options['pid']);
 407          
 408          if(!is_array($fselectcache))
 409          {
 410              if(!is_array($forum_cache))
 411              {
 412                  $forum_cache = cache_forums();
 413              }
 414      
 415              foreach($forum_cache as $fid => $forum)
 416              {
 417                  $fselectcache[$forum['pid']][$forum['disporder']][$forum['fid']] = $forum;
 418              }
 419          }
 420          
 421          if($options['main_option'] && $is_first)
 422          {
 423              $select_add = '';
 424              if($selected == -1)
 425              {
 426                  $select_add = " selected=\"selected\""; 
 427              }
 428              
 429              $selectoptions .= "<option value=\"-1\"{$select_add}>{$options['main_option']}</option>\n";
 430          }
 431          
 432          if(isset($fselectcache[$pid]))
 433          {
 434              foreach($fselectcache[$pid] as $main)
 435              {
 436                  foreach($main as $forum)
 437                  {
 438                      if($forum['fid'] != "0" && $forum['linkto'] == '')
 439                      {
 440                          $select_add = '';
 441      
 442                          if(!empty($selected) && ($forum['fid'] == $selected || (is_array($selected) && in_array($forum['fid'], $selected))))
 443                          {
 444                              $select_add = " selected=\"selected\"";
 445                          }
 446                          
 447                          $sep = '';
 448                          if(isset($options['depth']))
 449                          {
 450                              $sep = str_repeat("&nbsp;", $options['depth']);
 451                          }
 452                          
 453                          $style = "";
 454                          if($forum['active'] == 0)
 455                          {
 456                              $style = " style=\"font-style: italic;\"";
 457                          }
 458  
 459                          $selectoptions .= "<option value=\"{$forum['fid']}\"{$style}{$select_add}>".$sep.htmlspecialchars_uni(strip_tags($forum['name']))."</option>\n";
 460      
 461                          if($forum_cache[$forum['fid']])
 462                          {
 463                              $options['depth'] += 5;
 464                              $options['pid'] = $forum['fid'];
 465                              $this->generate_forum_select($forum['fid'], $selected, $options, 0);
 466                              $options['depth'] -= 5;
 467                          }
 468                      }
 469                  }
 470              }
 471          }
 472          
 473          if($is_first == 1)
 474          {
 475              if(!isset($options['multiple']))
 476              {
 477                  $select = "<select name=\"{$name}\"";
 478              }
 479              else
 480              {
 481                  $select = "<select name=\"{$name}\" multiple=\"multiple\"";
 482              }
 483              if(isset($options['class']))
 484              {
 485                  $select .= " class=\"{$options['class']}\"";
 486              }
 487              if(isset($options['id']))
 488              {
 489                  $select .= " id=\"{$options['id']}\"";
 490              }
 491              if(isset($options['size']))
 492              {
 493                  $select .= " size=\"{$options['size']}\"";
 494              }
 495              $select .= ">\n".$selectoptions."</select>\n";
 496              $selectoptions = '';
 497              return $select;
 498          }
 499      }
 500      
 501      /**
 502       * Generate a group selection box.
 503       *
 504       * @param string The name of the selection box.
 505       * @param mixed Array/string of the selected items.
 506       * @param array Array of options (class, id, multiple)
 507       * @return string The built select box.
 508       */
 509  	function generate_group_select($name, $selected=array(), $options=array())
 510      {
 511          global $cache;
 512          
 513          $select = "<select name=\"{$name}\"";
 514          
 515          if(isset($options['multiple']))
 516          {
 517              $select .= " multiple=\"multiple\"";
 518          }
 519          
 520          if(isset($options['class']))
 521          {
 522              $select .= " class=\"{$options['class']}\"";
 523          }
 524          
 525          if(isset($options['id']))
 526          {
 527              $select .= " id=\"{$options['id']}\"";
 528          }
 529          
 530          if(isset($options['size']))
 531          {
 532              $select .= " size=\"{$options['size']}\"";
 533          }
 534          
 535          $select .= ">\n";
 536          
 537          $groups_cache = $cache->read('usergroups');
 538          foreach($groups_cache as $group)
 539          {
 540              $selected_add = "";
 541              if(is_array($selected))
 542              {
 543                  if(in_array($group['gid'], $selected))
 544                  {
 545                      $selected_add = " selected=\"selected\"";
 546                  }
 547              }
 548              
 549              $select .= "<option value=\"{$group['gid']}\"{$selected_add}>".htmlspecialchars_uni(strip_tags($group['title']))."</option>";
 550          }
 551          
 552          $select .= "</select>";
 553          
 554          return $select;
 555      }
 556      
 557      /**
 558       * Generate a submit button.
 559       *
 560       * @param string The value for the submit button.
 561       * @param array Array of options for the submit button (class, id, name, dsiabled, onclick)
 562       * @return string The generated submit button.
 563       */
 564  	function generate_submit_button($value, $options=array())
 565      {
 566          $input = "<input type=\"submit\" value=\"".htmlspecialchars_uni($value)."\"";
 567  
 568          if(isset($options['class']))
 569          {
 570              $input .= " class=\"submit_button ".$options['class']."\"";
 571          }
 572          else
 573          {
 574              $input .= " class=\"submit_button\"";
 575          }
 576          if(isset($options['id']))
 577          {
 578              $input .= " id=\"".$options['id']."\"";
 579          }
 580          if(isset($options['name']))
 581          {
 582              $input .= " name=\"".$options['name']."\"";
 583          }
 584          if(isset($options['disabled']))
 585          {
 586              $input .= " disabled=\"disabled\"";
 587          }
 588          if(isset($options['onclick']))
 589          {
 590              $input .= " onclick=\"".str_replace('"', '\"', $options['onclick'])."\"";
 591          }
 592          $input .= " />";
 593          return $input;
 594      }
 595  
 596      /**
 597       * Generate a reset button.
 598       *
 599       * @param string The value for the reset button.
 600       * @param array Array of options for the reset button (class, id, name)
 601       * @return string The generated reset button.
 602       */
 603  	function generate_reset_button($value, $options=array())
 604      {
 605          $input = "<input type=\"reset\" value=\"".htmlspecialchars_uni($value)."\"";
 606  
 607          if(isset($options['class']))
 608          {
 609              $input .= " class=\"submit_button ".$options['class']."\"";
 610          }
 611          else
 612          {
 613              $input .= " class=\"submit_button\"";
 614          }
 615          if(isset($options['id']))
 616          {
 617              $input .= " id=\"".$options['id']."\"";
 618          }
 619          if(isset($options['name']))
 620          {
 621              $input .= " name=\"".$options['name']."\"";
 622          }
 623          $input .= " />";
 624          return $input;
 625      }
 626  
 627      /**
 628       * Generate a yes/no radio button choice.
 629       *
 630       * @param string The name of the yes/no choice field.
 631       * @param string The value that should be checked.
 632       * @param boolean Using integers for the checkbox?
 633       * @param array Array of options for the yes checkbox (@see generate_radio_button)
 634       * @param array Array of options for the no checkbox (@see generate_radio_button)
 635       * @return string The generated yes/no radio button.
 636       */
 637  	function generate_yes_no_radio($name, $value=1, $int=true, $yes_options=array(), $no_options = array())
 638      {
 639          global $lang;
 640          
 641          // Checked status
 642          if($value == "no" || $value === '0')
 643          {
 644              $no_checked = 1;
 645              $yes_checked = 0;
 646          }
 647          else
 648          {
 649              $yes_checked = 1;
 650              $no_checked = 0;
 651          }
 652          // Element value
 653          if($int == true)
 654          {
 655              $yes_value = 1;
 656              $no_value = 0;
 657          }
 658          else
 659          {
 660              $yes_value = "yes";
 661              $no_value = "no";
 662          }
 663  
 664          if(!isset($yes_options['class']))
 665          {
 666              $yes_options['class'] = '';
 667          }
 668  
 669          if(!isset($no_options['class']))
 670          {
 671              $no_options['class'] = '';
 672          }
 673  
 674          // Set the options straight
 675          $yes_options['class'] = "radio_yes ".$yes_options['class'];
 676          $yes_options['checked'] = $yes_checked;
 677          $no_options['class'] = "radio_no ".$no_options['class'];
 678          $no_options['checked'] = $no_checked;
 679          
 680          $yes = $this->generate_radio_button($name, $yes_value, $lang->yes, $yes_options);
 681          $no = $this->generate_radio_button($name, $no_value, $lang->no, $no_options);
 682          return $yes." ".$no;
 683      }
 684  
 685      /**
 686       * Generate an on/off radio button choice.
 687       *
 688       * @param string The name of the on/off choice field.
 689       * @param string The value that should be checked.
 690       * @param boolean Using integers for the checkbox?
 691       * @param array Array of options for the on checkbox (@see generate_radio_button)
 692       * @param array Array of options for the off checkbox (@see generate_radio_button)
 693       * @return string The generated on/off radio button.
 694       */
 695  	function generate_on_off_radio($name, $value=1, $int=true, $on_options=array(), $off_options = array())
 696      {
 697          global $lang;
 698          
 699          // Checked status
 700          if($value == "off" || (int) $value !== 1)
 701          {
 702              $off_checked = 1;
 703              $on_checked = 0;
 704          }
 705          else
 706          {
 707              $on_checked = 1;
 708              $off_checked = 0;
 709          }
 710          // Element value
 711          if($int == true)
 712          {
 713              $on_value = 1;
 714              $off_value = 0;
 715          }
 716          else
 717          {
 718              $on_value = "on";
 719              $off_value = "off";
 720          }
 721          
 722          // Set the options straight
 723          if(!isset($on_options['class']))
 724          {
 725              $on_options['class'] = '';
 726          }
 727  
 728          if(!isset($off_options['class']))
 729          {
 730              $off_options['class'] = '';
 731          }
 732  
 733          $on_options['class'] = "radio_on ".$on_options['class'];
 734          $on_options['checked'] = $on_checked;
 735          $off_options['class'] = "radio_off ".$off_options['class'];
 736          $off_options['checked'] = $off_checked;
 737          
 738          $on = $this->generate_radio_button($name, $on_value, $lang->on, $on_options);
 739          $off = $this->generate_radio_button($name, $off_value, $lang->off, $off_options);
 740          return $on." ".$off;
 741      }
 742      
 743  	function generate_date_select($name, $day="",$month="",$year="")
 744      {
 745          global $lang;
 746          
 747          $months = array(
 748              1 => $lang->january,
 749              2 => $lang->february,
 750              3 => $lang->march,
 751              4 => $lang->april,
 752              5 => $lang->may,
 753              6 => $lang->june,
 754              7 => $lang->july,
 755              8 => $lang->august,
 756              9 => $lang->september,
 757              10 => $lang->october,
 758              11 => $lang->november,
 759              12 => $lang->december,
 760          );
 761          
 762          // Construct option list for days
 763          $days = array();
 764          for($i = 1; $i <= 31; ++$i)
 765          {
 766              $days[$i] = $i;
 767          }
 768          
 769          if(!$day)
 770          {
 771              $day = date("j", TIME_NOW);
 772          }
 773          
 774          if(!$month)
 775          {
 776              $month = date("n", TIME_NOW);
 777          }
 778          
 779          if(!$year)
 780          {
 781              $year = date("Y", TIME_NOW);
 782          }
 783          
 784          $built = $this->generate_select_box($name.'_day', $days, intval($day), array('id' => $name.'_day'))." &nbsp; ";
 785          $built .= $this->generate_select_box($name.'_month', $months, intval($month), array('id' => $name.'_month'))." &nbsp; ";
 786          $built .= $this->generate_text_box($name.'_year', intval($year), array('id' => $name.'_year', 'style' => 'width: 100px;'));
 787          return $built;
 788      }
 789      
 790      /**
 791       * Output a row of buttons in a wrapped container.
 792       *
 793       * @param array Array of the buttons (html) to output.
 794       * @return string The submit wrapper (optional)
 795       */
 796  	function output_submit_wrapper($buttons)
 797      {
 798          global $plugins;
 799          $buttons = $plugins->run_hooks("admin_form_output_submit_wrapper", $buttons);
 800          $return = "<div class=\"form_button_wrapper\">\n";
 801          foreach($buttons as $button)
 802          {
 803              $return .= $button." \n";
 804          }
 805          $return .= "</div>\n";
 806          if($this->_return == false)
 807          {
 808              echo $return;
 809          }
 810          else
 811          {
 812              return $return;
 813          }
 814      }    
 815  
 816      /**
 817       * Finish up a form.
 818       *
 819       * @return string The ending form tag (optional)
 820       */
 821  	function end()
 822      {
 823          global $plugins;
 824          $plugins->run_hooks("admin_form_end", $this);
 825          if($this->_return == false)
 826          {
 827              echo "</form>";
 828          }
 829          else
 830          {
 831              return "</form>";
 832          }
 833      }
 834  }
 835  
 836  /**
 837   * Generate a form container.
 838   */
 839  class DefaultFormContainer
 840  {
 841      private $_container;
 842      public $_title;
 843  
 844      /**
 845       * Initialise the new form container.
 846       *
 847       * @param string The title of the forum container
 848       * @param string An additional class to apply if we have one.
 849       */
 850  	function __construct($title='', $extra_class='')
 851      {
 852          $this->_container = new Table;
 853          $this->extra_class = $extra_class;
 854          $this->_title = $title;
 855      }
 856  
 857      /**
 858       * Output a header row of the form container.
 859       *
 860       * @param string The header row label.
 861       * @param array TODO
 862       */
 863  	function output_row_header($title, $extra=array())
 864      {
 865          $this->_container->construct_header($title, $extra);
 866      }
 867  
 868      /**
 869       * Output a row of the form container.
 870       *
 871       * @param string The title of the row.
 872       * @param string The description of the row/field.
 873       * @param string The HTML content to show in the row.
 874       * @param string The ID of the control this row should be a label for.
 875       * @param array Array of options for the row cell.
 876       * @param array Array of options for the row container.
 877       */
 878  	function output_row($title, $description="", $content="", $label_for="", $options=array(), $row_options=array())
 879      {
 880          global $plugins;
 881          $pluginargs = array(
 882              'title' => &$title,
 883              'description' => &$description,
 884              'content' => &$content,
 885              'label_for' => &$label_for,
 886              'options' => &$options,
 887              'row_options' => &$row_options,
 888              'this' => &$this
 889          );
 890  
 891          $plugins->run_hooks("admin_formcontainer_output_row", $pluginargs);
 892  
 893          $row = $for = '';
 894          if($label_for != '')
 895          {
 896              $for = " for=\"{$label_for}\"";
 897          }
 898  
 899          if($title)
 900          {
 901              $row = "<label{$for}>{$title}</label>";
 902          }
 903  
 904          if(isset($options['id']))
 905          {
 906              $options['id'] = " id=\"{$options['id']}\"";
 907          }
 908          else
 909          {
 910              $options['id'] = '';
 911          }
 912  
 913          if($description != '')
 914          {
 915              $row .= "\n<div class=\"description\">{$description}</div>\n";
 916          }
 917  
 918          $row .= "<div class=\"form_row\"{$options['id']}>{$content}</div>\n";
 919          $this->_container->construct_cell($row, $options);
 920  
 921          if(!isset($options['skip_construct']))
 922          {
 923              $this->_container->construct_row($row_options);
 924          }
 925      }
 926      
 927      /**
 928       * Output a row cell for a table based form row.
 929       *
 930       * @param string The data to show in the cell.
 931       * @param array Array of options for the cell (optional).
 932       */
 933  	function output_cell($data, $options=array())
 934      {
 935          $this->_container->construct_cell($data, $options);
 936      }
 937      
 938      /**
 939       * Build a row for the table based form row.
 940       *
 941       * @param array Array of extra options for the cell (optional).
 942       */
 943  	function construct_row($extra=array())
 944      {
 945          $this->_container->construct_row($extra);
 946      }
 947      
 948      /**
 949       * return the cells of a row for the table based form row.
 950       *
 951       * @param string The id of the row.
 952       * @param boolean Whether or not to return or echo the resultant contents.
 953       * @return string The output of the row cells (optional).
 954       */
 955  	function output_row_cells($row_id, $return=false)
 956      {
 957          if(!$return)
 958          {
 959              echo $this->_container->output_row_cells($row_id, $return);
 960          }
 961          else
 962          {
 963              return $this->_container->output_row_cells($row_id, $return);
 964          }
 965      }
 966  
 967      /**
 968       * Count the number of rows in the form container. Useful for displaying a 'no rows' message.
 969       *
 970       * @return int The number of rows in the form container.
 971       */
 972  	function num_rows()
 973      {
 974          return $this->_container->num_rows();
 975      }
 976  
 977      /**
 978       * Output the end of the form container row.
 979       *
 980       * @param boolean Whether or not to return or echo the resultant contents.
 981       * @return string The output of the form container (optional).
 982       */
 983  	function end($return=false)
 984      {
 985          global $plugins;
 986          
 987          $hook = array(
 988              'return'    => &$return,
 989              'this'        => &$this
 990          );
 991          
 992          $plugins->run_hooks("admin_formcontainer_end", $hook);
 993          if($return == true)
 994          {
 995              return $this->_container->output($this->_title, 1, "general form_container {$this->extra_class}", true);
 996          }
 997          else
 998          {
 999              echo $this->_container->output($this->_title, 1, "general form_container {$this->extra_class}", false);
1000          }
1001      }
1002  }
1003  
1004  ?>


Generated: Tue Oct 8 19:19:50 2013 Cross-referenced by PHPXref 0.7.1