/** * Return a string with full address formated * * @param Translate $outputlangs Output langs object * @param Societe $sourcecompany Source company object * @param Societe $targetcompany Target company object * @param Contact $targetcontact Target contact object * @param int $usecontact Use contact instead of company * @param int $mode Address type ('source', 'target', 'targetwithdetails') * @return string String with full address */ function pdf_build_address($outputlangs, $sourcecompany, $targetcompany = '', $targetcontact = '', $usecontact = 0, $mode = 'source') { global $conf; $stringaddress = ''; if ($mode == 'source' && !is_object($sourcecompany)) { return -1; } if ($mode == 'target' && !is_object($targetcompany)) { return -1; } if (!empty($sourcecompany->state_id) && empty($sourcecompany->departement)) { $sourcecompany->departement = getState($sourcecompany->state_id); } //TODO: Deprecated if (!empty($sourcecompany->state_id) && empty($sourcecompany->state)) { $sourcecompany->state = getState($sourcecompany->state_id); } if (!empty($targetcompany->state_id) && empty($targetcompany->departement)) { $targetcompany->departement = getState($targetcompany->state_id); } if ($mode == 'source') { $withCountry = 0; if (!empty($sourcecompany->country_code) && $targetcompany->country_code != $sourcecompany->country_code) { $withCountry = 1; } $stringaddress .= ($stringaddress ? "\n" : '') . $outputlangs->convToOutputCharset(dol_format_address($sourcecompany, $withCountry, "\n", $outputlangs)) . "\n"; if (empty($conf->global->MAIN_PDF_DISABLESOURCEDETAILS)) { // Phone if ($sourcecompany->phone) { $stringaddress .= ($stringaddress ? "\n" : '') . $outputlangs->transnoentities("PhoneShort") . ": " . $outputlangs->convToOutputCharset($sourcecompany->phone); } // Fax if ($sourcecompany->fax) { $stringaddress .= ($stringaddress ? $sourcecompany->phone ? " - " : "\n" : '') . $outputlangs->transnoentities("Fax") . ": " . $outputlangs->convToOutputCharset($sourcecompany->fax); } // EMail if ($sourcecompany->email) { $stringaddress .= ($stringaddress ? "\n" : '') . $outputlangs->transnoentities("Email") . ": " . $outputlangs->convToOutputCharset($sourcecompany->email); } // Web if ($sourcecompany->url) { $stringaddress .= ($stringaddress ? "\n" : '') . $outputlangs->transnoentities("Web") . ": " . $outputlangs->convToOutputCharset($sourcecompany->url); } } } if ($mode == 'target' || $mode == 'targetwithdetails') { if ($usecontact) { $stringaddress .= ($stringaddress ? "\n" : '') . $outputlangs->convToOutputCharset($targetcontact->getFullName($outputlangs, 1)); if (!empty($targetcontact->address)) { $stringaddress .= ($stringaddress ? "\n" : '') . $outputlangs->convToOutputCharset(dol_format_address($targetcontact)) . "\n"; } else { $stringaddress .= ($stringaddress ? "\n" : '') . $outputlangs->convToOutputCharset(dol_format_address($targetcompany)) . "\n"; } // Country if (!empty($targetcontact->country_code) && $targetcontact->country_code != $sourcecompany->country_code) { $stringaddress .= $outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv("Country" . $targetcontact->country_code)) . "\n"; } else { if (empty($targetcontact->country_code) && !empty($targetcompany->country_code) && $targetcompany->country_code != $sourcecompany->country_code) { $stringaddress .= $outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv("Country" . $targetcompany->country_code)) . "\n"; } } if (!empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || $mode == 'targetwithdetails') { // Phone if (!empty($targetcontact->phone_pro) || !empty($targetcontact->phone_mobile)) { $stringaddress .= ($stringaddress ? "\n" : '') . $outputlangs->transnoentities("Phone") . ": "; } if (!empty($targetcontact->phone_pro)) { $stringaddress .= $outputlangs->convToOutputCharset($targetcontact->phone_pro); } if (!empty($targetcontact->phone_pro) && !empty($targetcontact->phone_mobile)) { $stringaddress .= " / "; } if (!empty($targetcontact->phone_mobile)) { $stringaddress .= $outputlangs->convToOutputCharset($targetcontact->phone_mobile); } // Fax if ($targetcontact->fax) { $stringaddress .= ($stringaddress ? "\n" : '') . $outputlangs->transnoentities("Fax") . ": " . $outputlangs->convToOutputCharset($targetcontact->fax); } // EMail if ($targetcontact->email) { $stringaddress .= ($stringaddress ? "\n" : '') . $outputlangs->transnoentities("Email") . ": " . $outputlangs->convToOutputCharset($targetcontact->email); } // Web if ($targetcontact->url) { $stringaddress .= ($stringaddress ? "\n" : '') . $outputlangs->transnoentities("Web") . ": " . $outputlangs->convToOutputCharset($targetcontact->url); } } } else { $stringaddress .= ($stringaddress ? "\n" : '') . $outputlangs->convToOutputCharset(dol_format_address($targetcompany)) . "\n"; // Country if (!empty($targetcompany->country_code) && $targetcompany->country_code != $sourcecompany->country_code) { $stringaddress .= $outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv("Country" . $targetcompany->country_code)) . "\n"; } if (!empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || $mode == 'targetwithdetails') { // Phone if (!empty($targetcompany->phone) || !empty($targetcompany->phone_mobile)) { $stringaddress .= ($stringaddress ? "\n" : '') . $outputlangs->transnoentities("Phone") . ": "; } if (!empty($targetcompany->phone)) { $stringaddress .= $outputlangs->convToOutputCharset($targetcompany->phone); } if (!empty($targetcompany->phone) && !empty($targetcompany->phone_mobile)) { $stringaddress .= " / "; } if (!empty($targetcompany->phone_mobile)) { $stringaddress .= $outputlangs->convToOutputCharset($targetcompany->phone_mobile); } // Fax if ($targetcompany->fax) { $stringaddress .= ($stringaddress ? "\n" : '') . $outputlangs->transnoentities("Fax") . ": " . $outputlangs->convToOutputCharset($targetcompany->fax); } // EMail if ($targetcompany->email) { $stringaddress .= ($stringaddress ? "\n" : '') . $outputlangs->transnoentities("Email") . ": " . $outputlangs->convToOutputCharset($targetcompany->email); } // Web if ($targetcompany->url) { $stringaddress .= ($stringaddress ? "\n" : '') . $outputlangs->transnoentities("Web") . ": " . $outputlangs->convToOutputCharset($targetcompany->url); } } } // Intra VAT if (empty($conf->global->MAIN_TVAINTRA_NOT_IN_ADDRESS)) { if ($targetcompany->tva_intra) { $stringaddress .= "\n" . $outputlangs->transnoentities("VATIntraShort") . ': ' . $outputlangs->convToOutputCharset($targetcompany->tva_intra); } } // Professionnal Ids if (!empty($conf->global->MAIN_PROFID1_IN_ADDRESS) && !empty($targetcompany->idprof1)) { $tmp = $outputlangs->transcountrynoentities("ProfId1", $targetcompany->country_code); if (preg_match('/\\((.+)\\)/', $tmp, $reg)) { $tmp = $reg[1]; } $stringaddress .= "\n" . $tmp . ': ' . $outputlangs->convToOutputCharset($targetcompany->idprof1); } if (!empty($conf->global->MAIN_PROFID2_IN_ADDRESS) && !empty($targetcompany->idprof2)) { $tmp = $outputlangs->transcountrynoentities("ProfId2", $targetcompany->country_code); if (preg_match('/\\((.+)\\)/', $tmp, $reg)) { $tmp = $reg[1]; } $stringaddress .= "\n" . $tmp . ': ' . $outputlangs->convToOutputCharset($targetcompany->idprof2); } if (!empty($conf->global->MAIN_PROFID3_IN_ADDRESS) && !empty($targetcompany->idprof3)) { $tmp = $outputlangs->transcountrynoentities("ProfId3", $targetcompany->country_code); if (preg_match('/\\((.+)\\)/', $tmp, $reg)) { $tmp = $reg[1]; } $stringaddress .= "\n" . $tmp . ': ' . $outputlangs->convToOutputCharset($targetcompany->idprof3); } if (!empty($conf->global->MAIN_PROFID4_IN_ADDRESS) && !empty($targetcompany->idprof4)) { $tmp = $outputlangs->transcountrynoentities("ProfId4", $targetcompany->country_code); if (preg_match('/\\((.+)\\)/', $tmp, $reg)) { $tmp = $reg[1]; } $stringaddress .= "\n" . $tmp . ': ' . $outputlangs->convToOutputCharset($targetcompany->idprof4); } } return $stringaddress; }
/** * Return name of contact with link (and eventually picto) * Use $this->id, $this->lastname, $this->firstname, this->civility_id * * @param int $withpicto Include picto with link * @param string $option Where the link point to * @param int $maxlen Max length of * @param string $moreparam Add more param into URL * @return string String with URL */ function getNomUrl($withpicto = 0, $option = '', $maxlen = 0, $moreparam = '') { global $conf, $langs; $result = ''; $label = '<u>' . $langs->trans("ShowContact") . '</u>'; $label .= '<br><b>' . $langs->trans("Name") . ':</b> ' . $this->getFullName($langs); //if ($this->civility_id) $label.= '<br><b>' . $langs->trans("Civility") . ':</b> '.$this->civility_id; // TODO Translate cibilty_id code if (!empty($this->poste)) { $label .= '<br><b>' . $langs->trans("Poste") . ':</b> ' . $this->poste; } if (!empty($this->email)) { $label .= '<br><b>' . $langs->trans("EMail") . ':</b> ' . $this->email; } $phonelist = array(); if ($this->phone_pro) { $phonelist[] = $this->phone_pro; } if ($this->phone_mobile) { $phonelist[] = $this->phone_mobile; } if ($this->phone_perso) { $phonelist[] = $this->phone_perso; } $label .= '<br><b>' . $langs->trans("Phone") . ':</b> ' . join(', ', $phonelist); $label .= '<br><b>' . $langs->trans("Address") . ':</b> ' . dol_format_address($this, 1, ' ', $langs); $link = '<a href="' . DOL_URL_ROOT . '/contact/card.php?id=' . $this->id . $moreparam . '"'; if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) { $label = $langs->trans("ShowContact"); $link .= ' alt="' . dol_escape_htmltag($label, 1) . '"'; } $link .= ' title="' . dol_escape_htmltag($label, 1) . '"'; $link .= ' class="classfortooltip">'; $linkend = '</a>'; if ($option == 'xxx') { $link = '<a href="' . DOL_URL_ROOT . '/contact/card.php?id=' . $this->id . $moreparam . '" title="' . dol_escape_htmltag($label, 1) . '" class="classfortooltip">'; $linkend = '</a>'; } if ($withpicto) { $result .= $link . img_object($label, 'contact', 'class="classfortooltip"') . $linkend . ' '; } $result .= $link . ($maxlen ? dol_trunc($this->getFullName($langs), $maxlen) : $this->getFullName($langs)) . $linkend; return $result; }
</head> <body> <div class="entete"> <div class="logo"><?php print '<img src="' . DOL_URL_ROOT . '/viewimage.php?modulepart=companylogo&file=' . urlencode('/thumbs/' . $mysoc->logo_small) . '">'; ?> </div> <div class="infos"> <p class="address"><?php echo $mysoc->name; ?> <br> <?php print dol_nl2br(dol_format_address($mysoc)); ?> <br> </p> <p class="date_heure"><?php // Recuperation et affichage de la date et de l'heure $now = dol_now(); print dol_print_date($now, 'dayhourtext') . '<br>'; print $object->ref; ?> </p> </div> </div> <br>
/** * Return full address of contact * * @param int $withcountry 1=Add country into address string * @param string $sep Separator to use to build string * @return string Full address string */ function getFullAddress($withcountry = 0, $sep = "\n") { if ($withcountry && $this->country_id && (empty($this->country_code) || empty($this->country))) { require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php'; $tmparray = getCountry($this->country_id, 'all'); $this->country_code = $tmparray['code']; $this->country = $tmparray['label']; } return dol_format_address($this, $withcountry, $sep); }
/** * testDolFormatAddress * * @return void */ public function testDolFormatAddress() { global $conf, $user, $langs, $db; $conf = $this->savconf; $user = $this->savuser; $langs = $this->savlangs; $db = $this->savdb; $object = new Societe($db); $object->initAsSpecimen(); $object->country_code = 'FR'; $address = dol_format_address($object); $this->assertEquals("21 jump street\n99999 MyTown", $address); $object->country_code = 'GB'; $address = dol_format_address($object); $this->assertEquals("21 jump street\nMyTown, MyState\n99999", $address); $object->country_code = 'US'; $address = dol_format_address($object); $this->assertEquals("21 jump street\nMyTown, MyState, 99999", $address); $object->country_code = 'AU'; $address = dol_format_address($object); $this->assertEquals("21 jump street\nMyTown, MyState, 99999", $address); }