Commit bb890f2e60a98b0f5e16ac51f3f65218a41c6002
1 parent
69c63082
"KTS-1994"
"KT webservice: add_document not working" Updated. Added new functions to cater for base64 encoding. Also added missing dependency. Reviewed By: Kevin Fourie git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@6660 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
330 additions
and
9 deletions
ktwebservice/webservice.php
| @@ -36,6 +36,8 @@ require_once('../ktapi/ktapi.inc.php'); | @@ -36,6 +36,8 @@ require_once('../ktapi/ktapi.inc.php'); | ||
| 36 | require_once('SOAP/Server.php'); | 36 | require_once('SOAP/Server.php'); |
| 37 | require_once('SOAP/Disco.php'); | 37 | require_once('SOAP/Disco.php'); |
| 38 | require_once('KTDownloadManager.inc.php'); | 38 | require_once('KTDownloadManager.inc.php'); |
| 39 | +require_once('KTUploadManager.inc.php'); | ||
| 40 | +require_once(KT_LIB_DIR . '/storage/storagemanager.inc.php'); | ||
| 39 | 41 | ||
| 40 | // TODO: Test getting files/metadata based on versioning works and implementation is consistent. | 42 | // TODO: Test getting files/metadata based on versioning works and implementation is consistent. |
| 41 | 43 | ||
| @@ -369,12 +371,25 @@ class KTWebService | @@ -369,12 +371,25 @@ class KTWebService | ||
| 369 | array('in' => array('session_id'=>'string','document_id'=>'int','filename'=>'string','reason' =>'string','tempfilename' =>'string', 'major_update'=>'boolean' ), | 371 | array('in' => array('session_id'=>'string','document_id'=>'int','filename'=>'string','reason' =>'string','tempfilename' =>'string', 'major_update'=>'boolean' ), |
| 370 | 'out' => array( 'return' => "{urn:$this->namespace}kt_response" ), | 372 | 'out' => array( 'return' => "{urn:$this->namespace}kt_response" ), |
| 371 | ); | 373 | ); |
| 374 | + | ||
| 375 | + // checkin_small_document | ||
| 376 | + $this->__dispatch_map['checkin_small_document'] = | ||
| 377 | + array('in' => array('session_id'=>'string','document_id'=>'int','filename'=>'string','reason' =>'string','base64' =>'string', 'major_update'=>'boolean' ), | ||
| 378 | + 'out' => array( 'return' => "{urn:$this->namespace}kt_response" ), | ||
| 379 | + ); | ||
| 380 | + | ||
| 372 | 381 | ||
| 373 | - // add_document | 382 | + // add_document |
| 374 | $this->__dispatch_map['add_document'] = | 383 | $this->__dispatch_map['add_document'] = |
| 375 | array('in' => array('session_id'=>'string','folder_id'=>'int','title'=>'string','filename'=>'string','documentype' =>'string','tempfilename' =>'string' ), | 384 | array('in' => array('session_id'=>'string','folder_id'=>'int','title'=>'string','filename'=>'string','documentype' =>'string','tempfilename' =>'string' ), |
| 376 | 'out' => array( 'return' => "{urn:$this->namespace}kt_document_detail" ), | 385 | 'out' => array( 'return' => "{urn:$this->namespace}kt_document_detail" ), |
| 377 | ); | 386 | ); |
| 387 | + | ||
| 388 | + // add_small_document | ||
| 389 | + $this->__dispatch_map['add_small_document'] = | ||
| 390 | + array('in' => array('session_id'=>'string','folder_id'=>'int','title'=>'string','filename'=>'string','documentype' =>'string','base64' =>'string' ), | ||
| 391 | + 'out' => array( 'return' => "{urn:$this->namespace}kt_document_detail" ), | ||
| 392 | + ); | ||
| 378 | 393 | ||
| 379 | // get_document_detail_by_name | 394 | // get_document_detail_by_name |
| 380 | $this->__dispatch_map['get_document_detail_by_name'] = | 395 | $this->__dispatch_map['get_document_detail_by_name'] = |
| @@ -388,18 +403,33 @@ class KTWebService | @@ -388,18 +403,33 @@ class KTWebService | ||
| 388 | 'out' => array('return' => "{urn:$this->namespace}kt_response" ), | 403 | 'out' => array('return' => "{urn:$this->namespace}kt_response" ), |
| 389 | ); | 404 | ); |
| 390 | 405 | ||
| 406 | + // checkout_small_document | ||
| 407 | + $this->__dispatch_map['checkout_small_document'] = | ||
| 408 | + array('in' => array('session_id'=>'string','document_id'=>'int','reason' =>'string','download' => 'boolean'), | ||
| 409 | + 'out' => array('return' => "{urn:$this->namespace}kt_response" ), | ||
| 410 | + ); | ||
| 411 | + | ||
| 412 | + | ||
| 391 | // undo_document_checkout | 413 | // undo_document_checkout |
| 392 | $this->__dispatch_map['undo_document_checkout'] = | 414 | $this->__dispatch_map['undo_document_checkout'] = |
| 393 | array('in' => array('session_id'=>'string','document_id'=>'int','reason' =>'string'), | 415 | array('in' => array('session_id'=>'string','document_id'=>'int','reason' =>'string'), |
| 394 | 'out' => array('return' => "{urn:$this->namespace}kt_response" ), | 416 | 'out' => array('return' => "{urn:$this->namespace}kt_response" ), |
| 395 | ); | 417 | ); |
| 396 | - // download_document | 418 | + |
| 419 | + // download_document | ||
| 397 | $this->__dispatch_map['download_document'] = | 420 | $this->__dispatch_map['download_document'] = |
| 398 | array('in' => array('session_id'=>'string','document_id'=>'int' ), | 421 | array('in' => array('session_id'=>'string','document_id'=>'int' ), |
| 399 | 'out' => array('return' => "{urn:$this->namespace}kt_response" ), | 422 | 'out' => array('return' => "{urn:$this->namespace}kt_response" ), |
| 400 | ); | 423 | ); |
| 401 | 424 | ||
| 402 | - // delete_document | 425 | + // download_small_document |
| 426 | + $this->__dispatch_map['download_small_document'] = | ||
| 427 | + array('in' => array('session_id'=>'string','document_id'=>'int' ), | ||
| 428 | + 'out' => array('return' => "{urn:$this->namespace}kt_response" ), | ||
| 429 | + ); | ||
| 430 | + | ||
| 431 | + | ||
| 432 | + // delete_document | ||
| 403 | $this->__dispatch_map['delete_document'] = | 433 | $this->__dispatch_map['delete_document'] = |
| 404 | array('in' => array('session_id'=>'string','document_id'=>'int','reason'=>'string'), | 434 | array('in' => array('session_id'=>'string','document_id'=>'int','reason'=>'string'), |
| 405 | 'out' => array( 'return' => "{urn:$this->namespace}kt_response" ), | 435 | 'out' => array( 'return' => "{urn:$this->namespace}kt_response" ), |
| @@ -1162,7 +1192,7 @@ class KTWebService | @@ -1162,7 +1192,7 @@ class KTWebService | ||
| 1162 | // we need to add some security to ensure that people don't frig the checkin process to access restricted files. | 1192 | // we need to add some security to ensure that people don't frig the checkin process to access restricted files. |
| 1163 | // possibly should change 'tempfilename' to be a hash or id of some sort if this is troublesome. | 1193 | // possibly should change 'tempfilename' to be a hash or id of some sort if this is troublesome. |
| 1164 | $upload_manager = new KTUploadManager(); | 1194 | $upload_manager = new KTUploadManager(); |
| 1165 | - if (substr($tempfilename,0,length($upload_manager->temp_dir)) != $upload_manager->temp_dir) | 1195 | + if (substr($tempfilename,0,strlen($upload_manager->temp_dir)) != $upload_manager->temp_dir) |
| 1166 | { | 1196 | { |
| 1167 | $response=array( | 1197 | $response=array( |
| 1168 | 'status_code'=>KTWS_ERR_INVALID_FOLDER, | 1198 | 'status_code'=>KTWS_ERR_INVALID_FOLDER, |
| @@ -1196,7 +1226,96 @@ class KTWebService | @@ -1196,7 +1226,96 @@ class KTWebService | ||
| 1196 | $detail['message'] = ''; | 1226 | $detail['message'] = ''; |
| 1197 | 1227 | ||
| 1198 | return new SOAP_Value('return',"{urn:$this->namespace}kt_document_detail", $detail); | 1228 | return new SOAP_Value('return',"{urn:$this->namespace}kt_document_detail", $detail); |
| 1199 | - } | 1229 | + } |
| 1230 | + | ||
| 1231 | + /** | ||
| 1232 | + * Adds a document to the repository. | ||
| 1233 | + * | ||
| 1234 | + * @param string $session_id | ||
| 1235 | + * @param int $folder_id | ||
| 1236 | + * @param string $title | ||
| 1237 | + * @param string $filename | ||
| 1238 | + * @param string $documenttype | ||
| 1239 | + * @param string $base64 | ||
| 1240 | + * @return kt_document_detail. status_code can be KTWS_ERR_INVALID_SESSION, KTWS_ERR_INVALID_FOLDER, KTWS_ERR_INVALID_DOCUMENT or KTWS_SUCCESS | ||
| 1241 | + */ | ||
| 1242 | + function add_small_document($session_id, $folder_id, $title, $filename, $documenttype, $base64) | ||
| 1243 | + { | ||
| 1244 | + $kt = &$this->get_ktapi($session_id ); | ||
| 1245 | + if (is_array($kt)) | ||
| 1246 | + { | ||
| 1247 | + return new SOAP_Value('return',"{urn:$this->namespace}kt_document_detail", $kt); | ||
| 1248 | + } | ||
| 1249 | + | ||
| 1250 | + // create a temporary file | ||
| 1251 | + $oConfig = KTConfig::getSingleton(); | ||
| 1252 | + $tmp_dir = $oConfig->get('webservice/uploadDirectory'); | ||
| 1253 | + | ||
| 1254 | + $tempfilename = tempnam($tmp_dir,'sa_'); | ||
| 1255 | + if (!is_writable($tempfilename)) | ||
| 1256 | + { | ||
| 1257 | + $response=array( | ||
| 1258 | + 'status_code'=>KTWS_ERR_INVALID_FOLDER, | ||
| 1259 | + 'message'=>'Cannot write to temp folder: ' + $tempfilename | ||
| 1260 | + ); | ||
| 1261 | + return new SOAP_Value('return',"{urn:$this->namespace}kt_document_detail", $response); | ||
| 1262 | + } | ||
| 1263 | + | ||
| 1264 | + // we need to add some security to ensure that people don't frig the checkin process to access restricted files. | ||
| 1265 | + // possibly should change 'tempfilename' to be a hash or id of some sort if this is troublesome. | ||
| 1266 | + $upload_manager = new KTUploadManager(); | ||
| 1267 | + if ( substr($tempfilename,0,strlen($upload_manager->temp_dir)) != $upload_manager->temp_dir) | ||
| 1268 | + { | ||
| 1269 | + $response=array( | ||
| 1270 | + 'status_code'=>KTWS_ERR_INVALID_FOLDER, | ||
| 1271 | + 'message'=>'Invalid temporary file.' | ||
| 1272 | + ); | ||
| 1273 | + return new SOAP_Value('return',"{urn:$this->namespace}kt_document_detail", $response); | ||
| 1274 | + } | ||
| 1275 | + | ||
| 1276 | + $folder = &$kt->get_folder_by_id($folder_id); | ||
| 1277 | + if (PEAR::isError($folder)) | ||
| 1278 | + { | ||
| 1279 | + $response=array( | ||
| 1280 | + 'status_code'=>KTWS_ERR_INVALID_FOLDER, | ||
| 1281 | + 'message'=>$folder->getMessage() | ||
| 1282 | + ); | ||
| 1283 | + return new SOAP_Value('return',"{urn:$this->namespace}kt_document_detail", $response); | ||
| 1284 | + } | ||
| 1285 | + | ||
| 1286 | + // write to the temporary file | ||
| 1287 | + $fp=fopen($tempfilename, 'wt'); | ||
| 1288 | + if ($fp === false) | ||
| 1289 | + { | ||
| 1290 | + $response=array( | ||
| 1291 | + 'status_code'=>KTWS_ERR_INVALID_DOCUMENT, | ||
| 1292 | + 'message'=>'Cannot write to temp file: ' + $tempfilename | ||
| 1293 | + ); | ||
| 1294 | + return new SOAP_Value('return',"{urn:$this->namespace}kt_document_detail", $response); | ||
| 1295 | + } | ||
| 1296 | + fwrite($fp, base64_decode($base64)); | ||
| 1297 | + fclose($fp); | ||
| 1298 | + | ||
| 1299 | + // simulate the upload | ||
| 1300 | + $upload_manager->uploaded($filename,$tempfilename, 'A'); | ||
| 1301 | + | ||
| 1302 | + // add the document | ||
| 1303 | + $document = &$folder->add_document($title, $filename, $documenttype, $tempfilename); | ||
| 1304 | + if (PEAR::isError($document)) | ||
| 1305 | + { | ||
| 1306 | + $response=array( | ||
| 1307 | + 'status_code'=>KTWS_ERR_INVALID_DOCUMENT, | ||
| 1308 | + 'message'=>$document->getMessage() | ||
| 1309 | + ); | ||
| 1310 | + return new SOAP_Value('return',"{urn:$this->namespace}kt_document_detail", $response); | ||
| 1311 | + } | ||
| 1312 | + | ||
| 1313 | + $detail = $document->get_detail(); | ||
| 1314 | + $detail['status_code'] = KTWS_SUCCESS; | ||
| 1315 | + $detail['message'] = ''; | ||
| 1316 | + | ||
| 1317 | + return new SOAP_Value('return',"{urn:$this->namespace}kt_document_detail", $detail); | ||
| 1318 | + } | ||
| 1200 | 1319 | ||
| 1201 | /** | 1320 | /** |
| 1202 | * Does a document checkin. | 1321 | * Does a document checkin. |
| @@ -1225,7 +1344,7 @@ class KTWebService | @@ -1225,7 +1344,7 @@ class KTWebService | ||
| 1225 | // we need to add some security to ensure that people don't frig the checkin process to access restricted files. | 1344 | // we need to add some security to ensure that people don't frig the checkin process to access restricted files. |
| 1226 | // possibly should change 'tempfilename' to be a hash or id of some sort if this is troublesome. | 1345 | // possibly should change 'tempfilename' to be a hash or id of some sort if this is troublesome. |
| 1227 | $upload_manager = new KTUploadManager(); | 1346 | $upload_manager = new KTUploadManager(); |
| 1228 | - if (substr($tempfilename,0,length($upload_manager->temp_dir)) != $upload_manager->temp_dir) | 1347 | + if (substr($tempfilename,0,strlen($upload_manager->temp_dir)) != $upload_manager->temp_dir) |
| 1229 | { | 1348 | { |
| 1230 | $response['message'] = 'Invalid temporary file'; | 1349 | $response['message'] = 'Invalid temporary file'; |
| 1231 | return new SOAP_Value('return',"{urn:$this->namespace}kt_document_detail", $response); | 1350 | return new SOAP_Value('return',"{urn:$this->namespace}kt_document_detail", $response); |
| @@ -1238,6 +1357,7 @@ class KTWebService | @@ -1238,6 +1357,7 @@ class KTWebService | ||
| 1238 | return new SOAP_Value('return',"{urn:$this->namespace}kt_document_detail", $response); | 1357 | return new SOAP_Value('return',"{urn:$this->namespace}kt_document_detail", $response); |
| 1239 | } | 1358 | } |
| 1240 | 1359 | ||
| 1360 | + // checkin | ||
| 1241 | $result = $document->checkin($filename, $reason, $tempfilename, $major_update); | 1361 | $result = $document->checkin($filename, $reason, $tempfilename, $major_update); |
| 1242 | if (PEAR::isError($result)) | 1362 | if (PEAR::isError($result)) |
| 1243 | { | 1363 | { |
| @@ -1248,7 +1368,89 @@ class KTWebService | @@ -1248,7 +1368,89 @@ class KTWebService | ||
| 1248 | $response['status_code'] = KTWS_SUCCESS; | 1368 | $response['status_code'] = KTWS_SUCCESS; |
| 1249 | 1369 | ||
| 1250 | return new SOAP_Value('return',"{urn:$this->namespace}kt_document_detail", $response); | 1370 | return new SOAP_Value('return',"{urn:$this->namespace}kt_document_detail", $response); |
| 1251 | - } | 1371 | + } |
| 1372 | + | ||
| 1373 | + /** | ||
| 1374 | + * Does a document checkin. | ||
| 1375 | + * | ||
| 1376 | + * @param string $session_id | ||
| 1377 | + * @param int $document_id | ||
| 1378 | + * @param string $filename | ||
| 1379 | + * @param string $reason | ||
| 1380 | + * @param string $base64 | ||
| 1381 | + * @param boolean $major_update | ||
| 1382 | + * @return kt_document_detail. status_code can be KTWS_ERR_INVALID_SESSION, KTWS_ERR_INVALID_FOLDER, KTWS_ERR_INVALID_DOCUMENT or KTWS_SUCCESS | ||
| 1383 | + */ | ||
| 1384 | + function checkin_small_document($session_id, $document_id, $filename, $reason, $base64, $major_update ) | ||
| 1385 | + { | ||
| 1386 | + $kt = &$this->get_ktapi($session_id ); | ||
| 1387 | + if (is_array($kt)) | ||
| 1388 | + { | ||
| 1389 | + return new SOAP_Value('return',"{urn:$this->namespace}kt_document_detail", $kt); | ||
| 1390 | + } | ||
| 1391 | + | ||
| 1392 | + $response=array( | ||
| 1393 | + 'status_code'=>KTWS_ERR_INVALID_DOCUMENT, | ||
| 1394 | + 'message'=>'', | ||
| 1395 | + ); | ||
| 1396 | + | ||
| 1397 | + // create a temporary file | ||
| 1398 | + $oConfig = KTConfig::getSingleton(); | ||
| 1399 | + $tmp_dir = $oConfig->get('webservice/uploadDirectory'); | ||
| 1400 | + | ||
| 1401 | + $tempfilename = tempnam($tmp_dir,'su_'); | ||
| 1402 | + if (!is_writable($tempfilename)) | ||
| 1403 | + { | ||
| 1404 | + $response=array( | ||
| 1405 | + 'status_code'=>KTWS_ERR_INVALID_FOLDER, | ||
| 1406 | + 'message'=>'Cannot write to temp folder: ' + $tempfilename | ||
| 1407 | + ); | ||
| 1408 | + return new SOAP_Value('return',"{urn:$this->namespace}kt_document_detail", $response); | ||
| 1409 | + } | ||
| 1410 | + | ||
| 1411 | + // we need to add some security to ensure that people don't frig the checkin process to access restricted files. | ||
| 1412 | + // possibly should change 'tempfilename' to be a hash or id of some sort if this is troublesome. | ||
| 1413 | + $upload_manager = new KTUploadManager(); | ||
| 1414 | + if (substr($tempfilename,0,strlen($upload_manager->temp_dir)) != $upload_manager->temp_dir) | ||
| 1415 | + { | ||
| 1416 | + $response['message'] = 'Invalid temporary file'; | ||
| 1417 | + return new SOAP_Value('return',"{urn:$this->namespace}kt_document_detail", $response); | ||
| 1418 | + } | ||
| 1419 | + | ||
| 1420 | + // write to the temporary file | ||
| 1421 | + $fp=fopen($tempfilename, 'wt'); | ||
| 1422 | + if ($fp === false) | ||
| 1423 | + { | ||
| 1424 | + $response=array( | ||
| 1425 | + 'status_code'=>KTWS_ERR_INVALID_DOCUMENT, | ||
| 1426 | + 'message'=>'Cannot write to temp file: ' + $tempfilename | ||
| 1427 | + ); | ||
| 1428 | + return new SOAP_Value('return',"{urn:$this->namespace}kt_document_detail", $response); | ||
| 1429 | + } | ||
| 1430 | + fwrite($fp, base64_decode($base64)); | ||
| 1431 | + fclose($fp); | ||
| 1432 | + | ||
| 1433 | + // simulate the upload | ||
| 1434 | + $upload_manager->uploaded($filename,$tempfilename, 'C'); | ||
| 1435 | + | ||
| 1436 | + $document = &$kt->get_document_by_id($document_id); | ||
| 1437 | + if (PEAR::isError($document)) | ||
| 1438 | + { | ||
| 1439 | + $response['message'] = $document->getMessage(); | ||
| 1440 | + return new SOAP_Value('return',"{urn:$this->namespace}kt_document_detail", $response); | ||
| 1441 | + } | ||
| 1442 | + | ||
| 1443 | + $result = $document->checkin($filename, $reason, $tempfilename, $major_update); | ||
| 1444 | + if (PEAR::isError($result)) | ||
| 1445 | + { | ||
| 1446 | + $response['message'] = $result->getMessage(); | ||
| 1447 | + return new SOAP_Value('return',"{urn:$this->namespace}kt_document_detail", $response); | ||
| 1448 | + } | ||
| 1449 | + | ||
| 1450 | + $response['status_code'] = KTWS_SUCCESS; | ||
| 1451 | + | ||
| 1452 | + return new SOAP_Value('return',"{urn:$this->namespace}kt_document_detail", $response); | ||
| 1453 | + } | ||
| 1252 | 1454 | ||
| 1253 | /** | 1455 | /** |
| 1254 | * Does a document checkout. | 1456 | * Does a document checkout. |
| @@ -1290,8 +1492,7 @@ class KTWebService | @@ -1290,8 +1492,7 @@ class KTWebService | ||
| 1290 | $download_manager = new KTDownloadManager(); | 1492 | $download_manager = new KTDownloadManager(); |
| 1291 | $download_manager->set_session($session->session); | 1493 | $download_manager->set_session($session->session); |
| 1292 | $download_manager->cleanup(); | 1494 | $download_manager->cleanup(); |
| 1293 | - $url = $download_manager->allow_download($document); | ||
| 1294 | - | 1495 | + $url = $download_manager->allow_download($document); |
| 1295 | 1496 | ||
| 1296 | $response['status_code'] = KTWS_SUCCESS; | 1497 | $response['status_code'] = KTWS_SUCCESS; |
| 1297 | $response['message'] = $url; | 1498 | $response['message'] = $url; |
| @@ -1300,6 +1501,67 @@ class KTWebService | @@ -1300,6 +1501,67 @@ class KTWebService | ||
| 1300 | } | 1501 | } |
| 1301 | 1502 | ||
| 1302 | /** | 1503 | /** |
| 1504 | + * Does a document checkout. | ||
| 1505 | + * | ||
| 1506 | + * @param string $session_id | ||
| 1507 | + * @param int $document_id | ||
| 1508 | + * @param string $reason | ||
| 1509 | + * @param boolean $download | ||
| 1510 | + * @return kt_response status_code can be KTWS_ERR_INVALID_SESSION, KTWS_ERR_INVALID_FOLDER or KTWS_SUCCESS | ||
| 1511 | + */ | ||
| 1512 | + function checkout_small_document($session_id, $document_id, $reason, $download) | ||
| 1513 | + { | ||
| 1514 | + $kt = &$this->get_ktapi($session_id ); | ||
| 1515 | + if (is_array($kt)) | ||
| 1516 | + { | ||
| 1517 | + return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $kt); | ||
| 1518 | + } | ||
| 1519 | + | ||
| 1520 | + $response=array( | ||
| 1521 | + 'status_code'=>KTWS_ERR_INVALID_DOCUMENT, | ||
| 1522 | + 'message'=>'' | ||
| 1523 | + ); | ||
| 1524 | + | ||
| 1525 | + $document = &$kt->get_document_by_id($document_id); | ||
| 1526 | + if (PEAR::isError($document)) | ||
| 1527 | + { | ||
| 1528 | + $response['message'] = $document->getMessage(); | ||
| 1529 | + return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response); | ||
| 1530 | + } | ||
| 1531 | + | ||
| 1532 | + $result = $document->checkout($reason); | ||
| 1533 | + if (PEAR::isError($result)) | ||
| 1534 | + { | ||
| 1535 | + $response['message'] = $result->getMessage(); | ||
| 1536 | + return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response); | ||
| 1537 | + } | ||
| 1538 | + | ||
| 1539 | + $content=''; | ||
| 1540 | + if ($download) | ||
| 1541 | + { | ||
| 1542 | + $document = $document->document; | ||
| 1543 | + | ||
| 1544 | + $oStorage =& KTStorageManagerUtil::getSingleton(); | ||
| 1545 | + $filename = $oStorage->temporaryFile($document); | ||
| 1546 | + | ||
| 1547 | + $fp=fopen($filename,'rt'); | ||
| 1548 | + if ($fp === false) | ||
| 1549 | + { | ||
| 1550 | + $response['message'] = 'The file is not in the storage system. Please contact an administrator!'; | ||
| 1551 | + return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response); | ||
| 1552 | + } | ||
| 1553 | + $content = fread($fp, filesize($filename)); | ||
| 1554 | + fclose($fp); | ||
| 1555 | + $content = base64_encode($content); | ||
| 1556 | + } | ||
| 1557 | + | ||
| 1558 | + $response['status_code'] = KTWS_SUCCESS; | ||
| 1559 | + $response['message'] = $content; | ||
| 1560 | + | ||
| 1561 | + return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response); | ||
| 1562 | + } | ||
| 1563 | + | ||
| 1564 | + /** | ||
| 1303 | * Undoes a document checkout. | 1565 | * Undoes a document checkout. |
| 1304 | * | 1566 | * |
| 1305 | * @param string $session_id | 1567 | * @param string $session_id |
| @@ -1387,6 +1649,65 @@ class KTWebService | @@ -1387,6 +1649,65 @@ class KTWebService | ||
| 1387 | } | 1649 | } |
| 1388 | 1650 | ||
| 1389 | /** | 1651 | /** |
| 1652 | + * Returns a reference to a file to be downloaded. | ||
| 1653 | + * | ||
| 1654 | + * @param string $session_id | ||
| 1655 | + * @param int $document_id | ||
| 1656 | + | ||
| 1657 | + * @return kt_response. status_code can be KTWS_ERR_INVALID_SESSION, KTWS_ERR_INVALID_DOCUMENT or KTWS_SUCCESS | ||
| 1658 | + */ | ||
| 1659 | + function download_small_document($session_id, $document_id) | ||
| 1660 | + { | ||
| 1661 | + $kt = &$this->get_ktapi($session_id ); | ||
| 1662 | + if (is_array($kt)) | ||
| 1663 | + { | ||
| 1664 | + return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $kt); | ||
| 1665 | + } | ||
| 1666 | + | ||
| 1667 | + $response=array( | ||
| 1668 | + 'status_code'=>KTWS_ERR_INVALID_DOCUMENT, | ||
| 1669 | + 'message'=>'' | ||
| 1670 | + ); | ||
| 1671 | + | ||
| 1672 | + $document = &$kt->get_document_by_id($document_id); | ||
| 1673 | + if (PEAR::isError($document)) | ||
| 1674 | + { | ||
| 1675 | + $response['message'] = $document->getMessage(); | ||
| 1676 | + return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response); | ||
| 1677 | + } | ||
| 1678 | + | ||
| 1679 | + $result = $document->download(); | ||
| 1680 | + if (PEAR::isError($result)) | ||
| 1681 | + { | ||
| 1682 | + $response['message'] = $result->getMessage(); | ||
| 1683 | + return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response); | ||
| 1684 | + } | ||
| 1685 | + | ||
| 1686 | + $content=''; | ||
| 1687 | + | ||
| 1688 | + $document = $document->document; | ||
| 1689 | + | ||
| 1690 | + $oStorage =& KTStorageManagerUtil::getSingleton(); | ||
| 1691 | + $filename = $oStorage->temporaryFile($document); | ||
| 1692 | + | ||
| 1693 | + $fp=fopen($filename,'rt'); | ||
| 1694 | + if ($fp === false) | ||
| 1695 | + { | ||
| 1696 | + $response['message'] = 'The file is not in the storage system. Please contact an administrator!'; | ||
| 1697 | + return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response); | ||
| 1698 | + } | ||
| 1699 | + $content = fread($fp, filesize($filename)); | ||
| 1700 | + fclose($fp); | ||
| 1701 | + $content = base64_encode($content); | ||
| 1702 | + | ||
| 1703 | + | ||
| 1704 | + $response['status_code'] = KTWS_SUCCESS; | ||
| 1705 | + $response['message'] = $content; | ||
| 1706 | + | ||
| 1707 | + return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response); | ||
| 1708 | + } | ||
| 1709 | + | ||
| 1710 | + /** | ||
| 1390 | * Deletes a document. | 1711 | * Deletes a document. |
| 1391 | * | 1712 | * |
| 1392 | * @param string $session_id | 1713 | * @param string $session_id |