File: perl.cgi

package info (click to toggle)
ohcount 3.0.0-6.1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 4,828 kB
  • sloc: ansic: 6,534; ruby: 2,560; perl: 2,041; erlang: 350; lisp: 272; sh: 244; pascal: 196; vhdl: 150; haskell: 149; asm: 127; cs: 124; awk: 98; java: 92; php: 73; tcl: 58; xml: 57; fortran: 54; makefile: 32; python: 31; ada: 30; objc: 30; jsp: 28; sql: 18; cobol: 13; ml: 9; cpp: 3
file content (66 lines) | stat: -rwxr-xr-x 2,103 bytes parent folder | download | duplicates (8)
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
#!/usr/bin/perl -w

# ajaxCheckbox.pl - a script to test Ajax functionality

use strict;
use CGI qw/:standard/;     
use CGI::Ajax;
use DBI;

# --- database authenication
my $dbh = do 'db.inc';

my $query = q{ SELECT project.project_id, project.name, project.phase, prio.prio, 
	       HEX((255 - prio.prio)) AS hex, begun, tags
		   FROM project JOIN prio 
		   ON (project.project_id = prio.project_id)
		   WHERE completed < 1
		   ORDER BY prio.prio DESC LIMIT 3};

my $sth = $dbh->prepare($query);
$sth->execute();
my $result = $dbh->selectall_arrayref($sth);

my $cgi = new CGI;
my $pjx = new CGI::Ajax( 'toStruck' => \&perl_func );
print $pjx->build_html( $cgi, \&Show_HTML);

sub Show_HTML {

    use CGI qw/:standard/; 

    my $html = <<HEAD;
    <!DOCTYPE html
	PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
	<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">
	<head>
	<title>This is the lastest source version</title>
	<link rel="stylesheet" type="text/css" href="/css/carrot.css" />
	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
	</head><body>
	<h2>Carrot Queue</h2><a href="/cgi-bin/source_carrot/index.cgi">Priority List</a><b>&nbsp; | &nbsp;</b>
	<a href="/cgi-bin/source_carrot/add.cgi">Add a listing</a><b>&nbsp; | &nbsp;</b><div class="content" /><h4>Project listing</h4>
HEAD

foreach my $row (@$result) {
    $html .= "<input type=\"checkbox\" name=name" . @$row[0] . " id=val" . @$row[0] . " value=\"ON\" onClick=\"toStruck( ['val@$row[0]'], ['div@$row[0]'] );\">";
    $html .= "<div id=\"div@$row[0]\" style=\"display: inline;\"><!-- This gets entirely replaced -->" . @$row[1] . "</span></div><br>";
}

# you can append stuff to the HTML this way 
$html .= "</body></html>";

return $html;
}

sub perl_func {
    my 	$input=shift;

    # if onClick the change the style
    if ($input eq "ON") {
	$input="<span style=\"text-decoration: line-through; display: inline;\">";
    } else {
	$input ="<span style=\"text-decoration: none; display: inline;\">";
    } 
}