Source for file webservice.php

Documentation is available at webservice.php

  1. <?
  2.  
  3. /**
  4.  *
  5.  * This implements the KnowledgeTree Web Service in SOAP.
  6.  * @license http://www.knowledgetree.com/KPL KnowledgeTree Public License Version 1.1
  7.  * @package KTWEBSERVICE
  8.  */
  9.  
  10. /*
  11.  *
  12.  * The contents of this file are subject to the KnowledgeTree Public
  13.  * License Version 1.1 ("License"); You may not use this file except in
  14.  * compliance with the License. You may obtain a copy of the License at
  15.  * http://www.knowledgetree.com/KPL
  16.  * 
  17.  * Software distributed under the License is distributed on an "AS IS"
  18.  * basis,
  19.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  20.  * for the specific language governing rights and limitations under the
  21.  * License.
  22.  * 
  23.  * The Original Code is: KnowledgeTree Open Source
  24.  * 
  25.  * The Initial Developer of the Original Code is The Jam Warehouse Software
  26.  * (Pty) Ltd, trading as KnowledgeTree.
  27.  * Portions created by The Jam Warehouse Software (Pty) Ltd are Copyright
  28.  * (C) 2007 The Jam Warehouse Software (Pty) Ltd;
  29.  * All Rights Reserved.
  30.  *
  31.  */
  32.  
  33. require_once('../config/dmsDefaults.php');
  34. require_once('../ktapi/ktapi.inc.php');
  35. require_once('SOAP/Server.php');
  36. require_once('SOAP/Disco.php');
  37. require_once('KTDownloadManager.inc.php');
  38.  
  39. // TODO: Test getting files/metadata based on versioning works and implementation is consistent.
  40.  
  41. // Status Codes as defined in the specification.
  42.  
  43. define('KTWS_SUCCESS',                        0);
  44. define('KTWS_ERR_INVALID_SESSION',            1);
  45. define('KTWS_ERR_AUTHENTICATION_ERROR',        2);
  46. define('KTWS_ERR_INSUFFICIENT_PERMISSIONS',    3);
  47. define('KTWS_ERR_FILE_NOT_FOUND',            10);
  48. define('KTWS_ERR_INVALID_FILENAME',            20);
  49. define('KTWS_ERR_INVALID_DOCUMENT',            21);
  50. define('KTWS_ERR_INVALID_FOLDER',            22);
  51. define('KTWS_ERR_INVALID_METADATA',            23);
  52. define('KTWS_ERR_INVALID_REASON',            24);
  53. define('KTWS_ERR_INVALID_DEPTH',            25);
  54. define('KTWS_ERR_PROBLEM',                    98);
  55. define('KTWS_ERR_DB_PROBLEM',                99);
  56.  
  57. {
  58.     /**
  59.      * Defines functions, parameters, and return values.
  60.      *
  61.      * @var array 
  62.      */
  63.     var $__dispatch_map = array();
  64.     
  65.     /**
  66.      * Defines the structures that are used by web service functions.
  67.      *
  68.      * @var array 
  69.      */
  70.     var $__typedef = array();
  71.     
  72.     /**
  73.      * This is the namespace used by the web service.
  74.      *
  75.      * @var unknown_type 
  76.      */
  77.     
  78.     var $namespace;
  79.     
  80.     function KTWebService(
  81.     {
  82.         // Caching was giving some problems, so disable it.
  83.         
  84.         $config &KTConfig::getSingleton();
  85.         $cache_enabled $config->get('cache/cacheEnabled');
  86.         if ($cache_enabled)
  87.         {
  88.             $config->setns('cache','cacheEnabled',false);
  89.         }
  90.         
  91.         $this->namespace = 'KnowledgeTree';
  92.  
  93.         $this->__typedef['kt_response'=
  94.              array(
  95.                 'status_code' => 'int',
  96.                 'message' => 'string'  
  97.              );  
  98.              
  99.         $this->__typedef['kt_folder_detail'=
  100.              array(
  101.                  'status_code'=>'int',
  102.                  'message'=>'string',
  103.                 'id' => 'int',
  104.                 'folder_name' => 'string',
  105.                 'parent_id' => 'int',
  106.                 'full_path' => 'string',
  107.              );                     
  108.         
  109.            
  110.              
  111.         $this->__typedef['kt_folder_item'=
  112.              array(
  113.                 'id' => 'int',
  114.                 'item_type' => 'string',
  115.                 'title' => 'string',
  116.                 'creator' => 'string',
  117.                 'checked_out_by' => 'string',
  118.                 'modified_by' => 'string',
  119.                 'filename' => 'string',
  120.                 'size' => 'string',
  121.                 'major_version' => 'string',
  122.                 'minor_version' => 'string',
  123.                 'storage_path' => 'string',
  124.                 'mime_type' => 'string',
  125.                 'mime_icon_path' => 'string',
  126.                 'mime_display' => 'string',        
  127.                 'items' =>"{urn:$this->namespace}kt_folder_items"         
  128.              );             
  129.  
  130.         $this->__typedef['kt_folder_items'=
  131.             array(
  132.                 array(
  133.                         'item' => "{urn:$this->namespace}kt_folder_item"
  134.                   )
  135.             );          
  136.  
  137.             
  138.         $this->__typedef['kt_folder_contents'=
  139.              array(
  140.                 'status_code' => 'int',      
  141.                 'message' => 'string',           
  142.                 'folder_id' => 'int',
  143.                 'folder_name' => 'string' ,
  144.                 'full_path' => 'string' ,
  145.                 'items' => "{urn:$this->namespace}kt_folder_items",           
  146.              );                 
  147.              
  148.          $this->__typedef['kt_document_detail'=
  149.              array(
  150.                  'status_code'=>'int',
  151.                  'message'=>'string',             
  152.                 'title' => 'string',
  153.                 'document_type' => 'string',
  154.                 'version' => 'string',
  155.                    'filename' => 'string',
  156.                    'created_date' => 'string',
  157.                    'created_by' => 'string',
  158.                    'updated_date' => 'string',
  159.                     'updated_by' => 'string',
  160.                      'document_id' => 'int',
  161.                       'folder_id' => 'int',
  162.                    'workflow' => 'string',
  163.                    'workflow_state' => 'string',
  164.                    'checkout_by' => 'string',
  165.                    'full_path' => 'string',        
  166.               //  'metadata' => "{urn:$this->namespace}kt_metadata_fieldsets" 
  167.              );             
  168.              
  169.         $this->__typedef['kt_metadata_selection_item'=
  170.              array(
  171.                 'id' => 'int',      
  172.                 'name' => 'string',           
  173.                 'value' => 'string',
  174.                 'parent_id' => 'int'          
  175.              );             
  176.                      
  177.  
  178.         $this->__typedef['kt_metadata_selection'=
  179.              array(
  180.                 array(
  181.                         'item' => "{urn:$this->namespace}kt_metadata_selection_item"
  182.                   )       
  183.              );              
  184.              
  185.              
  186.         $this->__typedef['kt_metadata_field'=
  187.              array(
  188.                 'name' => 'string',
  189.                 'required' => 'boolean' ,
  190.                 'value' => 'string' ,
  191.                 'description' => 'string' ,
  192.                 'control_type' => 'string' ,
  193.                 'selection' => "{urn:$this->namespace}kt_metadata_selection,
  194.              );
  195.  
  196.         $this->__typedef['kt_metadata_fields'=
  197.             array(
  198.                 array(
  199.                         'field' => "{urn:$this->namespace}kt_metadata_field"
  200.                   )
  201.             );
  202.         $this->__typedef['kt_metadata_fieldset'=
  203.              array(
  204.                 'fieldset' => 'string',
  205.                 'description' => 'string',
  206.                 'fields' => "{urn:$this->namespace}kt_metadata_fields,
  207.              );
  208.              
  209.         $this->__typedef['kt_metadata_fieldsets'=
  210.             array(
  211.                 array(
  212.                         'fieldset' => "{urn:$this->namespace}kt_metadata_fieldset"
  213.                   )
  214.             );             
  215.              
  216.         $this->__typedef['kt_metadata_response'=
  217.              array(
  218.                 'status_code' => 'int',
  219.                 'message' => 'string',
  220.                 'metadata' => "{urn:$this->namespace}kt_metadata_fieldsets,
  221.              );  
  222.                 
  223.         $this->__typedef['kt_document_transitions'=
  224.             array(
  225.                 array(
  226.                         'transition' => 'string'
  227.                   )
  228.             );     
  229.             
  230.         $this->__typedef['kt_document_transitions_response'=
  231.              array(
  232.                  'status_code'=>'int',
  233.                  'message'=>'string',
  234.                  'metadata' => "{urn:$this->namespace}kt_document_transitions
  235.                  );      
  236.                  
  237.         $this->__typedef['kt_document_transaction_history_item'=
  238.              array(
  239.                  'transaction_name'=>'string',
  240.                  'username'=>'string',
  241.                  'version' => 'string',
  242.                  'comment' => 'string',
  243.                  'datetime' => 'string',
  244.                   
  245.                  );                   
  246.                  
  247.              
  248.         $this->__typedef['kt_document_transaction_history'=
  249.             array(
  250.                 array(
  251.                         'history' => "{urn:$this->namespace}kt_document_transaction_history_item"
  252.                   )
  253.             );                   
  254.                  
  255.                  
  256.         $this->__typedef['kt_document_transaction_history_response'=
  257.              array(
  258.                  'status_code'=>'int',
  259.                  'message'=>'string',
  260.                  'history' => "{urn:$this->namespace}kt_document_transaction_history
  261.                  )
  262.  
  263.         $this->__typedef['kt_document_version_history_item'=
  264.              array(
  265.                  'user'=>'int',
  266.                  'metadata_version'=>'string',
  267.                  'content_version'=>'string'
  268.                  );                  
  269.                  
  270.                  
  271.         $this->__typedef['kt_document_version_history'=
  272.             array(
  273.                 array(
  274.                         'history' =>  "{urn:$this->namespace}kt_document_version_history_item
  275.                   )
  276.             );                   
  277.                  
  278.  
  279.         $this->__typedef['kt_document_version_history_response'=
  280.              array(
  281.                  'status_code'=>'int',
  282.                  'message'=>'string',
  283.                  'history' => "{urn:$this->namespace}kt_document_version_history
  284.                  )
  285.                  
  286.                  
  287.            $this->__typedef['kt_document_types_array'=
  288.             array(
  289.                 array(
  290.                         'document_type' => 'string'
  291.                   )
  292.             );               
  293.              
  294.         $this->__typedef['kt_document_types_response'=
  295.             array(
  296.                 'status_code' => 'int',
  297.                 'message' => 'string',
  298.                 'document_types' => "{urn:$this->namespace}kt_document_types_array"
  299.             );    
  300.                  
  301.              
  302.          /* methods */             
  303.              
  304.          // login
  305.          $this->__dispatch_map['login'=
  306.             array('in' => array('username' => 'string''password' => 'string''ip' => 'string'),
  307.                   'out' => array('return' => "{urn:$this->namespace}kt_response),
  308.             );
  309.             
  310.          // logout
  311.          $this->__dispatch_map['logout'=
  312.             array('in' => array('session_id' => 'string' )
  313.              'out' => array('return' => "{urn:$this->namespace}kt_response"  ),
  314.             );
  315.            
  316.          // get_folder_detail      
  317.          $this->__dispatch_map['get_folder_detail'=
  318.             array('in' => array('session_id' => 'string''folder_id' => 'int' )
  319.              'out' => array('return' => "{urn:$this->namespace}kt_folder_detail"),
  320.             )
  321.              
  322.          // get_folder_detail_by_name
  323.          $this->__dispatch_map['get_folder_detail_by_name'=
  324.             array('in' => array('session_id' => 'string''folder_name' => 'string' )
  325.              'out' => array('return' => "{urn:$this->namespace}kt_folder_detail"),
  326.             );  
  327.             
  328.          // get_folder_contents  
  329.          $this->__dispatch_map['get_folder_contents'=
  330.             array('in' => array('session_id'=>'string','folder_id'=>'int','depth'=>'int','what'=>'string')
  331.              'out' => array('return' => "{urn:$this->namespace}kt_folder_contents"),
  332.             );             
  333.             
  334.          // create_folder
  335.          $this->__dispatch_map['create_folder'=
  336.             array('in' => array('session_id'=>'string','folder_id'=>'int','folder_name' =>'string')
  337.              'out' => array('return' => "{urn:$this->namespace}kt_folder_detail"),
  338.             );
  339.  
  340.          // delete_folder
  341.          $this->__dispatch_map['delete_folder'=
  342.             array('in' => array('session_id'=>'string','folder_id'=>'int','reason' =>'string')
  343.              'out' => array('return' => "{urn:$this->namespace}kt_response),
  344.             )
  345.  
  346.          // rename_folder    
  347.          $this->__dispatch_map['rename_folder'=
  348.             array('in' => array('session_id'=>'string','folder_id'=>'int','newname' =>'string')
  349.              'out' => array('return' => "{urn:$this->namespace}kt_response"),
  350.             );             
  351.  
  352.            
  353.             
  354.             // copy_folder
  355.          $this->__dispatch_map['copy_folder'=
  356.             array('in' => array('session_id'=>'string','source_id'=>'int','target_id'=>'int','reason' =>'string')
  357.              'out' => array('return' => "{urn:$this->namespace}kt_response"  ),
  358.             );             
  359.  
  360.          // move_folder      
  361.          $this->__dispatch_map['move_folder'=
  362.             array('in' => array('session_id'=>'string','source_id'=>'int','target_id'=>'int','reason' =>'string')
  363.              'out' => array('return' => "{urn:$this->namespace}kt_response),
  364.             );
  365.             
  366.         // get_document_detail
  367.          $this->__dispatch_map['get_document_detail'=
  368.             array('in' => array('session_id' => 'string''document_id' => 'int' )
  369.              'out' => array('return' => "{urn:$this->namespace}kt_document_detail"),
  370.             );             
  371.             
  372.           //  checkin_document
  373.          $this->__dispatch_map['checkin_document'=
  374.             array('in' => array('session_id'=>'string','document_id'=>'int','filename'=>'string','reason' =>'string','tempfilename' =>'string''major_update'=>'boolean' )
  375.              'out' => array'return' => "{urn:$this->namespace}kt_response),
  376.             );      
  377.             
  378.                  // add_document
  379.          $this->__dispatch_map['add_document'=
  380.             array('in' => array('session_id'=>'string','folder_id'=>'int','title'=>'string','filename'=>'string','documentype' =>'string','tempfilename' =>'string' )
  381.              'out' => array'return' => "{urn:$this->namespace}kt_document_detail),
  382.             );  
  383.     
  384.          // get_document_detail_by_name
  385.          $this->__dispatch_map['get_document_detail_by_name'=
  386.             array('in' => array('session_id' => 'string''document_name' => 'string''what'=>'string' )
  387.              'out' => array('return' => "{urn:$this->namespace}kt_document_detail"),
  388.             );            
  389.  
  390.           // checkout_document
  391.            $this->__dispatch_map['checkout_document'=
  392.             array('in' => array('session_id'=>'string','document_id'=>'int','reason' =>'string')
  393.              'out' => array('return' => "{urn:$this->namespace}kt_response),
  394.             );   
  395.  
  396.             // undo_document_checkout
  397.             $this->__dispatch_map['undo_document_checkout'=
  398.             array('in' => array('session_id'=>'string','document_id'=>'int','reason' =>'string')
  399.              'out' => array('return' => "{urn:$this->namespace}kt_response),
  400.             );             
  401.                 // download_document
  402.             $this->__dispatch_map['download_document'=
  403.             array('in' => array('session_id'=>'string','document_id'=>'int' )
  404.              'out' => array('return' => "{urn:$this->namespace}kt_response),
  405.             );                      
  406.             
  407.             // delete_document 
  408.             $this->__dispatch_map['delete_document'=
  409.             array('in' => array('session_id'=>'string','document_id'=>'int','reason'=>'string')
  410.              'out' => array'return' => "{urn:$this->namespace}kt_response),
  411.             );  
  412.             
  413.               
  414.             // change_document_owner
  415.             $this->__dispatch_map['change_document_owner'=
  416.             array('in' => array('session_id'=>'string','document_id'=>'int','username'=>'string','reason'=>'string')
  417.              'out' => array'return' => "{urn:$this->namespace}kt_response),
  418.             );
  419.  
  420.             // copy_document
  421.             $this->__dispatch_map['copy_document'=
  422.             array('in' => array('session_id'=>'string','document_id'=>'int','folder_id'=>'int','reason'=>'string','newtitle'=>'string','newfilename'=>'string')
  423.              'out' => array'return' => "{urn:$this->namespace}kt_response),
  424.             );
  425.             
  426.             // move_document
  427.             $this->__dispatch_map['move_document'=
  428.             array('in' => array('session_id'=>'string','document_id'=>'int','folder_id'=>'int','reason'=>'string','newtitle'=>'string','newfilename'=>'string')
  429.              'out' => array'return' => "{urn:$this->namespace}kt_response),
  430.             );
  431.             // rename_document_title
  432.             $this->__dispatch_map['rename_document_title'=
  433.             array('in' => array('session_id'=>'string','document_id'=>'int''newtitle'=>'string' )
  434.              'out' => array'return' => "{urn:$this->namespace}kt_response),
  435.             );
  436.  
  437.             // rename_document_filename
  438.             $this->__dispatch_map['rename_document_filename'=
  439.             array('in' => array('session_id'=>'string','document_id'=>'int''newfilename'=>'string' )
  440.              'out' => array'return' => "{urn:$this-><