PageRenderTime 56ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/server/src/php/nitobi.xml.php

https://github.com/stevengill/completeui
PHP | 819 lines | 627 code | 48 blank | 144 comment | 20 complexity | 1c95b04a43cc8b5beed0d22d07530a60 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. var $m_primaryKey;
  208. function EBAGetHandler()
  209. {
  210. $this->m_ErrorMessage = "";
  211. $this->m_dataLanguage = "en";
  212. $this->m_localeConverter = new DefaultLocaleConverter();
  213. }
  214. function EnableEventMode()
  215. {
  216. $this->DefineField("startdate");
  217. $this->DefineField("enddate");
  218. $this->DefineField("location");
  219. $this->DefineField("description");
  220. $this->DefineField("type");
  221. }
  222. function CreateEvent($key, $startDate, $endDate, $location, $description)
  223. {
  224. $record = new EBARecord($key);
  225. $record->add("startdate", $startDate);
  226. $record->add("enddate", $endDate);
  227. $record->add("location", $location);
  228. $record->add("description", $description);
  229. $record->add("type", "event");
  230. $this->add($record);
  231. }
  232. function DisableDate($date)
  233. {
  234. $record = new EBARecord(0);
  235. $record->add("startdate", $date);
  236. $record->add("enddate", "");
  237. $record->add("location", "");
  238. $record->add("description", "");
  239. $record->add("type", "disabled");
  240. $this->add($record);
  241. }
  242. function SetTotalRowCount($rowCount)
  243. {
  244. $this->m_totalRowCount = (string) $rowCount;
  245. }
  246. function SetPrimaryKey($theKey)
  247. {
  248. $this->m_primaryKey = $theKey;
  249. }
  250. function DefineForeignKey($fk)
  251. {
  252. $this->m_foreignKey = $fk;
  253. }
  254. function DefineForeignKeyValue($value)
  255. {
  256. $this->m_foreignKeyValue = $value;
  257. }
  258. ///<function name="ProcessRecords" access="public">
  259. /// <summary>DEPRECIATED DO NOT USE</summary>
  260. ///<param name="XMLEncoding" type="string" >Do not use</param>
  261. /// <remarks>To set encoding use the 'encoding' parameter of the methods toXML or completeGet</remarks>
  262. ///</function>
  263. function ProcessRecords($XMLEncoding="UTF-8")
  264. {
  265. // this is a no op
  266. }
  267. ///<function name="DefineField" access="public">
  268. /// <summary>Allows the description of data without record being added.
  269. /// This allows the combo to render when there are zero records.</summary>
  270. /// <remarks>The fields do not have to be pre-defined. Fields are now
  271. /// created base on the records. Whenever a record is added all of
  272. /// the records fields are added to the global list of fields.
  273. /// Note DefineFields must be called if no records are added to the EBAGetHandler object.
  274. /// </remarks>
  275. ///<param name="XMLEncoding" type="string" ></param>
  276. ///</function>
  277. function DefineField($FieldName)
  278. {
  279. $this->m_ColunmNames[$FieldName] = 1;
  280. }
  281. ///<function name="CreateNewRecord" access="public">
  282. /// <summary>DEPRECIATED DO NOT USE</summary>
  283. /// <remarks>The supported method to create record is to call $currentRecord = new EBARecord($KeyVal);
  284. /// </remarks>
  285. ///</function>
  286. function CreateNewRecord($KeyVal)
  287. {
  288. $this->m_currentRecord = new EBARecord($KeyVal);
  289. }
  290. ///<function name="SaveRecord" access="public">
  291. /// <summary>DEPRECIATED DO NOT USE</summary>
  292. /// <remarks>The supported method of adding records is to call $currentGetHanlder->add($currentRecord);
  293. /// </remarks>
  294. ///</function>
  295. function SaveRecord()
  296. {
  297. $this->add($this->m_currentRecord);
  298. $this->m_currentRecord = "";
  299. }
  300. ///<function name="DefineRecordFieldValue" access="public">
  301. /// <summary>DEPRECIATED DO NOT USE</summary>
  302. /// <remarks>The supported method of adding field-value pairs is: $currentRecord->add($ColName, $DataValue)
  303. /// </remarks>
  304. ///</function>
  305. function DefineRecordFieldValue($ColName, $DataValue)
  306. {
  307. $this->m_currentRecord->add($ColName, $DataValue);
  308. }
  309. ///<function name="add" access="public">
  310. /// <summary> The 'record' added will become a row element in the eba xml</summary>
  311. ///<param name="record" type="EBARecord" >The record to add</param>
  312. ///</function>
  313. function add($record)
  314. {
  315. # add all the ColumnNames
  316. foreach ($record->getRows() as $columnName => $dummy)
  317. {
  318. $this->m_ColunmNames[$columnName] = 1;
  319. }
  320. # add the Rows
  321. $this->m_Rows[$record->getID()] = $record->getRows();
  322. }
  323. ///<function name="setLocaleConverter" access="public">
  324. /// <summary> Set the localeConverter. This is only needed if different character set are used.</summary>
  325. ///<param name="LocaleConverter" type="ILocaleConverter" >The localeConverter used to generate the EBA compessed xml response</param>
  326. ///</function>
  327. function setLocaleConverter($localeConverter)
  328. {
  329. $this->m_localeConverter = $localeConverter;
  330. }
  331. ///<function name="setDataLanguage" access="public">
  332. /// <summary> Set the datalanguage used for xml:lang</summary>
  333. ///<param name="language" type="string" >The value used for xml:lang</param>
  334. ///</function>
  335. function setDataLanguage($language)
  336. {
  337. $this->m_dataLanguage = $language;
  338. }
  339. ///<function name="setErrorMessage" access="public">
  340. ///<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>
  341. ///<param name="message" type="string" >The value for the error message</param>
  342. ///</function>
  343. function setErrorMessage($message)
  344. {
  345. $this->m_ErrorMessage = $message;
  346. }
  347. ///<function name="completeGet" access="public">
  348. /// <summary> Prints UTF-8 EBA XML to the respone</summary>
  349. ///</function>
  350. function completeGet($encoding="UTF-8")
  351. {
  352. header("Content-type:text/xml;charset=$encoding");
  353. print $this->toXML($encoding);
  354. }
  355. ///<function name="toXML" access="public">
  356. /// <summary> Creates an compressed EBA XML document based on the records added to the getHandler object</summary>
  357. /// <returns type="string"> compressed UTF-8 EBA XML document</returns>
  358. ///</function>
  359. function toXML($encoding="UTF-8")
  360. {
  361. $results = "<?xml version=\"1.0\" encoding=\"$encoding\" ?>";
  362. # print the columns as the fields attribute of the opening root tag
  363. $results .= "<root xml:lang=\"{$this->m_dataLanguage}\" primaryfield=\"{$this->m_primaryKey}\" fields=\"".
  364. strtr(implode("|",array_keys($this->m_ColunmNames)),$this->m_TranscodeList)."\"";
  365. if ($this->m_ErrorMessage != "")
  366. {
  367. $results .= " error=\"" . strtr($this->m_ErrorMessage,$this->m_TranscodeList) . "\"";
  368. }
  369. if ($this->m_totalRowCount != NULL)
  370. {
  371. $results .= " totalrowcount=\"" . $this->m_totalRowCount . "\"";
  372. }
  373. if ($this->m_foreignKey != NULL)
  374. {
  375. $results .= " parentfield=\"" . $this->m_foreignKey . "\"";
  376. }
  377. if ($this->m_foreignKeyValue != NULL)
  378. {
  379. $results .= " parentvalue=\"" . $this->m_foreignKeyValue . "\"";
  380. }
  381. $results .= ">";
  382. # print the rows
  383. # following is an example row
  384. # <e xk="de" a="de" b="images/flags/de_flag.gif" c="Deutschland"/>
  385. # create compression indexes a,..,z,aa,ab,..,zy,zz
  386. $EBAColumnOrder = range('a','z');
  387. foreach ($this->m_Rows as $rowID => $rowArray)
  388. {
  389. $results .= "<e xk=\"".strtr($rowID,$this->m_TranscodeList)."\"";
  390. $EBAIndex = -1;
  391. $EBASubIndex = 0;
  392. foreach ($this->m_ColunmNames as $columnName => $dummy)
  393. {
  394. if(count($EBAColumnOrder) <= $EBASubIndex)
  395. {
  396. $EBASubIndex = 0;
  397. $EBAIndex++;
  398. }
  399. $ColumnKey = $EBAColumnOrder[$EBASubIndex];
  400. if($EBAIndex > -1)
  401. {
  402. $ColumnKey = $EBAColumnOrder[$EBAIndex].$ColumnKey;
  403. }
  404. # index "$EBAColumnOrder[$index]$EBAColumnOrder[$subIndex]";
  405. $results .= " $ColumnKey=\"".strtr($rowArray[$columnName],$this->m_TranscodeList)."\"";
  406. $EBASubIndex++;
  407. }
  408. $results .= " />\n";
  409. }
  410. // finish document
  411. $results .= ( "</root>");
  412. return $this->m_localeConverter->createUnicodeString($results);
  413. }
  414. }
  415. ///</class>
  416. class EBASaveHandler
  417. {
  418. var $InsertRecords = array();
  419. var $UpdateRecords = array();
  420. var $DeleteRecords = array();
  421. var $InsertCount = 0;
  422. var $UpdateCount = 0;
  423. var $DeleteCount = 0;
  424. var $Fields = array();
  425. var $FieldsCount = 0;
  426. var $FieldsSet = array();
  427. var $XmlStr;
  428. var $m_ErrorMessage;
  429. var $m_ForeignKeyValue;
  430. var $m_PrimaryKey;
  431. # XML's reserved chars and their entity references
  432. var $m_TranscodeList = array(
  433. "&" => "&amp;", # Make sure to replace this first.
  434. "\"" => "&quot;",
  435. "<" => "&lt;",
  436. ">" => "&gt;",
  437. "\n" => "&#10;",);
  438. function EBASaveHandler()
  439. {
  440. $this->XmlStr = $GLOBALS["HTTP_RAW_POST_DATA"];
  441. }
  442. function CompleteSave($encoding="UTF-8")
  443. {
  444. header("Content-type:text/xml;charset=$encoding");
  445. // print $this->toXML($encoding);
  446. $this->XmlStr = str_replace("<root ", "<root primaryfield=\"".$this->m_PrimaryKey."\" ", $this->XmlStr);
  447. if( $this->m_ErrorMessage != "" )
  448. {
  449. print str_replace("<root ", "<root error=\"".strtr($this->m_ErrorMessage,$this->m_TranscodeList)."\" ", $this->XmlStr);
  450. }
  451. else
  452. {
  453. print $this->XmlStr;
  454. }
  455. }
  456. function SetPrimaryKey($theField)
  457. {
  458. $this->m_PrimaryKey = $theField;
  459. }
  460. function ReturnInsertCount()
  461. {
  462. return $this->InsertCount;
  463. }
  464. function ReturnUpdateCount()
  465. {
  466. return $this->UpdateCount;
  467. }
  468. function ReturnDeleteCount()
  469. {
  470. return $this->DeleteCount;
  471. }
  472. ///<function name="setErrorMessage" access="public">
  473. ///<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>
  474. ///<param name="message" type="string" >The value for the error message</param>
  475. ///</function>
  476. function setErrorMessage($message)
  477. {
  478. $this->m_ErrorMessage = $message;
  479. }
  480. //<function name="ReturnInsertField" access="public">
  481. // <summary> Returns the number of insert instructions in the updategram.
  482. // Updategrams (saving instructions) contain 3 types of instructions: INSERT, UPDATE, and DELETE.
  483. // Always process INSERT's first, UPDATE's next, and DELETE's last.</summary>
  484. // <returns type="string"> The value for a field. </returns>
  485. //</function>
  486. function ReturnInsertField($RecordNumber, $FieldName = "")
  487. {
  488. $postData = $GLOBALS["HTTP_RAW_POST_DATA"];
  489. $EBAResultValue = "";
  490. $EBASearchField = "";
  491. $index = array_search($FieldName, $this->Fields);
  492. if (($index !== FALSE) || ($FieldName == "") || ($FieldName == "EBAFK"))
  493. {
  494. if ($FieldName == "")
  495. {
  496. $EBASearchField = "xk=\"";
  497. }
  498. else if ($FieldName == "EBAFK")
  499. {
  500. $EBASearchField = "xf=\"";
  501. }
  502. else if (strlen($FieldName) > 0)
  503. {
  504. //"d" should be included here too
  505. //but this test wasn't working for some reason, and actually appending
  506. //the space to ALL EBASearchFields is fine
  507. //$EBASearchField = $this->FieldsSet[$index]."=\"";
  508. //if (($this->FieldsSet[$index] == "d" || $this->FieldsSet[$index] == "k") || ($this->FieldsSet[$index] == "i"))
  509. $EBASearchField = " ".$this->FieldsSet[$index] ."=\"";
  510. }
  511. $EBAUpdateGramTemp = EBAright($postData, strlen($postData) - $this->InsertRecords[$RecordNumber]);
  512. $EBANextPos = strpos($EBAUpdateGramTemp, $EBASearchField);
  513. if ($EBANextPos > 0)
  514. {
  515. $EBAUpdateGramTemp = EBAright($EBAUpdateGramTemp, strlen($EBAUpdateGramTemp) - $EBANextPos - strlen($EBASearchField));
  516. $EBANextPos = strpos($EBAUpdateGramTemp, "\"");
  517. $EBAUpdateGramTemp = EBAleft($EBAUpdateGramTemp,$EBANextPos);
  518. $EBAResultValue = $EBAUpdateGramTemp;
  519. }
  520. }
  521. return $EBAResultValue;
  522. }
  523. function ReturnForeignKeyValue($RecordNumber)
  524. {
  525. return $this->ReturnInsertField($RecordNumber, "EBAFK");
  526. }
  527. function ReturnUpdateField($RecordNumber, $FieldName = "")
  528. {
  529. $postData = $GLOBALS["HTTP_RAW_POST_DATA"];
  530. $EBAResultValue = "";
  531. $EBASearchField = "";
  532. $index = array_search($FieldName, $this->Fields);
  533. if (($index !== FALSE) || ($FieldName == ""))
  534. {
  535. $EBASearchField = "xk=\"";
  536. if (strlen($FieldName) > 0)
  537. {
  538. $EBASearchField = $this->FieldsSet[$index] ."=\"";
  539. //"d" should be included here too
  540. //but this test wasn't working for some reason, and actually appending
  541. //the space to ALL EBASearchFields is fine
  542. //if ($this->FieldsSet[$index] == "d" || $this->FieldsSet[$index] == "k" || $this->FieldsSet[$index] == "i")
  543. $EBASearchField = " ".$this->FieldsSet[$index] ."=\"";
  544. }
  545. $EBAUpdateGramTemp = EBAright($postData, strlen($postData) - $this->UpdateRecords[$RecordNumber]);
  546. $EBANextPos = strpos($EBAUpdateGramTemp, $EBASearchField);
  547. if ($EBANextPos > 0)
  548. {
  549. $EBAUpdateGramTemp = EBAright($EBAUpdateGramTemp, strlen($EBAUpdateGramTemp) - $EBANextPos - strlen($EBASearchField));
  550. $EBANextPos = strpos($EBAUpdateGramTemp, "\"");
  551. $EBAUpdateGramTemp = EBAleft($EBAUpdateGramTemp, $EBANextPos);
  552. $EBAResultValue = $EBAUpdateGramTemp;
  553. }
  554. }
  555. return $EBAResultValue;
  556. }
  557. function ReturnDeleteField($RecordNumber)
  558. {
  559. $postData = $GLOBALS["HTTP_RAW_POST_DATA"];
  560. $EBAResultValue = "";
  561. $EBASearchField = "xk=\"";
  562. $EBADeleteGramTemp = EBAright($postData, strlen($postData) - $this->DeleteRecords[$RecordNumber]);
  563. $EBANextPos = strpos($EBADeleteGramTemp, $EBASearchField);
  564. if ($EBANextPos > 0)
  565. {
  566. $EBADeleteGramTemp = EBAright($EBADeleteGramTemp, strlen($EBADeleteGramTemp) - $EBANextPos - strlen($EBASearchField));
  567. $EBANextPos = strpos($EBADeleteGramTemp, "\"");
  568. $EBADeleteGramTemp = EBAleft($EBADeleteGramTemp, $EBANextPos);
  569. $EBAResultValue = $EBADeleteGramTemp;
  570. }
  571. return $EBAResultValue;
  572. }
  573. //<function name="ProcessRecords" access="public">
  574. // <summary>This function initializes the SaveHandler based on the data in the GLOBALS[HTTP_RAW_POST_DATA] </summary>
  575. // <returns type="string"> The value for a field</returns>
  576. //</function>
  577. function ProcessRecords()
  578. {
  579. $postData = $GLOBALS["HTTP_RAW_POST_DATA"];
  580. # Populate EBAGetHandler_Fields with the fields names
  581. $EBAUpdategram = $postData;
  582. //print("POST DATA:" . $GLOBALS["HTTP_RAW_POST_DATA"]);
  583. $ParsePos = 0;
  584. if (strlen($EBAUpdategram) > 5)
  585. {
  586. $ParsePos = strpos(strtolower($EBAUpdategram), "fields");
  587. $ParsePos = strpos(EBAright($EBAUpdategram, strlen($EBAUpdategram) - $ParsePos), "\"") + 7;
  588. $EBAUpdategram = EBAright($EBAUpdategram, strlen($EBAUpdategram) - $ParsePos);
  589. #Begin grabbing fields
  590. $EBANextPos = 0;
  591. $EBAFieldName = "";
  592. do
  593. {
  594. $EBANextPos = strpos($EBAUpdategram, "|");
  595. $EBANextPos = min($EBANextPos, strpos($EBAUpdategram, "\""));
  596. if ($EBANextPos > 0)
  597. {
  598. $EBAFieldName = EBAleft($EBAUpdategram, $EBANextPos);
  599. $EBAUpdategram = EBAright($EBAUpdategram, strlen($EBAUpdategram) - $EBANextPos - 1);
  600. $this->Fields[$this->FieldsCount] = $EBAFieldName;
  601. $this->FieldsCount += 1;
  602. }
  603. }
  604. while ($EBANextPos > 0);
  605. $EBANextPos = strpos($EBAUpdategram, "\"");
  606. if ($EBANextPos > 0)
  607. {
  608. $EBAFieldName = EBAleft($EBAUpdategram, $EBANextPos);
  609. $EBAUpdategram = EBAright($EBAUpdategram, strlen($EBAUpdategram) - $EBANextPos - 1);
  610. $this->Fields[$this->FieldsCount] = $EBAFieldName;
  611. $this->FieldsCount += 1;
  612. }
  613. # Now we count the insert instructions
  614. $EBAUpdategram = $postData;
  615. $EBAUpdateGramTemp = $EBAUpdategram;
  616. $EBATotalCount = 0;
  617. do
  618. {
  619. $EBANextPos = strpos($EBAUpdateGramTemp, "<insert");
  620. if ($EBANextPos > 0)
  621. {
  622. $EBATotalCount += $EBANextPos+1;
  623. $this->InsertRecords[$this->InsertCount] = $EBATotalCount;
  624. $this->InsertCount += 1;
  625. $EBAUpdateGramTemp = EBAright($EBAUpdateGramTemp, strlen($EBAUpdateGramTemp) - $EBANextPos - 1);
  626. }
  627. }
  628. while ($EBANextPos > 0);
  629. $EBAUpdateGramTemp = $EBAUpdategram;
  630. $EBATotalCount = 0;
  631. do
  632. {
  633. $EBANextPos = strpos($EBAUpdateGramTemp, "<update");
  634. if ($EBANextPos > 0)
  635. {
  636. $EBATotalCount += $EBANextPos;
  637. $this->UpdateRecords[$this->UpdateCount] = $EBATotalCount;
  638. $this->UpdateCount += 1;
  639. $EBAUpdateGramTemp = EBAright($EBAUpdateGramTemp, strlen($EBAUpdateGramTemp) - $EBANextPos - 1);
  640. }
  641. }
  642. while ($EBANextPos > 0);
  643. $EBAUpdateGramTemp = $EBAUpdategram;
  644. $EBATotalCount = 0;
  645. do
  646. {
  647. $EBANextPos = strpos($EBAUpdateGramTemp, "<delete");
  648. if ($EBANextPos > 0)
  649. {
  650. $EBATotalCount += $EBANextPos;
  651. $this->DeleteRecords[$this->DeleteCount] = $EBATotalCount;
  652. $this->DeleteCount += 1;
  653. $EBAUpdateGramTemp = EBAright($EBAUpdateGramTemp, strlen($EBAUpdateGramTemp) - $EBANextPos - 1);
  654. }
  655. }
  656. while ($EBANextPos > 0);
  657. $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');
  658. $MainSetCounter = 0;
  659. for ( $index = 0; $index < 26; $index += 1)
  660. {
  661. $this->FieldsSet[$index] = $EBAFieldOrder[$index];
  662. $MainSetCounter += 1;
  663. }
  664. for ( $index = 0; $index < 26; $index += 1)
  665. {
  666. for ( $subIndex = 0; $subIndex < 26; $subIndex += 1)
  667. {
  668. $this->FieldsSet[$MainSetCounter] = $EBAFieldOrder[$index] . $EBAFieldOrder[$subIndex];
  669. $MainSetCounter += 1;
  670. }
  671. }
  672. }
  673. else
  674. {
  675. print "No valid EBA updategram was discovered!";
  676. }
  677. }
  678. //<function name="SetRecordKey" access="public">
  679. // <summary>In the case of an insert, we need to communicate back to the client
  680. // the new key for this record. After inserting into the database, call
  681. // this method to add the new key to the response back to the client.</summary>
  682. //</function>
  683. function SetRecordKey($RecordNumber, $key)
  684. {
  685. //
  686. $EBAUpdateGramTemp = EBAright($this->XmlStr, strlen($this->XmlStr) - $this->InsertRecords[$RecordNumber]);
  687. $EBANextPos = strpos($EBAUpdateGramTemp, "xk");
  688. $EBAInsertPos = strpos($this->XmlStr, $EBAUpdateGramTemp);
  689. if ($EBANextPos > 0)
  690. {
  691. $EBAUpdateGramWithKey = substr_replace($EBAUpdateGramTemp, "xk=\"" . $key . "\"", $EBANextPos, 5);
  692. $this->XmlStr = substr_replace($this->XmlStr, $EBAUpdateGramWithKey, $EBAInsertPos);
  693. }
  694. }
  695. }
  696. function EBAleft ($str, $howManyCharsFromLeft)
  697. {
  698. return substr ($str, 0, $howManyCharsFromLeft);
  699. }
  700. function EBAright ($str, $howManyCharsFromRight)
  701. {
  702. $strLen = strlen ($str);
  703. return substr ($str, $strLen - $howManyCharsFromRight, $strLen);
  704. }
  705. function EBAmid ($str, $start, $howManyCharsToRetrieve = 0)
  706. {
  707. $start--;
  708. if ($howManyCharsToRetrieve == 0)
  709. $howManyCharsToRetrieve = strlen ($str) - $start;
  710. return substr ($str, $start, $howManyCharsToRetrieve);
  711. }
  712. function getDateForMysqlDateField($val)
  713. {
  714. preg_match("#^([0-9]{2})/([0-9]{2})/([0-9]{4})#",$val,$Match);
  715. return(mktime(0,0,0,$Match[2],$Match[1],$Match[3]));
  716. }
  717. ?>