3 // Copyright (C) 2006-2021 Rod Roark <rod@sunsetsystems.com>
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 require_once("../globals.php");
11 require_once("drugs.inc.php");
12 require_once("$srcdir/options.inc.php");
14 use OpenEMR\Common\Acl\AclMain
;
15 use OpenEMR\Common\Csrf\CsrfUtils
;
16 use OpenEMR\Core\Header
;
19 $drug_id = $_REQUEST['drug'];
23 if (!AclMain
::aclCheckCore('admin', 'drugs')) {
24 die(xlt('Not authorized'));
27 // Write a line of data for one template to the form.
29 function writeTemplateLine($selector, $dosage, $period, $quantity, $refills, $prices, $taxrates, $pkgqty)
35 echo " <td class='tmplcell drugsonly'>";
36 echo "<input class='form-control' name='form_tmpl[" . attr($tmpl_line_no) . "][selector]' value='" . attr($selector) . "' size='8' maxlength='100'>";
38 echo " <td class='tmplcell drugsonly'>";
39 echo "<input class='form-control' name='form_tmpl[" . attr($tmpl_line_no) . "][dosage]' value='" . attr($dosage) . "' size='6' maxlength='10'>";
41 echo " <td class='tmplcell drugsonly'>";
42 generate_form_field(array(
44 'field_id' => 'tmpl[' . attr($tmpl_line_no) . '][period]',
45 'list_id' => 'drug_interval',
46 'empty_title' => 'SKIP'
49 echo " <td class='tmplcell drugsonly'>";
50 echo "<input class='form-control' name='form_tmpl[" . attr($tmpl_line_no) . "][quantity]' value='" . attr($quantity) . "' size='3' maxlength='7'>";
52 echo " <td class='tmplcell drugsonly'>";
53 echo "<input class='form-control' name='form_tmpl[" . attr($tmpl_line_no) . "][refills]' value='" . attr($refills) . "' size='3' maxlength='5'>";
56 /******************************************************************
57 echo " <td class='tmplcell drugsonly'>";
58 echo "<input type='text' class='form-control' name='form_tmpl[" . attr($tmpl_line_no) .
59 "][pkgqty]' value='" . attr($pkgqty) . "' size='3' maxlength='5'>";
61 ******************************************************************/
63 foreach ($prices as $pricelevel => $price) {
64 echo " <td class='tmplcell'>";
65 echo "<input class='form-control' name='form_tmpl[" . attr($tmpl_line_no) . "][price][" . attr($pricelevel) . "]' value='" . attr($price) . "' size='6' maxlength='12'>";
69 $pres = sqlStatement("SELECT option_id FROM list_options " .
70 "WHERE list_id = 'taxrate' AND activity = 1 ORDER BY seq");
71 while ($prow = sqlFetchArray($pres)) {
72 echo " <td class='tmplcell'>";
73 echo "<input type='checkbox' name='form_tmpl[" . attr($tmpl_line_no) . "][taxrate][" . attr($prow['option_id']) . "]' value='1'";
74 if (strpos(":$taxrates", $prow['option_id']) !== false) {
86 <title
><?php
echo $drug_id ?
xlt("Edit") : xlt("Add New");
87 echo ' ' . xlt('Drug'); ?
></title
>
89 <?php Header
::setupHeader(["opener"]); ?
>
93 <?php
if ($GLOBALS['sell_non_drug_products'] == 2) { // "Products but no prescription drugs and no templates" ?>
94 .drugsonly
{ display
:none
; }
99 <?php
if (empty($GLOBALS['ippf_specific'])) { ?
>
100 .ippfonly
{ display
:none
; }
109 <?php
require($GLOBALS['srcdir'] . "/restoreSession.php"); ?
>
111 // This is for callback by the find-code popup.
112 // Appends to or erases the current list of related codes.
113 // The target element is set by the find-code popup
114 // (this allows use of this in multiple form elements on the same page)
115 function set_related_target(codetype
, code
, selector
, codedesc
, target_element
, limit
=0) {
116 var f
= document
.forms
[0];
117 var s
= f
[target_element
].value
;
120 s
= codetype +
':' + code
;
123 if (codetype
!= 'PROD') {
124 // Return an error message if a service code is already selected.
125 if (s
.indexOf(codetype +
':') == 0 || s
.indexOf(';' + codetype +
':') > 0) {
126 return <?php
echo xlj('A code of this type is already selected. Erase the field first if you need to replace it.') ?
>;
132 s +
= codetype +
':' + code
;
137 f
[target_element
].value
= s
;
141 // This is for callback by the find-code popup.
142 // Returns the array of currently selected codes with each element in codetype:code format.
143 function get_related() {
144 return document
.forms
[0].form_related_code
.value
.split(';');
147 // This is for callback by the find-code popup.
148 // Deletes the specified codetype:code from the currently selected list.
149 function del_related(s
) {
150 my_del_related(s
, document
.forms
[0].form_related_code
, false);
153 // This invokes the find-code popup.
154 function sel_related(getter
= '') {
155 dlgopen('../patient_file/encounter/find_code_dynamic.php' + getter
, '_blank', 900, 800);
158 // onclick handler for "allow inventory" checkbox.
159 function dispensable_changed() {
160 var f
= document
.forms
[0];
161 var dis
= !f
.form_dispensable
.checked
;
162 f
.form_allow_multiple
.disabled
= dis
;
163 f
.form_allow_combining
.disabled
= dis
;
167 function validate(f
) {
168 var saving
= f
.form_save
.clicked ?
true : false;
169 f
.form_save
.clicked
= false;
171 if (f
.form_name
.value
.search(/[^\s
]/) < 0) {
172 alert(<?php
echo xlj('Product name is required'); ?
>);
176 var deleting
= f
.form_delete
.clicked ?
true : false;
177 f
.form_delete
.clicked
= false;
179 if (!confirm(<?php
echo xlj('This will permanently delete all lots of this product. Related reports will be incomplete or incorrect. Are you sure?'); ?
>)) {
183 top
.restoreSession();
191 <body
class="body_top">
193 // If we are saving, then save and close the window.
194 // First check for duplicates.
196 if (!empty($_POST['form_save'])) {
197 if (!CsrfUtils
::verifyCsrfToken($_POST["csrf_token_form"])) {
198 CsrfUtils
::csrfNotVerified();
201 $drugName = trim($_POST['form_name']);
202 if ($drugName === '') {
203 $alertmsg = xl('Drug name is required');
206 "SELECT COUNT(*) AS count FROM drugs WHERE " .
214 trim($_POST['form_name']),
215 trim($_POST['form_form']),
216 trim($_POST['form_size']),
217 trim($_POST['form_unit']),
218 trim($_POST['form_route']),
222 if ($crow['count']) {
223 $alertmsg = xl('Cannot add this entry because it already exists!');
228 if ((!empty($_POST['form_save']) ||
!empty($_POST['form_delete'])) && !$alertmsg) {
229 if (!CsrfUtils
::verifyCsrfToken($_POST["csrf_token_form"])) {
230 CsrfUtils
::csrfNotVerified();
235 if ($_POST['form_save']) { // updating an existing drug
237 "UPDATE drugs SET " .
242 "reorder_point = ?, " .
249 "related_code = ?, " .
250 "dispensable = ?, " .
251 "allow_multiple = ?, " .
252 "allow_combining = ?, " .
257 trim($_POST['form_name']),
258 trim($_POST['form_ndc_number']),
259 trim($_POST['form_drug_code']),
260 trim($_POST['form_on_order']),
261 trim($_POST['form_reorder_point']),
262 trim($_POST['form_max_level']),
263 trim($_POST['form_form']),
264 trim($_POST['form_size']),
265 trim($_POST['form_unit']),
266 trim($_POST['form_route']),
267 trim($_POST['form_cyp_factor']),
268 trim($_POST['form_related_code']),
269 (empty($_POST['form_dispensable' ]) ?
0 : 1),
270 (empty($_POST['form_allow_multiple' ]) ?
0 : 1),
271 (empty($_POST['form_allow_combining']) ?
0 : 1),
272 (empty($_POST['form_active']) ?
0 : 1),
273 (empty($_POST['form_consumable' ]) ?
0 : 1),
277 sqlStatement("DELETE FROM drug_templates WHERE drug_id = ?", array($drug_id));
279 if (AclMain
::aclCheckCore('admin', 'super')) {
280 sqlStatement("DELETE FROM drug_inventory WHERE drug_id = ?", array($drug_id));
281 sqlStatement("DELETE FROM drug_templates WHERE drug_id = ?", array($drug_id));
282 sqlStatement("DELETE FROM drugs WHERE drug_id = ?", array($drug_id));
283 sqlStatement("DELETE FROM prices WHERE pr_id = ? AND pr_selector != ''", array($drug_id));
286 } elseif ($_POST['form_save']) { // saving a new drug
288 $drug_id = sqlInsert(
289 "INSERT INTO drugs ( " .
290 "name, ndc_number, drug_code, on_order, reorder_point, max_level, form, " .
291 "size, unit, route, cyp_factor, related_code, " .
292 "dispensable, allow_multiple, allow_combining, active, consumable " .
312 trim($_POST['form_name']),
313 trim($_POST['form_ndc_number']),
314 trim($_POST['form_drug_code']),
315 trim($_POST['form_on_order']),
316 trim($_POST['form_reorder_point']),
317 trim($_POST['form_max_level']),
318 trim($_POST['form_form']),
319 trim($_POST['form_size']),
320 trim($_POST['form_unit']),
321 trim($_POST['form_route']),
322 trim($_POST['form_cyp_factor']),
323 trim($_POST['form_related_code']),
324 (empty($_POST['form_dispensable' ]) ?
0 : 1),
325 (empty($_POST['form_allow_multiple' ]) ?
0 : 1),
326 (empty($_POST['form_allow_combining']) ?
0 : 1),
327 (empty($_POST['form_active' ]) ?
0 : 1),
328 (empty($_POST['form_consumable' ]) ?
0 : 1)
333 if ($_POST['form_save'] && $drug_id) {
334 $tmpl = $_POST['form_tmpl'];
335 // If using the simplified drug form, then force the one and only
336 // selector name to be the same as the product name.
337 if ($GLOBALS['sell_non_drug_products'] == 2) {
338 $tmpl["1"]['selector'] = $_POST['form_name'];
341 sqlStatement("DELETE FROM prices WHERE pr_id = ? AND pr_selector != ''", array($drug_id));
342 for ($lino = 1; isset($tmpl["$lino"]['selector']); ++
$lino) {
343 $iter = $tmpl["$lino"];
344 $selector = trim($iter['selector']);
347 if (!empty($iter['taxrate'])) {
348 foreach ($iter['taxrate'] as $key => $value) {
349 $taxrates .= "$key:";
354 "INSERT INTO drug_templates ( " .
355 "drug_id, selector, dosage, period, quantity, refills, taxrates, pkgqty " .
356 ") VALUES ( ?, ?, ?, ?, ?, ?, ?, ? )",
360 trim($iter['dosage']),
361 trim($iter['period']),
362 trim($iter['quantity']),
363 trim($iter['refills']),
365 // floatval(trim($iter['pkgqty']))
370 // Add prices for this drug ID and selector.
371 foreach ($iter['price'] as $key => $value) {
375 "INSERT INTO prices ( " .
376 "pr_id, pr_selector, pr_level, pr_price ) VALUES ( " .
378 array($drug_id, $selector, $key, $value)
381 } // end foreach price
382 } // end if selector is present
383 } // end for each selector
384 // Save warehouse-specific mins and maxes for this drug.
385 sqlStatement("DELETE FROM product_warehouse WHERE pw_drug_id = ?", array($drug_id));
386 foreach ($_POST['form_wh_min'] as $whid => $whmin) {
388 $whmax = 0 +
$_POST['form_wh_max'][$whid];
389 if ($whmin != 0 ||
$whmax != 0) {
390 sqlStatement("INSERT INTO product_warehouse ( " .
391 "pw_drug_id, pw_warehouse, pw_min_level, pw_max_level ) VALUES ( " .
392 "?, ?, ?, ? )", array($drug_id, $whid, $whmin, $whmax));
395 } // end if saving a drug
397 // Close this window and redisplay the updated list of drugs.
401 echo " alert('" . addslashes($info_msg) . "');\n";
404 echo " if (opener.refreshme) opener.refreshme();\n";
406 echo " window.location.href='add_edit_lot.php?drug=" . attr_url($drug_id) . "&lot=0'\n";
408 echo " window.close();\n";
411 echo "</script></body></html>\n";
416 $row = sqlQuery("SELECT * FROM drugs WHERE drug_id = ?", array($drug_id));
417 $tres = sqlStatement("SELECT * FROM drug_templates WHERE " .
418 "drug_id = ? ORDER BY selector", array($drug_id));
423 'dispensable' => '1',
424 'allow_multiple' => '1',
425 'allow_combining' => '',
429 'reorder_point' => '0',
436 'related_code' => '',
439 $title = $drug_id ?
xl("Update Drug") : xl("Add Drug");
441 <h3
class="ml-1"><?php
echo text($title);?
></h3
>
442 <form method
='post' name
='theform' action
='add_edit_drug.php?drug=<?php echo attr_url($drug_id); ?>'
443 onsubmit
='return validate(this);'>
444 <input type
="hidden" name
="csrf_token_form" value
="<?php echo attr(CsrfUtils::collectCsrfToken()); ?>" />
446 <div
class="form-group">
447 <label
class="font-weight-bold"><?php
echo xlt('Name'); ?
>:</label
>
448 <input
class="form-control" size
="40" name
="form_name" maxlength
="80" value
='<?php echo attr($row['name
']) ?>' />
451 <div
class="form-group mt-3">
452 <label
class="font-weight-bold"><?php
echo xlt('Attributes'); ?
>:</label
>
453 <input type
='checkbox' name
='form_active' value
='1'<?php
454 if ($row['active']) {
457 <?php
echo xlt('Active{{Drug}}'); ?
>
458 <input type
='checkbox' name
='form_consumable' value
='1'<?php
459 if ($row['consumable']) {
462 <?php
echo xlt('Consumable'); ?
>
465 <div
class="form-group mt-3">
466 <label
class="font-weight-bold"><?php
echo xlt('Allow'); ?
>:</label
>
467 <input type
='checkbox' name
='form_dispensable' value
='1' onclick
='dispensable_changed();'<?php
468 if ($row['dispensable']) {
471 <?php
echo xlt('Inventory'); ?
>
472 <input type
='checkbox' name
='form_allow_multiple' value
='1'<?php
473 if ($row['allow_multiple']) {
476 <?php
echo xlt('Multiple Lots'); ?
>
477 <input type
='checkbox' name
='form_allow_combining' value
='1'<?php
478 if ($row['allow_combining']) {
481 <?php
echo xlt('Combining Lots'); ?
>
484 <div
class="form-group mt-3">
485 <label
class="font-weight-bold"><?php
echo xlt('NDC Number'); ?
>:</label
>
486 <input
class="form-control w-100" size
="40" name
="form_ndc_number" maxlength
="20" value
='<?php echo attr($row['ndc_number
']) ?>' onkeyup
='maskkeyup(this,"<?php echo attr(addslashes($GLOBALS['gbl_mask_product_id
'])); ?>")' onblur
='maskblur(this,"<?php echo attr(addslashes($GLOBALS['gbl_mask_product_id
'])); ?>")' />
489 <div
class="form-group mt-3">
490 <label
class="font-weight-bold"><?php
echo xlt('RXCUI Code'); ?
>:</label
>
491 <input
class="form-control w-100" type
="text" size
="50" name
="form_drug_code" value
='<?php echo attr($row['drug_code
']) ?>'
492 onclick
='sel_related("?codetype=RXCUI&limit=1&target_element=form_drug_code")' title
='<?php echo xla('Click to select RXCUI code
'); ?>' data
-toggle
="tooltip" data
-placement
="top" readonly
/>
495 <div
class="form-group mt-3">
496 <label
class="font-weight-bold"><?php
echo xlt('On Order'); ?
>:</label
>
497 <input
class="form-control" size
="5" name
="form_on_order" maxlength
="7" value
='<?php echo attr($row['on_order
']) ?>' />
500 <div
class="form-group mt-3">
501 <label
class="font-weight-bold"><?php
echo xlt('Limits'); ?
>:</label
>
502 <table
class="table table-borderless pl-5">
504 <td
class="align-top font-weight-bold">
505 <?php
echo !empty($GLOBALS['gbl_min_max_months']) ?
xlt('Months') : xlt('Units'); ?
>
507 <td
class="align-top"><?php
echo xlt('Global'); ?
></td
>
509 // One column header per warehouse title.
511 $pwres = sqlStatement(
512 "SELECT lo.option_id, lo.title, " .
513 "pw.pw_min_level, pw.pw_max_level " .
514 "FROM list_options AS lo " .
515 "LEFT JOIN product_warehouse AS pw ON " .
516 "pw.pw_drug_id = ? AND " .
517 "pw.pw_warehouse = lo.option_id WHERE " .
518 "lo.list_id = 'warehouse' AND lo.activity = 1 ORDER BY lo.seq, lo.title",
521 while ($pwrow = sqlFetchArray($pwres)) {
523 echo " <td class='align-top'>" . text($pwrow['title']) . "</td>\n";
528 <td
class="align-top"><?php
echo xlt('Min'); ?
> 
;</td
>
529 <td
class="align-top">
530 <input
class="form-control" size
='5' name
='form_reorder_point' maxlength
='7' value
='<?php echo attr($row['reorder_point
']) ?>' title
='<?php echo xla('Reorder point
, 0 if not applicable
'); ?>' data
-toggle
="tooltip" data
-placement
="top" />
533 foreach ($pwarr as $pwrow) {
534 echo " <td class='align-top'>";
535 echo "<input class='form-control' name='form_wh_min[" .
536 attr($pwrow['option_id']) .
537 "]' value='" . attr(0 +
$pwrow['pw_min_level']) . "' size='5' " .
538 "title='" . xla('Warehouse minimum, 0 if not applicable') . "' data-toggle='tooltip' data-placement='top' />";
539 echo " </td>\n";
544 <td
class="align-top"><?php
echo xlt('Max'); ?
> 
;</td
>
546 <input
class='form-control' size
='5' name
='form_max_level' maxlength
='7' value
='<?php echo attr($row['max_level
']) ?>' title
='<?php echo xla('Maximum reasonable inventory
, 0 if not applicable
'); ?>' data
-toggle
="tooltip" data
-placement
="top" />
549 foreach ($pwarr as $pwrow) {
550 echo " <td class='align-top'>";
551 echo "<input class='form-control' name='form_wh_max[" .
552 attr($pwrow['option_id']) .
553 "]' value='" . attr(0 +
$pwrow['pw_max_level']) . "' size='5' " .
554 "title='" . xla('Warehouse maximum, 0 if not applicable') . "' data-toggle='tooltip' data-placement='top' />";
562 <div
class="form-group mt-3 drugsonly">
563 <label
class="font-weight-bold"><?php
echo xlt('Form'); ?
>:</label
>
565 generate_form_field(array('data_type' => 1,'field_id' => 'form','list_id' => 'drug_form','empty_title' => 'SKIP'), $row['form']);
569 <div
class="form-group mt-3 drugsonly">
570 <label
class="font-weight-bold"><?php
echo xlt('Size'); ?
>:</label
>
571 <input
class="form-control" size
="5" name
="form_size" maxlength
="7" value
='<?php echo attr($row['size
']) ?>' />
574 <div
class="form-group mt-3 drugsonly" title
='<?php echo xlt('Measurement Units
'); ?>'>
575 <label
class="font-weight-bold"><?php
echo xlt('Units'); ?
>:</label
>
577 generate_form_field(array('data_type' => 1,'field_id' => 'unit','list_id' => 'drug_units','empty_title' => 'SKIP'), $row['unit']);
581 <div
class="form-group mt-3 drugsonly">
582 <label
class="font-weight-bold"><?php
echo xlt('Route'); ?
>:</label
>
584 generate_form_field(array('data_type' => 1,'field_id' => 'route','list_id' => 'drug_route','empty_title' => 'SKIP'), $row['route']);
588 <div
class="form-group mt-3 ippfonly" style
='display:none'> <!-- Removed per CV
2017-03-29 -->
589 <label
class="font-weight-bold"><?php
echo xlt('CYP Factor'); ?
>:</label
>
590 <input
class="form-control" size
="10" name
="form_cyp_factor" maxlength
="20" value
='<?php echo attr($row['cyp_factor
']) ?>' />
593 <div
class="form-group mt-3 drugsonly">
594 <label
class="font-weight-bold"><?php
echo xlt('Relate To'); ?
>:</label
>
595 <input
class="form-control w-100" type
="text" size
="50" name
="form_related_code" value
='<?php echo attr($row['related_code
']) ?>'
596 onclick
='sel_related("?target_element=form_related_code")' title
='<?php echo xla('Click to select related code
'); ?>' data
-toggle
="tooltip" data
-placement
="top" readonly
/>
599 <div
class="form-group mt-3">
600 <label
class="font-weight-bold">
601 <?php
echo $GLOBALS['sell_non_drug_products'] == 2 ?
xlt('Fees') : xlt('Templates'); ?
>:
603 <table
class='table table-borderless'>
605 <td
class='drugsonly font-weight-bold'><?php
echo xlt('Name'); ?
></td
>
606 <td
class='drugsonly font-weight-bold'><?php
echo xlt('Schedule'); ?
></td
>
607 <td
class='drugsonly font-weight-bold'><?php
echo xlt('Interval'); ?
></td
>
608 <td
class='drugsonly font-weight-bold'><?php
echo xlt('Basic Units'); ?
></td
>
609 <td
class='drugsonly font-weight-bold'><?php
echo xlt('Refills'); ?
></td
>
611 // Show a heading for each price level. Also create an array of prices
612 // for new template lines.
613 $emptyPrices = array();
614 $pres = sqlStatement("SELECT option_id, title FROM list_options " .
615 "WHERE list_id = 'pricelevel' AND activity = 1 ORDER BY seq");
616 while ($prow = sqlFetchArray($pres)) {
617 $emptyPrices[$prow['option_id']] = '';
618 echo " <td class='font-weight-bold'>" .
619 generate_display_field(array('data_type' => '1','list_id' => 'pricelevel'), $prow['option_id']) .
623 // Show a heading for each tax rate.
624 $pres = sqlStatement("SELECT option_id, title FROM list_options " .
625 "WHERE list_id = 'taxrate' AND activity = 1 ORDER BY seq");
626 while ($prow = sqlFetchArray($pres)) {
627 echo " <td class='font-weight-bold'>" .
628 generate_display_field(array('data_type' => '1','list_id' => 'taxrate'), $prow['option_id']) .
634 $blank_lines = $GLOBALS['sell_non_drug_products'] == 2 ?
1 : 3;
636 while ($trow = sqlFetchArray($tres)) {
637 $blank_lines = $GLOBALS['sell_non_drug_products'] == 2 ?
0 : 1;
638 $selector = $trow['selector'];
639 // Get array of prices.
641 $pres = sqlStatement(
642 "SELECT lo.option_id, p.pr_price " .
643 "FROM list_options AS lo LEFT OUTER JOIN prices AS p ON " .
644 "p.pr_id = ? AND p.pr_selector = ? AND " .
645 "p.pr_level = lo.option_id " .
646 "WHERE lo.list_id = 'pricelevel' AND lo.activity = 1 ORDER BY lo.seq",
647 array($drug_id, $selector)
649 while ($prow = sqlFetchArray($pres)) {
650 $prices[$prow['option_id']] = $prow['pr_price'];
666 for ($i = 0; $i < $blank_lines; ++
$i) {
667 $selector = $GLOBALS['sell_non_drug_products'] == 2 ?
$row['name'] : '';
668 writeTemplateLine($selector, '', '', '', '', $emptyPrices, '', '1');
674 <div
class="btn-group">
675 <button type
='submit' class="btn btn-primary btn-save" name
='form_save'
676 value
='<?php echo $drug_id ? xla('Update
') : xla('Add
') ; ?>'
677 onclick
='return this.clicked = true;'
678 ><?php
echo $drug_id ?
xlt('Update') : xlt('Add') ; ?
></button
>
679 <?php
if (AclMain
::aclCheckCore('admin', 'super') && $drug_id) { ?
>
680 <button
class="btn btn-danger" type
='submit' name
='form_delete'
681 onclick
='return this.clicked = true;' value
='<?php echo xla('Delete
'); ?>'
682 ><?php
echo xlt('Delete'); ?
></button
>
684 <button type
='button' class="btn btn-secondary btn-cancel" onclick
='window.close()'><?php
echo xlt('Cancel'); ?
></button
>
691 $
('[data-toggle="tooltip"]').tooltip();
694 dispensable_changed();
698 echo "alert('" . addslashes($alertmsg) . "');\n";