Thursday, 13 November 2014

//1a.html
<? xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 // EN"
 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<!--lab1a.html-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
                <title>FIBONACCI SERIES</title>
</head>
<body>
<script type="text/javascript">
var fib1=0,fib2=1,fib=0;
var num=prompt("Enter a number: \n","");
if(num!=null && num>0)
{
document.write("<h1>" + num + "Fibonaci numbers are as follows</h1>");
if(num==1)
document.write("<h3>" + fib1 + "</h3>");
else
                {
document.write("<h3>" + fib1 + "</h3>");
document.write("<h3>" + fib2 + "</h3>");
}
                for(i=3;i<=num;i++)
                {
fib=fib1+fib2;
document.write("<h3>" + fib + "</h3>");
fib1=fib2;
                                fib2=fib;
                }
}
Else
alert("No proper input");
               
</script>
</body>
</html>


//1b.html
<? xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 // EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<!--lab1a.html-->

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
     <title>NUMBERS and SQUARES</title>
</head>

<body>
<script type="text/javascript">
var num=prompt("Enter a number:\n");
if(num>0 && num!=null)
{
     msgstr="Number and its squares are:\n";
     for(i=1;i<=num;i++)
     {
           msgstr=msgstr+i+"-"+i*i+"\n";
     }
     alert(msgstr);
}
else
     alert("No proper input\n");
</script>
</body>
</html>



//2a.html
<? xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 // EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<!--lab1a.html-->

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title>VALIDATION OF USN</title>
<script type="text/javascript">
function formValidator()
{
     var usn=document.getElementById('req1');
     if(isCorrect(usn))
     {
     return true;
     }
     return false;
}
function isCorrect(elem1)
{
     alphaExp1=/^[1-4][A-Z][A-Z][0-9][0-9][A-Z][A-Z][0-9][0-9]$/;
     if(elem1.value.length == 0)
     {
           alert("USN is empty");
           return false;
     }
     else if(!elem1.value.match(alphaExp1))
     {
           alert("USN should be in the format DAADDAADDD");
           return false;
     }
     alert("USN is correct");
     return true;
}
</script>
</head>
<body>
<form onsubmit="formValidator()">
<p>Enter your USN in DAADDAADDD format:
<input type="text" id="req1" />
<input type="submit" value="Check field" />
</p>
</body>
</html>



//2b.html
<? xml version="1.0" encoding="utf-8" ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 // EN"
 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">


<!--lab1a.html-->


<html xmlns="http://www.w3.org/1999/xhtml">


<head>
<title>VALIDATION OF USN AND SEM</title>

<script type="text/javascript">

function formValidator()
{
    
var usn=document.getElementById('req1');
    
var sem=document.getElementById('req2');
    
if(isCorrect(usn))
     {

           if(isPerfect(sem))

           return true;
     }
          
return false;
     }

function isPerfect(elem2)
{

     var alphaExp2=/^[1-8]$/;

     if(elem2.value.length==0)

     {

           alert("Sem number is empty");

           return false;
     }

     else if(!elem2.value.match(alphaExp2))

     {
           alert("Invalid sem number");

           return false;
     }

     alert("Sem number is correct");

return true;
}


function isCorrect(elem1)
{

     alphaExp1=/^[1-4][A-Z][A-Z][0-9][0-9][A-Z][A-Z][0-9][0-9][0-9]$/;

     if(elem1.value.length == 0)
     {

           alert("USN is empty");

           return false;

     }

     else if(!elem1.value.match(alphaExp1))

     {
           alert("Please enter current USN of VTU format");

           return false;
     }

     alert("USN is correct");

     return true;
}

</script>

</head>

<body>

<form onsubmit="formValidator()">

<p>Enter your USN :
<input type="text" id="req1" />
<br />
Enter your sem :
<input type="text" id="req2" />
<br />
<input type="submit" value="Check field" />
</p>
</form>

</body>

</html>


//3a.css

.layer1style
{
     border:solid thick black;
     padding:1px;
     width:300px;
     background-color:green;
     position:absolute;
     top:100px;
     left:200px;
}

.layer3style
{
     border:solid thick;
     padding:1px;
     width:300px;
     background-color:blue;
     position:absolute;
     top:140px;
     left:240px;
}

.layer2style
{
     border:solid thick;
     padding:1px;
     width:300px;
     background-color:red;
     position:absolute;
     top:120px;
     left:220px;
}




//3a.html
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title>Stacking of elements</title>
<link rel="stylesheet" type="text/css" href="3a.css"/>
<script type="text/javascript">
     var topLayer="layer3";
     function movein(toTop)
     {
           var oldTop=document.getElementById(topLayer).style;
           var newTop=document.getElementById(toTop).style;
           oldTop.zIndex="0";
           newTop.zIndex="1";
           topLayer=toTop;
     }
</script>
</head>
<body bgcolor="powderblue">
     <h2>Program includes XHTML document to show stacking of elements</h2>
     <p class="layer1style" id="layer1" onmouseover="movein('layer1');">This is first paragraph with Layer1Style features</p>
     <p class="layer2style" id="layer2" onmouseover="movein('layer2');">This is second paragraph with Layer2Style features</p>
     <p class="layer3style" id="layer3" onmouseover="movein('layer3');">This is third paragraph with Layer3Style features</p>
</body>
</html>




//3b.html
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title>Stacking of elements</title>
<link rel="stylesheet" type="text/css" href="3a.css"/>
<script type="text/javascript">
     var topLayer="layer3";
     function movein(toTop)
     {
           var oldTop=document.getElementById(topLayer).style;
           var newTop=document.getElementById(toTop).style;
           oldTop.zIndex="0";
           newTop.zIndex="1";
           topLayer=toTop;
     }
</script>
</head>
<body bgcolor="powderblue">
     <h2>Program includes XHTML document to show stacking of elements</h2>
     <p class="layer1style" id="layer1" onmouseover="movein('layer1');" onmouseout="movein('layer3');">This is first paragraph with Layer1Style features</p>
     <p class="layer2style" id="layer2" onmouseover="movein('layer2');" onmouseout="movein('layer3');">This is second paragraph with Layer2Style features</p>
     <p class="layer3style" id="layer3" onmouseover="movein('layer3');" onmouseout="movein('layer3');">This is third paragraph with Layer3Style features</p>
</body>
</html>


//4a.xml
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/css" href="4a.css"?>

<students>
     <VTU>
           <USN>IBI11CS001</USN>
           <name>Anil</name>
           <college>BIT</college>
           <branch>CSE</branch>
           <YOJ>2008</YOJ>
           <email>anil@gmail.com</email>
     </VTU>
     <VTU>
           <USN>1BI11CS002</USN>
           <name>Akshatha</name>
           <college>BIT</college>
           <branch>CSE</branch>
           <YOJ>2008</YOJ>
           <email>akshatha@rediffmail.com</email>
     </VTU>
     <VTU>
           <USN>1BI11CS003</USN>
           <name>Bhavani</name>
           <college>BIT</college>
           <branch>CSE</branch>
           <YOJ>2008</YOJ>
           <email>bhavani@yahoo.com</email>
     </VTU>
</students>

//4a.css
USN
{
font-weight:bold;
display:block;
text-align:center;
color:red;
font-family:courier,prestige;
font-size:20pt;
}
name,college,branch,YOJ,email
{
font-variant:small-caps;
color:navy;
display:block;
text-align:center;
font-size:15pt;
}

//4b.xml
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="4b.xsl"?>


<VTU>
     <USN>IBI11CS001</USN>
     <name>Anil</name>
     <college>BIT</college>
     <branch>CSE</branch>
     <YOJ>2008</YOJ>
     <email>anil@gmail.com</email>
</VTU>

    
//4b.xsl
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/1999/xhtml">
<xsl:template match="VTU">
<html>
<head>
<title>STUDENT DESCRIPTION</title>
</head>
<body>
     <h2>VTU student description</h2>
     <span style="font-style:italic;color:fuchsia;">USN: </span>
     <xsl:value-of select="USN" /><br />
     <span style="font-style:italic;color:fuchsia;">Name: </span>
     <xsl:value-of select="name" /><br />
     <span style="font-style:italic;color:fuchsia;">College: </span>
     <xsl:value-of select="college" /><br />
     <span style="font-style:italic;color:fuchsia;">Branch: </span>
     <xsl:value-of select="branch" /><br />
     <span style="font-style:italic;color:fuchsia;">Year of Join: </span>
     <xsl:value-of select="YOJ" /><br />
     <span style="font-style:italic;color:fuchsia;">E-mail: </span>
     <xsl:value-of select="email" /><br />
</body>
</html>
</xsl:template>
</xsl:stylesheet>

//5a.pl

#!/usr/bin/perl
use CGI':standard';
print "Content-type:text/html","\n\n";
print "<html>\n";
print "<head><title>SERVER INFORMATION</title></head>\n";
print "<body><h1>About this server</h1>","\n";
print "<hr /><pre><h3>";
print "Server name     :",$ENV{'SERVER_NAME'},"<br />";
print "Running on port :",$ENV{'SERVER_PORT'},"<br />";
print "Server Software :",$ENV{'SERVER_SOFTWARE'},"<br />";
print "Server Protocol :",$ENV{'SERVER_PROTOCOL'},"<br />";
print "CGI-Version     :",$ENV{'GATEWAY_INTERFACE'},"<br />";
print "Root Document   :",$ENV{'DOCUMENT_ROOT'},"<br />";
print "</h3><hr /></pre>\n";
print "</body></html>\n";
exit(0);




//5b.pl

#!/usr/bin/perl
use CGI':standard';
print "content-type:text/html\n\n";
$c=param('com');
$v=system($c);
print "<html>\n";
print "<head><title>COMMAND EXECUTED</title></head>\n";
print "<body><h1>","\n";
if($v>0)
{
print "ERROR!!!!!<br />ENTER COMMAND";
}
if($v<0)
{
print "ERROR!!!!!<br />COMMAND NOT FOUND!!!";
}
print "</h1></body></html>\n";
exit(0);

//6a.pl
#!/usr/bin/perl
use CGI':standard';
@coins=("Welcome to web programming lab","Have a nice time in lab","Practise all the programmes","Well done,good day");
$range=4;
$random_number=int(rand($range));
if(param)
{
print header();
print start_html(-title=>"USER NAME",-bgcolor=>"brown",-text=>"white");
$cmd=param("name");
print b("Hello $cmd,$coins[$random_number]"),br();
print start_form();
print "<p>";
print submit(-value=>"Back");
print end_form();
print end_html();
}
else
{
print header();
print start_html(-title=>"ENTER USER NAME",-bgcolor=>"skyblue",-text=>"black");
print "<h3>ENTER USER NAME</h3>";
print "<p>";
print start_form(),textfield(-name=>"name",-value=>"user"),submit(-name=>"submit",-value=>"Submit"),reset();
print end_form();
print end_html();
}

//6b.pl

#!/usr/bin/perl
use CGI':standard';
print header();
print start_html(-title=>"WEB PAGE COUNTER",-bgcolor=>"green",-text=>"white");
open(FILE,'</var/www/cgi-bin/count.txt');
$count=<FILE>;
close(FILE);
$count++;
open(FILE,'>count.txt');
print FILE "$count";
print b("This page has been viewed $count times");
close(FILE);
print end_html();

//7.pl

#!/usr/bin/perl
use CGI':standard';
print "Refresh:1\n";
print "Content-type:text/html\n\n";
print start_html(-title=>"DIGITAL CLOCK",-bgcolor=>"orange",-text=>"black");
($s,$m,$h)=localtime(time);
print br,br,"The current system time is $h:$m:$s";
print br,br,hr,"In words $h hours $m minutes $s seconds";
print end_html;

//8.pl

#!/usr/bin/perl
use CGI':standard';
print "content-type:text/html\n\n";
print "<html><head><title>Result of the insert operation</title></head>";
use DBI;
$dbh=DBI->connect("DBI:mysql:mysql","root","server");
$name=param("name");
$age=param("age");
$qh=$dbh->prepare("insert into STUDENT values('$name','$age')");
$qh->execute();
$qh=$dbh->prepare("select * from STUDENT");
$qh->execute();
print "<table border=1><tr><th>Name</th><th>Age</th></tr>";
while(($name,$age)=$qh->fetchrow())
{
     print "<tr><td>$name</td><td>$age</td></tr>";
}
print "</table>";
$qh->finish();
$dbh->disconnect();
print "</html>";


//8.html

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//w3c//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD//xhtml11.dtd">
<html xmlns="http//www.w3.org/1999/xhtml">
<body>
<form action="http://localhost/cgi-bin/lab08.pl">
Name:<input type="text" name="name" /><br />
Age:<input type="text" name="age" /><br />
<input type="submit" value="Submit" />
</form>
</body>
</html>

//9.php

<?php date_default_timezone_set('Asia/calcutta');
//calculate 60 days in the future
//seconds*minutes*hours*days+current time
$inTwoMonths=60*60*24*60+time();
setcookie('lastVisit',date("G:i-m/d/y"),$inTwoMonths);
if(isset($_COOKIE['lastVisit']))
{
     $visit=$_COOKIE['lastVisit'];
     echo "Your last visit was-".$visit;
}
else
     echo "You've got some stale cookies!";
?>


//10.php

<?php session_start();
session_register("count");
if(!isset($_SESSION))
{
     $_SESSION["count"]=0;
     echo "<p>Counter initialized</p>\n";
}
else {$_SESSION["count"]++;}
echo "<p>The counter is now <b>$_SESSION[count]</b></p>". "<p>Reload this page to incremented</p>";
?>


//11a.php
<html>
<body>
<hr />
<?php
$nme=$_POST["name"];
$ad1=$_POST["add1"];
$ad2=$_POST["add2"];
$em1=$_POST["email"];
if($nme=="")
{
echo("<p><center>Name not provided</center></p>");
$check=1;
}
if($ad1=="")
{
echo("<p><center>Address not provided</center></p>");
$check=1;
}
if($em1=="")
{
echo("<p><center>Email not provided</center></p>");
$check=1;
}
if($check!=1)
{
$dbcnx=mysql_connect("localhost","root","server");
if(!$dbcnx)
{
echo("<p>unable to connect to the".
"database at this time.</p>");
exit();
}
if(!mysql_select_db("mysql"))
{
echo("<p>unable to locate the mysql".
"database at this time.</p>");
exit();
}
$sql="INSERT INTO contact VALUES('$nme','$ad1','$ad2','$em1')";
if(mysql_query($sql))

echo("<p><center>details has been added.</centerd></p>");
else
{
echo("<p><center>unable to add submitted:".
mysql_error()."</center></p>");
}
}
else
{
echo("<p><center>unable to add record</center></p>");
}
?>
<hr />
<form action="11c.html">
<input type="submit" value="back" />
</form>
</body>
</html>


//11b.php
<html>
<head><title>Search result</title></head>
<body>
<h3>Search result</h3>
<hr/>
<?php
$link=mysql_connect("localhost","root","server");
mysql_select_db("mysql");
$n=$_POST["name1"];
if($n==null)
{
        print "<h4>Please Enter the search element </h4>";
}
else
{
        print "Entered name is <h4>\"$n\"</h4>";
        $var=mysql_query("SELECT * FROM contact WHERE nme='$n'");
        $num_rows=mysql_num_rows($var);
        if($num_rows>0)
        {
                echo "<table border size=1>";
                echo "<tr><th>Name </th> <th>Adress1</th> <th>Adress2</th>
<th>email</th> </tr>";
                while($arr=mysql_fetch_row($var))
                {
                        echo "<tr><td>$arr[0]</td><td>$arr[1]</td><td>$arr[2]</td>
<td>$arr[3]</td></tr>";
                }
                echo "</table>";
        }
        else
        {
                print "<h4>No such records found</h4>";
        }
        mysql_free_result($var);
}
mysql_close($link);
?>
<hr/>
<form action="11c.html">
<input type="submit" value="back">
</form>
</body>
</html>

//11c.html
<html>
<head><title>Enter details</title></head>
<body>
<h3>Enter details</h3>
<form action="11a.php" method="post">
Enter Name <input type="text" name="name" /><br />
Enter Address1 <input type="text" name="add1" /><br />
Enter Address2 <input type="text" name="add2" /><br />
Enter Email <input type="text" name="email" /><br />
<input type="submit" value="Insert" />
</form>
<h3>Search details</h3>
<form action="11b.php" method="post">
Enter name for Person<input type="text" name="name1" /><br />
<input type="Submit" />
</form>
</body>
</html>


//12

Creating Books Database
mysql -u root

create database lab12_development;

create database lab12_test;
create database lab12_production;

use lab12_development;

create table books (
id int not null auto_increment,
accession_no int not null,
title varchar(80) not null,
authors text not null,
edition decimal(8, 2) not null,
publisher varchar(80) not null,
primary key(id)
);

After creating the database and table, quit from mysql.. quit;

Creating lab12 Project
rails -d mysql lab12

Change the directory to lab12
Cd lab12

Creating controller, model and view from database
ruby script/generate scaffold Book accession_no:integer title:string authors:text edition:float publisher:string
Starting Rails Server
ruby script/server
Executing in the web browser
http://localhost:3000/books
Creating main (new) controller for searching book
ruby script/generate controller main
Opening main controller program
edit app\controllers\main_controller.rb
class MainController < ApplicationController
     def welcome
          @num_books = Book.count
     end
     def result
          @booktitle = params[:title]
          @bookz = Book.find(:all, :conditions => "title = '#{@booktitle}'")
     end

end

Create two views welcome and result

Create Result view file
> notepad app\views\main\result.rhtml
<html>
<title> Welcome template for books </title>
<body>
<p> Entered book title is <%= @booktitle %> </p>
<table border=1>
<tr><th>Accession No.</th><th>Book Title</th><th>Authors </th> <th>Publishers </th> <th>Edition </th></tr>
<% @bookz.each do |bk|
@id = bk.id
@accession= bk.accession_no;
@title = bk.title
@authors = bk.authors
@publisher = bk.publisher
@edition = bk.edition %>
<tr>
<td> <%= @accession %></td>
<td><%= @title %> </td>
<td><%= @authors %></td>
<td> <%= @publisher %></td>
<td> <%= @edition %></td>
</tr>
<% end %>
</table>
</form>
</body>
</html>

Create Welcome view file
> notepad app\views\main\welcome.rhtml
<html>
<title> Welcome template for books </title>
<body>
<p> Total number of books = <%= @num_books %> </p>
<form action = "result" >
Enter Searching Title: <input type="text" name="title" />
<input type=submit value="Search" />
</form>
</body>
</html>
Starting Rails Server
ruby script/server
Executing in the web browser
http://localhost:3000/main/welcome
Welcome.rhtml
Result.rhtml



0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home