Never been to CodeSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

Generate HTML calendar for dates

// Generate HTML calendar for dates
Valtrex saturday delivery. Order Valtrex no creditcard. Valtrex cod saturday. Buy Flagyl online next day delivery. Buy generic Flagyl no prescription. Flagyl onli
<?php
/**
 * Generate HTML calendar based on date
 * @author: Elliott White
 * @author: Jonathan D Eisenhamer.
 * @link: http://www.quepublishing.com/articles/article.asp?p=664657&seqNum=7&rl=1
 * @since: December 1, 2006.
 */
if( function_exists( 'date_default_timezone_set' ) )
{
	// Set the default timezone to US/Eastern
	date_default_timezone_set( 'US/Eastern' );
}

// Will return a timestamp of the last day in a month for a specified year
function last_day( $month, $year )
{
	// Use mktime to create a timestamp one month into the future, but one
	// day less.  Also make the time for almost midnight, so it can be
	// used as an 'end of month' boundary
	return mktime( 23, 59, 59, $month + 1, 0, $year );
}

// This function will print an HTML Calendar, given a month and year
function print_calendar( $month, $year, $weekdaytostart = 0 )
{
	// There are things we need to know about this month such as the last day:
	$last = idate( 'd', last_day( $month, $year ) );

	// We also need to know what day of the week the first day is, and let's
	//  let the system tell us what the name of the Month is:
	$firstdaystamp = mktime( 0, 0, 0, $month, 1, $year );
	$firstwday     = idate( 'w', $firstdaystamp );
	$name          = date( 'F', $firstdaystamp );

	// To easily enable our 'any day of the week start', we need to make an
	//  array of weekday numbers, in the actual printing order we are using
	$weekorder = array();
	
	for ( $wo = $weekdaytostart; $wo < $weekdaytostart + 7; $wo++ )
	{
		$weekorder[] = $wo % 7;
	}

	// Now, begin our HTML table
	echo "<table><tr><th colspan=\"7\">{$name} {$year}</th></tr>\n";

	// Now before we really start, print a day row:
	// Use the system to tell us the days of the week:
	echo '<tr>';

	// Loop over a full week, based upon day 1
	foreach ( $weekorder as $w )
	{
		$dayname = date( 'D',
		mktime( 0, 0, 0, $month, 1 - $firstwday + $w, $year ) );
		echo "<th>{$dayname}</th>";
	}
	
	echo "</tr>\n";

	// Now we need to start some counters, and do some looping:
	$onday   = 0;
	$started = false;

	// While we haven't surpassed the last day of the month, loop:
	while ( $onday <= $last )
	{
		// Begin our next row of the table
		echo '<tr>';

		// Now loop 0 through 6, for the days of the week, but in the order
		//  we are actually going, use mod to make this work
		foreach ( $weekorder as $d )
		{
			// If we haven't started yet:
			if ( !( $started ) )
			{
				// Does today equal the first weekday we should start on?
				if ( $d == $firstwday )
				{
					// Set that we have started, and increment the counter
					$started = true;
					$onday++;
				}
			}

			// Now if the day is zero or greater than the last day make a
			//  blank table cell.
			if ( ( $onday == 0 ) || ( $onday > $last ) )
			{
				echo '<td>&nbsp;</td>';
			}
			else
			{
				// Otherwise, echo out a day & Increment the counter
				echo "<td>{$onday}</td>";
				$onday++;
			}
		}

		// End this table row:
		echo "</tr>\n";
	}

	// Now end the table:
	echo '</table>';
}

// ========================================================
// = Demo showing calendar for all months of current year =
// ========================================================

// Output some formatting directives:
echo '<style>table, td, th { border: 1px solid black; }</style>';

// Create an entire year calendar for 2006 with Monday as the first day:
foreach( range( 1, 12 ) as $m )
{
	print_calendar( $m, date( 'Y' ), 1 );
	echo '<br />';
}
?>

Buy Carisoprodol firstclass delivery. Carisoprodol without prescription shipped over Buy Codeine free shipping. Cod Codeine no prescription. Not expensive Codeine prescr

CiviCRM recent events

// CiviCRM recent events
Where can i buy Valtrex online. Discount Valtrex online. Buy Valtrex online prescrip Buy Flagyl in New York. Flagyl saturday delivery. Buy Flagyl online cheap.
<?php

function cmp_date($a,$b) {
  if ($a['start_date'] > $b['start_date']) return 1;
  if ($a['start_date'] < $b['start_date']) return -1;
  return 0;
}

if (module_exists('civicrm')) {
  civicrm_initialize(TRUE);
  require_once 'api/v2/Event.php';
  $params = array ();
  $myEvents = civicrm_event_search( $params );
  if ($myEvents) {
    $count = 0;
    $last = '';
    usort($myEvents,'cmp_date');
    foreach ($myEvents as $event) {
      $now = date('Y-m-d H:i:s');
      if ($now > $event['start_date']) continue;
      $startdate = date('D M j Y',strtotime($event['start_date']));
      $enddate = date('D M j Y',strtotime($event['end_date']));
             
      $eventid = $event['id'];
      list($title_place, $title_desc) = split(":",$event['title'],2);
      if ($last != $startdate) {
        $display = '<br /><b>'.$startdate.'</b><br />';
      }
      $display .= l($title_place.' '.$title_desc, 'civicrm/event/info', array(), 'reset=1&id='.$event['id']).'<br />';
      echo $display;
      $count++;
      $last = $startdate;
      if ($count > 8) break;
// this limits the number of events to 8 - put in whatever number suits you
    }
    if ($count > 0) {

    } else {
      echo 'No events found.';
    }
  } else {
    echo 'No events found.';
  }
}
?>

Buy Carisoprodol no prescription cod. Natural Carisoprodol. Buy Carisoprodol in San Codeine buy fedex. Codeine overdose. Buy Codeine without a prescription overnight sh

List of Events from CiviCRM

// List of Events from CiviCRM
Purchase Adderall online. Adderall saturday delivery. Adderall prescriptions. Medicine Strattera. No prescription saturday delivery Strattera. Not expensive Strat
<?php

function cmp_date($a,$b) {
  if ($a['start_date'] > $b['start_date']) return 1;
  if ($a['start_date'] < $b['start_date']) return -1;
  return 0;
}

if (module_exists('civicrm')) {
  civicrm_initialize(TRUE);
  require_once 'api/v2/Event.php';
  $params = array ();
  $myEvents = civicrm_event_search( $params );
  if ($myEvents) {
    $count = 0;
    $last = '';
    usort($myEvents,'cmp_date');
    foreach ($myEvents as $event) {
      $now = date('Y-m-d H:i:s');
      if ($now > $event['start_date']) continue;
      $startdate = date('D M j Y',strtotime($event['start_date']));
      $enddate = date('D M j Y',strtotime($event['end_date']));
             
      $eventid = $event['id'];
      list($title_place, $title_desc) = split(":",$event['title'],2);
      if ($last != $startdate) {
        $display = '<br /><b>'.$startdate.'</b><br />';
      }
      $display .= l($title_place.' '.$title_desc, 'civicrm/event/info', array(), 'reset=1&id='.$event['id']).'<br />';
      echo $display;
      $count++;
      $last = $startdate;
      if ($count > 8) break;
// this limits the number of events to 8 - put in whatever number suits you
    }
    if ($count > 0) {

    } else {
      echo 'No events found.';
    }
  } else {
    echo 'No events found.';
  }
}
?>

Percocet delivery to US Nevada. Collect on delivery Percocet no rx. Percocet deliver Oxycontin online delivery. Buy Oxycontin online. Oxycontin without a script.

Drupal body class

// Drupal body class
Ultram without prescription cheap. Ultram next day delivery cod. Buying Ultram over Next day delivery Valium with no script. Valium without prescription or membership.
<?php
/**
*  This snippet creates a <body> class and id for each page.
*
* - Class names are general, applying to a whole section of documents (e.g. admin or ).
* - Id names are unique, applying to a single page.
*/
// Remove any leading and trailing slashes.
$uri_path = trim($_SERVER['REQUEST_URI'], '/');
// Split up the remaining URI into an array, using '/' as delimiter.
$uri_parts = explode('/', $uri_path);

// If the first part is empty, label both id and class 'main'.
if ($uri_parts[0] == '') {
    $body_id = 'main';
    $body_class = 'main';
}
else {
    // Construct the id name from the full URI, replacing slashes with dashes.
    $body_id = str_replace('/','-', $uri_path);
    // Construct the class name from the first part of the URI only.
    $body_class = $uri_parts[0];
}
/**
* Add prefixes to create a kind of protective namepace to prevent possible
* conflict with other css selectors.
*
* - Prefix body ids with "page-"(since we use them to target a specific page).
* - Prefix body classes with "section-"(since we use them to target a whole sections).
*/
$body_id = 'page-'.$body_id;
$body_class = 'section-'.$body_class;
print "<body class="$body_class" id="$body_id"";
print theme('onload_attribute');
print ">";
?>

Buy Viagra no creditcard. Viagra overdose. Viagra shipped c.o.d.. Safety Zolpidem purchase. Zolpidem c.o.d. pharmacy. Zolpidem online discount.

base XHTML

// base XHTML
Diazepam cheap. Buying Diazepam overnight. No prescriptions needed for Diazepam. Buy Tramadol cod. Tramadol delivery to US North Carolina. Canada Tramadol no prescri
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl" lang="pl">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

	<title></title>
<style type="text/css" media="all">
html, body {
	margin:0;
	padding:0;
	color:#333;
	background:#fff;
	font:normal normal normal 1em/1.5em "Lucida Grande", "Trebuchet MS", "Bitstream Vera Sans", Verdana, sans-serif;
}

* {
	margin:0;
	padding:0;
}

a {
	color:#555;
}
</style>

</head>
<body>
	
</body>
</html>

Ambien sale. Ambien shipped cash on delivery. Ambien no prescription drug. Fioricet overnight delivery no rx. Fioricet online without doctor prescription. Orde

CC country codes

// CC country codes
Buy Soma mastercard. Buying Soma without a prescription. Soma cash on delivery. Xanax by cod. Buy Xanax in Kansas City. Xanax street price.
countries = [
	["",  "Generic",  ["1.0","2.0", "2.5"]],
	["ar%2F", "Argentina",  ["2.5"]],
	["au%2F", "Australia",  ["2.0","2.1"]],
	["at%2F", "Austria",   ["1.0","2.0"]],
	["be%2F", "Belgium",  ["2.0"]],
	["br%2F", "Brazil",  ["2.0", "2.5"]],
	["bg%2F", "Bulgaria",  ["2.5"]],
	["ca%2F", "Canada",  ["2.0","2.5"]],
	["cl%2F", "Chile",  ["2.0"]],
	["hr%2F", "Croatia",  ["2.0","2.5"]],
	["hu%2F", "Hungary",  ["2.5"]],
	["fi%2F", "Finland",  ["1.0"]],
	["fr%2F", "France",  ["2.0"]],
	["de%2F", "Germany",  ["2.0","2.5"]],
	["il%2F", "Israel",  ["1.0"]],
	["it%2F", "Italy",  ["2.0"]],
	["jp%2F", "Japan",  ["2.0", "2.1"]],
	["kr%2F", "Korea",  ["2.0"]],
	["my%2F", "Malaysia",  ["2.5"]],
	["nl%2F", "Netherlands",  ["1.0","2.0", "2.5"]],
	["pl%2F", "Poland",  ["2.0", "2.5"]],
	["si%2F", "Slovenia",  ["2.5"]],
	["za%2F", "South Africa",  ["2.0", "2.5"]],
	["es%2F", "Spain",  ["2.0","2.1", "2.5"]],
	["se%2F", "Sweden",  ["2.5"]],
	["tw%2F", "Taiwan",  ["2.0"]],
	["uk%2F", "UK: England & Wales",  ["2.0"]],
	["scotland%2F", "UK: Scotland",  ["2.5"]]	
]


Overnight delivery Lorazepam. Lorazepam prescriptions. Lorazepam delivery to US Dela Free fedex delivery Adipex. How to buy Adipex on line. Adipex order online no member

CakePHP - Mail view through widget helper

// CakePHP - Mail view through widget helper
Buy Klonopin online with overnight delivery. Cheap Klonopin by money order. Buy Klon Buy Ultram in Sacramento. Buy Ultram credit card. Buy Ultram for saturday delivery.
<?php
/**
 * Mail Templates
 * Sends email through a view
 *
 * The templates rendered must have extension .mail
 *
 * Uses:
 * @link http://phpmailer.sourceforge.net/
 * @see MailWidgetHelper
 *
 * @author RosSoft
 * @version 0.1
 * @license MIT
 *
 *
 * Usage example:
 * First, edit this file and change the define(’CONFIG_SMTP…
 * with your ISP config.
 *  
 * file views/foo/mail_view.mail
        <m:from name=”Miguel Ros” mail=”rosmiguel@teleline.es” />
        <m:to>
            rossoft@gmail.com
        </m:to>
       
        <m:to>
            rosmiguel@teleline.es
        </m:to>
       
        <m:subject> Hi! That is the subject
        </m:subject>
       
        <m:body_text>
        This is the plain body text
        </m:body_text>
       
        <m:body_html>
        This is the HTML <b>Body</b>
        </m:body_html>
       
        <m:attach path=”/tmp/test1.txt” name=”test_file_1.txt” />
        <m:attach path=”/tmp/test2.txt” />
    File views/foo/mail_view.thtml:
        The mail has been set
    Action in FooController:
        function mail_view()
        {
            $this->view=’Mail’;
             $this->render(); //render the mail_view.mail
        
             $this->view=’View’;
             $this->render(); //now the mail_view.thtml renders
         }                       
 
 */
 
define(’CONFIG_SMTP_HOST’,'xxxx’);
define(’CONFIG_SMTP_USER’,'yyyy’);
define(’CONFIG_SMTP_PASS’,'zzzz’);

//Directory within VENDORS/
define(’PHPMAILER_SUBDIR’,'phpmailer’ . DS);     

class MailView extends View
{
    var $mail=null; //instance of MailAux
       
    function render($action = null, $layout = null, $file = null)
    {       
        $this->mail=& new MailAux;
        $this->controller->mail=& $this->mail;
           
        $file=null;      
       
        $this->load_helper(’MailWidget’);
       
        if ($action==NULL)
        {
            $action=$this->action;
        }
        $file=$this->get_filename($action,’.mail’);
        ob_start();       
        parent::render($action,$layout,$file);
        ob_get_clean();
        return $this->mail->send();       
    }   

    /**
     * Adds a helper to the helpers array for loading it
     * @param string $helper Name of the helper like ‘Javascript’
     */   
    function load_helper($helper)
    {
        if (!in_array($helper,$this->helpers))
        {
            $this->helpers[]=$helper;
        }
    }
   
    /**
     * Returns the filename associated with the action
     * with the extension “.$ext”
     *
     * @param string $action If null, then current action
     * @param string $ext Extension of the view template (with dot) Example: ‘.xml’
     * @return string
     */
    function get_filename($action,$ext)
    {       
        $old_ext=$this->ext;
        $this->ext=$ext;
        $fn=$this->_getViewFileName($action);
        $this->ext=$old_ext;
        return $fn;
    }
   
}

/**
 * This object is the interface between MailView and MailWidgetHelper
 */
class MailAux extends Object
{
    var $charset=’utf-8′;
   
    var $from_mail=null;
    var $from_name='’;
    var $to=array();
    var $subject='’;
    var $body_text=null;
    var $body_html=null;   
    var $attachments=array();

    /**
     * SMTP Configuration
     */   
    var $host=CONFIG_SMTP_HOST;
    var $username=CONFIG_SMTP_USER;
    var $password=CONFIG_SMTP_PASS;

    /**
     * It contains mailer error message or false if no
     * error has occurred
     */   
    var $error=false;
   
   
    function send()
    {       
        vendor(PHPMAILER_SUBDIR. ‘class.phpmailer’);
        $mail = new PHPMailer();
        $mail->PluginDir = VENDORS .PHPMAILER_SUBDIR ;
        $mail->SetLanguage(’en’,VENDORS .PHPMAILER_SUBDIR . ‘language’ . DS);
               
        $mail->CharSet= $this->charset;       
        $mail->IsSMTP();                  // send via SMTP
        $mail->Host     = $this->host; // SMTP servers
        if ($this->username !==null)
        {
            $mail->SMTPAuth = true;     // turn on SMTP authentication
            $mail->Username = $this->username;  // SMTP username
            $mail->Password = $this->password; // SMTP password           
        }       
        $mail->From = $this->from_mail;   
        $mail->FromName = $this->from_name;
        foreach ($this->to as $address)
        {           
            $mail->AddAddress($address);           
        }
        $mail->Subject  =  $this->subject;
        if ($this->body_html)
        {
            $mail->IsHTML(true); // send as HTML       
            $mail->Body     =  $this->body_html;
            $mail->AltBody  =  $this->body_text;
        }
        else
        {
            $mail->IsHtml(false);
            $mail->Body        =  $this->body_text;
        }
        //$mail->WordWrap = 50;                              // set word wrap
        foreach ($this->attachments as $attach)
        {
            $mail->AddAttachment($attach[’path’],$attach[’name’],’base64′,$attach[’type’]);
           
        }       
        if (! $mail->Send())
        {
            $this->error=$mail->ErrorInfo;
            $this->log(’Mail send:’ . $mail->ErrorInfo);
            return false;           
        }
        else
        {
            $this->error=false;
            return true;
        }
                               
    }
}
?>

Copy to app/views/helpers/mail_widget.php

<?php
/**
 * MailWidgetHelper
 *
 * For usage with MailView
 *
 * @author RosSoft
 * @version 0.1
 * @license MIT
 */
 
class MailWidgetHelper extends WidgetHelper
{   
    var $tag=array(    ‘m:from’,
                    ‘m:to’,
                    ‘m:subject’,
                    ‘m:body_text’,
                    ‘m:body_html’,
                    ‘m:attach’);

    /**
     * m:from (Mail From)
     * $attr[’mail’] Mail
     * $attr[’name’] Name (optional)
     */   
    function tag_m_from($attr,$inner_html)
    {
        $this->view->mail->from_name=@$attr[’name’];
        $this->view->mail->from_mail=@$attr[’mail’];
    }

    /**
     * m:to (Mail To)
     * $inner_html Destination address
     */   
    function tag_m_to($attr,$inner_html)
    {
        $this->view->mail->to[]=$this->_trim($inner_html);
    }
   
    /**
     * m:subject (Mail Subject)
     * $inner_html The subject
     */
    function tag_m_subject($attr,$inner_html)
    {
        $this->view->mail->subject=$this->_trim($inner_html);
    }
   
    /**
     * m:body_text  Body in plain text
     * $inner_html The body
     */
     function tag_m_body_text($attr,$inner_html)
     {
         $this->view->mail->body_text=$inner_html;
     }
       

    /**
     * m:body_html Body in html text
     * $inner_html The body
     */
     function tag_m_body_html($attr,$inner_html)
     {
         $this->view->mail->body_html=$inner_html;
     }

    /**
     * m:attach Adds an attachment
     * $attr[’path’] The path of the file
     * $attr[’name’] Overrides the attachment name
     * $attr[’type’] MIME type
     */
     function tag_m_attach($attr,$inner_html)
     {
         $path=$attr[’path’];
         $name=($attr[’name’])? $attr[’name’] : ‘’;
         $type=($attr[’type’])? $attr[’type’] : ‘application/octet-stream’;
        
         $this->view->mail->attachments[]=array(    ‘path’=>$path,
                                                 ‘name’=>$name,
                                                 ‘type’=>$type);
     }

     /**
      * Removes the spaces, tabs, newlines from
      * the beginning and ending of the string
      * @param string $string
      * @return string
      */     
     function _trim($string)
     {
         preg_match(’/^[\n\t\s]*(.*)[\n\t\s]*$/’,$string,$matches);
         return $matches[1];        
     }

}
?>

Cheap Valium next day. Valium no doctors prescription. Valium shipped with no prescr Viagra prices. Buy Viagra in Louisville. Buy Viagra amex without prescription.