24if (!defined(
'NOCSRFCHECK')) {
25 define(
'NOCSRFCHECK',
'1');
27if (!defined(
'NOTOKENRENEWAL')) {
28 define(
'NOTOKENRENEWAL',
'1');
30if (!defined(
'NOREQUIREMENU')) {
31 define(
'NOREQUIREMENU',
'1');
33if (!defined(
'NOREQUIREHTML')) {
34 define(
'NOREQUIREHTML',
'1');
36if (!defined(
'NOREQUIREAJAX')) {
37 define(
'NOREQUIREAJAX',
'1');
39if (!defined(
"NOLOGIN")) {
40 define(
"NOLOGIN",
'1');
42if (!defined(
"NOSESSION")) {
43 define(
"NOSESSION",
'1');
46require
'../main.inc.php';
47require_once NUSOAP_PATH.
'/nusoap.php';
48require_once DOL_DOCUMENT_ROOT.
'/core/lib/ws.lib.php';
49require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
50require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
51require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
52require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
55dol_syslog(
"Call Dolibarr webservices interfaces");
61 $langs->load(
"admin");
62 dol_syslog(
"Call Dolibarr webservices interfaces with module webservices disabled");
63 print $langs->trans(
"WarningModuleNotActive",
'WebServices').
'.<br><br>';
64 print $langs->trans(
"ToActivateModule");
69$listofreferent = array(
71 'order' =>
'commande',
72 'invoice' =>
'facture',
73 'invoice_predefined' =>
'facture_rec',
74 'proposal_supplier' =>
'commande_fournisseur',
75 'order_supplier' =>
'commande_fournisseur',
76 'invoice_supplier' =>
'facture_fourn',
77 'contract' =>
'contrat',
78 'intervention' =>
'fichinter',
79 'trip' =>
'deplacement',
80 'expensereport' =>
'expensereport_det',
82 'agenda' =>
'actioncomm',
83 'project_task' =>
'projet_task',
87$server =
new nusoap_server();
88$server->soap_defencoding =
'UTF-8';
89$server->decode_utf8 =
false;
90$ns =
'http://www.dolibarr.org/ns/';
91$server->configureWSDL(
'WebServicesDolibarrOther', $ns);
92$server->wsdl->schemaTargetNamespace = $ns;
95$server->wsdl->addComplexType(
102 'dolibarrkey' => array(
'name'=>
'dolibarrkey',
'type'=>
'xsd:string'),
103 'sourceapplication' => array(
'name'=>
'sourceapplication',
'type'=>
'xsd:string'),
104 'login' => array(
'name'=>
'login',
'type'=>
'xsd:string'),
105 'password' => array(
'name'=>
'password',
'type'=>
'xsd:string'),
106 'entity' => array(
'name'=>
'entity',
'type'=>
'xsd:string'),
111$server->wsdl->addComplexType(
118 'result_code' => array(
'name'=>
'result_code',
'type'=>
'xsd:string'),
119 'result_label' => array(
'name'=>
'result_label',
'type'=>
'xsd:string'),
124$server->wsdl->addComplexType(
131 'id' => array(
'name'=>
'id',
'type'=>
'xsd:int'),
132 'user' => array(
'name'=>
'user',
'type'=>
'xsd:int'),
136$server->wsdl->addComplexType(
144 'name' =>
'elementsArray',
145 'type' =>
'tns:element',
147 'maxOccurs' =>
'unbounded'
152$project_elements = array();
153foreach ($listofreferent as $key => $label) {
154 $project_elements[$key] = array(
'name'=>$key,
'type'=>
'tns:elementsArray');
156$server->wsdl->addComplexType(
166$project_fields = array(
167 'id' => array(
'name'=>
'id',
'type'=>
'xsd:string'),
168 'ref' => array(
'name'=>
'ref',
'type'=>
'xsd:string'),
169 'label' => array(
'name'=>
'label',
'type'=>
'xsd:string'),
170 'thirdparty_id' => array(
'name'=>
'thirdparty_id',
'type'=>
'xsd:int'),
171 'public' => array(
'name'=>
'public',
'type'=>
'xsd:int'),
172 'status' => array(
'name'=>
'status',
'type'=>
'xsd:int'),
173 'date_start' => array(
'name'=>
'date_start',
'type'=>
'xsd:date'),
174 'date_end' => array(
'name'=>
'date_end',
'type'=>
'xsd:date'),
175 'budget' => array(
'name'=>
'budget',
'type'=>
'xsd:int'),
176 'description' => array(
'name'=>
'description',
'type'=>
'xsd:string'),
177 'elements' => array(
'name'=>
'elements',
'type'=>
'tns:elements')
180$elementtype =
'project';
185$extrafields->fetch_name_optionals_label($elementtype,
true);
186$extrafield_array =
null;
187if (is_array($extrafields) && count($extrafields) > 0) {
188 $extrafield_array = array();
190if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label'])) {
191 foreach ($extrafields->attributes[$elementtype][
'label'] as $key => $label) {
193 $type = $extrafields->attributes[$elementtype][
'type'][$key];
194 if ($type ==
'date' || $type ==
'datetime') {
195 $type =
'xsd:dateTime';
197 $type =
'xsd:string';
199 $extrafield_array[
'options_'.$key] = array(
'name'=>
'options_'.$key,
'type'=>$type);
202if (is_array($extrafield_array)) {
203 $project_fields = array_merge($project_fields, $extrafield_array);
206$server->wsdl->addComplexType(
219$styleuse =
'encoded';
226 array(
'authentication'=>
'tns:authentication',
'project'=>
'tns:project'),
228 array(
'result'=>
'tns:result',
'id'=>
'xsd:string',
'ref'=>
'xsd:string'),
230 $ns.
'#createProject',
233 'WS to create project'
240 array(
'authentication'=>
'tns:authentication',
'id'=>
'xsd:string',
'ref'=>
'xsd:string'),
242 array(
'result'=>
'tns:result',
'project'=>
'tns:project'),
262 dol_syslog(
"Function: createProject login=".$authentication[
'login']);
264 if ($authentication[
'entity']) {
265 $conf->entity = $authentication[
'entity'];
269 $objectresp = array();
275 if (empty($project[
'ref'])) {
278 $errorlabel =
"Name is mandatory.";
285 if ($fuser->hasRight(
'projet',
'creer')) {
287 $newobject->ref = $project[
'ref'];
288 $newobject->title = $project[
'label'];
289 $newobject->socid = $project[
'thirdparty_id'];
290 $newobject->public = $project[
'public'];
291 $newobject->statut = $project[
'status'];
292 $newobject->date_start =
dol_stringtotime($project[
'date_start'],
'dayrfc');
294 $newobject->budget_amount = $project[
'budget'];
295 $newobject->description = $project[
'description'];
297 $elementtype =
'project';
302 $extrafields->fetch_name_optionals_label($elementtype,
true);
303 if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label'])) {
304 foreach ($extrafields->attributes[$elementtype][
'label'] as $key => $label) {
305 $key =
'options_'.$key;
306 $newobject->array_options[$key] = $project[$key];
312 $result = $newobject->create($fuser);
313 if (!$error && $result > 0) {
315 $result = $newobject->add_contact($fuser->id,
'PROJECTLEADER',
'internal');
325 $objectresp = array(
'result'=>array(
'result_code'=>
'OK',
'result_label'=>
''),
'id'=>$newobject->id,
'ref'=>$newobject->ref);
330 $errorlabel = $newobject->error;
334 $errorcode =
'PERMISSION_DENIED';
335 $errorlabel =
'User does not have permission for this request';
340 $objectresp = array(
'result'=>array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
358 dol_syslog(
"Function: getProject login=".$authentication[
'login'].
" id=".$id.
" ref=".$ref);
360 if ($authentication[
'entity']) {
361 $conf->entity = $authentication[
'entity'];
365 $objectresp = array();
371 if (!$error && (($id && $ref))) {
373 $errorcode =
'BAD_PARAMETERS';
374 $errorlabel =
"Parameter id and ref can't be both provided. You must choose one or other but not both.";
380 if ($fuser->hasRight(
'projet',
'lire')) {
382 $result = $project->fetch($id, $ref);
384 $project_result_fields = array(
385 'id' => $project->id,
386 'ref' => $project->ref,
387 'label' => $project->title,
388 'thirdparty_id' => $project->socid,
389 'public' => $project->public,
390 'status' => $project->statut,
391 'date_start' => $project->date_start ?
dol_print_date($project->date_start,
'dayrfc') :
'',
392 'date_end' => $project->date_end ?
dol_print_date($project->date_end,
'dayrfc') :
'',
393 'budget' => $project->budget_amount,
394 'description' => $project->description,
397 $elementtype =
'project';
401 $extrafields->fetch_name_optionals_label($elementtype,
true);
404 if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label'])) {
405 $project->fetch_optionals();
406 foreach ($extrafields->attributes[$elementtype][
'label'] as $key => $label) {
407 $project_result_fields = array_merge($project_result_fields, array(
'options_'.$key => $project->array_options[
'options_'.$key]));
412 global $listofreferent;
414 foreach ($listofreferent as $key => $tablename) {
415 $elements[$key] = array();
416 $element_array = $project->get_element_list($key, $tablename);
417 if (count($element_array) > 0 && is_array($element_array)) {
418 foreach ($element_array as $element) {
419 $tmp = explode(
'_', $element);
420 $idofelement = count($tmp) > 0 ? $tmp[0] :
"";
421 $idofelementuser = count($tmp) > 1 ? $tmp[1] :
"";
422 $elements[$key][] = array(
'id' => $idofelement,
'user' => $idofelementuser);
426 $project_result_fields[
'elements'] = $elements;
430 'result'=>array(
'result_code'=>
'OK',
'result_label'=>
''),
431 'project'=>$project_result_fields
435 $errorcode =
'NOT_FOUND';
436 $errorlabel =
'Object not found for id='.$id.
' nor ref='.$ref;
440 $errorcode =
'PERMISSION_DENIED';
441 $errorlabel =
'User does not have permission for this request';
446 $objectresp = array(
'result'=>array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
453$server->service(file_get_contents(
"php://input"));
Class to manage projects.
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...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
createProject($authentication, $project)
Create project.
getProject($authentication, $id='', $ref='')
Get a project.
check_authentication($authentication, &$error, &$errorcode, &$errorlabel)
Check authentication array and set error, errorcode, errorlabel.