Formatare camp – format telefon – Sugar CRM P3

Configurare noua (How To)

Situatie

SugarCRM are un camp de tip telefon dar acest timp de camp nu permite nici un fel de formatare, numerele vor aparea asa cum au fost inserate (5555555555, 555 555 5555, 555 555 55 55, etc)

Daca dorim formatare de tip +Cod tara (xxx) xxx-xxxx avem mai multe variante.

Varianta3:

Cream un modul pentru upload cu un mic cod php (formatul modululi este disponibil pe sugarcrm.com in sectiunea suport):

<?php
//Test after_retrieve logic hook to format phone numbers from 5555555555 -> (555) 555 5555

class SecondLogicHook {
//Test Logic Function

function contactLogic(&$focus, $event, $arguments) {
//LOGIC GOES HERE
$GLOBALS[‘log’]->info(“You have reached your custom logic hook.”);
if(!empty($focus->contactphone_c)){
$two = $focus->contactphone_c;
preg_match_all(‘/d+/’, $two, $three);
$four = implode(“”,$three[0]);
$five1 = preg_replace(“/^([\+\d]*)(\d{3})(\d{3})(\d{4})$/u”, “$1”,$four);
$five2 = preg_replace(“/^([\+\d]*)(\d{3})(\d{3})(\d{4})$/u”, “($2) $3-$4”,$four);
if ($five1 != “”) {
$six = “+”.$five1.” “.$five2;
} else {
$six = “+1 “.$five2;
}
$focus->contactphone_c = $six;
}
if(!empty($focus->assistant_phone)){
$two = $focus->assistant_phone;
preg_match_all(‘/d+/’, $two, $three);
$four = implode(“”,$three[0]);
$five1 = preg_replace(“/^([\+\d]*)(\d{3})(\d{3})(\d{4})$/u”, “$1”,$four);
$five2 = preg_replace(“/^([\+\d]*)(\d{3})(\d{3})(\d{4})$/u”, “($2) $3-$4”,$four);
if ($five1 != “”) {
$six = “+”.$five1.” “.$five2;
} else {
$six = “+1 “.$five2;
}
$focus->assistant_phone = $six;
}
if(!empty($focus->directinwarddialphone_c)){
$two = $focus->directinwarddialphone_c;
preg_match_all(‘/d+/’, $two, $three);
$four = implode(“”,$three[0]);
$five1 = preg_replace(“/^([\+\d]*)(\d{3})(\d{3})(\d{4})$/u”, “$1”,$four);
$five2 = preg_replace(“/^([\+\d]*)(\d{3})(\d{3})(\d{4})$/u”, “($2) $3-$4”,$four);
if ($five1 != “”) {
$six = “+”.$five1.” “.$five2;
} else {
$six = “+1 “.$five2;
}
$focus->directinwarddialphone_c = $six;
}
if(!empty($focus->phone_fax)){
$two = $focus->phone_fax;
preg_match_all(‘/d+/’, $two, $three);
$four = implode(“”,$three[0]);
$five1 = preg_replace(“/^([\+\d]*)(\d{3})(\d{3})(\d{4})$/u”, “$1”,$four);
$five2 = preg_replace(“/^([\+\d]*)(\d{3})(\d{3})(\d{4})$/u”, “($2) $3-$4”,$four);
if ($five1 != “”) {
$six = “+”.$five1.” “.$five2;
} else {
$six = “+1 “.$five2;
}
$focus->phone_fax = $six;
}
if(!empty($focus->phone_home)){
$two = $focus->phone_home;
preg_match_all(‘/d+/’, $two, $three);
$four = implode(“”,$three[0]);
$five1 = preg_replace(“/^([\+\d]*)(\d{3})(\d{3})(\d{4})$/u”, “$1”,$four);
$five2 = preg_replace(“/^([\+\d]*)(\d{3})(\d{3})(\d{4})$/u”, “($2) $3-$4”,$four);
if ($five1 != “”) {
$six = “+”.$five1.” “.$five2;
} else {
$six = “+1 “.$five2;
}
$focus->phone_home = $six;
}
if(!empty($focus->phone_mobile)){
$two = $focus->phone_mobile;
preg_match_all(‘/d+/’, $two, $three);
$four = implode(“”,$three[0]);
$five1 = preg_replace(“/^([\+\d]*)(\d{3})(\d{3})(\d{4})$/u”, “$1”,$four);
$five2 = preg_replace(“/^([\+\d]*)(\d{3})(\d{3})(\d{4})$/u”, “($2) $3-$4”,$four);
if ($five1 != “”) {
$six = “+”.$five1.” “.$five2;
} else {
$six = “+1 “.$five2;
}
$focus->phone_mobile = $six;
}
if(!empty($focus->phone_other)){
$two = $focus->phone_other;
preg_match_all(‘/d+/’, $two, $three);
$four = implode(“”,$three[0]);
$five1 = preg_replace(“/^([\+\d]*)(\d{3})(\d{3})(\d{4})$/u”, “$1”,$four);
$five2 = preg_replace(“/^([\+\d]*)(\d{3})(\d{3})(\d{4})$/u”, “($2) $3-$4”,$four);
if ($five1 != “”) {
$six = “+”.$five1.” “.$five2;
} else {
$six = “+1 “.$five2;
}
$focus->phone_other = $six;
}
if(!empty($focus->phone_work)){
$two = $focus->phone_work;
preg_match_all(‘/d+/’, $two, $three);
$four = implode(“”,$three[0]);
$five1 = preg_replace(“/^([\+\d]*)(\d{3})(\d{3})(\d{4})$/u”, “$1”,$four);
$five2 = preg_replace(“/^([\+\d]*)(\d{3})(\d{3})(\d{4})$/u”, “($2) $3-$4”,$four);
if ($five1 != “”) {
$six = “+”.$five1.” “.$five2;
} else {
$six = “+1 “.$five2;
}
$focus->phone_work = $six;
}
}
}
?>

 

Modulul complet (manifest si cale + fisier php) se salveaza in format .zip si se adauga prin functa module loader.

Daca aveti sandbox sau aceeasi instanta pusa pe un server virtual este recomandat testarea modulului inainte de a aplicarea acestuia in mediul de productie.

 

Nota: Campurile de mai sus sunt denumite asa cum systemul le denumeste default, daca lucrati in campuri custom trebuie sa scrieti denumirea din campul field name si nu field label.

Solutie

Tip solutie

Permanent

Voteaza

(17 din 26 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?