<?php		//Call queues
include 'functions.php'; 
include 'func1.php'; 

//---------------------------------------------------------------------------
//	static variables
//	Qnam	array of queue names		count=Qnam_c	counter= $x
//	Qnum	array of queue numbers		count=Qnum_c	counter= $y
//	Qext	array of queue extensions	count=Qext_c	counter= 
//	Qper	array of peers

// --- start queue header list----------
$Qnam=v_queue_names();
	$Qnam_c=count($Qnam);
	// display Queues
	for($x=0;$x<$Qnam_c;$x++)
		{
		$t1=explode("!",$Qnam[$x]);
		$qq=iv_queuelist($t1[0]);
		echo $qq."\n";
		}
	echo "\n\n";
// --- end queue header list -----------

// --- start extensions listing --------
	for($x=0;$x<$Qnam_c;$x++)
		{	
		$t1=explode('!',$Qnam[$x]);
		$qe=v_queue_ext($t1[0]);
		$co=count($qe);
		for($y=0;$y<$co;$y++)
			{
			echo $qe[$y]."\n";
			}
		}
// --- end extensions listing ---------

// --- start calls in queue -----------
        echo "\n\nQueue \n";
	$a=v_queue_ring(); 
	echo "\n"; 
	$ac=count($a); 
	if($ac>=0)	
		{ 
		for($x=0;$x<$ac;$x++) 
			{ 
			echo $a[$x]."\n"; 
			} 
		} 
	echo "\n\n";
// --- end calls in queue -----------

// --- start outbound       -----------
        echo "Outbound \n";
        $ob=v_outbound();
        $co=count($ob);
        if($co>=0)
                {
                for($x=0;$x<$co;$x++)
                        {
                        $ob[$x]=str_replace(':','!',$ob[$x]);
                        echo $ob[$x]."\n";
                        }
                }
        echo "\n\n";
// --- end outbound       -----------

// --- start inbound       -----------
        echo "Inbound \n";
        $ob=v_queue_talk();
        $co=count($ob);
        if($co>=0)
                {
                for($x=0;$x<$co;$x++)
                        {
                        $ob[$x]=str_replace(':','!',$ob[$x]);
                        echo $ob[$x]."\n";
                        }
                }
        echo "\n\n";
// --- end inbound       -----------

// --- start parked       -----------
        echo "Parked \n";
        $ob=v_park();
        $co=count($ob);
        if($co>=0)
                {
                for($x=0;$x<$co;$x++)
                        {
                        $ob[$x]=str_replace(':','!',$ob[$x]);
                        echo $ob[$x]."\n";
                        }
                }
        echo "\n\n";
// --- end parked       -----------
function
iv_queuelist($q)
        {
        // get queue names
        $site='';
        $cmd1="/usr/bin/cat /var/www/html/pear/etc/qnames";
        $cmd1.="| grep : | grep -i -v duress";
        exec($cmd1,$Qnam);
        $Qcount=count($Qnam);
        for($x=0;$x<$Qcount;$x++)
                {
                $t1=explode(":",$Qnam[$x]);
                if($t1[0]==$q)
                        {
                        $cmd='';$Qnbr='';
                        $cmd="/usr/sbin/asterisk -rx 'queue show ".$q."'";
                        exec($cmd,$Qnbr);
                        $Qnbrcount=count($Qnbr);
                        $d=0;$c=0;$agent=array();$agent_count=0;
                        $y=0;
                        $Q1=$Qnbr[$y];
                        $queue_header='';
                        $Q1=str_replace(" has ",":".$t1[1].":current=:",$Q1);   //current calls
                        $Q1=str_replace(" calls (max unlimited) in ",':',$Q1);
                        $Q1=str_replace("'ringall' strategy (",'',$Q1);
                        $Q1=str_replace("), W",'',$Q1);
                        $Q1=str_replace(" within 60s",'',$Q1);
                        $Q1=str_replace(", SL",':SL=',$Q1);
                        $Q1=str_replace(", A",':lost=',$Q1);
                        $Q1=str_replace(", C",':answered=',$Q1);
                        $Q1=str_replace("s holdtime, ",':=holdtime:',$Q1);
                        $Q1=str_replace("s talktime",':=talktime:weight=',$Q1);
                        $t2=explode(":",$Q1);
                        $Q1=$t2[0].'!'.$t2[1]."!";              // queue!Queuename
                        $Q1.=$t2[3].'!';                        // current calls
                        $Q1.=$t2[4].'!';                        // average hold
                        $Q1.=$t2[6].'!';                        // average talk
                        $Q1.=$t2[11].'!';                       // answered calls
                        $Q1.=$t2[13].'!';                       // lost calls
                        $Q1.=$t2[15].'!';                       // service level
			$Q1.=v_queue_time($q).'!';		// time oldest queue
                        }
                }
        //      queue!name!waiting!av-hold!av-talk!answered!lost!SL!time
        return $Q1;
        }
// -----------------------------------------------------------------------------------------------

