⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 displaytable.pm

📁 snmp的源代码,已经在我的ubuntu下编译通过
💻 PM
📖 第 1 页 / 共 2 页
字号:
		}	    }	    if (defined($endhook)) {		&$endhook($dbh, $tablename);	    }	    if (!$config{'-noheaders'}) {		print "</tr>\n";	    }	    $doheader = 0;	}	print "<tr>";	if (defined($beginhook)) {	    &$beginhook($dbh, $tablename, $data);	}	if ($edited && $editable) {	    my @indexvalues = getvalues($data, @indexkeys);	    if ($modifiedhook) {		foreach my $valkey (@valuekeys) {		    my ($value) = getquery($q, $data, \@indexkeys, $valkey);		    if ($value ne $data->{$valkey}) {			&$modifiedhook($dbh, $tablename, $valkey, 				       $data, @indexvalues);		    }		}	    }		    	    my $ret = $uph->execute(getquery($q, $data, \@indexkeys, @valuekeys), 				    @indexvalues);	    foreach my $x (@indexkeys) {		next if (defined($indexhash{$x}));		$data->{$x} = $q->param(to_unique_key($x, $data, @indexkeys));	    }#	    print "ret: $ret, $DBI::errstr<br>\n";	}	if ($markable) {	    my $ukey = to_unique_key("mark", $data, @indexkeys);	    print "<td><input type=checkbox value=Y name=\"$ukey\"" .		(($q->param($ukey) eq "Y") ? " checked" : "") . "></td>\n";	    if ($q->param($ukey) eq "Y" && $config{'-onmarked'}) {		&{$config{'-onmarked'}}($dbh, $tablename, $data);	    }	}	    	foreach $key (@keys) {	    if (!defined($prefs) || 		$prefs->execute($tablename, $key) eq "0E0") {		print "<td>";		print "<a href=\"$ref\">" if (defined($datalink) && 					      defined($ref = &$datalink($key, $data->{$key})));		if ($editable && !defined($indexhash{$key})) {		    my $ukey = to_unique_key($key, $data, @indexkeys);		    my $sz;		    if ($config{'-sizehash'}) {			$sz = "size=" . $config{'-sizehash'}{$key};		    }		    if (!$sz && $config{'-inputsize'}) {			$sz = "size=" . $config{'-inputsize'};		    }		    print STDERR "size $key: $sz from $config{'-sizehash'}{$key} / $config{'-inputsize'}\n";		    print "<input type=text name=\"$ukey\" value=\"" . 			maybe_to_hex($data->{$key}) . "\" $sz>";		} else {		    if ($config{'-printer'}) {			&{$config{'-printer'}}($key, $data->{$key}, $data);		    } elsif ($data->{$key} ne "") {			print $data->{$key};		    } else {			print "&nbsp";		    }		}		print "</a>" if (defined($ref));		print "</td>";	    }	}	if (defined($endhook)) {	    &$endhook($dbh, $tablename, $data);	}	print "</tr>\n";	last if (defined($config{'-maxrows'}) && 		 $rowcount >= $config{'-maxrows'});    }    if ($rowcount > 0) {	print "</table>\n";    }    return $rowcount;}sub to_unique_key {    my $ret = shift;    $ret .= "_";    my $data = shift;    if (!defined($data)) {	$ret .= join("_",@_);    } else {	foreach my $i (@_) {	    $ret .= "_" . $data->{$i};	}    }    return toalpha($ret);}sub toalpha {    my $ret = join("",@_);    $ret =~ s/([^A-Za-z0-9_])/ord($1)/eg;    return $ret;}sub getvalues {    my $hash = shift;    my @ret;    foreach my $i (@_) {	push @ret, maybe_from_hex($hash->{$i});    }    return @ret;}sub getquery {    my $q = shift;    my $data = shift;    my $keys = shift;    my @ret;    foreach my $i (@_) {	push @ret, maybe_from_hex($q->param(to_unique_key($i, $data, @$keys)));    }    return @ret;}sub maybe_to_hex {    my $str = shift;    if (!isprint($str)) {	$str = "0x" . (unpack("H*", $str))[0];    }    $str =~ s/\"/&quot;/g;    return $str;}sub maybe_from_hex {    my $str = shift;    if (substr($str,0,2) eq "0x") {	($str) = pack("H*", substr($str,2));    }    return $str;}1;__END__=head1 NAMESNMP - The Perl5 'SNMP' Extension Module v3.1.0 for the UCD SNMPv3 Library=head1 SYNOPSIS use DBI; use displaytable; $dbh = DBI->connect(...); $numshown = displaytable($dbh, 'tablename', [options]);=head1 DESCRIPTIONThe displaytable and displaygraph functions format the output of a DBIdatabase query into an html or graph output.=head1 DISPLAYTABLE OPTIONS=over 4=item -select => VALUESelects a set of columns, or functions to be displayed in the resulting table.Example: -select => 'column1, column2'Default: *=item -title => VALUEUse VALUE as the title of the table.=item -notitle => 1Don't print a title for the table.=item -noheaders => 1Don't print a header row at the top of the table.=item -selectorder => 1=item -selectorder => [qw(column1 column2)]Defines the order of the columns.  A value of 1 will use the order ofthe -select statement by textually parsing it's comma seperated list.If an array is passed containing the column names, that order will beused.Example:   -select => distinct(column1) as foo, -selectorder => [qw(foo)]=item -maxrows => NUMLimits the number of display lines to NUM.=item -tableparms => PARAMS=item -headerparms => PARAMSThe parameters to be used for formating the table contents and theheader contents.Defaults:  -tableparms  => "border=1 bgcolor='#c0c0e0'"  -headerparms => "border=1 bgcolor='#b0e0b0'"=item -dolink => \&FUNCIf passed, FUNC(name) will be called on the tablename or header.  Thefunction should return a web url that the header/table name should belinked to.=item -datalink => \&FUNCIdentical to -dolink, but called for the data portion of the table.Arguments are the column name and the data element for that column.=item -printer => \&FUNCCalls FUNC(COLUMNNAME, COLUMNDATA, DATA) to print the data from eachcolumn.  COLUMNDATA is the data itself, and DATA is a reference to thehash for the entire row (IE, COLUMNDATA = $DATA->{$COLUMNNAME}).=item -beginhook => \&FUNC=item -endhook => \&FUNCdisplaytable will call these functions at the beginning and end of theprinting of a row.  Useful for inserting new columns at the beginningor end of the table.  When the headers to the table are being printed,they will be called like FUNC($dbh, TABLENAME).  When the data isbeing printed, they will be called like FUNC($dbh, TABLENAME, DATA),which DATA is a reference to the hash containing the row data.Example:   -endhook => sub {       my ($d, $t, $data) = @_;       if (defined($data)) { 	  print "<td>",(100 * $data->{'column1'} / $data->{'column2'}),"</td>";      } else { 	  print "<td>Percentage</td>";       }   }=item -clauses => sql_clausesAdds clauses to the sql expression.Example: -clauses => "where column1 = 'value' limit 10 order by column2"=item -xlat => xlattableTranslates column headers and the table name by looking in a table forthe appropriate translation.  Essentially uses:  SELECT newname FROM xlattable where oldname = ?to translate everything.=item -editable => 1=item -indexes   => [qw(INDEX_COLUMNS)]=item -CGI      => CGI_REFERENCEIf both of these are passed as arguments, the table is printed ineditable format.  The INDEX_COLUMNS should be a list of columns thatcan be used to uniquely identify a row.  They will be the non-editablecolumns shown in the table.  Everything else will be editable.  Theform and the submit button written by the rest of the script must loopback to the same displaytable clause for the edits to be committed tothe database.  CGI_REFERENCE should be a reference to the CGI objectused to query web parameters from ($CGI_REFERENCE = new CGI);=item -mark     => 1=item -indexes  => [qw(INDEX_COLUMNS)]=item -CGI      => CGI_REFERENCE=item -onmarked => \&FUNCWhen the first three of these are specified, the left hand most columnwill be a check box that allows users to mark the row for future work.FUNC($dbh, TABLENAME, DATA) will be called for each marked entry whena submission data has been processed.  $DATA is a hash reference tothe rows dataset.  See -editable above for more information.-onmarked => \&FUNC implies -mark => 1.=back=head1 Authorwjhardaker@ucdavis.edu=cut

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -