Kqueue.php 8.27 KB
<?php namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Log;

class Kqueue extends Model{

	protected $table = 'kqueues';

	//protected $fillable = array('status','data','log','group');

	public function userToConf($sipid)
	{
		//if($sipid->confup==0)//call anyway hopefully this will get rejected if in call
		{
			$odata=array();$odata['VARS']=array();
			$odata['fromext']="Local/1000".$sipid->id."@kstychDialer";
			$odata['context']="kstychDialer";
			$odata['callerid']="1000".$sipid->id;
			$odata['toext']="1001".$sipid->id;
			$odata['account']='m|u|'.$sipid->id;

			//originate conf
			$this->type="SIP_".$sipid->server;
			$this->key="originate";
			$this->status="New";
			$this->data=json_encode($odata);
			
			$this->save();
		}
	}
	public function custToConf($sipid,$callnumber,$callerid,$crmcall,$dialline)
	{
		$odata=array();$odata['VARS']=array();
		$odata['fromext']="Local/1000".$sipid->id."@kstychDialer";
		$odata['context']="kstychDialer";
		$odata['callerid']=$callerid;
		$odata['toext']="1002".$callnumber;
		$odata['account']='m|c|'.$crmcall->id;
		$odata['VARS']['dialstr']=$dialline->dialstr;

		//originate conf
		$this->type="SIP_".$sipid->server;
		$this->key="originate";
		$this->status="New";
		$this->data=json_encode($odata);
		$this->save();
	}
	public function autoCallOut($callnumber,$callerid,$crmcall,$dialline)
	{
		$dialstr = $dialline->dialstr;
		$server = $dialline->server;

		if($server != '')
		{
		$odata=array();$odata['VARS']=array();
		$odata['fromext']="Local/$callnumber@kstychDialerINB";
		$odata['context']="kstychDialer";
		$odata['callerid']=$callerid;
		$odata['toext']="1002".$callnumber;
		$odata['account']='m|a|'.$crmcall->id;
		$odata['VARS']['dialstr']=$dialstr;

		//originate conf
		$this->type="SIP_".$server;
		$this->key="originate";
		$this->status="New";
		$this->data=json_encode($odata);
		$this->save();
		}
		
	}
	public function transferCall($sipid,$callnumber,$callerid,$crmcall,$dialline)
	{
		$dialstr = $dialline->dialstr;
		$server = $dialline->server;
		$channel = $dialline->channel;

		if($server != '')
		{
		$odata=array();$odata['VARS']=array();
		/*$odata['fromext']="Local/1000".$sipid->id."@kstychDialer";
		$odata['context']="initiateTransfer";
		$odata['callerid']=$channel;
		$odata['toext']="1003".$callnumber;
		$odata['account']='m|t|'.$crmcall->id;
		$odata['VARS']['dialstr']=$dialstr;
		$odata['VARS']['chnl']=$channel;
		$odata['VARS']['callnumber']=$callnumber;*/

		$odata['channel']=$channel;
		$odata['exten']="1003".$callnumber;
		$odata['context']="initiateTransfer";
		$odata['priority']=1;


		//originate conf
		$this->type="SIP_".$server;
		$this->key="transfer";
		$this->status="New";
		$this->data=json_encode($odata);
		$this->save();
		}
		
	}
	public function sipOriginate($sipid,$to,$context)
	{
		$odata=array();$odata['VARS']=array();
		$odata['fromext']="SIP/".$sipid->id;
		$odata['context']=$context;
		$odata['callerid']="";
		$odata['toext']=$to;
		$odata['account']='';

		//originate conf
		$this->type="SIP_".$sipid->server;
		$this->key="originate";
		$this->status="New";
		$this->data=json_encode($odata);
		$this->save();
	}
	public function channelRedirectToExten($server,$channel,$exten,$context,$priority)
	{
		$odata=array();$odata['VARS']=array();
		$odata['channel']=$channel;
		$odata['exten']=$exten;
		$odata['context']=$context;
		$odata['priority']=$priority;

		//redirect to conf
		$this->type="SIP_".$server;
		$this->key="redirectchannel";
		$this->status="New";
		$this->data=json_encode($odata);
		$this->save();
	}
	public function sipNotify($sipid,$var1,$var2,$var3,$var4)
	{
		$this->type="SIP_".$sipid->server;
		$this->key="notify";
		$this->status="New";
		$this->data=json_encode(array($sipid->id,$var1,base64_encode($var2),base64_encode($var3),$var4));
		$this->save();
	}
	public function recordChannel($server,$channel,$recfile)
	{
		//start recording
		$this->type="SIP_".$server;
		$this->key="recordchannel";
		$this->status="New";
		$this->data=json_encode(array('channel'=>$channel,'filepath'=>$recfile));
		$this->save();
	}
	public function hangupChannel($dialline)
	{
		$this->hangupChannelS($dialline->channel,$dialline->server);
	}
	public function hangupChannelS($channel,$server)
	{
		$odata=array();$odata['VARS']=array();
		$odata['channel']=$channel;
					
		$this->type="SIP_".$server;
		$this->key="hangupchannel";
		$this->status="New";
		$this->data=json_encode($odata);
		$this->save();
	}
	public function channelMuteMic($channel,$server)
	{
		$odata=array();$odata['VARS']=array();
		$odata['channel']=$channel;

		$this->type="SIP_".$server;
		$this->key="channelmutemic";
		$this->status="New";
		$this->data=json_encode($odata);
		$this->save();
	}
	public function channelMuteSpeaker($channel,$server)
	{
		$odata=array();$odata['VARS']=array();
		$odata['channel']=$channel;

		$this->type="SIP_".$server;
		$this->key="channelmutespeaker";
		$this->status="New";
		$this->data=json_encode($odata);
		$this->save();
	}
	public function channelUnMuteMic($channel,$server)
	{
		$odata=array();$odata['VARS']=array();
		$odata['channel']=$channel;

		$this->type="SIP_".$server;
		$this->key="channelunmutemic";
		$this->status="New";
		$this->data=json_encode($odata);
		$this->save();
	}
	public function channelUnMuteSpeaker($channel,$server)
	{
		$odata=array();$odata['VARS']=array();
		$odata['channel']=$channel;

		$this->type="SIP_".$server;
		$this->key="channelunmutespeaker";
		$this->status="New";
		$this->data=json_encode($odata);
		$this->save();
	}
	public function astCommand($server,$cmd)
	{
		$odata=array();$odata['VARS']=array();
		$odata['command']=$cmd;

		$this->type="SIP_".$server;
		$this->key="astcommand";
		$this->status="New";
		$this->data=json_encode($odata);
		$this->save();
	}
	public function playfile($filepath,$confname,$context,$server)
	{
		$odata=array();$odata['VARS']=array();
		$odata['fromext']="Local/1@$context";
		$odata['context']="kstychPlayFile";
		$odata['callerid']="";
		$odata['toext']="1001";
		$odata['account']="";
		$odata['VARS']['confname']=$confname;
		$odata['VARS']['playfile']=$filepath;

		//originate conf
		$this->type="SIP_".$server;
		$this->key="originate";
		$this->status="New";
		$this->data=json_encode($odata);
		$this->save();
	}
	public function callforward($fromext,$server)
	{
		$odata=array();$odata['VARS']=array();
		$odata['fromext']=$fromext;
		$odata['context']="kstychDialerForward";
		$odata['callerid']="";
		$odata['toext']="000056";
		$odata['account']="";

		//originate conf
		$this->type="SIP_".$server;
		$this->key="Redirect";
		$this->status="New";
		$this->data=json_encode($odata);
		$this->save();
	}

	public function playnonworkingfile($fromext,$server)
	{
		$odata=array();$odata['VARS']=array();
		$odata['fromext']=$fromext;
		$odata['context']="kstychPlayNonWorkingFile";
		$odata['callerid']="";
		$odata['toext']="2001";
		$odata['account']="";

		//originate conf
		$this->type="SIP_".$server;
		$this->key="Redirect";
		$this->status="New";
		$this->data=json_encode($odata);
		$this->save();
	}

	public function playbusyfile($fromext,$server)
	{
		$odata=array();$odata['VARS']=array();
		$odata['fromext']=$fromext;
		$odata['context']="kstychPlayFile";
		$odata['callerid']="";
		$odata['toext']="1001";
		$odata['account']="";

		//originate conf
		$this->type="SIP_".$server;
		$this->key="Redirect";
		$this->status="New";
		$this->data=json_encode($odata);
		$this->save();
	}
	public function playabsencefile($fromext,$server)
        {
                $odata=array();$odata['VARS']=array();
                $odata['fromext']=$fromext;
                $odata['context']="kstychAbsFile";
                $odata['callerid']="";
                $odata['toext']="2001";
                $odata['account']="";

                //originate conf
                $this->type="SIP_".$server;
                $this->key="Redirect";
                $this->status="New";
                $this->data=json_encode($odata);
                $this->save();
        }
	public function playafterhrsfile($fromext,$server)
	{
		$odata=array();$odata['VARS']=array();
		$odata['fromext']=$fromext;
		$odata['context']="kstychAfterFile";
		$odata['callerid']="";
		$odata['toext']="3001";
		$odata['account']="";

		//originate conf
		$this->type="SIP_".$server;
		$this->key="Redirect";
		$this->status="New";
		$this->data=json_encode($odata);
		$this->save();
	}
}