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.

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