First commit
This commit is contained in:
commit
c6e2478c40
13918 changed files with 2303184 additions and 0 deletions
15
sites/all/modules/civicrm/packages/.gitignore
vendored
Normal file
15
sites/all/modules/civicrm/packages/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
*~
|
||||
*.bak
|
||||
DB/Table/Manager/ibase.php
|
||||
DB/Table/Manager/oci8.php
|
||||
DB/Table/Manager/sqlite.php
|
||||
DB/fbsql.php
|
||||
DB/ibase.php
|
||||
DB/ifx.php
|
||||
DB/msql.php
|
||||
DB/oci8.php
|
||||
DB/sqlite.php
|
||||
DB/sybase.php
|
||||
XML/RPC.php
|
||||
XML/RPC/Dump.php
|
||||
XML/RPC/Server.php
|
||||
290
sites/all/modules/civicrm/packages/Console/Getopt.php
Normal file
290
sites/all/modules/civicrm/packages/Console/Getopt.php
Normal file
|
|
@ -0,0 +1,290 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 5 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2004 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 3.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available through the world-wide-web at the following url: |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Andrei Zmievski <andrei@php.net> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Getopt.php,v 1.4 2007/06/12 14:58:56 cellog Exp $
|
||||
|
||||
require_once 'PEAR.php';
|
||||
|
||||
/**
|
||||
* Command-line options parsing class.
|
||||
*
|
||||
* @author Andrei Zmievski <andrei@php.net>
|
||||
*
|
||||
*/
|
||||
class Console_Getopt {
|
||||
/**
|
||||
* Parses the command-line options.
|
||||
*
|
||||
* The first parameter to this function should be the list of command-line
|
||||
* arguments without the leading reference to the running program.
|
||||
*
|
||||
* The second parameter is a string of allowed short options. Each of the
|
||||
* option letters can be followed by a colon ':' to specify that the option
|
||||
* requires an argument, or a double colon '::' to specify that the option
|
||||
* takes an optional argument.
|
||||
*
|
||||
* The third argument is an optional array of allowed long options. The
|
||||
* leading '--' should not be included in the option name. Options that
|
||||
* require an argument should be followed by '=', and options that take an
|
||||
* option argument should be followed by '=='.
|
||||
*
|
||||
* The return value is an array of two elements: the list of parsed
|
||||
* options and the list of non-option command-line arguments. Each entry in
|
||||
* the list of parsed options is a pair of elements - the first one
|
||||
* specifies the option, and the second one specifies the option argument,
|
||||
* if there was one.
|
||||
*
|
||||
* Long and short options can be mixed.
|
||||
*
|
||||
* Most of the semantics of this function are based on GNU getopt_long().
|
||||
*
|
||||
* @param array $args an array of command-line arguments
|
||||
* @param string $short_options specifies the list of allowed short options
|
||||
* @param array $long_options specifies the list of allowed long options
|
||||
*
|
||||
* @return array two-element array containing the list of parsed options and
|
||||
* the non-option arguments
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
*/
|
||||
function getopt2($args, $short_options, $long_options = null)
|
||||
{
|
||||
return Console_Getopt::doGetopt(2, $args, $short_options, $long_options);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function expects $args to start with the script name (POSIX-style).
|
||||
* Preserved for backwards compatibility.
|
||||
* @see getopt2()
|
||||
*/
|
||||
function getopt($args, $short_options, $long_options = null)
|
||||
{
|
||||
return Console_Getopt::doGetopt(1, $args, $short_options, $long_options);
|
||||
}
|
||||
|
||||
/**
|
||||
* The actual implementation of the argument parsing code.
|
||||
*/
|
||||
function doGetopt($version, $args, $short_options, $long_options = null)
|
||||
{
|
||||
// in case you pass directly readPHPArgv() as the first arg
|
||||
if (PEAR::isError($args)) {
|
||||
return $args;
|
||||
}
|
||||
if (empty($args)) {
|
||||
return array(array(), array());
|
||||
}
|
||||
$opts = array();
|
||||
$non_opts = array();
|
||||
|
||||
settype($args, 'array');
|
||||
|
||||
if ($long_options) {
|
||||
sort($long_options);
|
||||
}
|
||||
|
||||
/*
|
||||
* Preserve backwards compatibility with callers that relied on
|
||||
* erroneous POSIX fix.
|
||||
*/
|
||||
if ($version < 2) {
|
||||
if (isset($args[0]{0}) && $args[0]{0} != '-') {
|
||||
array_shift($args);
|
||||
}
|
||||
}
|
||||
|
||||
reset($args);
|
||||
while (list($i, $arg) = each($args)) {
|
||||
|
||||
/* The special element '--' means explicit end of
|
||||
options. Treat the rest of the arguments as non-options
|
||||
and end the loop. */
|
||||
if ($arg == '--') {
|
||||
$non_opts = array_merge($non_opts, array_slice($args, $i + 1));
|
||||
break;
|
||||
}
|
||||
|
||||
if ($arg{0} != '-' || (strlen($arg) > 1 && $arg{1} == '-' && !$long_options)) {
|
||||
$non_opts = array_merge($non_opts, array_slice($args, $i));
|
||||
break;
|
||||
} elseif (strlen($arg) > 1 && $arg{1} == '-') {
|
||||
$error = Console_Getopt::_parseLongOption(substr($arg, 2), $long_options, $opts, $args);
|
||||
if (PEAR::isError($error))
|
||||
return $error;
|
||||
} elseif ($arg == '-') {
|
||||
// - is stdin
|
||||
$non_opts = array_merge($non_opts, array_slice($args, $i));
|
||||
break;
|
||||
} else {
|
||||
$error = Console_Getopt::_parseShortOption(substr($arg, 1), $short_options, $opts, $args);
|
||||
if (PEAR::isError($error))
|
||||
return $error;
|
||||
}
|
||||
}
|
||||
|
||||
return array($opts, $non_opts);
|
||||
}
|
||||
|
||||
/**
|
||||
* @access private
|
||||
*
|
||||
*/
|
||||
function _parseShortOption($arg, $short_options, &$opts, &$args)
|
||||
{
|
||||
for ($i = 0; $i < strlen($arg); $i++) {
|
||||
$opt = $arg{$i};
|
||||
$opt_arg = null;
|
||||
|
||||
/* Try to find the short option in the specifier string. */
|
||||
if (($spec = strstr($short_options, $opt)) === false || $arg{$i} == ':')
|
||||
{
|
||||
return PEAR::raiseError("Console_Getopt: unrecognized option -- $opt");
|
||||
}
|
||||
|
||||
if (strlen($spec) > 1 && $spec{1} == ':') {
|
||||
if (strlen($spec) > 2 && $spec{2} == ':') {
|
||||
if ($i + 1 < strlen($arg)) {
|
||||
/* Option takes an optional argument. Use the remainder of
|
||||
the arg string if there is anything left. */
|
||||
$opts[] = array($opt, substr($arg, $i + 1));
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
/* Option requires an argument. Use the remainder of the arg
|
||||
string if there is anything left. */
|
||||
if ($i + 1 < strlen($arg)) {
|
||||
$opts[] = array($opt, substr($arg, $i + 1));
|
||||
break;
|
||||
} else if (list(, $opt_arg) = each($args)) {
|
||||
/* Else use the next argument. */;
|
||||
if (Console_Getopt::_isShortOpt($opt_arg) || Console_Getopt::_isLongOpt($opt_arg)) {
|
||||
return PEAR::raiseError("Console_Getopt: option requires an argument -- $opt");
|
||||
}
|
||||
} else {
|
||||
return PEAR::raiseError("Console_Getopt: option requires an argument -- $opt");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$opts[] = array($opt, $opt_arg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @access private
|
||||
*
|
||||
*/
|
||||
function _isShortOpt($arg)
|
||||
{
|
||||
return strlen($arg) == 2 && $arg[0] == '-' && preg_match('/[a-zA-Z]/', $arg[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @access private
|
||||
*
|
||||
*/
|
||||
function _isLongOpt($arg)
|
||||
{
|
||||
return strlen($arg) > 2 && $arg[0] == '-' && $arg[1] == '-' &&
|
||||
preg_match('/[a-zA-Z]+$/', substr($arg, 2));
|
||||
}
|
||||
|
||||
/**
|
||||
* @access private
|
||||
*
|
||||
*/
|
||||
function _parseLongOption($arg, $long_options, &$opts, &$args)
|
||||
{
|
||||
@list($opt, $opt_arg) = explode('=', $arg, 2);
|
||||
$opt_len = strlen($opt);
|
||||
|
||||
for ($i = 0; $i < count($long_options); $i++) {
|
||||
$long_opt = $long_options[$i];
|
||||
$opt_start = substr($long_opt, 0, $opt_len);
|
||||
$long_opt_name = str_replace('=', '', $long_opt);
|
||||
|
||||
/* Option doesn't match. Go on to the next one. */
|
||||
if ($long_opt_name != $opt) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$opt_rest = substr($long_opt, $opt_len);
|
||||
|
||||
/* Check that the options uniquely matches one of the allowed
|
||||
options. */
|
||||
if ($i + 1 < count($long_options)) {
|
||||
$next_option_rest = substr($long_options[$i + 1], $opt_len);
|
||||
} else {
|
||||
$next_option_rest = '';
|
||||
}
|
||||
if ($opt_rest != '' && $opt{0} != '=' &&
|
||||
$i + 1 < count($long_options) &&
|
||||
$opt == substr($long_options[$i+1], 0, $opt_len) &&
|
||||
$next_option_rest != '' &&
|
||||
$next_option_rest{0} != '=') {
|
||||
return PEAR::raiseError("Console_Getopt: option --$opt is ambiguous");
|
||||
}
|
||||
|
||||
if (substr($long_opt, -1) == '=') {
|
||||
if (substr($long_opt, -2) != '==') {
|
||||
/* Long option requires an argument.
|
||||
Take the next argument if one wasn't specified. */;
|
||||
if (!strlen($opt_arg) && !(list(, $opt_arg) = each($args))) {
|
||||
return PEAR::raiseError("Console_Getopt: option --$opt requires an argument");
|
||||
}
|
||||
if (Console_Getopt::_isShortOpt($opt_arg) || Console_Getopt::_isLongOpt($opt_arg)) {
|
||||
return PEAR::raiseError("Console_Getopt: option requires an argument --$opt");
|
||||
}
|
||||
}
|
||||
} else if ($opt_arg) {
|
||||
return PEAR::raiseError("Console_Getopt: option --$opt doesn't allow an argument");
|
||||
}
|
||||
|
||||
$opts[] = array('--' . $opt, $opt_arg);
|
||||
return;
|
||||
}
|
||||
|
||||
return PEAR::raiseError("Console_Getopt: unrecognized option --$opt");
|
||||
}
|
||||
|
||||
/**
|
||||
* Safely read the $argv PHP array across different PHP configurations.
|
||||
* Will take care on register_globals and register_argc_argv ini directives
|
||||
*
|
||||
* @access public
|
||||
* @return mixed the $argv PHP array or PEAR error if not registered
|
||||
*/
|
||||
function readPHPArgv()
|
||||
{
|
||||
global $argv;
|
||||
if (!is_array($argv)) {
|
||||
if (!@is_array($_SERVER['argv'])) {
|
||||
if (!@is_array($GLOBALS['HTTP_SERVER_VARS']['argv'])) {
|
||||
return PEAR::raiseError("Console_Getopt: Could not read cmd args (register_argc_argv=Off?)");
|
||||
}
|
||||
return $GLOBALS['HTTP_SERVER_VARS']['argv'];
|
||||
}
|
||||
return $_SERVER['argv'];
|
||||
}
|
||||
return $argv;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
2225
sites/all/modules/civicrm/packages/Contact/Vcard/Build.php
Normal file
2225
sites/all/modules/civicrm/packages/Contact/Vcard/Build.php
Normal file
File diff suppressed because it is too large
Load diff
768
sites/all/modules/civicrm/packages/Contact/Vcard/Parse.php
Normal file
768
sites/all/modules/civicrm/packages/Contact/Vcard/Parse.php
Normal file
|
|
@ -0,0 +1,768 @@
|
|||
<?php
|
||||
/**
|
||||
* Parse vCard 2.1 and 3.0 text blocks.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 2.0 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/2_02.txt. If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the world-wide-web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category File_Formats
|
||||
* @package Contact_Vcard_Parse
|
||||
* @author Paul M. Jones <pjones@ciaweb.net>
|
||||
* @copyright 1997-2007 The PHP Group
|
||||
* @license http://www.php.net/license/2_02.txt PHP License 2.0
|
||||
* @version CVS: $Id: Parse.php 288533 2009-09-21 15:04:29Z till $
|
||||
* @link http://pear.php.net/package/Contact_Vcard_Parse
|
||||
*/
|
||||
|
||||
/**
|
||||
* Parser for vCards.
|
||||
*
|
||||
* This class parses vCard 2.1 and 3.0 sources from file or text into a
|
||||
* structured array.
|
||||
*
|
||||
* Usage:
|
||||
*
|
||||
* <code>
|
||||
* // include this class file
|
||||
* require_once 'Contact_Vcard_Parse.php';
|
||||
*
|
||||
* // instantiate a parser object
|
||||
* $parse = new Contact_Vcard_Parse();
|
||||
*
|
||||
* // parse a vCard file and store the data
|
||||
* // in $cardinfo
|
||||
* $cardinfo = $parse->fromFile('sample.vcf');
|
||||
*
|
||||
* // view the card info array
|
||||
* echo '<pre>';
|
||||
* print_r($cardinfo);
|
||||
* echo '</pre>';
|
||||
* </code>
|
||||
*
|
||||
* @category File_Formats
|
||||
* @package Contact_Vcard_Parse
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
* @copyright 1997-2007 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version Release: 1.31.0
|
||||
* @link http://pear.php.net/package/Contact_Vcard_Parse
|
||||
*/
|
||||
class Contact_Vcard_Parse
|
||||
{
|
||||
/**
|
||||
* Reads a file for parsing, then sends it to $this->fromText()
|
||||
* and returns the results.
|
||||
*
|
||||
* @param array $filename The filename to read for vCard information.
|
||||
* @param boolean $decode_qp Optional; Decode quoted printable if true. This
|
||||
* is the default.
|
||||
*
|
||||
* @return array An array of of vCard information extracted from the
|
||||
* file.
|
||||
* @access public
|
||||
* @see self::fromText()
|
||||
* @see self::_fromArray()
|
||||
*/
|
||||
function fromFile($filename, $decode_qp = true)
|
||||
{
|
||||
$text = $this->fileGetContents($filename);
|
||||
|
||||
if ($text === false) {
|
||||
return false;
|
||||
}
|
||||
// dump to, and get return from, the fromText() method.
|
||||
return $this->fromText($text, $decode_qp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the contents of a file. Included for users whose PHP < 4.3.0.
|
||||
*
|
||||
* @param array $filename The filename to read for vCard information.
|
||||
*
|
||||
* @access public
|
||||
* @return string|bool The contents of the file if it exists and is
|
||||
* readable, or boolean false if not.
|
||||
* @see self::fromFile()
|
||||
*/
|
||||
function fileGetContents($filename)
|
||||
{
|
||||
if (file_exists($filename) && is_readable($filename)) {
|
||||
|
||||
$text = '';
|
||||
$len = filesize($filename);
|
||||
|
||||
$fp = fopen($filename, 'r');
|
||||
while ($line = fread($fp, filesize($filename))) {
|
||||
$text .= $line;
|
||||
}
|
||||
fclose($fp);
|
||||
|
||||
return $text;
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares a block of text for parsing, then sends it through and
|
||||
* returns the results from $this->fromArray().
|
||||
*
|
||||
* @param array $text A block of text to read for vCard information.
|
||||
* @param boolean $decode_qp Optional; Decode quoted printable if true. This
|
||||
* is the default.
|
||||
*
|
||||
* @access public
|
||||
* @return array An array of vCard information extracted from the
|
||||
* source text.
|
||||
* @see self::_fromArray()
|
||||
*/
|
||||
function fromText($text, $decode_qp = true)
|
||||
{
|
||||
// convert all kinds of line endings to Unix-standard and get
|
||||
// rid of double blank lines.
|
||||
$this->convertLineEndings($text);
|
||||
|
||||
// unfold lines. concat two lines where line 1 ends in \n and
|
||||
// line 2 starts with a whitespace character. only removes
|
||||
// the first whitespace character, leaves others in place.
|
||||
$fold_regex = '(\n)([ |\t])';
|
||||
$text = preg_replace("/$fold_regex/i", "", $text);
|
||||
|
||||
// massage for Macintosh OS X Address Book (remove nulls that
|
||||
// Address Book puts in for unicode chars)
|
||||
$text = str_replace("\x00", '', $text);
|
||||
|
||||
// convert the resulting text to an array of lines
|
||||
$lines = explode("\n", $text);
|
||||
|
||||
// parse the array of lines and return vCard info
|
||||
return $this->_fromArray($lines, $decode_qp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts line endings in text.
|
||||
*
|
||||
* Takes any text block and converts all line endings to UNIX
|
||||
* standard. DOS line endings are \r\n, Mac are \r, and UNIX is \n.
|
||||
*
|
||||
* NOTE: Acts on the text block in-place; does not return a value.
|
||||
*
|
||||
* @param string &$text The string on which to convert line endings.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function convertLineEndings(&$text)
|
||||
{
|
||||
// DOS
|
||||
$text = str_replace("\r\n", "\n", $text);
|
||||
|
||||
// Mac
|
||||
$text = str_replace("\r", "\n", $text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits a string into an array at semicolons. Honors backslash-
|
||||
* escaped semicolons (i.e., splits at ';' not '\;').
|
||||
*
|
||||
* @param string $text The string to split into an array.
|
||||
* @param boolean $convertSingle If splitting the string results in a
|
||||
* single array element, return a string instead of a one-
|
||||
* element array. Optional - defaults to false
|
||||
*
|
||||
* @access public
|
||||
* @return mixed An array of values, or a single string.
|
||||
*/
|
||||
function splitBySemi($text, $convertSingle = false)
|
||||
{
|
||||
// we use these double-backs (\\) because they get get converted
|
||||
// to single-backs (\) by preg_split. the quad-backs (\\\\) end
|
||||
// up as as double-backs (\\), which is what preg_split requires
|
||||
// to indicate a single backslash (\). what a mess.
|
||||
$regex = '(?<!\\\\)(\;)';
|
||||
$tmp = preg_split("/$regex/i", $text);
|
||||
|
||||
// if there is only one array-element and $convertSingle is
|
||||
// true, then return only the value of that one array element
|
||||
// (instead of returning the array).
|
||||
if ($convertSingle && count($tmp) == 1) {
|
||||
return $tmp[0];
|
||||
}
|
||||
return $tmp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits a string into an array at commas. Honors backslash-
|
||||
* escaped commas (i.e., splits at ',' not '\,').
|
||||
*
|
||||
* @param string $text The string to split into an array.
|
||||
* @param boolean $convertSingle If splitting the string results in a
|
||||
* single array element, return a string instead of a one-
|
||||
* element array. Optional - defaults to false.
|
||||
*
|
||||
* @access public
|
||||
* @return mixed An array of values, or a single string.
|
||||
*/
|
||||
function splitByComma($text, $convertSingle = false)
|
||||
{
|
||||
// we use these double-backs (\\) because they get get converted
|
||||
// to single-backs (\) by preg_split. the quad-backs (\\\\) end
|
||||
// up as as double-backs (\\), which is what preg_split requires
|
||||
// to indicate a single backslash (\). ye gods, how ugly.
|
||||
$regex = '(?<!\\\\)(\,)';
|
||||
$tmp = preg_split("/$regex/i", $text);
|
||||
|
||||
// if there is only one array-element and $convertSingle is
|
||||
// true, then return only the value of that one array element
|
||||
// (instead of returning the array).
|
||||
if ($convertSingle && count($tmp) == 1) {
|
||||
return $tmp[0];
|
||||
}
|
||||
return $tmp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to make string human-readable after being a vCard value.
|
||||
*
|
||||
* Converts...
|
||||
* \: => :
|
||||
* \; => ;
|
||||
* \, => ,
|
||||
* literal \n => newline
|
||||
*
|
||||
* @param mixed &$text The text to unescape.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function unescape(&$text)
|
||||
{
|
||||
if (is_array($text)) {
|
||||
foreach ($text as $key => $val) {
|
||||
$this->unescape($val);
|
||||
$text[$key] = $val;
|
||||
}
|
||||
return;
|
||||
}
|
||||
/*
|
||||
$text = str_replace('\:', ':', $text);
|
||||
$text = str_replace('\;', ';', $text);
|
||||
$text = str_replace('\,', ',', $text);
|
||||
$text = str_replace('\n', "\n", $text);
|
||||
*/
|
||||
// combined
|
||||
$find = array('\:', '\;', '\,', '\n');
|
||||
$replace = array(':', ';', ',', "\n");
|
||||
$text = str_replace($find, $replace, $text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Emulated destructor.
|
||||
*
|
||||
* @access private
|
||||
* @return boolean true
|
||||
*/
|
||||
function _Contact_Vcard_Parse()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses an array of source lines and returns an array of vCards.
|
||||
* Each element of the array is itself an array expressing the types,
|
||||
* parameters, and values of each part of the vCard. Processes both
|
||||
* 2.1 and 3.0 vCard sources.
|
||||
*
|
||||
* @param array $source An array of lines to be read for vCard
|
||||
* information.
|
||||
* @param boolean $decode_qp Optional; Decode quoted printable if true.
|
||||
* This is the default.
|
||||
*
|
||||
* @access private
|
||||
* @return array An array of of vCard information extracted from the
|
||||
* source array.
|
||||
*/
|
||||
function _fromArray($source, $decode_qp = true)
|
||||
{
|
||||
// the info array will hold all resulting vCard information.
|
||||
$info = array();
|
||||
|
||||
// tells us whether the source text indicates the beginning of a
|
||||
// new vCard with a BEGIN:VCARD tag.
|
||||
$begin = false;
|
||||
|
||||
// holds information about the current vCard being read from the
|
||||
// source text.
|
||||
$card = array();
|
||||
|
||||
// loop through each line in the source array
|
||||
foreach ($source as $line) {
|
||||
|
||||
// if the line is blank, skip it.
|
||||
if (trim($line) == '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
// find the first instance of ':' on the line. The part
|
||||
// to the left of the colon is the type and parameters;
|
||||
// the part to the right of the colon is the value data.
|
||||
$pos = strpos($line, ':');
|
||||
|
||||
// if there is no colon, skip the line.
|
||||
if ($pos === false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// get the left and right portions
|
||||
$left = trim(substr($line, 0, $pos));
|
||||
$right = trim(substr($line, $pos+1, strlen($line)));
|
||||
|
||||
// have we started yet?
|
||||
if (! $begin) {
|
||||
|
||||
// nope. does this line indicate the beginning of
|
||||
// a new vCard?
|
||||
if (strtoupper($left) == 'BEGIN' && strtoupper($right) == 'VCARD') {
|
||||
|
||||
// tell the loop that we've begun a new card
|
||||
$begin = true;
|
||||
}
|
||||
|
||||
// regardless, loop to the next line of source. if begin
|
||||
// is still false, the next loop will check the line. if
|
||||
// begin has now been set to true, the loop will start
|
||||
// collecting card info.
|
||||
continue;
|
||||
|
||||
} else {
|
||||
|
||||
// yep, we've started, but we don't know how far along
|
||||
// we are in the card. is this the ending line of the
|
||||
// current vCard?
|
||||
if (strtoupper($left) == 'END' && strtoupper($right) == 'VCARD') {
|
||||
|
||||
// yep, we're done. keep the info from the current
|
||||
// card...
|
||||
$info[] = $card;
|
||||
|
||||
// ...and reset to grab a new card if one exists in
|
||||
// the source array.
|
||||
$begin = false;
|
||||
$card = array();
|
||||
|
||||
} else {
|
||||
|
||||
// we're not on an ending line, so collect info from
|
||||
// this line into the current card. split the
|
||||
// left-portion of the line into a type-definition
|
||||
// (the kind of information) and parameters for the
|
||||
// type.
|
||||
$typedef = $this->_getTypeDef($left);
|
||||
$params = $this->_getParams($left);
|
||||
|
||||
// if we are decoding quoted-printable, do so now.
|
||||
// QUOTED-PRINTABLE is not allowed in version 3.0,
|
||||
// but we don't check for versioning, so we do it
|
||||
// regardless. ;-)
|
||||
$this->_decodeQp($params, $right);
|
||||
|
||||
// now get the value-data from the line, based on
|
||||
// the typedef
|
||||
switch ($typedef) {
|
||||
|
||||
case 'N':
|
||||
// structured name of the person
|
||||
$value = $this->_parseN($right);
|
||||
break;
|
||||
|
||||
case 'ADR':
|
||||
// structured address of the person
|
||||
$value = $this->_parseADR($right);
|
||||
break;
|
||||
|
||||
case 'NICKNAME':
|
||||
// nicknames
|
||||
$value = $this->_parseNICKNAME($right);
|
||||
break;
|
||||
|
||||
case 'ORG':
|
||||
// organizations the person belongs to
|
||||
$value = $this->_parseORG($right);
|
||||
break;
|
||||
|
||||
case 'CATEGORIES':
|
||||
// categories to which this card is assigned
|
||||
$value = $this->_parseCATEGORIES($right);
|
||||
break;
|
||||
|
||||
case 'GEO':
|
||||
// geographic coordinates
|
||||
$value = $this->_parseGEO($right);
|
||||
break;
|
||||
|
||||
default:
|
||||
// by default, just grab the plain value. keep
|
||||
// as an array to make sure *all* values are
|
||||
// arrays. for consistency. ;-)
|
||||
if (preg_match('/ITEM[0-9]*\.ADR/', $typedef)) {
|
||||
$value = $this->_parseADR($right);
|
||||
} else {
|
||||
$value = array(array($right));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// add the type, parameters, and value to the
|
||||
// current card array. note that we allow multiple
|
||||
// instances of the same type, which might be dumb
|
||||
// in some cases (e.g., N).
|
||||
$card[$typedef][] = array(
|
||||
'param' => $params,
|
||||
'value' => $value
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->unescape($info);
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes a vCard line and extracts the Type-Definition for the line.
|
||||
*
|
||||
* @param string $text A left-part (before-the-colon part) from a
|
||||
* vCard line.
|
||||
*
|
||||
* @access private
|
||||
* @return string The type definition for the line.
|
||||
*
|
||||
*/
|
||||
function _getTypeDef($text)
|
||||
{
|
||||
// split the text by semicolons
|
||||
$split = $this->splitBySemi($text);
|
||||
|
||||
// only return first element (the typedef)
|
||||
return strtoupper($split[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the Type-Definition parameters for a vCard line.
|
||||
*
|
||||
* @param string $text A left-part (before-the-colon part) from a
|
||||
* vCard line.
|
||||
*
|
||||
* @access private
|
||||
* @return mixed An array of parameters.
|
||||
*/
|
||||
function _getParams($text)
|
||||
{
|
||||
// split the text by semicolons into an array
|
||||
$split = $this->splitBySemi($text);
|
||||
|
||||
// drop the first element of the array (the type-definition)
|
||||
array_shift($split);
|
||||
|
||||
// set up an array to retain the parameters, if any
|
||||
$params = array();
|
||||
|
||||
// loop through each parameter. the params may be in the format...
|
||||
// "TYPE=type1,type2,type3"
|
||||
// ...or...
|
||||
// "TYPE=type1;TYPE=type2;TYPE=type3"
|
||||
foreach ($split as $full) {
|
||||
|
||||
// split the full parameter at the equal sign so we can tell
|
||||
// the parameter name from the parameter value
|
||||
$tmp = explode("=", $full);
|
||||
|
||||
// the key is the left portion of the parameter (before
|
||||
// '='). if in 2.1 format, the key may in fact be the
|
||||
// parameter value, not the parameter name.
|
||||
$key = strtoupper(trim($tmp[0]));
|
||||
|
||||
// list of all parameter values
|
||||
if (!isset($tmp[1])) {
|
||||
|
||||
// Parameter value without key - default to 'TYPE=<value>'
|
||||
$list = array($key);
|
||||
$name = 'TYPE';
|
||||
|
||||
} else {
|
||||
|
||||
// get the parameter name by checking to see if it's in
|
||||
// vCard 2.1 or 3.0 format.
|
||||
$name = $this->_getParamName($key);
|
||||
|
||||
// list of all parameter values
|
||||
if (isset($tmp[1])) {
|
||||
$listall = trim($tmp[1]);
|
||||
} else {
|
||||
$listall = '';
|
||||
}
|
||||
|
||||
// if there is a value-list for this parameter, they are
|
||||
// separated by commas, so split them out too.
|
||||
$list = $this->splitByComma($listall);
|
||||
|
||||
}
|
||||
|
||||
// now loop through each value in the parameter and retain
|
||||
// it. if the value is blank, that means it's a 2.1-style
|
||||
// param, and the key itself is the value.
|
||||
foreach ($list as $val) {
|
||||
if (trim($val) != '') {
|
||||
// 3.0 formatted parameter
|
||||
$params[$name][] = trim($val);
|
||||
} else {
|
||||
// 2.1 formatted parameter
|
||||
$params[$name][] = $key;
|
||||
}
|
||||
}
|
||||
|
||||
// if, after all this, there are no parameter values for the
|
||||
// parameter name, retain no info about the parameter (saves
|
||||
// ram and checking-time later).
|
||||
if (count($params[$name]) == 0) {
|
||||
unset($params[$name]);
|
||||
}
|
||||
}
|
||||
|
||||
// return the parameters array.
|
||||
return $params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Looks at the parameters of a vCard line; if one of them is
|
||||
* ENCODING[] => QUOTED-PRINTABLE then decode the text in-place.
|
||||
*
|
||||
* @param array &$params A parameter array from a vCard line.
|
||||
* @param string &$text A right-part (after-the-colon part) from a
|
||||
* vCard line.
|
||||
*
|
||||
* @access private
|
||||
* @return void
|
||||
*/
|
||||
function _decodeQp(&$params, &$text)
|
||||
{
|
||||
// loop through each parameter
|
||||
foreach ($params as $param_key => $param_val) {
|
||||
|
||||
// check to see if it's an encoding param
|
||||
if (trim(strtoupper($param_key)) != 'ENCODING') {
|
||||
continue;
|
||||
}
|
||||
|
||||
// loop through each encoding param value
|
||||
foreach ($param_val as $enc_key => $enc_val) {
|
||||
|
||||
// if any of the values are QP, decode the text
|
||||
// in-place and return
|
||||
$enc_val = trim(strtoupper($enc_val));
|
||||
if ($enc_val == 'QUOTED-PRINTABLE') {
|
||||
$text = quoted_printable_decode($text);
|
||||
return;
|
||||
}
|
||||
if ($enc_val == 'BASE64') {
|
||||
$text = base64_decode($text);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns parameter names from 2.1-formatted vCards.
|
||||
*
|
||||
* The vCard 2.1 specification allows parameter values without a
|
||||
* name. The parameter name is then determined from the unique
|
||||
* parameter value.
|
||||
*
|
||||
* Shamelessly lifted from Frank Hellwig <frank@hellwig.org> and his
|
||||
* vCard PHP project <http://vcardphp.sourceforge.net>.
|
||||
*
|
||||
* @param string $value The first element in a parameter name-value
|
||||
* pair.
|
||||
*
|
||||
* @access private
|
||||
* @return string The proper parameter name (TYPE, ENCODING, or
|
||||
* VALUE).
|
||||
*/
|
||||
function _getParamName($value)
|
||||
{
|
||||
static $types = array (
|
||||
'DOM', 'INTL', 'POSTAL', 'PARCEL','HOME', 'WORK',
|
||||
'PREF', 'VOICE', 'FAX', 'MSG', 'CELL', 'PAGER',
|
||||
'BBS', 'MODEM', 'CAR', 'ISDN', 'VIDEO',
|
||||
'AOL', 'APPLELINK', 'ATTMAIL', 'CIS', 'EWORLD',
|
||||
'INTERNET', 'IBMMAIL', 'MCIMAIL',
|
||||
'POWERSHARE', 'PRODIGY', 'TLX', 'X400',
|
||||
'GIF', 'CGM', 'WMF', 'BMP', 'MET', 'PMB', 'DIB',
|
||||
'PICT', 'TIFF', 'PDF', 'PS', 'JPEG', 'QTIME',
|
||||
'MPEG', 'MPEG2', 'AVI',
|
||||
'WAVE', 'AIFF', 'PCM',
|
||||
'X509', 'PGP'
|
||||
);
|
||||
|
||||
// CONTENT-ID added by pmj
|
||||
static $values = array (
|
||||
'INLINE', 'URL', 'CID', 'CONTENT-ID'
|
||||
);
|
||||
|
||||
// 8BIT added by pmj
|
||||
static $encodings = array (
|
||||
'7BIT', '8BIT', 'QUOTED-PRINTABLE', 'BASE64'
|
||||
);
|
||||
|
||||
// changed by pmj to the following so that the name defaults to
|
||||
// whatever the original value was. Frank Hellwig's original
|
||||
// code was "$name = 'UNKNOWN'".
|
||||
$name = $value;
|
||||
|
||||
if (in_array($value, $types)) {
|
||||
$name = 'TYPE';
|
||||
} elseif (in_array($value, $values)) {
|
||||
$name = 'VALUE';
|
||||
} elseif (in_array($value, $encodings)) {
|
||||
$name = 'ENCODING';
|
||||
}
|
||||
return $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a vCard line value identified as being of the "N"
|
||||
* (structured name) type-defintion.
|
||||
*
|
||||
* @param string $text The right-part (after-the-colon part) of a
|
||||
* vCard line.
|
||||
*
|
||||
* @access private
|
||||
* @return array An array of key-value pairs where the key is the
|
||||
* portion-name and the value is the portion-value. The value
|
||||
* itself may be an array as well if multiple comma-separated
|
||||
* values were indicated in the vCard source.
|
||||
*/
|
||||
function _parseN($text)
|
||||
{
|
||||
// make sure there are always at least 5 elements
|
||||
$tmp = array_pad($this->splitBySemi($text), 5, '');
|
||||
return array(
|
||||
$this->splitByComma($tmp[0]), // family (last)
|
||||
$this->splitByComma($tmp[1]), // given (first)
|
||||
$this->splitByComma($tmp[2]), // addl (middle)
|
||||
$this->splitByComma($tmp[3]), // prefix
|
||||
$this->splitByComma($tmp[4]) // suffix
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parses a vCard line value identified as being of the "ADR"
|
||||
* (structured address) type-defintion.
|
||||
*
|
||||
* @param string $text The right-part (after-the-colon part) of a
|
||||
* vCard line.
|
||||
*
|
||||
* @access private
|
||||
* @return array An array of key-value pairs where the key is the
|
||||
* portion-name and the value is the portion-value. The
|
||||
* value itself may be an array as well if multiple comma-
|
||||
* separated values were indicated in the vCard source.
|
||||
*/
|
||||
function _parseADR($text)
|
||||
{
|
||||
// make sure there are always at least 7 elements
|
||||
$tmp = array_pad($this->splitBySemi($text), 7, '');
|
||||
return array(
|
||||
$this->splitByComma($tmp[0]), // pob
|
||||
$this->splitByComma($tmp[1]), // extend
|
||||
$this->splitByComma($tmp[2]), // street
|
||||
$this->splitByComma($tmp[3]), // locality (city)
|
||||
$this->splitByComma($tmp[4]), // region (state)
|
||||
$this->splitByComma($tmp[5]), // postcode (ZIP)
|
||||
$this->splitByComma($tmp[6]) // country
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parses a vCard line value identified as being of the "NICKNAME"
|
||||
* (informal or descriptive name) type-defintion.
|
||||
*
|
||||
* @param string $text The right-part (after-the-colon part) of a
|
||||
* vCard line.
|
||||
*
|
||||
* @access private
|
||||
* @return array An array of nicknames.
|
||||
*/
|
||||
function _parseNICKNAME($text)
|
||||
{
|
||||
return array($this->splitByComma($text));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parses a vCard line value identified as being of the "ORG"
|
||||
* (organizational info) type-defintion.
|
||||
*
|
||||
* @param string $text The right-part (after-the-colon part) of a
|
||||
* vCard line.
|
||||
*
|
||||
* @access private
|
||||
* @return array An array of organizations; each element of the array
|
||||
* is itself an array, which indicates primary organization and
|
||||
* sub-organizations.
|
||||
*/
|
||||
function _parseORG($text)
|
||||
{
|
||||
$tmp = $this->splitbySemi($text);
|
||||
$list = array();
|
||||
foreach ($tmp as $val) {
|
||||
$list[] = array($val);
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a vCard line value identified as being of the "CATEGORIES"
|
||||
* (card-category) type-defintion.
|
||||
*
|
||||
* @param string $text The right-part (after-the-colon part) of a
|
||||
* vCard line.
|
||||
*
|
||||
* @access private
|
||||
* @return array An array of categories.
|
||||
*/
|
||||
function _parseCATEGORIES($text)
|
||||
{
|
||||
return array($this->splitByComma($text));
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a vCard line value identified as being of the "GEO"
|
||||
* (geographic coordinate) type-defintion.
|
||||
*
|
||||
* @param string $text The right-part (after-the-colon part) of a
|
||||
* vCard line.
|
||||
*
|
||||
* @access private
|
||||
* @return array An array of lat-lon geocoords.
|
||||
*/
|
||||
function _parseGEO($text)
|
||||
{
|
||||
// make sure there are always at least 2 elements
|
||||
$tmp = array_pad($this->splitBySemi($text), 2, '');
|
||||
return array(
|
||||
array($tmp[0]), // lat
|
||||
array($tmp[1]) // lon
|
||||
);
|
||||
}
|
||||
}
|
||||
?>
|
||||
1505
sites/all/modules/civicrm/packages/DB.php
Normal file
1505
sites/all/modules/civicrm/packages/DB.php
Normal file
File diff suppressed because it is too large
Load diff
4357
sites/all/modules/civicrm/packages/DB/DataObject.php
Normal file
4357
sites/all/modules/civicrm/packages/DB/DataObject.php
Normal file
File diff suppressed because it is too large
Load diff
549
sites/all/modules/civicrm/packages/DB/DataObject/Cast.php
Normal file
549
sites/all/modules/civicrm/packages/DB/DataObject/Cast.php
Normal file
|
|
@ -0,0 +1,549 @@
|
|||
<?php
|
||||
/**
|
||||
* Prototype Castable Object.. for DataObject queries
|
||||
*
|
||||
* Storage for Data that may be cast into a variety of formats.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt. If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category Database
|
||||
* @package DB_DataObject
|
||||
* @author Alan Knowles <alan@akbkhome.com>
|
||||
* @copyright 1997-2008 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: Cast.php 287158 2009-08-12 13:58:31Z alan_k $
|
||||
* @link http://pear.php.net/package/DB_DataObject
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* Common usages:
|
||||
* // blobs
|
||||
* $data = DB_DataObject_Cast::blob($somefile);
|
||||
* $data = DB_DataObject_Cast::string($somefile);
|
||||
* $dataObject->someblobfield = $data
|
||||
*
|
||||
* // dates?
|
||||
* $d1 = new DB_DataObject_Cast::date('12/12/2000');
|
||||
* $d2 = new DB_DataObject_Cast::date(2000,12,30);
|
||||
* $d3 = new DB_DataObject_Cast::date($d1->year, $d1->month+30, $d1->day+30);
|
||||
*
|
||||
* // time, datetime.. ?????????
|
||||
*
|
||||
* // raw sql????
|
||||
* $data = DB_DataObject_Cast::sql('cast("123123",datetime)');
|
||||
* $data = DB_DataObject_Cast::sql('NULL');
|
||||
*
|
||||
* // int's/string etc. are proably pretty pointless..!!!!
|
||||
*
|
||||
*
|
||||
* inside DB_DataObject,
|
||||
* if (is_a($v,'db_dataobject_class')) {
|
||||
* $value .= $v->toString(DB_DATAOBJECT_INT,'mysql');
|
||||
* }
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
|
||||
*/
|
||||
class DB_DataObject_Cast {
|
||||
|
||||
/**
|
||||
* Type of data Stored in the object..
|
||||
*
|
||||
* @var string (date|blob|.....?)
|
||||
* @access public
|
||||
*/
|
||||
var $type;
|
||||
|
||||
/**
|
||||
* Data For date representation
|
||||
*
|
||||
* @var int day/month/year
|
||||
* @access public
|
||||
*/
|
||||
var $day;
|
||||
var $month;
|
||||
var $year;
|
||||
|
||||
|
||||
/**
|
||||
* Generic Data..
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
|
||||
var $value;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Blob consructor
|
||||
*
|
||||
* create a Cast object from some raw data.. (binary)
|
||||
*
|
||||
*
|
||||
* @param string (with binary data!)
|
||||
*
|
||||
* @return object DB_DataObject_Cast
|
||||
* @access public
|
||||
*/
|
||||
|
||||
function blob($value) {
|
||||
$r = new DB_DataObject_Cast;
|
||||
$r->type = 'blob';
|
||||
$r->value = $value;
|
||||
return $r;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* String consructor (actually use if for ints and everything else!!!
|
||||
*
|
||||
* create a Cast object from some string (not binary)
|
||||
*
|
||||
*
|
||||
* @param string (with binary data!)
|
||||
*
|
||||
* @return object DB_DataObject_Cast
|
||||
* @access public
|
||||
*/
|
||||
|
||||
function string($value) {
|
||||
$r = new DB_DataObject_Cast;
|
||||
$r->type = 'string';
|
||||
$r->value = $value;
|
||||
return $r;
|
||||
}
|
||||
|
||||
/**
|
||||
* SQL constructor (for raw SQL insert)
|
||||
*
|
||||
* create a Cast object from some sql
|
||||
*
|
||||
* @param string (with binary data!)
|
||||
*
|
||||
* @return object DB_DataObject_Cast
|
||||
* @access public
|
||||
*/
|
||||
|
||||
function sql($value)
|
||||
{
|
||||
$r = new DB_DataObject_Cast;
|
||||
$r->type = 'sql';
|
||||
$r->value = $value;
|
||||
return $r;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Date Constructor
|
||||
*
|
||||
* create a Cast object from some string (not binary)
|
||||
* NO VALIDATION DONE, although some crappy re-calcing done!
|
||||
*
|
||||
* @param vargs... accepts
|
||||
* dd/mm
|
||||
* dd/mm/yyyy
|
||||
* yyyy-mm
|
||||
* yyyy-mm-dd
|
||||
* array(yyyy,dd)
|
||||
* array(yyyy,dd,mm)
|
||||
*
|
||||
*
|
||||
*
|
||||
* @return object DB_DataObject_Cast
|
||||
* @access public
|
||||
*/
|
||||
|
||||
function date()
|
||||
{
|
||||
$args = func_get_args();
|
||||
switch(count($args)) {
|
||||
case 0: // no args = today!
|
||||
$bits = explode('-',date('Y-m-d'));
|
||||
break;
|
||||
case 1: // one arg = a string
|
||||
|
||||
if (strpos($args[0],'/') !== false) {
|
||||
$bits = array_reverse(explode('/',$args[0]));
|
||||
} else {
|
||||
$bits = explode('-',$args[0]);
|
||||
}
|
||||
break;
|
||||
default: // 2 or more..
|
||||
$bits = $args;
|
||||
}
|
||||
if (count($bits) == 1) { // if YYYY set day = 1st..
|
||||
$bits[] = 1;
|
||||
}
|
||||
|
||||
if (count($bits) == 2) { // if YYYY-DD set day = 1st..
|
||||
$bits[] = 1;
|
||||
}
|
||||
|
||||
// if year < 1970 we cant use system tools to check it...
|
||||
// so we make a few best gueses....
|
||||
// basically do date calculations for the year 2000!!!
|
||||
// fix me if anyone has more time...
|
||||
if (($bits[0] < 1975) || ($bits[0] > 2030)) {
|
||||
$oldyear = $bits[0];
|
||||
$bits = explode('-',date('Y-m-d',mktime(1,1,1,$bits[1],$bits[2],2000)));
|
||||
$bits[0] = ($bits[0] - 2000) + $oldyear;
|
||||
} else {
|
||||
// now mktime
|
||||
$bits = explode('-',date('Y-m-d',mktime(1,1,1,$bits[1],$bits[2],$bits[0])));
|
||||
}
|
||||
$r = new DB_DataObject_Cast;
|
||||
$r->type = 'date';
|
||||
list($r->year,$r->month,$r->day) = $bits;
|
||||
return $r;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Data For time representation ** does not handle timezones!!
|
||||
*
|
||||
* @var int hour/minute/second
|
||||
* @access public
|
||||
*/
|
||||
var $hour;
|
||||
var $minute;
|
||||
var $second;
|
||||
|
||||
|
||||
/**
|
||||
* DateTime Constructor
|
||||
*
|
||||
* create a Cast object from a Date/Time
|
||||
* Maybe should accept a Date object.!
|
||||
* NO VALIDATION DONE, although some crappy re-calcing done!
|
||||
*
|
||||
* @param vargs... accepts
|
||||
* noargs (now)
|
||||
* yyyy-mm-dd HH:MM:SS (Iso)
|
||||
* array(yyyy,mm,dd,HH,MM,SS)
|
||||
*
|
||||
*
|
||||
* @return object DB_DataObject_Cast
|
||||
* @access public
|
||||
* @author therion 5 at hotmail
|
||||
*/
|
||||
|
||||
function dateTime()
|
||||
{
|
||||
$args = func_get_args();
|
||||
switch(count($args)) {
|
||||
case 0: // no args = now!
|
||||
$datetime = date('Y-m-d G:i:s', mktime());
|
||||
|
||||
case 1:
|
||||
// continue on from 0 args.
|
||||
if (!isset($datetime)) {
|
||||
$datetime = $args[0];
|
||||
}
|
||||
|
||||
$parts = explode(' ', $datetime);
|
||||
$bits = explode('-', $parts[0]);
|
||||
$bits = array_merge($bits, explode(':', $parts[1]));
|
||||
break;
|
||||
|
||||
default: // 2 or more..
|
||||
$bits = $args;
|
||||
|
||||
}
|
||||
|
||||
if (count($bits) != 6) {
|
||||
// PEAR ERROR?
|
||||
return false;
|
||||
}
|
||||
|
||||
$r = DB_DataObject_Cast::date($bits[0], $bits[1], $bits[2]);
|
||||
if (!$r) {
|
||||
return $r; // pass thru error (False) - doesnt happen at present!
|
||||
}
|
||||
// change the type!
|
||||
$r->type = 'datetime';
|
||||
|
||||
// should we mathematically sort this out..
|
||||
// (or just assume that no-one's dumb enough to enter 26:90:90 as a time!
|
||||
$r->hour = $bits[3];
|
||||
$r->minute = $bits[4];
|
||||
$r->second = $bits[5];
|
||||
return $r;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* time Constructor
|
||||
*
|
||||
* create a Cast object from a Date/Time
|
||||
* Maybe should accept a Date object.!
|
||||
* NO VALIDATION DONE, and no-recalcing done!
|
||||
*
|
||||
* @param vargs... accepts
|
||||
* noargs (now)
|
||||
* HH:MM:SS (Iso)
|
||||
* array(HH,MM,SS)
|
||||
*
|
||||
*
|
||||
* @return object DB_DataObject_Cast
|
||||
* @access public
|
||||
* @author therion 5 at hotmail
|
||||
*/
|
||||
function time()
|
||||
{
|
||||
$args = func_get_args();
|
||||
switch (count($args)) {
|
||||
case 0: // no args = now!
|
||||
$time = date('G:i:s', mktime());
|
||||
|
||||
case 1:
|
||||
// continue on from 0 args.
|
||||
if (!isset($time)) {
|
||||
$time = $args[0];
|
||||
}
|
||||
$bits = explode(':', $time);
|
||||
break;
|
||||
|
||||
default: // 2 or more..
|
||||
$bits = $args;
|
||||
|
||||
}
|
||||
|
||||
if (count($bits) != 3) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// now take data from bits into object fields
|
||||
$r = new DB_DataObject_Cast;
|
||||
$r->type = 'time';
|
||||
$r->hour = $bits[0];
|
||||
$r->minute = $bits[1];
|
||||
$r->second = $bits[2];
|
||||
return $r;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* get the string to use in the SQL statement for this...
|
||||
*
|
||||
*
|
||||
* @param int $to Type (DB_DATAOBJECT_*
|
||||
* @param object $db DB Connection Object
|
||||
*
|
||||
*
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
|
||||
function toString($to=false,$db)
|
||||
{
|
||||
// if $this->type is not set, we are in serious trouble!!!!
|
||||
// values for to:
|
||||
$method = 'toStringFrom'.$this->type;
|
||||
return $this->$method($to,$db);
|
||||
}
|
||||
|
||||
/**
|
||||
* get the string to use in the SQL statement from a blob of binary data
|
||||
* ** Suppots only blob->postgres::bytea
|
||||
*
|
||||
* @param int $to Type (DB_DATAOBJECT_*
|
||||
* @param object $db DB Connection Object
|
||||
*
|
||||
*
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
function toStringFromBlob($to,$db)
|
||||
{
|
||||
// first weed out invalid casts..
|
||||
// in blobs can only be cast to blobs.!
|
||||
|
||||
// perhaps we should support TEXT fields???
|
||||
|
||||
if (!($to & DB_DATAOBJECT_BLOB)) {
|
||||
return PEAR::raiseError('Invalid Cast from a DB_DataObject_Cast::blob to something other than a blob!');
|
||||
}
|
||||
|
||||
switch ($db->dsn["phptype"]) {
|
||||
case 'pgsql':
|
||||
return "'".pg_escape_bytea($this->value)."'::bytea";
|
||||
|
||||
case 'mysql':
|
||||
return "'".mysql_real_escape_string($this->value,$db->connection)."'";
|
||||
|
||||
case 'mysqli':
|
||||
// this is funny - the parameter order is reversed ;)
|
||||
return "'".mysqli_real_escape_string($db->connection, $this->value)."'";
|
||||
|
||||
case 'sqlite':
|
||||
// this is funny - the parameter order is reversed ;)
|
||||
return "'".sqlite_escape_string($this->value)."'";
|
||||
|
||||
|
||||
default:
|
||||
return PEAR::raiseError("DB_DataObject_Cast cant handle blobs for Database:{$db->dsn['phptype']} Yet");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* get the string to use in the SQL statement for a blob from a string!
|
||||
* ** Suppots only string->postgres::bytea
|
||||
*
|
||||
*
|
||||
* @param int $to Type (DB_DATAOBJECT_*
|
||||
* @param object $db DB Connection Object
|
||||
*
|
||||
*
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
function toStringFromString($to,$db)
|
||||
{
|
||||
// first weed out invalid casts..
|
||||
// in blobs can only be cast to blobs.!
|
||||
|
||||
// perhaps we should support TEXT fields???
|
||||
//
|
||||
|
||||
if (!($to & DB_DATAOBJECT_BLOB)) {
|
||||
return PEAR::raiseError('Invalid Cast from a DB_DataObject_Cast::string to something other than a blob!'.
|
||||
' (why not just use native features)');
|
||||
}
|
||||
|
||||
switch ($db->dsn['phptype']) {
|
||||
case 'pgsql':
|
||||
return "'".pg_escape_string($this->value)."'::bytea";
|
||||
|
||||
case 'mysql':
|
||||
return "'".mysql_real_escape_string($this->value,$db->connection)."'";
|
||||
|
||||
|
||||
case 'mysqli':
|
||||
return "'".mysqli_real_escape_string($db->connection, $this->value)."'";
|
||||
|
||||
|
||||
default:
|
||||
return PEAR::raiseError("DB_DataObject_Cast cant handle blobs for Database:{$db->dsn['phptype']} Yet");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get the string to use in the SQL statement for a date
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param int $to Type (DB_DATAOBJECT_*
|
||||
* @param object $db DB Connection Object
|
||||
*
|
||||
*
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
function toStringFromDate($to,$db)
|
||||
{
|
||||
// first weed out invalid casts..
|
||||
// in blobs can only be cast to blobs.!
|
||||
// perhaps we should support TEXT fields???
|
||||
//
|
||||
|
||||
if (($to !== false) && !($to & DB_DATAOBJECT_DATE)) {
|
||||
return PEAR::raiseError('Invalid Cast from a DB_DataObject_Cast::string to something other than a date!'.
|
||||
' (why not just use native features)');
|
||||
}
|
||||
return "'{$this->year}-{$this->month}-{$this->day}'";
|
||||
}
|
||||
|
||||
/**
|
||||
* get the string to use in the SQL statement for a datetime
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param int $to Type (DB_DATAOBJECT_*
|
||||
* @param object $db DB Connection Object
|
||||
*
|
||||
*
|
||||
* @return string
|
||||
* @access public
|
||||
* @author therion 5 at hotmail
|
||||
*/
|
||||
|
||||
function toStringFromDateTime($to,$db)
|
||||
{
|
||||
// first weed out invalid casts..
|
||||
// in blobs can only be cast to blobs.!
|
||||
// perhaps we should support TEXT fields???
|
||||
if (($to !== false) &&
|
||||
!($to & (DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME))) {
|
||||
return PEAR::raiseError('Invalid Cast from a ' .
|
||||
' DB_DataObject_Cast::dateTime to something other than a datetime!' .
|
||||
' (try using native features)');
|
||||
}
|
||||
return "'{$this->year}-{$this->month}-{$this->day} {$this->hour}:{$this->minute}:{$this->second}'";
|
||||
}
|
||||
|
||||
/**
|
||||
* get the string to use in the SQL statement for a time
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param int $to Type (DB_DATAOBJECT_*
|
||||
* @param object $db DB Connection Object
|
||||
*
|
||||
*
|
||||
* @return string
|
||||
* @access public
|
||||
* @author therion 5 at hotmail
|
||||
*/
|
||||
|
||||
function toStringFromTime($to,$db)
|
||||
{
|
||||
// first weed out invalid casts..
|
||||
// in blobs can only be cast to blobs.!
|
||||
// perhaps we should support TEXT fields???
|
||||
if (($to !== false) && !($to & DB_DATAOBJECT_TIME)) {
|
||||
return PEAR::raiseError('Invalid Cast from a' .
|
||||
' DB_DataObject_Cast::time to something other than a time!'.
|
||||
' (try using native features)');
|
||||
}
|
||||
return "'{$this->hour}:{$this->minute}:{$this->second}'";
|
||||
}
|
||||
|
||||
/**
|
||||
* get the string to use in the SQL statement for a raw sql statement.
|
||||
*
|
||||
* @param int $to Type (DB_DATAOBJECT_*
|
||||
* @param object $db DB Connection Object
|
||||
*
|
||||
*
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
function toStringFromSql($to,$db)
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
53
sites/all/modules/civicrm/packages/DB/DataObject/Error.php
Normal file
53
sites/all/modules/civicrm/packages/DB/DataObject/Error.php
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
/**
|
||||
* DataObjects error handler, loaded on demand...
|
||||
*
|
||||
* DB_DataObject_Error is a quick wrapper around pear error, so you can distinguish the
|
||||
* error code source.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt. If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category Database
|
||||
* @package DB_DataObject
|
||||
* @author Alan Knowles <alan@akbkhome.com>
|
||||
* @copyright 1997-2006 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: Error.php 287158 2009-08-12 13:58:31Z alan_k $
|
||||
* @link http://pear.php.net/package/DB_DataObject
|
||||
*/
|
||||
|
||||
|
||||
class DB_DataObject_Error extends PEAR_Error
|
||||
{
|
||||
|
||||
/**
|
||||
* DB_DataObject_Error constructor.
|
||||
*
|
||||
* @param mixed $code DB error code, or string with error message.
|
||||
* @param integer $mode what "error mode" to operate in
|
||||
* @param integer $level what error level to use for $mode & PEAR_ERROR_TRIGGER
|
||||
* @param mixed $debuginfo additional debug info, such as the last query
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @see PEAR_Error
|
||||
*/
|
||||
function __construct($message = '', $code = DB_ERROR, $mode = PEAR_ERROR_RETURN,
|
||||
$level = E_USER_NOTICE)
|
||||
{
|
||||
parent::__construct('DB_DataObject Error: ' . $message, $code, $mode, $level);
|
||||
|
||||
}
|
||||
|
||||
|
||||
// todo : - support code -> message handling, and translated error messages...
|
||||
|
||||
|
||||
|
||||
}
|
||||
1571
sites/all/modules/civicrm/packages/DB/DataObject/Generator.php
Normal file
1571
sites/all/modules/civicrm/packages/DB/DataObject/Generator.php
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -0,0 +1,59 @@
|
|||
#!/usr/bin/php -q
|
||||
<?php
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Alan Knowles <alan@akbkhome.com>
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: createTables.php 277015 2009-03-12 05:51:03Z alan_k $
|
||||
//
|
||||
|
||||
// since this version doesnt use overload,
|
||||
// and I assume anyone using custom generators should add this..
|
||||
|
||||
define('DB_DATAOBJECT_NO_OVERLOAD',1);
|
||||
|
||||
//require_once 'DB/DataObject/Generator.php';
|
||||
require_once 'DB/DataObject/Generator.php';
|
||||
|
||||
if (!ini_get('register_argc_argv')) {
|
||||
PEAR::raiseError("\nERROR: You must turn register_argc_argv On in you php.ini file for this to work\neg.\n\nregister_argc_argv = On\n\n", null, PEAR_ERROR_DIE);
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!@$_SERVER['argv'][1]) {
|
||||
PEAR::raiseError("\nERROR: createTable.php usage:\n\nC:\php\pear\DB\DataObjects\createTable.php example.ini\n\n", null, PEAR_ERROR_DIE);
|
||||
exit;
|
||||
}
|
||||
|
||||
$config = parse_ini_file($_SERVER['argv'][1], true);
|
||||
foreach($config as $class=>$values) {
|
||||
$options = PEAR::getStaticProperty($class,'options');
|
||||
$options = $values;
|
||||
}
|
||||
|
||||
|
||||
$options = PEAR::getStaticProperty('DB_DataObject','options');
|
||||
if (empty($options)) {
|
||||
PEAR::raiseError("\nERROR: could not read ini file\n\n", null, PEAR_ERROR_DIE);
|
||||
exit;
|
||||
}
|
||||
set_time_limit(0);
|
||||
|
||||
// use debug level from file if set..
|
||||
DB_DataObject::debugLevel(isset($options['debug']) ? $options['debug'] : 1);
|
||||
|
||||
$generator = new DB_DataObject_Generator;
|
||||
$generator->start();
|
||||
|
||||
2334
sites/all/modules/civicrm/packages/DB/Table.php
Normal file
2334
sites/all/modules/civicrm/packages/DB/Table.php
Normal file
File diff suppressed because it is too large
Load diff
755
sites/all/modules/civicrm/packages/DB/Table/Base.php
Normal file
755
sites/all/modules/civicrm/packages/DB/Table/Base.php
Normal file
|
|
@ -0,0 +1,755 @@
|
|||
<?php
|
||||
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* DB_Table_Base Base class for DB_Table and DB_Table_Database
|
||||
*
|
||||
* This utility class contains properties and methods that are common
|
||||
* to DB_Table and DB_Table database. These are all related to one of:
|
||||
* - DB/MDB2 connection object [ $db and $backend properties ]
|
||||
* - Error handling [ throwError() method, $error and $_primary_subclass ]
|
||||
* - SELECT queries [ select*() methods, $sql & $fetchmode* properties]
|
||||
* - buildSQL() and quote() SQL utilities
|
||||
* - _swapModes() method
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE:
|
||||
*
|
||||
* Copyright (c) 1997-2007, Paul M. Jones <pmjones@php.net>
|
||||
* David C. Morse <morse@php.net>
|
||||
* Mark Wiesemann <wiesemann@php.net>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * The names of the authors may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @category Database
|
||||
* @package DB_Table
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
* @author David C. Morse <morse@php.net>
|
||||
* @author Mark Wiesemann <wiesemann@php.net>
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version CVS: $Id: Base.php,v 1.4 2007/12/13 16:52:14 wiesemann Exp $
|
||||
* @link http://pear.php.net/package/DB_Table
|
||||
*/
|
||||
|
||||
require_once 'PEAR.php';
|
||||
|
||||
// {{{ DB_Table_Base
|
||||
|
||||
/**
|
||||
* Base class for DB_Table and DB_Table_Database
|
||||
*
|
||||
* @category Database
|
||||
* @package DB_Table
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
* @author David C. Morse <morse@php.net>
|
||||
* @author Mark Wiesemann <wiesemann@php.net>
|
||||
* @version Release: 1.5.6
|
||||
* @link http://pear.php.net/package/DB_Table
|
||||
*/
|
||||
class DB_Table_Base
|
||||
{
|
||||
|
||||
// {{{ properties
|
||||
|
||||
/**
|
||||
* The PEAR DB/MDB2 object that connects to the database.
|
||||
*
|
||||
* @var object
|
||||
* @access public
|
||||
*/
|
||||
var $db = null;
|
||||
|
||||
/**
|
||||
* The backend type, which must be 'db' or 'mdb2'
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $backend = null;
|
||||
|
||||
/**
|
||||
* If there is an error on instantiation, this captures that error.
|
||||
*
|
||||
* This property is used only for errors encountered in the constructor
|
||||
* at instantiation time. To check if there was an instantiation error...
|
||||
*
|
||||
* <code>
|
||||
* $obj = new DB_Table_*();
|
||||
* if ($obj->error) {
|
||||
* // ... error handling code here ...
|
||||
* }
|
||||
* </code>
|
||||
*
|
||||
* @var object PEAR_Error
|
||||
* @access public
|
||||
*/
|
||||
var $error = null;
|
||||
|
||||
/**
|
||||
* Baseline SELECT maps for buildSQL() and select*() methods.
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $sql = array();
|
||||
|
||||
/**
|
||||
* Format of rows in sets returned by the select() method
|
||||
*
|
||||
* This should be one of the DB/MDB2_FETCHMODE_* constant values, such as
|
||||
* MDB2_FETCHMODE_ASSOC, MDB2_FETCHMODE_ORDERED, or MDB2_FETCHMODE_OBJECT.
|
||||
* It determines whether select() returns represents individual rows as
|
||||
* associative arrays with column name keys, ordered/sequential arrays,
|
||||
* or objects with column names mapped to properties. Use corresponding
|
||||
* DB_FETCHMODE_* constants for use with the DB backend. It has no effect
|
||||
* upon the return value of selectResult().
|
||||
*
|
||||
* If a 'fetchmode' element is set for a specific query array, the query
|
||||
* fetchmode will override this DB_Table or DB_Table_Database property.
|
||||
* If no value is set for the query or the DB_Table_Base object, the value
|
||||
* or default set in the underlying DB/MDB2 object will be used.
|
||||
*
|
||||
* @var int
|
||||
* @access public
|
||||
*/
|
||||
var $fetchmode = null;
|
||||
|
||||
/**
|
||||
* Class of objects to use for rows returned as objects by select()
|
||||
*
|
||||
* When fetchmode is DB/MDB2_FETCHMODE_OBJECT, use this class for each
|
||||
* returned row in rsults of select(). May be overridden by value of
|
||||
* 'fetchmode_object_class'. If no class name is set in the query or
|
||||
* the DB_Table_Base, defaults to that set in the DB/MDB2 object, or
|
||||
* to default of StdObject.
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $fetchmode_object_class = null;
|
||||
|
||||
/**
|
||||
* Upper case name of primary subclass, 'DB_TABLE' or 'DB_TABLE_DATABASE'
|
||||
*
|
||||
* This should be set in the constructor of the child class, and is
|
||||
* used in the DB_Table_Base::throwError() method to determine the
|
||||
* location of the relevant error codes and messages. Error codes and
|
||||
* error code messages are defined in class $this->_primary_subclass.
|
||||
* Messages are stored in $GLOBALS['_' . $this->_primary_subclass]['error']
|
||||
*
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_primary_subclass = null;
|
||||
|
||||
// }}}
|
||||
// {{{ Methods
|
||||
|
||||
/**
|
||||
* Specialized version of throwError() modeled on PEAR_Error.
|
||||
*
|
||||
* Throws a PEAR_Error with an error message based on an error code
|
||||
* and corresponding error message defined in $this->_primary_subclass
|
||||
*
|
||||
* @param string $code An error code constant
|
||||
* @param string $extra Extra text for the error (in addition to the
|
||||
* regular error message).
|
||||
* @return object PEAR_Error
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
function &throwError($code, $extra = null)
|
||||
{
|
||||
// get the error message text based on the error code
|
||||
$index = '_' . $this->_primary_subclass;
|
||||
$text = $this->_primary_subclass . " Error - \n"
|
||||
. $GLOBALS[$index]['error'][$code];
|
||||
|
||||
// add any additional error text
|
||||
if ($extra) {
|
||||
$text .= ' ' . $extra;
|
||||
}
|
||||
|
||||
// done!
|
||||
$error = PEAR::throwError($text, $code);
|
||||
return $error;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overwrites one or more error messages, e.g., to internationalize them.
|
||||
*
|
||||
* May be used to change messages stored in global array $GLOBALS[$class_key]
|
||||
* @param mixed $code If string, the error message with code $code will be
|
||||
* overwritten by $message. If array, each key is a code
|
||||
* and each value is a new message.
|
||||
*
|
||||
* @param string $message Only used if $key is not an array.
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function setErrorMessage($code, $message = null) {
|
||||
$index = '_' . $this->_primary_subclass;
|
||||
if (is_array($code)) {
|
||||
foreach ($code as $single_code => $single_message) {
|
||||
$GLOBALS[$index]['error'][$single_code] = $single_message;
|
||||
}
|
||||
} else {
|
||||
$GLOBALS[$index]['error'][$code] = $message;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns SQL SELECT string constructed from sql query array
|
||||
*
|
||||
* @param mixed $query SELECT query array, or key string of $this->sql
|
||||
* @param string $filter SQL snippet to AND with default WHERE clause
|
||||
* @param string $order SQL snippet to override default ORDER BY clause
|
||||
* @param int $start The row number from which to start result set
|
||||
* @param int $count The number of rows to list in the result set.
|
||||
*
|
||||
* @return string SQL SELECT command string (or PEAR_Error on failure)
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function buildSQL($query, $filter = null, $order = null,
|
||||
$start = null, $count = null)
|
||||
{
|
||||
|
||||
// Is $query a query array or a key of $this->sql ?
|
||||
if (!is_array($query)) {
|
||||
if (is_string($query)) {
|
||||
if (isset($this->sql[$query])) {
|
||||
$query = $this->sql[$query];
|
||||
} else {
|
||||
return $this->throwError(
|
||||
constant($this->_primary_subclass . '_ERR_SQL_UNDEF'),
|
||||
$query);
|
||||
}
|
||||
} else {
|
||||
return $this->throwError(
|
||||
constant($this->_primary_subclass . '_ERR_SQL_NOT_STRING'));
|
||||
}
|
||||
}
|
||||
|
||||
// Construct SQL command from parts
|
||||
$s = array();
|
||||
if (isset($query['select'])) {
|
||||
$s[] = 'SELECT ' . $query['select'];
|
||||
} else {
|
||||
$s[] = 'SELECT *';
|
||||
}
|
||||
if (isset($query['from'])) {
|
||||
$s[] = 'FROM ' . $query['from'];
|
||||
} elseif ($this->_primary_subclass == 'DB_TABLE') {
|
||||
$s[] = 'FROM ' . $this->table;
|
||||
}
|
||||
if (isset($query['join'])) {
|
||||
$s[] = $query['join'];
|
||||
}
|
||||
if (isset($query['where'])) {
|
||||
if ($filter) {
|
||||
$s[] = 'WHERE ( ' . $query['where'] . ' )';
|
||||
$s[] = ' AND ( '. $filter . ' )';
|
||||
} else {
|
||||
$s[] = 'WHERE ' . $query['where'];
|
||||
}
|
||||
} elseif ($filter) {
|
||||
$s[] = 'WHERE ' . $filter;
|
||||
}
|
||||
if (isset($query['group'])) {
|
||||
$s[] = 'GROUP BY ' . $query['group'];
|
||||
}
|
||||
if (isset($query['having'])) {
|
||||
$s[] = 'HAVING '. $query['having'];
|
||||
}
|
||||
// If $order parameter is set, override 'order' element
|
||||
if (!is_null($order)) {
|
||||
$s[] = 'ORDER BY '. $order;
|
||||
} elseif (isset($query['order'])) {
|
||||
$s[] = 'ORDER BY ' . $query['order'];
|
||||
}
|
||||
$cmd = implode("\n", $s);
|
||||
|
||||
// add LIMIT if requested
|
||||
if (!is_null($start) && !is_null($count)) {
|
||||
$db =& $this->db;
|
||||
if ($this->backend == 'mdb2') {
|
||||
$db->setLimit($count, $start);
|
||||
} else {
|
||||
$cmd = $db->modifyLimitQuery(
|
||||
$cmd, $start, $count);
|
||||
}
|
||||
}
|
||||
|
||||
// Return command string
|
||||
return $cmd;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Selects rows using one of the DB/MDB2 get*() methods.
|
||||
*
|
||||
* @param string $query SQL SELECT query array, or a key of the
|
||||
* $this->sql property array.
|
||||
* @param string $filter SQL snippet to AND with default WHERE clause
|
||||
* @param string $order SQL snippet to override default ORDER BY clause
|
||||
* @param int $start The row number from which to start result set
|
||||
* @param int $count The number of rows to list in the result set.
|
||||
* @param array $params Parameters for placeholder substitutions, if any
|
||||
* @return mixed An array of records from the table if anything but
|
||||
* ('getOne'), a single value (if 'getOne'), or a PEAR_Error
|
||||
* @see DB::getAll()
|
||||
* @see MDB2::getAll()
|
||||
* @see DB::getAssoc()
|
||||
* @see MDB2::getAssoc()
|
||||
* @see DB::getCol()
|
||||
* @see MDB2::getCol()
|
||||
* @see DB::getOne()
|
||||
* @see MDB2::getOne()
|
||||
* @see DB::getRow()
|
||||
* @see MDB2::getRow()
|
||||
* @see DB_Table_Base::_swapModes()
|
||||
* @access public
|
||||
*/
|
||||
function select($query, $filter = null, $order = null,
|
||||
$start = null, $count = null, $params = array())
|
||||
{
|
||||
|
||||
// Is $query a query array or a key of $this->sql ?
|
||||
// On output from this block, $query is an array
|
||||
if (!is_array($query)) {
|
||||
if (is_string($query)) {
|
||||
if (isset($this->sql[$query])) {
|
||||
$query = $this->sql[$query];
|
||||
} else {
|
||||
return $this->throwError(
|
||||
constant($this->_primary_subclass . '_ERR_SQL_UNDEF'),
|
||||
$query);
|
||||
}
|
||||
} else {
|
||||
return $this->throwError(
|
||||
constant($this->_primary_subclass . '_ERR_SQL_NOT_STRING'));
|
||||
}
|
||||
}
|
||||
|
||||
// build the base command
|
||||
$sql = $this->buildSQL($query, $filter, $order, $start, $count);
|
||||
if (PEAR::isError($sql)) {
|
||||
return $sql;
|
||||
}
|
||||
|
||||
// set the get*() method name
|
||||
if (isset($query['get'])) {
|
||||
$method = ucwords(strtolower(trim($query['get'])));
|
||||
$method = "get$method";
|
||||
} else {
|
||||
$method = 'getAll';
|
||||
}
|
||||
|
||||
// DB_Table assumes you are using a shared PEAR DB/MDB2 object.
|
||||
// Record fetchmode settings, to be restored before returning.
|
||||
$db =& $this->db;
|
||||
$restore_mode = $db->fetchmode;
|
||||
if ($this->backend == 'mdb2') {
|
||||
$restore_class = $db->getOption('fetch_class');
|
||||
} else {
|
||||
$restore_class = $db->fetchmode_object_class;
|
||||
}
|
||||
|
||||
// swap modes
|
||||
$fetchmode = $this->fetchmode;
|
||||
$fetchmode_object_class = $this->fetchmode_object_class;
|
||||
if (isset($query['fetchmode'])) {
|
||||
$fetchmode = $query['fetchmode'];
|
||||
}
|
||||
if (isset($query['fetchmode_object_class'])) {
|
||||
$fetchmode_object_class = $query['fetchmode_object_class'];
|
||||
}
|
||||
$this->_swapModes($fetchmode, $fetchmode_object_class);
|
||||
|
||||
// make sure params is an array
|
||||
if (!is_null($params)) {
|
||||
$params = (array) $params;
|
||||
}
|
||||
|
||||
// get the result
|
||||
if ($this->backend == 'mdb2') {
|
||||
$result = $db->extended->$method($sql, null, $params);
|
||||
} else {
|
||||
switch ($method) {
|
||||
|
||||
case 'getCol':
|
||||
$result = $db->$method($sql, 0, $params);
|
||||
break;
|
||||
|
||||
case 'getAssoc':
|
||||
$result = $db->$method($sql, false, $params);
|
||||
break;
|
||||
|
||||
default:
|
||||
$result = $db->$method($sql, $params);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// restore old fetch_mode and fetch_object_class back
|
||||
$this->_swapModes($restore_mode, $restore_class);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Selects rows as a DB_Result/MDB2_Result_* object.
|
||||
*
|
||||
* @param string $query The name of the SQL SELECT to use from the
|
||||
* $this->sql property array.
|
||||
* @param string $filter SQL snippet to AND to the default WHERE clause
|
||||
* @param string $order SQL snippet to override default ORDER BY clause
|
||||
* @param int $start The record number from which to start result set
|
||||
* @param int $count The number of records to list in result set.
|
||||
* @param array $params Parameters for placeholder substitutions, if any.
|
||||
* @return object DB_Result/MDB2_Result_* object on success
|
||||
* (PEAR_Error on failure)
|
||||
* @see DB_Table::_swapModes()
|
||||
* @access public
|
||||
*/
|
||||
function selectResult($query, $filter = null, $order = null,
|
||||
$start = null, $count = null, $params = array())
|
||||
{
|
||||
// Is $query a query array or a key of $this->sql ?
|
||||
// On output from this block, $query is an array
|
||||
if (!is_array($query)) {
|
||||
if (is_string($query)) {
|
||||
if (isset($this->sql[$query])) {
|
||||
$query = $this->sql[$query];
|
||||
} else {
|
||||
return $this->throwError(
|
||||
constant($this->_primary_subclass . '_ERR_SQL_UNDEF'),
|
||||
$query);
|
||||
}
|
||||
} else {
|
||||
return $this->throwError(
|
||||
constant($this->_primary_subclass . '_ERR_SQL_NOT_STRING'));
|
||||
}
|
||||
}
|
||||
|
||||
// build the base command
|
||||
$sql = $this->buildSQL($query, $filter, $order, $start, $count);
|
||||
if (PEAR::isError($sql)) {
|
||||
return $sql;
|
||||
}
|
||||
|
||||
// DB_Table assumes you are using a shared PEAR DB/MDB2 object.
|
||||
// Record fetchmode settings, to be restored afterwards.
|
||||
$db =& $this->db;
|
||||
$restore_mode = $db->fetchmode;
|
||||
if ($this->backend == 'mdb2') {
|
||||
$restore_class = $db->getOption('fetch_class');
|
||||
} else {
|
||||
$restore_class = $db->fetchmode_object_class;
|
||||
}
|
||||
|
||||
// swap modes
|
||||
$fetchmode = $this->fetchmode;
|
||||
$fetchmode_object_class = $this->fetchmode_object_class;
|
||||
if (isset($query['fetchmode'])) {
|
||||
$fetchmode = $query['fetchmode'];
|
||||
}
|
||||
if (isset($query['fetchmode_object_class'])) {
|
||||
$fetchmode_object_class = $query['fetchmode_object_class'];
|
||||
}
|
||||
$this->_swapModes($fetchmode, $fetchmode_object_class);
|
||||
|
||||
// make sure params is an array
|
||||
if (!is_null($params)) {
|
||||
$params = (array) $params;
|
||||
}
|
||||
|
||||
// get the result
|
||||
if ($this->backend == 'mdb2') {
|
||||
$stmt =& $db->prepare($sql);
|
||||
if (PEAR::isError($stmt)) {
|
||||
return $stmt;
|
||||
}
|
||||
$result =& $stmt->execute($params);
|
||||
} else {
|
||||
$result =& $db->query($sql, $params);
|
||||
}
|
||||
|
||||
// swap modes back
|
||||
$this->_swapModes($restore_mode, $restore_class);
|
||||
|
||||
// return the result
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Counts the number of rows which will be returned by a query.
|
||||
*
|
||||
* This function works identically to {@link select()}, but it
|
||||
* returns the number of rows returned by a query instead of the
|
||||
* query results themselves.
|
||||
*
|
||||
* @author Ian Eure <ian@php.net>
|
||||
* @param string $query The name of the SQL SELECT to use from the
|
||||
* $this->sql property array.
|
||||
* @param string $filter Ad-hoc SQL snippet to AND with the default
|
||||
* SELECT WHERE clause.
|
||||
* @param string $order Ad-hoc SQL snippet to override the default
|
||||
* SELECT ORDER BY clause.
|
||||
* @param int $start Row number from which to start listing in result
|
||||
* @param int $count Number of rows to list in result set
|
||||
* @param array $params Parameters to use in placeholder substitutions
|
||||
* (if any).
|
||||
* @return int Number of records from the table (or PEAR_Error on failure)
|
||||
*
|
||||
* @see DB_Table::select()
|
||||
* @access public
|
||||
*/
|
||||
function selectCount($query, $filter = null, $order = null,
|
||||
$start = null, $count = null, $params = array())
|
||||
{
|
||||
|
||||
// Is $query a query array or a key of $this->sql ?
|
||||
if (is_array($query)) {
|
||||
$sql_key = null;
|
||||
$count_query = $query;
|
||||
} else {
|
||||
if (is_string($query)) {
|
||||
if (isset($this->sql[$query])) {
|
||||
$sql_key = $query;
|
||||
$count_query = $this->sql[$query];
|
||||
} else {
|
||||
return $this->throwError(
|
||||
constant($this->_primary_subclass . '_ERR_SQL_UNDEF'),
|
||||
$query);
|
||||
}
|
||||
} else {
|
||||
return $this->throwError(
|
||||
constant($this->_primary_subclass . '_ERR_SQL_NOT_STRING'));
|
||||
}
|
||||
}
|
||||
|
||||
// Use Table name as default 'from' if child class is DB_TABLE
|
||||
if ($this->_primary_subclass == 'DB_TABLE') {
|
||||
if (!isset($query['from'])) {
|
||||
$count_query['from'] = $this->table;
|
||||
}
|
||||
}
|
||||
|
||||
// If the query is a stored query in $this->sql, then create a corresponding
|
||||
// key for the count query, or check if the count-query already exists
|
||||
$ready = false;
|
||||
if ($sql_key) {
|
||||
// Create an sql key name for this count-query
|
||||
$count_key = '__count_' . $sql_key;
|
||||
// Check if a this count query alread exists in $this->sql
|
||||
if (isset($this->sql[$count_key])) {
|
||||
$ready = true;
|
||||
}
|
||||
}
|
||||
|
||||
// If a count-query does not already exist, create $count_query array
|
||||
if ($ready) {
|
||||
|
||||
$count_query = $this->sql[$count_key];
|
||||
|
||||
} else {
|
||||
|
||||
// Is a count-field set for the query?
|
||||
if (!isset($count_query['count']) ||
|
||||
trim($count_query['count']) == '') {
|
||||
$count_query['count'] = '*';
|
||||
}
|
||||
|
||||
// Replace the SELECT fields with a COUNT() command
|
||||
$count_query['select'] = "COUNT({$count_query['count']})";
|
||||
|
||||
// Replace the 'get' key so we only get one result item
|
||||
$count_query['get'] = 'one';
|
||||
|
||||
// Create a new count-query in $this->sql
|
||||
if ($sql_key) {
|
||||
$this->sql[$count_key] = $count_query;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Retrieve the count results
|
||||
return $this->select($count_query, $filter, $order,
|
||||
$start, $count, $params);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the $this->db PEAR DB/MDB2 object fetchmode and
|
||||
* fetchmode_object_class.
|
||||
*
|
||||
* @param string $new_mode A DB/MDB2_FETCHMODE_* constant. If null,
|
||||
* defaults to whatever the DB/MDB2 object is currently using.
|
||||
*
|
||||
* @param string $new_class The object class to use for results when
|
||||
* the $db object is in DB/MDB2_FETCHMODE_OBJECT fetch mode. If null,
|
||||
* defaults to whatever the the DB/MDB2 object is currently using.
|
||||
*
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function _swapModes($new_mode, $new_class)
|
||||
{
|
||||
// get the old (current) mode and class
|
||||
$db =& $this->db;
|
||||
$old_mode = $db->fetchmode;
|
||||
if ($this->backend == 'mdb2') {
|
||||
$old_class = $db->getOption('fetch_class');
|
||||
} else {
|
||||
$old_class = $db->fetchmode_object_class;
|
||||
}
|
||||
|
||||
// don't need to swap anything if the new modes are both
|
||||
// null or if the old and new modes already match.
|
||||
if ((is_null($new_mode) && is_null($new_class)) ||
|
||||
($old_mode == $new_mode && $old_class == $new_class)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// set the default new mode
|
||||
if (is_null($new_mode)) {
|
||||
$new_mode = $old_mode;
|
||||
}
|
||||
|
||||
// set the default new class
|
||||
if (is_null($new_class)) {
|
||||
$new_class = $old_class;
|
||||
}
|
||||
|
||||
// swap modes
|
||||
$db->setFetchMode($new_mode, $new_class);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns SQL condition equating columns to literal values.
|
||||
*
|
||||
* The parameter $data is an associative array in which keys are
|
||||
* column names and values are corresponding values. The method
|
||||
* returns an SQL string that is true if the value of every
|
||||
* specified database columns is equal to the corresponding
|
||||
* value in $data.
|
||||
*
|
||||
* For example, if:
|
||||
* <code>
|
||||
* $data = array( 'c1' => 'thing', 'c2' => 23, 'c3' => 0.32 )
|
||||
* </code>
|
||||
* then buildFilter($data) returns a string
|
||||
* <code>
|
||||
* c1 => 'thing' AND c2 => 23 AND c3 = 0.32
|
||||
* </code>
|
||||
* in which string values are replaced by SQL literal values,
|
||||
* quoted and escaped as necessary.
|
||||
*
|
||||
* Values are quoted and escaped as appropriate for each data
|
||||
* type and the backend RDBMS, using the MDB2::quote() or
|
||||
* DB::smartQuote() method. The behavior depends on the PHP type
|
||||
* of the value: string values are quoted and escaped, while
|
||||
* integer and float numerical values are not. Boolean values
|
||||
* in $data are represented as 0 or 1, consistent with the way
|
||||
* booleans are stored by DB_Table.
|
||||
*
|
||||
* Null values: The treatment of null values in $data depends upon
|
||||
* the value of the $match parameter . If $match == 'simple', an
|
||||
* empty string is returned if any $value of $data with a key in
|
||||
* $data_key is null. If $match == 'partial', the returned SQL
|
||||
* expression equates only the relevant non-null values of $data
|
||||
* to the values of corresponding database columns. If
|
||||
* $match == 'full', the function returns an empty string if all
|
||||
* of the relevant values of data are null, and returns a
|
||||
* PEAR_Error if some of the selected values are null and others
|
||||
* are not null.
|
||||
*
|
||||
* @param array $data associative array, keys are column names
|
||||
* @return string SQL expression equating values in $data to
|
||||
* values of columns named by keys.
|
||||
* @access public
|
||||
*/
|
||||
function buildFilter($data, $match = 'simple')
|
||||
{
|
||||
// Check $match type value
|
||||
if (!in_array($match, array('simple', 'partial', 'full'))) {
|
||||
return $this->throwError(
|
||||
DB_TABLE_DATABASE_ERR_MATCH_TYPE);
|
||||
}
|
||||
|
||||
if (count($data) == 0) {
|
||||
return '';
|
||||
}
|
||||
$filter = array();
|
||||
foreach ($data as $key => $value) {
|
||||
if (!is_null($value)) {
|
||||
if ($match == 'full' && isset($found_null)) {
|
||||
return $this->throwError(
|
||||
DB_TABLE_DATABASE_ERR_FULL_KEY);
|
||||
}
|
||||
if (is_bool($value)) {
|
||||
$value = $value ? '1' : '0';
|
||||
} else {
|
||||
if ($this->backend == 'mdb2') {
|
||||
$value = $this->db->quote($value);
|
||||
} else {
|
||||
$value = $this->db->quoteSmart($value);
|
||||
}
|
||||
}
|
||||
$filter[] = "$key = $value";
|
||||
} else {
|
||||
if ($match == 'simple') {
|
||||
return ''; // if any value in $data is null
|
||||
} elseif ($match == 'full') {
|
||||
$found_null = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return implode(' AND ', $filter);
|
||||
}
|
||||
|
||||
// }}}
|
||||
}
|
||||
|
||||
// }}}
|
||||
|
||||
/* Local variables:
|
||||
* tab-width: 4
|
||||
* c-basic-offset: 4
|
||||
* c-hanging-comment-ender-p: nil
|
||||
* End:
|
||||
*/
|
||||
|
||||
?>
|
||||
3495
sites/all/modules/civicrm/packages/DB/Table/Database.php
Normal file
3495
sites/all/modules/civicrm/packages/DB/Table/Database.php
Normal file
File diff suppressed because it is too large
Load diff
195
sites/all/modules/civicrm/packages/DB/Table/Date.php
Normal file
195
sites/all/modules/civicrm/packages/DB/Table/Date.php
Normal file
|
|
@ -0,0 +1,195 @@
|
|||
<?php
|
||||
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Generic date handling class for DB_Table.
|
||||
*
|
||||
* Stripped down to two essential methods specially for DB_Table from the
|
||||
* PEAR Date package by Paul M. Jones <pmjones@php.net>.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE:
|
||||
*
|
||||
* Copyright (c) 1997-2007, Paul M. Jones <pmjones@php.net>
|
||||
* David C. Morse <morse@php.net>
|
||||
* Mark Wiesemann <wiesemann@php.net>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * The names of the authors may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @category Database
|
||||
* @package DB_Table
|
||||
* @author Baba Buehler <baba@babaz.com>
|
||||
* @author Pierre-Alain Joye <pajoye@php.net>
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version CVS: $Id: Date.php,v 1.3 2007/12/13 16:52:14 wiesemann Exp $
|
||||
* @link http://pear.php.net/package/DB_Table
|
||||
*/
|
||||
|
||||
/**
|
||||
* Generic date handling class for DB_Table.
|
||||
*
|
||||
* @category Database
|
||||
* @package DB_Table
|
||||
* @author Baba Buehler <baba@babaz.com>
|
||||
* @author Pierre-Alain Joye <pajoye@php.net>
|
||||
* @version Release: 1.5.6
|
||||
* @link http://pear.php.net/package/DB_Table
|
||||
*/
|
||||
class DB_Table_Date {
|
||||
|
||||
/**
|
||||
* the year
|
||||
* @var int
|
||||
*/
|
||||
var $year;
|
||||
/**
|
||||
* the month
|
||||
* @var int
|
||||
*/
|
||||
var $month;
|
||||
/**
|
||||
* the day
|
||||
* @var int
|
||||
*/
|
||||
var $day;
|
||||
/**
|
||||
* the hour
|
||||
* @var int
|
||||
*/
|
||||
var $hour;
|
||||
/**
|
||||
* the minute
|
||||
* @var int
|
||||
*/
|
||||
var $minute;
|
||||
/**
|
||||
* the second
|
||||
* @var int
|
||||
*/
|
||||
var $second;
|
||||
/**
|
||||
* the parts of a second
|
||||
* @var float
|
||||
*/
|
||||
var $partsecond;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Creates a new DB_Table_Date Object. The date should be near to
|
||||
* ISO 8601 format.
|
||||
*
|
||||
* @access public
|
||||
* @param string $date A date in ISO 8601 format.
|
||||
*/
|
||||
function __construct($date)
|
||||
{
|
||||
// This regex is very loose and accepts almost any butchered
|
||||
// format you could throw at it. e.g. 2003-10-07 19:45:15 and
|
||||
// 2003-10071945:15 are the same thing in the eyes of this
|
||||
// regex, even though the latter is not a valid ISO 8601 date.
|
||||
preg_match('/^(\d{4})-?(\d{2})-?(\d{2})([T\s]?(\d{2}):?(\d{2}):?(\d{2})(\.\d+)?(Z|[\+\-]\d{2}:?\d{2})?)?$/i', $date, $regs);
|
||||
$this->year = $regs[1];
|
||||
$this->month = $regs[2];
|
||||
$this->day = $regs[3];
|
||||
$this->hour = isset($regs[5])?$regs[5]:0;
|
||||
$this->minute = isset($regs[6])?$regs[6]:0;
|
||||
$this->second = isset($regs[7])?$regs[7]:0;
|
||||
$this->partsecond = isset($regs[8])?(float)$regs[8]:(float)0;
|
||||
|
||||
// if an offset is defined, convert time to UTC
|
||||
// Date currently can't set a timezone only by offset,
|
||||
// so it has to store it as UTC
|
||||
if (isset($regs[9])) {
|
||||
$this->toUTCbyOffset($regs[9]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Date pretty printing, similar to strftime()
|
||||
*
|
||||
* Formats the date in the given format, much like
|
||||
* strftime(). Most strftime() options are supported.<br><br>
|
||||
*
|
||||
* formatting options:<br><br>
|
||||
*
|
||||
* <code>%Y </code> year as decimal including century (range 0000 to 9999) <br>
|
||||
* <code>%m </code> month as decimal number (range 01 to 12) <br>
|
||||
* <code>%d </code> day of month (range 00 to 31) <br>
|
||||
* <code>%H </code> hour as decimal number (00 to 23) <br>
|
||||
* <code>%M </code> minute as a decimal number (00 to 59) <br>
|
||||
* <code>%S </code> seconds as a decimal number (00 to 59) <br>
|
||||
* <code>%% </code> literal '%' <br>
|
||||
* <br>
|
||||
*
|
||||
* @access public
|
||||
* @param string format the format string for returned date/time
|
||||
* @return string date/time in given format
|
||||
*/
|
||||
function format($format)
|
||||
{
|
||||
$output = "";
|
||||
|
||||
for($strpos = 0; $strpos < strlen($format); $strpos++) {
|
||||
$char = substr($format,$strpos,1);
|
||||
if ($char == "%") {
|
||||
$nextchar = substr($format,$strpos + 1,1);
|
||||
switch ($nextchar) {
|
||||
case "Y":
|
||||
$output .= $this->year;
|
||||
break;
|
||||
case "m":
|
||||
$output .= sprintf("%02d",$this->month);
|
||||
break;
|
||||
case "d":
|
||||
$output .= sprintf("%02d",$this->day);
|
||||
break;
|
||||
case "H":
|
||||
$output .= sprintf("%02d", $this->hour);
|
||||
break;
|
||||
case "M":
|
||||
$output .= sprintf("%02d",$this->minute);
|
||||
break;
|
||||
case "S":
|
||||
$output .= sprintf("%02d", $this->second);
|
||||
break;
|
||||
default:
|
||||
$output .= $char.$nextchar;
|
||||
}
|
||||
$strpos++;
|
||||
} else {
|
||||
$output .= $char;
|
||||
}
|
||||
}
|
||||
return $output;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
1332
sites/all/modules/civicrm/packages/DB/Table/Generator.php
Normal file
1332
sites/all/modules/civicrm/packages/DB/Table/Generator.php
Normal file
File diff suppressed because it is too large
Load diff
2349
sites/all/modules/civicrm/packages/DB/Table/Manager.php
Normal file
2349
sites/all/modules/civicrm/packages/DB/Table/Manager.php
Normal file
File diff suppressed because it is too large
Load diff
443
sites/all/modules/civicrm/packages/DB/Table/Manager/mysql.php
Normal file
443
sites/all/modules/civicrm/packages/DB/Table/Manager/mysql.php
Normal file
|
|
@ -0,0 +1,443 @@
|
|||
<?php
|
||||
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Index, constraint and alter methods for DB_Table usage with
|
||||
* PEAR::DB as backend.
|
||||
*
|
||||
* The code in this class was adopted from the MDB2 PEAR package.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE:
|
||||
*
|
||||
* Copyright (c) 1997-2007, Lukas Smith <smith@pooteeweet.org>
|
||||
* Paul M. Jones <pmjones@php.net>
|
||||
* David C. Morse <morse@php.net>
|
||||
* Mark Wiesemann <wiesemann@php.net>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * The names of the authors may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @category Database
|
||||
* @package DB_Table
|
||||
* @author Lukas Smith <smith@pooteeweet.org>
|
||||
* @author Mark Wiesemann <wiesemann@php.net>
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version CVS: $Id: mysql.php,v 1.5 2007/12/13 16:52:15 wiesemann Exp $
|
||||
* @link http://pear.php.net/package/DB_Table
|
||||
*/
|
||||
|
||||
/**
|
||||
* require DB_Table class
|
||||
*/
|
||||
require_once 'DB/Table.php';
|
||||
|
||||
/**
|
||||
* Index, constraint and alter methods for DB_Table usage with
|
||||
* PEAR::DB as backend.
|
||||
*
|
||||
* The code in this class was adopted from the MDB2 PEAR package.
|
||||
*
|
||||
* @category Database
|
||||
* @package DB_Table
|
||||
* @author Lukas Smith <smith@pooteeweet.org>
|
||||
* @author Mark Wiesemann <wiesemann@php.net>
|
||||
* @version Release: 1.5.6
|
||||
* @link http://pear.php.net/package/DB_Table
|
||||
*/
|
||||
|
||||
class DB_Table_Manager_mysql {
|
||||
|
||||
/**
|
||||
*
|
||||
* The PEAR DB object that connects to the database.
|
||||
*
|
||||
* @access private
|
||||
*
|
||||
* @var object
|
||||
*
|
||||
*/
|
||||
|
||||
var $_db = null;
|
||||
|
||||
|
||||
/**
|
||||
* list all indexes in a table
|
||||
*
|
||||
* @param string $table name of table that should be used in method
|
||||
* @return mixed data array on success, a PEAR error on failure
|
||||
* @access public
|
||||
*/
|
||||
function listTableIndexes($table)
|
||||
{
|
||||
$key_name = 'Key_name';
|
||||
$non_unique = 'Non_unique';
|
||||
|
||||
$query = "SHOW INDEX FROM $table";
|
||||
$indexes = $this->_db->getAll($query, null, DB_FETCHMODE_ASSOC);
|
||||
if (PEAR::isError($indexes)) {
|
||||
return $indexes;
|
||||
}
|
||||
|
||||
$result = array();
|
||||
foreach ($indexes as $index_data) {
|
||||
if ($index_data[$non_unique]) {
|
||||
$result[$index_data[$key_name]] = true;
|
||||
}
|
||||
}
|
||||
$result = array_change_key_case($result, CASE_LOWER);
|
||||
|
||||
return array_keys($result);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* list all constraints in a table
|
||||
*
|
||||
* @param string $table name of table that should be used in method
|
||||
* @return mixed data array on success, a PEAR error on failure
|
||||
* @access public
|
||||
*/
|
||||
function listTableConstraints($table)
|
||||
{
|
||||
$key_name = 'Key_name';
|
||||
$non_unique = 'Non_unique';
|
||||
|
||||
$query = "SHOW INDEX FROM $table";
|
||||
$indexes = $this->_db->getAll($query, null, DB_FETCHMODE_ASSOC);
|
||||
if (PEAR::isError($indexes)) {
|
||||
return $indexes;
|
||||
}
|
||||
|
||||
$result = array();
|
||||
foreach ($indexes as $index_data) {
|
||||
if (!$index_data[$non_unique]) {
|
||||
if ($index_data[$key_name] !== 'PRIMARY') {
|
||||
$index = $index_data[$key_name];
|
||||
} else {
|
||||
$index = 'PRIMARY';
|
||||
}
|
||||
$result[$index] = true;
|
||||
}
|
||||
}
|
||||
$result = array_change_key_case($result, CASE_LOWER);
|
||||
|
||||
return array_keys($result);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get the structure of an index into an array
|
||||
*
|
||||
* @param string $table name of table that should be used in method
|
||||
* @param string $index_name name of index that should be used in method
|
||||
* @return mixed data array on success, a PEAR error on failure
|
||||
* @access public
|
||||
*/
|
||||
function getTableIndexDefinition($table, $index_name)
|
||||
{
|
||||
$result = $this->_db->query("SHOW INDEX FROM $table");
|
||||
if (PEAR::isError($result)) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
$definition = array();
|
||||
while (is_array($row = $result->fetchRow(DB_FETCHMODE_ASSOC))) {
|
||||
$row = array_change_key_case($row, CASE_LOWER);
|
||||
$key_name = $row['key_name'];
|
||||
$key_name = strtolower($key_name);
|
||||
|
||||
if ($index_name == $key_name) {
|
||||
$column_name = $row['column_name'];
|
||||
$column_name = strtolower($column_name);
|
||||
$definition['fields'][$column_name] = array();
|
||||
if (array_key_exists('collation', $row)) {
|
||||
$definition['fields'][$column_name]['sorting'] = ($row['collation'] == 'A'
|
||||
? 'ascending' : 'descending');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$result->free();
|
||||
|
||||
return $definition;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get the structure of a constraint into an array
|
||||
*
|
||||
* @param string $table name of table that should be used in method
|
||||
* @param string $index_name name of index that should be used in method
|
||||
* @return mixed data array on success, a PEAR error on failure
|
||||
* @access public
|
||||
*/
|
||||
function getTableConstraintDefinition($table, $index_name)
|
||||
{
|
||||
$result = $this->_db->query("SHOW INDEX FROM $table");
|
||||
if (PEAR::isError($result)) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
$definition = array();
|
||||
while (is_array($row = $result->fetchRow(DB_FETCHMODE_ASSOC))) {
|
||||
$row = array_change_key_case($row, CASE_LOWER);
|
||||
$key_name = $row['key_name'];
|
||||
$key_name = strtolower($key_name);
|
||||
|
||||
if ($index_name == $key_name) {
|
||||
if ($row['key_name'] == 'PRIMARY') {
|
||||
$definition['primary'] = true;
|
||||
} else {
|
||||
$definition['unique'] = true;
|
||||
}
|
||||
$column_name = $row['column_name'];
|
||||
$column_name = strtolower($column_name);
|
||||
$definition['fields'][$column_name] = array();
|
||||
if (array_key_exists('collation', $row)) {
|
||||
$definition['fields'][$column_name]['sorting'] = ($row['collation'] == 'A'
|
||||
? 'ascending' : 'descending');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$result->free();
|
||||
|
||||
return $definition;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* drop existing index
|
||||
*
|
||||
* @param string $table name of table that should be used in method
|
||||
* @param string $name name of the index to be dropped
|
||||
* @return mixed DB_OK on success, a PEAR error on failure
|
||||
* @access public
|
||||
*/
|
||||
function dropIndex($table, $name)
|
||||
{
|
||||
$table = $this->_db->quoteIdentifier($table);
|
||||
$name = $this->_db->quoteIdentifier($name);
|
||||
return $this->_db->query("DROP INDEX $name ON $table");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* drop existing constraint
|
||||
*
|
||||
* @param string $table name of table that should be used in method
|
||||
* @param string $name name of the constraint to be dropped
|
||||
* @return mixed DB_OK on success, a PEAR error on failure
|
||||
* @access public
|
||||
*/
|
||||
function dropConstraint($table, $name)
|
||||
{
|
||||
$table = $this->_db->quoteIdentifier($table);
|
||||
if (strtolower($name) == 'primary') {
|
||||
$query = "ALTER TABLE $table DROP PRIMARY KEY";
|
||||
} else {
|
||||
$name = $this->_db->quoteIdentifier($name);
|
||||
$query = "ALTER TABLE $table DROP INDEX $name";
|
||||
}
|
||||
return $this->_db->query($query);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* alter an existing table
|
||||
*
|
||||
* @param string $name name of the table that is intended to be changed.
|
||||
* @param array $changes associative array that contains the details of each type
|
||||
* of change that is intended to be performed. The types of
|
||||
* changes that are currently supported are defined as follows:
|
||||
*
|
||||
* name
|
||||
*
|
||||
* New name for the table.
|
||||
*
|
||||
* add
|
||||
*
|
||||
* Associative array with the names of fields to be added as
|
||||
* indexes of the array. The value of each entry of the array
|
||||
* should be set to another associative array with the properties
|
||||
* of the fields to be added. The properties of the fields should
|
||||
* be the same as defined by the Metabase parser.
|
||||
*
|
||||
*
|
||||
* remove
|
||||
*
|
||||
* Associative array with the names of fields to be removed as indexes
|
||||
* of the array. Currently the values assigned to each entry are ignored.
|
||||
* An empty array should be used for future compatibility.
|
||||
*
|
||||
* rename
|
||||
*
|
||||
* Associative array with the names of fields to be renamed as indexes
|
||||
* of the array. The value of each entry of the array should be set to
|
||||
* another associative array with the entry named name with the new
|
||||
* field name and the entry named Declaration that is expected to contain
|
||||
* the portion of the field declaration already in DBMS specific SQL code
|
||||
* as it is used in the CREATE TABLE statement.
|
||||
*
|
||||
* change
|
||||
*
|
||||
* Associative array with the names of the fields to be changed as indexes
|
||||
* of the array. Keep in mind that if it is intended to change either the
|
||||
* name of a field and any other properties, the change array entries
|
||||
* should have the new names of the fields as array indexes.
|
||||
*
|
||||
* The value of each entry of the array should be set to another associative
|
||||
* array with the properties of the fields to that are meant to be changed as
|
||||
* array entries. These entries should be assigned to the new values of the
|
||||
* respective properties. The properties of the fields should be the same
|
||||
* as defined by the Metabase parser.
|
||||
*
|
||||
* Example
|
||||
* array(
|
||||
* 'name' => 'userlist',
|
||||
* 'add' => array(
|
||||
* 'quota' => array(
|
||||
* 'type' => 'integer',
|
||||
* 'unsigned' => 1
|
||||
* )
|
||||
* ),
|
||||
* 'remove' => array(
|
||||
* 'file_limit' => array(),
|
||||
* 'time_limit' => array()
|
||||
* ),
|
||||
* 'change' => array(
|
||||
* 'name' => array(
|
||||
* 'length' => '20',
|
||||
* 'definition' => array(
|
||||
* 'type' => 'text',
|
||||
* 'length' => 20,
|
||||
* ),
|
||||
* )
|
||||
* ),
|
||||
* 'rename' => array(
|
||||
* 'sex' => array(
|
||||
* 'name' => 'gender',
|
||||
* 'definition' => array(
|
||||
* 'type' => 'text',
|
||||
* 'length' => 1,
|
||||
* 'default' => 'M',
|
||||
* ),
|
||||
* )
|
||||
* )
|
||||
* )
|
||||
*
|
||||
* @param boolean $check (ignored in DB_Table)
|
||||
* @access public
|
||||
*
|
||||
* @return mixed DB_OK on success, a PEAR error on failure
|
||||
*/
|
||||
function alterTable($name, $changes, $check)
|
||||
{
|
||||
foreach ($changes as $change_name => $change) {
|
||||
switch ($change_name) {
|
||||
case 'add':
|
||||
case 'remove':
|
||||
case 'change':
|
||||
case 'rename':
|
||||
case 'name':
|
||||
break;
|
||||
default:
|
||||
return DB_Table::throwError(DB_TABLE_ERR_ALTER_TABLE_IMPOS);
|
||||
}
|
||||
}
|
||||
|
||||
$query = '';
|
||||
if (array_key_exists('name', $changes)) {
|
||||
$change_name = $this->_db->quoteIdentifier($changes['name']);
|
||||
$query .= 'RENAME TO ' . $change_name;
|
||||
}
|
||||
|
||||
if (array_key_exists('add', $changes)) {
|
||||
foreach ($changes['add'] as $field_name => $field) {
|
||||
if ($query) {
|
||||
$query.= ', ';
|
||||
}
|
||||
$query.= 'ADD ' . $field_name . ' ' . $field;
|
||||
}
|
||||
}
|
||||
|
||||
if (array_key_exists('remove', $changes)) {
|
||||
foreach ($changes['remove'] as $field_name => $field) {
|
||||
if ($query) {
|
||||
$query.= ', ';
|
||||
}
|
||||
$field_name = $this->_db->quoteIdentifier($field_name);
|
||||
$query.= 'DROP ' . $field_name;
|
||||
}
|
||||
}
|
||||
|
||||
$rename = array();
|
||||
if (array_key_exists('rename', $changes)) {
|
||||
foreach ($changes['rename'] as $field_name => $field) {
|
||||
$rename[$field['name']] = $field_name;
|
||||
}
|
||||
}
|
||||
|
||||
if (array_key_exists('change', $changes)) {
|
||||
foreach ($changes['change'] as $field_name => $field) {
|
||||
if ($query) {
|
||||
$query.= ', ';
|
||||
}
|
||||
if (isset($rename[$field_name])) {
|
||||
$old_field_name = $rename[$field_name];
|
||||
unset($rename[$field_name]);
|
||||
} else {
|
||||
$old_field_name = $field_name;
|
||||
}
|
||||
$old_field_name = $this->_db->quoteIdentifier($old_field_name);
|
||||
$query.= "CHANGE $old_field_name " . $field_name . ' ' . $field['definition'];
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($rename)) {
|
||||
foreach ($rename as $rename_name => $renamed_field) {
|
||||
if ($query) {
|
||||
$query.= ', ';
|
||||
}
|
||||
$field = $changes['rename'][$renamed_field];
|
||||
$renamed_field = $this->_db->quoteIdentifier($renamed_field);
|
||||
$query.= 'CHANGE ' . $renamed_field . ' ' . $field['name'] . ' ' . $renamed_field['definition'];
|
||||
}
|
||||
}
|
||||
|
||||
if (!$query) {
|
||||
return DB_OK;
|
||||
}
|
||||
|
||||
$name = $this->_db->quoteIdentifier($name);
|
||||
return $this->_db->query("ALTER TABLE $name $query");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
440
sites/all/modules/civicrm/packages/DB/Table/Manager/mysqli.php
Normal file
440
sites/all/modules/civicrm/packages/DB/Table/Manager/mysqli.php
Normal file
|
|
@ -0,0 +1,440 @@
|
|||
<?php
|
||||
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Index, constraint and alter methods for DB_Table usage with
|
||||
* PEAR::DB as backend.
|
||||
*
|
||||
* The code in this class was adopted from the MDB2 PEAR package.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE:
|
||||
*
|
||||
* Copyright (c) 1997-2007, Lukas Smith <smith@pooteeweet.org>
|
||||
* Paul M. Jones <pmjones@php.net>
|
||||
* David C. Morse <morse@php.net>
|
||||
* Mark Wiesemann <wiesemann@php.net>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * The names of the authors may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @category Database
|
||||
* @package DB_Table
|
||||
* @author Lukas Smith <smith@pooteeweet.org>
|
||||
* @author Mark Wiesemann <wiesemann@php.net>
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version CVS: $Id: mysqli.php,v 1.6 2007/12/13 16:52:15 wiesemann Exp $
|
||||
* @link http://pear.php.net/package/DB_Table
|
||||
*/
|
||||
|
||||
/**
|
||||
* require DB_Table class
|
||||
*/
|
||||
require_once 'DB/Table.php';
|
||||
|
||||
/**
|
||||
* Index, constraint and alter methods for DB_Table usage with
|
||||
* PEAR::DB as backend.
|
||||
*
|
||||
* The code in this class was adopted from the MDB2 PEAR package.
|
||||
*
|
||||
* @category Database
|
||||
* @package DB_Table
|
||||
* @author Lukas Smith <smith@pooteeweet.org>
|
||||
* @author Mark Wiesemann <wiesemann@php.net>
|
||||
* @version Release: 1.5.6
|
||||
* @link http://pear.php.net/package/DB_Table
|
||||
*/
|
||||
class DB_Table_Manager_mysqli {
|
||||
|
||||
/**
|
||||
*
|
||||
* The PEAR DB object that connects to the database.
|
||||
*
|
||||
* @access private
|
||||
*
|
||||
* @var object
|
||||
*
|
||||
*/
|
||||
|
||||
var $_db = null;
|
||||
|
||||
|
||||
/**
|
||||
* list all indexes in a table
|
||||
*
|
||||
* @param string $table name of table that should be used in method
|
||||
* @return mixed data array on success, a PEAR error on failure
|
||||
* @access public
|
||||
*/
|
||||
function listTableIndexes($table)
|
||||
{
|
||||
$key_name = 'Key_name';
|
||||
$non_unique = 'Non_unique';
|
||||
|
||||
$query = "SHOW INDEX FROM $table";
|
||||
$indexes = $this->_db->getAll($query, null, DB_FETCHMODE_ASSOC);
|
||||
if (PEAR::isError($indexes)) {
|
||||
return $indexes;
|
||||
}
|
||||
|
||||
$result = array();
|
||||
foreach ($indexes as $index_data) {
|
||||
if ($index_data[$non_unique]) {
|
||||
$result[$index_data[$key_name]] = true;
|
||||
}
|
||||
}
|
||||
$result = array_change_key_case($result, CASE_LOWER);
|
||||
|
||||
return array_keys($result);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* list all constraints in a table
|
||||
*
|
||||
* @param string $table name of table that should be used in method
|
||||
* @return mixed data array on success, a PEAR error on failure
|
||||
* @access public
|
||||
*/
|
||||
function listTableConstraints($table)
|
||||
{
|
||||
$key_name = 'Key_name';
|
||||
$non_unique = 'Non_unique';
|
||||
|
||||
$query = "SHOW INDEX FROM $table";
|
||||
$indexes = $this->_db->getAll($query, null, DB_FETCHMODE_ASSOC);
|
||||
if (PEAR::isError($indexes)) {
|
||||
return $indexes;
|
||||
}
|
||||
|
||||
$result = array();
|
||||
foreach ($indexes as $index_data) {
|
||||
if (!$index_data[$non_unique]) {
|
||||
if ($index_data[$key_name] !== 'PRIMARY') {
|
||||
$index = $index_data[$key_name];
|
||||
} else {
|
||||
$index = 'PRIMARY';
|
||||
}
|
||||
$result[$index] = true;
|
||||
}
|
||||
}
|
||||
$result = array_change_key_case($result, CASE_LOWER);
|
||||
|
||||
return array_keys($result);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get the structure of an index into an array
|
||||
*
|
||||
* @param string $table name of table that should be used in method
|
||||
* @param string $index_name name of index that should be used in method
|
||||
* @return mixed data array on success, a PEAR error on failure
|
||||
* @access public
|
||||
*/
|
||||
function getTableIndexDefinition($table, $index_name)
|
||||
{
|
||||
$result = $this->_db->query("SHOW INDEX FROM $table");
|
||||
if (PEAR::isError($result)) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
$definition = array();
|
||||
while (is_array($row = $result->fetchRow(DB_FETCHMODE_ASSOC))) {
|
||||
$row = array_change_key_case($row, CASE_LOWER);
|
||||
$key_name = $row['key_name'];
|
||||
$key_name = strtolower($key_name);
|
||||
if ($index_name == $key_name) {
|
||||
$column_name = $row['column_name'];
|
||||
$column_name = strtolower($column_name);
|
||||
$definition['fields'][$column_name] = array();
|
||||
if (array_key_exists('collation', $row)) {
|
||||
$definition['fields'][$column_name]['sorting'] = ($row['collation'] == 'A'
|
||||
? 'ascending' : 'descending');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$result->free();
|
||||
|
||||
return $definition;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get the structure of a constraint into an array
|
||||
*
|
||||
* @param string $table name of table that should be used in method
|
||||
* @param string $index_name name of index that should be used in method
|
||||
* @return mixed data array on success, a PEAR error on failure
|
||||
* @access public
|
||||
*/
|
||||
function getTableConstraintDefinition($table, $index_name)
|
||||
{
|
||||
$result = $this->_db->query("SHOW INDEX FROM $table");
|
||||
if (PEAR::isError($result)) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
$definition = array();
|
||||
while (is_array($row = $result->fetchRow(DB_FETCHMODE_ASSOC))) {
|
||||
$row = array_change_key_case($row, CASE_LOWER);
|
||||
$key_name = $row['key_name'];
|
||||
$key_name = strtolower($key_name);
|
||||
if ($index_name == $key_name) {
|
||||
if ($row['key_name'] == 'PRIMARY') {
|
||||
$definition['primary'] = true;
|
||||
} else {
|
||||
$definition['unique'] = true;
|
||||
}
|
||||
$column_name = $row['column_name'];
|
||||
$column_name = strtolower($column_name);
|
||||
$definition['fields'][$column_name] = array();
|
||||
if (array_key_exists('collation', $row)) {
|
||||
$definition['fields'][$column_name]['sorting'] = ($row['collation'] == 'A'
|
||||
? 'ascending' : 'descending');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$result->free();
|
||||
|
||||
return $definition;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* drop existing index
|
||||
*
|
||||
* @param string $table name of table that should be used in method
|
||||
* @param string $name name of the index to be dropped
|
||||
* @return mixed DB_OK on success, a PEAR error on failure
|
||||
* @access public
|
||||
*/
|
||||
function dropIndex($table, $name)
|
||||
{
|
||||
$table = $this->_db->quoteIdentifier($table);
|
||||
$name = $this->_db->quoteIdentifier($name);
|
||||
return $this->_db->query("DROP INDEX $name ON $table");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* drop existing constraint
|
||||
*
|
||||
* @param string $table name of table that should be used in method
|
||||
* @param string $name name of the constraint to be dropped
|
||||
* @return mixed DB_OK on success, a PEAR error on failure
|
||||
* @access public
|
||||
*/
|
||||
function dropConstraint($table, $name)
|
||||
{
|
||||
$table = $this->_db->quoteIdentifier($table);
|
||||
if (strtolower($name) == 'primary') {
|
||||
$query = "ALTER TABLE $table DROP PRIMARY KEY";
|
||||
} else {
|
||||
$name = $this->_db->quoteIdentifier($name);
|
||||
$query = "ALTER TABLE $table DROP INDEX $name";
|
||||
}
|
||||
return $this->_db->query($query);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* alter an existing table
|
||||
*
|
||||
* @param string $name name of the table that is intended to be changed.
|
||||
* @param array $changes associative array that contains the details of each type
|
||||
* of change that is intended to be performed. The types of
|
||||
* changes that are currently supported are defined as follows:
|
||||
*
|
||||
* name
|
||||
*
|
||||
* New name for the table.
|
||||
*
|
||||
* add
|
||||
*
|
||||
* Associative array with the names of fields to be added as
|
||||
* indexes of the array. The value of each entry of the array
|
||||
* should be set to another associative array with the properties
|
||||
* of the fields to be added. The properties of the fields should
|
||||
* be the same as defined by the Metabase parser.
|
||||
*
|
||||
*
|
||||
* remove
|
||||
*
|
||||
* Associative array with the names of fields to be removed as indexes
|
||||
* of the array. Currently the values assigned to each entry are ignored.
|
||||
* An empty array should be used for future compatibility.
|
||||
*
|
||||
* rename
|
||||
*
|
||||
* Associative array with the names of fields to be renamed as indexes
|
||||
* of the array. The value of each entry of the array should be set to
|
||||
* another associative array with the entry named name with the new
|
||||
* field name and the entry named Declaration that is expected to contain
|
||||
* the portion of the field declaration already in DBMS specific SQL code
|
||||
* as it is used in the CREATE TABLE statement.
|
||||
*
|
||||
* change
|
||||
*
|
||||
* Associative array with the names of the fields to be changed as indexes
|
||||
* of the array. Keep in mind that if it is intended to change either the
|
||||
* name of a field and any other properties, the change array entries
|
||||
* should have the new names of the fields as array indexes.
|
||||
*
|
||||
* The value of each entry of the array should be set to another associative
|
||||
* array with the properties of the fields to that are meant to be changed as
|
||||
* array entries. These entries should be assigned to the new values of the
|
||||
* respective properties. The properties of the fields should be the same
|
||||
* as defined by the Metabase parser.
|
||||
*
|
||||
* Example
|
||||
* array(
|
||||
* 'name' => 'userlist',
|
||||
* 'add' => array(
|
||||
* 'quota' => array(
|
||||
* 'type' => 'integer',
|
||||
* 'unsigned' => 1
|
||||
* )
|
||||
* ),
|
||||
* 'remove' => array(
|
||||
* 'file_limit' => array(),
|
||||
* 'time_limit' => array()
|
||||
* ),
|
||||
* 'change' => array(
|
||||
* 'name' => array(
|
||||
* 'length' => '20',
|
||||
* 'definition' => array(
|
||||
* 'type' => 'text',
|
||||
* 'length' => 20,
|
||||
* ),
|
||||
* )
|
||||
* ),
|
||||
* 'rename' => array(
|
||||
* 'sex' => array(
|
||||
* 'name' => 'gender',
|
||||
* 'definition' => array(
|
||||
* 'type' => 'text',
|
||||
* 'length' => 1,
|
||||
* 'default' => 'M',
|
||||
* ),
|
||||
* )
|
||||
* )
|
||||
* )
|
||||
*
|
||||
* @param boolean $check (ignored in DB_Table)
|
||||
* @access public
|
||||
*
|
||||
* @return mixed DB_OK on success, a PEAR error on failure
|
||||
*/
|
||||
function alterTable($name, $changes, $check)
|
||||
{
|
||||
foreach ($changes as $change_name => $change) {
|
||||
switch ($change_name) {
|
||||
case 'add':
|
||||
case 'remove':
|
||||
case 'change':
|
||||
case 'rename':
|
||||
case 'name':
|
||||
break;
|
||||
default:
|
||||
return DB_Table::throwError(DB_TABLE_ERR_ALTER_TABLE_IMPOS);
|
||||
}
|
||||
}
|
||||
|
||||
$query = '';
|
||||
if (array_key_exists('name', $changes)) {
|
||||
$change_name = $this->_db->quoteIdentifier($changes['name']);
|
||||
$query .= 'RENAME TO ' . $change_name;
|
||||
}
|
||||
|
||||
if (array_key_exists('add', $changes)) {
|
||||
foreach ($changes['add'] as $field_name => $field) {
|
||||
if ($query) {
|
||||
$query.= ', ';
|
||||
}
|
||||
$query.= 'ADD ' . $field_name . ' ' . $field;
|
||||
}
|
||||
}
|
||||
|
||||
if (array_key_exists('remove', $changes)) {
|
||||
foreach ($changes['remove'] as $field_name => $field) {
|
||||
if ($query) {
|
||||
$query.= ', ';
|
||||
}
|
||||
$field_name = $db->quoteIdentifier($field_name);
|
||||
$query.= 'DROP ' . $field_name;
|
||||
}
|
||||
}
|
||||
|
||||
$rename = array();
|
||||
if (array_key_exists('rename', $changes)) {
|
||||
foreach ($changes['rename'] as $field_name => $field) {
|
||||
$rename[$field['name']] = $field_name;
|
||||
}
|
||||
}
|
||||
|
||||
if (array_key_exists('change', $changes)) {
|
||||
foreach ($changes['change'] as $field_name => $field) {
|
||||
if ($query) {
|
||||
$query.= ', ';
|
||||
}
|
||||
if (isset($rename[$field_name])) {
|
||||
$old_field_name = $rename[$field_name];
|
||||
unset($rename[$field_name]);
|
||||
} else {
|
||||
$old_field_name = $field_name;
|
||||
}
|
||||
$old_field_name = $this->_db->quoteIdentifier($old_field_name);
|
||||
$query.= "CHANGE $old_field_name " . $field_name . ' ' . $field['definition'];
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($rename)) {
|
||||
foreach ($rename as $rename_name => $renamed_field) {
|
||||
if ($query) {
|
||||
$query.= ', ';
|
||||
}
|
||||
$field = $changes['rename'][$renamed_field];
|
||||
$renamed_field = $this->_db->quoteIdentifier($renamed_field);
|
||||
$query.= 'CHANGE ' . $renamed_field . ' ' . $field['name'] . ' ' . $renamed_field['definition'];
|
||||
}
|
||||
}
|
||||
|
||||
if (!$query) {
|
||||
return DB_OK;
|
||||
}
|
||||
|
||||
$name = $this->_db->quoteIdentifier($name);
|
||||
return $this->_db->query("ALTER TABLE $name $query");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
440
sites/all/modules/civicrm/packages/DB/Table/Manager/pgsql.php
Normal file
440
sites/all/modules/civicrm/packages/DB/Table/Manager/pgsql.php
Normal file
|
|
@ -0,0 +1,440 @@
|
|||
<?php
|
||||
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Index, constraint and alter methods for DB_Table usage with
|
||||
* PEAR::DB as backend.
|
||||
*
|
||||
* The code in this class was adopted from the MDB2 PEAR package.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE:
|
||||
*
|
||||
* Copyright (c) 1997-2007, Paul Cooper <pgc@ucecom.com>
|
||||
* Paul M. Jones <pmjones@php.net>
|
||||
* David C. Morse <morse@php.net>
|
||||
* Mark Wiesemann <wiesemann@php.net>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * The names of the authors may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @category Database
|
||||
* @package DB_Table
|
||||
* @author Paul Cooper <pgc@ucecom.com>
|
||||
* @author Mark Wiesemann <wiesemann@php.net>
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version CVS: $Id: pgsql.php,v 1.5 2007/12/13 16:52:15 wiesemann Exp $
|
||||
* @link http://pear.php.net/package/DB_Table
|
||||
*/
|
||||
|
||||
/**
|
||||
* require DB_Table class
|
||||
*/
|
||||
require_once 'DB/Table.php';
|
||||
|
||||
/**
|
||||
* Index, constraint and alter methods for DB_Table usage with
|
||||
* PEAR::DB as backend.
|
||||
*
|
||||
* The code in this class was adopted from the MDB2 PEAR package.
|
||||
*
|
||||
* @category Database
|
||||
* @package DB_Table
|
||||
* @author Paul Cooper <pgc@ucecom.com>
|
||||
* @author Mark Wiesemann <wiesemann@php.net>
|
||||
* @version Release: 1.5.6
|
||||
* @link http://pear.php.net/package/DB_Table
|
||||
*/
|
||||
class DB_Table_Manager_pgsql {
|
||||
|
||||
/**
|
||||
*
|
||||
* The PEAR DB object that connects to the database.
|
||||
*
|
||||
* @access private
|
||||
*
|
||||
* @var object
|
||||
*
|
||||
*/
|
||||
|
||||
var $_db = null;
|
||||
|
||||
|
||||
/**
|
||||
* list all indexes in a table
|
||||
*
|
||||
* @param string $table name of table that should be used in method
|
||||
* @return mixed data array on success, a PEAR error on failure
|
||||
* @access public
|
||||
*/
|
||||
function listTableIndexes($table)
|
||||
{
|
||||
$subquery = "SELECT indexrelid FROM pg_index, pg_class";
|
||||
$subquery.= " WHERE pg_class.relname='$table' AND pg_class.oid=pg_index.indrelid AND indisunique != 't' AND indisprimary != 't'";
|
||||
$query = "SELECT relname FROM pg_class WHERE oid IN ($subquery)";
|
||||
$indexes = $this->_db->getCol($query);
|
||||
if (PEAR::isError($indexes)) {
|
||||
return $indexes;
|
||||
}
|
||||
|
||||
$result = array();
|
||||
foreach ($indexes as $index) {
|
||||
$result[$index] = true;
|
||||
}
|
||||
$result = array_change_key_case($result, CASE_LOWER);
|
||||
|
||||
return array_keys($result);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* list all constraints in a table
|
||||
*
|
||||
* @param string $table name of table that should be used in method
|
||||
* @return mixed data array on success, a PEAR error on failure
|
||||
* @access public
|
||||
*/
|
||||
function listTableConstraints($table)
|
||||
{
|
||||
$subquery = "SELECT indexrelid FROM pg_index, pg_class";
|
||||
$subquery.= " WHERE pg_class.relname='$table' AND pg_class.oid=pg_index.indrelid AND (indisunique = 't' OR indisprimary = 't')";
|
||||
$query = "SELECT relname FROM pg_class WHERE oid IN ($subquery)";
|
||||
$constraints = $this->_db->getCol($query);
|
||||
if (PEAR::isError($constraints)) {
|
||||
return $constraints;
|
||||
}
|
||||
|
||||
$result = array();
|
||||
foreach ($constraints as $constraint) {
|
||||
$result[$constraint] = true;
|
||||
}
|
||||
$result = array_change_key_case($result, CASE_LOWER);
|
||||
|
||||
return array_keys($result);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get the structure of an index into an array
|
||||
*
|
||||
* @param string $table name of table that should be used in method
|
||||
* @param string $index_name name of index that should be used in method
|
||||
* @return mixed data array on success, a PEAR error on failure
|
||||
* @access public
|
||||
*/
|
||||
function getTableIndexDefinition($table, $index_name)
|
||||
{
|
||||
$query = "SELECT relname, indkey FROM pg_index, pg_class
|
||||
WHERE pg_class.relname = ".$this->_db->quoteSmart($index_name)." AND pg_class.oid = pg_index.indexrelid
|
||||
AND indisunique != 't' AND indisprimary != 't'";
|
||||
$row = $this->_db->getRow($query, null, DB_FETCHMODE_ASSOC);
|
||||
if (PEAR::isError($row)) {
|
||||
return $row;
|
||||
}
|
||||
|
||||
$columns = $this->_listTableFields($table);
|
||||
|
||||
$definition = array();
|
||||
|
||||
$index_column_numbers = explode(' ', $row['indkey']);
|
||||
|
||||
foreach ($index_column_numbers as $number) {
|
||||
$definition['fields'][$columns[($number - 1)]] = array('sorting' => 'ascending');
|
||||
}
|
||||
return $definition;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get the structure of a constraint into an array
|
||||
*
|
||||
* @param string $table name of table that should be used in method
|
||||
* @param string $index_name name of index that should be used in method
|
||||
* @return mixed data array on success, a PEAR error on failure
|
||||
* @access public
|
||||
*/
|
||||
function getTableConstraintDefinition($table, $index_name)
|
||||
{
|
||||
$query = "SELECT relname, indisunique, indisprimary, indkey FROM pg_index, pg_class
|
||||
WHERE pg_class.relname = ".$this->_db->quoteSmart($index_name)." AND pg_class.oid = pg_index.indexrelid
|
||||
AND (indisunique = 't' OR indisprimary = 't')";
|
||||
$row = $this->_db->getRow($query, null, DB_FETCHMODE_ASSOC);
|
||||
if (PEAR::isError($row)) {
|
||||
return $row;
|
||||
}
|
||||
|
||||
$columns = $this->_listTableFields($table);
|
||||
|
||||
$definition = array();
|
||||
if ($row['indisprimary'] == 't') {
|
||||
$definition['primary'] = true;
|
||||
} elseif ($row['indisunique'] == 't') {
|
||||
$definition['unique'] = true;
|
||||
}
|
||||
|
||||
$index_column_numbers = explode(' ', $row['indkey']);
|
||||
|
||||
foreach ($index_column_numbers as $number) {
|
||||
$definition['fields'][$columns[($number - 1)]] = array('sorting' => 'ascending');
|
||||
}
|
||||
return $definition;
|
||||
}
|
||||
|
||||
/**
|
||||
* list all fields in a tables in the current database
|
||||
*
|
||||
* @param string $table name of table that should be used in method
|
||||
* @return mixed data array on success, a PEAR error on failure
|
||||
* @access private
|
||||
*/
|
||||
function _listTableFields($table)
|
||||
{
|
||||
$table = $this->_db->quoteIdentifier($table);
|
||||
$result2 = $this->_db->query("SELECT * FROM $table");
|
||||
if (PEAR::isError($result2)) {
|
||||
return $result2;
|
||||
}
|
||||
$columns = array();
|
||||
$numcols = $result2->numCols();
|
||||
for ($column = 0; $column < $numcols; $column++) {
|
||||
$column_name = @pg_field_name($result2->result, $column);
|
||||
$columns[$column_name] = $column;
|
||||
}
|
||||
$result2->free();
|
||||
return array_flip($columns);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* drop existing index
|
||||
*
|
||||
* @param string $table name of table that should be used in method
|
||||
* @param string $name name of the index to be dropped
|
||||
* @return mixed DB_OK on success, a PEAR error on failure
|
||||
* @access public
|
||||
*/
|
||||
function dropIndex($table, $name)
|
||||
{
|
||||
$name = $this->_db->quoteIdentifier($name);
|
||||
return $this->_db->query("DROP INDEX $name");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* drop existing constraint
|
||||
*
|
||||
* @param string $table name of table that should be used in method
|
||||
* @param string $name name of the constraint to be dropped
|
||||
* @return mixed DB_OK on success, a PEAR error on failure
|
||||
* @access public
|
||||
*/
|
||||
function dropConstraint($table, $name)
|
||||
{
|
||||
$table = $this->_db->quoteIdentifier($table);
|
||||
$name = $this->_db->quoteIdentifier($name);
|
||||
return $this->_db->query("ALTER TABLE $table DROP CONSTRAINT $name");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* alter an existing table
|
||||
*
|
||||
* @param string $name name of the table that is intended to be changed.
|
||||
* @param array $changes associative array that contains the details of each type
|
||||
* of change that is intended to be performed. The types of
|
||||
* changes that are currently supported are defined as follows:
|
||||
*
|
||||
* name
|
||||
*
|
||||
* New name for the table.
|
||||
*
|
||||
* add
|
||||
*
|
||||
* Associative array with the names of fields to be added as
|
||||
* indexes of the array. The value of each entry of the array
|
||||
* should be set to another associative array with the properties
|
||||
* of the fields to be added. The properties of the fields should
|
||||
* be the same as defined by the Metabase parser.
|
||||
*
|
||||
*
|
||||
* remove
|
||||
*
|
||||
* Associative array with the names of fields to be removed as indexes
|
||||
* of the array. Currently the values assigned to each entry are ignored.
|
||||
* An empty array should be used for future compatibility.
|
||||
*
|
||||
* rename
|
||||
*
|
||||
* Associative array with the names of fields to be renamed as indexes
|
||||
* of the array. The value of each entry of the array should be set to
|
||||
* another associative array with the entry named name with the new
|
||||
* field name and the entry named Declaration that is expected to contain
|
||||
* the portion of the field declaration already in DBMS specific SQL code
|
||||
* as it is used in the CREATE TABLE statement.
|
||||
*
|
||||
* change
|
||||
*
|
||||
* Associative array with the names of the fields to be changed as indexes
|
||||
* of the array. Keep in mind that if it is intended to change either the
|
||||
* name of a field and any other properties, the change array entries
|
||||
* should have the new names of the fields as array indexes.
|
||||
*
|
||||
* The value of each entry of the array should be set to another associative
|
||||
* array with the properties of the fields to that are meant to be changed as
|
||||
* array entries. These entries should be assigned to the new values of the
|
||||
* respective properties. The properties of the fields should be the same
|
||||
* as defined by the Metabase parser.
|
||||
*
|
||||
* Example
|
||||
* array(
|
||||
* 'name' => 'userlist',
|
||||
* 'add' => array(
|
||||
* 'quota' => array(
|
||||
* 'type' => 'integer',
|
||||
* 'unsigned' => 1
|
||||
* )
|
||||
* ),
|
||||
* 'remove' => array(
|
||||
* 'file_limit' => array(),
|
||||
* 'time_limit' => array()
|
||||
* ),
|
||||
* 'change' => array(
|
||||
* 'name' => array(
|
||||
* 'length' => '20',
|
||||
* 'definition' => array(
|
||||
* 'type' => 'text',
|
||||
* 'length' => 20,
|
||||
* ),
|
||||
* )
|
||||
* ),
|
||||
* 'rename' => array(
|
||||
* 'sex' => array(
|
||||
* 'name' => 'gender',
|
||||
* 'definition' => array(
|
||||
* 'type' => 'text',
|
||||
* 'length' => 1,
|
||||
* 'default' => 'M',
|
||||
* ),
|
||||
* )
|
||||
* )
|
||||
* )
|
||||
*
|
||||
* @param boolean $check (ignored in DB_Table)
|
||||
* @access public
|
||||
*
|
||||
* @return mixed DB_OK on success, a PEAR error on failure
|
||||
*/
|
||||
function alterTable($name, $changes, $check)
|
||||
{
|
||||
foreach ($changes as $change_name => $change) {
|
||||
switch ($change_name) {
|
||||
case 'add':
|
||||
case 'remove':
|
||||
case 'change':
|
||||
case 'name':
|
||||
case 'rename':
|
||||
break;
|
||||
default:
|
||||
return DB_Table::throwError(DB_TABLE_ERR_ALTER_TABLE_IMPOS);
|
||||
}
|
||||
}
|
||||
|
||||
if (array_key_exists('add', $changes)) {
|
||||
foreach ($changes['add'] as $field_name => $field) {
|
||||
$query = 'ADD ' . $field_name . ' ' . $field;
|
||||
$result = $this->_db->query("ALTER TABLE $name $query");
|
||||
if (PEAR::isError($result)) {
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (array_key_exists('remove', $changes)) {
|
||||
foreach ($changes['remove'] as $field_name => $field) {
|
||||
$field_name = $this->_db->quoteIdentifier($field_name);
|
||||
$query = 'DROP ' . $field_name;
|
||||
$result = $this->_db->query("ALTER TABLE $name $query");
|
||||
if (PEAR::isError($result)) {
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (array_key_exists('change', $changes)) {
|
||||
foreach ($changes['change'] as $field_name => $field) {
|
||||
$field_name = $this->_db->quoteIdentifier($field_name);
|
||||
if (array_key_exists('type', $field)) {
|
||||
$query = "ALTER $field_name TYPE " . $field['definition'];
|
||||
$result = $this->_db->query("ALTER TABLE $name $query");
|
||||
if (PEAR::isError($result)) {
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
/* default / notnull changes not (yet) supported in DB_Table
|
||||
if (array_key_exists('default', $field)) {
|
||||
$query = "ALTER $field_name SET DEFAULT ".$db->quote($field['definition']['default'], $field['definition']['type']);
|
||||
$result = $db->exec("ALTER TABLE $name $query");
|
||||
if (PEAR::isError($result)) {
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
if (array_key_exists('notnull', $field)) {
|
||||
$query.= "ALTER $field_name ".($field['definition']['notnull'] ? "SET" : "DROP").' NOT NULL';
|
||||
$result = $db->exec("ALTER TABLE $name $query");
|
||||
if (PEAR::isError($result)) {
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
if (array_key_exists('rename', $changes)) {
|
||||
foreach ($changes['rename'] as $field_name => $field) {
|
||||
$field_name = $this->_db->quoteIdentifier($field_name);
|
||||
$result = $this->_db->query("ALTER TABLE $name RENAME COLUMN $field_name TO ".$this->_db->quoteIdentifier($field['name']));
|
||||
if (PEAR::isError($result)) {
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$name = $this->_db->quoteIdentifier($name);
|
||||
if (array_key_exists('name', $changes)) {
|
||||
$change_name = $this->_db->quoteIdentifier($changes['name']);
|
||||
$result = $this->_db->query("ALTER TABLE $name RENAME TO ".$change_name);
|
||||
if (PEAR::isError($result)) {
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
return DB_OK;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
1173
sites/all/modules/civicrm/packages/DB/Table/QuickForm.php
Normal file
1173
sites/all/modules/civicrm/packages/DB/Table/QuickForm.php
Normal file
File diff suppressed because it is too large
Load diff
454
sites/all/modules/civicrm/packages/DB/Table/Valid.php
Normal file
454
sites/all/modules/civicrm/packages/DB/Table/Valid.php
Normal file
|
|
@ -0,0 +1,454 @@
|
|||
<?php
|
||||
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* DB_Table_Valid validates values against DB_Table column types.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE:
|
||||
*
|
||||
* Copyright (c) 1997-2007, Paul M. Jones <pmjones@php.net>
|
||||
* David C. Morse <morse@php.net>
|
||||
* Mark Wiesemann <wiesemann@php.net>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * The names of the authors may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @category Database
|
||||
* @package DB_Table
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
* @author David C. Morse <morse@php.net>
|
||||
* @author Mark Wiesemann <wiesemann@php.net>
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version CVS: $Id: Valid.php,v 1.10 2007/12/13 16:52:15 wiesemann Exp $
|
||||
* @link http://pear.php.net/package/DB_Table
|
||||
*/
|
||||
|
||||
/**
|
||||
* DB_Table class for constants and other globals.
|
||||
*/
|
||||
require_once 'DB/Table.php';
|
||||
|
||||
|
||||
/**
|
||||
* validation ranges for integers
|
||||
*/
|
||||
if (! isset($GLOBALS['_DB_TABLE']['valid'])) {
|
||||
$GLOBALS['_DB_TABLE']['valid'] = array(
|
||||
'smallint' => array(pow(-2, 15), pow(+2, 15) - 1),
|
||||
'integer' => array(pow(-2, 31), pow(+2, 31) - 1),
|
||||
'bigint' => array(pow(-2, 63), pow(+2, 63) - 1)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* DB_Table_Valid validates values against DB_Table column types.
|
||||
*
|
||||
* @category Database
|
||||
* @package DB_Table
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
* @author David C. Morse <morse@php.net>
|
||||
* @author Mark Wiesemann <wiesemann@php.net>
|
||||
* @version Release: 1.5.6
|
||||
* @link http://pear.php.net/package/DB_Table
|
||||
*/
|
||||
|
||||
class DB_Table_Valid {
|
||||
|
||||
/**
|
||||
*
|
||||
* Check if a value validates against the 'boolean' data type.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param mixed $value The value to validate.
|
||||
*
|
||||
* @return boolean True if the value is valid for the data type, false
|
||||
* if not.
|
||||
*
|
||||
*/
|
||||
|
||||
function isBoolean($value)
|
||||
{
|
||||
if ($value === true || $value === false) {
|
||||
return true;
|
||||
} elseif (is_numeric($value) && ($value == 0 || $value == 1)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Check if a value validates against the 'char' and 'varchar' data type.
|
||||
*
|
||||
* We allow most anything here, only checking that the length is in range.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param mixed $value The value to validate.
|
||||
*
|
||||
* @return boolean True if the value is valid for the data type, false
|
||||
* if not.
|
||||
*
|
||||
*/
|
||||
|
||||
function isChar($value, $colsize)
|
||||
{
|
||||
$is_scalar = (! is_array($value) && ! is_object($value));
|
||||
$in_range = (strlen($value) <= $colsize);
|
||||
return $is_scalar && $in_range;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Check if a value validates against the 'smallint' data type.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param mixed $value The value to validate.
|
||||
*
|
||||
* @return boolean True if the value is valid for the data type, false
|
||||
* if not.
|
||||
*
|
||||
*/
|
||||
|
||||
function isSmallint($value)
|
||||
{
|
||||
return is_integer($value) &&
|
||||
($value >= $GLOBALS['_DB_TABLE']['valid']['smallint'][0]) &&
|
||||
($value <= $GLOBALS['_DB_TABLE']['valid']['smallint'][1]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Check if a value validates against the 'integer' data type.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param mixed $value The value to validate.
|
||||
*
|
||||
* @return boolean True if the value is valid for the data type, false
|
||||
* if not.
|
||||
*
|
||||
*/
|
||||
|
||||
function isInteger($value)
|
||||
{
|
||||
return is_integer($value) &&
|
||||
($value >= $GLOBALS['_DB_TABLE']['valid']['integer'][0]) &&
|
||||
($value <= $GLOBALS['_DB_TABLE']['valid']['integer'][1]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Check if a value validates against the 'bigint' data type.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param mixed $value The value to validate.
|
||||
*
|
||||
* @return boolean True if the value is valid for the data type, false
|
||||
* if not.
|
||||
*
|
||||
*/
|
||||
|
||||
function isBigint($value)
|
||||
{
|
||||
return is_integer($value) &&
|
||||
($value >= $GLOBALS['_DB_TABLE']['valid']['bigint'][0]) &&
|
||||
($value <= $GLOBALS['_DB_TABLE']['valid']['bigint'][1]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Check if a value validates against the 'decimal' data type.
|
||||
*
|
||||
* For the column defined "DECIMAL(5,2)" standard SQL requires that
|
||||
* the column be able to store any value with 5 digits and 2
|
||||
* decimals. In this case, therefore, the range of values that can be
|
||||
* stored in the column is from -999.99 to 999.99. DB_Table attempts
|
||||
* to enforce this behavior regardless of the RDBMS backend behavior.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param mixed $value The value to validate.
|
||||
*
|
||||
* @param string $colsize The 'size' to use for validation (to make
|
||||
* sure of min/max and decimal places).
|
||||
*
|
||||
* @param string $colscope The 'scope' to use for validation (to make
|
||||
* sure of min/max and decimal places).
|
||||
*
|
||||
* @return boolean True if the value is valid for the data type, false
|
||||
* if not.
|
||||
*
|
||||
*/
|
||||
|
||||
function isDecimal($value, $colsize, $colscope)
|
||||
{
|
||||
if (! is_numeric($value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// maximum number of digits allowed to the left
|
||||
// and right of the decimal point.
|
||||
$right_max = $colscope;
|
||||
$left_max = $colsize - $colscope;
|
||||
|
||||
// ignore negative signs in all validation
|
||||
$value = str_replace('-', '', $value);
|
||||
|
||||
// find the decimal point, then get the left
|
||||
// and right portions.
|
||||
$pos = strpos($value, '.');
|
||||
if ($pos === false) {
|
||||
$left = $value;
|
||||
$right = '';
|
||||
} else {
|
||||
$left = substr($value, 0, $pos);
|
||||
$right = substr($value, $pos+1);
|
||||
}
|
||||
|
||||
// how long are the left and right portions?
|
||||
$left_len = strlen($left);
|
||||
$right_len = strlen($right);
|
||||
|
||||
// do the portions exceed their maxes?
|
||||
if ($left_len > $left_max ||
|
||||
$right_len > $right_max) {
|
||||
// one or the other exceeds the max lengths
|
||||
return false;
|
||||
} else {
|
||||
// both are within parameters
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Check if a value validates against the 'single' data type.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param mixed $value The value to validate.
|
||||
*
|
||||
* @return boolean True if the value is valid for the data type, false
|
||||
* if not.
|
||||
*
|
||||
*/
|
||||
|
||||
function isSingle($value)
|
||||
{
|
||||
return is_float($value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Check if a value validates against the 'double' data type.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param mixed $value The value to validate.
|
||||
*
|
||||
* @return boolean True if the value is valid for the data type, false
|
||||
* if not.
|
||||
*
|
||||
*/
|
||||
|
||||
function isDouble($value)
|
||||
{
|
||||
return is_float($value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Check if a value validates against the 'time' data type.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param mixed $value The value to validate.
|
||||
*
|
||||
* @return boolean True if the value is valid for the data type, false
|
||||
* if not.
|
||||
*
|
||||
*/
|
||||
|
||||
function isTime($value)
|
||||
{
|
||||
// hh:ii:ss
|
||||
// 01234567
|
||||
$h = substr($value, 0, 2);
|
||||
$s1 = substr($value, 2, 1);
|
||||
$i = substr($value, 3, 2);
|
||||
$s2 = substr($value, 5, 1);
|
||||
$s = substr($value, 6, 2);
|
||||
|
||||
// time check
|
||||
if (strlen($value) != 8 ||
|
||||
! is_numeric($h) || $h < 0 || $h > 23 ||
|
||||
$s1 != ':' ||
|
||||
! is_numeric($i) || $i < 0 || $i > 59 ||
|
||||
$s2 != ':' ||
|
||||
! is_numeric($s) || $s < 0 || $s > 59) {
|
||||
|
||||
return false;
|
||||
|
||||
} else {
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Check if a value validates against the 'date' data type.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param mixed $value The value to validate.
|
||||
*
|
||||
* @return boolean True if the value is valid for the data type, false
|
||||
* if not.
|
||||
*
|
||||
*/
|
||||
|
||||
function isDate($value)
|
||||
{
|
||||
// yyyy-mm-dd
|
||||
// 0123456789
|
||||
$y = substr($value, 0, 4);
|
||||
$s1 = substr($value, 4, 1);
|
||||
$m = substr($value, 5, 2);
|
||||
$s2 = substr($value, 7, 1);
|
||||
$d = substr($value, 8, 2);
|
||||
|
||||
// date check
|
||||
if (strlen($value) != 10 || $s1 != '-' || $s2 != '-' ||
|
||||
! checkdate($m, $d, $y)) {
|
||||
|
||||
return false;
|
||||
|
||||
} else {
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Check if a value validates against the 'timestamp' data type.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param mixed $value The value to validate.
|
||||
*
|
||||
* @return boolean True if the value is valid for the data type, false
|
||||
* if not.
|
||||
*
|
||||
*/
|
||||
|
||||
function isTimestamp($value)
|
||||
{
|
||||
// yyyy-mm-dd hh:ii:ss
|
||||
// 0123456789012345678
|
||||
$date = substr($value, 0, 10);
|
||||
$sep = substr($value, 10, 1);
|
||||
$time = substr($value, 11, 8);
|
||||
|
||||
if (strlen($value) != 19 || $sep != ' ' ||
|
||||
! DB_Table_Valid::isDate($date) ||
|
||||
! DB_Table_Valid::isTime($time)) {
|
||||
|
||||
return false;
|
||||
|
||||
} else {
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Check if a value validates against the 'clob' data type.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param mixed $value The value to validate.
|
||||
*
|
||||
* @return boolean True if the value is valid for the data type, false
|
||||
* if not.
|
||||
*
|
||||
*/
|
||||
|
||||
function isClob($value)
|
||||
{
|
||||
return is_string($value);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
111
sites/all/modules/civicrm/packages/DB/Table/XML.php
Normal file
111
sites/all/modules/civicrm/packages/DB/Table/XML.php
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
<?php
|
||||
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* A few simple static methods for writing XML
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE:
|
||||
*
|
||||
* Copyright (c) 1997-2007, Paul M. Jones <pmjones@php.net>
|
||||
* David C. Morse <morse@php.net>
|
||||
* Mark Wiesemann <wiesemann@php.net>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * The names of the authors may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @category Database
|
||||
* @package DB_Table
|
||||
* @author David C. Morse <morse@php.net>
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version CVS: $Id: XML.php,v 1.2 2007/12/13 16:52:15 wiesemann Exp $
|
||||
* @link http://pear.php.net/package/DB_Table
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class DB_Table_XML contains a few simple static methods for writing XML
|
||||
*
|
||||
* @category Database
|
||||
* @package DB_Table
|
||||
* @author David C. Morse <morse@php.net>
|
||||
* @version Release: 1.5.6
|
||||
* @link http://pear.php.net/package/DB_Table
|
||||
*/
|
||||
|
||||
class DB_Table_XML
|
||||
{
|
||||
|
||||
/**
|
||||
* Returns XML closing tag <tag>, increases $indent by 3 spaces
|
||||
*
|
||||
* @static
|
||||
* @param string $tag XML element tag name
|
||||
* @param string $indent current indentation, string of spaces
|
||||
* @return string XML opening tag
|
||||
* @access public
|
||||
*/
|
||||
function openTag($tag, &$indent)
|
||||
{
|
||||
$old_indent = $indent;
|
||||
$indent = $indent . ' ';
|
||||
return $old_indent . "<$tag>";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns XML closing tag </tag>, decreases $indent by 3 spaces
|
||||
*
|
||||
* @static
|
||||
* @param string $tag XML element tag name
|
||||
* @param string $indent current indentation, string of spaces
|
||||
* @return string XML closing tag
|
||||
* @access public
|
||||
*/
|
||||
function closeTag($tag, &$indent)
|
||||
{
|
||||
$indent = substr($indent, 0, -3);
|
||||
return $indent . "</$tag>";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns string single line XML element <tag>text</tag>
|
||||
*
|
||||
* @static
|
||||
* @param string $tag XML element tag name
|
||||
* @param string $text element contents
|
||||
* @param string $indent current indentation, string of spaces
|
||||
* @return string single-line XML element
|
||||
* @access public
|
||||
*/
|
||||
function lineElement($tag, $text, $indent)
|
||||
{
|
||||
return $indent . "<$tag>$text</$tag>";
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
2262
sites/all/modules/civicrm/packages/DB/common.php
Normal file
2262
sites/all/modules/civicrm/packages/DB/common.php
Normal file
File diff suppressed because it is too large
Load diff
510
sites/all/modules/civicrm/packages/DB/dbase.php
Normal file
510
sites/all/modules/civicrm/packages/DB/dbase.php
Normal file
|
|
@ -0,0 +1,510 @@
|
|||
<?php
|
||||
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* The PEAR DB driver for PHP's dbase extension
|
||||
* for interacting with dBase databases
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.0 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category Database
|
||||
* @package DB
|
||||
* @author Tomas V.V. Cox <cox@idecnet.com>
|
||||
* @author Daniel Convissor <danielc@php.net>
|
||||
* @copyright 1997-2007 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version CVS: $Id: dbase.php,v 1.45 2007/09/21 13:40:41 aharvey Exp $
|
||||
* @link http://pear.php.net/package/DB
|
||||
*/
|
||||
|
||||
/**
|
||||
* Obtain the DB_common class so it can be extended from
|
||||
*/
|
||||
require_once 'DB/common.php';
|
||||
|
||||
/**
|
||||
* The methods PEAR DB uses to interact with PHP's dbase extension
|
||||
* for interacting with dBase databases
|
||||
*
|
||||
* These methods overload the ones declared in DB_common.
|
||||
*
|
||||
* @category Database
|
||||
* @package DB
|
||||
* @author Tomas V.V. Cox <cox@idecnet.com>
|
||||
* @author Daniel Convissor <danielc@php.net>
|
||||
* @copyright 1997-2007 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version Release: 1.7.13
|
||||
* @link http://pear.php.net/package/DB
|
||||
*/
|
||||
class DB_dbase extends DB_common
|
||||
{
|
||||
// {{{ properties
|
||||
|
||||
/**
|
||||
* The DB driver type (mysql, oci8, odbc, etc.)
|
||||
* @var string
|
||||
*/
|
||||
var $phptype = 'dbase';
|
||||
|
||||
/**
|
||||
* The database syntax variant to be used (db2, access, etc.), if any
|
||||
* @var string
|
||||
*/
|
||||
var $dbsyntax = 'dbase';
|
||||
|
||||
/**
|
||||
* The capabilities of this DB implementation
|
||||
*
|
||||
* The 'new_link' element contains the PHP version that first provided
|
||||
* new_link support for this DBMS. Contains false if it's unsupported.
|
||||
*
|
||||
* Meaning of the 'limit' element:
|
||||
* + 'emulate' = emulate with fetch row by number
|
||||
* + 'alter' = alter the query
|
||||
* + false = skip rows
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $features = array(
|
||||
'limit' => false,
|
||||
'new_link' => false,
|
||||
'numrows' => true,
|
||||
'pconnect' => false,
|
||||
'prepare' => false,
|
||||
'ssl' => false,
|
||||
'transactions' => false,
|
||||
);
|
||||
|
||||
/**
|
||||
* A mapping of native error codes to DB error codes
|
||||
* @var array
|
||||
*/
|
||||
var $errorcode_map = array(
|
||||
);
|
||||
|
||||
/**
|
||||
* The raw database connection created by PHP
|
||||
* @var resource
|
||||
*/
|
||||
var $connection;
|
||||
|
||||
/**
|
||||
* The DSN information for connecting to a database
|
||||
* @var array
|
||||
*/
|
||||
var $dsn = array();
|
||||
|
||||
|
||||
/**
|
||||
* A means of emulating result resources
|
||||
* @var array
|
||||
*/
|
||||
var $res_row = array();
|
||||
|
||||
/**
|
||||
* The quantity of results so far
|
||||
*
|
||||
* For emulating result resources.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
var $result = 0;
|
||||
|
||||
/**
|
||||
* Maps dbase data type id's to human readable strings
|
||||
*
|
||||
* The human readable values are based on the output of PHP's
|
||||
* dbase_get_header_info() function.
|
||||
*
|
||||
* @var array
|
||||
* @since Property available since Release 1.7.0
|
||||
*/
|
||||
var $types = array(
|
||||
'C' => 'character',
|
||||
'D' => 'date',
|
||||
'L' => 'boolean',
|
||||
'M' => 'memo',
|
||||
'N' => 'number',
|
||||
);
|
||||
|
||||
|
||||
// }}}
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* This constructor calls <kbd>$this->DB_common()</kbd>
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ connect()
|
||||
|
||||
/**
|
||||
* Connect to the database and create it if it doesn't exist
|
||||
*
|
||||
* Don't call this method directly. Use DB::connect() instead.
|
||||
*
|
||||
* PEAR DB's dbase driver supports the following extra DSN options:
|
||||
* + mode An integer specifying the read/write mode to use
|
||||
* (0 = read only, 1 = write only, 2 = read/write).
|
||||
* Available since PEAR DB 1.7.0.
|
||||
* + fields An array of arrays that PHP's dbase_create() function needs
|
||||
* to create a new database. This information is used if the
|
||||
* dBase file specified in the "database" segment of the DSN
|
||||
* does not exist. For more info, see the PHP manual's
|
||||
* {@link http://php.net/dbase_create dbase_create()} page.
|
||||
* Available since PEAR DB 1.7.0.
|
||||
*
|
||||
* Example of how to connect and establish a new dBase file if necessary:
|
||||
* <code>
|
||||
* require_once 'DB.php';
|
||||
*
|
||||
* $dsn = array(
|
||||
* 'phptype' => 'dbase',
|
||||
* 'database' => '/path/and/name/of/dbase/file',
|
||||
* 'mode' => 2,
|
||||
* 'fields' => array(
|
||||
* array('a', 'N', 5, 0),
|
||||
* array('b', 'C', 40),
|
||||
* array('c', 'C', 255),
|
||||
* array('d', 'C', 20),
|
||||
* ),
|
||||
* );
|
||||
* $options = array(
|
||||
* 'debug' => 2,
|
||||
* 'portability' => DB_PORTABILITY_ALL,
|
||||
* );
|
||||
*
|
||||
* $db = DB::connect($dsn, $options);
|
||||
* if (PEAR::isError($db)) {
|
||||
* die($db->getMessage());
|
||||
* }
|
||||
* </code>
|
||||
*
|
||||
* @param array $dsn the data source name
|
||||
* @param bool $persistent should the connection be persistent?
|
||||
*
|
||||
* @return int DB_OK on success. A DB_Error object on failure.
|
||||
*/
|
||||
function connect($dsn, $persistent = false)
|
||||
{
|
||||
if (!PEAR::loadExtension('dbase')) {
|
||||
return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND);
|
||||
}
|
||||
|
||||
$this->dsn = $dsn;
|
||||
if ($dsn['dbsyntax']) {
|
||||
$this->dbsyntax = $dsn['dbsyntax'];
|
||||
}
|
||||
|
||||
/*
|
||||
* Turn track_errors on for entire script since $php_errormsg
|
||||
* is the only way to find errors from the dbase extension.
|
||||
*/
|
||||
@ini_set('track_errors', 1);
|
||||
$php_errormsg = '';
|
||||
|
||||
if (!file_exists($dsn['database'])) {
|
||||
$this->dsn['mode'] = 2;
|
||||
if (empty($dsn['fields']) || !is_array($dsn['fields'])) {
|
||||
return $this->raiseError(DB_ERROR_CONNECT_FAILED,
|
||||
null, null, null,
|
||||
'the dbase file does not exist and '
|
||||
. 'it could not be created because '
|
||||
. 'the "fields" element of the DSN '
|
||||
. 'is not properly set');
|
||||
}
|
||||
$this->connection = @dbase_create($dsn['database'],
|
||||
$dsn['fields']);
|
||||
if (!$this->connection) {
|
||||
return $this->raiseError(DB_ERROR_CONNECT_FAILED,
|
||||
null, null, null,
|
||||
'the dbase file does not exist and '
|
||||
. 'the attempt to create it failed: '
|
||||
. $php_errormsg);
|
||||
}
|
||||
} else {
|
||||
if (!isset($this->dsn['mode'])) {
|
||||
$this->dsn['mode'] = 0;
|
||||
}
|
||||
$this->connection = @dbase_open($dsn['database'],
|
||||
$this->dsn['mode']);
|
||||
if (!$this->connection) {
|
||||
return $this->raiseError(DB_ERROR_CONNECT_FAILED,
|
||||
null, null, null,
|
||||
$php_errormsg);
|
||||
}
|
||||
}
|
||||
return DB_OK;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ disconnect()
|
||||
|
||||
/**
|
||||
* Disconnects from the database server
|
||||
*
|
||||
* @return bool TRUE on success, FALSE on failure
|
||||
*/
|
||||
function disconnect()
|
||||
{
|
||||
$ret = @dbase_close($this->connection);
|
||||
$this->connection = null;
|
||||
return $ret;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ &query()
|
||||
|
||||
function &query($query = null)
|
||||
{
|
||||
// emulate result resources
|
||||
$this->res_row[(int)$this->result] = 0;
|
||||
$tmp = new DB_result($this, $this->result++);
|
||||
return $tmp;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ fetchInto()
|
||||
|
||||
/**
|
||||
* Places a row from the result set into the given array
|
||||
*
|
||||
* Formating of the array and the data therein are configurable.
|
||||
* See DB_result::fetchInto() for more information.
|
||||
*
|
||||
* This method is not meant to be called directly. Use
|
||||
* DB_result::fetchInto() instead. It can't be declared "protected"
|
||||
* because DB_result is a separate object.
|
||||
*
|
||||
* @param resource $result the query result resource
|
||||
* @param array $arr the referenced array to put the data in
|
||||
* @param int $fetchmode how the resulting array should be indexed
|
||||
* @param int $rownum the row number to fetch (0 = first row)
|
||||
*
|
||||
* @return mixed DB_OK on success, NULL when the end of a result set is
|
||||
* reached or on failure
|
||||
*
|
||||
* @see DB_result::fetchInto()
|
||||
*/
|
||||
function fetchInto($result, &$arr, $fetchmode, $rownum = null)
|
||||
{
|
||||
if ($rownum === null) {
|
||||
$rownum = $this->res_row[(int)$result]++;
|
||||
}
|
||||
if ($fetchmode & DB_FETCHMODE_ASSOC) {
|
||||
$arr = @dbase_get_record_with_names($this->connection, $rownum);
|
||||
if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE && $arr) {
|
||||
$arr = array_change_key_case($arr, CASE_LOWER);
|
||||
}
|
||||
} else {
|
||||
$arr = @dbase_get_record($this->connection, $rownum);
|
||||
}
|
||||
if (!$arr) {
|
||||
return null;
|
||||
}
|
||||
if ($this->options['portability'] & DB_PORTABILITY_RTRIM) {
|
||||
$this->_rtrimArrayValues($arr);
|
||||
}
|
||||
if ($this->options['portability'] & DB_PORTABILITY_NULL_TO_EMPTY) {
|
||||
$this->_convertNullArrayValuesToEmpty($arr);
|
||||
}
|
||||
return DB_OK;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ freeResult()
|
||||
|
||||
/**
|
||||
* Deletes the result set and frees the memory occupied by the result set.
|
||||
*
|
||||
* This method is a no-op for dbase, as there aren't result resources in
|
||||
* the same sense as most other database backends.
|
||||
*
|
||||
* @param resource $result PHP's query result resource
|
||||
*
|
||||
* @return bool TRUE on success, FALSE if $result is invalid
|
||||
*
|
||||
* @see DB_result::free()
|
||||
*/
|
||||
function freeResult($result)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ numCols()
|
||||
|
||||
/**
|
||||
* Gets the number of columns in a result set
|
||||
*
|
||||
* This method is not meant to be called directly. Use
|
||||
* DB_result::numCols() instead. It can't be declared "protected"
|
||||
* because DB_result is a separate object.
|
||||
*
|
||||
* @param resource $result PHP's query result resource
|
||||
*
|
||||
* @return int the number of columns. A DB_Error object on failure.
|
||||
*
|
||||
* @see DB_result::numCols()
|
||||
*/
|
||||
function numCols($foo)
|
||||
{
|
||||
return @dbase_numfields($this->connection);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ numRows()
|
||||
|
||||
/**
|
||||
* Gets the number of rows in a result set
|
||||
*
|
||||
* This method is not meant to be called directly. Use
|
||||
* DB_result::numRows() instead. It can't be declared "protected"
|
||||
* because DB_result is a separate object.
|
||||
*
|
||||
* @param resource $result PHP's query result resource
|
||||
*
|
||||
* @return int the number of rows. A DB_Error object on failure.
|
||||
*
|
||||
* @see DB_result::numRows()
|
||||
*/
|
||||
function numRows($foo)
|
||||
{
|
||||
return @dbase_numrecords($this->connection);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ quoteBoolean()
|
||||
|
||||
/**
|
||||
* Formats a boolean value for use within a query in a locale-independent
|
||||
* manner.
|
||||
*
|
||||
* @param boolean the boolean value to be quoted.
|
||||
* @return string the quoted string.
|
||||
* @see DB_common::quoteSmart()
|
||||
* @since Method available since release 1.7.8.
|
||||
*/
|
||||
function quoteBoolean($boolean) {
|
||||
return $boolean ? 'T' : 'F';
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ tableInfo()
|
||||
|
||||
/**
|
||||
* Returns information about the current database
|
||||
*
|
||||
* @param mixed $result THIS IS UNUSED IN DBASE. The current database
|
||||
* is examined regardless of what is provided here.
|
||||
* @param int $mode a valid tableInfo mode
|
||||
*
|
||||
* @return array an associative array with the information requested.
|
||||
* A DB_Error object on failure.
|
||||
*
|
||||
* @see DB_common::tableInfo()
|
||||
* @since Method available since Release 1.7.0
|
||||
*/
|
||||
function tableInfo($result = null, $mode = null)
|
||||
{
|
||||
if (function_exists('dbase_get_header_info')) {
|
||||
$id = @dbase_get_header_info($this->connection);
|
||||
if (!$id && $php_errormsg) {
|
||||
return $this->raiseError(DB_ERROR,
|
||||
null, null, null,
|
||||
$php_errormsg);
|
||||
}
|
||||
} else {
|
||||
/*
|
||||
* This segment for PHP 4 is loosely based on code by
|
||||
* Hadi Rusiah <deegos@yahoo.com> in the comments on
|
||||
* the dBase reference page in the PHP manual.
|
||||
*/
|
||||
$db = @fopen($this->dsn['database'], 'r');
|
||||
if (!$db) {
|
||||
return $this->raiseError(DB_ERROR_CONNECT_FAILED,
|
||||
null, null, null,
|
||||
$php_errormsg);
|
||||
}
|
||||
|
||||
$id = array();
|
||||
$i = 0;
|
||||
|
||||
$line = fread($db, 32);
|
||||
while (!feof($db)) {
|
||||
$line = fread($db, 32);
|
||||
if (substr($line, 0, 1) == chr(13)) {
|
||||
break;
|
||||
} else {
|
||||
$pos = strpos(substr($line, 0, 10), chr(0));
|
||||
$pos = ($pos == 0 ? 10 : $pos);
|
||||
$id[$i] = array(
|
||||
'name' => substr($line, 0, $pos),
|
||||
'type' => $this->types[substr($line, 11, 1)],
|
||||
'length' => ord(substr($line, 16, 1)),
|
||||
'precision' => ord(substr($line, 17, 1)),
|
||||
);
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
fclose($db);
|
||||
}
|
||||
|
||||
if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE) {
|
||||
$case_func = 'strtolower';
|
||||
} else {
|
||||
$case_func = 'strval';
|
||||
}
|
||||
|
||||
$res = array();
|
||||
$count = count($id);
|
||||
|
||||
if ($mode) {
|
||||
$res['num_fields'] = $count;
|
||||
}
|
||||
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
$res[$i] = array(
|
||||
'table' => $this->dsn['database'],
|
||||
'name' => $case_func($id[$i]['name']),
|
||||
'type' => $id[$i]['type'],
|
||||
'len' => $id[$i]['length'],
|
||||
'flags' => ''
|
||||
);
|
||||
if ($mode & DB_TABLEINFO_ORDER) {
|
||||
$res['order'][$res[$i]['name']] = $i;
|
||||
}
|
||||
if ($mode & DB_TABLEINFO_ORDERTABLE) {
|
||||
$res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i;
|
||||
}
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
// }}}
|
||||
}
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* tab-width: 4
|
||||
* c-basic-offset: 4
|
||||
* End:
|
||||
*/
|
||||
|
||||
?>
|
||||
963
sites/all/modules/civicrm/packages/DB/mssql.php
Normal file
963
sites/all/modules/civicrm/packages/DB/mssql.php
Normal file
|
|
@ -0,0 +1,963 @@
|
|||
<?php
|
||||
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* The PEAR DB driver for PHP's mssql extension
|
||||
* for interacting with Microsoft SQL Server databases
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.0 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category Database
|
||||
* @package DB
|
||||
* @author Sterling Hughes <sterling@php.net>
|
||||
* @author Daniel Convissor <danielc@php.net>
|
||||
* @copyright 1997-2007 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version CVS: $Id: mssql.php,v 1.92 2007/09/21 13:40:41 aharvey Exp $
|
||||
* @link http://pear.php.net/package/DB
|
||||
*/
|
||||
|
||||
/**
|
||||
* Obtain the DB_common class so it can be extended from
|
||||
*/
|
||||
require_once 'DB/common.php';
|
||||
|
||||
/**
|
||||
* The methods PEAR DB uses to interact with PHP's mssql extension
|
||||
* for interacting with Microsoft SQL Server databases
|
||||
*
|
||||
* These methods overload the ones declared in DB_common.
|
||||
*
|
||||
* DB's mssql driver is only for Microsfoft SQL Server databases.
|
||||
*
|
||||
* If you're connecting to a Sybase database, you MUST specify "sybase"
|
||||
* as the "phptype" in the DSN.
|
||||
*
|
||||
* This class only works correctly if you have compiled PHP using
|
||||
* --with-mssql=[dir_to_FreeTDS].
|
||||
*
|
||||
* @category Database
|
||||
* @package DB
|
||||
* @author Sterling Hughes <sterling@php.net>
|
||||
* @author Daniel Convissor <danielc@php.net>
|
||||
* @copyright 1997-2007 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version Release: 1.7.13
|
||||
* @link http://pear.php.net/package/DB
|
||||
*/
|
||||
class DB_mssql extends DB_common
|
||||
{
|
||||
// {{{ properties
|
||||
|
||||
/**
|
||||
* The DB driver type (mysql, oci8, odbc, etc.)
|
||||
* @var string
|
||||
*/
|
||||
var $phptype = 'mssql';
|
||||
|
||||
/**
|
||||
* The database syntax variant to be used (db2, access, etc.), if any
|
||||
* @var string
|
||||
*/
|
||||
var $dbsyntax = 'mssql';
|
||||
|
||||
/**
|
||||
* The capabilities of this DB implementation
|
||||
*
|
||||
* The 'new_link' element contains the PHP version that first provided
|
||||
* new_link support for this DBMS. Contains false if it's unsupported.
|
||||
*
|
||||
* Meaning of the 'limit' element:
|
||||
* + 'emulate' = emulate with fetch row by number
|
||||
* + 'alter' = alter the query
|
||||
* + false = skip rows
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $features = array(
|
||||
'limit' => 'emulate',
|
||||
'new_link' => false,
|
||||
'numrows' => true,
|
||||
'pconnect' => true,
|
||||
'prepare' => false,
|
||||
'ssl' => false,
|
||||
'transactions' => true,
|
||||
);
|
||||
|
||||
/**
|
||||
* A mapping of native error codes to DB error codes
|
||||
* @var array
|
||||
*/
|
||||
// XXX Add here error codes ie: 'S100E' => DB_ERROR_SYNTAX
|
||||
var $errorcode_map = array(
|
||||
102 => DB_ERROR_SYNTAX,
|
||||
110 => DB_ERROR_VALUE_COUNT_ON_ROW,
|
||||
155 => DB_ERROR_NOSUCHFIELD,
|
||||
156 => DB_ERROR_SYNTAX,
|
||||
170 => DB_ERROR_SYNTAX,
|
||||
207 => DB_ERROR_NOSUCHFIELD,
|
||||
208 => DB_ERROR_NOSUCHTABLE,
|
||||
245 => DB_ERROR_INVALID_NUMBER,
|
||||
319 => DB_ERROR_SYNTAX,
|
||||
321 => DB_ERROR_NOSUCHFIELD,
|
||||
325 => DB_ERROR_SYNTAX,
|
||||
336 => DB_ERROR_SYNTAX,
|
||||
515 => DB_ERROR_CONSTRAINT_NOT_NULL,
|
||||
547 => DB_ERROR_CONSTRAINT,
|
||||
1018 => DB_ERROR_SYNTAX,
|
||||
1035 => DB_ERROR_SYNTAX,
|
||||
1913 => DB_ERROR_ALREADY_EXISTS,
|
||||
2209 => DB_ERROR_SYNTAX,
|
||||
2223 => DB_ERROR_SYNTAX,
|
||||
2248 => DB_ERROR_SYNTAX,
|
||||
2256 => DB_ERROR_SYNTAX,
|
||||
2257 => DB_ERROR_SYNTAX,
|
||||
2627 => DB_ERROR_CONSTRAINT,
|
||||
2714 => DB_ERROR_ALREADY_EXISTS,
|
||||
3607 => DB_ERROR_DIVZERO,
|
||||
3701 => DB_ERROR_NOSUCHTABLE,
|
||||
7630 => DB_ERROR_SYNTAX,
|
||||
8134 => DB_ERROR_DIVZERO,
|
||||
9303 => DB_ERROR_SYNTAX,
|
||||
9317 => DB_ERROR_SYNTAX,
|
||||
9318 => DB_ERROR_SYNTAX,
|
||||
9331 => DB_ERROR_SYNTAX,
|
||||
9332 => DB_ERROR_SYNTAX,
|
||||
15253 => DB_ERROR_SYNTAX,
|
||||
);
|
||||
|
||||
/**
|
||||
* The raw database connection created by PHP
|
||||
* @var resource
|
||||
*/
|
||||
var $connection;
|
||||
|
||||
/**
|
||||
* The DSN information for connecting to a database
|
||||
* @var array
|
||||
*/
|
||||
var $dsn = array();
|
||||
|
||||
|
||||
/**
|
||||
* Should data manipulation queries be committed automatically?
|
||||
* @var bool
|
||||
* @access private
|
||||
*/
|
||||
var $autocommit = true;
|
||||
|
||||
/**
|
||||
* The quantity of transactions begun
|
||||
*
|
||||
* {@internal While this is private, it can't actually be designated
|
||||
* private in PHP 5 because it is directly accessed in the test suite.}}
|
||||
*
|
||||
* @var integer
|
||||
* @access private
|
||||
*/
|
||||
var $transaction_opcount = 0;
|
||||
|
||||
/**
|
||||
* The database specified in the DSN
|
||||
*
|
||||
* It's a fix to allow calls to different databases in the same script.
|
||||
*
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_db = null;
|
||||
|
||||
|
||||
// }}}
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* This constructor calls <kbd>$this->DB_common()</kbd>
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ connect()
|
||||
|
||||
/**
|
||||
* Connect to the database server, log in and open the database
|
||||
*
|
||||
* Don't call this method directly. Use DB::connect() instead.
|
||||
*
|
||||
* @param array $dsn the data source name
|
||||
* @param bool $persistent should the connection be persistent?
|
||||
*
|
||||
* @return int DB_OK on success. A DB_Error object on failure.
|
||||
*/
|
||||
function connect($dsn, $persistent = false)
|
||||
{
|
||||
if (!PEAR::loadExtension('mssql') && !PEAR::loadExtension('sybase')
|
||||
&& !PEAR::loadExtension('sybase_ct'))
|
||||
{
|
||||
return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND);
|
||||
}
|
||||
|
||||
$this->dsn = $dsn;
|
||||
if ($dsn['dbsyntax']) {
|
||||
$this->dbsyntax = $dsn['dbsyntax'];
|
||||
}
|
||||
|
||||
$params = array(
|
||||
$dsn['hostspec'] ? $dsn['hostspec'] : 'localhost',
|
||||
$dsn['username'] ? $dsn['username'] : null,
|
||||
$dsn['password'] ? $dsn['password'] : null,
|
||||
);
|
||||
if ($dsn['port']) {
|
||||
$params[0] .= ((substr(PHP_OS, 0, 3) == 'WIN') ? ',' : ':')
|
||||
. $dsn['port'];
|
||||
}
|
||||
|
||||
$connect_function = $persistent ? 'mssql_pconnect' : 'mssql_connect';
|
||||
|
||||
$this->connection = @call_user_func_array($connect_function, $params);
|
||||
|
||||
if (!$this->connection) {
|
||||
return $this->raiseError(DB_ERROR_CONNECT_FAILED,
|
||||
null, null, null,
|
||||
@mssql_get_last_message());
|
||||
}
|
||||
if ($dsn['database']) {
|
||||
if (!@mssql_select_db($dsn['database'], $this->connection)) {
|
||||
return $this->raiseError(DB_ERROR_NODBSELECTED,
|
||||
null, null, null,
|
||||
@mssql_get_last_message());
|
||||
}
|
||||
$this->_db = $dsn['database'];
|
||||
}
|
||||
return DB_OK;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ disconnect()
|
||||
|
||||
/**
|
||||
* Disconnects from the database server
|
||||
*
|
||||
* @return bool TRUE on success, FALSE on failure
|
||||
*/
|
||||
function disconnect()
|
||||
{
|
||||
$ret = @mssql_close($this->connection);
|
||||
$this->connection = null;
|
||||
return $ret;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ simpleQuery()
|
||||
|
||||
/**
|
||||
* Sends a query to the database server
|
||||
*
|
||||
* @param string the SQL query string
|
||||
*
|
||||
* @return mixed + a PHP result resrouce for successful SELECT queries
|
||||
* + the DB_OK constant for other successful queries
|
||||
* + a DB_Error object on failure
|
||||
*/
|
||||
function simpleQuery($query)
|
||||
{
|
||||
$ismanip = $this->_checkManip($query);
|
||||
$this->last_query = $query;
|
||||
if (!@mssql_select_db($this->_db, $this->connection)) {
|
||||
return $this->mssqlRaiseError(DB_ERROR_NODBSELECTED);
|
||||
}
|
||||
$query = $this->modifyQuery($query);
|
||||
if (!$this->autocommit && $ismanip) {
|
||||
if ($this->transaction_opcount == 0) {
|
||||
$result = @mssql_query('BEGIN TRAN', $this->connection);
|
||||
if (!$result) {
|
||||
return $this->mssqlRaiseError();
|
||||
}
|
||||
}
|
||||
$this->transaction_opcount++;
|
||||
}
|
||||
$result = @mssql_query($query, $this->connection);
|
||||
if (!$result) {
|
||||
return $this->mssqlRaiseError();
|
||||
}
|
||||
// Determine which queries that should return data, and which
|
||||
// should return an error code only.
|
||||
return $ismanip ? DB_OK : $result;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ nextResult()
|
||||
|
||||
/**
|
||||
* Move the internal mssql result pointer to the next available result
|
||||
*
|
||||
* @param a valid fbsql result resource
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @return true if a result is available otherwise return false
|
||||
*/
|
||||
function nextResult($result)
|
||||
{
|
||||
return @mssql_next_result($result);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ fetchInto()
|
||||
|
||||
/**
|
||||
* Places a row from the result set into the given array
|
||||
*
|
||||
* Formating of the array and the data therein are configurable.
|
||||
* See DB_result::fetchInto() for more information.
|
||||
*
|
||||
* This method is not meant to be called directly. Use
|
||||
* DB_result::fetchInto() instead. It can't be declared "protected"
|
||||
* because DB_result is a separate object.
|
||||
*
|
||||
* @param resource $result the query result resource
|
||||
* @param array $arr the referenced array to put the data in
|
||||
* @param int $fetchmode how the resulting array should be indexed
|
||||
* @param int $rownum the row number to fetch (0 = first row)
|
||||
*
|
||||
* @return mixed DB_OK on success, NULL when the end of a result set is
|
||||
* reached or on failure
|
||||
*
|
||||
* @see DB_result::fetchInto()
|
||||
*/
|
||||
function fetchInto($result, &$arr, $fetchmode, $rownum = null)
|
||||
{
|
||||
if ($rownum !== null) {
|
||||
if (!@mssql_data_seek($result, $rownum)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if ($fetchmode & DB_FETCHMODE_ASSOC) {
|
||||
$arr = @mssql_fetch_assoc($result);
|
||||
if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE && $arr) {
|
||||
$arr = array_change_key_case($arr, CASE_LOWER);
|
||||
}
|
||||
} else {
|
||||
$arr = @mssql_fetch_row($result);
|
||||
}
|
||||
if (!$arr) {
|
||||
return null;
|
||||
}
|
||||
if ($this->options['portability'] & DB_PORTABILITY_RTRIM) {
|
||||
$this->_rtrimArrayValues($arr);
|
||||
}
|
||||
if ($this->options['portability'] & DB_PORTABILITY_NULL_TO_EMPTY) {
|
||||
$this->_convertNullArrayValuesToEmpty($arr);
|
||||
}
|
||||
return DB_OK;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ freeResult()
|
||||
|
||||
/**
|
||||
* Deletes the result set and frees the memory occupied by the result set
|
||||
*
|
||||
* This method is not meant to be called directly. Use
|
||||
* DB_result::free() instead. It can't be declared "protected"
|
||||
* because DB_result is a separate object.
|
||||
*
|
||||
* @param resource $result PHP's query result resource
|
||||
*
|
||||
* @return bool TRUE on success, FALSE if $result is invalid
|
||||
*
|
||||
* @see DB_result::free()
|
||||
*/
|
||||
function freeResult($result)
|
||||
{
|
||||
return is_resource($result) ? mssql_free_result($result) : false;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ numCols()
|
||||
|
||||
/**
|
||||
* Gets the number of columns in a result set
|
||||
*
|
||||
* This method is not meant to be called directly. Use
|
||||
* DB_result::numCols() instead. It can't be declared "protected"
|
||||
* because DB_result is a separate object.
|
||||
*
|
||||
* @param resource $result PHP's query result resource
|
||||
*
|
||||
* @return int the number of columns. A DB_Error object on failure.
|
||||
*
|
||||
* @see DB_result::numCols()
|
||||
*/
|
||||
function numCols($result)
|
||||
{
|
||||
$cols = @mssql_num_fields($result);
|
||||
if (!$cols) {
|
||||
return $this->mssqlRaiseError();
|
||||
}
|
||||
return $cols;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ numRows()
|
||||
|
||||
/**
|
||||
* Gets the number of rows in a result set
|
||||
*
|
||||
* This method is not meant to be called directly. Use
|
||||
* DB_result::numRows() instead. It can't be declared "protected"
|
||||
* because DB_result is a separate object.
|
||||
*
|
||||
* @param resource $result PHP's query result resource
|
||||
*
|
||||
* @return int the number of rows. A DB_Error object on failure.
|
||||
*
|
||||
* @see DB_result::numRows()
|
||||
*/
|
||||
function numRows($result)
|
||||
{
|
||||
$rows = @mssql_num_rows($result);
|
||||
if ($rows === false) {
|
||||
return $this->mssqlRaiseError();
|
||||
}
|
||||
return $rows;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ autoCommit()
|
||||
|
||||
/**
|
||||
* Enables or disables automatic commits
|
||||
*
|
||||
* @param bool $onoff true turns it on, false turns it off
|
||||
*
|
||||
* @return int DB_OK on success. A DB_Error object if the driver
|
||||
* doesn't support auto-committing transactions.
|
||||
*/
|
||||
function autoCommit($onoff = false)
|
||||
{
|
||||
// XXX if $this->transaction_opcount > 0, we should probably
|
||||
// issue a warning here.
|
||||
$this->autocommit = $onoff ? true : false;
|
||||
return DB_OK;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ commit()
|
||||
|
||||
/**
|
||||
* Commits the current transaction
|
||||
*
|
||||
* @return int DB_OK on success. A DB_Error object on failure.
|
||||
*/
|
||||
function commit()
|
||||
{
|
||||
if ($this->transaction_opcount > 0) {
|
||||
if (!@mssql_select_db($this->_db, $this->connection)) {
|
||||
return $this->mssqlRaiseError(DB_ERROR_NODBSELECTED);
|
||||
}
|
||||
$result = @mssql_query('COMMIT TRAN', $this->connection);
|
||||
$this->transaction_opcount = 0;
|
||||
if (!$result) {
|
||||
return $this->mssqlRaiseError();
|
||||
}
|
||||
}
|
||||
return DB_OK;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ rollback()
|
||||
|
||||
/**
|
||||
* Reverts the current transaction
|
||||
*
|
||||
* @return int DB_OK on success. A DB_Error object on failure.
|
||||
*/
|
||||
function rollback()
|
||||
{
|
||||
if ($this->transaction_opcount > 0) {
|
||||
if (!@mssql_select_db($this->_db, $this->connection)) {
|
||||
return $this->mssqlRaiseError(DB_ERROR_NODBSELECTED);
|
||||
}
|
||||
$result = @mssql_query('ROLLBACK TRAN', $this->connection);
|
||||
$this->transaction_opcount = 0;
|
||||
if (!$result) {
|
||||
return $this->mssqlRaiseError();
|
||||
}
|
||||
}
|
||||
return DB_OK;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ affectedRows()
|
||||
|
||||
/**
|
||||
* Determines the number of rows affected by a data maniuplation query
|
||||
*
|
||||
* 0 is returned for queries that don't manipulate data.
|
||||
*
|
||||
* @return int the number of rows. A DB_Error object on failure.
|
||||
*/
|
||||
function affectedRows()
|
||||
{
|
||||
if ($this->_last_query_manip) {
|
||||
$res = @mssql_query('select @@rowcount', $this->connection);
|
||||
if (!$res) {
|
||||
return $this->mssqlRaiseError();
|
||||
}
|
||||
$ar = @mssql_fetch_row($res);
|
||||
if (!$ar) {
|
||||
$result = 0;
|
||||
} else {
|
||||
@mssql_free_result($res);
|
||||
$result = $ar[0];
|
||||
}
|
||||
} else {
|
||||
$result = 0;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ nextId()
|
||||
|
||||
/**
|
||||
* Returns the next free id in a sequence
|
||||
*
|
||||
* @param string $seq_name name of the sequence
|
||||
* @param boolean $ondemand when true, the seqence is automatically
|
||||
* created if it does not exist
|
||||
*
|
||||
* @return int the next id number in the sequence.
|
||||
* A DB_Error object on failure.
|
||||
*
|
||||
* @see DB_common::nextID(), DB_common::getSequenceName(),
|
||||
* DB_mssql::createSequence(), DB_mssql::dropSequence()
|
||||
*/
|
||||
function nextId($seq_name, $ondemand = true)
|
||||
{
|
||||
$seqname = $this->getSequenceName($seq_name);
|
||||
if (!@mssql_select_db($this->_db, $this->connection)) {
|
||||
return $this->mssqlRaiseError(DB_ERROR_NODBSELECTED);
|
||||
}
|
||||
$repeat = 0;
|
||||
do {
|
||||
$this->pushErrorHandling(PEAR_ERROR_RETURN);
|
||||
$result = $this->query("INSERT INTO $seqname (vapor) VALUES (0)");
|
||||
$this->popErrorHandling();
|
||||
if ($ondemand && DB::isError($result) &&
|
||||
($result->getCode() == DB_ERROR || $result->getCode() == DB_ERROR_NOSUCHTABLE))
|
||||
{
|
||||
$repeat = 1;
|
||||
$result = $this->createSequence($seq_name);
|
||||
if (DB::isError($result)) {
|
||||
return $this->raiseError($result);
|
||||
}
|
||||
} elseif (!DB::isError($result)) {
|
||||
$result = $this->query("SELECT IDENT_CURRENT('$seqname')");
|
||||
if (DB::isError($result)) {
|
||||
/* Fallback code for MS SQL Server 7.0, which doesn't have
|
||||
* IDENT_CURRENT. This is *not* safe for concurrent
|
||||
* requests, and really, if you're using it, you're in a
|
||||
* world of hurt. Nevertheless, it's here to ensure BC. See
|
||||
* bug #181 for the gory details.*/
|
||||
$result = $this->query("SELECT @@IDENTITY FROM $seqname");
|
||||
}
|
||||
$repeat = 0;
|
||||
} else {
|
||||
$repeat = false;
|
||||
}
|
||||
} while ($repeat);
|
||||
if (DB::isError($result)) {
|
||||
return $this->raiseError($result);
|
||||
}
|
||||
$result = $result->fetchRow(DB_FETCHMODE_ORDERED);
|
||||
return $result[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new sequence
|
||||
*
|
||||
* @param string $seq_name name of the new sequence
|
||||
*
|
||||
* @return int DB_OK on success. A DB_Error object on failure.
|
||||
*
|
||||
* @see DB_common::createSequence(), DB_common::getSequenceName(),
|
||||
* DB_mssql::nextID(), DB_mssql::dropSequence()
|
||||
*/
|
||||
function createSequence($seq_name)
|
||||
{
|
||||
return $this->query('CREATE TABLE '
|
||||
. $this->getSequenceName($seq_name)
|
||||
. ' ([id] [int] IDENTITY (1, 1) NOT NULL,'
|
||||
. ' [vapor] [int] NULL)');
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ dropSequence()
|
||||
|
||||
/**
|
||||
* Deletes a sequence
|
||||
*
|
||||
* @param string $seq_name name of the sequence to be deleted
|
||||
*
|
||||
* @return int DB_OK on success. A DB_Error object on failure.
|
||||
*
|
||||
* @see DB_common::dropSequence(), DB_common::getSequenceName(),
|
||||
* DB_mssql::nextID(), DB_mssql::createSequence()
|
||||
*/
|
||||
function dropSequence($seq_name)
|
||||
{
|
||||
return $this->query('DROP TABLE ' . $this->getSequenceName($seq_name));
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ quoteIdentifier()
|
||||
|
||||
/**
|
||||
* Quotes a string so it can be safely used as a table or column name
|
||||
*
|
||||
* @param string $str identifier name to be quoted
|
||||
*
|
||||
* @return string quoted identifier string
|
||||
*
|
||||
* @see DB_common::quoteIdentifier()
|
||||
* @since Method available since Release 1.6.0
|
||||
*/
|
||||
function quoteIdentifier($str)
|
||||
{
|
||||
return '[' . str_replace(']', ']]', $str) . ']';
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ mssqlRaiseError()
|
||||
|
||||
/**
|
||||
* Produces a DB_Error object regarding the current problem
|
||||
*
|
||||
* @param int $errno if the error is being manually raised pass a
|
||||
* DB_ERROR* constant here. If this isn't passed
|
||||
* the error information gathered from the DBMS.
|
||||
*
|
||||
* @return object the DB_Error object
|
||||
*
|
||||
* @see DB_common::raiseError(),
|
||||
* DB_mssql::errorNative(), DB_mssql::errorCode()
|
||||
*/
|
||||
function mssqlRaiseError($code = null)
|
||||
{
|
||||
$message = @mssql_get_last_message();
|
||||
if (!$code) {
|
||||
$code = $this->errorNative();
|
||||
}
|
||||
return $this->raiseError($this->errorCode($code, $message),
|
||||
null, null, null, "$code - $message");
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ errorNative()
|
||||
|
||||
/**
|
||||
* Gets the DBMS' native error code produced by the last query
|
||||
*
|
||||
* @return int the DBMS' error code
|
||||
*/
|
||||
function errorNative()
|
||||
{
|
||||
$res = @mssql_query('select @@ERROR as ErrorCode', $this->connection);
|
||||
if (!$res) {
|
||||
return DB_ERROR;
|
||||
}
|
||||
$row = @mssql_fetch_row($res);
|
||||
return $row[0];
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ errorCode()
|
||||
|
||||
/**
|
||||
* Determines PEAR::DB error code from mssql's native codes.
|
||||
*
|
||||
* If <var>$nativecode</var> isn't known yet, it will be looked up.
|
||||
*
|
||||
* @param mixed $nativecode mssql error code, if known
|
||||
* @return integer an error number from a DB error constant
|
||||
* @see errorNative()
|
||||
*/
|
||||
function errorCode($nativecode = null, $msg = '')
|
||||
{
|
||||
if (!$nativecode) {
|
||||
$nativecode = $this->errorNative();
|
||||
}
|
||||
if (isset($this->errorcode_map[$nativecode])) {
|
||||
if ($nativecode == 3701
|
||||
&& preg_match('/Cannot drop the index/i', $msg))
|
||||
{
|
||||
return DB_ERROR_NOT_FOUND;
|
||||
}
|
||||
return $this->errorcode_map[$nativecode];
|
||||
} else {
|
||||
return DB_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ tableInfo()
|
||||
|
||||
/**
|
||||
* Returns information about a table or a result set
|
||||
*
|
||||
* NOTE: only supports 'table' and 'flags' if <var>$result</var>
|
||||
* is a table name.
|
||||
*
|
||||
* @param object|string $result DB_result object from a query or a
|
||||
* string containing the name of a table.
|
||||
* While this also accepts a query result
|
||||
* resource identifier, this behavior is
|
||||
* deprecated.
|
||||
* @param int $mode a valid tableInfo mode
|
||||
*
|
||||
* @return array an associative array with the information requested.
|
||||
* A DB_Error object on failure.
|
||||
*
|
||||
* @see DB_common::tableInfo()
|
||||
*/
|
||||
function tableInfo($result, $mode = null)
|
||||
{
|
||||
if (is_string($result)) {
|
||||
/*
|
||||
* Probably received a table name.
|
||||
* Create a result resource identifier.
|
||||
*/
|
||||
if (!@mssql_select_db($this->_db, $this->connection)) {
|
||||
return $this->mssqlRaiseError(DB_ERROR_NODBSELECTED);
|
||||
}
|
||||
$id = @mssql_query("SELECT * FROM $result WHERE 1=0",
|
||||
$this->connection);
|
||||
$got_string = true;
|
||||
} elseif (isset($result->result)) {
|
||||
/*
|
||||
* Probably received a result object.
|
||||
* Extract the result resource identifier.
|
||||
*/
|
||||
$id = $result->result;
|
||||
$got_string = false;
|
||||
} else {
|
||||
/*
|
||||
* Probably received a result resource identifier.
|
||||
* Copy it.
|
||||
* Deprecated. Here for compatibility only.
|
||||
*/
|
||||
$id = $result;
|
||||
$got_string = false;
|
||||
}
|
||||
|
||||
if (!is_resource($id)) {
|
||||
return $this->mssqlRaiseError(DB_ERROR_NEED_MORE_DATA);
|
||||
}
|
||||
|
||||
if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE) {
|
||||
$case_func = 'strtolower';
|
||||
} else {
|
||||
$case_func = 'strval';
|
||||
}
|
||||
|
||||
$count = @mssql_num_fields($id);
|
||||
$res = array();
|
||||
|
||||
if ($mode) {
|
||||
$res['num_fields'] = $count;
|
||||
}
|
||||
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
if ($got_string) {
|
||||
$flags = $this->_mssql_field_flags($result,
|
||||
@mssql_field_name($id, $i));
|
||||
if (DB::isError($flags)) {
|
||||
return $flags;
|
||||
}
|
||||
} else {
|
||||
$flags = '';
|
||||
}
|
||||
|
||||
$res[$i] = array(
|
||||
'table' => $got_string ? $case_func($result) : '',
|
||||
'name' => $case_func(@mssql_field_name($id, $i)),
|
||||
'type' => @mssql_field_type($id, $i),
|
||||
'len' => @mssql_field_length($id, $i),
|
||||
'flags' => $flags,
|
||||
);
|
||||
if ($mode & DB_TABLEINFO_ORDER) {
|
||||
$res['order'][$res[$i]['name']] = $i;
|
||||
}
|
||||
if ($mode & DB_TABLEINFO_ORDERTABLE) {
|
||||
$res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i;
|
||||
}
|
||||
}
|
||||
|
||||
// free the result only if we were called on a table
|
||||
if ($got_string) {
|
||||
@mssql_free_result($id);
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ _mssql_field_flags()
|
||||
|
||||
/**
|
||||
* Get a column's flags
|
||||
*
|
||||
* Supports "not_null", "primary_key",
|
||||
* "auto_increment" (mssql identity), "timestamp" (mssql timestamp),
|
||||
* "unique_key" (mssql unique index, unique check or primary_key) and
|
||||
* "multiple_key" (multikey index)
|
||||
*
|
||||
* mssql timestamp is NOT similar to the mysql timestamp so this is maybe
|
||||
* not useful at all - is the behaviour of mysql_field_flags that primary
|
||||
* keys are alway unique? is the interpretation of multiple_key correct?
|
||||
*
|
||||
* @param string $table the table name
|
||||
* @param string $column the field name
|
||||
*
|
||||
* @return string the flags
|
||||
*
|
||||
* @access private
|
||||
* @author Joern Barthel <j_barthel@web.de>
|
||||
*/
|
||||
function _mssql_field_flags($table, $column)
|
||||
{
|
||||
static $tableName = null;
|
||||
static $flags = array();
|
||||
|
||||
if ($table != $tableName) {
|
||||
|
||||
$flags = array();
|
||||
$tableName = $table;
|
||||
|
||||
// get unique and primary keys
|
||||
$res = $this->getAll("EXEC SP_HELPINDEX $table", DB_FETCHMODE_ASSOC);
|
||||
if (DB::isError($res)) {
|
||||
return $res;
|
||||
}
|
||||
|
||||
foreach ($res as $val) {
|
||||
$keys = explode(', ', $val['index_keys']);
|
||||
|
||||
if (sizeof($keys) > 1) {
|
||||
foreach ($keys as $key) {
|
||||
$this->_add_flag($flags[$key], 'multiple_key');
|
||||
}
|
||||
}
|
||||
|
||||
if (strpos($val['index_description'], 'primary key')) {
|
||||
foreach ($keys as $key) {
|
||||
$this->_add_flag($flags[$key], 'primary_key');
|
||||
}
|
||||
} elseif (strpos($val['index_description'], 'unique')) {
|
||||
foreach ($keys as $key) {
|
||||
$this->_add_flag($flags[$key], 'unique_key');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// get auto_increment, not_null and timestamp
|
||||
$res = $this->getAll("EXEC SP_COLUMNS $table", DB_FETCHMODE_ASSOC);
|
||||
if (DB::isError($res)) {
|
||||
return $res;
|
||||
}
|
||||
|
||||
foreach ($res as $val) {
|
||||
$val = array_change_key_case($val, CASE_LOWER);
|
||||
if ($val['nullable'] == '0') {
|
||||
$this->_add_flag($flags[$val['column_name']], 'not_null');
|
||||
}
|
||||
if (strpos($val['type_name'], 'identity')) {
|
||||
$this->_add_flag($flags[$val['column_name']], 'auto_increment');
|
||||
}
|
||||
if (strpos($val['type_name'], 'timestamp')) {
|
||||
$this->_add_flag($flags[$val['column_name']], 'timestamp');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (array_key_exists($column, $flags)) {
|
||||
return(implode(' ', $flags[$column]));
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ _add_flag()
|
||||
|
||||
/**
|
||||
* Adds a string to the flags array if the flag is not yet in there
|
||||
* - if there is no flag present the array is created
|
||||
*
|
||||
* @param array &$array the reference to the flag-array
|
||||
* @param string $value the flag value
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @access private
|
||||
* @author Joern Barthel <j_barthel@web.de>
|
||||
*/
|
||||
function _add_flag(&$array, $value)
|
||||
{
|
||||
if (!is_array($array)) {
|
||||
$array = array($value);
|
||||
} elseif (!in_array($value, $array)) {
|
||||
array_push($array, $value);
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ getSpecialQuery()
|
||||
|
||||
/**
|
||||
* Obtains the query string needed for listing a given type of objects
|
||||
*
|
||||
* @param string $type the kind of objects you want to retrieve
|
||||
*
|
||||
* @return string the SQL query string or null if the driver doesn't
|
||||
* support the object type requested
|
||||
*
|
||||
* @access protected
|
||||
* @see DB_common::getListOf()
|
||||
*/
|
||||
function getSpecialQuery($type)
|
||||
{
|
||||
switch ($type) {
|
||||
case 'tables':
|
||||
return "SELECT name FROM sysobjects WHERE type = 'U'"
|
||||
. ' ORDER BY name';
|
||||
case 'views':
|
||||
return "SELECT name FROM sysobjects WHERE type = 'V'";
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
}
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* tab-width: 4
|
||||
* c-basic-offset: 4
|
||||
* End:
|
||||
*/
|
||||
|
||||
?>
|
||||
1046
sites/all/modules/civicrm/packages/DB/mysql.php
Normal file
1046
sites/all/modules/civicrm/packages/DB/mysql.php
Normal file
File diff suppressed because it is too large
Load diff
1101
sites/all/modules/civicrm/packages/DB/mysqli.php
Normal file
1101
sites/all/modules/civicrm/packages/DB/mysqli.php
Normal file
File diff suppressed because it is too large
Load diff
883
sites/all/modules/civicrm/packages/DB/odbc.php
Normal file
883
sites/all/modules/civicrm/packages/DB/odbc.php
Normal file
|
|
@ -0,0 +1,883 @@
|
|||
<?php
|
||||
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* The PEAR DB driver for PHP's odbc extension
|
||||
* for interacting with databases via ODBC connections
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.0 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category Database
|
||||
* @package DB
|
||||
* @author Stig Bakken <ssb@php.net>
|
||||
* @author Daniel Convissor <danielc@php.net>
|
||||
* @copyright 1997-2007 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version CVS: $Id: odbc.php,v 1.81 2007/07/06 05:19:21 aharvey Exp $
|
||||
* @link http://pear.php.net/package/DB
|
||||
*/
|
||||
|
||||
/**
|
||||
* Obtain the DB_common class so it can be extended from
|
||||
*/
|
||||
require_once 'DB/common.php';
|
||||
|
||||
/**
|
||||
* The methods PEAR DB uses to interact with PHP's odbc extension
|
||||
* for interacting with databases via ODBC connections
|
||||
*
|
||||
* These methods overload the ones declared in DB_common.
|
||||
*
|
||||
* More info on ODBC errors could be found here:
|
||||
* http://msdn.microsoft.com/library/default.asp?url=/library/en-us/trblsql/tr_err_odbc_5stz.asp
|
||||
*
|
||||
* @category Database
|
||||
* @package DB
|
||||
* @author Stig Bakken <ssb@php.net>
|
||||
* @author Daniel Convissor <danielc@php.net>
|
||||
* @copyright 1997-2007 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version Release: 1.7.13
|
||||
* @link http://pear.php.net/package/DB
|
||||
*/
|
||||
class DB_odbc extends DB_common
|
||||
{
|
||||
// {{{ properties
|
||||
|
||||
/**
|
||||
* The DB driver type (mysql, oci8, odbc, etc.)
|
||||
* @var string
|
||||
*/
|
||||
var $phptype = 'odbc';
|
||||
|
||||
/**
|
||||
* The database syntax variant to be used (db2, access, etc.), if any
|
||||
* @var string
|
||||
*/
|
||||
var $dbsyntax = 'sql92';
|
||||
|
||||
/**
|
||||
* The capabilities of this DB implementation
|
||||
*
|
||||
* The 'new_link' element contains the PHP version that first provided
|
||||
* new_link support for this DBMS. Contains false if it's unsupported.
|
||||
*
|
||||
* Meaning of the 'limit' element:
|
||||
* + 'emulate' = emulate with fetch row by number
|
||||
* + 'alter' = alter the query
|
||||
* + false = skip rows
|
||||
*
|
||||
* NOTE: The feature set of the following drivers are different than
|
||||
* the default:
|
||||
* + solid: 'transactions' = true
|
||||
* + navision: 'limit' = false
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $features = array(
|
||||
'limit' => 'emulate',
|
||||
'new_link' => false,
|
||||
'numrows' => true,
|
||||
'pconnect' => true,
|
||||
'prepare' => false,
|
||||
'ssl' => false,
|
||||
'transactions' => false,
|
||||
);
|
||||
|
||||
/**
|
||||
* A mapping of native error codes to DB error codes
|
||||
* @var array
|
||||
*/
|
||||
var $errorcode_map = array(
|
||||
'01004' => DB_ERROR_TRUNCATED,
|
||||
'07001' => DB_ERROR_MISMATCH,
|
||||
'21S01' => DB_ERROR_VALUE_COUNT_ON_ROW,
|
||||
'21S02' => DB_ERROR_MISMATCH,
|
||||
'22001' => DB_ERROR_INVALID,
|
||||
'22003' => DB_ERROR_INVALID_NUMBER,
|
||||
'22005' => DB_ERROR_INVALID_NUMBER,
|
||||
'22008' => DB_ERROR_INVALID_DATE,
|
||||
'22012' => DB_ERROR_DIVZERO,
|
||||
'23000' => DB_ERROR_CONSTRAINT,
|
||||
'23502' => DB_ERROR_CONSTRAINT_NOT_NULL,
|
||||
'23503' => DB_ERROR_CONSTRAINT,
|
||||
'23504' => DB_ERROR_CONSTRAINT,
|
||||
'23505' => DB_ERROR_CONSTRAINT,
|
||||
'24000' => DB_ERROR_INVALID,
|
||||
'34000' => DB_ERROR_INVALID,
|
||||
'37000' => DB_ERROR_SYNTAX,
|
||||
'42000' => DB_ERROR_SYNTAX,
|
||||
'42601' => DB_ERROR_SYNTAX,
|
||||
'IM001' => DB_ERROR_UNSUPPORTED,
|
||||
'S0000' => DB_ERROR_NOSUCHTABLE,
|
||||
'S0001' => DB_ERROR_ALREADY_EXISTS,
|
||||
'S0002' => DB_ERROR_NOSUCHTABLE,
|
||||
'S0011' => DB_ERROR_ALREADY_EXISTS,
|
||||
'S0012' => DB_ERROR_NOT_FOUND,
|
||||
'S0021' => DB_ERROR_ALREADY_EXISTS,
|
||||
'S0022' => DB_ERROR_NOSUCHFIELD,
|
||||
'S1009' => DB_ERROR_INVALID,
|
||||
'S1090' => DB_ERROR_INVALID,
|
||||
'S1C00' => DB_ERROR_NOT_CAPABLE,
|
||||
);
|
||||
|
||||
/**
|
||||
* The raw database connection created by PHP
|
||||
* @var resource
|
||||
*/
|
||||
var $connection;
|
||||
|
||||
/**
|
||||
* The DSN information for connecting to a database
|
||||
* @var array
|
||||
*/
|
||||
var $dsn = array();
|
||||
|
||||
|
||||
/**
|
||||
* The number of rows affected by a data manipulation query
|
||||
* @var integer
|
||||
* @access private
|
||||
*/
|
||||
var $affected = 0;
|
||||
|
||||
|
||||
// }}}
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* This constructor calls <kbd>$this->DB_common()</kbd>
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ connect()
|
||||
|
||||
/**
|
||||
* Connect to the database server, log in and open the database
|
||||
*
|
||||
* Don't call this method directly. Use DB::connect() instead.
|
||||
*
|
||||
* PEAR DB's odbc driver supports the following extra DSN options:
|
||||
* + cursor The type of cursor to be used for this connection.
|
||||
*
|
||||
* @param array $dsn the data source name
|
||||
* @param bool $persistent should the connection be persistent?
|
||||
*
|
||||
* @return int DB_OK on success. A DB_Error object on failure.
|
||||
*/
|
||||
function connect($dsn, $persistent = false)
|
||||
{
|
||||
if (!PEAR::loadExtension('odbc')) {
|
||||
return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND);
|
||||
}
|
||||
|
||||
$this->dsn = $dsn;
|
||||
if ($dsn['dbsyntax']) {
|
||||
$this->dbsyntax = $dsn['dbsyntax'];
|
||||
}
|
||||
switch ($this->dbsyntax) {
|
||||
case 'access':
|
||||
case 'db2':
|
||||
case 'solid':
|
||||
$this->features['transactions'] = true;
|
||||
break;
|
||||
case 'navision':
|
||||
$this->features['limit'] = false;
|
||||
}
|
||||
|
||||
/*
|
||||
* This is hear for backwards compatibility. Should have been using
|
||||
* 'database' all along, but prior to 1.6.0RC3 'hostspec' was used.
|
||||
*/
|
||||
if ($dsn['database']) {
|
||||
$odbcdsn = $dsn['database'];
|
||||
} elseif ($dsn['hostspec']) {
|
||||
$odbcdsn = $dsn['hostspec'];
|
||||
} else {
|
||||
$odbcdsn = 'localhost';
|
||||
}
|
||||
|
||||
$connect_function = $persistent ? 'odbc_pconnect' : 'odbc_connect';
|
||||
|
||||
if (empty($dsn['cursor'])) {
|
||||
$this->connection = @$connect_function($odbcdsn, $dsn['username'],
|
||||
$dsn['password']);
|
||||
} else {
|
||||
$this->connection = @$connect_function($odbcdsn, $dsn['username'],
|
||||
$dsn['password'],
|
||||
$dsn['cursor']);
|
||||
}
|
||||
|
||||
if (!is_resource($this->connection)) {
|
||||
return $this->raiseError(DB_ERROR_CONNECT_FAILED,
|
||||
null, null, null,
|
||||
$this->errorNative());
|
||||
}
|
||||
return DB_OK;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ disconnect()
|
||||
|
||||
/**
|
||||
* Disconnects from the database server
|
||||
*
|
||||
* @return bool TRUE on success, FALSE on failure
|
||||
*/
|
||||
function disconnect()
|
||||
{
|
||||
$err = @odbc_close($this->connection);
|
||||
$this->connection = null;
|
||||
return $err;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ simpleQuery()
|
||||
|
||||
/**
|
||||
* Sends a query to the database server
|
||||
*
|
||||
* @param string the SQL query string
|
||||
*
|
||||
* @return mixed + a PHP result resrouce for successful SELECT queries
|
||||
* + the DB_OK constant for other successful queries
|
||||
* + a DB_Error object on failure
|
||||
*/
|
||||
function simpleQuery($query)
|
||||
{
|
||||
$this->last_query = $query;
|
||||
$query = $this->modifyQuery($query);
|
||||
$result = @odbc_exec($this->connection, $query);
|
||||
if (!$result) {
|
||||
return $this->odbcRaiseError(); // XXX ERRORMSG
|
||||
}
|
||||
// Determine which queries that should return data, and which
|
||||
// should return an error code only.
|
||||
if ($this->_checkManip($query)) {
|
||||
$this->affected = $result; // For affectedRows()
|
||||
return DB_OK;
|
||||
}
|
||||
$this->affected = 0;
|
||||
return $result;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ nextResult()
|
||||
|
||||
/**
|
||||
* Move the internal odbc result pointer to the next available result
|
||||
*
|
||||
* @param a valid fbsql result resource
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @return true if a result is available otherwise return false
|
||||
*/
|
||||
function nextResult($result)
|
||||
{
|
||||
return @odbc_next_result($result);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ fetchInto()
|
||||
|
||||
/**
|
||||
* Places a row from the result set into the given array
|
||||
*
|
||||
* Formating of the array and the data therein are configurable.
|
||||
* See DB_result::fetchInto() for more information.
|
||||
*
|
||||
* This method is not meant to be called directly. Use
|
||||
* DB_result::fetchInto() instead. It can't be declared "protected"
|
||||
* because DB_result is a separate object.
|
||||
*
|
||||
* @param resource $result the query result resource
|
||||
* @param array $arr the referenced array to put the data in
|
||||
* @param int $fetchmode how the resulting array should be indexed
|
||||
* @param int $rownum the row number to fetch (0 = first row)
|
||||
*
|
||||
* @return mixed DB_OK on success, NULL when the end of a result set is
|
||||
* reached or on failure
|
||||
*
|
||||
* @see DB_result::fetchInto()
|
||||
*/
|
||||
function fetchInto($result, &$arr, $fetchmode, $rownum = null)
|
||||
{
|
||||
$arr = array();
|
||||
if ($rownum !== null) {
|
||||
$rownum++; // ODBC first row is 1
|
||||
if (version_compare(phpversion(), '4.2.0', 'ge')) {
|
||||
$cols = @odbc_fetch_into($result, $arr, $rownum);
|
||||
} else {
|
||||
$cols = @odbc_fetch_into($result, $rownum, $arr);
|
||||
}
|
||||
} else {
|
||||
$cols = @odbc_fetch_into($result, $arr);
|
||||
}
|
||||
if (!$cols) {
|
||||
return null;
|
||||
}
|
||||
if ($fetchmode !== DB_FETCHMODE_ORDERED) {
|
||||
for ($i = 0; $i < count($arr); $i++) {
|
||||
$colName = @odbc_field_name($result, $i+1);
|
||||
$a[$colName] = $arr[$i];
|
||||
}
|
||||
if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE) {
|
||||
$a = array_change_key_case($a, CASE_LOWER);
|
||||
}
|
||||
$arr = $a;
|
||||
}
|
||||
if ($this->options['portability'] & DB_PORTABILITY_RTRIM) {
|
||||
$this->_rtrimArrayValues($arr);
|
||||
}
|
||||
if ($this->options['portability'] & DB_PORTABILITY_NULL_TO_EMPTY) {
|
||||
$this->_convertNullArrayValuesToEmpty($arr);
|
||||
}
|
||||
return DB_OK;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ freeResult()
|
||||
|
||||
/**
|
||||
* Deletes the result set and frees the memory occupied by the result set
|
||||
*
|
||||
* This method is not meant to be called directly. Use
|
||||
* DB_result::free() instead. It can't be declared "protected"
|
||||
* because DB_result is a separate object.
|
||||
*
|
||||
* @param resource $result PHP's query result resource
|
||||
*
|
||||
* @return bool TRUE on success, FALSE if $result is invalid
|
||||
*
|
||||
* @see DB_result::free()
|
||||
*/
|
||||
function freeResult($result)
|
||||
{
|
||||
return is_resource($result) ? odbc_free_result($result) : false;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ numCols()
|
||||
|
||||
/**
|
||||
* Gets the number of columns in a result set
|
||||
*
|
||||
* This method is not meant to be called directly. Use
|
||||
* DB_result::numCols() instead. It can't be declared "protected"
|
||||
* because DB_result is a separate object.
|
||||
*
|
||||
* @param resource $result PHP's query result resource
|
||||
*
|
||||
* @return int the number of columns. A DB_Error object on failure.
|
||||
*
|
||||
* @see DB_result::numCols()
|
||||
*/
|
||||
function numCols($result)
|
||||
{
|
||||
$cols = @odbc_num_fields($result);
|
||||
if (!$cols) {
|
||||
return $this->odbcRaiseError();
|
||||
}
|
||||
return $cols;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ affectedRows()
|
||||
|
||||
/**
|
||||
* Determines the number of rows affected by a data maniuplation query
|
||||
*
|
||||
* 0 is returned for queries that don't manipulate data.
|
||||
*
|
||||
* @return int the number of rows. A DB_Error object on failure.
|
||||
*/
|
||||
function affectedRows()
|
||||
{
|
||||
if (empty($this->affected)) { // In case of SELECT stms
|
||||
return 0;
|
||||
}
|
||||
$nrows = @odbc_num_rows($this->affected);
|
||||
if ($nrows == -1) {
|
||||
return $this->odbcRaiseError();
|
||||
}
|
||||
return $nrows;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ numRows()
|
||||
|
||||
/**
|
||||
* Gets the number of rows in a result set
|
||||
*
|
||||
* Not all ODBC drivers support this functionality. If they don't
|
||||
* a DB_Error object for DB_ERROR_UNSUPPORTED is returned.
|
||||
*
|
||||
* This method is not meant to be called directly. Use
|
||||
* DB_result::numRows() instead. It can't be declared "protected"
|
||||
* because DB_result is a separate object.
|
||||
*
|
||||
* @param resource $result PHP's query result resource
|
||||
*
|
||||
* @return int the number of rows. A DB_Error object on failure.
|
||||
*
|
||||
* @see DB_result::numRows()
|
||||
*/
|
||||
function numRows($result)
|
||||
{
|
||||
$nrows = @odbc_num_rows($result);
|
||||
if ($nrows == -1) {
|
||||
return $this->odbcRaiseError(DB_ERROR_UNSUPPORTED);
|
||||
}
|
||||
if ($nrows === false) {
|
||||
return $this->odbcRaiseError();
|
||||
}
|
||||
return $nrows;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ quoteIdentifier()
|
||||
|
||||
/**
|
||||
* Quotes a string so it can be safely used as a table or column name
|
||||
*
|
||||
* Use 'mssql' as the dbsyntax in the DB DSN only if you've unchecked
|
||||
* "Use ANSI quoted identifiers" when setting up the ODBC data source.
|
||||
*
|
||||
* @param string $str identifier name to be quoted
|
||||
*
|
||||
* @return string quoted identifier string
|
||||
*
|
||||
* @see DB_common::quoteIdentifier()
|
||||
* @since Method available since Release 1.6.0
|
||||
*/
|
||||
function quoteIdentifier($str)
|
||||
{
|
||||
switch ($this->dsn['dbsyntax']) {
|
||||
case 'access':
|
||||
return '[' . $str . ']';
|
||||
case 'mssql':
|
||||
case 'sybase':
|
||||
return '[' . str_replace(']', ']]', $str) . ']';
|
||||
case 'mysql':
|
||||
case 'mysqli':
|
||||
return '`' . $str . '`';
|
||||
default:
|
||||
return '"' . str_replace('"', '""', $str) . '"';
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ quote()
|
||||
|
||||
/**
|
||||
* @deprecated Deprecated in release 1.6.0
|
||||
* @internal
|
||||
*/
|
||||
function quote($str)
|
||||
{
|
||||
return $this->quoteSmart($str);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ nextId()
|
||||
|
||||
/**
|
||||
* Returns the next free id in a sequence
|
||||
*
|
||||
* @param string $seq_name name of the sequence
|
||||
* @param boolean $ondemand when true, the seqence is automatically
|
||||
* created if it does not exist
|
||||
*
|
||||
* @return int the next id number in the sequence.
|
||||
* A DB_Error object on failure.
|
||||
*
|
||||
* @see DB_common::nextID(), DB_common::getSequenceName(),
|
||||
* DB_odbc::createSequence(), DB_odbc::dropSequence()
|
||||
*/
|
||||
function nextId($seq_name, $ondemand = true)
|
||||
{
|
||||
$seqname = $this->getSequenceName($seq_name);
|
||||
$repeat = 0;
|
||||
do {
|
||||
$this->pushErrorHandling(PEAR_ERROR_RETURN);
|
||||
$result = $this->query("update ${seqname} set id = id + 1");
|
||||
$this->popErrorHandling();
|
||||
if ($ondemand && DB::isError($result) &&
|
||||
$result->getCode() == DB_ERROR_NOSUCHTABLE) {
|
||||
$repeat = 1;
|
||||
$this->pushErrorHandling(PEAR_ERROR_RETURN);
|
||||
$result = $this->createSequence($seq_name);
|
||||
$this->popErrorHandling();
|
||||
if (DB::isError($result)) {
|
||||
return $this->raiseError($result);
|
||||
}
|
||||
$result = $this->query("insert into ${seqname} (id) values(0)");
|
||||
} else {
|
||||
$repeat = 0;
|
||||
}
|
||||
} while ($repeat);
|
||||
|
||||
if (DB::isError($result)) {
|
||||
return $this->raiseError($result);
|
||||
}
|
||||
|
||||
$result = $this->query("select id from ${seqname}");
|
||||
if (DB::isError($result)) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
$row = $result->fetchRow(DB_FETCHMODE_ORDERED);
|
||||
if (DB::isError($row || !$row)) {
|
||||
return $row;
|
||||
}
|
||||
|
||||
return $row[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new sequence
|
||||
*
|
||||
* @param string $seq_name name of the new sequence
|
||||
*
|
||||
* @return int DB_OK on success. A DB_Error object on failure.
|
||||
*
|
||||
* @see DB_common::createSequence(), DB_common::getSequenceName(),
|
||||
* DB_odbc::nextID(), DB_odbc::dropSequence()
|
||||
*/
|
||||
function createSequence($seq_name)
|
||||
{
|
||||
return $this->query('CREATE TABLE '
|
||||
. $this->getSequenceName($seq_name)
|
||||
. ' (id integer NOT NULL,'
|
||||
. ' PRIMARY KEY(id))');
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ dropSequence()
|
||||
|
||||
/**
|
||||
* Deletes a sequence
|
||||
*
|
||||
* @param string $seq_name name of the sequence to be deleted
|
||||
*
|
||||
* @return int DB_OK on success. A DB_Error object on failure.
|
||||
*
|
||||
* @see DB_common::dropSequence(), DB_common::getSequenceName(),
|
||||
* DB_odbc::nextID(), DB_odbc::createSequence()
|
||||
*/
|
||||
function dropSequence($seq_name)
|
||||
{
|
||||
return $this->query('DROP TABLE ' . $this->getSequenceName($seq_name));
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ autoCommit()
|
||||
|
||||
/**
|
||||
* Enables or disables automatic commits
|
||||
*
|
||||
* @param bool $onoff true turns it on, false turns it off
|
||||
*
|
||||
* @return int DB_OK on success. A DB_Error object if the driver
|
||||
* doesn't support auto-committing transactions.
|
||||
*/
|
||||
function autoCommit($onoff = false)
|
||||
{
|
||||
if (!@odbc_autocommit($this->connection, $onoff)) {
|
||||
return $this->odbcRaiseError();
|
||||
}
|
||||
return DB_OK;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ commit()
|
||||
|
||||
/**
|
||||
* Commits the current transaction
|
||||
*
|
||||
* @return int DB_OK on success. A DB_Error object on failure.
|
||||
*/
|
||||
function commit()
|
||||
{
|
||||
if (!@odbc_commit($this->connection)) {
|
||||
return $this->odbcRaiseError();
|
||||
}
|
||||
return DB_OK;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ rollback()
|
||||
|
||||
/**
|
||||
* Reverts the current transaction
|
||||
*
|
||||
* @return int DB_OK on success. A DB_Error object on failure.
|
||||
*/
|
||||
function rollback()
|
||||
{
|
||||
if (!@odbc_rollback($this->connection)) {
|
||||
return $this->odbcRaiseError();
|
||||
}
|
||||
return DB_OK;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ odbcRaiseError()
|
||||
|
||||
/**
|
||||
* Produces a DB_Error object regarding the current problem
|
||||
*
|
||||
* @param int $errno if the error is being manually raised pass a
|
||||
* DB_ERROR* constant here. If this isn't passed
|
||||
* the error information gathered from the DBMS.
|
||||
*
|
||||
* @return object the DB_Error object
|
||||
*
|
||||
* @see DB_common::raiseError(),
|
||||
* DB_odbc::errorNative(), DB_common::errorCode()
|
||||
*/
|
||||
function odbcRaiseError($errno = null)
|
||||
{
|
||||
if ($errno === null) {
|
||||
switch ($this->dbsyntax) {
|
||||
case 'access':
|
||||
if ($this->options['portability'] & DB_PORTABILITY_ERRORS) {
|
||||
$this->errorcode_map['07001'] = DB_ERROR_NOSUCHFIELD;
|
||||
} else {
|
||||
// Doing this in case mode changes during runtime.
|
||||
$this->errorcode_map['07001'] = DB_ERROR_MISMATCH;
|
||||
}
|
||||
|
||||
$native_code = odbc_error($this->connection);
|
||||
|
||||
// S1000 is for "General Error." Let's be more specific.
|
||||
if ($native_code == 'S1000') {
|
||||
$errormsg = odbc_errormsg($this->connection);
|
||||
static $error_regexps;
|
||||
if (!isset($error_regexps)) {
|
||||
$error_regexps = array(
|
||||
'/includes related records.$/i' => DB_ERROR_CONSTRAINT,
|
||||
'/cannot contain a Null value/i' => DB_ERROR_CONSTRAINT_NOT_NULL,
|
||||
);
|
||||
}
|
||||
foreach ($error_regexps as $regexp => $code) {
|
||||
if (preg_match($regexp, $errormsg)) {
|
||||
return $this->raiseError($code,
|
||||
null, null, null,
|
||||
$native_code . ' ' . $errormsg);
|
||||
}
|
||||
}
|
||||
$errno = DB_ERROR;
|
||||
} else {
|
||||
$errno = $this->errorCode($native_code);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$errno = $this->errorCode(odbc_error($this->connection));
|
||||
}
|
||||
}
|
||||
return $this->raiseError($errno, null, null, null,
|
||||
$this->errorNative());
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ errorNative()
|
||||
|
||||
/**
|
||||
* Gets the DBMS' native error code and message produced by the last query
|
||||
*
|
||||
* @return string the DBMS' error code and message
|
||||
*/
|
||||
function errorNative()
|
||||
{
|
||||
if (!is_resource($this->connection)) {
|
||||
return @odbc_error() . ' ' . @odbc_errormsg();
|
||||
}
|
||||
return @odbc_error($this->connection) . ' ' . @odbc_errormsg($this->connection);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ tableInfo()
|
||||
|
||||
/**
|
||||
* Returns information about a table or a result set
|
||||
*
|
||||
* @param object|string $result DB_result object from a query or a
|
||||
* string containing the name of a table.
|
||||
* While this also accepts a query result
|
||||
* resource identifier, this behavior is
|
||||
* deprecated.
|
||||
* @param int $mode a valid tableInfo mode
|
||||
*
|
||||
* @return array an associative array with the information requested.
|
||||
* A DB_Error object on failure.
|
||||
*
|
||||
* @see DB_common::tableInfo()
|
||||
* @since Method available since Release 1.7.0
|
||||
*/
|
||||
function tableInfo($result, $mode = null)
|
||||
{
|
||||
if (is_string($result)) {
|
||||
/*
|
||||
* Probably received a table name.
|
||||
* Create a result resource identifier.
|
||||
*/
|
||||
$id = @odbc_exec($this->connection, "SELECT * FROM $result");
|
||||
if (!$id) {
|
||||
return $this->odbcRaiseError();
|
||||
}
|
||||
$got_string = true;
|
||||
} elseif (isset($result->result)) {
|
||||
/*
|
||||
* Probably received a result object.
|
||||
* Extract the result resource identifier.
|
||||
*/
|
||||
$id = $result->result;
|
||||
$got_string = false;
|
||||
} else {
|
||||
/*
|
||||
* Probably received a result resource identifier.
|
||||
* Copy it.
|
||||
* Deprecated. Here for compatibility only.
|
||||
*/
|
||||
$id = $result;
|
||||
$got_string = false;
|
||||
}
|
||||
|
||||
if (!is_resource($id)) {
|
||||
return $this->odbcRaiseError(DB_ERROR_NEED_MORE_DATA);
|
||||
}
|
||||
|
||||
if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE) {
|
||||
$case_func = 'strtolower';
|
||||
} else {
|
||||
$case_func = 'strval';
|
||||
}
|
||||
|
||||
$count = @odbc_num_fields($id);
|
||||
$res = array();
|
||||
|
||||
if ($mode) {
|
||||
$res['num_fields'] = $count;
|
||||
}
|
||||
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
$col = $i + 1;
|
||||
$res[$i] = array(
|
||||
'table' => $got_string ? $case_func($result) : '',
|
||||
'name' => $case_func(@odbc_field_name($id, $col)),
|
||||
'type' => @odbc_field_type($id, $col),
|
||||
'len' => @odbc_field_len($id, $col),
|
||||
'flags' => '',
|
||||
);
|
||||
if ($mode & DB_TABLEINFO_ORDER) {
|
||||
$res['order'][$res[$i]['name']] = $i;
|
||||
}
|
||||
if ($mode & DB_TABLEINFO_ORDERTABLE) {
|
||||
$res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i;
|
||||
}
|
||||
}
|
||||
|
||||
// free the result only if we were called on a table
|
||||
if ($got_string) {
|
||||
@odbc_free_result($id);
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ getSpecialQuery()
|
||||
|
||||
/**
|
||||
* Obtains the query string needed for listing a given type of objects
|
||||
*
|
||||
* Thanks to symbol1@gmail.com and Philippe.Jausions@11abacus.com.
|
||||
*
|
||||
* @param string $type the kind of objects you want to retrieve
|
||||
*
|
||||
* @return string the list of objects requested
|
||||
*
|
||||
* @access protected
|
||||
* @see DB_common::getListOf()
|
||||
* @since Method available since Release 1.7.0
|
||||
*/
|
||||
function getSpecialQuery($type)
|
||||
{
|
||||
switch ($type) {
|
||||
case 'databases':
|
||||
if (!function_exists('odbc_data_source')) {
|
||||
return null;
|
||||
}
|
||||
$res = @odbc_data_source($this->connection, SQL_FETCH_FIRST);
|
||||
if (is_array($res)) {
|
||||
$out = array($res['server']);
|
||||
while($res = @odbc_data_source($this->connection,
|
||||
SQL_FETCH_NEXT))
|
||||
{
|
||||
$out[] = $res['server'];
|
||||
}
|
||||
return $out;
|
||||
} else {
|
||||
return $this->odbcRaiseError();
|
||||
}
|
||||
break;
|
||||
case 'tables':
|
||||
case 'schema.tables':
|
||||
$keep = 'TABLE';
|
||||
break;
|
||||
case 'views':
|
||||
$keep = 'VIEW';
|
||||
break;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
* Removing non-conforming items in the while loop rather than
|
||||
* in the odbc_tables() call because some backends choke on this:
|
||||
* odbc_tables($this->connection, '', '', '', 'TABLE')
|
||||
*/
|
||||
$res = @odbc_tables($this->connection);
|
||||
if (!$res) {
|
||||
return $this->odbcRaiseError();
|
||||
}
|
||||
$out = array();
|
||||
while ($row = odbc_fetch_array($res)) {
|
||||
if ($row['TABLE_TYPE'] != $keep) {
|
||||
continue;
|
||||
}
|
||||
if ($type == 'schema.tables') {
|
||||
$out[] = $row['TABLE_SCHEM'] . '.' . $row['TABLE_NAME'];
|
||||
} else {
|
||||
$out[] = $row['TABLE_NAME'];
|
||||
}
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
// }}}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* tab-width: 4
|
||||
* c-basic-offset: 4
|
||||
* End:
|
||||
*/
|
||||
|
||||
?>
|
||||
1116
sites/all/modules/civicrm/packages/DB/pgsql.php
Normal file
1116
sites/all/modules/civicrm/packages/DB/pgsql.php
Normal file
File diff suppressed because it is too large
Load diff
15
sites/all/modules/civicrm/packages/DB/scripts/DB_DataObject_createTables.bat
Executable file
15
sites/all/modules/civicrm/packages/DB/scripts/DB_DataObject_createTables.bat
Executable file
|
|
@ -0,0 +1,15 @@
|
|||
@ECHO OFF
|
||||
REM $Id: DB_DataObject_createTables.bat,v 1.1 2003/09/08 20:43:31 arnaud Exp $
|
||||
REM BATCH FILE TO EXECUTE PEAR::DB_DATAOBJECT createTables.php script
|
||||
|
||||
IF '%1' == '' (
|
||||
ECHO **************************************************
|
||||
ECHO * Please pass the name of the ini file
|
||||
ECHO * to process at the only parameter
|
||||
ECHO *
|
||||
ECHO * e.g.: DB_DataObject_createTables my_ini_file.ini
|
||||
ECHO **************************************************
|
||||
GOTO :EOF
|
||||
)
|
||||
|
||||
%PHP_PEAR_PHP_BIN% %PHP_PEAR_INSTALL_DIR%\DB\DataObject\createTables.php %1
|
||||
506
sites/all/modules/civicrm/packages/DB/storage.php
Normal file
506
sites/all/modules/civicrm/packages/DB/storage.php
Normal file
|
|
@ -0,0 +1,506 @@
|
|||
<?php
|
||||
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Provides an object interface to a table row
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.0 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category Database
|
||||
* @package DB
|
||||
* @author Stig Bakken <stig@php.net>
|
||||
* @copyright 1997-2007 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version CVS: $Id: storage.php,v 1.24 2007/08/12 05:27:25 aharvey Exp $
|
||||
* @link http://pear.php.net/package/DB
|
||||
*/
|
||||
|
||||
/**
|
||||
* Obtain the DB class so it can be extended from
|
||||
*/
|
||||
require_once 'DB.php';
|
||||
|
||||
/**
|
||||
* Provides an object interface to a table row
|
||||
*
|
||||
* It lets you add, delete and change rows using objects rather than SQL
|
||||
* statements.
|
||||
*
|
||||
* @category Database
|
||||
* @package DB
|
||||
* @author Stig Bakken <stig@php.net>
|
||||
* @copyright 1997-2007 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version Release: 1.7.13
|
||||
* @link http://pear.php.net/package/DB
|
||||
*/
|
||||
class DB_storage extends PEAR
|
||||
{
|
||||
// {{{ properties
|
||||
|
||||
/** the name of the table (or view, if the backend database supports
|
||||
updates in views) we hold data from */
|
||||
var $_table = null;
|
||||
|
||||
/** which column(s) in the table contains primary keys, can be a
|
||||
string for single-column primary keys, or an array of strings
|
||||
for multiple-column primary keys */
|
||||
var $_keycolumn = null;
|
||||
|
||||
/** DB connection handle used for all transactions */
|
||||
var $_dbh = null;
|
||||
|
||||
/** an assoc with the names of database fields stored as properties
|
||||
in this object */
|
||||
var $_properties = array();
|
||||
|
||||
/** an assoc with the names of the properties in this object that
|
||||
have been changed since they were fetched from the database */
|
||||
var $_changes = array();
|
||||
|
||||
/** flag that decides if data in this object can be changed.
|
||||
objects that don't have their table's key column in their
|
||||
property lists will be flagged as read-only. */
|
||||
var $_readonly = false;
|
||||
|
||||
/** function or method that implements a validator for fields that
|
||||
are set, this validator function returns true if the field is
|
||||
valid, false if not */
|
||||
var $_validator = null;
|
||||
|
||||
// }}}
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param $table string the name of the database table
|
||||
*
|
||||
* @param $keycolumn mixed string with name of key column, or array of
|
||||
* strings if the table has a primary key of more than one column
|
||||
*
|
||||
* @param $dbh object database connection object
|
||||
*
|
||||
* @param $validator mixed function or method used to validate
|
||||
* each new value, called with three parameters: the name of the
|
||||
* field/column that is changing, a reference to the new value and
|
||||
* a reference to this object
|
||||
*
|
||||
*/
|
||||
function __construct($table, $keycolumn, &$dbh, $validator = null)
|
||||
{
|
||||
parent::__construct('DB_Error');
|
||||
$this->_table = $table;
|
||||
$this->_keycolumn = $keycolumn;
|
||||
$this->_dbh = $dbh;
|
||||
$this->_readonly = false;
|
||||
$this->_validator = $validator;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ _makeWhere()
|
||||
|
||||
/**
|
||||
* Utility method to build a "WHERE" clause to locate ourselves in
|
||||
* the table.
|
||||
*
|
||||
* XXX future improvement: use rowids?
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
function _makeWhere($keyval = null)
|
||||
{
|
||||
if (is_array($this->_keycolumn)) {
|
||||
if ($keyval === null) {
|
||||
for ($i = 0; $i < sizeof($this->_keycolumn); $i++) {
|
||||
$keyval[] = $this->{$this->_keycolumn[$i]};
|
||||
}
|
||||
}
|
||||
$whereclause = '';
|
||||
for ($i = 0; $i < sizeof($this->_keycolumn); $i++) {
|
||||
if ($i > 0) {
|
||||
$whereclause .= ' AND ';
|
||||
}
|
||||
$whereclause .= $this->_keycolumn[$i];
|
||||
if (is_null($keyval[$i])) {
|
||||
// there's not much point in having a NULL key,
|
||||
// but we support it anyway
|
||||
$whereclause .= ' IS NULL';
|
||||
} else {
|
||||
$whereclause .= ' = ' . $this->_dbh->quote($keyval[$i]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ($keyval === null) {
|
||||
$keyval = @$this->{$this->_keycolumn};
|
||||
}
|
||||
$whereclause = $this->_keycolumn;
|
||||
if (is_null($keyval)) {
|
||||
// there's not much point in having a NULL key,
|
||||
// but we support it anyway
|
||||
$whereclause .= ' IS NULL';
|
||||
} else {
|
||||
$whereclause .= ' = ' . $this->_dbh->quote($keyval);
|
||||
}
|
||||
}
|
||||
return $whereclause;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ setup()
|
||||
|
||||
/**
|
||||
* Method used to initialize a DB_storage object from the
|
||||
* configured table.
|
||||
*
|
||||
* @param $keyval mixed the key[s] of the row to fetch (string or array)
|
||||
*
|
||||
* @return int DB_OK on success, a DB error if not
|
||||
*/
|
||||
function setup($keyval)
|
||||
{
|
||||
$whereclause = $this->_makeWhere($keyval);
|
||||
$query = 'SELECT * FROM ' . $this->_table . ' WHERE ' . $whereclause;
|
||||
$sth = $this->_dbh->query($query);
|
||||
if (DB::isError($sth)) {
|
||||
return $sth;
|
||||
}
|
||||
$row = $sth->fetchRow(DB_FETCHMODE_ASSOC);
|
||||
if (DB::isError($row)) {
|
||||
return $row;
|
||||
}
|
||||
if (!$row) {
|
||||
return $this->raiseError(null, DB_ERROR_NOT_FOUND, null, null,
|
||||
$query, null, true);
|
||||
}
|
||||
foreach ($row as $key => $value) {
|
||||
$this->_properties[$key] = true;
|
||||
$this->$key = $value;
|
||||
}
|
||||
return DB_OK;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ insert()
|
||||
|
||||
/**
|
||||
* Create a new (empty) row in the configured table for this
|
||||
* object.
|
||||
*/
|
||||
function insert($newpk)
|
||||
{
|
||||
if (is_array($this->_keycolumn)) {
|
||||
$primarykey = $this->_keycolumn;
|
||||
} else {
|
||||
$primarykey = array($this->_keycolumn);
|
||||
}
|
||||
settype($newpk, "array");
|
||||
for ($i = 0; $i < sizeof($primarykey); $i++) {
|
||||
$pkvals[] = $this->_dbh->quote($newpk[$i]);
|
||||
}
|
||||
|
||||
$sth = $this->_dbh->query("INSERT INTO $this->_table (" .
|
||||
implode(",", $primarykey) . ") VALUES(" .
|
||||
implode(",", $pkvals) . ")");
|
||||
if (DB::isError($sth)) {
|
||||
return $sth;
|
||||
}
|
||||
if (sizeof($newpk) == 1) {
|
||||
$newpk = $newpk[0];
|
||||
}
|
||||
$this->setup($newpk);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ toString()
|
||||
|
||||
/**
|
||||
* Output a simple description of this DB_storage object.
|
||||
* @return string object description
|
||||
*/
|
||||
function toString()
|
||||
{
|
||||
$info = strtolower(get_class($this));
|
||||
$info .= " (table=";
|
||||
$info .= $this->_table;
|
||||
$info .= ", keycolumn=";
|
||||
if (is_array($this->_keycolumn)) {
|
||||
$info .= "(" . implode(",", $this->_keycolumn) . ")";
|
||||
} else {
|
||||
$info .= $this->_keycolumn;
|
||||
}
|
||||
$info .= ", dbh=";
|
||||
if (is_object($this->_dbh)) {
|
||||
$info .= $this->_dbh->toString();
|
||||
} else {
|
||||
$info .= "null";
|
||||
}
|
||||
$info .= ")";
|
||||
if (sizeof($this->_properties)) {
|
||||
$info .= " [loaded, key=";
|
||||
$keyname = $this->_keycolumn;
|
||||
if (is_array($keyname)) {
|
||||
$info .= "(";
|
||||
for ($i = 0; $i < sizeof($keyname); $i++) {
|
||||
if ($i > 0) {
|
||||
$info .= ",";
|
||||
}
|
||||
$info .= $this->$keyname[$i];
|
||||
}
|
||||
$info .= ")";
|
||||
} else {
|
||||
$info .= $this->$keyname;
|
||||
}
|
||||
$info .= "]";
|
||||
}
|
||||
if (sizeof($this->_changes)) {
|
||||
$info .= " [modified]";
|
||||
}
|
||||
return $info;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ dump()
|
||||
|
||||
/**
|
||||
* Dump the contents of this object to "standard output".
|
||||
*/
|
||||
function dump()
|
||||
{
|
||||
foreach ($this->_properties as $prop => $foo) {
|
||||
print "$prop = ";
|
||||
print htmlentities($this->$prop);
|
||||
print "<br />\n";
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ &create()
|
||||
|
||||
/**
|
||||
* Static method used to create new DB storage objects.
|
||||
* @param $data assoc. array where the keys are the names
|
||||
* of properties/columns
|
||||
* @return object a new instance of DB_storage or a subclass of it
|
||||
*/
|
||||
function &create($table, &$data)
|
||||
{
|
||||
$classname = strtolower(get_class($this));
|
||||
$obj = new $classname($table);
|
||||
foreach ($data as $name => $value) {
|
||||
$obj->_properties[$name] = true;
|
||||
$obj->$name = &$value;
|
||||
}
|
||||
return $obj;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ loadFromQuery()
|
||||
|
||||
/**
|
||||
* Loads data into this object from the given query. If this
|
||||
* object already contains table data, changes will be saved and
|
||||
* the object re-initialized first.
|
||||
*
|
||||
* @param $query SQL query
|
||||
*
|
||||
* @param $params parameter list in case you want to use
|
||||
* prepare/execute mode
|
||||
*
|
||||
* @return int DB_OK on success, DB_WARNING_READ_ONLY if the
|
||||
* returned object is read-only (because the object's specified
|
||||
* key column was not found among the columns returned by $query),
|
||||
* or another DB error code in case of errors.
|
||||
*/
|
||||
// XXX commented out for now
|
||||
/*
|
||||
function loadFromQuery($query, $params = null)
|
||||
{
|
||||
if (sizeof($this->_properties)) {
|
||||
if (sizeof($this->_changes)) {
|
||||
$this->store();
|
||||
$this->_changes = array();
|
||||
}
|
||||
$this->_properties = array();
|
||||
}
|
||||
$rowdata = $this->_dbh->getRow($query, DB_FETCHMODE_ASSOC, $params);
|
||||
if (DB::isError($rowdata)) {
|
||||
return $rowdata;
|
||||
}
|
||||
reset($rowdata);
|
||||
$found_keycolumn = false;
|
||||
while (list($key, $value) = each($rowdata)) {
|
||||
if ($key == $this->_keycolumn) {
|
||||
$found_keycolumn = true;
|
||||
}
|
||||
$this->_properties[$key] = true;
|
||||
$this->$key = &$value;
|
||||
unset($value); // have to unset, or all properties will
|
||||
// refer to the same value
|
||||
}
|
||||
if (!$found_keycolumn) {
|
||||
$this->_readonly = true;
|
||||
return DB_WARNING_READ_ONLY;
|
||||
}
|
||||
return DB_OK;
|
||||
}
|
||||
*/
|
||||
|
||||
// }}}
|
||||
// {{{ set()
|
||||
|
||||
/**
|
||||
* Modify an attriute value.
|
||||
*/
|
||||
function set($property, $newvalue)
|
||||
{
|
||||
// only change if $property is known and object is not
|
||||
// read-only
|
||||
if ($this->_readonly) {
|
||||
return $this->raiseError(null, DB_WARNING_READ_ONLY, null,
|
||||
null, null, null, true);
|
||||
}
|
||||
if (@isset($this->_properties[$property])) {
|
||||
if (empty($this->_validator)) {
|
||||
$valid = true;
|
||||
} else {
|
||||
$valid = @call_user_func($this->_validator,
|
||||
$this->_table,
|
||||
$property,
|
||||
$newvalue,
|
||||
$this->$property,
|
||||
$this);
|
||||
}
|
||||
if ($valid) {
|
||||
$this->$property = $newvalue;
|
||||
if (empty($this->_changes[$property])) {
|
||||
$this->_changes[$property] = 0;
|
||||
} else {
|
||||
$this->_changes[$property]++;
|
||||
}
|
||||
} else {
|
||||
return $this->raiseError(null, DB_ERROR_INVALID, null,
|
||||
null, "invalid field: $property",
|
||||
null, true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return $this->raiseError(null, DB_ERROR_NOSUCHFIELD, null,
|
||||
null, "unknown field: $property",
|
||||
null, true);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ &get()
|
||||
|
||||
/**
|
||||
* Fetch an attribute value.
|
||||
*
|
||||
* @param string attribute name
|
||||
*
|
||||
* @return attribute contents, or null if the attribute name is
|
||||
* unknown
|
||||
*/
|
||||
function &get($property)
|
||||
{
|
||||
// only return if $property is known
|
||||
if (isset($this->_properties[$property])) {
|
||||
return $this->$property;
|
||||
}
|
||||
$tmp = null;
|
||||
return $tmp;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ _DB_storage()
|
||||
|
||||
/**
|
||||
* Destructor, calls DB_storage::store() if there are changes
|
||||
* that are to be kept.
|
||||
*/
|
||||
function _DB_storage()
|
||||
{
|
||||
if (sizeof($this->_changes)) {
|
||||
$this->store();
|
||||
}
|
||||
$this->_properties = array();
|
||||
$this->_changes = array();
|
||||
$this->_table = null;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ store()
|
||||
|
||||
/**
|
||||
* Stores changes to this object in the database.
|
||||
*
|
||||
* @return DB_OK or a DB error
|
||||
*/
|
||||
function store()
|
||||
{
|
||||
$params = array();
|
||||
$vars = array();
|
||||
foreach ($this->_changes as $name => $foo) {
|
||||
$params[] = &$this->$name;
|
||||
$vars[] = $name . ' = ?';
|
||||
}
|
||||
if ($vars) {
|
||||
$query = 'UPDATE ' . $this->_table . ' SET ' .
|
||||
implode(', ', $vars) . ' WHERE ' .
|
||||
$this->_makeWhere();
|
||||
$stmt = $this->_dbh->prepare($query);
|
||||
$res = $this->_dbh->execute($stmt, $params);
|
||||
if (DB::isError($res)) {
|
||||
return $res;
|
||||
}
|
||||
$this->_changes = array();
|
||||
}
|
||||
return DB_OK;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ remove()
|
||||
|
||||
/**
|
||||
* Remove the row represented by this object from the database.
|
||||
*
|
||||
* @return mixed DB_OK or a DB error
|
||||
*/
|
||||
function remove()
|
||||
{
|
||||
if ($this->_readonly) {
|
||||
return $this->raiseError(null, DB_WARNING_READ_ONLY, null,
|
||||
null, null, null, true);
|
||||
}
|
||||
$query = 'DELETE FROM ' . $this->_table .' WHERE '.
|
||||
$this->_makeWhere();
|
||||
$res = $this->_dbh->query($query);
|
||||
if (DB::isError($res)) {
|
||||
return $res;
|
||||
}
|
||||
foreach ($this->_properties as $prop => $foo) {
|
||||
unset($this->$prop);
|
||||
}
|
||||
$this->_properties = array();
|
||||
$this->_changes = array();
|
||||
return DB_OK;
|
||||
}
|
||||
|
||||
// }}}
|
||||
}
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* tab-width: 4
|
||||
* c-basic-offset: 4
|
||||
* End:
|
||||
*/
|
||||
|
||||
?>
|
||||
1465
sites/all/modules/civicrm/packages/Date.php
Normal file
1465
sites/all/modules/civicrm/packages/Date.php
Normal file
File diff suppressed because it is too large
Load diff
2089
sites/all/modules/civicrm/packages/Date/Calc.php
Normal file
2089
sites/all/modules/civicrm/packages/Date/Calc.php
Normal file
File diff suppressed because it is too large
Load diff
242
sites/all/modules/civicrm/packages/Date/Human.php
Normal file
242
sites/all/modules/civicrm/packages/Date/Human.php
Normal file
|
|
@ -0,0 +1,242 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
|
||||
|
||||
// {{{ Header
|
||||
|
||||
/**
|
||||
* Class to convert date strings between Gregorian and Human calendar formats
|
||||
*
|
||||
* The Human Calendar format has been proposed by Scott Flansburg and can be
|
||||
* explained as follows:
|
||||
* The year is made up of 13 months
|
||||
* Each month has 28 days
|
||||
* Counting of months starts from 0 (zero) so the months will run from 0 to 12
|
||||
* New Years day (00) is a monthless day
|
||||
* Note: Leap Years are not yet accounted for in the Human Calendar system
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE:
|
||||
*
|
||||
* Copyright (c) 1997-2006 Allan Kent
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted under the terms of the BSD License.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @category Date and Time
|
||||
* @package Date
|
||||
* @author Allan Kent <allan@lodestone.co.za>
|
||||
* @copyright 1997-2006 Allan Kent
|
||||
* @license http://www.opensource.org/licenses/bsd-license.php
|
||||
* BSD License
|
||||
* @version CVS: $Id: Human.php,v 1.6 2006/11/21 17:38:15 firman Exp $
|
||||
* @link http://pear.php.net/package/Date
|
||||
* @since File available since Release 1.3
|
||||
*/
|
||||
|
||||
// }}}
|
||||
// {{{ Class: Date_Human
|
||||
|
||||
/**
|
||||
* Class to convert date strings between Gregorian and Human calendar formats
|
||||
*
|
||||
* The Human Calendar format has been proposed by Scott Flansburg and can be
|
||||
* explained as follows:
|
||||
* The year is made up of 13 months
|
||||
* Each month has 28 days
|
||||
* Counting of months starts from 0 (zero) so the months will run from 0 to 12
|
||||
* New Years day (00) is a monthless day
|
||||
* Note: Leap Years are not yet accounted for in the Human Calendar system
|
||||
*
|
||||
* @author Allan Kent <allan@lodestone.co.za>
|
||||
* @copyright 1997-2005 Allan Kent
|
||||
* @license http://www.opensource.org/licenses/bsd-license.php
|
||||
* BSD License
|
||||
* @version Release: 1.4.7
|
||||
* @link http://pear.php.net/package/Date
|
||||
* @since Class available since Release 1.3
|
||||
*/
|
||||
class Date_Human
|
||||
{
|
||||
// {{{ gregorianToHuman()
|
||||
|
||||
/**
|
||||
* Returns an associative array containing the converted date information
|
||||
* in 'Human Calendar' format.
|
||||
*
|
||||
* @param int day in DD format, default current local day
|
||||
* @param int month in MM format, default current local month
|
||||
* @param int year in CCYY format, default to current local year
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @return associative array(
|
||||
* hdom, // Human Day Of Month, starting at 1
|
||||
* hdow, // Human Day Of Week, starting at 1
|
||||
* hwom, // Human Week of Month, starting at 1
|
||||
* hwoy, // Human Week of Year, starting at 1
|
||||
* hmoy, // Human Month of Year, starting at 0
|
||||
* )
|
||||
*
|
||||
* If the day is New Years Day, the function will return
|
||||
* "hdom" => 0
|
||||
* "hdow" => 0
|
||||
* "hwom" => 0
|
||||
* "hwoy" => 0
|
||||
* "hmoy" => -1
|
||||
* Since 0 is a valid month number under the Human Calendar, I have left
|
||||
* the month as -1 for New Years Day.
|
||||
*/
|
||||
function gregorianToHuman($day=0, $month=0, $year=0)
|
||||
{
|
||||
/*
|
||||
* Check to see if any of the arguments are empty
|
||||
* If they are then populate the $dateinfo array
|
||||
* Then check to see which arguments are empty and fill
|
||||
* those with the current date info
|
||||
*/
|
||||
if ((empty($day) || (empty($month)) || empty($year))) {
|
||||
$dateinfo = getdate(time());
|
||||
}
|
||||
if (empty($day)) {
|
||||
$day = $dateinfo["mday"];
|
||||
}
|
||||
if (empty($month)) {
|
||||
$month = $dateinfo["mon"];
|
||||
}
|
||||
if (empty($year)) {
|
||||
$year = $dateinfo["year"];
|
||||
}
|
||||
/*
|
||||
* We need to know how many days into the year we are
|
||||
*/
|
||||
$dateinfo = getdate(mktime(0, 0, 0, $month, $day, $year));
|
||||
$dayofyear = $dateinfo["yday"];
|
||||
/*
|
||||
* Human Calendar starts at 0 for months and the first day of the year
|
||||
* is designated 00, so we need to start our day of the year at 0 for
|
||||
* these calculations.
|
||||
* Also, the day of the month is calculated with a modulus of 28.
|
||||
* Because a day is 28 days, the last day of the month would have a
|
||||
* remainder of 0 and not 28 as it should be. Decrementing $dayofyear
|
||||
* gets around this.
|
||||
*/
|
||||
$dayofyear--;
|
||||
/*
|
||||
* 28 days in a month...
|
||||
*/
|
||||
$humanMonthOfYear = floor($dayofyear / 28);
|
||||
/*
|
||||
* If we are in the first month then the day of the month is $dayofyear
|
||||
* else we need to find the modulus of 28.
|
||||
*/
|
||||
if ($humanMonthOfYear == 0) {
|
||||
$humanDayOfMonth = $dayofyear;
|
||||
} else {
|
||||
$humanDayOfMonth = ($dayofyear) % 28;
|
||||
}
|
||||
/*
|
||||
* Day of the week is modulus 7
|
||||
*/
|
||||
$humanDayOfWeek = $dayofyear % 7;
|
||||
/*
|
||||
* We can now increment $dayofyear back to it's correct value for
|
||||
* the remainder of the calculations
|
||||
*/
|
||||
$dayofyear++;
|
||||
/*
|
||||
* $humanDayOfMonth needs to be incremented now - recall that we fudged
|
||||
* it a bit by decrementing $dayofyear earlier
|
||||
* Same goes for $humanDayOfWeek
|
||||
*/
|
||||
$humanDayOfMonth++;
|
||||
$humanDayOfWeek++;
|
||||
/*
|
||||
* Week of the month is day of the month divided by 7, rounded up
|
||||
* Same for week of the year, but use $dayofyear instead $humanDayOfMonth
|
||||
*/
|
||||
$humanWeekOfMonth = ceil($humanDayOfMonth / 7);
|
||||
$humanWeekOfYear = ceil($dayofyear / 7);
|
||||
/*
|
||||
* Return an associative array of the values
|
||||
*/
|
||||
return array(
|
||||
"hdom" => $humanDayOfMonth,
|
||||
"hdow" => $humanDayOfWeek,
|
||||
"hwom" => $humanWeekOfMonth,
|
||||
"hwoy" => $humanWeekOfYear,
|
||||
"hmoy" => $humanMonthOfYear );
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ humanToGregorian()
|
||||
|
||||
/**
|
||||
* Returns unix timestamp for a given Human Calendar date
|
||||
*
|
||||
* @param int day in DD format
|
||||
* @param int month in MM format
|
||||
* @param int year in CCYY format, default to current local year
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @return int unix timestamp of date
|
||||
*/
|
||||
function humanToGregorian($day, $month, $year=0)
|
||||
{
|
||||
/*
|
||||
* Check to see if the year has been passed through.
|
||||
* If not get current year
|
||||
*/
|
||||
if (empty($year)) {
|
||||
$dateinfo = getdate(time());
|
||||
$year = $dateinfo["year"];
|
||||
}
|
||||
/*
|
||||
* We need to get the day of the year that we are currently at so that
|
||||
* we can work out the Gregorian Month and day
|
||||
*/
|
||||
$DayOfYear = $month * 28;
|
||||
$DayOfYear += $day;
|
||||
/*
|
||||
* Human Calendar starts at 0, so we need to increment $DayOfYear
|
||||
* to take into account the day 00
|
||||
*/
|
||||
$DayOfYear++;
|
||||
/*
|
||||
* the mktime() function will correctly calculate the date for out of
|
||||
* range values, so putting $DayOfYear instead of the day of the month
|
||||
* will work fine.
|
||||
*/
|
||||
$GregorianTimeStamp = mktime(0, 0, 0, 1, $DayOfYear, $year);
|
||||
return $GregorianTimeStamp;
|
||||
}
|
||||
|
||||
// }}}
|
||||
}
|
||||
|
||||
// }}}
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* mode: php
|
||||
* tab-width: 4
|
||||
* c-basic-offset: 4
|
||||
* c-hanging-comment-ender-p: nil
|
||||
* End:
|
||||
*/
|
||||
?>
|
||||
1083
sites/all/modules/civicrm/packages/Date/Span.php
Normal file
1083
sites/all/modules/civicrm/packages/Date/Span.php
Normal file
File diff suppressed because it is too large
Load diff
4731
sites/all/modules/civicrm/packages/Date/TimeZone.php
Normal file
4731
sites/all/modules/civicrm/packages/Date/TimeZone.php
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -0,0 +1,114 @@
|
|||
<?php
|
||||
//
|
||||
// FPDI - Version 1.5
|
||||
//
|
||||
// Copyright 2004-2014 Setasign - Jan Slabon
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
/**
|
||||
* Class FilterASCII85
|
||||
*/
|
||||
class FilterASCII85
|
||||
{
|
||||
/**
|
||||
* Decode ASCII85 encoded string
|
||||
*
|
||||
* @param string $in
|
||||
* @return string
|
||||
* @throws Exception
|
||||
*/
|
||||
public function decode($in)
|
||||
{
|
||||
$ord = array(
|
||||
'~' => ord('~'),
|
||||
'z' => ord('z'),
|
||||
'u' => ord('u'),
|
||||
'z' => ord('z'),
|
||||
'!' => ord('!')
|
||||
);
|
||||
|
||||
$out = '';
|
||||
$state = 0;
|
||||
$chn = null;
|
||||
|
||||
$l = strlen($in);
|
||||
|
||||
for ($k = 0; $k < $l; ++$k) {
|
||||
$ch = ord($in[$k]) & 0xff;
|
||||
|
||||
if ($ch == $ord['~']) {
|
||||
break;
|
||||
}
|
||||
if (preg_match('/^\s$/',chr($ch))) {
|
||||
continue;
|
||||
}
|
||||
if ($ch == $ord['z'] && $state == 0) {
|
||||
$out .= chr(0) . chr(0) . chr(0) . chr(0);
|
||||
continue;
|
||||
}
|
||||
if ($ch < $ord['!'] || $ch > $ord['u']) {
|
||||
throw new Exception('Illegal character in ASCII85Decode.');
|
||||
}
|
||||
|
||||
$chn[$state++] = $ch - $ord['!'];
|
||||
|
||||
if ($state == 5) {
|
||||
$state = 0;
|
||||
$r = 0;
|
||||
for ($j = 0; $j < 5; ++$j)
|
||||
$r = $r * 85 + $chn[$j];
|
||||
$out .= chr($r >> 24);
|
||||
$out .= chr($r >> 16);
|
||||
$out .= chr($r >> 8);
|
||||
$out .= chr($r);
|
||||
}
|
||||
}
|
||||
$r = 0;
|
||||
|
||||
if ($state == 1) {
|
||||
throw new Exception('Illegal length in ASCII85Decode.');
|
||||
}
|
||||
|
||||
if ($state == 2) {
|
||||
$r = $chn[0] * 85 * 85 * 85 * 85 + ($chn[1]+1) * 85 * 85 * 85;
|
||||
$out .= chr($r >> 24);
|
||||
|
||||
} else if ($state == 3) {
|
||||
$r = $chn[0] * 85 * 85 * 85 * 85 + $chn[1] * 85 * 85 * 85 + ($chn[2]+1) * 85 * 85;
|
||||
$out .= chr($r >> 24);
|
||||
$out .= chr($r >> 16);
|
||||
|
||||
} else if ($state == 4) {
|
||||
$r = $chn[0] * 85 * 85 * 85 * 85 + $chn[1] * 85 * 85 * 85 + $chn[2] * 85 * 85 + ($chn[3]+1) * 85 ;
|
||||
$out .= chr($r >> 24);
|
||||
$out .= chr($r >> 16);
|
||||
$out .= chr($r >> 8);
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* NOT IMPLEMENTED
|
||||
*
|
||||
* @param string $in
|
||||
* @return string
|
||||
* @throws LogicException
|
||||
*/
|
||||
public function encode($in)
|
||||
{
|
||||
throw new LogicException("ASCII85 encoding not implemented.");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
//
|
||||
// FPDI - Version 1.5
|
||||
//
|
||||
// Copyright 2004-2014 Setasign - Jan Slabon
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
/**
|
||||
* Class FilterASCIIHexDecode
|
||||
*/
|
||||
class FilterASCIIHexDecode
|
||||
{
|
||||
/**
|
||||
* Converts an ASCII hexadecimal encoded string into it's binary representation.
|
||||
*
|
||||
* @param string $data The input string
|
||||
* @return string
|
||||
*/
|
||||
public function decode($data)
|
||||
{
|
||||
$data = preg_replace('/[^0-9A-Fa-f]/', '', rtrim($data, '>'));
|
||||
if ((strlen($data) % 2) == 1) {
|
||||
$data .= '0';
|
||||
}
|
||||
|
||||
return pack('H*', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a string into ASCII hexadecimal representation.
|
||||
*
|
||||
* @param string $data The input string
|
||||
* @param boolean $leaveEOD
|
||||
* @return string
|
||||
*/
|
||||
public function encode($data, $leaveEOD = false)
|
||||
{
|
||||
return current(unpack('H*', $data)) . ($leaveEOD ? '' : '>');
|
||||
}
|
||||
}
|
||||
173
sites/all/modules/civicrm/packages/FPDI/filters/FilterLZW.php
Normal file
173
sites/all/modules/civicrm/packages/FPDI/filters/FilterLZW.php
Normal file
|
|
@ -0,0 +1,173 @@
|
|||
<?php
|
||||
//
|
||||
// FPDI - Version 1.5
|
||||
//
|
||||
// Copyright 2004-2014 Setasign - Jan Slabon
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
/**
|
||||
* Class FilterLZW
|
||||
*/
|
||||
class FilterLZW
|
||||
{
|
||||
protected $_sTable = array();
|
||||
protected $_data = null;
|
||||
protected $_dataLength = 0;
|
||||
protected $_tIdx;
|
||||
protected $_bitsToGet = 9;
|
||||
protected $_bytePointer;
|
||||
protected $_bitPointer;
|
||||
protected $_nextData = 0;
|
||||
protected $_nextBits = 0;
|
||||
protected $_andTable = array(511, 1023, 2047, 4095);
|
||||
|
||||
/**
|
||||
* Decodes LZW compressed data.
|
||||
*
|
||||
* @param string $data The compressed data.
|
||||
* @throws Exception
|
||||
* @return string
|
||||
*/
|
||||
public function decode($data)
|
||||
{
|
||||
if ($data[0] == 0x00 && $data[1] == 0x01) {
|
||||
throw new Exception('LZW flavour not supported.');
|
||||
}
|
||||
|
||||
$this->_initsTable();
|
||||
|
||||
$this->_data = $data;
|
||||
$this->_dataLength = strlen($data);
|
||||
|
||||
// Initialize pointers
|
||||
$this->_bytePointer = 0;
|
||||
$this->_bitPointer = 0;
|
||||
|
||||
$this->_nextData = 0;
|
||||
$this->_nextBits = 0;
|
||||
|
||||
$oldCode = 0;
|
||||
|
||||
$unCompData = '';
|
||||
|
||||
while (($code = $this->_getNextCode()) != 257) {
|
||||
if ($code == 256) {
|
||||
$this->_initsTable();
|
||||
$code = $this->_getNextCode();
|
||||
|
||||
if ($code == 257) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (!isset($this->_sTable[$code])) {
|
||||
throw new Exception('Error while decompression LZW compressed data.');
|
||||
}
|
||||
|
||||
$unCompData .= $this->_sTable[$code];
|
||||
$oldCode = $code;
|
||||
|
||||
} else {
|
||||
|
||||
if ($code < $this->_tIdx) {
|
||||
$string = $this->_sTable[$code];
|
||||
$unCompData .= $string;
|
||||
|
||||
$this->_addStringToTable($this->_sTable[$oldCode], $string[0]);
|
||||
$oldCode = $code;
|
||||
} else {
|
||||
$string = $this->_sTable[$oldCode];
|
||||
$string = $string . $string[0];
|
||||
$unCompData .= $string;
|
||||
|
||||
$this->_addStringToTable($string);
|
||||
$oldCode = $code;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $unCompData;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Initialize the string table.
|
||||
*/
|
||||
protected function _initsTable()
|
||||
{
|
||||
$this->_sTable = array();
|
||||
|
||||
for ($i = 0; $i < 256; $i++)
|
||||
$this->_sTable[$i] = chr($i);
|
||||
|
||||
$this->_tIdx = 258;
|
||||
$this->_bitsToGet = 9;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new string to the string table.
|
||||
*/
|
||||
protected function _addStringToTable($oldString, $newString = '')
|
||||
{
|
||||
$string = $oldString . $newString;
|
||||
|
||||
// Add this new String to the table
|
||||
$this->_sTable[$this->_tIdx++] = $string;
|
||||
|
||||
if ($this->_tIdx == 511) {
|
||||
$this->_bitsToGet = 10;
|
||||
} else if ($this->_tIdx == 1023) {
|
||||
$this->_bitsToGet = 11;
|
||||
} else if ($this->_tIdx == 2047) {
|
||||
$this->_bitsToGet = 12;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the next 9, 10, 11 or 12 bits
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
protected function _getNextCode()
|
||||
{
|
||||
if ($this->_bytePointer == $this->_dataLength) {
|
||||
return 257;
|
||||
}
|
||||
|
||||
$this->_nextData = ($this->_nextData << 8) | (ord($this->_data[$this->_bytePointer++]) & 0xff);
|
||||
$this->_nextBits += 8;
|
||||
|
||||
if ($this->_nextBits < $this->_bitsToGet) {
|
||||
$this->_nextData = ($this->_nextData << 8) | (ord($this->_data[$this->_bytePointer++]) & 0xff);
|
||||
$this->_nextBits += 8;
|
||||
}
|
||||
|
||||
$code = ($this->_nextData >> ($this->_nextBits - $this->_bitsToGet)) & $this->_andTable[$this->_bitsToGet-9];
|
||||
$this->_nextBits -= $this->_bitsToGet;
|
||||
|
||||
return $code;
|
||||
}
|
||||
|
||||
/**
|
||||
* NOT IMPLEMENTED
|
||||
*
|
||||
* @param string $in
|
||||
* @return string
|
||||
* @throws LogicException
|
||||
*/
|
||||
public function encode($in)
|
||||
{
|
||||
throw new LogicException("LZW encoding not implemented.");
|
||||
}
|
||||
}
|
||||
555
sites/all/modules/civicrm/packages/FPDI/fpdf_tpl.php
Normal file
555
sites/all/modules/civicrm/packages/FPDI/fpdf_tpl.php
Normal file
|
|
@ -0,0 +1,555 @@
|
|||
<?php
|
||||
//
|
||||
// FPDI - Version 1.5
|
||||
//
|
||||
// Copyright 2004-2014 Setasign - Jan Slabon
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
require_once('fpdi_bridge.php');
|
||||
|
||||
/**
|
||||
* Class FPDF_TPL
|
||||
*/
|
||||
class FPDF_TPL extends fpdi_bridge
|
||||
{
|
||||
/**
|
||||
* Array of template data
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_tpls = array();
|
||||
|
||||
/**
|
||||
* Current Template-Id
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $tpl = 0;
|
||||
|
||||
/**
|
||||
* "In Template"-Flag
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_inTpl = false;
|
||||
|
||||
/**
|
||||
* Name prefix of templates used in Resources dictionary
|
||||
*
|
||||
* @var string A String defining the Prefix used as Template-Object-Names. Have to begin with an /
|
||||
*/
|
||||
public $tplPrefix = "/TPL";
|
||||
|
||||
/**
|
||||
* Resources used by templates and pages
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_res = array();
|
||||
|
||||
/**
|
||||
* Last used template data
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $lastUsedTemplateData = array();
|
||||
|
||||
/**
|
||||
* Start a template.
|
||||
*
|
||||
* This method starts a template. You can give own coordinates to build an own sized
|
||||
* template. Pay attention, that the margins are adapted to the new template size.
|
||||
* If you want to write outside the template, for example to build a clipped template,
|
||||
* you have to set the margins and "cursor"-position manual after beginTemplate()-call.
|
||||
*
|
||||
* If no parameter is given, the template uses the current page-size.
|
||||
* The method returns an id of the current template. This id is used later for using this template.
|
||||
* Warning: A created template is saved in the resulting PDF at all events. Also if you don't use it after creation!
|
||||
*
|
||||
* @param int $x The x-coordinate given in user-unit
|
||||
* @param int $y The y-coordinate given in user-unit
|
||||
* @param int $w The width given in user-unit
|
||||
* @param int $h The height given in user-unit
|
||||
* @return int The id of new created template
|
||||
* @throws LogicException
|
||||
*/
|
||||
public function beginTemplate($x = null, $y = null, $w = null, $h = null)
|
||||
{
|
||||
if (is_subclass_of($this, 'TCPDF')) {
|
||||
throw new LogicException('This method is only usable with FPDF. Use TCPDF methods startTemplate() instead.');
|
||||
}
|
||||
|
||||
if ($this->page <= 0) {
|
||||
throw new LogicException("You have to add at least a page first!");
|
||||
}
|
||||
|
||||
if ($x == null)
|
||||
$x = 0;
|
||||
if ($y == null)
|
||||
$y = 0;
|
||||
if ($w == null)
|
||||
$w = $this->w;
|
||||
if ($h == null)
|
||||
$h = $this->h;
|
||||
|
||||
// Save settings
|
||||
$this->tpl++;
|
||||
$tpl =& $this->_tpls[$this->tpl];
|
||||
$tpl = array(
|
||||
'o_x' => $this->x,
|
||||
'o_y' => $this->y,
|
||||
'o_AutoPageBreak' => $this->AutoPageBreak,
|
||||
'o_bMargin' => $this->bMargin,
|
||||
'o_tMargin' => $this->tMargin,
|
||||
'o_lMargin' => $this->lMargin,
|
||||
'o_rMargin' => $this->rMargin,
|
||||
'o_h' => $this->h,
|
||||
'o_w' => $this->w,
|
||||
'o_FontFamily' => $this->FontFamily,
|
||||
'o_FontStyle' => $this->FontStyle,
|
||||
'o_FontSizePt' => $this->FontSizePt,
|
||||
'o_FontSize' => $this->FontSize,
|
||||
'buffer' => '',
|
||||
'x' => $x,
|
||||
'y' => $y,
|
||||
'w' => $w,
|
||||
'h' => $h
|
||||
);
|
||||
|
||||
$this->SetAutoPageBreak(false);
|
||||
|
||||
// Define own high and width to calculate correct positions
|
||||
$this->h = $h;
|
||||
$this->w = $w;
|
||||
|
||||
$this->_inTpl = true;
|
||||
$this->SetXY($x + $this->lMargin, $y + $this->tMargin);
|
||||
$this->SetRightMargin($this->w - $w + $this->rMargin);
|
||||
|
||||
if ($this->CurrentFont) {
|
||||
$fontKey = $this->FontFamily . $this->FontStyle;
|
||||
if ($fontKey) {
|
||||
$this->_res['tpl'][$this->tpl]['fonts'][$fontKey] =& $this->fonts[$fontKey];
|
||||
$this->_out(sprintf('BT /F%d %.2f Tf ET', $this->CurrentFont['i'], $this->FontSizePt));
|
||||
}
|
||||
}
|
||||
|
||||
return $this->tpl;
|
||||
}
|
||||
|
||||
/**
|
||||
* End template.
|
||||
*
|
||||
* This method ends a template and reset initiated variables collected in {@link beginTemplate()}.
|
||||
*
|
||||
* @return int|boolean If a template is opened, the id is returned. If not a false is returned.
|
||||
*/
|
||||
public function endTemplate()
|
||||
{
|
||||
if (is_subclass_of($this, 'TCPDF')) {
|
||||
$args = func_get_args();
|
||||
return call_user_func_array(array($this, 'TCPDF::endTemplate'), $args);
|
||||
}
|
||||
|
||||
if ($this->_inTpl) {
|
||||
$this->_inTpl = false;
|
||||
$tpl = $this->_tpls[$this->tpl];
|
||||
$this->SetXY($tpl['o_x'], $tpl['o_y']);
|
||||
$this->tMargin = $tpl['o_tMargin'];
|
||||
$this->lMargin = $tpl['o_lMargin'];
|
||||
$this->rMargin = $tpl['o_rMargin'];
|
||||
$this->h = $tpl['o_h'];
|
||||
$this->w = $tpl['o_w'];
|
||||
$this->SetAutoPageBreak($tpl['o_AutoPageBreak'], $tpl['o_bMargin']);
|
||||
|
||||
$this->FontFamily = $tpl['o_FontFamily'];
|
||||
$this->FontStyle = $tpl['o_FontStyle'];
|
||||
$this->FontSizePt = $tpl['o_FontSizePt'];
|
||||
$this->FontSize = $tpl['o_FontSize'];
|
||||
|
||||
$fontKey = $this->FontFamily . $this->FontStyle;
|
||||
if ($fontKey)
|
||||
$this->CurrentFont =& $this->fonts[$fontKey];
|
||||
|
||||
return $this->tpl;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Use a template in current page or other template.
|
||||
*
|
||||
* You can use a template in a page or in another template.
|
||||
* You can give the used template a new size.
|
||||
* All parameters are optional. The width or height is calculated automatically
|
||||
* if one is given. If no parameter is given the origin size as defined in
|
||||
* {@link beginTemplate()} method is used.
|
||||
*
|
||||
* The calculated or used width and height are returned as an array.
|
||||
*
|
||||
* @param int $tplIdx A valid template-id
|
||||
* @param int $x The x-position
|
||||
* @param int $y The y-position
|
||||
* @param int $w The new width of the template
|
||||
* @param int $h The new height of the template
|
||||
* @return array The height and width of the template (array('w' => ..., 'h' => ...))
|
||||
* @throws LogicException|InvalidArgumentException
|
||||
*/
|
||||
public function useTemplate($tplIdx, $x = null, $y = null, $w = 0, $h = 0)
|
||||
{
|
||||
if ($this->page <= 0) {
|
||||
throw new LogicException('You have to add at least a page first!');
|
||||
}
|
||||
|
||||
if (!isset($this->_tpls[$tplIdx])) {
|
||||
throw new InvalidArgumentException('Template does not exist!');
|
||||
}
|
||||
|
||||
if ($this->_inTpl) {
|
||||
$this->_res['tpl'][$this->tpl]['tpls'][$tplIdx] =& $this->_tpls[$tplIdx];
|
||||
}
|
||||
|
||||
$tpl = $this->_tpls[$tplIdx];
|
||||
$_w = $tpl['w'];
|
||||
$_h = $tpl['h'];
|
||||
|
||||
if ($x == null) {
|
||||
$x = 0;
|
||||
}
|
||||
|
||||
if ($y == null) {
|
||||
$y = 0;
|
||||
}
|
||||
|
||||
$x += $tpl['x'];
|
||||
$y += $tpl['y'];
|
||||
|
||||
$wh = $this->getTemplateSize($tplIdx, $w, $h);
|
||||
$w = $wh['w'];
|
||||
$h = $wh['h'];
|
||||
|
||||
$tplData = array(
|
||||
'x' => $this->x,
|
||||
'y' => $this->y,
|
||||
'w' => $w,
|
||||
'h' => $h,
|
||||
'scaleX' => ($w / $_w),
|
||||
'scaleY' => ($h / $_h),
|
||||
'tx' => $x,
|
||||
'ty' => ($this->h - $y - $h),
|
||||
'lty' => ($this->h - $y - $h) - ($this->h - $_h) * ($h / $_h)
|
||||
);
|
||||
|
||||
$this->_out(sprintf('q %.4F 0 0 %.4F %.4F %.4F cm',
|
||||
$tplData['scaleX'], $tplData['scaleY'], $tplData['tx'] * $this->k, $tplData['ty'] * $this->k)
|
||||
); // Translate
|
||||
$this->_out(sprintf('%s%d Do Q', $this->tplPrefix, $tplIdx));
|
||||
|
||||
$this->lastUsedTemplateData = $tplData;
|
||||
|
||||
return array('w' => $w, 'h' => $h);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the calculated size of a template.
|
||||
*
|
||||
* If one size is given, this method calculates the other one.
|
||||
*
|
||||
* @param int $tplIdx A valid template-id
|
||||
* @param int $w The width of the template
|
||||
* @param int $h The height of the template
|
||||
* @return array The height and width of the template (array('w' => ..., 'h' => ...))
|
||||
*/
|
||||
public function getTemplateSize($tplIdx, $w = 0, $h = 0)
|
||||
{
|
||||
if (!isset($this->_tpls[$tplIdx]))
|
||||
return false;
|
||||
|
||||
$tpl = $this->_tpls[$tplIdx];
|
||||
$_w = $tpl['w'];
|
||||
$_h = $tpl['h'];
|
||||
|
||||
if ($w == 0 && $h == 0) {
|
||||
$w = $_w;
|
||||
$h = $_h;
|
||||
}
|
||||
|
||||
if ($w == 0)
|
||||
$w = $h * $_w / $_h;
|
||||
if($h == 0)
|
||||
$h = $w * $_h / $_w;
|
||||
|
||||
return array("w" => $w, "h" => $h);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the font used to print character strings.
|
||||
*
|
||||
* See FPDF/TCPDF documentation.
|
||||
*
|
||||
* @see http://fpdf.org/en/doc/setfont.htm
|
||||
* @see http://www.tcpdf.org/doc/code/classTCPDF.html#afd56e360c43553830d543323e81bc045
|
||||
*/
|
||||
public function SetFont($family, $style = '', $size = null, $fontfile = '', $subset = 'default', $out = true)
|
||||
{
|
||||
if (is_subclass_of($this, 'TCPDF')) {
|
||||
$args = func_get_args();
|
||||
return call_user_func_array(array($this, 'TCPDF::SetFont'), $args);
|
||||
}
|
||||
|
||||
parent::SetFont($family, $style, $size);
|
||||
|
||||
$fontkey = $this->FontFamily . $this->FontStyle;
|
||||
|
||||
if ($this->_inTpl) {
|
||||
$this->_res['tpl'][$this->tpl]['fonts'][$fontkey] =& $this->fonts[$fontkey];
|
||||
} else {
|
||||
$this->_res['page'][$this->page]['fonts'][$fontkey] =& $this->fonts[$fontkey];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Puts an image.
|
||||
*
|
||||
* See FPDF/TCPDF documentation.
|
||||
*
|
||||
* @see http://fpdf.org/en/doc/image.htm
|
||||
* @see http://www.tcpdf.org/doc/code/classTCPDF.html#a714c2bee7d6b39d4d6d304540c761352
|
||||
*/
|
||||
public function Image(
|
||||
$file, $x = '', $y = '', $w = 0, $h = 0, $type = '', $link = '', $align = '', $resize = false,
|
||||
$dpi = 300, $palign = '', $ismask = false, $imgmask = false, $border = 0, $fitbox = false,
|
||||
$hidden = false, $fitonpage = false, $alt = false, $altimgs = array()
|
||||
)
|
||||
{
|
||||
if (is_subclass_of($this, 'TCPDF')) {
|
||||
$args = func_get_args();
|
||||
return call_user_func_array(array($this, 'TCPDF::Image'), $args);
|
||||
}
|
||||
|
||||
$ret = parent::Image($file, $x, $y, $w, $h, $type, $link);
|
||||
if ($this->_inTpl) {
|
||||
$this->_res['tpl'][$this->tpl]['images'][$file] =& $this->images[$file];
|
||||
} else {
|
||||
$this->_res['page'][$this->page]['images'][$file] =& $this->images[$file];
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new page to the document.
|
||||
*
|
||||
* See FPDF/TCPDF documentation.
|
||||
*
|
||||
* This method cannot be used if you'd started a template.
|
||||
*
|
||||
* @see http://fpdf.org/en/doc/addpage.htm
|
||||
* @see http://www.tcpdf.org/doc/code/classTCPDF.html#a5171e20b366b74523709d84c349c1ced
|
||||
*/
|
||||
public function AddPage($orientation = '', $format = '', $keepmargins = false, $tocpage = false)
|
||||
{
|
||||
if (is_subclass_of($this, 'TCPDF')) {
|
||||
$args = func_get_args();
|
||||
return call_user_func_array(array($this, 'TCPDF::AddPage'), $args);
|
||||
}
|
||||
|
||||
if ($this->_inTpl) {
|
||||
throw new LogicException('Adding pages in templates is not possible!');
|
||||
}
|
||||
|
||||
parent::AddPage($orientation, $format);
|
||||
}
|
||||
|
||||
/**
|
||||
* Puts a link on a rectangular area of the page.
|
||||
*
|
||||
* Overwritten because adding links in a template will not work.
|
||||
*
|
||||
* @see http://fpdf.org/en/doc/link.htm
|
||||
* @see http://www.tcpdf.org/doc/code/classTCPDF.html#ab87bf1826384fbfe30eb499d42f1d994
|
||||
*/
|
||||
public function Link($x, $y, $w, $h, $link, $spaces = 0)
|
||||
{
|
||||
if (is_subclass_of($this, 'TCPDF')) {
|
||||
$args = func_get_args();
|
||||
return call_user_func_array(array($this, 'TCPDF::Link'), $args);
|
||||
}
|
||||
|
||||
if ($this->_inTpl) {
|
||||
throw new LogicException('Using links in templates is not posible!');
|
||||
}
|
||||
|
||||
parent::Link($x, $y, $w, $h, $link);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new internal link and returns its identifier.
|
||||
*
|
||||
* Overwritten because adding links in a template will not work.
|
||||
*
|
||||
* @see http://fpdf.org/en/doc/addlink.htm
|
||||
* @see http://www.tcpdf.org/doc/code/classTCPDF.html#a749522038ed7786c3e1701435dcb891e
|
||||
*/
|
||||
public function AddLink()
|
||||
{
|
||||
if (is_subclass_of($this, 'TCPDF')) {
|
||||
$args = func_get_args();
|
||||
return call_user_func_array(array($this, 'TCPDF::AddLink'), $args);
|
||||
}
|
||||
|
||||
if ($this->_inTpl) {
|
||||
throw new LogicException('Adding links in templates is not possible!');
|
||||
}
|
||||
|
||||
return parent::AddLink();
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the page and position a link points to.
|
||||
*
|
||||
* Overwritten because adding links in a template will not work.
|
||||
*
|
||||
* @see http://fpdf.org/en/doc/setlink.htm
|
||||
* @see http://www.tcpdf.org/doc/code/classTCPDF.html#ace5be60e7857953ea5e2b89cb90df0ae
|
||||
*/
|
||||
public function SetLink($link, $y = 0, $page = -1)
|
||||
{
|
||||
if (is_subclass_of($this, 'TCPDF')) {
|
||||
$args = func_get_args();
|
||||
return call_user_func_array(array($this, 'TCPDF::SetLink'), $args);
|
||||
}
|
||||
|
||||
if ($this->_inTpl) {
|
||||
throw new LogicException('Setting links in templates is not possible!');
|
||||
}
|
||||
|
||||
parent::SetLink($link, $y, $page);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the form XObjects to the PDF document.
|
||||
*/
|
||||
protected function _putformxobjects()
|
||||
{
|
||||
$filter=($this->compress) ? '/Filter /FlateDecode ' : '';
|
||||
reset($this->_tpls);
|
||||
|
||||
foreach($this->_tpls AS $tplIdx => $tpl) {
|
||||
$this->_newobj();
|
||||
$this->_tpls[$tplIdx]['n'] = $this->n;
|
||||
$this->_out('<<'.$filter.'/Type /XObject');
|
||||
$this->_out('/Subtype /Form');
|
||||
$this->_out('/FormType 1');
|
||||
$this->_out(sprintf('/BBox [%.2F %.2F %.2F %.2F]',
|
||||
// llx
|
||||
$tpl['x'] * $this->k,
|
||||
// lly
|
||||
-$tpl['y'] * $this->k,
|
||||
// urx
|
||||
($tpl['w'] + $tpl['x']) * $this->k,
|
||||
// ury
|
||||
($tpl['h'] - $tpl['y']) * $this->k
|
||||
));
|
||||
|
||||
if ($tpl['x'] != 0 || $tpl['y'] != 0) {
|
||||
$this->_out(sprintf('/Matrix [1 0 0 1 %.5F %.5F]',
|
||||
-$tpl['x'] * $this->k * 2, $tpl['y'] * $this->k * 2
|
||||
));
|
||||
}
|
||||
|
||||
$this->_out('/Resources ');
|
||||
$this->_out('<</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]');
|
||||
|
||||
if (isset($this->_res['tpl'][$tplIdx])) {
|
||||
$res = $this->_res['tpl'][$tplIdx];
|
||||
if (isset($res['fonts']) && count($res['fonts'])) {
|
||||
$this->_out('/Font <<');
|
||||
|
||||
foreach($res['fonts'] as $font) {
|
||||
$this->_out('/F' . $font['i'] . ' ' . $font['n'] . ' 0 R');
|
||||
}
|
||||
|
||||
$this->_out('>>');
|
||||
}
|
||||
|
||||
if(isset($res['images']) || isset($res['tpls'])) {
|
||||
$this->_out('/XObject <<');
|
||||
|
||||
if (isset($res['images'])) {
|
||||
foreach($res['images'] as $image)
|
||||
$this->_out('/I' . $image['i'] . ' ' . $image['n'] . ' 0 R');
|
||||
}
|
||||
|
||||
if (isset($res['tpls'])) {
|
||||
foreach($res['tpls'] as $i => $_tpl)
|
||||
$this->_out($this->tplPrefix . $i . ' ' . $_tpl['n'] . ' 0 R');
|
||||
}
|
||||
|
||||
$this->_out('>>');
|
||||
}
|
||||
}
|
||||
|
||||
$this->_out('>>');
|
||||
|
||||
$buffer = ($this->compress) ? gzcompress($tpl['buffer']) : $tpl['buffer'];
|
||||
$this->_out('/Length ' . strlen($buffer) . ' >>');
|
||||
$this->_putstream($buffer);
|
||||
$this->_out('endobj');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Output images.
|
||||
*
|
||||
* Overwritten to add {@link _putformxobjects()} after _putimages().
|
||||
*/
|
||||
public function _putimages()
|
||||
{
|
||||
parent::_putimages();
|
||||
$this->_putformxobjects();
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the references of XObject resources to the document.
|
||||
*
|
||||
* Overwritten to add the the templates to the XObject resource dictionary.
|
||||
*/
|
||||
public function _putxobjectdict()
|
||||
{
|
||||
parent::_putxobjectdict();
|
||||
|
||||
foreach($this->_tpls as $tplIdx => $tpl) {
|
||||
$this->_out(sprintf('%s%d %d 0 R', $this->tplPrefix, $tplIdx, $tpl['n']));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes bytes to the resulting document.
|
||||
*
|
||||
* Overwritten to delegate the data to the template buffer.
|
||||
*
|
||||
* @param string $s
|
||||
*/
|
||||
public function _out($s)
|
||||
{
|
||||
if ($this->state == 2 && $this->_inTpl) {
|
||||
$this->_tpls[$this->tpl]['buffer'] .= $s . "\n";
|
||||
} else {
|
||||
parent::_out($s);
|
||||
}
|
||||
}
|
||||
}
|
||||
695
sites/all/modules/civicrm/packages/FPDI/fpdi.php
Normal file
695
sites/all/modules/civicrm/packages/FPDI/fpdi.php
Normal file
|
|
@ -0,0 +1,695 @@
|
|||
<?php
|
||||
//
|
||||
// FPDI - Version 1.5
|
||||
//
|
||||
// Copyright 2004-2014 Setasign - Jan Slabon
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
require_once('fpdf_tpl.php');
|
||||
|
||||
/**
|
||||
* Class FPDI
|
||||
*/
|
||||
class FPDI extends FPDF_TPL
|
||||
{
|
||||
/**
|
||||
* FPDI version
|
||||
*
|
||||
* @string
|
||||
*/
|
||||
const VERSION = '1.5.0';
|
||||
|
||||
/**
|
||||
* Actual filename
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $currentFilename;
|
||||
|
||||
/**
|
||||
* Parser-Objects
|
||||
*
|
||||
* @var fpdi_pdf_parser[]
|
||||
*/
|
||||
public $parsers;
|
||||
|
||||
/**
|
||||
* Current parser
|
||||
*
|
||||
* @var fpdi_pdf_parser
|
||||
*/
|
||||
public $currentParser;
|
||||
|
||||
/**
|
||||
* The name of the last imported page box
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $lastUsedPageBox;
|
||||
|
||||
/**
|
||||
* Object stack
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_objStack;
|
||||
|
||||
/**
|
||||
* Done object stack
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_doneObjStack;
|
||||
|
||||
/**
|
||||
* Current Object Id.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $_currentObjId;
|
||||
|
||||
/**
|
||||
* Cache for imported pages/template ids
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_importedPages = array();
|
||||
|
||||
/**
|
||||
* Set a source-file.
|
||||
*
|
||||
* Depending on the PDF version of the used document the PDF version of the resulting document will
|
||||
* be adjusted to the higher version.
|
||||
*
|
||||
* @param string $filename A valid path to the PDF document from which pages should be imported from
|
||||
* @return int The number of pages in the document
|
||||
*/
|
||||
public function setSourceFile($filename)
|
||||
{
|
||||
$_filename = realpath($filename);
|
||||
if (false !== $_filename)
|
||||
$filename = $_filename;
|
||||
|
||||
$this->currentFilename = $filename;
|
||||
|
||||
if (!isset($this->parsers[$filename])) {
|
||||
$this->parsers[$filename] = $this->_getPdfParser($filename);
|
||||
$this->setPdfVersion(
|
||||
max($this->getPdfVersion(), $this->parsers[$filename]->getPdfVersion())
|
||||
);
|
||||
}
|
||||
|
||||
$this->currentParser =& $this->parsers[$filename];
|
||||
|
||||
return $this->parsers[$filename]->getPageCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a PDF parser object
|
||||
*
|
||||
* @param string $filename
|
||||
* @return fpdi_pdf_parser
|
||||
*/
|
||||
protected function _getPdfParser($filename)
|
||||
{
|
||||
require_once('fpdi_pdf_parser.php');
|
||||
return new fpdi_pdf_parser($filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current PDF version.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPdfVersion()
|
||||
{
|
||||
return $this->PDFVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the PDF version.
|
||||
*
|
||||
* @param string $version
|
||||
*/
|
||||
public function setPdfVersion($version = '1.3')
|
||||
{
|
||||
$this->PDFVersion = $version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Import a page.
|
||||
*
|
||||
* The second parameter defines the bounding box that should be used to transform the page into a
|
||||
* form XObject.
|
||||
*
|
||||
* Following values are available: MediaBox, CropBox, BleedBox, TrimBox, ArtBox.
|
||||
* If a box is not especially defined its default box will be used:
|
||||
*
|
||||
* <ul>
|
||||
* <li>CropBox: Default -> MediaBox</li>
|
||||
* <li>BleedBox: Default -> CropBox</li>
|
||||
* <li>TrimBox: Default -> CropBox</li>
|
||||
* <li>ArtBox: Default -> CropBox</li>
|
||||
* </ul>
|
||||
*
|
||||
* It is possible to get the used page box by the {@link getLastUsedPageBox()} method.
|
||||
*
|
||||
* @param int $pageNo The page number
|
||||
* @param string $boxName The boundary box to use when transforming the page into a form XObject
|
||||
* @param boolean $groupXObject Define the form XObject as a group XObject to support transparency (if used)
|
||||
* @return int An id of the imported page/template to use with e.g. fpdf_tpl::useTemplate()
|
||||
* @throws LogicException|InvalidArgumentException
|
||||
* @see getLastUsedPageBox()
|
||||
*/
|
||||
public function importPage($pageNo, $boxName = 'CropBox', $groupXObject = true)
|
||||
{
|
||||
if ($this->_inTpl) {
|
||||
throw new LogicException('Please import the desired pages before creating a new template.');
|
||||
}
|
||||
|
||||
$fn = $this->currentFilename;
|
||||
$boxName = '/' . ltrim($boxName, '/');
|
||||
|
||||
// check if page already imported
|
||||
$pageKey = $fn . '-' . ((int)$pageNo) . $boxName;
|
||||
if (isset($this->_importedPages[$pageKey])) {
|
||||
return $this->_importedPages[$pageKey];
|
||||
}
|
||||
|
||||
$parser = $this->parsers[$fn];
|
||||
$parser->setPageNo($pageNo);
|
||||
|
||||
if (!in_array($boxName, $parser->availableBoxes)) {
|
||||
throw new InvalidArgumentException(sprintf('Unknown box: %s', $boxName));
|
||||
}
|
||||
|
||||
$pageBoxes = $parser->getPageBoxes($pageNo, $this->k);
|
||||
|
||||
/**
|
||||
* MediaBox
|
||||
* CropBox: Default -> MediaBox
|
||||
* BleedBox: Default -> CropBox
|
||||
* TrimBox: Default -> CropBox
|
||||
* ArtBox: Default -> CropBox
|
||||
*/
|
||||
if (!isset($pageBoxes[$boxName]) && ($boxName == '/BleedBox' || $boxName == '/TrimBox' || $boxName == '/ArtBox'))
|
||||
$boxName = '/CropBox';
|
||||
if (!isset($pageBoxes[$boxName]) && $boxName == '/CropBox')
|
||||
$boxName = '/MediaBox';
|
||||
|
||||
if (!isset($pageBoxes[$boxName]))
|
||||
return false;
|
||||
|
||||
$this->lastUsedPageBox = $boxName;
|
||||
|
||||
$box = $pageBoxes[$boxName];
|
||||
|
||||
$this->tpl++;
|
||||
$this->_tpls[$this->tpl] = array();
|
||||
$tpl =& $this->_tpls[$this->tpl];
|
||||
$tpl['parser'] = $parser;
|
||||
$tpl['resources'] = $parser->getPageResources();
|
||||
$tpl['buffer'] = $parser->getContent();
|
||||
$tpl['box'] = $box;
|
||||
$tpl['groupXObject'] = $groupXObject;
|
||||
if ($groupXObject) {
|
||||
$this->setPdfVersion(max($this->getPdfVersion(), 1.4));
|
||||
}
|
||||
|
||||
// To build an array that can be used by PDF_TPL::useTemplate()
|
||||
$this->_tpls[$this->tpl] = array_merge($this->_tpls[$this->tpl], $box);
|
||||
|
||||
// An imported page will start at 0,0 all the time. Translation will be set in _putformxobjects()
|
||||
$tpl['x'] = 0;
|
||||
$tpl['y'] = 0;
|
||||
|
||||
// handle rotated pages
|
||||
$rotation = $parser->getPageRotation($pageNo);
|
||||
$tpl['_rotationAngle'] = 0;
|
||||
if (isset($rotation[1]) && ($angle = $rotation[1] % 360) != 0) {
|
||||
$steps = $angle / 90;
|
||||
|
||||
$_w = $tpl['w'];
|
||||
$_h = $tpl['h'];
|
||||
$tpl['w'] = $steps % 2 == 0 ? $_w : $_h;
|
||||
$tpl['h'] = $steps % 2 == 0 ? $_h : $_w;
|
||||
|
||||
if ($angle < 0)
|
||||
$angle += 360;
|
||||
|
||||
$tpl['_rotationAngle'] = $angle * -1;
|
||||
}
|
||||
|
||||
$this->_importedPages[$pageKey] = $this->tpl;
|
||||
|
||||
return $this->tpl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the last used page boundary box.
|
||||
*
|
||||
* @return string The used boundary box: MediaBox, CropBox, BleedBox, TrimBox or ArtBox
|
||||
*/
|
||||
public function getLastUsedPageBox()
|
||||
{
|
||||
return $this->lastUsedPageBox;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use a template or imported page in current page or other template.
|
||||
*
|
||||
* You can use a template in a page or in another template.
|
||||
* You can give the used template a new size. All parameters are optional.
|
||||
* The width or height is calculated automatically if one is given. If no
|
||||
* parameter is given the origin size as defined in beginTemplate() or of
|
||||
* the imported page is used.
|
||||
*
|
||||
* The calculated or used width and height are returned as an array.
|
||||
*
|
||||
* @param int $tplIdx A valid template-id
|
||||
* @param int $x The x-position
|
||||
* @param int $y The y-position
|
||||
* @param int $w The new width of the template
|
||||
* @param int $h The new height of the template
|
||||
* @param boolean $adjustPageSize If set to true the current page will be resized to fit the dimensions
|
||||
* of the template
|
||||
*
|
||||
* @return array The height and width of the template (array('w' => ..., 'h' => ...))
|
||||
* @throws LogicException|InvalidArgumentException
|
||||
*/
|
||||
public function useTemplate($tplIdx, $x = null, $y = null, $w = 0, $h = 0, $adjustPageSize = false)
|
||||
{
|
||||
if ($adjustPageSize == true && is_null($x) && is_null($y)) {
|
||||
$size = $this->getTemplateSize($tplIdx, $w, $h);
|
||||
$orientation = $size['w'] > $size['h'] ? 'L' : 'P';
|
||||
$size = array($size['w'], $size['h']);
|
||||
|
||||
if (is_subclass_of($this, 'TCPDF')) {
|
||||
$this->setPageFormat($size, $orientation);
|
||||
} else {
|
||||
$size = $this->_getpagesize($size);
|
||||
|
||||
if($orientation != $this->CurOrientation ||
|
||||
$size[0] != $this->CurPageSize[0] ||
|
||||
$size[1] != $this->CurPageSize[1]
|
||||
) {
|
||||
// New size or orientation
|
||||
if ($orientation=='P') {
|
||||
$this->w = $size[0];
|
||||
$this->h = $size[1];
|
||||
} else {
|
||||
$this->w = $size[1];
|
||||
$this->h = $size[0];
|
||||
}
|
||||
$this->wPt = $this->w * $this->k;
|
||||
$this->hPt = $this->h * $this->k;
|
||||
$this->PageBreakTrigger = $this->h - $this->bMargin;
|
||||
$this->CurOrientation = $orientation;
|
||||
$this->CurPageSize = $size;
|
||||
$this->PageSizes[$this->page] = array($this->wPt, $this->hPt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->_out('q 0 J 1 w 0 j 0 G 0 g'); // reset standard values
|
||||
$size = parent::useTemplate($tplIdx, $x, $y, $w, $h);
|
||||
$this->_out('Q');
|
||||
|
||||
return $size;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy all imported objects to the resulting document.
|
||||
*/
|
||||
protected function _putimportedobjects()
|
||||
{
|
||||
if (!is_array($this->parsers) || count($this->parsers) === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach($this->parsers AS $filename => $p) {
|
||||
$this->currentParser =& $p;
|
||||
if (!isset($this->_objStack[$filename]) || !is_array($this->_objStack[$filename])) {
|
||||
continue;
|
||||
}
|
||||
while(($n = key($this->_objStack[$filename])) !== null) {
|
||||
$nObj = $this->currentParser->resolveObject($this->_objStack[$filename][$n][1]);
|
||||
|
||||
$this->_newobj($this->_objStack[$filename][$n][0]);
|
||||
|
||||
if ($nObj[0] == pdf_parser::TYPE_STREAM) {
|
||||
$this->_writeValue($nObj);
|
||||
} else {
|
||||
$this->_writeValue($nObj[1]);
|
||||
}
|
||||
|
||||
$this->_out("\nendobj");
|
||||
$this->_objStack[$filename][$n] = null; // free memory
|
||||
unset($this->_objStack[$filename][$n]);
|
||||
reset($this->_objStack[$filename]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the form XObjects to the PDF document.
|
||||
*/
|
||||
protected function _putformxobjects()
|
||||
{
|
||||
$filter=($this->compress) ? '/Filter /FlateDecode ' : '';
|
||||
reset($this->_tpls);
|
||||
foreach($this->_tpls AS $tplIdx => $tpl) {
|
||||
$this->_newobj();
|
||||
$currentN = $this->n; // TCPDF/Protection: rem current "n"
|
||||
|
||||
$this->_tpls[$tplIdx]['n'] = $this->n;
|
||||
$this->_out('<<' . $filter . '/Type /XObject');
|
||||
$this->_out('/Subtype /Form');
|
||||
$this->_out('/FormType 1');
|
||||
|
||||
$this->_out(sprintf('/BBox [%.2F %.2F %.2F %.2F]',
|
||||
(isset($tpl['box']['llx']) ? $tpl['box']['llx'] : $tpl['x']) * $this->k,
|
||||
(isset($tpl['box']['lly']) ? $tpl['box']['lly'] : -$tpl['y']) * $this->k,
|
||||
(isset($tpl['box']['urx']) ? $tpl['box']['urx'] : $tpl['w'] + $tpl['x']) * $this->k,
|
||||
(isset($tpl['box']['ury']) ? $tpl['box']['ury'] : $tpl['h'] - $tpl['y']) * $this->k
|
||||
));
|
||||
|
||||
$c = 1;
|
||||
$s = 0;
|
||||
$tx = 0;
|
||||
$ty = 0;
|
||||
|
||||
if (isset($tpl['box'])) {
|
||||
$tx = -$tpl['box']['llx'];
|
||||
$ty = -$tpl['box']['lly'];
|
||||
|
||||
if ($tpl['_rotationAngle'] <> 0) {
|
||||
$angle = $tpl['_rotationAngle'] * M_PI/180;
|
||||
$c = cos($angle);
|
||||
$s = sin($angle);
|
||||
|
||||
switch($tpl['_rotationAngle']) {
|
||||
case -90:
|
||||
$tx = -$tpl['box']['lly'];
|
||||
$ty = $tpl['box']['urx'];
|
||||
break;
|
||||
case -180:
|
||||
$tx = $tpl['box']['urx'];
|
||||
$ty = $tpl['box']['ury'];
|
||||
break;
|
||||
case -270:
|
||||
$tx = $tpl['box']['ury'];
|
||||
$ty = -$tpl['box']['llx'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if ($tpl['x'] != 0 || $tpl['y'] != 0) {
|
||||
$tx = -$tpl['x'] * 2;
|
||||
$ty = $tpl['y'] * 2;
|
||||
}
|
||||
|
||||
$tx *= $this->k;
|
||||
$ty *= $this->k;
|
||||
|
||||
if ($c != 1 || $s != 0 || $tx != 0 || $ty != 0) {
|
||||
$this->_out(sprintf('/Matrix [%.5F %.5F %.5F %.5F %.5F %.5F]',
|
||||
$c, $s, -$s, $c, $tx, $ty
|
||||
));
|
||||
}
|
||||
|
||||
$this->_out('/Resources ');
|
||||
|
||||
if (isset($tpl['resources'])) {
|
||||
$this->currentParser = $tpl['parser'];
|
||||
$this->_writeValue($tpl['resources']); // "n" will be changed
|
||||
} else {
|
||||
|
||||
$this->_out('<</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]');
|
||||
if (isset($this->_res['tpl'][$tplIdx])) {
|
||||
$res = $this->_res['tpl'][$tplIdx];
|
||||
|
||||
if (isset($res['fonts']) && count($res['fonts'])) {
|
||||
$this->_out('/Font <<');
|
||||
foreach ($res['fonts'] as $font)
|
||||
$this->_out('/F' . $font['i'] . ' ' . $font['n'] . ' 0 R');
|
||||
$this->_out('>>');
|
||||
}
|
||||
if (isset($res['images']) && count($res['images']) ||
|
||||
isset($res['tpls']) && count($res['tpls']))
|
||||
{
|
||||
$this->_out('/XObject <<');
|
||||
if (isset($res['images'])) {
|
||||
foreach ($res['images'] as $image)
|
||||
$this->_out('/I' . $image['i'] . ' ' . $image['n'] . ' 0 R');
|
||||
}
|
||||
if (isset($res['tpls'])) {
|
||||
foreach ($res['tpls'] as $i => $_tpl)
|
||||
$this->_out($this->tplPrefix . $i . ' ' . $_tpl['n'] . ' 0 R');
|
||||
}
|
||||
$this->_out('>>');
|
||||
}
|
||||
$this->_out('>>');
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($tpl['groupXObject']) && $tpl['groupXObject']) {
|
||||
$this->_out('/Group <</Type/Group/S/Transparency>>');
|
||||
}
|
||||
|
||||
$newN = $this->n; // TCPDF: rem new "n"
|
||||
$this->n = $currentN; // TCPDF: reset to current "n"
|
||||
|
||||
$buffer = ($this->compress) ? gzcompress($tpl['buffer']) : $tpl['buffer'];
|
||||
|
||||
if (is_subclass_of($this, 'TCPDF')) {
|
||||
$buffer = $this->_getrawstream($buffer);
|
||||
$this->_out('/Length ' . strlen($buffer) . ' >>');
|
||||
$this->_out("stream\n" . $buffer . "\nendstream");
|
||||
} else {
|
||||
$this->_out('/Length ' . strlen($buffer) . ' >>');
|
||||
$this->_putstream($buffer);
|
||||
}
|
||||
$this->_out('endobj');
|
||||
$this->n = $newN; // TCPDF: reset to new "n"
|
||||
}
|
||||
|
||||
$this->_putimportedobjects();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and optionally write the object definition to the document.
|
||||
*
|
||||
* Rewritten to handle existing own defined objects
|
||||
*
|
||||
* @param bool $objId
|
||||
* @param bool $onlyNewObj
|
||||
* @return bool|int
|
||||
*/
|
||||
public function _newobj($objId = false, $onlyNewObj = false)
|
||||
{
|
||||
if (!$objId) {
|
||||
$objId = ++$this->n;
|
||||
}
|
||||
|
||||
//Begin a new object
|
||||
if (!$onlyNewObj) {
|
||||
$this->offsets[$objId] = is_subclass_of($this, 'TCPDF') ? $this->bufferlen : strlen($this->buffer);
|
||||
$this->_out($objId . ' 0 obj');
|
||||
$this->_currentObjId = $objId; // for later use with encryption
|
||||
}
|
||||
|
||||
return $objId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a PDF value to the resulting document.
|
||||
*
|
||||
* Needed to rebuild the source document
|
||||
*
|
||||
* @param mixed $value A PDF-Value. Structure of values see cases in this method
|
||||
*/
|
||||
protected function _writeValue(&$value)
|
||||
{
|
||||
if (is_subclass_of($this, 'TCPDF')) {
|
||||
parent::_prepareValue($value);
|
||||
}
|
||||
|
||||
switch ($value[0]) {
|
||||
|
||||
case pdf_parser::TYPE_TOKEN:
|
||||
$this->_straightOut($value[1] . ' ');
|
||||
break;
|
||||
case pdf_parser::TYPE_NUMERIC:
|
||||
case pdf_parser::TYPE_REAL:
|
||||
if (is_float($value[1]) && $value[1] != 0) {
|
||||
$this->_straightOut(rtrim(rtrim(sprintf('%F', $value[1]), '0'), '.') . ' ');
|
||||
} else {
|
||||
$this->_straightOut($value[1] . ' ');
|
||||
}
|
||||
break;
|
||||
|
||||
case pdf_parser::TYPE_ARRAY:
|
||||
|
||||
// An array. Output the proper
|
||||
// structure and move on.
|
||||
|
||||
$this->_straightOut('[');
|
||||
for ($i = 0; $i < count($value[1]); $i++) {
|
||||
$this->_writeValue($value[1][$i]);
|
||||
}
|
||||
|
||||
$this->_out(']');
|
||||
break;
|
||||
|
||||
case pdf_parser::TYPE_DICTIONARY:
|
||||
|
||||
// A dictionary.
|
||||
$this->_straightOut('<<');
|
||||
|
||||
reset ($value[1]);
|
||||
|
||||
while (list($k, $v) = each($value[1])) {
|
||||
$this->_straightOut($k . ' ');
|
||||
$this->_writeValue($v);
|
||||
}
|
||||
|
||||
$this->_straightOut('>>');
|
||||
break;
|
||||
|
||||
case pdf_parser::TYPE_OBJREF:
|
||||
|
||||
// An indirect object reference
|
||||
// Fill the object stack if needed
|
||||
$cpfn =& $this->currentParser->filename;
|
||||
if (!isset($this->_doneObjStack[$cpfn][$value[1]])) {
|
||||
$this->_newobj(false, true);
|
||||
$this->_objStack[$cpfn][$value[1]] = array($this->n, $value);
|
||||
$this->_doneObjStack[$cpfn][$value[1]] = array($this->n, $value);
|
||||
}
|
||||
$objId = $this->_doneObjStack[$cpfn][$value[1]][0];
|
||||
|
||||
$this->_out($objId . ' 0 R');
|
||||
break;
|
||||
|
||||
case pdf_parser::TYPE_STRING:
|
||||
|
||||
// A string.
|
||||
$this->_straightOut('(' . $value[1] . ')');
|
||||
|
||||
break;
|
||||
|
||||
case pdf_parser::TYPE_STREAM:
|
||||
|
||||
// A stream. First, output the
|
||||
// stream dictionary, then the
|
||||
// stream data itself.
|
||||
$this->_writeValue($value[1]);
|
||||
$this->_out('stream');
|
||||
$this->_out($value[2][1]);
|
||||
$this->_straightOut("endstream");
|
||||
break;
|
||||
|
||||
case pdf_parser::TYPE_HEX:
|
||||
$this->_straightOut('<' . $value[1] . '>');
|
||||
break;
|
||||
|
||||
case pdf_parser::TYPE_BOOLEAN:
|
||||
$this->_straightOut($value[1] ? 'true ' : 'false ');
|
||||
break;
|
||||
|
||||
case pdf_parser::TYPE_NULL:
|
||||
// The null object.
|
||||
|
||||
$this->_straightOut('null ');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Modified _out() method so not each call will add a newline to the output.
|
||||
*/
|
||||
protected function _straightOut($s)
|
||||
{
|
||||
if (!is_subclass_of($this, 'TCPDF')) {
|
||||
if ($this->state == 2) {
|
||||
$this->pages[$this->page] .= $s;
|
||||
} else {
|
||||
$this->buffer .= $s;
|
||||
}
|
||||
|
||||
} else {
|
||||
if ($this->state == 2) {
|
||||
if ($this->inxobj) {
|
||||
// we are inside an XObject template
|
||||
$this->xobjects[$this->xobjid]['outdata'] .= $s;
|
||||
} else if ((!$this->InFooter) AND isset($this->footerlen[$this->page]) AND ($this->footerlen[$this->page] > 0)) {
|
||||
// puts data before page footer
|
||||
$pagebuff = $this->getPageBuffer($this->page);
|
||||
$page = substr($pagebuff, 0, -$this->footerlen[$this->page]);
|
||||
$footer = substr($pagebuff, -$this->footerlen[$this->page]);
|
||||
$this->setPageBuffer($this->page, $page . $s . $footer);
|
||||
// update footer position
|
||||
$this->footerpos[$this->page] += strlen($s);
|
||||
} else {
|
||||
// set page data
|
||||
$this->setPageBuffer($this->page, $s, true);
|
||||
}
|
||||
} else if ($this->state > 0) {
|
||||
// set general data
|
||||
$this->setBuffer($s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ends the document
|
||||
*
|
||||
* Overwritten to close opened parsers
|
||||
*/
|
||||
public function _enddoc()
|
||||
{
|
||||
parent::_enddoc();
|
||||
$this->_closeParsers();
|
||||
}
|
||||
|
||||
/**
|
||||
* Close all files opened by parsers.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
protected function _closeParsers()
|
||||
{
|
||||
if ($this->state > 2) {
|
||||
$this->cleanUp();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes cycled references and closes the file handles of the parser objects.
|
||||
*/
|
||||
public function cleanUp()
|
||||
{
|
||||
while (($parser = array_pop($this->parsers)) !== null) {
|
||||
/**
|
||||
* @var fpdi_pdf_parser $parser
|
||||
*/
|
||||
$parser->closeFile();
|
||||
}
|
||||
}
|
||||
}
|
||||
215
sites/all/modules/civicrm/packages/FPDI/fpdi_bridge.php
Normal file
215
sites/all/modules/civicrm/packages/FPDI/fpdi_bridge.php
Normal file
|
|
@ -0,0 +1,215 @@
|
|||
<?php
|
||||
//
|
||||
// FPDI - Version 1.5
|
||||
//
|
||||
// Copyright 2004-2014 Setasign - Jan Slabon
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
/**
|
||||
* This file is used as a bridge between TCPDF or FPDF
|
||||
* It will dynamically create the class extending the available
|
||||
* class FPDF or TCPDF.
|
||||
*
|
||||
* This way it is possible to use FPDI for both FPDF and TCPDF with one FPDI version.
|
||||
*/
|
||||
|
||||
if (!class_exists('TCPDF', false)) {
|
||||
/**
|
||||
* Class fpdi_bridge
|
||||
*/
|
||||
class fpdi_bridge extends FPDF
|
||||
{
|
||||
// empty body
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
/**
|
||||
* Class fpdi_bridge
|
||||
*/
|
||||
class fpdi_bridge extends TCPDF
|
||||
{
|
||||
/**
|
||||
* Array of Tpl-Data
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_tpls = array();
|
||||
|
||||
/**
|
||||
* Name-prefix of Templates used in Resources-Dictionary
|
||||
*
|
||||
* @var string A String defining the Prefix used as Template-Object-Names. Have to begin with an /
|
||||
*/
|
||||
public $tplPrefix = "/TPL";
|
||||
|
||||
/**
|
||||
* Current Object Id.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $_currentObjId;
|
||||
|
||||
/**
|
||||
* Return XObjects Dictionary.
|
||||
*
|
||||
* Overwritten to add additional XObjects to the resources dictionary of TCPDF
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _getxobjectdict()
|
||||
{
|
||||
$out = parent::_getxobjectdict();
|
||||
foreach ($this->_tpls as $tplIdx => $tpl) {
|
||||
$out .= sprintf('%s%d %d 0 R', $this->tplPrefix, $tplIdx, $tpl['n']);
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a PDF value to the resulting document.
|
||||
*
|
||||
* Prepares the value for encryption of imported data by FPDI
|
||||
*
|
||||
* @param array $value
|
||||
*/
|
||||
protected function _prepareValue(&$value)
|
||||
{
|
||||
switch ($value[0]) {
|
||||
case pdf_parser::TYPE_STRING:
|
||||
if ($this->encrypted) {
|
||||
$value[1] = $this->_unescape($value[1]);
|
||||
$value[1] = $this->_encrypt_data($this->_currentObjId, $value[1]);
|
||||
$value[1] = TCPDF_STATIC::_escape($value[1]);
|
||||
}
|
||||
break;
|
||||
|
||||
case pdf_parser::TYPE_STREAM:
|
||||
if ($this->encrypted) {
|
||||
$value[2][1] = $this->_encrypt_data($this->_currentObjId, $value[2][1]);
|
||||
$value[1][1]['/Length'] = array(
|
||||
pdf_parser::TYPE_NUMERIC,
|
||||
strlen($value[2][1])
|
||||
);
|
||||
}
|
||||
break;
|
||||
|
||||
case pdf_parser::TYPE_HEX:
|
||||
if ($this->encrypted) {
|
||||
$value[1] = $this->hex2str($value[1]);
|
||||
$value[1] = $this->_encrypt_data($this->_currentObjId, $value[1]);
|
||||
|
||||
// remake hexstring of encrypted string
|
||||
$value[1] = $this->str2hex($value[1]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Un-escapes a PDF string
|
||||
*
|
||||
* @param string $s
|
||||
* @return string
|
||||
*/
|
||||
protected function _unescape($s)
|
||||
{
|
||||
$out = '';
|
||||
for ($count = 0, $n = strlen($s); $count < $n; $count++) {
|
||||
if ($s[$count] != '\\' || $count == $n-1) {
|
||||
$out .= $s[$count];
|
||||
} else {
|
||||
switch ($s[++$count]) {
|
||||
case ')':
|
||||
case '(':
|
||||
case '\\':
|
||||
$out .= $s[$count];
|
||||
break;
|
||||
case 'f':
|
||||
$out .= chr(0x0C);
|
||||
break;
|
||||
case 'b':
|
||||
$out .= chr(0x08);
|
||||
break;
|
||||
case 't':
|
||||
$out .= chr(0x09);
|
||||
break;
|
||||
case 'r':
|
||||
$out .= chr(0x0D);
|
||||
break;
|
||||
case 'n':
|
||||
$out .= chr(0x0A);
|
||||
break;
|
||||
case "\r":
|
||||
if ($count != $n-1 && $s[$count+1] == "\n")
|
||||
$count++;
|
||||
break;
|
||||
case "\n":
|
||||
break;
|
||||
default:
|
||||
// Octal-Values
|
||||
if (ord($s[$count]) >= ord('0') &&
|
||||
ord($s[$count]) <= ord('9')) {
|
||||
$oct = ''. $s[$count];
|
||||
|
||||
if (ord($s[$count+1]) >= ord('0') &&
|
||||
ord($s[$count+1]) <= ord('9')) {
|
||||
$oct .= $s[++$count];
|
||||
|
||||
if (ord($s[$count+1]) >= ord('0') &&
|
||||
ord($s[$count+1]) <= ord('9')) {
|
||||
$oct .= $s[++$count];
|
||||
}
|
||||
}
|
||||
|
||||
$out .= chr(octdec($oct));
|
||||
} else {
|
||||
$out .= $s[$count];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hexadecimal to string
|
||||
*
|
||||
* @param string $data
|
||||
* @return string
|
||||
*/
|
||||
public function hex2str($data)
|
||||
{
|
||||
$data = preg_replace('/[^0-9A-Fa-f]/', '', rtrim($data, '>'));
|
||||
if ((strlen($data) % 2) == 1) {
|
||||
$data .= '0';
|
||||
}
|
||||
|
||||
return pack('H*', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* String to hexadecimal
|
||||
*
|
||||
* @param string $str
|
||||
* @return string
|
||||
*/
|
||||
public function str2hex($str)
|
||||
{
|
||||
return current(unpack('H*', $str));
|
||||
}
|
||||
}
|
||||
}
|
||||
354
sites/all/modules/civicrm/packages/FPDI/fpdi_pdf_parser.php
Normal file
354
sites/all/modules/civicrm/packages/FPDI/fpdi_pdf_parser.php
Normal file
|
|
@ -0,0 +1,354 @@
|
|||
<?php
|
||||
//
|
||||
// FPDI - Version 1.5
|
||||
//
|
||||
// Copyright 2004-2014 Setasign - Jan Slabon
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
require_once('pdf_parser.php');
|
||||
|
||||
/**
|
||||
* Class fpdi_pdf_parser
|
||||
*/
|
||||
class fpdi_pdf_parser extends pdf_parser
|
||||
{
|
||||
/**
|
||||
* Pages
|
||||
*
|
||||
* Index begins at 0
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_pages;
|
||||
|
||||
/**
|
||||
* Page count
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $_pageCount;
|
||||
|
||||
/**
|
||||
* Current page number
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
public $pageNo;
|
||||
|
||||
/**
|
||||
* PDF version of imported document
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $_pdfVersion;
|
||||
|
||||
/**
|
||||
* Available BoxTypes
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $availableBoxes = array('/MediaBox', '/CropBox', '/BleedBox', '/TrimBox', '/ArtBox');
|
||||
|
||||
/**
|
||||
* The constructor.
|
||||
*
|
||||
* @param string $filename The source filename
|
||||
*/
|
||||
public function __construct($filename)
|
||||
{
|
||||
parent::__construct($filename);
|
||||
|
||||
// resolve Pages-Dictonary
|
||||
$pages = $this->resolveObject($this->_root[1][1]['/Pages']);
|
||||
|
||||
// Read pages
|
||||
$this->_readPages($pages, $this->_pages);
|
||||
|
||||
// count pages;
|
||||
$this->_pageCount = count($this->_pages);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get page count from source file.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getPageCount()
|
||||
{
|
||||
return $this->_pageCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the page number.
|
||||
*
|
||||
* @param int $pageNo Page number to use
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function setPageNo($pageNo)
|
||||
{
|
||||
$pageNo = ((int) $pageNo) - 1;
|
||||
|
||||
if ($pageNo < 0 || $pageNo >= $this->getPageCount()) {
|
||||
throw new InvalidArgumentException('Invalid page number!');
|
||||
}
|
||||
|
||||
$this->pageNo = $pageNo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get page-resources from current page
|
||||
*
|
||||
* @return array|boolean
|
||||
*/
|
||||
public function getPageResources()
|
||||
{
|
||||
return $this->_getPageResources($this->_pages[$this->pageNo]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get page-resources from a /Page dictionary.
|
||||
*
|
||||
* @param array $obj Array of pdf-data
|
||||
* @return array|boolean
|
||||
*/
|
||||
protected function _getPageResources($obj)
|
||||
{
|
||||
$obj = $this->resolveObject($obj);
|
||||
|
||||
// If the current object has a resources
|
||||
// dictionary associated with it, we use
|
||||
// it. Otherwise, we move back to its
|
||||
// parent object.
|
||||
if (isset($obj[1][1]['/Resources'])) {
|
||||
$res = $this->resolveObject($obj[1][1]['/Resources']);
|
||||
if ($res[0] == pdf_parser::TYPE_OBJECT)
|
||||
return $res[1];
|
||||
return $res;
|
||||
}
|
||||
|
||||
if (!isset($obj[1][1]['/Parent'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$res = $this->_getPageResources($obj[1][1]['/Parent']);
|
||||
if ($res[0] == pdf_parser::TYPE_OBJECT)
|
||||
return $res[1];
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get content of current page.
|
||||
*
|
||||
* If /Contents is an array, the streams are concatenated
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getContent()
|
||||
{
|
||||
$buffer = '';
|
||||
|
||||
if (isset($this->_pages[$this->pageNo][1][1]['/Contents'])) {
|
||||
$contents = $this->_getPageContent($this->_pages[$this->pageNo][1][1]['/Contents']);
|
||||
foreach ($contents AS $tmpContent) {
|
||||
$buffer .= $this->_unFilterStream($tmpContent) . ' ';
|
||||
}
|
||||
}
|
||||
|
||||
return $buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve all content objects.
|
||||
*
|
||||
* @param array $contentRef
|
||||
* @return array
|
||||
*/
|
||||
protected function _getPageContent($contentRef)
|
||||
{
|
||||
$contents = array();
|
||||
|
||||
if ($contentRef[0] == pdf_parser::TYPE_OBJREF) {
|
||||
$content = $this->resolveObject($contentRef);
|
||||
if ($content[1][0] == pdf_parser::TYPE_ARRAY) {
|
||||
$contents = $this->_getPageContent($content[1]);
|
||||
} else {
|
||||
$contents[] = $content;
|
||||
}
|
||||
} else if ($contentRef[0] == pdf_parser::TYPE_ARRAY) {
|
||||
foreach ($contentRef[1] AS $tmp_content_ref) {
|
||||
$contents = array_merge($contents, $this->_getPageContent($tmp_content_ref));
|
||||
}
|
||||
}
|
||||
|
||||
return $contents;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a boundary box from a page
|
||||
*
|
||||
* Array format is same as used by FPDF_TPL.
|
||||
*
|
||||
* @param array $page a /Page dictionary
|
||||
* @param string $boxIndex Type of box {see {@link $availableBoxes})
|
||||
* @param float Scale factor from user space units to points
|
||||
*
|
||||
* @return array|boolean
|
||||
*/
|
||||
protected function _getPageBox($page, $boxIndex, $k)
|
||||
{
|
||||
$page = $this->resolveObject($page);
|
||||
$box = null;
|
||||
if (isset($page[1][1][$boxIndex])) {
|
||||
$box = $page[1][1][$boxIndex];
|
||||
}
|
||||
|
||||
if (!is_null($box) && $box[0] == pdf_parser::TYPE_OBJREF) {
|
||||
$tmp_box = $this->resolveObject($box);
|
||||
$box = $tmp_box[1];
|
||||
}
|
||||
|
||||
if (!is_null($box) && $box[0] == pdf_parser::TYPE_ARRAY) {
|
||||
$b = $box[1];
|
||||
return array(
|
||||
'x' => $b[0][1] / $k,
|
||||
'y' => $b[1][1] / $k,
|
||||
'w' => abs($b[0][1] - $b[2][1]) / $k,
|
||||
'h' => abs($b[1][1] - $b[3][1]) / $k,
|
||||
'llx' => min($b[0][1], $b[2][1]) / $k,
|
||||
'lly' => min($b[1][1], $b[3][1]) / $k,
|
||||
'urx' => max($b[0][1], $b[2][1]) / $k,
|
||||
'ury' => max($b[1][1], $b[3][1]) / $k,
|
||||
);
|
||||
} else if (!isset($page[1][1]['/Parent'])) {
|
||||
return false;
|
||||
} else {
|
||||
return $this->_getPageBox($this->resolveObject($page[1][1]['/Parent']), $boxIndex, $k);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all page boundary boxes by page number
|
||||
*
|
||||
* @param int $pageNo The page number
|
||||
* @param float $k Scale factor from user space units to points
|
||||
* @return array
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function getPageBoxes($pageNo, $k)
|
||||
{
|
||||
if (!isset($this->_pages[$pageNo - 1])) {
|
||||
throw new InvalidArgumentException('Page ' . $pageNo . ' does not exists.');
|
||||
}
|
||||
|
||||
return $this->_getPageBoxes($this->_pages[$pageNo - 1], $k);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all boxes from /Page dictionary
|
||||
*
|
||||
* @param array $page A /Page dictionary
|
||||
* @param float $k Scale factor from user space units to points
|
||||
* @return array
|
||||
*/
|
||||
protected function _getPageBoxes($page, $k)
|
||||
{
|
||||
$boxes = array();
|
||||
|
||||
foreach($this->availableBoxes AS $box) {
|
||||
if ($_box = $this->_getPageBox($page, $box, $k)) {
|
||||
$boxes[$box] = $_box;
|
||||
}
|
||||
}
|
||||
|
||||
return $boxes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the page rotation by page number
|
||||
*
|
||||
* @param integer $pageNo
|
||||
* @throws InvalidArgumentException
|
||||
* @return array
|
||||
*/
|
||||
public function getPageRotation($pageNo)
|
||||
{
|
||||
if (!isset($this->_pages[$pageNo - 1])) {
|
||||
throw new InvalidArgumentException('Page ' . $pageNo . ' does not exists.');
|
||||
}
|
||||
|
||||
return $this->_getPageRotation($this->_pages[$pageNo - 1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the rotation value of a page
|
||||
*
|
||||
* @param array $obj A /Page dictionary
|
||||
* @return array|bool
|
||||
*/
|
||||
protected function _getPageRotation($obj)
|
||||
{
|
||||
$obj = $this->resolveObject($obj);
|
||||
if (isset($obj[1][1]['/Rotate'])) {
|
||||
$res = $this->resolveObject($obj[1][1]['/Rotate']);
|
||||
if ($res[0] == pdf_parser::TYPE_OBJECT)
|
||||
return $res[1];
|
||||
return $res;
|
||||
}
|
||||
|
||||
if (!isset($obj[1][1]['/Parent'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$res = $this->_getPageRotation($obj[1][1]['/Parent']);
|
||||
if ($res[0] == pdf_parser::TYPE_OBJECT)
|
||||
return $res[1];
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read all pages
|
||||
*
|
||||
* @param array $pages /Pages dictionary
|
||||
* @param array $result The result array
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function _readPages(&$pages, &$result)
|
||||
{
|
||||
// Get the kids dictionary
|
||||
$_kids = $this->resolveObject($pages[1][1]['/Kids']);
|
||||
|
||||
if (!is_array($_kids)) {
|
||||
throw new Exception('Cannot find /Kids in current /Page-Dictionary');
|
||||
}
|
||||
|
||||
if ($_kids[0] === self::TYPE_OBJECT) {
|
||||
$_kids = $_kids[1];
|
||||
}
|
||||
|
||||
$kids = $_kids[1];
|
||||
|
||||
foreach ($kids as $v) {
|
||||
$pg = $this->resolveObject($v);
|
||||
if ($pg[1][1]['/Type'][1] === '/Pages') {
|
||||
// If one of the kids is an embedded
|
||||
// /Pages array, resolve it as well.
|
||||
$this->_readPages($pg, $result);
|
||||
} else {
|
||||
$result[] = $pg;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
153
sites/all/modules/civicrm/packages/FPDI/pdf_context.php
Normal file
153
sites/all/modules/civicrm/packages/FPDI/pdf_context.php
Normal file
|
|
@ -0,0 +1,153 @@
|
|||
<?php
|
||||
//
|
||||
// FPDI - Version 1.5
|
||||
//
|
||||
// Copyright 2004-2014 Setasign - Jan Slabon
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
/**
|
||||
* Class pdf_context
|
||||
*/
|
||||
class pdf_context
|
||||
{
|
||||
/**
|
||||
* Mode
|
||||
*
|
||||
* @var integer 0 = file | 1 = string
|
||||
*/
|
||||
protected $_mode = 0;
|
||||
|
||||
/**
|
||||
* @var resource|string
|
||||
*/
|
||||
public $file;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $buffer;
|
||||
|
||||
/**
|
||||
* @var integer
|
||||
*/
|
||||
public $offset;
|
||||
|
||||
/**
|
||||
* @var integer
|
||||
*/
|
||||
public $length;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public $stack;
|
||||
|
||||
/**
|
||||
* The constructor
|
||||
*
|
||||
* @param resource $f
|
||||
*/
|
||||
public function __construct(&$f)
|
||||
{
|
||||
$this->file =& $f;
|
||||
if (is_string($this->file))
|
||||
$this->_mode = 1;
|
||||
|
||||
$this->reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the position in the file stream
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getPos()
|
||||
{
|
||||
if ($this->_mode == 0) {
|
||||
return ftell($this->file);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the position in the file stream.
|
||||
*
|
||||
* Optionally move the file pointer to a new location and reset the buffered data.
|
||||
*
|
||||
* @param null $pos
|
||||
* @param int $l
|
||||
*/
|
||||
public function reset($pos = null, $l = 100)
|
||||
{
|
||||
if ($this->_mode == 0) {
|
||||
if (!is_null($pos)) {
|
||||
fseek ($this->file, $pos);
|
||||
}
|
||||
|
||||
$this->buffer = $l > 0 ? fread($this->file, $l) : '';
|
||||
$this->length = strlen($this->buffer);
|
||||
if ($this->length < $l)
|
||||
$this->increaseLength($l - $this->length);
|
||||
} else {
|
||||
$this->buffer = $this->file;
|
||||
$this->length = strlen($this->buffer);
|
||||
}
|
||||
$this->offset = 0;
|
||||
$this->stack = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure that there is at least one character beyond the current offset in the buffer.
|
||||
*
|
||||
* To prevent the tokenizer from attempting to access data that does not exist.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function ensureContent()
|
||||
{
|
||||
if ($this->offset >= $this->length - 1) {
|
||||
return $this->increaseLength();
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Forcefully read more data into the buffer
|
||||
*
|
||||
* @param int $l
|
||||
* @return bool
|
||||
*/
|
||||
public function increaseLength($l = 100)
|
||||
{
|
||||
if ($this->_mode == 0 && feof($this->file)) {
|
||||
return false;
|
||||
} else if ($this->_mode == 0) {
|
||||
$totalLength = $this->length + $l;
|
||||
do {
|
||||
$toRead = $totalLength - $this->length;
|
||||
if ($toRead < 1)
|
||||
break;
|
||||
|
||||
$this->buffer .= fread($this->file, $toRead);
|
||||
} while ((($this->length = strlen($this->buffer)) != $totalLength) && !feof($this->file));
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
908
sites/all/modules/civicrm/packages/FPDI/pdf_parser.php
Normal file
908
sites/all/modules/civicrm/packages/FPDI/pdf_parser.php
Normal file
|
|
@ -0,0 +1,908 @@
|
|||
<?php
|
||||
//
|
||||
// FPDI - Version 1.5
|
||||
//
|
||||
// Copyright 2004-2014 Setasign - Jan Slabon
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
/**
|
||||
* Class pdf_parser
|
||||
*/
|
||||
class pdf_parser
|
||||
{
|
||||
/**
|
||||
* Type constant
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
const TYPE_NULL = 0;
|
||||
|
||||
/**
|
||||
* Type constant
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
const TYPE_NUMERIC = 1;
|
||||
|
||||
/**
|
||||
* Type constant
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
const TYPE_TOKEN = 2;
|
||||
|
||||
/**
|
||||
* Type constant
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
const TYPE_HEX = 3;
|
||||
|
||||
/**
|
||||
* Type constant
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
const TYPE_STRING = 4;
|
||||
|
||||
/**
|
||||
* Type constant
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
const TYPE_DICTIONARY = 5;
|
||||
|
||||
/**
|
||||
* Type constant
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
const TYPE_ARRAY = 6;
|
||||
|
||||
/**
|
||||
* Type constant
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
const TYPE_OBJDEC = 7;
|
||||
|
||||
/**
|
||||
* Type constant
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
const TYPE_OBJREF = 8;
|
||||
|
||||
/**
|
||||
* Type constant
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
const TYPE_OBJECT = 9;
|
||||
|
||||
/**
|
||||
* Type constant
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
const TYPE_STREAM = 10;
|
||||
|
||||
/**
|
||||
* Type constant
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
const TYPE_BOOLEAN = 11;
|
||||
|
||||
/**
|
||||
* Type constant
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
const TYPE_REAL = 12;
|
||||
|
||||
/**
|
||||
* Define the amount of byte in which the initial keyword of a PDF document should be searched.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
static public $searchForStartxrefLength = 5500;
|
||||
|
||||
/**
|
||||
* Filename
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $filename;
|
||||
|
||||
/**
|
||||
* File resource
|
||||
*
|
||||
* @var resource
|
||||
*/
|
||||
protected $_f;
|
||||
|
||||
/**
|
||||
* PDF Context
|
||||
*
|
||||
* @var pdf_context
|
||||
*/
|
||||
protected $_c;
|
||||
|
||||
/**
|
||||
* xref-Data
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_xref;
|
||||
|
||||
/**
|
||||
* Data of the Root object
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_root;
|
||||
|
||||
/**
|
||||
* PDF version of the loaded document
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_pdfVersion;
|
||||
|
||||
/**
|
||||
* For reading encrypted documents and xref/object streams are in use
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_readPlain = true;
|
||||
|
||||
/**
|
||||
* The current read object
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_currentObj;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $filename Source filename
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function __construct($filename)
|
||||
{
|
||||
$this->filename = $filename;
|
||||
|
||||
$this->_f = @fopen($this->filename, 'rb');
|
||||
|
||||
if (!$this->_f) {
|
||||
throw new InvalidArgumentException(sprintf('Cannot open %s !', $filename));
|
||||
}
|
||||
|
||||
$this->getPdfVersion();
|
||||
|
||||
require_once('pdf_context.php');
|
||||
$this->_c = new pdf_context($this->_f);
|
||||
|
||||
// Read xref-Data
|
||||
$this->_xref = array();
|
||||
$this->_readXref($this->_xref, $this->_findXref());
|
||||
|
||||
// Check for Encryption
|
||||
$this->getEncryption();
|
||||
|
||||
// Read root
|
||||
$this->_readRoot();
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
$this->closeFile();
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the opened file
|
||||
*/
|
||||
public function closeFile()
|
||||
{
|
||||
if (isset($this->_f) && is_resource($this->_f)) {
|
||||
fclose($this->_f);
|
||||
unset($this->_f);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check Trailer for Encryption
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getEncryption()
|
||||
{
|
||||
if (isset($this->_xref['trailer'][1]['/Encrypt'])) {
|
||||
throw new Exception('File is encrypted!');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get PDF-Version
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPdfVersion()
|
||||
{
|
||||
if ($this->_pdfVersion === null) {
|
||||
fseek($this->_f, 0);
|
||||
preg_match('/\d\.\d/', fread($this->_f, 16), $m);
|
||||
if (isset($m[0]))
|
||||
$this->_pdfVersion = $m[0];
|
||||
}
|
||||
|
||||
return $this->_pdfVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the /Root dictionary
|
||||
*/
|
||||
protected function _readRoot()
|
||||
{
|
||||
if ($this->_xref['trailer'][1]['/Root'][0] != self::TYPE_OBJREF) {
|
||||
throw new Exception('Wrong Type of Root-Element! Must be an indirect reference');
|
||||
}
|
||||
|
||||
$this->_root = $this->resolveObject($this->_xref['trailer'][1]['/Root']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the xref table
|
||||
*
|
||||
* @return integer
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function _findXref()
|
||||
{
|
||||
$toRead = self::$searchForStartxrefLength;
|
||||
|
||||
$stat = fseek($this->_f, -$toRead, SEEK_END);
|
||||
if ($stat === -1) {
|
||||
fseek($this->_f, 0);
|
||||
}
|
||||
|
||||
$data = fread($this->_f, $toRead);
|
||||
|
||||
$keywordPos = strpos(strrev($data), strrev('startxref'));
|
||||
if (false === $keywordPos) {
|
||||
$keywordPos = strpos(strrev($data), strrev('startref'));
|
||||
}
|
||||
|
||||
if (false === $keywordPos) {
|
||||
throw new Exception('Unable to find "startxref" keyword.');
|
||||
}
|
||||
|
||||
$pos = strlen($data) - $keywordPos;
|
||||
$data = substr($data, $pos);
|
||||
|
||||
if (!preg_match('/\s*(\d+).*$/s', $data, $matches)) {
|
||||
throw new Exception('Unable to find pointer to xref table.');
|
||||
}
|
||||
|
||||
return (int) $matches[1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the xref table
|
||||
*
|
||||
* @param array $result Array of xref table entries
|
||||
* @param integer $offset of xref table
|
||||
* @return boolean
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function _readXref(&$result, $offset)
|
||||
{
|
||||
$tempPos = $offset - min(20, $offset);
|
||||
fseek($this->_f, $tempPos); // set some bytes backwards to fetch corrupted docs
|
||||
|
||||
$data = fread($this->_f, 100);
|
||||
|
||||
$xrefPos = strrpos($data, 'xref');
|
||||
|
||||
if ($xrefPos === false) {
|
||||
$this->_c->reset($offset);
|
||||
$xrefStreamObjDec = $this->_readValue($this->_c);
|
||||
|
||||
if (is_array($xrefStreamObjDec) && isset($xrefStreamObjDec[0]) && $xrefStreamObjDec[0] == self::TYPE_OBJDEC) {
|
||||
throw new Exception(
|
||||
sprintf(
|
||||
'This document (%s) probably uses a compression technique which is not supported by the ' .
|
||||
'free parser shipped with FPDI. (See https://www.setasign.com/fpdi-pdf-parser for more details)',
|
||||
$this->filename
|
||||
)
|
||||
);
|
||||
} else {
|
||||
throw new Exception('Unable to find xref table.');
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($result['xrefLocation'])) {
|
||||
$result['xrefLocation'] = $tempPos + $xrefPos;
|
||||
$result['maxObject'] = 0;
|
||||
}
|
||||
|
||||
$cycles = -1;
|
||||
$bytesPerCycle = 100;
|
||||
|
||||
fseek($this->_f, $tempPos = $tempPos + $xrefPos + 4); // set the handle directly after the "xref"-keyword
|
||||
$data = fread($this->_f, $bytesPerCycle);
|
||||
|
||||
while (($trailerPos = strpos($data, 'trailer', max($bytesPerCycle * $cycles++, 0))) === false && !feof($this->_f)) {
|
||||
$data .= fread($this->_f, $bytesPerCycle);
|
||||
}
|
||||
|
||||
if ($trailerPos === false) {
|
||||
throw new Exception('Trailer keyword not found after xref table');
|
||||
}
|
||||
|
||||
$data = ltrim(substr($data, 0, $trailerPos));
|
||||
|
||||
// get Line-Ending
|
||||
preg_match_all("/(\r\n|\n|\r)/", substr($data, 0, 100), $m); // check the first 100 bytes for line breaks
|
||||
|
||||
$differentLineEndings = count(array_unique($m[0]));
|
||||
if ($differentLineEndings > 1) {
|
||||
$lines = preg_split("/(\r\n|\n|\r)/", $data, -1, PREG_SPLIT_NO_EMPTY);
|
||||
} else {
|
||||
$lines = explode($m[0][0], $data);
|
||||
}
|
||||
|
||||
$data = $differentLineEndings = $m = null;
|
||||
unset($data, $differentLineEndings, $m);
|
||||
|
||||
$linesCount = count($lines);
|
||||
|
||||
$start = 1;
|
||||
|
||||
for ($i = 0; $i < $linesCount; $i++) {
|
||||
$line = trim($lines[$i]);
|
||||
if ($line) {
|
||||
$pieces = explode(' ', $line);
|
||||
$c = count($pieces);
|
||||
switch($c) {
|
||||
case 2:
|
||||
$start = (int)$pieces[0];
|
||||
$end = $start + (int)$pieces[1];
|
||||
if ($end > $result['maxObject'])
|
||||
$result['maxObject'] = $end;
|
||||
break;
|
||||
case 3:
|
||||
if (!isset($result['xref'][$start]))
|
||||
$result['xref'][$start] = array();
|
||||
|
||||
if (!array_key_exists($gen = (int) $pieces[1], $result['xref'][$start])) {
|
||||
$result['xref'][$start][$gen] = $pieces[2] == 'n' ? (int) $pieces[0] : null;
|
||||
}
|
||||
$start++;
|
||||
break;
|
||||
default:
|
||||
throw new Exception('Unexpected data in xref table');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$lines = $pieces = $line = $start = $end = $gen = null;
|
||||
unset($lines, $pieces, $line, $start, $end, $gen);
|
||||
|
||||
$this->_c->reset($tempPos + $trailerPos + 7);
|
||||
$trailer = $this->_readValue($this->_c);
|
||||
|
||||
if (!isset($result['trailer'])) {
|
||||
$result['trailer'] = $trailer;
|
||||
}
|
||||
|
||||
if (isset($trailer[1]['/Prev'])) {
|
||||
$this->_readXref($result, $trailer[1]['/Prev'][1]);
|
||||
}
|
||||
|
||||
$trailer = null;
|
||||
unset($trailer);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a PDF value
|
||||
*
|
||||
* @param pdf_context $c
|
||||
* @param string $token A token
|
||||
* @return mixed
|
||||
*/
|
||||
protected function _readValue(&$c, $token = null)
|
||||
{
|
||||
if (is_null($token)) {
|
||||
$token = $this->_readToken($c);
|
||||
}
|
||||
|
||||
if ($token === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch ($token) {
|
||||
case '<':
|
||||
// This is a hex string.
|
||||
// Read the value, then the terminator
|
||||
|
||||
$pos = $c->offset;
|
||||
|
||||
while(1) {
|
||||
|
||||
$match = strpos ($c->buffer, '>', $pos);
|
||||
|
||||
// If you can't find it, try
|
||||
// reading more data from the stream
|
||||
|
||||
if ($match === false) {
|
||||
if (!$c->increaseLength()) {
|
||||
return false;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$result = substr ($c->buffer, $c->offset, $match - $c->offset);
|
||||
$c->offset = $match + 1;
|
||||
|
||||
return array (self::TYPE_HEX, $result);
|
||||
}
|
||||
break;
|
||||
|
||||
case '<<':
|
||||
// This is a dictionary.
|
||||
|
||||
$result = array();
|
||||
|
||||
// Recurse into this function until we reach
|
||||
// the end of the dictionary.
|
||||
while (($key = $this->_readToken($c)) !== '>>') {
|
||||
if ($key === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (($value = $this->_readValue($c)) === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Catch missing value
|
||||
if ($value[0] == self::TYPE_TOKEN && $value[1] == '>>') {
|
||||
$result[$key] = array(self::TYPE_NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
$result[$key] = $value;
|
||||
}
|
||||
|
||||
return array (self::TYPE_DICTIONARY, $result);
|
||||
|
||||
case '[':
|
||||
// This is an array.
|
||||
|
||||
$result = array();
|
||||
|
||||
// Recurse into this function until we reach
|
||||
// the end of the array.
|
||||
while (($token = $this->_readToken($c)) !== ']') {
|
||||
if ($token === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (($value = $this->_readValue($c, $token)) === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$result[] = $value;
|
||||
}
|
||||
|
||||
return array (self::TYPE_ARRAY, $result);
|
||||
|
||||
case '(':
|
||||
// This is a string
|
||||
$pos = $c->offset;
|
||||
|
||||
$openBrackets = 1;
|
||||
do {
|
||||
for (; $openBrackets != 0 && $pos < $c->length; $pos++) {
|
||||
switch (ord($c->buffer[$pos])) {
|
||||
case 0x28: // '('
|
||||
$openBrackets++;
|
||||
break;
|
||||
case 0x29: // ')'
|
||||
$openBrackets--;
|
||||
break;
|
||||
case 0x5C: // backslash
|
||||
$pos++;
|
||||
}
|
||||
}
|
||||
} while($openBrackets != 0 && $c->increaseLength());
|
||||
|
||||
$result = substr($c->buffer, $c->offset, $pos - $c->offset - 1);
|
||||
$c->offset = $pos;
|
||||
|
||||
return array (self::TYPE_STRING, $result);
|
||||
|
||||
case 'stream':
|
||||
$tempPos = $c->getPos() - strlen($c->buffer);
|
||||
$tempOffset = $c->offset;
|
||||
|
||||
$c->reset($startPos = $tempPos + $tempOffset);
|
||||
|
||||
$e = 0; // ensure line breaks in front of the stream
|
||||
if ($c->buffer[0] == chr(10) || $c->buffer[0] == chr(13))
|
||||
$e++;
|
||||
if ($c->buffer[1] == chr(10) && $c->buffer[0] != chr(10))
|
||||
$e++;
|
||||
|
||||
if ($this->_currentObj[1][1]['/Length'][0] == self::TYPE_OBJREF) {
|
||||
$tmpLength = $this->resolveObject($this->_currentObj[1][1]['/Length']);
|
||||
$length = $tmpLength[1][1];
|
||||
} else {
|
||||
$length = $this->_currentObj[1][1]['/Length'][1];
|
||||
}
|
||||
|
||||
if ($length > 0) {
|
||||
$c->reset($startPos + $e, $length);
|
||||
$v = $c->buffer;
|
||||
} else {
|
||||
$v = '';
|
||||
}
|
||||
|
||||
$c->reset($startPos + $e + $length);
|
||||
$endstream = $this->_readToken($c);
|
||||
|
||||
if ($endstream != 'endstream') {
|
||||
$c->reset($startPos + $e + $length + 9); // 9 = strlen("endstream")
|
||||
// We don't throw an error here because the next
|
||||
// round trip will start at a new offset
|
||||
}
|
||||
|
||||
return array(self::TYPE_STREAM, $v);
|
||||
|
||||
default :
|
||||
if (is_numeric($token)) {
|
||||
// A numeric token. Make sure that
|
||||
// it is not part of something else.
|
||||
if (($tok2 = $this->_readToken($c)) !== false) {
|
||||
if (is_numeric($tok2)) {
|
||||
|
||||
// Two numeric tokens in a row.
|
||||
// In this case, we're probably in
|
||||
// front of either an object reference
|
||||
// or an object specification.
|
||||
// Determine the case and return the data
|
||||
if (($tok3 = $this->_readToken($c)) !== false) {
|
||||
switch ($tok3) {
|
||||
case 'obj':
|
||||
return array(self::TYPE_OBJDEC, (int)$token, (int)$tok2);
|
||||
case 'R':
|
||||
return array(self::TYPE_OBJREF, (int)$token, (int)$tok2);
|
||||
}
|
||||
// If we get to this point, that numeric value up
|
||||
// there was just a numeric value. Push the extra
|
||||
// tokens back into the stack and return the value.
|
||||
array_push($c->stack, $tok3);
|
||||
}
|
||||
}
|
||||
|
||||
array_push($c->stack, $tok2);
|
||||
}
|
||||
|
||||
if ($token === (string)((int)$token))
|
||||
return array(self::TYPE_NUMERIC, (int)$token);
|
||||
else
|
||||
return array(self::TYPE_REAL, (float)$token);
|
||||
} else if ($token == 'true' || $token == 'false') {
|
||||
return array(self::TYPE_BOOLEAN, $token == 'true');
|
||||
} else if ($token == 'null') {
|
||||
return array(self::TYPE_NULL);
|
||||
} else {
|
||||
// Just a token. Return it.
|
||||
return array(self::TYPE_TOKEN, $token);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve an object
|
||||
*
|
||||
* @param array $objSpec The object-data
|
||||
* @return array|boolean
|
||||
* @throws Exception
|
||||
*/
|
||||
public function resolveObject($objSpec)
|
||||
{
|
||||
$c = $this->_c;
|
||||
|
||||
// Exit if we get invalid data
|
||||
if (!is_array($objSpec)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($objSpec[0] == self::TYPE_OBJREF) {
|
||||
|
||||
// This is a reference, resolve it
|
||||
if (isset($this->_xref['xref'][$objSpec[1]][$objSpec[2]])) {
|
||||
|
||||
// Save current file position
|
||||
// This is needed if you want to resolve
|
||||
// references while you're reading another object
|
||||
// (e.g.: if you need to determine the length
|
||||
// of a stream)
|
||||
|
||||
$oldPos = $c->getPos();
|
||||
|
||||
// Reposition the file pointer and
|
||||
// load the object header.
|
||||
|
||||
$c->reset($this->_xref['xref'][$objSpec[1]][$objSpec[2]]);
|
||||
|
||||
$header = $this->_readValue($c);
|
||||
|
||||
if ($header[0] != self::TYPE_OBJDEC || $header[1] != $objSpec[1] || $header[2] != $objSpec[2]) {
|
||||
$toSearchFor = $objSpec[1] . ' ' . $objSpec[2] . ' obj';
|
||||
if (preg_match('/' . $toSearchFor . '/', $c->buffer)) {
|
||||
$c->offset = strpos($c->buffer, $toSearchFor) + strlen($toSearchFor);
|
||||
// reset stack
|
||||
$c->stack = array();
|
||||
} else {
|
||||
throw new Exception(
|
||||
sprintf("Unable to find object (%s, %s) at expected location.", $objSpec[1], $objSpec[2])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// If we're being asked to store all the information
|
||||
// about the object, we add the object ID and generation
|
||||
// number for later use
|
||||
$result = array (
|
||||
self::TYPE_OBJECT,
|
||||
'obj' => $objSpec[1],
|
||||
'gen' => $objSpec[2]
|
||||
);
|
||||
|
||||
$this->_currentObj =& $result;
|
||||
|
||||
// Now simply read the object data until
|
||||
// we encounter an end-of-object marker
|
||||
while (true) {
|
||||
$value = $this->_readValue($c);
|
||||
if ($value === false || count($result) > 4) {
|
||||
// in this case the parser couldn't find an "endobj" so we break here
|
||||
break;
|
||||
}
|
||||
|
||||
if ($value[0] == self::TYPE_TOKEN && $value[1] === 'endobj') {
|
||||
break;
|
||||
}
|
||||
|
||||
$result[] = $value;
|
||||
}
|
||||
|
||||
$c->reset($oldPos);
|
||||
|
||||
if (isset($result[2][0]) && $result[2][0] == self::TYPE_STREAM) {
|
||||
$result[0] = self::TYPE_STREAM;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
} else {
|
||||
return $objSpec;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a token from the context
|
||||
*
|
||||
* @param pdf_context $c
|
||||
* @return mixed
|
||||
*/
|
||||
protected function _readToken($c)
|
||||
{
|
||||
// If there is a token available
|
||||
// on the stack, pop it out and
|
||||
// return it.
|
||||
|
||||
if (count($c->stack)) {
|
||||
return array_pop($c->stack);
|
||||
}
|
||||
|
||||
// Strip away any whitespace
|
||||
|
||||
do {
|
||||
if (!$c->ensureContent()) {
|
||||
return false;
|
||||
}
|
||||
$c->offset += strspn($c->buffer, "\x20\x0A\x0C\x0D\x09\x00", $c->offset);
|
||||
} while ($c->offset >= $c->length - 1);
|
||||
|
||||
// Get the first character in the stream
|
||||
|
||||
$char = $c->buffer[$c->offset++];
|
||||
|
||||
switch ($char) {
|
||||
|
||||
case '[':
|
||||
case ']':
|
||||
case '(':
|
||||
case ')':
|
||||
|
||||
// This is either an array or literal string
|
||||
// delimiter, Return it
|
||||
|
||||
return $char;
|
||||
|
||||
case '<':
|
||||
case '>':
|
||||
|
||||
// This could either be a hex string or
|
||||
// dictionary delimiter. Determine the
|
||||
// appropriate case and return the token
|
||||
|
||||
if ($c->buffer[$c->offset] == $char) {
|
||||
if (!$c->ensureContent()) {
|
||||
return false;
|
||||
}
|
||||
$c->offset++;
|
||||
return $char . $char;
|
||||
} else {
|
||||
return $char;
|
||||
}
|
||||
|
||||
case '%':
|
||||
|
||||
// This is a comment - jump over it!
|
||||
|
||||
$pos = $c->offset;
|
||||
while(1) {
|
||||
$match = preg_match("/(\r\n|\r|\n)/", $c->buffer, $m, PREG_OFFSET_CAPTURE, $pos);
|
||||
if ($match === 0) {
|
||||
if (!$c->increaseLength()) {
|
||||
return false;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$c->offset = $m[0][1] + strlen($m[0][0]);
|
||||
|
||||
return $this->_readToken($c);
|
||||
}
|
||||
|
||||
default:
|
||||
|
||||
// This is "another" type of token (probably
|
||||
// a dictionary entry or a numeric value)
|
||||
// Find the end and return it.
|
||||
|
||||
if (!$c->ensureContent()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
while(1) {
|
||||
|
||||
// Determine the length of the token
|
||||
|
||||
$pos = strcspn($c->buffer, "\x20%[]<>()/\x0A\x0C\x0D\x09\x00", $c->offset);
|
||||
|
||||
if ($c->offset + $pos <= $c->length - 1) {
|
||||
break;
|
||||
} else {
|
||||
// If the script reaches this point,
|
||||
// the token may span beyond the end
|
||||
// of the current buffer. Therefore,
|
||||
// we increase the size of the buffer
|
||||
// and try again--just to be safe.
|
||||
|
||||
$c->increaseLength();
|
||||
}
|
||||
}
|
||||
|
||||
$result = substr($c->buffer, $c->offset - 1, $pos + 1);
|
||||
|
||||
$c->offset += $pos;
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Un-filter a stream object
|
||||
*
|
||||
* @param array $obj
|
||||
* @return string
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function _unFilterStream($obj)
|
||||
{
|
||||
$filters = array();
|
||||
|
||||
if (isset($obj[1][1]['/Filter'])) {
|
||||
$filter = $obj[1][1]['/Filter'];
|
||||
|
||||
if ($filter[0] == pdf_parser::TYPE_OBJREF) {
|
||||
$tmpFilter = $this->resolveObject($filter);
|
||||
$filter = $tmpFilter[1];
|
||||
}
|
||||
|
||||
if ($filter[0] == pdf_parser::TYPE_TOKEN) {
|
||||
$filters[] = $filter;
|
||||
} else if ($filter[0] == pdf_parser::TYPE_ARRAY) {
|
||||
$filters = $filter[1];
|
||||
}
|
||||
}
|
||||
|
||||
$stream = $obj[2][1];
|
||||
|
||||
foreach ($filters AS $filter) {
|
||||
switch ($filter[1]) {
|
||||
case '/FlateDecode':
|
||||
case '/Fl':
|
||||
if (function_exists('gzuncompress')) {
|
||||
$oStream = $stream;
|
||||
$stream = (strlen($stream) > 0) ? @gzuncompress($stream) : '';
|
||||
} else {
|
||||
throw new Exception(
|
||||
sprintf('To handle %s filter, please compile php with zlib support.', $filter[1])
|
||||
);
|
||||
}
|
||||
|
||||
if ($stream === false) {
|
||||
$tries = 0;
|
||||
while ($tries < 8 && ($stream === false || strlen($stream) < strlen($oStream))) {
|
||||
$oStream = substr($oStream, 1);
|
||||
$stream = @gzinflate($oStream);
|
||||
$tries++;
|
||||
}
|
||||
|
||||
if ($stream === false) {
|
||||
throw new Exception('Error while decompressing stream.');
|
||||
}
|
||||
}
|
||||
break;
|
||||
case '/LZWDecode':
|
||||
require_once('filters/FilterLZW.php');
|
||||
$decoder = new FilterLZW();
|
||||
$stream = $decoder->decode($stream);
|
||||
break;
|
||||
case '/ASCII85Decode':
|
||||
require_once('filters/FilterASCII85.php');
|
||||
$decoder = new FilterASCII85();
|
||||
$stream = $decoder->decode($stream);
|
||||
break;
|
||||
case '/ASCIIHexDecode':
|
||||
require_once('filters/FilterASCIIHexDecode.php');
|
||||
$decoder = new FilterASCIIHexDecode();
|
||||
$stream = $decoder->decode($stream);
|
||||
break;
|
||||
case null:
|
||||
break;
|
||||
default:
|
||||
throw new Exception(sprintf('Unsupported Filter: %s', $filter[1]));
|
||||
}
|
||||
}
|
||||
|
||||
return $stream;
|
||||
}
|
||||
}
|
||||
703
sites/all/modules/civicrm/packages/FirstData/lphp.php
Normal file
703
sites/all/modules/civicrm/packages/FirstData/lphp.php
Normal file
|
|
@ -0,0 +1,703 @@
|
|||
<?php
|
||||
|
||||
|
||||
/* lphp.php LINKPOINT PHP MODULE */
|
||||
|
||||
/* A php interlocutor CLASS for
|
||||
LinkPoint: LINKPOINT LSGS API using
|
||||
libcurl, liblphp.so and liblpssl.so
|
||||
v3.0.005 20 Aug. 2003 smoffet */
|
||||
|
||||
|
||||
# Copyright 2003 LinkPoint International, Inc. All Rights Reserved.
|
||||
#
|
||||
# This software is the proprietary information of LinkPoint International, Inc.
|
||||
# Use is subject to license terms.
|
||||
|
||||
|
||||
### YOU REALLY DO NOT NEED TO EDIT THIS FILE! ###
|
||||
|
||||
|
||||
class lphp
|
||||
{
|
||||
var $debugging;
|
||||
|
||||
###########################################
|
||||
#
|
||||
# F U N C T I O N p r o c e s s ( )
|
||||
#
|
||||
# process a hash table or XML string
|
||||
# using LIBLPHP.SO and LIBLPSSL.SO
|
||||
#
|
||||
###########################################
|
||||
|
||||
function process( $data )
|
||||
{
|
||||
$using_xml = 0;
|
||||
$webspace = 1;
|
||||
|
||||
if ( isset( $data["webspace"] ) ) {
|
||||
if ( $data["webspace"] == "false" ) // if explicitly set to false, don't use html output
|
||||
$webspace = 0;
|
||||
}
|
||||
|
||||
if ( isset( $data["debugging"] ) || isset( $data["debug"] ) ) {
|
||||
if ( $data["debugging"] == "true" || $data["debug"] == "true" ) {
|
||||
$this->debugging = 1;
|
||||
|
||||
# print out incoming hash
|
||||
if ( $webspace ) { // use html-friendly output
|
||||
echo "at process, incoming data: <br>";
|
||||
while ( list( $key, $value ) = each( $data ) )
|
||||
echo htmlspecialchars( $key ) . " = " . htmlspecialchars( $value ) . "<BR>\n";
|
||||
} else { // don't use html output
|
||||
echo "at process, incoming data: \n";
|
||||
while ( list( $key, $value ) = each( $data ) )
|
||||
echo "$key = $value\n";
|
||||
}
|
||||
reset( $data );
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset( $data["xml"] ) ) { // if XML string is passed in, we'll use it
|
||||
$using_xml = 1;
|
||||
$xml = $data["xml"];
|
||||
} else {
|
||||
// otherwise convert incoming hash to XML string
|
||||
$xml = $this->buildXML($data);
|
||||
}
|
||||
|
||||
// then set up transaction variables
|
||||
$key = $data["keyfile"];
|
||||
$host = $data["host"];
|
||||
$port = $data[port];
|
||||
|
||||
|
||||
# FOR PERFORMANCE, Use the 'extensions' statement in your php.ini to load
|
||||
# this library at PHP startup, then comment out the next seven lines
|
||||
|
||||
// load library
|
||||
if ( !extension_loaded( 'liblphp' ) ) {
|
||||
if ( !dl( 'liblphp.so' ) ) {
|
||||
exit( "cannot load liblphp.so, bye\n" );
|
||||
}
|
||||
}
|
||||
|
||||
if ( $this->debugging ) {
|
||||
if ( $webspace )
|
||||
echo "<br>sending xml string:<br>" . htmlspecialchars($xml) . "<br><br>";
|
||||
else
|
||||
echo "\nsending xml string:\n$xml\n\n";
|
||||
}
|
||||
|
||||
// send transaction to LSGS
|
||||
$retstg = send_stg( $xml, $key, $host, $port );
|
||||
|
||||
|
||||
if ( strlen( $retstg ) < 4 )
|
||||
exit ( "cannot connect to lsgs, exiting" );
|
||||
|
||||
if ( $this->debugging ) {
|
||||
if ( $this->webspace ) // we're web space
|
||||
echo "<br>server responds:<br>" . htmlspecialchars($retstg) . "<br><br>";
|
||||
else // not html output
|
||||
echo "\nserver responds:\n $retstg\n\n";
|
||||
}
|
||||
|
||||
if ( $using_xml != 1 ) {
|
||||
// convert xml response back to hash
|
||||
$retarr = $this->decodeXML($retstg);
|
||||
|
||||
// and send it back to caller
|
||||
return ( $retarr );
|
||||
} else {
|
||||
// send server response back
|
||||
return $retstg;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#####################################################
|
||||
#
|
||||
# F U N C T I O N c u r l _ p r o c e s s ( )
|
||||
#
|
||||
# process hash table or xml string table using
|
||||
# curl, either with PHP built-in curl methods
|
||||
# or binary executable curl
|
||||
#
|
||||
#####################################################
|
||||
|
||||
function curl_process( $data )
|
||||
{
|
||||
$using_xml = 0;
|
||||
$webspace = 1;
|
||||
|
||||
if ( isset( $data["webspace"] ) ) {
|
||||
if ( $data["webspace"] == "false" ) // if explicitly set to false, don't use html output
|
||||
$webspace = 0;
|
||||
}
|
||||
|
||||
if ( isset( $data["debugging"] ) || isset( $data["debug"] ) ) {
|
||||
if ( $data["debugging"] == "true" || $data["debug"] == "true" ) {
|
||||
$this->debugging = 1;
|
||||
|
||||
# print out incoming hash
|
||||
if ( $webspace ) { // use html-friendly output
|
||||
echo "at curl_process, incoming data: <br>";
|
||||
while ( list( $key, $value ) = each( $data ) )
|
||||
echo htmlspecialchars( $key ) . " = " . htmlspecialchars( $value ) . "<BR>\n";
|
||||
} else { // don't use html output
|
||||
echo "at curl_process, incoming data: \n";
|
||||
while ( list( $key, $value ) = each( $data ) )
|
||||
echo "$key = $value\n";
|
||||
}
|
||||
reset( $data );
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset( $data["xml"] ) ) { // if XML string is passed in, we'll use it
|
||||
$using_xml = 1;
|
||||
$xml = $data["xml"];
|
||||
} else {
|
||||
// otherwise convert incoming hash to XML string
|
||||
$xml = $this->buildXML( $data );
|
||||
}
|
||||
|
||||
if ( $this->debugging ) {
|
||||
if ( $webspace )
|
||||
echo "<br>sending xml string:<br>" . htmlspecialchars( $xml ) . "<br><br>";
|
||||
else
|
||||
echo "\nsending xml string:\n$xml\n\n";
|
||||
}
|
||||
|
||||
// set up transaction variables
|
||||
$key = $data["keyfile"];
|
||||
$port = $data["port"];
|
||||
$host = $data["host"].":".$port."/LSGSXML";
|
||||
|
||||
|
||||
if ( isset($data["cbin"]) ) { //using BINARY curl methods
|
||||
if ( $data["cbin"] == "true" ) {
|
||||
if ( isset( $data["cpath"] ) )
|
||||
$cpath = $data["cpath"];
|
||||
|
||||
else { // curl path has not been set, try to find curl binary
|
||||
if ( getenv("OS") == "Windows_NT" )
|
||||
$cpath = "c:\\curl\\curl.exe";
|
||||
else
|
||||
$cpath = "/usr/bin/curl";
|
||||
}
|
||||
|
||||
// look for $cargs variable, otherwise use default curl arguments
|
||||
if ( isset($data["cargs"]) )
|
||||
$args = $data["cargs"];
|
||||
else
|
||||
$args = "-m 300 -s -S"; // default curl args; 5 min. timeout
|
||||
|
||||
|
||||
# TRANSACT #
|
||||
|
||||
if ( getenv("OS") == "Windows_NT" ) {
|
||||
if ( $this->debugging )
|
||||
$result = exec ( "$cpath -v -d \"$xml\" -E $key -k $host", $retarr, $retnum );
|
||||
else
|
||||
$result = exec ( "$cpath -d \"$xml\" -E $key -k $host", $retarr, $retnum );
|
||||
} else { //*nix string
|
||||
if ( $this->debugging )
|
||||
$result = exec ( "'$cpath' $args -v -E '$key' -d '$xml' '$host'", $retarr, $retnum );
|
||||
else
|
||||
$result = exec ( "'$cpath' $args -E '$key' -d '$xml' '$host'", $retarr, $retnum );
|
||||
}
|
||||
|
||||
# EVALUATE RESPONSE #
|
||||
|
||||
if ( strlen( $result ) < 2 ) { // no response
|
||||
$result = "<r_approved>FAILURE</r_approved><r_error>Could not connect.</r_error>";
|
||||
return $result;
|
||||
}
|
||||
|
||||
if ( $this->debugging ) {
|
||||
if ( $this->webspace )
|
||||
echo "<br>server responds:<br>" . htmlspecialchars( $result ) . "<br><br>";
|
||||
else // non html output
|
||||
echo "\nserver responds:\n $result\n\n";
|
||||
}
|
||||
|
||||
if ( $using_xml == 1 ) {
|
||||
// return xml string straight from server
|
||||
return ( $result );
|
||||
} else {
|
||||
// convert xml response back to hash
|
||||
$retarr = $this->decodeXML( $result );
|
||||
|
||||
// and send it back to caller. Done.
|
||||
return ( $retarr );
|
||||
}
|
||||
}
|
||||
} else { // using BUILT-IN PHP curl methods
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt( $ch, CURLOPT_URL, $host );
|
||||
curl_setopt( $ch, CURLOPT_POST, 1 );
|
||||
curl_setopt( $ch, CURLOPT_POSTFIELDS, $xml );
|
||||
curl_setopt( $ch, CURLOPT_SSLCERT, $key );
|
||||
curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0 );
|
||||
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 );
|
||||
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
|
||||
|
||||
if ( $this->debugging )
|
||||
curl_setopt( $ch, CURLOPT_VERBOSE, 1 );
|
||||
|
||||
# use curl to send the xml SSL string
|
||||
$result = curl_exec( $ch );
|
||||
curl_close( $ch );
|
||||
|
||||
if ( strlen( $result ) < 2 ) { # no response
|
||||
$result = "<r_approved>FAILURE 2</r_approved><r_error>Could not connect.</r_error>";
|
||||
return $result;
|
||||
}
|
||||
|
||||
if ( $this->debugging ) {
|
||||
if ( $webspace ) // html-friendly output
|
||||
echo "<br>server responds:<br>" . htmlspecialchars( $result ) . "<br><br>";
|
||||
else
|
||||
echo "\nserver responds:\n $result\n\n";
|
||||
}
|
||||
|
||||
if ( $using_xml ) {
|
||||
# send xml response back
|
||||
return $result;
|
||||
} else {
|
||||
#convert xml response to hash
|
||||
$retarr = $this->decodeXML( $result );
|
||||
|
||||
# and send it back
|
||||
return ( $retarr );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#############################################
|
||||
#
|
||||
# F U N C T I O N d e c o d e X M L ( )
|
||||
#
|
||||
# converts the LSGS response xml string
|
||||
# to a hash of name-value pairs
|
||||
#
|
||||
#############################################
|
||||
|
||||
function decodeXML( $xmlstg )
|
||||
{
|
||||
preg_match_all ( "/<(.*?)>(.*?)\</", $xmlstg, $out, PREG_SET_ORDER );
|
||||
|
||||
$n = 0;
|
||||
while ( isset( $out[$n] ) )
|
||||
{
|
||||
$retarr[$out[$n][1]] = strip_tags( $out[$n][0] );
|
||||
$n++;
|
||||
}
|
||||
|
||||
return $retarr;
|
||||
}
|
||||
|
||||
|
||||
############################################
|
||||
#
|
||||
# F U N C T I O N b u i l d X M L ( )
|
||||
#
|
||||
# converts a hash of name-value pairs
|
||||
# to the correct XML format for LSGS
|
||||
#
|
||||
############################################
|
||||
|
||||
function buildXML( $pdata )
|
||||
{
|
||||
|
||||
// while (list($key, $value) = each($pdata))
|
||||
// echo htmlspecialchars($key) . " = " . htmlspecialchars($value) . "<br>\n";
|
||||
|
||||
|
||||
### ORDEROPTIONS NODE ###
|
||||
$xml = "<order><orderoptions>";
|
||||
|
||||
if ( isset( $pdata["ordertype"] ) )
|
||||
$xml .= "<ordertype>" . $pdata["ordertype"] . "</ordertype>";
|
||||
|
||||
if ( isset( $pdata["result"] ) )
|
||||
$xml .= "<result>" . $pdata["result"] . "</result>";
|
||||
|
||||
$xml .= "</orderoptions>";
|
||||
|
||||
|
||||
### CREDITCARD NODE ###
|
||||
$xml .= "<creditcard>";
|
||||
|
||||
if ( isset( $pdata["cardnumber"] ) )
|
||||
$xml .= "<cardnumber>" . $pdata["cardnumber"] . "</cardnumber>";
|
||||
|
||||
if ( isset( $pdata["cardexpmonth"] ) )
|
||||
$xml .= "<cardexpmonth>" . $pdata["cardexpmonth"] . "</cardexpmonth>";
|
||||
|
||||
if ( isset( $pdata["cardexpyear"] ) )
|
||||
$xml .= "<cardexpyear>" . $pdata["cardexpyear"] . "</cardexpyear>";
|
||||
|
||||
if ( isset( $pdata["cvmvalue"] ) )
|
||||
$xml .= "<cvmvalue>" . $pdata["cvmvalue"] . "</cvmvalue>";
|
||||
|
||||
if ( isset( $pdata["cvmindicator"] ) )
|
||||
$xml .= "<cvmindicator>" . $pdata["cvmindicator"] . "</cvmindicator>";
|
||||
|
||||
if ( isset( $pdata["track"] ) )
|
||||
$xml .= "<track>" . $pdata["track"] . "</track>";
|
||||
|
||||
$xml .= "</creditcard>";
|
||||
|
||||
|
||||
### BILLING NODE ###
|
||||
$xml .= "<billing>";
|
||||
|
||||
if ( isset( $pdata["name"] ) )
|
||||
$xml .= "<name>" . $pdata["name"] . "</name>";
|
||||
|
||||
if ( isset( $pdata["company"] ) )
|
||||
$xml .= "<company>" . $pdata["company"] . "</company>";
|
||||
|
||||
if ( isset( $pdata["address1"] ) )
|
||||
$xml .= "<address1>" . $pdata["address1"] . "</address1>";
|
||||
elseif ( isset( $pdata["address"] ) )
|
||||
$xml .= "<address1>" . $pdata["address"] . "</address1>";
|
||||
|
||||
if ( isset( $pdata["address2"] ) )
|
||||
$xml .= "<address2>" . $pdata["address2"] . "</address2>";
|
||||
|
||||
if ( isset( $pdata["city"] ) )
|
||||
$xml .= "<city>" . $pdata["city"] . "</city>";
|
||||
|
||||
if ( isset( $pdata["state"] ) )
|
||||
$xml .= "<state>" . $pdata["state"] . "</state>";
|
||||
|
||||
if ( isset( $pdata["zip"] ) )
|
||||
$xml .= "<zip>" . $pdata["zip"] . "</zip>";
|
||||
|
||||
if ( isset( $pdata["country"] ) )
|
||||
$xml .= "<country>" . $pdata["country"] . "</country>";
|
||||
|
||||
if ( isset( $pdata["userid"] ) )
|
||||
$xml .= "<userid>" . $pdata["userid"] . "</userid>";
|
||||
|
||||
if ( isset( $pdata["email"] ) )
|
||||
$xml .= "<email>" . $pdata["email"] . "</email>";
|
||||
|
||||
if ( isset( $pdata["phone"] ) )
|
||||
$xml .= "<phone>" . $pdata["phone"] . "</phone>";
|
||||
|
||||
if ( isset( $pdata["fax"] ) )
|
||||
$xml .= "<fax>" . $pdata["fax"] . "</fax>";
|
||||
|
||||
if ( isset( $pdata["addrnum"] ) )
|
||||
$xml .= "<addrnum>" . $pdata["addrnum"] . "</addrnum>";
|
||||
|
||||
$xml .= "</billing>";
|
||||
|
||||
|
||||
## SHIPPING NODE ##
|
||||
$xml .= "<shipping>";
|
||||
|
||||
if ( isset( $pdata["sname"] ) )
|
||||
$xml .= "<name>" . $pdata["sname"] . "</name>";
|
||||
|
||||
if ( isset( $pdata["saddress1"] ) )
|
||||
$xml .= "<address1>" . $pdata["saddress1"] . "</address1>";
|
||||
|
||||
if ( isset( $pdata["saddress2"] ) )
|
||||
$xml .= "<address2>" . $pdata["saddress2"] . "</address2>";
|
||||
|
||||
if ( isset( $pdata["scity"] ) )
|
||||
$xml .= "<city>" . $pdata["scity"] . "</city>";
|
||||
|
||||
if ( isset( $pdata["sstate"] ) )
|
||||
$xml .= "<state>" . $pdata["sstate"] . "</state>";
|
||||
elseif ( isset( $pdata["state"] ) )
|
||||
$xml .= "<state>" . $pdata["sstate"] . "</state>";
|
||||
|
||||
if ( isset( $pdata["szip"] ) )
|
||||
$xml .= "<zip>" . $pdata["szip"] . "</zip>";
|
||||
elseif ( isset( $pdata["sip"] ) )
|
||||
$xml .= "<zip>" . $pdata["zip"] . "</zip>";
|
||||
|
||||
if ( isset( $pdata["scountry"] ) )
|
||||
$xml .= "<country>" . $pdata["scountry"] . "</country>";
|
||||
|
||||
if ( isset( $pdata["scarrier"] ) )
|
||||
$xml .= "<carrier>" . $pdata["scarrier"] . "</carrier>";
|
||||
|
||||
if ( isset( $pdata["sitems"] ) )
|
||||
$xml .= "<items>" . $pdata["sitems"] . "</items>";
|
||||
|
||||
if ( isset( $pdata["sweight"] ) )
|
||||
$xml .= "<weight>" . $pdata["sweight"] . "</weight>";
|
||||
|
||||
if ( isset( $pdata["stotal"] ) )
|
||||
$xml .= "<total>" . $pdata["stotal"] . "</total>";
|
||||
|
||||
$xml .= "</shipping>";
|
||||
|
||||
|
||||
### TRANSACTIONDETAILS NODE ###
|
||||
$xml .= "<transactiondetails>";
|
||||
|
||||
if ( isset( $pdata["oid"] ) )
|
||||
$xml .= "<oid>" . $pdata["oid"] . "</oid>";
|
||||
|
||||
if ( isset( $pdata["ponumber"] ) )
|
||||
$xml .= "<ponumber>" . $pdata["ponumber"] . "</ponumber>";
|
||||
|
||||
if ( isset( $pdata["recurring"] ) )
|
||||
$xml .= "<recurring>" . $pdata["recurring"] . "</recurring>";
|
||||
|
||||
if ( isset( $pdata["taxexempt"] ) )
|
||||
$xml .= "<taxexempt>" . $pdata["taxexempt"] . "</taxexempt>";
|
||||
|
||||
if ( isset( $pdata["terminaltype"] ) )
|
||||
$xml .= "<terminaltype>" . $pdata["terminaltype"] . "</terminaltype>";
|
||||
|
||||
if ( isset( $pdata["ip"] ) )
|
||||
$xml .= "<ip>" . $pdata["ip"] . "</ip>";
|
||||
|
||||
if ( isset( $pdata["reference_number"] ) )
|
||||
$xml .= "<reference_number>" . $pdata["reference_number"] . "</reference_number>";
|
||||
|
||||
if ( isset( $pdata["transactionorigin"] ) )
|
||||
$xml .= "<transactionorigin>" . $pdata["transactionorigin"] . "</transactionorigin>";
|
||||
|
||||
if ( isset( $pdata["invoice_number"] ) )
|
||||
$xml .= "<invoice_number>" . $pdata["invoice_number"] . "</invoice_number>";
|
||||
|
||||
if ( isset( $pdata["tdate"] ) )
|
||||
$xml .= "<tdate>" . $pdata["tdate"] . "</tdate>";
|
||||
|
||||
$xml .= "</transactiondetails>";
|
||||
|
||||
|
||||
### MERCHANTINFO NODE ###
|
||||
$xml .= "<merchantinfo>";
|
||||
|
||||
if ( isset( $pdata["configfile"] ) )
|
||||
$xml .= "<configfile>" . $pdata["configfile"] . "</configfile>";
|
||||
|
||||
if ( isset( $pdata["keyfile"] ) )
|
||||
$xml .= "<keyfile>" . $pdata["keyfile"] . "</keyfile>";
|
||||
|
||||
if ( isset( $pdata["host"] ) )
|
||||
$xml .= "<host>" . $pdata["host"] . "</host>";
|
||||
|
||||
if ( isset( $pdata["port"] ) )
|
||||
$xml .= "<port>" . $pdata["port"] . "</port>";
|
||||
|
||||
if ( isset( $pdata["appname"] ) )
|
||||
$xml .= "<appname>" . $pdata["appname"] . "</appname>";
|
||||
|
||||
$xml .= "</merchantinfo>";
|
||||
|
||||
|
||||
|
||||
### PAYMENT NODE ###
|
||||
$xml .= "<payment>";
|
||||
|
||||
if ( isset( $pdata["chargetotal"] ) )
|
||||
$xml .= "<chargetotal>" . $pdata["chargetotal"] . "</chargetotal>";
|
||||
|
||||
if ( isset( $pdata["tax"] ) )
|
||||
$xml .= "<tax>" . $pdata["tax"] . "</tax>";
|
||||
|
||||
if ( isset( $pdata["vattax"] ) )
|
||||
$xml .= "<vattax>" . $pdata["vattax"] . "</vattax>";
|
||||
|
||||
if ( isset( $pdata["shipping"] ) )
|
||||
$xml .= "<shipping>" . $pdata["shipping"] . "</shipping>";
|
||||
|
||||
if ( isset( $pdata["subtotal"] ) )
|
||||
$xml .= "<subtotal>" . $pdata["subtotal"] . "</subtotal>";
|
||||
|
||||
$xml .= "</payment>";
|
||||
|
||||
|
||||
### CHECK NODE ###
|
||||
|
||||
|
||||
if ( isset( $pdata["voidcheck"] ) ) {
|
||||
$xml .= "<telecheck><void>1</void></telecheck>";
|
||||
} elseif ( isset( $pdata["routing"] ) ) {
|
||||
$xml .= "<telecheck>";
|
||||
$xml .= "<routing>" . $pdata["routing"] . "</routing>";
|
||||
|
||||
if ( isset( $pdata["account"] ) )
|
||||
$xml .= "<account>" . $pdata["account"] . "</account>";
|
||||
|
||||
if ( isset( $pdata["bankname"] ) )
|
||||
$xml .= "<bankname>" . $pdata["bankname"] . "</bankname>";
|
||||
|
||||
if ( isset( $pdata["bankstate"] ) )
|
||||
$xml .= "<bankstate>" . $pdata["bankstate"] . "</bankstate>";
|
||||
|
||||
if ( isset( $pdata["ssn"] ) )
|
||||
$xml .= "<ssn>" . $pdata["ssn"] . "</ssn>";
|
||||
|
||||
if ( isset( $pdata["dl"] ) )
|
||||
$xml .= "<dl>" . $pdata["dl"] . "</dl>";
|
||||
|
||||
if ( isset( $pdata["dlstate"] ) )
|
||||
$xml .= "<dlstate>" . $pdata["dlstate"] . "</dlstate>";
|
||||
|
||||
if ( isset( $pdata["checknumber"] ) )
|
||||
$xml .= "<checknumber>" . $pdata["checknumber"] . "</checknumber>";
|
||||
|
||||
if ( isset( $pdata["accounttype"] ) )
|
||||
$xml .= "<accounttype>" . $pdata["accounttype"] . "</accounttype>";
|
||||
|
||||
$xml .= "</telecheck>";
|
||||
}
|
||||
|
||||
|
||||
### PERIODIC NODE ###
|
||||
|
||||
if ( isset( $pdata["startdate"] ) ) {
|
||||
$xml .= "<periodic>";
|
||||
|
||||
$xml .= "<startdate>" . $pdata["startdate"] . "</startdate>";
|
||||
|
||||
if ( isset( $pdata["installments"] ) )
|
||||
$xml .= "<installments>" . $pdata["installments"] . "</installments>";
|
||||
|
||||
if ( isset( $pdata["threshold"] ) )
|
||||
$xml .= "<threshold>" . $pdata["threshold"] . "</threshold>";
|
||||
|
||||
if ( isset( $pdata["periodicity"] ) )
|
||||
$xml .= "<periodicity>" . $pdata["periodicity"] . "</periodicity>";
|
||||
|
||||
if ( isset( $pdata["pbcomments"] ) )
|
||||
$xml .= "<comments>" . $pdata["pbcomments"] . "</comments>";
|
||||
|
||||
if ( isset( $pdata["action"] ) )
|
||||
$xml .= "<action>" . $pdata["action"] . "</action>";
|
||||
|
||||
$xml .= "</periodic>";
|
||||
}
|
||||
|
||||
|
||||
### NOTES NODE ###
|
||||
|
||||
if ( isset( $pdata["comments"] ) || isset( $pdata["referred"] ) ) {
|
||||
$xml .= "<notes>";
|
||||
|
||||
if ( isset( $pdata["comments"] ) )
|
||||
$xml .= "<comments>" . $pdata["comments"] . "</comments>";
|
||||
|
||||
if ( isset( $pdata["referred"] ) )
|
||||
$xml .= "<referred>" . $pdata["referred"] . "</referred>";
|
||||
|
||||
$xml .= "</notes>";
|
||||
}
|
||||
|
||||
### ITEMS AND OPTIONS NODES ###
|
||||
|
||||
if ( $this->debugging ) { // make it easy to see
|
||||
// LSGS doesn't mind whitespace
|
||||
reset( $pdata );
|
||||
|
||||
while ( list ( $key, $val ) = each ( $pdata ) ) {
|
||||
if ( is_array( $val ) ) {
|
||||
$otag = 0;
|
||||
$ostag = 0;
|
||||
$items_array = $val;
|
||||
$xml .= "\n<items>\n";
|
||||
|
||||
while( list( $key1, $val1 ) = each ( $items_array ) ) {
|
||||
$xml .= "\t<item>\n";
|
||||
|
||||
while ( list( $key2, $val2 ) = each ( $val1 ) ) {
|
||||
if ( !is_array( $val2 ) )
|
||||
$xml .= "\t\t<$key2>$val2</$key2>\n";
|
||||
else {
|
||||
if ( !$ostag ) {
|
||||
$xml .= "\t\t<options>\n";
|
||||
$ostag = 1;
|
||||
}
|
||||
|
||||
$xml .= "\t\t\t<option>\n";
|
||||
$otag = 1;
|
||||
|
||||
while ( list( $key3, $val3 ) = each ( $val2 ) )
|
||||
$xml .= "\t\t\t\t<$key3>$val3</$key3>\n";
|
||||
}
|
||||
|
||||
if ( $otag ) {
|
||||
$xml .= "\t\t\t</option>\n";
|
||||
$otag = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if ( $ostag ) {
|
||||
$xml .= "\t\t</options>\n";
|
||||
$ostag = 0;
|
||||
}
|
||||
$xml .= "\t</item>\n";
|
||||
}
|
||||
$xml .= "</items>\n";
|
||||
}
|
||||
}
|
||||
} else { // !debugging
|
||||
|
||||
|
||||
while ( list ( $key, $val ) = each( $pdata ) ) {
|
||||
if ( is_array( $val ) ) {
|
||||
$otag = 0;
|
||||
$ostag = 0;
|
||||
|
||||
|
||||
$xml .= "<items>";
|
||||
|
||||
while( list( $key1, $val1 ) = each( $items_array ) ) {
|
||||
$xml .= "<item>";
|
||||
|
||||
while ( list( $key2, $val2 ) = each( $val1 ) ) {
|
||||
if ( !is_array( $val2 ) )
|
||||
$xml .= "<$key2>$val2</$key2>";
|
||||
|
||||
else {
|
||||
if ( !$ostag ) {
|
||||
$xml .= "<options>";
|
||||
$ostag = 1;
|
||||
}
|
||||
|
||||
$xml .= "<option>";
|
||||
$otag = 1;
|
||||
|
||||
while ( list( $key3, $val3 ) = each ( $val2 ) )
|
||||
$xml .= "<$key3>$val3</$key3>";
|
||||
}
|
||||
|
||||
if ( $otag ) {
|
||||
$xml .= "</option>";
|
||||
$otag = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if ( $ostag ) {
|
||||
$xml .= "</options>";
|
||||
$ostag = 0;
|
||||
}
|
||||
$xml .= "</item>";
|
||||
}
|
||||
$xml .= "</items>";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$xml .= "</order>";
|
||||
|
||||
return $xml;
|
||||
}
|
||||
}
|
||||
?>
|
||||
465
sites/all/modules/civicrm/packages/HTML/Common.php
Normal file
465
sites/all/modules/civicrm/packages/HTML/Common.php
Normal file
|
|
@ -0,0 +1,465 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Base class for all HTML classes
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_Common
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: Common.php,v 1.15 2009/04/03 15:26:22 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_Common/
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for all HTML classes
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_Common
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @version Release: 1.2.5
|
||||
* @abstract
|
||||
*/
|
||||
class HTML_Common
|
||||
{
|
||||
/**
|
||||
* Associative array of attributes
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_attributes = array();
|
||||
|
||||
/**
|
||||
* Tab offset of the tag
|
||||
* @var int
|
||||
* @access private
|
||||
*/
|
||||
var $_tabOffset = 0;
|
||||
|
||||
/**
|
||||
* Tab string
|
||||
* @var string
|
||||
* @since 1.7
|
||||
* @access private
|
||||
*/
|
||||
var $_tab = "\11";
|
||||
|
||||
/**
|
||||
* Contains the line end string
|
||||
* @var string
|
||||
* @since 1.7
|
||||
* @access private
|
||||
*/
|
||||
var $_lineEnd = "\12";
|
||||
|
||||
/**
|
||||
* HTML comment on the object
|
||||
* @var string
|
||||
* @since 1.5
|
||||
* @access private
|
||||
*/
|
||||
var $_comment = '';
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
* @param mixed $attributes Associative array of table tag attributes
|
||||
* or HTML attributes name="value" pairs
|
||||
* @param int $tabOffset Indent offset in tabs
|
||||
* @access public
|
||||
*/
|
||||
function __construct($attributes = null, $tabOffset = 0)
|
||||
{
|
||||
$this->setAttributes($attributes);
|
||||
$this->setTabOffset($tabOffset);
|
||||
} // end constructor
|
||||
|
||||
/**
|
||||
* Returns the current API version
|
||||
* @access public
|
||||
* @returns double
|
||||
*/
|
||||
function apiVersion()
|
||||
{
|
||||
return 1.7;
|
||||
} // end func apiVersion
|
||||
|
||||
/**
|
||||
* Returns the lineEnd
|
||||
*
|
||||
* @since 1.7
|
||||
* @access private
|
||||
* @return string
|
||||
*/
|
||||
function _getLineEnd()
|
||||
{
|
||||
return $this->_lineEnd;
|
||||
} // end func getLineEnd
|
||||
|
||||
/**
|
||||
* Returns a string containing the unit for indenting HTML
|
||||
*
|
||||
* @since 1.7
|
||||
* @access private
|
||||
* @return string
|
||||
*/
|
||||
function _getTab()
|
||||
{
|
||||
return $this->_tab;
|
||||
} // end func _getTab
|
||||
|
||||
/**
|
||||
* Returns a string containing the offset for the whole HTML code
|
||||
*
|
||||
* @return string
|
||||
* @access private
|
||||
*/
|
||||
function _getTabs()
|
||||
{
|
||||
return str_repeat($this->_getTab(), $this->_tabOffset);
|
||||
} // end func _getTabs
|
||||
|
||||
/**
|
||||
* Returns an HTML formatted attribute string
|
||||
* @param array $attributes
|
||||
* @return string
|
||||
* @access private
|
||||
*/
|
||||
function _getAttrString($attributes)
|
||||
{
|
||||
$strAttr = '';
|
||||
|
||||
if (is_array($attributes)) {
|
||||
$charset = HTML_Common::charset();
|
||||
foreach ($attributes as $key => $value) {
|
||||
$strAttr .= ' ' . $key . '="' . htmlspecialchars($value, ENT_COMPAT, $charset) . '"';
|
||||
}
|
||||
}
|
||||
return $strAttr;
|
||||
} // end func _getAttrString
|
||||
|
||||
/**
|
||||
* Returns a valid atrributes array from either a string or array
|
||||
* @param mixed $attributes Either a typical HTML attribute string or an associative array
|
||||
* @access private
|
||||
* @return array
|
||||
*/
|
||||
function _parseAttributes($attributes)
|
||||
{
|
||||
if (is_array($attributes)) {
|
||||
$ret = array();
|
||||
foreach ($attributes as $key => $value) {
|
||||
if (is_int($key)) {
|
||||
$key = $value = strtolower($value);
|
||||
} else {
|
||||
$key = strtolower($key);
|
||||
}
|
||||
$ret[$key] = $value;
|
||||
}
|
||||
return $ret;
|
||||
|
||||
} elseif (is_string($attributes)) {
|
||||
$preg = "/(([A-Za-z_:]|[^\\x00-\\x7F])([A-Za-z0-9_:.-]|[^\\x00-\\x7F])*)" .
|
||||
"([ \\n\\t\\r]+)?(=([ \\n\\t\\r]+)?(\"[^\"]*\"|'[^']*'|[^ \\n\\t\\r]*))?/";
|
||||
if (preg_match_all($preg, $attributes, $regs)) {
|
||||
for ($counter=0; $counter<count($regs[1]); $counter++) {
|
||||
$name = $regs[1][$counter];
|
||||
$check = $regs[0][$counter];
|
||||
$value = $regs[7][$counter];
|
||||
if (trim($name) == trim($check)) {
|
||||
$arrAttr[strtolower(trim($name))] = strtolower(trim($name));
|
||||
} else {
|
||||
if (substr($value, 0, 1) == "\"" || substr($value, 0, 1) == "'") {
|
||||
$arrAttr[strtolower(trim($name))] = substr($value, 1, -1);
|
||||
} else {
|
||||
$arrAttr[strtolower(trim($name))] = trim($value);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $arrAttr;
|
||||
}
|
||||
}
|
||||
} // end func _parseAttributes
|
||||
|
||||
/**
|
||||
* Returns the array key for the given non-name-value pair attribute
|
||||
*
|
||||
* @param string $attr Attribute
|
||||
* @param array $attributes Array of attribute
|
||||
* @since 1.0
|
||||
* @access private
|
||||
* @return bool
|
||||
*/
|
||||
function _getAttrKey($attr, $attributes)
|
||||
{
|
||||
if (isset($attributes[strtolower($attr)])) {
|
||||
return true;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} //end func _getAttrKey
|
||||
|
||||
/**
|
||||
* Updates the attributes in $attr1 with the values in $attr2 without changing the other existing attributes
|
||||
* @param array $attr1 Original attributes array
|
||||
* @param array $attr2 New attributes array
|
||||
* @access private
|
||||
*/
|
||||
function _updateAttrArray(&$attr1, $attr2)
|
||||
{
|
||||
if (!is_array($attr2)) {
|
||||
return false;
|
||||
}
|
||||
foreach ($attr2 as $key => $value) {
|
||||
$attr1[$key] = $value;
|
||||
}
|
||||
} // end func _updateAtrrArray
|
||||
|
||||
/**
|
||||
* Removes the given attribute from the given array
|
||||
*
|
||||
* @param string $attr Attribute name
|
||||
* @param array $attributes Attribute array
|
||||
* @since 1.4
|
||||
* @access private
|
||||
* @return void
|
||||
*/
|
||||
function _removeAttr($attr, &$attributes)
|
||||
{
|
||||
$attr = strtolower($attr);
|
||||
if (isset($attributes[$attr])) {
|
||||
unset($attributes[$attr]);
|
||||
}
|
||||
} //end func _removeAttr
|
||||
|
||||
/**
|
||||
* Returns the value of the given attribute
|
||||
*
|
||||
* @param string $attr Attribute name
|
||||
* @since 1.5
|
||||
* @access public
|
||||
* @return string|null returns null if an attribute does not exist
|
||||
*/
|
||||
function getAttribute($attr)
|
||||
{
|
||||
$attr = strtolower($attr);
|
||||
if (isset($this->_attributes[$attr])) {
|
||||
return $this->_attributes[$attr];
|
||||
}
|
||||
return null;
|
||||
} //end func getAttribute
|
||||
|
||||
/**
|
||||
* Sets the value of the attribute
|
||||
*
|
||||
* @param string Attribute name
|
||||
* @param string Attribute value (will be set to $name if omitted)
|
||||
* @access public
|
||||
*/
|
||||
function setAttribute($name, $value = null)
|
||||
{
|
||||
$name = strtolower($name);
|
||||
if (is_null($value)) {
|
||||
$value = $name;
|
||||
}
|
||||
$this->_attributes[$name] = $value;
|
||||
} // end func setAttribute
|
||||
|
||||
/**
|
||||
* Sets the HTML attributes
|
||||
* @param mixed $attributes Either a typical HTML attribute string or an associative array
|
||||
* @access public
|
||||
*/
|
||||
function setAttributes($attributes)
|
||||
{
|
||||
$this->_attributes = $this->_parseAttributes($attributes);
|
||||
} // end func setAttributes
|
||||
|
||||
/**
|
||||
* Returns the assoc array (default) or string of attributes
|
||||
*
|
||||
* @param bool Whether to return the attributes as string
|
||||
* @since 1.6
|
||||
* @access public
|
||||
* @return mixed attributes
|
||||
*/
|
||||
function getAttributes($asString = false)
|
||||
{
|
||||
if ($asString) {
|
||||
return $this->_getAttrString($this->_attributes);
|
||||
} else {
|
||||
return $this->_attributes;
|
||||
}
|
||||
} //end func getAttributes
|
||||
|
||||
/**
|
||||
* Updates the passed attributes without changing the other existing attributes
|
||||
* @param mixed $attributes Either a typical HTML attribute string or an associative array
|
||||
* @access public
|
||||
*/
|
||||
function updateAttributes($attributes)
|
||||
{
|
||||
$this->_updateAttrArray($this->_attributes, $this->_parseAttributes($attributes));
|
||||
} // end func updateAttributes
|
||||
|
||||
/**
|
||||
* Removes an attribute
|
||||
*
|
||||
* @param string $attr Attribute name
|
||||
* @since 1.4
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function removeAttribute($attr)
|
||||
{
|
||||
$this->_removeAttr($attr, $this->_attributes);
|
||||
} //end func removeAttribute
|
||||
|
||||
/**
|
||||
* Sets the line end style to Windows, Mac, Unix or a custom string.
|
||||
*
|
||||
* @param string $style "win", "mac", "unix" or custom string.
|
||||
* @since 1.7
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setLineEnd($style)
|
||||
{
|
||||
switch ($style) {
|
||||
case 'win':
|
||||
$this->_lineEnd = "\15\12";
|
||||
break;
|
||||
case 'unix':
|
||||
$this->_lineEnd = "\12";
|
||||
break;
|
||||
case 'mac':
|
||||
$this->_lineEnd = "\15";
|
||||
break;
|
||||
default:
|
||||
$this->_lineEnd = $style;
|
||||
}
|
||||
} // end func setLineEnd
|
||||
|
||||
/**
|
||||
* Sets the tab offset
|
||||
*
|
||||
* @param int $offset
|
||||
* @access public
|
||||
*/
|
||||
function setTabOffset($offset)
|
||||
{
|
||||
$this->_tabOffset = $offset;
|
||||
} // end func setTabOffset
|
||||
|
||||
/**
|
||||
* Returns the tabOffset
|
||||
*
|
||||
* @since 1.5
|
||||
* @access public
|
||||
* @return int
|
||||
*/
|
||||
function getTabOffset()
|
||||
{
|
||||
return $this->_tabOffset;
|
||||
} //end func getTabOffset
|
||||
|
||||
/**
|
||||
* Sets the string used to indent HTML
|
||||
*
|
||||
* @since 1.7
|
||||
* @param string $string String used to indent ("\11", "\t", ' ', etc.).
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setTab($string)
|
||||
{
|
||||
$this->_tab = $string;
|
||||
} // end func setTab
|
||||
|
||||
/**
|
||||
* Sets the HTML comment to be displayed at the beginning of the HTML string
|
||||
*
|
||||
* @param string
|
||||
* @since 1.4
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setComment($comment)
|
||||
{
|
||||
$this->_comment = $comment;
|
||||
} // end func setHtmlComment
|
||||
|
||||
/**
|
||||
* Returns the HTML comment
|
||||
*
|
||||
* @since 1.5
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function getComment()
|
||||
{
|
||||
return $this->_comment;
|
||||
} //end func getComment
|
||||
|
||||
/**
|
||||
* Abstract method. Must be extended to return the objects HTML
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
* @abstract
|
||||
*/
|
||||
function toHtml()
|
||||
{
|
||||
return '';
|
||||
} // end func toHtml
|
||||
|
||||
/**
|
||||
* Displays the HTML to the screen
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function display()
|
||||
{
|
||||
print $this->toHtml();
|
||||
} // end func display
|
||||
|
||||
/**
|
||||
* Sets the charset to use by htmlspecialchars() function
|
||||
*
|
||||
* Since this parameter is expected to be global, the function is designed
|
||||
* to be called statically:
|
||||
* <code>
|
||||
* HTML_Common::charset('utf-8');
|
||||
* </code>
|
||||
* or
|
||||
* <code>
|
||||
* $charset = HTML_Common::charset();
|
||||
* </code>
|
||||
*
|
||||
* @param string New charset to use. Omit if just getting the
|
||||
* current value. Consult the htmlspecialchars() docs
|
||||
* for a list of supported character sets.
|
||||
* @return string Current charset
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
function charset($newCharset = null)
|
||||
{
|
||||
static $charset = 'ISO-8859-1';
|
||||
|
||||
if (!is_null($newCharset)) {
|
||||
$charset = $newCharset;
|
||||
}
|
||||
return $charset;
|
||||
} // end func charset
|
||||
} // end class HTML_Common
|
||||
?>
|
||||
2102
sites/all/modules/civicrm/packages/HTML/QuickForm.php
Normal file
2102
sites/all/modules/civicrm/packages/HTML/QuickForm.php
Normal file
File diff suppressed because it is too large
Load diff
55
sites/all/modules/civicrm/packages/HTML/QuickForm/Action.php
Normal file
55
sites/all/modules/civicrm/packages/HTML/QuickForm/Action.php
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Class representing an action to perform on HTTP request.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm_Controller
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2003-2007 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: Action.php,v 1.3 2007/05/18 09:34:18 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm_Controller
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class representing an action to perform on HTTP request.
|
||||
*
|
||||
* The Controller will select the appropriate Action to call on the request and
|
||||
* call its perform() method. The subclasses of this class should implement all
|
||||
* the necessary business logic.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm_Controller
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @version Release: 1.0.9
|
||||
* @abstract
|
||||
*/
|
||||
class HTML_QuickForm_Action
|
||||
{
|
||||
/**
|
||||
* Processes the request. This method should be overriden by child classes to
|
||||
* provide the necessary logic.
|
||||
*
|
||||
* @access public
|
||||
* @param HTML_QuickForm_Page The current form-page
|
||||
* @param string Current action name, as one Action object
|
||||
* can serve multiple actions
|
||||
* @throws PEAR_Error
|
||||
* @abstract
|
||||
*/
|
||||
function perform(&$page, $actionName)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* The action for a 'back' button of wizard-type multipage form.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm_Controller
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2003-2007 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: Back.php,v 1.6 2007/05/18 09:34:18 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm_Controller
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class representing an action to perform on HTTP request.
|
||||
*/
|
||||
require_once 'HTML/QuickForm/Action.php';
|
||||
|
||||
/**
|
||||
* The action for a 'back' button of wizard-type multipage form.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm_Controller
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @version Release: 1.0.9
|
||||
*/
|
||||
class HTML_QuickForm_Action_Back extends HTML_QuickForm_Action
|
||||
{
|
||||
function perform(&$page, $actionName)
|
||||
{
|
||||
// save the form values and validation status to the session
|
||||
$page->isFormBuilt() or $page->buildForm();
|
||||
$pageName = $page->getAttribute('id');
|
||||
$data =& $page->controller->container();
|
||||
$data['values'][$pageName] = $page->exportValues();
|
||||
if (!$page->controller->isModal()) {
|
||||
if (PEAR::isError($valid = $page->validate())) {
|
||||
return $valid;
|
||||
}
|
||||
$data['valid'][$pageName] = $valid;
|
||||
}
|
||||
|
||||
// get the previous page and go to it
|
||||
// we don't check validation status here, 'jump' handler should
|
||||
if (null === ($prevName = $page->controller->getPrevName($pageName))) {
|
||||
return $page->handle('jump');
|
||||
} else {
|
||||
$prev =& $page->controller->getPage($prevName);
|
||||
return $prev->handle('jump');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* This action allows to go to a specific page of a multipage form.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm_Controller
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2003-2007 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: Direct.php,v 1.4 2007/05/18 09:34:18 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm_Controller
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class representing an action to perform on HTTP request.
|
||||
*/
|
||||
require_once 'HTML/QuickForm/Action.php';
|
||||
|
||||
/**
|
||||
* This action allows to go to a specific page of a multipage form.
|
||||
*
|
||||
* Please note that the name for this action in addAction() should NOT be
|
||||
* 'direct', but the name of the page you wish to go to.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm_Controller
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @version Release: 1.0.9
|
||||
*/
|
||||
class HTML_QuickForm_Action_Direct extends HTML_QuickForm_Action
|
||||
{
|
||||
function perform(&$page, $actionName)
|
||||
{
|
||||
// save the form values and validation status to the session
|
||||
$page->isFormBuilt() or $page->buildForm();
|
||||
$pageName = $page->getAttribute('id');
|
||||
$data =& $page->controller->container();
|
||||
$data['values'][$pageName] = $page->exportValues();
|
||||
if (PEAR::isError($valid = $page->validate())) {
|
||||
return $valid;
|
||||
}
|
||||
$data['valid'][$pageName] = $valid;
|
||||
|
||||
$target =& $page->controller->getPage($actionName);
|
||||
if (PEAR::isError($target)) {
|
||||
return $target;
|
||||
} else {
|
||||
return $target->handle('jump');
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
@ -0,0 +1,89 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* This action handles output of the form.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm_Controller
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2003-2007 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: Display.php,v 1.7 2007/05/18 09:34:18 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm_Controller
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class representing an action to perform on HTTP request.
|
||||
*/
|
||||
require_once 'HTML/QuickForm/Action.php';
|
||||
|
||||
/**
|
||||
* This action handles output of the form.
|
||||
*
|
||||
* If you want to customize the form display, subclass this class and
|
||||
* override the _renderForm() method, you don't need to change the perform()
|
||||
* method itself.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm_Controller
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @version Release: 1.0.9
|
||||
*/
|
||||
class HTML_QuickForm_Action_Display extends HTML_QuickForm_Action
|
||||
{
|
||||
function perform(&$page, $actionName)
|
||||
{
|
||||
$pageName = $page->getAttribute('id');
|
||||
// If the original action was 'display' and we have values in container then we load them
|
||||
// BTW, if the page was invalid, we should later call validate() to get the errors
|
||||
list(, $oldName) = $page->controller->getActionName();
|
||||
if ('display' == $oldName) {
|
||||
// If the controller is "modal" we should not allow direct access to a page
|
||||
// unless all previous pages are valid (see also bug #2323)
|
||||
if ($page->controller->isModal() && !$page->controller->isValid($page->getAttribute('id'))) {
|
||||
$target =& $page->controller->getPage($page->controller->findInvalid());
|
||||
return $target->handle('jump');
|
||||
}
|
||||
$data =& $page->controller->container();
|
||||
if (!empty($data['values'][$pageName])) {
|
||||
$page->loadValues($data['values'][$pageName]);
|
||||
$validate = false === $data['valid'][$pageName];
|
||||
}
|
||||
}
|
||||
// set "common" defaults and constants
|
||||
$page->controller->applyDefaults($pageName);
|
||||
$page->isFormBuilt() or $page->buildForm();
|
||||
// if we had errors we should show them again
|
||||
if (isset($validate) && $validate) {
|
||||
if (PEAR::isError($err = $page->validate())) {
|
||||
return $err;
|
||||
}
|
||||
}
|
||||
return $this->_renderForm($page);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Actually outputs the form.
|
||||
*
|
||||
* If you want to customize the form's appearance (you most certainly will),
|
||||
* then you should override this method. There is no need to override perform()
|
||||
*
|
||||
* @access private
|
||||
* @param HTML_QuickForm_Page the page being processed
|
||||
*/
|
||||
function _renderForm(&$page)
|
||||
{
|
||||
$page->display();
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
@ -0,0 +1,162 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* This action performs HTTP redirect to a specific page.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm_Controller
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2003-2007 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: Jump.php,v 1.6 2008/07/22 11:05:20 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm_Controller
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class representing an action to perform on HTTP request.
|
||||
*/
|
||||
require_once 'HTML/QuickForm/Action.php';
|
||||
|
||||
/**
|
||||
* This action performs HTTP redirect to a specific page.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm_Controller
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @version Release: 1.0.9
|
||||
*/
|
||||
class HTML_QuickForm_Action_Jump extends HTML_QuickForm_Action
|
||||
{
|
||||
/**
|
||||
* Splits (part of) the URI into path and query components
|
||||
*
|
||||
* @param string String of the form 'foo?bar'
|
||||
* @return array Array of the form array('foo', '?bar)
|
||||
* @access private
|
||||
*/
|
||||
function _splitUri($uri)
|
||||
{
|
||||
if (false === ($qm = strpos($uri, '?'))) {
|
||||
return array($uri, '');
|
||||
} else {
|
||||
return array(substr($uri, 0, $qm), substr($uri, $qm));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the '..' and '.' segments from the path component
|
||||
*
|
||||
* @param string Path component of the URL, possibly with '.' and '..' segments
|
||||
* @return string Path component of the URL with '.' and '..' segments removed
|
||||
* @access private
|
||||
*/
|
||||
function _normalizePath($path)
|
||||
{
|
||||
$pathAry = explode('/', $path);
|
||||
$i = 1;
|
||||
|
||||
do {
|
||||
if ('.' == $pathAry[$i]) {
|
||||
if ($i < count($pathAry) - 1) {
|
||||
array_splice($pathAry, $i, 1);
|
||||
} else {
|
||||
$pathAry[$i] = '';
|
||||
$i++;
|
||||
}
|
||||
|
||||
} elseif ('..' == $pathAry[$i] && $i > 1 && '..' != $pathAry[$i - 1]) {
|
||||
if ($i < count($pathAry) -1) {
|
||||
array_splice($pathAry, $i - 1, 2);
|
||||
$i--;
|
||||
} else {
|
||||
array_splice($pathAry, $i - 1, 2, '');
|
||||
}
|
||||
|
||||
} else {
|
||||
$i++;
|
||||
}
|
||||
} while ($i < count($pathAry));
|
||||
|
||||
return implode('/', $pathAry);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves relative URL using current page's URL as base
|
||||
*
|
||||
* The method follows procedure described in section 4 of RFC 1808 and
|
||||
* passes the examples provided in section 5 of said RFC. Values from
|
||||
* $_SERVER array are used for calculation of "current URL"
|
||||
*
|
||||
* @param string Relative URL, probably from form's action attribute
|
||||
* @return string Absolute URL
|
||||
* @access private
|
||||
*/
|
||||
function _resolveRelativeURL($url)
|
||||
{
|
||||
$https = !empty($_SERVER['HTTPS']) && ('off' != $_SERVER['HTTPS']);
|
||||
$scheme = ($https? 'https:': 'http:');
|
||||
if ('//' == substr($url, 0, 2)) {
|
||||
return $scheme . $url;
|
||||
|
||||
} else {
|
||||
$host = $scheme . '//' . $_SERVER['SERVER_NAME'] .
|
||||
(($https && 443 == $_SERVER['SERVER_PORT'] ||
|
||||
!$https && 80 == $_SERVER['SERVER_PORT'])? '': ':' . $_SERVER['SERVER_PORT']);
|
||||
if ('' == $url) {
|
||||
return $host . $_SERVER['REQUEST_URI'];
|
||||
|
||||
} elseif ('/' == $url[0]) {
|
||||
return $host . $url;
|
||||
|
||||
} else {
|
||||
list($basePath, $baseQuery) = $this->_splitUri($_SERVER['REQUEST_URI']);
|
||||
list($actPath, $actQuery) = $this->_splitUri($url);
|
||||
if ('' == $actPath) {
|
||||
return $host . $basePath . $actQuery;
|
||||
} else {
|
||||
$path = substr($basePath, 0, strrpos($basePath, '/') + 1) . $actPath;
|
||||
return $host . $this->_normalizePath($path) . $actQuery;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function perform(&$page, $actionName)
|
||||
{
|
||||
// check whether the page is valid before trying to go to it
|
||||
if ($page->controller->isModal()) {
|
||||
// we check whether *all* pages up to current are valid
|
||||
// if there is an invalid page we go to it, instead of the
|
||||
// requested one
|
||||
$pageName = $page->getAttribute('id');
|
||||
if (!$page->controller->isValid($pageName)) {
|
||||
$pageName = $page->controller->findInvalid();
|
||||
}
|
||||
$current =& $page->controller->getPage($pageName);
|
||||
|
||||
} else {
|
||||
$current =& $page;
|
||||
}
|
||||
// generate the URL for the page 'display' event and redirect to it
|
||||
$action = $current->getAttribute('action');
|
||||
// Bug #13087: RFC 2616 requires an absolute URI in Location header
|
||||
if (!preg_match('!^https?://!i', $action)) {
|
||||
$action = $this->_resolveRelativeURL($action);
|
||||
}
|
||||
$url = $action . (false === strpos($action, '?')? '?': '&') .
|
||||
$current->getButtonName('display') . '=true' .
|
||||
((!defined('SID') || '' == SID || ini_get('session.use_only_cookies'))? '': '&' . SID);
|
||||
header('Location: ' . $url);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
@ -0,0 +1,73 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* The action for a 'next' button of wizard-type multipage form.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm_Controller
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2003-2007 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: Next.php,v 1.6 2007/05/18 09:34:18 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm_Controller
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class representing an action to perform on HTTP request.
|
||||
*/
|
||||
require_once 'HTML/QuickForm/Action.php';
|
||||
|
||||
/**
|
||||
* The action for a 'next' button of wizard-type multipage form.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm_Controller
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @version Release: 1.0.9
|
||||
*/
|
||||
class HTML_QuickForm_Action_Next extends HTML_QuickForm_Action
|
||||
{
|
||||
function perform(&$page, $actionName)
|
||||
{
|
||||
// save the form values and validation status to the session
|
||||
$page->isFormBuilt() or $page->buildForm();
|
||||
$pageName = $page->getAttribute('id');
|
||||
$data =& $page->controller->container();
|
||||
$data['values'][$pageName] = $page->exportValues();
|
||||
if (PEAR::isError($valid = $page->validate())) {
|
||||
return $valid;
|
||||
}
|
||||
$data['valid'][$pageName] = $valid;
|
||||
|
||||
// Modal form and page is invalid: don't go further
|
||||
if ($page->controller->isModal() && !$data['valid'][$pageName]) {
|
||||
return $page->handle('display');
|
||||
}
|
||||
// More pages?
|
||||
if (null !== ($nextName = $page->controller->getNextName($pageName))) {
|
||||
$next =& $page->controller->getPage($nextName);
|
||||
return $next->handle('jump');
|
||||
// Consider this a 'finish' button, if there is no explicit one
|
||||
} elseif($page->controller->isModal()) {
|
||||
if ($page->controller->isValid()) {
|
||||
return $page->handle('process');
|
||||
} else {
|
||||
// this should redirect to the first invalid page
|
||||
return $page->handle('jump');
|
||||
}
|
||||
} else {
|
||||
return $page->handle('display');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* The action for a 'submit' button.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm_Controller
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2003-2007 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: Submit.php,v 1.5 2007/05/18 09:34:18 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm_Controller
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class representing an action to perform on HTTP request.
|
||||
*/
|
||||
require_once 'HTML/QuickForm/Action.php';
|
||||
|
||||
/**
|
||||
* The action for a 'submit' button.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm_Controller
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @version Release: 1.0.9
|
||||
*/
|
||||
class HTML_QuickForm_Action_Submit extends HTML_QuickForm_Action
|
||||
{
|
||||
function perform(&$page, $actionName)
|
||||
{
|
||||
// save the form values and validation status to the session
|
||||
$page->isFormBuilt() or $page->buildForm();
|
||||
$pageName = $page->getAttribute('id');
|
||||
$data =& $page->controller->container();
|
||||
$data['values'][$pageName] = $page->exportValues();
|
||||
if (PEAR::isError($valid = $page->validate())) {
|
||||
return $valid;
|
||||
}
|
||||
$data['valid'][$pageName] = $valid;
|
||||
|
||||
// All pages are valid, process
|
||||
if ($page->controller->isValid()) {
|
||||
return $page->handle('process');
|
||||
|
||||
// Current page is invalid, display it
|
||||
} elseif (!$data['valid'][$pageName]) {
|
||||
return $page->handle('display');
|
||||
|
||||
// Some other page is invalid, redirect to it
|
||||
} else {
|
||||
$target =& $page->controller->getPage($page->controller->findInvalid());
|
||||
return $target->handle('jump');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
542
sites/all/modules/civicrm/packages/HTML/QuickForm/Controller.php
Normal file
542
sites/all/modules/civicrm/packages/HTML/QuickForm/Controller.php
Normal file
|
|
@ -0,0 +1,542 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* The class representing a Controller of MVC design pattern.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm_Controller
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @copyright 2003-2007 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: Controller.php,v 1.13 2007/05/18 09:34:18 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm_Controller
|
||||
*/
|
||||
|
||||
/**
|
||||
* The class representing a page of a multipage form.
|
||||
*/
|
||||
require_once 'HTML/QuickForm/Page.php';
|
||||
|
||||
/**
|
||||
* The class representing a Controller of MVC design pattern.
|
||||
*
|
||||
* This class keeps track of pages and (default) action handlers for the form,
|
||||
* it manages keeping the form values in session, setting defaults and
|
||||
* constants for the form as a whole and getting its submit values.
|
||||
*
|
||||
* Generally you don't need to subclass this.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm_Controller
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @version Release: 1.0.9
|
||||
*/
|
||||
class HTML_QuickForm_Controller
|
||||
{
|
||||
/**
|
||||
* Contains the pages (HTML_QuickForm_Page objects) of the miultipage form
|
||||
* @var array
|
||||
*/
|
||||
var $_pages = array();
|
||||
|
||||
/**
|
||||
* Contains the mapping of actions to corresponding HTML_QuickForm_Action objects
|
||||
* @var array
|
||||
*/
|
||||
var $_actions = array();
|
||||
|
||||
/**
|
||||
* Name of the form, used to store the values in session
|
||||
* @var string
|
||||
*/
|
||||
var $_name;
|
||||
|
||||
/**
|
||||
* Whether the form is modal
|
||||
* @var bool
|
||||
*/
|
||||
var $_modal = true;
|
||||
|
||||
/**
|
||||
* The action extracted from HTTP request: array('page', 'action')
|
||||
* @var array
|
||||
*/
|
||||
var $_actionName = null;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* Sets the form name and modal/non-modal behaviuor. Different multipage
|
||||
* forms should have different names, as they are used to store form
|
||||
* values in session. Modal forms allow passing to the next page only when
|
||||
* all of the previous pages are valid.
|
||||
*
|
||||
* @access public
|
||||
* @param string form name
|
||||
* @param bool whether the form is modal
|
||||
*/
|
||||
function __construct($name, $modal = true)
|
||||
{
|
||||
$this->_name = $name;
|
||||
$this->_modal = $modal;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a reference to a session variable containing the form-page
|
||||
* values and pages' validation status.
|
||||
*
|
||||
* This is a "low-level" method, use exportValues() if you want just to
|
||||
* get the form's values.
|
||||
*
|
||||
* @access public
|
||||
* @param bool If true, then reset the container: clear all default, constant and submitted values
|
||||
* @return array
|
||||
*/
|
||||
function &container($reset = false)
|
||||
{
|
||||
$name = '_' . $this->_name . '_container';
|
||||
if (!isset($_SESSION[$name]) || $reset) {
|
||||
$_SESSION[$name] = array(
|
||||
'defaults' => array(),
|
||||
'constants' => array(),
|
||||
'values' => array(),
|
||||
'valid' => array()
|
||||
);
|
||||
}
|
||||
foreach (array_keys($this->_pages) as $pageName) {
|
||||
if (!isset($_SESSION[$name]['values'][$pageName])) {
|
||||
$_SESSION[$name]['values'][$pageName] = array();
|
||||
$_SESSION[$name]['valid'][$pageName] = null;
|
||||
}
|
||||
}
|
||||
return $_SESSION[$name];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Processes the request.
|
||||
*
|
||||
* This finds the current page, the current action and passes the action
|
||||
* to the page's handle() method.
|
||||
*
|
||||
* @access public
|
||||
* @throws PEAR_Error
|
||||
*/
|
||||
function run()
|
||||
{
|
||||
// the names of the action and page should be saved
|
||||
list($page, $action) = $this->_actionName = $this->getActionName();
|
||||
return $this->_pages[$page]->handle($action);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Registers a handler for a specific action.
|
||||
*
|
||||
* @access public
|
||||
* @param string name of the action
|
||||
* @param HTML_QuickForm_Action the handler for the action
|
||||
*/
|
||||
function addAction($actionName, $action)
|
||||
{
|
||||
$this->_actions[$actionName] = $action;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds a new page to the form
|
||||
*
|
||||
* @access public
|
||||
* @param HTML_QuickForm_Page
|
||||
*/
|
||||
function addPage(&$page)
|
||||
{
|
||||
$page->controller =& $this;
|
||||
$this->_pages[$page->getAttribute('id')] =& $page;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a page
|
||||
*
|
||||
* @access public
|
||||
* @param string Name of a page
|
||||
* @return HTML_QuickForm_Page A reference to the page
|
||||
* @throws PEAR_Error
|
||||
*/
|
||||
function &getPage($pageName)
|
||||
{
|
||||
if (!isset($this->_pages[$pageName])) {
|
||||
return PEAR::raiseError('HTML_QuickForm_Controller: Unknown page "' . $pageName . '"');
|
||||
}
|
||||
return $this->_pages[$pageName];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handles an action.
|
||||
*
|
||||
* This will be called if the page itself does not have a handler
|
||||
* to a specific action. The method also loads and uses default handlers
|
||||
* for common actions, if specific ones were not added.
|
||||
*
|
||||
* @access public
|
||||
* @param HTML_QuickForm_Page The page that failed to handle the action
|
||||
* @param string Name of the action
|
||||
* @throws PEAR_Error
|
||||
*/
|
||||
function handle(&$page, $actionName)
|
||||
{
|
||||
if (isset($this->_actions[$actionName])) {
|
||||
return $this->_actions[$actionName]->perform($page, $actionName);
|
||||
}
|
||||
switch ($actionName) {
|
||||
case 'next':
|
||||
case 'back':
|
||||
case 'submit':
|
||||
case 'display':
|
||||
case 'jump':
|
||||
include_once 'HTML/QuickForm/Action/' . ucfirst($actionName) . '.php';
|
||||
$className = 'HTML_QuickForm_Action_' . $actionName;
|
||||
$this->_actions[$actionName] = new $className();
|
||||
return $this->_actions[$actionName]->perform($page, $actionName);
|
||||
break;
|
||||
default:
|
||||
return PEAR::raiseError('HTML_QuickForm_Controller: Unhandled action "' . $actionName . '" in page "' . $page->getAttribute('id') . '"');
|
||||
} // switch
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks whether the form is modal.
|
||||
*
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
function isModal()
|
||||
{
|
||||
return $this->_modal;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks whether the pages of the controller are valid
|
||||
*
|
||||
* @access public
|
||||
* @param string If set, check only the pages before (not including) that page
|
||||
* @return bool
|
||||
* @throws PEAR_Error
|
||||
*/
|
||||
function isValid($pageName = null)
|
||||
{
|
||||
$data =& $this->container();
|
||||
foreach (array_keys($this->_pages) as $key) {
|
||||
if (isset($pageName) && $pageName == $key) {
|
||||
return true;
|
||||
} elseif (!$data['valid'][$key]) {
|
||||
// We should handle the possible situation when the user has never
|
||||
// seen a page of a non-modal multipage form
|
||||
if (!$this->isModal() && null === $data['valid'][$key]) {
|
||||
$page =& $this->_pages[$key];
|
||||
// Fix for bug #8687: the unseen page was considered
|
||||
// submitted, so defaults for checkboxes and multiselects
|
||||
// were not used. Shouldn't break anything since this flag
|
||||
// will be reset right below in loadValues().
|
||||
$page->_flagSubmitted = false;
|
||||
// Use controller's defaults and constants, if present
|
||||
$this->applyDefaults($key);
|
||||
$page->isFormBuilt() or $page->BuildForm();
|
||||
// We use defaults and constants as if they were submitted
|
||||
$data['values'][$key] = $page->exportValues();
|
||||
$page->loadValues($data['values'][$key]);
|
||||
// Is the page now valid?
|
||||
if (PEAR::isError($valid = $page->validate())) {
|
||||
return $valid;
|
||||
}
|
||||
$data['valid'][$key] = $valid;
|
||||
if (true === $valid) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the name of the page before the given.
|
||||
*
|
||||
* @access public
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
function getPrevName($pageName)
|
||||
{
|
||||
$prev = null;
|
||||
foreach (array_keys($this->_pages) as $key) {
|
||||
if ($key == $pageName) {
|
||||
return $prev;
|
||||
}
|
||||
$prev = $key;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the name of the page after the given.
|
||||
*
|
||||
* @access public
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
function getNextName($pageName)
|
||||
{
|
||||
$prev = null;
|
||||
foreach (array_keys($this->_pages) as $key) {
|
||||
if ($prev == $pageName) {
|
||||
return $key;
|
||||
}
|
||||
$prev = $key;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Finds the (first) invalid page
|
||||
*
|
||||
* @access public
|
||||
* @return string Name of an invalid page
|
||||
*/
|
||||
function findInvalid()
|
||||
{
|
||||
$data =& $this->container();
|
||||
foreach (array_keys($this->_pages) as $key) {
|
||||
if (!$data['valid'][$key]) {
|
||||
return $key;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extracts the names of the current page and the current action from
|
||||
* HTTP request data.
|
||||
*
|
||||
* @access public
|
||||
* @return array first element is page name, second is action name
|
||||
*/
|
||||
function getActionName()
|
||||
{
|
||||
if (is_array($this->_actionName)) {
|
||||
return $this->_actionName;
|
||||
}
|
||||
$names = array_map('preg_quote', array_keys($this->_pages));
|
||||
$regex = '/^_qf_(' . implode('|', $names) . ')_(.+?)(_.+?)?(_x)?$/';
|
||||
$data =& $this->container();
|
||||
unset( $data['_qf_button_name'] );
|
||||
foreach (array_keys($_REQUEST) as $key) {
|
||||
if (preg_match($regex, $key, $matches)) {
|
||||
$data['_qf_button_name'] = $key;
|
||||
if ( array_key_exists( 3, $matches ) ) {
|
||||
$key = preg_replace( '/_(x|y)$/', '', $key );
|
||||
}
|
||||
return array($matches[1], $matches[2]);
|
||||
}
|
||||
}
|
||||
if (isset($_REQUEST['_qf_default'])) {
|
||||
$matches = explode(':', $_REQUEST['_qf_default'], 2);
|
||||
if (isset($this->_pages[$matches[0]])) {
|
||||
return $matches;
|
||||
}
|
||||
}
|
||||
reset($this->_pages);
|
||||
return array(key($this->_pages), 'display');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Initializes default form values.
|
||||
*
|
||||
* @access public
|
||||
* @param array default values
|
||||
* @param mixed filter(s) to apply to default values
|
||||
* @throws PEAR_Error
|
||||
*/
|
||||
function setDefaults($defaultValues = null, $filter = null)
|
||||
{
|
||||
if (is_array($defaultValues)) {
|
||||
$data =& $this->container();
|
||||
return $this->_setDefaultsOrConstants($data['defaults'], $defaultValues, $filter);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Initializes constant form values.
|
||||
* These values won't get overridden by POST or GET vars
|
||||
*
|
||||
* @access public
|
||||
* @param array constant values
|
||||
* @param mixed filter(s) to apply to constant values
|
||||
* @throws PEAR_Error
|
||||
*/
|
||||
function setConstants($constantValues = null, $filter = null)
|
||||
{
|
||||
if (is_array($constantValues)) {
|
||||
$data =& $this->container();
|
||||
return $this->_setDefaultsOrConstants($data['constants'], $constantValues, $filter);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds new values to defaults or constants array
|
||||
*
|
||||
* @access private
|
||||
* @param array array to add values to (either defaults or constants)
|
||||
* @param array values to add
|
||||
* @param mixed filters to apply to new values
|
||||
* @throws PEAR_Error
|
||||
*/
|
||||
function _setDefaultsOrConstants(&$values, $newValues, $filter = null)
|
||||
{
|
||||
if (isset($filter)) {
|
||||
if (is_array($filter) && (2 != count($filter) || !is_callable($filter))) {
|
||||
foreach ($filter as $val) {
|
||||
if (!is_callable($val)) {
|
||||
return PEAR::raiseError(null, QUICKFORM_INVALID_FILTER, null, E_USER_WARNING, "Callback function does not exist in QuickForm_Controller::_setDefaultsOrConstants()", 'HTML_QuickForm_Error', true);
|
||||
} else {
|
||||
$newValues = $this->_arrayMapRecursive($val, $newValues);
|
||||
}
|
||||
}
|
||||
} elseif (!is_callable($filter)) {
|
||||
return PEAR::raiseError(null, QUICKFORM_INVALID_FILTER, null, E_USER_WARNING, "Callback function does not exist in QuickForm_Controller::_setDefaultsOrConstants()", 'HTML_QuickForm_Error', true);
|
||||
} else {
|
||||
$newValues = $this->_arrayMapRecursive($val, $newValues);
|
||||
}
|
||||
}
|
||||
$values = HTML_QuickForm::arrayMerge($values, $newValues);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Recursively applies the callback function to the value
|
||||
*
|
||||
* @param mixed Callback function
|
||||
* @param mixed Value to process
|
||||
* @access private
|
||||
* @return mixed Processed values
|
||||
*/
|
||||
function _arrayMapRecursive($callback, $value)
|
||||
{
|
||||
if (!is_array($value)) {
|
||||
return call_user_func($callback, $value);
|
||||
} else {
|
||||
$map = array();
|
||||
foreach ($value as $k => $v) {
|
||||
$map[$k] = $this->_arrayMapRecursive($callback, $v);
|
||||
}
|
||||
return $map;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the default values for the given page
|
||||
*
|
||||
* @access public
|
||||
* @param string Name of a page
|
||||
*/
|
||||
function applyDefaults($pageName)
|
||||
{
|
||||
$data =& $this->container();
|
||||
if (!empty($data['defaults'])) {
|
||||
$this->_pages[$pageName]->setDefaults($data['defaults']);
|
||||
}
|
||||
if (!empty($data['constants'])) {
|
||||
$this->_pages[$pageName]->setConstants($data['constants']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the form's values
|
||||
*
|
||||
* @access public
|
||||
* @param string name of the page, if not set then returns values for all pages
|
||||
* @return array
|
||||
*/
|
||||
function exportValues($pageName = null)
|
||||
{
|
||||
$data =& $this->container();
|
||||
$values = array();
|
||||
if (isset($pageName)) {
|
||||
$pages = array($pageName);
|
||||
} else {
|
||||
$pages = array_keys($data['values']);
|
||||
}
|
||||
foreach ($pages as $page) {
|
||||
// skip elements representing actions
|
||||
foreach ($data['values'][$page] as $key => $value) {
|
||||
if (0 !== strpos($key, '_qf_')) {
|
||||
if (isset($values[$key]) && is_array($value)) {
|
||||
$values[$key] = HTML_QuickForm::arrayMerge($values[$key], $value);
|
||||
} else {
|
||||
$values[$key] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $values;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the element's value
|
||||
*
|
||||
* @access public
|
||||
* @param string name of the page
|
||||
* @param string name of the element in the page
|
||||
* @return mixed value for the element
|
||||
*/
|
||||
function exportValue($pageName, $elementName)
|
||||
{
|
||||
$data =& $this->container();
|
||||
return isset($data['values'][$pageName][$elementName])? $data['values'][$pageName][$elementName]: null;
|
||||
}
|
||||
|
||||
/**
|
||||
* resets a specifc page in the container
|
||||
*
|
||||
* @access public
|
||||
* @param string name of the page
|
||||
* @return void
|
||||
*/
|
||||
function resetPage($pageName, $valid = null)
|
||||
{
|
||||
$data =& $this->container();
|
||||
if (isset($data['values'][$pageName]) ||
|
||||
isset($data['valid'][$pageName])) {
|
||||
$data['values'][$pageName] = array( );
|
||||
$data['valid'][$pageName] = $valid;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
214
sites/all/modules/civicrm/packages/HTML/QuickForm/Page.php
Normal file
214
sites/all/modules/civicrm/packages/HTML/QuickForm/Page.php
Normal file
|
|
@ -0,0 +1,214 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Class representing a page of a multipage form.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm_Controller
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @copyright 2003-2007 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: Page.php,v 1.7 2007/05/18 09:34:18 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm_Controller
|
||||
*/
|
||||
|
||||
/**
|
||||
* Create, validate and process HTML forms
|
||||
*/
|
||||
require_once 'HTML/QuickForm.php';
|
||||
|
||||
/**
|
||||
* Class representing a page of a multipage form.
|
||||
*
|
||||
* Generally you'll need to subclass this and define your buildForm()
|
||||
* method that will build the form. While it is also possible to instantiate
|
||||
* this class and build the form manually, this is not the recommended way.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm_Controller
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @version Release: 1.0.9
|
||||
*/
|
||||
class HTML_QuickForm_Page extends HTML_QuickForm
|
||||
{
|
||||
/**
|
||||
* Contains the mapping of actions to corresponding HTML_QuickForm_Action objects
|
||||
* @var array
|
||||
*/
|
||||
var $_actions = array();
|
||||
|
||||
/**
|
||||
* Contains a reference to a Controller object containing this page
|
||||
* @var HTML_QuickForm_Controller
|
||||
* @access public
|
||||
*/
|
||||
var $controller = null;
|
||||
|
||||
/**
|
||||
* Should be set to true on first call to buildForm()
|
||||
* @var bool
|
||||
*/
|
||||
var $_formBuilt = false;
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function __construct($formName, $method = 'post', $target = '', $attributes = null)
|
||||
{
|
||||
parent::__construct($formName, $method, '', $target, $attributes);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Registers a handler for a specific action.
|
||||
*
|
||||
* @access public
|
||||
* @param string name of the action
|
||||
* @param HTML_QuickForm_Action the handler for the action
|
||||
*/
|
||||
function addAction($actionName, &$action)
|
||||
{
|
||||
$this->_actions[$actionName] =& $action;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handles an action.
|
||||
*
|
||||
* If an Action object was not registered here, controller's handle()
|
||||
* method will be called.
|
||||
*
|
||||
* @access public
|
||||
* @param string Name of the action
|
||||
* @throws PEAR_Error
|
||||
*/
|
||||
function handle($actionName)
|
||||
{
|
||||
if (isset($this->_actions[$actionName])) {
|
||||
return $this->_actions[$actionName]->perform($this, $actionName);
|
||||
} else {
|
||||
return $this->controller->handle($this, $actionName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a name for a submit button that will invoke a specific action.
|
||||
*
|
||||
* @access public
|
||||
* @param string Name of the action
|
||||
* @return string "name" attribute for a submit button
|
||||
*/
|
||||
function getButtonName($actionName, $subActionName = null)
|
||||
{
|
||||
if ( $subActionName != null ) {
|
||||
return '_qf_' . $this->getAttribute('id') . '_' . $actionName . '_' . $subActionName;
|
||||
} else {
|
||||
return '_qf_' . $this->getAttribute('id') . '_' . $actionName;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Loads the submit values from the array.
|
||||
*
|
||||
* The method is NOT intended for general usage.
|
||||
*
|
||||
* @param array 'submit' values
|
||||
* @access public
|
||||
*/
|
||||
function loadValues($values)
|
||||
{
|
||||
$this->_flagSubmitted = true;
|
||||
$this->_submitValues = $values;
|
||||
foreach (array_keys($this->_elements) as $key) {
|
||||
$this->_elements[$key]->onQuickFormEvent('updateValue', null, $this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Builds a form.
|
||||
*
|
||||
* You should override this method when you subclass HTML_QuickForm_Page,
|
||||
* it should contain all the necessary addElement(), applyFilter(), addRule()
|
||||
* and possibly setDefaults() and setConstants() calls. The method will be
|
||||
* called on demand, so please be sure to set $_formBuilt property to true to
|
||||
* assure that the method works only once.
|
||||
*
|
||||
* @access public
|
||||
* @abstract
|
||||
*/
|
||||
function buildForm()
|
||||
{
|
||||
$this->_formBuilt = true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks whether the form was already built.
|
||||
*
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
function isFormBuilt()
|
||||
{
|
||||
return $this->_formBuilt;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the default action invoked on page-form submit
|
||||
*
|
||||
* This is necessary as the user may just press Enter instead of
|
||||
* clicking one of the named submit buttons and then no action name will
|
||||
* be passed to the script.
|
||||
*
|
||||
* @access public
|
||||
* @param string default action name
|
||||
*/
|
||||
function setDefaultAction($actionName)
|
||||
{
|
||||
if ($this->elementExists('_qf_default')) {
|
||||
$element =& $this->getElement('_qf_default');
|
||||
$element->setValue($this->getAttribute('id') . ':' . $actionName);
|
||||
} else {
|
||||
$this->addElement('hidden', '_qf_default', $this->getAttribute('id') . ':' . $actionName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns 'safe' elements' values
|
||||
*
|
||||
* @param mixed Array/string of element names, whose values we want. If not set then return all elements.
|
||||
* @param bool Whether to remove internal (_qf_...) values from the resultant array
|
||||
*/
|
||||
function exportValues($elementList = null, $filterInternal = false)
|
||||
{
|
||||
$values = parent::exportValues($elementList);
|
||||
if ($filterInternal) {
|
||||
foreach (array_keys($values) as $key) {
|
||||
if (0 === strpos($key, '_qf_')) {
|
||||
unset($values[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $values;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
158
sites/all/modules/civicrm/packages/HTML/QuickForm/Renderer.php
Normal file
158
sites/all/modules/civicrm/packages/HTML/QuickForm/Renderer.php
Normal file
|
|
@ -0,0 +1,158 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* An abstract base class for QuickForm renderers
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id$
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* An abstract base class for QuickForm renderers
|
||||
*
|
||||
* The class implements a Visitor design pattern
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @version Release: 3.2.11
|
||||
* @since 3.0
|
||||
* @abstract
|
||||
*/
|
||||
class HTML_QuickForm_Renderer
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function __construct()
|
||||
{
|
||||
} // end constructor
|
||||
|
||||
/**
|
||||
* Called when visiting a form, before processing any form elements
|
||||
*
|
||||
* @param HTML_QuickForm a form being visited
|
||||
* @access public
|
||||
* @return void
|
||||
* @abstract
|
||||
*/
|
||||
function startForm(&$form)
|
||||
{
|
||||
return;
|
||||
} // end func startForm
|
||||
|
||||
/**
|
||||
* Called when visiting a form, after processing all form elements
|
||||
*
|
||||
* @param HTML_QuickForm a form being visited
|
||||
* @access public
|
||||
* @return void
|
||||
* @abstract
|
||||
*/
|
||||
function finishForm(&$form)
|
||||
{
|
||||
return;
|
||||
} // end func finishForm
|
||||
|
||||
/**
|
||||
* Called when visiting a header element
|
||||
*
|
||||
* @param HTML_QuickForm_header a header element being visited
|
||||
* @access public
|
||||
* @return void
|
||||
* @abstract
|
||||
*/
|
||||
function renderHeader(&$header)
|
||||
{
|
||||
return;
|
||||
} // end func renderHeader
|
||||
|
||||
/**
|
||||
* Called when visiting an element
|
||||
*
|
||||
* @param HTML_QuickForm_element form element being visited
|
||||
* @param bool Whether an element is required
|
||||
* @param string An error message associated with an element
|
||||
* @access public
|
||||
* @return void
|
||||
* @abstract
|
||||
*/
|
||||
function renderElement(&$element, $required, $error)
|
||||
{
|
||||
return;
|
||||
} // end func renderElement
|
||||
|
||||
/**
|
||||
* Called when visiting a hidden element
|
||||
*
|
||||
* @param HTML_QuickForm_element a hidden element being visited
|
||||
* @access public
|
||||
* @return void
|
||||
* @abstract
|
||||
*/
|
||||
function renderHidden(&$element)
|
||||
{
|
||||
return;
|
||||
} // end func renderHidden
|
||||
|
||||
/**
|
||||
* Called when visiting a raw HTML/text pseudo-element
|
||||
*
|
||||
* Only implemented in Default renderer. Usage of 'html' elements is
|
||||
* discouraged, templates should be used instead.
|
||||
*
|
||||
* @param HTML_QuickForm_html a 'raw html' element being visited
|
||||
* @access public
|
||||
* @return void
|
||||
* @abstract
|
||||
*/
|
||||
function renderHtml(&$data)
|
||||
{
|
||||
return;
|
||||
} // end func renderHtml
|
||||
|
||||
/**
|
||||
* Called when visiting a group, before processing any group elements
|
||||
*
|
||||
* @param HTML_QuickForm_group A group being visited
|
||||
* @param bool Whether a group is required
|
||||
* @param string An error message associated with a group
|
||||
* @access public
|
||||
* @return void
|
||||
* @abstract
|
||||
*/
|
||||
function startGroup(&$group, $required, $error)
|
||||
{
|
||||
return;
|
||||
} // end func startGroup
|
||||
|
||||
/**
|
||||
* Called when visiting a group, after processing all group elements
|
||||
*
|
||||
* @param HTML_QuickForm_group A group being visited
|
||||
* @access public
|
||||
* @return void
|
||||
* @abstract
|
||||
*/
|
||||
function finishGroup(&$group)
|
||||
{
|
||||
return;
|
||||
} // end func finishGroup
|
||||
} // end class HTML_QuickForm_Renderer
|
||||
?>
|
||||
|
|
@ -0,0 +1,350 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* A concrete renderer for HTML_QuickForm, makes an array of form contents
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @author Thomas Schulz <ths@4bconsult.de>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: Array.php,v 1.11 2009/04/04 21:34:04 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* An abstract base class for QuickForm renderers
|
||||
*/
|
||||
require_once 'HTML/QuickForm/Renderer.php';
|
||||
|
||||
/**
|
||||
* A concrete renderer for HTML_QuickForm, makes an array of form contents
|
||||
*
|
||||
* Based on old HTML_QuickForm::toArray() code.
|
||||
*
|
||||
* The form array structure is the following:
|
||||
* <pre>
|
||||
* array(
|
||||
* 'frozen' => 'whether the form is frozen',
|
||||
* 'javascript' => 'javascript for client-side validation',
|
||||
* 'attributes' => 'attributes for <form> tag',
|
||||
* 'requirednote => 'note about the required elements',
|
||||
* // if we set the option to collect hidden elements
|
||||
* 'hidden' => 'collected html of all hidden elements',
|
||||
* // if there were some validation errors:
|
||||
* 'errors' => array(
|
||||
* '1st element name' => 'Error for the 1st element',
|
||||
* ...
|
||||
* 'nth element name' => 'Error for the nth element'
|
||||
* ),
|
||||
* // if there are no headers in the form:
|
||||
* 'elements' => array(
|
||||
* element_1,
|
||||
* ...
|
||||
* element_N
|
||||
* )
|
||||
* // if there are headers in the form:
|
||||
* 'sections' => array(
|
||||
* array(
|
||||
* 'header' => 'Header text for the first header',
|
||||
* 'name' => 'Header name for the first header',
|
||||
* 'elements' => array(
|
||||
* element_1,
|
||||
* ...
|
||||
* element_K1
|
||||
* )
|
||||
* ),
|
||||
* ...
|
||||
* array(
|
||||
* 'header' => 'Header text for the Mth header',
|
||||
* 'name' => 'Header name for the Mth header',
|
||||
* 'elements' => array(
|
||||
* element_1,
|
||||
* ...
|
||||
* element_KM
|
||||
* )
|
||||
* )
|
||||
* )
|
||||
* );
|
||||
* </pre>
|
||||
*
|
||||
* where element_i is an array of the form:
|
||||
* <pre>
|
||||
* array(
|
||||
* 'name' => 'element name',
|
||||
* 'value' => 'element value',
|
||||
* 'type' => 'type of the element',
|
||||
* 'frozen' => 'whether element is frozen',
|
||||
* 'label' => 'label for the element',
|
||||
* 'required' => 'whether element is required',
|
||||
* 'error' => 'error associated with the element',
|
||||
* 'style' => 'some information about element style (e.g. for Smarty)',
|
||||
* // if element is not a group
|
||||
* 'html' => 'HTML for the element'
|
||||
* // if element is a group
|
||||
* 'separator' => 'separator for group elements',
|
||||
* 'elements' => array(
|
||||
* element_1,
|
||||
* ...
|
||||
* element_N
|
||||
* )
|
||||
* );
|
||||
* </pre>
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @author Thomas Schulz <ths@4bconsult.de>
|
||||
* @version Release: 3.2.11
|
||||
* @since 3.0
|
||||
*/
|
||||
class HTML_QuickForm_Renderer_Array extends HTML_QuickForm_Renderer
|
||||
{
|
||||
/**#@+
|
||||
* @access private
|
||||
*/
|
||||
/**
|
||||
* An array being generated
|
||||
* @var array
|
||||
*/
|
||||
var $_ary;
|
||||
|
||||
/**
|
||||
* Number of sections in the form (i.e. number of headers in it)
|
||||
* @var integer
|
||||
*/
|
||||
var $_sectionCount;
|
||||
|
||||
/**
|
||||
* Current section number
|
||||
* @var integer
|
||||
*/
|
||||
var $_currentSection;
|
||||
|
||||
/**
|
||||
* Array representing current group
|
||||
* @var array
|
||||
*/
|
||||
var $_currentGroup = null;
|
||||
|
||||
/**
|
||||
* Additional style information for different elements
|
||||
* @var array
|
||||
*/
|
||||
var $_elementStyles = array();
|
||||
|
||||
/**
|
||||
* true: collect all hidden elements into string; false: process them as usual form elements
|
||||
* @var bool
|
||||
*/
|
||||
var $_collectHidden = false;
|
||||
|
||||
/**
|
||||
* true: render an array of labels to many labels, $key 0 named 'label', the rest "label_$key"
|
||||
* false: leave labels as defined
|
||||
* @var bool
|
||||
*/
|
||||
var $_staticLabels = false;
|
||||
/**#@-*/
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param bool true: collect all hidden elements into string; false: process them as usual form elements
|
||||
* @param bool true: render an array of labels to many labels, $key 0 to 'label' and the oterh to "label_$key"
|
||||
* @access public
|
||||
*/
|
||||
function __construct($collectHidden = false, $staticLabels = false)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->_collectHidden = $collectHidden;
|
||||
$this->_staticLabels = $staticLabels;
|
||||
} // end constructor
|
||||
|
||||
|
||||
/**
|
||||
* Returns the resultant array
|
||||
*
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
function toArray()
|
||||
{
|
||||
return $this->_ary;
|
||||
}
|
||||
|
||||
|
||||
function startForm(&$form)
|
||||
{
|
||||
$this->_ary = array(
|
||||
'frozen' => $form->isFrozen(),
|
||||
'javascript' => $form->getValidationScript(),
|
||||
'attributes' => $form->getAttributes(true),
|
||||
'requirednote' => $form->getRequiredNote(),
|
||||
'errors' => array()
|
||||
);
|
||||
if ($this->_collectHidden) {
|
||||
$this->_ary['hidden'] = '';
|
||||
}
|
||||
$this->_elementIdx = 1;
|
||||
$this->_currentSection = null;
|
||||
$this->_sectionCount = 0;
|
||||
} // end func startForm
|
||||
|
||||
|
||||
function renderHeader(&$header)
|
||||
{
|
||||
$this->_ary['sections'][$this->_sectionCount] = array(
|
||||
'header' => $header->toHtml(),
|
||||
'name' => $header->getName()
|
||||
);
|
||||
$this->_currentSection = $this->_sectionCount++;
|
||||
} // end func renderHeader
|
||||
|
||||
|
||||
function renderElement(&$element, $required, $error)
|
||||
{
|
||||
$elAry = $this->_elementToArray($element, $required, $error);
|
||||
if (!empty($error)) {
|
||||
$this->_ary['errors'][$elAry['name']] = $error;
|
||||
}
|
||||
$this->_storeArray($elAry);
|
||||
} // end func renderElement
|
||||
|
||||
|
||||
function renderHidden(&$element, $required = FALSE, $error = FALSE)
|
||||
{
|
||||
if ($this->_collectHidden) {
|
||||
// add to error array
|
||||
if (!empty($error)) {
|
||||
$this->_ary['errors']['hidden'] = $error;
|
||||
}
|
||||
$this->_ary['hidden'] .= $element->toHtml() . "\n";
|
||||
} else {
|
||||
$this->renderElement($element, $required, $error);
|
||||
}
|
||||
} // end func renderHidden
|
||||
|
||||
|
||||
function startGroup(&$group, $required, $error)
|
||||
{
|
||||
$this->_currentGroup = $this->_elementToArray($group, $required, $error);
|
||||
if (!empty($error)) {
|
||||
$this->_ary['errors'][$this->_currentGroup['name']] = $error;
|
||||
}
|
||||
} // end func startGroup
|
||||
|
||||
|
||||
function finishGroup(&$group)
|
||||
{
|
||||
$this->_storeArray($this->_currentGroup);
|
||||
$this->_currentGroup = null;
|
||||
} // end func finishGroup
|
||||
|
||||
|
||||
/**
|
||||
* Creates an array representing an element
|
||||
*
|
||||
* @access private
|
||||
* @param HTML_QuickForm_element element being processed
|
||||
* @param bool Whether an element is required
|
||||
* @param string Error associated with the element
|
||||
* @return array
|
||||
*/
|
||||
function _elementToArray(&$element, $required, $error)
|
||||
{
|
||||
$ret = array(
|
||||
'name' => $element->getName(),
|
||||
'value' => $element->getValue(),
|
||||
'type' => $element->getType(),
|
||||
'frozen' => $element->isFrozen(),
|
||||
'required' => $required,
|
||||
'error' => $error
|
||||
);
|
||||
|
||||
$id = $element->getAttribute('id');
|
||||
if ( $id ) {
|
||||
$ret['id'] = $id;
|
||||
}
|
||||
|
||||
// render label(s)
|
||||
$labels = $element->getLabel();
|
||||
if (is_array($labels) && $this->_staticLabels) {
|
||||
foreach($labels as $key => $label) {
|
||||
$key = is_int($key)? $key + 1: $key;
|
||||
if (1 === $key) {
|
||||
$ret['label'] = $label;
|
||||
} else {
|
||||
$ret['label_' . $key] = $label;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$ret['label'] = $labels;
|
||||
}
|
||||
|
||||
// set the style for the element
|
||||
if (isset($this->_elementStyles[$ret['name']])) {
|
||||
$ret['style'] = $this->_elementStyles[$ret['name']];
|
||||
}
|
||||
if ('group' == $ret['type']) {
|
||||
$ret['separator'] = $element->_separator;
|
||||
$ret['elements'] = array();
|
||||
} else {
|
||||
$ret['html'] = $element->toHtml();
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Stores an array representation of an element in the form array
|
||||
*
|
||||
* @access private
|
||||
* @param array Array representation of an element
|
||||
* @return void
|
||||
*/
|
||||
function _storeArray($elAry)
|
||||
{
|
||||
// where should we put this element...
|
||||
if (is_array($this->_currentGroup) && ('group' != $elAry['type'])) {
|
||||
$this->_currentGroup['elements'][] = $elAry;
|
||||
} elseif (isset($this->_currentSection)) {
|
||||
$this->_ary['sections'][$this->_currentSection]['elements'][] = $elAry;
|
||||
} else {
|
||||
$this->_ary['elements'][] = $elAry;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets a style to use for element rendering
|
||||
*
|
||||
* @param mixed element name or array ('element name' => 'style name')
|
||||
* @param string style name if $elementName is not an array
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setElementStyle($elementName, $styleName = null)
|
||||
{
|
||||
if (is_array($elementName)) {
|
||||
$this->_elementStyles = array_merge($this->_elementStyles, $elementName);
|
||||
} else {
|
||||
$this->_elementStyles[$elementName] = $styleName;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
@ -0,0 +1,403 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* A static renderer for HTML_QuickForm, makes an array of form content
|
||||
* useful for a Smarty template
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @author Thomas Schulz <ths@4bconsult.de>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: ArraySmarty.php,v 1.14 2009/04/06 12:02:08 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* A concrete renderer for HTML_QuickForm, makes an array of form contents
|
||||
*/
|
||||
require_once 'HTML/QuickForm/Renderer/Array.php';
|
||||
|
||||
/**
|
||||
* A static renderer for HTML_QuickForm, makes an array of form content
|
||||
* useful for a Smarty template
|
||||
*
|
||||
* Based on old HTML_QuickForm::toArray() code and ITStatic renderer.
|
||||
*
|
||||
* The form array structure is the following:
|
||||
* <pre>
|
||||
* Array (
|
||||
* [frozen] => whether the complete form is frozen'
|
||||
* [javascript] => javascript for client-side validation
|
||||
* [attributes] => attributes for <form> tag
|
||||
* [hidden] => html of all hidden elements
|
||||
* [requirednote] => note about the required elements
|
||||
* [errors] => Array
|
||||
* (
|
||||
* [1st_element_name] => Error for the 1st element
|
||||
* ...
|
||||
* [nth_element_name] => Error for the nth element
|
||||
* )
|
||||
*
|
||||
* [header] => Array
|
||||
* (
|
||||
* [1st_header_name] => Header text for the 1st header
|
||||
* ...
|
||||
* [nth_header_name] => Header text for the nth header
|
||||
* )
|
||||
*
|
||||
* [1st_element_name] => Array for the 1st element
|
||||
* ...
|
||||
* [nth_element_name] => Array for the nth element
|
||||
* </pre>
|
||||
*
|
||||
* where an element array has the form:
|
||||
* <pre>
|
||||
* (
|
||||
* [name] => element name
|
||||
* [value] => element value,
|
||||
* [type] => type of the element
|
||||
* [frozen] => whether element is frozen
|
||||
* [label] => label for the element
|
||||
* [required] => whether element is required
|
||||
* // if element is not a group:
|
||||
* [html] => HTML for the element
|
||||
* // if element is a group:
|
||||
* [separator] => separator for group elements
|
||||
* [1st_gitem_name] => Array for the 1st element in group
|
||||
* ...
|
||||
* [nth_gitem_name] => Array for the nth element in group
|
||||
* )
|
||||
* )
|
||||
* </pre>
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @author Thomas Schulz <ths@4bconsult.de>
|
||||
* @version Release: 3.2.11
|
||||
* @since 3.0
|
||||
*/
|
||||
class HTML_QuickForm_Renderer_ArraySmarty extends HTML_QuickForm_Renderer_Array
|
||||
{
|
||||
/**#@+
|
||||
* @access private
|
||||
*/
|
||||
/**
|
||||
* The Smarty template engine instance
|
||||
* @var object
|
||||
*/
|
||||
var $_tpl = null;
|
||||
|
||||
/**
|
||||
* Current element index
|
||||
* @var integer
|
||||
*/
|
||||
var $_elementIdx = 0;
|
||||
|
||||
/**
|
||||
* The current element index inside a group
|
||||
* @var integer
|
||||
*/
|
||||
var $_groupElementIdx = 0;
|
||||
|
||||
/**
|
||||
* How to handle the required tag for required fields
|
||||
* @var string
|
||||
* @see setRequiredTemplate()
|
||||
*/
|
||||
var $_required = '';
|
||||
|
||||
/**
|
||||
* How to handle error messages in form validation
|
||||
* @var string
|
||||
* @see setErrorTemplate()
|
||||
*/
|
||||
var $_error = '';
|
||||
/**#@-*/
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Smarty reference to the Smarty template engine instance
|
||||
* @param bool true: render an array of labels to many labels, $key 0 to 'label' and the oterh to "label_$key"
|
||||
* @param bool true: collect all hidden elements into string; false: process them as usual form elements
|
||||
* @access public
|
||||
*/
|
||||
function __construct(&$tpl, $staticLabels = false, $collectHidden = true)
|
||||
{
|
||||
parent::__construct($collectHidden, $staticLabels);
|
||||
$this->_tpl =& $tpl;
|
||||
} // end constructor
|
||||
|
||||
/**
|
||||
* Called when visiting a header element
|
||||
*
|
||||
* @param HTML_QuickForm_header header element being visited
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function renderHeader(&$header)
|
||||
{
|
||||
if ($name = $header->getName()) {
|
||||
$this->_ary['header'][$name] = $header->toHtml();
|
||||
} else {
|
||||
$this->_ary['header'][$this->_sectionCount] = $header->toHtml();
|
||||
}
|
||||
$this->_currentSection = $this->_sectionCount++;
|
||||
} // end func renderHeader
|
||||
|
||||
/**
|
||||
* Called when visiting a group, before processing any group elements
|
||||
*
|
||||
* @param HTML_QuickForm_group group being visited
|
||||
* @param bool Whether a group is required
|
||||
* @param string An error message associated with a group
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function startGroup(&$group, $required, $error)
|
||||
{
|
||||
parent::startGroup($group, $required, $error);
|
||||
$this->_groupElementIdx = 1;
|
||||
} // end func startGroup
|
||||
|
||||
/**
|
||||
* Creates an array representing an element containing
|
||||
* the key for storing this
|
||||
*
|
||||
* @access private
|
||||
* @param HTML_QuickForm_element form element being visited
|
||||
* @param bool Whether an element is required
|
||||
* @param string Error associated with the element
|
||||
* @return array
|
||||
*/
|
||||
function _elementToArray(&$element, $required, $error)
|
||||
{
|
||||
$ret = parent::_elementToArray($element, $required, $error);
|
||||
|
||||
if ('group' == $ret['type']) {
|
||||
$ret['html'] = $element->toHtml();
|
||||
// we don't need the elements, see the array structure
|
||||
unset($ret['elements']);
|
||||
}
|
||||
if (($required || $error) && !empty($this->_required)){
|
||||
$this->_renderRequired($ret['label'], $ret['html'], $required, $error);
|
||||
}
|
||||
if ($error && !empty($this->_error)) {
|
||||
$this->_renderError($ret['label'], $ret['html'], $error);
|
||||
$ret['error'] = $error;
|
||||
}
|
||||
// create keys for elements grouped by native group or name
|
||||
if (strstr($ret['name'], '[') or $this->_currentGroup) {
|
||||
// Fix for bug #8123: escape backslashes and quotes to prevent errors
|
||||
// in eval(). The code below seems to handle the case where element
|
||||
// name has unbalanced square brackets. Dunno whether we really
|
||||
// need this after the fix for #8123, but I'm wary of making big
|
||||
// changes to this code.
|
||||
preg_match('/([^]]*)\\[([^]]*)\\]/', $ret['name'], $matches);
|
||||
if (isset($matches[1])) {
|
||||
$sKeysSub = substr_replace($ret['name'], '', 0, strlen($matches[1]));
|
||||
$sKeysSub = str_replace(
|
||||
array('\\', '\'', '[' , ']', '[\'\']'),
|
||||
array('\\\\', '\\\'', '[\'', '\']', '[]' ),
|
||||
$sKeysSub
|
||||
);
|
||||
$sKeys = '[\'' . str_replace(array('\\', '\''), array('\\\\', '\\\''), $matches[1]) . '\']' . $sKeysSub;
|
||||
} else {
|
||||
$sKeys = '[\'' . str_replace(array('\\', '\''), array('\\\\', '\\\''), $ret['name']) . '\']';
|
||||
}
|
||||
// special handling for elements in native groups
|
||||
if ($this->_currentGroup) {
|
||||
// skip unnamed group items unless radios: no name -> no static access
|
||||
// identification: have the same key string as the parent group
|
||||
if ($this->_currentGroup['keys'] == $sKeys and 'radio' != $ret['type']) {
|
||||
return false;
|
||||
}
|
||||
// reduce string of keys by remove leading group keys
|
||||
if (0 === strpos($sKeys, $this->_currentGroup['keys'])) {
|
||||
$sKeys = substr_replace($sKeys, '', 0, strlen($this->_currentGroup['keys']));
|
||||
}
|
||||
}
|
||||
// element without a name
|
||||
} elseif ($ret['name'] == '') {
|
||||
$sKeys = '[\'element_' . $this->_elementIdx . '\']';
|
||||
// other elements
|
||||
} else {
|
||||
$sKeys = '[\'' . str_replace(array('\\', '\''), array('\\\\', '\\\''), $ret['name']) . '\']';
|
||||
}
|
||||
// for radios: add extra key from value
|
||||
if ('radio' == $ret['type'] and substr($sKeys, -2) != '[]') {
|
||||
$sKeys .= '[\'' . str_replace(array('\\', '\''), array('\\\\', '\\\''), $ret['value']) . '\']';
|
||||
}
|
||||
$this->_elementIdx++;
|
||||
$ret['keys'] = $sKeys;
|
||||
return $ret;
|
||||
} // end func _elementToArray
|
||||
|
||||
/**
|
||||
* Stores an array representation of an element in the form array
|
||||
*
|
||||
* @access private
|
||||
* @param array Array representation of an element
|
||||
* @return void
|
||||
*/
|
||||
function _storeArray($elAry)
|
||||
{
|
||||
if ($elAry) {
|
||||
$sKeys = $elAry['keys'];
|
||||
unset($elAry['keys']);
|
||||
// where should we put this element...
|
||||
if (is_array($this->_currentGroup) && ('group' != $elAry['type'])) {
|
||||
$toEval = '$this->_currentGroup' . $sKeys . ' = $elAry;';
|
||||
} else {
|
||||
$toEval = '$this->_ary' . $sKeys . ' = $elAry;';
|
||||
}
|
||||
eval($toEval);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when an element is required
|
||||
*
|
||||
* This method will add the required tag to the element label and/or the element html
|
||||
* such as defined with the method setRequiredTemplate.
|
||||
*
|
||||
* @param string The element label
|
||||
* @param string The element html rendering
|
||||
* @param boolean The element required
|
||||
* @param string The element error
|
||||
* @see setRequiredTemplate()
|
||||
* @access private
|
||||
* @return void
|
||||
*/
|
||||
function _renderRequired(&$label, &$html, &$required, &$error)
|
||||
{
|
||||
$this->_tpl->assign(array(
|
||||
'label' => $label,
|
||||
'html' => $html,
|
||||
'required' => $required,
|
||||
'error' => $error
|
||||
));
|
||||
if (!empty($label) && strpos($this->_required, $this->_tpl->left_delimiter . '$label') !== false) {
|
||||
$label = $this->_tplFetch($this->_required);
|
||||
}
|
||||
if (!empty($html) && strpos($this->_required, $this->_tpl->left_delimiter . '$html') !== false) {
|
||||
$html = $this->_tplFetch($this->_required);
|
||||
}
|
||||
$this->_tpl->clear_assign(array('label', 'html', 'required'));
|
||||
} // end func _renderRequired
|
||||
|
||||
/**
|
||||
* Called when an element has a validation error
|
||||
*
|
||||
* This method will add the error message to the element label or the element html
|
||||
* such as defined with the method setErrorTemplate. If the error placeholder is not found
|
||||
* in the template, the error will be displayed in the form error block.
|
||||
*
|
||||
* @param string The element label
|
||||
* @param string The element html rendering
|
||||
* @param string The element error
|
||||
* @see setErrorTemplate()
|
||||
* @access private
|
||||
* @return void
|
||||
*/
|
||||
function _renderError(&$label, &$html, &$error)
|
||||
{
|
||||
$this->_tpl->assign(array('label' => '', 'html' => '', 'error' => $error));
|
||||
$error = $this->_tplFetch($this->_error);
|
||||
$this->_tpl->assign(array('label' => $label, 'html' => $html));
|
||||
|
||||
if (!empty($label) && strpos($this->_error, $this->_tpl->left_delimiter . '$label') !== false) {
|
||||
$label = $this->_tplFetch($this->_error);
|
||||
} elseif (!empty($html) && strpos($this->_error, $this->_tpl->left_delimiter . '$html') !== false) {
|
||||
$html = $this->_tplFetch($this->_error);
|
||||
}
|
||||
$this->_tpl->clear_assign(array('label', 'html', 'error'));
|
||||
} // end func _renderError
|
||||
|
||||
/**
|
||||
* Process an template sourced in a string with Smarty
|
||||
*
|
||||
* Smarty has no core function to render a template given as a string.
|
||||
* So we use the smarty eval plugin function to do this.
|
||||
*
|
||||
* @param string The template source
|
||||
* @access private
|
||||
* @return void
|
||||
*/
|
||||
function _tplFetch($tplSource)
|
||||
{
|
||||
if (!function_exists('smarty_function_eval')) {
|
||||
require SMARTY_DIR . '/plugins/function.eval.php';
|
||||
}
|
||||
return smarty_function_eval(array('var' => $tplSource), $this->_tpl);
|
||||
}// end func _tplFetch
|
||||
|
||||
/**
|
||||
* Sets the way required elements are rendered
|
||||
*
|
||||
* You can use {$label} or {$html} placeholders to let the renderer know where
|
||||
* where the element label or the element html are positionned according to the
|
||||
* required tag. They will be replaced accordingly with the right value. You
|
||||
* can use the full smarty syntax here, especially a custom modifier for I18N.
|
||||
* For example:
|
||||
* {if $required}<span style="color: red;">*</span>{/if}{$label|translate}
|
||||
* will put a red star in front of the label if the element is required and
|
||||
* translate the label.
|
||||
*
|
||||
*
|
||||
* @param string The required element template
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setRequiredTemplate($template)
|
||||
{
|
||||
$this->_required = $template;
|
||||
} // end func setRequiredTemplate
|
||||
|
||||
/**
|
||||
* Sets the way elements with validation errors are rendered
|
||||
*
|
||||
* You can use {$label} or {$html} placeholders to let the renderer know where
|
||||
* where the element label or the element html are positionned according to the
|
||||
* error message. They will be replaced accordingly with the right value.
|
||||
* The error message will replace the {$error} placeholder.
|
||||
* For example:
|
||||
* {if $error}<span style="color: red;">{$error}</span>{/if}<br />{$html}
|
||||
* will put the error message in red on top of the element html.
|
||||
*
|
||||
* If you want all error messages to be output in the main error block, use
|
||||
* the {$form.errors} part of the rendered array that collects all raw error
|
||||
* messages.
|
||||
*
|
||||
* If you want to place all error messages manually, do not specify {$html}
|
||||
* nor {$label}.
|
||||
*
|
||||
* Groups can have special layouts. With this kind of groups, you have to
|
||||
* place the formated error message manually. In this case, use {$form.group.error}
|
||||
* where you want the formated error message to appear in the form.
|
||||
*
|
||||
* @param string The element error template
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setErrorTemplate($template)
|
||||
{
|
||||
$this->_error = $template;
|
||||
} // end func setErrorTemplate
|
||||
}
|
||||
?>
|
||||
|
|
@ -0,0 +1,489 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* A concrete renderer for HTML_QuickForm, based on QuickForm 2.x built-in one
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id$
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* An abstract base class for QuickForm renderers
|
||||
*/
|
||||
require_once 'HTML/QuickForm/Renderer.php';
|
||||
|
||||
/**
|
||||
* A concrete renderer for HTML_QuickForm, based on QuickForm 2.x built-in one
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @version Release: 3.2.11
|
||||
* @since 3.0
|
||||
*/
|
||||
class HTML_QuickForm_Renderer_Default extends HTML_QuickForm_Renderer
|
||||
{
|
||||
/**
|
||||
* The HTML of the form
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_html;
|
||||
|
||||
/**
|
||||
* Header Template string
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_headerTemplate =
|
||||
"\n\t<tr>\n\t\t<td style=\"white-space: nowrap; background-color: #CCCCCC;\" align=\"left\" valign=\"top\" colspan=\"2\"><b>{header}</b></td>\n\t</tr>";
|
||||
|
||||
/**
|
||||
* Element template string
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_elementTemplate =
|
||||
"\n\t<tr>\n\t\t<td align=\"right\" valign=\"top\"><!-- BEGIN required --><span style=\"color: #ff0000\">*</span><!-- END required --><b>{label}</b></td>\n\t\t<td valign=\"top\" align=\"left\"><!-- BEGIN error --><span style=\"color: #ff0000\">{error}</span><br /><!-- END error -->\t{element}</td>\n\t</tr>";
|
||||
|
||||
/**
|
||||
* Form template string
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_formTemplate =
|
||||
"\n<form{attributes}>\n<div>\n{hidden}<table border=\"0\">\n{content}\n</table>\n</div>\n</form>";
|
||||
|
||||
/**
|
||||
* Required Note template string
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_requiredNoteTemplate =
|
||||
"\n\t<tr>\n\t\t<td></td>\n\t<td align=\"left\" valign=\"top\">{requiredNote}</td>\n\t</tr>";
|
||||
|
||||
/**
|
||||
* Array containing the templates for customised elements
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_templates = array();
|
||||
|
||||
/**
|
||||
* Array containing the templates for group wraps.
|
||||
*
|
||||
* These templates are wrapped around group elements and groups' own
|
||||
* templates wrap around them. This is set by setGroupTemplate().
|
||||
*
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_groupWraps = array();
|
||||
|
||||
/**
|
||||
* Array containing the templates for elements within groups
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_groupTemplates = array();
|
||||
|
||||
/**
|
||||
* True if we are inside a group
|
||||
* @var bool
|
||||
* @access private
|
||||
*/
|
||||
var $_inGroup = false;
|
||||
|
||||
/**
|
||||
* Array with HTML generated for group elements
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_groupElements = array();
|
||||
|
||||
/**
|
||||
* Template for an element inside a group
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_groupElementTemplate = '';
|
||||
|
||||
/**
|
||||
* HTML that wraps around the group elements
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_groupWrap = '';
|
||||
|
||||
/**
|
||||
* HTML for the current group
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_groupTemplate = '';
|
||||
|
||||
/**
|
||||
* Collected HTML of the hidden fields
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_hiddenHtml = '';
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
} // end constructor
|
||||
|
||||
/**
|
||||
* returns the HTML generated for the form
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function toHtml()
|
||||
{
|
||||
// _hiddenHtml is cleared in finishForm(), so this only matters when
|
||||
// finishForm() was not called (e.g. group::toHtml(), bug #3511)
|
||||
return $this->_hiddenHtml . $this->_html;
|
||||
} // end func toHtml
|
||||
|
||||
/**
|
||||
* Called when visiting a form, before processing any form elements
|
||||
*
|
||||
* @param HTML_QuickForm form object being visited
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function startForm(&$form)
|
||||
{
|
||||
$this->_html = '';
|
||||
$this->_hiddenHtml = '';
|
||||
} // end func startForm
|
||||
|
||||
/**
|
||||
* Called when visiting a form, after processing all form elements
|
||||
* Adds required note, form attributes, validation javascript and form content.
|
||||
*
|
||||
* @param HTML_QuickForm form object being visited
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function finishForm(&$form)
|
||||
{
|
||||
// add a required note, if one is needed
|
||||
if (!empty($form->_required) && !$form->_freezeAll) {
|
||||
$this->_html .= str_replace('{requiredNote}', $form->getRequiredNote(), $this->_requiredNoteTemplate);
|
||||
}
|
||||
// add form attributes and content
|
||||
$html = str_replace('{attributes}', $form->getAttributes(true), $this->_formTemplate);
|
||||
if (strpos($this->_formTemplate, '{hidden}')) {
|
||||
$html = str_replace('{hidden}', $this->_hiddenHtml, $html);
|
||||
} else {
|
||||
$this->_html .= $this->_hiddenHtml;
|
||||
}
|
||||
$this->_hiddenHtml = '';
|
||||
$this->_html = str_replace('{content}', $this->_html, $html);
|
||||
// add a validation script
|
||||
if ('' != ($script = $form->getValidationScript())) {
|
||||
$this->_html = $script . "\n" . $this->_html;
|
||||
}
|
||||
} // end func finishForm
|
||||
|
||||
/**
|
||||
* Called when visiting a header element
|
||||
*
|
||||
* @param HTML_QuickForm_header header element being visited
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function renderHeader(&$header)
|
||||
{
|
||||
$name = $header->getName();
|
||||
if (!empty($name) && isset($this->_templates[$name])) {
|
||||
$this->_html .= str_replace('{header}', $header->toHtml(), $this->_templates[$name]);
|
||||
} else {
|
||||
$this->_html .= str_replace('{header}', $header->toHtml(), $this->_headerTemplate);
|
||||
}
|
||||
} // end func renderHeader
|
||||
|
||||
/**
|
||||
* Helper method for renderElement
|
||||
*
|
||||
* @param string Element name
|
||||
* @param mixed Element label (if using an array of labels, you should set the appropriate template)
|
||||
* @param bool Whether an element is required
|
||||
* @param string Error message associated with the element
|
||||
* @access private
|
||||
* @see renderElement()
|
||||
* @return string Html for element
|
||||
*/
|
||||
function _prepareTemplate($name, $label, $required, $error)
|
||||
{
|
||||
if (is_array($label)) {
|
||||
$nameLabel = array_shift($label);
|
||||
} else {
|
||||
$nameLabel = $label;
|
||||
}
|
||||
if (isset($this->_templates[$name])) {
|
||||
$html = str_replace('{label}', $nameLabel, $this->_templates[$name]);
|
||||
} else {
|
||||
$html = str_replace('{label}', $nameLabel, $this->_elementTemplate);
|
||||
}
|
||||
if ($required) {
|
||||
$html = str_replace('<!-- BEGIN required -->', '', $html);
|
||||
$html = str_replace('<!-- END required -->', '', $html);
|
||||
} else {
|
||||
$html = preg_replace("/([ \t\n\r]*)?<!-- BEGIN required -->.*<!-- END required -->([ \t\n\r]*)?/isU", '', $html);
|
||||
}
|
||||
if (isset($error)) {
|
||||
$html = str_replace('{error}', $error, $html);
|
||||
$html = str_replace('<!-- BEGIN error -->', '', $html);
|
||||
$html = str_replace('<!-- END error -->', '', $html);
|
||||
} else {
|
||||
$html = preg_replace("/([ \t\n\r]*)?<!-- BEGIN error -->.*<!-- END error -->([ \t\n\r]*)?/isU", '', $html);
|
||||
}
|
||||
if (is_array($label)) {
|
||||
foreach($label as $key => $text) {
|
||||
$key = is_int($key)? $key + 2: $key;
|
||||
$html = str_replace("{label_{$key}}", $text, $html);
|
||||
$html = str_replace("<!-- BEGIN label_{$key} -->", '', $html);
|
||||
$html = str_replace("<!-- END label_{$key} -->", '', $html);
|
||||
}
|
||||
}
|
||||
if (strpos($html, '{label_')) {
|
||||
$html = preg_replace('/\s*<!-- BEGIN label_(\S+) -->.*<!-- END label_\1 -->\s*/is', '', $html);
|
||||
}
|
||||
return $html;
|
||||
} // end func _prepareTemplate
|
||||
|
||||
/**
|
||||
* Renders an element Html
|
||||
* Called when visiting an element
|
||||
*
|
||||
* @param HTML_QuickForm_element form element being visited
|
||||
* @param bool Whether an element is required
|
||||
* @param string An error message associated with an element
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function renderElement(&$element, $required, $error)
|
||||
{
|
||||
// make sure that all elements are id'ed even in a group!
|
||||
|
||||
CRM_Core_Form_Renderer::updateAttributes( $element, $required, $error );
|
||||
|
||||
if (!$this->_inGroup) {
|
||||
$html = $this->_prepareTemplate($element->getName(), $element->getLabel(), $required, $error);
|
||||
$this->_html .= str_replace('{element}', $element->toHtml(), $html);
|
||||
|
||||
} elseif (!empty($this->_groupElementTemplate)) {
|
||||
$html = str_replace('{label}', $element->getLabel(), $this->_groupElementTemplate);
|
||||
if ($required) {
|
||||
$html = str_replace('<!-- BEGIN required -->', '', $html);
|
||||
$html = str_replace('<!-- END required -->', '', $html);
|
||||
} else {
|
||||
$html = preg_replace("/([ \t\n\r]*)?<!-- BEGIN required -->.*<!-- END required -->([ \t\n\r]*)?/isU", '', $html);
|
||||
}
|
||||
$this->_groupElements[] = str_replace('{element}', $element->toHtml(), $html);
|
||||
|
||||
} else {
|
||||
$this->_groupElements[] = $element->toHtml();
|
||||
}
|
||||
} // end func renderElement
|
||||
|
||||
/**
|
||||
* Renders an hidden element
|
||||
* Called when visiting a hidden element
|
||||
*
|
||||
* @param HTML_QuickForm_element form element being visited
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function renderHidden(&$element)
|
||||
{
|
||||
$this->_hiddenHtml .= $element->toHtml() . "\n";
|
||||
} // end func renderHidden
|
||||
|
||||
/**
|
||||
* Called when visiting a raw HTML/text pseudo-element
|
||||
*
|
||||
* @param HTML_QuickForm_html element being visited
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function renderHtml(&$data)
|
||||
{
|
||||
$this->_html .= $data->toHtml();
|
||||
} // end func renderHtml
|
||||
|
||||
/**
|
||||
* Called when visiting a group, before processing any group elements
|
||||
*
|
||||
* @param HTML_QuickForm_group group being visited
|
||||
* @param bool Whether a group is required
|
||||
* @param string An error message associated with a group
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function startGroup(&$group, $required, $error)
|
||||
{
|
||||
$name = $group->getName();
|
||||
$this->_groupTemplate = $this->_prepareTemplate($name, $group->getLabel(), $required, $error);
|
||||
$this->_groupElementTemplate = empty($this->_groupTemplates[$name])? '': $this->_groupTemplates[$name];
|
||||
$this->_groupWrap = empty($this->_groupWraps[$name])? '': $this->_groupWraps[$name];
|
||||
$this->_groupElements = array();
|
||||
$this->_inGroup = true;
|
||||
} // end func startGroup
|
||||
|
||||
/**
|
||||
* Called when visiting a group, after processing all group elements
|
||||
*
|
||||
* @param HTML_QuickForm_group group being visited
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function finishGroup(&$group)
|
||||
{
|
||||
$separator = $group->_separator;
|
||||
if (is_array($separator)) {
|
||||
$count = count($separator);
|
||||
$html = '';
|
||||
for ($i = 0; $i < count($this->_groupElements); $i++) {
|
||||
$html .= (0 == $i? '': $separator[($i - 1) % $count]) . $this->_groupElements[$i];
|
||||
}
|
||||
} else {
|
||||
if (is_null($separator)) {
|
||||
$separator = ' ';
|
||||
}
|
||||
$html = implode((string)$separator, $this->_groupElements);
|
||||
}
|
||||
if (!empty($this->_groupWrap)) {
|
||||
$html = str_replace('{content}', $html, $this->_groupWrap);
|
||||
}
|
||||
$this->_html .= str_replace('{element}', $html, $this->_groupTemplate);
|
||||
$this->_inGroup = false;
|
||||
} // end func finishGroup
|
||||
|
||||
/**
|
||||
* Sets element template
|
||||
*
|
||||
* @param string The HTML surrounding an element
|
||||
* @param string (optional) Name of the element to apply template for
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setElementTemplate($html, $element = null)
|
||||
{
|
||||
if (is_null($element)) {
|
||||
$this->_elementTemplate = $html;
|
||||
} else {
|
||||
$this->_templates[$element] = $html;
|
||||
}
|
||||
} // end func setElementTemplate
|
||||
|
||||
|
||||
/**
|
||||
* Sets template for a group wrapper
|
||||
*
|
||||
* This template is contained within a group-as-element template
|
||||
* set via setTemplate() and contains group's element templates, set
|
||||
* via setGroupElementTemplate()
|
||||
*
|
||||
* @param string The HTML surrounding group elements
|
||||
* @param string Name of the group to apply template for
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setGroupTemplate($html, $group)
|
||||
{
|
||||
$this->_groupWraps[$group] = $html;
|
||||
} // end func setGroupTemplate
|
||||
|
||||
/**
|
||||
* Sets element template for elements within a group
|
||||
*
|
||||
* @param string The HTML surrounding an element
|
||||
* @param string Name of the group to apply template for
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setGroupElementTemplate($html, $group)
|
||||
{
|
||||
$this->_groupTemplates[$group] = $html;
|
||||
} // end func setGroupElementTemplate
|
||||
|
||||
/**
|
||||
* Sets header template
|
||||
*
|
||||
* @param string The HTML surrounding the header
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setHeaderTemplate($html)
|
||||
{
|
||||
$this->_headerTemplate = $html;
|
||||
} // end func setHeaderTemplate
|
||||
|
||||
/**
|
||||
* Sets form template
|
||||
*
|
||||
* @param string The HTML surrounding the form tags
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setFormTemplate($html)
|
||||
{
|
||||
$this->_formTemplate = $html;
|
||||
} // end func setFormTemplate
|
||||
|
||||
/**
|
||||
* Sets the note indicating required fields template
|
||||
*
|
||||
* @param string The HTML surrounding the required note
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setRequiredNoteTemplate($html)
|
||||
{
|
||||
$this->_requiredNoteTemplate = $html;
|
||||
} // end func setRequiredNoteTemplate
|
||||
|
||||
/**
|
||||
* Clears all the HTML out of the templates that surround notes, elements, etc.
|
||||
* Useful when you want to use addData() to create a completely custom form look
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function clearAllTemplates()
|
||||
{
|
||||
$this->setElementTemplate('{element}');
|
||||
$this->setFormTemplate("\n\t<form{attributes}>{content}\n\t</form>\n");
|
||||
$this->setRequiredNoteTemplate('');
|
||||
$this->_templates = array();
|
||||
} // end func clearAllTemplates
|
||||
} // end class HTML_QuickForm_Renderer_Default
|
||||
?>
|
||||
|
|
@ -0,0 +1,300 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* A concrete renderer for HTML_QuickForm, using Integrated Templates.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: ITDynamic.php,v 1.7 2009/04/04 21:34:04 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* An abstract base class for QuickForm renderers
|
||||
*/
|
||||
require_once 'HTML/QuickForm/Renderer.php';
|
||||
|
||||
/**
|
||||
* A concrete renderer for HTML_QuickForm, using Integrated Templates.
|
||||
*
|
||||
* This is a "dynamic" renderer, which means that concrete form look
|
||||
* is defined at runtime. This also means that you can define
|
||||
* <b>one</b> template file for <b>all</b> your forms. That template
|
||||
* should contain a block for every element 'look' appearing in your
|
||||
* forms and also some special blocks (consult the examples). If a
|
||||
* special block is not set for an element, the renderer falls back to
|
||||
* a default one.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @version Release: 3.2.11
|
||||
* @since 3.0
|
||||
*/
|
||||
class HTML_QuickForm_Renderer_ITDynamic extends HTML_QuickForm_Renderer
|
||||
{
|
||||
/**#@+
|
||||
* @access private
|
||||
*/
|
||||
/**
|
||||
* A template class (HTML_Template_ITX or HTML_Template_Sigma) instance
|
||||
* @var HTML_Template_ITX|HTML_Template_Sigma
|
||||
*/
|
||||
var $_tpl = null;
|
||||
|
||||
/**
|
||||
* The errors that were not shown near concrete fields go here
|
||||
* @var array
|
||||
*/
|
||||
var $_errors = array();
|
||||
|
||||
/**
|
||||
* Show the block with required note?
|
||||
* @var bool
|
||||
*/
|
||||
var $_showRequired = false;
|
||||
|
||||
/**
|
||||
* A separator for group elements
|
||||
* @var mixed
|
||||
*/
|
||||
var $_groupSeparator = null;
|
||||
|
||||
/**
|
||||
* The current element index inside a group
|
||||
* @var integer
|
||||
*/
|
||||
var $_groupElementIdx = 0;
|
||||
|
||||
/**
|
||||
* Blocks to use for different elements
|
||||
* @var array
|
||||
*/
|
||||
var $_elementBlocks = array();
|
||||
|
||||
/**
|
||||
* Block to use for headers
|
||||
* @var string
|
||||
*/
|
||||
var $_headerBlock = null;
|
||||
/**#@-*/
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param HTML_Template_ITX|HTML_Template_Sigma Template object to use
|
||||
*/
|
||||
function __construct(&$tpl)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->_tpl =& $tpl;
|
||||
$this->_tpl->setCurrentBlock('qf_main_loop');
|
||||
}
|
||||
|
||||
|
||||
function finishForm(&$form)
|
||||
{
|
||||
// display errors above form
|
||||
if (!empty($this->_errors) && $this->_tpl->blockExists('qf_error_loop')) {
|
||||
foreach ($this->_errors as $error) {
|
||||
$this->_tpl->setVariable('qf_error', $error);
|
||||
$this->_tpl->parse('qf_error_loop');
|
||||
}
|
||||
}
|
||||
// show required note
|
||||
if ($this->_showRequired) {
|
||||
$this->_tpl->setVariable('qf_required_note', $form->getRequiredNote());
|
||||
}
|
||||
// assign form attributes
|
||||
$this->_tpl->setVariable('qf_attributes', $form->getAttributes(true));
|
||||
// assign javascript validation rules
|
||||
$this->_tpl->setVariable('qf_javascript', $form->getValidationScript());
|
||||
}
|
||||
|
||||
|
||||
function renderHeader(&$header)
|
||||
{
|
||||
$blockName = $this->_matchBlock($header);
|
||||
if ('qf_header' == $blockName && isset($this->_headerBlock)) {
|
||||
$blockName = $this->_headerBlock;
|
||||
}
|
||||
$this->_tpl->setVariable('qf_header', $header->toHtml());
|
||||
$this->_tpl->parse($blockName);
|
||||
$this->_tpl->parse('qf_main_loop');
|
||||
}
|
||||
|
||||
|
||||
function renderElement(&$element, $required, $error)
|
||||
{
|
||||
$blockName = $this->_matchBlock($element);
|
||||
// are we inside a group?
|
||||
if ('qf_main_loop' != $this->_tpl->currentBlock) {
|
||||
if (0 != $this->_groupElementIdx && $this->_tpl->placeholderExists('qf_separator', $blockName)) {
|
||||
if (is_array($this->_groupSeparator)) {
|
||||
$this->_tpl->setVariable('qf_separator', $this->_groupSeparator[($this->_groupElementIdx - 1) % count($this->_groupSeparator)]);
|
||||
} else {
|
||||
$this->_tpl->setVariable('qf_separator', (string)$this->_groupSeparator);
|
||||
}
|
||||
}
|
||||
$this->_groupElementIdx++;
|
||||
|
||||
} elseif(!empty($error)) {
|
||||
// show the error message or keep it for later use
|
||||
if ($this->_tpl->blockExists($blockName . '_error')) {
|
||||
$this->_tpl->setVariable('qf_error', $error);
|
||||
} else {
|
||||
$this->_errors[] = $error;
|
||||
}
|
||||
}
|
||||
// show an '*' near the required element
|
||||
if ($required) {
|
||||
$this->_showRequired = true;
|
||||
if ($this->_tpl->blockExists($blockName . '_required')) {
|
||||
$this->_tpl->touchBlock($blockName . '_required');
|
||||
}
|
||||
}
|
||||
// Prepare multiple labels
|
||||
$labels = $element->getLabel();
|
||||
if (is_array($labels)) {
|
||||
$mainLabel = array_shift($labels);
|
||||
} else {
|
||||
$mainLabel = $labels;
|
||||
}
|
||||
// render the element itself with its main label
|
||||
$this->_tpl->setVariable('qf_element', $element->toHtml());
|
||||
if ($this->_tpl->placeholderExists('qf_label', $blockName)) {
|
||||
$this->_tpl->setVariable('qf_label', $mainLabel);
|
||||
}
|
||||
// render extra labels, if any
|
||||
if (is_array($labels)) {
|
||||
foreach($labels as $key => $label) {
|
||||
$key = is_int($key)? $key + 2: $key;
|
||||
if ($this->_tpl->blockExists($blockName . '_label_' . $key)) {
|
||||
$this->_tpl->setVariable('qf_label_' . $key, $label);
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->_tpl->parse($blockName);
|
||||
$this->_tpl->parseCurrentBlock();
|
||||
}
|
||||
|
||||
|
||||
function renderHidden(&$element)
|
||||
{
|
||||
$this->_tpl->setVariable('qf_hidden', $element->toHtml());
|
||||
$this->_tpl->parse('qf_hidden_loop');
|
||||
}
|
||||
|
||||
|
||||
function startGroup(&$group, $required, $error)
|
||||
{
|
||||
$blockName = $this->_matchBlock($group);
|
||||
$this->_tpl->setCurrentBlock($blockName . '_loop');
|
||||
$this->_groupElementIdx = 0;
|
||||
$this->_groupSeparator = is_null($group->_separator)? ' ': $group->_separator;
|
||||
// show an '*' near the required element
|
||||
if ($required) {
|
||||
$this->_showRequired = true;
|
||||
if ($this->_tpl->blockExists($blockName . '_required')) {
|
||||
$this->_tpl->touchBlock($blockName . '_required');
|
||||
}
|
||||
}
|
||||
// show the error message or keep it for later use
|
||||
if (!empty($error)) {
|
||||
if ($this->_tpl->blockExists($blockName . '_error')) {
|
||||
$this->_tpl->setVariable('qf_error', $error);
|
||||
} else {
|
||||
$this->_errors[] = $error;
|
||||
}
|
||||
}
|
||||
$this->_tpl->setVariable('qf_group_label', $group->getLabel());
|
||||
}
|
||||
|
||||
|
||||
function finishGroup(&$group)
|
||||
{
|
||||
$this->_tpl->parse($this->_matchBlock($group));
|
||||
$this->_tpl->setCurrentBlock('qf_main_loop');
|
||||
$this->_tpl->parseCurrentBlock();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the name of a block to use for element rendering
|
||||
*
|
||||
* If a name was not explicitly set via setElementBlock(), it tries
|
||||
* the names '{prefix}_{element type}' and '{prefix}_{element}', where
|
||||
* prefix is either 'qf' or the name of the current group's block
|
||||
*
|
||||
* @param HTML_QuickForm_element form element being rendered
|
||||
* @access private
|
||||
* @return string block name
|
||||
*/
|
||||
function _matchBlock(&$element)
|
||||
{
|
||||
$name = $element->getName();
|
||||
$type = $element->getType();
|
||||
if (isset($this->_elementBlocks[$name]) && $this->_tpl->blockExists($this->_elementBlocks[$name])) {
|
||||
if (('group' == $type) || ($this->_elementBlocks[$name] . '_loop' != $this->_tpl->currentBlock)) {
|
||||
return $this->_elementBlocks[$name];
|
||||
}
|
||||
}
|
||||
if ('group' != $type && 'qf_main_loop' != $this->_tpl->currentBlock) {
|
||||
$prefix = substr($this->_tpl->currentBlock, 0, -5); // omit '_loop' postfix
|
||||
} else {
|
||||
$prefix = 'qf';
|
||||
}
|
||||
if ($this->_tpl->blockExists($prefix . '_' . $type)) {
|
||||
return $prefix . '_' . $type;
|
||||
} elseif ($this->_tpl->blockExists($prefix . '_' . $name)) {
|
||||
return $prefix . '_' . $name;
|
||||
} else {
|
||||
return $prefix . '_element';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the block to use for element rendering
|
||||
*
|
||||
* @param mixed element name or array ('element name' => 'block name')
|
||||
* @param string block name if $elementName is not an array
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setElementBlock($elementName, $blockName = null)
|
||||
{
|
||||
if (is_array($elementName)) {
|
||||
$this->_elementBlocks = array_merge($this->_elementBlocks, $elementName);
|
||||
} else {
|
||||
$this->_elementBlocks[$elementName] = $blockName;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the name of a block to use for header rendering
|
||||
*
|
||||
* @param string block name
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setHeaderBlock($blockName)
|
||||
{
|
||||
$this->_headerBlock = $blockName;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
@ -0,0 +1,504 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* A static renderer for HTML_QuickForm compatible
|
||||
* with HTML_Template_IT and HTML_Template_Sigma.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: ITStatic.php,v 1.9 2009/04/04 21:34:04 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* An abstract base class for QuickForm renderers
|
||||
*/
|
||||
require_once 'HTML/QuickForm/Renderer.php';
|
||||
|
||||
/**
|
||||
* A static renderer for HTML_QuickForm compatible
|
||||
* with HTML_Template_IT and HTML_Template_Sigma.
|
||||
*
|
||||
* As opposed to the dynamic renderer, this renderer needs
|
||||
* every elements and labels in the form to be specified by
|
||||
* placeholders at the position you want them to be displayed.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @version Release: 3.2.11
|
||||
* @since 3.0
|
||||
*/
|
||||
class HTML_QuickForm_Renderer_ITStatic extends HTML_QuickForm_Renderer
|
||||
{
|
||||
/**#@+
|
||||
* @access private
|
||||
*/
|
||||
/**
|
||||
* An HTML_Template_IT or some other API compatible Template instance
|
||||
* @var object
|
||||
*/
|
||||
var $_tpl = null;
|
||||
|
||||
/**
|
||||
* Rendered form name
|
||||
* @var string
|
||||
*/
|
||||
var $_formName = 'form';
|
||||
|
||||
/**
|
||||
* The errors that were not shown near concrete fields go here
|
||||
* @var array
|
||||
*/
|
||||
var $_errors = array();
|
||||
|
||||
/**
|
||||
* Show the block with required note?
|
||||
* @var bool
|
||||
*/
|
||||
var $_showRequired = false;
|
||||
|
||||
/**
|
||||
* Which group are we currently parsing ?
|
||||
* @var string
|
||||
*/
|
||||
var $_inGroup;
|
||||
|
||||
/**
|
||||
* Index of the element in its group
|
||||
* @var int
|
||||
*/
|
||||
var $_elementIndex = 0;
|
||||
|
||||
/**
|
||||
* If elements have been added with the same name
|
||||
* @var array
|
||||
*/
|
||||
var $_duplicateElements = array();
|
||||
|
||||
/**
|
||||
* How to handle the required tag for required fields
|
||||
* @var string
|
||||
*/
|
||||
var $_required = '{label}<font size="1" color="red">*</font>';
|
||||
|
||||
/**
|
||||
* How to handle error messages in form validation
|
||||
* @var string
|
||||
*/
|
||||
var $_error = '<font color="red">{error}</font><br />{html}';
|
||||
|
||||
/**
|
||||
* Collected HTML for hidden elements, if needed
|
||||
* @var string
|
||||
*/
|
||||
var $_hidden = '';
|
||||
/**#@-*/
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param HTML_Template_IT|HTML_Template_Sigma Template object to use
|
||||
*/
|
||||
function __construct(&$tpl)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->_tpl =& $tpl;
|
||||
} // end constructor
|
||||
|
||||
/**
|
||||
* Called when visiting a form, before processing any form elements
|
||||
*
|
||||
* @param HTML_QuickForm form object being visited
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function startForm(&$form)
|
||||
{
|
||||
$this->_formName = $form->getAttribute('id');
|
||||
|
||||
if (count($form->_duplicateIndex) > 0) {
|
||||
// Take care of duplicate elements
|
||||
foreach ($form->_duplicateIndex as $elementName => $indexes) {
|
||||
$this->_duplicateElements[$elementName] = 0;
|
||||
}
|
||||
}
|
||||
} // end func startForm
|
||||
|
||||
/**
|
||||
* Called when visiting a form, after processing all form elements
|
||||
*
|
||||
* @param HTML_QuickForm form object being visited
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function finishForm(&$form)
|
||||
{
|
||||
// display errors above form
|
||||
if (!empty($this->_errors) && $this->_tpl->blockExists($this->_formName.'_error_loop')) {
|
||||
foreach ($this->_errors as $error) {
|
||||
$this->_tpl->setVariable($this->_formName.'_error', $error);
|
||||
$this->_tpl->parse($this->_formName.'_error_loop');
|
||||
}
|
||||
}
|
||||
// show required note
|
||||
if ($this->_showRequired) {
|
||||
$this->_tpl->setVariable($this->_formName.'_required_note', $form->getRequiredNote());
|
||||
}
|
||||
// add hidden elements, if collected
|
||||
if (!empty($this->_hidden)) {
|
||||
$this->_tpl->setVariable($this->_formName . '_hidden', $this->_hidden);
|
||||
}
|
||||
// assign form attributes
|
||||
$this->_tpl->setVariable($this->_formName.'_attributes', $form->getAttributes(true));
|
||||
// assign javascript validation rules
|
||||
$this->_tpl->setVariable($this->_formName.'_javascript', $form->getValidationScript());
|
||||
} // end func finishForm
|
||||
|
||||
/**
|
||||
* Called when visiting a header element
|
||||
*
|
||||
* @param HTML_QuickForm_header header element being visited
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function renderHeader(&$header)
|
||||
{
|
||||
$name = $header->getName();
|
||||
$varName = $this->_formName.'_header';
|
||||
|
||||
// Find placeHolder
|
||||
if (!empty($name) && $this->_tpl->placeHolderExists($this->_formName.'_header_'.$name)) {
|
||||
$varName = $this->_formName.'_header_'.$name;
|
||||
}
|
||||
$this->_tpl->setVariable($varName, $header->toHtml());
|
||||
} // end func renderHeader
|
||||
|
||||
/**
|
||||
* Called when visiting an element
|
||||
*
|
||||
* @param HTML_QuickForm_element form element being visited
|
||||
* @param bool Whether an element is required
|
||||
* @param string An error message associated with an element
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function renderElement(&$element, $required, $error)
|
||||
{
|
||||
$name = $element->getName();
|
||||
|
||||
// are we inside a group?
|
||||
if (!empty($this->_inGroup)) {
|
||||
$varName = $this->_formName.'_'.str_replace(array('[', ']'), '_', $name);
|
||||
if (substr($varName, -2) == '__') {
|
||||
// element name is of type : group[]
|
||||
$varName = $this->_inGroup.'_'.$this->_elementIndex.'_';
|
||||
$this->_elementIndex++;
|
||||
}
|
||||
if ($varName != $this->_inGroup) {
|
||||
$varName .= '_' == substr($varName, -1)? '': '_';
|
||||
// element name is of type : group[name]
|
||||
$label = $element->getLabel();
|
||||
$html = $element->toHtml();
|
||||
|
||||
if ($required && !$element->isFrozen()) {
|
||||
$this->_renderRequired($label, $html);
|
||||
$this->_showRequired = true;
|
||||
}
|
||||
if (!empty($label)) {
|
||||
if (is_array($label)) {
|
||||
foreach ($label as $key => $value) {
|
||||
$this->_tpl->setVariable($varName.'label_'.$key, $value);
|
||||
}
|
||||
} else {
|
||||
$this->_tpl->setVariable($varName.'label', $label);
|
||||
}
|
||||
}
|
||||
$this->_tpl->setVariable($varName.'html', $html);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
$name = str_replace(array('[', ']'), array('_', ''), $name);
|
||||
|
||||
if (isset($this->_duplicateElements[$name])) {
|
||||
// Element is a duplicate
|
||||
$varName = $this->_formName.'_'.$name.'_'.$this->_duplicateElements[$name];
|
||||
$this->_duplicateElements[$name]++;
|
||||
} else {
|
||||
$varName = $this->_formName.'_'.$name;
|
||||
}
|
||||
|
||||
$label = $element->getLabel();
|
||||
$html = $element->toHtml();
|
||||
|
||||
if ($required) {
|
||||
$this->_showRequired = true;
|
||||
$this->_renderRequired($label, $html);
|
||||
}
|
||||
if (!empty($error)) {
|
||||
$this->_renderError($label, $html, $error);
|
||||
}
|
||||
if (is_array($label)) {
|
||||
foreach ($label as $key => $value) {
|
||||
$this->_tpl->setVariable($varName.'_label_'.$key, $value);
|
||||
}
|
||||
} else {
|
||||
$this->_tpl->setVariable($varName.'_label', $label);
|
||||
}
|
||||
$this->_tpl->setVariable($varName.'_html', $html);
|
||||
}
|
||||
} // end func renderElement
|
||||
|
||||
/**
|
||||
* Called when visiting a hidden element
|
||||
*
|
||||
* @param HTML_QuickForm_element hidden element being visited
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function renderHidden(&$element)
|
||||
{
|
||||
if ($this->_tpl->placeholderExists($this->_formName . '_hidden')) {
|
||||
$this->_hidden .= $element->toHtml();
|
||||
} else {
|
||||
$name = $element->getName();
|
||||
$name = str_replace(array('[', ']'), array('_', ''), $name);
|
||||
$this->_tpl->setVariable($this->_formName.'_'.$name.'_html', $element->toHtml());
|
||||
}
|
||||
} // end func renderHidden
|
||||
|
||||
/**
|
||||
* Called when visiting a group, before processing any group elements
|
||||
*
|
||||
* @param HTML_QuickForm_group group being visited
|
||||
* @param bool Whether a group is required
|
||||
* @param string An error message associated with a group
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function startGroup(&$group, $required, $error)
|
||||
{
|
||||
$name = $group->getName();
|
||||
$varName = $this->_formName.'_'.$name;
|
||||
|
||||
$this->_elementIndex = 0;
|
||||
|
||||
$html = $this->_tpl->placeholderExists($varName.'_html') ? $group->toHtml() : '';
|
||||
$label = $group->getLabel();
|
||||
|
||||
if ($required) {
|
||||
$this->_renderRequired($label, $html);
|
||||
}
|
||||
if (!empty($error)) {
|
||||
$this->_renderError($label, $html, $error);
|
||||
}
|
||||
if (!empty($html)) {
|
||||
$this->_tpl->setVariable($varName.'_html', $html);
|
||||
} else {
|
||||
// Uses error blocks to set the special groups layout error
|
||||
// <!-- BEGIN form_group_error -->{form_group_error}<!-- END form_group_error -->
|
||||
if (!empty($error)) {
|
||||
if ($this->_tpl->placeholderExists($varName.'_error')) {
|
||||
if ($this->_tpl->blockExists($this->_formName . '_error_block')) {
|
||||
$this->_tpl->setVariable($this->_formName . '_error', $error);
|
||||
$error = $this->_getTplBlock($this->_formName . '_error_block');
|
||||
} elseif (strpos($this->_error, '{html}') !== false || strpos($this->_error, '{label}') !== false) {
|
||||
$error = str_replace('{error}', $error, $this->_error);
|
||||
}
|
||||
}
|
||||
$this->_tpl->setVariable($varName . '_error', $error);
|
||||
array_pop($this->_errors);
|
||||
}
|
||||
}
|
||||
if (is_array($label)) {
|
||||
foreach ($label as $key => $value) {
|
||||
$this->_tpl->setVariable($varName.'_label_'.$key, $value);
|
||||
}
|
||||
} else {
|
||||
$this->_tpl->setVariable($varName.'_label', $label);
|
||||
}
|
||||
$this->_inGroup = $varName;
|
||||
} // end func startGroup
|
||||
|
||||
/**
|
||||
* Called when visiting a group, after processing all group elements
|
||||
*
|
||||
* @param HTML_QuickForm_group group being visited
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function finishGroup(&$group)
|
||||
{
|
||||
$this->_inGroup = '';
|
||||
} // end func finishGroup
|
||||
|
||||
/**
|
||||
* Sets the way required elements are rendered
|
||||
*
|
||||
* You can use {label} or {html} placeholders to let the renderer know where
|
||||
* where the element label or the element html are positionned according to the
|
||||
* required tag. They will be replaced accordingly with the right value.
|
||||
* For example:
|
||||
* <font color="red">*</font>{label}
|
||||
* will put a red star in front of the label if the element is required.
|
||||
*
|
||||
* @param string The required element template
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setRequiredTemplate($template)
|
||||
{
|
||||
$this->_required = $template;
|
||||
} // end func setRequiredTemplate
|
||||
|
||||
/**
|
||||
* Sets the way elements with validation errors are rendered
|
||||
*
|
||||
* You can use {label} or {html} placeholders to let the renderer know where
|
||||
* where the element label or the element html are positionned according to the
|
||||
* error message. They will be replaced accordingly with the right value.
|
||||
* The error message will replace the {error} place holder.
|
||||
* For example:
|
||||
* <font color="red">{error}</font><br />{html}
|
||||
* will put the error message in red on top of the element html.
|
||||
*
|
||||
* If you want all error messages to be output in the main error block, do not specify
|
||||
* {html} nor {label}.
|
||||
*
|
||||
* Groups can have special layouts. With this kind of groups, the renderer will need
|
||||
* to know where to place the error message. In this case, use error blocks like:
|
||||
* <!-- BEGIN form_group_error -->{form_group_error}<!-- END form_group_error -->
|
||||
* where you want the error message to appear in the form.
|
||||
*
|
||||
* @param string The element error template
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setErrorTemplate($template)
|
||||
{
|
||||
$this->_error = $template;
|
||||
} // end func setErrorTemplate
|
||||
|
||||
/**
|
||||
* Called when an element is required
|
||||
*
|
||||
* This method will add the required tag to the element label and/or the element html
|
||||
* such as defined with the method setRequiredTemplate
|
||||
*
|
||||
* @param string The element label
|
||||
* @param string The element html rendering
|
||||
* @see setRequiredTemplate()
|
||||
* @access private
|
||||
* @return void
|
||||
*/
|
||||
function _renderRequired(&$label, &$html)
|
||||
{
|
||||
if ($this->_tpl->blockExists($tplBlock = $this->_formName . '_required_block')) {
|
||||
if (!empty($label) && $this->_tpl->placeholderExists($this->_formName . '_label', $tplBlock)) {
|
||||
$this->_tpl->setVariable($this->_formName . '_label', is_array($label)? $label[0]: $label);
|
||||
if (is_array($label)) {
|
||||
$label[0] = $this->_getTplBlock($tplBlock);
|
||||
} else {
|
||||
$label = $this->_getTplBlock($tplBlock);
|
||||
}
|
||||
}
|
||||
if (!empty($html) && $this->_tpl->placeholderExists($this->_formName . '_html', $tplBlock)) {
|
||||
$this->_tpl->setVariable($this->_formName . '_html', $html);
|
||||
$html = $this->_getTplBlock($tplBlock);
|
||||
}
|
||||
} else {
|
||||
if (!empty($label) && strpos($this->_required, '{label}') !== false) {
|
||||
if (is_array($label)) {
|
||||
$label[0] = str_replace('{label}', $label[0], $this->_required);
|
||||
} else {
|
||||
$label = str_replace('{label}', $label, $this->_required);
|
||||
}
|
||||
}
|
||||
if (!empty($html) && strpos($this->_required, '{html}') !== false) {
|
||||
$html = str_replace('{html}', $html, $this->_required);
|
||||
}
|
||||
}
|
||||
} // end func _renderRequired
|
||||
|
||||
/**
|
||||
* Called when an element has a validation error
|
||||
*
|
||||
* This method will add the error message to the element label or the element html
|
||||
* such as defined with the method setErrorTemplate. If the error placeholder is not found
|
||||
* in the template, the error will be displayed in the form error block.
|
||||
*
|
||||
* @param string The element label
|
||||
* @param string The element html rendering
|
||||
* @param string The element error
|
||||
* @see setErrorTemplate()
|
||||
* @access private
|
||||
* @return void
|
||||
*/
|
||||
function _renderError(&$label, &$html, $error)
|
||||
{
|
||||
if ($this->_tpl->blockExists($tplBlock = $this->_formName . '_error_block')) {
|
||||
$this->_tpl->setVariable($this->_formName . '_error', $error);
|
||||
if (!empty($label) && $this->_tpl->placeholderExists($this->_formName . '_label', $tplBlock)) {
|
||||
$this->_tpl->setVariable($this->_formName . '_label', is_array($label)? $label[0]: $label);
|
||||
if (is_array($label)) {
|
||||
$label[0] = $this->_getTplBlock($tplBlock);
|
||||
} else {
|
||||
$label = $this->_getTplBlock($tplBlock);
|
||||
}
|
||||
} elseif (!empty($html) && $this->_tpl->placeholderExists($this->_formName . '_html', $tplBlock)) {
|
||||
$this->_tpl->setVariable($this->_formName . '_html', $html);
|
||||
$html = $this->_getTplBlock($tplBlock);
|
||||
}
|
||||
// clean up after ourselves
|
||||
$this->_tpl->setVariable($this->_formName . '_error', null);
|
||||
} elseif (!empty($label) && strpos($this->_error, '{label}') !== false) {
|
||||
if (is_array($label)) {
|
||||
$label[0] = str_replace(array('{label}', '{error}'), array($label[0], $error), $this->_error);
|
||||
} else {
|
||||
$label = str_replace(array('{label}', '{error}'), array($label, $error), $this->_error);
|
||||
}
|
||||
} elseif (!empty($html) && strpos($this->_error, '{html}') !== false) {
|
||||
$html = str_replace(array('{html}', '{error}'), array($html, $error), $this->_error);
|
||||
} else {
|
||||
$this->_errors[] = $error;
|
||||
}
|
||||
}// end func _renderError
|
||||
|
||||
|
||||
/**
|
||||
* Returns the block's contents
|
||||
*
|
||||
* The method is needed because ITX and Sigma implement clearing
|
||||
* the block contents on get() a bit differently
|
||||
*
|
||||
* @param string Block name
|
||||
* @return string Block contents
|
||||
*/
|
||||
function _getTplBlock($block)
|
||||
{
|
||||
$this->_tpl->parse($block);
|
||||
if (is_a($this->_tpl, 'html_template_sigma')) {
|
||||
$ret = $this->_tpl->get($block, true);
|
||||
} else {
|
||||
$oldClear = $this->_tpl->clearCache;
|
||||
$this->_tpl->clearCache = true;
|
||||
$ret = $this->_tpl->get($block);
|
||||
$this->_tpl->clearCache = $oldClear;
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
} // end class HTML_QuickForm_Renderer_ITStatic
|
||||
?>
|
||||
|
|
@ -0,0 +1,461 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* A concrete renderer for HTML_QuickForm, makes an object from form contents
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Ron McClain <ron@humaniq.com>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: Object.php,v 1.6 2009/04/04 21:34:04 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* An abstract base class for QuickForm renderers
|
||||
*/
|
||||
require_once 'HTML/QuickForm/Renderer.php';
|
||||
|
||||
/**
|
||||
* A concrete renderer for HTML_QuickForm, makes an object from form contents
|
||||
*
|
||||
* Based on HTML_Quickform_Renderer_Array code
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Ron McClain <ron@humaniq.com>
|
||||
* @version Release: 3.2.11
|
||||
* @since 3.1.1
|
||||
*/
|
||||
class HTML_QuickForm_Renderer_Object extends HTML_QuickForm_Renderer
|
||||
{
|
||||
/**#@+
|
||||
* @access private
|
||||
*/
|
||||
/**
|
||||
* The object being generated
|
||||
* @var QuickformForm
|
||||
*/
|
||||
var $_obj= null;
|
||||
|
||||
/**
|
||||
* Number of sections in the form (i.e. number of headers in it)
|
||||
* @var integer $_sectionCount
|
||||
*/
|
||||
var $_sectionCount;
|
||||
|
||||
/**
|
||||
* Current section number
|
||||
* @var integer $_currentSection
|
||||
*/
|
||||
var $_currentSection;
|
||||
|
||||
/**
|
||||
* Object representing current group
|
||||
* @var object $_currentGroup
|
||||
*/
|
||||
var $_currentGroup = null;
|
||||
|
||||
/**
|
||||
* Class of Element Objects
|
||||
* @var object $_elementType
|
||||
*/
|
||||
var $_elementType = 'QuickFormElement';
|
||||
|
||||
/**
|
||||
* Additional style information for different elements
|
||||
* @var array $_elementStyles
|
||||
*/
|
||||
var $_elementStyles = array();
|
||||
|
||||
/**
|
||||
* true: collect all hidden elements into string; false: process them as usual form elements
|
||||
* @var bool $_collectHidden
|
||||
*/
|
||||
var $_collectHidden = false;
|
||||
/**#@-*/
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param bool true: collect all hidden elements
|
||||
* @access public
|
||||
*/
|
||||
function __construct($collecthidden = false)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->_collectHidden = $collecthidden;
|
||||
$this->_obj = new QuickformForm;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the rendered Object
|
||||
* @access public
|
||||
*/
|
||||
function toObject()
|
||||
{
|
||||
return $this->_obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the class of the form elements. Defaults to QuickformElement.
|
||||
* @param string Name of element class
|
||||
* @access public
|
||||
*/
|
||||
function setElementType($type)
|
||||
{
|
||||
$this->_elementType = $type;
|
||||
}
|
||||
|
||||
function startForm(&$form)
|
||||
{
|
||||
$this->_obj->frozen = $form->isFrozen();
|
||||
$this->_obj->javascript = $form->getValidationScript();
|
||||
$this->_obj->attributes = $form->getAttributes(true);
|
||||
$this->_obj->requirednote = $form->getRequiredNote();
|
||||
$this->_obj->errors = new StdClass;
|
||||
|
||||
if($this->_collectHidden) {
|
||||
$this->_obj->hidden = '';
|
||||
}
|
||||
$this->_elementIdx = 1;
|
||||
$this->_currentSection = null;
|
||||
$this->_sectionCount = 0;
|
||||
} // end func startForm
|
||||
|
||||
function renderHeader(&$header)
|
||||
{
|
||||
$hobj = new StdClass;
|
||||
$hobj->header = $header->toHtml();
|
||||
$this->_obj->sections[$this->_sectionCount] = $hobj;
|
||||
$this->_currentSection = $this->_sectionCount++;
|
||||
}
|
||||
|
||||
function renderElement(&$element, $required, $error)
|
||||
{
|
||||
$elObj = $this->_elementToObject($element, $required, $error);
|
||||
if(!empty($error)) {
|
||||
$name = $elObj->name;
|
||||
$this->_obj->errors->$name = $error;
|
||||
}
|
||||
$this->_storeObject($elObj);
|
||||
} // end func renderElement
|
||||
|
||||
function renderHidden(&$element)
|
||||
{
|
||||
if($this->_collectHidden) {
|
||||
$this->_obj->hidden .= $element->toHtml() . "\n";
|
||||
} else {
|
||||
$this->renderElement($element, false, null);
|
||||
}
|
||||
} //end func renderHidden
|
||||
|
||||
function startGroup(&$group, $required, $error)
|
||||
{
|
||||
$this->_currentGroup = $this->_elementToObject($group, $required, $error);
|
||||
if(!empty($error)) {
|
||||
$name = $this->_currentGroup->name;
|
||||
$this->_obj->errors->$name = $error;
|
||||
}
|
||||
} // end func startGroup
|
||||
|
||||
function finishGroup(&$group)
|
||||
{
|
||||
$this->_storeObject($this->_currentGroup);
|
||||
$this->_currentGroup = null;
|
||||
} // end func finishGroup
|
||||
|
||||
/**
|
||||
* Creates an object representing an element
|
||||
*
|
||||
* @access private
|
||||
* @param HTML_QuickForm_element form element being rendered
|
||||
* @param required bool Whether an element is required
|
||||
* @param error string Error associated with the element
|
||||
* @return object
|
||||
*/
|
||||
function _elementToObject(&$element, $required, $error)
|
||||
{
|
||||
if($this->_elementType) {
|
||||
$ret = new $this->_elementType;
|
||||
}
|
||||
$ret->name = $element->getName();
|
||||
$ret->value = $element->getValue();
|
||||
$ret->type = $element->getType();
|
||||
$ret->frozen = $element->isFrozen();
|
||||
$labels = $element->getLabel();
|
||||
if (is_array($labels)) {
|
||||
$ret->label = array_shift($labels);
|
||||
foreach ($labels as $key => $label) {
|
||||
$key = is_int($key)? $key + 2: $key;
|
||||
$ret->{'label_' . $key} = $label;
|
||||
}
|
||||
} else {
|
||||
$ret->label = $labels;
|
||||
}
|
||||
$ret->required = $required;
|
||||
$ret->error = $error;
|
||||
|
||||
if(isset($this->_elementStyles[$ret->name])) {
|
||||
$ret->style = $this->_elementStyles[$ret->name];
|
||||
$ret->styleTemplate = "styles/". $ret->style .".html";
|
||||
}
|
||||
if($ret->type == 'group') {
|
||||
$ret->separator = $element->_separator;
|
||||
$ret->elements = array();
|
||||
} else {
|
||||
$ret->html = $element->toHtml();
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores an object representation of an element in the form array
|
||||
*
|
||||
* @access private
|
||||
* @param QuickformElement Object representation of an element
|
||||
* @return void
|
||||
*/
|
||||
function _storeObject($elObj)
|
||||
{
|
||||
$name = $elObj->name;
|
||||
if(is_object($this->_currentGroup) && $elObj->type != 'group') {
|
||||
$this->_currentGroup->elements[] = $elObj;
|
||||
} elseif (isset($this->_currentSection)) {
|
||||
$this->_obj->sections[$this->_currentSection]->elements[] = $elObj;
|
||||
} else {
|
||||
$this->_obj->elements[] = $elObj;
|
||||
}
|
||||
}
|
||||
|
||||
function setElementStyle($elementName, $styleName = null)
|
||||
{
|
||||
if(is_array($elementName)) {
|
||||
$this->_elementStyles = array_merge($this->_elementStyles, $elementName);
|
||||
} else {
|
||||
$this->_elementStyles[$elementName] = $styleName;
|
||||
}
|
||||
}
|
||||
|
||||
} // end class HTML_QuickForm_Renderer_Object
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Convenience class for the form object passed to outputObject()
|
||||
*
|
||||
* Eg.
|
||||
* <pre>
|
||||
* {form.outputJavaScript():h}
|
||||
* {form.outputHeader():h}
|
||||
* <table>
|
||||
* <tr>
|
||||
* <td>{form.name.label:h}</td><td>{form.name.html:h}</td>
|
||||
* </tr>
|
||||
* </table>
|
||||
* </form>
|
||||
* </pre>
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Ron McClain <ron@humaniq.com>
|
||||
* @version Release: 3.2.11
|
||||
* @since 3.1.1
|
||||
*/
|
||||
class QuickformForm
|
||||
{
|
||||
/**
|
||||
* Whether the form has been frozen
|
||||
* @var boolean $frozen
|
||||
*/
|
||||
var $frozen;
|
||||
|
||||
/**
|
||||
* Javascript for client-side validation
|
||||
* @var string $javascript
|
||||
*/
|
||||
var $javascript;
|
||||
|
||||
/**
|
||||
* Attributes for form tag
|
||||
* @var string $attributes
|
||||
*/
|
||||
var $attributes;
|
||||
|
||||
/**
|
||||
* Note about required elements
|
||||
* @var string $requirednote
|
||||
*/
|
||||
var $requirednote;
|
||||
|
||||
/**
|
||||
* Collected html of all hidden variables
|
||||
* @var string $hidden
|
||||
*/
|
||||
var $hidden;
|
||||
|
||||
/**
|
||||
* Set if there were validation errors.
|
||||
* StdClass object with element names for keys and their
|
||||
* error messages as values
|
||||
* @var object $errors
|
||||
*/
|
||||
var $errors;
|
||||
|
||||
/**
|
||||
* Array of QuickformElementObject elements. If there are headers in the form
|
||||
* this will be empty and the elements will be in the
|
||||
* separate sections
|
||||
* @var array $elements
|
||||
*/
|
||||
var $elements;
|
||||
|
||||
/**
|
||||
* Array of sections contained in the document
|
||||
* @var array $sections
|
||||
*/
|
||||
var $sections;
|
||||
|
||||
/**
|
||||
* Output <form> header
|
||||
* {form.outputHeader():h}
|
||||
* @return string <form attributes>
|
||||
*/
|
||||
function outputHeader()
|
||||
{
|
||||
return "<form " . $this->attributes . ">\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* Output form javascript
|
||||
* {form.outputJavaScript():h}
|
||||
* @return string Javascript
|
||||
*/
|
||||
function outputJavaScript()
|
||||
{
|
||||
return $this->javascript;
|
||||
}
|
||||
} // end class QuickformForm
|
||||
|
||||
|
||||
/**
|
||||
* Convenience class describing a form element.
|
||||
*
|
||||
* The properties defined here will be available from
|
||||
* your flexy templates by referencing
|
||||
* {form.zip.label:h}, {form.zip.html:h}, etc.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Ron McClain <ron@humaniq.com>
|
||||
* @version Release: 3.2.11
|
||||
* @since 3.1.1
|
||||
*/
|
||||
class QuickformElement
|
||||
{
|
||||
/**
|
||||
* Element name
|
||||
* @var string $name
|
||||
*/
|
||||
var $name;
|
||||
|
||||
/**
|
||||
* Element value
|
||||
* @var mixed $value
|
||||
*/
|
||||
var $value;
|
||||
|
||||
/**
|
||||
* Type of element
|
||||
* @var string $type
|
||||
*/
|
||||
var $type;
|
||||
|
||||
/**
|
||||
* Whether the element is frozen
|
||||
* @var boolean $frozen
|
||||
*/
|
||||
var $frozen;
|
||||
|
||||
/**
|
||||
* Label for the element
|
||||
* @var string $label
|
||||
*/
|
||||
var $label;
|
||||
|
||||
/**
|
||||
* Whether element is required
|
||||
* @var boolean $required
|
||||
*/
|
||||
var $required;
|
||||
|
||||
/**
|
||||
* Error associated with the element
|
||||
* @var string $error
|
||||
*/
|
||||
var $error;
|
||||
|
||||
/**
|
||||
* Some information about element style
|
||||
* @var string $style
|
||||
*/
|
||||
var $style;
|
||||
|
||||
/**
|
||||
* HTML for the element
|
||||
* @var string $html
|
||||
*/
|
||||
var $html;
|
||||
|
||||
/**
|
||||
* If element is a group, the group separator
|
||||
* @var mixed $separator
|
||||
*/
|
||||
var $separator;
|
||||
|
||||
/**
|
||||
* If element is a group, an array of subelements
|
||||
* @var array $elements
|
||||
*/
|
||||
var $elements;
|
||||
|
||||
function isType($type)
|
||||
{
|
||||
return ($this->type == $type);
|
||||
}
|
||||
|
||||
function notFrozen()
|
||||
{
|
||||
return !$this->frozen;
|
||||
}
|
||||
|
||||
function isButton()
|
||||
{
|
||||
return ($this->type == "submit" || $this->type == "reset");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* XXX: why does it use Flexy when all other stuff here does not depend on it?
|
||||
*/
|
||||
function outputStyle()
|
||||
{
|
||||
ob_start();
|
||||
HTML_Template_Flexy::staticQuickTemplate('styles/' . $this->style . '.html', $this);
|
||||
$ret = ob_get_contents();
|
||||
ob_end_clean();
|
||||
return $ret;
|
||||
}
|
||||
} // end class QuickformElement
|
||||
?>
|
||||
|
|
@ -0,0 +1,291 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* QuickForm renderer for Flexy template engine, static version.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Ron McClain <ron@humaniq.com>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: ObjectFlexy.php,v 1.10 2009/04/04 21:34:04 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* A concrete renderer for HTML_QuickForm, makes an object from form contents
|
||||
*/
|
||||
require_once 'HTML/QuickForm/Renderer/Object.php';
|
||||
|
||||
/**
|
||||
* QuickForm renderer for Flexy template engine, static version.
|
||||
*
|
||||
* A static renderer for HTML_Quickform. Makes a QuickFormFlexyObject
|
||||
* from the form content suitable for use with a Flexy template
|
||||
*
|
||||
* Usage:
|
||||
* <code>
|
||||
* $form =& new HTML_QuickForm('form', 'POST');
|
||||
* $template =& new HTML_Template_Flexy();
|
||||
* $renderer =& new HTML_QuickForm_Renderer_ObjectFlexy(&$template);
|
||||
* $renderer->setHtmlTemplate("html.html");
|
||||
* $renderer->setLabelTemplate("label.html");
|
||||
* $form->accept($renderer);
|
||||
* $view = new StdClass;
|
||||
* $view->form = $renderer->toObject();
|
||||
* $template->compile("mytemplate.html");
|
||||
* </code>
|
||||
*
|
||||
* Based on the code for HTML_QuickForm_Renderer_ArraySmarty
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Ron McClain <ron@humaniq.com>
|
||||
* @version Release: 3.2.11
|
||||
* @since 3.1.1
|
||||
*/
|
||||
class HTML_QuickForm_Renderer_ObjectFlexy extends HTML_QuickForm_Renderer_Object
|
||||
{
|
||||
/**#@+
|
||||
* @access private
|
||||
*/
|
||||
/**
|
||||
* HTML_Template_Flexy instance
|
||||
* @var object $_flexy
|
||||
*/
|
||||
var $_flexy;
|
||||
|
||||
/**
|
||||
* Current element index
|
||||
* @var integer $_elementIdx
|
||||
*/
|
||||
var $_elementIdx;
|
||||
|
||||
/**
|
||||
* The current element index inside a group
|
||||
* @var integer $_groupElementIdx
|
||||
*/
|
||||
var $_groupElementIdx = 0;
|
||||
|
||||
/**
|
||||
* Name of template file for form html
|
||||
* @var string $_html
|
||||
* @see setRequiredTemplate()
|
||||
*/
|
||||
var $_html = '';
|
||||
|
||||
/**
|
||||
* Name of template file for form labels
|
||||
* @var string $label
|
||||
* @see setErrorTemplate()
|
||||
*/
|
||||
var $label = '';
|
||||
|
||||
/**
|
||||
* Class of the element objects, so you can add your own
|
||||
* element methods
|
||||
* @var string $_elementType
|
||||
*/
|
||||
var $_elementType = 'QuickformFlexyElement';
|
||||
/**#@-*/
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param HTML_Template_Flexy template object to use
|
||||
* @public
|
||||
*/
|
||||
function __construct(&$flexy)
|
||||
{
|
||||
parent::__construct(true);
|
||||
$this->_obj = new QuickformFlexyForm();
|
||||
$this->_flexy =& $flexy;
|
||||
} // end constructor
|
||||
|
||||
function renderHeader(&$header)
|
||||
{
|
||||
if($name = $header->getName()) {
|
||||
$this->_obj->header->$name = $header->toHtml();
|
||||
} else {
|
||||
$this->_obj->header[$this->_sectionCount] = $header->toHtml();
|
||||
}
|
||||
$this->_currentSection = $this->_sectionCount++;
|
||||
} // end func renderHeader
|
||||
|
||||
function startGroup(&$group, $required, $error)
|
||||
{
|
||||
parent::startGroup($group, $required, $error);
|
||||
$this->_groupElementIdx = 1;
|
||||
} //end func startGroup
|
||||
|
||||
/**
|
||||
* Creates an object representing an element containing
|
||||
* the key for storing this
|
||||
*
|
||||
* @access private
|
||||
* @param HTML_QuickForm_element form element being rendered
|
||||
* @param bool Whether an element is required
|
||||
* @param string Error associated with the element
|
||||
* @return object
|
||||
*/
|
||||
function _elementToObject(&$element, $required, $error)
|
||||
{
|
||||
$ret = parent::_elementToObject($element, $required, $error);
|
||||
if($ret->type == 'group') {
|
||||
$ret->html = $element->toHtml();
|
||||
unset($ret->elements);
|
||||
}
|
||||
if(!empty($this->_label)) {
|
||||
$this->_renderLabel($ret);
|
||||
}
|
||||
|
||||
if(!empty($this->_html)) {
|
||||
$this->_renderHtml($ret);
|
||||
$ret->error = $error;
|
||||
}
|
||||
|
||||
// Create an element key from the name
|
||||
if (false !== ($pos = strpos($ret->name, '[')) || is_object($this->_currentGroup)) {
|
||||
if (!$pos) {
|
||||
$keys = '->{\'' . str_replace(array('\\', '\''), array('\\\\', '\\\''), $ret->name) . '\'}';
|
||||
} else {
|
||||
$keys = '->{\'' . str_replace(
|
||||
array('\\', '\'', '[', ']'), array('\\\\', '\\\'', '\'}->{\'', ''),
|
||||
$ret->name
|
||||
) . '\'}';
|
||||
}
|
||||
// special handling for elements in native groups
|
||||
if (is_object($this->_currentGroup)) {
|
||||
// skip unnamed group items unless radios: no name -> no static access
|
||||
// identification: have the same key string as the parent group
|
||||
if ($this->_currentGroup->keys == $keys && 'radio' != $ret->type) {
|
||||
return false;
|
||||
}
|
||||
// reduce string of keys by remove leading group keys
|
||||
if (0 === strpos($keys, $this->_currentGroup->keys)) {
|
||||
$keys = substr_replace($keys, '', 0, strlen($this->_currentGroup->keys));
|
||||
}
|
||||
}
|
||||
} elseif (0 == strlen($ret->name)) {
|
||||
$keys = '->{\'element_' . $this->_elementIdx . '\'}';
|
||||
} else {
|
||||
$keys = '->{\'' . str_replace(array('\\', '\''), array('\\\\', '\\\''), $ret->name) . '\'}';
|
||||
}
|
||||
// for radios: add extra key from value
|
||||
if ('radio' == $ret->type && '[]' != substr($keys, -2)) {
|
||||
$keys .= '->{\'' . str_replace(array('\\', '\''), array('\\\\', '\\\''), $ret->value) . '\'}';
|
||||
}
|
||||
$ret->keys = $keys;
|
||||
$this->_elementIdx++;
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores an object representation of an element in the
|
||||
* QuickformFormObject instance
|
||||
*
|
||||
* @access private
|
||||
* @param QuickformElement Object representation of an element
|
||||
* @return void
|
||||
*/
|
||||
function _storeObject($elObj)
|
||||
{
|
||||
if ($elObj) {
|
||||
$keys = $elObj->keys;
|
||||
unset($elObj->keys);
|
||||
if(is_object($this->_currentGroup) && ('group' != $elObj->type)) {
|
||||
$code = '$this->_currentGroup' . $keys . ' = $elObj;';
|
||||
} else {
|
||||
$code = '$this->_obj' . $keys . ' = $elObj;';
|
||||
}
|
||||
eval($code);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the filename of the template to render html elements.
|
||||
* In your template, {html} is replaced by the unmodified html.
|
||||
* If the element is required, {required} will be true.
|
||||
* Eg.
|
||||
* <pre>
|
||||
* {if:error}
|
||||
* <font color="red" size="1">{error:h}</font><br />
|
||||
* {end:}
|
||||
* {html:h}
|
||||
* </pre>
|
||||
*
|
||||
* @access public
|
||||
* @param string Filename of template
|
||||
* @return void
|
||||
*/
|
||||
function setHtmlTemplate($template)
|
||||
{
|
||||
$this->_html = $template;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the filename of the template to render form labels
|
||||
* In your template, {label} is replaced by the unmodified label.
|
||||
* {error} will be set to the error, if any. {required} will
|
||||
* be true if this is a required field
|
||||
* Eg.
|
||||
* <pre>
|
||||
* {if:required}
|
||||
* <font color="orange" size="1">*</font>
|
||||
* {end:}
|
||||
* {label:h}
|
||||
* </pre>
|
||||
*
|
||||
* @access public
|
||||
* @param string Filename of template
|
||||
* @return void
|
||||
*/
|
||||
function setLabelTemplate($template)
|
||||
{
|
||||
$this->_label = $template;
|
||||
}
|
||||
|
||||
function _renderLabel(&$ret)
|
||||
{
|
||||
$this->_flexy->compile($this->_label);
|
||||
$ret->label = $this->_flexy->bufferedOutputObject($ret);
|
||||
}
|
||||
|
||||
function _renderHtml(&$ret)
|
||||
{
|
||||
$this->_flexy->compile($this->_html);
|
||||
$ret->html = $this->_flexy->bufferedOutputObject($ret);
|
||||
}
|
||||
} // end class HTML_QuickForm_Renderer_ObjectFlexy
|
||||
|
||||
/**
|
||||
* Adds nothing to QuickformForm, left for backwards compatibility
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @ignore
|
||||
*/
|
||||
class QuickformFlexyForm extends QuickformForm
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds nothing to QuickformElement, left for backwards compatibility
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @ignore
|
||||
*/
|
||||
class QuickformFlexyElement extends QuickformElement
|
||||
{
|
||||
}
|
||||
?>
|
||||
|
|
@ -0,0 +1,213 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* A renderer that makes it quick and easy to create customized forms.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Jason Rust <jrust@rustyparts.com>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: QuickHtml.php,v 1.3 2009/04/04 21:34:04 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* A concrete renderer for HTML_QuickForm, based on QuickForm 2.x built-in one
|
||||
*/
|
||||
require_once 'HTML/QuickForm/Renderer/Default.php';
|
||||
|
||||
/**
|
||||
* A renderer that makes it quick and easy to create customized forms.
|
||||
*
|
||||
* This renderer has three main distinctives: an easy way to create
|
||||
* custom-looking forms, the ability to separate the creation of form
|
||||
* elements from their display, and being able to use QuickForm in
|
||||
* widget-based template systems. See the online docs for more info.
|
||||
* For a usage example see: docs/renderers/QuickHtml_example.php
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Jason Rust <jrust@rustyparts.com>
|
||||
* @version Release: 3.2.11
|
||||
* @since 3.1.1
|
||||
*/
|
||||
class HTML_QuickForm_Renderer_QuickHtml extends HTML_QuickForm_Renderer_Default {
|
||||
// {{{ properties
|
||||
|
||||
/**
|
||||
* The array of rendered elements
|
||||
* @var array
|
||||
*/
|
||||
var $renderedElements = array();
|
||||
|
||||
// }}}
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
// The default templates aren't used for this renderer
|
||||
$this->clearAllTemplates();
|
||||
} // end constructor
|
||||
|
||||
// }}}
|
||||
// {{{ toHtml()
|
||||
|
||||
/**
|
||||
* returns the HTML generated for the form
|
||||
*
|
||||
* @param string $data (optional) Any extra data to put before the end of the form
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function toHtml($data = '')
|
||||
{
|
||||
// Render any elements that haven't been rendered explicitly by elementToHtml()
|
||||
foreach (array_keys($this->renderedElements) as $key) {
|
||||
if (!$this->renderedElements[$key]['rendered']) {
|
||||
$this->renderedElements[$key]['rendered'] = true;
|
||||
$data .= $this->renderedElements[$key]['html'] . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
// Insert the extra data and form elements at the end of the form
|
||||
$this->_html = str_replace('</form>', $data . "\n</form>", $this->_html);
|
||||
return $this->_html;
|
||||
} // end func toHtml
|
||||
|
||||
// }}}
|
||||
// {{{ elementToHtml()
|
||||
|
||||
/**
|
||||
* Gets the html for an element and marks it as rendered.
|
||||
*
|
||||
* @param string $elementName The element name
|
||||
* @param string $elementValue (optional) The value of the element. This is only useful
|
||||
* for elements that have the same name (i.e. radio and checkbox), but
|
||||
* different values
|
||||
*
|
||||
* @access public
|
||||
* @return string The html for the QuickForm element
|
||||
* @throws HTML_QuickForm_Error
|
||||
*/
|
||||
function elementToHtml($elementName, $elementValue = null)
|
||||
{
|
||||
$elementKey = null;
|
||||
// Find the key for the element
|
||||
foreach ($this->renderedElements as $key => $data) {
|
||||
if ($data['name'] == $elementName &&
|
||||
// See if the value must match as well
|
||||
(is_null($elementValue) ||
|
||||
$data['value'] == $elementValue)) {
|
||||
$elementKey = $key;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_null($elementKey)) {
|
||||
$msg = is_null($elementValue) ? "Element $elementName does not exist." :
|
||||
"Element $elementName with value of $elementValue does not exist.";
|
||||
return PEAR::raiseError(null, QUICKFORM_UNREGISTERED_ELEMENT, null, E_USER_WARNING, $msg, 'HTML_QuickForm_Error', true);
|
||||
} else {
|
||||
if ($this->renderedElements[$elementKey]['rendered']) {
|
||||
$msg = is_null($elementValue) ? "Element $elementName has already been rendered." :
|
||||
"Element $elementName with value of $elementValue has already been rendered.";
|
||||
return PEAR::raiseError(null, QUICKFORM_ERROR, null, E_USER_WARNING, $msg, 'HTML_QuickForm_Error', true);
|
||||
} else {
|
||||
$this->renderedElements[$elementKey]['rendered'] = true;
|
||||
return $this->renderedElements[$elementKey]['html'];
|
||||
}
|
||||
}
|
||||
} // end func elementToHtml
|
||||
|
||||
// }}}
|
||||
// {{{ renderElement()
|
||||
|
||||
/**
|
||||
* Gets the html for an element and adds it to the array by calling
|
||||
* parent::renderElement()
|
||||
*
|
||||
* @param HTML_QuickForm_element form element being visited
|
||||
* @param bool Whether an element is required
|
||||
* @param string An error message associated with an element
|
||||
*
|
||||
* @access public
|
||||
* @return mixed HTML string of element if $immediateRender is set, else we just add the
|
||||
* html to the global _html string
|
||||
*/
|
||||
function renderElement(&$element, $required, $error)
|
||||
{
|
||||
$this->_html = '';
|
||||
parent::renderElement($element, $required, $error);
|
||||
if (!$this->_inGroup) {
|
||||
$this->renderedElements[] = array(
|
||||
'name' => $element->getName(),
|
||||
'value' => $element->getValue(),
|
||||
'html' => $this->_html,
|
||||
'rendered' => false);
|
||||
}
|
||||
$this->_html = '';
|
||||
} // end func renderElement
|
||||
|
||||
// }}}
|
||||
// {{{ renderHidden()
|
||||
|
||||
/**
|
||||
* Gets the html for a hidden element and adds it to the array.
|
||||
*
|
||||
* @param HTML_QuickForm_element hidden form element being visited
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function renderHidden(&$element)
|
||||
{
|
||||
$this->renderedElements[] = array(
|
||||
'name' => $element->getName(),
|
||||
'value' => $element->getValue(),
|
||||
'html' => $element->toHtml(),
|
||||
'rendered' => false);
|
||||
} // end func renderHidden
|
||||
|
||||
// }}}
|
||||
// {{{ finishGroup()
|
||||
|
||||
/**
|
||||
* Gets the html for the group element and adds it to the array by calling
|
||||
* parent::finishGroup()
|
||||
*
|
||||
* @param HTML_QuickForm_group group being visited
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function finishGroup(&$group)
|
||||
{
|
||||
$this->_html = '';
|
||||
parent::finishGroup($group);
|
||||
$this->renderedElements[] = array(
|
||||
'name' => $group->getName(),
|
||||
'value' => $group->getValue(),
|
||||
'html' => $this->_html,
|
||||
'rendered' => false);
|
||||
$this->_html = '';
|
||||
} // end func finishGroup
|
||||
|
||||
// }}}
|
||||
} // end class HTML_QuickForm_Renderer_QuickHtml
|
||||
?>
|
||||
82
sites/all/modules/civicrm/packages/HTML/QuickForm/Rule.php
Normal file
82
sites/all/modules/civicrm/packages/HTML/QuickForm/Rule.php
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Abstract base class for QuickForm validation rules
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: Rule.php,v 1.4 2009/04/04 21:34:02 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Abstract base class for QuickForm validation rules
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @version Release: 3.2.11
|
||||
* @since 3.2
|
||||
* @abstract
|
||||
*/
|
||||
class HTML_QuickForm_Rule
|
||||
{
|
||||
/**
|
||||
* Name of the rule to use in validate method
|
||||
*
|
||||
* This property is used in more global rules like Callback and Regex
|
||||
* to determine which callback and which regex is to be used for validation
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $name;
|
||||
|
||||
/**
|
||||
* Validates a value
|
||||
*
|
||||
* @access public
|
||||
* @abstract
|
||||
*/
|
||||
function validate($value)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the rule name
|
||||
*
|
||||
* @param string rule name
|
||||
* @access public
|
||||
*/
|
||||
function setName($ruleName)
|
||||
{
|
||||
$this->name = $ruleName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the javascript test (the test should return true if the value is INVALID)
|
||||
*
|
||||
* @param mixed Options for the rule
|
||||
* @access public
|
||||
* @return array first element is code to setup validation, second is the check itself
|
||||
* @abstract
|
||||
*/
|
||||
function getValidationScript($options = null)
|
||||
{
|
||||
return array('', '');
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
@ -0,0 +1,124 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Validates values using callback functions or methods
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: Callback.php,v 1.9 2009/04/04 21:34:04 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Abstract base class for QuickForm validation rules
|
||||
*/
|
||||
require_once 'HTML/QuickForm/Rule.php';
|
||||
|
||||
/**
|
||||
* Validates values using callback functions or methods
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @version Release: 3.2.11
|
||||
* @since 3.2
|
||||
*/
|
||||
class HTML_QuickForm_Rule_Callback extends HTML_QuickForm_Rule
|
||||
{
|
||||
/**
|
||||
* Array of callbacks
|
||||
*
|
||||
* Array is in the format:
|
||||
* $_data['rulename'] = array('functionname', 'classname');
|
||||
* If the callback is not a method, then the class name is not set.
|
||||
*
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_data = array();
|
||||
|
||||
/**
|
||||
* Whether to use BC mode for specific rules
|
||||
*
|
||||
* Previous versions of QF passed element's name as a first parameter
|
||||
* to validation functions, but not to validation methods. This behaviour
|
||||
* is emulated if you are using 'function' as rule type when registering.
|
||||
*
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_BCMode = array();
|
||||
|
||||
/**
|
||||
* Validates a value using a callback
|
||||
*
|
||||
* @param string $value Value to be checked
|
||||
* @param mixed $options Options for callback
|
||||
* @access public
|
||||
* @return boolean true if value is valid
|
||||
*/
|
||||
function validate($value, $options = null)
|
||||
{
|
||||
if (isset($this->_data[$this->name])) {
|
||||
$callback = $this->_data[$this->name];
|
||||
if (isset($callback[1])) {
|
||||
return call_user_func(array($callback[1], $callback[0]), $value, $options);
|
||||
} elseif ($this->_BCMode[$this->name]) {
|
||||
return $callback[0]('', $value, $options);
|
||||
} else {
|
||||
return $callback[0]($value, $options);
|
||||
}
|
||||
} elseif (is_callable($options)) {
|
||||
return call_user_func($options, $value);
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
} // end func validate
|
||||
|
||||
/**
|
||||
* Adds new callbacks to the callbacks list
|
||||
*
|
||||
* @param string $name Name of rule
|
||||
* @param string $callback Name of function or method
|
||||
* @param string $class Name of class containing the method
|
||||
* @param bool $BCMode Backwards compatibility mode
|
||||
* @access public
|
||||
*/
|
||||
function addData($name, $callback, $class = null, $BCMode = false)
|
||||
{
|
||||
if (!empty($class)) {
|
||||
$this->_data[$name] = array($callback, $class);
|
||||
} else {
|
||||
$this->_data[$name] = array($callback);
|
||||
}
|
||||
$this->_BCMode[$name] = $BCMode;
|
||||
} // end func addData
|
||||
|
||||
|
||||
function getValidationScript($options = null)
|
||||
{
|
||||
if (isset($this->_data[$this->name])) {
|
||||
$callback = $this->_data[$this->name][0];
|
||||
$params = ($this->_BCMode[$this->name]? "'', {jsVar}": '{jsVar}') .
|
||||
(isset($options)? ", '{$options}'": '');
|
||||
} else {
|
||||
$callback = is_array($options)? $options[1]: $options;
|
||||
$params = '{jsVar}';
|
||||
}
|
||||
return array('', "{jsVar} != '' && !{$callback}({$params})");
|
||||
} // end func getValidationScript
|
||||
|
||||
} // end class HTML_QuickForm_Rule_Callback
|
||||
?>
|
||||
|
|
@ -0,0 +1,105 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Rule to compare two form fields
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: Compare.php,v 1.7 2009/04/04 21:34:04 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Abstract base class for QuickForm validation rules
|
||||
*/
|
||||
require_once 'HTML/QuickForm/Rule.php';
|
||||
|
||||
/**
|
||||
* Rule to compare two form fields
|
||||
*
|
||||
* The most common usage for this is to ensure that the password
|
||||
* confirmation field matches the password field
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @version Release: 3.2.11
|
||||
* @since 3.2
|
||||
*/
|
||||
class HTML_QuickForm_Rule_Compare extends HTML_QuickForm_Rule
|
||||
{
|
||||
/**
|
||||
* Possible operators to use
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_operators = array(
|
||||
'eq' => '===',
|
||||
'neq' => '!==',
|
||||
'gt' => '>',
|
||||
'gte' => '>=',
|
||||
'lt' => '<',
|
||||
'lte' => '<=',
|
||||
'==' => '===',
|
||||
'!=' => '!=='
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Returns the operator to use for comparing the values
|
||||
*
|
||||
* @access private
|
||||
* @param string operator name
|
||||
* @return string operator to use for validation
|
||||
*/
|
||||
function _findOperator($name)
|
||||
{
|
||||
if (empty($name)) {
|
||||
return '===';
|
||||
} elseif (isset($this->_operators[$name])) {
|
||||
return $this->_operators[$name];
|
||||
} elseif (in_array($name, $this->_operators)) {
|
||||
return $name;
|
||||
} else {
|
||||
return '===';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function validate($values, $operator = null)
|
||||
{
|
||||
$operator = $this->_findOperator($operator);
|
||||
if ('===' != $operator && '!==' != $operator) {
|
||||
$compareFn = create_function('$a, $b', 'return floatval($a) ' . $operator . ' floatval($b);');
|
||||
} else {
|
||||
$compareFn = create_function('$a, $b', 'return strval($a) ' . $operator . ' strval($b);');
|
||||
}
|
||||
|
||||
return $compareFn($values[0], $values[1]);
|
||||
}
|
||||
|
||||
|
||||
function getValidationScript($operator = null)
|
||||
{
|
||||
$operator = $this->_findOperator($operator);
|
||||
if ('===' != $operator && '!==' != $operator) {
|
||||
$check = "!(Number({jsVar}[0]) {$operator} Number({jsVar}[1]))";
|
||||
} else {
|
||||
$check = "!(String({jsVar}[0]) {$operator} String({jsVar}[1]))";
|
||||
}
|
||||
return array('', "'' != {jsVar}[0] && {$check}");
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
@ -0,0 +1,86 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Email validation rule
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: Email.php,v 1.7 2009/04/04 21:34:04 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Abstract base class for QuickForm validation rules
|
||||
*/
|
||||
require_once 'HTML/QuickForm/Rule.php';
|
||||
|
||||
/**
|
||||
* Email validation rule
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @version Release: 3.2.11
|
||||
* @since 3.2
|
||||
*/
|
||||
class HTML_QuickForm_Rule_Email extends HTML_QuickForm_Rule
|
||||
{
|
||||
// switching to a better regex as per CRM-40
|
||||
// var $regex = '/^((\"[^\"\f\n\r\t\v\b]+\")|([\w\!\#\$\%\&\'\*\+\-\~\/\^\`\|\{\}]+(\.[\w\!\#\$\%\&\'\*\+\-\~\/\^\`\|\{\}]+)*))@((\[(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))\])|(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))|((([A-Za-z0-9\-])+\.)+[A-Za-z\-]+))$/';
|
||||
var $regex = '/^([a-zA-Z0-9&_?\/`!|#*$^%=~{}+\'-]+|"([\x00-\x0C\x0E-\x21\x23-\x5B\x5D-\x7F]|\\[\x00-\x7F])*")(\.([a-zA-Z0-9&_?\/`!|#*$^%=~{}+\'-]+|"([\x00-\x0C\x0E-\x21\x23-\x5B\x5D-\x7F]|\\[\x00-\x7F])*"))*@([a-zA-Z0-9&_?\/`!|#*$^%=~{}+\'-]+|\[([\x00-\x0C\x0E-\x5A\x5E-\x7F]|\\[\x00-\x7F])*\])(\.([a-zA-Z0-9&_?\/`!|#*$^%=~{}+\'-]+|\[([\x00-\x0C\x0E-\x5A\x5E-\x7F]|\\[\x00-\x7F])*\]))*$/';
|
||||
|
||||
/**
|
||||
* Validates an email address
|
||||
*
|
||||
* @param string $email Email address
|
||||
* @param boolean $checkDomain True if dns check should be performed
|
||||
* @access public
|
||||
* @return boolean true if email is valid
|
||||
*/
|
||||
function validate($email, $checkDomain = false)
|
||||
{
|
||||
if (function_exists('idn_to_ascii')) {
|
||||
if ($parts = explode('@', $email)) {
|
||||
if (sizeof($parts) == 2) {
|
||||
foreach ($parts as &$part) {
|
||||
$part = idn_to_ascii($part);
|
||||
}
|
||||
$email = implode('@', $parts);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fix for bug #10799: add 'D' modifier to regex
|
||||
if (preg_match($this->regex . 'D', $email)) {
|
||||
if ($checkDomain && function_exists('checkdnsrr')) {
|
||||
$tokens = explode('@', $email);
|
||||
if (checkdnsrr($tokens[1], 'MX') || checkdnsrr($tokens[1], 'A')) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} // end func validate
|
||||
|
||||
|
||||
function getValidationScript($options = null)
|
||||
{
|
||||
return array(" var regex = " . $this->regex . ";\n", "{jsVar} != '' && !regex.test({jsVar})");
|
||||
} // end func getValidationScript
|
||||
|
||||
} // end class HTML_QuickForm_Rule_Email
|
||||
?>
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Checks that the length of value is within range
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: Range.php,v 1.8 2009/04/04 21:34:04 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Abstract base class for QuickForm validation rules
|
||||
*/
|
||||
require_once 'HTML/QuickForm/Rule.php';
|
||||
|
||||
/**
|
||||
* Checks that the length of value is within range
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @version Release: 3.2.11
|
||||
* @since 3.2
|
||||
*/
|
||||
class HTML_QuickForm_Rule_Range extends HTML_QuickForm_Rule
|
||||
{
|
||||
/**
|
||||
* Validates a value using a range comparison
|
||||
*
|
||||
* @param string $value Value to be checked
|
||||
* @param mixed $options Int for length, array for range
|
||||
* @access public
|
||||
* @return boolean true if value is valid
|
||||
*/
|
||||
function validate($value, $options)
|
||||
{
|
||||
$length = strlen($value);
|
||||
switch ($this->name) {
|
||||
case 'minlength': return ($length >= $options);
|
||||
case 'maxlength': return ($length <= $options);
|
||||
default: return ($length >= $options[0] && $length <= $options[1]);
|
||||
}
|
||||
} // end func validate
|
||||
|
||||
|
||||
function getValidationScript($options = null)
|
||||
{
|
||||
switch ($this->name) {
|
||||
case 'minlength':
|
||||
$test = '{jsVar}.length < '.$options;
|
||||
break;
|
||||
case 'maxlength':
|
||||
$test = '{jsVar}.length > '.$options;
|
||||
break;
|
||||
default:
|
||||
$test = '({jsVar}.length < '.$options[0].' || {jsVar}.length > '.$options[1].')';
|
||||
}
|
||||
return array('', "{jsVar} != '' && {$test}");
|
||||
} // end func getValidationScript
|
||||
|
||||
} // end class HTML_QuickForm_Rule_Range
|
||||
?>
|
||||
107
sites/all/modules/civicrm/packages/HTML/QuickForm/Rule/Regex.php
Normal file
107
sites/all/modules/civicrm/packages/HTML/QuickForm/Rule/Regex.php
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Validates values using regular expressions
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: Regex.php,v 1.6 2009/04/04 21:34:04 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Abstract base class for QuickForm validation rules
|
||||
*/
|
||||
require_once 'HTML/QuickForm/Rule.php';
|
||||
|
||||
/**
|
||||
* Validates values using regular expressions
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @version Release: 3.2.11
|
||||
* @since 3.2
|
||||
*/
|
||||
class HTML_QuickForm_Rule_Regex extends HTML_QuickForm_Rule
|
||||
{
|
||||
/**
|
||||
* Array of regular expressions
|
||||
*
|
||||
* Array is in the format:
|
||||
* $_data['rulename'] = 'pattern';
|
||||
*
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_data = array(
|
||||
'lettersonly' => '/^[a-zA-Z]+$/',
|
||||
'alphanumeric' => '/^[a-zA-Z0-9]+$/',
|
||||
'numeric' => '/(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/',
|
||||
'nopunctuation' => '/^[^().\/\*\^\?#!@$%+=,\"\'><~\[\]{}]+$/',
|
||||
'nonzero' => '/^-?[1-9][0-9]*/'
|
||||
);
|
||||
|
||||
/**
|
||||
* Validates a value using a regular expression
|
||||
*
|
||||
* @param string $value Value to be checked
|
||||
* @param string $regex Regular expression
|
||||
* @access public
|
||||
* @return boolean true if value is valid
|
||||
*/
|
||||
function validate($value, $regex = null)
|
||||
{
|
||||
// Fix for bug #10799: add 'D' modifier to regex
|
||||
if (isset($this->_data[$this->name])) {
|
||||
if (!preg_match($this->_data[$this->name] . 'D', $value)) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!preg_match($regex . 'D', $value)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} // end func validate
|
||||
|
||||
/**
|
||||
* Adds new regular expressions to the list
|
||||
*
|
||||
* @param string $name Name of rule
|
||||
* @param string $pattern Regular expression pattern
|
||||
* @access public
|
||||
*/
|
||||
function addData($name, $pattern)
|
||||
{
|
||||
$this->_data[$name] = $pattern;
|
||||
} // end func addData
|
||||
|
||||
|
||||
function getValidationScript($options = null)
|
||||
{
|
||||
$regex = isset($this->_data[$this->name]) ? $this->_data[$this->name] : $options;
|
||||
|
||||
// bug #12376, converting unicode escapes and stripping 'u' modifier
|
||||
if ($pos = strpos($regex, 'u', strrpos($regex, '/'))) {
|
||||
$regex = substr($regex, 0, $pos) . substr($regex, $pos + 1);
|
||||
$regex = preg_replace('/(?<!\\\\)(?>\\\\\\\\)*\\\\x{([a-fA-F0-9]+)}/', '\\u$1', $regex);
|
||||
}
|
||||
|
||||
return array(" var regex = " . $regex . ";\n", "{jsVar} != '' && !regex.test({jsVar})");
|
||||
} // end func getValidationScript
|
||||
|
||||
} // end class HTML_QuickForm_Rule_Regex
|
||||
?>
|
||||
|
|
@ -0,0 +1,86 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Required elements validation
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: Required.php,v 1.6 2009/04/04 21:34:04 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Abstract base class for QuickForm validation rules
|
||||
*/
|
||||
require_once 'HTML/QuickForm/Rule.php';
|
||||
|
||||
/**
|
||||
* Required elements validation
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @version Release: 3.2.11
|
||||
* @since 3.2
|
||||
*/
|
||||
class HTML_QuickForm_Rule_Required extends HTML_QuickForm_Rule
|
||||
{
|
||||
/**
|
||||
* Checks if an element is empty
|
||||
*
|
||||
* @param string $value Value to check
|
||||
* @param mixed $options Not used yet
|
||||
* @access public
|
||||
* @return boolean true if value is not empty
|
||||
*/
|
||||
function validate($value, $options = null)
|
||||
{
|
||||
if ( is_array( $value ) ) {
|
||||
// check if file type, if so permit empty type
|
||||
$fileType =
|
||||
array_key_exists( 'name', $value ) &&
|
||||
array_key_exists( 'tmp_name', $value );
|
||||
// hack to fix required issue with advcheckbox, but in general if any value is present then
|
||||
// it should pass required check
|
||||
$return = false;
|
||||
foreach ( $value as $k => $v ) {
|
||||
// dont check type field. Safari3 Beta does not set this
|
||||
if ( $fileType && $k == 'type' ) {
|
||||
continue;
|
||||
}
|
||||
if ( is_array($v) ) {
|
||||
if ( $v ) {
|
||||
$return = true;
|
||||
}
|
||||
}
|
||||
elseif ( ( string ) $v != '' ) {
|
||||
$return = true;
|
||||
}
|
||||
}
|
||||
return $return;
|
||||
} else if ((string)$value == '') {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} // end func validate
|
||||
|
||||
|
||||
function getValidationScript($options = null)
|
||||
{
|
||||
return array('', "{jsVar} == ''");
|
||||
} // end func getValidationScript
|
||||
|
||||
} // end class HTML_QuickForm_Rule_Required
|
||||
?>
|
||||
|
|
@ -0,0 +1,349 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Registers rule objects and uses them for validation
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: RuleRegistry.php,v 1.19 2009/04/04 21:34:02 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Registers rule objects and uses them for validation
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @version Release: 3.2.11
|
||||
* @since 3.2
|
||||
*/
|
||||
class HTML_QuickForm_RuleRegistry
|
||||
{
|
||||
/**
|
||||
* Array containing references to used rules
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_rules = array();
|
||||
|
||||
|
||||
/**
|
||||
* Returns a singleton of HTML_QuickForm_RuleRegistry
|
||||
*
|
||||
* Usually, only one RuleRegistry object is needed, this is the reason
|
||||
* why it is recommended to use this method to get the validation object.
|
||||
*
|
||||
* @access public
|
||||
* @static
|
||||
* @return HTML_QuickForm_RuleRegistry
|
||||
*/
|
||||
static function &singleton()
|
||||
{
|
||||
static $obj;
|
||||
if (!isset($obj)) {
|
||||
$obj = new HTML_QuickForm_RuleRegistry();
|
||||
}
|
||||
return $obj;
|
||||
} // end func singleton
|
||||
|
||||
/**
|
||||
* Registers a new validation rule
|
||||
*
|
||||
* In order to use a custom rule in your form, you need to register it
|
||||
* first. For regular expressions, one can directly use the 'regex' type
|
||||
* rule in addRule(), this is faster than registering the rule.
|
||||
*
|
||||
* Functions and methods can be registered. Use the 'function' type.
|
||||
* When registering a method, specify the class name as second parameter.
|
||||
*
|
||||
* You can also register an HTML_QuickForm_Rule subclass with its own
|
||||
* validate() method.
|
||||
*
|
||||
* @param string $ruleName Name of validation rule
|
||||
* @param string $type Either: 'regex', 'function' or null
|
||||
* @param string $data1 Name of function, regular expression or
|
||||
* HTML_QuickForm_Rule object class name
|
||||
* @param string $data2 Object parent of above function or HTML_QuickForm_Rule file path
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function registerRule($ruleName, $type, $data1, $data2 = null)
|
||||
{
|
||||
$type = strtolower($type);
|
||||
if ($type == 'regex') {
|
||||
// Regular expression
|
||||
$rule =& $this->getRule('regex');
|
||||
$rule->addData($ruleName, $data1);
|
||||
$GLOBALS['_HTML_QuickForm_registered_rules'][$ruleName] = $GLOBALS['_HTML_QuickForm_registered_rules']['regex'];
|
||||
|
||||
} elseif ($type == 'function' || $type == 'callback') {
|
||||
// Callback function
|
||||
$rule =& $this->getRule('callback');
|
||||
$rule->addData($ruleName, $data1, $data2, 'function' == $type);
|
||||
$GLOBALS['_HTML_QuickForm_registered_rules'][$ruleName] = $GLOBALS['_HTML_QuickForm_registered_rules']['callback'];
|
||||
|
||||
} elseif (is_object($data1)) {
|
||||
// An instance of HTML_QuickForm_Rule
|
||||
$this->_rules[strtolower(get_class($data1))] = $data1;
|
||||
$GLOBALS['_HTML_QuickForm_registered_rules'][$ruleName] = array(strtolower(get_class($data1)), null);
|
||||
|
||||
} else {
|
||||
// Rule class name
|
||||
$GLOBALS['_HTML_QuickForm_registered_rules'][$ruleName] = array(strtolower($data1), $data2);
|
||||
}
|
||||
} // end func registerRule
|
||||
|
||||
/**
|
||||
* Returns a reference to the requested rule object
|
||||
*
|
||||
* @param string $ruleName Name of the requested rule
|
||||
* @access public
|
||||
* @return HTML_QuickForm_Rule
|
||||
*/
|
||||
function &getRule($ruleName)
|
||||
{
|
||||
list($class, $path) = $GLOBALS['_HTML_QuickForm_registered_rules'][$ruleName];
|
||||
|
||||
if (!isset($this->_rules[$class])) {
|
||||
if (!empty($path)) {
|
||||
include_once($path);
|
||||
}
|
||||
$this->_rules[$class] = new $class();
|
||||
}
|
||||
$this->_rules[$class]->setName($ruleName);
|
||||
return $this->_rules[$class];
|
||||
} // end func getRule
|
||||
|
||||
/**
|
||||
* Performs validation on the given values
|
||||
*
|
||||
* @param string $ruleName Name of the rule to be used
|
||||
* @param mixed $values Can be a scalar or an array of values
|
||||
* to be validated
|
||||
* @param mixed $options Options used by the rule
|
||||
* @param mixed $multiple Whether to validate an array of values altogether
|
||||
* @access public
|
||||
* @return mixed true if no error found, int of valid values (when an array of values is given) or false if error
|
||||
*/
|
||||
function validate($ruleName, $values, $options = null, $multiple = false)
|
||||
{
|
||||
$rule =& $this->getRule($ruleName);
|
||||
|
||||
if (is_array($values) && !$multiple) {
|
||||
$result = 0;
|
||||
foreach ($values as $value) {
|
||||
if ($rule->validate($value, $options) === true) {
|
||||
$result++;
|
||||
}
|
||||
}
|
||||
return ($result == 0) ? false : $result;
|
||||
} else {
|
||||
return $rule->validate($values, $options);
|
||||
}
|
||||
} // end func validate
|
||||
|
||||
/**
|
||||
* Returns the validation test in javascript code
|
||||
*
|
||||
* @param array|HTML_QuickForm_element Element(s) the rule applies to
|
||||
* @param string Element name, in case $element is
|
||||
* not an array
|
||||
* @param array Rule data
|
||||
* @access public
|
||||
* @return string JavaScript for the rule
|
||||
*/
|
||||
function getValidationScript(&$element, $elementName, $ruleData)
|
||||
{
|
||||
$reset = (isset($ruleData['reset'])) ? $ruleData['reset'] : false;
|
||||
$rule =& $this->getRule($ruleData['type']);
|
||||
if (!is_array($element)) {
|
||||
list($jsValue, $jsReset) = $this->_getJsValue($element, $elementName, $reset, null);
|
||||
} else {
|
||||
$jsValue = " value = new Array();\n";
|
||||
$jsReset = '';
|
||||
for ($i = 0; $i < count($element); $i++) {
|
||||
list($tmp_value, $tmp_reset) = $this->_getJsValue($element[$i], $element[$i]->getName(), $reset, $i);
|
||||
$jsValue .= "\n" . $tmp_value;
|
||||
$jsReset .= $tmp_reset;
|
||||
}
|
||||
}
|
||||
$jsField = isset($ruleData['group'])? $ruleData['group']: $elementName;
|
||||
list ($jsPrefix, $jsCheck) = $rule->getValidationScript($ruleData['format']);
|
||||
if (!isset($ruleData['howmany'])) {
|
||||
$js = $jsValue . "\n" . $jsPrefix .
|
||||
" if (" . str_replace('{jsVar}', 'value', $jsCheck) . " && !errFlag['{$jsField}']) {\n" .
|
||||
" errFlag['{$jsField}'] = true;\n" .
|
||||
" _qfMsg = _qfMsg + '\\n - {$ruleData['message']}';\n" .
|
||||
$jsReset .
|
||||
" }\n";
|
||||
} else {
|
||||
$js = $jsValue . "\n" . $jsPrefix .
|
||||
" var res = 0;\n" .
|
||||
" for (var i = 0; i < value.length; i++) {\n" .
|
||||
" if (!(" . str_replace('{jsVar}', 'value[i]', $jsCheck) . ")) {\n" .
|
||||
" res++;\n" .
|
||||
" }\n" .
|
||||
" }\n" .
|
||||
" if (res < {$ruleData['howmany']} && !errFlag['{$jsField}']) {\n" .
|
||||
" errFlag['{$jsField}'] = true;\n" .
|
||||
" _qfMsg = _qfMsg + '\\n - {$ruleData['message']}';\n" .
|
||||
$jsReset .
|
||||
" }\n";
|
||||
}
|
||||
return $js;
|
||||
} // end func getValidationScript
|
||||
|
||||
|
||||
/**
|
||||
* Returns JavaScript to get and to reset the element's value
|
||||
*
|
||||
* @access private
|
||||
* @param HTML_QuickForm_element element being processed
|
||||
* @param string element's name
|
||||
* @param bool whether to generate JavaScript to reset
|
||||
* the value
|
||||
* @param integer value's index in the array (only used for
|
||||
* multielement rules)
|
||||
* @return array first item is value javascript, second is reset
|
||||
*/
|
||||
function _getJsValue(&$element, $elementName, $reset = false, $index = null)
|
||||
{
|
||||
$jsIndex = isset($index)? '[' . $index . ']': '';
|
||||
$tmp_reset = $reset? " var field = frm.elements['$elementName'];\n": '';
|
||||
if (is_a($element, 'html_quickform_group')) {
|
||||
$value = " _qfGroups['{$elementName}'] = {";
|
||||
$elements =& $element->getElements();
|
||||
for ($i = 0, $count = count($elements); $i < $count; $i++) {
|
||||
$append = ($elements[$i]->getType() == 'select' && $elements[$i]->getMultiple())? '[]': '';
|
||||
$value .= "'" . $element->getElementName($i) . $append . "': true" .
|
||||
($i < $count - 1? ', ': '');
|
||||
}
|
||||
$value .=
|
||||
"};\n" .
|
||||
" value{$jsIndex} = new Array();\n" .
|
||||
" var valueIdx = 0;\n" .
|
||||
" for (var i = 0; i < frm.elements.length; i++) {\n" .
|
||||
" var _element = frm.elements[i];\n" .
|
||||
" if (_element.name in _qfGroups['{$elementName}']) {\n" .
|
||||
" switch (_element.type) {\n" .
|
||||
" case 'checkbox':\n" .
|
||||
" case 'radio':\n" .
|
||||
" if (_element.checked) {\n" .
|
||||
" value{$jsIndex}[valueIdx++] = _element.value;\n" .
|
||||
" }\n" .
|
||||
" break;\n" .
|
||||
" case 'select-one':\n" .
|
||||
" if (-1 != _element.selectedIndex) {\n" .
|
||||
" value{$jsIndex}[valueIdx++] = _element.options[_element.selectedIndex].value;\n" .
|
||||
" }\n" .
|
||||
" break;\n" .
|
||||
" case 'select-multiple':\n" .
|
||||
" var tmpVal = new Array();\n" .
|
||||
" var tmpIdx = 0;\n" .
|
||||
" for (var j = 0; j < _element.options.length; j++) {\n" .
|
||||
" if (_element.options[j].selected) {\n" .
|
||||
" tmpVal[tmpIdx++] = _element.options[j].value;\n" .
|
||||
" }\n" .
|
||||
" }\n" .
|
||||
" if (tmpIdx > 0) {\n" .
|
||||
" value{$jsIndex}[valueIdx++] = tmpVal;\n" .
|
||||
" }\n" .
|
||||
" break;\n" .
|
||||
" default:\n" .
|
||||
" value{$jsIndex}[valueIdx++] = _element.value;\n" .
|
||||
" }\n" .
|
||||
" }\n" .
|
||||
" }\n";
|
||||
if ($reset) {
|
||||
$tmp_reset =
|
||||
" for (var i = 0; i < frm.elements.length; i++) {\n" .
|
||||
" var _element = frm.elements[i];\n" .
|
||||
" if (_element.name in _qfGroups['{$elementName}']) {\n" .
|
||||
" switch (_element.type) {\n" .
|
||||
" case 'checkbox':\n" .
|
||||
" case 'radio':\n" .
|
||||
" _element.checked = _element.defaultChecked;\n" .
|
||||
" break;\n" .
|
||||
" case 'select-one':\n" .
|
||||
" case 'select-multiple':\n" .
|
||||
" for (var j = 0; j < _element.options.length; j++) {\n" .
|
||||
" _element.options[j].selected = _element.options[j].defaultSelected;\n" .
|
||||
" }\n" .
|
||||
" break;\n" .
|
||||
" default:\n" .
|
||||
" _element.value = _element.defaultValue;\n" .
|
||||
" }\n" .
|
||||
" }\n" .
|
||||
" }\n";
|
||||
}
|
||||
|
||||
} elseif ($element->getType() == 'select') {
|
||||
if ($element->getMultiple()) {
|
||||
$elementName .= '[]';
|
||||
$value =
|
||||
" value{$jsIndex} = new Array();\n" .
|
||||
" var valueIdx = 0;\n" .
|
||||
" for (var i = 0; i < frm.elements['{$elementName}'].options.length; i++) {\n" .
|
||||
" if (frm.elements['{$elementName}'].options[i].selected) {\n" .
|
||||
" value{$jsIndex}[valueIdx++] = frm.elements['{$elementName}'].options[i].value;\n" .
|
||||
" }\n" .
|
||||
" }\n";
|
||||
} else {
|
||||
$value = " value{$jsIndex} = frm.elements['{$elementName}'].selectedIndex == -1? '': frm.elements['{$elementName}'].options[frm.elements['{$elementName}'].selectedIndex].value;\n";
|
||||
}
|
||||
if ($reset) {
|
||||
$tmp_reset .=
|
||||
" for (var i = 0; i < field.options.length; i++) {\n" .
|
||||
" field.options[i].selected = field.options[i].defaultSelected;\n" .
|
||||
" }\n";
|
||||
}
|
||||
|
||||
} elseif ($element->getType() == 'checkbox') {
|
||||
if (is_a($element, 'html_quickform_advcheckbox')) {
|
||||
$value = " value{$jsIndex} = frm.elements['$elementName'][1].checked? frm.elements['$elementName'][1].value: frm.elements['$elementName'][0].value;\n";
|
||||
$tmp_reset .= $reset ? " field[1].checked = field[1].defaultChecked;\n" : '';
|
||||
} else {
|
||||
$value = " value{$jsIndex} = frm.elements['$elementName'].checked? '1': '';\n";
|
||||
$tmp_reset .= $reset ? " field.checked = field.defaultChecked;\n" : '';
|
||||
}
|
||||
|
||||
} elseif ($element->getType() == 'radio') {
|
||||
$value = " value{$jsIndex} = '';\n" .
|
||||
// Fix for bug #5644
|
||||
" var els = 'length' in frm.elements['$elementName']? frm.elements['$elementName']: [ frm.elements['$elementName'] ];\n" .
|
||||
" for (var i = 0; i < els.length; i++) {\n" .
|
||||
" if (els[i].checked) {\n" .
|
||||
" value{$jsIndex} = els[i].value;\n" .
|
||||
" }\n" .
|
||||
" }";
|
||||
if ($reset) {
|
||||
$tmp_reset .= " for (var i = 0; i < field.length; i++) {\n" .
|
||||
" field[i].checked = field[i].defaultChecked;\n" .
|
||||
" }";
|
||||
}
|
||||
|
||||
} else {
|
||||
$value = " value{$jsIndex} = frm.elements['$elementName'].value;";
|
||||
$tmp_reset .= ($reset) ? " field.value = field.defaultValue;\n" : '';
|
||||
}
|
||||
return array($value, $tmp_reset);
|
||||
}
|
||||
} // end class HTML_QuickForm_RuleRegistry
|
||||
?>
|
||||
|
|
@ -0,0 +1,286 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* HTML class for an advanced checkbox type field
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Jason Rust <jrust@php.net>
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: advcheckbox.php,v 1.18 2009/04/04 21:34:02 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* HTML class for a checkbox type field
|
||||
*/
|
||||
require_once 'HTML/QuickForm/checkbox.php';
|
||||
|
||||
/**
|
||||
* HTML class for an advanced checkbox type field
|
||||
*
|
||||
* Basically this fixes a problem that HTML has had
|
||||
* where checkboxes can only pass a single value (the
|
||||
* value of the checkbox when checked). A value for when
|
||||
* the checkbox is not checked cannot be passed, and
|
||||
* furthermore the checkbox variable doesn't even exist if
|
||||
* the checkbox was submitted unchecked.
|
||||
*
|
||||
* It works by prepending a hidden field with the same name and
|
||||
* another "unchecked" value to the checbox. If the checkbox is
|
||||
* checked, PHP overwrites the value of the hidden field with
|
||||
* its value.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Jason Rust <jrust@php.net>
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @version Release: 3.2.11
|
||||
* @since 2.0
|
||||
*/
|
||||
class HTML_QuickForm_advcheckbox extends HTML_QuickForm_checkbox
|
||||
{
|
||||
// {{{ properties
|
||||
|
||||
/**
|
||||
* The values passed by the hidden elment
|
||||
*
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_values = null;
|
||||
|
||||
/**
|
||||
* The default value
|
||||
*
|
||||
* @var boolean
|
||||
* @access private
|
||||
*/
|
||||
var $_currentValue = null;
|
||||
|
||||
// }}}
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string $elementName (optional)Input field name attribute
|
||||
* @param string $elementLabel (optional)Input field label
|
||||
* @param string $text (optional)Text to put after the checkbox
|
||||
* @param mixed $attributes (optional)Either a typical HTML attribute string
|
||||
* or an associative array
|
||||
* @param mixed $values (optional)Values to pass if checked or not checked
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function __construct($elementName=null, $elementLabel=null, $text=null, $attributes=null, $values=null)
|
||||
{
|
||||
parent::__construct($elementName, $elementLabel, $text, $attributes);
|
||||
$this->setValues($values);
|
||||
} //end constructor
|
||||
|
||||
// }}}
|
||||
// {{{ getPrivateName()
|
||||
|
||||
/**
|
||||
* Gets the private name for the element
|
||||
*
|
||||
* @param string $elementName The element name to make private
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*
|
||||
* @deprecated Deprecated since 3.2.6, both generated elements have the same name
|
||||
*/
|
||||
function getPrivateName($elementName)
|
||||
{
|
||||
return '__'.$elementName;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ getOnclickJs()
|
||||
|
||||
/**
|
||||
* Create the javascript for the onclick event which will
|
||||
* set the value of the hidden field
|
||||
*
|
||||
* @param string $elementName The element name
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*
|
||||
* @deprecated Deprecated since 3.2.6, this element no longer uses any javascript
|
||||
*/
|
||||
function getOnclickJs($elementName)
|
||||
{
|
||||
$onclickJs = 'if (this.checked) { this.form[\''.$elementName.'\'].value=\''.addcslashes($this->_values[1], '\'').'\'; }';
|
||||
$onclickJs .= 'else { this.form[\''.$elementName.'\'].value=\''.addcslashes($this->_values[0], '\'').'\'; }';
|
||||
return $onclickJs;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ setValues()
|
||||
|
||||
/**
|
||||
* Sets the values used by the hidden element
|
||||
*
|
||||
* @param mixed $values The values, either a string or an array
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setValues($values)
|
||||
{
|
||||
if (empty($values)) {
|
||||
// give it default checkbox behavior
|
||||
$this->_values = array('', 1);
|
||||
} elseif (is_scalar($values)) {
|
||||
// if it's string, then assume the value to
|
||||
// be passed is for when the element is checked
|
||||
$this->_values = array('', $values);
|
||||
} else {
|
||||
$this->_values = $values;
|
||||
}
|
||||
$this->updateAttributes(array('value' => $this->_values[1]));
|
||||
$this->setChecked($this->_currentValue == $this->_values[1]);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ setValue()
|
||||
|
||||
/**
|
||||
* Sets the element's value
|
||||
*
|
||||
* @param mixed Element's value
|
||||
* @access public
|
||||
*/
|
||||
function setValue($value)
|
||||
{
|
||||
$this->setChecked(isset($this->_values[1]) && $value == $this->_values[1]);
|
||||
$this->_currentValue = $value;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ getValue()
|
||||
|
||||
/**
|
||||
* Returns the element's value
|
||||
*
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
function getValue()
|
||||
{
|
||||
if (is_array($this->_values)) {
|
||||
return $this->_values[$this->getChecked()? 1: 0];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ toHtml()
|
||||
|
||||
/**
|
||||
* Returns the checkbox element in HTML
|
||||
* and the additional hidden element in HTML
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function toHtml()
|
||||
{
|
||||
if ($this->_flagFrozen) {
|
||||
return parent::toHtml();
|
||||
} else {
|
||||
return '<input' . $this->_getAttrString(array(
|
||||
'type' => 'hidden',
|
||||
'name' => $this->getName(),
|
||||
'value' => $this->_values[0]
|
||||
)) . ' />' . parent::toHtml();
|
||||
|
||||
}
|
||||
} //end func toHtml
|
||||
|
||||
// }}}
|
||||
// {{{ getFrozenHtml()
|
||||
|
||||
/**
|
||||
* Unlike checkbox, this has to append a hidden input in both
|
||||
* checked and non-checked states
|
||||
*/
|
||||
function getFrozenHtml()
|
||||
{
|
||||
return ($this->getChecked()? '<tt>[x]</tt>': '<tt>[ ]</tt>') .
|
||||
$this->_getPersistantData();
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ onQuickFormEvent()
|
||||
|
||||
/**
|
||||
* Called by HTML_QuickForm whenever form event is made on this element
|
||||
*
|
||||
* @param string $event Name of event
|
||||
* @param mixed $arg event arguments
|
||||
* @param object &$caller calling object
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function onQuickFormEvent($event, $arg, &$caller)
|
||||
{
|
||||
switch ($event) {
|
||||
case 'updateValue':
|
||||
// constant values override both default and submitted ones
|
||||
// default values are overriden by submitted
|
||||
$value = $this->_findValue($caller->_constantValues);
|
||||
if (null === $value) {
|
||||
$value = $this->_findValue($caller->_submitValues);
|
||||
if (null === $value) {
|
||||
$value = $this->_findValue($caller->_defaultValues);
|
||||
}
|
||||
}
|
||||
if (null !== $value) {
|
||||
$this->setValue($value);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
parent::onQuickFormEvent($event, $arg, $caller);
|
||||
}
|
||||
return true;
|
||||
} // end func onQuickFormLoad
|
||||
|
||||
// }}}
|
||||
// {{{ exportValue()
|
||||
|
||||
/**
|
||||
* This element has a value even if it is not checked, thus we override
|
||||
* checkbox's behaviour here
|
||||
*/
|
||||
function exportValue(&$submitValues, $assoc = false)
|
||||
{
|
||||
$value = $this->_findValue($submitValues);
|
||||
if (null === $value) {
|
||||
$value = $this->getValue();
|
||||
} elseif (is_array($this->_values) && ($value != $this->_values[0]) && ($value != $this->_values[1])) {
|
||||
$value = null;
|
||||
}
|
||||
return $this->_prepareValue($value, $assoc);
|
||||
}
|
||||
// }}}
|
||||
} //end class HTML_QuickForm_advcheckbox
|
||||
?>
|
||||
1180
sites/all/modules/civicrm/packages/HTML/QuickForm/advmultiselect.php
Normal file
1180
sites/all/modules/civicrm/packages/HTML/QuickForm/advmultiselect.php
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -0,0 +1,258 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* HTML class for an autocomplete element
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Matteo Di Giovinazzo <matteodg@infinito.it>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: autocomplete.php,v 1.8 2009/04/04 21:34:02 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* HTML class for a text field
|
||||
*/
|
||||
require_once 'HTML/QuickForm/text.php';
|
||||
|
||||
/**
|
||||
* HTML class for an autocomplete element
|
||||
*
|
||||
* Creates an HTML input text element that
|
||||
* at every keypressed javascript event checks in an array of options
|
||||
* if there's a match and autocompletes the text in case of match.
|
||||
*
|
||||
* For the JavaScript code thanks to Martin Honnen and Nicholas C. Zakas
|
||||
* See {@link http://www.faqts.com/knowledge_base/view.phtml/aid/13562} and
|
||||
* {@link http://www.sitepoint.com/article/1220}
|
||||
*
|
||||
* Example:
|
||||
* <code>
|
||||
* $autocomplete =& $form->addElement('autocomplete', 'fruit', 'Favourite fruit:');
|
||||
* $options = array("Apple", "Orange", "Pear", "Strawberry");
|
||||
* $autocomplete->setOptions($options);
|
||||
* </code>
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Matteo Di Giovinazzo <matteodg@infinito.it>
|
||||
* @version Release: 3.2.11
|
||||
* @since 3.2
|
||||
*/
|
||||
class HTML_QuickForm_autocomplete extends HTML_QuickForm_text
|
||||
{
|
||||
// {{{ properties
|
||||
|
||||
/**
|
||||
* Options for the autocomplete input text element
|
||||
*
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_options = array();
|
||||
|
||||
/**
|
||||
* "One-time" javascript (containing functions), see bug #4611
|
||||
*
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_js = '';
|
||||
|
||||
// }}}
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string $elementName (optional)Input field name attribute
|
||||
* @param string $elementLabel (optional)Input field label in form
|
||||
* @param array $options (optional)Autocomplete options
|
||||
* @param mixed $attributes (optional)Either a typical HTML attribute string
|
||||
* or an associative array. Date format is passed along the attributes.
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function __construct($elementName = null, $elementLabel = null, $options = null, $attributes = null)
|
||||
{
|
||||
parent::__construct($elementName, $elementLabel, $attributes);
|
||||
$this->_persistantFreeze = true;
|
||||
$this->_type = 'autocomplete';
|
||||
if (isset($options)) {
|
||||
$this->setOptions($options);
|
||||
}
|
||||
} //end constructor
|
||||
|
||||
// }}}
|
||||
// {{{ setOptions()
|
||||
|
||||
/**
|
||||
* Sets the options for the autocomplete input text element
|
||||
*
|
||||
* @param array $options Array of options for the autocomplete input text element
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setOptions($options)
|
||||
{
|
||||
$this->_options = array_values($options);
|
||||
} // end func setOptions
|
||||
|
||||
// }}}
|
||||
// {{{ toHtml()
|
||||
|
||||
/**
|
||||
* Returns Html for the autocomplete input text element
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function toHtml()
|
||||
{
|
||||
// prevent problems with grouped elements
|
||||
$arrayName = str_replace(array('[', ']'), array('__', ''), $this->getName()) . '_values';
|
||||
|
||||
$this->updateAttributes(array(
|
||||
'onkeypress' => 'return autocomplete(this, event, ' . $arrayName . ');'
|
||||
));
|
||||
if ($this->_flagFrozen) {
|
||||
$js = '';
|
||||
} else {
|
||||
$js = "<script type=\"text/javascript\">\n//<![CDATA[\n";
|
||||
if (!defined('HTML_QUICKFORM_AUTOCOMPLETE_EXISTS')) {
|
||||
$this->_js .= <<<EOS
|
||||
|
||||
/* begin javascript for autocomplete */
|
||||
function setSelectionRange(input, selectionStart, selectionEnd) {
|
||||
if (input.setSelectionRange) {
|
||||
input.setSelectionRange(selectionStart, selectionEnd);
|
||||
}
|
||||
else if (input.createTextRange) {
|
||||
var range = input.createTextRange();
|
||||
range.collapse(true);
|
||||
range.moveEnd("character", selectionEnd);
|
||||
range.moveStart("character", selectionStart);
|
||||
range.select();
|
||||
}
|
||||
input.focus();
|
||||
}
|
||||
|
||||
function setCaretToPosition(input, position) {
|
||||
setSelectionRange(input, position, position);
|
||||
}
|
||||
|
||||
function replaceSelection (input, replaceString) {
|
||||
var len = replaceString.length;
|
||||
if (input.setSelectionRange) {
|
||||
var selectionStart = input.selectionStart;
|
||||
var selectionEnd = input.selectionEnd;
|
||||
|
||||
input.value = input.value.substring(0, selectionStart) + replaceString + input.value.substring(selectionEnd);
|
||||
input.selectionStart = selectionStart + len;
|
||||
input.selectionEnd = selectionStart + len;
|
||||
}
|
||||
else if (document.selection) {
|
||||
var range = document.selection.createRange();
|
||||
var saved_range = range.duplicate();
|
||||
|
||||
if (range.parentElement() == input) {
|
||||
range.text = replaceString;
|
||||
range.moveEnd("character", saved_range.selectionStart + len);
|
||||
range.moveStart("character", saved_range.selectionStart + len);
|
||||
range.select();
|
||||
}
|
||||
}
|
||||
input.focus();
|
||||
}
|
||||
|
||||
|
||||
function autocompleteMatch (text, values) {
|
||||
for (var i = 0; i < values.length; i++) {
|
||||
if (values[i].toUpperCase().indexOf(text.toUpperCase()) == 0) {
|
||||
return values[i];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function autocomplete(textbox, event, values) {
|
||||
if (textbox.setSelectionRange || textbox.createTextRange) {
|
||||
switch (event.keyCode) {
|
||||
case 38: // up arrow
|
||||
case 40: // down arrow
|
||||
case 37: // left arrow
|
||||
case 39: // right arrow
|
||||
case 33: // page up
|
||||
case 34: // page down
|
||||
case 36: // home
|
||||
case 35: // end
|
||||
case 13: // enter
|
||||
case 9: // tab
|
||||
case 27: // esc
|
||||
case 16: // shift
|
||||
case 17: // ctrl
|
||||
case 18: // alt
|
||||
case 20: // caps lock
|
||||
case 8: // backspace
|
||||
case 46: // delete
|
||||
return true;
|
||||
break;
|
||||
|
||||
default:
|
||||
var c = String.fromCharCode(
|
||||
(event.charCode == undefined) ? event.keyCode : event.charCode
|
||||
);
|
||||
replaceSelection(textbox, c);
|
||||
sMatch = autocompleteMatch(textbox.value, values);
|
||||
var len = textbox.value.length;
|
||||
|
||||
if (sMatch != null) {
|
||||
textbox.value = sMatch;
|
||||
setSelectionRange(textbox, len, textbox.value.length);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
/* end javascript for autocomplete */
|
||||
|
||||
EOS;
|
||||
define('HTML_QUICKFORM_AUTOCOMPLETE_EXISTS', true);
|
||||
}
|
||||
$jsEscape = array(
|
||||
"\r" => '\r',
|
||||
"\n" => '\n',
|
||||
"\t" => '\t',
|
||||
"'" => "\\'",
|
||||
'"' => '\"',
|
||||
'\\' => '\\\\'
|
||||
);
|
||||
|
||||
$js .= $this->_js;
|
||||
$js .= 'var ' . $arrayName . " = new Array();\n";
|
||||
for ($i = 0; $i < count($this->_options); $i++) {
|
||||
$js .= $arrayName . '[' . $i . "] = '" . strtr($this->_options[$i], $jsEscape) . "';\n";
|
||||
}
|
||||
$js .= "//]]>\n</script>";
|
||||
}
|
||||
return $js . parent::toHtml();
|
||||
}// end func toHtml
|
||||
|
||||
// }}}
|
||||
} // end class HTML_QuickForm_autocomplete
|
||||
?>
|
||||
80
sites/all/modules/civicrm/packages/HTML/QuickForm/button.php
Normal file
80
sites/all/modules/civicrm/packages/HTML/QuickForm/button.php
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* HTML class for an <input type="button" /> elements
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: button.php,v 1.6 2009/04/04 21:34:02 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for <input /> form elements
|
||||
*/
|
||||
require_once 'HTML/QuickForm/input.php';
|
||||
|
||||
/**
|
||||
* HTML class for an <input type="button" /> elements
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @version Release: 3.2.11
|
||||
* @since 1.0
|
||||
*/
|
||||
class HTML_QuickForm_button extends HTML_QuickForm_input
|
||||
{
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string $elementName (optional)Input field name attribute
|
||||
* @param string $value (optional)Input field value
|
||||
* @param mixed $attributes (optional)Either a typical HTML attribute string
|
||||
* or an associative array
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function __construct($elementName=null, $value=null, $attributes=null)
|
||||
{
|
||||
parent::__construct($elementName, null, $attributes);
|
||||
$this->_persistantFreeze = false;
|
||||
$this->setValue($value);
|
||||
$this->setType('button');
|
||||
} //end constructor
|
||||
|
||||
// }}}
|
||||
// {{{ freeze()
|
||||
|
||||
/**
|
||||
* Freeze the element so that only its value is returned
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function freeze()
|
||||
{
|
||||
return false;
|
||||
} //end func freeze
|
||||
|
||||
// }}}
|
||||
|
||||
} //end class HTML_QuickForm_button
|
||||
?>
|
||||
291
sites/all/modules/civicrm/packages/HTML/QuickForm/checkbox.php
Normal file
291
sites/all/modules/civicrm/packages/HTML/QuickForm/checkbox.php
Normal file
|
|
@ -0,0 +1,291 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* HTML class for a checkbox type field
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: checkbox.php,v 1.23 2009/04/04 21:34:02 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for <input /> form elements
|
||||
*/
|
||||
require_once 'HTML/QuickForm/input.php';
|
||||
|
||||
/**
|
||||
* HTML class for a checkbox type field
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @version Release: 3.2.11
|
||||
* @since 1.0
|
||||
*/
|
||||
class HTML_QuickForm_checkbox extends HTML_QuickForm_input
|
||||
{
|
||||
// {{{ properties
|
||||
|
||||
/**
|
||||
* Checkbox display text
|
||||
* @var string
|
||||
* @since 1.1
|
||||
* @access private
|
||||
*/
|
||||
var $_text = '';
|
||||
|
||||
// }}}
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string $elementName (optional)Input field name attribute
|
||||
* @param string $elementLabel (optional)Input field value
|
||||
* @param string $text (optional)Checkbox display text
|
||||
* @param mixed $attributes (optional)Either a typical HTML attribute string
|
||||
* or an associative array
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function __construct($elementName=null, $elementLabel=null, $text='', $attributes=null)
|
||||
{
|
||||
//hack to add 'id' for checkbox
|
||||
if ( !$attributes ) {
|
||||
$attributes = array( 'id' => $elementName );
|
||||
} else {
|
||||
// set element id only if its not set
|
||||
if ( !isset( $attributes['id'] ) ) {
|
||||
$attributes['id'] = $elementName;
|
||||
}
|
||||
}
|
||||
|
||||
parent::__construct($elementName, $elementLabel, $attributes);
|
||||
$this->_persistantFreeze = true;
|
||||
$this->_text = $text;
|
||||
$this->setType('checkbox');
|
||||
$this->updateAttributes(array('value'=>1));
|
||||
$this->_generateId();
|
||||
} //end constructor
|
||||
|
||||
// }}}
|
||||
// {{{ setChecked()
|
||||
|
||||
/**
|
||||
* Sets whether a checkbox is checked
|
||||
*
|
||||
* @param bool $checked Whether the field is checked or not
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setChecked($checked)
|
||||
{
|
||||
if (!$checked) {
|
||||
$this->removeAttribute('checked');
|
||||
} else {
|
||||
$this->updateAttributes(array('checked'=>'checked'));
|
||||
}
|
||||
} //end func setChecked
|
||||
|
||||
// }}}
|
||||
// {{{ getChecked()
|
||||
|
||||
/**
|
||||
* Returns whether a checkbox is checked
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
function getChecked()
|
||||
{
|
||||
return (bool)$this->getAttribute('checked');
|
||||
} //end func getChecked
|
||||
|
||||
// }}}
|
||||
// {{{ toHtml()
|
||||
|
||||
/**
|
||||
* Returns the checkbox element in HTML
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function toHtml()
|
||||
{
|
||||
$attributes = $this->getAttributes();
|
||||
|
||||
if (0 == strlen($this->_text)) {
|
||||
$label = '';
|
||||
} elseif ($this->_flagFrozen || isset( $attributes['skiplabel']) ) {
|
||||
$label = $this->_text;
|
||||
} else {
|
||||
$label = '<label for="' . $this->getAttribute('id') . '">' . $this->_text . '</label>';
|
||||
}
|
||||
|
||||
unset( $attributes['skipLabel'] );
|
||||
return HTML_QuickForm_input::toHtml() . $label;
|
||||
} //end func toHtml
|
||||
|
||||
// }}}
|
||||
// {{{ getFrozenHtml()
|
||||
|
||||
/**
|
||||
* Returns the value of field without HTML tags
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function getFrozenHtml()
|
||||
{
|
||||
if ($this->getChecked()) {
|
||||
return '<tt>[x]</tt>' .
|
||||
$this->_getPersistantData();
|
||||
} else {
|
||||
return '<tt>[ ]</tt>';
|
||||
}
|
||||
} //end func getFrozenHtml
|
||||
|
||||
// }}}
|
||||
// {{{ setText()
|
||||
|
||||
/**
|
||||
* Sets the checkbox text
|
||||
*
|
||||
* @param string $text
|
||||
* @since 1.1
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setText($text)
|
||||
{
|
||||
$this->_text = $text;
|
||||
} //end func setText
|
||||
|
||||
// }}}
|
||||
// {{{ getText()
|
||||
|
||||
/**
|
||||
* Returns the checkbox text
|
||||
*
|
||||
* @since 1.1
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function getText()
|
||||
{
|
||||
return $this->_text;
|
||||
} //end func getText
|
||||
|
||||
// }}}
|
||||
// {{{ setValue()
|
||||
|
||||
/**
|
||||
* Sets the value of the form element
|
||||
*
|
||||
* @param string $value Default value of the form element
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setValue($value)
|
||||
{
|
||||
return $this->setChecked($value);
|
||||
} // end func setValue
|
||||
|
||||
// }}}
|
||||
// {{{ getValue()
|
||||
|
||||
/**
|
||||
* Returns the value of the form element
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
function getValue()
|
||||
{
|
||||
return $this->getChecked();
|
||||
} // end func getValue
|
||||
|
||||
// }}}
|
||||
// {{{ onQuickFormEvent()
|
||||
|
||||
/**
|
||||
* Called by HTML_QuickForm whenever form event is made on this element
|
||||
*
|
||||
* @param string $event Name of event
|
||||
* @param mixed $arg event arguments
|
||||
* @param object &$caller calling object
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function onQuickFormEvent($event, $arg, &$caller)
|
||||
{
|
||||
switch ($event) {
|
||||
case 'updateValue':
|
||||
// constant values override both default and submitted ones
|
||||
// default values are overriden by submitted
|
||||
$value = $this->_findValue($caller->_constantValues);
|
||||
if (null === $value) {
|
||||
// if no boxes were checked, then there is no value in the array
|
||||
// yet we don't want to display default value in this case
|
||||
if ($caller->isSubmitted()) {
|
||||
$value = $this->_findValue($caller->_submitValues);
|
||||
} else {
|
||||
$value = $this->_findValue($caller->_defaultValues);
|
||||
}
|
||||
}
|
||||
if (null !== $value || $caller->isSubmitted()) {
|
||||
$this->setChecked($value);
|
||||
}
|
||||
break;
|
||||
case 'setGroupValue':
|
||||
$this->setChecked($arg);
|
||||
break;
|
||||
default:
|
||||
parent::onQuickFormEvent($event, $arg, $caller);
|
||||
}
|
||||
return true;
|
||||
} // end func onQuickFormEvent
|
||||
|
||||
// }}}
|
||||
// {{{ exportValue()
|
||||
|
||||
/**
|
||||
* Return true if the checkbox is checked, null if it is not checked (getValue() returns false)
|
||||
*/
|
||||
function exportValue(&$submitValues, $assoc = false)
|
||||
{
|
||||
$value = $this->_findValue($submitValues);
|
||||
if (null === $value) {
|
||||
$value = $this->getChecked()? true: null;
|
||||
}
|
||||
return $this->_prepareValue($value, $assoc);
|
||||
}
|
||||
|
||||
// }}}
|
||||
} //end class HTML_QuickForm_checkbox
|
||||
?>
|
||||
399
sites/all/modules/civicrm/packages/HTML/QuickForm/date.php
Normal file
399
sites/all/modules/civicrm/packages/HTML/QuickForm/date.php
Normal file
|
|
@ -0,0 +1,399 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Class for a group of elements used to input dates (and times).
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: date.php,v 1.62 2009/04/04 21:34:02 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class for a group of form elements
|
||||
*/
|
||||
require_once 'HTML/QuickForm/group.php';
|
||||
/**
|
||||
* Class for <select></select> elements
|
||||
*/
|
||||
require_once 'HTML/QuickForm/select.php';
|
||||
|
||||
/**
|
||||
* Class for a group of elements used to input dates (and times).
|
||||
*
|
||||
* Inspired by original 'date' element but reimplemented as a subclass
|
||||
* of HTML_QuickForm_group
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @version Release: 3.2.11
|
||||
* @since 3.1
|
||||
*/
|
||||
class HTML_QuickForm_date extends HTML_QuickForm_group
|
||||
{
|
||||
// {{{ properties
|
||||
|
||||
/**
|
||||
* Various options to control the element's display.
|
||||
*
|
||||
* @access private
|
||||
* @var array
|
||||
*/
|
||||
var $_options = array(
|
||||
'format' => 'dMY',
|
||||
'minYear' => 2001,
|
||||
'maxYear' => 2012,
|
||||
'addEmptyOption' => false,
|
||||
'emptyOptionValue' => '',
|
||||
'emptyOptionText' => ' ',
|
||||
'optionIncrement' => array('i' => 1, 's' => 1)
|
||||
);
|
||||
|
||||
/**
|
||||
* These complement separators, they are appended to the resultant HTML
|
||||
* @access private
|
||||
* @var array
|
||||
*/
|
||||
var $_wrap = array('', '');
|
||||
|
||||
/**
|
||||
* Locale array build from CRM_Utils_Date-provided names
|
||||
*
|
||||
* @access private
|
||||
* @var array
|
||||
*/
|
||||
var $_locale = array();
|
||||
|
||||
// }}}
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* The following keys may appear in $options array:
|
||||
* - 'language': date language
|
||||
* - 'format': Format of the date, based on PHP's date() function.
|
||||
* The following characters are currently recognised in format string:
|
||||
* <pre>
|
||||
* D => Short names of days
|
||||
* l => Long names of days
|
||||
* d => Day numbers
|
||||
* M => Short names of months
|
||||
* F => Long names of months
|
||||
* m => Month numbers
|
||||
* Y => Four digit year
|
||||
* y => Two digit year
|
||||
* h => 12 hour format
|
||||
* H => 23 hour format
|
||||
* i => Minutes
|
||||
* s => Seconds
|
||||
* a => am/pm
|
||||
* A => AM/PM
|
||||
* </pre>
|
||||
* - 'minYear': Minimum year in year select
|
||||
* - 'maxYear': Maximum year in year select
|
||||
* - 'addEmptyOption': Should an empty option be added to the top of
|
||||
* each select box?
|
||||
* - 'emptyOptionValue': The value passed by the empty option.
|
||||
* - 'emptyOptionText': The text displayed for the empty option.
|
||||
* - 'optionIncrement': Step to increase the option values by (works for 'i' and 's')
|
||||
*
|
||||
* @access public
|
||||
* @param string Element's name
|
||||
* @param mixed Label(s) for an element
|
||||
* @param array Options to control the element's display
|
||||
* @param mixed Either a typical HTML attribute string or an associative array
|
||||
*/
|
||||
function __construct($elementName = null, $elementLabel = null, $options = array(), $attributes = null)
|
||||
{
|
||||
$this->_locale = array(
|
||||
'weekdays_short'=> CRM_Utils_Date::getAbbrWeekdayNames(),
|
||||
'weekdays_long' => CRM_Utils_Date::getFullWeekdayNames(),
|
||||
'months_short' => CRM_Utils_Date::getAbbrMonthNames(),
|
||||
'months_long' => CRM_Utils_Date::getFullMonthNames()
|
||||
);
|
||||
parent::__construct($elementName, $elementLabel, null, null, null, $attributes);
|
||||
$this->_persistantFreeze = true;
|
||||
$this->_appendName = true;
|
||||
$this->_type = 'date';
|
||||
// set the options, do not bother setting bogus ones
|
||||
if (is_array($options)) {
|
||||
foreach ($options as $name => $value) {
|
||||
if (isset($this->_options[$name])) {
|
||||
if (is_array($value) && is_array($this->_options[$name])) {
|
||||
$this->_options[$name] = @array_merge($this->_options[$name], $value);
|
||||
} else {
|
||||
$this->_options[$name] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ _createElements()
|
||||
|
||||
function _createElements()
|
||||
{
|
||||
$this->_separator = $this->_elements = array();
|
||||
$separator = '';
|
||||
$locale =& $this->_locale;
|
||||
$backslash = false;
|
||||
for ($i = 0, $length = strlen($this->_options['format']); $i < $length; $i++) {
|
||||
$sign = $this->_options['format']{$i};
|
||||
if ($backslash) {
|
||||
$backslash = false;
|
||||
$separator .= $sign;
|
||||
} else {
|
||||
$loadSelect = true;
|
||||
switch ($sign) {
|
||||
case 'D':
|
||||
// Sunday is 0 like with 'w' in date()
|
||||
$options = $locale['weekdays_short'];
|
||||
$emptyText = ts('-day of week-');
|
||||
break;
|
||||
case 'l':
|
||||
$options = $locale['weekdays_long'];
|
||||
$emptyText = ts('-day of week-');
|
||||
break;
|
||||
case 'd':
|
||||
$options = $this->_createOptionList(1, 31);
|
||||
$emptyText = ts('-day-');
|
||||
break;
|
||||
case 'j':
|
||||
// the no-zero-padding option (CRM-2793)
|
||||
$options = $this->_createOptionList(1, 31, 1, false);
|
||||
$emptyText = ts('-day-');
|
||||
break;
|
||||
case 'M':
|
||||
$options = $locale['months_short'];
|
||||
array_unshift($options , '');
|
||||
unset($options[0]);
|
||||
$emptyText = ts('-month-');
|
||||
break;
|
||||
case 'm':
|
||||
$options = $this->_createOptionList(1, 12);
|
||||
$emptyText = ts('-month-');
|
||||
break;
|
||||
case 'F':
|
||||
$options = $locale['months_long'];
|
||||
array_unshift($options , '');
|
||||
unset($options[0]);
|
||||
$emptyText = ts('-month-');
|
||||
break;
|
||||
case 'Y':
|
||||
$options = $this->_createOptionList(
|
||||
$this->_options['minYear'],
|
||||
$this->_options['maxYear'],
|
||||
$this->_options['minYear'] > $this->_options['maxYear']? -1: 1
|
||||
);
|
||||
$emptyText = ts('-year-');
|
||||
break;
|
||||
case 'y':
|
||||
$options = $this->_createOptionList(
|
||||
$this->_options['minYear'],
|
||||
$this->_options['maxYear'],
|
||||
$this->_options['minYear'] > $this->_options['maxYear']? -1: 1
|
||||
);
|
||||
array_walk($options, create_function('&$v,$k','$v = substr($v,-2);'));
|
||||
$emptyText = ts('-year-');
|
||||
break;
|
||||
case 'h':
|
||||
$options = $this->_createOptionList(1, 12);
|
||||
$emptyText = ts('-hour-');
|
||||
break;
|
||||
case 'g':
|
||||
$options = $this->_createOptionList(1, 12);
|
||||
array_walk($options, create_function('&$v,$k', '$v = intval($v);'));
|
||||
break;
|
||||
case 'H':
|
||||
$options = $this->_createOptionList(0, 23);
|
||||
$emptyText = ts('-hour-');
|
||||
break;
|
||||
case 'i':
|
||||
$options = $this->_createOptionList(0, 59, $this->_options['optionIncrement']['i']);
|
||||
$emptyText = ts('-min-');
|
||||
break;
|
||||
case 's':
|
||||
$options = $this->_createOptionList(0, 59, $this->_options['optionIncrement']['s']);
|
||||
$emptyText = ts('-sec-');
|
||||
break;
|
||||
case 'a':
|
||||
$options = array('am' => 'am', 'pm' => 'pm');
|
||||
$emptyText = '-am/pm-';
|
||||
break;
|
||||
case 'A':
|
||||
$options = array('AM' => 'AM', 'PM' => 'PM');
|
||||
$emptyText = '-AM/PM-';
|
||||
break;
|
||||
case 'W':
|
||||
$options = $this->_createOptionList(1, 53);
|
||||
break;
|
||||
case '\\':
|
||||
$backslash = true;
|
||||
$loadSelect = false;
|
||||
break;
|
||||
default:
|
||||
$separator .= (' ' == $sign? ' ': $sign);
|
||||
$loadSelect = false;
|
||||
}
|
||||
|
||||
if ($loadSelect) {
|
||||
if (0 < count($this->_elements)) {
|
||||
$this->_separator[] = $separator;
|
||||
} else {
|
||||
$this->_wrap[0] = $separator;
|
||||
}
|
||||
$separator = '';
|
||||
// Should we add an empty option to the top of the select?
|
||||
if (!is_array($this->_options['addEmptyOption']) && $this->_options['addEmptyOption'] ||
|
||||
is_array($this->_options['addEmptyOption']) && !empty($this->_options['addEmptyOption'][$sign])) {
|
||||
|
||||
// Using '+' array operator to preserve the keys
|
||||
if (is_array($this->_options['emptyOptionText']) && !empty($this->_options['emptyOptionText'][$sign])) {
|
||||
$text = $emptyText ? $emptyText : $this->_options['emptyOptionText'][$sign];
|
||||
$options = array($this->_options['emptyOptionValue'] => $text) + $options;
|
||||
} else {
|
||||
$text = $emptyText ? $emptyText : $this->_options['emptyOptionText'];
|
||||
$options = array($this->_options['emptyOptionValue'] => $text) + $options;
|
||||
}
|
||||
}
|
||||
|
||||
//modified autogenerated id for date select boxes.
|
||||
$attribs = $this->getAttributes();
|
||||
$elementName = $this->getName();
|
||||
$attribs['id'] = $elementName.'['.$sign.']';
|
||||
|
||||
$this->_elements[] = new HTML_QuickForm_select($sign, null, $options, $attribs);
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->_wrap[1] = $separator . ($backslash? '\\': '');
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ _createOptionList()
|
||||
|
||||
/**
|
||||
* Creates an option list containing the numbers from the start number to the end, inclusive
|
||||
*
|
||||
* @param int The start number
|
||||
* @param int The end number
|
||||
* @param int Increment by this value
|
||||
* @param bool Whether to pad the result with leading zero (CRM-2793)
|
||||
* @access private
|
||||
* @return array An array of numeric options.
|
||||
*/
|
||||
function _createOptionList($start, $end, $step = 1, $pad = true)
|
||||
{
|
||||
for ($i = $start, $options = array(); $start > $end? $i >= $end: $i <= $end; $i += $step) {
|
||||
$options[$i] = $pad ? sprintf('%02d', $i) : sprintf('%d', $i);
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ _trimLeadingZeros()
|
||||
|
||||
/**
|
||||
* Trims leading zeros from the (numeric) string
|
||||
*
|
||||
* @param string A numeric string, possibly with leading zeros
|
||||
* @return string String with leading zeros removed
|
||||
*/
|
||||
function _trimLeadingZeros($str)
|
||||
{
|
||||
if (0 == strcmp($str, $this->_options['emptyOptionValue'])) {
|
||||
return $str;
|
||||
}
|
||||
$trimmed = ltrim($str, '0');
|
||||
return strlen($trimmed)? $trimmed: '0';
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ setValue()
|
||||
|
||||
function setValue($value)
|
||||
{
|
||||
if (empty($value)) {
|
||||
$value = array();
|
||||
} elseif (is_scalar($value)) {
|
||||
if (!is_numeric($value)) {
|
||||
$value = strtotime($value);
|
||||
}
|
||||
// might be a unix epoch, then we fill all possible values
|
||||
$arr = explode('-', date('w-j-n-Y-g-G-i-s-a-A-W', (int)$value));
|
||||
$value = array(
|
||||
'D' => $arr[0],
|
||||
'l' => $arr[0],
|
||||
'd' => $arr[1],
|
||||
'M' => $arr[2],
|
||||
'm' => $arr[2],
|
||||
'F' => $arr[2],
|
||||
'Y' => $arr[3],
|
||||
'y' => $arr[3],
|
||||
'h' => $arr[4],
|
||||
'g' => $arr[4],
|
||||
'H' => $arr[5],
|
||||
'i' => $this->_trimLeadingZeros($arr[6]),
|
||||
's' => $this->_trimLeadingZeros($arr[7]),
|
||||
'a' => $arr[8],
|
||||
'A' => $arr[9],
|
||||
'W' => $this->_trimLeadingZeros($arr[10])
|
||||
);
|
||||
} else {
|
||||
$value = array_map(array($this, '_trimLeadingZeros'), $value);
|
||||
}
|
||||
parent::setValue($value);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ toHtml()
|
||||
|
||||
function toHtml()
|
||||
{
|
||||
include_once('HTML/QuickForm/Renderer/Default.php');
|
||||
$renderer = new HTML_QuickForm_Renderer_Default();
|
||||
$renderer->setElementTemplate('{element}');
|
||||
parent::accept($renderer);
|
||||
return $this->_wrap[0] . $renderer->toHtml() . $this->_wrap[1];
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ accept()
|
||||
|
||||
function accept(&$renderer, $required = false, $error = null)
|
||||
{
|
||||
$renderer->renderElement($this, $required, $error);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ onQuickFormEvent()
|
||||
|
||||
function onQuickFormEvent($event, $arg, &$caller)
|
||||
{
|
||||
if ('updateValue' == $event) {
|
||||
// we need to call setValue(), 'cause the default/constant value
|
||||
// may be in fact a timestamp, not an array
|
||||
return HTML_QuickForm_element::onQuickFormEvent($event, $arg, $caller);
|
||||
} else {
|
||||
return parent::onQuickFormEvent($event, $arg, $caller);
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
}
|
||||
?>
|
||||
493
sites/all/modules/civicrm/packages/HTML/QuickForm/element.php
Normal file
493
sites/all/modules/civicrm/packages/HTML/QuickForm/element.php
Normal file
|
|
@ -0,0 +1,493 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Base class for form elements
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: element.php,v 1.37 2009/04/04 21:34:02 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for all HTML classes
|
||||
*/
|
||||
require_once 'HTML/Common.php';
|
||||
|
||||
/**
|
||||
* Base class for form elements
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @version Release: 3.2.11
|
||||
* @since 1.0
|
||||
* @abstract
|
||||
*/
|
||||
class HTML_QuickForm_element extends HTML_Common
|
||||
{
|
||||
// {{{ properties
|
||||
|
||||
/**
|
||||
* Label of the field
|
||||
* @var string
|
||||
* @since 1.3
|
||||
* @access private
|
||||
*/
|
||||
var $_label = '';
|
||||
|
||||
/**
|
||||
* Form element type
|
||||
* @var string
|
||||
* @since 1.0
|
||||
* @access private
|
||||
*/
|
||||
var $_type = '';
|
||||
|
||||
/**
|
||||
* Flag to tell if element is frozen
|
||||
* @var boolean
|
||||
* @since 1.0
|
||||
* @access private
|
||||
*/
|
||||
var $_flagFrozen = false;
|
||||
|
||||
/**
|
||||
* Does the element support persistant data when frozen
|
||||
* @var boolean
|
||||
* @since 1.3
|
||||
* @access private
|
||||
*/
|
||||
var $_persistantFreeze = false;
|
||||
|
||||
// }}}
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string Name of the element
|
||||
* @param mixed Label(s) for the element
|
||||
* @param mixed Associative array of tag attributes or HTML attributes name="value" pairs
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function __construct($elementName=null, $elementLabel=null, $attributes=null)
|
||||
{
|
||||
parent::__construct($attributes);
|
||||
if (isset($elementName)) {
|
||||
$this->setName($elementName);
|
||||
}
|
||||
if (isset($elementLabel)) {
|
||||
$this->setLabel($elementLabel);
|
||||
}
|
||||
} //end constructor
|
||||
|
||||
// }}}
|
||||
// {{{ apiVersion()
|
||||
|
||||
/**
|
||||
* Returns the current API version
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return float
|
||||
*/
|
||||
function apiVersion()
|
||||
{
|
||||
return 3.2;
|
||||
} // end func apiVersion
|
||||
|
||||
// }}}
|
||||
// {{{ getType()
|
||||
|
||||
/**
|
||||
* Returns element type
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function getType()
|
||||
{
|
||||
return $this->_type;
|
||||
} // end func getType
|
||||
|
||||
// }}}
|
||||
// {{{ setName()
|
||||
|
||||
/**
|
||||
* Sets the input field name
|
||||
*
|
||||
* @param string $name Input field name attribute
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setName($name)
|
||||
{
|
||||
// interface method
|
||||
} //end func setName
|
||||
|
||||
// }}}
|
||||
// {{{ getName()
|
||||
|
||||
/**
|
||||
* Returns the element name
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function getName()
|
||||
{
|
||||
// interface method
|
||||
} //end func getName
|
||||
|
||||
// }}}
|
||||
// {{{ setValue()
|
||||
|
||||
/**
|
||||
* Sets the value of the form element
|
||||
*
|
||||
* @param string $value Default value of the form element
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setValue($value)
|
||||
{
|
||||
// interface
|
||||
} // end func setValue
|
||||
|
||||
// }}}
|
||||
// {{{ getValue()
|
||||
|
||||
/**
|
||||
* Returns the value of the form element
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
function getValue()
|
||||
{
|
||||
// interface
|
||||
return null;
|
||||
} // end func getValue
|
||||
|
||||
// }}}
|
||||
// {{{ freeze()
|
||||
|
||||
/**
|
||||
* Freeze the element so that only its value is returned
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function freeze()
|
||||
{
|
||||
$this->_flagFrozen = true;
|
||||
} //end func freeze
|
||||
|
||||
// }}}
|
||||
// {{{ unfreeze()
|
||||
|
||||
/**
|
||||
* Unfreezes the element so that it becomes editable
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @since 3.2.4
|
||||
*/
|
||||
function unfreeze()
|
||||
{
|
||||
$this->_flagFrozen = false;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ getFrozenHtml()
|
||||
|
||||
/**
|
||||
* Returns the value of field without HTML tags
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function getFrozenHtml()
|
||||
{
|
||||
$value = $this->getValue();
|
||||
return (strlen($value)? htmlspecialchars($value): ' ') .
|
||||
$this->_getPersistantData();
|
||||
} //end func getFrozenHtml
|
||||
|
||||
// }}}
|
||||
// {{{ _getPersistantData()
|
||||
|
||||
/**
|
||||
* Used by getFrozenHtml() to pass the element's value if _persistantFreeze is on
|
||||
*
|
||||
* @access private
|
||||
* @return string
|
||||
*/
|
||||
function _getPersistantData()
|
||||
{
|
||||
if (!$this->_persistantFreeze) {
|
||||
return '';
|
||||
} else {
|
||||
$id = $this->getAttribute('id');
|
||||
return '<input' . $this->_getAttrString(array(
|
||||
'type' => 'hidden',
|
||||
'name' => $this->getName(),
|
||||
'value' => $this->getValue()
|
||||
) + (isset($id)? array('id' => $id): array())) . ' />';
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ isFrozen()
|
||||
|
||||
/**
|
||||
* Returns whether or not the element is frozen
|
||||
*
|
||||
* @since 1.3
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
function isFrozen()
|
||||
{
|
||||
return $this->_flagFrozen;
|
||||
} // end func isFrozen
|
||||
|
||||
// }}}
|
||||
// {{{ setPersistantFreeze()
|
||||
|
||||
/**
|
||||
* Sets wether an element value should be kept in an hidden field
|
||||
* when the element is frozen or not
|
||||
*
|
||||
* @param bool $persistant True if persistant value
|
||||
* @since 2.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setPersistantFreeze($persistant=false)
|
||||
{
|
||||
$this->_persistantFreeze = $persistant;
|
||||
} //end func setPersistantFreeze
|
||||
|
||||
// }}}
|
||||
// {{{ setLabel()
|
||||
|
||||
/**
|
||||
* Sets display text for the element
|
||||
*
|
||||
* @param string $label Display text for the element
|
||||
* @since 1.3
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setLabel($label)
|
||||
{
|
||||
$this->_label = $label;
|
||||
} //end func setLabel
|
||||
|
||||
// }}}
|
||||
// {{{ getLabel()
|
||||
|
||||
/**
|
||||
* Returns display text for the element
|
||||
*
|
||||
* @since 1.3
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function getLabel()
|
||||
{
|
||||
return $this->_label;
|
||||
} //end func getLabel
|
||||
|
||||
// }}}
|
||||
// {{{ _findValue()
|
||||
|
||||
/**
|
||||
* Tries to find the element value from the values array
|
||||
*
|
||||
* @since 2.7
|
||||
* @access private
|
||||
* @return mixed
|
||||
*/
|
||||
function _findValue(&$values)
|
||||
{
|
||||
if (empty($values)) {
|
||||
return null;
|
||||
}
|
||||
$elementName = $this->getName();
|
||||
if (isset($values[$elementName])) {
|
||||
return $values[$elementName];
|
||||
} elseif (strpos($elementName, '[')) {
|
||||
$myVar = "['" . str_replace(
|
||||
array('\\', '\'', ']', '['), array('\\\\', '\\\'', '', "']['"),
|
||||
$elementName
|
||||
) . "']";
|
||||
return eval("return (isset(\$values$myVar)) ? \$values$myVar : null;");
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} //end func _findValue
|
||||
|
||||
// }}}
|
||||
// {{{ onQuickFormEvent()
|
||||
|
||||
/**
|
||||
* Called by HTML_QuickForm whenever form event is made on this element
|
||||
*
|
||||
* @param string $event Name of event
|
||||
* @param mixed $arg event arguments
|
||||
* @param object &$caller calling object
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function onQuickFormEvent($event, $arg, &$caller)
|
||||
{
|
||||
switch ($event) {
|
||||
case 'createElement':
|
||||
$this->__construct($arg[0], $arg[1], $arg[2], $arg[3], $arg[4]);
|
||||
break;
|
||||
case 'addElement':
|
||||
$this->onQuickFormEvent('createElement', $arg, $caller);
|
||||
$this->onQuickFormEvent('updateValue', null, $caller);
|
||||
break;
|
||||
case 'updateValue':
|
||||
// constant values override both default and submitted ones
|
||||
// default values are overriden by submitted
|
||||
$value = $this->_findValue($caller->_constantValues);
|
||||
if (null === $value) {
|
||||
$value = $this->_findValue($caller->_submitValues);
|
||||
if (null === $value) {
|
||||
$value = $this->_findValue($caller->_defaultValues);
|
||||
}
|
||||
}
|
||||
if (null !== $value) {
|
||||
$this->setValue($value);
|
||||
}
|
||||
break;
|
||||
case 'setGroupValue':
|
||||
$this->setValue($arg);
|
||||
}
|
||||
return true;
|
||||
} // end func onQuickFormEvent
|
||||
|
||||
// }}}
|
||||
// {{{ accept()
|
||||
|
||||
/**
|
||||
* Accepts a renderer
|
||||
*
|
||||
* @param HTML_QuickForm_Renderer renderer object
|
||||
* @param bool Whether an element is required
|
||||
* @param string An error message associated with an element
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function accept(&$renderer, $required=false, $error=null)
|
||||
{
|
||||
$renderer->renderElement($this, $required, $error);
|
||||
} // end func accept
|
||||
|
||||
// }}}
|
||||
// {{{ _generateId()
|
||||
|
||||
/**
|
||||
* Automatically generates and assigns an 'id' attribute for the element.
|
||||
*
|
||||
* Currently used to ensure that labels work on radio buttons and
|
||||
* checkboxes. Per idea of Alexander Radivanovich.
|
||||
*
|
||||
* @access private
|
||||
* @return void
|
||||
*/
|
||||
function _generateId()
|
||||
{
|
||||
static $idx = 1;
|
||||
|
||||
if (!$this->getAttribute('id')) {
|
||||
$this->updateAttributes(array('id' => 'qf_' . substr(md5(microtime() . $idx++), 0, 6)));
|
||||
}
|
||||
} // end func _generateId
|
||||
|
||||
// }}}
|
||||
// {{{ exportValue()
|
||||
|
||||
/**
|
||||
* Returns a 'safe' element's value
|
||||
*
|
||||
* @param array array of submitted values to search
|
||||
* @param bool whether to return the value as associative array
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
function exportValue(&$submitValues, $assoc = false)
|
||||
{
|
||||
$value = $this->_findValue($submitValues);
|
||||
if (null === $value) {
|
||||
$value = $this->getValue();
|
||||
}
|
||||
return $this->_prepareValue($value, $assoc);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ _prepareValue()
|
||||
|
||||
/**
|
||||
* Used by exportValue() to prepare the value for returning
|
||||
*
|
||||
* @param mixed the value found in exportValue()
|
||||
* @param bool whether to return the value as associative array
|
||||
* @access private
|
||||
* @return mixed
|
||||
*/
|
||||
function _prepareValue($value, $assoc)
|
||||
{
|
||||
if (null === $value) {
|
||||
return null;
|
||||
} elseif (!$assoc) {
|
||||
return $value;
|
||||
} else {
|
||||
$name = $this->getName();
|
||||
if (!strpos($name, '[')) {
|
||||
return array($name => $value);
|
||||
} else {
|
||||
$valueAry = array();
|
||||
$myIndex = "['" . str_replace(
|
||||
array('\\', '\'', ']', '['), array('\\\\', '\\\'', '', "']['"),
|
||||
$name
|
||||
) . "']";
|
||||
eval("\$valueAry$myIndex = \$value;");
|
||||
return $valueAry;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
} // end class HTML_QuickForm_element
|
||||
?>
|
||||
359
sites/all/modules/civicrm/packages/HTML/QuickForm/file.php
Normal file
359
sites/all/modules/civicrm/packages/HTML/QuickForm/file.php
Normal file
|
|
@ -0,0 +1,359 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* HTML class for a file upload field
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: file.php,v 1.25 2009/04/04 21:34:02 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for <input /> form elements
|
||||
*/
|
||||
require_once 'HTML/QuickForm/input.php';
|
||||
|
||||
// register file-related rules
|
||||
if (class_exists('HTML_QuickForm')) {
|
||||
HTML_QuickForm::registerRule('uploadedfile', 'callback', '_ruleIsUploadedFile', 'HTML_QuickForm_file');
|
||||
HTML_QuickForm::registerRule('maxfilesize', 'callback', '_ruleCheckMaxFileSize', 'HTML_QuickForm_file');
|
||||
HTML_QuickForm::registerRule('mimetype', 'callback', '_ruleCheckMimeType', 'HTML_QuickForm_file');
|
||||
HTML_QuickForm::registerRule('filename', 'callback', '_ruleCheckFileName', 'HTML_QuickForm_file');
|
||||
}
|
||||
|
||||
/**
|
||||
* HTML class for a file upload field
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @version Release: 3.2.11
|
||||
* @since 1.0
|
||||
*/
|
||||
class HTML_QuickForm_file extends HTML_QuickForm_input
|
||||
{
|
||||
// {{{ properties
|
||||
|
||||
/**
|
||||
* Uploaded file data, from $_FILES
|
||||
* @var array
|
||||
*/
|
||||
var $_value = null;
|
||||
|
||||
// }}}
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string Input field name attribute
|
||||
* @param string Input field label
|
||||
* @param mixed (optional)Either a typical HTML attribute string
|
||||
* or an associative array
|
||||
* @since 1.0
|
||||
* @access public
|
||||
*/
|
||||
function __construct($elementName=null, $elementLabel=null, $attributes=null)
|
||||
{
|
||||
parent::__construct($elementName, $elementLabel, $attributes);
|
||||
$this->setType('file');
|
||||
} //end constructor
|
||||
|
||||
// }}}
|
||||
// {{{ setSize()
|
||||
|
||||
/**
|
||||
* Sets size of file element
|
||||
*
|
||||
* @param int Size of file element
|
||||
* @since 1.0
|
||||
* @access public
|
||||
*/
|
||||
function setSize($size)
|
||||
{
|
||||
$this->updateAttributes(array('size' => $size));
|
||||
} //end func setSize
|
||||
|
||||
// }}}
|
||||
// {{{ getSize()
|
||||
|
||||
/**
|
||||
* Returns size of file element
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return int
|
||||
*/
|
||||
function getSize()
|
||||
{
|
||||
return $this->getAttribute('size');
|
||||
} //end func getSize
|
||||
|
||||
// }}}
|
||||
// {{{ freeze()
|
||||
|
||||
/**
|
||||
* Freeze the element so that only its value is returned
|
||||
*
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
function freeze()
|
||||
{
|
||||
return false;
|
||||
} //end func freeze
|
||||
|
||||
// }}}
|
||||
// {{{ setValue()
|
||||
|
||||
/**
|
||||
* Sets value for file element.
|
||||
*
|
||||
* Actually this does nothing. The function is defined here to override
|
||||
* HTML_Quickform_input's behaviour of setting the 'value' attribute. As
|
||||
* no sane user-agent uses <input type="file">'s value for anything
|
||||
* (because of security implications) we implement file's value as a
|
||||
* read-only property with a special meaning.
|
||||
*
|
||||
* @param mixed Value for file element
|
||||
* @since 3.0
|
||||
* @access public
|
||||
*/
|
||||
function setValue($value)
|
||||
{
|
||||
return null;
|
||||
} //end func setValue
|
||||
|
||||
// }}}
|
||||
// {{{ getValue()
|
||||
|
||||
/**
|
||||
* Returns information about the uploaded file
|
||||
*
|
||||
* @since 3.0
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
function getValue()
|
||||
{
|
||||
return $this->_value;
|
||||
} // end func getValue
|
||||
|
||||
// }}}
|
||||
// {{{ onQuickFormEvent()
|
||||
|
||||
/**
|
||||
* Called by HTML_QuickForm whenever form event is made on this element
|
||||
*
|
||||
* @param string Name of event
|
||||
* @param mixed event arguments
|
||||
* @param object calling object
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
function onQuickFormEvent($event, $arg, &$caller)
|
||||
{
|
||||
switch ($event) {
|
||||
case 'updateValue':
|
||||
if ($caller->getAttribute('method') == 'get') {
|
||||
return PEAR::raiseError('Cannot add a file upload field to a GET method form');
|
||||
}
|
||||
$placeholder = array();
|
||||
$this->_value = $this->_findValue($placeholder);
|
||||
$caller->updateAttributes(array('enctype' => 'multipart/form-data'));
|
||||
$caller->setMaxFileSize();
|
||||
break;
|
||||
case 'addElement':
|
||||
$this->onQuickFormEvent('createElement', $arg, $caller);
|
||||
return $this->onQuickFormEvent('updateValue', null, $caller);
|
||||
break;
|
||||
case 'createElement':
|
||||
$className = get_class($this);
|
||||
$this->__construct($arg[0], $arg[1], $arg[2]);
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
} // end func onQuickFormEvent
|
||||
|
||||
// }}}
|
||||
// {{{ moveUploadedFile()
|
||||
|
||||
/**
|
||||
* Moves an uploaded file into the destination
|
||||
*
|
||||
* @param string Destination directory path
|
||||
* @param string New file name
|
||||
* @access public
|
||||
* @return bool Whether the file was moved successfully
|
||||
*/
|
||||
function moveUploadedFile($dest, $fileName = '')
|
||||
{
|
||||
if ($dest != '' && substr($dest, -1) != '/') {
|
||||
$dest .= '/';
|
||||
}
|
||||
$fileName = ($fileName != '') ? $fileName : basename($this->_value['name']);
|
||||
return move_uploaded_file($this->_value['tmp_name'], $dest . $fileName);
|
||||
} // end func moveUploadedFile
|
||||
|
||||
// }}}
|
||||
// {{{ isUploadedFile()
|
||||
|
||||
/**
|
||||
* Checks if the element contains an uploaded file
|
||||
*
|
||||
* @access public
|
||||
* @return bool true if file has been uploaded, false otherwise
|
||||
*/
|
||||
function isUploadedFile()
|
||||
{
|
||||
return $this->_ruleIsUploadedFile($this->_value);
|
||||
} // end func isUploadedFile
|
||||
|
||||
// }}}
|
||||
// {{{ _ruleIsUploadedFile()
|
||||
|
||||
/**
|
||||
* Checks if the given element contains an uploaded file
|
||||
*
|
||||
* @param array Uploaded file info (from $_FILES)
|
||||
* @access private
|
||||
* @return bool true if file has been uploaded, false otherwise
|
||||
*/
|
||||
static function _ruleIsUploadedFile($elementValue)
|
||||
{
|
||||
if ((isset($elementValue['error']) && $elementValue['error'] == 0) ||
|
||||
(!empty($elementValue['tmp_name']) && $elementValue['tmp_name'] != 'none')) {
|
||||
return is_uploaded_file($elementValue['tmp_name']);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} // end func _ruleIsUploadedFile
|
||||
|
||||
// }}}
|
||||
// {{{ _ruleCheckMaxFileSize()
|
||||
|
||||
/**
|
||||
* Checks that the file does not exceed the max file size
|
||||
*
|
||||
* @param array Uploaded file info (from $_FILES)
|
||||
* @param int Max file size
|
||||
* @access private
|
||||
* @return bool true if filesize is lower than maxsize, false otherwise
|
||||
*/
|
||||
static function _ruleCheckMaxFileSize($elementValue, $maxSize)
|
||||
{
|
||||
if (!empty($elementValue['error']) &&
|
||||
(UPLOAD_ERR_FORM_SIZE == $elementValue['error'] || UPLOAD_ERR_INI_SIZE == $elementValue['error'])) {
|
||||
return false;
|
||||
}
|
||||
if (!HTML_QuickForm_file::_ruleIsUploadedFile($elementValue)) {
|
||||
return true;
|
||||
}
|
||||
return ($maxSize >= @filesize($elementValue['tmp_name']));
|
||||
} // end func _ruleCheckMaxFileSize
|
||||
|
||||
// }}}
|
||||
// {{{ _ruleCheckMimeType()
|
||||
|
||||
/**
|
||||
* Checks if the given element contains an uploaded file of the right mime type
|
||||
*
|
||||
* @param array Uploaded file info (from $_FILES)
|
||||
* @param mixed Mime Type (can be an array of allowed types)
|
||||
* @access private
|
||||
* @return bool true if mimetype is correct, false otherwise
|
||||
*/
|
||||
static function _ruleCheckMimeType($elementValue, $mimeType)
|
||||
{
|
||||
if (!HTML_QuickForm_file::_ruleIsUploadedFile($elementValue)) {
|
||||
return true;
|
||||
}
|
||||
if (is_array($mimeType)) {
|
||||
return in_array($elementValue['type'], $mimeType);
|
||||
}
|
||||
return $elementValue['type'] == $mimeType;
|
||||
} // end func _ruleCheckMimeType
|
||||
|
||||
// }}}
|
||||
// {{{ _ruleCheckFileName()
|
||||
|
||||
/**
|
||||
* Checks if the given element contains an uploaded file of the filename regex
|
||||
*
|
||||
* @param array Uploaded file info (from $_FILES)
|
||||
* @param string Regular expression
|
||||
* @access private
|
||||
* @return bool true if name matches regex, false otherwise
|
||||
*/
|
||||
static function _ruleCheckFileName($elementValue, $regex)
|
||||
{
|
||||
if (!HTML_QuickForm_file::_ruleIsUploadedFile($elementValue)) {
|
||||
return true;
|
||||
}
|
||||
return (bool)preg_match($regex, $elementValue['name']);
|
||||
} // end func _ruleCheckFileName
|
||||
|
||||
// }}}
|
||||
// {{{ _findValue()
|
||||
|
||||
/**
|
||||
* Tries to find the element value from the values array
|
||||
*
|
||||
* Needs to be redefined here as $_FILES is populated differently from
|
||||
* other arrays when element name is of the form foo[bar]
|
||||
*
|
||||
* @access private
|
||||
* @return mixed
|
||||
*/
|
||||
function _findValue(&$values)
|
||||
{
|
||||
if (empty($_FILES)) {
|
||||
return null;
|
||||
}
|
||||
$elementName = $this->getName();
|
||||
if (isset($_FILES[$elementName])) {
|
||||
return $_FILES[$elementName];
|
||||
} elseif (false !== ($pos = strpos($elementName, '['))) {
|
||||
$base = str_replace(
|
||||
array('\\', '\''), array('\\\\', '\\\''),
|
||||
substr($elementName, 0, $pos)
|
||||
);
|
||||
$idx = "['" . str_replace(
|
||||
array('\\', '\'', ']', '['), array('\\\\', '\\\'', '', "']['"),
|
||||
substr($elementName, $pos + 1, -1)
|
||||
) . "']";
|
||||
$props = array('name', 'type', 'size', 'tmp_name', 'error');
|
||||
$code = "if (!isset(\$_FILES['{$base}']['name']{$idx})) {\n" .
|
||||
" return null;\n" .
|
||||
"} else {\n" .
|
||||
" \$value = array();\n";
|
||||
foreach ($props as $prop) {
|
||||
$code .= " \$value['{$prop}'] = \$_FILES['{$base}']['{$prop}']{$idx};\n";
|
||||
}
|
||||
return eval($code . " return \$value;\n}\n");
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
} // end class HTML_QuickForm_file
|
||||
?>
|
||||
593
sites/all/modules/civicrm/packages/HTML/QuickForm/group.php
Normal file
593
sites/all/modules/civicrm/packages/HTML/QuickForm/group.php
Normal file
|
|
@ -0,0 +1,593 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* HTML class for a form element group
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: group.php,v 1.40 2009/04/04 21:34:03 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for form elements
|
||||
*/
|
||||
require_once 'HTML/QuickForm/element.php';
|
||||
|
||||
/**
|
||||
* HTML class for a form element group
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @version Release: 3.2.11
|
||||
* @since 1.0
|
||||
*/
|
||||
class HTML_QuickForm_group extends HTML_QuickForm_element
|
||||
{
|
||||
// {{{ properties
|
||||
|
||||
/**
|
||||
* Name of the element
|
||||
* @var string
|
||||
* @since 1.0
|
||||
* @access private
|
||||
*/
|
||||
var $_name = '';
|
||||
|
||||
/**
|
||||
* Array of grouped elements
|
||||
* @var array
|
||||
* @since 1.0
|
||||
* @access private
|
||||
*/
|
||||
var $_elements = array();
|
||||
|
||||
/**
|
||||
* String to separate elements
|
||||
* @var mixed
|
||||
* @since 2.5
|
||||
* @access private
|
||||
*/
|
||||
var $_separator = null;
|
||||
|
||||
/**
|
||||
* Required elements in this group
|
||||
* @var array
|
||||
* @since 2.5
|
||||
* @access private
|
||||
*/
|
||||
var $_required = array();
|
||||
|
||||
/**
|
||||
* Whether to change elements' names to $groupName[$elementName] or leave them as is
|
||||
* @var bool
|
||||
* @since 3.0
|
||||
* @access private
|
||||
*/
|
||||
var $_appendName = true;
|
||||
|
||||
// }}}
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string $elementName (optional)Group name
|
||||
* @param array $elementLabel (optional)Group label
|
||||
* @param array $elements (optional)Group elements
|
||||
* @param mixed $separator (optional)Use a string for one separator,
|
||||
* use an array to alternate the separators.
|
||||
* @param bool $appendName (optional)whether to change elements' names to
|
||||
* the form $groupName[$elementName] or leave
|
||||
* them as is.
|
||||
* @param mixed $attributes (optional)Either a typical HTML attribute string
|
||||
* or an associative array. Date format is passed along the attributes.
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function __construct($elementName=null, $elementLabel=null, $elements=null, $separator=null, $appendName = true, $attributes = null)
|
||||
{
|
||||
parent::__construct($elementName, $elementLabel, $attributes);
|
||||
$this->_type = 'group';
|
||||
if (isset($elements) && is_array($elements)) {
|
||||
$this->setElements($elements);
|
||||
}
|
||||
if (isset($separator)) {
|
||||
$this->_separator = $separator;
|
||||
}
|
||||
if (isset($appendName)) {
|
||||
$this->_appendName = $appendName;
|
||||
}
|
||||
} //end constructor
|
||||
|
||||
// }}}
|
||||
// {{{ setName()
|
||||
|
||||
/**
|
||||
* Sets the group name
|
||||
*
|
||||
* @param string $name Group name
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setName($name)
|
||||
{
|
||||
$this->_name = $name;
|
||||
} //end func setName
|
||||
|
||||
// }}}
|
||||
// {{{ getName()
|
||||
|
||||
/**
|
||||
* Returns the group name
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function getName()
|
||||
{
|
||||
return $this->_name;
|
||||
} //end func getName
|
||||
|
||||
// }}}
|
||||
// {{{ setValue()
|
||||
|
||||
/**
|
||||
* Sets values for group's elements
|
||||
*
|
||||
* @param mixed Values for group's elements
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setValue($value)
|
||||
{
|
||||
$this->_createElementsIfNotExist();
|
||||
foreach (array_keys($this->_elements) as $key) {
|
||||
if (!$this->_appendName) {
|
||||
$v = $this->_elements[$key]->_findValue($value);
|
||||
if (null !== $v) {
|
||||
$this->_elements[$key]->onQuickFormEvent('setGroupValue', $v, $this);
|
||||
}
|
||||
|
||||
} else {
|
||||
$elementName = $this->_elements[$key]->getName();
|
||||
$index = strlen($elementName) ? $elementName : $key;
|
||||
if (is_array($value)) {
|
||||
if (isset($value[$index])) {
|
||||
$this->_elements[$key]->onQuickFormEvent('setGroupValue', $value[$index], $this);
|
||||
}
|
||||
} elseif (isset($value)) {
|
||||
$this->_elements[$key]->onQuickFormEvent('setGroupValue', $value, $this);
|
||||
}
|
||||
}
|
||||
}
|
||||
} //end func setValue
|
||||
|
||||
// }}}
|
||||
// {{{ getValue()
|
||||
|
||||
/**
|
||||
* Returns the value of the group
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
function getValue()
|
||||
{
|
||||
$value = null;
|
||||
foreach (array_keys($this->_elements) as $key) {
|
||||
$element =& $this->_elements[$key];
|
||||
switch ($element->getType()) {
|
||||
case 'radio':
|
||||
$v = $element->getChecked()? $element->getValue(): null;
|
||||
break;
|
||||
case 'checkbox':
|
||||
$v = $element->getChecked()? true: null;
|
||||
break;
|
||||
default:
|
||||
$v = $element->getValue();
|
||||
}
|
||||
if (null !== $v) {
|
||||
$elementName = $element->getName();
|
||||
if (is_null($elementName)) {
|
||||
$value = $v;
|
||||
} else {
|
||||
if (!is_array($value)) {
|
||||
$value = is_null($value)? array(): array($value);
|
||||
}
|
||||
if ('' === $elementName) {
|
||||
$value[] = $v;
|
||||
} else {
|
||||
$value[$elementName] = $v;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $value;
|
||||
} // end func getValue
|
||||
|
||||
// }}}
|
||||
// {{{ setElements()
|
||||
|
||||
/**
|
||||
* Sets the grouped elements
|
||||
*
|
||||
* @param array $elements Array of elements
|
||||
* @since 1.1
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setElements($elements)
|
||||
{
|
||||
$this->_elements = array_values($elements);
|
||||
if ($this->_flagFrozen) {
|
||||
$this->freeze();
|
||||
}
|
||||
} // end func setElements
|
||||
|
||||
// }}}
|
||||
// {{{ getElements()
|
||||
|
||||
/**
|
||||
* Gets the grouped elements
|
||||
*
|
||||
* @since 2.4
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
function &getElements()
|
||||
{
|
||||
$this->_createElementsIfNotExist();
|
||||
return $this->_elements;
|
||||
} // end func getElements
|
||||
|
||||
// }}}
|
||||
// {{{ getGroupType()
|
||||
|
||||
/**
|
||||
* Gets the group type based on its elements
|
||||
* Will return 'mixed' if elements contained in the group
|
||||
* are of different types.
|
||||
*
|
||||
* @access public
|
||||
* @return string group elements type
|
||||
*/
|
||||
function getGroupType()
|
||||
{
|
||||
$this->_createElementsIfNotExist();
|
||||
$prevType = '';
|
||||
foreach (array_keys($this->_elements) as $key) {
|
||||
$type = $this->_elements[$key]->getType();
|
||||
if ($type != $prevType && $prevType != '') {
|
||||
return 'mixed';
|
||||
}
|
||||
$prevType = $type;
|
||||
}
|
||||
return $type;
|
||||
} // end func getGroupType
|
||||
|
||||
// }}}
|
||||
// {{{ toHtml()
|
||||
|
||||
/**
|
||||
* Returns Html for the group
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function toHtml()
|
||||
{
|
||||
include_once('HTML/QuickForm/Renderer/Default.php');
|
||||
$renderer = new HTML_QuickForm_Renderer_Default();
|
||||
$renderer->setElementTemplate('{element}');
|
||||
$this->accept($renderer);
|
||||
return $renderer->toHtml();
|
||||
} //end func toHtml
|
||||
|
||||
// }}}
|
||||
// {{{ getElementName()
|
||||
|
||||
/**
|
||||
* Returns the element name inside the group such as found in the html form
|
||||
*
|
||||
* @param mixed $index Element name or element index in the group
|
||||
* @since 3.0
|
||||
* @access public
|
||||
* @return mixed string with element name, false if not found
|
||||
*/
|
||||
function getElementName($index)
|
||||
{
|
||||
$this->_createElementsIfNotExist();
|
||||
$elementName = false;
|
||||
if (is_int($index) && isset($this->_elements[$index])) {
|
||||
$elementName = $this->_elements[$index]->getName();
|
||||
if (isset($elementName) && $elementName == '') {
|
||||
$elementName = $index;
|
||||
}
|
||||
if ($this->_appendName) {
|
||||
if (is_null($elementName)) {
|
||||
$elementName = $this->getName();
|
||||
} else {
|
||||
$elementName = $this->getName().'['.$elementName.']';
|
||||
}
|
||||
}
|
||||
|
||||
} elseif (is_string($index)) {
|
||||
foreach (array_keys($this->_elements) as $key) {
|
||||
$elementName = $this->_elements[$key]->getName();
|
||||
if ($index == $elementName) {
|
||||
if ($this->_appendName) {
|
||||
$elementName = $this->getName().'['.$elementName.']';
|
||||
}
|
||||
break;
|
||||
} elseif ($this->_appendName && $this->getName().'['.$elementName.']' == $index) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $elementName;
|
||||
} //end func getElementName
|
||||
|
||||
// }}}
|
||||
// {{{ getFrozenHtml()
|
||||
|
||||
/**
|
||||
* Returns the value of field without HTML tags
|
||||
*
|
||||
* @since 1.3
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function getFrozenHtml()
|
||||
{
|
||||
$flags = array();
|
||||
$this->_createElementsIfNotExist();
|
||||
foreach (array_keys($this->_elements) as $key) {
|
||||
if (false === ($flags[$key] = $this->_elements[$key]->isFrozen())) {
|
||||
$this->_elements[$key]->freeze();
|
||||
}
|
||||
}
|
||||
$html = $this->toHtml();
|
||||
foreach (array_keys($this->_elements) as $key) {
|
||||
if (!$flags[$key]) {
|
||||
$this->_elements[$key]->unfreeze();
|
||||
}
|
||||
}
|
||||
return $html;
|
||||
} //end func getFrozenHtml
|
||||
|
||||
// }}}
|
||||
// {{{ onQuickFormEvent()
|
||||
|
||||
/**
|
||||
* Called by HTML_QuickForm whenever form event is made on this element
|
||||
*
|
||||
* @param string $event Name of event
|
||||
* @param mixed $arg event arguments
|
||||
* @param object &$caller calling object
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function onQuickFormEvent($event, $arg, &$caller)
|
||||
{
|
||||
switch ($event) {
|
||||
case 'updateValue':
|
||||
$this->_createElementsIfNotExist();
|
||||
foreach (array_keys($this->_elements) as $key) {
|
||||
if ($this->_appendName) {
|
||||
$elementName = $this->_elements[$key]->getName();
|
||||
if (is_null($elementName)) {
|
||||
$this->_elements[$key]->setName($this->getName());
|
||||
} elseif ('' === $elementName) {
|
||||
$this->_elements[$key]->setName($this->getName() . '[' . $key . ']');
|
||||
} else {
|
||||
$this->_elements[$key]->setName($this->getName() . '[' . $elementName . ']');
|
||||
}
|
||||
}
|
||||
$this->_elements[$key]->onQuickFormEvent('updateValue', $arg, $caller);
|
||||
if ($this->_appendName) {
|
||||
$this->_elements[$key]->setName($elementName);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
parent::onQuickFormEvent($event, $arg, $caller);
|
||||
}
|
||||
return true;
|
||||
} // end func onQuickFormEvent
|
||||
|
||||
// }}}
|
||||
// {{{ accept()
|
||||
|
||||
/**
|
||||
* Accepts a renderer
|
||||
*
|
||||
* @param HTML_QuickForm_Renderer renderer object
|
||||
* @param bool Whether a group is required
|
||||
* @param string An error message associated with a group
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function accept(&$renderer, $required = false, $error = null)
|
||||
{
|
||||
$this->_createElementsIfNotExist();
|
||||
$renderer->startGroup($this, $required, $error);
|
||||
$name = $this->getName();
|
||||
foreach (array_keys($this->_elements) as $key) {
|
||||
$element =& $this->_elements[$key];
|
||||
|
||||
if ($this->_appendName) {
|
||||
$elementName = $element->getName();
|
||||
if (isset($elementName)) {
|
||||
$newName = $name . '['. (strlen($elementName)? $elementName: $key) .']';
|
||||
$newID = str_replace(array(']', '['), array('', '_'), $newName);
|
||||
$element->setName($newName);
|
||||
$element->updateAttributes( array( 'id' => $newID ) );
|
||||
} else {
|
||||
$element->setName($name);
|
||||
}
|
||||
}
|
||||
|
||||
$required = !$element->isFrozen() && in_array($element->getName(), $this->_required);
|
||||
|
||||
$element->accept($renderer, $required);
|
||||
|
||||
// restore the element's name
|
||||
if ($this->_appendName) {
|
||||
$element->setName($elementName);
|
||||
}
|
||||
}
|
||||
$renderer->finishGroup($this);
|
||||
} // end func accept
|
||||
|
||||
// }}}
|
||||
// {{{ exportValue()
|
||||
|
||||
/**
|
||||
* As usual, to get the group's value we access its elements and call
|
||||
* their exportValue() methods
|
||||
*/
|
||||
function exportValue(&$submitValues, $assoc = false)
|
||||
{
|
||||
$value = null;
|
||||
foreach (array_keys($this->_elements) as $key) {
|
||||
$elementName = $this->_elements[$key]->getName();
|
||||
if ($this->_appendName) {
|
||||
if (is_null($elementName)) {
|
||||
$this->_elements[$key]->setName($this->getName());
|
||||
} elseif ('' === $elementName) {
|
||||
$this->_elements[$key]->setName($this->getName() . '[' . $key . ']');
|
||||
} else {
|
||||
$this->_elements[$key]->setName($this->getName() . '[' . $elementName . ']');
|
||||
}
|
||||
}
|
||||
$v = $this->_elements[$key]->exportValue($submitValues, $assoc);
|
||||
if ($this->_appendName) {
|
||||
$this->_elements[$key]->setName($elementName);
|
||||
}
|
||||
if (null !== $v) {
|
||||
// Make $value an array, we will use it like one
|
||||
if (null === $value) {
|
||||
$value = array();
|
||||
}
|
||||
if ($assoc) {
|
||||
// just like HTML_QuickForm::exportValues()
|
||||
$value = HTML_QuickForm::arrayMerge($value, $v);
|
||||
} else {
|
||||
// just like getValue(), but should work OK every time here
|
||||
if (is_null($elementName)) {
|
||||
$value = $v;
|
||||
} elseif ('' === $elementName) {
|
||||
$value[] = $v;
|
||||
} else {
|
||||
$value[$elementName] = $v;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// do not pass the value through _prepareValue, we took care of this already
|
||||
return $value;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ _createElements()
|
||||
|
||||
/**
|
||||
* Creates the group's elements.
|
||||
*
|
||||
* This should be overriden by child classes that need to create their
|
||||
* elements. The method will be called automatically when needed, calling
|
||||
* it from the constructor is discouraged as the constructor is usually
|
||||
* called _twice_ on element creation, first time with _no_ parameters.
|
||||
*
|
||||
* @access private
|
||||
* @abstract
|
||||
*/
|
||||
function _createElements()
|
||||
{
|
||||
// abstract
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ _createElementsIfNotExist()
|
||||
|
||||
/**
|
||||
* A wrapper around _createElements()
|
||||
*
|
||||
* This method calls _createElements() if the group's _elements array
|
||||
* is empty. It also performs some updates, e.g. freezes the created
|
||||
* elements if the group is already frozen.
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
function _createElementsIfNotExist()
|
||||
{
|
||||
if (empty($this->_elements)) {
|
||||
$this->_createElements();
|
||||
if ($this->_flagFrozen) {
|
||||
$this->freeze();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ freeze()
|
||||
|
||||
function freeze()
|
||||
{
|
||||
parent::freeze();
|
||||
foreach (array_keys($this->_elements) as $key) {
|
||||
$this->_elements[$key]->freeze();
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ unfreeze()
|
||||
|
||||
function unfreeze()
|
||||
{
|
||||
parent::unfreeze();
|
||||
foreach (array_keys($this->_elements) as $key) {
|
||||
$this->_elements[$key]->unfreeze();
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ setPersistantFreeze()
|
||||
|
||||
function setPersistantFreeze($persistant = false)
|
||||
{
|
||||
parent::setPersistantFreeze($persistant);
|
||||
foreach (array_keys($this->_elements) as $key) {
|
||||
$this->_elements[$key]->setPersistantFreeze($persistant);
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
} //end class HTML_QuickForm_group
|
||||
?>
|
||||
74
sites/all/modules/civicrm/packages/HTML/QuickForm/header.php
Normal file
74
sites/all/modules/civicrm/packages/HTML/QuickForm/header.php
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* A pseudo-element used for adding headers to form
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: header.php,v 1.3 2009/04/04 21:34:03 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* HTML class for static data
|
||||
*/
|
||||
require_once 'HTML/QuickForm/static.php';
|
||||
|
||||
/**
|
||||
* A pseudo-element used for adding headers to form
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @version Release: 3.2.11
|
||||
* @since 3.0
|
||||
*/
|
||||
class HTML_QuickForm_header extends HTML_QuickForm_static
|
||||
{
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string $elementName Header name
|
||||
* @param string $text Header text
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function __construct($elementName = null, $text = null)
|
||||
{
|
||||
parent::__construct($elementName, null, $text);
|
||||
$this->_type = 'header';
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ accept()
|
||||
|
||||
/**
|
||||
* Accepts a renderer
|
||||
*
|
||||
* @param HTML_QuickForm_Renderer renderer object
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function accept(&$renderer)
|
||||
{
|
||||
$renderer->renderHeader($this);
|
||||
} // end func accept
|
||||
|
||||
// }}}
|
||||
|
||||
} //end class HTML_QuickForm_header
|
||||
?>
|
||||
96
sites/all/modules/civicrm/packages/HTML/QuickForm/hidden.php
Normal file
96
sites/all/modules/civicrm/packages/HTML/QuickForm/hidden.php
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* HTML class for a hidden type element
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: hidden.php,v 1.12 2009/04/04 21:34:03 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for <input /> form elements
|
||||
*/
|
||||
require_once 'HTML/QuickForm/input.php';
|
||||
|
||||
/**
|
||||
* HTML class for a hidden type element
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @version Release: 3.2.11
|
||||
* @since 1.0
|
||||
*/
|
||||
class HTML_QuickForm_hidden extends HTML_QuickForm_input
|
||||
{
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string $elementName (optional)Input field name attribute
|
||||
* @param string $value (optional)Input field value
|
||||
* @param mixed $attributes (optional)Either a typical HTML attribute string
|
||||
* or an associative array
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function __construct($elementName=null, $value='', $attributes=null)
|
||||
{
|
||||
parent::__construct($elementName, null, $attributes);
|
||||
$this->setType('hidden');
|
||||
$this->setValue($value);
|
||||
} //end constructor
|
||||
|
||||
// }}}
|
||||
// {{{ freeze()
|
||||
|
||||
/**
|
||||
* Freeze the element so that only its value is returned
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function freeze()
|
||||
{
|
||||
return false;
|
||||
} //end func freeze
|
||||
|
||||
// }}}
|
||||
// {{{ accept()
|
||||
|
||||
/**
|
||||
* Accepts a renderer
|
||||
*
|
||||
* @param HTML_QuickForm_Renderer renderer object
|
||||
* @param bool Whether an element is required
|
||||
* @param string An error message associated with an element
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function accept(&$renderer, $required=false, $error=null)
|
||||
{
|
||||
$renderer->renderHidden($this, $required, $error);
|
||||
} // end func accept
|
||||
|
||||
// }}}
|
||||
|
||||
} //end class HTML_QuickForm_hidden
|
||||
?>
|
||||
|
|
@ -0,0 +1,118 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Hidden select pseudo-element
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Isaac Shepard <ishepard@bsiweb.com>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: hiddenselect.php,v 1.7 2009/04/04 21:34:03 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class for <select></select> elements
|
||||
*/
|
||||
require_once 'HTML/QuickForm/select.php';
|
||||
|
||||
/**
|
||||
* Hidden select pseudo-element
|
||||
*
|
||||
* This class takes the same arguments as a select element, but instead
|
||||
* of creating a select ring it creates hidden elements for all values
|
||||
* already selected with setDefault or setConstant. This is useful if
|
||||
* you have a select ring that you don't want visible, but you need all
|
||||
* selected values to be passed.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Isaac Shepard <ishepard@bsiweb.com>
|
||||
* @version Release: 3.2.11
|
||||
* @since 2.1
|
||||
*/
|
||||
class HTML_QuickForm_hiddenselect extends HTML_QuickForm_select
|
||||
{
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string Select name attribute
|
||||
* @param mixed Label(s) for the select (not used)
|
||||
* @param mixed Data to be used to populate options
|
||||
* @param mixed Either a typical HTML attribute string or an associative array (not used)
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function __construct($elementName=null, $elementLabel=null, $options=null, $attributes=null)
|
||||
{
|
||||
parent::__construct($elementName, $elementLabel, $attributes);
|
||||
$this->_persistantFreeze = true;
|
||||
$this->_type = 'hiddenselect';
|
||||
if (isset($options)) {
|
||||
$this->load($options);
|
||||
}
|
||||
} //end constructor
|
||||
|
||||
// }}}
|
||||
// {{{ toHtml()
|
||||
|
||||
/**
|
||||
* Returns the SELECT in HTML
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
* @throws
|
||||
*/
|
||||
function toHtml()
|
||||
{
|
||||
if (empty($this->_values)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$tabs = $this->_getTabs();
|
||||
$name = $this->getPrivateName();
|
||||
$strHtml = '';
|
||||
|
||||
foreach ($this->_values as $key => $val) {
|
||||
for ($i = 0, $optCount = count($this->_options); $i < $optCount; $i++) {
|
||||
if ($val == $this->_options[$i]['attr']['value']) {
|
||||
$strHtml .= $tabs . '<input' . $this->_getAttrString(array(
|
||||
'type' => 'hidden',
|
||||
'name' => $name,
|
||||
'value' => $val
|
||||
)) . " />\n" ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $strHtml;
|
||||
} //end func toHtml
|
||||
|
||||
// }}}
|
||||
// {{{ accept()
|
||||
|
||||
/**
|
||||
* This is essentially a hidden element and should be rendered as one
|
||||
*/
|
||||
function accept(&$renderer)
|
||||
{
|
||||
$renderer->renderHidden($this);
|
||||
}
|
||||
|
||||
// }}}
|
||||
} //end class HTML_QuickForm_hiddenselect
|
||||
?>
|
||||
487
sites/all/modules/civicrm/packages/HTML/QuickForm/hierselect.php
Normal file
487
sites/all/modules/civicrm/packages/HTML/QuickForm/hierselect.php
Normal file
|
|
@ -0,0 +1,487 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP version 4.0 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2004 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Herim Vasquez <vasquezh@iro.umontreal.ca> |
|
||||
// | Bertrand Mansion <bmansion@mamasam.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: hierselect.php,v 1.12 2004/10/20 10:03:49 avb Exp $
|
||||
|
||||
require_once('HTML/QuickForm/group.php');
|
||||
require_once('HTML/QuickForm/select.php');
|
||||
|
||||
/**
|
||||
* Class to dynamically create two or more HTML Select elements
|
||||
* The first select changes the content of the second select and so on.
|
||||
* This element is considered as a group. Selects will be named
|
||||
* groupName[0], groupName[1], groupName[2]...
|
||||
*
|
||||
* @author Herim Vasquez <vasquezh@iro.umontreal.ca>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @version 1.0
|
||||
* @since PHP4.04pl1
|
||||
* @access public
|
||||
*/
|
||||
class HTML_QuickForm_hierselect extends HTML_QuickForm_group
|
||||
{
|
||||
// {{{ properties
|
||||
|
||||
/**
|
||||
* Options for all the select elements
|
||||
*
|
||||
* Format is a bit more complex as we need to know which options
|
||||
* are related to the ones in the previous select:
|
||||
*
|
||||
* Ex:
|
||||
* // first select
|
||||
* $select1[0] = 'Pop';
|
||||
* $select1[1] = 'Classical';
|
||||
* $select1[2] = 'Funeral doom';
|
||||
*
|
||||
* // second select
|
||||
* $select2[0][0] = 'Red Hot Chil Peppers';
|
||||
* $select2[0][1] = 'The Pixies';
|
||||
* $select2[1][0] = 'Wagner';
|
||||
* $select2[1][1] = 'Strauss';
|
||||
* $select2[2][0] = 'Pantheist';
|
||||
* $select2[2][1] = 'Skepticism';
|
||||
*
|
||||
* // If only need two selects
|
||||
* // - and using the depracated functions
|
||||
* $sel =& $form->addElement('hierselect', 'cds', 'Choose CD:');
|
||||
* $sel->setMainOptions($select1);
|
||||
* $sel->setSecOptions($select2);
|
||||
*
|
||||
* // - and using the new setOptions function
|
||||
* $sel =& $form->addElement('hierselect', 'cds', 'Choose CD:');
|
||||
* $sel->setOptions(array($select1, $select2));
|
||||
*
|
||||
* // If you have a third select with prices for the cds
|
||||
* $select3[0][0][0] = '15.00$';
|
||||
* $select3[0][0][1] = '17.00$';
|
||||
* etc
|
||||
*
|
||||
* // You can now use
|
||||
* $sel =& $form->addElement('hierselect', 'cds', 'Choose CD:');
|
||||
* $sel->setOptions(array($select1, $select2, $select3));
|
||||
*
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_options = array();
|
||||
|
||||
/**
|
||||
* Number of select elements on this group
|
||||
*
|
||||
* @var int
|
||||
* @access private
|
||||
*/
|
||||
var $_nbElements = 0;
|
||||
|
||||
/**
|
||||
* The javascript used to set and change the options
|
||||
*
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_js = '';
|
||||
|
||||
/**
|
||||
* The javascript array name
|
||||
*/
|
||||
var $_jsArrayName = '';
|
||||
|
||||
// }}}
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string $elementName (optional)Input field name attribute
|
||||
* @param string $elementLabel (optional)Input field label in form
|
||||
* @param mixed $attributes (optional)Either a typical HTML attribute string
|
||||
* or an associative array. Date format is passed along the attributes.
|
||||
* @param mixed $separator (optional)Use a string for one separator,
|
||||
* use an array to alternate the separators.
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function __construct($elementName=null, $elementLabel=null, $attributes=null, $separator=null)
|
||||
{
|
||||
parent::__construct($elementName, $elementLabel, null, null, null, $attributes);
|
||||
$this->_persistantFreeze = true;
|
||||
if (isset($separator)) {
|
||||
$this->_separator = $separator;
|
||||
}
|
||||
$this->_type = 'hierselect';
|
||||
$this->_appendName = true;
|
||||
} //end constructor
|
||||
|
||||
// }}}
|
||||
// {{{ setOptions()
|
||||
|
||||
/**
|
||||
* Initialize the array structure containing the options for each select element.
|
||||
* Call the functions that actually do the magic.
|
||||
*
|
||||
* @param array $options Array of options defining each element
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setOptions($options)
|
||||
{
|
||||
$this->_options = $options;
|
||||
|
||||
if (empty($this->_elements)) {
|
||||
$this->_nbElements = count($this->_options);
|
||||
$this->_createElements();
|
||||
} else {
|
||||
// setDefaults has probably been called before this function
|
||||
// check if all elements have been created
|
||||
$totalNbElements = count($this->_options);
|
||||
for ($i = $this->_nbElements; $i < $totalNbElements; $i ++) {
|
||||
$this->_elements[] = new HTML_QuickForm_select($i, null, array(), $this->getAttributes());
|
||||
$this->_nbElements++;
|
||||
}
|
||||
}
|
||||
|
||||
$this->_setOptions();
|
||||
$this->_setJS();
|
||||
} // end func setMainOptions
|
||||
|
||||
// }}}
|
||||
// {{{ setMainOptions()
|
||||
|
||||
/**
|
||||
* Sets the options for the first select element. Deprecated. setOptions() should be used.
|
||||
*
|
||||
* @param array $array Options for the first select element
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setMainOptions($array)
|
||||
{
|
||||
$this->_options[0] = $array;
|
||||
|
||||
if (empty($this->_elements)) {
|
||||
$this->_nbElements = 2;
|
||||
$this->_createElements();
|
||||
}
|
||||
} // end func setMainOptions
|
||||
|
||||
// }}}
|
||||
// {{{ setSecOptions()
|
||||
|
||||
/**
|
||||
* Sets the options for the second select element. Deprecated. setOptions() should be used.
|
||||
* The main _options array is initialized and the _setOptions function is called.
|
||||
*
|
||||
* @param array $array Options for the second select element
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setSecOptions($array)
|
||||
{
|
||||
$this->_options[1] = $array;
|
||||
|
||||
if (empty($this->_elements)) {
|
||||
$this->_nbElements = 2;
|
||||
$this->_createElements();
|
||||
} else {
|
||||
// setDefaults has probably been called before this function
|
||||
// check if all elements have been created
|
||||
$totalNbElements = 2;
|
||||
for ($i = $this->_nbElements; $i < $totalNbElements; $i ++) {
|
||||
$this->_elements[] = new HTML_QuickForm_select($i, null, array(), $this->getAttributes());
|
||||
$this->_nbElements++;
|
||||
}
|
||||
}
|
||||
|
||||
$this->_setOptions();
|
||||
$this->_setJS();
|
||||
} // end func setSecOptions
|
||||
|
||||
// }}}
|
||||
// {{{ _setOptions()
|
||||
|
||||
/**
|
||||
* Sets the options for each select element
|
||||
*
|
||||
* @access private
|
||||
* @return void
|
||||
*/
|
||||
function _setOptions()
|
||||
{
|
||||
$toLoad = '';
|
||||
foreach (array_keys($this->_elements) AS $key) {
|
||||
if (eval("return isset(\$this->_options[{$key}]{$toLoad});") ) {
|
||||
$array = eval("return \$this->_options[{$key}]{$toLoad};");
|
||||
if (is_array($array)) {
|
||||
$select =& $this->_elements[$key];
|
||||
$select->_options = array();
|
||||
$select->loadArray($array);
|
||||
|
||||
$value = is_array($v = $select->getValue()) ? $v[0] : key($array);
|
||||
$toLoad .= '[\''.$value.'\']';
|
||||
}
|
||||
}
|
||||
}
|
||||
} // end func _setOptions
|
||||
|
||||
// }}}
|
||||
// {{{ setValue()
|
||||
|
||||
/**
|
||||
* Sets values for group's elements
|
||||
*
|
||||
* @param array $value An array of 2 or more values, for the first,
|
||||
* the second, the third etc. select
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setValue($value)
|
||||
{
|
||||
$this->_nbElements = count($value);
|
||||
parent::setValue($value);
|
||||
$this->_setOptions();
|
||||
} // end func setValue
|
||||
|
||||
// }}}
|
||||
// {{{ _createElements()
|
||||
|
||||
/**
|
||||
* Creates all the elements for the group
|
||||
*
|
||||
* @access private
|
||||
* @return void
|
||||
*/
|
||||
function _createElements()
|
||||
{
|
||||
//hack to add id attribute for hier select
|
||||
$attributes = $this->getAttributes();
|
||||
$id = null;
|
||||
if ( isset( $attributes['id'] ) ) {
|
||||
$id = "{$attributes['id']}";
|
||||
}
|
||||
|
||||
for ($i = 0; $i < $this->_nbElements; $i++) {
|
||||
if ( isset( $id ) ) {
|
||||
$attributes['id'] = "{$id}_{$i}";
|
||||
}
|
||||
|
||||
$this->_elements[] = new HTML_QuickForm_select($i, null, array(), $attributes);
|
||||
}
|
||||
} // end func _createElements
|
||||
|
||||
// }}}
|
||||
// {{{ _setJS()
|
||||
|
||||
/**
|
||||
* Set the JavaScript for each select element (excluding de main one).
|
||||
*
|
||||
* @access private
|
||||
* @return void
|
||||
*/
|
||||
function _setJS()
|
||||
{
|
||||
static $jsArrayName = null;
|
||||
|
||||
$this->_js = $js = '';
|
||||
if ( ! $jsArrayName ) {
|
||||
$this->_jsArrayName = 'hs_' . preg_replace('/\[|\]/', '_', $this->getName());
|
||||
for ($i = 1; $i < $this->_nbElements; $i++) {
|
||||
$this->_setJSArray($this->_jsArrayName, $this->_options[$i], $js);
|
||||
}
|
||||
$jsArrayName = $this->_jsArrayName;
|
||||
} else {
|
||||
$this->_jsArrayName = $jsArrayName;
|
||||
}
|
||||
} // end func _setJS
|
||||
|
||||
// }}}
|
||||
// {{{ _setJSArray()
|
||||
|
||||
/**
|
||||
* Recursively builds the JavaScript array defining the options that a select
|
||||
* element can have.
|
||||
*
|
||||
* @param string $grpName Group Name attribute
|
||||
* @param array $options Select element options
|
||||
* @param string $js JavaScript definition is build using this variable
|
||||
* @param string $optValue The value for the current JavaScript option
|
||||
*
|
||||
* @access private
|
||||
* @return void
|
||||
*/
|
||||
function _setJSArray($grpName, $options, &$js, $optValue = '')
|
||||
{
|
||||
static $jsNameCache = array( );
|
||||
if (is_array($options)) {
|
||||
$js = '';
|
||||
// For a hierselect containing 3 elements:
|
||||
// if option 1 has been selected for the 1st element
|
||||
// and option 3 has been selected for the 2nd element,
|
||||
// then the javascript array containing the values to load
|
||||
// on the 3rd element will have the following name: grpName_1_3
|
||||
$name = ($optValue === '') ? $grpName : $grpName.'_'.$optValue;
|
||||
foreach($options AS $k => $v) {
|
||||
$this->_setJSArray($name, $v, $js, $k);
|
||||
}
|
||||
|
||||
// if $js !== '' add it to the JavaScript
|
||||
|
||||
if ( $js !== '' ) {
|
||||
// check if we have already this js in cache, if so reuse it
|
||||
$cacheKey = md5( $js );
|
||||
if ( array_key_exists( $cacheKey, $jsNameCache ) ) {
|
||||
$this->_js .= "$name = {$jsNameCache[$cacheKey]}\n";
|
||||
} else {
|
||||
$this->_js .= $name." = {\n".$js."\n}\n";
|
||||
$jsNameCache[$cacheKey] = $name;
|
||||
}
|
||||
}
|
||||
$js = '';
|
||||
} else {
|
||||
// $js empty means that we are adding the first element to the JavaScript.
|
||||
if ($js != '') {
|
||||
$js .= ",\n";
|
||||
}
|
||||
$js .= '"'.$optValue.'":"'.addcslashes($options,'"').'"';
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ toHtml()
|
||||
|
||||
/**
|
||||
* Returns Html for the group
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function toHtml()
|
||||
{
|
||||
if ($this->_flagFrozen) {
|
||||
$this->_js = '';
|
||||
} else {
|
||||
// set the onchange attribute for each element
|
||||
$keys = array_keys($this->_elements);
|
||||
$nbElements = count($keys);
|
||||
$nbElementsUsingFnc = $nbElements - 1; // last element doesn't need it
|
||||
for ($i = 0; $i < $nbElementsUsingFnc; $i++) {
|
||||
$select =& $this->_elements[$keys[$i]];
|
||||
$select->updateAttributes(
|
||||
array('onChange' => 'swapOptions(this.form, \''.$this->getName().'\', '.$keys[$i].', '.$nbElements.', \''.$this->_jsArrayName.'\');')
|
||||
);
|
||||
}
|
||||
|
||||
// create the js function to call
|
||||
if (!defined('HTML_QUICKFORM_HIERSELECT_EXISTS')) {
|
||||
$this->_js .= "function swapOptions(frm, grpName, eleIndex, nbElements, arName)\n"
|
||||
."{\n"
|
||||
." var n = \"\";\n"
|
||||
." var ctl;\n\n"
|
||||
." for (var i = 0; i < nbElements; i++) {\n"
|
||||
." ctl = frm[grpName+'['+i+']'];\n"
|
||||
." if (!ctl) {\n"
|
||||
." ctl = frm[grpName+'['+i+'][]'];\n"
|
||||
." }\n"
|
||||
." if (i <= eleIndex) {\n"
|
||||
." n += \"_\"+ctl.value;\n"
|
||||
." } else {\n"
|
||||
." ctl.length = 0;\n"
|
||||
." }\n"
|
||||
." }\n\n"
|
||||
." var t = eval(\"typeof(\"+arName + n +\")\");\n"
|
||||
." if (t != 'undefined') {\n"
|
||||
." var the_array = eval(arName+n);\n"
|
||||
." var j = 0;\n"
|
||||
." n = eleIndex + 1;\n"
|
||||
." ctl = frm[grpName+'['+ n +']'];\n"
|
||||
." if (!ctl) {\n"
|
||||
." ctl = frm[grpName+'['+ n +'][]'];\n"
|
||||
." }\n"
|
||||
." ctl.style.display = 'inline';\n"
|
||||
." for (var i in the_array) {\n"
|
||||
." opt = new Option(the_array[i], i, false, false);\n"
|
||||
." ctl.options[j++] = opt;\n"
|
||||
." }\n"
|
||||
." } else {\n"
|
||||
." n = eleIndex + 1;\n"
|
||||
." ctl = frm[grpName+'['+n+']'];\n"
|
||||
." if (!ctl) {\n"
|
||||
." ctl = frm[grpName+'['+ n +'][]'];\n"
|
||||
." }\n"
|
||||
." if (ctl) {\n"
|
||||
." ctl.style.display = 'none';\n"
|
||||
." }\n"
|
||||
." }\n"
|
||||
." if (eleIndex+1 < nbElements) {\n"
|
||||
." swapOptions(frm, grpName, eleIndex+1, nbElements, arName);\n"
|
||||
." }\n"
|
||||
."}\n";
|
||||
define('HTML_QUICKFORM_HIERSELECT_EXISTS', true);
|
||||
}
|
||||
}
|
||||
include_once('HTML/QuickForm/Renderer/Default.php');
|
||||
$renderer = new HTML_QuickForm_Renderer_Default();
|
||||
$renderer->setElementTemplate('{element}');
|
||||
parent::accept($renderer);
|
||||
$result = null;
|
||||
if ( ! empty( $this->_js ) ) {
|
||||
$result .= "<script type=\"text/javascript\">\n//<![CDATA[\n" . $this->_js . "//]]>\n</script>";
|
||||
}
|
||||
return $result .
|
||||
$renderer->toHtml();
|
||||
} // end func toHtml
|
||||
|
||||
// }}}
|
||||
// {{{ accept()
|
||||
|
||||
/**
|
||||
* Accepts a renderer
|
||||
*
|
||||
* @param object An HTML_QuickForm_Renderer object
|
||||
* @param bool Whether a group is required
|
||||
* @param string An error message associated with a group
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function accept(&$renderer, $required = false, $error = null)
|
||||
{
|
||||
$renderer->renderElement($this, $required, $error);
|
||||
} // end func accept
|
||||
|
||||
// }}}
|
||||
// {{{ onQuickFormEvent()
|
||||
|
||||
function onQuickFormEvent($event, $arg, &$caller)
|
||||
{
|
||||
if ('updateValue' == $event) {
|
||||
// we need to call setValue() so that the secondary option
|
||||
// matches the main option
|
||||
return HTML_QuickForm_element::onQuickFormEvent($event, $arg, $caller);
|
||||
} else {
|
||||
return parent::onQuickFormEvent($event, $arg, $caller);
|
||||
}
|
||||
} // end func onQuickFormEvent
|
||||
|
||||
// }}}
|
||||
} // end class HTML_QuickForm_hierselect
|
||||
?>
|
||||
77
sites/all/modules/civicrm/packages/HTML/QuickForm/html.php
Normal file
77
sites/all/modules/civicrm/packages/HTML/QuickForm/html.php
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* A pseudo-element used for adding raw HTML to form
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: html.php,v 1.3 2009/04/04 21:34:03 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* HTML class for static data
|
||||
*/
|
||||
require_once 'HTML/QuickForm/static.php';
|
||||
|
||||
/**
|
||||
* A pseudo-element used for adding raw HTML to form
|
||||
*
|
||||
* Intended for use with the default renderer only, template-based
|
||||
* ones may (and probably will) completely ignore this
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @version Release: 3.2.11
|
||||
* @since 3.0
|
||||
* @deprecated Please use the templates rather than add raw HTML via this element
|
||||
*/
|
||||
class HTML_QuickForm_html extends HTML_QuickForm_static
|
||||
{
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string $text raw HTML to add
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function __construct($text = null)
|
||||
{
|
||||
parent::__construct(null, null, $text);
|
||||
$this->_type = 'html';
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ accept()
|
||||
|
||||
/**
|
||||
* Accepts a renderer
|
||||
*
|
||||
* @param HTML_QuickForm_Renderer renderer object (only works with Default renderer!)
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function accept(&$renderer)
|
||||
{
|
||||
$renderer->renderHtml($this);
|
||||
} // end func accept
|
||||
|
||||
// }}}
|
||||
|
||||
} //end class HTML_QuickForm_html
|
||||
?>
|
||||
127
sites/all/modules/civicrm/packages/HTML/QuickForm/image.php
Normal file
127
sites/all/modules/civicrm/packages/HTML/QuickForm/image.php
Normal file
|
|
@ -0,0 +1,127 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* HTML class for an <input type="image" /> element
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: image.php,v 1.6 2009/04/04 21:34:03 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for <input /> form elements
|
||||
*/
|
||||
require_once 'HTML/QuickForm/input.php';
|
||||
|
||||
/**
|
||||
* HTML class for an <input type="image" /> element
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @version Release: 3.2.11
|
||||
* @since 1.0
|
||||
*/
|
||||
class HTML_QuickForm_image extends HTML_QuickForm_input
|
||||
{
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string $elementName (optional)Element name attribute
|
||||
* @param string $src (optional)Image source
|
||||
* @param mixed $attributes (optional)Either a typical HTML attribute string
|
||||
* or an associative array
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function __construct($elementName=null, $src='', $attributes=null)
|
||||
{
|
||||
parent::__construct($elementName, null, $attributes);
|
||||
$this->setType('image');
|
||||
$this->setSource($src);
|
||||
} // end class constructor
|
||||
|
||||
// }}}
|
||||
// {{{ setSource()
|
||||
|
||||
/**
|
||||
* Sets source for image element
|
||||
*
|
||||
* @param string $src source for image element
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setSource($src)
|
||||
{
|
||||
$this->updateAttributes(array('src' => $src));
|
||||
} // end func setSource
|
||||
|
||||
// }}}
|
||||
// {{{ setBorder()
|
||||
|
||||
/**
|
||||
* Sets border size for image element
|
||||
*
|
||||
* @param string $border border for image element
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setBorder($border)
|
||||
{
|
||||
$this->updateAttributes(array('border' => $border));
|
||||
} // end func setBorder
|
||||
|
||||
// }}}
|
||||
// {{{ setAlign()
|
||||
|
||||
/**
|
||||
* Sets alignment for image element
|
||||
*
|
||||
* @param string $align alignment for image element
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setAlign($align)
|
||||
{
|
||||
$this->updateAttributes(array('align' => $align));
|
||||
} // end func setAlign
|
||||
|
||||
// }}}
|
||||
// {{{ freeze()
|
||||
|
||||
/**
|
||||
* Freeze the element so that only its value is returned
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function freeze()
|
||||
{
|
||||
return false;
|
||||
} //end func freeze
|
||||
|
||||
// }}}
|
||||
|
||||
} // end class HTML_QuickForm_image
|
||||
?>
|
||||
209
sites/all/modules/civicrm/packages/HTML/QuickForm/input.php
Normal file
209
sites/all/modules/civicrm/packages/HTML/QuickForm/input.php
Normal file
|
|
@ -0,0 +1,209 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Base class for <input /> form elements
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: input.php,v 1.10 2009/04/04 21:34:03 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for form elements
|
||||
*/
|
||||
require_once 'HTML/QuickForm/element.php';
|
||||
|
||||
/**
|
||||
* Base class for <input /> form elements
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @version Release: 3.2.11
|
||||
* @since 1.0
|
||||
* @abstract
|
||||
*/
|
||||
class HTML_QuickForm_input extends HTML_QuickForm_element
|
||||
{
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string Input field name attribute
|
||||
* @param mixed Label(s) for the input field
|
||||
* @param mixed Either a typical HTML attribute string or an associative array
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function __construct($elementName=null, $elementLabel=null, $attributes=null)
|
||||
{
|
||||
parent::__construct($elementName, $elementLabel, $attributes);
|
||||
} //end constructor
|
||||
|
||||
// }}}
|
||||
// {{{ setType()
|
||||
|
||||
/**
|
||||
* Sets the element type
|
||||
*
|
||||
* @param string $type Element type
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setType($type)
|
||||
{
|
||||
$this->_type = $type;
|
||||
$this->updateAttributes(array('type'=>$type));
|
||||
} // end func setType
|
||||
|
||||
// }}}
|
||||
// {{{ setName()
|
||||
|
||||
/**
|
||||
* Sets the input field name
|
||||
*
|
||||
* @param string $name Input field name attribute
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setName($name)
|
||||
{
|
||||
$this->updateAttributes(array('name'=>$name));
|
||||
} //end func setName
|
||||
|
||||
// }}}
|
||||
// {{{ getName()
|
||||
|
||||
/**
|
||||
* Returns the element name
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function getName()
|
||||
{
|
||||
return $this->getAttribute('name');
|
||||
} //end func getName
|
||||
|
||||
// }}}
|
||||
// {{{ setValue()
|
||||
|
||||
/**
|
||||
* Sets the value of the form element
|
||||
*
|
||||
* @param string $value Default value of the form element
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setValue($value)
|
||||
{
|
||||
$this->updateAttributes(array('value'=>$value));
|
||||
} // end func setValue
|
||||
|
||||
// }}}
|
||||
// {{{ getValue()
|
||||
|
||||
/**
|
||||
* Returns the value of the form element
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function getValue()
|
||||
{
|
||||
return $this->getAttribute('value');
|
||||
} // end func getValue
|
||||
|
||||
// }}}
|
||||
// {{{ toHtml()
|
||||
|
||||
/**
|
||||
* Returns the input field in HTML
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function toHtml()
|
||||
{
|
||||
if ($this->_flagFrozen) {
|
||||
return $this->getFrozenHtml();
|
||||
} else {
|
||||
return $this->_getTabs() . '<input' . $this->_getAttrString($this->_attributes) . ' />';
|
||||
}
|
||||
} //end func toHtml
|
||||
|
||||
// }}}
|
||||
// {{{ onQuickFormEvent()
|
||||
|
||||
/**
|
||||
* Called by HTML_QuickForm whenever form event is made on this element
|
||||
*
|
||||
* @param string $event Name of event
|
||||
* @param mixed $arg event arguments
|
||||
* @param object &$caller calling object
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws
|
||||
*/
|
||||
function onQuickFormEvent($event, $arg, &$caller)
|
||||
{
|
||||
// do not use submit values for button-type elements
|
||||
$type = $this->getType();
|
||||
if (('updateValue' != $event) ||
|
||||
('submit' != $type && 'reset' != $type && 'image' != $type && 'button' != $type)) {
|
||||
parent::onQuickFormEvent($event, $arg, $caller);
|
||||
} else {
|
||||
$value = $this->_findValue($caller->_constantValues);
|
||||
if (null === $value) {
|
||||
$value = $this->_findValue($caller->_defaultValues);
|
||||
}
|
||||
if (null !== $value) {
|
||||
$this->setValue($value);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} // end func onQuickFormEvent
|
||||
|
||||
// }}}
|
||||
// {{{ exportValue()
|
||||
|
||||
/**
|
||||
* We don't need values from button-type elements (except submit) and files
|
||||
*/
|
||||
function exportValue(&$submitValues, $assoc = false)
|
||||
{
|
||||
$type = $this->getType();
|
||||
if ('reset' == $type || 'image' == $type || 'button' == $type || 'file' == $type) {
|
||||
return null;
|
||||
} else {
|
||||
return parent::exportValue($submitValues, $assoc);
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
} // end class HTML_QuickForm_element
|
||||
?>
|
||||
200
sites/all/modules/civicrm/packages/HTML/QuickForm/link.php
Normal file
200
sites/all/modules/civicrm/packages/HTML/QuickForm/link.php
Normal file
|
|
@ -0,0 +1,200 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* HTML class for a link type field
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: link.php,v 1.4 2009/04/04 21:34:04 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* HTML class for static data
|
||||
*/
|
||||
require_once 'HTML/QuickForm/static.php';
|
||||
|
||||
/**
|
||||
* HTML class for a link type field
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @version Release: 3.2.11
|
||||
* @since 2.0
|
||||
*/
|
||||
class HTML_QuickForm_link extends HTML_QuickForm_static
|
||||
{
|
||||
// {{{ properties
|
||||
|
||||
/**
|
||||
* Link display text
|
||||
* @var string
|
||||
* @since 1.0
|
||||
* @access private
|
||||
*/
|
||||
var $_text = "";
|
||||
|
||||
// }}}
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string $elementLabel (optional)Link label
|
||||
* @param string $href (optional)Link href
|
||||
* @param string $text (optional)Link display text
|
||||
* @param mixed $attributes (optional)Either a typical HTML attribute string
|
||||
* or an associative array
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws
|
||||
*/
|
||||
function __construct($elementName=null, $elementLabel=null, $href=null, $text=null, $attributes=null)
|
||||
{
|
||||
parent::__construct($elementName, $elementLabel, $attributes);
|
||||
$this->_persistantFreeze = false;
|
||||
$this->_type = 'link';
|
||||
$this->setHref($href);
|
||||
$this->_text = $text;
|
||||
} //end constructor
|
||||
|
||||
// }}}
|
||||
// {{{ setName()
|
||||
|
||||
/**
|
||||
* Sets the input field name
|
||||
*
|
||||
* @param string $name Input field name attribute
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws
|
||||
*/
|
||||
function setName($name)
|
||||
{
|
||||
$this->updateAttributes(array('name'=>$name));
|
||||
} //end func setName
|
||||
|
||||
// }}}
|
||||
// {{{ getName()
|
||||
|
||||
/**
|
||||
* Returns the element name
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
* @throws
|
||||
*/
|
||||
function getName()
|
||||
{
|
||||
return $this->getAttribute('name');
|
||||
} //end func getName
|
||||
|
||||
// }}}
|
||||
// {{{ setValue()
|
||||
|
||||
/**
|
||||
* Sets value for textarea element
|
||||
*
|
||||
* @param string $value Value for password element
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws
|
||||
*/
|
||||
function setValue($value)
|
||||
{
|
||||
return;
|
||||
} //end func setValue
|
||||
|
||||
// }}}
|
||||
// {{{ getValue()
|
||||
|
||||
/**
|
||||
* Returns the value of the form element
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws
|
||||
*/
|
||||
function getValue()
|
||||
{
|
||||
return;
|
||||
} // end func getValue
|
||||
|
||||
|
||||
// }}}
|
||||
// {{{ setHref()
|
||||
|
||||
/**
|
||||
* Sets the links href
|
||||
*
|
||||
* @param string $href
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws
|
||||
*/
|
||||
function setHref($href)
|
||||
{
|
||||
$this->updateAttributes(array('href'=>$href));
|
||||
} // end func setHref
|
||||
|
||||
// }}}
|
||||
// {{{ toHtml()
|
||||
|
||||
/**
|
||||
* Returns the textarea element in HTML
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
* @throws
|
||||
*/
|
||||
function toHtml()
|
||||
{
|
||||
$tabs = $this->_getTabs();
|
||||
$html = "$tabs<a".$this->_getAttrString($this->_attributes).">";
|
||||
$html .= $this->_text;
|
||||
$html .= "</a>";
|
||||
return $html;
|
||||
} //end func toHtml
|
||||
|
||||
// }}}
|
||||
// {{{ getFrozenHtml()
|
||||
|
||||
/**
|
||||
* Returns the value of field without HTML tags (in this case, value is changed to a mask)
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
* @throws
|
||||
*/
|
||||
function getFrozenHtml()
|
||||
{
|
||||
return;
|
||||
} //end func getFrozenHtml
|
||||
|
||||
// }}}
|
||||
|
||||
} //end class HTML_QuickForm_textarea
|
||||
?>
|
||||
115
sites/all/modules/civicrm/packages/HTML/QuickForm/password.php
Normal file
115
sites/all/modules/civicrm/packages/HTML/QuickForm/password.php
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* HTML class for a password type field
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: password.php,v 1.8 2009/04/04 21:34:04 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for <input /> form elements
|
||||
*/
|
||||
require_once 'HTML/QuickForm/input.php';
|
||||
|
||||
/**
|
||||
* HTML class for a password type field
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @version Release: 3.2.11
|
||||
* @since 1.0
|
||||
*/
|
||||
class HTML_QuickForm_password extends HTML_QuickForm_input
|
||||
{
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string $elementName (optional)Input field name attribute
|
||||
* @param string $elementLabel (optional)Input field label
|
||||
* @param mixed $attributes (optional)Either a typical HTML attribute string
|
||||
* or an associative array
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws
|
||||
*/
|
||||
function __construct($elementName=null, $elementLabel=null, $attributes=null)
|
||||
{
|
||||
parent::__construct($elementName, $elementLabel, $attributes);
|
||||
$this->setType('password');
|
||||
} //end constructor
|
||||
|
||||
// }}}
|
||||
// {{{ setSize()
|
||||
|
||||
/**
|
||||
* Sets size of password element
|
||||
*
|
||||
* @param string $size Size of password field
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setSize($size)
|
||||
{
|
||||
$this->updateAttributes(array('size'=>$size));
|
||||
} //end func setSize
|
||||
|
||||
// }}}
|
||||
// {{{ setMaxlength()
|
||||
|
||||
/**
|
||||
* Sets maxlength of password element
|
||||
*
|
||||
* @param string $maxlength Maximum length of password field
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setMaxlength($maxlength)
|
||||
{
|
||||
$this->updateAttributes(array('maxlength'=>$maxlength));
|
||||
} //end func setMaxlength
|
||||
|
||||
// }}}
|
||||
// {{{ getFrozenHtml()
|
||||
|
||||
/**
|
||||
* Returns the value of field without HTML tags (in this case, value is changed to a mask)
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
* @throws
|
||||
*/
|
||||
function getFrozenHtml()
|
||||
{
|
||||
$value = $this->getValue();
|
||||
return ('' != $value? '**********': ' ') .
|
||||
$this->_getPersistantData();
|
||||
} //end func getFrozenHtml
|
||||
|
||||
// }}}
|
||||
|
||||
} //end class HTML_QuickForm_password
|
||||
?>
|
||||
271
sites/all/modules/civicrm/packages/HTML/QuickForm/radio.php
Normal file
271
sites/all/modules/civicrm/packages/HTML/QuickForm/radio.php
Normal file
|
|
@ -0,0 +1,271 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* HTML class for a radio type element
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: radio.php,v 1.20 2009/04/04 21:34:04 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for <input /> form elements
|
||||
*/
|
||||
require_once 'HTML/QuickForm/input.php';
|
||||
|
||||
/**
|
||||
* HTML class for a radio type element
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @version Release: 3.2.11
|
||||
* @since 1.0
|
||||
*/
|
||||
class HTML_QuickForm_radio extends HTML_QuickForm_input
|
||||
{
|
||||
// {{{ properties
|
||||
|
||||
/**
|
||||
* Radio display text
|
||||
* @var string
|
||||
* @since 1.1
|
||||
* @access private
|
||||
*/
|
||||
var $_text = '';
|
||||
|
||||
// }}}
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string Input field name attribute
|
||||
* @param mixed Label(s) for a field
|
||||
* @param string Text to display near the radio
|
||||
* @param string Input field value
|
||||
* @param mixed Either a typical HTML attribute string or an associative array
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function __construct($elementName=null, $elementLabel=null, $text=null, $value=null, $attributes=null)
|
||||
{
|
||||
|
||||
parent::__construct($elementName, $elementLabel, $attributes);
|
||||
if (isset($value)) {
|
||||
$this->setValue($value);
|
||||
}
|
||||
$this->_persistantFreeze = true;
|
||||
$this->setType('radio');
|
||||
$this->_text = $text;
|
||||
// $this->_generateId();
|
||||
if ( ! $this->getAttribute('id') ) {
|
||||
//hack to add 'id' for radio
|
||||
static $idTextStr = 1;
|
||||
if (CRM_Utils_Array::value('id_suffix', $attributes)) {
|
||||
$idSuffix = $attributes['id_suffix'];
|
||||
$this->removeAttribute('id_suffix');
|
||||
}
|
||||
else {
|
||||
$idSuffix = $idTextStr;
|
||||
$idTextStr++;
|
||||
}
|
||||
|
||||
$this->updateAttributes( array('id' => CRM_Utils_String::munge( "CIVICRM_QFID_{$value}_{$idSuffix}" ) ) );
|
||||
}
|
||||
} //end constructor
|
||||
|
||||
// }}}
|
||||
// {{{ setChecked()
|
||||
|
||||
/**
|
||||
* Sets whether radio button is checked
|
||||
*
|
||||
* @param bool $checked Whether the field is checked or not
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setChecked($checked)
|
||||
{
|
||||
if (!$checked) {
|
||||
$this->removeAttribute('checked');
|
||||
} else {
|
||||
$this->updateAttributes(array('checked'=>'checked'));
|
||||
}
|
||||
} //end func setChecked
|
||||
|
||||
// }}}
|
||||
// {{{ getChecked()
|
||||
|
||||
/**
|
||||
* Returns whether radio button is checked
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function getChecked()
|
||||
{
|
||||
return $this->getAttribute('checked');
|
||||
} //end func getChecked
|
||||
|
||||
// }}}
|
||||
// {{{ toHtml()
|
||||
|
||||
/**
|
||||
* Returns the radio element in HTML
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function toHtml()
|
||||
{
|
||||
if (0 == strlen($this->_text)) {
|
||||
$label = '';
|
||||
} elseif ($this->_flagFrozen) {
|
||||
$label = $this->_text;
|
||||
} else {
|
||||
$label = '<label for="' . $this->getAttribute('id') . '">' . $this->_text . '</label>';
|
||||
}
|
||||
return HTML_QuickForm_input::toHtml() . $label;
|
||||
} //end func toHtml
|
||||
|
||||
// }}}
|
||||
// {{{ getFrozenHtml()
|
||||
|
||||
/**
|
||||
* Returns the value of field without HTML tags
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function getFrozenHtml()
|
||||
{
|
||||
if ($this->getChecked()) {
|
||||
return '<tt>(x)</tt>' .
|
||||
$this->_getPersistantData();
|
||||
} else {
|
||||
return '<tt>( )</tt>';
|
||||
}
|
||||
} //end func getFrozenHtml
|
||||
|
||||
// }}}
|
||||
// {{{ setText()
|
||||
|
||||
/**
|
||||
* Sets the radio text
|
||||
*
|
||||
* @param string $text Text to display near the radio button
|
||||
* @since 1.1
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setText($text)
|
||||
{
|
||||
$this->_text = $text;
|
||||
} //end func setText
|
||||
|
||||
// }}}
|
||||
// {{{ getText()
|
||||
|
||||
/**
|
||||
* Returns the radio text
|
||||
*
|
||||
* @since 1.1
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function getText()
|
||||
{
|
||||
return $this->_text;
|
||||
} //end func getText
|
||||
|
||||
// }}}
|
||||
// {{{ onQuickFormEvent()
|
||||
|
||||
/**
|
||||
* Called by HTML_QuickForm whenever form event is made on this element
|
||||
*
|
||||
* @param string $event Name of event
|
||||
* @param mixed $arg event arguments
|
||||
* @param object &$caller calling object
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function onQuickFormEvent($event, $arg, &$caller)
|
||||
{
|
||||
switch ($event) {
|
||||
case 'updateValue':
|
||||
// constant values override both default and submitted ones
|
||||
$value = $this->_findValue($caller->_constantValues);
|
||||
if (null === $value) {
|
||||
// we should retrieve value from submitted values when form is submitted,
|
||||
// else set value from defaults values
|
||||
if ( $caller->isSubmitted( ) ) {
|
||||
$value = $this->_findValue($caller->_submitValues);
|
||||
} else {
|
||||
$value = $this->_findValue($caller->_defaultValues);
|
||||
}
|
||||
}
|
||||
if (!is_null($value) && $value == $this->getValue()) {
|
||||
$this->setChecked(true);
|
||||
} else {
|
||||
$this->setChecked(false);
|
||||
}
|
||||
break;
|
||||
case 'setGroupValue':
|
||||
if ($arg == $this->getValue()) {
|
||||
$this->setChecked(true);
|
||||
} else {
|
||||
$this->setChecked(false);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
parent::onQuickFormEvent($event, $arg, $caller);
|
||||
}
|
||||
return true;
|
||||
} // end func onQuickFormLoad
|
||||
|
||||
// }}}
|
||||
// {{{ exportValue()
|
||||
|
||||
/**
|
||||
* Returns the value attribute if the radio is checked, null if it is not
|
||||
*/
|
||||
function exportValue(&$submitValues, $assoc = false)
|
||||
{
|
||||
$value = $this->_findValue($submitValues);
|
||||
if (null === $value) {
|
||||
// fix to return blank value when all radio's are unselected / not selected
|
||||
// always use submitted values rather than defaults
|
||||
//$value = $this->getChecked()? $this->getValue(): null;
|
||||
$value = '';
|
||||
} elseif ($value != $this->getValue()) {
|
||||
$value = null;
|
||||
}
|
||||
return $this->_prepareValue($value, $assoc);
|
||||
}
|
||||
|
||||
// }}}
|
||||
} //end class HTML_QuickForm_radio
|
||||
?>
|
||||
79
sites/all/modules/civicrm/packages/HTML/QuickForm/reset.php
Normal file
79
sites/all/modules/civicrm/packages/HTML/QuickForm/reset.php
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* HTML class for a reset type element
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: reset.php,v 1.6 2009/04/04 21:34:04 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for <input /> form elements
|
||||
*/
|
||||
require_once 'HTML/QuickForm/input.php';
|
||||
|
||||
/**
|
||||
* HTML class for a reset type element
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @version Release: 3.2.11
|
||||
* @since 1.0
|
||||
*/
|
||||
class HTML_QuickForm_reset extends HTML_QuickForm_input
|
||||
{
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string $elementName (optional)Input field name attribute
|
||||
* @param string $value (optional)Input field value
|
||||
* @param mixed $attributes (optional)Either a typical HTML attribute string
|
||||
* or an associative array
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function __construct($elementName=null, $value=null, $attributes=null)
|
||||
{
|
||||
parent::__construct($elementName, null, $attributes);
|
||||
$this->setValue($value);
|
||||
$this->setType('reset');
|
||||
} //end constructor
|
||||
|
||||
// }}}
|
||||
// {{{ freeze()
|
||||
|
||||
/**
|
||||
* Freeze the element so that only its value is returned
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function freeze()
|
||||
{
|
||||
return false;
|
||||
} //end func freeze
|
||||
|
||||
// }}}
|
||||
|
||||
} //end class HTML_QuickForm_reset
|
||||
?>
|
||||
627
sites/all/modules/civicrm/packages/HTML/QuickForm/select.php
Normal file
627
sites/all/modules/civicrm/packages/HTML/QuickForm/select.php
Normal file
|
|
@ -0,0 +1,627 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Class to dynamically create an HTML SELECT
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: select.php,v 1.34 2009/04/04 21:34:04 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for form elements
|
||||
*/
|
||||
require_once 'HTML/QuickForm/element.php';
|
||||
|
||||
/**
|
||||
* Class to dynamically create an HTML SELECT
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @version Release: 3.2.11
|
||||
* @since 1.0
|
||||
*/
|
||||
class HTML_QuickForm_select extends HTML_QuickForm_element {
|
||||
|
||||
// {{{ properties
|
||||
|
||||
/**
|
||||
* Contains the select options
|
||||
*
|
||||
* @var array
|
||||
* @since 1.0
|
||||
* @access private
|
||||
*/
|
||||
var $_options = array();
|
||||
|
||||
/**
|
||||
* Default values of the SELECT
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0
|
||||
* @access private
|
||||
*/
|
||||
var $_values = null;
|
||||
|
||||
// }}}
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string Select name attribute
|
||||
* @param mixed Label(s) for the select
|
||||
* @param mixed Data to be used to populate options
|
||||
* @param mixed Either a typical HTML attribute string or an associative array
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function __construct($elementName=null, $elementLabel=null, $options=null, $attributes=null)
|
||||
{
|
||||
parent::__construct($elementName, $elementLabel, $attributes);
|
||||
$this->_persistantFreeze = true;
|
||||
$this->_type = 'select';
|
||||
if (isset($options)) {
|
||||
$this->load($options);
|
||||
}
|
||||
} //end constructor
|
||||
|
||||
// }}}
|
||||
// {{{ apiVersion()
|
||||
|
||||
/**
|
||||
* Returns the current API version
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return double
|
||||
*/
|
||||
function apiVersion()
|
||||
{
|
||||
return 2.3;
|
||||
} //end func apiVersion
|
||||
|
||||
// }}}
|
||||
// {{{ setSelected()
|
||||
|
||||
/**
|
||||
* Sets the default values of the select box
|
||||
*
|
||||
* @param mixed $values Array or comma delimited string of selected values
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setSelected($values)
|
||||
{
|
||||
if (is_string($values) && $this->getMultiple()) {
|
||||
$values = preg_split("/[ ]?,[ ]?/", $values);
|
||||
}
|
||||
if (is_array($values)) {
|
||||
$this->_values = array_values($values);
|
||||
} else {
|
||||
$this->_values = array($values);
|
||||
}
|
||||
} //end func setSelected
|
||||
|
||||
// }}}
|
||||
// {{{ getSelected()
|
||||
|
||||
/**
|
||||
* Returns an array of the selected values
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return array of selected values
|
||||
*/
|
||||
function getSelected()
|
||||
{
|
||||
return $this->_values;
|
||||
} // end func getSelected
|
||||
|
||||
// }}}
|
||||
// {{{ setName()
|
||||
|
||||
/**
|
||||
* Sets the input field name
|
||||
*
|
||||
* @param string $name Input field name attribute
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setName($name)
|
||||
{
|
||||
$this->updateAttributes(array('name' => $name));
|
||||
} //end func setName
|
||||
|
||||
// }}}
|
||||
// {{{ getName()
|
||||
|
||||
/**
|
||||
* Returns the element name
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function getName()
|
||||
{
|
||||
return $this->getAttribute('name');
|
||||
} //end func getName
|
||||
|
||||
// }}}
|
||||
// {{{ getPrivateName()
|
||||
|
||||
/**
|
||||
* Returns the element name (possibly with brackets appended)
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function getPrivateName()
|
||||
{
|
||||
if ($this->getAttribute('multiple')) {
|
||||
return $this->getName() . '[]';
|
||||
} else {
|
||||
return $this->getName();
|
||||
}
|
||||
} //end func getPrivateName
|
||||
|
||||
// }}}
|
||||
// {{{ setValue()
|
||||
|
||||
/**
|
||||
* Sets the value of the form element
|
||||
*
|
||||
* @param mixed $values Array or comma delimited string of selected values
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setValue($value)
|
||||
{
|
||||
$this->setSelected($value);
|
||||
} // end func setValue
|
||||
|
||||
// }}}
|
||||
// {{{ getValue()
|
||||
|
||||
/**
|
||||
* Returns an array of the selected values
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return array of selected values
|
||||
*/
|
||||
function getValue()
|
||||
{
|
||||
return $this->_values;
|
||||
} // end func getValue
|
||||
|
||||
// }}}
|
||||
// {{{ setSize()
|
||||
|
||||
/**
|
||||
* Sets the select field size, only applies to 'multiple' selects
|
||||
*
|
||||
* @param int $size Size of select field
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setSize($size)
|
||||
{
|
||||
$this->updateAttributes(array('size' => $size));
|
||||
} //end func setSize
|
||||
|
||||
// }}}
|
||||
// {{{ getSize()
|
||||
|
||||
/**
|
||||
* Returns the select field size
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return int
|
||||
*/
|
||||
function getSize()
|
||||
{
|
||||
return $this->getAttribute('size');
|
||||
} //end func getSize
|
||||
|
||||
// }}}
|
||||
// {{{ setMultiple()
|
||||
|
||||
/**
|
||||
* Sets the select mutiple attribute
|
||||
*
|
||||
* @param bool $multiple Whether the select supports multi-selections
|
||||
* @since 1.2
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setMultiple($multiple)
|
||||
{
|
||||
if ($multiple) {
|
||||
$this->updateAttributes(array('multiple' => 'multiple'));
|
||||
} else {
|
||||
$this->removeAttribute('multiple');
|
||||
}
|
||||
} //end func setMultiple
|
||||
|
||||
// }}}
|
||||
// {{{ getMultiple()
|
||||
|
||||
/**
|
||||
* Returns the select mutiple attribute
|
||||
*
|
||||
* @since 1.2
|
||||
* @access public
|
||||
* @return bool true if multiple select, false otherwise
|
||||
*/
|
||||
function getMultiple()
|
||||
{
|
||||
return (bool)$this->getAttribute('multiple');
|
||||
} //end func getMultiple
|
||||
|
||||
// }}}
|
||||
// {{{ addOption()
|
||||
|
||||
/**
|
||||
* Adds a new OPTION to the SELECT
|
||||
*
|
||||
* @param string $text Display text for the OPTION
|
||||
* @param string $value Value for the OPTION
|
||||
* @param mixed $attributes Either a typical HTML attribute string
|
||||
* or an associative array
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function addOption($text, $value, $attributes=null)
|
||||
{
|
||||
if (null === $attributes) {
|
||||
$attributes = array('value' => (string)$value);
|
||||
} else {
|
||||
$attributes = $this->_parseAttributes($attributes);
|
||||
if (isset($attributes['selected'])) {
|
||||
// the 'selected' attribute will be set in toHtml()
|
||||
$this->_removeAttr('selected', $attributes);
|
||||
if (is_null($this->_values)) {
|
||||
$this->_values = array($value);
|
||||
} elseif (!in_array($value, $this->_values)) {
|
||||
$this->_values[] = $value;
|
||||
}
|
||||
}
|
||||
$this->_updateAttrArray($attributes, array('value' => (string)$value));
|
||||
}
|
||||
$this->_options[] = array('text' => $text, 'attr' => $attributes);
|
||||
} // end func addOption
|
||||
|
||||
// }}}
|
||||
// {{{ loadArray()
|
||||
|
||||
/**
|
||||
* Loads the options from an associative array
|
||||
*
|
||||
* @param array $arr Associative array of options
|
||||
* @param mixed $values (optional) Array or comma delimited string of selected values
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return PEAR_Error on error or true
|
||||
* @throws PEAR_Error
|
||||
*/
|
||||
function loadArray($arr, $values=null)
|
||||
{
|
||||
if (!is_array($arr)) {
|
||||
return PEAR::raiseError('Argument 1 of HTML_Select::loadArray is not a valid array');
|
||||
}
|
||||
if (isset($values)) {
|
||||
$this->setSelected($values);
|
||||
}
|
||||
foreach ($arr as $key => $val) {
|
||||
// Warning: new API since release 2.3
|
||||
$this->addOption($val, $key);
|
||||
}
|
||||
return true;
|
||||
} // end func loadArray
|
||||
|
||||
// }}}
|
||||
// {{{ loadDbResult()
|
||||
|
||||
/**
|
||||
* Loads the options from DB_result object
|
||||
*
|
||||
* If no column names are specified the first two columns of the result are
|
||||
* used as the text and value columns respectively
|
||||
* @param object $result DB_result object
|
||||
* @param string $textCol (optional) Name of column to display as the OPTION text
|
||||
* @param string $valueCol (optional) Name of column to use as the OPTION value
|
||||
* @param mixed $values (optional) Array or comma delimited string of selected values
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return PEAR_Error on error or true
|
||||
* @throws PEAR_Error
|
||||
*/
|
||||
function loadDbResult(&$result, $textCol=null, $valueCol=null, $values=null)
|
||||
{
|
||||
if (!is_object($result) || !is_a($result, 'db_result')) {
|
||||
return PEAR::raiseError('Argument 1 of HTML_Select::loadDbResult is not a valid DB_result');
|
||||
}
|
||||
if (isset($values)) {
|
||||
$this->setValue($values);
|
||||
}
|
||||
$fetchMode = ($textCol && $valueCol) ? DB_FETCHMODE_ASSOC : DB_FETCHMODE_ORDERED;
|
||||
while (is_array($row = $result->fetchRow($fetchMode)) ) {
|
||||
if ($fetchMode == DB_FETCHMODE_ASSOC) {
|
||||
$this->addOption($row[$textCol], $row[$valueCol]);
|
||||
} else {
|
||||
$this->addOption($row[0], $row[1]);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} // end func loadDbResult
|
||||
|
||||
// }}}
|
||||
// {{{ loadQuery()
|
||||
|
||||
/**
|
||||
* Queries a database and loads the options from the results
|
||||
*
|
||||
* @param mixed $conn Either an existing DB connection or a valid dsn
|
||||
* @param string $sql SQL query string
|
||||
* @param string $textCol (optional) Name of column to display as the OPTION text
|
||||
* @param string $valueCol (optional) Name of column to use as the OPTION value
|
||||
* @param mixed $values (optional) Array or comma delimited string of selected values
|
||||
* @since 1.1
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws PEAR_Error
|
||||
*/
|
||||
function loadQuery(&$conn, $sql, $textCol=null, $valueCol=null, $values=null)
|
||||
{
|
||||
if (is_string($conn)) {
|
||||
require_once('DB.php');
|
||||
$dbConn = DB::connect($conn, true);
|
||||
if (DB::isError($dbConn)) {
|
||||
return $dbConn;
|
||||
}
|
||||
} elseif (is_subclass_of($conn, "db_common")) {
|
||||
$dbConn = &$conn;
|
||||
} else {
|
||||
return PEAR::raiseError('Argument 1 of HTML_Select::loadQuery is not a valid type');
|
||||
}
|
||||
$result = $dbConn->query($sql);
|
||||
if (DB::isError($result)) {
|
||||
return $result;
|
||||
}
|
||||
$this->loadDbResult($result, $textCol, $valueCol, $values);
|
||||
$result->free();
|
||||
if (is_string($conn)) {
|
||||
$dbConn->disconnect();
|
||||
}
|
||||
return true;
|
||||
} // end func loadQuery
|
||||
|
||||
// }}}
|
||||
// {{{ load()
|
||||
|
||||
/**
|
||||
* Loads options from different types of data sources
|
||||
*
|
||||
* This method is a simulated overloaded method. The arguments, other than the
|
||||
* first are optional and only mean something depending on the type of the first argument.
|
||||
* If the first argument is an array then all arguments are passed in order to loadArray.
|
||||
* If the first argument is a db_result then all arguments are passed in order to loadDbResult.
|
||||
* If the first argument is a string or a DB connection then all arguments are
|
||||
* passed in order to loadQuery.
|
||||
* @param mixed $options Options source currently supports assoc array or DB_result
|
||||
* @param mixed $param1 (optional) See function detail
|
||||
* @param mixed $param2 (optional) See function detail
|
||||
* @param mixed $param3 (optional) See function detail
|
||||
* @param mixed $param4 (optional) See function detail
|
||||
* @since 1.1
|
||||
* @access public
|
||||
* @return PEAR_Error on error or true
|
||||
* @throws PEAR_Error
|
||||
*/
|
||||
function load(&$options, $param1=null, $param2=null, $param3=null, $param4=null)
|
||||
{
|
||||
switch (true) {
|
||||
case is_array($options):
|
||||
return $this->loadArray($options, $param1);
|
||||
break;
|
||||
case (is_a($options, 'db_result')):
|
||||
return $this->loadDbResult($options, $param1, $param2, $param3);
|
||||
break;
|
||||
case (is_string($options) && !empty($options) || is_subclass_of($options, "db_common")):
|
||||
return $this->loadQuery($options, $param1, $param2, $param3, $param4);
|
||||
break;
|
||||
}
|
||||
} // end func load
|
||||
|
||||
// }}}
|
||||
// {{{ toHtml()
|
||||
|
||||
/**
|
||||
* Returns the SELECT in HTML
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function toHtml()
|
||||
{
|
||||
if ($this->_flagFrozen) {
|
||||
return $this->getFrozenHtml();
|
||||
} else {
|
||||
$tabs = $this->_getTabs();
|
||||
$strHtml = '';
|
||||
|
||||
if ($this->getComment() != '') {
|
||||
$strHtml .= $tabs . '<!-- ' . $this->getComment() . " //-->\n";
|
||||
}
|
||||
|
||||
if (!$this->getMultiple()) {
|
||||
$attrString = $this->_getAttrString($this->_attributes);
|
||||
} else {
|
||||
$myName = $this->getName();
|
||||
$this->setName($myName . '[]');
|
||||
$attrString = $this->_getAttrString($this->_attributes);
|
||||
$this->setName($myName);
|
||||
}
|
||||
$strHtml .= $tabs . '<select' . $attrString . ">\n";
|
||||
|
||||
$strValues = is_array($this->_values)? array_map('strval', $this->_values): array();
|
||||
foreach ($this->_options as $option) {
|
||||
if (!empty($strValues) && in_array($option['attr']['value'], $strValues, true)) {
|
||||
$option['attr']['selected'] = 'selected';
|
||||
}
|
||||
$strHtml .= $tabs . "\t<option" . $this->_getAttrString($option['attr']) . '>' .
|
||||
$option['text'] . "</option>\n";
|
||||
}
|
||||
|
||||
return $strHtml . $tabs . '</select>';
|
||||
}
|
||||
} //end func toHtml
|
||||
|
||||
// }}}
|
||||
// {{{ getFrozenHtml()
|
||||
|
||||
/**
|
||||
* Returns the value of field without HTML tags
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function getFrozenHtml()
|
||||
{
|
||||
$value = array();
|
||||
if (is_array($this->_values)) {
|
||||
foreach ($this->_values as $key => $val) {
|
||||
if ( $val || is_numeric($val) ) {
|
||||
foreach ($this->_options as $oKey => $oVal ) {
|
||||
if (0 == strcmp($val, $this->_options[$oKey]['attr']['value'])) {
|
||||
$value[$key] = $oVal['text'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$html = empty($value)? ' ': join('<br />', $value);
|
||||
if ($this->_persistantFreeze) {
|
||||
$name = $this->getPrivateName();
|
||||
// Only use id attribute if doing single hidden input
|
||||
if (1 == count($value)) {
|
||||
$id = $this->getAttribute('id');
|
||||
$idAttr = isset($id)? array('id' => $id): array();
|
||||
} else {
|
||||
$idAttr = array();
|
||||
}
|
||||
foreach ($value as $key => $item) {
|
||||
$html .= '<input' . $this->_getAttrString(array(
|
||||
'type' => 'hidden',
|
||||
'name' => $name,
|
||||
'value' => $this->_values[$key]
|
||||
) + $idAttr) . ' />';
|
||||
}
|
||||
}
|
||||
return $html;
|
||||
} //end func getFrozenHtml
|
||||
|
||||
// }}}
|
||||
// {{{ exportValue()
|
||||
|
||||
/**
|
||||
* We check the options and return only the values that _could_ have been
|
||||
* selected. We also return a scalar value if select is not "multiple"
|
||||
*/
|
||||
function exportValue(&$submitValues, $assoc = false)
|
||||
{
|
||||
$value = $this->_findValue($submitValues);
|
||||
if (is_null($value)) {
|
||||
// if value is null, default value is set for advselect
|
||||
// fix for CRM-1431 - kurund
|
||||
//$value = $this->getValue();
|
||||
} elseif(!is_array($value)) {
|
||||
$value = array($value);
|
||||
}
|
||||
if (is_array($value) && !empty($this->_options)) {
|
||||
$cleanValue = null;
|
||||
foreach ($value as $v) {
|
||||
for ($i = 0, $optCount = count($this->_options); $i < $optCount; $i++) {
|
||||
if (0 == strcmp($v, $this->_options[$i]['attr']['value'])) {
|
||||
$cleanValue[] = $v;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//if value is null make it empty array, checked most of
|
||||
// the stuff, value is null for advselect
|
||||
// fix for CRM-1431 - kurund
|
||||
if (is_null($value)) {
|
||||
$cleanValue = array();
|
||||
} else {
|
||||
$cleanValue = $value;
|
||||
}
|
||||
}
|
||||
if (is_array($cleanValue) && !$this->getMultiple()) {
|
||||
if ( isset( $cleanValue[0] ) ) {
|
||||
return $this->_prepareValue($cleanValue[0], $assoc);
|
||||
}
|
||||
} else {
|
||||
return $this->_prepareValue($cleanValue, $assoc);
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ onQuickFormEvent()
|
||||
|
||||
function onQuickFormEvent($event, $arg, &$caller)
|
||||
{
|
||||
if ('updateValue' == $event) {
|
||||
$value = $this->_findValue($caller->_constantValues);
|
||||
if (null === $value) {
|
||||
$value = $this->_findValue($caller->_submitValues);
|
||||
// Fix for bug #4465 & #5269
|
||||
// XXX: should we push this to element::onQuickFormEvent()?
|
||||
if (null === $value && (!$caller->isSubmitted() || !$this->getMultiple())) {
|
||||
$value = $this->_findValue($caller->_defaultValues);
|
||||
}
|
||||
}
|
||||
if (null !== $value) {
|
||||
$this->setValue($value);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return parent::onQuickFormEvent($event, $arg, $caller);
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
} //end class HTML_QuickForm_select
|
||||
?>
|
||||
201
sites/all/modules/civicrm/packages/HTML/QuickForm/static.php
Normal file
201
sites/all/modules/civicrm/packages/HTML/QuickForm/static.php
Normal file
|
|
@ -0,0 +1,201 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* HTML class for static data
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Wojciech Gdela <eltehaem@poczta.onet.pl>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: static.php,v 1.8 2009/04/04 21:34:04 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for form elements
|
||||
*/
|
||||
require_once 'HTML/QuickForm/element.php';
|
||||
|
||||
/**
|
||||
* HTML class for static data
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Wojciech Gdela <eltehaem@poczta.onet.pl>
|
||||
* @version Release: 3.2.11
|
||||
* @since 2.7
|
||||
*/
|
||||
class HTML_QuickForm_static extends HTML_QuickForm_element {
|
||||
|
||||
// {{{ properties
|
||||
|
||||
/**
|
||||
* Display text
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_text = null;
|
||||
|
||||
// }}}
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string $elementLabel (optional)Label
|
||||
* @param string $text (optional)Display text
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function __construct($elementName=null, $elementLabel=null, $text=null)
|
||||
{
|
||||
parent::__construct($elementName, $elementLabel);
|
||||
$this->_persistantFreeze = false;
|
||||
$this->_type = 'static';
|
||||
$this->_text = $text;
|
||||
} //end constructor
|
||||
|
||||
// }}}
|
||||
// {{{ setName()
|
||||
|
||||
/**
|
||||
* Sets the element name
|
||||
*
|
||||
* @param string $name Element name
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setName($name)
|
||||
{
|
||||
$this->updateAttributes(array('name'=>$name));
|
||||
} //end func setName
|
||||
|
||||
// }}}
|
||||
// {{{ getName()
|
||||
|
||||
/**
|
||||
* Returns the element name
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function getName()
|
||||
{
|
||||
return $this->getAttribute('name');
|
||||
} //end func getName
|
||||
|
||||
// }}}
|
||||
// {{{ setText()
|
||||
|
||||
/**
|
||||
* Sets the text
|
||||
*
|
||||
* @param string $text
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setText($text)
|
||||
{
|
||||
$this->_text = $text;
|
||||
} // end func setText
|
||||
|
||||
// }}}
|
||||
// {{{ setValue()
|
||||
|
||||
/**
|
||||
* Sets the text (uses the standard setValue call to emulate a form element.
|
||||
*
|
||||
* @param string $text
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setValue($text)
|
||||
{
|
||||
$this->setText($text);
|
||||
} // end func setValue
|
||||
|
||||
// }}}
|
||||
// {{{ toHtml()
|
||||
|
||||
/**
|
||||
* Returns the static text element in HTML
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function toHtml()
|
||||
{
|
||||
return $this->_getTabs() . $this->_text;
|
||||
} //end func toHtml
|
||||
|
||||
// }}}
|
||||
// {{{ getFrozenHtml()
|
||||
|
||||
/**
|
||||
* Returns the value of field without HTML tags
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function getFrozenHtml()
|
||||
{
|
||||
return $this->toHtml();
|
||||
} //end func getFrozenHtml
|
||||
|
||||
// }}}
|
||||
// {{{ onQuickFormEvent()
|
||||
|
||||
/**
|
||||
* Called by HTML_QuickForm whenever form event is made on this element
|
||||
*
|
||||
* @param string $event Name of event
|
||||
* @param mixed $arg event arguments
|
||||
* @param object &$caller calling object
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws
|
||||
*/
|
||||
function onQuickFormEvent($event, $arg, &$caller)
|
||||
{
|
||||
switch ($event) {
|
||||
case 'updateValue':
|
||||
// do NOT use submitted values for static elements
|
||||
$value = $this->_findValue($caller->_constantValues);
|
||||
if (null === $value) {
|
||||
$value = $this->_findValue($caller->_defaultValues);
|
||||
}
|
||||
if (null !== $value) {
|
||||
$this->setValue($value);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
parent::onQuickFormEvent($event, $arg, $caller);
|
||||
}
|
||||
return true;
|
||||
} // end func onQuickFormEvent
|
||||
|
||||
// }}}
|
||||
// {{{ exportValue()
|
||||
|
||||
/**
|
||||
* We override this here because we don't want any values from static elements
|
||||
*/
|
||||
function exportValue(&$submitValues, $assoc = false)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// }}}
|
||||
} //end class HTML_QuickForm_static
|
||||
?>
|
||||
89
sites/all/modules/civicrm/packages/HTML/QuickForm/submit.php
Normal file
89
sites/all/modules/civicrm/packages/HTML/QuickForm/submit.php
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* HTML class for a submit type element
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: submit.php,v 1.6 2009/04/04 21:34:04 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for <input /> form elements
|
||||
*/
|
||||
require_once 'HTML/QuickForm/input.php';
|
||||
|
||||
/**
|
||||
* HTML class for a submit type element
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @version Release: 3.2.11
|
||||
* @since 1.0
|
||||
*/
|
||||
class HTML_QuickForm_submit extends HTML_QuickForm_input
|
||||
{
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string Input field name attribute
|
||||
* @param string Input field value
|
||||
* @param mixed Either a typical HTML attribute string or an associative array
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function __construct($elementName=null, $value=null, $attributes=null)
|
||||
{
|
||||
parent::__construct($elementName, null, $attributes);
|
||||
$this->setValue($value);
|
||||
$this->setType('submit');
|
||||
} //end constructor
|
||||
|
||||
// }}}
|
||||
// {{{ freeze()
|
||||
|
||||
/**
|
||||
* Freeze the element so that only its value is returned
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function freeze()
|
||||
{
|
||||
return false;
|
||||
} //end func freeze
|
||||
|
||||
// }}}
|
||||
// {{{ exportValue()
|
||||
|
||||
/**
|
||||
* Only return the value if it is found within $submitValues (i.e. if
|
||||
* this particular submit button was clicked)
|
||||
*/
|
||||
function exportValue(&$submitValues, $assoc = false)
|
||||
{
|
||||
return $this->_prepareValue($this->_findValue($submitValues), $assoc);
|
||||
}
|
||||
|
||||
// }}}
|
||||
} //end class HTML_QuickForm_submit
|
||||
?>
|
||||
98
sites/all/modules/civicrm/packages/HTML/QuickForm/text.php
Normal file
98
sites/all/modules/civicrm/packages/HTML/QuickForm/text.php
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* HTML class for a text field
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: text.php,v 1.7 2009/04/04 21:34:04 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for <input /> form elements
|
||||
*/
|
||||
require_once 'HTML/QuickForm/input.php';
|
||||
|
||||
/**
|
||||
* HTML class for a text field
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @version Release: 3.2.11
|
||||
* @since 1.0
|
||||
*/
|
||||
class HTML_QuickForm_text extends HTML_QuickForm_input
|
||||
{
|
||||
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string $elementName (optional)Input field name attribute
|
||||
* @param string $elementLabel (optional)Input field label
|
||||
* @param mixed $attributes (optional)Either a typical HTML attribute string
|
||||
* or an associative array
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function __construct($elementName=null, $elementLabel=null, $attributes=null)
|
||||
{
|
||||
parent::__construct($elementName, $elementLabel, $attributes);
|
||||
$this->_persistantFreeze = true;
|
||||
$this->setType('text');
|
||||
} //end constructor
|
||||
|
||||
// }}}
|
||||
// {{{ setSize()
|
||||
|
||||
/**
|
||||
* Sets size of text field
|
||||
*
|
||||
* @param string $size Size of text field
|
||||
* @since 1.3
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setSize($size)
|
||||
{
|
||||
$this->updateAttributes(array('size'=>$size));
|
||||
} //end func setSize
|
||||
|
||||
// }}}
|
||||
// {{{ setMaxlength()
|
||||
|
||||
/**
|
||||
* Sets maxlength of text field
|
||||
*
|
||||
* @param string $maxlength Maximum length of text field
|
||||
* @since 1.3
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setMaxlength($maxlength)
|
||||
{
|
||||
$this->updateAttributes(array('maxlength'=>$maxlength));
|
||||
} //end func setMaxlength
|
||||
|
||||
// }}}
|
||||
|
||||
} //end class HTML_QuickForm_text
|
||||
?>
|
||||
229
sites/all/modules/civicrm/packages/HTML/QuickForm/textarea.php
Normal file
229
sites/all/modules/civicrm/packages/HTML/QuickForm/textarea.php
Normal file
|
|
@ -0,0 +1,229 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* HTML class for a textarea type field
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: textarea.php,v 1.13 2009/04/04 21:34:04 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for form elements
|
||||
*/
|
||||
require_once 'HTML/QuickForm/element.php';
|
||||
|
||||
/**
|
||||
* HTML class for a textarea type field
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @version Release: 3.2.11
|
||||
* @since 1.0
|
||||
*/
|
||||
class HTML_QuickForm_textarea extends HTML_QuickForm_element
|
||||
{
|
||||
// {{{ properties
|
||||
|
||||
/**
|
||||
* Field value
|
||||
* @var string
|
||||
* @since 1.0
|
||||
* @access private
|
||||
*/
|
||||
var $_value = null;
|
||||
|
||||
// }}}
|
||||
// {{{ constructor
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string Input field name attribute
|
||||
* @param mixed Label(s) for a field
|
||||
* @param mixed Either a typical HTML attribute string or an associative array
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function __construct($elementName=null, $elementLabel=null, $attributes=null)
|
||||
{
|
||||
parent::__construct($elementName, $elementLabel, $attributes);
|
||||
$this->_persistantFreeze = true;
|
||||
$this->_type = 'textarea';
|
||||
} //end constructor
|
||||
|
||||
// }}}
|
||||
// {{{ setName()
|
||||
|
||||
/**
|
||||
* Sets the input field name
|
||||
*
|
||||
* @param string $name Input field name attribute
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setName($name)
|
||||
{
|
||||
$this->updateAttributes(array('name'=>$name));
|
||||
} //end func setName
|
||||
|
||||
// }}}
|
||||
// {{{ getName()
|
||||
|
||||
/**
|
||||
* Returns the element name
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function getName()
|
||||
{
|
||||
return $this->getAttribute('name');
|
||||
} //end func getName
|
||||
|
||||
// }}}
|
||||
// {{{ setValue()
|
||||
|
||||
/**
|
||||
* Sets value for textarea element
|
||||
*
|
||||
* @param string $value Value for textarea element
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setValue($value)
|
||||
{
|
||||
$this->_value = $value;
|
||||
} //end func setValue
|
||||
|
||||
// }}}
|
||||
// {{{ getValue()
|
||||
|
||||
/**
|
||||
* Returns the value of the form element
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function getValue()
|
||||
{
|
||||
return $this->_value;
|
||||
} // end func getValue
|
||||
|
||||
// }}}
|
||||
// {{{ setWrap()
|
||||
|
||||
/**
|
||||
* Sets wrap type for textarea element
|
||||
*
|
||||
* @param string $wrap Wrap type
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setWrap($wrap)
|
||||
{
|
||||
$this->updateAttributes(array('wrap' => $wrap));
|
||||
} //end func setWrap
|
||||
|
||||
// }}}
|
||||
// {{{ setRows()
|
||||
|
||||
/**
|
||||
* Sets height in rows for textarea element
|
||||
*
|
||||
* @param string $rows Height expressed in rows
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setRows($rows)
|
||||
{
|
||||
$this->updateAttributes(array('rows' => $rows));
|
||||
} //end func setRows
|
||||
|
||||
// }}}
|
||||
// {{{ setCols()
|
||||
|
||||
/**
|
||||
* Sets width in cols for textarea element
|
||||
*
|
||||
* @param string $cols Width expressed in cols
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setCols($cols)
|
||||
{
|
||||
$this->updateAttributes(array('cols' => $cols));
|
||||
} //end func setCols
|
||||
|
||||
// }}}
|
||||
// {{{ toHtml()
|
||||
|
||||
/**
|
||||
* Returns the textarea element in HTML
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function toHtml()
|
||||
{
|
||||
if ($this->_flagFrozen) {
|
||||
return $this->getFrozenHtml();
|
||||
} else {
|
||||
return $this->_getTabs() .
|
||||
'<textarea' . $this->_getAttrString($this->_attributes) . '>' .
|
||||
// because we wrap the form later we don't want the text indented
|
||||
preg_replace("/(\r\n|\n|\r)/", '
', htmlspecialchars($this->_value)) .
|
||||
'</textarea>';
|
||||
}
|
||||
} //end func toHtml
|
||||
|
||||
// }}}
|
||||
// {{{ getFrozenHtml()
|
||||
|
||||
/**
|
||||
* Returns the value of field without HTML tags (in this case, value is changed to a mask)
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function getFrozenHtml()
|
||||
{
|
||||
$value = htmlspecialchars($this->getValue());
|
||||
if ($this->getAttribute('wrap') == 'off') {
|
||||
$html = $this->_getTabs() . '<pre>' . $value."</pre>\n";
|
||||
} else {
|
||||
$html = nl2br($value)."\n";
|
||||
}
|
||||
return $html . $this->_getPersistantData();
|
||||
} //end func getFrozenHtml
|
||||
|
||||
// }}}
|
||||
|
||||
} //end class HTML_QuickForm_textarea
|
||||
?>
|
||||
153
sites/all/modules/civicrm/packages/HTML/QuickForm/xbutton.php
Normal file
153
sites/all/modules/civicrm/packages/HTML/QuickForm/xbutton.php
Normal file
|
|
@ -0,0 +1,153 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Class for HTML 4.0 <button> element
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.01 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_01.txt If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2001-2009 The PHP Group
|
||||
* @license http://www.php.net/license/3_01.txt PHP License 3.01
|
||||
* @version CVS: $Id: xbutton.php,v 1.3 2009/04/04 21:34:04 avb Exp $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for form elements
|
||||
*/
|
||||
require_once 'HTML/QuickForm/element.php';
|
||||
|
||||
/**
|
||||
* Class for HTML 4.0 <button> element
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @version Release: 3.2.11
|
||||
* @since 3.2.3
|
||||
*/
|
||||
class HTML_QuickForm_xbutton extends HTML_QuickForm_element
|
||||
{
|
||||
/**
|
||||
* Contents of the <button> tag
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_content;
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string Button name
|
||||
* @param string Button content (HTML to add between <button></button> tags)
|
||||
* @param mixed Either a typical HTML attribute string or an associative array
|
||||
* @access public
|
||||
*/
|
||||
function __construct($elementName = null, $elementContent = null, $attributes = null)
|
||||
{
|
||||
parent::__construct($elementName, null, $attributes);
|
||||
$this->setContent($elementContent);
|
||||
$this->setPersistantFreeze(false);
|
||||
$this->_type = 'xbutton';
|
||||
}
|
||||
|
||||
|
||||
function toHtml()
|
||||
{
|
||||
return '<button' . $this->getAttributes(true) . '>' . $this->_content . '</button>';
|
||||
}
|
||||
|
||||
|
||||
function getFrozenHtml()
|
||||
{
|
||||
return $this->toHtml();
|
||||
}
|
||||
|
||||
|
||||
function freeze()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
function setName($name)
|
||||
{
|
||||
$this->updateAttributes(array(
|
||||
'name' => $name
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
function getName()
|
||||
{
|
||||
return $this->getAttribute('name');
|
||||
}
|
||||
|
||||
|
||||
function setValue($value)
|
||||
{
|
||||
$this->updateAttributes(array(
|
||||
'value' => $value
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
function getValue()
|
||||
{
|
||||
return $this->getAttribute('value');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the contents of the button element
|
||||
*
|
||||
* @param string Button content (HTML to add between <button></button> tags)
|
||||
*/
|
||||
function setContent($content)
|
||||
{
|
||||
$this->_content = $content;
|
||||
}
|
||||
|
||||
|
||||
function onQuickFormEvent($event, $arg, &$caller)
|
||||
{
|
||||
if ('updateValue' != $event) {
|
||||
return parent::onQuickFormEvent($event, $arg, $caller);
|
||||
} else {
|
||||
$value = $this->_findValue($caller->_constantValues);
|
||||
if (null === $value) {
|
||||
$value = $this->_findValue($caller->_defaultValues);
|
||||
}
|
||||
if (null !== $value) {
|
||||
$this->setValue($value);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a 'safe' element's value
|
||||
*
|
||||
* The value is only returned if the button's type is "submit" and if this
|
||||
* particlular button was clicked
|
||||
*/
|
||||
function exportValue(&$submitValues, $assoc = false)
|
||||
{
|
||||
if ('submit' == $this->getAttribute('type')) {
|
||||
return $this->_prepareValue($this->_findValue($submitValues), $assoc);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue