Skip to content
Snippets Groups Projects
Commit 81a97edf authored by Regis Houssin's avatar Regis Houssin
Browse files

Merge branch 'develop' of git+ssh://git@github.com/Dolibarr/dolibarr.git into develop

parents 205f884e 826a5f80
Branches
Tags
No related merge requests found
......@@ -30,6 +30,7 @@ $WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_productorservice.php';
//$WS_DOL_URL = 'http://localhost:8080/'; // To test with Soapui mock. If not a page, should end with /
$WS_METHOD1 = 'createProductOrService';
$WS_METHOD2 = 'getProductOrService';
$WS_METHOD3 = 'getListOfProductsOrServices';
$ns='http://www.dolibarr.org/ns/';
......@@ -47,6 +48,13 @@ if ($soapclient2)
$soapclient2->soap_defencoding='UTF-8';
$soapclient2->decodeUTF8(false);
}
$soapclient3 = new nusoap_client($WS_DOL_URL);
if ($soapclient3)
{
$soapclient3->soap_defencoding='UTF-8';
$soapclient3->decodeUTF8(false);
}
// Call the WebService method and store its result in $result.
$authentication=array(
......@@ -79,14 +87,31 @@ if ($WS_METHOD2)
{
$parameters = array('authentication'=>$authentication,'id'=>1,'ref'=>'');
dol_syslog("Call method ".$WS_METHOD2);
$result2 = $soapclient1->call($WS_METHOD2,$parameters,$ns,'');
$result2 = $soapclient2->call($WS_METHOD2,$parameters,$ns,'');
if (! $result2)
{
print $soapclient1->error_str;
print $soapclient2->error_str;
print "<br>\n\n";
print $soapclient1->request;
print $soapclient2->request;
print "<br>\n\n";
print $soapclient1->response;
print $soapclient2->response;
exit;
}
}
// Test url 3
if ($WS_METHOD3)
{
$parameters = array('authentication'=>$authentication,'filterproduct'=>array('type'=>-1));
dol_syslog("Call method ".$WS_METHOD3);
$result3 = $soapclient3->call($WS_METHOD3,$parameters,$ns,'');
if (! $result3)
{
print $soapclient3->error_str;
print "<br>\n\n";
print $soapclient3->request;
print "<br>\n\n";
print $soapclient3->response;
exit;
}
}
......@@ -111,7 +136,7 @@ echo '<h4>Function</h4>';
echo $WS_METHOD1;
echo '<h4>SOAP Message</h4>';
echo '<pre>' . htmlspecialchars($soapclient1->request, ENT_QUOTES) . '</pre>';
echo '<hr>';
//echo '<hr>';
echo "<h2>Response:</h2>";
echo '<h4>Result</h4>';
echo '<pre>';
......@@ -127,7 +152,7 @@ echo '<h4>Function</h4>';
echo $WS_METHOD2;
echo '<h4>SOAP Message</h4>';
echo '<pre>' . htmlspecialchars($soapclient2->request, ENT_QUOTES) . '</pre>';
echo '<hr>';
//echo '<hr>';
echo "<h2>Response:</h2>";
echo '<h4>Result</h4>';
echo '<pre>';
......@@ -136,6 +161,22 @@ echo '</pre>';
echo '<h4>SOAP Message</h4>';
echo '<pre>' . htmlspecialchars($soapclient2->response, ENT_QUOTES) . '</pre>';
print '<hr>';
echo "<h2>Request:</h2>";
echo '<h4>Function</h4>';
echo $WS_METHOD3;
echo '<h4>SOAP Message</h4>';
echo '<pre>' . htmlspecialchars($soapclient3->request, ENT_QUOTES) . '</pre>';
//echo '<hr>';
echo "<h2>Response:</h2>";
echo '<h4>Result</h4>';
echo '<pre>';
print_r($result3);
echo '</pre>';
echo '<h4>SOAP Message</h4>';
echo '<pre>' . htmlspecialchars($soapclient3->response, ENT_QUOTES) . '</pre>';
echo '</body>'."\n";;
echo '</html>'."\n";;
?>
......@@ -117,6 +117,34 @@ $server->wsdl->addComplexType(
)
);
// Define other specific objects
$server->wsdl->addComplexType(
'filterproduct',
'complexType',
'struct',
'all',
'',
array(
// 'limit' => array('name'=>'limit','type'=>'xsd:string'),
'type' => array('name'=>'type','type'=>'xsd:string'),
'status_tobuy' => array('name'=>'status_tobuy','type'=>'xsd:string'),
'status_tosell' => array('name'=>'status_tosell','type'=>'xsd:string'),
)
);
// Define other specific objects
$server->wsdl->addComplexType(
'arrayproducts',
'complexType',
'struct',
'all',
'',
array(
'id' => array('name'=>'id','type'=>'xsd:string'),
'ref' => array('name'=>'ref','type'=>'xsd:string'),
'ref_ext' => array('name'=>'ref_ext','type'=>'xsd:string'),
)
);
// 5 styles: RPC/encoded, RPC/literal, Document/encoded (not WS-I compliant), Document/literal, Document/literal wrapped
......@@ -155,6 +183,20 @@ $server->register(
'WS to create a product or service'
);
// Register WSDL
$server->register(
'getListOfProductsOrServices',
// Entry values
array('authentication'=>'tns:authentication','filterproduct'=>'tns:filterproduct'),
// Exit values
array('result'=>'tns:result','arrayproducts'=>'tns:arrayproducts'),
$ns,
$ns.'#getListOfProductsOrServices',
$styledoc,
$styleuse,
'WS to get list of all products or services id and ref'
);
/**
* Get produt or service
......@@ -358,6 +400,84 @@ function createProductOrService($authentication,$product)
}
/**
* getListOfProductsOrServices
*
* @param array $authentication Array of authentication information
* @param array $filterproduct Filter fields
* @return array Array result
*/
function getListOfProductsOrServices($authentication,$filterproduct)
{
global $db,$conf,$langs;
$now=dol_now();
dol_syslog("Function: getListOfProductsOrServices login=".$authentication['login']);
if ($authentication['entity']) $conf->entity=$authentication['entity'];
// Init and check authentication
$objectresp=array();
$arrayproducts=array();
$errorcode='';$errorlabel='';
$error=0;
$fuser=check_authentication($authentication,$error,$errorcode,$errorlabel);
// Check parameters
if (! $error)
{
$sql ="SELECT rowid, ref, ref_ext";
$sql.=" FROM ".MAIN_DB_PREFIX."product";
$sql.=" WHERE entity=".$conf->entity;
foreach($filterproduct as $key => $val)
{
if ($key == 'type' && $val >= 0) $sql.=" AND fk_product_type = ".$db->escape($val);
if ($key == 'tosell') $sql.=" AND to_sell = ".$db->escape($val);
if ($key == 'tobuy') $sql.=" AND to_buy = ".$db->escape($val);
}
$resql=$db->query($sql);
if ($resql)
{
$num=$db->num_rows($resql);
$i=0;
while ($i < $num)
{
$obj=$db->fetch_object($resql);
$arrayproducts[$obj->rowid]=array('id'=>$obj->rowid,'ref'=>$obj->ref,'ref_ext'=>$obj->ref_ext);
$i++;
}
}
else
{
$error++;
$errorcode=$db->lasterrno();
$errorlabel=$db->lasterror();
}
}
if ($error)
{
$objectresp = array(
'result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel),
'arrayproducts'=>$arrayproducts
);
}
else
{
$objectresp = array(
'result'=>array('result_code' => 'OK', 'result_label' => ''),
'arrayproducts'=>$arrayproducts
);
}
var_dump($objectresp);exit;
return $objectresp;
}
// Return the results.
$server->service($HTTP_RAW_POST_DATA);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment