PageRenderTime 62ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/server/samples/treegrid/php/treedata/nitobi.xml.php

https://github.com/stevengill/completeui
PHP | 774 lines | 583 code | 48 blank | 143 comment | 20 complexity | 027196a8cca814916ad78d81f0f51493 MD5 | raw file
Possible License(s): Apache-2.0, AGPL-3.0, BSD-3-Clause
  1. <?php
  2. // *****************************************************************************
  3. // *****************************************************************************
  4. // * EBAXML PHP Library v2.15
  5. // *****************************************************************************
  6. // * Copyright (C) eBusiness Applications
  7. // * The SOFTWARE PRODUCT is protected by copyright laws and international
  8. // * copyright treaties, as well as other intellectual property laws and treaties.
  9. // * The SOFTWARE PRODUCT is licensed, not sold. The eBusiness Applications
  10. // * distribution file may not have files added to it or removed from it.
  11. // * None of its compiled or encoded contents may be decompiled, or reverse engineered.
  12. // * You may not reverse engineer, decompile, or disassemble the SOFTWARE PRODUCT,
  13. // * except and only to the extent that such activity is expressly permitted by
  14. // * applicable law notwithstanding this limitation.
  15. // *****************************************************************************
  16. ///<class name='ILocaleConverter'>
  17. /// <summary>
  18. /// ILocaleConverter provides a means of extending EBAXML.php to handle different
  19. /// character encodings. If you are using a new encoding you should create a
  20. /// subclass and override the createUnicodeString method
  21. /// </summary>
  22. /// <remarks> The ILocaleConverter is used for internationalization. ILocaleConverter:createUnicodeString should be treated as an pure virtual abstract method. Please create an instance of DefaultLocaleConverter.</remarks>
  23. ///
  24. class ILocaleConverter
  25. {
  26. function ILocaleConverter()
  27. {
  28. }
  29. ///<function name="createUnicodeString" access="public">
  30. ///<summary>Creates a Unicode string</summary>
  31. ///<param name="nativeString" type="string" >A natively encode string</param>
  32. ///<returns type="string" >A Unicode string</returns>
  33. ///<remarks>ILocaleConverter->createUnicodeString should be treated as an pure virtual abstract method. Please create an instance of DefaultLocaleConverter.</remarks>
  34. function createUnicodeString($nativeString)
  35. {
  36. trigger_error("ILocaleConverter->createUnicodeString should be treated as an pure virtual abstract method. Please create an instance of DefaultLocaleConverter.",E_USER_ERROR);
  37. }
  38. ///</function>
  39. }
  40. ///</class>
  41. ///<class name='DefaultLocaleConverter' inherits='ILocaleConverter'>
  42. /// <summary>
  43. /// Converter to create Unicode strings from the default php native encoding
  44. /// </summary>
  45. /// <remarks>
  46. /// It is best to have the mbstring extension loaded. To load this extension
  47. /// remove the ';' from the beginning of the ';extension=php_mbstring.dll' line in
  48. /// your php.ini and restart you webserver. If mbstring is not loaded the
  49. /// nativeString is returned unchanged.
  50. /// </remarks>
  51. class DefaultLocaleConverter extends ILocaleConverter
  52. {
  53. function DefaultLocaleConverter()
  54. {
  55. }
  56. ///<function name="createUnicodeString" access="public">
  57. ///<summary>Creates a Unicode string</summary>
  58. ///<param name="nativeString" type="string" >A string</param>
  59. ///<returns type="string" >A Unicode string</returns>
  60. function createUnicodeString($nativeString)
  61. {
  62. # by default just return the input
  63. $result = $nativeString;
  64. # check if mbstring is loaded.
  65. if(extension_loaded("mbstring"))
  66. {
  67. $result = mb_convert_encoding($nativeString, "UTF-8");
  68. }
  69. return $result;
  70. }
  71. ///</function>
  72. }
  73. ///</class>
  74. ///<class name='Shift_JISLocaleConverter' inherits='ILocaleConverter' >
  75. /// <summary>
  76. /// A Converter use to create Unicode strings from Shift_JIS encoding
  77. /// </summary>
  78. /// <remarks>
  79. /// It is best to have the mbstring extension loaded. To load this extension
  80. /// remove the ';' from the beginning of the ';extension=php_mbstring.dll' line in
  81. /// your php.ini and restart you webserver. If mbstring is not loaded the
  82. /// nativeString is returned unchanged.
  83. /// </remarks>
  84. /// <remarks> Shift_JISLocaleConverter will only work if the mbstring extension is loaded. To load the mbstrings extention, please remove the ';' from the beginning of the ';extension=php_mbstring.dll' line in your php.ini and restart you webserver. For more details see http://ca.php.net/mbstring </remarks>
  85. class Shift_JISLocaleConverter extends ILocaleConverter
  86. {
  87. function Shift_JISLocaleConverter()
  88. {
  89. }
  90. ///<function name="createUnicodeString" access="public">
  91. ///<summary>creates a Unicode encoded string from a Shift_JIS string</summary>
  92. ///<param name="nativeString" type="string" >A string of Shift_JIS encoded characters</param>
  93. ///<returns type="string" >A Unicode string</returns>
  94. function createUnicodeString($nativeString)
  95. {
  96. $result = $nativeString;
  97. if(extension_loaded("mbstring"))
  98. {
  99. $result = mb_convert_encoding($nativeString, "UTF-8", "SJIS");
  100. }
  101. else
  102. {
  103. trigger_error("Shift_JISLocaleConverter will only work if the mbstring extension is loaded. To load the mbstrings extention, please remove the ';' from the beginning of the ';extension=php_mbstring.dll' line in your php.ini and restart you webserver. For more details see http://ca.php.net/mbstring",E_USER_ERROR);
  104. }
  105. return $result;
  106. }
  107. ///</function>
  108. }
  109. ///</class>
  110. ///<class name='EBARecord'>
  111. ///<summary> EBARecord encapsulates a single row of data
  112. /// The row has an id and a set of name value pairs
  113. ///</summary>
  114. class EBARecord
  115. {
  116. var $m_ID = 0;
  117. # Files is a pair of name value fields.
  118. var $m_Fields = array();
  119. function EBARecord($id)
  120. {
  121. $this->m_ID=$id;
  122. }
  123. ///<function name="add" access="public">
  124. /// <summary>Adds a new name value pair to the record</summary>
  125. ///<param name="columnName" type="string" >Name of field</param>
  126. ///<param name="columnValue" type="string" >Field value</param>
  127. ///</function>
  128. function add($columnName, $columnValue)
  129. {
  130. $this->m_Fields[$columnName] = $columnValue;
  131. }
  132. ///<function name="getRows" access="public">
  133. ///<summary>Adds a new name value pair to the record</summary>
  134. ///<returns>An associative array of the name value pairs </returns>
  135. ///</function>
  136. function getRows()
  137. {
  138. return $this->m_Fields;
  139. }
  140. ///<function name="getID" access="public">
  141. ///<summary>Return the ID of the record</summary>
  142. ///<returns type="string" >Record ID</returns>
  143. ///</function>
  144. function getID()
  145. {
  146. return $this->m_ID;
  147. }
  148. }
  149. ///</class>
  150. // EBAXML PHP Library v2.01 Copyright (C) eBusiness Applications The SOFTWARE
  151. // PRODUCT is protected by copyright laws and international copyright treaties, as
  152. // well as other intellectual property laws and treaties. The SOFTWARE PRODUCT is
  153. // licensed, not sold. The eBusiness Applications distribution file may not have
  154. // files added to it or removed from it. None of its compiled or encoded contents
  155. // may be decompiled, or reverse engineered. You may not reverse engineer,
  156. // decompile, or disassemble the SOFTWARE PRODUCT, except and only to the extent
  157. // that such activity is expressly permitted by applicable law notwithstanding
  158. // this limitation. EBAGetHandler is an encapsulation of the data structure used
  159. // to create EBA compressed XML The data includes a set of column names and a set
  160. // of records
  161. // @created 23-Sep-2005 3:19:21 PM
  162. ///<class name='EBAGetHandler'>
  163. /// <summary>Write EBA compressed XML based on a set of records </summary>
  164. //
  165. // The following are a set of depreciated functions Please make your
  166. // life easy and stop using the following functions:
  167. // ProcessRecords - This is now a no-op
  168. // DefineField - This is now a no-op
  169. // CreateNewRecord - No longer supported
  170. // SaveRecord - No longer supported
  171. // DefineRecordFieldValue - No longer supported
  172. // <br></br>
  173. //
  174. // <example>
  175. //<code>
  176. // $getHandler = new EBAGetHandler();
  177. // $record = new EBARecord("ID1");
  178. // $record->add("Field1", "Value One");
  179. // $getHandler.add($record);
  180. // $getHandle.CompleteGet();
  181. //</code>
  182. //</example>
  183. class EBAGetHandler
  184. {
  185. # a list of columns that will be included in the component
  186. var $m_ColunmNames = array();
  187. var $m_Rows = array();
  188. # XML's reserved chars and their entity references
  189. var $m_TranscodeList = array(
  190. "&" => "&amp;", # Make sure to replace this first.
  191. "\"" => "&quot;",
  192. "<" => "&lt;",
  193. ">" => "&gt;",
  194. "\n" => "&#10;",);
  195. # carriageReturn => "&#13;" # need to add c/r
  196. var $m_currentRecord;
  197. # allows for the transcoding of strings
  198. var $m_localeConverter;
  199. # adds the xml:lang attribute to the xml
  200. var $m_dataLanguage;
  201. # for keeping track of any errors. if this is set to a non-empty string then it
  202. # will be sent back to the client as an attribute called "error" in the root element.
  203. var $m_ErrorMessage;
  204. var $m_totalRowCount;
  205. var $m_foreignKey;
  206. var $m_foreignKeyValue;
  207. function EBAGetHandler()
  208. {
  209. $this->m_ErrorMessage = "";
  210. $this->m_dataLanguage = "en";
  211. $this->m_localeConverter = new DefaultLocaleConverter();
  212. }
  213. function SetTotalRowCount($rowCount)
  214. {
  215. $this->m_totalRowCount = $rowCount;
  216. }
  217. function DefineForeignKey($fk)
  218. {
  219. $this->m_foreignKey = $fk;
  220. }
  221. function DefineForeignKeyValue($value)
  222. {
  223. $this->m_foreignKeyValue = $value;
  224. }
  225. ///<function name="ProcessRecords" access="public">
  226. /// <summary>DEPRECIATED DO NOT USE</summary>
  227. ///<param name="XMLEncoding" type="string" >Do not use</param>
  228. /// <remarks>To set encoding use the 'encoding' parameter of the methods toXML or completeGet</remarks>
  229. ///</function>
  230. function ProcessRecords($XMLEncoding="UTF-8")
  231. {
  232. // this is a no op
  233. }
  234. ///<function name="DefineField" access="public">
  235. /// <summary>Allows the description of data without record being added.
  236. /// This allows the combo to render when there are zero records.</summary>
  237. /// <remarks>The fields do not have to be pre-defined. Fields are now
  238. /// created base on the records. Whenever a record is added all of
  239. /// the records fields are added to the global list of fields.
  240. /// Note DefineFields must be called if no records are added to the EBAGetHandler object.
  241. /// </remarks>
  242. ///<param name="XMLEncoding" type="string" ></param>
  243. ///</function>
  244. function DefineField($FieldName)
  245. {
  246. $this->m_ColunmNames[$FieldName] = 1;
  247. }
  248. ///<function name="CreateNewRecord" access="public">
  249. /// <summary>DEPRECIATED DO NOT USE</summary>
  250. /// <remarks>The supported method to create record is to call $currentRecord = new EBARecord($KeyVal);
  251. /// </remarks>
  252. ///</function>
  253. function CreateNewRecord($KeyVal)
  254. {
  255. $this->m_currentRecord = new EBARecord($KeyVal);
  256. }
  257. ///<function name="SaveRecord" access="public">
  258. /// <summary>DEPRECIATED DO NOT USE</summary>
  259. /// <remarks>The supported method of adding records is to call $currentGetHanlder->add($currentRecord);
  260. /// </remarks>
  261. ///</function>
  262. function SaveRecord()
  263. {
  264. $this->add($this->m_currentRecord);
  265. $this->m_currentRecord = "";
  266. }
  267. ///<function name="DefineRecordFieldValue" access="public">
  268. /// <summary>DEPRECIATED DO NOT USE</summary>
  269. /// <remarks>The supported method of adding field-value pairs is: $currentRecord->add($ColName, $DataValue)
  270. /// </remarks>
  271. ///</function>
  272. function DefineRecordFieldValue($ColName, $DataValue)
  273. {
  274. $this->m_currentRecord->add($ColName, $DataValue);
  275. }
  276. ///<function name="add" access="public">
  277. /// <summary> The 'record' added will become a row element in the eba xml</summary>
  278. ///<param name="record" type="EBARecord" >The record to add</param>
  279. ///</function>
  280. function add($record)
  281. {
  282. # add all the ColumnNames
  283. foreach ($record->getRows() as $columnName => $dummy)
  284. {
  285. $this->m_ColunmNames[$columnName] = 1;
  286. }
  287. # add the Rows
  288. $this->m_Rows[$record->getID()] = $record->getRows();
  289. }
  290. ///<function name="setLocaleConverter" access="public">
  291. /// <summary> Set the localeConverter. This is only needed if different character set are used.</summary>
  292. ///<param name="LocaleConverter" type="ILocaleConverter" >The localeConverter used to generate the EBA compessed xml response</param>
  293. ///</function>
  294. function setLocaleConverter($localeConverter)
  295. {
  296. $this->m_localeConverter = $localeConverter;
  297. }
  298. ///<function name="setDataLanguage" access="public">
  299. /// <summary> Set the datalanguage used for xml:lang</summary>
  300. ///<param name="language" type="string" >The value used for xml:lang</param>
  301. ///</function>
  302. function setDataLanguage($language)
  303. {
  304. $this->m_dataLanguage = $language;
  305. }
  306. ///<function name="setErrorMessage" access="public">
  307. ///<summary> Sets an error message to be sent back to the client in the response. Set this to any empty string to clear the error message.</summary>
  308. ///<param name="message" type="string" >The value for the error message</param>
  309. ///</function>
  310. function setErrorMessage($message)
  311. {
  312. $this->m_ErrorMessage = $message;
  313. }
  314. ///<function name="completeGet" access="public">
  315. /// <summary> Prints UTF-8 EBA XML to the respone</summary>
  316. ///</function>
  317. function completeGet($encoding="UTF-8")
  318. {
  319. header("Content-type:text/xml;charset=$encoding");
  320. print $this->toXML($encoding);
  321. }
  322. ///<function name="toXML" access="public">
  323. /// <summary> Creates an compressed EBA XML document based on the records added to the getHandler object</summary>
  324. /// <returns type="string"> compressed UTF-8 EBA XML document</returns>
  325. ///</function>
  326. function toXML($encoding="UTF-8")
  327. {
  328. $results = "<?xml version=\"1.0\" encoding=\"$encoding\" ?>";
  329. # print the columns as the fields attribute of the opening root tag
  330. $results .= "<root xml:lang=\"{$this->m_dataLanguage}\" fields=\"".
  331. strtr(implode("|",array_keys($this->m_ColunmNames)),$this->m_TranscodeList)."\"";
  332. if ($this->m_ErrorMessage != "")
  333. {
  334. $results .= " error=\"" . strtr($this->m_ErrorMessage,$this->m_TranscodeList) . "\"";
  335. }
  336. if ($this->m_totalRowCount != NULL)
  337. {
  338. $results .= " totalrowcount=\"" . $this->m_totalRowCount . "\"";
  339. }
  340. if ($this->m_foreignKey != NULL)
  341. {
  342. $results .= " parentfield=\"" . $this->m_foreignKey . "\"";
  343. }
  344. if ($this->m_foreignKeyValue != NULL)
  345. {
  346. $results .= " parentvalue=\"" . $this->m_foreignKeyValue . "\"";
  347. }
  348. $results .= ">";
  349. # print the rows
  350. # following is an example row
  351. # <e xk="de" a="de" b="images/flags/de_flag.gif" c="Deutschland"/>
  352. # create compression indexes a,..,z,aa,ab,..,zy,zz
  353. $EBAColumnOrder = range('a','z');
  354. foreach ($this->m_Rows as $rowID => $rowArray)
  355. {
  356. $results .= "<e xk=\"".strtr($rowID,$this->m_TranscodeList)."\"";
  357. $EBAIndex = -1;
  358. $EBASubIndex = 0;
  359. foreach ($this->m_ColunmNames as $columnName => $dummy)
  360. {
  361. if(count($EBAColumnOrder) <= $EBASubIndex)
  362. {
  363. $EBASubIndex = 0;
  364. $EBAIndex++;
  365. }
  366. $ColumnKey = $EBAColumnOrder[$EBASubIndex];
  367. if($EBAIndex > -1)
  368. {
  369. $ColumnKey = $EBAColumnOrder[$EBAIndex].$ColumnKey;
  370. }
  371. # index "$EBAColumnOrder[$index]$EBAColumnOrder[$subIndex]";
  372. $results .= " $ColumnKey=\"".strtr($rowArray[$columnName],$this->m_TranscodeList)."\"";
  373. $EBASubIndex++;
  374. }
  375. $results .= " />\n";
  376. }
  377. // finish document
  378. $results .= ( "</root>");
  379. return $this->m_localeConverter->createUnicodeString($results);
  380. }
  381. }
  382. ///</class>
  383. class EBASaveHandler
  384. {
  385. var $InsertRecords = array();
  386. var $UpdateRecords = array();
  387. var $DeleteRecords = array();
  388. var $InsertCount = 0;
  389. var $UpdateCount = 0;
  390. var $DeleteCount = 0;
  391. var $Fields = array();
  392. var $FieldsCount = 0;
  393. var $FieldsSet = array();
  394. var $XmlStr;
  395. var $m_ErrorMessage;
  396. var $m_ForeignKeyValue;
  397. # XML's reserved chars and their entity references
  398. var $m_TranscodeList = array(
  399. "&" => "&amp;", # Make sure to replace this first.
  400. "\"" => "&quot;",
  401. "<" => "&lt;",
  402. ">" => "&gt;",
  403. "\n" => "&#10;",);
  404. function EBASaveHandler()
  405. {
  406. $this->XmlStr = $GLOBALS["HTTP_RAW_POST_DATA"];
  407. }
  408. function CompleteSave($encoding="UTF-8")
  409. {
  410. header("Content-type:text/xml;charset=$encoding");
  411. // print $this->toXML($encoding);
  412. if( $this->m_ErrorMessage != "" )
  413. {
  414. print str_replace("<root ", "<root error=\"".strtr($this->m_ErrorMessage,$this->m_TranscodeList)."\" ", $this->XmlStr);
  415. }
  416. else
  417. {
  418. print $this->XmlStr;
  419. }
  420. }
  421. function ReturnInsertCount()
  422. {
  423. return $this->InsertCount;
  424. }
  425. function ReturnUpdateCount()
  426. {
  427. return $this->UpdateCount;
  428. }
  429. function ReturnDeleteCount()
  430. {
  431. return $this->DeleteCount;
  432. }
  433. ///<function name="setErrorMessage" access="public">
  434. ///<summary> Sets an error message to be sent back to the client in the response. Set this to any empty string to clear the error message.</summary>
  435. ///<param name="message" type="string" >The value for the error message</param>
  436. ///</function>
  437. function setErrorMessage($message)
  438. {
  439. $this->m_ErrorMessage = $message;
  440. }
  441. //<function name="ReturnInsertField" access="public">
  442. // <summary> Returns the number of insert instructions in the updategram.
  443. // Updategrams (saving instructions) contain 3 types of instructions: INSERT, UPDATE, and DELETE.
  444. // Always process INSERT's first, UPDATE's next, and DELETE's last.</summary>
  445. // <returns type="string"> The value for a field. </returns>
  446. //</function>
  447. function ReturnInsertField($RecordNumber, $FieldName = "")
  448. {
  449. $postData = $GLOBALS["HTTP_RAW_POST_DATA"];
  450. $EBAResultValue = "";
  451. $EBASearchField = "";
  452. $index = array_search($FieldName, $this->Fields);
  453. if (($index !== FALSE) || ($FieldName == "") || ($FieldName == "EBAFK"))
  454. {
  455. if ($FieldName == "")
  456. {
  457. $EBASearchField = "xk=\"";
  458. }
  459. else if ($FieldName == "EBAFK")
  460. {
  461. $EBASearchField = "xf=\"";
  462. }
  463. else if (strlen($FieldName) > 0)
  464. {
  465. //"d" should be included here too
  466. //but this test wasn't working for some reason, and actually appending
  467. //the space to ALL EBASearchFields is fine
  468. //$EBASearchField = $this->FieldsSet[$index]."=\"";
  469. //if (($this->FieldsSet[$index] == "d" || $this->FieldsSet[$index] == "k") || ($this->FieldsSet[$index] == "i"))
  470. $EBASearchField = " ".$this->FieldsSet[$index] ."=\"";
  471. }
  472. $EBAUpdateGramTemp = EBAright($postData, strlen($postData) - $this->InsertRecords[$RecordNumber]);
  473. $EBANextPos = strpos($EBAUpdateGramTemp, $EBASearchField);
  474. if ($EBANextPos > 0)
  475. {
  476. $EBAUpdateGramTemp = EBAright($EBAUpdateGramTemp, strlen($EBAUpdateGramTemp) - $EBANextPos - strlen($EBASearchField));
  477. $EBANextPos = strpos($EBAUpdateGramTemp, "\"");
  478. $EBAUpdateGramTemp = EBAleft($EBAUpdateGramTemp,$EBANextPos);
  479. $EBAResultValue = $EBAUpdateGramTemp;
  480. }
  481. }
  482. return $EBAResultValue;
  483. }
  484. function ReturnForeignKeyValue($RecordNumber)
  485. {
  486. return $this->ReturnInsertField($RecordNumber, "EBAFK");
  487. }
  488. function ReturnUpdateField($RecordNumber, $FieldName = "")
  489. {
  490. $postData = $GLOBALS["HTTP_RAW_POST_DATA"];
  491. $EBAResultValue = "";
  492. $EBASearchField = "";
  493. $index = array_search($FieldName, $this->Fields);
  494. if (($index !== FALSE) || ($FieldName == ""))
  495. {
  496. $EBASearchField = "xk=\"";
  497. if (strlen($FieldName) > 0)
  498. {
  499. $EBASearchField = $this->FieldsSet[$index] ."=\"";
  500. //"d" should be included here too
  501. //but this test wasn't working for some reason, and actually appending
  502. //the space to ALL EBASearchFields is fine
  503. //if ($this->FieldsSet[$index] == "d" || $this->FieldsSet[$index] == "k" || $this->FieldsSet[$index] == "i")
  504. $EBASearchField = " ".$this->FieldsSet[$index] ."=\"";
  505. }
  506. $EBAUpdateGramTemp = EBAright($postData, strlen($postData) - $this->UpdateRecords[$RecordNumber]);
  507. $EBANextPos = strpos($EBAUpdateGramTemp, $EBASearchField);
  508. if ($EBANextPos > 0)
  509. {
  510. $EBAUpdateGramTemp = EBAright($EBAUpdateGramTemp, strlen($EBAUpdateGramTemp) - $EBANextPos - strlen($EBASearchField));
  511. $EBANextPos = strpos($EBAUpdateGramTemp, "\"");
  512. $EBAUpdateGramTemp = EBAleft($EBAUpdateGramTemp, $EBANextPos);
  513. $EBAResultValue = $EBAUpdateGramTemp;
  514. }
  515. }
  516. return $EBAResultValue;
  517. }
  518. function ReturnDeleteField($RecordNumber)
  519. {
  520. $postData = $GLOBALS["HTTP_RAW_POST_DATA"];
  521. $EBAResultValue = "";
  522. $EBASearchField = "xk=\"";
  523. $EBADeleteGramTemp = EBAright($postData, strlen($postData) - $this->DeleteRecords[$RecordNumber]);
  524. $EBANextPos = strpos($EBADeleteGramTemp, $EBASearchField);
  525. if ($EBANextPos > 0)
  526. {
  527. $EBADeleteGramTemp = EBAright($EBADeleteGramTemp, strlen($EBADeleteGramTemp) - $EBANextPos - strlen($EBASearchField));
  528. $EBANextPos = strpos($EBADeleteGramTemp, "\"");
  529. $EBADeleteGramTemp = EBAleft($EBADeleteGramTemp, $EBANextPos);
  530. $EBAResultValue = $EBADeleteGramTemp;
  531. }
  532. return $EBAResultValue;
  533. }
  534. //<function name="ProcessRecords" access="public">
  535. // <summary>This function initializes the SaveHandler based on the data in the GLOBALS[HTTP_RAW_POST_DATA] </summary>
  536. // <returns type="string"> The value for a field</returns>
  537. //</function>
  538. function ProcessRecords()
  539. {
  540. $postData = $GLOBALS["HTTP_RAW_POST_DATA"];
  541. # Populate EBAGetHandler_Fields with the fields names
  542. $EBAUpdategram = $postData;
  543. $ParsePos = 0;
  544. if (strlen($EBAUpdategram) > 5)
  545. {
  546. $ParsePos = strpos(strtolower($EBAUpdategram), "fields");
  547. $ParsePos = strpos(EBAright($EBAUpdategram, strlen($EBAUpdategram) - $ParsePos), "\"") + 7;
  548. $EBAUpdategram = EBAright($EBAUpdategram, strlen($EBAUpdategram) - $ParsePos);
  549. #Begin grabbing fields
  550. $EBANextPos = 0;
  551. $EBAFieldName = "";
  552. do
  553. {
  554. $EBANextPos = strpos($EBAUpdategram, "|");
  555. $EBANextPos = min($EBANextPos, strpos($EBAUpdategram, "\""));
  556. if ($EBANextPos > 0)
  557. {
  558. $EBAFieldName = EBAleft($EBAUpdategram, $EBANextPos);
  559. $EBAUpdategram = EBAright($EBAUpdategram, strlen($EBAUpdategram) - $EBANextPos - 1);
  560. $this->Fields[$this->FieldsCount] = $EBAFieldName;
  561. $this->FieldsCount += 1;
  562. }
  563. }
  564. while ($EBANextPos > 0);
  565. $EBANextPos = strpos($EBAUpdategram, "\"");
  566. if ($EBANextPos > 0)
  567. {
  568. $EBAFieldName = EBAleft($EBAUpdategram, $EBANextPos);
  569. $EBAUpdategram = EBAright($EBAUpdategram, strlen($EBAUpdategram) - $EBANextPos - 1);
  570. $this->Fields[$this->FieldsCount] = $EBAFieldName;
  571. $this->FieldsCount += 1;
  572. }
  573. # Now we count the insert instructions
  574. $EBAUpdategram = $postData;
  575. $EBAUpdateGramTemp = $EBAUpdategram;
  576. $EBATotalCount = 0;
  577. do
  578. {
  579. $EBANextPos = strpos($EBAUpdateGramTemp, "<insert");
  580. if ($EBANextPos > 0)
  581. {
  582. $EBATotalCount += $EBANextPos+1;
  583. $this->InsertRecords[$this->InsertCount] = $EBATotalCount;
  584. $this->InsertCount += 1;
  585. $EBAUpdateGramTemp = EBAright($EBAUpdateGramTemp, strlen($EBAUpdateGramTemp) - $EBANextPos - 1);
  586. }
  587. }
  588. while ($EBANextPos > 0);
  589. $EBAUpdateGramTemp = $EBAUpdategram;
  590. $EBATotalCount = 0;
  591. do
  592. {
  593. $EBANextPos = strpos($EBAUpdateGramTemp, "<update");
  594. if ($EBANextPos > 0)
  595. {
  596. $EBATotalCount += $EBANextPos;
  597. $this->UpdateRecords[$this->UpdateCount] = $EBATotalCount;
  598. $this->UpdateCount += 1;
  599. $EBAUpdateGramTemp = EBAright($EBAUpdateGramTemp, strlen($EBAUpdateGramTemp) - $EBANextPos - 1);
  600. }
  601. }
  602. while ($EBANextPos > 0);
  603. $EBAUpdateGramTemp = $EBAUpdategram;
  604. $EBATotalCount = 0;
  605. do
  606. {
  607. $EBANextPos = strpos($EBAUpdateGramTemp, "<delete");
  608. if ($EBANextPos > 0)
  609. {
  610. $EBATotalCount += $EBANextPos;
  611. $this->DeleteRecords[$this->DeleteCount] = $EBATotalCount;
  612. $this->DeleteCount += 1;
  613. $EBAUpdateGramTemp = EBAright($EBAUpdateGramTemp, strlen($EBAUpdateGramTemp) - $EBANextPos - 1);
  614. }
  615. }
  616. while ($EBANextPos > 0);
  617. $EBAFieldOrder = array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z');
  618. $MainSetCounter = 0;
  619. for ( $index = 0; $index < 26; $index += 1)
  620. {
  621. $this->FieldsSet[$index] = $EBAFieldOrder[$index];
  622. $MainSetCounter += 1;
  623. }
  624. for ( $index = 0; $index < 26; $index += 1)
  625. {
  626. for ( $subIndex = 0; $subIndex < 26; $subIndex += 1)
  627. {
  628. $this->FieldsSet[$MainSetCounter] = $EBAFieldOrder[$index] . $EBAFieldOrder[$subIndex];
  629. $MainSetCounter += 1;
  630. }
  631. }
  632. }
  633. else
  634. {
  635. print "No valid EBA updategram was discovered!";
  636. }
  637. }
  638. //<function name="SetRecordKey" access="public">
  639. // <summary>In the case of an insert, we need to communicate back to the client
  640. // the new key for this record. After inserting into the database, call
  641. // this method to add the new key to the response back to the client.</summary>
  642. //</function>
  643. function SetRecordKey($RecordNumber, $key)
  644. {
  645. //
  646. $EBAUpdateGramTemp = EBAright($this->XmlStr, strlen($this->XmlStr) - $this->InsertRecords[$RecordNumber]);
  647. $EBANextPos = strpos($EBAUpdateGramTemp, "xk");
  648. $EBAInsertPos = strpos($this->XmlStr, $EBAUpdateGramTemp);
  649. if ($EBANextPos > 0)
  650. {
  651. $EBAUpdateGramWithKey = substr_replace($EBAUpdateGramTemp, "xk=\"" . $key . "\"", $EBANextPos, 5);
  652. $this->XmlStr = substr_replace($this->XmlStr, $EBAUpdateGramWithKey, $EBAInsertPos);
  653. }
  654. }
  655. }
  656. function EBAleft ($str, $howManyCharsFromLeft)
  657. {
  658. return substr ($str, 0, $howManyCharsFromLeft);
  659. }
  660. function EBAright ($str, $howManyCharsFromRight)
  661. {
  662. $strLen = strlen ($str);
  663. return substr ($str, $strLen - $howManyCharsFromRight, $strLen);
  664. }
  665. function EBAmid ($str, $start, $howManyCharsToRetrieve = 0)
  666. {
  667. $start--;
  668. if ($howManyCharsToRetrieve == 0)
  669. $howManyCharsToRetrieve = strlen ($str) - $start;
  670. return substr ($str, $start, $howManyCharsToRetrieve);
  671. }
  672. function getDateForMysqlDateField($val)
  673. {
  674. preg_match("#^([0-9]{2})/([0-9]{2})/([0-9]{4})#",$val,$Match);
  675. return(mktime(0,0,0,$Match[2],$Match[1],$Match[3]));
  676. }
  677. ?>