minor changes to prior commit
[openemr.git] / interface / patient_file / letter.php
blobbd24e7074664cc2adc3958baabaa0178340c1508
1 <?php
2 /**
3 * letter.php
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) 2007-2011 Rod Roark <rod@sunsetsystems.com>
10 * @copyright Copyright (c) 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($GLOBALS['srcdir'] . "/patient.inc");
18 use OpenEMR\Core\Header;
20 $template_dir = $GLOBALS['OE_SITE_DIR'] . "/letter_templates";
22 // array of field name tags to allow internationalization
23 // of templates
24 $FIELD_TAG = array(
25 'DATE' => xl('DATE'),
26 'FROM_TITLE' => xl('FROM_TITLE'),
27 'FROM_FNAME' => xl('FROM_FNAME'),
28 'FROM_LNAME' => xl('FROM_LNAME'),
29 'FROM_MNAME' => xl('FROM_MNAME'),
30 'FROM_STREET' => xl('FROM_STREET'),
31 'FROM_CITY' => xl('FROM_CITY'),
32 'FROM_STATE' => xl('FROM_STATE'),
33 'FROM_POSTAL' => xl('FROM_POSTAL'),
34 'FROM_VALEDICTORY' => xl('FROM_VALEDICTORY'),
35 'FROM_PHONE' => xl('FROM_PHONE'),
36 'FROM_PHONECELL' => xl('FROM_PHONECELL'),
37 'FROM_EMAIL' => xl('FROM_EMAIL'),
38 'TO_TITLE' => xl('TO_TITLE'),
39 'TO_FNAME' => xl('TO_FNAME'),
40 'TO_LNAME' => xl('TO_LNAME'),
41 'TO_MNAME' => xl('TO_MNAME'),
42 'TO_STREET' => xl('TO_STREET'),
43 'TO_CITY' => xl('TO_CITY'),
44 'TO_STATE' => xl('TO_STATE'),
45 'TO_POSTAL' => xl('TO_POSTAL'),
46 'TO_VALEDICTORY' => xl('TO_VALEDICTORY'),
47 'TO_PHONE' => xl('TO_PHONE'),
48 'TO_PHONECELL' => xl('TO_PHONECELL'),
49 'TO_FAX' => xl('TO_FAX'),
50 'TO_ORGANIZATION' => xl('TO_ORGANIZATION'),
51 'PT_FNAME' => xl('PT_FNAME'),
52 'PT_LNAME' => xl('PT_LNAME'),
53 'PT_MNAME' => xl('PT_MNAME'),
54 'PT_STREET' => xl('PT_STREET'),
55 'PT_CITY' => xl('PT_CITY'),
56 'PT_STATE' => xl('PT_STATE'),
57 'PT_POSTAL' => xl('PT_POSTAL'),
58 'PT_PHONE_HOME' => xl('PT_PHONE_HOME'),
59 'PT_PHONE_CELL' => xl('PT_PHONE_CELL'),
60 'PT_SSN' => xl('PT_SSN'),
61 'PT_EMAIL' => xl('PT_EMAIL'),
62 'PT_DOB' => xl('PT_DOB')
66 $patdata = sqlQuery("SELECT " .
67 "p.fname, p.mname, p.lname, p.pubpid, p.DOB, " .
68 "p.street, p.city, p.state, p.phone_home, p.phone_cell, p.ss, p.email, p.postal_code " .
69 "FROM patient_data AS p " .
70 "WHERE p.pid = ? LIMIT 1", array($pid));
72 $alertmsg = ''; // anything here pops up in an alert box
74 // If the Generate button was clicked...
75 if ($_POST['formaction']=="generate") {
76 $form_pid = $_POST['form_pid'];
77 $form_from = $_POST['form_from'];
78 $form_to = $_POST['form_to'];
79 $form_date = $_POST['form_date'];
80 $form_template = $_POST['form_template'];
81 $form_format = $_POST['form_format'];
82 $form_body = $_POST['form_body'];
84 $frow = sqlQuery("SELECT * FROM users WHERE id = ?", array($form_from));
85 $trow = sqlQuery("SELECT * FROM users WHERE id = ?", array($form_to));
87 $datestr = $form_date;
88 $from_title = $frow['title'] ? $frow['title'] . ' ' : '';
89 $to_title = $trow['title'] ? $trow['title'] . ' ' : '';
91 $cpstring = $_POST['form_body'];
93 // attempt to save to the autosaved template
94 $fh = fopen("$template_dir/autosaved", 'w');
95 // translate from definition to the constant
96 $temp_bodytext = $cpstring;
97 foreach ($FIELD_TAG as $key => $value) {
98 $temp_bodytext = str_replace("{".$value."}", "{".$key."}", $temp_bodytext);
101 if (! fwrite($fh, $temp_bodytext)) {
102 echo xl('Error while saving to the file', '', '', ' ') . $template_dir."/autosaved" .
103 xl('Ensure OpenEMR has write privileges to directory', '', ' . ', ' ') . $template_dir . "/ ." ;
104 die;
107 fclose($fh);
109 $cpstring = str_replace('{'.$FIELD_TAG['DATE'].'}', $datestr, $cpstring);
110 $cpstring = str_replace('{'.$FIELD_TAG['FROM_TITLE'].'}', $from_title, $cpstring);
111 $cpstring = str_replace('{'.$FIELD_TAG['FROM_FNAME'].'}', $frow['fname'], $cpstring);
112 $cpstring = str_replace('{'.$FIELD_TAG['FROM_LNAME'].'}', $frow['lname'], $cpstring);
113 $cpstring = str_replace('{'.$FIELD_TAG['FROM_MNAME'].'}', $frow['mname'], $cpstring);
114 $cpstring = str_replace('{'.$FIELD_TAG['FROM_STREET'].'}', $frow['street'], $cpstring);
115 $cpstring = str_replace('{'.$FIELD_TAG['FROM_CITY'].'}', $frow['city'], $cpstring);
116 $cpstring = str_replace('{'.$FIELD_TAG['FROM_STATE'].'}', $frow['state'], $cpstring);
117 $cpstring = str_replace('{'.$FIELD_TAG['FROM_POSTAL'].'}', $frow['zip'], $cpstring);
118 $cpstring = str_replace('{'.$FIELD_TAG['FROM_VALEDICTORY'].'}', $frow['valedictory'], $cpstring);
119 $cpstring = str_replace('{'.$FIELD_TAG['FROM_PHONECELL'].'}', $frow['phonecell'], $cpstring);
120 $cpstring = str_replace('{'.$FIELD_TAG['FROM_PHONE'].'}', $frow['phone'], $cpstring);
121 $cpstring = str_replace('{'.$FIELD_TAG['FROM_EMAIL'].'}', $frow['email'], $cpstring);
122 $cpstring = str_replace('{'.$FIELD_TAG['TO_TITLE'].'}', $to_title, $cpstring);
123 $cpstring = str_replace('{'.$FIELD_TAG['TO_FNAME'].'}', $trow['fname'], $cpstring);
124 $cpstring = str_replace('{'.$FIELD_TAG['TO_LNAME'].'}', $trow['lname'], $cpstring);
125 $cpstring = str_replace('{'.$FIELD_TAG['TO_MNAME'].'}', $trow['mname'], $cpstring);
126 $cpstring = str_replace('{'.$FIELD_TAG['TO_STREET'].'}', $trow['street'], $cpstring);
127 $cpstring = str_replace('{'.$FIELD_TAG['TO_CITY'].'}', $trow['city'], $cpstring);
128 $cpstring = str_replace('{'.$FIELD_TAG['TO_STATE'].'}', $trow['state'], $cpstring);
129 $cpstring = str_replace('{'.$FIELD_TAG['TO_POSTAL'].'}', $trow['zip'], $cpstring);
130 $cpstring = str_replace('{'.$FIELD_TAG['TO_VALEDICTORY'].'}', $trow['valedictory'], $cpstring);
131 $cpstring = str_replace('{'.$FIELD_TAG['TO_FAX'].'}', $trow['fax'], $cpstring);
132 $cpstring = str_replace('{'.$FIELD_TAG['TO_PHONE'].'}', $trow['phone'], $cpstring);
133 $cpstring = str_replace('{'.$FIELD_TAG['TO_PHONECELL'].'}', $trow['phonecell'], $cpstring);
134 $cpstring = str_replace('{'.$FIELD_TAG['TO_ORGANIZATION'].'}', $trow['organization'], $cpstring);
135 $cpstring = str_replace('{'.$FIELD_TAG['PT_FNAME'].'}', $patdata['fname'], $cpstring);
136 $cpstring = str_replace('{'.$FIELD_TAG['PT_LNAME'].'}', $patdata['lname'], $cpstring);
137 $cpstring = str_replace('{'.$FIELD_TAG['PT_MNAME'].'}', $patdata['mname'], $cpstring);
138 $cpstring = str_replace('{'.$FIELD_TAG['PT_STREET'].'}', $patdata['street'], $cpstring);
139 $cpstring = str_replace('{'.$FIELD_TAG['PT_CITY'].'}', $patdata['city'], $cpstring);
140 $cpstring = str_replace('{'.$FIELD_TAG['PT_STATE'].'}', $patdata['state'], $cpstring);
141 $cpstring = str_replace('{'.$FIELD_TAG['PT_POSTAL'].'}', $patdata['postal_code'], $cpstring);
142 $cpstring = str_replace('{'.$FIELD_TAG['PT_PHONE_HOME'].'}', $patdata['phone_home'], $cpstring);
143 $cpstring = str_replace('{'.$FIELD_TAG['PT_PHONE_CELL'].'}', $patdata['phone_cell'], $cpstring);
144 $cpstring = str_replace('{'.$FIELD_TAG['PT_SSN'].'}', $patdata['ss'], $cpstring);
145 $cpstring = str_replace('{'.$FIELD_TAG['PT_EMAIL'].'}', $patdata['email'], $cpstring);
146 $cpstring = str_replace('{'.$FIELD_TAG['PT_DOB'].'}', $patdata['DOB'], $cpstring);
148 if ($form_format == "pdf") {
149 $pdf = new Cezpdf($GLOBALS['rx_paper_size']);
150 $pdf->ezSetMargins($GLOBALS['rx_top_margin'], $GLOBALS['rx_bottom_margin'], $GLOBALS['rx_left_margin'], $GLOBALS['rx_right_margin']);
151 if (file_exists("$template_dir/custom_pdf.php")) {
152 include("$template_dir/custom_pdf.php");
153 } else {
154 $pdf->selectFont('Helvetica');
155 $pdf->ezText($cpstring, 12);
158 $pdf->ezStream();
159 exit;
160 } else { // $form_format = html
161 $cpstring = text($cpstring); //escape to prevent stored cross script attack
162 $cpstring = str_replace("\n", "<br>", $cpstring);
163 $cpstring = str_replace("\t", "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;", $cpstring);
165 <html>
166 <head>
167 <style>
168 body {
169 font-family: sans-serif;
170 font-weight: normal;
171 font-size: 12pt;
172 background: white;
173 color: black;
175 .paddingdiv {
176 width: 524pt;
177 padding: 0pt;
178 margin-top: 50pt;
180 .navigate {
181 margin-top: 2.5em;
183 @media print {
184 .navigate {
185 display: none;
188 </style>
189 <title><?php echo xlt('Letter'); ?></title>
190 </head>
191 <body>
192 <div class='paddingdiv'>
193 <?php echo $cpstring; ?>
194 <div class="navigate">
195 <a href='<?php echo $GLOBALS['rootdir'] . '/patient_file/letter.php?template=autosaved'; ?>' onclick='top.restoreSession()'>(<?php echo xlt('Back'); ?>)</a>
196 </div>
197 <script language='JavaScript'>
198 window.print();
199 </script>
200 </body>
201 </div>
202 <?php
203 exit;
205 } else if (isset($_GET['template']) && $_GET['template'] != "") {
206 // utilized to go back to autosaved template
207 $bodytext = "";
208 $fh = fopen("$template_dir/" . convert_very_strict_label($_GET['template']), 'r');
210 if (!$fh) {
211 die(xlt("Requested template does not exist"));
214 while (!feof($fh)) {
215 $bodytext.= fread($fh, 8192);
218 fclose($fh);
219 // translate from constant to the definition
220 foreach ($FIELD_TAG as $key => $value) {
221 $bodytext = str_replace("{".$key."}", "{".$value."}", $bodytext);
223 } else if ($_POST['formaction'] == "loadtemplate" && $_POST['form_template'] != "") {
224 $bodytext = "";
225 $fh = fopen("$template_dir/" . convert_very_strict_label($_POST['form_template']), 'r');
227 if (!$fh) {
228 die(xlt("Requested template does not exist"));
231 while (!feof($fh)) {
232 $bodytext.= fread($fh, 8192);
235 fclose($fh);
236 // translate from constant to the definition
237 foreach ($FIELD_TAG as $key => $value) {
238 $bodytext = str_replace("{".$key."}", "{".$value."}", $bodytext);
240 } else if ($_POST['formaction'] == "newtemplate" && $_POST['newtemplatename'] != "") {
241 // attempt to save the template
242 $fh = fopen("$template_dir/" . convert_very_strict_label($_POST['newtemplatename']), 'w');
243 // translate from definition to the constant
244 $temp_bodytext = $_POST['form_body'];
245 foreach ($FIELD_TAG as $key => $value) {
246 $temp_bodytext = str_replace("{".$value."}", "{".$key."}", $temp_bodytext);
249 if (! fwrite($fh, $temp_bodytext)) {
250 echo xlt('Error while writing to file') . ' ' . $template_dir."/" . $_POST['newtemplatename'];
251 die;
254 fclose($fh);
256 // read the saved file back
257 $_POST['form_template'] = $_POST['newtemplatename'];
258 $fh = fopen("$template_dir/" . convert_very_strict_label($_POST['form_template']), 'r');
260 if (!$fh) {
261 die(xlt("Requested template does not exist"));
264 while (!feof($fh)) {
265 $bodytext.= fread($fh, 8192);
268 fclose($fh);
269 // translate from constant to the definition
270 foreach ($FIELD_TAG as $key => $value) {
271 $bodytext = str_replace("{".$key."}", "{".$value."}", $bodytext);
273 } else if ($_POST['formaction'] == "savetemplate" && $_POST['form_template'] != "") {
274 // attempt to save the template
275 $fh = fopen("$template_dir/" . convert_very_strict_label($_POST['form_template']), 'w');
276 // translate from definition to the constant
277 $temp_bodytext = $_POST['form_body'];
278 foreach ($FIELD_TAG as $key => $value) {
279 $temp_bodytext = str_replace("{".$value."}", "{".$key."}", $temp_bodytext);
282 if (! fwrite($fh, $temp_bodytext)) {
283 echo xlt('Error while writing to file') . ' ' . $template_dir."/".$_POST['form_template'];
284 die;
287 fclose($fh);
289 // read the saved file back
290 $fh = fopen("$template_dir/" . convert_very_strict_label($_POST['form_template']), 'r');
292 if (!$fh) {
293 die(xlt("Requested template does not exist"));
296 while (!feof($fh)) {
297 $bodytext.= fread($fh, 8192);
300 fclose($fh);
301 // translate from constant to the definition
302 foreach ($FIELD_TAG as $key => $value) {
303 $bodytext = str_replace("{".$key."}", "{".$value."}", $bodytext);
307 // This is the case where we display the form for data entry.
308 // Get the users list.
309 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
310 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
311 "ORDER BY lname, fname");
312 $i = 0;
313 $optfrom = '';
314 $optto = '';
315 $ulist = "var ulist = new Array();\n";
316 while ($urow = sqlFetchArray($ures)) {
317 $uname = $urow['lname'];
318 if ($urow['fname']) {
319 $uname .= ", " . $urow['fname'];
322 $tmp1 = " <option value='" . attr($urow['id']) . "'";
323 $tmp2 = ">" . text($uname) . "</option>\n";
324 $optto .= $tmp1 . $tmp2;
325 if ($urow['id'] == $_SESSION['authUserID']) {
326 $tmp1 .= " selected";
329 $optfrom .= $tmp1 . $tmp2;
330 $ulist .= "ulist[$i] = '" . attr($uname) . "|" .
331 attr($urow['id']) . "|" . attr($urow['specialty']) . "';\n";
332 ++$i;
335 // Get the unique specialties.
336 $sres = sqlStatement("SELECT DISTINCT specialty FROM users " .
337 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
338 "ORDER BY specialty");
339 $optspec = "<option value='All'>" . xlt('All') . "</option>\n";
340 while ($srow = sqlFetchArray($sres)) {
341 $optspec .= " <option value='" . attr($srow['specialty']) . "'>" .
342 text($srow['specialty']) . "</option>\n";
346 <html>
347 <head>
348 <title><?php echo xlt('Letter Generator'); ?></title>
349 <?php Header::setupHeader(['datetime-picker', 'topdialog']); ?>
351 <script language="JavaScript">
352 <?php echo $ulist; ?>
354 // React to selection of a specialty. This rebuilds the "to" users list
355 // with users having that specialty, or all users if "All" is selected.
356 function newspecialty() {
357 var f = document.forms[0];
358 var s = f.form_specialty.value;
359 var theopts = f.form_to.options;
360 theopts.length = 0;
361 var j = 0;
362 for (var i = 0; i < ulist.length; ++i) {
363 tmp = ulist[i].split("|");
364 if (s != 'All' && s != tmp[2]) continue;
365 theopts[j++] = new Option(tmp[0], tmp[1], false, false);
370 // insert text into a textarea where the cursor is
371 function insertAtCaret(areaId,text) {
372 var txtarea = document.getElementById(areaId);
373 var scrollPos = txtarea.scrollTop;
374 var strPos = 0;
375 var br = ((txtarea.selectionStart || txtarea.selectionStart == '0') ?
376 "ff" : (document.selection ? "ie" : false ) );
377 if (br == "ie") {
378 txtarea.focus();
379 var range = document.selection.createRange();
380 range.moveStart ('character', -txtarea.value.length);
381 strPos = range.text.length;
383 else if (br == "ff") strPos = txtarea.selectionStart;
385 var front = (txtarea.value).substring(0,strPos);
386 var back = (txtarea.value).substring(strPos,txtarea.value.length);
387 txtarea.value=front+text+back;
388 strPos = strPos + text.length;
389 if (br == "ie") {
390 txtarea.focus();
391 var range = document.selection.createRange();
392 range.moveStart ('character', -txtarea.value.length);
393 range.moveStart ('character', strPos);
394 range.moveEnd ('character', 0);
395 range.select();
397 else if (br == "ff") {
398 txtarea.selectionStart = strPos;
399 txtarea.selectionEnd = strPos;
400 txtarea.focus();
402 txtarea.scrollTop = scrollPos;
405 function insertAtCursor(myField, myValue) {
406 //IE support
407 if (document.selection) {
408 myField.focus();
409 sel = document.selection.createRange();
410 sel.text = myValue;
412 //MOZILLA/NETSCAPE support
413 else if (myField.selectionStart || myField.selectionStart == '0') {
414 var startPos = myField.selectionStart;
415 var endPos = myField.selectionEnd;
416 myField.value = myField.value.substring(0, startPos)
417 + myValue
418 + myField.value.substring(endPos, myField.value.length);
419 } else {
420 myField.value += myValue;
425 </script>
427 </head>
429 <body class="body_top" onunload='imclosing()'>
431 <!-- <form method='post' action='letter.php' onsubmit='return top.restoreSession()'> -->
432 <form method='post' action='letter.php' id="theform" name="theform" onsubmit="return top.restoreSession()">
433 <input type="hidden" name="formaction" id="formaction" value="">
434 <input type='hidden' name='form_pid' value='<?php echo attr($pid) ?>' />
436 <center>
438 <table width='98%'>
440 <tr>
441 <td colspan='4' align='center'>
442 &nbsp;<br>
443 <b><?php echo xlt('Generate Letter regarding ') . text($patdata['fname']) . " " .
444 text($patdata['lname']) . " (" . text($patdata['pubpid']) . ")" ?></b>
445 <br>&nbsp;
446 </td>
447 </tr>
449 <tr>
451 <td class='control-label'>
452 <?php echo xlt('From'); ?>:
453 </td>
455 <td>
456 <select name='form_from' class='form-control'>
457 <?php echo $optfrom; ?>
458 </select>
459 </td>
461 <td class='control-label'>
462 <?php echo xlt('Date'); ?>:
463 </td>
465 <td>
466 <input type='text' size='10' name='form_date' id='form_date' class='datepicker form-control'
467 value='<?php echo attr(oeFormatShortDate(date('Y-m-d'))); ?>'
468 title='<?php echo xlt('Date of this letter'); ?>' />
469 </td>
471 </tr>
473 <tr>
475 <td class='control-label'>
476 <?php echo xlt('Specialty'); ?>:
477 </td>
479 <td>
480 <select name='form_specialty' onchange='newspecialty()' class='form-control'>
481 <?php echo $optspec; ?>
482 </select>
483 </td>
485 <td class='control-label'>
486 <?php echo xlt('Template'); ?>:
487 </td>
489 <td>
490 <select name="form_template" id="form_template" class='form-control'>
491 <option value="">(<?php echo xlt('none'); ?>)</option>
492 <?php
493 $tpldir = $GLOBALS['OE_SITE_DIR'] . "/letter_templates";
494 $dh = opendir($tpldir);
495 if (! $dh) {
496 die(xlt('Cannot read') . ' ' . $tpldir);
499 while (false !== ($tfname = readdir($dh))) {
500 // skip dot-files, scripts and images
501 if (preg_match("/^\./", $tfname)) {
502 continue;
505 if (preg_match("/\.php$/", $tfname)) {
506 continue;
509 if (preg_match("/\.jpg$/", $tfname)) {
510 continue;
513 if (preg_match("/\.png$/", $tfname)) {
514 continue;
517 echo "<option value='" . attr($tfname) . "'";
518 if (($tfname == $_POST['form_template']) || ($tfname == $_GET['template'])) {
519 echo " SELECTED";
522 echo ">";
523 if ($tfname == 'autosaved') {
524 echo xlt($tfname);
525 } else {
526 echo text($tfname);
529 echo "</option>";
532 closedir($dh);
534 </select>
535 </td>
537 </tr>
539 </tr>
541 <tr>
543 <td class='control-label'>
544 <?php echo xlt('To'); ?>:
545 </td>
547 <td>
548 <select name='form_to' class='form-control'>
549 <?php echo $optto; ?>
550 </select>
551 </td>
553 <td class='control-label'>
554 <?php echo xlt('Print Format'); ?>:
555 </td>
557 <td>
558 <select name='form_format' class='form-control'>
559 <option value='html'><?php echo xlt('HTML'); ?></option>
560 <option value='pdf'><?php echo xlt('PDF'); ?></option>
561 </select>
562 </td>
564 </tr>
566 <tr>
567 <td colspan='4'>
568 <div id="letter_toolbar" class='text' style="width: 100%; background-color: #ddd; padding: 5px; margin: 0px;">
569 <span class='control-label'><?php echo xlt('Insert special field'); ?>:</span>
570 <select id="letter_field" class='form-control'>
571 <option value="">- <?php echo xlt('Choose'); ?> -</option>
572 <option value="<?php echo '{'.$FIELD_TAG['DATE'].'}'; ?>"><?php echo xlt('Today\'s Date'); ?></option>
573 <option value="<?php echo '{'.$FIELD_TAG['FROM_TITLE'].'}'; ?>"><?php echo xlt('FROM'); ?> - <?php echo xlt('Title'); ?></option>
574 <option value="<?php echo '{'.$FIELD_TAG['FROM_FNAME'].'}'; ?>"><?php echo xlt('FROM'); ?> - <?php echo xlt('First name'); ?></option>
575 <option value="<?php echo '{'.$FIELD_TAG['FROM_MNAME'].'}'; ?>"><?php echo xlt('FROM'); ?> - <?php echo xlt('Middle name'); ?></option>
576 <option value="<?php echo '{'.$FIELD_TAG['FROM_LNAME'].'}'; ?>"><?php echo xlt('FROM'); ?> - <?php echo xlt('Last name'); ?></option>
577 <option value="<?php echo '{'.$FIELD_TAG['FROM_STREET'].'}'; ?>"><?php echo xlt('FROM'); ?> - <?php echo xlt('Street'); ?></option>
578 <option value="<?php echo '{'.$FIELD_TAG['FROM_CITY'].'}'; ?>"><?php echo xlt('FROM'); ?> - <?php echo xlt('City'); ?></option>
579 <option value="<?php echo '{'.$FIELD_TAG['FROM_STATE'].'}'; ?>"><?php echo xlt('FROM'); ?> - <?php echo xlt('State'); ?></option>
580 <option value="<?php echo '{'.$FIELD_TAG['FROM_POSTAL'].'}'; ?>"><?php echo xlt('FROM'); ?> - <?php echo xlt('Postal Code'); ?></option>
581 <option value="<?php echo '{'.$FIELD_TAG['FROM_VALEDICTORY'].'}'; ?>"><?php echo xlt('FROM'); ?> - <?php echo xlt('Valedictory'); ?></option>
582 <option value="<?php echo '{'.$FIELD_TAG['FROM_PHONECELL'].'}'; ?>"><?php echo xlt('FROM'); ?> - <?php echo xlt('Cell Phone'); ?></option>
583 <option value="<?php echo '{'.$FIELD_TAG['FROM_PHONE'].'}'; ?>"><?php echo xlt('FROM'); ?> - <?php echo xlt('Phone'); ?></option>
584 <option value="<?php echo '{'.$FIELD_TAG['FROM_EMAIL'].'}'; ?>"><?php echo xlt('FROM'); ?> - <?php echo xlt('email'); ?></option>
585 <option value="<?php echo '{'.$FIELD_TAG['TO_TITLE'].'}'; ?>"><?php echo xlt('TO'); ?> - <?php echo xlt('Title'); ?></option>
586 <option value="<?php echo '{'.$FIELD_TAG['TO_FNAME'].'}'; ?>"><?php echo xlt('TO'); ?> - <?php echo xlt('First name'); ?></option>
587 <option value="<?php echo '{'.$FIELD_TAG['TO_MNAME'].'}'; ?>"><?php echo xlt('TO'); ?> - <?php echo xlt('Middle name'); ?></option>
588 <option value="<?php echo '{'.$FIELD_TAG['TO_LNAME'].'}'; ?>"><?php echo xlt('TO'); ?> - <?php echo xlt('Last name'); ?></option>
589 <option value="<?php echo '{'.$FIELD_TAG['TO_STREET'].'}'; ?>"><?php echo xlt('TO'); ?> - <?php echo xlt('Street'); ?></option>
590 <option value="<?php echo '{'.$FIELD_TAG['TO_CITY'].'}'; ?>"><?php echo xlt('TO'); ?> - <?php echo xlt('City'); ?></option>
591 <option value="<?php echo '{'.$FIELD_TAG['TO_STATE'].'}'; ?>"><?php echo xlt('TO'); ?> - <?php echo xlt('State'); ?></option>
592 <option value="<?php echo '{'.$FIELD_TAG['TO_POSTAL'].'}'; ?>"><?php echo xlt('TO'); ?> - <?php echo xlt('Postal Code'); ?></option>
593 <option value="<?php echo '{'.$FIELD_TAG['TO_VALEDICTORY'].'}'; ?>"><?php echo xlt('TO'); ?> - <?php echo xlt('Valedictory'); ?></option>
594 <option value="<?php echo '{'.$FIELD_TAG['TO_ORGANIZATION'].'}'; ?>"><?php echo xlt('TO'); ?> - <?php echo xlt('Organization'); ?></option>
595 <option value="<?php echo '{'.$FIELD_TAG['TO_FAX'].'}'; ?>"><?php echo xlt('TO'); ?> - <?php echo xlt('Fax number'); ?></option>
596 <option value="<?php echo '{'.$FIELD_TAG['TO_PHONE'].'}'; ?>"><?php echo xlt('TO'); ?> - <?php echo xlt('Phone number'); ?></option>
597 <option value="<?php echo '{'.$FIELD_TAG['TO_PHONECELL'].'}'; ?>"><?php echo xlt('TO'); ?> - <?php echo xlt('Cell phone number'); ?></option>
598 <option value="<?php echo '{'.$FIELD_TAG['PT_FNAME'].'}'; ?>"><?php echo xlt('PATIENT'); ?> - <?php echo xlt('First name'); ?></option>
599 <option value="<?php echo '{'.$FIELD_TAG['PT_MNAME'].'}'; ?>"><?php echo xlt('PATIENT'); ?> - <?php echo xlt('Middle name'); ?></option>
600 <option value="<?php echo '{'.$FIELD_TAG['PT_LNAME'].'}'; ?>"><?php echo xlt('PATIENT'); ?> - <?php echo xlt('Last name'); ?></option>
601 <option value="<?php echo '{'.$FIELD_TAG['PT_STREET'].'}'; ?>"><?php echo xlt('PATIENT'); ?> - <?php echo xlt('Street'); ?></option>
602 <option value="<?php echo '{'.$FIELD_TAG['PT_CITY'].'}'; ?>"><?php echo xlt('PATIENT'); ?> - <?php echo xlt('City'); ?></option>
603 <option value="<?php echo '{'.$FIELD_TAG['PT_STATE'].'}'; ?>"><?php echo xlt('PATIENT'); ?> - <?php echo xlt('State'); ?></option>
604 <option value="<?php echo '{'.$FIELD_TAG['PT_POSTAL'].'}'; ?>"><?php echo xlt('PATIENT'); ?> - <?php echo xlt('Postal Code'); ?></option>
605 <option value="<?php echo '{'.$FIELD_TAG['PT_PHONE_HOME'].'}'; ?>"><?php echo xlt('PATIENT'); ?> - <?php echo xlt('Phone Home'); ?></option>
606 <option value="<?php echo '{'.$FIELD_TAG['PT_PHONE_CELL'].'}'; ?>"><?php echo xlt('PATIENT'); ?> - <?php echo xlt('Phone Cell'); ?></option>
607 <option value="<?php echo '{'.$FIELD_TAG['PT_SSN'].'}'; ?>"><?php echo xlt('PATIENT'); ?> - <?php echo xlt('SSN'); ?></option>
608 <option value="<?php echo '{'.$FIELD_TAG['PT_DOB'].'}'; ?>"><?php echo xlt('PATIENT'); ?> - <?php echo xlt('Date of birth'); ?></option>
609 </select>
610 </div>
611 <textarea name='form_body' id="form_body" class='form-control' rows='20' cols='30' style='width:100%'
612 title='<?php echo xla('Enter body of letter here'); ?>' /><?php echo text($bodytext); ?></textarea>
613 </td>
614 </tr>
616 </table>
618 <div class="btn-group" role="group">
619 <button type='button' class='addtemplate btn btn-default btn-save'><?php echo xlt('Save as New'); ?></button>
620 <button type='button' class='btn btn-default btn-save' name='savetemplate' id="savetemplate"><?php echo xlt('Save Changes'); ?></button>
621 <button type='button' class='btn btn-default btn-transmit' name='form_generate' id="form_generate"><?php echo xlt('Generate Letter'); ?></button>
622 </div>
624 </center>
626 <!-- template DIV that appears when user chooses to add a new letter template -->
627 <div id="newtemplatedetail" style="margin-top: 4em; display: none; visibility: hidden;">
628 <span class='control-label'><?php echo xlt('Template Name'); ?>:</span> <input type="textbox" size="20" maxlength="30" name="newtemplatename" id="newtemplatename" class="form-control">
629 <br>
630 <div class="btn-group" role="group">
631 <button type="button" class="savenewtemplate btn btn-default btn-save"><?php echo xlt('Save new template'); ?></button>
632 <button type="button" class="cancelnewtemplate btn btn-link btn-cancel"><?php echo xlt('Cancel'); ?></button>
633 </div>
634 </div>
636 </form>
637 </body>
639 <script language='JavaScript'>
641 // jQuery stuff to make the page a little easier to use
643 $(document).ready(function(){
644 $("#form_generate").click(function() { $("#formaction").val("generate"); $("#theform").submit(); });
645 $("#form_template").change(function() { $("#formaction").val("loadtemplate"); $("#theform").submit(); });
647 $("#savetemplate").click(function() { SaveTemplate(this); });
649 $("#letter_field").change(function() { insertAtCursor(document.getElementById("form_body"), $(this).val()); $(this).attr("selectedIndex", "0"); });
651 $(".addtemplate").click(function() { AddTemplate(this); });
652 $(".savenewtemplate").click(function() { SaveNewTemplate(this); });
653 $(".deletetemplate").click(function() { DeleteTemplate(this); });
654 $(".cancelnewtemplate").click(function() { CancelNewTemplate(this); });
656 $('.datepicker').datetimepicker({
657 <?php $datetimepicker_timepicker = false; ?>
658 <?php $datetimepicker_showseconds = false; ?>
659 <?php $datetimepicker_formatInput = true; ?>
660 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
661 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
664 // display the 'new group' DIV
665 var AddTemplate = function(btnObj) {
666 // show the field details DIV
667 $('#newtemplatedetail').css('visibility', 'visible');
668 $('#newtemplatedetail').css('display', 'block');
669 $(btnObj).parent().append($("#newtemplatedetail"));
670 $('#newtemplatedetail > #newtemplatename').focus();
671 $(window).scrollTop($(document).height());
674 // save the new template
675 var SaveNewTemplate = function(btnObj) {
676 // the template name can only have letters, numbers, spaces and underscores
677 // AND it cannot start with a number
678 if ($("#newtemplatename").val().match(/^\d+/)) {
679 alert("<?php echo xls('Template names cannot start with numbers.'); ?>");
680 return false;
682 var validname = $("#newtemplatename").val().replace(/[^A-za-z0-9]/g, "_"); // match any non-word characters and replace them
683 $("#newtemplatename").val(validname);
685 // submit the form to add a new field to a specific group
686 $("#formaction").val("newtemplate");
687 $("#theform").submit();
690 // actually delete a template file
692 var DeleteTemplate = function(btnObj) {
693 var parts = $(btnObj).attr("id");
694 var groupname = parts.replace(/^\d+/, "");
695 if (confirm("WARNING - This action cannot be undone.\n Are you sure you wish to delete the entire group named '"+groupname+"'?")) {
696 // submit the form to add a new field to a specific group
697 $("#formaction").val("deletegroup");
698 $("#deletegroupname").val(parts);
699 $("#theform").submit();
704 // just hide the new template DIV
705 var CancelNewTemplate = function(btnObj) {
706 // hide the field details DIV
707 $('#newtemplatedetail').css('visibility', 'hidden');
708 $('#newtemplatedetail').css('display', 'none');
709 // reset the new group values to a default
710 $('#newtemplatedetail > #newtemplatename').val("");
714 // save the template, overwriting the older version
715 var SaveTemplate = function(btnObj) {
716 if (! confirm("<?php echo xls('You are about to permanently replace the existing template. Are you sure you wish to continue?'); ?>")) {
717 return false;
719 $("#formaction").val("savetemplate");
720 $("#theform").submit();
724 </script>
726 </html>