Initial Revision
[ohcount] / test / src_dir / perl.cgi
1 #!/usr/bin/perl -w
2
3 # ajaxCheckbox.pl - a script to test Ajax functionality
4
5 use strict;
6 use CGI qw/:standard/;     
7 use CGI::Ajax;
8 use DBI;
9
10 # --- database authenication
11 my $dbh = do 'db.inc';
12
13 my $query = q{ SELECT project.project_id, project.name, project.phase, prio.prio, 
14                HEX((255 - prio.prio)) AS hex, begun, tags
15                    FROM project JOIN prio 
16                    ON (project.project_id = prio.project_id)
17                    WHERE completed < 1
18                    ORDER BY prio.prio DESC LIMIT 3};
19
20 my $sth = $dbh->prepare($query);
21 $sth->execute();
22 my $result = $dbh->selectall_arrayref($sth);
23
24 my $cgi = new CGI;
25 my $pjx = new CGI::Ajax( 'toStruck' => \&perl_func );
26 print $pjx->build_html( $cgi, \&Show_HTML);
27
28 sub Show_HTML {
29
30     use CGI qw/:standard/; 
31
32     my $html = <<HEAD;
33     <!DOCTYPE html
34         PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
35         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
36         <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">
37         <head>
38         <title>This is the lastest source version</title>
39         <link rel="stylesheet" type="text/css" href="/css/carrot.css" />
40         <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
41         </head><body>
42         <h2>Carrot Queue</h2><a href="/cgi-bin/source_carrot/index.cgi">Priority List</a><b>&nbsp; | &nbsp;</b>
43         <a href="/cgi-bin/source_carrot/add.cgi">Add a listing</a><b>&nbsp; | &nbsp;</b><div class="content" /><h4>Project listing</h4>
44 HEAD
45
46 foreach my $row (@$result) {
47     $html .= "<input type=\"checkbox\" name=name" . @$row[0] . " id=val" . @$row[0] . " value=\"ON\" onClick=\"toStruck( ['val@$row[0]'], ['div@$row[0]'] );\">";
48     $html .= "<div id=\"div@$row[0]\" style=\"display: inline;\"><!-- This gets entirely replaced -->" . @$row[1] . "</span></div><br>";
49 }
50
51 # you can append stuff to the HTML this way 
52 $html .= "</body></html>";
53
54 return $html;
55 }
56
57 sub perl_func {
58     my  $input=shift;
59
60     # if onClick the change the style
61     if ($input eq "ON") {
62         $input="<span style=\"text-decoration: line-through; display: inline;\">";
63     } else {
64         $input ="<span style=\"text-decoration: none; display: inline;\">";
65     } 
66 }