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   my $config           = $::lx_office_conf{cti} || {};
 
  35   if ($config->{dial_command}) {
 
  36     return "controller.pl?action=CTI/call&number=" . uri_encode($class->sanitize_number(number => $params{number})) . ($params{internal} ? '&internal=1' : '');
 
  38     return 'callto://' . uri_encode($class->sanitize_number(number => $params{number}));
 
  43   my ($class, %params) = @_;
 
  45   my $config           = $::lx_office_conf{cti} || {};
 
  46   my $idp              = $config->{international_dialing_prefix} // '00';
 
  48   my $number           = $params{number} // '';
 
  49   $number              =~ s/[^0-9+]//g;                                        # delete unsupported characters
 
  50   my $countrycode      = $number =~ s/^(?: $idp | \+ ) ( \d{2} )//x ? $1 : ''; # TODO: countrycodes can have more or less than 2 digits
 
  51   $number              =~ s/^0//x if $countrycode;                             # kill non standard optional zero after global identifier
 
  52   $number              =~ s{[^0-9]+}{}g;
 
  54   return '' unless $number;
 
  56   return ($countrycode ? $idp . $countrycode : '') . $number;