Moved recent v5.0.0 statement fix to current master.
[openemr.git] / interface / batchcom / batchcom.inc.php
blob716903edf34d6809b31dc22fd3ee014848393f4f
1 <?php
2 /**
3 * Misc. BatchCom convenience functions
5 * @package OpenEMR
6 * @link http://www.open-emr.org
7 * @author Andres Paglayan <andres@paglayan.com>
8 * @author Jason 'Toolbox' Oettinger <jason@oettinger.email>
9 * @copyright Copyright (c) 2005 Andres Paglayan <andres@paglayan.com>
10 * @copyright Copyright (c) 2017 Jason 'Toolbox' Oettinger <jason@oettinger.email>
11 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
14 //validation functions
15 function check_date_format($date)
17 $pat = "/^(19[0-9]{2}|20[0-1]{1}[0-9]{1})-(0[1-9]|1[0-2])-(0[1-9]{1}|1[0-9]{1}|2[0-9]{1}|3[0-1]{1})$/";
18 return preg_match($pat, $date) or $date=='' or $date=='0000-00-00';
21 function check_age($age)
23 $age = trim($age);
24 $pat = "/^([0-9]+)$/";
25 return preg_match($pat, $age) or $age=='';
28 function check_select($select, $array)
30 return array_search($select, $array) or 0===array_search($select, $array);
33 function where_or_and($and)
35 if ($and=='') {
36 $and='WHERE ';
37 } elseif ($and=='WHERE ') {
38 $and='AND ';
39 } else {
40 $and='AND ';
43 return $and;
46 function register_email($patient_id, $sent_by, $msg_type, $msg_subject, $msg_text)
49 $sql = "INSERT INTO batchcom SET patient_id=?, sent_by=?,
50 msg_type=?, msg_subject=?,
51 msg_text=?, msg_date_sent=NOW()";
53 echo $sql;
55 $res = sqlStatement($sql, array($patient_id, $sent_by, $msg_type, $msg_subject, $msg_text));
58 function generate_csv($sql_result)
60 /* batch CSV processor, included from batchcom */
61 // create file header.
62 // menu for fields could be added in the future
64 while ($row=sqlFetchArray($sql_result)) {
65 if (!$flag_on) {
66 $flag_on = true;
67 foreach ($row as $key => $value) {
68 $file .= "$key,";
71 $file = substr($file, 0, -1);
72 $file .= "\n";
73 reset($row);
76 foreach ($row as $key => $value) {
77 $line .= "$value,";
80 $line = substr($line, 0, -1);
81 $line .= "\n";
82 $file .= $line;
83 $line = '';
86 //download
87 $today = date('Y-m-d:H:i:s');
88 $filename = "CSVdata-".$today.".csv";
89 header('Pragma: private');
90 header('Cache-control: private, must-revalidate');
91 header("Content-type: text/comma-separated-values");
92 header("Content-Disposition: attachment; filename=" . $filename);
93 print $file;
94 exit();