Kqueue.php 7.85 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 userToMobileAgent($usermobile, $dialline)
	{
		//if($sipid->confup==0)//call anyway hopefully this will get rejected if in call
		{
			$odata = array();
			$odata['VARS'] = array();
			$odata['fromext'] =  "Local/" . $usermobile->number . "@BuzzMAgents";
			$odata['context'] = "kstychDialer";
			$odata['callerid'] = $usermobile->number;
			$odata['toext'] = "1003" . $usermobile->number; #Without Mixmonitor to avoid recording for mobile agent call.
			$odata['account'] = 'm|m|' . $usermobile->id . '|' . $dialline->id;
			$odata['VARS']['dialstr'] = $dialline->dialstr;
			$this->type = "SIP_" . $usermobile->server;
			$this->key = "originate";
			$this->status = "New";
			$this->data = json_encode($odata);
			$this->save();
		}
	}
	public function custToMagentConf($usernumber, $crmcall, $dialer_did, $dialline)
	{
		//custToConfpstn($usernumber, $crmcall, $dialer_did, $dialline)
		$odata = array();
		$odata['VARS'] = array();
		$odata['fromext'] =  "Local/1004" . $usernumber->number . "@kstychDialer";
		$odata['context'] = "kstychDialer";
		$odata['callerid'] = $dialer_did;
		$odata['toext'] = "1002" . $crmcall->number;
		$odata['account'] = 'm|mc|' . $crmcall->id . '|' . $usernumber->id;
		$odata['VARS']['dialstr'] = $dialline->dialstr;
		$odata['VARS']['dchannel'] = $usernumber->channel;

		//originate conf
		$this->type = "SIP_" . $dialline->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 . '|' . $dialline->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 voiceBlasterCallOut($callnumber, $callerid, $crmcall, $dialline)
	{

		$dialstr = $dialline->dialstr;
		$server = $dialline->server;

		if ($server != '') {
			$odata = array();
			$odata['VARS'] = array();
			$odata['fromext'] = "Local/$callnumber@voiceBlasterINB";
			$odata['context'] = "kstychDialer";
			$odata['callerid'] = $callerid;
			$odata['toext'] = "1002" . $callnumber;
			$odata['account'] = 'm|v|' . $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 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)
	{
		if ($sipid->server != "") {
			$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();
	}
}