/
planet-info
executable file
·121 lines (110 loc) · 4.2 KB
/
planet-info
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
#!/usr/bin/perl -w
# safe 070204 (except comment)
use strict;
use CGI ":standard";
my $title="manage planet info";
my %options;
use awstandard;
use awinput;
awinput_init();
our @weekday1=qw(sun mon tue wed thu fri sat);
our @weekday2=qw(sunday monday tuesday wednesday thursday friday saturday);
my $weekdays=join("\\b|\\b",@weekday2,@weekday1);
my $weekdayre=qr/($weekdays)/i;
sub weekday2date($) {
my $w=lc($_[0]);
for my $i (0..6) {
if($w eq $weekday1[$i] or $w eq $weekday2[$i]) {
my $t=time;# to allow -1..+5 range: -24*3600;
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) = gmtime($t);
my $diff=($i-$wday)%7;
# print "$wday $diff $w\n";
return AWisodate($t+$diff*24*3600);
}
}
return "?";
}
print AWheader($title);
for my $p (qw'id status who comment submit') {
$options{$p}=param($p);
}
html_encode($options{comment});
if(param("legend")) {
print "legend: ";
for my $n (1..7) {
my $color=getstatuscolor($n);
print span({-style=>'color: '.$color}, br."$n $color = $planetstatusstring{$n}\n");
}
print AWtail;
exit 0; # modperl OK
}
$options{status}+=0;
if($options{status} && $options{status}>=1 && $options{status}<=9) {
if($options{who}!~/^[0-9]+$/) {
$options{who}=playername2id($options{who}); # sanitizes
}
if(!$options{who}) {$options{who}=2};
if($options{id}!~m/^(\d+)#(\d+)$/) {print "invalid system/planet id\n",AWtail; exit 0; } # modperl OK
my ($sid,$pid)=($1,$2);
my @pinfo=getplanetinfo($sid,$pid,1);
my $mod=(@pinfo)? "modified" : "added";
my $plinfo;
if($options{submit} && $options{submit}=~/delete/) {
$mod="deleted";
} else {
#$options{info}=$options{comment};
for($options{comment}) {
s/\btomorrow\b/in 1 d/i;
s/\bnow\b/in 0 h/i;
s/\btoday\b/in 0 d/i;
s/\byesterday\b/in -1 d/i;
s/\bin ([-+]?\d+) (days|d)\b/AWisodate(time()+3600*24*$1)/ge;
s/\bin (\d+) (hours|h)\b/AWisodatetime(time()+3600*$1)/ge;
s/$weekdayre(?!=)\b/$1."=".weekday2date($1)/ge;
param('comment', $_);
}
$plinfo={"sidpid"=>sidpid22sidpid3($sid,$pid), "status"=>$options{status}, "who"=>$options{who}, "info"=>$options{comment}};
}
setplanetinfo($pinfo[3], $plinfo);
print span({-style=>'color: darkgreen'},"$mod $options{id}"),br;
}
if($options{id}) {
my $id=$options{id};
if($id!~m/(\d+)#(\d+)/) {print "invalid system/planet id\n",AWtail; exit 0; } # modperl OK
my ($sid,$pid)=($1,$2);
print qq!<a href="?legend=1">legend</a>!,br;
my $new="edit existing entry";
my $link="";
my $pim=getplanetinfom($sid,$pid);
my @pinfo;
if(!$pim) {
$options{status}=1;
$options{who}=2;
$options{comment}="";
$new=span({-style=>'color: red'},"add new entry");
} else {
@pinfo=($pim->[3],$pim->[4],$pim->[8]);
($options{status},$options{who},$options{comment})=@pinfo;
my $name=playerid2name($options{who});
$link=qq! - <a href="relations?name=$name">info on $name</a>!;
print "last modified by: ",playerid2link($pim->[5]), " , last modified at: ",scalar gmtime $pim->[6],br;
}
print start_form(-name=>"form"), "$new: ". span({-style=>'color: '.getstatuscolor($options{status})},systemid2name($sid)."($id)")." ", systemlink($sid,$pid), br,
popup_menu(-name=>'status', -values=>[1..7], -default=>$options{status},
-labels=>\%planetstatusstring), " status", br,
textfield(-name=>'who', -value=>$options{who}, -class=>'text'), " user-id or user-name of the one who does the above $link", br,
textarea(-name=>'comment', -value=>"\n".$options{comment}, -rows=>9, -cols=>40, -class=>'text'), " why, when, how, plans, etc...", br,
hidden(-name=>'id', $id),
submit(-name=>"submit", -class=>'smbutton'), " ", submit(-name=>"submit",-value=>"delete entry", -class=>'smbutton').
AWfocus("form.who").br;
my $fleets=awinput::sidpid2fleets(sidpid22sidpid3m($sid,$pid));
foreach my $f (@$fleets) {
print show_fleet($f).br;
}
} else {
print start_form(-method=>'get', -name=>"form"), textfield(-name=>'id', -class=>'text'), " ID: system#planet".AWfocus("form.id"), br,
submit(-name=>"query", -class=>'smbutton')
}
print end_form,
br,"Note: entries expire 14 days after last modification",
AWtail();