⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch11.htm

📁 Web_Programming_with_Perl5,一个不错的Perl语言教程。
💻 HTM
📖 第 1 页 / 共 4 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">



<HTML>







<HEAD>



<!-- This document was created from RTF source by rtftohtml version 3.0.1 -->







	<META NAME="GENERATOR" Content="Symantec Visual Page 1.0">



	<META HTTP-EQUIV="Content-Type" CONTENT="text/html;CHARSET=iso-8859-1">



	<TITLE>Without a title - Title</TITLE>



</HEAD>







<BODY BACKGROUND="r2harch.gif" tppabs="http://210.32.137.15/ebook/Web%20Programming%20with%20Perl%205/r2harch.gif" TEXT="#000000" BGCOLOR="#FFFFFF">







<H2 ALIGN="CENTER"><A HREF="ch10.htm" tppabs="http://210.32.137.15/ebook/Web%20Programming%20with%20Perl%205/ch10.htm"><IMG SRC="blanprev.gif" tppabs="http://210.32.137.15/ebook/Web%20Programming%20with%20Perl%205/blanprev.gif" WIDTH="37" HEIGHT="37"



ALIGN="BOTTOM" BORDER="2"></A><A HREF="index-1.htm" tppabs="http://210.32.137.15/ebook/Web%20Programming%20with%20Perl%205/index-1.htm"><IMG SRC="blantoc.gif" tppabs="http://210.32.137.15/ebook/Web%20Programming%20with%20Perl%205/blantoc.gif" WIDTH="42"



HEIGHT="37" ALIGN="BOTTOM" BORDER="2"></A><A HREF="ch12.htm" tppabs="http://210.32.137.15/ebook/Web%20Programming%20with%20Perl%205/ch12.htm"><IMG SRC="blannext.gif" tppabs="http://210.32.137.15/ebook/Web%20Programming%20with%20Perl%205/blannext.gif"



WIDTH="45" HEIGHT="37" ALIGN="BOTTOM" BORDER="2"></A><BR>



<BR>



<FONT COLOR="#0000AA">11</FONT><BR>



<A NAME="Heading1"></A><FONT COLOR="#000077">Datebooks, Calendars, and Scheduling



on the Web<BR>



</FONT>



<HR>



</H2>







<UL>



	<LI><A HREF="#Heading1">Datebooks, Calendars, and Scheduling on the Web</A>



	<UL>



		<LI><A HREF="#Heading2">HyperCalA Modular Perl5 Calendar and Datebook</A>



		<LI><A HREF="#Heading3">Listing 11.1. hypercal.cgi</A>



		<UL>



			<LI><A HREF="#Heading5">Configuration of HyperCalThe Variables File</A>



		</UL>



		<LI><A HREF="#Heading6">Listing 11.2. Variables and configuration file for HyperCal</A>



		<UL>



			<LI><A HREF="#Heading8">Displaying Appointments on a Specific Day: disp_day.cgi</A>



		</UL>



		<LI><A HREF="#Heading9">Listing 11.3. disp_day.cgi</A>



		<UL>



			<LI><A HREF="#Heading11">Adding Calendar Entries with add_date.cgi</A>



		</UL>



		<LI><A HREF="#Heading12">Listing 11.4. add_date.cgi</A>



		<UL>



			<LI><A HREF="#Heading14">Changing User Passwords with password.change</A>



		</UL>



		<LI><A HREF="#Heading15">Listing 11.5. password.change</A>



		<UL>



			<LI><A HREF="#Heading17">Other Supplementary Programs</A>



		</UL>



		<LI><A HREF="#Heading18">Summary</A>



	</UL>



</UL>







<P>



<HR>



</P>



<P><TT>HyperCal--A Modular Perl5 Calendar and Datebook</TT> As the Internet and corporate



intranets become more and more widespread, and we find Netscape and other browsers



running on more and more PCs, Web-based applications that keep us organized are becoming



more prevalent. Why use a Web-based calendar or datebook? Web-based calendars and



datebooks are the ultimate way to take advantage of the Web, especially in inter-office,



or intranet environments.</P>



<P>Let's consider an example. Your boss has given your team a new project. It is



your responsibility to coordinate the schedules of each of the 10 people on your



team. Do you see where this is going? Each member could access a Web-based scheduling



mechanism, update his or her schedule, see what everyone else is doing, easily communicate



with each other, make comments, and so on. In addition to being a convenient and



efficient way to coordinate people and manage resources, once the data has been entered,



you can easily use Perl to generate reports, calculate efficiency of work cycles,



and so on. The possibilities are endless. Furthermore, using Perl and the Web, the



system is accessible anywhere Netscape is running and is totally extensible and scaleable.



You could manage and track the schedules of everyone in your entire organization.



<H3 ALIGN="CENTER"><A NAME="Heading2"></A><FONT COLOR="#000077">HyperCalA Modular



Perl5 Calendar and Datebook</FONT></H3>



<P>In the pages that follow, we will explore HyperCal, a Calendar/Datebook program



written for Perl5 by Richard Bowen. HyperCal can be obtained from Richard Bowen's



Web site at</P>



<PRE><A HREF="javascript:if(confirm('http://www.rcbowen.com/perl/HyperCal.html  \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address.  \n\nDo you want to open it from the server?'))window.location='http://www.rcbowen.com/perl/HyperCal.html'" tppabs="http://www.rcbowen.com/perl/HyperCal.html"><FONT COLOR="#0066FF">http://www.rcbowen.com/perl/HyperCal.html</FONT></A><FONT



COLOR="#0066FF">



</FONT></PRE>



<P>I recommend installing HyperCal on your Web server before proceeding any further.



To install HyperCal, download the HyperCal_2.x.tar file to your server, place it



in a directory under CGI-bin, and extract the tar archive.</P>



<P>I encourage you to use your understanding of this example as a stepping stone



to implementing a complete Web-based scheduling system customized for your needs.



HyperCal consists of eight pieces of code that perform specific tasks related to



the calendar. This chapter is intended to show how Perl5 can be used to maintain



a Web-based datebook and calendar. I encourage you to look over the source code and



its output as you read through the chapter. I also encourage you to set HyperCal



up on your server and play with the source code and see how it affects the output.</P>



<P>The power of Perl lies in the capability to easily and quickly reuse and modify



existing code to suit your needs. With this in mind, let's discuss &quot;style&quot;



for a minute. Every programmer has his or her own &quot;style&quot; or way he or



she likes to organize the logical flow of code. It makes sense to take advantage



of Perl5's object oriented, modular design whenever you write a Perl5 CGI. The power



and prominence of CGI.pm and other modules discussed in this book are a testament



to this. As you begin to conceptualize your Perl5 program, consider the following



questions:







<OL>



	<LI>Is it modular? Major functions should be broken out into separate autonomous



	modules that can be used in other programs.



	<P>



	<LI>Is it configurable? Configuration settings or variables should be located in



	a separate file.



	<P>



	<LI>Is it understandable? Break your code down into subroutines that do specific



	tasks. Major tasks that might be useful in other programs you write should be broken



	out into modules. Program logic should consist of making calls to subroutines. Use



	whitespace to make your code easier to read. Place comments where it is not obvious



	what your code is doing.



	<P>



	<LI>Is it upgradeable? If you follow the first three directives, this one comes easy.



	<P>



	<LI>Is it portable? Avoid hard-coded references to resources only available on specific



	hardware platforms. If this is not possible, specify them in a separate config file



	instead of in the main code. Examples include pathnames and <TT>flock</TT> routines.



</OL>







<P>If you follow these five directives, you will save yourself considerable amounts



of time and grief, both as you write your code and as you try to maintain and upgrade



it in the future.</P>



<P>Listing 11.1 contains the main hypercal.cgi Perl5 CGI script. This script is responsible



for actually displaying the calendar itself.



<H3 ALIGN="CENTER"><A NAME="Heading3"></A><FONT COLOR="#000077">Listing 11.1. hypercal.cgi</FONT></H3>



<PRE><FONT COLOR="#0066FF">#!/usr/bin/perl



#  HyperCal   by   Richard Bowen



#  A HTML datebook.



#



#  This part draws the calendar and links it to the other scripts.



#  Can be called as http://URL/hypercal, or with arguments



#  as http://URL/hypercal?month&amp;year



require `httools.pl';



require `variables';



$args=$ENV{`QUERY_STRING'};



($sub=$ENV{`PATH_INFO'})=~ s#^/##;



if ($sub=~/personal/) { &amp;personal };



if ($sub eq &quot;goto&quot;) { &amp;goto }



else { &amp;main };



sub main    {



  &amp;header;



  ($this_month,$this_year)=split(/&amp;/,$args);



  if ($args eq &quot;&quot;) {    #  Defaults to current date if none specified.



    &amp;date;   #  Calls the todays date subroutine from httools.pl



    $this_month=$month;



    $this_year=$year;}



($junksec,$junkmin,$junkhour,$today_day,$today_month,$today_year,$junkwday,



&#194;$junkyday,$junkisdst)=localtime(time);$today_year+=1900;$today_month+=1;



&amp;month_txt(&quot;$this_month&quot;);



print &quot;&lt;html&gt;&lt;head&gt;&lt;title&gt;$title - $month_txt, $this_year&lt;/title&gt;&lt;/head&gt;\n&quot;;



print &quot;&lt;body&quot;;



$month_image=@month_images[$this_month-1];



($icon,$bg,$color,$text,$link,$vlink)=split(/~~/,$month_image);



print &quot; background=\&quot;$bg\&quot;&quot; unless ($bg eq &quot;none&quot;);



print &quot; bgcolor=\&quot;$color\&quot;&quot; unless ($color eq &quot;none&quot;);



print &quot; text=\&quot;$text\&quot;&quot; unless ($text eq &quot;none&quot;);



print &quot; link=\&quot;$link\&quot;&quot; unless ($link eq &quot;none&quot;);



print &quot; vlink=\&quot;$vlink\&quot;&quot; unless ($vlink eq &quot;none&quot;);



print &quot;&gt;\n&quot;;



open (DATES, $datebook);



@datebook=&lt;DATES&gt;;



@months=(&quot;December&quot;, &quot;January&quot;, &quot;February&quot;, &quot;March&quot;, &quot;April&quot;, &quot;May&quot;, &quot;June&quot;,



&#194; &quot;July&quot;, &quot;August&quot;, &quot;September&quot;, &quot;October&quot;, &quot;November&quot;, &quot;December&quot;);



@last_days=(31,31,28,31,30,31,30,31,31,30,31,30,31);



@days_of_week=(&quot;Sun&quot;,&quot;Mon&quot;,&quot;Tue&quot;,&quot;Wed&quot;,&quot;Thu&quot;,&quot;Fri&quot;,&quot;Sat&quot;);



@month_offset=(3,3,0,3,2,3,2,3,3,2,3,2,3);



print &quot;&lt;center&gt;&quot;;



print &quot;&lt;table border=6 cellpadding=5 width=100%&gt;\n&quot;;



print &quot;&lt;tr&gt;&lt;td align=center colspan=7&gt;&lt;center&gt;&lt;h2&gt;@months[$this_month],



&#194; $this_year&lt;/h2&gt;&quot;;



if ($multi_user eq &quot;yes&quot; &amp;&amp; $personal_on eq &quot;no&quot;) {



print &quot;&lt;form method=post action=\&quot;$base_url$hypercal/personal\&quot;&gt;&quot;;



print &quot;&lt;input type=submit value=\&quot;Go To Personal Calendar\&quot;&gt;&quot;;}



elsif ($personal_on eq &quot;yes&quot;)    {



($link=$hypercal)=~s/\/personal//g;



print &quot;&lt;form method=post action=\&quot;$base_url$link\&quot;&gt;&quot;;



print &quot;&lt;input type=submit value=\&quot;Go To Public Calendar\&quot;&gt;&quot;;}



print &quot;&lt;img src=\&quot;$icon\&quot; alt=\&quot;\&quot; align=middle hspace=30&gt;&quot; unless



&#194; ($icon eq &quot;none&quot;);



print &quot;&lt;/form&gt;&quot;;



print &quot;&lt;/center&gt;&quot;;



$week_days=join(&quot; &lt;th&gt; &quot;,@days_of_week);



print &quot;&lt;tr&gt;&lt;th&gt;$week_days&lt;br&gt;\n&quot;;



for ($i=1906; $i&lt;$this_year; $i++)    {



    $days_offset++;



    if (($i)%4==0)



        {$days_offset++}; # Leap years



    } # end for



if (($this_year%4)==0 &amp;&amp; ($this_month&gt;2))



    {$days_offset++}; #  Current year is leap year



for ($j=1; $j&lt;($this_month);$j++)    {



    $days_offset+=@month_offset[$j]};



$first_day_of_month=($days_offset%7);



$last_day_in_month=@last_days[$this_month];



if (($this_month==2)&amp;&amp;($this_year%4==0)){$last_day_in_month=29};



$date_place=0;



while ($date_place&lt;$last_day_in_month)    {



print &quot;&lt;tr&gt;&quot;;



for ($j=0; $j&lt;=6; $j++)    {



    if (($first_day_of_month&gt;=0)||($date_place&gt;=$last_day_in_month))



    {print &quot;&lt;td align=center&gt;-&quot;;



    $first_day_of_month--}



    else    {



    $date_place++;



    print &quot;&lt;td align=center&gt;



           &lt;a href=\&quot;$base_url$disp_day?$this_month 



&#194;&amp;$date_place&amp;$this_year\&quot;&gt; $date_place &lt;/a&gt;&quot;;



&amp;appoints($this_month,$date_place,$this_year);



if ($today_day==$date_place &amp;&amp; $today_month==$this_month &amp;&amp; 



&#194;$today_year==$this_year){print&quot;&lt;br&gt;&lt;b&gt;&lt;font color=red&gt;TODAY&lt;/font&gt;&lt;/b&gt;&quot;};



} # end else



}    #end for



print &quot;&lt;br&gt;\n&quot;;



}    #  end while



open (ANNO, &quot;$announce&quot;);



@announce=&lt;ANNO&gt;;



$search=$this_month.&quot;_&quot;.$this_year;



$any_announce=&quot;no&quot;;



for $announces (@announce)    {



($mo,$msg,$aid)=split(/&amp;&amp;/,$announces);



if ($mo eq $search){



if ($any_announce eq &quot;no&quot;){print &quot;&lt;br&gt;&lt;tr&gt;&lt;td align=center colspan=7&gt;&quot;;}



print &quot;&lt;center&gt;&lt;b&gt;$msg&lt;/b&gt;&lt;/center&gt;&lt;br&gt;&quot;;



$any_announce=&quot;yes&quot;;}



        }



print &quot;&lt;/table&gt;&lt;/center&gt;&lt;br&gt;\n&quot;;



print &quot;&lt;center&gt;Select a day to see the appointments for that day.  



       Numbers in parentheses indicate how many appointments 



       are on that day.&lt;/center&gt;&quot;;



print &quot;&lt;hr&gt;\n&quot;;



print &quot;&lt;center&gt;Go to:&lt;/center&gt;&lt;br&gt;\n&quot;;



print &quot;&lt;center&gt;&quot;;



# print &quot;&lt;table border=0 cellpadding=5 width=100%&gt;&quot;;



$last_year=$this_year;



$last_month=($this_month-1);



if ($last_month == 0) {$last_month=12; $last_year=($this_year-1);}



print &quot;[ &lt;a href=\&quot;$base_url$hypercal?$last_month&amp;$last_year\&quot;&gt;



       Previous month  &lt;/a&gt;|\n&quot;;



$next_year=$this_year;



$next_month=($this_month+1);



if ($next_month == 13) {$next_month=1; $next_year=($this_year+1);}



print &quot;&lt;a href=\&quot;$base_url$hypercal?$next_month&amp;$next_year\&quot;&gt;



       Next month  &lt;/a&gt;|&quot;;



print &quot;&lt;a href=\&quot;$base_url$hypercal\&quot;&gt;  Current month  &lt;/a&gt;]



       &lt;/center&gt;&lt;br&gt;\n&quot;;



print &quot;&lt;center&gt;&lt;form method=get action=$base_url$hypercal/goto&gt;&quot;;



print &quot;&lt;input type=submit value=\&quot;Jump\&quot;&gt; to &lt;input name=\&quot;month\&quot;



       size=2&gt; \/ &lt;input name=\&quot;year\&quot; size=4 value=\&quot;$this_year\&quot;&gt;&quot;;



print &quot;&lt;input type=hidden name=\&quot;this_year\&quot; value=\&quot;$this_year\&quot;&gt;&quot;;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -