Debian Codegraph @

src/ics/ics206.cxx

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