4cbac761 by Manish Mihsra

Changed diallines hangup condition and created new function to connect calls in Predictive

1 parent 9c31f85c
...@@ -75,7 +75,8 @@ class KPAMIListen implements IEventListener ...@@ -75,7 +75,8 @@ class KPAMIListen implements IEventListener
75 while(true) 75 while(true)
76 { 76 {
77 usleep(2000*1000); 77 usleep(2000*1000);
78 $this->redirectIncoming(); 78 $this->connectAvailCalls();
79 //$this->redirectIncoming();
79 } 80 }
80 return; 81 return;
81 } 82 }
...@@ -431,11 +432,6 @@ class KPAMIListen implements IEventListener ...@@ -431,11 +432,6 @@ class KPAMIListen implements IEventListener
431 432
432 $cause=$event->getKey("Cause"); 433 $cause=$event->getKey("Cause");
433 $causetxt=$event->getKey("Cause-txt"); 434 $causetxt=$event->getKey("Cause-txt");
434 //Log::info("<<<<<<<<<<<<<<<<<<=====Start");
435 //Log::info("eventname");
436 //Log::info("eventname=====".$eventname);
437 //Log::info("exten=====".$exten);
438 //Log::info("context=====".$context);
439 435
440 if($accountcode!="") 436 if($accountcode!="")
441 { 437 {
...@@ -508,6 +504,31 @@ class KPAMIListen implements IEventListener ...@@ -508,6 +504,31 @@ class KPAMIListen implements IEventListener
508 { 504 {
509 $nowts=microtime(true)*1000; 505 $nowts=microtime(true)*1000;
510 506
507 $dialline=Dialline::find($crmcall->dialline_id);
508
509 if($dialline && ($dialline->channel==$channel || $dialline->status== "AutoCall"))
510 {
511 $dialline->status="Free";
512 $dialline->conf="";
513 $dialline->number="";
514 $dialline->uniqueid="";
515 $dialline->channel="";
516 $dialline->regexstr="";
517 $dialline->did="";
518 $dialline->save();
519
520 $tsip=Sipid::find($crmcall->sipid_id);
521
522 if(!empty($tsip))
523 {
524 $tsip->patched=0;
525 $tsip->save();
526
527 $newqueue=new Kqueue();
528 $newqueue->sipNotify($tsip,"dialerUI","hangup","c",$crmcall->id."~".$crmcall->number."~".base64_encode($channel));
529 }
530 }
531
511 $crmcall->setTs('ts_Recend',$nowts); 532 $crmcall->setTs('ts_Recend',$nowts);
512 533
513 $crmcall->state=$eventname; 534 $crmcall->state=$eventname;
...@@ -567,34 +588,6 @@ class KPAMIListen implements IEventListener ...@@ -567,34 +588,6 @@ class KPAMIListen implements IEventListener
567 } 588 }
568 } 589 }
569 590
570 $dialline=Dialline::find($crmcall->dialline_id);
571
572 if($dialline && ($dialline->channel==$channel || $dialline->status== "AutoCall") )
573 {
574 $dialline->status="Free";
575 $dialline->conf="";
576 $dialline->number="";
577 $dialline->uniqueid="";
578 $dialline->channel="";
579 $dialline->regexstr="";
580 $dialline->did="";
581 $dialline->save();
582
583 $tsip=Sipid::find($crmcall->sipid_id);
584
585 if(!empty($tsip))
586 {
587 $tsip->patched=0;
588 $tsip->save();
589
590 $newqueue=new Kqueue();
591 $newqueue->sipNotify($tsip,"dialerUI","hangup","c",$crmcall->id."~".$crmcall->number."~".base64_encode($channel));
592 }
593
594 //$newqueue=new Kqueue();
595 //$newqueue->sipNotify($tsip,"dialerUI","hangup","c",$crmcall->id."~".$crmcall->number."~".base64_encode($channel));
596 }
597
598 $crmcall->addEventLog($nowts,"$accountcode:HangupEvent : $eventname $channelstate:$channelstatedesc $uniqueid $exten:$priority $channel $cause:$causetxt"); 591 $crmcall->addEventLog($nowts,"$accountcode:HangupEvent : $eventname $channelstate:$channelstatedesc $uniqueid $exten:$priority $channel $cause:$causetxt");
599 592
600 $crmcall->save(); 593 $crmcall->save();
...@@ -1420,19 +1413,18 @@ class KPAMIListen implements IEventListener ...@@ -1420,19 +1413,18 @@ class KPAMIListen implements IEventListener
1420 1413
1421 } 1414 }
1422 1415
1423 1416 private function connectAvailCalls()
1424 private function redirectIncoming()
1425 { 1417 {
1426 $diallines=Dialline::where('server','=',$this->sipip)->whereIn("status",["Inbound","Auto"])->where("conf","=","")->get(); 1418 $diallines=Dialline::where('server','=',$this->sipip)->where("status","=","Auto")->where("conf","=","")->get();
1427 if($diallines) 1419 if($diallines)
1428 { 1420 {
1429 foreach($diallines as $dialline) 1421 foreach($diallines as $dialline)
1430 { 1422 {
1431 $lastUpdatedTime = strtotime(date("Y-m-d H:i:s")) - strtotime($dialline->updated_at); 1423 $lastUpdatedTime = strtotime(date("Y-m-d H:i:s")) - strtotime($dialline->updated_at);
1432 1424
1433 if($lastUpdatedTime < 8) continue; 1425 if($lastUpdatedTime < 5) continue;
1434 1426
1435 exec("/usr/sbin/asterisk -rx 'core show channels'",$allChnnlsArr); 1427 /*exec("/usr/sbin/asterisk -rx 'core show channels'",$allChnnlsArr);
1436 $cnt = 0; 1428 $cnt = 0;
1437 foreach($allChnnlsArr as $allChnnls) 1429 foreach($allChnnlsArr as $allChnnls)
1438 { 1430 {
...@@ -1457,99 +1449,29 @@ class KPAMIListen implements IEventListener ...@@ -1457,99 +1449,29 @@ class KPAMIListen implements IEventListener
1457 $dialline->save(); 1449 $dialline->save();
1458 1450
1459 continue; 1451 continue;
1460 } 1452 }*/
1461 1453
1462 echo $dialline->number." waiting\n";
1463 $crmcall=CRMCall::where("uniqueid","like","%".$dialline->uniqueid."%")->first(); 1454 $crmcall=CRMCall::where("uniqueid","like","%".$dialline->uniqueid."%")->first();
1464 1455
1465 if($crmcall) 1456 if($crmcall)
1466 { 1457 {
1467 echo "Callid : ".$crmcall->id." : $crmcall->did\n";
1468
1469 $nowts=microtime(true)*1000; 1458 $nowts=microtime(true)*1000;
1470 $crmcalldata=json_decode($crmcall->data,true); 1459 $crmcalldata=json_decode($crmcall->data,true);
1471 if(!isset($crmcalldata["userbusyfile"]))$crmcalldata["userbusyfile"]=0; 1460 if(!isset($crmcalldata["userbusyfile"]))$crmcalldata["userbusyfile"]=0;
1472 $playnoroute=env('playnoroute',public_path("assets/sounds/astring"));
1473 $playnoroutelen=env('playnoroutelen',4);
1474 $playnouser=env('playnouser',public_path("assets/sounds/astring"));
1475 $playnouserlen=env('playnouserlen',4);
1476 $playuserbusy=env('playuserbusy',public_path("assets/sounds/astring"));
1477 $playuserbusylen=env('playuserbusylen',4);
1478
1479 if($crmcall->client==".")
1480 {
1481 $wakka = new KHRMSLib();
1482 $users=$wakka->searchPhone("mobile",$crmcall->number);
1483 if(!empty($users))
1484 {
1485 $ppldata=unserialize($users[0]['peopledata']);
1486
1487 $crmcall->crm_id=$users[0]['id'];
1488 $crmcall->number=$users[0]['mobile'];
1489 $crmcall->client=($ppldata['client']?$ppldata['client']:"");
1490 $crmcall->department=($ppldata['department']?$ppldata['department']:"");
1491 $crmcall->call_flag="C";
1492 $wakka->setPersonKey($crmcall->crm_id,"dialer_lastcall",date("Y-m-d H:i:s"));
1493 echo $users[0]['id']." -- ID Found\n";
1494 }
1495 else
1496 {
1497 $crmcall->crm_id=0;
1498 $crmcall->client="";
1499 $crmcall->department="";
1500 $crmcall->call_flag="C";
1501 echo "User Not Found!!\n";
1502 }
1503 $crmcall->save();
1504 }
1505 1461
1506 $sipids=array(); 1462 $sipids=array();
1507 if($crmcall->client!="") 1463
1508 { 1464 $sipids=Sipid::where('server','=',$this->sipip)->where("status","=","1")->where("ready","=","1")->where("prepare_call","=","1")->orderBy("updated_at","desc")->get();
1509 $sipids=Sipid::where('server','=',$this->sipip)->where("status","=","1")->where("clients","like","%".$crmcall->client."%")->where("clients","like","%".$crmcall->did."%")->orderBy("updated_at","desc")->get();
1510 }
1511 else if($crmcall->did!="")
1512 {
1513 $sipids=Sipid::where('server','=',$this->sipip)->where("status","=","1")->where("clients","like","%".$crmcall->did."%")->orderBy("updated_at","desc")->get();
1514 }
1515 else
1516 {
1517 $sipids=Sipid::where('server','=',$this->sipip)->where("status","=","1")->orderBy("updated_at","desc")->get();//send to all?
1518 }
1519 1465
1520 if(!empty($sipids)) 1466 if(!empty($sipids))
1521 { 1467 {
1522 echo "sipids found "; 1468 echo "sipids found ";
1523 1469
1524 //create map?
1525 $first_r=0;$first_w=0;$first_a=0;$allsipids=array(); 1470 $first_r=0;$first_w=0;$first_a=0;$allsipids=array();
1526 foreach($sipids as $sipid)
1527 {
1528 //if($sipid->ready==1)
1529 if($sipid->ready==1&&$sipid->prepare_call==0&&$dialline->status=="Inbound")
1530 {
1531 $clientsarr=json_decode($sipid->clients,true);
1532 if($crmcall->client=="")$first_a=$sipid;
1533 else
1534 {
1535 if($clientsarr['a']!="")$clientaarr = explode(",", $clientsarr['a']);
1536 if(isset($clientsarr['a'])&&in_array($crmcall->client, $clientaarr))$first_a=$sipid;
1537 if($clientsarr['w']!="")$clientwarr = explode(",", $clientsarr['w']);
1538 if(isset($clientsarr['w'])&&in_array($crmcall->client, $clientwarr))$first_w=$sipid;
1539 if($clientsarr['r']!="")$clientrarr = explode(",", $clientsarr['r']);
1540 if(isset($clientsarr['r'])&&in_array($crmcall->client, $clientrarr))$first_r=$sipid;
1541 }
1542 }
1543 else
1544 {
1545 $allsipids[]=$sipid;
1546 }
1547 }
1548 1471
1549 foreach($sipids as $sipid) 1472 foreach($sipids as $sipid)
1550 { 1473 {
1551 if($sipid->ready==1&&$sipid->prepare_call==1&&$dialline->status=="Auto") 1474
1552 {
1553 $clientsarr=json_decode($sipid->clients,true); 1475 $clientsarr=json_decode($sipid->clients,true);
1554 if($crmcall->client=="")$first_a=$sipid; 1476 if($crmcall->client=="")$first_a=$sipid;
1555 else 1477 else
...@@ -1562,11 +1484,6 @@ class KPAMIListen implements IEventListener ...@@ -1562,11 +1484,6 @@ class KPAMIListen implements IEventListener
1562 if(isset($clientsarr['r'])&&in_array($crmcall->client, $clientrarr))$first_r=$sipid; 1484 if(isset($clientsarr['r'])&&in_array($crmcall->client, $clientrarr))$first_r=$sipid;
1563 } 1485 }
1564 } 1486 }
1565 else
1566 {
1567 $allsipids[]=$sipid;
1568 }
1569 }
1570 1487
1571 echo "Notifying Total ::".sizeof($allsipids)."\n"; 1488 echo "Notifying Total ::".sizeof($allsipids)."\n";
1572 1489
...@@ -1577,7 +1494,7 @@ class KPAMIListen implements IEventListener ...@@ -1577,7 +1494,7 @@ class KPAMIListen implements IEventListener
1577 1494
1578 if($found) 1495 if($found)
1579 { 1496 {
1580 $alreadyconf=Dialline::where('server','=',$this->sipip)->where("status","=","Inbound")->where("conf","=","1000".$found->id)->get(); 1497 $alreadyconf=Dialline::where('server','=',$this->sipip)->where("status","=","Auto")->where("conf","=","1000".$found->id)->get();
1581 if(sizeof($alreadyconf)>0) 1498 if(sizeof($alreadyconf)>0)
1582 { 1499 {
1583 echo $found->id." : Found but Already in Conf!!!\n"; 1500 echo $found->id." : Found but Already in Conf!!!\n";
...@@ -1589,7 +1506,48 @@ class KPAMIListen implements IEventListener ...@@ -1589,7 +1506,48 @@ class KPAMIListen implements IEventListener
1589 { 1506 {
1590 echo "sipids : $found->id \n"; 1507 echo "sipids : $found->id \n";
1591 1508
1592 //get ts_Wait 1509 $userEntry = User::find($found->user);
1510
1511 if(!empty($userEntry)){
1512 if($userEntry->current_dialmode != "Predictive" || $found->ready != 1) return;
1513 }
1514
1515 exec("/usr/sbin/asterisk -rx 'core show channels'",$allChnnlsArr);
1516 $cnt = 0;
1517 foreach($allChnnlsArr as $allChnnls)
1518 {
1519 if(stristr($allChnnls, substr(stripslashes($dialline->channel),0, 20)))
1520 {
1521 $cnt++;
1522 }
1523 }
1524
1525 if($cnt == 0)
1526 {
1527 Log::useFiles(storage_path()."/logs/Predictive/predictive_".date("Y_m_d").".log");
1528 Log::info($crmcall->id);Log::info($dialline);
1529
1530 $dialline->status="Free";
1531 $dialline->conf="";
1532 $dialline->number="";
1533 $dialline->uniqueid="";
1534 $dialline->src_channel="";
1535 $dialline->channel="";
1536 $dialline->regexstr="";
1537 $dialline->save();
1538
1539 continue;
1540 }
1541
1542 $dialline->user_id = $found->user;
1543 $dialline->conf = "1000".$found->id;
1544 $dialline->save();
1545
1546 $found->ready=0;
1547 $found->prepare_call=0;
1548 $found->patched=1;
1549 $found->save();
1550
1593 $userlog=UserLog::where('user_id','=',$found->user)->orderBy("id","DESC")->first(); 1551 $userlog=UserLog::where('user_id','=',$found->user)->orderBy("id","DESC")->first();
1594 $ts_Wait=$userlog->getLastTs($found->id,$nowts); 1552 $ts_Wait=$userlog->getLastTs($found->id,$nowts);
1595 $userlog->save(); 1553 $userlog->save();
...@@ -1610,18 +1568,11 @@ class KPAMIListen implements IEventListener ...@@ -1610,18 +1568,11 @@ class KPAMIListen implements IEventListener
1610 1568
1611 $crmcall->save(); 1569 $crmcall->save();
1612 1570
1613 $dialline->user_id = $found->user;
1614 $dialline->conf = "1000".$found->id;
1615 $dialline->save();
1616 1571
1617 if($crmcall->crm_id>0){ 1572 if($crmcall->crm_id>0){
1618 DB::table('records')->where('id',$crmcall->crm_id)->update(['filter_condition'=>'3','usr_id'=>$found->user]); 1573 DB::table('records')->where('id',$crmcall->crm_id)->update(['filter_condition'=>'3','usr_id'=>$found->user]);
1619 1574
1620 } 1575 }
1621 $found->ready=0;
1622 $found->prepare_call=0;
1623 $found->patched=1;
1624 $found->save();
1625 1576
1626 $recfile=$crmcall->newRecFilePath(); 1577 $recfile=$crmcall->newRecFilePath();
1627 1578
...@@ -1633,80 +1584,303 @@ class KPAMIListen implements IEventListener ...@@ -1633,80 +1584,303 @@ class KPAMIListen implements IEventListener
1633 $newqueue->recordChannel($dialline->server,$dialline->channel,$recfile); 1584 $newqueue->recordChannel($dialline->server,$dialline->channel,$recfile);
1634 1585
1635 $newqueue=new Kqueue(); 1586 $newqueue=new Kqueue();
1636 $newqueue->userToConf($found);
1637
1638 $newqueue=new Kqueue();
1639 $newqueue->channelRedirectToExten($found->server,$dialline->channel,"1000".$found->id,"kstychDialer","1"); 1587 $newqueue->channelRedirectToExten($found->server,$dialline->channel,"1000".$found->id,"kstychDialer","1");
1640 1588
1641 //notify UI (only the sip id)
1642 $newqueue=new Kqueue();
1643 $newqueue->sipNotify($found,"dialerUI","dialstart","c",$crmcall->number);
1644
1645 $newqueue=new Kqueue(); 1589 $newqueue=new Kqueue();
1646 $newqueue->sipNotify($found,"incomingCall",$crmcall->id,$crmcall->crm_id,$crmcall->number."@".$dialline->channel); 1590 $newqueue->sipNotify($found,"incomingCall",$crmcall->id,$crmcall->crm_id,$crmcall->number."@".$dialline->channel);
1647 } 1591 }
1648 else
1649 {
1650 if(!empty($allsipids))
1651 {
1652 foreach($allsipids as $tsip)
1653 {
1654 //$newqueue=new Kqueue();
1655 //$newqueue->sipNotify($tsip,"popupalert"," Incoming Calls",$crmcall->number."|".$crmcall->client,"");
1656 if($dialline->status!="Auto")
1657 {
1658 $newqueue=new Kqueue();
1659 $newqueue->sipNotify($tsip,"popupalert"," Incoming Calls",$crmcall->number."|".$crmcall->client,"");
1660 }
1661 }
1662 }
1663 else
1664 {
1665 //play no users available
1666 if($crmcalldata["userbusyfile"]<$nowts)
1667 {
1668 $crmcalldata["userbusyfile"]=$nowts+(($playnouserlen+2)*1000);
1669 $crmcall->data=json_encode($crmcalldata);
1670 $crmcall->save();
1671 }
1672
1673 }
1674 //no ready user, send notifications
1675 }
1676 }
1677 else
1678 {
1679 //no users online
1680 //play no routes file
1681 if($crmcalldata["userbusyfile"]<$nowts)
1682 {
1683 $crmcalldata["userbusyfile"]=$nowts+(($playnoroutelen+2)*1000);
1684 $crmcall->data=json_encode($crmcalldata);
1685 $crmcall->save();
1686
1687 //$newqueue=new Kqueue();
1688 //$newqueue->playfile($playnoroute,$dialline->channel,"kstychDialerINB",$dialline->server);
1689 } 1592 }
1690 } 1593 }
1691
1692 }
1693 else
1694 {
1695 //$dialline->status='Free';
1696 //$dialline->save();
1697 } 1594 }
1698 //if client was matched then find users by client
1699 //else find users by DID
1700 //ele everyone
1701 } 1595 }
1702
1703 } 1596 }
1704 1597
1705 } 1598 // private function redirectIncoming()
1599 // {
1600 // $diallines=Dialline::where('server','=',$this->sipip)->whereIn("status",["Inbound","Auto"])->where("conf","=","")->get();
1601 // if($diallines)
1602 // {
1603 // foreach($diallines as $dialline)
1604 // {
1605 // $lastUpdatedTime = strtotime(date("Y-m-d H:i:s")) - strtotime($dialline->updated_at);
1606
1607 // if($lastUpdatedTime < 8) continue;
1608
1609 // exec("/usr/sbin/asterisk -rx 'core show channels'",$allChnnlsArr);
1610 // $cnt = 0;
1611 // foreach($allChnnlsArr as $allChnnls)
1612 // {
1613 // if(stristr($allChnnls, substr(stripslashes($dialline->channel),0, 20)))
1614 // {
1615 // $cnt++;
1616 // }
1617 // }
1618
1619 // if($cnt == 0)
1620 // {
1621 // Log::useFiles(storage_path()."/logs/Predictive/predictive_".date("Y_m_d").".log");
1622 // Log::info($dialline);
1623
1624 // $dialline->status="Free";
1625 // $dialline->conf="";
1626 // $dialline->number="";
1627 // $dialline->uniqueid="";
1628 // $dialline->src_channel="";
1629 // $dialline->channel="";
1630 // $dialline->regexstr="";
1631 // $dialline->save();
1632
1633 // continue;
1634 // }
1635
1636 // echo $dialline->number." waiting\n";
1637 // $crmcall=CRMCall::where("uniqueid","like","%".$dialline->uniqueid."%")->first();
1638
1639 // if($crmcall)
1640 // {
1641 // echo "Callid : ".$crmcall->id." : $crmcall->did\n";
1642
1643 // $nowts=microtime(true)*1000;
1644 // $crmcalldata=json_decode($crmcall->data,true);
1645 // if(!isset($crmcalldata["userbusyfile"]))$crmcalldata["userbusyfile"]=0;
1646 // $playnoroute=env('playnoroute',public_path("assets/sounds/astring"));
1647 // $playnoroutelen=env('playnoroutelen',4);
1648 // $playnouser=env('playnouser',public_path("assets/sounds/astring"));
1649 // $playnouserlen=env('playnouserlen',4);
1650 // $playuserbusy=env('playuserbusy',public_path("assets/sounds/astring"));
1651 // $playuserbusylen=env('playuserbusylen',4);
1652
1653 // if($crmcall->client==".")
1654 // {
1655 // $wakka = new KHRMSLib();
1656 // $users=$wakka->searchPhone("mobile",$crmcall->number);
1657 // if(!empty($users))
1658 // {
1659 // $ppldata=unserialize($users[0]['peopledata']);
1660
1661 // $crmcall->crm_id=$users[0]['id'];
1662 // $crmcall->number=$users[0]['mobile'];
1663 // $crmcall->client=($ppldata['client']?$ppldata['client']:"");
1664 // $crmcall->department=($ppldata['department']?$ppldata['department']:"");
1665 // $crmcall->call_flag="C";
1666 // $wakka->setPersonKey($crmcall->crm_id,"dialer_lastcall",date("Y-m-d H:i:s"));
1667 // echo $users[0]['id']." -- ID Found\n";
1668 // }
1669 // else
1670 // {
1671 // $crmcall->crm_id=0;
1672 // $crmcall->client="";
1673 // $crmcall->department="";
1674 // $crmcall->call_flag="C";
1675 // echo "User Not Found!!\n";
1676 // }
1677 // $crmcall->save();
1678 // }
1679
1680 // $sipids=array();
1681 // if($crmcall->client!="")
1682 // {
1683 // $sipids=Sipid::where('server','=',$this->sipip)->where("status","=","1")->where("clients","like","%".$crmcall->client."%")->where("clients","like","%".$crmcall->did."%")->orderBy("updated_at","desc")->get();
1684 // }
1685 // else if($crmcall->did!="")
1686 // {
1687 // $sipids=Sipid::where('server','=',$this->sipip)->where("status","=","1")->where("clients","like","%".$crmcall->did."%")->orderBy("updated_at","desc")->get();
1688 // }
1689 // else
1690 // {
1691 // $sipids=Sipid::where('server','=',$this->sipip)->where("status","=","1")->orderBy("updated_at","desc")->get();//send to all?
1692 // }
1693
1694 // if(!empty($sipids))
1695 // {
1696 // echo "sipids found ";
1697
1698 // //create map?
1699 // $first_r=0;$first_w=0;$first_a=0;$allsipids=array();
1700 // foreach($sipids as $sipid)
1701 // {
1702 // //if($sipid->ready==1)
1703 // if($sipid->ready==1&&$sipid->prepare_call==0&&$dialline->status=="Inbound")
1704 // {
1705 // $clientsarr=json_decode($sipid->clients,true);
1706 // if($crmcall->client=="")$first_a=$sipid;
1707 // else
1708 // {
1709 // if($clientsarr['a']!="")$clientaarr = explode(",", $clientsarr['a']);
1710 // if(isset($clientsarr['a'])&&in_array($crmcall->client, $clientaarr))$first_a=$sipid;
1711 // if($clientsarr['w']!="")$clientwarr = explode(",", $clientsarr['w']);
1712 // if(isset($clientsarr['w'])&&in_array($crmcall->client, $clientwarr))$first_w=$sipid;
1713 // if($clientsarr['r']!="")$clientrarr = explode(",", $clientsarr['r']);
1714 // if(isset($clientsarr['r'])&&in_array($crmcall->client, $clientrarr))$first_r=$sipid;
1715 // }
1716 // }
1717 // else
1718 // {
1719 // $allsipids[]=$sipid;
1720 // }
1721 // }
1722
1723 // foreach($sipids as $sipid)
1724 // {
1725 // if($sipid->ready==1&&$sipid->prepare_call==1&&$dialline->status=="Auto")
1726 // {
1727 // $clientsarr=json_decode($sipid->clients,true);
1728 // if($crmcall->client=="")$first_a=$sipid;
1729 // else
1730 // {
1731 // if($clientsarr['a']!="")$clientaarr = explode(",", $clientsarr['a']);
1732 // if(isset($clientsarr['a'])&&in_array($crmcall->client, $clientaarr))$first_a=$sipid;
1733 // if($clientsarr['w']!="")$clientwarr = explode(",", $clientsarr['w']);
1734 // if(isset($clientsarr['w'])&&in_array($crmcall->client, $clientwarr))$first_w=$sipid;
1735 // if($clientsarr['r']!="")$clientrarr = explode(",", $clientsarr['r']);
1736 // if(isset($clientsarr['r'])&&in_array($crmcall->client, $clientrarr))$first_r=$sipid;
1737 // }
1738 // }
1739 // else
1740 // {
1741 // $allsipids[]=$sipid;
1742 // }
1743 // }
1744
1745 // echo "Notifying Total ::".sizeof($allsipids)."\n";
1746
1747 // $found=false;
1748 // if($first_a)$found=$first_a;
1749 // else if($first_w)$found=$first_w;
1750 // else if($first_r)$found=$first_r;
1751
1752 // if($found)
1753 // {
1754 // $alreadyconf=Dialline::where('server','=',$this->sipip)->whereIn("status",["Inbound","Auto"])->where("conf","=","1000".$found->id)->get();
1755 // if(sizeof($alreadyconf)>0)
1756 // {
1757 // echo $found->id." : Found but Already in Conf!!!\n";
1758 // $found=false;
1759 // }
1760 // }
1761
1762 // if($found)
1763 // {
1764 // echo "sipids : $found->id \n";
1765
1766 // //get ts_Wait
1767 // $userlog=UserLog::where('user_id','=',$found->user)->orderBy("id","DESC")->first();
1768 // $ts_Wait=$userlog->getLastTs($found->id,$nowts);
1769 // $userlog->save();
1770
1771 // $crmcall->user_id=$found->user;
1772 // $crmcall->sipid_id=$found->id;
1773
1774 // if($ts_Wait<=$crmcall->ts_Wait) //user waiting
1775 // {
1776 // $crmcall->ts_Wait=$ts_Wait;
1777 // $crmcall->setTs('ts_Talk',$nowts);
1778 // }
1779 // else //call waiting
1780 // {
1781 // $crmcall->ts_Wait-=($nowts-$ts_Wait);
1782 // $crmcall->setTs('ts_Talk',$nowts);
1783 // }
1784
1785 // $crmcall->save();
1786
1787 // $dialline->user_id = $found->user;
1788 // $dialline->conf = "1000".$found->id;
1789 // $dialline->save();
1790
1791 // if($crmcall->crm_id>0){
1792 // DB::table('records')->where('id',$crmcall->crm_id)->update(['filter_condition'=>'3','usr_id'=>$found->user]);
1793
1794 // }
1795 // $found->ready=0;
1796 // $found->prepare_call=0;
1797 // $found->patched=1;
1798 // $found->save();
1799
1800 // $recfile=$crmcall->newRecFilePath();
1801
1802 // $crmcall->setTs('ts_Recstart',$nowts);
1803 // $crmcall->save();
1804
1805 // //start recording
1806 // $newqueue=new Kqueue();
1807 // $newqueue->recordChannel($dialline->server,$dialline->channel,$recfile);
1808
1809 // $newqueue=new Kqueue();
1810 // $newqueue->userToConf($found);
1811
1812 // $newqueue=new Kqueue();
1813 // $newqueue->channelRedirectToExten($found->server,$dialline->channel,"1000".$found->id,"kstychDialer","1");
1814
1815 // //notify UI (only the sip id)
1816 // $newqueue=new Kqueue();
1817 // $newqueue->sipNotify($found,"dialerUI","dialstart","c",$crmcall->number);
1818
1819 // $newqueue=new Kqueue();
1820 // $newqueue->sipNotify($found,"incomingCall",$crmcall->id,$crmcall->crm_id,$crmcall->number."@".$dialline->channel);
1821 // }
1822 // else
1823 // {
1824 // if(!empty($allsipids))
1825 // {
1826 // foreach($allsipids as $tsip)
1827 // {
1828 // //$newqueue=new Kqueue();
1829 // //$newqueue->sipNotify($tsip,"popupalert"," Incoming Calls",$crmcall->number."|".$crmcall->client,"");
1830 // if($dialline->status!="Auto")
1831 // {
1832 // $newqueue=new Kqueue();
1833 // $newqueue->sipNotify($tsip,"popupalert"," Incoming Calls",$crmcall->number."|".$crmcall->client,"");
1834 // }
1835 // }
1836 // }
1837 // else
1838 // {
1839 // //play no users available
1840 // if($crmcalldata["userbusyfile"]<$nowts)
1841 // {
1842 // $crmcalldata["userbusyfile"]=$nowts+(($playnouserlen+2)*1000);
1843 // $crmcall->data=json_encode($crmcalldata);
1844 // $crmcall->save();
1845 // }
1846
1847 // }
1848 // //no ready user, send notifications
1849 // }
1850 // }
1851 // else
1852 // {
1853 // //no users online
1854 // //play no routes file
1855 // if($crmcalldata["userbusyfile"]<$nowts)
1856 // {
1857 // $crmcalldata["userbusyfile"]=$nowts+(($playnoroutelen+2)*1000);
1858 // $crmcall->data=json_encode($crmcalldata);
1859 // $crmcall->save();
1860
1861 // //$newqueue=new Kqueue();
1862 // //$newqueue->playfile($playnoroute,$dialline->channel,"kstychDialerINB",$dialline->server);
1863 // }
1864 // }
1865
1866 // }
1867 // else
1868 // {
1869 // //$dialline->status='Free';
1870 // //$dialline->save();
1871 // }
1872 // //if client was matched then find users by client
1873 // //else find users by DID
1874 // //ele everyone
1875 // }
1876
1877 // }
1878
1879 // }
1706 1880
1707 private function sendAMICommands() 1881 private function sendAMICommands()
1708 { 1882 {
1709 $queues=Kqueue::where("type","=","SIP_".$this->sipip)->where("status","=","New")->take(5)->get(); 1883 $queues=Kqueue::where("type","=","SIP_".$this->sipip)->take(5)->get();
1710 1884
1711 if(!$queues->isEmpty())foreach($queues as $i=>$tqueue) 1885 if(!$queues->isEmpty())foreach($queues as $i=>$tqueue)
1712 { 1886 {
...@@ -1718,7 +1892,7 @@ class KPAMIListen implements IEventListener ...@@ -1718,7 +1892,7 @@ class KPAMIListen implements IEventListener
1718 $notify->setVariable('kstych-Data', "$data[1]|$data[2]|$data[3]|$data[4]"); 1892 $notify->setVariable('kstych-Data', "$data[1]|$data[2]|$data[3]|$data[4]");
1719 $res=$this->_client->send($notify); 1893 $res=$this->_client->send($notify);
1720 } 1894 }
1721 else if($tqueue->key=="originate") 1895 elseif($tqueue->key=="originate")
1722 { 1896 {
1723 $originateMsg = new OriginateAction($data['fromext']); 1897 $originateMsg = new OriginateAction($data['fromext']);
1724 $originateMsg->setContext($data['context']); 1898 $originateMsg->setContext($data['context']);
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!