Commit 67af63a59daf2b61d3e88644a3133dc1bbc36dfd

Authored by Conrad Vermeulen
1 parent 8b01e2d2

WSA-87

"Comparison of folders when validating upload path does not work on windows correctly"
Fixed. Refactored some functionality and made the path seperator consistent. Path was not being returned correctly in some cases.

Committed By: Conrad Vermeulen
Reviewed By: Isaac Lundal

git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@7789 c91229c3-7414-0410-bfa2-8a42b809f60b
ktwebservice/KTUploadManager.inc.php
... ... @@ -64,7 +64,7 @@ class KTUploadManager
64 64 function set_session($session)
65 65 {
66 66 $user = &$session->get_user();
67   - $this->userid=$user->getId();
  67 + $this->userid=$_SESSION['userID'];
68 68 $this->session = $session->get_session();
69 69 }
70 70  
... ... @@ -119,7 +119,7 @@ class KTUploadManager
119 119 $now=date('Y-m-d H:i:s');
120 120 $now_str=date('YmdHis');
121 121  
122   - $newtempfile = realpath($this->temp_dir) . '/' . $this->userid . '-'. $now_str;
  122 + $newtempfile = realpath($this->temp_dir) . '/' . $_SESSION['userID'] . '-'. $now_str;
123 123 if (OS_WINDOWS)
124 124 {
125 125 $tempfile = str_replace('/','\\',$tempfile);
... ... @@ -145,7 +145,15 @@ class KTUploadManager
145 145 return $id;
146 146 }
147 147 global $php_errormsg;
148   - $result = @move_uploaded_file($tempfile, $newtempfile);
  148 + if (is_uploaded_file($tempfile))
  149 + {
  150 + $result = @move_uploaded_file($tempfile, $newtempfile);
  151 + }
  152 + else
  153 + {
  154 + $result = @rename($tempfile, $newtempfile);
  155 + }
  156 +
149 157 $tmp = $php_errormsg;
150 158  
151 159 if ($result == false)
... ...
ktwebservice/webservice.php
... ... @@ -59,7 +59,18 @@ if (defined('HAS_SEARCH_FUNCTIONALITY'))
59 59 require_once(KT_DIR . '/search2/search/search.inc.php');
60 60 }
61 61  
62   -// TODO: Test getting files/metadata based on versioning works and implementation is consistent.
  62 +// TODO: allow downloading of metadata versions
  63 +// TODO: allow downloading of document versions
  64 +// TODO: chunking search results
  65 +// TODO: add basic permissions management - add permissions to folder based on user/groups
  66 +// TODO: refactor!!! download manager, split this file into a few smaller ones, etc
  67 +// TOdO: define more reason codes!
  68 +// TODO: get_folder must have a 'create' option
  69 +// TODO: redo metadata encoding
  70 +// TODO: unit tests - metadata - test return values in selectin - list/tree
  71 +// TODO: ktwsapi/php must be made compatible with v2/v3
  72 +
  73 +// NOTE: some features are not implemented yet. most expected for v3. e.g. oem_document_no, custom_document_no, download($version)., get_metadata($version)
63 74  
64 75 // Status Codes as defined in the specification.
65 76  
... ... @@ -67,16 +78,24 @@ define('KTWS_SUCCESS', 0);
67 78 define('KTWS_ERR_INVALID_SESSION', 1);
68 79 define('KTWS_ERR_AUTHENTICATION_ERROR', 2);
69 80 define('KTWS_ERR_INSUFFICIENT_PERMISSIONS', 3);
  81 +
70 82 define('KTWS_ERR_FILE_NOT_FOUND', 10);
71 83 define('KTWS_ERR_INVALID_FILENAME', 20);
  84 +
72 85 define('KTWS_ERR_INVALID_DOCUMENT', 21);
73 86 define('KTWS_ERR_INVALID_FOLDER', 22);
74 87 define('KTWS_ERR_INVALID_METADATA', 23);
75 88 define('KTWS_ERR_INVALID_REASON', 24);
76 89 define('KTWS_ERR_INVALID_DEPTH', 25);
  90 +define('KTWS_ERR_INVALID_DOCUMENT_TYPE', 26);
  91 +
77 92 define('KTWS_ERR_PROBLEM', 98);
78 93 define('KTWS_ERR_DB_PROBLEM', 99);
79 94  
  95 +if (!defined('LATEST_WEBSERVICE_VERSION'))
  96 +{
  97 + define('LATEST_WEBSERVICE_VERSION',2);
  98 +}
80 99  
81 100 function bool2str($bool)
82 101 {
... ... @@ -120,7 +139,7 @@ class KTWebService
120 139 var $version;
121 140 var $ktapi;
122 141  
123   -
  142 + static $wsclass = 'KTWebService';
124 143  
125 144 function KTWebService()
126 145 {
... ... @@ -396,7 +415,6 @@ class KTWebService
396 415 'parent_id' => 'int'
397 416 );
398 417  
399   -
400 418 $this->__typedef["{urn:$this->namespace}kt_metadata_selection"] =
401 419 array(
402 420 array(
... ... @@ -404,7 +422,6 @@ class KTWebService
404 422 )
405 423 );
406 424  
407   -
408 425 $this->__typedef["{urn:$this->namespace}kt_metadata_field"] =
409 426 array(
410 427 'name' => 'string',
... ... @@ -478,7 +495,6 @@ class KTWebService
478 495 );
479 496 }
480 497  
481   -
482 498 $this->__typedef["{urn:$this->namespace}kt_linked_document"] =
483 499 array(
484 500 'document_id'=>'int',
... ... @@ -539,7 +555,6 @@ class KTWebService
539 555 );
540 556 }
541 557  
542   -
543 558 $this->__typedef["{urn:$this->namespace}kt_document_version_history"] =
544 559 array(
545 560 array(
... ... @@ -582,7 +597,6 @@ class KTWebService
582 597 )
583 598 );
584 599  
585   -
586 600 $this->__typedef["{urn:$this->namespace}kt_client_policies_response"] =
587 601 array(
588 602 'status_code' => 'int',
... ... @@ -593,7 +607,6 @@ class KTWebService
593 607 /* methods */
594 608 if (defined('HAS_SEARCH_FUNCTIONALITY'))
595 609 {
596   -
597 610 $this->__dispatch_map['search'] = array(
598 611 'in' => array('session_id' => 'string', 'search'=>'string' ,'options'=>'string'),
599 612 'out' => array('return' => "{urn:$this->namespace}kt_search_response" ),
... ... @@ -612,7 +625,6 @@ class KTWebService
612 625 'out' => array('return' => "{urn:$this->namespace}kt_response" ),
613 626 );
614 627  
615   -
616 628 // logout
617 629 $this->__dispatch_map['logout'] =
618 630 array('in' => array('session_id' => 'string' ),
... ... @@ -625,12 +637,22 @@ class KTWebService
625 637 'out' => array('return' => "{urn:$this->namespace}kt_folder_detail"),
626 638 );
627 639  
  640 + if ($this->version >=3)
  641 + {
  642 + $this->__dispatch_map['get_folder_detail']['in'] = array('session_id' => 'string', 'folder_id' => 'int', 'create'=>'boolean' );
  643 + }
  644 +
628 645 // get_folder_detail_by_name
629 646 $this->__dispatch_map['get_folder_detail_by_name'] =
630 647 array('in' => array('session_id' => 'string', 'folder_name' => 'string' ),
631 648 'out' => array('return' => "{urn:$this->namespace}kt_folder_detail"),
632 649 );
633 650  
  651 + if ($this->version >=3)
  652 + {
  653 + $this->__dispatch_map['get_folder_detail_by_name']['in'] = array('session_id' => 'string', 'folder_id' => 'int', 'create'=>'boolean' );
  654 + }
  655 +
634 656 // get_folder_contents
635 657 $this->__dispatch_map['get_folder_contents'] =
636 658 array('in' => array('session_id'=>'string','folder_id'=>'int','depth'=>'int','what'=>'string'),
... ... @@ -653,7 +675,6 @@ class KTWebService
653 675 );
654 676 }
655 677  
656   -
657 678 // delete_folder
658 679 $this->__dispatch_map['delete_folder'] =
659 680 array('in' => array('session_id'=>'string','folder_id'=>'int','reason' =>'string'),
... ... @@ -708,7 +729,6 @@ class KTWebService
708 729 $this->__dispatch_map['get_document_detail']['in'] = array('session_id' => 'string', 'document_id' => 'int', 'detail'=>'string' );
709 730 }
710 731  
711   -
712 732 // checkin_document
713 733 $this->__dispatch_map['checkin_document'] =
714 734 array('in' => array('session_id'=>'string','document_id'=>'int','filename'=>'string','reason' =>'string','tempfilename' =>'string', 'major_update'=>'boolean' ),
... ... @@ -739,7 +759,6 @@ class KTWebService
739 759 array('in' => array('session_id'=>'string','document_id'=>'int','filename'=>'string','reason' =>'string','tempfilename' =>'string', 'major_update'=>'boolean', 'metadata'=>"{urn:$this->namespace}kt_metadata_fieldsets",'sysdata'=>"{urn:$this->namespace}kt_sysdata" ),
740 760 'out' => array( 'return' => "{urn:$this->namespace}kt_document_detail" )
741 761 );
742   -
743 762 }
744 763  
745 764 // add_document
... ... @@ -774,12 +793,8 @@ class KTWebService
774 793 array('in' => array('session_id'=>'string','folder_id'=>'int','title'=>'string','filename'=>'string','documentype' =>'string','tempfilename' =>'string', 'metadata'=>"{urn:$this->namespace}kt_metadata_fieldsets",'sysdata'=>"{urn:$this->namespace}kt_sysdata" ),
775 794 'out' => array( 'return' => "{urn:$this->namespace}kt_document_detail" )
776 795 );
777   -
778   -
779 796 }
780 797  
781   -
782   -
783 798 // get_document_detail_by_name
784 799 $this->__dispatch_map['get_document_detail_by_name'] =
785 800 array('in' => array('session_id' => 'string', 'document_name' => 'string', 'what'=>'string' ),
... ... @@ -815,7 +830,6 @@ class KTWebService
815 830 );
816 831 }
817 832  
818   -
819 833 // checkout_small_document
820 834 $this->__dispatch_map['checkout_small_document'] =
821 835 array('in' => array('session_id'=>'string','document_id'=>'int','reason' =>'string','download' => 'boolean'),
... ... @@ -827,7 +841,6 @@ class KTWebService
827 841 $this->__dispatch_map['checkout_small_document']['out'] = array('return' => "{urn:$this->namespace}kt_document_detail" );
828 842 }
829 843  
830   -
831 844 // checkout_base64_document
832 845 $this->__dispatch_map['checkout_base64_document'] =
833 846 array('in' => array('session_id'=>'string','document_id'=>'int','reason' =>'string','download' => 'boolean'),
... ... @@ -840,7 +853,6 @@ class KTWebService
840 853 $this->__dispatch_map['checkout_base64_document']['out'] = array('return' => "{urn:$this->namespace}kt_document_detail" );
841 854 }
842 855  
843   -
844 856 // undo_document_checkout
845 857 $this->__dispatch_map['undo_document_checkout'] =
846 858 array('in' => array('session_id'=>'string','document_id'=>'int','reason' =>'string'),
... ... @@ -852,8 +864,6 @@ class KTWebService
852 864 $this->__dispatch_map['undo_document_checkout']['out'] = array('return' => "{urn:$this->namespace}kt_document_detail" );
853 865 }
854 866  
855   -
856   -
857 867 // download_document
858 868 $this->__dispatch_map['download_document'] =
859 869 array('in' => array('session_id'=>'string','document_id'=>'int' ),
... ... @@ -873,13 +883,19 @@ class KTWebService
873 883 'alias' => 'download_small_document'
874 884 );
875 885  
  886 + if ($this->version >= 3)
  887 + {
  888 + $this->__dispatch_map['download_document']['in'] = array('session_id'=>'string','document_id'=>'int', 'version'=>'string' );
  889 + $this->__dispatch_map['download_small_document']['in'] = array('session_id'=>'string','document_id'=>'int', 'version'=>'string' );
  890 + $this->__dispatch_map['download_base64_document']['in'] = array('session_id'=>'string','document_id'=>'int', 'version'=>'string' );
  891 + }
  892 +
876 893 // delete_document
877 894 $this->__dispatch_map['delete_document'] =
878 895 array('in' => array('session_id'=>'string','document_id'=>'int','reason'=>'string'),
879 896 'out' => array( 'return' => "{urn:$this->namespace}kt_response" ),
880 897 );
881 898  
882   -
883 899 // change_document_owner
884 900 $this->__dispatch_map['change_document_owner'] =
885 901 array('in' => array('session_id'=>'string','document_id'=>'int','username'=>'string','reason'=>'string'),
... ... @@ -891,7 +907,6 @@ class KTWebService
891 907 $this->__dispatch_map['change_document_owner']['out'] = array( 'return' => "{urn:$this->namespace}kt_document_detail" );
892 908 }
893 909  
894   -
895 910 // copy_document
896 911 $this->__dispatch_map['copy_document'] =
897 912 array('in' => array('session_id'=>'string','document_id'=>'int','folder_id'=>'int','reason'=>'string','newtitle'=>'string','newfilename'=>'string'),
... ... @@ -931,7 +946,6 @@ class KTWebService
931 946 $this->__dispatch_map['rename_document_filename']['out'] = array( 'return' => "{urn:$this->namespace}kt_document_detail" );
932 947 }
933 948  
934   -
935 949 // change_document_type
936 950 $this->__dispatch_map['change_document_type'] =
937 951 array('in' => array('session_id'=>'string','document_id'=>'int', 'documenttype'=>'string' ),
... ... @@ -989,6 +1003,11 @@ class KTWebService
989 1003 'out' => array( 'return' => "{urn:$this->namespace}kt_metadata_response" ),
990 1004 );
991 1005  
  1006 + if ($this->version >= 3)
  1007 + {
  1008 + $this->__dispatch_map['get_document_metadata']['in'] = array('session_id'=>'string','document_id'=>'int', 'version'=>'string');
  1009 + }
  1010 +
992 1011 // get_document_type_metadata
993 1012 $this->__dispatch_map['get_document_type_metadata'] =
994 1013 array('in' => array('session_id'=>'string','document_type'=>'string' ),
... ... @@ -1007,17 +1026,14 @@ class KTWebService
1007 1026 'out' => array( 'return' => "{urn:$this->namespace}kt_document_detail" )
1008 1027 );
1009 1028  
1010   -
1011 1029 }
1012 1030  
1013   -
1014 1031 //get_document_workflow_transitions
1015 1032 $this->__dispatch_map['get_document_workflow_transitions'] =
1016 1033 array('in' => array('session_id'=>'string','document_id'=>'int' ),
1017 1034 'out' => array( 'return' => "{urn:$this->namespace}kt_workflow_transitions_response" ),
1018 1035 );
1019 1036  
1020   -
1021 1037 //get_document_workflow_state
1022 1038 $this->__dispatch_map['get_document_workflow_state'] =
1023 1039 array('in' => array('session_id'=>'string','document_id'=>'int' ),
... ... @@ -1030,7 +1046,6 @@ class KTWebService
1030 1046 'out' => array( 'return' => "{urn:$this->namespace}kt_document_transaction_history_response" ),
1031 1047 );
1032 1048  
1033   -
1034 1049 // get_document_version_history
1035 1050 $this->__dispatch_map['get_document_version_history'] =
1036 1051 array('in' => array('session_id'=>'string','document_id'=>'int' ),
... ... @@ -1058,10 +1073,18 @@ class KTWebService
1058 1073 if ($this->version >= 2)
1059 1074 {
1060 1075 $this->__dispatch_map['get_client_policies']['in'] = array('session_id'=>'string', 'client'=>'string');
1061   -
1062 1076 }
  1077 + }
1063 1078  
1064   -
  1079 + function get()
  1080 + {
  1081 + static $ws = null;
  1082 + if (is_null($ws))
  1083 + {
  1084 + $classname = KTWebService::$wsclass;
  1085 + $ws = new $classname();
  1086 + }
  1087 + return $ws;
1065 1088 }
1066 1089  
1067 1090 function debug($msg, $function = null, $level=0)
... ... @@ -1091,6 +1114,14 @@ class KTWebService
1091 1114 }
1092 1115 }
1093 1116  
  1117 + function _status($code, $message='')
  1118 + {
  1119 + if (PEAR::isError($message))
  1120 + {
  1121 + $message = $message->getMessage();
  1122 + }
  1123 + return array('status_code'=>$code, 'message'=>$message);
  1124 + }
1094 1125  
1095 1126 /**
1096 1127 * This is used by all exposed functions dependant on the sessionid.
... ... @@ -1111,12 +1142,7 @@ class KTWebService
1111 1142  
1112 1143 if ( PEAR::isError($session))
1113 1144 {
1114   - $response=array(
1115   - 'status_code'=>KTWS_ERR_INVALID_SESSION,
1116   - 'message'=>$session->getMessage()
1117   - );
1118   -
1119   - return $response;
  1145 + return KTWebService::_status(KTWS_ERR_INVALID_SESSION,$session);
1120 1146 }
1121 1147 $this->ktapi = $kt;
1122 1148 return $kt;
... ... @@ -1130,10 +1156,7 @@ class KTWebService
1130 1156 */
1131 1157 function anonymous_login($ip=null)
1132 1158 {
1133   - $response = array(
1134   - 'status_code'=>KTWS_ERR_AUTHENTICATION_ERROR,
1135   - 'message'=>'',
1136   - );
  1159 + $response = KTWebService::_status(KTWS_ERR_AUTHENTICATION_ERROR);
1137 1160  
1138 1161 $kt = new KTAPI();
1139 1162  
... ... @@ -1165,10 +1188,7 @@ class KTWebService
1165 1188 */
1166 1189 function login($username, $password, $ip=null)
1167 1190 {
1168   - $response = array(
1169   - 'status_code'=>KTWS_ERR_AUTHENTICATION_ERROR,
1170   - 'message'=>'',
1171   - );
  1191 + $response = KTWebService::_status(KTWS_ERR_AUTHENTICATION_ERROR);
1172 1192  
1173 1193 $kt = new KTAPI();
1174 1194  
... ... @@ -1205,10 +1225,7 @@ class KTWebService
1205 1225 return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $kt);
1206 1226 }
1207 1227  
1208   - $response=array(
1209   - 'status_code'=>KTWS_ERR_INVALID_SESSION,
1210   - 'message'=>''
1211   - );
  1228 + $response = KTWebService::_status(KTWS_ERR_INVALID_SESSION);
1212 1229  
1213 1230 $session = &$kt->get_session();
1214 1231 if (PEAR::isError($session))
... ... @@ -1243,10 +1260,7 @@ class KTWebService
1243 1260 $folder = &$kt->get_folder_by_id($folder_id);
1244 1261 if (PEAR::isError($folder))
1245 1262 {
1246   - $response=array(
1247   - 'status_code'=>KTWS_ERR_INVALID_FOLDER,
1248   - 'message'=>$folder->getMessage()
1249   - );
  1263 + $response = KTWebService::_status(KTWS_ERR_INVALID_FOLDER,$folder);
1250 1264 $this->debug("get_folder_detail - " . $folder->getMessage(), $session_id);
1251 1265 return new SOAP_Value('return',"{urn:$this->namespace}kt_folder_detail", $response);
1252 1266 }
... ... @@ -1277,10 +1291,7 @@ class KTWebService
1277 1291 $folder = &$kt->get_folder_by_name($folder_name);
1278 1292 if (PEAR::isError($folder))
1279 1293 {
1280   - $response=array(
1281   - 'status_code'=>KTWS_ERR_INVALID_FOLDER,
1282   - 'message'=>$folder->getMessage()
1283   - );
  1294 + $response = KTWebService::_status(KTWS_ERR_INVALID_FOLDER,$folder);
1284 1295 $this->debug("get_folder_detail_by_name - cannot get folder $folder_name - " . $folder->getMessage(), $session_id);
1285 1296 return new SOAP_Value('return',"{urn:$this->namespace}kt_folder_detail", $response);
1286 1297 }
... ... @@ -1290,48 +1301,6 @@ class KTWebService
1290 1301 $detail['message']='';
1291 1302  
1292 1303 return new SOAP_Value('return',"{urn:$this->namespace}kt_folder_detail", $detail);
1293   -
1294   - }
1295   -
1296   - /**
1297   - * Encodes an array as kt_folder_item
1298   - *
1299   - * @param array $item
1300   - * @param string $name
1301   - * @return SOAP_Value of kt_folder_item
1302   - * @access private
1303   - * @static
1304   - */
1305   - function _encode_folder_item($item, $name='item')
1306   - {
1307   - $item['id'] = (int) $item['id'];
1308   -
1309   - if (!empty($item['items']))
1310   - {
1311   - $item['items'] = KTWebService::_encode_folder_items($item['items']);
1312   - }
1313   -
1314   - return new SOAP_Value($name,"{urn:$this->namespace}kt_folder_item", $item);
1315   - }
1316   -
1317   - /**
1318   - * Encodes an array as kt_folder_items
1319   - *
1320   - * @param array $items
1321   - * @param string $name
1322   - * @return SOAP_Value of kt_folder_items
1323   - * @access private
1324   - * @static
1325   - */
1326   - function _encode_folder_items($items, $name='items')
1327   - {
1328   - $encoded=array();
1329   - foreach($items as $item)
1330   - {
1331   - $encoded[] = KTWebService::_encode_folder_item($item);
1332   - }
1333   -
1334   - return new SOAP_Value($name,"{urn:$this->namespace}kt_folder_items", $encoded);
1335 1304 }
1336 1305  
1337 1306 /**
... ... @@ -1343,12 +1312,17 @@ class KTWebService
1343 1312 * @access private
1344 1313 * @static
1345 1314 */
1346   - function _encode_folder_contents($contents, $name='return')
  1315 + function _encode_folder_items($items)
1347 1316 {
1348   - $contents['items'] = KTWebService::_encode_folder_items($contents['items']);
1349   - return new SOAP_Value($name,"{urn:$this->namespace}kt_folder_contents", $contents);
1350   - }
  1317 + foreach($items as $key=>$item)
  1318 + {
  1319 + $item['id'] = (int) $item['id'];
  1320 + $item['items'] = KTWebService::_encode_folder_items($item['items']);
1351 1321  
  1322 + $items[$key] = new SOAP_Value('item',"{urn:$this->namespace}kt_folder_item", $item);
  1323 + }
  1324 + return new SOAP_Value('items',"{urn:$this->namespace}kt_folder_items", $items);
  1325 + }
1352 1326  
1353 1327 /**
1354 1328 * Returns the contents of a folder.
... ... @@ -1371,10 +1345,8 @@ class KTWebService
1371 1345 $folder = &$kt->get_folder_by_id($folder_id);
1372 1346 if (PEAR::isError($folder))
1373 1347 {
1374   - $response=array(
1375   - 'status_code'=>KTWS_ERR_INVALID_FOLDER,
1376   - 'message'=>$folder->getMessage()
1377   - );
  1348 + $response = KTWebService::_status(KTWS_ERR_INVALID_FOLDER,$folder);
  1349 +
1378 1350 $this->debug("get_folder_contents - cannot get folderid $folder_id - " . $folder->getMessage(), $session_id);
1379 1351 return new SOAP_Value('return',"{urn:$this->namespace}kt_folder_contents", $response);
1380 1352 }
... ... @@ -1387,10 +1359,10 @@ class KTWebService
1387 1359 'folder_id' => $folder_id+0,
1388 1360 'folder_name'=>$folder->get_folder_name(),
1389 1361 'full_path'=>$folder->get_full_path(),
1390   - 'items'=>$listing
  1362 + 'items'=>KTWebService::_encode_folder_items($listing)
1391 1363 );
1392 1364  
1393   - return KTWebService::_encode_folder_contents($contents);
  1365 + return new SOAP_Value($name,"{urn:$this->namespace}kt_folder_contents", $contents);
1394 1366 }
1395 1367  
1396 1368 /**
... ... @@ -1414,10 +1386,8 @@ class KTWebService
1414 1386 $folder = &$kt->get_folder_by_id($folder_id);
1415 1387 if (PEAR::isError($folder))
1416 1388 {
1417   - $response=array(
1418   - 'status_code'=>KTWS_ERR_INVALID_FOLDER,
1419   - 'message'=>$folder->getMessage()
1420   - );
  1389 + $response = KTWebService::_status(KTWS_ERR_INVALID_FOLDER,$folder);
  1390 +
1421 1391 $this->debug("create_folder - cannot get folderid $folder_id - " . $folder->getMessage(), $session_id);
1422 1392  
1423 1393 return new SOAP_Value('return',"{urn:$this->namespace}kt_folder_detail", $response);
... ... @@ -1426,10 +1396,7 @@ class KTWebService
1426 1396 $newfolder = &$folder->add_folder($folder_name);
1427 1397 if (PEAR::isError($newfolder))
1428 1398 {
1429   - $response=array(
1430   - 'status_code'=>KTWS_ERR_INVALID_FOLDER,
1431   - 'message'=>$newfolder->getMessage()
1432   - );
  1399 + $response = KTWebService::_status(KTWS_ERR_INVALID_FOLDER,$newfolder);
1433 1400 $this->debug("create_folder - cannot create folder $folder_name - " . $folder->getMessage(), $session_id);
1434 1401  
1435 1402 return new SOAP_Value('return',"{urn:$this->namespace}kt_folder_detail", $response);
... ... @@ -1459,10 +1426,7 @@ class KTWebService
1459 1426 return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $kt);
1460 1427 }
1461 1428  
1462   - $response=array(
1463   - 'status_code'=>KTWS_ERR_INVALID_FOLDER,
1464   - 'message'=>''
1465   - );
  1429 + $response = KTWebService::_status(KTWS_ERR_INVALID_FOLDER);
1466 1430  
1467 1431 $folder = &$kt->get_folder_by_id($folder_id);
1468 1432 if (PEAR::isError($folder))
... ... @@ -1503,10 +1467,7 @@ class KTWebService
1503 1467 return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $kt);
1504 1468 }
1505 1469  
1506   - $response=array(
1507   - 'status_code'=>KTWS_ERR_INVALID_FOLDER,
1508   - 'message'=>''
1509   - );
  1470 + $response = KTWebService::_status(KTWS_ERR_INVALID_FOLDER);
1510 1471  
1511 1472 $folder = &$kt->get_folder_by_id($folder_id);
1512 1473 if (PEAR::isError($folder))
... ... @@ -1548,10 +1509,7 @@ class KTWebService
1548 1509 return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $kt);
1549 1510 }
1550 1511  
1551   - $response=array(
1552   - 'status_code'=>KTWS_ERR_INVALID_FOLDER,
1553   - 'message'=>''
1554   - );
  1512 + $response = KTWebService::_status(KTWS_ERR_INVALID_FOLDER);
1555 1513  
1556 1514 $src_folder = &$kt->get_folder_by_id($source_id);
1557 1515 if (PEAR::isError($src_folder))
... ... @@ -1603,10 +1561,7 @@ class KTWebService
1603 1561 return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $kt);
1604 1562 }
1605 1563  
1606   - $response=array(
1607   - 'status_code'=>KTWS_ERR_INVALID_FOLDER,
1608   - 'message'=>''
1609   - );
  1564 + $response = KTWebService::_status(KTWS_ERR_INVALID_FOLDER);
1610 1565  
1611 1566 $src_folder = &$kt->get_folder_by_id($source_id);
1612 1567 if (PEAR::isError($src_folder))
... ... @@ -1653,10 +1608,7 @@ class KTWebService
1653 1608 return new SOAP_Value('return',"{urn:$this->namespace}kt_document_types_response", $kt);
1654 1609 }
1655 1610  
1656   - $response=array(
1657   - 'status_code'=>KTWS_ERR_PROBLEM,
1658   - 'message'=>''
1659   - );
  1611 + $response = KTWebService::_status(KTWS_ERR_PROBLEM);
1660 1612  
1661 1613 $result = $kt->get_documenttypes();
1662 1614 if (PEAR::isError($result))
... ... @@ -1683,10 +1635,7 @@ class KTWebService
1683 1635 return new SOAP_Value('return',"{urn:$this->namespace}kt_document_types_response", $kt);
1684 1636 }
1685 1637  
1686   - $response=array(
1687   - 'status_code'=>KTWS_ERR_PROBLEM,
1688   - 'message'=>''
1689   - );
  1638 + $response = KTWebService::_status(KTWS_ERR_PROBLEM);
1690 1639  
1691 1640 $result = $kt->get_document_link_types();
1692 1641 if (PEAR::isError($result))
... ... @@ -1723,10 +1672,8 @@ class KTWebService
1723 1672 $document = $kt->get_document_by_id($document_id);
1724 1673 if (PEAR::isError($document))
1725 1674 {
1726   - $response=array(
1727   - 'status_code'=>KTWS_ERR_INVALID_DOCUMENT,
1728   - 'message'=>$document->getMessage()
1729   - );
  1675 + $response = KTWebService::_status(KTWS_ERR_INVALID_DOCUMENT,$document);
  1676 +
1730 1677 $this->debug("get_document_detail - cannot get documentid $document_id - " . $document->getMessage(), $session_id);
1731 1678  
1732 1679 return new SOAP_Value('return',"{urn:$this->namespace}kt_document_detail", $response);
... ... @@ -1837,10 +1784,9 @@ class KTWebService
1837 1784 function get_document_detail_by_name($session_id, $folder_id, $document_name, $what='T', $detail='')
1838 1785 {
1839 1786 $this->debug("get_document_detail_by_name('$session_id','$document_name','$what','$detail')");
1840   - $response=array(
1841   - 'status_code'=>KTWS_ERR_INVALID_FOLDER,
1842   - 'message'=>''
1843   - );
  1787 +
  1788 + $response = KTWebService::_status(KTWS_ERR_INVALID_FOLDER);
  1789 +
1844 1790 if (empty($document_name))
1845 1791 {
1846 1792 $response['message'] = 'Document_name is empty.';
... ... @@ -1891,8 +1837,6 @@ class KTWebService
1891 1837 return $this->get_document_detail($session_id, $document->documentid, $detail);
1892 1838 }
1893 1839  
1894   -
1895   -
1896 1840 /**
1897 1841 * Adds a document to the repository.
1898 1842 *
... ... @@ -1918,10 +1862,7 @@ class KTWebService
1918 1862 $upload_manager = new KTUploadManager();
1919 1863 if (!$upload_manager->is_valid_temporary_file($tempfilename))
1920 1864 {
1921   - $response=array(
1922   - 'status_code'=>KTWS_ERR_INVALID_DOCUMENT,
1923   - 'message'=>"Invalid temporary file: $tempfilename. Not compatible with $upload_manager->temp_dir."
1924   - );
  1865 + $response = KTWebService::_status(KTWS_ERR_INVALID_DOCUMENT,"Invalid temporary file: $tempfilename. Not compatible with $upload_manager->temp_dir.");
1925 1866  
1926 1867 $this->debug("add_document - Invalid temporary file: $tempfilename. Not compatible with $upload_manager->temp_dir.", $session_id);
1927 1868  
... ... @@ -1931,10 +1872,7 @@ class KTWebService
1931 1872 $folder = &$kt->get_folder_by_id($folder_id);
1932 1873 if (PEAR::isError($folder))
1933 1874 {
1934   - $response=array(
1935   - 'status_code'=>KTWS_ERR_INVALID_FOLDER,
1936   - 'message'=>$folder->getMessage()
1937   - );
  1875 + $response = KTWebService::_status(KTWS_ERR_INVALID_FOLDER,$folder);
1938 1876  
1939 1877 $this->debug("add_document - cannot get folder $folder_id - " . $folder->getMessage(), $session_id);
1940 1878  
... ... @@ -1944,13 +1882,8 @@ class KTWebService
1944 1882 $document = &$folder->add_document($title, $filename, $documenttype, $tempfilename);
1945 1883 if (PEAR::isError($document))
1946 1884 {
1947   - $response=array(
1948   - 'status_code'=>KTWS_ERR_INVALID_DOCUMENT,
1949   - 'message'=>$document->getMessage()
1950   - );
1951   -
  1885 + $response = KTWebService::_status(KTWS_ERR_INVALID_DOCUMENT,$document);
1952 1886 $this->debug("add_document - cannot add document - " . $document->getMessage(), $session_id);
1953   -
1954 1887 return new SOAP_Value('return',"{urn:$this->namespace}kt_document_detail", $response);
1955 1888 }
1956 1889  
... ... @@ -2029,8 +1962,6 @@ class KTWebService
2029 1962 return $update_result;
2030 1963 }
2031 1964  
2032   -
2033   -
2034 1965 /**
2035 1966 * Adds a document to the repository.
2036 1967 *
... ... @@ -2054,10 +1985,7 @@ class KTWebService
2054 1985 $folder = &$kt->get_folder_by_id($folder_id);
2055 1986 if (PEAR::isError($folder))
2056 1987 {
2057   - $response=array(
2058   - 'status_code'=>KTWS_ERR_INVALID_FOLDER,
2059   - 'message'=>$folder->getMessage()
2060   - );
  1988 + $response = KTWebService::_status(KTWS_ERR_INVALID_FOLDER,$folder);
2061 1989 $this->debug("add_small_document - cannot get folderid $folder_id - " . $folder->getMessage(), $session_id);
2062 1990 return new SOAP_Value('return',"{urn:$this->namespace}kt_document_detail", $response);
2063 1991 }
... ... @@ -2067,26 +1995,21 @@ class KTWebService
2067 1995 if (PEAR::isError($tempfilename))
2068 1996 {
2069 1997 $reason = $tempfilename->getMessage();
2070   - $response=array(
2071   - 'status_code'=>KTWS_ERR_INVALID_DOCUMENT,
2072   - 'message'=>'Cannot write to temp file: ' + $tempfilename . ". Reason: $reason"
2073   - );
  1998 + $response = KTWebService::_status(KTWS_ERR_INVALID_DOCUMENT,'Cannot write to temp file: ' + $tempfilename . ". Reason: $reason");
2074 1999 $this->debug("add_small_document - cannot write $tempfilename. Reason: $reason", $session_id);
2075 2000  
2076 2001 return new SOAP_Value('return',"{urn:$this->namespace}kt_document_detail", $response);
2077 2002 }
2078 2003  
2079 2004 // simulate the upload
2080   - $upload_manager->uploaded($filename,$tempfilename, 'A');
  2005 + $tempfilename = $upload_manager->uploaded($filename,$tempfilename, 'A');
2081 2006  
2082 2007 // add the document
2083 2008 $document = &$folder->add_document($title, $filename, $documenttype, $tempfilename);
2084 2009 if (PEAR::isError($document))
2085 2010 {
2086   - $response=array(
2087   - 'status_code'=>KTWS_ERR_INVALID_DOCUMENT,
2088   - 'message'=>$document->getMessage()
2089   - );
  2011 + $response = KTWebService::_status(KTWS_ERR_INVALID_DOCUMENT,$document);
  2012 +
2090 2013 $this->debug("add_small_document - cannot add document - " . $document->getMessage(), $session_id);
2091 2014 return new SOAP_Value('return',"{urn:$this->namespace}kt_document_detail", $response);
2092 2015 }
... ... @@ -2118,12 +2041,9 @@ class KTWebService
2118 2041 return new SOAP_Value('return',"{urn:$this->namespace}kt_document_detail", $kt);
2119 2042 }
2120 2043  
2121   - $response=array(
2122   - 'status_code'=>KTWS_ERR_INVALID_DOCUMENT,
2123   - 'message'=>'',
2124   - );
  2044 + $response = KTWebService::_status(KTWS_ERR_INVALID_DOCUMENT);
2125 2045  
2126   - // we need to add some security to ensure that people don't frig the checkin process to access restricted files.
  2046 + // we need to add some security to ensure that people don't frig the checkin process to access restricted files.
2127 2047 // possibly should change 'tempfilename' to be a hash or id of some sort if this is troublesome.
2128 2048 $upload_manager = new KTUploadManager();
2129 2049 if (!$upload_manager->is_valid_temporary_file($tempfilename))
... ... @@ -2155,9 +2075,8 @@ class KTWebService
2155 2075 return $this->get_document_detail($session_id, $document_id);
2156 2076 }
2157 2077  
2158   -
2159   - function checkin_small_document_with_metadata($session_id, $document_id, $filename, $reason, $base64, $major_update, $metadata, $sysdata)
2160   - {
  2078 + function checkin_small_document_with_metadata($session_id, $document_id, $filename, $reason, $base64, $major_update, $metadata, $sysdata)
  2079 + {
2161 2080 $add_result = $this->checkin_small_document($session_id, $document_id, $filename, $reason, $base64, $major_update);
2162 2081  
2163 2082 $status_code = $add_result->value['status_code'];
... ... @@ -2187,10 +2106,10 @@ class KTWebService
2187 2106 }
2188 2107  
2189 2108 return $update_result;
2190   - }
  2109 + }
2191 2110  
2192   - function checkin_document_with_metadata($session_id, $document_id, $filename, $reason, $tempfilename, $major_update, $metadata, $sysdata)
2193   - {
  2111 + function checkin_document_with_metadata($session_id, $document_id, $filename, $reason, $tempfilename, $major_update, $metadata, $sysdata)
  2112 + {
2194 2113 $add_result = $this->checkin_document($session_id, $document_id, $filename, $reason, $tempfilename, $major_update);
2195 2114  
2196 2115 $status_code = $add_result->value['status_code'];
... ... @@ -2220,7 +2139,7 @@ class KTWebService
2220 2139 }
2221 2140  
2222 2141 return $update_result;
2223   - }
  2142 + }
2224 2143  
2225 2144  
2226 2145 /**
... ... @@ -2243,27 +2162,21 @@ class KTWebService
2243 2162 return new SOAP_Value('return',"{urn:$this->namespace}kt_document_detail", $kt);
2244 2163 }
2245 2164  
2246   - $response=array(
2247   - 'status_code'=>KTWS_ERR_INVALID_DOCUMENT,
2248   - 'message'=>'',
2249   - );
  2165 + $response = KTWebService::_status(KTWS_ERR_INVALID_DOCUMENT);
2250 2166  
2251 2167 $upload_manager = new KTUploadManager();
2252 2168 $tempfilename = $upload_manager->store_base64_file($base64, 'su_');
2253 2169 if (PEAR::isError($tempfilename))
2254 2170 {
2255 2171 $reason = $tempfilename->getMessage();
2256   - $response=array(
2257   - 'status_code'=>KTWS_ERR_INVALID_DOCUMENT,
2258   - 'message'=>'Cannot write to temp file: ' + $tempfilename . ". Reason: $reason"
2259   - );
  2172 + $response = KTWebService::_status(KTWS_ERR_INVALID_DOCUMENT,'Cannot write to temp file: ' + $tempfilename . ". Reason: $reason");
2260 2173 $this->debug("checkin_small_document - cannot write $tempfilename. Reason: $reason", $session_id);
2261 2174  
2262 2175 return new SOAP_Value('return',"{urn:$this->namespace}kt_document_detail", $response);
2263 2176 }
2264 2177  
2265 2178 // simulate the upload
2266   - $upload_manager->uploaded($filename,$tempfilename, 'C');
  2179 + $tempfilename = $upload_manager->uploaded($filename,$tempfilename, 'C');
2267 2180  
2268 2181 $document = &$kt->get_document_by_id($document_id);
2269 2182 if (PEAR::isError($document))
... ... @@ -2302,10 +2215,7 @@ class KTWebService
2302 2215 return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $kt);
2303 2216 }
2304 2217  
2305   - $response=array(
2306   - 'status_code'=>KTWS_ERR_INVALID_DOCUMENT,
2307   - 'message'=>''
2308   - );
  2218 + $response = KTWebService::_status(KTWS_ERR_INVALID_DOCUMENT);
2309 2219  
2310 2220 $document = &$kt->get_document_by_id($document_id);
2311 2221 if (PEAR::isError($document))
... ... @@ -2367,10 +2277,7 @@ class KTWebService
2367 2277 return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $kt);
2368 2278 }
2369 2279  
2370   - $response=array(
2371   - 'status_code'=>KTWS_ERR_INVALID_DOCUMENT,
2372   - 'message'=>''
2373   - );
  2280 + $response = KTWebService::_status(KTWS_ERR_INVALID_DOCUMENT);
2374 2281  
2375 2282 $document = &$kt->get_document_by_id($document_id);
2376 2283 if (PEAR::isError($document))
... ... @@ -2441,10 +2348,7 @@ class KTWebService
2441 2348 return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $kt);
2442 2349 }
2443 2350  
2444   - $response=array(
2445   - 'status_code'=>KTWS_ERR_INVALID_DOCUMENT,
2446   - 'message'=>''
2447   - );
  2351 + $response = KTWebService::_status(KTWS_ERR_INVALID_DOCUMENT);
2448 2352  
2449 2353 $document = &$kt->get_document_by_id($document_id);
2450 2354 if (PEAR::isError($document))
... ... @@ -2482,7 +2386,7 @@ class KTWebService
2482 2386  
2483 2387 * @return kt_response. status_code can be KTWS_ERR_INVALID_SESSION, KTWS_ERR_INVALID_DOCUMENT or KTWS_SUCCESS
2484 2388 */
2485   - function download_document($session_id, $document_id)
  2389 + function download_document($session_id, $document_id, $version=null)
2486 2390 {
2487 2391 $this->debug("download_document('$session_id',$document_id)");
2488 2392  
... ... @@ -2492,10 +2396,7 @@ class KTWebService
2492 2396 return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $kt);
2493 2397 }
2494 2398  
2495   - $response=array(
2496   - 'status_code'=>KTWS_ERR_INVALID_DOCUMENT,
2497   - 'message'=>''
2498   - );
  2399 + $response = KTWebService::_status(KTWS_ERR_INVALID_DOCUMENT);
2499 2400  
2500 2401 $document = &$kt->get_document_by_id($document_id);
2501 2402 if (PEAR::isError($document))
... ... @@ -2534,7 +2435,7 @@ class KTWebService
2534 2435  
2535 2436 * @return kt_response. status_code can be KTWS_ERR_INVALID_SESSION, KTWS_ERR_INVALID_DOCUMENT or KTWS_SUCCESS
2536 2437 */
2537   - function download_small_document($session_id, $document_id)
  2438 + function download_small_document($session_id, $document_id, $version=null)
2538 2439 {
2539 2440 $this->debug("download_small_document('$session_id',$document_id)");
2540 2441  
... ... @@ -2544,10 +2445,7 @@ class KTWebService
2544 2445 return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $kt);
2545 2446 }
2546 2447  
2547   - $response=array(
2548   - 'status_code'=>KTWS_ERR_INVALID_DOCUMENT,
2549   - 'message'=>''
2550   - );
  2448 + $response = KTWebService::_status(KTWS_ERR_INVALID_DOCUMENT);
2551 2449  
2552 2450 $document = &$kt->get_document_by_id($document_id);
2553 2451 if (PEAR::isError($document))
... ... @@ -2606,10 +2504,8 @@ class KTWebService
2606 2504 {
2607 2505 return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $kt);
2608 2506 }
2609   - $response=array(
2610   - 'status_code'=>KTWS_ERR_INVALID_DOCUMENT,
2611   - 'message'=>''
2612   - );
  2507 +
  2508 + $response = KTWebService::_status(KTWS_ERR_INVALID_DOCUMENT);
2613 2509  
2614 2510 $document = &$kt->get_document_by_id($document_id);
2615 2511 if (PEAR::isError($document))
... ... @@ -2656,10 +2552,8 @@ class KTWebService
2656 2552 {
2657 2553 return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $kt);
2658 2554 }
2659   - $response=array(
2660   - 'status_code'=>KTWS_ERR_INVALID_DOCUMENT,
2661   - 'message'=>''
2662   - );
  2555 +
  2556 + $response = KTWebService::_status(KTWS_ERR_INVALID_DOCUMENT);
2663 2557  
2664 2558 $document = &$kt->get_document_by_id($document_id);
2665 2559 if (PEAR::isError($document))
... ... @@ -2673,6 +2567,7 @@ class KTWebService
2673 2567 $result = $document->change_document_type($documenttype);
2674 2568 if (PEAR::isError($result))
2675 2569 {
  2570 + $response['status_code'] = KTWS_ERR_INVALID_DOCUMENT_TYPE;
2676 2571 $response['message'] = $result->getMessage();
2677 2572 $this->debug("change_document_type - cannot change type - " . $result->getMessage(), $session_id);
2678 2573  
... ... @@ -2708,10 +2603,8 @@ class KTWebService
2708 2603 {
2709 2604 return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $kt);
2710 2605 }
2711   - $response=array(
2712   - 'status_code'=>KTWS_ERR_INVALID_DOCUMENT,
2713   - 'message'=>''
2714   - );
  2606 +
  2607 + $response = KTWebService::_status(KTWS_ERR_INVALID_DOCUMENT);
2715 2608  
2716 2609 $document = &$kt->get_document_by_id($document_id);
2717 2610 if (PEAR::isError($document))
... ... @@ -2766,10 +2659,8 @@ class KTWebService
2766 2659 {
2767 2660 return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $kt);
2768 2661 }
2769   - $response=array(
2770   - 'status_code'=>KTWS_ERR_INVALID_DOCUMENT,
2771   - 'message'=>''
2772   - );
  2662 +
  2663 + $response = KTWebService::_status(KTWS_ERR_INVALID_DOCUMENT);
2773 2664  
2774 2665 $document = &$kt->get_document_by_id($document_id);
2775 2666 if (PEAR::isError($document))
... ... @@ -2823,10 +2714,8 @@ class KTWebService
2823 2714 {
2824 2715 return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $kt);
2825 2716 }
2826   - $response=array(
2827   - 'status_code'=>KTWS_ERR_INVALID_DOCUMENT,
2828   - 'message'=>''
2829   - );
  2717 +
  2718 + $response = KTWebService::_status(KTWS_ERR_INVALID_DOCUMENT);
2830 2719  
2831 2720 $document = &$kt->get_document_by_id($document_id);
2832 2721 if (PEAR::isError($document))
... ... @@ -2876,10 +2765,8 @@ class KTWebService
2876 2765 {
2877 2766 return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $kt);
2878 2767 }
2879   - $response=array(
2880   - 'status_code'=>KTWS_ERR_INVALID_DOCUMENT,
2881   - 'message'=>''
2882   - );
  2768 +
  2769 + $response = KTWebService::_status(KTWS_ERR_INVALID_DOCUMENT);
2883 2770  
2884 2771 $document = &$kt->get_document_by_id($document_id);
2885 2772 if (PEAR::isError($document))
... ... @@ -2902,7 +2789,6 @@ class KTWebService
2902 2789 return $this->get_document_detail($session_id, $document_id);
2903 2790 }
2904 2791  
2905   -
2906 2792 return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $response);
2907 2793 }
2908 2794  
... ... @@ -2932,10 +2818,7 @@ class KTWebService
2932 2818 return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $kt);
2933 2819 }
2934 2820  
2935   - $response=array(
2936   - 'status_code'=>KTWS_ERR_INVALID_DOCUMENT,
2937   - 'message'=>''
2938   - );
  2821 + $response = KTWebService::_status(KTWS_ERR_INVALID_DOCUMENT);
2939 2822  
2940 2823 $document = &$kt->get_document_by_id($document_id);
2941 2824 if (PEAR::isError($document))
... ... @@ -2985,10 +2868,8 @@ class KTWebService
2985 2868 {
2986 2869 return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $kt);
2987 2870 }
2988   - $response=array(
2989   - 'status_code'=>KTWS_ERR_INVALID_DOCUMENT,
2990   - 'message'=>''
2991   - );
  2871 +
  2872 + $response = KTWebService::_status(KTWS_ERR_INVALID_DOCUMENT);
2992 2873  
2993 2874 $document = &$kt->get_document_by_id($document_id);
2994 2875 if (PEAR::isError($document))
... ... @@ -3035,10 +2916,8 @@ class KTWebService
3035 2916 {
3036 2917 return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $kt);
3037 2918 }
3038   - $response=array(
3039   - 'status_code'=>KTWS_ERR_INVALID_DOCUMENT,
3040   - 'message'=>''
3041   - );
  2919 +
  2920 + $response = KTWebService::_status(KTWS_ERR_INVALID_DOCUMENT);
3042 2921  
3043 2922 $document = &$kt->get_document_by_id($document_id);
3044 2923 if (PEAR::isError($document))
... ... @@ -3088,10 +2967,8 @@ class KTWebService
3088 2967 {
3089 2968 return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $kt);
3090 2969 }
3091   - $response=array(
3092   - 'status_code'=>KTWS_ERR_INVALID_DOCUMENT,
3093   - 'message'=>''
3094   - );
  2970 +
  2971 + $response = KTWebService::_status(KTWS_ERR_INVALID_DOCUMENT);
3095 2972  
3096 2973 $document = &$kt->get_document_by_id($document_id);
3097 2974 if (PEAR::isError($document))
... ... @@ -3127,9 +3004,8 @@ class KTWebService
3127 3004 * @access private
3128 3005 * @static
3129 3006 */
3130   - function _encode_metadata_fields($fields, $name='fields')
  3007 + function _encode_metadata_fields($fields)
3131 3008 {
3132   -
3133 3009 foreach($fields as $key=>$field)
3134 3010 {
3135 3011 $selection = $field['selection'];
... ... @@ -3144,17 +3020,17 @@ class KTWebService
3144 3020 {
3145 3021 $sitem['parent_id'] = (int) $sitem['parent_id'];
3146 3022 }
3147   - $selection[$skey] = new SOAP_Value($name,"{urn:$this->namespace}kt_metadata_selection_item", $sitem);
  3023 + $selection[$skey] = new SOAP_Value('item',"{urn:$this->namespace}kt_metadata_selection_item", $sitem);
3148 3024 }
3149 3025  
3150   - $field['selection'] = new SOAP_Value($name,"{urn:$this->namespace}kt_metadata_selection", $selection);
  3026 + $field['selection'] = new SOAP_Value('selection',"{urn:$this->namespace}kt_metadata_selection", $selection);
3151 3027  
3152 3028 $field['required'] = is_null($field['required'])?false:(bool) $field['required'];
3153 3029  
3154   - $fields[$key] = new SOAP_Value($name,"{urn:$this->namespace}kt_metadata_field", $field);
  3030 + $fields[$key] = new SOAP_Value('field',"{urn:$this->namespace}kt_metadata_field", $field);
3155 3031 }
3156 3032  
3157   - return new SOAP_Value($name,"{urn:$this->namespace}kt_metadata_fields", $fields);
  3033 + return new SOAP_Value('fields',"{urn:$this->namespace}kt_metadata_fields", $fields);
3158 3034 }
3159 3035  
3160 3036 /**
... ... @@ -3219,7 +3095,6 @@ class KTWebService
3219 3095 }
3220 3096  
3221 3097 return new SOAP_Value($name,"{urn:$this->namespace}kt_metadata_response", $response);
3222   -
3223 3098 }
3224 3099  
3225 3100 /**
... ... @@ -3229,7 +3104,6 @@ class KTWebService
3229 3104 * @param string $document_type
3230 3105 * @return kt_metadata_response
3231 3106 */
3232   -
3233 3107 function get_document_type_metadata($session_id, $document_type)
3234 3108 {
3235 3109 $this->debug("get_document_type_metadata('$session_id','$document_type')");
... ... @@ -3238,10 +3112,8 @@ class KTWebService
3238 3112 {
3239 3113 return new SOAP_Value('return',"{urn:$this->namespace}kt_metadata_response", $kt);
3240 3114 }
3241   - $response=array(
3242   - 'status_code'=>KTWS_ERR_INVALID_DOCUMENT,
3243   - 'message'=>''
3244   - );
  3115 +
  3116 + $response = KTWebService::_status(KTWS_ERR_INVALID_DOCUMENT);
3245 3117  
3246 3118 $metadata = $kt->get_document_type_metadata($document_type);
3247 3119 if (PEAR::isError($metadata))
... ... @@ -3298,10 +3170,8 @@ class KTWebService
3298 3170 {
3299 3171 return new SOAP_Value('return',"{urn:$this->namespace}kt_metadata_response", $kt);
3300 3172 }
3301   - $response=array(
3302   - 'status_code'=>KTWS_ERR_INVALID_DOCUMENT,
3303   - 'message'=>''
3304   - );
  3173 +
  3174 + $response = KTWebService::_status(KTWS_ERR_INVALID_DOCUMENT);
3305 3175  
3306 3176 $document = &$kt->get_document_by_id($document_id);
3307 3177 if (PEAR::isError($document))
... ... @@ -3366,10 +3236,8 @@ class KTWebService
3366 3236 {
3367 3237 return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $kt);
3368 3238 }
3369   - $response=array(
3370   - 'status_code'=>KTWS_ERR_INVALID_DOCUMENT,
3371   - 'message'=>''
3372   - );
  3239 +
  3240 + $response = KTWebService::_status(KTWS_ERR_INVALID_DOCUMENT);
3373 3241  
3374 3242 $document = &$kt->get_document_by_id($document_id);
3375 3243 if (PEAR::isError($document))
... ... @@ -3387,7 +3255,6 @@ class KTWebService
3387 3255 return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $response);
3388 3256 }
3389 3257  
3390   -
3391 3258 if ($this->version >= 2)
3392 3259 {
3393 3260 $result = $document->update_sysdata($sysdata);
... ... @@ -3398,13 +3265,11 @@ class KTWebService
3398 3265 return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $response);
3399 3266 }
3400 3267  
3401   -
3402 3268 return $this->get_document_detail($session_id, $document_id, 'M');
3403 3269 }
3404 3270 $response['status_code'] = KTWS_SUCCESS;
3405 3271  
3406 3272 return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $response);
3407   -
3408 3273 }
3409 3274  
3410 3275 /**
... ... @@ -3422,10 +3287,7 @@ class KTWebService
3422 3287 {
3423 3288 return new SOAP_Value('return',"{urn:$this->namespace}kt_workflow_transitions_response", $kt);
3424 3289 }
3425   - $response=array(
3426   - 'status_code'=>KTWS_ERR_INVALID_DOCUMENT,
3427   - 'message'=>''
3428   - );
  3290 + $response = KTWebService::_status(KTWS_ERR_INVALID_DOCUMENT);
3429 3291  
3430 3292 $document = &$kt->get_document_by_id($document_id);
3431 3293 if (PEAR::isError($document))
... ... @@ -3471,10 +3333,7 @@ class KTWebService
3471 3333 {
3472 3334 return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $kt);
3473 3335 }
3474   - $response=array(
3475   - 'status_code'=>KTWS_ERR_INVALID_DOCUMENT,
3476   - 'message'=>''
3477   - );
  3336 + $response = KTWebService::_status(KTWS_ERR_INVALID_DOCUMENT);
3478 3337  
3479 3338 $document = &$kt->get_document_by_id($document_id);
3480 3339 if (PEAR::isError($document))
... ... @@ -3514,7 +3373,6 @@ class KTWebService
3514 3373 {
3515 3374 $history[$key] = new SOAP_Value('item',"{urn:$this->namespace}kt_document_transaction_history_item", $item);
3516 3375 }
3517   -
3518 3376 return new SOAP_Value($name,"{urn:$this->namespace}kt_document_transaction_history", $history);
3519 3377 }
3520 3378  
... ... @@ -3533,10 +3391,7 @@ class KTWebService
3533 3391 {
3534 3392 return new SOAP_Value('return',"{urn:$this->namespace}kt_document_transaction_history_response", $kt);
3535 3393 }
3536   - $response=array(
3537   - 'status_code'=>KTWS_ERR_INVALID_DOCUMENT,
3538   - 'message'=>''
3539   - );
  3394 + $response = KTWebService::_status(KTWS_ERR_INVALID_DOCUMENT);
3540 3395  
3541 3396 $document = &$kt->get_document_by_id($document_id);
3542 3397 if (PEAR::isError($document))
... ... @@ -3576,7 +3431,6 @@ class KTWebService
3576 3431 {
3577 3432 $history[$key] = new SOAP_Value('item',"{urn:$this->namespace}kt_document_version_history_item", $item);
3578 3433 }
3579   -
3580 3434 return new SOAP_Value($name,"{urn:$this->namespace}kt_document_version_history", $history);
3581 3435 }
3582 3436  
... ... @@ -3596,10 +3450,7 @@ class KTWebService
3596 3450 {
3597 3451 return new SOAP_Value('return',"{urn:$this->namespace}kt_document_version_history_response", $kt);
3598 3452 }
3599   - $response=array(
3600   - 'status_code'=>KTWS_ERR_INVALID_DOCUMENT,
3601   - 'message'=>''
3602   - );
  3453 + $response = KTWebService::_status(KTWS_ERR_INVALID_DOCUMENT);
3603 3454  
3604 3455 $document = &$kt->get_document_by_id($document_id);
3605 3456 if (PEAR::isError($document))
... ... @@ -3624,7 +3475,6 @@ class KTWebService
3624 3475 return new SOAP_Value('return',"{urn:$this->namespace}kt_document_version_history_response", $response);
3625 3476 }
3626 3477  
3627   -
3628 3478 /**
3629 3479 * Returns a list of linked documents
3630 3480 *
... ... @@ -3678,7 +3528,6 @@ class KTWebService
3678 3528 return new SOAP_Value($name,"{urn:$this->namespace}kt_linked_documents", $links);
3679 3529 }
3680 3530  
3681   -
3682 3531 /**
3683 3532 * Removes a link between documents
3684 3533 *
... ... @@ -3696,10 +3545,7 @@ class KTWebService
3696 3545 {
3697 3546 return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $kt);
3698 3547 }
3699   - $response=array(
3700   - 'status_code'=>KTWS_ERR_INVALID_DOCUMENT,
3701   - 'message'=>''
3702   - );
  3548 + $response = KTWebService::_status(KTWS_ERR_INVALID_DOCUMENT);
3703 3549  
3704 3550 $document = &$kt->get_document_by_id($parent_document_id);
3705 3551 if (PEAR::isError($document))
... ... @@ -3748,10 +3594,7 @@ class KTWebService
3748 3594 {
3749 3595 return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $kt);
3750 3596 }
3751   - $response=array(
3752   - 'status_code'=>KTWS_ERR_INVALID_DOCUMENT,
3753   - 'message'=>''
3754   - );
  3597 + $response = KTWebService::_status(KTWS_ERR_INVALID_DOCUMENT);
3755 3598  
3756 3599 $document = &$kt->get_document_by_id($parent_document_id);
3757 3600 if (PEAR::isError($document))
... ... @@ -3846,7 +3689,6 @@ class KTWebService
3846 3689 ),
3847 3690 );
3848 3691  
3849   -
3850 3692 $response['policies'] = $this->_encode_client_policies($policies);
3851 3693 $response['message'] = 'Knowledgetree client policies retrieval succeeded.';
3852 3694 $response['status_code'] = KTWS_SUCCESS;
... ... @@ -3871,11 +3713,9 @@ class KTWebService
3871 3713 {
3872 3714 return new SOAP_Value('return',"{urn:$this->namespace}kt_search_response", $kt);
3873 3715 }
3874   - $response=array(
3875   - 'status_code'=>KTWS_ERR_PROBLEM,
3876   - 'message'=>'',
3877   - 'hits'=>array()
3878   - );
  3716 +
  3717 + $response = KTWebService::_status(KTWS_ERR_PROBLEM);
  3718 + $response['hits'] = array();
3879 3719  
3880 3720 if (!defined('HAS_SEARCH_FUNCTIONALITY'))
3881 3721 {
... ... @@ -3904,7 +3744,6 @@ class KTWebService
3904 3744 return new SOAP_Value('return',"{urn:$this->namespace}kt_search_response", $response);
3905 3745 }
3906 3746  
3907   -
3908 3747 /**
3909 3748 * The main json request processing function.
3910 3749 *
... ... @@ -4066,7 +3905,7 @@ class KTWebService
4066 3905  
4067 3906 }
4068 3907  
4069   -$webservice = new KTWebService();
  3908 +$webservice = KTWebService::get();
4070 3909 $webservice->run();
4071 3910  
4072 3911 ?>
4073 3912 \ No newline at end of file
... ...