src/AppBundle/Controller/DefaultController.php line 134

Open in your IDE?
  1. <?php
  2. namespace AppBundle\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  4. use Symfony\Component\HttpFoundation\Request;
  5. //use AppBundle\Controller\SecurityController;
  6. use Symfony\Component\HttpFoundation\RedirectResponse;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  9. use Symfony\Component\HttpFoundation\JsonResponse;
  10. use AppBundle\Helpers\Constants;
  11. use Twilio\Rest\Client;
  12. use AppBundle\Helpers\MailerHelper;
  13. use Doctrine\ORM\EntityManagerInterface;
  14. use AppBundle\Shame\Shame;
  15. class DefaultController extends Controller
  16. {
  17.     /**
  18.      * @Route("/sendcert", name="sendcert")
  19.      * @param Request $request
  20.      * @return string
  21.      */
  22.     public function sendcertAction(Request $request)
  23.     {
  24.         $subject $request->get('subject');
  25.         $email $request->get('to');
  26.         $cc $request->get('cc');
  27.         $cc2 $request->get('cc2');
  28.         $body $request->get('body');
  29.         $id $request->get('cert');
  30.         $mail = new MailerHelper();
  31.         $email str_replace(';'','$email);
  32.         $to = [ $email$cc];
  33.         if ($cc2) {
  34.             $to[] = $cc2;
  35.         }
  36.         $ch curl_init();
  37.         curl_setopt($chCURLOPT_URL"https://api.accredible.com/v1/credentials/generate_single_pdf/$id");
  38.         curl_setopt($chCURLOPT_RETURNTRANSFERTRUE);
  39.         curl_setopt($chCURLOPT_HEADERFALSE);
  40.         curl_setopt($chCURLOPT_POSTTRUE);
  41.         curl_setopt($chCURLOPT_HTTPHEADER, array(
  42.             "Content-Type: application/json",
  43.             "Authorization: Token token=ebcdbc42460d12266cc0f76d8a49286a"
  44.         ));
  45.         $response curl_exec($ch);
  46.         curl_close($ch);
  47.         $data =json_decode($response);
  48.         $arrContextOptions=array(
  49.             "ssl"=>array(
  50.                 "verify_peer"=>false,
  51.                 "verify_peer_name"=>false,
  52.             ),
  53.         );
  54.         $response file_get_contents($data->filefalsestream_context_create($arrContextOptions));
  55.         file_put_contents('pdf/' $id .'.pdf'$response);
  56.         $html $body;
  57.         $response $mail->sendEmailwithAttachment(
  58.             $email,
  59.             'info@asbestosonlinetraining.com' ,
  60.             'Asbestos Guys',
  61.             $cc,
  62.             $cc2,
  63.             $subject,
  64.             $html,
  65.             $body,
  66.             'pdf/' $id .'.pdf'
  67.         );
  68.         return (new Response("OK"));
  69.     }
  70.     /**
  71.      * @Route("/sendtest", name="sendtest")
  72.      * @param Request $request
  73.      * @return string
  74.      */
  75.     public function sendtestAction(Request $request)
  76.     {
  77.         $subject 'This is a test';
  78.         $email 'erik@olson.host';
  79.         $cc 'erik@evodialer.com';
  80.         $cc2 'erikolson1965@gmail.com';
  81.         $body 'Hello World - this is a test';
  82.         $html '<h1>Hello World</h2><hr><p>This is a test</p>';
  83.         $mail = new MailerHelper();
  84.         $response $mail->sendEmailwithAttachment(
  85.             $email,
  86.             'info@asbestosonlinetraining.com' ,
  87.             'Asbestos Guys',
  88.             $cc,
  89.             $cc2,
  90.             $subject,
  91.             $html,
  92.             $body,
  93.             '/var/www/apic/web/robots.txt'
  94.         );
  95.         return (new Response("OK"));
  96.     }
  97.     /**
  98.      * @Route("/sendm", name="sendm")
  99.      * @param Request $request
  100.      * @return string
  101.      */
  102.     public function sendmAction(Request $request)
  103.     {
  104.         $subject $request->get('subject');
  105.         $body $request->get('body');
  106.         $email $request->get('email');
  107.         $mail = new MailerHelper();
  108.         $ctr 1;
  109.         $email str_replace(';'','$email);
  110.         $email explode(','$email);
  111.         $response $mail->sendEmail$email'info@asbestosonlinetraining.com' $subject$body);
  112.         return (new Response("OK"));
  113.     }
  114.     /**
  115.      * @Route("/post", name="post")
  116.      * @param Request $request
  117.      * @return string
  118.      */
  119.     public function postAction(Request $request)
  120.     {
  121.         $subject $request->get('subject');
  122.         $body $request->get('body');
  123.         $emails $request->get('emails');
  124.         file_put_contents('mail.html.json'json_encode([$subject$body]));
  125.         $emails str_replace([ ',' "\n","\r",' ' ], ';'$emails);
  126.         $emails explode(';',$emails);
  127.         $emails array_filter($emails);
  128.         echo "<h1>Sending...</h1><pre>";
  129.         //var_dump($emails);
  130.         $mail = new MailerHelper();
  131.         $ctr 1;
  132.         foreach ($emails as $email) {
  133.             if ($ctr++ > 14) {
  134.                 $ctr 1;
  135.                 flush();
  136.                 sleep(1);
  137.             }
  138.             echo "Sending to: $email\n";
  139.             $response $mail->sendEmail( [ $email ], 'info@asbestosonlinetraining.com' $subject$body);
  140.             echo "AWS Response: $response\n\n";
  141.         }
  142.         return (new Response("Send Completee\n\n</pre><a href='/mailthing'>Send summore mails</a>"));
  143.     }
  144.     /**
  145.      * @Route("/mailthing", name="mailthing")
  146.      * @param Request $request
  147.      * @return string
  148.      */
  149.     public function indexAction(Request $request)
  150.     {
  151.         //return $this->render('default/index.html.twig');
  152.         //$shame = new Shame($this);
  153.         //return (new JsonResponse($shame->getUsers()));
  154.         $email file_get_contents('mail.html.json');
  155.         $email json_decode($email);
  156.         return $this->render('mail.html.twig', [
  157.             'body' => $email[1],
  158.             'subject' => $email[0]
  159.         ]);
  160.     }
  161.     private function init() {
  162.         $this->shame = new Shame($this);
  163.     }
  164.     public function getP($name)
  165.     {
  166.         try {
  167.             return $this->getParameter($name);
  168.         } catch (\Exception $e) {
  169.         }
  170.         try {
  171.             return $this->getParameter(strtoupper($name));
  172.         } catch (\Exception $e) {
  173.         }
  174.         try {
  175.             return $this->getParameter(strtolower($name));
  176.         } catch (\Exception $e) {
  177.             exit($e->getMessage() . " Both upper and lower case variable names were attempted");
  178.         }
  179.     }
  180.     /**
  181.      * @Route("/artefacts/recording-events", name="artefacts-recording-events")
  182.      * @param Request $request
  183.      * @return string
  184.      *
  185.      * Receive a Callback Event
  186.      *
  187.      */
  188.     public function recordingEventAction(Request $request)
  189.     {
  190.         $response = new Response();
  191.         $dir $request->get('RecordingDuration');
  192.         if ($dir 20) {
  193.             $text "Call Recording ($dir seconds)\n";
  194.             $text .= $request->get('RecordingUrl');
  195.             $this->send($texttruefalse);
  196.         }
  197.         return $response->setContent("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
  198.     }
  199.     /**
  200.      * @Route("/artefacts/dial-status-events", name="artefacts-dial-status-events")
  201.      * @param Request $request
  202.      * @param mixed $text
  203.      * @return string
  204.      *
  205.      * Receive a Callback Event
  206.      *
  207.      */
  208.     public function dialEventAction(Request $request$text "Call Status Update")
  209.     {
  210.         $text .= "\n";
  211.         $response = new Response();
  212.         $data = [
  213.             'CallStatus',
  214.             'CallDuration',
  215.             'CallerName',
  216.             'Caller',
  217.             'CallerCity',
  218.             'CallerCountry',
  219.             'CallerState',
  220.             'CallerZip',
  221.         ];
  222.         foreach ($data as $datum) {
  223.             if ($request->get($datum)) {
  224.                 $text .= "$datum:".$request->get($datum) . "\n";
  225.             }
  226.         }
  227.         $this->send($text);
  228.         return $response->setContent("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
  229.     }
  230.     /**
  231.      * @Route("/artefacts/call-status-events", name="artefacts-call-status-events")
  232.      * @param Request $request
  233.      * @return string
  234.      *
  235.      * Receive a Callback Event
  236.      *
  237.      */
  238.     public function callEventAction(Request $request)
  239.     {
  240.         $response = new Response();
  241.         return $response->setContent("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
  242.     }
  243.     /**
  244.      * @Route("/artefacts/hold-music")
  245.      * @param Request $request
  246.      * @return string
  247.      *
  248.      * Hold Music
  249.      * rick-olson_sahara-groove-studio
  250.      *
  251.      */
  252.     public function holdMusicAction(Request $request)
  253.     {
  254.         $response = new Response();
  255.         // Send a Text and Initiate agent dialing before returning hold music to play.
  256.         $data = [
  257.             'CallStatus',
  258.             'CallerName',
  259.             'Caller',
  260.             'CallerCity',
  261.             'CallerCountry',
  262.             'CallerState',
  263.             'CallerZip',
  264.             'CurrentQueueSize',
  265.             'QueuePosition',
  266.             'QueueTime',
  267.             'AvgQueueTime',
  268.         ];
  269.         $text "Caller in Queue!\n";
  270.         foreach ($data as $datum) {
  271.             if ($request->get($datum)) {
  272.                 $text .= "$datum:".$request->get($datum) . "\n";
  273.             }
  274.         }
  275.         $artefacts_sid getenv('ARTEFACTS_SID');
  276.         $artefacts_token getenv('ARTEFACTS_TOKEN');
  277.         $artefacts = new Client($artefacts_sid$artefacts_token);
  278.         $users = new Users();
  279.         $who $users->getUsers();
  280.         $A getenv('ARTEFACTS_ACTIVE_TABLE');
  281.         $O getenv('ARTEFACTS_ONCALL_TABLE');
  282.         $host getenv('PLUGINS_HOST');
  283.         $activeCounter 0;
  284.         $oncallCounter 0;
  285.         foreach ($who as $he) {
  286.             $phone $he[0];
  287.             $data $he[1];
  288.             if ($data == 'artefacts-supportdesk-active') {
  289.                 $isActive $users->getUserX($phone$A);
  290.                 $isOncall $users->getUserX($phone$O);
  291.                 $phone filter_var($phoneFILTER_SANITIZE_NUMBER_INT);
  292.                 if (strlen($phone) == 10) {
  293.                     $phone '1' $phone;
  294.                 }
  295.                 if ($isActive) {
  296.                     $activeCounter++;
  297.                     $artefacts->messages->create(
  298.                         '+' $phone,
  299.                         array(
  300.                             'from' => '+18444493911',
  301.                             'body' => $text
  302.                         )
  303.                     );
  304.                 }
  305.                 if ($isOncall) {
  306.                     $oncallCounter++;
  307.                     $call $artefacts->calls
  308.                         ->create("+" $phone,  // to
  309.                             "+18444493911",     // from
  310.                             array("url" => "$host/artefacts/agent")
  311.                         );
  312.                 }
  313.             }
  314.         }
  315.         $everyone = [];
  316.         if ($oncallCounter == 0) {
  317.             foreach ($who as $he) {
  318.                 $phone $he[0];
  319.                 $data $he[1];
  320.                 if ($data == 'artefacts-supportdesk-active') {
  321.                     if (strlen($phone) == 10) {
  322.                         $phone '1' $phone;
  323.                     }
  324.                     $everyone[] = $phone;
  325.                 }
  326.             }
  327.             foreach ($everyone as $phone) {
  328.                 $artefacts->messages->create(
  329.                     '+' $phone,
  330.                     array(
  331.                         'from' => '+18444493911',
  332.                         'body' => "WARNING - NO ONE IS ON-CALL - SO I'M CALLING EVERYBODY!!\n\n" $text
  333.                     )
  334.                 );
  335.             }
  336.             foreach ($everyone as $phone) {
  337.                 $call $artefacts->calls
  338.                     ->create("+" $phone,  // to
  339.                         "+18444493911",     // from
  340.                         array("url" => "$host/artefacts/agent")
  341.                     );
  342.             }
  343.         }
  344.         return $response->setContent('<?xml version="1.0" encoding="UTF-8"?>
  345. <Response>
  346.     <Play>https://chargebacks911.com/Apps/rick-olson_sahara-groove-studio-downsampled220.mp3</Play>
  347. </Response>');
  348.     }
  349.     /**
  350.      * @Route("/artefacts/agent-hold-music")
  351.      * @param Request $request
  352.      * @return string
  353.      *
  354.      * Agent Hold Music
  355.      */
  356.     public function agentHoldMusicAction(Request $request)
  357.     {
  358.         $response = new Response();
  359.         // http://com.artefacts.sounds.music.s3.amazonaws.com/...
  360.         // ClockworkWaltz.mp3
  361.         // BusyStrings.mp3
  362.         // Mellotroniac_-_Flight_Of_Young_Hearts_Flute.mp3
  363.         // ith_chopin-15-2.mp3
  364.         // oldDog_-_endless_goodbye_(instr.).mp3
  365.         // MARKOVICHAMP-Borghestral.mp3
  366.         return $response->setContent('<?xml version="1.0" encoding="UTF-8"?>
  367. <Response>
  368.     <Play>http://com.twilio.sounds.music.s3.amazonaws.com/ith_chopin-15-2.mp3</Play>
  369. </Response>');
  370.     }
  371.     /**
  372.      * @Route("/artefacts/call", name="artefacts-call")
  373.      * @param Request $request
  374.      * @return string
  375.      *
  376.      * Receive a Call
  377.      *
  378.      */
  379.     public function callAction(Request $request)
  380.     {
  381.         $To $request->get('Called');
  382.         $From $request->get('Caller');
  383.         $response = new Response();
  384.         if ((!$To) or (!$From)) {
  385.             $response->setStatusCode(Response::HTTP_BAD_REQUEST);
  386.             return $response;
  387.         }
  388.         // Todo: Send a text to everyone who is ACTIVE
  389.         /*
  390.          * Send a text to
  391.             00000000000 Jeanette, 00000000000000 Jaclyn
  392.          *   00000000000 Others
  393.          *
  394.          */
  395.         $text "Incoming Call\n";
  396.         $response = new Response();
  397.         $data = [
  398.             'CallStatus',
  399.             'CallDuration',
  400.             'CallerName',
  401.             'Caller',
  402.             'CallerCity',
  403.             'CallerCountry',
  404.             'CallerState',
  405.             'CallerZip',
  406.         ];
  407.         foreach ($data as $datum) {
  408.             if ($request->get($datum)) {
  409.                 $text .= "$datum:".$request->get($datum) . "\n";
  410.             }
  411.         }
  412.         $this->send($text);
  413.         $user = new Users();
  414.         $onCall $user->getUsersX(getenv('ARTEFACTS_ONCALL_TABLE'));
  415.         // Don't forget to activate group extensions and increase the timeout on US
  416.         // from 4 seconds to 20 seconds
  417.         // put back greeting
  418.         $twiml =
  419.             '<?xml version="1.0" encoding="UTF-8"?>
  420.  <Response>
  421.  <Play>https://chargebacks911.com/Apps/artefactshotlinegreeting.mp3?x=2</Play>
  422.  <!-- include the below if you want to try ringing a receptionist before queuing to cell phones -->
  423.  <!--Dial record="record-from-ringing-dual"
  424.     recordingStatusCallback="/artefacts/recording-events"
  425.     recordingStatusCallbackEvent="completed"
  426.     method="GET">
  427.  <Sip>sip:7080@52.207.99.81;region=us1</Sip>
  428.  </Dial-->
  429.  <!--
  430.  If we get here, that means the above call ended for whatever reason.
  431.  If no office is open, this happens right away with the intention of
  432.  getting the caller to an On-Call team member.
  433.  However, the caller is just as likely to have been talking to an office
  434.  team member and this call is ending normally.  So, for this reason, we
  435.  will want to have a little bit of silence so the caller can hang up.
  436.   -->
  437.  <!--Pause length="3"/-->
  438.  <Enqueue waitUrl="/artefacts/hold-music">support</Enqueue> 
  439. </Response>';
  440.         $response->setContent($twiml);
  441.         return $response;
  442.     }
  443.     /**
  444.      * @Route("/artefacts/agent")
  445.      * @param Request $request
  446.      * @return string
  447.      *
  448.      * Agent grab caller in Queue
  449.      *
  450.      */
  451.     public function agentAction(Request $request)
  452.     {
  453.         $response = new Response();
  454.         if ($request->get('Digits')) {
  455.             return $response->setContent('<?xml version="1.0" encoding="UTF-8"?>
  456. <Response>
  457.     <Dial record="record-from-ringing-dual"
  458.     recordingStatusCallback="/artefacts/recording-events"
  459.     recordingStatusCallbackEvent="completed"
  460.     method="GET">
  461.        <Queue>support</Queue>
  462.     </Dial>       
  463. </Response>');
  464.         } else {
  465.             return $response->setContent('<?xml version="1.0" encoding="UTF-8"?>
  466. <Response>
  467.     <Gather>
  468.     <Say>I have a call for you. Please press 1 at any time to access the queue.  If you hear music, then the queue is empty. You may stay on the line and if someone calls they will be transferred to you immediately.</Say>
  469.     </Gather>
  470.     <Say>Goodbye!</Say>
  471. </Response>');
  472.         }
  473.     }
  474.     public function send($text$Active=true$Oncall true$override false)
  475.     {
  476.         $artefacts_sid getenv('ARTEFACTS_SID');
  477.         $artefacts_token getenv('ARTEFACTS_TOKEN');
  478.         $artefacts = new Client($artefacts_sid$artefacts_token);
  479.         $users = new Users();
  480.         $who $users->getUsers();
  481.         $A getenv('ARTEFACTS_ACTIVE_TABLE');
  482.         $O getenv('ARTEFACTS_ONCALL_TABLE');
  483.         $cnt 0;
  484.         foreach ($who as $he) {
  485.             $phone $he[0];
  486.             $data $he[1];
  487.             if ($data == 'artefacts-supportdesk-active') {
  488.                 $isActive false;
  489.                 $isOncall false;
  490.                 if ($Active) {
  491.                     $isActive $users->getUserX($phone$A);
  492.                 }
  493.                 if ($Oncall) {
  494.                     $isOncall $users->getUserX($phone$O);
  495.                 }
  496.                 // If nobody is active, do something like email everyone
  497.                 if ($isActive or $isOncall or $override) {
  498.                     $cnt++;
  499.                     $phone filter_var($phoneFILTER_SANITIZE_NUMBER_INT);
  500.                     if (strlen($phone) == 10) {
  501.                         $phone '1' $phone;
  502.                     }
  503.                     $artefacts->messages->create(
  504.                         '+' $phone,
  505.                         array(
  506.                             'from' => '+18444493911',
  507.                             'body' => $text
  508.                         )
  509.                     );
  510.                 }
  511.             }
  512.         }
  513.         return $cnt;
  514.     }
  515.     public function sendTo($text$recipients)
  516.     {
  517.         $artefacts_sid getenv('ARTEFACTS_SID');
  518.         $artefacts_token getenv('ARTEFACTS_TOKEN');
  519.         $artefacts = new Client($artefacts_sid$artefacts_token);
  520.         foreach ($recipients as $phone) {
  521.             $phone filter_var($phoneFILTER_SANITIZE_NUMBER_INT);
  522.             if (strlen($phone) == 10) {
  523.                 $phone '1' $phone;
  524.             }
  525.             $artefacts->messages->create(
  526.                 '+' $phone,
  527.                 array(
  528.                     'from' => '+18444493911',
  529.                     'body' => $text
  530.                 )
  531.             );
  532.         }
  533.     }
  534. }