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 // ics206 fields
76 
77 // compatibility fields required to read older data files
78 
79 string aics206_name                 = "<nam:";
80 string aics206_period               = "<opp:";
81 string aics206_date_prepared        = "<dat:";
82 string aics206_time_prepared        = "<tim:";
83 string aics206_procedure            = "<proc:";
84 string aics206_preparer             = "<prep:";
85 string aics206_reviewer             = "<rvwr:";
86 string aics206_medaid_sta           = "<msta0:"; // array of 5
87 string aics206_medaid_loc           = "<mloc0:"; // ...
88 string aics206_medaid_paramedics    = "<mpar0:"; // bool
89 string aics206_transport_name       = "<tname0:"; // array of 5
90 string aics206_transport_address    = "<taddr0:"; // ...
91 string aics206_transport_phone      = "<tphon0:";
92 string aics206_transport_paramedics = "<tpara0:"; // bool
93 string aics206_ambulance_name       = "<aname0:"; // array of 5
94 string aics206_ambulance_loc        = "<aloca0:"; // ...
95 string aics206_ambulance_paramedics = "<apara0:"; // bool
96 string aics206_hosp_name            = "<hname0:"; // array of 5
97 string aics206_hosp_address         = "<haddr0:"; // ...
98 string aics206_hosp_phone           = "<hphon0:";
99 string aics206_hosp_airtime         = "<hatim0:";
100 string aics206_hosp_gndtime         = "<hgtim0:";
101 string aics206_hosp_helipad         = "<hheli0:"; // bool (5)
102 string aics206_hosp_burn_center     = "<hburn0:"; // ...
103 
104 string ics206_name                 = ":nam:";
105 string ics206_period               = ":opp:";
106 string ics206_date_prepared        = ":dat:";
107 string ics206_time_prepared        = ":tim:";
108 string ics206_procedure            = ":proc:";
109 string ics206_preparer             = ":prep:";
110 string ics206_reviewer             = ":rvwr:";
111 string ics206_medaid_sta           = ":msta0:"; // array of 5
112 string ics206_medaid_loc           = ":mloc0:"; // ...
113 string ics206_medaid_paramedics    = ":mpar0:"; // bool
114 string ics206_transport_name       = ":tname0:"; // array of 5
115 string ics206_transport_address    = ":taddr0:"; // ...
116 string ics206_transport_phone      = ":tphon0:";
117 string ics206_transport_paramedics = ":tpara0:"; // bool
118 string ics206_ambulance_name       = ":aname0:"; // array of 5
119 string ics206_ambulance_loc        = ":aloca0:"; // ...
120 string ics206_ambulance_paramedics = ":apara0:"; // bool
121 string ics206_hosp_name            = ":hname0:"; // array of 5
122 string ics206_hosp_address         = ":haddr0:"; // ...
123 string ics206_hosp_phone           = ":hphon0:";
124 string ics206_hosp_airtime         = ":hatim0:";
125 string ics206_hosp_gndtime         = ":hgtim0:";
126 string ics206_hosp_helipad         = ":hheli0:"; // bool (5)
127 string ics206_hosp_burn_center     = ":hburn0:"; // ...
128 
129 string s206_name;
130 string s206_period;
131 string s206_date_prepared;
132 string s206_time_prepared;
133 string s206_procedure;
134 string s206_preparer;
135 string s206_reviewer;
136 
137 string s206_medaid_sta[5];
138 string s206_medaid_loc[5];
139 bool   b206_medaid_paramedics[5];
140 string s206_transport_name[5];
141 string s206_transport_address[5];
142 string s206_transport_phone[5];
143 bool   b206_transport_paramedics[5];
144 string s206_ambulance_name[5];
145 string s206_ambulance_loc[5];
146 bool   b206_ambulance_paramedics[5];
147 string s206_hosp_name[5];
148 string s206_hosp_address[5];
149 string s206_hosp_phone[5];
150 string s206_hosp_airtime[5];
151 string s206_hosp_gndtime[5];
152 bool   b206_hosp_helipad[5];
153 bool   b206_hosp_burn_center[5];
154 
155 string buff206;
156 string def_206_filename = "";
157 string base_206_filename = "";
158 string def_206_TemplateName = "";
159 bool using_ics206_template = false;
160 
cb_206_setdate()161 void cb_206_setdate()
162 {
163 	txt_206_date_prepared->value(szDate(progStatus.dtformat));
164 }
165 
cb_206_settime()166 void cb_206_settime()
167 {
168 	txt_206_time_prepared->value(szTime(progStatus.UTC));
169 }
170 
clear_206fields()171 void clear_206fields()
172 {
173 	s206_name.clear();
174 	s206_period.clear();
175 	s206_date_prepared.clear();
176 	s206_time_prepared.clear();
177 	s206_procedure.clear();
178 	s206_preparer.clear();
179 	s206_reviewer.clear();
180 
181 	for (int i = 0; i < 5; i++) {
182 		s206_medaid_sta[i].clear();
183 		s206_medaid_loc[i].clear();
184 		s206_transport_name[i].clear();
185 		s206_transport_address[i].clear();
186 		s206_transport_phone[i].clear();
187 		s206_ambulance_name[i].clear();
188 		s206_ambulance_loc[i].clear();
189 		s206_hosp_name[i].clear();
190 		s206_hosp_address[i].clear();
191 		s206_hosp_phone[i].clear();
192 		s206_hosp_airtime[i].clear();
193 		s206_hosp_gndtime[i].clear();
194 
195 		b206_medaid_paramedics[i] = false;
196 		b206_transport_paramedics[i] = false;
197 		b206_ambulance_paramedics[i] = false;
198 		b206_hosp_helipad[i] = false;
199 		b206_hosp_burn_center[i] = false;
200 	}
201 }
202 
check_206fields()203 bool check_206fields()
204 {
205 	if (s206_name != txt_206_name->value())
206 		return true;
207 	if (s206_period != txt_206_op_period->value())
208 		return true;
209 	if (s206_date_prepared != txt_206_date_prepared->value())
210 		return true;
211 	if (s206_time_prepared != txt_206_time_prepared->value())
212 		return true;
213 	if (s206_procedure != txt_206_procedure->buffer()->text())
214 		return true;
215 	if (s206_preparer != txt_206_preparer->value())
216 		return true;
217 	if (s206_reviewer != txt_206_reviewer->value())
218 		return true;
219 
220 	for (int i = 0; i < 5; i++) {
221 		if (s206_medaid_sta[i] != txt_206_medaid_sta[i]->value())
222 			return true;
223 		if (s206_medaid_loc[i] != txt_206_medaid_loc[i]->value())
224 			return true;
225 		if (s206_transport_name[i] != txt_206_transport_name[i]->value())
226 			return true;
227 		if (s206_transport_address[i] != txt_206_transport_address[i]->value())
228 			return true;
229 		if (s206_transport_phone[i] != txt_206_transport_phone[i]->value())
230 			return true;
231 		if (s206_ambulance_name[i] != txt_206_ambulance_name[i]->value())
232 			return true;
233 		if (s206_ambulance_loc[i] != txt_206_ambulance_loc[i]->value())
234 			return true;
235 		if (s206_hosp_name[i] != txt_206_hosp_name[i]->value())
236 			return true;
237 		if (s206_hosp_address[i] != txt_206_hosp_address[i]->value())
238 			return true;
239 		if (s206_hosp_phone[i] != txt_206_hosp_phone[i]->value())
240 			return true;
241 		if (s206_hosp_airtime[i] != txt_206_hosp_airtime[i]->value())
242 			return true;
243 		if (s206_hosp_gndtime[i] != txt_206_hosp_gndtime[i]->value())
244 			return true;
245 		if (b206_medaid_paramedics[i] != btn_206_medaid_paramedics[i]->value())
246 			return true;
247 		if (b206_transport_paramedics[i] != btn_206_transport_paramedics[i]->value())
248 			return true;
249 		if (b206_ambulance_paramedics[i] != btn_206_ambulance_paramedics[i]->value())
250 			return true;
251 		if (b206_hosp_helipad[i] != btn_206_hosp_helipad[i]->value())
252 			return true;
253 		if (b206_hosp_burn_center[i] != btn_206_hosp_burn_center[i]->value())
254 			return true;
255 	}
256 	return false;
257 }
258 
update_206fields()259 void update_206fields()
260 {
261 	s206_name = txt_206_name->value();
262 	s206_period = txt_206_op_period->value();
263 	s206_date_prepared = txt_206_date_prepared->value();
264 	s206_time_prepared = txt_206_time_prepared->value();
265 	s206_procedure = txt_206_procedure->buffer()->text();
266 	s206_preparer = txt_206_preparer->value();
267 	s206_reviewer = txt_206_reviewer->value();
268 
269 	for (int i = 0; i < 5; i++) {
270 		s206_medaid_sta[i] = txt_206_medaid_sta[i]->value();
271 		s206_medaid_loc[i] = txt_206_medaid_loc[i]->value();
272 		s206_transport_name[i] = txt_206_transport_name[i]->value();
273 		s206_transport_address[i] = txt_206_transport_address[i]->value();
274 		s206_transport_phone[i] = txt_206_transport_phone[i]->value();
275 		s206_ambulance_name[i] = txt_206_ambulance_name[i]->value();
276 		s206_ambulance_loc[i] = txt_206_ambulance_loc[i]->value();
277 		s206_hosp_name[i] = txt_206_hosp_name[i]->value();
278 		s206_hosp_address[i] = txt_206_hosp_address[i]->value();
279 		s206_hosp_phone[i] = txt_206_hosp_phone[i]->value();
280 		s206_hosp_airtime[i] = txt_206_hosp_airtime[i]->value();
281 		s206_hosp_gndtime[i] = txt_206_hosp_gndtime[i]->value();
282 		b206_medaid_paramedics[i] = btn_206_medaid_paramedics[i]->value();
283 		b206_transport_paramedics[i] = btn_206_transport_paramedics[i]->value();
284 		b206_ambulance_paramedics[i] = btn_206_ambulance_paramedics[i]->value();
285 		b206_hosp_helipad[i] = btn_206_hosp_helipad[i]->value();
286 		b206_hosp_burn_center[i] = btn_206_hosp_burn_center[i]->value();
287 	}
288 }
289 
update_206form()290 void update_206form()
291 {
292 	txt_206_name->value(s206_name.c_str());
293 	txt_206_op_period->value(s206_period.c_str());
294 	txt_206_date_prepared->value(s206_date_prepared.c_str());
295 	txt_206_time_prepared->value(s206_time_prepared.c_str());
296 	txt_206_procedure->addstr(s206_procedure.c_str());
297 	txt_206_preparer->value(s206_preparer.c_str());
298 	txt_206_reviewer->value(s206_reviewer.c_str());
299 
300 	for (int i = 0; i < 5; i++) {
301 		txt_206_medaid_sta[i]->value(s206_medaid_sta[i].c_str());
302 		txt_206_medaid_loc[i]->value(s206_medaid_loc[i].c_str());
303 		txt_206_transport_name[i]->value(s206_transport_name[i].c_str());
304 		txt_206_transport_address[i]->value(s206_transport_address[i].c_str());
305 		txt_206_transport_phone[i]->value(s206_transport_phone[i].c_str());
306 		txt_206_ambulance_name[i]->value(s206_ambulance_name[i].c_str());
307 		txt_206_ambulance_loc[i]->value(s206_ambulance_loc[i].c_str());
308 		txt_206_hosp_name[i]->value(s206_hosp_name[i].c_str());
309 		txt_206_hosp_address[i]->value(s206_hosp_address[i].c_str());
310 		txt_206_hosp_phone[i]->value(s206_hosp_phone[i].c_str());
311 		txt_206_hosp_airtime[i]->value(s206_hosp_airtime[i].c_str());
312 		txt_206_hosp_gndtime[i]->value(s206_hosp_gndtime[i].c_str());
313 
314 		btn_206_medaid_paramedics[i]->value(b206_medaid_paramedics[i]);
315 		btn_206_transport_paramedics[i]->value(b206_transport_paramedics[i]);
316 		btn_206_ambulance_paramedics[i]->value(b206_ambulance_paramedics[i]);
317 		btn_206_hosp_helipad[i]->value(b206_hosp_helipad[i]);
318 		btn_206_hosp_burn_center[i]->value(b206_hosp_burn_center[i]);
319 	}
320 }
321 
clear_206_form()322 void clear_206_form()
323 {
324 	clear_206fields();
325 
326 	txt_206_name->value("");
327 	txt_206_op_period->value("");
328 	txt_206_date_prepared->value("");
329 	txt_206_time_prepared->value("");
330 	txt_206_procedure->clear();
331 	txt_206_preparer->value("");
332 	txt_206_reviewer->value("");
333 
334 	for (int i = 0; i < 5; i++) {
335 		txt_206_medaid_sta[i]->value("");
336 		txt_206_medaid_loc[i]->value("");
337 		txt_206_transport_name[i]->value("");
338 		txt_206_transport_address[i]->value("");
339 		txt_206_transport_phone[i]->value("");
340 		txt_206_ambulance_name[i]->value("");
341 		txt_206_ambulance_loc[i]->value("");
342 		txt_206_hosp_name[i]->value("");
343 		txt_206_hosp_address[i]->value("");
344 		txt_206_hosp_phone[i]->value("");
345 		txt_206_hosp_airtime[i]->value("");
346 		txt_206_hosp_gndtime[i]->value("");
347 
348 		btn_206_medaid_paramedics[i]->value(false);
349 		btn_206_transport_paramedics[i]->value(false);
350 		btn_206_ambulance_paramedics[i]->value(false);
351 		btn_206_hosp_helipad[i]->value(false);
352 		btn_206_hosp_burn_center[i]->value(false);
353 	}
354 }
355 
make_buff206(bool compress=false)356 void make_buff206(bool compress = false)
357 {
358 	string mbuff;
359 	mbuff.clear();
360 	mbuff.append( lineout( ics206_name, s206_name ) );
361 	mbuff.append( lineout( ics206_period, s206_period ) );
362 	mbuff.append( lineout( ics206_date_prepared, s206_date_prepared ) );
363 	mbuff.append( lineout( ics206_time_prepared, s206_time_prepared ) );
364 	mbuff.append( lineout( ics206_procedure, s206_procedure ) );
365 	mbuff.append( lineout( ics206_preparer, s206_preparer ) );
366 	mbuff.append( lineout( ics206_reviewer, s206_reviewer ) );
367 
368 	for (int i = 0; i < 5; i++) {
369 		ics206_medaid_sta[5] = ics206_medaid_loc[5] = ics206_medaid_paramedics[5] =
370 		ics206_transport_address[6] = ics206_transport_name[6] =
371 		ics206_transport_phone[6] = ics206_transport_paramedics[6] =
372 		ics206_ambulance_loc[6] = ics206_ambulance_name[6] = ics206_ambulance_paramedics[6] =
373 		ics206_hosp_address[6] = ics206_hosp_name[6] =
374 		ics206_hosp_airtime[6] = ics206_hosp_gndtime[6] =
375 		ics206_hosp_phone[6] = ics206_hosp_helipad[6] =
376 		ics206_hosp_burn_center[6] = '0' + i;
377 
378 		mbuff.append( lineout( ics206_medaid_sta, s206_medaid_sta[i] ) );
379 		mbuff.append( lineout( ics206_medaid_loc, s206_medaid_loc[i] ) );
380 		mbuff.append( binout( ics206_medaid_paramedics, b206_medaid_paramedics[i] ) );
381 
382 		mbuff.append( lineout( ics206_transport_address, s206_transport_address[i] ) );
383 		mbuff.append( lineout( ics206_transport_name, s206_transport_name[i] ) );
384 		mbuff.append( lineout( ics206_transport_phone, s206_transport_phone[i] ) );
385 		mbuff.append( binout( ics206_transport_paramedics, b206_transport_paramedics[i] ) );
386 
387 		mbuff.append( lineout( ics206_ambulance_loc, s206_ambulance_loc[i] ) );
388 		mbuff.append( lineout( ics206_ambulance_name, s206_ambulance_name[i] ) );
389 		mbuff.append( binout( ics206_ambulance_paramedics, b206_ambulance_paramedics[i] ) );
390 
391 		mbuff.append( lineout( ics206_hosp_name, s206_hosp_name[i] ) );
392 		mbuff.append( lineout( ics206_hosp_address, s206_hosp_address[i] ) );
393 		mbuff.append( lineout( ics206_hosp_phone, s206_hosp_phone[i] ) );
394 		mbuff.append( lineout( ics206_hosp_airtime, s206_hosp_airtime[i] ) );
395 		mbuff.append( lineout( ics206_hosp_gndtime, s206_hosp_gndtime[i] ) );
396 		mbuff.append( binout( ics206_hosp_helipad, b206_hosp_helipad[i] ) );
397 		mbuff.append( binout( ics206_hosp_burn_center, b206_hosp_burn_center[i] ) );
398 	}
399 	if (compress) compress_maybe(mbuff);
400 	buff206.append(mbuff);
401 }
402 
read_206_buffer(string data)403 void read_206_buffer(string data)
404 {
405 	clear_206fields();
406 	read_header(data);
407 
408 	s206_name = findstr(data, ics206_name);
409 	s206_period = findstr(data, ics206_period);
410 	s206_date_prepared = findstr(data, ics206_date_prepared);
411 	s206_time_prepared = findstr(data, ics206_time_prepared);
412 	s206_procedure = findstr(data, ics206_procedure);
413 	s206_preparer = findstr(data, ics206_preparer);
414 	s206_reviewer = findstr(data, ics206_reviewer);
415 
416 	for (int i = 0; i < 5; i++) {
417 		ics206_medaid_sta[5] = ics206_medaid_loc[5] = ics206_medaid_paramedics[5] =
418 		ics206_transport_address[6] = ics206_transport_name[6] =
419 		ics206_transport_phone[6] = ics206_transport_paramedics[6] =
420 		ics206_ambulance_loc[6] = ics206_ambulance_name[6] = ics206_ambulance_paramedics[6] =
421 		ics206_hosp_address[6] = ics206_hosp_name[6] =
422 		ics206_hosp_airtime[6] = ics206_hosp_gndtime[6] =
423 		ics206_hosp_phone[6] = ics206_hosp_helipad[6] =
424 		ics206_hosp_burn_center[6] = '0' + i;
425 
426 		s206_medaid_sta[i] = findstr(data, ics206_medaid_sta);
427 		s206_medaid_loc[i] = findstr(data, ics206_medaid_loc);
428 		b206_medaid_paramedics[i] = findbin(data, ics206_medaid_paramedics);
429 
430 		s206_transport_address[i] = findstr(data, ics206_transport_address);
431 		s206_transport_name[i] = findstr(data, ics206_transport_name);
432 		s206_transport_phone[i] = findstr(data, ics206_transport_phone);
433 		b206_transport_paramedics[i] = findbin(data, ics206_transport_paramedics);
434 
435 		s206_ambulance_loc[i] = findstr(data, ics206_ambulance_loc);
436 		s206_ambulance_name[i] = findstr(data, ics206_ambulance_name);
437 		b206_ambulance_paramedics[i] = findbin(data, ics206_ambulance_paramedics);
438 
439 		s206_hosp_name[i] = findstr(data, ics206_hosp_name);
440 		s206_hosp_address[i] = findstr(data, ics206_hosp_address);
441 		s206_hosp_phone[i] = findstr(data, ics206_hosp_phone);
442 		s206_hosp_airtime[i] = findstr(data, ics206_hosp_airtime);
443 		s206_hosp_gndtime[i] = findstr(data, ics206_hosp_gndtime);
444 		b206_hosp_helipad[i] = findbin(data, ics206_hosp_helipad);
445 		b206_hosp_burn_center[i] = findbin(data, ics206_hosp_burn_center);
446 	}
447 	if (s206_name.empty()) {
448 		s206_name = findstr(data, aics206_name);
449 		s206_period = findstr(data, aics206_period);
450 		s206_date_prepared = findstr(data, aics206_date_prepared);
451 		s206_time_prepared = findstr(data, aics206_time_prepared);
452 		s206_procedure = findstr(data, aics206_procedure);
453 		s206_preparer = findstr(data, aics206_preparer);
454 		s206_reviewer = findstr(data, aics206_reviewer);
455 
456 		for (int i = 0; i < 5; i++) {
457 			aics206_medaid_sta[5] = aics206_medaid_loc[5] = aics206_medaid_paramedics[5] =
458 			aics206_transport_address[6] = aics206_transport_name[6] =
459 			aics206_transport_phone[6] = aics206_transport_paramedics[6] =
460 			aics206_ambulance_loc[6] = aics206_ambulance_name[6] = aics206_ambulance_paramedics[6] =
461 			aics206_hosp_address[6] = aics206_hosp_name[6] =
462 			aics206_hosp_airtime[6] = aics206_hosp_gndtime[6] =
463 			aics206_hosp_phone[6] = aics206_hosp_helipad[6] =
464 			aics206_hosp_burn_center[6] = '0' + i;
465 
466 			s206_medaid_sta[i] = findstr(data, aics206_medaid_sta);
467 			s206_medaid_loc[i] = findstr(data, aics206_medaid_loc);
468 			b206_medaid_paramedics[i] = findbin(data, aics206_medaid_paramedics);
469 
470 			s206_transport_address[i] = findstr(data, aics206_transport_address);
471 			s206_transport_name[i] = findstr(data, aics206_transport_name);
472 			s206_transport_phone[i] = findstr(data, aics206_transport_phone);
473 			b206_transport_paramedics[i] = findbin(data, aics206_transport_paramedics);
474 
475 			s206_ambulance_loc[i] = findstr(data, aics206_ambulance_loc);
476 			s206_ambulance_name[i] = findstr(data, aics206_ambulance_name);
477 			b206_ambulance_paramedics[i] = findbin(data, aics206_ambulance_paramedics);
478 
479 			s206_hosp_name[i] = findstr(data, aics206_hosp_name);
480 			s206_hosp_address[i] = findstr(data, aics206_hosp_address);
481 			s206_hosp_phone[i] = findstr(data, aics206_hosp_phone);
482 			s206_hosp_airtime[i] = findstr(data, aics206_hosp_airtime);
483 			s206_hosp_gndtime[i] = findstr(data, aics206_hosp_gndtime);
484 			b206_hosp_helipad[i] = findbin(data, aics206_hosp_helipad);
485 			b206_hosp_burn_center[i] = findbin(data, aics206_hosp_burn_center);
486 		}
487 	}
488 	update_206form();
489 }
490 
cb_206_new()491 void cb_206_new()
492 {
493 	if (check_206fields()) {
494 		if (fl_choice2("Form modified, save?", "No", "Yes", NULL) == 1) {
495 			update_header(CHANGED);
496 			cb_206_save();
497 		}
498 	}
499 	clear_206_form();
500 	clear_header();
501 	def_206_filename = ICS_msg_dir;
502 	def_206_filename.append("new").append(F206_EXT);
503 	show_filename(def_206_filename);
504 	using_ics206_template = false;
505 }
506 
cb_206_import()507 void cb_206_import()
508 {
509 	fl_alert2("Not implemented");
510 }
511 
cb_206_export()512 void cb_206_export()
513 {
514 	fl_alert2("Not implemented");
515 }
516 
cb_206_wrap_import(string wrapfilename,string inpbuffer)517 void cb_206_wrap_import(string wrapfilename, string inpbuffer)
518 {
519 	clear_206_form();
520 	read_206_buffer(inpbuffer);
521 	def_206_filename = ICS_msg_dir;
522 	def_206_filename.append(wrapfilename);
523 	show_filename(def_206_filename);
524 	using_ics206_template = false;
525 }
526 
eval_206_fsize()527 int eval_206_fsize()
528 {
529 	Ccrc16 chksum;
530 	evalstr.assign("[WRAP:beg][WRAP:lf][WRAP:fn ");
531 	evalstr.append(base_206_filename).append("]");
532 	update_206fields();
533 	update_header(FROM);
534 	evalstr.append(header("<ics206>"));
535 	buff206.clear();
536 	make_buff206(true);
537 	if (buff206.empty()) return 0;
538 	compress_maybe( buff206 );
539 	evalstr.append( buff206 );
540 	evalstr.append("[WRAP:chksum ").append(chksum.scrc16(evalstr)).append("][WRAP:end]");
541 	return evalstr.length();
542 }
543 
cb_206_wrap_export()544 void cb_206_wrap_export()
545 {
546 	if (check_206fields()) {
547 		if (fl_choice2("Form modified, save?", "No", "Yes", NULL) == 0)
548 			return;
549 		update_header(CHANGED);
550 	}
551 	update_206fields();
552 
553 	if (base_206_filename == string("new").append(F206_EXT) ||
554 		base_206_filename == string("default").append(F206_EXT) )
555 		if (!cb_206_save_as()) return;
556 
557 	string wrapfilename = WRAP_send_dir;
558 	wrapfilename.append(base_206_filename);
559 	wrapfilename.append(".wrap");
560 	const char *p = FSEL::saveas(
561 			"Save as wrap file",
562 			"Wrap file\t*.{wrap,WRAP}",
563 			wrapfilename.c_str());
564 	if (p) {
565 		string pext = fl_filename_ext(p);
566 		wrapfilename = p;
567 		update_header(FROM);
568 		buff206.assign(header("<ics206>"));
569 		make_buff206(true);
570 		export_wrapfile(base_206_filename, wrapfilename, buff206, pext != ".wrap");
571 
572 		buff206.assign(header("<ics206>"));
573 		make_buff206(false);
574 		write_206(def_206_filename);
575 	}
576 }
577 
cb_206_wrap_autosend()578 void cb_206_wrap_autosend()
579 {
580 	if (check_206fields()) {
581 		if (fl_choice2("Form modified, save?", "No", "Yes", NULL) == 0)
582 			return;
583 		update_header(CHANGED);
584 	}
585 	update_206fields();
586 
587 	if (base_206_filename == string("new").append(F206_EXT) ||
588 		base_206_filename == string("default").append(F206_EXT) )
589 		if (!cb_206_save_as()) return;
590 
591 	update_header(FROM);
592 	buff206.assign(header("<ics206>"));
593 	make_buff206(true);
594 	xfr_via_socket(base_206_filename, buff206);
595 
596 	buff206.assign(header("<ics206>"));
597 	make_buff206(false);
598 	write_206(def_206_filename);
599 }
600 
cb_206_load_template()601 void cb_206_load_template()
602 {
603 	string def_206_filename = def_206_TemplateName;
604 	const char *p = FSEL::select(
605 			"Open template file",
606 			string("Template file\t*").append(T206_EXT).c_str(),
607 			def_206_filename.c_str());
608 	if (p) {
609 		clear_206_form();
610 		read_data_file(p);
611 		def_206_TemplateName = p;
612 		show_filename(def_206_TemplateName);
613 		using_ics206_template = true;
614 	}
615 }
616 
cb_206_save_template()617 void cb_206_save_template()
618 {
619 	if (!using_ics206_template) {
620 		cb_206_save_as_template();
621 		return;
622 	}
623 	string def_206_filename = def_206_TemplateName;
624 	const char *p = FSEL::saveas(
625 			"Save template file",
626 			string("Template file\t*").append(T206_EXT).c_str(),
627 			def_206_filename.c_str());
628 	if (p) {
629 		update_header(CHANGED);
630 		buff206.assign(header("<ics206>"));
631 		make_buff206();
632 		write_206(p);
633 	}
634 }
635 
cb_206_save_as_template()636 void cb_206_save_as_template()
637 {
638 	string def_206_filename = def_206_TemplateName;
639 	const char *p = FSEL::saveas(
640 			"Save as template file",
641 			string("Template file\t*").append(T206_EXT).c_str(),
642 			def_206_filename.c_str());
643 	if (p) {
644 		const char *pext = fl_filename_ext(p);
645 		def_206_TemplateName = p;
646 		if (strlen(pext) == 0) def_206_TemplateName.append(T206_EXT);
647 		remove_spaces_from_filename(def_206_TemplateName);\
648 		clear_header();
649 		update_header(CHANGED);
650 		buff206.assign(header("<ics206>"));
651 		make_buff206();
652 		write_206(def_206_TemplateName);
653 		show_filename(def_206_TemplateName);
654 		using_ics206_template = true;
655 	}
656 }
657 
cb_206_open()658 void cb_206_open()
659 {
660 	const char *p = FSEL::select(
661 			_("Open data file"),
662 			string("ICS-206\t*").append(F206_EXT).c_str(),
663 			def_206_filename.c_str());
664 	if (!p) return;
665 	if (strlen(p) == 0) return;
666 	clear_206_form();
667 	read_data_file(p);
668 	using_ics206_template = false;
669 	def_206_filename = p;
670 	show_filename(def_206_filename);
671 }
672 
write_206(string s)673 void write_206(string s)
674 {
675 	FILE *file206 = fopen(s.c_str(), "w");
676 	if (!file206) return;
677 
678 	fwrite(buff206.c_str(), buff206.length(), 1, file206);
679 	fclose(file206);
680 }
681 
cb_206_save_as()682 bool cb_206_save_as()
683 {
684 	const char *p;
685 	string newfilename;
686 
687 	string name = named_file();
688 	if (!name.empty()) {
689 		name.append(F206_EXT);
690 		newfilename = ICS_msg_dir;
691 		newfilename.append(name);
692 	} else
693 		newfilename = def_206_filename;
694 
695 	p = FSEL::saveas(
696 			_("Save data file"),
697 			string("ICS-206\t*").append(F206_EXT).c_str(),
698 			newfilename.c_str());
699 
700 	if (!p) return false;
701 	if (strlen(p) == 0) return false;
702 
703 	if (progStatus.sernbr_fname) update_sernbr();
704 
705 	const char *pext = fl_filename_ext(p);
706 	def_206_filename = p;
707 	if (strlen(pext) == 0) def_206_filename.append(F206_EXT);
708 
709 	remove_spaces_from_filename(def_206_filename);
710 	update_206fields();
711 	update_header(NEW);
712 	buff206.assign("<ics206>");
713 	make_buff206();
714 	write_206(def_206_filename);
715 
716 	using_ics206_template = false;
717 	show_filename(def_206_filename);
718 	return true;
719 }
720 
cb_206_save()721 void cb_206_save()
722 {
723 	if (base_206_filename == string("new").append(F206_EXT) ||
724 		base_206_filename == string("default").append(F206_EXT) ||
725 		using_ics206_template == true) {
726 		cb_206_save_as();
727 		return;
728 	}
729 	if (check_206fields()) update_header(CHANGED);
730 	update_206fields();
731 	buff206.assign(header("<ics206>"));
732 	make_buff206();
733 	write_206(def_206_filename);
734 	using_ics206_template = false;
735 }
736 
737 string yes = "YES";
738 string no =  "";
739 
cb_206_html()740 void cb_206_html()
741 {
742 	string fname_name = fl_filename_name(def_206_filename.c_str());
743 	size_t p = fname_name.rfind('.');
744 	if (p != string::npos) fname_name.erase(p);
745 
746 	string ics206_fname = ICS_dir;
747 	ics206_fname.append(fname_name);
748 	ics206_fname.append(".html");
749 
750 	string html_text = "";
751 
752 	update_206fields();
753 	string form206 = ics206_html_template;
754 
755 	replacestr(form206, TITLE, fname_name);
756 	replacestr(form206, ics206_name, s206_name);
757 	replacestr(form206, ics206_period, s206_period);
758 	replacestr(form206, ics206_date_prepared, s206_date_prepared);
759 	replacestr(form206, ics206_time_prepared, s206_time_prepared);
760 	for (int i = 0; i < 5; i++) {
761 		ics206_medaid_sta[5] = ics206_medaid_loc[5] = ics206_medaid_paramedics[5] =
762 		ics206_transport_address[6] = ics206_transport_name[6] =
763 		ics206_transport_phone[6] = ics206_transport_paramedics[6] =
764 		ics206_ambulance_loc[6] = ics206_ambulance_name[6] = ics206_ambulance_paramedics[6] =
765 		ics206_hosp_address[6] = ics206_hosp_name[6] =
766 		ics206_hosp_airtime[6] = ics206_hosp_gndtime[6] =
767 		ics206_hosp_phone[6] = ics206_hosp_helipad[6] =
768 		ics206_hosp_burn_center[6] = '0' + i;
769 		replacestr(form206, ics206_medaid_sta, s206_medaid_sta[i]);
770 		replacestr(form206, ics206_medaid_loc, s206_medaid_loc[i]);
771 		replacestr(form206, ics206_medaid_paramedics, b206_medaid_paramedics[i] ? yes : no);
772 		replacestr(form206, ics206_transport_name, s206_transport_name[i]);
773 		replacestr(form206, ics206_transport_address, s206_transport_address[i]);
774 		replacestr(form206, ics206_transport_phone, s206_transport_phone[i]);
775 		replacestr(form206, ics206_transport_paramedics, b206_transport_paramedics[i] ? yes : no);
776 		replacestr(form206, ics206_ambulance_name, s206_ambulance_name[i]);
777 		replacestr(form206, ics206_ambulance_loc, s206_ambulance_loc[i]);
778 		replacestr(form206, ics206_ambulance_paramedics, b206_ambulance_paramedics[i] ? yes : no);
779 		replacestr(form206, ics206_hosp_name, s206_hosp_name[i]);
780 		replacestr(form206, ics206_hosp_address, s206_hosp_address[i]);
781 		replacestr(form206, ics206_hosp_phone, s206_hosp_phone[i]);
782 		replacestr(form206, ics206_hosp_airtime, s206_hosp_airtime[i]);
783 		replacestr(form206, ics206_hosp_gndtime, s206_hosp_gndtime[i]);
784 		replacestr(form206, ics206_hosp_helipad, b206_hosp_helipad[i] ? yes : no);
785 		replacestr(form206, ics206_hosp_burn_center, b206_hosp_burn_center[i] ? yes : no);
786 	}
787 
788 	string temp = "<pre><big style=\"font-family: monospace;\">";
789 	if (progStatus.autowordwrap)
790 		html_text.append(wordwrap(s206_procedure, progStatus.charcount));
791 	else
792 		temp.append(s206_procedure);
793 	temp.append("</big></pre>");
794 	replacestr(form206, ics206_procedure, temp);
795 
796 	replacestr(form206, ics206_preparer, s206_preparer);
797 	replacestr(form206, ics206_reviewer, s206_reviewer);
798 
799 	FILE *file206 = fopen(ics206_fname.c_str(), "w");
800 	fprintf(file206,"%s", form206.c_str());
801 	fclose(file206);
802 
803 	open_url(ics206_fname.c_str());
804 }
805 
cb_206_msg_type()806 void cb_206_msg_type()
807 {
808 	if (tabs_msg_type->value() == tab_ics206 ) {
809 		tab_ics206_type->value(tab_206_med_plan);
810 		show_filename(def_206_filename);
811 	}
812 }
813 
cb_206_textout()814 void cb_206_textout()
815 {
816 	string ics206_fname = ICS_dir;
817 	ics206_fname.append("ics206.txt");
818 
819 	update_206fields();
820 	string form206 = ics206_text_template;
821 
822 	replacestr(form206, ics206_name, s206_name);
823 	replacestr(form206, ics206_period, s206_period);
824 	replacestr(form206, ics206_date_prepared, s206_date_prepared);
825 	replacestr(form206, ics206_time_prepared, s206_time_prepared);
826 	for (int i = 0; i < 5; i++) {
827 		ics206_medaid_sta[5] = ics206_medaid_loc[5] = ics206_medaid_paramedics[5] =
828 		ics206_transport_address[6] = ics206_transport_name[6] =
829 		ics206_transport_phone[6] = ics206_transport_paramedics[6] =
830 		ics206_ambulance_loc[6] = ics206_ambulance_name[6] = ics206_ambulance_paramedics[6] =
831 		ics206_hosp_address[6] = ics206_hosp_name[6] =
832 		ics206_hosp_airtime[6] = ics206_hosp_gndtime[6] =
833 		ics206_hosp_phone[6] = ics206_hosp_helipad[6] =
834 		ics206_hosp_burn_center[6] = '0' + i;
835 		replacestr(form206, ics206_medaid_sta, s206_medaid_sta[i]);
836 		replacestr(form206, ics206_medaid_loc, s206_medaid_loc[i]);
837 		replacestr(form206, ics206_medaid_paramedics, b206_medaid_paramedics[i] ? yes : no);
838 		replacestr(form206, ics206_transport_name, s206_transport_name[i]);
839 		replacestr(form206, ics206_transport_address, s206_transport_address[i]);
840 		replacestr(form206, ics206_transport_phone, s206_transport_phone[i]);
841 		replacestr(form206, ics206_transport_paramedics, b206_transport_paramedics[i] ? yes : no);
842 		replacestr(form206, ics206_ambulance_name, s206_ambulance_name[i]);
843 		replacestr(form206, ics206_ambulance_loc, s206_ambulance_loc[i]);
844 		replacestr(form206, ics206_ambulance_paramedics, b206_ambulance_paramedics[i] ? yes : no);
845 		replacestr(form206, ics206_hosp_name, s206_hosp_name[i]);
846 		replacestr(form206, ics206_hosp_address, s206_hosp_address[i]);
847 		replacestr(form206, ics206_hosp_phone, s206_hosp_phone[i]);
848 		replacestr(form206, ics206_hosp_airtime, s206_hosp_airtime[i]);
849 		replacestr(form206, ics206_hosp_gndtime, s206_hosp_gndtime[i]);
850 		replacestr(form206, ics206_hosp_helipad, b206_hosp_helipad[i] ? yes : no);
851 		replacestr(form206, ics206_hosp_burn_center, b206_hosp_burn_center[i] ? yes : no);
852 	}
853 
854 	replacestr(form206, ics206_procedure, s206_procedure);
855 
856 	replacestr(form206, ics206_preparer, s206_preparer);
857 	replacestr(form206, ics206_reviewer, s206_reviewer);
858 
859 	FILE *file206 = fopen(ics206_fname.c_str(), "w");
860 	fprintf(file206,"%s", form206.c_str());
861 	fclose(file206);
862 
863 	open_url(ics206_fname.c_str());
864 }
865