2 // Copyright (C) 2007-2011 Rod Roark <rod@sunsetsystems.com>
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
9 use OpenEMR\Core\Header
;
11 include_once("../globals.php");
12 include_once($GLOBALS['srcdir'] . "/patient.inc");
14 $template_dir = $GLOBALS['OE_SITE_DIR'] . "/letter_templates";
16 // array of field name tags to allow internationalization
20 'FROM_TITLE' => xl('FROM_TITLE'),
21 'FROM_FNAME' => xl('FROM_FNAME'),
22 'FROM_LNAME' => xl('FROM_LNAME'),
23 'FROM_MNAME' => xl('FROM_MNAME'),
24 'FROM_STREET' => xl('FROM_STREET'),
25 'FROM_CITY' => xl('FROM_CITY'),
26 'FROM_STATE' => xl('FROM_STATE'),
27 'FROM_POSTAL' => xl('FROM_POSTAL'),
28 'FROM_VALEDICTORY' => xl('FROM_VALEDICTORY'),
29 'FROM_PHONE' => xl('FROM_PHONE'),
30 'FROM_PHONECELL' => xl('FROM_PHONECELL'),
31 'FROM_EMAIL' => xl('FROM_EMAIL'),
32 'TO_TITLE' => xl('TO_TITLE'),
33 'TO_FNAME' => xl('TO_FNAME'),
34 'TO_LNAME' => xl('TO_LNAME'),
35 'TO_MNAME' => xl('TO_MNAME'),
36 'TO_STREET' => xl('TO_STREET'),
37 'TO_CITY' => xl('TO_CITY'),
38 'TO_STATE' => xl('TO_STATE'),
39 'TO_POSTAL' => xl('TO_POSTAL'),
40 'TO_VALEDICTORY' => xl('TO_VALEDICTORY'),
41 'TO_PHONE' => xl('TO_PHONE'),
42 'TO_PHONECELL' => xl('TO_PHONECELL'),
43 'TO_FAX' => xl('TO_FAX'),
44 'TO_ORGANIZATION' => xl('TO_ORGANIZATION'),
45 'PT_FNAME' => xl('PT_FNAME'),
46 'PT_LNAME' => xl('PT_LNAME'),
47 'PT_MNAME' => xl('PT_MNAME'),
48 'PT_STREET' => xl('PT_STREET'),
49 'PT_CITY' => xl('PT_CITY'),
50 'PT_STATE' => xl('PT_STATE'),
51 'PT_POSTAL' => xl('PT_POSTAL'),
52 'PT_PHONE_HOME' => xl('PT_PHONE_HOME'),
53 'PT_PHONE_CELL' => xl('PT_PHONE_CELL'),
54 'PT_SSN' => xl('PT_SSN'),
55 'PT_EMAIL' => xl('PT_EMAIL'),
56 'PT_DOB' => xl('PT_DOB')
60 $patdata = sqlQuery("SELECT " .
61 "p.fname, p.mname, p.lname, p.pubpid, p.DOB, " .
62 "p.street, p.city, p.state, p.phone_home, p.phone_cell, p.ss, p.email, p.postal_code " .
63 "FROM patient_data AS p " .
64 "WHERE p.pid = ? LIMIT 1", array($pid));
66 $alertmsg = ''; // anything here pops up in an alert box
68 // If the Generate button was clicked...
69 if ($_POST['formaction']=="generate") {
70 $form_pid = $_POST['form_pid'];
71 $form_from = $_POST['form_from'];
72 $form_to = $_POST['form_to'];
73 $form_date = $_POST['form_date'];
74 $form_template = $_POST['form_template'];
75 $form_format = $_POST['form_format'];
76 $form_body = $_POST['form_body'];
78 $frow = sqlQuery("SELECT * FROM users WHERE id = ?", array($form_from));
79 $trow = sqlQuery("SELECT * FROM users WHERE id = ?", array($form_to));
81 $datestr = $form_date;
82 $from_title = $frow['title'] ?
$frow['title'] . ' ' : '';
83 $to_title = $trow['title'] ?
$trow['title'] . ' ' : '';
85 $cpstring = $_POST['form_body'];
87 // attempt to save to the autosaved template
88 $fh = fopen("$template_dir/autosaved", 'w');
89 // translate from definition to the constant
90 $temp_bodytext = $cpstring;
91 foreach ($FIELD_TAG as $key => $value) {
92 $temp_bodytext = str_replace("{".$value."}", "{".$key."}", $temp_bodytext);
95 if (! fwrite($fh, $temp_bodytext)) {
96 echo xl('Error while saving to the file', '', '', ' ') . $template_dir."/autosaved" .
97 xl('Ensure OpenEMR has write privileges to directory', '', ' . ', ' ') . $template_dir . "/ ." ;
103 $cpstring = str_replace('{'.$FIELD_TAG['DATE'].'}', $datestr, $cpstring);
104 $cpstring = str_replace('{'.$FIELD_TAG['FROM_TITLE'].'}', $from_title, $cpstring);
105 $cpstring = str_replace('{'.$FIELD_TAG['FROM_FNAME'].'}', $frow['fname'], $cpstring);
106 $cpstring = str_replace('{'.$FIELD_TAG['FROM_LNAME'].'}', $frow['lname'], $cpstring);
107 $cpstring = str_replace('{'.$FIELD_TAG['FROM_MNAME'].'}', $frow['mname'], $cpstring);
108 $cpstring = str_replace('{'.$FIELD_TAG['FROM_STREET'].'}', $frow['street'], $cpstring);
109 $cpstring = str_replace('{'.$FIELD_TAG['FROM_CITY'].'}', $frow['city'], $cpstring);
110 $cpstring = str_replace('{'.$FIELD_TAG['FROM_STATE'].'}', $frow['state'], $cpstring);
111 $cpstring = str_replace('{'.$FIELD_TAG['FROM_POSTAL'].'}', $frow['zip'], $cpstring);
112 $cpstring = str_replace('{'.$FIELD_TAG['FROM_VALEDICTORY'].'}', $frow['valedictory'], $cpstring);
113 $cpstring = str_replace('{'.$FIELD_TAG['FROM_PHONECELL'].'}', $frow['phonecell'], $cpstring);
114 $cpstring = str_replace('{'.$FIELD_TAG['FROM_PHONE'].'}', $frow['phone'], $cpstring);
115 $cpstring = str_replace('{'.$FIELD_TAG['FROM_EMAIL'].'}', $frow['email'], $cpstring);
116 $cpstring = str_replace('{'.$FIELD_TAG['TO_TITLE'].'}', $to_title, $cpstring);
117 $cpstring = str_replace('{'.$FIELD_TAG['TO_FNAME'].'}', $trow['fname'], $cpstring);
118 $cpstring = str_replace('{'.$FIELD_TAG['TO_LNAME'].'}', $trow['lname'], $cpstring);
119 $cpstring = str_replace('{'.$FIELD_TAG['TO_MNAME'].'}', $trow['mname'], $cpstring);
120 $cpstring = str_replace('{'.$FIELD_TAG['TO_STREET'].'}', $trow['street'], $cpstring);
121 $cpstring = str_replace('{'.$FIELD_TAG['TO_CITY'].'}', $trow['city'], $cpstring);
122 $cpstring = str_replace('{'.$FIELD_TAG['TO_STATE'].'}', $trow['state'], $cpstring);
123 $cpstring = str_replace('{'.$FIELD_TAG['TO_POSTAL'].'}', $trow['zip'], $cpstring);
124 $cpstring = str_replace('{'.$FIELD_TAG['TO_VALEDICTORY'].'}', $trow['valedictory'], $cpstring);
125 $cpstring = str_replace('{'.$FIELD_TAG['TO_FAX'].'}', $trow['fax'], $cpstring);
126 $cpstring = str_replace('{'.$FIELD_TAG['TO_PHONE'].'}', $trow['phone'], $cpstring);
127 $cpstring = str_replace('{'.$FIELD_TAG['TO_PHONECELL'].'}', $trow['phonecell'], $cpstring);
128 $cpstring = str_replace('{'.$FIELD_TAG['TO_ORGANIZATION'].'}', $trow['organization'], $cpstring);
129 $cpstring = str_replace('{'.$FIELD_TAG['PT_FNAME'].'}', $patdata['fname'], $cpstring);
130 $cpstring = str_replace('{'.$FIELD_TAG['PT_LNAME'].'}', $patdata['lname'], $cpstring);
131 $cpstring = str_replace('{'.$FIELD_TAG['PT_MNAME'].'}', $patdata['mname'], $cpstring);
132 $cpstring = str_replace('{'.$FIELD_TAG['PT_STREET'].'}', $patdata['street'], $cpstring);
133 $cpstring = str_replace('{'.$FIELD_TAG['PT_CITY'].'}', $patdata['city'], $cpstring);
134 $cpstring = str_replace('{'.$FIELD_TAG['PT_STATE'].'}', $patdata['state'], $cpstring);
135 $cpstring = str_replace('{'.$FIELD_TAG['PT_POSTAL'].'}', $patdata['postal_code'], $cpstring);
136 $cpstring = str_replace('{'.$FIELD_TAG['PT_PHONE_HOME'].'}', $patdata['phone_home'], $cpstring);
137 $cpstring = str_replace('{'.$FIELD_TAG['PT_PHONE_CELL'].'}', $patdata['phone_cell'], $cpstring);
138 $cpstring = str_replace('{'.$FIELD_TAG['PT_SSN'].'}', $patdata['ss'], $cpstring);
139 $cpstring = str_replace('{'.$FIELD_TAG['PT_EMAIL'].'}', $patdata['email'], $cpstring);
140 $cpstring = str_replace('{'.$FIELD_TAG['PT_DOB'].'}', $patdata['DOB'], $cpstring);
142 if ($form_format == "pdf") {
143 $pdf = new Cezpdf($GLOBALS['rx_paper_size']);
144 $pdf->ezSetMargins($GLOBALS['rx_top_margin'], $GLOBALS['rx_bottom_margin'], $GLOBALS['rx_left_margin'], $GLOBALS['rx_right_margin']);
145 if (file_exists("$template_dir/custom_pdf.php")) {
146 include("$template_dir/custom_pdf.php");
148 $pdf->selectFont('Helvetica');
149 $pdf->ezText($cpstring, 12);
154 } else { // $form_format = html
155 $cpstring = text($cpstring); //escape to prevent stored cross script attack
156 $cpstring = str_replace("\n", "<br>", $cpstring);
157 $cpstring = str_replace("\t", " ", $cpstring);
163 font
-family
: sans
-serif
;
183 <title
><?php
echo xlt('Letter'); ?
></title
>
186 <div
class='paddingdiv'>
187 <?php
echo $cpstring; ?
>
188 <div
class="navigate">
189 <a href
='<?php echo $GLOBALS['rootdir
'] . '/patient_file
/letter
.php?template
=autosaved
'; ?>' onclick
='top.restoreSession()'>(<?php
echo xlt('Back'); ?
>)</a
>
191 <script language
='JavaScript'>
199 } else if (isset($_GET['template']) && $_GET['template'] != "") {
200 // utilized to go back to autosaved template
202 $fh = fopen("$template_dir/".$_GET['template'], 'r');
204 $bodytext.= fread($fh, 8192);
208 // translate from constant to the definition
209 foreach ($FIELD_TAG as $key => $value) {
210 $bodytext = str_replace("{".$key."}", "{".$value."}", $bodytext);
212 } else if ($_POST['formaction'] == "loadtemplate" && $_POST['form_template'] != "") {
214 $fh = fopen("$template_dir/".$_POST['form_template'], 'r');
216 $bodytext.= fread($fh, 8192);
220 // translate from constant to the definition
221 foreach ($FIELD_TAG as $key => $value) {
222 $bodytext = str_replace("{".$key."}", "{".$value."}", $bodytext);
224 } else if ($_POST['formaction'] == "newtemplate" && $_POST['newtemplatename'] != "") {
225 // attempt to save the template
226 $fh = fopen("$template_dir/".$_POST['newtemplatename'], 'w');
227 // translate from definition to the constant
228 $temp_bodytext = $_POST['form_body'];
229 foreach ($FIELD_TAG as $key => $value) {
230 $temp_bodytext = str_replace("{".$value."}", "{".$key."}", $temp_bodytext);
233 if (! fwrite($fh, $temp_bodytext)) {
234 echo xlt('Error while writing to file') . ' ' . $template_dir."/".$_POST['newtemplatename'];
240 // read the saved file back
241 $_POST['form_template'] = $_POST['newtemplatename'];
242 $fh = fopen("$template_dir/".$_POST['form_template'], 'r');
244 $bodytext.= fread($fh, 8192);
248 // translate from constant to the definition
249 foreach ($FIELD_TAG as $key => $value) {
250 $bodytext = str_replace("{".$key."}", "{".$value."}", $bodytext);
252 } else if ($_POST['formaction'] == "savetemplate" && $_POST['form_template'] != "") {
253 // attempt to save the template
254 $fh = fopen("$template_dir/".$_POST['form_template'], 'w');
255 // translate from definition to the constant
256 $temp_bodytext = $_POST['form_body'];
257 foreach ($FIELD_TAG as $key => $value) {
258 $temp_bodytext = str_replace("{".$value."}", "{".$key."}", $temp_bodytext);
261 if (! fwrite($fh, $temp_bodytext)) {
262 echo xlt('Error while writing to file') . ' ' . $template_dir."/".$_POST['form_template'];
268 // read the saved file back
269 $fh = fopen("$template_dir/".$_POST['form_template'], 'r');
271 $bodytext.= fread($fh, 8192);
275 // translate from constant to the definition
276 foreach ($FIELD_TAG as $key => $value) {
277 $bodytext = str_replace("{".$key."}", "{".$value."}", $bodytext);
281 // This is the case where we display the form for data entry.
282 // Get the users list.
283 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
284 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
285 "ORDER BY lname, fname");
289 $ulist = "var ulist = new Array();\n";
290 while ($urow = sqlFetchArray($ures)) {
291 $uname = $urow['lname'];
292 if ($urow['fname']) {
293 $uname .= ", " . $urow['fname'];
296 $tmp1 = " <option value='" . attr($urow['id']) . "'";
297 $tmp2 = ">" . text($uname) . "</option>\n";
298 $optto .= $tmp1 . $tmp2;
299 if ($urow['id'] == $_SESSION['authUserID']) {
300 $tmp1 .= " selected";
303 $optfrom .= $tmp1 . $tmp2;
304 $ulist .= "ulist[$i] = '" . attr($uname) . "|" .
305 attr($urow['id']) . "|" . attr($urow['specialty']) . "';\n";
309 // Get the unique specialties.
310 $sres = sqlStatement("SELECT DISTINCT specialty FROM users " .
311 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
312 "ORDER BY specialty");
313 $optspec = "<option value='All'>" . xlt('All') . "</option>\n";
314 while ($srow = sqlFetchArray($sres)) {
315 $optspec .= " <option value='" . attr($srow['specialty']) . "'>" .
316 text($srow['specialty']) . "</option>\n";
322 <title
><?php
echo xlt('Letter Generator'); ?
></title
>
323 <?php Header
::setupHeader(['datetime-picker', 'topdialog']); ?
>
325 <script language
="JavaScript">
326 <?php
echo $ulist; ?
>
328 // React to selection of a specialty. This rebuilds the "to" users list
329 // with users having that specialty, or all users if "All" is selected.
330 function newspecialty() {
331 var f
= document
.forms
[0];
332 var s
= f
.form_specialty
.value
;
333 var theopts
= f
.form_to
.options
;
336 for (var i
= 0; i
< ulist
.length
; ++i
) {
337 tmp
= ulist
[i
].split("|");
338 if (s
!= 'All' && s
!= tmp
[2]) continue;
339 theopts
[j++
] = new Option(tmp
[0], tmp
[1], false, false);
344 // insert text into a textarea where the cursor is
345 function insertAtCaret(areaId
,text
) {
346 var txtarea
= document
.getElementById(areaId
);
347 var scrollPos
= txtarea
.scrollTop
;
349 var br
= ((txtarea
.selectionStart || txtarea
.selectionStart
== '0') ?
350 "ff" : (document
.selection ?
"ie" : false ) );
353 var range
= document
.selection
.createRange();
354 range
.moveStart ('character', -txtarea
.value
.length
);
355 strPos
= range
.text
.length
;
357 else if (br
== "ff") strPos
= txtarea
.selectionStart
;
359 var front
= (txtarea
.value
).substring(0,strPos
);
360 var back
= (txtarea
.value
).substring(strPos
,txtarea
.value
.length
);
361 txtarea
.value
=front+text+back
;
362 strPos
= strPos + text
.length
;
365 var range
= document
.selection
.createRange();
366 range
.moveStart ('character', -txtarea
.value
.length
);
367 range
.moveStart ('character', strPos
);
368 range
.moveEnd ('character', 0);
371 else if (br
== "ff") {
372 txtarea
.selectionStart
= strPos
;
373 txtarea
.selectionEnd
= strPos
;
376 txtarea
.scrollTop
= scrollPos
;
379 function insertAtCursor(myField
, myValue
) {
381 if (document
.selection
) {
383 sel
= document
.selection
.createRange();
386 //MOZILLA/NETSCAPE support
387 else if (myField
.selectionStart || myField
.selectionStart
== '0') {
388 var startPos
= myField
.selectionStart
;
389 var endPos
= myField
.selectionEnd
;
390 myField
.value
= myField
.value
.substring(0, startPos
)
392 + myField
.value
.substring(endPos
, myField
.value
.length
);
394 myField
.value +
= myValue
;
403 <body
class="body_top" onunload
='imclosing()'>
405 <!-- <form method
='post' action
='letter.php' onsubmit
='return top.restoreSession()'> -->
406 <form method
='post' action
='letter.php' id
="theform" name
="theform" onsubmit
="return top.restoreSession()">
407 <input type
="hidden" name
="formaction" id
="formaction" value
="">
408 <input type
='hidden' name
='form_pid' value
='<?php echo attr($pid) ?>' />
415 <td colspan
='4' align
='center'>
417 <b
><?php
echo xlt('Generate Letter regarding ') . text($patdata['fname']) . " " .
418 text($patdata['lname']) . " (" . text($patdata['pubpid']) . ")" ?
></b
>
425 <td
class='control-label'>
426 <?php
echo xlt('From'); ?
>:
430 <select name
='form_from' class='form-control'>
431 <?php
echo $optfrom; ?
>
435 <td
class='control-label'>
436 <?php
echo xlt('Date'); ?
>:
440 <input type
='text' size
='10' name
='form_date' id
='form_date' class='datepicker form-control'
441 value
='<?php echo oeFormatShortDate(date('Y
-m
-d
')); ?>'
442 title
='<?php echo xlt('Date of this letter
'); ?>' />
449 <td
class='control-label'>
450 <?php
echo xlt('Specialty'); ?
>:
454 <select name
='form_specialty' onchange
='newspecialty()' class='form-control'>
455 <?php
echo $optspec; ?
>
459 <td
class='control-label'>
460 <?php
echo xlt('Template'); ?
>:
464 <select name
="form_template" id
="form_template" class='form-control'>
465 <option value
="">(<?php
echo xlt('none'); ?
>)</option
>
467 $tpldir = $GLOBALS['OE_SITE_DIR'] . "/letter_templates";
468 $dh = opendir($tpldir);
470 die(xlt('Cannot read') . ' ' . $tpldir);
473 while (false !== ($tfname = readdir($dh))) {
474 // skip dot-files, scripts and images
475 if (preg_match("/^\./", $tfname)) {
479 if (preg_match("/\.php$/", $tfname)) {
483 if (preg_match("/\.jpg$/", $tfname)) {
487 if (preg_match("/\.png$/", $tfname)) {
491 echo "<option value='" . attr($tfname) . "'";
492 if (($tfname == $_POST['form_template']) ||
($tfname == $_GET['template'])) {
497 if ($tfname == 'autosaved') {
517 <td
class='control-label'>
518 <?php
echo xlt('To'); ?
>:
522 <select name
='form_to' class='form-control'>
523 <?php
echo $optto; ?
>
527 <td
class='control-label'>
528 <?php
echo xlt('Print Format'); ?
>:
532 <select name
='form_format' class='form-control'>
533 <option value
='html'><?php
echo xlt('HTML'); ?
></option
>
534 <option value
='pdf'><?php
echo xlt('PDF'); ?
></option
>
542 <div id
="letter_toolbar" class='text' style
="width: 100%; background-color: #ddd; padding: 5px; margin: 0px;">
543 <span
class='control-label'><?php
echo xlt('Insert special field'); ?
>:</span
>
544 <select id
="letter_field" class='form-control'>
545 <option value
="">- <?php
echo xlt('Choose'); ?
> -</option
>
546 <option value
="<?php echo '{'.$FIELD_TAG['DATE'].'}'; ?>"><?php
echo xlt('Today\'s Date'); ?
></option
>
547 <option value
="<?php echo '{'.$FIELD_TAG['FROM_TITLE'].'}'; ?>"><?php
echo xlt('FROM'); ?
> - <?php
echo xlt('Title'); ?
></option
>
548 <option value
="<?php echo '{'.$FIELD_TAG['FROM_FNAME'].'}'; ?>"><?php
echo xlt('FROM'); ?
> - <?php
echo xlt('First name'); ?
></option
>
549 <option value
="<?php echo '{'.$FIELD_TAG['FROM_MNAME'].'}'; ?>"><?php
echo xlt('FROM'); ?
> - <?php
echo xlt('Middle name'); ?
></option
>
550 <option value
="<?php echo '{'.$FIELD_TAG['FROM_LNAME'].'}'; ?>"><?php
echo xlt('FROM'); ?
> - <?php
echo xlt('Last name'); ?
></option
>
551 <option value
="<?php echo '{'.$FIELD_TAG['FROM_STREET'].'}'; ?>"><?php
echo xlt('FROM'); ?
> - <?php
echo xlt('Street'); ?
></option
>
552 <option value
="<?php echo '{'.$FIELD_TAG['FROM_CITY'].'}'; ?>"><?php
echo xlt('FROM'); ?
> - <?php
echo xlt('City'); ?
></option
>
553 <option value
="<?php echo '{'.$FIELD_TAG['FROM_STATE'].'}'; ?>"><?php
echo xlt('FROM'); ?
> - <?php
echo xlt('State'); ?
></option
>
554 <option value
="<?php echo '{'.$FIELD_TAG['FROM_POSTAL'].'}'; ?>"><?php
echo xlt('FROM'); ?
> - <?php
echo xlt('Postal Code'); ?
></option
>
555 <option value
="<?php echo '{'.$FIELD_TAG['FROM_VALEDICTORY'].'}'; ?>"><?php
echo xlt('FROM'); ?
> - <?php
echo xlt('Valedictory'); ?
></option
>
556 <option value
="<?php echo '{'.$FIELD_TAG['FROM_PHONECELL'].'}'; ?>"><?php
echo xlt('FROM'); ?
> - <?php
echo xlt('Cell Phone'); ?
></option
>
557 <option value
="<?php echo '{'.$FIELD_TAG['FROM_PHONE'].'}'; ?>"><?php
echo xlt('FROM'); ?
> - <?php
echo xlt('Phone'); ?
></option
>
558 <option value
="<?php echo '{'.$FIELD_TAG['FROM_EMAIL'].'}'; ?>"><?php
echo xlt('FROM'); ?
> - <?php
echo xlt('email'); ?
></option
>
559 <option value
="<?php echo '{'.$FIELD_TAG['TO_TITLE'].'}'; ?>"><?php
echo xlt('TO'); ?
> - <?php
echo xlt('Title'); ?
></option
>
560 <option value
="<?php echo '{'.$FIELD_TAG['TO_FNAME'].'}'; ?>"><?php
echo xlt('TO'); ?
> - <?php
echo xlt('First name'); ?
></option
>
561 <option value
="<?php echo '{'.$FIELD_TAG['TO_MNAME'].'}'; ?>"><?php
echo xlt('TO'); ?
> - <?php
echo xlt('Middle name'); ?
></option
>
562 <option value
="<?php echo '{'.$FIELD_TAG['TO_LNAME'].'}'; ?>"><?php
echo xlt('TO'); ?
> - <?php
echo xlt('Last name'); ?
></option
>
563 <option value
="<?php echo '{'.$FIELD_TAG['TO_STREET'].'}'; ?>"><?php
echo xlt('TO'); ?
> - <?php
echo xlt('Street'); ?
></option
>
564 <option value
="<?php echo '{'.$FIELD_TAG['TO_CITY'].'}'; ?>"><?php
echo xlt('TO'); ?
> - <?php
echo xlt('City'); ?
></option
>
565 <option value
="<?php echo '{'.$FIELD_TAG['TO_STATE'].'}'; ?>"><?php
echo xlt('TO'); ?
> - <?php
echo xlt('State'); ?
></option
>
566 <option value
="<?php echo '{'.$FIELD_TAG['TO_POSTAL'].'}'; ?>"><?php
echo xlt('TO'); ?
> - <?php
echo xlt('Postal Code'); ?
></option
>
567 <option value
="<?php echo '{'.$FIELD_TAG['TO_VALEDICTORY'].'}'; ?>"><?php
echo xlt('TO'); ?
> - <?php
echo xlt('Valedictory'); ?
></option
>
568 <option value
="<?php echo '{'.$FIELD_TAG['TO_ORGANIZATION'].'}'; ?>"><?php
echo xlt('TO'); ?
> - <?php
echo xlt('Organization'); ?
></option
>
569 <option value
="<?php echo '{'.$FIELD_TAG['TO_FAX'].'}'; ?>"><?php
echo xlt('TO'); ?
> - <?php
echo xlt('Fax number'); ?
></option
>
570 <option value
="<?php echo '{'.$FIELD_TAG['TO_PHONE'].'}'; ?>"><?php
echo xlt('TO'); ?
> - <?php
echo xlt('Phone number'); ?
></option
>
571 <option value
="<?php echo '{'.$FIELD_TAG['TO_PHONECELL'].'}'; ?>"><?php
echo xlt('TO'); ?
> - <?php
echo xlt('Cell phone number'); ?
></option
>
572 <option value
="<?php echo '{'.$FIELD_TAG['PT_FNAME'].'}'; ?>"><?php
echo xlt('PATIENT'); ?
> - <?php
echo xlt('First name'); ?
></option
>
573 <option value
="<?php echo '{'.$FIELD_TAG['PT_MNAME'].'}'; ?>"><?php
echo xlt('PATIENT'); ?
> - <?php
echo xlt('Middle name'); ?
></option
>
574 <option value
="<?php echo '{'.$FIELD_TAG['PT_LNAME'].'}'; ?>"><?php
echo xlt('PATIENT'); ?
> - <?php
echo xlt('Last name'); ?
></option
>
575 <option value
="<?php echo '{'.$FIELD_TAG['PT_STREET'].'}'; ?>"><?php
echo xlt('PATIENT'); ?
> - <?php
echo xlt('Street'); ?
></option
>
576 <option value
="<?php echo '{'.$FIELD_TAG['PT_CITY'].'}'; ?>"><?php
echo xlt('PATIENT'); ?
> - <?php
echo xlt('City'); ?
></option
>
577 <option value
="<?php echo '{'.$FIELD_TAG['PT_STATE'].'}'; ?>"><?php
echo xlt('PATIENT'); ?
> - <?php
echo xlt('State'); ?
></option
>
578 <option value
="<?php echo '{'.$FIELD_TAG['PT_POSTAL'].'}'; ?>"><?php
echo xlt('PATIENT'); ?
> - <?php
echo xlt('Postal Code'); ?
></option
>
579 <option value
="<?php echo '{'.$FIELD_TAG['PT_PHONE_HOME'].'}'; ?>"><?php
echo xlt('PATIENT'); ?
> - <?php
echo xlt('Phone Home'); ?
></option
>
580 <option value
="<?php echo '{'.$FIELD_TAG['PT_PHONE_CELL'].'}'; ?>"><?php
echo xlt('PATIENT'); ?
> - <?php
echo xlt('Phone Cell'); ?
></option
>
581 <option value
="<?php echo '{'.$FIELD_TAG['PT_SSN'].'}'; ?>"><?php
echo xlt('PATIENT'); ?
> - <?php
echo xlt('SSN'); ?
></option
>
582 <option value
="<?php echo '{'.$FIELD_TAG['PT_DOB'].'}'; ?>"><?php
echo xlt('PATIENT'); ?
> - <?php
echo xlt('Date of birth'); ?
></option
>
585 <textarea name
='form_body' id
="form_body" class='form-control' rows
='20' cols
='30' style
='width:100%'
586 title
='<?php echo xla('Enter body of letter here
'); ?>' /><?php
echo text($bodytext); ?
></textarea
>
592 <div
class="btn-group" role
="group">
593 <button type
='button' class='addtemplate btn btn-default btn-save'><?php
echo xlt('Save as New'); ?
></button
>
594 <button type
='button' class='btn btn-default btn-save' name
='savetemplate' id
="savetemplate"><?php
echo xlt('Save Changes'); ?
></button
>
595 <button type
='button' class='btn btn-default btn-transmit' name
='form_generate' id
="form_generate"><?php
echo xlt('Generate Letter'); ?
></button
>
600 <!-- template DIV that appears when user chooses to add a
new letter template
-->
601 <div id
="newtemplatedetail" style
="margin-top: 4em; display: none; visibility: hidden;">
602 <span
class='control-label'><?php
echo xlt('Template Name'); ?
>:</span
> <input type
="textbox" size
="20" maxlength
="30" name
="newtemplatename" id
="newtemplatename" class="form-control">
604 <div
class="btn-group" role
="group">
605 <button type
="button" class="savenewtemplate btn btn-default btn-save"><?php
echo xlt('Save new template'); ?
></button
>
606 <button type
="button" class="cancelnewtemplate btn btn-link btn-cancel"><?php
echo xlt('Cancel'); ?
></button
>
613 <script language
='JavaScript'>
615 // jQuery stuff to make the page a little easier to use
617 $
(document
).ready(function(){
618 $
("#form_generate").click(function() { $
("#formaction").val("generate"); $
("#theform").submit(); });
619 $
("#form_template").change(function() { $
("#formaction").val("loadtemplate"); $
("#theform").submit(); });
621 $
("#savetemplate").click(function() { SaveTemplate(this
); });
623 $
("#letter_field").change(function() { insertAtCursor(document
.getElementById("form_body"), $
(this
).val()); $
(this
).attr("selectedIndex", "0"); });
625 $
(".addtemplate").click(function() { AddTemplate(this
); });
626 $
(".savenewtemplate").click(function() { SaveNewTemplate(this
); });
627 $
(".deletetemplate").click(function() { DeleteTemplate(this
); });
628 $
(".cancelnewtemplate").click(function() { CancelNewTemplate(this
); });
630 $
('.datepicker').datetimepicker({
631 <?php
$datetimepicker_timepicker = false; ?
>
632 <?php
$datetimepicker_showseconds = false; ?
>
633 <?php
$datetimepicker_formatInput = true; ?
>
634 <?php
require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?
>
635 <?php
// can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
638 // display the 'new group' DIV
639 var AddTemplate
= function(btnObj
) {
640 // show the field details DIV
641 $
('#newtemplatedetail').css('visibility', 'visible');
642 $
('#newtemplatedetail').css('display', 'block');
643 $
(btnObj
).parent().append($
("#newtemplatedetail"));
644 $
('#newtemplatedetail > #newtemplatename').focus();
645 $
(window
).scrollTop($
(document
).height());
648 // save the new template
649 var SaveNewTemplate
= function(btnObj
) {
650 // the template name can only have letters, numbers, spaces and underscores
651 // AND it cannot start with a number
652 if ($
("#newtemplatename").val().match(/^\d+
/)) {
653 alert("<?php echo xls('Template names cannot start with numbers.'); ?>");
656 var validname
= $
("#newtemplatename").val().replace(/[^A
-za
-z0
-9]/g
, "_"); // match any non-word characters and replace them
657 $
("#newtemplatename").val(validname
);
659 // submit the form to add a new field to a specific group
660 $
("#formaction").val("newtemplate");
661 $
("#theform").submit();
664 // actually delete a template file
666 var DeleteTemplate = function(btnObj) {
667 var parts = $(btnObj).attr("id");
668 var groupname = parts.replace(/^\d+/, "");
669 if (confirm("WARNING - This action cannot be undone.\n Are you sure you wish to delete the entire group named '"+groupname+"'?")) {
670 // submit the form to add a new field to a specific group
671 $("#formaction").val("deletegroup");
672 $("#deletegroupname").val(parts);
673 $("#theform").submit();
678 // just hide the new template DIV
679 var CancelNewTemplate
= function(btnObj
) {
680 // hide the field details DIV
681 $
('#newtemplatedetail').css('visibility', 'hidden');
682 $
('#newtemplatedetail').css('display', 'none');
683 // reset the new group values to a default
684 $
('#newtemplatedetail > #newtemplatename').val("");
688 // save the template, overwriting the older version
689 var SaveTemplate
= function(btnObj
) {
690 if (! confirm("<?php echo xls('You are about to permanently replace the existing template. Are you sure you wish to continue?'); ?>")) {
693 $
("#formaction").val("savetemplate");
694 $
("#theform").submit();