1 // ----------------------------------------------------------------------------
2 // Copyright (C) 2014
3 //              David Freese, W1HKJ
4 //
5 // This file is part of flmsg
6 //
7 // flrig is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // flrig is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 // ----------------------------------------------------------------------------
20 
21 #include <stdlib.h>
22 #include <iostream>
23 #include <fstream>
24 #include <cstring>
25 #include <ctime>
26 #include <sys/types.h>
27 #include <sys/stat.h>
28 #include <stdio.h>
29 #include <errno.h>
30 
31 #include <FL/Fl.H>
32 #include <FL/Enumerations.H>
33 #include <FL/Fl_Window.H>
34 #include <FL/Fl_Button.H>
35 #include <FL/Fl_Group.H>
36 #include <FL/Fl_Sys_Menu_Bar.H>
37 #include <FL/x.H>
38 #include <FL/Fl_Help_Dialog.H>
39 #include <FL/Fl_Menu_Item.H>
40 #include <FL/Fl_File_Icon.H>
41 
42 #include "config.h"
43 #include "flmsg_config.h"
44 
45 #include "flmsg.h"
46 #include "templates.h"
47 #include "debug.h"
48 #include "util.h"
49 #include "gettext.h"
50 #include "flmsg_dialog.h"
51 #include "flinput2.h"
52 #include "date.h"
53 #include "calendar.h"
54 #include "icons.h"
55 #include "fileselect.h"
56 #include "wrap.h"
57 #include "status.h"
58 #include "parse_xml.h"
59 
60 #ifdef WIN32
61 #  include "flmsgrc.h"
62 #  include "compat.h"
63 #  define dirent fl_dirent_no_thanks
64 #endif
65 
66 #include <FL/filename.H>
67 #include "dirent-check.h"
68 
69 #include <FL/x.H>
70 #include <FL/Fl_Pixmap.H>
71 #include <FL/Fl_Image.H>
72 
73 using namespace std;
74 
75 // hics206 tag fields
76 string h206_tag_name =					":1:";
77 string h206_tag_date_prepared =			":2:";
78 string h206_tag_time_prepared =			":3:";
79 string h206_tag_period =				":4:";
80 
81 string h206_tag_location =				":5:";
82 string h206_tag_loc_contact =			":6:";
83 string h206_tag_team_leader =			":7:";
84 string h206_tag_team_contact =			":8:";
85 string h206_tag_special_instructions =	":9:";
86 
87 string h206_tag_md_do =					":10:";
88 string h206_tag_litters =				":11:";
89 string h206_tag_pa_np =					":14:";
90 string h206_tag_portable =				":15:";
91 string h206_tag_rn_lpn =				":18:";
92 string h206_tag_transport =				":19:";
93 string h206_tag_tech_cn =				":22:";
94 string h206_tag_wheelchairs =			":23:";
95 string h206_tag_team_other =			":26:";
96 string h206_tag_transport_other =		":27:";
97 
98 string h206_tag_meds_1 = 				":12:";
99 string h206_tag_meds_2 = 				":16:";
100 string h206_tag_meds_3 = 				":20:";
101 string h206_tag_meds_4 = 				":24:";
102 string h206_tag_meds_5 = 				":28:";
103 string h206_tag_supp_1 = 				":13:";
104 string h206_tag_supp_2 = 				":17:";
105 string h206_tag_supp_3 = 				":21:";
106 string h206_tag_supp_4 = 				":25:";
107 string h206_tag_supp_5 = 				":29:";
108 
109 string h206_tag_site_1 =				":30:";
110 string h206_tag_address_1 =				":31:";
111 string h206_tag_phone_1 =				":32:";
112 string h206_tag_spec_care_1 =			":33:";
113 
114 string h206_tag_site_2 =				":34:";
115 string h206_tag_address_2 =				":35:";
116 string h206_tag_phone_2 =				":36:";
117 string h206_tag_spec_care_2 =			":37:";
118 
119 string h206_tag_site_3 =				":38:";
120 string h206_tag_address_3 =				":39:";
121 string h206_tag_phone_3 =				":40:";
122 string h206_tag_spec_care_3 =			":41:";
123 
124 string h206_tag_site_4 =				":42:";
125 string h206_tag_address_4 =				":43:";
126 string h206_tag_phone_4 =				":44:";
127 string h206_tag_spec_care_4 =			":45:";
128 
129 string h206_tag_preparer =				":46:";
130 string h206_tag_facility =				":47:";
131 
132 string h206_name;
133 string h206_period;
134 string h206_date_prepared;
135 string h206_time_prepared;
136 
137 string h206_location;
138 string h206_loc_contact;
139 string h206_team_leader;
140 string h206_team_contact;
141 string h206_special_instructions;
142 
143 string h206_md_do;
144 string h206_litters;
145 string h206_pa_np;
146 string h206_portable;
147 string h206_rn_lpn;
148 string h206_transport;
149 string h206_tech_cn;
150 string h206_wheelchairs;
151 string h206_team_other;
152 string h206_transport_other;
153 
154 string h206_meds_1;
155 string h206_meds_2;
156 string h206_meds_3;
157 string h206_meds_4;
158 string h206_meds_5;
159 string h206_supp_1;
160 string h206_supp_2;
161 string h206_supp_3;
162 string h206_supp_4;
163 string h206_supp_5;
164 
165 string h206_site_1;
166 string h206_address_1;
167 string h206_phone_1;
168 string h206_spec_care_1;
169 string h206_site_2;
170 string h206_address_2;
171 string h206_phone_2;
172 string h206_spec_care_2;
173 string h206_site_3;
174 string h206_address_3;
175 string h206_phone_3;
176 string h206_spec_care_3;
177 string h206_site_4;
178 string h206_address_4;
179 string h206_phone_4;
180 string h206_spec_care_4;
181 
182 string h206_preparer;
183 string h206_facility;
184 
185 string h206_buff;
186 string h206_def_filename = "";
187 string h206_base_filename = "";
188 string h206_def_template_name = "";
189 bool   h206_using206_template = false;
190 
h206_cb_setdate()191 void h206_cb_setdate()
192 {
193 	h206_txt_date_prepared->value(szDate(progStatus.dtformat));
194 }
195 
h206_cb_settime()196 void h206_cb_settime()
197 {
198 	h206_txt_time_prepared->value(szTime(progStatus.UTC));
199 }
200 
h206_clear_fields()201 void h206_clear_fields()
202 {
203 	h206_name.clear();
204 	h206_period.clear();
205 	h206_date_prepared.clear();
206 	h206_time_prepared.clear();
207 
208 	h206_location.clear();
209 	h206_loc_contact.clear();
210 	h206_team_leader.clear();
211 	h206_team_contact.clear();
212 
213 	h206_md_do.clear();
214 	h206_litters.clear();
215 	h206_pa_np.clear();
216 	h206_portable.clear();
217 	h206_rn_lpn.clear();
218 	h206_transport.clear();
219 	h206_tech_cn.clear();
220 	h206_wheelchairs.clear();
221 	h206_team_other.clear();
222 	h206_transport_other.clear();
223 	h206_meds_1.clear();
224 	h206_supp_1.clear();
225 	h206_meds_2.clear();
226 	h206_supp_2.clear();
227 	h206_meds_3.clear();
228 	h206_supp_3.clear();
229 	h206_meds_4.clear();
230 	h206_supp_4.clear();
231 	h206_meds_5.clear();
232 	h206_supp_5.clear();
233 
234 	h206_special_instructions.clear();
235 	h206_preparer.clear();
236 	h206_facility.clear();
237 
238 	h206_site_1.clear();
239 	h206_address_1.clear();
240 	h206_phone_1.clear();
241 	h206_spec_care_1.clear();
242 	h206_site_2.clear();
243 	h206_address_2.clear();
244 	h206_phone_2.clear();
245 	h206_spec_care_2.clear();
246 	h206_site_3.clear();
247 	h206_address_3.clear();
248 	h206_phone_3.clear();
249 	h206_spec_care_3.clear();
250 	h206_site_4.clear();
251 	h206_address_4.clear();
252 	h206_phone_4.clear();
253 	h206_spec_care_4.clear();
254 
255 }
256 
check_hics206fields()257 bool check_hics206fields()
258 {
259 	if (h206_name != h206_txt_name->value())
260 		return true;
261 	if (h206_period != h206_txt_op_period->value())
262 		return true;
263 	if (h206_date_prepared != h206_txt_date_prepared->value())
264 		return true;
265 	if (h206_time_prepared != h206_txt_time_prepared->value())
266 		return true;
267 
268 	if (h206_location != h206_txt_location->value())
269 		return true;
270 	if (h206_loc_contact != h206_txt_loc_contact->value())
271 		return true;
272 	if (h206_team_leader != h206_txt_team_leader->value())
273 		return true;
274 	if (h206_team_contact != h206_txt_team_contact->value())
275 		return true;
276 	if (h206_md_do != h206_txt_md_do->value())
277 		return true;
278 	if (h206_litters != h206_txt_litters->value())
279 		return true;
280 	if (h206_pa_np != h206_txt_pa_np->value())
281 		return true;
282 	if (h206_portable != h206_txt_portable->value())
283 		return true;
284 	if (h206_rn_lpn != h206_txt_rn_lpn->value())
285 		return true;
286 	if (h206_transport != h206_txt_transport->value())
287 		return true;
288 	if (h206_tech_cn != h206_txt_tech_cn->value())
289 		return true;
290 	if (h206_wheelchairs != h206_txt_wheelchairs->value())
291 		return true;
292 	if (h206_team_other != h206_txt_team_other->value())
293 		return true;
294 	if (h206_transport_other != h206_txt_transport_other->value())
295 		return true;
296 	if (h206_meds_1 != h206_txt_meds_1->value())
297 		return true;
298 	if (h206_supp_1 != h206_txt_supp_1->value())
299 		return true;
300 	if (h206_meds_2 != h206_txt_meds_2->value())
301 		return true;
302 	if (h206_supp_2 != h206_txt_supp_2->value())
303 		return true;
304 	if (h206_meds_3 != h206_txt_meds_3->value())
305 		return true;
306 	if (h206_supp_3 != h206_txt_supp_3->value())
307 		return true;
308 	if (h206_meds_4 != h206_txt_meds_4->value())
309 		return true;
310 	if (h206_supp_4 != h206_txt_supp_4->value())
311 		return true;
312 	if (h206_meds_5 != h206_txt_meds_5->value())
313 		return true;
314 	if (h206_supp_5 != h206_txt_supp_5->value())
315 		return true;
316 
317 	if (h206_special_instructions != h206_txt_special_instructions->buffer()->text())
318 		return true;
319 
320 	if (h206_preparer != h206_txt_preparer->value())
321 		return true;
322 	if (h206_facility != h206_txt_facility->value())
323 		return true;
324 
325 	if (h206_site_1 != h206_txt_site_1->value())
326 		return true;
327 	if (h206_address_1 != h206_txt_address_1->value())
328 		return true;
329 	if (h206_phone_1 != h206_txt_phone_1->value())
330 		return true;
331 	if (h206_spec_care_1 != h206_txt_spec_care_1->value())
332 		return true;
333 	if (h206_site_2 != h206_txt_site_2->value())
334 		return true;
335 	if (h206_address_2 != h206_txt_address_2->value())
336 		return true;
337 	if (h206_phone_2 != h206_txt_phone_2->value())
338 		return true;
339 	if (h206_spec_care_2 != h206_txt_spec_care_2->value())
340 		return true;
341 	if (h206_site_3 != h206_txt_site_3->value())
342 		return true;
343 	if (h206_address_3 != h206_txt_address_3->value())
344 		return true;
345 	if (h206_phone_3 != h206_txt_phone_3->value())
346 		return true;
347 	if (h206_spec_care_3 != h206_txt_spec_care_3->value())
348 		return true;
349 	if (h206_site_4 != h206_txt_site_4->value())
350 		return true;
351 	if (h206_address_4 != h206_txt_address_4->value())
352 		return true;
353 	if (h206_phone_4 != h206_txt_phone_4->value())
354 		return true;
355 	if (h206_spec_care_4 != h206_txt_spec_care_4->value())
356 		return true;
357 
358 	return false;
359 }
360 
h206_update_fields()361 void h206_update_fields()
362 {
363 	h206_name = h206_txt_name->value();
364 	h206_period = h206_txt_op_period->value();
365 	h206_date_prepared = h206_txt_date_prepared->value();
366 	h206_time_prepared = h206_txt_time_prepared->value();
367 
368 	h206_location = h206_txt_location->value();
369 	h206_loc_contact = h206_txt_loc_contact->value();
370 	h206_team_leader = h206_txt_team_leader->value();
371 	h206_team_contact = h206_txt_team_contact->value();
372 	h206_md_do = h206_txt_md_do->value();
373 	h206_litters = h206_txt_litters->value();
374 	h206_pa_np = h206_txt_pa_np->value();
375 	h206_portable = h206_txt_portable->value();
376 	h206_rn_lpn = h206_txt_rn_lpn->value();
377 	h206_transport = h206_txt_transport->value();
378 	h206_tech_cn = h206_txt_tech_cn->value();
379 	h206_wheelchairs = h206_txt_wheelchairs->value();
380 	h206_team_other = h206_txt_team_other->value();
381 	h206_transport_other = h206_txt_transport_other->value();
382 	h206_meds_1 = h206_txt_meds_1->value();
383 	h206_supp_1 = h206_txt_supp_1->value();
384 	h206_meds_2 = h206_txt_meds_2->value();
385 	h206_supp_2 = h206_txt_supp_2->value();
386 	h206_meds_3 = h206_txt_meds_3->value();
387 	h206_supp_3 = h206_txt_supp_3->value();
388 	h206_meds_4 = h206_txt_meds_4->value();
389 	h206_supp_4 = h206_txt_supp_4->value();
390 	h206_meds_5 = h206_txt_meds_5->value();
391 	h206_supp_5 = h206_txt_supp_5->value();
392 
393 	h206_special_instructions = h206_txt_special_instructions->buffer()->text();
394 
395 	h206_preparer = h206_txt_preparer->value();
396 	h206_facility = h206_txt_facility->value();
397 
398 	h206_site_1 = h206_txt_site_1->value();
399 	h206_address_1 = h206_txt_address_1->value();
400 	h206_phone_1 = h206_txt_phone_1->value();
401 	h206_spec_care_1 = h206_txt_spec_care_1->value();
402 	h206_site_2 = h206_txt_site_2->value();
403 	h206_address_2 = h206_txt_address_2->value();
404 	h206_phone_2 = h206_txt_phone_2->value();
405 	h206_spec_care_2 = h206_txt_spec_care_2->value();
406 	h206_site_3 = h206_txt_site_3->value();
407 	h206_address_3 = h206_txt_address_3->value();
408 	h206_phone_3 = h206_txt_phone_3->value();
409 	h206_spec_care_3 = h206_txt_spec_care_3->value();
410 	h206_site_4 = h206_txt_site_4->value();
411 	h206_address_4 = h206_txt_address_4->value();
412 	h206_phone_4 = h206_txt_phone_4->value();
413 	h206_spec_care_4 = h206_txt_spec_care_4->value();
414 }
415 
h206_update_form()416 void h206_update_form()
417 {
418 	h206_txt_name->value(h206_name.c_str());
419 	h206_txt_op_period->value(h206_period.c_str());
420 	h206_txt_date_prepared->value(h206_date_prepared.c_str());
421 	h206_txt_time_prepared->value(h206_time_prepared.c_str());
422 
423 	h206_txt_location->value(h206_location.c_str());
424 	h206_txt_loc_contact->value(h206_loc_contact.c_str());
425 	h206_txt_team_leader->value(h206_team_leader.c_str());
426 	h206_txt_team_contact->value(h206_team_contact.c_str());
427 
428 	h206_txt_md_do->value(h206_md_do.c_str());
429 	h206_txt_litters->value(h206_litters.c_str());
430 	h206_txt_pa_np->value(h206_pa_np.c_str());
431 	h206_txt_portable->value(h206_portable.c_str());
432 	h206_txt_rn_lpn->value(h206_rn_lpn.c_str());
433 	h206_txt_transport->value(h206_transport.c_str());
434 	h206_txt_tech_cn->value(h206_tech_cn.c_str());
435 	h206_txt_wheelchairs->value(h206_wheelchairs.c_str());
436 	h206_txt_team_other->value(h206_team_other.c_str());
437 	h206_txt_transport_other->value(h206_transport_other.c_str());
438 	h206_txt_meds_1->value(h206_meds_1.c_str());
439 	h206_txt_supp_1->value(h206_supp_1.c_str());
440 	h206_txt_meds_2->value(h206_meds_2.c_str());
441 	h206_txt_supp_2->value(h206_supp_2.c_str());
442 	h206_txt_meds_3->value(h206_meds_3.c_str());
443 	h206_txt_supp_3->value(h206_supp_3.c_str());
444 	h206_txt_meds_4->value(h206_meds_4.c_str());
445 	h206_txt_supp_4->value(h206_supp_4.c_str());
446 	h206_txt_meds_5->value(h206_meds_5.c_str());
447 	h206_txt_supp_5->value(h206_supp_5.c_str());
448 
449 	h206_txt_special_instructions->addstr(h206_special_instructions.c_str());
450 
451 	h206_txt_preparer->value(h206_preparer.c_str());
452 	h206_txt_facility->value(h206_facility.c_str());
453 
454 	h206_txt_site_1->value(h206_site_1.c_str());
455 	h206_txt_address_1->value(h206_address_1.c_str());
456 	h206_txt_phone_1->value(h206_phone_1.c_str());
457 	h206_txt_spec_care_1->value(h206_spec_care_1.c_str());
458 	h206_txt_site_2->value(h206_site_2.c_str());
459 	h206_txt_address_2->value(h206_address_2.c_str());
460 	h206_txt_phone_2->value(h206_phone_2.c_str());
461 	h206_txt_spec_care_2->value(h206_spec_care_2.c_str());
462 	h206_txt_site_3->value(h206_site_3.c_str());
463 	h206_txt_address_3->value(h206_address_3.c_str());
464 	h206_txt_phone_3->value(h206_phone_3.c_str());
465 	h206_txt_spec_care_3->value(h206_spec_care_3.c_str());
466 	h206_txt_site_4->value(h206_site_4.c_str());
467 	h206_txt_address_4->value(h206_address_4.c_str());
468 	h206_txt_phone_4->value(h206_phone_4.c_str());
469 	h206_txt_spec_care_4->value(h206_spec_care_4.c_str());
470 
471 }
472 
h206_clear__form()473 void h206_clear__form()
474 {
475 	h206_clear_fields();
476 
477 	h206_txt_name->value("");
478 	h206_txt_op_period->value("");
479 	h206_txt_date_prepared->value("");
480 	h206_txt_time_prepared->value("");
481 
482 	h206_txt_location->value("");
483 	h206_txt_loc_contact->value("");
484 	h206_txt_team_leader->value("");
485 	h206_txt_team_contact->value("");
486 
487 	h206_txt_md_do->value("");
488 	h206_txt_litters->value("");
489 	h206_txt_pa_np->value("");
490 	h206_txt_portable->value("");
491 	h206_txt_rn_lpn->value("");
492 	h206_txt_transport->value("");
493 	h206_txt_tech_cn->value("");
494 	h206_txt_wheelchairs->value("");
495 	h206_txt_team_other->value("");
496 	h206_txt_transport_other->value("");
497 	h206_txt_meds_1->value("");
498 	h206_txt_supp_1->value("");
499 	h206_txt_meds_2->value("");
500 	h206_txt_supp_2->value("");
501 	h206_txt_meds_3->value("");
502 	h206_txt_supp_3->value("");
503 	h206_txt_meds_4->value("");
504 	h206_txt_supp_4->value("");
505 	h206_txt_meds_5->value("");
506 	h206_txt_supp_5->value("");
507 
508 	h206_txt_special_instructions->clear();
509 
510 	h206_txt_preparer->value("");
511 	h206_txt_facility->value("");
512 
513 	h206_txt_site_1->value("");
514 	h206_txt_address_1->value("");
515 	h206_txt_phone_1->value("");
516 	h206_txt_spec_care_1->value("");
517 	h206_txt_site_2->value("");
518 	h206_txt_address_2->value("");
519 	h206_txt_phone_2->value("");
520 	h206_txt_spec_care_2->value("");
521 	h206_txt_site_3->value("");
522 	h206_txt_address_3->value("");
523 	h206_txt_phone_3->value("");
524 	h206_txt_spec_care_3->value("");
525 	h206_txt_site_4->value("");
526 	h206_txt_address_4->value("");
527 	h206_txt_phone_4->value("");
528 	h206_txt_spec_care_4->value("");
529 
530 }
531 
h206_make_buff(bool compress=false)532 void h206_make_buff(bool compress = false)
533 {
534 	string mbuff;
535 	mbuff.assign( lineout( h206_tag_name, h206_name ) );
536 	mbuff.append( lineout( h206_tag_period, h206_period ) );
537 	mbuff.append( lineout( h206_tag_date_prepared, h206_date_prepared ) );
538 	mbuff.append( lineout( h206_tag_time_prepared, h206_time_prepared ) );
539 
540 	mbuff.append( lineout( h206_tag_location, h206_location));
541 	mbuff.append( lineout( h206_tag_loc_contact, h206_loc_contact));
542 	mbuff.append( lineout( h206_tag_team_leader, h206_team_leader));
543 	mbuff.append( lineout( h206_tag_team_contact, h206_team_contact));
544 
545 	mbuff.append( lineout( h206_tag_md_do, h206_md_do));
546 	mbuff.append( lineout( h206_tag_litters, h206_litters));
547 	mbuff.append( lineout( h206_tag_pa_np, h206_pa_np));
548 	mbuff.append( lineout( h206_tag_portable, h206_portable));
549 	mbuff.append( lineout( h206_tag_rn_lpn, h206_rn_lpn));
550 	mbuff.append( lineout( h206_tag_transport, h206_transport));
551 	mbuff.append( lineout( h206_tag_tech_cn, h206_tech_cn));
552 	mbuff.append( lineout( h206_tag_wheelchairs, h206_wheelchairs));
553 	mbuff.append( lineout( h206_tag_team_other, h206_team_other));
554 	mbuff.append( lineout( h206_tag_transport_other, h206_transport_other));
555 	mbuff.append( lineout( h206_tag_meds_1, h206_meds_1));
556 	mbuff.append( lineout( h206_tag_supp_1, h206_supp_1));
557 	mbuff.append( lineout( h206_tag_meds_2, h206_meds_2));
558 	mbuff.append( lineout( h206_tag_supp_2, h206_supp_2));
559 	mbuff.append( lineout( h206_tag_meds_3, h206_meds_3));
560 	mbuff.append( lineout( h206_tag_supp_3, h206_supp_3));
561 	mbuff.append( lineout( h206_tag_meds_4, h206_meds_4));
562 	mbuff.append( lineout( h206_tag_supp_4, h206_supp_4));
563 	mbuff.append( lineout( h206_tag_meds_5, h206_meds_5));
564 	mbuff.append( lineout( h206_tag_supp_5, h206_supp_5));
565 
566 	mbuff.append( lineout( h206_tag_special_instructions, h206_special_instructions ) );
567 
568 	mbuff.append( lineout( h206_tag_preparer, h206_preparer ) );
569 	mbuff.append( lineout( h206_tag_facility, h206_facility ) );
570 
571 	mbuff.append( lineout( h206_tag_site_1, h206_site_1 ) );
572 	mbuff.append( lineout( h206_tag_address_1, h206_address_1 ) );
573 	mbuff.append( lineout( h206_tag_phone_1, h206_phone_1 ) );
574 	mbuff.append( lineout( h206_tag_spec_care_1, h206_spec_care_1 ) );
575 	mbuff.append( lineout( h206_tag_site_2, h206_site_2 ) );
576 	mbuff.append( lineout( h206_tag_address_2, h206_address_2 ) );
577 	mbuff.append( lineout( h206_tag_phone_2, h206_phone_2 ) );
578 	mbuff.append( lineout( h206_tag_spec_care_2, h206_spec_care_2 ) );
579 	mbuff.append( lineout( h206_tag_site_3, h206_site_3 ) );
580 	mbuff.append( lineout( h206_tag_address_3, h206_address_3 ) );
581 	mbuff.append( lineout( h206_tag_phone_3, h206_phone_3 ) );
582 	mbuff.append( lineout( h206_tag_spec_care_3, h206_spec_care_3 ) );
583 	mbuff.append( lineout( h206_tag_site_4, h206_site_4 ) );
584 	mbuff.append( lineout( h206_tag_address_4, h206_address_4 ) );
585 	mbuff.append( lineout( h206_tag_phone_4, h206_phone_4 ) );
586 	mbuff.append( lineout( h206_tag_spec_care_4, h206_spec_care_4 ) );
587 
588 	if (compress) compress_maybe(mbuff);
589 	h206_buff.append(mbuff);
590 }
591 
h206_read_buffer(string data)592 void h206_read_buffer(string data)
593 {
594 	h206_clear_fields();
595 	read_header(data);
596 
597 	h206_name = findstr(data, h206_tag_name);
598 	h206_period = findstr(data, h206_tag_period);
599 	h206_date_prepared = findstr(data, h206_tag_date_prepared);
600 	h206_time_prepared = findstr(data, h206_tag_time_prepared);
601 
602 	h206_location = findstr(data, h206_tag_location);
603 	h206_loc_contact = findstr(data, h206_tag_loc_contact);
604 	h206_team_leader = findstr(data, h206_tag_team_leader);
605 	h206_team_contact = findstr(data, h206_tag_team_contact);
606 
607 	h206_md_do = findstr(data, h206_tag_md_do);
608 	h206_litters = findstr(data, h206_tag_litters);
609 	h206_pa_np = findstr(data, h206_tag_pa_np);
610 	h206_portable = findstr(data, h206_tag_portable);
611 	h206_rn_lpn = findstr(data, h206_tag_rn_lpn);
612 	h206_transport = findstr(data, h206_tag_transport);
613 	h206_tech_cn = findstr(data, h206_tag_tech_cn);
614 	h206_wheelchairs = findstr(data, h206_tag_wheelchairs);
615 	h206_team_other = findstr(data, h206_tag_team_other);
616 	h206_transport_other = findstr(data, h206_tag_transport_other);
617 	h206_meds_1 = findstr(data, h206_tag_meds_1);
618 	h206_supp_1 = findstr(data, h206_tag_supp_1);
619 	h206_meds_2 = findstr(data, h206_tag_meds_2);
620 	h206_supp_2 = findstr(data, h206_tag_supp_2);
621 	h206_meds_3 = findstr(data, h206_tag_meds_3);
622 	h206_supp_3 = findstr(data, h206_tag_supp_3);
623 	h206_meds_4 = findstr(data, h206_tag_meds_4);
624 	h206_supp_4 = findstr(data, h206_tag_supp_4);
625 	h206_meds_5 = findstr(data, h206_tag_meds_5);
626 	h206_supp_5 = findstr(data, h206_tag_supp_5);
627 
628 	h206_special_instructions = findstr(data, h206_tag_special_instructions);
629 
630 	h206_preparer = findstr(data, h206_tag_preparer);
631 	h206_facility = findstr(data, h206_tag_facility);
632 
633 	h206_site_1 = findstr(data, h206_tag_site_1);
634 	h206_address_1 = findstr(data, h206_tag_address_1);
635 	h206_phone_1 = findstr(data, h206_tag_phone_1);
636 	h206_spec_care_1 = findstr(data, h206_tag_spec_care_1);
637 	h206_site_2 = findstr(data, h206_tag_site_2);
638 	h206_address_2 = findstr(data, h206_tag_address_2);
639 	h206_phone_2 = findstr(data, h206_tag_phone_2);
640 	h206_spec_care_2 = findstr(data, h206_tag_spec_care_2);
641 	h206_site_3 = findstr(data, h206_tag_site_3);
642 	h206_address_3 = findstr(data, h206_tag_address_3);
643 	h206_phone_3 = findstr(data, h206_tag_phone_3);
644 	h206_spec_care_3 = findstr(data, h206_tag_spec_care_4);
645 	h206_site_4 = findstr(data, h206_tag_site_4);
646 	h206_address_4 = findstr(data, h206_tag_address_4);
647 	h206_phone_4 = findstr(data, h206_tag_phone_4);
648 	h206_spec_care_4 = findstr(data, h206_tag_spec_care_4);
649 
650 	h206_update_form();
651 }
652 
h206_cb_new()653 void h206_cb_new()
654 {
655 	if (check_hics206fields()) {
656 		if (fl_choice2("Form modified, save?", "No", "Yes", NULL) == 1) {
657 			update_header(CHANGED);
658 			h206_cb_save();
659 		}
660 	}
661 	h206_clear__form();
662 	clear_header();
663 	h206_def_filename = ICS_msg_dir;
664 	h206_def_filename.append("new").append(HF206_EXT);
665 	show_filename(h206_def_filename);
666 	h206_using206_template = false;
667 }
668 
h206_cb_import()669 void h206_cb_import()
670 {
671 	fl_alert2("Not implemented");
672 }
673 
h206_cb_export()674 void h206_cb_export()
675 {
676 	fl_alert2("Not implemented");
677 }
678 
h206_cb_wrap_import(string wrapfilename,string inpbuffer)679 void h206_cb_wrap_import(string wrapfilename, string inpbuffer)
680 {
681 	h206_clear__form();
682 	h206_read_buffer(inpbuffer);
683 	h206_def_filename = ICS_msg_dir;
684 	h206_def_filename.append(wrapfilename);
685 	show_filename(h206_def_filename);
686 	h206_using206_template = false;
687 }
688 
eval_h206_fsize()689 int eval_h206_fsize()
690 {
691 	Ccrc16 chksum;
692 	evalstr.assign("[WRAP:beg][WRAP:lf][WRAP:fn ");
693 	evalstr.append(h206_base_filename).append("]");
694 	h206_update_fields();
695 	update_header(FROM);
696 	evalstr.append(header("<hics206>"));
697 	h206_buff.clear();
698 	h206_make_buff(true);
699 	if (h206_buff.empty()) return 0;
700 	compress_maybe( h206_buff );
701 	evalstr.append( h206_buff );
702 	evalstr.append("[WRAP:chksum ").append(chksum.scrc16(evalstr)).append("][WRAP:end]");
703 	return evalstr.length();
704 }
705 
h206_cb_wrap_export()706 void h206_cb_wrap_export()
707 {
708 	if (check_hics206fields()) {
709 		if (fl_choice2("Form modified, save?", "No", "Yes", NULL) == 0)
710 			return;
711 		update_header(CHANGED);
712 	}
713 	h206_update_fields();
714 
715 	if (h206_base_filename == string("new").append(HF206_EXT) ||
716 		h206_base_filename == string("default").append(HF206_EXT) )
717 		if (!h206_cb_save_as()) return;
718 
719 	string wrapfilename = WRAP_send_dir;
720 	wrapfilename.append(h206_base_filename);
721 	wrapfilename.append(".wrap");
722 	const char *p = FSEL::saveas(
723 			"Save as wrap file",
724 			"Wrap file\t*.{wrap,WRAP}",
725 			wrapfilename.c_str());
726 	if (p) {
727 		string pext = fl_filename_ext(p);
728 		wrapfilename = p;
729 		update_header(FROM);
730 		h206_buff.assign(header("<hics206>"));
731 		h206_make_buff(true);
732 		export_wrapfile(h206_base_filename, wrapfilename, h206_buff, pext != ".wrap");
733 
734 		h206_buff.assign(header("<hics206>"));
735 		h206_make_buff(false);
736 		h206_write(h206_def_filename);
737 	}
738 }
739 
h206_cb_wrap_autosend()740 void h206_cb_wrap_autosend()
741 {
742 	if (check_hics206fields()) {
743 		if (fl_choice2("Form modified, save?", "No", "Yes", NULL) == 0)
744 			return;
745 		update_header(CHANGED);
746 	}
747 	h206_update_fields();
748 
749 	if (h206_base_filename == string("new").append(HF206_EXT) ||
750 		h206_base_filename == string("default").append(HF206_EXT) )
751 		if (!h206_cb_save_as()) return;
752 
753 	update_header(FROM);
754 	h206_buff.assign(header("<hics206>"));
755 	h206_make_buff(true);
756 	xfr_via_socket(h206_base_filename, h206_buff);
757 
758 	h206_buff.assign(header("<hics206>"));
759 	h206_make_buff(false);
760 	h206_write(h206_def_filename);
761 }
762 
h206_cb_load_template()763 void h206_cb_load_template()
764 {
765 	string h206_def_filename = h206_def_template_name;
766 	const char *p = FSEL::select(
767 			"Open template file",
768 			std::string("Template file\t*").append(HT206_EXT).c_str(),
769 			h206_def_filename.c_str());
770 	if (p) {
771 		h206_clear__form();
772 		read_data_file(p);
773 		h206_def_template_name = p;
774 		show_filename(h206_def_template_name);
775 		h206_using206_template = true;
776 	}
777 }
778 
h206_cb_save_template()779 void h206_cb_save_template()
780 {
781 	if (!h206_using206_template) {
782 		h206_cb_save_as_template();
783 		return;
784 	}
785 	string h206_def_filename = h206_def_template_name;
786 	const char *p = FSEL::saveas(
787 			"Save template file",
788 			std::string("Template file\t*").append(HT206_EXT).c_str(),
789 			h206_def_filename.c_str());
790 	if (p) {
791 		update_header(CHANGED);
792 		h206_update_fields();
793 		h206_buff.assign(header("<hics206>"));
794 		h206_make_buff();
795 		h206_write(p);
796 	}
797 }
798 
h206_cb_save_as_template()799 void h206_cb_save_as_template()
800 {
801 	string h206_def_filename = h206_def_template_name;
802 	const char *p = FSEL::saveas(
803 			"Save as template file",
804 			std::string("Template file\t*").append(HT206_EXT).c_str(),
805 			h206_def_filename.c_str());
806 	if (p) {
807 		const char *pext = fl_filename_ext(p);
808 		h206_def_template_name = p;
809 		if (strlen(pext) == 0) h206_def_template_name.append(HT206_EXT);
810 		remove_spaces_from_filename(h206_def_template_name);
811 		clear_header();
812 		update_header(CHANGED);
813 		h206_update_fields();
814 		h206_buff.assign(header("<hics206>"));
815 		h206_make_buff();
816 		h206_write(h206_def_template_name);
817 		show_filename(h206_def_template_name);
818 		h206_using206_template = true;
819 	}
820 }
821 
h206_cb_open()822 void h206_cb_open()
823 {
824 	const char *p = FSEL::select(
825 			_("Open data file"),
826 			string("HICS-206\t*").append(HF206_EXT).c_str(),
827 			h206_def_filename.c_str());
828 	if (!p) return;
829 	if (strlen(p) == 0) return;
830 	h206_clear__form();
831 	read_data_file(p);
832 	h206_using206_template = false;
833 	h206_def_filename = p;
834 	show_filename(h206_def_filename);
835 }
836 
h206_write(string s)837 void h206_write(string s)
838 {
839 	FILE *file206 = fopen(s.c_str(), "w");
840 	if (!file206) return;
841 
842 	fwrite(h206_buff.c_str(), h206_buff.length(), 1, file206);
843 	fclose(file206);
844 }
845 
h206_cb_save_as()846 bool h206_cb_save_as()
847 {
848 	const char *p;
849 	string newfilename;
850 
851 	string name = named_file();
852 	if (!name.empty()) {
853 		name.append(HF206_EXT);
854 		newfilename = ICS_msg_dir;
855 		newfilename.append(name);
856 	} else
857 		newfilename = h206_def_filename;
858 
859 	p = FSEL::saveas(
860 			_("Save data file"),
861 			string("HICS-206\t*").append(HF206_EXT).c_str(),
862 			newfilename.c_str());
863 
864 	if (!p) return false;
865 	if (strlen(p) == 0) return false;
866 
867 	if (progStatus.sernbr_fname) update_sernbr();
868 
869 	const char *pext = fl_filename_ext(p);
870 	h206_def_filename = p;
871 	if (strlen(pext) == 0) h206_def_filename.append(HF206_EXT);
872 
873 	remove_spaces_from_filename(h206_def_filename);
874 	h206_update_fields();
875 	update_header(NEW);
876 	h206_buff.assign(header("<hics206>"));
877 	h206_write(h206_def_filename);
878 
879 	h206_using206_template = false;
880 	show_filename(h206_def_filename);
881 	return true;
882 }
883 
h206_cb_save()884 void h206_cb_save()
885 {
886 	if (h206_base_filename == string("new").append(HF206_EXT) ||
887 		h206_base_filename == string("default").append(HF206_EXT) ||
888 		h206_using206_template == true) {
889 		h206_cb_save_as();
890 		return;
891 	}
892 	if (check_hics206fields()) update_header(CHANGED);
893 	h206_buff.assign(header("<hics206>"));
894 	h206_make_buff();
895 	h206_write(h206_def_filename);
896 	h206_using206_template = false;
897 }
898 
h206_cb_html()899 void h206_cb_html()
900 {
901 	string fname_name = fl_filename_name(h206_def_filename.c_str());
902 	size_t p = fname_name.rfind('.');
903 	if (p != string::npos) fname_name.erase(p);
904 
905 	string hics206_fname = ICS_dir;
906 	hics206_fname.append(fname_name);
907 	hics206_fname.append(".html");
908 
909 	string html_text = "";
910 
911 	h206_update_fields();
912 	string form206 = hics206_html_template;
913 
914 	replacestr(form206, TITLE, fname_name);
915 	replacestr(form206, h206_tag_name, h206_name);
916 	replacestr(form206, h206_tag_date_prepared, h206_date_prepared);
917 	replacestr(form206, h206_tag_time_prepared, h206_time_prepared);
918 	replacestr(form206, h206_tag_period, h206_period);
919 
920 	replacestr(form206, h206_tag_location, h206_location);
921 	replacestr(form206, h206_tag_loc_contact, h206_loc_contact);
922 	replacestr(form206, h206_tag_team_leader, h206_team_leader);
923 	replacestr(form206, h206_tag_team_contact, h206_team_contact);
924 
925 	replacestr(form206, h206_tag_md_do, h206_md_do);
926 	replacestr(form206, h206_tag_litters, h206_litters);
927 	replacestr(form206, h206_tag_pa_np, h206_pa_np);
928 	replacestr(form206, h206_tag_portable, h206_portable);
929 	replacestr(form206, h206_tag_rn_lpn, h206_rn_lpn);
930 	replacestr(form206, h206_tag_transport, h206_transport);
931 	replacestr(form206, h206_tag_tech_cn, h206_tech_cn);
932 	replacestr(form206, h206_tag_wheelchairs, h206_wheelchairs);
933 	replacestr(form206, h206_tag_team_other, h206_team_other);
934 	replacestr(form206, h206_tag_transport_other, h206_transport_other);
935 	replacestr(form206, h206_tag_meds_1, h206_meds_1);
936 	replacestr(form206, h206_tag_supp_1, h206_supp_1);
937 	replacestr(form206, h206_tag_meds_2, h206_meds_2);
938 	replacestr(form206, h206_tag_supp_2, h206_supp_2);
939 	replacestr(form206, h206_tag_meds_3, h206_meds_3);
940 	replacestr(form206, h206_tag_supp_3, h206_supp_3);
941 	replacestr(form206, h206_tag_meds_4, h206_meds_4);
942 	replacestr(form206, h206_tag_supp_4, h206_supp_4);
943 	replacestr(form206, h206_tag_meds_5, h206_meds_5);
944 	replacestr(form206, h206_tag_supp_5, h206_supp_5);
945 	string temp = h206_special_instructions;
946 	if (progStatus.autowordwrap)
947 		temp = wordwrap(h206_special_instructions, progStatus.charcount);
948 	replacestr(form206, h206_tag_special_instructions, temp);
949 	replacestr(form206, h206_tag_site_1, h206_site_1);
950 	replacestr(form206, h206_tag_address_1, h206_address_1);
951 	replacestr(form206, h206_tag_phone_1, h206_phone_1);
952 	replacestr(form206, h206_tag_spec_care_1, h206_spec_care_1);
953 	replacestr(form206, h206_tag_site_2, h206_site_2);
954 	replacestr(form206, h206_tag_address_2, h206_address_2);
955 	replacestr(form206, h206_tag_phone_2, h206_phone_2);
956 	replacestr(form206, h206_tag_spec_care_2, h206_spec_care_2);
957 	replacestr(form206, h206_tag_site_3, h206_site_3);
958 	replacestr(form206, h206_tag_address_3, h206_address_3);
959 	replacestr(form206, h206_tag_phone_3, h206_phone_3);
960 	replacestr(form206, h206_tag_spec_care_3, h206_spec_care_3);
961 	replacestr(form206, h206_tag_site_4, h206_site_4);
962 	replacestr(form206, h206_tag_address_4, h206_address_4);
963 	replacestr(form206, h206_tag_phone_4, h206_phone_4);
964 	replacestr(form206, h206_tag_spec_care_4, h206_spec_care_4);
965 
966 	replacestr(form206, h206_tag_preparer, h206_preparer);
967 	replacestr(form206, h206_tag_facility, h206_facility);
968 
969 	FILE *file206 = fopen(hics206_fname.c_str(), "w");
970 	fprintf(file206,"%s", form206.c_str());
971 	fclose(file206);
972 
973 	open_url(hics206_fname.c_str());
974 }
975 
h206_cb_textout()976 void h206_cb_textout()
977 {
978 	string hics206_fname = ICS_dir;
979 	hics206_fname.append("hics206.txt");
980 
981 	h206_update_fields();
982 	string form206 = hics206_text_template;
983 
984 	replacestr(form206, h206_tag_name, h206_name);
985 	replacestr(form206, h206_tag_period, h206_period);
986 	replacestr(form206, h206_tag_date_prepared, h206_date_prepared);
987 	replacestr(form206, h206_tag_time_prepared, h206_time_prepared);
988 
989 	replacestr(form206, h206_tag_location, h206_location);
990 	replacestr(form206, h206_tag_loc_contact, h206_loc_contact);
991 	replacestr(form206, h206_tag_team_leader, h206_team_leader);
992 	replacestr(form206, h206_tag_team_contact, h206_team_contact);
993 
994 	replacestr(form206, h206_tag_md_do, h206_md_do);
995 	replacestr(form206, h206_tag_litters, h206_litters);
996 	replacestr(form206, h206_tag_pa_np, h206_pa_np);
997 	replacestr(form206, h206_tag_portable, h206_portable);
998 	replacestr(form206, h206_tag_rn_lpn, h206_rn_lpn);
999 	replacestr(form206, h206_tag_transport, h206_transport);
1000 	replacestr(form206, h206_tag_tech_cn, h206_tech_cn);
1001 	replacestr(form206, h206_tag_wheelchairs, h206_wheelchairs);
1002 	replacestr(form206, h206_tag_team_other, h206_team_other);
1003 	replacestr(form206, h206_tag_transport_other, h206_transport_other);
1004 	replacestr(form206, h206_tag_meds_1, h206_meds_1);
1005 	replacestr(form206, h206_tag_supp_1, h206_supp_1);
1006 	replacestr(form206, h206_tag_meds_2, h206_meds_2);
1007 	replacestr(form206, h206_tag_supp_2, h206_supp_2);
1008 	replacestr(form206, h206_tag_meds_3, h206_meds_3);
1009 	replacestr(form206, h206_tag_supp_3, h206_supp_3);
1010 	replacestr(form206, h206_tag_meds_4, h206_meds_4);
1011 	replacestr(form206, h206_tag_supp_4, h206_supp_4);
1012 	replacestr(form206, h206_tag_meds_5, h206_meds_5);
1013 	replacestr(form206, h206_tag_supp_5, h206_supp_5);
1014 
1015 	replacestr(form206, h206_tag_special_instructions, h206_special_instructions);
1016 
1017 	replacestr(form206, h206_tag_site_1, h206_site_1);
1018 	replacestr(form206, h206_tag_address_1, h206_address_1);
1019 	replacestr(form206, h206_tag_phone_1, h206_phone_1);
1020 	replacestr(form206, h206_tag_spec_care_1, h206_spec_care_1);
1021 	replacestr(form206, h206_tag_site_2, h206_site_2);
1022 	replacestr(form206, h206_tag_address_2, h206_address_2);
1023 	replacestr(form206, h206_tag_phone_2, h206_phone_2);
1024 	replacestr(form206, h206_tag_spec_care_2, h206_spec_care_2);
1025 	replacestr(form206, h206_tag_site_3, h206_site_3);
1026 	replacestr(form206, h206_tag_address_3, h206_address_3);
1027 	replacestr(form206, h206_tag_phone_3, h206_phone_3);
1028 	replacestr(form206, h206_tag_spec_care_3, h206_spec_care_3);
1029 	replacestr(form206, h206_tag_site_4, h206_site_4);
1030 	replacestr(form206, h206_tag_address_4, h206_address_4);
1031 	replacestr(form206, h206_tag_phone_4, h206_phone_4);
1032 	replacestr(form206, h206_tag_spec_care_4, h206_spec_care_4);
1033 
1034 	replacestr(form206, h206_tag_preparer, h206_preparer);
1035 	replacestr(form206, h206_tag_facility, h206_facility);
1036 
1037 	FILE *file206 = fopen(hics206_fname.c_str(), "w");
1038 	fprintf(file206,"%s", form206.c_str());
1039 	fclose(file206);
1040 
1041 	open_url(hics206_fname.c_str());
1042 }
1043