%PDF- %PDF-
Direktori : /home/pantanal/public_html/admin/includes/tng/ |
Current File : /home/pantanal/public_html/admin/includes/tng/tNG_dispatcher.class.php |
<?php /* Copyright (c) InterAKT Online 2000-2005 */ /** * The dispatcher class, that handles all the transactions in a page. * @access public */ class tNG_dispatcher { /** * The associated transactions array * @var array * @access private */ var $tNGs = array(); /** * The number of associated transactions * @var integer * @access private */ var $n = 0; var $UnivalProps = array(); /** * The relative path of the current tNG_dispathcer * @var string * @access public */ var $relPath = ""; var $UnivalCount = 0; function tNG_dispatcher($relPath) { $this->relPath = $relPath; } /** * Adds a transaction to the current dispatcher * @param object tNG &$tNG - the transaction to add * @access public */ function addTransaction(&$tNG) { $tNG->setDispatcher($this); $this->tNGs[$this->n++] = &$tNG; } /** * Gets the correct recordset from the transactions * @param string $tableName - the table to search * @return object RedourceID * the Recordset Resource ID * @access public */ function getRecordset($tableName) { $method_where = -1; $method = -1; /* -1 = unknown 1 = default values 2 = from recordset 3 = submitted values */ for ($i=0;$i<$this->n;$i++) { if ($this->tNGs[$i]->getTable() == $tableName) { switch($this->tNGs[$i]->getTransactionType()) { case '_login': case '_custom': case '_insert': case '_multipleInsert': if ($method < 1) { $method = 1; $method_where = $i; } break; case '_update': case '_multipleUpdate': $pkv = $this->tNGs[$i]->getPrimaryKeyValue(); if (isset($pkv)) { if ($method < 2) { $method = 2; $method_where = $i; } } break; } if ($this->tNGs[$i]->isStarted()) { if ($this->tNGs[$i]->exportsRecordset()) { $tmpArrErr = $this->tNGs[$i]->getErrorMsg(); if ($tmpArrErr[1] != '' || $tmpArrErr[2] != '') { $method = 3; $method_where = $i; } } } } } if ($method_where == -1) { $ret = $this->tNGs[0]->getRecordset(); //die('tNG_dispatcher.getRecordset:<br/>The transaction that handles the curent recordset is not properly configured.<br>Check the settings from the user interface that generated the code. Possible reasons for this failure: you have specified URL parameter for the Primary key column in the interface and you are running the page without any parameter or the incorect parameter.'); } else { $ret = $this->tNGs[$method_where]->getRecordset(); } return $ret; } /** * Executes the linked transactions, one by one * @access public */ function executeTransactions() { for ($i=0;$i<$this->n;$i++) { $this->tNGs[$i]->executeTransaction(); } } function displayValidationRules() { $outRules = ''; $outRules .= '<script src="'.$this->relPath.'includes/tng/scripts/FormValidation.js" type="text/javascript" language="javascript"></script>' . "\r\n"; $outRules .= '<script src="'.$this->relPath.'includes/tng/scripts/FormValidation.js.php" type="text/javascript" language="javascript"></script>' . "\r\n"; if (isset($this->UnivalProps) && is_array($this->UnivalProps) && count($this->UnivalProps) > 0) { $outRules .= '<script type="text/javascript" language="javascript">'; $univalPropKeys = array_keys($this->UnivalProps); $count = count($univalPropKeys); $sw = false; for ($i = 0; $i < $count; $i++) { $fieldName = $univalPropKeys[$i]; $field = $this->UnivalProps[$fieldName]; // get the form field name $formFieldName = $fieldName; for ($j=0;$j<$this->n;$j++) { if (isset($this->tNGs[$j]->columns[$fieldName])) { $formFieldName = $this->tNGs[$j]->columns[$fieldName]['reference']; break; } } if ($formFieldName !== '') { $outRules .= "\r\n KT_FVO['" . KT_escapeJS($formFieldName) . "'] = {"; $outRules .= "required: " . $field['required'] . ", "; $outRules .= "type: '" . $field['type'] . "', "; if ($field['format'] != '' ) { $outRules .= "format: '" . $field['format'] . "', "; } if ($field['additional_params'] != '') { $outRules .= "additional_params: '" . KT_escapeJS($field['additional_params']) . "', "; } if ($field['min'] != '' ) { $outRules .= "min: '" . $field['min'] . "', "; } if ($field['max'] != '' ) { $outRules .= "max: '" . $field['max'] . "', "; } if ($this->UnivalErrors[$fieldName] != '' ) { $outRules .= "errorMessage: '" . KT_escapeJS($this->UnivalErrors[$fieldName]) . "', "; } $outRules = substr($outRules, 0, strlen($outRules) - 2); $outRules .= "}"; } } $outRules .= "\r\n\r\n"; $outRules .= " KT_FVO_properties['noTriggers'] += " . $this->UnivalCount . ";\r\n"; $outRules .= " KT_FVO_properties['noTransactions'] += " . $this->n . ";\r\n"; $outRules .= '</script>'; } return $outRules; } function displayFieldHint($fieldName) { if (isset($this->fieldHints[$fieldName]) && $this->fieldHints[$fieldName] != '()') { return '<span class="KT_field_hint">'.$this->fieldHints[$fieldName].'</span>'."\r\n"; } } function displayFieldError($tableName, $fieldName, $cnt = 1) { $ret = ''; for ($i=0; $i<$this->n; $i++) { if ($this->tNGs[$i]->getTable() == $tableName) { if ($this->tNGs[$i]->isStarted()) { $tmp = $this->tNGs[$i]->getError(); if ($tmp) { $ret = $this->tNGs[$i]->getFieldError($fieldName, $cnt); break; } } } } if ($ret != '') { return '<br class="clearfixplain" /><div class="KT_field_error">'.$ret.'</div>'."\r\n"; } else { return ''; } } function prepareValidation(&$uniVal) { $this->UnivalCount++; if (!is_array($uniVal->columns) || count($uniVal->columns) == 0) { return; } foreach ($uniVal->columns as $columnName => $column) { // Set unival JS div errors // here we set the least restrictive required prop $required = ($column['required']===true)?'true':'false'; if (array_key_exists($columnName, $this->UnivalProps)) { if ($this->UnivalProps[$columnName]['required'] != $required) { $required = 'false'; } } $this->UnivalProps[$columnName]['required'] = $required; $this->UnivalProps[$columnName]['type'] = $column['type']; $this->UnivalProps[$columnName]['format'] = $column['format']; $this->UnivalProps[$columnName]['additional_params'] = $column['additional_params']; $this->UnivalProps[$columnName]['min'] = $column['min_cs']; $this->UnivalProps[$columnName]['max'] = $column['max_cs']; @$this->UnivalProps[$columnName]['count']++; $this->UnivalErrors[$columnName] = $column['message']; // Set field Hints if ($column['type'] == 'regexp') { $this->fieldHints[$columnName] = ''; } elseif ($column['type'] == 'mask') { $this->fieldHints[$columnName] = '(' . $column['additional_params'] . ')'; } elseif ($column['type'] == 'date' && $column['format'] != '') { $this->fieldHints[$columnName] = '(' . $uniVal->genericValidationMessages['date_' . $column['format']] . ' ' . $column['date_screen_format'] . ')'; } elseif ($column['format'] != '') { $this->fieldHints[$columnName] = '(' . $uniVal->genericValidationMessages[$column['type'] . '_' . $column['format']] . ')'; } } } function getErrorMsg() { $ret_warning = ''; $ret_user = ''; $ret_devel = ''; $errorWasFound = false; for ($i=0;$i<$this->n;$i++) { list($ret_warning, $ret_user, $ret_devel) = $this->tNGs[$i]->getErrorMsg(); if ($ret_warning!='' || $ret_user!='' || $ret_devel != '') { $errorWasFound = true; break; } } $rethead = ''; //$rethead = '<link href="' . $this->relPath . 'includes/tng/styles/default.css" rel="stylesheet" type="text/css" />' . "\r\n"; //$rethead .= '<script src="' . $this->relPath . 'includes/common/js/base.js" type="text/javascript" language="javascript"></script>' . "\r\n"; //$rethead .= '<script src="' . $this->relPath . 'includes/common/js/utility.js" type="text/javascript" language="javascript"></script>' . "\r\n"; $ret = ''; $txtContent = ""; $txtContent .= "Client IP:\r\n " . $_SERVER['REMOTE_ADDR']; $txtContent .= "\r\n\r\nHost:\r\n " . $_SERVER['HTTP_HOST']; $txtContent .= "\r\n\r\nRequested URI:\r\n " . KT_getFullUri(); $txtContent .= "\r\n\r\nDate:\r\n " . date("Y-m-d H:i:s"); if ($errorWasFound) { if ($ret_warning!='') { $ret .= '<div id="KT_tngwarning">'. $ret_warning . "</div>\r\n"; $txtContent .= "\r\n\r\nWarning:\r\n " . $ret_warning; } if ($ret_user!='') { $ret .= '<div id="KT_tngerror"><label>'.KT_getResource('ERROR_LABEL','tNG').'</label><div>' . $ret_user . '</div></div>' . "\r\n"; $txtContent .= "\r\n\r\n".KT_getResource('ERROR_LABEL','tNG')."\r\n " . $ret_user; } if ('DEVELOPMENT' == $GLOBALS['tNG_debug_mode']) { $js_err = KT_escapeJS($ret_user); $js_devNotes = KT_escapeJS($ret_devel); $js_os = PHP_OS; $js_webserver = @$_SERVER['SERVER_SOFTWARE']; $js_servermodel = (!file_exists($this->relPath . 'adodb/')? 'PHP MySQL ': 'PHP ADODB ') . phpversion(); $js_installation = KT_escapeJS(php_sapi_name()); $js_extensions = KT_escapeJS(var_export(get_loaded_extensions(),true)); $ret = $rethead . $ret; $ret .= <<<EOD <script type="text/javascript" language="javascript"> function needHelp() { if (confirm('Some data will be submitted to InterAKT. Do you want to continue?')) { var rand = Math.random().toString().substring(3, 10); var wnd = window.open('{$this->relPath}includes/tng/pub/blank.html', 'KTDebugger_' + rand, ''); try { var doc = wnd.document; } catch(e) { alert("The popup could not be opened. Please configure your pop-up blocker software to allow this."); return; } var frm = utility.dom.createElement( "FORM", { 'action': 'http://www.interaktonline.com/error/', 'method': 'POST', 'style': "display: none" }, wnd ); frm.appendChild(utility.dom.createElement('INPUT', {'type': 'hidden', 'name': 'err', 'value': '{$js_err}'}, wnd)); frm.appendChild(utility.dom.createElement('INPUT', {'type': 'hidden', 'name': 'devNotes', 'value': '{$js_devNotes}'}, wnd)); frm.appendChild(utility.dom.createElement('INPUT', {'type': 'hidden', 'name': 'os', 'value': '{$js_os}'}, wnd)); frm.appendChild(utility.dom.createElement('INPUT', {'type': 'hidden', 'name': 'webserver', 'value': '{$js_webserver}'}, wnd)); frm.appendChild(utility.dom.createElement('INPUT', {'type': 'hidden', 'name': 'servermodel', 'value': '{$js_servermodel}'}, wnd)); frm.appendChild(utility.dom.createElement('INPUT', {'type': 'hidden', 'name': 'installation', 'value': '{$js_installation}'}, wnd)); frm.appendChild(utility.dom.createElement('INPUT', {'type': 'hidden', 'name': 'extensions', 'value': '{$js_extensions}'}, wnd)); setTimeout(function() { wnd.document.body.appendChild(frm); frm.submit(); }, 5); } //return false; } </script> EOD; if ($ret_devel != '') { $ret .= '<div id="KT_tngdeverror"><label>Developer Details:</label><div>'.$ret_devel.'</div><div id="KT_needhelp"><a href="javascript:needHelp()">'.KT_getResource('ONLINE_TROUBLESHOOT','tNG').'</a></div></div>'; } $tmp = tNG_log::getResult('html'); $ret .= '<div id="KT_tngtrace"><label>tNG Execution Trace - <a href="#" onclick="document.getElementById(\'KT_tngtrace_details\').style.display=(document.getElementById(\'KT_tngtrace_details\').style.display!=\'block\'?\'block\':\'none\'); return false;">VIEW</a></label>' . $tmp . '</div>'; } if ("" != $GLOBALS['tNG_debug_log_type']) { $txtContent .= "\r\n\r\nDeveloper Details:\r\n " . $ret_devel; $tmp = tNG_log::getResult('text'); $txtContent .= "\r\n\r\ntNG Execution Trace:\r\n" . $tmp; if ($GLOBALS['tNG_debug_log_type'] == 'logfile') { // log file $logFile = dirname(realpath(__FILE__)) . "/logs/" . date("Ym") . ".log"; $f = @fopen($logFile, "a"); if ($f) { if (flock($f, LOCK_EX)) { // do an exclusive lock fwrite($f, "=== BEGIN MESSAGE ===\r\n"); fwrite($f, $txtContent); fwrite($f, "=== END MESSAGE ===\r\n"); flock($f, LOCK_UN); // release the lock } fclose($f); } } else { $email = new KT_Email(); //$email->setPriority("medium"); $email->sendEmail($GLOBALS['tNG_email_host'], $GLOBALS['tNG_email_port'], $GLOBALS['tNG_email_user'], $GLOBALS['tNG_email_password'], $GLOBALS['tNG_debug_email_from'], $GLOBALS['tNG_debug_email_to'], "", "", $GLOBALS['tNG_debug_email_subject'], "ISO-8859-1", $txtContent, ""); } } } return $ret; } /** * Returns the messages for the Login Page * @access public */ function getLoginMsg() { $show = false; for ($i=0;$i<$this->n;$i++) { if ($this->tNGs[$i]->getTransactionType() == '_login' && !$this->tNGs[$i]->started) { $show = true; break; } } if ($show) { $info_resources = array('REG_ACTIVATE', 'REG_EMAIL', 'REG', 'ACTIVATED', 'FORGOT', 'DENIED'); $info_key = KT_getRealValue("GET", "info"); if ($info_key != "") { if (in_array($info_key, $info_resources)) { $ret = '<div id="KT_tngdeverror">'; $ret .= '<label>Message:</label>'; $ret .= '<div>' . KT_getResource('LOGIN_MESSAGE__'.$info_key, 'tNG') . '</div>'; $ret .= '</div>'; return $ret; } } } return ''; } } ?>