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");
60if (empty($conf->global->MAIN_MODULE_WEBSERVICES)) {
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();
270 $errorcode =
''; $errorlabel =
'';
274 if (empty($project[
'ref'])) {
275 $error++; $errorcode =
'KO'; $errorlabel =
"Name is mandatory.";
282 if ($fuser->rights->projet->creer) {
284 $newobject->ref = $project[
'ref'];
285 $newobject->title = $project[
'label'];
286 $newobject->socid = $project[
'thirdparty_id'];
287 $newobject->public = $project[
'public'];
288 $newobject->statut = $project[
'status'];
289 $newobject->date_start =
dol_stringtotime($project[
'date_start'],
'dayrfc');
291 $newobject->budget_amount = $project[
'budget'];
292 $newobject->description = $project[
'description'];
294 $elementtype =
'project';
299 $extrafields->fetch_name_optionals_label($elementtype,
true);
300 if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label'])) {
301 foreach ($extrafields->attributes[$elementtype][
'label'] as $key => $label) {
302 $key =
'options_'.$key;
303 $newobject->array_options[$key] = $project[$key];
309 $result = $newobject->create($fuser);
310 if (!$error && $result > 0) {
312 $result = $newobject->add_contact($fuser->id,
'PROJECTLEADER',
'internal');
322 $objectresp = array(
'result'=>array(
'result_code'=>
'OK',
'result_label'=>
''),
'id'=>$newobject->id,
'ref'=>$newobject->ref);
327 $errorlabel = $newobject->error;
331 $errorcode =
'PERMISSION_DENIED'; $errorlabel =
'User does not have permission for this request';
336 $objectresp = array(
'result'=>array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
354 dol_syslog(
"Function: getProject login=".$authentication[
'login'].
" id=".$id.
" ref=".$ref);
356 if ($authentication[
'entity']) {
357 $conf->entity = $authentication[
'entity'];
361 $objectresp = array();
362 $errorcode =
''; $errorlabel =
'';
366 if (!$error && (($id && $ref))) {
368 $errorcode =
'BAD_PARAMETERS'; $errorlabel =
"Parameter id and ref can't be both provided. You must choose one or other but not both.";
374 if ($fuser->rights->projet->lire) {
376 $result = $project->fetch($id, $ref);
378 $project_result_fields = array(
379 'id' => $project->id,
380 'ref' => $project->ref,
381 'label' => $project->title,
382 'thirdparty_id' => $project->socid,
383 'public' => $project->public,
384 'status' => $project->statut,
385 'date_start' => $project->date_start ?
dol_print_date($project->date_start,
'dayrfc') :
'',
386 'date_end' => $project->date_end ?
dol_print_date($project->date_end,
'dayrfc') :
'',
387 'budget' => $project->budget_amount,
388 'description' => $project->description,
391 $elementtype =
'project';
395 $extrafields->fetch_name_optionals_label($elementtype,
true);
398 if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label'])) {
399 $project->fetch_optionals();
400 foreach ($extrafields->attributes[$elementtype][
'label'] as $key => $label) {
401 $project_result_fields = array_merge($project_result_fields, array(
'options_'.$key => $project->array_options[
'options_'.$key]));
406 global $listofreferent;
408 foreach ($listofreferent as $key => $tablename) {
409 $elements[$key] = array();
410 $element_array = $project->get_element_list($key, $tablename);
411 if (count($element_array) > 0 && is_array($element_array)) {
412 foreach ($element_array as $element) {
413 $tmp = explode(
'_', $element);
414 $idofelement = count($tmp) > 0 ? $tmp[0] :
"";
415 $idofelementuser = count($tmp) > 1 ? $tmp[1] :
"";
416 $elements[$key][] = array(
'id' => $idofelement,
'user' => $idofelementuser);
420 $project_result_fields[
'elements'] = $elements;
424 'result'=>array(
'result_code'=>
'OK',
'result_label'=>
''),
425 'project'=>$project_result_fields
429 $errorcode =
'NOT_FOUND'; $errorlabel =
'Object not found for id='.$id.
' nor ref='.$ref;
433 $errorcode =
'PERMISSION_DENIED'; $errorlabel =
'User does not have permission for this request';
438 $objectresp = array(
'result'=>array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
445$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).
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.