/** * Creates a fake recordset from the given columns associative array * This function is called on error or for the insert default values. * @param array $fakeArr The associative array * @return object resource Recordset resource * @access protected */ function getFakeRecordset($fakeArr) { tNG_log::log('tNG' . $this->transactionType, "getFakeRecordset"); $fakeRs = new KT_FakeRecordset($this->connection); $KT_fakeRs = $fakeRs->getFakeRecordset($fakeArr); if ($fakeRs->hasError) { tNG_log::log('KT_ERROR'); $this->setError(new tNG_error('FIELDS_FAKE_RS_ERROR', array(), array($fakeRs->getError()))); $disp = $this->getDispatcher(); die($disp->getErrorMsg()); } return $KT_fakeRs; }
/** * Main class method. return array of values/columns * @param string primary key table from slave table * @param string idx for multiple transactions * @param string pk name from many to many table * @param object recordeset reference * @return array * @access public */ function Execute($fk, $cnt1, $pkName, &$rs) { $arr = $this->arrFields; if (is_resource($rs)) { mysql_data_seek($rs, 0); $totalRows = mysql_num_rows($rs); $row = mysql_fetch_assoc($rs); } else { $rs->MoveFirst(); $row = $rs->fields; $totalRows = $rs->RecordCount(); } foreach ($row as $k => $v) { if (!isset($arr[$k])) { $arr[$k][0] = ''; } } $arrFields = $arr; for ($i = 0; $i < $totalRows; $i++) { $id = $this->getColValue($row, $fk); reset($arr); foreach ($arr as $k => $v) { if ($k != $pkName) { $name = $this->reference . '_' . $k . '_' . $id; } else { $name = $this->reference . '_' . $id; } if ($cnt1 > 0) { $name .= '_' . $cnt1; } $arrFields[$k][$i] = $arr[$k][0]; if (isset($_POST[$name])) { $arrFields[$k][$i] = $_POST[$name]; } else { if ($this->getColValue($row, $pkName) != '' || $arr[$k][0] == '') { $arrFields[$k][$i] = $this->getColValue($row, $k); } } if (isset($this->arrTypes[$k]) && $this->arrTypes[$k] == 'DATE_TYPE' && ($this->getColValue($row, $k) == '' || isset($_POST[$name]))) { $arrFields[$k][$i] = KT_formatDate2DB($arrFields[$k][$i]); } } // move next row; if (is_resource($rs)) { $row = mysql_fetch_assoc($rs); } else { $rs->MoveNext(); $row = $rs; } } $obj = new KT_FakeRecordset($this->conn); return $obj->getFakeRecordset($arrFields); }
/** * 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; }
/** * Creates a fake recordset from the given columns associative array * This function is called ONLY on error * @param array $fakeArr The associative array (it has multiple rows) * @return object resource Recordset resource * @access private */ function getFakeRecordset($fakeArr) { tNG_log::log('tNG' . $this->transactionType, "getFakeRecordset"); $localFakeArr = array(); $i = 0; foreach ($fakeArr as $fakeKey => $fakeA) { foreach ($fakeA as $key => $value) { if (!isset($localFakeArr[$key])) { $localFakeArr[$key] = array(); } $localFakeArr[$key][$i] = $value; } $i++; } $fakeRs = new KT_FakeRecordset($this->connection); $KT_fakeRs = $fakeRs->getFakeRecordset($localFakeArr); if ($fakeRs->hasError) { tNG_log::log('KT_ERROR'); $this->setError(new tNG_error('MULTIPLE_FAKE_RS_ERROR', array(), array($fakeRs->getError()))); $disp = $this->getDispatcher(); die($disp->getErrorMsg()); } return $KT_fakeRs; }