3 * SOAP Documentation Include - this file contains wrapper functions for the SOAP interface
5 * Copyright 2004 (c) GForge, LLC
6 * Copyright 2016, Franck Villaume - TrivialDev
9 * This file is part of FusionForge. FusionForge is free software;
10 * you can redistribute it and/or modify it under the terms of the
11 * GNU General Public License as published by the Free Software
12 * Foundation; either version 2 of the Licence, or (at your option)
15 * FusionForge is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 require_once $gfcommon.'include/FFError.class.php';
26 require_once $gfcommon.'docman/Document.class.php';
27 require_once $gfcommon.'docman/DocumentFactory.class.php';
28 require_once $gfcommon.'docman/DocumentGroup.class.php';
29 require_once $gfcommon.'docman/DocumentGroupFactory.class.php';
34 $server->wsdl->addComplexType(
41 'doc_group_id' => array('name' => 'doc_group_id', 'type' => 'xsd:int'),
42 'parent_doc_group' => array('name' => 'parent_doc_group', 'type' => 'xsd:int'),
43 'groupname' => array('name' => 'groupname', 'type' => 'xsd:string'),
44 'stateid' => array('name' => 'stateid', 'type' => 'xsd:int')
49 // DocumentGroup Array
52 $server->wsdl->addComplexType(
53 'ArrayOfDocumentGroup',
59 array(array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:DocumentGroup[]')),
65 $server->wsdl->addComplexType(
72 'docid' => array('name' => 'docid', 'type' => 'xsd:int'),
73 'doc_group' => array('name' => 'doc_group', 'type' => 'xsd:int'),
74 'title' => array('name' => 'title', 'type' => 'xsd:string'),
75 'description' => array('name' => 'description', 'type' => 'xsd:string'),
76 'stateid' => array('name' => 'stateid', 'type' => 'xsd:int'),
77 'filesize' => array('name' => 'filesize', 'type' => 'xsd:int')
85 $server->wsdl->addComplexType(
92 array(array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:Document[]')),
98 $server->wsdl->addComplexType(
105 'filename' => array('name' => 'filename', 'type' => 'xsd:string'),
106 'filetype' => array('name' => 'filetype', 'type' => 'xsd:string'),
107 'data' => array('name' => 'data', 'type' => 'xsd:string')
112 // DocumentFiles Array
115 $server->wsdl->addComplexType(
116 'ArrayOfDocumentFile',
122 array(array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:DocumentFile[]')),
128 $server->wsdl->addComplexType(
135 'state_id' => array('name' => 'state_id', 'type' => 'xsd:int'),
136 'description' => array('name' => 'description', 'type' => 'xsd:string')
141 // DocumentState Array
144 $server->wsdl->addComplexType(
145 'ArrayOfDocumentState',
151 array(array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:DocumentState[]')),
152 'tns:DocumentState');
160 'session_ser' => 'xsd:string'
162 array('getDocumentStatesResponse' => 'tns:ArrayOfDocumentState'),
163 $uri, $uri.'#getDocumentStates', 'rpc', 'encoded');
167 function getDocumentStates($session_ser) {
168 continue_session($session_ser);
171 $states = db_query_params ('select * from doc_states',
173 for ($row=0; $row<db_numrows($states); $row++) {
175 'state_id' => db_result($states, $row, 'stateid'),
176 'description' => db_result($states, $row, 'name')
183 // validateState is used to validate that the state_id that is provided is valid.
186 function validateState($state_id) {
187 $res = db_query_params ('SELECT name FROM doc_states WHERE stateid=$1',
189 if(db_numrows($res)==1) {
202 'session_ser' => 'xsd:string',
203 'group_id' => 'xsd:int',
204 'doc_group' => 'xsd:int',
205 'title' => 'xsd:string',
206 'description' => 'xsd:string',
207 'base64_contents' => 'xsd:string',
208 'filename' => 'xsd:string',
209 'file_url' => 'xsd:string'
211 array('addDocumentResponse' => 'xsd:int'),
212 $uri, $uri.'#addDocument', 'rpc', 'encoded'
215 function addDocument($session_ser, $group_id, $doc_group, $title, $description, $base64_contents, $filename, $file_url) {
216 continue_session($session_ser);
218 $g = group_get_object($group_id);
219 if (!$g || !is_object($g)) {
220 return new soap_fault('', 'addDocument', 'Could Not Get Project','Could Not Get Project');
221 } elseif ($g->isError()) {
222 return new soap_fault('', 'addDocument', $g->getErrorMessage(), $g->getErrorMessage());
225 $d = new Document($g);
226 if (!$d || !is_object($d)) {
227 return new soap_fault('', 'addDocument', 'Could Not create Document','Could Not create Document');
228 } elseif ($d->isError()) {
229 return new soap_fault('', 'addDocument', $d->getErrorMessage(), $d->getErrorMessage());
232 if ($base64_contents) {
233 $file = tempnam(forge_get_config('data_path'), 'tmp');
234 file_put_contents($file, base64_decode($base64_contents));
235 $uploaded_data_name=$filename;
236 } elseif ($file_url) {
238 $uploaded_data_name=$file_url;
239 $uploaded_data_type='URL';
242 if (!$d->create($uploaded_data_name, $uploaded_data_type, $file, $doc_group, $title, $description)) {
243 return new soap_fault('', 'addDocument', $d->getErrorMessage(), $d->getErrorMessage());
255 'session_ser' => 'xsd:string',
256 'group_id' => 'xsd:int',
257 'doc_group' => 'xsd:int',
258 'doc_id' => 'xsd:int',
259 'title' => 'xsd:string',
260 'description' => 'xsd:string',
261 'base64_contents' => 'xsd:string',
262 'filename' => 'xsd:string',
263 'file_url' => 'xsd:string',
264 'state_id' => 'xsd:int'
266 array('updateDocumentResponse' => 'xsd:boolean'),
267 $uri, $uri.'#updateDocument', 'rpc', 'encoded'
273 function updateDocument($session_ser, $group_id, $doc_group, $doc_id, $title, $description, $base64_contents, $filename, $file_url, $state_id) {
274 continue_session($session_ser);
276 $g = group_get_object($group_id);
277 if (!$g || !is_object($g)) {
278 return new soap_fault('', 'updateDocument', 'Could Not Get Project','Could Not Get Project');
279 } elseif ($g->isError()) {
280 return new soap_fault('', 'updateDocument', $g->getErrorMessage(), $g->getErrorMessage());
283 $d = new Document($g, $doc_id);
284 if (!$d || !is_object($d)) {
285 return new soap_fault('', 'updateDocument', 'Could Not create Document','Could Not create Document');
286 } elseif ($d->isError()) {
287 return new soap_fault('', 'updateDocument', $d->getErrorMessage(), $d->getErrorMessage());
291 if(!validateState($state_id)) {
292 return new soap_fault('', 'updateDocument', 'Invalid State ID','Invalid State ID');
295 $state_id=$d->getStateID();
299 $title=$d->getName();
303 $description=$d->getDescription();
306 if((!$base64_contents) && (!$file_url)) {
307 if((!$base64_contents) && (!$d->isURL())) {
308 $data = $d->getFileData();
309 $uploaded_data_name=$d->getFileName();
312 if((!$file_url) && ($d->isURL())) {
314 $uploaded_data_name=$d->getFileName();
315 $uploaded_data_type='URL';
318 } elseif($file_url) {
320 $uploaded_data_name=$file_url;
321 $uploaded_data_type='URL';
322 } elseif($base64_contents) {
323 $file = tempnam(forge_get_config('data_path'), 'tmp');
324 file_put_contents($file, base64_decode($base64_contents));
325 $uploaded_data_name=$filename;
328 if (!$d->update($uploaded_data_name, $uploaded_data_type, $file, $doc_group, $title, $description, $state_id)) {
329 return new soap_fault('', 'updateDocument', $d->getErrorMessage(), $d->getErrorMessage());
342 'session_ser' => 'xsd:string',
343 'group_id' => 'xsd:int',
344 'groupname' => 'xsd:string',
345 'parent_doc_group' => 'xsd:int'
347 array('addDocumentGroupResponse' => 'xsd:int'),
348 $uri, $uri.'#addDocumentGroup', 'rpc', 'encoded'
354 function addDocumentGroup($session_ser, $group_id, $groupname, $parent_doc_group) {
355 continue_session($session_ser);
357 $g = group_get_object($group_id);
358 if (!$g || !is_object($g)) {
359 return new soap_fault('', 'addDocumentGroup', 'Could Not Get Project','Could Not Get Project');
360 } elseif ($g->isError()) {
361 return new soap_fault('', 'addDocumentGroup', $g->getErrorMessage(), $g->getErrorMessage());
364 $dg = new DocumentGroup($g);
365 if (!$dg || !is_object($dg)) {
366 return new soap_fault('', 'addDocumentGroup', 'Could Not get Document Group','Could Not Get Document Group');
367 } elseif ($dg->isError()) {
368 return new soap_fault('', 'addDocumentGroup', $dg->getErrorMessage(), $dg->getErrorMessage());
370 if (!$dg->create($groupname, $parent_doc_group)) {
371 return new soap_fault('', 'addDocumentGroup', 'Could Not Create Document Group','Could Not Create Document Group');
378 //updateDocumentGroup
381 'updateDocumentGroup',
383 'session_ser' => 'xsd:string',
384 'group_id' => 'xsd:int',
385 'doc_group' => 'xsd:int',
386 'new_groupname' => 'xsd:string',
387 'new_parent_doc_group' => 'xsd:int'
389 array('updateDocumentGroupResponse' => 'xsd:boolean'),
390 $uri, $uri.'#updateDocumentGroup', 'rpc', 'encoded'
394 // updateDocumentGroup
396 function updateDocumentGroup($session_ser, $group_id, $doc_group, $new_groupname, $new_parent_doc_group) {
397 continue_session($session_ser);
399 $g = group_get_object($group_id);
400 if (!$g || !is_object($g)) {
401 return new soap_fault('', 'updateDocumentGroup', 'Could Not Get Project','Could Not Get Project');
402 } elseif ($g->isError()) {
403 return new soap_fault('', 'updateDocumentGroup', $g->getErrorMessage(), $g->getErrorMessage());
406 $dg = new DocumentGroup($g, $doc_group);
407 if (!$dg || !is_object($dg)) {
408 return new soap_fault('', 'updateDocumentGroup', 'Could Not get Document Group','Could Not Get Document Group');
409 } elseif ($dg->isError()) {
410 return new soap_fault('', 'updateDocumentGroup', $dg->getErrorMessage(), $dg->getErrorMessage());
413 if (!$dg->update($new_groupname, $new_parent_doc_group)) {
414 return new soap_fault('', 'updateDocumentGroup', $dg->getErrorMessage(), $dg->getErrorMessage());
426 'session_ser' => 'xsd:string',
427 'group_id' => 'xsd:int',
428 'doc_group' => 'xsd:int'
430 array('getDocumentsResponse' => 'tns:ArrayOfDocument'),
431 $uri, $uri.'#getDocuments', 'rpc', 'encoded');
437 function getDocuments($session_ser, $group_id, $doc_group_id) {
438 continue_session($session_ser);
439 $g = group_get_object($group_id);
440 if (!$g || !is_object($g)) {
441 return new soap_fault('', 'getDocuments', 'Could Not Get Project','Could Not Get Project');
442 } elseif ($g->isError()) {
443 return new soap_fault('', 'getDocuments', $g->getErrorMessage(), $g->getErrorMessage());
446 $df = new DocumentFactory($g);
447 if (!$df || !is_object($df)) {
448 return new soap_fault('', 'getDocuments', 'Could Not Get Document Factory','Could Not Get Document Factory');
449 } elseif ($df->isError()) {
450 return new soap_fault('', 'getDocuments', $df->getErrorMessage(), $df->getErrorMessage());
453 $df->setDocGroupID($doc_group_id);
455 return documents_to_soap($df->getDocuments());
460 // convert array of documents to soap data structure
462 function documents_to_soap($d_arr) {
464 for ($i=0; $i<count($d_arr); $i++) {
465 if ($d_arr[$i]->isError()) {
470 // Retrieving the documents details
472 if(count($d_arr[$i]) < 1) { continue; }
475 'docid' => $d_arr[$i]->data_array['docid'],
476 'doc_group' => $d_arr[$i]->data_array['doc_group'],
477 'title' => $d_arr[$i]->data_array['title'],
478 'description' => $d_arr[$i]->data_array['description'],
479 'stateid' => $d_arr[$i]->data_array['stateid'],
480 'filesize' => $d_arr[$i]->data_array['filesize']
493 'session_ser' => 'xsd:string',
494 'group_id' => 'xsd:int'
496 array('getDocumentGroupsResponse' => 'tns:ArrayOfDocumentGroup'),
497 $uri, $uri.'#getDocumentGroups', 'rpc', 'encoded');
502 function getDocumentGroups($session_ser, $group_id) {
503 continue_session($session_ser);
504 $g = group_get_object($group_id);
505 if (!$g || !is_object($g)) {
506 return new soap_fault('', 'getDocumentGroups', 'Could Not Get Project','Could Not Get Project');
507 } elseif ($g->isError()) {
508 return new soap_fault('', 'getDocumentGroups', $g->getErrorMessage(), $g->getErrorMessage());
511 $dgf = new DocumentGroupFactory($g);
512 if (!$dgf || !is_object($dgf)) {
513 return new soap_fault('', 'getDocumentGroups', 'Could Not Get Document Group Factory','Could Not Get Document Group Factory');
514 } elseif ($dgf->isError()) {
515 return new soap_fault('', 'getDocumentGroups', $dgf->getErrorMessage(), $dgf->getErrorMessage());
518 return documentsGroup_to_soap($dgf->getDocumentGroups());
522 // convert array of document group to soap data structure
524 function documentsGroup_to_soap($dg_arr) {
526 if (is_array($dg_arr) && !empty($dg_arr)) {
527 for ($i=0; $i<count($dg_arr); $i++) {
528 if ($dg_arr[$i]->isError()) {
532 'doc_group_id' => $dg_arr[$i]->getID(),
533 'parent_doc_group' => $dg_arr[$i]->getParentID(),
534 'groupname' => $dg_arr[$i]->getName()
548 'session_ser' => 'xsd:string',
549 'group_id' => 'xsd:int',
550 'doc_group' => 'xsd:int'
552 array('getDocumentGroupResponse' => 'tns:DocumentGroup'),
553 $uri, $uri.'#getDocumentGroup', 'rpc', 'encoded');
558 function getDocumentGroup($session_ser, $group_id, $doc_group) {
559 continue_session($session_ser);
560 $g = group_get_object($group_id);
561 if (!$g || !is_object($g)) {
562 return new soap_fault('', 'getDocumentGroup', 'Could Not Get Project','Could Not Get Project');
563 } elseif ($g->isError()) {
564 return new soap_fault('', 'getDocumentGroup', $g->getErrorMessage(), $g->getErrorMessage());
567 $dg = new DocumentGroup($g, $doc_group);
568 if (!$dg || !is_object($dg)) {
569 return new soap_fault('', 'getDocumentGroup', 'Could Not Get Document Group Factory','Could Not Get Document Group Factory');
570 } elseif ($dg->isError()) {
571 return new soap_fault('', 'getDocumentGroup', $dg->getErrorMessage(), $dg->getErrorMessage());
574 $documentGroup=array('doc_group_id' => $dg->getID(),
575 'parent_doc_group' => $dg->getParentID(),
576 'groupname' => $dg->getName());
578 return $documentGroup;
588 'session_ser' => 'xsd:string',
589 'group_id' => 'xsd:int',
590 'doc_id' => 'xsd:int'
592 array('getDocumentFilesResponse' => 'tns:ArrayOfDocumentFile'),
593 $uri, $uri.'#getDocuments', 'rpc', 'encoded');
598 function getDocumentFiles($session_ser, $group_id, $doc_id) {
599 continue_session($session_ser);
600 $g = group_get_object($group_id);
601 if (!$g || !is_object($g)) {
602 return new soap_fault('', 'GetDocumentFiles', 'Could Not Get Project','Could Not Get Project');
603 } elseif ($g->isError()) {
604 return new soap_fault('', 'GetDocumentFiles', $g->getErrorMessage(), $g->getErrorMessage());
607 $d=new Document($g, $doc_id);
608 if (!$d || !is_object($d)) {
609 return new soap_fault('', 'GetDocumentFiles', 'Could Not Get Document','Could Not Get Document');
610 } elseif ($d->isError()) {
611 return new soap_fault('', 'GetDocumentFiles', $d->getErrorMessage(), $d->getErrorMessage());
614 $return = (documentfiles_to_soap($d));
620 // convert array of document files to soap data structure
622 function documentfiles_to_soap($document) {
626 'filename' => $document->getFileName(),
627 'filetype' => $document->getFileType(),
628 'data' => base64_encode($document->getFileData())
638 array('session_ser' => 'xsd:string', 'group_id' => 'xsd:int', 'doc_id'=>'xsd:int'),
639 array('documentDeleteResponse' => 'xsd:boolean'),
640 $uri, $uri.'#documentDeleteResponse', 'rpc', 'encoded'
643 function documentDelete($session_ser, $group_id, $doc_id) {
644 continue_session($session_ser);
646 $g = group_get_object($group_id);
647 if (!$g || !is_object($g)) {
648 return new soap_fault('', 'documentDelete', 'Could Not Get Project','Could Not Get Project');
649 } elseif ($g->isError()) {
650 return new soap_fault('', 'documentDelete', $g->getErrorMessage(), $g->getErrorMessage());
653 $d= new Document($g, $doc_id);
654 if (!$d || !is_object($d)) {
655 return new soap_fault('', 'documentDelete', 'Could Not Get Document','Could Not Get Document');
656 } elseif ($d->isError()) {
657 return new soap_fault('', 'documentDelete', $d->getErrorMessage(), $d->getErrorMessage());
661 return new soap_fault('', 'documentDelete', $d->getErrorMessage(), $d->getErrorMessage());