diff --git a/htdocs/core/class/commondocgenerator.class.php b/htdocs/core/class/commondocgenerator.class.php index 1b290222a11..702c2d93014 100644 --- a/htdocs/core/class/commondocgenerator.class.php +++ b/htdocs/core/class/commondocgenerator.class.php @@ -195,12 +195,86 @@ abstract class CommonDocGenerator { $object->array_options['options_'.$key] = $extrafields->attribute_param[$key]['options'][$object->array_options['options_'.$key]]; } - $array_thirdparty=array_merge($array_thirdparty,array('company_options_'.$key => $object->array_options['options_'.$key])); - } - } - return $array_thirdparty; - } - + $array_thirdparty = array_merge ( $array_thirdparty, array ( + 'company_options_' . $key => $object->array_options ['options_' . $key] + ) ); + } + } + return $array_thirdparty; + } + + /** + * Define array with couple subtitution key => subtitution value + * + * @param Object $object contact + * @param Translate $outputlangs object for output + * @param array_key $array_key Name of the key for return array + * @return array of substitution key->code + */ + function get_substitutionarray_contact($object, $outputlangs, $array_key = 'object') { + global $conf; + + if(empty($object->country) && ! empty($object->country_code)) + { + $object->country = $outputlangs->transnoentitiesnoconv("Country" . $object->country_code); + } + if(empty($object->state) && ! empty($object->state_code)) + { + $object->state = getState($object->state_code, 0); + } + + $array_contact = array ( + $array_key . '_fullname' => $object->getFullName($outputlangs, 1), + $array_key . '_lastname' => $object->lastname, + $array_key . '_firstname' => $object->firstname, + $array_key . '_address' => $object->address, + $array_key . '_zip' => $object->zip, + $array_key . '_town' => $object->town, + $array_key . '_state_id' => $object->state_id, + $array_key . '_state_code' => $object->state_code, + $array_key . '_state' => $object->state, + $array_key . '_country_id' => $object->country_id, + $array_key . '_country_code' => $object->country_code, + $array_key . '_country' => $object->country, + $array_key . '_poste' => $object->poste, + $array_key . '_socid' => $object->socid, + $array_key . '_statut' => $object->statut, + $array_key . '_code' => $object->code, + $array_key . '_email' => $object->email, + $array_key . '_jabberid' => $object->jabberid, + $array_key . '_phone_pro' => $object->phone_pro, + $array_key . '_phone_perso' => $object->phone_perso, + $array_key . '_phone_mobile' => $object->phone_mobile, + $array_key . '_fax' => $object->fax, + $array_key . '_birthday' => $object->birthday, + $array_key . '_default_lang' => $object->default_lang, + $array_key . '_note_public' => $object->note_public, + $array_key . '_note_private' => $object->note_private + ); + + // Retrieve extrafields + if (is_array($object->array_options) && count($object->array_options)) { + require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php'; + $extrafields = new ExtraFields($this->db); + $extralabels = $extrafields->fetch_name_optionals_label('contact', true); + $object->fetch_optionals($object->id, $extralabels); + + foreach($extrafields->attribute_label as $key => $label) + { + if ($extrafields->attribute_type[$key] == 'price') + { + $object->array_options['options_' . $key] = price($object->array_options ['options_' . $key], 0, $outputlangs, 0, 0, - 1, $conf->currency); + } + elseif($extrafields->attribute_type[$key] == 'select') + { + $object->array_options['options_' . $key] = $extrafields->attribute_param[$key]['options'][$object->array_options['options_' . $key]]; + } + $array_contact = array_merge($array_contact, array('contact_options_' . $key => $object->array_options['options_'. $key])); + } + } + return $array_contact; + } + /** * Define array with couple subtitution key => subtitution value diff --git a/htdocs/core/modules/societe/doc/doc_generic_odt.modules.php b/htdocs/core/modules/societe/doc/doc_generic_odt.modules.php index 563444a51a3..75b54ba285e 100644 --- a/htdocs/core/modules/societe/doc/doc_generic_odt.modules.php +++ b/htdocs/core/modules/societe/doc/doc_generic_odt.modules.php @@ -293,9 +293,69 @@ class doc_generic_odt extends ModeleThirdPartyDoc // setVars failed, probably because key not found } } - // Make substitutions into odt of thirdparty + external modules - $tmparray=$this->get_substitutionarray_thirdparty($object,$outputlangs); - complete_substitutions_array($tmparray, $outputlangs, $object); + + + // Replace tags of lines for contacts + $contact_arrray=array(); + + $sql = "SELECT p.rowid"; + $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as p"; + $sql .= " WHERE p.fk_soc = ".$object->id; + + dol_syslog('doc_generic_odt :: sql='.$sql,LOG_DEBUG); + $result = $this->db->query($sql); + $num = $this->db->num_rows($result); + + $var=true; + if ($num) + { + $i=0; + $contactstatic = new Contact($this->db); + + while($i < $num) + { + $obj = $this->db->fetch_object($result); + + $contact_arrray[$i] = $obj->rowid; + $i++; + } + } + if((is_array($contact_arrray) && count($contact_arrray) > 0)) + { + try + { + $listlines = $odfHandler->setSegment('companycontacts'); + + foreach($contact_arrray as $array_key => $contact_id) + { + $res_contact = $contactstatic->fetch($contact_id); + //$contact['fullname']=$objectdetail->getFullName($outputlangs,1); + $tmparray=$this->get_substitutionarray_contact($contactstatic,$outputlangs,'contact'); + foreach($tmparray as $key => $val) + { + try + { + $listlines->setVars($key, $val, true, 'UTF-8'); + } + catch(OdfException $e) + { + } + catch(SegmentException $e) + { + } + } + $listlines->merge(); + } + $odfHandler->mergeSegment($listlines); + } + catch(OdfException $e) + { + $this->error=$e->getMessage(); + dol_syslog($this->error, LOG_WARNING); + //return -1; + } + } + // Call the ODTSubstitution hook $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray); $reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks @@ -330,8 +390,13 @@ class doc_generic_odt extends ModeleThirdPartyDoc { } } + + + // Make substitutions into odt of thirdparty + external modules + $tmparray=$this->get_substitutionarray_thirdparty($object,$outputlangs); + complete_substitutions_array($tmparray, $outputlangs, $object); - // Call the beforeODTSave hook + // Call the beforeODTSave hook $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs); $reshook=$hookmanager->executeHooks('beforeODTSave',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks