From 7d51c62d93c37e6a7e82ac4861aa955bb3efc040 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 31 Aug 2019 14:14:24 +0200 Subject: [PATCH] Fix warning when array empty --- htdocs/webservices/server_actioncomm.php | 45 +++++++++----- htdocs/webservices/server_contact.php | 46 ++++++++++----- htdocs/webservices/server_order.php | 59 ++++++++++++------- .../webservices/server_productorservice.php | 53 ++++++++++++----- htdocs/webservices/server_project.php | 37 ++++++++---- htdocs/webservices/server_thirdparty.php | 57 +++++++++++++----- htdocs/webservices/server_user.php | 26 +++++--- 7 files changed, 219 insertions(+), 104 deletions(-) diff --git a/htdocs/webservices/server_actioncomm.php b/htdocs/webservices/server_actioncomm.php index c8211799d02..36423c57a5d 100644 --- a/htdocs/webservices/server_actioncomm.php +++ b/htdocs/webservices/server_actioncomm.php @@ -122,15 +122,17 @@ $extrafield_array=null; if (is_array($extrafields) && count($extrafields)>0) { $extrafield_array = array(); } -foreach($extrafields->attributes[$elementtype]['label'] as $key=>$label) +if (is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) { - $type =$extrafields->attributes[$elementtype]['type'][$key]; - if ($type=='date' || $type=='datetime') {$type='xsd:dateTime';} - else {$type='xsd:string';} + 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';} - $extrafield_array['options_'.$key]=array('name'=>'options_'.$key,'type'=>$type); + $extrafield_array['options_'.$key]=array('name'=>'options_'.$key,'type'=>$type); + } } - if (is_array($extrafield_array)) $actioncomm_fields=array_merge($actioncomm_fields, $extrafield_array); // Define other specific objects @@ -304,6 +306,8 @@ function getActionComm($authentication, $id) 'elementtype'=> $actioncomm->elementtype ); + $elementtype = 'actioncomm'; + // Retreive all extrafield for actioncomm // fetch optionals attributes and labels $extrafields=new ExtraFields($db); @@ -311,9 +315,12 @@ function getActionComm($authentication, $id) //Get extrafield values $actioncomm->fetch_optionals(); - foreach($extrafields->attributes[$elementtype]['label'] as $key=>$label) + if (is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) { - $actioncomm_result_fields=array_merge($actioncomm_result_fields, array('options_'.$key => $actioncomm->array_options['options_'.$key])); + foreach($extrafields->attributes[$elementtype]['label'] as $key=>$label) + { + $actioncomm_result_fields=array_merge($actioncomm_result_fields, array('options_'.$key => $actioncomm->array_options['options_'.$key])); + } } // Create @@ -447,14 +454,19 @@ function createActionComm($authentication, $actioncomm) $newobject->fk_element=$actioncomm['fk_element']; $newobject->elementtype=$actioncomm['elementtype']; + $elementtype = 'actioncomm'; + //Retreive all extrafield for actioncomm // fetch optionals attributes and labels $extrafields=new ExtraFields($db); $extralabels=$extrafields->fetch_name_optionals_label('actioncomm', true); - foreach($extrafields->attributes[$elementtype]['label'] as $key=>$label) + if (is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) { - $key='options_'.$key; - $newobject->array_options[$key]=$actioncomm[$key]; + foreach($extrafields->attributes[$elementtype]['label'] as $key=>$label) + { + $key='options_'.$key; + $newobject->array_options[$key]=$actioncomm[$key]; + } } $db->begin(); @@ -541,14 +553,19 @@ function updateActionComm($authentication, $actioncomm) $object->fk_element=$actioncomm['fk_element']; $object->elementtype=$actioncomm['elementtype']; + $elementtype = 'actioncomm'; + //Retreive all extrafield for actioncomm // fetch optionals attributes and labels $extrafields=new ExtraFields($db); $extralabels=$extrafields->fetch_name_optionals_label('actioncomm', true); - foreach($extrafields->attributes[$elementtype]['label'] as $key=>$label) + if (is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) { - $key='options_'.$key; - $object->array_options[$key]=$actioncomm[$key]; + foreach($extrafields->attributes[$elementtype]['label'] as $key=>$label) + { + $key='options_'.$key; + $object->array_options[$key]=$actioncomm[$key]; + } } $db->begin(); diff --git a/htdocs/webservices/server_contact.php b/htdocs/webservices/server_contact.php index 0abbf02bd50..bced951f58b 100644 --- a/htdocs/webservices/server_contact.php +++ b/htdocs/webservices/server_contact.php @@ -127,15 +127,17 @@ $extrafield_array=null; if (is_array($extrafields) && count($extrafields)>0) { $extrafield_array = array(); } -foreach($extrafields->attributes[$elementtype]['label'] as $key=>$label) +if (is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) { - $type =$extrafields->attributes[$elementtype]['type'][$key]; - if ($type=='date' || $type=='datetime') {$type='xsd:dateTime';} - else {$type='xsd:string';} + 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';} - $extrafield_array['options_'.$key]=array('name'=>'options_'.$key,'type'=>$type); + $extrafield_array['options_'.$key]=array('name'=>'options_'.$key,'type'=>$type); + } } - if (is_array($extrafield_array)) $contact_fields=array_merge($contact_fields, $extrafield_array); // Define other specific objects @@ -308,6 +310,8 @@ function getContact($authentication, $id, $ref_ext) 'poste' => $contact->poste ); + $elementtype = 'socpeople'; + //Retreive all extrafield for thirdsparty // fetch optionals attributes and labels $extrafields=new ExtraFields($db); @@ -315,12 +319,14 @@ function getContact($authentication, $id, $ref_ext) //Get extrafield values $contact->fetch_optionals(); - foreach($extrafields->attributes[$elementtype]['label'] as $key=>$label) + if (is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) { - $contact_result_fields=array_merge($contact_result_fields, array('options_'.$key => $contact->array_options['options_'.$key])); + foreach($extrafields->attributes[$elementtype]['label'] as $key=>$label) + { + $contact_result_fields=array_merge($contact_result_fields, array('options_'.$key => $contact->array_options['options_'.$key])); + } } - // Create $objectresp = array( 'result'=>array('result_code'=>'OK', 'result_label'=>''), @@ -416,18 +422,22 @@ function createContact($authentication, $contact) $newobject->user_login=$contact['user_login']; $newobject->poste=$contact['poste']; + $elementtype = 'socpeople'; + //Retreive all extrafield for thirdsparty // fetch optionals attributes and labels $extrafields=new ExtraFields($db); $extralabels=$extrafields->fetch_name_optionals_label('socpeople', true); - foreach($extrafields->attributes[$elementtype]['label'] as $key=>$label) + if (is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) { - $key='options_'.$key; - $newobject->array_options[$key]=$contact[$key]; + foreach($extrafields->attributes[$elementtype]['label'] as $key=>$label) + { + $key='options_'.$key; + $newobject->array_options[$key]=$contact[$key]; + } } - //... $db->begin(); @@ -662,15 +672,19 @@ function updateContact($authentication, $contact) $object->statut=$contact['status']; + $elementtype = 'socpeople'; //Retreive all extrafield for contact // fetch optionals attributes and labels $extrafields=new ExtraFields($db); $extralabels=$extrafields->fetch_name_optionals_label('socpeople', true); - foreach($extrafields->attributes[$elementtype]['label'] as $key=>$label) + if (is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) { - $key='options_'.$key; - $object->array_options[$key]=$contact[$key]; + foreach($extrafields->attributes[$elementtype]['label'] as $key=>$label) + { + $key='options_'.$key; + $object->array_options[$key]=$contact[$key]; + } } $db->begin(); diff --git a/htdocs/webservices/server_order.php b/htdocs/webservices/server_order.php index ebd1b71b0ed..fd4c40881e0 100644 --- a/htdocs/webservices/server_order.php +++ b/htdocs/webservices/server_order.php @@ -120,13 +120,16 @@ $extrafield_line_array=null; if (is_array($extrafields) && count($extrafields)>0) { $extrafield_line_array = array(); } -foreach($extrafields->attributes[$elementtype]['label'] as $key=>$label) +if (is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['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';} - $extrafield_line_array['options_'.$key]=array('name'=>'options_'.$key,'type'=>$type); + 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';} + $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); @@ -222,13 +225,16 @@ $extrafield_array=null; if (is_array($extrafields) && count($extrafields)>0) { $extrafield_array = array(); } -foreach($extrafields->attributes[$elementtype]['label'] as $key=>$label) +if (is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['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';} - $extrafield_array['options_'.$key]=array('name'=>'options_'.$key,'type'=>$type); + 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';} + $extrafield_array['options_'.$key]=array('name'=>'options_'.$key,'type'=>$type); + } } if (is_array($extrafield_array)) $order_fields=array_merge($order_fields, $extrafield_array); @@ -703,10 +709,13 @@ function createOrder($authentication, $order) // fetch optionals attributes and labels $extrafields=new ExtraFields($db); $extralabels=$extrafields->fetch_name_optionals_label('commande', true); - foreach($extrafields->attributes[$elementtype]['label'] as $key=>$label) + if (is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) { - $key='options_'.$key; - $newobject->array_options[$key]=$order[$key]; + foreach($extrafields->attributes[$elementtype]['label'] as $key=>$label) + { + $key='options_'.$key; + $newobject->array_options[$key]=$order[$key]; + } } // Trick because nusoap does not store data with same structure if there is one or several lines @@ -738,10 +747,13 @@ function createOrder($authentication, $order) // fetch optionals attributes and labels $extrafields=new ExtraFields($db); $extralabels=$extrafields->fetch_name_optionals_label('commandedet', true); - foreach($extrafields->attributes[$elementtype]['label'] as $key=>$label) + if (is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) { - $key='options_'.$key; - $newline->array_options[$key]=$line[$key]; + foreach($extrafields->attributes[$elementtype]['label'] as $key=>$label) + { + $key='options_'.$key; + $newline->array_options[$key]=$line[$key]; + } } $newobject->lines[]=$newline; @@ -946,12 +958,15 @@ function updateOrder($authentication, $order) // fetch optionals attributes and labels $extrafields=new ExtraFields($db); $extralabels=$extrafields->fetch_name_optionals_label('commande', true); - foreach($extrafields->attributes[$elementtype]['label'] as $key=>$label) + if (is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) { - $key='options_'.$key; - if (isset($order[$key])) + foreach($extrafields->attributes[$elementtype]['label'] as $key=>$label) { - $result=$object->setValueFrom($key, $order[$key], 'commande_extrafields'); + $key='options_'.$key; + if (isset($order[$key])) + { + $result=$object->setValueFrom($key, $order[$key], 'commande_extrafields'); + } } } diff --git a/htdocs/webservices/server_productorservice.php b/htdocs/webservices/server_productorservice.php index f3d97c1c76f..bd705e52875 100644 --- a/htdocs/webservices/server_productorservice.php +++ b/htdocs/webservices/server_productorservice.php @@ -142,13 +142,16 @@ $extrafield_array=null; if (is_array($extrafields) && count($extrafields) > 0) { $extrafield_array = array(); } -foreach($extrafields->attributes[$elementtype]['label'] as $key=>$label) +if (is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) { - $type =$extrafields->attributes[$elementtype]['type'][$key]; - if ($type=='date' || $type=='datetime') {$type='xsd:dateTime';} - else {$type='xsd:string';} + 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';} - $extrafield_array['options_'.$key]=array('name'=>'options_'.$key,'type'=>$type); + $extrafield_array['options_'.$key]=array('name'=>'options_'.$key,'type'=>$type); + } } if (is_array($extrafield_array)) $productorservice_fields=array_merge($productorservice_fields, $extrafield_array); @@ -425,6 +428,8 @@ function getProductOrService($authentication, $id = '', $ref = '', $ref_ext = '' 'images' => $product->liste_photos($dir, $nbmax) ); + $elementtype = 'product'; + //Retreive all extrafield for thirdsparty // fetch optionals attributes and labels $extrafields=new ExtraFields($db); @@ -432,9 +437,12 @@ function getProductOrService($authentication, $id = '', $ref = '', $ref_ext = '' //Get extrafield values $product->fetch_optionals(); - foreach($extrafields->attributes[$elementtype]['label'] as $key=>$label) + if (is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) { - $productorservice_result_fields=array_merge($productorservice_result_fields, array('options_'.$key => $product->array_options['options_'.$key])); + foreach($extrafields->attributes[$elementtype]['label'] as $key=>$label) + { + $productorservice_result_fields=array_merge($productorservice_result_fields, array('options_'.$key => $product->array_options['options_'.$key])); + } } // Create @@ -554,12 +562,17 @@ function createProductOrService($authentication, $product) //var_dump($product['ref_ext']); //var_dump($product['lines'][0]['type']); + $elementtype = 'product'; + $extrafields=new ExtraFields($db); $extralabels=$extrafields->fetch_name_optionals_label('product', true); - foreach($extrafields->attributes[$elementtype]['label'] as $key=>$label) + if (is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) { - $key='options_'.$key; - $newobject->array_options[$key]=$product[$key]; + foreach($extrafields->attributes[$elementtype]['label'] as $key=>$label) + { + $key='options_'.$key; + $newobject->array_options[$key]=$product[$key]; + } } $db->begin(); @@ -723,12 +736,17 @@ function updateProductOrService($authentication, $product) //var_dump($product['ref_ext']); //var_dump($product['lines'][0]['type']); + $elementtype = 'product'; + $extrafields=new ExtraFields($db); $extralabels=$extrafields->fetch_name_optionals_label('product', true); - foreach($extrafields->attributes[$elementtype]['label'] as $key=>$label) + if (is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) { - $key='options_'.$key; - $newobject->array_options[$key]=$product[$key]; + foreach($extrafields->attributes[$elementtype]['label'] as $key=>$label) + { + $key='options_'.$key; + $newobject->array_options[$key]=$product[$key]; + } } $db->begin(); @@ -1096,6 +1114,8 @@ function getProductsForCategory($authentication, $id, $lang = '') 'images' => $tmpproduct->liste_photos($dir, $nbmax) ); + $elementtype = 'product'; + //Retreive all extrafield for thirdsparty // fetch optionals attributes and labels $extrafields=new ExtraFields($db); @@ -1103,9 +1123,12 @@ function getProductsForCategory($authentication, $id, $lang = '') //Get extrafield values $tmpproduct->fetch_optionals(); - foreach($extrafields->attributes[$elementtype]['label'] as $key=>$label) + if (is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) { - $products[$iProduct]=array_merge($products[$iProduct], array('options_'.$key => $tmpproduct->array_options['options_'.$key])); + foreach($extrafields->attributes[$elementtype]['label'] as $key=>$label) + { + $products[$iProduct]=array_merge($products[$iProduct], array('options_'.$key => $tmpproduct->array_options['options_'.$key])); + } } $iProduct++; diff --git a/htdocs/webservices/server_project.php b/htdocs/webservices/server_project.php index 063f244a80a..1373e921720 100644 --- a/htdocs/webservices/server_project.php +++ b/htdocs/webservices/server_project.php @@ -169,13 +169,16 @@ $extrafield_array=null; if (is_array($extrafields) && count($extrafields)>0) { $extrafield_array = array(); } -foreach($extrafields->attributes[$elementtype]['label'] as $key=>$label) +if (is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['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';} - $extrafield_array['options_'.$key]=array('name'=>'options_'.$key,'type'=>$type); + 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';} + $extrafield_array['options_'.$key]=array('name'=>'options_'.$key,'type'=>$type); + } } if (is_array($extrafield_array)) $project_fields=array_merge($project_fields, $extrafield_array); @@ -268,14 +271,19 @@ function createProject($authentication, $project) $newobject->budget_amount=$project['budget']; $newobject->description=$project['description']; + $elementtype = 'project'; + // Retrieve all extrafields for project // fetch optionals attributes and labels $extrafields=new ExtraFields($db); $extralabels=$extrafields->fetch_name_optionals_label('project', true); - foreach($extrafields->attributes[$elementtype]['label'] as $key=>$label) + if (is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) { - $key='options_'.$key; - $newobject->array_options[$key]=$project[$key]; + foreach($extrafields->attributes[$elementtype]['label'] as $key=>$label) + { + $key='options_'.$key; + $newobject->array_options[$key]=$project[$key]; + } } $db->begin(); @@ -374,15 +382,20 @@ function getProject($authentication, $id = '', $ref = '') 'description' => $project->description, ); + $elementtype = 'project'; + //Retrieve all extrafields for project $extrafields=new ExtraFields($db); $extralabels=$extrafields->fetch_name_optionals_label('project', true); //Get extrafield values - $project->fetch_optionals(); - foreach($extrafields->attributes[$elementtype]['label'] as $key=>$label) + if (is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) { - $project_result_fields=array_merge($project_result_fields, array('options_'.$key => $project->array_options['options_'.$key])); + $project->fetch_optionals(); + foreach($extrafields->attributes[$elementtype]['label'] as $key=>$label) + { + $project_result_fields=array_merge($project_result_fields, array('options_'.$key => $project->array_options['options_'.$key])); + } } //Get linked elements diff --git a/htdocs/webservices/server_thirdparty.php b/htdocs/webservices/server_thirdparty.php index e897c4cccfc..9815b17fa65 100644 --- a/htdocs/webservices/server_thirdparty.php +++ b/htdocs/webservices/server_thirdparty.php @@ -130,14 +130,17 @@ $extrafield_array=null; if (is_array($extrafields) && count($extrafields)>0) { $extrafield_array = array(); } -foreach($extrafields->attributes[$elementtype]['label'] as $key=>$label) +if (is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['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';} + 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';} - $extrafield_array['options_'.$key]=array('name'=>'options_'.$key,'type'=>$type); + $extrafield_array['options_'.$key]=array('name'=>'options_'.$key,'type'=>$type); + } } if (is_array($extrafield_array)) $thirdparty_fields=array_merge($thirdparty_fields, $extrafield_array); @@ -354,6 +357,8 @@ function getThirdParty($authentication, $id = '', $ref = '', $ref_ext = '') 'note_private' => $thirdparty->note_private, 'note_public' => $thirdparty->note_public); + $elementtype = 'societe'; + // Retrieve all extrafields for thirdsparty // fetch optionals attributes and labels $extrafields=new ExtraFields($db); @@ -361,9 +366,12 @@ function getThirdParty($authentication, $id = '', $ref = '', $ref_ext = '') //Get extrafield values $thirdparty->fetch_optionals(); - foreach($extrafields->attributes[$elementtype]['label'] as $key=>$label) + if (is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) { - $thirdparty_result_fields=array_merge($thirdparty_result_fields, array('options_'.$key => $thirdparty->array_options['options_'.$key])); + foreach($extrafields->attributes[$elementtype]['label'] as $key=>$label) + { + $thirdparty_result_fields=array_merge($thirdparty_result_fields, array('options_'.$key => $thirdparty->array_options['options_'.$key])); + } } // Create @@ -470,14 +478,19 @@ function createThirdParty($authentication, $thirdparty) $newobject->canvas=$thirdparty['canvas']; $newobject->particulier=$thirdparty['individual']; + $elementtype = 'societe'; + // Retrieve all extrafields for thirdsparty // fetch optionals attributes and labels $extrafields=new ExtraFields($db); $extralabels=$extrafields->fetch_name_optionals_label('societe', true); - foreach($extrafields->attributes[$elementtype]['label'] as $key=>$label) + if (is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) { - $key='options_'.$key; - $newobject->array_options[$key]=$thirdparty[$key]; + foreach($extrafields->attributes[$elementtype]['label'] as $key=>$label) + { + $key='options_'.$key; + $newobject->array_options[$key]=$thirdparty[$key]; + } } $db->begin(); @@ -601,14 +614,19 @@ function updateThirdParty($authentication, $thirdparty) $object->canvas=$thirdparty['canvas']; + $elementtype = 'societe'; + // Retrieve all extrafields for thirdsparty // fetch optionals attributes and labels $extrafields=new ExtraFields($db); $extralabels=$extrafields->fetch_name_optionals_label('societe', true); - foreach($extrafields->attributes[$elementtype]['label'] as $key=>$label) + if (is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) { - $key='options_'.$key; - $object->array_options[$key]=$thirdparty[$key]; + foreach($extrafields->attributes[$elementtype]['label'] as $key=>$label) + { + $key='options_'.$key; + $object->array_options[$key]=$thirdparty[$key]; + } } $db->begin(); @@ -693,6 +711,8 @@ function getListOfThirdParties($authentication, $filterthirdparty) } dol_syslog("Function: getListOfThirdParties", LOG_DEBUG); + $elementtype = 'societe'; + $extrafields=new ExtraFields($db); $extralabels=$extrafields->fetch_name_optionals_label('societe', true); @@ -707,10 +727,15 @@ function getListOfThirdParties($authentication, $filterthirdparty) { $extrafieldsOptions=array(); $obj=$db->fetch_object($resql); - foreach($extrafields->attributes[$elementtype]['label'] as $key=>$label) + + if (is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) { - $extrafieldsOptions['options_'.$key] = $obj->{$key}; + foreach($extrafields->attributes[$elementtype]['label'] as $key=>$label) + { + $extrafieldsOptions['options_'.$key] = $obj->{$key}; + } } + $arraythirdparties[]=array('id'=>$obj->socRowid, 'ref'=>$obj->ref, 'ref_ext'=>$obj->ref_ext, diff --git a/htdocs/webservices/server_user.php b/htdocs/webservices/server_user.php index 8de37788010..5864ff01586 100644 --- a/htdocs/webservices/server_user.php +++ b/htdocs/webservices/server_user.php @@ -193,13 +193,16 @@ $extrafield_array=null; if (is_array($extrafields) && count($extrafields)>0) { $extrafield_array = array(); } -foreach($extrafields->attributes[$elementtype]['label'] as $key=>$label) +if (is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) { - $type =$extrafields->attributes[$elementtype]['type'][$key]; - if ($type=='date' || $type=='datetime') {$type='xsd:dateTime';} - else {$type='xsd:string';} + 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';} - $extrafield_array['contact_options_'.$key]=array('name'=>'contact_options_'.$key,'type'=>$type); + $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); @@ -596,15 +599,20 @@ function createUserFromThirdparty($authentication, $thirdpartywithuser) $contact->country_id = $thirdparty->country_id; $contact->country_code = $thirdparty->country_code; + $elementtype = 'socpeople'; + //Retreive all extrafield for thirdsparty // fetch optionals attributes and labels $extrafields=new ExtraFields($db); $extralabels=$extrafields->fetch_name_optionals_label('socpeople', true); - foreach($extrafields->attributes[$elementtype]['label'] as $key=>$label) + if (is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) { - $key='contact_options_'.$key; - $key=substr($key, 8); // Remove 'contact_' prefix - $contact->array_options[$key]=$thirdpartywithuser[$key]; + 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]; + } } $contact_id = $contact->create($fuser);