PHP Classes
Icontem

File: index.php


  Search   All class groups All class groups   Latest entries Latest entries   Top 10 charts Top 10 charts   Newsletter Newsletter   Blog Blog   Forums Forums   Help FAQ Help FAQ  
  Login   Register  
Recommend this page to a friend! ReTweet ReTweet Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Ken Stanley  >  Class Calendar  >  index.php  
File: index.php
Role: Example script
Content type: text/plain
Description: Advanced Usage Example
Class: Class Calendar
Generate month calendar arrays
 

Contents

Class file image Download
<?php
/******************************************************************************/
/* class_calendar.php: Gregorian calendar to easily create calendars.         */
/* Copyright (C) 2005 Ken Stanley <phpclasses@kennethpaul.com>                */
/*                                                                            */
/* This library is free software; you can redistribute it and/or              */
/* modify it under the terms of the GNU Lesser General Public                 */
/* License as published by the Free Software Foundation; either               */
/* version 2.1 of the License, or (at your option) any later version.         */
/*                                                                            */
/* This library is distributed in the hope that it will be useful,            */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of             */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU          */
/* Lesser General Public License for more details.                            */
/*                                                                            */
/* You should have received a copy of the GNU Lesser General Public           */
/* License along with this library; if not, write to the Free Software        */
/* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
/******************************************************************************/
    
include_once('class_calendar.php');

    
/* Check to see if the user requested a specific language */
    
$lang = isset($_GET['lang']) ? $_GET['lang'] : 'en';

    
/* Create the class object */
    
$cal = new calendar($lang);

    
/* Pad all digits less than ten with a leading zero */
    
$cal->pad_dates TRUE;

    
/* This sets an upper and lower limit for the year */
    
$cal->min_year 1977;
    
$cal->max_year 2007;

    
/* Set the current month, day and year; either use requested date or today's date */
    
$cal->month    = (isset($_GET['month']) ? $_GET['month'] : date("m"));
    
$cal->day    = (isset($_GET['day']) ? $_GET['day'] : date("d"));
    
$cal->year    = (isset($_GET['year']) ? $_GET['year'] : date("Y"));

    
/* Validate the date we have to ensure it falls within our parameters */
    
$cal->valid_date($cal->month$cal->day$cal->year);

    
/* Create the array that contains the requested month */
    
$cal->month_array $cal->get_month($cal->month$cal->year);

    
/* Get the length of the requested month */
    
$cal->month_length $cal->month_length($cal->month$cal->year);

    
/* This array holds the day name and the month name */
    
$cal->name = array(
        
'day' => $cal->day_name($cal->get_day($cal->month$cal->day$cal->year)),
        
'month' => $cal->month_name($cal->month)
    );

    
/* Check to see if the user requested to view the events for a given date */
    
$get_events = (isset($_GET['ge']) && is_numeric($_GET['ge'])) ? $_GET['ge'] : 0;

    
/* Check to see if the user requested to store an event */
    
$add_event = (isset($_POST['e'])) ? $_POST['e'] : NULL;

    
/* Add the event to the SQLite database */
    
if (!is_null($add_event)) {
        
$cal->add_event($cal->month$cal->day$cal->year$add_event);
    }

    
/* Check to see if the user requested to delete an event */
    
$del_event = (isset($_POST['d'])) ? $_POST['d'] : NULL;

    if (!
is_null($del_event)) {
        
$cal->del_event($del_event);
    }

    
/* Cycle through all possible parameters and build a query string for the forms;
       this ensures consistency for the end-user */
    
$query_string '';

    if (isset(
$_GET) && (sizeof($_GET) > 0)) {
        
$query_string .= '?';
    }

    if (isset(
$cal->month) && is_numeric($cal->month)) {
        
$query_string .= "month=" $cal->month;
    }

    if (isset(
$cal->day) && is_numeric($cal->day)) {
        
$query_string .= "&day=" $cal->day;
    }

    if (isset(
$cal->year) && is_numeric($cal->year)) {
        
$query_string .= "&year=" $cal->year;
    }

    if (isset(
$get_events) && is_numeric($get_events)) {
        
$query_string .= "&ge=" $get_events;
    }

    if (isset(
$lang) && is_string($lang)) {
        
$query_string .= "&lang=" $lang;
    }
    
/* End building query_string */
?>
<html lang="en">
 <head>
  <title>Calendar: <?php printf("%s, %s %s, %s"$cal->name['day'], $cal->name['month'], $cal->day$cal->year);?></title>
  <meta http-equiv="Pragma" content="No-cache">
  <style type="text/css" media="screen">
BODY, FORM {
    background-color: white; color: black;
    font-size: 12px;
    margin: 0; padding: 0;
}

#CAL {
    border: 1px solid black;
    background-color: darkred;
}

#CAL A.DAY:LINK, #CAL A.DAY:VISITED {
    display: block;
    width: 100%; height: 100%;
    color: red;
    font-weight: bolder;
    text-decoration: none;
}

#CAL A.DAY:HOVER {
    background-color: red;
    color: white;
}

#CAL A.NORMAL:LINK, #CAL A.NORMAL:VISITED {
    color: red;
}

#CAL A.NORMAL:HOVER {
    color: white;
    background-color: red;
}

#CAL .HEADER {
    background-color: white; color: black;
    font-weight: bolder;
    border-bottom: 1px solid black;
    padding: 2px 4px 2px 4px;
}

#CAL .FOOTER {
    background-color: white; color: black;
    font-weight: bolder;
    border-top: 1px solid black;
    padding: 2px 4px 2px 4px;
}

#CAL .EVENT {
    background-color: white; color: black;
    padding: 2px 4px 2px 4px;
}

#CAL .INDENT {
    width: 100%; height: 100%;
    text-indent: 10px;
}

#CAL .DAY_NORMAL {
    background-color: white;
}

#CAL .DAY_SELECTED {
    color: white;
    font-weight: bolder;
}
  </style>
 </head>
 <body>
  <table border=0 cellpadding=0 cellspacing=0 width="100%" style="height: 100%">
   <tr>
    <td align="center" valign="middle">
     <table id="cal" border=0 cellpadding=0 cellspacing=5 width=300>
      <tr>
       <td align="left" class="header" colspan=7>
        <table border=0 cellpadding=0 cellspacing=0 width="100%">
         <tr>
          <td>
           <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="get" name="lang">
            <input type="hidden" name="month" value="<?php echo $cal->month;?>">
            <input type="hidden" name="day" value="<?php echo $cal->day;?>">
            <input type="hidden" name="year" value="<?php echo $cal->year;?>">
            <label>Language:</label>
            <select name="lang" onchange="document.forms.lang.submit()">
             <option value="en" <?php if ($lang == "en") { echo "selected"; }?>>English
             <option value="fr" <?php if ($lang == "fr") { echo "selected"; }?>>French
             <option value="de" <?php if ($lang == "de") { echo "selected"; }?>>German
             <option value="hu" <?php if ($lang == "hu") { echo "selected"; }?>>Hungarian
             <option value="it" <?php if ($lang == "it") { echo "selected"; }?>>Italian
            </select>
           </form>
          </td>
          <td align="left">
           <a class="normal" href="<?php echo $_SERVER['PHP_SELF'];?>">Reset</a>
          </td>
         </tr>
        </table>
       </td>
      </tr>
      <tr>
       <td align="center" valign="middle" class="header" colspan=7>
        <?php printf("%s, %s %s, %s"$cal->name['day'], $cal->name['month'], $cal->day$cal->year);?> 
       </td>
      </tr>
      <tr>
<?php
    
for ($i 0$i 7$i += 1) {
?>
       <td align="center" valign="middle" class="header"><?php echo $cal->day_name($i2);?></td>
<?php
    
}
?>
      </tr>
<?php
    
for ($i 0$i <= 5$i += 1) {
?>
      <tr>
<?php
        
for ($j 0$j <= 6$j += 1) {
            
$d $cal->month_array[$i][$j];

            if (
$d == 0) {
?>
       <td align="center" valign="middle" class="day_selected">&nbsp;</td>
<?php
            
} else {
                
$num_events $cal->num_events($cal->month$d$cal->year);

                if (
$num_events 0) {
                    
$day sprintf(
                        
"<a class=\"day\" href=\"%s?month=%s&amp;day=%s&amp;year=%s&amp;lang=%s&amp;ge=1\">%s</a>",
                        
$_SERVER['PHP_SELF'],
                        (int)
$cal->month,
                        (int)
$d,
                        (int)
$cal->year,
                        
$lang,
                        
$d
                    
);
                } else {
                    
$day $d;
                }

                if (
$d == $cal->day) {
?>
       <td align="center" valign="middle" class="day_selected"><?php echo $day;?></td>
<?php
                
} else {
?>
       <td align="center" valign="middle" class="day_normal"><?php echo $day;?></td>
<?php
                
}
            }
        }
?>
      </tr>
<?php
    
}
?>
      <tr>
       <td align="center" valign="middle" class="footer" colspan=7>
        <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="get">
         <input type="hidden" name="lang" value="<?php echo $lang;?>">
         <select name="month">
<?php
    
for ($i 1$i <= 12$i += 1) {
        if (
$i == $cal->month) {
?>
          <option value="<?php echo $i;?>" SELECTED><?php echo $cal->month_name($i);?> 
<?php
        
} else {
?>
          <option value="<?php echo $i;?>"><?php echo $cal->month_name($i);?> 
<?php
        
}
    }
?>
         </select>
         <input type="text" name="day" value="<?php echo $cal->day;?>" size=2 maxlength=2>
         <input type="text" name="year" value="<?php echo $cal->year;?>" size=4 maxlength=4>
         <input type="submit" value="Submit">
        </form>
       </td>
      </tr>
<?php
    
if ($cal->has_sqlite) {
?>
      <tr>
       <td align="center" class="footer" colspan=7>
        <form action="<?php echo $_SERVER['PHP_SELF'] . $query_string;?>" method="post">
         <label>Add Event:</label>
         <input type="text" name="e">
         <input type="submit" value="Add">
        </form>
       </td>
      </tr>
<?php
        
if ($get_events == TRUE) {
            
$events $cal->get_events($cal->month$cal->day$cal->year);

            if (
$events) {
                for (
$i 0$j sizeof($events); $i $j$i += 1) {
?>
      <tr>
       <td class="event" colspan=7>
        <table border=0 cellpadding=0 cellspacing=0 width="100%">
         <tr>
          <td><strong><cite><?php echo $cal->date("%a, %d %b %Y %T %Z"$events[$i]['added']);?></cite></strong></td>
          <td align="right">
           <form action="<?php echo $_SERVER['PHP_SELF'] . $query_string;?>" method="post">
            <input type="hidden" name="d" value="<?php echo $events[$i]['id'];?>">
            <input type="submit" value="Delete">
           </form>
          </td>
         </tr>
         <tr>
          <td colspan=2><span class="indent"><?php echo $events[$i]['event'];?></span></td>
         </tr>
        </table>
       </td>
      </tr>
<?php
                
}
            }
        }
    }
?>
     </table>
    </td>
   </tr>
  </table>
 </body>
</html>

 
  Advertise on this site Advertise on this site   Site map Site map   Statistics Statistics   Site tips Site tips   Privacy policy Privacy policy   Contact Contact  

For more information send a message to :
info at phpclasses dot org.
Copyright (c) Icontem 1999-2009 PHP Classes - PHP Class Scripts
  PHP Book Reviews - Reviews of books and other products