Esempio n. 1
0
 protected function send_fax($job_id, $faxnumber, $faxrecipient)
 {
     $fax_data = Sendfax::find($job_id);
     if ($faxnumber != '' && $faxrecipient != '') {
         $meta = array("(", ")", "-", " ");
         $fax = str_replace($meta, "", $faxnumber);
         $send_list_data = array('faxrecipient' => $faxrecipient, 'faxnumber' => str_replace($meta, "", $faxnumber), 'job_id' => $job_id);
         DB::table('recipients')->insert($send_list_data);
         $this->audit('Add');
     }
     $faxrecipients = '';
     $faxnumbers = '';
     $recipientlist = DB::table('recipients')->where('job_id', '=', $job_id)->select('faxrecipient', 'faxnumber')->get();
     foreach ($recipientlist as $row) {
         $faxrecipients .= $row->faxrecipient . ', Fax: ' . $row->faxnumber . "\n";
         if ($faxnumbers != '') {
             $faxnumbers .= ',' . $row->faxnumber;
         } else {
             $faxnumbers .= $row->faxnumber;
         }
     }
     $practice_row = Practiceinfo::find(Session::get('practice_id'));
     $faxnumber_array = explode(",", $faxnumbers);
     $pagesInfo = DB::table('pages')->where('job_id', '=', $job_id)->get();
     $faxpages = '';
     $totalpages = 0;
     $senddate = date('Y-m-d H:i:s');
     foreach ($pagesInfo as $row4) {
         $faxpages .= ' ' . $row4->file;
         $totalpages = $totalpages + $row4->pagecount;
     }
     if ($fax_data->faxcoverpage == 'yes') {
         $cover_filename = Session::get('documents_dir') . 'sentfax/' . $job_id . '/coverpage.pdf';
         if (file_exists($cover_filename)) {
             unlink($cover_filename);
         }
         $cover_html = $this->page_intro('Cover Page', Session::get('practice_id'))->render();
         $cover_html .= $this->page_coverpage($job_id, $totalpages, $faxrecipients, date("M d, Y, h:i", time()))->render();
         $this->generate_pdf($cover_html, $cover_filename, 'footerpdf');
         while (!file_exists($cover_filename)) {
             sleep(2);
         }
     }
     if ($practice_row->fax_type != 'phaxio') {
         $config = array('driver' => 'smtp', 'host' => $practice_row->fax_email_smtp, 'port' => 465, 'from' => array('address' => null, 'name' => null), 'encryption' => 'ssl', 'username' => $practice_row->fax_email, 'password' => $practice_row->fax_email_password, 'sendmail' => '/usr/sbin/sendmail -bs', 'pretend' => false);
         Config::set('mail', $config);
         $data_message = array();
         Mail::send('emails.blank', $data_message, function ($message) use($faxnumber_array, $practice_row, $fax_data, $cover_filename, $pagesInfo) {
             $i = 0;
             foreach ($faxnumber_array as $faxnumber_row) {
                 if ($i == 0) {
                     $message->to($faxnumber_row . '@' . $practice_row->fax_type);
                 } else {
                     $message->cc($faxnumber_row . '@' . $practice_row->fax_type);
                 }
                 $i++;
             }
             $message->from($practice_row->email, $practice_row->practice_name);
             $message->subject($fax_data->faxsubject);
             if ($fax_data->faxcoverpage == 'yes') {
                 $message->attach($cover_filename);
             }
             foreach ($pagesInfo as $row5) {
                 $message->attach($row5->file);
             }
         });
         $fax_update_data = array('sentdate' => date('Y-m-d'), 'ready_to_send' => '1', 'senddate' => $senddate, 'faxdraft' => '0', 'attempts' => '0', 'success' => '1');
     } else {
         $phaxio_files_array = array();
         if ($fax_data->faxcoverpage == 'yes') {
             $phaxio_files_array[] = $cover_filename;
         }
         foreach ($pagesInfo as $phaxio_file) {
             $phaxio_files_array[] = $phaxio_file->file;
         }
         $phaxio = new Phaxio($practice_row->phaxio_api_key, $practice_row->phaxio_api_secret);
         $phaxio_result = $phaxio->sendFax($faxnumber_array, $phaxio_files_array);
         $phaxio_result_array = json_decode($phaxio_result, true);
         $fax_update_data = array('sentdate' => date('Y-m-d'), 'ready_to_send' => '1', 'senddate' => $senddate, 'faxdraft' => '0', 'attempts' => '0', 'success' => '0');
         if ($phaxio_result_array['success'] == true) {
             $fax_update_data['success'] = '2';
             $fax_update_data['command'] = $phaxio_result_array['faxId'];
         }
     }
     DB::table('sendfax')->where('job_id', '=', $job_id)->update($fax_update_data);
     $this->audit('Update');
     Session::forget('job_id');
     return 'Fax Job ' . $job_id . ' Sent';
 }
Esempio n. 2
0
 public function phaxio($practice_id)
 {
     $row = DB::table('practiceinfo')->where('practice_id', '=', $practice_id)->first();
     if ($row->fax_type == 'phaxio') {
         $result = json_decode(Input::get('fax'), true);
         $data['fileDateTime'] = date('Y-m-d H:i:s', $result['completed_at']);
         $data['practice_id'] = $practice_id;
         $data['fileFrom'] = $result['from_number'];
         $data['filePages'] = $result['num_pages'];
         $file1 = $result['id'] . '_' . time() . '.pdf';
         $received_dir = $row->documents_dir . 'received/' . $practice_id;
         if (!file_exists($received_dir)) {
             mkdir($received_dir, 0777);
         }
         $path = $row->documents_dir . 'received/' . $practice_id . '/' . $file1;
         $phaxio = new Phaxio($row->phaxio_api_key, $row->phaxio_api_secret);
         $file_result = $phaxio->faxFile($result['id']);
         File::put($path, $file_result);
         $data['fileName'] = $file1;
         $data['filePath'] = $path;
         DB::table('received')->insert($data);
         $this->audit('Add');
     }
 }