/** * execute method of the class; check if master record exists and return null or error; * @param none * @return mix null or error object if records don't exists * @access public */ function Execute() { $this->errorIfExists(false); $err = parent::Execute(); if ($err != NULL) { $useSavedData = false; if (in_array($this->tNG->transactionType, array('_delete', '_multipleDelete'))) { $useSavedData = true; } $this->errorMsg = KT_DynamicData($this->errorMsg, $this->tNG, '', $useSavedData); $err = new tNG_error('TRIGGER_MESSAGE__CHECK_MASTER_RECORD', array(), array()); if ($this->fkField != '') { // set field error to $this->errorMsg $err->setFieldError($this->fkField, '%s', array($this->errorMsg)); if ($this->tNG->columns[$this->fkField]['method'] != 'POST') { // set composed message as user error $err->addDetails('%s', array($this->errorMsg), array('')); } } else { // set composed message as user error $err->addDetails('%s', array($this->errorMsg), array('')); } } return $err; }
/** * Prepares the custom SQL query to be executed * @access protected */ function prepareSQL() { tNG_log::log('tNG_custom', 'prepareSQL', 'begin'); parent::prepareSQL(); $sql = KT_DynamicData($this->sql, $this, "SQL"); $this->setSQL($sql); tNG_log::log('tNG_custom', 'prepareSQL', 'end'); return null; }
function Collapsible($id, $title, $file, $options = array()) { $title = KT_DynamicData($title, null, ''); $file = KT_DynamicData($file, null, ''); $this->id = $id; $this->title = $title; $this->file_name = $file; $this->options = $GLOBALS['Widgets.Collapsible.default_options']; $this->options = array_merge($this->options, $options); }
function editForId($pkvalue, $fieldvalue) { $pkvalue = KT_DynamicData($pkvalue, null, ''); if (is_null($fieldvalue) || $fieldvalue == '') { if ($this->isEnabled) { $fieldvalue = $GLOBALS['Widgets.EditInPlace.default_options']['empty']; } } $content = '' . '<div class="editinplace" id="editinplace_' . $this->id . '_' . $pkvalue . '">' . $fieldvalue . '</div>'; if ($this->isEnabled) { $content .= '<script type="text/javascript">' . 'var editinplace_' . $this->id . '_' . $pkvalue . ' =' . ' new Widgets.EditInPlace("' . addslashes($this->id) . '", ' . '"' . addslashes($pkvalue) . '", ' . KT_json($this->options) . ');' . '</script>'; } return $content; }
function renderForId($index, $currentRating) { $index = KT_DynamicData($index, null, ''); $content = ''; $this->currentRating = intval($currentRating); if ($this->currentRating == null) { $this->currentRating = 0; } for ($i = 0; $i < 5; $i++) { $content .= '<a href="#' . ($i + 1) . '" title="' . $this->options['titles'][$i] . '">' . '<img src="' . $this->relPath . 'includes/jaxon/widgets/rating/img/' . $this->getRateClass($i + 1, $index) . '.gif" style="border:0px;" alt="' . $this->options['titles'][$i] . '"/>' . '</a>'; } $content = ' <div class="rater" id="rating_' . $this->id . '_' . $index . '">' . $content . '</div><script type="text/javascript">var rating_' . $this->id . '_' . $index . ' = new Widgets.Rating("' . addslashes($this->id) . '", "' . addslashes($index) . '", ' . KT_json($this->options) . ', "' . md5($this->id . $this->config['table'] . $this->config['primaryKey'] . $this->config['ratingField'] . $index) . '");</script>'; return $content; }
/** * Main method of the class. make the redirect * @return nothing * @access public */ function Execute() { if (!isset($this->tNG)) { $page = KT_DynamicData($this->URL, null, 'rawurlencode'); } else { $useSavedData = false; if ($this->tNG->getTransactionType() == '_delete' || $this->tNG->getTransactionType() == '_multipleDelete') { $useSavedData = true; } $page = KT_DynamicData($this->URL, $this->tNG, 'rawurlencode', $useSavedData); } if ($this->keepUrlParams) { foreach ($_GET as $param => $value) { $page = KT_addReplaceParam($page, $param, $value); } } KT_redir($page); }
/** * execute method of the class; check if detail record exists and return null or error; * @param none * @return mix null or error object if records exists; * @access public */ function Execute() { $this->setFieldType($this->tNG->getColumnType($this->tNG->getPrimaryKey())); $this->setFieldValue($this->tNG->getPrimaryKeyValue()); $this->errorIfExists(true); $err = parent::Execute(); if ($err != NULL) { // change the default error message $useSavedData = false; if (in_array($this->tNG->transactionType, array('_delete', '_multipleDelete'))) { $useSavedData = true; } $this->errorMsg = KT_DynamicData($this->errorMsg, $this->tNG, '', $useSavedData); // set only user message $err = new tNG_error('TRIGGER_MESSAGE__CHECK_DETAIL_RECORD', array(), array()); $err->addDetails('%s', array($this->errorMsg), array('')); } return $err; }
/** * Setter. Sets the information for one comparison * @param string field 1 * @param string field 2 * @param string operation * @param string error message * @access public */ function addField($name1, $name2, $operation, $error) { $value1 = $this->tNG->getColumnValue($name1); $value2 = KT_DynamicData($name2, null); if ($value2 == $name2) { $value2 = KT_DynamicData($name2, $this->tNG); } if ($this->tNG->getColumnType($name1) == 'DATE_TYPE') { $value1 = KT_convertDate($value1, $GLOBALS['KT_db_date_format'] . ' ' . $GLOBALS['KT_db_time_format_internal'], "yyyy-mm-dd HH:ii:ss"); $value2 = KT_convertDate($value2, $GLOBALS['KT_db_date_format'] . ' ' . $GLOBALS['KT_db_time_format_internal'], "yyyy-mm-dd HH:ii:ss"); $value1 = strtotime($value1); $value2 = strtotime($value2); } else { if ($this->tNG->getColumnType($name1) == 'NUMERIC_TYPE' || $this->tNG->getColumnType($name1) == 'DOUBLE_TYPE') { $value1 = (double) $value1; $value2 = (double) $value2; } } $this->fields[] = array('0' => array('name' => $name1, 'value' => $value1, 'type' => $this->tNG->getColumnType($name1)), '1' => array('name' => $name2, 'value' => $value2, 'type' => $this->tNG->getColumnType($name1)), 'operation' => $operation, 'error' => KT_DynamicData($error, $this->tNG)); }
function setMetaSource($path) { $this->metaSource = KT_DynamicData($path, null); }
/** * This function checks to see if a file is within the specified folder. * * @param dynamicBaseFolder The folder from which the base folder is computed. * @param dynamicFileName The name of the file for which to check. * * @return True or false whether the file is or is not in the base folder. * */ function tNG_isFileInsideBaseFolder($dynamicBaseFolder, $dynamicFileName) { $baseFolder = tNG_getBaseFolder($dynamicBaseFolder); $folder = KT_realPath(KT_DynamicData($dynamicBaseFolder, null)); $fileName = KT_DynamicData($dynamicFileName, null); $absPath = KT_realPath($folder . $fileName, false); if (substr($absPath, 0, strlen($baseFolder)) === $baseFolder) { return true; } return false; }
function addTab($title, $file) { $title = KT_DynamicData($title, null, ''); $file = KT_DynamicData($file, null, ''); array_push($this->tabs, array('title' => $title, 'file' => $file)); }
/** * Setter. Sets a column name, type and default value * @param string * @param string * @param string * @access public */ function addField($colName, $type, $default = '') { $this->arrFields[$colName] = array(KT_DynamicData($default, null)); $this->arrTypes[$colName] = $type; }
/** * Adds a column to the transaction * @see $columns * @param string $colName The column name * @param string $type The column type (NUMERIC_TYPE, STRING_TYPE, etc) * @param string $method The request method (GET, POST, FILE, COOKIE, SESSION) * @param string $reference The submitted variable name (if method=GET and reference=test, value=$_GET['test']) * @access public */ function addColumn($colName, $type, $method, $reference) { if ($this->started && ($method != 'VALUE' && $method != 'EXPRESSION')) { die("You can only add supplemental columns by value or by expression once the transaction is started."); } if (!isset($this->columns[$colName])) { $this->columns[$colName] = array(); } $this->columns[$colName]['type'] = $type; $this->columns[$colName]['method'] = $method; $this->columns[$colName]['reference'] = $reference; if ($method == 'VALUE') { $this->columns[$colName]['value'] = $reference; } if ($method == 'EXPRESSION') { $this->columns[$colName]['method'] = "VALUE"; $this->columns[$colName]['reference'] = KT_DynamicData($reference, $this, '', $this->getTransactionType() == "_delete"); if ($type == "NUMERIC_TYPE" || $type == "DOUBLE_TYPE") { $this->columns[$colName]['reference'] = $this->evaluateNumeric($this->columns[$colName]['reference']); } } if ($this->started) { tNG_prepareValues($this->columns[$colName]); } }
/** * contruct the SQL and execute it. it is using as value for the field the primarey key value from the transaction; * return mix null or error object; * @access public */ function Execute() { $pk_value = $this->tNG->getPrimaryKeyValue(); $pk_type = $this->tNG->getColumnType($this->tNG->getPrimaryKey()); $pk_value = KT_escapeForSql($pk_value, $pk_type); if (count($this->fileRenameRule) > 0 || count($this->folderRenameRule) > 0) { $sql = 'SELECT * FROM ' . $this->table . ' WHERE ' . KT_escapeFieldName($this->field) . " = " . $pk_value; $rs = $this->tNG->connection->Execute($sql); if ($rs === false) { return new tNG_error('DEL_DR_SQL_ERROR', array(), array($this->tNG->connection->ErrorMsg(), $sql)); } if ($rs->RecordCount() == 0) { return null; } } // prepare to delete files if (count($this->fileRenameRule) > 0) { $fullFileName = array(); $fullFileNameFolder = array(); for ($i = 0; $i < count($this->fileRenameRule); $i++) { while (!$rs->EOF) { $arr = array(); foreach ($rs->fields as $col => $value) { $arr[$col] = $value; } $folder = $this->fileFolder[$i]; $fileName = KT_DynamicData($this->fileRenameRule[$i], $this->tNG, '', false, $arr); // security if (substr(KT_realpath($folder . $fileName), 0, strlen($folder)) != $folder) { $baseFileName = dirname(KT_realpath($folder . $fileName, false)); $ret = new tNG_error("FOLDER_DEL_SECURITY_ERROR", array(), array($baseFileName, $folder)); return $ret; } $fullFileName[] = $fileName; $fullFileNameFolder[] = $folder; $rs->MoveNext(); } $rs->MoveFirst(); } } // prepare to delete related folders if (count($this->folderRenameRule) > 0) { $relatedFolder = array(); for ($i = 0; $i < count($this->folderRenameRule); $i++) { while (!$rs->EOF) { $arr = array(); foreach ($rs->fields as $col => $value) { $arr[$col] = $value; } $folder = $this->folder[$i]; $f = KT_DynamicData($this->folderRenameRule[$i], $this->tNG, '', false, $arr); // security if (substr(KT_realpath($folder . $f), 0, strlen($folder)) != $folder) { $baseFileName = dirname(KT_realpath($folder . $f, false)); $ret = new tNG_error("FOLDER_DEL_SECURITY_ERROR", array(), array($baseFileName, $folder)); return $ret; } $relatedFolder[] = $folder . $f; $rs->MoveNext(); } $rs->MoveFirst(); } } // delete reocords $sql = "DELETE FROM " . $this->table . " WHERE " . KT_escapeFieldName($this->field) . " = " . $pk_value; $ret = $this->tNG->connection->Execute($sql); if ($ret === false) { return new tNG_error('DEL_DR_SQL_ERROR', array(), array($this->tNG->connection->ErrorMsg(), $sql)); } // delete files if (count($this->fileRenameRule) > 0) { for ($i = 0; $i < count($fullFileName); $i++) { if (file_exists($fullFileNameFolder[$i] . $fullFileName[$i])) { $delRet = @unlink($fullFileNameFolder[$i] . $fullFileName[$i]); $path_info = KT_pathinfo($fullFileNameFolder[$i] . $fullFileName[$i]); $this->deleteThumbnails($path_info['dirname'] . '/thumbnails/', $path_info['basename']); } } } // delete related folder if (count($this->folderRenameRule) > 0) { for ($i = 0; $i < count($relatedFolder); $i++) { $folder = new KT_Folder(); // delete thumbnails $folder->deleteFolderNR($relatedFolder[$i]); } } return null; }
/** * setter. set the error message * @param string error message * @return nothing * @access public */ function setErrorMsg($err1, $err2) { if ($GLOBALS['tNG_debug_mode'] == 'DEVELOPMENT') { $this->errorMsg = KT_DynamicData($err2, $this->tNG, '', false); } else { $this->errorMsg = KT_DynamicData($err1, $this->tNG, '', false); } }
/** * Executes the registered triggers that matches the specified type * @param string $triggerType (STARTER, AFTER, BEFORE, ERROR and END) * @access protected */ function executeTriggers($triggerType) { if (isset($this->triggers[$triggerType]) && is_array($this->triggers[$triggerType])) { uasort($this->triggers[$triggerType], array('tNG', 'compareTriggers')); foreach ($this->triggers[$triggerType] as $key => $trigger) { $run = KT_DynamicData($trigger[0], $this, 'expression'); $runTrigger = false; $ok = false; @eval('$runTrigger = (' . $run . ');$ok = true;'); if ($ok !== true) { die('Internal Error.Invalid boolean expression: ' . $run); } if ($runTrigger) { $callBackFunction = $trigger[1]; $tempParam = array_reverse($trigger[3]); $tempParam[] =& $this; $tempParam = array_reverse($tempParam, true); tNG_log::log($triggerType, $callBackFunction, 'begin'); if (is_string($callBackFunction) && function_exists($callBackFunction)) { $ret = call_user_func_array($callBackFunction, $tempParam); } else { die('Internal Error. Trigger "' . $callBackFunction . '" does not exist.'); } // call all triggers for ERROR and STARTER tiggers if ($triggerType != "ERROR") { if (is_object($ret)) { tNG_log::log('KT_ERROR'); tNG_log::log($triggerType, $callBackFunction, 'end'); return $ret; } } tNG_log::log($triggerType, $callBackFunction, 'end'); } } } return null; }
/** * Main method of the class. Execute the code * Return the error object with the error message in it and set the field error message on the field from transaction if the field was set in the class; * @return object error * @access public */ function Execute() { $useSavedData = false; if (in_array($this->tNG->transactionType, array('_delete', '_multipleDelete'))) { $useSavedData = true; } $this->errorMsg = KT_DynamicData($this->errorMsg, $this->tNG, '', $useSavedData); $this->fieldErrorMsg = KT_DynamicData($this->fieldErrorMsg, $this->tNG, '', $useSavedData); $err = new tNG_error('%s', array($this->errorMsg), array('')); if (isset($this->tNG->columns[$this->field])) { // set field error to $this->errorMsg $err->setFieldError($this->field, '%s', array($this->fieldErrorMsg)); if ($this->tNG->columns[$this->field]['method'] != 'POST') { // set composed message as user error $err->addDetails('%s', array($this->fieldErrorMsg), array('')); } } else { // set composed message as user error $err->addDetails('%s', array($this->fieldErrorMsg), array('')); } return $err; }
/** * sets the title, meta description and keywords * @param string $title * @param string $description * @param string $keywords * @return null */ function setMetaInfo($title, $description, $keywords) { $this->title = KT_DynamicData($title, null, null, false, array(), false); $this->description = KT_DynamicData($description, null, null, false, array(), false); $this->keywords = KT_DynamicData($keywords, null, null, false, array(), false); }
/** NAME: Execute DESCRIPTION: validates the columnsValue based on regExp and required information ARGUMENTS: none - property used: $columns $columnsValue RETURN: string - empty on succes , an error message if fails property changed: - none **/ function Execute() { $failed = false; $errObj = new tNG_error('', array(), array()); if ($this->mustValidate && count($this->columns) > 0) { $columnKeys = array_keys($this->columns); $cols = count($columnKeys); for ($i = 0; $i < $cols; $i++) { $doRequiredVal = true; $colIdx = $columnKeys[$i]; $column =& $this->columns[$colIdx]; if (!in_array($column['name'], array_keys($this->tNG->columns))) { continue; } // on update don't require FILE_TYPE and tNG password fields if ($this->tNG->getTransactionType() == '_update' || $this->tNG->getTransactionType() == '_multipleUpdate') { if ($this->tNG->getColumnType($column['name']) == 'FILE_TYPE') { $doRequiredVal = false; } if ($this->tNG->getTable() == $GLOBALS['tNG_login_config']["table"] && $column['name'] == $GLOBALS['tNG_login_config']["password_field"]) { $doRequiredVal = false; } // if it is setted to CURRVAL is not required; if ($this->tNG->columns[$column['name']]['method'] == 'CURRVAL') { $doRequiredVal = false; } } $hasRequiredError = false; $hasTypeError = false; $tmpFieldValue = $this->tNG->getColumnValue($column['name']); if ($column['type'] == 'date' && $column['format'] != '') { if (!in_array($this->tNG->getColumnType($column['name']), array('DATE_TYPE', 'DATE_ACCESS_TYPE'))) { $tmpFieldValue = KT_formatDate2DB($tmpFieldValue); } } $column['failed'] = false; // required parameter validation $colCustomMsg = $column['message']; if ($doRequiredVal && $column['required']) { if (strlen($colCustomMsg) == 0) { $colCustomMsg = $this->genericValidationMessages['required']; } if ((string) $tmpFieldValue == '') { $failed = true; $hasRequiredError = true; $column['failed'] = true; if ($this->tNG->exportsRecordset() !== true) { $colCustomMsg = KT_DynamicData($colCustomMsg, $this->tNG, '', $this->tNG->transactionType == '_delete'); $errObj->addDetails('%s', array($colCustomMsg), array($colCustomMsg)); } else { $errObj->setFieldError($column['name'], '%s', array($colCustomMsg)); } } } // type and format validation $colCustomMsg = $column['message']; if ($tmpFieldValue != '' && $column['type'] != '') { if (strlen($colCustomMsg) == 0) { $colCustomMsgBefore = $this->genericValidationMessages['format']; $colCustomMsgAfter = $this->genericValidationMessages[$column['type'] . '_' . $column['format']]; $colCustomMsg = sprintf($colCustomMsgBefore, $colCustomMsgAfter); } $tmpFieldValue = substr($tmpFieldValue, 0, 400); switch ($column['type']) { case 'regexp': $res = @preg_match($column['additional_params'], $tmpFieldValue); if ($res === false) { $hasTypeError = true; $colCustomMsgBefore = $this->genericValidationMessages['format']; $colCustomMsgAfter = $this->genericValidationMessages['regexp_failed']; $colCustomMsg = sprintf($colCustomMsgBefore, $colCustomMsgAfter); } if ($res === 0) { $hasTypeError = true; } break; case 'mask': $myRegexp = $this->mask2regexp($column['additional_params']); if (!preg_match($myRegexp, $tmpFieldValue)) { $hasTypeError = true; } break; case 'text': case 'numeric': case 'double': $type = $column['type']; $format = $column['format']; if (is_array($this->validationRules[$type][$format])) { $myValidationRule =& $this->validationRules[$type][$format]; if (isset($myValidationRule['mask'])) { $myRegexp = $this->mask2regexp($myValidationRule['mask']); $myValidationRule['regexp'] = $myRegexp; } if (isset($myValidationRule['regexp'])) { if (!preg_match($myValidationRule['regexp'], $tmpFieldValue)) { $hasTypeError = true; } } if (isset($myValidationRule['callback'])) { $ret = call_user_func(array('tNG_FormValidation', $myValidationRule['callback']), $tmpFieldValue); if (!$ret) { $hasTypeError = true; } } } break; case 'date': $format = $column['format']; $checkFullDateTime = true; switch ($format) { case 'date': $inFmtRule = KT_format2rule($GLOBALS['KT_db_date_format']); $checkFullDateTime = true; break; case 'time': $inFmtRule = KT_format2rule($GLOBALS['KT_db_time_format_internal']); $checkFullDateTime = false; break; case 'datetime': $inFmtRule = KT_format2rule($GLOBALS['KT_db_date_format'] . ' ' . $GLOBALS['KT_db_time_format_internal']); $checkFullDateTime = true; break; default: break 2; } $dateArr = KT_applyDate2rule($tmpFieldValue, $inFmtRule); $ret = KT_isValidDate($dateArr, $checkFullDateTime); if (!$ret) { $hasTypeError = true; } break; } } if (!$hasRequiredError && $hasTypeError) { $column['failed'] = true; $failed = true; if ($this->tNG->exportsRecordset() !== true) { $colCustomMsg = KT_DynamicData($colCustomMsg, $this->tNG, '', $this->tNG->transactionType == '_delete'); $errObj->addDetails('%s', array($colCustomMsg), array($colCustomMsg)); } else { $errObj->setFieldError($column['name'], '%s', array($colCustomMsg)); } } } for ($i = 0; $i < $cols; $i++) { $colIdx = $columnKeys[$i]; $column =& $this->columns[$colIdx]; if (!in_array($column['name'], array_keys($this->tNG->columns))) { continue; } $hasMinMaxError = false; $tmpFieldValue = $this->tNG->getColumnValue($column['name']); if ($column['type'] == 'date' && $column['format'] != '') { if (!in_array($this->tNG->getColumnType($column['name']), array('DATE_TYPE', 'DATE_ACCESS_TYPE'))) { $tmpFieldValue = KT_formatDate2DB($tmpFieldValue); } } // MIN MAX parameter validation $tNG_tNGfield_min = array(); $tNG_tNGfield_max = array(); $min = $column['min']; $min_placeholders = KT_getReplacementsFromMessage($min); if (count($min_placeholders) > 0) { foreach ($min_placeholders as $key => $placeholder) { if (strpos($placeholder, '.') === false) { $tNG_tNGfield_min[] = $placeholder; } } } $max = $column['max']; $max_placeholders = KT_getReplacementsFromMessage($max); if (count($max_placeholders) > 0) { foreach ($max_placeholders as $key => $placeholder) { if (strpos($placeholder, '.') === false) { $tNG_tNGfield_max[] = $placeholder; } } } $min = KT_DynamicData($min, $this->tNG); $max = KT_DynamicData($max, $this->tNG); // MIN parameter validation if ($tmpFieldValue != '' && $min != '') { if ($column['type'] == 'text') { if (strlen($tmpFieldValue) < $min) { $hasMinMaxError = true; } } if (in_array($column['type'], array('numeric', 'double'))) { $evaluateNumeric = true; if (count($tNG_tNGfield_min) > 0) { foreach ($tNG_tNGfield_min as $key => $tNG_tNGfield) { if (!isset($this->columns[$tNG_tNGfield]) || !in_array($this->columns[$tNG_tNGfield]['type'], array('numeric', 'double')) || $this->columns[$tNG_tNGfield]['format'] == '' || $column['failed']) { $evaluateNumeric = false; break; } } } $tmpFieldValue = str_replace(',', '.', $tmpFieldValue); $min = str_replace(',', '.', $min); if ($evaluateNumeric) { $min = $this->tNG->evaluateNumeric($min); } if (floatval($tmpFieldValue) < floatval($min)) { $hasMinMaxError = true; } } if ($column['type'] == 'date') { if (count($tNG_tNGfield_min) > 0) { foreach ($tNG_tNGfield_min as $key => $tNG_tNGfield) { if (in_array($this->tNG->getColumnType($tNG_tNGfield), array('DATE_TYPE', 'DATE_ACCESS_TYPE'))) { $min = KT_formatDate($min); break; } } } $minDate = KT_formatDate2DB($min); $format = $column['format']; $checkFullDateTime = true; switch ($format) { case 'date': $inFmtRule = KT_format2rule($GLOBALS['KT_db_date_format']); $checkFullDateTime = true; break; case 'time': $inFmtRule = KT_format2rule($GLOBALS['KT_db_time_format_internal']); $checkFullDateTime = false; break; case 'datetime': $inFmtRule = KT_format2rule($GLOBALS['KT_db_date_format'] . ' ' . $GLOBALS['KT_db_time_format_internal']); $checkFullDateTime = true; break; default: break 2; } $dateArr = KT_applyDate2rule($tmpFieldValue, $inFmtRule); $minArr = KT_applyDate2rule($minDate, $inFmtRule); if (KT_isValidDate($minArr, $checkFullDateTime)) { if (KT_compareDates($dateArr, $minArr) === 1) { $hasMinMaxError = true; } } } } // MAX parameter validation if ($tmpFieldValue != '' && $max != '') { if ($column['type'] == 'text') { if (strlen($tmpFieldValue) > $max) { $hasMinMaxError = true; } } if (in_array($column['type'], array('numeric', 'double'))) { $evaluateNumeric = true; if (count($tNG_tNGfield_max) > 0) { foreach ($tNG_tNGfield_max as $key => $tNG_tNGfield) { if (!isset($this->columns[$tNG_tNGfield]) || !in_array($this->columns[$tNG_tNGfield]['type'], array('numeric', 'double')) || $this->columns[$tNG_tNGfield]['format'] == '' || $column['failed']) { $evaluateNumeric = false; break; } } } $tmpFieldValue = str_replace(',', '.', $tmpFieldValue); $max = str_replace(',', '.', $max); if ($evaluateNumeric) { $max = $this->tNG->evaluateNumeric($max); } if (floatval($tmpFieldValue) > floatval($max)) { $hasMinMaxError = true; } } if ($column['type'] == 'date') { if (count($tNG_tNGfield_max) > 0) { foreach ($tNG_tNGfield_max as $key => $tNG_tNGfield) { if (in_array($this->tNG->getColumnType($tNG_tNGfield), array('DATE_TYPE', 'DATE_ACCESS_TYPE'))) { $max = KT_formatDate($max); break; } } } $maxDate = KT_formatDate2DB($max); $format = $column['format']; $checkFullDateTime = true; switch ($format) { case 'date': $inFmtRule = KT_format2rule($GLOBALS['KT_db_date_format']); $checkFullDateTime = true; break; case 'time': $inFmtRule = KT_format2rule($GLOBALS['KT_db_time_format_internal']); $checkFullDateTime = false; break; case 'datetime': $inFmtRule = KT_format2rule($GLOBALS['KT_db_date_format'] . ' ' . $GLOBALS['KT_db_time_format_internal']); $checkFullDateTime = true; break; default: break 2; } $dateArr = KT_applyDate2rule($tmpFieldValue, $inFmtRule); $maxArr = KT_applyDate2rule($maxDate, $inFmtRule); if (KT_isValidDate($maxArr, $checkFullDateTime)) { if (KT_compareDates($dateArr, $maxArr) === -1) { $hasMinMaxError = true; } } } } $colCustomMsg = $column['message']; if (strlen($colCustomMsg) == 0) { $colCustomMsgBefore = $column['type'] == 'text' ? 'text' : 'other'; if ($min != '' && $max != '') { $colCustomMsgAfter = 'between'; $colCustomMsg = $this->genericValidationMessages[$colCustomMsgBefore . '_' . $colCustomMsgAfter]; $colCustomMsg = sprintf($colCustomMsg, $min, $max); } elseif ($min != '') { $colCustomMsgAfter = 'min'; $colCustomMsg = $this->genericValidationMessages[$colCustomMsgBefore . '_' . $colCustomMsgAfter]; $colCustomMsg = sprintf($colCustomMsg, $min); } else { $colCustomMsgAfter = 'max'; $colCustomMsg = $this->genericValidationMessages[$colCustomMsgBefore . '_' . $colCustomMsgAfter]; $colCustomMsg = sprintf($colCustomMsg, $max); } } if ($hasMinMaxError && $column['failed'] == false) { $column['failed'] = true; $failed = true; if ($this->tNG->exportsRecordset() !== true) { $colCustomMsg = KT_DynamicData($colCustomMsg, $this->tNG, '', $this->tNG->transactionType == '_delete'); $errObj->addDetails('%s', array($colCustomMsg), array($colCustomMsg)); } else { $errObj->setFieldError($column['name'], '%s', array($colCustomMsg)); } } } } if (!$failed) { $errObj = null; } else { if ($this->tNG->exportsRecordset() === true) { $errObj->addDetails('%s', array($this->genericValidationMessages['failed']), array('')); } } return $errObj; }
/** * set the the errror message * @param string error * @return nothing */ function setErrorMsg($errorMessage) { $this->errorMessage = KT_DynamicData($errorMessage, $this->tNG); }
/** * Prepare the hash values and store it in the session; Return the calculated link. * @return string url for download the file * @access public */ function getDownloadLink() { $this->preparedFolder = $this->folder; //security $fullFolderPath = KT_realpath($this->preparedFolder, true); $fullFilePath = KT_DynamicData($this->renameRule, null); $fullFilePath = KT_realpath($this->preparedFolder . $fullFilePath, true); if (substr($fullFilePath, 0, strlen($fullFolderPath)) != $fullFolderPath) { $this->setError(new tNG_error("FOLDER_DEL_SECURITY_ERROR", array(), array($fullFolderPath, $fullFilePath))); return $this->relPath . 'includes/tng/pub/tNG_download4.php'; } $url = ''; if (!isset($_SESSION['tng_download'])) { $_SESSION['tng_download'] = array(); } if (!isset($_SESSION['tng_download'][$this->reference])) { $_SESSION['tng_download'][$this->reference] = array(); } // sets the common values; if (!$this->isSetted) { $_SESSION['tng_download'][$this->reference]['properties'] = array(); $_SESSION['tng_download'][$this->reference]['properties']['time'] = time(); $_SESSION['tng_download'][$this->reference]['properties']['table'] = $this->table; if (isset($this->pk['field']) && isset($this->pk['type'])) { $_SESSION['tng_download'][$this->reference]['properties']['pk_c'] = array('field' => $this->pk['field'], 'type' => $this->pk['type']); } else { $_SESSION['tng_download'][$this->reference]['properties']['pk_c'] = array(); } $_SESSION['tng_download'][$this->reference]['properties']['counterField'] = $this->counterField; $_SESSION['tng_download'][$this->reference]['properties']['tableMtm'] = $this->tableMtm; if (isset($this->pkMtm['field']) && isset($this->pkMtm['type'])) { $_SESSION['tng_download'][$this->reference]['properties']['pkMtm_c'] = array('field' => $this->pkMtm['field'], 'type' => $this->pkMtm['type']); } else { $_SESSION['tng_download'][$this->reference]['properties']['pkMtm_c'] = array(); } if (isset($this->fkMtm['field']) && isset($this->fkMtm['type'])) { $_SESSION['tng_download'][$this->reference]['properties']['fkMtm_c'] = array('field' => $this->fkMtm['field'], 'type' => $this->fkMtm['type']); } else { $_SESSION['tng_download'][$this->reference]['properties']['fkMtm_c'] = array(); } $_SESSION['tng_download'][$this->reference]['properties']['counterFieldMtm'] = $this->counterFieldMtm; $_SESSION['tng_download'][$this->reference]['properties']['maxCounterFieldMtm'] = $this->maxCounterFieldMtm; $_SESSION['tng_download'][$this->reference]['properties']['maxCounterValueMtm'] = $this->maxCounterValueMtm; $_SESSION['tng_download'][$this->reference]['properties']['conn'] = $this->connName; $_SESSION['tng_download'][$this->reference]['properties']['relPath'] = $this->relPath; $_SESSION['tng_download'][$this->reference]['properties']['backUri'] = KT_getFullUri(); $_SESSION['tng_download'][$this->reference]['files'] = array(); $this->isSetted = true; } // set the class members in hash session to use in the download page; $hash = md5(uniqid("", true)); $_SESSION['tng_download'][$this->reference]['files'][$hash] = array(); $_SESSION['tng_download'][$this->reference]['files'][$hash]['folder'] = $this->preparedFolder; $_SESSION['tng_download'][$this->reference]['files'][$hash]['fileName'] = KT_DynamicData($this->renameRule, null); if (isset($this->pk['reference']) && $this->pk['reference'] != '') { $_SESSION['tng_download'][$this->reference]['files'][$hash]['pk'] = KT_DynamicData($this->pk['reference'], null); } if (isset($this->pkMtm['reference']) && $this->pkMtm['reference'] != '') { $_SESSION['tng_download'][$this->reference]['files'][$hash]['pkMtm'] = KT_DynamicData($this->pkMtm['reference'], null); } if (isset($this->fkMtm['field']) && $this->fkMtm['field'] != '' && isset($_SESSION['kt_login_id'])) { $_SESSION['tng_download'][$this->reference]['files'][$hash]['fkMtm'] = $_SESSION['kt_login_id']; } $url = $this->relPath . 'includes/tng/pub/tNG_download4.php'; $arr = array(); foreach ($_GET as $key => $val) { if (!preg_match("/^KT_download/is", $key)) { $arr[] = $key . '=' . $val; } } $url .= '?' . implode('&', $arr); $url = KT_addReplaceParam($url, $this->reference, $hash); return $url; }
/** * Method that checks if all dynamic data placeholders have been replaced. * * @param text The string containing the dynamic data placeholders. * * @returns true or false depending on whether all placeholders have been replaced. */ function isValidReplacement($text) { if (preg_match_all('/\\{([\\w\\d\\.\\s\\(\\)]+)\\}/', $text, $matches)) { if (isset($matches[1]) && is_array($matches[1])) { foreach ($matches[1] as $key => $placeholder) { $value = KT_DynamicData('{' . $placeholder . '}', $this->tNG, '', false, array(), false); if (empty($value)) { return false; } } } } return true; }
/** * setter. set the error message * @param string error message * @return nothing * @access public */ function setErrorMsg($error) { $this->errorMsg = KT_DynamicData($error, $this->tNG, '', false); }
/** * the main method, execute the code of the class; * Upload the file, set the file name in transaction; * return mix null or error object * @access public */ function Execute() { if ($this->tNG->getTransactionType() == "_import") { $this->tNG->uploadObj =& $this; } $ret = null; if ($this->dbFieldName != '') { $oldFileName = $this->tNG->getSavedValue($this->dbFieldName); $saveFileName = $this->tNG->getColumnValue($this->dbFieldName); if ($this->tNG->getColumnType($this->dbFieldName) != 'FILE_TYPE') { $errObj = new tNG_error('FILE_UPLOAD_WRONG_COLTYPE', array(), array($this->dbFieldName)); $errObj->addFieldError($this->dbFieldName, 'FILE_UPLOAD_WRONG_COLTYPE_D', array($this->dbFieldName)); return $errObj; } } else { $oldFileName = KT_DynamicData($this->renameRule, $this->tNG, '', true); if (isset($this->tNG->multipleIdx)) { $saveFileName = @$_FILES[$this->formFieldName . "_" . $this->tNG->multipleIdx]['name']; } else { $saveFileName = @$_FILES[$this->formFieldName]['name']; } } $this->dynamicFolder = KT_DynamicData($this->folder, $this->tNG, '', false); $arrArgs = array(); $autoRename = false; switch ($this->rename) { case 'auto': $autoRename = true; break; case 'none': break; case 'custom': $path_info = KT_pathinfo($saveFileName); $arrArgs = array('KT_name' => $path_info['filename'], 'KT_ext' => $path_info['extension']); $saveFileName = KT_DynamicData($this->renameRule, $this->tNG, '', false, $arrArgs); break; default: die('INTERNAL ERROR: Unknown upload rename method.'); } if (tNG_isFileInsideBaseFolder($this->folder, $saveFileName) === false) { $baseFileName = dirname(KT_realPath($this->dynamicFolder . $saveFileName, false)); return new tNG_error("FOLDER_DEL_SECURITY_ERROR", array(), array($baseFileName, tNG_getBaseFolder($this->folder))); } // Upload File $fileUpload = new KT_fileUpload(); if (isset($this->tNG->multipleIdx)) { $fileUpload->setFileInfo($this->formFieldName . "_" . $this->tNG->multipleIdx); } else { $fileUpload->setFileInfo($this->formFieldName); } $fileUpload->setFolder($this->dynamicFolder); $fileUpload->setRequired(false); $fileUpload->setAllowedExtensions($this->allowedExtensions); $fileUpload->setAutoRename($autoRename); $fileUpload->setMaxSize($this->maxSize); $this->uploadedFileName = $fileUpload->uploadFile($saveFileName, $oldFileName); $updateDB = basename($this->uploadedFileName); if ($fileUpload->hasError()) { $arrError = $fileUpload->getError(); $errObj = new tNG_error('FILE_UPLOAD_ERROR', array($arrError[0]), array($arrError[1])); if ($this->dbFieldName != '') { $errObj->addFieldError($this->dbFieldName, '%s', array($arrError[0])); } $ret = $errObj; } else { $this->dynamicFolder = KT_realpath($this->dynamicFolder); if ($this->uploadedFileName == "") { //Check if for update we need to rename file if ($this->rename == "custom") { $path_info = KT_pathinfo($oldFileName); $arrArgs['KT_ext'] = $path_info['extension']; } $tmpFileName = KT_DynamicData($this->renameRule, $this->tNG, '', false, $arrArgs); if ($tmpFileName != "" && $oldFileName != "" && $tmpFileName != $oldFileName) { if (file_exists($this->dynamicFolder . $oldFileName)) { if (@rename($this->dynamicFolder . $oldFileName, $this->dynamicFolder . $tmpFileName) === true) { $this->uploadedFileName = $tmpFileName; $updateDB = basename($this->uploadedFileName); } else { $ret = new tNG_error('FILE_UPLOAD_RENAME', array(), array($this->dynamicFolder . $oldFileName, $this->dynamicFolder . $tmpFileName)); } } } } if ($ret === null) { if ($this->tNG->getTransactionType() == "_insert" || $this->tNG->getTransactionType() == "_multipleInsert") { $this->tNG->registerTrigger('ERROR', 'Trigger_Default_RollBack', 1, $this); } $this->deleteThumbnails($this->dynamicFolder . 'thumbnails' . DIRECTORY_SEPARATOR, $oldFileName); if ($this->uploadedFileName != '') { $this->deleteThumbnails($this->dynamicFolder . 'thumbnails' . DIRECTORY_SEPARATOR, $this->uploadedFileName); } if ($this->dbFieldName != '' && $this->uploadedFileName != "") { $ret = $this->tNG->afterUpdateField($this->dbFieldName, $updateDB); } } if ($ret === null && $this->dbFieldName != "") { $this->tNG->setRawColumnValue($this->dbFieldName, $updateDB); } } $this->errObj = $ret; return $ret; }
/** * Getter. Get htmlBody. * @return string the content of the email (can have any html tags but <script>) * @access protected */ function getHtmlBody() { if ($this->format != 'text') { $text = KT_DynamicData($this->content, $this->getTng(), $this->escapeMethod, $this->getUseSavedData(), array(), false); $text = $this->removeScript($text); return KT_transformsPaths(KT_makeIncludedURL($this->file), $text, true); } else { return; } }
/** * Main class method. Resize the image and apply the watermark; * @return string error string or url to thumbnail * @access public */ function Execute() { $ret = ""; $relpath = $this->relpath; $folder = KT_TransformToUrlPath($this->folder); $fileName = KT_DynamicData($this->renameRule, null); $fileName = KT_TransformToUrlPath($fileName, false); $fullFolder = KT_realpath($folder, true); $fullFileName = KT_realpath($fullFolder . $fileName, false); $path_info = KT_pathinfo($fullFileName); $thumbnailFolder = $path_info['dirname'] . '/thumbnails/'; if (substr($fullFileName, 0, strlen($fullFolder)) != $fullFolder) { if ($GLOBALS['tNG_debug_mode'] == 'DEVELOPMENT') { $baseFileName = dirname($fullFileName); $errorMsg = KT_getResource("FOLDER_DEL_SECURITY_ERROR_D", "tNG", array($baseFileName, $fullFolder)); $ret = $relpath . "includes/tng/styles/cannot_thumbnail.gif\" />" . $errorMsg . "<img style=\"display:none\" src=\"" . $relpath . "includes/tng/styles/cannot_thumbnail.gif"; } else { $ret = $relpath . "includes/tng/styles/cannot_thumbnail.gif"; } } else { if ($this->getFileName() !== false) { // make the resize $proportional = $this->keepProportion; $width = $this->width; $height = $this->height; if (!$this->watermark) { $thumbnailName = $path_info['filename'] . '_' . $width . 'x' . $height . (isset($path_info['extension']) ? '.' . $path_info['extension'] : ''); } else { $hash = tNG_watermarkHash(KT_realpath($this->watermarkImage, false), $this->watermarkAlpha, $this->watermarkResize, $this->watermarkAlignment); $thumbnailName = $path_info['filename'] . '_' . $width . 'x' . $height . '_w_' . $hash . (isset($path_info['extension']) ? '.' . $path_info['extension'] : ''); } $thumbnailFullName = $thumbnailFolder . $thumbnailName; if (!file_exists(KT_realpath($thumbnailFullName, false))) { $imageObj = new KT_image(); $imageObj->setPreferedLib($GLOBALS['tNG_prefered_image_lib']); $imageObj->addCommand($GLOBALS['tNG_prefered_imagemagick_path']); $imageObj->thumbnail($fullFileName, $thumbnailFolder, $thumbnailName, (int) $width, (int) $height, $proportional); if ($imageObj->hasError()) { $errorArr = $imageObj->getError(); if ($GLOBALS['tNG_debug_mode'] == 'DEVELOPMENT') { $errMsg = $errorArr[1]; $ret = $relpath . "includes/tng/styles/cannot_thumbnail.gif\" />" . $errMsg . "<img style=\"display:none\" src=\"" . $relpath . "includes/tng/styles/cannot_thumbnail.gif"; } else { $ret = $relpath . "includes/tng/styles/cannot_thumbnail.gif"; } return $ret; } else { // apply watermark if ($this->watermark) { // delete other watermarks for same picture tNG_deleteThumbnails($thumbnailFolder, $path_info['filename'] . '_' . $width . 'x' . $height, $hash); $imageObj = new KT_image(); $imageObj->setPreferedLib($GLOBALS['tNG_prefered_image_lib']); $imageObj->addCommand($GLOBALS['tNG_prefered_imagemagick_path']); $imageObj->watermark($thumbnailFullName, $thumbnailFullName, KT_realpath($this->watermarkImage, false), $this->watermarkAlpha, $this->watermarkResize, $this->watermarkAlignment); if ($imageObj->hasError()) { @unlink($thumbnailFullName); $arrError = $imageObj->getError(); $errObj = new tNG_error('IMG_WATERMARK', array(), array($arrError[1])); if ($GLOBALS['tNG_debug_mode'] == 'DEVELOPMENT') { $errMsg = $arrError[1]; $ret = $relpath . "includes/tng/styles/cannot_thumbnail.gif\" />" . $errMsg . "<img style=\"display:none\" src=\"" . $relpath . "includes/tng/styles/cannot_thumbnail.gif"; } else { $ret = $relpath . "includes/tng/styles/cannot_thumbnail.gif"; } return $ret; } } } $thumbnailURL = $this->folder . KT_DynamicData($this->renameRule, null); $thumbnailURL = dirname($thumbnailURL) . "/thumbnails/" . $thumbnailName; $ret = KT_CanonizeRelPath($thumbnailURL); if (!$imageObj->hasError()) { //$ret .= '?' . md5(filectime($ret)); } } else { $thumbnailURL = $this->folder . KT_DynamicData($this->renameRule, null); $thumbnailURL = dirname($thumbnailURL) . "/thumbnails/" . $thumbnailName; $ret = KT_CanonizeRelPath($thumbnailURL); } } else { $ret = $relpath . "includes/tng/styles/img_not_found.gif"; } } return $ret; }
function Trigger_UpdatePassword_CheckOldPassword(&$tNG) { $password_field = $GLOBALS['tNG_login_config']['password_field']; $password_value = $tNG->getColumnValue($password_field); $old_password_value = KT_DynamicData("{POST.old_" . $password_field . "}", $tNG); if ($old_password_value != "" && $password_value == "") { $errObj = new tNG_error("UPDATEPASS_NO_NEW_PASS", array(), array()); $errObj->setFieldError($password_field, "UPDATEPASS_NO_NEW_PASS_FIELDERR", array()); return $errObj; } if ($password_value != "") { if ($GLOBALS['tNG_login_config']['password_encrypt'] == "true") { if ($old_password_value != "") { $old_password_value = tNG_encryptString($old_password_value); } } $table = $GLOBALS['tNG_login_config']['table']; $pk_field = $GLOBALS['tNG_login_config']['pk_field']; $pk_value = KT_escapeForSql($tNG->getPrimaryKeyValue(), $GLOBALS['tNG_login_config']['pk_type']); $sql = "SELECT " . KT_escapeFieldName($password_field) . " FROM " . $table . " WHERE " . KT_escapeFieldName($pk_field) . "=" . $pk_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("UPDATEPASS_NO_RECORD", array(), array()); } if ($rs->RecordCount() != 1) { return new tNG_error("UPDATEPASS_TOMANY_RECORDS", array(), array()); } $db_password_value = $rs->Fields($GLOBALS['tNG_login_config']['password_field']); if ($db_password_value != $old_password_value) { $tNG->addColumn("old_" . $password_field, "STRING_TYPE", "VALUE", ""); $errObj = new tNG_error("UPDATEPASS_WRONG_OLD_PASS", array(), array()); $errObj->setFieldError("old_" . $password_field, "UPDATEPASS_WRONG_OLD_PASS_FIELDERR", array()); return $errObj; } } return null; }
/** * Main class method. Return a fake recordset. * @var string * @access private */ function Execute() { $relFolder = KT_DynamicData($this->folder, '', '', false, array(), false); $relFolder = KT_TransformToUrlPath($relFolder, true); if (substr($relFolder, 0, 1) == '/') { $relFolder = substr($relFolder, 1); } $fullFolderPath = KT_realpath($this->baseFolder . $relFolder, true); if (substr($fullFolderPath, 0, strlen($this->baseFolder)) != $this->baseFolder) { if (isset($GLOBALS['tNG_debug_mode']) && $GLOBALS['tNG_debug_mode'] == "DEVELOPMENT") { die("Security error. The folder '" . $fullFolderPath . "' is out of base folder '" . $this->baseFolder . "'"); } else { die("Security error. Access to this folder is forbidden."); } } $this->path = $fullFolderPath; $noOfEntries = 0; $startCountEntries = $this->page * $this->recordsPerPage; $this->totalNo = 0; if (file_exists($this->path)) { //read folders $folder = new KT_folder(); $entries = $folder->readFolder($this->path, true); if ($folder->hasError()) { $err = $folder->getError(); if (isset($GLOBALS['tNG_debug_mode']) && $GLOBALS['tNG_debug_mode'] == "DEVELOPMENT") { $this->error = $err[1]; } else { $this->error = $err[0]; } } $this->filesArr = $entries['files']; $tmpFilesArr = array(); $tmpArr = array(); for ($i = 0; $i < count($this->filesArr); $i++) { $this->filesArr[$i]['fullname'] = $relFolder . $this->filesArr[$i]['name']; $path_info = KT_pathinfo($this->filesArr[$i]['name']); $this->filesArr[$i]['extension'] = $path_info['extension']; $filetime = filectime($this->path . $this->filesArr[$i]['name']); $this->filesArr[$i]['date'] = $filetime; if (in_array(strtolower($this->filesArr[$i]['extension']), $this->allowedExtensions) || in_array("*", $this->allowedExtensions)) { $tmpArr[] = $this->filesArr[$i][$this->orderField]; $tmpFilesArr[] = $this->filesArr[$i]; } } $this->filesArr = $tmpFilesArr; $this->Sort($tmpArr); $this->totalNo = count($this->filesArr); if ($this->recordsPerPage > 0) { $from = $this->page * $this->recordsPerPage; $this->filesArr = array_slice($this->filesArr, $from, $this->recordsPerPage); } for ($i = 0; $i < count($this->filesArr); $i++) { $this->filesArr[$i]['date'] = KT_convertDate(date("Y-m-d H:i:s", $this->filesArr[$i]['date']), "yyyy-mm-dd HH:ii:ss", $GLOBALS['KT_screen_date_format'] . ' ' . $GLOBALS['KT_screen_time_format_internal']); } // create fake recordset $this->filesArr = $this->formatData($this->filesArr); } $KT_FakeRecordset = new KT_FakeRecordset($this->conn); $ret = $KT_FakeRecordset->getFakeRecordset($this->filesArr); if ($ret === NULL) { if (isset($GLOBALS['tNG_debug_mode']) && $GLOBALS['tNG_debug_mode'] == "DEVELOPMENT") { die("Internal error: cannot create fake recordset. " . $KT_FakeRecordset->getError()); } else { die("Internal error: cannot create fake recordset."); } } return $ret; }
/** * Getter. Gets the link to the upload page * sets in session the neccesary info * @return string * @access public */ function getUploadLink() { if (!$this->checkSecurity()) { return ''; } $siteroot = KT_realpath($this->relPath, true); $uploadFolder = KT_realpath($this->baseFolder, true); $this->baseFolder = $this->relPath . substr($uploadFolder, strlen($siteroot)); $url = ''; if (!isset($_SESSION['tng_upload'])) { $_SESSION['tng_upload'] = array(); } $this->noOfCalls++; if ($this->noOfCalls == 1) { $this->garbageCollector(); if (!isset($_POST[$this->reference . '_' . $this->noOfCalls]) || !isset($_SESSION['tng_upload'][$this->reference]['files'])) { $_SESSION['tng_upload'][$this->reference] = array(); $_SESSION['tng_upload'][$this->reference]['properties'] = array(); $_SESSION['tng_upload'][$this->reference]['properties']['maxSize'] = $this->maxSize; $_SESSION['tng_upload'][$this->reference]['properties']['maxFiles'] = $this->maxFiles; $_SESSION['tng_upload'][$this->reference]['properties']['allowedExtensions'] = $this->allowedExtensions; $_SESSION['tng_upload'][$this->reference]['properties']['relPath'] = $this->relPath; $_SESSION['tng_upload'][$this->reference]['properties']['connName'] = $this->connName; $_SESSION['tng_upload'][$this->reference]['properties']['time'] = time(); $_SESSION['tng_upload'][$this->reference]['files'] = array(); } if (isset($_SESSION['tng_upload'][$this->reference]['files'])) { $tmpArr = array(); for ($i = 1; $i <= count($_SESSION['tng_upload'][$this->reference]['files']); $i++) { if ($_SESSION['tng_upload'][$this->reference]['files'][$i] !== null) { $tmpArr[count($tmpArr) + 1] = $_SESSION['tng_upload'][$this->reference]['files'][$i]; } } $_SESSION['tng_upload'][$this->reference]['files'] = $tmpArr; } } $pk = KT_DynamicData($this->pkRenameRule, null); if ($pk == $this->pkRenameRule) { $pk = ''; } if (!isset($_POST[$this->reference . '_' . $this->noOfCalls]) || !isset($_SESSION['tng_upload'][$this->reference]['files'][$this->noOfCalls])) { $_SESSION['tng_upload'][$this->reference]['files'][$this->noOfCalls] = array(); if ($pk == '') { $_SESSION['tng_upload'][$this->reference]['files'][$this->noOfCalls]['pk'] = str_replace('.', '_', uniqid("", true)); if ($this->noOfCalls == 1) { $_SESSION['tng_upload'][$this->reference]['properties']['pkRule'] = $this->pk; $_SESSION['tng_upload'][$this->reference]['properties']['folderRule'] = $this->baseFolder . $this->folder; } } else { $_SESSION['tng_upload'][$this->reference]['files'][$this->noOfCalls]['pk'] = $pk; } $_SESSION['tng_upload'][$this->reference]['files'][$this->noOfCalls]['folder'] = str_replace('{' . $this->pk . '}', $_SESSION['tng_upload'][$this->reference]['files'][$this->noOfCalls]['pk'], $this->baseFolder . $this->folder); } $url = $this->relPath . 'includes/tng/pub/multiple_upload.php'; $url = KT_addReplaceParam($url, $this->reference, $this->noOfCalls); return $url; }
/** * execute method of the class; check if record exists and return null or error; * @param none * @return mix null or error object if record exists * @access public */ function Execute() { $where = array(); $i = 0; foreach ($this->field as $field) { if ($i++ == 0) { $first = $field; } $type = $this->tNG->getColumnType($field); $value = $this->tNG->getColumnValue($field); $where[] = KT_escapeFieldName($field) . " = " . KT_escapeForSql($value, $type); } $sql = "SELECT * FROM " . $this->table . " WHERE " . implode(' AND ', $where); if (in_array($this->tNG->transactionType, array('_update', '_multipleUpdate'))) { $pk = $this->tNG->getPrimaryKey(); $pk_value = $this->tNG->getPrimaryKeyValue(); $pk_type = $this->tNG->getColumnType($this->tNG->getPrimaryKey()); $pk_value = KT_escapeForSql($pk_value, $pk_type); $sql .= " AND " . $pk . " <> " . $pk_value; } $ret = $this->tNG->connection->Execute($sql); if ($ret === false) { return new tNG_error('CHECK_TF_SQL_ERROR', array(), array($this->tNG->connection->ErrorMsg(), $sql)); } if (!$ret->EOF) { $useSavedData = false; if (in_array($this->tNG->transactionType, array('_delete', '_multipleDelete'))) { $useSavedData = true; } $this->errorMsg = KT_DynamicData($this->errorMsg, $this->tNG, '', $useSavedData); if ($GLOBALS['tNG_debug_mode'] == 'DEVELOPMENT') { $err = new tNG_error('TRIGGER_MESSAGE__CHECK_UNIQUE', array(implode(', ', $this->field)), array()); } else { $err = new tNG_error('%s', array($this->errorMsg), array()); } if (count($this->field) == 1 && isset($this->tNG->columns[$this->field[$first]])) { // set field error to $this->errorMsg $err->setFieldError($this->field[$first], '%s', array($this->errorMsg)); if ($this->tNG->columns[$this->field[$first]]['method'] != 'POST') { // set composed message as user error $err->addDetails('%s', array($this->errorMsg), array('')); } } else { // set composed message as user error $err->addDetails('%s', array($this->errorMsg), array('')); } return $err; } return null; }