consolidate attr_url function (#2143)
[openemr.git] / interface / fax / fax_dispatch.php
blobcd11724bf5b655660aea55aedfe7a44e4381970c
1 <?php
2 /**
3 * fax dispatch
5 * @package OpenEMR
6 * @link http://www.open-emr.org
7 * @author Rod Roark <rod@sunsetsystems.com>
8 * @author Brady Miller <brady.g.miller@gmail.com>
9 * @copyright Copyright (c) 2006-2010 Rod Roark <rod@sunsetsystems.com>
10 * @copyright Copyright (c) 2017-2018 Brady Miller <brady.g.miller@gmail.com>
11 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
15 require_once("../globals.php");
16 require_once("$srcdir/patient.inc");
17 require_once("$srcdir/pnotes.inc");
18 require_once("$srcdir/forms.inc");
19 require_once("$srcdir/options.inc.php");
20 require_once("$srcdir/gprelations.inc.php");
22 use OpenEMR\Core\Header;
24 if ($_GET['file']) {
25 if (!verifyCsrfToken($_GET["csrf_token_form"])) {
26 csrfNotVerified();
29 $mode = 'fax';
30 $filename = $_GET['file'];
32 // ensure the file variable has no illegal characters
33 check_file_dir_name($filename);
35 $filepath = $GLOBALS['hylafax_basedir'] . '/recvq/' . $filename;
36 } else if ($_GET['scan']) {
37 if (!verifyCsrfToken($_GET["csrf_token_form"])) {
38 csrfNotVerified();
41 $mode = 'scan';
42 $filename = $_GET['scan'];
44 // ensure the file variable has no illegal characters
45 check_file_dir_name($filename);
47 $filepath = $GLOBALS['scanner_output_directory'] . '/' . $filename;
48 } else {
49 die("No filename was given.");
52 $ext = substr($filename, strrpos($filename, '.'));
53 $filebase = basename("/$filename", $ext);
54 $faxcache = $GLOBALS['OE_SITE_DIR'] . "/faxcache/$mode/$filebase";
56 $info_msg = "";
58 // This function builds an array of document categories recursively.
59 // Kittens are the children of cats, you know. :-)getKittens
61 function getKittens($catid, $catstring, &$categories)
63 $cres = sqlStatement("SELECT id, name FROM categories " .
64 "WHERE parent = ? ORDER BY name", array($catid));
65 $childcount = 0;
66 while ($crow = sqlFetchArray($cres)) {
67 ++$childcount;
68 getKittens($crow['id'], ($catstring ? "$catstring / " : "") .
69 ($catid ? $crow['name'] : ''), $categories);
72 // If no kitties, then this is a leaf node and should be listed.
73 if (!$childcount) {
74 $categories[$catid] = $catstring;
78 // This merges the tiff files for the selected pages into one tiff file.
80 function mergeTiffs()
82 global $faxcache;
83 $msg = '';
84 $inames = '';
85 $tmp1 = array();
86 $tmp2 = 0;
87 // form_images are the checkboxes to the right of the images.
88 foreach ($_POST['form_images'] as $inbase) {
89 check_file_dir_name($inbase);
90 $inames .= ' ' . escapeshellarg("$inbase.tif");
93 if (!$inames) {
94 die(xlt("Internal error - no pages were selected!"));
97 $tmp0 = exec("cd " . escapeshellarg($faxcache) . "; tiffcp $inames temp.tif", $tmp1, $tmp2);
98 if ($tmp2) {
99 $msg .= "tiffcp returned $tmp2: $tmp0 ";
102 return $msg;
105 // If we are submitting...
107 if ($_POST['form_save']) {
108 if (!verifyCsrfToken($_POST["csrf_token_form"])) {
109 csrfNotVerified();
112 $action_taken = false;
113 $tmp1 = array();
114 $tmp2 = 0;
116 if ($_POST['form_cb_copy']) {
117 $patient_id = (int) $_POST['form_pid'];
118 if (!$patient_id) {
119 die(xlt('Internal error - patient ID was not provided!'));
122 // Compute the name of the target directory and make sure it exists.
123 $docdir = $GLOBALS['OE_SITE_DIR'] . "/documents/" . check_file_dir_name($patient_id);
124 exec("mkdir -p " . escapeshellarg($docdir));
126 // If copying to patient documents...
128 if ($_POST['form_cb_copy_type'] == 1) {
129 // Compute a target filename that does not yet exist.
130 $ffname = check_file_dir_name(trim($_POST['form_filename']));
131 $i = strrpos($ffname, '.');
132 if ($i) {
133 $ffname = trim(substr($ffname, 0, $i));
136 if (!$ffname) {
137 $ffname = $filebase;
140 $ffmod = '';
141 $ffsuff = '.pdf';
142 // If the target filename exists, modify it until it doesn't.
143 $count = 0;
144 while (is_file("$docdir/$ffname$ffmod$ffsuff")) {
145 ++$count;
146 $ffmod = "_$count";
149 $target = "$docdir/$ffname$ffmod$ffsuff";
150 $docdate = fixDate($_POST['form_docdate']);
152 // Create the target PDF. Note that we are relying on the .tif files for
153 // the individual pages to already exist in the faxcache directory.
155 $info_msg .= mergeTiffs();
156 // The -j option here requires that libtiff is configured with libjpeg.
157 // It could be omitted, but the output PDFs would then be quite large.
158 $tmp0 = exec("tiff2pdf -j -p letter -o " . escapeshellarg($target) . " " . escapeshellarg($faxcache.'/temp.tif'), $tmp1, $tmp2);
160 if ($tmp2) {
161 $info_msg .= "tiff2pdf returned $tmp2: $tmp0 ";
162 } else {
163 $newid = generate_id();
164 $fsize = filesize($target);
165 $catid = (int) $_POST['form_category'];
166 // Update the database.
167 $query = "INSERT INTO documents ( " .
168 "id, type, size, date, url, mimetype, foreign_id, docdate" .
169 " ) VALUES ( " .
170 "?, 'file_url', ?, NOW(), ?, " .
171 "'application/pdf', ?, ? " .
172 ")";
173 sqlStatement($query, array($newid, $fsize, 'file://'.$target, $patient_id, $docdate));
174 $query = "INSERT INTO categories_to_documents ( " .
175 "category_id, document_id" .
176 " ) VALUES ( " .
177 "?, ? " .
178 ")";
179 sqlStatement($query, array($catid, $newid));
180 } // end not error
182 // If we are posting a note...
183 if ($_POST['form_cb_note'] && !$info_msg) {
184 // Build note text in a way that identifies the new document.
185 // See pnotes_full.php which uses this to auto-display the document.
186 $note = "$ffname$ffmod$ffsuff";
187 for ($tmp = $catid; $tmp;) {
188 $catrow = sqlQuery("SELECT name, parent FROM categories WHERE id = ?", array($tmp));
189 $note = $catrow['name'] . "/$note";
190 $tmp = $catrow['parent'];
193 $note = "New scanned document $newid: $note";
194 $form_note_message = trim($_POST['form_note_message']);
195 if ($form_note_message) {
196 $note .= "\n" . $form_note_message;
199 $noteid = addPnote(
200 $_POST['form_pid'],
201 $note,
202 $userauthorized,
203 '1',
204 $_POST['form_note_type'],
205 $_POST['form_note_to']
207 // Link the new patient note to the document.
208 setGpRelation(1, $newid, 6, $noteid);
209 } // end post patient note
210 } // end copy to documents
212 // Otherwise creating a scanned encounter note...
214 else {
215 // Get desired $encounter_id.
216 $encounter_id = 0;
217 if (empty($_POST['form_copy_sn_visit'])) {
218 $info_msg .= "This patient has no visits! ";
219 } else {
220 $encounter_id = 0 + $_POST['form_copy_sn_visit'];
223 if (!$info_msg) {
224 // Merge the selected pages.
225 $info_msg .= mergeTiffs();
226 $tmp_name = "$faxcache/temp.tif";
229 if (!$info_msg) {
230 // The following is cloned from contrib/forms/scanned_notes/new.php:
232 $query = "INSERT INTO form_scanned_notes ( notes ) VALUES ( ? )";
233 $formid = sqlInsert($query, array($_POST['form_copy_sn_comments']));
234 addForm(
235 $encounter_id,
236 "Scanned Notes",
237 $formid,
238 "scanned_notes",
239 $patient_id,
240 $userauthorized
243 $imagedir = $GLOBALS['OE_SITE_DIR'] . "/documents/" . check_file_dir_name($patient_id) . "/encounters";
244 $imagepath = "$imagedir/" . check_file_dir_name($encounter_id) . "_" . check_file_dir_name($formid) . ".jpg";
245 if (! is_dir($imagedir)) {
246 $tmp0 = exec('mkdir -p ' . escapeshellarg($imagedir), $tmp1, $tmp2);
247 if ($tmp2) {
248 die("mkdir returned " . text($tmp2) . ": " . text($tmp0));
251 exec("touch " . escapeshellarg($imagedir."/index.html"));
254 if (is_file($imagepath)) {
255 unlink($imagepath);
258 // TBD: There may be a faster way to create this file, given that
259 // we already have a jpeg for each page in faxcache.
260 $cmd = "convert -resize 800 -density 96 " . escapeshellarg($tmp_name) . " -append " . escapeshellarg($imagepath);
261 $tmp0 = exec($cmd, $tmp1, $tmp2);
262 if ($tmp2) {
263 die("\"" . text($cmd) . "\" returned " . text($tmp2) . ": " . text($tmp0));
267 // If we are posting a patient note...
268 if ($_POST['form_cb_note'] && !$info_msg) {
269 $note = "New scanned encounter note for visit on " . substr($erow['date'], 0, 10);
270 $form_note_message = trim($_POST['form_note_message']);
271 if ($form_note_message) {
272 $note .= "\n" . $form_note_message;
275 addPnote(
276 $patient_id,
277 $note,
278 $userauthorized,
279 '1',
280 $_POST['form_note_type'],
281 $_POST['form_note_to']
283 } // end post patient note
286 $action_taken = true;
287 } // end copy to chart
289 if ($_POST['form_cb_forward']) {
290 $form_from = trim($_POST['form_from']);
291 $form_to = trim($_POST['form_to']);
292 $form_fax = trim($_POST['form_fax']);
293 $form_message = trim($_POST['form_message']);
294 $form_finemode = $_POST['form_finemode'] ? '-m' : '-l';
296 // Generate a cover page using enscript. This can be a cool thing
297 // to do, as enscript is very powerful.
299 $tmp1 = array();
300 $tmp2 = 0;
301 $tmpfn1 = tempnam("/tmp", "fax1");
302 $tmpfn2 = tempnam("/tmp", "fax2");
303 $tmph = fopen($tmpfn1, "w");
304 $cpstring = '';
305 $fh = fopen($GLOBALS['OE_SITE_DIR'] . "/faxcover.txt", 'r');
306 while (!feof($fh)) {
307 $cpstring .= fread($fh, 8192);
310 fclose($fh);
311 $cpstring = str_replace('{CURRENT_DATE}', date('F j, Y'), $cpstring);
312 $cpstring = str_replace('{SENDER_NAME}', $form_from, $cpstring);
313 $cpstring = str_replace('{RECIPIENT_NAME}', $form_to, $cpstring);
314 $cpstring = str_replace('{RECIPIENT_FAX}', $form_fax, $cpstring);
315 $cpstring = str_replace('{MESSAGE}', $form_message, $cpstring);
316 fwrite($tmph, $cpstring);
317 fclose($tmph);
318 $tmp0 = exec("cd " . escapeshellarg($webserver_root.'/custom') . "; " . escapeshellcmd($GLOBALS['hylafax_enscript']) .
319 " -o " . escapeshellarg($tmpfn2) . " " . escapeshellarg($tmpfn1), $tmp1, $tmp2);
320 if ($tmp2) {
321 $info_msg .= "enscript returned $tmp2: $tmp0 ";
324 unlink($tmpfn1);
326 // Send the fax as the cover page followed by the selected pages.
327 $info_msg .= mergeTiffs();
328 $tmp0 = exec(
329 "sendfax -A -n " . escapeshellarg($form_finemode) . " -d " .
330 escapeshellarg($form_fax) . " " . escapeshellarg($tmpfn2) . " " . escapeshellarg($faxcache.'/temp.tif'),
331 $tmp1,
332 $tmp2
334 if ($tmp2) {
335 $info_msg .= "sendfax returned $tmp2: $tmp0 ";
338 unlink($tmpfn2);
340 $action_taken = true;
341 } // end forward
343 $form_cb_delete = $_POST['form_cb_delete'];
345 // If deleting selected, do it and then check if any are left.
346 if ($form_cb_delete == '1' && !$info_msg) {
347 foreach ($_POST['form_images'] as $inbase) {
348 check_file_dir_name($inbase);
349 unlink($faxcache . "/" . $inbase . ".jpg");
350 $action_taken = true;
353 // Check if any .jpg files remain... if not we'll clean up.
354 if ($action_taken) {
355 $dh = opendir($faxcache);
356 if (! $dh) {
357 die("Cannot read " . text($faxcache));
360 $form_cb_delete = '2';
361 while (false !== ($jfname = readdir($dh))) {
362 if (preg_match('/\.jpg$/', $jfname)) {
363 $form_cb_delete = '1';
367 closedir($dh);
369 } // end delete 1
371 if ($form_cb_delete == '2' && !$info_msg) {
372 // Delete the tiff file, with archiving if desired.
373 if ($GLOBALS['hylafax_archdir'] && $mode == 'fax') {
374 rename($filepath, $GLOBALS['hylafax_archdir'] . '/' . $filename);
375 } else {
376 unlink($filepath);
379 // Erase its cache.
380 if (is_dir($faxcache)) {
381 $dh = opendir($faxcache);
382 while (($tmp = readdir($dh)) !== false) {
383 if (is_file("$faxcache/$tmp")) {
384 unlink("$faxcache/$tmp");
388 closedir($dh);
389 rmdir($faxcache);
392 $action_taken = true;
393 } // end delete 2
395 if (!$action_taken && !$info_msg) {
396 $info_msg = xl('You did not choose any actions.');
399 if ($info_msg || $form_cb_delete != '1') {
400 // Close this window and refresh the fax list.
401 echo "<html>\n<body>\n<script language='JavaScript'>\n";
402 if ($info_msg) {
403 echo " alert('" . addslashes($info_msg) . "');\n";
406 echo " if (!opener.closed && opener.refreshme) opener.refreshme();\n";
407 echo " window.close();\n";
408 echo "</script>\n</body>\n</html>\n";
409 exit();
411 } // end submit logic
413 // If we get this far then we are displaying the form.
415 // Find out if the scanned_notes form is installed and active.
417 $tmp = sqlQuery("SELECT count(*) AS count FROM registry WHERE " .
418 "directory LIKE 'scanned_notes' AND state = 1 AND sql_run = 1");
419 $using_scanned_notes = $tmp['count'];
421 // If the image cache does not yet exist for this fax, build it.
422 // This will contain a .tif image as well as a .jpg image for each page.
424 if (! is_dir($faxcache)) {
425 $tmp0 = exec('mkdir -p ' . escapeshellarg($faxcache), $tmp1, $tmp2);
426 if ($tmp2) {
427 die("mkdir returned " . text($tmp2) . ": " . text($tmp0));
430 if (strtolower($ext) != '.tif') {
431 // convert's default density for PDF-to-TIFF conversion is 72 dpi which is
432 // not very good, so we upgrade it to "fine mode" fax quality. It's really
433 // better and faster if the scanner produces TIFFs instead of PDFs.
434 $tmp0 = exec("convert -density 203x196 " . escapeshellarg($filepath) . " " . escapeshellarg($faxcache.'/deleteme.tif'), $tmp1, $tmp2);
435 if ($tmp2) {
436 die("convert returned " . text($tmp2) . ": " . text($tmp0));
439 $tmp0 = exec("cd " . escapeshellarg($faxcache) . "; tiffsplit 'deleteme.tif'; rm -f 'deleteme.tif'", $tmp1, $tmp2);
440 if ($tmp2) {
441 die("tiffsplit/rm returned " . text($tmp2) . ": " . text($tmp0));
443 } else {
444 $tmp0 = exec("cd " . escapeshellarg($faxcache) . "; tiffsplit " . escapeshellarg($filepath), $tmp1, $tmp2);
445 if ($tmp2) {
446 die("tiffsplit returned " . text($tmp2) . ": " . text($tmp0));
450 $tmp0 = exec("cd " . escapeshellarg($faxcache) . "; mogrify -resize 750x970 -format jpg *.tif", $tmp1, $tmp2);
451 if ($tmp2) {
452 die("mogrify returned " . text($tmp2) . ": " . text($tmp0) . "; ext is '" . text($ext) . "'; filepath is '" . text($filepath) . "'");
456 // Get the categories list.
457 $categories = array();
458 getKittens(0, '', $categories);
460 // Get the users list.
461 $ures = sqlStatement("SELECT username, fname, lname FROM users " .
462 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
463 "ORDER BY lname, fname");
465 <html>
466 <head>
468 <?php Header::setupHeader(['opener', 'datetime-picker', 'jquery-ui']);?>
469 <title><?php echo xlt('Dispatch Received Document'); ?></title>
471 <style>
473 td, input, select, textarea {
474 font-size: 10pt;
477 .itemtitle {
478 font-weight: bold;
481 div.section {
482 border: solid;
483 border-width: 1px;
484 border-color: #0000ff;
485 margin-left: 2em;
486 padding: 1em;
489 </style>
491 <script language="JavaScript">
493 <?php require($GLOBALS['srcdir'] . "/restoreSession.php"); ?>
495 function divclick(cb, divid) {
496 var divstyle = document.getElementById(divid).style;
497 if (cb.checked) {
498 if (divid == 'div_copy_doc') {
499 document.getElementById('div_copy_sn').style.display = 'none';
501 else if (divid == 'div_copy_sn') {
502 document.getElementById('div_copy_doc').style.display = 'none';
504 divstyle.display = 'block';
505 } else {
506 divstyle.display = 'none';
508 return true;
511 // This is for callback by the find-patient popup.
512 function setpatient(pid, lname, fname, dob) {
513 var f = document.forms[0];
514 f.form_patient.value = lname + ', ' + fname;
515 f.form_pid.value = pid;
516 <?php if ($using_scanned_notes) { ?>
517 // This loads the patient's list of recent encounters:
518 f.form_copy_sn_visit.options.length = 0;
519 f.form_copy_sn_visit.options[0] = new Option('Loading...', '0');
520 $.getScript("fax_dispatch_newpid.php?p=" + encodeURIComponent(pid) + "&csrf_token_form=" + <?php echo js_url(collectCsrfToken()); ?>);
521 <?php } ?>
524 // This invokes the find-patient popup.
525 function sel_patient() {
526 dlgopen('../main/calendar/find_patient_popup.php', '_blank', 750, 550, false, 'Select Patient');
529 // Check for errors when the form is submitted.
530 function validate() {
531 var f = document.forms[0];
533 if (f.form_cb_copy.checked) {
534 if (! f.form_pid.value) {
535 alert('You have not selected a patient!');
536 return false;
540 if (f.form_cb_forward.checked) {
541 var s = f.form_fax.value;
542 if (! s) {
543 alert('A fax number is required!');
544 return false;
546 var digcount = 0;
547 for (var i = 0; i < s.length; ++i) {
548 var c = s.charAt(i);
549 if (c >= '0' && c <= '9') {
550 ++digcount;
552 else if (digcount == 0 || c != '-') {
553 alert('Invalid character(s) in fax number!');
554 return false;
557 if (digcount == 7) {
558 if (s.charAt(0) < '2') {
559 alert('Local phone number starts with an invalid digit!');
560 return false;
563 else if (digcount == 11) {
564 if (s.charAt(0) != '1') {
565 alert('11-digit number must begin with 1!');
566 return false;
569 else if (digcount == 10) {
570 if (s.charAt(0) < '2') {
571 alert('10-digit number starts with an invalid digit!');
572 return false;
574 f.form_fax.value = '1' + s;
576 else {
577 alert('Invalid number of digits in fax telephone number!');
578 return false;
582 if (f.form_cb_copy.checked || f.form_cb_forward.checked) {
583 var check_count = 0;
584 for (var i = 0; i < f.elements.length; ++i) {
585 if (f.elements[i].name == 'form_images[]' && f.elements[i].checked)
586 ++check_count;
588 if (check_count == 0) {
589 alert('No pages have been selected!');
590 return false;
594 top.restoreSession();
595 return true;
598 function allCheckboxes(issel) {
599 var f = document.forms[0];
600 for (var i = 0; i < f.elements.length; ++i) {
601 if (f.elements[i].name == 'form_images[]') f.elements[i].checked = issel;
605 $(document).ready(function(){
606 $('.datepicker').datetimepicker({
607 <?php $datetimepicker_timepicker = false; ?>
608 <?php $datetimepicker_showseconds = false; ?>
609 <?php $datetimepicker_formatInput = false; ?>
610 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
611 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
614 </script>
616 </head>
618 <body class="body_top" onunload='imclosing()'>
620 <center><h2><?php echo xlt('Dispatch Received Document'); ?></h2></center>
622 <form method='post' name='theform'
623 action='fax_dispatch.php?<?php echo ($mode == 'fax') ? 'file' : 'scan'; ?>=<?php echo attr_url($filename); ?>' onsubmit='return validate()'>
624 <input type="hidden" name="csrf_token_form" value="<?php echo attr(collectCsrfToken()); ?>" />
626 <p><input type='checkbox' name='form_cb_copy' value='1'
627 onclick='return divclick(this,"div_copy");' />
628 <b><?php echo xlt('Copy Pages to Patient Chart'); ?></b></p>
630 <div id='div_copy' class='section' style='display:none;'>
631 <table>
632 <tr>
633 <td class='itemtitle' width='1%' nowrap><?php echo xlt('Patient'); ?></td>
634 <td>
635 <input type='text' size='10' name='form_patient' style='width:100%'
636 value=' (<?php echo xla('Click to select'); ?>)' onclick='sel_patient()'
637 title='<?php echo xla('Click to select patient'); ?>' readonly />
638 <input type='hidden' name='form_pid' value='0' />
639 </td>
640 </tr>
641 <tr>
642 <td colspan='2' style='padding-top:0.5em;'>
643 <input type='radio' name='form_cb_copy_type' value='1'
644 onclick='return divclick(this,"div_copy_doc");' checked />
645 <b><?php echo xlt('Patient Document'); ?></b>&nbsp;
646 <?php if ($using_scanned_notes) { ?>
647 <input type='radio' name='form_cb_copy_type' value='2'
648 onclick='return divclick(this,"div_copy_sn");' />
649 <b><?php echo xlt('Scanned Encounter Note'); ?></b>
650 <?php } ?>
651 <div id='div_copy_doc' class='section' style='margin-top:0.5em;'>
652 <table width='100%'>
653 <tr>
654 <td class='itemtitle' nowrap><?php echo xlt('Category'); ?></td>
655 <td>
656 <select name='form_category' style='width:100%'>
657 <?php
658 foreach ($categories as $catkey => $catname) {
659 echo " <option value='" . attr($catkey) . "'";
660 echo ">" . text($catname) . "</option>\n";
663 </select>
664 </td>
665 </tr>
666 <tr>
667 <td class='itemtitle' nowrap><?php echo xlt('Filename'); ?></td>
668 <td>
669 <input type='text' size='10' name='form_filename' style='width:100%'
670 value='<?php echo attr($filebase) . ".pdf" ?>'
671 title='Name for this document in the patient chart' />
672 </td>
673 </tr>
674 <tr>
675 <td class='itemtitle' nowrap><?php echo xlt('Document Date'); ?></td>
676 <td>
677 <input type='text' class='datepicker' size='10' name='form_docdate' id='form_docdate'
678 value='<?php echo date('Y-m-d'); ?>'
679 title='<?php echo xla('yyyy-mm-dd date associated with this document'); ?>' />
680 </td>
681 </tr>
682 </table>
683 </div><!-- end div_copy_doc -->
684 <div id='div_copy_sn' class='section' style='display:none;margin-top:0.5em;'>
685 <table width='100%'>
686 <tr>
687 <td class='itemtitle' width='1%' nowrap><?php echo xlt('Visit Date'); ?></td>
688 <td>
689 <select name='form_copy_sn_visit' style='width:100%'>
690 </select>
691 </td>
692 </tr>
693 <tr>
694 <td class='itemtitle' width='1%' nowrap><?php echo xlt('Comments'); ?></td>
695 <td>
696 <textarea name='form_copy_sn_comments' rows='3' cols='30' style='width:100%'
697 title='Comments associated with this scanned note'
698 /></textarea>
699 </td>
700 </tr>
701 </table>
702 </div><!-- end div_copy_sn -->
703 </td>
704 </tr>
705 <tr>
706 <td colspan='2' style='padding-top:0.5em;'>
707 <input type='checkbox' name='form_cb_note' value='1'
708 onclick='return divclick(this,"div_note");' />
709 <b><?php echo xlt('Create Patient Note'); ?></b>
710 <div id='div_note' class='section' style='display:none;margin-top:0.5em;'>
711 <table>
712 <tr>
713 <td class='itemtitle' width='1%' nowrap><?php echo xlt('Type'); ?></td>
714 <td>
715 <?php
716 // Added 6/2009 by BM to incorporate the patient notes into the list_options listings
717 generate_form_field(array('data_type'=>1,'field_id'=>'note_type','list_id'=>'note_type','empty_title'=>'SKIP'), '');
719 </td>
720 </tr>
721 <tr>
722 <td class='itemtitle' width='1%' nowrap>To</td>
723 <td>
724 <select name='form_note_to' style='width:100%'>
725 <?php
726 while ($urow = sqlFetchArray($ures)) {
727 echo " <option value='" . attr($urow['username']) . "'";
728 echo ">" . text($urow['lname']);
729 if ($urow['fname']) {
730 echo ", " . text($urow['fname']);
733 echo "</option>\n";
736 <option value=''>** <?php echo xlt('Close'); ?> **</option>
737 </select>
738 </td>
739 </tr>
740 <tr>
741 <td class='itemtitle' nowrap><?php echo xlt('Message'); ?></td>
742 <td>
743 <textarea name='form_note_message' rows='3' cols='30' style='width:100%'
744 title='Your comments' /></textarea>
745 </td>
746 </tr>
747 </table>
748 </div><!-- end div_note -->
749 </td>
750 </tr>
751 </table>
752 </div><!-- end div_copy -->
754 <p><input type='checkbox' name='form_cb_forward' value='1'
755 onclick='return divclick(this,"div_forward");' />
756 <b><?php echo xlt('Forward Pages via Fax'); ?></b></p>
758 <div id='div_forward' class='section' style='display:none;'>
759 <table>
760 <tr>
761 <td class='itemtitle' width='1%' nowrap><?php echo xlt('From'); ?></td>
762 <td>
763 <input type='text' size='10' name='form_from' style='width:100%'
764 title='Type your name here' />
765 </td>
766 </tr>
767 <tr>
768 <td class='itemtitle' nowrap><?php echo xlt('To'); ?></td>
769 <td>
770 <input type='text' size='10' name='form_to' style='width:100%'
771 title='Type the recipient name here' />
772 </td>
773 </tr>
774 <tr>
775 <td class='itemtitle' nowrap><?php echo xlt('Fax'); ?></td>
776 <td>
777 <input type='text' size='10' name='form_fax' style='width:100%'
778 title='The fax phone number to send this to' />
779 </td>
780 </tr>
781 <tr>
782 <td class='itemtitle' nowrap><?php echo xlt('Message'); ?></td>
783 <td>
784 <textarea name='form_message' rows='3' cols='30' style='width:100%'
785 title='Your comments to include with this message' /></textarea>
786 </td>
787 </tr>
788 <tr>
789 <td class='itemtitle' nowrap><?php echo xlt('Quality'); ?></td>
790 <td>
791 <input type='radio' name='form_finemode' value='' /><?php echo xlt('Normal'); ?> &nbsp;
792 <input type='radio' name='form_finemode' value='1' checked /><?php echo xlt('Fine'); ?> &nbsp;
793 </td>
794 </tr>
795 </table>
796 </div><!-- end div_forward -->
798 <p><b><?php echo xlt('Delete Pages'); ?>:</b>&nbsp;
799 <input type='radio' name='form_cb_delete' value='2' />All&nbsp;
800 <input type='radio' name='form_cb_delete' value='1' checked />Selected&nbsp;
801 <input type='radio' name='form_cb_delete' value='0' />None
802 </p>
804 <center>
806 <input type='submit' name='form_save' value='<?php echo xla('OK'); ?>' />
807 &nbsp; &nbsp;
808 <input type='button' value='<?php echo xla('Cancel'); ?>' onclick='window.close()' />
809 &nbsp; &nbsp;
810 <input type='button' value='<?php echo xla('Select All'); ?>' onclick='allCheckboxes(true)' />
811 &nbsp; &nbsp;
812 <input type='button' value='<?php echo xla('Clear All'); ?>' onclick='allCheckboxes(false)' />
813 </p>
815 <p><br /><b><?php echo xlt('Please select the desired pages to copy or forward:'); ?></b></p>
816 <table>
818 <?php
819 $dh = opendir($faxcache);
820 if (! $dh) {
821 die("Cannot read " . text($faxcache));
824 $jpgarray = array();
825 while (false !== ($jfname = readdir($dh))) {
826 if (preg_match("/^(.*)\.jpg/", $jfname, $matches)) {
827 $jpgarray[$matches[1]] = $jfname;
831 closedir($dh);
832 // readdir does not read in any particular order, we must therefore sort
833 // by filename so the display order matches the original document.
834 ksort($jpgarray);
835 $page = 0;
836 foreach ($jpgarray as $jfnamebase => $jfname) {
837 ++$page;
838 echo " <tr>\n";
839 echo " <td valign='top'>\n";
840 echo " <img src='../../sites/" . attr($_SESSION['site_id']) . "/faxcache/" . attr($mode) . "/" . attr($filebase) . "/" . attr($jfname) . "' />\n";
841 echo " </td>\n";
842 echo " <td align='center' valign='top'>\n";
843 echo " <input type='checkbox' name='form_images[]' value='" . attr($jfnamebase) . "' checked />\n";
844 echo " <br />" . text($page) . "\n";
845 echo " </td>\n";
846 echo " </tr>\n";
850 </table>
851 </center>
852 </form>
853 </body>
854 </html>