Commit 43daf1ccda2f37bb0931b3a37681ae0b64a457fb
1 parent
681f0f64
KTS-1694
"SOAP Webservice Implementation" Implemented. This implements the Web Service Object Model API. Currently, it is in PHP5. Reviewed By: Jalaloedien Abrahams git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@6448 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
2 changed files
with
1054 additions
and
0 deletions
ktwsapi/ktwsapi.inc.php
0 → 100644
| 1 | +<? | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * | |
| 5 | + * This is the object model for the KnowledgeTree WebService. | |
| 6 | + * | |
| 7 | + * The contents of this file are subject to the KnowledgeTree Public | |
| 8 | + * License Version 1.1 ("License"); You may not use this file except in | |
| 9 | + * compliance with the License. You may obtain a copy of the License at | |
| 10 | + * http://www.knowledgetree.com/KPL | |
| 11 | + * | |
| 12 | + * Software distributed under the License is distributed on an "AS IS" | |
| 13 | + * basis, | |
| 14 | + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | |
| 15 | + * for the specific language governing rights and limitations under the | |
| 16 | + * License. | |
| 17 | + * | |
| 18 | + * The Original Code is: KnowledgeTree Open Source | |
| 19 | + * | |
| 20 | + * The Initial Developer of the Original Code is The Jam Warehouse Software | |
| 21 | + * (Pty) Ltd, trading as KnowledgeTree. | |
| 22 | + * Portions created by The Jam Warehouse Software (Pty) Ltd are Copyright | |
| 23 | + * (C) 2007 The Jam Warehouse Software (Pty) Ltd; | |
| 24 | + * All Rights Reserved. | |
| 25 | + * | |
| 26 | + */ | |
| 27 | + | |
| 28 | +// TODO: comment | |
| 29 | +// TODO: php4 compatability | |
| 30 | + | |
| 31 | +require_once('ktwsapi_cfg.inc.php'); | |
| 32 | + | |
| 33 | +ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . KT_PEAR_DIR); | |
| 34 | + | |
| 35 | +require_once('SOAP/Client.php'); | |
| 36 | + | |
| 37 | +define('KTWSAPI_ERR_SESSION_IN_USE','There is a session already active.'); | |
| 38 | +define('KTWSAPI_ERR_SESSION_NOT_STARTED','An active session has not been started.'); | |
| 39 | + | |
| 40 | +class KTWSAPI_FolderItem | |
| 41 | +{ | |
| 42 | + var $ktapi; | |
| 43 | + | |
| 44 | + function _upload_file($filename, $action, $document_id=null) | |
| 45 | + { | |
| 46 | + if (!extension_loaded('curl')) | |
| 47 | + { | |
| 48 | + return new PEAR_Error('CURL library not included.'); | |
| 49 | + } | |
| 50 | + | |
| 51 | + if (!is_file($filename) || !is_readable($filename)) | |
| 52 | + { | |
| 53 | + return new PEAR_Error('Could not access file to upload.'); | |
| 54 | + } | |
| 55 | + | |
| 56 | + if (is_null($document_id)) | |
| 57 | + { | |
| 58 | + $uploadname="upload_document"; | |
| 59 | + } | |
| 60 | + else | |
| 61 | + { | |
| 62 | + $uploadname="upload_$document_id"; | |
| 63 | + | |
| 64 | + } | |
| 65 | + | |
| 66 | + $session_id = $this->ktapi->session; | |
| 67 | + | |
| 68 | + $ch = curl_init(); | |
| 69 | + $fp = fopen ($filename, 'r'); | |
| 70 | + curl_setopt($ch, CURLOPT_URL, KTUploadURL); | |
| 71 | + curl_setopt($ch, CURLOPT_POST, 1); | |
| 72 | + | |
| 73 | + $post_fields = array( | |
| 74 | + 'session_id'=>$session_id, | |
| 75 | + 'action'=>$action, | |
| 76 | + 'document_id'=>$document_id, | |
| 77 | + $uploadname=>'@' . $filename | |
| 78 | + | |
| 79 | + ); | |
| 80 | + | |
| 81 | + $str = serialize($post_fields); | |
| 82 | + | |
| 83 | + curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields); | |
| 84 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); | |
| 85 | + $response = curl_exec ($ch); | |
| 86 | + curl_close ($ch); | |
| 87 | + | |
| 88 | + if ($response == '') | |
| 89 | + { | |
| 90 | + return new PEAR_Error('No response from server.'); | |
| 91 | + } | |
| 92 | + | |
| 93 | + $fields=explode('&',$response); | |
| 94 | + $status_code=-1; | |
| 95 | + $msg='*not set*'; | |
| 96 | + $upload_status=''; | |
| 97 | + | |
| 98 | + | |
| 99 | + foreach($fields as $field) | |
| 100 | + { | |
| 101 | + list($fieldname, $value) = explode('=', $field); | |
| 102 | + | |
| 103 | + $$fieldname = $value; | |
| 104 | + } | |
| 105 | + | |
| 106 | + if ($status_code == 0) | |
| 107 | + { | |
| 108 | + $upload_status= unserialize(urldecode($upload_status)); | |
| 109 | + | |
| 110 | + if ($upload_status[$uploadname]['size'] == filesize($filename)) | |
| 111 | + { | |
| 112 | + return $upload_status[$uploadname]['tmp_name']; | |
| 113 | + } | |
| 114 | + } | |
| 115 | + return new PEAR_Error('Could not upload file.'); | |
| 116 | + | |
| 117 | + } | |
| 118 | + | |
| 119 | + function _download_file($url, $localpath, $filename) | |
| 120 | + { | |
| 121 | + $localfilename = $localpath . '/' . $filename; | |
| 122 | + | |
| 123 | + $fp = fopen($localfilename,'wb'); | |
| 124 | + if ($fp == null) | |
| 125 | + { | |
| 126 | + return new PEAR_Error('Could not create local file'); | |
| 127 | + } | |
| 128 | + | |
| 129 | + $ch = curl_init(); | |
| 130 | + | |
| 131 | + curl_setopt($ch, CURLOPT_FILE, $fp); | |
| 132 | + curl_setopt($ch, CURLOPT_HEADER, 0); | |
| 133 | + curl_setopt($ch, CURLOPT_URL, $url); | |
| 134 | + | |
| 135 | + $response = curl_exec($ch); | |
| 136 | + curl_close($ch); | |
| 137 | + | |
| 138 | + fclose($fp); | |
| 139 | + | |
| 140 | + return $response; | |
| 141 | + } | |
| 142 | + | |
| 143 | +} | |
| 144 | + | |
| 145 | +class KTWSAPI_Folder extends KTWSAPI_FolderItem | |
| 146 | +{ | |
| 147 | + var $folder_name; | |
| 148 | + var $parent_id; | |
| 149 | + var $full_path; | |
| 150 | + var $folderid; | |
| 151 | + | |
| 152 | + function KTWSAPI_Folder($ktapi, $kt_folder_detail) | |
| 153 | + { | |
| 154 | + $this->ktapi = $ktapi; | |
| 155 | + $this->folderid = $kt_folder_detail->id+0; | |
| 156 | + $this->folder_name = $kt_folder_detail->folder_name; | |
| 157 | + $this->parent_id = $kt_folder_detail->parent_id+0; | |
| 158 | + $this->full_path = $kt_folder_detail->full_path; | |
| 159 | + } | |
| 160 | + | |
| 161 | + function get($ktapi, $folderid) | |
| 162 | + { | |
| 163 | + assert(!is_null($ktapi)); | |
| 164 | + assert(is_a($ktapi, 'KTWSAPI')); | |
| 165 | + assert(is_numeric($folderid)); | |
| 166 | + | |
| 167 | + $folderid += 0; | |
| 168 | + | |
| 169 | + $kt_folder_detail = $ktapi->soapclient->get_folder_detail($ktapi->session, $folderid); | |
| 170 | + if (SOAP_Client::isError($kt_folder_detail)) | |
| 171 | + { | |
| 172 | + return $kt_folder_detail; | |
| 173 | + } | |
| 174 | + | |
| 175 | + if ($kt_folder_detail->status_code != 0) | |
| 176 | + { | |
| 177 | + return new PEAR_Error($kt_folder_detail->message); | |
| 178 | + } | |
| 179 | + | |
| 180 | + return new KTWSAPI_Folder($ktapi, $kt_folder_detail); | |
| 181 | + } | |
| 182 | + | |
| 183 | + function get_parent_folder_id() | |
| 184 | + { | |
| 185 | + return $this->parent_id; | |
| 186 | + } | |
| 187 | + | |
| 188 | + function get_folder_name() | |
| 189 | + { | |
| 190 | + return $this->folder_name; | |
| 191 | + } | |
| 192 | + | |
| 193 | + function get_folderid() | |
| 194 | + { | |
| 195 | + return $this->folderid; | |
| 196 | + } | |
| 197 | + | |
| 198 | + /** | |
| 199 | + * | |
| 200 | + * | |
| 201 | + * @param string $foldername | |
| 202 | + * @return KTWSAPI_Folder | |
| 203 | + */ | |
| 204 | + function get_folder_by_name($foldername) | |
| 205 | + { | |
| 206 | + $path = $this->full_path . '/' . $foldername; | |
| 207 | + if (substr($path,0,13) == '/Root Folder/') | |
| 208 | + { | |
| 209 | + $path = substr($path,13); | |
| 210 | + } | |
| 211 | + if (substr($path,0,12) == 'Root Folder/') | |
| 212 | + { | |
| 213 | + $path = substr($path,12); | |
| 214 | + } | |
| 215 | + | |
| 216 | + $kt_folder_detail = $this->ktapi->soapclient->get_folder_detail_by_name($this->ktapi->session, $path); | |
| 217 | + | |
| 218 | + if (SOAP_Client::isError($kt_folder_detail)) | |
| 219 | + { | |
| 220 | + return $kt_folder_detail; | |
| 221 | + } | |
| 222 | + | |
| 223 | + if ($kt_folder_detail->status_code != 0) | |
| 224 | + { | |
| 225 | + return new PEAR_Error($kt_folder_detail->message); | |
| 226 | + } | |
| 227 | + | |
| 228 | + return new KTWSAPI_Folder($this->ktapi, $kt_folder_detail); | |
| 229 | + } | |
| 230 | + | |
| 231 | + function get_full_path() | |
| 232 | + { | |
| 233 | + return $this->full_path; | |
| 234 | + } | |
| 235 | + | |
| 236 | + function get_listing($depth=1, $what='DF') | |
| 237 | + { | |
| 238 | + $kt_folder_contents = $this->ktapi->soapclient->get_folder_contents($this->ktapi->session, $this->folderid, $depth+0, $what); | |
| 239 | + if (SOAP_Client::isError($kt_folder_contents)) | |
| 240 | + { | |
| 241 | + return $kt_folder_contents; | |
| 242 | + } | |
| 243 | + | |
| 244 | + if ($kt_folder_contents->status_code != 0) | |
| 245 | + { | |
| 246 | + return new PEAR_Error($kt_folder_contents->message); | |
| 247 | + } | |
| 248 | + | |
| 249 | + return $kt_folder_contents->items; | |
| 250 | + | |
| 251 | + } | |
| 252 | + | |
| 253 | + function get_document_by_name($title) | |
| 254 | + { | |
| 255 | + $path = $this->full_path . '/' . $title; | |
| 256 | + if (substr($path,0,13) == '/Root Folder/') | |
| 257 | + { | |
| 258 | + $path = substr($path,13); | |
| 259 | + } | |
| 260 | + if (substr($path,0,12) == 'Root Folder/') | |
| 261 | + { | |
| 262 | + $path = substr($path,12); | |
| 263 | + } | |
| 264 | + | |
| 265 | + $kt_document_detail = $this->ktapi->soapclient->get_document_detail_by_name($this->ktapi->session, $path, 'T'); | |
| 266 | + | |
| 267 | + if (SOAP_Client::isError($kt_document_detail)) | |
| 268 | + { | |
| 269 | + return $kt_document_detail; | |
| 270 | + } | |
| 271 | + | |
| 272 | + if ($kt_document_detail->status_code != 0) | |
| 273 | + { | |
| 274 | + return new PEAR_Error($kt_document_detail->message); | |
| 275 | + } | |
| 276 | + | |
| 277 | + return new KTWSAPI_Document($this->ktapi, $kt_document_detail); | |
| 278 | + } | |
| 279 | + | |
| 280 | + function get_document_by_filename($filename) | |
| 281 | + { | |
| 282 | + $path = $this->full_path . '/' . $filename; | |
| 283 | + if (substr($path,0,13) == '/Root Folder/') | |
| 284 | + { | |
| 285 | + $path = substr($path,13); | |
| 286 | + } | |
| 287 | + if (substr($path,0,12) == 'Root Folder/') | |
| 288 | + { | |
| 289 | + $path = substr($path,12); | |
| 290 | + } | |
| 291 | + | |
| 292 | + $kt_document_detail = $this->ktapi->soapclient->get_document_detail_by_name($this->ktapi->session, $path, 'F'); | |
| 293 | + | |
| 294 | + if (SOAP_Client::isError($kt_document_detail)) | |
| 295 | + { | |
| 296 | + return $kt_document_detail; | |
| 297 | + } | |
| 298 | + | |
| 299 | + if ($kt_document_detail->status_code != 0) | |
| 300 | + { | |
| 301 | + return new PEAR_Error($kt_document_detail->message); | |
| 302 | + } | |
| 303 | + | |
| 304 | + return new KTWSAPI_Document($this->ktapi, $kt_document_detail); | |
| 305 | + } | |
| 306 | + | |
| 307 | + | |
| 308 | + /** | |
| 309 | + * | |
| 310 | + * | |
| 311 | + * @param unknown_type $foldername | |
| 312 | + * @return KTWSAPI_Folder | |
| 313 | + */ | |
| 314 | + function add_folder($foldername) | |
| 315 | + { | |
| 316 | + $kt_folder_detail = $this->ktapi->soapclient->create_folder($this->ktapi->session, $this->folderid, $foldername); | |
| 317 | + if (SOAP_Client::isError($kt_folder_detail)) | |
| 318 | + { | |
| 319 | + return $kt_folder_detail; | |
| 320 | + } | |
| 321 | + | |
| 322 | + if ($kt_folder_detail->status_code != 0) | |
| 323 | + { | |
| 324 | + return new PEAR_Error($kt_folder_detail->message); | |
| 325 | + } | |
| 326 | + | |
| 327 | + return new KTWSAPI_Folder($this->ktapi, $kt_folder_detail); | |
| 328 | + } | |
| 329 | + | |
| 330 | + function delete($reason) | |
| 331 | + { | |
| 332 | + // TODO: check why no transaction in folder_transactions | |
| 333 | + $kt_response = $this->ktapi->soapclient->delete_folder($this->ktapi->session, $this->folderid, $reason); | |
| 334 | + if (SOAP_Client::isError($kt_response)) | |
| 335 | + { | |
| 336 | + return $kt_response; | |
| 337 | + } | |
| 338 | + | |
| 339 | + if ($kt_response->status_code != 0) | |
| 340 | + { | |
| 341 | + return new PEAR_Error($kt_response->message); | |
| 342 | + } | |
| 343 | + | |
| 344 | + return true; | |
| 345 | + } | |
| 346 | + | |
| 347 | + function rename($newname) | |
| 348 | + { | |
| 349 | + $kt_response = $this->ktapi->soapclient->rename_folder($this->ktapi->session, $this->folderid, $newname); | |
| 350 | + if (SOAP_Client::isError($kt_response)) | |
| 351 | + { | |
| 352 | + return $kt_response; | |
| 353 | + } | |
| 354 | + | |
| 355 | + if ($kt_response->status_code != 0) | |
| 356 | + { | |
| 357 | + return new PEAR_Error($kt_response->message); | |
| 358 | + } | |
| 359 | + | |
| 360 | + return true; | |
| 361 | + } | |
| 362 | + | |
| 363 | + /** | |
| 364 | + * Enter description here... | |
| 365 | + * | |
| 366 | + * @param KTWSAPI_Folder $ktwsapi_target_folder | |
| 367 | + * @param string $reason | |
| 368 | + */ | |
| 369 | + function move($ktwsapi_target_folder, $reason='') | |
| 370 | + { | |
| 371 | + assert(!is_null($ktwsapi_target_folder)); | |
| 372 | + assert(is_a($ktwsapi_target_folder,'KTWSAPI_Folder')); | |
| 373 | + | |
| 374 | + $kt_response = $this->ktapi->soapclient->move_folder($this->ktapi->session, $this->folderid,$ktwsapi_target_folder->get_folderid(), $newname); | |
| 375 | + if (SOAP_Client::isError($kt_response)) | |
| 376 | + { | |
| 377 | + return $kt_response; | |
| 378 | + } | |
| 379 | + | |
| 380 | + if ($kt_response->status_code != 0) | |
| 381 | + { | |
| 382 | + return new PEAR_Error($kt_response->message); | |
| 383 | + } | |
| 384 | + | |
| 385 | + return true; | |
| 386 | + } | |
| 387 | + | |
| 388 | + /** | |
| 389 | + * Enter description here... | |
| 390 | + * | |
| 391 | + * @param KTWSAPI_Folder $ktwsapi_target_folder | |
| 392 | + * @param string $reason | |
| 393 | + * @return unknown | |
| 394 | + */ | |
| 395 | + function copy($ktwsapi_target_folder, $reason='') | |
| 396 | + { | |
| 397 | + assert(!is_null($ktwsapi_target_folder)); | |
| 398 | + assert(is_a($ktwsapi_target_folder,'KTWSAPI_Folder')); | |
| 399 | + | |
| 400 | + $targetid=$ktwsapi_target_folder->get_folderid(); | |
| 401 | + | |
| 402 | + $kt_response = $this->ktapi->soapclient->copy_folder($this->ktapi->session, $this->folderid,$targetid, $reason); | |
| 403 | + if (SOAP_Client::isError($kt_response)) | |
| 404 | + { | |
| 405 | + return $kt_response; | |
| 406 | + } | |
| 407 | + | |
| 408 | + if ($kt_response->status_code != 0) | |
| 409 | + { | |
| 410 | + return new PEAR_Error($kt_response->message); | |
| 411 | + } | |
| 412 | + | |
| 413 | + return true; | |
| 414 | + } | |
| 415 | + | |
| 416 | + function add_document($filename, $title=null, $documenttype=null) | |
| 417 | + { | |
| 418 | + if (empty($title)) | |
| 419 | + { | |
| 420 | + $title=basename($filename); | |
| 421 | + } | |
| 422 | + $basename=basename($filename); | |
| 423 | + | |
| 424 | + if (empty($documenttype)) | |
| 425 | + { | |
| 426 | + $documenttype='Default'; | |
| 427 | + } | |
| 428 | + | |
| 429 | + // First step - upload file | |
| 430 | + $tempfilename = $this->_upload_file($filename,'A'); | |
| 431 | + if (PEAR::isError($tempfilename)) | |
| 432 | + { | |
| 433 | + return new PEAR_Error($tempfilename->message); | |
| 434 | + } | |
| 435 | + | |
| 436 | + // Second step - move file into KT | |
| 437 | + $kt_document_detail = $this->ktapi->soapclient->add_document($this->ktapi->session, $this->folderid, $title, $basename, $documenttype, $tempfilename ); | |
| 438 | + if (SOAP_Client::isError($kt_document_detail)) | |
| 439 | + { | |
| 440 | + return $kt_document_detail; | |
| 441 | + } | |
| 442 | + | |
| 443 | + if ($kt_document_detail->status_code != 0) | |
| 444 | + { | |
| 445 | + return new PEAR_Error($kt_document_detail->message); | |
| 446 | + } | |
| 447 | + | |
| 448 | + return true; | |
| 449 | + } | |
| 450 | +} | |
| 451 | + | |
| 452 | +class KTWSAPI_Document extends KTWSAPI_FolderItem | |
| 453 | +{ | |
| 454 | + var $document_id; | |
| 455 | + var $title; | |
| 456 | + var $document_type; | |
| 457 | + var $version; | |
| 458 | + var $filename; | |
| 459 | + var $created_date; | |
| 460 | + var $created_by; | |
| 461 | + var $updated_date; | |
| 462 | + var $updated_by; | |
| 463 | + var $folder_id; | |
| 464 | + var $workflow; | |
| 465 | + var $workflow_state; | |
| 466 | + var $checkout_by; | |
| 467 | + var $full_path; | |
| 468 | + | |
| 469 | + function KTWSAPI_Document($ktapi, $kt_document_detail) | |
| 470 | + { | |
| 471 | + $this->ktapi=$ktapi; | |
| 472 | + $this->document_id = $kt_document_detail->document_id; | |
| 473 | + $this->title = $kt_document_detail->title; | |
| 474 | + $this->document_type = $kt_document_detail->document_type; | |
| 475 | + $this->version = $kt_document_detail->version; | |
| 476 | + $this->filename = $kt_document_detail->filename; | |
| 477 | + $this->created_date = $kt_document_detail->created_date; | |
| 478 | + $this->created_by = $kt_document_detail->created_by; | |
| 479 | + $this->updated_date = $kt_document_detail->updated_date; | |
| 480 | + $this->updated_by = $kt_document_detail->updated_by; | |
| 481 | + $this->folder_id = $kt_document_detail->folder_id; | |
| 482 | + $this->workflow = $kt_document_detail->workflow; | |
| 483 | + $this->workflow_state = $kt_document_detail->workflow_state; | |
| 484 | + $this->checkout_by = $kt_document_detail->checkout_by; | |
| 485 | + $this->full_path = $kt_document_detail->full_path; | |
| 486 | + } | |
| 487 | + | |
| 488 | + function get($ktapi, $documentid, $loadinfo=true) | |
| 489 | + { | |
| 490 | + assert(!is_null($ktapi)); | |
| 491 | + assert(is_a($ktapi, 'KTWSAPI')); | |
| 492 | + assert(is_numeric($documentid)); | |
| 493 | + | |
| 494 | + if ($loadinfo) | |
| 495 | + { | |
| 496 | + $kt_document_detail = $ktapi->soapclient->get_document_detail($ktapi->session, $documentid); | |
| 497 | + if (SOAP_Client::isError($kt_document_detail)) | |
| 498 | + { | |
| 499 | + return $kt_document_detail; | |
| 500 | + } | |
| 501 | + | |
| 502 | + if ($kt_document_detail->status_code != 0) | |
| 503 | + { | |
| 504 | + return new PEAR_Error($kt_document_detail->message); | |
| 505 | + } | |
| 506 | + } | |
| 507 | + else | |
| 508 | + { | |
| 509 | + $kt_document_detail = array( | |
| 510 | + 'document_id'=>$documentid, | |
| 511 | + ); | |
| 512 | + } | |
| 513 | + | |
| 514 | + return new KTWSAPI_Document($ktapi, $kt_document_detail); | |
| 515 | + } | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + function checkin($filename, $reason, $major_update ) | |
| 520 | + { | |
| 521 | + $basename=basename($filename); | |
| 522 | + | |
| 523 | + $tempfilename = $this->_upload_file($filename,'C', $this->document_id); | |
| 524 | + if (PEAR::isError($tempfilename)) | |
| 525 | + { | |
| 526 | + return new PEAR_Error($tempfilename->message); | |
| 527 | + } | |
| 528 | + | |
| 529 | + $kt_response = $this->ktapi->soapclient->checkin_document($this->ktapi->session, $this->document_id, $basename, $reason, $tempfilename, $major_update ); | |
| 530 | + if (SOAP_Client::isError($kt_response)) | |
| 531 | + { | |
| 532 | + return $kt_response; | |
| 533 | + } | |
| 534 | + | |
| 535 | + if ($kt_response->status_code != 0) | |
| 536 | + { | |
| 537 | + return new PEAR_Error($kt_response->message); | |
| 538 | + } | |
| 539 | + | |
| 540 | + return true; | |
| 541 | + } | |
| 542 | + | |
| 543 | + function checkout($reason, $localpath=null) | |
| 544 | + { | |
| 545 | + if (is_null($localpath)) | |
| 546 | + { | |
| 547 | + $localpath = $this->ktapi->get_download_path(); | |
| 548 | + } | |
| 549 | + | |
| 550 | + if (!is_dir($localpath)) | |
| 551 | + { | |
| 552 | + return new PEAR_Error('local path does not exist'); | |
| 553 | + } | |
| 554 | + if (!is_writable($localpath)) | |
| 555 | + { | |
| 556 | + return new PEAR_Error('local path is not writable'); | |
| 557 | + } | |
| 558 | + | |
| 559 | + $kt_response = $this->ktapi->soapclient->checkout_document($this->ktapi->session, $this->document_id, $reason); | |
| 560 | + if (SOAP_Client::isError($kt_response)) | |
| 561 | + { | |
| 562 | + return $kt_response; | |
| 563 | + } | |
| 564 | + | |
| 565 | + if ($kt_response->status_code != 0) | |
| 566 | + { | |
| 567 | + return new PEAR_Error($kt_response->message); | |
| 568 | + } | |
| 569 | + | |
| 570 | + $url = $kt_response->message; | |
| 571 | + | |
| 572 | + $response = $this->_download_file($url, $localpath, $this->filename); | |
| 573 | + if (PEAR::isError($response)) | |
| 574 | + { | |
| 575 | + return new PEAR_Error($kt_response->message); | |
| 576 | + } | |
| 577 | + | |
| 578 | + return true; | |
| 579 | + } | |
| 580 | + | |
| 581 | + function undo_checkout($reason) | |
| 582 | + { | |
| 583 | + $kt_response = $this->ktapi->soapclient->undo_document_checkout($this->ktapi->session, $this->document_id, $reason); | |
| 584 | + if (SOAP_Client::isError($kt_response)) | |
| 585 | + { | |
| 586 | + return $kt_response; | |
| 587 | + } | |
| 588 | + | |
| 589 | + if ($kt_response->status_code != 0) | |
| 590 | + { | |
| 591 | + return new PEAR_Error($kt_response->message); | |
| 592 | + } | |
| 593 | + | |
| 594 | + return true; | |
| 595 | + } | |
| 596 | + | |
| 597 | + function download($version=null, $localpath=null) | |
| 598 | + { | |
| 599 | + if (is_null($localpath)) | |
| 600 | + { | |
| 601 | + $localpath = $this->ktapi->get_download_path(); | |
| 602 | + } | |
| 603 | + | |
| 604 | + if (!is_dir($localpath)) | |
| 605 | + { | |
| 606 | + return new PEAR_Error('local path does not exist'); | |
| 607 | + } | |
| 608 | + if (!is_writable($localpath)) | |
| 609 | + { | |
| 610 | + return new PEAR_Error('local path is not writable'); | |
| 611 | + } | |
| 612 | + | |
| 613 | + $kt_response = $this->ktapi->soapclient->download_document($this->ktapi->session, $this->document_id); | |
| 614 | + if (SOAP_Client::isError($kt_response)) | |
| 615 | + { | |
| 616 | + return $kt_response; | |
| 617 | + } | |
| 618 | + | |
| 619 | + if ($kt_response->status_code != 0) | |
| 620 | + { | |
| 621 | + return new PEAR_Error($kt_response->message); | |
| 622 | + } | |
| 623 | + | |
| 624 | + $url = $kt_response->message; | |
| 625 | + | |
| 626 | + $response = $this->_download_file($url, $localpath, $this->filename); | |
| 627 | + if (PEAR::isError($response)) | |
| 628 | + { | |
| 629 | + return new PEAR_Error($kt_response->message); | |
| 630 | + } | |
| 631 | + | |
| 632 | + return true; | |
| 633 | + } | |
| 634 | + | |
| 635 | + function delete($reason) | |
| 636 | + { | |
| 637 | + $kt_response = $this->ktapi->soapclient->delete_document($this->ktapi->session, $this->document_id, $reason); | |
| 638 | + if (SOAP_Client::isError($kt_response)) | |
| 639 | + { | |
| 640 | + return $kt_response; | |
| 641 | + } | |
| 642 | + | |
| 643 | + if ($kt_response->status_code != 0) | |
| 644 | + { | |
| 645 | + return new PEAR_Error($kt_response->message); | |
| 646 | + } | |
| 647 | + | |
| 648 | + return true; | |
| 649 | + } | |
| 650 | + | |
| 651 | + function change_owner($username, $reason) | |
| 652 | + { | |
| 653 | + $kt_response = $this->ktapi->soapclient->change_document_owner($this->ktapi->session, $this->document_id, $username, $reason); | |
| 654 | + if (SOAP_Client::isError($kt_response)) | |
| 655 | + { | |
| 656 | + return $kt_response; | |
| 657 | + } | |
| 658 | + | |
| 659 | + if ($kt_response->status_code != 0) | |
| 660 | + { | |
| 661 | + return new PEAR_Error($kt_response->message); | |
| 662 | + } | |
| 663 | + | |
| 664 | + return true; | |
| 665 | + } | |
| 666 | + | |
| 667 | + /** | |
| 668 | + * Enter description here... | |
| 669 | + * | |
| 670 | + * @param KTWSAPI_Folder $folder | |
| 671 | + * @param unknown_type $reason | |
| 672 | + * @param unknown_type $newtitle | |
| 673 | + * @param unknown_type $newfilename | |
| 674 | + */ | |
| 675 | + | |
| 676 | + function copy($folder,$reason,$newtitle='',$newfilename='') | |
| 677 | + { | |
| 678 | + $folder_id = $folder->folderid; | |
| 679 | + $kt_response = $this->ktapi->soapclient->copy_document($this->ktapi->session, $this->document_id, $folder_id, $reason, $newtitle, $newfilename); | |
| 680 | + if (SOAP_Client::isError($kt_response)) | |
| 681 | + { | |
| 682 | + return $kt_response; | |
| 683 | + } | |
| 684 | + | |
| 685 | + if ($kt_response->status_code != 0) | |
| 686 | + { | |
| 687 | + return new PEAR_Error($kt_response->message); | |
| 688 | + } | |
| 689 | + | |
| 690 | + return true; | |
| 691 | + } | |
| 692 | + function move($folder,$reason,$newtitle='',$newfilename='') | |
| 693 | + { | |
| 694 | + $folder_id = $folder->folderid; | |
| 695 | + $kt_response = $this->ktapi->soapclient->move_document($this->ktapi->session, $this->document_id, $folder_id, $reason, $newtitle, $newfilename); | |
| 696 | + if (SOAP_Client::isError($kt_response)) | |
| 697 | + { | |
| 698 | + return $kt_response; | |
| 699 | + } | |
| 700 | + | |
| 701 | + if ($kt_response->status_code != 0) | |
| 702 | + { | |
| 703 | + return new PEAR_Error($kt_response->message); | |
| 704 | + } | |
| 705 | + | |
| 706 | + return true; | |
| 707 | + } | |
| 708 | + | |
| 709 | + function change_document_type($documenttype) | |
| 710 | + { | |
| 711 | + $kt_response = $this->ktapi->soapclient->change_document_type($this->ktapi->session, $this->document_id, $documenttype); | |
| 712 | + if (SOAP_Client::isError($kt_response)) | |
| 713 | + { | |
| 714 | + return $kt_response; | |
| 715 | + } | |
| 716 | + | |
| 717 | + if ($kt_response->status_code != 0) | |
| 718 | + { | |
| 719 | + return new PEAR_Error($kt_response->message); | |
| 720 | + } | |
| 721 | + | |
| 722 | + return true; | |
| 723 | + } | |
| 724 | + | |
| 725 | + function rename_title( $newtitle) | |
| 726 | + { | |
| 727 | + $kt_response = $this->ktapi->soapclient->rename_document_title($this->ktapi->session, $this->document_id, $newtitle); | |
| 728 | + if (SOAP_Client::isError($kt_response)) | |
| 729 | + { | |
| 730 | + return $kt_response; | |
| 731 | + } | |
| 732 | + | |
| 733 | + if ($kt_response->status_code != 0) | |
| 734 | + { | |
| 735 | + return new PEAR_Error($kt_response->message); | |
| 736 | + } | |
| 737 | + | |
| 738 | + return true; | |
| 739 | + } | |
| 740 | + function rename_filename( $newfilename) | |
| 741 | + { | |
| 742 | + $kt_response = $this->ktapi->soapclient->rename_document_filename($this->ktapi->session, $this->document_id, $newfilename); | |
| 743 | + if (SOAP_Client::isError($kt_response)) | |
| 744 | + { | |
| 745 | + return $kt_response; | |
| 746 | + } | |
| 747 | + | |
| 748 | + if ($kt_response->status_code != 0) | |
| 749 | + { | |
| 750 | + return new PEAR_Error($kt_response->message); | |
| 751 | + } | |
| 752 | + | |
| 753 | + return true; | |
| 754 | + } | |
| 755 | + | |
| 756 | + function start_workflow($workflow) | |
| 757 | + { | |
| 758 | + $kt_response = $this->ktapi->soapclient->start_document_workflow($this->ktapi->session, $this->document_id, $workflow); | |
| 759 | + if (SOAP_Client::isError($kt_response)) | |
| 760 | + { | |
| 761 | + return $kt_response; | |
| 762 | + } | |
| 763 | + | |
| 764 | + if ($kt_response->status_code != 0) | |
| 765 | + { | |
| 766 | + return new PEAR_Error($kt_response->message); | |
| 767 | + } | |
| 768 | + | |
| 769 | + return true; | |
| 770 | + } | |
| 771 | + | |
| 772 | + function delete_document_workflow() | |
| 773 | + { | |
| 774 | + $kt_response = $this->ktapi->soapclient->delete_document_workflow($this->ktapi->session, $this->document_id); | |
| 775 | + if (SOAP_Client::isError($kt_response)) | |
| 776 | + { | |
| 777 | + return $kt_response; | |
| 778 | + } | |
| 779 | + | |
| 780 | + if ($kt_response->status_code != 0) | |
| 781 | + { | |
| 782 | + return new PEAR_Error($kt_response->message); | |
| 783 | + } | |
| 784 | + | |
| 785 | + return true; | |
| 786 | + } | |
| 787 | + | |
| 788 | + function perform_document_workflow_transition($session_id,$document_id,$transition,$reason) | |
| 789 | + { | |
| 790 | + $kt_response = $this->ktapi->soapclient->delete_document_workflow($this->ktapi->session, $this->document_id, $transition, $reason); | |
| 791 | + if (SOAP_Client::isError($kt_response)) | |
| 792 | + { | |
| 793 | + return $kt_response; | |
| 794 | + } | |
| 795 | + | |
| 796 | + if ($kt_response->status_code != 0) | |
| 797 | + { | |
| 798 | + return new PEAR_Error($kt_response->message); | |
| 799 | + } | |
| 800 | + | |
| 801 | + return true; | |
| 802 | + } | |
| 803 | + | |
| 804 | + function get_metadata() | |
| 805 | + { | |
| 806 | + $kt_metadata_response = $this->ktapi->soapclient->get_document_metadata($this->ktapi->session, $this->document_id ); | |
| 807 | + if (SOAP_Client::isError($kt_metadata_response)) | |
| 808 | + { | |
| 809 | + return $kt_metadata_response; | |
| 810 | + } | |
| 811 | + | |
| 812 | + if ($kt_metadata_response->status_code != 0) | |
| 813 | + { | |
| 814 | + return new PEAR_Error($kt_metadata_response->message); | |
| 815 | + } | |
| 816 | + | |
| 817 | + return $kt_metadata_response; | |
| 818 | + } | |
| 819 | + | |
| 820 | + function update_metadata($metadata) | |
| 821 | + { | |
| 822 | + $kt_response = $this->ktapi->soapclient->update_document_metadata($this->ktapi->session, $this->document_id, $metadata); | |
| 823 | + if (SOAP_Client::isError($kt_response)) | |
| 824 | + { | |
| 825 | + return $kt_response; | |
| 826 | + } | |
| 827 | + | |
| 828 | + if ($kt_response->status_code != 0) | |
| 829 | + { | |
| 830 | + return new PEAR_Error($kt_response->message); | |
| 831 | + } | |
| 832 | + | |
| 833 | + return $kt_response; | |
| 834 | + } | |
| 835 | + | |
| 836 | + function get_transaction_history() | |
| 837 | + { | |
| 838 | + $kt_document_transaction_history_response = $this->ktapi->soapclient->get_document_transaction_history($this->ktapi->session, $this->document_id); | |
| 839 | + if (SOAP_Client::isError($kt_document_transaction_history_response)) | |
| 840 | + { | |
| 841 | + return $kt_document_transaction_history_response; | |
| 842 | + } | |
| 843 | + | |
| 844 | + if ($kt_document_transaction_history_response->status_code != 0) | |
| 845 | + { | |
| 846 | + return new PEAR_Error($kt_document_transaction_history_response->message); | |
| 847 | + } | |
| 848 | + | |
| 849 | + return $kt_document_transaction_history_response->history; | |
| 850 | + } | |
| 851 | + | |
| 852 | + function get_version_history() | |
| 853 | + { | |
| 854 | + $kt_document_version_history_response = $this->ktapi->soapclient->get_document_version_history($this->ktapi->session, $this->document_id); | |
| 855 | + if (SOAP_Client::isError($kt_document_version_history_response)) | |
| 856 | + { | |
| 857 | + return $kt_document_version_history_response; | |
| 858 | + } | |
| 859 | + | |
| 860 | + if ($kt_document_version_history_response->status_code != 0) | |
| 861 | + { | |
| 862 | + return new PEAR_Error($kt_document_version_history_response->message); | |
| 863 | + } | |
| 864 | + | |
| 865 | + return $kt_document_version_history_response->history; | |
| 866 | + } | |
| 867 | +} | |
| 868 | + | |
| 869 | +class KTWSAPI | |
| 870 | +{ | |
| 871 | + var $wsdl; | |
| 872 | + /** | |
| 873 | + * Enter description here... | |
| 874 | + * | |
| 875 | + * @var SOAP_Client | |
| 876 | + */ | |
| 877 | + var $soapclient; | |
| 878 | + var $timeout; | |
| 879 | + var $session; | |
| 880 | + var $download_path; | |
| 881 | + | |
| 882 | + function KTWSAPI($wsdl, $timeout=30) | |
| 883 | + { | |
| 884 | + $this->wsdl = new SOAP_WSDL($wsdl); | |
| 885 | + $this->timeout = $timeout; | |
| 886 | + $this->soapclient = $this->wsdl->getProxy(); | |
| 887 | + $this->soapclient->setOpt('timeout', $this->timeout); | |
| 888 | + $this->download_path = 'c:/temp'; | |
| 889 | + } | |
| 890 | + | |
| 891 | + function get_download_path() | |
| 892 | + { | |
| 893 | + return $this->download_path; | |
| 894 | + } | |
| 895 | + | |
| 896 | + function set_download_path($download_path) | |
| 897 | + { | |
| 898 | + if (!is_dir($download_path)) | |
| 899 | + { | |
| 900 | + return new PEAR_Error('local path is not writable'); | |
| 901 | + } | |
| 902 | + | |
| 903 | + if (!is_writable($download_path)) | |
| 904 | + { | |
| 905 | + return new PEAR_Error('local path is not writable'); | |
| 906 | + } | |
| 907 | + $this->download_path = $download_path; | |
| 908 | + } | |
| 909 | + | |
| 910 | + function start_anonymous_session($ip=null) | |
| 911 | + { | |
| 912 | + return $this->start_session('anonymous','',$ip); | |
| 913 | + } | |
| 914 | + | |
| 915 | + function start_session($username, $password, $ip=null) | |
| 916 | + { | |
| 917 | + if (!is_null($this->session)) | |
| 918 | + { | |
| 919 | + return new PEAR_Error(KTWSAPI_ERR_SESSION_IN_USE); | |
| 920 | + } | |
| 921 | + $kt_response = $this->soapclient->login($username, $password, $ip); | |
| 922 | + if (SOAP_Client::isError($kt_response)) | |
| 923 | + { | |
| 924 | + return $kt_response; | |
| 925 | + } | |
| 926 | + | |
| 927 | + if ($kt_response->status_code == 0) | |
| 928 | + { | |
| 929 | + $this->session = $kt_response->message; | |
| 930 | + } | |
| 931 | + else | |
| 932 | + { | |
| 933 | + return new PEAR_Error($kt_response->message); | |
| 934 | + } | |
| 935 | + | |
| 936 | + return $this->session; | |
| 937 | + } | |
| 938 | + | |
| 939 | + function active_session($session, $ip=null) | |
| 940 | + { | |
| 941 | + if (!is_null($this->session)) | |
| 942 | + { | |
| 943 | + return new PEAR_Error(KTWSAPI_ERR_SESSION_IN_USE); | |
| 944 | + } | |
| 945 | + $this->session = $session; | |
| 946 | + | |
| 947 | + return $session; | |
| 948 | + } | |
| 949 | + | |
| 950 | + function logout() | |
| 951 | + { | |
| 952 | + if (is_null($this->session)) | |
| 953 | + { | |
| 954 | + return new PEAR_Error(KTWSAPI_ERR_SESSION_NOT_STARTED); | |
| 955 | + } | |
| 956 | + | |
| 957 | + $kt_response = $this->soapclient->logout($this->session); | |
| 958 | + | |
| 959 | + if ($kt_response->status_code != 0) | |
| 960 | + { | |
| 961 | + return new PEAR_Error($kt_response->message); | |
| 962 | + } | |
| 963 | + $this->session = null; | |
| 964 | + | |
| 965 | + return true; | |
| 966 | + } | |
| 967 | + | |
| 968 | + /** | |
| 969 | + * | |
| 970 | + * | |
| 971 | + * @return KTWSAPI_Folder | |
| 972 | + */ | |
| 973 | + function get_root_folder() | |
| 974 | + { | |
| 975 | + return $this->get_folder_by_id(1); | |
| 976 | + } | |
| 977 | + | |
| 978 | + /** | |
| 979 | + * | |
| 980 | + * | |
| 981 | + * @return KTWSAPI_Folder | |
| 982 | + */ | |
| 983 | + function get_folder_by_id($folderid) | |
| 984 | + { | |
| 985 | + if (is_null($this->session)) | |
| 986 | + { | |
| 987 | + return new PEAR_Error('A session is not active'); | |
| 988 | + } | |
| 989 | + | |
| 990 | + $folder = KTWSAPI_Folder::get($this, $folderid); | |
| 991 | + | |
| 992 | + return $folder; | |
| 993 | + } | |
| 994 | + | |
| 995 | + /** | |
| 996 | + * Enter description here... | |
| 997 | + * | |
| 998 | + * @param int $documentid | |
| 999 | + * @return KTWSAPI_Document | |
| 1000 | + */ | |
| 1001 | + function get_document_by_id($documentid) | |
| 1002 | + { | |
| 1003 | + if (is_null($this->session)) | |
| 1004 | + { | |
| 1005 | + return new PEAR_Error('A session is not active'); | |
| 1006 | + } | |
| 1007 | + | |
| 1008 | + $document = KTWSAPI_Document::get($this, $documentid); | |
| 1009 | + | |
| 1010 | + return $document; | |
| 1011 | + } | |
| 1012 | +} | |
| 1013 | + | |
| 1014 | +?> | |
| 0 | 1015 | \ No newline at end of file | ... | ... |
ktwsapi/ktwsapi_cfg.inc.php
0 → 100644
| 1 | +<? | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * | |
| 5 | + * This is the basic configuration for the KnowledgeTree WebService object model. | |
| 6 | + * | |
| 7 | + * The contents of this file are subject to the KnowledgeTree Public | |
| 8 | + * License Version 1.1 ("License"); You may not use this file except in | |
| 9 | + * compliance with the License. You may obtain a copy of the License at | |
| 10 | + * http://www.knowledgetree.com/KPL | |
| 11 | + * | |
| 12 | + * Software distributed under the License is distributed on an "AS IS" | |
| 13 | + * basis, | |
| 14 | + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | |
| 15 | + * for the specific language governing rights and limitations under the | |
| 16 | + * License. | |
| 17 | + * | |
| 18 | + * The Original Code is: KnowledgeTree Open Source | |
| 19 | + * | |
| 20 | + * The Initial Developer of the Original Code is The Jam Warehouse Software | |
| 21 | + * (Pty) Ltd, trading as KnowledgeTree. | |
| 22 | + * Portions created by The Jam Warehouse Software (Pty) Ltd are Copyright | |
| 23 | + * (C) 2007 The Jam Warehouse Software (Pty) Ltd; | |
| 24 | + * All Rights Reserved. | |
| 25 | + * | |
| 26 | + */ | |
| 27 | + | |
| 28 | +// Path to PEAR libraries | |
| 29 | + | |
| 30 | +define('KT_PEAR_DIR', 'c:/kt/kt.trunk/thirdparty/pear'); | |
| 31 | + | |
| 32 | +// URL to KnowledgeTree installation | |
| 33 | +// This must be configured by the administrator installing this component. | |
| 34 | + | |
| 35 | +define('KTWebServiceURL', 'http://ktdms.trunk'); | |
| 36 | + | |
| 37 | +define('KTWebService_WSDL', KTWebServiceURL . '/ktwebservice/?wsdl'); | |
| 38 | +define('KTUploadURL', KTWebServiceURL . '/ktwebservice/upload.php'); | |
| 39 | + | |
| 40 | +?> | |
| 0 | 41 | \ No newline at end of file | ... | ... |