Repository navigation
Expand file tree
/
Copy pathprofile.php
More file actions
1133 lines (831 loc) · 33.5 KB
/
Copy pathprofile.php
File metadata and controls
1133 lines (831 loc) · 33.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/************************************************************************************
t. schneider | tes at mit.edu | 11.1.07
laboratory for autonomous marine sensing systems
profile.php - allows users to create profiles to view in google earth
three types of profiles
-realtime : see vehicles from now looking back a set amount of time - requires constant
queries to the webserver (1 second is good)
-playback: similar to realtime but define "now" as a point in the past that progresses
at some rate (also requires constant queries to the server)
-history: show a block of time and vehicles that can be manipulated directly in
google earth once it is loaded in
************************************************************************************/
/************************************************************************************
definitions
************************************************************************************/
// connections from a web browser are defined in this system as 1, google earth is 2
define("HTTP_CLIENT_ID", 1);
define("GE_CLIENT_ID", 2);
/************************************************************************************
connections
************************************************************************************/
require_once('connections/mysql.php');
/************************************************************************************
function includes
************************************************************************************/
include_once('includes/geov_html_writer.php');
include_once('includes/ge_functions.php');
include_once('includes/module_class.php');
$html = new geov_html_writer();
/************************************************************************************
handle url variables (POST/GET)
************************************************************************************/
// determine actions to undertake before displaying page
$get_actions = array();
$post_actions = array('logout', 'profile_change','sort', 'login', 'profile', 'save', 'delete', 'copy', 'rename', 'copy_module', 'switch_realism');
$do = "nothing";
foreach($get_actions as $action)
$do = (isset($_GET[$action])) ? $action : $do;
foreach($post_actions as $action)
$do = (isset($_POST[$action])) ? $action : $do;
$sort = (isset($_GET['sort'])) ? $_GET['sort'] : "vehicle_type ASC, vehicle_name ASC";
// determine other variables
list($cid, $username, $userid, $last_message) = finduserfromip();
// find the profile related to this user
$profileid = (isset($_POST['profile_id_rt']) || isset($_POST['profile_id_pb']) || isset($_POST['profile_id_hist'])) ?
max($_POST['profile_id_rt'],$_POST['profile_id_pb'], $_POST['profile_id_hist']) :
mysql_get_single_value("SELECT user_active_profileid ".
"FROM core_user ".
"WHERE user_id = ".$userid);
/************************************************************************************
define classes
************************************************************************************/
$module_class = instantiate_modules($profileid);
/************************************************************************************
do stuff (pre html actions)
************************************************************************************/
$message = "";
switch($do)
{
default:
break;
// post actions
case "logout":
/************************************************************************************
logout
************************************************************************************/
mysqli_query($connection,"DELETE FROM core_connected ".
"WHERE connected_ip = '".$_SERVER['REMOTE_ADDR']."' ".
"AND connected_client='".HTTP_CLIENT_ID."'")
or die(mysqli_error($connection));
$userid = 0;
header_with_message();
break;
case "profile_change":
/************************************************************************************
allow the user to select a new profile
************************************************************************************/
mysqli_query($connection,"UPDATE core_user ".
"SET user_active_profileid = 0 ".
"WHERE user_id = ".$userid)
or die(mysqli_error($connection));
$profileid = 0;
header_with_message();
break;
case "sort":
/************************************************************************************
update sort options
************************************************************************************/
profile_save($profileid);
foreach($_POST['sort'] as $type => $value);
mysqli_query($connection,"UPDATE core_profile ".
"SET profile_sort = '".$type."' ".
"WHERE profile_id = ".$profileid)
or die(mysqli_error($connection));
header_with_message("vehicle_table");
break;
case "login":
/************************************************************************************
login
************************************************************************************/
// passed from the select menu
$userid = $_POST['user_id'];
if (!$userid && $_POST['user_name'] == "")
{
$message .= "error: you must specify a user or enter a new user name.\n";
break;
}
// see if someone already has this user name
if (!$userid)
{
$user_name = mysqli_real_escape_string($connection, $_POST['user_name']);
$query_find =
"SELECT user_id ".
"FROM core_user ".
"WHERE user_name = '".$user_name."'";
// is that user name not in the database
if (!mysql_get_num_rows($query_find))
{
// no, create it
mysqli_query($connection,"INSERT INTO core_user (user_name, user_active_profileid) ".
"VALUES ('".$user_name."', 0)")
or die(mysqli_error($connection));
$userid = mysqli_insert_id($connection);
}
else
{
$message .= "error: user exists.\n";
break;
}
}
// create a new connection
mysqli_query($connection,"INSERT INTO ".
" core_connected ".
" (connected_ip, ".
" connected_userid, ".
" connected_client) ".
"VALUES".
" ('".$_SERVER['REMOTE_ADDR']."', ".
" '$userid', ".
" '".HTTP_CLIENT_ID."')")
or die(mysqli_error($connection));
list($cid, $username, $userid, $last_message) = finduserfromip();
// find the profile related to this user
$profileid = mysql_get_single_value("SELECT user_active_profileid ".
"FROM core_user ".
"WHERE user_id = ".$userid);
if($profileid)
$message .= "your last active profile has been loaded. click (change profile) to edit a different profile or create a new one.\n";
header_with_message();
break;
case "profile":
/************************************************************************************
create a new profile or retrieve an old one
************************************************************************************/
if(isset($_POST['profile']['auto']))
{
$ip = $_SERVER['REMOTE_ADDR'];
$profileid = mysql_get_single_value("SELECT connected_profileid FROM core_connected WHERE connected_ip = '$ip' AND connected_client = ".GE_CLIENT_ID);
}
if (!$profileid && $_POST['profile_name'] == "")
{
$message .= "error: you must specify a profile to edit or enter a new profile name.\n";
header_with_message();
break;
}
if (!$profileid)
{
$profileid = mysql_get_single_value("SELECT (max(profile_id) + 1) FROM core_profile");
if($profileid == 0)
$profileid = 1;
if($module_class)
{
foreach($module_class as $module)
{
$module->create($profileid, $_POST['profile_name'], $_POST['profile_mode'], $userid);
}
}
}
$query =
"UPDATE core_user ".
"SET user_active_profileid = '$profileid' ".
"WHERE user_id = '$userid'";
mysqli_query($connection,$query) or die(mysqli_error($connection));
header_with_message();
break;
case "save":
profile_save($profileid);
// jumps to part of page where "apply" button was pushed.
if(is_array($_POST['save']))
{
foreach($_POST['save'] as $key => $value)
{
$location = $key;
}
}
header_with_message($location);
break;
case "delete":
/************************************************************************************
delete this profile
************************************************************************************/
if($_POST['delete_confirm'] != "DELETE")
{
$message .= "you must type DELETE in the box below to confirm this delete.\n";
break;
}
list($profilename, $profilemode, $simulation) = findprofinfo($profileid);
$message .= "profile '".$profilename."' deleted.\n";
$query =
"SELECT connected_id FROM core_connected WHERE connected_profileid=$profileid";
$result = mysqli_query($connection,$query) or die(mysqli_error($connection));
while($row = mysqli_fetch_assoc($result))
{
$cidarray[] = $row["connected_id"];
}
foreach($module_class as $module)
{
$module->delete($profileid, $cidarray);
}
mysqli_query($connection,"UPDATE core_user ".
"SET user_active_profileid = 0 ".
"WHERE user_id = ".$userid)
or die(mysqli_error($connection));
$profileid = 0;
header_with_message();
break;
case "rename":
/************************************************************************************
rename the profile
************************************************************************************/
profile_save($profileid);
$new_name = $_POST['rename_profile_name'];
$new_type = $_POST['rename_profile_type'];
if($new_name == "")
{
$message .= "profile name cannot be blank.\n";
break;
}
mysqli_query($connection,"UPDATE core_profile ".
"SET profile_name = '".$new_name."', ".
" profile_mode = '".$new_type."' ".
"WHERE profile_id = ".$profileid)
or die(mysqli_error($connection));
$message .= "profile renamed to '".$new_name."'.\n";
header_with_message();
break;
case "copy":
/************************************************************************************
create a copy of the profile
************************************************************************************/
profile_save($profileid);
// use $_POST['copy_user_id'] to copy to
$new_profileid = mysql_get_single_value("SELECT (max(profile_id) + 1) FROM core_profile");
foreach($module_class as $module)
{
$module->copy($profileid, $new_profileid, $_POST['copy_user_id']);
}
$message .= "profile copied.";
header_with_message();
break;
case "copy_module":
/************************************************************************************
copies module configuration from one profile to another
************************************************************************************/
profile_save($profileid);
if($_POST['copy_module_name'] && $_POST['copy_module_profile'])
{
$module_class[$_POST['copy_module_name']]->copy($profileid, $_POST['copy_module_profile'], $userid);
$message .= "module copied.";
$query =
"REPLACE core_profile_module (p_module_profileid, p_module_moduleid) ".
"VALUES ('".$_POST['copy_module_profile']."','".$_POST['copy_module_name']."' )";
mysqli_query($connection,$query) or die(mysqli_error($connection));
}
else
{
$message .= "invalid selection.";
}
header_with_message();
break;
case "switch_realism":
profile_save($profileid);
/************************************************************************************
toggles between showing simulated data and real data
************************************************************************************/
mysqli_query($connection,"UPDATE core_profile ".
"SET profile_simulation = !profile_simulation ".
"WHERE profile_id = ".$profileid)
or die(mysqli_error($connection));
header_with_message();
break;
}
/************************************************************************************
start html output (no header() past here)
************************************************************************************/
include "includes/geov_header.php";
$html->h2("profile manager");
$html->hr();
$html->navbar("profile manager");
$html->hr();
$html->push("form", array("method"=>"post", "action"=>"profile.php"));
if($last_message != "" || $message != "")
{
$html->pre($last_message.$message);
$html->hr();
}
if(!$userid)
{
/************************************************************************************
show first layer - that is, let the user log in
************************************************************************************/
$html->h3("specify a user:");
$query_users =
"SELECT user_id, user_name ".
"FROM core_user ".
"ORDER BY user_name ASC";
$users = mysqli_query($connection,$query_users) or die(mysqli_error($connection));
$value[0] = 0;
$text[0] = "(choose existing user)";
while($row_users = mysqli_fetch_assoc($users))
{
$value[] = $row_users['user_id'];
$text[] = stripslashes($row_users['user_name']);
}
$html->push("p");
$html->input_select("user_id", $value, $text, 0);
$html->pop();
$html->p("<strong>or</strong> enter a new user name:");
$html->push("p");
$html->input_text("user_name", "");
$html->pop();
$html->push("p");
$html->button("log in", array("name"=>"login", "type"=>"submit"));
$html->pop();
}
else if(!$profileid)
{
/************************************************************************************
show second layer - determine the profile
************************************************************************************/
$html->h3("select a profile:");
$query =
"SELECT ".
" profile_id, ".
" profile_name, ".
" profile_createtime, ".
" profile_mode ".
"FROM ".
" core_profile ".
"WHERE ".
" profile_userid = '$userid' ".
"ORDER BY ".
" profile_name ".
"ASC";
$result = mysqli_query($connection,$query) or die(mysqli_error($connection));
$value_rt[0] = 0;
$text_rt[0] = "(realtime saved profiles)";
$value_pb[0] = 0;
$text_pb[0] = "(playback saved profiles)";
$value_hist[0] = 0;
$text_hist[0] = "(history saved profiles)";
while($row = mysqli_fetch_assoc($result))
{
switch($row['profile_mode'])
{
case "realtime":
$value_rt[] = $row['profile_id'];
$text_rt[] =
stripslashes($row['profile_name']);
break;
case "playback":
$value_pb[] = $row['profile_id'];
$text_pb[] =
stripslashes($row['profile_name']);
break;
case "history":
$value_hist[] = $row['profile_id'];
$text_hist[] =
stripslashes($row['profile_name']);
break;
}
}
$html->push("p");
$html->input_select("profile_id_rt", $value_rt, $text_rt, 0);
$html->pop();
$html->push("p");
$html->input_select("profile_id_pb", $value_pb, $text_pb, 0);
$html->pop();
$html->push("p");
$html->input_select("profile_id_hist", $value_hist, $text_hist, 0);
$html->pop();
$html->push("p");
$html->button("submit", array("name"=>"profile", "type"=>"submit"));
$html->insert(" | ");
$html->button("show currently bound profile", array("name"=>"profile[auto]", "type"=>"submit"));
$html->pop();
$html->p(" <strong>or</strong> enter a new profile name:");
$mode_value = array("realtime", "playback", "history");
$html->push("p");
$html->input_text("profile_name", "");
$html->insert(" of type ");
$html->input_select("profile_mode", $mode_value, $mode_value, 1);
$html->pop();
$html->push("p");
$html->button("submit", array("name"=>"profile", "type"=>"submit"));
$html->pop();
$html->hr();
$html->push("div");
showuserin($username);
$html->pop(); //</div>
}
else
{
/************************************************************************************
show final layer - editing the profile
************************************************************************************/
list($profilename, $profilemode, $simulation) = findprofinfo($profileid);
$html->push("div");
showprofilein($profilename, $profilemode, $username, $simulation);
$html->pop(); //</div>
$html->hr();
// add any profile modules that don't exist
foreach($module_class as $module)
{
if(!($module->profile_exists($profileid)))
$module->create($profileid);
}
// show ip binding
$html->p_jump("bind");
$html->push("h3");
$html->insert("choose one or more computers running google earth <br /> on which you would like to run this profile:");
$html->pop(); // </h3>
$html->h4("add bindings:");
$html->push("p");
$html->insert("(typical) bind to this machine's ip (".
$_SERVER['REMOTE_ADDR']."): ");
$html->input_checkbox("iplocal", false);
$html->insert("<br /> <strong>or</strong> manually enter other ip address: ");
$html->input_text("ip0", "", 3);
$html->insert(".");
$html->input_text("ip1", "", 3);
$html->insert(".");
$html->input_text("ip2", "", 3);
$html->insert(".");
$html->input_text("ip3", "", 3);
$html->pop(); // </p>
$html->h4("remove bindings:");
$query =
"SELECT connected_ip ".
"FROM core_connected ".
"WHERE connected_profileid = $profileid";
$result = mysqli_query($connection,$query) or die(mysqli_error($connection));
if(mysqli_num_rows($result))
{
$html->push("p");
while($row = mysqli_fetch_assoc($result))
{
$html->insert(" ");
$html->input_checkbox("unbind[".$row["connected_ip"]."]", false);
$html->insert($row["connected_ip"]);
}
$html->pop(); // </p>
}
else
{
$html->p("(no bindings: you must bind the IP address of the computer running google earth)", array("class"=>"red"));
}
$html->push("p");
$html->button("apply", array("name"=>"save"));
$html->pop(); // </p>
$html->hr();
$html->p_jump("vehicle_config");
$html->push("h3");
$html->insert("choose and configure the vehicles you wish to see:");
$html->pop(); // </h3>
$html->p("pick <strong>vehicle(s)</strong> and addon <strong>module(s)</strong>, then click apply.");
// show boxes as to what should be displayed
$query =
"SELECT ".
" vehicle_id, ".
" vehicle_name ".
"FROM core_vehicle ".
"WHERE vehicle_disabled = 0 ".
"ORDER BY vehicle_name ASC";
$result = mysqli_query($connection,$query) or die(mysqli_error($connection));
while ($row = mysqli_fetch_assoc($result))
{
$v_name[] = $row['vehicle_name'];
$v_id[] = $row['vehicle_id'];
}
$query =
"SELECT ".
" module_name, ".
" module_id ".
"FROM core_module ".
"ORDER BY module_name ASC";
$result = mysqli_query($connection,$query) or die(mysqli_error($connection));
while ($row = mysqli_fetch_assoc($result))
{
$v_module[] = $row['module_name'];
$v_module_id[] = $row['module_id'];
}
$html->push("p");
$html->input_array_select("show[name][]", $v_id, $v_name, array(), 10);
$html->input_array_select("show[module][]", $v_module_id, $v_module, array(), 10);
$html->pop(); // </p>
$html->push("p");
$html->button("apply", array("name"=>"save[vehicle_config]", "type"=>"submit"));
$html->pop(); // </p>
$html->hr();
$html->p_jump("vehicle_table");
if(mysql_get_num_rows("SELECT vehicle_id FROM core_vehicle LIMIT 1"))
{
// show table for vehicles
$html->push("table");
foreach($module_class as $module)
{
$module->veh_parameter_disp($profileid, $profilemode);
}
$html->pop(); //</table>
}
$html->push("p");
$html->button("apply", array("name"=>"save[vehicle_table]", "type"=>"submit"));
$html->pop(); // </p>
$html->hr();
$html->p_jump("non_vehicle_config");
$html->push("h3");
$html->insert("configure parameters not specific to each vehicle:");
$html->pop();
// show options for profile (not vehicle specific)
foreach($module_class as $module)
{
$module->gen_parameter_disp($profileid, $profilemode);
}
$html->push("p");
$html->button("apply", array("name"=>"save[non_vehicle_config]", "type"=>"submit"));
$html->pop(); // </p>
$html->hr();
//other profile actions
$html->p_jump("profile_actions");
$html->push("h3");
$html->insert("profile actions:");
$html->pop();
$html->push("p");
$html->insert("rename profile / change mode: ");
$html->input_text("rename_profile_name", $profilename);
$html->input_select("rename_profile_type", array("realtime", "playback", "history"), array("realtime", "playback", "history"), $profilemode);
$html->pop(); //</p>
$html->push("p");
$html->button("rename", array("name"=>"rename","type"=>"submit"));
$html->pop(); //</p>
$query_users =
"SELECT user_id, user_name ".
"FROM core_user ".
"ORDER BY user_name ASC";
$users = mysqli_query($connection,$query_users) or die(mysqli_error($connection));
$value = array();
$value[0] = 0;
$text[0] = "(choose user)";
while($row_users = mysqli_fetch_assoc($users))
{
$value[] = $row_users['user_id'];
$text[] = stripslashes($row_users['user_name']);
}
$html->push("p");
$html->insert("create copy for: ");
$html->input_select("copy_user_id", $value, $text, 0);
$html->pop(); //</p>
$html->push("p");
$html->button("copy", array("name"=>"copy","type"=>"submit"));
$html->pop(); //</p>
$html->push("p");
$html->insert("copy module config for module: ");
unset($value, $text);
$value[0] = 0;
$text[0] = "(choose module)";
foreach($module_class as $id=>$module)
{
if($module->name() != "core")
{
$value[] = $id;
$text[] = $module->name();
}
}
$html->input_select("copy_module_name", $value, $text, 0);
$html->insert("to profile: ");
unset($value, $text);
$value[0] = 0;
$text[0] = "(choose profile)";
$query =
"SELECT ".
" profile_id, ".
" profile_name, ".
" profile_mode ".
"FROM ".
" core_profile ".
"WHERE ".
" profile_userid = '$userid' ".
"ORDER BY ".
" profile_mode, profile_name ".
"ASC";
$result = mysqli_query($connection,$query) or die(mysqli_error($connection));
while($row=mysqli_fetch_assoc($result))
{
$value[] = $row["profile_id"];
$text[] = $row["profile_name"]." (".$row["profile_mode"].")";
}
$html->input_select("copy_module_profile", $value, $text, 0);
$html->pop(); //</p>
$html->push("p");
$html->button("copy module config", array("name"=>"copy_module","type"=>"submit"));
$html->pop(); //</p>
//submission buttons
$html->p("delete profile by typing DELETE in the box:");
$html->push("p");
$html->input_text("delete_confirm", "", 10);
$html->insert(" ");
$html->button("delete", array("name"=>"delete", "type"=>"submit"));
$html->pop(); //</p>
$html->hr();
showprofilein($profilename, $profilemode, $username, $simulation);
}
$html->pop(); //</form>
$html->hr();
include "includes/geov_footer.php";
// closes all tags
$html->echo_html();
/************************************************************************************
functions
************************************************************************************/
function findprofinfo($profileid)
{
$query =
"SELECT profile_name, profile_mode, profile_simulation ".
"FROM core_profile ".
"WHERE profile_id = '$profileid'";
global $connection;
$result = mysqli_query($connection,$query) or die(mysqli_error($connection));
$row = mysqli_fetch_assoc($result);
return array(stripslashes($row['profile_name']), $row['profile_mode'], $row['profile_simulation']);
}
function showuserin($username)
{
global $html;
$html->push("span");
$html->insert("logged in user: <strong>".$username."</strong>"." » ");
$html->button("logout",array("name"=>"logout","type"=>"submit"));
$html->pop(); //</span>
}
function showprofilein($profilename, $profilemode, $username, $simulation)
{
global $html;
$html->push("span");
$html->insert("editing profile: <strong>$profilename</strong> / <em>$profilemode</em> » ");
$html->button("change profile", array("name"=>"profile_change", "type"=>"submit"));
$html->insert(" | ");
$html->pop(); // </span>
$html->push("span");
if(!$simulation)
{
$html->insert("<strong>showing real data <em>only</em></strong> » ");
$html->button("show simulation", array("name"=>"switch_realism", "type"=>"submit"));
}
else
{
$html->insert("<strong>showing simulated data <em>only</em></strong> » ");
$html->button("show real data", array("name"=>"switch_realism", "type"=>"submit"));
}
$html->insert(" | ");
$html->pop(); // </span>
showuserin($username);
if($profilemode == "playback")
{
global $profileid;
$html->span(" / (<a href=\"playbackctrl.php?id=".$profileid."\" target=\"_new\">launch playback controls</a>)");
}
}
//returns the vehicle name from its id
function vid2name($vid)
{
return mysql_get_single_value("SELECT vehicle_name ".
"FROM core_vehicle ".
"WHERE vehicle_id = $vid");
}
function profile_save($profileid)
{
global $html;
global $connection;
global $vehicleid;
global $message;
global $module_class;
global $userid;
/************************************************************************************
save the profile information
-update the profile
-clear all the profile_vehicle rows
-add the needed profile_vehicle rows
************************************************************************************/
if(!$profileid)
return;
list($profilename, $profilemode, $simulation) = findprofinfo($profileid);
// update vehicles and modules to show
if(isset($_POST['show']))
{
foreach($_POST['show'] as $type => $type_array)
{
if($type == "name")
{
foreach($type_array as $vid)
{
foreach($module_class as $module)
{
$module->add_vehicle_row($profileid, $vid, true);
}
}
}
else if($type == "module")
{
foreach($type_array as $mid)
{
$query =
"DELETE FROM core_profile_module ".
"WHERE p_module_moduleid = '".$mid."' ".
"AND p_module_profileid = ".$profileid;
mysqli_query($connection,$query) or die(mysqli_error($connection));
$query =
"INSERT INTO core_profile_module ".
" (p_module_profileid, p_module_moduleid) ".
"VALUES ".
" ('$profileid', '$mid')";