| [ Index ] |
PHP Cross Reference of Quick Form DataBase |
[Summary view] [Print] [Text view]
1 <?php 2 if (!defined('QFDB_SECURITY')) { 3 die("You can't access this file directly..."); 4 } 5 6 7 /** 8 * Form QFDB Object: Build a Radio Form Field 9 * 10 * @author Everaldo Wanderlei Uavniczak <everaldouav [at] gmail.com> 11 * @since 0.1 12 * @package quickformdb 13 * @see http://www.qfdb.net/ 14 * @license BSD License <http://www.qfdb.net/bsd_license.txt> 15 * @link http://w3schools.com/tags/tag_input.asp 16 * @todo implement reference to error_message 17 * @todo implement support to insert and update values of radio in other table of relational database 18 * @todo implement error_msg if is used both 'element_query' and 'element_array' 19 * @todo redefine (or fix) struct of 'element_query' and 'element_array' 20 * @todo define error message in 'element_emptymsg' (if number of elements is equal a 0) 21 * @todo document all error and warning 22 * @todo define warning message if 'cols'< 1 23 */ 24 25 26 27 28 class qfdbobj_radio { 29 30 static function obj_struct(&$qfdb) 31 { 32 $qfdb->m['object'] = 'radio'; 33 $qfdb->m['status'] = '1234'; 34 $qfdb->m['if'] = ''; 35 $qfdb->m['alias'] = ''; 36 37 $qfdb->m['db_field'] = ''; 38 $qfdb->m['form_field'] = ''; 39 40 $qfdb->m['element_query'] = ''; 41 $qfdb->m['element_array'] = ''; 42 $qfdb->m['element_class'] = $qfdb->get_css_value('qfdb_radio_element'); 43 $qfdb->m['element_others'] = ''; 44 $qfdb->m['element_label_class'] = $qfdb->get_css_value('qfdb_radio_element_label'); 45 $qfdb->m['element_label_others'] = ''; 46 47 $qfdb->m['nullval_value'] = ''; 48 $qfdb->m['nullval_label'] = ''; 49 $qfdb->m['nullval_others_label'] = ''; 50 $qfdb->m['nullval_others_element'] = ''; 51 52 $qfdb->m['cols'] = '3'; 53 $qfdb->m['cols_container_class'] = $qfdb->get_css_value('qfdb_radio_container_cols'); 54 $qfdb->m['cols_container_others'] = ''; 55 $qfdb->m['cols_class'] = $qfdb->get_css_value('qfdb_radio_cols'); 56 $qfdb->m['cols_style'] = ''; 57 $qfdb->m['cols_others'] = ''; 58 $qfdb->m['cols_break'] = '<br />'; 59 60 $qfdb->m['title'] = ''; 61 $qfdb->m['id'] = ''; 62 $qfdb->m['disabled'] = ''; 63 $qfdb->m['required'] = ''; 64 $qfdb->m['value'] = ''; 65 $qfdb->m['help'] = ''; 66 $qfdb->m['beggin'] = ''; 67 $qfdb->m['end'] = ''; 68 69 $qfdb->m['display'] = 'two_cell'; 70 71 $qfdb->m['label'] = ''; 72 $qfdb->m['label_class'] = $qfdb->get_css_value('qfdb_tpl_label'); 73 $qfdb->m['label_others'] = ''; 74 75 $qfdb->m['colspan_class'] = $qfdb->get_css_value('qfdb_tpl_colspan'); 76 $qfdb->m['colspan_others'] = ''; 77 $qfdb->m['left_class'] = $qfdb->get_css_value('qfdb_tpl_left'); 78 $qfdb->m['left_others'] = ''; 79 $qfdb->m['right_class'] = $qfdb->get_css_value('qfdb_tpl_right'); 80 $qfdb->m['right_others'] = ''; 81 $qfdb->m['validate'] = ''; 82 83 $qfdb->m['object_properties'] = count($qfdb->m) +2; 84 } // end func 85 86 87 static function obj_html(&$qfdb) 88 { 89 /////////////////////////////////////////////// 90 // generate elements -> format 91 // $radio[ $value ]['label'] 92 // $radio[ $value ]['others_element'] 93 // $radio[ $value ]['others_label'] 94 95 if (strlen($qfdb->m['nullval_value'])) { 96 $radio[ $qfdb->m['nullval_value'] ]['label'] = $qfdb->m['nullval_label']; 97 $radio[ $qfdb->m['nullval_value'] ]['others_element'] = $qfdb->m['nullval_others_element']; 98 $radio[ $qfdb->m['nullval_value'] ]['others_label'] = $qfdb->m['nullval_others_label']; 99 } 100 101 // query generate radio elements 102 if ($qfdb->m['element_query']) { 103 if ($result = $qfdb->sql_query($qfdb->m['element_query'])) { 104 if ($qfdb->sql_numrows() < 1) { 105 # @todo generate error message 106 die('A query não retornou nenhum resultado.'); 107 } 108 while ($row = $qfdb->sql_fetchrow($result)) { 109 if (!isset($row[0]) || !isset($row[1]) || isset($row[4])) { 110 $qfdb->add_critical_error( sprintf(QFDBOBJ_RADIO_QUERY_WRONG_RETURN, $qfdb->m['element_query']) ); 111 } 112 $radio[ $row[0] ]['label'] = (isset($row[1])) ? ' '.$row[1] : ''; 113 $radio[ $row[0] ]['others_element'] = (isset($row[2])) ? ' '.$row[2] : ''; 114 $radio[ $row[0] ]['others_label'] = (isset($row[3])) ? ' '.$row[3] : ''; 115 } 116 117 } else { 118 $qfdb->add_critical_error( sprintf(QFDBOBJ_RADIO_ELEMENT_QUERY_INVALID, $qfdb->m['element_query']) ); 119 return false; 120 } 121 } elseif ($qfdb->m['element_array']) { // array generate radio elements 122 $var = $qfdb->m['element_array']; 123 124 if (!isset($GLOBALS[ $var ])) { 125 # @todo generate error message 126 die('Var '.$var.' não existe para gerar o radio.'); 127 } 128 129 if (!is_array($GLOBALS[ $var ])) { 130 # @todo generate error message 131 die('Var '.$var.' não é um array - para gerar o radio.'); 132 } 133 134 $var = $GLOBALS[ $var ]; 135 136 if (is_array($var)) { 137 foreach ($var as $value => $label) { 138 $label = explode('|||', $label); 139 $radio[ $value ]['label'] = $label[0]; 140 $radio[ $value ]['others_element'] = (isset($label[1])) ? ' '.trim($label[1]) : ''; 141 $radio[ $value ]['others_label'] = (isset($label[2])) ? ' '.trim($label[2]) : ''; 142 } 143 } else { 144 $qfdb->add_critical_error( sprintf(QFDBOBJ_RADIO_ELEMENT_ARRAY_INVALID, $qfdb->m['element_array'], gettype($var) ) ); 145 } 146 } else { 147 # @todo generate error message 148 die('defina uma query ou um array para o campo radio'); 149 } 150 151 152 /////////////////////////////////////////////// 153 // generate input type=radio element prototype 154 $radio_element = '<input type="radio" '; 155 if ($qfdb->m['form_field']) { 156 $radio_element .= 'name="'.$qfdb->m['form_field'].'[]"'; 157 } 158 if ($qfdb->m['disabled'] == 'true') { 159 $radio_element .= ' disabled="disabled"'; 160 } 161 if ($qfdb->m['element_class']) { 162 $radio_element .= ' class="'.$qfdb->m['element_class'].'"'; 163 } 164 if ($qfdb->m['element_others']) { 165 $radio_element .= ' '.$qfdb->m['element_others']; 166 } 167 168 /////////////////////////////////////////////// 169 // generate label of input type=radio element prototype 170 $radio_label = '<label'; 171 if ($qfdb->m['element_label_class']) { 172 $radio_label .= ' class="'.$qfdb->m['element_label_class'].'"'; 173 } 174 if ($qfdb->m['element_label_others']) { 175 $radio_label .= ' '.$qfdb->m['element_label_others']; 176 } 177 178 /////////////////////////////////////////////// 179 // generate container (TD) to all input type=radio element prototype 180 $radio_table = $radio_sltable = $radio_td = $radio_sltd = $radio_tr = $radio_sltr = ''; 181 if ($qfdb->m['cols'] > 1) { 182 $radio_table .= $qfdb->i(3)."<table width=\"100%\""; 183 if ($qfdb->m['cols_container_class']) { 184 $radio_table .= ' class="'.$qfdb->m['cols_container_class'].'"'; 185 } 186 if ($qfdb->m['cols_container_others']) { 187 $radio_table .= ' '.$qfdb->m['cols_container_others']; 188 } 189 if ($qfdb->m['title']) { 190 $radio_table .= ' title="'.$qfdb->m['title'].'"'; 191 } 192 $radio_table .=">\n"; 193 194 $radio_sltable .= $qfdb->i(3)."</table>"; 195 196 $radio_tr .= $qfdb->i(3)."<tr>\n"; 197 $radio_sltr .= $qfdb->i(3)."</tr>\n"; 198 199 $td_size = floor(100/$qfdb->m['cols']); 200 $radio_td .= $qfdb->i(4).'<td width="'.$td_size.'%"'; 201 if ($qfdb->m['cols_class']) { 202 $radio_td .= ' class="'.$qfdb->m['cols_class'].'"'; 203 } 204 if ($qfdb->m['cols_style']) { 205 $radio_td .= ' style="'.$qfdb->m['cols_style'].'"'; 206 } 207 if ($qfdb->m['cols_others']) { 208 $radio_td .= ' '.$qfdb->m['cols_others']; 209 } 210 $radio_td .= ">\n"; 211 $radio_sltd = $qfdb->i(4)."</td>\n"; 212 213 } else { 214 if ($qfdb->m['title']) { 215 $radio_table = $qfdb->i(3).'<div title="'.$qfdb->m['title'].'">'."\n"; 216 $radio_sltable = $qfdb->i(3).'</div>'; 217 } 218 } 219 220 /////////////////////////////////////////////// 221 // generate label of input type=radio element prototype 222 $elements_in_cols = ceil( count($radio)/$qfdb->m['cols'] ); 223 224 $object = "\n"; 225 226 if ($qfdb->m['beggin']) { 227 $object .= $qfdb->i(2)."{$qfdb->m['beggin']}\n\n"; 228 } 229 230 231 $object .= $radio_table . $radio_tr; 232 233 234 $j = $i = 0; 235 foreach ($radio as $key => $value) { 236 if (!$j) { 237 $object .= $radio_td; 238 } 239 $j++; $i++; 240 $key = $key; 241 $qfdb->m['value'] = ' '.$qfdb->m['value'].' '; 242 $radio_checked = ($key == $qfdb->m['value']) ? ' checked="checked"': ''; 243 $object .= $qfdb->i(5)."$radio_element id=\"{$qfdb->m['id']}_{$key}\"{$value['others_element']} value=\"$key\" {$radio_checked} /> $radio_label for=\"{$qfdb->m['id']}_{$key}\" {$value['others_label']}>{$value['label']}</label>{$qfdb->m['cols_break']}\n"; 244 245 if ($j == $elements_in_cols) { 246 $object .= $radio_sltd; 247 $j = 0; 248 $next_sltd = ''; 249 continue; 250 } else { 251 $next_sltd = $radio_sltd; 252 } 253 } 254 $object .= $next_sltd . $radio_sltr . $radio_sltable; 255 256 if ($qfdb->m['end']) { 257 $object .= "\n\n".$qfdb->i(2)."{$qfdb->m['end']}"; 258 } 259 $object .= "\n"; 260 261 262 if ($qfdb->m['display'] == 'object_only') { 263 $qfdb->add_output('html', $object."\n"); 264 } elseif ($qfdb->m['display'] == 'one_cell') { 265 $label = qfdb_themes::themes_label($qfdb->m); 266 $qfdb->add_output('html', qfdb_themes::themes_container_one_cell( array('content'=>$object, 'others'=>$qfdb->m['colspan_others'], 'class'=>$qfdb->m['colspan_class'], $label) )); 267 } else { // $qfdb->m['display'] == 'two_cell' 268 $label = qfdb_themes::themes_label($qfdb->m); 269 $qfdb->add_output('html', qfdb_themes::themes_container_two_cells( array('label'=>$label, 'content'=>$object, 'label_others'=>$qfdb->m['left_others'], 'content_others'=>$qfdb->m['right_others'], 'label_class'=>$qfdb->m['left_class'], 'content_class'=>$qfdb->m['right_class']) )); 270 } 271 } // end func 272 273 274 static function obj_db(&$qfdb) 275 { 276 } // end func 277 278 279 static function obj_debug(&$qfdb) 280 { 281 } // end func 282 283 284 static function obj_fixed(&$qfdb) 285 { 286 // element_query AND element_array 287 if (!$qfdb->m['element_query'] && !$qfdb->m['element_array']) { 288 $qfdb->add_critical_error(QFDBOBJ_RADIO_QUERYARRAY_NONE); 289 } 290 if ($qfdb->m['element_query'] && $qfdb->m['element_array']) { 291 $qfdb->add_critical_error(QFDBOBJ_RADIO_QUERYARRAY_BOTH); 292 } 293 294 // nullval_label AND nullval_value 295 if ((strlen($qfdb->m['nullval_value']) && !strlen($qfdb->m['nullval_label'])) || 296 (!strlen($qfdb->m['nullval_value']) && strlen($qfdb->m['nullval_label']))) { 297 $qfdb->add_critical_error( sprintf(QFDBOBJ_RADIO_NULLVALL_INCONSISTENT, $qfdb->m['nullval_value'], $qfdb->m['nullval_label']) ); 298 } 299 300 $qfdb->fix_radiocheck_cols(); 301 $qfdb->fix_disabled(); 302 $qfdb->fix_required(); 303 $qfdb->fix_display_3(); 304 305 // cols 306 $qfdb->m['cols'] = intval($qfdb->m['cols']); 307 if ($qfdb->m['cols']<1) { 308 $qfdb->m['cols'] = 1; 309 } 310 311 if (!$qfdb->m['id']) { 312 if ($qfdb->m['form_field']) { 313 $qfdb->m['id'] = $qfdb->m['form_field']; 314 } else { 315 $qfdb->m['id'] = 'q'.substr( md5(microtime()), 0, 10); 316 } 317 } 318 $qfdb->m['id'] = eregi_replace('[^a-zA-Z0-9_-]', '_', $qfdb->m['id']); 319 } // end func 320 321 } // end class 322
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Fri Nov 14 17:48:13 2008 | Cross-referenced by PHPXref 0.7 |