psf
 All Classes Functions Variables
checkbox.php
1 <?php
2 
3 // Part of simple php framework (spf)
4 
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 
15 // Copyright (c) Petr Bena <petr@bena.rocks> 2015 - 2017
16 
17 if (!defined("PSF_ENTRY_POINT"))
18  die("Not a valid psf entry point");
19 
20 require_once (dirname(__FILE__) . "/element.php");
21 
22 class CheckBox extends HtmlElement
23 {
24  public $Enabled = true;
25  public $Name;
26  public $Value;
27  public $Text = NULL;
28  public $Checked;
29 
30  public function __construct($_name = NULL, $_value = NULL, $_checked = false, $_parent = NULL)
31  {
32  $this->Checked = $_checked;
33  $this->Name = $_name;
34  $this->Value = $_value;
35  parent::__construct($_parent);
36  }
37 
38  public function ToHtml()
39  {
40  $_e = "<input type=\"checkbox\"";
41  if ($this->Name !== NULL)
42  $_e .= " name=\"$this->Name\"";
43  if ($this->Value !== NULL)
44  $_e .= " value=\"$this->Value\"";
45  if ($this->ClassName !== NULL)
46  $_e .= " class=\"" . $this->ClassName . "\"";
47  if ($this->Checked)
48  $_e .= " checked";
49  if (!$this->Enabled)
50  $_e .= " disabled readonly";
51  $_e .= ">";
52  if ($this->Text !== NULL)
53  $_e = "<label>$_e" . $this->Text . "</label>";
54  return $_e;
55  }
56 }