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 // ---------------------------------------------------------------------
76 // hics 203 field variables and template variables
77 // ---------------------------------------------------------------------
78
79 string hics203_tag_incident = ":inc:";
80 string hics203_tag_date = ":dat:";
81 string hics203_tag_time = ":tim:";
82 string hics203_tag_op_period = ":opp:";
83 string hics203_tag_incident_commander = ":icc:";
84 string hics203_tag_incident_safety_officer = ":ics:";
85 string hics203_tag_incident_info_officer = ":ici:";
86 string hics203_tag_liaison_officer = ":icl:";
87 string hics203_tag_prepared_by = ":pre:";
88 string hics203_tag_facility = ":facility:";
89
90 string hics203_tag_tech_spc = ":tech_spc[n]:"; // 6
91
92 string hics203_tag_ops_chief = ":ops_chief:";
93 string hics203_tag_bus_brch = ":bus_brch:";
94 string hics203_tag_stg_mgr = ":stg_mgr:";
95 string hics203_tag_med_care_brch = ":med_care_brch:";
96 string hics203_tag_infr_brch = ":infr_brch:";
97 string hics203_tag_sec_brch = ":sec_brch:";
98 string hics203_tag_hazmat_brch = ":hazmat_brch:";
99 string hics203_tag_ops_other = ":ops_other:";
100
101 string hics203_tag_fin_chief = ":fin_chief:";
102 string hics203_tag_cost_unit = ":cost_unit:";
103 string hics203_tag_proc_unit = ":proc_unit:";
104 string hics203_tag_comp_unit = ":comp_unit:";
105 string hics203_tag_time_unit = ":time_unit:";
106 string hics203_tag_fin_other = ":fin_other:";
107
108 string hics203_tag_planning_chief = ":planning_chief:";
109 string hics203_tag_res_unit = ":res_unit:";
110 string hics203_tag_sit_unit = ":sit_unit:";
111 string hics203_tag_doc_unit = ":doc_unit:";
112 string hics203_tag_dem_unit = ":dem_unit:";
113 string hics203_tag_planning_other = ":planning_other:";
114
115 string hics203_tag_log_chief = ":log_chief:";
116 string hics203_tag_sup_brch = ":sup_brch:";
117 string hics203_tag_svc_brch = ":svc_brch:";
118 string hics203_tag_log_other = ":log_other:";
119
120 string hics203_tag_hcc_agency = ":hcc_agency:";
121 string hics203_tag_hcc_rep = ":hcc_rep:";
122 string hics203_tag_ext_loc = ":ext_loc:";
123 string hics203_tag_ext_rep = ":ext_rep:";
124
125 string hics203_incident;
126 string hics203_date;
127 string hics203_time;
128 string hics203_op_period;
129 string hics203_incident_commander;
130 string hics203_incident_safety_officer;
131 string hics203_incident_info_officer;
132 string hics203_liaison_officer;
133 string hics203_prepared_by;
134 string hics203_facility;
135
136 string hics203_fin_chief;
137 string hics203_fin_other;
138 string hics203_time_unit;
139 string hics203_proc_unit;
140 string hics203_comp_unit;
141 string hics203_cost_unit;
142
143 string hics203_tech_spc[6];
144
145 string hics203_planning_chief;
146 string hics203_planning_other;
147 string hics203_res_unit;
148 string hics203_sit_unit;
149 string hics203_doc_unit;
150 string hics203_dem_unit;
151 string hics203_log_chief;
152 string hics203_log_other;
153 string hics203_log_sup_brch;
154 string hics203_bus_brch;
155 string hics203_stg_mgr;
156 string hics203_med_care_brch;
157 string hics203_infr_brch;
158 string hics203_sec_brch;
159 string hics203_hazmat_brch;
160 string hics203_hcc_agency;
161 string hics203_svc_brch;
162 string hics203_hcc_rep;
163 string hics203_ext_loc;
164 string hics203_ext_rep;
165 string hics203_ops_chief;
166 string hics203_ops_other;
167
168 // =====================================================================
169
170 string hics_buff203;
171 string def_hics203_filename = "";
172 string base_hics203_filename = "";
173 string def_hics203_TemplateName = "";
174 bool using_hics203_template = false;
175
cb_hics203_set_date()176 void cb_hics203_set_date()
177 {
178 txt_hics203_date->value(szDate(progStatus.dtformat));
179 }
180
cb_hics203_set_time()181 void cb_hics203_set_time()
182 {
183 txt_hics203_time->value(szTime(progStatus.UTC));
184 }
185
clear_hics203fields()186 void clear_hics203fields()
187 {
188 hics203_incident.clear();
189 hics203_date.clear();
190 hics203_time.clear();
191 hics203_op_period.clear();
192 hics203_incident_commander.clear();
193 hics203_incident_safety_officer.clear();
194 hics203_incident_info_officer.clear();
195 hics203_liaison_officer.clear();
196 hics203_prepared_by.clear();
197 hics203_facility.clear();
198 hics203_planning_chief.clear();
199 hics203_planning_other.clear();
200 hics203_res_unit.clear();
201 hics203_sit_unit.clear();
202 hics203_doc_unit.clear();
203 hics203_dem_unit.clear();
204 hics203_log_chief.clear();
205 hics203_log_other.clear();
206 hics203_log_sup_brch.clear();
207 hics203_bus_brch.clear();
208 hics203_stg_mgr.clear();
209 hics203_med_care_brch.clear();
210 hics203_infr_brch.clear();
211 hics203_sec_brch.clear();
212 hics203_hazmat_brch.clear();
213 hics203_hcc_agency.clear();
214 hics203_svc_brch.clear();
215 hics203_hcc_rep.clear();
216 hics203_ext_loc.clear();
217 hics203_ext_rep.clear();
218 hics203_ops_chief.clear();
219 hics203_ops_other.clear();
220 hics203_fin_chief.clear();
221 hics203_fin_other.clear();
222 hics203_time_unit.clear();
223 hics203_proc_unit.clear();
224 hics203_comp_unit.clear();
225 hics203_cost_unit.clear();
226
227 for (int i = 0; i < 6; i++) {
228 hics203_tech_spc[i].clear();
229 }
230 }
231
check_hics203fields()232 bool check_hics203fields()
233 {
234 if (hics203_incident != txt_hics203_incident->value())
235 return true;
236 if (hics203_date != txt_hics203_date->value())
237 return true;
238 if (hics203_time != txt_hics203_time->value())
239 return true;
240 if (hics203_op_period != txt_hics203_op_period->value())
241 return true;
242 if (hics203_incident_commander != txt_hics203_incident_commander->value())
243 return true;
244 if (hics203_incident_safety_officer != txt_hics203_incident_safety_officer->value())
245 return true;
246 if (hics203_incident_info_officer != txt_hics203_incident_info_officer->value())
247 return true;
248 if (hics203_liaison_officer != txt_hics203_liaison_officer->value())
249 return true;
250 if (hics203_prepared_by != txt_hics203_prepared_by->value())
251 return true;
252 if (hics203_facility != txt_hics203_facility->value())
253 return true;
254 if (hics203_planning_chief != txt_hics203_planning_chief->value())
255 return true;
256 if (hics203_planning_other != txt_hics203_planning_other->value())
257 return true;
258 if (hics203_res_unit != txt_hics203_res_unit->value())
259 return true;
260 if (hics203_sit_unit != txt_hics203_sit_unit->value())
261 return true;
262 if (hics203_doc_unit != txt_hics203_doc_unit->value())
263 return true;
264 if (hics203_dem_unit != txt_hics203_dem_unit->value())
265 return true;
266 if (hics203_log_chief != txt_hics203_log_chief->value())
267 return true;
268 if (hics203_log_other != txt_hics203_log_other->value())
269 return true;
270 if (hics203_log_sup_brch != txt_hics203_log_sup_brch->value())
271 return true;
272 if (hics203_bus_brch != txt_hics203_bus_brch->value())
273 return true;
274 if (hics203_stg_mgr != txt_hics203_stg_mgr->value())
275 return true;
276 if (hics203_med_care_brch != txt_hics203_med_care_brch->value())
277 return true;
278 if (hics203_infr_brch != txt_hics203_infr_brch->value())
279 return true;
280 if (hics203_sec_brch != txt_hics203_sec_brch->value())
281 return true;
282 if (hics203_hazmat_brch != txt_hics203_hazmat_brch->value())
283 return true;
284 if (hics203_hcc_agency != txt_hics203_hcc_agency->value())
285 return true;
286 if (hics203_svc_brch != txt_hics203_svc_brch->value())
287 return true;
288 if (hics203_hcc_rep != txt_hics203_hcc_rep->value())
289 return true;
290 if (hics203_ext_loc != txt_hics203_ext_loc->value())
291 return true;
292 if (hics203_ext_rep != txt_hics203_ext_rep->value())
293 return true;
294 if (hics203_ops_chief != txt_hics203_ops_chief->value())
295 return true;
296 if (hics203_ops_other != txt_hics203_ops_other->value())
297 return true;
298 if (hics203_fin_chief != txt_hics203_fin_chief->value())
299 return true;
300 if (hics203_fin_other != txt_hics203_fin_other->value())
301 return true;
302 if (hics203_time_unit != txt_hics203_time_unit->value())
303 return true;
304 if (hics203_proc_unit != txt_hics203_proc_unit->value())
305 return true;
306 if (hics203_comp_unit != txt_hics203_comp_unit->value())
307 return true;
308 if (hics203_cost_unit != txt_hics203_cost_unit->value())
309 return true;
310
311 for (int i = 0; i < 6; i++) {
312 if (hics203_tech_spc[i] != txt_hics203_tech_spc[i]->value())
313 return true;
314 }
315 return false;
316 }
317
update_hics203fields()318 void update_hics203fields()
319 {
320 hics203_incident = txt_hics203_incident->value();
321 hics203_date = txt_hics203_date->value();
322 hics203_time = txt_hics203_time->value();
323 hics203_op_period = txt_hics203_op_period->value();
324 hics203_incident_commander = txt_hics203_incident_commander->value();
325 hics203_incident_safety_officer = txt_hics203_incident_safety_officer->value();
326 hics203_incident_info_officer = txt_hics203_incident_info_officer->value();
327 hics203_liaison_officer = txt_hics203_liaison_officer->value();
328 hics203_prepared_by = txt_hics203_prepared_by->value();
329 hics203_facility = txt_hics203_facility->value();
330 hics203_planning_chief = txt_hics203_planning_chief->value();
331 hics203_planning_other = txt_hics203_planning_other->value();
332 hics203_res_unit = txt_hics203_res_unit->value();
333 hics203_sit_unit = txt_hics203_sit_unit->value();
334 hics203_doc_unit = txt_hics203_doc_unit->value();
335 hics203_dem_unit = txt_hics203_dem_unit->value();
336 hics203_log_chief = txt_hics203_log_chief->value();
337 hics203_log_other = txt_hics203_log_other->value();
338 hics203_log_sup_brch = txt_hics203_log_sup_brch->value();
339 hics203_bus_brch = txt_hics203_bus_brch->value();
340 hics203_stg_mgr = txt_hics203_stg_mgr->value();
341 hics203_med_care_brch = txt_hics203_med_care_brch->value();
342 hics203_infr_brch = txt_hics203_infr_brch->value();
343 hics203_sec_brch = txt_hics203_sec_brch->value();
344 hics203_hazmat_brch = txt_hics203_hazmat_brch->value();
345 hics203_hcc_agency = txt_hics203_hcc_agency->value();
346 hics203_svc_brch = txt_hics203_svc_brch->value();
347 hics203_hcc_rep = txt_hics203_hcc_rep->value();
348 hics203_ext_loc = txt_hics203_ext_loc->value();
349 hics203_ext_rep = txt_hics203_ext_rep->value();
350 hics203_ops_chief = txt_hics203_ops_chief->value();
351 hics203_ops_other = txt_hics203_ops_other->value();
352 hics203_fin_chief = txt_hics203_fin_chief->value();
353 hics203_fin_other = txt_hics203_fin_other->value();
354 hics203_time_unit = txt_hics203_time_unit->value();
355 hics203_proc_unit = txt_hics203_proc_unit->value();
356 hics203_comp_unit = txt_hics203_comp_unit->value();
357 hics203_cost_unit = txt_hics203_cost_unit->value();
358
359 for (int i = 0; i < 6; i++) {
360 hics203_tech_spc[i] = txt_hics203_tech_spc[i]->value();
361 }
362 }
363
update_hics203form()364 void update_hics203form()
365 {
366 txt_hics203_incident->value(hics203_incident.c_str());
367 txt_hics203_date->value(hics203_date.c_str());
368 txt_hics203_time->value(hics203_time.c_str());
369 txt_hics203_op_period->value(hics203_op_period.c_str());
370 txt_hics203_incident_commander->value(hics203_incident_commander.c_str());
371 txt_hics203_incident_safety_officer->value(hics203_incident_safety_officer.c_str());
372 txt_hics203_incident_info_officer->value(hics203_incident_info_officer.c_str());
373 txt_hics203_liaison_officer->value(hics203_liaison_officer.c_str());
374 txt_hics203_prepared_by->value(hics203_prepared_by.c_str());
375 txt_hics203_facility->value(hics203_facility.c_str());
376 txt_hics203_planning_chief->value(hics203_planning_chief.c_str());
377 txt_hics203_planning_other->value(hics203_planning_other.c_str());
378 txt_hics203_res_unit->value(hics203_res_unit.c_str());
379 txt_hics203_sit_unit->value(hics203_sit_unit.c_str());
380 txt_hics203_doc_unit->value(hics203_doc_unit.c_str());
381 txt_hics203_dem_unit->value(hics203_dem_unit.c_str());
382 txt_hics203_log_chief->value(hics203_log_chief.c_str());
383 txt_hics203_log_other->value(hics203_log_other.c_str());
384 txt_hics203_log_sup_brch->value(hics203_log_sup_brch.c_str());
385 txt_hics203_bus_brch->value(hics203_bus_brch.c_str());
386 txt_hics203_stg_mgr->value(hics203_stg_mgr.c_str());
387 txt_hics203_med_care_brch->value(hics203_med_care_brch.c_str());
388 txt_hics203_infr_brch->value(hics203_infr_brch.c_str());
389 txt_hics203_sec_brch->value(hics203_sec_brch.c_str());
390 txt_hics203_hazmat_brch->value(hics203_hazmat_brch.c_str());
391 txt_hics203_hcc_agency->value(hics203_hcc_agency.c_str());
392 txt_hics203_svc_brch->value(hics203_svc_brch.c_str());
393 txt_hics203_hcc_rep->value(hics203_hcc_rep.c_str());
394 txt_hics203_ext_loc->value(hics203_ext_loc.c_str());
395 txt_hics203_ext_rep->value(hics203_ext_rep.c_str());
396 txt_hics203_ops_chief->value(hics203_ops_chief.c_str());
397 txt_hics203_ops_other->value(hics203_ops_other.c_str());
398 txt_hics203_fin_chief->value(hics203_fin_chief.c_str());
399 txt_hics203_fin_other->value(hics203_fin_other.c_str());
400 txt_hics203_time_unit->value(hics203_time_unit.c_str());
401 txt_hics203_proc_unit->value(hics203_proc_unit.c_str());
402 txt_hics203_comp_unit->value(hics203_comp_unit.c_str());
403 txt_hics203_cost_unit->value(hics203_cost_unit.c_str());
404
405 for (int i = 0; i < 6; i++) {
406 txt_hics203_tech_spc[i]->value(hics203_tech_spc[i].c_str());
407 }
408 }
409
clear_hics203_form()410 void clear_hics203_form()
411 {
412 clear_hics203fields();
413
414 txt_hics203_incident->value("");
415 txt_hics203_date->value("");
416 txt_hics203_time->value("");
417 txt_hics203_op_period->value("");
418 txt_hics203_incident_commander->value("");
419 txt_hics203_incident_safety_officer->value("");
420 txt_hics203_incident_info_officer->value("");
421 txt_hics203_liaison_officer->value("");
422 txt_hics203_prepared_by->value("");
423 txt_hics203_facility->value("");
424 txt_hics203_planning_chief->value("");
425 txt_hics203_planning_other->value("");
426 txt_hics203_res_unit->value("");
427 txt_hics203_sit_unit->value("");
428 txt_hics203_doc_unit->value("");
429 txt_hics203_dem_unit->value("");
430 txt_hics203_log_chief->value("");
431 txt_hics203_log_other->value("");
432 txt_hics203_log_sup_brch->value("");
433 txt_hics203_bus_brch->value("");
434 txt_hics203_stg_mgr->value("");
435 txt_hics203_med_care_brch->value("");
436 txt_hics203_infr_brch->value("");
437 txt_hics203_sec_brch->value("");
438 txt_hics203_hazmat_brch->value("");
439 txt_hics203_hcc_agency->value("");
440 txt_hics203_svc_brch->value("");
441 txt_hics203_hcc_rep->value("");
442 txt_hics203_ext_loc->value("");
443 txt_hics203_ext_rep->value("");
444 txt_hics203_ops_chief->value("");
445 txt_hics203_ops_other->value("");
446 txt_hics203_fin_chief->value("");
447 txt_hics203_fin_other->value("");
448 txt_hics203_time_unit->value("");
449 txt_hics203_proc_unit->value("");
450 txt_hics203_comp_unit->value("");
451 txt_hics203_cost_unit->value("");
452
453 for (int i = 0; i < 6; i++) {
454 txt_hics203_tech_spc[i]->value("");
455 }
456 }
457
hics_n(string & subst,int n)458 string &hics_n(string & subst, int n)
459 {
460 static string garbage = "#$^*!";
461 size_t pos = subst.find("[");
462 if (pos == string::npos) return garbage;
463 pos++;
464 subst[pos] = '0' + n;
465 return subst;
466 }
467
make_hics_buff203(bool compress=false)468 void make_hics_buff203(bool compress = false)
469 {
470 string mbuff;
471 mbuff.assign( lineout( hics203_tag_incident, hics203_incident ) );
472 mbuff.append( lineout( hics203_tag_date, hics203_date ) );
473 mbuff.append( lineout( hics203_tag_time, hics203_time ) );
474 mbuff.append( lineout( hics203_tag_op_period, hics203_op_period ) );
475 mbuff.append( lineout( hics203_tag_incident_commander, hics203_incident_commander ) );
476 mbuff.append( lineout( hics203_tag_incident_safety_officer, hics203_incident_safety_officer ) );
477 mbuff.append( lineout( hics203_tag_incident_info_officer, hics203_incident_info_officer ) );
478 mbuff.append( lineout( hics203_tag_liaison_officer, hics203_liaison_officer ) );
479 mbuff.append( lineout( hics203_tag_prepared_by, hics203_prepared_by ) );
480 mbuff.append( lineout( hics203_tag_facility, hics203_facility ) );
481 mbuff.append( lineout( hics203_tag_planning_chief, hics203_planning_chief ) );
482 mbuff.append( lineout( hics203_tag_planning_other, hics203_planning_other ) );
483 mbuff.append( lineout( hics203_tag_res_unit, hics203_res_unit ) );
484 mbuff.append( lineout( hics203_tag_sit_unit, hics203_sit_unit ) );
485 mbuff.append( lineout( hics203_tag_doc_unit, hics203_doc_unit ) );
486 mbuff.append( lineout( hics203_tag_dem_unit, hics203_dem_unit ) );
487 mbuff.append( lineout( hics203_tag_log_chief, hics203_log_chief ) );
488 mbuff.append( lineout( hics203_tag_log_other, hics203_log_other ) );
489 mbuff.append( lineout( hics203_tag_sup_brch, hics203_log_sup_brch ) );
490 mbuff.append( lineout( hics203_tag_bus_brch, hics203_bus_brch ) );
491 mbuff.append( lineout( hics203_tag_stg_mgr, hics203_stg_mgr ) );
492 mbuff.append( lineout( hics203_tag_med_care_brch, hics203_med_care_brch ) );
493 mbuff.append( lineout( hics203_tag_infr_brch, hics203_infr_brch ) );
494 mbuff.append( lineout( hics203_tag_sec_brch, hics203_sec_brch ) );
495 mbuff.append( lineout( hics203_tag_hazmat_brch, hics203_hazmat_brch ) );
496 mbuff.append( lineout( hics203_tag_hcc_agency, hics203_hcc_agency ) );
497 mbuff.append( lineout( hics203_tag_svc_brch, hics203_svc_brch ) );
498 mbuff.append( lineout( hics203_tag_hcc_rep, hics203_hcc_rep ) );
499 mbuff.append( lineout( hics203_tag_ext_loc, hics203_ext_loc ) );
500 mbuff.append( lineout( hics203_tag_ext_rep, hics203_ext_rep ) );
501 mbuff.append( lineout( hics203_tag_ops_chief, hics203_ops_chief ) );
502 mbuff.append( lineout( hics203_tag_ops_other, hics203_ops_other ) );
503 mbuff.append( lineout( hics203_tag_fin_chief, hics203_fin_chief ) );
504 mbuff.append( lineout( hics203_tag_fin_other, hics203_fin_other ) );
505 mbuff.append( lineout( hics203_tag_time_unit, hics203_time_unit ) );
506 mbuff.append( lineout( hics203_tag_proc_unit, hics203_proc_unit ) );
507 mbuff.append( lineout( hics203_tag_comp_unit, hics203_comp_unit ) );
508 mbuff.append( lineout( hics203_tag_cost_unit, hics203_cost_unit ) );
509
510 for (int i = 0; i < 6; i++) {
511 mbuff.append( lineout( hics_n( hics203_tag_tech_spc, i ), hics203_tech_spc[i] ) );
512 }
513 if (compress) compress_maybe(mbuff);
514 hics_buff203.append(mbuff);
515 }
516
read_hics203_buffer(string data)517 void read_hics203_buffer(string data)
518 {
519 clear_hics203fields();
520 read_header(data);
521
522 hics203_incident = findstr(data, hics203_tag_incident);
523 hics203_date = findstr(data, hics203_tag_date);
524 hics203_time = findstr(data, hics203_tag_time);
525 hics203_op_period = findstr(data, hics203_tag_op_period);
526 hics203_incident_commander = findstr(data, hics203_tag_incident_commander);
527 hics203_incident_safety_officer = findstr(data, hics203_tag_incident_safety_officer);
528 hics203_incident_info_officer = findstr(data, hics203_tag_incident_info_officer);
529 hics203_liaison_officer = findstr(data, hics203_tag_liaison_officer);
530 hics203_prepared_by = findstr(data, hics203_tag_prepared_by);
531 hics203_facility = findstr(data, hics203_tag_facility);
532 hics203_planning_chief = findstr(data, hics203_tag_planning_chief);
533 hics203_planning_other = findstr(data, hics203_tag_planning_other);
534 hics203_res_unit = findstr(data, hics203_tag_res_unit);
535 hics203_sit_unit = findstr(data, hics203_tag_sit_unit);
536 hics203_doc_unit = findstr(data, hics203_tag_doc_unit);
537 hics203_dem_unit = findstr(data, hics203_tag_dem_unit);
538 hics203_log_chief = findstr(data, hics203_tag_log_chief);
539 hics203_log_other = findstr(data, hics203_tag_log_other);
540 hics203_log_sup_brch = findstr(data, hics203_tag_sup_brch);
541 hics203_bus_brch = findstr(data, hics203_tag_bus_brch);
542 hics203_stg_mgr = findstr(data, hics203_tag_stg_mgr);
543 hics203_med_care_brch = findstr(data, hics203_tag_med_care_brch);
544 hics203_infr_brch = findstr(data, hics203_tag_infr_brch);
545 hics203_sec_brch = findstr(data, hics203_tag_sec_brch);
546 hics203_hazmat_brch = findstr(data, hics203_tag_hazmat_brch);
547 hics203_hcc_agency = findstr(data, hics203_tag_hcc_agency);
548 hics203_svc_brch = findstr(data, hics203_tag_svc_brch);
549 hics203_hcc_rep = findstr(data, hics203_tag_hcc_rep);
550 hics203_ext_loc = findstr(data, hics203_tag_ext_loc);
551 hics203_ext_rep = findstr(data, hics203_tag_ext_rep);
552 hics203_ops_chief = findstr(data, hics203_tag_ops_chief);
553 hics203_ops_other = findstr(data, hics203_tag_ops_other);
554 hics203_fin_chief = findstr(data, hics203_tag_fin_chief);
555 hics203_fin_other = findstr(data, hics203_tag_fin_other);
556 hics203_time_unit = findstr(data, hics203_tag_time_unit);
557 hics203_proc_unit = findstr(data, hics203_tag_proc_unit);
558 hics203_comp_unit = findstr(data, hics203_tag_comp_unit);
559 hics203_cost_unit = findstr(data, hics203_tag_cost_unit);
560
561 for (int i = 0; i < 6; i++) {
562 hics203_tech_spc[i] = findstr(data, hics_n( hics203_tag_tech_spc, i) );
563 }
564 update_hics203form();
565 }
566
cb_hics203_new()567 void cb_hics203_new()
568 {
569 if (check_hics203fields()) {
570 if (fl_choice2("Form modified, save?", "No", "Yes", NULL) == 1) {
571 update_header(CHANGED);
572 cb_hics203_save();
573 }
574 }
575 clear_hics203_form();
576 clear_header();
577 def_hics203_filename = ICS_msg_dir;
578 def_hics203_filename.append("new").append(HF203_EXT);
579 show_filename(def_hics203_filename);
580 using_hics203_template = false;
581 }
582
cb_hics203_import()583 void cb_hics203_import()
584 {
585 fl_alert2("Not implemented");
586 }
587
cb_hics203_export()588 void cb_hics203_export()
589 {
590 fl_alert2("Not implemented");
591 }
592
cb_hics203_wrap_import(string wrapfilename,string inpbuffer)593 void cb_hics203_wrap_import(string wrapfilename, string inpbuffer)
594 {
595 clear_hics203_form();
596 read_hics203_buffer(inpbuffer);
597 def_hics203_filename = ICS_msg_dir;
598 def_hics203_filename.append(wrapfilename);
599 show_filename(def_hics203_filename);
600 using_hics203_template = false;
601 }
602
eval_hics203_fsize()603 int eval_hics203_fsize()
604 {
605 Ccrc16 chksum;
606 evalstr.assign("[WRAP:beg][WRAP:lf][WRAP:fn ");
607 evalstr.append(base_hics203_filename).append("]");
608 update_hics203fields();
609 update_header(FROM);
610 evalstr.append(header("<hics203>"));
611 hics_buff203.clear();
612 make_hics_buff203(true);
613 if (hics_buff203.empty()) return 0;
614 compress_maybe( hics_buff203 );
615 evalstr.append( hics_buff203 );
616 evalstr.append("[WRAP:chksum ").append(chksum.scrc16(evalstr)).append("][WRAP:end]");
617 return evalstr.length();
618 }
619
cb_hics203_wrap_export()620 void cb_hics203_wrap_export()
621 {
622 if (check_hics203fields()) {
623 if (fl_choice2("Form modified, save?", "No", "Yes", NULL) == 0)
624 return;
625 update_header(CHANGED);
626 }
627 update_hics203fields();
628
629 if (base_hics203_filename == string("new").append(HF203_EXT) ||
630 base_hics203_filename == string("default").append(HF203_EXT) )
631 if (!cb_hics203_save_as()) return;
632
633 string wrapfilename = WRAP_send_dir;
634 wrapfilename.append(base_hics203_filename);
635 wrapfilename.append(".wrap");
636 const char *p = FSEL::saveas(
637 "Save as wrap file",
638 "Wrap file\t*.{wrap,WRAP}",
639 wrapfilename.c_str());
640 if (p) {
641 string pext = fl_filename_ext(p);
642 wrapfilename = p;
643 update_header(FROM);
644 hics_buff203.assign(header("<hics203>"));
645 make_hics_buff203(true);
646 export_wrapfile(base_hics203_filename, wrapfilename, hics_buff203, pext != ".wrap");
647
648 hics_buff203.assign(header("<hics203>"));
649 make_hics_buff203(false);
650 write_hics203(def_hics203_filename);
651 }
652 }
653
cb_hics203_wrap_autosend()654 void cb_hics203_wrap_autosend()
655 {
656 if (check_hics203fields()) {
657 if (fl_choice2("Form modified, save?", "No", "Yes", NULL) == 0)
658 return;
659 update_header(CHANGED);
660 }
661 update_hics203fields();
662
663 if (base_hics203_filename == string("new").append(HF203_EXT) ||
664 base_hics203_filename == string("default").append(HF203_EXT) )
665 cb_hics203_save_as();
666
667 update_header(FROM);
668 hics_buff203.assign(header("<hics203>"));
669 make_hics_buff203(true);
670 xfr_via_socket(base_hics203_filename, hics_buff203);
671
672 hics_buff203.assign(header("<hics203>"));
673 make_hics_buff203(false);
674 write_hics203(def_hics203_filename);
675 }
676
cb_hics203_load_template()677 void cb_hics203_load_template()
678 {
679 string def_hics203_filename = def_hics203_TemplateName;
680 const char *p = FSEL::select(
681 "Open template file",
682 string("Template file\t*").append(HT203_EXT).c_str(),
683 def_hics203_filename.c_str());
684 if (p) {
685 clear_hics203_form();
686 read_data_file(p);
687 def_hics203_TemplateName = p;
688 show_filename(def_hics203_TemplateName);
689 using_hics203_template = true;
690 }
691 }
692
cb_hics203_save_template()693 void cb_hics203_save_template()
694 {
695 if (!using_hics203_template) {
696 cb_hics203_save_as_template();
697 return;
698 }
699 string def_hics203_filename = def_hics203_TemplateName;
700 const char *p = FSEL::saveas(
701 "Save template file",
702 string("Template file\t*").append(HT203_EXT).c_str(),
703 def_hics203_filename.c_str());
704 if (p) {
705 update_header(CHANGED);
706 update_203fields();
707 hics_buff203.assign(header("<hics203>"));
708 make_hics_buff203();
709 write_hics203(p);
710 }
711 }
712
cb_hics203_save_as_template()713 void cb_hics203_save_as_template()
714 {
715 string def_hics203_filename = def_hics203_TemplateName;
716 const char *p = FSEL::saveas(
717 "Save as template file",
718 string("Template file\t*").append(HT203_EXT).c_str(),
719 def_hics203_filename.c_str());
720 if (p) {
721 const char *pext = fl_filename_ext(p);
722 def_hics203_TemplateName = p;
723 if (strlen(pext) == 0) def_hics203_TemplateName.append(HT203_EXT);
724 remove_spaces_from_filename(def_hics203_TemplateName);
725 clear_header();
726 update_header(CHANGED);
727 update_203fields();
728 hics_buff203.assign(header("<hics203>"));
729 make_hics_buff203();
730 write_hics203(def_hics203_TemplateName);
731 show_filename(def_hics203_TemplateName);
732 using_hics203_template = true;
733 }
734 }
735
cb_hics203_open()736 void cb_hics203_open()
737 {
738 const char *p = FSEL::select(
739 _("Open data file"),
740 string("HICS-203\t*").append(HF203_EXT).c_str(),
741 def_hics203_filename.c_str());
742 if (!p) return;
743 if (strlen(p) == 0) return;
744 clear_hics203_form();
745 read_data_file(p);
746 using_hics203_template = false;
747 def_hics203_filename = p;
748 show_filename(def_hics203_filename);
749 }
750
write_hics203(string s)751 void write_hics203(string s)
752 {
753 FILE *file203 = fopen(s.c_str(), "w");
754 if (!file203) return;
755
756 fwrite(hics_buff203.c_str(), hics_buff203.length(), 1, file203);
757 fclose(file203);
758 }
759
cb_hics203_save_as()760 bool cb_hics203_save_as()
761 {
762 const char *p;
763 string newfilename;
764
765 string name = named_file();
766 if (!name.empty()) {
767 name.append(F203_EXT);
768 newfilename = ICS_msg_dir;
769 newfilename.append(name);
770 } else
771 newfilename = def_hics203_filename;
772
773 p = FSEL::saveas(
774 _("Save data file"),
775 string("HICS-203\t*").append(HF203_EXT).c_str(),
776 newfilename.c_str());
777
778 if (!p) return false;
779 if (strlen(p) == 0) return false;
780
781 if (progStatus.sernbr_fname) update_sernbr();
782
783 const char *pext = fl_filename_ext(p);
784 def_hics203_filename = p;
785 if (strlen(pext) == 0) def_hics203_filename.append(HF203_EXT);
786
787 remove_spaces_from_filename(def_hics203_filename);
788 update_hics203fields();
789 update_header(NEW);
790 hics_buff203.assign(header("<hics203>"));
791 make_hics_buff203();
792 write_hics203(def_hics203_filename);
793
794 using_hics203_template = false;
795 show_filename(def_hics203_filename);
796 return true;
797 }
798
cb_hics203_save()799 void cb_hics203_save()
800 {
801 if (base_hics203_filename == string("new").append(HF203_EXT) ||
802 base_hics203_filename == string("default").append(HF203_EXT) ||
803 using_hics203_template == true) {
804 cb_hics203_save_as();
805 return;
806 }
807 if (check_hics203fields()) update_header(CHANGED);
808 update_hics203fields();
809 hics_buff203.assign(header("<hics203>"));
810 make_hics_buff203();
811 write_hics203(def_hics203_filename);
812 using_hics203_template = false;
813 }
814
cb_hics203_html()815 void cb_hics203_html()
816 {
817 string fname_name = fl_filename_name(def_hics203_filename.c_str());
818 size_t p = fname_name.rfind('.');
819 if (p != string::npos) fname_name.erase(p);
820
821 string hics203_fname = ICS_dir;
822 hics203_fname.append(fname_name);
823 hics203_fname.append(".html");
824
825 string html_text = "";
826
827 update_hics203fields();
828 string form203 = hics203_html_template;
829 replacestr(form203, TITLE, fname_name);
830
831 replacestr(form203, hics203_tag_incident, hics203_incident );
832 replacestr(form203, hics203_tag_date, hics203_date );
833 replacestr(form203, hics203_tag_time, hics203_time );
834 replacestr(form203, hics203_tag_op_period, hics203_op_period );
835 replacestr(form203, hics203_tag_incident_commander, hics203_incident_commander );
836 replacestr(form203, hics203_tag_incident_safety_officer, hics203_incident_safety_officer );
837 replacestr(form203, hics203_tag_incident_info_officer, hics203_incident_info_officer );
838 replacestr(form203, hics203_tag_liaison_officer, hics203_liaison_officer );
839 replacestr(form203, hics203_tag_prepared_by, hics203_prepared_by );
840 replacestr(form203, hics203_tag_facility, hics203_facility );
841 replacestr(form203, hics203_tag_planning_chief, hics203_planning_chief );
842 replacestr(form203, hics203_tag_planning_other, hics203_planning_other );
843 replacestr(form203, hics203_tag_res_unit, hics203_res_unit );
844 replacestr(form203, hics203_tag_sit_unit, hics203_sit_unit );
845 replacestr(form203, hics203_tag_doc_unit, hics203_doc_unit );
846 replacestr(form203, hics203_tag_dem_unit, hics203_dem_unit );
847 replacestr(form203, hics203_tag_log_chief, hics203_log_chief );
848 replacestr(form203, hics203_tag_log_other, hics203_log_other );
849 replacestr(form203, hics203_tag_sup_brch, hics203_log_sup_brch );
850 replacestr(form203, hics203_tag_bus_brch, hics203_bus_brch );
851 replacestr(form203, hics203_tag_stg_mgr, hics203_stg_mgr);
852 replacestr(form203, hics203_tag_med_care_brch, hics203_med_care_brch);
853 replacestr(form203, hics203_tag_infr_brch, hics203_infr_brch);
854 replacestr(form203, hics203_tag_sec_brch, hics203_sec_brch);
855 replacestr(form203, hics203_tag_hazmat_brch, hics203_hazmat_brch );
856 replacestr(form203, hics203_tag_hcc_agency, hics203_hcc_agency );
857 replacestr(form203, hics203_tag_svc_brch, hics203_svc_brch );
858 replacestr(form203, hics203_tag_hcc_rep, hics203_hcc_rep );
859 replacestr(form203, hics203_tag_ext_loc, hics203_ext_loc );
860 replacestr(form203, hics203_tag_ext_rep, hics203_ext_rep );
861 replacestr(form203, hics203_tag_ops_chief, hics203_ops_chief );
862 replacestr(form203, hics203_tag_ops_other, hics203_ops_other );
863 replacestr(form203, hics203_tag_fin_chief, hics203_fin_chief );
864 replacestr(form203, hics203_tag_fin_other, hics203_fin_other );
865 replacestr(form203, hics203_tag_time_unit, hics203_time_unit );
866 replacestr(form203, hics203_tag_proc_unit, hics203_proc_unit );
867 replacestr(form203, hics203_tag_comp_unit, hics203_comp_unit );
868 replacestr(form203, hics203_tag_cost_unit, hics203_cost_unit );
869
870 for (int i = 0; i < 6; i++) {
871 replacestr(form203, hics_n( hics203_tag_tech_spc, i ), hics203_tech_spc[i] );
872 }
873
874 FILE *file203 = fopen(hics203_fname.c_str(), "w");
875 fprintf(file203,"%s", form203.c_str());
876 fclose(file203);
877
878 open_url(hics203_fname.c_str());
879 }
880
cb_hics203_msg_type()881 void cb_hics203_msg_type()
882 {
883 if (tabs_msg_type->value() == tab_hics203 ) {
884 tab_hics203_type->value(tab_hics203_1);
885 show_filename(def_hics203_filename);
886 }
887 }
888
cb_hics203_textout()889 void cb_hics203_textout()
890 {
891 string hics203_fname = ICS_dir;
892 hics203_fname.append("hics203.txt");
893
894 update_hics203fields();
895 string form203 = hics203_text_template;
896
897 replacestr(form203, hics203_tag_incident, hics203_incident );
898 replacestr(form203, hics203_tag_date, hics203_date );
899 replacestr(form203, hics203_tag_time, hics203_time );
900 replacestr(form203, hics203_tag_op_period, hics203_op_period );
901 replacestr(form203, hics203_tag_incident_commander, hics203_incident_commander );
902 replacestr(form203, hics203_tag_incident_safety_officer, hics203_incident_safety_officer );
903 replacestr(form203, hics203_tag_incident_info_officer, hics203_incident_info_officer );
904 replacestr(form203, hics203_tag_liaison_officer, hics203_liaison_officer );
905 replacestr(form203, hics203_tag_prepared_by, hics203_prepared_by );
906 replacestr(form203, hics203_tag_facility, hics203_facility );
907 replacestr(form203, hics203_tag_planning_chief, hics203_planning_chief );
908 replacestr(form203, hics203_tag_planning_other, hics203_planning_other );
909 replacestr(form203, hics203_tag_res_unit, hics203_res_unit );
910 replacestr(form203, hics203_tag_sit_unit, hics203_sit_unit );
911 replacestr(form203, hics203_tag_doc_unit, hics203_doc_unit );
912 replacestr(form203, hics203_tag_dem_unit, hics203_dem_unit );
913 replacestr(form203, hics203_tag_log_chief, hics203_log_chief );
914 replacestr(form203, hics203_tag_log_other, hics203_log_other );
915 replacestr(form203, hics203_tag_sup_brch, hics203_log_sup_brch );
916 replacestr(form203, hics203_tag_bus_brch, hics203_bus_brch );
917 replacestr(form203, hics203_tag_stg_mgr, hics203_stg_mgr);
918 replacestr(form203, hics203_tag_med_care_brch, hics203_med_care_brch);
919 replacestr(form203, hics203_tag_infr_brch, hics203_infr_brch);
920 replacestr(form203, hics203_tag_sec_brch, hics203_sec_brch);
921 replacestr(form203, hics203_tag_hazmat_brch, hics203_hazmat_brch );
922 replacestr(form203, hics203_tag_hcc_agency, hics203_hcc_agency );
923 replacestr(form203, hics203_tag_svc_brch, hics203_svc_brch );
924 replacestr(form203, hics203_tag_hcc_rep, hics203_hcc_rep );
925 replacestr(form203, hics203_tag_ext_loc, hics203_ext_loc );
926 replacestr(form203, hics203_tag_ext_rep, hics203_ext_rep );
927 replacestr(form203, hics203_tag_ops_chief, hics203_ops_chief );
928 replacestr(form203, hics203_tag_ops_other, hics203_ops_other );
929 replacestr(form203, hics203_tag_fin_chief, hics203_fin_chief );
930 replacestr(form203, hics203_tag_fin_other, hics203_fin_other );
931 replacestr(form203, hics203_tag_time_unit, hics203_time_unit );
932 replacestr(form203, hics203_tag_proc_unit, hics203_proc_unit );
933 replacestr(form203, hics203_tag_comp_unit, hics203_comp_unit );
934 replacestr(form203, hics203_tag_cost_unit, hics203_cost_unit );
935
936 for (int i = 0; i < 6; i++) {
937 replacestr(form203, hics_n( hics203_tag_tech_spc, i ), hics203_tech_spc[i] );
938 }
939
940 FILE *file203 = fopen(hics203_fname.c_str(), "w");
941 fprintf(file203,"%s", form203.c_str());
942 fclose(file203);
943
944 open_url(hics203_fname.c_str());
945 }
946