| [ 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 9 /* 10 11 12 13 14 15 QUERY 16 $row[0] = id 17 $row[1] = text 18 $row[2] = others 19 $row[3] = optgroup 20 $row[4] = optgroup_others 21 22 ARRAY 23 $arr_select[ $id ] = 'text ||| others ||| optgroup_text ||| optgroup_others '; 24 25 $ar_select[ $id ] ['text'] = ''; 26 $ar_select[ $id ] ['others'] = ''; 27 $ar_select[ $id ] ['optgroup_text'] = ''; 28 $ar_select[ $id ] ['optgroup_others'] = ''; 29 30 31 $qfdb->m['option_empty'] = ''; // string 32 $qfdb->m['option_emptymsg'] = ''; // string 33 34 35 */ 36 37 38 class qfdbobj_select { 39 // 0.4 40 static function obj_struct(&$qfdb) 41 { 42 $qfdb->m['object'] = 'select'; // string (fixed) 43 $qfdb->m['status'] = '1234'; // string 44 $qfdb->m['if'] = ''; // string 45 $qfdb->m['alias'] = ''; // string 46 47 $qfdb->m['db_field'] = ''; // string 48 $qfdb->m['form_field'] = ''; // string 49 $qfdb->m['size'] = '1'; // int 50 $qfdb->m['multiple'] = 'false'; // bool 51 $qfdb->m['id'] = ''; // bool 52 53 $qfdb->m['option_query'] = 'SELECT * FROM vars WHERE 1 ORDER BY id ASC'; // string 54 $qfdb->m['option_array'] = ''; // string 55 $qfdb->m['option_class'] = $qfdb->get_css_value('qfdb_select_option'); // string 56 $qfdb->m['option_others'] = ''; // string 57 $qfdb->m['option_empty'] = ''; // string 58 $qfdb->m['option_emptymsg'] = ''; // string 59 60 $qfdb->m['nullval_value'] = ''; // string 61 $qfdb->m['nullval_text'] = ''; // string 62 $qfdb->m['nullval_others'] = ''; // string 63 $qfdb->m['nullval_optgroup'] = ''; // string 64 $qfdb->m['nullval_optgroup_others'] = ''; // string 65 66 $qfdb->m['title'] = ''; // string 67 $qfdb->m['disabled'] = 'false'; // bool 68 $qfdb->m['required'] = 'false'; // bool 69 $qfdb->m['value'] = ''; // string 70 $qfdb->m['help'] = ''; // string 71 $qfdb->m['style'] = ''; // string 72 $qfdb->m['class'] = $qfdb->get_css_value('qfdb_select'); // string 73 $qfdb->m['others'] = ''; // string 74 $qfdb->m['ps_start'] = ''; // string 75 $qfdb->m['ps_end'] = ''; // string 76 $qfdb->m['optgroup'] = 'false'; // string 77 $qfdb->m['optgroup_style'] = ''; // string 78 $qfdb->m['optgroup_class'] = $qfdb->get_css_value('qfdb_select_optgroup'); // string 79 $qfdb->m['optgroup_others'] = ''; // string 80 $qfdb->m['label'] = ''; // string 81 $qfdb->m['label_class'] = $qfdb->get_css_value('qfdb_tpl_label'); // string 82 $qfdb->m['label_others'] = ''; // string 83 $qfdb->m['display'] = 'two_cell'; // string 84 $qfdb->m['colspan_class'] = $qfdb->get_css_value('qfdb_tpl_colspan'); // string 85 $qfdb->m['colspan_others'] = ''; // string 86 $qfdb->m['left_class'] = $qfdb->get_css_value('qfdb_tpl_left'); // string 87 $qfdb->m['left_others'] = ''; // string 88 $qfdb->m['right_class'] = $qfdb->get_css_value('qfdb_tpl_right'); // string 89 $qfdb->m['right_others'] = ''; // string 90 $qfdb->m['validate'] = ''; // string 91 92 $qfdb->m['object_properties'] = count($qfdb->m) +2; // int 93 } // end func 94 95 // 0.3 96 static function obj_html(&$qfdb) 97 { 98 $opt = ($qfdb->m['optgroup'] == 'true') ? true : false; 99 100 /////////////////////////////////////////////// 101 // generate elements -> format 102 // $ar_select[ $value ]['text'] 103 // $ar_select[ $value ]['others'] 104 // $ar_select[ $value ]['optgroup'] 105 // $ar_select[ $value ]['optgroup_others'] 106 107 if (strlen($qfdb->m['nullval_value'])) { 108 $ar_select[ $qfdb->m['nullval_value'] ]['text'] = ' '.$qfdb->m['nullval_text']; 109 $ar_select[ $qfdb->m['nullval_value'] ]['others'] = ' '.$qfdb->m['nullval_others']; 110 if ($opt) { 111 $ar_select[ $qfdb->m['nullval_value'] ]['optgroup'] = ' '.$qfdb->m['nullval_optgroup']; 112 $ar_select[ $qfdb->m['nullval_value'] ]['optgroup_others'] = ' '.$qfdb->m['nullval_optgroup_others']; 113 } else { 114 $ar_select[ $qfdb->m['nullval_value'] ]['optgroup'] = ''; 115 $ar_select[ $qfdb->m['nullval_value'] ]['optgroup_others'] = ''; 116 } 117 } 118 119 // query generate select options 120 if ($qfdb->m['option_query']) { 121 if ($result = $qfdb->sql_query($qfdb->m['option_query'])) { 122 $i=0; 123 while ($row = $qfdb->sql_fetchrow($result)) { 124 if (!isset($row[0]) || !isset($row[1]) || isset($row[5])) { 125 $qfdb->add_critical_error( sprintf(QFDBOBJ_SELECT_QUERY_WRONG_RETURN, $qfdb->m['option_query']) ); 126 } 127 $ar_select[ $row[0] ]['text'] = $row[1]; 128 $ar_select[ $row[0] ]['others'] = isset($row[2]) ? $row[2] : ''; 129 if ($opt) { 130 $ar_select[ $row[0] ]['optgroup'] = ' '.(isset($row[3])) ? $row[3] : ''; 131 $ar_select[ $row[0] ]['optgroup_others'] = ' '.(isset($row[4])) ? $row[4] : ''; 132 } else { 133 $ar_select[ $row[0] ]['optgroup'] = ''; 134 $ar_select[ $row[0] ]['optgroup_others'] = ''; 135 } 136 } 137 } else { 138 $qfdb->add_critical_error( sprintf(QFDBOBJ_SELECT_OPTION_QUERY_INVALID, $qfdb->m['option_query']) ); 139 return; 140 } 141 } 142 143 // array generate select elements 144 if ($qfdb->m['option_array']) { 145 $var = $qfdb->m['option_array']; 146 $var = $GLOBALS[ $var ]; 147 148 if (is_array($var)) { 149 foreach ($var as $value => $text) { 150 $text = explode('|||', $text); 151 $select[ $value ]['text'] = $text[0]; 152 $select[ $value ]['others'] = ' '.(isset($text[1])) ? trim($text[1]) : ''; 153 if ($opt) { 154 $select[ $value ]['optgroup'] = ' '.(isset($text[2])) ? trim($text[2]) : ''; 155 $select[ $value ]['optgroup_others'] = ' '.(isset($text[3])) ? trim($text[3]) : ''; 156 } else { 157 $select[ $value ]['optgroup'] = ''; 158 $select[ $value ]['optgroup_others'] = ''; 159 } 160 } 161 } else { 162 $qfdb->add_critical_error( sprintf(QFDBOBJ_SELECT_OPTION_ARRAY_INVALID, $qfdb->m['element_array'], gettype($var) ) ); 163 } 164 } 165 166 167 /////////////////////////////////////////////// 168 // generate input type=select element prototype 169 $array_mark = ($qfdb->m['multiple'] == 'true') ? '[]' : ''; 170 $select = ' <select type="select" name="'.$qfdb->m['form_field'].$array_mark.'" id="'.$qfdb->m['id'].'"'; 171 if ($qfdb->m['class']) { 172 $select .= ' class="'.$qfdb->m['class'].'"'; 173 } 174 if ($qfdb->m['disabled'] == 'true') { 175 $select .= ' disabled="disabled"'; 176 } 177 if ($qfdb->m['class']) { 178 $select .= ' class="'.$qfdb->m['class'].'"'; 179 } 180 if ($qfdb->m['style']) { 181 $select .= ' style="'.$qfdb->m['style'].'"'; 182 } 183 if ($qfdb->m['title']) { 184 $select .= ' title="'.$qfdb->m['title'].'"'; 185 } 186 if ($qfdb->m['others']) { 187 $select .= ' '.$qfdb->m['others']; 188 } 189 if (intval($qfdb->m['size']) > 1) { 190 $select .= ' size="'.$qfdb->m['size'].'"'; 191 } 192 if ($qfdb->m['multiple'] == 'true') { 193 $select .= ' multiple="true"'; 194 } 195 $select .= ">\n"; 196 $sl_select = " </select>\n"; 197 198 199 /////////////////////////////////////////////// 200 // generate optgroup 201 if ($qfdb->m['optgroup'] == 'true') { 202 $optgroup = ' <optgroup'; 203 if ($qfdb->m['optgroup_class']) { 204 $optgroup .= ' class="'.$qfdb->m['optgroup_class'].'"'; 205 } 206 if ($qfdb->m['optgroup_style']) { 207 $optgroup .= ' style="'.$qfdb->m['optgroup_style'].'"'; 208 } 209 if ($qfdb->m['optgroup_others']) { 210 $optgroup .= ' '.$qfdb->m['optgroup_others']; 211 } 212 213 $sl_optgroup = " </optgroup>\n"; 214 $space = ' '; 215 } else { 216 $space = ''; 217 } 218 219 220 /////////////////////////////////////////////// 221 // generate option 222 $option = $space.' <option'; 223 if ($qfdb->m['option_class']) { 224 $option .= ' class="'.$qfdb->m['option_class'].'"'; 225 } 226 if ($qfdb->m['option_others']) { 227 $option .= ' '.$qfdb->m['option_others']; 228 } 229 230 /////////////////////////////////////////////// 231 // generate object 232 233 $object = ''; 234 if ($qfdb->m['ps_start']) { 235 $object .= "\n {$qfdb->m['ps_start']}\n\n"; 236 } 237 238 $object .= $select; 239 240 $opt_val = 'null_qfdb_null_start_null'; 241 foreach ($ar_select as $key => $value) { 242 if ($opt) { 243 if ($opt_val != $value['optgroup']) { 244 if ($opt_val != 'null_qfdb_null_start_null') { 245 $object .= $sl_optgroup; 246 } 247 $object .= $optgroup . ' label="'.$value['optgroup'].'"'; 248 $opt_val = $value['optgroup']; 249 if ($value['optgroup_others']) { 250 $object .= ' '.$value['optgroup_others']; 251 } 252 $object .= ">\n"; 253 } 254 } // end opt 255 256 $object .= $option; 257 if ($value['others']) { 258 $object .= ' '. $value['others']; 259 } 260 261 // verify of object is selected 262 if ($qfdb->m['multiple'] == 'true') { 263 $selected = (eregi("\|\|\|$key\|\|\|", $qfdb->m['value'])) ? ' selected="selected"' : ''; 264 } else { 265 $selected = ($key == $qfdb->m['value'] || "|||$key|||" == $qfdb->m['value']) ? ' selected="selected"' : ''; 266 } 267 268 $object .= "$selected value=\"$key\">{$value['text']}</option>\n"; 269 } 270 271 if ($opt && $opt_val != 'null_qfdb_null_start_null') { 272 $object .= $sl_optgroup; 273 } 274 275 $object .= $sl_select; 276 277 278 if ($qfdb->m['ps_end']) { 279 $object .= "\n {$qfdb->m['ps_end']}\n\n"; 280 } 281 282 283 if ($qfdb->m['display'] == 'object_only') { 284 $qfdb->add_output('html', $object."\n"); 285 } elseif ($qfdb->m['display'] == 'one_cell') { 286 if ($qfdb->m['colspan_class']) { 287 $qfdb->m['colspan_others'] .= ' class="'.$qfdb->m['colspan_class'].'"'; 288 } 289 $label = qfdb_themes::themes_label($qfdb->m); 290 $qfdb->add_output('html', qfdb_themes::themes_container_one_cell( array('content'=>$object, 'others'=>$qfdb->m['colspan_others'], 'class'=>$qfdb->m['colspan_class'], 'label'=>$label) )); 291 } else { // $qfdb->m['display'] == 'two_cell' 292 if ($qfdb->m['left_class']) { 293 $qfdb->m['left_others'] .= ' class="'.$qfdb->m['left_class'].'"'; 294 } 295 if ($qfdb->m['right_class']) { 296 $qfdb->m['right_others'] .= ' class="'.$qfdb->m['right_class'].'"'; 297 } 298 $label = qfdb_themes::themes_label($qfdb->m); 299 $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']) )); 300 } 301 } // end func 302 303 304 // 0.3 305 static function obj_db(&$qfdb) 306 { 307 } // end func 308 309 310 // 0.3 311 static function obj_debug(&$qfdb) 312 { 313 } // end func 314 315 316 // 0.4 317 static function obj_fixed(&$qfdb) 318 { 319 // id 320 if (!$qfdb->m['id']) { 321 $qfdb->m['id'] = $qfdb->m['form_field']; 322 } 323 324 // element_query AND element_array 325 if (!$qfdb->m['option_query'] && !$qfdb->m['option_array']) { 326 $qfdb->add_critical_error(QFDBOBJ_SELECT_QUERYARRAY_NONE); 327 } 328 if ($qfdb->m['option_query'] && $qfdb->m['option_array']) { 329 $qfdb->add_critical_error(QFDBOBJ_SELECT_QUERYARRAY_BOTH); 330 } 331 332 // nullval_text AND nullval_value 333 if ((strlen($qfdb->m['nullval_value']) && !strlen($qfdb->m['nullval_text'])) || 334 (!strlen($qfdb->m['nullval_value']) && strlen($qfdb->m['nullval_text']))) { 335 $qfdb->add_critical_error( sprintf(QFDBOBJ_SELECT_NULLVALL_INCONSISTENT, $qfdb->m['nullval_value'], $qfdb->m['nullval_text']) ); 336 } 337 338 $qfdb->fix_disabled(); 339 $qfdb->fix_required(); 340 $qfdb->fix_display_3(); 341 } // end func 342 343 } // end class
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 |