24 if (!defined(
"NOCSRFCHECK")) define(
"NOCSRFCHECK",
'1');
26 require
'../master.inc.php';
27 require_once NUSOAP_PATH.
'/nusoap.php';
28 require_once DOL_DOCUMENT_ROOT.
'/core/lib/ws.lib.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
30 require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
31 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
32 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
35 dol_syslog(
"Call Dolibarr webservices interfaces");
40 if (empty($conf->global->MAIN_MODULE_WEBSERVICES))
42 $langs->load(
"admin");
43 dol_syslog(
"Call Dolibarr webservices interfaces with module webservices disabled");
44 print $langs->trans(
"WarningModuleNotActive",
'WebServices').
'.<br><br>';
45 print $langs->trans(
"ToActivateModule");
50 $listofreferent = array(
52 'order' =>
'commande',
53 'invoice' =>
'facture',
54 'invoice_predefined' =>
'facture_rec',
55 'proposal_supplier' =>
'commande_fournisseur',
56 'order_supplier' =>
'commande_fournisseur',
57 'invoice_supplier' =>
'facture_fourn',
58 'contract' =>
'contrat',
59 'intervention' =>
'fichinter',
60 'trip' =>
'deplacement',
61 'expensereport' =>
'expensereport_det',
63 'agenda' =>
'actioncomm',
64 'project_task' =>
'projet_task',
68 $server =
new nusoap_server();
69 $server->soap_defencoding =
'UTF-8';
70 $server->decode_utf8 =
false;
71 $ns =
'http://www.dolibarr.org/ns/';
72 $server->configureWSDL(
'WebServicesDolibarrOther', $ns);
73 $server->wsdl->schemaTargetNamespace = $ns;
76 $server->wsdl->addComplexType(
83 'dolibarrkey' => array(
'name'=>
'dolibarrkey',
'type'=>
'xsd:string'),
84 'sourceapplication' => array(
'name'=>
'sourceapplication',
'type'=>
'xsd:string'),
85 'login' => array(
'name'=>
'login',
'type'=>
'xsd:string'),
86 'password' => array(
'name'=>
'password',
'type'=>
'xsd:string'),
87 'entity' => array(
'name'=>
'entity',
'type'=>
'xsd:string'),
92 $server->wsdl->addComplexType(
99 'result_code' => array(
'name'=>
'result_code',
'type'=>
'xsd:string'),
100 'result_label' => array(
'name'=>
'result_label',
'type'=>
'xsd:string'),
105 $server->wsdl->addComplexType(
112 'id' => array(
'name'=>
'id',
'type'=>
'xsd:int'),
113 'user' => array(
'name'=>
'user',
'type'=>
'xsd:int'),
117 $server->wsdl->addComplexType(
125 'name' =>
'elementsArray',
126 'type' =>
'tns:element',
128 'maxOccurs' =>
'unbounded'
133 $project_elements = array();
134 foreach ($listofreferent as $key => $label)
136 $project_elements[$key] = array(
'name'=>$key,
'type'=>
'tns:elementsArray');
138 $server->wsdl->addComplexType(
148 $project_fields = array(
149 'id' => array(
'name'=>
'id',
'type'=>
'xsd:string'),
150 'ref' => array(
'name'=>
'ref',
'type'=>
'xsd:string'),
151 'label' => array(
'name'=>
'label',
'type'=>
'xsd:string'),
152 'thirdparty_id' => array(
'name'=>
'thirdparty_id',
'type'=>
'xsd:int'),
153 'public' => array(
'name'=>
'public',
'type'=>
'xsd:int'),
154 'status' => array(
'name'=>
'status',
'type'=>
'xsd:int'),
155 'date_start' => array(
'name'=>
'date_start',
'type'=>
'xsd:date'),
156 'date_end' => array(
'name'=>
'date_end',
'type'=>
'xsd:date'),
157 'budget' => array(
'name'=>
'budget',
'type'=>
'xsd:int'),
158 'description' => array(
'name'=>
'description',
'type'=>
'xsd:string'),
159 'elements' => array(
'name'=>
'elements',
'type'=>
'tns:elements')
162 $elementtype =
'project';
167 $extrafields->fetch_name_optionals_label($elementtype,
true);
168 $extrafield_array = null;
169 if (is_array($extrafields) && count($extrafields) > 0) {
170 $extrafield_array = array();
172 if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label']))
174 foreach ($extrafields->attributes[$elementtype][
'label'] as $key=>$label)
177 $type = $extrafields->attributes[$elementtype][
'type'][$key];
178 if ($type ==
'date' || $type ==
'datetime') {$type =
'xsd:dateTime'; }
179 else {$type =
'xsd:string'; }
180 $extrafield_array[
'options_'.$key] = array(
'name'=>
'options_'.$key,
'type'=>$type);
183 if (is_array($extrafield_array)) $project_fields = array_merge($project_fields, $extrafield_array);
185 $server->wsdl->addComplexType(
198 $styleuse =
'encoded';
205 array(
'authentication'=>
'tns:authentication',
'project'=>
'tns:project'),
207 array(
'result'=>
'tns:result',
'id'=>
'xsd:string',
'ref'=>
'xsd:string'),
209 $ns.
'#createProject',
212 'WS to create project'
219 array(
'authentication'=>
'tns:authentication',
'id'=>
'xsd:string',
'ref'=>
'xsd:string'),
221 array(
'result'=>
'tns:result',
'project'=>
'tns:project'),
241 dol_syslog(
"Function: createProject login=".$authentication[
'login']);
243 if ($authentication[
'entity']) $conf->entity = $authentication[
'entity'];
246 $objectresp = array();
247 $errorcode =
''; $errorlabel =
'';
251 if (empty($project[
'ref']))
253 $error++; $errorcode =
'KO'; $errorlabel =
"Name is mandatory.";
261 if ($fuser->rights->projet->creer)
264 $newobject->ref = $project[
'ref'];
265 $newobject->title = $project[
'label'];
266 $newobject->socid = $project[
'thirdparty_id'];
267 $newobject->public = $project[
'public'];
268 $newobject->statut = $project[
'status'];
269 $newobject->date_start =
dol_stringtotime($project[
'date_start'],
'dayrfc');
271 $newobject->budget_amount = $project[
'budget'];
272 $newobject->description = $project[
'description'];
274 $elementtype =
'project';
279 $extrafields->fetch_name_optionals_label($elementtype,
true);
280 if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label']))
282 foreach ($extrafields->attributes[$elementtype][
'label'] as $key => $label)
284 $key =
'options_'.$key;
285 $newobject->array_options[$key] = $project[$key];
291 $result = $newobject->create($fuser);
292 if (!$error && $result > 0)
295 $result = $newobject->add_contact($fuser->id,
'PROJECTLEADER',
'internal');
308 $objectresp = array(
'result'=>array(
'result_code'=>
'OK',
'result_label'=>
''),
'id'=>$newobject->id,
'ref'=>$newobject->ref);
314 $errorlabel = $newobject->error;
319 $errorcode =
'PERMISSION_DENIED'; $errorlabel =
'User does not have permission for this request';
325 $objectresp = array(
'result'=>array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
343 dol_syslog(
"Function: getProject login=".$authentication[
'login'].
" id=".$id.
" ref=".$ref);
345 if ($authentication[
'entity']) $conf->entity = $authentication[
'entity'];
348 $objectresp = array();
349 $errorcode =
''; $errorlabel =
'';
353 if (!$error && (($id && $ref)))
356 $errorcode =
'BAD_PARAMETERS'; $errorlabel =
"Parameter id and ref can't be both provided. You must choose one or other but not both.";
363 if ($fuser->rights->projet->lire)
366 $result = $project->fetch($id, $ref);
369 $project_result_fields = array(
370 'id' => $project->id,
371 'ref' => $project->ref,
372 'label' => $project->title,
373 'thirdparty_id' => $project->socid,
374 'public' => $project->public,
375 'status' => $project->statut,
376 'date_start' => $project->date_start ?
dol_print_date($project->date_start,
'dayrfc') :
'',
377 'date_end' => $project->date_end ?
dol_print_date($project->date_end,
'dayrfc') :
'',
378 'budget' => $project->budget_amount,
379 'description' => $project->description,
382 $elementtype =
'project';
386 $extrafields->fetch_name_optionals_label($elementtype,
true);
389 if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label']))
391 $project->fetch_optionals();
392 foreach ($extrafields->attributes[$elementtype][
'label'] as $key => $label)
394 $project_result_fields = array_merge($project_result_fields, array(
'options_'.$key => $project->array_options[
'options_'.$key]));
399 global $listofreferent;
401 foreach ($listofreferent as $key => $tablename)
403 $elements[$key] = array();
404 $element_array = $project->get_element_list($key, $tablename);
405 if (count($element_array) > 0 && is_array($element_array))
407 foreach ($element_array as $element)
409 $tmp = explode(
'_', $element);
410 $idofelement = count($tmp) > 0 ? $tmp[0] :
"";
411 $idofelementuser = count($tmp) > 1 ? $tmp[1] :
"";
412 $elements[$key][] = array(
'id' => $idofelement,
'user' => $idofelementuser);
416 $project_result_fields[
'elements'] = $elements;
420 'result'=>array(
'result_code'=>
'OK',
'result_label'=>
''),
421 'project'=>$project_result_fields
426 $errorcode =
'NOT_FOUND'; $errorlabel =
'Object not found for id='.$id.
' nor ref='.$ref;
431 $errorcode =
'PERMISSION_DENIED'; $errorlabel =
'User does not have permission for this request';
437 $objectresp = array(
'result'=>array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
444 $server->service(file_get_contents(
"php://input"));
check_authentication($authentication, &$error, &$errorcode, &$errorlabel)
Check authentication array and set error, errorcode, errorlabel.
getProject($authentication, $id= '', $ref= '')
Get a project.
dol_stringtotime($string, $gm=1)
Convert a string date into a GM Timestamps date Warning: YYYY-MM-DDTHH:MM:SS+02:00 (RFC3339) is not s...
Class to manage projects.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
createProject($authentication, $project)
Create project.
print
Draft customers invoices.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).