diff --git a/htdocs/webservices/server_productorservice.php b/htdocs/webservices/server_productorservice.php index 0bba1e80058ee17cdb6a4c7db4afb7232188a501..e6caadaed578bcd2e4d482c3780b7e3e39271d13 100755 --- a/htdocs/webservices/server_productorservice.php +++ b/htdocs/webservices/server_productorservice.php @@ -31,6 +31,8 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php'; require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; +require_once(DOL_DOCUMENT_ROOT."/categories/class/categorie.class.php"); + dol_syslog("Call Dolibarr webservices interfaces"); @@ -255,6 +257,20 @@ $server->register( 'WS to get list of all products or services id and ref' ); +// Register WSDL +$server->register( + 'getProductsForCategory', + // Entry values + array('authentication'=>'tns:authentication','id'=>'xsd:string'), + // Exit values + array('result'=>'tns:result','products'=>'ProductsArray'), + $ns, + $ns.'#getProductsForCategory', + $styledoc, + $styleuse, + 'WS to get list of all products or services for a category' +); + /** * Get produt or service @@ -541,6 +557,135 @@ function getListOfProductsOrServices($authentication,$filterproduct) } +// return category infos and children +function getProductsForCategory($authentication,$id) +{ + global $db,$conf,$langs; + + dol_syslog("Function: getProductsForCategory login=".$authentication['login']." id=".$id); + + if ($authentication['entity']) $conf->entity=$authentication['entity']; + + $objectresp=array(); + $errorcode='';$errorlabel=''; + $error=0; + + $fuser=check_authentication($authentication,$error,$errorcode,$errorlabel); + + + if (! $error && !$id) + { + $error++; + $errorcode='BAD_PARAMETERS'; $errorlabel="Parameter id must be provided."; + } + + + if (! $error) + { + $fuser->getrights(); + + if ($fuser->rights->produit->lire) + { + $categorie=new Categorie($db); + $result=$categorie->fetch($id); + if ($result > 0) + { + $table = "product"; + $field = "product"; + $sql = "SELECT fk_".$field." FROM ".MAIN_DB_PREFIX."categorie_".$table; + $sql .= " WHERE fk_categorie = ".$id; + $sql .= " ORDER BY fk_".$field." ASC" ; + + + dol_syslog("GetProductsForCategory::get_type sql=".$sql); + $res = $db->query($sql); + if ($res) + { + + while ($rec = $db->fetch_array ($res)) + { + $obj = new Product ($db); + $obj->fetch ($rec['fk_'.$field]); + if($obj->status > 0 ) { + + $dir = (!empty($conf->product->dir_output)?$conf->product->dir_output:$conf->service->dir_output); + $pdir = get_exdir($obj->id,2) . $obj->id ."/photos/"; + $dir = $dir . '/'. $pdir; + + $products[] = array( + + 'id' => $obj->id, + 'ref' => $obj->ref, + 'ref_ext' => $obj->ref_ext, + 'label' => $obj->label, + 'description' => $obj->description, + 'date_creation' => dol_print_date($obj->date_creation,'dayhourrfc'), + 'date_modification' => dol_print_date($obj->date_modification,'dayhourrfc'), + 'note' => $obj->note, + 'status_tosell' => $obj->status, + 'status_tobuy' => $obj->status_buy, + 'type' => $obj->type, + 'barcode' => $obj->barcode, + 'barcode_type' => $obj->barcode_type, + 'country_id' => $obj->country_id>0?$obj->country_id:'', + 'country_code' => $obj->country_code, + 'custom_code' => $obj->customcode, + + 'price_net' => $obj->price, + 'price' => ($obj->price_ttc-$obj->price), + 'vat_rate' => $obj->tva_tx, + 'price_ttc' => $obj->price_ttc, + 'price_base_type' => $obj->price_base_type, + + 'stock_real' => $obj->stock_reel, + 'stock_alert' => $obj->seuil_stock_alerte, + 'pmp' => $obj->pmp, + 'import_key' => $obj->import_key, + 'dir' => $pdir, + 'photos' => $obj->liste_photos($dir,$nbmax=10) + + + ); + } + + } + + // Retour + $objectresp = array( + 'result'=>array('result_code'=>'OK', 'result_label'=>''), + 'products'=> $products + ); + + } + else + { + $errorcode='NORECORDS_FOR_ASSOCIATION'; $errorlabel='No products associated'.$sql; + $objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel)); + dol_syslog("getProductsForCategory:: ".$c->error, LOG_DEBUG); + + } + } + else + { + $error++; + $errorcode='NOT_FOUND'; $errorlabel='Object not found for id='.$id; + } + } + 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; +} + // Return the results. diff --git a/htdocs/webservices/server_user.php b/htdocs/webservices/server_user.php index 4aee9cf42b04570835e85f0281b5f08fe28c559c..e035b098b91faba3c39d5367ead323ff94f6b5de 100644 --- a/htdocs/webservices/server_user.php +++ b/htdocs/webservices/server_user.php @@ -120,6 +120,34 @@ $server->wsdl->addComplexType( ) ); +// Define other specific objects +$server->wsdl->addComplexType( + 'group', + 'complexType', + 'struct', + 'all', + '', + array( + 'nom' => array('name'=>'nom','type'=>'xsd:string'), + 'id' => array('name'=>'id','type'=>'xsd:string'), + 'datec' => array('name'=>'datec','type'=>'xsd:string'), + 'nb' => array('name'=>'nb','type'=>'xsd:string') + ) +); + +$server->wsdl->addComplexType( + 'GroupsArray', + 'complexType', + 'array', + '', + 'SOAP-ENC:Array', + array(), + array( + array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:group[]') + ), + 'tns:group' +); + // 5 styles: RPC/encoded, RPC/literal, Document/encoded (not WS-I compliant), Document/literal, Document/literal wrapped @@ -144,6 +172,19 @@ $server->register( 'WS to get user' ); +$server->register( + 'getListOfGroups', + // Entry values + array('authentication'=>'tns:authentication'), + // Exit values + array('result'=>'tns:result','groups'=>'tns:GroupsArray'), + $ns, + $ns.'#getListOfGroups', + $styledoc, + $styleuse, + 'WS to get list of groups' +); + @@ -246,6 +287,83 @@ function getUser($authentication,$id,$ref='',$ref_ext='') return $objectresp; } +/** + * getListOfGroups + * + * @param array $authentication Array of authentication information + * @return array Array result + */ +function getListOfGroups($authentication) +{ + global $db,$conf,$langs; + + $now=dol_now(); + + dol_syslog("Function: getListOfGroups login=".$authentication['login']); + + if ($authentication['entity']) $conf->entity=$authentication['entity']; + + // Init and check authentication + $objectresp=array(); + $arraygroups=array(); + $errorcode='';$errorlabel=''; + $error=0; + $fuser=check_authentication($authentication,$error,$errorcode,$errorlabel); + // Check parameters + + if (! $error) + { + $sql = "SELECT g.rowid, g.nom, g.entity, g.datec, COUNT(DISTINCT ugu.fk_user) as nb"; + $sql.= " FROM ".MAIN_DB_PREFIX."usergroup as g"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."usergroup_user as ugu ON ugu.fk_usergroup = g.rowid"; + if (! empty($conf->multicompany->enabled) && $conf->entity == 1 && ($conf->multicompany->transverse_mode || ($user->admin && ! $user->entity))) + { + $sql.= " WHERE g.entity IS NOT NULL"; + } + else + { + $sql.= " WHERE g.entity IN (0,".$conf->entity.")"; + } + $sql.= " GROUP BY g.rowid, g.nom, g.entity, g.datec"; + $resql=$db->query($sql); + if ($resql) + { + $num=$db->num_rows($resql); + + $i=0; + while ($i < $num) + { + $obj=$db->fetch_object($resql); + $arraygroups[]=array('id'=>$obj->rowid,'nom'=>$obj->nom,'datec'=>$obj->datec,'nb'=>$obj->nb); + $i++; + } + } + else + { + $error++; + $errorcode=$db->lasterrno(); + $errorlabel=$db->lasterror(); + } + } + + if ($error) + { + $objectresp = array( + 'result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel), + 'groups'=>$arraygroups + ); + } + else + { + $objectresp = array( + 'result'=>array('result_code' => 'OK', 'result_label' => ''), + 'groups'=>$arraygroups + ); + } + + return $objectresp; +} + // Return the results.