26if (!defined(
'NOCSRFCHECK')) {
27 define(
'NOCSRFCHECK',
'1');
29if (!defined(
'NOTOKENRENEWAL')) {
30 define(
'NOTOKENRENEWAL',
'1');
32if (!defined(
'NOREQUIREMENU')) {
33 define(
'NOREQUIREMENU',
'1');
35if (!defined(
'NOREQUIREHTML')) {
36 define(
'NOREQUIREHTML',
'1');
38if (!defined(
'NOREQUIREAJAX')) {
39 define(
'NOREQUIREAJAX',
'1');
41if (!defined(
"NOLOGIN")) {
42 define(
"NOLOGIN",
'1');
44if (!defined(
"NOSESSION")) {
45 define(
"NOSESSION",
'1');
48require
'../main.inc.php';
49require_once NUSOAP_PATH.
'/nusoap.php';
50require_once DOL_DOCUMENT_ROOT.
'/core/lib/ws.lib.php';
51require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
52require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
53require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
54require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
61dol_syslog(
"Call Dolibarr webservices interfaces");
67 $langs->load(
"admin");
68 dol_syslog(
"Call Dolibarr webservices interfaces with module webservices disabled");
69 print $langs->trans(
"WarningModuleNotActive",
'WebServices').
'.<br><br>';
70 print $langs->trans(
"ToActivateModule");
75$listofreferent = array(
77 'order' =>
'commande',
78 'invoice' =>
'facture',
79 'invoice_predefined' =>
'facture_rec',
80 'proposal_supplier' =>
'commande_fournisseur',
81 'order_supplier' =>
'commande_fournisseur',
82 'invoice_supplier' =>
'facture_fourn',
83 'contract' =>
'contrat',
84 'intervention' =>
'fichinter',
85 'trip' =>
'deplacement',
86 'expensereport' =>
'expensereport_det',
88 'agenda' =>
'actioncomm',
89 'project_task' =>
'projet_task',
93$server =
new nusoap_server();
94$server->soap_defencoding =
'UTF-8';
95$server->decode_utf8 =
false;
96$ns =
'http://www.dolibarr.org/ns/';
97$server->configureWSDL(
'WebServicesDolibarrOther', $ns);
98$server->wsdl->schemaTargetNamespace = $ns;
101$server->wsdl->addComplexType(
108 'dolibarrkey' => array(
'name' =>
'dolibarrkey',
'type' =>
'xsd:string'),
109 'sourceapplication' => array(
'name' =>
'sourceapplication',
'type' =>
'xsd:string'),
110 'login' => array(
'name' =>
'login',
'type' =>
'xsd:string'),
111 'password' => array(
'name' =>
'password',
'type' =>
'xsd:string'),
112 'entity' => array(
'name' =>
'entity',
'type' =>
'xsd:string'),
117$server->wsdl->addComplexType(
124 'result_code' => array(
'name' =>
'result_code',
'type' =>
'xsd:string'),
125 'result_label' => array(
'name' =>
'result_label',
'type' =>
'xsd:string'),
130$server->wsdl->addComplexType(
137 'id' => array(
'name' =>
'id',
'type' =>
'xsd:int'),
138 'user' => array(
'name' =>
'user',
'type' =>
'xsd:int'),
142$server->wsdl->addComplexType(
150 'name' =>
'elementsArray',
151 'type' =>
'tns:element',
153 'maxOccurs' =>
'unbounded'
158$project_elements = array();
159foreach ($listofreferent as $key => $label) {
160 $project_elements[$key] = array(
'name' => $key,
'type' =>
'tns:elementsArray');
162$server->wsdl->addComplexType(
172$project_fields = array(
173 'id' => array(
'name' =>
'id',
'type' =>
'xsd:string'),
174 'ref' => array(
'name' =>
'ref',
'type' =>
'xsd:string'),
175 'label' => array(
'name' =>
'label',
'type' =>
'xsd:string'),
176 'thirdparty_id' => array(
'name' =>
'thirdparty_id',
'type' =>
'xsd:int'),
177 'public' => array(
'name' =>
'public',
'type' =>
'xsd:int'),
178 'status' => array(
'name' =>
'status',
'type' =>
'xsd:int'),
179 'date_start' => array(
'name' =>
'date_start',
'type' =>
'xsd:date'),
180 'date_end' => array(
'name' =>
'date_end',
'type' =>
'xsd:date'),
181 'budget' => array(
'name' =>
'budget',
'type' =>
'xsd:int'),
182 'description' => array(
'name' =>
'description',
'type' =>
'xsd:string'),
183 'elements' => array(
'name' =>
'elements',
'type' =>
'tns:elements')
186$elementtype =
'project';
191$extrafields->fetch_name_optionals_label($elementtype,
true);
192$extrafield_array =
null;
193if (is_array($extrafields->attributes) && $extrafields->attributes[$elementtype][
'count'] > 0) {
194 $extrafield_array = array();
196if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label'])) {
197 foreach ($extrafields->attributes[$elementtype][
'label'] as $key => $label) {
199 $type = $extrafields->attributes[$elementtype][
'type'][$key];
200 if ($type ==
'date' || $type ==
'datetime') {
201 $type =
'xsd:dateTime';
203 $type =
'xsd:string';
205 $extrafield_array[
'options_'.$key] = array(
'name' =>
'options_'.$key,
'type' => $type);
208if (is_array($extrafield_array)) {
209 $project_fields = array_merge($project_fields, $extrafield_array);
212$server->wsdl->addComplexType(
225$styleuse =
'encoded';
232 array(
'authentication' =>
'tns:authentication',
'project' =>
'tns:project'),
234 array(
'result' =>
'tns:result',
'id' =>
'xsd:string',
'ref' =>
'xsd:string'),
236 $ns.
'#createProject',
239 'WS to create project'
246 array(
'authentication' =>
'tns:authentication',
'id' =>
'xsd:string',
'ref' =>
'xsd:string'),
248 array(
'result' =>
'tns:result',
'project' =>
'tns:project'),
268 dol_syslog(
"Function: createProject login=".$authentication[
'login']);
270 if ($authentication[
'entity']) {
271 $conf->entity = $authentication[
'entity'];
275 $objectresp = array();
281 if (empty($project[
'ref'])) {
284 $errorlabel =
"Name is mandatory.";
289 $fuser->loadRights();
291 if ($fuser->hasRight(
'projet',
'creer')) {
293 $newobject->ref = $project[
'ref'];
294 $newobject->title = $project[
'label'];
295 $newobject->socid = $project[
'thirdparty_id'];
296 $newobject->public = $project[
'public'];
297 $newobject->statut = $project[
'status'];
298 $newobject->date_start =
dol_stringtotime($project[
'date_start'],
'dayrfc');
300 $newobject->budget_amount = $project[
'budget'];
301 $newobject->description = $project[
'description'];
303 $elementtype =
'project';
308 $extrafields->fetch_name_optionals_label($elementtype,
true);
309 if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label'])) {
310 foreach ($extrafields->attributes[$elementtype][
'label'] as $key => $label) {
311 $key =
'options_'.$key;
312 $newobject->array_options[$key] = $project[$key];
318 $result = $newobject->create($fuser);
319 if (!$error && $result > 0) {
321 $result = $newobject->add_contact($fuser->id,
'PROJECTLEADER',
'internal');
331 $objectresp = array(
'result' => array(
'result_code' =>
'OK',
'result_label' =>
''),
'id' => $newobject->id,
'ref' => $newobject->ref);
336 $errorlabel = $newobject->error;
340 $errorcode =
'PERMISSION_DENIED';
341 $errorlabel =
'User does not have permission for this request';
346 $objectresp = array(
'result' => array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
364 dol_syslog(
"Function: getProject login=".$authentication[
'login'].
" id=".
$id.
" ref=".$ref);
366 if ($authentication[
'entity']) {
367 $conf->entity = $authentication[
'entity'];
371 $objectresp = array();
377 if (!$error && ((
$id && $ref))) {
379 $errorcode =
'BAD_PARAMETERS';
380 $errorlabel =
"Parameter id and ref can't be both provided. You must choose one or other but not both.";
384 $fuser->loadRights();
386 if ($fuser->hasRight(
'projet',
'lire')) {
388 $result = $project->fetch(
$id, $ref);
390 $project_result_fields = array(
391 'id' => $project->id,
392 'ref' => $project->ref,
393 'label' => $project->title,
394 'thirdparty_id' => $project->socid,
395 'public' => $project->public,
396 'status' => $project->statut,
397 'date_start' => $project->date_start ?
dol_print_date($project->date_start,
'dayrfc') :
'',
398 'date_end' => $project->date_end ?
dol_print_date($project->date_end,
'dayrfc') :
'',
399 'budget' => $project->budget_amount,
400 'description' => $project->description,
403 $elementtype =
'project';
407 $extrafields->fetch_name_optionals_label($elementtype,
true);
410 if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label'])) {
411 $project->fetch_optionals();
412 foreach ($extrafields->attributes[$elementtype][
'label'] as $key => $label) {
413 $project_result_fields = array_merge($project_result_fields, array(
'options_'.$key => $project->array_options[
'options_'.$key]));
418 global $listofreferent;
420 foreach ($listofreferent as $key => $tablename) {
421 $elements[$key] = array();
422 $element_array = $project->get_element_list($key, $tablename);
423 if (count($element_array) > 0 && is_array($element_array)) {
424 foreach ($element_array as $element) {
425 $tmp = explode(
'_', $element);
426 $idofelement = count($tmp) > 0 ? $tmp[0] :
"";
427 $idofelementuser = count($tmp) > 1 ? $tmp[1] :
"";
428 $elements[$key][] = array(
'id' => $idofelement,
'user' => $idofelementuser);
432 $project_result_fields[
'elements'] = $elements;
436 'result' => array(
'result_code' =>
'OK',
'result_label' =>
''),
437 'project' => $project_result_fields
441 $errorcode =
'NOT_FOUND';
442 $errorlabel =
'Object not found for id='.$id.
' nor ref='.$ref;
446 $errorcode =
'PERMISSION_DENIED';
447 $errorlabel =
'User does not have permission for this request';
452 $objectresp = array(
'result' => array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
459$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=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
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.