Bump phpmailer/phpmailer from 6.1.5 to 6.1.6 (#3567)
[openemr.git] / library / api.inc
blob43ac957b6ffdd5323f3161e31c5bfce45af3836b
1 <?php
3 //our api for 3rd party developers
4 require_once(dirname(__FILE__) . "/../interface/globals.php");
6 use OpenEMR\Billing\BillingUtilities;
8 $GLOBALS['form_exit_url'] = "javascript:parent.closeTab(window.name, false)";
10 function formHeader($title = "My Form")
12     ?>
13     <html>
14     <head>
15     <link rel=stylesheet href="<?php echo $GLOBALS['css_header']?>" type="text/css">
16     <title><?php echo text($title); ?></title>
17     </head>
18     <body background="<?php echo $GLOBALS['backpic']?>" topmargin=0 rightmargin=0 leftmargin=2 bottommargin=0 marginwidth=2 marginheight=0>
19     <?php
22 function formFooter()
24     ?>
25     </body>
26     </html>
27     <?php
30 function formSubmit($tableName, $values, $id, $authorized = "0")
32     global $attendant_type;
34     $sqlBindingArray = [$_SESSION['pid'], $_SESSION['authProvider'], $_SESSION['authUser'], $authorized];
35     $sql = "insert into " . escape_table_name($tableName) . " set " .  escape_sql_column_name($attendant_type, array($tableName)) . "=?, groupname=?, user=?, authorized=?, activity=1, date = NOW(),";
36     foreach ($values as $key => $value) {
37         if ($key == "csrf_token_form") {
38             continue;
39         }
40         if (strpos($key, "openemr_net_cpt") === 0) {
41             //code to auto add cpt code
42             if (!empty($value)) {
43                 $code_array = explode(" ", $value, 2);
45                 BillingUtilities::addBilling(date("Ymd"), 'CPT4', $code_array[0], $code_array[1], $_SESSION['pid'], $authorized, $_SESSION['authUserID']);
46             }
47         } elseif (strpos($key, "diagnosis") == (strlen($key) - 10) && !(strpos($key, "diagnosis") === false )) {
48             //case where key looks like "[a-zA-Z]*diagnosis[0-9]" which is special, it is used to auto add ICD codes
49             //icd auto add ICD9-CM
50             if (!empty($value)) {
51                 $code_array = explode(" ", $value, 2);
52                 BillingUtilities::addBilling(date("Ymd"), 'ICD9-M', $code_array[0], $code_array[1], $_SESSION['pid'], $authorized, $_SESSION['authUserID']);
53             }
54         } else {
55             $sql .= " " . escape_sql_column_name($key, array($tableName)) . " = ?,";
56             $sqlBindingArray[] = $value;
57         }
58     }
60     $sql = substr($sql, 0, -1);
61     return sqlInsert($sql, $sqlBindingArray);
65 function formUpdate($tableName, $values, $id, $authorized = "0")
67     $sqlBindingArray = [$_SESSION['pid'], $_SESSION['authProvider'], $_SESSION['authUser'], $authorized];
68     $sql = "update " . escape_table_name($tableName) . " set pid =?, groupname=?, user=? ,authorized=?, activity=1, date = NOW(),";
69     foreach ($values as $key => $value) {
70         if ($key == "csrf_token_form") {
71             continue;
72         }
73         $sql .= " " . escape_sql_column_name($key, array($tableName)) . " = ?,";
74         $sqlBindingArray[] = $value;
75     }
77     $sql = substr($sql, 0, -1);
78     $sql .= " where id=?";
79     $sqlBindingArray[] = $id;
81     return sqlInsert($sql, $sqlBindingArray);
84 function formJump($address = '')
86     echo "<script>\n";
87     if ($address) {
88         echo "top.restoreSession();\n";
89         echo "location.href = " . js_escape($address) . ";\n";
90     } else {
91         echo "parent.closeTab(window.name, true);\n";
92     }
93     echo "</script>\n";
94     // TBD: Exit seems wrong here, but that's how it has been forever.
95     exit;
98 function formFetch($tableName, $id, $cols = "*", $activity = "1")
100         // Run through escape_table_name() function to support dynamic form names in addition to mitigate sql table casing issues.
101     return sqlQuery("select " . escape_sql_column_name(process_cols_escape($cols), array($tableName)) . " from `" . escape_table_name($tableName) . "` where id=? and pid = ? and activity like ? order by date DESC LIMIT 0,1", array($id,$GLOBALS['pid'],$activity)) ;
105 function formDisappear($tableName, $id)
107         // Run through escape_table_name() function to support dynamic form names in addition to mitigate sql table casing issues.
108     if (sqlStatement("update `" . escape_table_name($tableName) . "` set activity = '0' where id=? and pid=?", [$id, $pid])) {
109         return true;
110     }
112     return false;
115 function formReappear($tableName, $id)
117         // Run through escape_table_name() function to support dynamic form names in addition to mitigate sql table casing issues.
118     if (sqlStatement("update `" . escape_table_name($tableName) . "` set activity = '1' where id=? and pid=?", [$id, $pid])) {
119         return true;
120     }
122     return false;