| 4185 | | push @return, "$canal=$position|$estado_final|$texto_pos|$unico_id|$canalid"; |
|---|
| 4186 | | push @return, "$canal=$position|setalpha|100|$unico_id|$canalid"; |
|---|
| | 4170 | my @queue_events = recompute_queues_onjoin(\%hash_temporal,$server,$canalid); |
|---|
| | 4171 | foreach my $valor (@queue_events) { |
|---|
| | 4172 | push @return, $valor; |
|---|
| | 4173 | } |
|---|
| | 4174 | } |
|---|
| | 4175 | elsif ( $evento eq "leave" ) { |
|---|
| | 4176 | $canal = "QUEUE/" . $hash_temporal{"Queue"}; |
|---|
| | 4177 | $canal =~ tr/a-z/A-Z/; |
|---|
| | 4178 | $estado_final = "ocupado"; |
|---|
| | 4179 | my $plural = ""; |
|---|
| | 4180 | if ( $hash_temporal{"Count"} > 1 ) { $plural = "s"; } |
|---|
| | 4181 | if ( $hash_temporal{"Count"} == 0 ) { $estado_final = "corto"; } |
|---|
| | 4182 | $texto = "&waitingonqueue," . $hash_temporal{"Count"} . ",$plural&"; |
|---|
| | 4183 | $unico_id = "$canal-$server"; |
|---|
| | 4184 | push @return, "$canal|$estado_final|$texto|$unico_id|$canalid"; |
|---|
| 4189 | | my $tiempo = time(); |
|---|
| 4190 | | if ( defined( $hash_temporal{Wait} ) ) { |
|---|
| 4191 | | $tiempo = $tiempo - $hash_temporal{Wait}; |
|---|
| 4192 | | push @return, "$canal=$position|settimer|$hash_temporal{Wait}\@UP|$unico_id|$canalid"; |
|---|
| 4193 | | } |
|---|
| 4194 | | $cola->{$canalid}{POSITION} = $position; |
|---|
| 4195 | | $cola->{$canalid}{QUEUE} = $canal; |
|---|
| 4196 | | $cola->{$canalid}{CLID} = $qclidnum; |
|---|
| 4197 | | $cola->{$canalid}{CLIDNAME} = $qclidname; |
|---|
| 4198 | | $cola->{$canalid}{SERVER} = $server; |
|---|
| 4199 | | $cola->{$canalid}{TIME} = $tiempo; |
|---|
| 4200 | | |
|---|
| | 4187 | print_sesbot(1); |
|---|
| | 4188 | my @queue_events = recompute_queues_onleave($canalid); |
|---|
| | 4189 | foreach my $valor (@queue_events) { |
|---|
| | 4190 | push @return, $valor; |
|---|
| | 4191 | } |
|---|
| | 4192 | print_sesbot(2); |
|---|
| 4414 | | } |
|---|
| 4415 | | elsif ( $evento eq "leave" ) { |
|---|
| 4416 | | $canal = "QUEUE/" . $hash_temporal{"Queue"}; |
|---|
| 4417 | | $canal =~ tr/a-z/A-Z/; |
|---|
| 4418 | | $estado_final = "ocupado"; |
|---|
| 4419 | | my $plural = ""; |
|---|
| 4420 | | if ( $hash_temporal{"Count"} > 1 ) { $plural = "s"; } |
|---|
| 4421 | | if ( $hash_temporal{"Count"} == 0 ) { $estado_final = "corto"; } |
|---|
| 4422 | | $texto = "&waitingonqueue," . $hash_temporal{"Count"} . ",$plural&"; |
|---|
| 4423 | | $unico_id = "$canal-$server"; |
|---|
| 4424 | | push @return, "$canal|$estado_final|$texto|$unico_id|$canalid"; |
|---|
| 4425 | | $evento = ""; |
|---|
| 4426 | | |
|---|
| 4427 | | print_sesbot(1); |
|---|
| 4428 | | my @queue_events = recompute_queues($canalid); |
|---|
| 4429 | | foreach my $valor (@queue_events) { |
|---|
| 4430 | | push @return, $valor; |
|---|
| 4431 | | } |
|---|
| 4432 | | print_sesbot(2); |
|---|
| 9021 | | sub recompute_queues { |
|---|
| | 8994 | sub recompute_queues_onjoin { |
|---|
| | 8995 | my ($hash_temporal,$server,$canalid) = @_; |
|---|
| | 8996 | my @return = (); |
|---|
| | 8997 | my @corto = (); |
|---|
| | 8998 | my @ocupado = (); |
|---|
| | 8999 | my $qclidnum = ""; |
|---|
| | 9000 | my $qclidname = ""; |
|---|
| | 9001 | |
|---|
| | 9002 | if ( defined( $hash_temporal->{CallerIDName} ) ) { |
|---|
| | 9003 | $qclidnum = $hash_temporal->{CallerID}; |
|---|
| | 9004 | $qclidname = $hash_temporal->{CallerIDName}; |
|---|
| | 9005 | } |
|---|
| | 9006 | elsif ( defined( $hash_temporal->{CalleridName} ) ) { |
|---|
| | 9007 | $qclidnum = $hash_temporal->{Callerid}; |
|---|
| | 9008 | $qclidname = $hash_temporal->{CalleridName}; |
|---|
| | 9009 | } |
|---|
| | 9010 | else { |
|---|
| | 9011 | ( $qclidnum, $qclidname ) = split_callerid( $hash_temporal->{CallerID} ); |
|---|
| | 9012 | } |
|---|
| | 9013 | my $texto_pos = "[$qclidname $qclidnum]"; |
|---|
| | 9014 | |
|---|
| | 9015 | my $canal = "QUEUE/" . $hash_temporal->{Queue}; |
|---|
| | 9016 | my $position = $hash_temporal->{Position}; |
|---|
| | 9017 | $canal =~ tr/a-z/A-Z/; |
|---|
| | 9018 | my $unico_id = "$canal-$server"; |
|---|
| | 9019 | |
|---|
| | 9020 | # Verify if the position is already taken (by means of QUEUE_PRIO) |
|---|
| | 9021 | my $tengo = 0; |
|---|
| | 9022 | foreach my $id ( keys %{$cola} ) { |
|---|
| | 9023 | unless ( $cola->{$id}{QUEUE} ) { |
|---|
| | 9024 | delete( $cola->{$id} ); |
|---|
| | 9025 | next; |
|---|
| | 9026 | } |
|---|
| | 9027 | |
|---|
| | 9028 | if ( $canal eq $cola->{$id}{QUEUE} ) { |
|---|
| | 9029 | if ( $position eq $cola->{$id}{POSITION} ) { |
|---|
| | 9030 | $tengo = 1; |
|---|
| | 9031 | } |
|---|
| | 9032 | } |
|---|
| | 9033 | } |
|---|
| | 9034 | if($tengo==1) { |
|---|
| | 9035 | # Queue prio! |
|---|
| | 9036 | my $time = time(); |
|---|
| | 9037 | foreach my $id ( keys %{$cola} ) { |
|---|
| | 9038 | unless ( $cola->{$id}{QUEUE} ) { |
|---|
| | 9039 | delete( $cola->{$id} ); |
|---|
| | 9040 | next; |
|---|
| | 9041 | } |
|---|
| | 9042 | |
|---|
| | 9043 | if ( $canal eq $cola->{$id}{QUEUE} ) { |
|---|
| | 9044 | if($cola->{$id}{POSITION} >= $position) { |
|---|
| | 9045 | my $diftime = $time - $cola->{$id}{TIME}; |
|---|
| | 9046 | if ( $queue_hide == 1 ) { |
|---|
| | 9047 | push @corto, construct_cmd( $cola, $id, "setalpha", "000" ); |
|---|
| | 9048 | } |
|---|
| | 9049 | push @corto, construct_cmd( $cola, $id, "corto", "" ); |
|---|
| | 9050 | |
|---|
| | 9051 | $cola->{$id}{POSITION}++; |
|---|
| | 9052 | my $clidtext = $cola->{$id}{CLIDNAME} . " " . $cola->{$id}{CLID}; |
|---|
| | 9053 | push @ocupado, construct_cmd( $cola, $id, "settimer", $diftime ); |
|---|
| | 9054 | push @ocupado, construct_cmd( $cola, $id, "ocupado", "[$clidtext]" ); |
|---|
| | 9055 | } |
|---|
| | 9056 | } |
|---|
| | 9057 | } |
|---|
| | 9058 | @ocupado = unique(@ocupado); |
|---|
| | 9059 | @corto = unique(@corto); |
|---|
| | 9060 | } |
|---|
| | 9061 | # Normal, add new call at the end of the queue |
|---|
| | 9062 | push @return, "$canal=$position|ocupado2|$texto_pos|$unico_id|$canalid"; |
|---|
| | 9063 | push @return, "$canal=$position|setalpha|100|$unico_id|$canalid"; |
|---|
| | 9064 | |
|---|
| | 9065 | my $tiempo = time(); |
|---|
| | 9066 | if ( defined( $hash_temporal->{Wait} ) ) { |
|---|
| | 9067 | $tiempo = $tiempo - $hash_temporal->{Wait}; |
|---|
| | 9068 | push @return, "$canal=$position|settimer|".$hash_temporal->{Wait}."\@UP|$unico_id|$canalid"; |
|---|
| | 9069 | } |
|---|
| | 9070 | $cola->{$canalid}{POSITION} = $position; |
|---|
| | 9071 | $cola->{$canalid}{QUEUE} = $canal; |
|---|
| | 9072 | $cola->{$canalid}{CLID} = $qclidnum; |
|---|
| | 9073 | $cola->{$canalid}{CLIDNAME} = $qclidname; |
|---|
| | 9074 | $cola->{$canalid}{SERVER} = $server; |
|---|
| | 9075 | $cola->{$canalid}{TIME} = $tiempo; |
|---|
| | 9076 | if (@corto) { |
|---|
| | 9077 | return ( @corto, @ocupado, @return ); |
|---|
| | 9078 | } else { |
|---|
| | 9079 | return @return; |
|---|
| | 9080 | } |
|---|
| | 9081 | } |
|---|
| | 9082 | |
|---|
| | 9083 | sub recompute_queues_onleave { |
|---|