You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

235 lines
7.5 KiB

26 years ago
  1. <?
  2. $id = 188178; // A plain/text document
  3. $collid = 169828; // A collection
  4. $query = "Name=m*"; // Search query for test_9
  5. $host = "gehtnix";
  6. $username = "annonymous";
  7. $password = "";
  8. $connect = hw_connect($host, 418, $username, $password);
  9. if(hw_error($connect)) {
  10. echo "ERROR: ".hw_errormsg($connect)."\n";
  11. exit;
  12. }
  13. // Set all test to 'yes' if they shall be executed
  14. $test_1 = "no"; // Get the text document with id $id and output it
  15. $test_2 = "no"; // Check if id $id is in $collid
  16. $test_3 = "no"; // Convert object record to object array and back
  17. $test_4 = "no"; // Get object record of object with id $id
  18. $test_5 = "no"; // List children of $collid
  19. $test_6 = "no"; // List parents of $id
  20. $test_7 = "no"; // Insert a new text document
  21. $test_8 = "no"; // Remove the just inserted text document
  22. $test_9 = "no"; // Searching for objects with Name $query
  23. $test_10= "no"; // Listing all anchors of a document
  24. $test_11= "no"; // Creates document from file and outputs it.
  25. $test_12= "yes"; // Creates document from file and outputs it.
  26. /* Lists an object array
  27. */
  28. function list_attr($attributes) {
  29. // var_dump($attributes);
  30. // return;
  31. for($i=0; $i<count($attributes); $i++) {
  32. $key = key($attributes);
  33. switch($key) {
  34. case "Title":
  35. case "Description":
  36. $title_arr = $attributes[$key];
  37. $cj = count($title_arr);
  38. printf("%s = ", $key);
  39. for($j=0; $j<$cj; $j++) {
  40. $tkey = key($title_arr);
  41. switch($tkey) {
  42. case "en":
  43. $flagfile = "english.gif";
  44. break;
  45. case "ge":
  46. $flagfile = "german.gif";
  47. break;
  48. case "du":
  49. $flagfile = "dutch.gif";
  50. break;
  51. default:
  52. $flagfile = "europe.gif";
  53. }
  54. printf("%s:%s; ", $tkey, $title_arr[$tkey]);
  55. next($title_arr);
  56. }
  57. printf("\n");
  58. break;
  59. default:
  60. if(is_array($attributes[$key])) {
  61. $group_arr = $attributes[$key];
  62. $cj = count($group_arr);
  63. for($j=0; $j<$cj; $j++) {
  64. printf("%s = %s\n", $key, $group_arr[$j]);
  65. next($group_arr);
  66. }
  67. } else {
  68. printf("%s = %s\n", $key, $attributes[$key]);
  69. }
  70. }
  71. next($attributes);
  72. }
  73. echo "\n";
  74. }
  75. // Here come the tests
  76. if($test_1 == "yes") {
  77. echo "TEST 1 ----------------------------------------------\n";
  78. echo "Get the text document with id 0x".dechex($id)."\n";
  79. $doc = hw_gettext($connect, $id);
  80. if(hw_error($connect)) {
  81. echo "ERROR: ".hw_errormsg($connect)."\n";
  82. exit;
  83. }
  84. hw_output_document($doc);
  85. echo "\n";
  86. }
  87. if($test_2 == "yes") {
  88. echo "TEST 2 ----------------------------------------------\n";
  89. echo "Checking if '$id' (0x".dechex($id).") is in collection '$collid (0x".dechex($collid).")'\n";
  90. $incoll = hw_incollections($connect, array($id), array($collid), 0);
  91. if(hw_error($connect)) {
  92. echo "ERROR: ".hw_errormsg($connect)."\n";
  93. exit;
  94. }
  95. for($i=0; $i<count($incoll); $i++)
  96. echo $incoll[$i]."\n";
  97. }
  98. if($test_3 == "yes") {
  99. echo "TEST 3 ----------------------------------------------\n";
  100. echo "Convert an object array into an object record\n";
  101. $objrec = hw_array2objrec(array("Title"=>"ge:Hier der Titel", "Author"=>"Hier der Autor"));
  102. echo $objrec."\n";
  103. $objrec .= "\nTitle=en:Here the title";
  104. echo "Add another title and convert it back to an object array\n";
  105. $objarr = hw_objrec2array($objrec);
  106. list_attr($objarr);
  107. }
  108. if($test_4 == "yes") {
  109. echo "TEST 4 ----------------------------------------------\n";
  110. echo "Get the object array of document with id 0x".dechex($id)."\n";
  111. $objrec = hw_getobject($connect, $id);
  112. if(hw_error($connect)) {
  113. echo "ERROR: ".hw_errormsg($connect)."\n";
  114. exit;
  115. }
  116. $objarr = hw_objrec2array($objrec);
  117. list_attr($objarr);
  118. }
  119. if($test_5 == "yes") {
  120. echo "TEST 5 ----------------------------------------------\n";
  121. echo "List the children of collection 0x".dechex($collid)."\n";
  122. $children = hw_childrenobj($connect, $collid);
  123. if(hw_error($connect)) {
  124. echo "ERROR: ".hw_errormsg($connect)."\n";
  125. exit;
  126. }
  127. $c_children = count($children) - 1;
  128. for($i=0; $i<$c_children; $i++) {
  129. $objarr = hw_objrec2array($children[$i]);
  130. list_attr($objarr);
  131. }
  132. list_attr($children[$c_children]);
  133. }
  134. if($test_6 == "yes") {
  135. echo "TEST 6 ----------------------------------------------\n";
  136. echo "List the parents of object 0x".dechex($id)."\n";
  137. $parents = hw_getparentsobj($connect, $collid);
  138. if(hw_error($connect)) {
  139. echo "ERROR: ".hw_errormsg($connect)."\n";
  140. exit;
  141. }
  142. $c_parents = count($parents) - 1;
  143. for($i=0; $i<$c_parents; $i++) {
  144. $objarr = hw_objrec2array($parents[$i]);
  145. list_attr($objarr);
  146. }
  147. list_attr($parents[$c_parents]);
  148. }
  149. if($test_7 == "yes") {
  150. echo "TEST 7 ----------------------------------------------\n";
  151. echo "Inserting a new text document into 0x".dechex($collid)."\n";
  152. $objrec = "Type=Document\nDocumentType=text\nName=HWTest\nTitle=en:Component\nMimeType=text/plain\nAuthor=".$username;
  153. $contents = "Ein bischen Text";
  154. $doc = hw_new_document($objrec, $contents, strlen($contents)+1);
  155. $objid = hw_insertdocument($connect, $collid, $doc);
  156. if(hw_error($connect)) {
  157. echo "ERROR: ".hw_errormsg($connect)."\n";
  158. exit;
  159. }
  160. $objrec = hw_getobject($connect, $objid);
  161. if(hw_error($connect)) {
  162. echo "ERROR: ".hw_errormsg($connect)."\n";
  163. exit;
  164. }
  165. $objarr = hw_objrec2array($objrec);
  166. list_attr($objarr);
  167. }
  168. if($test_8 == "yes") {
  169. echo "TEST 8 ----------------------------------------------\n";
  170. echo "Removing text document just inserted\n";
  171. $kk[0] = (int) $objid;
  172. hw_mv($connect, $kk, $collid, 0);
  173. if(hw_error($connect)) {
  174. echo "ERROR: ".hw_errormsg($connect)."\n";
  175. exit;
  176. }
  177. echo "If the document was really deleted you should see an error now\n";
  178. $objrec = hw_getobject($connect, $objid);
  179. if(hw_error($connect)) {
  180. echo "ERROR: ".hw_errormsg($connect)."\n";
  181. } else {
  182. $objarr = hw_objrec2array($objrec);
  183. list_attr($objarr);
  184. }
  185. }
  186. if($test_9 == "yes") {
  187. echo "TEST 9 ----------------------------------------------\n";
  188. echo "Searching for objects with $query\n";
  189. $objrecs = hw_getobjectbyqueryobj($connect, $query, -1);
  190. $c_objrecs = count($objrecs) - 1;
  191. echo "$c_objrecs found\n";
  192. for($i=0; $i<$c_objrecs; $i++) {
  193. $objarr = hw_objrec2array($objrecs[$i]);
  194. list_attr($objarr);
  195. }
  196. list_attr($objrecs[$c_objrecs]);
  197. }
  198. if($test_10 == "yes") {
  199. $anchors = hw_getanchorsobj($connect, $id);
  200. $countanchors = count($anchors) - 1;
  201. echo "$countanchors Anchors of Object $id\n";
  202. for($i=0; $i<$countanchors; $i++) {
  203. $arr = hw_objrec2array($anchors[$i]);
  204. list_attr($arr);
  205. }
  206. }
  207. if($test_11 == "yes") {
  208. $doc = hw_new_document_from_file("ObjectRecord", "hw_document.txt");
  209. hw_output_document($doc);
  210. }
  211. if($test_12 == "yes") {
  212. $doc = hw_new_document_from_file("ObjectRecord", "hw_document.txt");
  213. hw_insertanchors($doc, array("Position=0x2 0x7\nObjectID=0x3\nTAnchor=Src\nDest=0x5"), array("ObjectID=0x5\nName=DestDoc"));
  214. hw_output_document($doc);
  215. }
  216. hw_close($connect);
  217. ?>