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.

200 lines
6.3 KiB

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