/pma/libraries/bfShapeFiles/ShapeFile.lib.php

https://bitbucket.org/markmoskalenko/svitor · PHP · 649 lines · 544 code · 95 blank · 10 comment · 84 complexity · 3515dff542d8e86fff79447b2eb74147 MD5 · raw file

  1. <?php
  2. function loadData($type, $data) {
  3. if (!$data) return $data;
  4. $tmp = unpack($type, $data);
  5. return current($tmp);
  6. }
  7. function swap($binValue) {
  8. $result = $binValue{strlen($binValue) - 1};
  9. for($i = strlen($binValue) - 2; $i >= 0 ; $i--) {
  10. $result .= $binValue{$i};
  11. }
  12. return $result;
  13. }
  14. function packDouble($value, $mode = 'LE') {
  15. $value = (double)$value;
  16. $bin = pack("d", $value);
  17. //We test if the conversion of an integer (1) is done as LE or BE by default
  18. switch (pack ('L', 1)) {
  19. case pack ('V', 1): //Little Endian
  20. $result = ($mode == 'LE') ? $bin : swap($bin);
  21. break;
  22. case pack ('N', 1): //Big Endian
  23. $result = ($mode == 'BE') ? $bin : swap($bin);
  24. break;
  25. default: //Some other thing, we just return false
  26. $result = FALSE;
  27. }
  28. return $result;
  29. }
  30. class ShapeFile {
  31. var $FileName;
  32. var $SHPFile;
  33. var $SHXFile;
  34. var $DBFFile;
  35. var $DBFHeader;
  36. var $lastError = "";
  37. var $boundingBox = array("xmin" => 0.0, "ymin" => 0.0, "xmax" => 0.0, "ymax" => 0.0);
  38. var $fileLength = 0;
  39. var $shapeType = 0;
  40. var $records;
  41. function ShapeFile($shapeType, $boundingBox = array("xmin" => 0.0, "ymin" => 0.0, "xmax" => 0.0, "ymax" => 0.0), $FileName = NULL) {
  42. $this->shapeType = $shapeType;
  43. $this->boundingBox = $boundingBox;
  44. $this->FileName = $FileName;
  45. $this->fileLength = 50;
  46. }
  47. function loadFromFile($FileName) {
  48. $this->FileName = $FileName;
  49. if (($this->_openSHPFile()) && ($this->_openDBFFile())) {
  50. $this->_loadHeaders();
  51. $this->_loadRecords();
  52. $this->_closeSHPFile();
  53. $this->_closeDBFFile();
  54. } else {
  55. return false;
  56. }
  57. }
  58. function saveToFile($FileName = NULL) {
  59. if ($FileName != NULL) $this->FileName = $FileName;
  60. if (($this->_openSHPFile(TRUE)) && ($this->_openSHXFile(TRUE)) && ($this->_openDBFFile(TRUE))) {
  61. $this->_saveHeaders();
  62. $this->_saveRecords();
  63. $this->_closeSHPFile();
  64. $this->_closeSHXFile();
  65. $this->_closeDBFFile();
  66. } else {
  67. return false;
  68. }
  69. }
  70. function addRecord($record) {
  71. if ((isset($this->DBFHeader)) && (is_array($this->DBFHeader))) {
  72. $record->updateDBFInfo($this->DBFHeader);
  73. }
  74. $this->fileLength += ($record->getContentLength() + 4);
  75. $this->records[] = $record;
  76. $this->records[count($this->records) - 1]->recordNumber = count($this->records);
  77. return (count($this->records) - 1);
  78. }
  79. function deleteRecord($index) {
  80. if (isset($this->records[$index])) {
  81. $this->fileLength -= ($this->records[$index]->getContentLength() + 4);
  82. for ($i = $index; $i < (count($this->records) - 1); $i++) {
  83. $this->records[$i] = $this->records[$i + 1];
  84. }
  85. unset($this->records[count($this->records) - 1]);
  86. $this->_deleteRecordFromDBF($index);
  87. }
  88. }
  89. function getDBFHeader() {
  90. return $this->DBFHeader;
  91. }
  92. function setDBFHeader($header) {
  93. $this->DBFHeader = $header;
  94. for ($i = 0; $i < count($this->records); $i++) {
  95. $this->records[$i]->updateDBFInfo($header);
  96. }
  97. }
  98. function getIndexFromDBFData($field, $value) {
  99. $result = -1;
  100. for ($i = 0; $i < (count($this->records) - 1); $i++) {
  101. if (isset($this->records[$i]->DBFData[$field]) && (strtoupper($this->records[$i]->DBFData[$field]) == strtoupper($value))) {
  102. $result = $i;
  103. }
  104. }
  105. return $result;
  106. }
  107. function _loadDBFHeader() {
  108. $DBFFile = fopen(str_replace('.*', '.dbf', $this->FileName), 'r');
  109. $result = array();
  110. $buff32 = array();
  111. $i = 1;
  112. $inHeader = true;
  113. while ($inHeader) {
  114. if (!feof($DBFFile)) {
  115. $buff32 = fread($DBFFile, 32);
  116. if ($i > 1) {
  117. if (substr($buff32, 0, 1) == chr(13)) {
  118. $inHeader = false;
  119. } else {
  120. $pos = strpos(substr($buff32, 0, 10), chr(0));
  121. $pos = ($pos == 0 ? 10 : $pos);
  122. $fieldName = substr($buff32, 0, $pos);
  123. $fieldType = substr($buff32, 11, 1);
  124. $fieldLen = ord(substr($buff32, 16, 1));
  125. $fieldDec = ord(substr($buff32, 17, 1));
  126. array_push($result, array($fieldName, $fieldType, $fieldLen, $fieldDec));
  127. }
  128. }
  129. $i++;
  130. } else {
  131. $inHeader = false;
  132. }
  133. }
  134. fclose($DBFFile);
  135. return($result);
  136. }
  137. function _deleteRecordFromDBF($index) {
  138. if (@dbase_delete_record($this->DBFFile, $index)) {
  139. @dbase_pack($this->DBFFile);
  140. }
  141. }
  142. function _loadHeaders() {
  143. fseek($this->SHPFile, 24, SEEK_SET);
  144. $this->fileLength = loadData("N", fread($this->SHPFile, 4));
  145. fseek($this->SHPFile, 32, SEEK_SET);
  146. $this->shapeType = loadData("V", fread($this->SHPFile, 4));
  147. $this->boundingBox = array();
  148. $this->boundingBox["xmin"] = loadData("d", fread($this->SHPFile, 8));
  149. $this->boundingBox["ymin"] = loadData("d", fread($this->SHPFile, 8));
  150. $this->boundingBox["xmax"] = loadData("d", fread($this->SHPFile, 8));
  151. $this->boundingBox["ymax"] = loadData("d", fread($this->SHPFile, 8));
  152. $this->DBFHeader = $this->_loadDBFHeader();
  153. }
  154. function _saveHeaders() {
  155. fwrite($this->SHPFile, pack("NNNNNN", 9994, 0, 0, 0, 0, 0));
  156. fwrite($this->SHPFile, pack("N", $this->fileLength));
  157. fwrite($this->SHPFile, pack("V", 1000));
  158. fwrite($this->SHPFile, pack("V", $this->shapeType));
  159. fwrite($this->SHPFile, packDouble($this->boundingBox['xmin']));
  160. fwrite($this->SHPFile, packDouble($this->boundingBox['ymin']));
  161. fwrite($this->SHPFile, packDouble($this->boundingBox['xmax']));
  162. fwrite($this->SHPFile, packDouble($this->boundingBox['ymax']));
  163. fwrite($this->SHPFile, pack("dddd", 0, 0, 0, 0));
  164. fwrite($this->SHXFile, pack("NNNNNN", 9994, 0, 0, 0, 0, 0));
  165. fwrite($this->SHXFile, pack("N", 50 + 4*count($this->records)));
  166. fwrite($this->SHXFile, pack("V", 1000));
  167. fwrite($this->SHXFile, pack("V", $this->shapeType));
  168. fwrite($this->SHXFile, packDouble($this->boundingBox['xmin']));
  169. fwrite($this->SHXFile, packDouble($this->boundingBox['ymin']));
  170. fwrite($this->SHXFile, packDouble($this->boundingBox['xmax']));
  171. fwrite($this->SHXFile, packDouble($this->boundingBox['ymax']));
  172. fwrite($this->SHXFile, pack("dddd", 0, 0, 0, 0));
  173. }
  174. function _loadRecords() {
  175. fseek($this->SHPFile, 100);
  176. while (!feof($this->SHPFile)) {
  177. $bByte = ftell($this->SHPFile);
  178. $record = new ShapeRecord(-1);
  179. $record->loadFromFile($this->SHPFile, $this->DBFFile);
  180. $eByte = ftell($this->SHPFile);
  181. if (($eByte <= $bByte) || ($record->lastError != "")) {
  182. return false;
  183. }
  184. $this->records[] = $record;
  185. }
  186. }
  187. function _saveRecords() {
  188. if (file_exists(str_replace('.*', '.dbf', $this->FileName))) {
  189. @unlink(str_replace('.*', '.dbf', $this->FileName));
  190. }
  191. if (!($this->DBFFile = @dbase_create(str_replace('.*', '.dbf', $this->FileName), $this->DBFHeader))) {
  192. return $this->setError(sprintf("It wasn't possible to create the DBase file '%s'", str_replace('.*', '.dbf', $this->FileName)));
  193. }
  194. $offset = 50;
  195. if (is_array($this->records) && (count($this->records) > 0)) {
  196. reset($this->records);
  197. while (list($index, $record) = each($this->records)) {
  198. //Save the record to the .shp file
  199. $record->saveToFile($this->SHPFile, $this->DBFFile, $index + 1);
  200. //Save the record to the .shx file
  201. fwrite($this->SHXFile, pack("N", $offset));
  202. fwrite($this->SHXFile, pack("N", $record->getContentLength()));
  203. $offset += (4 + $record->getContentLength());
  204. }
  205. }
  206. @dbase_pack($this->DBFFile);
  207. }
  208. function _openSHPFile($toWrite = false) {
  209. $this->SHPFile = @fopen(str_replace('.*', '.shp', $this->FileName), ($toWrite ? "wb+" : "rb"));
  210. if (!$this->SHPFile) {
  211. return $this->setError(sprintf("It wasn't possible to open the Shape file '%s'", str_replace('.*', '.shp', $this->FileName)));
  212. }
  213. return TRUE;
  214. }
  215. function _closeSHPFile() {
  216. if ($this->SHPFile) {
  217. fclose($this->SHPFile);
  218. $this->SHPFile = NULL;
  219. }
  220. }
  221. function _openSHXFile($toWrite = false) {
  222. $this->SHXFile = @fopen(str_replace('.*', '.shx', $this->FileName), ($toWrite ? "wb+" : "rb"));
  223. if (!$this->SHXFile) {
  224. return $this->setError(sprintf("It wasn't possible to open the Index file '%s'", str_replace('.*', '.shx', $this->FileName)));
  225. }
  226. return TRUE;
  227. }
  228. function _closeSHXFile() {
  229. if ($this->SHXFile) {
  230. fclose($this->SHXFile);
  231. $this->SHXFile = NULL;
  232. }
  233. }
  234. function _openDBFFile($toWrite = false) {
  235. $checkFunction = $toWrite ? "is_writable" : "is_readable";
  236. if (($toWrite) && (!file_exists(str_replace('.*', '.dbf', $this->FileName)))) {
  237. if (!@dbase_create(str_replace('.*', '.dbf', $this->FileName), $this->DBFHeader)) {
  238. return $this->setError(sprintf("It wasn't possible to create the DBase file '%s'", str_replace('.*', '.dbf', $this->FileName)));
  239. }
  240. }
  241. if ($checkFunction(str_replace('.*', '.dbf', $this->FileName))) {
  242. $this->DBFFile = dbase_open(str_replace('.*', '.dbf', $this->FileName), ($toWrite ? 2 : 0));
  243. if (!$this->DBFFile) {
  244. return $this->setError(sprintf("It wasn't possible to open the DBase file '%s'", str_replace('.*', '.dbf', $this->FileName)));
  245. }
  246. } else {
  247. return $this->setError(sprintf("It wasn't possible to find the DBase file '%s'", str_replace('.*', '.dbf', $this->FileName)));
  248. }
  249. return TRUE;
  250. }
  251. function _closeDBFFile() {
  252. if ($this->DBFFile) {
  253. dbase_close($this->DBFFile);
  254. $this->DBFFile = NULL;
  255. }
  256. }
  257. function setError($error) {
  258. $this->lastError = $error;
  259. return false;
  260. }
  261. }
  262. class ShapeRecord {
  263. var $SHPFile = NULL;
  264. var $DBFFile = NULL;
  265. var $recordNumber = NULL;
  266. var $shapeType = NULL;
  267. var $lastError = "";
  268. var $SHPData = array();
  269. var $DBFData = array();
  270. function ShapeRecord($shapeType) {
  271. $this->shapeType = $shapeType;
  272. }
  273. function loadFromFile(&$SHPFile, &$DBFFile) {
  274. $this->SHPFile = $SHPFile;
  275. $this->DBFFile = $DBFFile;
  276. $this->_loadHeaders();
  277. switch ($this->shapeType) {
  278. case 0:
  279. $this->_loadNullRecord();
  280. break;
  281. case 1:
  282. $this->_loadPointRecord();
  283. break;
  284. case 3:
  285. $this->_loadPolyLineRecord();
  286. break;
  287. case 5:
  288. $this->_loadPolygonRecord();
  289. break;
  290. case 8:
  291. $this->_loadMultiPointRecord();
  292. break;
  293. default:
  294. $this->setError(sprintf("The Shape Type '%s' is not supported.", $this->shapeType));
  295. break;
  296. }
  297. $this->_loadDBFData();
  298. }
  299. function saveToFile(&$SHPFile, &$DBFFile, $recordNumber) {
  300. $this->SHPFile = $SHPFile;
  301. $this->DBFFile = $DBFFile;
  302. $this->recordNumber = $recordNumber;
  303. $this->_saveHeaders();
  304. switch ($this->shapeType) {
  305. case 0:
  306. $this->_saveNullRecord();
  307. break;
  308. case 1:
  309. $this->_savePointRecord();
  310. break;
  311. case 3:
  312. $this->_savePolyLineRecord();
  313. break;
  314. case 5:
  315. $this->_savePolygonRecord();
  316. break;
  317. case 8:
  318. $this->_saveMultiPointRecord();
  319. break;
  320. default:
  321. $this->setError(sprintf("The Shape Type '%s' is not supported.", $this->shapeType));
  322. break;
  323. }
  324. $this->_saveDBFData();
  325. }
  326. function updateDBFInfo($header) {
  327. $tmp = $this->DBFData;
  328. unset($this->DBFData);
  329. $this->DBFData = array();
  330. reset($header);
  331. while (list($key, $value) = each($header)) {
  332. $this->DBFData[$value[0]] = (isset($tmp[$value[0]])) ? $tmp[$value[0]] : "";
  333. }
  334. }
  335. function _loadHeaders() {
  336. $this->recordNumber = loadData("N", fread($this->SHPFile, 4));
  337. $tmp = loadData("N", fread($this->SHPFile, 4)); //We read the length of the record
  338. $this->shapeType = loadData("V", fread($this->SHPFile, 4));
  339. }
  340. function _saveHeaders() {
  341. fwrite($this->SHPFile, pack("N", $this->recordNumber));
  342. fwrite($this->SHPFile, pack("N", $this->getContentLength()));
  343. fwrite($this->SHPFile, pack("V", $this->shapeType));
  344. }
  345. function _loadPoint() {
  346. $data = array();
  347. $data["x"] = loadData("d", fread($this->SHPFile, 8));
  348. $data["y"] = loadData("d", fread($this->SHPFile, 8));
  349. return $data;
  350. }
  351. function _savePoint($data) {
  352. fwrite($this->SHPFile, packDouble($data["x"]));
  353. fwrite($this->SHPFile, packDouble($data["y"]));
  354. }
  355. function _loadNullRecord() {
  356. $this->SHPData = array();
  357. }
  358. function _saveNullRecord() {
  359. //Don't save anything
  360. }
  361. function _loadPointRecord() {
  362. $this->SHPData = $this->_loadPoint();
  363. }
  364. function _savePointRecord() {
  365. $this->_savePoint($this->SHPData);
  366. }
  367. function _loadMultiPointRecord() {
  368. $this->SHPData = array();
  369. $this->SHPData["xmin"] = loadData("d", fread($this->SHPFile, 8));
  370. $this->SHPData["ymin"] = loadData("d", fread($this->SHPFile, 8));
  371. $this->SHPData["xmax"] = loadData("d", fread($this->SHPFile, 8));
  372. $this->SHPData["ymax"] = loadData("d", fread($this->SHPFile, 8));
  373. $this->SHPData["numpoints"] = loadData("V", fread($this->SHPFile, 4));
  374. for ($i = 0; $i <= $this->SHPData["numpoints"]; $i++) {
  375. $this->SHPData["points"][] = $this->_loadPoint();
  376. }
  377. }
  378. function _saveMultiPointRecord() {
  379. fwrite($this->SHPFile, pack("dddd", $this->SHPData["xmin"], $this->SHPData["ymin"], $this->SHPData["xmax"], $this->SHPData["ymax"]));
  380. fwrite($this->SHPFile, pack("V", $this->SHPData["numpoints"]));
  381. for ($i = 0; $i <= $this->SHPData["numpoints"]; $i++) {
  382. $this->_savePoint($this->SHPData["points"][$i]);
  383. }
  384. }
  385. function _loadPolyLineRecord() {
  386. $this->SHPData = array();
  387. $this->SHPData["xmin"] = loadData("d", fread($this->SHPFile, 8));
  388. $this->SHPData["ymin"] = loadData("d", fread($this->SHPFile, 8));
  389. $this->SHPData["xmax"] = loadData("d", fread($this->SHPFile, 8));
  390. $this->SHPData["ymax"] = loadData("d", fread($this->SHPFile, 8));
  391. $this->SHPData["numparts"] = loadData("V", fread($this->SHPFile, 4));
  392. $this->SHPData["numpoints"] = loadData("V", fread($this->SHPFile, 4));
  393. for ($i = 0; $i < $this->SHPData["numparts"]; $i++) {
  394. $this->SHPData["parts"][$i] = loadData("V", fread($this->SHPFile, 4));
  395. }
  396. $firstIndex = ftell($this->SHPFile);
  397. $readPoints = 0;
  398. reset($this->SHPData["parts"]);
  399. while (list($partIndex, $partData) = each($this->SHPData["parts"])) {
  400. if (!isset($this->SHPData["parts"][$partIndex]["points"]) || !is_array($this->SHPData["parts"][$partIndex]["points"])) {
  401. $this->SHPData["parts"][$partIndex] = array();
  402. $this->SHPData["parts"][$partIndex]["points"] = array();
  403. }
  404. while (!in_array($readPoints, $this->SHPData["parts"]) && ($readPoints < ($this->SHPData["numpoints"])) && !feof($this->SHPFile)) {
  405. $this->SHPData["parts"][$partIndex]["points"][] = $this->_loadPoint();
  406. $readPoints++;
  407. }
  408. }
  409. fseek($this->SHPFile, $firstIndex + ($readPoints*16));
  410. }
  411. function _savePolyLineRecord() {
  412. fwrite($this->SHPFile, pack("dddd", $this->SHPData["xmin"], $this->SHPData["ymin"], $this->SHPData["xmax"], $this->SHPData["ymax"]));
  413. fwrite($this->SHPFile, pack("VV", $this->SHPData["numparts"], $this->SHPData["numpoints"]));
  414. for ($i = 0; $i < $this->SHPData["numparts"]; $i++) {
  415. fwrite($this->SHPFile, pack("V", count($this->SHPData["parts"][$i])));
  416. }
  417. reset($this->SHPData["parts"]);
  418. foreach ($this->SHPData["parts"] as $partData){
  419. reset($partData["points"]);
  420. while (list($pointIndex, $pointData) = each($partData["points"])) {
  421. $this->_savePoint($pointData);
  422. }
  423. }
  424. }
  425. function _loadPolygonRecord() {
  426. $this->_loadPolyLineRecord();
  427. }
  428. function _savePolygonRecord() {
  429. $this->_savePolyLineRecord();
  430. }
  431. function addPoint($point, $partIndex = 0) {
  432. switch ($this->shapeType) {
  433. case 0:
  434. //Don't add anything
  435. break;
  436. case 1:
  437. //Substitutes the value of the current point
  438. $this->SHPData = $point;
  439. break;
  440. case 3:
  441. case 5:
  442. //Adds a new point to the selected part
  443. if (!isset($this->SHPData["xmin"]) || ($this->SHPData["xmin"] > $point["x"])) $this->SHPData["xmin"] = $point["x"];
  444. if (!isset($this->SHPData["ymin"]) || ($this->SHPData["ymin"] > $point["y"])) $this->SHPData["ymin"] = $point["y"];
  445. if (!isset($this->SHPData["xmax"]) || ($this->SHPData["xmax"] < $point["x"])) $this->SHPData["xmax"] = $point["x"];
  446. if (!isset($this->SHPData["ymax"]) || ($this->SHPData["ymax"] < $point["y"])) $this->SHPData["ymax"] = $point["y"];
  447. $this->SHPData["parts"][$partIndex]["points"][] = $point;
  448. $this->SHPData["numparts"] = count($this->SHPData["parts"]);
  449. $this->SHPData["numpoints"]++;
  450. break;
  451. case 8:
  452. //Adds a new point
  453. if (!isset($this->SHPData["xmin"]) || ($this->SHPData["xmin"] > $point["x"])) $this->SHPData["xmin"] = $point["x"];
  454. if (!isset($this->SHPData["ymin"]) || ($this->SHPData["ymin"] > $point["y"])) $this->SHPData["ymin"] = $point["y"];
  455. if (!isset($this->SHPData["xmax"]) || ($this->SHPData["xmax"] < $point["x"])) $this->SHPData["xmax"] = $point["x"];
  456. if (!isset($this->SHPData["ymax"]) || ($this->SHPData["ymax"] < $point["y"])) $this->SHPData["ymax"] = $point["y"];
  457. $this->SHPData["points"][] = $point;
  458. $this->SHPData["numpoints"]++;
  459. break;
  460. default:
  461. $this->setError(sprintf("The Shape Type '%s' is not supported.", $this->shapeType));
  462. break;
  463. }
  464. }
  465. function deletePoint($pointIndex = 0, $partIndex = 0) {
  466. switch ($this->shapeType) {
  467. case 0:
  468. //Don't delete anything
  469. break;
  470. case 1:
  471. //Sets the value of the point to zero
  472. $this->SHPData["x"] = 0.0;
  473. $this->SHPData["y"] = 0.0;
  474. break;
  475. case 3:
  476. case 5:
  477. //Deletes the point from the selected part, if exists
  478. if (isset($this->SHPData["parts"][$partIndex]) && isset($this->SHPData["parts"][$partIndex]["points"][$pointIndex])) {
  479. for ($i = $pointIndex; $i < (count($this->SHPData["parts"][$partIndex]["points"]) - 1); $i++) {
  480. $this->SHPData["parts"][$partIndex]["points"][$i] = $this->SHPData["parts"][$partIndex]["points"][$i + 1];
  481. }
  482. unset($this->SHPData["parts"][$partIndex]["points"][count($this->SHPData["parts"][$partIndex]["points"]) - 1]);
  483. $this->SHPData["numparts"] = count($this->SHPData["parts"]);
  484. $this->SHPData["numpoints"]--;
  485. }
  486. break;
  487. case 8:
  488. //Deletes the point, if exists
  489. if (isset($this->SHPData["points"][$pointIndex])) {
  490. for ($i = $pointIndex; $i < (count($this->SHPData["points"]) - 1); $i++) {
  491. $this->SHPData["points"][$i] = $this->SHPData["points"][$i + 1];
  492. }
  493. unset($this->SHPData["points"][count($this->SHPData["points"]) - 1]);
  494. $this->SHPData["numpoints"]--;
  495. }
  496. break;
  497. default:
  498. $this->setError(sprintf("The Shape Type '%s' is not supported.", $this->shapeType));
  499. break;
  500. }
  501. }
  502. function getContentLength() {
  503. switch ($this->shapeType) {
  504. case 0:
  505. $result = 0;
  506. break;
  507. case 1:
  508. $result = 10;
  509. break;
  510. case 3:
  511. case 5:
  512. $result = 22 + 2*count($this->SHPData["parts"]);
  513. for ($i = 0; $i < count($this->SHPData["parts"]); $i++) {
  514. $result += 8*count($this->SHPData["parts"][$i]["points"]);
  515. }
  516. break;
  517. case 8:
  518. $result = 20 + 8*count($this->SHPData["points"]);
  519. break;
  520. default:
  521. $result = false;
  522. $this->setError(sprintf("The Shape Type '%s' is not supported.", $this->shapeType));
  523. break;
  524. }
  525. return $result;
  526. }
  527. function _loadDBFData() {
  528. $this->DBFData = @dbase_get_record_with_names($this->DBFFile, $this->recordNumber);
  529. unset($this->DBFData["deleted"]);
  530. }
  531. function _saveDBFData() {
  532. unset($this->DBFData["deleted"]);
  533. if ($this->recordNumber <= dbase_numrecords($this->DBFFile)) {
  534. if (!dbase_replace_record($this->DBFFile, array_values($this->DBFData), $this->recordNumber)) {
  535. $this->setError("I wasn't possible to update the information in the DBF file.");
  536. }
  537. } else {
  538. if (!dbase_add_record($this->DBFFile, array_values($this->DBFData))) {
  539. $this->setError("I wasn't possible to add the information to the DBF file.");
  540. }
  541. }
  542. }
  543. function setError($error) {
  544. $this->lastError = $error;
  545. return false;
  546. }
  547. }
  548. ?>