Some jquery updates (#2028)
[openemr.git] / interface / patient_file / encounter / delete_form.php
blob762b14962ca3b6188004beb378160b5d4391f3f8
1 <?php
2 /**
3 * This script delete an Encounter form.
5 * @package OpenEMR
6 * @link http://www.open-emr.org
7 * @author Roberto Vasquez <robertogagliotta@gmail.com>
8 * @author Brady Miller <brady.g.miller@gmail.com>
9 * @copyright Copyright (c) 2015 Roberto Vasquez <robertogagliotta@gmail.com>
10 * @copyright Copyright (c) 2018 Brady Miller <brady.g.miller@gmail.com>
11 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
15 require_once("../../globals.php");
17 use OpenEMR\Core\Header;
19 // allow a custom 'delete' form
20 $deleteform = $incdir . "/forms/" . $_REQUEST["formname"]."/delete.php";
22 check_file_dir_name($_REQUEST["formname"]);
24 if (file_exists($deleteform)) {
25 include_once($deleteform);
26 exit;
29 // if no custom 'delete' form, then use a generic one
31 // when the Cancel button is pressed, where do we go?
32 $returnurl = 'forms.php';
34 if ($_POST['confirm']) {
35 if (!verifyCsrfToken($_POST["csrf_token_form"])) {
36 csrfNotVerified();
39 if ($_POST['id'] != "*" && $_POST['id'] != '') {
40 // set the deleted flag of the indicated form
41 $sql = "update forms set deleted=1 where id=?";
42 sqlInsert($sql, array($_POST['id']));
43 // Delete the visit's "source=visit" attributes that are not used by any other form.
44 sqlStatement(
45 "DELETE FROM shared_attributes WHERE " .
46 "pid = ? AND encounter = ? AND field_id NOT IN (" .
47 "SELECT lo.field_id FROM forms AS f, layout_options AS lo WHERE " .
48 "f.pid = ? AND f.encounter = ? AND f.formdir LIKE 'LBF%' AND " .
49 "f.deleted = 0 AND " .
50 "lo.form_id = f.formdir AND lo.source = 'E' AND lo.uor > 0)",
51 array($pid, $encounter, $pid, $encounter)
54 // log the event
55 newEvent("delete", $_SESSION['authUser'], $_SESSION['authProvider'], 1, "Form ".$_POST['formname']." deleted from Encounter ".$_POST['encounter']);
57 // redirect back to the encounter
58 $address = "{$GLOBALS['rootdir']}/patient_file/encounter/$returnurl";
59 echo "\n<script language='Javascript'>top.restoreSession();window.location='$address';</script>\n";
60 exit;
63 <html>
65 <head>
66 <?php Header::setupHeader(['no_bootstrap', 'no_fontawesome', 'no_textformat', 'no_dialog' ]); ?>
67 </head>
69 <body class="body_top">
71 <span class="title"><?php echo xlt('Delete Encounter Form'); ?></span>
73 <form method="post" action="<?php echo $rootdir;?>/patient_file/encounter/delete_form.php" name="my_form" id="my_form">
74 <input type="hidden" name="csrf_token_form" value="<?php echo attr(collectCsrfToken()); ?>" />
76 <?php
77 // output each GET variable as a hidden form input
78 foreach ($_GET as $key => $value) {
79 echo '<input type="hidden" id="'.attr($key).'" name="'.attr($key).'" value="'.attr($value).'"/>'."\n";
82 <input type="hidden" id="confirm" name="confirm" value="1"/>
83 <p>
84 <?php echo xlt('You are about to delete the following form from this encounter') . ': ' . text(xl_form_title($_GET['formname'])); ?>
85 </p>
86 <input type="button" id="confirmbtn" name="confirmbtn" value='<?php echo xla('Yes, Delete this form'); ?>'>
87 <input type="button" id="cancel" name="cancel" value='<?php echo xla('Cancel'); ?>'>
88 </form>
90 </body>
92 <script language="javascript">
93 // jQuery stuff to make the page a little easier to use
95 $(document).ready(function(){
96 $("#confirmbtn").on("click", function() { return ConfirmDelete(); });
97 $("#cancel").on("click", function() { location.href='<?php echo "$rootdir/patient_file/encounter/$returnurl";?>'; });
98 });
100 function ConfirmDelete() {
101 if (confirm(<?php echo xlj('This action cannot be undone. Are you sure you wish to delete this form?'); ?>)) {
102 top.restoreSession();
103 $("#my_form").submit();
104 return true;
106 return false;
109 </script>
111 </html>