fixed width for css output
[openemr.git] / interface / patient_file / letter.php
blob0272f658d8d8189dff5ffc153216b88ccf4dd89d
1 <?php
2 // Copyright (C) 2007 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_DOB' => xl('PT_DOB')
45 $patdata = sqlQuery("SELECT " .
46 "p.fname, p.mname, p.lname, p.pubpid, p.DOB " .
47 "FROM patient_data AS p " .
48 "WHERE p.pid = '$pid' LIMIT 1");
50 $alertmsg = ''; // anything here pops up in an alert box
52 // If the Generate button was clicked...
53 if ($_POST['formaction']=="generate") {
55 $form_pid = $_POST['form_pid'];
56 $form_from = $_POST['form_from'];
57 $form_to = $_POST['form_to'];
58 $form_date = $_POST['form_date'];
59 $form_template = $_POST['form_template'];
60 $form_format = $_POST['form_format'];
61 $form_body = $_POST['form_body'];
63 $frow = sqlQuery("SELECT * FROM users WHERE id = '$form_from'");
64 $trow = sqlQuery("SELECT * FROM users WHERE id = '$form_to'");
66 $datestr = date('j F Y', strtotime($form_date));
67 $from_title = $frow['title'] ? $frow['title'] . ' ' : '';
68 $to_title = $trow['title'] ? $trow['title'] . ' ' : '';
70 $cpstring = $_POST['form_body'];
72 // attempt to save to the autosaved template
73 $fh = fopen("$template_dir/autosaved", 'w');
74 // translate from definition to the constant
75 $temp_bodytext = $cpstring;
76 foreach ($FIELD_TAG as $key => $value) {
77 $temp_bodytext = str_replace("{".$value."}", "{".$key."}", $temp_bodytext);
79 if (! fwrite($fh, $temp_bodytext)) {
80 echo xl('Error while saving to the file','','',' ') . $template_dir."/autosaved" .
81 xl('Ensure OpenEMR has write privileges to directory','',' . ',' ') . $template_dir . "/ ." ;
82 die;
84 fclose($fh);
86 $cpstring = str_replace('{'.$FIELD_TAG['DATE'].'}' , $datestr, $cpstring);
87 $cpstring = str_replace('{'.$FIELD_TAG['FROM_TITLE'].'}' , $from_title, $cpstring);
88 $cpstring = str_replace('{'.$FIELD_TAG['FROM_FNAME'].'}' , $frow['fname'], $cpstring);
89 $cpstring = str_replace('{'.$FIELD_TAG['FROM_LNAME'].'}' , $frow['lname'], $cpstring);
90 $cpstring = str_replace('{'.$FIELD_TAG['FROM_MNAME'].'}' , $frow['mname'], $cpstring);
91 $cpstring = str_replace('{'.$FIELD_TAG['FROM_STREET'].'}' , $frow['street'], $cpstring);
92 $cpstring = str_replace('{'.$FIELD_TAG['FROM_CITY'].'}' , $frow['city'], $cpstring);
93 $cpstring = str_replace('{'.$FIELD_TAG['FROM_STATE'].'}' , $frow['state'], $cpstring);
94 $cpstring = str_replace('{'.$FIELD_TAG['FROM_POSTAL'].'}' , $frow['zip'], $cpstring);
95 $cpstring = str_replace('{'.$FIELD_TAG['FROM_VALEDICTORY'].'}', $frow['valedictory'], $cpstring);
96 $cpstring = str_replace('{'.$FIELD_TAG['FROM_PHONECELL'].'}' , $frow['phonecell'], $cpstring);
97 $cpstring = str_replace('{'.$FIELD_TAG['TO_TITLE'].'}' , $to_title, $cpstring);
98 $cpstring = str_replace('{'.$FIELD_TAG['TO_FNAME'].'}' , $trow['fname'], $cpstring);
99 $cpstring = str_replace('{'.$FIELD_TAG['TO_LNAME'].'}' , $trow['lname'], $cpstring);
100 $cpstring = str_replace('{'.$FIELD_TAG['TO_MNAME'].'}' , $trow['mname'], $cpstring);
101 $cpstring = str_replace('{'.$FIELD_TAG['TO_STREET'].'}' , $trow['street'], $cpstring);
102 $cpstring = str_replace('{'.$FIELD_TAG['TO_CITY'].'}' , $trow['city'], $cpstring);
103 $cpstring = str_replace('{'.$FIELD_TAG['TO_STATE'].'}' , $trow['state'], $cpstring);
104 $cpstring = str_replace('{'.$FIELD_TAG['TO_POSTAL'].'}' , $trow['zip'], $cpstring);
105 $cpstring = str_replace('{'.$FIELD_TAG['TO_VALEDICTORY'].'}' , $trow['valedictory'], $cpstring);
106 $cpstring = str_replace('{'.$FIELD_TAG['TO_FAX'].'}' , $trow['fax'], $cpstring);
107 $cpstring = str_replace('{'.$FIELD_TAG['TO_ORGANIZATION'].'}' , $trow['organization'], $cpstring);
108 $cpstring = str_replace('{'.$FIELD_TAG['PT_FNAME'].'}' , $patdata['fname'], $cpstring);
109 $cpstring = str_replace('{'.$FIELD_TAG['PT_LNAME'].'}' , $patdata['lname'], $cpstring);
110 $cpstring = str_replace('{'.$FIELD_TAG['PT_MNAME'].'}' , $patdata['mname'], $cpstring);
111 $cpstring = str_replace('{'.$FIELD_TAG['PT_DOB'].'}' , $patdata['DOB'], $cpstring);
113 if ($form_format == "pdf") {
114 // documentation for ezpdf is here --> http://www.ros.co.nz/pdf/
115 require_once ($GLOBALS['fileroot'] . "/library/classes/class.ezpdf.php");
116 $pdf =& new Cezpdf($GLOBALS['oer_config']['prescriptions']['paper_size']);
117 $pdf->ezSetMargins($GLOBALS['oer_config']['prescriptions']['top']
118 ,$GLOBALS['oer_config']['prescriptions']['bottom']
119 ,$GLOBALS['oer_config']['prescriptions']['left']
120 ,$GLOBALS['oer_config']['prescriptions']['right']
122 $pdf->selectFont($GLOBALS['fileroot'] . "/library/fonts/Helvetica.afm");
123 //if(!empty($this->pconfig['logo'])) {
124 // $pdf->ezImage($this->pconfig['logo'],"","","none","left");
126 $pdf->ezText($cpstring, 12);
127 $pdf->ezStream();
128 exit;
130 else { // $form_format = html
131 $cpstring = str_replace("\n", "<br>", $cpstring);
132 $cpstring = str_replace("\t", "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;", $cpstring);
134 <html>
135 <head>
136 <style>
137 body {
138 font-family: sans-serif;
139 font-weight: normal;
140 font-size: 12pt;
141 background: white;
142 color: black;
144 .paddingdiv {
145 width: 524pt;
146 padding: 0pt;
147 margin-top: 50pt;
149 .navigate {
150 margin-top: 2.5em;
152 @media print {
153 .navigate {
154 display: none;
157 </style>
158 <title><?php xl('Letter','e'); ?></title>
159 </head>
160 <body>
161 <div class='paddingdiv'>
162 <?php echo $cpstring; ?>
163 <div class="navigate">
164 <a href="<?php echo $GLOBALS['rootdir'] . '/patient_file/letter.php?template=autosaved'; ?>">(<?php xl('Back','e'); ?>)</a>
165 </div>
166 <script language='JavaScript'>
167 window.print();
168 </script>
169 </body>
170 </div>
171 <?php
172 exit;
175 else if (isset($_GET['template']) && $_GET['template'] != "") {
176 // utilized to go back to autosaved template
177 $bodytext = "";
178 $fh = fopen("$template_dir/".$_GET['template'], 'r');
179 while (!feof($fh)) $bodytext.= fread($fh, 8192);
180 fclose($fh);
181 // translate from constant to the definition
182 foreach ($FIELD_TAG as $key => $value) {
183 $bodytext = str_replace("{".$key."}", "{".$value."}", $bodytext);
186 else if ($_POST['formaction'] == "loadtemplate" && $_POST['form_template'] != "") {
187 $bodytext = "";
188 $fh = fopen("$template_dir/".$_POST['form_template'], 'r');
189 while (!feof($fh)) $bodytext.= fread($fh, 8192);
190 fclose($fh);
191 // translate from constant to the definition
192 foreach ($FIELD_TAG as $key => $value) {
193 $bodytext = str_replace("{".$key."}", "{".$value."}", $bodytext);
196 else if ($_POST['formaction'] == "newtemplate" && $_POST['newtemplatename'] != "") {
197 // attempt to save the template
198 $fh = fopen("$template_dir/".$_POST['newtemplatename'], 'w');
199 // translate from definition to the constant
200 $temp_bodytext = $_POST['form_body'];
201 foreach ($FIELD_TAG as $key => $value) {
202 $temp_bodytext = str_replace("{".$value."}", "{".$key."}", $temp_bodytext);
204 if (! fwrite($fh, $temp_bodytext)) {
205 echo xl('Error while writing to file','','',' ') . $template_dir."/".$_POST['newtemplatename'];
206 die;
208 fclose($fh);
210 // read the saved file back
211 $_POST['form_template'] = $_POST['newtemplatename'];
212 $fh = fopen("$template_dir/".$_POST['form_template'], 'r');
213 while (!feof($fh)) $bodytext.= fread($fh, 8192);
214 fclose($fh);
215 // translate from constant to the definition
216 foreach ($FIELD_TAG as $key => $value) {
217 $bodytext = str_replace("{".$key."}", "{".$value."}" , $bodytext);
220 else if ($_POST['formaction'] == "savetemplate" && $_POST['form_template'] != "") {
221 // attempt to save the template
222 $fh = fopen("$template_dir/".$_POST['form_template'], 'w');
223 // translate from definition to the constant
224 $temp_bodytext = $_POST['form_body'];
225 foreach ($FIELD_TAG as $key => $value) {
226 $temp_bodytext = str_replace("{".$value."}", "{".$key."}", $temp_bodytext);
228 if (! fwrite($fh, $temp_bodytext)) {
229 echo xl('Error while writing to file','','',' ') . $template_dir."/".$_POST['form_template'];
230 die;
232 fclose($fh);
234 // read the saved file back
235 $fh = fopen("$template_dir/".$_POST['form_template'], 'r');
236 while (!feof($fh)) $bodytext.= fread($fh, 8192);
237 fclose($fh);
238 // translate from constant to the definition
239 foreach ($FIELD_TAG as $key => $value) {
240 $bodytext = str_replace("{".$key."}", "{".$value."}", $bodytext);
244 // This is the case where we display the form for data entry.
246 // Get the users list.
247 $ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
248 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
249 "ORDER BY lname, fname");
250 $i = 0;
251 $optfrom = '';
252 $optto = '';
253 $ulist = "var ulist = new Array();\n";
254 while ($urow = sqlFetchArray($ures)) {
255 $uname = $urow['lname'];
256 if ($urow['fname']) $uname .= ", " . $urow['fname'];
257 $tmp1 = " <option value='" . $urow['id'] . "'";
258 $tmp2 = ">$uname</option>\n";
259 $optto .= $tmp1 . $tmp2;
260 if ($urow['id'] == $_SESSION['authUserID']) $tmp1 .= " selected";
261 $optfrom .= $tmp1 . $tmp2;
262 $ulist .= "ulist[$i] = '" . addslashes($uname) . "|" .
263 $urow['id'] . "|" . addslashes($urow['specialty']) . "';\n";
264 ++$i;
267 // Get the unique specialties.
268 $sres = sqlStatement("SELECT DISTINCT specialty FROM users " .
269 "WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
270 "ORDER BY specialty");
271 $optspec = "<option value='All'>" . xl('All') . "</option>\n";
272 while ($srow = sqlFetchArray($sres)) {
273 $optspec .= " <option value='" . $srow['specialty'] . "'>" .
274 $srow['specialty'] . "</option>\n";
278 <html>
279 <head>
280 <?php html_header_show();?>
281 <title><?php xl('Letter Generator','e'); ?></title>
283 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
284 <link rel='stylesheet' href='<?php echo $css_header ?>' type='text/css'>
286 <!-- supporting javascript code -->
287 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery.js"></script>
289 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/topdialog.js"></script>
290 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dialog.js"></script>
291 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/textformat.js"></script>
292 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dynarch_calendar.js"></script>
293 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dynarch_calendar_en.js"></script>
294 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dynarch_calendar_setup.js"></script>
296 <script language="JavaScript">
297 <?php echo $ulist; ?>
299 // React to selection of a specialty. This rebuilds the "to" users list
300 // with users having that specialty, or all users if "All" is selected.
301 function newspecialty() {
302 var f = document.forms[0];
303 var s = f.form_specialty.value;
304 var theopts = f.form_to.options;
305 theopts.length = 0;
306 var j = 0;
307 for (var i = 0; i < ulist.length; ++i) {
308 tmp = ulist[i].split("|");
309 if (s != 'All' && s != tmp[2]) continue;
310 theopts[j++] = new Option(tmp[0], tmp[1], false, false);
315 // insert text into a textarea where the cursor is
316 function insertAtCaret(areaId,text) {
317 var txtarea = document.getElementById(areaId);
318 var scrollPos = txtarea.scrollTop;
319 var strPos = 0;
320 var br = ((txtarea.selectionStart || txtarea.selectionStart == '0') ?
321 "ff" : (document.selection ? "ie" : false ) );
322 if (br == "ie") {
323 txtarea.focus();
324 var range = document.selection.createRange();
325 range.moveStart ('character', -txtarea.value.length);
326 strPos = range.text.length;
328 else if (br == "ff") strPos = txtarea.selectionStart;
330 var front = (txtarea.value).substring(0,strPos);
331 var back = (txtarea.value).substring(strPos,txtarea.value.length);
332 txtarea.value=front+text+back;
333 strPos = strPos + text.length;
334 if (br == "ie") {
335 txtarea.focus();
336 var range = document.selection.createRange();
337 range.moveStart ('character', -txtarea.value.length);
338 range.moveStart ('character', strPos);
339 range.moveEnd ('character', 0);
340 range.select();
342 else if (br == "ff") {
343 txtarea.selectionStart = strPos;
344 txtarea.selectionEnd = strPos;
345 txtarea.focus();
347 txtarea.scrollTop = scrollPos;
350 function insertAtCursor(myField, myValue) {
351 //IE support
352 if (document.selection) {
353 myField.focus();
354 sel = document.selection.createRange();
355 sel.text = myValue;
357 //MOZILLA/NETSCAPE support
358 else if (myField.selectionStart || myField.selectionStart == '0') {
359 var startPos = myField.selectionStart;
360 var endPos = myField.selectionEnd;
361 myField.value = myField.value.substring(0, startPos)
362 + myValue
363 + myField.value.substring(endPos, myField.value.length);
364 } else {
365 myField.value += myValue;
370 </script>
372 </head>
374 <body class="body_top" onunload='imclosing()'>
376 <!-- <form method='post' action='letter.php' onsubmit='return top.restoreSession()'> -->
377 <form method='post' action='letter.php' id="theform" name="theform">
378 <input type="hidden" name="formaction" id="formaction" value="">
379 <input type='hidden' name='form_pid' value='<?php echo $pid ?>' />
381 <center>
383 <table border='0' cellspacing='8' width='98%'>
385 <tr>
386 <td colspan='4' align='center'>
387 &nbsp;<br>
388 <b><?php xl('Generate Letter regarding ','e','',' '); echo $patdata['fname'] . " " .
389 $patdata['lname'] . " (" . $patdata['pubpid'] . ")" ?></b>
390 <br>&nbsp;
391 </td>
392 </tr>
394 <tr>
396 <td>
397 <?php xl('From','e'); ?>:
398 </td>
400 <td>
401 <select name='form_from'>
402 <?php echo $optfrom; ?>
403 </select>
404 </td>
406 <td>
407 <?php xl('Date','e'); ?>:
408 </td>
410 <td>
411 <input type='text' size='10' name='form_date' id='form_date'
412 value='<?php echo date('Y-m-d'); ?>'
413 title='<?php xl('yyyy-mm-dd date of this letter','e'); ?>'
414 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' />
415 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
416 id='img_date' border='0' alt='[?]' style='cursor:pointer'
417 title='<?php xl('Click here to choose a date','e'); ?>' />
418 </td>
420 </tr>
422 <tr>
424 <td>
425 <?php xl('Specialty','e'); ?>:
426 </td>
428 <td>
429 <select name='form_specialty' onchange='newspecialty()'>
430 <?php echo $optspec; ?>
431 </select>
432 </td>
434 <td>
435 <?php xl('Template','e'); ?>:
436 </td>
438 <td>
439 <select name="form_template" id="form_template">
440 <option value="">(<?php xl('none','e'); ?>)</option>
441 <?php
442 $tpldir = "$webserver_root/custom/letter_templates";
443 $dh = opendir($tpldir);
444 if (! $dh) die(xl('Cannot read','','',' ') . $tpldir);
445 while (false !== ($tfname = readdir($dh))) {
446 // skip dot-files
447 if (preg_match("/^\./", $tfname)) { continue; }
448 echo "<option value=".$tfname;
449 if (($tfname == $_POST['form_template']) || ($tfname == $_GET['template'])) echo " SELECTED";
450 echo ">";
451 if ($tfname == 'autosaved') {
452 echo xl($tfname);
454 else {
455 echo $tfname;
457 echo "</option>";
459 closedir($dh);
461 </select>
462 </td>
464 </tr>
466 </tr>
468 <tr>
470 <td>
471 <?php xl('To','e'); ?>:
472 </td>
474 <td>
475 <select name='form_to'>
476 <?php echo $optto; ?>
477 </select>
478 </td>
480 <td>
481 <?php xl('Print Format','e'); ?>:
482 </td>
484 <td>
485 <select name='form_format'>
486 <option value='html'><?php xl('HTML','e'); ?></option>
487 <option value='pdf'><?php xl('PDF','e'); ?></option>
488 </select>
489 </td>
491 </tr>
493 <tr>
494 <td colspan='4'>
495 <div id="letter_toolbar" class='text' style="width: 100%; background-color: #ddd; padding: 5px; margin: 0px;">
496 Insert special field:
497 <select id="letter_field">
498 <option value="">- <?php xl('Choose','e'); ?> -</option>
499 <option value="<?php echo '{'.$FIELD_TAG['DATE'].'}'; ?>"><?php xl('Today\'s Date','e'); ?></option>
500 <option value="<?php echo '{'.$FIELD_TAG['FROM_TITLE'].'}'; ?>"><?php xl('FROM','e'); ?> - <?php xl('Title','e'); ?></option>
501 <option value="<?php echo '{'.$FIELD_TAG['FROM_FNAME'].'}'; ?>"><?php xl('FROM','e'); ?> - <?php xl('First name','e'); ?></option>
502 <option value="<?php echo '{'.$FIELD_TAG['FROM_MNAME'].'}'; ?>"><?php xl('FROM','e'); ?> - <?php xl('Middle name','e'); ?></option>
503 <option value="<?php echo '{'.$FIELD_TAG['FROM_LNAME'].'}'; ?>"><?php xl('FROM','e'); ?> - <?php xl('Last name','e'); ?></option>
504 <option value="<?php echo '{'.$FIELD_TAG['FROM_STREET'].'}'; ?>"><?php xl('FROM','e'); ?> - <?php xl('Street','e'); ?></option>
505 <option value="<?php echo '{'.$FIELD_TAG['FROM_CITY'].'}'; ?>"><?php xl('FROM','e'); ?> - <?php xl('City','e'); ?></option>
506 <option value="<?php echo '{'.$FIELD_TAG['FROM_STATE'].'}'; ?>"><?php xl('FROM','e'); ?> - <?php xl('State','e'); ?></option>
507 <option value="<?php echo '{'.$FIELD_TAG['FROM_POSTAL'].'}'; ?>"><?php xl('FROM','e'); ?> - <?php xl('Postal Code','e'); ?></option>
508 <option value="<?php echo '{'.$FIELD_TAG['FROM_VALEDICTORY'].'}'; ?>"><?php xl('FROM','e'); ?> - <?php xl('Valedictory','e'); ?></option>
509 <option value="<?php echo '{'.$FIELD_TAG['FROM_PHONECELL'].'}'; ?>"><?php xl('FROM','e'); ?> - <?php xl('Cell Phone','e'); ?></option>
510 <option value="<?php echo '{'.$FIELD_TAG['TO_TITLE'].'}'; ?>"><?php xl('TO','e'); ?> - <?php xl('Title','e'); ?></option>
511 <option value="<?php echo '{'.$FIELD_TAG['TO_FNAME'].'}'; ?>"><?php xl('TO','e'); ?> - <?php xl('First name','e'); ?></option>
512 <option value="<?php echo '{'.$FIELD_TAG['TO_MNAME'].'}'; ?>"><?php xl('TO','e'); ?> - <?php xl('Middle name','e'); ?></option>
513 <option value="<?php echo '{'.$FIELD_TAG['TO_LNAME'].'}'; ?>"><?php xl('TO','e'); ?> - <?php xl('Last name','e'); ?></option>
514 <option value="<?php echo '{'.$FIELD_TAG['TO_STREET'].'}'; ?>"><?php xl('TO','e'); ?> - <?php xl('Street','e'); ?></option>
515 <option value="<?php echo '{'.$FIELD_TAG['TO_CITY'].'}'; ?>"><?php xl('TO','e'); ?> - <?php xl('City','e'); ?></option>
516 <option value="<?php echo '{'.$FIELD_TAG['TO_STATE'].'}'; ?>"><?php xl('TO','e'); ?> - <?php xl('State','e'); ?></option>
517 <option value="<?php echo '{'.$FIELD_TAG['TO_POSTAL'].'}'; ?>"><?php xl('TO','e'); ?> - <?php xl('Postal Code','e'); ?></option>
518 <option value="<?php echo '{'.$FIELD_TAG['TO_VALEDICTORY'].'}'; ?>"><?php xl('TO','e'); ?> - <?php xl('Valedictory','e'); ?></option>
519 <option value="<?php echo '{'.$FIELD_TAG['TO_ORGANIZATION'].'}'; ?>"><?php xl('TO','e'); ?> - <?php xl('Organization','e'); ?></option>
520 <option value="<?php echo '{'.$FIELD_TAG['TO_FAX'].'}'; ?>"><?php xl('TO','e'); ?> - <?php xl('Fax number','e'); ?></option>
521 <option value="<?php echo '{'.$FIELD_TAG['PT_FNAME'].'}'; ?>"><?php xl('PATIENT','e'); ?> - <?php xl('First name','e'); ?></option>
522 <option value="<?php echo '{'.$FIELD_TAG['PT_MNAME'].'}'; ?>"><?php xl('PATIENT','e'); ?> - <?php xl('Middle name','e'); ?></option>
523 <option value="<?php echo '{'.$FIELD_TAG['PT_LNAME'].'}'; ?>"><?php xl('PATIENT','e'); ?> - <?php xl('Last name','e'); ?></option>
524 <option value="<?php echo '{'.$FIELD_TAG['PT_DOB'].'}'; ?>"><?php xl('PATIENT','e'); ?> - <?php xl('Date of birth','e'); ?></option>
525 </select>
526 </div>
527 <textarea name='form_body' id="form_body" rows='20' cols='30' style='width:100%'
528 title=<?php xl('Enter body of letter here','e','\'','\''); ?> /><?php echo $bodytext; ?></textarea>
529 </td>
530 </tr>
532 </table>
534 <input type='button' class="addtemplate" value=<?php xl('Save as New','e','\'','\''); ?>>
535 <input type='button' name='savetemplate' id="savetemplate" value=<?php xl('Save Changes','e','\'','\''); ?>>
536 <input type='button' name='form_generate' id="form_generate" value=<?php xl('Generate Letter','e','\'','\''); ?>>
538 </center>
540 <!-- template DIV that appears when user chooses to add a new letter template -->
541 <div id="newtemplatedetail" style="border: 1px solid black; padding: 3px; display: none; visibility: hidden; background-color: lightgrey;">
542 <?php xl('Template Name','e'); ?>: <input type="textbox" size="20" maxlength="30" name="newtemplatename" id="newtemplatename">
543 <br>
544 <input type="button" class="savenewtemplate" value=<?php xl('Save new template','e','\'','\''); ?>>
545 <input type="button" class="cancelnewtemplate" value=<?php xl('Cancel','e','\'','\''); ?>>
546 </div>
548 </form>
549 </body>
551 <script language='JavaScript'>
552 Calendar.setup({inputField:"form_date", ifFormat:"%Y-%m-%d", button:"img_date"});
554 // jQuery stuff to make the page a little easier to use
556 $(document).ready(function(){
557 $("#form_generate").click(function() { $("#formaction").val("generate"); $("#theform").submit(); });
558 $("#form_template").change(function() { $("#formaction").val("loadtemplate"); $("#theform").submit(); });
560 $("#savetemplate").click(function() { SaveTemplate(this); });
562 $("#letter_field").change(function() { insertAtCursor(document.getElementById("form_body"), $(this).val()); $(this).attr("selectedIndex", "0"); });
564 $(".addtemplate").click(function() { AddTemplate(this); });
565 $(".savenewtemplate").click(function() { SaveNewTemplate(this); });
566 $(".deletetemplate").click(function() { DeleteTemplate(this); });
567 $(".cancelnewtemplate").click(function() { CancelNewTemplate(this); });
569 // display the 'new group' DIV
570 var AddTemplate = function(btnObj) {
571 // show the field details DIV
572 $('#newtemplatedetail').css('visibility', 'visible');
573 $('#newtemplatedetail').css('display', 'block');
574 $(btnObj).parent().append($("#newtemplatedetail"));
575 $('#newtemplatedetail > #newtemplatename').focus();
578 // save the new template
579 var SaveNewTemplate = function(btnObj) {
580 // the template name can only have letters, numbers, spaces and underscores
581 // AND it cannot start with a number
582 if ($("#newtemplatename").val().match(/^\d+/)) {
583 alert("<?php xl('Template names cannot start with numbers.','e'); ?>");
584 return false;
586 var validname = $("#newtemplatename").val().replace(/[^A-za-z0-9]/g, "_"); // match any non-word characters and replace them
587 $("#newtemplatename").val(validname);
589 // submit the form to add a new field to a specific group
590 $("#formaction").val("newtemplate");
591 $("#theform").submit();
594 // actually delete a template file
596 var DeleteTemplate = function(btnObj) {
597 var parts = $(btnObj).attr("id");
598 var groupname = parts.replace(/^\d+/, "");
599 if (confirm("WARNING - This action cannot be undone.\n Are you sure you wish to delete the entire group named '"+groupname+"'?")) {
600 // submit the form to add a new field to a specific group
601 $("#formaction").val("deletegroup");
602 $("#deletegroupname").val(parts);
603 $("#theform").submit();
608 // just hide the new template DIV
609 var CancelNewTemplate = function(btnObj) {
610 // hide the field details DIV
611 $('#newtemplatedetail').css('visibility', 'hidden');
612 $('#newtemplatedetail').css('display', 'none');
613 // reset the new group values to a default
614 $('#newtemplatedetail > #newtemplatename').val("");
618 // save the template, overwriting the older version
619 var SaveTemplate = function(btnObj) {
620 if (! confirm("<?php xl('You are about to permanently replace the existing template. Are you sure you wish to continue?','e'); ?>")) {
621 return false;
623 $("#formaction").val("savetemplate");
624 $("#theform").submit();
628 </script>
630 </html>