fix to display the four-panel link in the prescription list only when CAMOS is installed
[openemr.git] / controllers / C_Prescription.class.php
blobfc1ee39c3cc313fa9907439967b8fc97cbfcefa0
1 <?php
3 require_once($GLOBALS['fileroot'] . "/library/classes/Controller.class.php");
4 require_once($GLOBALS['fileroot'] . "/library/classes/Prescription.class.php");
5 require_once($GLOBALS['fileroot'] . "/library/classes/Provider.class.php");
6 require_once($GLOBALS['fileroot'] . "/library/classes/RXList.class.php");
7 require_once($GLOBALS['fileroot'] . "/library/registry.inc");
9 class C_Prescription extends Controller {
11 var $template_mod;
12 var $pconfig;
13 var $providerid = 0;
14 var $is_faxing = false;
15 var $is_print_to_fax = false;
17 function C_Prescription($template_mod = "general") {
18 parent::Controller();
20 $this->template_mod = $template_mod;
21 $this->assign("FORM_ACTION", $GLOBALS['webroot']."/controller.php?" . $_SERVER['QUERY_STRING']);
22 $this->assign("TOP_ACTION", $GLOBALS['webroot']."/controller.php?" . "prescription" . "&");
23 $this->assign("STYLE", $GLOBALS['style']);
24 $this->assign("WEIGHT_LOSS_CLINIC", $GLOBALS['weight_loss_clinic']);
25 $this->assign("SIMPLIFIED_PRESCRIPTIONS", $GLOBALS['simplified_prescriptions']);
26 $this->pconfig = $GLOBALS['oer_config']['prescriptions'];
28 if ($GLOBALS['inhouse_pharmacy']) {
29 // Make an array of drug IDs and selectors for the template.
30 $drug_array_values = array(0);
31 $drug_array_output = array("-- or select from inventory --");
32 $drug_attributes = '';
34 // $res = sqlStatement("SELECT * FROM drugs ORDER BY selector");
36 $res = sqlStatement("SELECT d.name, d.ndc_number, d.form, d.size, " .
37 "d.unit, d.route, d.substitute, t.drug_id, t.selector, t.dosage, " .
38 "t.period, t.quantity, t.refills " .
39 "FROM drug_templates AS t, drugs AS d WHERE " .
40 "d.drug_id = t.drug_id ORDER BY t.selector");
42 while ($row = sqlFetchArray($res)) {
43 $tmp_output = $row['selector'];
44 if ($row['ndc_number']) {
45 $tmp_output .= ' [' . $row['ndc_number'] . ']';
47 $drug_array_values[] = $row['drug_id'];
48 $drug_array_output[] = $tmp_output;
49 if ($drug_attributes) $drug_attributes .= ',';
50 $drug_attributes .= "['" .
51 $row['name'] . "'," . // 0
52 $row['form'] . ",'" . // 1
53 $row['dosage'] . "'," . // 2
54 $row['size'] . "," . // 3
55 $row['unit'] . "," . // 4
56 $row['route'] . "," . // 5
57 $row['period'] . "," . // 6
58 $row['substitute'] . "," . // 7
59 $row['quantity'] . "," . // 8
60 $row['refills'] . "," . // 9
61 $row['quantity'] . "]"; // 10 quantity per_refill
63 $this->assign("DRUG_ARRAY_VALUES", $drug_array_values);
64 $this->assign("DRUG_ARRAY_OUTPUT", $drug_array_output);
65 $this->assign("DRUG_ATTRIBUTES", $drug_attributes);
69 function default_action() {
70 $this->assign("prescription",$this->prescriptions[0]);
71 $this->display($GLOBALS['template_dir'] . "prescription/" . $this->template_mod . "_edit.html");
74 function edit_action($id = "",$patient_id="",$p_obj = null) {
76 if ($p_obj != null && get_class($p_obj) == "prescription") {
77 $this->prescriptions[0] = $p_obj;
79 elseif (get_class($this->prescriptions[0]) != "prescription" ) {
80 $this->prescriptions[0] = new Prescription($id);
83 if (!empty($patient_id)) {
84 $this->prescriptions[0]->set_patient_id($patient_id);
87 // If quantity to dispense is not already set from a POST, set its
88 // default value.
89 if (! $this->get_template_vars('DISP_QUANTITY')) {
90 $this->assign('DISP_QUANTITY', $this->prescriptions[0]->quantity);
93 $this->default_action();
96 function list_action($id,$sort = "") {
97 if (empty($id)) {
98 $this->function_argument_error();
99 exit;
101 if (!empty($sort)) {
102 $this->assign("prescriptions", Prescription::prescriptions_factory($id,$sort));
104 else {
105 $this->assign("prescriptions", Prescription::prescriptions_factory($id));
108 // flag to indicate the CAMOS form is regsitered and active
109 $this->assign("CAMOS_FORM", isRegistered(getIdByDirectory("CAMOS")));
111 $this->display($GLOBALS['template_dir'] . "prescription/" . $this->template_mod . "_list.html");
114 function block_action($id,$sort = "") {
115 if (empty($id)) {
116 $this->function_argument_error();
117 exit;
119 if (!empty($sort)) {
120 $this->assign("prescriptions", Prescription::prescriptions_factory($id,$sort));
122 else {
123 $this->assign("prescriptions", Prescription::prescriptions_factory($id));
125 //print_r(Prescription::prescriptions_factory($id));
126 $this->display($GLOBALS['template_dir'] . "prescription/" . $this->template_mod . "_block.html");
129 function lookup_action() {
130 $this->do_lookup();
131 $this->display($GLOBALS['template_dir'] . "prescription/" . $this->template_mod . "_lookup.html");
134 function edit_action_process() {
135 if ($_POST['process'] != "true")
136 return;
137 //print_r($_POST);
139 // Stupid Smarty code treats empty values as not specified values.
140 // Since active is a checkbox, represent the unchecked state as -1.
141 if (empty($_POST['active'])) $_POST['active'] = '-1';
143 $this->prescriptions[0] = new Prescription($_POST['id']);
144 parent::populate_object($this->prescriptions[0]);
145 //echo $this->prescriptions[0]->toString(true);
146 $this->prescriptions[0]->persist();
147 $_POST['process'] = "";
149 // If the "Prescribe and Dispense" button was clicked, then
150 // redisplay as in edit_action() but also replicate the fee and
151 // include a piece of javascript to call dispense().
153 if ($_POST['disp_button']) {
154 $this->assign("DISP_QUANTITY", $_POST['disp_quantity']);
155 $this->assign("DISP_FEE", $_POST['disp_fee']);
156 $this->assign("ENDING_JAVASCRIPT", "dispense();");
157 $this->_state = false;
158 return $this->edit_action($this->prescriptions[0]->id);
161 if ($this->prescriptions[0]->get_active() > 0) {
162 return $this->send_action($this->prescriptions[0]->id);
164 $this->list_action($this->prescriptions[0]->get_patient_id());
165 exit;
168 function send_action($id) {
169 $_POST['process'] = "true";
170 if(empty($id)) {
171 $this->function_argument_error();
174 $rx = new Prescription($id);
175 // Populate pharmacy info if the patient has a default pharmacy.
176 // Probably the Prescription object should handle this instead, but
177 // doing it there will require more careful research and testing.
178 $prow = sqlQuery("SELECT pt.pharmacy_id FROM prescriptions AS rx, " .
179 "patient_data AS pt WHERE rx.id = '$id' AND pt.pid = rx.patient_id");
180 if ($prow['pharmacy_id']) {
181 $rx->pharmacy->set_id($prow['pharmacy_id']);
182 $rx->pharmacy->populate();
184 $this->assign("prescription", $rx);
186 $this->_state = false;
187 return $this->fetch($GLOBALS['template_dir'] . "prescription/" .
188 $this->template_mod . "_send.html");
191 function multiprintfax_header(& $pdf, $p) {
192 return $this->multiprint_header( $pdf, $p );
195 function multiprint_header(& $pdf, $p) {
196 $this->providerid = $p->provider->id;
197 //print header
198 $pdf->ezImage($GLOBALS['fileroot'] . '/interface/pic/Rx.png','','50','','center','');
199 $pdf->ezColumnsStart(array('num'=>2, 'gap'=>10));
200 $res = sqlQuery("SELECT concat('<b>',f.name,'</b>\n',f.street,'\n',f.city,', ',f.state,' ',f.postal_code,'\nTel:',f.phone,if(f.fax != '',concat('\nFax: ',f.fax),'')) addr FROM users JOIN facility AS f ON f.name = users.facility where users.id ='" .
201 mysql_real_escape_string($p->provider->id) . "'");
202 $pdf->ezText($res['addr'],12);
203 $my_y = $pdf->y;
204 $pdf->ezNewPage();
205 $pdf->ezText('<b>' . $p->provider->get_name_display() . '</b>',12);
206 // A client had a bad experience with a patient misusing a DEA number, so
207 // now the doctors write those in on printed prescriptions and only when
208 // necessary. If you need to change this back, then please make it a
209 // configurable option. Faxed prescriptions were not changed. -- Rod
210 // Now it is configureable. Change value in
211 // <openemr root>/includes/config.php - Tekknogenius
212 if ($this->is_faxing || $GLOBALS['oer_config']['prescriptions']['show_DEA'])
213 $pdf->ezText('<b>DEA:</b>' . $p->provider->federal_drug_id, 12);
214 else
215 $pdf->ezText('<b>DEA:</b> ________________________', 12);
216 $pdf->ezColumnsStop();
217 if ($my_y < $pdf->y){
218 $pdf->ezSetY($my_y);
220 $pdf->ezText('',10);
221 $pdf->setLineStyle(1);
222 $pdf->ezColumnsStart(array('num'=>2));
223 $pdf->line($pdf->ez['leftMargin'],$pdf->y,$pdf->ez['pageWidth']-$pdf->ez['rightMargin'],$pdf->y);
224 $pdf->ezText('<b>Patient Name & Address</b>',6);
225 $pdf->ezText($p->patient->get_name_display(),10);
226 $res = sqlQuery("SELECT concat(street,'\n',city,', ',state,' ',postal_code,'\n',if(phone_home!='',phone_home,if(phone_cell!='',phone_cell,if(phone_biz!='',phone_biz,'')))) addr from patient_data where pid =". mysql_real_escape_string ($p->patient->id));
227 $pdf->ezText($res['addr']);
228 $my_y = $pdf->y;
229 $pdf->ezNewPage();
230 $pdf->line($pdf->ez['leftMargin'],$pdf->y,$pdf->ez['pageWidth']-$pdf->ez['rightMargin'],$pdf->y);
231 $pdf->ezText('<b>Date of Birth</b>',6);
232 $pdf->ezText($p->patient->date_of_birth,10);
233 $pdf->ezText('');
234 $pdf->line($pdf->ez['leftMargin'],$pdf->y,$pdf->ez['pageWidth']-$pdf->ez['rightMargin'],$pdf->y);
235 $pdf->ezText('<b>Medical Record #</b>',6);
236 $pdf->ezText(str_pad($p->patient->get_pubpid(), 10, "0", STR_PAD_LEFT),10);
237 $pdf->ezColumnsStop();
238 if ($my_y < $pdf->y){
239 $pdf->ezSetY($my_y);
241 $pdf->ezText('');
242 $pdf->line($pdf->ez['leftMargin'],$pdf->y,$pdf->ez['pageWidth']-$pdf->ez['rightMargin'],$pdf->y);
243 $pdf->ezText('<b>Prescriptions</b>',6);
244 $pdf->ezText('',10);
247 function multiprintfax_footer( & $pdf ) {
248 return $this->multiprint_footer( $pdf );
251 function multiprint_footer(& $pdf) {
252 if($this->pconfig['use_signature'] && ( $this->is_faxing || $this->is_print_to_fax ) ) {
253 $sigfile = str_replace('{userid}', $_SESSION{"authUser"}, $this->pconfig['signature']);
254 if (file_exists($sigfile)) {
255 $pdf->ezText("Signature: ",12);
256 // $pdf->ezImage($sigfile, "", "", "none", "left");
257 $pdf->ezImage($sigfile, "", "", "none", "center");
258 $pdf->ezText("Date: " . date('Y-m-d'), 12);
259 if ( $this->is_print_to_fax ) {
260 $pdf->ezText("Please do not accept this prescription unless it was received via facimile.");
263 $addenumFile = $this->pconfig['addendum_file'];
264 if ( file_exists( $addenumFile ) ) {
265 $pdf->ezText('');
266 $f = fopen($addenumFile, "r");
267 while ( $line = fgets($f, 1000) ) {
268 $pdf->ezText(rtrim($line));
272 return;
275 $pdf->ezText("\n\n\n\nSignature:________________________________\nDate: " . date('Y-m-d'),12);
278 function get_prescription_body_text($p) {
279 $body = '<b>Rx: ' . $p->get_drug() . ' ' . $p->get_size() . ' ' . $p->get_unit_display();
280 if ($p->get_form()) $body .= ' [' . $p->form_array[$p->get_form()] . "]";
281 $body .= "</b> <i>" .
282 $p->substitute_array[$p->get_substitute()] . "</i>\n" .
283 '<b>Disp #:</b> <u>' . $p->get_quantity() . "</u>\n" .
284 '<b>Sig:</b> ' . $p->get_dosage() . ' ' . $p->form_array[$p->get_form()] . ' ' .
285 $p->route_array[$p->get_route()] . ' ' . $p->interval_array[$p->get_interval()] . "\n";
286 if ($p->get_refills() > 0) {
287 $body .= "\n<b>Refills:</b> <u>" . $p->get_refills();
288 if ($p->get_per_refill()) {
289 $body .= " of quantity " . $p->get_per_refill();
291 $body .= "</u>\n";
293 else {
294 $body .= "\n<b>Refills:</b> <u>0 (Zero)</u>\n";
296 $note = $p->get_note();
297 if ($note != '') {
298 $body .= "\n$note\n";
300 return $body;
303 function multiprintfax_body(& $pdf, $p){
304 return $this->multiprint_body( $pdf, $p );
307 function multiprint_body(& $pdf, $p){
308 $pdf->ez['leftMargin'] += $pdf->ez['leftMargin'];
309 $pdf->ez['rightMargin'] += $pdf->ez['rightMargin'];
310 $d = $this->get_prescription_body_text($p);
311 if ( $pdf->ezText($d,10,array(),1) ) {
312 $pdf->ez['leftMargin'] -= $pdf->ez['leftMargin'];
313 $pdf->ez['rightMargin'] -= $pdf->ez['rightMargin'];
314 $this->multiprint_footer($pdf);
315 $pdf->ezNewPage();
316 $this->multiprint_header($pdf, $p);
317 $pdf->ez['leftMargin'] += $pdf->ez['leftMargin'];
318 $pdf->ez['rightMargin'] += $pdf->ez['rightMargin'];
320 $my_y = $pdf->y;
321 $pdf->ezText($d,10);
322 if($this->pconfig['shading']) {
323 $pdf->setColor(.9,.9,.9);
324 $pdf->filledRectangle($pdf->ez['leftMargin'],$pdf->y,$pdf->ez['pageWidth']-$pdf->ez['rightMargin']-$pdf->ez['leftMargin'],$my_y - $pdf->y);
325 $pdf->setColor(0,0,0);
327 $pdf->ezSetY($my_y);
328 $pdf->ezText($d,10);
329 $pdf->ez['leftMargin'] = $GLOBALS['oer_config']['prescriptions']['left'];
330 $pdf->ez['rightMargin'] = $GLOBALS['oer_config']['prescriptions']['right'];
331 $pdf->ezText('');
332 $pdf->line($pdf->ez['leftMargin'],$pdf->y,$pdf->ez['pageWidth']-$pdf->ez['rightMargin'],$pdf->y);
333 $pdf->ezText('');
336 function multiprintfax_action($id = "") {
337 $this->is_print_to_fax=true;
338 return $this->multiprint_action( $id );
341 function multiprint_action($id = "") {
342 $_POST['process'] = "true";
343 if(empty($id)) {
344 $this->function_argument_error();
346 require_once ($GLOBALS['fileroot'] . "/library/classes/class.ezpdf.php");
347 $pdf =& new Cezpdf($GLOBALS['oer_config']['prescriptions']['paper_size']);
348 $pdf->ezSetMargins($GLOBALS['oer_config']['prescriptions']['top']
349 ,$GLOBALS['oer_config']['prescriptions']['bottom']
350 ,$GLOBALS['oer_config']['prescriptions']['left']
351 ,$GLOBALS['oer_config']['prescriptions']['right']
353 $pdf->selectFont($GLOBALS['fileroot'] . "/library/fonts/Helvetica.afm");
355 // $print_header = true;
356 $on_this_page = 0;
358 //print prescriptions body
359 $this->_state = false; // Added by Rod - see Controller.class.php
360 $ids = preg_split('/::/', substr($id,1,strlen($id) - 2), -1, PREG_SPLIT_NO_EMPTY);
361 foreach ($ids as $id) {
362 $p = new Prescription($id);
363 // if ($print_header == true) {
364 if ($on_this_page == 0) {
365 $this->multiprint_header($pdf, $p);
367 if (++$on_this_page > 3 || $p->provider->id != $this->providerid) {
368 $this->multiprint_footer($pdf);
369 $pdf->ezNewPage();
370 $this->multiprint_header($pdf, $p);
371 // $print_header = false;
372 $on_this_page = 1;
374 $this->multiprint_body($pdf, $p);
377 $this->multiprint_footer($pdf);
379 $pdf->ezStream();
380 return;
383 function send_action_process($id) {
384 $dummy = ""; // Added by Rod to avoid run-time warnings
385 if ($_POST['process'] != "true")
386 return;
387 if(empty($id)) {
388 $this->function_argument_error();
390 $p = new Prescription($id);
391 switch ($_POST['submit']) {
393 case "Print":
394 // The following statement added by Rod.
395 // Looking at Controller.class.php, it appears that _state is set to false
396 // to indicate that no further HTML is to be generated.
397 $this->_state = false; // Added by Rod - see Controller.class.php
398 return $this->_print_prescription($p, $dummy);
399 break;
400 case "Print To Fax":
401 $this->_state = false;
402 $this->is_print_to_fax = true;
403 return $this->_print_prescription($p, $dummy);
404 break;
405 case "Email":
406 return $this->_email_prescription($p,$_POST['email_to']);
407 break;
408 case "Fax":
409 //this is intended to be the hook for the hylafax code we already have that hasn't worked its way into the tree yet.
410 //$this->assign("process_result","No fax server is currently setup.");
411 return $this->_fax_prescription($p,$_POST['fax_to']);
412 break;
413 case "Auto Send":
414 $pharmacy_id = $_POST['pharmacy_id'];
415 //echo "auto sending to : " . $_POST['pharmacy_id'];
416 $phar = new Pharmacy($_POST['pharmacy_id']);
417 //print_r($phar);
418 if ($phar->get_transmit_method() == TRANSMIT_PRINT) {
419 return $this->_print_prescription($p, $dummy);
421 elseif ($phar->get_transmit_method() == TRANSMIT_EMAIL) {
422 $email = $phar->get_email();
423 if (!empty($email)) {
424 return $this->_email_prescription($p,$phar->get_email());
426 //else print it
428 elseif ($phar->get_transmit_method() == TRANSMIT_FAX) {
429 $faxNum= $phar->get_fax();
430 if(!empty($faxNum)) {
431 Return $this->_fax_prescription ($p,$faxNum);
433 // return $this->assign("process_result","No fax server is currently setup.");
434 // else default is printing,
436 else {
437 //the pharmacy has no default or default is print
438 return $this->_print_prescription($p, $dummy);
440 break;
443 return;
447 function _print_prescription($p, & $toFile) {
448 require_once ($GLOBALS['fileroot'] . "/library/classes/class.ezpdf.php");
449 $pdf =& new Cezpdf($GLOBALS['oer_config']['prescriptions']['paper_size']);
450 $pdf->ezSetMargins($GLOBALS['oer_config']['prescriptions']['top']
451 ,$GLOBALS['oer_config']['prescriptions']['bottom']
452 ,$GLOBALS['oer_config']['prescriptions']['left']
453 ,$GLOBALS['oer_config']['prescriptions']['right']
456 $pdf->selectFont($GLOBALS['fileroot'] . "/library/fonts/Helvetica.afm");
458 // Signature images are to be used only when faxing.
459 if(!empty($toFile)) $this->is_faxing = true;
461 $this->multiprint_header($pdf, $p);
462 $this->multiprint_body($pdf, $p);
463 $this->multiprint_footer($pdf);
465 if(!empty($toFile)) {
466 $toFile = $pdf->ezOutput();
468 else {
469 $pdf->ezStream();
470 // $pdf->ezStream(array('compress' => 0)); // for testing with uncompressed output
472 return;
475 function _print_prescription_old($p, & $toFile) {
476 require_once ($GLOBALS['fileroot'] . "/library/classes/class.ezpdf.php");
477 $pdf =& new Cezpdf($GLOBALS['oer_config']['prescriptions']['paper_size']);
478 $pdf->ezSetMargins($GLOBALS['oer_config']['prescriptions']['top']
479 ,$GLOBALS['oer_config']['prescriptions']['bottom']
480 ,$GLOBALS['oer_config']['prescriptions']['left']
481 ,$GLOBALS['oer_config']['prescriptions']['right']
483 $pdf->selectFont($GLOBALS['fileroot'] . "/library/fonts/Helvetica.afm");
484 if(!empty($this->pconfig['logo'])) {
485 $pdf->ezImage($this->pconfig['logo'],"","","none","left");
487 $pdf->ezText($p->get_prescription_display(),10);
488 if($this->pconfig['use_signature']) {
489 $pdf->ezImage($this->pconfig['signature'],"","","none","left");
491 else{
492 $pdf->ezText("\n\n\n\nSignature:________________________________",10);
494 if(!empty($toFile))
496 $toFile = $pdf->ezOutput();
498 else
500 $pdf->ezStream();
501 // $pdf->ezStream(array('compress' => 0)); // for testing with uncompressed output
503 return;
506 function _email_prescription($p,$email) {
507 if (empty($email)) {
508 $this->assign("process_result","Email could not be sent, the address supplied: '$email' was empty or invalid.");
509 return;
511 require($GLOBALS['fileroot'] . "/library/classes/class.phpmailer.php");
512 $mail = new PHPMailer();
513 $mail->SetLanguage("en",$GLOBALS['fileroot'] . "/library/" );
514 //this is a temporary config item until the rest of the per practice billing settings make their way in
515 $mail->From = $GLOBALS['practice_return_email_path'];
516 $mail->FromName = $p->provider->get_name_display();
517 $mail->isMail();
518 $mail->Host = "localhost";
519 $mail->Mailer = "mail";
520 $text_body = $p->get_prescription_display();
521 $mail->Body = $text_body;
522 $mail->Subject = "Prescription for: " . $p->patient->get_name_display();
523 $mail->AddAddress($email);
524 if($mail->Send()) {
525 $this->assign("process_result","Email was successfully sent to: " . $email);
526 return;
528 else {
529 $this->assign("process_result","There has been a mail error sending to " . $_POST['email_to'] . " " . $mail->ErrorInfo);
530 return;
534 function do_lookup() {
535 if ($_POST['process'] != "true") {
536 // don't do a lookup
537 $this->assign("drug", $_GET['drug']);
538 return;
541 // process the lookup
542 $this->assign("drug", $_POST['drug']);
543 $list = array();
544 if (!empty($_POST['drug'])) {
545 $list = @RxList::get_list($_POST['drug']);
548 if (is_array($list)) {
549 $list = array_flip($list);
550 $this->assign("drug_options",$list);
551 $this->assign("drug_values",array_keys($list));
553 else {
554 $this->assign("NO_RESULTS","No results found for: " .$_POST['drug'] . "<br />");
556 //print_r($_POST);
557 //$this->assign("PROCESS","");
559 $_POST['process'] = "";
562 function _fax_prescription($p,$faxNum)
564 $err = "Sent fax";
565 //strip - ,(, ), and ws
566 $faxNum = preg_replace("/(-*)(\(*)(\)*)(\s*)/","",$faxNum);
567 //validate the number
569 if(!empty($faxNum) && is_numeric($faxNum))
571 //get the sendfax command and execute it
572 $cmd = $this->pconfig['sendfax'];
573 // prepend any prefix to the fax number
574 $pref=$this->pconfig['prefix'];
575 $faxNum=$pref.$faxNum;
576 if(empty($cmd))
578 $err .= " Send fax not set in includes/config.php";
579 break;
581 else
583 //generate file to fax
584 $faxFile = "Failed";
585 $this->_print_prescription($p, $faxFile);
586 if(empty($faxFile))
588 $err .= " _print_prescription returned empty file";
589 break;
591 $fileName = dirname(__FILE__)."/../documents/".$p->get_id()
592 .$p->get_patient_id()."_fax_.pdf";
593 //print "filename is $fileName";
594 touch($fileName); // php bug
595 $handle = fopen($fileName,"w");
596 if(!$handle)
598 $err .= " Failed to open file $fileName to write fax to";
599 break;
601 if(fwrite($handle, $faxFile) === false)
603 $err .= " Failed to write data to $fileName";
604 break;
606 fclose($handle);
607 $args = " -n -d $faxNum $fileName";
608 //print "command is $cmd $args<br>";
609 exec($cmd . $args);
613 else
615 $err = "bad fax number passed to function";
617 if($err)
619 $this->assign("process_result",$err);