3 * SOAP Documentation Include - this file contains wrapper functions for the SOAP interface
5 * Copyright 2004 (c) GForge, LLC
8 * This file is part of FusionForge. FusionForge is free software;
9 * you can redistribute it and/or modify it under the terms of the
10 * GNU General Public License as published by the Free Software
11 * Foundation; either version 2 of the Licence, or (at your option)
14 * FusionForge is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 require_once $gfcommon.'include/Error.class.php';
25 require_once $gfcommon.'docman/Document.class.php';
26 require_once $gfcommon.'docman/DocumentFactory.class.php';
27 require_once $gfcommon.'docman/DocumentGroup.class.php';
28 require_once $gfcommon.'docman/DocumentGroupFactory.class.php';
36 $server->wsdl->addComplexType(
43 'doc_group_id' => array('name'=>'doc_group_id', 'type' => 'xsd:int'),
44 'parent_doc_group' => array('name'=>'parent_doc_group', 'type' => 'xsd:int'),
45 'groupname' => array('name'=>'groupname', 'type' => 'xsd:string')
50 // DocumentGroup Array
53 $server->wsdl->addComplexType(
54 'ArrayOfDocumentGroup',
60 array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:DocumentGroup[]')),
68 $server->wsdl->addComplexType(
75 'docid' => array('name'=>'docid', 'type' => 'xsd:int'),
76 'doc_group' => array('name'=>'doc_group', 'type' => 'xsd:int'),
77 'title' => array('name'=>'title', 'type' => 'xsd:string'),
78 'description' => array('name'=>'description', 'type' => 'xsd:string'),
79 'stateid' => array('name'=>'stateid', 'type' => 'xsd:int'),
80 'language_id' => array('name'=>'language_id', 'type' => 'xsd:int'),
81 'filesize' => array('name'=>'filesize', 'type' => 'xsd:int')
89 $server->wsdl->addComplexType(
96 array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:Document[]')),
102 $server->wsdl->addComplexType(
109 'filename' => array('name'=>'filename', 'type' => 'xsd:string'),
110 'filetype' => array('name'=>'filetype', 'type' => 'xsd:string'),
111 'data' => array('name'=>'data', 'type' => 'xsd:string')
116 // DocumentFiles Array
119 $server->wsdl->addComplexType(
120 'ArrayOfDocumentFile',
126 array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:DocumentFile[]')),
134 $server->wsdl->addComplexType(
141 'state_id' => array('name'=>'state_id', 'type' => 'xsd:int'),
142 'description' => array('name'=>'description', 'type' => 'xsd:string')
147 // DocumentState Array
150 $server->wsdl->addComplexType(
151 'ArrayOfDocumentState',
157 array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:DocumentState[]')),
158 'tns:DocumentState');
168 'session_ser'=>'xsd:string'
170 array('getDocumentStatesResponse'=>'tns:ArrayOfDocumentState'),
171 $uri,$uri.'#getDocumentStates','rpc','encoded');
175 function &getDocumentStates($session_ser) {
176 continue_session($session_ser);
179 $states = db_query_params ('select * from doc_states',
181 for ($row=0; $row<db_numrows($states); $row++) {
183 'state_id'=>db_result($states,$row,'stateid'),
184 'description'=>db_result($states,$row,'name')
191 // validateState is used to validate that the state_id that is provided is valid.
194 function validateState($state_id){
195 $res = db_query_params ('SELECT name FROM doc_states WHERE stateid=$1',
197 if(db_numrows($res)==1){
209 $server->wsdl->addComplexType(
216 'language_id' => array('name'=>'language_id', 'type' => 'xsd:int'),
217 'description' => array('name'=>'description', 'type' => 'xsd:string')
223 // DocumentLanguage Array
226 $server->wsdl->addComplexType(
227 'ArrayOfDocumentLanguage',
233 array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:DocumentLanguage[]')),
234 'tns:DocumentLanguage');
237 //getDocumentLanguages
240 'getDocumentLanguages',
242 'session_ser'=>'xsd:string'
244 array('getDocumentLanguagesResponse'=>'tns:ArrayOfDocumentLanguage'),
245 $uri,$uri.'#getDocumentLanguages','rpc','encoded');
249 //getDocumentLanguages
251 function &getDocumentLanguages($session_ser) {
252 continue_session($session_ser);
255 $languages = db_query_params ('select language_id, classname from supported_languages',
257 for ($row=0; $row<db_numrows($languages); $row++) {
259 'language_id'=>db_result($languages,$row,'language_id'),
260 'description'=>db_result($languages,$row,'classname')
267 // validateLanguage is used to validate that the language_id that is provided is valid.
270 function validateLanguage($language_id){
271 $res = db_query_params ('SELECT classname FROM supported_languages WHERE language_id=$1',
272 array ($language_id));
273 if(db_numrows($res)==1){
286 'session_ser'=>'xsd:string',
287 'group_id'=>'xsd:int',
288 'doc_group'=>'xsd:int',
289 'title'=>'xsd:string',
290 'description'=>'xsd:string',
291 'language_id'=>'xsd:int',
292 'base64_contents'=>'xsd:string',
293 'filename'=>'xsd:string',
294 'file_url'=>'xsd:string'
296 array('addDocumentResponse'=>'xsd:int'),
297 $uri,$uri.'#addDocument','rpc','encoded'
300 function &addDocument($session_ser,$group_id,$doc_group,$title,$description,$language_id, $base64_contents,$filename,$file_url) {
301 continue_session($session_ser);
303 $g = group_get_object($group_id);
304 if (!$g || !is_object($g)) {
305 return new soap_fault ('','addDocument','Could Not Get Project','Could Not Get Project');
306 } elseif ($g->isError()) {
307 return new soap_fault ('','addDocument',$g->getErrorMessage(),$g->getErrorMessage());
310 $d = new Document($g);
311 if (!$d || !is_object($d)) {
312 return new soap_fault ('','addDocument','Could Not create Document','Could Not create Document');
313 } elseif ($d->isError()) {
314 return new soap_fault ('','addDocument',$d->getErrorMessage(),$d->getErrorMessage());
317 if(!validateLanguage($language_id)){
318 return new soap_fault ('','addDocument','Invalid Language ID','Invalid Language ID');
321 if ($base64_contents) {
322 $data = base64_decode($base64_contents);
324 $uploaded_data_name=$filename;
325 } elseif ($file_url) {
327 $uploaded_data_name=$file_url;
328 $uploaded_data_type='URL';
331 if (!$d->create($uploaded_data_name,$uploaded_data_type,$data,$doc_group,$title,$language_id,$description)) {
332 return new soap_fault ('','addDocument',$d->getErrorMessage(),$d->getErrorMessage());
345 'session_ser'=>'xsd:string',
346 'group_id'=>'xsd:int',
347 'doc_group'=>'xsd:int',
349 'title'=>'xsd:string',
350 'description'=>'xsd:string',
351 'language_id'=>'xsd:int',
352 'base64_contents'=>'xsd:string',
353 'filename'=>'xsd:string',
354 'file_url'=>'xsd:string',
355 'state_id'=>'xsd:int'
357 array('updateDocumentResponse'=>'xsd:boolean'),
358 $uri,$uri.'#updateDocument','rpc','encoded'
364 function &updateDocument($session_ser,$group_id,$doc_group,$doc_id,$title,$description,$language_id, $base64_contents,$filename,$file_url,$state_id) {
365 continue_session($session_ser);
367 $g = group_get_object($group_id);
368 if (!$g || !is_object($g)) {
369 return new soap_fault ('','updateDocument','Could Not Get Project','Could Not Get Project');
370 } elseif ($g->isError()) {
371 return new soap_fault ('','updateDocument',$g->getErrorMessage(),$g->getErrorMessage());
374 $d = new Document($g,$doc_id);
375 if (!$d || !is_object($d)) {
376 return new soap_fault ('','updateDocument','Could Not create Document','Could Not create Document');
377 } elseif ($d->isError()) {
378 return new soap_fault ('','updateDocument',$d->getErrorMessage(),$d->getErrorMessage());
383 if(!validateLanguage($language_id)){
384 return new soap_fault ('','updateDocument','Invalid Language ID','Invalid Language ID');
387 $language_id=$d->getLanguageID();
391 if(!validateState($state_id)){
392 return new soap_fault ('','updateDocument','Invalid State ID','Invalid State ID');
395 $state_id=$d->getStateID();
399 $title=$d->getName();
403 $description=$d->getDescription();
407 if((!$base64_contents) && (!$file_url)){
408 if((!$base64_contents) && (!$d->isURL())){
409 $data = $d->getFileData();
410 $uploaded_data_name=$d->getFileName();
413 if((!$file_url) && ($d->isURL())){
416 $uploaded_data_name=$d->getFileName();
417 $uploaded_data_type='URL';
422 $uploaded_data_name=$file_url;
423 $uploaded_data_type='URL';
424 }elseif($base64_contents){
425 $data = base64_decode($base64_contents);
427 $uploaded_data_name=$filename;
431 if (!$d->update($uploaded_data_name,$uploaded_data_type,$data,$doc_group,$title,$language_id,$description,$state_id)) {
432 return new soap_fault ('','updateDocument',$d->getErrorMessage(),$d->getErrorMessage());
448 'session_ser'=>'xsd:string',
449 'group_id'=>'xsd:int',
450 'groupname'=>'xsd:string',
451 'parent_doc_group'=>'xsd:int'
453 array('addDocumentGroupResponse'=>'xsd:int'),
454 $uri,$uri.'#addDocumentGroup','rpc','encoded'
460 function &addDocumentGroup($session_ser,$group_id,$groupname,$parent_doc_group) {
461 continue_session($session_ser);
463 $g = group_get_object($group_id);
464 if (!$g || !is_object($g)) {
465 return new soap_fault ('','addDocumentGroup','Could Not Get Project','Could Not Get Project');
466 } elseif ($g->isError()) {
467 return new soap_fault ('','addDocumentGroup',$g->getErrorMessage(),$g->getErrorMessage());
470 $dg = new DocumentGroup($g);
471 if (!$dg || !is_object($dg)) {
472 return new soap_fault ('','addDocumentGroup','Could Not get Document Group','Could Not Get Document Group');
473 }elseif ($dg->isError()) {
474 return new soap_fault ('','addDocumentGroup',$dg->getErrorMessage(),$dg->getErrorMessage());
476 if (!$dg->create($groupname, $parent_doc_group)) {
477 return new soap_fault ('','addDocumentGroup','Could Not Create Document Group','Could Not Create Document Group');
485 //updateDocumentGroup
488 'updateDocumentGroup',
490 'session_ser'=>'xsd:string',
491 'group_id'=>'xsd:int',
492 'doc_group'=>'xsd:int',
493 'new_groupname'=>'xsd:string',
494 'new_parent_doc_group'=>'xsd:int'
496 array('updateDocumentGroupResponse'=>'xsd:boolean'),
497 $uri,$uri.'#updateDocumentGroup','rpc','encoded'
501 // updateDocumentGroup
503 function &updateDocumentGroup($session_ser, $group_id, $doc_group, $new_groupname, $new_parent_doc_group) {
504 continue_session($session_ser);
506 $g = group_get_object($group_id);
507 if (!$g || !is_object($g)) {
508 return new soap_fault ('','updateDocumentGroup','Could Not Get Project','Could Not Get Project');
509 } elseif ($g->isError()) {
510 return new soap_fault ('','updateDocumentGroup',$g->getErrorMessage(),$g->getErrorMessage());
513 $dg = new DocumentGroup($g,$doc_group);
514 if (!$dg || !is_object($dg)) {
515 return new soap_fault ('','updateDocumentGroup','Could Not get Document Group','Could Not Get Document Group');
516 }elseif ($dg->isError()) {
517 return new soap_fault ('','updateDocumentGroup',$dg->getErrorMessage(),$dg->getErrorMessage());
520 if (!$dg->update($new_groupname, $new_parent_doc_group)) {
521 return new soap_fault ('','updateDocumentGroup',$dg->getErrorMessage(),$dg->getErrorMessage());
536 'session_ser'=>'xsd:string',
537 'group_id'=>'xsd:int',
538 'doc_group'=>'xsd:int'
540 array('getDocumentsResponse'=>'tns:ArrayOfDocument'),
541 $uri,$uri.'#getDocuments','rpc','encoded');
547 function &getDocuments($session_ser,$group_id,$doc_group_id) {
548 continue_session($session_ser);
549 $g = group_get_object($group_id);
550 if (!$g || !is_object($g)) {
551 return new soap_fault ('','getDocuments','Could Not Get Project','Could Not Get Project');
552 } elseif ($g->isError()) {
553 return new soap_fault ('','getDocuments',$g->getErrorMessage(),$g->getErrorMessage());
557 $df = new DocumentFactory($g);
558 if (!$df || !is_object($df)) {
559 return new soap_fault ('','getDocuments','Could Not Get Document Factory','Could Not Get Document Factory');
560 } elseif ($df->isError()) {
561 return new soap_fault ('','getDocuments',$df->getErrorMessage(),$df->getErrorMessage());
564 $df->setDocGroupID($doc_group_id);
566 return documents_to_soap($df->getDocuments());
572 // convert array of documents to soap data structure
574 function documents_to_soap($d_arr) {
576 for ($i=0; $i<count($d_arr); $i++) {
577 if ($d_arr[$i]->isError()) {
582 // Retrieving the documents details
585 if(count($d_arr[$i]) < 1) { continue; }
588 'docid'=>$d_arr[$i]->data_array['docid'],
589 'doc_group'=>$d_arr[$i]->data_array['doc_group'],
590 'title'=>$d_arr[$i]->data_array['title'],
591 'description'=>$d_arr[$i]->data_array['description'],
592 'stateid'=>$d_arr[$i]->data_array['stateid'],
593 'language_id'=>$d_arr[$i]->data_array['language_id'],
594 'filesize'=>$d_arr[$i]->data_array['filesize']
607 'session_ser'=>'xsd:string',
608 'group_id'=>'xsd:int'
610 array('getDocumentGroupsResponse'=>'tns:ArrayOfDocumentGroup'),
611 $uri,$uri.'#getDocumentGroups','rpc','encoded');
616 function &getDocumentGroups($session_ser,$group_id) {
617 continue_session($session_ser);
618 $g = group_get_object($group_id);
619 if (!$g || !is_object($g)) {
620 return new soap_fault ('','getDocumentGroups','Could Not Get Project','Could Not Get Project');
621 } elseif ($g->isError()) {
622 return new soap_fault ('','getDocumentGroups',$g->getErrorMessage(),$g->getErrorMessage());
626 $dgf = new DocumentGroupFactory($g);
627 if (!$dgf || !is_object($dgf)) {
628 return new soap_fault ('','getDocumentGroups','Could Not Get Document Group Factory','Could Not Get Document Group Factory');
629 } elseif ($dgf->isError()) {
630 return new soap_fault ('','getDocumentGroups',$dgf->getErrorMessage(),$dgf->getErrorMessage());
633 return documentsGroup_to_soap($dgf->getDocumentGroups());
638 // convert array of document group to soap data structure
640 function documentsGroup_to_soap($dg_arr) {
642 if (is_array($dg_arr) && count($dg_arr) > 0) {
643 for ($i=0; $i<count($dg_arr); $i++) {
644 if ($dg_arr[$i]->isError()) {
648 'doc_group_id'=>$dg_arr[$i]->getID(),
649 'parent_doc_group'=>$dg_arr[$i]->getParentID(),
650 'groupname'=>$dg_arr[$i]->getName()
669 'session_ser'=>'xsd:string',
670 'group_id'=>'xsd:int',
671 'doc_group'=>'xsd:int'
673 array('getDocumentGroupResponse'=>'tns:DocumentGroup'),
674 $uri,$uri.'#getDocumentGroup','rpc','encoded');
679 function &getDocumentGroup($session_ser,$group_id,$doc_group) {
680 continue_session($session_ser);
681 $g = group_get_object($group_id);
682 if (!$g || !is_object($g)) {
683 return new soap_fault ('','getDocumentGroup','Could Not Get Project','Could Not Get Project');
684 } elseif ($g->isError()) {
685 return new soap_fault ('','getDocumentGroup',$g->getErrorMessage(),$g->getErrorMessage());
689 $dg = new DocumentGroup($g,$doc_group);
690 if (!$dg || !is_object($dg)) {
691 return new soap_fault ('','getDocumentGroup','Could Not Get Document Group Factory','Could Not Get Document Group Factory');
692 } elseif ($dg->isError()) {
693 return new soap_fault ('','getDocumentGroup',$dg->getErrorMessage(),$dg->getErrorMessage());
697 $documentGroup=array('doc_group_id'=>$dg->getID(),
698 'parent_doc_group'=>$dg->getParentID(),
699 'groupname'=>$dg->getName());
702 return $documentGroup;
715 'session_ser'=>'xsd:string',
716 'group_id'=>'xsd:int',
719 array('getDocumentFilesResponse'=>'tns:ArrayOfDocumentFile'),
720 $uri,$uri.'#getDocuments','rpc','encoded');
725 function &getDocumentFiles($session_ser,$group_id,$doc_id) {
726 continue_session($session_ser);
727 $g = group_get_object($group_id);
728 if (!$g || !is_object($g)) {
729 return new soap_fault ('','GetDocumentFiles','Could Not Get Project','Could Not Get Project');
730 } elseif ($g->isError()) {
731 return new soap_fault ('','GetDocumentFiles',$g->getErrorMessage(),$g->getErrorMessage());
734 $d=new Document($g,$doc_id);
735 if (!$d || !is_object($d)) {
736 return new soap_fault ('','GetDocumentFiles','Could Not Get Document','Could Not Get Document');
737 } elseif ($d->isError()) {
738 return new soap_fault ('','GetDocumentFiles',$d->getErrorMessage(),$d->getErrorMessage());
741 $return = (documentfiles_to_soap($d));
748 // convert array of document files to soap data structure
750 function documentfiles_to_soap($document) {
754 'filename'=>$document->getFileName(),
755 'filetype'=>$document->getFileType(),
756 'data'=>base64_encode($document->getFileData())
767 array('session_ser'=>'xsd:string','group_id'=>'xsd:int','doc_id'=>'xsd:int'),
768 array('documentDeleteResponse'=>'xsd:boolean'),
769 $uri,$uri.'#documentDeleteResponse','rpc','encoded'
772 function documentDelete($session_ser,$group_id,$doc_id) {
773 continue_session($session_ser);
775 $g = group_get_object($group_id);
776 if (!$g || !is_object($g)) {
777 return new soap_fault ('','documentDelete','Could Not Get Project','Could Not Get Project');
778 } elseif ($g->isError()) {
779 return new soap_fault ('','documentDelete',$g->getErrorMessage(),$g->getErrorMessage());
782 $d= new Document($g,$doc_id);
783 if (!$d || !is_object($d)) {
784 return new soap_fault ('','documentDelete','Could Not Get Document','Could Not Get Document');
785 } elseif ($d->isError()) {
786 return new soap_fault ('','documentDelete',$d->getErrorMessage(),$d->getErrorMessage());
790 return new soap_fault ('','documentDelete',$d->getErrorMessage(),$d->getErrorMessage());