/
export.php
321 lines (314 loc) · 14.4 KB
/
export.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
<?php
require("globals.php5");
define(PG_SIZE,50);
require("cookies.php5");
$mesg = '';
if( $UUID && $ACCESS >= 200 ) try {
// do stuff
$db = db_career();
if( $_POST['submit'] && $_POST['extype'] ) {
// extype C (300+) masters 1/0, E exyear1, D (400+) exyear2, L exlist (=lid)
// filename (optional)
$filename = stripslashes(trim(str_replace('"',"'",$_POST['filename'])));
if( empty($filename) ) $filename = 'export-'.time().'.csv';
if( strpos($filename,'.') === false ) $filename .= '.csv'; // trivial check
$extype = $_POST['extype'];
if( $extype === 'C' && $ACCESS >= 300 ) {
// customers raw data dump
$sql = 'select `uid`, `email`, `firstname`, `lastname`, `mrmsdr`, `phone`, `fax`, `title`, `company`, `addr1`, `addr2`, `city`, `state`, `zip`, `acct`, `master_acct`, `subaccts`, `exp_date`, `status`, `subscription`, `specs`, `tc_agreed` from clients';
if( $_POST['masters'] ) $sql .= ' where `master_acct` = 1';
$res = $db->query($sql);
if( $res && $res->num_rows ) {
header('Content-type: text/plain');
header('Content-Disposition: attachment; filename="'.$filename.'"');
$firstline = true;
for( $i=0; $i < $res->num_rows; $i++ ) {
// export
if( $firstline ) {
$firstline = false;
$row = $res->fetch_assoc();
$firstElem = true;
foreach( $row as $key => $value ) {
if( $firstElem ) $firstElem = false;
else echo ',';
echo '"'.stripslashes($key).'"';
}
echo "\r\n"; // windows style is always ok
}
else $row = $res->fetch_row();
$firstElem = true;
foreach( $row as $value ) {
if( $firstElem ) $firstElem = false;
else echo ',';
$value = str_replace("\r\n"," ",$value);
if( $key == "zip" || $key == "ofzip" ) echo "\"'".stripslashes($value).'"';
else echo '"'.stripslashes($value).'"';
}
echo "\r\n"; // windows style is always ok
}
$res->free();
exit;
} else throw new Exception('No customers',__LINE__);
} // C
/* ******************************************************************* TOTAL REWRITE */
elseif( $extype === 'E' ) {
// E exyear1, D (400+) exyear2, L exlist (=lid)
// export active verified docs
$extypee = $_POST['extypee']; // (M)ail* or (C)ontact or Full
$ofaddr = $_POST['ofaddr'];
$homaddr = ',addr1,`addr2`, city, state, zip ';
$adrcond = '(addr1 is not null or addr2 is not null) and ';
if( $ofaddr ) {
$ofaddr = ',`ofaddr1`, `ofaddr2`, `ofcity`,`ofstate`,`ofzip` ';
if( $_POST['ofnohome'] ) {
$homaddr = '';
$adrcond = '(ofaddr1 is not null or ofaddr2 is not null) and ';
}
else $adrcond = '(addr1 is not null or ofaddr1 is not null or addr2 is not null or ofaddr2 is not null) and ';
}
else $ofaddr = '';
//$resdb = db_career();
$addsql = "";
//if( !$_POST['committed'] ) $addsql .= " and interviewing=1 ";
if( !$_POST['inactives'] ) $addsql .= " and status=1 ";
if( !$_POST['checkins'] ) $addsql .= " and checkin=1 ";
if( !$_POST['subscribed'] ) $addsql .= " and campaigns=1 ";
if( !$_POST['already'] ) $addsql .= " and lastlogdate is null ";
//if( $_POST['yerr'] && is_numeric($_POST['yerr']) ) $addsql .= " and `year`=".$_POST['yerr'];
if( ($ACCESS >= 400) && $extypee === 'F' )
$sql = "select `ph_id`,`fname`,`midname`,`lname`,`mddo`, d.addr1, `addr2`, d.city, d.state, d.zip, `ofaddr1`, `ofaddr2`, `ofcity`,`ofstate`,`ofzip`, `homephone`, `cellphone`, `officephone`, `officeext`, `email`, `spec`, `spec_2nd`, `school`, `sch_loc`, `sch_state`, `amg`, `sch_year`, `program`, res_city, `res_state`, `res_year`, `res_spec`, `fellowship`,`fel_city`, `fel_state`, `fel_spec`, `fel_year`, `avail_date`, `licensed`, `visa_status`, case `citizen` when 1 then 'US citizen' when 2 then 'perm.res.' end as us_citizen, `birth_state`, `bcbe`, `pref_region`, `pref_states`, `pref_stopen`, `pref_city`, `pref_commu2` as preferred_community, `pref_practice`, `marital_status`, `children`, `spouse`, `spouse_prof`, `spouse_spec`, `spouse_state`,`languages`, `hobbies`, `ct_pref` as contact_preference, `reason_leaving`, `other_pref` from physicians d join cont_pref on contact_pref = ct_id where inactive=0 and dup=0";
elseif( $extypee === 'C' ) // Full Contact Info
$sql = "select ph_id, spec, fname, midname, lname, mddo$homaddr$ofaddr, homephone, cellphone, officephone, officeext, CASE WHEN email_bounces=1 THEN null ELSE email END as email_addr from physicians where inactive=0 and dup=0 $addsql";
else // Mail Merge
$sql = "select ph_id, spec, fname, midname, lname, mddo$homaddr$ofaddr from physicians where $adrcond inactive=0 and dup=0 $addsql";
$res = $db->query($sql);
if( $res && $res->num_rows ) {
header('Content-type: text/plain');
header('Content-Disposition: attachment; filename="'.$filename.'"');
$firstline = true;
for( $i=0; $i < $res->num_rows; $i++ ) {
// export
if( $firstline ) {
$firstline = false;
$row = $res->fetch_assoc();
$firstElem = true;
foreach( $row as $key => $value ) {
if( $firstElem ) $firstElem = false;
else echo ',';
echo '"'.stripslashes($key).'"';
}
echo "\r\n"; // windows style is always ok
}
else $row = $res->fetch_row();
$firstElem = true;
foreach( $row as $value ) {
if( $firstElem ) $firstElem = false;
else echo ',';
$value = str_replace("\r\n"," ",$value);
//if( $key == "zip" || $key == "ofzip" ) echo "\"'".stripslashes($value).'"';
//else
echo '"'.stripslashes($value).'"';
}
echo "\r\n"; // windows style is always ok
}
$res->free();
exit;
} else throw new Exception('No available records',__LINE__); // DEBUG?"$db->error : $sql":
} // E
/* ********************************************************* */
elseif( $extype === 'L' ) {
// L exlist (=lid)
// export docs from custom list
$lid = $_POST['exlist'];
if( empty($lid) || !is_numeric($lid) ) throw new Exception('No list selected',__LINE__);
//$lst = $db->query("select `year` from custlistdesc where uid=$UUID and listid=$lid and `year`!=1");
//list($yer) = $lst->fetch_row();
//$lst->free();
//$resdb = db_resident(2007);
$sql = 'select `ph_id`,`fname`,`midname`,`lname`,`mddo`, `addr1`, `addr2`, `city`, `state`, `zip`, `ofaddr1`, `ofaddr2`, `ofcity`,`ofstate`,`ofzip`, `homephone`, `cellphone`, `officephone`, `officeext`, `email`,`spec`, `spec_2nd`, `school`, `sch_loc`, `sch_state`, `amg`, `sch_year`, `program`, `res_city`, `res_state`, `res_spec`, `res_year`, `fellowship`,`fel_city`, `fel_state`, `fel_spec`, `fel_year`, `program_2`, `res2_city`, `res2_state`, `res2_spec`, `res2_year`, `fellow_2`,`fel2_city`, `fel2_state`, `fel2_spec`, `fel2_year`, `avail_date`, `licensed`, `visa_status`, case `citizen` when 1 then \'US citizen\' when 2 then \'perm.res.\' end as us_citizen, `birth_state`, `bcbe`, `pref_region`, `pref_states`, `pref_stopen`, `pref_city`, `pref_commu2` as preferred_community, `pref_practice`, `marital_status`, `children`, `spouse`, `spouse_prof`, `spouse_spec`, `spouse_state`,`languages`, `hobbies`, `ct_pref` as contact_preference, `reason_leaving`, `other_pref`, `newsletter`,`notifications`,`campaigns` from physicians join cont_pref on contact_pref = ct_id join custlistsus on (memberuid = ph_id) where '.
"owneruid=$UUID and listid=$lid";
$res = $db->query($sql);
if( $res && $res->num_rows ) {
header('Content-type: text/plain');
header('Content-Disposition: attachment; filename="'.$filename.'"');
$firstline = true;
for( $i=0; $i < $res->num_rows; $i++ ) {
// export
if( $firstline ) {
$firstline = false;
$row = $res->fetch_assoc();
$firstElem = true;
foreach( $row as $key => $value ) {
if( $firstElem ) $firstElem = false;
else echo ',';
echo '"'.stripslashes($key).'"';
}
echo "\r\n"; // windows style is always ok
}
else $row = $res->fetch_row();
$firstElem = true;
foreach( $row as $value ) {
if( $firstElem ) $firstElem = false;
else echo ',';
$value = str_replace("\r\n"," ",$value);
if( $key == "zip" || $key == "ofzip" ) echo "\"'".stripslashes($value).'"';
else echo '"'.stripslashes($value).'"';
}
echo "\r\n"; // windows style is always ok
}
exit;
} else throw new Exception('No available records',__LINE__); // DEBUG?"$db->error : $sql":
} // L
elseif( $extype === 'V' && $ACCESS >=400 ) {
// V committed inactives (not)checkins
//$resdb = db_career();
$addsql = "";
if( !$_POST['inactives'] ) $addsql .= " and status=1 ";
if( !$_POST['checkins'] ) $addsql .= " and checkin=1 ";
if( !$_POST['already'] ) $addsql .= " and lastlogdate is null ";
$sql = "select `ph_id`,`fname`,`lname`,`email` from physicians where `email` is not null and inactive=0 and email_bounces=0 and newsletter=1 $addsql";
$res = $db->query($sql);
if( $res && $res->num_rows ) {
header('Content-type: text/plain');
header('Content-Disposition: attachment; filename="'.$filename.'"');
//$firstline = true;
for( $i=0; $i < $res->num_rows; $i++ ) {
// export
$row = $res->fetch_object();
$eml = $row->email;
$newt = time();
$hashlink = 'http://physiciancareer.com/login.php?i='.$row->ph_id
.'&d='.$newt.'&m='. sha1($row->ph_id.$row->fname.$row->lname.$newt.'Please let me in, I got this email - this is the secret code!');
echo stripslashes('"","","'.$row->fname.'","' .$row->lname. '","'.$hashlink.'","","","","","","","","","' .$eml. '","","","","","","","","",""' ."\r\n");
}
exit;
} else throw new Exception('No available records',__LINE__); // DEBUG?"$db->error : $sql":
} // V
elseif( $extype === 'W' && $ACCESS >=400 ) {
// W committed inactives (not)checkins
//$resdb = db_career();
$addsql = "";
if( !$_POST['inactives'] ) $addsql .= " and status=1 ";
if( !$_POST['checkins'] ) $addsql .= " and checkin=1 ";
if( !$_POST['already'] ) $addsql .= " and lastlogdate is null ";
$sql = "select `fname`,`lname`,`email` from physicians where `email` is not null and inactive=0 and email_bounces=0 and newsletter=1 $addsql";
$res = $db->query($sql);
if( $res && $res->num_rows ) {
header('Content-type: text/plain');
header('Content-Disposition: attachment; filename="'.$filename.'"');
//$firstline = true;
for( $i=0; $i < $res->num_rows; $i++ ) {
// export
$row = $res->fetch_object();
$eml = $row->email;
$newt = time();
echo stripslashes('"'.$row->lname.', ' .$row->fname. '" <'.$eml.'>'."\r\n");
}
exit;
} else throw new Exception('No available records',__LINE__); // DEBUG?"$db->error : $sql":
} // W
}
else {
$sql = "select listid,name,description from custlistdesc where uid = $UUID and `year`=2005 order by name";
$lists = $db->query($sql);
}
}
catch(Exception $e) {
$mesg = "Request failed: ".$e->getMessage().' ('.$e->getCode().')<br>';
}
$style = new OperPage('Data Export',$UUID,'reports','export');
$scrip = "<script language=\"JavaScript\" type=\"text/JavaScript\"><!--\r\nfunction selRadio(elem) {\r\n".
" document.getElementById(elem).checked = true;\r\n return true;\r\n}\r\n// -->\r\n</script>\r\n";
$style->Output($scrip);
if( $UUID ) {
if( $ACCESS < 200 ) echo '<h1>Access Denied</h1>';
else {
?>
<h1>Data Export</h1>
<?php
if( $mesg ) echo "<p id='error_msg'>$mesg</p>";
?>
<p>Export Customer List, Export list for customers, and the whole Residents DB into a CSV file, depending of the access level.<br>
Export residents from your custom lists (in the form of the Export List, choice two below)..</p>
<div id="formdiv">
<form action="export.php" method="post" name="formex" id="formex">
<p>Select Export type:
<br>
<?php if( $ACCESS >= 300 ) { // acct manager
?>
<input name="extype" type="radio" id="excust" value="C">
Customers
<input name="masters" type="checkbox" id="masters" value="1" checked onClick="selRadio('excust')">
only master accounts<br>
<?php }
?>
<input name="extype" type="radio" id="exsave" value="L">
Custom/Saved list:
<select name="exlist" id="exlist" onClick="selRadio('exsave')">
<?php
$clo = '';
for( $i=0; $lists && $i < $lists->num_rows; $i++ ) {
list($lid,$name,$desc) = $lists->fetch_row();
$desc = substr($desc,0,40);
$clo .= "<option value='$lid'>$name ($desc)</option>";
echo "<option value='$lid'>$name ($desc)</option>";
}
?>
</select>
<br>
<?php if( $ACCESS >= 400 ) {
?>
<input name="extype" type="radio" id="exsave2" value="V">
List for PC Nudge: (+options, see below)
<br>
<input name="extype" type="radio" id="exsave2" value="W">
List for PC Newsletter: (+options, see below)
<br>
<?php }
if( $ACCESS >= 200 ) { // cust serv
?>
<input name="extype" type="radio" id="exexp" value="E">
List to send to a customer: (+options, see below)
<br>
Export type:
<label><input name="extypee" type="radio" value="M" checked>
Mail Merge</label>
<label><input name="extypee" type="radio" value="C">
Contact Information</label>
<?php if( $ACCESS >= 400 ) { ?>
<label><input name="extypee" type="radio" value="F">
Full File</label>
<?php } ?>
<br>
Contact Info:
<input name="ofaddr" type="checkbox" id="ofaddr" value="1">
Include Office Address
<input name="ofnohome" type="checkbox" id="ofnohome" value="1">
Exclude Home Address
<br>
<br>
Options:
<input name="inactives" type="checkbox" value="1"> +Inactive; <input name="checkins" type="checkbox" checked value="1"> +Private; <input name="already" type="checkbox" checked value="1">
+Logged-in;
<input name="subscribed" type="checkbox" value="1"> +Un-Subscribed
<br>
<br>
<?php } // cust serv
?>
Export File Name (optional):
<input name="filename" type="text" id="filename">
.CSV
<input type="submit" name="submit" value="Export">
</p>
</form>
</div>
<p>Import HMA Jobs: <a href="import-hma.php">Click here</a>.</p>
<p>Import HPP Jobs: <a href="import-hpp.php">Click here</a>.</p>
<p>Import Providence Jobs: <a href="import-providence.php">Click here</a>.</p>
<?php
} // ACCESS
}
else showLoginForm(); // UUID
$style->ShowFooter();
?>