Visolve: Clear Active Patient Changes
[openemr.git] / interface / patient_file / letter.php
blob7072f19cab7382790225375e1ee8655724f2a565
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_PHONECELL' => xl('FROM_PHONECELL'),
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_FAX' => xl('TO_FAX'),
42 'TO_ORGANIZATION' => xl('TO_ORGANIZATION'),
43 'PT_FNAME' => xl('PT_FNAME'),
44 'PT_LNAME' => xl('PT_LNAME'),
45 'PT_MNAME' => xl('PT_MNAME'),
46 'PT_STREET' => xl('PT_STREET'),
47 'PT_CITY' => xl('PT_CITY'),
48 'PT_STATE' => xl('PT_STATE'),
49 'PT_POSTAL' => xl('PT_POSTAL'),
50 'PT_DOB' => xl('PT_DOB')
53 $patdata = sqlQuery("SELECT " .
54 "p.fname, p.mname, p.lname, p.pubpid, p.DOB, " .
55 "p.street, p.city, p.state, p.postal_code " .
56 "FROM patient_data AS p " .
57 "WHERE p.pid = '$pid' LIMIT 1");
59 $alertmsg = ''; // anything here pops up in an alert box
61 // If the Generate button was clicked...
62 if ($_POST['formaction']=="generate") {
64 $form_pid = $_POST['form_pid'];
65 $form_from = $_POST['form_from'];
66 $form_to = $_POST['form_to'];
67 $form_date = $_POST['form_date'];
68 $form_template = $_POST['form_template'];
69 $form_format = $_POST['form_format'];
70 $form_body = $_POST['form_body'];
72 $frow = sqlQuery("SELECT * FROM users WHERE id = '$form_from'");
73 $trow = sqlQuery("SELECT * FROM users WHERE id = '$form_to'");
75 $datestr = date('j F Y', strtotime($form_date));
76 $from_title = $frow['title'] ? $frow['title'] . ' ' : '';
77 $to_title = $trow['title'] ? $trow['title'] . ' ' : '';
79 $cpstring = $_POST['form_body'];
81 // attempt to save to the autosaved template
82 $fh = fopen("$template_dir/autosaved", 'w');
83 // translate from definition to the constant
84 $temp_bodytext = $cpstring;
85 foreach ($FIELD_TAG as $key => $value) {
86 $temp_bodytext = str_replace("{".$value."}", "{".$key."}", $temp_bodytext);
88 if (! fwrite($fh, $temp_bodytext)) {
89 echo xl('Error while saving to the file','','',' ') . $template_dir."/autosaved" .
90 xl('Ensure OpenEMR has write privileges to directory','',' . ',' ') . $template_dir . "/ ." ;
91 die;
93 fclose($fh);
95 $cpstring = str_replace('{'.$FIELD_TAG['DATE'].'}' , $datestr, $cpstring);
96 $cpstring = str_replace('{'.$FIELD_TAG['FROM_TITLE'].'}' , $from_title, $cpstring);
97 $cpstring = str_replace('{'.$FIELD_TAG['FROM_FNAME'].'}' , $frow['fname'], $cpstring);
98 $cpstring = str_replace('{'.$FIELD_TAG['FROM_LNAME'].'}' , $frow['lname'], $cpstring);
99 $cpstring = str_replace('{'.$FIELD_TAG['FROM_MNAME'].'}' , $frow['mname'], $cpstring);
100 $cpstring = str_replace('{'.$FIELD_TAG['FROM_STREET'].'}' , $frow['street'], $cpstring);
101 $cpstring = str_replace('{'.$FIELD_TAG['FROM_CITY'].'}' , $frow['city'], $cpstring);
102 $cpstring = str_replace('{'.$FIELD_TAG['FROM_STATE'].'}' , $frow['state'], $cpstring);
103 $cpstring = str_replace('{'.$FIELD_TAG['FROM_POSTAL'].'}' , $frow['zip'], $cpstring);
104 $cpstring = str_replace('{'.$FIELD_TAG['FROM_VALEDICTORY'].'}', $frow['valedictory'], $cpstring);
105 $cpstring = str_replace('{'.$FIELD_TAG['FROM_PHONECELL'].'}' , $frow['phonecell'], $cpstring);
106 $cpstring = str_replace('{'.$FIELD_TAG['TO_TITLE'].'}' , $to_title, $cpstring);
107 $cpstring = str_replace('{'.$FIELD_TAG['TO_FNAME'].'}' , $trow['fname'], $cpstring);
108 $cpstring = str_replace('{'.$FIELD_TAG['TO_LNAME'].'}' , $trow['lname'], $cpstring);
109 $cpstring = str_replace('{'.$FIELD_TAG['TO_MNAME'].'}' , $trow['mname'], $cpstring);
110 $cpstring = str_replace('{'.$FIELD_TAG['TO_STREET'].'}' , $trow['street'], $cpstring);
111 $cpstring = str_replace('{'.$FIELD_TAG['TO_CITY'].'}' , $trow['city'], $cpstring);
112 $cpstring = str_replace('{'.$FIELD_TAG['TO_STATE'].'}' , $trow['state'], $cpstring);
113 $cpstring = str_replace('{'.$FIELD_TAG['TO_POSTAL'].'}' , $trow['zip'], $cpstring);
114 $cpstring = str_replace('{'.$FIELD_TAG['TO_VALEDICTORY'].'}' , $trow['valedictory'], $cpstring);
115 $cpstring = str_replace('{'.$FIELD_TAG['TO_FAX'].'}' , $trow['fax'], $cpstring);
116 $cpstring = str_replace('{'.$FIELD_TAG['TO_ORGANIZATION'].'}' , $trow['organization'], $cpstring);
117 $cpstring = str_replace('{'.$FIELD_TAG['PT_FNAME'].'}' , $patdata['fname'], $cpstring);
118 $cpstring = str_replace('{'.$FIELD_TAG['PT_LNAME'].'}' , $patdata['lname'], $cpstring);
119 $cpstring = str_replace('{'.$FIELD_TAG['PT_MNAME'].'}' , $patdata['mname'], $cpstring);
120 $cpstring = str_replace('{'.$FIELD_TAG['PT_STREET'].'}' , $patdata['street'], $cpstring);
121 $cpstring = str_replace('{'.$FIELD_TAG['PT_CITY'].'}' , $patdata['city'], $cpstring);
122 $cpstring = str_replace('{'.$FIELD_TAG['PT_STATE'].'}' , $patdata['state'], $cpstring);
123 $cpstring = str_replace('{'.$FIELD_TAG['PT_POSTAL'].'}' , $patdata['postal_code'], $cpstring);
124 $cpstring = str_replace('{'.$FIELD_TAG['PT_DOB'].'}' , $patdata['DOB'], $cpstring);
126 if ($form_format == "pdf") {
127 // documentation for ezpdf is here --> http://www.ros.co.nz/pdf/
128 require_once ($GLOBALS['fileroot'] . "/library/classes/class.ezpdf.php");
129 $pdf =& new Cezpdf($GLOBALS['rx_paper_size']);
130 $pdf->ezSetMargins($GLOBALS['rx_top_margin']
131 ,$GLOBALS['rx_bottom_margin']
132 ,$GLOBALS['rx_left_margin']
133 ,$GLOBALS['rx_right_margin']
135 if (file_exists("$template_dir/custom_pdf.php")) {
136 include("$template_dir/custom_pdf.php");
138 else {
139 $pdf->selectFont($GLOBALS['fileroot'] . "/library/fonts/Helvetica.afm");
140 $pdf->ezText($cpstring, 12);
142 $pdf->ezStream();
143 exit;
145 else { // $form_format = html
146 $cpstring = str_replace("\n", "<br>", $cpstring);
147 $cpstring = str_replace("\t", "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;", $cpstring);
149 <html>
150 <head>
151 <style>
152 body {
153 font-family: sans-serif;
154 font-weight: normal;
155 font-size: 12pt;
156 background: white;
157 color: black;
159 .paddingdiv {
160 width: 524pt;
161 padding: 0pt;
162 margin-top: 50pt;
164 .navigate {
165 margin-top: 2.5em;
167 @media print {
168 .navigate {
169 display: none;
172 </style>
173 <title><?php xl('Letter','e'); ?></title>
174 </head>
175 <body>
176 <div class='paddingdiv'>
177 <?php echo $cpstring; ?>
178 <div class="navigate">
179 <a href="<?php echo $GLOBALS['rootdir'] . '/patient_file/letter.php?template=autosaved'; ?>">(<?php xl('Back','e'); ?>)</a>
180 </div>
181 <script language='JavaScript'>
182 window.print();
183 </script>
184 </body>
185 </div>
186 <?php
187 exit;
190 else if (isset($_GET['template']) && $_GET['template'] != "") {
191 // utilized to go back to autosaved template
192 $bodytext = "";
193 $fh = fopen("$template_dir/".$_GET['template'], 'r');
194 while (!feof($fh)) $bodytext.= fread($fh, 8192);
195 fclose($fh);
196 // translate from constant to the definition
197 foreach ($FIELD_TAG as $key => $value) {
198 $bodytext = str_replace("{".$key."}", "{".$value."}", $bodytext);
201 else if ($_POST['formaction'] == "loadtemplate" && $_POST['form_template'] != "") {
202 $bodytext = "";
203 $fh = fopen("$template_dir/".$_POST['form_template'], 'r');
204 while (!feof($fh)) $bodytext.= fread($fh, 8192);
205 fclose($fh);
206 // translate from constant to the definition
207 foreach ($FIELD_TAG as $key => $value) {
208 $bodytext = str_replace("{".$key."}", "{".$value."}", $bodytext);
211 else if ($_POST['formaction'] == "newtemplate" && $_POST['newtemplatename'] != "") {
212 // attempt to save the template
213 $fh = fopen("$template_dir/".$_POST['newtemplatename'], 'w');
214 // translate from definition to the constant
215 $temp_bodytext = $_POST['form_body'];
216 foreach ($FIELD_TAG as $key => $value) {
217 $temp_bodytext = str_replace("{".$value."}", "{".$key."}", $temp_bodytext);
219 if (! fwrite($fh, $temp_bodytext)) {
220 echo xl('Error while writing to file','','',' ') . $template_dir."/".$_POST['newtemplatename'];
221 die;
223 fclose($fh);
225 // read the saved file back
226 $_POST['form_template'] = $_POST['newtemplatename'];
227 $fh = fopen("$template_dir/".$_POST['form_template'], 'r');
228 while (!feof($fh)) $bodytext.= fread($fh, 8192);
229 fclose($fh);
230 // translate from constant to the definition
231 foreach ($FIELD_TAG as $key => $value) {
232 $bodytext = str_replace("{".$key."}", "{".$value."}" , $bodytext);
235 else if ($_POST['formaction'] == "savetemplate" && $_POST['form_template'] != "") {
236 // attempt to save the template
237 $fh = fopen("$template_dir/".$_POST['form_template'], 'w');
238 // translate from definition to the constant
239 $temp_bodytext = $_POST['form_body'];
240 foreach ($FIELD_TAG as $key => $value) {
241 $temp_bodytext = str_replace("{".$value."}", "{".$key."}", $temp_bodytext);
243 if (! fwrite($fh, $temp_bodytext)) {
244 echo xl('Error while writing to file','','',' ') . $template_dir."/".$_POST['form_template'];
245 die;
247 fclose($fh);
249 // read the saved file back
250 $fh = fopen("$template_dir/".$_POST['form_template'], 'r');
251 while (!feof($fh)) $bodytext.= fread($fh, 8192);
252 fclose($fh);
253 // translate from constant to the definition
254 foreach ($FIELD_TAG as $key => $value) {
255 $bodytext = str_replace("{".$key."}", "{".$value."}", $bodytext);
259 // This is the case where we display the form for data entry.
261 // Get the users list.
262 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
263 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
264 "ORDER BY lname, fname");
265 $i = 0;
266 $optfrom = '';
267 $optto = '';
268 $ulist = "var ulist = new Array();\n";
269 while ($urow = sqlFetchArray($ures)) {
270 $uname = $urow['lname'];
271 if ($urow['fname']) $uname .= ", " . $urow['fname'];
272 $tmp1 = " <option value='" . $urow['id'] . "'";
273 $tmp2 = ">$uname</option>\n";
274 $optto .= $tmp1 . $tmp2;
275 if ($urow['id'] == $_SESSION['authUserID']) $tmp1 .= " selected";
276 $optfrom .= $tmp1 . $tmp2;
277 $ulist .= "ulist[$i] = '" . addslashes($uname) . "|" .
278 $urow['id'] . "|" . addslashes($urow['specialty']) . "';\n";
279 ++$i;
282 // Get the unique specialties.
283 $sres = sqlStatement("SELECT DISTINCT specialty FROM users " .
284 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
285 "ORDER BY specialty");
286 $optspec = "<option value='All'>" . xl('All') . "</option>\n";
287 while ($srow = sqlFetchArray($sres)) {
288 $optspec .= " <option value='" . $srow['specialty'] . "'>" .
289 $srow['specialty'] . "</option>\n";
293 <html>
294 <head>
295 <?php html_header_show();?>
296 <title><?php xl('Letter Generator','e'); ?></title>
298 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
299 <link rel='stylesheet' href='<?php echo $css_header ?>' type='text/css'>
301 <!-- supporting javascript code -->
302 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery.js"></script>
304 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/topdialog.js"></script>
305 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dialog.js"></script>
306 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/textformat.js"></script>
307 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dynarch_calendar.js"></script>
308 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
309 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dynarch_calendar_setup.js"></script>
311 <script language="JavaScript">
312 <?php echo $ulist; ?>
314 // React to selection of a specialty. This rebuilds the "to" users list
315 // with users having that specialty, or all users if "All" is selected.
316 function newspecialty() {
317 var f = document.forms[0];
318 var s = f.form_specialty.value;
319 var theopts = f.form_to.options;
320 theopts.length = 0;
321 var j = 0;
322 for (var i = 0; i < ulist.length; ++i) {
323 tmp = ulist[i].split("|");
324 if (s != 'All' && s != tmp[2]) continue;
325 theopts[j++] = new Option(tmp[0], tmp[1], false, false);
330 // insert text into a textarea where the cursor is
331 function insertAtCaret(areaId,text) {
332 var txtarea = document.getElementById(areaId);
333 var scrollPos = txtarea.scrollTop;
334 var strPos = 0;
335 var br = ((txtarea.selectionStart || txtarea.selectionStart == '0') ?
336 "ff" : (document.selection ? "ie" : false ) );
337 if (br == "ie") {
338 txtarea.focus();
339 var range = document.selection.createRange();
340 range.moveStart ('character', -txtarea.value.length);
341 strPos = range.text.length;
343 else if (br == "ff") strPos = txtarea.selectionStart;
345 var front = (txtarea.value).substring(0,strPos);
346 var back = (txtarea.value).substring(strPos,txtarea.value.length);
347 txtarea.value=front+text+back;
348 strPos = strPos + text.length;
349 if (br == "ie") {
350 txtarea.focus();
351 var range = document.selection.createRange();
352 range.moveStart ('character', -txtarea.value.length);
353 range.moveStart ('character', strPos);
354 range.moveEnd ('character', 0);
355 range.select();
357 else if (br == "ff") {
358 txtarea.selectionStart = strPos;
359 txtarea.selectionEnd = strPos;
360 txtarea.focus();
362 txtarea.scrollTop = scrollPos;
365 function insertAtCursor(myField, myValue) {
366 //IE support
367 if (document.selection) {
368 myField.focus();
369 sel = document.selection.createRange();
370 sel.text = myValue;
372 //MOZILLA/NETSCAPE support
373 else if (myField.selectionStart || myField.selectionStart == '0') {
374 var startPos = myField.selectionStart;
375 var endPos = myField.selectionEnd;
376 myField.value = myField.value.substring(0, startPos)
377 + myValue
378 + myField.value.substring(endPos, myField.value.length);
379 } else {
380 myField.value += myValue;
385 </script>
387 </head>
389 <body class="body_top" onunload='imclosing()'>
391 <!-- <form method='post' action='letter.php' onsubmit='return top.restoreSession()'> -->
392 <form method='post' action='letter.php' id="theform" name="theform">
393 <input type="hidden" name="formaction" id="formaction" value="">
394 <input type='hidden' name='form_pid' value='<?php echo $pid ?>' />
396 <center>
398 <table border='0' cellspacing='8' width='98%'>
400 <tr>
401 <td colspan='4' align='center'>
402 &nbsp;<br>
403 <b><?php xl('Generate Letter regarding ','e','',' '); echo $patdata['fname'] . " " .
404 $patdata['lname'] . " (" . $patdata['pubpid'] . ")" ?></b>
405 <br>&nbsp;
406 </td>
407 </tr>
409 <tr>
411 <td>
412 <?php xl('From','e'); ?>:
413 </td>
415 <td>
416 <select name='form_from'>
417 <?php echo $optfrom; ?>
418 </select>
419 </td>
421 <td>
422 <?php xl('Date','e'); ?>:
423 </td>
425 <td>
426 <input type='text' size='10' name='form_date' id='form_date'
427 value='<?php echo date('Y-m-d'); ?>'
428 title='<?php xl('yyyy-mm-dd date of this letter','e'); ?>'
429 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' />
430 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
431 id='img_date' border='0' alt='[?]' style='cursor:pointer'
432 title='<?php xl('Click here to choose a date','e'); ?>' />
433 </td>
435 </tr>
437 <tr>
439 <td>
440 <?php xl('Specialty','e'); ?>:
441 </td>
443 <td>
444 <select name='form_specialty' onchange='newspecialty()'>
445 <?php echo $optspec; ?>
446 </select>
447 </td>
449 <td>
450 <?php xl('Template','e'); ?>:
451 </td>
453 <td>
454 <select name="form_template" id="form_template">
455 <option value="">(<?php xl('none','e'); ?>)</option>
456 <?php
457 $tpldir = $GLOBALS['OE_SITE_DIR'] . "/letter_templates";
458 $dh = opendir($tpldir);
459 if (! $dh) die(xl('Cannot read','','',' ') . $tpldir);
460 while (false !== ($tfname = readdir($dh))) {
461 // skip dot-files, scripts and images
462 if (preg_match("/^\./" , $tfname)) { continue; }
463 if (preg_match("/\.php$/", $tfname)) { continue; }
464 if (preg_match("/\.jpg$/", $tfname)) { continue; }
465 if (preg_match("/\.png$/", $tfname)) { continue; }
466 echo "<option value=".$tfname;
467 if (($tfname == $_POST['form_template']) || ($tfname == $_GET['template'])) echo " SELECTED";
468 echo ">";
469 if ($tfname == 'autosaved') {
470 echo xl($tfname);
472 else {
473 echo $tfname;
475 echo "</option>";
477 closedir($dh);
479 </select>
480 </td>
482 </tr>
484 </tr>
486 <tr>
488 <td>
489 <?php xl('To','e'); ?>:
490 </td>
492 <td>
493 <select name='form_to'>
494 <?php echo $optto; ?>
495 </select>
496 </td>
498 <td>
499 <?php xl('Print Format','e'); ?>:
500 </td>
502 <td>
503 <select name='form_format'>
504 <option value='html'><?php xl('HTML','e'); ?></option>
505 <option value='pdf'><?php xl('PDF','e'); ?></option>
506 </select>
507 </td>
509 </tr>
511 <tr>
512 <td colspan='4'>
513 <div id="letter_toolbar" class='text' style="width: 100%; background-color: #ddd; padding: 5px; margin: 0px;">
514 Insert special field:
515 <select id="letter_field">
516 <option value="">- <?php xl('Choose','e'); ?> -</option>
517 <option value="<?php echo '{'.$FIELD_TAG['DATE'].'}'; ?>"><?php xl('Today\'s Date','e'); ?></option>
518 <option value="<?php echo '{'.$FIELD_TAG['FROM_TITLE'].'}'; ?>"><?php xl('FROM','e'); ?> - <?php xl('Title','e'); ?></option>
519 <option value="<?php echo '{'.$FIELD_TAG['FROM_FNAME'].'}'; ?>"><?php xl('FROM','e'); ?> - <?php xl('First name','e'); ?></option>
520 <option value="<?php echo '{'.$FIELD_TAG['FROM_MNAME'].'}'; ?>"><?php xl('FROM','e'); ?> - <?php xl('Middle name','e'); ?></option>
521 <option value="<?php echo '{'.$FIELD_TAG['FROM_LNAME'].'}'; ?>"><?php xl('FROM','e'); ?> - <?php xl('Last name','e'); ?></option>
522 <option value="<?php echo '{'.$FIELD_TAG['FROM_STREET'].'}'; ?>"><?php xl('FROM','e'); ?> - <?php xl('Street','e'); ?></option>
523 <option value="<?php echo '{'.$FIELD_TAG['FROM_CITY'].'}'; ?>"><?php xl('FROM','e'); ?> - <?php xl('City','e'); ?></option>
524 <option value="<?php echo '{'.$FIELD_TAG['FROM_STATE'].'}'; ?>"><?php xl('FROM','e'); ?> - <?php xl('State','e'); ?></option>
525 <option value="<?php echo '{'.$FIELD_TAG['FROM_POSTAL'].'}'; ?>"><?php xl('FROM','e'); ?> - <?php xl('Postal Code','e'); ?></option>
526 <option value="<?php echo '{'.$FIELD_TAG['FROM_VALEDICTORY'].'}'; ?>"><?php xl('FROM','e'); ?> - <?php xl('Valedictory','e'); ?></option>
527 <option value="<?php echo '{'.$FIELD_TAG['FROM_PHONECELL'].'}'; ?>"><?php xl('FROM','e'); ?> - <?php xl('Cell Phone','e'); ?></option>
528 <option value="<?php echo '{'.$FIELD_TAG['TO_TITLE'].'}'; ?>"><?php xl('TO','e'); ?> - <?php xl('Title','e'); ?></option>
529 <option value="<?php echo '{'.$FIELD_TAG['TO_FNAME'].'}'; ?>"><?php xl('TO','e'); ?> - <?php xl('First name','e'); ?></option>
530 <option value="<?php echo '{'.$FIELD_TAG['TO_MNAME'].'}'; ?>"><?php xl('TO','e'); ?> - <?php xl('Middle name','e'); ?></option>
531 <option value="<?php echo '{'.$FIELD_TAG['TO_LNAME'].'}'; ?>"><?php xl('TO','e'); ?> - <?php xl('Last name','e'); ?></option>
532 <option value="<?php echo '{'.$FIELD_TAG['TO_STREET'].'}'; ?>"><?php xl('TO','e'); ?> - <?php xl('Street','e'); ?></option>
533 <option value="<?php echo '{'.$FIELD_TAG['TO_CITY'].'}'; ?>"><?php xl('TO','e'); ?> - <?php xl('City','e'); ?></option>
534 <option value="<?php echo '{'.$FIELD_TAG['TO_STATE'].'}'; ?>"><?php xl('TO','e'); ?> - <?php xl('State','e'); ?></option>
535 <option value="<?php echo '{'.$FIELD_TAG['TO_POSTAL'].'}'; ?>"><?php xl('TO','e'); ?> - <?php xl('Postal Code','e'); ?></option>
536 <option value="<?php echo '{'.$FIELD_TAG['TO_VALEDICTORY'].'}'; ?>"><?php xl('TO','e'); ?> - <?php xl('Valedictory','e'); ?></option>
537 <option value="<?php echo '{'.$FIELD_TAG['TO_ORGANIZATION'].'}'; ?>"><?php xl('TO','e'); ?> - <?php xl('Organization','e'); ?></option>
538 <option value="<?php echo '{'.$FIELD_TAG['TO_FAX'].'}'; ?>"><?php xl('TO','e'); ?> - <?php xl('Fax number','e'); ?></option>
539 <option value="<?php echo '{'.$FIELD_TAG['PT_FNAME'].'}'; ?>"><?php xl('PATIENT','e'); ?> - <?php xl('First name','e'); ?></option>
540 <option value="<?php echo '{'.$FIELD_TAG['PT_MNAME'].'}'; ?>"><?php xl('PATIENT','e'); ?> - <?php xl('Middle name','e'); ?></option>
541 <option value="<?php echo '{'.$FIELD_TAG['PT_LNAME'].'}'; ?>"><?php xl('PATIENT','e'); ?> - <?php xl('Last name','e'); ?></option>
542 <option value="<?php echo '{'.$FIELD_TAG['PT_STREET'].'}'; ?>"><?php xl('PATIENT','e'); ?> - <?php xl('Street','e'); ?></option>
543 <option value="<?php echo '{'.$FIELD_TAG['PT_CITY'].'}'; ?>"><?php xl('PATIENT','e'); ?> - <?php xl('City','e'); ?></option>
544 <option value="<?php echo '{'.$FIELD_TAG['PT_STATE'].'}'; ?>"><?php xl('PATIENT','e'); ?> - <?php xl('State','e'); ?></option>
545 <option value="<?php echo '{'.$FIELD_TAG['PT_POSTAL'].'}'; ?>"><?php xl('PATIENT','e'); ?> - <?php xl('Postal Code','e'); ?></option>
546 <option value="<?php echo '{'.$FIELD_TAG['PT_DOB'].'}'; ?>"><?php xl('PATIENT','e'); ?> - <?php xl('Date of birth','e'); ?></option>
547 </select>
548 </div>
549 <textarea name='form_body' id="form_body" rows='20' cols='30' style='width:100%'
550 title=<?php xl('Enter body of letter here','e','\'','\''); ?> /><?php echo $bodytext; ?></textarea>
551 </td>
552 </tr>
554 </table>
556 <input type='button' class="addtemplate" value=<?php xl('Save as New','e','\'','\''); ?>>
557 <input type='button' name='savetemplate' id="savetemplate" value=<?php xl('Save Changes','e','\'','\''); ?>>
558 <input type='button' name='form_generate' id="form_generate" value=<?php xl('Generate Letter','e','\'','\''); ?>>
560 </center>
562 <!-- template DIV that appears when user chooses to add a new letter template -->
563 <div id="newtemplatedetail" style="border: 1px solid black; padding: 3px; display: none; visibility: hidden; background-color: lightgrey;">
564 <?php xl('Template Name','e'); ?>: <input type="textbox" size="20" maxlength="30" name="newtemplatename" id="newtemplatename">
565 <br>
566 <input type="button" class="savenewtemplate" value=<?php xl('Save new template','e','\'','\''); ?>>
567 <input type="button" class="cancelnewtemplate" value=<?php xl('Cancel','e','\'','\''); ?>>
568 </div>
570 </form>
571 </body>
573 <script language='JavaScript'>
574 Calendar.setup({inputField:"form_date", ifFormat:"%Y-%m-%d", button:"img_date"});
576 // jQuery stuff to make the page a little easier to use
578 $(document).ready(function(){
579 $("#form_generate").click(function() { $("#formaction").val("generate"); $("#theform").submit(); });
580 $("#form_template").change(function() { $("#formaction").val("loadtemplate"); $("#theform").submit(); });
582 $("#savetemplate").click(function() { SaveTemplate(this); });
584 $("#letter_field").change(function() { insertAtCursor(document.getElementById("form_body"), $(this).val()); $(this).attr("selectedIndex", "0"); });
586 $(".addtemplate").click(function() { AddTemplate(this); });
587 $(".savenewtemplate").click(function() { SaveNewTemplate(this); });
588 $(".deletetemplate").click(function() { DeleteTemplate(this); });
589 $(".cancelnewtemplate").click(function() { CancelNewTemplate(this); });
591 // display the 'new group' DIV
592 var AddTemplate = function(btnObj) {
593 // show the field details DIV
594 $('#newtemplatedetail').css('visibility', 'visible');
595 $('#newtemplatedetail').css('display', 'block');
596 $(btnObj).parent().append($("#newtemplatedetail"));
597 $('#newtemplatedetail > #newtemplatename').focus();
600 // save the new template
601 var SaveNewTemplate = function(btnObj) {
602 // the template name can only have letters, numbers, spaces and underscores
603 // AND it cannot start with a number
604 if ($("#newtemplatename").val().match(/^\d+/)) {
605 alert("<?php xl('Template names cannot start with numbers.','e'); ?>");
606 return false;
608 var validname = $("#newtemplatename").val().replace(/[^A-za-z0-9]/g, "_"); // match any non-word characters and replace them
609 $("#newtemplatename").val(validname);
611 // submit the form to add a new field to a specific group
612 $("#formaction").val("newtemplate");
613 $("#theform").submit();
616 // actually delete a template file
618 var DeleteTemplate = function(btnObj) {
619 var parts = $(btnObj).attr("id");
620 var groupname = parts.replace(/^\d+/, "");
621 if (confirm("WARNING - This action cannot be undone.\n Are you sure you wish to delete the entire group named '"+groupname+"'?")) {
622 // submit the form to add a new field to a specific group
623 $("#formaction").val("deletegroup");
624 $("#deletegroupname").val(parts);
625 $("#theform").submit();
630 // just hide the new template DIV
631 var CancelNewTemplate = function(btnObj) {
632 // hide the field details DIV
633 $('#newtemplatedetail').css('visibility', 'hidden');
634 $('#newtemplatedetail').css('display', 'none');
635 // reset the new group values to a default
636 $('#newtemplatedetail > #newtemplatename').val("");
640 // save the template, overwriting the older version
641 var SaveTemplate = function(btnObj) {
642 if (! confirm("<?php xl('You are about to permanently replace the existing template. Are you sure you wish to continue?','e'); ?>")) {
643 return false;
645 $("#formaction").val("savetemplate");
646 $("#theform").submit();
650 </script>
652 </html>