hier steppt ja wieder der Bär ;). Okay, was haltet ihr von meinem Entwurf:
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
#!/usr/bin/perl -w
use strict;
use warnings;
use DBI;
my ($dbh, $sth);
my %software;
my @installed;
my $iid = '1'; # Inventar-ID
# main
$dbh = &connect();
&fetch_software();
&fetch_installed($iid);
&html_selection();
$dbh->disconnect();
exit(0);
# subs
sub is_in {
# is_in gibt die Anzahl an Übereinstimmungen eines Elementes
# zu einer Menge in einem Array zurück.
my $test = shift @_;
my @in = @_;
my $answer = 0;
for (@in) {
$answer++ if ($test eq $_);
}
return $answer;
}
sub connect {
return DBI->connect ("DBI:mysql:host=192.168.0.1;database=meine",
"ich", "geheim", {PrintError => 0, RaiseError => 1});
}
sub fetch_installed {
my $iid = shift @_;
$sth = $dbh->prepare (" SELECT SOID
FROM nutzt_software
WHERE IID = $iid
");
$sth->execute();
while (my ($soid) = $sth->fetchrow_array()) { push @installed, $soid; }
$sth->finish();
}
sub fetch_software {
$sth = $dbh->prepare (" SELECT SOID, Produkt
FROM Software ");
$sth->execute();
while (my ($soid, $produkt) = $sth->fetchrow_array()) {
$software{$soid}=$produkt;
}
$sth->finish();
}
sub html_selection {
print "<select name='Installationen'>\n";
for (sort(keys(%software))) {
if (&is_in($_, @installed)) {
print "<option selected>$software{$_}</option>\n";
} else {
print "<option>$software{$_}</option>\n";
}
}
print "</select>\n";
}
Gruss,
Ronnie