| [ Index ] |
PHP Cross Reference of Quick Form DataBase |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Main File of Quick Form DataBase (QFDB) Framework 4 * 5 * @author Everaldo Wanderlei Uavniczak <everaldouav [at] gmail.com> 6 * @version 0.5 7 * @package quickformdb 8 * @see http://www.qfdb.net/ 9 * @license BSD License <http://www.qfdb.net/bsd_license.txt> 10 * @todo implement restriction methods 11 * @todo implement load_header(), load_footer() and load_body() methods 12 * @todo implement 'if' (QFDB properties of QFDB Object) 13 */ 14 15 16 if (!defined('QFDB_SECURITY')) { 17 define('QFDB_SECURITY', true); 18 } 19 20 21 22 /** 23 * Include file to initialize and prepare quickformdb state 24 */ 25 require_once(dirname(__FILE__) . '/quickformdb_init.php'); 26 27 28 class quickformdb extends qfdb_db { 29 // #################################### 30 // #################################### 31 // #################################### 32 // #################################### 33 // PROPERTIES 34 35 // flags 36 private $ok; 37 private $status; 38 protected $db; 39 public $error; 40 private $css; 41 private $debug; 42 private $debug_msg; 43 private $js; 44 private $parsed; 45 private $dtd; 46 private $charset; 47 private $indent; 48 private $step; 49 50 // parser 51 private $cache; // PHA 52 private $matrix_header; 53 private $matrix_footer; 54 private $matrix_body; 55 public $m; 56 private $matrix_line; 57 private $matrix_content; 58 private $matrix_object; 59 public $matrix_validate; 60 private $vars; 61 private $restriction; 62 63 // core 64 private $db_alias; 65 private $dbval_rescue; 66 private $postval_rescue; 67 68 // output 69 private $output; 70 private $pagetitle; 71 private $message; 72 73 74 // #################################### 75 // #################################### 76 // #################################### 77 // #################################### 78 // CONSTRUCT 79 80 81 /** 82 * Constructor Method of QFDB 83 * 84 * @since: 0.5 85 * @param: void 86 * @return: void 87 * @access: public 88 */ 89 public function __construct() { 90 // flags 91 $this->ok = true; 92 $this->status = 0; 93 $this->init_db(); 94 $this->init_error(); 95 $this->set_css(true); 96 $this->js = true; 97 $this->debug = false; 98 $this->parsed = false; 99 //$this->nicetitle = false; 100 $this->dtd = 'xhtml_transitional'; 101 $this->charset = 'utf-8'; 102 $this->indent = ' '; 103 $this->step = 'beggin'; 104 105 // parsed 106 $this->matrix = array(); 107 $this->matrix_line = -1; 108 $this->matrix_object = ''; 109 $this->matrix_content = ''; 110 $this->matrix_validate = array(); 111 $this->m = ''; 112 $this->init_header_footer(); 113 114 // verify properties 115 $this->var_verify = array(); 116 $this->init_restriction(); 117 118 // core 119 $this->db_alias = array(); 120 $this->dbval_rescue = array(); 121 $this->postval_rescue = array(); 122 123 124 // output 125 $this->init_cache(); 126 $this->init_output(); 127 $this->pagetitle = ''; 128 $this->init_message(); 129 $this->init_debug_msg(); 130 131 132 // define the main constants 133 define('QFDB_OBJECT_PATH', dirname(__FILE__) . '/objects/'); 134 define('QFDB_RULES_PATH', dirname(__FILE__) . '/rules/'); 135 define('QFDB_LANG_PATH', dirname(__FILE__) . '/lang/'); 136 137 // if quickformdb init function exists, load the defined configuration 138 if (function_exists('qfdb_load_configs')) { 139 qfdb_load_configs($this); 140 } 141 } // end __construct() 142 143 144 145 /** 146 * Destructor Method of QFDB 147 * 148 * @since: 0.5 149 * @param: void 150 * @return: void 151 * @access: private 152 * @see: quickformdb::debug_msg 153 * @see: quickformdb::set_debug_msg() 154 * @see: quickformdb::debug_msg_make_content() 155 */ 156 public function __destruct() 157 { 158 if (($this->error['warning_flag'] && $this->debug_msg['warning']) || $this->error['critical_flag']) { 159 if ($this->debug_msg['type'] === 'no_msg' || $this->debug_msg['type'] === 'screen') { 160 return; 161 } 162 163 $d['datetime'] = @date('Y/m/d h:i:s'); 164 $d['remote_addr'] = $_SERVER['REMOTE_ADDR']; 165 $d['request_uri'] = $_SERVER['REQUEST_URI']; 166 $d['filename'] = $_SERVER['SCRIPT_FILENAME']; 167 168 // if saved in file 169 if ($this->debug_msg['type'] == 'file') { 170 // save $content in file 171 $put_file = @file_put_contents($this->debug_msg['aux'], $this->debug_msg_make_content($d), FILE_APPEND); 172 if (!$put_file && $this->debug_msg['mail']) { 173 @mail($this->debug_msg['mail'], $this->message['error_msg_mail_subject'], $this->debug_msg_make_content($d)); 174 } 175 // if save in DB 176 } elseif ($this->debug_msg['type'] == 'db') { 177 // if database don't has connected 178 if (!$this->db['connect_id'] && $this->debug_msg['mail']) { 179 @mail($this->debug_msg['mail'], $this->message['error_msg_mail_subject'], $this->debug_msg_make_content($d)); 180 return; 181 } 182 $d['get_var'] = serialize($_GET); 183 $d['post_var'] = serialize($_POST); 184 $d['cookie_var'] = serialize($_COOKIE); 185 $d['session_var'] = serialize($_SESSION); 186 $d['global_var'] = ($this->debug_msg['include_globals']) ? serialize($GLOBALS) : ''; 187 $d['qfdb_object'] = ($this->debug_msg['include_qfdb']) ? serialize($this) : ''; 188 $d['qfdb_error'] = serialize($this->error); 189 //$d['php_error'] = serialize(); 190 191 $field = $data = ''; 192 foreach ($d as $key => $value) { 193 if ($field) { 194 $field .= ', '; 195 $data .= ', '; 196 } 197 $field .= "`$key`"; 198 $data .= "'".$this->sql_scape_string($value, false)."'"; 199 } 200 201 $this->sql_query("INSERT INTO {$this->debug_msg['aux']} ($field) VALUES($data)"); 202 } 203 } 204 // close DB connection 205 $this->sql_close(); 206 } // end __destruct() 207 208 209 210 // #################################### 211 // #################################### 212 // #################################### 213 // #################################### 214 // INIT 215 216 217 /** 218 * Initialize quickformdb::cache 219 * 220 * @since: 0.5 221 * @return: void 222 * @param: void 223 * @access: private 224 * @see: quickformdb::cache 225 * @see: quickformdb::set_cache() 226 */ 227 private function init_cache() 228 { 229 $this->cache['active'] = false; 230 $this->cache['db_table'] = ''; 231 $this->cache['file_updated'] = 0; 232 $this->cache['init_file_updated'] = 0; 233 $this->cache['filename'] = ''; 234 $this->cache['init_filename'] = ''; 235 } // end init_cache() 236 237 238 /** 239 * Generate message to put in file or send mail to make debug_message 240 * 241 * @since: 0.5 242 * @param: array of string $d Array with messages 243 * @return: void 244 * @access: private 245 * @see: quickformdb::debug_msg 246 * @see: quickformdb::__destruct() 247 * @see: quickformdb::set_debug_msg() 248 */ 249 private function debug_msg_make_content(&$d) 250 { 251 $d['get_vars'] = ''; 252 foreach ($_GET as $key => $value) { 253 $d['get_vars'] .= "[$key]=>$value "; 254 } 255 256 $d['post_vars'] = ''; 257 foreach ($_POST as $key => $value) { 258 $d['post_vars'] .= "[$key]=>$value "; 259 } 260 261 $d['cookie_vars'] = ''; 262 foreach ($_COOKIE as $key => $value) { 263 $d['cookie_vars'] .= "[$key]=>$value "; 264 } 265 266 $d['session_vars'] = ''; 267 foreach ($_SESSION as $key => $value) { 268 $d['session_vars'] .= "[$key]=>$value "; 269 } 270 $d['qfdb_errors'] = ''; 271 if ($this->debug_msg['warning']) { 272 $d['qfdb_errors'] .= "WARNING: \n"; 273 foreach ($this->error['warning_msg'] as $key => $value) { 274 $d['qfdb_errors'] .= " [$key]=>$value\n"; 275 } 276 } 277 $d['qfdb_errors'] .= "CRITICAL_ERROR: \n"; 278 foreach ($this->error['critical_msg'] as $key => $value) { 279 $d['qfdb_errors'] .= " [$key]=>$value\n"; 280 } 281 282 return "================\nDate: {$d['datetime']}\nIP: {$d['remote_addr']}\n". 283 "URL: {$d['request_uri']}\nFilename: {$d['filename']}\n\$_GET: {$d['get_vars']}\n\$_POST: {$d['post_vars']}\n". 284 "\$_COOKIE: {$d['cookie_vars']}\n\$_SESSION: {$d['session_vars']}\n". 285 "\nERROR:\n{$d['qfdb_errors']}================\n\n\n\n\n"; 286 } // end debug_msg_make_content() 287 288 289 290 /** 291 * Initialize quickformdb::output 292 * 293 * @since: 0.5 294 * @param: void 295 * @return: void 296 * @access: private 297 * @see: quickformdb::debug_msg 298 * @see: quickformdb::set_debug_msg() 299 */ 300 private function init_debug_msg() 301 { 302 $this->debug_msg['type'] = 'screen'; 303 $this->debug_msg['warning'] = true; 304 $this->debug_msg['aux'] = ''; 305 $this->debug_msg['include_qfdb'] = false; 306 $this->debug_msg['include_globals'] = false; 307 $this->debug_msg['mail'] = ''; 308 } // end init_debug_msg() 309 310 311 312 /** 313 * Initialize quickformdb::output 314 * 315 * @since: 0.5 316 * @param: void 317 * @return: void 318 * @access: private 319 * @see: quickformdb::output 320 */ 321 private function init_output() 322 { 323 $this->output['html_header'] = ''; 324 $this->output['html_header_ok'] = false; 325 $this->output['html_footer'] = ''; 326 $this->output['html_footer_ok'] = false; 327 $this->output['html_body'] = ''; 328 $this->output['html_user_error'] = ''; 329 $this->output['html_user_message'] = ''; 330 $this->output['html_type'] = 'body'; 331 $this->output['js'] = ''; 332 $this->output['jsall'] = ''; 333 $this->output['jsfunc'] = ''; 334 $this->output['jsonload'] = ''; 335 $this->output['jsprinted'] = false; 336 } // end init_output() 337 338 339 340 /** 341 * Initialize quickformdb::db 342 * 343 * @since: 0.5 344 * @param: void 345 * @return: void 346 * @access: private 347 * @see: quickformdb::db 348 */ 349 private function init_db() 350 { 351 $this->db['connected'] = false; 352 $this->db['host'] = ''; 353 $this->db['user'] = ''; 354 $this->db['pass'] = ''; 355 $this->db['db'] = ''; 356 $this->db['persistency'] = false; 357 $this->db['table'] = ''; 358 $this->db['primary_key'] = ''; 359 $this->db['id'] = ''; 360 $this->db['connect_id'] = false; 361 $this->db['query_result'] = false; 362 $this->db['last_insert_id'] = 0; 363 } // end init_db() 364 365 366 367 /** 368 * Initialize quickformdb::error 369 * 370 * @since: 0.5 371 * @param: void 372 * @return: void 373 * @access: private 374 * @see: quickformdb::error 375 */ 376 private function init_error() 377 { 378 $this->error['user_msg'] = array(); 379 $this->error['warning_msg'] = array(); 380 $this->error['critical_msg'] = array(); 381 $this->error['user_flag'] = false; 382 $this->error['critical_flag'] = false; 383 $this->error['warning_flag'] = false; 384 $this->error['abort_on_warning'] = false; 385 } // end init_error() 386 387 388 389 /** 390 * Initialize quickformdb::message 391 * 392 * @since: 0.5 393 * @param: void 394 * @return: void 395 * @access: private 396 * @see: quickformdb::message 397 */ 398 private function init_message() 399 { 400 $this->message['js_alert_title'] = QFDBM_JS_ALERT_TITLE; 401 $this->message['js_alert_content'] = QFDBM_JS_ALERT_CONTENT; 402 403 $this->message['generic_error'] = QFDBM_GENERIC_ERROR; 404 $this->message['js_user_error'] = QFDBM_MESSAGE_JS_USER_ERROR; 405 $this->message['db_insert_sucess'] = QFDBM_MESSAGE_DB_INSERT_SUCESS; 406 $this->message['db_insert_error'] = QFDBM_MESSAGE_DB_INSERT_ERROR; 407 $this->message['db_update_sucess'] = QFDBM_MESSAGE_DB_UPDATE_SUCESS; 408 $this->message['error_msg_mail_subject'] = QFDBM_MESSAGE_DEBUG_MSG_MAIL_SUBJECT; 409 410 $this->message['db_update_error'] = QFDBM_MESSAGE_DB_UPDATE_ERROR; 411 $this->message['display_error_header'] = '<html><head><title>__TITLE__</title>'. 412 '<style>*{font-face: verdana, sans-serif; font-size: 10pt;} '. 413 'body {padding: 30px; text-align: left;}'. 414 'div.qfdb_messagebox_message_error{margin: 15px; 0}'. 415 '.qfdb_messagebox_title_error { background-color: white; border: 1px solid #ccc; padding: 10px;'. 416 'margin: 10px auto; color: #306; font-weight: bolder; text-align: center; width: 90%; }'. 417 '.qfdb_messagebox_message_error { background-color: #ccc; border: 1px solid #999; '. 418 'padding: 0 10px 10px; margin: 10px auto; color: #306; text-align: left; width: 500px; font-weight: normal;}'. 419 '.qfdb_messagebox_message_error li {list-style: none; background-color: #ccc; }'. 420 '</style></head><body>'; 421 $this->message['display_error_footer'] = '</body></html>'; 422 } // end init_message() 423 424 425 426 /** 427 * Initialize quickformdb::restriction 428 * 429 * @since: 0.5 430 * @param: void 431 * @return: void 432 * @access: private 433 * @see: quickformdb::restriction 434 */ 435 private function init_restriction() 436 { 437 for ($i=1; $i<=8; $i++) { 438 $this->restriction[$i]['before'] = array('function' => '', 'arg' => '', 'message' => ''); 439 $this->restriction[$i]['after'] = array('function' => '', 'arg' => '', 'message' => ''); 440 } 441 } // end init_restriction() 442 443 444 445 /** 446 * Initialize quickformdb::matrix_[header | body | footer] 447 * 448 * @since: 0.5 449 * @param: void 450 * @return: void 451 * @access: private 452 * @see: quickformdb::message 453 */ 454 private function init_header_footer() 455 { 456 $this->matrix_header['no_parsed'] = array(); 457 $this->matrix_header['parsed'] = array(); 458 $this->matrix_header['print'] = true; 459 $this->matrix_body['no_parsed'] = array(); 460 $this->matrix_body['parsed'] = array(); 461 $this->matrix_footer['no_parsed'] = array(); 462 $this->matrix_footer['parsed'] = array(); 463 $this->matrix_footer['print'] = true; 464 } // end init_header_footer() 465 466 467 468 469 // #################################### 470 // #################################### 471 // #################################### 472 // #################################### 473 // FLAGS 474 475 /** 476 * Configure cache parameters 477 * 478 * @since: 0.5 479 * @param: bool $active Active cache 480 * @param: string $db_table DataBase table to chache 481 * @param: string $filename Index filename 482 * @param: string $init_filename Init filename 483 * @return: void 484 * @access: private 485 * @see: quickformdb::cache 486 * @see: quickformdb::init_cache() 487 */ 488 public function set_cache($active = false, $db_table = 'qfdb_cache', $filename='./index.php', $init_filename = './main_qfdb_init.php') 489 { 490 if (!$this->sql_is_connected(__METHOD__)) { 491 return; 492 } 493 494 if (is_bool($active)) { 495 $this->cache['active'] = $active; 496 } else { 497 $this->add_critical_error(QFDBE_FLAGS_BAD_CACHE_ACTIVE.$this->make_error_ref('QFDBE_FLAGS_BAD_CACHE_ACTIVE')); 498 return; 499 } 500 501 if ($active) { 502 $db_table = $this->qfdb_varname($db_table); 503 $filename = trim($filename); 504 $init_filename = trim($init_filename); 505 506 if ($this->debug) { 507 if (!$this->sql_table_exists($db_table)) { 508 $this->add_critical_error( sprintf(QFDBE_FLAGS_BAD_CACHE_DB_TABLE, $db_table ).$this->make_error_ref('QFDBE_FLAGS_BAD_CACHE_DB_TABLE')); 509 return; 510 } 511 512 // verify if all fields exists in db table 513 $fields_error = false; 514 $fields = $this->sql_get_fields($db_table); 515 $table_fields = array('area', 'updated', 'data'); 516 if (count($fields) != count($table_fields)) { 517 $fields_error = true; 518 } else { 519 foreach ($table_fields as $key => $value) { 520 if ($fields[$key] !== $value) { 521 $fields_error = true; 522 break; 523 } 524 } 525 } 526 if ($fields_error) { 527 $this->add_critical_error( sprintf(QFDBE_FLAGS_BAD_CACHE_DBFIELDS.$this->make_error_ref('QFDBE_FLAGS_BAD_CACHE_DBFIELDS'), $db_table, 528 implode(', ', $table_fields), implode(', ', $fields)) ); 529 } 530 } 531 532 // verify if file exists and try to get update date 533 if ($filename && file_exists($filename)) { 534 $this->cache['file_updated'] = @date ("YmdHis", filemtime($filename)); 535 clearstatcache(); 536 } else { 537 $this->add_critical_error( sprintf(QFDBE_FLAGS_CACHE_FILE_DONT_EXISTS.$this->make_error_ref('QFDBE_FLAGS_CACHE_FILE_DONT_EXISTS'), $filename) ); 538 } 539 540 // verify if file exists and try to get update date 541 if ($init_filename && file_exists($init_filename)) { 542 $this->cache['init_file_updated'] = @date ("YmdHis", filemtime($init_filename)); 543 clearstatcache(); 544 } else { 545 $this->add_critical_error( sprintf(QFDBE_FLAGS_CACHE_FILE_DONT_EXISTS.$this->make_error_ref('QFDBE_FLAGS_CACHE_FILE_DONT_EXISTS'), $init_filename) ); 546 } 547 } 548 549 $this->cache['db_table'] = $db_table; 550 $this->cache['filename'] = $filename; 551 $this->cache['init_filename'] = $init_filename; 552 553 } // end func 554 555 556 557 /** 558 * Return quickformdb::ok 559 * 560 * @since: 0.5 561 * @param: void 562 * @return: bool 563 * @access: private 564 * @see: quickformdb::ok 565 */ 566 public function get_ok() 567 { 568 return $this->ok; 569 } // end get_ok() 570 571 572 573 /** 574 * Set quickformdb::status 575 * 576 * @since: 0.4 577 * @param: int $status Status that QFDB will be run 578 * @return: void 579 * @access: private 580 * @see: quickformdb::status 581 * @see: quickformdb::get_ok() 582 */ 583 private function set_status($status) 584 { 585 $status = intval($status); 586 587 if ($status < 1 || $status > 9) { 588 $this->add_critical_error( sprintf(QFDBE_FLAGS_BAD_STATUS.$this->make_error_ref('QFDBE_FLAGS_BAD_STATUS')) ); 589 } else { 590 $this->status = $status; 591 } 592 } // end set_status() 593 594 595 596 /** 597 * Return value of the quickformdb::status properties 598 * 599 * @since: 0.5 600 * @param: void 601 * @return: bool 602 * @access: private 603 * @see: quickformdb::status 604 * @see: quickformdb::set_status() 605 */ 606 public function get_status() 607 { 608 return $this->status; 609 } // end get_status() 610 611 612 613 /** 614 * Set the data ID that will be edited or updated. 615 * 616 * @since: 0.1 617 * @param: int $id Data ID edited 618 * @return: void 619 * @access: private 620 * @see: quickformdb::db 621 * @see: quickformdb::get_id() 622 */ 623 private function set_id($id) 624 { 625 // scape all db special char, include % and _ (underscore) 626 $this->db['id'] = $this->sql_scape_string(trim($id), true); 627 } // end set_id() 628 629 630 631 /** 632 * Get the data ID that will be edited or updated. 633 * 634 * @since: 0.5 635 * @param: void 636 * @return: mixed 637 * @access: public 638 * @see: quickformdb::db 639 * @see: quickformdb::set_id() 640 */ 641 public function get_id() 642 { 643 return $this->strip_db_slashes($this->db['id'], true); 644 } // end get_id() 645 646 647 648 /** 649 * Define if will be used the default CSS classname 650 * 651 * @since: 0.4 652 * @param: bool $css Define the default CSS classname 653 * @return: void 654 * @access: public 655 * @see: quickformdb::css 656 * @see: quickformdb::set_css() 657 * @see: quickformdb::get_css_value() 658 * @see: quickformdb::set_css_value() 659 */ 660 public function set_css($css) 661 { 662 if(!is_bool($css)) { 663 $this->add_critical_error(QFDBE_FLAGS_BAD_CSS . $this->make_error_ref('QFDBE_FLAGS_BAD_CSS')); 664 } else { 665 if ($css) { 666 $this->css['qfdb_input_error'] = 'qfdb_input_error'; 667 668 $this->css['qfdb_fieldset'] = 'qfdb_fieldset'; 669 $this->css['qfdb_legend'] = 'qfdb_legend'; 670 671 $this->css['qfdb_table'] = 'qfdb_table'; 672 $this->css['qfdb_textarea'] = 'qfdb_textarea'; 673 $this->css['qfdb_text'] = 'qfdb_text'; 674 $this->css['qfdb_title'] = 'qfdb_title'; 675 $this->css['qfdb_file'] = 'qfdb_file'; 676 677 $this->css['qfdb_reset'] = 'qfdb_reset'; 678 $this->css['qfdb_submit'] = 'qfdb_submit'; 679 $this->css['qfdb_button'] = 'qfdb_button'; 680 $this->css['qfdb_tpl_colspan_button'] = 'qfdb_tpl_colspan_button'; 681 $this->css['qfdb_tpl_colspan_ibutton'] = 'qfdb_tpl_colspan_ibutton'; 682 683 $this->css['qfdb_select'] = 'qfdb_select'; 684 $this->css['qfdb_select_option'] = 'qfdb_select_option'; 685 $this->css['qfdb_select_optgroup'] = 'qfdb_select_optgroup'; 686 687 $this->css['qfdb_radio_element'] = 'qfdb_radio_element'; 688 $this->css['qfdb_radio_element_label'] = 'qfdb_radio_element_label'; 689 $this->css['qfdb_radio_container_cols'] = 'qfdb_radio_container_cols'; 690 $this->css['qfdb_radio_cols'] = 'qfdb_radio_cols'; 691 692 $this->css['qfdb_checkbox_element'] = 'qfdb_checkbox_element'; 693 $this->css['qfdb_checkbox_element_label'] = 'qfdb_checkbox_element_label'; 694 $this->css['qfdb_checkbox_container_cols'] = 'qfdb_checkbox_container_cols'; 695 $this->css['qfdb_checkbox_cols'] = 'qfdb_checkbox_cols'; 696 697 $this->css['qfdb_report_line_1'] = 'qfdb_report_line_1'; 698 $this->css['qfdb_report_line_2'] = 'qfdb_report_line_2'; 699 $this->css['qfdb_report_paginate'] = 'qfdb_report_paginate'; 700 $this->css['qfdb_report_paginate_top'] = 'qfdb_report_paginate_top'; 701 $this->css['qfdb_report_paginate_bottom'] = 'qfdb_report_paginate_bottom'; 702 $this->css['qfdb_report_edit'] = 'qfdb_report_edit'; 703 $this->css['qfdb_report_thead'] = 'qfdb_report_thead'; 704 $this->css['qfdb_report_table'] = 'qfdb_report_table'; 705 706 $this->css['qfdb_messagebox_title'] = 'qfdb_messagebox_title'; 707 $this->css['qfdb_messagebox_message'] = 'qfdb_messagebox_message'; 708 709 $this->css['qfdb_tpl_left'] = 'qfdb_tpl_left'; 710 $this->css['qfdb_tpl_right'] = 'qfdb_tpl_right'; 711 $this->css['qfdb_tpl_colspan'] = 'qfdb_tpl_colspan'; 712 $this->css['qfdb_tpl_label'] = 'qfdb_tpl_label'; 713 $this->css['qfdb_tpl_help'] = 'qfdb_tpl_help'; 714 $this->css['qfdb_tpl_required'] = 'qfdb_tpl_required'; 715 } else { 716 $this->css['required'] = ''; 717 $this->css['help'] = ''; 718 $this->css['messagebox_message'] = ''; 719 $this->css['messagebox_title'] = ''; 720 $this->css['button'] = ''; 721 $this->css['fieldset'] = ''; 722 $this->css['input'] = ''; 723 $this->css['input_error'] = ''; 724 $this->css['label'] = ''; 725 $this->css['legend'] = ''; 726 $this->css['reset'] = ''; 727 $this->css['select'] = ''; 728 $this->css['submit'] = ''; 729 $this->css['table'] = ''; 730 $this->css['textarea'] = ''; 731 $this->css['title'] = ''; 732 $this->css['file'] = ''; 733 } 734 } 735 } // end func 736 737 738 739 /** 740 * Set a specific CSS classname for one QFDB Object 741 * 742 * @since: 0.5 743 * @param: string $index Index of quickformdb::css[] 744 * @param: string $value Name of CSS ClassName 745 * @return: void 746 * @access: public 747 * @see: quickformdb::css 748 * @see: quickformdb::set_css() 749 * @see: quickformdb::get_css_value() 750 */ 751 public function set_css_value($index, $class_name) 752 { 753 if (isset($this->css[$index])) { 754 $this->css[$index] = $class_name; 755 } else { 756 $this->add_critical_error( sprintf(QFDBE_FLAGS_BAD_CSS_INDEX.$this->make_error_ref('QFDBE_FLAGS_BAD_CSS_INDEX'), $index, 'set_css_value') ); 757 } 758 } // end set_css_value() 759 760 761 762 /** 763 * Get a specific CSS classname for one QFDB Object 764 * 765 * @since: 0.5 766 * @param: string $index Index of quickformdb::css[] 767 * @return: string 768 * @access: public 769 * @see: quickformdb::css 770 * @see: quickformdb::set_css() 771 * @see: quickformdb::set_css_value() 772 */ 773 public function get_css_value($index) 774 { 775 if (isset($this->css[$index])) { 776 return $this->css[$index]; 777 } else { 778 $this->add_critical_error( sprintf(QFDBE_FLAGS_BAD_CSS_INDEX.$this->make_error_ref('QFDBE_FLAGS_BAD_CSS_INDEX'), $index, 'get_css_value') ); 779 return false; 780 } 781 } // end get_css_value() 782 783 784 785 /** 786 * Specific if WARNING will be same as CRITICAL_ERROR 787 * 788 * @since: 0.5 789 * @param: string $index Index of quickformdb::css[] 790 * @return: string 791 * @access: public 792 * @see: quickformdb::css 793 * @see: quickformdb::set_css() 794 * @see: quickformdb::set_css_value() 795 */ 796 public function set_abort_on_warning($abw) 797 { 798 if (!is_bool($abw)) { 799 $this->add_critical_error(QFDBE_FLAGS_BAD_ABORT_ON_WARNING.$this->make_error_ref('QFDBE_FLAGS_BAD_ABORT_ON_WARNING')); 800 } else { 801 $this->error['abort_on_warning'] = $abw; 802 } 803 } // end set_abort_on_warning() 804 805 806 807 /** 808 * Define QFDB to run in debug mode 809 * 810 * @since: 0.3 811 * @param: bool $debug Debug mode 812 * @return: void 813 * @access: public 814 * @see: quickformdb::debug 815 * @see: quickformdb::get_debug() 816 */ 817 public function set_debug($debug=false) 818 { 819 if (!is_bool($debug)) { 820 $this->add_critical_error(QFDBE_FLAGS_BAD_DEBUG.$this->make_error_ref('QFDBE_FLAGS_BAD_DEBUG')); 821 } else { 822 $this->debug = $debug; 823 } 824 } // end set_debug() 825 826 827 828 /** 829 * Get value of the quickformdb::debug properties 830 * 831 * @since: 0.5 832 * @param: void 833 * @return: bool 834 * @access: public 835 * @see: quickformdb::debug 836 * @see: quickformdb::set_debug() 837 */ 838 public function get_debug() 839 { 840 return $this->debug; 841 } // end get_debug() 842 843 844 845 /** 846 * Define characters-sets used in QFDB Project -> default: UTF-8 847 * 848 * @since: 0.5 849 * @param: string $charset Character Sets 850 * @return: void 851 * @access: public 852 * @see: quickformdb::charset 853 * @see: quickformdb::get_charset() 854 * @see: http://www.iana.org/assignments/character-sets 855 */ 856 public function set_charset($charset='utf-8') 857 { 858 $this->charset = $charset; 859 } // end set_charset() 860 861 862 863 /** 864 * Get characters-sets used in QFDB Projet -> default: UTF-8 865 * 866 * @since: 0.5 867 * @param: string $charset Character-set 868 * @return: void 869 * @access: public 870 * @see: quickformdb::charset 871 * @see: quickformdb::get_charset() 872 * @see: http://www.iana.org/assignments/character-sets 873 */ 874 public function get_charset() 875 { 876 return $this->charset; 877 } // end get_charset() 878 879 880 881 /** 882 * Configure how error and warning messages will be treaties 883 * 884 * @since: 0.5 885 * @param: mixed $debugmsg How the error and warning message will be treaties 886 * @param: bool $warning Show warning message 887 * @param: string $aux Auxiliary var if $debugmsg equal 'file' or 'db' 888 * @param: string $mail Mail to send message if $debugmsg == 'db' or 'file' 889 * @param: bool $include_qfdb Include $qfdb Object 890 * @param: bool $include_globals Include $GLOBALS 891 * @return: void 892 * @access: public 893 * @see: quickformdb::debug_msg 894 */ 895 public function set_debug_msg($debugmsg='screen', $warning=true, $aux='', $mail='', $include_qfdb=false, $include_globals=false) 896 { 897 $this->debug_msg['type'] = $debugmsg; 898 $this->debug_msg['warning'] = $warning; 899 900 if (!is_bool($warning)) { 901 $this->add_critical_error( sprintf(QFDBE_FLAGS_DEBUGMSG_BAD_WARNING.$this->make_error_ref('QFDBE_FLAGS_DEBUGMSG_BAD_WARNING'), $warning) ); 902 } 903 904 if ($debugmsg == 'no_msg') { 905 $this->debug_msg['warning'] = false; 906 $this->debug = false; 907 } elseif ($debugmsg == 'screen') { 908 } elseif($debugmsg == 'file') { 909 $this->debug_msg['aux'] = $aux; 910 if ($this->debug) { 911 // verify if file exists and if was write permission 912 $aux = trim($aux); 913 if (!is_file($aux)) { 914 $this->add_critical_error( sprintf(QFDBE_FLAGS_DEBUGMSG_NOT_FILE.$this->make_error_ref('QFDBE_FLAGS_DEBUGMSG_NOT_FILE'), $aux) ); 915 } else { 916 if (!is_writable($aux)) { 917 $this->add_critical_error( sprintf(QFDBE_FLAGS_DEBUGMSG_NOT_WRITABLE.$this->make_error_ref('QFDBE_FLAGS_DEBUGMSG_NOT_WRITABLE'), $aux) ); 918 } 919 } 920 clearstatcache(); 921 } 922 $this->debug_msg['mail'] = $mail; 923 } elseif ($debugmsg == 'db') { 924 $aux = trim($aux); 925 $this->debug_msg['aux'] = $aux; 926 if ($this->debug) { 927 if (!$this->sql_is_connected(__FUNCTION__)) { 928 return; 929 } 930 931 if (!is_bool($include_qfdb)) { 932 $this->add_critical_error( sprintf(QFDBE_FLAGS_DEBUGMSG_BAD_INCLUDEQFDB.$this->make_error_ref('QFDBE_FLAGS_DEBUGMSG_BAD_INCLUDEQFDB'), gettype($include_qfdb)." '".$include_qfdb."'") ); 933 return; 934 } 935 936 if (!is_bool($include_globals)) { 937 $this->add_critical_error( sprintf(QFDBE_FLAGS_DEBUGMSG_BAD_INCLUDEGLOBALS.$this->make_error_ref('QFDBE_FLAGS_DEBUGMSG_BAD_INCLUDEGLOBALS'), gettype($include_globals)." '".$include_globals."'") ); 938 return; 939 } 940 941 // verify if table exists in data base 942 if (!$this->sql_table_exists($aux)) { 943 $this->add_critical_error( sprintf(QFDBE_FLAGS_DEBUGMSG_BAD_DBTABLE.$this->make_error_ref('QFDBE_FLAGS_DEBUGMSG_BAD_DBTABLE'), $aux) ); 944 return; 945 } 946 947 // verify if all fields exists in db table 948 $fields = $this->sql_get_fields($aux); 949 $fields_error = false; 950 $table_fields = array('id_error', 'datetime', 'remote_addr', 'filename', 'request_uri', 'get_var', 'post_var', 'cookie_var', 951 'session_var', 'global_var', 'qfdb_error', 'php_error', 'qfdb_object'); 952 if (count($fields) != count($table_fields)) { 953 $fields_error = true; 954 } else { 955 foreach ($table_fields as $key => $value) { 956 if ($fields[$key] !== $value) { 957 $fields_error = true; 958 break; 959 } 960 } 961 } 962 if ($fields_error) { 963 $this->add_critical_error( sprintf(QFDBE_FLAGS_DEBUGMSG_BAD_DBFIELDS.$this->make_error_ref('QFDBE_FLAGS_DEBUGMSG_BAD_DBFIELDS'), $aux, 964 implode(', ', $table_fields), implode(', ', $fields)) ); 965 return; 966 } 967 } 968 $this->debug_msg['include_qfdb'] = $include_qfdb; 969 $this->debug_msg['include_globals'] = $include_globals; 970 $this->debug_msg['mail'] = $mail; 971 } else { 972 $this->add_critical_error( sprintf(QFDBE_FLAGS_BAD_DEBUG_MSG.$this->make_error_ref('QFDBE_FLAGS_BAD_DEBUG_MSG'), $debugmsg) ); 973 } 974 } // end set_debug_msg() 975 976 977 978 /** 979 * This Method specified the use of JavaScript 980 * 981 * @since: 0.1 982 * @param: bool $js Specifies the use of JS 983 * @return: void 984 * @access: public 985 * @see: quickformdb::js 986 * @see: quickformdb::get_js() 987 */ 988 public function set_js($js) 989 { 990 if (!is_bool($js)) { 991 $this->add_critical_error(QFDBE_FLAGS_BAD_JS.$this->make_error_ref('QFDBE_FLAGS_BAD_JS')); 992 } else { 993 $this->js = $js; 994 } 995 } // end set_js() 996 997 998 999 /** 1000 * Return value of quickformdb::js 1001 * 1002 * @since: 0.5 1003 * @param: void 1004 * @return: bool 1005 * @access: public 1006 * @see: quickformdb::js 1007 * @see: quickformdb::set_js() 1008 */ 1009 public function get_js() 1010 { 1011 return $this->js; 1012 } // end get_js() 1013 1014 1015 1016 /** 1017 * Define DTD of Document 1018 * 1019 * @since: 0.3 1020 * @param: string $dtd DTD of Document 1021 * @return: void 1022 * @access: public 1023 * @see: quickformdb::dtd 1024 * @see: quickformdb::set_dts() 1025 * @link: http://w3schools.com/xhtml/xhtml_dtd.asp 1026 */ 1027 public function set_dtd($dtd='xhtml_transitional') 1028 { 1029 $dtd = strtolower(trim($dtd)); 1030 if ($dtd == 'xhtml_strict' || $dtd == 'xhtml_frameset' || $dtd == 'xhtml_transitional' || $dtd == 'html_strict' || 1031 $dtd == 'html_frameset' || $dtd == 'html_transitional') { 1032 $this->dtd = $dtd; 1033 } else { 1034 $this->add_critical_error(QFDBE_FLAGS_BAD_DTD.$this->make_error_ref('QFDBE_FLAGS_BAD_DTD')); 1035 } 1036 } // end set_dtd() 1037 1038 1039 1040 /** 1041 * Return value of quickformdb::dtd 1042 * 1043 * @since: 0.5 1044 * @param: void 1045 * @return: string 1046 * @access: public 1047 * @see: quickformdb::dtd 1048 * @see: quickformdb::set_dts() 1049 * @link: http://w3schools.com/xhtml/xhtml_dtd.asp 1050 */ 1051 public function get_dtd() 1052 { 1053 return $this->dtd; 1054 } // end get_dtd() 1055 1056 1057 1058 /** 1059 * Allow set restrictions for one or more status. 1060 * 1061 * @since: 0.5 1062 * @param: string $step When the restrictions are applied (before or after) 1063 * @param: int $status Allow define one or more status 1064 * @param: string $function Function to be called 1065 * @param: string $message Message shown if the function returns false 1066 * @return: void 1067 * @access: public 1068 * @see: quickformdb::restriction 1069 * @see: quickformdb::set_restriction() 1070 */ 1071 public function register_restriction($step, $_status, $function, $message) 1072 { 1073 $step = trim(strtolower($step)); 1074 $status = strval(ereg_replace('[^1-8]', '', $_status)); 1075 $function = trim($function); 1076 $message = trim($message); 1077 1078 if ($step != 'before' && $step != 'after') { 1079 $this->add_critical_error( sprintf(QFDBE_FLAGS_BAD_RESTRICTION_STEP.$this->make_error_ref('QFDBE_FLAGS_BAD_RESTRICTION_STEP'), $step) ); 1080 } 1081 1082 if (!$status) { 1083 $this->add_critical_error( sprintf(QFDBE_FLAGS_BAD_RESTRICTION_STATUS.$this->make_error_ref('QFDBE_FLAGS_BAD_RESTRICTION_STATUS'), $_status) ); 1084 } 1085 1086 if (!function_exists($function)) { 1087 $this->add_critical_error( sprintf(QFDBE_FLAGS_BAD_RESTRICTION_FUNCTION.$this->make_error_ref('QFDBE_FLAGS_BAD_RESTRICTION_FUNCTION'), $function) ); 1088 } 1089 1090 if (!strlen($message)) { 1091 $this->add_warning( sprintf(QFDBE_FLAGS_BAD_RESTRICTION_MESSAGE.$this->make_error_ref('QFDBE_FLAGS_BAD_RESTRICTION_MESSAGE'), $function) ); 1092 } 1093 1094 if (!$this->ok) { 1095 return; 1096 } 1097 1098 // set restriction for all status defined in this method 1099 for ($i=1; $i<strlen($status); $i++) { 1100 // verify if this restriction will be redefined 1101 if ($this->restriction[$i][$step]['function'] !== '') { 1102 $this->add_warning( sprintf(QFDBE_FLAGS_REDEFINE_RESTRICTION.$this->make_error_ref('QFDBE_FLAGS_REDEFINE_RESTRICTION'), 1103 $i, $step, $function, $this->restriction[$i][$step]['function']) ); 1104 } 1105 $this->restriction[$i][$step] = array('function' => $function, 'message' => $message); 1106 } 1107 } // end register_restriction() 1108 1109 1110 1111 /** 1112 * Define title of document 1113 * 1114 * @since: 0.5 1115 * @param: string $pagetitle Title of Document 1116 * @return: void 1117 * @access: public 1118 * @see: quickformdb::pagetitle 1119 * @see: quickformdb::concat_pagetitle() 1120 * @see: quickformdb::get_pagetitle() 1121 */ 1122 public function set_pagetitle($pagetitle) 1123 { 1124 $this->pagetitle = $pagetitle; 1125 } // end set_pagetititle() 1126 1127 1128 1129 /** 1130 * Concat a string to the title 1131 * 1132 * @since: 0.5 1133 * @param: string $pagetitle Title of Document 1134 * @return: void 1135 * @access: public 1136 * @see: quickformdb::pagetitle 1137 * @see: quickformdb::set_pagetitle() 1138 * @see: quickformdb::get_pagetitle() 1139 */ 1140 public function concat_pagetitle($pagetitle) 1141 { 1142 $this->pagetitle .= $pagetitle; 1143 } // end concat_pagetitle() 1144 1145 1146 1147 /** 1148 * Return quickformdb::pagetitle value 1149 * 1150 * @since: 0.5 1151 * @param: void 1152 * @return: string 1153 * @access: public 1154 * @see: quickformdb::pagetitle 1155 * @see: quickformdb::set_pagetitle() 1156 * @see: quickformdb::concat_pagetitle() 1157 */ 1158 public function get_pagetitle() 1159 { 1160 return $this->pagetitle; 1161 } // end get_pagetitle() 1162 1163 1164 1165 /** 1166 * Add variable to a QFDB Object 1167 * 1168 * @since: 0.5 1169 * @param: string $varname Varname (add like index of quickformdb::vars) 1170 * @param: mixed $value Value to set 1171 * @return: void 1172 * @access: public 1173 * @see: quickformdb::vars 1174 * @see: quickformdb::get_var() 1175 * @see: quickformdb::capture_var() 1176 */ 1177 public function add_var($_varname, $value) 1178 { 1179 $_varname = strval(trim($_varname)); 1180 $varname = ereg_replace('[^0-9a-zA-Z_]', '', $_varname); 1181 1182 if ($varname != $_varname) { 1183 $this->add_critical_error(sprintf(QFDBE_FLAGS_VARS_BAD_VARNAME.$this->make_error_ref('QFDBE_FLAGS_VARS_BAD_VARNAME'), __FUNCTION__, $_varname)); 1184 return; 1185 } 1186 1187 if ($this->debug && isset($this->vars[ $varname ])) { 1188 $this->add_warning(sprintf(QFDBE_FLAGS_VARS_REDEFINE_VARS.$this->make_error_ref('QFDBE_FLAGS_VARS_REDEFINE_VARS'), $varname, $this->vars[$varname], __FUNCTION__, $value)); 1189 } 1190 $this->vars[$varname] = $value; 1191 } // end add_var() 1192 1193 1194 1195 /** 1196 * Capture variable to a QFDB Object 1197 * 1198 * @since: 0.5 1199 * @param: string $varname Varname (add like index of quickformdb::vars) 1200 * @param: string $order Location to seek values 1201 * @param: mixed $default Value to set if no one $order is set 1202 * @return: void 1203 * @access: public 1204 * @see: quickformdb::vars 1205 * @see: quickformdb::add_var() 1206 * @see: quickformdb::get_var() 1207 */ 1208 public function capture_var($_varname='', $order='PGCSA', $default='') 1209 { 1210 $_varname = strval(trim($_varname)); 1211 $varname = ereg_replace('[^0-9a-zA-Z_]', '', $_varname); 1212 $order = trim(strtoupper($order)); 1213 1214 if ($varname != $_varname) { 1215 $this->add_critical_error(sprintf(QFDBE_FLAGS_VARS_BAD_VARNAME.$this->make_error_ref('QFDBE_FLAGS_VARS_BAD_VARNAME'), __FUNCTION__, $_varname)); 1216 return; 1217 } 1218 1219 if ($this->debug && isset($this->vars[ $varname ])) { 1220 $this->add_warning(sprintf(QFDBE_FLAGS_VARS_REDEFINE_VARS.$this->make_error_ref('QFDBE_FLAGS_VARS_REDEFINE_VARS'), $varname, $this->vars[$varname], __FUNCTION__, " arrays ($order)")); 1221 } 1222 1223 for ($i=0; $i<strlen($order); $i++) { 1224 switch ($order{$i}) { 1225 case 'P': // if POST 1226 if (isset($_POST[$varname])) { 1227 $this->vars[$varname] = $_POST[$varname]; 1228 return; 1229 } 1230 break; 1231 case 'G': // if GET 1232 if (isset($_GET[$varname])) { 1233 $this->vars[$varname] = $_GET[$varname]; 1234 return; 1235 } 1236 break; 1237 case 'C': // if COOKIE 1238 if (isset($_COOKIE[$varname])) { 1239 $this->vars[$varname] = $_COOKIE[$varname]; 1240 return; 1241 } 1242 break; 1243 case 'S': // if SESSION 1244 if (isset($_SESSION[$varname])) { 1245 $this->vars[$varname] = $_SESSION[$varname]; 1246 return; 1247 } 1248 break; 1249 case 'A': // if GLOBALS ARRAY 1250 if (isset($GLOBALS[$varname])) { 1251 $this->vars[$varname] = $GLOBALS[$varname]; 1252 return; 1253 } 1254 break; 1255 default: 1256 $this->add_critical_error(sprintf(QFDBE_FLAGS_VARS_BAD_ORDER.$this->make_error_ref('QFDBE_FLAGS_VARS_BAD_ORDER'), $order{$i})); 1257 return; 1258 break; 1259 } // end switch 1260 } 1261 $this->vars[$varname] = $default; 1262 } // end capture_var() 1263 1264 1265 1266 /** 1267 * Get variable registered in QFDB Object 1268 * 1269 * @since: 0.5 1270 * @param: string $varname Index of quickformdb::vars to return 1271 * @return: mixed 1272 * @access: public 1273 * @see: quickformdb::vars 1274 * @see: quickformdb::add_var() 1275 * @see: quickformdb::capture_var() 1276 */ 1277 public function get_var($varname) 1278 { 1279 if (isset($this->vars[$varname])) { 1280 return $this->vars[$varname]; 1281 } else { 1282 $this->add_critical_error(sprintf(QFDBE_FLAGS_VAR_DONT_EXISTS.$this->make_error_ref('QFDBE_FLAGS_VAR_DONT_EXISTS'), $varname)); 1283 } 1284 } // end get_var() 1285 1286 1287 1288 /** 1289 * Set one or more characteres to be used in code indentation 1290 * 1291 * @since: 0.5 1292 * @param: string $indent One or more characteres used to indent HTML code 1293 * @return: void 1294 * @access: public 1295 * @see: quickformdb::indent 1296 * @see: quickformdb::get_indent() 1297 */ 1298 public function set_indent($indent='') 1299 { 1300 $this->indent = $indent; 1301 } // end set_indent() 1302 1303 1304 1305 /** 1306 * Get quickformdb::indent value 1307 * 1308 * @since: 0.5 1309 * @param: int $n Print quickformdb::indent $n times 1310 * @return: string 1311 * @access: public 1312 * @see: quickformdb::indent 1313 * @see: quickformdb::set_indent() 1314 * @see: quickformdb::i() 1315 */ 1316 public function get_indent($n=1) 1317 { 1318 return $this->i($n); 1319 } // end get_indent() 1320 1321 1322 1323 /** 1324 * Same of quickformdb::get_indent() 1325 * 1326 * @since: 0.5 1327 * @param: int $n Print quickformdb::indent $n times 1328 * @return: string 1329 * @access: public 1330 * @see: quickformdb::indent 1331 * @see: quickformdb::set_indent() 1332 * @see: quickformdb::get_indent() 1333 */ 1334 public function i($n=1) 1335 { 1336 $n = intval($n); 1337 $return = ''; 1338 for ($i=0; $i<$n; $i++) { 1339 $return .= $this->indent; 1340 } 1341 return $return; 1342 } // end func 1343 1344 1345 1346 // #################################### 1347 // #################################### 1348 // #################################### 1349 // #################################### 1350 // PARSER 1351 1352 1353 /** 1354 * Add qfdb_type properties for each QFDB Object 1355 * 1356 * @since: 0.5 1357 * @param: array of mixed $matrix Matrix to parser or Parsed Matrix with QFDB Objects 1358 * @param: string $type Type of qfdb_type properties of all QFDB Objects 1359 * @param: bool $parser Indicate if $matrix was parsed or not 1360 * @return: void 1361 * @access: private 1362 * @see: quickformdb::matrix_header 1363 * @see: quickformdb::matrix_footer 1364 * @see: quickformdb::matrix_body 1365 * @see: quickformdb::add_header() 1366 * @see: quickformdb::add_footer() 1367 * @see: quickformdb::add_matrix() 1368 * @see: quickformdb::parse_matrix() 1369 * @see: quickformdb::parse_all_matrix() 1370 * @see: quickformdb::load_header() 1371 * @see: quickformdb::load_footer() 1372 * @see: quickformdb::load_matrix() 1373 */ 1374 private function add_qfdb_type(&$matrix, $qfdb_type='body', $parsed=true) 1375 { 1376 if ($parsed) { 1377 foreach ($matrix as $key => $value) { 1378 $matrix[$key]['qfdb_type'] = $qfdb_type; 1379 } 1380 } else { 1381 foreach ($matrix as $key => $value) { 1382 $matrix[$key] .= ' ||| qfdb_type='.$qfdb_type; 1383 } 1384 } 1385 } // end add_qfdb_type() 1386 1387 1388 1389 /** 1390 * Parse $matrix_header 1391 * 1392 * @since: 0.5 1393 * @param: array of string $matrix_header Matrix with Page's Header 1394 * @return: void 1395 * @access: public 1396 * @see: quickformdb::matrix_header 1397 * @see: quickformdb::add_footer() 1398 * @see: quickformdb::add_body() 1399 * @see: quickformdb::parse_matrix() 1400 * @see: quickformdb::parse_all_matrix() 1401 * @see: quickformdb::load_header() 1402 * @see: quickformdb::load_footer() 1403 * @see: quickformdb::load_matrix() 1404 */ 1405 public function add_header($matrix_header) 1406 { 1407 if (is_array($matrix_header)) { 1408 $this->add_qfdb_type($matrix_header, 'header', false); 1409 $this->matrix_header['no_parsed'] = $matrix_header; 1410 } else { 1411 $this->add_critical_error( sprintf(QFDBE_PARSER_WRONG_MATRIX.$this->make_error_ref('QFDBE_PARSER_WRONG_MATRIX'), __FUNCTION__)); 1412 } 1413 } // end add_header() 1414 1415 1416 1417 /** 1418 * Parse $matrix_footer 1419 * 1420 * @since: 0.5 1421 * @param: array of string $matrix_footer Matrix with Page's Footer 1422 * @return: void 1423 * @access: public 1424 * @see: quickformdb::matrix_footer 1425 * @see: quickformdb::add_header() 1426 * @see: quickformdb::add_body() 1427 * @see: quickformdb::parse_matrix() 1428 * @see: quickformdb::parse_all_matrix() 1429 * @see: quickformdb::load_header() 1430 * @see: quickformdb::load_footer() 1431 * @see: quickformdb::load_matrix() 1432 */ 1433 public function add_footer($matrix_footer) 1434 { 1435 if (is_array($matrix_footer)) { 1436 $this->add_qfdb_type($matrix_footer, 'footer', false); 1437 $this->matrix_footer['no_parsed'] = $matrix_footer; 1438 } else { 1439 $this->add_critical_error(sprintf(QFDBE_PARSER_WRONG_MATRIX.$this->make_error_ref('QFDBE_PARSER_WRONG_MATRIX'), __FUNCTION__)); 1440 } 1441 } // end add_footer() 1442 1443 1444 1445 /** 1446 * Parse $matrix 1447 * 1448 * @since: 0.4 1449 * @param: array of string $matrix Matrix with Page's Body 1450 * @return: void 1451 * @access: public 1452 * @see: quickformdb::matrix_body 1453 * @see: quickformdb::add_header() 1454 * @see: quickformdb::add_footer() 1455 * @see: quickformdb::parse_matrix() 1456 * @see: quickformdb::parse_all_matrix() 1457 * @see: quickformdb::load_header() 1458 * @see: quickformdb::load_footer() 1459 * @see: quickformdb::load_matrix() 1460 */ 1461 public function add_body($matrix_body) 1462 { 1463 if (is_array($matrix_body)) { 1464 $this->add_qfdb_type($matrix_body, 'footer', false); 1465 $this->matrix_body['no_parsed'] = $matrix_body; 1466 } else { 1467 $this->add_critical_error(sprintf(QFDBE_PARSER_WRONG_MATRIX.$this->make_error_ref('QFDBE_PARSER_WRONG_MATRIX'), __FUNCTION__)); 1468 } 1469 } // end add_body() 1470 1471 1472 1473 /** 1474 * Parse all $matrix 1475 * 1476 * @since: 0.4 1477 * @param: void 1478 * @return: void 1479 * @access: private 1480 * @see: quickformdb::matrix_header 1481 * @see: quickformdb::matrix_footer 1482 * @see: quickformdb::matrix_body 1483 * @see: quickformdb::add_header() 1484 * @see: quickformdb::add_footer() 1485 * @see: quickformdb::add_body() 1486 * @see: quickformdb::parse_matrix() 1487 * @see: quickformdb::parse_all_matrix() 1488 * @see: quickformdb::load_header() 1489 * @see: quickformdb::load_footer() 1490 * @see: quickformdb::load_matrix() 1491 */ 1492 public function parse_matrix($area='') 1493 { 1494 if (!$this->ok) { 1495 return; 1496 } 1497 1498 // parse body 1499 $this->step = 'beggin_parse_body'; 1500 $this->output['html_type'] = 'body'; 1501 $this->parse_all_matrix($this->matrix_body['no_parsed'], $area); 1502 $this->step = 'end_parse_body'; 1503 1504 if (!$this->ok) { 1505 return; 1506 } 1507 1508 // parse header 1509 $this->step = 'beggin_parse_header'; 1510 $this->output['html_type'] = 'header'; 1511 $this->parse_all_matrix($this->matrix_header['no_parsed'], 'qfdb_header'); 1512 $this->step = 'end_parse_header'; 1513 1514 if (!$this->ok) { 1515 return; 1516 } 1517 1518 // parse footer 1519 $this->step = 'beggin_parse_footer'; 1520 $this->output['html_type'] = 'footer'; 1521 $this->parse_all_matrix($this->matrix_footer['no_parsed'], 'qfdb_footer'); 1522 $this->step = 'end_parse_footer'; 1523 1524 // set the parser properties to true if finish with sucess 1525 $this->parsed = true; 1526 $this->matrix_object = ''; 1527 $this->m = array(); 1528 $this->matrix_content = ''; 1529 $this->matrix_line = -1; 1530 } // end parse_matrix() 1531 1532 1533 1534 /** 1535 * Parse $matrix and fixed struct of all QFDB Objects 1536 * 1537 * @since: 0.5 1538 * @param: array of mixed $matrix Matrix to fixed struct of QFDB Objects 1539 * @return: void 1540 * @access: private 1541 * @see: quickformdb::matrix_header 1542 * @see: quickformdb::matrix_footer 1543 * @see: quickformdb::matrix_body 1544 * @see: quickformdb::parse_header() 1545 * @see: quickformdb::parse_footer() 1546 * @see: quickformdb::parse_matrix() 1547 * @see: quickformdb::add_qfdb_type() 1548 * @see: quickformdb::load_header() 1549 * @see: quickformdb::load_footer() 1550 * @see: quickformdb::load_matrix() 1551 */ 1552 private function parse_all_matrix($matrix, $area) 1553 { 1554 $cache_matrix = false; 1555 $cache_exists = false; 1556 $area = $this->sql_scape_string($area, false); 1557 1558 $active = ($area) ? true: false; 1559 $file_updated = ($area == 'qfdb_header' || $area == 'qfdb_footer') ? $this->cache['init_file_updated'] : $this->cache['file_updated']; 1560 1561 // try to rescue a cached matrix 1562 if ($this->cache['active'] && $active) { 1563 $query = "SELECT * FROM `{$this->cache['db_table']}` WHERE `area`='{$area}' "; 1564 $result = $this->sql_query($query); 1565 if ($this->sql_numrows() == 1) { 1566 $cache_exists = true; 1567 $row = $this->sql_fetchrow($result); 1568 $updated = eregi_replace('[^0-9]', '', $row['updated']); 1569 $data = unserialize($row['data']); 1570 1571 if ($data !== false) { 1572 // verify if db_cache is up2date 1573 if ($updated+1 > $file_updated) { // add 1 second to fix float precision error 1574 eval('$this->matrix_'.$this->output['html_type'].'[ \'parsed\' ] = $data;'); // echo ' load cache --- '; 1575 1576 foreach ($data as $key => $value) { 1577 $constant = 'QFDB_OBJECT_'.strtoupper($value['object']).'_LOAD'; 1578 1579 $this->matrix_object = $value['object']; 1580 1581 if ($constant && !defined($constant)) { 1582 $this->load_object_file($constant); 1583 } 1584 } 1585 return; 1586 } else { 1587 $cache_matrix = true; 1588 } 1589 } else { // if data is corrupted 1590 $cache_matrix = true; 1591 } 1592 } else { 1593 $cache_matrix = true; 1594 } 1595 } 1596 1597 // start the parser; 1598 foreach ($matrix as $this->matrix_line => $this->matrix_content) { 1599 $line = explode('=>', $this->matrix_content, 2); 1600 1601 // verify if the object is defined in the current status 1602 $status_verify = explode('|||', $line[0]); 1603 1604 $status_verify[1] = trim($status_verify[1]); 1605 if (!isset($status_verify[1]) || strlen($status_verify[1]) < 1 ) { 1606 $this->add_warning( sprintf(QFDBE_PARSER_WRONG_STATUS_VAL.$this->make_error_ref('QFDBE_PARSER_WRONG_STATUS_VAL'), $status_verify[0]) ); 1607 $status_verify[1] = ''; 1608 } 1609 1610 $line[0] = trim($status_verify[0]); 1611 1612 $this->matrix_object = str_replace('/', 'sl', $line[0]); 1613 1614 $constant = false; 1615 if (count($line) != 2) { 1616 $this->add_critical_error( sprintf(QFDBE_PARSER_BAD_MATRIX_LINE.$this->make_error_ref('QFDBE_PARSER_BAD_MATRIX_LINE'), $this->matrix_content) ); 1617 } else { 1618 $this->matrix_object = trim($line[0]); 1619 $constant = 'QFDB_OBJECT_'.strtoupper($this->matrix_object).'_LOAD'; 1620 } 1621 1622 if ($constant && !defined($constant)) { 1623 $this->load_object_file($constant); 1624 } 1625 1626 if (!$this->ok) { 1627 return; 1628 } 1629 1630 // restore the array 1631 $this->m = array(); 1632 1633 // get the default struct of object in the current line 1634 eval("qfdbobj_{$this->matrix_object}::obj_struct(\$this);"); 1635 $this->m['object'] = $this->matrix_object; 1636 $this->m['status'] = trim($status_verify[1]); 1637 // verify of there are values that update the default struct values of object in the matrix current line 1638 if (function_exists("qfdbobj_{$this->matrix_object}")) { 1639 $function = "qfdbobj_{$this->matrix_object}"; 1640 $function($this); 1641 if (!is_array($this->m)) { 1642 $this->add_critical_error( sprintf(QFDBE_PARSER_BAD_QFDB_STRUCT.$this->make_error_ref('QFDBE_PARSER_BAD_QFDB_STRUCT'), $function) ); 1643 return; 1644 } 1645 } 1646 1647 // update the default struct base with values defined by developer 1648 $line = explode('|||', $line[1]); 1649 foreach ($line as $linevalue) { 1650 1651 if (!trim($linevalue)) { 1652 continue; 1653 } 1654 1655 $linevalue = explode('=', $linevalue, 2); 1656 if (count($linevalue) != 2) { 1657 $this->add_critical_error( sprintf(QFDBE_PARSER_BAD_OBJVALUE.$this->make_error_ref('QFDBE_PARSER_BAD_OBJVALUE'), $linevalue[0], $this->matrix_line) ); 1658 $linevalue[1] = ''; 1659 } 1660 $this->m[ trim($linevalue[0]) ] = trim($linevalue[1]); 1661 } 1662 1663 // fix some few struct values of the elements of objects 1664 eval("qfdbobj_{$this->matrix_object}::obj_fixed(\$this);"); 1665 $this->fixed_common_properties(); 1666 1667 if (!$this->ok) { 1668 return; 1669 } 1670 eval('$this->matrix_'.$this->output['html_type'].'[ \'parsed\' ][] = $this->m;'); 1671 } 1672 1673 // try to save data in database (to cache) 1674 if ($cache_matrix && $this->cache['active'] && $active) { 1675 eval('$data = $this->matrix_'.$this->output['html_type'].'[ \'parsed\' ];'); 1676 $data = $this->sql_scape_string(serialize($data), false); 1677 if ($cache_exists) { // update 1678 $this->sql_query("UPDATE `{$this->cache['db_table']}` SET `updated`='{$file_updated}', `data`='$data' WHERE `area`='{$area}' "); // echo ' update cache --- '; 1679 } else { // insert 1680 $this->sql_query("INSERT INTO `{$this->cache['db_table']}` (`area`, `updated`, `data`) VALUES ('$area', '{$file_updated}', '$data') "); // echo ' insert cache --- '; 1681 } 1682 } 1683 } // end parse_all_matrix() 1684 1685 1686 1687 /** 1688 * Load $matrix_header 1689 * 1690 * @since: 0.5 1691 * @param: array of string $matrix_header Matrix with Page's Header (Parsed) 1692 * @return: void 1693 * @access: public 1694 * @see: quickformdb::matrix_header 1695 * @see: quickformdb::parse_header() 1696 * @see: quickformdb::parse_footer() 1697 * @see: quickformdb::parse_matrix() 1698 * @see: quickformdb::parse_all_matrix() 1699 * @see: quickformdb::load_footer() 1700 * @see: quickformdb::load_matrix() 1701 */ 1702 public function load_header($matrix_header) 1703 { 1704 $this->step = 'beggin_load_header'; 1705 if (is_array($matrix_header)) { 1706 $this->add_qfdb_type($matrix_header, 'header', true); 1707 $this->matrix_header['parsed'] = $matrix_header; 1708 } else { 1709 $this->add_critical_error(sprintf(QFDBE_PARSER_WRONG_MATRIX.$this->make_error_ref('QFDBE_PARSER_WRONG_MATRIX'), __FUNCTION__)); 1710 } 1711 $this->step = 'end_load_header'; 1712 } // end func 1713 1714 1715 1716 /** 1717 * Load $matrix_footer 1718 * 1719 * @since: 0.5 1720 * @param: array of string $matrix_footer Matrix with Page's Footer (Parsed) 1721 * @return: void 1722 * @access: public 1723 * @see: quickformdb::matrix_footer 1724 * @see: quickformdb::parse_header() 1725 * @see: quickformdb::parse_footer() 1726 * @see: quickformdb::parse_matrix() 1727 * @see: quickformdb::parse_all_matrix() 1728 * @see: quickformdb::load_header() 1729 * @see: quickformdb::load_matrix() 1730 */ 1731 public function load_footer($matrix_footer) 1732 { 1733 $this->step = 'beggin_load_footer'; 1734 if (is_array($matrix_footer)) { 1735 $this->add_qfdb_type($matrix_header, 'footer', true); 1736 $this->matrix_footer['parsed'] = $matrix_footer; 1737 } else { 1738 $this->add_critical_error(sprintf(QFDBE_PARSER_WRONG_MATRIX.$this->make_error_ref('QFDBE_PARSER_WRONG_MATRIX'), __FUNCTION__)); 1739 } 1740 $this->step = 'end_load_header'; 1741 } // end func 1742 1743 1744 1745 /** 1746 * Load $matrix_body 1747 * 1748 * @since: 0.5 1749 * @param: array of string $matrix_body Matrix with Page's Body (Parsed) 1750 * @return: void 1751 * @access: public 1752 * @see: quickformdb::matrix_body 1753 * @see: quickformdb::parse_header() 1754 * @see: quickformdb::parse_footer() 1755 * @see: quickformdb::parse_matrix() 1756 * @see: quickformdb::parse_all_matrix() 1757 * @see: quickformdb::load_header() 1758 * @see: quickformdb::load_footer() 1759 */ 1760 public function load_body($matrix_body) 1761 { 1762 $this->step = 'beggin_load_matrix'; 1763 if (is_array($matrix_body)) { 1764 $this->add_qfdb_type($matrix_body, 'body', true); 1765 $this->matrix_body['parsed'] = $matrix_body; 1766 $this->parsed = true; 1767 } else { 1768 $this->add_critical_error(sprintf(QFDBE_PARSER_WRONG_MATRIX.$this->make_error_ref('QFDBE_PARSER_WRONG_MATRIX'), __FUNCTION__)); 1769 } 1770 $this->step = 'end_load_matrix'; 1771 } // end func 1772 1773 1774 1775 /** 1776 * Load QFDB Object File and its language file 1777 * 1778 * @since: 0.3 1779 * @param: string $constant File Constant to define and avoids new attempt to load it. 1780 * @return: void 1781 * @access: private 1782 * @see: quickformdb::parse_all_matrix() 1783 */ 1784 private function load_object_file($constant) 1785 { 1786 $file = QFDB_OBJECT_PATH . "qfdbobj_{$this->matrix_object}.php"; 1787 if (file_exists($file)) { 1788 include_once($file); 1789 $langfile = QFDB_LANG_PATH . QFDB_LANG . "/objects/qfdbl_{$this->matrix_object}.php"; 1790 if (file_exists($langfile)) { 1791 require_once($langfile); 1792 } else { 1793 $this->add_critical_error( sprintf(QFDBE_PARSER_OBJECT_LANGFILE_NOT_FOUND.$this->make_error_ref('QFDBE_PARSER_OBJECT_LANGFILE_NOT_FOUND'), $langfile) ); 1794 return; 1795 } 1796 define($constant, true); 1797 } else { 1798 $this->add_critical_error( sprintf(QFDBE_PARSER_OBJECT_FILE_NOT_FOUND.$this->make_error_ref('QFDBE_PARSER_OBJECT_FILE_NOT_FOUND'), $file) ); 1799 } 1800 } // end load_object_file() 1801 1802 1803 1804 // #################################### 1805 // #################################### 1806 // #################################### 1807 // #################################### 1808 // CORE 1809 1810 /** 1811 * Execute all QFDB Objects 1812 * 1813 * @since: 0.1 1814 * @param: int $status Status to set the QFDB 1815 * @param: mixed $id ID of Data to edited or updated 1816 * @param: bool $print_header Will be print Page Header 1817 * @param: bool $print_footer Will be print Page Footer 1818 * @return: void 1819 * @access: public 1820 * @see: quickformdb::make_html() 1821 * @see: quickformdb::make_db() 1822 */ 1823 public function action($status, $id=0, $print_header=true, $print_footer=true) 1824 { 1825 $this->step = 'beggin_action'; 1826 if (!$this->ok) { 1827 return; 1828 } 1829 1830 $this->set_status($status); 1831 $this->set_id($id); 1832 1833 if (is_bool($print_header)) { 1834 $this->matrix_header['print'] = $print_header; 1835 } else { 1836 $this->add_critical_error( sprintf(QFDBE_CORE_ACTION_WRONG_BOOLVAL.$this->make_error_ref('QFDBE_CORE_ACTION_WRONG_BOOLVAL'), 'print_header') ); 1837 } 1838 1839 if (is_bool($print_footer)) { 1840 $this->matrix_footer['print'] = $print_footer; 1841 } else { 1842 $this->add_critical_error( sprintf(QFDBE_CORE_ACTION_WRONG_BOOLVAL.$this->make_error_ref('QFDBE_CORE_ACTION_WRONG_BOOLVAL'), 'print_footer') ); 1843 } 1844 1845 if (!$this->parsed) { 1846 $this->add_critical_error(QFDBE_CORE_NO_MATRIX.$this->make_error_ref('QFDBE_CORE_NO_MATRIX')); 1847 } 1848 1849 // if $this->status == 3 or 4, verify $this->db var 1850 if ($this->status == 3 || $this->status == 4) { 1851 if (!$this->db['id']) { 1852 $this->add_critical_error(QFDBE_CORE_NO_ID.$this->make_error_ref('QFDBE_CORE_NO_ID')); 1853 } 1854 if (!$this->db['primary_key']) { 1855 $this->add_critical_error(QFDBE_CORE_NO_PRIMARY_KEY.$this->make_error_ref('QFDBE_CORE_NO_PRIMARY_KEY')); 1856 } 1857 1858 if (!$this->db['connect_id']) { 1859 $this->add_critical_error( sprintf(QFDBE_CORE_DB_CONNECTID_NOT_EXISTS.$this->make_error_ref('QFDBE_CORE_DB_CONNECTID_NOT_EXISTS'), $this->status) ); 1860 return; 1861 } 1862 1863 if (!$this->db['table']) { 1864 $this->add_critical_error( sprintf(QFDBE_CORE_DBTABLE_NOT_DEFINED.$this->make_error_ref('QFDBE_CORE_DBTABLE_NOT_DEFINED'), $this->status) ); 1865 return; 1866 } 1867 1868 } 1869 1870 if (!$this->ok) { 1871 return; 1872 } 1873 1874 // verify if exists one restrict function 'before' for the current status 1875 $aux = false; 1876 if ($this->status != 9 && $this->restriction[ $this->status ]['before']['function'] !== '') { 1877 $function = '$aux = '.$this->restriction[ $this->status ]['before']['function'].'('.$this->restriction[ $this->status ]['before']['function'].');'; 1878 exec($function); 1879 if ($aux === false) { 1880 $this->add_user_error($this->restriction[ $this->status ]['before']['message']); 1881 $this->add_critical_error( sprintf(QFDBE_CORE_AFTERBEFORE_BLOCKED.$this->make_error_ref('QFDBE_CORE_AFTERBEFORE_BLOCKED'), '', 1882 $this->restriction[ $this->status ]['before']['function'], $this->restriction[ $this->status ]['before']['message']) ); 1883 return; 1884 } 1885 } 1886 1887 switch ($this->status) { 1888 case 1: // form (insert) 1889 case 5: // report or neutral status (for object that not need form interaction) 1890 case 6: // some of status 5, for more option to programmer 1891 case 7: 1892 case 8: 1893 case 9: 1894 $this->make_html(false); 1895 break; 1896 1897 case 2: // db (insert) 1898 $this->make_db(); 1899 if ($this->ok) { 1900 if (!$this->error['user_flag']) { 1901 $this->make_db_insert(); 1902 } 1903 $this->db_alias = array(); 1904 1905 if ($this->ok) { 1906 if (!$this->error['user_flag']) { 1907 $this->make_db_sucess('insert'); 1908 return; 1909 } 1910 } 1911 } 1912 1913 $this->put_user_error(); 1914 1915 // if occurred error, return to status 1 1916 if (!$this->ok || $this->error['user_flag']) { 1917 $this->clear_on_error(); 1918 $this->status = 1; 1919 $this->make_html(true); 1920 } 1921 break; 1922 1923 case 3: // form (edit) 1924 $this->get_db_values(); 1925 $this->make_html(false); 1926 break; 1927 1928 case 4: // db (update) 1929 $this->make_db(); 1930 1931 if ($this->ok) { 1932 if (!$this->error['user_flag']) { 1933 $this->make_db_update(); 1934 } 1935 $this->db_alias = array(); 1936 1937 if ($this->ok) { 1938 if (!$this->error['user_flag']) { 1939 $this->make_db_sucess('update'); 1940 return; 1941 } 1942 } 1943 } 1944 1945 $this->put_user_error(); 1946 1947 // if occurred error, return to status 3 1948 if (!$this->ok || $this->error['user_flag']) { 1949 $this->clear_on_error(); 1950 $this->status = 3; 1951 $this->make_html(true); 1952 } 1953 break; 1954 } // end witch 1955 1956 // verify if exists one restrict function 'after' for the current status 1957 $aux = false; 1958 if ($this->ok && $this->status != 9 && $this->restriction[ $this->status ]['after']['function'] !== '') { 1959 $function = '$aux = '.$this->restriction[ $this->status ]['after']['function'].'('.$this->restriction[ $this->status ]['after']['function'].');'; 1960 exec($function); 1961 if ($aux === false) { 1962 $this->add_user_error($this->restriction[ $this->status ]['after']['message']); 1963 $this->add_critical_error( sprintf(QFDBE_CORE_AFTERBEFORE_BLOCKED.$this->make_error_ref('QFDBE_CORE_AFTERBEFORE_BLOCKED'), '', 1964 $this->restriction[ $this->status ]['after']['function'], $this->restriction[ $this->status ]['after']['message']) ); 1965 return; 1966 } 1967 } 1968 $this->step = 'end_action'; 1969 } // end action() 1970 1971 1972 1973 /** 1974 * Execute QFDB Objects in HTML Mode 1975 * 1976 * @since: 0.1 1977 * @param: bool $user_error Indicate that user error as occured 1978 * @return: void 1979 * @access: private 1980 * @see: quickformdb::action() 1981 * @see: quickformdb::make_db() 1982 */ 1983 private function make_html($user_error = false) 1984 { 1985 // $this->matrix_content is only used in parser 1986 $this->matrix_content = ''; 1987 1988 // parse header 1989 if (!$this->output['html_header_ok'] && count($this->matrix_header['parsed'])) { 1990 $this->output['html_type'] = 'header'; 1991 foreach ($this->matrix_header['parsed'] as $this->matrix_line => $this->m) { 1992 if(!$this->defined_in_status() || !$this->defined_in_qfdbtype()) { 1993 continue; 1994 } 1995 $this->m['object'] = str_replace('/', 'sl', $this->m['object']); 1996 eval("qfdbobj_{$this->m['object']}::obj_debug(\$this);"); 1997 eval("qfdbobj_{$this->m['object']}::obj_html(\$this);"); 1998 $this->qfdb_error_object_properties(); 1999 } 2000 $this->output['html_header_ok'] = true; 2001 } 2002 2003 if (!$this->ok) { 2004 return; 2005 } 2006 2007 // parse body 2008 $this->output['html_type'] = 'body'; 2009 if (count($this->matrix_body['parsed'])) { 2010 foreach ($this->matrix_body['parsed'] as $this->matrix_line => $this->m) { 2011 if(!$this->defined_in_status() || !$this->defined_in_qfdbtype()) { 2012 continue; 2013 } 2014 $this->m['object'] = str_replace('/', 'sl', $this->m['object']); 2015 $this->make_db_alias(); 2016 $this->make_value(); 2017 eval("qfdbobj_{$this->m['object']}::obj_debug(\$this);"); 2018 eval("qfdbobj_{$this->m['object']}::obj_html(\$this);"); 2019 $this->make_validate(); 2020 $this->make_postval2db(); 2021 $this->qfdb_error_object_properties(); 2022 } 2023 } 2024 2025 if (!$this->ok) { 2026 return; 2027 } 2028 2029 // parse footer 2030 $this->output['html_type'] = 'footer'; 2031 if (!$this->output['html_footer_ok'] && count($this->matrix_footer['parsed'])) { 2032 foreach ($this->matrix_footer['parsed'] as $this->matrix_line => $this->m) { 2033 if(!$this->defined_in_status() || !$this->defined_in_qfdbtype()) { 2034 continue; 2035 } 2036 $this->m['object'] = str_replace('/', 'sl', $this->m['object']); 2037 eval("qfdbobj_{$this->m['object']}::obj_debug(\$this);"); 2038 eval("qfdbobj_{$this->m['object']}::obj_html(\$this);"); 2039 $this->qfdb_error_object_properties(); 2040 } 2041 $this->output['html_footer_ok'] = true; 2042 } 2043 if (!$this->ok) { 2044 return; 2045 } 2046 2047 // set the parser properties to true if finished with sucess 2048 $this->parsed = true; 2049 $this->matrix_object = ''; 2050 $this->m = array(); 2051 $this->matrix_content = ''; 2052 $this->matrix_line = -1; 2053 } // end make_html() 2054 2055 2056 2057 /** 2058 * Execute QFDB Objects in DB Mode 2059 * 2060 * @since: 0.1 2061 * @param: void 2062 * @return: void 2063 * @access: private 2064 * @see: quickformdb::action() 2065 * @see: quickformdb::make_html() 2066 * @see: quickformdb::get_db_value() 2067 * @see: quickformdb::make_db_sucess() 2068 * @see: quickformdb::make_db_insertl() 2069 * @see: quickformdb::make_db_update() 2070 */ 2071 private function make_db() 2072 { 2073 // apenas usada no parser 2074 $this->matrix_content = ''; 2075 2076 if (!$this->db['connect_id']) { 2077 $this->add_critical_error( sprintf(QFDBE_CORE_DB_CONNECTID_NOT_EXISTS.$this->make_error_ref('QFDBE_CORE_DB_CONNECTID_NOT_EXISTS'), $this->status) ); 2078 } 2079 2080 if (!$this->db['table']) { 2081 $this->add_critical_error( sprintf(QFDBE_CORE_DBTABLE_NOT_DEFINED.$this->make_error_ref('QFDBE_CORE_DBTABLE_NOT_DEFINED'), $this->status)); 2082 } 2083 2084 if (!$this->db['primary_key']) { 2085 $this->add_critical_error(QFDBE_CORE_DBPRIMARYKEY_NOT_DEFINED.$this->make_error_ref('QFDBE_CORE_DBPRIMARYKEY_NOT_DEFINED')); 2086 } 2087 if ($this->status == 4 && !$this->db['id']) { 2088 $this->add_critical_error(QFDBE_CORE_DBID_NOT_DEFINED.$this->make_error_ref('QFDBE_CORE_DBID_NOT_DEFINED')); 2089 } 2090 2091 if (!$this->ok) { 2092 return; 2093 } 2094 2095 // run in matrix end process QFDB objects 2096 $this->output['html_type'] = 'body'; 2097 foreach ($this->matrix_body['parsed'] as $this->matrix_line => $this->m) { 2098 if(!$this->defined_in_status() || !$this->defined_in_qfdbtype()) { 2099 continue; 2100 } 2101 2102 $this->m['object'] = str_replace('/', 'sl', $this->m['object']); 2103 $this->make_db_alias(); 2104 $this->make_value(); 2105 eval("qfdbobj_{$this->m['object']}::obj_debug(\$this);"); 2106 eval("qfdbobj_{$this->m['object']}::obj_db(\$this);"); 2107 $this->make_validate(); 2108 $this->make_postval2db(); 2109 if (!$this->ok) { 2110 return; 2111 } 2112 } 2113 2114 if (!$this->ok) { 2115 return; 2116 } 2117 2118 // parse header 2119 if (!$this->output['html_header_ok'] && count($this->matrix_header['parsed'])) { 2120 $this->output['html_type'] = 'header'; 2121 foreach ($this->matrix_header['parsed'] as $this->matrix_line => $this->m) { 2122 if(!$this->defined_in_status() || !$this->defined_in_qfdbtype()) { 2123 continue; 2124 } 2125 $this->m['object'] = str_replace('/', 'sl', $this->m['object']); 2126 eval("qfdbobj_{$this->m['object']}::obj_debug(\$this);"); 2127 eval("qfdbobj_{$this->m['object']}::obj_db(\$this);"); 2128 $this->qfdb_error_object_properties(); 2129 } 2130 $this->output['html_header_ok'] = true; 2131 } 2132 2133 if (!$this->ok) { 2134 return; 2135 } 2136 2137 // parse footer 2138 $this->output['html_type'] = 'footer'; 2139 if (!$this->output['html_footer_ok'] && count($this->matrix_footer['parsed'])) { 2140 foreach ($this->matrix_footer['parsed'] as $this->matrix_line => $this->m) { 2141 if(!$this->defined_in_status() || !$this->defined_in_qfdbtype()) { 2142 continue; 2143 } 2144 $this->m['object'] = str_replace('/', 'sl', $this->m['object']); 2145 eval("qfdbobj_{$this->m['object']}::obj_debug(\$this);"); 2146 eval("qfdbobj_{$this->m['object']}::obj_db(\$this);"); 2147 $this->qfdb_error_object_properties(); 2148 } 2149 $this->output['html_footer_ok'] = true; 2150 } 2151 } // end make_db() 2152 2153 2154 2155 /** 2156 * Get DB Value of register in DB Table with ID=$this->db['id'] if $this->status==3 2157 * 2158 * @since: 0.2 2159 * @param: void 2160 * @return: void 2161 * @access: private 2162 * @see: quickformdb::dbval_rescue 2163 * @see: quickformdb::make_db() 2164 */ 2165 private function get_db_values() 2166 { 2167 $fields = ''; 2168 foreach ($this->matrix_body['parsed'] as $key => $value) { 2169 if (!isset($value['db_field']) || !isset($value['form_field']) || strlen($value['form_field'])<1 || strlen(