NEW #37727 phone input with country code (#37728)

* New phone input with country code

* CI fixes

* Assure AJAX CSRF check

* Fix SQL migration typo

* Remove unnecessary CSRFCHECK_WITH_TOKEN in getphonecode.php AJAX endpoint
This commit is contained in:
Florian Charlaix 2026-04-21 16:15:38 +02:00 committed by GitHub
parent 906ec585ee
commit 029a1fbc1b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 1191 additions and 26 deletions

View file

@ -12,7 +12,7 @@
* Copyright (C) 2015 Ferran Marcet <fmarcet@2byte.es>
* Copyright (C) 2016 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
* Copyright (C) 2019-2026 Frédéric France <frederic.france@free.fr>
* Copyright (C) 2020-2022 Open-Dsi <support@open-dsi.fr>
* Copyright (C) 2020-2026 Open-Dsi <support@open-dsi.fr>
* Copyright (C) 2024-2025 Charlene Benke <charlene@patas-monkey.com>
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
*
@ -270,7 +270,7 @@ $tabsql = array();
$tabsql[DICT_FORME_JURIDIQUE] = "SELECT f.rowid as rowid, f.code, f.libelle, c.code as country_code, c.label as country, f.active FROM ".MAIN_DB_PREFIX."c_forme_juridique as f, ".MAIN_DB_PREFIX."c_country as c WHERE f.fk_pays=c.rowid";
$tabsql[DICT_DEPARTEMENTS] = "SELECT d.rowid as rowid, d.code_departement as code, d.nom as libelle, d.fk_region as region_id, r.nom as region, c.code as country_code, c.label as country, d.active FROM ".MAIN_DB_PREFIX."c_departements as d, ".MAIN_DB_PREFIX."c_regions as r, ".MAIN_DB_PREFIX."c_country as c WHERE d.fk_region=r.code_region and r.fk_pays=c.rowid and r.active=1 and c.active=1";
$tabsql[DICT_REGIONS] = "SELECT r.rowid as rowid, r.code_region as code, r.nom as libelle, r.fk_pays as country_id, c.code as country_code, c.label as country, r.active FROM ".MAIN_DB_PREFIX."c_regions as r, ".MAIN_DB_PREFIX."c_country as c WHERE r.fk_pays=c.rowid and c.active=1";
$tabsql[DICT_COUNTRY] = "SELECT c.rowid as rowid, c.code, c.label, c.active, c.favorite, c.eec, c.sepa FROM ".MAIN_DB_PREFIX."c_country AS c";
$tabsql[DICT_COUNTRY] = "SELECT c.rowid as rowid, c.code, c.label, c.phone_code, c.trunk_prefix, c.active, c.favorite, c.eec, c.sepa FROM ".MAIN_DB_PREFIX."c_country AS c";
$tabsql[DICT_CIVILITY] = "SELECT c.rowid as rowid, c.code as code, c.label, c.active FROM ".MAIN_DB_PREFIX."c_civility AS c";
$tabsql[DICT_ACTIONCOMM] = "SELECT a.id as rowid, a.code as code, a.libelle AS libelle, a.type, a.active, a.module, a.color, a.position FROM ".MAIN_DB_PREFIX."c_actioncomm AS a";
$tabsql[DICT_CHARGESOCIALES] = "SELECT a.id as rowid, a.code as code, a.libelle AS libelle, a.accountancy_code as accountancy_code, c.code as country_code, c.label as country, a.fk_pays as country_id, a.active FROM ".MAIN_DB_PREFIX."c_chargesociales AS a, ".MAIN_DB_PREFIX."c_country as c WHERE a.fk_pays = c.rowid and c.active = 1";
@ -364,7 +364,7 @@ $tabfield = array();
$tabfield[DICT_FORME_JURIDIQUE] = "code,libelle,country";
$tabfield[DICT_DEPARTEMENTS] = "code,libelle,region_id,region,country"; // "code,libelle,region,country_code-country"
$tabfield[DICT_REGIONS] = "code,libelle,country_id,country";
$tabfield[DICT_COUNTRY] = "code,label";
$tabfield[DICT_COUNTRY] = "code,label,phone_code,trunk_prefix";
$tabfield[DICT_CIVILITY] = "code,label";
$tabfield[DICT_ACTIONCOMM] = "code,libelle,type,color,position";
$tabfield[DICT_CHARGESOCIALES] = "code,libelle,country,accountancy_code";
@ -411,7 +411,7 @@ $tabfieldvalue = array();
$tabfieldvalue[DICT_FORME_JURIDIQUE] = "code,libelle,country";
$tabfieldvalue[DICT_DEPARTEMENTS] = "code,libelle,region"; // "code,libelle,region"
$tabfieldvalue[DICT_REGIONS] = "code,libelle,country";
$tabfieldvalue[DICT_COUNTRY] = "code,label";
$tabfieldvalue[DICT_COUNTRY] = "code,label,phone_code,trunk_prefix";
$tabfieldvalue[DICT_CIVILITY] = "code,label";
$tabfieldvalue[DICT_ACTIONCOMM] = "code,libelle,type,color,position";
$tabfieldvalue[DICT_CHARGESOCIALES] = "code,libelle,country,accountancy_code";
@ -458,7 +458,7 @@ $tabfieldinsert = array();
$tabfieldinsert[DICT_FORME_JURIDIQUE] = "code,libelle,fk_pays";
$tabfieldinsert[DICT_DEPARTEMENTS] = "code_departement,nom,fk_region";
$tabfieldinsert[DICT_REGIONS] = "code_region,nom,fk_pays";
$tabfieldinsert[DICT_COUNTRY] = "code,label";
$tabfieldinsert[DICT_COUNTRY] = "code,label,phone_code,trunk_prefix";
$tabfieldinsert[DICT_CIVILITY] = "code,label";
$tabfieldinsert[DICT_ACTIONCOMM] = "code,libelle,type,color,position";
$tabfieldinsert[DICT_CHARGESOCIALES] = "code,libelle,fk_pays,accountancy_code";
@ -613,7 +613,7 @@ $tabcomplete = array(
'picto' => 'region',
'help' => array('code' => $langs->trans("EnterAnyCode"))
),
'c_country' => array('picto' => 'country', 'help' => array('code' => $langs->trans("EnterAnyCode"))),
'c_country' => array('picto' => 'country', 'help' => array('code' => $langs->trans("EnterAnyCode"), 'phone_code' => 'e.g. 33', 'trunk_prefix' => 'e.g. 0')),
'c_civility' => array('picto' => 'contact', 'help' => array('code' => $langs->trans("EnterAnyCode"))),
'c_actioncomm' => array('picto' => 'action', 'help' => array('code' => $langs->trans("EnterAnyCode"), 'color' => $langs->trans("ColorFormat"), 'position' => $langs->trans("PositionIntoComboList"))),
'c_chargesociales' => array('picto' => 'bill', 'help' => array('code' => $langs->trans("EnterAnyCode"))),
@ -2117,6 +2117,12 @@ if ($id > 0) {
if ($value == 'country') {
$valuetoshow = $langs->trans("Country");
}
if ($value == 'phone_code') {
$valuetoshow = $langs->trans("PhoneCode");
}
if ($value == 'trunk_prefix') {
$valuetoshow = $langs->trans("TrunkPrefix");
}
if ($value == 'department_buyer') {
$valuetoshow = $langs->trans('DepartmentBuyer');
}
@ -2434,7 +2440,7 @@ if ($id > 0) {
//var_dump($fieldlist);
$class = '';
$showfield = 1;
$valuetoshow = empty($obj->$value) ? '' : $obj->$value;
$valuetoshow = (isset($obj->$value) && $obj->$value !== null && $obj->$value !== '') ? $obj->$value : '';
$titletoshow = '';
if ($value == 'entity') {

View file

@ -10,7 +10,7 @@
* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
* Copyright (C) 2018-2025 Frédéric France <frederic.france@free.fr>
* Copyright (C) 2019 Josep Lluís Amador <joseplluis@lliuretic.cat>
* Copyright (C) 2020 Open-Dsi <support@open-dsi.fr>
* Copyright (C) 2020-2026 Open-Dsi <support@open-dsi.fr>
* Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
*
* This program is free software; you can redistribute it and/or modify
@ -793,28 +793,30 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) {
// Phone / Fax
print '<tr><td>'.$form->editfieldkey('PhonePro', 'phone_pro', '', $object, 0).'</td>';
print '<td>';
print img_picto('', 'object_phoning', 'class="pictofixedwidth"');
print '<input type="text" name="phone_pro" id="phone_pro" class="maxwidth250 widthcentpercentminusx" value="'.(GETPOSTISSET('phone_pro') ? GETPOST('phone_pro', 'alpha') : $object->phone_pro).'"></td>';
print $form->showPhoneInput($object->phone_pro, 'phone_pro', $object->country_id, 'object_phoning', 'maxwidth150 widthcentpercentminusx');
print '</td>';
if ($conf->browser->layout == 'phone') {
print '</tr><tr>';
}
print '<td>'.$form->editfieldkey('PhonePerso', 'phone_perso', '', $object, 0).'</td>';
print '<td>';
print img_picto('', 'object_phoning', 'class="pictofixedwidth"');
print '<input type="text" name="phone_perso" id="phone_perso" class="maxwidth200 widthcentpercentminusx" value="'.(GETPOSTISSET('phone_perso') ? GETPOST('phone_perso', 'alpha') : $object->phone_perso).'"></td>';
print $form->showPhoneInput($object->phone_perso, 'phone_perso', $object->country_id, 'object_phoning', 'maxwidth150 widthcentpercentminusx');
print '</td>';
print '</tr>';
print '<tr><td>'.$form->editfieldkey('PhoneMobile', 'phone_mobile', '', $object, 0).'</td>';
print '<td>';
print img_picto('', 'object_phoning_mobile', 'class="pictofixedwidth"');
print '<input type="text" name="phone_mobile" id="phone_mobile" class="maxwidth200 widthcentpercentminusx" value="'.(GETPOSTISSET('phone_mobile') ? GETPOST('phone_mobile', 'alpha') : $object->phone_mobile).'"></td>';
print $form->showPhoneInput($object->phone_mobile, 'phone_mobile', $object->country_id, 'object_phoning_mobile', 'maxwidth150 widthcentpercentminusx');
print '</td>';
if ($conf->browser->layout == 'phone') {
print '</tr><tr>';
}
print '<td>'.$form->editfieldkey('Fax', 'fax', '', $object, 0).'</td>';
print '<td>';
print img_picto('', 'object_phoning_fax', 'class="pictofixedwidth"');
print '<input type="text" name="fax" id="fax" class="maxwidth200 widthcentpercentminusx" value="'.(GETPOSTISSET('fax') ? GETPOST('fax', 'alpha') : $object->fax).'"></td>';
print $form->showPhoneInput($object->fax, 'fax', $object->country_id, 'object_phoning_fax', 'maxwidth150 widthcentpercentminusx');
print '</td>';
print '</tr>';
if (((isset($objsoc->typent_code) && $objsoc->typent_code == 'TE_PRIVATE') || getDolGlobalString('CONTACT_USE_COMPANY_ADDRESS')) && dol_strlen(trim($object->email)) == 0) {
@ -1072,27 +1074,29 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) {
// Phone
print '<tr><td>'.$form->editfieldkey('PhonePro', 'phone_pro', GETPOST('phone_pro', 'alpha'), $object, 0).'</td>';
print '<td>';
print img_picto('', 'object_phoning', 'class="pictofixedwidth"');
print '<input type="text" name="phone_pro" id="phone_pro" class="maxwidth200" maxlength="80" value="'.(GETPOSTISSET('phone_pro') ? GETPOST('phone_pro', 'alpha') : $object->phone_pro).'"></td>';
print $form->showPhoneInput($object->phone_pro, 'phone_pro', $object->country_id, 'object_phoning', 'maxwidth150', 80);
print '</td>';
if ($conf->browser->layout == 'phone') {
print '</tr><tr>';
}
print '<td>'.$form->editfieldkey('PhonePerso', 'fax', GETPOST('phone_perso', 'alpha'), $object, 0).'</td>';
print '<td>'.$form->editfieldkey('PhonePerso', 'phone_perso', GETPOST('phone_perso', 'alpha'), $object, 0).'</td>';
print '<td>';
print img_picto('', 'object_phoning', 'class="pictofixedwidth"');
print '<input type="text" name="phone_perso" id="phone_perso" class="maxwidth200" maxlength="80" value="'.(GETPOSTISSET('phone_perso') ? GETPOST('phone_perso', 'alpha') : $object->phone_perso).'"></td></tr>';
print $form->showPhoneInput($object->phone_perso, 'phone_perso', $object->country_id, 'object_phoning', 'maxwidth150', 80);
print '</td></tr>';
print '<tr><td>'.$form->editfieldkey('PhoneMobile', 'phone_mobile', GETPOST('phone_mobile', 'alpha'), $object, 0, 'string', '').'</td>';
print '<td>';
print img_picto('', 'object_phoning_mobile', 'class="pictofixedwidth"');
print '<input type="text" name="phone_mobile" id="phone_mobile" class="maxwidth200" maxlength="80" value="'.(GETPOSTISSET('phone_mobile') ? GETPOST('phone_mobile', 'alpha') : $object->phone_mobile).'"></td>';
print $form->showPhoneInput($object->phone_mobile, 'phone_mobile', $object->country_id, 'object_phoning_mobile', 'maxwidth150', 80);
print '</td>';
if ($conf->browser->layout == 'phone') {
print '</tr><tr>';
}
print '<td>'.$form->editfieldkey('Fax', 'fax', GETPOST('fax', 'alpha'), $object, 0).'</td>';
print '<td>';
print img_picto('', 'object_phoning_fax', 'class="pictofixedwidth"');
print '<input type="text" name="fax" id="fax" class="maxwidth200" maxlength="80" value="'.(GETPOSTISSET('phone_fax') ? GETPOST('phone_fax', 'alpha') : $object->fax).'"></td></tr>';
print $form->showPhoneInput($object->fax, 'fax', $object->country_id, 'object_phoning_fax', 'maxwidth150', 80);
print '</td></tr>';
// EMail
print '<tr><td>'.$form->editfieldkey('EMail', 'email', GETPOST('email', 'alpha'), $object, 0, 'string', '', (int) (getDolGlobalInt('SOCIETE_EMAIL_MANDATORY'))).'</td>';

View file

@ -0,0 +1,58 @@
<?php
/* Copyright (C) 2026 Open-Dsi <support@open-dsi.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/core/ajax/getphonecode.php
* \brief Returns JSON phone_code for a given country_id
*/
if (!defined('NOTOKENRENEWAL')) {
define('NOTOKENRENEWAL', '1'); // Disables token renewal
}
if (!defined('NOREQUIREMENU')) {
define('NOREQUIREMENU', '1');
}
if (!defined('NOREQUIREAJAX')) {
define('NOREQUIREAJAX', '1');
}
// Load Dolibarr environment
require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/phone.lib.php';
/**
* @var DoliDB $db
* @var User $user
*/
$country_id = GETPOSTINT('country_id');
// Security check - user must be logged in
if (empty($user->id)) {
http_response_code(403);
echo json_encode(array('error' => 'Not authorized'));
exit;
}
/*
* View
*/
top_httphead('application/json');
$phone_code = dol_get_phone_code_from_country($db, $country_id);
echo json_encode(array('phone_code' => $phone_code));

View file

@ -26,6 +26,7 @@
* Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
* Copyright (C) 2024 William Mead <william.mead@manchenumerique.fr>
* Copyright (C) 2026 Lenin Rivas <lenin.rivas777@gmail.com>
* Copyright (C) 2026 Open-Dsi <support@open-dsi.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -98,6 +99,11 @@ class Form
/** @var array<string,string> */
public $cache_rule_for_lines_dates = array();
/**
* @var bool Whether the shared phone input JS (country-sync) has been emitted
*/
private $phoneInputSharedJsLoaded = false;
/**
* Constructor
@ -1114,6 +1120,285 @@ class Form
return $out;
}
/**
* Return a select list of country phone calling codes
*
* @param string $selected Pre-selected phone code value (e.g. "+33")
* @param string $htmlname Name of HTML select element
* @param string $morecss More CSS classes
* @param int $showempty Show empty option (1) or not (0)
* @param int $country_id_hint Country ID to prefer when multiple countries share a code
* @return string HTML select string
*/
public function selectPhoneCode($selected = '', $htmlname = 'phone_code', $morecss = 'maxwidth150', $showempty = 0, $country_id_hint = 0)
{
global $langs;
$langs->load("dict");
$out = '';
$codeArray = array();
$favorite = array();
$label = array();
$atleastonefavorite = 0;
$sql = "SELECT rowid, code, label, phone_code, favorite, trunk_prefix";
$sql .= " FROM ".$this->db->prefix()."c_country";
$sql .= " WHERE active > 0 AND phone_code IS NOT NULL AND phone_code != ''";
dol_syslog(get_class($this)."::selectPhoneCode", LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql) {
$num = $this->db->num_rows($resql);
$i = 0;
while ($i < $num) {
$obj = $this->db->fetch_object($resql);
$translabel = ($obj->code && $langs->transnoentitiesnoconv("Country".$obj->code) != "Country".$obj->code) ? $langs->transnoentitiesnoconv("Country".$obj->code) : $obj->label;
$codeArray[$i]['rowid'] = $obj->rowid;
$codeArray[$i]['code'] = $obj->code;
$codeArray[$i]['label'] = $translabel;
$codeArray[$i]['phone_code'] = '+'.$obj->phone_code;
$codeArray[$i]['favorite'] = $obj->favorite;
$codeArray[$i]['trunk_prefix'] = $obj->trunk_prefix;
$favorite[$i] = $obj->favorite;
$label[$i] = dol_string_unaccent($translabel);
$i++;
}
$array1_sort_order = SORT_DESC;
$array2_sort_order = SORT_ASC;
array_multisort($favorite, $array1_sort_order, $label, $array2_sort_order, $codeArray);
$out .= '<select id="select'.$htmlname.'" class="flat selectphonecode'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'">';
if ($showempty) {
$out .= '<option value="">&nbsp;</option>'."\n";
}
// Determine which row index to select: prefer country_id_hint match, fallback to first phone_code match
$selectedIdx = -1;
$firstMatchIdx = -1;
if ($selected !== '') {
foreach ($codeArray as $idx => $row) {
if ($row['phone_code'] == $selected) {
if ($firstMatchIdx < 0) {
$firstMatchIdx = $idx;
}
if ($country_id_hint > 0 && $row['rowid'] == $country_id_hint) {
$selectedIdx = $idx;
break;
}
}
}
if ($selectedIdx < 0 && $firstMatchIdx >= 0) {
$selectedIdx = $firstMatchIdx;
}
}
foreach ($codeArray as $idx => $row) {
if (empty($row['code'])) {
continue;
}
if ($row['favorite']) {
$atleastonefavorite++;
}
if (empty($row['favorite']) && $atleastonefavorite) {
$atleastonefavorite = 0;
$out .= '<option value="" disabled class="selectoptiondisabledwhite">------------</option>';
}
$tmpflag = picto_from_langcode($row['code'], 'class="saturatemedium paddingrightonly"', 1);
// Short label for selected display: flag + country code
$selectlabel = ($tmpflag ? $tmpflag.' ' : '').$row['code'];
// Detailed label for dropdown list: flag + country name + phone code
$labeltoshow = ($tmpflag ? $tmpflag.' ' : '').$row['label'].' '.$row['phone_code'];
$out .= '<option value="'.dol_escape_htmltag($row['phone_code']).'"';
if ($idx === $selectedIdx) {
$out .= ' selected';
}
$out .= ' data-html="'.dol_escape_htmltag($labeltoshow).'"';
$out .= ' data-select-html="'.dol_escape_htmltag($selectlabel).'"';
$out .= ' data-country-id="'.((int) $row['rowid']).'"';
$out .= ' data-trunk-prefix="'.dol_escape_htmltag((string) $row['trunk_prefix']).'"';
$out .= '>';
$out .= dol_string_nohtmltag($labeltoshow);
$out .= '</option>'."\n";
}
$out .= '</select>';
} else {
dol_print_error($this->db);
}
// Make select dynamic
include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
$out .= ajax_combobox('select'.$htmlname, array(), 0, 0, 'resolve');
return $out;
}
/**
* Show a self-contained phone input: hidden field + country code dropdown + number text field + JS.
*
* The hidden field (named $htmlname) carries the full phone value (e.g. "+33 644986885")
* and is the only field POSTed. The code select and number input have no name attribute
* (or a display-only name). JS keeps the hidden field in sync.
*
* @param string $phoneValue Stored phone value (e.g. "+33 644986885") or empty
* @param string $htmlname Base name for the input (e.g. "phone_pro")
* @param int $country_id_hint Country ID for default phone code (0 = fallback to company country)
* @param string $picto Picto name (e.g. "object_phoning")
* @param string $morecss Additional CSS for the text input
* @param int $maxlength Max length attribute for the text input
* @param string $countrySelectorId ID of the country select to sync with
* @return string HTML output
*/
public function showPhoneInput($phoneValue, $htmlname, $country_id_hint = 0, $picto = 'object_phoning', $morecss = 'maxwidth150', $maxlength = 0, $countrySelectorId = 'selectcountry_id')
{
global $mysoc;
include_once DOL_DOCUMENT_ROOT.'/core/lib/phone.lib.php';
$codename = $htmlname.'_code';
// Fallback country_id: use caller hint, else main company country
if (empty($country_id_hint) && !empty($mysoc->country_id)) {
$country_id_hint = $mysoc->country_id;
}
// On POST re-display, read the hidden field (which contains the full phone string)
if (GETPOSTISSET($htmlname)) {
$fullPhone = (string) GETPOST($htmlname);
} else {
$fullPhone = (string) $phoneValue;
}
// Split into code + number
$parsed = dol_parse_phone($fullPhone);
// Resolve default phone code: parsed code if set, else from country hint
$phonecode = !empty($parsed['code']) ? $parsed['code'] : dol_get_phone_code_from_country($this->db, $country_id_hint);
$selectedCode = $phonecode;
$numberValue = $parsed['number'];
// Add back trunk prefix for display (e.g. "644986885" → "0644986885" for France)
if ($numberValue !== '' && $selectedCode !== '') {
$trunkPrefix = dol_get_trunk_prefix($this->db, $selectedCode);
if ($trunkPrefix !== '' && strpos($numberValue, $trunkPrefix) !== 0) {
$numberValue = $trunkPrefix.$numberValue;
}
}
// Build output: hidden field (POSTed value)
$out = '<input type="hidden" name="'.dol_escape_htmltag($htmlname).'" id="'.dol_escape_htmltag($htmlname).'" value="'.dol_escape_htmltag($fullPhone).'">';
// Picto
$out .= img_picto('', $picto, 'class="pictofixedwidth"');
// Phone code select (display-only name, not submitted as separate POST param)
$out .= $this->selectPhoneCode($selectedCode, $codename, 'maxwidth75 phone_code_select', 0, $country_id_hint);
// Visible number input (no name — not POSTed)
$out .= '<input type="tel" inputmode="numeric" pattern="[0-9]*" id="'.dol_escape_htmltag($htmlname).'_input" class="'.dol_escape_htmltag($morecss).'"';
if ($maxlength > 0) {
$out .= ' maxlength="'.$maxlength.'"';
}
$out .= ' value="'.dol_escape_htmltag($numberValue).'">';
// Per-field JS to sync hidden field
$out .= $this->getPhoneInputFieldJs($htmlname, $codename);
// Shared JS for country-sync (output once per page)
$out .= $this->getPhoneInputSharedJs($countrySelectorId);
return $out;
}
/**
* Return inline JS that syncs the hidden phone field from select + text input.
*
* Strips formatting chars and trunk prefix from the number, then builds
* the hidden value as "{code} {number}" or just "{number}" if no code.
*
* @param string $htmlname Base name (e.g. "phone_pro")
* @param string $codename Code select name (e.g. "phone_pro_code")
* @return string Inline <script> block
*/
private function getPhoneInputFieldJs($htmlname, $codename)
{
$hiddenId = dol_escape_js($htmlname);
$inputId = dol_escape_js($htmlname).'_input';
$selectId = 'select'.dol_escape_js($codename);
$out = "\n".'<script type="text/javascript">'."\n";
$out .= 'jQuery(document).ready(function() {'."\n";
$out .= ' function syncPhoneField_'.$hiddenId.'() {'."\n";
$out .= ' var selectEl = jQuery("#'.$selectId.'");'."\n";
$out .= ' var code = selectEl.val() || "";'."\n";
$out .= ' var number = (jQuery("#'.$inputId.'").val() || "").replace(/[^0-9]/g, "");'."\n";
$out .= ' if (code && number) {'."\n";
$out .= ' var selOpt = selectEl[0] && selectEl[0].selectedOptions && selectEl[0].selectedOptions[0];'."\n";
$out .= ' var trunkPrefix = selOpt ? (selOpt.getAttribute("data-trunk-prefix") || "") : "";'."\n";
$out .= ' if (trunkPrefix !== "" && number.indexOf(trunkPrefix) === 0) {'."\n";
$out .= ' number = number.substring(trunkPrefix.length);'."\n";
$out .= ' }'."\n";
$out .= ' jQuery("#'.$hiddenId.'").val(code + " " + number);'."\n";
$out .= ' } else if (number) {'."\n";
$out .= ' jQuery("#'.$hiddenId.'").val(number);'."\n";
$out .= ' } else {'."\n";
$out .= ' jQuery("#'.$hiddenId.'").val("");'."\n";
$out .= ' }'."\n";
$out .= ' }'."\n";
$out .= ' jQuery("#'.$selectId.'").on("change", function() { syncPhoneField_'.$hiddenId.'(); });'."\n";
$out .= ' jQuery("#'.$inputId.'").on("input change", function() { syncPhoneField_'.$hiddenId.'(); });'."\n";
$out .= '});'."\n";
$out .= '</script>'."\n";
return $out;
}
/**
* Return inline JS for country-selector → phone code sync (output once per page).
*
* When the country select changes, fetches the phone code via AJAX and updates
* all .phone_code_select dropdowns, which in turn triggers per-field sync.
*
* @param string $countrySelectorId ID of the country select element
* @return string Inline <script> block or empty string
*/
private function getPhoneInputSharedJs($countrySelectorId)
{
if ($this->phoneInputSharedJsLoaded) {
return '';
}
$this->phoneInputSharedJsLoaded = true;
$out = "\n".'<script type="text/javascript">'."\n";
$out .= 'jQuery(document).ready(function() {'."\n";
$out .= ' jQuery("#'.dol_escape_js($countrySelectorId).'").on("change", function() {'."\n";
$out .= ' var country_id = jQuery(this).val();'."\n";
$out .= ' if (country_id) {'."\n";
$out .= ' jQuery.getJSON("'.DOL_URL_ROOT.'/core/ajax/getphonecode.php", {country_id: country_id, token: "'.currentToken().'"}, function(data) {'."\n";
$out .= ' if (data.phone_code) {'."\n";
$out .= ' jQuery(".phone_code_select").each(function() {'."\n";
$out .= ' jQuery(this).val(data.phone_code).trigger("change");'."\n";
$out .= ' });'."\n";
$out .= ' }'."\n";
$out .= ' });'."\n";
$out .= ' }'."\n";
$out .= ' });'."\n";
$out .= '});'."\n";
$out .= '</script>'."\n";
return $out;
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**

View file

@ -4,6 +4,7 @@
* Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
* Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
* Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
* Copyright (C) 2026 Open-Dsi <support@open-dsi.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -557,6 +558,11 @@ function ajax_combobox($htmlname, $events = array(), $minLengthToAutocomplete =
},
templateSelection: function (selection) { /* Format visible output of selected value */
if (selection.id == \''.(dol_escape_js($idforemptyvalue)).'\') return \'<span class="placeholder">\'+selection.text+\'</span>\';
if (selection.element && $(selection.element).attr("data-select-html") != undefined) {
if (typeof htmlEntityDecodeJs === "function") {
return htmlEntityDecodeJs($(selection.element).attr("data-select-html"));
}
}
return selection.text;
},
escapeMarkup: function(markup) {

View file

@ -0,0 +1,160 @@
<?php
/* Copyright (C) 2026 Open-Dsi <support@open-dsi.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/core/lib/phone.lib.php
* \ingroup core
* \brief Helper functions for phone number formatting
*/
/**
* Parse a stored phone number into country code and number parts
*
* Stored format is "+{code} {number}" (e.g. "+33 644986885").
* If no code is found, returns empty code and the full string as number.
*
* @param string $phone Stored phone number
* @return array{code:string,number:string} Array with 'code' and 'number' keys
*/
function dol_parse_phone($phone)
{
$phone = trim((string) $phone);
if ($phone === '') {
return array('code' => '', 'number' => '');
}
if (strpos($phone, '+') === 0) {
$pos = strpos($phone, ' ');
if ($pos !== false) {
return array(
'code' => substr($phone, 0, $pos),
'number' => substr($phone, $pos + 1)
);
}
// Phone starts with + but has no space: try to keep it as-is in code
return array('code' => '', 'number' => $phone);
}
return array('code' => '', 'number' => $phone);
}
/**
* Build a normalized phone string from code and number parts
*
* Strips formatting characters (spaces, dashes, dots, parentheses) from number.
* Also strips the national trunk prefix for the country matching $code
* (e.g. leading "0" for France, "8" for Russia, "06" for Hungary).
* Returns "+{code} {number}" or just the number if code is empty.
*
* @param DoliDB $db Database handler
* @param string $code Country calling code (e.g. "+33")
* @param string $number Phone number (may contain formatting)
* @return string Normalized phone string
*/
function dol_build_phone($db, $code, $number)
{
$number = preg_replace('/[\s\-\.\(\)]/', '', trim((string) $number));
$code = trim((string) $code);
if ($number === '') {
return '';
}
if ($code !== '') {
// Strip national trunk prefix (e.g. leading "0" for France)
$sql = "SELECT trunk_prefix FROM ".$db->prefix()."c_country";
$sql .= " WHERE phone_code = ".((int) ltrim($code, '+'));
$sql .= " AND trunk_prefix IS NOT NULL AND trunk_prefix != ''";
$sql .= " LIMIT 1";
$resql = $db->query($sql);
if ($resql) {
$obj = $db->fetch_object($resql);
if ($obj && isset($obj->trunk_prefix) && $obj->trunk_prefix !== '' && $obj->trunk_prefix !== null) {
$prefix = $obj->trunk_prefix;
if (strpos($number, $prefix) === 0) {
$number = substr($number, strlen($prefix));
}
}
$db->free($resql);
}
}
if ($code !== '') {
return $code.' '.$number;
}
return $number;
}
/**
* Get the national trunk prefix for a phone code
*
* @param DoliDB $db Database handler
* @param string $phone_code Phone code (e.g. "+33")
* @return string Trunk prefix (e.g. "0") or empty string
*/
function dol_get_trunk_prefix($db, $phone_code)
{
$phone_code = trim((string) $phone_code);
if ($phone_code === '') {
return '';
}
$sql = "SELECT trunk_prefix FROM ".$db->prefix()."c_country";
$sql .= " WHERE phone_code = ".((int) ltrim($phone_code, '+'));
$sql .= " AND trunk_prefix IS NOT NULL AND trunk_prefix != ''";
$sql .= " LIMIT 1";
$resql = $db->query($sql);
if ($resql) {
$obj = $db->fetch_object($resql);
if ($obj && isset($obj->trunk_prefix) && $obj->trunk_prefix !== '' && $obj->trunk_prefix !== null) {
$db->free($resql);
return $obj->trunk_prefix;
}
$db->free($resql);
}
return '';
}
/**
* Get the phone calling code for a country
*
* @param DoliDB $db Database handler
* @param int $country_id Country rowid
* @return string Phone code (e.g. "+33") or empty string
*/
function dol_get_phone_code_from_country($db, $country_id)
{
$country_id = (int) $country_id;
if ($country_id <= 0) {
return '';
}
$sql = "SELECT phone_code FROM ".$db->prefix()."c_country WHERE rowid = ".((int) $country_id);
$resql = $db->query($sql);
if ($resql) {
$obj = $db->fetch_object($resql);
if ($obj && !empty($obj->phone_code)) {
$db->free($resql);
return '+'.$obj->phone_code;
}
$db->free($resql);
}
return '';
}

View file

@ -8,6 +8,7 @@
-- Copyright (C) 2014 Alexandre Spangaro <aspangaro@open-dsi.fr>
-- Copyright (C) 2021-2022 Udo Tamm <dev@dolibit.de>
-- Copyright (C) 2025 Nick Fragoulis
-- Copyright (C) 2026 Open-Dsi <support@open-dsi.fr>
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
@ -544,3 +545,381 @@ UPDATE llx_c_country SET eec = 1 WHERE code IN ('AT','BE','BG','CY','CZ','DE','D
-- Source: https://www.europeanpaymentscouncil.eu/document-library/other/epc-list-sepa-scheme-countries
-- Set field sepa
UPDATE llx_c_country SET sepa = 1 WHERE code IN ('AD','AL','AT','AX','BE','BG','BL','CH','CY','CZ','DE','DK','EE','ES','FI','FR','GB','GF','GG','GI','GP','GR','HR','HU','IE','IM','IS','IT','JE','LI','LT','LU','LV','MC','MD','ME','MF','MK','MQ','MT','NL','NO','PL','PM','PT','RE','RO','RS','SE','SI','SK','SM','VA','YT');
-- Set field phone_code (ITU-T country calling codes)
UPDATE llx_c_country SET phone_code = 33 WHERE code = 'FR';
UPDATE llx_c_country SET phone_code = 32 WHERE code = 'BE';
UPDATE llx_c_country SET phone_code = 39 WHERE code = 'IT';
UPDATE llx_c_country SET phone_code = 34 WHERE code = 'ES';
UPDATE llx_c_country SET phone_code = 49 WHERE code = 'DE';
UPDATE llx_c_country SET phone_code = 41 WHERE code = 'CH';
UPDATE llx_c_country SET phone_code = 44 WHERE code = 'GB';
UPDATE llx_c_country SET phone_code = 353 WHERE code = 'IE';
UPDATE llx_c_country SET phone_code = 86 WHERE code = 'CN';
UPDATE llx_c_country SET phone_code = 216 WHERE code = 'TN';
UPDATE llx_c_country SET phone_code = 1 WHERE code = 'US';
UPDATE llx_c_country SET phone_code = 212 WHERE code = 'MA';
UPDATE llx_c_country SET phone_code = 213 WHERE code = 'DZ';
UPDATE llx_c_country SET phone_code = 1 WHERE code = 'CA';
UPDATE llx_c_country SET phone_code = 228 WHERE code = 'TG';
UPDATE llx_c_country SET phone_code = 241 WHERE code = 'GA';
UPDATE llx_c_country SET phone_code = 31 WHERE code = 'NL';
UPDATE llx_c_country SET phone_code = 36 WHERE code = 'HU';
UPDATE llx_c_country SET phone_code = 7 WHERE code = 'RU';
UPDATE llx_c_country SET phone_code = 46 WHERE code = 'SE';
UPDATE llx_c_country SET phone_code = 225 WHERE code = 'CI';
UPDATE llx_c_country SET phone_code = 221 WHERE code = 'SN';
UPDATE llx_c_country SET phone_code = 54 WHERE code = 'AR';
UPDATE llx_c_country SET phone_code = 237 WHERE code = 'CM';
UPDATE llx_c_country SET phone_code = 351 WHERE code = 'PT';
UPDATE llx_c_country SET phone_code = 966 WHERE code = 'SA';
UPDATE llx_c_country SET phone_code = 377 WHERE code = 'MC';
UPDATE llx_c_country SET phone_code = 61 WHERE code = 'AU';
UPDATE llx_c_country SET phone_code = 65 WHERE code = 'SG';
UPDATE llx_c_country SET phone_code = 93 WHERE code = 'AF';
UPDATE llx_c_country SET phone_code = 358 WHERE code = 'AX';
UPDATE llx_c_country SET phone_code = 355 WHERE code = 'AL';
UPDATE llx_c_country SET phone_code = 1684 WHERE code = 'AS';
UPDATE llx_c_country SET phone_code = 376 WHERE code = 'AD';
UPDATE llx_c_country SET phone_code = 244 WHERE code = 'AO';
UPDATE llx_c_country SET phone_code = 1264 WHERE code = 'AI';
UPDATE llx_c_country SET phone_code = 1268 WHERE code = 'AG';
UPDATE llx_c_country SET phone_code = 374 WHERE code = 'AM';
UPDATE llx_c_country SET phone_code = 297 WHERE code = 'AW';
UPDATE llx_c_country SET phone_code = 43 WHERE code = 'AT';
UPDATE llx_c_country SET phone_code = 994 WHERE code = 'AZ';
UPDATE llx_c_country SET phone_code = 1242 WHERE code = 'BS';
UPDATE llx_c_country SET phone_code = 973 WHERE code = 'BH';
UPDATE llx_c_country SET phone_code = 880 WHERE code = 'BD';
UPDATE llx_c_country SET phone_code = 1246 WHERE code = 'BB';
UPDATE llx_c_country SET phone_code = 375 WHERE code = 'BY';
UPDATE llx_c_country SET phone_code = 501 WHERE code = 'BZ';
UPDATE llx_c_country SET phone_code = 229 WHERE code = 'BJ';
UPDATE llx_c_country SET phone_code = 1441 WHERE code = 'BM';
UPDATE llx_c_country SET phone_code = 975 WHERE code = 'BT';
UPDATE llx_c_country SET phone_code = 591 WHERE code = 'BO';
UPDATE llx_c_country SET phone_code = 387 WHERE code = 'BA';
UPDATE llx_c_country SET phone_code = 267 WHERE code = 'BW';
UPDATE llx_c_country SET phone_code = 55 WHERE code = 'BR';
UPDATE llx_c_country SET phone_code = 246 WHERE code = 'IO';
UPDATE llx_c_country SET phone_code = 673 WHERE code = 'BN';
UPDATE llx_c_country SET phone_code = 359 WHERE code = 'BG';
UPDATE llx_c_country SET phone_code = 226 WHERE code = 'BF';
UPDATE llx_c_country SET phone_code = 257 WHERE code = 'BI';
UPDATE llx_c_country SET phone_code = 855 WHERE code = 'KH';
UPDATE llx_c_country SET phone_code = 238 WHERE code = 'CV';
UPDATE llx_c_country SET phone_code = 1345 WHERE code = 'KY';
UPDATE llx_c_country SET phone_code = 236 WHERE code = 'CF';
UPDATE llx_c_country SET phone_code = 235 WHERE code = 'TD';
UPDATE llx_c_country SET phone_code = 56 WHERE code = 'CL';
UPDATE llx_c_country SET phone_code = 61 WHERE code = 'CX';
UPDATE llx_c_country SET phone_code = 61 WHERE code = 'CC';
UPDATE llx_c_country SET phone_code = 57 WHERE code = 'CO';
UPDATE llx_c_country SET phone_code = 269 WHERE code = 'KM';
UPDATE llx_c_country SET phone_code = 242 WHERE code = 'CG';
UPDATE llx_c_country SET phone_code = 243 WHERE code = 'CD';
UPDATE llx_c_country SET phone_code = 682 WHERE code = 'CK';
UPDATE llx_c_country SET phone_code = 506 WHERE code = 'CR';
UPDATE llx_c_country SET phone_code = 385 WHERE code = 'HR';
UPDATE llx_c_country SET phone_code = 53 WHERE code = 'CU';
UPDATE llx_c_country SET phone_code = 357 WHERE code = 'CY';
UPDATE llx_c_country SET phone_code = 420 WHERE code = 'CZ';
UPDATE llx_c_country SET phone_code = 45 WHERE code = 'DK';
UPDATE llx_c_country SET phone_code = 253 WHERE code = 'DJ';
UPDATE llx_c_country SET phone_code = 1767 WHERE code = 'DM';
UPDATE llx_c_country SET phone_code = 1809 WHERE code = 'DO';
UPDATE llx_c_country SET phone_code = 593 WHERE code = 'EC';
UPDATE llx_c_country SET phone_code = 20 WHERE code = 'EG';
UPDATE llx_c_country SET phone_code = 503 WHERE code = 'SV';
UPDATE llx_c_country SET phone_code = 240 WHERE code = 'GQ';
UPDATE llx_c_country SET phone_code = 291 WHERE code = 'ER';
UPDATE llx_c_country SET phone_code = 372 WHERE code = 'EE';
UPDATE llx_c_country SET phone_code = 251 WHERE code = 'ET';
UPDATE llx_c_country SET phone_code = 500 WHERE code = 'FK';
UPDATE llx_c_country SET phone_code = 298 WHERE code = 'FO';
UPDATE llx_c_country SET phone_code = 679 WHERE code = 'FJ';
UPDATE llx_c_country SET phone_code = 358 WHERE code = 'FI';
UPDATE llx_c_country SET phone_code = 594 WHERE code = 'GF';
UPDATE llx_c_country SET phone_code = 689 WHERE code = 'PF';
UPDATE llx_c_country SET phone_code = 220 WHERE code = 'GM';
UPDATE llx_c_country SET phone_code = 995 WHERE code = 'GE';
UPDATE llx_c_country SET phone_code = 233 WHERE code = 'GH';
UPDATE llx_c_country SET phone_code = 350 WHERE code = 'GI';
UPDATE llx_c_country SET phone_code = 30 WHERE code = 'GR';
UPDATE llx_c_country SET phone_code = 299 WHERE code = 'GL';
UPDATE llx_c_country SET phone_code = 1473 WHERE code = 'GD';
UPDATE llx_c_country SET phone_code = 1671 WHERE code = 'GU';
UPDATE llx_c_country SET phone_code = 502 WHERE code = 'GT';
UPDATE llx_c_country SET phone_code = 224 WHERE code = 'GN';
UPDATE llx_c_country SET phone_code = 245 WHERE code = 'GW';
UPDATE llx_c_country SET phone_code = 509 WHERE code = 'HT';
UPDATE llx_c_country SET phone_code = 379 WHERE code = 'VA';
UPDATE llx_c_country SET phone_code = 504 WHERE code = 'HN';
UPDATE llx_c_country SET phone_code = 852 WHERE code = 'HK';
UPDATE llx_c_country SET phone_code = 354 WHERE code = 'IS';
UPDATE llx_c_country SET phone_code = 91 WHERE code = 'IN';
UPDATE llx_c_country SET phone_code = 62 WHERE code = 'ID';
UPDATE llx_c_country SET phone_code = 98 WHERE code = 'IR';
UPDATE llx_c_country SET phone_code = 964 WHERE code = 'IQ';
UPDATE llx_c_country SET phone_code = 972 WHERE code = 'IL';
UPDATE llx_c_country SET phone_code = 1876 WHERE code = 'JM';
UPDATE llx_c_country SET phone_code = 81 WHERE code = 'JP';
UPDATE llx_c_country SET phone_code = 962 WHERE code = 'JO';
UPDATE llx_c_country SET phone_code = 7 WHERE code = 'KZ';
UPDATE llx_c_country SET phone_code = 254 WHERE code = 'KE';
UPDATE llx_c_country SET phone_code = 686 WHERE code = 'KI';
UPDATE llx_c_country SET phone_code = 850 WHERE code = 'KP';
UPDATE llx_c_country SET phone_code = 82 WHERE code = 'KR';
UPDATE llx_c_country SET phone_code = 965 WHERE code = 'KW';
UPDATE llx_c_country SET phone_code = 996 WHERE code = 'KG';
UPDATE llx_c_country SET phone_code = 856 WHERE code = 'LA';
UPDATE llx_c_country SET phone_code = 371 WHERE code = 'LV';
UPDATE llx_c_country SET phone_code = 961 WHERE code = 'LB';
UPDATE llx_c_country SET phone_code = 266 WHERE code = 'LS';
UPDATE llx_c_country SET phone_code = 231 WHERE code = 'LR';
UPDATE llx_c_country SET phone_code = 218 WHERE code = 'LY';
UPDATE llx_c_country SET phone_code = 423 WHERE code = 'LI';
UPDATE llx_c_country SET phone_code = 370 WHERE code = 'LT';
UPDATE llx_c_country SET phone_code = 352 WHERE code = 'LU';
UPDATE llx_c_country SET phone_code = 853 WHERE code = 'MO';
UPDATE llx_c_country SET phone_code = 389 WHERE code = 'MK';
UPDATE llx_c_country SET phone_code = 261 WHERE code = 'MG';
UPDATE llx_c_country SET phone_code = 265 WHERE code = 'MW';
UPDATE llx_c_country SET phone_code = 60 WHERE code = 'MY';
UPDATE llx_c_country SET phone_code = 960 WHERE code = 'MV';
UPDATE llx_c_country SET phone_code = 223 WHERE code = 'ML';
UPDATE llx_c_country SET phone_code = 356 WHERE code = 'MT';
UPDATE llx_c_country SET phone_code = 692 WHERE code = 'MH';
UPDATE llx_c_country SET phone_code = 222 WHERE code = 'MR';
UPDATE llx_c_country SET phone_code = 230 WHERE code = 'MU';
UPDATE llx_c_country SET phone_code = 262 WHERE code = 'YT';
UPDATE llx_c_country SET phone_code = 52 WHERE code = 'MX';
UPDATE llx_c_country SET phone_code = 691 WHERE code = 'FM';
UPDATE llx_c_country SET phone_code = 373 WHERE code = 'MD';
UPDATE llx_c_country SET phone_code = 976 WHERE code = 'MN';
UPDATE llx_c_country SET phone_code = 1664 WHERE code = 'MS';
UPDATE llx_c_country SET phone_code = 258 WHERE code = 'MZ';
UPDATE llx_c_country SET phone_code = 95 WHERE code = 'MM';
UPDATE llx_c_country SET phone_code = 264 WHERE code = 'NA';
UPDATE llx_c_country SET phone_code = 674 WHERE code = 'NR';
UPDATE llx_c_country SET phone_code = 977 WHERE code = 'NP';
UPDATE llx_c_country SET phone_code = 599 WHERE code = 'CW';
UPDATE llx_c_country SET phone_code = 1721 WHERE code = 'SX';
UPDATE llx_c_country SET phone_code = 687 WHERE code = 'NC';
UPDATE llx_c_country SET phone_code = 64 WHERE code = 'NZ';
UPDATE llx_c_country SET phone_code = 505 WHERE code = 'NI';
UPDATE llx_c_country SET phone_code = 227 WHERE code = 'NE';
UPDATE llx_c_country SET phone_code = 234 WHERE code = 'NG';
UPDATE llx_c_country SET phone_code = 683 WHERE code = 'NU';
UPDATE llx_c_country SET phone_code = 672 WHERE code = 'NF';
UPDATE llx_c_country SET phone_code = 1670 WHERE code = 'MP';
UPDATE llx_c_country SET phone_code = 47 WHERE code = 'NO';
UPDATE llx_c_country SET phone_code = 968 WHERE code = 'OM';
UPDATE llx_c_country SET phone_code = 92 WHERE code = 'PK';
UPDATE llx_c_country SET phone_code = 680 WHERE code = 'PW';
UPDATE llx_c_country SET phone_code = 970 WHERE code = 'PS';
UPDATE llx_c_country SET phone_code = 507 WHERE code = 'PA';
UPDATE llx_c_country SET phone_code = 675 WHERE code = 'PG';
UPDATE llx_c_country SET phone_code = 595 WHERE code = 'PY';
UPDATE llx_c_country SET phone_code = 51 WHERE code = 'PE';
UPDATE llx_c_country SET phone_code = 63 WHERE code = 'PH';
UPDATE llx_c_country SET phone_code = 48 WHERE code = 'PL';
UPDATE llx_c_country SET phone_code = 1787 WHERE code = 'PR';
UPDATE llx_c_country SET phone_code = 974 WHERE code = 'QA';
UPDATE llx_c_country SET phone_code = 40 WHERE code = 'RO';
UPDATE llx_c_country SET phone_code = 250 WHERE code = 'RW';
UPDATE llx_c_country SET phone_code = 290 WHERE code = 'SH';
UPDATE llx_c_country SET phone_code = 1869 WHERE code = 'KN';
UPDATE llx_c_country SET phone_code = 1758 WHERE code = 'LC';
UPDATE llx_c_country SET phone_code = 508 WHERE code = 'PM';
UPDATE llx_c_country SET phone_code = 1784 WHERE code = 'VC';
UPDATE llx_c_country SET phone_code = 685 WHERE code = 'WS';
UPDATE llx_c_country SET phone_code = 378 WHERE code = 'SM';
UPDATE llx_c_country SET phone_code = 239 WHERE code = 'ST';
UPDATE llx_c_country SET phone_code = 381 WHERE code = 'RS';
UPDATE llx_c_country SET phone_code = 248 WHERE code = 'SC';
UPDATE llx_c_country SET phone_code = 232 WHERE code = 'SL';
UPDATE llx_c_country SET phone_code = 421 WHERE code = 'SK';
UPDATE llx_c_country SET phone_code = 386 WHERE code = 'SI';
UPDATE llx_c_country SET phone_code = 677 WHERE code = 'SB';
UPDATE llx_c_country SET phone_code = 252 WHERE code = 'SO';
UPDATE llx_c_country SET phone_code = 27 WHERE code = 'ZA';
UPDATE llx_c_country SET phone_code = 94 WHERE code = 'LK';
UPDATE llx_c_country SET phone_code = 249 WHERE code = 'SD';
UPDATE llx_c_country SET phone_code = 597 WHERE code = 'SR';
UPDATE llx_c_country SET phone_code = 47 WHERE code = 'SJ';
UPDATE llx_c_country SET phone_code = 268 WHERE code = 'SZ';
UPDATE llx_c_country SET phone_code = 963 WHERE code = 'SY';
UPDATE llx_c_country SET phone_code = 886 WHERE code = 'TW';
UPDATE llx_c_country SET phone_code = 992 WHERE code = 'TJ';
UPDATE llx_c_country SET phone_code = 255 WHERE code = 'TZ';
UPDATE llx_c_country SET phone_code = 66 WHERE code = 'TH';
UPDATE llx_c_country SET phone_code = 670 WHERE code = 'TL';
UPDATE llx_c_country SET phone_code = 690 WHERE code = 'TK';
UPDATE llx_c_country SET phone_code = 676 WHERE code = 'TO';
UPDATE llx_c_country SET phone_code = 1868 WHERE code = 'TT';
UPDATE llx_c_country SET phone_code = 90 WHERE code = 'TR';
UPDATE llx_c_country SET phone_code = 993 WHERE code = 'TM';
UPDATE llx_c_country SET phone_code = 1649 WHERE code = 'TC';
UPDATE llx_c_country SET phone_code = 688 WHERE code = 'TV';
UPDATE llx_c_country SET phone_code = 256 WHERE code = 'UG';
UPDATE llx_c_country SET phone_code = 380 WHERE code = 'UA';
UPDATE llx_c_country SET phone_code = 971 WHERE code = 'AE';
UPDATE llx_c_country SET phone_code = 598 WHERE code = 'UY';
UPDATE llx_c_country SET phone_code = 998 WHERE code = 'UZ';
UPDATE llx_c_country SET phone_code = 678 WHERE code = 'VU';
UPDATE llx_c_country SET phone_code = 58 WHERE code = 'VE';
UPDATE llx_c_country SET phone_code = 84 WHERE code = 'VN';
UPDATE llx_c_country SET phone_code = 1284 WHERE code = 'VG';
UPDATE llx_c_country SET phone_code = 1340 WHERE code = 'VI';
UPDATE llx_c_country SET phone_code = 681 WHERE code = 'WF';
UPDATE llx_c_country SET phone_code = 967 WHERE code = 'YE';
UPDATE llx_c_country SET phone_code = 260 WHERE code = 'ZM';
UPDATE llx_c_country SET phone_code = 263 WHERE code = 'ZW';
UPDATE llx_c_country SET phone_code = 44 WHERE code = 'GG';
UPDATE llx_c_country SET phone_code = 44 WHERE code = 'IM';
UPDATE llx_c_country SET phone_code = 44 WHERE code = 'JE';
UPDATE llx_c_country SET phone_code = 382 WHERE code = 'ME';
UPDATE llx_c_country SET phone_code = 590 WHERE code = 'BL';
UPDATE llx_c_country SET phone_code = 590 WHERE code = 'MF';
UPDATE llx_c_country SET phone_code = 383 WHERE code = 'XK';
-- Set field trunk_prefix (national trunk prefix stripped in international format)
-- Trunk prefix '0' (~101 countries)
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'FR';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'BE';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'DE';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'CH';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'GB';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'IE';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'NL';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'SE';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'AT';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'GR';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'FI';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'HR';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'BA';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'BG';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'RO';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'RS';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'ME';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'MK';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'AL';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'SK';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'SI';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'LT';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'MD';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'UA';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'GE';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'XK';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'TR';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'CN';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'IN';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'ID';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'JP';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'KR';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'TH';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'VN';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'MY';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'PH';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'BD';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'PK';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'AF';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'IR';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'IQ';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'JO';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'LB';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'SA';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'AE';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'IL';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'SY';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'YE';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'AM';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'AZ';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'KH';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'LA';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'MM';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'NP';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'LK';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'TW';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'MN';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'KG';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'UZ';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'PS';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'KP';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'MA';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'DZ';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'EG';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'ZA';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'NG';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'GH';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'KE';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'ET';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'TZ';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'UG';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'SD';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'LY';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'NA';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'SL';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'ZM';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'ZW';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'ER';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'CD';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'AO';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'EH';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'AU';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'NZ';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'AR';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'BR';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'CU';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'VE';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'PE';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'EC';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'BO';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'PY';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'SR';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'GF';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'YT';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'PM';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'BL';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'MF';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'GG';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'JE';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'IM';
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code = 'AX';
-- Trunk prefix '8' (post-Soviet countries)
UPDATE llx_c_country SET trunk_prefix = '8' WHERE code = 'RU';
UPDATE llx_c_country SET trunk_prefix = '8' WHERE code = 'BY';
UPDATE llx_c_country SET trunk_prefix = '8' WHERE code = 'KZ';
UPDATE llx_c_country SET trunk_prefix = '8' WHERE code = 'TJ';
UPDATE llx_c_country SET trunk_prefix = '8' WHERE code = 'TM';
-- Trunk prefix '06' (Hungary)
UPDATE llx_c_country SET trunk_prefix = '06' WHERE code = 'HU';
-- Trunk prefix '1' (NANP countries)
UPDATE llx_c_country SET trunk_prefix = '1' WHERE code = 'US';
UPDATE llx_c_country SET trunk_prefix = '1' WHERE code = 'CA';
UPDATE llx_c_country SET trunk_prefix = '1' WHERE code = 'PR';
UPDATE llx_c_country SET trunk_prefix = '1' WHERE code = 'VI';
UPDATE llx_c_country SET trunk_prefix = '1' WHERE code = 'GU';
UPDATE llx_c_country SET trunk_prefix = '1' WHERE code = 'AS';
UPDATE llx_c_country SET trunk_prefix = '1' WHERE code = 'MP';
UPDATE llx_c_country SET trunk_prefix = '1' WHERE code = 'JM';
UPDATE llx_c_country SET trunk_prefix = '1' WHERE code = 'BS';
UPDATE llx_c_country SET trunk_prefix = '1' WHERE code = 'BB';
UPDATE llx_c_country SET trunk_prefix = '1' WHERE code = 'AG';
UPDATE llx_c_country SET trunk_prefix = '1' WHERE code = 'DM';
UPDATE llx_c_country SET trunk_prefix = '1' WHERE code = 'GD';
UPDATE llx_c_country SET trunk_prefix = '1' WHERE code = 'KN';
UPDATE llx_c_country SET trunk_prefix = '1' WHERE code = 'LC';
UPDATE llx_c_country SET trunk_prefix = '1' WHERE code = 'VC';
UPDATE llx_c_country SET trunk_prefix = '1' WHERE code = 'TT';
UPDATE llx_c_country SET trunk_prefix = '1' WHERE code = 'DO';
UPDATE llx_c_country SET trunk_prefix = '1' WHERE code = 'AI';
UPDATE llx_c_country SET trunk_prefix = '1' WHERE code = 'BM';
UPDATE llx_c_country SET trunk_prefix = '1' WHERE code = 'VG';
UPDATE llx_c_country SET trunk_prefix = '1' WHERE code = 'KY';
UPDATE llx_c_country SET trunk_prefix = '1' WHERE code = 'MS';
UPDATE llx_c_country SET trunk_prefix = '1' WHERE code = 'TC';
UPDATE llx_c_country SET trunk_prefix = '1' WHERE code = 'SX';
UPDATE llx_c_country SET trunk_prefix = '1' WHERE code = 'MH';
UPDATE llx_c_country SET trunk_prefix = '1' WHERE code = 'FM';

View file

@ -224,6 +224,8 @@ ALTER TABLE llx_prelevement_lignes ADD COLUMN bic varchar(11); -- 11 accordi
ALTER TABLE llx_prelevement_lignes ADD COLUMN iban varchar(80); -- full iban. 34 according to ISO 13616 but we set 80 to allow to store it with encryption information
ALTER TABLE llx_prelevement_lignes ADD COLUMN rum varchar(32); -- rum used
-- Add phone_code column to country table
ALTER TABLE llx_c_country ADD COLUMN phone_code integer;
ALTER TABLE llx_product_customer_price CHANGE COLUMN localtax1_tx localtax1_tx varchar(20) DEFAULT '0';
ALTER TABLE llx_product_customer_price CHANGE COLUMN localtax2_tx localtax2_tx varchar(20) DEFAULT '0';
@ -438,4 +440,262 @@ INSERT INTO llx_accounting_system (fk_country, pcg_version, label, active) VALUE
INSERT INTO llx_accounting_system (fk_country, pcg_version, label, active) VALUES ( 4, 'PCG08-PYME-CAT', 'The PYME accountancy spanish plan in catalan language', 1);
-- Populate phone codes (ITU-T country calling codes)
UPDATE llx_c_country SET phone_code = 33 WHERE code = 'FR';
UPDATE llx_c_country SET phone_code = 32 WHERE code = 'BE';
UPDATE llx_c_country SET phone_code = 39 WHERE code = 'IT';
UPDATE llx_c_country SET phone_code = 34 WHERE code = 'ES';
UPDATE llx_c_country SET phone_code = 49 WHERE code = 'DE';
UPDATE llx_c_country SET phone_code = 41 WHERE code = 'CH';
UPDATE llx_c_country SET phone_code = 44 WHERE code = 'GB';
UPDATE llx_c_country SET phone_code = 353 WHERE code = 'IE';
UPDATE llx_c_country SET phone_code = 86 WHERE code = 'CN';
UPDATE llx_c_country SET phone_code = 216 WHERE code = 'TN';
UPDATE llx_c_country SET phone_code = 1 WHERE code = 'US';
UPDATE llx_c_country SET phone_code = 212 WHERE code = 'MA';
UPDATE llx_c_country SET phone_code = 213 WHERE code = 'DZ';
UPDATE llx_c_country SET phone_code = 1 WHERE code = 'CA';
UPDATE llx_c_country SET phone_code = 228 WHERE code = 'TG';
UPDATE llx_c_country SET phone_code = 241 WHERE code = 'GA';
UPDATE llx_c_country SET phone_code = 31 WHERE code = 'NL';
UPDATE llx_c_country SET phone_code = 36 WHERE code = 'HU';
UPDATE llx_c_country SET phone_code = 7 WHERE code = 'RU';
UPDATE llx_c_country SET phone_code = 46 WHERE code = 'SE';
UPDATE llx_c_country SET phone_code = 225 WHERE code = 'CI';
UPDATE llx_c_country SET phone_code = 221 WHERE code = 'SN';
UPDATE llx_c_country SET phone_code = 54 WHERE code = 'AR';
UPDATE llx_c_country SET phone_code = 237 WHERE code = 'CM';
UPDATE llx_c_country SET phone_code = 351 WHERE code = 'PT';
UPDATE llx_c_country SET phone_code = 966 WHERE code = 'SA';
UPDATE llx_c_country SET phone_code = 377 WHERE code = 'MC';
UPDATE llx_c_country SET phone_code = 61 WHERE code = 'AU';
UPDATE llx_c_country SET phone_code = 65 WHERE code = 'SG';
UPDATE llx_c_country SET phone_code = 93 WHERE code = 'AF';
UPDATE llx_c_country SET phone_code = 358 WHERE code = 'AX';
UPDATE llx_c_country SET phone_code = 355 WHERE code = 'AL';
UPDATE llx_c_country SET phone_code = 1684 WHERE code = 'AS';
UPDATE llx_c_country SET phone_code = 376 WHERE code = 'AD';
UPDATE llx_c_country SET phone_code = 244 WHERE code = 'AO';
UPDATE llx_c_country SET phone_code = 1264 WHERE code = 'AI';
UPDATE llx_c_country SET phone_code = 1268 WHERE code = 'AG';
UPDATE llx_c_country SET phone_code = 374 WHERE code = 'AM';
UPDATE llx_c_country SET phone_code = 297 WHERE code = 'AW';
UPDATE llx_c_country SET phone_code = 43 WHERE code = 'AT';
UPDATE llx_c_country SET phone_code = 994 WHERE code = 'AZ';
UPDATE llx_c_country SET phone_code = 1242 WHERE code = 'BS';
UPDATE llx_c_country SET phone_code = 973 WHERE code = 'BH';
UPDATE llx_c_country SET phone_code = 880 WHERE code = 'BD';
UPDATE llx_c_country SET phone_code = 1246 WHERE code = 'BB';
UPDATE llx_c_country SET phone_code = 375 WHERE code = 'BY';
UPDATE llx_c_country SET phone_code = 501 WHERE code = 'BZ';
UPDATE llx_c_country SET phone_code = 229 WHERE code = 'BJ';
UPDATE llx_c_country SET phone_code = 1441 WHERE code = 'BM';
UPDATE llx_c_country SET phone_code = 975 WHERE code = 'BT';
UPDATE llx_c_country SET phone_code = 591 WHERE code = 'BO';
UPDATE llx_c_country SET phone_code = 387 WHERE code = 'BA';
UPDATE llx_c_country SET phone_code = 267 WHERE code = 'BW';
UPDATE llx_c_country SET phone_code = 55 WHERE code = 'BR';
UPDATE llx_c_country SET phone_code = 246 WHERE code = 'IO';
UPDATE llx_c_country SET phone_code = 673 WHERE code = 'BN';
UPDATE llx_c_country SET phone_code = 359 WHERE code = 'BG';
UPDATE llx_c_country SET phone_code = 226 WHERE code = 'BF';
UPDATE llx_c_country SET phone_code = 257 WHERE code = 'BI';
UPDATE llx_c_country SET phone_code = 855 WHERE code = 'KH';
UPDATE llx_c_country SET phone_code = 238 WHERE code = 'CV';
UPDATE llx_c_country SET phone_code = 1345 WHERE code = 'KY';
UPDATE llx_c_country SET phone_code = 236 WHERE code = 'CF';
UPDATE llx_c_country SET phone_code = 235 WHERE code = 'TD';
UPDATE llx_c_country SET phone_code = 56 WHERE code = 'CL';
UPDATE llx_c_country SET phone_code = 61 WHERE code = 'CX';
UPDATE llx_c_country SET phone_code = 61 WHERE code = 'CC';
UPDATE llx_c_country SET phone_code = 57 WHERE code = 'CO';
UPDATE llx_c_country SET phone_code = 269 WHERE code = 'KM';
UPDATE llx_c_country SET phone_code = 242 WHERE code = 'CG';
UPDATE llx_c_country SET phone_code = 243 WHERE code = 'CD';
UPDATE llx_c_country SET phone_code = 682 WHERE code = 'CK';
UPDATE llx_c_country SET phone_code = 506 WHERE code = 'CR';
UPDATE llx_c_country SET phone_code = 385 WHERE code = 'HR';
UPDATE llx_c_country SET phone_code = 53 WHERE code = 'CU';
UPDATE llx_c_country SET phone_code = 357 WHERE code = 'CY';
UPDATE llx_c_country SET phone_code = 420 WHERE code = 'CZ';
UPDATE llx_c_country SET phone_code = 45 WHERE code = 'DK';
UPDATE llx_c_country SET phone_code = 253 WHERE code = 'DJ';
UPDATE llx_c_country SET phone_code = 1767 WHERE code = 'DM';
UPDATE llx_c_country SET phone_code = 1809 WHERE code = 'DO';
UPDATE llx_c_country SET phone_code = 593 WHERE code = 'EC';
UPDATE llx_c_country SET phone_code = 20 WHERE code = 'EG';
UPDATE llx_c_country SET phone_code = 503 WHERE code = 'SV';
UPDATE llx_c_country SET phone_code = 240 WHERE code = 'GQ';
UPDATE llx_c_country SET phone_code = 291 WHERE code = 'ER';
UPDATE llx_c_country SET phone_code = 372 WHERE code = 'EE';
UPDATE llx_c_country SET phone_code = 251 WHERE code = 'ET';
UPDATE llx_c_country SET phone_code = 500 WHERE code = 'FK';
UPDATE llx_c_country SET phone_code = 298 WHERE code = 'FO';
UPDATE llx_c_country SET phone_code = 679 WHERE code = 'FJ';
UPDATE llx_c_country SET phone_code = 358 WHERE code = 'FI';
UPDATE llx_c_country SET phone_code = 594 WHERE code = 'GF';
UPDATE llx_c_country SET phone_code = 689 WHERE code = 'PF';
UPDATE llx_c_country SET phone_code = 220 WHERE code = 'GM';
UPDATE llx_c_country SET phone_code = 995 WHERE code = 'GE';
UPDATE llx_c_country SET phone_code = 233 WHERE code = 'GH';
UPDATE llx_c_country SET phone_code = 350 WHERE code = 'GI';
UPDATE llx_c_country SET phone_code = 30 WHERE code = 'GR';
UPDATE llx_c_country SET phone_code = 299 WHERE code = 'GL';
UPDATE llx_c_country SET phone_code = 1473 WHERE code = 'GD';
UPDATE llx_c_country SET phone_code = 1671 WHERE code = 'GU';
UPDATE llx_c_country SET phone_code = 502 WHERE code = 'GT';
UPDATE llx_c_country SET phone_code = 224 WHERE code = 'GN';
UPDATE llx_c_country SET phone_code = 245 WHERE code = 'GW';
UPDATE llx_c_country SET phone_code = 509 WHERE code = 'HT';
UPDATE llx_c_country SET phone_code = 379 WHERE code = 'VA';
UPDATE llx_c_country SET phone_code = 504 WHERE code = 'HN';
UPDATE llx_c_country SET phone_code = 852 WHERE code = 'HK';
UPDATE llx_c_country SET phone_code = 354 WHERE code = 'IS';
UPDATE llx_c_country SET phone_code = 91 WHERE code = 'IN';
UPDATE llx_c_country SET phone_code = 62 WHERE code = 'ID';
UPDATE llx_c_country SET phone_code = 98 WHERE code = 'IR';
UPDATE llx_c_country SET phone_code = 964 WHERE code = 'IQ';
UPDATE llx_c_country SET phone_code = 972 WHERE code = 'IL';
UPDATE llx_c_country SET phone_code = 1876 WHERE code = 'JM';
UPDATE llx_c_country SET phone_code = 81 WHERE code = 'JP';
UPDATE llx_c_country SET phone_code = 962 WHERE code = 'JO';
UPDATE llx_c_country SET phone_code = 7 WHERE code = 'KZ';
UPDATE llx_c_country SET phone_code = 254 WHERE code = 'KE';
UPDATE llx_c_country SET phone_code = 686 WHERE code = 'KI';
UPDATE llx_c_country SET phone_code = 850 WHERE code = 'KP';
UPDATE llx_c_country SET phone_code = 82 WHERE code = 'KR';
UPDATE llx_c_country SET phone_code = 965 WHERE code = 'KW';
UPDATE llx_c_country SET phone_code = 996 WHERE code = 'KG';
UPDATE llx_c_country SET phone_code = 856 WHERE code = 'LA';
UPDATE llx_c_country SET phone_code = 371 WHERE code = 'LV';
UPDATE llx_c_country SET phone_code = 961 WHERE code = 'LB';
UPDATE llx_c_country SET phone_code = 266 WHERE code = 'LS';
UPDATE llx_c_country SET phone_code = 231 WHERE code = 'LR';
UPDATE llx_c_country SET phone_code = 218 WHERE code = 'LY';
UPDATE llx_c_country SET phone_code = 423 WHERE code = 'LI';
UPDATE llx_c_country SET phone_code = 370 WHERE code = 'LT';
UPDATE llx_c_country SET phone_code = 352 WHERE code = 'LU';
UPDATE llx_c_country SET phone_code = 853 WHERE code = 'MO';
UPDATE llx_c_country SET phone_code = 389 WHERE code = 'MK';
UPDATE llx_c_country SET phone_code = 261 WHERE code = 'MG';
UPDATE llx_c_country SET phone_code = 265 WHERE code = 'GH';
UPDATE llx_c_country SET phone_code = 350 WHERE code = 'GI';
UPDATE llx_c_country SET phone_code = 30 WHERE code = 'MW';
UPDATE llx_c_country SET phone_code = 60 WHERE code = 'MY';
UPDATE llx_c_country SET phone_code = 960 WHERE code = 'MV';
UPDATE llx_c_country SET phone_code = 223 WHERE code = 'ML';
UPDATE llx_c_country SET phone_code = 356 WHERE code = 'MT';
UPDATE llx_c_country SET phone_code = 692 WHERE code = 'MH';
UPDATE llx_c_country SET phone_code = 222 WHERE code = 'MR';
UPDATE llx_c_country SET phone_code = 230 WHERE code = 'MU';
UPDATE llx_c_country SET phone_code = 262 WHERE code = 'YT';
UPDATE llx_c_country SET phone_code = 52 WHERE code = 'MX';
UPDATE llx_c_country SET phone_code = 691 WHERE code = 'FM';
UPDATE llx_c_country SET phone_code = 373 WHERE code = 'MD';
UPDATE llx_c_country SET phone_code = 976 WHERE code = 'MN';
UPDATE llx_c_country SET phone_code = 1664 WHERE code = 'MS';
UPDATE llx_c_country SET phone_code = 258 WHERE code = 'MZ';
UPDATE llx_c_country SET phone_code = 95 WHERE code = 'MM';
UPDATE llx_c_country SET phone_code = 264 WHERE code = 'NA';
UPDATE llx_c_country SET phone_code = 674 WHERE code = 'NR';
UPDATE llx_c_country SET phone_code = 977 WHERE code = 'NP';
UPDATE llx_c_country SET phone_code = 599 WHERE code = 'CW';
UPDATE llx_c_country SET phone_code = 1721 WHERE code = 'SX';
UPDATE llx_c_country SET phone_code = 687 WHERE code = 'NC';
UPDATE llx_c_country SET phone_code = 64 WHERE code = 'NZ';
UPDATE llx_c_country SET phone_code = 505 WHERE code = 'NI';
UPDATE llx_c_country SET phone_code = 227 WHERE code = 'NE';
UPDATE llx_c_country SET phone_code = 234 WHERE code = 'NG';
UPDATE llx_c_country SET phone_code = 683 WHERE code = 'NU';
UPDATE llx_c_country SET phone_code = 672 WHERE code = 'NF';
UPDATE llx_c_country SET phone_code = 1670 WHERE code = 'MP';
UPDATE llx_c_country SET phone_code = 47 WHERE code = 'NO';
UPDATE llx_c_country SET phone_code = 968 WHERE code = 'OM';
UPDATE llx_c_country SET phone_code = 92 WHERE code = 'PK';
UPDATE llx_c_country SET phone_code = 680 WHERE code = 'PW';
UPDATE llx_c_country SET phone_code = 970 WHERE code = 'PS';
UPDATE llx_c_country SET phone_code = 507 WHERE code = 'PA';
UPDATE llx_c_country SET phone_code = 675 WHERE code = 'PG';
UPDATE llx_c_country SET phone_code = 595 WHERE code = 'PY';
UPDATE llx_c_country SET phone_code = 51 WHERE code = 'PE';
UPDATE llx_c_country SET phone_code = 63 WHERE code = 'PH';
UPDATE llx_c_country SET phone_code = 48 WHERE code = 'PL';
UPDATE llx_c_country SET phone_code = 1787 WHERE code = 'PR';
UPDATE llx_c_country SET phone_code = 974 WHERE code = 'QA';
UPDATE llx_c_country SET phone_code = 40 WHERE code = 'RO';
UPDATE llx_c_country SET phone_code = 250 WHERE code = 'RW';
UPDATE llx_c_country SET phone_code = 290 WHERE code = 'SH';
UPDATE llx_c_country SET phone_code = 1869 WHERE code = 'KN';
UPDATE llx_c_country SET phone_code = 1758 WHERE code = 'LC';
UPDATE llx_c_country SET phone_code = 508 WHERE code = 'PM';
UPDATE llx_c_country SET phone_code = 1784 WHERE code = 'VC';
UPDATE llx_c_country SET phone_code = 685 WHERE code = 'WS';
UPDATE llx_c_country SET phone_code = 378 WHERE code = 'SM';
UPDATE llx_c_country SET phone_code = 239 WHERE code = 'ST';
UPDATE llx_c_country SET phone_code = 381 WHERE code = 'RS';
UPDATE llx_c_country SET phone_code = 248 WHERE code = 'SC';
UPDATE llx_c_country SET phone_code = 232 WHERE code = 'SL';
UPDATE llx_c_country SET phone_code = 421 WHERE code = 'SK';
UPDATE llx_c_country SET phone_code = 386 WHERE code = 'SI';
UPDATE llx_c_country SET phone_code = 677 WHERE code = 'SB';
UPDATE llx_c_country SET phone_code = 252 WHERE code = 'SO';
UPDATE llx_c_country SET phone_code = 27 WHERE code = 'ZA';
UPDATE llx_c_country SET phone_code = 94 WHERE code = 'LK';
UPDATE llx_c_country SET phone_code = 249 WHERE code = 'SD';
UPDATE llx_c_country SET phone_code = 597 WHERE code = 'SR';
UPDATE llx_c_country SET phone_code = 47 WHERE code = 'SJ';
UPDATE llx_c_country SET phone_code = 268 WHERE code = 'SZ';
UPDATE llx_c_country SET phone_code = 963 WHERE code = 'SY';
UPDATE llx_c_country SET phone_code = 886 WHERE code = 'TW';
UPDATE llx_c_country SET phone_code = 992 WHERE code = 'TJ';
UPDATE llx_c_country SET phone_code = 255 WHERE code = 'TZ';
UPDATE llx_c_country SET phone_code = 66 WHERE code = 'TH';
UPDATE llx_c_country SET phone_code = 670 WHERE code = 'TL';
UPDATE llx_c_country SET phone_code = 690 WHERE code = 'TK';
UPDATE llx_c_country SET phone_code = 676 WHERE code = 'TO';
UPDATE llx_c_country SET phone_code = 1868 WHERE code = 'TT';
UPDATE llx_c_country SET phone_code = 90 WHERE code = 'TR';
UPDATE llx_c_country SET phone_code = 993 WHERE code = 'TM';
UPDATE llx_c_country SET phone_code = 1649 WHERE code = 'TC';
UPDATE llx_c_country SET phone_code = 688 WHERE code = 'TV';
UPDATE llx_c_country SET phone_code = 256 WHERE code = 'UG';
UPDATE llx_c_country SET phone_code = 380 WHERE code = 'UA';
UPDATE llx_c_country SET phone_code = 971 WHERE code = 'AE';
UPDATE llx_c_country SET phone_code = 598 WHERE code = 'UY';
UPDATE llx_c_country SET phone_code = 998 WHERE code = 'UZ';
UPDATE llx_c_country SET phone_code = 678 WHERE code = 'VU';
UPDATE llx_c_country SET phone_code = 58 WHERE code = 'VE';
UPDATE llx_c_country SET phone_code = 84 WHERE code = 'VN';
UPDATE llx_c_country SET phone_code = 1284 WHERE code = 'VG';
UPDATE llx_c_country SET phone_code = 1340 WHERE code = 'VI';
UPDATE llx_c_country SET phone_code = 681 WHERE code = 'WF';
UPDATE llx_c_country SET phone_code = 967 WHERE code = 'YE';
UPDATE llx_c_country SET phone_code = 260 WHERE code = 'ZM';
UPDATE llx_c_country SET phone_code = 263 WHERE code = 'ZW';
UPDATE llx_c_country SET phone_code = 44 WHERE code = 'GG';
UPDATE llx_c_country SET phone_code = 44 WHERE code = 'IM';
UPDATE llx_c_country SET phone_code = 44 WHERE code = 'JE';
UPDATE llx_c_country SET phone_code = 382 WHERE code = 'ME';
UPDATE llx_c_country SET phone_code = 590 WHERE code = 'BL';
UPDATE llx_c_country SET phone_code = 590 WHERE code = 'MF';
UPDATE llx_c_country SET phone_code = 383 WHERE code = 'XK';
-- Add trunk_prefix column to llx_c_country
ALTER TABLE llx_c_country ADD COLUMN trunk_prefix varchar(5);
-- Populate trunk_prefix for countries with trunk prefix '0'
UPDATE llx_c_country SET trunk_prefix = '0' WHERE code IN ('FR','BE','DE','CH','GB','IE','NL','SE','AT','GR','FI','HR','BA','BG','RO','RS','ME','MK','AL','SK','SI','LT','MD','UA','GE','XK','TR','CN','IN','ID','JP','KR','TH','VN','MY','PH','BD','PK','AF','IR','IQ','JO','LB','SA','AE','IL','SY','YE','AM','AZ','KH','LA','MM','NP','LK','TW','MN','KG','UZ','PS','KP','MA','DZ','EG','ZA','NG','GH','KE','ET','TZ','UG','SD','LY','NA','SL','ZM','ZW','ER','CD','AO','EH','AU','NZ','AR','BR','CU','VE','PE','EC','BO','PY','SR','GF','YT','PM','BL','MF','GG','JE','IM','AX');
-- Populate trunk_prefix for post-Soviet countries with trunk prefix '8'
UPDATE llx_c_country SET trunk_prefix = '8' WHERE code IN ('RU','BY','KZ','TJ','TM');
-- Populate trunk_prefix for Hungary with trunk prefix '06'
UPDATE llx_c_country SET trunk_prefix = '06' WHERE code = 'HU';
-- Populate trunk_prefix for NANP countries with trunk prefix '1'
UPDATE llx_c_country SET trunk_prefix = '1' WHERE code IN ('US','CA','PR','VI','GU','AS','MP','JM','BS','BB','AG','DM','GD','KN','LC','VC','TT','DO','AI','BM','VG','KY','MS','TC','SX','MH','FM');
-- Strip formatting sugar from existing phone numbers in llx_socpeople
UPDATE llx_socpeople SET phone = REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(phone, ' ', ''), '-', ''), '.', ''), '(', ''), ')', '') WHERE phone IS NOT NULL AND phone != '';
UPDATE llx_socpeople SET phone_perso = REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(phone_perso, ' ', ''), '-', ''), '.', ''), '(', ''), ')', '') WHERE phone_perso IS NOT NULL AND phone_perso != '';
UPDATE llx_socpeople SET phone_mobile = REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(phone_mobile, ' ', ''), '-', ''), '.', ''), '(', ''), ')', '') WHERE phone_mobile IS NOT NULL AND phone_mobile != '';
UPDATE llx_socpeople SET fax = REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(fax, ' ', ''), '-', ''), '.', ''), '(', ''), ')', '') WHERE fax IS NOT NULL AND fax != '';
-- end of migration

View file

@ -3,6 +3,7 @@
-- Copyright (C) 2004 Laurent Destailleur <eldy@users.sourceforge.net>
-- Copyright (C) 2014 Alexandre Spangaro <aspangaro@open-dsi.fr>
-- Copyright (C) 2022 Juanjo Menent <jmenent@2byte.es>
-- Copyright (C) 2026 Open-Dsi <support@open-dsi.fr>
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
@ -29,5 +30,7 @@ create table llx_c_country
eec tinyint DEFAULT 0 NOT NULL,
sepa tinyint DEFAULT 0 NOT NULL,
active tinyint DEFAULT 1 NOT NULL,
favorite tinyint DEFAULT 0 NOT NULL
favorite tinyint DEFAULT 0 NOT NULL,
phone_code integer,
trunk_prefix varchar(5)
)ENGINE=innodb;

View file

@ -458,6 +458,8 @@ PaymentTermsSupplier=Payment Term - Vendor
PaymentTypeBoth=Payment Type - Customer and Vendor
MulticurrencyUsed=Use Multicurrency
MulticurrencyCurrency=Currency
PhoneCode=Phone code
TrunkPrefix=Trunk prefix
InEEC=Europe (EEC)
RestOfEurope=Rest of Europe (EEC)
OutOfEurope=Out of Europe (EEC)

View file

@ -458,6 +458,8 @@ PaymentTermsSupplier=Conditions de paiement - fournisseur
PaymentTypeBoth=Type de paiement - Client et fournisseur
MulticurrencyUsed=Utiliser plusieurs devises
MulticurrencyCurrency=Devise
PhoneCode=Indicatif tél.
TrunkPrefix=Préfixe trunk
InEEC=Union Européenne (UE)
RestOfEurope=Reste de l'Union Européenne (UE)
OutOfEurope=Hors Union Européenne (UE)