3.0.1.3.2 – Introduction to CGI 4/8/2004 3.0.1.3.2 - Introduction to CGI 1 3.0.1.3.2 Introduction to CGI – Session 2 · Introduction to CGI:  Generating.

Slides:



Advertisements
Similar presentations
Connecting to Databases. connecting to DB DB server typically a standalone application Server runs on localhost for smaller sites –i.e. Same machine as.
Advertisements

Connecting to Databases. relational databases tables and relations accessed using SQL database -specific functionality –transaction processing commit.
Programming MySQL, Perl COEN 351. Reading List Paul DuBois: MySQL and Perl for the Web, New Riders, 2002 Jacqueline D. Hamilton: CGI Programming 101,
KompoZer. This is what KompoZer will look like with a blank document open. As you can see, there are a lot of icons for beginning users. But don't be.
PHP Sample Application Simple graphics and database.
W EB A PPLICATION D EVELOPMENT A PPLICATION T O B IO -I NFORMATICS -III Vicky Khanna M-Tech Bioinformatics.
CGI Programming.
CGI Programming Part 2. Input Tags Many different ways of getting data from the user. The tag is used most often. has a type attribute –Specifies the.
Implementing Session Support COEN 351. State Maintenance Client Side Mechanisms  Cookies Client needs to allow cookies Cookie handling done by browser.
MSc Bioinformatics 2006 Biocomputing Databases and Perl 13 th February 2006.
Copyright 2004 Monash University IMS5401 Web-based Systems Development Topic 2: Elements of the Web (g) Interactivity.
CGI programming in Perl Learning Objectives: 1. To understand how a CGI program works in Perl and how to make it runnable in web browsers 2. To learn how.
Perl and MySQL Using apache server with perl cgi Using MySQL Need to install dbi and dbd modules to your perl installation. There are some good examples.
Databases and Perl Using Perl to talk to databases.
CGI Programming in Perl Software Tools. Lecture 22 / Slide 2 CGI Programming l Last time we looked at designing a static web page. Today we will see how.
CGI programming in Perl Learning Objectives: 1. To understand how a CGI program works in Perl and how to make it runnable in web browsers 2. To learn how.
M.P. Johnson, DBMS, Stern/NYU, Spring C : Database Management Systems Lecture #21 M.P. Johnson Stern School of Business, NYU Spring, 2005.
Lossless Compression in Multimedia Data Representation Hao Jiang Computer Science Department Sept. 20, 2007.
Perl DBI Scripting with the ILS Roy Zimmer Western Michigan University.
2440: 141 Web Site Administration Web Server-Side Programming Professor: Enoch E. Damson.
Scanning and Graphics Workshop I Graphics for the Web, Scanning and Introduction to Photoshop.
With Alex Conger – President of Webmajik.com FrontPage 2002 Level I (Intro & Training) FrontPage 2002 Level I (Intro & Training)
 2004 Prentice Hall, Inc. All rights reserved. Chapter 25 – Perl and CGI (Common Gateway Interface) Outline 25.1 Introduction 25.2 Perl 25.3 String Processing.
Chapter 14-Designing for the World Wide Web. Overview Introducing multimedia on the Web. Designing text for the Web. Creating images for the Web. Adding.
Data Visualisation A picture is worth a thousand words.
Set 5: Perl and Database Connections
1 HTML and CGI Scripting CSC8304 – Computing Environments for Bioinformatics - Lecture 10.
Database testing Prepared by Saurabh sinha. Database testing mainly focus on: Data integrity test Data integrity test Stored procedures test Stored procedures.
27/07/2001 Copyright 2001, Munica Corporation, 1 How to write a DBD driver Daini Xie Strathy President Munica Corporation
European Computer Driving Licence Syllabus version 5.0 Module 4 – Spreadsheets Chapter 22 – Functions Pass ECDL5 for Office 2007 Module 4 Spreadsheets.
DBI tutorial February 5 th, What is DBI DBI is short for Database Interface, which is a Perl module DBI is short for Database Interface, which is.
Information & Decision Management Dept West Texas A&M University
Digital Image: Representation & Processing (2/2) Lecture-3
2 1 Sending Data Using a Hyperlink CGI/Perl Programming By Diane Zak.
Images Inserting an image on a web page. chcslonline.org2 ITEMS REQUIRED Go to the course download page on the course website and download the 3 images.
Perl Web Page – Just Enough Pepper. Web site Set up the top of your script to indicate perl and plain text #!/usr/bin/perl print "Content-type:text/plain\n\n";
Database Chess A server-based web gaming application by Jordan Arnold.
CSU - DCE Advanced Perl CGI Operation - Fort Collins, CO Copyright © XTR Systems, LLC Introduction to the Common Gateway Interface (CGI) on the.
1 Web Developer & Design Foundations with XHTML Chapter 4 Key Concepts.
Applied Research Laboratory UNCLASSIFIED IOUW 2000 Managing Oracle and Other Cool Things You Can Do with PERL John D. Groenveld Manufacturing Systems Division.
BINF 634 Fall Lec 11 Visualization1 Plan for Tonight A synopsis of our progress through the course Lecture 11 Visualization in PERL Lab 2 Based.
(Chapter 10 continued) Our examples feature MySQL as the database engine. It's open source and free. It's fully featured. And it's platform independent.
1 Ethics of Computing MONT 113G, Spring 2012 Session 10 HTML Tables Graphics on the Web.
9 1 DBM Databases CGI/Perl Programming By Diane Zak.
Data Compression. Compression? Compression refers to the ways in which the amount of data needed to store an image or other file can be reduced. This.
Information Processes and Technology Multimedia: Graphics.
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
Databases On The Web with perl Archie Warnock
Computational Boot Camp HTML Mike Schaffer. 8/23/2002 (MES) HTML What is HTML? HTML stands for HyperText Markup Language HTML is the language for publishing.
A BCDE.
Java, JDBC, Perl, CGI Embedded SQL November 3 rd, 2000.
Intermediate CGI & CGI.pm Webmaster II - Fort Collins, CO Copyright © XTR Systems, LLC CGI Programming & The CGI.pm Perl Module Instructor: Joseph DiVerdi,
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
Web Design and Development. World Wide Web  World Wide Web (WWW or W3), collection of globally distributed text and multimedia documents and files 
Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. Intermediate Perl Programming Class Three Instructor:
 2001 Prentice Hall, Inc. All rights reserved. Chapter 7 - Introduction to Common Gateway Interface (CGI) Outline 7.1Introduction 7.2A Simple HTTP Transaction.
CP476 Internet Computing Perl CGI and MySql 1 Relational Databases –A database is a collection of data organized to allow relatively easy access for retrievals,
Slide 1 Graphics (Characteristics 1) Images have various characteristics that affect performance Size (number of pixels) – Large images can be several.
DBI: The Neophyte's Guide1 What is DBI? DBI = DataBase Interface DBI is database-independent DBI allows you to write code that interacts with databases.
PHP and SQL Server: Connection IST 210: Organization of Data IST2101.
COMP234 - perl Perl DBI Topics Database vs access methods DBMS and DBMS API's Relational database SEQUEL Perl DBI SQL.
Sending data with CGI/Perl Please use speaker notes for additional information!
University of Kansas Department of Electrical Engineering and Computer Science Dr. Susan Gauch April 21, 2005 I T T C Introduction to Web Technologies.
Revision Lecture: HTML, CSS and XML Perl/CGI, Perl/DOM, Perl/DBI, Remote Procedure Calls Dr. Andrew C.R. Martin
Chapter 7 - Introduction to Common Gateway Interface (CGI)
Chapter 21 – Graphics/Tk Outline 21.1 Introduction 21.2 GD Module: Creating Simple Shapes 21.3 GD Module: Image Manipulation 21.4 Chart Module 21.5 Introduction.
Perl Database – Just Enough
CGI Programming Part II UNIX Security
Graphics (Characteristics 1)
Tutorial 6 PHP & MySQL Li Xu
Presentation transcript:

– Introduction to CGI 4/8/ Introduction to CGI Introduction to CGI – Session 2 · Introduction to CGI:  Generating images with Perl  GD.pm module  Databases: introduction  Database simulation with CSV  Working Bulletin Board example

– Introduction to CGI 4/8/ Introduction to CGI 2 Drawing Images with Perl CPAN provides a multitude of different modules for generating different kinds of graphic output

– Introduction to CGI 4/8/ Introduction to CGI 3 On image formats supported by GD.pm · GIF · Last version of GD.pm which supports GIF format is 1.19, · GIF features: 256 colors, Interlace, Animated GIF (Gif89a) LZW compression (lossless) · PNG · LZW-stripped GIF, · Additional features: · Alternative compression algorithm, · 3modes: 256 color; 16-bit grayscale, 48-bit truecolor · Support for alpha channel, · Better interlacing · JPEG · Ideal for photographs, as it designed for encoding continuous tone images · 24-bit color, · Compression with losses Legal battle between Unisys (creator of LZW compression algorithm) and developers resulted in dropping of GIF support in newer versions of GD.pm

– Introduction to CGI 4/8/ Introduction to CGI 4 GD.pm - module by Lincoln Stein #!/usr/local/bin/perl -wT use CGI qw(:standard); use GD;.. my $im = new GD::Image(400,400); my %color = (black=>$im->colorAllocate(0,0,0), white=>$im->colorAllocate(255,255,255), yellow=>$im->colorAllocate(255,255,0) ); $im->fill(200,200,$color{white}); $im->arc(200,200,150,150,0,360,$color{black}); $im->fill(200,200,$color{yellow}); $im->arc(170,170,10,10,0,360,$color{black}); $im->arc(230,170,10,10,0,360,$color{black}); $im->fill(200,200,$color{yellow}); $im->arc(200,200,110,110,0,180,$color{black}); print header(-type=>"image/gif"); binmode STDOUT; print $im->gif; First Example: simple drawing This code uses $image->gif method, so it runs only with Version 1.19 of GD

– Introduction to CGI 4/8/ Introduction to CGI 5 GD.pm drawing methods · Some drawing methods of GD.pm: · Coordinate system. The start of coordinate axis screen. X lies horizontally and Y - vertically use GD;.. my $im = new GD::Image($width,$height); $im->line($x1,$y1,$x2,$y2,$color); $im->arc($x,$y,$width,$height,$start,$end,$color); $im->ellipse($cx,$cy,$width,$height,$color); $image->filledRectangle($x1,$y1,$x2,$y2,$color); $im->string($font,$x,$y,$string,$color); $im->fill(200,200,$color); $im->fillToBorder($x,$y,$bordercolor,$color); print header(-type=>"image/png"); binmode STDOUT; print $im->png;

– Introduction to CGI 4/8/ Introduction to CGI 6 Calling CGI-generated images · Referencing Images: · In the URL box of a web browser: · In HTML code of your web page: · Object-oriented way (CGI.pm style):.. print img({-src=>”

– Introduction to CGI 4/8/ Introduction to CGI 7 Manipulating static images #!/usr/bin/perl -w use CGI qw(:standard); use GD; use IO::File; use strict; my $fh = new IO::File; $fh->open("Myimage.gif") or die "Couldn't open file\n"; my $im2 = GD::Image->newFromGif($fh); $fh->close; my $im = new GD::Image(500,635); my %color = (black => $im->colorAllocate(0,0,0), white => $im->colorAllocate(255,255,255), green => $im->colorAllocate(0,255,0) ); $im->fill(100,100,$color{green}); $im->arc(390,100,250,150,0,360,$color{black}); $im->fill(390,100,$color{white}); $im->transparent($color{green}); $im->string(gdGiantFont,310,90,“Some stuff",$color{black}); $im2->copy($im,0,0,0,0,500,635); print header(-type=>"image/gif"); binmode STDOUT; print $im2->gif; GD may be also used for rotating, cloning, merging Images etc

– Introduction to CGI 4/8/ Introduction to CGI 8 Debriefing: First, we are bringing in the external image into the script using its file handle as an argument for newFromGif() method When an image is merged with another one, its pixel data overwrites the pixel data of the target image #!/usr/bin/perl -w use CGI qw(:standard); use GD; use IO::File; use strict; my $fh = new IO::File; $fh->open("Myimage.gif") or die "Couldn't open file\n"; my $im2 = GD::Image->newFromGif($fh); $fh->close; $im2->copy($im,0,0,0,0,500,635); print header(-type=>"image/gif"); binmode STDOUT; print $im2->gif; Beware of newer methods in later versions of GD, as the given example might benefit greatly by using some newer stuff and the code would have been much shorter!

– Introduction to CGI 4/8/ Introduction to CGI 9 GD::Graph modules · GD::Graph provides basic diagram modules: · Points, Bars, Pie Charts, Area, 3D graphs etc.

– Introduction to CGI 4/8/ Introduction to CGI 10 Simple example of using GG::Graph::bars · Printing bars in CGI:.. use CGI; use GD::Graph::bars; use constant TITLE => "Number of Chromosomes in mammals"; my $q = new CGI; my $graph = new GD::Graph::bars(400,400); = ( [ qw(Cow Chimp Human Dog Mouse Camel)], [ 60,48,46,78,40,74 ] ); $graph->set(x_label=> 'Species', y_label=> 'chromosomes', title => TITLE, ) or die $graph->error; print $q->header(-type=>"image/gif"); my $image = binmode STDOUT; print $image->gif; As the previous example, this code uses GIF format, so please note that it runs only with version 1.19 of GD set() and plot() methods are common for all GD::Graph modules

– Introduction to CGI 4/8/ Introduction to CGI 11 Common methods for GD::Graph modules · Use array of anonymous arrays to pass the data to GD::Graph modules, X series goes first. Please note, that there are specific procedures are required to make X axis numeric. Sort your data by X value. · Set() and plot() methods · = ( · [ qw(Cow Chimp Human Dog Mouse Camel)], · [ 60,48,46,78,40,74 ] · ); · $graph->set(x_label=> 'Species', · y_label=> 'chromosomes', · title => “some title”, · ) or die $graph->error; · my $image = Look for more bells and whistles in documentation for GD::Graph modules available on CPAN website

– Introduction to CGI 4/8/ Introduction to CGI 12 Examples from scientific websites NCBI Mapviewer. Wormbase website.

– Introduction to CGI 4/8/ Introduction to CGI 13 Using databases in Perl · DBI and DBD interaction: Definitions: DBI - Database interface DBD - Database driver

– Introduction to CGI 4/8/ Introduction to CGI 14 Checking on DBD drivers:.. use CGI; use DBI; use CGI::Carp(fatalsToBrowser); my $q = new CGI; print $q->header(-type=>"text/html"); print $q->start_html(-title=>"Testing DBI drivers"); = DBI->available_drivers; print print "CGI version ".$q->version; print $q->end_html; Interpreter: usr/local/bin/perl (above) usr/bin/perl (below)

– Introduction to CGI 4/8/ Introduction to CGI 15 Connection to mysql databse: example · First, get a handle for that database: · Second, hmm….. There two things could be done: · If you need to get some data from database, create a statement handle: use DBI; my $dbh = DBI->connect(‘DBI:mysql:database:host:3306’,’user’,’password’) or die “No luck\n”;.. $dbh->do(qq(insert into table_name values(‘Frodo’, ‘hobbit’,’ ’))); my $sth = $dbh->prepare(qq(select from table_name name, occupation, phone_number)); $sth->execute;

– Introduction to CGI 4/8/ Introduction to CGI 16 Getting data with statement handle · First thing to do after execution: · Other methods for fetching data from statement handle: · Clean after yourself: = $sth->fetchrow_array){.. do something here } $sth->finish; $dbh->disconnect; $ary_ref = $sth->fetchrow_arrayref; $hash_ref = $sth->fetchrow_hashref; $ary_ref = $sth->fetchall_arrayref; $ary_ref = $sth->fetchall_arrayref( $slice, $max_rows ); Perl can disconnect on exit but it is not a good thing to leave it neglected

– Introduction to CGI 4/8/ Introduction to CGI 17 DBI::CSV - testing ground for database development DBD::CSV provides SQL-database functionality without database engine · CSV stands for Comma Separated Values. There is no database backend in case of CSV (no db engine running). Relies on flock() method (file locking system). · CSV database understands SQL - migration to fully-functional mySQL database requires only couple of lines of code! · Note: CSV driver may not work correctly over NFS, the best way to make it work - run Apache on localhost for testing CSV-powered cgi scripts. Offline scripts work just fine! #!/usr/bin/perl -w use DBI; my $dbh = DBI->connect("DBI:CSV:f_dir=/home/user/www/cgi-bin/db") or die "Couldn't connect\n”;

– Introduction to CGI 4/8/ Introduction to CGI 18 Simple example (table creation and insertion of data) · Simple example · The following script does two things: · creates a table · puts some records into table #!/usr/bin/perl -w use DBI; my $dbh = DBI->connect("DBI:CSV:f_dir=/home/user/www/cgi-bin/db") or die "Couldn't connect to the database\n"; my $sth = $dbh->prepare(qq( create table forum( Name CHAR(15), Message CHAR(100) )) ) or die "CAN NOT PREPARE STMT\n"; $sth->execute; $dbh->do("insert into forum values('Frodo','Umm... Ring')"); $dbh->do("insert into forum values('Gollum','This is my precois')"); $dbh->do("insert into forum values('Gandalf','Relax, buddy - you can not pass')"); $dbh->disconnect;

– Introduction to CGI 4/8/ Introduction to CGI 19 Connecting to database from CGI script · Let’s build a CGI script which reads from CSV table · This script connects to the database from the previous example, reads our records and print them in a HTML table.. use DBI; my $dbh = DBI->connect("DBI:CSV:f_dir=db") or die "Couldn't connect to the database\n"; my $sth = $dbh->prepare("select * from forum") or $dbh->errstr(); $sth->execute or $dbh->errstr(); = $sth->fetchrow_array){ } $sth->finish; $dbh->disconnect; print header(-type=>"text/html"); print start_html(-title=>"Creator of tables"); print end_html;

– Introduction to CGI 4/8/ Introduction to CGI 20 Dynamic update of CSV database from a web page use DBI; my $name = param("Name"); my $message = param("Message"); if($name && $message){ my $dbh = DBI->connect("DBI:CSV:f_dir=db") or die "Couldn't connect to the database\n"; $dbh->do("insert into forum values('$name','$message')"); $dbh->disconnect; print redirect("forum_csv.cgi"); }.. print start_form(-name =>"poster", -action=>"forum_csv.cgi", -method=>"post"), "Name:", textfield(-name =>"Name", -maxlength=>18), br, textarea(-name=>"Message", -cols=>40, -rows=>15), br, submit(-name=>"sender", -value=>"Send"), end_form, end_html;

– Introduction to CGI 4/8/ Introduction to CGI Introduction to CGI – Session 2 · Images: · CGI can make images dynamic · GD.pm is good for schematic drawings · Use CPAN to look for fancy stuff · Database: · DBI is your friend · Use DBI::CSV for apps development