Refactor previous name into dedicated service (#7571)
[openemr.git] / interface / batchcom / batchcom.inc.php
blob5525531c412a11f1299501b5ed20950d3a8034e0
1 <?php
3 /**
4 * Misc. BatchCom convenience functions
6 * @package OpenEMR
7 * @link http://www.open-emr.org
8 * @author Andres Paglayan <andres@paglayan.com>
9 * @author Jason 'Toolbox' Oettinger <jason@oettinger.email>
10 * @copyright Copyright (c) 2005 Andres Paglayan <andres@paglayan.com>
11 * @copyright Copyright (c) 2017 Jason 'Toolbox' Oettinger <jason@oettinger.email>
12 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
15 //validation functions
16 function check_date_format($date)
18 if (($date == '') || ($date == '0000-00-00')) {
19 return true;
21 $ymd = explode('-', $date);
22 return (count($ymd) == 3) && ($ymd[0] > 1900) && checkdate($ymd[1], $ymd[2], $ymd[0]);
25 function check_age($age)
27 $age = trim($age);
28 $pat = "/^([0-9]+)$/";
29 return preg_match($pat, $age) or $age == '';
32 function check_select($select, $array)
34 return array_search($select, $array) or 0 === array_search($select, $array);
37 function where_or_and($and)
39 if ($and == '') {
40 $and = 'WHERE ';
41 } elseif ($and == 'WHERE ') {
42 $and = 'AND ';
43 } else {
44 $and = 'AND ';
47 return $and;
50 function register_email($patient_id, $sent_by, $msg_type, $msg_subject, $msg_text)
53 $sql = "INSERT INTO batchcom SET patient_id=?, sent_by=?,
54 msg_type=?, msg_subject=?,
55 msg_text=?, msg_date_sent=NOW()";
57 echo $sql;
59 $res = sqlStatement($sql, array($patient_id, $sent_by, $msg_type, $msg_subject, $msg_text));
62 function generate_csv($sql_result)
64 /* batch CSV processor, included from batchcom */
65 // create file header.
66 // menu for fields could be added in the future
68 while ($row = sqlFetchArray($sql_result)) {
69 if (!$flag_on) {
70 $flag_on = true;
71 foreach ($row as $key => $value) {
72 $file .= csvEscape($key) . ",";
75 $file = substr($file, 0, -1);
76 $file .= "\n";
77 reset($row);
80 foreach ($row as $key => $value) {
81 $line .= csvEscape($value) . ",";
84 $line = substr($line, 0, -1);
85 $line .= "\n";
86 $file .= $line;
87 $line = '';
90 //download
91 $today = date('Y-m-d:H:i:s');
92 $filename = "CSVdata-" . $today . ".csv";
93 header('Pragma: private');
94 header('Cache-control: private, must-revalidate');
95 header("Content-type: text/comma-separated-values");
96 header("Content-Disposition: attachment; filename=" . $filename);
97 print $file;
98 exit();