Web Service Agenda/Actioncomm with extrafields
This commit is contained in:
parent
605d236ecc
commit
ff5f01646a
165
htdocs/webservices/demo_wsclient_actioncomm.php-NORUN
Executable file
165
htdocs/webservices/demo_wsclient_actioncomm.php-NORUN
Executable file
@ -0,0 +1,165 @@
|
||||
<?php
|
||||
/* Copyright (C) 2006-2010 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2012 Florian Henry <florian.henry@open-concept.pro>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file htdocs/webservices/demo_wsclient_actioncomm.php
|
||||
* \brief Demo page to make a client call to Dolibarr WebServices "server_other"
|
||||
*/
|
||||
|
||||
// This is to make Dolibarr working with Plesk
|
||||
set_include_path($_SERVER['DOCUMENT_ROOT'].'/htdocs');
|
||||
|
||||
require_once '../master.inc.php';
|
||||
require_once NUSOAP_PATH.'/nusoap.php'; // Include SOAP
|
||||
|
||||
$WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_actioncomm.php';
|
||||
//$WS_DOL_URL = 'http://localhost:8080/'; // If not a page, should end with /
|
||||
$WS_METHOD_GET = 'getActionComm';
|
||||
$WS_METHOD_CREATE = 'createActionComm';
|
||||
$WS_METHOD_GET_C_LIST = 'getListActionCommType';
|
||||
$ns='http://www.dolibarr.org/ns/';
|
||||
|
||||
//Chosse action to do
|
||||
//$action='get';
|
||||
//$action='getlist';
|
||||
$action='create';
|
||||
|
||||
|
||||
// Set the WebService URL
|
||||
dol_syslog("Create nusoap_actioncomm for URL=".$WS_DOL_URL);
|
||||
$soapclient = new nusoap_client($WS_DOL_URL);
|
||||
if ($soapclient)
|
||||
{
|
||||
$soapclient->soap_defencoding='UTF-8';
|
||||
$soapclient->decodeUTF8(false);
|
||||
}
|
||||
|
||||
// Call the WebService method and store its result in $result.
|
||||
$authentication=array(
|
||||
'dolibarrkey'=>$conf->global->WEBSERVICES_KEY,
|
||||
'sourceapplication'=>'DEMO',
|
||||
'login'=>'admin_dolibarDev',
|
||||
'password'=>'homedread',
|
||||
'entity'=>'1');
|
||||
|
||||
|
||||
// Test URL
|
||||
if ($action=='get')
|
||||
{
|
||||
$WS_METHOD=$WS_METHOD_GET;
|
||||
$parameters = array('authentication'=>$authentication,'id'=>1);
|
||||
dol_syslog("Call method ".$WS_METHOD_GET);
|
||||
$result = $soapclient->call($WS_METHOD_GET,$parameters,$ns,'');
|
||||
if (! $result)
|
||||
{
|
||||
print $soapclient->error_str;
|
||||
print "<br>\n\n";
|
||||
print $soapclient->request;
|
||||
print "<br>\n\n";
|
||||
print $soapclient->response;
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Test URL
|
||||
if ($action=='getlist')
|
||||
{
|
||||
$WS_METHOD=$WS_METHOD_GET_C_LIST;
|
||||
$parameters = array('authentication'=>$authentication);
|
||||
dol_syslog("Call method ".$WS_METHOD_GET_C_LIST);
|
||||
$result = $soapclient->call($WS_METHOD_GET_C_LIST,$parameters,$ns,'');
|
||||
if (! $result)
|
||||
{
|
||||
print $soapclient->error_str;
|
||||
print "<br>\n\n";
|
||||
print $soapclient->request;
|
||||
print "<br>\n\n";
|
||||
print $soapclient->response;
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
// Test URL
|
||||
if ($action=='create')
|
||||
{
|
||||
$WS_METHOD=$WS_METHOD_CREATE;
|
||||
$new=array(
|
||||
'datep'=>dol_mktime(13, 30, 00, 12, 16, 2012),
|
||||
'datef'=>dol_mktime(15, 30, 00, 12, 16, 2012),
|
||||
'type_code'=>'AC_RDV',
|
||||
'socid'=>'1',
|
||||
'projectid'=>'',
|
||||
'note'=>'This is note',
|
||||
'contactid'=>'',
|
||||
'usertodo'=>'1',
|
||||
'userdone'=>'1',
|
||||
'label'=>'Ceci est les titre de l\'envenement',
|
||||
'percentage'=>'100',
|
||||
'location'=>'Location1'
|
||||
);
|
||||
|
||||
|
||||
$parameters = array('authentication'=>$authentication,'actioncomm'=>$new);
|
||||
dol_syslog("Call method ".$WS_METHOD_CREATE);
|
||||
$result = $soapclient->call($WS_METHOD_CREATE,$parameters,$ns,'');
|
||||
if (! $result)
|
||||
{
|
||||
print $soapclient->error_str;
|
||||
print "<br>\n\n";
|
||||
print $soapclient->request;
|
||||
print "<br>\n\n";
|
||||
print $soapclient->response;
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* View
|
||||
*/
|
||||
|
||||
header("Content-type: text/html; charset=utf8");
|
||||
print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">'."\n";
|
||||
echo '<html>'."\n";
|
||||
echo '<head>';
|
||||
echo '<title>WebService Test: '.$WS_METHOD.'</title>';
|
||||
echo '</head>'."\n";
|
||||
|
||||
echo '<body>'."\n";
|
||||
echo 'NUSOAP_PATH='.NUSOAP_PATH.'<br>';
|
||||
|
||||
echo "<h2>Request:</h2>";
|
||||
echo '<h4>Function</h4>';
|
||||
echo $WS_METHOD;
|
||||
echo '<h4>SOAP Message</h4>';
|
||||
echo '<pre>' . htmlspecialchars($soapclient->request, ENT_QUOTES) . '</pre>';
|
||||
|
||||
echo '<hr>';
|
||||
|
||||
echo "<h2>Response:</h2>";
|
||||
echo '<h4>Result</h4>';
|
||||
echo '<pre>';
|
||||
print_r($result);
|
||||
echo '</pre>';
|
||||
echo '<h4>SOAP Message</h4>';
|
||||
echo '<pre>' . htmlspecialchars($soapclient->response, ENT_QUOTES) . '</pre>';
|
||||
|
||||
echo '</body>'."\n";;
|
||||
echo '</html>'."\n";;
|
||||
?>
|
||||
481
htdocs/webservices/server_actioncomm.php
Normal file
481
htdocs/webservices/server_actioncomm.php
Normal file
@ -0,0 +1,481 @@
|
||||
<?php
|
||||
/* Copyright (C) 2006-2011 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2012 Florian Henry <florian.henry@open-concept.pro>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file htdocs/webservices/server_actioncomm.php
|
||||
* \brief File that is entry point to call Dolibarr WebServices
|
||||
* \version $Id: server_actioncomm.php,v 1.7 2010/12/19 11:49:37 eldy Exp $
|
||||
*/
|
||||
|
||||
// This is to make Dolibarr working with Plesk
|
||||
set_include_path($_SERVER['DOCUMENT_ROOT'].'/htdocs');
|
||||
|
||||
require_once("../master.inc.php");
|
||||
require_once(NUSOAP_PATH.'/nusoap.php'); // Include SOAP
|
||||
require_once(DOL_DOCUMENT_ROOT."/core/lib/ws.lib.php");
|
||||
|
||||
require_once(DOL_DOCUMENT_ROOT."/comm/action/class/actioncomm.class.php");
|
||||
require_once(DOL_DOCUMENT_ROOT."/comm/action/class/cactioncomm.class.php");
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
|
||||
|
||||
|
||||
dol_syslog("Call ActionComm webservices interfaces");
|
||||
|
||||
// Enable and test if module web services is enabled
|
||||
if (empty($conf->global->MAIN_MODULE_WEBSERVICES))
|
||||
{
|
||||
$langs->load("admin");
|
||||
dol_syslog("Call Dolibarr webservices interfaces with module webservices disabled");
|
||||
print $langs->trans("WarningModuleNotActive",'WebServices').'.<br><br>';
|
||||
print $langs->trans("ToActivateModule");
|
||||
exit;
|
||||
}
|
||||
|
||||
// Create the soap Object
|
||||
$server = new nusoap_server();
|
||||
$server->soap_defencoding='UTF-8';
|
||||
$server->decode_utf8=false;
|
||||
$ns='http://www.dolibarr.org/ns/';
|
||||
$server->configureWSDL('WebServicesDolibarrActionComm',$ns);
|
||||
$server->wsdl->schemaTargetNamespace=$ns;
|
||||
|
||||
|
||||
// Define WSDL Authentication object
|
||||
$server->wsdl->addComplexType(
|
||||
'authentication',
|
||||
'complexType',
|
||||
'struct',
|
||||
'all',
|
||||
'',
|
||||
array(
|
||||
'dolibarrkey' => array('name'=>'dolibarrkey','type'=>'xsd:string'),
|
||||
'sourceapplication' => array('name'=>'sourceapplication','type'=>'xsd:string'),
|
||||
'login' => array('name'=>'login','type'=>'xsd:string'),
|
||||
'password' => array('name'=>'password','type'=>'xsd:string'),
|
||||
'entity' => array('name'=>'entity','type'=>'xsd:string'),
|
||||
)
|
||||
);
|
||||
|
||||
// Define WSDL Return object
|
||||
$server->wsdl->addComplexType(
|
||||
'result',
|
||||
'complexType',
|
||||
'struct',
|
||||
'all',
|
||||
'',
|
||||
array(
|
||||
'result_code' => array('name'=>'result_code','type'=>'xsd:string'),
|
||||
'result_label' => array('name'=>'result_label','type'=>'xsd:string'),
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
$actioncomm_fields= array(
|
||||
'id' => array('name'=>'id','type'=>'xsd:string'),
|
||||
'ref' => array('name'=>'ref','type'=>'xsd:string'),
|
||||
'ref_ext' => array('name'=>'ref_ext','type'=>'xsd:string'),
|
||||
'type_id' => array('name'=>'type_id','type'=>'xsd:string'),
|
||||
'type_code' => array('name'=>'type_code','type'=>'xsd:string'),
|
||||
'type' => array('name'=>'type','type'=>'xsd:string'),
|
||||
'label' => array('name'=>'label','type'=>'xsd:string'),
|
||||
'datep' => array('name'=>'datep','type'=>'xsd:dateTime'),
|
||||
'datef' => array('name'=>'datef','type'=>'xsd:dateTime'),
|
||||
'datec' => array('name'=>'datec','type'=>'xsd:dateTime'),
|
||||
'datem' => array('name'=>'datem','type'=>'xsd:dateTime'),
|
||||
'note' => array('name'=>'note','type'=>'xsd:string'),
|
||||
'percentage' => array('name'=>'percentage','type'=>'xsd:string'),
|
||||
'author' => array('name'=>'author','type'=>'xsd:string'),
|
||||
'usermod' => array('name'=>'usermod','type'=>'xsd:string'),
|
||||
'usertodo' => array('name'=>'usertodo','type'=>'xsd:string'),
|
||||
'userdone' => array('name'=>'userdone','type'=>'xsd:string'),
|
||||
'priority' => array('name'=>'priority','type'=>'xsd:string'),
|
||||
'fulldayevent' => array('name'=>'fulldayevent','type'=>'xsd:string'),
|
||||
'location' => array('name'=>'location','type'=>'xsd:string'),
|
||||
'socid' => array('name'=>'socid','type'=>'xsd:string'),
|
||||
'contactid' => array('name'=>'contactid','type'=>'xsd:string'),
|
||||
'projectid' => array('name'=>'projectid','type'=>'xsd:string'),
|
||||
'fk_element' => array('name'=>'fk_element','type'=>'xsd:string'),
|
||||
'elementtype' => array('name'=>'elementtype','type'=>'xsd:string'));
|
||||
|
||||
//Retreive all extrafield for actioncomm
|
||||
// fetch optionals attributes and labels
|
||||
$extrafields=new ExtraFields($db);
|
||||
$extralabels=$extrafields->fetch_name_optionals_label('actioncomm');
|
||||
if (count($extrafields)>0) {
|
||||
$extrafield_array = array();
|
||||
}
|
||||
foreach($extrafields->attribute_label as $key=>$label)
|
||||
{
|
||||
$type =$extrafields->attribute_type[$key];
|
||||
if ($type=='date' || $type=='datetime') {$type='xsd:dateTime';}
|
||||
else {$type='xsd:string';}
|
||||
|
||||
$extrafield_array['options_'.$key]=array('name'=>'options_'.$key,'type'=>$type);
|
||||
}
|
||||
|
||||
$actioncomm_fields=array_merge($actioncomm_fields,$extrafield_array);
|
||||
|
||||
// Define other specific objects
|
||||
$server->wsdl->addComplexType(
|
||||
'actioncomm',
|
||||
'complexType',
|
||||
'struct',
|
||||
'all',
|
||||
'',
|
||||
$actioncomm_fields
|
||||
);
|
||||
|
||||
|
||||
$server->wsdl->addComplexType(
|
||||
'actioncommtype',
|
||||
'complexType',
|
||||
'array',
|
||||
'sequence',
|
||||
'',
|
||||
array(
|
||||
'code' => array('name'=>'code','type'=>'xsd:string'),
|
||||
'libelle' => array('name'=>'libelle','type'=>'xsd:string')
|
||||
)
|
||||
);
|
||||
|
||||
$server->wsdl->addComplexType(
|
||||
'actioncommtypes',
|
||||
'complexType',
|
||||
'array',
|
||||
'sequence',
|
||||
'',
|
||||
array(
|
||||
'actioncommtype' => array(
|
||||
'name' => 'actioncommtype',
|
||||
'type' => 'tns:actioncommtype',
|
||||
'minOccurs' => '0',
|
||||
'maxOccurs' => 'unbounded'
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
// 5 styles: RPC/encoded, RPC/literal, Document/encoded (not WS-I compliant), Document/literal, Document/literal wrapped
|
||||
// Style merely dictates how to translate a WSDL binding to a SOAP message. Nothing more. You can use either style with any programming model.
|
||||
// http://www.ibm.com/developerworks/webservices/library/ws-whichwsdl/
|
||||
$styledoc='rpc'; // rpc/document (document is an extend into SOAP 1.0 to support unstructured messages)
|
||||
$styleuse='encoded'; // encoded/literal/literal wrapped
|
||||
// Better choice is document/literal wrapped but literal wrapped not supported by nusoap.
|
||||
|
||||
|
||||
// Register WSDL
|
||||
$server->register(
|
||||
'getListActionCommType',
|
||||
// Entry values
|
||||
array('authentication'=>'tns:authentication'),
|
||||
// Exit values
|
||||
array('result'=>'tns:result','actioncommtypes'=>'tns:actioncommtypes'),
|
||||
$ns,
|
||||
$ns.'#getListActionCommType',
|
||||
$styledoc,
|
||||
$styleuse,
|
||||
'WS to get actioncommType'
|
||||
);
|
||||
|
||||
// Register WSDL
|
||||
$server->register(
|
||||
'getActionComm',
|
||||
// Entry values
|
||||
array('authentication'=>'tns:authentication','id'=>'xsd:string'),
|
||||
// Exit values
|
||||
array('result'=>'tns:result','actioncomm'=>'tns:actioncomm'),
|
||||
$ns,
|
||||
$ns.'#getActionComm',
|
||||
$styledoc,
|
||||
$styleuse,
|
||||
'WS to get actioncomm'
|
||||
);
|
||||
|
||||
// Register WSDL
|
||||
$server->register(
|
||||
'createActionComm',
|
||||
// Entry values
|
||||
array('authentication'=>'tns:authentication','actioncomm'=>'tns:actioncomm'),
|
||||
// Exit values
|
||||
array('result'=>'tns:result','id'=>'xsd:string'),
|
||||
$ns,
|
||||
$ns.'#createActionComm',
|
||||
$styledoc,
|
||||
$styleuse,
|
||||
'WS to create a actioncomm'
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get ActionComm
|
||||
*
|
||||
* @param array $authentication Array of authentication information
|
||||
* @param int $id Id of object
|
||||
* @param string $ref Ref of object
|
||||
* @param ref_ext $ref_ext Ref external of object
|
||||
* @return mixed
|
||||
*/
|
||||
function getActionComm($authentication,$id)
|
||||
{
|
||||
global $db,$conf,$langs;
|
||||
|
||||
dol_syslog("Function: getActionComm login=".$authentication['login']." id=".$id);
|
||||
|
||||
if ($authentication['entity']) $conf->entity=$authentication['entity'];
|
||||
|
||||
// Init and check authentication
|
||||
$objectresp=array();
|
||||
$errorcode='';$errorlabel='';
|
||||
$error=0;
|
||||
$fuser=check_authentication($authentication,$error,$errorcode,$errorlabel);
|
||||
// Check parameters
|
||||
if ($error || (! $id))
|
||||
{
|
||||
$error++;
|
||||
$errorcode='BAD_PARAMETERS'; $errorlabel="Parameter id, ref and ref_ext can't be both provided. You must choose one or other but not both.";
|
||||
}
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
$fuser->getrights();
|
||||
|
||||
if ($fuser->rights->agenda->allactions->read)
|
||||
{
|
||||
$actioncomm=new ActionComm($db);
|
||||
$result=$actioncomm->fetch($id);
|
||||
if ($result > 0)
|
||||
{
|
||||
|
||||
$actioncomm_result_fields=array(
|
||||
'id' => $actioncomm->id,
|
||||
'ref'=> $actioncomm->ref,
|
||||
'ref_ext'=> $actioncomm->ref_ext,
|
||||
'type_id'=> $actioncomm->type_id,
|
||||
'type_code'=> $actioncomm->type_code,
|
||||
'type'=> $actioncomm->type,
|
||||
'label'=> $actioncomm->label,
|
||||
'datep'=> dol_print_date($actioncomm->datep,'dayhourrfc'),
|
||||
'datef'=> dol_print_date($actioncomm->datef,'dayhourrfc'),
|
||||
'datec'=> dol_print_date($actioncomm->datec,'dayhourrfc'),
|
||||
'datem'=> dol_print_date($actioncomm->datem,'dayhourrfc'),
|
||||
'note'=> $actioncomm->note,
|
||||
'percentage'=> $actioncomm->percentage,
|
||||
'author'=> $actioncomm->author->id,
|
||||
'usermod'=> $actioncomm->usermod->id,
|
||||
'usertodo'=> $actioncomm->usertodo->id,
|
||||
'userdone'=> $actioncomm->userdone->id,
|
||||
'priority'=> $actioncomm->priority,
|
||||
'fulldayevent'=> $actioncomm->fulldayevent,
|
||||
'location'=> $actioncomm->location,
|
||||
'socid'=> $actioncomm->societe->id,
|
||||
'contactid'=> $actioncomm->contact->id,
|
||||
'projectid'=> $actioncomm->fk_project,
|
||||
'fk_element'=> $actioncomm->fk_element,
|
||||
'elementtype'=> $actioncomm->elementtype);
|
||||
|
||||
//Retreive all extrafield for actioncomm
|
||||
// fetch optionals attributes and labels
|
||||
$extrafields=new ExtraFields($db);
|
||||
$extralabels=$extrafields->fetch_name_optionals_label('actioncomm');
|
||||
//Get extrafield values
|
||||
$actioncomm->fetch_optionals($actioncomm->id,$extralabels);
|
||||
|
||||
foreach($extrafields->attribute_label as $key=>$label)
|
||||
{
|
||||
$actioncomm_result_fields=array_merge($actioncomm_result_fields,array('options_'.$key => $actioncomm->array_options['options_'.$key]));
|
||||
}
|
||||
|
||||
// Create
|
||||
$objectresp = array(
|
||||
'result'=>array('result_code'=>'OK', 'result_label'=>''),
|
||||
'actioncomm'=>$actioncomm_result_fields);
|
||||
}
|
||||
else
|
||||
{
|
||||
$error++;
|
||||
$errorcode='NOT_FOUND'; $errorlabel='Object not found for id='.$id.' nor ref='.$ref.' nor ref_ext='.$ref_ext;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$error++;
|
||||
$errorcode='PERMISSION_DENIED'; $errorlabel='User does not have permission for this request';
|
||||
}
|
||||
}
|
||||
|
||||
if ($error)
|
||||
{
|
||||
$objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
|
||||
}
|
||||
|
||||
return $objectresp;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get getListActionCommType
|
||||
*
|
||||
* @param array $authentication Array of authentication information
|
||||
* @return mixed
|
||||
*/
|
||||
function getListActionCommType($authentication)
|
||||
{
|
||||
global $db,$conf,$langs;
|
||||
|
||||
dol_syslog("Function: getListActionCommType login=".$authentication['login']);
|
||||
|
||||
if ($authentication['entity']) $conf->entity=$authentication['entity'];
|
||||
|
||||
// Init and check authentication
|
||||
$objectresp=array();
|
||||
$errorcode='';$errorlabel='';
|
||||
$error=0;
|
||||
$fuser=check_authentication($authentication,$error,$errorcode,$errorlabel);
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
$fuser->getrights();
|
||||
|
||||
if ($fuser->rights->agenda->myactions->read)
|
||||
{
|
||||
$cactioncomm=new CActionComm($db);
|
||||
$result=$cactioncomm->liste_array('','code');
|
||||
if ($result > 0)
|
||||
{
|
||||
$resultarray=array();
|
||||
foreach($cactioncomm->liste_array as $code=>$libeller) {
|
||||
$resultarray[]=array('code'=>$code,'libelle'=>$libeller);
|
||||
}
|
||||
|
||||
$objectresp = array(
|
||||
'result'=>array('result_code'=>'OK', 'result_label'=>''),
|
||||
'actioncommtypes'=>$resultarray);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
$error++;
|
||||
$errorcode='NOT_FOUND'; $errorlabel='Object not found for id='.$id.' nor ref='.$ref.' nor ref_ext='.$ref_ext;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$error++;
|
||||
$errorcode='PERMISSION_DENIED'; $errorlabel='User does not have permission for this request';
|
||||
}
|
||||
}
|
||||
|
||||
if ($error)
|
||||
{
|
||||
$objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
|
||||
}
|
||||
|
||||
return $objectresp;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create ActionComm
|
||||
*
|
||||
* @param array $authentication Array of authentication information
|
||||
* @param ActionComm $actioncomm $actioncomm
|
||||
* @return array Array result
|
||||
*/
|
||||
function createActionComm($authentication,$actioncomm)
|
||||
{
|
||||
global $db,$conf,$langs;
|
||||
|
||||
$now=dol_now();
|
||||
|
||||
dol_syslog("Function: createActionComm login=".$authentication['login']);
|
||||
|
||||
if ($authentication['entity']) $conf->entity=$authentication['entity'];
|
||||
|
||||
// Init and check authentication
|
||||
$objectresp=array();
|
||||
$errorcode='';$errorlabel='';
|
||||
$error=0;
|
||||
$fuser=check_authentication($authentication,$error,$errorcode,$errorlabel);
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
$newobject=new ActionComm($db);
|
||||
|
||||
$newobject->datep=$actioncomm['datep'];
|
||||
$newobject->datef=$actioncomm['datef'];
|
||||
$newobject->type_code=$actioncomm['type_code'];
|
||||
$newobject->societe->id=$actioncomm['socid'];
|
||||
$newobject->fk_project=$actioncomm['projectid'];
|
||||
$newobject->note=$actioncomm['note'];
|
||||
$newobject->contact->id=$actioncomm['contactid'];
|
||||
$newobject->usertodo->id=$actioncomm['usertodo'];
|
||||
$newobject->userdone->id=$actioncomm['userdone'];
|
||||
$newobject->label=$actioncomm['label'];
|
||||
$newobject->percentage=$actioncomm['percentage'];
|
||||
$newobject->priority=$actioncomm['priority'];
|
||||
$newobject->fulldayevent=$actioncomm['fulldayevent'];
|
||||
$newobject->location=$actioncomm['location'];
|
||||
$newobject->fk_element=$actioncomm['fk_element'];
|
||||
$newobject->elementtype=$actioncomm['elementtype'];
|
||||
|
||||
//Retreive all extrafield for actioncomm
|
||||
// fetch optionals attributes and labels
|
||||
$extrafields=new ExtraFields($db);
|
||||
$extralabels=$extrafields->fetch_name_optionals_label('actioncomm');
|
||||
foreach($extrafields->attribute_label as $key=>$label)
|
||||
{
|
||||
$key='options_'.$key;
|
||||
$newobject->array_options[$key]=$actioncomm[$key];
|
||||
}
|
||||
|
||||
$db->begin();
|
||||
|
||||
$result=$newobject->add($fuser);
|
||||
if ($result <= 0)
|
||||
{
|
||||
$error++;
|
||||
}
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
$db->commit();
|
||||
$objectresp=array('result'=>array('result_code'=>'OK', 'result_label'=>''),'id'=>$newobject->id,'ref'=>$newobject->ref);
|
||||
}
|
||||
else
|
||||
{
|
||||
$db->rollback();
|
||||
$error++;
|
||||
$errorcode='KO';
|
||||
$errorlabel=$newobject->error;
|
||||
}
|
||||
}
|
||||
|
||||
if ($error)
|
||||
{
|
||||
$objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
|
||||
}
|
||||
|
||||
return $objectresp;
|
||||
}
|
||||
|
||||
// Return the results.
|
||||
$server->service($HTTP_RAW_POST_DATA);
|
||||
|
||||
?>
|
||||
Loading…
Reference in New Issue
Block a user