diff -Nupwbr -x .svn kt/includes/KnowledgeTreeService_REST.php /tmp/kt/includes/KnowledgeTreeService_REST.php
--- kt/includes/KnowledgeTreeService_REST.php	1969-12-31 16:00:00.000000000 -0800
+++ /tmp/kt/includes/KnowledgeTreeService_REST.php	2009-08-02 13:37:21.000000000 -0700
@@ -0,0 +1,928 @@
+<?php
+
+/*
+ * Generated automatically from KT 3.6.1 WSDL
+ * Using WSDL->PHP generator http://code.google.com/p/wsdl2php-interpreter/
+ * with a few custom tweaks
+ *
+ * Added login code and REST call function
+ *
+ * @author aantonop
+ */
+include "KnowledgeTreeService_classes.php";
+
+if (!class_exists("KnowledgeTreeRESTService")) {
+
+
+  /**
+   * KnowledgeTreeRESTService
+   * @author WSDLInterpreter
+   */
+  class KnowledgeTreeRESTService {
+    /**
+     * Default class map for wsdl=>php
+     * @access private
+     * @var array
+     */
+    private static $classmap = array(
+		"kt_response" => "kt_response",
+		"kt_folder_detail" => "kt_folder_detail",
+		"kt_folder_item" => "kt_folder_item",
+		"kt_folder_items" => "kt_folder_items",
+		"kt_folder_contents" => "kt_folder_contents",
+		"kt_document_detail" => "kt_document_detail",
+		"kt_search_result_item" => "kt_search_result_item",
+		"kt_search_results" => "kt_search_results",
+		"kt_search_response" => "kt_search_response",
+		"kt_sysdata_item" => "kt_sysdata_item",
+		"kt_sysdata" => "kt_sysdata",
+		"kt_metadata_selection_item" => "kt_metadata_selection_item",
+		"kt_metadata_selection" => "kt_metadata_selection",
+		"kt_metadata_field" => "kt_metadata_field",
+		"kt_metadata_fields" => "kt_metadata_fields",
+		"kt_metadata_fieldset" => "kt_metadata_fieldset",
+		"kt_metadata_fieldsets" => "kt_metadata_fieldsets",
+		"kt_metadata_response" => "kt_metadata_response",
+		"kt_workflow_transitions" => "kt_workflow_transitions",
+		"kt_workflow_transitions_response" => "kt_workflow_transitions_response",
+		"kt_workflows_array" => "kt_workflows_array",
+		"kt_workflows_response" => "kt_workflows_response",
+		"kt_document_transaction_history_item" => "kt_document_transaction_history_item",
+		"kt_linked_document" => "kt_linked_document",
+		"kt_linked_documents" => "kt_linked_documents",
+		"kt_linked_document_response" => "kt_linked_document_response",
+		"kt_document_transaction_history" => "kt_document_transaction_history",
+		"kt_document_transaction_history_response" => "kt_document_transaction_history_response",
+		"kt_document_version_history_item" => "kt_document_version_history_item",
+		"kt_document_collection" => "kt_document_collection",
+		"kt_document_collection_response" => "kt_document_collection_response",
+		"kt_folder_collection" => "kt_folder_collection",
+		"kt_folder_collection_response" => "kt_folder_collection_response",
+		"kt_document_version_history" => "kt_document_version_history",
+		"kt_document_version_history_response" => "kt_document_version_history_response",
+		"kt_document_types_array" => "kt_document_types_array",
+		"kt_document_types_response" => "kt_document_types_response",
+		"kt_client_policy" => "kt_client_policy",
+		"kt_client_policies_array" => "kt_client_policies_array",
+		"kt_client_policies_response" => "kt_client_policies_response",
+    );
+
+    /**
+     * Store session URL and session ID
+     */
+    var $session = Array(
+    	'session_id' => NULL,
+    	'session_url' => '', // Example: 'http://localhost/ktwebservice/KTWebService.php'
+        'username' => '',
+    );
+
+    /**
+     * A very basic error log, as a string
+     * @var string
+     */
+    public $error;
+
+    /**
+     * Log an error or debug notice
+     *
+     * This is meant to be extended by a child class to provide real logging
+     * for example, extend and send to syslog or a file or multiple files
+     *
+     * This stub ignores the level argument and simply appends to the error string
+     *
+     */
+    function log($log, $level="ERROR") {
+      $this->error .= "\n". $error;
+    }
+
+    /**
+     * Call the REST API over HTTP
+     *
+     * All the stub functions use this to make the REST call
+     * If there is an existing session it uses it. If not you can only call "login" to set a session up.
+     *
+     */
+    function _kt_REST_call($method, $args) {
+
+      $url = $this->session['session_url'].'?';
+
+      // Check if there is an existing session or if this is the login call
+      if (!isset($this->session['session_id']) && $method != "login") { // Haven't opened a session yet, must log in first
+        $this->log("Trying to execute method ". $method ." without an established session. You must call login method first!", "ERROR");
+        return FALSE;
+      } // Either login method or session exists
+      else if (isset($this->session['session_id'])) { // Session exists
+        $url = $url.'session_id='. $this->session['session_id'] ."&";
+      }
+
+      $rest_call_url = $url ."method=". $method . $args;
+      $this->log("Executing REST call: ".$rest_call_url, "DEBUG");
+
+      if ($result = $this->_kt_http_get($rest_call_url)) { // HTTP call succeeded
+        try {
+          $response = @new SimpleXMLElement($result);
+        } catch (Exception $e) { // SimpleXMLElement processing failed
+          $this->log("XML processing failed with error:".$e."\n...while processing XML response:\n<pre>".print_r($result,TRUE).'</pre>', 'ERROR');
+          return FALSE;
+        }
+        if ($response->status_code == 0) { // REST call success
+          $this->log("\n\n=======\n\nREST Call Request: ".$rest_call_url."\nCall Results: ".print_r($response->results,TRUE)."\n\n========\n", "DEBUG");
+          return $response->results;
+        }
+        else { // REST Call failed
+          $this->log('REST Call failed with message: '. $response->message, "WARNING");
+          return FALSE;
+        }
+      }
+      else { // HTTP call failed
+        return FALSE;
+      }
+    }
+
+    /**
+     * Make an HTTP call
+     * This is meant to be extended and overriden by whatever HTTP library you use
+     * eg. curl or pecl_http
+     * This example uses drupal's http request
+     *
+     */
+    function _kt_http_get ($url) {
+
+      $response = drupal_http_request($url, array('Content-Type' => 'text/xml'), "GET");
+
+      if($response->code == 200) { // HTTP Call success
+        $this->log("HTTP Call succeeded for ". $url, "DEBUG");
+        return $response->data;
+      }
+      else { // HTTP Call failed
+        $this->log('HTTP Error '. $response->code .' - on REST Call with URL '. $url, "ERROR");
+        return FALSE;
+      }
+    }
+
+    /**
+     * REST Call: login
+     *
+     * @author aantonop - rewritten from stub
+     *
+     * Parameter options:
+     * (string) username, (string) password, (string) ip
+     * @return (boolean) success, stores session in object
+     */
+    function login($url, $username, $password) {
+
+      $this->session = array(
+        'session_url' => $url,
+      	'username' => $username,
+      );
+
+      if ($response = $this->_kt_REST_call("login", "&username=". urlencode($username) ."&password=". urlencode($password))) {
+        $this->session['session_id'] = (string)$response;
+        return TRUE;
+      }
+      else {
+        $this->log("Login Failed", "ERROR");
+        return FALSE;
+      }
+
+    }
+
+
+    /**
+     *
+     * Rest of these functions are stubs. They may work "right out of the box" or may need some tweaking
+     * Not all the functions listed in the WSDL are currently supported by the REST API
+     * Some are only supported by the SOAP API
+     *
+     */
+
+	/**
+	 * REST Call: search
+	 *
+	 * Read the document search2/docs/userguide.txt in KT's root directory
+	 *
+	 * The core of the search engine is the 'expression language'.
+     * Expressions may be built up using the following grammar:
+     * expr ::= expr { AND | OR } expr
+     * expr ::= NOT expr
+     * expr ::= expr { < | <= | = | > | >= | CONTAINS |STARTS WITH | ENDS WITH } value
+     * expr ::= field BETWEEN value AND value
+     * expr ::= field DOES [ NOT ] CONTAIN value
+     * expr ::= field IS [ NOT ] LIKE value
+     * value ::= "search text here"
+     *
+     * A field may be one of the following:
+     * CheckedOut , CheckedOutBy , CheckedoutDelta , Created , CreatedBy , CreatedDelta , DiscussionText , DocumentId ,
+     * DocumentText , DocumentType , Filename , Filesize , Folder , GeneralText , IsCheckedOut , IsImmutable ,
+     * Metadata , MimeType , Modified , ModifiedBy , ModifiedDelta , Tag , Title , Workflow ,
+     * WorkflowID , WorkflowState , WorkflowStateID
+     *
+     * A 'field' may also refer to metadata using the following syntax:
+     * ["fieldset name"]["field name"]
+     *
+     * Note that 'values' must be contained within "double quotes".
+     *
+     * Example for $search argument: 'Filename CONTAINS "e"'
+     *
+     * Note: $options seems to be ignored, but has to contain a value. I pass "none" and it works
+     *
+     *
+	 * Parameter options:
+	 * (string) search, (string) options
+	 * @return kt_search_response
+	 */
+	public function search($search, $options) {
+		$rest_args = '&query='. urlencode($search) .'&options='. urlencode($options);
+		return $this->_kt_REST_call("search", $rest_args);
+	}
+
+
+	/**
+	 * REST Call: anonymous_login
+	 * Parameter options:
+	 * (string) ip
+	 * @return kt_response
+	 */
+	public function anonymous_login($ip) {
+		$rest_args = '&ip='. urlencode($ip);
+		return $this->_kt_REST_call("anonymous_login", $rest_args);
+	}
+
+
+	/**
+	 * REST Call: logout
+	 * @return kt_response
+	 */
+	public function logout() {
+		return $this->_kt_REST_call("logout", "");
+	}
+
+
+	/**
+	 * REST Call: get_folder_detail
+	 * Parameter options:
+	 * (integer) folder_id
+	 * @return kt_folder_detail
+	 */
+	public function get_folder_detail($folder_id) {
+		$rest_args = '&folder_id='. urlencode($folder_id);
+		return $this->_kt_REST_call("get_folder_detail", $rest_args);
+	}
+
+
+	/**
+	 * REST Call: get_documents_by_oem_no
+	 * Parameter options:
+	 * (string) oem_no, (string) detail
+	 * @return kt_document_collection_response
+	 */
+	public function get_documents_by_oem_no($oem_no, $detail) {
+		$rest_args = '&oem_no='. urlencode($oem_no) .'&detail='. urlencode($detail);
+		return $this->_kt_REST_call("get_documents_by_oem_no", $rest_args);
+	}
+
+
+	/**
+	 * REST Call: get_folder_detail_by_name
+	 * Parameter options:
+	 * (string) folder_name
+	 * @return kt_folder_detail
+	 */
+	public function get_folder_detail_by_name($folder_name) {
+		$rest_args = '&folder_name='. urlencode($folder_name);
+		return $this->_kt_REST_call("get_folder_detail_by_name", $rest_args);
+	}
+
+
+	/**
+	 * REST Call: get_folder_contents
+	 * Parameter options:
+	 * (integer) folder_id, (integer) depth, (string) what
+	 * @return kt_folder_contents
+	 */
+	public function get_folder_contents($folder_id, $depth, $what) {
+		$rest_args = '&folder_id='. urlencode($folder_id) .'&depth='. urlencode($depth) .'&what='. urlencode($what);
+		return $this->_kt_REST_call("get_folder_contents", $rest_args);
+	}
+
+
+	/**
+	 * REST Call: create_folder
+	 * Parameter options:
+	 * (integer) folder_id, (string) folder_name
+	 * @return kt_folder_detail
+	 */
+	public function create_folder($folder_id, $folder_name) {
+		$rest_args = '&folder_id='. urlencode($folder_id) .'&folder_name='. urlencode($folder_name);
+		return $this->_kt_REST_call("create_folder", $rest_args);
+	}
+
+
+	/**
+	 * REST Call: add_folder
+	 * Parameter options:
+	 * (integer) folder_id, (string) folder_name
+	 * @return kt_folder_detail
+	 */
+	public function add_folder($folder_id, $folder_name) {
+		$rest_args = '&folder_id='. urlencode($folder_id) .'&folder_name='. urlencode($folder_name);
+		return $this->_kt_REST_call("add_folder", $rest_args);
+	}
+
+
+	/**
+	 * REST Call: delete_folder
+	 * Parameter options:
+	 * (integer) folder_id, (string) reason
+	 * @return kt_response
+	 */
+	public function delete_folder($folder_id, $reason) {
+		$rest_args = '&folder_id='. urlencode($folder_id) .'&reason='. urlencode($reason);
+		return $this->_kt_REST_call("delete_folder", $rest_args);
+	}
+
+
+	/**
+	 * REST Call: rename_folder
+	 * Parameter options:
+	 * (integer) folder_id, (string) newname
+	 * @return kt_response
+	 */
+	public function rename_folder($folder_id, $newname) {
+		$rest_args = '&folder_id='. urlencode($folder_id) .'&newname='. urlencode($newname);
+		return $this->_kt_REST_call("rename_folder", $rest_args);
+	}
+
+
+	/**
+	 * REST Call: get_document_links
+	 * Parameter options:
+	 * (integer) document_id
+	 * @return kt_linked_document_response
+	 */
+	public function get_document_links($document_id) {
+		$rest_args = '&document_id='. urlencode($document_id);
+		return $this->_kt_REST_call("get_document_links", $rest_args);
+	}
+
+
+	/**
+	 * REST Call: link_documents
+	 * Parameter options:
+	 * (integer) parent_document_id, (integer) child_document_id, (string) type
+	 * @return kt_response
+	 */
+	public function link_documents($parent_document_id, $child_document_id, $type) {
+		$rest_args = '&parent_document_id='. urlencode($parent_document_id) .'&child_document_id='. urlencode($child_document_id) .'&type='. urlencode($type);
+		return $this->_kt_REST_call("link_documents", $rest_args);
+	}
+
+
+	/**
+	 * REST Call: unlink_documents
+	 * Parameter options:
+	 * (integer) parent_document_id, (integer) child_document_id
+	 * @return kt_response
+	 */
+	public function unlink_documents($parent_document_id, $child_document_id) {
+		$rest_args = '&parent_document_id='. urlencode($parent_document_id) .'&child_document_id='. urlencode($child_document_id);
+		return $this->_kt_REST_call("unlink_documents", $rest_args);
+	}
+
+
+	/**
+	 * REST Call: copy_folder
+	 * Parameter options:
+	 * (integer) source_id, (integer) target_id, (string) reason
+	 * @return kt_folder_detail
+	 */
+	public function copy_folder($source_id, $target_id, $reason) {
+		$rest_args = '&source_id='. urlencode($source_id) .'&target_id='. urlencode($target_id) .'&reason='. urlencode($reason);
+		return $this->_kt_REST_call("copy_folder", $rest_args);
+	}
+
+
+	/**
+	 * REST Call: move_folder
+	 * Parameter options:
+	 * (integer) source_id, (integer) target_id, (string) reason
+	 * @return kt_folder_detail
+	 */
+	public function move_folder($source_id, $target_id, $reason) {
+		$rest_args = '&source_id='. urlencode($source_id) .'&target_id='. urlencode($target_id) .'&reason='. urlencode($reason);
+		return $this->_kt_REST_call("move_folder", $rest_args);
+	}
+
+
+	/**
+	 * REST Call: get_document_detail
+	 * Parameter options:
+	 * (integer) document_id, (string) detail
+	 * @return kt_document_detail
+	 */
+	public function get_document_detail($document_id, $detail) {
+		$rest_args = '&document_id='. urlencode($document_id) .'&detail='. urlencode($detail);
+		return $this->_kt_REST_call("get_document_detail", $rest_args);
+	}
+
+
+	/**
+	 * REST Call: checkin_document
+	 * Parameter options:
+	 * (integer) document_id, (string) filename, (string) reason, (string) tempfilename, (boolean) major_update
+	 * @return kt_document_detail
+	 */
+	public function checkin_document($document_id, $filename, $reason, $tempfilename, $major_update) {
+		$rest_args = '&document_id='. urlencode($document_id) .'&filename='. urlencode($filename) .'&reason='. urlencode($reason) .'&tempfilename='. urlencode($tempfilename) .'&major_update='. urlencode($major_update);
+		return $this->_kt_REST_call("checkin_document", $rest_args);
+	}
+
+
+	/**
+	 * REST Call: checkin_small_document
+	 * Parameter options:
+	 * (integer) document_id, (string) filename, (string) reason, (string) base64, (boolean) major_update
+	 * @return kt_document_detail
+	 */
+	public function checkin_small_document($document_id, $filename, $reason, $base64, $major_update) {
+		$rest_args = '&document_id='. urlencode($document_id) .'&filename='. urlencode($filename) .'&reason='. urlencode($reason) .'&base64='. urlencode($base64) .'&major_update='. urlencode($major_update);
+		return $this->_kt_REST_call("checkin_small_document", $rest_args);
+	}
+
+
+	/**
+	 * REST Call: checkin_base64_document
+	 * Parameter options:
+	 * (integer) document_id, (string) filename, (string) reason, (string) base64, (boolean) major_update
+	 * @return kt_document_detail
+	 */
+	public function checkin_base64_document($document_id, $filename, $reason, $base64, $major_update) {
+		$rest_args = '&document_id='. urlencode($document_id) .'&filename='. urlencode($filename) .'&reason='. urlencode($reason) .'&base64='. urlencode($base64) .'&major_update='. urlencode($major_update);
+		return $this->_kt_REST_call("checkin_base64_document", $rest_args);
+	}
+
+
+	/**
+	 * REST Call: checkin_base64_document_with_metadata
+	 * Parameter options:
+	 * (integer) document_id, (string) filename, (string) reason, (string) base64, (boolean) major_update, (kt_metadata_fieldsets) metadata, (kt_sysdata) sysdata
+	 * @return kt_document_detail
+	 */
+	public function checkin_base64_document_with_metadata($document_id, $filename, $reason, $base64, $major_update, $metadata, $sysdata) {
+		$rest_args = '&document_id='. urlencode($document_id) .'&filename='. urlencode($filename) .'&reason='. urlencode($reason) .'&base64='. urlencode($base64) .'&major_update='. urlencode($major_update) .'&metadata='. urlencode($metadata) .'&sysdata='. urlencode($sysdata);
+		return $this->_kt_REST_call("checkin_base64_document_with_metadata", $rest_args);
+	}
+
+
+	/**
+	 * REST Call: checkin_document_with_metadata
+	 * Parameter options:
+	 * (integer) document_id, (string) filename, (string) reason, (string) tempfilename, (boolean) major_update, (kt_metadata_fieldsets) metadata, (kt_sysdata) sysdata
+	 * @return kt_document_detail
+	 */
+	public function checkin_document_with_metadata($document_id, $filename, $reason, $tempfilename, $major_update, $metadata, $sysdata) {
+		$rest_args = '&document_id='. urlencode($document_id) .'&filename='. urlencode($filename) .'&reason='. urlencode($reason) .'&tempfilename='. urlencode($tempfilename) .'&major_update='. urlencode($major_update) .'&metadata='. urlencode($metadata) .'&sysdata='. urlencode($sysdata);
+		return $this->_kt_REST_call("checkin_document_with_metadata", $rest_args);
+	}
+
+
+	/**
+	 * REST Call: add_document
+	 * Parameter options:
+	 * (integer) folder_id, (string) title, (string) filename, (string) documentype, (string) tempfilename
+	 * @return kt_document_detail
+	 */
+	public function add_document($folder_id, $title, $filename, $documentype, $tempfilename) {
+		$rest_args = '&folder_id='. urlencode($folder_id) .'&title='. urlencode($title) .'&filename='. urlencode($filename) .'&documentype='. urlencode($documentype) .'&tempfilename='. urlencode($tempfilename);
+		return $this->_kt_REST_call("add_document", $rest_args);
+	}
+
+
+	/**
+	 * REST Call: add_small_document
+	 * Parameter options:
+	 * (integer) folder_id, (string) title, (string) filename, (string) documentype, (string) base64
+	 * @return kt_document_detail
+	 */
+	public function add_small_document($folder_id, $title, $filename, $documentype, $base64) {
+		$rest_args = '&folder_id='. urlencode($folder_id) .'&title='. urlencode($title) .'&filename='. urlencode($filename) .'&documentype='. urlencode($documentype) .'&base64='. urlencode($base64);
+		return $this->_kt_REST_call("add_small_document", $rest_args);
+	}
+
+
+	/**
+	 * REST Call: add_base64_document
+	 * Parameter options:
+	 * (integer) folder_id, (string) title, (string) filename, (string) documentype, (string) base64
+	 * @return kt_document_detail
+	 */
+	public function add_base64_document($folder_id, $title, $filename, $documentype, $base64) {
+		$rest_args = '&folder_id='. urlencode($folder_id) .'&title='. urlencode($title) .'&filename='. urlencode($filename) .'&documentype='. urlencode($documentype) .'&base64='. urlencode($base64);
+		return $this->_kt_REST_call("add_base64_document", $rest_args);
+	}
+
+
+	/**
+	 * REST Call: add_base64_document_with_metadata
+	 * Parameter options:
+	 * (integer) folder_id, (string) title, (string) filename, (string) documentype, (string) base64, (kt_metadata_fieldsets) metadata, (kt_sysdata) sysdata
+	 * @return kt_document_detail
+	 */
+	public function add_base64_document_with_metadata($folder_id, $title, $filename, $documentype, $base64, $metadata, $sysdata) {
+		$rest_args = '&folder_id='. urlencode($folder_id) .'&title='. urlencode($title) .'&filename='. urlencode($filename) .'&documentype='. urlencode($documentype) .'&base64='. urlencode($base64) .'&metadata='. urlencode($metadata) .'&sysdata='. urlencode($sysdata);
+		return $this->_kt_REST_call("add_base64_document_with_metadata", $rest_args);
+	}
+
+
+	/**
+	 * REST Call: add_document_with_metadata
+	 * Parameter options:
+	 * (integer) folder_id, (string) title, (string) filename, (string) documentype, (string) tempfilename, (kt_metadata_fieldsets) metadata, (kt_sysdata) sysdata
+	 * @return kt_document_detail
+	 */
+	public function add_document_with_metadata($folder_id, $title, $filename, $documentype, $tempfilename, $metadata, $sysdata) {
+		$rest_args = '&folder_id='. urlencode($folder_id) .'&title='. urlencode($title) .'&filename='. urlencode($filename) .'&documentype='. urlencode($documentype) .'&tempfilename='. urlencode($tempfilename) .'&metadata='. urlencode($metadata) .'&sysdata='. urlencode($sysdata);
+		return $this->_kt_REST_call("add_document_with_metadata", $rest_args);
+	}
+
+
+	/**
+	 * REST Call: get_document_detail_by_name
+	 * Parameter options:
+	 * (integer) folder_id, (string) document_name, (string) what, (string) detail
+	 * @return kt_document_detail
+	 */
+	public function get_document_detail_by_name($folder_id, $document_name, $what, $detail) {
+		$rest_args = '&folder_id='. urlencode($folder_id) .'&document_name='. urlencode($document_name) .'&what='. urlencode($what) .'&detail='. urlencode($detail);
+		return $this->_kt_REST_call("get_document_detail_by_name", $rest_args);
+	}
+
+
+	/**
+	 * REST Call: get_document_detail_by_title
+	 * Parameter options:
+	 * (integer) folder_id, (string) title, (string) detail
+	 * @return kt_document_detail
+	 */
+	public function get_document_detail_by_title($folder_id, $title, $detail) {
+		$rest_args = '&folder_id='. urlencode($folder_id) .'&title='. urlencode($title) .'&detail='. urlencode($detail);
+		return $this->_kt_REST_call("get_document_detail_by_title", $rest_args);
+	}
+
+
+	/**
+	 * REST Call: get_document_detail_by_filename
+	 * Parameter options:
+	 * (integer) folder_id, (string) filename, (string) detail
+	 * @return kt_document_detail
+	 */
+	public function get_document_detail_by_filename($folder_id, $filename, $detail) {
+		$rest_args = '&folder_id='. urlencode($folder_id) .'&filename='. urlencode($filename) .'&detail='. urlencode($detail);
+		return $this->_kt_REST_call("get_document_detail_by_filename", $rest_args);
+	}
+
+
+	/**
+	 * REST Call: checkout_document
+	 * Parameter options:
+	 * (integer) document_id, (string) reason, (boolean) download
+	 * @return kt_document_detail
+	 */
+	public function checkout_document($document_id, $reason, $download) {
+		$rest_args = '&document_id='. urlencode($document_id) .'&reason='. urlencode($reason) .'&download='. urlencode($download);
+		return $this->_kt_REST_call("checkout_document", $rest_args);
+	}
+
+
+	/**
+	 * REST Call: checkout_small_document
+	 * Parameter options:
+	 * (integer) document_id, (string) reason, (boolean) download
+	 * @return kt_document_detail
+	 */
+	public function checkout_small_document($document_id, $reason, $download) {
+		$rest_args = '&document_id='. urlencode($document_id) .'&reason='. urlencode($reason) .'&download='. urlencode($download);
+		return $this->_kt_REST_call("checkout_small_document", $rest_args);
+	}
+
+
+	/**
+	 * REST Call: checkout_base64_document
+	 * Parameter options:
+	 * (integer) document_id, (string) reason, (boolean) download
+	 * @return kt_document_detail
+	 */
+	public function checkout_base64_document($document_id, $reason, $download) {
+		$rest_args = '&document_id='. urlencode($document_id) .'&reason='. urlencode($reason) .'&download='. urlencode($download);
+		return $this->_kt_REST_call("checkout_base64_document", $rest_args);
+	}
+
+
+	/**
+	 * REST Call: undo_document_checkout
+	 * Parameter options:
+	 * (integer) document_id, (string) reason
+	 * @return kt_document_detail
+	 */
+	public function undo_document_checkout($document_id, $reason) {
+		$rest_args = '&document_id='. urlencode($document_id) .'&reason='. urlencode($reason);
+		return $this->_kt_REST_call("undo_document_checkout", $rest_args);
+	}
+
+
+	/**
+	 * REST Call: download_document
+	 * Parameter options:
+	 * (integer) document_id
+	 * @return kt_response
+	 */
+	public function download_document($document_id) {
+		$rest_args = '&document_id='. urlencode($document_id);
+		return $this->_kt_REST_call("download_document", $rest_args);
+	}
+
+
+	/**
+	 * REST Call: download_small_document
+	 * Parameter options:
+	 * (integer) document_id
+	 * @return kt_response
+	 */
+	public function download_small_document($document_id) {
+		$rest_args = '&document_id='. urlencode($document_id);
+		return $this->_kt_REST_call("download_small_document", $rest_args);
+	}
+
+
+	/**
+	 * REST Call: download_base64_document
+	 * Parameter options:
+	 * (integer) document_id
+	 * @return kt_response
+	 */
+	public function download_base64_document($document_id) {
+		$rest_args = '&document_id='. urlencode($document_id);
+		return $this->_kt_REST_call("download_base64_document", $rest_args);
+	}
+
+
+	/**
+	 * REST Call: delete_document
+	 * Parameter options:
+	 * (integer) document_id, (string) reason
+	 * @return kt_response
+	 */
+	public function delete_document($document_id, $reason) {
+		$rest_args = '&document_id='. urlencode($document_id) .'&reason='. urlencode($reason);
+		return $this->_kt_REST_call("delete_document", $rest_args);
+	}
+
+
+	/**
+	 * REST Call: change_document_owner
+	 * Parameter options:
+	 * (integer) document_id, (string) username, (string) reason
+	 * @return kt_document_detail
+	 */
+	public function change_document_owner($document_id, $username, $reason) {
+		$rest_args = '&document_id='. urlencode($document_id) .'&username='. urlencode($username) .'&reason='. urlencode($reason);
+		return $this->_kt_REST_call("change_document_owner", $rest_args);
+	}
+
+
+	/**
+	 * REST Call: copy_document
+	 * Parameter options:
+	 * (integer) document_id, (integer) folder_id, (string) reason, (string) options
+	 * @return kt_document_detail
+	 */
+	public function copy_document($document_id, $folder_id, $reason, $options) {
+		$rest_args = '&document_id='. urlencode($document_id) .'&folder_id='. urlencode($folder_id) .'&reason='. urlencode($reason) .'&options='. urlencode($options);
+		return $this->_kt_REST_call("copy_document", $rest_args);
+	}
+
+
+	/**
+	 * REST Call: move_document
+	 * Parameter options:
+	 * (integer) document_id, (integer) folder_id, (string) reason, (string) options
+	 * @return kt_document_detail
+	 */
+	public function move_document($document_id, $folder_id, $reason, $options) {
+		$rest_args = '&document_id='. urlencode($document_id) .'&folder_id='. urlencode($folder_id) .'&reason='. urlencode($reason) .'&options='. urlencode($options);
+		return $this->_kt_REST_call("move_document", $rest_args);
+	}
+
+
+	/**
+	 * REST Call: rename_document_title
+	 * Parameter options:
+	 * (integer) document_id, (string) newtitle
+	 * @return kt_document_detail
+	 */
+	public function rename_document_title($document_id, $newtitle) {
+		$rest_args = '&document_id='. urlencode($document_id) .'&newtitle='. urlencode($newtitle);
+		return $this->_kt_REST_call("rename_document_title", $rest_args);
+	}
+
+
+	/**
+	 * REST Call: rename_document_filename
+	 * Parameter options:
+	 * (integer) document_id, (string) newfilename
+	 * @return kt_document_detail
+	 */
+	public function rename_document_filename($document_id, $newfilename) {
+		$rest_args = '&document_id='. urlencode($document_id) .'&newfilename='. urlencode($newfilename);
+		return $this->_kt_REST_call("rename_document_filename", $rest_args);
+	}
+
+
+	/**
+	 * REST Call: change_document_type
+	 * Parameter options:
+	 * (integer) document_id, (string) documenttype
+	 * @return kt_document_detail
+	 */
+	public function change_document_type($document_id, $documenttype) {
+		$rest_args = '&document_id='. urlencode($document_id) .'&documenttype='. urlencode($documenttype);
+		return $this->_kt_REST_call("change_document_type", $rest_args);
+	}
+
+
+	/**
+	 * REST Call: start_document_workflow
+	 * Parameter options:
+	 * (integer) document_id, (string) workflow
+	 * @return kt_document_detail
+	 */
+	public function start_document_workflow($document_id, $workflow) {
+		$rest_args = '&document_id='. urlencode($document_id) .'&workflow='. urlencode($workflow);
+		return $this->_kt_REST_call("start_document_workflow", $rest_args);
+	}
+
+
+	/**
+	 * REST Call: delete_document_workflow
+	 * Parameter options:
+	 * (integer) document_id
+	 * @return kt_document_detail
+	 */
+	public function delete_document_workflow($document_id) {
+		$rest_args = '&document_id='. urlencode($document_id);
+		return $this->_kt_REST_call("delete_document_workflow", $rest_args);
+	}
+
+
+	/**
+	 * REST Call: stop_document_workflow
+	 * Parameter options:
+	 * (integer) document_id
+	 * @return kt_document_detail
+	 */
+	public function stop_document_workflow($document_id) {
+		$rest_args = '&document_id='. urlencode($document_id);
+		return $this->_kt_REST_call("stop_document_workflow", $rest_args);
+	}
+
+
+	/**
+	 * REST Call: perform_document_workflow_transition
+	 * Parameter options:
+	 * (integer) document_id, (string) transition, (string) reason
+	 * @return kt_document_detail
+	 */
+	public function perform_document_workflow_transition($document_id, $transition, $reason) {
+		$rest_args = '&document_id='. urlencode($document_id) .'&transition='. urlencode($transition) .'&reason='. urlencode($reason);
+		return $this->_kt_REST_call("perform_document_workflow_transition", $rest_args);
+	}
+
+
+	/**
+	 * REST Call: get_document_metadata
+	 * Parameter options:
+	 * (integer) document_id
+	 * @return kt_metadata_response
+	 */
+	public function get_document_metadata($document_id) {
+		$rest_args = '&document_id='. urlencode($document_id);
+		return $this->_kt_REST_call("get_document_metadata", $rest_args);
+	}
+
+
+	/**
+	 * REST Call: get_document_type_metadata
+	 * Parameter options:
+	 * (string) document_type
+	 * @return kt_metadata_response
+	 */
+	public function get_document_type_metadata($document_type) {
+		$rest_args = '&document_type='. urlencode($document_type);
+		return $this->_kt_REST_call("get_document_type_metadata", $rest_args);
+	}
+
+
+	/**
+	 * REST Call: update_document_metadata
+	 * Parameter options:
+	 * (integer) document_id, (kt_metadata_fieldsets) metadata, (kt_sysdata) sysdata
+	 * @return kt_document_detail
+	 */
+	public function update_document_metadata($document_id, $metadata, $sysdata) {
+		$rest_args = '&document_id='. urlencode($document_id) .'&metadata='. urlencode($metadata) .'&sysdata='. urlencode($sysdata);
+		return $this->_kt_REST_call("update_document_metadata", $rest_args);
+	}
+
+
+	/**
+	 * REST Call: get_document_workflow_transitions
+	 * Parameter options:
+	 * (integer) document_id
+	 * @return kt_workflow_transitions_response
+	 */
+	public function get_document_workflow_transitions($document_id) {
+		$rest_args = '&document_id='. urlencode($document_id);
+		return $this->_kt_REST_call("get_document_workflow_transitions", $rest_args);
+	}
+
+
+	/**
+	 * REST Call: get_document_workflow_state
+	 * Parameter options:
+	 * (integer) document_id
+	 * @return kt_response
+	 */
+	public function get_document_workflow_state($document_id) {
+		$rest_args = '&document_id='. urlencode($document_id);
+		return $this->_kt_REST_call("get_document_workflow_state", $rest_args);
+	}
+
+
+	/**
+	 * REST Call: get_document_transaction_history
+	 * Parameter options:
+	 * (integer) document_id
+	 * @return kt_document_transaction_history_response
+	 */
+	public function get_document_transaction_history($document_id) {
+		$rest_args = '&document_id='. urlencode($document_id);
+		return $this->_kt_REST_call("get_document_transaction_history", $rest_args);
+	}
+
+
+	/**
+	 * REST Call: get_document_version_history
+	 * Parameter options:
+	 * (integer) document_id
+	 * @return kt_document_version_history_response
+	 */
+	public function get_document_version_history($document_id) {
+		$rest_args = '&document_id='. urlencode($document_id);
+		return $this->_kt_REST_call("get_document_version_history", $rest_args);
+	}
+
+
+	/**
+	 * REST Call: get_document_types
+	 * @return kt_document_types_response
+	 */
+	public function get_document_types() {
+		return $this->_kt_REST_call("get_document_types", "");
+	}
+
+
+	/**
+	 * REST Call: get_workflows
+	 * @return kt_workflows_response
+	 */
+	public function get_workflows() {
+		return $this->_kt_REST_call("get_workflows", "");
+	}
+
+
+	/**
+	 * REST Call: get_document_link_types
+	 * @return kt_document_types_response
+	 */
+	public function get_document_link_types() {
+		return $this->_kt_REST_call("get_document_link_types", "");
+	}
+
+
+	/**
+	 * REST Call: get_client_policies
+	 * Parameter options:
+	 * (string) client
+	 * @return kt_client_policies_response
+	 */
+	public function get_client_policies($client) {
+		$rest_args = '&client='. urlencode($client);
+		return $this->_kt_REST_call("get_client_policies", $rest_args);
+	}
+
+
+
+  }
+}
+
+?>
diff -Nupwbr -x .svn kt/includes/KnowledgeTreeService_SOAP.php /tmp/kt/includes/KnowledgeTreeService_SOAP.php
--- kt/includes/KnowledgeTreeService_SOAP.php	1969-12-31 16:00:00.000000000 -0800
+++ /tmp/kt/includes/KnowledgeTreeService_SOAP.php	2009-08-02 12:05:10.000000000 -0700
@@ -0,0 +1,1184 @@
+<?php
+
+/*
+ * Generated automatically from KT 3.6.1 WSDL
+ * Using WSDL->PHP generator http://code.google.com/p/wsdl2php-interpreter/
+ * with a few custom tweaks
+ * @author aantonop
+ */
+
+include "KnowledgeTreeService_classes.php";
+
+if (!class_exists("KnowledgeTreeSOAPService")) {
+/**
+ * KnowledgeTreeSOAPService
+ * @author WSDLInterpreter
+ */
+class KnowledgeTreeSOAPService extends SoapClient {
+	/**
+	 * Default class map for wsdl=>php
+	 * @access private
+	 * @var array
+	 */
+	private static $classmap = array(
+		"kt_response" => "kt_response",
+		"kt_folder_detail" => "kt_folder_detail",
+		"kt_folder_item" => "kt_folder_item",
+		"kt_folder_items" => "kt_folder_items",
+		"kt_folder_contents" => "kt_folder_contents",
+		"kt_document_detail" => "kt_document_detail",
+		"kt_search_result_item" => "kt_search_result_item",
+		"kt_search_results" => "kt_search_results",
+		"kt_search_response" => "kt_search_response",
+		"kt_sysdata_item" => "kt_sysdata_item",
+		"kt_sysdata" => "kt_sysdata",
+		"kt_metadata_selection_item" => "kt_metadata_selection_item",
+		"kt_metadata_selection" => "kt_metadata_selection",
+		"kt_metadata_field" => "kt_metadata_field",
+		"kt_metadata_fields" => "kt_metadata_fields",
+		"kt_metadata_fieldset" => "kt_metadata_fieldset",
+		"kt_metadata_fieldsets" => "kt_metadata_fieldsets",
+		"kt_metadata_response" => "kt_metadata_response",
+		"kt_workflow_transitions" => "kt_workflow_transitions",
+		"kt_workflow_transitions_response" => "kt_workflow_transitions_response",
+		"kt_workflows_array" => "kt_workflows_array",
+		"kt_workflows_response" => "kt_workflows_response",
+		"kt_document_transaction_history_item" => "kt_document_transaction_history_item",
+		"kt_linked_document" => "kt_linked_document",
+		"kt_linked_documents" => "kt_linked_documents",
+		"kt_linked_document_response" => "kt_linked_document_response",
+		"kt_document_transaction_history" => "kt_document_transaction_history",
+		"kt_document_transaction_history_response" => "kt_document_transaction_history_response",
+		"kt_document_version_history_item" => "kt_document_version_history_item",
+		"kt_document_collection" => "kt_document_collection",
+		"kt_document_collection_response" => "kt_document_collection_response",
+		"kt_folder_collection" => "kt_folder_collection",
+		"kt_folder_collection_response" => "kt_folder_collection_response",
+		"kt_document_version_history" => "kt_document_version_history",
+		"kt_document_version_history_response" => "kt_document_version_history_response",
+		"kt_document_types_array" => "kt_document_types_array",
+		"kt_document_types_response" => "kt_document_types_response",
+		"kt_client_policy" => "kt_client_policy",
+		"kt_client_policies_array" => "kt_client_policies_array",
+		"kt_client_policies_response" => "kt_client_policies_response",
+	);
+
+	/**
+	 * Constructor using wsdl location and options array
+	 * @param string $wsdl WSDL location for this service
+	 * @param array $options Options for the SoapClient
+	 */
+	public function __construct($wsdl="http://localhost/kt/ktwebservice/index.php?wsdl", $options=array()) {
+		foreach(self::$classmap as $wsdlClassName => $phpClassName) {
+		    if(!isset($options['classmap'][$wsdlClassName])) {
+		        $options['classmap'][$wsdlClassName] = $phpClassName;
+		    }
+		}
+		parent::__construct($wsdl, $options);
+	}
+
+	/**
+	 * Checks if an argument list matches against a valid argument type list
+	 * @param array $arguments The argument list to check
+	 * @param array $validParameters A list of valid argument types
+	 * @return boolean true if arguments match against validParameters
+	 * @throws Exception invalid function signature message
+	 */
+	public function _checkArguments($arguments, $validParameters) {
+		$variables = "";
+		foreach ($arguments as $arg) {
+		    $type = gettype($arg);
+		    if ($type == "object") {
+		        $type = get_class($arg);
+		    }
+		    $variables .= "(".$type.")";
+		}
+		if (!in_array($variables, $validParameters)) {
+		    throw new Exception("Invalid parameter types: ".str_replace(")(", ", ", $variables));
+		}
+		return true;
+	}
+
+	/**
+	 * Service Call: search
+	 * Parameter options:
+	 * (string) session_id, (string) search, (string) options
+	 * @param mixed,... See function description for parameter options
+	 * @return kt_search_response
+	 * @throws Exception invalid function signature message
+	 */
+	public function search($mixed = null) {
+		$validParameters = array(
+			"(string)(string)(string)",
+		);
+		$args = func_get_args();
+		$this->_checkArguments($args, $validParameters);
+		return $this->__soapCall("search", $args);
+	}
+
+
+	/**
+	 * Service Call: login
+	 * Parameter options:
+	 * (string) username, (string) password, (string) ip
+	 * @param mixed,... See function description for parameter options
+	 * @return kt_response
+	 * @throws Exception invalid function signature message
+	 */
+	public function login($mixed = null) {
+		$validParameters = array(
+			"(string)(string)(string)",
+		);
+		$args = func_get_args();
+		$this->_checkArguments($args, $validParameters);
+		return $this->__soapCall("login", $args);
+	}
+
+
+	/**
+	 * Service Call: anonymous_login
+	 * Parameter options:
+	 * (string) ip
+	 * @param mixed,... See function description for parameter options
+	 * @return kt_response
+	 * @throws Exception invalid function signature message
+	 */
+	public function anonymous_login($mixed = null) {
+		$validParameters = array(
+			"(string)",
+		);
+		$args = func_get_args();
+		$this->_checkArguments($args, $validParameters);
+		return $this->__soapCall("anonymous_login", $args);
+	}
+
+
+	/**
+	 * Service Call: logout
+	 * Parameter options:
+	 * (string) session_id
+	 * @param mixed,... See function description for parameter options
+	 * @return kt_response
+	 * @throws Exception invalid function signature message
+	 */
+	public function logout($mixed = null) {
+		$validParameters = array(
+			"(string)",
+		);
+		$args = func_get_args();
+		$this->_checkArguments($args, $validParameters);
+		return $this->__soapCall("logout", $args);
+	}
+
+
+	/**
+	 * Service Call: get_folder_detail
+	 * Parameter options:
+	 * (string) session_id, (integer) folder_id
+	 * @param mixed,... See function description for parameter options
+	 * @return kt_folder_detail
+	 * @throws Exception invalid function signature message
+	 */
+	public function get_folder_detail($mixed = null) {
+		$validParameters = array(
+			"(string)(integer)",
+		);
+		$args = func_get_args();
+		$this->_checkArguments($args, $validParameters);
+		return $this->__soapCall("get_folder_detail", $args);
+	}
+
+
+	/**
+	 * Service Call: get_documents_by_oem_no
+	 * Parameter options:
+	 * (string) session_id, (string) oem_no, (string) detail
+	 * @param mixed,... See function description for parameter options
+	 * @return kt_document_collection_response
+	 * @throws Exception invalid function signature message
+	 */
+	public function get_documents_by_oem_no($mixed = null) {
+		$validParameters = array(
+			"(string)(string)(string)",
+		);
+		$args = func_get_args();
+		$this->_checkArguments($args, $validParameters);
+		return $this->__soapCall("get_documents_by_oem_no", $args);
+	}
+
+
+	/**
+	 * Service Call: get_folder_detail_by_name
+	 * Parameter options:
+	 * (string) session_id, (string) folder_name
+	 * @param mixed,... See function description for parameter options
+	 * @return kt_folder_detail
+	 * @throws Exception invalid function signature message
+	 */
+	public function get_folder_detail_by_name($mixed = null) {
+		$validParameters = array(
+			"(string)(string)",
+		);
+		$args = func_get_args();
+		$this->_checkArguments($args, $validParameters);
+		return $this->__soapCall("get_folder_detail_by_name", $args);
+	}
+
+
+	/**
+	 * Service Call: get_folder_contents
+	 * Parameter options:
+	 * (string) session_id, (integer) folder_id, (integer) depth, (string) what
+	 * @param mixed,... See function description for parameter options
+	 * @return kt_folder_contents
+	 * @throws Exception invalid function signature message
+	 */
+	public function get_folder_contents($mixed = null) {
+		$validParameters = array(
+			"(string)(integer)(integer)(string)",
+		);
+		$args = func_get_args();
+		$this->_checkArguments($args, $validParameters);
+		return $this->__soapCall("get_folder_contents", $args);
+	}
+
+
+	/**
+	 * Service Call: create_folder
+	 * Parameter options:
+	 * (string) session_id, (integer) folder_id, (string) folder_name
+	 * @param mixed,... See function description for parameter options
+	 * @return kt_folder_detail
+	 * @throws Exception invalid function signature message
+	 */
+	public function create_folder($mixed = null) {
+		$validParameters = array(
+			"(string)(integer)(string)",
+		);
+		$args = func_get_args();
+		$this->_checkArguments($args, $validParameters);
+		return $this->__soapCall("create_folder", $args);
+	}
+
+
+	/**
+	 * Service Call: add_folder
+	 * Parameter options:
+	 * (string) session_id, (integer) folder_id, (string) folder_name
+	 * @param mixed,... See function description for parameter options
+	 * @return kt_folder_detail
+	 * @throws Exception invalid function signature message
+	 */
+	public function add_folder($mixed = null) {
+		$validParameters = array(
+			"(string)(integer)(string)",
+		);
+		$args = func_get_args();
+		$this->_checkArguments($args, $validParameters);
+		return $this->__soapCall("add_folder", $args);
+	}
+
+
+	/**
+	 * Service Call: delete_folder
+	 * Parameter options:
+	 * (string) session_id, (integer) folder_id, (string) reason
+	 * @param mixed,... See function description for parameter options
+	 * @return kt_response
+	 * @throws Exception invalid function signature message
+	 */
+	public function delete_folder($mixed = null) {
+		$validParameters = array(
+			"(string)(integer)(string)",
+		);
+		$args = func_get_args();
+		$this->_checkArguments($args, $validParameters);
+		return $this->__soapCall("delete_folder", $args);
+	}
+
+
+	/**
+	 * Service Call: rename_folder
+	 * Parameter options:
+	 * (string) session_id, (integer) folder_id, (string) newname
+	 * @param mixed,... See function description for parameter options
+	 * @return kt_response
+	 * @throws Exception invalid function signature message
+	 */
+	public function rename_folder($mixed = null) {
+		$validParameters = array(
+			"(string)(integer)(string)",
+		);
+		$args = func_get_args();
+		$this->_checkArguments($args, $validParameters);
+		return $this->__soapCall("rename_folder", $args);
+	}
+
+
+	/**
+	 * Service Call: get_document_links
+	 * Parameter options:
+	 * (string) session_id, (integer) document_id
+	 * @param mixed,... See function description for parameter options
+	 * @return kt_linked_document_response
+	 * @throws Exception invalid function signature message
+	 */
+	public function get_document_links($mixed = null) {
+		$validParameters = array(
+			"(string)(integer)",
+		);
+		$args = func_get_args();
+		$this->_checkArguments($args, $validParameters);
+		return $this->__soapCall("get_document_links", $args);
+	}
+
+
+	/**
+	 * Service Call: link_documents
+	 * Parameter options:
+	 * (string) session_id, (integer) parent_document_id, (integer) child_document_id, (string) type
+	 * @param mixed,... See function description for parameter options
+	 * @return kt_response
+	 * @throws Exception invalid function signature message
+	 */
+	public function link_documents($mixed = null) {
+		$validParameters = array(
+			"(string)(integer)(integer)(string)",
+		);
+		$args = func_get_args();
+		$this->_checkArguments($args, $validParameters);
+		return $this->__soapCall("link_documents", $args);
+	}
+
+
+	/**
+	 * Service Call: unlink_documents
+	 * Parameter options:
+	 * (string) session_id, (integer) parent_document_id, (integer) child_document_id
+	 * @param mixed,... See function description for parameter options
+	 * @return kt_response
+	 * @throws Exception invalid function signature message
+	 */
+	public function unlink_documents($mixed = null) {
+		$validParameters = array(
+			"(string)(integer)(integer)",
+		);
+		$args = func_get_args();
+		$this->_checkArguments($args, $validParameters);
+		return $this->__soapCall("unlink_documents", $args);
+	}
+
+
+	/**
+	 * Service Call: copy_folder
+	 * Parameter options:
+	 * (string) session_id, (integer) source_id, (integer) target_id, (string) reason
+	 * @param mixed,... See function description for parameter options
+	 * @return kt_folder_detail
+	 * @throws Exception invalid function signature message
+	 */
+	public function copy_folder($mixed = null) {
+		$validParameters = array(
+			"(string)(integer)(integer)(string)",
+		);
+		$args = func_get_args();
+		$this->_checkArguments($args, $validParameters);
+		return $this->__soapCall("copy_folder", $args);
+	}
+
+
+	/**
+	 * Service Call: move_folder
+	 * Parameter options:
+	 * (string) session_id, (integer) source_id, (integer) target_id, (string) reason
+	 * @param mixed,... See function description for parameter options
+	 * @return kt_folder_detail
+	 * @throws Exception invalid function signature message
+	 */
+	public function move_folder($mixed = null) {
+		$validParameters = array(
+			"(string)(integer)(integer)(string)",
+		);
+		$args = func_get_args();
+		$this->_checkArguments($args, $validParameters);
+		return $this->__soapCall("move_folder", $args);
+	}
+
+
+	/**
+	 * Service Call: get_document_detail
+	 * Parameter options:
+	 * (string) session_id, (integer) document_id, (string) detail
+	 * @param mixed,... See function description for parameter options
+	 * @return kt_document_detail
+	 * @throws Exception invalid function signature message
+	 */
+	public function get_document_detail($mixed = null) {
+		$validParameters = array(
+			"(string)(integer)(string)",
+		);
+		$args = func_get_args();
+		$this->_checkArguments($args, $validParameters);
+		return $this->__soapCall("get_document_detail", $args);
+	}
+
+
+	/**
+	 * Service Call: checkin_document
+	 * Parameter options:
+	 * (string) session_id, (integer) document_id, (string) filename, (string) reason, (string) tempfilename, (boolean) major_update
+	 * @param mixed,... See function description for parameter options
+	 * @return kt_document_detail
+	 * @throws Exception invalid function signature message
+	 */
+	public function checkin_document($mixed = null) {
+		$validParameters = array(
+			"(string)(integer)(string)(string)(string)(boolean)",
+		);
+		$args = func_get_args();
+		$this->_checkArguments($args, $validParameters);
+		return $this->__soapCall("checkin_document", $args);
+	}
+
+
+	/**
+	 * Service Call: checkin_small_document
+	 * Parameter options:
+	 * (string) session_id, (integer) document_id, (string) filename, (string) reason, (string) base64, (boolean) major_update
+	 * @param mixed,... See function description for parameter options
+	 * @return kt_document_detail
+	 * @throws Exception invalid function signature message
+	 */
+	public function checkin_small_document($mixed = null) {
+		$validParameters = array(
+			"(string)(integer)(string)(string)(string)(boolean)",
+		);
+		$args = func_get_args();
+		$this->_checkArguments($args, $validParameters);
+		return $this->__soapCall("checkin_small_document", $args);
+	}
+
+
+	/**
+	 * Service Call: checkin_base64_document
+	 * Parameter options:
+	 * (string) session_id, (integer) document_id, (string) filename, (string) reason, (string) base64, (boolean) major_update
+	 * @param mixed,... See function description for parameter options
+	 * @return kt_document_detail
+	 * @throws Exception invalid function signature message
+	 */
+	public function checkin_base64_document($mixed = null) {
+		$validParameters = array(
+			"(string)(integer)(string)(string)(string)(boolean)",
+		);
+		$args = func_get_args();
+		$this->_checkArguments($args, $validParameters);
+		return $this->__soapCall("checkin_base64_document", $args);
+	}
+
+
+	/**
+	 * Service Call: checkin_base64_document_with_metadata
+	 * Parameter options:
+	 * (string) session_id, (integer) document_id, (string) filename, (string) reason, (string) base64, (boolean) major_update, (kt_metadata_fieldsets) metadata, (kt_sysdata) sysdata
+	 * @param mixed,... See function description for parameter options
+	 * @return kt_document_detail
+	 * @throws Exception invalid function signature message
+	 */
+	public function checkin_base64_document_with_metadata($mixed = null) {
+		$validParameters = array(
+			"(string)(integer)(string)(string)(string)(boolean)(kt_metadata_fieldsets)(kt_sysdata)",
+		);
+		$args = func_get_args();
+		$this->_checkArguments($args, $validParameters);
+		return $this->__soapCall("checkin_base64_document_with_metadata", $args);
+	}
+
+
+	/**
+	 * Service Call: checkin_document_with_metadata
+	 * Parameter options:
+	 * (string) session_id, (integer) document_id, (string) filename, (string) reason, (string) tempfilename, (boolean) major_update, (kt_metadata_fieldsets) metadata, (kt_sysdata) sysdata
+	 * @param mixed,... See function description for parameter options
+	 * @return kt_document_detail
+	 * @throws Exception invalid function signature message
+	 */
+	public function checkin_document_with_metadata($mixed = null) {
+		$validParameters = array(
+			"(string)(integer)(string)(string)(string)(boolean)(kt_metadata_fieldsets)(kt_sysdata)",
+		);
+		$args = func_get_args();
+		$this->_checkArguments($args, $validParameters);
+		return $this->__soapCall("checkin_document_with_metadata", $args);
+	}
+
+
+	/**
+	 * Service Call: add_document
+	 * Parameter options:
+	 * (string) session_id, (integer) folder_id, (string) title, (string) filename, (string) documentype, (string) tempfilename
+	 * @param mixed,... See function description for parameter options
+	 * @return kt_document_detail
+	 * @throws Exception invalid function signature message
+	 */
+	public function add_document($mixed = null) {
+		$validParameters = array(
+			"(string)(integer)(string)(string)(string)(string)",
+		);
+		$args = func_get_args();
+		$this->_checkArguments($args, $validParameters);
+		return $this->__soapCall("add_document", $args);
+	}
+
+
+	/**
+	 * Service Call: add_small_document
+	 * Parameter options:
+	 * (string) session_id, (integer) folder_id, (string) title, (string) filename, (string) documentype, (string) base64
+	 * @param mixed,... See function description for parameter options
+	 * @return kt_document_detail
+	 * @throws Exception invalid function signature message
+	 */
+	public function add_small_document($mixed = null) {
+		$validParameters = array(
+			"(string)(integer)(string)(string)(string)(string)",
+		);
+		$args = func_get_args();
+		$this->_checkArguments($args, $validParameters);
+		return $this->__soapCall("add_small_document", $args);
+	}
+
+
+	/**
+	 * Service Call: add_base64_document
+	 * Parameter options:
+	 * (string) session_id, (integer) folder_id, (string) title, (string) filename, (string) documentype, (string) base64
+	 * @param mixed,... See function description for parameter options
+	 * @return kt_document_detail
+	 * @throws Exception invalid function signature message
+	 */
+	public function add_base64_document($mixed = null) {
+		$validParameters = array(
+			"(string)(integer)(string)(string)(string)(string)",
+		);
+		$args = func_get_args();
+		$this->_checkArguments($args, $validParameters);
+		return $this->__soapCall("add_base64_document", $args);
+	}
+
+
+	/**
+	 * Service Call: add_base64_document_with_metadata
+	 * Parameter options:
+	 * (string) session_id, (integer) folder_id, (string) title, (string) filename, (string) documentype, (string) base64, (kt_metadata_fieldsets) metadata, (kt_sysdata) sysdata
+	 * @param mixed,... See function description for parameter options
+	 * @return kt_document_detail
+	 * @throws Exception invalid function signature message
+	 */
+	public function add_base64_document_with_metadata($mixed = null) {
+		$validParameters = array(
+			"(string)(integer)(string)(string)(string)(string)(kt_metadata_fieldsets)(kt_sysdata)",
+		);
+		$args = func_get_args();
+		$this->_checkArguments($args, $validParameters);
+		return $this->__soapCall("add_base64_document_with_metadata", $args);
+	}
+
+
+	/**
+	 * Service Call: add_document_with_metadata
+	 * Parameter options:
+	 * (string) session_id, (integer) folder_id, (string) title, (string) filename, (string) documentype, (string) tempfilename, (kt_metadata_fieldsets) metadata, (kt_sysdata) sysdata
+	 * @param mixed,... See function description for parameter options
+	 * @return kt_document_detail
+	 * @throws Exception invalid function signature message
+	 */
+	public function add_document_with_metadata($mixed = null) {
+		$validParameters = array(
+			"(string)(integer)(string)(string)(string)(string)(kt_metadata_fieldsets)(kt_sysdata)",
+		);
+		$args = func_get_args();
+		$this->_checkArguments($args, $validParameters);
+		return $this->__soapCall("add_document_with_metadata", $args);
+	}
+
+
+	/**
+	 * Service Call: get_document_detail_by_name
+	 * Parameter options:
+	 * (string) session_id, (integer) folder_id, (string) document_name, (string) what, (string) detail
+	 * @param mixed,... See function description for parameter options
+	 * @return kt_document_detail
+	 * @throws Exception invalid function signature message
+	 */
+	public function get_document_detail_by_name($mixed = null) {
+		$validParameters = array(
+			"(string)(integer)(string)(string)(string)",
+		);
+		$args = func_get_args();
+		$this->_checkArguments($args, $validParameters);
+		return $this->__soapCall("get_document_detail_by_name", $args);
+	}
+
+
+	/**
+	 * Service Call: get_document_detail_by_title
+	 * Parameter options:
+	 * (string) session_id, (integer) folder_id, (string) title, (string) detail
+	 * @param mixed,... See function description for parameter options
+	 * @return kt_document_detail
+	 * @throws Exception invalid function signature message
+	 */
+	public function get_document_detail_by_title($mixed = null) {
+		$validParameters = array(
+			"(string)(integer)(string)(string)",
+		);
+		$args = func_get_args();
+		$this->_checkArguments($args, $validParameters);
+		return $this->__soapCall("get_document_detail_by_title", $args);
+	}
+
+
+	/**
+	 * Service Call: get_document_detail_by_filename
+	 * Parameter options:
+	 * (string) session_id, (integer) folder_id, (string) filename, (string) detail
+	 * @param mixed,... See function description for parameter options
+	 * @return kt_document_detail
+	 * @throws Exception invalid function signature message
+	 */
+	public function get_document_detail_by_filename($mixed = null) {
+		$validParameters = array(
+			"(string)(integer)(string)(string)",
+		);
+		$args = func_get_args();
+		$this->_checkArguments($args, $validParameters);
+		return $this->__soapCall("get_document_detail_by_filename", $args);
+	}
+
+
+	/**
+	 * Service Call: checkout_document
+	 * Parameter options:
+	 * (string) session_id, (integer) document_id, (string) reason, (boolean) download
+	 * @param mixed,... See function description for parameter options
+	 * @return kt_document_detail
+	 * @throws Exception invalid function signature message
+	 */
+	public function checkout_document($mixed = null) {
+		$validParameters = array(
+			"(string)(integer)(string)(boolean)",
+		);
+		$args = func_get_args();
+		$this->_checkArguments($args, $validParameters);
+		return $this->__soapCall("checkout_document", $args);
+	}
+
+
+	/**
+	 * Service Call: checkout_small_document
+	 * Parameter options:
+	 * (string) session_id, (integer) document_id, (string) reason, (boolean) download
+	 * @param mixed,... See function description for parameter options
+	 * @return kt_document_detail
+	 * @throws Exception invalid function signature message
+	 */
+	public function checkout_small_document($mixed = null) {
+		$validParameters = array(
+			"(string)(integer)(string)(boolean)",
+		);
+		$args = func_get_args();
+		$this->_checkArguments($args, $validParameters);
+		return $this->__soapCall("checkout_small_document", $args);
+	}
+
+
+	/**
+	 * Service Call: checkout_base64_document
+	 * Parameter options:
+	 * (string) session_id, (integer) document_id, (string) reason, (boolean) download
+	 * @param mixed,... See function description for parameter options
+	 * @return kt_document_detail
+	 * @throws Exception invalid function signature message
+	 */
+	public function checkout_base64_document($mixed = null) {
+		$validParameters = array(
+			"(string)(integer)(string)(boolean)",
+		);
+		$args = func_get_args();
+		$this->_checkArguments($args, $validParameters);
+		return $this->__soapCall("checkout_base64_document", $args);
+	}
+
+
+	/**
+	 * Service Call: undo_document_checkout
+	 * Parameter options:
+	 * (string) session_id, (integer) document_id, (string) reason
+	 * @param mixed,... See function description for parameter options
+	 * @return kt_document_detail
+	 * @throws Exception invalid function signature message
+	 */
+	public function undo_document_checkout($mixed = null) {
+		$validParameters = array(
+			"(string)(integer)(string)",
+		);
+		$args = func_get_args();
+		$this->_checkArguments($args, $validParameters);
+		return $this->__soapCall("undo_document_checkout", $args);
+	}
+
+
+	/**
+	 * Service Call: download_document
+	 * Parameter options:
+	 * (string) session_id, (integer) document_id
+	 * @param mixed,... See function description for parameter options
+	 * @return kt_response
+	 * @throws Exception invalid function signature message
+	 */
+	public function download_document($mixed = null) {
+		$validParameters = array(
+			"(string)(integer)",
+		);
+		$args = func_get_args();
+		$this->_checkArguments($args, $validParameters);
+		return $this->__soapCall("download_document", $args);
+	}
+
+
+	/**
+	 * Service Call: download_small_document
+	 * Parameter options:
+	 * (string) session_id, (integer) document_id
+	 * @param mixed,... See function description for parameter options
+	 * @return kt_response
+	 * @throws Exception invalid function signature message
+	 */
+	public function download_small_document($mixed = null) {
+		$validParameters = array(
+			"(string)(integer)",
+		);
+		$args = func_get_args();
+		$this->_checkArguments($args, $validParameters);
+		return $this->__soapCall("download_small_document", $args);
+	}
+
+
+	/**
+	 * Service Call: download_base64_document
+	 * Parameter options:
+	 * (string) session_id, (integer) document_id
+	 * @param mixed,... See function description for parameter options
+	 * @return kt_response
+	 * @throws Exception invalid function signature message
+	 */
+	public function download_base64_document($mixed = null) {
+		$validParameters = array(
+			"(string)(integer)",
+		);
+		$args = func_get_args();
+		$this->_checkArguments($args, $validParameters);
+		return $this->__soapCall("download_base64_document", $args);
+	}
+
+
+	/**
+	 * Service Call: delete_document
+	 * Parameter options:
+	 * (string) session_id, (integer) document_id, (string) reason
+	 * @param mixed,... See function description for parameter options
+	 * @return kt_response
+	 * @throws Exception invalid function signature message
+	 */
+	public function delete_document($mixed = null) {
+		$validParameters = array(
+			"(string)(integer)(string)",
+		);
+		$args = func_get_args();
+		$this->_checkArguments($args, $validParameters);
+		return $this->__soapCall("delete_document", $args);
+	}
+
+
+	/**
+	 * Service Call: change_document_owner
+	 * Parameter options:
+	 * (string) session_id, (integer) document_id, (string) username, (string) reason
+	 * @param mixed,... See function description for parameter options
+	 * @return kt_document_detail
+	 * @throws Exception invalid function signature message
+	 */
+	public function change_document_owner($mixed = null) {
+		$validParameters = array(
+			"(string)(integer)(string)(string)",
+		);
+		$args = func_get_args();
+		$this->_checkArguments($args, $validParameters);
+		return $this->__soapCall("change_document_owner", $args);
+	}
+
+
+	/**
+	 * Service Call: copy_document
+	 * Parameter options:
+	 * (string) session_id, (integer) document_id, (integer) folder_id, (string) reason, (string) options
+	 * @param mixed,... See function description for parameter options
+	 * @return kt_document_detail
+	 * @throws Exception invalid function signature message
+	 */
+	public function copy_document($mixed = null) {
+		$validParameters = array(
+			"(string)(integer)(integer)(string)(string)",
+		);
+		$args = func_get_args();
+		$this->_checkArguments($args, $validParameters);
+		return $this->__soapCall("copy_document", $args);
+	}
+
+
+	/**
+	 * Service Call: move_document
+	 * Parameter options:
+	 * (string) session_id, (integer) document_id, (integer) folder_id, (string) reason, (string) options
+	 * @param mixed,... See function description for parameter options
+	 * @return kt_document_detail
+	 * @throws Exception invalid function signature message
+	 */
+	public function move_document($mixed = null) {
+		$validParameters = array(
+			"(string)(integer)(integer)(string)(string)",
+		);
+		$args = func_get_args();
+		$this->_checkArguments($args, $validParameters);
+		return $this->__soapCall("move_document", $args);
+	}
+
+
+	/**
+	 * Service Call: rename_document_title
+	 * Parameter options:
+	 * (string) session_id, (integer) document_id, (string) newtitle
+	 * @param mixed,... See function description for parameter options
+	 * @return kt_document_detail
+	 * @throws Exception invalid function signature message
+	 */
+	public function rename_document_title($mixed = null) {
+		$validParameters = array(
+			"(string)(integer)(string)",
+		);
+		$args = func_get_args();
+		$this->_checkArguments($args, $validParameters);
+		return $this->__soapCall("rename_document_title", $args);
+	}
+
+
+	/**
+	 * Service Call: rename_document_filename
+	 * Parameter options:
+	 * (string) session_id, (integer) document_id, (string) newfilename
+	 * @param mixed,... See function description for parameter options
+	 * @return kt_document_detail
+	 * @throws Exception invalid function signature message
+	 */
+	public function rename_document_filename($mixed = null) {
+		$validParameters = array(
+			"(string)(integer)(string)",
+		);
+		$args = func_get_args();
+		$this->_checkArguments($args, $validParameters);
+		return $this->__soapCall("rename_document_filename", $args);
+	}
+
+
+	/**
+	 * Service Call: change_document_type
+	 * Parameter options:
+	 * (string) session_id, (integer) document_id, (string) documenttype
+	 * @param mixed,... See function description for parameter options
+	 * @return kt_document_detail
+	 * @throws Exception invalid function signature message
+	 */
+	public function change_document_type($mixed = null) {
+		$validParameters = array(
+			"(string)(integer)(string)",
+		);
+		$args = func_get_args();
+		$this->_checkArguments($args, $validParameters);
+		return $this->__soapCall("change_document_type", $args);
+	}
+
+
+	/**
+	 * Service Call: start_document_workflow
+	 * Parameter options:
+	 * (string) session_id, (integer) document_id, (string) workflow
+	 * @param mixed,... See function description for parameter options
+	 * @return kt_document_detail
+	 * @throws Exception invalid function signature message
+	 */
+	public function start_document_workflow($mixed = null) {
+		$validParameters = array(
+			"(string)(integer)(string)",
+		);
+		$args = func_get_args();
+		$this->_checkArguments($args, $validParameters);
+		return $this->__soapCall("start_document_workflow", $args);
+	}
+
+
+	/**
+	 * Service Call: delete_document_workflow
+	 * Parameter options:
+	 * (string) session_id, (integer) document_id
+	 * @param mixed,... See function description for parameter options
+	 * @return kt_document_detail
+	 * @throws Exception invalid function signature message
+	 */
+	public function delete_document_workflow($mixed = null) {
+		$validParameters = array(
+			"(string)(integer)",
+		);
+		$args = func_get_args();
+		$this->_checkArguments($args, $validParameters);
+		return $this->__soapCall("delete_document_workflow", $args);
+	}
+
+
+	/**
+	 * Service Call: stop_document_workflow
+	 * Parameter options:
+	 * (string) session_id, (integer) document_id
+	 * @param mixed,... See function description for parameter options
+	 * @return kt_document_detail
+	 * @throws Exception invalid function signature message
+	 */
+	public function stop_document_workflow($mixed = null) {
+		$validParameters = array(
+			"(string)(integer)",
+		);
+		$args = func_get_args();
+		$this->_checkArguments($args, $validParameters);
+		return $this->__soapCall("stop_document_workflow", $args);
+	}
+
+
+	/**
+	 * Service Call: perform_document_workflow_transition
+	 * Parameter options:
+	 * (string) session_id, (integer) document_id, (string) transition, (string) reason
+	 * @param mixed,... See function description for parameter options
+	 * @return kt_document_detail
+	 * @throws Exception invalid function signature message
+	 */
+	public function perform_document_workflow_transition($mixed = null) {
+		$validParameters = array(
+			"(string)(integer)(string)(string)",
+		);
+		$args = func_get_args();
+		$this->_checkArguments($args, $validParameters);
+		return $this->__soapCall("perform_document_workflow_transition", $args);
+	}
+
+
+	/**
+	 * Service Call: get_document_metadata
+	 * Parameter options:
+	 * (string) session_id, (integer) document_id
+	 * @param mixed,... See function description for parameter options
+	 * @return kt_metadata_response
+	 * @throws Exception invalid function signature message
+	 */
+	public function get_document_metadata($mixed = null) {
+		$validParameters = array(
+			"(string)(integer)",
+		);
+		$args = func_get_args();
+		$this->_checkArguments($args, $validParameters);
+		return $this->__soapCall("get_document_metadata", $args);
+	}
+
+
+	/**
+	 * Service Call: get_document_type_metadata
+	 * Parameter options:
+	 * (string) session_id, (string) document_type
+	 * @param mixed,... See function description for parameter options
+	 * @return kt_metadata_response
+	 * @throws Exception invalid function signature message
+	 */
+	public function get_document_type_metadata($mixed = null) {
+		$validParameters = array(
+			"(string)(string)",
+		);
+		$args = func_get_args();
+		$this->_checkArguments($args, $validParameters);
+		return $this->__soapCall("get_document_type_metadata", $args);
+	}
+
+
+	/**
+	 * Service Call: update_document_metadata
+	 * Parameter options:
+	 * (string) session_id, (integer) document_id, (kt_metadata_fieldsets) metadata, (kt_sysdata) sysdata
+	 * @param mixed,... See function description for parameter options
+	 * @return kt_document_detail
+	 * @throws Exception invalid function signature message
+	 */
+	public function update_document_metadata($mixed = null) {
+		$validParameters = array(
+			"(string)(integer)(kt_metadata_fieldsets)(kt_sysdata)",
+		);
+		$args = func_get_args();
+		$this->_checkArguments($args, $validParameters);
+		return $this->__soapCall("update_document_metadata", $args);
+	}
+
+
+	/**
+	 * Service Call: get_document_workflow_transitions
+	 * Parameter options:
+	 * (string) session_id, (integer) document_id
+	 * @param mixed,... See function description for parameter options
+	 * @return kt_workflow_transitions_response
+	 * @throws Exception invalid function signature message
+	 */
+	public function get_document_workflow_transitions($mixed = null) {
+		$validParameters = array(
+			"(string)(integer)",
+		);
+		$args = func_get_args();
+		$this->_checkArguments($args, $validParameters);
+		return $this->__soapCall("get_document_workflow_transitions", $args);
+	}
+
+
+	/**
+	 * Service Call: get_document_workflow_state
+	 * Parameter options:
+	 * (string) session_id, (integer) document_id
+	 * @param mixed,... See function description for parameter options
+	 * @return kt_response
+	 * @throws Exception invalid function signature message
+	 */
+	public function get_document_workflow_state($mixed = null) {
+		$validParameters = array(
+			"(string)(integer)",
+		);
+		$args = func_get_args();
+		$this->_checkArguments($args, $validParameters);
+		return $this->__soapCall("get_document_workflow_state", $args);
+	}
+
+
+	/**
+	 * Service Call: get_document_transaction_history
+	 * Parameter options:
+	 * (string) session_id, (integer) document_id
+	 * @param mixed,... See function description for parameter options
+	 * @return kt_document_transaction_history_response
+	 * @throws Exception invalid function signature message
+	 */
+	public function get_document_transaction_history($mixed = null) {
+		$validParameters = array(
+			"(string)(integer)",
+		);
+		$args = func_get_args();
+		$this->_checkArguments($args, $validParameters);
+		return $this->__soapCall("get_document_transaction_history", $args);
+	}
+
+
+	/**
+	 * Service Call: get_document_version_history
+	 * Parameter options:
+	 * (string) session_id, (integer) document_id
+	 * @param mixed,... See function description for parameter options
+	 * @return kt_document_version_history_response
+	 * @throws Exception invalid function signature message
+	 */
+	public function get_document_version_history($mixed = null) {
+		$validParameters = array(
+			"(string)(integer)",
+		);
+		$args = func_get_args();
+		$this->_checkArguments($args, $validParameters);
+		return $this->__soapCall("get_document_version_history", $args);
+	}
+
+
+	/**
+	 * Service Call: get_document_types
+	 * Parameter options:
+	 * (string) session_id
+	 * @param mixed,... See function description for parameter options
+	 * @return kt_document_types_response
+	 * @throws Exception invalid function signature message
+	 */
+	public function get_document_types($mixed = null) {
+		$validParameters = array(
+			"(string)",
+		);
+		$args = func_get_args();
+		$this->_checkArguments($args, $validParameters);
+		return $this->__soapCall("get_document_types", $args);
+	}
+
+
+	/**
+	 * Service Call: get_workflows
+	 * Parameter options:
+	 * (string) session_id
+	 * @param mixed,... See function description for parameter options
+	 * @return kt_workflows_response
+	 * @throws Exception invalid function signature message
+	 */
+	public function get_workflows($mixed = null) {
+		$validParameters = array(
+			"(string)",
+		);
+		$args = func_get_args();
+		$this->_checkArguments($args, $validParameters);
+		return $this->__soapCall("get_workflows", $args);
+	}
+
+
+	/**
+	 * Service Call: get_document_link_types
+	 * Parameter options:
+	 * (string) session_id
+	 * @param mixed,... See function description for parameter options
+	 * @return kt_document_types_response
+	 * @throws Exception invalid function signature message
+	 */
+	public function get_document_link_types($mixed = null) {
+		$validParameters = array(
+			"(string)",
+		);
+		$args = func_get_args();
+		$this->_checkArguments($args, $validParameters);
+		return $this->__soapCall("get_document_link_types", $args);
+	}
+
+
+	/**
+	 * Service Call: get_client_policies
+	 * Parameter options:
+	 * (string) session_id, (string) client
+	 * @param mixed,... See function description for parameter options
+	 * @return kt_client_policies_response
+	 * @throws Exception invalid function signature message
+	 */
+	public function get_client_policies($mixed = null) {
+		$validParameters = array(
+			"(string)(string)",
+		);
+		$args = func_get_args();
+		$this->_checkArguments($args, $validParameters);
+		return $this->__soapCall("get_client_policies", $args);
+	}
+
+
+}}
+
+?>
\ No newline at end of file
diff -Nupwbr -x .svn kt/includes/KnowledgeTreeService_classes.php /tmp/kt/includes/KnowledgeTreeService_classes.php
--- kt/includes/KnowledgeTreeService_classes.php	1969-12-31 16:00:00.000000000 -0800
+++ /tmp/kt/includes/KnowledgeTreeService_classes.php	2009-08-02 12:05:10.000000000 -0700
@@ -0,0 +1,1141 @@
+<?php
+
+/*
+ * Generated automatically from KT 3.6.1 WSDL
+ * Using WSDL->PHP generator http://code.google.com/p/wsdl2php-interpreter/
+ * with a few custom tweaks
+ * @author aantonop
+ */
+
+
+if (!class_exists("kt_response")) {
+/**
+ * kt_response
+ */
+class kt_response {
+	/**
+	 * @access public
+	 * @var integer
+	 */
+	public $status_code;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $message;
+}}
+
+if (!class_exists("kt_folder_detail")) {
+/**
+ * kt_folder_detail
+ */
+class kt_folder_detail {
+	/**
+	 * @access public
+	 * @var integer
+	 */
+	public $status_code;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $message;
+	/**
+	 * @access public
+	 * @var integer
+	 */
+	public $id;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $folder_name;
+	/**
+	 * @access public
+	 * @var integer
+	 */
+	public $parent_id;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $full_path;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $created_by;
+}}
+
+if (!class_exists("kt_folder_item")) {
+/**
+ * kt_folder_item
+ */
+class kt_folder_item {
+	/**
+	 * @access public
+	 * @var integer
+	 */
+	public $id;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $item_type;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $custom_document_no;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $oem_document_no;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $title;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $document_type;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $filename;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $filesize;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $created_by;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $created_date;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $checked_out_by;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $checked_out_date;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $modified_by;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $modified_date;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $owned_by;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $version;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $is_immutable;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $permissions;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $workflow;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $workflow_state;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $mime_type;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $mime_icon_path;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $mime_display;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $storage_path;
+	/**
+	 * @access public
+	 * @var kt_folder_items
+	 */
+	public $items;
+}}
+
+if (!class_exists("kt_folder_items")) {
+/**
+ * kt_folder_items
+ */
+class kt_folder_items {
+}}
+
+if (!class_exists("kt_folder_contents")) {
+/**
+ * kt_folder_contents
+ */
+class kt_folder_contents {
+	/**
+	 * @access public
+	 * @var integer
+	 */
+	public $status_code;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $message;
+	/**
+	 * @access public
+	 * @var integer
+	 */
+	public $folder_id;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $folder_name;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $full_path;
+	/**
+	 * @access public
+	 * @var kt_folder_items
+	 */
+	public $items;
+}}
+
+if (!class_exists("kt_document_detail")) {
+/**
+ * kt_document_detail
+ */
+class kt_document_detail {
+	/**
+	 * @access public
+	 * @var integer
+	 */
+	public $status_code;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $message;
+	/**
+	 * @access public
+	 * @var integer
+	 */
+	public $document_id;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $custom_document_no;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $oem_document_no;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $title;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $document_type;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $full_path;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $filename;
+	/**
+	 * @access public
+	 * @var integer
+	 */
+	public $filesize;
+	/**
+	 * @access public
+	 * @var integer
+	 */
+	public $folder_id;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $created_by;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $created_date;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $checked_out_by;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $checked_out_date;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $modified_by;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $modified_date;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $owned_by;
+	/**
+	 * @access public
+	 * @var double
+	 */
+	public $version;
+	/**
+	 * @access public
+	 * @var boolean
+	 */
+	public $is_immutable;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $permissions;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $workflow;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $workflow_state;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $mime_type;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $mime_icon_path;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $mime_display;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $storage_path;
+	/**
+	 * @access public
+	 * @var kt_metadata_fieldsets
+	 */
+	public $metadata;
+	/**
+	 * @access public
+	 * @var kt_linked_documents
+	 */
+	public $links;
+	/**
+	 * @access public
+	 * @var kt_workflow_transitions
+	 */
+	public $transitions;
+	/**
+	 * @access public
+	 * @var kt_document_version_history
+	 */
+	public $version_history;
+	/**
+	 * @access public
+	 * @var kt_document_transaction_history
+	 */
+	public $transaction_history;
+}}
+
+if (!class_exists("kt_search_result_item")) {
+/**
+ * kt_search_result_item
+ */
+class kt_search_result_item {
+	/**
+	 * @access public
+	 * @var integer
+	 */
+	public $document_id;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $custom_document_no;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $oem_document_no;
+	/**
+	 * @access public
+	 * @var double
+	 */
+	public $relevance;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $text;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $title;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $document_type;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $fullpath;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $filename;
+	/**
+	 * @access public
+	 * @var integer
+	 */
+	public $filesize;
+	/**
+	 * @access public
+	 * @var integer
+	 */
+	public $folder_id;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $created_by;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $created_date;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $checked_out_by;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $checked_out_date;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $modified_by;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $modified_date;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $owned_by;
+	/**
+	 * @access public
+	 * @var double
+	 */
+	public $version;
+	/**
+	 * @access public
+	 * @var boolean
+	 */
+	public $is_immutable;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $permissions;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $workflow;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $workflow_state;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $mime_type;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $mime_icon_path;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $mime_display;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $storage_path;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $status;
+}}
+
+if (!class_exists("kt_search_results")) {
+/**
+ * kt_search_results
+ */
+class kt_search_results {
+}}
+
+if (!class_exists("kt_search_response")) {
+/**
+ * kt_search_response
+ */
+class kt_search_response {
+	/**
+	 * @access public
+	 * @var integer
+	 */
+	public $status_code;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $message;
+	/**
+	 * @access public
+	 * @var kt_search_results
+	 */
+	public $hits;
+}}
+
+if (!class_exists("kt_sysdata_item")) {
+/**
+ * kt_sysdata_item
+ */
+class kt_sysdata_item {
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $name;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $value;
+}}
+
+if (!class_exists("kt_sysdata")) {
+/**
+ * kt_sysdata
+ */
+class kt_sysdata {
+}}
+
+if (!class_exists("kt_metadata_selection_item")) {
+/**
+ * kt_metadata_selection_item
+ */
+class kt_metadata_selection_item {
+	/**
+	 * @access public
+	 * @var integer
+	 */
+	public $id;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $name;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $value;
+	/**
+	 * @access public
+	 * @var integer
+	 */
+	public $parent_id;
+}}
+
+if (!class_exists("kt_metadata_selection")) {
+/**
+ * kt_metadata_selection
+ */
+class kt_metadata_selection {
+}}
+
+if (!class_exists("kt_metadata_field")) {
+/**
+ * kt_metadata_field
+ */
+class kt_metadata_field {
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $name;
+	/**
+	 * @access public
+	 * @var boolean
+	 */
+	public $required;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $value;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $description;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $control_type;
+	/**
+	 * @access public
+	 * @var kt_metadata_selection
+	 */
+	public $selection;
+}}
+
+if (!class_exists("kt_metadata_fields")) {
+/**
+ * kt_metadata_fields
+ */
+class kt_metadata_fields {
+}}
+
+if (!class_exists("kt_metadata_fieldset")) {
+/**
+ * kt_metadata_fieldset
+ */
+class kt_metadata_fieldset {
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $fieldset;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $description;
+	/**
+	 * @access public
+	 * @var kt_metadata_fields
+	 */
+	public $fields;
+}}
+
+if (!class_exists("kt_metadata_fieldsets")) {
+/**
+ * kt_metadata_fieldsets
+ */
+class kt_metadata_fieldsets {
+}}
+
+if (!class_exists("kt_metadata_response")) {
+/**
+ * kt_metadata_response
+ */
+class kt_metadata_response {
+	/**
+	 * @access public
+	 * @var integer
+	 */
+	public $status_code;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $message;
+	/**
+	 * @access public
+	 * @var kt_metadata_fieldsets
+	 */
+	public $metadata;
+}}
+
+if (!class_exists("kt_workflow_transitions")) {
+/**
+ * kt_workflow_transitions
+ */
+class kt_workflow_transitions {
+}}
+
+if (!class_exists("kt_workflow_transitions_response")) {
+/**
+ * kt_workflow_transitions_response
+ */
+class kt_workflow_transitions_response {
+	/**
+	 * @access public
+	 * @var integer
+	 */
+	public $status_code;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $message;
+	/**
+	 * @access public
+	 * @var kt_workflow_transitions
+	 */
+	public $transitions;
+}}
+
+if (!class_exists("kt_workflows_array")) {
+/**
+ * kt_workflows_array
+ */
+class kt_workflows_array {
+}}
+
+if (!class_exists("kt_workflows_response")) {
+/**
+ * kt_workflows_response
+ */
+class kt_workflows_response {
+	/**
+	 * @access public
+	 * @var integer
+	 */
+	public $status_code;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $message;
+	/**
+	 * @access public
+	 * @var kt_workflows_array
+	 */
+	public $workflows;
+}}
+
+if (!class_exists("kt_document_transaction_history_item")) {
+/**
+ * kt_document_transaction_history_item
+ */
+class kt_document_transaction_history_item {
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $transaction_name;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $username;
+	/**
+	 * @access public
+	 * @var double
+	 */
+	public $version;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $comment;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $datetime;
+}}
+
+if (!class_exists("kt_linked_document")) {
+/**
+ * kt_linked_document
+ */
+class kt_linked_document {
+	/**
+	 * @access public
+	 * @var integer
+	 */
+	public $document_id;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $custom_document_no;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $oem_document_no;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $title;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $document_type;
+	/**
+	 * @access public
+	 * @var integer
+	 */
+	public $filesize;
+	/**
+	 * @access public
+	 * @var double
+	 */
+	public $version;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $workflow;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $workflow_state;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $link_type;
+}}
+
+if (!class_exists("kt_linked_documents")) {
+/**
+ * kt_linked_documents
+ */
+class kt_linked_documents {
+}}
+
+if (!class_exists("kt_linked_document_response")) {
+/**
+ * kt_linked_document_response
+ */
+class kt_linked_document_response {
+	/**
+	 * @access public
+	 * @var integer
+	 */
+	public $status_code;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $message;
+	/**
+	 * @access public
+	 * @var integer
+	 */
+	public $parent_document_id;
+	/**
+	 * @access public
+	 * @var kt_linked_documents
+	 */
+	public $links;
+}}
+
+if (!class_exists("kt_document_transaction_history")) {
+/**
+ * kt_document_transaction_history
+ */
+class kt_document_transaction_history {
+}}
+
+if (!class_exists("kt_document_transaction_history_response")) {
+/**
+ * kt_document_transaction_history_response
+ */
+class kt_document_transaction_history_response {
+	/**
+	 * @access public
+	 * @var integer
+	 */
+	public $status_code;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $message;
+	/**
+	 * @access public
+	 * @var kt_document_transaction_history
+	 */
+	public $history;
+}}
+
+if (!class_exists("kt_document_version_history_item")) {
+/**
+ * kt_document_version_history_item
+ */
+class kt_document_version_history_item {
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $user;
+	/**
+	 * @access public
+	 * @var integer
+	 */
+	public $metadata_version;
+	/**
+	 * @access public
+	 * @var double
+	 */
+	public $content_version;
+}}
+
+if (!class_exists("kt_document_collection")) {
+/**
+ * kt_document_collection
+ */
+class kt_document_collection {
+}}
+
+if (!class_exists("kt_document_collection_response")) {
+/**
+ * kt_document_collection_response
+ */
+class kt_document_collection_response {
+	/**
+	 * @access public
+	 * @var integer
+	 */
+	public $status_code;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $message;
+	/**
+	 * @access public
+	 * @var kt_document_collection
+	 */
+	public $collection;
+}}
+
+if (!class_exists("kt_folder_collection")) {
+/**
+ * kt_folder_collection
+ */
+class kt_folder_collection {
+}}
+
+if (!class_exists("kt_folder_collection_response")) {
+/**
+ * kt_folder_collection_response
+ */
+class kt_folder_collection_response {
+	/**
+	 * @access public
+	 * @var integer
+	 */
+	public $status_code;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $message;
+	/**
+	 * @access public
+	 * @var kt_folder_collection
+	 */
+	public $collection;
+}}
+
+if (!class_exists("kt_document_version_history")) {
+/**
+ * kt_document_version_history
+ */
+class kt_document_version_history {
+}}
+
+if (!class_exists("kt_document_version_history_response")) {
+/**
+ * kt_document_version_history_response
+ */
+class kt_document_version_history_response {
+	/**
+	 * @access public
+	 * @var integer
+	 */
+	public $status_code;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $message;
+	/**
+	 * @access public
+	 * @var kt_document_version_history
+	 */
+	public $history;
+}}
+
+if (!class_exists("kt_document_types_array")) {
+/**
+ * kt_document_types_array
+ */
+class kt_document_types_array {
+}}
+
+if (!class_exists("kt_document_types_response")) {
+/**
+ * kt_document_types_response
+ */
+class kt_document_types_response {
+	/**
+	 * @access public
+	 * @var integer
+	 */
+	public $status_code;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $message;
+	/**
+	 * @access public
+	 * @var kt_document_types_array
+	 */
+	public $document_types;
+}}
+
+if (!class_exists("kt_client_policy")) {
+/**
+ * kt_client_policy
+ */
+class kt_client_policy {
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $name;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $value;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $type;
+}}
+
+if (!class_exists("kt_client_policies_array")) {
+/**
+ * kt_client_policies_array
+ */
+class kt_client_policies_array {
+}}
+
+if (!class_exists("kt_client_policies_response")) {
+/**
+ * kt_client_policies_response
+ */
+class kt_client_policies_response {
+	/**
+	 * @access public
+	 * @var integer
+	 */
+	public $status_code;
+	/**
+	 * @access public
+	 * @var string
+	 */
+	public $message;
+	/**
+	 * @access public
+	 * @var kt_client_policies_array
+	 */
+	public $policies;
+}}
+
+?>
\ No newline at end of file
diff -Nupwbr -x .svn kt/kt_api/kt_api.info /tmp/kt/kt_api/kt_api.info
--- kt/kt_api/kt_api.info	1969-12-31 16:00:00.000000000 -0800
+++ /tmp/kt/kt_api/kt_api.info	2009-08-02 12:05:10.000000000 -0700
@@ -0,0 +1,6 @@
+; $Id$
+name = KnowledgeTree REST API
+description = Implements a skeleton REST API to interface with Knowledgetree
+package = KnowledgeTree
+project = "KT Rest API"
+core = 6.x
\ No newline at end of file
diff -Nupwbr -x .svn kt/kt_api/kt_api.module /tmp/kt/kt_api/kt_api.module
--- kt/kt_api/kt_api.module	1969-12-31 16:00:00.000000000 -0800
+++ /tmp/kt/kt_api/kt_api.module	2009-08-02 12:05:10.000000000 -0700
@@ -0,0 +1,195 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Implements a REST API to an external Knowledgetree Installation
+ */
+
+require_once drupal_get_path('module', 'kt').'/includes/KnowledgeTreeService_REST.php';
+
+function kt_api_menu() {
+  $items['admin/settings/kt_api/test'] = array(
+    'title'  => "KT REST Test",
+    'page callback' => 'kt_api_page',
+    'page arguments' => array(1),
+    'access arguments' => array('administer site configuration'),
+  	'type' => MENU_NORMAL_ITEM,
+  );
+  $items['admin/settings/kt_api'] = array(
+    'title' => t('KnowledgeTree REST API Settings'),
+    'description' => t('Configure the integration with KnowledgeTree\'s REST API'),
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('kt_api_settings'),
+    'access arguments' => array('administer site configuration'),
+    'type' => MENU_NORMAL_ITEM,
+  );
+
+  return $items;
+}
+
+function kt_api_settings() {
+
+  $form = array();
+
+  $form['kt_root_url'] = array (
+      '#type' => 'textfield',
+      '#title' => t('Knowledgetree root URL'),
+      '#default_value' => variable_get('kt_root_url', 'http://localhost/kt/'),
+      '#description' => t("The root URL of your Knowledgtree Installation, including a trailing slash. eg. http://localhost/kt/"),
+    );
+  $form['kt_login'] = array(
+   	  '#type' => 'fieldset',
+      '#title' => t('KnowledgeTree Authentication'),
+      '#description' => t('Authentication details for accessing KT from Drupal.  <strong>Best to create a new user in KT with restricted permissions. Whatever this user can access in KT will be accessible to all drupal users.</strong>'),
+      '#collapsible' => TRUE,
+      '#collapsed' => FALSE,
+    );
+
+  $form['kt_login']['kt_username'] = array (
+      '#type' => 'textfield',
+      '#title' => t('Knowledgetree Login Username'),
+      '#default_value' => variable_get('kt_username', 'drupal'),
+      '#size' => 20,
+      '#maxlength' => 50,
+      '#description' => t("The username drupal will use to access Knowledgetree."),
+    );
+   $form['kt_login']['kt_password'] = array (
+      '#type' => 'password',
+      '#title' => t('Knowledgetree Login Password'),
+      '#size' => 20,
+      '#maxlength' => 255,
+      '#description' => t("The password drupal will use to access Knowledgetree."),
+    );
+    $session_timeout_options = array(
+      0 => t("Do not cache session"),
+      30 => t("Cache session for 30 sec"),
+      60 => t("Cahce session for 1 min"),
+      300 => t("Cache session for 5 min"),
+      1800 => t("Cache session for 30 min"),
+    );
+
+    $form['kt_login']['kt_session_cache'] = array (
+      '#type' => 'select',
+      '#title' => t('KnowledgeTree Session Caching'),
+      '#description' => t('How long should Drupal cache the KT session. The KT default timeout for inactivity is 1200 seconds (See KT General Settings page). If this cache timeout is set to a higher number than KTs session timeout, errors may occur.'),
+      '#default_value' => variable_get('kt_session_cache', 300),
+      '#options' => $session_timeout_options,
+      '#required' => TRUE,
+    );
+
+    $form['kt_debug'] = array (
+      '#type' => 'checkbox',
+      '#title' => t('KT REST Debug'),
+      '#default_value' => variable_get('kt_debug', 0),
+      '#description' => t('Print verbose debug information on each REST call'),
+    );
+
+  return system_settings_form($form);
+}
+
+//function kt_api_perms() {
+//  return array('display KT REST Test Page');
+//}
+
+function kt_api_page() {
+
+  $page = "";
+
+  $kt = new Drupal_KT_REST;
+  $kt->login();
+
+  //$search_results = _kt_xmlobj2array($kt->search('Filename CONTAINS "e" ', "none"));
+  //$page = "<pre>".print_r($search_results, TRUE)."</pre>";
+
+  //$document = $kt->get_document_detail("1", "");
+  //$document = _kt_xmlobj2array($document);
+  //$page = "<p>If this test is successful you should see an array with document details matching the document with ID#1 in KnowledgeTree:\n<pre>".print_r($document, TRUE)."</pre>";
+
+  $response = $kt->download_document("1");
+
+  $page = kpr($response,TRUE);
+
+
+  return $page;
+}
+
+/**
+ * Converts an XML object (such as the one returned by SimpleXML::simplexml_load_string)
+ * into a simple array
+ *
+ */
+function _kt_xmlobj2array($Data) {
+  if (is_object($Data)) {
+    foreach (get_object_vars($Data) as $key => $val) {
+      $ret[$key] = _kt_xmlobj2array($val);
+    }
+    return $ret;
+  } elseif (is_array($Data)) {
+    foreach ($Data as $key => $val) {
+      $ret[$key] = _kt_xmlobj2array($val);
+    }
+    return $ret;
+  } else {
+    return $Data;
+  }
+}
+
+
+
+class Drupal_KT_REST extends KnowledgeTreeRESTService {
+
+  function login() {
+
+    // Check for a cached session first
+    $cached_session=cache_get('kt_session', 'cache');
+    if (isset($cached_session->data) && ($cached_session->expire > time()) && variable_get('kt_session_cache', 0)) {
+      $this->session = $cached_session->data;
+      $this->log('KT REST: Using cached session :'.print_r($this->session,TRUE), 'DEBUG');
+    }
+    else { // No cached session exists or cached session expired, use regular login call
+
+      cache_clear_all('kt_session', 'cache'); // Clear old cached session, if any
+
+      if (($kt_url = variable_get('kt_root_url', '')) == '') {
+        $this->log('KT REST: No KT root URL set. Check the Knowledgetree REST API Settings.', 'ERROR');
+      }
+      if (($kt_user = variable_get('kt_username', '')) == '') {
+        $this->log('KT REST: No KT username set. Check the Knowledgetree REST API Settings.', 'ERROR');
+      }
+      if (($kt_pass = variable_get('kt_password', '')) == '') {
+        $this->log('KT REST: No KT password set. Check the Knowledgetree REST API Settings.', 'ERROR');
+      }
+      parent::login($kt_url.'ktwebservice/KTWebService.php',$kt_user, $kt_pass);
+      if (isset($this->session['session_id']) && $this->session['session_id'] != 0) {
+        // Cache the new session id to keep persistent session with timeout
+        cache_set("kt_session", $this->session, "cache", time() + variable_get('kt_session_cache', 0));
+      }
+      else { // parent::login failed
+        return FALSE;
+      }
+    }
+    return TRUE;
+  }
+
+  function log($message, $level='DEBUG') {
+    if (is_string($message) && !empty($message)) {
+      switch ($level) {
+        case 'ERROR':
+          watchdog('kt_api', $message, WATCHDOG_ERROR);
+          if (variable_get('kt_debug',0)) {
+            drupal_set_message('<pre>'.$message.'</pre>','error');
+          }
+          break;
+        case 'WARNING':
+        case 'DEBUG':
+          if (variable_get('kt_debug',0)) {
+            drupal_set_message('<pre>'.$message.'</pre>', 'info');
+          }
+          break;
+      }
+    }
+  }
+
+
+} // end class
\ No newline at end of file
diff -Nupwbr -x .svn kt/kt_docreference/kt_docreference.info /tmp/kt/kt_docreference/kt_docreference.info
--- kt/kt_docreference/kt_docreference.info	1969-12-31 16:00:00.000000000 -0800
+++ /tmp/kt/kt_docreference/kt_docreference.info	2009-08-02 12:07:57.000000000 -0700
@@ -0,0 +1,12 @@
+; $Id$
+name = KnowledgeTree Document Reference
+description = Defines a field type for referencing a knowledgtree document.
+dependencies[] = content
+dependencies[] = number
+dependencies[] = kt_api
+package = CCK
+core = 6.x
+
+version = "6.x-1.0"
+project = "kt"
+datestamp = "1245237621"
\ No newline at end of file
diff -Nupwbr -x .svn kt/kt_docreference/kt_docreference.install /tmp/kt/kt_docreference/kt_docreference.install
--- kt/kt_docreference/kt_docreference.install	1969-12-31 16:00:00.000000000 -0800
+++ /tmp/kt/kt_docreference/kt_docreference.install	2009-08-02 12:05:10.000000000 -0700
@@ -0,0 +1,39 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Implementation of hook_install().
+ */
+function kt_docreference_install() {
+  drupal_load('module', 'content');
+  content_notify('install', 'kt_docreference');
+}
+
+/**
+ * Implementation of hook_uninstall().
+ */
+function kt_docreference_uninstall() {
+  drupal_load('module', 'content');
+  content_notify('uninstall', 'kt_docreference');
+}
+
+/**
+ * Implementation of hook_enable().
+ *
+ * Notify content module when this module is enabled.
+ */
+function kt_docreference_enable() {
+  drupal_load('module', 'content');
+  content_notify('enable', 'kt_docreference');
+}
+
+/**
+ * Implementation of hook_disable().
+ *
+ * Notify content module when this module is disabled.
+ */
+function kt_docreference_disable() {
+  drupal_load('module', 'content');
+  content_notify('disable', 'kt_docreference');
+}
diff -Nupwbr -x .svn kt/kt_docreference/kt_docreference.module /tmp/kt/kt_docreference/kt_docreference.module
--- kt/kt_docreference/kt_docreference.module	1969-12-31 16:00:00.000000000 -0800
+++ /tmp/kt/kt_docreference/kt_docreference.module	2009-08-02 13:29:24.000000000 -0700
@@ -0,0 +1,373 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Defines a field type for referencing a knowledgtree document from a drupal node
+ */
+
+/**
+ * Implementation of hook_menu().
+ *
+ * @TODO: Provide some relevant permissions and use here
+ */
+function kt_docreference_menu() {
+  $items = array();
+  $items['kt_docreference/autocomplete'] = array(
+    'title' => 'kt_docreference autocomplete',
+    'page callback' => 'kt_docreference_autocomplete',
+    'access arguments' => array('access content'),
+    'type' => MENU_CALLBACK
+  );
+  return $items;
+}
+
+/**
+ * Implementation of hook_field_info().
+ */
+function kt_docreference_field_info() {
+  return array(
+    'kt_docreference' => array(
+      'label' => t('Knowledgetree doc reference'),
+      'description' => t('Store the ID of a knowledgetree document as an integer value.'),
+      'content_icon' => 'icon_content_ktdocref.png',
+    ),
+  );
+}
+
+function kt_docreference_field_settings($op, $field) {
+  switch ($op) {
+
+    case 'database columns':
+      $columns = array(
+        'value' => array('type' => 'int', 'length' => 11, 'sortable' => FALSE),
+      );
+      return $columns;
+  }
+}
+
+function kt_docreference_field($op, &$node, $field, &$items, $teaser, $page) {
+   switch ($op) {
+    case 'validate':
+      return $items;
+  }
+}
+
+function kt_docreference_widget_info() {
+  return array(
+    'kt_docreference_autocomplete' => array(
+      'label' => t('Autocomplete text field'),
+      'field types' => array('kt_docreference'),
+      'multiple values' => CONTENT_HANDLE_CORE,
+      'callbacks' => array(
+        'default value' => CONTENT_CALLBACK_DEFAULT,
+      ),
+    ),
+  );
+}
+
+function kt_docreference_widget(&$form, &$form_state, $field, $items, $delta = 0) {
+  switch ($field['widget']['type']) {
+    case 'kt_docreference_autocomplete':
+      $element = array(
+          '#type' => 'kt_docreference_autocomplete',
+          '#default_value' => isset($items[$delta]['value']) ? $items[$delta]['value'] : '',
+          '#value_callback' => 'kt_docreference_autocomplete_value',
+      );
+      break;
+  }
+  return $element;
+
+}
+
+function kt_docreference_content_is_empty($item, $field) {
+  if (empty($item['value']) && (string)$item['value'] !== '0') {
+    return TRUE;
+  }
+  return FALSE;
+}
+
+function kt_docreference_field_formatter_info() {
+  return array(
+    'plain' => array(
+      'label' => t('Document Name (no link)'),
+      'field types' => array('kt_docreference'),
+      'multiple values' => CONTENT_HANDLE_CORE,
+    ),
+    'default' => array(
+      'label' => t('Document Name (link to KT detail)'),
+      'field types' => array('kt_docreference'),
+      'multiple values' => CONTENT_HANDLE_CORE,
+    ),
+    'download' => array(
+      'label' => t('Document Name (link to download)'),
+      'field types' => array('kt_docreference'),
+      'multiple values' => CONTENT_HANDLE_CORE,
+    ),
+    'multi' => array(
+      'label' => t('Document Name (links to view and download)'),
+      'field types' => array('kt_docreference'),
+      'multiple values' => CONTENT_HANDLE_CORE,
+    ),
+
+  );
+}
+
+/**
+ * Implementation of FAPI hook_elements().
+ *
+ * Any FAPI callbacks needed for individual widgets can be declared here,
+ * and the element will be passed to those callbacks for processing.
+ *
+ * Drupal will automatically theme the element using a theme with
+ * the same name as the hook_elements key.
+ *
+ * Autocomplete_path is not used by text_widget but other widgets can use it
+ * (see nodereference and userreference).
+ */
+function kt_docreference_elements() {
+  return array(
+    'kt_docreference_autocomplete' => array(
+      '#input' => TRUE,
+      '#columns' => array('name'), '#delta' => 0,
+      '#process' => array('kt_docreference_autocomplete_process'),
+      '#autocomplete_path' => FALSE,
+      ),
+    );
+}
+function kt_docreference_theme() {
+  return array(
+  	'kt_docreference_autocomplete' => array(
+      'arguments' => array('element'),
+    ),
+    'kt_docreference_formatter_default' => array(
+      'arguments' => array('element'),
+      'function' => 'theme_kt_docreference_formatter_default',
+    ),
+    'kt_docreference_formatter_plain' => array(
+      'arguments' => array('element'),
+      'function' => 'theme_kt_docreference_formatter_plain',
+    ),
+    'kt_docreference_formatter_download' => array(
+      'arguments' => array('element'),
+      'function' => 'theme_kt_docreference_formatter_download',
+    ),
+    'kt_docreference_formatter_multi' => array(
+      'arguments' => array('element'),
+      'function' => 'theme_kt_docreference_formatter_multi',
+    ),
+  );
+}
+
+function theme_kt_docreference_formatter_plain($element) {
+  $output = '';
+  if (!empty($element['#item']['value']) && is_numeric($element['#item']['value']) && ($title = _kt_docreference_document_title($element['#item']['value']))) {
+    $output = $title;
+  }
+  return $output;
+}
+
+function theme_kt_docreference_formatter_default($element) {
+  $output = '';
+  if (!empty($element['#item']['value']) && is_numeric($element['#item']['value']) && ($title = _kt_docreference_document_title($element['#item']['value']))) {
+    $output = _kt_docreference_details_link($title, $element['#item']['value']);
+  }
+  return $output;
+}
+
+function theme_kt_docreference_formatter_download($element) {
+  $output = '';
+  if (!empty($element['#item']['value']) && is_numeric($element['#item']['value']) && ($title = _kt_docreference_document_title($element['#item']['value']))) {
+    $output = _kt_docreference_download_link($title, $element['#item']['value']);
+  }
+  return $output;
+}
+
+function theme_kt_docreference_formatter_multi($element) {
+  $output = '';
+  if (!empty($element['#item']['value']) && is_numeric($element['#item']['value']) && ($title = _kt_docreference_document_title($element['#item']['value']))) {
+    $output = $title ." ("._kt_docreference_details_link('Details', $element['#item']['value'])."|"._kt_docreference_download_link('Download', $element['#item']['value']).")";
+  }
+  return $output;
+}
+
+function _kt_docreference_document_title($document_id) {
+
+  $document = array();
+
+  $kt = new Drupal_KT_REST;
+  $kt->login();
+  if ($document = $kt->get_document_detail($document_id, "")) {
+      $document = _kt_xmlobj2array($document);
+  }
+  if (isset($document['title']) && !empty($document['title'])) {
+    return $document['title'];
+  }
+  else {
+    return "Untitled Document #".$document_id;
+  }
+}
+
+function _kt_docreference_details_link($title, $document_id) {
+  if (($kt_url = variable_get('kt_root_url', '')) == '') {
+      watchdog("kt_docreference", "KT REST root URL is not configured, so document links cannot be displayed", WATCHDOG_WARNING);
+      return $title;
+  }
+  else {
+      return l($title, $kt_url.'view.php?fDocumentId='. $document_id, array('attributes' => array('target' => '_blank')));
+  }
+}
+
+function _kt_docreference_download_link($title, $document_id) {
+if (($kt_url = variable_get('kt_root_url', '')) == '') {
+      watchdog("kt_docreference", "KT REST root URL is not configured, so document links cannot be displayed", WATCHDOG_WARNING);
+      return $title;
+  }
+  else {
+      return l($title, $kt_url.'action.php?kt_path_info=ktcore.actions.document.view&fDocumentId='. $document_id, array('attributes' => array('target' => '_blank')));
+  }
+
+}
+
+/**
+ * Value for a kt_docreference autocomplete element.
+ *
+ * Substitute in the node title for the node nid.
+ */
+function kt_docreference_autocomplete_value($element, $edit = FALSE) {
+  $field_key  = $element['#columns'][0];
+  if (!empty($element['#default_value'])) {
+    $document_id = $element['#default_value'];
+    $value = _kt_docreference_document_title($document_id);
+    $value .= ' [DocumentID:'. $document_id .']';
+    return array($field_key => $value);
+  }
+  return array($field_key => NULL);
+}
+
+/**
+ * Process an individual element.
+ *
+ * Build the form element. When creating a form using FAPI #process,
+ * note that $element['#value'] is already set.
+ *
+ */
+function kt_docreference_autocomplete_process($element, $edit, $form_state, $form) {
+
+  // The kt_docreference autocomplete widget doesn't need to create its own
+  // element, it can wrap around the text_textfield element and add an autocomplete
+  // path and some extra processing to it.
+  // Add a validation step where the value can be unwrapped.
+  $field_key  = $element['#columns'][0];
+
+  $element[$field_key] = array(
+    '#type' => 'text_textfield',
+    '#default_value' => isset($element['#value']) ? $element['#value'] : '',
+    '#autocomplete_path' => 'kt_docreference/autocomplete/'. $element['#field_name'],
+    // The following values were set by the content module and need
+    // to be passed down to the nested element.
+    '#title' => $element['#title'],
+    '#required' => $element['#required'],
+    '#description' => $element['#description'],
+    '#field_name' => $element['#field_name'],
+    '#type_name' => $element['#type_name'],
+    '#delta' => $element['#delta'],
+    '#columns' => $element['#columns'],
+  );
+  if (empty($element[$field_key]['#element_validate'])) {
+    $element[$field_key]['#element_validate'] = array();
+  }
+  array_unshift($element[$field_key]['#element_validate'], 'kt_docreference_autocomplete_validate');
+
+  // Used so that hook_field('validate') knows where to flag an error.
+  $element['_error_element'] = array(
+    '#type' => 'value',
+    // Wrapping the element around a text_textfield element creates a
+    // nested element, so the final id will look like 'field-name-0-nid-nid'.
+    '#value' => implode('][', array_merge($element['#parents'], array($field_key, $field_key))),
+  );
+  return $element;
+}
+
+/**
+ * Validate an autocomplete element.
+ *
+ * Remove the wrapper layer and set the right element's value.
+ * This will move the nested value at 'field-name-0-nid-nid'
+ * back to its original location, 'field-name-0-nid'.
+ */
+function kt_docreference_autocomplete_validate($element, &$form_state) {
+  $field_name = $element['#field_name'];
+  $type_name = $element['#type_name'];
+  $field = content_fields($field_name, $type_name);
+  $field_key  = $element['#columns'][0];
+  $delta = $element['#delta'];
+  $value = $element['#value'][$field_key];
+  $document_id = NULL;
+  if (!empty($value)) {
+    preg_match('/^(?:\s*|(.*) )?\[DocumentID:(\d+)\]$/', $value, $matches);
+    if (!empty($matches)) {
+      // Explicit [DocumentID:n].
+      list(, $title, $document_id) = $matches;
+      if (!empty($title) && ($title != _kt_docreference_document_title($document_id))) {
+        form_error($element[$field_key], t('%name: title mismatch. Please check your selection.', array('%name' => t($field['widget']['label']))));
+      }
+    }
+    else {
+      // No explicit DocumentID.
+      $reference = _kt_docreference_autocomplete($field, $value);
+      if (empty($reference)) {
+        form_error($element[$field_key], t('%name: found no valid document with that title.', array('%name' => t($field['widget']['label']))));
+      }
+      else {
+        // TODO:
+        // the best thing would be to present the user with an additional form,
+        // allowing the user to choose between valid candidates with the same title
+        // ATM, we pick the first matching candidate...
+        $document_id = key($reference);
+      }
+    }
+  }
+  form_set_value($element, $document_id, $form_state);
+}
+/**
+ * Menu callback; Retrieve a pipe delimited string of autocomplete suggestions for existing users
+ */
+function kt_docreference_autocomplete($field_name, $string = '') {
+
+  if ($string == '') {
+      return;
+  }
+
+  $kt = new Drupal_KT_REST;
+  $kt->login();
+
+  $search_query = '(Filename CONTAINS "'.$string.'") OR (Title CONTAINS "'.$string.'")';
+
+  $results = array();
+  $results = _kt_xmlobj2array($kt->search($search_query, "optionsargdoesntseemtodoanything"));
+
+  if (!is_array($results) || empty($results)) { // We got nothing!
+    drupal_json(array()); // return empty array
+    return;
+  }
+  else if (is_array($results['item'][0])) { // We got multiple results = array(item=>(0=>first_doc,1=>second_doc...))
+    $results = $results['item']; //
+  }
+  else { // We got only one document - results = array(item=>first_doc) with no index.
+    $results[0] = $results['item']; // Make it consistent with multiple results structure, only one doc on index 0
+  }
+
+  foreach ($results as $result) {
+    // Add a class wrapper for a few required CSS overrides.
+    $title = $result['title'];
+    $id = $result['document_id'];
+    $matches[$title ." [DocumentID:$id]"] = '<div class="reference-autocomplete">'. $title . '</div>';
+  }
+
+  drupal_json($matches);
+}
+
+function theme_kt_docreference_autocomplete($element) {
+  return $element['#children'];
+}
\ No newline at end of file
