5 use String::ShellQuote;
7 use SL::MoreCommon qw(uri_encode);
10 my ($class, %params) = @_;
12 my $config = $::lx_office_conf{cti} || {};
13 my $command = $config->{dial_command} || die $::locale->text('Dial command missing in kivitendo configuration\'s [cti] section');
14 my $external_prefix = $params{internal} ? '' : ($config->{external_prefix} // '');
17 phone_extension => $::myconfig{phone_extension} || die($::locale->text('Phone extension missing in user configuration')),
18 phone_password => $::myconfig{phone_password} || die($::locale->text('Phone password missing in user configuration')),
19 number => $external_prefix . $class->sanitize_number(%params),
22 foreach my $key (keys %command_args) {
23 my $value = shell_quote($command_args{$key});
24 $command =~ s{<\% ${key} \%>}{$value}gx;
31 my ($class, %params) = @_;
33 return "controller.pl?action=CTI/call&number=" . uri_encode($class->sanitize_number(number => $params{number})) . ($params{internal} ? '&internal=1' : '');
37 my ($class, %params) = @_;
39 my $config = $::lx_office_conf{cti} || {};
40 my $idp = $config->{international_dialing_prefix} // '00';
42 my $number = $params{number} // '';
43 $number =~ s/[^0-9+\.-]//g; # delete unsupported characters
44 my $countrycode = $number =~ s/^(?: $idp | \+ ) ( \d{2} )//x ? $1 : ''; # TODO: countrycodes can have more or less than 2 digits
45 $number =~ s/^0//x if $countrycode; # kill non standard optional zero after global identifier
47 return '' unless $number;
49 return ($countrycode ? $idp . $countrycode : '') . $number;