/** * Executes all sub-transactions * @param none * @access protected */ function prepareSQL() { tNG_log::log('tNG_multipleDelete', 'prepareSQL', 'begin'); $failed = false; $ret = null; for ($i = 1; true; $i++) { $tmp = KT_getRealValue("POST", $this->pkName . "_" . $i); if (!isset($tmp)) { break; } $this->multTNGs[$i - 1] = new tNG_delete($this->connection); $this->multTNGs[$i - 1]->setDispatcher($this->dispatcher); $this->multTNGs[$i - 1]->multipleIdx = $i; // register triggers $this->multTNGs[$i - 1]->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "VALUE", true); for ($j = 0; $j < sizeof($this->multTriggers); $j++) { call_user_func_array(array(&$this->multTNGs[$i - 1], "registerConditionalTrigger"), $this->multTriggers[$j]); } // add columns $this->multTNGs[$i - 1]->setTable($this->table); foreach ($this->columns as $colName => $colDetails) { $this->multTNGs[$i - 1]->addColumn($colName, $colDetails['type'], $colDetails['method'], $colDetails['reference'] . "_" . $i); } $this->multTNGs[$i - 1]->setPrimaryKey($this->primaryKey, $this->primaryKeyColumn['type'], "POST", $this->pkName . "_" . $i); $this->multTNGs[$i - 1]->executeTransaction(); if ($this->multTNGs[$i - 1]->getError()) { $failed = true; } } if ($failed) { $ret = new tNG_error('MDEL_ERROR', array(), array()); } tNG_log::log('tNG_multipleDelete', 'prepareSQL', 'end'); return $ret; }
function Trigger_Activation_Check(&$tNG) { if ($GLOBALS['tNG_login_config']['activation_field'] == "") { return new tNG_error("ACTIVATION_NOT_ENABLED", array(), array()); } if ($GLOBALS['tNG_login_config']['email_field'] == "") { return new tNG_error("ACTIVATION_NO_EMAIL", array(), array()); } if ($tNG->getTable() != $GLOBALS['tNG_login_config']['table']) { return new tNG_error("ACTIVATION_WRONG_TABLE", array(), array()); } if ($tNG->getPrimaryKey() != $GLOBALS['tNG_login_config']['pk_field']) { return new tNG_error("ACTIVATION_WRONG_PK", array(), array()); } if (!isset($tNG->columns[$GLOBALS['tNG_login_config']['activation_field']])) { return new tNG_error("ACTIVATION_NO_ACTIVE_FIELD", array(), array()); } // build the sql string to check if ($GLOBALS['tNG_login_config']['randomkey_field'] != "") { $random_key = KT_getRealValue("GET", "kt_login_random"); if ($random_key == "") { return new tNG_error("ACTIVATION_NO_PARAM_RANDOM", array(), array()); } $random_key = KT_escapeForSql($random_key, "STRING_TYPE"); $pk_value = KT_escapeForSql($tNG->getPrimaryKeyValue(), $GLOBALS['tNG_login_config']['pk_type']); $sql = "SELECT " . KT_escapeFieldName($tNG->getPrimaryKey()) . ", " . KT_escapeFieldName($GLOBALS['tNG_login_config']['activation_field']) . " FROM " . $tNG->getTable() . " WHERE " . KT_escapeFieldName($tNG->getPrimaryKey()) . "=" . $pk_value . " AND " . KT_escapeFieldName($GLOBALS['tNG_login_config']['randomkey_field']) . "=" . $random_key; $rs = $tNG->connection->Execute($sql); if (!is_object($rs)) { return new tNG_error("LOGIN_RECORDSET_ERR", array(), array()); } } else { $email_value = KT_getRealValue("GET", "kt_login_email"); if ($email_value == "") { return new tNG_error("ACTIVATION_NO_PARAM_EMAIL", array(), array()); } $email_value = KT_escapeForSql($email_value, "STRING_TYPE"); $pk_value = KT_escapeForSql($tNG->getPrimaryKeyValue(), $GLOBALS['tNG_login_config']['pk_type']); $sql = "SELECT " . KT_escapeFieldName($tNG->getPrimaryKey()) . ", " . KT_escapeFieldName($GLOBALS['tNG_login_config']['activation_field']) . " FROM " . $tNG->getTable() . " WHERE " . KT_escapeFieldName($tNG->getPrimaryKey()) . "=" . $pk_value . " AND " . KT_escapeFieldName($GLOBALS['tNG_login_config']['email_field']) . "=" . $email_value; $rs = $tNG->connection->Execute($sql); if (!is_object($rs)) { return new tNG_error("LOGIN_RECORDSET_ERR", array(), array()); } } if ($rs->RecordCount() == 0) { return new tNG_error("ACTIVATION_NO_RECORDS", array(), array()); } if ($rs->RecordCount() != 1) { return new tNG_error("ACTIVATION_TOOMANY_RECORDS", array(), array()); } // check for inactive if ($rs->Fields($GLOBALS['tNG_login_config']['activation_field']) != 0) { return new tNG_error("ACTIVATION_ALREADY_ACTIVE", array(), array()); } // register the AFTER trigger $tNG->registerTrigger("AFTER", "Trigger_Activation_Login", -1); return null; }
function handleAjaxRequest() { if (isset($_GET['AjaxServiceCall'])) { $this->checkServiceCall(); //get object / method from variables $object = $_GET['ServiceObject']; if ($object == '') { $object = null; } $method = $_GET['ServiceMethod']; $params = array(); foreach ($_GET as $k => $v) { if (preg_match("/^params_\\d{1,2}\$/", $k)) { array_push($params, KT_getRealValue("GET", $k)); } } foreach ($_POST as $k => $v) { array_push($params, KT_getRealValue("POST", $k)); } $params = array_values($params); $m = $this->findServiceCall($object, $method); if ($m['object']) { $toret = call_user_func_array(array(&$GLOBALS[$m['object']], $m['method']), $params); } else { $toret = call_user_func_array($m['method'], $params); } // do not cache AJAX Requests $seconds_expire = -86400; //one day ago KT_sendExpireHeader($seconds_expire); $isOpera = false; if (isset($_SERVER) && isset($_SERVER['HTTP_USER_AGENT'])) { if (stristr($_SERVER['HTTP_USER_AGENT'], 'opera/9.')) { $isOpera = true; } } if (isset($_SERVER['HTTP_KT_CHARSET'])) { header('Content-Type: text/' . (!$isOpera ? 'jaxon' : 'plain') . '; charset=' . $_SERVER['HTTP_KT_CHARSET']); } else { header('Content-Type: text/' . (!$isOpera ? 'jaxon' : 'plain') . ''); } echo KT_json($toret); die; } }
/** * Function KT_DynamicData replace all the dynamic data with their values; * @param string $expression The expression to be evaluated * @param object or null $tNG The tNG context in which the expression is evaluated * @param string $escapeMethod The string escape method for the evaluated values (rawurlencode and SQL) * @param booolean $useSavedData Weather to use the current tNG data or the saved values * @param array $extraParams Extra expression parameters passed when for evaluation (of form $key => $value; any encounter of key will be replaced with its value) * @return string the string with the dynamic data replaced with their values; */ function KT_DynamicData($expression, $tNG, $escapeMethod = '', $useSavedData = false, $extraParams = array(), $errorIfNotFound = true) { $PB = '{'; $PE = '}'; if (!is_string($expression)) { return $expression; } // DynamicData functions - use this to define more functions KT_getInternalTimeFormat(); $date_now = KT_convertDate(date('Y-m-d'), "yyyy-mm-dd", $GLOBALS['KT_screen_date_format']); $date_dt_now = KT_convertDate(date('Y-m-d H:i:s'), "yyyy-mm-dd HH:ii:ss", $GLOBALS['KT_screen_date_format'] . ' ' . $GLOBALS['KT_screen_time_format_internal']); $date_t_now = KT_convertDate(date('H:i:s'), "HH:ii:ss", $GLOBALS['KT_screen_time_format_internal']); $dynamicDataFunctions = array('NOW()' => $date_now, 'now()' => $date_now, 'NOW' => $date_now, 'now' => $date_now, 'NOW_DT()' => $date_dt_now, 'now_dt()' => $date_dt_now, 'NOW_DT' => $date_dt_now, 'now_dt' => $date_dt_now, 'NOW_T()' => $date_t_now, 'now_t()' => $date_t_now, 'NOW_T' => $date_t_now, 'now_t' => $date_t_now, 'KT_REFERRER' => isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '', 'kt_referrer' => isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '', 'KT_CSV_LINE' => isset($GLOBALS['KT_CSV_LINE']) ? $GLOBALS['KT_CSV_LINE'] : '', 'KT_XML_LINE' => isset($GLOBALS['KT_XML_LINE']) ? $GLOBALS['KT_XML_LINE'] : ''); $placeholdersArr = KT_getReplacementsFromMessage($expression); $replacementsArr = array(); switch ($escapeMethod) { case 'rawurlencode': break; case 'expression': break; case 'SQL': if (!isset($tNG)) { $escapeMethod = false; } break; default: $escapeMethod = false; break; } if ($useSavedData !== true) { $useSavedData = false; } foreach ($placeholdersArr as $key => $placeholder) { if (array_key_exists($placeholder, $extraParams)) { // extra params have priority 1 $placeholderType = 'tng_ddextra'; $placeholderName = $placeholder; } else { // functions have priority 2 if (array_key_exists($placeholder, $dynamicDataFunctions)) { $placeholderType = 'tNG_DDfunction'; $placeholderName = $placeholder; } else { $ptpos = strpos($placeholder, '.'); if (!$ptpos) { // tng field if (isset($tNG)) { // attached to a tng, replace field with value $placeholderType = 'tNG_tNGfield'; $placeholderName = $placeholder; } else { // no tng, leave as is $placeholderType = 'tNG_tNGfieldLater'; $placeholderName = $placeholder; } } else { $placeholderType = substr($placeholder, 0, $ptpos); $placeholderName = substr($placeholder, $ptpos + 1); } } } $placeholder = $PB . $placeholder . $PE; switch (strtolower($placeholderType)) { case 'tng_ddfunction': $replacementsArr[$placeholder] = $dynamicDataFunctions[$placeholderName]; break; case 'tng_ddextra': $replacementsArr[$placeholder] = $extraParams[$placeholderName]; break; case 'tng_tngfield': if ($useSavedData) { $placeholderValue = $tNG->getSavedValue($placeholderName); } else { if (isset($tNG->columns[$placeholderName]) || $placeholderName == $tNG->getPrimaryKey()) { $placeholderValue = $tNG->getColumnValue($placeholderName); $placeholderType = $tNG->getColumnType($placeholderName); } else { if ($errorIfNotFound == true) { die('KT_DynamicData:<br />Column ' . $placeholderName . ' is not part of the current transaction.'); } else { $placeholderValue = $placeholder; } } if ($escapeMethod == 'SQL') { $placeholderValue = KT_escapeForSql($placeholderValue, $placeholderType); } } $replacementsArr[$placeholder] = $placeholderValue; break; case 'tng_tngfieldlater': break; case 'get': $myPlaceholderName = $placeholderName; if (isset($tNG)) { if (isset($tNG->multipleIdx)) { $myPlaceholderName .= "_" . $tNG->multipleIdx; } } $replacementsArr[$placeholder] = KT_getRealValue("GET", $myPlaceholderName); if (!isset($replacementsArr[$placeholder])) { $replacementsArr[$placeholder] = KT_getRealValue("GET", $placeholderName); } break; case 'post': $myPlaceholderName = $placeholderName; if (isset($tNG)) { if (isset($tNG->multipleIdx)) { $myPlaceholderName .= "_" . $tNG->multipleIdx; } } $replacementsArr[$placeholder] = KT_getRealValue("POST", $myPlaceholderName); if (!isset($replacementsArr[$placeholder])) { $replacementsArr[$placeholder] = KT_getRealValue("POST", $placeholderName); } break; case 'cookie': $replacementsArr[$placeholder] = KT_getRealValue("COOKIE", $placeholderName); break; case 'session': KT_session_start(); $replacementsArr[$placeholder] = KT_getRealValue("SESSION", $placeholderName); break; case 'globals': $replacementsArr[$placeholder] = KT_getRealValue("GLOBALS", $placeholderName); break; case 'request': $replacementsArr[$placeholder] = KT_getRealValue("GLOBALS", $placeholderName); break; case 'server': $replacementsArr[$placeholder] = KT_getRealValue("SERVER", $placeholderName); break; case 'application': // CF only break; case 'csv': $replacementsArr[$placeholder] = KT_getRealValue("CSV", $placeholderName); break; default: // recordset if (isset($GLOBALS[$placeholderType])) { $rs = $GLOBALS[$placeholderType]; if (is_resource($rs)) { $placeholderValue = $GLOBALS["row_" . $placeholderType][$placeholderName]; } elseif (is_object($rs)) { $placeholderValue = $rs->Fields($placeholderName); } else { break; } } else { $placeholderValue = $placeholder; } $replacementsArr[$placeholder] = $placeholderValue; break; } } reset($replacementsArr); if ($escapeMethod == 'rawurlencode') { if (!array_key_exists("{kt_login_redirect}", $replacementsArr) && !array_key_exists("{kt_referrer}", $replacementsArr) && !array_key_exists("{KT_REFERRER}", $replacementsArr)) { $replacementsArr = array_map($escapeMethod, $replacementsArr); } } elseif ($escapeMethod == 'expression') { $replacementsArr = array_map('KT_escapeExpression', $replacementsArr); } $newexpression = str_replace(array_keys($replacementsArr), array_values($replacementsArr), $expression); /*if ($escapeMethod == 'expression') { echo $newexpression."\n<br/>\n"; }*/ return $newexpression; }
function checkBoundries() { if (isset($_GET['KT_az'])) { $cond = KT_getRealValue("GET", "KT_az"); $do_redirect = false; if ($this->linkRenderType != 2) { if (!in_array($cond, $this->arrLetters)) { $do_redirect = true; } } else { $allowed = range('A', 'Z'); if ($this->useNumbers) { $allowed[] = "0_9"; } $allowed[] = "other"; $allowed[] = "all"; if (!in_array($cond, $allowed)) { $do_redirect = true; } } if ($do_redirect) { $KT_url = KT_getFullUri(); $KT_url = KT_addReplaceParam($KT_url, 'KT_az'); KT_redir($KT_url); } } }
/** * Sets the value for a specific column * @param array &$colDetails column details (one element of the $column array) * @access private */ function tNG_prepareValues(&$colDetails) { $type2alt = array('CHECKBOX_1_0_TYPE' => '1', 'CHECKBOX_-1_0_TYPE' => '-1', 'CHECKBOX_YN_TYPE' => "Y", 'CHECKBOX_TF_TYPE' => "t"); if (isset($colDetails['method']) && isset($colDetails['reference']) && isset($colDetails['type'])) { $colValue = KT_getRealValue($colDetails['method'], $colDetails['reference']); if ($colDetails['method'] == 'VALUE') { $colValue = KT_DynamicData($colValue, null); if (isset($colDetails['default'])) { $colDetails['default'] = $colValue; } } elseif (isset($colDetails['default'])) { $colDetails['default'] = KT_DynamicData($colDetails['default'], null); } switch ($colDetails['type']) { case 'CHECKBOX_YN_TYPE': case 'CHECKBOX_1_0_TYPE': case 'CHECKBOX_-1_0_TYPE': case 'CHECKBOX_TF_TYPE': $colValue = !isset($colValue) ? '' : $type2alt[$colDetails['type']]; break; case 'DATE_TYPE': case 'DATE_ACCESS_TYPE': $colValue = KT_formatDate2DB($colValue); if (isset($colDetails['default'])) { $colDetails['default'] = KT_formatDate2DB($colDetails['default']); } break; } } else { $colValue = ""; } $colDetails['value'] = $colValue; }
/** * 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', 'MAXTRIES', 'ACCOUNT_EXPIRE'); $info_key = KT_getRealValue("GET", "info"); if ($info_key != "") { if (in_array($info_key, $info_resources)) { $ret = '<div id="KT_tngdeverror">'; $ret .= '<label>' . KT_getResource('LOGIN_MESSAGE_LABEL', 'tNG') . '</label>'; $ret .= '<div>' . KT_getResource('LOGIN_MESSAGE__' . $info_key, 'tNG') . '</div>'; $ret .= '</div>'; return $ret; } } } return ''; }
/** * set the form field value * @param string method of the form (post / get) * @param string field name * @return nothing */ function setFormField($method, $reference) { $this->fieldValue = KT_getRealValue($method, $reference); }
/** * execute and calculate the filter condition and store in a local variable * if no filter was submited, then the condition is 1=1; * @return nothing; * @access public */ function prepareFilter() { if (isset($_GET['show_filter_' . $this->listName])) { $this->filterVisible = true; } if (isset($_GET[$this->listName])) { foreach ($this->columns as $colname => $colDetails) { $value = trim(KT_getRealValue("GET", $this->listName . '_' . $colname)); if ($value != '') { $this->filter[$colname] = $value; } } } $condition = ''; if (count($this->filter) > 0) { foreach ($this->filter as $colname => $value) { if ($condition != '') { $condition .= " AND "; } $compareType = $this->columns[$colname]['compare_type']; $type = $this->columns[$colname]['type']; switch ($type) { case 'NUMERIC_TYPE': case 'DOUBLE_TYPE': // if decimal separator is , => . $value = str_replace(',', '.', $value); if (preg_match('/^(<|>|=|<=|>=|=<|=>|<>|!=)\\s?-?\\d*\\.?\\d+$/', $value, $matches)) { $modifier = trim($matches[1]); if ($modifier == '!=') { $modifier = '<>'; } $value = trim(substr($value, strlen($modifier))); $condition .= KT_escapeFieldName($colname) . ' ' . $modifier . ' ' . $value; } else { $condition .= KT_escapeFieldName($colname) . ' ' . $compareType . ' ' . KT_escapeForSql($value, $type); } break; case 'CHECKBOX_1_0_TYPE': case 'CHECKBOX_-1_0_TYPE': if (preg_match('/^[<>]{1}\\s?-?\\d*\\.?\\d+$/', $value)) { $condition .= KT_escapeFieldName($colname) . $value; } else { $condition .= KT_escapeFieldName($colname) . " = " . KT_escapeForSql($value, $type); } break; case 'DATE_TYPE': case 'DATE_ACCESS_TYPE': $localCond = $this->prepareDateCondition($colname, $this->columns[$colname], $value); if ($localCond != '') { $condition .= $localCond; } break; default: switch ($compareType) { case '=': break; case 'A%': $value = $value . '%'; $compareType = 'LIKE'; break; case '%A': $value = '%' . $value; $compareType = 'LIKE'; break; default: $value = '%' . $value . '%'; $compareType = 'LIKE'; break; } $value = KT_escapeForSql($value, $type); $condition .= KT_escapeFieldName($colname) . ' ' . $compareType . ' ' . $value; break; } } // end foreach if ($condition != '') { $this->filterCalculated = $condition; } $this->filterCalculated = str_replace("%", "%%", $this->filterCalculated); } }
*/ require_once dirname(realpath(__FILE__)) . '/WDG.php'; $WDG_sessInsTest =& $_SESSION['WDG_sessInsTest']; $vars = $WDG_sessInsTest[$_GET['id']]; require_once dirname(realpath(__FILE__)) . '/../../Connections/' . $vars['conn'] . '.php'; $KT_conn = ${$vars['conn']}; $KT_conndb = ${'database_' . $vars['conn']}; // mysql adodb abstraction layer if (is_resource($KT_conn)) { $conn = new KT_Connection($KT_conn, $KT_conndb); } else { $conn =& $KT_conn; } KT_setDbType($conn); $el = KT_getRealValue('GET', 'el'); $text = KT_getRealValue('GET', 'text'); $sql = 'INSERT INTO ' . $vars['table'] . ' (' . KT_escapeFieldName($vars['updatefield']) . ') VALUES (' . KT_escapeForSql($text, 'STRING_TYPE') . ')'; $conn->Execute($sql); $ERROR = $conn->ErrorMsg(); $sql = 'SELECT ' . KT_escapeFieldName($vars['idfield']) . ' AS id FROM ' . $vars['table'] . ' WHERE ' . KT_escapeFieldName($vars['updatefield']) . ' = ' . KT_escapeForSql($text, 'STRING_TYPE'); $rsName = $vars['rsName']; ${$rsName} = $conn->Execute($sql); ${'row_' . $rsName} = ${$rsName}->fields; $text = KT_escapeJS($text); //JSRecordset($rsName); ?> <html><body onLoad="parent.MXW_DynamicObject_reportDone('<?php echo $el; ?> ', isError)"> <?php
function checkBoundries() { if (isset($_GET[$this->getVarName])) { $needle = KT_getRealValue("GET", $this->getVarName); if (!in_array($needle, $this->arrCategory)) { $KT_url = KT_getFullUri(); $KT_url = KT_addReplaceParam($KT_url, $this->getVarName); KT_redir($KT_url); } } }
/** * Starter for the download operation. Check if we have a download * @return boolean true if we have a download to serve; * @access public */ function isDownload() { $downloadID = KT_getRealValue('GET', $this->reference); if (!isset($downloadID)) { return null; } if (!isset($_SESSION['tng_download'][$this->reference])) { return null; } if (!isset($_SESSION['tng_download'][$this->reference]['files'][$downloadID])) { return null; } // initialize the class members from Hash Session; $this->downloadHash = $_SESSION['tng_download'][$this->reference]['files'][$downloadID]; $this->table = $_SESSION['tng_download'][$this->reference]['properties']['table']; $this->pk = $_SESSION['tng_download'][$this->reference]['properties']['pk_c']; $this->counterField = $_SESSION['tng_download'][$this->reference]['properties']['counterField']; $this->tableMtm = $_SESSION['tng_download'][$this->reference]['properties']['tableMtm']; $this->pkMtm = $_SESSION['tng_download'][$this->reference]['properties']['pkMtm_c']; $this->fkMtm = $_SESSION['tng_download'][$this->reference]['properties']['fkMtm_c']; $this->counterFieldMtm = $_SESSION['tng_download'][$this->reference]['properties']['counterFieldMtm']; $this->maxCounterFieldMtm = $_SESSION['tng_download'][$this->reference]['properties']['maxCounterFieldMtm']; $this->maxCounterValueMtm = $_SESSION['tng_download'][$this->reference]['properties']['maxCounterValueMtm']; if ($_SESSION['tng_download'][$this->reference]['properties']['conn'] != '') { require_once dirname(__FILE__) . '/../../../Connections/' . $_SESSION['tng_download'][$this->reference]['properties']['conn'] . '.php'; $this->conn = ${$_SESSION}['tng_download'][$this->reference]['properties']['conn']; if (is_resource($this->conn)) { $database = 'database_' . $_SESSION['tng_download'][$this->reference]['properties']['conn']; $this->conn = new KT_connection(${$_SESSION}['tng_download'][$this->reference]['properties']['conn'], ${$database}); } } $this->relPath = $_SESSION['tng_download'][$this->reference]['properties']['relPath']; $this->backUri = $_SESSION['tng_download'][$this->reference]['properties']['backUri']; return true; }
/** * Sets the column details corresponding to its method and current transaction index * @param array $colDetails Column details (one element of the $column array) * @param integer $tNGindex The current transaction's index * @return array $colDetails * @access private */ function computeMultipleValues($colDetails, $tNGindex) { if ($colDetails['method'] == 'VALUE') { $reference = $colDetails['reference']; $value = KT_getRealValue($colDetails['method'], $colDetails['reference']); } elseif ($colDetails['method'] == $this->importType) { $value = KT_getRealValue($colDetails['method'], $this->headers[$colDetails['reference']]); $reference = $this->headers[$colDetails['reference']]; } else { $reference = $colDetails['reference'] . '_' . $tNGindex; $value = KT_getRealValue($colDetails['method'], $colDetails['reference'] . '_' . $tNGindex); if (!isset($value)) { $reference = $colDetails['reference']; $value = KT_getRealValue($colDetails['method'], $colDetails['reference']); } } $colDetails['value'] = $value; $colDetails['reference'] = $reference; return $colDetails; }
/** * Get the local recordset associated to this transaction * @return object resource Recordset resource * @access public */ function getLocalRecordset() { tNG_log::log('tNG_update', 'getLocalRecordset'); $sql = ''; $tmpArr = $this->columns; $tmpArr[$this->primaryKey]['type'] = $this->primaryKeyColumn['type']; $tmpArr[$this->primaryKey]['method'] = $this->primaryKeyColumn['method']; $tmpArr[$this->primaryKey]['reference'] = $this->primaryKeyColumn['reference']; foreach ($tmpArr as $colName => $colDetails) { if ($sql != '') { $sql .= ','; } $sql .= KT_escapeFieldName($colName); } $sql .= ', ' . KT_escapeFieldName($this->primaryKey) . ' as ' . KT_escapeFieldName($this->pkName); $sql = 'SELECT ' . $sql . ' FROM ' . $this->table; $sql = $sql . ' WHERE ' . KT_escapeFieldName($this->primaryKey) . ' ='; $pkValue = KT_getRealValue($this->primaryKeyColumn['method'], $this->primaryKeyColumn['reference']); $sql = $sql . KT_escapeForSql($pkValue, $this->primaryKeyColumn['type']); if (isset($this->connection->servermodel)) { $rs = $this->connection->MySQL_Execute($sql); } else { $rs = $this->connection->Execute($sql); } if (!$rs) { tNG_log::log('KT_ERROR'); $this->setError(new tNG_error('UPD_RS', array(), array($this->connection->ErrorMsg(), $sql))); echo $this->dispatcher->getErrorMsg(); exit; } return $rs; }
/** * Get the local recordset associated to this transaction * @return object resource Recordset resource * @access protected */ function getLocalRecordset() { tNG_log::log('tNG_multipleUpdate', 'getLocalRecordset'); $sql = ''; $tmpArr = $this->columns; $tmpArr[$this->primaryKey]['type'] = $this->primaryKeyColumn['type']; $tmpArr[$this->primaryKey]['method'] = $this->primaryKeyColumn['method']; $tmpArr[$this->primaryKey]['reference'] = $this->primaryKeyColumn['reference']; foreach ($tmpArr as $colName => $colDetails) { if ($sql != '') { $sql .= ','; } $sql .= KT_escapeFieldName($colName); } $sql .= ', ' . KT_escapeFieldName($this->primaryKey) . ' as ' . KT_escapeFieldName($this->pkName); $sql = 'SELECT ' . $sql . ' FROM ' . $this->table; $tmp_colValue = KT_getRealValue($this->primaryKeyColumn['method'], $this->primaryKeyColumn['reference'] . "_1"); $pkv = KT_getRealValue($this->primaryKeyColumn['method'], $this->primaryKeyColumn['reference']); if (isset($tmp_colValue)) { $sql = $sql . ' WHERE ' . KT_escapeFieldName($this->primaryKey) . ' IN ('; $sql = $sql . KT_escapeForSql($pkv, $this->primaryKeyColumn['type']); $cnt = 1; while (true) { $tmp_colValue = KT_getRealValue($this->primaryKeyColumn['method'], $this->primaryKeyColumn['reference'] . "_" . $cnt++); if (isset($tmp_colValue)) { $sql = $sql . ", " . KT_escapeForSql($tmp_colValue, $this->primaryKeyColumn['type']); } else { break; } } $sql = $sql . ')'; } else { $sql = $sql . ' WHERE ' . KT_escapeFieldName($this->primaryKey) . '='; $sql = $sql . KT_escapeForSql($pkv, $this->primaryKeyColumn['type']); } $rs = false; if (isset($_SESSION['KT_lastUsedList']) && isset($_SESSION['sorter_tso_' . $_SESSION['KT_lastUsedList']])) { $tmp_sql = $sql . ' ORDER BY ' . $_SESSION['sorter_tso_' . $_SESSION['KT_lastUsedList']]; $table_columns = array(); if (isset($this->connection->servermodel)) { $res = $this->connection->Execute('SELECT * FROM ' . $this->table . ' LIMIT 1'); $table_columns = array_keys($res->fields); } else { $res = $this->connection->MetaColumns($this->table); foreach ($res as $field => $col) { $table_columns[] = $col->name; } } $order_column = str_replace(' DESC', '', $_SESSION['sorter_tso_' . $_SESSION['KT_lastUsedList']]); $order_column = explode('.', $order_column); $order_column = $order_column[count($order_column) - 1]; if (in_array($order_column, $table_columns)) { if (isset($this->connection->servermodel)) { $rs = $this->connection->MySQL_Execute($tmp_sql); } else { $rs = $this->connection->Execute($tmp_sql); } } } if (!$rs) { if (isset($this->connection->servermodel)) { $rs = $this->connection->MySQL_Execute($sql); } else { $rs = $this->connection->Execute($sql); } } if (!$rs) { tNG_log::log('KT_ERROR'); $this->setError(new tNG_error('MUPD_RS', array(), array($this->connection->ErrorMsg(), $sql))); echo $this->dispatcher->getErrorMsg(); exit; } return $rs; }
/** * Executes all sub-transactions * @access protected */ function prepareSQL() { tNG_log::log('tNG_multipleInsert', 'prepareSQL', 'begin'); $ret = null; $this->noSuccess = 0; $failed = false; for ($i = 1; true; $i++) { $tmp = KT_getRealValue("POST", $this->pkName . "_" . $i); if (!isset($tmp)) { break; } $this->multTNGs[$i - 1] = new tNG_insert($this->connection); $this->multTNGs[$i - 1]->setDispatcher($this->dispatcher); $this->multTNGs[$i - 1]->multipleIdx = $i; // register triggers for ($j = 0; $j < sizeof($this->multTriggers); $j++) { call_user_func_array(array(&$this->multTNGs[$i - 1], "registerConditionalTrigger"), $this->multTriggers[$j]); } // add columns $this->multTNGs[$i - 1]->setTable($this->table); foreach ($this->columns as $colName => $colDetails) { if ($colDetails['method'] == 'VALUE') { $reference = $colDetails['reference']; $value = KT_getRealValue($colDetails['method'], $colDetails['reference']); } else { $reference = $colDetails['reference'] . "_" . $i; $value = KT_getRealValue($colDetails['method'], $colDetails['reference'] . "_" . $i); if (!isset($value)) { $reference = $colDetails['reference']; $value = KT_getRealValue($colDetails['method'], $colDetails['reference']); } } $this->columns[$colName]['value'] = $value; $this->multTNGs[$i - 1]->addColumn($colName, $colDetails['type'], $colDetails['method'], $reference, $colDetails['default']); } $this->multTNGs[$i - 1]->setPrimaryKey($this->primaryKey, $this->primaryKeyColumn['type']); $this->multTNGs[$i - 1]->compileColumnsValues(); if ($this->getError()) { $this->multTNGs[$i - 1]->setError($this->getError()); } $this->multTNGs[$i - 1]->setStarted(true); $this->multTNGs[$i - 1]->doTransaction(); if ($this->multTNGs[$i - 1]->getError()) { $sw = $this->multTNGs[$i - 1]->wereValuesSubmitted(); if ($sw) { $failed = true; } else { if ($i != 1) { // if there was an unival error on one of the 2nd-to-last inserts, ignore it. $this->multTNGs[$i - 1]->setError(null); } } } else { $this->noSuccess++; $this->primaryKeyColumn['value'] = $this->multTNGs[$i - 1]->getPrimaryKeyValue(); } } if ($this->noSuccess == 0) { $failed = true; } if ($failed) { $ret = new tNG_error('MINS_ERROR', array(), array()); if ($this->executeSubSets === false) { for ($i = 0; $i < sizeof($this->multTNGs); $i++) { if (!$this->multTNGs[$i]->getError()) { $this->multTNGs[$i]->setError($ret); $this->multTNGs[$i]->executeTriggers('ERROR'); } } } } if ($this->executeSubSets === false) { $this->noSuccess = 0; } tNG_log::log('tNG_multipleInsert', 'prepareSQL', 'end'); return $ret; }