santhanalakshmi -2 Junior Poster in Training

Hi,
This is my perl program..........

#!c:/perl/bin/perl
use CGI qw(:all);

$pfaccode=param('faccode');
$pprogramme=param('programme');
$pdeptcode=param('deptcode');
$pbrancode=param('brancode');
$psemester=param('semester');

$pkook = cookie(-name=>'logtime');

print "Content-type: text/html\n\n";
print "<body bgcolor=\"#ffcccc\">";
use DBI;
my $dbh = DBI->connect("DBI:ODBC:wwwdsn","webid","dibew") or die "Cant connect: $DBI::errstr\n";

my $sth = $dbh->prepare("select kid from facltmst where faccode = ?") or die "Can not prepare SQL statement\n";
$sth->execute($pfaccode) or die "Cant execute SQL: $DBI::errstr\n";
$kid = 0;
while ( @row = $sth->fetchrow_array())
{
	$kid=$row[0];
}
if(($kid eq 0) || ($kid ne $pkook))
{
        print "<BR><h2>Please Login.</h2>";
        print "<HR>";
        exit;
}

my $sth = $dbh->prepare("select pregp from clockmst") or die "Can not prepare SQL statement\n";
$sth->execute or die "Cant execute SQL: $DBI::errstr\n";
while ( @row = $sth->fetchrow_array())
{
	$mperiod = $row[0];
}


my @rollarr;
$sth = $dbh->prepare("select rollno,semester,programme,brancode from stuacmst where faccode = ? and programme = ? and deptcode = ? and brancode = ? and semester = ? and studstat = ? order by programme,brancode,semester,rollno") or die "Cant prepare: $DBI::errstr\n";
$sth->execute($pfaccode,$pprogramme,$pdeptcode,$pbrancode,$psemester,'C') or die "Cant execute: $DBI::errstr\n";
while ( @row = $sth->fetchrow_array())
{
	$mrollno = $row[0];
	$lc = substr($mrollno,7,1);
	if ($lc eq ' ')
	{
		$mrollno = substr($mrollno,0,7);
	}
	push(@rollarr,$mrollno);
}

my @backarr;
if ($pprogramme eq 'B' or $pprogramme eq 'L')
{
	$sth = $dbh->prepare("select distinct a.rollno from ucsrgdet a, corsemst b where a.rollno in (select rollno from stuacmst where faccode = ? and programme = ? and deptcode = ? and brancode = ? and semester = ?) and a.crseid = b.crseid and (a.grade=\'U\' or a.grade=\'W\') and not exists ( select c.crseid from ucsrgdet c,corsemst d where c.rollno = a.rollno and d.crseno = b.crseno and c.crseid = d.crseid and c.grade<>\'U\' and c.grade<>\'W\') order by a.rollno") or die "Cant prepare: $DBI::errstr\n";
}
else
{
	$sth = $dbh->prepare("select distinct a.rollno from pcsrgdet a, corsemst b where a.rollno in (select rollno from stuacmst where faccode = ? and programme = ? and deptcode = ? and brancode = ? and semester = ?) and a.crseid = b.crseid and (a.grade=\'U\' or a.grade=\'W\') and not exists ( select c.crseid from pcsrgdet c,corsemst d where c.rollno = a.rollno and d.crseno = b.crseno and c.crseid = d.crseid and c.grade<>\'U\' and c.grade<>\'W\') order by a.rollno") or die "Cant prepare: $DBI::errstr\n";
}
$sth->execute($pfaccode,$pprogramme,$pdeptcode,$pbrancode,$psemester) or die "Cant execute: $DBI::errstr\n";
while ( @row = $sth->fetchrow_array())
{
	$mrollno = $row[0];
	$lc = substr($mrollno,7,1);
	if ($lc eq ' ')
	{
		$mrollno = substr($mrollno,0,7);
	}
	push(@backarr,$mrollno);
}

if ($pprogramme eq 'B' or $pprogramme eq 'L')
{
	$sth = $dbh->prepare("select a.rollno from stuacmst a where a.faccode = ? and a.programme = ? and a.deptcode = ? and a.brancode = ? and a.semester = ? and exists(select b.crseno from corcsmst b where b.deptcode = a.deptcode and b.brancode = a.brancode and b.programme = a.programme and b.semester <= a.semester and b.crseno not in (select distinct e.crseno from ucsrgdet d, corsemst e where d.rollno = a.rollno and d.crseid = e.crseid union select distinct g.crseno from crnrgdet f, corsemst g where f.rollno = a.rollno and f.crseid = g.crseid))") or die "Cant prepare: $DBI::errstr\n"; 
}
else
{
	$sth = $dbh->prepare("select a.rollno from stuacmst a where a.faccode = ? and a.programme = ? and a.deptcode = ? and a.brancode = ? and a.semester = ? and exists(select b.crseno from corcsmst b where b.deptcode = a.deptcode and b.brancode = a.brancode and b.programme = a.programme and b.semester <= a.semester and b.crseno not in (select distinct e.crseno from pcsrgdet d, corsemst e where d.rollno = a.rollno and d.crseid = e.crseid union select distinct g.crseno from crnrgdet f, corsemst g where f.rollno = a.rollno and f.crseid = g.crseid))") or die "Cant prepare: $DBI::errstr\n"; 
}
$sth->execute($pfaccode,$pprogramme,$pdeptcode,$pbrancode,$psemester) or die "Cant execute: $DBI::errstr\n";
while ( @row = $sth->fetchrow_array())
{
	$mrollno = $row[0];
	$lc = substr($mrollno,7,1);
	if ($lc eq ' ')
	{
		$mrollno = substr($mrollno,0,7);
	}
	push(@backarr,$mrollno);
}

$msem = $psemester;
$msem = $msem + 1;
if ($msem < 10)
{
	$msemester = "0"."$msem";
}
else
{
	$msemester = "$msem";
}

my @tcslotarr;
my @tccrsearr;
my @pcslotarr;
my @pccrsearr;
my @pccatgarr;

$sth = $dbh->prepare("select crseno,category from corcsmst where deptcode = ? and brancode = ? and programme = ? and semester = ? order by crseno") or die "can not prepare SQL\n";
$sth->execute($pdeptcode,$pbrancode,$pprogramme,$msemester) or die "Can not execte SQL";

while ( @row = $sth->fetchrow_array())
{
	push(@tccrsearr,$row[0]);
	push(@tccatgarr,$row[1]);
}

$mtcount = @tccrsearr - 1;

for $i(0..$mtcount)
{
	$mcrseno = $tccrsearr[$i];
	$lc = substr($mcrseno,5,1);
	if ($lc eq ' ')
	{
		$mcrseno = substr($mcrseno,0,5);
	}

	$sth = $dbh->prepare("select distinct slot from crncsdet where period = ? and crseid in (select crseid from corsemst where crseno = ?) order by slot") or die "can not prepare SQL\n";
	$sth->execute($mperiod,$mcrseno) or die "Can not execte SQL";
	$mslot = ' ';
	while ( @row = $sth->fetchrow_array())
	{
		if ($mslot eq ' ')
		{
			$mslot = $row[0];
		}
		else
		{
			$mslot = $mslot."/".$row[0];
		}
	}
	$mcatg = $tccatgarr[$i];

	push(@pcslotarr,$mslot);
	push(@pccrsearr,$mcrseno);
	push(@pccatgarr,$mcatg);
}

my @petypearr;
$sth = $dbh->prepare("select a.etype from eletpdet a where a.deptcode = \'$pdeptcode\' and a.brancode = \'$pbrancode\' and a.programme = \'$pprogramme\' and a.semester = \'$msemester\' order by a.etype") or die "can not prepare SQL\n";
$sth->execute or die "Can not execte SQL";
while ( @row = $sth->fetchrow_array())
{
	push(@petypearr,$row[0]);
}

$mccount = @pccrsearr - 1;
$mecount = @petypearr - 1;

$mc = $mccount + 1;
$me = $mecount + 1;

$mprogramme = $pprogramme;
if ($mprogramme eq 'B')
{
	$sprog = "BTech";
}
elsif ($mprogramme eq 'L')
{
	$sprog = "Dual Degree";
}
elsif ($mprogramme eq 'M')
{
	$sprog = "MTech";
}
elsif ($mprogramme eq 'C')
{
	$sprog = "MSc";
}
elsif ($mprogramme eq 'A')
{
	$sprog = "MBA";
}
elsif ($mprogramme eq 'I')
{
	$sprog = "Int. PhD";
}

print "<h2><center>Pre-Registration for $mperiod</center></h2>\n";
#$sth = $dbh->prepare("select branname from brnchmst where brancode = ?") or die "Can not prepare SQL statement\n";
$sth = $dbh->prepare("select branname from brnchmst where brancode = ? and programme<>'F'") or die "Can not prepare SQL statement\n";

$sth->execute($pbrancode) or die "Can not execte SQL";
$mbranname = '';
while ( @row = $sth->fetchrow_array())
{
	$mbranname = $row[0];
}
print "<center><b>$sprog-$mbranname-$msemester Semester</center>";
print "<hr>";

print "<h3>Curriculum</h3>";
print "<table border=1>";
print "<tr><th>Slot<th>Crseno<th>Title<th>Credit<th>Cat<th>Pre. Req</tr>";
for $i(0..$mccount)
{
	$mslot = $pcslotarr[$i];
	$mcrseno = $pccrsearr[$i];
	$sth = $dbh->prepare("select a.crsename,a.credit,a.crseid,b.category from corsemst a, corcsmst b where a.crseno = ? and a.wdrawdate = ? and a.crseno = b.crseno and b.brancode = ? and b.semester = ?") or die "Can not prepare SQL statement\n";
	$sth->execute($mcrseno,'1900/01/01',$pbrancode,$msemester) or die "Can not execte SQL";
	$mcrsename = '';
	$mcredit = '';
	$mcatg='';
	while ( @row = $sth->fetchrow_array())
	{
		$mcrsename = $row[0];
		$mcredit = $row[1];
		$mcrseid = $row[2];
		$mcatg = $row[3];
	}
	$sth = $dbh->prepare("select rcot from crncsdet where crseid = ? and period = ?") or die "Can not prepare SQL statement\n";
	$sth->execute($mcrseid,$mperiod) or die "Can not execte SQL";
	$mrcot = '';
	while ( @row = $sth->fetchrow_array())
	{
		$mrcot = $row[0];
	}
	$mpre='-';
	if ($mrcot eq 'Y')
	{
		$mpre = 'COT';
	}
	print "<tr><td>$mslot</td><td>$mcrseno</td><td>$mcrsename</td><td>$mcredit</td><td>$mcatg</td><td>$mpre</td></tr>";
}

for $i(0..$mecount)
{
	$metype = $petypearr[$i];
	$sth = $dbh->prepare("select a.ename,b.credit,a.category from eletpmst a, eletpdet b where a.etype = ? and a.etype = b.etype and b.brancode = ? and b.semester = ?") or die "Can not prepare SQL statement\n";
	$sth->execute($metype,$pbrancode,$msemester) or die "Can not execte SQL";
	$mename = '';
	$mcredit = '';
	$mcatg = '';
	while ( @row = $sth->fetchrow_array())
	{
		$mename = $row[0];
		$mcredit = $row[1];
		$mcatg = $row[2];
	}
	$mslot = '-';
	$mpre = '-';
	print "<tr><td>$mslot</td><td>$metype</td><td>$mename</td><td>$mcredit</td><td>$mcatg</td><td>$mpre</td></tr>";
}
print "</table>";

print "<h3>Registration form</h3>";
print "<table border=1>\n";
print "<tr><th rowspan=2>SlNo<th rowspan=2>Rollno<th colspan=$mc>Core<th colspan=$me>Electives<th rowspan=2>Backlogs<th rowspan=2>Others<th rowspan=2>Form<th rowspan=2>Approval</tr>\n";
print "<tr>";
if($mccount > -1)
{
	for $i(0..$mccount)
	{
		if ($pcslotarr[$i] eq ' ')
		{
			print "<th>-";
		}
		else
		{
			print "<th>$pcslotarr[$i]";
		}

	}
}
else
{
		print "<th>-";
}
for $i(0..$mecount)
{
	print "<th>$petypearr[$i]";
}
print "</tr>";
$mscount = @rollarr - 1;
for $i(0..$mscount)
{
	$mrollno = $rollarr[$i];


	$sth = $dbh->prepare("select crseno from prergtmp where rollno = ? and period = ?") or die "can not prepare SQL\n";
	$sth->execute($mrollno,$mperiod) or die "Can not execte SQL";
	$mp = 'N';
	while ( @row = $sth->fetchrow_array())
	{
		$mp = 'Y';
	}
	if ($mp eq 'N')
	{
		$sth = $dbh->prepare("insert into prergtmp(rollno,crseno,category,ctype,semester,period,slot) values (?,?,?,?,?,?,?)") or die "can not prepare SQL\n";
		for $k(0..$mccount)
		{
			$mcrse = $pccrsearr[$k];
			$mcatg = $pccatgarr[$k];
			$mslot = $pcslotarr[$k];
			$sth->execute($mrollno,$mcrse,$mcatg,'CORE',$msemester,$mperiod,$mslot) or die "Can not execte SQL";
		}
		for $k(0..$mecount)
		{
			$metype = $petypearr[$k];
			$sth = $dbh->prepare("select b.crseno,a.category from crnrgdet a, corsemst b where a.rollno = ? and a.period = ? and a.ctype = ? and a.crseid = b.crseid") or die "can not prepare SQL\n";
			$sth->execute($mrollno,$mperiod,$metype) or die "Can not execte SQL";
			$mep = 'N';
			while ( @row = $sth->fetchrow_array())
			{
				$mcrse = $row[0];
				$mcatg = $row[1];
				$mep = 'Y';
			}
			if ($mep eq 'Y')
			{
				$sth = $dbh->prepare("insert into prergtmp(rollno,crseno,category,ctype,semester,period) values (?,?,?,?,?,?)") or die "can not prepare SQL\n";
				$sth->execute($mrollno,$mcrse,$mcatg,$metype,$msemester,$mperiod) or die "Can not execte SQL";
			}
		}
	}

	$menrolled = 'N';
	$sth = $dbh->prepare("select enrolled from stuacmst where rollno = ?") or die "Cant prepare: $DBI::errstr\n";
	$sth->execute($mrollno) or die "Can not execte SQL";
	while ( @row = $sth->fetchrow_array())
	{
		$menrolled = $row[0];
	}	
	if ($menrolled eq 'Y')
	{
		print "<tr bgcolor=#00FFcc>";
	}
	else
	{
		print "<tr>";
	}
	$j = $i + 1;
	print "<td>$j</td>\n";
      #print "<td>$j</td>\n";
      print "<td>$mrollno</td>\n";
	if($mccount > -1)
	{
		for $k(0..$mccount)
		{
			$mcrse = $pccrsearr[$k];
			$mcp = 'N';
			$sth = $dbh->prepare("select crseno from prergtmp where rollno = ? and crseno = ? and period = ? and ctype = ?") or die "can not prepare SQL\n";
			$sth->execute($mrollno,$mcrse,$mperiod,'CORE') or die "Can not execte SQL";
			while ( @row = $sth->fetchrow_array())
			{
				$mcp = 'Y';
			}
			if ($mcp eq 'Y')
			{
				print "<td><a href=/cgi-bin/oregn/slotchco.cgi?rollno=$mrollno&semester=$psemester&crseno=$pccrsearr[$k]&faccode=$pfaccode&programme=$pprogramme&deptcode=$pdeptcode&brancode=$pbrancode target=workwind>$pccrsearr[$k]</a></td>\n";
			}
			else
			{
				print "<td><a href=/cgi-bin/oregn/slotchco.cgi?rollno=$mrollno&semester=$psemester&crseno=$pccrsearr[$k]&faccode=$pfaccode&programme=$pprogramme&deptcode=$pdeptcode&brancode=$pbrancode target=workwind>NONE</a></td>\n";
			}
		}
	}
	else
	{
		print "<td><center>-</center></td>";
	}
	if($mecount > -1)
	{
		for $k(0..$mecount)
		{
			$metype = $petypearr[$k];
			$mep = 'N';
			$sth = $dbh->prepare("select crseno from prergtmp where rollno = ? and ctype = ? and period = ?") or die "can not prepare SQL\n";
			$sth->execute($mrollno,$metype,$mperiod) or die "Can not execte SQL";
			while ( @row = $sth->fetchrow_array())
			{
				$mep = 'Y';
				$mecrse = $row[0];
			}
			if ($mep eq 'Y')
			{
				print "<td><a href=/cgi-bin/oregn/slotchel.cgi?rollno=$mrollno&semester=$psemester&etype=$metype&faccode=$pfaccode&programme=$pprogramme&deptcode=$pdeptcode&brancode=$pbrancode target=workwind>$mecrse</a></td>";
			}
			else
			{
				print "<td><a href=/cgi-bin/oregn/slotchel.cgi?rollno=$mrollno&semester=$psemester&etype=$metype&faccode=$pfaccode&programme=$pprogramme&deptcode=$pdeptcode&brancode=$pbrancode target=workwind>register</a></td>";
			}	
		}
	}
	else
	{
		print "<td><center>-</center></td>";
	}
	$miback='N';
	foreach $backroll(@backarr)
	{
		if ($backroll eq $mrollno)
		{
			$miback = 'Y';
		}
	}
	if ($miback eq 'Y')
	{
		$sth = $dbh->prepare("select crseno from prergtmp where rollno = ? and ctype = ? and period = ?") or die "can not prepare SQL\n";
		$sth->execute($mrollno,'BKLG',$mperiod) or die "Can not execte SQL";
		$mbstr = ' ';
		while ( @row = $sth->fetchrow_array())
		{
			if ($mbstr eq ' ')
			{
				$mbstr = $mbstr.$row[0];
			}
			else
			{
				$mbstr = $mbstr.'<br>'.$row[0];
			}
		}
		if ($mbstr ne ' ')
		{
			print "<td><a href=/cgi-bin/oregn/slotchbk.cgi?rollno=$mrollno&semester=$psemester&faccode=$pfaccode&programme=$pprogramme&deptcode=$pdeptcode&brancode=$pbrancode target=workwind>$mbstr</a></td>";
		}
		else
		{
			print "<td><a href=/cgi-bin/oregn/slotchbk.cgi?rollno=$mrollno&semester=$psemester&faccode=$pfaccode&programme=$pprogramme&deptcode=$pdeptcode&brancode=$pbrancode target=workwind>register</a></td>";
		}
	}
	else
	{
		print "<td><center>-</center></td>\n";
	}

	$sth = $dbh->prepare("select crseno from prergtmp where rollno = ? and ctype = ? and period = ?") or die "can not prepare SQL\n";
	$sth->execute($mrollno,'EXT1',$mperiod) or die "Can not execte SQL";
	$mxstr = ' ';
	while ( @row = $sth->fetchrow_array())
	{
		$mxstr = $mxstr.$row[0];
	}

	$sth->execute($mrollno,'EXT2',$mperiod) or die "Can not execte SQL";
	while ( @row = $sth->fetchrow_array())
	{
		if ($mxstr eq ' ')
		{
			$mxstr = $mxstr.$row[0];
		}
		else
		{
			$mxstr = $mxstr.'<br>'.$row[0];
		}
	}

	if ($mxstr ne ' ')
	{
		print "<td><a href=/cgi-bin/oregn/slotchex.cgi?rollno=$mrollno&semester=$psemester&faccode=$pfaccode&programme=$pprogramme&deptcode=$pdeptcode&brancode=$pbrancode target=workwind>$mxstr</a></td>";
	}
	else
	{
		print "<td><a href=/cgi-bin/oregn/slotchex.cgi?rollno=$mrollno&semester=$psemester&faccode=$pfaccode&programme=$pprogramme&deptcode=$pdeptcode&brancode=$pbrancode target=workwind>register</a></td>";
	}

	print "<td><a href=/cgi-bin/oregn/regnform.cgi?rollno=$mrollno&faccode=$pfaccode target=workwind>view</a></td>";

       

	print "<form action=/cgi-bin/oregn/regnappr.cgi method=post name=orderform>";
	print "<input type=hidden name=rollno value=$mrollno>";
	print "<input type=hidden name=faccode value=$pfaccode>";
	print "<input type=hidden name=programme value=$pprogramme>";
	print "<input type=hidden name=deptcode value=$pdeptcode>";
	print "<input type=hidden name=brancode value=$pbrancode>";
	print "<input type=hidden name=semester value=$psemester>";

      
      #print "<td><input type=checkbox name=chk value=$mrollno>$mrollno</td>";

	if ($menrolled eq 'Y')
	{
		print "<td><input type=submit value=Approved></td>";
            #print "<td><input type=checkbox name=$mrollno value=Approved checked></td>";

	}
	else
	{
		print "<td><input type=submit value=Approve></td>";
            #print "<td><input type=checkbox  name=$mrollno  value=Approve></td>";

      }
     
      
}
print "</tr>";
print "</table>";
#print "<P><INPUT type=submit value=Submit onclick=get_check_value()>";
#print "<INPUT type=reset value=Reset></P>"; 
print "</form>";
print "<hr>";

This is my Javascript Code.I want to add this javascript code in the above coding( *.cgi program).Please help me out ,how to add this javascript in the above coding.what is the syntax?how to add ?

<script type="text/javascript">


function get_check_value()
{
var c_value = "";
for (var i=0; i < document.orderform.music.length; i++)
   {
   if (document.orderform.music[i].checked)
      {
      c_value = c_value + document.orderform.music[i].value + "\n";
      }
   }
}


</script>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.