36 $phone = trim((
string) $phone);
38 return array(
'code' =>
'',
'number' =>
'');
41 if (strpos($phone,
'+') === 0) {
42 $pos = strpos($phone,
' ');
45 'code' => substr($phone, 0, $pos),
46 'number' => substr($phone, $pos + 1)
50 return array(
'code' =>
'',
'number' => $phone);
53 return array(
'code' =>
'',
'number' => $phone);
71 $number = preg_replace(
'/[\s\-\.\(\)]/',
'', trim((
string) $number));
72 $code = trim((
string) $code);
80 $sql =
"SELECT trunk_prefix FROM ".$db->prefix().
"c_country";
81 $sql .=
" WHERE phone_code = ".((int) ltrim($code,
'+'));
82 $sql .=
" AND trunk_prefix IS NOT NULL AND trunk_prefix != ''";
84 $resql = $db->query($sql);
86 $obj = $db->fetch_object($resql);
87 if ($obj && isset($obj->trunk_prefix) && $obj->trunk_prefix !==
'' && $obj->trunk_prefix !==
null) {
88 $prefix = $obj->trunk_prefix;
89 if (strpos($number, $prefix) === 0) {
90 $number = substr($number, strlen($prefix));
98 return $code.
' '.$number;
113 $phone_code = trim((
string) $phone_code);
114 if ($phone_code ===
'') {
118 $sql =
"SELECT trunk_prefix FROM ".$db->prefix().
"c_country";
119 $sql .=
" WHERE phone_code = ".((int) ltrim($phone_code,
'+'));
120 $sql .=
" AND trunk_prefix IS NOT NULL AND trunk_prefix != ''";
122 $resql = $db->query($sql);
124 $obj = $db->fetch_object($resql);
125 if ($obj && isset($obj->trunk_prefix) && $obj->trunk_prefix !==
'' && $obj->trunk_prefix !==
null) {
127 return $obj->trunk_prefix;
143 static $cache =
null;
144 if ($cache !==
null) {
149 $sql =
"SELECT DISTINCT trunk_prefix FROM ".$db->prefix().
"c_country";
150 $sql .=
" WHERE trunk_prefix IS NOT NULL AND trunk_prefix != ''";
151 $resql = $db->query($sql);
153 while ($obj = $db->fetch_object($resql)) {
154 $cache[] = $obj->trunk_prefix;
175 $value = trim((
string) $value);
180 $stripped = preg_replace(
'/[\s\-\.\(\)]/',
'', $value);
182 $candidates = array($stripped);
183 if (strpos($stripped,
'+') !== 0) {
185 if ($prefix !==
'' && strpos($stripped, $prefix) === 0) {
186 $candidates[] = substr($stripped, strlen($prefix));
191 $candidates = array_values(array_unique(array_filter($candidates,
function (
string $c) {
194 if (empty($candidates)) {
195 $candidates = array($value);
198 return natural_search($fields, implode(
'|', $candidates), 0, $nofirstand);
210 $country_id = (int) $country_id;
211 if ($country_id <= 0) {
215 $sql =
"SELECT phone_code FROM ".$db->prefix().
"c_country WHERE rowid = ".((int) $country_id);
216 $resql = $db->query($sql);
218 $obj = $db->fetch_object($resql);
219 if ($obj && !empty($obj->phone_code)) {
221 return '+'.$obj->phone_code;
natural_search($fields, $value, $mode=0, $nofirstand=0, $sqltoadd='')
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
dol_get_trunk_prefix($db, $phone_code)
Get the national trunk prefix for a phone code.
dol_get_all_trunk_prefixes($db)
Get the list of all distinct national trunk prefixes known in llx_c_country.
dol_build_phone($db, $code, $number)
Build a normalized phone string from code and number parts.
dol_natural_search_phone($db, $fields, $value, $nofirstand=0)
Build a natural_search() SQL fragment for a phone/fax field, tolerant of the international storage fo...
dol_parse_phone($phone)
Parse a stored phone number into country code and number parts.
dol_get_phone_code_from_country($db, $country_id)
Get the phone calling code for a country.