fixes for prior commit
[openemr.git] / interface / patient_file / letter.php
blobb0705b5a07a8273f824be6aba017e8a6ec337884
1 <?php
2 // Copyright (C) 2007-2011 Rod Roark <rod@sunsetsystems.com>
3 //
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 // Undo magic quotes and do not allow fake register globals.
10 $sanitize_all_escapes = true;
11 $fake_register_globals = false;
13 include_once("../globals.php");
14 include_once($GLOBALS['srcdir'] . "/patient.inc");
16 $template_dir = $GLOBALS['OE_SITE_DIR'] . "/letter_templates";
18 // array of field name tags to allow internationalization
19 // of templates
20 $FIELD_TAG = array(
21 'DATE' => xl('DATE'),
22 'FROM_TITLE' => xl('FROM_TITLE'),
23 'FROM_FNAME' => xl('FROM_FNAME'),
24 'FROM_LNAME' => xl('FROM_LNAME'),
25 'FROM_MNAME' => xl('FROM_MNAME'),
26 'FROM_STREET' => xl('FROM_STREET'),
27 'FROM_CITY' => xl('FROM_CITY'),
28 'FROM_STATE' => xl('FROM_STATE'),
29 'FROM_POSTAL' => xl('FROM_POSTAL'),
30 'FROM_VALEDICTORY' => xl('FROM_VALEDICTORY'),
31 'FROM_PHONE' => xl('FROM_PHONE'),
32 'FROM_PHONECELL' => xl('FROM_PHONECELL'),
33 'FROM_EMAIL' => xl('FROM_EMAIL'),
34 'TO_TITLE' => xl('TO_TITLE'),
35 'TO_FNAME' => xl('TO_FNAME'),
36 'TO_LNAME' => xl('TO_LNAME'),
37 'TO_MNAME' => xl('TO_MNAME'),
38 'TO_STREET' => xl('TO_STREET'),
39 'TO_CITY' => xl('TO_CITY'),
40 'TO_STATE' => xl('TO_STATE'),
41 'TO_POSTAL' => xl('TO_POSTAL'),
42 'TO_VALEDICTORY' => xl('TO_VALEDICTORY'),
43 'TO_PHONE' => xl('TO_PHONE'),
44 'TO_PHONECELL' => xl('TO_PHONECELL'),
45 'TO_FAX' => xl('TO_FAX'),
46 'TO_ORGANIZATION' => xl('TO_ORGANIZATION'),
47 'PT_FNAME' => xl('PT_FNAME'),
48 'PT_LNAME' => xl('PT_LNAME'),
49 'PT_MNAME' => xl('PT_MNAME'),
50 'PT_STREET' => xl('PT_STREET'),
51 'PT_CITY' => xl('PT_CITY'),
52 'PT_STATE' => xl('PT_STATE'),
53 'PT_POSTAL' => xl('PT_POSTAL'),
54 'PT_PHONE_HOME' => xl('PT_PHONE_HOME'),
55 'PT_PHONE_CELL' => xl('PT_PHONE_CELL'),
56 'PT_SSN' => xl('PT_SSN'),
57 'PT_EMAIL' => xl('PT_EMAIL'),
58 'PT_DOB' => xl('PT_DOB')
62 $patdata = sqlQuery("SELECT " .
63 "p.fname, p.mname, p.lname, p.pubpid, p.DOB, " .
64 "p.street, p.city, p.state, p.phone_home, p.phone_cell, p.ss, p.email, p.postal_code " .
65 "FROM patient_data AS p " .
66 "WHERE p.pid = '$pid' LIMIT 1");
68 $alertmsg = ''; // anything here pops up in an alert box
70 // If the Generate button was clicked...
71 if ($_POST['formaction']=="generate") {
73 $form_pid = $_POST['form_pid'];
74 $form_from = $_POST['form_from'];
75 $form_to = $_POST['form_to'];
76 $form_date = $_POST['form_date'];
77 $form_template = $_POST['form_template'];
78 $form_format = $_POST['form_format'];
79 $form_body = $_POST['form_body'];
81 $frow = sqlQuery("SELECT * FROM users WHERE id = '$form_from'");
82 $trow = sqlQuery("SELECT * FROM users WHERE id = '$form_to'");
84 $datestr = date('j F Y', strtotime($form_date));
85 $from_title = $frow['title'] ? $frow['title'] . ' ' : '';
86 $to_title = $trow['title'] ? $trow['title'] . ' ' : '';
88 $cpstring = $_POST['form_body'];
90 // attempt to save to the autosaved template
91 $fh = fopen("$template_dir/autosaved", 'w');
92 // translate from definition to the constant
93 $temp_bodytext = $cpstring;
94 foreach ($FIELD_TAG as $key => $value) {
95 $temp_bodytext = str_replace("{".$value."}", "{".$key."}", $temp_bodytext);
97 if (! fwrite($fh, $temp_bodytext)) {
98 echo xl('Error while saving to the file','','',' ') . $template_dir."/autosaved" .
99 xl('Ensure OpenEMR has write privileges to directory','',' . ',' ') . $template_dir . "/ ." ;
100 die;
102 fclose($fh);
104 $cpstring = str_replace('{'.$FIELD_TAG['DATE'].'}' , $datestr, $cpstring);
105 $cpstring = str_replace('{'.$FIELD_TAG['FROM_TITLE'].'}' , $from_title, $cpstring);
106 $cpstring = str_replace('{'.$FIELD_TAG['FROM_FNAME'].'}' , $frow['fname'], $cpstring);
107 $cpstring = str_replace('{'.$FIELD_TAG['FROM_LNAME'].'}' , $frow['lname'], $cpstring);
108 $cpstring = str_replace('{'.$FIELD_TAG['FROM_MNAME'].'}' , $frow['mname'], $cpstring);
109 $cpstring = str_replace('{'.$FIELD_TAG['FROM_STREET'].'}' , $frow['street'], $cpstring);
110 $cpstring = str_replace('{'.$FIELD_TAG['FROM_CITY'].'}' , $frow['city'], $cpstring);
111 $cpstring = str_replace('{'.$FIELD_TAG['FROM_STATE'].'}' , $frow['state'], $cpstring);
112 $cpstring = str_replace('{'.$FIELD_TAG['FROM_POSTAL'].'}' , $frow['zip'], $cpstring);
113 $cpstring = str_replace('{'.$FIELD_TAG['FROM_VALEDICTORY'].'}', $frow['valedictory'], $cpstring);
114 $cpstring = str_replace('{'.$FIELD_TAG['FROM_PHONECELL'].'}' , $frow['phonecell'], $cpstring);
115 $cpstring = str_replace('{'.$FIELD_TAG['FROM_PHONE'].'}' , $frow['phone'], $cpstring);
116 $cpstring = str_replace('{'.$FIELD_TAG['FROM_EMAIL'].'}' , $frow['email'], $cpstring);
117 $cpstring = str_replace('{'.$FIELD_TAG['TO_TITLE'].'}' , $to_title, $cpstring);
118 $cpstring = str_replace('{'.$FIELD_TAG['TO_FNAME'].'}' , $trow['fname'], $cpstring);
119 $cpstring = str_replace('{'.$FIELD_TAG['TO_LNAME'].'}' , $trow['lname'], $cpstring);
120 $cpstring = str_replace('{'.$FIELD_TAG['TO_MNAME'].'}' , $trow['mname'], $cpstring);
121 $cpstring = str_replace('{'.$FIELD_TAG['TO_STREET'].'}' , $trow['street'], $cpstring);
122 $cpstring = str_replace('{'.$FIELD_TAG['TO_CITY'].'}' , $trow['city'], $cpstring);
123 $cpstring = str_replace('{'.$FIELD_TAG['TO_STATE'].'}' , $trow['state'], $cpstring);
124 $cpstring = str_replace('{'.$FIELD_TAG['TO_POSTAL'].'}' , $trow['zip'], $cpstring);
125 $cpstring = str_replace('{'.$FIELD_TAG['TO_VALEDICTORY'].'}' , $trow['valedictory'], $cpstring);
126 $cpstring = str_replace('{'.$FIELD_TAG['TO_FAX'].'}' , $trow['fax'], $cpstring);
127 $cpstring = str_replace('{'.$FIELD_TAG['TO_PHONE'].'}' , $trow['phone'], $cpstring);
128 $cpstring = str_replace('{'.$FIELD_TAG['TO_PHONECELL'].'}' , $trow['phonecell'], $cpstring);
129 $cpstring = str_replace('{'.$FIELD_TAG['TO_ORGANIZATION'].'}' , $trow['organization'], $cpstring);
130 $cpstring = str_replace('{'.$FIELD_TAG['PT_FNAME'].'}' , $patdata['fname'], $cpstring);
131 $cpstring = str_replace('{'.$FIELD_TAG['PT_LNAME'].'}' , $patdata['lname'], $cpstring);
132 $cpstring = str_replace('{'.$FIELD_TAG['PT_MNAME'].'}' , $patdata['mname'], $cpstring);
133 $cpstring = str_replace('{'.$FIELD_TAG['PT_STREET'].'}' , $patdata['street'], $cpstring);
134 $cpstring = str_replace('{'.$FIELD_TAG['PT_CITY'].'}' , $patdata['city'], $cpstring);
135 $cpstring = str_replace('{'.$FIELD_TAG['PT_STATE'].'}' , $patdata['state'], $cpstring);
136 $cpstring = str_replace('{'.$FIELD_TAG['PT_POSTAL'].'}' , $patdata['postal_code'], $cpstring);
137 $cpstring = str_replace('{'.$FIELD_TAG['PT_PHONE_HOME'].'}' , $patdata['phone_home'], $cpstring);
138 $cpstring = str_replace('{'.$FIELD_TAG['PT_PHONE_CELL'].'}' , $patdata['phone_cell'], $cpstring);
139 $cpstring = str_replace('{'.$FIELD_TAG['PT_SSN'].'}' , $patdata['ss'], $cpstring);
140 $cpstring = str_replace('{'.$FIELD_TAG['PT_EMAIL'].'}' , $patdata['email'], $cpstring);
141 $cpstring = str_replace('{'.$FIELD_TAG['PT_DOB'].'}' , $patdata['DOB'], $cpstring);
143 if ($form_format == "pdf") {
144 // documentation for ezpdf is here --> http://www.ros.co.nz/pdf/
145 require_once ($GLOBALS['fileroot'] . "/library/classes/class.ezpdf.php");
146 $pdf =& new Cezpdf($GLOBALS['rx_paper_size']);
147 $pdf->ezSetMargins($GLOBALS['rx_top_margin']
148 ,$GLOBALS['rx_bottom_margin']
149 ,$GLOBALS['rx_left_margin']
150 ,$GLOBALS['rx_right_margin']
152 if (file_exists("$template_dir/custom_pdf.php")) {
153 include("$template_dir/custom_pdf.php");
155 else {
156 $pdf->selectFont($GLOBALS['fileroot'] . "/library/fonts/Helvetica.afm");
157 $pdf->ezText($cpstring, 12);
159 $pdf->ezStream();
160 exit;
162 else { // $form_format = html
163 $cpstring = text($cpstring); //escape to prevent stored cross script attack
164 $cpstring = str_replace("\n", "<br>", $cpstring);
165 $cpstring = str_replace("\t", "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;", $cpstring);
167 <html>
168 <head>
169 <style>
170 body {
171 font-family: sans-serif;
172 font-weight: normal;
173 font-size: 12pt;
174 background: white;
175 color: black;
177 .paddingdiv {
178 width: 524pt;
179 padding: 0pt;
180 margin-top: 50pt;
182 .navigate {
183 margin-top: 2.5em;
185 @media print {
186 .navigate {
187 display: none;
190 </style>
191 <title><?php xl('Letter','e'); ?></title>
192 </head>
193 <body>
194 <div class='paddingdiv'>
195 <?php echo $cpstring; ?>
196 <div class="navigate">
197 <a href="<?php echo $GLOBALS['rootdir'] . '/patient_file/letter.php?template=autosaved'; ?>">(<?php xl('Back','e'); ?>)</a>
198 </div>
199 <script language='JavaScript'>
200 window.print();
201 </script>
202 </body>
203 </div>
204 <?php
205 exit;
208 else if (isset($_GET['template']) && $_GET['template'] != "") {
209 // utilized to go back to autosaved template
210 $bodytext = "";
211 $fh = fopen("$template_dir/".$_GET['template'], 'r');
212 while (!feof($fh)) $bodytext.= fread($fh, 8192);
213 fclose($fh);
214 // translate from constant to the definition
215 foreach ($FIELD_TAG as $key => $value) {
216 $bodytext = str_replace("{".$key."}", "{".$value."}", $bodytext);
219 else if ($_POST['formaction'] == "loadtemplate" && $_POST['form_template'] != "") {
220 $bodytext = "";
221 $fh = fopen("$template_dir/".$_POST['form_template'], 'r');
222 while (!feof($fh)) $bodytext.= fread($fh, 8192);
223 fclose($fh);
224 // translate from constant to the definition
225 foreach ($FIELD_TAG as $key => $value) {
226 $bodytext = str_replace("{".$key."}", "{".$value."}", $bodytext);
229 else if ($_POST['formaction'] == "newtemplate" && $_POST['newtemplatename'] != "") {
230 // attempt to save the template
231 $fh = fopen("$template_dir/".$_POST['newtemplatename'], 'w');
232 // translate from definition to the constant
233 $temp_bodytext = $_POST['form_body'];
234 foreach ($FIELD_TAG as $key => $value) {
235 $temp_bodytext = str_replace("{".$value."}", "{".$key."}", $temp_bodytext);
237 if (! fwrite($fh, $temp_bodytext)) {
238 echo xl('Error while writing to file','','',' ') . $template_dir."/".$_POST['newtemplatename'];
239 die;
241 fclose($fh);
243 // read the saved file back
244 $_POST['form_template'] = $_POST['newtemplatename'];
245 $fh = fopen("$template_dir/".$_POST['form_template'], 'r');
246 while (!feof($fh)) $bodytext.= fread($fh, 8192);
247 fclose($fh);
248 // translate from constant to the definition
249 foreach ($FIELD_TAG as $key => $value) {
250 $bodytext = str_replace("{".$key."}", "{".$value."}" , $bodytext);
253 else if ($_POST['formaction'] == "savetemplate" && $_POST['form_template'] != "") {
254 // attempt to save the template
255 $fh = fopen("$template_dir/".$_POST['form_template'], 'w');
256 // translate from definition to the constant
257 $temp_bodytext = $_POST['form_body'];
258 foreach ($FIELD_TAG as $key => $value) {
259 $temp_bodytext = str_replace("{".$value."}", "{".$key."}", $temp_bodytext);
261 if (! fwrite($fh, $temp_bodytext)) {
262 echo xl('Error while writing to file','','',' ') . $template_dir."/".$_POST['form_template'];
263 die;
265 fclose($fh);
267 // read the saved file back
268 $fh = fopen("$template_dir/".$_POST['form_template'], 'r');
269 while (!feof($fh)) $bodytext.= fread($fh, 8192);
270 fclose($fh);
271 // translate from constant to the definition
272 foreach ($FIELD_TAG as $key => $value) {
273 $bodytext = str_replace("{".$key."}", "{".$value."}", $bodytext);
277 // This is the case where we display the form for data entry.
278 // Get the users list.
279 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
280 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
281 "ORDER BY lname, fname");
282 $i = 0;
283 $optfrom = '';
284 $optto = '';
285 $ulist = "var ulist = new Array();\n";
286 while ($urow = sqlFetchArray($ures)) {
287 $uname = $urow['lname'];
288 if ($urow['fname']) $uname .= ", " . $urow['fname'];
289 $tmp1 = " <option value='" . $urow['id'] . "'";
290 $tmp2 = ">$uname</option>\n";
291 $optto .= $tmp1 . $tmp2;
292 if ($urow['id'] == $_SESSION['authUserID']) $tmp1 .= " selected";
293 $optfrom .= $tmp1 . $tmp2;
294 $ulist .= "ulist[$i] = '" . addslashes($uname) . "|" .
295 $urow['id'] . "|" . addslashes($urow['specialty']) . "';\n";
296 ++$i;
299 // Get the unique specialties.
300 $sres = sqlStatement("SELECT DISTINCT specialty FROM users " .
301 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
302 "ORDER BY specialty");
303 $optspec = "<option value='All'>" . xl('All') . "</option>\n";
304 while ($srow = sqlFetchArray($sres)) {
305 $optspec .= " <option value='" . $srow['specialty'] . "'>" .
306 $srow['specialty'] . "</option>\n";
310 <html>
311 <head>
312 <?php html_header_show();?>
313 <title><?php xl('Letter Generator','e'); ?></title>
315 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
316 <link rel='stylesheet' href='<?php echo $css_header ?>' type='text/css'>
318 <!-- supporting javascript code -->
319 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery.js"></script>
321 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/topdialog.js"></script>
322 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dialog.js"></script>
323 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/textformat.js"></script>
324 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dynarch_calendar.js"></script>
325 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
326 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dynarch_calendar_setup.js"></script>
328 <script language="JavaScript">
329 <?php echo $ulist; ?>
331 // React to selection of a specialty. This rebuilds the "to" users list
332 // with users having that specialty, or all users if "All" is selected.
333 function newspecialty() {
334 var f = document.forms[0];
335 var s = f.form_specialty.value;
336 var theopts = f.form_to.options;
337 theopts.length = 0;
338 var j = 0;
339 for (var i = 0; i < ulist.length; ++i) {
340 tmp = ulist[i].split("|");
341 if (s != 'All' && s != tmp[2]) continue;
342 theopts[j++] = new Option(tmp[0], tmp[1], false, false);
347 // insert text into a textarea where the cursor is
348 function insertAtCaret(areaId,text) {
349 var txtarea = document.getElementById(areaId);
350 var scrollPos = txtarea.scrollTop;
351 var strPos = 0;
352 var br = ((txtarea.selectionStart || txtarea.selectionStart == '0') ?
353 "ff" : (document.selection ? "ie" : false ) );
354 if (br == "ie") {
355 txtarea.focus();
356 var range = document.selection.createRange();
357 range.moveStart ('character', -txtarea.value.length);
358 strPos = range.text.length;
360 else if (br == "ff") strPos = txtarea.selectionStart;
362 var front = (txtarea.value).substring(0,strPos);
363 var back = (txtarea.value).substring(strPos,txtarea.value.length);
364 txtarea.value=front+text+back;
365 strPos = strPos + text.length;
366 if (br == "ie") {
367 txtarea.focus();
368 var range = document.selection.createRange();
369 range.moveStart ('character', -txtarea.value.length);
370 range.moveStart ('character', strPos);
371 range.moveEnd ('character', 0);
372 range.select();
374 else if (br == "ff") {
375 txtarea.selectionStart = strPos;
376 txtarea.selectionEnd = strPos;
377 txtarea.focus();
379 txtarea.scrollTop = scrollPos;
382 function insertAtCursor(myField, myValue) {
383 //IE support
384 if (document.selection) {
385 myField.focus();
386 sel = document.selection.createRange();
387 sel.text = myValue;
389 //MOZILLA/NETSCAPE support
390 else if (myField.selectionStart || myField.selectionStart == '0') {
391 var startPos = myField.selectionStart;
392 var endPos = myField.selectionEnd;
393 myField.value = myField.value.substring(0, startPos)
394 + myValue
395 + myField.value.substring(endPos, myField.value.length);
396 } else {
397 myField.value += myValue;
402 </script>
404 </head>
406 <body class="body_top" onunload='imclosing()'>
408 <!-- <form method='post' action='letter.php' onsubmit='return top.restoreSession()'> -->
409 <form method='post' action='letter.php' id="theform" name="theform">
410 <input type="hidden" name="formaction" id="formaction" value="">
411 <input type='hidden' name='form_pid' value='<?php echo $pid ?>' />
413 <center>
415 <table border='0' cellspacing='8' width='98%'>
417 <tr>
418 <td colspan='4' align='center'>
419 &nbsp;<br>
420 <b><?php xl('Generate Letter regarding ','e','',' '); echo $patdata['fname'] . " " .
421 $patdata['lname'] . " (" . $patdata['pubpid'] . ")" ?></b>
422 <br>&nbsp;
423 </td>
424 </tr>
426 <tr>
428 <td>
429 <?php xl('From','e'); ?>:
430 </td>
432 <td>
433 <select name='form_from'>
434 <?php echo $optfrom; ?>
435 </select>
436 </td>
438 <td>
439 <?php xl('Date','e'); ?>:
440 </td>
442 <td>
443 <input type='text' size='10' name='form_date' id='form_date'
444 value='<?php echo date('Y-m-d'); ?>'
445 title='<?php xl('yyyy-mm-dd date of this letter','e'); ?>'
446 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' />
447 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
448 id='img_date' border='0' alt='[?]' style='cursor:pointer'
449 title='<?php xl('Click here to choose a date','e'); ?>' />
450 </td>
452 </tr>
454 <tr>
456 <td>
457 <?php xl('Specialty','e'); ?>:
458 </td>
460 <td>
461 <select name='form_specialty' onchange='newspecialty()'>
462 <?php echo $optspec; ?>
463 </select>
464 </td>
466 <td>
467 <?php xl('Template','e'); ?>:
468 </td>
470 <td>
471 <select name="form_template" id="form_template">
472 <option value="">(<?php xl('none','e'); ?>)</option>
473 <?php
474 $tpldir = $GLOBALS['OE_SITE_DIR'] . "/letter_templates";
475 $dh = opendir($tpldir);
476 if (! $dh) die(xl('Cannot read','','',' ') . $tpldir);
477 while (false !== ($tfname = readdir($dh))) {
478 // skip dot-files, scripts and images
479 if (preg_match("/^\./" , $tfname)) { continue; }
480 if (preg_match("/\.php$/", $tfname)) { continue; }
481 if (preg_match("/\.jpg$/", $tfname)) { continue; }
482 if (preg_match("/\.png$/", $tfname)) { continue; }
483 echo "<option value=".$tfname;
484 if (($tfname == $_POST['form_template']) || ($tfname == $_GET['template'])) echo " SELECTED";
485 echo ">";
486 if ($tfname == 'autosaved') {
487 echo xl($tfname);
489 else {
490 echo $tfname;
492 echo "</option>";
494 closedir($dh);
496 </select>
497 </td>
499 </tr>
501 </tr>
503 <tr>
505 <td>
506 <?php xl('To','e'); ?>:
507 </td>
509 <td>
510 <select name='form_to'>
511 <?php echo $optto; ?>
512 </select>
513 </td>
515 <td>
516 <?php xl('Print Format','e'); ?>:
517 </td>
519 <td>
520 <select name='form_format'>
521 <option value='html'><?php xl('HTML','e'); ?></option>
522 <option value='pdf'><?php xl('PDF','e'); ?></option>
523 </select>
524 </td>
526 </tr>
528 <tr>
529 <td colspan='4'>
530 <div id="letter_toolbar" class='text' style="width: 100%; background-color: #ddd; padding: 5px; margin: 0px;">
531 Insert special field:
532 <select id="letter_field">
533 <option value="">- <?php xl('Choose','e'); ?> -</option>
534 <option value="<?php echo '{'.$FIELD_TAG['DATE'].'}'; ?>"><?php xl('Today\'s Date','e'); ?></option>
535 <option value="<?php echo '{'.$FIELD_TAG['FROM_TITLE'].'}'; ?>"><?php xl('FROM','e'); ?> - <?php xl('Title','e'); ?></option>
536 <option value="<?php echo '{'.$FIELD_TAG['FROM_FNAME'].'}'; ?>"><?php xl('FROM','e'); ?> - <?php xl('First name','e'); ?></option>
537 <option value="<?php echo '{'.$FIELD_TAG['FROM_MNAME'].'}'; ?>"><?php xl('FROM','e'); ?> - <?php xl('Middle name','e'); ?></option>
538 <option value="<?php echo '{'.$FIELD_TAG['FROM_LNAME'].'}'; ?>"><?php xl('FROM','e'); ?> - <?php xl('Last name','e'); ?></option>
539 <option value="<?php echo '{'.$FIELD_TAG['FROM_STREET'].'}'; ?>"><?php xl('FROM','e'); ?> - <?php xl('Street','e'); ?></option>
540 <option value="<?php echo '{'.$FIELD_TAG['FROM_CITY'].'}'; ?>"><?php xl('FROM','e'); ?> - <?php xl('City','e'); ?></option>
541 <option value="<?php echo '{'.$FIELD_TAG['FROM_STATE'].'}'; ?>"><?php xl('FROM','e'); ?> - <?php xl('State','e'); ?></option>
542 <option value="<?php echo '{'.$FIELD_TAG['FROM_POSTAL'].'}'; ?>"><?php xl('FROM','e'); ?> - <?php xl('Postal Code','e'); ?></option>
543 <option value="<?php echo '{'.$FIELD_TAG['FROM_VALEDICTORY'].'}'; ?>"><?php xl('FROM','e'); ?> - <?php xl('Valedictory','e'); ?></option>
544 <option value="<?php echo '{'.$FIELD_TAG['FROM_PHONECELL'].'}'; ?>"><?php xl('FROM','e'); ?> - <?php xl('Cell Phone','e'); ?></option>
545 <option value="<?php echo '{'.$FIELD_TAG['FROM_PHONE'].'}'; ?>"><?php xl('FROM','e'); ?> - <?php xl('Phone','e'); ?></option>
546 <option value="<?php echo '{'.$FIELD_TAG['FROM_EMAIL'].'}'; ?>"><?php xl('FROM','e'); ?> - <?php xl('email','e'); ?></option>
547 <option value="<?php echo '{'.$FIELD_TAG['TO_TITLE'].'}'; ?>"><?php xl('TO','e'); ?> - <?php xl('Title','e'); ?></option>
548 <option value="<?php echo '{'.$FIELD_TAG['TO_FNAME'].'}'; ?>"><?php xl('TO','e'); ?> - <?php xl('First name','e'); ?></option>
549 <option value="<?php echo '{'.$FIELD_TAG['TO_MNAME'].'}'; ?>"><?php xl('TO','e'); ?> - <?php xl('Middle name','e'); ?></option>
550 <option value="<?php echo '{'.$FIELD_TAG['TO_LNAME'].'}'; ?>"><?php xl('TO','e'); ?> - <?php xl('Last name','e'); ?></option>
551 <option value="<?php echo '{'.$FIELD_TAG['TO_STREET'].'}'; ?>"><?php xl('TO','e'); ?> - <?php xl('Street','e'); ?></option>
552 <option value="<?php echo '{'.$FIELD_TAG['TO_CITY'].'}'; ?>"><?php xl('TO','e'); ?> - <?php xl('City','e'); ?></option>
553 <option value="<?php echo '{'.$FIELD_TAG['TO_STATE'].'}'; ?>"><?php xl('TO','e'); ?> - <?php xl('State','e'); ?></option>
554 <option value="<?php echo '{'.$FIELD_TAG['TO_POSTAL'].'}'; ?>"><?php xl('TO','e'); ?> - <?php xl('Postal Code','e'); ?></option>
555 <option value="<?php echo '{'.$FIELD_TAG['TO_VALEDICTORY'].'}'; ?>"><?php xl('TO','e'); ?> - <?php xl('Valedictory','e'); ?></option>
556 <option value="<?php echo '{'.$FIELD_TAG['TO_ORGANIZATION'].'}'; ?>"><?php xl('TO','e'); ?> - <?php xl('Organization','e'); ?></option>
557 <option value="<?php echo '{'.$FIELD_TAG['TO_FAX'].'}'; ?>"><?php xl('TO','e'); ?> - <?php xl('Fax number','e'); ?></option>
558 <option value="<?php echo '{'.$FIELD_TAG['TO_PHONE'].'}'; ?>"><?php xl('TO','e'); ?> - <?php xl('Phone number','e'); ?></option>
559 <option value="<?php echo '{'.$FIELD_TAG['TO_PHONECELL'].'}'; ?>"><?php xl('TO','e'); ?> - <?php xl('Cell phone number','e'); ?></option>
560 <option value="<?php echo '{'.$FIELD_TAG['PT_FNAME'].'}'; ?>"><?php xl('PATIENT','e'); ?> - <?php xl('First name','e'); ?></option>
561 <option value="<?php echo '{'.$FIELD_TAG['PT_MNAME'].'}'; ?>"><?php xl('PATIENT','e'); ?> - <?php xl('Middle name','e'); ?></option>
562 <option value="<?php echo '{'.$FIELD_TAG['PT_LNAME'].'}'; ?>"><?php xl('PATIENT','e'); ?> - <?php xl('Last name','e'); ?></option>
563 <option value="<?php echo '{'.$FIELD_TAG['PT_STREET'].'}'; ?>"><?php xl('PATIENT','e'); ?> - <?php xl('Street','e'); ?></option>
564 <option value="<?php echo '{'.$FIELD_TAG['PT_CITY'].'}'; ?>"><?php xl('PATIENT','e'); ?> - <?php xl('City','e'); ?></option>
565 <option value="<?php echo '{'.$FIELD_TAG['PT_STATE'].'}'; ?>"><?php xl('PATIENT','e'); ?> - <?php xl('State','e'); ?></option>
566 <option value="<?php echo '{'.$FIELD_TAG['PT_POSTAL'].'}'; ?>"><?php xl('PATIENT','e'); ?> - <?php xl('Postal Code','e'); ?></option>
567 <option value="<?php echo '{'.$FIELD_TAG['PT_PHONE_HOME'].'}'; ?>"><?php xl('PATIENT','e'); ?> - <?php xl('Phone Home','e'); ?></option>
568 <option value="<?php echo '{'.$FIELD_TAG['PT_PHONE_CELL'].'}'; ?>"><?php xl('PATIENT','e'); ?> - <?php xl('Phone Cell','e'); ?></option>
569 <option value="<?php echo '{'.$FIELD_TAG['PT_SSN'].'}'; ?>"><?php xl('PATIENT','e'); ?> - <?php xl('SSN','e'); ?></option>
570 <option value="<?php echo '{'.$FIELD_TAG['PT_DOB'].'}'; ?>"><?php xl('PATIENT','e'); ?> - <?php xl('Date of birth','e'); ?></option>
571 </select>
572 </div>
573 <textarea name='form_body' id="form_body" rows='20' cols='30' style='width:100%'
574 title=<?php xl('Enter body of letter here','e','\'','\''); ?> /><?php echo $bodytext; ?></textarea>
575 </td>
576 </tr>
578 </table>
580 <input type='button' class="addtemplate" value=<?php xl('Save as New','e','\'','\''); ?>>
581 <input type='button' name='savetemplate' id="savetemplate" value=<?php xl('Save Changes','e','\'','\''); ?>>
582 <input type='button' name='form_generate' id="form_generate" value=<?php xl('Generate Letter','e','\'','\''); ?>>
584 </center>
586 <!-- template DIV that appears when user chooses to add a new letter template -->
587 <div id="newtemplatedetail" style="border: 1px solid black; padding: 3px; display: none; visibility: hidden; background-color: lightgrey;">
588 <?php xl('Template Name','e'); ?>: <input type="textbox" size="20" maxlength="30" name="newtemplatename" id="newtemplatename">
589 <br>
590 <input type="button" class="savenewtemplate" value=<?php xl('Save new template','e','\'','\''); ?>>
591 <input type="button" class="cancelnewtemplate" value=<?php xl('Cancel','e','\'','\''); ?>>
592 </div>
594 </form>
595 </body>
597 <script language='JavaScript'>
598 Calendar.setup({inputField:"form_date", ifFormat:"%Y-%m-%d", button:"img_date"});
600 // jQuery stuff to make the page a little easier to use
602 $(document).ready(function(){
603 $("#form_generate").click(function() { $("#formaction").val("generate"); $("#theform").submit(); });
604 $("#form_template").change(function() { $("#formaction").val("loadtemplate"); $("#theform").submit(); });
606 $("#savetemplate").click(function() { SaveTemplate(this); });
608 $("#letter_field").change(function() { insertAtCursor(document.getElementById("form_body"), $(this).val()); $(this).attr("selectedIndex", "0"); });
610 $(".addtemplate").click(function() { AddTemplate(this); });
611 $(".savenewtemplate").click(function() { SaveNewTemplate(this); });
612 $(".deletetemplate").click(function() { DeleteTemplate(this); });
613 $(".cancelnewtemplate").click(function() { CancelNewTemplate(this); });
615 // display the 'new group' DIV
616 var AddTemplate = function(btnObj) {
617 // show the field details DIV
618 $('#newtemplatedetail').css('visibility', 'visible');
619 $('#newtemplatedetail').css('display', 'block');
620 $(btnObj).parent().append($("#newtemplatedetail"));
621 $('#newtemplatedetail > #newtemplatename').focus();
624 // save the new template
625 var SaveNewTemplate = function(btnObj) {
626 // the template name can only have letters, numbers, spaces and underscores
627 // AND it cannot start with a number
628 if ($("#newtemplatename").val().match(/^\d+/)) {
629 alert("<?php xl('Template names cannot start with numbers.','e'); ?>");
630 return false;
632 var validname = $("#newtemplatename").val().replace(/[^A-za-z0-9]/g, "_"); // match any non-word characters and replace them
633 $("#newtemplatename").val(validname);
635 // submit the form to add a new field to a specific group
636 $("#formaction").val("newtemplate");
637 $("#theform").submit();
640 // actually delete a template file
642 var DeleteTemplate = function(btnObj) {
643 var parts = $(btnObj).attr("id");
644 var groupname = parts.replace(/^\d+/, "");
645 if (confirm("WARNING - This action cannot be undone.\n Are you sure you wish to delete the entire group named '"+groupname+"'?")) {
646 // submit the form to add a new field to a specific group
647 $("#formaction").val("deletegroup");
648 $("#deletegroupname").val(parts);
649 $("#theform").submit();
654 // just hide the new template DIV
655 var CancelNewTemplate = function(btnObj) {
656 // hide the field details DIV
657 $('#newtemplatedetail').css('visibility', 'hidden');
658 $('#newtemplatedetail').css('display', 'none');
659 // reset the new group values to a default
660 $('#newtemplatedetail > #newtemplatename').val("");
664 // save the template, overwriting the older version
665 var SaveTemplate = function(btnObj) {
666 if (! confirm("<?php xl('You are about to permanently replace the existing template. Are you sure you wish to continue?','e'); ?>")) {
667 return false;
669 $("#formaction").val("savetemplate");
670 $("#theform").submit();
674 </script>
676 </html>