code syntax variants webservice directory
This commit is contained in:
parent
0d7a2c1d81
commit
db871994fb
@ -25,8 +25,9 @@ $langs->loadLangs(array("admin", "products"));
|
||||
$action = GETPOST('action', 'alphanohtml');
|
||||
|
||||
// Security check
|
||||
if (!$user->admin || (empty($conf->product->enabled) && empty($conf->service->enabled)))
|
||||
if (!$user->admin || (empty($conf->product->enabled) && empty($conf->service->enabled))) {
|
||||
accessforbidden();
|
||||
}
|
||||
|
||||
$error = 0;
|
||||
|
||||
|
||||
@ -16,11 +16,21 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
if (!defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1');
|
||||
if (!defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1');
|
||||
if (!defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1');
|
||||
if (!defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1');
|
||||
if (!defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1');
|
||||
if (!defined('NOTOKENRENEWAL')) {
|
||||
define('NOTOKENRENEWAL', '1');
|
||||
}
|
||||
if (!defined('NOREQUIREMENU')) {
|
||||
define('NOREQUIREMENU', '1');
|
||||
}
|
||||
if (!defined('NOREQUIREHTML')) {
|
||||
define('NOREQUIREHTML', '1');
|
||||
}
|
||||
if (!defined('NOREQUIREAJAX')) {
|
||||
define('NOREQUIREAJAX', '1');
|
||||
}
|
||||
if (!defined('NOREQUIRESOC')) {
|
||||
define('NOREQUIRESOC', '1');
|
||||
}
|
||||
|
||||
require '../../main.inc.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
|
||||
|
||||
@ -15,11 +15,21 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
if (!defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1');
|
||||
if (!defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1');
|
||||
if (!defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1');
|
||||
if (!defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1');
|
||||
if (!defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1');
|
||||
if (!defined('NOTOKENRENEWAL')) {
|
||||
define('NOTOKENRENEWAL', '1');
|
||||
}
|
||||
if (!defined('NOREQUIREMENU')) {
|
||||
define('NOREQUIREMENU', '1');
|
||||
}
|
||||
if (!defined('NOREQUIREHTML')) {
|
||||
define('NOREQUIREHTML', '1');
|
||||
}
|
||||
if (!defined('NOREQUIREAJAX')) {
|
||||
define('NOREQUIREAJAX', '1');
|
||||
}
|
||||
if (!defined('NOREQUIRESOC')) {
|
||||
define('NOREQUIRESOC', '1');
|
||||
}
|
||||
|
||||
require '../../main.inc.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
|
||||
|
||||
@ -16,12 +16,24 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
if (!defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); // Disable token renewal
|
||||
if (!defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1');
|
||||
if (!defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1');
|
||||
if (!defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1');
|
||||
if (!defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1');
|
||||
if (!defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1');
|
||||
if (!defined('NOTOKENRENEWAL')) {
|
||||
define('NOTOKENRENEWAL', '1'); // Disable token renewal
|
||||
}
|
||||
if (!defined('NOREQUIREMENU')) {
|
||||
define('NOREQUIREMENU', '1');
|
||||
}
|
||||
if (!defined('NOREQUIREHTML')) {
|
||||
define('NOREQUIREHTML', '1');
|
||||
}
|
||||
if (!defined('NOREQUIREAJAX')) {
|
||||
define('NOREQUIREAJAX', '1');
|
||||
}
|
||||
if (!defined('NOREQUIRESOC')) {
|
||||
define('NOREQUIRESOC', '1');
|
||||
}
|
||||
if (!defined('NOREQUIRETRAN')) {
|
||||
define('NOREQUIRETRAN', '1');
|
||||
}
|
||||
|
||||
require '../../main.inc.php';
|
||||
|
||||
|
||||
@ -41,7 +41,9 @@ if ($object->fetch($id) < 1) {
|
||||
* Actions
|
||||
*/
|
||||
|
||||
if ($cancel) $action = '';
|
||||
if ($cancel) {
|
||||
$action = '';
|
||||
}
|
||||
|
||||
if ($action) {
|
||||
if ($action == 'update') {
|
||||
@ -60,19 +62,16 @@ if ($action) {
|
||||
$objectval->ref = $ref;
|
||||
$objectval->value = GETPOST('value', 'alpha');
|
||||
|
||||
if (empty($objectval->ref))
|
||||
{
|
||||
if (empty($objectval->ref)) {
|
||||
$error++;
|
||||
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Ref")), null, 'errors');
|
||||
}
|
||||
if (empty($objectval->value))
|
||||
{
|
||||
if (empty($objectval->value)) {
|
||||
$error++;
|
||||
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors');
|
||||
}
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
if (!$error) {
|
||||
if ($objectval->update($user) > 0) {
|
||||
setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
|
||||
} else {
|
||||
@ -102,8 +101,7 @@ if ($confirm == 'yes') {
|
||||
header('Location: '.dol_buildpath('/variants/list.php', 2));
|
||||
}
|
||||
exit();
|
||||
} elseif ($action == 'confirm_deletevalue')
|
||||
{
|
||||
} elseif ($action == 'confirm_deletevalue') {
|
||||
if ($objectval->fetch($valueid) > 0) {
|
||||
if ($objectval->delete($user) < 1) {
|
||||
setEventMessages($langs->trans('CoreErrorMessage'), $objectval->errors, 'errors');
|
||||
|
||||
@ -116,8 +116,7 @@ class ProductAttribute extends CommonObject
|
||||
$sql = 'SELECT rowid, ref, ref_ext, label, rang FROM '.MAIN_DB_PREFIX."product_attribute WHERE entity IN (".getEntity('product').')';
|
||||
$sql .= $this->db->order('rang', 'asc');
|
||||
$query = $this->db->query($sql);
|
||||
if ($query)
|
||||
{
|
||||
if ($query) {
|
||||
while ($result = $this->db->fetch_object($query)) {
|
||||
$tmp = new ProductAttribute($this->db);
|
||||
$tmp->id = $result->rowid;
|
||||
@ -128,8 +127,9 @@ class ProductAttribute extends CommonObject
|
||||
|
||||
$return[] = $tmp;
|
||||
}
|
||||
} else {
|
||||
dol_print_error($this->db);
|
||||
}
|
||||
else dol_print_error($this->db);
|
||||
|
||||
return $return;
|
||||
}
|
||||
@ -159,8 +159,7 @@ class ProductAttribute extends CommonObject
|
||||
VALUES ('".$this->db->escape($this->ref)."', '".$this->db->escape($this->ref_ext)."', '".$this->db->escape($this->label)."', ".(int) $this->entity.", ".(int) $this->rang.")";
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
if ($query)
|
||||
{
|
||||
if ($query) {
|
||||
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'product_attribute');
|
||||
|
||||
return $this->id;
|
||||
|
||||
@ -174,8 +174,7 @@ class ProductCombination
|
||||
*/
|
||||
if ($fk_price_level > 0) {
|
||||
$combination_price_levels[$fk_price_level] = ProductCombinationLevel::createFromParent($this->db, $this, $fk_price_level);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
for ($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++) {
|
||||
$combination_price_levels[$i] = ProductCombinationLevel::createFromParent($this->db, $this, $i);
|
||||
}
|
||||
@ -227,8 +226,7 @@ class ProductCombination
|
||||
|
||||
if ($error) {
|
||||
return $error * -1;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@ -327,7 +325,9 @@ class ProductCombination
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql) {
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
if ($obj) $nb = $obj->nb;
|
||||
if ($obj) {
|
||||
$nb = $obj->nb;
|
||||
}
|
||||
}
|
||||
|
||||
return $nb;
|
||||
@ -506,8 +506,7 @@ class ProductCombination
|
||||
|
||||
// MultiPrix
|
||||
if (!empty($conf->global->PRODUIT_MULTIPRICES)) {
|
||||
for ($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++)
|
||||
{
|
||||
for ($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++) {
|
||||
if ($parent->multiprices[$i] != '' || isset($this->combination_price_levels[$i]->variation_price)) {
|
||||
$new_type = $parent->multiprices_base_type[$i];
|
||||
$new_min_price = $parent->multiprices_min[$i];
|
||||
@ -709,8 +708,7 @@ class ProductCombination
|
||||
//Final price impact
|
||||
if (!is_array($forced_pricevar)) {
|
||||
$price_impact[1] = (float) $forced_pricevar; // If false, return 0
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$price_impact = $forced_pricevar;
|
||||
}
|
||||
|
||||
@ -765,8 +763,7 @@ class ProductCombination
|
||||
|
||||
// Manage Price levels
|
||||
if ($conf->global->PRODUIT_MULTIPRICES) {
|
||||
for ($i = 2; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++)
|
||||
{
|
||||
for ($i = 2; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++) {
|
||||
$price_impact[$i] += (float) price2num($variations[$currcombattr][$currcombval]['price']);
|
||||
}
|
||||
}
|
||||
@ -826,8 +823,7 @@ class ProductCombination
|
||||
$newproduct->barcode = -1;
|
||||
$result = $newproduct->create($user);
|
||||
|
||||
if ($result < 0)
|
||||
{
|
||||
if ($result < 0) {
|
||||
//In case the error is not related with an already existing product
|
||||
if ($newproduct->error != 'ErrorProductAlreadyExists') {
|
||||
$this->error[] = $newproduct->error;
|
||||
@ -867,8 +863,7 @@ class ProductCombination
|
||||
}
|
||||
} else {
|
||||
$result = $newproduct->update($newproduct->id, $user);
|
||||
if ($result < 0)
|
||||
{
|
||||
if ($result < 0) {
|
||||
$this->db->rollback();
|
||||
return -1;
|
||||
}
|
||||
@ -876,8 +871,7 @@ class ProductCombination
|
||||
|
||||
$newcomb->fk_product_child = $newproduct->id;
|
||||
|
||||
if ($newcomb->update($user) < 0)
|
||||
{
|
||||
if ($newcomb->update($user) < 0) {
|
||||
$this->error = $newcomb->error;
|
||||
$this->errors = $newcomb->errors;
|
||||
$this->db->rollback();
|
||||
@ -925,8 +919,7 @@ class ProductCombination
|
||||
$combination->variation_price_percentage,
|
||||
$combination->variation_price,
|
||||
$combination->variation_weight
|
||||
) < 0)
|
||||
{
|
||||
) < 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -954,12 +947,10 @@ class ProductCombination
|
||||
|
||||
$i = 0;
|
||||
|
||||
while ($i < $num)
|
||||
{
|
||||
while ($i < $num) {
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
|
||||
if ($obj->label)
|
||||
{
|
||||
if ($obj->label) {
|
||||
$label .= ' '.$obj->label;
|
||||
}
|
||||
$i++;
|
||||
|
||||
@ -58,8 +58,7 @@ $prodattr = new ProductAttribute($db);
|
||||
$prodattr_val = new ProductAttributeValue($db);
|
||||
|
||||
$object = new Product($db);
|
||||
if ($id > 0 || $ref)
|
||||
{
|
||||
if ($id > 0 || $ref) {
|
||||
$object->fetch($id, $ref);
|
||||
}
|
||||
|
||||
@ -80,16 +79,13 @@ if (!$object->isProduct() && !$object->isService()) {
|
||||
header('Location: '.dol_buildpath('/product/card.php?id='.$object->id, 2));
|
||||
exit();
|
||||
}
|
||||
if ($action == 'add')
|
||||
{
|
||||
if ($action == 'add') {
|
||||
unset($selectedvariant);
|
||||
unset($_SESSION['addvariant_'.$object->id]);
|
||||
}
|
||||
if ($action == 'create' && GETPOST('selectvariant', 'alpha')) // We click on select combination
|
||||
{
|
||||
if ($action == 'create' && GETPOST('selectvariant', 'alpha')) { // We click on select combination
|
||||
$action = 'add';
|
||||
if (GETPOST('attribute') != '-1' && GETPOST('value') != '-1')
|
||||
{
|
||||
if (GETPOST('attribute') != '-1' && GETPOST('value') != '-1') {
|
||||
$selectedvariant[GETPOST('attribute').':'.GETPOST('value')] = GETPOST('attribute').':'.GETPOST('value');
|
||||
$_SESSION['addvariant_'.$object->id] = $selectedvariant;
|
||||
}
|
||||
@ -101,9 +97,8 @@ $prodcomb2val = new ProductCombination2ValuePair($db);
|
||||
|
||||
$productCombination2ValuePairs1 = array();
|
||||
|
||||
if (($action == 'add' || $action == 'create') && empty($massaction) && !GETPOST('selectvariant', 'alpha')) // We click on Create all defined combinations
|
||||
{
|
||||
//$features = GETPOST('features', 'array');
|
||||
if (($action == 'add' || $action == 'create') && empty($massaction) && !GETPOST('selectvariant', 'alpha')) { // We click on Create all defined combinations
|
||||
//$features = GETPOST('features', 'array');
|
||||
$features = $_SESSION['addvariant_'.$object->id];
|
||||
|
||||
if (!$features) {
|
||||
@ -121,8 +116,7 @@ if (($action == 'add' || $action == 'create') && empty($massaction) && !GETPOST(
|
||||
// for conf PRODUIT_MULTIPRICES
|
||||
if ($conf->global->PRODUIT_MULTIPRICES) {
|
||||
$level_price_impact = array_map('price2num', $level_price_impact);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$level_price_impact = array(1 => $price_impact);
|
||||
$level_price_impact_percent = array(1 => $price_impact_percent);
|
||||
}
|
||||
@ -156,11 +150,9 @@ if (($action == 'add' || $action == 'create') && empty($massaction) && !GETPOST(
|
||||
// sanit_feature is an array with 1 (and only 1) value per attribute.
|
||||
// For example: Color->blue, Size->Small, Option->2
|
||||
//var_dump($sanit_features);
|
||||
if (!$prodcomb->fetchByProductCombination2ValuePairs($id, $sanit_features))
|
||||
{
|
||||
if (!$prodcomb->fetchByProductCombination2ValuePairs($id, $sanit_features)) {
|
||||
$result = $prodcomb->createProductCombination($user, $object, $sanit_features, array(), $level_price_impact_percent, $level_price_impact, $weight_impact, $reference);
|
||||
if ($result > 0)
|
||||
{
|
||||
if ($result > 0) {
|
||||
setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
|
||||
unset($_SESSION['addvariant_'.$object->id]);
|
||||
|
||||
@ -243,8 +235,7 @@ if (($action == 'add' || $action == 'create') && empty($massaction) && !GETPOST(
|
||||
|
||||
$prodcomb->variation_price = $level_price_impact[1];
|
||||
$prodcomb->variation_price_percentage = (bool) $level_price_impact_percent[1];
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$level_price_impact = array(1 => $price_impact);
|
||||
$level_price_impact_percent = array(1 => $price_impact_percent);
|
||||
|
||||
@ -330,12 +321,13 @@ if ($action === 'confirm_deletecombination') {
|
||||
|
||||
$form = new Form($db);
|
||||
|
||||
if (!empty($id) || !empty($ref))
|
||||
{
|
||||
if (!empty($id) || !empty($ref)) {
|
||||
llxHeader("", "", $langs->trans("CardProduct".$object->type));
|
||||
|
||||
$showbarcode = empty($conf->barcode->enabled) ? 0 : 1;
|
||||
if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->barcode->lire_advance)) $showbarcode = 0;
|
||||
if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->barcode->lire_advance)) {
|
||||
$showbarcode = 0;
|
||||
}
|
||||
|
||||
$head = product_prepare_head($object);
|
||||
$titre = $langs->trans("CardProduct".$object->type);
|
||||
@ -357,17 +349,25 @@ if (!empty($id) || !empty($ref))
|
||||
print '<tr><td class="titlefield">'.$langs->trans("DefaultTaxRate").'</td><td>';
|
||||
|
||||
$positiverates = '';
|
||||
if (price2num($object->tva_tx)) $positiverates .= ($positiverates ? '/' : '').price2num($object->tva_tx);
|
||||
if (price2num($object->localtax1_type)) $positiverates .= ($positiverates ? '/' : '').price2num($object->localtax1_tx);
|
||||
if (price2num($object->localtax2_type)) $positiverates .= ($positiverates ? '/' : '').price2num($object->localtax2_tx);
|
||||
if (empty($positiverates)) $positiverates = '0';
|
||||
if (price2num($object->tva_tx)) {
|
||||
$positiverates .= ($positiverates ? '/' : '').price2num($object->tva_tx);
|
||||
}
|
||||
if (price2num($object->localtax1_type)) {
|
||||
$positiverates .= ($positiverates ? '/' : '').price2num($object->localtax1_tx);
|
||||
}
|
||||
if (price2num($object->localtax2_type)) {
|
||||
$positiverates .= ($positiverates ? '/' : '').price2num($object->localtax2_tx);
|
||||
}
|
||||
if (empty($positiverates)) {
|
||||
$positiverates = '0';
|
||||
}
|
||||
echo vatrate($positiverates.($object->default_vat_code ? ' ('.$object->default_vat_code.')' : ''), '%', $object->tva_npr);
|
||||
/*
|
||||
if ($object->default_vat_code)
|
||||
{
|
||||
print vatrate($object->tva_tx, true) . ' ('.$object->default_vat_code.')';
|
||||
}
|
||||
else print vatrate($object->tva_tx, true, $object->tva_npr, true);*/
|
||||
if ($object->default_vat_code)
|
||||
{
|
||||
print vatrate($object->tva_tx, true) . ' ('.$object->default_vat_code.')';
|
||||
}
|
||||
else print vatrate($object->tva_tx, true, $object->tva_npr, true);*/
|
||||
print '</td></tr>';
|
||||
|
||||
// Price
|
||||
@ -390,8 +390,7 @@ if (!empty($id) || !empty($ref))
|
||||
|
||||
// Weight
|
||||
print '<tr><td>'.$langs->trans("Weight").'</td><td>';
|
||||
if ($object->weight != '')
|
||||
{
|
||||
if ($object->weight != '') {
|
||||
print $object->weight." ".measuringUnitString(0, "weight", $object->weight_units);
|
||||
} else {
|
||||
print ' ';
|
||||
@ -466,14 +465,14 @@ if (!empty($id) || !empty($ref))
|
||||
foreach ($productCombination2ValuePairs1 as $pc2v) {
|
||||
$prodattr_val->fetch($pc2v->fk_prod_attr_val);
|
||||
?>
|
||||
variants_selected.index.push(<?php echo $pc2v->fk_prod_attr ?>);
|
||||
variants_selected.info[<?php echo $pc2v->fk_prod_attr ?>] = {
|
||||
attribute: variants_available[<?php echo $pc2v->fk_prod_attr ?>],
|
||||
value: {
|
||||
id: <?php echo $pc2v->fk_prod_attr_val ?>,
|
||||
label: '<?php echo $prodattr_val->value ?>'
|
||||
}
|
||||
};
|
||||
variants_selected.index.push(<?php echo $pc2v->fk_prod_attr ?>);
|
||||
variants_selected.info[<?php echo $pc2v->fk_prod_attr ?>] = {
|
||||
attribute: variants_available[<?php echo $pc2v->fk_prod_attr ?>],
|
||||
value: {
|
||||
id: <?php echo $pc2v->fk_prod_attr_val ?>,
|
||||
label: '<?php echo $prodattr_val->value ?>'
|
||||
}
|
||||
};
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
@ -604,8 +603,7 @@ if (!empty($id) || !empty($ref))
|
||||
print '<table class="border" style="width: 100%">';
|
||||
|
||||
// When in edit mode
|
||||
if (is_array($productCombination2ValuePairs1) && count($productCombination2ValuePairs1))
|
||||
{
|
||||
if (is_array($productCombination2ValuePairs1) && count($productCombination2ValuePairs1)) {
|
||||
?>
|
||||
<tr>
|
||||
<td class="titlefieldcreate tdtop"><label for="features"><?php echo $langs->trans('Combination') ?></label></td>
|
||||
@ -616,8 +614,7 @@ if (!empty($id) || !empty($ref))
|
||||
$result1 = $prodattr->fetch($val->fk_prod_attr);
|
||||
$result2 = $prodattr_val->fetch($val->fk_prod_attr_val);
|
||||
//print 'rr'.$result1.' '.$result2;
|
||||
if ($result1 > 0 && $result2 > 0)
|
||||
{
|
||||
if ($result1 > 0 && $result2 > 0) {
|
||||
print $prodattr->label.' - '.$prodattr_val->value.'<br>';
|
||||
// TODO Add delete link
|
||||
}
|
||||
@ -651,8 +648,7 @@ if (!empty($id) || !empty($ref))
|
||||
} else {
|
||||
$prodcomb->fetchCombinationPriceLevels();
|
||||
|
||||
for ($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++)
|
||||
{
|
||||
for ($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++) {
|
||||
print '<tr>';
|
||||
print '<td><label for="level_price_impact_'.$i.'">'.$langs->trans('ImpactOnPriceLevel', $i).'</label>';
|
||||
if ($i === 1) {
|
||||
@ -703,7 +699,9 @@ if (!empty($id) || !empty($ref))
|
||||
?>
|
||||
|
||||
<div style="text-align: center">
|
||||
<input type="submit" name="create" <?php if (!is_array($productCombination2ValuePairs1)) print ' disabled="disabled"'; ?> value="<?php echo $action == 'add' ? $langs->trans('Create') : $langs->trans("Save") ?>" class="button button-save">
|
||||
<input type="submit" name="create" <?php if (!is_array($productCombination2ValuePairs1)) {
|
||||
print ' disabled="disabled"';
|
||||
} ?> value="<?php echo $action == 'add' ? $langs->trans('Create') : $langs->trans("Save") ?>" class="button button-save">
|
||||
|
||||
<input type="submit" name="cancel" value="<?php echo $langs->trans("Cancel"); ?>" class="button button-cancel">
|
||||
</div>
|
||||
@ -732,8 +730,7 @@ if (!empty($id) || !empty($ref))
|
||||
|
||||
$comb2val = new ProductCombination2ValuePair($db);
|
||||
|
||||
if ($productCombinations)
|
||||
{
|
||||
if ($productCombinations) {
|
||||
?>
|
||||
|
||||
<script type="text/javascript">
|
||||
@ -767,8 +764,7 @@ if (!empty($id) || !empty($ref))
|
||||
|
||||
print '<a href="combinations.php?id='.$object->id.'&action=add&token='.newToken().'" class="butAction">'.$langs->trans('NewProductCombination').'</a>'; // NewVariant
|
||||
|
||||
if ($productCombinations)
|
||||
{
|
||||
if ($productCombinations) {
|
||||
print '<a href="combinations.php?id='.$object->id.'&action=copy&token='.newToken().'" class="butAction">'.$langs->trans('PropagateVariant').'</a>';
|
||||
}
|
||||
|
||||
@ -791,8 +787,8 @@ if (!empty($id) || !empty($ref))
|
||||
// List of mass actions available
|
||||
/*
|
||||
$arrayofmassactions = array(
|
||||
'presend'=>$langs->trans("SendByMail"),
|
||||
'builddoc'=>$langs->trans("PDFMerge"),
|
||||
'presend'=>$langs->trans("SendByMail"),
|
||||
'builddoc'=>$langs->trans("PDFMerge"),
|
||||
);
|
||||
if ($user->rights->product->supprimer) $arrayofmassactions['predelete']='<span class="fa fa-trash paddingrightonly"></span>'.$langs->trans("Delete");
|
||||
if (in_array($massaction, array('presend','predelete'))) $arrayofmassactions=array();
|
||||
@ -800,8 +796,7 @@ if (!empty($id) || !empty($ref))
|
||||
*/
|
||||
|
||||
$aaa = '';
|
||||
if (count($productCombinations))
|
||||
{
|
||||
if (count($productCombinations)) {
|
||||
$aaa = '<label for="massaction">'.$langs->trans('BulkActions').'</label>';
|
||||
$aaa .= '<select id="bulk_action" name="massaction" class="flat">';
|
||||
$aaa .= ' <option value="nothing"> </option>';
|
||||
@ -826,11 +821,13 @@ if (!empty($id) || !empty($ref))
|
||||
<td class="liste_titre"><?php echo $langs->trans('Product') ?></td>
|
||||
<td class="liste_titre"><?php echo $langs->trans('Combination') ?></td>
|
||||
<td class="liste_titre right"><?php echo $langs->trans('PriceImpact') ?></td>
|
||||
<?php if ($object->isProduct()) print'<td class="liste_titre right">'.$langs->trans('WeightImpact').'</td>'; ?>
|
||||
<?php if ($object->isProduct()) {
|
||||
print'<td class="liste_titre right">'.$langs->trans('WeightImpact').'</td>';
|
||||
} ?>
|
||||
<td class="liste_titre center"><?php echo $langs->trans('OnSell') ?></td>
|
||||
<td class="liste_titre center"><?php echo $langs->trans('OnBuy') ?></td>
|
||||
<td class="liste_titre"></td>
|
||||
<?php
|
||||
<?php
|
||||
print '<td class="liste_titre center">';
|
||||
$searchpicto = $form->showCheckAddButtons('checkforselect', 1);
|
||||
print $searchpicto;
|
||||
@ -839,10 +836,8 @@ if (!empty($id) || !empty($ref))
|
||||
</tr>
|
||||
<?php
|
||||
|
||||
if (count($productCombinations))
|
||||
{
|
||||
foreach ($productCombinations as $currcomb)
|
||||
{
|
||||
if (count($productCombinations)) {
|
||||
foreach ($productCombinations as $currcomb) {
|
||||
$prodstatic->fetch($currcomb->fk_product_child);
|
||||
print '<tr class="oddeven">';
|
||||
print '<td>'.$prodstatic->getNomUrl(1).'</td>';
|
||||
@ -869,10 +864,11 @@ if (!empty($id) || !empty($ref))
|
||||
print '<a class="paddingleft paddingright" href="'.$_SERVER["PHP_SELF"].'?id='.$id.'&action=delete&token='.newToken().'&valueid='.$currcomb->id.'">'.img_delete().'</a>';
|
||||
print '</td>';
|
||||
print '<td class="nowrap center">';
|
||||
if ($productCombinations || $massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
|
||||
{
|
||||
if ($productCombinations || $massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
|
||||
$selected = 0;
|
||||
if (in_array($prodstatic->id, $arrayofselected)) $selected = 1;
|
||||
if (in_array($prodstatic->id, $arrayofselected)) {
|
||||
$selected = 1;
|
||||
}
|
||||
print '<input id="cb'.$prodstatic->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$prodstatic->id.'"'.($selected ? ' checked="checked"' : '').'>';
|
||||
}
|
||||
print '</td>';
|
||||
|
||||
@ -40,8 +40,7 @@ if ($action == 'add') {
|
||||
$resid = $prodattr->create($user);
|
||||
if ($resid > 0) {
|
||||
setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
|
||||
if ($backtopage)
|
||||
{
|
||||
if ($backtopage) {
|
||||
header('Location: '.$backtopage);
|
||||
} else {
|
||||
header('Location: '.DOL_URL_ROOT.'/variants/card.php?id='.$resid.'&backtopage='.urlencode($backtopage));
|
||||
|
||||
@ -41,8 +41,7 @@ if ($object->fetch($id) < 1) {
|
||||
* Actions
|
||||
*/
|
||||
|
||||
if ($cancel)
|
||||
{
|
||||
if ($cancel) {
|
||||
$action = '';
|
||||
header('Location: '.DOL_URL_ROOT.'/variants/card.php?id='.$object->id);
|
||||
exit();
|
||||
@ -56,8 +55,7 @@ if ($cancel)
|
||||
* View
|
||||
*/
|
||||
|
||||
if ($action == 'add')
|
||||
{
|
||||
if ($action == 'add') {
|
||||
if (empty($ref) || empty($value)) {
|
||||
setEventMessages($langs->trans('ErrorFieldsRequired'), null, 'errors');
|
||||
} else {
|
||||
|
||||
@ -56,8 +56,7 @@ $variants = $object->fetchAll();
|
||||
llxHeader('', $title);
|
||||
|
||||
$newcardbutton = '';
|
||||
if ($user->rights->produit->creer)
|
||||
{
|
||||
if ($user->rights->produit->creer) {
|
||||
$newcardbutton .= dolGetButtonTitle($langs->trans('Create'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/variants/create.php');
|
||||
}
|
||||
|
||||
|
||||
@ -29,26 +29,24 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
|
||||
|
||||
$langs->load("admin");
|
||||
|
||||
if (!$user->admin)
|
||||
if (!$user->admin) {
|
||||
accessforbidden();
|
||||
}
|
||||
|
||||
$actionsave = GETPOST("save");
|
||||
|
||||
// Sauvegardes parametres
|
||||
if ($actionsave)
|
||||
{
|
||||
if ($actionsave) {
|
||||
$i = 0;
|
||||
|
||||
$db->begin();
|
||||
|
||||
$i += dolibarr_set_const($db, 'WEBSERVICES_KEY', GETPOST("WEBSERVICES_KEY"), 'chaine', 0, '', $conf->entity);
|
||||
|
||||
if ($i >= 1)
|
||||
{
|
||||
if ($i >= 1) {
|
||||
$db->commit();
|
||||
setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$db->rollback();
|
||||
setEventMessages($langs->trans("Error"), null, 'errors');
|
||||
}
|
||||
@ -84,8 +82,9 @@ print "</tr>";
|
||||
print '<tr class="oddeven">';
|
||||
print '<td class="fieldrequired">'.$langs->trans("KeyForWebServicesAccess").'</td>';
|
||||
print '<td><input type="text" class="flat" id="WEBSERVICES_KEY" name="WEBSERVICES_KEY" value="'.(GETPOST('WEBSERVICES_KEY') ?GETPOST('WEBSERVICES_KEY') : (!empty($conf->global->WEBSERVICES_KEY) ? $conf->global->WEBSERVICES_KEY : '')).'" size="40">';
|
||||
if (!empty($conf->use_javascript_ajax))
|
||||
if (!empty($conf->use_javascript_ajax)) {
|
||||
print ' '.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token" class="linkobject"');
|
||||
}
|
||||
print '</td>';
|
||||
print '<td> </td>';
|
||||
print '</tr>';
|
||||
@ -118,9 +117,10 @@ $webservices = array(
|
||||
|
||||
// WSDL
|
||||
print '<u>'.$langs->trans("WSDLCanBeDownloadedHere").':</u><br>';
|
||||
foreach ($webservices as $name => $right)
|
||||
{
|
||||
if (!empty($right) && !verifCond($right)) continue;
|
||||
foreach ($webservices as $name => $right) {
|
||||
if (!empty($right) && !verifCond($right)) {
|
||||
continue;
|
||||
}
|
||||
$url = DOL_MAIN_URL_ROOT.'/webservices/server_'.$name.'.php?wsdl';
|
||||
print img_picto('', 'globe').' <a href="'.$url.'" target="_blank">'.$url."</a><br>\n";
|
||||
}
|
||||
@ -129,9 +129,10 @@ print '<br>';
|
||||
|
||||
// Endpoint
|
||||
print '<u>'.$langs->trans("EndPointIs").':</u><br>';
|
||||
foreach ($webservices as $name => $right)
|
||||
{
|
||||
if (!empty($right) && !verifCond($right)) continue;
|
||||
foreach ($webservices as $name => $right) {
|
||||
if (!empty($right) && !verifCond($right)) {
|
||||
continue;
|
||||
}
|
||||
$url = DOL_MAIN_URL_ROOT.'/webservices/server_'.$name.'.php';
|
||||
print img_picto('', 'globe').' <a href="'.$url.'" target="_blank">'.$url."</a><br>\n";
|
||||
}
|
||||
@ -141,8 +142,7 @@ print '<br>';
|
||||
print '<br>';
|
||||
print $langs->trans("OnlyActiveElementsAreShown", DOL_URL_ROOT.'/admin/modules.php');
|
||||
|
||||
if (!empty($conf->use_javascript_ajax))
|
||||
{
|
||||
if (!empty($conf->use_javascript_ajax)) {
|
||||
print "\n".'<script type="text/javascript">';
|
||||
print '$(document).ready(function () {
|
||||
$("#generate_token").click(function() {
|
||||
|
||||
@ -38,8 +38,7 @@ $langs->load("admin");
|
||||
dol_syslog("Call Dolibarr webservices interfaces");
|
||||
|
||||
// Enable and test if module web services is enabled
|
||||
if (empty($conf->global->MAIN_MODULE_WEBSERVICES))
|
||||
{
|
||||
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>';
|
||||
|
||||
@ -23,7 +23,9 @@
|
||||
* \brief File that is entry point to call Dolibarr WebServices
|
||||
*/
|
||||
|
||||
if (!defined("NOCSRFCHECK")) define("NOCSRFCHECK", '1');
|
||||
if (!defined("NOCSRFCHECK")) {
|
||||
define("NOCSRFCHECK", '1');
|
||||
}
|
||||
|
||||
require "../master.inc.php";
|
||||
require_once NUSOAP_PATH.'/nusoap.php'; // Include SOAP
|
||||
@ -37,8 +39,7 @@ 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))
|
||||
{
|
||||
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>';
|
||||
@ -122,18 +123,21 @@ $extrafield_array = null;
|
||||
if (is_array($extrafields) && count($extrafields) > 0) {
|
||||
$extrafield_array = array();
|
||||
}
|
||||
if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label']))
|
||||
{
|
||||
foreach ($extrafields->attributes[$elementtype]['label'] as $key=>$label)
|
||||
{
|
||||
if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) {
|
||||
foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) {
|
||||
$type = $extrafields->attributes[$elementtype]['type'][$key];
|
||||
if ($type == 'date' || $type == 'datetime') {$type = 'xsd:dateTime'; }
|
||||
else {$type = 'xsd:string'; }
|
||||
if ($type == 'date' || $type == 'datetime') {
|
||||
$type = 'xsd:dateTime';
|
||||
} else {
|
||||
$type = 'xsd:string';
|
||||
}
|
||||
|
||||
$extrafield_array['options_'.$key] = array('name'=>'options_'.$key, 'type'=>$type);
|
||||
}
|
||||
}
|
||||
if (is_array($extrafield_array)) $actioncomm_fields = array_merge($actioncomm_fields, $extrafield_array);
|
||||
if (is_array($extrafield_array)) {
|
||||
$actioncomm_fields = array_merge($actioncomm_fields, $extrafield_array);
|
||||
}
|
||||
|
||||
// Define other specific objects
|
||||
$server->wsdl->addComplexType(
|
||||
@ -255,7 +259,9 @@ function getActionComm($authentication, $id)
|
||||
|
||||
dol_syslog("Function: getActionComm login=".$authentication['login']." id=".$id);
|
||||
|
||||
if ($authentication['entity']) $conf->entity = $authentication['entity'];
|
||||
if ($authentication['entity']) {
|
||||
$conf->entity = $authentication['entity'];
|
||||
}
|
||||
|
||||
// Init and check authentication
|
||||
$objectresp = array();
|
||||
@ -263,22 +269,18 @@ function getActionComm($authentication, $id)
|
||||
$error = 0;
|
||||
$fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
|
||||
// Check parameters
|
||||
if ($error || (!$id))
|
||||
{
|
||||
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)
|
||||
{
|
||||
if (!$error) {
|
||||
$fuser->getrights();
|
||||
|
||||
if ($fuser->rights->agenda->allactions->read)
|
||||
{
|
||||
if ($fuser->rights->agenda->allactions->read) {
|
||||
$actioncomm = new ActionComm($db);
|
||||
$result = $actioncomm->fetch($id);
|
||||
if ($result > 0)
|
||||
{
|
||||
if ($result > 0) {
|
||||
$actioncomm_result_fields = array(
|
||||
'id' => $actioncomm->id,
|
||||
'ref'=> $actioncomm->ref,
|
||||
@ -315,10 +317,8 @@ function getActionComm($authentication, $id)
|
||||
//Get extrafield values
|
||||
$actioncomm->fetch_optionals();
|
||||
|
||||
if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label']))
|
||||
{
|
||||
foreach ($extrafields->attributes[$elementtype]['label'] as $key=>$label)
|
||||
{
|
||||
if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) {
|
||||
foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) {
|
||||
$actioncomm_result_fields = array_merge($actioncomm_result_fields, array('options_'.$key => $actioncomm->array_options['options_'.$key]));
|
||||
}
|
||||
}
|
||||
@ -327,20 +327,17 @@ function getActionComm($authentication, $id)
|
||||
$objectresp = array(
|
||||
'result'=>array('result_code'=>'OK', 'result_label'=>''),
|
||||
'actioncomm'=>$actioncomm_result_fields);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$error++;
|
||||
$errorcode = 'NOT_FOUND'; $errorlabel = 'Object not found for id='.$id.' nor ref='.$ref.' nor ref_ext='.$ref_ext;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$error++;
|
||||
$errorcode = 'PERMISSION_DENIED'; $errorlabel = 'User does not have permission for this request';
|
||||
}
|
||||
}
|
||||
|
||||
if ($error)
|
||||
{
|
||||
if ($error) {
|
||||
$objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
|
||||
}
|
||||
|
||||
@ -360,7 +357,9 @@ function getListActionCommType($authentication)
|
||||
|
||||
dol_syslog("Function: getListActionCommType login=".$authentication['login']);
|
||||
|
||||
if ($authentication['entity']) $conf->entity = $authentication['entity'];
|
||||
if ($authentication['entity']) {
|
||||
$conf->entity = $authentication['entity'];
|
||||
}
|
||||
|
||||
// Init and check authentication
|
||||
$objectresp = array();
|
||||
@ -368,18 +367,15 @@ function getListActionCommType($authentication)
|
||||
$error = 0;
|
||||
$fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
if (!$error) {
|
||||
$fuser->getrights();
|
||||
|
||||
if ($fuser->rights->agenda->myactions->read)
|
||||
{
|
||||
if ($fuser->rights->agenda->myactions->read) {
|
||||
$cactioncomm = new CActionComm($db);
|
||||
$result = $cactioncomm->liste_array('', 'code');
|
||||
if ($result > 0)
|
||||
{
|
||||
if ($result > 0) {
|
||||
$resultarray = array();
|
||||
foreach ($cactioncomm->liste_array as $code=>$libeller) {
|
||||
foreach ($cactioncomm->liste_array as $code => $libeller) {
|
||||
$resultarray[] = array('code'=>$code, 'libelle'=>$libeller);
|
||||
}
|
||||
|
||||
@ -396,8 +392,7 @@ function getListActionCommType($authentication)
|
||||
}
|
||||
}
|
||||
|
||||
if ($error)
|
||||
{
|
||||
if ($error) {
|
||||
$objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
|
||||
}
|
||||
|
||||
@ -420,7 +415,9 @@ function createActionComm($authentication, $actioncomm)
|
||||
|
||||
dol_syslog("Function: createActionComm login=".$authentication['login']);
|
||||
|
||||
if ($authentication['entity']) $conf->entity = $authentication['entity'];
|
||||
if ($authentication['entity']) {
|
||||
$conf->entity = $authentication['entity'];
|
||||
}
|
||||
|
||||
// Init and check authentication
|
||||
$objectresp = array();
|
||||
@ -428,8 +425,7 @@ function createActionComm($authentication, $actioncomm)
|
||||
$error = 0;
|
||||
$fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
if (!$error) {
|
||||
$newobject = new ActionComm($db);
|
||||
|
||||
$newobject->datep = $actioncomm['datep'];
|
||||
@ -454,10 +450,8 @@ function createActionComm($authentication, $actioncomm)
|
||||
// fetch optionals attributes and labels
|
||||
$extrafields = new ExtraFields($db);
|
||||
$extrafields->fetch_name_optionals_label($elementtype, true);
|
||||
if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label']))
|
||||
{
|
||||
foreach ($extrafields->attributes[$elementtype]['label'] as $key=>$label)
|
||||
{
|
||||
if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) {
|
||||
foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) {
|
||||
$key = 'options_'.$key;
|
||||
$newobject->array_options[$key] = $actioncomm[$key];
|
||||
}
|
||||
@ -466,17 +460,14 @@ function createActionComm($authentication, $actioncomm)
|
||||
$db->begin();
|
||||
|
||||
$result = $newobject->create($fuser);
|
||||
if ($result <= 0)
|
||||
{
|
||||
if ($result <= 0) {
|
||||
$error++;
|
||||
}
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
if (!$error) {
|
||||
$db->commit();
|
||||
$objectresp = array('result'=>array('result_code'=>'OK', 'result_label'=>''), 'id'=>$newobject->id);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$db->rollback();
|
||||
$error++;
|
||||
$errorcode = 'KO';
|
||||
@ -484,8 +475,7 @@ function createActionComm($authentication, $actioncomm)
|
||||
}
|
||||
}
|
||||
|
||||
if ($error)
|
||||
{
|
||||
if ($error) {
|
||||
$objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
|
||||
}
|
||||
|
||||
@ -507,7 +497,9 @@ function updateActionComm($authentication, $actioncomm)
|
||||
|
||||
dol_syslog("Function: updateActionComm login=".$authentication['login']);
|
||||
|
||||
if ($authentication['entity']) $conf->entity = $authentication['entity'];
|
||||
if ($authentication['entity']) {
|
||||
$conf->entity = $authentication['entity'];
|
||||
}
|
||||
|
||||
// Init and check authentication
|
||||
$objectresp = array();
|
||||
@ -519,8 +511,7 @@ function updateActionComm($authentication, $actioncomm)
|
||||
$error++; $errorcode = 'KO'; $errorlabel = "Actioncomm id is mandatory.";
|
||||
}
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
if (!$error) {
|
||||
$objectfound = false;
|
||||
|
||||
$object = new ActionComm($db);
|
||||
@ -551,10 +542,8 @@ function updateActionComm($authentication, $actioncomm)
|
||||
// fetch optionals attributes and labels
|
||||
$extrafields = new ExtraFields($db);
|
||||
$extrafields->fetch_name_optionals_label($elementtype, true);
|
||||
if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label']))
|
||||
{
|
||||
foreach ($extrafields->attributes[$elementtype]['label'] as $key=>$label)
|
||||
{
|
||||
if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) {
|
||||
foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) {
|
||||
$key = 'options_'.$key;
|
||||
$object->array_options[$key] = $actioncomm[$key];
|
||||
}
|
||||
@ -568,16 +557,13 @@ function updateActionComm($authentication, $actioncomm)
|
||||
}
|
||||
}
|
||||
|
||||
if ((!$error) && ($objectfound))
|
||||
{
|
||||
if ((!$error) && ($objectfound)) {
|
||||
$db->commit();
|
||||
$objectresp = array(
|
||||
'result'=>array('result_code'=>'OK', 'result_label'=>''),
|
||||
'id'=>$object->id
|
||||
);
|
||||
}
|
||||
elseif ($objectfound)
|
||||
{
|
||||
} elseif ($objectfound) {
|
||||
$db->rollback();
|
||||
$error++;
|
||||
$errorcode = 'KO';
|
||||
@ -589,8 +575,7 @@ function updateActionComm($authentication, $actioncomm)
|
||||
}
|
||||
}
|
||||
|
||||
if ($error)
|
||||
{
|
||||
if ($error) {
|
||||
$objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
|
||||
}
|
||||
|
||||
|
||||
@ -21,7 +21,9 @@
|
||||
* \brief File that is entry point to call Dolibarr WebServices
|
||||
*/
|
||||
|
||||
if (!defined("NOCSRFCHECK")) define("NOCSRFCHECK", '1');
|
||||
if (!defined("NOCSRFCHECK")) {
|
||||
define("NOCSRFCHECK", '1');
|
||||
}
|
||||
|
||||
require "../master.inc.php";
|
||||
require_once NUSOAP_PATH.'/nusoap.php'; // Include SOAP
|
||||
@ -32,8 +34,7 @@ require_once DOL_DOCUMENT_ROOT."/categories/class/categorie.class.php";
|
||||
dol_syslog("Call Dolibarr webservices interfaces");
|
||||
|
||||
// Enable and test if module web services is enabled
|
||||
if (empty($conf->global->MAIN_MODULE_WEBSERVICES))
|
||||
{
|
||||
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>';
|
||||
@ -109,12 +110,12 @@ $server->wsdl->addComplexType(
|
||||
* Image of product
|
||||
*/
|
||||
$server->wsdl->addComplexType(
|
||||
'PhotosArray',
|
||||
'complexType',
|
||||
'array',
|
||||
'sequence',
|
||||
'',
|
||||
array(
|
||||
'PhotosArray',
|
||||
'complexType',
|
||||
'array',
|
||||
'sequence',
|
||||
'',
|
||||
array(
|
||||
'image' => array(
|
||||
'name' => 'image',
|
||||
'type' => 'tns:image',
|
||||
@ -128,12 +129,12 @@ $server->wsdl->addComplexType(
|
||||
* An image
|
||||
*/
|
||||
$server->wsdl->addComplexType(
|
||||
'image',
|
||||
'complexType',
|
||||
'struct',
|
||||
'all',
|
||||
'',
|
||||
array(
|
||||
'image',
|
||||
'complexType',
|
||||
'struct',
|
||||
'all',
|
||||
'',
|
||||
array(
|
||||
'photo' => array('name'=>'photo', 'type'=>'xsd:string'),
|
||||
'photo_vignette' => array('name'=>'photo_vignette', 'type'=>'xsd:string'),
|
||||
'imgWidth' => array('name'=>'imgWidth', 'type'=>'xsd:string'),
|
||||
@ -194,30 +195,28 @@ function getCategory($authentication, $id)
|
||||
|
||||
dol_syslog("Function: getCategory login=".$authentication['login']." id=".$id);
|
||||
|
||||
if ($authentication['entity']) $conf->entity = $authentication['entity'];
|
||||
if ($authentication['entity']) {
|
||||
$conf->entity = $authentication['entity'];
|
||||
}
|
||||
|
||||
$objectresp = array();
|
||||
$errorcode = ''; $errorlabel = '';
|
||||
$error = 0;
|
||||
$fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
|
||||
|
||||
if (!$error && !$id)
|
||||
{
|
||||
if (!$error && !$id) {
|
||||
$error++;
|
||||
$errorcode = 'BAD_PARAMETERS'; $errorlabel = "Parameter id must be provided.";
|
||||
}
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
if (!$error) {
|
||||
$fuser->getrights();
|
||||
|
||||
$nbmax = 10;
|
||||
if ($fuser->rights->categorie->lire)
|
||||
{
|
||||
if ($fuser->rights->categorie->lire) {
|
||||
$categorie = new Categorie($db);
|
||||
$result = $categorie->fetch($id);
|
||||
if ($result > 0)
|
||||
{
|
||||
if ($result > 0) {
|
||||
$dir = (!empty($conf->categorie->dir_output) ? $conf->categorie->dir_output : $conf->service->dir_output);
|
||||
$pdir = get_exdir($categorie->id, 2, 0, 0, $categorie, 'category').$categorie->id."/photos/";
|
||||
$dir = $dir.'/'.$pdir;
|
||||
@ -235,10 +234,8 @@ function getCategory($authentication, $id)
|
||||
);
|
||||
|
||||
$cats = $categorie->get_filles();
|
||||
if (count($cats) > 0)
|
||||
{
|
||||
foreach ($cats as $fille)
|
||||
{
|
||||
if (count($cats) > 0) {
|
||||
foreach ($cats as $fille) {
|
||||
$dir = (!empty($conf->categorie->dir_output) ? $conf->categorie->dir_output : $conf->service->dir_output);
|
||||
$pdir = get_exdir($fille->id, 2, 0, 0, $categorie, 'category').$fille->id."/photos/";
|
||||
$dir = $dir.'/'.$pdir;
|
||||
@ -261,20 +258,17 @@ function getCategory($authentication, $id)
|
||||
'result'=>array('result_code'=>'OK', 'result_label'=>''),
|
||||
'categorie'=> $cat
|
||||
);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$error++;
|
||||
$errorcode = 'NOT_FOUND'; $errorlabel = 'Object not found for id='.$id;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$error++;
|
||||
$errorcode = 'PERMISSION_DENIED'; $errorlabel = 'User does not have permission for this request';
|
||||
}
|
||||
}
|
||||
|
||||
if ($error)
|
||||
{
|
||||
if ($error) {
|
||||
$objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
|
||||
}
|
||||
|
||||
|
||||
@ -21,7 +21,9 @@
|
||||
* \brief File that is entry point to call Dolibarr WebServices
|
||||
*/
|
||||
|
||||
if (!defined("NOCSRFCHECK")) define("NOCSRFCHECK", '1');
|
||||
if (!defined("NOCSRFCHECK")) {
|
||||
define("NOCSRFCHECK", '1');
|
||||
}
|
||||
|
||||
require "../master.inc.php";
|
||||
require_once NUSOAP_PATH.'/nusoap.php'; // Include SOAP
|
||||
@ -33,8 +35,7 @@ require_once DOL_DOCUMENT_ROOT."/core/class/extrafields.class.php";
|
||||
dol_syslog("Call Contact webservices interfaces");
|
||||
|
||||
// Enable and test if module web services is enabled
|
||||
if (empty($conf->global->MAIN_MODULE_WEBSERVICES))
|
||||
{
|
||||
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>';
|
||||
@ -127,18 +128,21 @@ $extrafield_array = null;
|
||||
if (is_array($extrafields) && count($extrafields) > 0) {
|
||||
$extrafield_array = array();
|
||||
}
|
||||
if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label']))
|
||||
{
|
||||
foreach ($extrafields->attributes[$elementtype]['label'] as $key=>$label)
|
||||
{
|
||||
if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) {
|
||||
foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) {
|
||||
$type = $extrafields->attributes[$elementtype]['type'][$key];
|
||||
if ($type == 'date' || $type == 'datetime') {$type = 'xsd:dateTime'; }
|
||||
else {$type = 'xsd:string'; }
|
||||
if ($type == 'date' || $type == 'datetime') {
|
||||
$type = 'xsd:dateTime';
|
||||
} else {
|
||||
$type = 'xsd:string';
|
||||
}
|
||||
|
||||
$extrafield_array['options_'.$key] = array('name'=>'options_'.$key, 'type'=>$type);
|
||||
}
|
||||
}
|
||||
if (is_array($extrafield_array)) $contact_fields = array_merge($contact_fields, $extrafield_array);
|
||||
if (is_array($extrafield_array)) {
|
||||
$contact_fields = array_merge($contact_fields, $extrafield_array);
|
||||
}
|
||||
|
||||
// Define other specific objects
|
||||
$server->wsdl->addComplexType(
|
||||
@ -247,7 +251,9 @@ function getContact($authentication, $id, $ref_ext)
|
||||
|
||||
dol_syslog("Function: getContact login=".$authentication['login']." id=".$id." ref_ext=".$ref_ext);
|
||||
|
||||
if ($authentication['entity']) $conf->entity = $authentication['entity'];
|
||||
if ($authentication['entity']) {
|
||||
$conf->entity = $authentication['entity'];
|
||||
}
|
||||
|
||||
// Init and check authentication
|
||||
$objectresp = array();
|
||||
@ -255,24 +261,20 @@ function getContact($authentication, $id, $ref_ext)
|
||||
$error = 0;
|
||||
$fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
|
||||
// Check parameters
|
||||
if (!$error && ($id && $ref_ext))
|
||||
{
|
||||
if (!$error && ($id && $ref_ext)) {
|
||||
$error++;
|
||||
$errorcode = 'BAD_PARAMETERS'; $errorlabel = "Parameter id and ref_ext can't be both provided. You must choose one or other but not both.";
|
||||
}
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
if (!$error) {
|
||||
$fuser->getrights();
|
||||
|
||||
$contact = new Contact($db);
|
||||
$result = $contact->fetch($id, 0, $ref_ext);
|
||||
if ($result > 0)
|
||||
{
|
||||
if ($result > 0) {
|
||||
// Only internal user who have contact read permission
|
||||
// Or for external user who have contact read permission, with restrict on socid
|
||||
if (
|
||||
$fuser->rights->societe->contact->lire && !$fuser->socid
|
||||
if ($fuser->rights->societe->contact->lire && !$fuser->socid
|
||||
|| ($fuser->rights->societe->contact->lire && ($fuser->socid == $contact->socid))
|
||||
) {
|
||||
$contact_result_fields = array(
|
||||
@ -319,10 +321,8 @@ function getContact($authentication, $id, $ref_ext)
|
||||
//Get extrafield values
|
||||
$contact->fetch_optionals();
|
||||
|
||||
if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label']))
|
||||
{
|
||||
foreach ($extrafields->attributes[$elementtype]['label'] as $key=>$label)
|
||||
{
|
||||
if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) {
|
||||
foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) {
|
||||
$contact_result_fields = array_merge($contact_result_fields, array('options_'.$key => $contact->array_options['options_'.$key]));
|
||||
}
|
||||
}
|
||||
@ -332,20 +332,17 @@ function getContact($authentication, $id, $ref_ext)
|
||||
'result'=>array('result_code'=>'OK', 'result_label'=>''),
|
||||
'contact'=>$contact_result_fields
|
||||
);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$error++;
|
||||
$errorcode = 'PERMISSION_DENIED'; $errorlabel = 'User does not have permission for this request';
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$error++;
|
||||
$errorcode = 'NOT_FOUND'; $errorlabel = 'Object not found for id='.$id.' nor ref_ext='.$ref_ext;
|
||||
}
|
||||
}
|
||||
|
||||
if ($error)
|
||||
{
|
||||
if ($error) {
|
||||
$objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
|
||||
}
|
||||
|
||||
@ -368,7 +365,9 @@ function createContact($authentication, $contact)
|
||||
|
||||
dol_syslog("Function: createContact login=".$authentication['login']);
|
||||
|
||||
if ($authentication['entity']) $conf->entity = $authentication['entity'];
|
||||
if ($authentication['entity']) {
|
||||
$conf->entity = $authentication['entity'];
|
||||
}
|
||||
|
||||
// Init and check authentication
|
||||
$objectresp = array();
|
||||
@ -376,13 +375,11 @@ function createContact($authentication, $contact)
|
||||
$error = 0;
|
||||
$fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
|
||||
// Check parameters
|
||||
if (empty($contact['lastname']))
|
||||
{
|
||||
if (empty($contact['lastname'])) {
|
||||
$error++; $errorcode = 'KO'; $errorlabel = "Name is mandatory.";
|
||||
}
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
if (!$error) {
|
||||
$newobject = new Contact($db);
|
||||
|
||||
$newobject->id = $contact['id'];
|
||||
@ -424,10 +421,8 @@ function createContact($authentication, $contact)
|
||||
// fetch optionals attributes and labels
|
||||
$extrafields = new ExtraFields($db);
|
||||
$extrafields->fetch_name_optionals_label($elementtype, true);
|
||||
if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label']))
|
||||
{
|
||||
foreach ($extrafields->attributes[$elementtype]['label'] as $key=>$label)
|
||||
{
|
||||
if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) {
|
||||
foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) {
|
||||
$key = 'options_'.$key;
|
||||
$newobject->array_options[$key] = $contact[$key];
|
||||
}
|
||||
@ -439,17 +434,14 @@ function createContact($authentication, $contact)
|
||||
$db->begin();
|
||||
|
||||
$result = $newobject->create($fuser);
|
||||
if ($result <= 0)
|
||||
{
|
||||
if ($result <= 0) {
|
||||
$error++;
|
||||
}
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
if (!$error) {
|
||||
$db->commit();
|
||||
$objectresp = array('result'=>array('result_code'=>'OK', 'result_label'=>''), 'id'=>$newobject->id, 'ref'=>$newobject->ref);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$db->rollback();
|
||||
$error++;
|
||||
$errorcode = 'KO';
|
||||
@ -457,8 +449,7 @@ function createContact($authentication, $contact)
|
||||
}
|
||||
}
|
||||
|
||||
if ($error)
|
||||
{
|
||||
if ($error) {
|
||||
$objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
|
||||
}
|
||||
|
||||
@ -478,7 +469,9 @@ function getContactsForThirdParty($authentication, $idthirdparty)
|
||||
|
||||
dol_syslog("Function: getContactsForThirdParty login=".$authentication['login']." idthirdparty=".$idthirdparty);
|
||||
|
||||
if ($authentication['entity']) $conf->entity = $authentication['entity'];
|
||||
if ($authentication['entity']) {
|
||||
$conf->entity = $authentication['entity'];
|
||||
}
|
||||
|
||||
// Init and check authentication
|
||||
$objectresp = array();
|
||||
@ -486,14 +479,12 @@ function getContactsForThirdParty($authentication, $idthirdparty)
|
||||
$error = 0;
|
||||
$fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
|
||||
// Check parameters
|
||||
if (!$error && empty($idthirdparty))
|
||||
{
|
||||
if (!$error && empty($idthirdparty)) {
|
||||
$error++;
|
||||
$errorcode = 'BAD_PARAMETERS'; $errorlabel = 'Parameter id is not provided';
|
||||
}
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
if (!$error) {
|
||||
$linesinvoice = array();
|
||||
|
||||
$sql = "SELECT c.rowid, c.fk_soc, c.civility as civility_id, c.lastname, c.firstname, c.statut as status,";
|
||||
@ -515,12 +506,10 @@ function getContactsForThirdParty($authentication, $idthirdparty)
|
||||
$sql .= " WHERE c.fk_soc = ".$idthirdparty;
|
||||
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
if ($resql) {
|
||||
$num = $db->num_rows($resql);
|
||||
$i = 0;
|
||||
while ($i < $num)
|
||||
{
|
||||
while ($i < $num) {
|
||||
// En attendant remplissage par boucle
|
||||
$obj = $db->fetch_object($resql);
|
||||
|
||||
@ -580,15 +569,13 @@ function getContactsForThirdParty($authentication, $idthirdparty)
|
||||
'contacts'=>$linescontact
|
||||
|
||||
);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$error++;
|
||||
$errorcode = $db->lasterrno(); $errorlabel = $db->lasterror();
|
||||
}
|
||||
}
|
||||
|
||||
if ($error)
|
||||
{
|
||||
if ($error) {
|
||||
$objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
|
||||
}
|
||||
|
||||
@ -611,7 +598,9 @@ function updateContact($authentication, $contact)
|
||||
|
||||
dol_syslog("Function: updateContact login=".$authentication['login']);
|
||||
|
||||
if ($authentication['entity']) $conf->entity = $authentication['entity'];
|
||||
if ($authentication['entity']) {
|
||||
$conf->entity = $authentication['entity'];
|
||||
}
|
||||
|
||||
// Init and check authentication
|
||||
$objectresp = array();
|
||||
@ -623,14 +612,12 @@ function updateContact($authentication, $contact)
|
||||
$error++; $errorcode = 'KO'; $errorlabel = "Contact id or ref_ext is mandatory.";
|
||||
}
|
||||
// Check parameters
|
||||
if (!$error && ($id && $ref_ext))
|
||||
{
|
||||
if (!$error && ($id && $ref_ext)) {
|
||||
$error++;
|
||||
$errorcode = 'BAD_PARAMETERS'; $errorlabel = "Parameter id and ref_ext can't be all provided. You must choose one of them.";
|
||||
}
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
if (!$error) {
|
||||
$objectfound = false;
|
||||
|
||||
include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
|
||||
@ -650,7 +637,9 @@ function updateContact($authentication, $contact)
|
||||
$object->town = $contact['town'];
|
||||
|
||||
$object->country_id = $contact['country_id'];
|
||||
if ($contact['country_code']) $object->country_id = getCountry($contact['country_code'], 3);
|
||||
if ($contact['country_code']) {
|
||||
$object->country_id = getCountry($contact['country_code'], 3);
|
||||
}
|
||||
$object->province_id = $contact['province_id'];
|
||||
|
||||
|
||||
@ -671,10 +660,8 @@ function updateContact($authentication, $contact)
|
||||
// fetch optionals attributes and labels
|
||||
$extrafields = new ExtraFields($db);
|
||||
$extrafields->fetch_name_optionals_label($elementtype, true);
|
||||
if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label']))
|
||||
{
|
||||
foreach ($extrafields->attributes[$elementtype]['label'] as $key=>$label)
|
||||
{
|
||||
if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) {
|
||||
foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) {
|
||||
$key = 'options_'.$key;
|
||||
$object->array_options[$key] = $contact[$key];
|
||||
}
|
||||
@ -688,16 +675,13 @@ function updateContact($authentication, $contact)
|
||||
}
|
||||
}
|
||||
|
||||
if ((!$error) && ($objectfound))
|
||||
{
|
||||
if ((!$error) && ($objectfound)) {
|
||||
$db->commit();
|
||||
$objectresp = array(
|
||||
'result'=>array('result_code'=>'OK', 'result_label'=>''),
|
||||
'id'=>$object->id
|
||||
);
|
||||
}
|
||||
elseif ($objectfound)
|
||||
{
|
||||
} elseif ($objectfound) {
|
||||
$db->rollback();
|
||||
$error++;
|
||||
$errorcode = 'KO';
|
||||
@ -709,8 +693,7 @@ function updateContact($authentication, $contact)
|
||||
}
|
||||
}
|
||||
|
||||
if ($error)
|
||||
{
|
||||
if ($error) {
|
||||
$objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
|
||||
}
|
||||
|
||||
|
||||
@ -21,7 +21,9 @@
|
||||
* \brief File that is entry point to call Dolibarr WebServices
|
||||
*/
|
||||
|
||||
if (!defined("NOCSRFCHECK")) define("NOCSRFCHECK", '1');
|
||||
if (!defined("NOCSRFCHECK")) {
|
||||
define("NOCSRFCHECK", '1');
|
||||
}
|
||||
|
||||
require '../master.inc.php';
|
||||
require_once NUSOAP_PATH.'/nusoap.php'; // Include SOAP
|
||||
@ -38,8 +40,7 @@ dol_syslog("Call Dolibarr webservices interfaces");
|
||||
$langs->load("main");
|
||||
|
||||
// Enable and test if module web services is enabled
|
||||
if (empty($conf->global->MAIN_MODULE_WEBSERVICES))
|
||||
{
|
||||
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>';
|
||||
@ -112,16 +113,16 @@ $server->wsdl->addComplexType(
|
||||
);
|
||||
|
||||
/*$server->wsdl->addComplexType(
|
||||
'LinesArray',
|
||||
'complexType',
|
||||
'array',
|
||||
'',
|
||||
'SOAP-ENC:Array',
|
||||
array(),
|
||||
array(
|
||||
array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:line[]')
|
||||
),
|
||||
'tns:line'
|
||||
'LinesArray',
|
||||
'complexType',
|
||||
'array',
|
||||
'',
|
||||
'SOAP-ENC:Array',
|
||||
array(),
|
||||
array(
|
||||
array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:line[]')
|
||||
),
|
||||
'tns:line'
|
||||
);*/
|
||||
$server->wsdl->addComplexType(
|
||||
'LinesArray2',
|
||||
@ -176,16 +177,16 @@ $server->wsdl->addComplexType(
|
||||
);
|
||||
/*
|
||||
$server->wsdl->addComplexType(
|
||||
'InvoicesArray',
|
||||
'complexType',
|
||||
'array',
|
||||
'',
|
||||
'SOAP-ENC:Array',
|
||||
array(),
|
||||
array(
|
||||
array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:invoice[]')
|
||||
),
|
||||
'tns:invoice'
|
||||
'InvoicesArray',
|
||||
'complexType',
|
||||
'array',
|
||||
'',
|
||||
'SOAP-ENC:Array',
|
||||
array(),
|
||||
array(
|
||||
array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:invoice[]')
|
||||
),
|
||||
'tns:invoice'
|
||||
);*/
|
||||
$server->wsdl->addComplexType(
|
||||
'InvoicesArray2',
|
||||
@ -252,16 +253,16 @@ $server->register(
|
||||
'WS to create an invoice'
|
||||
);
|
||||
$server->register(
|
||||
'createInvoiceFromOrder',
|
||||
// Entry values
|
||||
'createInvoiceFromOrder',
|
||||
// Entry values
|
||||
array('authentication'=>'tns:authentication', 'id_order'=>'xsd:string', 'ref_order'=>'xsd:string', 'ref_ext_order'=>'xsd:string'),
|
||||
// Exit values
|
||||
// Exit values
|
||||
array('result'=>'tns:result', 'id'=>'xsd:string', 'ref'=>'xsd:string', 'ref_ext'=>'xsd:string'),
|
||||
$ns,
|
||||
$ns.'#createInvoiceFromOrder',
|
||||
$styledoc,
|
||||
$styleuse,
|
||||
'WS to create an invoice from an order'
|
||||
$ns,
|
||||
$ns.'#createInvoiceFromOrder',
|
||||
$styledoc,
|
||||
$styleuse,
|
||||
'WS to create an invoice from an order'
|
||||
);
|
||||
$server->register(
|
||||
'updateInvoice',
|
||||
@ -292,7 +293,9 @@ function getInvoice($authentication, $id = '', $ref = '', $ref_ext = '')
|
||||
|
||||
dol_syslog("Function: getInvoice login=".$authentication['login']." id=".$id." ref=".$ref." ref_ext=".$ref_ext);
|
||||
|
||||
if ($authentication['entity']) $conf->entity = $authentication['entity'];
|
||||
if ($authentication['entity']) {
|
||||
$conf->entity = $authentication['entity'];
|
||||
}
|
||||
|
||||
// Init and check authentication
|
||||
$objectresp = array();
|
||||
@ -300,26 +303,21 @@ function getInvoice($authentication, $id = '', $ref = '', $ref_ext = '')
|
||||
$error = 0;
|
||||
$fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
|
||||
// Check parameters
|
||||
if (!$error && (($id && $ref) || ($id && $ref_ext) || ($ref && $ref_ext)))
|
||||
{
|
||||
if (!$error && (($id && $ref) || ($id && $ref_ext) || ($ref && $ref_ext))) {
|
||||
$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)
|
||||
{
|
||||
if (!$error) {
|
||||
$fuser->getrights();
|
||||
|
||||
if ($fuser->rights->facture->lire)
|
||||
{
|
||||
if ($fuser->rights->facture->lire) {
|
||||
$invoice = new Facture($db);
|
||||
$result = $invoice->fetch($id, $ref, $ref_ext);
|
||||
if ($result > 0)
|
||||
{
|
||||
if ($result > 0) {
|
||||
$linesresp = array();
|
||||
$i = 0;
|
||||
foreach ($invoice->lines as $line)
|
||||
{
|
||||
foreach ($invoice->lines as $line) {
|
||||
//var_dump($line); exit;
|
||||
$linesresp[] = array(
|
||||
'id'=>$line->id,
|
||||
@ -346,7 +344,7 @@ function getInvoice($authentication, $id = '', $ref = '', $ref_ext = '')
|
||||
'result'=>array('result_code'=>'OK', 'result_label'=>''),
|
||||
'invoice'=>array(
|
||||
'id' => $invoice->id,
|
||||
'ref' => $invoice->ref,
|
||||
'ref' => $invoice->ref,
|
||||
'ref_ext' => $invoice->ref_ext ? $invoice->ref_ext : '', // If not defined, field is not added into soap
|
||||
'thirdparty_id' => $invoice->socid,
|
||||
'fk_user_author' => $invoice->user_author ? $invoice->user_author : '',
|
||||
@ -369,20 +367,17 @@ function getInvoice($authentication, $id = '', $ref = '', $ref_ext = '')
|
||||
'payment_mode_id' => $invoice->mode_reglement_id ? $invoice->mode_reglement_id : '',
|
||||
'lines' => $linesresp
|
||||
));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$error++;
|
||||
$errorcode = 'NOT_FOUND'; $errorlabel = 'Object not found for id='.$id.' nor ref='.$ref.' nor ref_ext='.$ref_ext;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$error++;
|
||||
$errorcode = 'PERMISSION_DENIED'; $errorlabel = 'User does not have permission for this request';
|
||||
}
|
||||
}
|
||||
|
||||
if ($error)
|
||||
{
|
||||
if ($error) {
|
||||
$objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
|
||||
}
|
||||
|
||||
@ -403,7 +398,9 @@ function getInvoicesForThirdParty($authentication, $idthirdparty)
|
||||
|
||||
dol_syslog("Function: getInvoicesForThirdParty login=".$authentication['login']." idthirdparty=".$idthirdparty);
|
||||
|
||||
if ($authentication['entity']) $conf->entity = $authentication['entity'];
|
||||
if ($authentication['entity']) {
|
||||
$conf->entity = $authentication['entity'];
|
||||
}
|
||||
|
||||
// Init and check authentication
|
||||
$objectresp = array();
|
||||
@ -411,31 +408,31 @@ function getInvoicesForThirdParty($authentication, $idthirdparty)
|
||||
$error = 0;
|
||||
$fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
|
||||
|
||||
if ($fuser->socid) $socid = $fuser->socid;
|
||||
if ($fuser->socid) {
|
||||
$socid = $fuser->socid;
|
||||
}
|
||||
|
||||
// Check parameters
|
||||
if (!$error && empty($idthirdparty))
|
||||
{
|
||||
if (!$error && empty($idthirdparty)) {
|
||||
$error++;
|
||||
$errorcode = 'BAD_PARAMETERS'; $errorlabel = 'Parameter idthirdparty is not provided';
|
||||
}
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
if (!$error) {
|
||||
$linesinvoice = array();
|
||||
|
||||
$sql = 'SELECT f.rowid as facid, ref as ref, ref_ext, type, fk_statut as status, total_ttc, total, tva';
|
||||
$sql .= ' FROM '.MAIN_DB_PREFIX.'facture as f';
|
||||
$sql .= " WHERE f.entity IN (".getEntity('invoice').")";
|
||||
if ($idthirdparty != 'all') $sql .= " AND f.fk_soc = ".$db->escape($idthirdparty);
|
||||
if ($idthirdparty != 'all') {
|
||||
$sql .= " AND f.fk_soc = ".$db->escape($idthirdparty);
|
||||
}
|
||||
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
if ($resql) {
|
||||
$num = $db->num_rows($resql);
|
||||
$i = 0;
|
||||
while ($i < $num)
|
||||
{
|
||||
while ($i < $num) {
|
||||
// En attendant remplissage par boucle
|
||||
$obj = $db->fetch_object($resql);
|
||||
|
||||
@ -443,18 +440,15 @@ function getInvoicesForThirdParty($authentication, $idthirdparty)
|
||||
$invoice->fetch($obj->facid);
|
||||
|
||||
// Sécurité pour utilisateur externe
|
||||
if ($socid && ($socid != $invoice->socid))
|
||||
{
|
||||
if ($socid && ($socid != $invoice->socid)) {
|
||||
$error++;
|
||||
$errorcode = 'PERMISSION_DENIED'; $errorlabel = $invoice->socid.' User does not have permission for this request';
|
||||
}
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
if (!$error) {
|
||||
// Define lines of invoice
|
||||
$linesresp = array();
|
||||
foreach ($invoice->lines as $line)
|
||||
{
|
||||
foreach ($invoice->lines as $line) {
|
||||
$linesresp[] = array(
|
||||
'id'=>$line->id,
|
||||
'type'=>$line->product_type,
|
||||
@ -508,15 +502,13 @@ function getInvoicesForThirdParty($authentication, $idthirdparty)
|
||||
'invoices'=>$linesinvoice
|
||||
|
||||
);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$error++;
|
||||
$errorcode = $db->lasterrno(); $errorlabel = $db->lasterror();
|
||||
}
|
||||
}
|
||||
|
||||
if ($error)
|
||||
{
|
||||
if ($error) {
|
||||
$objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
|
||||
}
|
||||
|
||||
@ -539,7 +531,9 @@ function createInvoice($authentication, $invoice)
|
||||
|
||||
dol_syslog("Function: createInvoice login=".$authentication['login']." id=".$invoice['id'].", ref=".$invoice['ref'].", ref_ext=".$invoice['ref_ext']);
|
||||
|
||||
if ($authentication['entity']) $conf->entity = $authentication['entity'];
|
||||
if ($authentication['entity']) {
|
||||
$conf->entity = $authentication['entity'];
|
||||
}
|
||||
|
||||
// Init and check authentication
|
||||
$objectresp = array();
|
||||
@ -552,8 +546,7 @@ function createInvoice($authentication, $invoice)
|
||||
$error++; $errorcode = 'KO'; $errorlabel = "Invoice id or ref or ref_ext is mandatory.";
|
||||
}
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
if (!$error) {
|
||||
$new_invoice = new Facture($db);
|
||||
$new_invoice->socid = $invoice['thirdparty_id'];
|
||||
$new_invoice->type = $invoice['type'];
|
||||
@ -571,16 +564,19 @@ function createInvoice($authentication, $invoice)
|
||||
if ($res > 0) {
|
||||
$new_invoice->mode_reglement_id = !empty($invoice['payment_mode_id']) ? $invoice['payment_mode_id'] : $soc->mode_reglement_id;
|
||||
$new_invoice->cond_reglement_id = $soc->cond_reglement_id;
|
||||
} else {
|
||||
$new_invoice->mode_reglement_id = $invoice['payment_mode_id'];
|
||||
}
|
||||
else $new_invoice->mode_reglement_id = $invoice['payment_mode_id'];
|
||||
|
||||
// Trick because nusoap does not store data with same structure if there is one or several lines
|
||||
$arrayoflines = array();
|
||||
if (isset($invoice['lines']['line'][0])) $arrayoflines = $invoice['lines']['line'];
|
||||
else $arrayoflines = $invoice['lines'];
|
||||
if (isset($invoice['lines']['line'][0])) {
|
||||
$arrayoflines = $invoice['lines']['line'];
|
||||
} else {
|
||||
$arrayoflines = $invoice['lines'];
|
||||
}
|
||||
|
||||
foreach ($arrayoflines as $line)
|
||||
{
|
||||
foreach ($arrayoflines as $line) {
|
||||
// $key can be 'line' or '0','1',...
|
||||
$newline = new FactureLigne($db);
|
||||
$newline->product_type = $line['type'];
|
||||
@ -603,27 +599,22 @@ function createInvoice($authentication, $invoice)
|
||||
$db->begin();
|
||||
|
||||
$result = $new_invoice->create($fuser, 0, dol_stringtotime($invoice['date_due'], 'dayrfc'));
|
||||
if ($result < 0)
|
||||
{
|
||||
if ($result < 0) {
|
||||
$error++;
|
||||
}
|
||||
|
||||
if (!$error && $invoice['status'] == Facture::STATUS_VALIDATED) // We want invoice to have status validated
|
||||
{
|
||||
if (!$error && $invoice['status'] == Facture::STATUS_VALIDATED) { // We want invoice to have status validated
|
||||
$result = $new_invoice->validate($fuser);
|
||||
if ($result < 0)
|
||||
{
|
||||
if ($result < 0) {
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
if (!$error) {
|
||||
$db->commit();
|
||||
$objectresp = array('result'=>array('result_code'=>'OK', 'result_label'=>''), 'id'=>$new_invoice->id,
|
||||
'ref'=>$new_invoice->ref, 'ref_ext'=>$new_invoice->ref_ext);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$db->rollback();
|
||||
$error++;
|
||||
$errorcode = 'KO';
|
||||
@ -632,8 +623,7 @@ function createInvoice($authentication, $invoice)
|
||||
}
|
||||
}
|
||||
|
||||
if ($error)
|
||||
{
|
||||
if ($error) {
|
||||
$objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
|
||||
}
|
||||
|
||||
@ -655,14 +645,18 @@ function createInvoiceFromOrder($authentication, $id_order = '', $ref_order = ''
|
||||
|
||||
dol_syslog("Function: createInvoiceFromOrder login=".$authentication['login']." id=".$id_order.", ref=".$ref_order.", ref_ext=".$ref_ext_order);
|
||||
|
||||
if ($authentication['entity']) $conf->entity = $authentication['entity'];
|
||||
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 ($fuser->socid) $socid = $fuser->socid;
|
||||
if ($fuser->socid) {
|
||||
$socid = $fuser->socid;
|
||||
}
|
||||
|
||||
// Check parameters
|
||||
if (empty($id_order) && empty($ref_order) && empty($ref_ext_order)) {
|
||||
@ -670,51 +664,41 @@ function createInvoiceFromOrder($authentication, $id_order = '', $ref_order = ''
|
||||
}
|
||||
|
||||
//////////////////////
|
||||
if (!$error)
|
||||
{
|
||||
if (!$error) {
|
||||
$fuser->getrights();
|
||||
|
||||
if ($fuser->rights->commande->lire)
|
||||
{
|
||||
if ($fuser->rights->commande->lire) {
|
||||
$order = new Commande($db);
|
||||
$result = $order->fetch($id_order, $ref_order, $ref_ext_order);
|
||||
if ($result > 0)
|
||||
{
|
||||
if ($result > 0) {
|
||||
// Security for external user
|
||||
if ($socid && ($socid != $order->socid))
|
||||
{
|
||||
if ($socid && ($socid != $order->socid)) {
|
||||
$error++;
|
||||
$errorcode = 'PERMISSION_DENIED'; $errorlabel = $order->socid.'User does not have permission for this request';
|
||||
}
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
if (!$error) {
|
||||
$newobject = new Facture($db);
|
||||
$result = $newobject->createFromOrder($order, $fuser);
|
||||
|
||||
if ($result < 0)
|
||||
{
|
||||
if ($result < 0) {
|
||||
$error++;
|
||||
dol_syslog("Webservice server_invoice:: invoice creation from order failed", LOG_ERR);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$error++;
|
||||
$errorcode = 'NOT_FOUND'; $errorlabel = 'Object not found for id='.$id_order.' nor ref='.$ref_order.' nor ref_ext='.$ref_ext_order;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$error++;
|
||||
$errorcode = 'PERMISSION_DENIED'; $errorlabel = 'User does not have permission for this request';
|
||||
}
|
||||
}
|
||||
|
||||
if ($error)
|
||||
{
|
||||
if ($error) {
|
||||
$objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$objectresp = array('result'=>array('result_code'=>'OK', 'result_label'=>''), 'id'=>$newobject->id, 'ref'=>$newobject->ref, 'ref_ext'=>$newobject->ref_ext);
|
||||
}
|
||||
|
||||
@ -735,7 +719,9 @@ function updateInvoice($authentication, $invoice)
|
||||
dol_syslog("Function: updateInvoice login=".$authentication['login']." id=".$invoice['id'].
|
||||
", ref=".$invoice['ref'].", ref_ext=".$invoice['ref_ext']);
|
||||
|
||||
if ($authentication['entity']) $conf->entity = $authentication['entity'];
|
||||
if ($authentication['entity']) {
|
||||
$conf->entity = $authentication['entity'];
|
||||
}
|
||||
|
||||
// Init and check authentication
|
||||
$objectresp = array();
|
||||
@ -748,8 +734,7 @@ function updateInvoice($authentication, $invoice)
|
||||
$error++; $errorcode = 'KO'; $errorlabel = "Invoice id or ref or ref_ext is mandatory.";
|
||||
}
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
if (!$error) {
|
||||
$objectfound = false;
|
||||
|
||||
$object = new Facture($db);
|
||||
@ -760,18 +745,14 @@ function updateInvoice($authentication, $invoice)
|
||||
|
||||
$db->begin();
|
||||
|
||||
if (isset($invoice['status']))
|
||||
{
|
||||
if ($invoice['status'] == Facture::STATUS_DRAFT)
|
||||
{
|
||||
if (isset($invoice['status'])) {
|
||||
if ($invoice['status'] == Facture::STATUS_DRAFT) {
|
||||
$result = $object->setDraft($fuser);
|
||||
}
|
||||
if ($invoice['status'] == Facture::STATUS_VALIDATED)
|
||||
{
|
||||
if ($invoice['status'] == Facture::STATUS_VALIDATED) {
|
||||
$result = $object->validate($fuser);
|
||||
|
||||
if ($result >= 0)
|
||||
{
|
||||
if ($result >= 0) {
|
||||
// Define output language
|
||||
$outputlangs = $langs;
|
||||
$object->generateDocument($object->model_pdf, $outputlangs);
|
||||
@ -806,8 +787,7 @@ function updateInvoice($authentication, $invoice)
|
||||
}
|
||||
}
|
||||
|
||||
if ($error)
|
||||
{
|
||||
if ($error) {
|
||||
$objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
|
||||
}
|
||||
|
||||
|
||||
@ -22,7 +22,9 @@
|
||||
* \brief File that is entry point to call Dolibarr WebServices
|
||||
*/
|
||||
|
||||
if (!defined("NOCSRFCHECK")) define("NOCSRFCHECK", '1');
|
||||
if (!defined("NOCSRFCHECK")) {
|
||||
define("NOCSRFCHECK", '1');
|
||||
}
|
||||
|
||||
require '../master.inc.php';
|
||||
require_once NUSOAP_PATH.'/nusoap.php'; // Include SOAP
|
||||
@ -36,8 +38,7 @@ dol_syslog("Call Dolibarr webservices interfaces");
|
||||
$langs->load("main");
|
||||
|
||||
// Enable and test if module web services is enabled
|
||||
if (empty($conf->global->MAIN_MODULE_WEBSERVICES))
|
||||
{
|
||||
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>';
|
||||
@ -56,12 +57,12 @@ $server->wsdl->schemaTargetNamespace = $ns;
|
||||
|
||||
// Define WSDL Authentication object
|
||||
$server->wsdl->addComplexType(
|
||||
'authentication',
|
||||
'complexType',
|
||||
'struct',
|
||||
'all',
|
||||
'',
|
||||
array(
|
||||
'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'),
|
||||
@ -71,12 +72,12 @@ $server->wsdl->addComplexType(
|
||||
);
|
||||
// Define WSDL Return object
|
||||
$server->wsdl->addComplexType(
|
||||
'result',
|
||||
'complexType',
|
||||
'struct',
|
||||
'all',
|
||||
'',
|
||||
array(
|
||||
'result',
|
||||
'complexType',
|
||||
'struct',
|
||||
'all',
|
||||
'',
|
||||
array(
|
||||
'result_code' => array('name'=>'result_code', 'type'=>'xsd:string'),
|
||||
'result_label' => array('name'=>'result_label', 'type'=>'xsd:string'),
|
||||
)
|
||||
@ -120,27 +121,30 @@ $extrafield_line_array = null;
|
||||
if (is_array($extrafields) && count($extrafields) > 0) {
|
||||
$extrafield_line_array = array();
|
||||
}
|
||||
if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label']))
|
||||
{
|
||||
foreach ($extrafields->attributes[$elementtype]['label'] as $key=>$label)
|
||||
{
|
||||
if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) {
|
||||
foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) {
|
||||
//$value=$object->array_options["options_".$key];
|
||||
$type = $extrafields->attributes[$elementtype]['type'][$key];
|
||||
if ($type == 'date' || $type == 'datetime') {$type = 'xsd:dateTime'; }
|
||||
else {$type = 'xsd:string'; }
|
||||
if ($type == 'date' || $type == 'datetime') {
|
||||
$type = 'xsd:dateTime';
|
||||
} else {
|
||||
$type = 'xsd:string';
|
||||
}
|
||||
$extrafield_line_array['options_'.$key] = array('name'=>'options_'.$key, 'type'=>$type);
|
||||
}
|
||||
}
|
||||
if (is_array($extrafield_line_array)) $line_fields = array_merge($line_fields, $extrafield_line_array);
|
||||
if (is_array($extrafield_line_array)) {
|
||||
$line_fields = array_merge($line_fields, $extrafield_line_array);
|
||||
}
|
||||
|
||||
// Define other specific objects
|
||||
$server->wsdl->addComplexType(
|
||||
'line',
|
||||
'complexType',
|
||||
'struct',
|
||||
'all',
|
||||
'',
|
||||
$line_fields
|
||||
'line',
|
||||
'complexType',
|
||||
'struct',
|
||||
'all',
|
||||
'',
|
||||
$line_fields
|
||||
);
|
||||
|
||||
/*$server->wsdl->addComplexType(
|
||||
@ -159,12 +163,12 @@ $server->wsdl->addComplexType(
|
||||
'tns:line'
|
||||
);*/
|
||||
$server->wsdl->addComplexType(
|
||||
'LinesArray2',
|
||||
'complexType',
|
||||
'array',
|
||||
'sequence',
|
||||
'',
|
||||
array(
|
||||
'LinesArray2',
|
||||
'complexType',
|
||||
'array',
|
||||
'sequence',
|
||||
'',
|
||||
array(
|
||||
'line' => array(
|
||||
'name' => 'line',
|
||||
'type' => 'tns:line',
|
||||
@ -224,26 +228,29 @@ $extrafield_array = null;
|
||||
if (is_array($extrafields) && count($extrafields) > 0) {
|
||||
$extrafield_array = array();
|
||||
}
|
||||
if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label']))
|
||||
{
|
||||
foreach ($extrafields->attributes[$elementtype]['label'] as $key=>$label)
|
||||
{
|
||||
if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) {
|
||||
foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) {
|
||||
//$value=$object->array_options["options_".$key];
|
||||
$type = $extrafields->attributes[$elementtype]['type'][$key];
|
||||
if ($type == 'date' || $type == 'datetime') {$type = 'xsd:dateTime'; }
|
||||
else {$type = 'xsd:string'; }
|
||||
if ($type == 'date' || $type == 'datetime') {
|
||||
$type = 'xsd:dateTime';
|
||||
} else {
|
||||
$type = 'xsd:string';
|
||||
}
|
||||
$extrafield_array['options_'.$key] = array('name'=>'options_'.$key, 'type'=>$type);
|
||||
}
|
||||
}
|
||||
if (is_array($extrafield_array)) $order_fields = array_merge($order_fields, $extrafield_array);
|
||||
if (is_array($extrafield_array)) {
|
||||
$order_fields = array_merge($order_fields, $extrafield_array);
|
||||
}
|
||||
|
||||
$server->wsdl->addComplexType(
|
||||
'order',
|
||||
'complexType',
|
||||
'struct',
|
||||
'all',
|
||||
'',
|
||||
$order_fields
|
||||
'order',
|
||||
'complexType',
|
||||
'struct',
|
||||
'all',
|
||||
'',
|
||||
$order_fields
|
||||
);
|
||||
|
||||
/*
|
||||
@ -263,12 +270,12 @@ $server->wsdl->addComplexType(
|
||||
'tns:order'
|
||||
);*/
|
||||
$server->wsdl->addComplexType(
|
||||
'OrdersArray2',
|
||||
'complexType',
|
||||
'array',
|
||||
'sequence',
|
||||
'',
|
||||
array(
|
||||
'OrdersArray2',
|
||||
'complexType',
|
||||
'array',
|
||||
'sequence',
|
||||
'',
|
||||
array(
|
||||
'order' => array(
|
||||
'name' => 'order',
|
||||
'type' => 'tns:order',
|
||||
@ -289,58 +296,58 @@ $styleuse = 'encoded'; // encoded/literal/literal wrapped
|
||||
|
||||
// Register WSDL
|
||||
$server->register(
|
||||
'getOrder',
|
||||
array('authentication'=>'tns:authentication', 'id'=>'xsd:string', 'ref'=>'xsd:string', 'ref_ext'=>'xsd:string'), // Entry values
|
||||
array('result'=>'tns:result', 'order'=>'tns:order'), // Exit values
|
||||
$ns,
|
||||
$ns.'#getOrder',
|
||||
$styledoc,
|
||||
$styleuse,
|
||||
'WS to get a particular invoice'
|
||||
'getOrder',
|
||||
array('authentication'=>'tns:authentication', 'id'=>'xsd:string', 'ref'=>'xsd:string', 'ref_ext'=>'xsd:string'), // Entry values
|
||||
array('result'=>'tns:result', 'order'=>'tns:order'), // Exit values
|
||||
$ns,
|
||||
$ns.'#getOrder',
|
||||
$styledoc,
|
||||
$styleuse,
|
||||
'WS to get a particular invoice'
|
||||
);
|
||||
|
||||
$server->register(
|
||||
'getOrdersForThirdParty',
|
||||
array('authentication'=>'tns:authentication', 'idthirdparty'=>'xsd:string'), // Entry values
|
||||
array('result'=>'tns:result', 'orders'=>'tns:OrdersArray2'), // Exit values
|
||||
$ns,
|
||||
$ns.'#getOrdersForThirdParty',
|
||||
$styledoc,
|
||||
$styleuse,
|
||||
'WS to get all orders of a third party'
|
||||
'getOrdersForThirdParty',
|
||||
array('authentication'=>'tns:authentication', 'idthirdparty'=>'xsd:string'), // Entry values
|
||||
array('result'=>'tns:result', 'orders'=>'tns:OrdersArray2'), // Exit values
|
||||
$ns,
|
||||
$ns.'#getOrdersForThirdParty',
|
||||
$styledoc,
|
||||
$styleuse,
|
||||
'WS to get all orders of a third party'
|
||||
);
|
||||
|
||||
$server->register(
|
||||
'createOrder',
|
||||
array('authentication'=>'tns:authentication', 'order'=>'tns:order'), // Entry values
|
||||
array('result'=>'tns:result', 'id'=>'xsd:string', 'ref'=>'xsd:string'), // Exit values
|
||||
$ns,
|
||||
$ns.'#createOrder',
|
||||
$styledoc,
|
||||
$styleuse,
|
||||
'WS to create an order'
|
||||
'createOrder',
|
||||
array('authentication'=>'tns:authentication', 'order'=>'tns:order'), // Entry values
|
||||
array('result'=>'tns:result', 'id'=>'xsd:string', 'ref'=>'xsd:string'), // Exit values
|
||||
$ns,
|
||||
$ns.'#createOrder',
|
||||
$styledoc,
|
||||
$styleuse,
|
||||
'WS to create an order'
|
||||
);
|
||||
|
||||
$server->register(
|
||||
'updateOrder',
|
||||
array('authentication'=>'tns:authentication', 'order'=>'tns:order'), // Entry values
|
||||
array('result'=>'tns:result', 'id'=>'xsd:string', 'ref'=>'xsd:string', 'ref_ext'=>'xsd:string'), // Exit values
|
||||
$ns,
|
||||
$ns.'#updateOrder',
|
||||
$styledoc,
|
||||
$styleuse,
|
||||
'WS to update an order'
|
||||
'updateOrder',
|
||||
array('authentication'=>'tns:authentication', 'order'=>'tns:order'), // Entry values
|
||||
array('result'=>'tns:result', 'id'=>'xsd:string', 'ref'=>'xsd:string', 'ref_ext'=>'xsd:string'), // Exit values
|
||||
$ns,
|
||||
$ns.'#updateOrder',
|
||||
$styledoc,
|
||||
$styleuse,
|
||||
'WS to update an order'
|
||||
);
|
||||
|
||||
$server->register(
|
||||
'validOrder',
|
||||
array('authentication'=>'tns:authentication', 'id'=>'xsd:string', 'id_warehouse'=>'xsd:string'), // Entry values
|
||||
array('result'=>'tns:result'), // Exit values
|
||||
$ns,
|
||||
$ns.'#validOrder',
|
||||
$styledoc,
|
||||
$styleuse,
|
||||
'WS to valid an order'
|
||||
'validOrder',
|
||||
array('authentication'=>'tns:authentication', 'id'=>'xsd:string', 'id_warehouse'=>'xsd:string'), // Entry values
|
||||
array('result'=>'tns:result'), // Exit values
|
||||
$ns,
|
||||
$ns.'#validOrder',
|
||||
$styledoc,
|
||||
$styleuse,
|
||||
'WS to valid an order'
|
||||
);
|
||||
|
||||
/**
|
||||
@ -358,7 +365,9 @@ function getOrder($authentication, $id = '', $ref = '', $ref_ext = '')
|
||||
|
||||
dol_syslog("Function: getOrder login=".$authentication['login']." id=".$id." ref=".$ref." ref_ext=".$ref_ext);
|
||||
|
||||
if ($authentication['entity']) $conf->entity = $authentication['entity'];
|
||||
if ($authentication['entity']) {
|
||||
$conf->entity = $authentication['entity'];
|
||||
}
|
||||
|
||||
// Init and check authentication
|
||||
$objectresp = array();
|
||||
@ -368,38 +377,33 @@ function getOrder($authentication, $id = '', $ref = '', $ref_ext = '')
|
||||
|
||||
$fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
|
||||
|
||||
if ($fuser->socid) $socid = $fuser->socid;
|
||||
if ($fuser->socid) {
|
||||
$socid = $fuser->socid;
|
||||
}
|
||||
|
||||
// Check parameters
|
||||
if (!$error && (($id && $ref) || ($id && $ref_ext) || ($ref && $ref_ext)))
|
||||
{
|
||||
if (!$error && (($id && $ref) || ($id && $ref_ext) || ($ref && $ref_ext))) {
|
||||
$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)
|
||||
{
|
||||
if (!$error) {
|
||||
$fuser->getrights();
|
||||
|
||||
if ($fuser->rights->commande->lire)
|
||||
{
|
||||
if ($fuser->rights->commande->lire) {
|
||||
$order = new Commande($db);
|
||||
$result = $order->fetch($id, $ref, $ref_ext);
|
||||
if ($result > 0)
|
||||
{
|
||||
if ($result > 0) {
|
||||
// Security for external user
|
||||
if ($socid && $socid != $order->socid)
|
||||
{
|
||||
if ($socid && $socid != $order->socid) {
|
||||
$error++;
|
||||
$errorcode = 'PERMISSION_DENIED'; $errorlabel = 'User does not have permission for this request';
|
||||
}
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
if (!$error) {
|
||||
$linesresp = array();
|
||||
$i = 0;
|
||||
foreach ($order->lines as $line)
|
||||
{
|
||||
foreach ($order->lines as $line) {
|
||||
//var_dump($line); exit;
|
||||
$linesresp[] = array(
|
||||
'id'=>$line->rowid,
|
||||
@ -473,22 +477,19 @@ function getOrder($authentication, $id = '', $ref = '', $ref_ext = '')
|
||||
'lines' => $linesresp
|
||||
));
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$error++;
|
||||
$errorcode = 'NOT_FOUND';
|
||||
$errorlabel = 'Object not found for id='.$id.' nor ref='.$ref.' nor ref_ext='.$ref_ext;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$error++;
|
||||
$errorcode = 'PERMISSION_DENIED';
|
||||
$errorlabel = 'User does not have permission for this request';
|
||||
}
|
||||
}
|
||||
|
||||
if ($error)
|
||||
{
|
||||
if ($error) {
|
||||
$objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
|
||||
}
|
||||
|
||||
@ -509,7 +510,9 @@ function getOrdersForThirdParty($authentication, $idthirdparty)
|
||||
|
||||
dol_syslog("Function: getOrdersForThirdParty login=".$authentication['login']." idthirdparty=".$idthirdparty);
|
||||
|
||||
if ($authentication['entity']) $conf->entity = $authentication['entity'];
|
||||
if ($authentication['entity']) {
|
||||
$conf->entity = $authentication['entity'];
|
||||
}
|
||||
|
||||
// Init and check authentication
|
||||
$objectresp = array();
|
||||
@ -517,32 +520,32 @@ function getOrdersForThirdParty($authentication, $idthirdparty)
|
||||
$error = 0;
|
||||
$fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
|
||||
|
||||
if ($fuser->socid) $socid = $fuser->socid;
|
||||
if ($fuser->socid) {
|
||||
$socid = $fuser->socid;
|
||||
}
|
||||
|
||||
// Check parameters
|
||||
if (!$error && empty($idthirdparty))
|
||||
{
|
||||
if (!$error && empty($idthirdparty)) {
|
||||
$error++;
|
||||
$errorcode = 'BAD_PARAMETERS'; $errorlabel = 'Parameter id is not provided';
|
||||
}
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
if (!$error) {
|
||||
$linesorders = array();
|
||||
|
||||
$sql = 'SELECT c.rowid as orderid';
|
||||
$sql .= ' FROM '.MAIN_DB_PREFIX.'commande as c';
|
||||
$sql .= " WHERE c.entity = ".$conf->entity;
|
||||
if ($idthirdparty != 'all') $sql .= " AND c.fk_soc = ".$db->escape($idthirdparty);
|
||||
if ($idthirdparty != 'all') {
|
||||
$sql .= " AND c.fk_soc = ".$db->escape($idthirdparty);
|
||||
}
|
||||
|
||||
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
if ($resql) {
|
||||
$num = $db->num_rows($resql);
|
||||
$i = 0;
|
||||
while ($i < $num)
|
||||
{
|
||||
while ($i < $num) {
|
||||
// En attendant remplissage par boucle
|
||||
$obj = $db->fetch_object($resql);
|
||||
|
||||
@ -550,19 +553,16 @@ function getOrdersForThirdParty($authentication, $idthirdparty)
|
||||
$order->fetch($obj->orderid);
|
||||
|
||||
// Sécurité pour utilisateur externe
|
||||
if ($socid && ($socid != $order->socid))
|
||||
{
|
||||
if ($socid && ($socid != $order->socid)) {
|
||||
$error++;
|
||||
$errorcode = 'PERMISSION_DENIED';
|
||||
$errorlabel = $order->socid.' User does not have permission for this request';
|
||||
}
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
if (!$error) {
|
||||
// Define lines of invoice
|
||||
$linesresp = array();
|
||||
foreach ($order->lines as $line)
|
||||
{
|
||||
foreach ($order->lines as $line) {
|
||||
$linesresp[] = array(
|
||||
'id'=>$line->rowid,
|
||||
'type'=>$line->product_type,
|
||||
@ -638,15 +638,13 @@ function getOrdersForThirdParty($authentication, $idthirdparty)
|
||||
'orders'=>$linesorders
|
||||
|
||||
);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$error++;
|
||||
$errorcode = $db->lasterrno(); $errorlabel = $db->lasterror();
|
||||
}
|
||||
}
|
||||
|
||||
if ($error)
|
||||
{
|
||||
if ($error) {
|
||||
$objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
|
||||
}
|
||||
|
||||
@ -671,7 +669,9 @@ function createOrder($authentication, $order)
|
||||
|
||||
dol_syslog("Function: createOrder login=".$authentication['login']." socid :".$order['socid']);
|
||||
|
||||
if ($authentication['entity']) $conf->entity = $authentication['entity'];
|
||||
if ($authentication['entity']) {
|
||||
$conf->entity = $authentication['entity'];
|
||||
}
|
||||
|
||||
// Init and check authentication
|
||||
$objectresp = array();
|
||||
@ -683,8 +683,7 @@ function createOrder($authentication, $order)
|
||||
// Check parameters
|
||||
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
if (!$error) {
|
||||
$newobject = new Commande($db);
|
||||
$newobject->socid = $order['thirdparty_id'];
|
||||
$newobject->type = $order['type'];
|
||||
@ -706,10 +705,8 @@ function createOrder($authentication, $order)
|
||||
// fetch optionals attributes and labels
|
||||
$extrafields = new ExtraFields($db);
|
||||
$extrafields->fetch_name_optionals_label($elementtype, true);
|
||||
if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label']))
|
||||
{
|
||||
foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label)
|
||||
{
|
||||
if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) {
|
||||
foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) {
|
||||
$key = 'options_'.$key;
|
||||
$newobject->array_options[$key] = $order[$key];
|
||||
}
|
||||
@ -717,11 +714,13 @@ function createOrder($authentication, $order)
|
||||
|
||||
// Trick because nusoap does not store data with same structure if there is one or several lines
|
||||
$arrayoflines = array();
|
||||
if (isset($order['lines']['line'][0])) $arrayoflines = $order['lines']['line'];
|
||||
else $arrayoflines = $order['lines'];
|
||||
if (isset($order['lines']['line'][0])) {
|
||||
$arrayoflines = $order['lines']['line'];
|
||||
} else {
|
||||
$arrayoflines = $order['lines'];
|
||||
}
|
||||
|
||||
foreach ($arrayoflines as $key => $line)
|
||||
{
|
||||
foreach ($arrayoflines as $key => $line) {
|
||||
// $key can be 'line' or '0','1',...
|
||||
$newline = new OrderLine($db);
|
||||
|
||||
@ -744,10 +743,8 @@ function createOrder($authentication, $order)
|
||||
// fetch optionals attributes and labels
|
||||
$extrafields = new ExtraFields($db);
|
||||
$extrafields->fetch_name_optionals_label($elementtype, true);
|
||||
if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label']))
|
||||
{
|
||||
foreach ($extrafields->attributes[$elementtype]['label'] as $key=>$label)
|
||||
{
|
||||
if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) {
|
||||
foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) {
|
||||
$key = 'options_'.$key;
|
||||
$newline->array_options[$key] = $line[$key];
|
||||
}
|
||||
@ -761,30 +758,25 @@ function createOrder($authentication, $order)
|
||||
dol_syslog("Webservice server_order:: order creation start", LOG_DEBUG);
|
||||
$result = $newobject->create($fuser);
|
||||
dol_syslog('Webservice server_order:: order creation done with $result='.$result, LOG_DEBUG);
|
||||
if ($result < 0)
|
||||
{
|
||||
if ($result < 0) {
|
||||
dol_syslog("Webservice server_order:: order creation failed", LOG_ERR);
|
||||
$error++;
|
||||
}
|
||||
|
||||
if ($order['status'] == 1) // We want order to have status validated
|
||||
{
|
||||
if ($order['status'] == 1) { // We want order to have status validated
|
||||
dol_syslog("Webservice server_order:: order validation start", LOG_DEBUG);
|
||||
$result = $newobject->valid($fuser);
|
||||
if ($result < 0)
|
||||
{
|
||||
if ($result < 0) {
|
||||
dol_syslog("Webservice server_order:: order validation failed", LOG_ERR);
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
|
||||
if ($result >= 0)
|
||||
{
|
||||
if ($result >= 0) {
|
||||
dol_syslog("Webservice server_order:: order creation & validation succeeded, commit", LOG_DEBUG);
|
||||
$db->commit();
|
||||
$objectresp = array('result'=>array('result_code'=>'OK', 'result_label'=>''), 'id'=>$newobject->id, 'ref'=>$newobject->ref);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
dol_syslog("Webservice server_order:: order creation or validation failed, rollback", LOG_ERR);
|
||||
$db->rollback();
|
||||
$error++;
|
||||
@ -793,8 +785,7 @@ function createOrder($authentication, $order)
|
||||
}
|
||||
}
|
||||
|
||||
if ($error)
|
||||
{
|
||||
if ($error) {
|
||||
$objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
|
||||
}
|
||||
|
||||
@ -821,45 +812,40 @@ function validOrder($authentication, $id = '', $id_warehouse = 0)
|
||||
$errorcode = '';
|
||||
$errorlabel = '';
|
||||
$error = 0;
|
||||
if ($authentication['entity']) $conf->entity = $authentication['entity'];
|
||||
if ($authentication['entity']) {
|
||||
$conf->entity = $authentication['entity'];
|
||||
}
|
||||
$fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
if (!$error) {
|
||||
$fuser->getrights();
|
||||
|
||||
if ($fuser->rights->commande->lire)
|
||||
{
|
||||
if ($fuser->rights->commande->lire) {
|
||||
$order = new Commande($db);
|
||||
$result = $order->fetch($id);
|
||||
|
||||
$order->fetch_thirdparty();
|
||||
$db->begin();
|
||||
if ($result > 0)
|
||||
{
|
||||
if ($result > 0) {
|
||||
$result = $order->valid($fuser, $id_warehouse);
|
||||
|
||||
if ($result >= 0)
|
||||
{
|
||||
if ($result >= 0) {
|
||||
// Define output language
|
||||
$outputlangs = $langs;
|
||||
$order->generateDocument($order->model_pdf, $outputlangs);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$db->rollback();
|
||||
$error++;
|
||||
$errorcode = 'KO';
|
||||
$errorlabel = $order->error;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$db->rollback();
|
||||
$error++;
|
||||
$errorcode = 'KO';
|
||||
$errorlabel = $order->error;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$db->rollback();
|
||||
$error++;
|
||||
$errorcode = 'KO';
|
||||
@ -867,11 +853,9 @@ function validOrder($authentication, $id = '', $id_warehouse = 0)
|
||||
}
|
||||
}
|
||||
|
||||
if ($error)
|
||||
{
|
||||
if ($error) {
|
||||
$objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$db->commit();
|
||||
$objectresp = array('result'=>array('result_code'=>'OK', 'result_label'=>''));
|
||||
}
|
||||
@ -892,7 +876,9 @@ function updateOrder($authentication, $order)
|
||||
|
||||
dol_syslog("Function: updateOrder login=".$authentication['login']);
|
||||
|
||||
if ($authentication['entity']) $conf->entity = $authentication['entity'];
|
||||
if ($authentication['entity']) {
|
||||
$conf->entity = $authentication['entity'];
|
||||
}
|
||||
|
||||
// Init and check authentication
|
||||
$objectresp = array();
|
||||
@ -904,8 +890,7 @@ function updateOrder($authentication, $order)
|
||||
$error++; $errorcode = 'KO'; $errorlabel = "Order id or ref or ref_ext is mandatory.";
|
||||
}
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
if (!$error) {
|
||||
$objectfound = false;
|
||||
|
||||
include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
|
||||
@ -918,27 +903,33 @@ function updateOrder($authentication, $order)
|
||||
|
||||
$db->begin();
|
||||
|
||||
if (isset($order['status']))
|
||||
{
|
||||
if ($order['status'] == -1) $result = $object->cancel($fuser);
|
||||
if ($order['status'] == 1)
|
||||
{
|
||||
if (isset($order['status'])) {
|
||||
if ($order['status'] == -1) {
|
||||
$result = $object->cancel($fuser);
|
||||
}
|
||||
if ($order['status'] == 1) {
|
||||
$result = $object->valid($fuser);
|
||||
if ($result >= 0)
|
||||
{
|
||||
if ($result >= 0) {
|
||||
// Define output language
|
||||
$outputlangs = $langs;
|
||||
$object->generateDocument($order->model_pdf, $outputlangs);
|
||||
}
|
||||
}
|
||||
if ($order['status'] == 0) $result = $object->set_reopen($fuser);
|
||||
if ($order['status'] == 3) $result = $object->cloture($fuser);
|
||||
if ($order['status'] == 0) {
|
||||
$result = $object->set_reopen($fuser);
|
||||
}
|
||||
if ($order['status'] == 3) {
|
||||
$result = $object->cloture($fuser);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($order['billed']))
|
||||
{
|
||||
if ($order['billed']) $result = $object->classifyBilled($fuser);
|
||||
if (!$order['billed']) $result = $object->classifyUnBilled($fuser);
|
||||
if (isset($order['billed'])) {
|
||||
if ($order['billed']) {
|
||||
$result = $object->classifyBilled($fuser);
|
||||
}
|
||||
if (!$order['billed']) {
|
||||
$result = $object->classifyUnBilled($fuser);
|
||||
}
|
||||
}
|
||||
|
||||
$elementtype = 'commande';
|
||||
@ -947,13 +938,10 @@ function updateOrder($authentication, $order)
|
||||
// fetch optionals attributes and labels
|
||||
$extrafields = new ExtraFields($db);
|
||||
$extrafields->fetch_name_optionals_label($elementtype, true);
|
||||
if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label']))
|
||||
{
|
||||
foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label)
|
||||
{
|
||||
if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) {
|
||||
foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) {
|
||||
$key = 'options_'.$key;
|
||||
if (isset($order[$key]))
|
||||
{
|
||||
if (isset($order[$key])) {
|
||||
$result = $object->setValueFrom($key, $order[$key], 'commande_extrafields');
|
||||
}
|
||||
}
|
||||
@ -964,8 +952,7 @@ function updateOrder($authentication, $order)
|
||||
}
|
||||
}
|
||||
|
||||
if ((!$error) && ($objectfound))
|
||||
{
|
||||
if ((!$error) && ($objectfound)) {
|
||||
$db->commit();
|
||||
$objectresp = array(
|
||||
'result'=>array('result_code'=>'OK', 'result_label'=>''),
|
||||
@ -973,9 +960,7 @@ function updateOrder($authentication, $order)
|
||||
'ref'=>$object->ref,
|
||||
'ref_ext'=>$object->ref_ext
|
||||
);
|
||||
}
|
||||
elseif ($objectfound)
|
||||
{
|
||||
} elseif ($objectfound) {
|
||||
$db->rollback();
|
||||
$error++;
|
||||
$errorcode = 'KO';
|
||||
@ -987,8 +972,7 @@ function updateOrder($authentication, $order)
|
||||
}
|
||||
}
|
||||
|
||||
if ($error)
|
||||
{
|
||||
if ($error) {
|
||||
$objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
|
||||
}
|
||||
|
||||
|
||||
@ -20,7 +20,9 @@
|
||||
* \brief File that is entry point to call Dolibarr WebServices
|
||||
*/
|
||||
|
||||
if (!defined("NOCSRFCHECK")) define("NOCSRFCHECK", '1');
|
||||
if (!defined("NOCSRFCHECK")) {
|
||||
define("NOCSRFCHECK", '1');
|
||||
}
|
||||
|
||||
require '../master.inc.php';
|
||||
require_once NUSOAP_PATH.'/nusoap.php'; // Include SOAP
|
||||
@ -35,8 +37,7 @@ dol_syslog("Call Dolibarr webservices interfaces");
|
||||
$langs->load("main");
|
||||
|
||||
// Enable and test if module web services is enabled
|
||||
if (empty($conf->global->MAIN_MODULE_WEBSERVICES))
|
||||
{
|
||||
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>';
|
||||
@ -149,7 +150,9 @@ function getVersions($authentication)
|
||||
|
||||
dol_syslog("Function: getVersions login=".$authentication['login']);
|
||||
|
||||
if ($authentication['entity']) $conf->entity = $authentication['entity'];
|
||||
if ($authentication['entity']) {
|
||||
$conf->entity = $authentication['entity'];
|
||||
}
|
||||
|
||||
// Init and check authentication
|
||||
$objectresp = array();
|
||||
@ -159,8 +162,7 @@ function getVersions($authentication)
|
||||
// Check parameters
|
||||
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
if (!$error) {
|
||||
$objectresp['result'] = array('result_code'=>'OK', 'result_label'=>'');
|
||||
$objectresp['dolibarr'] = version_dolibarr();
|
||||
$objectresp['os'] = version_os();
|
||||
@ -168,8 +170,7 @@ function getVersions($authentication)
|
||||
$objectresp['webserver'] = version_webserver();
|
||||
}
|
||||
|
||||
if ($error)
|
||||
{
|
||||
if ($error) {
|
||||
$objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
|
||||
}
|
||||
|
||||
@ -192,7 +193,9 @@ function getDocument($authentication, $modulepart, $file, $refname = '')
|
||||
|
||||
dol_syslog("Function: getDocument login=".$authentication['login'].' - modulepart='.$modulepart.' - file='.$file);
|
||||
|
||||
if ($authentication['entity']) $conf->entity = $authentication['entity'];
|
||||
if ($authentication['entity']) {
|
||||
$conf->entity = $authentication['entity'];
|
||||
}
|
||||
|
||||
$objectresp = array();
|
||||
$errorcode = ''; $errorlabel = '';
|
||||
@ -208,24 +211,26 @@ function getDocument($authentication, $modulepart, $file, $refname = '')
|
||||
|
||||
$fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
|
||||
|
||||
if ($fuser->socid) $socid = $fuser->socid;
|
||||
if ($fuser->socid) {
|
||||
$socid = $fuser->socid;
|
||||
}
|
||||
|
||||
// Check parameters
|
||||
if (!$error && (!$file || !$modulepart))
|
||||
{
|
||||
if (!$error && (!$file || !$modulepart)) {
|
||||
$error++;
|
||||
$errorcode = 'BAD_PARAMETERS'; $errorlabel = "Parameter file and modulepart must be both provided.";
|
||||
}
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
if (!$error) {
|
||||
$fuser->getrights();
|
||||
|
||||
// Suppression de la chaine de caractere ../ dans $original_file
|
||||
$original_file = str_replace("../", "/", $original_file);
|
||||
|
||||
// find the subdirectory name as the reference
|
||||
if (empty($refname)) $refname = basename(dirname($original_file)."/");
|
||||
if (empty($refname)) {
|
||||
$refname = basename(dirname($original_file)."/");
|
||||
}
|
||||
|
||||
// Security check
|
||||
$check_access = dol_check_secure_access_document($modulepart, $original_file, $conf->entity, $fuser, $refname);
|
||||
@ -234,20 +239,15 @@ function getDocument($authentication, $modulepart, $file, $refname = '')
|
||||
$original_file = $check_access['original_file'];
|
||||
|
||||
// Basic protection (against external users only)
|
||||
if ($fuser->socid > 0)
|
||||
{
|
||||
if ($sqlprotectagainstexternals)
|
||||
{
|
||||
if ($fuser->socid > 0) {
|
||||
if ($sqlprotectagainstexternals) {
|
||||
$resql = $db->query($sqlprotectagainstexternals);
|
||||
if ($resql)
|
||||
{
|
||||
if ($resql) {
|
||||
$num = $db->num_rows($resql);
|
||||
$i = 0;
|
||||
while ($i < $num)
|
||||
{
|
||||
while ($i < $num) {
|
||||
$obj = $db->fetch_object($resql);
|
||||
if ($fuser->socid != $obj->fk_soc)
|
||||
{
|
||||
if ($fuser->socid != $obj->fk_soc) {
|
||||
$accessallowed = 0;
|
||||
break;
|
||||
}
|
||||
@ -259,8 +259,7 @@ function getDocument($authentication, $modulepart, $file, $refname = '')
|
||||
|
||||
// Security:
|
||||
// Limite acces si droits non corrects
|
||||
if (!$accessallowed)
|
||||
{
|
||||
if (!$accessallowed) {
|
||||
$errorcode = 'NOT_PERMITTED';
|
||||
$errorlabel = 'Access not allowed';
|
||||
$error++;
|
||||
@ -269,8 +268,7 @@ function getDocument($authentication, $modulepart, $file, $refname = '')
|
||||
// Security:
|
||||
// On interdit les remontees de repertoire ainsi que les pipe dans
|
||||
// les noms de fichiers.
|
||||
if (preg_match('/\.\./', $original_file) || preg_match('/[<>|]/', $original_file))
|
||||
{
|
||||
if (preg_match('/\.\./', $original_file) || preg_match('/[<>|]/', $original_file)) {
|
||||
dol_syslog("Refused to deliver file ".$original_file);
|
||||
$errorcode = 'REFUSED';
|
||||
$errorlabel = '';
|
||||
@ -279,10 +277,8 @@ function getDocument($authentication, $modulepart, $file, $refname = '')
|
||||
|
||||
clearstatcache();
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
if (file_exists($original_file))
|
||||
{
|
||||
if (!$error) {
|
||||
if (file_exists($original_file)) {
|
||||
dol_syslog("Function: getDocument $original_file content-type=$type");
|
||||
|
||||
$f = fopen($original_file, 'r');
|
||||
@ -300,8 +296,7 @@ function getDocument($authentication, $modulepart, $file, $refname = '')
|
||||
'result'=>array('result_code'=>'OK', 'result_label'=>''),
|
||||
'document'=>$objectret
|
||||
);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
dol_syslog("File doesn't exist ".$original_file);
|
||||
$errorcode = 'NOT_FOUND';
|
||||
$errorlabel = '';
|
||||
@ -310,8 +305,7 @@ function getDocument($authentication, $modulepart, $file, $refname = '')
|
||||
}
|
||||
}
|
||||
|
||||
if ($error)
|
||||
{
|
||||
if ($error) {
|
||||
$objectresp = array(
|
||||
'result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel)
|
||||
);
|
||||
|
||||
@ -42,8 +42,7 @@ dol_syslog("Call Dolibarr webservices interfaces");
|
||||
$langs->load("main");
|
||||
|
||||
// Enable and test if module web services is enabled
|
||||
if (empty($conf->global->MAIN_MODULE_WEBSERVICES))
|
||||
{
|
||||
if (empty($conf->global->MAIN_MODULE_WEBSERVICES)) {
|
||||
$langs->load("admin");
|
||||
|
||||
dol_syslog("Call Dolibarr webservices interfaces with module webservices disabled");
|
||||
@ -147,7 +146,9 @@ function createPayment($authentication, $payment)
|
||||
dol_syslog("Function: createPayment login=".$authentication['login']." id=".$payment->id.
|
||||
", ref=".$payment->ref.", ref_ext=".$payment->ref_ext);
|
||||
|
||||
if ($authentication['entity']) $conf->entity = $authentication['entity'];
|
||||
if ($authentication['entity']) {
|
||||
$conf->entity = $authentication['entity'];
|
||||
}
|
||||
|
||||
// Init and check authentication
|
||||
$objectresp = array();
|
||||
@ -163,8 +164,7 @@ function createPayment($authentication, $payment)
|
||||
$errorlabel = "You must specify the amount and the third party's ID.";
|
||||
}
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
if (!$error) {
|
||||
$soc = new Societe($db);
|
||||
$soc->fetch($payment['thirdparty_id']);
|
||||
|
||||
@ -188,17 +188,14 @@ function createPayment($authentication, $payment)
|
||||
$new_payment->addPaymentToBank($fuser, 'payment', $payment['int_label'], $payment['bank_account'], $payment['emitter'], $payment['bank_source']);
|
||||
}
|
||||
|
||||
if ($result < 0)
|
||||
{
|
||||
if ($result < 0) {
|
||||
$error++;
|
||||
}
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
if (!$error) {
|
||||
$db->commit();
|
||||
$objectresp = array('result'=>array('result_code'=>'OK', 'result_label'=>''), 'id'=>$new_payment->id);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$db->rollback();
|
||||
$error++;
|
||||
$errorcode = 'KO';
|
||||
@ -207,8 +204,7 @@ function createPayment($authentication, $payment)
|
||||
}
|
||||
}
|
||||
|
||||
if ($error)
|
||||
{
|
||||
if ($error) {
|
||||
$objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
|
||||
}
|
||||
|
||||
|
||||
@ -712,7 +712,9 @@ function updateProductOrService($authentication, $product)
|
||||
$newobject->seuil_stock_alerte = isset($product['stock_alert']) ? $product['stock_alert'] : null;
|
||||
|
||||
$newobject->country_id = isset($product['country_id']) ? $product['country_id'] : 0;
|
||||
if (!empty($product['country_code'])) $newobject->country_id = getCountry($product['country_code'], 3);
|
||||
if (!empty($product['country_code'])) {
|
||||
$newobject->country_id = getCountry($product['country_code'], 3);
|
||||
}
|
||||
$newobject->customcode = isset($product['customcode']) ? $product['customcode'] : '';
|
||||
|
||||
$newobject->canvas = isset($product['canvas']) ? $product['canvas'] : '';
|
||||
|
||||
@ -21,7 +21,9 @@
|
||||
* \brief File that is entry point to call Dolibarr WebServices
|
||||
*/
|
||||
|
||||
if (!defined("NOCSRFCHECK")) define("NOCSRFCHECK", '1');
|
||||
if (!defined("NOCSRFCHECK")) {
|
||||
define("NOCSRFCHECK", '1');
|
||||
}
|
||||
|
||||
require '../master.inc.php';
|
||||
require_once NUSOAP_PATH.'/nusoap.php'; // Include SOAP
|
||||
@ -37,8 +39,7 @@ dol_syslog("Call Dolibarr webservices interfaces");
|
||||
$langs->load("main");
|
||||
|
||||
// Enable and test if module web services is enabled
|
||||
if (empty($conf->global->MAIN_MODULE_WEBSERVICES))
|
||||
{
|
||||
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>';
|
||||
@ -131,8 +132,7 @@ $server->wsdl->addComplexType(
|
||||
);
|
||||
|
||||
$project_elements = array();
|
||||
foreach ($listofreferent as $key => $label)
|
||||
{
|
||||
foreach ($listofreferent as $key => $label) {
|
||||
$project_elements[$key] = array('name'=>$key, 'type'=>'tns:elementsArray');
|
||||
}
|
||||
$server->wsdl->addComplexType(
|
||||
@ -169,18 +169,21 @@ $extrafield_array = null;
|
||||
if (is_array($extrafields) && count($extrafields) > 0) {
|
||||
$extrafield_array = array();
|
||||
}
|
||||
if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label']))
|
||||
{
|
||||
foreach ($extrafields->attributes[$elementtype]['label'] as $key=>$label)
|
||||
{
|
||||
if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) {
|
||||
foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) {
|
||||
//$value=$object->array_options["options_".$key];
|
||||
$type = $extrafields->attributes[$elementtype]['type'][$key];
|
||||
if ($type == 'date' || $type == 'datetime') {$type = 'xsd:dateTime'; }
|
||||
else {$type = 'xsd:string'; }
|
||||
if ($type == 'date' || $type == 'datetime') {
|
||||
$type = 'xsd:dateTime';
|
||||
} else {
|
||||
$type = 'xsd:string';
|
||||
}
|
||||
$extrafield_array['options_'.$key] = array('name'=>'options_'.$key, 'type'=>$type);
|
||||
}
|
||||
}
|
||||
if (is_array($extrafield_array)) $project_fields = array_merge($project_fields, $extrafield_array);
|
||||
if (is_array($extrafield_array)) {
|
||||
$project_fields = array_merge($project_fields, $extrafield_array);
|
||||
}
|
||||
|
||||
$server->wsdl->addComplexType(
|
||||
'project',
|
||||
@ -240,7 +243,9 @@ function createProject($authentication, $project)
|
||||
|
||||
dol_syslog("Function: createProject login=".$authentication['login']);
|
||||
|
||||
if ($authentication['entity']) $conf->entity = $authentication['entity'];
|
||||
if ($authentication['entity']) {
|
||||
$conf->entity = $authentication['entity'];
|
||||
}
|
||||
|
||||
// Init and check authentication
|
||||
$objectresp = array();
|
||||
@ -248,18 +253,15 @@ function createProject($authentication, $project)
|
||||
$error = 0;
|
||||
$fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
|
||||
// Check parameters
|
||||
if (empty($project['ref']))
|
||||
{
|
||||
if (empty($project['ref'])) {
|
||||
$error++; $errorcode = 'KO'; $errorlabel = "Name is mandatory.";
|
||||
}
|
||||
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
if (!$error) {
|
||||
$fuser->getrights();
|
||||
|
||||
if ($fuser->rights->projet->creer)
|
||||
{
|
||||
if ($fuser->rights->projet->creer) {
|
||||
$newobject = new Project($db);
|
||||
$newobject->ref = $project['ref'];
|
||||
$newobject->title = $project['label'];
|
||||
@ -277,10 +279,8 @@ function createProject($authentication, $project)
|
||||
// fetch optionals attributes and labels
|
||||
$extrafields = new ExtraFields($db);
|
||||
$extrafields->fetch_name_optionals_label($elementtype, true);
|
||||
if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label']))
|
||||
{
|
||||
foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label)
|
||||
{
|
||||
if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) {
|
||||
foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) {
|
||||
$key = 'options_'.$key;
|
||||
$newobject->array_options[$key] = $project[$key];
|
||||
}
|
||||
@ -289,39 +289,32 @@ function createProject($authentication, $project)
|
||||
$db->begin();
|
||||
|
||||
$result = $newobject->create($fuser);
|
||||
if (!$error && $result > 0)
|
||||
{
|
||||
if (!$error && $result > 0) {
|
||||
// Add myself as project leader
|
||||
$result = $newobject->add_contact($fuser->id, 'PROJECTLEADER', 'internal');
|
||||
if ($result < 0)
|
||||
{
|
||||
if ($result < 0) {
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$error++;
|
||||
}
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
if (!$error) {
|
||||
$db->commit();
|
||||
$objectresp = array('result'=>array('result_code'=>'OK', 'result_label'=>''), 'id'=>$newobject->id, 'ref'=>$newobject->ref);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$db->rollback();
|
||||
$error++;
|
||||
$errorcode = 'KO';
|
||||
$errorlabel = $newobject->error;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$error++;
|
||||
$errorcode = 'PERMISSION_DENIED'; $errorlabel = 'User does not have permission for this request';
|
||||
}
|
||||
}
|
||||
|
||||
if ($error)
|
||||
{
|
||||
if ($error) {
|
||||
$objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
|
||||
}
|
||||
|
||||
@ -342,7 +335,9 @@ function getProject($authentication, $id = '', $ref = '')
|
||||
|
||||
dol_syslog("Function: getProject login=".$authentication['login']." id=".$id." ref=".$ref);
|
||||
|
||||
if ($authentication['entity']) $conf->entity = $authentication['entity'];
|
||||
if ($authentication['entity']) {
|
||||
$conf->entity = $authentication['entity'];
|
||||
}
|
||||
|
||||
// Init and check authentication
|
||||
$objectresp = array();
|
||||
@ -350,22 +345,18 @@ function getProject($authentication, $id = '', $ref = '')
|
||||
$error = 0;
|
||||
$fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
|
||||
// Check parameters
|
||||
if (!$error && (($id && $ref)))
|
||||
{
|
||||
if (!$error && (($id && $ref))) {
|
||||
$error++;
|
||||
$errorcode = 'BAD_PARAMETERS'; $errorlabel = "Parameter id and ref can't be both provided. You must choose one or other but not both.";
|
||||
}
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
if (!$error) {
|
||||
$fuser->getrights();
|
||||
|
||||
if ($fuser->rights->projet->lire)
|
||||
{
|
||||
if ($fuser->rights->projet->lire) {
|
||||
$project = new Project($db);
|
||||
$result = $project->fetch($id, $ref);
|
||||
if ($result > 0)
|
||||
{
|
||||
if ($result > 0) {
|
||||
$project_result_fields = array(
|
||||
'id' => $project->id,
|
||||
'ref' => $project->ref,
|
||||
@ -386,11 +377,9 @@ function getProject($authentication, $id = '', $ref = '')
|
||||
$extrafields->fetch_name_optionals_label($elementtype, true);
|
||||
|
||||
//Get extrafield values
|
||||
if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label']))
|
||||
{
|
||||
if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) {
|
||||
$project->fetch_optionals();
|
||||
foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label)
|
||||
{
|
||||
foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) {
|
||||
$project_result_fields = array_merge($project_result_fields, array('options_'.$key => $project->array_options['options_'.$key]));
|
||||
}
|
||||
}
|
||||
@ -398,14 +387,11 @@ function getProject($authentication, $id = '', $ref = '')
|
||||
//Get linked elements
|
||||
global $listofreferent;
|
||||
$elements = array();
|
||||
foreach ($listofreferent as $key => $tablename)
|
||||
{
|
||||
foreach ($listofreferent as $key => $tablename) {
|
||||
$elements[$key] = array();
|
||||
$element_array = $project->get_element_list($key, $tablename);
|
||||
if (count($element_array) > 0 && is_array($element_array))
|
||||
{
|
||||
foreach ($element_array as $element)
|
||||
{
|
||||
if (count($element_array) > 0 && is_array($element_array)) {
|
||||
foreach ($element_array as $element) {
|
||||
$tmp = explode('_', $element);
|
||||
$idofelement = count($tmp) > 0 ? $tmp[0] : "";
|
||||
$idofelementuser = count($tmp) > 1 ? $tmp[1] : "";
|
||||
@ -420,20 +406,17 @@ function getProject($authentication, $id = '', $ref = '')
|
||||
'result'=>array('result_code'=>'OK', 'result_label'=>''),
|
||||
'project'=>$project_result_fields
|
||||
);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$error++;
|
||||
$errorcode = 'NOT_FOUND'; $errorlabel = 'Object not found for id='.$id.' nor ref='.$ref;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$error++;
|
||||
$errorcode = 'PERMISSION_DENIED'; $errorlabel = 'User does not have permission for this request';
|
||||
}
|
||||
}
|
||||
|
||||
if ($error)
|
||||
{
|
||||
if ($error) {
|
||||
$objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
|
||||
}
|
||||
|
||||
|
||||
@ -20,7 +20,9 @@
|
||||
* \brief File that is entry point to call Dolibarr WebServices
|
||||
*/
|
||||
|
||||
if (!defined("NOCSRFCHECK")) define("NOCSRFCHECK", '1');
|
||||
if (!defined("NOCSRFCHECK")) {
|
||||
define("NOCSRFCHECK", '1');
|
||||
}
|
||||
|
||||
require '../master.inc.php';
|
||||
require_once NUSOAP_PATH.'/nusoap.php'; // Include SOAP
|
||||
@ -34,8 +36,7 @@ dol_syslog("Call Dolibarr webservices interfaces");
|
||||
$langs->load("main");
|
||||
|
||||
// Enable and test if module web services is enabled
|
||||
if (empty($conf->global->MAIN_MODULE_WEBSERVICES))
|
||||
{
|
||||
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>';
|
||||
@ -229,7 +230,9 @@ function getSupplierInvoice($authentication, $id = '', $ref = '', $ref_ext = '')
|
||||
|
||||
dol_syslog("Function: getSupplierInvoice login=".$authentication['login']." id=".$id." ref=".$ref." ref_ext=".$ref_ext);
|
||||
|
||||
if ($authentication['entity']) $conf->entity = $authentication['entity'];
|
||||
if ($authentication['entity']) {
|
||||
$conf->entity = $authentication['entity'];
|
||||
}
|
||||
|
||||
// Init and check authentication
|
||||
$objectresp = array();
|
||||
@ -237,26 +240,21 @@ function getSupplierInvoice($authentication, $id = '', $ref = '', $ref_ext = '')
|
||||
$error = 0;
|
||||
$fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
|
||||
// Check parameters
|
||||
if (!$error && (($id && $ref) || ($id && $ref_ext) || ($ref && $ref_ext)))
|
||||
{
|
||||
if (!$error && (($id && $ref) || ($id && $ref_ext) || ($ref && $ref_ext))) {
|
||||
$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)
|
||||
{
|
||||
if (!$error) {
|
||||
$fuser->getrights();
|
||||
|
||||
if ($fuser->rights->fournisseur->facture->lire)
|
||||
{
|
||||
if ($fuser->rights->fournisseur->facture->lire) {
|
||||
$invoice = new FactureFournisseur($db);
|
||||
$result = $invoice->fetch($id, $ref, $ref_ext);
|
||||
if ($result > 0)
|
||||
{
|
||||
if ($result > 0) {
|
||||
$linesresp = array();
|
||||
$i = 0;
|
||||
foreach ($invoice->lines as $line)
|
||||
{
|
||||
foreach ($invoice->lines as $line) {
|
||||
//var_dump($line); exit;
|
||||
$linesresp[] = array(
|
||||
'id'=>$line->rowid,
|
||||
@ -275,7 +273,7 @@ function getSupplierInvoice($authentication, $id = '', $ref = '', $ref_ext = '')
|
||||
'result'=>array('result_code'=>'OK', 'result_label'=>''),
|
||||
'invoice'=>array(
|
||||
'id' => $invoice->id,
|
||||
'ref' => $invoice->ref,
|
||||
'ref' => $invoice->ref,
|
||||
'ref_supplier'=>$invoice->ref_supplier,
|
||||
'ref_ext' => $invoice->ref_ext,
|
||||
'fk_user_author' => $invoice->fk_user_author,
|
||||
@ -302,20 +300,17 @@ function getSupplierInvoice($authentication, $id = '', $ref = '', $ref_ext = '')
|
||||
// '1'=>array('id'=>333,'type'=>1)),
|
||||
|
||||
));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$error++;
|
||||
$errorcode = 'NOT_FOUND'; $errorlabel = 'Object not found for id='.$id.' nor ref='.$ref.' nor ref_ext='.$ref_ext;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$error++;
|
||||
$errorcode = 'PERMISSION_DENIED'; $errorlabel = 'User does not have permission for this request';
|
||||
}
|
||||
}
|
||||
|
||||
if ($error)
|
||||
{
|
||||
if ($error) {
|
||||
$objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
|
||||
}
|
||||
|
||||
@ -337,7 +332,9 @@ function getSupplierInvoicesForThirdParty($authentication, $idthirdparty)
|
||||
|
||||
dol_syslog("Function: getSupplierInvoicesForThirdParty login=".$authentication['login']." idthirdparty=".$idthirdparty);
|
||||
|
||||
if ($authentication['entity']) $conf->entity = $authentication['entity'];
|
||||
if ($authentication['entity']) {
|
||||
$conf->entity = $authentication['entity'];
|
||||
}
|
||||
|
||||
// Init and check authentication
|
||||
$objectresp = array();
|
||||
@ -346,14 +343,12 @@ function getSupplierInvoicesForThirdParty($authentication, $idthirdparty)
|
||||
$fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
|
||||
|
||||
// Check parameters
|
||||
if (!$error && empty($idthirdparty))
|
||||
{
|
||||
if (!$error && empty($idthirdparty)) {
|
||||
$error++;
|
||||
$errorcode = 'BAD_PARAMETERS'; $errorlabel = 'Parameter id is not provided';
|
||||
}
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
if (!$error) {
|
||||
$linesinvoice = array();
|
||||
|
||||
$sql .= 'SELECT f.rowid as facid';
|
||||
@ -363,22 +358,21 @@ function getSupplierInvoicesForThirdParty($authentication, $idthirdparty)
|
||||
//$sql.=" WHERE f.fk_soc = s.rowid AND nom = '".$db->escape($idthirdparty)."'";
|
||||
//$sql.=" WHERE f.fk_soc = s.rowid AND nom = '".$db->escape($idthirdparty)."'";
|
||||
$sql .= " WHERE f.entity = ".$conf->entity;
|
||||
if ($idthirdparty != 'all') $sql .= " AND f.fk_soc = ".$db->escape($idthirdparty);
|
||||
if ($idthirdparty != 'all') {
|
||||
$sql .= " AND f.fk_soc = ".$db->escape($idthirdparty);
|
||||
}
|
||||
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
if ($resql) {
|
||||
$num = $db->num_rows($resql);
|
||||
$i = 0;
|
||||
while ($i < $num)
|
||||
{
|
||||
while ($i < $num) {
|
||||
// En attendant remplissage par boucle
|
||||
$obj = $db->fetch_object($resql);
|
||||
|
||||
$invoice = new FactureFournisseur($db);
|
||||
$result = $invoice->fetch($obj->facid);
|
||||
if ($result < 0)
|
||||
{
|
||||
if ($result < 0) {
|
||||
$error++;
|
||||
$errorcode = $result; $errorlabel = $invoice->error;
|
||||
break;
|
||||
@ -386,9 +380,8 @@ function getSupplierInvoicesForThirdParty($authentication, $idthirdparty)
|
||||
|
||||
// Define lines of invoice
|
||||
$linesresp = array();
|
||||
foreach ($invoice->lines as $line)
|
||||
{
|
||||
$linesresp[] = array(
|
||||
foreach ($invoice->lines as $line) {
|
||||
$linesresp[] = array(
|
||||
'id'=>$line->rowid,
|
||||
'type'=>$line->product_type,
|
||||
'desc'=>dol_htmlcleanlastbr($line->description),
|
||||
@ -397,10 +390,10 @@ function getSupplierInvoicesForThirdParty($authentication, $idthirdparty)
|
||||
'total'=>$line->total_ttc,
|
||||
'vat_rate'=>$line->tva_tx,
|
||||
'qty'=>$line->qty,
|
||||
'product_ref'=>$line->product_ref,
|
||||
'product_ref'=>$line->product_ref,
|
||||
'product_label'=>$line->product_label,
|
||||
'product_desc'=>$line->product_desc,
|
||||
);
|
||||
);
|
||||
}
|
||||
|
||||
// Now define invoice
|
||||
@ -439,15 +432,13 @@ function getSupplierInvoicesForThirdParty($authentication, $idthirdparty)
|
||||
'invoices'=>$linesinvoice
|
||||
|
||||
);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$error++;
|
||||
$errorcode = $db->lasterrno(); $errorlabel = $db->lasterror();
|
||||
}
|
||||
}
|
||||
|
||||
if ($error)
|
||||
{
|
||||
if ($error) {
|
||||
$objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
|
||||
}
|
||||
|
||||
|
||||
@ -20,7 +20,9 @@
|
||||
* \brief File that is entry point to call Dolibarr WebServices
|
||||
*/
|
||||
|
||||
if (!defined("NOCSRFCHECK")) define("NOCSRFCHECK", '1');
|
||||
if (!defined("NOCSRFCHECK")) {
|
||||
define("NOCSRFCHECK", '1');
|
||||
}
|
||||
|
||||
require_once '../master.inc.php';
|
||||
require_once NUSOAP_PATH.'/nusoap.php'; // Include SOAP
|
||||
@ -36,8 +38,7 @@ dol_syslog("Call Dolibarr webservices interfaces");
|
||||
$langs->load("main");
|
||||
|
||||
// Enable and test if module web services is enabled
|
||||
if (empty($conf->global->MAIN_MODULE_WEBSERVICES))
|
||||
{
|
||||
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>';
|
||||
@ -130,20 +131,23 @@ $extrafield_array = null;
|
||||
if (is_array($extrafields) && count($extrafields) > 0) {
|
||||
$extrafield_array = array();
|
||||
}
|
||||
if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label']))
|
||||
{
|
||||
foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label)
|
||||
{
|
||||
if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) {
|
||||
foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) {
|
||||
//$value=$object->array_options["options_".$key];
|
||||
$type = $extrafields->attributes[$elementtype]['type'][$key];
|
||||
if ($type == 'date' || $type == 'datetime') {$type = 'xsd:dateTime'; }
|
||||
else {$type = 'xsd:string'; }
|
||||
if ($type == 'date' || $type == 'datetime') {
|
||||
$type = 'xsd:dateTime';
|
||||
} else {
|
||||
$type = 'xsd:string';
|
||||
}
|
||||
|
||||
$extrafield_array['options_'.$key] = array('name'=>'options_'.$key, 'type'=>$type);
|
||||
}
|
||||
}
|
||||
|
||||
if (is_array($extrafield_array)) $thirdparty_fields = array_merge($thirdparty_fields, $extrafield_array);
|
||||
if (is_array($extrafield_array)) {
|
||||
$thirdparty_fields = array_merge($thirdparty_fields, $extrafield_array);
|
||||
}
|
||||
|
||||
// Define other specific objects
|
||||
$server->wsdl->addComplexType(
|
||||
@ -265,16 +269,16 @@ $server->register(
|
||||
|
||||
// Register WSDL
|
||||
$server->register(
|
||||
'deleteThirdParty',
|
||||
// Entry values
|
||||
'deleteThirdParty',
|
||||
// Entry values
|
||||
array('authentication'=>'tns:authentication', 'id'=>'xsd:string', 'ref'=>'xsd:string', 'ref_ext'=>'xsd:string'),
|
||||
// Exit values
|
||||
// Exit values
|
||||
array('result'=>'tns:result', 'id'=>'xsd:string'),
|
||||
$ns,
|
||||
$ns.'#deleteThirdParty',
|
||||
$styledoc,
|
||||
$styleuse,
|
||||
'WS to delete a thirdparty from its id, ref or ref_ext'
|
||||
$ns,
|
||||
$ns.'#deleteThirdParty',
|
||||
$styledoc,
|
||||
$styleuse,
|
||||
'WS to delete a thirdparty from its id, ref or ref_ext'
|
||||
);
|
||||
|
||||
|
||||
@ -294,7 +298,9 @@ function getThirdParty($authentication, $id = '', $ref = '', $ref_ext = '')
|
||||
|
||||
dol_syslog("Function: getThirdParty login=".$authentication['login']." id=".$id." ref=".$ref." ref_ext=".$ref_ext);
|
||||
|
||||
if ($authentication['entity']) $conf->entity = $authentication['entity'];
|
||||
if ($authentication['entity']) {
|
||||
$conf->entity = $authentication['entity'];
|
||||
}
|
||||
|
||||
// Init and check authentication
|
||||
$objectresp = array();
|
||||
@ -302,27 +308,23 @@ function getThirdParty($authentication, $id = '', $ref = '', $ref_ext = '')
|
||||
$error = 0;
|
||||
$fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
|
||||
// Check parameters
|
||||
if (!$error && (($id && $ref) || ($id && $ref_ext) || ($ref && $ref_ext)))
|
||||
{
|
||||
if (!$error && (($id && $ref) || ($id && $ref_ext) || ($ref && $ref_ext))) {
|
||||
$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)
|
||||
{
|
||||
if (!$error) {
|
||||
$fuser->getrights();
|
||||
|
||||
if ($fuser->rights->societe->lire)
|
||||
{
|
||||
if ($fuser->rights->societe->lire) {
|
||||
$thirdparty = new Societe($db);
|
||||
$result = $thirdparty->fetch($id, $ref, $ref_ext);
|
||||
if ($result > 0)
|
||||
{
|
||||
if ($result > 0) {
|
||||
$thirdparty_result_fields = array(
|
||||
'id' => $thirdparty->id,
|
||||
'ref' => $thirdparty->name,
|
||||
'ref_ext' => $thirdparty->ref_ext,
|
||||
'status' => $thirdparty->status,
|
||||
'ref' => $thirdparty->name,
|
||||
'ref_ext' => $thirdparty->ref_ext,
|
||||
'status' => $thirdparty->status,
|
||||
'client' => $thirdparty->client,
|
||||
'supplier' => $thirdparty->fournisseur,
|
||||
'customer_code' => $thirdparty->code_client,
|
||||
@ -351,7 +353,7 @@ function getThirdParty($authentication, $id = '', $ref = '', $ref_ext = '')
|
||||
'profid5' => $thirdparty->idprof5,
|
||||
'profid6' => $thirdparty->idprof6,
|
||||
'capital' => $thirdparty->capital,
|
||||
'barcode' => $thirdparty->barcode,
|
||||
'barcode' => $thirdparty->barcode,
|
||||
'vat_used' => $thirdparty->tva_assuj,
|
||||
'vat_number' => $thirdparty->tva_intra,
|
||||
'note_private' => $thirdparty->note_private,
|
||||
@ -366,10 +368,8 @@ function getThirdParty($authentication, $id = '', $ref = '', $ref_ext = '')
|
||||
//Get extrafield values
|
||||
$thirdparty->fetch_optionals();
|
||||
|
||||
if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label']))
|
||||
{
|
||||
foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label)
|
||||
{
|
||||
if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) {
|
||||
foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) {
|
||||
if (isset($thirdparty->array_options['options_'.$key])) {
|
||||
$thirdparty_result_fields = array_merge($thirdparty_result_fields, array('options_'.$key => $thirdparty->array_options['options_'.$key]));
|
||||
}
|
||||
@ -380,20 +380,17 @@ function getThirdParty($authentication, $id = '', $ref = '', $ref_ext = '')
|
||||
$objectresp = array(
|
||||
'result'=>array('result_code'=>'OK', 'result_label'=>''),
|
||||
'thirdparty'=>$thirdparty_result_fields);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$error++;
|
||||
$errorcode = 'NOT_FOUND'; $errorlabel = 'Object not found for id='.$id.' nor ref='.$ref.' nor ref_ext='.$ref_ext;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$error++;
|
||||
$errorcode = 'PERMISSION_DENIED'; $errorlabel = 'User does not have permission for this request';
|
||||
}
|
||||
}
|
||||
|
||||
if ($error)
|
||||
{
|
||||
if ($error) {
|
||||
$objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
|
||||
}
|
||||
|
||||
@ -417,7 +414,9 @@ function createThirdParty($authentication, $thirdparty)
|
||||
|
||||
dol_syslog("Function: createThirdParty login=".$authentication['login']);
|
||||
|
||||
if ($authentication['entity']) $conf->entity = $authentication['entity'];
|
||||
if ($authentication['entity']) {
|
||||
$conf->entity = $authentication['entity'];
|
||||
}
|
||||
|
||||
// Init and check authentication
|
||||
$objectresp = array();
|
||||
@ -425,14 +424,12 @@ function createThirdParty($authentication, $thirdparty)
|
||||
$error = 0;
|
||||
$fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
|
||||
// Check parameters
|
||||
if (empty($thirdparty['ref']))
|
||||
{
|
||||
if (empty($thirdparty['ref'])) {
|
||||
$error++; $errorcode = 'KO'; $errorlabel = "Name is mandatory.";
|
||||
}
|
||||
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
if (!$error) {
|
||||
include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
|
||||
|
||||
$newobject = new Societe($db);
|
||||
@ -454,7 +451,9 @@ function createThirdParty($authentication, $thirdparty)
|
||||
$newobject->town = $thirdparty['town'];
|
||||
|
||||
$newobject->country_id = $thirdparty['country_id'];
|
||||
if ($thirdparty['country_code']) $newobject->country_id = getCountry($thirdparty['country_code'], 3);
|
||||
if ($thirdparty['country_code']) {
|
||||
$newobject->country_id = getCountry($thirdparty['country_code'], 3);
|
||||
}
|
||||
$newobject->province_id = $thirdparty['province_id'];
|
||||
//if ($thirdparty['province_code']) $newobject->province_code=getCountry($thirdparty['province_code'],3);
|
||||
|
||||
@ -484,10 +483,8 @@ function createThirdParty($authentication, $thirdparty)
|
||||
// fetch optionals attributes and labels
|
||||
$extrafields = new ExtraFields($db);
|
||||
$extrafields->fetch_name_optionals_label($elementtype, true);
|
||||
if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label']))
|
||||
{
|
||||
foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label)
|
||||
{
|
||||
if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) {
|
||||
foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) {
|
||||
$key = 'options_'.$key;
|
||||
if (isset($thirdparty[$key])) {
|
||||
$newobject->array_options[$key] = $thirdparty[$key];
|
||||
@ -503,22 +500,20 @@ function createThirdParty($authentication, $thirdparty)
|
||||
$newobject->name_bis = $thirdparty['lastname'];
|
||||
$result = $newobject->create_individual($fuser);
|
||||
}
|
||||
if ($result <= 0)
|
||||
{
|
||||
if ($result <= 0) {
|
||||
$error++;
|
||||
}
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
if (!$error) {
|
||||
$db->commit();
|
||||
|
||||
// Patch to add capability to associate (one) sale representative
|
||||
if (!empty($thirdparty['commid']) && $thirdparty['commid'] > 0)
|
||||
if (!empty($thirdparty['commid']) && $thirdparty['commid'] > 0) {
|
||||
$newobject->add_commercial($fuser, $thirdparty["commid"]);
|
||||
}
|
||||
|
||||
$objectresp = array('result'=>array('result_code'=>'OK', 'result_label'=>''), 'id'=>$newobject->id, 'ref'=>$newobject->ref);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$db->rollback();
|
||||
$error++;
|
||||
$errorcode = 'KO';
|
||||
@ -526,8 +521,7 @@ function createThirdParty($authentication, $thirdparty)
|
||||
}
|
||||
}
|
||||
|
||||
if ($error)
|
||||
{
|
||||
if ($error) {
|
||||
$objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
|
||||
}
|
||||
|
||||
@ -549,7 +543,9 @@ function updateThirdParty($authentication, $thirdparty)
|
||||
|
||||
dol_syslog("Function: updateThirdParty login=".$authentication['login']);
|
||||
|
||||
if ($authentication['entity']) $conf->entity = $authentication['entity'];
|
||||
if ($authentication['entity']) {
|
||||
$conf->entity = $authentication['entity'];
|
||||
}
|
||||
|
||||
// Init and check authentication
|
||||
$objectresp = array();
|
||||
@ -561,8 +557,7 @@ function updateThirdParty($authentication, $thirdparty)
|
||||
$error++; $errorcode = 'KO'; $errorlabel = "Thirdparty id is mandatory.";
|
||||
}
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
if (!$error) {
|
||||
$objectfound = false;
|
||||
|
||||
include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
|
||||
@ -591,7 +586,9 @@ function updateThirdParty($authentication, $thirdparty)
|
||||
$object->town = $thirdparty['town'];
|
||||
|
||||
$object->country_id = $thirdparty['country_id'];
|
||||
if ($thirdparty['country_code']) $object->country_id = getCountry($thirdparty['country_code'], 3);
|
||||
if ($thirdparty['country_code']) {
|
||||
$object->country_id = getCountry($thirdparty['country_code'], 3);
|
||||
}
|
||||
$object->province_id = $thirdparty['province_id'];
|
||||
//if ($thirdparty['province_code']) $newobject->province_code=getCountry($thirdparty['province_code'],3);
|
||||
|
||||
@ -620,10 +617,8 @@ function updateThirdParty($authentication, $thirdparty)
|
||||
// fetch optionals attributes and labels
|
||||
$extrafields = new ExtraFields($db);
|
||||
$extrafields->fetch_name_optionals_label($elementtype, true);
|
||||
if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label']))
|
||||
{
|
||||
foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label)
|
||||
{
|
||||
if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) {
|
||||
foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) {
|
||||
$key = 'options_'.$key;
|
||||
if (isset($thirdparty[$key])) {
|
||||
$object->array_options[$key] = $thirdparty[$key];
|
||||
@ -639,16 +634,13 @@ function updateThirdParty($authentication, $thirdparty)
|
||||
}
|
||||
}
|
||||
|
||||
if ((!$error) && ($objectfound))
|
||||
{
|
||||
if ((!$error) && ($objectfound)) {
|
||||
$db->commit();
|
||||
$objectresp = array(
|
||||
'result'=>array('result_code'=>'OK', 'result_label'=>''),
|
||||
'id'=>$object->id
|
||||
);
|
||||
}
|
||||
elseif ($objectfound)
|
||||
{
|
||||
} elseif ($objectfound) {
|
||||
$db->rollback();
|
||||
$error++;
|
||||
$errorcode = 'KO';
|
||||
@ -660,8 +652,7 @@ function updateThirdParty($authentication, $thirdparty)
|
||||
}
|
||||
}
|
||||
|
||||
if ($error)
|
||||
{
|
||||
if ($error) {
|
||||
$objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
|
||||
}
|
||||
|
||||
@ -683,7 +674,9 @@ function getListOfThirdParties($authentication, $filterthirdparty)
|
||||
|
||||
dol_syslog("Function: getListOfThirdParties login=".$authentication['login']);
|
||||
|
||||
if ($authentication['entity']) $conf->entity = $authentication['entity'];
|
||||
if ($authentication['entity']) {
|
||||
$conf->entity = $authentication['entity'];
|
||||
}
|
||||
|
||||
// Init and check authentication
|
||||
$objectresp = array();
|
||||
@ -694,20 +687,26 @@ function getListOfThirdParties($authentication, $filterthirdparty)
|
||||
$fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
|
||||
// Check parameters
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
if (!$error) {
|
||||
$sql = "SELECT s.rowid as socRowid, s.nom as ref, s.ref_ext, s.address, s.zip, s.town, c.label as country, s.phone, s.fax, s.url, extra.*";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON s.fk_pays = c.rowid";
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_extrafields as extra ON s.rowid=fk_object";
|
||||
|
||||
$sql .= " WHERE entity=".$conf->entity;
|
||||
foreach ($filterthirdparty as $key => $val)
|
||||
{
|
||||
if ($key == 'name' && $val != '') $sql .= " AND s.name LIKE '%".$db->escape($val)."%'";
|
||||
if ($key == 'client' && (int) $val > 0) $sql .= " AND s.client = ".$db->escape($val);
|
||||
if ($key == 'supplier' && (int) $val > 0) $sql .= " AND s.fournisseur = ".$db->escape($val);
|
||||
if ($key == 'category' && (int) $val > 0) $sql .= " AND s.rowid IN (SELECT fk_soc FROM ".MAIN_DB_PREFIX."categorie_societe WHERE fk_categorie=".$db->escape($val).") ";
|
||||
foreach ($filterthirdparty as $key => $val) {
|
||||
if ($key == 'name' && $val != '') {
|
||||
$sql .= " AND s.name LIKE '%".$db->escape($val)."%'";
|
||||
}
|
||||
if ($key == 'client' && (int) $val > 0) {
|
||||
$sql .= " AND s.client = ".$db->escape($val);
|
||||
}
|
||||
if ($key == 'supplier' && (int) $val > 0) {
|
||||
$sql .= " AND s.fournisseur = ".$db->escape($val);
|
||||
}
|
||||
if ($key == 'category' && (int) $val > 0) {
|
||||
$sql .= " AND s.rowid IN (SELECT fk_soc FROM ".MAIN_DB_PREFIX."categorie_societe WHERE fk_categorie=".$db->escape($val).") ";
|
||||
}
|
||||
}
|
||||
dol_syslog("Function: getListOfThirdParties", LOG_DEBUG);
|
||||
|
||||
@ -718,20 +717,16 @@ function getListOfThirdParties($authentication, $filterthirdparty)
|
||||
|
||||
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
if ($resql) {
|
||||
$num = $db->num_rows($resql);
|
||||
|
||||
$i = 0;
|
||||
while ($i < $num)
|
||||
{
|
||||
while ($i < $num) {
|
||||
$extrafieldsOptions = array();
|
||||
$obj = $db->fetch_object($resql);
|
||||
|
||||
if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label']))
|
||||
{
|
||||
foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label)
|
||||
{
|
||||
if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) {
|
||||
foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) {
|
||||
if (isset($obj->{$key})) {
|
||||
$extrafieldsOptions['options_'.$key] = $obj->{$key};
|
||||
}
|
||||
@ -753,22 +748,19 @@ function getListOfThirdParties($authentication, $filterthirdparty)
|
||||
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$error++;
|
||||
$errorcode = $db->lasterrno();
|
||||
$errorlabel = $db->lasterror();
|
||||
}
|
||||
}
|
||||
|
||||
if ($error)
|
||||
{
|
||||
if ($error) {
|
||||
$objectresp = array(
|
||||
'result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel),
|
||||
'thirdparties'=>$arraythirdparties
|
||||
);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$objectresp = array(
|
||||
'result'=>array('result_code' => 'OK', 'result_label' => ''),
|
||||
'thirdparties'=>$arraythirdparties
|
||||
@ -793,7 +785,9 @@ function deleteThirdParty($authentication, $id = '', $ref = '', $ref_ext = '')
|
||||
|
||||
dol_syslog("Function: deleteThirdParty login=".$authentication['login']." id=".$id." ref=".$ref." ref_ext=".$ref_ext);
|
||||
|
||||
if ($authentication['entity']) $conf->entity = $authentication['entity'];
|
||||
if ($authentication['entity']) {
|
||||
$conf->entity = $authentication['entity'];
|
||||
}
|
||||
|
||||
// Init and check authentication
|
||||
$objectresp = array();
|
||||
@ -801,56 +795,47 @@ function deleteThirdParty($authentication, $id = '', $ref = '', $ref_ext = '')
|
||||
$error = 0;
|
||||
$fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
|
||||
// Check parameters
|
||||
if (!$error && (($id && $ref) || ($id && $ref_ext) || ($ref && $ref_ext)))
|
||||
{
|
||||
if (!$error && (($id && $ref) || ($id && $ref_ext) || ($ref && $ref_ext))) {
|
||||
dol_syslog("Function: deleteThirdParty checkparam");
|
||||
$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.";
|
||||
}
|
||||
dol_syslog("Function: deleteThirdParty 1");
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
if (!$error) {
|
||||
$fuser->getrights();
|
||||
|
||||
if ($fuser->rights->societe->lire && $fuser->rights->societe->supprimer)
|
||||
{
|
||||
if ($fuser->rights->societe->lire && $fuser->rights->societe->supprimer) {
|
||||
$thirdparty = new Societe($db);
|
||||
$result = $thirdparty->fetch($id, $ref, $ref_ext);
|
||||
|
||||
if ($result > 0)
|
||||
{
|
||||
if ($result > 0) {
|
||||
$db->begin();
|
||||
|
||||
$result = $thirdparty->delete($thirdparty->id, $fuser);
|
||||
|
||||
if ($result > 0)
|
||||
{
|
||||
if ($result > 0) {
|
||||
$db->commit();
|
||||
|
||||
$objectresp = array('result'=>array('result_code'=>'OK', 'result_label'=>''));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$db->rollback();
|
||||
$error++;
|
||||
$errorcode = 'KO';
|
||||
$errorlabel = $thirdparty->error;
|
||||
dol_syslog("Function: deleteThirdParty cant delete");
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$error++;
|
||||
$errorcode = 'NOT_FOUND'; $errorlabel = 'Object not found for id='.$id.' nor ref='.$ref.' nor ref_ext='.$ref_ext;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$error++;
|
||||
$errorcode = 'PERMISSION_DENIED'; $errorlabel = 'User does not have permission for this request';
|
||||
}
|
||||
}
|
||||
|
||||
if ($error)
|
||||
{
|
||||
if ($error) {
|
||||
$objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
|
||||
}
|
||||
|
||||
|
||||
@ -20,7 +20,9 @@
|
||||
* \brief File that is entry point to call Dolibarr WebServices
|
||||
*/
|
||||
|
||||
if (!defined("NOCSRFCHECK")) define("NOCSRFCHECK", '1');
|
||||
if (!defined("NOCSRFCHECK")) {
|
||||
define("NOCSRFCHECK", '1');
|
||||
}
|
||||
|
||||
require_once '../master.inc.php';
|
||||
require_once NUSOAP_PATH.'/nusoap.php'; // Include SOAP
|
||||
@ -36,8 +38,7 @@ dol_syslog("Call User webservices interfaces");
|
||||
$langs->load("main");
|
||||
|
||||
// Enable and test if module web services is enabled
|
||||
if (empty($conf->global->MAIN_MODULE_WEBSERVICES))
|
||||
{
|
||||
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>';
|
||||
@ -193,19 +194,22 @@ $extrafield_array = null;
|
||||
if (is_array($extrafields) && count($extrafields) > 0) {
|
||||
$extrafield_array = array();
|
||||
}
|
||||
if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label']))
|
||||
{
|
||||
foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label)
|
||||
{
|
||||
if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) {
|
||||
foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) {
|
||||
$type = $extrafields->attributes[$elementtype]['type'][$key];
|
||||
if ($type == 'date' || $type == 'datetime') {$type = 'xsd:dateTime'; }
|
||||
else {$type = 'xsd:string'; }
|
||||
if ($type == 'date' || $type == 'datetime') {
|
||||
$type = 'xsd:dateTime';
|
||||
} else {
|
||||
$type = 'xsd:string';
|
||||
}
|
||||
|
||||
$extrafield_array['contact_options_'.$key] = array('name'=>'contact_options_'.$key, 'type'=>$type);
|
||||
}
|
||||
}
|
||||
|
||||
if (is_array($extrafield_array)) $thirdpartywithuser_fields = array_merge($thirdpartywithuser_fields, $extrafield_array);
|
||||
if (is_array($extrafield_array)) {
|
||||
$thirdpartywithuser_fields = array_merge($thirdpartywithuser_fields, $extrafield_array);
|
||||
}
|
||||
|
||||
|
||||
$server->wsdl->addComplexType(
|
||||
@ -312,7 +316,9 @@ function getUser($authentication, $id, $ref = '', $ref_ext = '')
|
||||
|
||||
dol_syslog("Function: getUser login=".$authentication['login']." id=".$id." ref=".$ref." ref_ext=".$ref_ext);
|
||||
|
||||
if ($authentication['entity']) $conf->entity = $authentication['entity'];
|
||||
if ($authentication['entity']) {
|
||||
$conf->entity = $authentication['entity'];
|
||||
}
|
||||
|
||||
// Init and check authentication
|
||||
$objectresp = array();
|
||||
@ -320,25 +326,21 @@ function getUser($authentication, $id, $ref = '', $ref_ext = '')
|
||||
$error = 0;
|
||||
$fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
|
||||
// Check parameters
|
||||
if (!$error && (($id && $ref) || ($id && $ref_ext) || ($ref && $ref_ext)))
|
||||
{
|
||||
if (!$error && (($id && $ref) || ($id && $ref_ext) || ($ref && $ref_ext))) {
|
||||
$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)
|
||||
{
|
||||
if (!$error) {
|
||||
$fuser->getrights();
|
||||
|
||||
if ($fuser->rights->user->user->lire
|
||||
|| ($fuser->rights->user->self->creer && $id && $id == $fuser->id)
|
||||
|| ($fuser->rights->user->self->creer && $ref && $ref == $fuser->login)
|
||||
|| ($fuser->rights->user->self->creer && $ref_ext && $ref_ext == $fuser->ref_ext))
|
||||
{
|
||||
|| ($fuser->rights->user->self->creer && $ref_ext && $ref_ext == $fuser->ref_ext)) {
|
||||
$user = new User($db);
|
||||
$result = $user->fetch($id, $ref, $ref_ext);
|
||||
if ($result > 0)
|
||||
{
|
||||
if ($result > 0) {
|
||||
// Create
|
||||
$objectresp = array(
|
||||
'result'=>array('result_code'=>'OK', 'result_label'=>''),
|
||||
@ -371,20 +373,17 @@ function getUser($authentication, $id, $ref = '', $ref_ext = '')
|
||||
'canvas' => $user->canvas
|
||||
)
|
||||
);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$error++;
|
||||
$errorcode = 'NOT_FOUND'; $errorlabel = 'Object not found for id='.$id.' nor ref='.$ref.' nor ref_ext='.$ref_ext;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$error++;
|
||||
$errorcode = 'PERMISSION_DENIED'; $errorlabel = 'User does not have permission for this request';
|
||||
}
|
||||
}
|
||||
|
||||
if ($error)
|
||||
{
|
||||
if ($error) {
|
||||
$objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
|
||||
}
|
||||
|
||||
@ -403,7 +402,9 @@ function getListOfGroups($authentication)
|
||||
|
||||
dol_syslog("Function: getListOfGroups login=".$authentication['login']);
|
||||
|
||||
if ($authentication['entity']) $conf->entity = $authentication['entity'];
|
||||
if ($authentication['entity']) {
|
||||
$conf->entity = $authentication['entity'];
|
||||
}
|
||||
|
||||
// Init and check authentication
|
||||
$objectresp = array();
|
||||
@ -413,47 +414,39 @@ function getListOfGroups($authentication)
|
||||
$fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
|
||||
// Check parameters
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
if (!$error) {
|
||||
$sql = "SELECT g.rowid, g.nom as name, 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->global->MULTICOMPANY_TRANSVERSE_MODE || ($user->admin && !$user->entity)))
|
||||
{
|
||||
if (!empty($conf->multicompany->enabled) && $conf->entity == 1 && ($conf->global->MULTICOMPANY_TRANSVERSE_MODE || ($user->admin && !$user->entity))) {
|
||||
$sql .= " WHERE g.entity IS NOT NULL";
|
||||
}
|
||||
else {
|
||||
} 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)
|
||||
{
|
||||
if ($resql) {
|
||||
$num = $db->num_rows($resql);
|
||||
|
||||
$i = 0;
|
||||
while ($i < $num)
|
||||
{
|
||||
while ($i < $num) {
|
||||
$obj = $db->fetch_object($resql);
|
||||
$arraygroups[] = array('id'=>$obj->rowid, 'name'=>$obj->name, 'datec'=>$obj->datec, 'nb'=>$obj->nb);
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$error++;
|
||||
$errorcode = $db->lasterrno();
|
||||
$errorlabel = $db->lasterror();
|
||||
}
|
||||
}
|
||||
|
||||
if ($error)
|
||||
{
|
||||
if ($error) {
|
||||
$objectresp = array(
|
||||
'result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel),
|
||||
'groups'=>$arraygroups
|
||||
);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$objectresp = array(
|
||||
'result'=>array('result_code' => 'OK', 'result_label' => ''),
|
||||
'groups'=>$arraygroups
|
||||
@ -477,7 +470,9 @@ function createUserFromThirdparty($authentication, $thirdpartywithuser)
|
||||
|
||||
dol_syslog("Function: createUserFromThirdparty login=".$authentication['login']);
|
||||
|
||||
if ($authentication['entity']) $conf->entity = $authentication['entity'];
|
||||
if ($authentication['entity']) {
|
||||
$conf->entity = $authentication['entity'];
|
||||
}
|
||||
|
||||
$objectresp = array();
|
||||
$errorcode = ''; $errorlabel = '';
|
||||
@ -485,20 +480,19 @@ function createUserFromThirdparty($authentication, $thirdpartywithuser)
|
||||
|
||||
$fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
|
||||
|
||||
if ($fuser->socid) $socid = $fuser->socid;
|
||||
if ($fuser->socid) {
|
||||
$socid = $fuser->socid;
|
||||
}
|
||||
|
||||
if (!$error && !$thirdpartywithuser)
|
||||
{
|
||||
if (!$error && !$thirdpartywithuser) {
|
||||
$error++;
|
||||
$errorcode = 'BAD_PARAMETERS'; $errorlabel = "Parameter thirdparty must be provided.";
|
||||
}
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
if (!$error) {
|
||||
$fuser->getrights();
|
||||
|
||||
if ($fuser->rights->societe->creer)
|
||||
{
|
||||
if ($fuser->rights->societe->creer) {
|
||||
$thirdparty = new Societe($db);
|
||||
|
||||
// If a contact / company already exists with the email, return the corresponding socid
|
||||
@ -510,16 +504,13 @@ function createUserFromThirdparty($authentication, $thirdpartywithuser)
|
||||
$sql .= $db->plimit(1);
|
||||
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
if ($resql) {
|
||||
// If a company or contact is found with the same email we return an error
|
||||
$row = $db->fetch_object($resql);
|
||||
if ($row)
|
||||
{
|
||||
if ($row) {
|
||||
$error++;
|
||||
$errorcode = 'ALREADY_EXIST'; $errorlabel = 'Object not create : company or contact exists '.$thirdpartywithuser['email'];
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$db->begin();
|
||||
/*
|
||||
* Company creation
|
||||
@ -541,11 +532,9 @@ function createUserFromThirdparty($authentication, $thirdpartywithuser)
|
||||
$sql .= " AND code='".$db->escape($thirdparty->country_code)."'";
|
||||
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
if ($resql) {
|
||||
$num = $db->num_rows($resql);
|
||||
if ($num)
|
||||
{
|
||||
if ($num) {
|
||||
$obj = $db->fetch_object($resql);
|
||||
$thirdparty->country_id = $obj->rowid;
|
||||
}
|
||||
@ -567,8 +556,7 @@ function createUserFromThirdparty($authentication, $thirdpartywithuser)
|
||||
|
||||
$socid_return = $thirdparty->create($fuser);
|
||||
|
||||
if ($socid_return > 0)
|
||||
{
|
||||
if ($socid_return > 0) {
|
||||
$thirdparty->fetch($socid_return);
|
||||
|
||||
/*
|
||||
@ -597,10 +585,8 @@ function createUserFromThirdparty($authentication, $thirdpartywithuser)
|
||||
// fetch optionals attributes and labels
|
||||
$extrafields = new ExtraFields($db);
|
||||
$extrafields->fetch_name_optionals_label($elementtype, true);
|
||||
if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label']))
|
||||
{
|
||||
foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label)
|
||||
{
|
||||
if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) {
|
||||
foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) {
|
||||
$key = 'contact_options_'.$key;
|
||||
$key = substr($key, 8); // Remove 'contact_' prefix
|
||||
$contact->array_options[$key] = $thirdpartywithuser[$key];
|
||||
@ -609,8 +595,7 @@ function createUserFromThirdparty($authentication, $thirdpartywithuser)
|
||||
|
||||
$contact_id = $contact->create($fuser);
|
||||
|
||||
if ($contact_id > 0)
|
||||
{
|
||||
if ($contact_id > 0) {
|
||||
/*
|
||||
* User creation
|
||||
*
|
||||
@ -618,19 +603,17 @@ function createUserFromThirdparty($authentication, $thirdpartywithuser)
|
||||
$edituser = new User($db);
|
||||
|
||||
$id = $edituser->create_from_contact($contact, $thirdpartywithuser["login"]);
|
||||
if ($id > 0)
|
||||
{
|
||||
if ($id > 0) {
|
||||
$edituser->setPassword($fuser, trim($thirdpartywithuser['password']));
|
||||
|
||||
if ($thirdpartywithuser['group_id'] > 0)
|
||||
if ($thirdpartywithuser['group_id'] > 0) {
|
||||
$edituser->SetInGroup($thirdpartywithuser['group_id'], $conf->entity);
|
||||
}
|
||||
else {
|
||||
}
|
||||
} else {
|
||||
$error++;
|
||||
$errorcode = 'NOT_CREATE'; $errorlabel = 'Object not create : '.$edituser->error;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$error++;
|
||||
$errorcode = 'NOT_CREATE'; $errorlabel = 'Object not create : '.$contact->error;
|
||||
}
|
||||
@ -656,8 +639,7 @@ function createUserFromThirdparty($authentication, $thirdpartywithuser)
|
||||
}
|
||||
}
|
||||
|
||||
if ($error)
|
||||
{
|
||||
if ($error) {
|
||||
$db->rollback();
|
||||
$objectresp = array(
|
||||
'result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel)
|
||||
@ -682,7 +664,9 @@ function setUserPassword($authentication, $shortuser)
|
||||
|
||||
dol_syslog("Function: setUserPassword login=".$authentication['login']);
|
||||
|
||||
if ($authentication['entity']) $conf->entity = $authentication['entity'];
|
||||
if ($authentication['entity']) {
|
||||
$conf->entity = $authentication['entity'];
|
||||
}
|
||||
|
||||
$objectresp = array();
|
||||
$errorcode = ''; $errorlabel = '';
|
||||
@ -690,50 +674,43 @@ function setUserPassword($authentication, $shortuser)
|
||||
|
||||
$fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
|
||||
|
||||
if ($fuser->socid) $socid = $fuser->socid;
|
||||
if ($fuser->socid) {
|
||||
$socid = $fuser->socid;
|
||||
}
|
||||
|
||||
if (!$error && !$shortuser)
|
||||
{
|
||||
if (!$error && !$shortuser) {
|
||||
$error++;
|
||||
$errorcode = 'BAD_PARAMETERS'; $errorlabel = "Parameter shortuser must be provided.";
|
||||
}
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
if (!$error) {
|
||||
$fuser->getrights();
|
||||
|
||||
if ($fuser->rights->user->user->password || $fuser->rights->user->self->password)
|
||||
{
|
||||
if ($fuser->rights->user->user->password || $fuser->rights->user->self->password) {
|
||||
$userstat = new User($db);
|
||||
$res = $userstat->fetch('', $shortuser['login']);
|
||||
if ($res)
|
||||
{
|
||||
if ($res) {
|
||||
$res = $userstat->setPassword($userstat, $shortuser['password']);
|
||||
if ($res)
|
||||
{
|
||||
if ($res) {
|
||||
$objectresp = array(
|
||||
'result'=>array('result_code' => 'OK', 'result_label' => ''),
|
||||
);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$error++;
|
||||
$errorcode = 'NOT_MODIFIED'; $errorlabel = 'Error when changing password';
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$error++;
|
||||
$errorcode = 'NOT_FOUND'; $errorlabel = 'User not found';
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$error++;
|
||||
$errorcode = 'PERMISSION_DENIED'; $errorlabel = 'User does not have permission for this request';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($error)
|
||||
{
|
||||
if ($error) {
|
||||
$objectresp = array(
|
||||
'result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel)
|
||||
);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user