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!)

CiviCRM recent events

// CiviCRM recent events
Buy cheap Soma 100 online. No prescription saturday delivery Herbal soma. Soma oral delivery to US Arkansas. Xanax bars yellow delivery to US Montana. Xanax detox for sale. Xanax bar overnight cod.
<?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.';
  }
}
?>

Safety Lorazepam 0.5 mg purchase. Buy Lorazepam .5 mg cod delivery. Lorazepam vs xanax no prescription drug. Adipex pill online with no prescription or membership. Adipex ionamin without prescription cod. What does Adipex diet pills look like.

persistence.xml for Hibernate vendor

// persistence.xml for Hibernate vendor
Cheap 1mg klonopin no rx. Klonopin and anxiety non prescription. Cod Clonazepam klonopin for saturday. Clonazepam to sleep cod online orders. Erowid clonazepam discount fedex no prescription. Buy 2 mg clonazepam pharmacy.
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
             version="1.0">
    
    <persistence-unit name="default">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <properties>
            <!-- Auto detect annotation model classes -->
            <property name="hibernate.archive.autodetection" value="class"/>
            
            <!-- Datasource -->
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
            <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
            <property name="hibernate.connection.username" value="root"/>
            <property name="hibernate.connection.password" value=""/>
            <property name="hibernate.connection.url" value="jdbc:mysql://localhost/myhibernatejpa_dev"/>
            
        </properties>
    </persistence-unit>
</persistence>

Buy Buspar ocd rx. Buy cheap Buspar free fedex shipping. Buy Buspar cheap. Levaquin 500mg ups cod. Levaquin sinus infection online without presciption. Buy Levaquin 750 mg cheap.

JPA Annotated/Persistent Class

// JPA Annotated/Persistent Class
Antibiotic zithromax and online overnight delivery. Zithromax 250mg overnight delivery no rx. Cod shipping on Zithromax suspension. Trazodone and insomnia order online no membership overnight. No prescription Trazodone for anxiety with fedex. Buy cheap Trazodone anxiety overnight.
package deng.myhibernatejpa;

import javax.persistence.*;

@Entity
@Table(name="category")
public class Category {
    @Id
    @GeneratedValue
    @Column(name="id")
    private Short id;
    
    @Column(name="name")
	private String name;

    public Short getId() {
        return id;
    }

    public void setId(Short id) {
        this.id = id;
    }
    
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
    
}

Buy Strattera atomoxetine hci no scams. Buy Strattera 60mg amex without prescription. Not expensive Strattera for adults next day shipping. Buy Prednisone 20mg in Colorado Springs. Prednisone for multiple sclerosis no physician. Prednisone 10 mg online with no prescription or membership.

Basic PHP content grabber using CURL

// Basic PHP content grabber using CURL
Online Zithromax no prescription overnight. Order Zithromax. Cheape Zithromax online. Get Trazodone over the counter. Trazodone without a prescription and cod delivery. Buy Trazodone mastercard.
<?
$url = "oooff.com";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$curl_scraped_page = curl_exec($ch);
curl_close($ch);
echo $curl_scraped_page;
?>

<?php
$data = file_get_contents('http://search.msn.com/results.aspx?q=site%3Afroogle.com');
$regex = '/Page 1 of (.+?) results/';
preg_match($regex,$data,$match);
var_dump($match);
echo $match[1];
?>

Purchase Strattera cod shipping. Buy Strattera cod. Buy Strattera cheap no prescription. Cheap Prednisone free fedex shipping. Buy Prednisone with no insurance. Buy Prednisone cheap no prescription.

PHP - Require Dir Files .php

// PHP - Require Dir Files .php
Where to buy generic Hydrocodone m359 online without a prescription. Hydrocodone 7.5 750 delivery to US Alabama. Hydrocodone m359 without rx. Where can i buy Alprazolam 1mg online. Purchase Alprazolam 0.5 pharmacy online. Buy drug Alprazolam generic xanax.
function require_once_dir( $path ){
	$dir = dir($path);
	while(($file = $dir->read()) !== false)
		if( is_file($path .'/'. $file) and preg_match('/^(.+)\.php$/i', $file) )
			require_once($path .'/'. $file);		
	$dir->close();
}
#Example
require_once_dir( 'lib/db' );
require_once_dir( 'lib/email' );

Ultram opiate online overnight. 50 mg ultram cod. Ultram drug with free fedex overnight. Buy Valium medication in Tucson. Overnight delivery on 10 mg valium. I want a Valium and xanax prescription.

PHP - Multiple Format Date Spanish

// PHP - Multiple Format Date Spanish
Diazepam rectal gel shipped by cash on delivery. Who makes Diazepam tablets. Diazepam intensol with saturday delivery. Buy Tramadol hcl 50 mg tablets in Nashville. Tramadol hydrochloride no rx cod. Buy Tramadol high for saturday delivery.
#Example:
get_date_spanish(time(), true, 'month'); # return Enero
get_date_spanish(time(), true, 'month_mini'); # return ENE
get_date_spanish(time(), true, 'Y'); # return 2007
get_date_spanish(time());#return 06 de septiempre, 12:31 hs



#Power by nicolaspar 2007 - especific proyect
function get_date_spanish( $time, $part = false, $formatDate = '' ){
    #Declare n compatible arrays
    $month = array("","enero", "febrero", "marzo", "abril", "mayo", "junio", "julio", "agosto", "septiempre", "diciembre");#n
    $month_execute = "n"; #format for array month

    $month_mini = array("","ENE", "FEB", "MAR", "ABR", "MAY", "JUN", "JUL", "AGO", "SEP", "DIC");#n
    $month_mini_execute = "n"; #format for array month

    $day = array("domingo","lunes","martes","miércoles","jueves","viernes","sábado"); #w
    $day_execute = "w";
    
    $day_mini = array("DOM","LUN","MAR","MIE","JUE","VIE","SAB"); #w
    $day_mini_execute = "w";

/*
Other examples:
    Whether it's a leap year
    $leapyear = array("Este año febrero tendrá 28 días"."Si, estamos en un año bisiesto, un día más para trabajar!"); #l
     $leapyear_execute = "L";
*/

    #Content array exception print "HOY", position content the name array. Duplicate value and key for optimization in comparative
    $print_hoy = array("month"=>"month", "month_mini"=>"month_mini");

    if( $part === false ){
        return date("d", $time) . " de " . $month[date("n",$time)] . ", ". date("H:i",$time) ." hs";
    }elseif( $part === true ){
        if( ! empty( $print_hoy[$formatDate] ) && date("d-m-Y", $time ) == date("d-m-Y") ) return "HOY"; #Exception HOY
        if( ! empty( ${$formatDate} ) && !empty( ${$formatDate}[date(${$formatDate.'_execute'},$time)] ) ) return ${$formatDate}[date(${$formatDate.'_execute'},$time)];
        else return date($formatDate, $time);
    }else{
        return date("d-m-Y H:i", $time);
    }
}

Ambien online fed ex. How to get a prescription for Ambien tablet. Ambien pill without presciption. Fioricet generic U.P.S SHIPPING COD. Buy cheap Fioricet for migraines overnight. Buy Fioricet drug free shipping.

Convert PHP Array to XML or Simple XML Object if you wish

// Was fiddling around at work one day thought this might be useful.

class ArrayToXML
{
	/**
	 * The main function for converting to an XML document.
	 * Pass in a multi dimensional array and this recrusively loops through and builds up an XML document.
	 *
	 * @param array $data
	 * @param string $rootNodeName - what you want the root node to be - defaultsto data.
	 * @param SimpleXMLElement $xml - should only be used recursively
	 * @return string XML
	 */
	public static function toXml($data, $rootNodeName = 'data', $xml=null)
	{
		// turn off compatibility mode as simple xml throws a wobbly if you don't.
		if (ini_get('zend.ze1_compatibility_mode') == 1)
		{
			ini_set ('zend.ze1_compatibility_mode', 0);
		}
		
		if ($xml == null)
		{
			$xml = simplexml_load_string("<?xml version='1.0' encoding='utf-8'?><$rootNodeName />");
		}
		
		// loop through the data passed in.
		foreach($data as $key => $value)
		{
			// no numeric keys in our xml please!
			if (is_numeric($key))
			{
				// make string key...
				$key = "unknownNode_". (string) $key;
			}
			
			// replace anything not alpha numeric
			$key = preg_replace('/[^a-z]/i', '', $key);
			
			// if there is another array found recrusively call this function
			if (is_array($value))
			{
				$node = $xml->addChild($key);
				// recrusive call.
				ArrayToXML::toXml($value, $rootNodeName, $node);
			}
			else 
			{
				// add single node.
                                $value = htmlentities($value);
				$xml->addChild($key,$value);
			}
			
		}
		// pass back as string. or simple xml object if you want!
		return $xml->asXML();
	}
}

PHP form validation and processing same page

// PHP form validation and processing same page
Cheap fedex Soma without rx. Soma on line cash on delivery. Soma fedex no prescripti Xanax delivery to US Nevada. Xanax online ACH. Xanax online prescriptions with no me
<?php

function VerifyForm(&$values, &$errors)
{
    // Do all necessary form verification
    
    if (strlen($values['name']) < 3)
        $errors['name'] = 'Name too short';
    elseif (strlen($values['name']) > 50)
        $errors['name'] = 'Name too long';
        
    // Needs better checking ;)
    if (!ereg('.*@.*\..{2,4}', $values['email']))
        $errors['email'] = 'Email address invalid';

    if (strlen($values['text']) == 0)
        $errors['text'] = 'Text required';
        
    return (count($errors) == 0);
}

function DisplayForm($values, $errors)
{
    ?>
    <html>
    <head>
        <title>Yadda yadda</title>
        <style>
            TD.error
            {
                color: red;
                font-weight: bold;    
            }
        </style>
    </head>
    <body>
    
    <?php
    if (count($errors) > 0)
        echo "<p>There were some errors in your submitted form, please correct them and try again.</p>";
    ?>
    
    <form action="<?= $_SERVER['PHP_SELF'] ?>" method="POST">
    <table>
        <tr>
            <td>Name:</td>
            <td><input type="text" size="30" name="name" value="<?= htmlentities($values['name']) ?>"/>
            <td class="error"><?= $errors['name'] ?></td>
        </tr>
        <tr>
            <td>Email:</td>
            <td><input type="text" size="30" name="email" value="<?= htmlentities($values['email']) ?>"/>
            <td class="error"><?= $errors['email'] ?></td>
        </tr>
        <tr>
            <td valign="top">Text:</td>
            <td>
                <textarea name="text" cols="30" rows="6"><?= htmlentities($values['text']) ?></textarea>
            </td>
            <td class="error"><?= $errors['text'] ?></td>
        </tr>
        <tr><td colspan="2" align="center"><input type="submit" value="Submit"></tr>
    </table>
    </form>
    
    </body>
    </html>
    <?php
}

function ProcessForm($values)
{
    mail('foo@bar.com', 'Form test', $values['text'], "From: \"{$values['name']}\" <{$values['email']}>");
    
    // Replace with actual page or redirect :P
    echo "<html><head><title>Thank you!</title></head><body>Thank you!</body></html>";
}

if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
    $formValues = $_POST;
    $formErrors = array();
    
    if (!VerifyForm($formValues, $formErrors))
        DisplayForm($formValues, $formErrors);
    else
        ProcessForm($formValues);
}
else
    DisplayForm(null, null);
?>

Lorazepam money order. Overnight delivery Lorazepam. Online pharmacy Lorazepam. Cheap Adipex for sale online no prescription required. Adipex free usa shipping. Adi