XOOPS RMCommon Utilities  2.1.8.91RC
 All Classes Namespaces Files Functions Variables
checks.class.php
Go to the documentation of this file.
1 <?php
2 // $Id: checks.class.php 825 2011-12-09 00:06:11Z i.bitcero $
3 // --------------------------------------------------------------
4 // Red México Common Utilities
5 // A framework for Red México Modules
6 // Author: Eduardo Cortés <i.bitcero@gmail.com>
7 // Email: i.bitcero@gmail.com
8 // License: GPL 2.0
9 // --------------------------------------------------------------
10 
15 {
16  private $asTable = false;
17  private $tableCols = 3;
18  private $_options = array();
22  function __construct($caption){
23  $this->setCaption($caption);
24  }
32  public function addOption($caption, $name, $value, $state=0){
33  $rtn = array();
34  $rtn['caption'] = $caption;
35  $rtn['value'] = $value;
36  $rtn['state'] = $state;
37  $rtn['name'] = $name;
38  $this->_options[] = $rtn;
39  }
44  public function getOptions(){
45  return $this->_options;
46  }
51  function render(){
52  $rtn = '';
53  if ($this->asTable){
54  $rtn .= "<table width='100%' cellspacing='1' cellpadding='2' border='0'><tr>";
55  $cols = 1;
56  foreach ($this->_options as $k => $v){
57  if ($cols>$this->tableCols){
58  $rtn .= '</tr><tr>';
59  $cols = 1;
60  }
61  $rtn .= "<td><label><input type='checkbox' name='$v[name]' id='".$this->id()."' value='$v[value]' ";
62  //if ($v['state']==1){
63  $rtn .= isset($_REQUEST[$v['name']]) && $_REQUEST[$v['name']]==$v['value'] ? "checked='checked' " : ($v['state']==1 ? "checked='checked' " : '');
64  //}
65  $rtn .= "/> $v[caption]</label></td>";
66  $cols++;
67  }
68  $rtn .= "</tr></table>";
69  } else {
70  foreach ($this->_options as $k => $v){
71  $rtn .= "<input type='checkbox' name='$v[name]' id='".$this->id()."' value='$v[value]' ";
72  //if ($v['state']==1){
73  // $rtn .= "checked='checked' ";
74  //}
75  $rtn .= isset($_REQUEST[$v['name']]) && $_REQUEST[$v['name']]==$v['value'] ? "checked='checked' " : ($v['state']==1 ? "checked='checked' " : '');
76  $rtn .= "/> $v[caption]<br />";
77  }
78  }
79  return $rtn;
80  }
84  function asTable($cols=3){
85  $this->asTable = true;
86  if ($cols<=0) $cols = 3;
87  $this->tableCols = $cols;
88  }
89 }
90 
95 {
96 
97  private $_options = array();
98  private $_break;
99  private $_type = 0;
100  private $_cols = 3;
101 
109  public function __construct($caption, $name, $salto=0, $type = 0, $cols = 3){
110  $this->setCaption($caption);
111  $this->setName($name);
112  $this->_type = $type;
113  $this->_cols = $cols;
114  if ($salto==0){ $this->_break = '<br />'; } else { $this->_break = '&nbsp;&nbsp;'; }
115  }
122  public function addOption($caption, $value, $state = 0, $extra = ''){
123  $rtn = array();
124  $rtn['caption'] = $caption;
125  $rtn['value'] = $value;
126  $rtn['state'] = $state;
127  $rtn['extra'] = $extra;
128  $this->_options[] = $rtn;
129  }
134  public function getOptions(){
135  return $this->_options;
136  }
141  public function render(){
142  $rtn = '';
143 
144  if ($this->_type){
145 
146  $rtn .= "<table cellspacing='1' cellpadding='2' border='0'><tr>";
147  $i = 1;
148  foreach ($this->_options as $k => $v){
149  if ($i>$this->_cols){
150  $i = 1;
151  $rtn .= "</tr><tr>";
152  }
153  $rtn .= "<td><label><input name='".$this->getName()."' id='".$this->id()."' type='radio' value='$v[value]' ";
154  $rtn .= isset($_REQUEST[$this->getName()]) && $_REQUEST[$this->getName()]==$v['value'] ? "checked='checked' " : ($v['state']==1 ? "checked='checked' " : '');
155  $rtn .= ($v['extra']!='' ? "$v[extra] " : '')."/> $v[caption]</label></td>";
156  $i++;
157  }
158  $rtn .= "</tr></table>";
159 
160  } else {
161 
162  foreach ($this->_options as $k => $v){
163  $rtn .= "<label><input name='".$this->getName()."' id='".$this->id()."' type='radio' value='$v[value]' ";
164  $rtn .= isset($_REQUEST[$this->getName()]) && $_REQUEST[$this->getName()]==$v['value'] ? "checked='checked' " : ($v['state']==1 ? "checked='checked' " : '');
165  $rtn .= ($v['extra']!='' ? "$v[extra] " : '')."/> $v[caption]</label>".$this->_break;
166  }
167 
168  }
169  return $rtn;
170  }
171 }
172 
177 {
178  var $_value = '';
184  public function __construct($caption, $name, $inicial=0){
185  $this->setCaption($caption);
186  $this->setName($name);
187  $this->_value = isset($_REQUEST[$this->getName()]) ? $_REQUEST[$this->getName()] : $inicial;
188  }
193  public function setValue($value){
194  $this->_value = $value;
195  }
200  public function getValue(){
201  return $this->_value;
202  }
207  public function render(){
208  $rtn = "<input name='".$this->getName()."' id='".$this->getName()."' type='radio' value='1' ";
209  if ($this->_value==1){
210  $rtn .= "checked='checked' ";
211  }
212  $rtn .= "/> ".__('Yes','rmcommon')."&nbsp;&nbsp;";
213  $rtn .= "<input name='".$this->getName()."' id='".$this->getName()."' type='radio' value='0' ";
214  if ($this->_value==0){
215  $rtn .= "checked='checked' ";
216  }
217  $rtn .= "/> ".__('No','rmcommon');
218  return $rtn;
219  }
220 }