<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>

<channel>
	<title>Brain Dump v1.0</title>
	<atom:link href="http://sgowtham.net/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://sgowtham.net/blog</link>
	<description>Rambling About Life's Little Things</description>
	<pubDate>Fri, 25 Jul 2008 13:57:10 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6</generator>
	<language>en</language>
			<item>
		<title>Storing And Querying Information with PERL-MySQL</title>
		<link>http://sgowtham.net/blog/2008/07/25/storing-and-querying-information-with-perl-mysql/</link>
		<comments>http://sgowtham.net/blog/2008/07/25/storing-and-querying-information-with-perl-mysql/#comments</comments>
		<pubDate>Fri, 25 Jul 2008 04:01:27 +0000</pubDate>
		<dc:creator>Gowtham</dc:creator>
		
		<category><![CDATA[MTU]]></category>

		<category><![CDATA[Research]]></category>

		<category><![CDATA[Scripting]]></category>

		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://sgowtham.net/blog/?p=359</guid>
		<description><![CDATA[During the Christmas break of 2005-06 (while I was a graduate student in Michigan Technological University), I thought it would be nice to have a tool to store details pertaining to our research group publications in a MySQL database (instead of a flat HTML file). Some underlying motives were as follows:

List all publications in a [...]]]></description>
			<content:encoded><![CDATA[<p>During the Christmas break of 2005-06 (while I was a graduate student in <a href="http://www.mtu.edu/" target="_blank">Michigan Technological University</a>), I thought it would be nice to have a tool to store details pertaining to our <a href="http://www.phy.mtu.edu/pandey/" target="_blank">research group</a> publications in a MySQL database (instead of a flat HTML file). Some underlying motives were as follows:</p>
<ol>
<li>List all publications in a year - helps when generating annual progress reports</li>
<li>List all publications by any given author(s)</li>
<li>A combination of the above two possibilities</li>
</ol>
<p>The server which served our research group website used Sun OS 5.6 and for security-related reasons, it did not have PHP. As such, it became necessary (a good thing!) that this utility had to be written using PERL CGI (<a href="http://en.wikipedia.org/wiki/Common_Gateway_Interface" target="_blank">Common Gateway Interface</a>). List of required features (implemented over a period of time) included:</p>
<ol>
<li><strong>User Side</strong>
<ol>
<li>Display all publications when no query is submitted (default display) - include a search form</li>
<li>Searchable by year of publication</li>
<li>Searchable by two authors</li>
<li>Searchable by a combination of #2 and #3</li>
<li>When displaying queried results, include Abstract</li>
</ol>
</li>
<li><strong>Admin Side:</strong>
<ol>
<li>Adding a new publication to the database, with PDF upload option (GUI)</li>
<li>Updating details for an entry that already exists in a database (GUI)</li>
<li>Deleting an entry from the database (GUI)</li>
<li>Restricted access</li>
</ol>
</li>
</ol>
<p>Starting with MySQL database/table structure, these requirements are described one by one in following subsections.</p>
<p><br clear="all"></p>
<h3 class="blog">#0. Preliminary Settings</h3>
<p>Let us assume that:</p>
<ol>
<li>The web documents are stored under <strong>/var/www/html</strong> and will henceforth be referred to as <strong>$DocumentRoot</strong> (if you are trying to implement this in your research group in a university/academic institution, please check with your systems administrator for the appropriate value of <strong>$DocumentRoot</strong>).</li>
<li>The page (with search form) which users will interact is called <strong>publications.cgi</strong> and is stored under <strong>$DocumentRoot</strong>.</li>
<li>The folder that contains PDF version of publications is called <strong>pdf</strong> and is located under <strong>$DocumentRoot</strong>. Make sure this folder has <strong>777</strong> permission.</li>
<li>The folder that contains administrative CGI scripts is called <strong>admin</strong> and is located under <strong>$DocumentRoot</strong>. This folder must have restricted access.</li>
</ol>
<p><br clear="all"></p>
<h3 class="blog">#1. MySQL Database</h3>
<ol>
<li>Create a database. If <strong>einstein</strong> is userid of the group&#8217;s principal investigator, then <strong>einstein_research</strong> would be just fine a name for the database. </li>
<li>Create a dummy user (within MySQL), <strong>einstein_webuser</strong>, with at least <strong>INSERT</strong>, <strong>UPDATE</strong>, <strong>SELECT</strong> and <strong>DELETE</strong> previliges on <strong>einstein_research</strong> database.</li>
<li>Set a (strong enough) password for this dummy user.</li>
<li>Create a table within <strong>einstein_research</strong> database, <strong>publications</strong>, with following structure:

<div class="wp_syntax"><div class="code"><pre class="sql"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #ff0000;">`publications`</span> <span style="color: #66cc66;">&#40;</span>
  <span style="color: #ff0000;">`PubID`</span>    int<span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">11</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span> <span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`BibID`</span>    varchar<span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">15</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #66cc66;">,</span> 
  <span style="color: #ff0000;">`Title`</span>    varchar<span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">255</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`Authors`</span>  varchar<span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">150</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`JName`</span>    varchar<span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">30</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`JVolume`</span>  int<span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">8</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`JYear`</span>    year<span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">4</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`JPage`</span>    int<span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">11</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`Abstract`</span> text<span style="color: #66cc66;">,</span>
  <span style="color: #993333; font-weight: bold;">UNIQUE</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #ff0000;">`BibID`</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">`BibID`</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">,</span>
  <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #ff0000;">`PubID`</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">`PubID`</span> <span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span> ENGINE <span style="color: #66cc66;">=</span> MYISAM <span style="color: #993333; font-weight: bold;">DEFAULT</span> CHARSET <span style="color: #66cc66;">=</span> latin1;</pre></div></div>

</li>
</ol>
<p>It is generally a good idea to back up these databases on a regular basis - to save oneself from the pain of re-entering everything if something were to go wrong. You may refer to one of my previous posts that discusses <a href="http://sgowtham.net/blog/2008/04/04/backing-up-and-restoring-mysql-databases/" target="_blank">backing up and restoring MySQL databases</a> in detail.</p>
<p><br clear="all"></p>
<h3 class="blog">#2. User Side: <strong>publications.cgi</strong></h3>
<p>Following one of the requirements as mentioned before, this page must display all publications when no query is submitted (default view) and display only those publications (with abstract) when a query is submitted. The part below is the code for default view.</p>

<div class="wp_syntax"><div class="code"><pre class="perl"><span style="color: #666666; font-style: italic;">#! /usr/bin/perl</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># publications.cgi (PART #1)</span>
<span style="color: #666666; font-style: italic;"># CGI script to search the database</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Modules being used</span>
<span style="color: #000000; font-weight: bold;">use</span> DBI<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> CGI<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Make a CGI object and retrieve information from the form</span>
<span style="color: #0000ff;">$inputform</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> CGI<span style="color: #339933;">;</span>
<span style="color: #000066;">print</span> <span style="color: #0000ff;">$inputform</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">header</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Get values from the form</span>
<span style="color: #0000ff;">$year</span>    <span style="color: #339933;">=</span> <span style="color: #0000ff;">$inputform</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">param</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;year&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$title</span>   <span style="color: #339933;">=</span> <span style="color: #0000ff;">$inputform</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">param</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;title&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$author1</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$inputform</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">param</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;author1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$author2</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$inputform</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">param</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;author2&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$bo1</span>     <span style="color: #339933;">=</span> <span style="color: #0000ff;">$inputform</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">param</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;BO1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$bo2</span>     <span style="color: #339933;">=</span> <span style="color: #0000ff;">$inputform</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">param</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;BO2&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$bo3</span>     <span style="color: #339933;">=</span> <span style="color: #0000ff;">$inputform</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">param</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;BO3&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$ffill</span>   <span style="color: #339933;">=</span> <span style="color: #0000ff;">$inputform</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">param</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;ffill&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># If the variable 'ffill' is empty, then display the form</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$ffill</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #000066;">print</span> <span style="color: #cc0000; font-style: italic;">&lt;&lt; &quot;EOF&quot;;
&lt;!-- www.w3c.org standard --&gt;
&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;&gt;
&nbsp;
&lt;!-- HTML begins --&gt;
&lt;html&gt;
&nbsp;
&lt;!-- HEAD section --&gt;
&lt;head&gt;
&nbsp;
&lt;!-- TITLE section --&gt;
&lt;title&gt;
Your Research Group, Your Academic Institution
&lt;/title&gt;
&nbsp;
&lt;/head&gt;
&nbsp;
&lt;!-- BODY section --&gt;
&lt;body&gt;
&nbsp;
&lt;!-- Group Header --&gt;
&lt;h1&gt;YOUR GROUP NAME&lt;/h1&gt;
&nbsp;
&lt;h2&gt;Publications&lt;/h2&gt;
&nbsp;
&lt;!-- FORM --&gt;
&lt;form method=&quot;POST&quot; action=&quot;/publications.cgi&quot;&gt;
&lt;table border=&quot;0&quot; cellpadding=&quot;5&quot; cellspacing=&quot;3&quot; align=&quot;center&quot;&gt;
&nbsp;
&lt;tr&gt;
&lt;td&gt;&lt;b&gt;Year&lt;/b&gt; &amp;nbsp; &amp;nbsp;&lt;/td&gt;
&lt;td&gt;
  &lt;select name=&quot;year&quot;&gt;
    &lt;option value='%'&gt;Any&lt;/option&gt;
    &lt;option value='2008'&gt;2008&lt;/option&gt;
    &lt;option value='2007'&gt;2007&lt;/option&gt;
    &lt;option value='2006'&gt;2006&lt;/option&gt;
    &lt;option value='2005'&gt;2005&lt;/option&gt;
    &lt;option value='2004'&gt;2004&lt;/option&gt;
    &lt;option value='2003'&gt;2003&lt;/option&gt;
    &lt;option value='2002'&gt;2002&lt;/option&gt;
    &lt;option value='2001'&gt;2001&lt;/option&gt;
    &lt;option value='2000'&gt;2000&lt;/option&gt;
  &lt;/select&gt;
&lt;/td&gt;
&lt;td&gt;
  &lt;select name=&quot;BO1&quot;&gt;
    &lt;option value='AND'&gt;AND&lt;/option&gt;
    &lt;option value='OR'&gt;OR&lt;/option&gt;
  &lt;/select&gt;
&lt;/td&gt;
&lt;td&gt;&lt;b&gt;Title&lt;/b&gt;&lt;/td&gt;
&lt;td&gt;
  &lt;input type=&quot;text&quot; name=&quot;title&quot; size=&quot;15&quot;&gt; &amp;nbsp; &amp;nbsp;
&lt;/td&gt;
&lt;td&gt;
  &lt;select name=&quot;BO2&quot;&gt;
    &lt;option value='AND'&gt;AND&lt;/option&gt;
    &lt;option value='OR'&gt;OR&lt;/option&gt;
  &lt;/select&gt;
&lt;/td&gt;
&lt;/tr&gt;
&nbsp;
&lt;tr&gt;
&lt;td&gt;&lt;b&gt;Author&lt;/b&gt;&lt;/td&gt;
&lt;td&gt;
  &lt;input type=&quot;text&quot; name=&quot;author1&quot; size=&quot;15&quot;&gt;
&lt;/td&gt;
&lt;td&gt;
  &lt;select name=&quot;BO3&quot;&gt;
    &lt;option value='AND'&gt;AND&lt;/option&gt;
    &lt;option value='OR'&gt;OR&lt;/option&gt;
  &lt;/select&gt;
&lt;/td&gt;
&lt;td&gt;&lt;b&gt;Author&lt;/b&gt;&lt;/td&gt;
&lt;td&gt;
  &lt;input type=&quot;text&quot; name=&quot;author2&quot; size=&quot;15&quot;&gt;
&lt;/td&gt;
&lt;td&gt;
&amp;nbsp;
&lt;/td&gt;
&lt;/tr&gt;
&nbsp;
&lt;tr&gt;
&lt;td colspan=&quot;6&quot;&gt;
  &lt;input type=&quot;hidden&quot; name=&quot;ffill&quot; value=&quot;filled&quot; size=&quot;15&quot;&gt;
  &lt;input type=&quot;submit&quot; value=&quot;Search&quot;&gt;
  &lt;input type=&quot;reset&quot;  value=&quot;Clear&quot;&gt;
&lt;/td&gt;
&lt;/tr&gt;
&nbsp;
&lt;tr&gt;
&lt;td colspan=&quot;6&quot;&gt;
&lt;br&gt;** All fields are optional
&lt;/td&gt;
&lt;/tr&gt;
&nbsp;
&lt;/table&gt;
&lt;/form&gt;
EOF</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Connect to the database and perform the SQL query</span>
<span style="color: #0000ff;">$dbh</span>      <span style="color: #339933;">=</span> DBI<span style="color: #339933;">-&gt;</span><span style="color: #006600;">connect</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'dbi:mysql:einstein_research:localhost'</span><span style="color: #339933;">,</span><span style="color: #ff0000;">'einstein_web'</span><span style="color: #339933;">,</span><span style="color: #ff0000;">'PASSWORD'</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">or</span> <span style="color: #000066;">die</span> <span style="color: #ff0000;">&quot;Error&quot;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$sql1</span>     <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;SELECT * FROM publications ORDER BY JYear DESC, &quot;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$sql</span>      <span style="color: #339933;">=</span> <span style="color: #0000ff;">$sql1</span> . <span style="color: #ff0000;">&quot;JName ASC, JVolume DESC, JPage DESC, Title&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #0000ff;">$query</span>    <span style="color: #339933;">=</span> <span style="color: #0000ff;">$dbh</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">prepare</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">execute</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$nresults</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">rows</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Display the results</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$nresults</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000066;">print</span> <span style="color: #cc0000; font-style: italic;">&lt;&lt; &quot;EOF&quot;;
&lt;table width=&quot;100%&quot; cellpadding=&quot;5&quot; cellspacing=&quot;5&quot; border=&quot;0&quot;&gt;
&lt;tr&gt;
&lt;td valign=&quot;top&quot;&gt;&lt;b&gt;#&lt;/b&gt;&lt;/td&gt;
&lt;td&gt;&lt;b&gt;BibID / Title / Authors / Citation&lt;/b&gt; 
	(Last-to-first, with Journals alphabetically sorted)&lt;/td&gt;
&lt;/tr&gt;
EOF</span>
&nbsp;
<span style="color: #0000ff;">$id</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$PubID</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$BibID</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$Title</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$Authors</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$JName</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$JVolume</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$JYear</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$JPage</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$Abstract</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">=</span><span style="color: #0000ff;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">fetchrow</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000066;">print</span> <span style="color: #cc0000; font-style: italic;">&lt;&lt; &quot;EOF&quot;;
  &lt;tr&gt;
  &lt;td valign=&quot;top&quot;&gt;
  $id
  &lt;/td&gt;
  &lt;td valign=&quot;top&quot;&gt;
  $BibID | 
  &lt;a href=&quot;/pdf/$BibID.pdf&quot; target=&quot;_blank&quot;&gt;PDF&lt;/a&gt;&lt;br&gt;
  $Title&lt;br&gt;
  $Authors&lt;br&gt;
  &lt;i&gt;$JName&lt;/i&gt;, &lt;b&gt;$JVolume&lt;/b&gt;, $JPage ($JYear)
  &lt;/td&gt;
  &lt;/tr&gt;
EOF</span>
  <span style="color: #0000ff;">$id</span><span style="color: #339933;">++;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000066;">print</span> <span style="color: #cc0000; font-style: italic;">&lt;&lt; &quot;EOF&quot;;
&lt;/table&gt;
EOF</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;&lt;h3&gt;Search Results&lt;/h3&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;&lt;font color=red&gt;Sorry, no records were found!&lt;/font&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000066;">print</span> <span style="color: #cc0000; font-style: italic;">&lt;&lt; &quot;EOF&quot;;
&lt;!-- Body ends --&gt;
&lt;/body&gt;
&nbsp;
&lt;!-- HTML ends --&gt;
&lt;/html&gt;
EOF</span>
<span style="color: #000066;">exit</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The part below contains the code that takes care of search-results part.</p>

<div class="wp_syntax"><div class="code"><pre class="perl"><span style="color: #666666; font-style: italic;"># publications.cgi (PART #2)</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># If the variable 'ffill' is not empty, then query the database</span>
<span style="color: #666666; font-style: italic;"># and display results</span>
<span style="color: #000066;">print</span> <span style="color: #cc0000; font-style: italic;">&lt;&lt; &quot;EOF&quot;;
&lt;!-- www.w3c.org standard --&gt;
&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;&gt;
&nbsp;
&lt;!-- HTML begins --&gt;
&lt;html&gt;
&nbsp;
&lt;!-- HEAD section --&gt;
&lt;head&gt;
&nbsp;
&lt;!-- TITLE section --&gt;
&lt;title&gt;
Your Research Group, Your Academic Institution
&lt;/title&gt;
&nbsp;
&lt;/head&gt;
&nbsp;
&lt;!-- BODY section --&gt;
&lt;body&gt;
&nbsp;
&lt;!-- Group Header --&gt;
&lt;h1&gt;YOUR GROUP NAME&lt;/h1&gt;
&nbsp;
&lt;h2&gt;Publications&lt;/h2&gt;
&nbsp;
&lt;!-- FORM --&gt;
&lt;form method=&quot;POST&quot; action=&quot;/publications.cgi&quot;&gt;
&lt;table border=&quot;0&quot; cellpadding=&quot;5&quot; cellspacing=&quot;3&quot; align=&quot;center&quot;&gt;
&nbsp;
&lt;tr&gt;
&lt;td&gt;&lt;b&gt;Year&lt;/b&gt; &amp;nbsp; &amp;nbsp;&lt;/td&gt;
&lt;td&gt;
  &lt;select name=&quot;year&quot;&gt;
    &lt;option value='%'&gt;Any&lt;/option&gt;
    &lt;option value='2008'&gt;2008&lt;/option&gt;
    &lt;option value='2007'&gt;2007&lt;/option&gt;
    &lt;option value='2006'&gt;2006&lt;/option&gt;
    &lt;option value='2005'&gt;2005&lt;/option&gt;
    &lt;option value='2004'&gt;2004&lt;/option&gt;
    &lt;option value='2003'&gt;2003&lt;/option&gt;
    &lt;option value='2002'&gt;2002&lt;/option&gt;
    &lt;option value='2001'&gt;2001&lt;/option&gt;
    &lt;option value='2000'&gt;2000&lt;/option&gt;
  &lt;/select&gt;
&lt;/td&gt;
&lt;td&gt;
  &lt;select name=&quot;BO1&quot;&gt;
    &lt;option value='AND'&gt;AND&lt;/option&gt;
    &lt;option value='OR'&gt;OR&lt;/option&gt;
  &lt;/select&gt;
&lt;/td&gt;
&lt;td&gt;&lt;b&gt;Title&lt;/b&gt;&lt;/td&gt;
&lt;td&gt;
  &lt;input type=&quot;text&quot; name=&quot;title&quot; size=&quot;15&quot;&gt; &amp;nbsp; &amp;nbsp;
&lt;/td&gt;
&lt;td&gt;
  &lt;select name=&quot;BO2&quot;&gt;
    &lt;option value='AND'&gt;AND&lt;/option&gt;
    &lt;option value='OR'&gt;OR&lt;/option&gt;
  &lt;/select&gt;
&lt;/td&gt;
&lt;/tr&gt;
&nbsp;
&lt;tr&gt;
&lt;td&gt;&lt;b&gt;Author&lt;/b&gt;&lt;/td&gt;
&lt;td&gt;
  &lt;input type=&quot;text&quot; name=&quot;author1&quot; size=&quot;15&quot;&gt;
&lt;/td&gt;
&lt;td&gt;
  &lt;select name=&quot;BO3&quot;&gt;
    &lt;option value='AND'&gt;AND&lt;/option&gt;
    &lt;option value='OR'&gt;OR&lt;/option&gt;
  &lt;/select&gt;
&lt;/td&gt;
&lt;td&gt;&lt;b&gt;Author&lt;/b&gt;&lt;/td&gt;
&lt;td&gt;
  &lt;input type=&quot;text&quot; name=&quot;author2&quot; size=&quot;15&quot;&gt;
&lt;/td&gt;
&lt;td&gt;
&amp;nbsp;
&lt;/td&gt;
&lt;/tr&gt;
&nbsp;
&lt;tr&gt;
&lt;td colspan=&quot;6&quot;&gt;
  &lt;input type=&quot;hidden&quot; name=&quot;ffill&quot; value=&quot;filled&quot; size=&quot;15&quot;&gt;
  &lt;input type=&quot;submit&quot; value=&quot;Search&quot;&gt;
  &lt;input type=&quot;reset&quot;  value=&quot;Clear&quot;&gt;
&lt;/td&gt;
&lt;/tr&gt;
&nbsp;
&lt;tr&gt;
&lt;td colspan=&quot;6&quot;&gt;
&lt;br&gt;** All fields are optional
&lt;/td&gt;
&lt;/tr&gt;
&nbsp;
&lt;/table&gt;
&lt;/form&gt;
EOF</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># If the variable 'ffill' is not empty, display the search results</span>
<span style="color: #666666; font-style: italic;"># Connect to the database and perform the SQL query</span>
<span style="color: #0000ff;">$dbh</span>      <span style="color: #339933;">=</span> DBI<span style="color: #339933;">-&gt;</span><span style="color: #006600;">connect</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'dbi:mysql:einstein_research:localhost'</span><span style="color: #339933;">,</span><span style="color: #ff0000;">'einstein_web'</span><span style="color: #339933;">,</span><span style="color: #ff0000;">'PASSWORD'</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">or</span> <span style="color: #000066;">die</span> <span style="color: #ff0000;">&quot;Error&quot;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$sql1</span>     <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;SELECT * FROM publications WHERE JYear LIKE <span style="color: #000099; font-weight: bold;">\&quot;</span>$year<span style="color: #000099; font-weight: bold;">\&quot;</span> $bo1 &quot;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$sql2</span>     <span style="color: #339933;">=</span> <span style="color: #0000ff;">$sql1</span> . <span style="color: #ff0000;">&quot;Title LIKE <span style="color: #000099; font-weight: bold;">\&quot;</span>%$title%<span style="color: #000099; font-weight: bold;">\&quot;</span> $bo2 Authors LIKE <span style="color: #000099; font-weight: bold;">\&quot;</span>%$author1%<span style="color: #000099; font-weight: bold;">\&quot;</span> $bo3 &quot;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$sql3</span>     <span style="color: #339933;">=</span> <span style="color: #0000ff;">$sql2</span> . <span style="color: #ff0000;">&quot;Authors LIKE <span style="color: #000099; font-weight: bold;">\&quot;</span>%$author2%<span style="color: #000099; font-weight: bold;">\&quot;</span> ORDER BY JYear DESC, JName ASC, &quot;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$sql</span>      <span style="color: #339933;">=</span> <span style="color: #0000ff;">$sql3</span> . <span style="color: #ff0000;">&quot;JVolume DESC, JPage DESC, Title&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #0000ff;">$query</span>    <span style="color: #339933;">=</span> <span style="color: #0000ff;">$dbh</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">prepare</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">execute</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$nresults</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">rows</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Display the results</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$nresults</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000066;">print</span> <span style="color: #cc0000; font-style: italic;">&lt;&lt; &quot;EOF&quot;;
&lt;h3&gt;Search Results&lt;/h3&gt;
Your query matched &lt;b&gt;$nresults&lt;/b&gt; result(s)&lt;br&gt;&lt;br&gt;
&lt;table width=&quot;100%&quot; cellpadding=&quot;5&quot; cellspacing=&quot;5&quot; border=&quot;0&quot;&gt;
&lt;tr&gt;
&lt;td valign=&quot;top&quot;&gt;&lt;b&gt;#&lt;/b&gt;&lt;/td&gt;
&lt;td&gt;&lt;b&gt;BibID / Title / Authors / Citation / Abstract&lt;/b&gt; 
	(Last-to-first, with Journals alphabetically sorted)&lt;/td&gt;
&lt;/tr&gt;
EOF</span>
&nbsp;
<span style="color: #0000ff;">$id</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$PubID</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$BibID</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$Title</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$Authors</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$JName</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$JVolume</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$JYear</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$JPage</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$Abstract</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">=</span><span style="color: #0000ff;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">fetchrow</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000066;">print</span> <span style="color: #cc0000; font-style: italic;">&lt;&lt; &quot;EOF&quot;;
  &lt;tr&gt;
  &lt;td valign=&quot;top&quot;&gt;
  $id
  &lt;/td&gt;
  &lt;td valign=&quot;top&quot;&gt;
  $BibID |
  &lt;a href=&quot;/pdf/$BibID.pdf&quot; target=&quot;_blank&quot;&gt;PDF&lt;/a&gt;&lt;br&gt;
  $Title&lt;br&gt;
  $Authors&lt;br&gt;
  &lt;i&gt;$JName&lt;/i&gt;, &lt;b&gt;$JVolume&lt;/b&gt;, $JPage ($JYear)
  &lt;br&gt;&lt;br&gt;
  &lt;p align=&quot;justify&quot;&gt;
  $Abstract
  &lt;/p&gt;
  &lt;br&gt;&lt;br&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
EOF</span>
  <span style="color: #0000ff;">$id</span><span style="color: #339933;">++;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000066;">print</span> <span style="color: #cc0000; font-style: italic;">&lt;&lt; &quot;EOF&quot;;
&lt;/table&gt;
EOF</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;&lt;h3&gt;Search Results&lt;/h3&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;&lt;font color=red&gt;Sorry, no records were found!&lt;/font&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000066;">print</span> <span style="color: #cc0000; font-style: italic;">&lt;&lt; &quot;EOF&quot;;
&lt;!-- Body ends --&gt;
&lt;/body&gt;
&nbsp;
&lt;!-- HTML ends --&gt;
&lt;/html&gt;
EOF</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Close database connection</span>
<span style="color: #0000ff;">$dbh</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">disconnect</span><span style="color: #339933;">;</span></pre></div></div>

<p><br clear="all"></p>
<h3 class="blog">#3. Admin Side: <strong>pub_entry.cgi</strong></h3>
<p>Guidelines for using this are as follows:</p>
<ol>
<li>
  <b>BibID</b></p>
<ol>
<li>Cannot be empty</li>
<li>Maximum of 15 characters</li>
<li>Must be UNIQUE</li>
<li>Cannot be changed later</li>
<li>Good way to compose this is by using first letters of authors&#8217; last names along with year<br />
      (i.e., if R. J. Smith, A. S. Young and B. L. Spring published an article in 2006, BibID would be SYS2006.<br />
      <br />
      In case of single author, use Smith2006)
    </li>
<li>If you expect to have more than one publication in a year by the same set of authors,<br />
      use SYS2006_0, SYS2006_1, and so on OR Smith2006_0, Smith2006_1, etc.</li>
<li>Required to delete/update an entry, if such a need arises</li>
</ol>
</li>
<li>
  <b>Title</b></p>
<ol>
<li>Cannot be empty</li>
<li>Maximum of 255 characters</li>
<li>Can contain some HTML tags (&lt;b&gt;, &lt;em&gt;, &lt;sup&gt;, &lt;sub&gt;, etc)</li>
<li>Use backslash ( &#92; ) to escape single-quotes ( &#8216; )</li>
</ol>
</li>
<li>
  <b>Authors</b></p>
<ol>
<li>Cannot be empty</li>
<li>Maximum of 150 characters</li>
<li>Separate authors by using &#8216;,&#8217; (comma)</li>
<li>Do not use &#8216;and&#8217;</li>
</ol>
</li>
<li>
  <b>Journal :: Name</b></p>
<ol>
<li>Cannot be empty</li>
<li>Maximum of 30 characters</li>
<li>Can contain some HTML tags (&lt;sup&gt;, &lt;sub&gt;, etc)</li>
</ol>
</li>
<li>
  <b>Journal :: Volume</b></p>
<ol>
<li>Cannot be empty</li>
<li>Must be an integer</li>
</ol>
</li>
<li>
  <b>Journal :: Year</b></p>
<ol>
<li>Cannot be empty</li>
<li>Must be an integer</li>
<li>Use all four digits to specify (like &#8216;2006&#8242; instead of &#8216;06&#8242;)</li>
</ol>
</li>
<li>
  <b>Journal :: Starting Page</b></p>
<ol>
<li>Cannot be empty</li>
<li>Must be an integer</li>
</ol>
</li>
<li>
  <b>Abstract</b></p>
<ol>
<li>Can be empty</li>
<li>Maximum of 255 characters</li>
<li>Can contain some HTML tags<br />
    (&lt;b&gt;, &lt;em&gt;, &lt;sup&gt;, &lt;sub&gt;, etc)</li>
<li>Use backslash ( &#92; ) to escape single-quotes ( &#8216; )</li>
</ol>
</li>
<li>
  <b>Journal :: PDF Version</b></p>
<ol>
<li>Cannot be empty</li>
<li>PDF document MUST have the SAME name as BibID</li>
<li>MUST be PDF (not just the filename extension)</li>
<li>Process DOES NOT check to make sure it is PDF</li>
</ol>
</li>
</ol>
<p>The code is split into two parts - default view is to just display a form. When properly submitted, it makes an entry into the database. Code for default view is below:</p>

<div class="wp_syntax"><div class="code"><pre class="perl"><span style="color: #666666; font-style: italic;">#! /usr/bin/perl</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># pub_entry.cgi (PART #1)</span>
<span style="color: #666666; font-style: italic;"># CGI script to make an entry into publication</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Modules being used</span>
<span style="color: #000000; font-weight: bold;">use</span> DBI<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> CGI<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> CGI<span style="color: #339933;">::</span><span style="color: #006600;">Carp</span> <span style="color: #000066;">qw</span> <span style="color: #009900;">&#40;</span> fatalsToBrowser <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> File<span style="color: #339933;">::</span><span style="color: #006600;">Basename</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Make a CGI object and retrieve information from the form</span>
<span style="color: #0000ff;">$inputform</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> CGI<span style="color: #339933;">;</span>
<span style="color: #000066;">print</span> <span style="color: #0000ff;">$inputform</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">header</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Assign form-values to local variables</span>
<span style="color: #0000ff;">$bibid</span>    <span style="color: #339933;">=</span> <span style="color: #0000ff;">$inputform</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">param</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;bibid&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$title</span>    <span style="color: #339933;">=</span> <span style="color: #0000ff;">$inputform</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">param</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;title&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$authors</span>  <span style="color: #339933;">=</span> <span style="color: #0000ff;">$inputform</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">param</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;authors&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$jname</span>    <span style="color: #339933;">=</span> <span style="color: #0000ff;">$inputform</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">param</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;jname&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$jvolume</span>  <span style="color: #339933;">=</span> <span style="color: #0000ff;">$inputform</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">param</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;jvolume&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$jyear</span>    <span style="color: #339933;">=</span> <span style="color: #0000ff;">$inputform</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">param</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;jyear&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$jpage</span>    <span style="color: #339933;">=</span> <span style="color: #0000ff;">$inputform</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">param</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;jpage&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$abstract</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$inputform</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">param</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;abstract&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$jpdfdoc</span>  <span style="color: #339933;">=</span> <span style="color: #0000ff;">$inputform</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">param</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;jpdfdoc&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$efill</span>    <span style="color: #339933;">=</span> <span style="color: #0000ff;">$inputform</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">param</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;efill&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># If variable 'efill' is empty, then display the form</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$efill</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000066;">print</span> <span style="color: #cc0000; font-style: italic;">&lt;&lt; &quot;EOF&quot;;
&lt;!-- www.w3c.org standard --&gt;
&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;&gt;
&nbsp;
&lt;!-- HTML begins --&gt;
&lt;html&gt;
&nbsp;
&lt;!-- HEAD section --&gt;
&lt;head&gt;
&nbsp;
&lt;!-- TITLE section --&gt;
&lt;title&gt;
Your Research Group, Your Academic Institution
&lt;/title&gt;
&nbsp;
&lt;/head&gt;
&nbsp;
&lt;!-- BODY section --&gt;
&lt;body&gt;
&nbsp;
&lt;!-- Group Header --&gt;
&lt;h1&gt;YOUR GROUP NAME&lt;/h1&gt;
&nbsp;
&lt;h2&gt;Publications :: Database Management :: Entry&lt;/h2&gt;
&nbsp;
&lt;!-- Database Entry Form --&gt;
&lt;form method=&quot;POST&quot; action=&quot;./pub_entry.cgi&quot; enctype=&quot;multipart/form-data&quot;&gt;
&lt;table border=&quot;0&quot; cellpadding=&quot;5&quot; cellspacing=&quot;3&quot; align=&quot;left&quot;&gt;
&nbsp;
&lt;tr&gt;
&lt;td valign=&quot;top&quot;&gt;&lt;b&gt;BibID&lt;/b&gt;&lt;/td&gt;
&nbsp;
&lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;bibid&quot; size=&quot;15&quot;&gt;&lt;/td&gt;
&lt;/tr&gt;
&nbsp;
&lt;tr&gt;
&lt;td valign=&quot;top&quot;&gt;&lt;b&gt;Title&lt;/b&gt;&lt;/td&gt;
&lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;title&quot; size=&quot;35&quot;&gt;&amp;nbsp;&lt;/td&gt;
&lt;/tr&gt;
&nbsp;
&lt;tr&gt;
&lt;td valign=&quot;top&quot;&gt;&lt;b&gt;Authors&lt;/b&gt;&lt;/td&gt;
&lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;authors&quot; size=&quot;35&quot;&gt;&lt;/td&gt;
&lt;/tr&gt;
&nbsp;
&lt;tr&gt;
&lt;td valign=&quot;top&quot;&gt;&lt;b&gt;Journal :: Name&lt;/b&gt;&lt;/td&gt;
&lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;jname&quot; size=&quot;35&quot;&gt;&lt;/td&gt;
&lt;/tr&gt;
&nbsp;
&lt;tr&gt;
&lt;td valign=&quot;top&quot;&gt;&lt;b&gt;Journal :: Volume&lt;/b&gt;&lt;/td&gt;
&lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;jvolume&quot; size=&quot;15&quot;&gt;&lt;/td&gt;
&lt;/tr&gt;
&nbsp;
&lt;tr&gt;
&lt;td valign=&quot;top&quot;&gt;&lt;b&gt;Journal :: Year&lt;/b&gt;&lt;/td&gt;
&lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;jyear&quot; size=&quot;15&quot;&gt;&lt;/td&gt;
&lt;/tr&gt;
&nbsp;
&lt;tr&gt;
&lt;td valign=&quot;top&quot;&gt;&lt;b&gt;Journal :: Starting Page&lt;/b&gt; &amp;nbsp; &lt;/td&gt;
&lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;jpage&quot; size=&quot;15&quot;&gt;&lt;/td&gt;
&lt;/tr&gt;
&nbsp;
&lt;tr&gt;
&lt;td valign=&quot;top&quot;&gt;&lt;b&gt;Journal :: Abstract&lt;/b&gt;&lt;/td&gt;
&lt;td&gt;
&lt;textarea name=&quot;abstract&quot; rows=&quot;5&quot; cols=&quot;40&quot;&gt;&lt;/textarea&gt;
&lt;/td&gt;
&lt;/tr&gt;
&nbsp;
&lt;tr&gt;
&lt;td valign=&quot;top&quot;&gt;&lt;b&gt;Journal :: PDF Version&lt;/b&gt; &amp;nbsp; &lt;/td&gt;
&lt;td&gt;&lt;input type=&quot;file&quot; name=&quot;jpdfdoc&quot; size=&quot;15&quot;&gt;&lt;/td&gt;
&lt;/tr&gt;
&nbsp;
&lt;tr&gt;
&lt;td colspan=&quot;6&quot;&gt;
  &lt;input type=&quot;hidden&quot; name=&quot;efill&quot; value=&quot;filled&quot; size=&quot;15&quot;&gt;
  &lt;input type=&quot;submit&quot; value=&quot;Make An Entry&quot;&gt;
  &lt;input type=&quot;reset&quot;  value=&quot;Clear Values&quot;&gt;
&lt;/td&gt;
&lt;/tr&gt;
&nbsp;
&lt;/table&gt;
&lt;/form&gt;
&nbsp;
&lt;br clear=&quot;all&quot;&gt;
&lt;hr&gt;
&nbsp;
&lt;!-- Body ends --&gt;
&lt;/body&gt;
&nbsp;
&lt;!-- HTML ends --&gt;
&lt;/html&gt;
&nbsp;
EOF</span>
<span style="color: #000066;">exit</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The details regarding <a href="http://sgowtham.net/blog/2008/07/24/file-uploads-via-perl-and-cgi/" target="_blank">uploading a document via PERL &amp; CGI</a> are contained in one of my previous posts. Code for entering the above information into the database follows below:</p>

<div class="wp_syntax"><div class="code"><pre class="perl"><span style="color: #666666; font-style: italic;"># pub_entry.cgi (PART #2)</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># If variable 'efill' is not empty, then insert the data</span>
<span style="color: #666666; font-style: italic;"># into the database</span>
<span style="color: #000066;">print</span> <span style="color: #cc0000; font-style: italic;">&lt;&lt; &quot;EOF&quot;;
&lt;!-- www.w3c.org standard --&gt;
&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;&gt;
&nbsp;
&lt;!-- HTML begins --&gt;
&lt;html&gt;
&nbsp;
&lt;!-- HEAD section --&gt;
&lt;head&gt;
&nbsp;
&lt;!-- TITLE section --&gt;
&lt;title&gt;
Your Research Group, Your Academic Institution
&lt;/title&gt;
&nbsp;
&lt;/head&gt;
&nbsp;
&lt;!-- BODY section --&gt;
&lt;body&gt;
&nbsp;
&lt;!-- Group Header --&gt;
&lt;h1&gt;YOUR GROUP NAME&lt;/h1&gt;
&nbsp;
&lt;h2&gt;Publications :: Database Management :: Entry&lt;/h2&gt;
&lt;hr&gt;
EOF</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Connect to the database and perform the SQL query</span>
<span style="color: #0000ff;">$db</span>    <span style="color: #339933;">=</span> DBI<span style="color: #339933;">-&gt;</span><span style="color: #006600;">connect</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'dbi:mysql:einstein_research:localhost'</span><span style="color: #339933;">,</span><span style="color: #ff0000;">'einstein_web'</span><span style="color: #339933;">,</span><span style="color: #ff0000;">'PASSWORD'</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">or</span> <span style="color: #000066;">die</span> <span style="color: #ff0000;">&quot;Error&quot;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$sql1</span>  <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;INSERT INTO publications VALUES ('', '$bibid', '$title', &quot;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$sql2</span>  <span style="color: #339933;">=</span> <span style="color: #0000ff;">$sql1</span> . <span style="color: #ff0000;">&quot;'$authors', '$jname', '$jvolume', '$jyear', '$jpage', &quot;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$sql</span>   <span style="color: #339933;">=</span> <span style="color: #0000ff;">$sql2</span> . <span style="color: #ff0000;">&quot;'$abstract')&quot;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">prepare</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">execute</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># PDF upload part</span>
<span style="color: #666666; font-style: italic;"># 5MB limit on the size of the document</span>
<span style="color: #0000ff;">$CGI</span><span style="color: #339933;">::</span><span style="color: #006600;">POST_MAX</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1024</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">1024</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Characters that are allowed to be part of the filename</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$safe_characters</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;a-zA-Z0-9_.-&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Update location</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$upload_location</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;/var/www/html/pdf&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$filename</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$inputform</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">param</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;jpdfdoc&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><span style="color: #0000ff;">$filename</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
 <span style="color: #000066;">print</span> <span style="color: #0000ff;">$inputform</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">header</span> <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #000066;">print</span> <span style="color: #cc0000; font-style: italic;">&lt;&lt; &quot;EOF&quot;;
 &lt;p align=&quot;justify&quot;&gt;
 There was a problem uploading the PDF
 &lt;/p&gt;
EOF</span>
 <span style="color: #000066;">exit</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Clean up the filename - remove any 'path' and split the filename into</span>
<span style="color: #666666; font-style: italic;"># basename and extension</span>
<span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$name</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$path</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$extension</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> fileparse <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$filename</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'\..*'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$filename</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$name</span> . <span style="color: #0000ff;">$extension</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Replace blank space in filename with 'underscore'</span>
<span style="color: #0000ff;">$filename</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">tr/ /_/</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Remove any 'not safe' characters</span>
<span style="color: #0000ff;">$filename</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">s/[^$safe_characters]//g</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Untaint the filename</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$filename</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">/^([$safe_characters]+)$/</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
 <span style="color: #0000ff;">$filename</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$1</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
 <span style="color: #000066;">die</span> <span style="color: #ff0000;">&quot;Filename contains invalid characters&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$upload_filehandle</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$inputform</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">upload</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;jpdfdoc&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066;">open</span> <span style="color: #009900;">&#40;</span> UPLOADFILE<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;&gt;$upload_location/$filename&quot;</span> <span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">or</span> <span style="color: #000066;">die</span> <span style="color: #ff0000;">&quot;$!&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">binmode</span> UPLOADFILE<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">&lt;</span><span style="color: #0000ff;">$upload_filehandle</span><span style="color: #339933;">&gt;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
 <span style="color: #000066;">print</span> UPLOADFILE<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000066;">close</span> UPLOADFILE<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066;">print</span> <span style="color: #cc0000; font-style: italic;">&lt;&lt; &quot;EOF&quot;;
&lt;p align=&quot;justify&quot;&gt;
Data was successfully entered into the database. Click
&lt;a href=&quot;./pub_entry.cgi&quot;&gt;here&lt;/a&gt; to make another entry.
&lt;/p&gt;
&nbsp;
&lt;!-- Body ends --&gt;
&lt;/body&gt;
&nbsp;
&lt;!-- HTML ends --&gt;
&lt;/html&gt;
EOF</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Close Database Connection</span>
<span style="color: #0000ff;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">disconnect</span><span style="color: #339933;">;</span></pre></div></div>

<p><br clear="all"></p>
<h3 class="blog">#4. Admin Side: <strong>pub_update.cgi</strong> and <strong>pub_updated.cgi</strong></h3>
<p>Often times, it becomes necessary to update an entry (author names, citation, abstract, etc.) and to do so, the appropriate entry must be retrieved from the database. Code for <strong>pub_update.cgi</strong> follows:</p>

<div class="wp_syntax"><div class="code"><pre class="perl"><span style="color: #666666; font-style: italic;">#! /usr/bin/perl</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># pub_update.cgi</span>
<span style="color: #666666; font-style: italic;"># CGI script to retrieve a publication from the database</span>
<span style="color: #666666; font-style: italic;"># for update</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Modules being used</span>
<span style="color: #000000; font-weight: bold;">use</span> DBI<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> CGI<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Make a CGI object and retrieve information from the form</span>
<span style="color: #0000ff;">$inputform</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> CGI<span style="color: #339933;">;</span>
<span style="color: #000066;">print</span> <span style="color: #0000ff;">$inputform</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">header</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Assign form-values to local variables</span>
<span style="color: #0000ff;">$bibid</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$inputform</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">param</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;bibid&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$rfill</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$inputform</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">param</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;rfill&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># If variable 'rfill' is empty, then display the form</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$rfill</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000066;">print</span> <span style="color: #cc0000; font-style: italic;">&lt;&lt; &quot;EOF&quot;;
&lt;!-- www.w3c.org standard --&gt;
&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;&gt;
&nbsp;
&lt;!-- HTML begins --&gt;
&lt;html&gt;
&nbsp;
&lt;!-- HEAD section --&gt;
&lt;head&gt;
&nbsp;
&lt;!-- TITLE section --&gt;
&lt;title&gt;
Your Research Group, Your Academic Institution
&lt;/title&gt;
&nbsp;
&lt;/head&gt;
&nbsp;
&lt;!-- BODY section --&gt;
&lt;body&gt;
&nbsp;
&lt;!-- Group Header --&gt;
&lt;h1&gt;YOUR GROUP NAME&lt;/h1&gt;
&nbsp;
&lt;h2&gt;Publications :: Database Management :: Retrieve&lt;/h2&gt;
&lt;hr&gt;
&nbsp;
&lt;!-- Retrieval For Update Form --&gt;
&lt;form method=&quot;POST&quot; action=&quot;./dbretrieve.cgi&quot;&gt;
&lt;table border=&quot;0&quot; cellpadding=&quot;5&quot; cellspacing=&quot;3&quot; align=&quot;left&quot;&gt;
&nbsp;
&lt;tr&gt;
&lt;td valign=&quot;top&quot;&gt;&lt;b&gt;BibID&lt;/b&gt;&lt;/td&gt;
&lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;bibid&quot; size=&quot;15&quot;&gt;&lt;/td&gt;
&lt;/tr&gt;
&nbsp;
&lt;tr&gt;
&lt;td colspan=&quot;6&quot;&gt;
  &lt;input type=&quot;hidden&quot; name=&quot;rfill&quot; value=&quot;filled&quot; size=&quot;15&quot;&gt;
  &lt;input type=&quot;submit&quot; value=&quot;Retrieve An Entry&quot;&gt;
  &lt;input type=&quot;reset&quot;  value=&quot;Clear&quot;&gt;
&lt;/td&gt;
&lt;/tr&gt;
&nbsp;
&lt;/table&gt;
&lt;/form&gt;
&nbsp;
&lt;br clear=&quot;all&quot;&gt;
&lt;hr&gt;
&nbsp;
&lt;!-- Body ends --&gt;
&lt;/body&gt;
&nbsp;
&lt;!-- HTML ends --&gt;
&lt;/html&gt;
EOF</span>
<span style="color: #000066;">exit</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;"># If variable 'rfill' is not empty, retrieve data from the database</span>
<span style="color: #000066;">print</span> <span style="color: #cc0000; font-style: italic;">&lt;&lt; &quot;EOF&quot;;
&lt;!-- www.w3c.org standard --&gt;
&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;&gt;
&nbsp;
&lt;!-- HTML begins --&gt;
&lt;html&gt;
&nbsp;
&lt;!-- HEAD section --&gt;
&lt;head&gt;
&nbsp;
&lt;!-- TITLE section --&gt;
&lt;title&gt;
Your Research Group, Your Academic Institution
&lt;/title&gt;
&nbsp;
&lt;/head&gt;
&nbsp;
&lt;!-- BODY section --&gt;
&lt;body&gt;
&nbsp;
&lt;!-- Group Header --&gt;
&lt;h1&gt;YOUR GROUP NAME&lt;/h1&gt;
&nbsp;
&lt;h2&gt;Publications :: Database Management :: Retrieve&lt;/h2&gt;
&lt;hr&gt;
EOF</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Connect to the database and perform the SQL query</span>
<span style="color: #0000ff;">$db</span>    <span style="color: #339933;">=</span> DBI<span style="color: #339933;">-&gt;</span><span style="color: #006600;">connect</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'dbi:mysql:einstein_research:localhost'</span><span style="color: #339933;">,</span><span style="color: #ff0000;">'einstein_web'</span><span style="color: #339933;">,</span><span style="color: #ff0000;">'PASSWORD'</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">or</span> <span style="color: #000066;">die</span> <span style="color: #ff0000;">&quot;Error&quot;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$sql</span>   <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;SELECT * FROM publications WHERE BibID='$bibid' LIMIT 1&quot;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">prepare</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$sql</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">or</span> <span style="color: #000066;">die</span> <span style="color: #ff0000;">&quot;Error&quot;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">execute</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$PubID</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$BibID</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$Title</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$Authors</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$JName</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$JVolume</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$JYear</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$JPage</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$Abstract</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">=</span><span style="color: #0000ff;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">fetchrow</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000066;">print</span> <span style="color: #cc0000; font-style: italic;">&lt;&lt; &quot;EOF&quot;;
&nbsp;
&lt;!-- Database Entry Form --&gt;
&lt;form method=&quot;POST&quot; action=&quot;./pub_updated.cgi&quot;&gt;
&lt;table border=&quot;0&quot; cellpadding=&quot;5&quot; cellspacing=&quot;3&quot; align=&quot;left&quot;&gt;
&nbsp;
&lt;tr&gt;
&lt;td valign=&quot;top&quot; width=&quot;25%&quot;&gt;&lt;b&gt;BibID&lt;/b&gt;&lt;/td&gt;
&lt;td&gt;$BibID&lt;/td&gt;
&lt;/tr&gt;
&nbsp;
&lt;tr&gt;
&lt;td valign=&quot;top&quot;&gt;&lt;b&gt;Title&lt;/b&gt;&lt;/td&gt;
&lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;title&quot; size=&quot;35&quot; value='$Title'&gt;&amp;nbsp;&lt;/td&gt;
&lt;/tr&gt;
&nbsp;
&lt;tr&gt;
&lt;td valign=&quot;top&quot;&gt;&lt;b&gt;Authors&lt;/b&gt;&lt;/td&gt;
&lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;authors&quot; size=&quot;35&quot; value='$Authors'&gt;&lt;/td&gt;
&lt;/tr&gt;
&nbsp;
&lt;tr&gt;
&lt;td valign=&quot;top&quot;&gt;&lt;b&gt;Journal :: Name&lt;/b&gt;&lt;/td&gt;
&lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;jname&quot; size=&quot;35&quot; value='$JName'&gt;&lt;/td&gt;
&lt;/tr&gt;
&nbsp;
&lt;tr&gt;
&lt;td valign=&quot;top&quot;&gt;&lt;b&gt;Journal :: Volume&lt;/b&gt;&lt;/td&gt;
&lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;jvolume&quot; size=&quot;15&quot; value='$JVolume'&gt;&lt;/td&gt;
&lt;/tr&gt;
&nbsp;
&lt;tr&gt;
&lt;td valign=&quot;top&quot;&gt;&lt;b&gt;Journal :: Year&lt;/b&gt;&lt;/td&gt;
&lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;jyear&quot; size=&quot;15&quot; value='$JYear'&gt;&lt;/td&gt;
&lt;/tr&gt;
&nbsp;
&lt;tr&gt;
&lt;td valign=&quot;top&quot;&gt;&lt;b&gt;Journal :: Starting Page&lt;/b&gt; &amp;nbsp; &lt;/td&gt;
&lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;jpage&quot; size=&quot;15&quot; value='$JPage'&gt;&lt;/td&gt;
&lt;/tr&gt;
&nbsp;
&lt;tr&gt;
&lt;td valign=&quot;top&quot;&gt;&lt;b&gt;Journal :: Abstract&lt;/b&gt;&lt;/td&gt;
&lt;td&gt;
&lt;blockquote&gt;
$Abstract
&lt;/blockquote&gt;
&lt;textarea name=&quot;abstract&quot; rows=&quot;5&quot; cols=&quot;40&quot; value='$Abstract'&gt;
Type in new abstract OR copy the existing one from above&lt;/textarea&gt;
&lt;/td&gt;
&lt;/tr&gt;
&nbsp;
&lt;tr&gt;
&lt;td colspan=&quot;6&quot;&gt;
  &lt;input type=&quot;hidden&quot; name=&quot;bibid&quot; value='$bibid'&gt;
  &lt;input type=&quot;hidden&quot; name=&quot;rfill&quot; value=&quot;filled&quot; size=&quot;15&quot;&gt;
  &lt;input type=&quot;submit&quot; value=&quot;Update An Entry&quot;&gt;
  &lt;input type=&quot;reset&quot;  value=&quot;Clear Values&quot;&gt;
&lt;/td&gt;
&lt;/tr&gt;
&nbsp;
&lt;/table&gt;
&lt;/form&gt;
EOF</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000066;">print</span> <span style="color: #cc0000; font-style: italic;">&lt;&lt; &quot;EOF&quot;;
&lt;!-- Body ends --&gt;
&lt;/body&gt;
&nbsp;
&lt;!-- HTML ends --&gt;
&lt;/html&gt;
EOF</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Close Database Connection</span>
<span style="color: #0000ff;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">disconnect</span><span style="color: #339933;">;</span></pre></div></div>

<p><strong>pub_update.cgi</strong> takes all the information and passes it over to <strong>pub_updated.cgi</strong>, which updates the record. Code for <strong>pub_updated.cgi</strong> follows below:</p>

<div class="wp_syntax"><div class="code"><pre class="perl"><span style="color: #666666; font-style: italic;">#! /usr/bin/perl</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># pub_updated.cgi</span>
<span style="color: #666666; font-style: italic;"># CGI script to update an entry in the database</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Modules being used</span>
<span style="color: #000000; font-weight: bold;">use</span> DBI<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> CGI<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Make a CGI object and retrieve information from the form</span>
<span style="color: #0000ff;">$inputform</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> CGI<span style="color: #339933;">;</span>
<span style="color: #000066;">print</span> <span style="color: #0000ff;">$inputform</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">header</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Assign form-values to local variables</span>
<span style="color: #0000ff;">$bibid</span>    <span style="color: #339933;">=</span> <span style="color: #0000ff;">$inputform</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">param</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;bibid&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$title</span>    <span style="color: #339933;">=</span> <span style="color: #0000ff;">$inputform</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">param</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;title&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$authors</span>  <span style="color: #339933;">=</span> <span style="color: #0000ff;">$inputform</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">param</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;authors&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$jname</span>    <span style="color: #339933;">=</span> <span style="color: #0000ff;">$inputform</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">param</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;jname&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$jvolume</span>  <span style="color: #339933;">=</span> <span style="color: #0000ff;">$inputform</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">param</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;jvolume&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$jyear</span>    <span style="color: #339933;">=</span> <span style="color: #0000ff;">$inputform</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">param</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;jyear&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$jpage</span>    <span style="color: #339933;">=</span> <span style="color: #0000ff;">$inputform</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">param</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;jpage&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$abstract</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$inputform</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">param</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;abstract&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066;">print</span> <span style="color: #cc0000; font-style: italic;">&lt;&lt; &quot;EOF&quot;;
&lt;!-- www.w3c.org standard --&gt;
&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;&gt;
&nbsp;
&lt;!-- HTML begins --&gt;
&lt;html&gt;
&nbsp;
&lt;!-- HEAD section --&gt;
&lt;head&gt;
&nbsp;
&lt;!-- TITLE section --&gt;
&lt;title&gt;
Your Research Group, Your Academic Institution
&lt;/title&gt;
&nbsp;
&lt;/head&gt;
&nbsp;
&lt;!-- BODY section --&gt;
&lt;body&gt;
&nbsp;
&lt;!-- Group Header --&gt;
&lt;h1&gt;YOUR GROUP NAME&lt;/h1&gt;
&nbsp;
&lt;h2&gt;Publications :: Database Management :: Retrieve&lt;/h2&gt;
&lt;hr&gt;
EOF</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Connect to the database and perform the SQL query</span>
<span style="color: #0000ff;">$db</span>    <span style="color: #339933;">=</span> DBI<span style="color: #339933;">-&gt;</span><span style="color: #006600;">connect</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'dbi:mysql:einstein_research:localhost'</span><span style="color: #339933;">,</span><span style="color: #ff0000;">'einstein_web'</span><span style="color: #339933;">,</span><span style="color: #ff0000;">'PASSWORD'</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">or</span> <span style="color: #000066;">die</span> <span style="color: #ff0000;">&quot;Error&quot;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$sql1</span>  <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;UPDATE publications SET Title='$title',Authors='$authors',&quot;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$sql2</span>  <span style="color: #339933;">=</span> <span style="color: #0000ff;">$sql1</span> . <span style="color: #ff0000;">&quot;JName='$jname',JVolume='$jvolume',JYear='$jyear',&quot;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$sql</span>   <span style="color: #339933;">=</span> <span style="color: #0000ff;">$sql2</span> . <span style="color: #ff0000;">&quot;JPage='$jpage',Abstract='$abstract' WHERE BibID='$bibid' &quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #0000ff;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">prepare</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">execute</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066;">print</span> <span style="color: #cc0000; font-style: italic;">&lt;&lt; &quot;EOF&quot;;
&lt;p align=&quot;justify&quot;&gt;
Data was successfully updated in the database. Click
&lt;a href=&quot;./pub_update.cgi&quot;&gt;here&lt;/a&gt; to update another entry.
&lt;/p&gt;
&nbsp;
&lt;!-- Body ends --&gt;
&lt;/body&gt;
&nbsp;
&lt;!-- HTML ends --&gt;
&lt;/html&gt;
EOF</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Close Database Connection</span>
<span style="color: #0000ff;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">disconnect</span><span style="color: #339933;">;</span></pre></div></div>

<p><br clear="all"></p>
<h3 class="blog">#5. Admin Side: <strong>pub_delete.cgi</strong></h3>
<p>Seldom it becomes necessary to delete an entry from the database (a reference article entered in by mistake as a publication, etc.) and the code for <strong>pub_delete.cgi</strong> follows:</p>

<div class="wp_syntax"><div class="code"><pre class="perl"><span style="color: #666666; font-style: italic;">#! /usr/bin/perl</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># pub_delete.cgi</span>
<span style="color: #666666; font-style: italic;"># CGI script to delete an entry from the database</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Modules being used</span>
<span style="color: #000000; font-weight: bold;">use</span> DBI<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> CGI<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Make a CGI object and retrieve information from the form</span>
<span style="color: #0000ff;">$inputform</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> CGI<span style="color: #339933;">;</span>
<span style="color: #000066;">print</span> <span style="color: #0000ff;">$inputform</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">header</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Assign form-values to local variables</span>
<span style="color: #0000ff;">$bibid</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$inputform</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">param</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;bibid&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$dfill</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$inputform</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">param</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;dfill&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># If variable 'dfill' is empty, then display the form</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$dfill</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000066;">print</span> <span style="color: #cc0000; font-style: italic;">&lt;&lt; &quot;EOF&quot;;
&lt;!-- www.w3c.org standard --&gt;
&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;&gt;
&nbsp;
&lt;!-- HTML begins --&gt;
&lt;html&gt;
&nbsp;
&lt;!-- HEAD section --&gt;
&lt;head&gt;
&nbsp;
&lt;!-- TITLE section --&gt;
&lt;title&gt;
Your Research Group, Your Academic Institution
&lt;/title&gt;
&nbsp;
&lt;/head&gt;
&nbsp;
&lt;!-- BODY section --&gt;
&lt;body&gt;
&nbsp;
&lt;!-- Group Header --&gt;
&lt;h1&gt;YOUR GROUP NAME&lt;/h1&gt;
&nbsp;
&lt;h2&gt;Publications :: Database Management :: Delete&lt;/h2&gt;
&lt;hr&gt;
&nbsp;
&lt;!-- Database Deletion Form --&gt;
&lt;form method=&quot;POST&quot; action=&quot;./pub_delete.cgi&quot;&gt;
&lt;table border=&quot;0&quot; cellpadding=&quot;5&quot; cellspacing=&quot;3&quot; align=&quot;left&quot;&gt;
&nbsp;
&lt;tr&gt;
&lt;td valign=&quot;top&quot;&gt;&lt;b&gt;BibID&lt;/b&gt;&lt;/td&gt;
&lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;bibid&quot; size=&quot;15&quot;&gt;&lt;/td&gt;
&lt;/tr&gt;
&nbsp;
&lt;tr&gt;
&lt;td colspan=&quot;6&quot;&gt;
  &lt;input type=&quot;hidden&quot; name=&quot;dfill&quot; value=&quot;filled&quot; size=&quot;15&quot;&gt;
  &lt;input type=&quot;submit&quot; value=&quot;Delete An Entry&quot;&gt;
  &lt;input type=&quot;reset&quot;  value=&quot;Clear&quot;&gt;
&lt;/td&gt;
&lt;/tr&gt;
&nbsp;
&lt;/table&gt;
&lt;/form&gt;
&nbsp;
&lt;br clear=&quot;all&quot;&gt;
&lt;hr&gt;
&nbsp;
&lt;!-- Body ends --&gt;
&lt;/body&gt;
&nbsp;
&lt;!-- HTML ends --&gt;
&lt;/html&gt;
EOF</span>
<span style="color: #000066;">exit</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># If variable 'dfill' is not empty, then delete an entry</span>
<span style="color: #666666; font-style: italic;"># from the database</span>
<span style="color: #000066;">print</span> <span style="color: #cc0000; font-style: italic;">&lt;&lt; &quot;EOF&quot;;
&lt;!-- www.w3c.org standard --&gt;
&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;&gt;
&nbsp;
&nbsp;
&nbsp;
&lt;!-- HTML begins --&gt;
&lt;html&gt;
&nbsp;
&lt;!-- HEAD section --&gt;
&lt;head&gt;
&nbsp;
&lt;!-- TITLE section --&gt;
&lt;title&gt;
Your Research Group, Your Academic Institution
&lt;/title&gt;
&nbsp;
&lt;/head&gt;
&nbsp;
&lt;!-- BODY section --&gt;
&lt;body&gt;
&nbsp;
&lt;!-- Group Header --&gt;
&lt;h1&gt;YOUR GROUP NAME&lt;/h1&gt;
&nbsp;
&lt;h2&gt;Publications :: Database Management :: Delete&lt;/h2&gt;
&lt;hr&gt;
EOF</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Connect to the database and perform the SQL query</span>
<span style="color: #0000ff;">$db</span>    <span style="color: #339933;">=</span> DBI<span style="color: #339933;">-&gt;</span><span style="color: #006600;">connect</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'dbi:mysql:einstein_research:localhost'</span><span style="color: #339933;">,</span><span style="color: #ff0000;">'einstein_web'</span><span style="color: #339933;">,</span><span style="color: #ff0000;">'PASSWORD'</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">or</span> <span style="color: #000066;">die</span> <span style="color: #ff0000;">&quot;Error&quot;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$sql</span>   <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;DELETE FROM publications WHERE BibID='$bibid' LIMIT 1&quot;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">prepare</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$sql</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">or</span> <span style="color: #000066;">die</span> <span style="color: #ff0000;">&quot;Error&quot;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">execute</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066;">print</span> <span style="color: #cc0000; font-style: italic;">&lt;&lt; &quot;EOF&quot;;
&lt;p align=&quot;justify&quot;&gt;
Entry was successfully deleted from the database. Click
&lt;a href=&quot;./pub_delete.cgi&quot;&gt;here&lt;/a&gt; to delete another entry.
&lt;/p&gt;
&nbsp;
&lt;!-- Body ends --&gt;
&lt;/body&gt;
&nbsp;
&lt;!-- HTML ends --&gt;
&lt;/html&gt;
EOF</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Close Database Connection</span>
<span style="color: #0000ff;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">disconnect</span><span style="color: #339933;">;</span></pre></div></div>

<p><br clear="all"></p>
<h3 class="blog">#6. Admin Side: Restricting Access To Admin Interface</h3>
<p>There are some ways of achieving this - to prevent unauthorized personnel from messing with databases and files. </p>
<ol>
<li>Password protect the admin folder - allow only a certain user from any machine</li>
<li>IP address/Hostname based restriction - allow any user (preferably a group member) to access the admin interface from certain machine(s).</li>
<li>Combination of #1 &amp; #2 - allow only certain users from certain machines.</li>
</ol>
<p>A simple Google!ing for <strong>password protection .htaccess .htpasswd</strong> should result in a good number of decent documents. But do check/discuss your approach with your systems administrator(s) - to make sure that it can be applied, is feasible and less mis-usable under existing circumstances.</p>
<p><br clear="all"></p>
<h3 class="blog">Screenshots</h3>
<p>The screenshots below were generated after incorporating the style sheets (<a href="http://en.wikipedia.org/wiki/Cascading_Style_Sheets" target="_blank">CSS</a>) that are in-line with Michigan Tech theme. The code in the above sections, however, results in very plain, bare-bone HTML pages.  With a basic, working knowledge of CSS, it should not be too difficult to spice up the appearance:</p>
<p><br clear="all"><br />
<img class="framed" src="http://sgowtham.net/blog/images/20080725/publication_0.png" alt="Storing And Querying Information with PERL-MySQL" title="Storing And Querying Information with PERL-MySQL" border="0"></p>
<p class="bpcaption">Publications - Default View</p>
<p><br clear="all"><br />
<img class="framed" src="http://sgowtham.net/blog/images/20080725/publication_1.png" alt="Storing And Querying Information with PERL-MySQL" title="Storing And Querying Information with PERL-MySQL" border="0"></p>
<p class="bpcaption">Publications - When a query is performed</p>
<p><br clear="all"><br />
<img class="framed" src="http://sgowtham.net/blog/images/20080725/pub_entry.png" alt="Storing And Querying Information with PERL-MySQL" title="Storing And Querying Information with PERL-MySQL" border="0"></p>
<p class="bpcaption">Making a new entry</p>
<p><br clear="all"><br />
<img class="framed" src="http://sgowtham.net/blog/images/20080725/pub_delete.png" alt="Storing And Querying Information with PERL-MySQL" title="Storing And Querying Information with PERL-MySQL" border="0"></p>
<p class="bpcaption">Deleting an entry</p>
<p><br clear="all"><br />
<img class="framed" src="http://sgowtham.net/blog/images/20080725/pub_update_0.png" alt="Storing And Querying Information with PERL-MySQL" title="Storing And Querying Information with PERL-MySQL" border="0"></p>
<p class="bpcaption">Retrieval for update</p>
<p><br clear="all"><br />
<img class="framed" src="http://sgowtham.net/blog/images/20080725/pub_update_1.png" alt="Storing And Querying Information with PERL-MySQL" title="Storing And Querying Information with PERL-MySQL" border="0" align="center"></p>
<p class="bpcaption">Updating an entry</p>
<p><br clear="all"></p>
<h3 class="blog">Demonstration</h3>
<p>Live demo of this code, only the <strong>publications.cgi</strong>, is <a href="http://www.phy.mtu.edu/pandey/publications.cgi" target="_blank">here</a>. Others, as can be expected, are hidden in a secure folder.</p>
<p><br clear="all"></p>
<h3 class="blog">Disclaimer</h3>
<p>The aforementioned instructions/steps worked for me and it may very well work for you on Sun OS / linux distributions. Please note that if you decide to use these instructions on your machine (either for this particular application and/or for other kind of information), you are doing so entirely at your very own discretion and that neither this site, <a href="http://sgowtham.net/" target="_blank">sgowtham.net</a>, nor its author is responsible for any/all damage - intellectual or otherwise.</p>
]]></content:encoded>
			<wfw:commentRss>http://sgowtham.net/blog/2008/07/25/storing-and-querying-information-with-perl-mysql/feed/</wfw:commentRss>
		</item>
		<item>
		<title>File Uploads Via PERL And CGI</title>
		<link>http://sgowtham.net/blog/2008/07/24/file-uploads-via-perl-and-cgi/</link>
		<comments>http://sgowtham.net/blog/2008/07/24/file-uploads-via-perl-and-cgi/#comments</comments>
		<pubDate>Thu, 24 Jul 2008 20:18:36 +0000</pubDate>
		<dc:creator>Gowtham</dc:creator>
		
		<category><![CDATA[Computers]]></category>

		<category><![CDATA[Linux]]></category>

		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://sgowtham.net/blog/?p=399</guid>
		<description><![CDATA[A while ago, I wrote about uploading files to a web server via PHP and this post follows along similar lines - only accomplishing the same task using PERL. There are numerous articles on the web and in the books, but what follows here is what worked for me - it is expected to serve [...]]]></description>
			<content:encoded><![CDATA[<p>A while ago, I wrote about <a href="http://sgowtham.net/blog/2008/06/08/file-upload-via-php/" target="_blank">uploading files to a web server via PHP</a> and this post follows along similar lines - only accomplishing the same task using PERL. There are numerous articles on the web and in the books, but what follows here is what worked for me - it is expected to serve as a Note2Self but if you find it useful, please feel free to do so.</p>
<p><br clear="all"></p>
<h3 class="blog">A Form To Select The File</h3>
<p>Let us suppose that the HTML file that displays this form is called <b>NewFile.html</b> and the PERL file that does the actual uploading work (and some more) is called <b>Uploader.cgi</b>.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict"><span style="color: #00bbdd;">&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;html&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;body&gt;</span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- The data encoding type, enctype, MUST be specified as below --&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;form</span> <span style="color: #000066;">enctype</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;multipart/form-data&quot;</span> <span style="color: #000066;">action</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Uploader.cgi&quot;</span> <span style="color: #000066;">method</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;POST&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;table</span> <span style="color: #000066;">align</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;left&quot;</span> <span style="color: #000066;">cellpadding</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;5&quot;</span> <span style="color: #000066;">cellspacing</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;5&quot;</span> <span style="color: #000066;">border</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">width</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;100%&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tr&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;td</span> <span style="color: #000066;">align</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;left&quot;</span> <span style="color: #000066;">valign</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;top&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        Select A File
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/td&gt;</span></span>
&nbsp;
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;td</span> <span style="color: #000066;">align</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;left&quot;</span> <span style="color: #000066;">valign</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;top&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- uploaded_file is the reference assigned in the form. --&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;input</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;uploaded_file&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;file&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/td&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tr&gt;</span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tr&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;td</span> <span style="color: #000066;">align</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;left&quot;</span> <span style="color: #000066;">valign</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;top&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #ddbb00;">&amp;nbsp;</span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/td&gt;</span></span>
&nbsp;
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;td</span> <span style="color: #000066;">align</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;left&quot;</span> <span style="color: #000066;">valign</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;top&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Upload This File&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/td&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tr&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/table&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/form&gt;</span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/body&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/html&gt;</span></span></pre></div></div>

<p><br clear="all"></p>
<h3 class="blog">Uploader.cgi</h3>
<p>Suppose that the end-user selected a file to upload and hit the <b>Upload This File</b> button. Now, the file, <b>Uploader.cgi</b> takes over and does a few things. The source code, adopted from a <a href="http://www.sitepoint.com/article/uploading-files-cgi-perl" target="_blank">Site Point article</a>, follows:</p>

<div class="wp_syntax"><div class="code"><pre class="perl"><span style="color: #666666; font-style: italic;">#! /usr/bin/perl -wT</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># -w switch to make Perl warn us of any potential dangers in our code.</span>
<span style="color: #666666; font-style: italic;"># -T switch turns on taint checking. This ensures that any untrusted </span>
<span style="color: #666666; font-style: italic;"># input to the script, such as the uploaded file's filename, is marked as tainted.</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">use</span> strict<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> CGI<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> CGI<span style="color: #339933;">::</span><span style="color: #006600;">Carp</span> <span style="color: #000066;">qw</span> <span style="color: #009900;">&#40;</span> fatalsToBrowser <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> File<span style="color: #339933;">::</span><span style="color: #006600;">Basename</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Tto prevent the server being overloaded by huge file uploads, </span>
<span style="color: #666666; font-style: italic;"># the allowable size of an uploaded file can be limited to 2MB.</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># 1024 bytes in 1 kB; 1024 kB in 1 MB (1048576 bytes in 1 MB)</span>
<span style="color: #0000ff;">$CGI</span><span style="color: #339933;">::</span><span style="color: #006600;">POST_MAX</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1024</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">1024</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Some characters, such as slashes (/), are dangerous in filenames, </span>
<span style="color: #666666; font-style: italic;"># as they might allow file uploads to any directory. Alphabets,</span>
<span style="color: #666666; font-style: italic;"># numerics, underscores, hyphens and periods may be considered safe.</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$safe_characters</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;a-zA-Z0-9_.-&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># In Red Hat (like) distribtutions, the DocumentRoot variable in Apache</span>
<span style="color: #666666; font-style: italic;"># is set by default to '/var/www/html'. Suppose that all uploaded files</span>
<span style="color: #666666; font-style: italic;"># will be put into a folder called 'uploads' under DocumentRoot.</span>
<span style="color: #666666; font-style: italic;"># 'uploads' folder must have 777 permission.</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$upload_location</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;/var/www/html/uploads&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># The next step is to create a CGI object (assigned to $query below).</span>
<span style="color: #666666; font-style: italic;"># This allows one to access methods in the CGI.pm library. One can then</span>
<span style="color: #666666; font-style: italic;"># read in the filename of uploaded file.</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$query</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> CGI<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># If there was a problem uploading the file -- for example, the </span>
<span style="color: #666666; font-style: italic;"># file was bigger than the $CGI::POST_MAX setting -- $filename </span>
<span style="color: #666666; font-style: italic;"># will be empty. The following bit tests for such problems.</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Value within param() is the same as the reference used in the form</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$filename</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">param</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;uploaded_file&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><span style="color: #0000ff;">$filename</span> <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
 <span style="color: #000066;">print</span> <span style="color: #0000ff;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">header</span> <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;There was a problem uploading the file. May be it is too big?.&quot;</span><span style="color: #339933;">;</span>
 <span style="color: #000066;">exit</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># The first thing to do with filename is use the 'fileparse' routine in</span>
<span style="color: #666666; font-style: italic;"># File::Basename module to split the filename into its leading path </span>
<span style="color: #666666; font-style: italic;"># (if any), the filename itself, and the file extension. One can then </span>
<span style="color: #666666; font-style: italic;"># safely ignore the leading path. Not only does this help prevent </span>
<span style="color: #666666; font-style: italic;"># attempts to save the file anywhere on the web server, but </span>
<span style="color: #666666; font-style: italic;"># some browsers send the whole path to the file on the user's hard drive.</span>
<span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$name</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$path</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$extension</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> fileparse <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$filename</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'\..*'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$filename</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$name</span> . <span style="color: #0000ff;">$extension</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Convert any spaces in the filename to underscores</span>
<span style="color: #0000ff;">$filename</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">tr/ /_/</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Remove any characters that are not in safe character list </span>
<span style="color: #0000ff;">$filename</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">s/[^$safe_characters]//g</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Untaint the $filename variable. </span>
<span style="color: #666666; font-style: italic;"># This variable is tainted because it contains potentially unsafe </span>
<span style="color: #666666; font-style: italic;"># data passed by the browser. The only way to untaint a tainted </span>
<span style="color: #666666; font-style: italic;"># variable is to use regular expression matching to extract the </span>
<span style="color: #666666; font-style: italic;"># safe characters:</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$filename</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">/^([$safe_characters]+)$/</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
 <span style="color: #0000ff;">$filename</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$1</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
 <span style="color: #000066;">die</span> <span style="color: #ff0000;">&quot;Filename contains invalid characters&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># The upload method can be used to grab the file handle of the </span>
<span style="color: #666666; font-style: italic;"># uploaded file (which  points to a temporary file created by CGI.pm).</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$upload_filehandle</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">upload</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;uploaded_file&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># One can now read the contents of the handle, its contents can be read</span>
<span style="color: #666666; font-style: italic;"># and saved to a new file under 'uploads' folder. One can retain the</span>
<span style="color: #666666; font-style: italic;"># uploaded file's name as the name of the new file.</span>
<span style="color: #000066;">open</span> <span style="color: #009900;">&#40;</span> UPLOADFILE<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;&gt;$upload_location/$filename&quot;</span> <span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">or</span> <span style="color: #000066;">die</span> <span style="color: #ff0000;">&quot;$!&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">binmode</span> UPLOADFILE<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">&lt;</span><span style="color: #0000ff;">$upload_filehandle</span><span style="color: #339933;">&gt;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
 <span style="color: #000066;">print</span> UPLOADFILE<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000066;">close</span> UPLOADFILE<span style="color: #339933;">;</span></pre></div></div>

<p><br clear="all"></p>
<h3 class="blog">Specific MIME Type</h3>
<p>The purpose of this code is to be facilitate uploading journal publications to our <a href="http://www.phy.mtu.edu/pandey/" target="_blank">research group website</a>. Since most journals do provide PDF version of published material and PDF is as platform-independent a document format as one can get, it wouldn&#8217;t make much sense to upload anything but PDF files.</p>
<p><br clear="all"></p>
<h3 class="blog">Disclaimer</h3>
<p>The aforementioned instructions/steps worked for me and it may very well work for you. Please note that if you decide to use these instructions on your machine, you are doing so entirely at your very own discretion and that neither this site, <a href="http://sgowtham.net/" target="_blank">sgowtham.net</a>, nor its author is responsible for any/all damage - intellectual or otherwise.</p>
]]></content:encoded>
			<wfw:commentRss>http://sgowtham.net/blog/2008/07/24/file-uploads-via-perl-and-cgi/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Copyrighting Images With Images Using Adobe Photoshop</title>
		<link>http://sgowtham.net/blog/2008/07/21/copyrighting-images-with-images-using-adobe-photoshop/</link>
		<comments>http://sgowtham.net/blog/2008/07/21/copyrighting-images-with-images-using-adobe-photoshop/#comments</comments>
		<pubDate>Mon, 21 Jul 2008 22:00:21 +0000</pubDate>
		<dc:creator>Gowtham</dc:creator>
		
		<category><![CDATA[Graphics]]></category>

		<category><![CDATA[Mac]]></category>

		<category><![CDATA[Photography]]></category>

		<guid isPermaLink="false">http://sgowtham.net/blog/?p=341</guid>
		<description><![CDATA[Most of us take photographs and many of us post them in this vast, nearly infinite internet. Inherent to this process is a desire to put our name on the pictures - either to protect them from plagiarism or to feed our ego or whatever other reason. There are many software and multiple ways to [...]]]></description>
			<content:encoded><![CDATA[<p>Most of us take photographs and many of us post them in this vast, nearly infinite internet. Inherent to this process is a desire to put our name on the pictures - either to protect them from plagiarism or to feed our ego or whatever other reason. There are many software and multiple ways to get this done. Although I don&#8217;t use this method all the frequently, I have tested it on CS2 and CS3 editions of Adobe Photoshop and you might find it useful. In one of my <a href="http://sgowtham.net/blog/2007/10/15/copyrighting-images-with-adobe-photoshop/" target="_blank">previous posts</a>, I had discussed this process and what follows here is a series of steps to use another (smaller) image instead of text to copyright (or just overlay) the main image.</p>
<p><br clear="all"></p>
<h3 class="blog">Disclaimer</h3>
<p>Below given instructions are what I used to copyright my images on my Apple MacBook Pro running OS X v10.5.x and these may very well work for you. However, please note that you are using these instructions at your very own risk and this website, <a href="http://sgowtham.net/" target="_blank">sgowtham.net</a>, is not responsible for any/all damage caused to your property, intellectual or otherwise.</p>
<p><br clear="all"></p>
<h3 class="blog">Get The Images Ready</h3>
<p><font color="#ff0000">Backup the original picture(s)</font>. Using Photoshop (or otherwise), resize your original picture to a reasonable size. 800&#215;600 px is the approximate dimension of my resized picture.</p>
<p><br clear="all"></p>
<h3 class="blog">Start The Process</h3>
<p>Open the resized image in Photoshop and the screen should look something like:</p>
<p><img class="framed" src="http://sgowtham.net/blog/images/20080721/Copyright_00.jpg" alt="Copyrighting Images with Images using Adobe Photoshop" title="Copyrighting Images with Images using Adobe Photoshop" border="0"><br />
<br clear="all"></p>
<p>We could continue this process assuming that there is only one picture to copyright but it is seldom the case. Let us assume that there is a folder full of images that need similar work and since doing all these steps one at a time for each picture can be laborious task, let us take the <b>Photoshop Action</b> approach. To this effect, pick a <strong>New Action</strong> from the <strong>Actions</strong> palette and give it a suitable name:</p>
<p><img class="framed" src="http://sgowtham.net/blog/images/20080721/Copyright_01.jpg" alt="Copyrighting Images with Images using Adobe Photoshop" title="Copyrighting Images with Images using Adobe Photoshop" border="0"><br />
<img class="framed" src="http://sgowtham.net/blog/images/20080721/Copyright_02.jpg" alt="Copyrighting Images with Images using Adobe Photoshop" title="Copyrighting Images with Images using Adobe Photoshop" border="0"><br />
<br clear="all"></p>
<p>Click on <strong>Record</strong> and You should see the Red circular button in the <strong>Actions</strong> palette, indicating the recording is <strong>ON</strong>.</p>
<p><img class="framed" src="http://sgowtham.net/blog/images/20080721/Copyright_03.jpg" alt="Copyrighting Images with Images using Adobe Photoshop" title="Copyrighting Images with Images using Adobe Photoshop" border="0"><br />
<br clear="all"></p>
<p><strong>File &rarr; Open</strong> and select the image which will be used instead of  (or in addition to) the copyright note.</p>
<p><img class="framed" src="http://sgowtham.net/blog/images/20080721/Copyright_04.jpg" alt="Copyrighting Images with Images using Adobe Photoshop" title="Copyrighting Images with Images using Adobe Photoshop" border="0"><br />
<img class="framed" src="http://sgowtham.net/blog/images/20080721/Copyright_05.jpg" alt="Copyrighting Images with Images using Adobe Photoshop" title="Copyrighting Images with Images using Adobe Photoshop" border="0"><br />
<img class="framed" src="http://sgowtham.net/blog/images/20080721/Copyright_06.jpg" alt="Copyrighting Images with Images using Adobe Photoshop" title="Copyrighting Images with Images using Adobe Photoshop" border="0"><br />
<br clear="all"></p>
<p>Click on the small image and press the following key combination: <strong>cmd + A</strong> followed by <strong>cmd + C</strong> (<strong>ctrl + A</strong> followed by <strong>ctrl + C</strong> in Windows).</p>
<p><img class="framed" src="http://sgowtham.net/blog/images/20080721/Copyright_07.jpg" alt="Copyrighting Images with Images using Adobe Photoshop" title="Copyrighting Images with Images using Adobe Photoshop" border="0"><br />
<br clear="all"></p>
<p>Click on the larger image (image to be copyrighted) and press the following key combination: <strong>cmd + V</strong> (<strong>ctrl + V</strong> in Windows).</p>
<p><img class="framed" src="http://sgowtham.net/blog/images/20080721/Copyright_08.jpg" alt="Copyrighting Images with Images using Adobe Photoshop" title="Copyrighting Images with Images using Adobe Photoshop" border="0"><br />
<br clear="all"></p>
<p>Once the smaller image appears as on overlay on top of the larger image, smaller image needs to be properly aligned. To keep track, one may rename the layer that contains smaller image. </p>
<p><img class="framed" src="http://sgowtham.net/blog/images/20080721/Copyright_09.jpg" alt="Copyrighting Images with Images using Adobe Photoshop" title="Copyrighting Images with Images using Adobe Photoshop" border="0"><br />
<img class="framed" src="http://sgowtham.net/blog/images/20080721/Copyright_10.jpg" alt="Copyrighting Images with Images using Adobe Photoshop" title="Copyrighting Images with Images using Adobe Photoshop" border="0"><br />
<img class="framed" src="http://sgowtham.net/blog/images/20080721/Copyright_11.jpg" alt="Copyrighting Images with Images using Adobe Photoshop" title="Copyrighting Images with Images using Adobe Photoshop" border="0"><br />
<img class="framed" src="http://sgowtham.net/blog/images/20080721/Copyright_12.jpg" alt="Copyrighting Images with Images using Adobe Photoshop" title="Copyrighting Images with Images using Adobe Photoshop" border="0"><br />
<img class="framed" src="http://sgowtham.net/blog/images/20080721/Copyright_13.jpg" alt="Copyrighting Images with Images using Adobe Photoshop" title="Copyrighting Images with Images using Adobe Photoshop" border="0"><br />
<br clear="all"></p>
<p>After the last four steps (assuming that you picked <strong>Bottom</strong> &amp; <strong>Right Edges</strong>), the result should look something as follows. As one can note, the overlayed image is too close to the edges. To make it easily readable, select the <strong>Move</strong> tool and nudge the small image layer  - both in upward and left directions - by a few keystrokes using the arrow keys.</p>
<p><img class="framed" src="http://sgowtham.net/blog/images/20080721/Copyright_14.jpg" alt="Copyrighting Images with Images using Adobe Photoshop" title="Copyrighting Images with Images using Adobe Photoshop" border="0"><br />
<br clear="all"></p>
<p>Once that&#8217;s done, press the Blue square button in the <strong>Actions</strong> palette to STOP recording.</p>
<p><img class="framed" src="http://sgowtham.net/blog/images/20080721/Copyright_15.jpg" alt="Copyrighting Images with Images using Adobe Photoshop" title="Copyrighting Images with Images using Adobe Photoshop" border="0"><br />
<br clear="all"></p>
<p>That&#8217;s it. Now this sequence of steps can be called as and when needed and the best part is that it can be used with other built-in features of Photoshop to work on folder full of images. Let us assume the following directory structure:</p>
<p><strong>Pictures/Processing/Originals</strong>: contains a <u>copy</u> of the original, resized images.<br />
<strong>Pictures/Processing/Copyrighted</strong>: will contain copyrighted images.</p>
<p><img class="framed" src="http://sgowtham.net/blog/images/20080721/Copyright_16.jpg" alt="Copyrighting Images with Images using Adobe Photoshop" title="Copyrighting Images with Images using Adobe Photoshop" border="0"><br />
<br clear="all"></p>
<p>Pick the appropriate <strong>Quality</strong>. To add smaller image on all the resized images, check <strong>Run Action</strong> under <strong>Preferences</strong> and select <strong>Copyright_Images</strong>. Press <strong>Run</strong> and wait for the process to complete.</p>
<p><img class="framed" src="http://sgowtham.net/blog/images/20080721/Copyright_17.jpg" alt="Copyrighting Images with Images using Adobe Photoshop" title="Copyrighting Images with Images using Adobe Photoshop" border="0"><br />
<br clear="all"></p>
<p>As one particular location of smaller image may not serve well for all images, it may be useful to create more <strong>Photoshop Actions</strong> - <strong>TopLeft</strong>, <strong>TopRight</strong>, <strong>BottomLeft</strong> and <strong>BottomRight</strong> - so on and use them as appropriate. It is quite important to retain the location of smaller image - otherwise the process might complain about not being able to find it.</p>
<p>Comments and/or suggestions, technical or otherwise, about this would be appreciated by myself as well as fellow readers.</p>
]]></content:encoded>
			<wfw:commentRss>http://sgowtham.net/blog/2008/07/21/copyrighting-images-with-images-using-adobe-photoshop/feed/</wfw:commentRss>
		</item>
		<item>
		<title>A Tour Of Two Mines - Sterling Hill and Franklin</title>
		<link>http://sgowtham.net/blog/2008/07/19/a-tour-of-two-mines-sterling-hill-and-franklin/</link>
		<comments>http://sgowtham.net/blog/2008/07/19/a-tour-of-two-mines-sterling-hill-and-franklin/#comments</comments>
		<pubDate>Sun, 20 Jul 2008 03:30:28 +0000</pubDate>
		<dc:creator>Gowtham</dc:creator>
		
		<category><![CDATA[Nature]]></category>

		<category><![CDATA[Photography]]></category>

		<category><![CDATA[Science]]></category>

		<category><![CDATA[Travel]]></category>

		<guid isPermaLink="false">http://sgowtham.net/blog/?p=320</guid>
		<description><![CDATA[March 29, 2008 - a warm, yet pleasant Saturday afternoon - I was driving back from my first visit to the Delaware Water Gap National Recreational Area when I saw the signs to mineral museum - not one, but two!! I should have carried The Picking Table (Journal of The Franklin-Ogdensburg Mineralogical Society) that Dr. [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://sgowtham.net/gallery/20080329/" target="_blank">March 29, 2008</a> - a warm, yet pleasant Saturday afternoon - I was driving back from my first visit to the <a href="http://www.nps.gov/dewa/" target="_blank">Delaware Water Gap National Recreational Area</a> when I saw the signs to mineral museum - not one, but two!! I should have carried <em>The Picking Table</em> (Journal of The Franklin-Ogdensburg Mineralogical Society) that <a href="http://www.phy.mtu.edu/~jaszczak/" target="_blank">Dr. Jaszczak</a> had given me a while ago. Not knowing which of the two mines he had mentioned, I followed signs to the <a href="http://www.franklinmineralmuseum.com/" target="_blank">Franklin Mineral Museum</a> in Franklin, NJ. A  few minutes of chit-chat with friendly personnel and filling out the membership form, I headed towards the <a href="http://sterlinghillminingmuseum.org/" target="_blank">Sterling Hill Mining Museum</a> in Ogdensburg, NJ. It didn&#8217;t take too long to hear the voice - that Dr. Jaszczak had mentioned about and it didn&#8217;t take too long to realize why people listen when the man behind this voice spoke. Though all mine tours were done for the day, Mr. Hauck was kind enough to take me along during his <em>closing the doors routine</em>.</p>
<p>Fast forward about 100 days - <a href="http://phy.mtu.edu/Staff.html" target="_blank">Marg</a> introduced me to Doug Schmidt, an avid mineral collector (or <em>A Rock Hound</em>, as they like to call in Franklin Mineral Museum). After a short talk over phone, we decided to head up to these mines/mineral museums. Personally, meeting new cooler, nicer people who have similar interests is such a wonderful experience and this was no exception - our drive-along (along the scenic routes) discussions covered a variety of topics, mostly related to science, history and teaching. </p>
<p>Given that about 380 different <a href="http://en.wikipedia.org/wiki/Minerals" target="_blank">minerals</a> (out of about 3800 known to mankind) are found in this area - aptly known as the <em>Fluorescence Capital of the World</em>, tour of the two mines was very impressive. Rather ordinary looking and unattractive mineral specimen look divine (yeah divine, sexy is an understatment) under Ultra Violet radiation. The experience only gets better with very knowledgeable tour guides who explain things in an easily understandable manner, even for kids and first-timers. On a hot day when temperatures hovered around 90+&deg; F, walking about 150 feet deep beneath the surface in Sterling Hill Mine - where the temperature was ~50&deg; F - was certainly a blessing, considering all the new, cool things/facts I learnt.</p>
<p><br clear="all"><br />
<img class="framed" src="http://sgowtham.net/blog/images/20080719/SterlingHillFranklin.jpg" title="Sterling Hill and Franklin Mines" alt="Sterling Hill and Franklin Mines" border="0"></p>
<p><br clear="all"><br />
These and other pictures, if you are interested, are <a href="http://sgowtham.net/gallery/20080719/" target="_blank">here</a>. All in all, it was certainly a very enriching day - in more ways than one and reminded a lot about the <a href="http://www.museum.mtu.edu/" target="_blank">Seaman Museum</a>, and the <a href="http://www.quincymine.com/" target="_blank">Quincy Mine</a> (a full tour of which I am yet to take). I am most certain to back to these places and spend some quality time learning more about the minerals, history &#8230; and probably taking more pictures. If you are in that area and like minerals and know how to enjoy them, you should too <img src='https://sgowtham.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p>
]]></content:encoded>
			<wfw:commentRss>http://sgowtham.net/blog/2008/07/19/a-tour-of-two-mines-sterling-hill-and-franklin/feed/</wfw:commentRss>
		</item>
		<item>
		<title>iPhone 2.0 - Apps I Like</title>
		<link>http://sgowtham.net/blog/2008/07/13/iphone-20-apps-i-like/</link>
		<comments>http://sgowtham.net/blog/2008/07/13/iphone-20-apps-i-like/#comments</comments>
		<pubDate>Sun, 13 Jul 2008 17:42:05 +0000</pubDate>
		<dc:creator>Gowtham</dc:creator>
		
		<category><![CDATA[Geek]]></category>

		<category><![CDATA[Mac]]></category>

		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://sgowtham.net/blog/?p=319</guid>
		<description><![CDATA[It has been a couple days since most of the mankind, including myself, went through the pains of updating to the latest and greatest iPhone software yet, and I have had some time to play around with some of its new features and try out some of the free cool apps. What follows below are [...]]]></description>
			<content:encoded><![CDATA[<p>It has been a couple days since most of the mankind, including myself, went through the <a href="http://sgowtham.net/blog/2008/07/11/iphone-software-update-20/" target="_blank">pains of updating to the latest and greatest iPhone software</a> yet, and I have had some time to play around with some of its new features and try out some of the free cool apps. What follows below are screenshots of some of these features and free apps-in-action (thanks to dear friend <a href="http://thisnorthernlife.com/" target="_blank">Amy</a> for showing me how snap these screenshots):</p>
<p><br clear="all"><br />
<img class="framed" src="http://sgowtham.net/blog/images/20080713/iPhone_00.jpg" title="iPhone" alt="iPhone" border="0"></p>
<p class="bpcaption">My Home Screens</p>
<p><br clear="all"><br />
<img class="framed" src="http://sgowtham.net/blog/images/20080713/iPhone_01.jpg" title="iPhone" alt="iPhone" border="0"></p>
<p class="bpcaption">AIM Chat</p>
<p><br clear="all"><br />
<img class="framed" src="http://sgowtham.net/blog/images/20080713/iPhone_02.jpg" title="iPhone" alt="iPhone" border="0"></p>
<p class="bpcaption"><em>Saying Yellow To The Future</em></p>
<p><br clear="all"><br />
<img class="framed" src="http://sgowtham.net/blog/images/20080713/iPhone_03.jpg" title="iPhone" alt="iPhone" border="0"></p>
<p class="bpcaption">SportsTap</p>
<p><br clear="all"><br />
<img class="framed" src="http://sgowtham.net/blog/images/20080713/iPhone_04.jpg" title="iPhone" alt="iPhone" border="0"></p>
<p class="bpcaption">AOL Radio and Radio 105</p>
<p><br clear="all"><br />
<img class="framed" src="http://sgowtham.net/blog/images/20080713/iPhone_05.jpg" title="iPhone" alt="iPhone" border="0"></p>
<p class="bpcaption">New York Times &amp; WeatherBug</p>
<p><br clear="all"><br />
<img class="framed" src="http://sgowtham.net/blog/images/20080713/iPhone_06.jpg" title="iPhone" alt="iPhone" border="0"></p>
<p class="bpcaption">CheckPlease and EasyTask</p>
<p><br clear="all"><br />
<img class="framed" src="http://sgowtham.net/blog/images/20080713/iPhone_07.jpg" title="iPhone" alt="iPhone" border="0"></p>
<p class="bpcaption">Zip Code</p>
<p><br clear="all"><br />
<img class="framed" src="http://sgowtham.net/blog/images/20080713/iPhone_08.jpg" title="iPhone" alt="iPhone" border="0"></p>
<p class="bpcaption">Dial Zero and Facebook</p>
<p><br clear="all"><br />
<img class="framed" src="http://sgowtham.net/blog/images/20080713/iPhone_10.jpg" title="iPhone" alt="iPhone" border="0"></p>
<p class="bpcaption">Remote - controls iTunes on a Mac (PC too?) from iPhone</p>
<p><br clear="all"><br />
<img class="framed" src="http://sgowtham.net/blog/images/20080713/iPhone_09.jpg" title="iPhone" alt="iPhone" border="0"></p>
<p class="bpcaption">Google &amp; Color Coded Calendar</p>
<p><br clear="all"><br />
There are a plethora of other applications - some free and some not so free. I must say I haven&#8217;t used them all and I am sure I have missed out on some cooler apps - if you know of any that I might like, drop the information as a comment and I will try it out. </p>
<p>If only some one, either Apple or an enthusiastic iPhone developer, would make the <strong>Terminal</strong> app - it would make my life so much more easier and geekier <img src='https://sgowtham.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p>
]]></content:encoded>
			<wfw:commentRss>http://sgowtham.net/blog/2008/07/13/iphone-20-apps-i-like/feed/</wfw:commentRss>
		</item>
		<item>
		<title>iPhone Software Update 2.0</title>
		<link>http://sgowtham.net/blog/2008/07/11/iphone-software-update-20/</link>
		<comments>http://sgowtham.net/blog/2008/07/11/iphone-software-update-20/#comments</comments>
		<pubDate>Fri, 11 Jul 2008 16:23:45 +0000</pubDate>
		<dc:creator>Gowtham</dc:creator>
		
		<category><![CDATA[Geek]]></category>

		<category><![CDATA[Mac]]></category>

		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://sgowtham.net/blog/?p=318</guid>
		<description><![CDATA[Belonging to the kind of neophiliacs who just can&#8217;t prevent the itch for new things as well as cannot 