added support for optional custom pdf logic
[openemr.git] / interface / patient_file / letter.php
blobfd1e8da5c47b07ebe25d138d44f1c40214830332
1 <?php
2 // Copyright (C) 2007, 2009 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 include_once("../globals.php");
10 include_once($GLOBALS['srcdir'] . "/patient.inc");
12 $template_dir = "$webserver_root/custom/letter_templates";
14 // array of field name tags to allow internationalization
15 // of templates
16 $FIELD_TAG = array(
17 'DATE' => xl('DATE'),
18 'FROM_TITLE' => xl('FROM_TITLE'),
19 'FROM_FNAME' => xl('FROM_FNAME'),
20 'FROM_LNAME' => xl('FROM_LNAME'),
21 'FROM_MNAME' => xl('FROM_MNAME'),
22 'FROM_STREET' => xl('FROM_STREET'),
23 'FROM_CITY' => xl('FROM_CITY'),
24 'FROM_STATE' => xl('FROM_STATE'),
25 'FROM_POSTAL' => xl('FROM_POSTAL'),
26 'FROM_VALEDICTORY' => xl('FROM_VALEDICTORY'),
27 'FROM_PHONECELL' => xl('FROM_PHONECELL'),
28 'TO_TITLE' => xl('TO_TITLE'),
29 'TO_FNAME' => xl('TO_FNAME'),
30 'TO_LNAME' => xl('TO_LNAME'),
31 'TO_MNAME' => xl('TO_MNAME'),
32 'TO_STREET' => xl('TO_STREET'),
33 'TO_CITY' => xl('TO_CITY'),
34 'TO_STATE' => xl('TO_STATE'),
35 'TO_POSTAL' => xl('TO_POSTAL'),
36 'TO_VALEDICTORY' => xl('TO_VALEDICTORY'),
37 'TO_FAX' => xl('TO_FAX'),
38 'TO_ORGANIZATION' => xl('TO_ORGANIZATION'),
39 'PT_FNAME' => xl('PT_FNAME'),
40 'PT_LNAME' => xl('PT_LNAME'),
41 'PT_MNAME' => xl('PT_MNAME'),
42 'PT_STREET' => xl('PT_STREET'),
43 'PT_CITY' => xl('PT_CITY'),
44 'PT_STATE' => xl('PT_STATE'),
45 'PT_POSTAL' => xl('PT_POSTAL'),
46 'PT_DOB' => xl('PT_DOB')
49 $patdata = sqlQuery("SELECT " .
50 "p.fname, p.mname, p.lname, p.pubpid, p.DOB, " .
51 "p.street, p.city, p.state, p.postal_code " .
52 "FROM patient_data AS p " .
53 "WHERE p.pid = '$pid' LIMIT 1");
55 $alertmsg = ''; // anything here pops up in an alert box
57 // If the Generate button was clicked...
58 if ($_POST['formaction']=="generate") {
60 $form_pid = $_POST['form_pid'];
61 $form_from = $_POST['form_from'];
62 $form_to = $_POST['form_to'];
63 $form_date = $_POST['form_date'];
64 $form_template = $_POST['form_template'];
65 $form_format = $_POST['form_format'];
66 $form_body = $_POST['form_body'];
68 $frow = sqlQuery("SELECT * FROM users WHERE id = '$form_from'");
69 $trow = sqlQuery("SELECT * FROM users WHERE id = '$form_to'");
71 $datestr = date('j F Y', strtotime($form_date));
72 $from_title = $frow['title'] ? $frow['title'] . ' ' : '';
73 $to_title = $trow['title'] ? $trow['title'] . ' ' : '';
75 $cpstring = $_POST['form_body'];
77 // attempt to save to the autosaved template
78 $fh = fopen("$template_dir/autosaved", 'w');
79 // translate from definition to the constant
80 $temp_bodytext = $cpstring;
81 foreach ($FIELD_TAG as $key => $value) {
82 $temp_bodytext = str_replace("{".$value."}", "{".$key."}", $temp_bodytext);
84 if (! fwrite($fh, $temp_bodytext)) {
85 echo xl('Error while saving to the file','','',' ') . $template_dir."/autosaved" .
86 xl('Ensure OpenEMR has write privileges to directory','',' . ',' ') . $template_dir . "/ ." ;
87 die;
89 fclose($fh);
91 $cpstring = str_replace('{'.$FIELD_TAG['DATE'].'}' , $datestr, $cpstring);
92 $cpstring = str_replace('{'.$FIELD_TAG['FROM_TITLE'].'}' , $from_title, $cpstring);
93 $cpstring = str_replace('{'.$FIELD_TAG['FROM_FNAME'].'}' , $frow['fname'], $cpstring);
94 $cpstring = str_replace('{'.$FIELD_TAG['FROM_LNAME'].'}' , $frow['lname'], $cpstring);
95 $cpstring = str_replace('{'.$FIELD_TAG['FROM_MNAME'].'}' , $frow['mname'], $cpstring);
96 $cpstring = str_replace('{'.$FIELD_TAG['FROM_STREET'].'}' , $frow['street'], $cpstring);
97 $cpstring = str_replace('{'.$FIELD_TAG['FROM_CITY'].'}' , $frow['city'], $cpstring);
98 $cpstring = str_replace('{'.$FIELD_TAG['FROM_STATE'].'}' , $frow['state'], $cpstring);
99 $cpstring = str_replace('{'.$FIELD_TAG['FROM_POSTAL'].'}' , $frow['zip'], $cpstring);
100 $cpstring = str_replace('{'.$FIELD_TAG['FROM_VALEDICTORY'].'}', $frow['valedictory'], $cpstring);
101 $cpstring = str_replace('{'.$FIELD_TAG['FROM_PHONECELL'].'}' , $frow['phonecell'], $cpstring);
102 $cpstring = str_replace('{'.$FIELD_TAG['TO_TITLE'].'}' , $to_title, $cpstring);
103 $cpstring = str_replace('{'.$FIELD_TAG['TO_FNAME'].'}' , $trow['fname'], $cpstring);
104 $cpstring = str_replace('{'.$FIELD_TAG['TO_LNAME'].'}' , $trow['lname'], $cpstring);
105 $cpstring = str_replace('{'.$FIELD_TAG['TO_MNAME'].'}' , $trow['mname'], $cpstring);
106 $cpstring = str_replace('{'.$FIELD_TAG['TO_STREET'].'}' , $trow['street'], $cpstring);
107 $cpstring = str_replace('{'.$FIELD_TAG['TO_CITY'].'}' , $trow['city'], $cpstring);
108 $cpstring = str_replace('{'.$FIELD_TAG['TO_STATE'].'}' , $trow['state'], $cpstring);
109 $cpstring = str_replace('{'.$FIELD_TAG['TO_POSTAL'].'}' , $trow['zip'], $cpstring);
110 $cpstring = str_replace('{'.$FIELD_TAG['TO_VALEDICTORY'].'}' , $trow['valedictory'], $cpstring);
111 $cpstring = str_replace('{'.$FIELD_TAG['TO_FAX'].'}' , $trow['fax'], $cpstring);
112 $cpstring = str_replace('{'.$FIELD_TAG['TO_ORGANIZATION'].'}' , $trow['organization'], $cpstring);
113 $cpstring = str_replace('{'.$FIELD_TAG['PT_FNAME'].'}' , $patdata['fname'], $cpstring);
114 $cpstring = str_replace('{'.$FIELD_TAG['PT_LNAME'].'}' , $patdata['lname'], $cpstring);
115 $cpstring = str_replace('{'.$FIELD_TAG['PT_MNAME'].'}' , $patdata['mname'], $cpstring);
116 $cpstring = str_replace('{'.$FIELD_TAG['PT_STREET'].'}' , $patdata['street'], $cpstring);
117 $cpstring = str_replace('{'.$FIELD_TAG['PT_CITY'].'}' , $patdata['city'], $cpstring);
118 $cpstring = str_replace('{'.$FIELD_TAG['PT_STATE'].'}' , $patdata['state'], $cpstring);
119 $cpstring = str_replace('{'.$FIELD_TAG['PT_POSTAL'].'}' , $patdata['postal_code'], $cpstring);
120 $cpstring = str_replace('{'.$FIELD_TAG['PT_DOB'].'}' , $patdata['DOB'], $cpstring);
122 if ($form_format == "pdf") {
123 // documentation for ezpdf is here --> http://www.ros.co.nz/pdf/
124 require_once ($GLOBALS['fileroot'] . "/library/classes/class.ezpdf.php");
125 $pdf =& new Cezpdf($GLOBALS['oer_config']['prescriptions']['paper_size']);
126 $pdf->ezSetMargins($GLOBALS['oer_config']['prescriptions']['top']
127 ,$GLOBALS['oer_config']['prescriptions']['bottom']
128 ,$GLOBALS['oer_config']['prescriptions']['left']
129 ,$GLOBALS['oer_config']['prescriptions']['right']
131 if (file_exists("$template_dir/custom_pdf.php")) {
132 include("$template_dir/custom_pdf.php");
134 else {
135 $pdf->selectFont($GLOBALS['fileroot'] . "/library/fonts/Helvetica.afm");
136 $pdf->ezText($cpstring, 12);
138 $pdf->ezStream();
139 exit;
141 else { // $form_format = html
142 $cpstring = str_replace("\n", "<br>", $cpstring);
143 $cpstring = str_replace("\t", "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;", $cpstring);
145 <html>
146 <head>
147 <style>
148 body {
149 font-family: sans-serif;
150 font-weight: normal;
151 font-size: 12pt;
152 background: white;
153 color: black;
155 .paddingdiv {
156 width: 524pt;
157 padding: 0pt;
158 margin-top: 50pt;
160 .navigate {
161 margin-top: 2.5em;
163 @media print {
164 .navigate {
165 display: none;
168 </style>
169 <title><?php xl('Letter','e'); ?></title>
170 </head>
171 <body>
172 <div class='paddingdiv'>
173 <?php echo $cpstring; ?>
174 <div class="navigate">
175 <a href="<?php echo $GLOBALS['rootdir'] . '/patient_file/letter.php?template=autosaved'; ?>">(<?php xl('Back','e'); ?>)</a>
176 </div>
177 <script language='JavaScript'>
178 window.print();
179 </script>
180 </body>
181 </div>
182 <?php
183 exit;
186 else if (isset($_GET['template']) && $_GET['template'] != "") {
187 // utilized to go back to autosaved template
188 $bodytext = "";
189 $fh = fopen("$template_dir/".$_GET['template'], 'r');
190 while (!feof($fh)) $bodytext.= fread($fh, 8192);
191 fclose($fh);
192 // translate from constant to the definition
193 foreach ($FIELD_TAG as $key => $value) {
194 $bodytext = str_replace("{".$key."}", "{".$value."}", $bodytext);
197 else if ($_POST['formaction'] == "loadtemplate" && $_POST['form_template'] != "") {
198 $bodytext = "";
199 $fh = fopen("$template_dir/".$_POST['form_template'], 'r');
200 while (!feof($fh)) $bodytext.= fread($fh, 8192);
201 fclose($fh);
202 // translate from constant to the definition
203 foreach ($FIELD_TAG as $key => $value) {
204 $bodytext = str_replace("{".$key."}", "{".$value."}", $bodytext);
207 else if ($_POST['formaction'] == "newtemplate" && $_POST['newtemplatename'] != "") {
208 // attempt to save the template
209 $fh = fopen("$template_dir/".$_POST['newtemplatename'], 'w');
210 // translate from definition to the constant
211 $temp_bodytext = $_POST['form_body'];
212 foreach ($FIELD_TAG as $key => $value) {
213 $temp_bodytext = str_replace("{".$value."}", "{".$key."}", $temp_bodytext);
215 if (! fwrite($fh, $temp_bodytext)) {
216 echo xl('Error while writing to file','','',' ') . $template_dir."/".$_POST['newtemplatename'];
217 die;
219 fclose($fh);
221 // read the saved file back
222 $_POST['form_template'] = $_POST['newtemplatename'];
223 $fh = fopen("$template_dir/".$_POST['form_template'], 'r');
224 while (!feof($fh)) $bodytext.= fread($fh, 8192);
225 fclose($fh);
226 // translate from constant to the definition
227 foreach ($FIELD_TAG as $key => $value) {
228 $bodytext = str_replace("{".$key."}", "{".$value."}" , $bodytext);
231 else if ($_POST['formaction'] == "savetemplate" && $_POST['form_template'] != "") {
232 // attempt to save the template
233 $fh = fopen("$template_dir/".$_POST['form_template'], 'w');
234 // translate from definition to the constant
235 $temp_bodytext = $_POST['form_body'];
236 foreach ($FIELD_TAG as $key => $value) {
237 $temp_bodytext = str_replace("{".$value."}", "{".$key."}", $temp_bodytext);
239 if (! fwrite($fh, $temp_bodytext)) {
240 echo xl('Error while writing to file','','',' ') . $template_dir."/".$_POST['form_template'];
241 die;
243 fclose($fh);
245 // read the saved file back
246 $fh = fopen("$template_dir/".$_POST['form_template'], 'r');
247 while (!feof($fh)) $bodytext.= fread($fh, 8192);
248 fclose($fh);
249 // translate from constant to the definition
250 foreach ($FIELD_TAG as $key => $value) {
251 $bodytext = str_replace("{".$key."}", "{".$value."}", $bodytext);
255 // This is the case where we display the form for data entry.
257 // Get the users list.
258 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
259 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
260 "ORDER BY lname, fname");
261 $i = 0;
262 $optfrom = '';
263 $optto = '';
264 $ulist = "var ulist = new Array();\n";
265 while ($urow = sqlFetchArray($ures)) {
266 $uname = $urow['lname'];
267 if ($urow['fname']) $uname .= ", " . $urow['fname'];
268 $tmp1 = " <option value='" . $urow['id'] . "'";
269 $tmp2 = ">$uname</option>\n";
270 $optto .= $tmp1 . $tmp2;
271 if ($urow['id'] == $_SESSION['authUserID']) $tmp1 .= " selected";
272 $optfrom .= $tmp1 . $tmp2;
273 $ulist .= "ulist[$i] = '" . addslashes($uname) . "|" .
274 $urow['id'] . "|" . addslashes($urow['specialty']) . "';\n";
275 ++$i;
278 // Get the unique specialties.
279 $sres = sqlStatement("SELECT DISTINCT specialty FROM users " .
280 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
281 "ORDER BY specialty");
282 $optspec = "<option value='All'>" . xl('All') . "</option>\n";
283 while ($srow = sqlFetchArray($sres)) {
284 $optspec .= " <option value='" . $srow['specialty'] . "'>" .
285 $srow['specialty'] . "</option>\n";
289 <html>
290 <head>
291 <?php html_header_show();?>
292 <title><?php xl('Letter Generator','e'); ?></title>
294 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
295 <link rel='stylesheet' href='<?php echo $css_header ?>' type='text/css'>
297 <!-- supporting javascript code -->
298 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery.js"></script>
300 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/topdialog.js"></script>
301 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dialog.js"></script>
302 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/textformat.js"></script>
303 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dynarch_calendar.js"></script>
304 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dynarch_calendar_en.js"></script>
305 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dynarch_calendar_setup.js"></script>
307 <script language="JavaScript">
308 <?php echo $ulist; ?>
310 // React to selection of a specialty. This rebuilds the "to" users list
311 // with users having that specialty, or all users if "All" is selected.
312 function newspecialty() {
313 var f = document.forms[0];
314 var s = f.form_specialty.value;
315 var theopts = f.form_to.options;
316 theopts.length = 0;
317 var j = 0;
318 for (var i = 0; i < ulist.length; ++i) {
319 tmp = ulist[i].split("|");
320 if (s != 'All' && s != tmp[2]) continue;
321 theopts[j++] = new Option(tmp[0], tmp[1], false, false);
326 // insert text into a textarea where the cursor is
327 function insertAtCaret(areaId,text) {
328 var txtarea = document.getElementById(areaId);
329 var scrollPos = txtarea.scrollTop;
330 var strPos = 0;
331 var br = ((txtarea.selectionStart || txtarea.selectionStart == '0') ?
332 "ff" : (document.selection ? "ie" : false ) );
333 if (br == "ie") {
334 txtarea.focus();
335 var range = document.selection.createRange();
336 range.moveStart ('character', -txtarea.value.length);
337 strPos = range.text.length;
339 else if (br == "ff") strPos = txtarea.selectionStart;
341 var front = (txtarea.value).substring(0,strPos);
342 var back = (txtarea.value).substring(strPos,txtarea.value.length);
343 txtarea.value=front+text+back;
344 strPos = strPos + text.length;
345 if (br == "ie") {
346 txtarea.focus();
347 var range = document.selection.createRange();
348 range.moveStart ('character', -txtarea.value.length);
349 range.moveStart ('character', strPos);
350 range.moveEnd ('character', 0);
351 range.select();
353 else if (br == "ff") {
354 txtarea.selectionStart = strPos;
355 txtarea.selectionEnd = strPos;
356 txtarea.focus();
358 txtarea.scrollTop = scrollPos;
361 function insertAtCursor(myField, myValue) {
362 //IE support
363 if (document.selection) {
364 myField.focus();
365 sel = document.selection.createRange();
366 sel.text = myValue;
368 //MOZILLA/NETSCAPE support
369 else if (myField.selectionStart || myField.selectionStart == '0') {
370 var startPos = myField.selectionStart;
371 var endPos = myField.selectionEnd;
372 myField.value = myField.value.substring(0, startPos)
373 + myValue
374 + myField.value.substring(endPos, myField.value.length);
375 } else {
376 myField.value += myValue;
381 </script>
383 </head>
385 <body class="body_top" onunload='imclosing()'>
387 <!-- <form method='post' action='letter.php' onsubmit='return top.restoreSession()'> -->
388 <form method='post' action='letter.php' id="theform" name="theform">
389 <input type="hidden" name="formaction" id="formaction" value="">
390 <input type='hidden' name='form_pid' value='<?php echo $pid ?>' />
392 <center>
394 <table border='0' cellspacing='8' width='98%'>
396 <tr>
397 <td colspan='4' align='center'>
398 &nbsp;<br>
399 <b><?php xl('Generate Letter regarding ','e','',' '); echo $patdata['fname'] . " " .
400 $patdata['lname'] . " (" . $patdata['pubpid'] . ")" ?></b>
401 <br>&nbsp;
402 </td>
403 </tr>
405 <tr>
407 <td>
408 <?php xl('From','e'); ?>:
409 </td>
411 <td>
412 <select name='form_from'>
413 <?php echo $optfrom; ?>
414 </select>
415 </td>
417 <td>
418 <?php xl('Date','e'); ?>:
419 </td>
421 <td>
422 <input type='text' size='10' name='form_date' id='form_date'
423 value='<?php echo date('Y-m-d'); ?>'
424 title='<?php xl('yyyy-mm-dd date of this letter','e'); ?>'
425 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' />
426 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
427 id='img_date' border='0' alt='[?]' style='cursor:pointer'
428 title='<?php xl('Click here to choose a date','e'); ?>' />
429 </td>
431 </tr>
433 <tr>
435 <td>
436 <?php xl('Specialty','e'); ?>:
437 </td>
439 <td>
440 <select name='form_specialty' onchange='newspecialty()'>
441 <?php echo $optspec; ?>
442 </select>
443 </td>
445 <td>
446 <?php xl('Template','e'); ?>:
447 </td>
449 <td>
450 <select name="form_template" id="form_template">
451 <option value="">(<?php xl('none','e'); ?>)</option>
452 <?php
453 $tpldir = "$webserver_root/custom/letter_templates";
454 $dh = opendir($tpldir);
455 if (! $dh) die(xl('Cannot read','','',' ') . $tpldir);
456 while (false !== ($tfname = readdir($dh))) {
457 // skip dot-files, scripts and images
458 if (preg_match("/^\./" , $tfname)) { continue; }
459 if (preg_match("/\.php$/", $tfname)) { continue; }
460 if (preg_match("/\.jpg$/", $tfname)) { continue; }
461 if (preg_match("/\.png$/", $tfname)) { continue; }
462 echo "<option value=".$tfname;
463 if (($tfname == $_POST['form_template']) || ($tfname == $_GET['template'])) echo " SELECTED";
464 echo ">";
465 if ($tfname == 'autosaved') {
466 echo xl($tfname);
468 else {
469 echo $tfname;
471 echo "</option>";
473 closedir($dh);
475 </select>
476 </td>
478 </tr>
480 </tr>
482 <tr>
484 <td>
485 <?php xl('To','e'); ?>:
486 </td>
488 <td>
489 <select name='form_to'>
490 <?php echo $optto; ?>
491 </select>
492 </td>
494 <td>
495 <?php xl('Print Format','e'); ?>:
496 </td>
498 <td>
499 <select name='form_format'>
500 <option value='html'><?php xl('HTML','e'); ?></option>
501 <option value='pdf'><?php xl('PDF','e'); ?></option>
502 </select>
503 </td>
505 </tr>
507 <tr>
508 <td colspan='4'>
509 <div id="letter_toolbar" class='text' style="width: 100%; background-color: #ddd; padding: 5px; margin: 0px;">
510 Insert special field:
511 <select id="letter_field">
512 <option value="">- <?php xl('Choose','e'); ?> -</option>
513 <option value="<?php echo '{'.$FIELD_TAG['DATE'].'}'; ?>"><?php xl('Today\'s Date','e'); ?></option>
514 <option value="<?php echo '{'.$FIELD_TAG['FROM_TITLE'].'}'; ?>"><?php xl('FROM','e'); ?> - <?php xl('Title','e'); ?></option>
515 <option value="<?php echo '{'.$FIELD_TAG['FROM_FNAME'].'}'; ?>"><?php xl('FROM','e'); ?> - <?php xl('First name','e'); ?></option>
516 <option value="<?php echo '{'.$FIELD_TAG['FROM_MNAME'].'}'; ?>"><?php xl('FROM','e'); ?> - <?php xl('Middle name','e'); ?></option>
517 <option value="<?php echo '{'.$FIELD_TAG['FROM_LNAME'].'}'; ?>"><?php xl('FROM','e'); ?> - <?php xl('Last name','e'); ?></option>
518 <option value="<?php echo '{'.$FIELD_TAG['FROM_STREET'].'}'; ?>"><?php xl('FROM','e'); ?> - <?php xl('Street','e'); ?></option>
519 <option value="<?php echo '{'.$FIELD_TAG['FROM_CITY'].'}'; ?>"><?php xl('FROM','e'); ?> - <?php xl('City','e'); ?></option>
520 <option value="<?php echo '{'.$FIELD_TAG['FROM_STATE'].'}'; ?>"><?php xl('FROM','e'); ?> - <?php xl('State','e'); ?></option>
521 <option value="<?php echo '{'.$FIELD_TAG['FROM_POSTAL'].'}'; ?>"><?php xl('FROM','e'); ?> - <?php xl('Postal Code','e'); ?></option>
522 <option value="<?php echo '{'.$FIELD_TAG['FROM_VALEDICTORY'].'}'; ?>"><?php xl('FROM','e'); ?> - <?php xl('Valedictory','e'); ?></option>
523 <option value="<?php echo '{'.$FIELD_TAG['FROM_PHONECELL'].'}'; ?>"><?php xl('FROM','e'); ?> - <?php xl('Cell Phone','e'); ?></option>
524 <option value="<?php echo '{'.$FIELD_TAG['TO_TITLE'].'}'; ?>"><?php xl('TO','e'); ?> - <?php xl('Title','e'); ?></option>
525 <option value="<?php echo '{'.$FIELD_TAG['TO_FNAME'].'}'; ?>"><?php xl('TO','e'); ?> - <?php xl('First name','e'); ?></option>
526 <option value="<?php echo '{'.$FIELD_TAG['TO_MNAME'].'}'; ?>"><?php xl('TO','e'); ?> - <?php xl('Middle name','e'); ?></option>
527 <option value="<?php echo '{'.$FIELD_TAG['TO_LNAME'].'}'; ?>"><?php xl('TO','e'); ?> - <?php xl('Last name','e'); ?></option>
528 <option value="<?php echo '{'.$FIELD_TAG['TO_STREET'].'}'; ?>"><?php xl('TO','e'); ?> - <?php xl('Street','e'); ?></option>
529 <option value="<?php echo '{'.$FIELD_TAG['TO_CITY'].'}'; ?>"><?php xl('TO','e'); ?> - <?php xl('City','e'); ?></option>
530 <option value="<?php echo '{'.$FIELD_TAG['TO_STATE'].'}'; ?>"><?php xl('TO','e'); ?> - <?php xl('State','e'); ?></option>
531 <option value="<?php echo '{'.$FIELD_TAG['TO_POSTAL'].'}'; ?>"><?php xl('TO','e'); ?> - <?php xl('Postal Code','e'); ?></option>
532 <option value="<?php echo '{'.$FIELD_TAG['TO_VALEDICTORY'].'}'; ?>"><?php xl('TO','e'); ?> - <?php xl('Valedictory','e'); ?></option>
533 <option value="<?php echo '{'.$FIELD_TAG['TO_ORGANIZATION'].'}'; ?>"><?php xl('TO','e'); ?> - <?php xl('Organization','e'); ?></option>
534 <option value="<?php echo '{'.$FIELD_TAG['TO_FAX'].'}'; ?>"><?php xl('TO','e'); ?> - <?php xl('Fax number','e'); ?></option>
535 <option value="<?php echo '{'.$FIELD_TAG['PT_FNAME'].'}'; ?>"><?php xl('PATIENT','e'); ?> - <?php xl('First name','e'); ?></option>
536 <option value="<?php echo '{'.$FIELD_TAG['PT_MNAME'].'}'; ?>"><?php xl('PATIENT','e'); ?> - <?php xl('Middle name','e'); ?></option>
537 <option value="<?php echo '{'.$FIELD_TAG['PT_LNAME'].'}'; ?>"><?php xl('PATIENT','e'); ?> - <?php xl('Last name','e'); ?></option>
538 <option value="<?php echo '{'.$FIELD_TAG['PT_STREET'].'}'; ?>"><?php xl('PATIENT','e'); ?> - <?php xl('Street','e'); ?></option>
539 <option value="<?php echo '{'.$FIELD_TAG['PT_CITY'].'}'; ?>"><?php xl('PATIENT','e'); ?> - <?php xl('City','e'); ?></option>
540 <option value="<?php echo '{'.$FIELD_TAG['PT_STATE'].'}'; ?>"><?php xl('PATIENT','e'); ?> - <?php xl('State','e'); ?></option>
541 <option value="<?php echo '{'.$FIELD_TAG['PT_POSTAL'].'}'; ?>"><?php xl('PATIENT','e'); ?> - <?php xl('Postal Code','e'); ?></option>
542 <option value="<?php echo '{'.$FIELD_TAG['PT_DOB'].'}'; ?>"><?php xl('PATIENT','e'); ?> - <?php xl('Date of birth','e'); ?></option>
543 </select>
544 </div>
545 <textarea name='form_body' id="form_body" rows='20' cols='30' style='width:100%'
546 title=<?php xl('Enter body of letter here','e','\'','\''); ?> /><?php echo $bodytext; ?></textarea>
547 </td>
548 </tr>
550 </table>
552 <input type='button' class="addtemplate" value=<?php xl('Save as New','e','\'','\''); ?>>
553 <input type='button' name='savetemplate' id="savetemplate" value=<?php xl('Save Changes','e','\'','\''); ?>>
554 <input type='button' name='form_generate' id="form_generate" value=<?php xl('Generate Letter','e','\'','\''); ?>>
556 </center>
558 <!-- template DIV that appears when user chooses to add a new letter template -->
559 <div id="newtemplatedetail" style="border: 1px solid black; padding: 3px; display: none; visibility: hidden; background-color: lightgrey;">
560 <?php xl('Template Name','e'); ?>: <input type="textbox" size="20" maxlength="30" name="newtemplatename" id="newtemplatename">
561 <br>
562 <input type="button" class="savenewtemplate" value=<?php xl('Save new template','e','\'','\''); ?>>
563 <input type="button" class="cancelnewtemplate" value=<?php xl('Cancel','e','\'','\''); ?>>
564 </div>
566 </form>
567 </body>
569 <script language='JavaScript'>
570 Calendar.setup({inputField:"form_date", ifFormat:"%Y-%m-%d", button:"img_date"});
572 // jQuery stuff to make the page a little easier to use
574 $(document).ready(function(){
575 $("#form_generate").click(function() { $("#formaction").val("generate"); $("#theform").submit(); });
576 $("#form_template").change(function() { $("#formaction").val("loadtemplate"); $("#theform").submit(); });
578 $("#savetemplate").click(function() { SaveTemplate(this); });
580 $("#letter_field").change(function() { insertAtCursor(document.getElementById("form_body"), $(this).val()); $(this).attr("selectedIndex", "0"); });
582 $(".addtemplate").click(function() { AddTemplate(this); });
583 $(".savenewtemplate").click(function() { SaveNewTemplate(this); });
584 $(".deletetemplate").click(function() { DeleteTemplate(this); });
585 $(".cancelnewtemplate").click(function() { CancelNewTemplate(this); });
587 // display the 'new group' DIV
588 var AddTemplate = function(btnObj) {
589 // show the field details DIV
590 $('#newtemplatedetail').css('visibility', 'visible');
591 $('#newtemplatedetail').css('display', 'block');
592 $(btnObj).parent().append($("#newtemplatedetail"));
593 $('#newtemplatedetail > #newtemplatename').focus();
596 // save the new template
597 var SaveNewTemplate = function(btnObj) {
598 // the template name can only have letters, numbers, spaces and underscores
599 // AND it cannot start with a number
600 if ($("#newtemplatename").val().match(/^\d+/)) {
601 alert("<?php xl('Template names cannot start with numbers.','e'); ?>");
602 return false;
604 var validname = $("#newtemplatename").val().replace(/[^A-za-z0-9]/g, "_"); // match any non-word characters and replace them
605 $("#newtemplatename").val(validname);
607 // submit the form to add a new field to a specific group
608 $("#formaction").val("newtemplate");
609 $("#theform").submit();
612 // actually delete a template file
614 var DeleteTemplate = function(btnObj) {
615 var parts = $(btnObj).attr("id");
616 var groupname = parts.replace(/^\d+/, "");
617 if (confirm("WARNING - This action cannot be undone.\n Are you sure you wish to delete the entire group named '"+groupname+"'?")) {
618 // submit the form to add a new field to a specific group
619 $("#formaction").val("deletegroup");
620 $("#deletegroupname").val(parts);
621 $("#theform").submit();
626 // just hide the new template DIV
627 var CancelNewTemplate = function(btnObj) {
628 // hide the field details DIV
629 $('#newtemplatedetail').css('visibility', 'hidden');
630 $('#newtemplatedetail').css('display', 'none');
631 // reset the new group values to a default
632 $('#newtemplatedetail > #newtemplatename').val("");
636 // save the template, overwriting the older version
637 var SaveTemplate = function(btnObj) {
638 if (! confirm("<?php xl('You are about to permanently replace the existing template. Are you sure you wish to continue?','e'); ?>")) {
639 return false;
641 $("#formaction").val("savetemplate");
642 $("#theform").submit();
646 </script>
648 </html>