File size: 13,399 Bytes
07c3cdd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
<?php

/**
 * class.pmTrSharepoint.pmFunctions.php
 *
 * ProcessMaker Open Source Edition
 * Copyright (C) 2004 - 2008 Colosa Inc.
 * *
 */
////////////////////////////////////////////////////
// pmTrSharepoint PM Functions
//
// Copyright (C) 2007 COLOSA
//
// License: LGPL, see LICENSE
////////////////////////////////////////////////////


/**
 * Sharepoint Triggers that allow ProcessMaker to perform common DWS actions
 * @class pmTrSharepoint
 *
 * @name Sharepoint DWS Triggers v. 0.1
 * @icon /images/triggers/sharepoint.gif
 * @className class.pmTrSharepoint.pmFunctions.php
 */

/**
 *
 * @method
 *
 * Create a DWS in Sharepoint server
 *
 * @name createDWS
 * @label Create a DWS in Sharepoint server
 *
 * @param string | $sharepointServer | Server name and port whre DWS wsdl exists, including protocol | http://server:port
 * @param string | $auth | Valid Auth string to connect to server | user:password
 * @param string | $name | Name of DWS
 * @param string | $users | Relevent User of DWS
 * @param string | $title | Title of DWS
 * @param string | $documents | Document that need to be attached to DWS
 *
 * @return string | $result | Response |
 *
 */
function createDWS ($sharepointServer, $auth, $name = "", $users = "", $title = "", $documents = "", $result = "")
{
    //print "Trigger: createDWS";
    require_once (PATH_CORE . 'classes' . PATH_SEP . 'triggers' . PATH_SEP . 'class.pmTrSharepoint.php');
    $pmTrSharepoint = new PmTrSharepointClass( $sharepointServer, $auth );
    $beforeResult = $pmTrSharepoint->createDWS( $name, $users, $title, $documents );
    return $beforeResult;
}

/**
 *
 * @method
 *
 * Delete a DWS in Sharepoint server
 *
 * @name deleteDWS
 * @label Delete a DWS in Sharepoint server
 *
 * @param string | $sharepointServer | Server name and port whre DWS wsdl exists, including protocol | http://server:port/_vti_bin/Dws.asmx?WSDL
 * @param string | $auth | Valid Auth string to connect to server | user:password
 * @param string | $dwsname | Name of DWS to be deleted
 *
 * @return string | $result | Response |
 *
 */
function deleteDWS ($sharepointServer, $auth, $dwsname)
{
    require_once (PATH_CORE . 'classes' . PATH_SEP . 'triggers' . PATH_SEP . 'class.pmTrSharepoint.php');
    $pmTrSharepoint = new PmTrSharepointClass( $sharepointServer, $auth );
    $beforeResult = $pmTrSharepoint->deleteDWS( $dwsname );
    $newResult = $beforeResult->DeleteDwsResult;
    if ($newResult == '<Result/>') {
        return "Successfully deleted the DWS";
    } else {
        return "Error in deleting the DWS";
    }

}

/**
 *
 * @method
 *
 * Create a folder in a DWS
 *
 * @name createFolderDWS
 * @label Create a folder in a DWS
 *
 * @param string | $sharepointServer | Server name and port whre DWS wsdl exists, including protocol | http://server:port/_vti_bin/Dws.asmx?WSDL
 * @param string | $auth | Valid Auth string to connect to server | user:password
 * @param string | $dwsname | Name of DWS
 * @param string | $dwsFolderName | Name of DWS folder
 *
 * @return string | $result | Response |
 *
 */
function createFolderDWS ($sharepointServer, $auth, $dwsname, $dwsFolderName)
{
    require_once (PATH_CORE . 'classes' . PATH_SEP . 'triggers' . PATH_SEP . 'class.pmTrSharepoint.php');
    $pmTrSharepoint = new PmTrSharepointClass( $sharepointServer, $auth );
    $result = $pmTrSharepoint->createFolderDWS( $dwsname, $dwsFolderName );
    var_dump( $result );
    $newResult = $result->CreateFolderResult;
    var_dump( $newResult );
    if (isset( $newResult )) {
        if ($newResult == '<Result/>') {
            return "Folder is created";
        } else {
            return "Folder could not be created";
        }
    }
}

/**
 *
 * @method
 *
 * Delete a DWS folder
 *
 * @name deleteFolderDWS
 * @label Delete a DWS folder
 *
 * @param string | $sharepointServer | Server name and port whre DWS wsdl exists, including protocol | http://server:port/_vti_bin/Dws.asmx?WSDL
 * @param string | $auth | Valid Auth string to connect to server | user:password
 * @param string | $dwsname | Name of DWS
 * @param string | $delDwsFolderName | Name of DWS folder to be deleted
 *
 * @return string | $result | Response |
 *
 */

function deleteFolderDWS ($sharepointServer, $auth, $dwsname, $folderName)
{
    require_once (PATH_CORE . 'classes' . PATH_SEP . 'triggers' . PATH_SEP . 'class.pmTrSharepoint.php');
    $pmTrSharepoint = new PmTrSharepointClass( $sharepointServer, $auth );
    $result = $pmTrSharepoint->deleteFolderDWS( $dwsname, $folderName );
    $newResult = $result->DeleteFolderResult;
    if (isset( $newResult )) {
        if ($newResult == '<Result/>') {
            return "Folder is deleted";
        } else {
            return "Folder could not be deleted";
        }
    }
}

/**
 *
 * @method
 *
 * Get DWS data
 *
 * @name getDWSData
 * @label Get DWS data
 *
 * @param string | $sharepointServer | Server name and port whre DWS wsdl exists, including protocol | http://server:port/_vti_bin/Dws.asmx?WSDL
 * @param string | $auth | Valid Auth string to connect to server | user:password
 * @param string | $newFileName | File Name
 * @param string | $dwsname | Name of DWS
 * @param string | $lastUpdate | LastUpdate
 *
 * @return string | $result | Response |
 *
 */
function getDWSData ($sharepointServer, $auth, $newFileName, $dwsname, $lastUpdate)
{
    require_once (PATH_CORE . 'classes' . PATH_SEP . 'triggers' . PATH_SEP . 'class.pmTrSharepoint.php');
    $pmTrSharepoint = new PmTrSharepointClass( $sharepointServer, $auth );
    $resultDWSData = $pmTrSharepoint->getDWSData( $newFileName, $dwsname, $lastUpdate );
    if ($resultDWSData) {
        return $resultDWSData;
    } else {
        return "There was some error while getting the DWS Data";
    }
}

/**
 *
 * @method
 *
 * Get DWS meta data
 *
 * @name getDWSMetaData
 * @label Get DWS meta data
 *
 * @param string | $sharepointServer | Server name and port whre DWS wsdl exists, including protocol | http://server:port/_vti_bin/Dws.asmx?WSDL
 * @param string | $auth | Valid Auth string to connect to server | user:password
 * @param string | $newFileName | File Name
 * @param string | $dwsname | Name of DWS
 * @param string | $id | ID
 *
 *
 * @return string | $result | Response |
 *
 */
function getDWSMetaData ($sharepointServer, $auth, $newFileName, $dwsname, $id)
{
    require_once (PATH_CORE . 'classes' . PATH_SEP . 'triggers' . PATH_SEP . 'class.pmTrSharepoint.php');
    $pmTrSharepoint = new PmTrSharepointClass( $sharepointServer, $auth );
    $result = $pmTrSharepoint->getDWSMetaData( $newFileName, $dwsname, $id );
    //$newResult = $result->GetDwsMetaDataResult;
    if (isset( $result )) {
        return $result;
    } else {
        return "Document workspace Meta-data not found";
    }

}

/**
 *
 * @method
 *
 * Copy/Upload Documents to DWS folder
 *
 * @name uploadDocumentDWS
 * @label Copy/Upload Documents to DWS folder
 *
 * @param string | $sharepointServer | Server name and port whre DWS wsdl exists, including protocol | http://server:port/_vti_bin/Dws.asmx?WSDL
 * @param string | $auth | Valid Auth string to connect to server | user:password
 * @param string | $dwsname | DWS name in which you want to Upload the Folder
 * @param string | $folderName | Folder Name, dont provide folder name in case upload is in "Shared Directory"
 * @param string | $sourceUrl | Absolute path of the file to upload
 * @param string | $filename | Name of the File to Upload
 *
 * @return string | $result | Response |
 *
 */
function uploadDocumentDWS ($sharepointServer, $auth, $dwsname, $folderName, $sourceUrl, $filename)
{
    require_once (PATH_CORE . 'classes' . PATH_SEP . 'triggers' . PATH_SEP . 'class.pmTrSharepoint.php');
    $pmTrSharepoint = new PmTrSharepointClass( $sharepointServer, $auth );
    $beforeResult = $pmTrSharepoint->uploadDocumentDWS( $dwsname, $folderName, $sourceUrl, $filename );

    return $beforeResult;
}

/**
 *
 * @method
 *
 * Download documents from DWS folder
 *
 * @name downloadDocumentDWS
 * @label Download DWS Documents
 *
 * @param string | $sharepointServer | Server name and port whre DWS wsdl exists, including protocol | http://server:port/_vti_bin/Dws.asmx?WSDL
 * @param string | $auth | Valid Auth string to connect to server | user:password
 * @param string | $dwsname | Name of DWS
 * @param string | $fileName | File to be downloaded
 * @param string | $fileLocation | Location to be downloaded into
 *
 * @return string | $result | Response |
 *
 */
function downloadDocumentDWS ($sharepointServer, $auth, $dwsname, $fileName, $fileLocation)
{
    require_once (PATH_CORE . 'classes' . PATH_SEP . 'triggers' . PATH_SEP . 'class.pmTrSharepoint.php');
    $pmTrSharepoint = new PmTrSharepointClass( $sharepointServer, $auth );
    $result = $pmTrSharepoint->downloadDocumentDWS( $dwsname, $fileName, $fileLocation );
    if (isset( $result )) {
        return "Document downloaded";
    } else {
        return "Document cannot be downloaded";
    }
}

/**
 *
 * @method
 *
 * Get DWS Folder items
 *
 * @name getDWSFolderItems
 * @label Get DWS Folder items
 *
 * @param string | $sharepointServer | Server name and port whre DWS wsdl exists, including protocol | http://server:port/_vti_bin/Dws.asmx?WSDL
 * @param string | $auth | Valid Auth string to connect to server | user:password
 * @param string | $dwsname | Name of the DWS
 * @param string | $strFolderUrl | Folder URL
 *
 * @return string | $result | Response |
 *
 */
function getDWSFolderItems ($sharepointServer, $auth, $dwsname, $strFolderUrl)
{
    require_once (PATH_CORE . 'classes' . PATH_SEP . 'triggers' . PATH_SEP . 'class.pmTrSharepoint.php');
    $pmTrSharepoint = new PmTrSharepointClass( $sharepointServer, $auth );
    $result = $pmTrSharepoint->getDWSFolderItems( $dwsname, $strFolderUrl );
    if (isset( $result )) {
        return $result;
    } else {
        return "Folder does not exist";
    }
}

/**
 *
 * @method
 *
 * Get DWS Document Versions
 *
 * @name getDWSDocumentVersions
 * @label Get DWS Document Versions
 *
 * @param string | $sharepointServer | Server name and port whre DWS wsdl exists, including protocol | http://server:port/_vti_bin/Dws.asmx?WSDL
 * @param string | $auth | Valid Auth string to connect to server | user:password
 * @param string | $newFileName | Name of New File
 * @param string | $dwsname | Name of DWS
 *
 * @return string | $result | Response |
 *
 */
function getDWSDocumentVersions ($sharepointServer, $auth, $newFileName, $dwsname)
{
    require_once (PATH_CORE . 'classes' . PATH_SEP . 'triggers' . PATH_SEP . 'class.pmTrSharepoint.php');
    $pmTrSharepoint = new PmTrSharepointClass( $sharepointServer, $auth );
    $result = $pmTrSharepoint->getDWSDocumentVersions( $newFileName, $dwsname );
    if (isset( $result->GetVersionsResult )) {
        /*
                         * Code to get the Document's Version/s
                         */
        $xml = $result->GetVersionsResult->any; // in Result we get string in Xml format
        $xmlNew = simplexml_load_string( $xml ); // used to parse string to xml
        $xmlArray = @G::json_decode( @G::json_encode( $xmlNew ), 1 ); // used to convert Objects to array
        $resultCount = count( $xmlArray['result'] );
        for ($i = 0; $i < $resultCount; $i ++) {
            $version[] = $xmlArray['result'][$i]['@attributes']['version'];
        }
        $serializeResult = serialize( $version ); // serializing the Array for Returning.
        return $serializeResult;
    } else {
        return "No version found";
    }
}

/**
 *
 * @method
 *
 * Delete DWS Document Version
 *
 * @name deleteDWSDocumentVersion
 * @label Delete DWS Document Version
 *
 * @param string | $sharepointServer | Server name and port whre DWS wsdl exists, including protocol | http://server:port/_vti_bin/Dws.asmx?WSDL
 * @param string | $auth | Valid Auth string to connect to server | user:password
 * @param string | $newFileName | Name of the file
 * @param string | $dwsname | Name of DWS
 * @param string | $versionNum | Version No.
 *
 * @return string | $result | Response |
 *
 */
function deleteDWSDocumentVersion ($sharepointServer, $auth, $newFileName, $dwsname, $versionNum)
{
    require_once (PATH_CORE . 'classes' . PATH_SEP . 'triggers' . PATH_SEP . 'class.pmTrSharepoint.php');
    $pmTrSharepoint = new PmTrSharepointClass( $sharepointServer, $auth );
    $result = $pmTrSharepoint->deleteDWSDocVersion( $newFileName, $dwsname, $versionNum );
    return $result;
}

/**
 *
 * @method
 *
 * Delete all DWS Document Versions
 *
 * @name deleteDWSAllDocumentVersion
 * @label Delete all DWS Document Versions
 *
 * @param string | $sharepointServer | Server name and port whre DWS wsdl exists, including protocol | http://server:port/_vti_bin/Dws.asmx?WSDL
 * @param string | $auth | Valid Auth string to connect to server | user:password
 * @param string | $newFileName | Name of File
 * @param string | $dwsname | Name of DWS
 *
 * @return string | $result | Response |
 *
 */
function deleteDWSAllDocumentVersion ($sharepointServer, $auth, $newFileName, $dwsname)
{
    require_once (PATH_CORE . 'classes' . PATH_SEP . 'triggers' . PATH_SEP . 'class.pmTrSharepoint.php');
    $pmTrSharepoint = new PmTrSharepointClass( $sharepointServer, $auth );
    $result = $pmTrSharepoint->deleteAllDWSDocVersion( $newFileName, $dwsname );
    return $result;
}