/trunk/jrest/lib/.directory |
---|
New file |
0,0 → 1,2 |
[Dolphin] |
Timestamp=2010,6,10,16,46,25 |
/trunk/jrest/lib/WdHTMLParser.php |
---|
New file |
0,0 → 1,144 |
<?php |
/** |
* |
* @author Olivier Laviale |
* @see http://www.weirdog.com/blog/php/un-parser-html-des-plus-leger.html |
* |
*/ |
class WdHTMLParser { |
private $encoding; |
private $matches; |
private $escaped; |
private $opened = array(); |
public $malformed; |
public function parse($html, $namespace=NULL, $encoding='utf-8') { |
$this->malformed = false; |
$this->encoding = $encoding; |
// we take care of escaping comments and processing options. they will not be parsed |
// and will end as text nodes |
$html = $this->escapeSpecials($html); |
// in order to create a tree, we first need to split the HTML using the markups, |
// creating a nice flat array of texts and opening and closing markups. |
// |
// the array can be read as follows : |
// |
// i+0 => some text |
// i+1 => '/' for closing markups, nothing otherwise |
// i+2 => the markup it self, without the '<' '>' |
// |
// note that i+2 might end with a '/' indicating an auto-closing markup |
$this->matches = preg_split('#<(/?)' . $namespace . '([^>]*)>#', $html, -1, PREG_SPLIT_DELIM_CAPTURE); |
// the flat representation is now ready, we can create our tree |
$tree = $this->buildTree(); |
// if comments or processing options where escaped, we can |
// safely unescape them now |
if ($this->escaped) { |
$tree = $this->unescapeSpecials($tree); |
} |
return $tree; |
} |
private function escapeSpecials($html) { |
// here we escape comments |
$html = preg_replace_callback('#<\!--.+-->#sU', array($this, 'escapeSpecials_callback'), $html); |
// and processing options |
$html = preg_replace_callback('#<\?.+\?>#sU', array($this, 'escapeSpecials_callback'), $html); |
return $html; |
} |
private function escapeSpecials_callback($m) { |
$this->escaped = true; |
$text = $m[0]; |
$text = str_replace(array('<', '>'), array("\x01", "\x02"), $text); |
return $text; |
} |
private function unescapeSpecials($tree) { |
return is_array($tree) ? array_map(array($this, 'unescapeSpecials'), $tree) : str_replace(array("\x01", "\x02"), array('<', '>'), $tree); |
} |
private function buildTree() { |
$nodes = array(); |
$i = 0; |
$text = NULL; |
while (($value = array_shift($this->matches)) !== NULL) { |
switch ($i++ % 3) { |
case 0: |
// if the trimed value is not empty we preserve the value, |
// otherwise we discard it. |
if (trim($value)){ |
$nodes[] = $value; |
} |
break; |
case 1: |
$closing = ($value == '/'); |
break; |
case 2: |
if (substr($value, -1, 1) == '/') { |
// auto closing |
$nodes[] = $this->parseMarkup(substr($value, 0, -1)); |
} else if ($closing) { |
// closing markup |
$open = array_pop($this->opened); |
if ($value != $open) { |
$this->error($value, $open); |
} |
return $nodes; |
} else { |
// this is an open markup with possible children |
$node = $this->parseMarkup($value); |
// push the markup name into the opened markups |
$this->opened[] = $node['name']; |
// create the node and parse its children |
$node['children'] = $this->buildTree($this->matches); |
$nodes[] = $node; |
} |
break; |
} |
} |
return $nodes; |
} |
public function parseMarkup($markup) { |
// get markup's name |
preg_match('#^[^\s]+#', $markup, $matches); |
$name = $matches[0]; |
// get markup's arguments |
preg_match_all('#\s+([^=]+)\s*=\s*"([^"]+)"#', $markup, $matches, PREG_SET_ORDER); |
// transform the matches into a nice key/value array |
$args = array(); |
foreach ($matches as $m) { |
// we unescape the html entities of the argument's value |
$args[$m[1]] = html_entity_decode($m[2], ENT_QUOTES, $this->encoding); |
} |
return array('name' => $name, 'args' => $args); |
} |
public function error($markup, $expected) { |
$this->malformed = true; |
printf('unexpected closing markup "%s", should be "%s"', $markup, $expected); |
} |
} |
?> |
/trunk/jrest/lib/Writer.php |
---|
New file |
0,0 → 1,104 |
<?php |
/* |
* Module written/ported by Xavier Noguer <xnoguer@rezebra.com> |
* |
* PERL Spreadsheet::WriteExcel module. |
* |
* The author of the Spreadsheet::WriteExcel module is John McNamara |
* <jmcnamara@cpan.org> |
* |
* I _DO_ maintain this code, and John McNamara has nothing to do with the |
* porting of this code to PHP. Any questions directly related to this |
* class library should be directed to me. |
* |
* License Information: |
* |
* Spreadsheet_Excel_Writer: A library for generating Excel Spreadsheets |
* Copyright (c) 2002-2003 Xavier Noguer xnoguer@rezebra.com |
* |
* This library is free software; you can redistribute it and/or |
* modify it under the terms of the GNU Lesser General Public |
* License as published by the Free Software Foundation; either |
* version 2.1 of the License, or (at your option) any later version. |
* |
* This library is distributed in the hope that it will be useful, |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
* Lesser General Public License for more details. |
* |
* You should have received a copy of the GNU Lesser General Public |
* License along with this library; if not, write to the Free Software |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
*/ |
require_once 'PEAR.php'; |
require_once 'Spreadsheet/Excel/Writer/Workbook.php'; |
/** |
* Class for writing Excel Spreadsheets. This class should change COMPLETELY. |
* |
* @author Xavier Noguer <xnoguer@rezebra.com> |
* @category FileFormats |
* @package Spreadsheet_Excel_Writer |
*/ |
class Spreadsheet_Excel_Writer extends Spreadsheet_Excel_Writer_Workbook |
{ |
/** |
* The constructor. It just creates a Workbook |
* |
* @param string $filename The optional filename for the Workbook. |
* @return Spreadsheet_Excel_Writer_Workbook The Workbook created |
*/ |
function Spreadsheet_Excel_Writer($filename = '') |
{ |
$this->_filename = $filename; |
$this->Spreadsheet_Excel_Writer_Workbook($filename); |
} |
/** |
* Send HTTP headers for the Excel file. |
* |
* @param string $filename The filename to use for HTTP headers |
* @access public |
*/ |
function send($filename) |
{ |
header("Content-type: application/vnd.ms-excel"); |
header("Content-Disposition: attachment; filename=\"$filename\""); |
header("Expires: 0"); |
header("Cache-Control: must-revalidate, post-check=0,pre-check=0"); |
header("Pragma: public"); |
} |
/** |
* Utility function for writing formulas |
* Converts a cell's coordinates to the A1 format. |
* |
* @access public |
* @static |
* @param integer $row Row for the cell to convert (0-indexed). |
* @param integer $col Column for the cell to convert (0-indexed). |
* @return string The cell identifier in A1 format |
*/ |
function rowcolToCell($row, $col) |
{ |
if ($col > 255) { //maximum column value exceeded |
return new PEAR_Error("Maximum column value exceeded: $col"); |
} |
$int = (int)($col / 26); |
$frac = $col % 26; |
$chr1 = ''; |
if ($int > 0) { |
$chr1 = chr(ord('A') + $int - 1); |
} |
$chr2 = chr(ord('A') + $frac); |
$row++; |
return $chr1 . $chr2 . $row; |
} |
} |
?> |
/trunk/jrest/lib/DB/common.php |
---|
New file |
0,0 → 1,2040 |
<?php |
/* vim: set expandtab tabstop=4 shiftwidth=4 foldmethod=marker: */ |
// +----------------------------------------------------------------------+ |
// | PHP Version 4 | |
// +----------------------------------------------------------------------+ |
// | Copyright (c) 1997-2004 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: Stig Bakken <ssb@php.net> | |
// | Tomas V.V.Cox <cox@idecnet.com> | |
// | Maintainer: Daniel Convissor <danielc@php.net> | |
// +----------------------------------------------------------------------+ |
// |
// $Id$ |
require_once 'PEAR.php'; |
/** |
* DB_common is a base class for DB implementations, and must be |
* inherited by all such |
* |
* @package DB |
* @version $Id$ |
* @category Database |
* @author Stig Bakken <ssb@php.net> |
* @author Tomas V.V.Cox <cox@idecnet.com> |
*/ |
class DB_common extends PEAR |
{ |
// {{{ properties |
/** |
* assoc of capabilities for this DB implementation |
* $features['limit'] => 'emulate' => emulate with fetch row by number |
* 'alter' => alter the query |
* false => skip rows |
* @var array |
*/ |
var $features = array(); |
/** |
* assoc mapping native error codes to DB ones |
* @var array |
*/ |
var $errorcode_map = array(); |
/** |
* DB type (mysql, oci8, odbc etc.) |
* @var string |
*/ |
var $phptype; |
/** |
* @var string |
*/ |
var $prepare_tokens; |
/** |
* @var string |
*/ |
var $prepare_types; |
/** |
* @var string |
*/ |
var $prepared_queries; |
/** |
* @var integer |
*/ |
var $prepare_maxstmt = 0; |
/** |
* @var string |
*/ |
var $last_query = ''; |
/** |
* @var integer |
*/ |
var $fetchmode = DB_FETCHMODE_ORDERED; |
/** |
* @var string |
*/ |
var $fetchmode_object_class = 'stdClass'; |
/** |
* Run-time configuration options. |
* |
* The 'optimize' option has been deprecated. Use the 'portability' |
* option instead. |
* |
* @see DB_common::setOption() |
* @var array |
*/ |
var $options = array( |
'persistent' => false, |
'ssl' => false, |
'debug' => 0, |
'seqname_format' => '%s_seq', |
'autofree' => false, |
'portability' => DB_PORTABILITY_NONE, |
'optimize' => 'performance', // Deprecated. Use 'portability'. |
); |
/** |
* DB handle |
* @var resource |
*/ |
var $dbh; |
// }}} |
// {{{ toString() |
/** |
* String conversation |
* |
* @return string |
* @access private |
*/ |
function toString() |
{ |
$info = strtolower(get_class($this)); |
$info .= ': (phptype=' . $this->phptype . |
', dbsyntax=' . $this->dbsyntax . |
')'; |
if ($this->connection) { |
$info .= ' [connected]'; |
} |
return $info; |
} |
// }}} |
// {{{ constructor |
/** |
* Constructor |
*/ |
function DB_common() |
{ |
$this->PEAR('DB_Error'); |
} |
// }}} |
// {{{ quoteString() |
/** |
* DEPRECATED: Quotes a string so it can be safely used within string |
* delimiters in a query |
* |
* @return string quoted string |
* |
* @see DB_common::quoteSmart(), DB_common::escapeSimple() |
* @deprecated Deprecated in release 1.2 or lower |
* @internal |
*/ |
function quoteString($string) |
{ |
$string = $this->quote($string); |
if ($string{0} == "'") { |
return substr($string, 1, -1); |
} |
return $string; |
} |
// }}} |
// {{{ quote() |
/** |
* DEPRECATED: Quotes a string so it can be safely used in a query |
* |
* @param string $string the input string to quote |
* |
* @return string The NULL string or the string quotes |
* in magic_quote_sybase style |
* |
* @see DB_common::quoteSmart(), DB_common::escapeSimple() |
* @deprecated Deprecated in release 1.6.0 |
* @internal |
*/ |
function quote($string = null) |
{ |
return ($string === null) ? 'NULL' : "'".str_replace("'", "''", $string)."'"; |
} |
// }}} |
// {{{ quoteIdentifier() |
/** |
* Quote a string so it can be safely used as a table or column name |
* |
* Delimiting style depends on which database driver is being used. |
* |
* NOTE: just because you CAN use delimited identifiers doesn't mean |
* you SHOULD use them. In general, they end up causing way more |
* problems than they solve. |
* |
* Portability is broken by using the following characters inside |
* delimited identifiers: |
* + backtick (<kbd>`</kbd>) -- due to MySQL |
* + double quote (<kbd>"</kbd>) -- due to Oracle |
* + brackets (<kbd>[</kbd> or <kbd>]</kbd>) -- due to Access |
* |
* Delimited identifiers are known to generally work correctly under |
* the following drivers: |
* + mssql |
* + mysql |
* + mysqli |
* + oci8 |
* + odbc(access) |
* + odbc(db2) |
* + pgsql |
* + sqlite |
* + sybase |
* |
* InterBase doesn't seem to be able to use delimited identifiers |
* via PHP 4. They work fine under PHP 5. |
* |
* @param string $str identifier name to be quoted |
* |
* @return string quoted identifier string |
* |
* @since 1.6.0 |
* @access public |
*/ |
function quoteIdentifier($str) |
{ |
return '"' . str_replace('"', '""', $str) . '"'; |
} |
// }}} |
// {{{ quoteSmart() |
/** |
* Format input so it can be safely used in a query |
* |
* The output depends on the PHP data type of input and the database |
* type being used. |
* |
* @param mixed $in data to be quoted |
* |
* @return mixed the format of the results depends on the input's |
* PHP type: |
* |
* <ul> |
* <li> |
* <kbd>input</kbd> -> <samp>returns</samp> |
* </li> |
* <li> |
* <kbd>null</kbd> -> the string <samp>NULL</samp> |
* </li> |
* <li> |
* <kbd>integer</kbd> or <kbd>double</kbd> -> the unquoted number |
* </li> |
* <li> |
* &type.bool; -> output depends on the driver in use |
* Most drivers return integers: <samp>1</samp> if |
* <kbd>true</kbd> or <samp>0</samp> if |
* <kbd>false</kbd>. |
* Some return strings: <samp>TRUE</samp> if |
* <kbd>true</kbd> or <samp>FALSE</samp> if |
* <kbd>false</kbd>. |
* Finally one returns strings: <samp>T</samp> if |
* <kbd>true</kbd> or <samp>F</samp> if |
* <kbd>false</kbd>. Here is a list of each DBMS, |
* the values returned and the suggested column type: |
* <ul> |
* <li> |
* <kbd>dbase</kbd> -> <samp>T/F</samp> |
* (<kbd>Logical</kbd>) |
* </li> |
* <li> |
* <kbd>fbase</kbd> -> <samp>TRUE/FALSE</samp> |
* (<kbd>BOOLEAN</kbd>) |
* </li> |
* <li> |
* <kbd>ibase</kbd> -> <samp>1/0</samp> |
* (<kbd>SMALLINT</kbd>) [1] |
* </li> |
* <li> |
* <kbd>ifx</kbd> -> <samp>1/0</samp> |
* (<kbd>SMALLINT</kbd>) [1] |
* </li> |
* <li> |
* <kbd>msql</kbd> -> <samp>1/0</samp> |
* (<kbd>INTEGER</kbd>) |
* </li> |
* <li> |
* <kbd>mssql</kbd> -> <samp>1/0</samp> |
* (<kbd>BIT</kbd>) |
* </li> |
* <li> |
* <kbd>mysql</kbd> -> <samp>1/0</samp> |
* (<kbd>TINYINT(1)</kbd>) |
* </li> |
* <li> |
* <kbd>mysqli</kbd> -> <samp>1/0</samp> |
* (<kbd>TINYINT(1)</kbd>) |
* </li> |
* <li> |
* <kbd>oci8</kbd> -> <samp>1/0</samp> |
* (<kbd>NUMBER(1)</kbd>) |
* </li> |
* <li> |
* <kbd>odbc</kbd> -> <samp>1/0</samp> |
* (<kbd>SMALLINT</kbd>) [1] |
* </li> |
* <li> |
* <kbd>pgsql</kbd> -> <samp>TRUE/FALSE</samp> |
* (<kbd>BOOLEAN</kbd>) |
* </li> |
* <li> |
* <kbd>sqlite</kbd> -> <samp>1/0</samp> |
* (<kbd>INTEGER</kbd>) |
* </li> |
* <li> |
* <kbd>sybase</kbd> -> <samp>1/0</samp> |
* (<kbd>TINYINT(1)</kbd>) |
* </li> |
* </ul> |
* [1] Accommodate the lowest common denominator because not all |
* versions of have <kbd>BOOLEAN</kbd>. |
* </li> |
* <li> |
* other (including strings and numeric strings) -> |
* the data with single quotes escaped by preceeding |
* single quotes, backslashes are escaped by preceeding |
* backslashes, then the whole string is encapsulated |
* between single quotes |
* </li> |
* </ul> |
* |
* @since 1.6.0 |
* @see DB_common::escapeSimple() |
* @access public |
*/ |
function quoteSmart($in) |
{ |
if (is_int($in) || is_double($in)) { |
return $in; |
} elseif (is_bool($in)) { |
return $in ? 1 : 0; |
} elseif (is_null($in)) { |
return 'NULL'; |
} else { |
return "'" . $this->escapeSimple($in) . "'"; |
} |
} |
// }}} |
// {{{ escapeSimple() |
/** |
* Escape a string according to the current DBMS's standards |
* |
* In SQLite, this makes things safe for inserts/updates, but may |
* cause problems when performing text comparisons against columns |
* containing binary data. See the |
* {@link http://php.net/sqlite_escape_string PHP manual} for more info. |
* |
* @param string $str the string to be escaped |
* |
* @return string the escaped string |
* |
* @since 1.6.0 |
* @see DB_common::quoteSmart() |
* @access public |
*/ |
function escapeSimple($str) { |
return str_replace("'", "''", $str); |
} |
// }}} |
// {{{ provides() |
/** |
* Tell whether a DB implementation or its backend extension |
* supports a given feature |
* |
* @param array $feature name of the feature (see the DB class doc) |
* @return bool whether this DB implementation supports $feature |
* @access public |
*/ |
function provides($feature) |
{ |
return $this->features[$feature]; |
} |
// }}} |
// {{{ errorCode() |
/** |
* Map native error codes to DB's portable ones |
* |
* Requires that the DB implementation's constructor fills |
* in the <var>$errorcode_map</var> property. |
* |
* @param mixed $nativecode the native error code, as returned by the |
* backend database extension (string or integer) |
* |
* @return int a portable DB error code, or DB_ERROR if this DB |
* implementation has no mapping for the given error code. |
* |
* @access public |
*/ |
function errorCode($nativecode) |
{ |
if (isset($this->errorcode_map[$nativecode])) { |
return $this->errorcode_map[$nativecode]; |
} |
// Fall back to DB_ERROR if there was no mapping. |
return DB_ERROR; |
} |
// }}} |
// {{{ errorMessage() |
/** |
* Map a DB error code to a textual message. This is actually |
* just a wrapper for DB::errorMessage() |
* |
* @param integer $dbcode the DB error code |
* |
* @return string the corresponding error message, of false |
* if the error code was unknown |
* |
* @access public |
*/ |
function errorMessage($dbcode) |
{ |
return DB::errorMessage($this->errorcode_map[$dbcode]); |
} |
// }}} |
// {{{ raiseError() |
/** |
* Communicate an error and invoke error callbacks, etc |
* |
* Basically a wrapper for PEAR::raiseError without the message string. |
* |
* @param mixed integer error code, or a PEAR error object (all |
* other parameters are ignored if this parameter is |
* an object |
* |
* @param int error mode, see PEAR_Error docs |
* |
* @param mixed If error mode is PEAR_ERROR_TRIGGER, this is the |
* error level (E_USER_NOTICE etc). If error mode is |
* PEAR_ERROR_CALLBACK, this is the callback function, |
* either as a function name, or as an array of an |
* object and method name. For other error modes this |
* parameter is ignored. |
* |
* @param string Extra debug information. Defaults to the last |
* query and native error code. |
* |
* @param mixed Native error code, integer or string depending the |
* backend. |
* |
* @return object a PEAR error object |
* |
* @access public |
* @see PEAR_Error |
*/ |
function &raiseError($code = DB_ERROR, $mode = null, $options = null, |
$userinfo = null, $nativecode = null) |
{ |
// The error is yet a DB error object |
if (is_object($code)) { |
// because we the static PEAR::raiseError, our global |
// handler should be used if it is set |
if ($mode === null && !empty($this->_default_error_mode)) { |
$mode = $this->_default_error_mode; |
$options = $this->_default_error_options; |
} |
$tmp = PEAR::raiseError($code, null, $mode, $options, null, null, true); |
return $tmp; |
} |
if ($userinfo === null) { |
$userinfo = $this->last_query; |
} |
if ($nativecode) { |
$userinfo .= ' [nativecode=' . trim($nativecode) . ']'; |
} |
$tmp = PEAR::raiseError(null, $code, $mode, $options, $userinfo, |
'DB_Error', true); |
return $tmp; |
} |
// }}} |
// {{{ setFetchMode() |
/** |
* Sets which fetch mode should be used by default on queries |
* on this connection |
* |
* @param integer $fetchmode DB_FETCHMODE_ORDERED or |
* DB_FETCHMODE_ASSOC, possibly bit-wise OR'ed with |
* DB_FETCHMODE_FLIPPED. |
* |
* @param string $object_class The class of the object |
* to be returned by the fetch methods when |
* the DB_FETCHMODE_OBJECT mode is selected. |
* If no class is specified by default a cast |
* to object from the assoc array row will be done. |
* There is also the posibility to use and extend the |
* 'DB_row' class. |
* |
* @see DB_FETCHMODE_ORDERED |
* @see DB_FETCHMODE_ASSOC |
* @see DB_FETCHMODE_FLIPPED |
* @see DB_FETCHMODE_OBJECT |
* @see DB_row::DB_row() |
* @access public |
*/ |
function setFetchMode($fetchmode, $object_class = 'stdClass') |
{ |
switch ($fetchmode) { |
case DB_FETCHMODE_OBJECT: |
$this->fetchmode_object_class = $object_class; |
case DB_FETCHMODE_ORDERED: |
case DB_FETCHMODE_ASSOC: |
$this->fetchmode = $fetchmode; |
break; |
default: |
return $this->raiseError('invalid fetchmode mode'); |
} |
} |
// }}} |
// {{{ setOption() |
/** |
* Set run-time configuration options for PEAR DB |
* |
* Options, their data types, default values and description: |
* <ul> |
* <li> |
* <var>autofree</var> <kbd>boolean</kbd> = <samp>false</samp> |
* <br />should results be freed automatically when there are no |
* more rows? |
* </li><li> |
* <var>debug</var> <kbd>integer</kbd> = <samp>0</samp> |
* <br />debug level |
* </li><li> |
* <var>persistent</var> <kbd>boolean</kbd> = <samp>false</samp> |
* <br />should the connection be persistent? |
* </li><li> |
* <var>portability</var> <kbd>integer</kbd> = <samp>DB_PORTABILITY_NONE</samp> |
* <br />portability mode constant (see below) |
* </li><li> |
* <var>seqname_format</var> <kbd>string</kbd> = <samp>%s_seq</samp> |
* <br />the sprintf() format string used on sequence names. This |
* format is applied to sequence names passed to |
* createSequence(), nextID() and dropSequence(). |
* </li><li> |
* <var>ssl</var> <kbd>boolean</kbd> = <samp>false</samp> |
* <br />use ssl to connect? |
* </li> |
* </ul> |
* |
* ----------------------------------------- |
* |
* PORTABILITY MODES |
* |
* These modes are bitwised, so they can be combined using <kbd>|</kbd> |
* and removed using <kbd>^</kbd>. See the examples section below on how |
* to do this. |
* |
* <samp>DB_PORTABILITY_NONE</samp> |
* turn off all portability features |
* |
* This mode gets automatically turned on if the deprecated |
* <var>optimize</var> option gets set to <samp>performance</samp>. |
* |
* |
* <samp>DB_PORTABILITY_LOWERCASE</samp> |
* convert names of tables and fields to lower case when using |
* <kbd>get*()</kbd>, <kbd>fetch*()</kbd> and <kbd>tableInfo()</kbd> |
* |
* This mode gets automatically turned on in the following databases |
* if the deprecated option <var>optimize</var> gets set to |
* <samp>portability</samp>: |
* + oci8 |
* |
* |
* <samp>DB_PORTABILITY_RTRIM</samp> |
* right trim the data output by <kbd>get*()</kbd> <kbd>fetch*()</kbd> |
* |
* |
* <samp>DB_PORTABILITY_DELETE_COUNT</samp> |
* force reporting the number of rows deleted |
* |
* Some DBMS's don't count the number of rows deleted when performing |
* simple <kbd>DELETE FROM tablename</kbd> queries. This portability |
* mode tricks such DBMS's into telling the count by adding |
* <samp>WHERE 1=1</samp> to the end of <kbd>DELETE</kbd> queries. |
* |
* This mode gets automatically turned on in the following databases |
* if the deprecated option <var>optimize</var> gets set to |
* <samp>portability</samp>: |
* + fbsql |
* + mysql |
* + mysqli |
* + sqlite |
* |
* |
* <samp>DB_PORTABILITY_NUMROWS</samp> |
* enable hack that makes <kbd>numRows()</kbd> work in Oracle |
* |
* This mode gets automatically turned on in the following databases |
* if the deprecated option <var>optimize</var> gets set to |
* <samp>portability</samp>: |
* + oci8 |
* |
* |
* <samp>DB_PORTABILITY_ERRORS</samp> |
* makes certain error messages in certain drivers compatible |
* with those from other DBMS's |
* |
* + mysql, mysqli: change unique/primary key constraints |
* DB_ERROR_ALREADY_EXISTS -> DB_ERROR_CONSTRAINT |
* |
* + odbc(access): MS's ODBC driver reports 'no such field' as code |
* 07001, which means 'too few parameters.' When this option is on |
* that code gets mapped to DB_ERROR_NOSUCHFIELD. |
* DB_ERROR_MISMATCH -> DB_ERROR_NOSUCHFIELD |
* |
* |
* <samp>DB_PORTABILITY_NULL_TO_EMPTY</samp> |
* convert null values to empty strings in data output by get*() and |
* fetch*(). Needed because Oracle considers empty strings to be null, |
* while most other DBMS's know the difference between empty and null. |
* |
* |
* <samp>DB_PORTABILITY_ALL</samp> |
* turn on all portability features |
* |
* ----------------------------------------- |
* |
* Example 1. Simple setOption() example |
* <code> <?php |
* $dbh->setOption('autofree', true); |
* ?></code> |
* |
* Example 2. Portability for lowercasing and trimming |
* <code> <?php |
* $dbh->setOption('portability', |
* DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_RTRIM); |
* ?></code> |
* |
* Example 3. All portability options except trimming |
* <code> <?php |
* $dbh->setOption('portability', |
* DB_PORTABILITY_ALL ^ DB_PORTABILITY_RTRIM); |
* ?></code> |
* |
* @param string $option option name |
* @param mixed $value value for the option |
* |
* @return int DB_OK on success. DB_Error object on failure. |
* |
* @see DB_common::$options |
*/ |
function setOption($option, $value) |
{ |
if (isset($this->options[$option])) { |
$this->options[$option] = $value; |
/* |
* Backwards compatibility check for the deprecated 'optimize' |
* option. Done here in case settings change after connecting. |
*/ |
if ($option == 'optimize') { |
if ($value == 'portability') { |
switch ($this->phptype) { |
case 'oci8': |
$this->options['portability'] = |
DB_PORTABILITY_LOWERCASE | |
DB_PORTABILITY_NUMROWS; |
break; |
case 'fbsql': |
case 'mysql': |
case 'mysqli': |
case 'sqlite': |
$this->options['portability'] = |
DB_PORTABILITY_DELETE_COUNT; |
break; |
} |
} else { |
$this->options['portability'] = DB_PORTABILITY_NONE; |
} |
} |
return DB_OK; |
} |
return $this->raiseError("unknown option $option"); |
} |
// }}} |
// {{{ getOption() |
/** |
* Returns the value of an option |
* |
* @param string $option option name |
* |
* @return mixed the option value |
*/ |
function getOption($option) |
{ |
if (isset($this->options[$option])) { |
return $this->options[$option]; |
} |
return $this->raiseError("unknown option $option"); |
} |
// }}} |
// {{{ prepare() |
/** |
* Prepares a query for multiple execution with execute() |
* |
* Creates a query that can be run multiple times. Each time it is run, |
* the placeholders, if any, will be replaced by the contents of |
* execute()'s $data argument. |
* |
* Three types of placeholders can be used: |
* + <kbd>?</kbd> scalar value (i.e. strings, integers). The system |
* will automatically quote and escape the data. |
* + <kbd>!</kbd> value is inserted 'as is' |
* + <kbd>&</kbd> requires a file name. The file's contents get |
* inserted into the query (i.e. saving binary |
* data in a db) |
* |
* Example 1. |
* <code> <?php |
* $sth = $dbh->prepare('INSERT INTO tbl (a, b, c) VALUES (?, !, &)'); |
* $data = array( |
* "John's text", |
* "'it''s good'", |
* 'filename.txt' |
* ); |
* $res = $dbh->execute($sth, $data); |
* ?></code> |
* |
* Use backslashes to escape placeholder characters if you don't want |
* them to be interpreted as placeholders: |
* <pre> |
* "UPDATE foo SET col=? WHERE col='over \& under'" |
* </pre> |
* |
* With some database backends, this is emulated. |
* |
* {@internal ibase and oci8 have their own prepare() methods.}} |
* |
* @param string $query query to be prepared |
* |
* @return mixed DB statement resource on success. DB_Error on failure. |
* |
* @see DB_common::execute() |
* @access public |
*/ |
function prepare($query) |
{ |
$tokens = preg_split('/((?<!\\\)[&?!])/', $query, -1, |
PREG_SPLIT_DELIM_CAPTURE); |
$token = 0; |
$types = array(); |
$newtokens = array(); |
foreach ($tokens as $val) { |
switch ($val) { |
case '?': |
$types[$token++] = DB_PARAM_SCALAR; |
break; |
case '&': |
$types[$token++] = DB_PARAM_OPAQUE; |
break; |
case '!': |
$types[$token++] = DB_PARAM_MISC; |
break; |
default: |
$newtokens[] = preg_replace('/\\\([&?!])/', "\\1", $val); |
} |
} |
$this->prepare_tokens[] = &$newtokens; |
end($this->prepare_tokens); |
$k = key($this->prepare_tokens); |
$this->prepare_types[$k] = $types; |
$this->prepared_queries[$k] = implode(' ', $newtokens); |
return $k; |
} |
// }}} |
// {{{ autoPrepare() |
/** |
* Automaticaly generate an insert or update query and pass it to prepare() |
* |
* @param string $table name of the table |
* @param array $table_fields ordered array containing the fields names |
* @param int $mode type of query to make (DB_AUTOQUERY_INSERT or DB_AUTOQUERY_UPDATE) |
* @param string $where in case of update queries, this string will be put after the sql WHERE statement |
* @return resource handle for the query |
* @see DB_common::prepare(), DB_common::buildManipSQL() |
* @access public |
*/ |
function autoPrepare($table, $table_fields, $mode = DB_AUTOQUERY_INSERT, $where = false) |
{ |
$query = $this->buildManipSQL($table, $table_fields, $mode, $where); |
return $this->prepare($query); |
} |
// }}} |
// {{{ autoExecute() |
/** |
* Automaticaly generate an insert or update query and call prepare() |
* and execute() with it |
* |
* @param string $table name of the table |
* @param array $fields_values assoc ($key=>$value) where $key is a field name and $value its value |
* @param int $mode type of query to make (DB_AUTOQUERY_INSERT or DB_AUTOQUERY_UPDATE) |
* @param string $where in case of update queries, this string will be put after the sql WHERE statement |
* @return mixed a new DB_Result or a DB_Error when fail |
* @see DB_common::autoPrepare(), DB_common::buildManipSQL() |
* @access public |
*/ |
function autoExecute($table, $fields_values, $mode = DB_AUTOQUERY_INSERT, $where = false) |
{ |
$sth = $this->autoPrepare($table, array_keys($fields_values), $mode, $where); |
$ret =& $this->execute($sth, array_values($fields_values)); |
$this->freePrepared($sth); |
return $ret; |
} |
// }}} |
// {{{ buildManipSQL() |
/** |
* Make automaticaly an sql query for prepare() |
* |
* Example : buildManipSQL('table_sql', array('field1', 'field2', 'field3'), DB_AUTOQUERY_INSERT) |
* will return the string : INSERT INTO table_sql (field1,field2,field3) VALUES (?,?,?) |
* NB : - This belongs more to a SQL Builder class, but this is a simple facility |
* - Be carefull ! If you don't give a $where param with an UPDATE query, all |
* the records of the table will be updated ! |
* |
* @param string $table name of the table |
* @param array $table_fields ordered array containing the fields names |
* @param int $mode type of query to make (DB_AUTOQUERY_INSERT or DB_AUTOQUERY_UPDATE) |
* @param string $where in case of update queries, this string will be put after the sql WHERE statement |
* @return string sql query for prepare() |
* @access public |
*/ |
function buildManipSQL($table, $table_fields, $mode, $where = false) |
{ |
if (count($table_fields) == 0) { |
$this->raiseError(DB_ERROR_NEED_MORE_DATA); |
} |
$first = true; |
switch ($mode) { |
case DB_AUTOQUERY_INSERT: |
$values = ''; |
$names = ''; |
foreach ($table_fields as $value) { |
if ($first) { |
$first = false; |
} else { |
$names .= ','; |
$values .= ','; |
} |
$names .= $value; |
$values .= '?'; |
} |
return "INSERT INTO $table ($names) VALUES ($values)"; |
case DB_AUTOQUERY_UPDATE: |
$set = ''; |
foreach ($table_fields as $value) { |
if ($first) { |
$first = false; |
} else { |
$set .= ','; |
} |
$set .= "$value = ?"; |
} |
$sql = "UPDATE $table SET $set"; |
if ($where) { |
$sql .= " WHERE $where"; |
} |
return $sql; |
default: |
$this->raiseError(DB_ERROR_SYNTAX); |
} |
} |
// }}} |
// {{{ execute() |
/** |
* Executes a DB statement prepared with prepare() |
* |
* Example 1. |
* <code> <?php |
* $sth = $dbh->prepare('INSERT INTO tbl (a, b, c) VALUES (?, !, &)'); |
* $data = array( |
* "John's text", |
* "'it''s good'", |
* 'filename.txt' |
* ); |
* $res =& $dbh->execute($sth, $data); |
* ?></code> |
* |
* @param resource $stmt a DB statement resource returned from prepare() |
* @param mixed $data array, string or numeric data to be used in |
* execution of the statement. Quantity of items |
* passed must match quantity of placeholders in |
* query: meaning 1 placeholder for non-array |
* parameters or 1 placeholder per array element. |
* |
* @return object a new DB_Result or a DB_Error when fail |
* |
* {@internal ibase and oci8 have their own execute() methods.}} |
* |
* @see DB_common::prepare() |
* @access public |
*/ |
function &execute($stmt, $data = array()) |
{ |
$realquery = $this->executeEmulateQuery($stmt, $data); |
if (DB::isError($realquery)) { |
return $realquery; |
} |
$result = $this->simpleQuery($realquery); |
if (DB::isError($result) || $result === DB_OK) { |
return $result; |
} else { |
$tmp =& new DB_result($this, $result); |
return $tmp; |
} |
} |
// }}} |
// {{{ executeEmulateQuery() |
/** |
* Emulates the execute statement, when not supported |
* |
* @param resource $stmt a DB statement resource returned from execute() |
* @param mixed $data array, string or numeric data to be used in |
* execution of the statement. Quantity of items |
* passed must match quantity of placeholders in |
* query: meaning 1 placeholder for non-array |
* parameters or 1 placeholder per array element. |
* |
* @return mixed a string containing the real query run when emulating |
* prepare/execute. A DB error code is returned on failure. |
* |
* @see DB_common::execute() |
* @access private |
*/ |
function executeEmulateQuery($stmt, $data = array()) |
{ |
if (!is_array($data)) { |
$data = array($data); |
} |
if (count($this->prepare_types[$stmt]) != count($data)) { |
$this->last_query = $this->prepared_queries[$stmt]; |
return $this->raiseError(DB_ERROR_MISMATCH); |
} |
$realquery = $this->prepare_tokens[$stmt][0]; |
$i = 0; |
foreach ($data as $value) { |
if ($this->prepare_types[$stmt][$i] == DB_PARAM_SCALAR) { |
$realquery .= $this->quoteSmart($value); |
} elseif ($this->prepare_types[$stmt][$i] == DB_PARAM_OPAQUE) { |
$fp = @fopen($value, 'rb'); |
if (!$fp) { |
return $this->raiseError(DB_ERROR_ACCESS_VIOLATION); |
} |
$realquery .= $this->quoteSmart(fread($fp, filesize($value))); |
fclose($fp); |
} else { |
$realquery .= $value; |
} |
$realquery .= $this->prepare_tokens[$stmt][++$i]; |
} |
return $realquery; |
} |
// }}} |
// {{{ executeMultiple() |
/** |
* This function does several execute() calls on the same |
* statement handle |
* |
* $data must be an array indexed numerically |
* from 0, one execute call is done for every "row" in the array. |
* |
* If an error occurs during execute(), executeMultiple() does not |
* execute the unfinished rows, but rather returns that error. |
* |
* @param resource $stmt query handle from prepare() |
* @param array $data numeric array containing the |
* data to insert into the query |
* |
* @return mixed DB_OK or DB_Error |
* |
* @see DB_common::prepare(), DB_common::execute() |
* @access public |
*/ |
function executeMultiple($stmt, $data) |
{ |
foreach ($data as $value) { |
$res =& $this->execute($stmt, $value); |
if (DB::isError($res)) { |
return $res; |
} |
} |
return DB_OK; |
} |
// }}} |
// {{{ freePrepared() |
/** |
* Free the resource used in a prepared query |
* |
* @param $stmt The resurce returned by the prepare() function |
* @see DB_common::prepare() |
*/ |
function freePrepared($stmt) |
{ |
// Free the internal prepared vars |
if (isset($this->prepare_tokens[$stmt])) { |
unset($this->prepare_tokens[$stmt]); |
unset($this->prepare_types[$stmt]); |
unset($this->prepared_queries[$stmt]); |
return true; |
} |
return false; |
} |
// }}} |
// {{{ modifyQuery() |
/** |
* This method is used by backends to alter queries for various |
* reasons |
* |
* It is defined here to assure that all implementations |
* have this method defined. |
* |
* @param string $query query to modify |
* |
* @return the new (modified) query |
* |
* @access private |
*/ |
function modifyQuery($query) { |
return $query; |
} |
// }}} |
// {{{ modifyLimitQuery() |
/** |
* This method is used by backends to alter limited queries |
* |
* @param string $query query to modify |
* @param integer $from the row to start to fetching |
* @param integer $count the numbers of rows to fetch |
* |
* @return the new (modified) query |
* |
* @access private |
*/ |
function modifyLimitQuery($query, $from, $count, $params = array()) |
{ |
return $query; |
} |
// }}} |
// {{{ query() |
/** |
* Send a query to the database and return any results with a |
* DB_result object |
* |
* The query string can be either a normal statement to be sent directly |
* to the server OR if <var>$params</var> are passed the query can have |
* placeholders and it will be passed through prepare() and execute(). |
* |
* @param string $query the SQL query or the statement to prepare |
* @param mixed $params array, string or numeric data to be used in |
* execution of the statement. Quantity of items |
* passed must match quantity of placeholders in |
* query: meaning 1 placeholder for non-array |
* parameters or 1 placeholder per array element. |
* |
* @return mixed a DB_result object or DB_OK on success, a DB |
* error on failure |
* |
* @see DB_result, DB_common::prepare(), DB_common::execute() |
* @access public |
*/ |
function &query($query, $params = array()) |
{ |
if (sizeof($params) > 0) { |
$sth = $this->prepare($query); |
if (DB::isError($sth)) { |
return $sth; |
} |
$ret =& $this->execute($sth, $params); |
$this->freePrepared($sth); |
return $ret; |
} else { |
$result = $this->simpleQuery($query); |
if (DB::isError($result) || $result === DB_OK) { |
return $result; |
} else { |
$tmp =& new DB_result($this, $result); |
return $tmp; |
} |
} |
} |
// }}} |
// {{{ limitQuery() |
/** |
* Generates a limited query |
* |
* @param string $query query |
* @param integer $from the row to start to fetching |
* @param integer $count the numbers of rows to fetch |
* @param mixed $params array, string or numeric data to be used in |
* execution of the statement. Quantity of items |
* passed must match quantity of placeholders in |
* query: meaning 1 placeholder for non-array |
* parameters or 1 placeholder per array element. |
* |
* @return mixed a DB_Result object, DB_OK or a DB_Error |
* |
* @access public |
*/ |
function &limitQuery($query, $from, $count, $params = array()) |
{ |
$query = $this->modifyLimitQuery($query, $from, $count, $params); |
if (DB::isError($query)){ |
return $query; |
} |
$result =& $this->query($query, $params); |
if (is_a($result, 'DB_result')) { |
$result->setOption('limit_from', $from); |
$result->setOption('limit_count', $count); |
} |
return $result; |
} |
// }}} |
// {{{ getOne() |
/** |
* Fetch the first column of the first row of data returned from |
* a query |
* |
* Takes care of doing the query and freeing the results when finished. |
* |
* @param string $query the SQL query |
* @param mixed $params array, string or numeric data to be used in |
* execution of the statement. Quantity of items |
* passed must match quantity of placeholders in |
* query: meaning 1 placeholder for non-array |
* parameters or 1 placeholder per array element. |
* |
* @return mixed the returned value of the query. DB_Error on failure. |
* |
* @access public |
*/ |
function &getOne($query, $params = array()) |
{ |
settype($params, 'array'); |
if (sizeof($params) > 0) { |
$sth = $this->prepare($query); |
if (DB::isError($sth)) { |
return $sth; |
} |
$res =& $this->execute($sth, $params); |
$this->freePrepared($sth); |
} else { |
$res =& $this->query($query); |
} |
if (DB::isError($res)) { |
return $res; |
} |
$err = $res->fetchInto($row, DB_FETCHMODE_ORDERED); |
$res->free(); |
if ($err !== DB_OK) { |
return $err; |
} |
return $row[0]; |
} |
// }}} |
// {{{ getRow() |
/** |
* Fetch the first row of data returned from a query |
* |
* Takes care of doing the query and freeing the results when finished. |
* |
* @param string $query the SQL query |
* @param array $params array to be used in execution of the statement. |
* Quantity of array elements must match quantity |
* of placeholders in query. This function does |
* NOT support scalars. |
* @param int $fetchmode the fetch mode to use |
* |
* @return array the first row of results as an array indexed from |
* 0, or a DB error code. |
* |
* @access public |
*/ |
function &getRow($query, |
$params = array(), |
$fetchmode = DB_FETCHMODE_DEFAULT) |
{ |
// compat check, the params and fetchmode parameters used to |
// have the opposite order |
if (!is_array($params)) { |
if (is_array($fetchmode)) { |
if ($params === null) { |
$tmp = DB_FETCHMODE_DEFAULT; |
} else { |
$tmp = $params; |
} |
$params = $fetchmode; |
$fetchmode = $tmp; |
} elseif ($params !== null) { |
$fetchmode = $params; |
$params = array(); |
} |
} |
if (sizeof($params) > 0) { |
$sth = $this->prepare($query); |
if (DB::isError($sth)) { |
return $sth; |
} |
$res =& $this->execute($sth, $params); |
$this->freePrepared($sth); |
} else { |
$res =& $this->query($query); |
} |
if (DB::isError($res)) { |
return $res; |
} |
$err = $res->fetchInto($row, $fetchmode); |
$res->free(); |
if ($err !== DB_OK) { |
return $err; |
} |
return $row; |
} |
// }}} |
// {{{ getCol() |
/** |
* Fetch a single column from a result set and return it as an |
* indexed array |
* |
* @param string $query the SQL query |
* @param mixed $col which column to return (integer [column number, |
* starting at 0] or string [column name]) |
* @param mixed $params array, string or numeric data to be used in |
* execution of the statement. Quantity of items |
* passed must match quantity of placeholders in |
* query: meaning 1 placeholder for non-array |
* parameters or 1 placeholder per array element. |
* |
* @return array an indexed array with the data from the first |
* row at index 0, or a DB error code |
* |
* @see DB_common::query() |
* @access public |
*/ |
function &getCol($query, $col = 0, $params = array()) |
{ |
settype($params, 'array'); |
if (sizeof($params) > 0) { |
$sth = $this->prepare($query); |
if (DB::isError($sth)) { |
return $sth; |
} |
$res =& $this->execute($sth, $params); |
$this->freePrepared($sth); |
} else { |
$res =& $this->query($query); |
} |
if (DB::isError($res)) { |
return $res; |
} |
$fetchmode = is_int($col) ? DB_FETCHMODE_ORDERED : DB_FETCHMODE_ASSOC; |
if (!is_array($row = $res->fetchRow($fetchmode))) { |
$ret = array(); |
} else { |
if (!array_key_exists($col, $row)) { |
$ret =& $this->raiseError(DB_ERROR_NOSUCHFIELD); |
} else { |
$ret = array($row[$col]); |
while (is_array($row = $res->fetchRow($fetchmode))) { |
$ret[] = $row[$col]; |
} |
} |
} |
$res->free(); |
if (DB::isError($row)) { |
$ret = $row; |
} |
return $ret; |
} |
// }}} |
// {{{ getAssoc() |
/** |
* Fetch the entire result set of a query and return it as an |
* associative array using the first column as the key |
* |
* If the result set contains more than two columns, the value |
* will be an array of the values from column 2-n. If the result |
* set contains only two columns, the returned value will be a |
* scalar with the value of the second column (unless forced to an |
* array with the $force_array parameter). A DB error code is |
* returned on errors. If the result set contains fewer than two |
* columns, a DB_ERROR_TRUNCATED error is returned. |
* |
* For example, if the table "mytable" contains: |
* |
* <pre> |
* ID TEXT DATE |
* -------------------------------- |
* 1 'one' 944679408 |
* 2 'two' 944679408 |
* 3 'three' 944679408 |
* </pre> |
* |
* Then the call getAssoc('SELECT id,text FROM mytable') returns: |
* <pre> |
* array( |
* '1' => 'one', |
* '2' => 'two', |
* '3' => 'three', |
* ) |
* </pre> |
* |
* ...while the call getAssoc('SELECT id,text,date FROM mytable') returns: |
* <pre> |
* array( |
* '1' => array('one', '944679408'), |
* '2' => array('two', '944679408'), |
* '3' => array('three', '944679408') |
* ) |
* </pre> |
* |
* If the more than one row occurs with the same value in the |
* first column, the last row overwrites all previous ones by |
* default. Use the $group parameter if you don't want to |
* overwrite like this. Example: |
* |
* <pre> |
* getAssoc('SELECT category,id,name FROM mytable', false, null, |
* DB_FETCHMODE_ASSOC, true) returns: |
* |
* array( |
* '1' => array(array('id' => '4', 'name' => 'number four'), |
* array('id' => '6', 'name' => 'number six') |
* ), |
* '9' => array(array('id' => '4', 'name' => 'number four'), |
* array('id' => '6', 'name' => 'number six') |
* ) |
* ) |
* </pre> |
* |
* Keep in mind that database functions in PHP usually return string |
* values for results regardless of the database's internal type. |
* |
* @param string $query the SQL query |
* @param boolean $force_array used only when the query returns |
* exactly two columns. If true, the values |
* of the returned array will be one-element |
* arrays instead of scalars. |
* @param mixed $params array, string or numeric data to be used in |
* execution of the statement. Quantity of items |
* passed must match quantity of placeholders in |
* query: meaning 1 placeholder for non-array |
* parameters or 1 placeholder per array element. |
* @param int $fetchmode the fetch mode to use |
* @param boolean $group if true, the values of the returned array |
* is wrapped in another array. If the same |
* key value (in the first column) repeats |
* itself, the values will be appended to |
* this array instead of overwriting the |
* existing values. |
* |
* @return array associative array with results from the query. |
* DB Error on failure. |
* |
* @access public |
*/ |
function &getAssoc($query, $force_array = false, $params = array(), |
$fetchmode = DB_FETCHMODE_DEFAULT, $group = false) |
{ |
settype($params, 'array'); |
if (sizeof($params) > 0) { |
$sth = $this->prepare($query); |
if (DB::isError($sth)) { |
return $sth; |
} |
$res =& $this->execute($sth, $params); |
$this->freePrepared($sth); |
} else { |
$res =& $this->query($query); |
} |
if (DB::isError($res)) { |
return $res; |
} |
if ($fetchmode == DB_FETCHMODE_DEFAULT) { |
$fetchmode = $this->fetchmode; |
} |
$cols = $res->numCols(); |
if ($cols < 2) { |
$tmp =& $this->raiseError(DB_ERROR_TRUNCATED); |
return $tmp; |
} |
$results = array(); |
if ($cols > 2 || $force_array) { |
// return array values |
// XXX this part can be optimized |
if ($fetchmode == DB_FETCHMODE_ASSOC) { |
while (is_array($row = $res->fetchRow(DB_FETCHMODE_ASSOC))) { |
reset($row); |
$key = current($row); |
unset($row[key($row)]); |
if ($group) { |
$results[$key][] = $row; |
} else { |
$results[$key] = $row; |
} |
} |
} elseif ($fetchmode == DB_FETCHMODE_OBJECT) { |
while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT)) { |
$arr = get_object_vars($row); |
$key = current($arr); |
if ($group) { |
$results[$key][] = $row; |
} else { |
$results[$key] = $row; |
} |
} |
} else { |
while (is_array($row = $res->fetchRow(DB_FETCHMODE_ORDERED))) { |
// we shift away the first element to get |
// indices running from 0 again |
$key = array_shift($row); |
if ($group) { |
$results[$key][] = $row; |
} else { |
$results[$key] = $row; |
} |
} |
} |
if (DB::isError($row)) { |
$results = $row; |
} |
} else { |
// return scalar values |
while (is_array($row = $res->fetchRow(DB_FETCHMODE_ORDERED))) { |
if ($group) { |
$results[$row[0]][] = $row[1]; |
} else { |
$results[$row[0]] = $row[1]; |
} |
} |
if (DB::isError($row)) { |
$results = $row; |
} |
} |
$res->free(); |
return $results; |
} |
// }}} |
// {{{ getAll() |
/** |
* Fetch all the rows returned from a query |
* |
* @param string $query the SQL query |
* @param array $params array to be used in execution of the statement. |
* Quantity of array elements must match quantity |
* of placeholders in query. This function does |
* NOT support scalars. |
* @param int $fetchmode the fetch mode to use |
* |
* @return array an nested array. DB error on failure. |
* |
* @access public |
*/ |
function &getAll($query, |
$params = array(), |
$fetchmode = DB_FETCHMODE_DEFAULT) |
{ |
// compat check, the params and fetchmode parameters used to |
// have the opposite order |
if (!is_array($params)) { |
if (is_array($fetchmode)) { |
if ($params === null) { |
$tmp = DB_FETCHMODE_DEFAULT; |
} else { |
$tmp = $params; |
} |
$params = $fetchmode; |
$fetchmode = $tmp; |
} elseif ($params !== null) { |
$fetchmode = $params; |
$params = array(); |
} |
} |
if (sizeof($params) > 0) { |
$sth = $this->prepare($query); |
if (DB::isError($sth)) { |
return $sth; |
} |
$res =& $this->execute($sth, $params); |
$this->freePrepared($sth); |
} else { |
$res =& $this->query($query); |
} |
if (DB::isError($res) || $res === DB_OK) { |
return $res; |
} |
$results = array(); |
while (DB_OK === $res->fetchInto($row, $fetchmode)) { |
if ($fetchmode & DB_FETCHMODE_FLIPPED) { |
foreach ($row as $key => $val) { |
$results[$key][] = $val; |
} |
} else { |
$results[] = $row; |
} |
} |
$res->free(); |
if (DB::isError($row)) { |
$tmp =& $this->raiseError($row); |
return $tmp; |
} |
return $results; |
} |
// }}} |
// {{{ autoCommit() |
/** |
* enable automatic Commit |
* |
* @param boolean $onoff |
* @return mixed DB_Error |
* |
* @access public |
*/ |
function autoCommit($onoff=false) |
{ |
return $this->raiseError(DB_ERROR_NOT_CAPABLE); |
} |
// }}} |
// {{{ commit() |
/** |
* starts a Commit |
* |
* @return mixed DB_Error |
* |
* @access public |
*/ |
function commit() |
{ |
return $this->raiseError(DB_ERROR_NOT_CAPABLE); |
} |
// }}} |
// {{{ rollback() |
/** |
* starts a rollback |
* |
* @return mixed DB_Error |
* |
* @access public |
*/ |
function rollback() |
{ |
return $this->raiseError(DB_ERROR_NOT_CAPABLE); |
} |
// }}} |
// {{{ numRows() |
/** |
* Returns the number of rows in a result object |
* |
* @param object DB_Result the result object to check |
* |
* @return mixed DB_Error or the number of rows |
* |
* @access public |
*/ |
function numRows($result) |
{ |
return $this->raiseError(DB_ERROR_NOT_CAPABLE); |
} |
// }}} |
// {{{ affectedRows() |
/** |
* Returns the affected rows of a query |
* |
* @return mixed DB_Error or number of rows |
* |
* @access public |
*/ |
function affectedRows() |
{ |
return $this->raiseError(DB_ERROR_NOT_CAPABLE); |
} |
// }}} |
// {{{ errorNative() |
/** |
* Returns an errormessage, provides by the database |
* |
* @return mixed DB_Error or message |
* |
* @access public |
*/ |
function errorNative() |
{ |
return $this->raiseError(DB_ERROR_NOT_CAPABLE); |
} |
// }}} |
// {{{ getSequenceName() |
/** |
* Generate the name used inside the database for a sequence |
* |
* The createSequence() docblock contains notes about storing sequence |
* names. |
* |
* @param string $sqn the sequence's public name |
* |
* @return string the sequence's name in the backend |
* |
* @see DB_common::createSequence(), DB_common::dropSequence(), |
* DB_common::nextID(), DB_common::setOption() |
* @access private |
*/ |
function getSequenceName($sqn) |
{ |
return sprintf($this->getOption('seqname_format'), |
preg_replace('/[^a-z0-9_.]/i', '_', $sqn)); |
} |
// }}} |
// {{{ 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. DB_Error if problem. |
* |
* @see DB_common::createSequence(), DB_common::dropSequence(), |
* DB_common::getSequenceName() |
* @access public |
*/ |
function nextId($seq_name, $ondemand = true) |
{ |
return $this->raiseError(DB_ERROR_NOT_CAPABLE); |
} |
// }}} |
// {{{ createSequence() |
/** |
* Creates a new sequence |
* |
* The name of a given sequence is determined by passing the string |
* provided in the <var>$seq_name</var> argument through PHP's sprintf() |
* function using the value from the <var>seqname_format</var> option as |
* the sprintf()'s format argument. |
* |
* <var>seqname_format</var> is set via setOption(). |
* |
* @param string $seq_name name of the new sequence |
* |
* @return int DB_OK on success. A DB_Error object is returned if |
* problems arise. |
* |
* @see DB_common::dropSequence(), DB_common::getSequenceName(), |
* DB_common::nextID() |
* @access public |
*/ |
function createSequence($seq_name) |
{ |
return $this->raiseError(DB_ERROR_NOT_CAPABLE); |
} |
// }}} |
// {{{ dropSequence() |
/** |
* Deletes a sequence |
* |
* @param string $seq_name name of the sequence to be deleted |
* |
* @return int DB_OK on success. DB_Error if problems. |
* |
* @see DB_common::createSequence(), DB_common::getSequenceName(), |
* DB_common::nextID() |
* @access public |
*/ |
function dropSequence($seq_name) |
{ |
return $this->raiseError(DB_ERROR_NOT_CAPABLE); |
} |
// }}} |
// {{{ tableInfo() |
/** |
* Returns information about a table or a result set |
* |
* The format of the resulting array depends on which <var>$mode</var> |
* you select. The sample output below is based on this query: |
* <pre> |
* SELECT tblFoo.fldID, tblFoo.fldPhone, tblBar.fldId |
* FROM tblFoo |
* JOIN tblBar ON tblFoo.fldId = tblBar.fldId |
* </pre> |
* |
* <ul> |
* <li> |
* |
* <kbd>null</kbd> (default) |
* <pre> |
* [0] => Array ( |
* [table] => tblFoo |
* [name] => fldId |
* [type] => int |
* [len] => 11 |
* [flags] => primary_key not_null |
* ) |
* [1] => Array ( |
* [table] => tblFoo |
* [name] => fldPhone |
* [type] => string |
* [len] => 20 |
* [flags] => |
* ) |
* [2] => Array ( |
* [table] => tblBar |
* [name] => fldId |
* [type] => int |
* [len] => 11 |
* [flags] => primary_key not_null |
* ) |
* </pre> |
* |
* </li><li> |
* |
* <kbd>DB_TABLEINFO_ORDER</kbd> |
* |
* <p>In addition to the information found in the default output, |
* a notation of the number of columns is provided by the |
* <samp>num_fields</samp> element while the <samp>order</samp> |
* element provides an array with the column names as the keys and |
* their location index number (corresponding to the keys in the |
* the default output) as the values.</p> |
* |
* <p>If a result set has identical field names, the last one is |
* used.</p> |
* |
* <pre> |
* [num_fields] => 3 |
* [order] => Array ( |
* [fldId] => 2 |
* [fldTrans] => 1 |
* ) |
* </pre> |
* |
* </li><li> |
* |
* <kbd>DB_TABLEINFO_ORDERTABLE</kbd> |
* |
* <p>Similar to <kbd>DB_TABLEINFO_ORDER</kbd> but adds more |
* dimensions to the array in which the table names are keys and |
* the field names are sub-keys. This is helpful for queries that |
* join tables which have identical field names.</p> |
* |
* <pre> |
* [num_fields] => 3 |
* [ordertable] => Array ( |
* [tblFoo] => Array ( |
* [fldId] => 0 |
* [fldPhone] => 1 |
* ) |
* [tblBar] => Array ( |
* [fldId] => 2 |
* ) |
* ) |
* </pre> |
* |
* </li> |
* </ul> |
* |
* The <samp>flags</samp> element contains a space separated list |
* of extra information about the field. This data is inconsistent |
* between DBMS's due to the way each DBMS works. |
* + <samp>primary_key</samp> |
* + <samp>unique_key</samp> |
* + <samp>multiple_key</samp> |
* + <samp>not_null</samp> |
* |
* Most DBMS's only provide the <samp>table</samp> and <samp>flags</samp> |
* elements if <var>$result</var> is a table name. The following DBMS's |
* provide full information from queries: |
* + fbsql |
* + mysql |
* |
* If the 'portability' option has <samp>DB_PORTABILITY_LOWERCASE</samp> |
* turned on, the names of tables and fields will be lowercased. |
* |
* @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 either unused or one of the tableInfo modes: |
* <kbd>DB_TABLEINFO_ORDERTABLE</kbd>, |
* <kbd>DB_TABLEINFO_ORDER</kbd> or |
* <kbd>DB_TABLEINFO_FULL</kbd> (which does both). |
* These are bitwise, so the first two can be |
* combined using <kbd>|</kbd>. |
* @return array an associative array with the information requested. |
* If something goes wrong an error object is returned. |
* |
* @see DB_common::setOption() |
* @access public |
*/ |
function tableInfo($result, $mode = null) |
{ |
/* |
* If the DB_<driver> class has a tableInfo() method, that one |
* overrides this one. But, if the driver doesn't have one, |
* this method runs and tells users about that fact. |
*/ |
return $this->raiseError(DB_ERROR_NOT_CAPABLE); |
} |
// }}} |
// {{{ getTables() |
/** |
* @deprecated Deprecated in release 1.2 or lower |
*/ |
function getTables() |
{ |
return $this->getListOf('tables'); |
} |
// }}} |
// {{{ getListOf() |
/** |
* list internal DB info |
* valid values for $type are db dependent, |
* often: databases, users, view, functions |
* |
* @param string $type type of requested info |
* |
* @return mixed DB_Error or the requested data |
* |
* @access public |
*/ |
function getListOf($type) |
{ |
$sql = $this->getSpecialQuery($type); |
if ($sql === null) { // No support |
return $this->raiseError(DB_ERROR_UNSUPPORTED); |
} elseif (is_int($sql) || DB::isError($sql)) { // Previous error |
return $this->raiseError($sql); |
} elseif (is_array($sql)) { // Already the result |
return $sql; |
} |
return $this->getCol($sql); // Launch this query |
} |
// }}} |
// {{{ getSpecialQuery() |
/** |
* Returns the query needed to get some backend info |
* |
* @param string $type What kind of info you want to retrieve |
* |
* @return string The SQL query string |
* |
* @access public |
*/ |
function getSpecialQuery($type) |
{ |
return $this->raiseError(DB_ERROR_UNSUPPORTED); |
} |
// }}} |
// {{{ _rtrimArrayValues() |
/** |
* Right trim all strings in an array |
* |
* @param array $array the array to be trimmed (passed by reference) |
* @return void |
* @access private |
*/ |
function _rtrimArrayValues(&$array) |
{ |
foreach ($array as $key => $value) { |
if (is_string($value)) { |
$array[$key] = rtrim($value); |
} |
} |
} |
// }}} |
// {{{ _convertNullArrayValuesToEmpty() |
/** |
* Convert all null values in an array to empty strings |
* |
* @param array $array the array to be de-nullified (passed by reference) |
* @return void |
* @access private |
*/ |
function _convertNullArrayValuesToEmpty(&$array) |
{ |
foreach ($array as $key => $value) { |
if (is_null($value)) { |
$array[$key] = ''; |
} |
} |
} |
// }}} |
} |
/* |
* Local variables: |
* tab-width: 4 |
* c-basic-offset: 4 |
* End: |
*/ |
?> |
/trunk/jrest/lib/DB/.directory |
---|
New file |
0,0 → 1,5 |
[Dolphin] |
Timestamp=2010,6,10,16,42,30 |
[Settings] |
ShowDotFiles=true |
/trunk/jrest/lib/DB/mysql.php |
---|
New file |
0,0 → 1,916 |
<?php |
/* vim: set expandtab tabstop=4 shiftwidth=4 foldmethod=marker: */ |
// +----------------------------------------------------------------------+ |
// | PHP Version 4 | |
// +----------------------------------------------------------------------+ |
// | Copyright (c) 1997-2004 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: Stig Bakken <ssb@php.net> | |
// | Maintainer: Daniel Convissor <danielc@php.net> | |
// +----------------------------------------------------------------------+ |
// |
// $Id$ |
// XXX legend: |
// |
// XXX ERRORMSG: The error message from the mysql function should |
// be registered here. |
// |
// TODO/wishlist: |
// longReadlen |
// binmode |
require_once 'DB/common.php'; |
/** |
* Database independent query interface definition for PHP's MySQL |
* extension. |
* |
* This is for MySQL versions 4.0 and below. |
* |
* @package DB |
* @version $Id$ |
* @category Database |
* @author Stig Bakken <ssb@php.net> |
*/ |
class DB_mysql extends DB_common |
{ |
// {{{ properties |
var $connection; |
var $phptype, $dbsyntax; |
var $prepare_tokens = array(); |
var $prepare_types = array(); |
var $num_rows = array(); |
var $transaction_opcount = 0; |
var $autocommit = true; |
var $fetchmode = DB_FETCHMODE_ORDERED; /* Default fetch mode */ |
var $_db = false; |
// }}} |
// {{{ constructor |
/** |
* DB_mysql constructor. |
* |
* @access public |
*/ |
function DB_mysql() |
{ |
$this->DB_common(); |
$this->phptype = 'mysql'; |
$this->dbsyntax = 'mysql'; |
$this->features = array( |
'prepare' => false, |
'pconnect' => true, |
'transactions' => true, |
'limit' => 'alter' |
); |
$this->errorcode_map = array( |
1004 => DB_ERROR_CANNOT_CREATE, |
1005 => DB_ERROR_CANNOT_CREATE, |
1006 => DB_ERROR_CANNOT_CREATE, |
1007 => DB_ERROR_ALREADY_EXISTS, |
1008 => DB_ERROR_CANNOT_DROP, |
1022 => DB_ERROR_ALREADY_EXISTS, |
1046 => DB_ERROR_NODBSELECTED, |
1048 => DB_ERROR_CONSTRAINT, |
1050 => DB_ERROR_ALREADY_EXISTS, |
1051 => DB_ERROR_NOSUCHTABLE, |
1054 => DB_ERROR_NOSUCHFIELD, |
1062 => DB_ERROR_ALREADY_EXISTS, |
1064 => DB_ERROR_SYNTAX, |
1100 => DB_ERROR_NOT_LOCKED, |
1136 => DB_ERROR_VALUE_COUNT_ON_ROW, |
1146 => DB_ERROR_NOSUCHTABLE, |
1216 => DB_ERROR_CONSTRAINT, |
1217 => DB_ERROR_CONSTRAINT, |
); |
} |
// }}} |
// {{{ connect() |
/** |
* Connect to a database and log in as the specified user. |
* |
* @param $dsn the data source name (see DB::parseDSN for syntax) |
* @param $persistent (optional) whether the connection should |
* be persistent |
* @access public |
* @return int DB_OK on success, a DB error on failure |
*/ |
function connect($dsninfo, $persistent = false) |
{ |
if (!DB::assertExtension('mysql')) { |
return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND); |
} |
$this->dsn = $dsninfo; |
if ($dsninfo['protocol'] && $dsninfo['protocol'] == 'unix') { |
$dbhost = ':' . $dsninfo['socket']; |
} else { |
$dbhost = $dsninfo['hostspec'] ? $dsninfo['hostspec'] : 'localhost'; |
if ($dsninfo['port']) { |
$dbhost .= ':' . $dsninfo['port']; |
} |
} |
$connect_function = $persistent ? 'mysql_pconnect' : 'mysql_connect'; |
if ($dbhost && $dsninfo['username'] && isset($dsninfo['password'])) { |
$conn = @$connect_function($dbhost, $dsninfo['username'], |
$dsninfo['password']); |
} elseif ($dbhost && $dsninfo['username']) { |
$conn = @$connect_function($dbhost, $dsninfo['username']); |
} elseif ($dbhost) { |
$conn = @$connect_function($dbhost); |
} else { |
$conn = false; |
} |
if (!$conn) { |
if (($err = @mysql_error()) != '') { |
return $this->raiseError(DB_ERROR_CONNECT_FAILED, null, null, |
null, $err); |
} elseif (empty($php_errormsg)) { |
return $this->raiseError(DB_ERROR_CONNECT_FAILED); |
} else { |
return $this->raiseError(DB_ERROR_CONNECT_FAILED, null, null, |
null, $php_errormsg); |
} |
} |
if ($dsninfo['database']) { |
if (!@mysql_select_db($dsninfo['database'], $conn)) { |
switch(mysql_errno($conn)) { |
case 1049: |
return $this->raiseError(DB_ERROR_NOSUCHDB, null, null, |
null, @mysql_error($conn)); |
case 1044: |
return $this->raiseError(DB_ERROR_ACCESS_VIOLATION, null, null, |
null, @mysql_error($conn)); |
default: |
return $this->raiseError(DB_ERROR, null, null, |
null, @mysql_error($conn)); |
} |
} |
// fix to allow calls to different databases in the same script |
$this->_db = $dsninfo['database']; |
} |
$this->connection = $conn; |
return DB_OK; |
} |
// }}} |
// {{{ disconnect() |
/** |
* Log out and disconnect from the database. |
* |
* @access public |
* |
* @return bool true on success, false if not connected. |
*/ |
function disconnect() |
{ |
$ret = @mysql_close($this->connection); |
$this->connection = null; |
return $ret; |
} |
// }}} |
// {{{ simpleQuery() |
/** |
* Send a query to MySQL and return the results as a MySQL resource |
* identifier. |
* |
* @param the SQL query |
* |
* @access public |
* |
* @return mixed returns a valid MySQL result for successful SELECT |
* queries, DB_OK for other successful queries. A DB error is |
* returned on failure. |
*/ |
function simpleQuery($query) |
{ |
$ismanip = DB::isManip($query); |
$this->last_query = $query; |
$query = $this->modifyQuery($query); |
if ($this->_db) { |
if (!@mysql_select_db($this->_db, $this->connection)) { |
return $this->mysqlRaiseError(DB_ERROR_NODBSELECTED); |
} |
} |
if (!$this->autocommit && $ismanip) { |
if ($this->transaction_opcount == 0) { |
$result = @mysql_query('SET AUTOCOMMIT=0', $this->connection); |
$result = @mysql_query('BEGIN', $this->connection); |
if (!$result) { |
return $this->mysqlRaiseError(); |
} |
} |
$this->transaction_opcount++; |
} |
$result = @mysql_query($query, $this->connection); |
if (!$result) { |
return $this->mysqlRaiseError(); |
} |
if (is_resource($result)) { |
$numrows = $this->numrows($result); |
if (is_object($numrows)) { |
return $numrows; |
} |
$this->num_rows[(int)$result] = $numrows; |
return $result; |
} |
return DB_OK; |
} |
// }}} |
// {{{ nextResult() |
/** |
* Move the internal mysql result pointer to the next available result |
* |
* This method has not been implemented yet. |
* |
* @param a valid sql result resource |
* |
* @access public |
* |
* @return false |
*/ |
function nextResult($result) |
{ |
return false; |
} |
// }}} |
// {{{ fetchInto() |
/** |
* Fetch a row and insert the data into an existing array. |
* |
* Formating of the array and the data therein are configurable. |
* See DB_result::fetchInto() for more information. |
* |
* @param resource $result query result identifier |
* @param array $arr (reference) array where data from the row |
* should be placed |
* @param int $fetchmode how the resulting array should be indexed |
* @param int $rownum the row number to fetch |
* |
* @return mixed DB_OK on success, null when end of result set is |
* reached or on failure |
* |
* @see DB_result::fetchInto() |
* @access private |
*/ |
function fetchInto($result, &$arr, $fetchmode, $rownum=null) |
{ |
if ($rownum !== null) { |
if (!@mysql_data_seek($result, $rownum)) { |
return null; |
} |
} |
if ($fetchmode & DB_FETCHMODE_ASSOC) { |
$arr = @mysql_fetch_array($result, MYSQL_ASSOC); |
if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE && $arr) { |
$arr = array_change_key_case($arr, CASE_LOWER); |
} |
} else { |
$arr = @mysql_fetch_row($result); |
} |
if (!$arr) { |
// See: http://bugs.php.net/bug.php?id=22328 |
// for why we can't check errors on fetching |
return null; |
/* |
$errno = @mysql_errno($this->connection); |
if (!$errno) { |
return null; |
} |
return $this->mysqlRaiseError($errno); |
*/ |
} |
if ($this->options['portability'] & DB_PORTABILITY_RTRIM) { |
/* |
* Even though this DBMS already trims output, we do this because |
* a field might have intentional whitespace at the end that |
* gets removed by DB_PORTABILITY_RTRIM under another driver. |
*/ |
$this->_rtrimArrayValues($arr); |
} |
if ($this->options['portability'] & DB_PORTABILITY_NULL_TO_EMPTY) { |
$this->_convertNullArrayValuesToEmpty($arr); |
} |
return DB_OK; |
} |
// }}} |
// {{{ freeResult() |
/** |
* Free the internal resources associated with $result. |
* |
* @param $result MySQL result identifier |
* |
* @access public |
* |
* @return bool true on success, false if $result is invalid |
*/ |
function freeResult($result) |
{ |
unset($this->num_rows[(int)$result]); |
return @mysql_free_result($result); |
} |
// }}} |
// {{{ numCols() |
/** |
* Get the number of columns in a result set. |
* |
* @param $result MySQL result identifier |
* |
* @access public |
* |
* @return int the number of columns per row in $result |
*/ |
function numCols($result) |
{ |
$cols = @mysql_num_fields($result); |
if (!$cols) { |
return $this->mysqlRaiseError(); |
} |
return $cols; |
} |
// }}} |
// {{{ numRows() |
/** |
* Get the number of rows in a result set. |
* |
* @param $result MySQL result identifier |
* |
* @access public |
* |
* @return int the number of rows in $result |
*/ |
function numRows($result) |
{ |
$rows = @mysql_num_rows($result); |
if ($rows === null) { |
return $this->mysqlRaiseError(); |
} |
return $rows; |
} |
// }}} |
// {{{ autoCommit() |
/** |
* Enable/disable automatic commits |
*/ |
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() |
/** |
* Commit the current transaction. |
*/ |
function commit() |
{ |
if ($this->transaction_opcount > 0) { |
if ($this->_db) { |
if (!@mysql_select_db($this->_db, $this->connection)) { |
return $this->mysqlRaiseError(DB_ERROR_NODBSELECTED); |
} |
} |
$result = @mysql_query('COMMIT', $this->connection); |
$result = @mysql_query('SET AUTOCOMMIT=1', $this->connection); |
$this->transaction_opcount = 0; |
if (!$result) { |
return $this->mysqlRaiseError(); |
} |
} |
return DB_OK; |
} |
// }}} |
// {{{ rollback() |
/** |
* Roll back (undo) the current transaction. |
*/ |
function rollback() |
{ |
if ($this->transaction_opcount > 0) { |
if ($this->_db) { |
if (!@mysql_select_db($this->_db, $this->connection)) { |
return $this->mysqlRaiseError(DB_ERROR_NODBSELECTED); |
} |
} |
$result = @mysql_query('ROLLBACK', $this->connection); |
$result = @mysql_query('SET AUTOCOMMIT=1', $this->connection); |
$this->transaction_opcount = 0; |
if (!$result) { |
return $this->mysqlRaiseError(); |
} |
} |
return DB_OK; |
} |
// }}} |
// {{{ affectedRows() |
/** |
* Gets the number of rows affected by the data manipulation |
* query. For other queries, this function returns 0. |
* |
* @return number of rows affected by the last query |
*/ |
function affectedRows() |
{ |
if (DB::isManip($this->last_query)) { |
return @mysql_affected_rows($this->connection); |
} else { |
return 0; |
} |
} |
// }}} |
// {{{ errorNative() |
/** |
* Get the native error code of the last error (if any) that |
* occured on the current connection. |
* |
* @access public |
* |
* @return int native MySQL error code |
*/ |
function errorNative() |
{ |
return @mysql_errno($this->connection); |
} |
// }}} |
// {{{ 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. DB_Error if problem. |
* |
* @internal |
* @see DB_common::nextID() |
* @access public |
*/ |
function nextId($seq_name, $ondemand = true) |
{ |
$seqname = $this->getSequenceName($seq_name); |
do { |
$repeat = 0; |
$this->pushErrorHandling(PEAR_ERROR_RETURN); |
$result = $this->query("UPDATE ${seqname} ". |
'SET id=LAST_INSERT_ID(id+1)'); |
$this->popErrorHandling(); |
if ($result === DB_OK) { |
/** COMMON CASE **/ |
$id = @mysql_insert_id($this->connection); |
if ($id != 0) { |
return $id; |
} |
/** EMPTY SEQ TABLE **/ |
// Sequence table must be empty for some reason, so fill it and return 1 |
// Obtain a user-level lock |
$result = $this->getOne("SELECT GET_LOCK('${seqname}_lock',10)"); |
if (DB::isError($result)) { |
return $this->raiseError($result); |
} |
if ($result == 0) { |
// Failed to get the lock, bail with a DB_ERROR_NOT_LOCKED error |
return $this->mysqlRaiseError(DB_ERROR_NOT_LOCKED); |
} |
// add the default value |
$result = $this->query("REPLACE INTO ${seqname} (id) VALUES (0)"); |
if (DB::isError($result)) { |
return $this->raiseError($result); |
} |
// Release the lock |
$result = $this->getOne("SELECT RELEASE_LOCK('${seqname}_lock')"); |
if (DB::isError($result)) { |
return $this->raiseError($result); |
} |
// We know what the result will be, so no need to try again |
return 1; |
/** ONDEMAND TABLE CREATION **/ |
} elseif ($ondemand && DB::isError($result) && |
$result->getCode() == DB_ERROR_NOSUCHTABLE) |
{ |
$result = $this->createSequence($seq_name); |
if (DB::isError($result)) { |
return $this->raiseError($result); |
} else { |
$repeat = 1; |
} |
/** BACKWARDS COMPAT **/ |
} elseif (DB::isError($result) && |
$result->getCode() == DB_ERROR_ALREADY_EXISTS) |
{ |
// see _BCsequence() comment |
$result = $this->_BCsequence($seqname); |
if (DB::isError($result)) { |
return $this->raiseError($result); |
} |
$repeat = 1; |
} |
} while ($repeat); |
return $this->raiseError($result); |
} |
// }}} |
// {{{ createSequence() |
/** |
* Creates a new sequence |
* |
* @param string $seq_name name of the new sequence |
* |
* @return int DB_OK on success. A DB_Error object is returned if |
* problems arise. |
* |
* @internal |
* @see DB_common::createSequence() |
* @access public |
*/ |
function createSequence($seq_name) |
{ |
$seqname = $this->getSequenceName($seq_name); |
$res = $this->query("CREATE TABLE ${seqname} ". |
'(id INTEGER UNSIGNED AUTO_INCREMENT NOT NULL,'. |
' PRIMARY KEY(id))'); |
if (DB::isError($res)) { |
return $res; |
} |
// insert yields value 1, nextId call will generate ID 2 |
$res = $this->query("INSERT INTO ${seqname} (id) VALUES (0)"); |
if (DB::isError($res)) { |
return $res; |
} |
// so reset to zero |
return $this->query("UPDATE ${seqname} SET id = 0;"); |
} |
// }}} |
// {{{ dropSequence() |
/** |
* Deletes a sequence |
* |
* @param string $seq_name name of the sequence to be deleted |
* |
* @return int DB_OK on success. DB_Error if problems. |
* |
* @internal |
* @see DB_common::dropSequence() |
* @access public |
*/ |
function dropSequence($seq_name) |
{ |
return $this->query('DROP TABLE ' . $this->getSequenceName($seq_name)); |
} |
// }}} |
// {{{ _BCsequence() |
/** |
* Backwards compatibility with old sequence emulation implementation |
* (clean up the dupes) |
* |
* @param string $seqname The sequence name to clean up |
* @return mixed DB_Error or true |
*/ |
function _BCsequence($seqname) |
{ |
// Obtain a user-level lock... this will release any previous |
// application locks, but unlike LOCK TABLES, it does not abort |
// the current transaction and is much less frequently used. |
$result = $this->getOne("SELECT GET_LOCK('${seqname}_lock',10)"); |
if (DB::isError($result)) { |
return $result; |
} |
if ($result == 0) { |
// Failed to get the lock, can't do the conversion, bail |
// with a DB_ERROR_NOT_LOCKED error |
return $this->mysqlRaiseError(DB_ERROR_NOT_LOCKED); |
} |
$highest_id = $this->getOne("SELECT MAX(id) FROM ${seqname}"); |
if (DB::isError($highest_id)) { |
return $highest_id; |
} |
// This should kill all rows except the highest |
// We should probably do something if $highest_id isn't |
// numeric, but I'm at a loss as how to handle that... |
$result = $this->query("DELETE FROM ${seqname} WHERE id <> $highest_id"); |
if (DB::isError($result)) { |
return $result; |
} |
// If another thread has been waiting for this lock, |
// it will go thru the above procedure, but will have no |
// real effect |
$result = $this->getOne("SELECT RELEASE_LOCK('${seqname}_lock')"); |
if (DB::isError($result)) { |
return $result; |
} |
return true; |
} |
// }}} |
// {{{ quoteIdentifier() |
/** |
* Quote a string so it can be safely used as a table or column name |
* |
* Quoting style depends on which database driver is being used. |
* |
* MySQL can't handle the backtick character (<kbd>`</kbd>) in |
* table or column names. |
* |
* @param string $str identifier name to be quoted |
* |
* @return string quoted identifier string |
* |
* @since 1.6.0 |
* @access public |
* @internal |
*/ |
function quoteIdentifier($str) |
{ |
return '`' . $str . '`'; |
} |
// }}} |
// {{{ quote() |
/** |
* @deprecated Deprecated in release 1.6.0 |
* @internal |
*/ |
function quote($str) { |
return $this->quoteSmart($str); |
} |
// }}} |
// {{{ escapeSimple() |
/** |
* Escape a string according to the current DBMS's standards |
* |
* @param string $str the string to be escaped |
* |
* @return string the escaped string |
* |
* @internal |
*/ |
function escapeSimple($str) { |
if (function_exists('mysql_real_escape_string')) { |
return @mysql_real_escape_string($str, $this->connection); |
} else { |
return @mysql_escape_string($str); |
} |
} |
// }}} |
// {{{ modifyQuery() |
function modifyQuery($query) |
{ |
if ($this->options['portability'] & DB_PORTABILITY_DELETE_COUNT) { |
// "DELETE FROM table" gives 0 affected rows in MySQL. |
// This little hack lets you know how many rows were deleted. |
if (preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $query)) { |
$query = preg_replace('/^\s*DELETE\s+FROM\s+(\S+)\s*$/', |
'DELETE FROM \1 WHERE 1=1', $query); |
} |
} |
return $query; |
} |
// }}} |
// {{{ modifyLimitQuery() |
function modifyLimitQuery($query, $from, $count, $params = array()) |
{ |
if (DB::isManip($query)) { |
return $query . " LIMIT $count"; |
} else { |
return $query . " LIMIT $from, $count"; |
} |
} |
// }}} |
// {{{ mysqlRaiseError() |
/** |
* Gather information about an error, then use that info to create a |
* DB error object and finally return that object. |
* |
* @param integer $errno PEAR error number (usually a DB constant) if |
* manually raising an error |
* @return object DB error object |
* @see DB_common::errorCode() |
* @see DB_common::raiseError() |
*/ |
function mysqlRaiseError($errno = null) |
{ |
if ($errno === null) { |
if ($this->options['portability'] & DB_PORTABILITY_ERRORS) { |
$this->errorcode_map[1022] = DB_ERROR_CONSTRAINT; |
$this->errorcode_map[1048] = DB_ERROR_CONSTRAINT_NOT_NULL; |
$this->errorcode_map[1062] = DB_ERROR_CONSTRAINT; |
} else { |
// Doing this in case mode changes during runtime. |
$this->errorcode_map[1022] = DB_ERROR_ALREADY_EXISTS; |
$this->errorcode_map[1048] = DB_ERROR_CONSTRAINT; |
$this->errorcode_map[1062] = DB_ERROR_ALREADY_EXISTS; |
} |
$errno = $this->errorCode(mysql_errno($this->connection)); |
} |
return $this->raiseError($errno, null, null, null, |
@mysql_errno($this->connection) . ' ** ' . |
@mysql_error($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 |
* @param int $mode a valid tableInfo mode |
* @return array an associative array with the information requested |
* or an error object if something is wrong |
* @access public |
* @internal |
* @see DB_common::tableInfo() |
*/ |
function tableInfo($result, $mode = null) { |
if (isset($result->result)) { |
/* |
* Probably received a result object. |
* Extract the result resource identifier. |
*/ |
$id = $result->result; |
$got_string = false; |
} elseif (is_string($result)) { |
/* |
* Probably received a table name. |
* Create a result resource identifier. |
*/ |
$id = @mysql_list_fields($this->dsn['database'], |
$result, $this->connection); |
$got_string = true; |
} 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->mysqlRaiseError(DB_ERROR_NEED_MORE_DATA); |
} |
if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE) { |
$case_func = 'strtolower'; |
} else { |
$case_func = 'strval'; |
} |
$count = @mysql_num_fields($id); |
// made this IF due to performance (one if is faster than $count if's) |
if (!$mode) { |
for ($i=0; $i<$count; $i++) { |
$res[$i]['table'] = $case_func(@mysql_field_table($id, $i)); |
$res[$i]['name'] = $case_func(@mysql_field_name($id, $i)); |
$res[$i]['type'] = @mysql_field_type($id, $i); |
$res[$i]['len'] = @mysql_field_len($id, $i); |
$res[$i]['flags'] = @mysql_field_flags($id, $i); |
} |
} else { // full |
$res['num_fields']= $count; |
for ($i=0; $i<$count; $i++) { |
$res[$i]['table'] = $case_func(@mysql_field_table($id, $i)); |
$res[$i]['name'] = $case_func(@mysql_field_name($id, $i)); |
$res[$i]['type'] = @mysql_field_type($id, $i); |
$res[$i]['len'] = @mysql_field_len($id, $i); |
$res[$i]['flags'] = @mysql_field_flags($id, $i); |
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) { |
@mysql_free_result($id); |
} |
return $res; |
} |
// }}} |
// {{{ getSpecialQuery() |
/** |
* Returns the query needed to get some backend info |
* @param string $type What kind of info you want to retrieve |
* @return string The SQL query string |
*/ |
function getSpecialQuery($type) |
{ |
switch ($type) { |
case 'tables': |
return 'SHOW TABLES'; |
case 'views': |
return DB_ERROR_NOT_CAPABLE; |
case 'users': |
$sql = 'select distinct User from user'; |
if ($this->dsn['database'] != 'mysql') { |
$dsn = $this->dsn; |
$dsn['database'] = 'mysql'; |
if (DB::isError($db = DB::connect($dsn))) { |
return $db; |
} |
$sql = $db->getCol($sql); |
$db->disconnect(); |
// XXX Fixme the mysql driver should take care of this |
if (!@mysql_select_db($this->dsn['database'], $this->connection)) { |
return $this->mysqlRaiseError(DB_ERROR_NODBSELECTED); |
} |
} |
return $sql; |
case 'databases': |
return 'SHOW DATABASES'; |
default: |
return null; |
} |
} |
// }}} |
} |
/* |
* Local variables: |
* tab-width: 4 |
* c-basic-offset: 4 |
* End: |
*/ |
?> |
/trunk/jrest/lib/Log.php |
---|
New file |
0,0 → 1,195 |
<?php |
//declare(encoding='UTF-8'); |
/** |
* Classe permettant de logger des messages dans les fichier situés dans le dossier de log |
* |
* PHP Version 5 |
* |
* @category PHP |
* @package Framework |
* @author aurelien <aurelien@tela-botanica.org> |
* @copyright 2009 Tela-Botanica |
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL |
* @version SVN: <svn_id> |
* @link /doc/framework/ |
*/ |
class Log { |
/** |
* Tableau associatif stockant les descripteurs de fichiers |
*/ |
private static $fichiersLog = array(); |
/** |
* Chemin de base du dossier log de l'application |
*/ |
private static $cheminLogs = ''; |
/** |
* Booleen indiquant si l'on peut correctement écrire dans les fichiers de logs |
*/ |
private static $droitLogger = true; |
/** |
* Zone horaire (pour éviter des avertissements dans les dates) |
*/ |
private static $timeZone = ''; |
/** |
* Taille maximum d'un fichier de log avant que celui ne soit archivé (en octets) |
*/ |
private static $tailleMax = 10000; |
/** |
* séparateur de chemin |
*/ |
private static $sd = DIRECTORY_SEPARATOR; |
/** |
* Extension des fichiers de log |
*/ |
private static $ext = '.log'; |
/** |
* La classe registre se contient elle-même, (pour le pattern singleton) |
*/ |
private static $log; |
/** |
* Constructeur par défaut, privé, car on accède à la classe par le getInstance |
*/ |
private function __construct() { |
self::$sd = $sd; |
// gestion de la timezone pour éviter des erreurs |
if(function_exists("date_default_timezone_set") and function_exists("date_default_timezone_get")) { |
date_default_timezone_set(self::$timeZone); |
} |
if(!is_dir(self::$cheminLogs) || !is_writable(self::$cheminLogs)) { |
self::desactiverEcriture(); |
} |
} |
public static function setCheminLog($nouveauCheminLogs) { |
self::$cheminLogs = $nouveauCheminLogs; |
} |
public static function getCheminLog() { |
return self::$cheminLogs; |
} |
public static function setTimeZone($NouvelleTimeZone) { |
self::$timeZone = $NouvelleTimeZone; |
} |
public static function setTailleMax($nouvelleTailleMax) { |
self::$tailleMax = $nouvelleTailleMax; |
} |
/** |
* Fonction qui renvoie l'instance de classe en assurant son unicité, c'est l'unique méthode qui doit être |
* utilisée pour récupérer l'objet Registre |
* @return Log le gestionnaire de log en cours |
*/ |
public static function getInstance() { |
if (self::$log instanceof Log) { |
return self::$log; |
} |
self::$log = new Log(); |
return self::$log; |
} |
/** |
* Ajoute une entrée au log spécifié par le paramètre $nomFichier |
* @param string $nomFichier le nom du fichier dans lequel écrire |
*/ |
public static function ajouterEntree($nomFichier,$entree,$mode='a+') { |
if(self::$droitLogger) { |
$date = "\n"."\n".date('d m Y H:i')."\n" ; |
// si le fichier est déjà dans le tableau et qu'on peut y écrire |
if(self::verifierOuvrirFichier($nomFichier,$mode)) { |
// on y écrit le message de log |
fwrite(self::$fichiersLog[$nomFichier],$date.$entree); |
// on vérifie si le fichier ne dépasse pas la taille maximale |
self::verifierTailleFichierOuArchiver($nomFichier); |
} else { |
// sinon on interdit l'écriture |
self::desactiverEcriture($nomFichier); |
} |
} |
} |
/** |
* Vide un fichier log indiqué |
* @param string $nomFichier le nom du fichier à vider |
*/ |
public static function viderLog($nomFichier) { |
ajouterEntree($nomFichier,'','w'); |
} |
/** |
* Vérifie la présence d'un fichier dans le tableau, ses droits d'écriture, |
* l'ouvre si nécessaire |
* @param string $nomFichier le nom du fichier dont on doit vérifier la présence |
* @return boolean true si le fichier est ouvert ou maintenant accessible, false sinon |
*/ |
public static function verifierOuvrirFichier($nomFichier,$mode) { |
// le fichier est il déjà ouvert ? |
if(in_array($nomFichier,self::$fichiersLog)) { |
// si oui peut on y écrire ? |
if(is_writable(self::$cheminLogs.$nomFichier.self::$ext)) { |
// si oui on renvoie le descripteur |
return true; |
} |
return false; |
} else { |
// sinon on l'ouvre |
$fp = @fopen(self::$cheminLogs.$nomFichier.self::$ext,$mode); |
// si l'ouverture a réussi et si le fichier a les droits d'écriture |
if($fp && is_writable(self::$cheminLogs.$nomFichier.self::$ext)) { |
// si oui on renvoie le descripteur qu'on ajoute au tableau |
self::$fichiersLog[$nomFichier] = $fp; |
return true; |
} |
return false; |
} |
} |
/** |
* Vérifie la taille d'un fichier donné et si celle ci est trop importante |
* archive le fichier de log |
* @param string $nomFichier nom du fichier à vérifier |
*/ |
private static function verifierTailleFichierOuArchiver($nomFichier) { |
if(filesize(self::$cheminLogs.$nomFichier.self::$ext) > self::$tailleMax) { |
rename(self::$cheminLogs.$nomFichier.self::$ext,self::$cheminLogs.$nomFichier.date('d_m_Y_H:i').self::$ext); |
self::ajouterEntree($nomFichier,''); |
} |
} |
/** |
* Désactive l'écriture du log et envoie un message au gestionnaire d'erreurs |
* @param string $nomFichier le nom du fichier qui a causé l'erreur |
*/ |
private static function desactiverEcriture($nomFichier = '') { |
self::$droitLogger = false; |
if($nomFichier != '') { |
$fichierDossier = 'fichier '.$nomFichier ; |
} else { |
$fichierDossier = 'dossier des logs'; |
} |
} |
/** |
* destructeur de classe, ferme les descripteurs ouverts |
*/ |
public function __destruct() { |
foreach(self::$fichiersLog as $nomFichier => $fp) { |
fclose($fp); |
} |
} |
} |
?> |
/trunk/jrest/lib/zip.php |
---|
New file |
0,0 → 1,190 |
<?php |
/* vim: set expandtab sw=4 ts=4 sts=4: */ |
/** |
* |
* @version $Id: zip.lib.php 10240 2007-04-01 11:02:46Z cybot_tm $ |
*/ |
/** |
* Zip file creation class. |
* Makes zip files. |
* |
* Based on : |
* |
* http://www.zend.com/codex.php?id=535&single=1 |
* By Eric Mueller <eric@themepark.com> |
* |
* http://www.zend.com/codex.php?id=470&single=1 |
* by Denis125 <webmaster@atlant.ru> |
* |
* a patch from Peter Listiak <mlady@users.sourceforge.net> for last modified |
* date and time of the compressed file |
* |
* Official ZIP file format: http://www.pkware.com/appnote.txt |
* |
* @access public |
*/ |
class zipfile |
{ |
/** |
* Array to store compressed data |
* |
* @var array $datasec |
*/ |
var $datasec = array(); |
/** |
* Central directory |
* |
* @var array $ctrl_dir |
*/ |
var $ctrl_dir = array(); |
/** |
* End of central directory record |
* |
* @var string $eof_ctrl_dir |
*/ |
var $eof_ctrl_dir = "\x50\x4b\x05\x06\x00\x00\x00\x00"; |
/** |
* Last offset position |
* |
* @var integer $old_offset |
*/ |
var $old_offset = 0; |
/** |
* Converts an Unix timestamp to a four byte DOS date and time format (date |
* in high two bytes, time in low two bytes allowing magnitude comparison). |
* |
* @param integer the current Unix timestamp |
* |
* @return integer the current date in a four byte DOS format |
* |
* @access private |
*/ |
function unix2DosTime($unixtime = 0) { |
$timearray = ($unixtime == 0) ? getdate() : getdate($unixtime); |
if ($timearray['year'] < 1980) { |
$timearray['year'] = 1980; |
$timearray['mon'] = 1; |
$timearray['mday'] = 1; |
$timearray['hours'] = 0; |
$timearray['minutes'] = 0; |
$timearray['seconds'] = 0; |
} // end if |
return (($timearray['year'] - 1980) << 25) | ($timearray['mon'] << 21) | ($timearray['mday'] << 16) | |
($timearray['hours'] << 11) | ($timearray['minutes'] << 5) | ($timearray['seconds'] >> 1); |
} // end of the 'unix2DosTime()' method |
/** |
* Adds "file" to archive |
* |
* @param string file contents |
* @param string name of the file in the archive (may contains the path) |
* @param integer the current timestamp |
* |
* @access public |
*/ |
function addFile($data, $name, $time = 0) |
{ |
$name = str_replace('\\', '/', $name); |
$dtime = dechex($this->unix2DosTime($time)); |
$hexdtime = '\x' . $dtime[6] . $dtime[7] |
. '\x' . $dtime[4] . $dtime[5] |
. '\x' . $dtime[2] . $dtime[3] |
. '\x' . $dtime[0] . $dtime[1]; |
eval('$hexdtime = "' . $hexdtime . '";'); |
$fr = "\x50\x4b\x03\x04"; |
$fr .= "\x14\x00"; // ver needed to extract |
$fr .= "\x00\x00"; // gen purpose bit flag |
$fr .= "\x08\x00"; // compression method |
$fr .= $hexdtime; // last mod time and date |
// "local file header" segment |
$unc_len = strlen($data); |
$crc = crc32($data); |
$zdata = gzcompress($data); |
$zdata = substr(substr($zdata, 0, strlen($zdata) - 4), 2); // fix crc bug |
$c_len = strlen($zdata); |
$fr .= pack('V', $crc); // crc32 |
$fr .= pack('V', $c_len); // compressed filesize |
$fr .= pack('V', $unc_len); // uncompressed filesize |
$fr .= pack('v', strlen($name)); // length of filename |
$fr .= pack('v', 0); // extra field length |
$fr .= $name; |
// "file data" segment |
$fr .= $zdata; |
// "data descriptor" segment (optional but necessary if archive is not |
// served as file) |
// nijel(2004-10-19): this seems not to be needed at all and causes |
// problems in some cases (bug #1037737) |
//$fr .= pack('V', $crc); // crc32 |
//$fr .= pack('V', $c_len); // compressed filesize |
//$fr .= pack('V', $unc_len); // uncompressed filesize |
// add this entry to array |
$this -> datasec[] = $fr; |
// now add to central directory record |
$cdrec = "\x50\x4b\x01\x02"; |
$cdrec .= "\x00\x00"; // version made by |
$cdrec .= "\x14\x00"; // version needed to extract |
$cdrec .= "\x00\x00"; // gen purpose bit flag |
$cdrec .= "\x08\x00"; // compression method |
$cdrec .= $hexdtime; // last mod time & date |
$cdrec .= pack('V', $crc); // crc32 |
$cdrec .= pack('V', $c_len); // compressed filesize |
$cdrec .= pack('V', $unc_len); // uncompressed filesize |
$cdrec .= pack('v', strlen($name)); // length of filename |
$cdrec .= pack('v', 0); // extra field length |
$cdrec .= pack('v', 0); // file comment length |
$cdrec .= pack('v', 0); // disk number start |
$cdrec .= pack('v', 0); // internal file attributes |
$cdrec .= pack('V', 32); // external file attributes - 'archive' bit set |
$cdrec .= pack('V', $this -> old_offset); // relative offset of local header |
$this -> old_offset += strlen($fr); |
$cdrec .= $name; |
// optional extra field, file comment goes here |
// save to central directory |
$this -> ctrl_dir[] = $cdrec; |
} // end of the 'addFile()' method |
/** |
* Dumps out file |
* |
* @return string the zipped file |
* |
* @access public |
*/ |
function file() |
{ |
$data = implode('', $this -> datasec); |
$ctrldir = implode('', $this -> ctrl_dir); |
return |
$data . |
$ctrldir . |
$this -> eof_ctrl_dir . |
pack('v', sizeof($this -> ctrl_dir)) . // total # of entries "on this disk" |
pack('v', sizeof($this -> ctrl_dir)) . // total # of entries overall |
pack('V', strlen($ctrldir)) . // size of central dir |
pack('V', strlen($data)) . // offset to start of central dir |
"\x00\x00"; // .zip file comment length |
} // end of the 'file()' method |
} // end of the 'zipfile' class |
?> |
/trunk/jrest/lib/DB.php |
---|
New file |
0,0 → 1,1114 |
<?php |
/* vim: set expandtab tabstop=4 shiftwidth=4 foldmethod=marker: */ |
// +----------------------------------------------------------------------+ |
// | PHP Version 4 | |
// +----------------------------------------------------------------------+ |
// | Copyright (c) 1997-2004 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. | |
// +----------------------------------------------------------------------+ |
// | Authors: Stig Bakken <ssb@php.net> | |
// | Tomas V.V.Cox <cox@idecnet.com> | |
// | Maintainer: Daniel Convissor <danielc@php.net> | |
// +----------------------------------------------------------------------+ |
// |
// $Id$ |
// |
// Database independent query interface. |
require_once 'PEAR.php'; |
// {{{ constants |
// {{{ error codes |
/* |
* The method mapErrorCode in each DB_dbtype implementation maps |
* native error codes to one of these. |
* |
* If you add an error code here, make sure you also add a textual |
* version of it in DB::errorMessage(). |
*/ |
define('DB_OK', 1); |
define('DB_ERROR', -1); |
define('DB_ERROR_SYNTAX', -2); |
define('DB_ERROR_CONSTRAINT', -3); |
define('DB_ERROR_NOT_FOUND', -4); |
define('DB_ERROR_ALREADY_EXISTS', -5); |
define('DB_ERROR_UNSUPPORTED', -6); |
define('DB_ERROR_MISMATCH', -7); |
define('DB_ERROR_INVALID', -8); |
define('DB_ERROR_NOT_CAPABLE', -9); |
define('DB_ERROR_TRUNCATED', -10); |
define('DB_ERROR_INVALID_NUMBER', -11); |
define('DB_ERROR_INVALID_DATE', -12); |
define('DB_ERROR_DIVZERO', -13); |
define('DB_ERROR_NODBSELECTED', -14); |
define('DB_ERROR_CANNOT_CREATE', -15); |
define('DB_ERROR_CANNOT_DELETE', -16); |
define('DB_ERROR_CANNOT_DROP', -17); |
define('DB_ERROR_NOSUCHTABLE', -18); |
define('DB_ERROR_NOSUCHFIELD', -19); |
define('DB_ERROR_NEED_MORE_DATA', -20); |
define('DB_ERROR_NOT_LOCKED', -21); |
define('DB_ERROR_VALUE_COUNT_ON_ROW', -22); |
define('DB_ERROR_INVALID_DSN', -23); |
define('DB_ERROR_CONNECT_FAILED', -24); |
define('DB_ERROR_EXTENSION_NOT_FOUND',-25); |
define('DB_ERROR_ACCESS_VIOLATION', -26); |
define('DB_ERROR_NOSUCHDB', -27); |
define('DB_ERROR_CONSTRAINT_NOT_NULL',-29); |
// }}} |
// {{{ prepared statement-related |
/* |
* These constants are used when storing information about prepared |
* statements (using the "prepare" method in DB_dbtype). |
* |
* The prepare/execute model in DB is mostly borrowed from the ODBC |
* extension, in a query the "?" character means a scalar parameter. |
* There are two extensions though, a "&" character means an opaque |
* parameter. An opaque parameter is simply a file name, the real |
* data are in that file (useful for putting uploaded files into your |
* database and such). The "!" char means a parameter that must be |
* left as it is. |
* They modify the quote behavoir: |
* DB_PARAM_SCALAR (?) => 'original string quoted' |
* DB_PARAM_OPAQUE (&) => 'string from file quoted' |
* DB_PARAM_MISC (!) => original string |
*/ |
define('DB_PARAM_SCALAR', 1); |
define('DB_PARAM_OPAQUE', 2); |
define('DB_PARAM_MISC', 3); |
// }}} |
// {{{ binary data-related |
/* |
* These constants define different ways of returning binary data |
* from queries. Again, this model has been borrowed from the ODBC |
* extension. |
* |
* DB_BINMODE_PASSTHRU sends the data directly through to the browser |
* when data is fetched from the database. |
* DB_BINMODE_RETURN lets you return data as usual. |
* DB_BINMODE_CONVERT returns data as well, only it is converted to |
* hex format, for example the string "123" would become "313233". |
*/ |
define('DB_BINMODE_PASSTHRU', 1); |
define('DB_BINMODE_RETURN', 2); |
define('DB_BINMODE_CONVERT', 3); |
// }}} |
// {{{ fetch modes |
/** |
* This is a special constant that tells DB the user hasn't specified |
* any particular get mode, so the default should be used. |
*/ |
define('DB_FETCHMODE_DEFAULT', 0); |
/** |
* Column data indexed by numbers, ordered from 0 and up |
*/ |
define('DB_FETCHMODE_ORDERED', 1); |
/** |
* Column data indexed by column names |
*/ |
define('DB_FETCHMODE_ASSOC', 2); |
/** |
* Column data as object properties |
*/ |
define('DB_FETCHMODE_OBJECT', 3); |
/** |
* For multi-dimensional results: normally the first level of arrays |
* is the row number, and the second level indexed by column number or name. |
* DB_FETCHMODE_FLIPPED switches this order, so the first level of arrays |
* is the column name, and the second level the row number. |
*/ |
define('DB_FETCHMODE_FLIPPED', 4); |
/* for compatibility */ |
define('DB_GETMODE_ORDERED', DB_FETCHMODE_ORDERED); |
define('DB_GETMODE_ASSOC', DB_FETCHMODE_ASSOC); |
define('DB_GETMODE_FLIPPED', DB_FETCHMODE_FLIPPED); |
// }}} |
// {{{ tableInfo() && autoPrepare()-related |
/** |
* these are constants for the tableInfo-function |
* they are bitwised or'ed. so if there are more constants to be defined |
* in the future, adjust DB_TABLEINFO_FULL accordingly |
*/ |
define('DB_TABLEINFO_ORDER', 1); |
define('DB_TABLEINFO_ORDERTABLE', 2); |
define('DB_TABLEINFO_FULL', 3); |
/* |
* Used by autoPrepare() |
*/ |
define('DB_AUTOQUERY_INSERT', 1); |
define('DB_AUTOQUERY_UPDATE', 2); |
// }}} |
// {{{ portability modes |
/** |
* Portability: turn off all portability features. |
* @see DB_common::setOption() |
*/ |
define('DB_PORTABILITY_NONE', 0); |
/** |
* Portability: convert names of tables and fields to lower case |
* when using the get*(), fetch*() and tableInfo() methods. |
* @see DB_common::setOption() |
*/ |
define('DB_PORTABILITY_LOWERCASE', 1); |
/** |
* Portability: right trim the data output by get*() and fetch*(). |
* @see DB_common::setOption() |
*/ |
define('DB_PORTABILITY_RTRIM', 2); |
/** |
* Portability: force reporting the number of rows deleted. |
* @see DB_common::setOption() |
*/ |
define('DB_PORTABILITY_DELETE_COUNT', 4); |
/** |
* Portability: enable hack that makes numRows() work in Oracle. |
* @see DB_common::setOption() |
*/ |
define('DB_PORTABILITY_NUMROWS', 8); |
/** |
* Portability: makes certain error messages in certain drivers compatible |
* with those from other DBMS's. |
* |
* + mysql, mysqli: change unique/primary key constraints |
* DB_ERROR_ALREADY_EXISTS -> DB_ERROR_CONSTRAINT |
* |
* + odbc(access): MS's ODBC driver reports 'no such field' as code |
* 07001, which means 'too few parameters.' When this option is on |
* that code gets mapped to DB_ERROR_NOSUCHFIELD. |
* |
* @see DB_common::setOption() |
*/ |
define('DB_PORTABILITY_ERRORS', 16); |
/** |
* Portability: convert null values to empty strings in data output by |
* get*() and fetch*(). |
* @see DB_common::setOption() |
*/ |
define('DB_PORTABILITY_NULL_TO_EMPTY', 32); |
/** |
* Portability: turn on all portability features. |
* @see DB_common::setOption() |
*/ |
define('DB_PORTABILITY_ALL', 63); |
// }}} |
// }}} |
// {{{ class DB |
/** |
* The main "DB" class is simply a container class with some static |
* methods for creating DB objects as well as some utility functions |
* common to all parts of DB. |
* |
* The object model of DB is as follows (indentation means inheritance): |
* |
* DB The main DB class. This is simply a utility class |
* with some "static" methods for creating DB objects as |
* well as common utility functions for other DB classes. |
* |
* DB_common The base for each DB implementation. Provides default |
* | implementations (in OO lingo virtual methods) for |
* | the actual DB implementations as well as a bunch of |
* | query utility functions. |
* | |
* +-DB_mysql The DB implementation for MySQL. Inherits DB_common. |
* When calling DB::factory or DB::connect for MySQL |
* connections, the object returned is an instance of this |
* class. |
* |
* @package DB |
* @author Stig Bakken <ssb@php.net> |
* @author Tomas V.V.Cox <cox@idecnet.com> |
* @since PHP 4.0 |
* @version $Id$ |
* @category Database |
*/ |
class DB |
{ |
// {{{ &factory() |
/** |
* Create a new DB object for the specified database type. |
* |
* Allows creation of a DB_<driver> object from which the object's |
* methods can be utilized without actually connecting to a database. |
* |
* @param string $type database type, for example "mysql" |
* @param array $options associative array of option names and values |
* |
* @return object a new DB object. On error, an error object. |
* |
* @see DB_common::setOption() |
* @access public |
*/ |
function &factory($type, $options = false) |
{ |
if (!is_array($options)) { |
$options = array('persistent' => $options); |
} |
if (isset($options['debug']) && $options['debug'] >= 2) { |
// expose php errors with sufficient debug level |
include_once "DB/{$type}.php"; |
} else { |
@include_once "DB/{$type}.php"; |
} |
$classname = "DB_${type}"; |
if (!class_exists($classname)) { |
$tmp = PEAR::raiseError(null, DB_ERROR_NOT_FOUND, null, null, |
"Unable to include the DB/{$type}.php file", |
'DB_Error', true); |
return $tmp; |
} |
@$obj =& new $classname; |
foreach ($options as $option => $value) { |
$test = $obj->setOption($option, $value); |
if (DB::isError($test)) { |
return $test; |
} |
} |
return $obj; |
} |
// }}} |
// {{{ &connect() |
/** |
* Create a new DB object and connect to the specified database. |
* |
* Example 1. |
* <code> <?php |
* require_once 'DB.php'; |
* |
* $dsn = 'mysql://user:password@host/database' |
* $options = array( |
* 'debug' => 2, |
* 'portability' => DB_PORTABILITY_ALL, |
* ); |
* |
* $dbh =& DB::connect($dsn, $options); |
* if (DB::isError($dbh)) { |
* die($dbh->getMessage()); |
* } |
* ?></code> |
* |
* @param mixed $dsn string "data source name" or an array in the |
* format returned by DB::parseDSN() |
* |
* @param array $options an associative array of option names and |
* their values |
* |
* @return object a newly created DB connection object, or a DB |
* error object on error |
* |
* @see DB::parseDSN(), DB_common::setOption(), DB::isError() |
* @access public |
*/ |
function &connect($dsn, $options = array()) |
{ |
$dsninfo = DB::parseDSN($dsn); |
$type = $dsninfo['phptype']; |
if (!is_array($options)) { |
/* |
* For backwards compatibility. $options used to be boolean, |
* indicating whether the connection should be persistent. |
*/ |
$options = array('persistent' => $options); |
} |
if (isset($options['debug']) && $options['debug'] >= 2) { |
// expose php errors with sufficient debug level |
include_once "DB/${type}.php"; |
} else { |
@include_once "DB/${type}.php"; |
} |
$classname = "DB_${type}"; |
if (!class_exists($classname)) { |
$tmp = PEAR::raiseError(null, DB_ERROR_NOT_FOUND, null, null, |
"Unable to include the DB/{$type}.php file for `$dsn'", |
'DB_Error', true); |
return $tmp; |
} |
@$obj =& new $classname; |
foreach ($options as $option => $value) { |
$test = $obj->setOption($option, $value); |
if (DB::isError($test)) { |
return $test; |
} |
} |
$err = $obj->connect($dsninfo, $obj->getOption('persistent')); |
if (DB::isError($err)) { |
$err->addUserInfo($dsn); |
return $err; |
} |
return $obj; |
} |
// }}} |
// {{{ apiVersion() |
/** |
* Return the DB API version |
* |
* @return int the DB API version number |
* |
* @access public |
*/ |
function apiVersion() |
{ |
return 2; |
} |
// }}} |
// {{{ isError() |
/** |
* Tell whether a result code from a DB method is an error |
* |
* @param int $value result code |
* |
* @return bool whether $value is an error |
* |
* @access public |
*/ |
function isError($value) |
{ |
return is_a($value, 'DB_Error'); |
} |
// }}} |
// {{{ isConnection() |
/** |
* Tell whether a value is a DB connection |
* |
* @param mixed $value value to test |
* |
* @return bool whether $value is a DB connection |
* |
* @access public |
*/ |
function isConnection($value) |
{ |
return (is_object($value) && |
is_subclass_of($value, 'db_common') && |
method_exists($value, 'simpleQuery')); |
} |
// }}} |
// {{{ isManip() |
/** |
* Tell whether a query is a data manipulation query (insert, |
* update or delete) or a data definition query (create, drop, |
* alter, grant, revoke). |
* |
* @access public |
* |
* @param string $query the query |
* |
* @return boolean whether $query is a data manipulation query |
*/ |
function isManip($query) |
{ |
$manips = 'INSERT|UPDATE|DELETE|LOAD DATA|'.'REPLACE|CREATE|DROP|'. |
'ALTER|GRANT|REVOKE|'.'LOCK|UNLOCK'; |
if (preg_match('/^\s*"?('.$manips.')\s+/i', $query)) { |
return true; |
} |
return false; |
} |
// }}} |
// {{{ errorMessage() |
/** |
* Return a textual error message for a DB error code |
* |
* @param integer $value error code |
* |
* @return string error message, or false if the error code was |
* not recognized |
*/ |
function errorMessage($value) |
{ |
static $errorMessages; |
if (!isset($errorMessages)) { |
$errorMessages = array( |
DB_ERROR => 'unknown error', |
DB_ERROR_ALREADY_EXISTS => 'already exists', |
DB_ERROR_CANNOT_CREATE => 'can not create', |
DB_ERROR_CANNOT_DELETE => 'can not delete', |
DB_ERROR_CANNOT_DROP => 'can not drop', |
DB_ERROR_CONSTRAINT => 'constraint violation', |
DB_ERROR_CONSTRAINT_NOT_NULL=> 'null value violates not-null constraint', |
DB_ERROR_DIVZERO => 'division by zero', |
DB_ERROR_INVALID => 'invalid', |
DB_ERROR_INVALID_DATE => 'invalid date or time', |
DB_ERROR_INVALID_NUMBER => 'invalid number', |
DB_ERROR_MISMATCH => 'mismatch', |
DB_ERROR_NODBSELECTED => 'no database selected', |
DB_ERROR_NOSUCHFIELD => 'no such field', |
DB_ERROR_NOSUCHTABLE => 'no such table', |
DB_ERROR_NOT_CAPABLE => 'DB backend not capable', |
DB_ERROR_NOT_FOUND => 'not found', |
DB_ERROR_NOT_LOCKED => 'not locked', |
DB_ERROR_SYNTAX => 'syntax error', |
DB_ERROR_UNSUPPORTED => 'not supported', |
DB_ERROR_VALUE_COUNT_ON_ROW => 'value count on row', |
DB_ERROR_INVALID_DSN => 'invalid DSN', |
DB_ERROR_CONNECT_FAILED => 'connect failed', |
DB_OK => 'no error', |
DB_ERROR_NEED_MORE_DATA => 'insufficient data supplied', |
DB_ERROR_EXTENSION_NOT_FOUND=> 'extension not found', |
DB_ERROR_NOSUCHDB => 'no such database', |
DB_ERROR_ACCESS_VIOLATION => 'insufficient permissions', |
DB_ERROR_TRUNCATED => 'truncated' |
); |
} |
if (DB::isError($value)) { |
$value = $value->getCode(); |
} |
return isset($errorMessages[$value]) ? $errorMessages[$value] : $errorMessages[DB_ERROR]; |
} |
// }}} |
// {{{ parseDSN() |
/** |
* Parse a data source name. |
* |
* Additional keys can be added by appending a URI query string to the |
* end of the DSN. |
* |
* The format of the supplied DSN is in its fullest form: |
* <code> |
* phptype(dbsyntax)://username:password@protocol+hostspec/database?option=8&another=true |
* </code> |
* |
* Most variations are allowed: |
* <code> |
* phptype://username:password@protocol+hostspec:110//usr/db_file.db?mode=0644 |
* phptype://username:password@hostspec/database_name |
* phptype://username:password@hostspec |
* phptype://username@hostspec |
* phptype://hostspec/database |
* phptype://hostspec |
* phptype(dbsyntax) |
* phptype |
* </code> |
* |
* @param string $dsn Data Source Name to be parsed |
* |
* @return array an associative array with the following keys: |
* + phptype: Database backend used in PHP (mysql, odbc etc.) |
* + dbsyntax: Database used with regards to SQL syntax etc. |
* + protocol: Communication protocol to use (tcp, unix etc.) |
* + hostspec: Host specification (hostname[:port]) |
* + database: Database to use on the DBMS server |
* + username: User name for login |
* + password: Password for login |
* |
* @author Tomas V.V.Cox <cox@idecnet.com> |
*/ |
function parseDSN($dsn) |
{ |
$parsed = array( |
'phptype' => false, |
'dbsyntax' => false, |
'username' => false, |
'password' => false, |
'protocol' => false, |
'hostspec' => false, |
'port' => false, |
'socket' => false, |
'database' => false, |
); |
if (is_array($dsn)) { |
$dsn = array_merge($parsed, $dsn); |
if (!$dsn['dbsyntax']) { |
$dsn['dbsyntax'] = $dsn['phptype']; |
} |
return $dsn; |
} |
// Find phptype and dbsyntax |
if (($pos = strpos($dsn, '://')) !== false) { |
$str = substr($dsn, 0, $pos); |
$dsn = substr($dsn, $pos + 3); |
} else { |
$str = $dsn; |
$dsn = null; |
} |
// Get phptype and dbsyntax |
// $str => phptype(dbsyntax) |
if (preg_match('|^(.+?)\((.*?)\)$|', $str, $arr)) { |
$parsed['phptype'] = $arr[1]; |
$parsed['dbsyntax'] = !$arr[2] ? $arr[1] : $arr[2]; |
} else { |
$parsed['phptype'] = $str; |
$parsed['dbsyntax'] = $str; |
} |
if (!count($dsn)) { |
return $parsed; |
} |
// Get (if found): username and password |
// $dsn => username:password@protocol+hostspec/database |
if (($at = strrpos($dsn,'@')) !== false) { |
$str = substr($dsn, 0, $at); |
$dsn = substr($dsn, $at + 1); |
if (($pos = strpos($str, ':')) !== false) { |
$parsed['username'] = rawurldecode(substr($str, 0, $pos)); |
$parsed['password'] = rawurldecode(substr($str, $pos + 1)); |
} else { |
$parsed['username'] = rawurldecode($str); |
} |
} |
// Find protocol and hostspec |
// $dsn => proto(proto_opts)/database |
if (preg_match('|^([^(]+)\((.*?)\)/?(.*?)$|', $dsn, $match)) { |
$proto = $match[1]; |
$proto_opts = $match[2] ? $match[2] : false; |
$dsn = $match[3]; |
// $dsn => protocol+hostspec/database (old format) |
} else { |
if (strpos($dsn, '+') !== false) { |
list($proto, $dsn) = explode('+', $dsn, 2); |
} |
if (strpos($dsn, '/') !== false) { |
list($proto_opts, $dsn) = explode('/', $dsn, 2); |
} else { |
$proto_opts = $dsn; |
$dsn = null; |
} |
} |
// process the different protocol options |
$parsed['protocol'] = (!empty($proto)) ? $proto : 'tcp'; |
$proto_opts = rawurldecode($proto_opts); |
if ($parsed['protocol'] == 'tcp') { |
if (strpos($proto_opts, ':') !== false) { |
list($parsed['hostspec'], $parsed['port']) = explode(':', $proto_opts); |
} else { |
$parsed['hostspec'] = $proto_opts; |
} |
} elseif ($parsed['protocol'] == 'unix') { |
$parsed['socket'] = $proto_opts; |
} |
// Get dabase if any |
// $dsn => database |
if ($dsn) { |
// /database |
if (($pos = strpos($dsn, '?')) === false) { |
$parsed['database'] = $dsn; |
// /database?param1=value1¶m2=value2 |
} else { |
$parsed['database'] = substr($dsn, 0, $pos); |
$dsn = substr($dsn, $pos + 1); |
if (strpos($dsn, '&') !== false) { |
$opts = explode('&', $dsn); |
} else { // database?param1=value1 |
$opts = array($dsn); |
} |
foreach ($opts as $opt) { |
list($key, $value) = explode('=', $opt); |
if (!isset($parsed[$key])) { |
// don't allow params overwrite |
$parsed[$key] = rawurldecode($value); |
} |
} |
} |
} |
return $parsed; |
} |
// }}} |
// {{{ assertExtension() |
/** |
* Load a PHP database extension if it is not loaded already. |
* |
* @access public |
* |
* @param string $name the base name of the extension (without the .so or |
* .dll suffix) |
* |
* @return boolean true if the extension was already or successfully |
* loaded, false if it could not be loaded |
*/ |
function assertExtension($name) |
{ |
if (!extension_loaded($name)) { |
$dlext = OS_WINDOWS ? '.dll' : '.so'; |
$dlprefix = OS_WINDOWS ? 'php_' : ''; |
@dl($dlprefix . $name . $dlext); |
return extension_loaded($name); |
} |
return true; |
} |
// }}} |
} |
// }}} |
// {{{ class DB_Error |
/** |
* DB_Error implements a class for reporting portable database error |
* messages. |
* |
* @package DB |
* @author Stig Bakken <ssb@php.net> |
*/ |
class DB_Error extends PEAR_Error |
{ |
// {{{ constructor |
/** |
* DB_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 DB_Error($code = DB_ERROR, $mode = PEAR_ERROR_RETURN, |
$level = E_USER_NOTICE, $debuginfo = null) |
{ |
if (is_int($code)) { |
$this->PEAR_Error('DB Error: ' . DB::errorMessage($code), $code, $mode, $level, $debuginfo); |
} else { |
$this->PEAR_Error("DB Error: $code", DB_ERROR, $mode, $level, $debuginfo); |
} |
} |
// }}} |
} |
// }}} |
// {{{ class DB_result |
/** |
* This class implements a wrapper for a DB result set. |
* A new instance of this class will be returned by the DB implementation |
* after processing a query that returns data. |
* |
* @package DB |
* @author Stig Bakken <ssb@php.net> |
*/ |
class DB_result |
{ |
// {{{ properties |
var $dbh; |
var $result; |
var $row_counter = null; |
/** |
* for limit queries, the row to start fetching |
* @var integer |
*/ |
var $limit_from = null; |
/** |
* for limit queries, the number of rows to fetch |
* @var integer |
*/ |
var $limit_count = null; |
// }}} |
// {{{ constructor |
/** |
* DB_result constructor. |
* @param resource &$dbh DB object reference |
* @param resource $result result resource id |
* @param array $options assoc array with optional result options |
*/ |
function DB_result(&$dbh, $result, $options = array()) |
{ |
$this->dbh = &$dbh; |
$this->result = $result; |
foreach ($options as $key => $value) { |
$this->setOption($key, $value); |
} |
$this->limit_type = $dbh->features['limit']; |
$this->autofree = $dbh->options['autofree']; |
$this->fetchmode = $dbh->fetchmode; |
$this->fetchmode_object_class = $dbh->fetchmode_object_class; |
} |
function setOption($key, $value = null) |
{ |
switch ($key) { |
case 'limit_from': |
$this->limit_from = $value; break; |
case 'limit_count': |
$this->limit_count = $value; break; |
} |
} |
// }}} |
// {{{ fetchRow() |
/** |
* Fetch a row of data and return it by reference into an array. |
* |
* The type of array returned can be controlled either by setting this |
* method's <var>$fetchmode</var> parameter or by changing the default |
* fetch mode setFetchMode() before calling this method. |
* |
* There are two options for standardizing the information returned |
* from databases, ensuring their values are consistent when changing |
* DBMS's. These portability options can be turned on when creating a |
* new DB object or by using setOption(). |
* |
* + <samp>DB_PORTABILITY_LOWERCASE</samp> |
* convert names of fields to lower case |
* |
* + <samp>DB_PORTABILITY_RTRIM</samp> |
* right trim the data |
* |
* @param int $fetchmode how the resulting array should be indexed |
* @param int $rownum the row number to fetch |
* |
* @return array a row of data, null on no more rows or PEAR_Error |
* object on error |
* |
* @see DB_common::setOption(), DB_common::setFetchMode() |
* @access public |
*/ |
function &fetchRow($fetchmode = DB_FETCHMODE_DEFAULT, $rownum=null) |
{ |
if ($fetchmode === DB_FETCHMODE_DEFAULT) { |
$fetchmode = $this->fetchmode; |
} |
if ($fetchmode === DB_FETCHMODE_OBJECT) { |
$fetchmode = DB_FETCHMODE_ASSOC; |
$object_class = $this->fetchmode_object_class; |
} |
if ($this->limit_from !== null) { |
if ($this->row_counter === null) { |
$this->row_counter = $this->limit_from; |
// Skip rows |
if ($this->limit_type == false) { |
$i = 0; |
while ($i++ < $this->limit_from) { |
$this->dbh->fetchInto($this->result, $arr, $fetchmode); |
} |
} |
} |
if ($this->row_counter >= ( |
$this->limit_from + $this->limit_count)) |
{ |
if ($this->autofree) { |
$this->free(); |
} |
$tmp = null; |
return $tmp; |
} |
if ($this->limit_type == 'emulate') { |
$rownum = $this->row_counter; |
} |
$this->row_counter++; |
} |
$res = $this->dbh->fetchInto($this->result, $arr, $fetchmode, $rownum); |
if ($res === DB_OK) { |
if (isset($object_class)) { |
// default mode specified in DB_common::fetchmode_object_class property |
if ($object_class == 'stdClass') { |
$arr = (object) $arr; |
} else { |
$arr = &new $object_class($arr); |
} |
} |
return $arr; |
} |
if ($res == null && $this->autofree) { |
$this->free(); |
} |
return $res; |
} |
// }}} |
// {{{ fetchInto() |
/** |
* Fetch a row of data into an array which is passed by reference. |
* |
* The type of array returned can be controlled either by setting this |
* method's <var>$fetchmode</var> parameter or by changing the default |
* fetch mode setFetchMode() before calling this method. |
* |
* There are two options for standardizing the information returned |
* from databases, ensuring their values are consistent when changing |
* DBMS's. These portability options can be turned on when creating a |
* new DB object or by using setOption(). |
* |
* + <samp>DB_PORTABILITY_LOWERCASE</samp> |
* convert names of fields to lower case |
* |
* + <samp>DB_PORTABILITY_RTRIM</samp> |
* right trim the data |
* |
* @param array &$arr (reference) array where data from the row |
* should be placed |
* @param int $fetchmode how the resulting array should be indexed |
* @param int $rownum the row number to fetch |
* |
* @return mixed DB_OK on success, null on no more rows or |
* a DB_Error object on error |
* |
* @see DB_common::setOption(), DB_common::setFetchMode() |
* @access public |
*/ |
function fetchInto(&$arr, $fetchmode = DB_FETCHMODE_DEFAULT, $rownum=null) |
{ |
if ($fetchmode === DB_FETCHMODE_DEFAULT) { |
$fetchmode = $this->fetchmode; |
} |
if ($fetchmode === DB_FETCHMODE_OBJECT) { |
$fetchmode = DB_FETCHMODE_ASSOC; |
$object_class = $this->fetchmode_object_class; |
} |
if ($this->limit_from !== null) { |
if ($this->row_counter === null) { |
$this->row_counter = $this->limit_from; |
// Skip rows |
if ($this->limit_type == false) { |
$i = 0; |
while ($i++ < $this->limit_from) { |
$this->dbh->fetchInto($this->result, $arr, $fetchmode); |
} |
} |
} |
if ($this->row_counter >= ( |
$this->limit_from + $this->limit_count)) |
{ |
if ($this->autofree) { |
$this->free(); |
} |
return null; |
} |
if ($this->limit_type == 'emulate') { |
$rownum = $this->row_counter; |
} |
$this->row_counter++; |
} |
$res = $this->dbh->fetchInto($this->result, $arr, $fetchmode, $rownum); |
if ($res === DB_OK) { |
if (isset($object_class)) { |
// default mode specified in DB_common::fetchmode_object_class property |
if ($object_class == 'stdClass') { |
$arr = (object) $arr; |
} else { |
$arr = new $object_class($arr); |
} |
} |
return DB_OK; |
} |
if ($res == null && $this->autofree) { |
$this->free(); |
} |
return $res; |
} |
// }}} |
// {{{ numCols() |
/** |
* Get the the number of columns in a result set. |
* |
* @return int the number of columns, or a DB error |
* |
* @access public |
*/ |
function numCols() |
{ |
return $this->dbh->numCols($this->result); |
} |
// }}} |
// {{{ numRows() |
/** |
* Get the number of rows in a result set. |
* |
* @return int the number of rows, or a DB error |
* |
* @access public |
*/ |
function numRows() |
{ |
return $this->dbh->numRows($this->result); |
} |
// }}} |
// {{{ nextResult() |
/** |
* Get the next result if a batch of queries was executed. |
* |
* @return bool true if a new result is available or false if not. |
* |
* @access public |
*/ |
function nextResult() |
{ |
return $this->dbh->nextResult($this->result); |
} |
// }}} |
// {{{ free() |
/** |
* Frees the resources allocated for this result set. |
* @return int error code |
* |
* @access public |
*/ |
function free() |
{ |
$err = $this->dbh->freeResult($this->result); |
if (DB::isError($err)) { |
return $err; |
} |
$this->result = false; |
return true; |
} |
// }}} |
// {{{ tableInfo() |
/** |
* @deprecated |
* @internal |
* @see DB_common::tableInfo() |
*/ |
function tableInfo($mode = null) |
{ |
if (is_string($mode)) { |
return $this->dbh->raiseError(DB_ERROR_NEED_MORE_DATA); |
} |
return $this->dbh->tableInfo($this, $mode); |
} |
// }}} |
// {{{ getRowCounter() |
/** |
* returns the actual row number |
* @return integer |
*/ |
function getRowCounter() |
{ |
return $this->row_counter; |
} |
// }}} |
} |
// }}} |
// {{{ class DB_row |
/** |
* Pear DB Row Object |
* @see DB_common::setFetchMode() |
*/ |
class DB_row |
{ |
// {{{ constructor |
/** |
* constructor |
* |
* @param resource row data as array |
*/ |
function DB_row(&$arr) |
{ |
foreach ($arr as $key => $value) { |
$this->$key = &$arr[$key]; |
} |
} |
// }}} |
} |
// }}} |
/* |
* Local variables: |
* tab-width: 4 |
* c-basic-offset: 4 |
* End: |
*/ |
?> |
/trunk/jrest/lib/PEAR.php |
---|
New file |
0,0 → 1,971 |
<?php |
// |
// +----------------------------------------------------------------------+ |
// | PEAR, the PHP Extension and Application Repository | |
// +----------------------------------------------------------------------+ |
// | 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 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. | |
// +----------------------------------------------------------------------+ |
// | Authors: Sterling Hughes <sterling@php.net> | |
// | Stig Bakken <ssb@php.net> | |
// | Tomas V.V.Cox <cox@idecnet.com> | |
// +----------------------------------------------------------------------+ |
// |
// $Id$ |
// |
define('PEAR_ERROR_RETURN', 1); |
define('PEAR_ERROR_PRINT', 2); |
define('PEAR_ERROR_TRIGGER', 4); |
define('PEAR_ERROR_DIE', 8); |
define('PEAR_ERROR_CALLBACK', 16); |
define('PEAR_ERROR_EXCEPTION', 32); |
define('PEAR_ZE2', (function_exists('version_compare') && |
version_compare(zend_version(), "2-dev", "ge"))); |
if (substr(PHP_OS, 0, 3) == 'WIN') { |
define('OS_WINDOWS', true); |
define('OS_UNIX', false); |
define('PEAR_OS', 'Windows'); |
} else { |
define('OS_WINDOWS', false); |
define('OS_UNIX', true); |
define('PEAR_OS', 'Unix'); // blatant assumption |
} |
// instant backwards compatibility |
if (!defined('PATH_SEPARATOR')) { |
if (OS_WINDOWS) { |
define('PATH_SEPARATOR', ';'); |
} else { |
define('PATH_SEPARATOR', ':'); |
} |
} |
$GLOBALS['_PEAR_default_error_mode'] = PEAR_ERROR_RETURN; |
$GLOBALS['_PEAR_default_error_options'] = E_USER_NOTICE; |
$GLOBALS['_PEAR_destructor_object_list'] = array(); |
$GLOBALS['_PEAR_shutdown_funcs'] = array(); |
$GLOBALS['_PEAR_error_handler_stack'] = array(); |
ini_set('track_errors', true); |
/** |
* Base class for other PEAR classes. Provides rudimentary |
* emulation of destructors. |
* |
* If you want a destructor in your class, inherit PEAR and make a |
* destructor method called _yourclassname (same name as the |
* constructor, but with a "_" prefix). Also, in your constructor you |
* have to call the PEAR constructor: $this->PEAR();. |
* The destructor method will be called without parameters. Note that |
* at in some SAPI implementations (such as Apache), any output during |
* the request shutdown (in which destructors are called) seems to be |
* discarded. If you need to get any debug information from your |
* destructor, use error_log(), syslog() or something similar. |
* |
* IMPORTANT! To use the emulated destructors you need to create the |
* objects by reference: $obj =& new PEAR_child; |
* |
* @since PHP 4.0.2 |
* @author Stig Bakken <ssb@php.net> |
* @see http://pear.php.net/manual/ |
*/ |
class PEAR |
{ |
// {{{ properties |
/** |
* Whether to enable internal debug messages. |
* |
* @var bool |
* @access private |
*/ |
var $_debug = false; |
/** |
* Default error mode for this object. |
* |
* @var int |
* @access private |
*/ |
var $_default_error_mode = null; |
/** |
* Default error options used for this object when error mode |
* is PEAR_ERROR_TRIGGER. |
* |
* @var int |
* @access private |
*/ |
var $_default_error_options = null; |
/** |
* Default error handler (callback) for this object, if error mode is |
* PEAR_ERROR_CALLBACK. |
* |
* @var string |
* @access private |
*/ |
var $_default_error_handler = ''; |
/** |
* Which class to use for error objects. |
* |
* @var string |
* @access private |
*/ |
var $_error_class = 'PEAR_Error'; |
/** |
* An array of expected errors. |
* |
* @var array |
* @access private |
*/ |
var $_expected_errors = array(); |
// }}} |
// {{{ constructor |
/** |
* Constructor. Registers this object in |
* $_PEAR_destructor_object_list for destructor emulation if a |
* destructor object exists. |
* |
* @param string $error_class (optional) which class to use for |
* error objects, defaults to PEAR_Error. |
* @access public |
* @return void |
*/ |
function PEAR($error_class = null) |
{ |
$classname = get_class($this); |
if ($this->_debug) { |
print "PEAR constructor called, class=$classname\n"; |
} |
if ($error_class !== null) { |
$this->_error_class = $error_class; |
} |
while ($classname) { |
$destructor = "_$classname"; |
if (method_exists($this, $destructor)) { |
global $_PEAR_destructor_object_list; |
$_PEAR_destructor_object_list[] = &$this; |
break; |
} else { |
$classname = get_parent_class($classname); |
} |
} |
} |
// }}} |
// {{{ destructor |
/** |
* Destructor (the emulated type of...). Does nothing right now, |
* but is included for forward compatibility, so subclass |
* destructors should always call it. |
* |
* See the note in the class desciption about output from |
* destructors. |
* |
* @access public |
* @return void |
*/ |
function _PEAR() { |
if ($this->_debug) { |
printf("PEAR destructor called, class=%s\n", get_class($this)); |
} |
} |
// }}} |
// {{{ getStaticProperty() |
/** |
* If you have a class that's mostly/entirely static, and you need static |
* properties, you can use this method to simulate them. Eg. in your method(s) |
* do this: $myVar = &PEAR::getStaticProperty('myVar'); |
* You MUST use a reference, or they will not persist! |
* |
* @access public |
* @param string $class The calling classname, to prevent clashes |
* @param string $var The variable to retrieve. |
* @return mixed A reference to the variable. If not set it will be |
* auto initialised to NULL. |
*/ |
function &getStaticProperty($class, $var) |
{ |
static $properties; |
return $properties[$class][$var]; |
} |
// }}} |
// {{{ registerShutdownFunc() |
/** |
* Use this function to register a shutdown method for static |
* classes. |
* |
* @access public |
* @param mixed $func The function name (or array of class/method) to call |
* @param mixed $args The arguments to pass to the function |
* @return void |
*/ |
function registerShutdownFunc($func, $args = array()) |
{ |
$GLOBALS['_PEAR_shutdown_funcs'][] = array($func, $args); |
} |
// }}} |
// {{{ isError() |
/** |
* Tell whether a value is a PEAR error. |
* |
* @param mixed $data the value to test |
* @param int $code if $data is an error object, return true |
* only if $code is a string and |
* $obj->getMessage() == $code or |
* $code is an integer and $obj->getCode() == $code |
* @access public |
* @return bool true if parameter is an error |
*/ |
function isError($data, $code = null) |
{ |
if (is_a($data, 'PEAR_Error')) { |
if (is_null($code)) { |
return true; |
} elseif (is_string($code)) { |
return $data->getMessage() == $code; |
} else { |
return $data->getCode() == $code; |
} |
} |
return false; |
} |
// }}} |
// {{{ setErrorHandling() |
/** |
* Sets how errors generated by this object should be handled. |
* Can be invoked both in objects and statically. If called |
* statically, setErrorHandling sets the default behaviour for all |
* PEAR objects. If called in an object, setErrorHandling sets |
* the default behaviour for that object. |
* |
* @param int $mode |
* One of PEAR_ERROR_RETURN, PEAR_ERROR_PRINT, |
* PEAR_ERROR_TRIGGER, PEAR_ERROR_DIE, |
* PEAR_ERROR_CALLBACK or PEAR_ERROR_EXCEPTION. |
* |
* @param mixed $options |
* When $mode is PEAR_ERROR_TRIGGER, this is the error level (one |
* of E_USER_NOTICE, E_USER_WARNING or E_USER_ERROR). |
* |
* When $mode is PEAR_ERROR_CALLBACK, this parameter is expected |
* to be the callback function or method. A callback |
* function is a string with the name of the function, a |
* callback method is an array of two elements: the element |
* at index 0 is the object, and the element at index 1 is |
* the name of the method to call in the object. |
* |
* When $mode is PEAR_ERROR_PRINT or PEAR_ERROR_DIE, this is |
* a printf format string used when printing the error |
* message. |
* |
* @access public |
* @return void |
* @see PEAR_ERROR_RETURN |
* @see PEAR_ERROR_PRINT |
* @see PEAR_ERROR_TRIGGER |
* @see PEAR_ERROR_DIE |
* @see PEAR_ERROR_CALLBACK |
* @see PEAR_ERROR_EXCEPTION |
* |
* @since PHP 4.0.5 |
*/ |
function setErrorHandling($mode = null, $options = null) |
{ |
if (isset($this) && is_a($this, 'PEAR')) { |
$setmode = &$this->_default_error_mode; |
$setoptions = &$this->_default_error_options; |
} else { |
$setmode = &$GLOBALS['_PEAR_default_error_mode']; |
$setoptions = &$GLOBALS['_PEAR_default_error_options']; |
} |
switch ($mode) { |
case PEAR_ERROR_RETURN: |
case PEAR_ERROR_PRINT: |
case PEAR_ERROR_TRIGGER: |
case PEAR_ERROR_DIE: |
case PEAR_ERROR_EXCEPTION: |
case null: |
$setmode = $mode; |
$setoptions = $options; |
break; |
case PEAR_ERROR_CALLBACK: |
$setmode = $mode; |
// class/object method callback |
if (is_callable($options)) { |
$setoptions = $options; |
} else { |
trigger_error("invalid error callback", E_USER_WARNING); |
} |
break; |
default: |
trigger_error("invalid error mode", E_USER_WARNING); |
break; |
} |
} |
// }}} |
// {{{ expectError() |
/** |
* This method is used to tell which errors you expect to get. |
* Expected errors are always returned with error mode |
* PEAR_ERROR_RETURN. Expected error codes are stored in a stack, |
* and this method pushes a new element onto it. The list of |
* expected errors are in effect until they are popped off the |
* stack with the popExpect() method. |
* |
* Note that this method can not be called statically |
* |
* @param mixed $code a single error code or an array of error codes to expect |
* |
* @return int the new depth of the "expected errors" stack |
* @access public |
*/ |
function expectError($code = '*') |
{ |
if (is_array($code)) { |
array_push($this->_expected_errors, $code); |
} else { |
array_push($this->_expected_errors, array($code)); |
} |
return sizeof($this->_expected_errors); |
} |
// }}} |
// {{{ popExpect() |
/** |
* This method pops one element off the expected error codes |
* stack. |
* |
* @return array the list of error codes that were popped |
*/ |
function popExpect() |
{ |
return array_pop($this->_expected_errors); |
} |
// }}} |
// {{{ _checkDelExpect() |
/** |
* This method checks unsets an error code if available |
* |
* @param mixed error code |
* @return bool true if the error code was unset, false otherwise |
* @access private |
* @since PHP 4.3.0 |
*/ |
function _checkDelExpect($error_code) |
{ |
$deleted = false; |
foreach ($this->_expected_errors AS $key => $error_array) { |
if (in_array($error_code, $error_array)) { |
unset($this->_expected_errors[$key][array_search($error_code, $error_array)]); |
$deleted = true; |
} |
// clean up empty arrays |
if (0 == count($this->_expected_errors[$key])) { |
unset($this->_expected_errors[$key]); |
} |
} |
return $deleted; |
} |
// }}} |
// {{{ delExpect() |
/** |
* This method deletes all occurences of the specified element from |
* the expected error codes stack. |
* |
* @param mixed $error_code error code that should be deleted |
* @return mixed list of error codes that were deleted or error |
* @access public |
* @since PHP 4.3.0 |
*/ |
function delExpect($error_code) |
{ |
$deleted = false; |
if ((is_array($error_code) && (0 != count($error_code)))) { |
// $error_code is a non-empty array here; |
// we walk through it trying to unset all |
// values |
foreach($error_code as $key => $error) { |
if ($this->_checkDelExpect($error)) { |
$deleted = true; |
} else { |
$deleted = false; |
} |
} |
return $deleted ? true : PEAR::raiseError("The expected error you submitted does not exist"); // IMPROVE ME |
} elseif (!empty($error_code)) { |
// $error_code comes alone, trying to unset it |
if ($this->_checkDelExpect($error_code)) { |
return true; |
} else { |
return PEAR::raiseError("The expected error you submitted does not exist"); // IMPROVE ME |
} |
} else { |
// $error_code is empty |
return PEAR::raiseError("The expected error you submitted is empty"); // IMPROVE ME |
} |
} |
// }}} |
// {{{ raiseError() |
/** |
* This method is a wrapper that returns an instance of the |
* configured error class with this object's default error |
* handling applied. If the $mode and $options parameters are not |
* specified, the object's defaults are used. |
* |
* @param mixed $message a text error message or a PEAR error object |
* |
* @param int $code a numeric error code (it is up to your class |
* to define these if you want to use codes) |
* |
* @param int $mode One of PEAR_ERROR_RETURN, PEAR_ERROR_PRINT, |
* PEAR_ERROR_TRIGGER, PEAR_ERROR_DIE, |
* PEAR_ERROR_CALLBACK, PEAR_ERROR_EXCEPTION. |
* |
* @param mixed $options If $mode is PEAR_ERROR_TRIGGER, this parameter |
* specifies the PHP-internal error level (one of |
* E_USER_NOTICE, E_USER_WARNING or E_USER_ERROR). |
* If $mode is PEAR_ERROR_CALLBACK, this |
* parameter specifies the callback function or |
* method. In other error modes this parameter |
* is ignored. |
* |
* @param string $userinfo If you need to pass along for example debug |
* information, this parameter is meant for that. |
* |
* @param string $error_class The returned error object will be |
* instantiated from this class, if specified. |
* |
* @param bool $skipmsg If true, raiseError will only pass error codes, |
* the error message parameter will be dropped. |
* |
* @access public |
* @return object a PEAR error object |
* @see PEAR::setErrorHandling |
* @since PHP 4.0.5 |
*/ |
function raiseError($message = null, |
$code = null, |
$mode = null, |
$options = null, |
$userinfo = null, |
$error_class = null, |
$skipmsg = false) |
{ |
// The error is yet a PEAR error object |
if (is_object($message)) { |
$code = $message->getCode(); |
$userinfo = $message->getUserInfo(); |
$error_class = $message->getType(); |
$message->error_message_prefix = ''; |
$message = $message->getMessage(); |
} |
if (isset($this) && isset($this->_expected_errors) && sizeof($this->_expected_errors) > 0 && sizeof($exp = end($this->_expected_errors))) { |
if ($exp[0] == "*" || |
(is_int(reset($exp)) && in_array($code, $exp)) || |
(is_string(reset($exp)) && in_array($message, $exp))) { |
$mode = PEAR_ERROR_RETURN; |
} |
} |
// No mode given, try global ones |
if ($mode === null) { |
// Class error handler |
if (isset($this) && isset($this->_default_error_mode)) { |
$mode = $this->_default_error_mode; |
$options = $this->_default_error_options; |
// Global error handler |
} elseif (isset($GLOBALS['_PEAR_default_error_mode'])) { |
$mode = $GLOBALS['_PEAR_default_error_mode']; |
$options = $GLOBALS['_PEAR_default_error_options']; |
} |
} |
if ($error_class !== null) { |
$ec = $error_class; |
} elseif (isset($this) && isset($this->_error_class)) { |
$ec = $this->_error_class; |
} else { |
$ec = 'PEAR_Error'; |
} |
if ($skipmsg) { |
return new $ec($code, $mode, $options, $userinfo); |
} else { |
return new $ec($message, $code, $mode, $options, $userinfo); |
} |
} |
// }}} |
// {{{ throwError() |
/** |
* Simpler form of raiseError with fewer options. In most cases |
* message, code and userinfo are enough. |
* |
* @param string $message |
* |
*/ |
function throwError($message = null, |
$code = null, |
$userinfo = null) |
{ |
if (isset($this) && is_subclass_of($this, 'PEAR_Error')) { |
return $this->raiseError($message, $code, null, null, $userinfo); |
} else { |
return PEAR::raiseError($message, $code, null, null, $userinfo); |
} |
} |
// }}} |
// {{{ pushErrorHandling() |
/** |
* Push a new error handler on top of the error handler options stack. With this |
* you can easily override the actual error handler for some code and restore |
* it later with popErrorHandling. |
* |
* @param mixed $mode (same as setErrorHandling) |
* @param mixed $options (same as setErrorHandling) |
* |
* @return bool Always true |
* |
* @see PEAR::setErrorHandling |
*/ |
function pushErrorHandling($mode, $options = null) |
{ |
$stack = &$GLOBALS['_PEAR_error_handler_stack']; |
if (isset($this) && is_a($this, 'PEAR')) { |
$def_mode = &$this->_default_error_mode; |
$def_options = &$this->_default_error_options; |
} else { |
$def_mode = &$GLOBALS['_PEAR_default_error_mode']; |
$def_options = &$GLOBALS['_PEAR_default_error_options']; |
} |
$stack[] = array($def_mode, $def_options); |
if (isset($this) && is_a($this, 'PEAR')) { |
$this->setErrorHandling($mode, $options); |
} else { |
PEAR::setErrorHandling($mode, $options); |
} |
$stack[] = array($mode, $options); |
return true; |
} |
// }}} |
// {{{ popErrorHandling() |
/** |
* Pop the last error handler used |
* |
* @return bool Always true |
* |
* @see PEAR::pushErrorHandling |
*/ |
function popErrorHandling() |
{ |
$stack = &$GLOBALS['_PEAR_error_handler_stack']; |
array_pop($stack); |
list($mode, $options) = $stack[sizeof($stack) - 1]; |
array_pop($stack); |
if (isset($this) && is_a($this, 'PEAR')) { |
$this->setErrorHandling($mode, $options); |
} else { |
PEAR::setErrorHandling($mode, $options); |
} |
return true; |
} |
// }}} |
// {{{ loadExtension() |
/** |
* OS independant PHP extension load. Remember to take care |
* on the correct extension name for case sensitive OSes. |
* |
* @param string $ext The extension name |
* @return bool Success or not on the dl() call |
*/ |
function loadExtension($ext) |
{ |
if (!extension_loaded($ext)) { |
// if either returns true dl() will produce a FATAL error, stop that |
if ((ini_get('enable_dl') != 1) || (ini_get('safe_mode') == 1)) { |
return false; |
} |
if (OS_WINDOWS) { |
$suffix = '.dll'; |
} elseif (PHP_OS == 'HP-UX') { |
$suffix = '.sl'; |
} elseif (PHP_OS == 'AIX') { |
$suffix = '.a'; |
} elseif (PHP_OS == 'OSX') { |
$suffix = '.bundle'; |
} else { |
$suffix = '.so'; |
} |
return @dl('php_'.$ext.$suffix) || @dl($ext.$suffix); |
} |
return true; |
} |
// }}} |
} |
// {{{ _PEAR_call_destructors() |
function _PEAR_call_destructors() |
{ |
global $_PEAR_destructor_object_list; |
if (is_array($_PEAR_destructor_object_list) && |
sizeof($_PEAR_destructor_object_list)) |
{ |
reset($_PEAR_destructor_object_list); |
while (list($k, $objref) = each($_PEAR_destructor_object_list)) { |
$classname = get_class($objref); |
while ($classname) { |
$destructor = "_$classname"; |
if (method_exists($objref, $destructor)) { |
$objref->$destructor(); |
break; |
} else { |
$classname = get_parent_class($classname); |
} |
} |
} |
// Empty the object list to ensure that destructors are |
// not called more than once. |
$_PEAR_destructor_object_list = array(); |
} |
// Now call the shutdown functions |
if (is_array($GLOBALS['_PEAR_shutdown_funcs']) AND !empty($GLOBALS['_PEAR_shutdown_funcs'])) { |
foreach ($GLOBALS['_PEAR_shutdown_funcs'] as $value) { |
call_user_func_array($value[0], $value[1]); |
} |
} |
} |
// }}} |
class PEAR_Error |
{ |
// {{{ properties |
var $error_message_prefix = ''; |
var $mode = PEAR_ERROR_RETURN; |
var $level = E_USER_NOTICE; |
var $code = -1; |
var $message = ''; |
var $userinfo = ''; |
var $backtrace = null; |
// }}} |
// {{{ constructor |
/** |
* PEAR_Error constructor |
* |
* @param string $message message |
* |
* @param int $code (optional) error code |
* |
* @param int $mode (optional) error mode, one of: PEAR_ERROR_RETURN, |
* PEAR_ERROR_PRINT, PEAR_ERROR_DIE, PEAR_ERROR_TRIGGER, |
* PEAR_ERROR_CALLBACK or PEAR_ERROR_EXCEPTION |
* |
* @param mixed $options (optional) error level, _OR_ in the case of |
* PEAR_ERROR_CALLBACK, the callback function or object/method |
* tuple. |
* |
* @param string $userinfo (optional) additional user/debug info |
* |
* @access public |
* |
*/ |
function PEAR_Error($message = 'unknown error', $code = null, |
$mode = null, $options = null, $userinfo = null) |
{ |
if ($mode === null) { |
$mode = PEAR_ERROR_RETURN; |
} |
$this->message = $message; |
$this->code = $code; |
$this->mode = $mode; |
$this->userinfo = $userinfo; |
if (function_exists("debug_backtrace")) { |
$this->backtrace = debug_backtrace(); |
} |
if ($mode & PEAR_ERROR_CALLBACK) { |
$this->level = E_USER_NOTICE; |
$this->callback = $options; |
} else { |
if ($options === null) { |
$options = E_USER_NOTICE; |
} |
$this->level = $options; |
$this->callback = null; |
} |
if ($this->mode & PEAR_ERROR_PRINT) { |
if (is_null($options) || is_int($options)) { |
$format = "%s"; |
} else { |
$format = $options; |
} |
printf($format, $this->getMessage()); |
} |
if ($this->mode & PEAR_ERROR_TRIGGER) { |
trigger_error($this->getMessage(), $this->level); |
} |
if ($this->mode & PEAR_ERROR_DIE) { |
$msg = $this->getMessage(); |
if (is_null($options) || is_int($options)) { |
$format = "%s"; |
if (substr($msg, -1) != "\n") { |
$msg .= "\n"; |
} |
} else { |
$format = $options; |
} |
die(sprintf($format, $msg)); |
} |
if ($this->mode & PEAR_ERROR_CALLBACK) { |
if (is_callable($this->callback)) { |
call_user_func($this->callback, $this); |
} |
} |
if (PEAR_ZE2 && $this->mode & PEAR_ERROR_EXCEPTION) { |
eval('throw $this;'); |
} |
} |
// }}} |
// {{{ getMode() |
/** |
* Get the error mode from an error object. |
* |
* @return int error mode |
* @access public |
*/ |
function getMode() { |
return $this->mode; |
} |
// }}} |
// {{{ getCallback() |
/** |
* Get the callback function/method from an error object. |
* |
* @return mixed callback function or object/method array |
* @access public |
*/ |
function getCallback() { |
return $this->callback; |
} |
// }}} |
// {{{ getMessage() |
/** |
* Get the error message from an error object. |
* |
* @return string full error message |
* @access public |
*/ |
function getMessage() |
{ |
return ($this->error_message_prefix . $this->message); |
} |
// }}} |
// {{{ getCode() |
/** |
* Get error code from an error object |
* |
* @return int error code |
* @access public |
*/ |
function getCode() |
{ |
return $this->code; |
} |
// }}} |
// {{{ getType() |
/** |
* Get the name of this error/exception. |
* |
* @return string error/exception name (type) |
* @access public |
*/ |
function getType() |
{ |
return get_class($this); |
} |
// }}} |
// {{{ getUserInfo() |
/** |
* Get additional user-supplied information. |
* |
* @return string user-supplied information |
* @access public |
*/ |
function getUserInfo() |
{ |
return $this->userinfo; |
} |
// }}} |
// {{{ getDebugInfo() |
/** |
* Get additional debug information supplied by the application. |
* |
* @return string debug information |
* @access public |
*/ |
function getDebugInfo() |
{ |
return $this->getUserInfo(); |
} |
// }}} |
// {{{ getBacktrace() |
/** |
* Get the call backtrace from where the error was generated. |
* Supported with PHP 4.3.0 or newer. |
* |
* @param int $frame (optional) what frame to fetch |
* @return array Backtrace, or NULL if not available. |
* @access public |
*/ |
function getBacktrace($frame = null) |
{ |
if ($frame === null) { |
return $this->backtrace; |
} |
return $this->backtrace[$frame]; |
} |
// }}} |
// {{{ addUserInfo() |
function addUserInfo($info) |
{ |
if (empty($this->userinfo)) { |
$this->userinfo = $info; |
} else { |
$this->userinfo .= " ** $info"; |
} |
} |
// }}} |
// {{{ toString() |
/** |
* Make a string representation of this object. |
* |
* @return string a string with an object summary |
* @access public |
*/ |
function toString() { |
$modes = array(); |
$levels = array(E_USER_NOTICE => 'notice', |
E_USER_WARNING => 'warning', |
E_USER_ERROR => 'error'); |
if ($this->mode & PEAR_ERROR_CALLBACK) { |
if (is_array($this->callback)) { |
$callback = get_class($this->callback[0]) . '::' . |
$this->callback[1]; |
} else { |
$callback = $this->callback; |
} |
return sprintf('[%s: message="%s" code=%d mode=callback '. |
'callback=%s prefix="%s" info="%s"]', |
get_class($this), $this->message, $this->code, |
$callback, $this->error_message_prefix, |
$this->userinfo); |
} |
if ($this->mode & PEAR_ERROR_PRINT) { |
$modes[] = 'print'; |
} |
if ($this->mode & PEAR_ERROR_TRIGGER) { |
$modes[] = 'trigger'; |
} |
if ($this->mode & PEAR_ERROR_DIE) { |
$modes[] = 'die'; |
} |
if ($this->mode & PEAR_ERROR_RETURN) { |
$modes[] = 'return'; |
} |
return sprintf('[%s: message="%s" code=%d mode=%s level=%s '. |
'prefix="%s" info="%s"]', |
get_class($this), $this->message, $this->code, |
implode("|", $modes), $levels[$this->level], |
$this->error_message_prefix, |
$this->userinfo); |
} |
// }}} |
} |
register_shutdown_function("_PEAR_call_destructors"); |
/* |
* Local Variables: |
* mode: php |
* tab-width: 4 |
* c-basic-offset: 4 |
* End: |
*/ |
?> |
/trunk/jrest/lib/DBAccessor.php |
---|
New file |
0,0 → 1,34 |
<?php |
require_once 'JrestService.php'; |
class DBAccessor extends JrestService { |
public function connectDB($config, $base = 'database') { |
require_once 'DB.php'; |
$dsn = $config[$base]; |
$DB =& DB::connect($dsn); |
if (DB::isError($DB)) { |
die($DB->getMessage()); |
} |
$DB->query("SET NAMES 'utf8'"); |
return $DB; |
} |
public function connecterPDO($config, $base = 'database') { |
$cfg = $config[$base]; |
$dsn = $cfg['phptype'].':dbname='.$cfg['database'].';host='.$cfg['hostspec']; |
try { |
$PDO = new PDO($dsn, $cfg['username'], $cfg['password']); |
} catch (PDOException $e) { |
echo 'La connexion à la base de donnée via PDO a échouée : ' . $e->getMessage(); |
} |
// Passe en UTF-8 la connexion à la BDD |
$PDO->exec("SET NAMES 'utf8'"); |
// Affiche les erreurs détectées par PDO (sinon mode silencieux => aucune erreur affiché) |
$PDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
return $PDO; |
} |
} |
?> |
/trunk/jrest/lib/JrestService.php |
---|
New file |
0,0 → 1,72 |
<?php |
/** |
* PHP Version 5 |
* |
* @category PHP |
* @package jrest |
* @author aurelien <aurelien@tela-botanica.org> |
* @copyright 2009 Tela-Botanica |
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL |
* @version $$id$$ |
* @link /doc/jrest/ |
*/ |
class JrestService { |
protected $config; |
protected $script_time; |
protected $max_exec_time; |
public function JrestService($config) { |
$this->config = config; |
$this->script_time = microtime(true); |
$this->max_exec_time = ini_get('max_execution_time'); |
} |
public function isAdmin($id) { |
$admins = $this->config['jrest_admin']['admin']; |
$admin_tab = split(',',$admins); |
if (in_array($id,$admin_tab)) { |
return true; |
} else { |
return false; |
} |
} |
public function controleUtilisateur($id) { |
if ($_SESSION['user']['name'] == '') { |
//cas de la session temporaire, on ne fait rien de particulier |
} else { |
if (!$this->isAdmin($_SESSION['user']['name']) && $_SESSION['user']['name'] != $id) { |
// cas d'usurpation d'identité |
print 'Accès interdit'; |
exit(); |
} |
} |
} |
public function logger($index,$chaine) { |
if(!class_exists('Log')) { |
include_once('Log.php'); |
Log::getInstance(); |
} |
Log::setCheminLog($this->config['log']['cheminlog']); |
Log::setTimeZone($this->config['log']['timezone']); |
Log::setTailleMax($this->config['log']['taillemax']); |
Log::ajouterEntree($index,$chaine); |
} |
public function verifierOuRelancerExecution() { |
if((microtime(true) - $this->script_time) > ($this->max_exec_time - 5)*100) { |
set_time_limit(2); |
$this->logger('JRestService','Durée du script augmentée :'.microtime(true).' - '.$this->script_time.'.) > ('.$this->max_exec_time.' - 5)*1000000'); |
return true; |
} |
return false; |
} |
} |
?> |
/trunk/jrest/lib/HTTP/.directory |
---|
New file |
0,0 → 1,5 |
[Dolphin] |
Timestamp=2010,6,10,16,42,37 |
[Settings] |
ShowDotFiles=true |
/trunk/jrest/lib/HTTP/Download.php |
---|
New file |
0,0 → 1,1034 |
<?php |
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ |
/** |
* HTTP::Download |
* |
* PHP versions 4 and 5 |
* |
* @category HTTP |
* @package HTTP_Download |
* @author Michael Wallner <mike@php.net> |
* @copyright 2003-2005 Michael Wallner |
* @license BSD, revised |
* @version CVS: $Id$ |
* @link http://pear.php.net/package/HTTP_Download |
*/ |
// {{{ includes |
/** |
* Requires PEAR |
*/ |
require_once 'PEAR.php'; |
/** |
* Requires HTTP_Header |
*/ |
require_once 'HTTP/Header.php'; |
// }}} |
// {{{ constants |
/**#@+ Use with HTTP_Download::setContentDisposition() **/ |
/** |
* Send data as attachment |
*/ |
define('HTTP_DOWNLOAD_ATTACHMENT', 'attachment'); |
/** |
* Send data inline |
*/ |
define('HTTP_DOWNLOAD_INLINE', 'inline'); |
/**#@-**/ |
/**#@+ Use with HTTP_Download::sendArchive() **/ |
/** |
* Send as uncompressed tar archive |
*/ |
define('HTTP_DOWNLOAD_TAR', 'TAR'); |
/** |
* Send as gzipped tar archive |
*/ |
define('HTTP_DOWNLOAD_TGZ', 'TGZ'); |
/** |
* Send as bzip2 compressed tar archive |
*/ |
define('HTTP_DOWNLOAD_BZ2', 'BZ2'); |
/** |
* Send as zip archive |
*/ |
define('HTTP_DOWNLOAD_ZIP', 'ZIP'); |
/**#@-**/ |
/**#@+ |
* Error constants |
*/ |
define('HTTP_DOWNLOAD_E_HEADERS_SENT', -1); |
define('HTTP_DOWNLOAD_E_NO_EXT_ZLIB', -2); |
define('HTTP_DOWNLOAD_E_NO_EXT_MMAGIC', -3); |
define('HTTP_DOWNLOAD_E_INVALID_FILE', -4); |
define('HTTP_DOWNLOAD_E_INVALID_PARAM', -5); |
define('HTTP_DOWNLOAD_E_INVALID_RESOURCE', -6); |
define('HTTP_DOWNLOAD_E_INVALID_REQUEST', -7); |
define('HTTP_DOWNLOAD_E_INVALID_CONTENT_TYPE', -8); |
define('HTTP_DOWNLOAD_E_INVALID_ARCHIVE_TYPE', -9); |
/**#@-**/ |
// }}} |
/** |
* Send HTTP Downloads/Responses. |
* |
* With this package you can handle (hidden) downloads. |
* It supports partial downloads, resuming and sending |
* raw data ie. from database BLOBs. |
* |
* <i>ATTENTION:</i> |
* You shouldn't use this package together with ob_gzhandler or |
* zlib.output_compression enabled in your php.ini, especially |
* if you want to send already gzipped data! |
* |
* @access public |
* @version $Revision$ |
*/ |
class HTTP_Download |
{ |
// {{{ protected member variables |
/** |
* Path to file for download |
* |
* @see HTTP_Download::setFile() |
* @access protected |
* @var string |
*/ |
var $file = ''; |
/** |
* Data for download |
* |
* @see HTTP_Download::setData() |
* @access protected |
* @var string |
*/ |
var $data = null; |
/** |
* Resource handle for download |
* |
* @see HTTP_Download::setResource() |
* @access protected |
* @var int |
*/ |
var $handle = null; |
/** |
* Whether to gzip the download |
* |
* @access protected |
* @var bool |
*/ |
var $gzip = false; |
/** |
* Whether to allow caching of the download on the clients side |
* |
* @access protected |
* @var bool |
*/ |
var $cache = true; |
/** |
* Size of download |
* |
* @access protected |
* @var int |
*/ |
var $size = 0; |
/** |
* Last modified |
* |
* @access protected |
* @var int |
*/ |
var $lastModified = 0; |
/** |
* HTTP headers |
* |
* @access protected |
* @var array |
*/ |
var $headers = array( |
'Content-Type' => 'application/x-octetstream', |
'Pragma' => 'cache', |
'Cache-Control' => 'public, must-revalidate, max-age=0', |
'Accept-Ranges' => 'bytes', |
'X-Sent-By' => 'PEAR::HTTP::Download' |
); |
/** |
* HTTP_Header |
* |
* @access protected |
* @var object |
*/ |
var $HTTP = null; |
/** |
* ETag |
* |
* @access protected |
* @var string |
*/ |
var $etag = ''; |
/** |
* Buffer Size |
* |
* @access protected |
* @var int |
*/ |
var $bufferSize = 2097152; |
/** |
* Throttle Delay |
* |
* @access protected |
* @var float |
*/ |
var $throttleDelay = 0; |
/** |
* Sent Bytes |
* |
* @access public |
* @var int |
*/ |
var $sentBytes = 0; |
// }}} |
// {{{ constructor |
/** |
* Constructor |
* |
* Set supplied parameters. |
* |
* @access public |
* @param array $params associative array of parameters |
* |
* <b>one of:</b> |
* o 'file' => path to file for download |
* o 'data' => raw data for download |
* o 'resource' => resource handle for download |
* <br/> |
* <b>and any of:</b> |
* o 'cache' => whether to allow cs caching |
* o 'gzip' => whether to gzip the download |
* o 'lastmodified' => unix timestamp |
* o 'contenttype' => content type of download |
* o 'contentdisposition' => content disposition |
* o 'buffersize' => amount of bytes to buffer |
* o 'throttledelay' => amount of secs to sleep |
* o 'cachecontrol' => cache privacy and validity |
* |
* <br /> |
* 'Content-Disposition' is not HTTP compliant, but most browsers |
* follow this header, so it was borrowed from MIME standard. |
* |
* It looks like this: <br /> |
* "Content-Disposition: attachment; filename=example.tgz". |
* |
* @see HTTP_Download::setContentDisposition() |
*/ |
function HTTP_Download($params = array()) |
{ |
$this->HTTP = &new HTTP_Header; |
$this->setParams($params); |
} |
// }}} |
// {{{ public methods |
/** |
* Set parameters |
* |
* Set supplied parameters through its accessor methods. |
* |
* @access public |
* @return mixed Returns true on success or PEAR_Error on failure. |
* @param array $params associative array of parameters |
* |
* @see HTTP_Download::HTTP_Download() |
*/ |
function setParams($params) |
{ |
foreach((array) $params as $param => $value){ |
$method = 'set'. $param; |
if (!method_exists($this, $method)) { |
return PEAR::raiseError( |
"Method '$method' doesn't exist.", |
HTTP_DOWNLOAD_E_INVALID_PARAM |
); |
} |
$e = call_user_func_array(array(&$this, $method), (array) $value); |
if (PEAR::isError($e)) { |
return $e; |
} |
} |
return true; |
} |
/** |
* Set path to file for download |
* |
* The Last-Modified header will be set to files filemtime(), actually. |
* Returns PEAR_Error (HTTP_DOWNLOAD_E_INVALID_FILE) if file doesn't exist. |
* Sends HTTP 404 status if $send_404 is set to true. |
* |
* @access public |
* @return mixed Returns true on success or PEAR_Error on failure. |
* @param string $file path to file for download |
* @param bool $send_404 whether to send HTTP/404 if |
* the file wasn't found |
*/ |
function setFile($file, $send_404 = true) |
{ |
$file = realpath($file); |
if (!is_file($file)) { |
if ($send_404) { |
$this->HTTP->sendStatusCode(404); |
} |
return PEAR::raiseError( |
"File '$file' not found.", |
HTTP_DOWNLOAD_E_INVALID_FILE |
); |
} |
$this->setLastModified(filemtime($file)); |
$this->file = $file; |
$this->size = filesize($file); |
return true; |
} |
/** |
* Set data for download |
* |
* Set $data to null if you want to unset this. |
* |
* @access public |
* @return void |
* @param $data raw data to send |
*/ |
function setData($data = null) |
{ |
$this->data = $data; |
$this->size = strlen($data); |
} |
/** |
* Set resource for download |
* |
* The resource handle supplied will be closed after sending the download. |
* Returns a PEAR_Error (HTTP_DOWNLOAD_E_INVALID_RESOURCE) if $handle |
* is no valid resource. Set $handle to null if you want to unset this. |
* |
* @access public |
* @return mixed Returns true on success or PEAR_Error on failure. |
* @param int $handle resource handle |
*/ |
function setResource($handle = null) |
{ |
if (!isset($handle)) { |
$this->handle = null; |
$this->size = 0; |
return true; |
} |
if (is_resource($handle)) { |
$this->handle = $handle; |
$filestats = fstat($handle); |
$this->size = $filestats['size']; |
return true; |
} |
return PEAR::raiseError( |
"Handle '$handle' is no valid resource.", |
HTTP_DOWNLOAD_E_INVALID_RESOURCE |
); |
} |
/** |
* Whether to gzip the download |
* |
* Returns a PEAR_Error (HTTP_DOWNLOAD_E_NO_EXT_ZLIB) |
* if ext/zlib is not available/loadable. |
* |
* @access public |
* @return mixed Returns true on success or PEAR_Error on failure. |
* @param bool $gzip whether to gzip the download |
*/ |
function setGzip($gzip = false) |
{ |
if ($gzip && !PEAR::loadExtension('zlib')){ |
return PEAR::raiseError( |
'GZIP compression (ext/zlib) not available.', |
HTTP_DOWNLOAD_E_NO_EXT_ZLIB |
); |
} |
$this->gzip = (bool) $gzip; |
return true; |
} |
/** |
* Whether to allow caching |
* |
* If set to true (default) we'll send some headers that are commonly |
* used for caching purposes like ETag, Cache-Control and Last-Modified. |
* |
* If caching is disabled, we'll send the download no matter if it |
* would actually be cached at the client side. |
* |
* @access public |
* @return void |
* @param bool $cache whether to allow caching |
*/ |
function setCache($cache = true) |
{ |
$this->cache = (bool) $cache; |
} |
/** |
* Whether to allow proxies to cache |
* |
* If set to 'private' proxies shouldn't cache the response. |
* This setting defaults to 'public' and affects only cached responses. |
* |
* @access public |
* @return bool |
* @param string $cache private or public |
* @param int $maxage maximum age of the client cache entry |
*/ |
function setCacheControl($cache = 'public', $maxage = 0) |
{ |
switch ($cache = strToLower($cache)) |
{ |
case 'private': |
case 'public': |
$this->headers['Cache-Control'] = |
$cache .', must-revalidate, max-age='. abs($maxage); |
return true; |
break; |
} |
return false; |
} |
/** |
* Set ETag |
* |
* Sets a user-defined ETag for cache-validation. The ETag is usually |
* generated by HTTP_Download through its payload information. |
* |
* @access public |
* @return void |
* @param string $etag Entity tag used for strong cache validation. |
*/ |
function setETag($etag = null) |
{ |
$this->etag = (string) $etag; |
} |
/** |
* Set Size of Buffer |
* |
* The amount of bytes specified as buffer size is the maximum amount |
* of data read at once from resources or files. The default size is 2M |
* (2097152 bytes). Be aware that if you enable gzip compression and |
* you set a very low buffer size that the actual file size may grow |
* due to added gzip headers for each sent chunk of the specified size. |
* |
* Returns PEAR_Error (HTTP_DOWNLOAD_E_INVALID_PARAM) if $size is not |
* greater than 0 bytes. |
* |
* @access public |
* @return mixed Returns true on success or PEAR_Error on failure. |
* @param int $bytes Amount of bytes to use as buffer. |
*/ |
function setBufferSize($bytes = 2097152) |
{ |
if (0 >= $bytes) { |
return PEAR::raiseError( |
'Buffer size must be greater than 0 bytes ('. $bytes .' given)', |
HTTP_DOWNLOAD_E_INVALID_PARAM); |
} |
$this->bufferSize = abs($bytes); |
return true; |
} |
/** |
* Set Throttle Delay |
* |
* Set the amount of seconds to sleep after each chunck that has been |
* sent. One can implement some sort of throttle through adjusting the |
* buffer size and the throttle delay. With the following settings |
* HTTP_Download will sleep a second after each 25 K of data sent. |
* |
* <code> |
* Array( |
* 'throttledelay' => 1, |
* 'buffersize' => 1024 * 25, |
* ) |
* </code> |
* |
* Just be aware that if gzipp'ing is enabled, decreasing the chunk size |
* too much leads to proportionally increased network traffic due to added |
* gzip header and bottom bytes around each chunk. |
* |
* @access public |
* @return void |
* @param float $seconds Amount of seconds to sleep after each |
* chunk that has been sent. |
*/ |
function setThrottleDelay($seconds = 0) |
{ |
$this->throttleDelay = abs($seconds) * 1000; |
} |
/** |
* Set "Last-Modified" |
* |
* This is usually determined by filemtime() in HTTP_Download::setFile() |
* If you set raw data for download with HTTP_Download::setData() and you |
* want do send an appropiate "Last-Modified" header, you should call this |
* method. |
* |
* @access public |
* @return void |
* @param int unix timestamp |
*/ |
function setLastModified($last_modified) |
{ |
$this->lastModified = $this->headers['Last-Modified'] = (int) $last_modified; |
} |
/** |
* Set Content-Disposition header |
* |
* @see HTTP_Download::HTTP_Download |
* |
* @access public |
* @return void |
* @param string $disposition whether to send the download |
* inline or as attachment |
* @param string $file_name the filename to display in |
* the browser's download window |
* |
* <b>Example:</b> |
* <code> |
* $HTTP_Download->setContentDisposition( |
* HTTP_DOWNLOAD_ATTACHMENT, |
* 'download.tgz' |
* ); |
* </code> |
*/ |
function setContentDisposition( $disposition = HTTP_DOWNLOAD_ATTACHMENT, |
$file_name = null) |
{ |
$cd = $disposition; |
if (isset($file_name)) { |
$cd .= '; filename="' . $file_name . '"'; |
} elseif ($this->file) { |
$cd .= '; filename="' . basename($this->file) . '"'; |
} |
$this->headers['Content-Disposition'] = $cd; |
} |
/** |
* Set content type of the download |
* |
* Default content type of the download will be 'application/x-octetstream'. |
* Returns PEAR_Error (HTTP_DOWNLOAD_E_INVALID_CONTENT_TYPE) if |
* $content_type doesn't seem to be valid. |
* |
* @access public |
* @return mixed Returns true on success or PEAR_Error on failure. |
* @param string $content_type content type of file for download |
*/ |
function setContentType($content_type = 'application/x-octetstream') |
{ |
if (!preg_match('/^[a-z]+\w*\/[a-z]+[\w.;= -]*$/', $content_type)) { |
return PEAR::raiseError( |
"Invalid content type '$content_type' supplied.", |
HTTP_DOWNLOAD_E_INVALID_CONTENT_TYPE |
); |
} |
$this->headers['Content-Type'] = $content_type; |
return true; |
} |
/** |
* Guess content type of file |
* |
* First we try to use PEAR::MIME_Type, if installed, to detect the content |
* type, else we check if ext/mime_magic is loaded and properly configured. |
* |
* Returns PEAR_Error if: |
* o if PEAR::MIME_Type failed to detect a proper content type |
* (HTTP_DOWNLOAD_E_INVALID_CONTENT_TYPE) |
* o ext/magic.mime is not installed, or not properly configured |
* (HTTP_DOWNLOAD_E_NO_EXT_MMAGIC) |
* o mime_content_type() couldn't guess content type or returned |
* a content type considered to be bogus by setContentType() |
* (HTTP_DOWNLOAD_E_INVALID_CONTENT_TYPE) |
* |
* @access public |
* @return mixed Returns true on success or PEAR_Error on failure. |
*/ |
function guessContentType() |
{ |
if (class_exists('MIME_Type') || @include_once 'MIME/Type.php') { |
if (PEAR::isError($mime_type = MIME_Type::autoDetect($this->file))) { |
return PEAR::raiseError($mime_type->getMessage(), |
HTTP_DOWNLOAD_E_INVALID_CONTENT_TYPE); |
} |
return $this->setContentType($mime_type); |
} |
if (!function_exists('mime_content_type')) { |
return PEAR::raiseError( |
'This feature requires ext/mime_magic!', |
HTTP_DOWNLOAD_E_NO_EXT_MMAGIC |
); |
} |
if (!is_file(ini_get('mime_magic.magicfile'))) { |
return PEAR::raiseError( |
'ext/mime_magic is loaded but not properly configured!', |
HTTP_DOWNLOAD_E_NO_EXT_MMAGIC |
); |
} |
if (!$content_type = @mime_content_type($this->file)) { |
return PEAR::raiseError( |
'Couldn\'t guess content type with mime_content_type().', |
HTTP_DOWNLOAD_E_INVALID_CONTENT_TYPE |
); |
} |
return $this->setContentType($content_type); |
} |
/** |
* Send |
* |
* Returns PEAR_Error if: |
* o HTTP headers were already sent (HTTP_DOWNLOAD_E_HEADERS_SENT) |
* o HTTP Range was invalid (HTTP_DOWNLOAD_E_INVALID_REQUEST) |
* |
* @access public |
* @return mixed Returns true on success or PEAR_Error on failure. |
* @param bool $autoSetContentDisposition Whether to set the |
* Content-Disposition header if it isn't already. |
*/ |
function send($autoSetContentDisposition = true) |
{ |
if (headers_sent()) { |
return PEAR::raiseError( |
'Headers already sent.', |
HTTP_DOWNLOAD_E_HEADERS_SENT |
); |
} |
if (!ini_get('safe_mode')) { |
@set_time_limit(0); |
} |
if ($autoSetContentDisposition && |
!isset($this->headers['Content-Disposition'])) { |
$this->setContentDisposition(); |
} |
if ($this->cache) { |
$this->headers['ETag'] = $this->generateETag(); |
if ($this->isCached()) { |
$this->HTTP->sendStatusCode(304); |
$this->sendHeaders(); |
return true; |
} |
} else { |
unset($this->headers['Last-Modified']); |
} |
if (ob_get_level()) { |
while (@ob_end_clean()); |
} |
if ($this->gzip) { |
@ob_start('ob_gzhandler'); |
} else { |
ob_start(); |
} |
$this->sentBytes = 0; |
if ($this->isRangeRequest()) { |
$this->HTTP->sendStatusCode(206); |
$chunks = $this->getChunks(); |
} else { |
$this->HTTP->sendStatusCode(200); |
$chunks = array(array(0, $this->size)); |
if (!$this->gzip && count(ob_list_handlers()) < 2) { |
$this->headers['Content-Length'] = $this->size; |
} |
} |
if (PEAR::isError($e = $this->sendChunks($chunks))) { |
ob_end_clean(); |
$this->HTTP->sendStatusCode(416); |
return $e; |
} |
ob_end_flush(); |
flush(); |
return true; |
} |
/** |
* Static send |
* |
* @see HTTP_Download::HTTP_Download() |
* @see HTTP_Download::send() |
* |
* @static |
* @access public |
* @return mixed Returns true on success or PEAR_Error on failure. |
* @param array $params associative array of parameters |
* @param bool $guess whether HTTP_Download::guessContentType() |
* should be called |
*/ |
function staticSend($params, $guess = false) |
{ |
$d = &new HTTP_Download(); |
$e = $d->setParams($params); |
if (PEAR::isError($e)) { |
return $e; |
} |
if ($guess) { |
$e = $d->guessContentType(); |
if (PEAR::isError($e)) { |
return $e; |
} |
} |
return $d->send(); |
} |
/** |
* Send a bunch of files or directories as an archive |
* |
* Example: |
* <code> |
* require_once 'HTTP/Download.php'; |
* HTTP_Download::sendArchive( |
* 'myArchive.tgz', |
* '/var/ftp/pub/mike', |
* HTTP_DOWNLOAD_TGZ, |
* '', |
* '/var/ftp/pub' |
* ); |
* </code> |
* |
* @see Archive_Tar::createModify() |
* @deprecated use HTTP_Download_Archive::send() |
* @static |
* @access public |
* @return mixed Returns true on success or PEAR_Error on failure. |
* @param string $name name the sent archive should have |
* @param mixed $files files/directories |
* @param string $type archive type |
* @param string $add_path path that should be prepended to the files |
* @param string $strip_path path that should be stripped from the files |
*/ |
function sendArchive( $name, |
$files, |
$type = HTTP_DOWNLOAD_TGZ, |
$add_path = '', |
$strip_path = '') |
{ |
require_once 'HTTP/Download/Archive.php'; |
return HTTP_Download_Archive::send($name, $files, $type, |
$add_path, $strip_path); |
} |
// }}} |
// {{{ protected methods |
/** |
* Generate ETag |
* |
* @access protected |
* @return string |
*/ |
function generateETag() |
{ |
if (!$this->etag) { |
if ($this->data) { |
$md5 = md5($this->data); |
} else { |
$fst = is_resource($this->handle) ? |
fstat($this->handle) : stat($this->file); |
$md5 = md5($fst['mtime'] .'='. $fst['ino'] .'='. $fst['size']); |
} |
$this->etag = '"' . $md5 . '-' . crc32($md5) . '"'; |
} |
return $this->etag; |
} |
/** |
* Send multiple chunks |
* |
* @access protected |
* @return mixed Returns true on success or PEAR_Error on failure. |
* @param array $chunks |
*/ |
function sendChunks($chunks) |
{ |
if (count($chunks) == 1) { |
return $this->sendChunk(current($chunks)); |
} |
$bound = uniqid('HTTP_DOWNLOAD-', true); |
$cType = $this->headers['Content-Type']; |
$this->headers['Content-Type'] = |
'multipart/byteranges; boundary=' . $bound; |
$this->sendHeaders(); |
foreach ($chunks as $chunk){ |
if (PEAR::isError($e = $this->sendChunk($chunk, $cType, $bound))) { |
return $e; |
} |
} |
#echo "\r\n--$bound--\r\n"; |
return true; |
} |
/** |
* Send chunk of data |
* |
* @access protected |
* @return mixed Returns true on success or PEAR_Error on failure. |
* @param array $chunk start and end offset of the chunk to send |
* @param string $cType actual content type |
* @param string $bound boundary for multipart/byteranges |
*/ |
function sendChunk($chunk, $cType = null, $bound = null) |
{ |
list($offset, $lastbyte) = $chunk; |
$length = ($lastbyte - $offset) + 1; |
if ($length < 1) { |
return PEAR::raiseError( |
"Error processing range request: $offset-$lastbyte/$length", |
HTTP_DOWNLOAD_E_INVALID_REQUEST |
); |
} |
$range = $offset . '-' . $lastbyte . '/' . $this->size; |
if (isset($cType, $bound)) { |
echo "\r\n--$bound\r\n", |
"Content-Type: $cType\r\n", |
"Content-Range: bytes $range\r\n\r\n"; |
} else { |
if ($this->isRangeRequest()) { |
$this->headers['Content-Length'] = $length; |
$this->headers['Content-Range'] = 'bytes '. $range; |
} |
$this->sendHeaders(); |
} |
if ($this->data) { |
while (($length -= $this->bufferSize) > 0) { |
$this->flush(substr($this->data, $offset, $this->bufferSize)); |
$this->throttleDelay and $this->sleep(); |
$offset += $this->bufferSize; |
} |
if ($length) { |
$this->flush(substr($this->data, $offset, $this->bufferSize + $length)); |
} |
} else { |
if (!is_resource($this->handle)) { |
$this->handle = fopen($this->file, 'rb'); |
} |
fseek($this->handle, $offset); |
while (($length -= $this->bufferSize) > 0) { |
$this->flush(fread($this->handle, $this->bufferSize)); |
$this->throttleDelay and $this->sleep(); |
} |
if ($length) { |
$this->flush(fread($this->handle, $this->bufferSize + $length)); |
} |
} |
return true; |
} |
/** |
* Get chunks to send |
* |
* @access protected |
* @return array |
*/ |
function getChunks() |
{ |
$parts = array(); |
foreach (explode(',', $this->getRanges()) as $chunk){ |
list($o, $e) = explode('-', $chunk); |
if ($e >= $this->size || (empty($e) && $e !== 0 && $e !== '0')) { |
$e = $this->size - 1; |
} |
if (empty($o) && $o !== 0 && $o !== '0') { |
$o = $this->size - $e; |
$e = $this->size - 1; |
} |
$parts[] = array($o, $e); |
} |
return $parts; |
} |
/** |
* Check if range is requested |
* |
* @access protected |
* @return bool |
*/ |
function isRangeRequest() |
{ |
if (!isset($_SERVER['HTTP_RANGE'])) { |
return false; |
} |
return $this->isValidRange(); |
} |
/** |
* Get range request |
* |
* @access protected |
* @return array |
*/ |
function getRanges() |
{ |
return preg_match('/^bytes=((\d*-\d*,? ?)+)$/', |
@$_SERVER['HTTP_RANGE'], $matches) ? $matches[1] : array(); |
} |
/** |
* Check if entity is cached |
* |
* @access protected |
* @return bool |
*/ |
function isCached() |
{ |
return ( |
(isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && |
$this->lastModified == strtotime(current($a = explode( |
';', $_SERVER['HTTP_IF_MODIFIED_SINCE'])))) || |
(isset($_SERVER['HTTP_IF_NONE_MATCH']) && |
$this->compareAsterisk('HTTP_IF_NONE_MATCH', $this->etag)) |
); |
} |
/** |
* Check if entity hasn't changed |
* |
* @access protected |
* @return bool |
*/ |
function isValidRange() |
{ |
if (isset($_SERVER['HTTP_IF_MATCH']) && |
!$this->compareAsterisk('HTTP_IF_MATCH', $this->etag)) { |
return false; |
} |
if (isset($_SERVER['HTTP_IF_RANGE']) && |
$_SERVER['HTTP_IF_RANGE'] !== $this->etag && |
strtotime($_SERVER['HTTP_IF_RANGE']) !== $this->lastModified) { |
return false; |
} |
if (isset($_SERVER['HTTP_IF_UNMODIFIED_SINCE'])) { |
$lm = current($a = explode(';', $_SERVER['HTTP_IF_UNMODIFIED_SINCE'])); |
if (strtotime($lm) !== $this->lastModified) { |
return false; |
} |
} |
if (isset($_SERVER['HTTP_UNLESS_MODIFIED_SINCE'])) { |
$lm = current($a = explode(';', $_SERVER['HTTP_UNLESS_MODIFIED_SINCE'])); |
if (strtotime($lm) !== $this->lastModified) { |
return false; |
} |
} |
return true; |
} |
/** |
* Compare against an asterisk or check for equality |
* |
* @access protected |
* @return bool |
* @param string key for the $_SERVER array |
* @param string string to compare |
*/ |
function compareAsterisk($svar, $compare) |
{ |
foreach (array_map('trim', explode(',', $_SERVER[$svar])) as $request) { |
if ($request === '*' || $request === $compare) { |
return true; |
} |
} |
return false; |
} |
/** |
* Send HTTP headers |
* |
* @access protected |
* @return void |
*/ |
function sendHeaders() |
{ |
foreach ($this->headers as $header => $value) { |
$this->HTTP->setHeader($header, $value); |
} |
$this->HTTP->sendHeaders(); |
/* NSAPI won't output anything if we did this */ |
if (strncasecmp(PHP_SAPI, 'nsapi', 5)) { |
ob_flush(); |
flush(); |
} |
} |
/** |
* Flush |
* |
* @access protected |
* @return void |
* @param string $data |
*/ |
function flush($data = '') |
{ |
if ($dlen = strlen($data)) { |
$this->sentBytes += $dlen; |
echo $data; |
} |
ob_flush(); |
flush(); |
} |
/** |
* Sleep |
* |
* @access protected |
* @return void |
*/ |
function sleep() |
{ |
if (OS_WINDOWS) { |
com_message_pump($this->throttleDelay); |
} else { |
usleep($this->throttleDelay * 1000); |
} |
} |
// }}} |
} |
?> |
/trunk/jrest/lib/JSON.php |
---|
New file |
0,0 → 1,806 |
<?php |
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ |
/** |
* Converts to and from JSON format. |
* |
* JSON (JavaScript Object Notation) is a lightweight data-interchange |
* format. It is easy for humans to read and write. It is easy for machines |
* to parse and generate. It is based on a subset of the JavaScript |
* Programming Language, Standard ECMA-262 3rd Edition - December 1999. |
* This feature can also be found in Python. JSON is a text format that is |
* completely language independent but uses conventions that are familiar |
* to programmers of the C-family of languages, including C, C++, C#, Java, |
* JavaScript, Perl, TCL, and many others. These properties make JSON an |
* ideal data-interchange language. |
* |
* This package provides a simple encoder and decoder for JSON notation. It |
* is intended for use with client-side Javascript applications that make |
* use of HTTPRequest to perform server communication functions - data can |
* be encoded into JSON notation for use in a client-side javascript, or |
* decoded from incoming Javascript requests. JSON format is native to |
* Javascript, and can be directly eval()'ed with no further parsing |
* overhead |
* |
* All strings should be in ASCII or UTF-8 format! |
* |
* LICENSE: 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. |
* |
* THIS SOFTWARE IS PROVIDED ``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 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 |
* @package Services_JSON |
* @author Michal Migurski <mike-json@teczno.com> |
* @author Matt Knapp <mdknapp[at]gmail[dot]com> |
* @author Brett Stimmerman <brettstimmerman[at]gmail[dot]com> |
* @copyright 2005 Michal Migurski |
* @version CVS: $Id$ |
* @license http://www.opensource.org/licenses/bsd-license.php |
* @link http://pear.php.net/pepr/pepr-proposal-show.php?id=198 |
*/ |
/** |
* Marker constant for Services_JSON::decode(), used to flag stack state |
*/ |
define('SERVICES_JSON_SLICE', 1); |
/** |
* Marker constant for Services_JSON::decode(), used to flag stack state |
*/ |
define('SERVICES_JSON_IN_STR', 2); |
/** |
* Marker constant for Services_JSON::decode(), used to flag stack state |
*/ |
define('SERVICES_JSON_IN_ARR', 3); |
/** |
* Marker constant for Services_JSON::decode(), used to flag stack state |
*/ |
define('SERVICES_JSON_IN_OBJ', 4); |
/** |
* Marker constant for Services_JSON::decode(), used to flag stack state |
*/ |
define('SERVICES_JSON_IN_CMT', 5); |
/** |
* Behavior switch for Services_JSON::decode() |
*/ |
define('SERVICES_JSON_LOOSE_TYPE', 16); |
/** |
* Behavior switch for Services_JSON::decode() |
*/ |
define('SERVICES_JSON_SUPPRESS_ERRORS', 32); |
/** |
* Converts to and from JSON format. |
* |
* Brief example of use: |
* |
* <code> |
* // create a new instance of Services_JSON |
* $json = new Services_JSON(); |
* |
* // convert a complexe value to JSON notation, and send it to the browser |
* $value = array('foo', 'bar', array(1, 2, 'baz'), array(3, array(4))); |
* $output = $json->encode($value); |
* |
* print($output); |
* // prints: ["foo","bar",[1,2,"baz"],[3,[4]]] |
* |
* // accept incoming POST data, assumed to be in JSON notation |
* $input = file_get_contents('php://input', 1000000); |
* $value = $json->decode($input); |
* </code> |
*/ |
class Services_JSON |
{ |
/** |
* constructs a new JSON instance |
* |
* @param int $use object behavior flags; combine with boolean-OR |
* |
* possible values: |
* - SERVICES_JSON_LOOSE_TYPE: loose typing. |
* "{...}" syntax creates associative arrays |
* instead of objects in decode(). |
* - SERVICES_JSON_SUPPRESS_ERRORS: error suppression. |
* Values which can't be encoded (e.g. resources) |
* appear as NULL instead of throwing errors. |
* By default, a deeply-nested resource will |
* bubble up with an error, so all return values |
* from encode() should be checked with isError() |
*/ |
function Services_JSON($use = 0) |
{ |
$this->use = $use; |
} |
/** |
* convert a string from one UTF-16 char to one UTF-8 char |
* |
* Normally should be handled by mb_convert_encoding, but |
* provides a slower PHP-only method for installations |
* that lack the multibye string extension. |
* |
* @param string $utf16 UTF-16 character |
* @return string UTF-8 character |
* @access private |
*/ |
function utf162utf8($utf16) |
{ |
// oh please oh please oh please oh please oh please |
if(function_exists('mb_convert_encoding')) { |
return mb_convert_encoding($utf16, 'UTF-8', 'UTF-16'); |
} |
$bytes = (ord($utf16{0}) << 8) | ord($utf16{1}); |
switch(true) { |
case ((0x7F & $bytes) == $bytes): |
// this case should never be reached, because we are in ASCII range |
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
return chr(0x7F & $bytes); |
case (0x07FF & $bytes) == $bytes: |
// return a 2-byte UTF-8 character |
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
return chr(0xC0 | (($bytes >> 6) & 0x1F)) |
. chr(0x80 | ($bytes & 0x3F)); |
case (0xFFFF & $bytes) == $bytes: |
// return a 3-byte UTF-8 character |
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
return chr(0xE0 | (($bytes >> 12) & 0x0F)) |
. chr(0x80 | (($bytes >> 6) & 0x3F)) |
. chr(0x80 | ($bytes & 0x3F)); |
} |
// ignoring UTF-32 for now, sorry |
return ''; |
} |
/** |
* convert a string from one UTF-8 char to one UTF-16 char |
* |
* Normally should be handled by mb_convert_encoding, but |
* provides a slower PHP-only method for installations |
* that lack the multibye string extension. |
* |
* @param string $utf8 UTF-8 character |
* @return string UTF-16 character |
* @access private |
*/ |
function utf82utf16($utf8) |
{ |
// oh please oh please oh please oh please oh please |
if(function_exists('mb_convert_encoding')) { |
return mb_convert_encoding($utf8, 'UTF-16', 'UTF-8'); |
} |
switch(strlen($utf8)) { |
case 1: |
// this case should never be reached, because we are in ASCII range |
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
return $utf8; |
case 2: |
// return a UTF-16 character from a 2-byte UTF-8 char |
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
return chr(0x07 & (ord($utf8{0}) >> 2)) |
. chr((0xC0 & (ord($utf8{0}) << 6)) |
| (0x3F & ord($utf8{1}))); |
case 3: |
// return a UTF-16 character from a 3-byte UTF-8 char |
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
return chr((0xF0 & (ord($utf8{0}) << 4)) |
| (0x0F & (ord($utf8{1}) >> 2))) |
. chr((0xC0 & (ord($utf8{1}) << 6)) |
| (0x7F & ord($utf8{2}))); |
} |
// ignoring UTF-32 for now, sorry |
return ''; |
} |
/** |
* encodes an arbitrary variable into JSON format |
* |
* @param mixed $var any number, boolean, string, array, or object to be encoded. |
* see argument 1 to Services_JSON() above for array-parsing behavior. |
* if var is a strng, note that encode() always expects it |
* to be in ASCII or UTF-8 format! |
* |
* @return mixed JSON string representation of input var or an error if a problem occurs |
* @access public |
*/ |
function encode($var) |
{ |
switch (gettype($var)) { |
case 'boolean': |
return $var ? 'true' : 'false'; |
case 'NULL': |
return 'null'; |
case 'integer': |
return (int) $var; |
case 'double': |
case 'float': |
return (float) $var; |
case 'string': |
// STRINGS ARE EXPECTED TO BE IN ASCII OR UTF-8 FORMAT |
$ascii = ''; |
$strlen_var = strlen($var); |
/* |
* Iterate over every character in the string, |
* escaping with a slash or encoding to UTF-8 where necessary |
*/ |
for ($c = 0; $c < $strlen_var; ++$c) { |
$ord_var_c = ord($var{$c}); |
switch (true) { |
case $ord_var_c == 0x08: |
$ascii .= '\b'; |
break; |
case $ord_var_c == 0x09: |
$ascii .= '\t'; |
break; |
case $ord_var_c == 0x0A: |
$ascii .= '\n'; |
break; |
case $ord_var_c == 0x0C: |
$ascii .= '\f'; |
break; |
case $ord_var_c == 0x0D: |
$ascii .= '\r'; |
break; |
case $ord_var_c == 0x22: |
case $ord_var_c == 0x2F: |
case $ord_var_c == 0x5C: |
// double quote, slash, slosh |
$ascii .= '\\'.$var{$c}; |
break; |
case (($ord_var_c >= 0x20) && ($ord_var_c <= 0x7F)): |
// characters U-00000000 - U-0000007F (same as ASCII) |
$ascii .= $var{$c}; |
break; |
case (($ord_var_c & 0xE0) == 0xC0): |
// characters U-00000080 - U-000007FF, mask 110XXXXX |
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
$char = pack('C*', $ord_var_c, ord($var{$c + 1})); |
$c += 1; |
$utf16 = $this->utf82utf16($char); |
$ascii .= sprintf('\u%04s', bin2hex($utf16)); |
break; |
case (($ord_var_c & 0xF0) == 0xE0): |
// characters U-00000800 - U-0000FFFF, mask 1110XXXX |
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
$char = pack('C*', $ord_var_c, |
ord($var{$c + 1}), |
ord($var{$c + 2})); |
$c += 2; |
$utf16 = $this->utf82utf16($char); |
$ascii .= sprintf('\u%04s', bin2hex($utf16)); |
break; |
case (($ord_var_c & 0xF8) == 0xF0): |
// characters U-00010000 - U-001FFFFF, mask 11110XXX |
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
$char = pack('C*', $ord_var_c, |
ord($var{$c + 1}), |
ord($var{$c + 2}), |
ord($var{$c + 3})); |
$c += 3; |
$utf16 = $this->utf82utf16($char); |
$ascii .= sprintf('\u%04s', bin2hex($utf16)); |
break; |
case (($ord_var_c & 0xFC) == 0xF8): |
// characters U-00200000 - U-03FFFFFF, mask 111110XX |
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
$char = pack('C*', $ord_var_c, |
ord($var{$c + 1}), |
ord($var{$c + 2}), |
ord($var{$c + 3}), |
ord($var{$c + 4})); |
$c += 4; |
$utf16 = $this->utf82utf16($char); |
$ascii .= sprintf('\u%04s', bin2hex($utf16)); |
break; |
case (($ord_var_c & 0xFE) == 0xFC): |
// characters U-04000000 - U-7FFFFFFF, mask 1111110X |
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
$char = pack('C*', $ord_var_c, |
ord($var{$c + 1}), |
ord($var{$c + 2}), |
ord($var{$c + 3}), |
ord($var{$c + 4}), |
ord($var{$c + 5})); |
$c += 5; |
$utf16 = $this->utf82utf16($char); |
$ascii .= sprintf('\u%04s', bin2hex($utf16)); |
break; |
} |
} |
return '"'.$ascii.'"'; |
case 'array': |
/* |
* As per JSON spec if any array key is not an integer |
* we must treat the the whole array as an object. We |
* also try to catch a sparsely populated associative |
* array with numeric keys here because some JS engines |
* will create an array with empty indexes up to |
* max_index which can cause memory issues and because |
* the keys, which may be relevant, will be remapped |
* otherwise. |
* |
* As per the ECMA and JSON specification an object may |
* have any string as a property. Unfortunately due to |
* a hole in the ECMA specification if the key is a |
* ECMA reserved word or starts with a digit the |
* parameter is only accessible using ECMAScript's |
* bracket notation. |
*/ |
// treat as a JSON object |
if (is_array($var) && count($var) && (array_keys($var) !== range(0, sizeof($var) - 1))) { |
$properties = array_map(array($this, 'name_value'), |
array_keys($var), |
array_values($var)); |
foreach($properties as $property) { |
if(Services_JSON::isError($property)) { |
return $property; |
} |
} |
return '{' . join(',', $properties) . '}'; |
} |
// treat it like a regular array |
$elements = array_map(array($this, 'encode'), $var); |
foreach($elements as $element) { |
if(Services_JSON::isError($element)) { |
return $element; |
} |
} |
return '[' . join(',', $elements) . ']'; |
case 'object': |
$vars = get_object_vars($var); |
$properties = array_map(array($this, 'name_value'), |
array_keys($vars), |
array_values($vars)); |
foreach($properties as $property) { |
if(Services_JSON::isError($property)) { |
return $property; |
} |
} |
return '{' . join(',', $properties) . '}'; |
default: |
return ($this->use & SERVICES_JSON_SUPPRESS_ERRORS) |
? 'null' |
: new Services_JSON_Error(gettype($var)." can not be encoded as JSON string"); |
} |
} |
/** |
* array-walking function for use in generating JSON-formatted name-value pairs |
* |
* @param string $name name of key to use |
* @param mixed $value reference to an array element to be encoded |
* |
* @return string JSON-formatted name-value pair, like '"name":value' |
* @access private |
*/ |
function name_value($name, $value) |
{ |
$encoded_value = $this->encode($value); |
if(Services_JSON::isError($encoded_value)) { |
return $encoded_value; |
} |
return $this->encode(strval($name)) . ':' . $encoded_value; |
} |
/** |
* reduce a string by removing leading and trailing comments and whitespace |
* |
* @param $str string string value to strip of comments and whitespace |
* |
* @return string string value stripped of comments and whitespace |
* @access private |
*/ |
function reduce_string($str) |
{ |
$str = preg_replace(array( |
// eliminate single line comments in '// ...' form |
'#^\s*//(.+)$#m', |
// eliminate multi-line comments in '/* ... */' form, at start of string |
'#^\s*/\*(.+)\*/#Us', |
// eliminate multi-line comments in '/* ... */' form, at end of string |
'#/\*(.+)\*/\s*$#Us' |
), '', $str); |
// eliminate extraneous space |
return trim($str); |
} |
/** |
* decodes a JSON string into appropriate variable |
* |
* @param string $str JSON-formatted string |
* |
* @return mixed number, boolean, string, array, or object |
* corresponding to given JSON input string. |
* See argument 1 to Services_JSON() above for object-output behavior. |
* Note that decode() always returns strings |
* in ASCII or UTF-8 format! |
* @access public |
*/ |
function decode($str) |
{ |
$str = $this->reduce_string($str); |
switch (strtolower($str)) { |
case 'true': |
return true; |
case 'false': |
return false; |
case 'null': |
return null; |
default: |
$m = array(); |
if (is_numeric($str)) { |
// Lookie-loo, it's a number |
// This would work on its own, but I'm trying to be |
// good about returning integers where appropriate: |
// return (float)$str; |
// Return float or int, as appropriate |
return ((float)$str == (integer)$str) |
? (integer)$str |
: (float)$str; |
} elseif (preg_match('/^("|\').*(\1)$/s', $str, $m) && $m[1] == $m[2]) { |
// STRINGS RETURNED IN UTF-8 FORMAT |
$delim = substr($str, 0, 1); |
$chrs = substr($str, 1, -1); |
$utf8 = ''; |
$strlen_chrs = strlen($chrs); |
for ($c = 0; $c < $strlen_chrs; ++$c) { |
$substr_chrs_c_2 = substr($chrs, $c, 2); |
$ord_chrs_c = ord($chrs{$c}); |
switch (true) { |
case $substr_chrs_c_2 == '\b': |
$utf8 .= chr(0x08); |
++$c; |
break; |
case $substr_chrs_c_2 == '\t': |
$utf8 .= chr(0x09); |
++$c; |
break; |
case $substr_chrs_c_2 == '\n': |
$utf8 .= chr(0x0A); |
++$c; |
break; |
case $substr_chrs_c_2 == '\f': |
$utf8 .= chr(0x0C); |
++$c; |
break; |
case $substr_chrs_c_2 == '\r': |
$utf8 .= chr(0x0D); |
++$c; |
break; |
case $substr_chrs_c_2 == '\\"': |
case $substr_chrs_c_2 == '\\\'': |
case $substr_chrs_c_2 == '\\\\': |
case $substr_chrs_c_2 == '\\/': |
if (($delim == '"' && $substr_chrs_c_2 != '\\\'') || |
($delim == "'" && $substr_chrs_c_2 != '\\"')) { |
$utf8 .= $chrs{++$c}; |
} |
break; |
case preg_match('/\\\u[0-9A-F]{4}/i', substr($chrs, $c, 6)): |
// single, escaped unicode character |
$utf16 = chr(hexdec(substr($chrs, ($c + 2), 2))) |
. chr(hexdec(substr($chrs, ($c + 4), 2))); |
$utf8 .= $this->utf162utf8($utf16); |
$c += 5; |
break; |
case ($ord_chrs_c >= 0x20) && ($ord_chrs_c <= 0x7F): |
$utf8 .= $chrs{$c}; |
break; |
case ($ord_chrs_c & 0xE0) == 0xC0: |
// characters U-00000080 - U-000007FF, mask 110XXXXX |
//see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
$utf8 .= substr($chrs, $c, 2); |
++$c; |
break; |
case ($ord_chrs_c & 0xF0) == 0xE0: |
// characters U-00000800 - U-0000FFFF, mask 1110XXXX |
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
$utf8 .= substr($chrs, $c, 3); |
$c += 2; |
break; |
case ($ord_chrs_c & 0xF8) == 0xF0: |
// characters U-00010000 - U-001FFFFF, mask 11110XXX |
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
$utf8 .= substr($chrs, $c, 4); |
$c += 3; |
break; |
case ($ord_chrs_c & 0xFC) == 0xF8: |
// characters U-00200000 - U-03FFFFFF, mask 111110XX |
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
$utf8 .= substr($chrs, $c, 5); |
$c += 4; |
break; |
case ($ord_chrs_c & 0xFE) == 0xFC: |
// characters U-04000000 - U-7FFFFFFF, mask 1111110X |
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
$utf8 .= substr($chrs, $c, 6); |
$c += 5; |
break; |
} |
} |
return $utf8; |
} elseif (preg_match('/^\[.*\]$/s', $str) || preg_match('/^\{.*\}$/s', $str)) { |
// array, or object notation |
if ($str{0} == '[') { |
$stk = array(SERVICES_JSON_IN_ARR); |
$arr = array(); |
} else { |
if ($this->use & SERVICES_JSON_LOOSE_TYPE) { |
$stk = array(SERVICES_JSON_IN_OBJ); |
$obj = array(); |
} else { |
$stk = array(SERVICES_JSON_IN_OBJ); |
$obj = new stdClass(); |
} |
} |
array_push($stk, array('what' => SERVICES_JSON_SLICE, |
'where' => 0, |
'delim' => false)); |
$chrs = substr($str, 1, -1); |
$chrs = $this->reduce_string($chrs); |
if ($chrs == '') { |
if (reset($stk) == SERVICES_JSON_IN_ARR) { |
return $arr; |
} else { |
return $obj; |
} |
} |
//print("\nparsing {$chrs}\n"); |
$strlen_chrs = strlen($chrs); |
for ($c = 0; $c <= $strlen_chrs; ++$c) { |
$top = end($stk); |
$substr_chrs_c_2 = substr($chrs, $c, 2); |
if (($c == $strlen_chrs) || (($chrs{$c} == ',') && ($top['what'] == SERVICES_JSON_SLICE))) { |
// found a comma that is not inside a string, array, etc., |
// OR we've reached the end of the character list |
$slice = substr($chrs, $top['where'], ($c - $top['where'])); |
array_push($stk, array('what' => SERVICES_JSON_SLICE, 'where' => ($c + 1), 'delim' => false)); |
//print("Found split at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n"); |
if (reset($stk) == SERVICES_JSON_IN_ARR) { |
// we are in an array, so just push an element onto the stack |
array_push($arr, $this->decode($slice)); |
} elseif (reset($stk) == SERVICES_JSON_IN_OBJ) { |
// we are in an object, so figure |
// out the property name and set an |
// element in an associative array, |
// for now |
$parts = array(); |
if (preg_match('/^\s*(["\'].*[^\\\]["\'])\s*:\s*(\S.*),?$/Uis', $slice, $parts)) { |
// "name":value pair |
$key = $this->decode($parts[1]); |
$val = $this->decode($parts[2]); |
if ($this->use & SERVICES_JSON_LOOSE_TYPE) { |
$obj[$key] = $val; |
} else { |
$obj->$key = $val; |
} |
} elseif (preg_match('/^\s*(\w+)\s*:\s*(\S.*),?$/Uis', $slice, $parts)) { |
// name:value pair, where name is unquoted |
$key = $parts[1]; |
$val = $this->decode($parts[2]); |
if ($this->use & SERVICES_JSON_LOOSE_TYPE) { |
$obj[$key] = $val; |
} else { |
$obj->$key = $val; |
} |
} |
} |
} elseif ((($chrs{$c} == '"') || ($chrs{$c} == "'")) && ($top['what'] != SERVICES_JSON_IN_STR)) { |
// found a quote, and we are not inside a string |
array_push($stk, array('what' => SERVICES_JSON_IN_STR, 'where' => $c, 'delim' => $chrs{$c})); |
//print("Found start of string at {$c}\n"); |
} elseif (($chrs{$c} == $top['delim']) && |
($top['what'] == SERVICES_JSON_IN_STR) && |
((strlen(substr($chrs, 0, $c)) - strlen(rtrim(substr($chrs, 0, $c), '\\'))) % 2 != 1)) { |
// found a quote, we're in a string, and it's not escaped |
// we know that it's not escaped becase there is _not_ an |
// odd number of backslashes at the end of the string so far |
array_pop($stk); |
//print("Found end of string at {$c}: ".substr($chrs, $top['where'], (1 + 1 + $c - $top['where']))."\n"); |
} elseif (($chrs{$c} == '[') && |
in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) { |
// found a left-bracket, and we are in an array, object, or slice |
array_push($stk, array('what' => SERVICES_JSON_IN_ARR, 'where' => $c, 'delim' => false)); |
//print("Found start of array at {$c}\n"); |
} elseif (($chrs{$c} == ']') && ($top['what'] == SERVICES_JSON_IN_ARR)) { |
// found a right-bracket, and we're in an array |
array_pop($stk); |
//print("Found end of array at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n"); |
} elseif (($chrs{$c} == '{') && |
in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) { |
// found a left-brace, and we are in an array, object, or slice |
array_push($stk, array('what' => SERVICES_JSON_IN_OBJ, 'where' => $c, 'delim' => false)); |
//print("Found start of object at {$c}\n"); |
} elseif (($chrs{$c} == '}') && ($top['what'] == SERVICES_JSON_IN_OBJ)) { |
// found a right-brace, and we're in an object |
array_pop($stk); |
//print("Found end of object at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n"); |
} elseif (($substr_chrs_c_2 == '/*') && |
in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) { |
// found a comment start, and we are in an array, object, or slice |
array_push($stk, array('what' => SERVICES_JSON_IN_CMT, 'where' => $c, 'delim' => false)); |
$c++; |
//print("Found start of comment at {$c}\n"); |
} elseif (($substr_chrs_c_2 == '*/') && ($top['what'] == SERVICES_JSON_IN_CMT)) { |
// found a comment end, and we're in one now |
array_pop($stk); |
$c++; |
for ($i = $top['where']; $i <= $c; ++$i) |
$chrs = substr_replace($chrs, ' ', $i, 1); |
//print("Found end of comment at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n"); |
} |
} |
if (reset($stk) == SERVICES_JSON_IN_ARR) { |
return $arr; |
} elseif (reset($stk) == SERVICES_JSON_IN_OBJ) { |
return $obj; |
} |
} |
} |
} |
/** |
* @todo Ultimately, this should just call PEAR::isError() |
*/ |
function isError($data, $code = null) |
{ |
if (class_exists('pear')) { |
return PEAR::isError($data, $code); |
} elseif (is_object($data) && (get_class($data) == 'services_json_error' || |
is_subclass_of($data, 'services_json_error'))) { |
return true; |
} |
return false; |
} |
} |
if (class_exists('PEAR_Error')) { |
class Services_JSON_Error extends PEAR_Error |
{ |
function Services_JSON_Error($message = 'unknown error', $code = null, |
$mode = null, $options = null, $userinfo = null) |
{ |
parent::PEAR_Error($message, $code, $mode, $options, $userinfo); |
} |
} |
} else { |
/** |
* @todo Ultimately, this class shall be descended from PEAR_Error |
*/ |
class Services_JSON_Error |
{ |
function Services_JSON_Error($message = 'unknown error', $code = null, |
$mode = null, $options = null, $userinfo = null) |
{ |
} |
} |
} |
?> |
/trunk/jrest/lib/PDF.php |
---|
New file |
0,0 → 1,3001 |
<?php |
/** |
* File_PDF:: |
* |
* The File_PDF:: class provides a PHP-only implementation of a PDF library. |
* No external libs or PHP extensions are required. |
* |
* Based on the FPDF class by Olivier Plathey (http://www.fpdf.org). |
* |
* Copyright 2001-2003 Olivier Plathey <olivier@fpdf.org> |
* Copyright 2003-2007 The Horde Project (http://www.horde.org/) |
* |
* See the enclosed file COPYING for license information (LGPL). If you |
* did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. |
* |
* $Horde: framework/File_PDF/PDF.php,v 1.48 2007/01/05 13:12:21 jan Exp $ |
* |
* @author Olivier Plathey <olivier@fpdf.org> |
* @author Marko Djukic <marko@oblo.com> |
* @author Jan Schneider <jan@horde.org> |
* @package File_PDF |
* @category Fileformats |
*/ |
class File_PDF { |
/** |
* Current page number. |
* |
* @var integer |
*/ |
var $_page = 0; |
/** |
* Current object number. |
* |
* @var integer |
*/ |
var $_n = 2; |
/** |
* Array of object offsets. |
* |
* @var array |
*/ |
var $_offsets = array(); |
/** |
* Buffer holding in-memory PDF. |
* |
* @var string |
*/ |
var $_buffer = ''; |
/** |
* Array containing the pages. |
* |
* @var array |
*/ |
var $_pages = array(); |
/** |
* Current document state. |
* 0 - initial state |
* 1 - document opened |
* 2 - page opened |
* 3 - document closed |
* |
* @var integer |
*/ |
var $_state = 0; |
/** |
* Flag indicating if PDF file is to be compressed or not. |
* |
* @var boolean |
*/ |
var $_compress; |
/** |
* The default page orientation. |
* |
* @var string |
*/ |
var $_default_orientation; |
/** |
* The current page orientation. |
* |
* @var string |
*/ |
var $_current_orientation; |
/** |
* Array indicating orientation changes. |
* |
* @var array |
*/ |
var $_orientation_changes = array(); |
/** |
* Current width of page format in points. |
* |
* @var float |
*/ |
var $fwPt; |
/** |
* Current height of page format in points. |
* |
* @var float |
*/ |
var $fhPt; |
/** |
* Current width of page format in user units. |
* |
* @var float |
*/ |
var $fw; |
/** |
* Current height of page format in user units. |
* |
* @var float |
*/ |
var $fh; |
/** |
* Current width of page in points. |
* |
* @var float |
*/ |
var $wPt; |
/** |
* Current height of page in points. |
* |
* @var float |
*/ |
var $hPt; |
/** |
* Current width of page in user units |
* |
* @var float |
*/ |
var $w; |
/** |
* Current height of page in user units |
* |
* @var float |
*/ |
var $h; |
/** |
* Scale factor (number of points in user units). |
* |
* @var float |
*/ |
var $_scale; |
/** |
* Left page margin size. |
* |
* @var float |
*/ |
var $_left_margin; |
/** |
* Top page margin size. |
* |
* @var float |
*/ |
var $_top_margin; |
/** |
* Right page margin size. |
* |
* @var float |
*/ |
var $_right_margin; |
/** |
* Break page margin size, the bottom margin which triggers a page break. |
* |
* @var float |
*/ |
var $_break_margin; |
/** |
* Cell margin size. |
* |
* @var float |
*/ |
var $_cell_margin; |
/** |
* The current horizontal position for cell positioning. |
* Value is set in user units and is calculated from the top left corner |
* as origin. |
* |
* @var float |
*/ |
var $x; |
/** |
* The current vertical position for cell positioning. |
* Value is set in user units and is calculated from the top left corner |
* as origin. |
* |
* @var float |
*/ |
var $y; |
/** |
* The height of the last cell printed. |
* |
* @var float |
*/ |
var $_last_height; |
/** |
* Line width in user units. |
* |
* @var float |
*/ |
var $_line_width; |
/** |
* An array of standard font names. |
* |
* @var array |
*/ |
var $_core_fonts = array('courier' => 'Courier', |
'courierB' => 'Courier-Bold', |
'courierI' => 'Courier-Oblique', |
'courierBI' => 'Courier-BoldOblique', |
'helvetica' => 'Helvetica', |
'helveticaB' => 'Helvetica-Bold', |
'helveticaI' => 'Helvetica-Oblique', |
'helveticaBI' => 'Helvetica-BoldOblique', |
'times' => 'Times-Roman', |
'timesB' => 'Times-Bold', |
'timesI' => 'Times-Italic', |
'timesBI' => 'Times-BoldItalic', |
'symbol' => 'Symbol', |
'zapfdingbats' => 'ZapfDingbats'); |
/** |
* An array of used fonts. |
* |
* @var array |
*/ |
var $_fonts = array(); |
/** |
* An array of font files. |
* |
* @var array |
*/ |
var $_font_files = array(); |
/** |
* An array of encoding differences. |
* |
* @var array |
*/ |
var $_diffs = array(); |
/** |
* An array of used images. |
* |
* @var array |
*/ |
var $_images = array(); |
/** |
* An array of links in pages. |
* |
* @var array |
*/ |
var $_page_links; |
/** |
* An array of internal links. |
* |
* @var array |
*/ |
var $_links = array(); |
/** |
* Current font family. |
* |
* @var string |
*/ |
var $_font_family = ''; |
/** |
* Current font style. |
* |
* @var string |
*/ |
var $_font_style = ''; |
/** |
* Underlining flag. |
* |
* @var boolean |
*/ |
var $_underline = false; |
/** |
* An array containing current font info. |
* |
* @var array |
*/ |
var $_current_font; |
/** |
* Current font size in points. |
* |
* @var float |
*/ |
var $_font_size_pt = 12; |
/** |
* Current font size in user units. |
* |
* @var float |
*/ |
var $_font_size; |
/** |
* Commands for filling color. |
* |
* @var string |
*/ |
var $_fill_color = '0 g'; |
/** |
* Commands for text color. |
* |
* @var string |
*/ |
var $_text_color = '0 g'; |
/** |
* Whether text color is different from fill color. |
* |
* @var boolean |
*/ |
var $_color_flag = false; |
/** |
* Commands for drawing color. |
* |
* @var string |
*/ |
var $_draw_color = '0 G'; |
/** |
* Word spacing. |
* |
* @var integer |
*/ |
var $_word_spacing = 0; |
/** |
* Automatic page breaking. |
* |
* @var boolean |
*/ |
var $_auto_page_break; |
/** |
* Threshold used to trigger page breaks. |
* |
* @var float |
*/ |
var $_page_break_trigger; |
/** |
* Flag set when processing footer. |
* |
* @var boolean |
*/ |
var $_in_footer = false; |
/** |
* Zoom display mode. |
* |
* @var string |
*/ |
var $_zoom_mode; |
/** |
* Layout display mode. |
* |
* @var string |
*/ |
var $_layout_mode; |
/** |
* An array containing the document info, consisting of: |
* - title |
* - subject |
* - author |
* - keywords |
* - creator |
* |
* @var array |
*/ |
var $_info = array(); |
/** |
* Alias for total number of pages. |
* |
* @var string |
*/ |
var $_alias_nb_pages = '{nb}'; |
/** |
* Attempts to return a conrete PDF instance. It allows to set up the page |
* format, the orientation and the units of measurement used in all the |
* methods (except for the font sizes). |
* |
* Example:<pre> |
* $pdf = &File_PDF::factory(array('orientation' => 'P', |
* 'unit' => 'mm', |
* 'format' => 'A4'));</pre> |
* |
* @param array $params A hash with parameters for the created PDF object. |
* Possible parameters are: |
* orientation - Default page orientation. Possible |
* values are (case insensitive): |
* <pre> |
* - P or Portrait (default) |
* - L or Landscape |
* </pre> |
* unit - User measure units. Possible values values |
* are: |
* <pre> |
* - pt: point |
* - mm: millimeter (default) |
* - cm: centimeter |
* - in: inch |
* </pre> |
* A point equals 1/72 of inch, that is to say about |
* 0.35 mm (an inch being 2.54 cm). This is a very |
* common unit in typography; font sizes are |
* expressed in that unit. |
* format - The format used for pages. It can be |
* either one of the following values (case |
* insensitive): |
* <pre> |
* - A3 |
* - A4 (default) |
* - A5 |
* - Letter |
* - Legal |
* </pre> |
* or a custom format in the form of a two-element |
* array containing the width and the height |
* (expressed in the unit given by the unit |
* parameter). |
* @param string $class The concrete class name to return an instance of. |
* Defaults to File_PDF. |
*/ |
function &factory($params = array(), $class = 'File_PDF') |
{ |
/* Check for PHP locale-related bug. */ |
if (1.1 == 1) { |
$error = File_PDF::raiseError('Do not alter the locale before including the class file.'); |
return $error; |
} |
/* Default parameters. */ |
$defaults = array('orientation' => 'P', 'unit' => 'mm', 'format' => 'A4'); |
/* Backward compatibility with old method signature. */ |
/* Should be removed a few versions later. */ |
if (!is_array($params)) { |
$class = 'File_PDF'; |
$params = $defaults; |
$names = array_keys($defaults); |
for ($i = 0; $i < func_num_args(); $i++) { |
$params[$names[$i]] = func_get_arg($i); |
} |
} else { |
$params = array_merge($defaults, $params); |
} |
/* Create the PDF object. */ |
$pdf = &new $class(); |
/* Scale factor. */ |
if ($params['unit'] == 'pt') { |
$pdf->_scale = 1; |
} elseif ($params['unit'] == 'mm') { |
$pdf->_scale = 72 / 25.4; |
} elseif ($params['unit'] == 'cm') { |
$pdf->_scale = 72 / 2.54; |
} elseif ($params['unit'] == 'in') { |
$pdf->_scale = 72; |
} else { |
$error = File_PDF::raiseError(sprintf('Incorrect units: %s', $params['unit'])); |
return $error; |
} |
/* Page format. */ |
if (is_string($params['format'])) { |
$params['format'] = strtolower($params['format']); |
if ($params['format'] == 'a3') { |
$params['format'] = array(841.89, 1190.55); |
} elseif ($params['format'] == 'a4') { |
$params['format'] = array(595.28, 841.89); |
} elseif ($params['format'] == 'a5') { |
$params['format'] = array(420.94, 595.28); |
} elseif ($params['format'] == 'letter') { |
$params['format'] = array(612, 792); |
} elseif ($params['format'] == 'legal') { |
$params['format'] = array(612, 1008); |
} else { |
$error = File_PDF::raiseError(sprintf('Unknown page format: %s', $params['format'])); |
return $error; |
} |
$pdf->fwPt = $params['format'][0]; |
$pdf->fhPt = $params['format'][1]; |
} else { |
$pdf->fwPt = $params['format'][0] * $pdf->_scale; |
$pdf->fhPt = $params['format'][1] * $pdf->_scale; |
} |
$pdf->fw = $pdf->fwPt / $pdf->_scale; |
$pdf->fh = $pdf->fhPt / $pdf->_scale; |
/* Page orientation. */ |
$params['orientation'] = strtolower($params['orientation']); |
if ($params['orientation'] == 'p' || $params['orientation'] == 'portrait') { |
$pdf->_default_orientation = 'P'; |
$pdf->wPt = $pdf->fwPt; |
$pdf->hPt = $pdf->fhPt; |
} elseif ($params['orientation'] == 'l' || $params['orientation'] == 'landscape') { |
$pdf->_default_orientation = 'L'; |
$pdf->wPt = $pdf->fhPt; |
$pdf->hPt = $pdf->fwPt; |
} else { |
$error = File_PDF::raiseError(sprintf('Incorrect orientation: %s', $params['orientation'])); |
return $error; |
} |
$pdf->_current_orientation = $pdf->_default_orientation; |
$pdf->w = $pdf->wPt / $pdf->_scale; |
$pdf->h = $pdf->hPt / $pdf->_scale; |
/* Page margins (1 cm) */ |
$margin = 28.35 / $pdf->_scale; |
$pdf->setMargins($margin, $margin); |
/* Interior cell margin (1 mm) */ |
$pdf->_cell_margin = $margin / 10; |
/* Line width (0.2 mm) */ |
$pdf->_line_width = .567 / $pdf->_scale; |
/* Automatic page break */ |
$pdf->setAutoPageBreak(true, 2 * $margin); |
/* Full width display mode */ |
$pdf->setDisplayMode('fullwidth'); |
/* Compression */ |
$pdf->setCompression(true); |
return $pdf; |
} |
/** |
* Returns a PEAR_Error object. Wraps around PEAR::raiseError() to |
* avoid having to include PEAR.php unless an error occurs. |
* |
* @param mixed $error The error message. |
* |
* @return object PEAR_Error |
*/ |
function raiseError($error) |
{ |
require_once 'PEAR.php'; |
return PEAR::raiseError($error); |
} |
/** |
* Defines the left, top and right margins. By default, they equal 1 cm. |
* Call this method to change them. |
* |
* @param float $left Left margin. |
* @param float $top Top margin. |
* @param float $right Right margin. If not specified default to the value |
* of the left one. |
* |
* @see File_PDF::setAutoPageBreak |
* @see File_PDF::setLeftMargin |
* @see File_PDF::setRightMargin |
* @see File_PDF::setTopMargin |
*/ |
function setMargins($left, $top, $right = null) |
{ |
/* Set left and top margins. */ |
$this->_left_margin = $left; |
$this->_top_margin = $top; |
/* If no right margin set default to same as left. */ |
$this->_right_margin = (is_null($right) ? $left : $right); |
} |
/** |
* Defines the left margin. The method can be called before creating the |
* first page. |
* If the current abscissa gets out of page, it is brought back to the |
* margin. |
* |
* @param float $margin The margin. |
* |
* @see File_PDF::setAutoPageBreak |
* @see File_PDF::setMargins |
* @see File_PDF::setRightMargin |
* @see File_PDF::setTopMargin |
*/ |
function setLeftMargin($margin) |
{ |
$this->_left_margin = $margin; |
/* If there is a current page and the current X position is less than |
* margin set the X position to the margin value. */ |
if ($this->_page > 0 && $this->x < $margin) { |
$this->x = $margin; |
} |
} |
/** |
* Defines the top margin. The method can be called before creating the |
* first page. |
* |
* @param float $margin The margin. |
*/ |
function setTopMargin($margin) |
{ |
$this->_top_margin = $margin; |
} |
/** |
* Defines the right margin. The method can be called before creating the |
* first page. |
* |
* @param float $margin The margin. |
*/ |
function setRightMargin($margin) |
{ |
$this->_right_margin = $margin; |
} |
/** |
* Returns the actual page width. |
* |
* @since File_PDF 0.2.0 |
* @since Horde 3.2 |
* |
* @return float The page width. |
*/ |
function getPageWidth() |
{ |
return ($this->w - $this->_right_margin - $this->_left_margin); |
} |
/** |
* Returns the actual page height. |
* |
* @since File_PDF 0.2.0 |
* @since Horde 3.2 |
* |
* @return float The page height. |
*/ |
function getPageHeight() |
{ |
return ($this->h - $this->_top_margin - $this->_break_margin); |
} |
/** |
* Enables or disables the automatic page breaking mode. When enabling, |
* the second parameter is the distance from the bottom of the page that |
* defines the triggering limit. By default, the mode is on and the margin |
* is 2 cm. |
* |
* @param boolean auto Boolean indicating if mode should be on or off. |
* @param float $margin Distance from the bottom of the page. |
*/ |
function setAutoPageBreak($auto, $margin = 0) |
{ |
$this->_auto_page_break = $auto; |
$this->_break_margin = $margin; |
$this->_page_break_trigger = $this->h - $margin; |
} |
/** |
* Defines the way the document is to be displayed by the viewer. The zoom |
* level can be set: pages can be displayed entirely on screen, occupy the |
* full width of the window, use real size, be scaled by a specific |
* zooming factor or use viewer default (configured in the Preferences |
* menu of Acrobat). The page layout can be specified too: single at once, |
* continuous display, two columns or viewer default. |
* By default, documents use the full width mode with continuous display. |
* |
* @param mixed $zoom The zoom to use. It can be one of the |
* following string values: |
* - fullpage: entire page on screen |
* - fullwidth: maximum width of window |
* - real: uses real size (100% zoom) |
* - default: uses viewer default mode |
* or a number indicating the zooming factor. |
* @param string layout The page layout. Possible values are: |
* - single: one page at once |
* - continuous: pages in continuously |
* - two: two pages on two columns |
* - default: uses viewer default mode |
* Default value is continuous. |
*/ |
function setDisplayMode($zoom, $layout = 'continuous') |
{ |
$zoom = strtolower($zoom); |
if ($zoom == 'fullpage' || $zoom == 'fullwidth' || $zoom == 'real' |
|| $zoom == 'default' || !is_string($zoom)) { |
$this->_zoom_mode = $zoom; |
} elseif ($zoom == 'zoom') { |
$this->_zoom_mode = $layout; |
} else { |
return $this->raiseError(sprintf('Incorrect zoom display mode: %s', $zoom)); |
} |
$layout = strtolower($layout); |
if ($layout == 'single' || $layout == 'continuous' || $layout == 'two' |
|| $layout == 'default') { |
$this->_layout_mode = $layout; |
} elseif ($zoom != 'zoom') { |
return $this->raiseError(sprintf('Incorrect layout display mode: %s', $layout)); |
} |
} |
/** |
* Activates or deactivates page compression. When activated, the internal |
* representation of each page is compressed, which leads to a compression |
* ratio of about 2 for the resulting document. |
* Compression is on by default. |
* Note: the Zlib extension is required for this feature. If not present, |
* compression will be turned off. |
* |
* @param boolean $compress Boolean indicating if compression must be |
* enabled or not. |
*/ |
function setCompression($compress) |
{ |
/* If no gzcompress function is available then default to false. */ |
$this->_compress = (function_exists('gzcompress') ? $compress : false); |
} |
/** |
* Set the info to a document. Possible info settings are: |
* - title |
* - subject |
* - author |
* - keywords |
* - creator |
* |
* @param mixed $info If passed as an array then the complete hash |
* containing the info to be inserted into the |
* document. Otherwise the name of setting to be set. |
* @param string $value The value of the setting. |
*/ |
function setInfo($info, $value = '') |
{ |
if (is_array($info)) { |
$this->_info = $info; |
} else { |
$this->_info[$info] = $value; |
} |
} |
/** |
* Defines an alias for the total number of pages. It will be substituted |
* as the document is closed. |
* |
* Example: |
* class My_File_PDF extends File_PDF { |
* function footer() |
* { |
* // Go to 1.5 cm from bottom |
* $this->setY(-15); |
* // Select Arial italic 8 |
* $this->setFont('Arial', 'I', 8); |
* // Print current and total page numbers |
* $this->cell(0, 10, 'Page ' . $this->getPageNo() . '/{nb}', 0, |
* 0, 'C'); |
* } |
* } |
* $pdf = &My_File_PDF::factory(); |
* $pdf->aliasNbPages(); |
* |
* @param string $alias The alias. Default value: {nb}. |
* |
* @see File_PDF::getPageNo |
* @see File_PDF::footer |
*/ |
function aliasNbPages($alias = '{nb}') |
{ |
$this->_alias_nb_pages = $alias; |
} |
/** |
* This method begins the generation of the PDF document; it must be |
* called before any output commands. No page is created by this method, |
* therefore it is necessary to call File_PDF::addPage. |
* |
* @see File_PDF::addPage |
* @see File_PDF::close |
*/ |
function open() |
{ |
$this->_beginDoc(); |
} |
/** |
* Terminates the PDF document. It is not necessary to call this method |
* explicitly because File_PDF::output does it automatically. |
* If the document contains no page, File_PDF::addPage is called to prevent |
* from getting an invalid document. |
* |
* @see File_PDF::open |
* @see File_PDF::output |
*/ |
function close() |
{ |
/* Terminate document */ |
if ($this->_page == 0) { |
$this->addPage(); |
} |
/* Page footer */ |
$this->_in_footer = true; |
$this->footer(); |
$this->_in_footer = false; |
/* Close page */ |
$this->_endPage(); |
/* Close document */ |
$this->_endDoc(); |
} |
/** |
* Adds a new page to the document. If a page is already present, the |
* File_PDF::footer method is called first to output the footer. Then the |
* page is added, the current position set to the top-left corner according |
* to the left and top margins, and File_PDF::header is called to display |
* the header. |
* The font which was set before calling is automatically restored. There |
* is no need to call File_PDF::setFont again if you want to continue with |
* the same font. The same is true for colors and line width. |
* The origin of the coordinate system is at the top-left corner and |
* increasing ordinates go downwards. |
* |
* @param string $orientation Page orientation. Possible values |
* are (case insensitive): |
* - P or Portrait |
* - L or Landscape |
* The default value is the one passed to the |
* constructor. |
* |
* @see File_PDF::PDF |
* @see File_PDF::header |
* @see File_PDF::footer |
* @see File_PDF::setMargins |
*/ |
function addPage($orientation = '') |
{ |
/* For good measure make sure this is called. */ |
$this->_beginDoc(); |
/* Save style settings so that they are not overridden by footer(). */ |
$lw = $this->_line_width; |
$dc = $this->_draw_color; |
$fc = $this->_fill_color; |
$tc = $this->_text_color; |
$cf = $this->_color_flag; |
if ($this->_page > 0) { |
/* Page footer. */ |
$this->_in_footer = true; |
$this->footer(); |
$this->_in_footer = false; |
/* Close page. */ |
$this->_endPage(); |
} |
/* Start new page. */ |
$this->_beginPage($orientation); |
/* Set line cap style to square. */ |
$this->_out('2 J'); |
/* Set line width. */ |
$this->_line_width = $lw; |
$this->_out(sprintf('%.2f w', $lw * $this->_scale)); |
/* Set font for the beginning of the page. */ |
$font_family = null; |
if ($this->_font_family) { |
$font_family = $this->_font_family; |
$font_style = $this->_font_style . ($this->_underline ? 'U' : ''); |
$font_size = $this->_font_size_pt; |
$this->setFont($font_family, $font_style, $font_size); |
} |
/* Set colors. */ |
$this->_fill_color = $fc; |
/* Check if fill color has been set before this page. */ |
if ($this->_fill_color != '0 g') { |
$this->_out($this->_fill_color); |
} |
$this->_draw_color = $dc; |
/* Check if draw color has been set before this page. */ |
if ($this->_draw_color != '0 G') { |
$this->_out($this->_draw_color); |
} |
$this->_text_color = $tc; |
$this->_color_flag = $cf; |
/* Page header. */ |
$this->header(); |
/* Restore line width. */ |
if ($this->_line_width != $lw) { |
$this->_line_width = $lw; |
$this->_out(sprintf('%.2f w', $lw * $this->_scale)); |
} |
/* Make sure the font is set for this page as it was before the |
* header. */ |
if ($font_family) { |
$this->setFont($font_family, $font_style, $font_size, true); |
} |
/* Restore colors. */ |
if ($this->_draw_color != $dc) { |
$this->_draw_color = $dc; |
$this->_out($dc); |
} |
if ($this->_fill_color != $fc) { |
$this->_fill_color = $fc; |
$this->_out($fc); |
} |
$this->_text_color = $tc; |
$this->_color_flag = $cf; |
} |
/** |
* This method is used to render the page header. It is automatically |
* called by File_PDF::addPage and should not be called directly by the |
* application. The implementation in File_PDF:: is empty, so you have to |
* subclass it and override the method if you want a specific processing. |
* |
* Example: |
* |
* class My_File_PDF extends File_PDF { |
* function header() |
* { |
* // Select Arial bold 15 |
* $this->setFont('Arial', 'B', 15); |
* // Move to the right |
* $this->cell(80); |
* // Framed title |
* $this->cell(30, 10, 'Title', 1, 0, 'C'); |
* // Line break |
* $this->newLine(20); |
* } |
* } |
* |
* @see File_PDF::footer |
*/ |
function header() |
{ |
/* To be implemented in your own inherited class. */ |
} |
/** |
* This method is used to render the page footer. It is automatically |
* called by File_PDF::addPage and File_PDF::close and should not be called |
* directly by the application. The implementation in File_PDF:: is empty, |
* so you have to subclass it and override the method if you want a specific |
* processing. |
* |
* Example: |
* |
* class My_File_PDF extends File_PDF { |
* function footer() |
* { |
* // Go to 1.5 cm from bottom |
* $this->setY(-15); |
* // Select Arial italic 8 |
* $this->setFont('Arial', 'I', 8); |
* // Print centered page number |
* $this->cell(0, 10, 'Page ' . $this->getPageNo(), 0, 0, 'C'); |
* } |
* } |
* |
* @see File_PDF::header |
*/ |
function footer() |
{ |
/* To be implemented in your own inherited class. */ |
} |
/** |
* Returns the current page number. |
* |
* @return integer |
* |
* @see File_PDF::aliasNbPages |
*/ |
function getPageNo() |
{ |
return $this->_page; |
} |
/** |
* Sets the fill color. |
* |
* Depending on the colorspace called, the number of color component |
* parameters required can be either 1, 3 or 4. The method can be called |
* before the first page is created and the color is retained from page to |
* page. |
* |
* @param string $cs Indicates the colorspace which can be either 'rgb', |
* 'cmyk' or 'gray'. Defaults to 'rgb'. |
* @param float $c1 First color component, floating point value between 0 |
* and 1. Required for gray, rgb and cmyk. |
* @param float $c2 Second color component, floating point value between |
* 0 and 1. Required for rgb and cmyk. |
* @param float $c3 Third color component, floating point value between |
* 0 and 1. Required for rgb and cmyk. |
* @param float $c4 Fourth color component, floating point value between |
* 0 and 1. Required for cmyk. |
* |
* @see File_PDF::setTextColor |
* @see File_PDF::setDrawColor |
* @see File_PDF::rect |
* @see File_PDF::cell |
* @see File_PDF::multiCell |
*/ |
function setFillColor($cs = 'rgb', $c1, $c2 = 0, $c3 = 0, $c4 = 0) |
{ |
$cs = strtolower($cs); |
if ($cs == 'rgb') { |
$this->_fill_color = sprintf('%.3f %.3f %.3f rg', $c1, $c2, $c3); |
} elseif ($cs == 'cmyk') { |
$this->_fill_color = sprintf('%.3f %.3f %.3f %.3f k', $c1, $c2, $c3, $c4); |
} else { |
$this->_fill_color = sprintf('%.3f g', $c1); |
} |
if ($this->_page > 0) { |
$this->_out($this->_fill_color); |
} |
$this->_color_flag = $this->_fill_color != $this->_text_color; |
} |
/** |
* Sets the text color. |
* |
* Depending on the colorspace called, the number of color component |
* parameters required can be either 1, 3 or 4. The method can be called |
* before the first page is created and the color is retained from page to |
* page. |
* |
* @param string $cs Indicates the colorspace which can be either 'rgb', |
* 'cmyk' or 'gray'. Defaults to 'rgb'. |
* @param float $c1 First color component, floating point value between 0 |
* and 1. Required for gray, rgb and cmyk. |
* @param float $c2 Second color component, floating point value between |
* 0 and 1. Required for rgb and cmyk. |
* @param float $c3 Third color component, floating point value between |
* 0 and 1. Required for rgb and cmyk. |
* @param float $c4 Fourth color component, floating point value between |
* 0 and 1. Required for cmyk. |
* |
* @since File_PDF 0.2.0 |
* @since Horde 3.2 |
* @see File_PDF::setFillColor |
* @see File_PDF::setDrawColor |
* @see File_PDF::rect |
* @see File_PDF::cell |
* @see File_PDF::multiCell |
*/ |
function setTextColor($cs = 'rgb', $c1, $c2 = 0, $c3 = 0, $c4 = 0) |
{ |
$cs = strtolower($cs); |
if ($cs == 'rgb') { |
$this->_text_color = sprintf('%.3f %.3f %.3f rg', $c1, $c2, $c3); |
} elseif ($cs == 'cmyk') { |
$this->_text_color = sprintf('%.3f %.3f %.3f %.3f k', $c1, $c2, $c3, $c4); |
} else { |
$this->_text_color = sprintf('%.3f g', $c1); |
} |
if ($this->_page > 0) { |
$this->_out($this->_text_color); |
} |
$this->_color_flag = $this->_fill_color != $this->_text_color; |
} |
/** |
* Sets the draw color, used when drawing lines. Depending on the |
* colorspace called, the number of color component parameters required |
* can be either 1, 3 or 4. The method can be called before the first page |
* is created and the color is retained from page to page. |
* |
* @param string $cs Indicates the colorspace which can be either 'rgb', |
* 'cmyk' or 'gray'. Defaults to 'rgb'. |
* @param float $c1 First color component, floating point value between 0 |
* and 1. Required for gray, rgb and cmyk. |
* @param float $c2 Second color component, floating point value between |
* 0 and 1. Required for rgb and cmyk. |
* @param float $c3 Third color component, floating point value between 0 |
* and 1. Required for rgb and cmyk. |
* @param float $c4 Fourth color component, floating point value between |
* 0 and 1. Required for cmyk. |
* |
* @see File_PDF::setFillColor |
* @see File_PDF::line |
* @see File_PDF::rect |
* @see File_PDF::cell |
* @see File_PDF::multiCell |
*/ |
function setDrawColor($cs = 'rgb', $c1, $c2 = 0, $c3 = 0, $c4 = 0) |
{ |
$cs = strtolower($cs); |
if ($cs == 'rgb') { |
$this->_draw_color = sprintf('%.3f %.3f %.3f RG', $c1, $c2, $c3); |
} elseif ($cs == 'cmyk') { |
$this->_draw_color = sprintf('%.3f %.3f %.3f %.3f K', $c1, $c2, $c3, $c4); |
} else { |
$this->_draw_color = sprintf('%.3f G', $c1); |
} |
if ($this->_page > 0) { |
$this->_out($this->_draw_color); |
} |
} |
/** |
* Returns the length of a text string. A font must be selected. |
* |
* @param string $text The text whose length is to be computed. |
* @param boolean $pt Boolean to indicate if the width should be returned |
* in points or user units. Default is 'false'. |
* |
* @return float |
*/ |
function getStringWidth($text, $pt = false) |
{ |
$text = (string)$text; |
$width = 0; |
$length = strlen($text); |
for ($i = 0; $i < $length; $i++) { |
$width += $this->_current_font['cw'][$text{$i}]; |
} |
/* Adjust for word spacing. */ |
$width += $this->_word_spacing * substr_count($text, ' ') * $this->_current_font['cw'][' ']; |
if ($pt) { |
return $width * $this->_font_size_pt / 1000; |
} else { |
return $width * $this->_font_size / 1000; |
} |
} |
/** |
* Defines the line width. By default, the value equals 0.2 mm. The method |
* can be called before the first page is created and the value is |
* retained from page to page. |
* |
* @param float $width The width. |
* |
* @see File_PDF::line |
* @see File_PDF::rect |
* @see File_PDF::cell |
* @see File_PDF::multiCell |
*/ |
function setLineWidth($width) |
{ |
$this->_line_width = $width; |
if ($this->_page > 0) { |
$this->_out(sprintf('%.2f w', $width * $this->_scale)); |
} |
} |
/** |
* Draws a line between two points. |
* |
* All coordinates can be negative to provide values from the right or |
* bottom edge of the page (since File_PDF 0.2.0, Horde 3.2). |
* |
* @param float $x1 Abscissa of first point. |
* @param float $y1 Ordinate of first point. |
* @param float $x2 Abscissa of second point. |
* @param float $y2 Ordinate of second point. |
* |
* @see File_PDF::setLineWidth |
* @see File_PDF::setDrawColor. |
*/ |
function line($x1, $y1, $x2, $y2) |
{ |
if ($x1 < 0) { |
$x1 += $this->w; |
} |
if ($y1 < 0) { |
$y1 += $this->h; |
} |
if ($x2 < 0) { |
$x2 += $this->w; |
} |
if ($y2 < 0) { |
$y2 += $this->h; |
} |
$this->_out(sprintf('%.2f %.2f m %.2f %.2f l S', $x1 * $this->_scale, ($this->h - $y1) * $this->_scale, $x2 * $this->_scale, ($this->h - $y2) * $this->_scale)); |
} |
/** |
* Outputs a rectangle. It can be drawn (border only), filled (with no |
* border) or both. |
* |
* All coordinates can be negative to provide values from the right or |
* bottom edge of the page (since File_PDF 0.2.0, Horde 3.2). |
* |
* @param float $x Abscissa of upper-left corner. |
* @param float $y Ordinate of upper-left corner. |
* @param float $width Width. |
* @param float $height Height. |
* @param float $style Style of rendering. Possible values are: |
* - D or empty string: draw (default) |
* - F: fill |
* - DF or FD: draw and fill |
* |
* @see File_PDF::setLineWidth |
* @see File_PDF::setDrawColor |
* @see File_PDF::setFillColor |
*/ |
function rect($x, $y, $width, $height, $style = '') |
{ |
if ($x < 0) { |
$x += $this->w; |
} |
if ($y < 0) { |
$y += $this->h; |
} |
$style = strtoupper($style); |
if ($style == 'F') { |
$op = 'f'; |
} elseif ($style == 'FD' || $style == 'DF') { |
$op = 'B'; |
} else { |
$op = 'S'; |
} |
$x = $this->_toPt($x); |
$y = $this->_toPt($y); |
$width = $this->_toPt($width); |
$height = $this->_toPt($height); |
$this->_out(sprintf('%.2f %.2f %.2f %.2f re %s', $x, $this->hPt - $y, $width, -$height, $op)); |
} |
/** |
* Outputs a circle. It can be drawn (border only), filled (with no |
* border) or both. |
* |
* All coordinates can be negative to provide values from the right or |
* bottom edge of the page (since File_PDF 0.2.0, Horde 3.2). |
* |
* @param float $x Abscissa of the center of the circle. |
* @param float $y Ordinate of the center of the circle. |
* @param float $r Circle radius. |
* @param string $style Style of rendering. Possible values are: |
* - D or empty string: draw (default) |
* - F: fill |
* - DF or FD: draw and fill |
*/ |
function circle($x, $y, $r, $style = '') |
{ |
if ($x < 0) { |
$x += $this->w; |
} |
if ($y < 0) { |
$y += $this->h; |
} |
$style = strtolower($style); |
if ($style == 'f') { |
$op = 'f'; // Style is fill only. |
} elseif ($style == 'fd' || $style == 'df') { |
$op = 'B'; // Style is fill and stroke. |
} else { |
$op = 'S'; // Style is stroke only. |
} |
$x = $this->_toPt($x); |
$y = $this->_toPt($y); |
$r = $this->_toPt($r); |
/* Invert the y scale. */ |
$y = $this->hPt - $y; |
/* Length of the Bezier control. */ |
$b = $r * 0.552; |
/* Move from the given origin and set the current point |
* to the start of the first Bezier curve. */ |
$c = sprintf('%.2f %.2f m', $x - $r, $y); |
$x = $x - $r; |
/* First circle quarter. */ |
$c .= sprintf(' %.2f %.2f %.2f %.2f %.2f %.2f c', |
$x, $y + $b, // First control point. |
$x + $r - $b, $y + $r, // Second control point. |
$x + $r, $y + $r); // Final point. |
/* Set x/y to the final point. */ |
$x = $x + $r; |
$y = $y + $r; |
/* Second circle quarter. */ |
$c .= sprintf(' %.2f %.2f %.2f %.2f %.2f %.2f c', |
$x + $b, $y, |
$x + $r, $y - $r + $b, |
$x + $r, $y - $r); |
/* Set x/y to the final point. */ |
$x = $x + $r; |
$y = $y - $r; |
/* Third circle quarter. */ |
$c .= sprintf(' %.2f %.2f %.2f %.2f %.2f %.2f c', |
$x, $y - $b, |
$x - $r + $b, $y - $r, |
$x - $r, $y - $r); |
/* Set x/y to the final point. */ |
$x = $x - $r; |
$y = $y - $r; |
/* Fourth circle quarter. */ |
$c .= sprintf(' %.2f %.2f %.2f %.2f %.2f %.2f c %s', |
$x - $b, $y, |
$x - $r, $y + $r - $b, |
$x - $r, $y + $r, |
$op); |
/* Output the whole string. */ |
$this->_out($c); |
} |
/** |
* Imports a TrueType or Type1 font and makes it available. It is |
* necessary to generate a font definition file first with the |
* makefont.php utility. |
* The location of the definition file (and the font file itself when |
* embedding) must be found at the full path name included. |
* |
* Example: |
* $pdf->addFont('Comic', 'I'); |
* is equivalent to: |
* $pdf->addFont('Comic', 'I', 'comici.php'); |
* |
* @param string $family Font family. The name can be chosen arbitrarily. |
* If it is a standard family name, it will |
* override the corresponding font. |
* @param string $style Font style. Possible values are (case |
* insensitive): |
* - empty string: regular (default) |
* - B: bold |
* - I: italic |
* - BI or IB: bold italic |
* @param string $file The font definition file. By default, the name is |
* built from the family and style, in lower case |
* with no space. |
* |
* @see File_PDF::setFont |
*/ |
function addFont($family, $style = '', $file = '') |
{ |
$family = strtolower($family); |
if ($family == 'arial') { |
$family = 'helvetica'; |
} |
$style = strtoupper($style); |
if ($style == 'IB') { |
$style = 'BI'; |
} |
if (isset($this->_fonts[$family . $style])) { |
return $this->raiseError(sprintf('Font already added: %s %s', $family, $style)); |
} |
if ($file == '') { |
$file = str_replace(' ', '', $family) . strtolower($style) . '.php'; |
} |
include($file); |
if (!isset($name)) { |
return $this->raiseError('Could not include font definition file.'); |
} |
$i = count($this->_fonts) + 1; |
$this->_fonts[$family . $style] = array('i' => $i, 'type' => $type, 'name' => $name, 'desc' => $desc, 'up' => $up, 'ut' => $ut, 'cw' => $cw, 'enc' => $enc, 'file' => $file); |
if ($diff) { |
/* Search existing encodings. */ |
$d = 0; |
$nb = count($this->_diffs); |
for ($i = 1; $i <= $nb; $i++) { |
if ($this->_diffs[$i] == $diff) { |
$d = $i; |
break; |
} |
} |
if ($d == 0) { |
$d = $nb + 1; |
$this->_diffs[$d] = $diff; |
} |
$this->_fonts[$family.$style]['diff'] = $d; |
} |
if ($file) { |
if ($type == 'TrueType') { |
$this->_font_files[$file] = array('length1' => $originalsize); |
} else { |
$this->_font_files[$file] = array('length1' => $size1, 'length2' => $size2); |
} |
} |
} |
/** |
* Sets the font used to print character strings. It is mandatory to call |
* this method at least once before printing text or the resulting |
* document would not be valid. The font can be either a standard one or a |
* font added via the File_PDF::addFont method. Standard fonts use Windows |
* encoding cp1252 (Western Europe). |
* The method can be called before the first page is created and the font |
* is retained from page to page. |
* If you just wish to change the current font size, it is simpler to call |
* File_PDF::setFontSize. |
* |
* @param string $family Family font. It can be either a name defined by |
* File_PDF::addFont or one of the standard families |
* (case insensitive): |
* - Courier (fixed-width) |
* - Helvetica or Arial (sans serif) |
* - Times (serif) |
* - Symbol (symbolic) |
* - ZapfDingbats (symbolic) |
* It is also possible to pass an empty string. In |
* that case, the current family is retained. |
* @param string $style Font style. Possible values are (case |
* insensitive): |
* - empty string: regular |
* - B: bold |
* - I: italic |
* - U: underline |
* or any combination. The default value is regular. |
* Bold and italic styles do not apply to Symbol and |
* ZapfDingbats. |
* @param integer $size Font size in points. The default value is the |
* current size. If no size has been specified since |
* the beginning of the document, the value taken |
* is 12. |
* @param boolean $force Force the setting of the font. Each new page will |
* require a new call to File_PDF::setFont and |
* settings this to true will make sure that the |
* checks for same font calls will be skipped. |
* |
* @see File_PDF::addFont |
* @see File_PDF::setFontSize |
* @see File_PDF::cell |
* @see File_PDF::multiCell |
* @see File_PDF::Write |
*/ |
function setFont($family, $style = '', $size = null, $force = false) |
{ |
$family = strtolower($family); |
if ($family == 'arial') { |
/* Use helvetica instead of arial. */ |
$family = 'helvetica'; |
} elseif ($family == 'symbol' || $family == 'zapfdingbats') { |
/* These two fonts do not have styles available. */ |
$style = ''; |
} |
$style = strtoupper($style); |
/* Underline is handled separately, if specified in the style var |
* remove it from the style and set the underline flag. */ |
if (strpos($style, 'U') !== false) { |
$this->_underline = true; |
$style = str_replace('U', '', $style); |
} else { |
$this->_underline = false; |
} |
if ($style == 'IB') { |
$style = 'BI'; |
} |
/* If no size specified, use current size. */ |
if (is_null($size)) { |
$size = $this->_font_size_pt; |
} |
/* If font requested is already the current font and no force setting |
* of the font is requested (eg. when adding a new page) don't bother |
* with the rest of the function and simply return. */ |
if ($this->_font_family == $family && $this->_font_style == $style && |
$this->_font_size_pt == $size && !$force) { |
return; |
} |
/* Set the font key. */ |
$fontkey = $family . $style; |
/* Test if already cached. */ |
if (!isset($this->_fonts[$fontkey])) { |
/* Get the character width definition file. */ |
$font_widths = &File_PDF::_getFontFile($fontkey); |
if (is_a($font_widths, 'PEAR_Error')) { |
return $font_widths; |
} |
$i = count($this->_fonts) + 1; |
$this->_fonts[$fontkey] = array( |
'i' => $i, |
'type' => 'core', |
'name' => $this->_core_fonts[$fontkey], |
'up' => -100, |
'ut' => 50, |
'cw' => $font_widths[$fontkey]); |
} |
/* Store font information as current font. */ |
$this->_font_family = $family; |
$this->_font_style = $style; |
$this->_font_size_pt = $size; |
$this->_font_size = $size / $this->_scale; |
$this->_current_font = &$this->_fonts[$fontkey]; |
/* Output font information if at least one page has been defined. */ |
if ($this->_page > 0) { |
$this->_out(sprintf('BT /F%d %.2f Tf ET', $this->_current_font['i'], $this->_font_size_pt)); |
} |
} |
/** |
* Defines the size of the current font. |
* |
* @param float $size The size (in points). |
* |
* @see File_PDF::setFont |
*/ |
function setFontSize($size) |
{ |
/* If the font size is already the current font size, just return. */ |
if ($this->_font_size_pt == $size) { |
return; |
} |
/* Set the current font size, both in points and scaled to user |
* units. */ |
$this->_font_size_pt = $size; |
$this->_font_size = $size / $this->_scale; |
/* Output font information if at least one page has been defined. */ |
if ($this->_page > 0) { |
$this->_out(sprintf('BT /F%d %.2f Tf ET', $this->_current_font['i'], $this->_font_size_pt)); |
} |
} |
/** |
* Defines the style of the current font. |
* |
* @param string $style The font style. |
* |
* @see File_PDF::setFont |
* @since File_PDF 0.2.0 |
* @since Horde 3.2 |
*/ |
function setFontStyle($style) |
{ |
$this->setFont($this->_font_family, $style); |
} |
/** |
* Creates a new internal link and returns its identifier. An internal |
* link is a clickable area which directs to another place within the |
* document. |
* The identifier can then be passed to File_PDF::cell, File_PDF::write, |
* File_PDF::image or File_PDF::link. The destination is defined with |
* File_PDF::setLink. |
* |
* @see File_PDF::cell |
* @see File_PDF::Write |
* @see File_PDF::image |
* @see File_PDF::Link |
* @see File_PDF::SetLink |
*/ |
function addLink() |
{ |
$n = count($this->_links) + 1; |
$this->_links[$n] = array(0, 0); |
return $n; |
} |
/** |
* Defines the page and position a link points to. |
* |
* @param integer $link The link identifier returned by File_PDF::addLink. |
* @param float $y Ordinate of target position; -1 indicates the |
* current position. The default value is 0 (top of |
* page). |
* @param integer $page Number of target page; -1 indicates the current |
* page. This is the default value. |
* |
* @see File_PDF::addLink |
*/ |
function setLink($link, $y = 0, $page = -1) |
{ |
if ($y == -1) { |
$y = $this->y; |
} |
if ($page == -1) { |
$page = $this->_page; |
} |
$this->_links[$link] = array($page, $y); |
} |
/** |
* Puts a link on a rectangular area of the page. Text or image links are |
* generally put via File_PDF::cell, File_PDF::Write or File_PDF::image, |
* but this method can be useful for instance to define a clickable area |
* inside an image. |
* |
* All coordinates can be negative to provide values from the right or |
* bottom edge of the page (since File_PDF 0.2.0, Horde 3.2). |
* |
* @param float $x Abscissa of the upper-left corner of the rectangle. |
* @param float $y Ordinate of the upper-left corner of the rectangle. |
* @param float $width Width of the rectangle. |
* @param float $height Height of the rectangle. |
* @param mixed $link URL or identifier returned by File_PDF::addLink. |
* |
* @see File_PDF::addLink |
* @see File_PDF::cell |
* @see File_PDF::Write |
* @see File_PDF::image |
*/ |
function link($x, $y, $width, $height, $link) |
{ |
if ($x < 0) { |
$x += $this->w; |
} |
if ($y < 0) { |
$y += $this->h; |
} |
/* Set up the coordinates with correct scaling in pt. */ |
$x = $this->_toPt($x); |
$y = $this->hPt - $this->_toPt($y); |
$width = $this->_toPt($width); |
$height = $this->_toPt($height); |
/* Save link to page links array. */ |
$this->_link($x, $y, $width, $height, $link); |
} |
/** |
* Prints a character string. The origin is on the left of the first |
* character, on the baseline. This method allows to place a string |
* precisely on the page, but it is usually easier to use File_PDF::cell, |
* File_PDF::multiCell or File_PDF::Write which are the standard methods to |
* print text. |
* |
* All coordinates can be negative to provide values from the right or |
* bottom edge of the page (since File_PDF 0.2.0, Horde 3.2). |
* |
* @param float $x Abscissa of the origin. |
* @param float $y Ordinate of the origin. |
* @param string $text String to print. |
* |
* @see File_PDF::setFont |
* @see File_PDF::cell |
* @see File_PDF::multiCell |
* @see File_PDF::Write |
*/ |
function text($x, $y, $text) |
{ |
if ($x < 0) { |
$x += $this->w; |
} |
if ($y < 0) { |
$y += $this->h; |
} |
/* Scale coordinates into points and set correct Y position. */ |
$x = $this->_toPt($x); |
$y = $this->hPt - $this->_toPt($y); |
/* Escape any potentially harmful characters. */ |
$text = $this->_escape($text); |
$out = sprintf('BT %.2f %.2f Td (%s) Tj ET', $x, $y, $text); |
if ($this->_underline && $text != '') { |
$out .= ' ' . $this->_doUnderline($x, $y, $text); |
} |
if ($this->_color_flag) { |
$out = sprintf('q %s %s Q', $this->_text_color, $out); |
} |
$this->_out($out); |
} |
/** |
* Whenever a page break condition is met, the method is called, and the |
* break is issued or not depending on the returned value. The default |
* implementation returns a value according to the mode selected by |
* File_PDF:setAutoPageBreak. |
* This method is called automatically and should not be called directly |
* by the application. |
* |
* @return boolean |
* |
* @see File_PDF::setAutoPageBreak. |
*/ |
function acceptPageBreak() |
{ |
return $this->_auto_page_break; |
} |
/** |
* Prints a cell (rectangular area) with optional borders, background |
* color and character string. The upper-left corner of the cell |
* corresponds to the current position. The text can be aligned or |
* centered. After the call, the current position moves to the right or to |
* the next line. It is possible to put a link on the text. |
* If automatic page breaking is enabled and the cell goes beyond the |
* limit, a page break is done before outputting. |
* |
* @param float $width Cell width. If 0, the cell extends up to the right |
* margin. |
* @param float $height Cell height. Default value: 0. |
* @param string $text String to print. Default value: empty. |
* @param mixed $border Indicates if borders must be drawn around the |
* cell. The value can be either a number: |
* - 0: no border (default) |
* - 1: frame |
* or a string containing some or all of the |
* following characters (in any order): |
* - L: left |
* - T: top |
* - R: right |
* - B: bottom |
* @param integer $ln Indicates where the current position should go |
* after the call. Possible values are: |
* - 0: to the right (default) |
* - 1: to the beginning of the next line |
* - 2: below |
* Putting 1 is equivalent to putting 0 and calling |
* File_PDF::newLine just after. |
* @param string $align Allows to center or align the text. Possible |
* values are: |
* - L or empty string: left (default) |
* - C: center |
* - R: right |
* @param integer $fill Indicates if the cell fill type. Possible values |
* are: |
* - 0: transparent (default) |
* - 1: painted |
* @param string $link URL or identifier returned by |
* File_PDF:addLink. |
* |
* @see File_PDF::setFont |
* @see File_PDF::setDrawColor |
* @see File_PDF::setFillColor |
* @see File_PDF::setLineWidth |
* @see File_PDF::addLink |
* @see File_PDF::newLine |
* @see File_PDF::multiCell |
* @see File_PDF::Write |
* @see File_PDF::setAutoPageBreak |
*/ |
function cell($width, $height = 0, $text = '', $border = 0, $ln = 0, |
$align = '', $fill = 0, $link = '') |
{ |
$k = $this->_scale; |
if ($this->y + $height > $this->_page_break_trigger && |
!$this->_in_footer && $this->AcceptPageBreak()) { |
$x = $this->x; |
$ws = $this->_word_spacing; |
if ($ws > 0) { |
$this->_word_spacing = 0; |
$this->_out('0 Tw'); |
} |
$this->addPage($this->_current_orientation); |
$this->x = $x; |
if ($ws > 0) { |
$this->_word_spacing = $ws; |
$this->_out(sprintf('%.3f Tw', $ws * $k)); |
} |
} |
if ($width == 0) { |
$width = $this->w - $this->_right_margin - $this->x; |
} |
$s = ''; |
if ($fill == 1 || $border == 1) { |
if ($fill == 1) { |
$op = ($border == 1) ? 'B' : 'f'; |
} else { |
$op = 'S'; |
} |
$s = sprintf('%.2f %.2f %.2f %.2f re %s ', $this->x * $k, ($this->h - $this->y) * $k, $width * $k, -$height * $k, $op); |
} |
if (is_string($border)) { |
if (strpos($border, 'L') !== false) { |
$s .= sprintf('%.2f %.2f m %.2f %.2f l S ', $this->x * $k, ($this->h - $this->y) * $k, $this->x * $k, ($this->h - ($this->y + $height)) * $k); |
} |
if (strpos($border, 'T') !== false) { |
$s .= sprintf('%.2f %.2f m %.2f %.2f l S ', $this->x * $k, ($this->h - $this->y) * $k, ($this->x + $width) * $k, ($this->h - $this->y) * $k); |
} |
if (strpos($border, 'R') !== false) { |
$s .= sprintf('%.2f %.2f m %.2f %.2f l S ', ($this->x + $width) * $k, ($this->h - $this->y) * $k, ($this->x + $width) * $k, ($this->h - ($this->y + $height)) * $k); |
} |
if (strpos($border, 'B') !== false) { |
$s .= sprintf('%.2f %.2f m %.2f %.2f l S ', $this->x * $k, ($this->h - ($this->y + $height)) * $k, ($this->x + $width) * $k, ($this->h - ($this->y + $height)) * $k); |
} |
} |
if ($text != '') { |
if ($align == 'R') { |
$dx = $width - $this->_cell_margin - $this->getStringWidth($text); |
} elseif ($align == 'C') { |
$dx = ($width - $this->getStringWidth($text)) / 2; |
} else { |
$dx = $this->_cell_margin; |
} |
if ($this->_color_flag) { |
$s .= 'q ' . $this->_text_color . ' '; |
} |
$text = str_replace(')', '\\)', str_replace('(', '\\(', str_replace('\\', '\\\\', $text))); |
$test2 = ((.5 * $height) + (.3 * $this->_font_size)); |
$test1 = $this->fhPt - (($this->y + $test2) * $k); |
$s .= sprintf('BT %.2f %.2f Td (%s) Tj ET', ($this->x + $dx) * $k, ($this->h - ($this->y + .5 * $height + .3 * $this->_font_size)) * $k, $text); |
if ($this->_underline) { |
$s .= ' ' . $this->_doUnderline($this->x + $dx, $this->y + .5 * $height + .3 * $this->_font_size, $text); |
} |
if ($this->_color_flag) { |
$s .= ' Q'; |
} |
if ($link) { |
$this->link($this->x + $dx, $this->y + .5 * $height-.5 * $this->_font_size, $this->getStringWidth($text), $this->_font_size, $link); |
} |
} |
if ($s) { |
$this->_out($s); |
} |
$this->_last_height = $height; |
if ($ln > 0) { |
/* Go to next line. */ |
$this->y += $height; |
if ($ln == 1) { |
$this->x = $this->_left_margin; |
} |
} else { |
$this->x += $width; |
} |
} |
/** |
* This method allows printing text with line breaks. They can be |
* automatic (as soon as the text reaches the right border of the cell) or |
* explicit (via the \n character). As many cells as necessary are output, |
* one below the other. |
* Text can be aligned, centered or justified. The cell block can be |
* framed and the background painted. |
* |
* @param float $width Width of cells. If 0, they extend up to the right |
* margin of the page. |
* @param float $height Height of cells. |
* @param string $text String to print. |
* @param mixed $border Indicates if borders must be drawn around the cell |
* block. The value can be either a number: |
* - 0: no border (default) |
* - 1: frame |
* or a string containing some or all of the |
* following characters (in any order): |
* - L: left |
* - T: top |
* - R: right |
* - B: bottom |
* @param string $align Sets the text alignment. Possible values are: |
* - L: left alignment |
* - C: center |
* - R: right alignment |
* - J: justification (default value) |
* @param integer $fill Indicates if the cell background must: |
* - 0: transparent (default) |
* - 1: painted |
* |
* @see File_PDF::setFont |
* @see File_PDF::setDrawColor |
* @see File_PDF::setFillColor |
* @see File_PDF::setLineWidth |
* @see File_PDF::cell |
* @see File_PDF::write |
* @see File_PDF::setAutoPageBreak |
*/ |
function multiCell($width, $height, $text, $border = 0, $align = 'J', |
$fill = 0) |
{ |
$cw = &$this->_current_font['cw']; |
if ($width == 0) { |
$width = $this->w - $this->_right_margin - $this->x; |
} |
$wmax = ($width-2 * $this->_cell_margin) * 1000 / $this->_font_size; |
$s = str_replace("\r", '', $text); |
$nb = strlen($s); |
if ($nb > 0 && $s[$nb-1] == "\n") { |
$nb--; |
} |
$b = 0; |
if ($border) { |
if ($border == 1) { |
$border = 'LTRB'; |
$b = 'LRT'; |
$b2 = 'LR'; |
} else { |
$b2 = ''; |
if (strpos($border, 'L') !== false) { |
$b2 .= 'L'; |
} |
if (strpos($border, 'R') !== false) { |
$b2 .= 'R'; |
} |
$b = (strpos($border, 'T') !== false) ? $b2 . 'T' : $b2; |
} |
} |
$sep = -1; |
$i = 0; |
$j = 0; |
$l = 0; |
$ns = 0; |
$nl = 1; |
while ($i < $nb) { |
/* Get next character. */ |
$c = $s[$i]; |
if ($c == "\n") { |
/* Explicit line break. */ |
if ($this->_word_spacing > 0) { |
$this->_word_spacing = 0; |
$this->_out('0 Tw'); |
} |
$this->cell($width, $height, substr($s, $j, $i-$j), $b, 2, $align, $fill); |
$i++; |
$sep = -1; |
$j = $i; |
$l = 0; |
$ns = 0; |
$nl++; |
if ($border && $nl == 2) { |
$b = $b2; |
} |
continue; |
} |
if ($c == ' ') { |
$sep = $i; |
$ls = $l; |
$ns++; |
} |
$l += $cw[$c]; |
if ($l > $wmax) { |
/* Automatic line break. */ |
if ($sep == -1) { |
if ($i == $j) { |
$i++; |
} |
if ($this->_word_spacing > 0) { |
$this->_word_spacing = 0; |
$this->_out('0 Tw'); |
} |
$this->cell($width, $height, substr($s, $j, $i - $j), $b, 2, $align, $fill); |
} else { |
if ($align == 'J') { |
$this->_word_spacing = ($ns>1) ? ($wmax - $ls)/1000 * $this->_font_size / ($ns - 1) : 0; |
$this->_out(sprintf('%.3f Tw', $this->_word_spacing * $this->_scale)); |
} |
$this->cell($width, $height, substr($s, $j, $sep - $j), $b, 2, $align, $fill); |
$i = $sep + 1; |
} |
$sep = -1; |
$j = $i; |
$l = 0; |
$ns = 0; |
$nl++; |
if ($border && $nl == 2) { |
$b = $b2; |
} |
} else { |
$i++; |
} |
} |
/* Last chunk. */ |
if ($this->_word_spacing > 0) { |
$this->_word_spacing = 0; |
$this->_out('0 Tw'); |
} |
if ($border && strpos($border, 'B') !== false) { |
$b .= 'B'; |
} |
$this->cell($width, $height, substr($s, $j, $i), $b, 2, $align, $fill); |
$this->x = $this->_left_margin; |
} |
/** |
* This method prints text from the current position. When the right |
* margin is reached (or the \n character is met) a line break occurs and |
* text continues from the left margin. Upon method exit, the current |
* position is left just at the end of the text. |
* It is possible to put a link on the text. |
* |
* Example: |
* //Begin with regular font |
* $pdf->setFont('Arial','',14); |
* $pdf->write(5,'Visit '); |
* //Then put a blue underlined link |
* $pdf->setTextColor(0,0,255); |
* $pdf->setFont('','U'); |
* $pdf->write(5,'www.fpdf.org','http://www.fpdf.org'); |
* |
* @param float $height Line height. |
* @param string $text String to print. |
* @param mixed $link URL or identifier returned by AddLink(). |
* |
* @see File_PDF::setFont |
* @see File_PDF::addLink |
* @see File_PDF::multiCell |
* @see File_PDF::setAutoPageBreak |
*/ |
function write($height, $text, $link = '') |
{ |
$cw = &$this->_current_font['cw']; |
$width = $this->w - $this->_right_margin - $this->x; |
$wmax = ($width - 2 * $this->_cell_margin) * 1000 / $this->_font_size; |
$s = str_replace("\r", '', $text); |
$nb = strlen($s); |
$sep = -1; |
$i = 0; |
$j = 0; |
$l = 0; |
$nl = 1; |
while ($i < $nb) { |
/* Get next character. */ |
$c = $s{$i}; |
if ($c == "\n") { |
/* Explicit line break. */ |
$this->cell($width, $height, substr($s, $j, $i - $j), 0, 2, '', 0, $link); |
$i++; |
$sep = -1; |
$j = $i; |
$l = 0; |
if ($nl == 1) { |
$this->x = $this->_left_margin; |
$width = $this->w - $this->_right_margin - $this->x; |
$wmax = ($width - 2 * $this->_cell_margin) * 1000 / $this->_font_size; |
} |
$nl++; |
continue; |
} |
if ($c == ' ') { |
$sep = $i; |
$ls = $l; |
} |
$l += (isset($cw[$c]) ? $cw[$c] : 0); |
if ($l > $wmax) { |
/* Automatic line break. */ |
if ($sep == -1) { |
if ($this->x > $this->_left_margin) { |
/* Move to next line. */ |
$this->x = $this->_left_margin; |
$this->y += $height; |
$width = $this->w - $this->_right_margin - $this->x; |
$wmax = ($width - 2 * $this->_cell_margin) * 1000 / $this->_font_size; |
$i++; |
$nl++; |
continue; |
} |
if ($i == $j) { |
$i++; |
} |
$this->cell($width, $height, substr($s, $j, $i - $j), 0, 2, '', 0, $link); |
} else { |
$this->cell($width, $height, substr($s, $j, $sep - $j), 0, 2, '', 0, $link); |
$i = $sep + 1; |
} |
$sep = -1; |
$j = $i; |
$l = 0; |
if ($nl == 1) { |
$this->x = $this->_left_margin; |
$width = $this->w - $this->_right_margin - $this->x; |
$wmax = ($width - 2 * $this->_cell_margin) * 1000 / $this->_font_size; |
} |
$nl++; |
} else { |
$i++; |
} |
} |
/* Last chunk. */ |
if ($i != $j) { |
$this->cell($l / 1000 * $this->_font_size, $height, substr($s, $j, $i), 0, 0, '', 0, $link); |
} |
} |
/** |
* Writes text at an angle. |
* |
* All coordinates can be negative to provide values from the right or |
* bottom edge of the page (since File_PDF 0.2.0, Horde 3.2). |
* |
* @param integer $x X coordinate. |
* @param integer $y Y coordinate. |
* @param string $text Text to write. |
* @param float $text_angle Angle to rotate (Eg. 90 = bottom to top). |
* @param float $font_angle Rotate characters as well as text. |
* |
* @see File_PDF::setFont |
*/ |
function writeRotated($x, $y, $text, $text_angle, $font_angle = 0) |
{ |
if ($x < 0) { |
$x += $this->w; |
} |
if ($y < 0) { |
$y += $this->h; |
} |
/* Escape text. */ |
$text = $this->_escape($text); |
$font_angle += 90 + $text_angle; |
$text_angle *= M_PI / 180; |
$font_angle *= M_PI / 180; |
$text_dx = cos($text_angle); |
$text_dy = sin($text_angle); |
$font_dx = cos($font_angle); |
$font_dy = sin($font_angle); |
$s= sprintf('BT %.2f %.2f %.2f %.2f %.2f %.2f Tm (%s) Tj ET', |
$text_dx, $text_dy, $font_dx, $font_dy, |
$x * $this->_scale, ($this->h-$y) * $this->_scale, $text); |
if ($this->_draw_color) { |
$s = 'q ' . $this->_draw_color . ' ' . $s . ' Q'; |
} |
$this->_out($s); |
} |
/** |
* Prints an image in the page. The upper-left corner and at least one of |
* the dimensions must be specified; the height or the width can be |
* calculated automatically in order to keep the image proportions. |
* Supported formats are JPEG and PNG. |
* |
* All coordinates can be negative to provide values from the right or |
* bottom edge of the page (since File_PDF 0.2.0, Horde 3.2). |
* |
* For JPEG, all flavors are allowed: |
* - gray scales |
* - true colors (24 bits) |
* - CMYK (32 bits) |
* |
* For PNG, are allowed: |
* - gray scales on at most 8 bits (256 levels) |
* - indexed colors |
* - true colors (24 bits) |
* but are not supported: |
* - Interlacing |
* - Alpha channel |
* |
* If a transparent color is defined, it will be taken into account (but |
* will be only interpreted by Acrobat 4 and above). |
* The format can be specified explicitly or inferred from the file |
* extension. |
* It is possible to put a link on the image. |
* |
* Remark: if an image is used several times, only one copy will be |
* embedded in the file. |
* |
* @param string $file Name of the file containing the image. |
* @param float $x Abscissa of the upper-left corner. |
* @param float $y Ordinate of the upper-left corner. |
* @param float $width Width of the image in the page. If equal to zero, |
* it is automatically calculated to keep the |
* original proportions. |
* @param float $height Height of the image in the page. If not specified |
* or equal to zero, it is automatically calculated |
* to keep the original proportions. |
* @param string $type Image format. Possible values are (case |
* insensitive) : JPG, JPEG, PNG. If not specified, |
* the type is inferred from the file extension. |
* @param mixed $link URL or identifier returned by File_PDF::addLink. |
* |
* @see File_PDF::addLink |
*/ |
function image($file, $x, $y, $width = 0, $height = 0, $type = '', |
$link = '') |
{ |
if ($x < 0) { |
$x += $this->w; |
} |
if ($y < 0) { |
$y += $this->h; |
} |
if (!isset($this->_images[$file])) { |
/* First use of image, get some file info. */ |
if ($type == '') { |
$pos = strrpos($file, '.'); |
if ($pos === false) { |
return $this->raiseError(sprintf('Image file has no extension and no type was specified: %s', $file)); |
} |
$type = substr($file, $pos + 1); |
} |
$type = strtolower($type); |
$mqr = get_magic_quotes_runtime(); |
set_magic_quotes_runtime(0); |
if ($type == 'jpg' || $type == 'jpeg') { |
$info = $this->_parseJPG($file); |
} elseif ($type == 'png') { |
$info = $this->_parsePNG($file); |
} else { |
return $this->raiseError(sprintf('Unsupported image file type: %s', $type)); |
} |
if (is_a($info, 'PEAR_Error')) { |
return $info; |
} |
set_magic_quotes_runtime($mqr); |
$info['i'] = count($this->_images) + 1; |
$this->_images[$file] = $info; |
} else { |
$info = $this->_images[$file]; |
} |
/* Make sure all vars are converted to pt scale. */ |
$x = $this->_toPt($x); |
$y = $this->_toPt($y); |
$width = $this->_toPt($width); |
$height = $this->_toPt($height); |
/* If not specified do automatic width and height calculations. */ |
if (empty($width) && empty($height)) { |
$width = $info['w']; |
$height = $info['h']; |
} elseif (empty($width)) { |
$width = $height * $info['w'] / $info['h']; |
} elseif (empty($height)) { |
$height = $width * $info['h'] / $info['w']; |
} |
$this->_out(sprintf('q %.2f 0 0 %.2f %.2f %.2f cm /I%d Do Q', $width, $height, $x, $this->hPt - ($y + $height), $info['i'])); |
/* Set any link if requested. */ |
if ($link) { |
$this->_link($x, $y, $width, $height, $link); |
} |
} |
/** |
* Performs a line break. The current abscissa goes back to the left |
* margin and the ordinate increases by the amount passed in parameter. |
* |
* @param float $height The height of the break. By default, the value |
* equals the height of the last printed cell. |
* |
* @see File_PDF::cell |
*/ |
function newLine($height = '') |
{ |
$this->x = $this->_left_margin; |
if (is_string($height)) { |
$this->y += $this->_last_height; |
} else { |
$this->y += $height; |
} |
} |
/** |
* Returns the abscissa of the current position in user units. |
* |
* @return float |
* |
* @see File_PDF::setX |
* @see File_PDF::getY |
* @see File_PDF::setY |
*/ |
function getX() |
{ |
return $this->x; |
} |
/** |
* Defines the abscissa of the current position. If the passed value is |
* negative, it is relative to the right of the page. |
* |
* @param float $x The value of the abscissa. |
* |
* @see File_PDF::getX |
* @see File_PDF::getY |
* @see File_PDF::setY |
* @see File_PDF::setXY |
*/ |
function setX($x) |
{ |
if ($x >= 0) { |
/* Absolute value. */ |
$this->x = $x; |
} else { |
/* Negative, so relative to right edge of the page. */ |
$this->x = $this->w + $x; |
} |
} |
/** |
* Returns the ordinate of the current position in user units. |
* |
* @return float |
* |
* @see File_PDF::setY |
* @see File_PDF::getX |
* @see File_PDF::setX |
*/ |
function getY() |
{ |
return $this->y; |
} |
/** |
* Defines the ordinate of the current position. If the passed value is |
* negative, it is relative to the bottom of the page. |
* |
* @param float $y The value of the ordinate. |
* |
* @see File_PDF::getX |
* @see File_PDF::getY |
* @see File_PDF::setY |
* @see File_PDF::setXY |
*/ |
function setY($y) |
{ |
if ($y >= 0) { |
/* Absolute value. */ |
$this->y = $y; |
} else { |
/* Negative, so relative to bottom edge of the page. */ |
$this->y = $this->h + $y; |
} |
} |
/** |
* Defines the abscissa and ordinate of the current position. If the |
* passed values are negative, they are relative respectively to the right |
* and bottom of the page. |
* |
* @param float $x The value of the abscissa. |
* @param float $y The value of the ordinate. |
* |
* @see File_PDF::setX |
* @see File_PDF::setY |
*/ |
function setXY($x, $y) |
{ |
$this->setY($y); |
$this->setX($x); |
} |
/** |
* Returns the raw PDF file. |
* |
* @see File_PDF::output |
*/ |
function getOutput() |
{ |
/* Check whether file has been closed. */ |
if ($this->_state < 3) { |
$this->close(); |
} |
return $this->_buffer; |
} |
/** |
* Function to output the buffered data to the browser. |
* |
* @param string $filename The filename for the output file. |
* @param boolean $inline True if inline, false if attachment. |
*/ |
function output($filename = 'unknown.pdf', $inline = false) |
{ |
/* Check whether file has been closed. */ |
if ($this->_state < 3) { |
$this->close(); |
} |
/* Check if headers have been sent. */ |
if (headers_sent()) { |
return $this->raiseError('Unable to send PDF file, some data has already been output to browser.'); |
} |
/* If HTTP_Download is not available return a PEAR_Error. */ |
if (!include_once 'HTTP/Download.php') { |
return $this->raiseError('Missing PEAR package HTTP_Download.'); |
} |
/* Params for the output. */ |
$disposition = !$inline ? HTTP_DOWNLOAD_ATTACHMENT : HTTP_DOWNLOAD_INLINE; |
$params = array('data' => $this->_buffer, |
'contenttype' => 'application/pdf', |
'contentdisposition' => array($disposition, $filename)); |
/* Output the file. */ |
return HTTP_Download::staticSend($params); |
} |
/** |
* Function to save the PDF file somewhere local to the server. |
* |
* @param string $filename The filename for the output file. |
*/ |
function save($filename = 'unknown.pdf') |
{ |
/* Check whether file has been closed. */ |
if ($this->_state < 3) { |
$this->close(); |
} |
$f = fopen($filename, 'wb'); |
if (!$f) { |
return $this->raiseError(sprintf('Unable to save PDF file: %s', $filename)); |
} |
fwrite($f, $this->_buffer, strlen($this->_buffer)); |
fclose($f); |
} |
function _toPt($val) |
{ |
return $val * $this->_scale; |
} |
function &_getFontFile($fontkey, $path = '') |
{ |
static $font_widths; |
if (!isset($font_widths[$fontkey])) { |
if (!empty($path)) { |
$file = $path . strtolower($fontkey) . '.php'; |
} else { |
$file = 'File/PDF/fonts/' . strtolower($fontkey) . '.php'; |
} |
include $file; |
if (!isset($font_widths[$fontkey])) { |
return $this->raiseError(sprintf('Could not include font metric file: %s', $file)); |
} |
} |
return $font_widths; |
} |
function _link($x, $y, $width, $height, $link) |
{ |
/* Save link to page links array. */ |
$this->_page_links[$this->_page][] = array($x, $y, $width, $height, $link); |
} |
function _beginDoc() |
{ |
/* Start document, but only if not yet started. */ |
if ($this->_state < 1) { |
$this->_state = 1; |
$this->_out('%PDF-1.3'); |
} |
} |
function _putPages() |
{ |
$nb = $this->_page; |
if (!empty($this->_alias_nb_pages)) { |
/* Replace number of pages. */ |
for ($n = 1; $n <= $nb; $n++) { |
$this->_pages[$n] = str_replace($this->_alias_nb_pages, $nb, $this->_pages[$n]); |
} |
} |
if ($this->_default_orientation == 'P') { |
$wPt = $this->fwPt; |
$hPt = $this->fhPt; |
} else { |
$wPt = $this->fhPt; |
$hPt = $this->fwPt; |
} |
$filter = ($this->_compress) ? '/Filter /FlateDecode ' : ''; |
for ($n = 1; $n <= $nb; $n++) { |
/* Page */ |
$this->_newobj(); |
$this->_out('<</Type /Page'); |
$this->_out('/Parent 1 0 R'); |
if (isset($this->_orientation_changes[$n])) { |
$this->_out(sprintf('/MediaBox [0 0 %.2f %.2f]', $hPt, $wPt)); |
} |
$this->_out('/Resources 2 0 R'); |
if (isset($this->_page_links[$n])) { |
/* Links */ |
$annots = '/Annots ['; |
foreach ($this->_page_links[$n] as $pl) { |
$rect = sprintf('%.2f %.2f %.2f %.2f', $pl[0], $pl[1], $pl[0] + $pl[2], $pl[1] - $pl[3]); |
$annots .= '<</Type /Annot /Subtype /Link /Rect [' . $rect . '] /Border [0 0 0] '; |
if (is_string($pl[4])) { |
$annots .= '/A <</S /URI /URI ' . $this->_textString($pl[4]) . '>>>>'; |
} else { |
$l = $this->_links[$pl[4]]; |
$height = isset($this->_orientation_changes[$l[0]]) ? $wPt : $hPt; |
$annots .= sprintf('/Dest [%d 0 R /XYZ 0 %.2f null]>>', 1 + 2 * $l[0], $height - $l[1] * $this->_scale); |
} |
} |
$this->_out($annots.']'); |
} |
$this->_out('/Contents ' . ($this->_n + 1) . ' 0 R>>'); |
$this->_out('endobj'); |
/* Page content */ |
$p = ($this->_compress) ? gzcompress($this->_pages[$n]) : $this->_pages[$n]; |
$this->_newobj(); |
$this->_out('<<' . $filter . '/Length ' . strlen($p) . '>>'); |
$this->_putStream($p); |
$this->_out('endobj'); |
} |
/* Pages root */ |
$this->_offsets[1] = strlen($this->_buffer); |
$this->_out('1 0 obj'); |
$this->_out('<</Type /Pages'); |
$kids = '/Kids ['; |
for ($i = 0; $i < $nb; $i++) { |
$kids .= (3 + 2 * $i) . ' 0 R '; |
} |
$this->_out($kids . ']'); |
$this->_out('/Count ' . $nb); |
$this->_out(sprintf('/MediaBox [0 0 %.2f %.2f]', $wPt, $hPt)); |
$this->_out('>>'); |
$this->_out('endobj'); |
} |
function _putFonts() |
{ |
$nf = $this->_n; |
foreach ($this->_diffs as $diff) { |
/* Encodings */ |
$this->_newobj(); |
$this->_out('<</Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences [' . $diff . ']>>'); |
$this->_out('endobj'); |
} |
$mqr = get_magic_quotes_runtime(); |
set_magic_quotes_runtime(0); |
foreach ($this->_font_files as $file => $info) { |
/* Font file embedding. */ |
$this->_newobj(); |
$this->_font_files[$file]['n'] = $this->_n; |
$size = filesize($file); |
if (!$size) { |
return $this->raiseError('Font file not found.'); |
} |
$this->_out('<</Length ' . $size); |
if (substr($file, -2) == '.z') { |
$this->_out('/Filter /FlateDecode'); |
} |
$this->_out('/Length1 ' . $info['length1']); |
if (isset($info['length2'])) { |
$this->_out('/Length2 ' . $info['length2'] . ' /Length3 0'); |
} |
$this->_out('>>'); |
$f = fopen($file, 'rb'); |
$this->_putStream(fread($f, $size)); |
fclose($f); |
$this->_out('endobj'); |
} |
set_magic_quotes_runtime($mqr); |
foreach ($this->_fonts as $k => $font) { |
/* Font objects */ |
$this->_newobj(); |
$this->_fonts[$k]['n'] = $this->_n; |
$name = $font['name']; |
$this->_out('<</Type /Font'); |
$this->_out('/BaseFont /' . $name); |
if ($font['type'] == 'core') { |
/* Standard font. */ |
$this->_out('/Subtype /Type1'); |
if ($name != 'Symbol' && $name != 'ZapfDingbats') { |
$this->_out('/Encoding /WinAnsiEncoding'); |
} |
} else { |
/* Additional font. */ |
$this->_out('/Subtype /' . $font['type']); |
$this->_out('/FirstChar 32'); |
$this->_out('/LastChar 255'); |
$this->_out('/Widths ' . ($this->_n + 1) . ' 0 R'); |
$this->_out('/FontDescriptor ' . ($this->_n + 2) . ' 0 R'); |
if ($font['enc']) { |
if (isset($font['diff'])) { |
$this->_out('/Encoding ' . ($nf + $font['diff']).' 0 R'); |
} else { |
$this->_out('/Encoding /WinAnsiEncoding'); |
} |
} |
} |
$this->_out('>>'); |
$this->_out('endobj'); |
if ($font['type'] != 'core') { |
/* Widths. */ |
$this->_newobj(); |
$cw = &$font['cw']; |
$s = '['; |
for ($i = 32; $i <= 255; $i++) { |
$s .= $cw[chr($i)] . ' '; |
} |
$this->_out($s . ']'); |
$this->_out('endobj'); |
/* Descriptor. */ |
$this->_newobj(); |
$s = '<</Type /FontDescriptor /FontName /' . $name; |
foreach ($font['desc'] as $k => $v) { |
$s .= ' /' . $k . ' ' . $v; |
} |
$file = $font['file']; |
if ($file) { |
$s .= ' /FontFile' . ($font['type'] == 'Type1' ? '' : '2') . ' ' . $this->_font_files[$file]['n'] . ' 0 R'; |
} |
$this->_out($s . '>>'); |
$this->_out('endobj'); |
} |
} |
} |
function _putImages() |
{ |
$filter = ($this->_compress) ? '/Filter /FlateDecode ' : ''; |
foreach ($this->_images as $file => $info) { |
$this->_newobj(); |
$this->_images[$file]['n'] = $this->_n; |
$this->_out('<</Type /XObject'); |
$this->_out('/Subtype /Image'); |
$this->_out('/Width ' . $info['w']); |
$this->_out('/Height ' . $info['h']); |
if ($info['cs'] == 'Indexed') { |
$this->_out('/ColorSpace [/Indexed /DeviceRGB ' . (strlen($info['pal'])/3 - 1) . ' ' . ($this->_n + 1).' 0 R]'); |
} else { |
$this->_out('/ColorSpace /' . $info['cs']); |
if ($info['cs'] == 'DeviceCMYK') { |
$this->_out('/Decode [1 0 1 0 1 0 1 0]'); |
} |
} |
$this->_out('/BitsPerComponent ' . $info['bpc']); |
$this->_out('/Filter /' . $info['f']); |
if (isset($info['parms'])) { |
$this->_out($info['parms']); |
} |
if (isset($info['trns']) && is_array($info['trns'])) { |
$trns = ''; |
$i_max = count($info['trns']); |
for ($i = 0; $i < $i_max; $i++) { |
$trns .= $info['trns'][$i] . ' ' . $info['trns'][$i].' '; |
} |
$this->_out('/Mask [' . $trns . ']'); |
} |
$this->_out('/Length ' . strlen($info['data']) . '>>'); |
$this->_putStream($info['data']); |
$this->_out('endobj'); |
/* Palette. */ |
if ($info['cs'] == 'Indexed') { |
$this->_newobj(); |
$pal = ($this->_compress) ? gzcompress($info['pal']) : $info['pal']; |
$this->_out('<<' . $filter . '/Length ' . strlen($pal) . '>>'); |
$this->_putStream($pal); |
$this->_out('endobj'); |
} |
} |
} |
function _putResources() |
{ |
$this->_putFonts(); |
$this->_putImages(); |
/* Resource dictionary */ |
$this->_offsets[2] = strlen($this->_buffer); |
$this->_out('2 0 obj'); |
$this->_out('<</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]'); |
$this->_out('/Font <<'); |
foreach ($this->_fonts as $font) { |
$this->_out('/F' . $font['i'] . ' ' . $font['n'] . ' 0 R'); |
} |
$this->_out('>>'); |
if (count($this->_images)) { |
$this->_out('/XObject <<'); |
foreach ($this->_images as $image) { |
$this->_out('/I' . $image['i'] . ' ' . $image['n'] . ' 0 R'); |
} |
$this->_out('>>'); |
} |
$this->_out('>>'); |
$this->_out('endobj'); |
} |
function _putInfo() |
{ |
$this->_out('/Producer ' . $this->_textString('Horde PDF')); |
if (!empty($this->_info['title'])) { |
$this->_out('/Title ' . $this->_textString($this->_info['title'])); |
} |
if (!empty($this->_info['subject'])) { |
$this->_out('/Subject ' . $this->_textString($this->_info['subject'])); |
} |
if (!empty($this->_info['author'])) { |
$this->_out('/Author ' . $this->_textString($this->_info['author'])); |
} |
if (!empty($this->keywords)) { |
$this->_out('/Keywords ' . $this->_textString($this->keywords)); |
} |
if (!empty($this->creator)) { |
$this->_out('/Creator ' . $this->_textString($this->creator)); |
} |
$this->_out('/CreationDate ' . $this->_textString('D:' . date('YmdHis'))); |
} |
function _putCatalog() |
{ |
$this->_out('/Type /Catalog'); |
$this->_out('/Pages 1 0 R'); |
if ($this->_zoom_mode == 'fullpage') { |
$this->_out('/OpenAction [3 0 R /Fit]'); |
} elseif ($this->_zoom_mode == 'fullwidth') { |
$this->_out('/OpenAction [3 0 R /FitH null]'); |
} elseif ($this->_zoom_mode == 'real') { |
$this->_out('/OpenAction [3 0 R /XYZ null null 1]'); |
} elseif (!is_string($this->_zoom_mode)) { |
$this->_out('/OpenAction [3 0 R /XYZ null null ' . ($this->_zoom_mode / 100).']'); |
} |
if ($this->_layout_mode == 'single') { |
$this->_out('/PageLayout /SinglePage'); |
} elseif ($this->_layout_mode == 'continuous') { |
$this->_out('/PageLayout /OneColumn'); |
} elseif ($this->_layout_mode == 'two') { |
$this->_out('/PageLayout /TwoColumnLeft'); |
} |
} |
function _putTrailer() |
{ |
$this->_out('/Size ' . ($this->_n + 1)); |
$this->_out('/Root ' . $this->_n . ' 0 R'); |
$this->_out('/Info ' . ($this->_n - 1) . ' 0 R'); |
} |
function _endDoc() |
{ |
$this->_putPages(); |
$this->_putResources(); |
/* Info */ |
$this->_newobj(); |
$this->_out('<<'); |
$this->_putInfo(); |
$this->_out('>>'); |
$this->_out('endobj'); |
/* Catalog */ |
$this->_newobj(); |
$this->_out('<<'); |
$this->_putCatalog(); |
$this->_out('>>'); |
$this->_out('endobj'); |
/* Cross-ref */ |
$o = strlen($this->_buffer); |
$this->_out('xref'); |
$this->_out('0 ' . ($this->_n + 1)); |
$this->_out('0000000000 65535 f '); |
for ($i = 1; $i <= $this->_n; $i++) { |
$this->_out(sprintf('%010d 00000 n ', $this->_offsets[$i])); |
} |
/* Trailer */ |
$this->_out('trailer'); |
$this->_out('<<'); |
$this->_putTrailer(); |
$this->_out('>>'); |
$this->_out('startxref'); |
$this->_out($o); |
$this->_out('%%EOF'); |
$this->_state = 3; |
} |
function _beginPage($orientation) |
{ |
$this->_page++; |
$this->_pages[$this->_page] = ''; |
$this->_state = 2; |
$this->x = $this->_left_margin; |
$this->y = $this->_top_margin; |
$this->_last_height = 0; |
/* Page orientation */ |
if (!$orientation) { |
$orientation = $this->_default_orientation; |
} else { |
$orientation = strtoupper($orientation[0]); |
if ($orientation != $this->_default_orientation) { |
$this->_orientation_changes[$this->_page] = true; |
} |
} |
if ($orientation != $this->_current_orientation) { |
/* Change orientation */ |
if ($orientation == 'P') { |
$this->wPt = $this->fwPt; |
$this->hPt = $this->fhPt; |
$this->w = $this->fw; |
$this->h = $this->fh; |
} else { |
$this->wPt = $this->fhPt; |
$this->hPt = $this->fwPt; |
$this->w = $this->fh; |
$this->h = $this->fw; |
} |
$this->_page_break_trigger = $this->h - $this->_break_margin; |
$this->_current_orientation = $orientation; |
} |
} |
function _endPage() |
{ |
/* End of page contents */ |
$this->_state = 1; |
} |
function _newobj() |
{ |
/* Begin a new object */ |
$this->_n++; |
$this->_offsets[$this->_n] = strlen($this->_buffer); |
$this->_out($this->_n . ' 0 obj'); |
} |
function _doUnderline($x, $y, $text) |
{ |
/* Set the rectangle width according to text width. */ |
$width = $this->getStringWidth($text, true); |
/* Set rectangle position and height, using underline position and |
* thickness settings scaled by the font size. */ |
$y = $y + ($this->_current_font['up'] * $this->_font_size_pt / 1000); |
$height = -$this->_current_font['ut'] * $this->_font_size_pt / 1000; |
return sprintf('%.2f %.2f %.2f %.2f re f', $x, $y, $width, $height); |
} |
function _parseJPG($file) |
{ |
/* Extract info from a JPEG file. */ |
$img = @getimagesize($file); |
if (!$img) { |
return $this->raiseError(sprintf('Missing or incorrect image file: %s', $file)); |
} |
if ($img[2] != 2) { |
return $this->raiseError(sprintf('Not a JPEG file: %s', $file)); |
} |
if (!isset($img['channels']) || $img['channels'] == 3) { |
$colspace = 'DeviceRGB'; |
} elseif ($img['channels'] == 4) { |
$colspace = 'DeviceCMYK'; |
} else { |
$colspace = 'DeviceGray'; |
} |
$bpc = isset($img['bits']) ? $img['bits'] : 8; |
/* Read whole file. */ |
$f = fopen($file, 'rb'); |
$data = fread($f, filesize($file)); |
fclose($f); |
return array('w' => $img[0], 'h' => $img[1], 'cs' => $colspace, 'bpc' => $bpc, 'f' => 'DCTDecode', 'data' => $data); |
} |
function _parsePNG($file) |
{ |
/* Extract info from a PNG file. */ |
$f = fopen($file, 'rb'); |
if (!$f) { |
return $this->raiseError(sprintf('Unable to open image file: %s', $file)); |
} |
/* Check signature. */ |
if (fread($f, 8) != chr(137) . 'PNG' . chr(13) . chr(10) . chr(26) . chr(10)) { |
return $this->raiseError(sprintf('Not a PNG file: %s', $file)); |
} |
/* Read header chunk. */ |
fread($f, 4); |
if (fread($f, 4) != 'IHDR') { |
return $this->raiseError(sprintf('Incorrect PNG file: %s', $file)); |
} |
$width = $this->_freadInt($f); |
$height = $this->_freadInt($f); |
$bpc = ord(fread($f, 1)); |
if ($bpc > 8) { |
return $this->raiseError(sprintf('16-bit depth not supported: %s', $file)); |
} |
$ct = ord(fread($f, 1)); |
if ($ct == 0) { |
$colspace = 'DeviceGray'; |
} elseif ($ct == 2) { |
$colspace = 'DeviceRGB'; |
} elseif ($ct == 3) { |
$colspace = 'Indexed'; |
} else { |
return $this->raiseError(sprintf('Alpha channel not supported: %s', $file)); |
} |
if (ord(fread($f, 1)) != 0) { |
return $this->raiseError(sprintf('Unknown compression method: %s', $file)); |
} |
if (ord(fread($f, 1)) != 0) { |
return $this->raiseError(sprintf('Unknown filter method: %s', $file)); |
} |
if (ord(fread($f, 1)) != 0) { |
return $this->raiseError(sprintf('Interlacing not supported: %s', $file)); |
} |
fread($f, 4); |
$parms = '/DecodeParms <</Predictor 15 /Colors ' . ($ct == 2 ? 3 : 1).' /BitsPerComponent ' . $bpc . ' /Columns ' . $width.'>>'; |
/* Scan chunks looking for palette, transparency and image data. */ |
$pal = ''; |
$trns = ''; |
$data = ''; |
do { |
$n = $this->_freadInt($f); |
$type = fread($f, 4); |
if ($type == 'PLTE') { |
/* Read palette */ |
$pal = fread($f, $n); |
fread($f, 4); |
} elseif ($type == 'tRNS') { |
/* Read transparency info */ |
$t = fread($f, $n); |
if ($ct == 0) { |
$trns = array(ord(substr($t, 1, 1))); |
} elseif ($ct == 2) { |
$trns = array(ord(substr($t, 1, 1)), ord(substr($t, 3, 1)), ord(substr($t, 5, 1))); |
} else { |
$pos = strpos($t, chr(0)); |
if (is_int($pos)) { |
$trns = array($pos); |
} |
} |
fread($f, 4); |
} elseif ($type == 'IDAT') { |
/* Read image data block */ |
$data .= fread($f, $n); |
fread($f, 4); |
} elseif ($type == 'IEND') { |
break; |
} else { |
fread($f, $n + 4); |
} |
} while ($n); |
if ($colspace == 'Indexed' && empty($pal)) { |
return $this->raiseError(sprintf('Missing palette in: %s', $file)); |
} |
fclose($f); |
return array('w' => $width, 'h' => $height, 'cs' => $colspace, 'bpc' => $bpc, 'f' => 'FlateDecode', 'parms' => $parms, 'pal' => $pal, 'trns' => $trns, 'data' => $data); |
} |
function _freadInt($f) |
{ |
/* Read a 4-byte integer from file. */ |
$i = ord(fread($f, 1)) << 24; |
$i += ord(fread($f, 1)) << 16; |
$i += ord(fread($f, 1)) << 8; |
$i += ord(fread($f, 1)); |
return $i; |
} |
function _textString($s) |
{ |
/* Format a text string */ |
return '(' . $this->_escape($s) . ')'; |
} |
function _escape($s) |
{ |
/* Add \ before \, ( and ) */ |
return str_replace(array(')','(','\\'), |
array('\\)','\\(','\\\\'), |
$s); |
} |
function _putStream($s) |
{ |
$this->_out('stream'); |
$this->_out($s); |
$this->_out('endstream'); |
} |
function _out($s) |
{ |
/* Add a line to the document. */ |
if ($this->_state == 2) { |
$this->_pages[$this->_page] .= $s . "\n"; |
} else { |
$this->_buffer .= $s . "\n"; |
} |
} |
} |
/trunk/jrest/lib/SpreadsheetProductor.php |
---|
New file |
0,0 → 1,15 |
<?php |
Class SpreadsheetProductor { |
function initSpreadsheet() { |
require_once("Spreadsheet/Excel/Writer.php"); |
} |
} |
?> |
/trunk/jrest/lib/PDFProductor.php |
---|
New file |
0,0 → 1,14 |
<?php |
Class PDFProductor { |
function initPDF() { |
require_once("PDF.php"); |
} |
} |
?> |
/trunk/jrest/.htaccess |
---|
New file |
0,0 → 1,4 |
RewriteEngine On |
RewriteCond %{REQUEST_FILENAME} !-d |
RewriteCond %{REQUEST_FILENAME} !-f |
RewriteRule ^.*$ /annuaire/jrest/index.php/ |
/trunk/jrest/jrest.ini.php |
---|
New file |
0,0 → 1,35 |
;<?/* |
[settings] |
baseURL = "/annuaire/jrest/" |
; Default |
[appli] |
phptype = mysql |
username = aurelien |
password = Canard |
hostspec = localhost |
database = tela_prod |
; Identification |
[database_ident] |
phptype = mysql |
username = aurelien |
password = Canard |
hostspec = localhost |
database = tela_prod |
annuaire = annuaire_tela |
ann_id = U_MAIL |
ann_pwd = U_PASSWD |
pass_crypt_funct = md5 |
; LOGS |
[log] |
cheminlog = "/home/aurelien/Logs/" |
timezone = "Europe/Paris" |
taillemax = 100000 |
; ADMIN |
[jrest_admin] |
admin = aurelien@tela-botanica.org,david.delon@clapas.net,jpm@tela-botanica.org,marie@tela-botanica.org |
;*/?> |
/trunk/jrest/JRest.php |
---|
New file |
0,0 → 1,302 |
<?php |
// In : utf8 url_encoded (get et post) |
// Out : utf8 |
// TODO : gerer les retours : dans ce controleur : code retour et envoi ... |
class JRest { |
/** Parsed configuration file */ |
private $config; |
/** The HTTP request method used. */ |
private $method = 'GET'; |
/** The HTTP request data sent (if any). */ |
private $requestData = NULL; |
/** Array of strings to convert into the HTTP response. */ |
private $output = array(); |
/** Nom resource. */ |
private $resource = NULL; |
/** Identifiant unique resource. */ |
private $uid = NULL; |
/** |
* Constructor. Parses the configuration file "JRest.ini", grabs any request data sent, records the HTTP |
* request method used and parses the request URL to find out the requested resource |
* @param str iniFile Configuration file to use |
*/ |
public function JRest($iniFile = 'jrest.ini.php') { |
$this->config = parse_ini_file($iniFile, TRUE); |
if (isset($_SERVER['REQUEST_URI']) && isset($_SERVER['REQUEST_METHOD']) && isset($_SERVER['QUERY_STRING'])) { |
if (isset($_SERVER['CONTENT_LENGTH']) && $_SERVER['CONTENT_LENGTH'] > 0) { |
$this->requestData = ''; |
$httpContent = fopen('php://input', 'r'); |
while ($data = fread($httpContent, 1024)) { |
$this->requestData .= $data; |
} |
fclose($httpContent); |
} |
if (strlen($_SERVER['QUERY_STRING']) == 0) { |
$len = strlen($_SERVER['REQUEST_URI']); |
} else { |
$len = -(strlen($_SERVER['QUERY_STRING']) + 1); |
} |
$urlString = substr($_SERVER['REQUEST_URI'], strlen($this->config['settings']['baseURL']), $len); |
$urlParts = explode('/', $urlString); |
if (isset($urlParts[0])) $this->resource = $urlParts[0]; |
if (count($urlParts) > 1 && $urlParts[1] != '') { |
array_shift($urlParts); |
foreach ($urlParts as $uid) { |
if ($uid != '') { |
$this->uid[] = urldecode($uid); |
} |
} |
} |
$this->method = $_SERVER['REQUEST_METHOD']; |
} else { |
trigger_error('I require the server variables REQUEST_URI, REQUEST_METHOD and QUERY_STRING to work.', E_USER_ERROR); |
} |
} |
/** |
* Execute the request. |
*/ |
function exec() { |
switch ($this->method) { |
case 'GET': |
$this->get(); |
break; |
case 'POST': |
$this->post(); |
break; |
case 'DELETE': |
$this->delete(); |
break; |
case 'PUT': |
$this->add(); |
break; |
} |
} |
/** |
* Execute a GET request. A GET request fetches a list of resource when no resource name is given, a list of element |
* when a resource name is given, or a resource element when a resource and resource unique identifier are given. It does not change the |
* database contents. |
*/ |
private function get() { |
if ($this->resource) { |
$resource_file = 'services/'.ucfirst($this->resource).'.php'; |
$resource_class = ucfirst($this->resource); |
if (file_exists($resource_file)) { |
include_once $resource_file; |
if (class_exists($resource_class)) { |
$service = new $resource_class($this->config); |
if ($this->uid) { // get a resource element |
if (method_exists($service, 'getElement')) { |
$service->getElement($this->uid); |
} |
} elseif (method_exists($service, 'getRessource')) { // get all elements of a ressource |
$service->getRessource(); |
} |
} |
} |
} else { // get resources |
// include set.jrest.php, instanticiation et appel |
} |
} |
private function post() { |
$pairs = array(); |
// Récupération des paramètres passés dans le contenu de la requête HTTP (= POST) |
if ($this->requestData) { |
$pairs = $this->parseRequestData(); |
} |
// Ajout des informations concernant l'upload de fichier passées dans la variable $_FILE |
if(isset($_FILES)) { |
foreach ($_FILES as $v) { |
$pairs[$v['name']] = $v; |
} |
// Ne pas effacer cette ligne ! Elle est indispensable pour les services du Carnet en ligne |
// qui n'utilisent que le tableau pairs dans les posts |
$pairs = array_merge($pairs, $_POST); |
} |
// gestion du contenu du post |
if(isset($_POST)) |
{ |
// Safari ne sait pas envoyer des DELETE avec gwt... |
// Nous utilisons le parametre "action" passé dans le POST qui doit contenir DELETE pour lancer la supression |
if ($pairs['action'] == 'DELETE') { |
$this->delete(); |
return; |
} |
if (count($pairs) != 0) { |
if ($this->uid) { // get a resource element |
$resource_file = 'services/'.ucfirst($this->resource).'.php'; |
$resource_class = ucfirst($this->resource); |
if (file_exists($resource_file)) { |
include_once $resource_file; |
if (class_exists($resource_class)) { |
$service = new $resource_class($this->config); |
if (method_exists($service,'updateElement')) { // Update element |
// TODO : a voir le retour ... |
if ($service->updateElement($this->uid, $pairs)) { |
$this->created(); |
} |
} |
} |
} |
} else { // get all elements of a ressource |
$this->add($pairs); |
} |
} else { |
$this->lengthRequired(); |
} |
} |
} |
private function delete() { |
$resource_file = 'services/'.ucfirst($this->resource).'.php'; |
$resource_class = ucfirst($this->resource); |
if (file_exists($resource_file)) { |
include_once $resource_file; |
if (class_exists($resource_class)) { |
$service = new $resource_class($this->config); |
if ($this->uid) { // get a resource element |
if (method_exists($service, 'deleteElement')) { // Delete element |
if ($service->deleteElement($this->uid)) { |
$this->noContent(); |
} |
} |
} |
} |
} |
} |
private function add($pairs = null) { |
if (is_null($pairs)) { |
$pairs = array(); |
// Récupération des paramètres passés dans le contenu de la requête HTTP (= POST) |
// FIXME : vérifier que l'on récupère bien les données passées par PUT |
if ($this->requestData) { |
$pairs = $this->parseRequestData(); |
} |
} |
if (count($pairs) != 0) { |
$resource_file = 'services/'.ucfirst($this->resource).'.php'; |
$resource_class = ucfirst($this->resource); |
if (file_exists($resource_file)) { |
include_once $resource_file; |
if (class_exists($resource_class)) { |
$service = new $resource_class($this->config); |
if (method_exists($service,'createElement')) { // Create a new element |
if ($service->createElement($pairs)) { |
$this->created(); |
} |
} |
} |
} |
} else { |
$this->lengthRequired(); |
} |
} |
/** |
* Parse the HTTP request data. |
* @return str[] Array of name value pairs |
*/ |
private function parseRequestData() { |
$values = array(); |
$pairs = explode('&', $this->requestData); |
foreach ($pairs as $pair) { |
$parts = explode('=', $pair); |
if (isset($parts[0]) && isset($parts[1])) { |
$parts[1] = rtrim(urldecode($parts[1])); |
$values[$parts[0]] = $parts[1]; |
} |
} |
return $values; |
} |
/** |
* Send a HTTP 201 response header. |
*/ |
private function created($url = FALSE) { |
header('HTTP/1.0 201 Created'); |
if ($url) { |
header('Location: '.$url); |
} |
} |
/** |
* Send a HTTP 204 response header. |
*/ |
private function noContent() { |
header('HTTP/1.0 204 No Content'); |
} |
/** |
* Send a HTTP 400 response header. |
*/ |
private function badRequest() { |
header('HTTP/1.0 400 Bad Request'); |
} |
/** |
* Send a HTTP 401 response header. |
*/ |
private function unauthorized($realm = 'JRest') { |
if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW'])) { |
header('WWW-Authenticate: Basic realm="'.$realm.'"'); |
} |
header('HTTP/1.0 401 Unauthorized'); |
} |
/** |
* Send a HTTP 404 response header. |
*/ |
private function notFound() { |
header('HTTP/1.0 404 Not Found'); |
} |
/** |
* Send a HTTP 405 response header. |
*/ |
private function methodNotAllowed($allowed = 'GET, HEAD') { |
header('HTTP/1.0 405 Method Not Allowed'); |
header('Allow: '.$allowed); |
} |
/** |
* Send a HTTP 406 response header. |
*/ |
private function notAcceptable() { |
header('HTTP/1.0 406 Not Acceptable'); |
echo join(', ', array_keys($this->config['renderers'])); |
} |
/** |
* Send a HTTP 411 response header. |
*/ |
private function lengthRequired() { |
header('HTTP/1.0 411 Length Required'); |
} |
/** |
* Send a HTTP 500 response header. |
*/ |
private function internalServerError() { |
header('HTTP/1.0 500 Internal Server Error'); |
} |
} |
?> |
/trunk/jrest/index.php |
---|
New file |
0,0 → 1,42 |
<?php |
// Decommenter ces lignes si version de php < 5 |
//require_once 'lib/JSON.php'; |
// Lazy require |
// TODO : voir si on ne peut pas dépacer ces inclusions directement dans les services. |
//require_once 'lib/DBAccessor.php'; |
//require_once 'lib/SpreadsheetProductor.php'; |
//require_once 'lib/PDFProductor.php'; |
//require 'JRest.php'; |
/** |
* La fonction __autoload() charge dynamiquement les classes trouvées dans le code. |
* |
* Cette fonction est appelée par php5 quand il trouve une instanciation de classe dans le code. |
* |
*@param string le nom de la classe appelée. |
*@return void le fichier contenant la classe doit être inclu par la fonction. |
*/ |
function __autoloadJRest($classe) |
{ |
if (class_exists($classe)) { |
return null; |
} |
$chemins = array('', 'services/', 'services/include/', 'lib/'); |
foreach ($chemins as $chemin) { |
$chemin = $chemin.$classe.'.php'; |
if (file_exists($chemin)) { |
require_once $chemin; |
} |
} |
} |
spl_autoload_register('__autoloadJRest'); |
require_once('../initialisation.php'); |
$jRest =& new JRest(); |
$jRest->exec(); |
?> |
/trunk/jrest/util/images/pme-copy.png |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = image/png |
/trunk/jrest/util/images/pme-copy.png |
---|
New file |
Property changes: |
Added: svn:mime-type |
+image/png |
\ No newline at end of property |
/trunk/jrest/util/images/pme-view.png |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = image/png |
/trunk/jrest/util/images/pme-view.png |
---|
New file |
Property changes: |
Added: svn:mime-type |
+image/png |
\ No newline at end of property |
/trunk/jrest/util/images/alt/pme-change.png |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = image/png |
/trunk/jrest/util/images/alt/pme-change.png |
---|
New file |
Property changes: |
Added: svn:mime-type |
+image/png |
\ No newline at end of property |
/trunk/jrest/util/images/alt/pme-copy.png |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = image/png |
/trunk/jrest/util/images/alt/pme-copy.png |
---|
New file |
Property changes: |
Added: svn:mime-type |
+image/png |
\ No newline at end of property |
/trunk/jrest/util/images/alt/pme-view.png |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = image/png |
/trunk/jrest/util/images/alt/pme-view.png |
---|
New file |
Property changes: |
Added: svn:mime-type |
+image/png |
\ No newline at end of property |
/trunk/jrest/util/images/alt/.directory |
---|
New file |
0,0 → 1,5 |
[Dolphin] |
Timestamp=2010,6,10,16,41,1 |
[Settings] |
ShowDotFiles=true |
/trunk/jrest/util/images/alt/pme-delete.png |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = image/png |
/trunk/jrest/util/images/alt/pme-delete.png |
---|
New file |
Property changes: |
Added: svn:mime-type |
+image/png |
\ No newline at end of property |
/trunk/jrest/util/images/.directory |
---|
New file |
0,0 → 1,2 |
[Dolphin] |
Timestamp=2010,6,10,16,42,12 |
/trunk/jrest/util/images/pme-delete.png |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = image/png |
/trunk/jrest/util/images/pme-delete.png |
---|
New file |
Property changes: |
Added: svn:mime-type |
+image/png |
\ No newline at end of property |
/trunk/jrest/util/images/pme-change.png |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = image/png |
/trunk/jrest/util/images/pme-change.png |
---|
New file |
Property changes: |
Added: svn:mime-type |
+image/png |
\ No newline at end of property |
/trunk/jrest/util/cel_inventory.php |
---|
New file |
0,0 → 1,252 |
<style type="text/css"> |
hr.pme-hr { border: 0px solid; padding: 0px; margin: 0px; border-top-width: 1px; height: 1px; } |
table.pme-main { border: #004d9c 1px solid; border-collapse: collapse; border-spacing: 0px; width: 100%; } |
table.pme-navigation { border: #004d9c 0px solid; border-collapse: collapse; border-spacing: 0px; width: 100%; } |
th.pme-header { border: #004d9c 1px solid; padding: 4px; background: #add8e6; } |
td.pme-key-0, td.pme-value-0, td.pme-help-0, td.pme-navigation-0, td.pme-cell-0, |
td.pme-key-1, td.pme-value-1, td.pme-help-0, td.pme-navigation-1, td.pme-cell-1, |
td.pme-sortinfo, td.pme-filter { border: #004d9c 1px solid; padding: 3px; } |
td.pme-buttons { text-align: left; } |
td.pme-message { text-align: center; } |
td.pme-stats { text-align: right; } |
</style><?php |
/* |
* IMPORTANT NOTE: This generated file contains only a subset of huge amount |
* of options that can be used with phpMyEdit. To get information about all |
* features offered by phpMyEdit, check official documentation. It is available |
* online and also for download on phpMyEdit project management page: |
* |
* http://platon.sk/projects/main_page.php?project_id=5 |
* |
* This file was generated by: |
* |
* phpMyEdit version: 5.6 |
* phpMyEdit.class.php core class: 1.188 |
* phpMyEditSetup.php script: 1.48 |
* generating setup script: 1.48 |
*/ |
// MySQL host name, user name, password, database, and table |
$opts['hn'] = 'localhost'; |
$opts['un'] = 'root'; |
$opts['pw'] = ''; |
$opts['db'] = 'cel'; |
$opts['tb'] = 'cel_inventory'; |
// Name of field which is the unique key |
$opts['key'] = 'id'; |
// Type of key field (int/real/string/date etc.) |
$opts['key_type'] = 'int'; |
// Sorting field(s) |
$opts['sort_field'] = array('id'); |
// Number of records to display on the screen |
// Value of -1 lists all records in a table |
$opts['inc'] = 15; |
// Options you wish to give the users |
// A - add, C - change, P - copy, V - view, D - delete, |
// F - filter, I - initial sort suppressed |
$opts['options'] = 'ACPVDF'; |
// Number of lines to display on multiple selection filters |
$opts['multiple'] = '4'; |
// Navigation style: B - buttons (default), T - text links, G - graphic links |
// Buttons position: U - up, D - down (default) |
$opts['navigation'] = 'TB'; |
// Display special page elements |
$opts['display'] = array( |
'form' => true, |
'query' => true, |
'sort' => true, |
'time' => true, |
'tabs' => true |
); |
// Set default prefixes for variables |
$opts['js']['prefix'] = 'PME_js_'; |
$opts['dhtml']['prefix'] = 'PME_dhtml_'; |
$opts['cgi']['prefix']['operation'] = 'PME_op_'; |
$opts['cgi']['prefix']['sys'] = 'PME_sys_'; |
$opts['cgi']['prefix']['data'] = 'PME_data_'; |
/* Get the user's default language and use it if possible or you can |
specify particular one you want to use. Refer to official documentation |
for list of available languages. */ |
$opts['language'] = $_SERVER['HTTP_ACCEPT_LANGUAGE']; |
/* Table-level filter capability. If set, it is included in the WHERE clause |
of any generated SELECT statement in SQL query. This gives you ability to |
work only with subset of data from table. |
$opts['filters'] = "column1 like '%11%' AND column2<17"; |
$opts['filters'] = "section_id = 9"; |
$opts['filters'] = "PMEtable0.sessions_count > 200"; |
*/ |
/* Field definitions |
Fields will be displayed left to right on the screen in the order in which they |
appear in generated list. Here are some most used field options documented. |
['name'] is the title used for column headings, etc.; |
['maxlen'] maximum length to display add/edit/search input boxes |
['trimlen'] maximum length of string content to display in row listing |
['width'] is an optional display width specification for the column |
e.g. ['width'] = '100px'; |
['mask'] a string that is used by sprintf() to format field output |
['sort'] true or false; means the users may sort the display on this column |
['strip_tags'] true or false; whether to strip tags from content |
['nowrap'] true or false; whether this field should get a NOWRAP |
['select'] T - text, N - numeric, D - drop-down, M - multiple selection |
['options'] optional parameter to control whether a field is displayed |
L - list, F - filter, A - add, C - change, P - copy, D - delete, V - view |
Another flags are: |
R - indicates that a field is read only |
W - indicates that a field is a password field |
H - indicates that a field is to be hidden and marked as hidden |
['URL'] is used to make a field 'clickable' in the display |
e.g.: 'mailto:$value', 'http://$value' or '$page?stuff'; |
['URLtarget'] HTML target link specification (for example: _blank) |
['textarea']['rows'] and/or ['textarea']['cols'] |
specifies a textarea is to be used to give multi-line input |
e.g. ['textarea']['rows'] = 5; ['textarea']['cols'] = 10 |
['values'] restricts user input to the specified constants, |
e.g. ['values'] = array('A','B','C') or ['values'] = range(1,99) |
['values']['table'] and ['values']['column'] restricts user input |
to the values found in the specified column of another table |
['values']['description'] = 'desc_column' |
The optional ['values']['description'] field allows the value(s) displayed |
to the user to be different to those in the ['values']['column'] field. |
This is useful for giving more meaning to column values. Multiple |
descriptions fields are also possible. Check documentation for this. |
*/ |
$opts['fdd']['id'] = array( |
'name' => 'ID', |
'select' => 'T', |
'options' => 'AVCPDR', // auto increment |
'maxlen' => 20, |
'default' => '0', |
'sort' => true |
); |
$opts['fdd']['identifiant'] = array( |
'name' => 'Identifiant', |
'select' => 'T', |
'maxlen' => 128, |
'sort' => true |
); |
$opts['fdd']['ordre'] = array( |
'name' => 'Ordre', |
'select' => 'T', |
'maxlen' => 20, |
'sort' => true |
); |
$opts['fdd']['nom_sel'] = array( |
'name' => 'Nom sel', |
'select' => 'T', |
'maxlen' => 255, |
'sort' => true |
); |
$opts['fdd']['num_nom_sel'] = array( |
'name' => 'Num nom sel', |
'select' => 'T', |
'maxlen' => 11, |
'sort' => true |
); |
$opts['fdd']['nom_ret'] = array( |
'name' => 'Nom ret', |
'select' => 'T', |
'maxlen' => 255, |
'sort' => true |
); |
$opts['fdd']['num_nom_ret'] = array( |
'name' => 'Num nom ret', |
'select' => 'T', |
'maxlen' => 11, |
'sort' => true |
); |
$opts['fdd']['num_taxon'] = array( |
'name' => 'Num taxon', |
'select' => 'T', |
'maxlen' => 11, |
'sort' => true |
); |
$opts['fdd']['famille'] = array( |
'name' => 'Famille', |
'select' => 'T', |
'maxlen' => 255, |
'sort' => true |
); |
$opts['fdd']['location'] = array( |
'name' => 'Location', |
'select' => 'T', |
'maxlen' => 50, |
'sort' => true |
); |
$opts['fdd']['id_location'] = array( |
'name' => 'ID location', |
'select' => 'T', |
'maxlen' => 10, |
'sort' => true |
); |
$opts['fdd']['date_observation'] = array( |
'name' => 'Date observation', |
'select' => 'T', |
'maxlen' => 19, |
'sort' => true |
); |
$opts['fdd']['station'] = array( |
'name' => 'Station', |
'select' => 'T', |
'maxlen' => 255, |
'sort' => true |
); |
$opts['fdd']['milieu'] = array( |
'name' => 'Milieu', |
'select' => 'T', |
'maxlen' => 255, |
'sort' => true |
); |
$opts['fdd']['commentaire'] = array( |
'name' => 'Commentaire', |
'select' => 'T', |
'maxlen' => 1024, |
'sort' => true |
); |
$opts['fdd']['transmission'] = array( |
'name' => 'Transmission', |
'select' => 'T', |
'maxlen' => 4, |
'sort' => true |
); |
$opts['fdd']['date_creation'] = array( |
'name' => 'Date creation', |
'select' => 'T', |
'maxlen' => 19, |
'sort' => true |
); |
$opts['fdd']['date_modification'] = array( |
'name' => 'Date modification', |
'select' => 'T', |
'maxlen' => 19, |
'sort' => true |
); |
$opts['fdd']['date_transmission'] = array( |
'name' => 'Date transmission', |
'select' => 'T', |
'maxlen' => 19, |
'sort' => true |
); |
// Now important call to phpMyEdit |
require_once 'phpMyEdit.class.php'; |
new phpMyEdit($opts); |
?> |
/trunk/jrest/util/phpMyEditSetup.php |
---|
New file |
0,0 → 1,569 |
<?php |
/* |
* phpMyEdit - instant MySQL table editor and code generator |
* |
* phpMyEditSetup.php - interactive table configuration utility (setup) |
* ____________________________________________________________ |
* |
* Copyright (c) 1999-2002 John McCreesh <jpmcc@users.sourceforge.net> |
* Copyright (c) 2001-2002 Jim Kraai <jkraai@users.sourceforge.net> |
* Versions 5.0 and higher developed by Ondrej Jombik <nepto@php.net> |
* Copyright (c) 2002-2006 Platon Group, http://platon.sk/ |
* All rights reserved. |
* |
* See README file for more information about this software. |
* See COPYING file for license information. |
* |
* Download the latest version from |
* http://platon.sk/projects/phpMyEdit/ |
*/ |
/* $Platon: phpMyEdit/phpMyEditSetup.php,v 1.48 2006-09-09 07:38:54 nepto Exp $ */ |
?> |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" |
"http://www.w3.org/TR/html4/loose.dtd"> |
<html> |
<head> |
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii"> |
<title>phpMyEdit Setup</title> |
<style type="text/css"> |
<!-- |
body { font-family: "Verdana", "Arial", "Sans-Serif"; text-align: left } |
h1 { color: #004d9c; font-size: 13pt; font-weight: bold } |
h2 { color: #004d9c; font-size: 11pt; font-weight: bold } |
h3 { color: #004d9c; font-size: 11pt; } |
p { color: #004d9c; font-size: 9pt; } |
table { border: 1px solid #004d9c; border-collapse: collapse; border-spacing: 0px; } |
td { border: 1px solid; padding: 3px; color: #004d9c; font-size: 9pt; } |
hr |
{ |
height: 1px; |
background-color: #000000; |
color: #000000; |
border: solid #000000 0; |
padding: 0; |
margin: 0; |
border-top-width: 1px; |
} |
--> |
</style> |
</head> |
<body bgcolor="white"> |
<?php |
if (! defined('PHP_EOL')) { |
define('PHP_EOL', strtoupper(substr(PHP_OS, 0, 3) == 'WIN') ? "\r\n" |
: strtoupper(substr(PHP_OS, 0, 3) == 'MAC') ? "\r" : "\n"); |
} |
$hn = @$_POST['hn']; |
$un = @$_POST['un']; |
$pw = @$_POST['pw']; |
if(strlen($_POST['db'])>0) $db = @$_POST['db']; |
if(strlen($_POST['tb'])>0) $tb = @$_POST['tb']; |
$id = @$_POST['id']; |
$submit = @$_POST['submit']; |
$options = @$_POST['options']; |
$baseFilename = @$_POST['baseFilename']; |
$pageTitle = @$_POST['pageTitle']; |
$pageHeader = @$_POST['pageHeader']; |
$HTMLissues = @$_POST['HTMLissues']; |
$CSSstylesheet = @$_POST['CSSstylesheet']; |
$phpExtension = '.php'; |
if (isset($baseFilename) && $baseFilename != '') { |
$phpFile = $baseFilename.$phpExtension; |
//$contentFile = $baseFilename.'Content.inc'; |
$contentFile = $baseFilename.'.php'; |
} elseif (isset($tb)) { |
$phpFile = $tb.$phpExtension; |
//$contentFile = $tb.'Content.inc'; |
$contentFile = $tb.'.php'; |
} else { |
$phpFile = 'index'.$phpExtension; |
//$contentFile = 'Content.inc'; |
$contentFile = 'phpMyEdit-content.php'; |
} |
$buffer = ''; |
function echo_html($x) |
{ |
echo htmlspecialchars($x),PHP_EOL; |
} |
function echo_buffer($x) |
{ |
global $buffer; |
$buffer .= $x.PHP_EOL; |
} |
#:#####################################:# |
#:# Function: check_constraints #:# |
#:# Parameters: tb=table name #:# |
#:# fd=field name #:# |
#:# return: lookup default for #:# |
#:# said constraint #:# |
#:# or null if no #:# |
#:# constraint is found. #:# |
#:# Contributed by Wade Ryan, #:# |
#:# 20060906 #:# |
#:#####################################:# |
function check_constraints($tb,$fd) |
{ |
$query = "show create table $tb"; |
$result = mysql_query($query); |
$tableDef = preg_split('/\n/',mysql_result($result,0,1)); |
$constraint_arg=""; |
while (list($key,$val) = each($tableDef)) { |
$words=preg_split("/[\s'`()]+/", $val); |
if ($words[1] == "CONSTRAINT" && $words[6]=="REFERENCES") { |
if ($words[5]==$fd) { |
$constraint_arg=" 'values' => array(\n". |
" 'table' => '$words[7]',\n". |
" 'column' => '$words[8]'\n". |
" ),\n"; |
} |
} |
} |
return $constraint_arg; |
} |
function get_versions() |
{ |
$ret_ar = array(); |
$dirname = dirname(__FILE__); |
foreach (array( |
'current' => __FILE__, |
'setup' => "$dirname/phpMyEditSetup.php", |
'core' => "$dirname/phpMyEdit.class.php", |
'version' => "$dirname/doc/VERSION") |
as $type => $file) { |
if (@file_exists($file) && @is_readable($file)) { |
if (($f = fopen($file, 'r')) == false) { |
continue; |
} |
$str = trim(fread($f, 4096)); |
if (strpos($str, ' ') === false && strlen($str) < 10) { |
$ret_ar[$type] = $str; |
} else if (preg_match('|\$'.'Platon:\s+\S+,v\s+(\d+.\d+)\s+|', $str, $matches)) { |
$ret_ar[$type] = $matches[1]; |
} |
fclose($f); |
} |
} |
return $ret_ar; |
} |
$self = basename($_SERVER['PHP_SELF']); |
$dbl = @mysql_pconnect($hn, $un, $pw); |
if ((!$dbl) or empty($submit)) { |
echo '<h1>Please log in to your MySQL database</h1>'; |
if (!empty($submit)) { |
echo '<h2>Sorry - login failed - please try again</h2>'.PHP_EOL; |
} |
if (! isset($hn)) { |
$hn = 'localhost'; |
} |
echo ' |
<form action="'.htmlspecialchars($self).'" method="POST"> |
<table border="1" cellpadding="1" cellspacing="0" summary="Login form"> |
<tr> |
<td>Hostname:</td> |
<td><input type="text" name="hn" value="'.htmlspecialchars($hn).'"></td> |
</tr><tr> |
<td>Username:</td> |
<td><input type="text" name="un" value="'.htmlspecialchars($un).'"></td> |
</tr><tr> |
<td>Password:</td> |
<td><input type="password" name="pw" value="'.htmlspecialchars($pw).'"></td> |
</tr><tr> |
<td>Database:</td> |
<td><input type="text" name="db" value="'.htmlspecialchars($db).'"></td> |
</tr><tr> |
<td>Table:</td> |
<td><input type="text" name="tb" value="'.htmlspecialchars($tb).'"></td> |
</tr> |
</table><br> |
<input type="submit" name="submit" value="Submit"> |
</form>'.PHP_EOL; |
} else if (! isset($db)) { |
$dbs = @mysql_list_dbs($dbl); |
$num_dbs = @mysql_num_rows($dbs); |
echo '<h1>Please select a database</h1> |
<form action="'.htmlspecialchars($self).'" method="POST"> |
<input type="hidden" name="hn" value="'.htmlspecialchars($hn).'"> |
<input type="hidden" name="un" value="'.htmlspecialchars($un).'"> |
<input type="hidden" name="pw" value="'.htmlspecialchars($pw).'"> |
<table border="1" cellpadding="1" cellspacing="1" summary="Database selection">'.PHP_EOL; |
for ($i = 0; $i < $num_dbs; $i++) { |
$db = @mysql_db_name($dbs, $i); |
$checked = ! strcasecmp($un, $db) ? ' checked' : ''; |
$db = htmlspecialchars($db); |
echo '<tr><td><input'.$checked.' type="radio" name="db" value="'.$db.'"></td><td>'.$db.'</td></tr>'.PHP_EOL; |
} |
echo '</table><br> |
<input type="submit" name="submit" value="Submit"> |
<input type="submit" name="cancel" value="Cancel"> |
</form>'.PHP_EOL; |
} else if (!isset($tb)) { |
echo '<h1>Please select a table from database: '.htmlspecialchars($db).'</h1> |
<form action="'.htmlspecialchars($self).'" method="POST"> |
<input type="hidden" name="hn" value="'.htmlspecialchars($hn).'"> |
<input type="hidden" name="un" value="'.htmlspecialchars($un).'"> |
<input type="hidden" name="pw" value="'.htmlspecialchars($pw).'"> |
<input type="hidden" name="db" value="'.htmlspecialchars($db).'"> |
<table border="1" cellpadding="1" cellspacing="1" summary="Table selection">'.PHP_EOL; |
$tbs = @mysql_list_tables($db, $dbl); |
$num_tbs = @mysql_num_rows($tbs); |
for ($j = 0; $j < $num_tbs; $j++) { |
$tb = @mysql_tablename($tbs, $j); |
$tb = htmlspecialchars($tb); |
$checked = $j == 0 ? ' checked' : ''; |
echo '<tr><td><input'.$checked.' type="radio" name="tb" value="'.$tb.'"></td><td>'.$tb.'</td></tr>'.PHP_EOL; |
} |
echo '</table><br> |
<input type="submit" name="submit" value="Submit"> |
<input type="submit" name="cancel" value="Cancel"> |
</form>'.PHP_EOL; |
} else if (!isset($id)) { |
echo ' <h1>Please select an identifier from table: '.htmlspecialchars($tb).'</h1> |
<p> |
This field will be used in change, view, copy and delete operations.<br> |
The field should be numeric and must uniquely identify a record. |
</p> |
<p> |
Please note, that there were problems reported by phpMyEdit users |
regarding using MySQL reserved word as unique key name (the example for |
this is "key" name). Thus we recommend you to use another name |
of unique key. Usage of "id" or "ID" should be safe and good idea. |
</p> |
<form action="'.htmlspecialchars($self).'" method="POST"> |
<input type="hidden" name="hn" value="'.htmlspecialchars($hn).'"> |
<input type="hidden" name="un" value="'.htmlspecialchars($un).'"> |
<input type="hidden" name="pw" value="'.htmlspecialchars($pw).'"> |
<input type="hidden" name="db" value="'.htmlspecialchars($db).'"> |
<input type="hidden" name="tb" value="'.htmlspecialchars($tb).'"> |
<table border="1" cellpadding="1" cellspacing="1" summary="Key selection">'.PHP_EOL; |
// <tr><td><input type="radio" name="id" value=""> |
// <td><i>None</i></td><td><i>No id field required</i></td></tr> |
@mysql_select_db($db); |
$tb_desc = @mysql_query("DESCRIBE $tb"); |
$fds = @mysql_list_fields($db,$tb,$dbl); |
for ($j = 0; ($fd = @mysql_field_name($fds, $j)) != false; $j++) { |
$ff = @mysql_field_flags($fds, $j); |
strlen($ff) <= 0 && $ff = '---'; |
$checked = stristr($ff, 'primary_key') ? ' checked' : ''; |
echo '<tr><td><input',$checked,' type="radio" name="id" value="',htmlspecialchars($fd),'"></td>'; |
echo '<td>',htmlspecialchars($fd),'</td>'; |
echo '<td>',htmlspecialchars($ff),'</td>'; |
$r = @mysql_fetch_array($tb_desc, $j); |
} |
echo '</table><br> |
<input type="submit" name="submit" value="Submit"> |
<input type="submit" name="cancel" value="Cancel"> |
</form>'.PHP_EOL; |
} else if (!isset($options)) { |
echo '<h1>Please select additional options</h1> |
<form action="'.htmlspecialchars($self).'" method="POST"> |
<input type="hidden" name="hn" value="'.htmlspecialchars($hn).'"> |
<input type="hidden" name="un" value="'.htmlspecialchars($un).'"> |
<input type="hidden" name="pw" value="'.htmlspecialchars($pw).'"> |
<input type="hidden" name="db" value="'.htmlspecialchars($db).'"> |
<input type="hidden" name="tb" value="'.htmlspecialchars($tb).'"> |
<input type="hidden" name="id" value="'.htmlspecialchars($id).'"> |
<table border="1" cellpadding="1" cellspacing="1" summary="Additional options"> |
<tr><td>Base filename</td><td><input type="text" name=baseFilename value ="'.htmlspecialchars($tb).'"></td></tr> |
<tr><td>Page title</td><td><input type="text" name=pageTitle value ="'.htmlspecialchars($tb).'"></td></tr> |
<tr><td>Page header</td><td><input type="checkbox" name=pageHeader></td></tr> |
<tr><td>HTML header & footer</td><td><input type="checkbox" name=HTMLissues></td></tr> |
<tr><td>CSS basic stylesheet</td><td><input checked type="checkbox" name=CSSstylesheet></td></tr> |
</table><br> |
<input type="submit" name="submit" value="Submit"> |
<input type="submit" name="cancel" value="Cancel"> |
<input type="hidden" name="options" value="1"> |
</form>'.PHP_EOL; |
} else { |
echo '<h1>Here is your phpMyEdit calling program</h1>'.PHP_EOL; |
echo '<h2>You may now copy and paste it into your PHP editor</h2>'.PHP_EOL; |
if ($pageHeader) { |
echo_buffer('<h3>'.$pageTitle.'</h3>'); |
} |
$versions = ''; |
$versions_ar = get_versions(); |
foreach (array( |
'version' => 'phpMyEdit version:', |
'core' => 'phpMyEdit.class.php core class:', |
'setup' => 'phpMyEditSetup.php script:', |
'current' => 'generating setup script:') |
as $type => $desc) { |
$version = isset($versions_ar[$type]) ? $versions_ar[$type] : 'unknown'; |
$versions .= sprintf("\n * %36s %s", $desc, $version); |
} |
echo_buffer("<?php |
/* |
* IMPORTANT NOTE: This generated file contains only a subset of huge amount |
* of options that can be used with phpMyEdit. To get information about all |
* features offered by phpMyEdit, check official documentation. It is available |
* online and also for download on phpMyEdit project management page: |
* |
* http://platon.sk/projects/main_page.php?project_id=5 |
* |
* This file was generated by: |
*$versions |
*/ |
// MySQL host name, user name, password, database, and table |
\$opts['hn'] = '$hn'; |
\$opts['un'] = '$un'; |
\$opts['pw'] = '$pw'; |
\$opts['db'] = '$db'; |
\$opts['tb'] = '$tb'; |
// Name of field which is the unique key |
\$opts['key'] = '$id'; |
// Type of key field (int/real/string/date etc.)"); |
if ($id == '') { |
echo_buffer("\$opts['key_type'] = '';"); |
} else { |
$fds = @mysql_list_fields($db,$tb,$dbl); |
for ($j = 0; ($fd = @mysql_field_name($fds, $j)) != ''; $j++) { |
if ($fd == $id) { |
echo_buffer("\$opts['key_type'] = '".@mysql_field_type($fds, $j)."';"); |
break; |
} |
} |
} |
echo_buffer(" |
// Sorting field(s) |
\$opts['sort_field'] = array('$id'); |
// Number of records to display on the screen |
// Value of -1 lists all records in a table |
\$opts['inc'] = 15; |
// Options you wish to give the users |
// A - add, C - change, P - copy, V - view, D - delete, |
// F - filter, I - initial sort suppressed |
\$opts['options'] = 'ACPVDF'; |
// Number of lines to display on multiple selection filters |
\$opts['multiple'] = '4'; |
// Navigation style: B - buttons (default), T - text links, G - graphic links |
// Buttons position: U - up, D - down (default) |
\$opts['navigation'] = 'DB'; |
// Display special page elements |
\$opts['display'] = array( |
'form' => true, |
'query' => true, |
'sort' => true, |
'time' => true, |
'tabs' => true |
); |
// Set default prefixes for variables |
\$opts['js']['prefix'] = 'PME_js_'; |
\$opts['dhtml']['prefix'] = 'PME_dhtml_'; |
\$opts['cgi']['prefix']['operation'] = 'PME_op_'; |
\$opts['cgi']['prefix']['sys'] = 'PME_sys_'; |
\$opts['cgi']['prefix']['data'] = 'PME_data_'; |
/* Get the user's default language and use it if possible or you can |
specify particular one you want to use. Refer to official documentation |
for list of available languages. */ |
\$opts['language'] = \$_SERVER['HTTP_ACCEPT_LANGUAGE']; |
/* Table-level filter capability. If set, it is included in the WHERE clause |
of any generated SELECT statement in SQL query. This gives you ability to |
work only with subset of data from table. |
\$opts['filters'] = \"column1 like '%11%' AND column2<17\"; |
\$opts['filters'] = \"section_id = 9\"; |
\$opts['filters'] = \"PMEtable0.sessions_count > 200\"; |
*/ |
/* Field definitions |
Fields will be displayed left to right on the screen in the order in which they |
appear in generated list. Here are some most used field options documented. |
['name'] is the title used for column headings, etc.; |
['maxlen'] maximum length to display add/edit/search input boxes |
['trimlen'] maximum length of string content to display in row listing |
['width'] is an optional display width specification for the column |
e.g. ['width'] = '100px'; |
['mask'] a string that is used by sprintf() to format field output |
['sort'] true or false; means the users may sort the display on this column |
['strip_tags'] true or false; whether to strip tags from content |
['nowrap'] true or false; whether this field should get a NOWRAP |
['select'] T - text, N - numeric, D - drop-down, M - multiple selection |
['options'] optional parameter to control whether a field is displayed |
L - list, F - filter, A - add, C - change, P - copy, D - delete, V - view |
Another flags are: |
R - indicates that a field is read only |
W - indicates that a field is a password field |
H - indicates that a field is to be hidden and marked as hidden |
['URL'] is used to make a field 'clickable' in the display |
e.g.: 'mailto:\$value', 'http://\$value' or '\$page?stuff'; |
['URLtarget'] HTML target link specification (for example: _blank) |
['textarea']['rows'] and/or ['textarea']['cols'] |
specifies a textarea is to be used to give multi-line input |
e.g. ['textarea']['rows'] = 5; ['textarea']['cols'] = 10 |
['values'] restricts user input to the specified constants, |
e.g. ['values'] = array('A','B','C') or ['values'] = range(1,99) |
['values']['table'] and ['values']['column'] restricts user input |
to the values found in the specified column of another table |
['values']['description'] = 'desc_column' |
The optional ['values']['description'] field allows the value(s) displayed |
to the user to be different to those in the ['values']['column'] field. |
This is useful for giving more meaning to column values. Multiple |
descriptions fields are also possible. Check documentation for this. |
*/ |
"); |
@mysql_select_db($db); |
$tb_desc = @mysql_query("DESCRIBE $tb"); |
$fds = @mysql_list_fields($db, $tb, $dbl); |
$num_fds = @mysql_num_fields($fds); |
$ts_cnt = 0; |
for ($k = 0; $k < $num_fds; $k++) { |
$fd = mysql_field_name($fds,$k); |
$fm = mysql_fetch_field($fds,$k); |
$fn = strtr($fd, '_-.', ' '); |
$fn = preg_replace('/(^| +)id( +|$)/', '\\1ID\\2', $fn); // uppercase IDs |
$fn = ucfirst($fn); |
$row = @mysql_fetch_array($tb_desc); |
echo_buffer('$opts[\'fdd\'][\''.$fd.'\'] = array('); // ) |
echo_buffer(" 'name' => '".str_replace('\'','\\\'',$fn)."',"); |
$auto_increment = strstr($row[5], 'auto_increment') ? 1 : 0; |
if (substr($row[1],0,3) == 'set') { |
echo_buffer(" 'select' => 'M',"); |
} else { |
echo_buffer(" 'select' => 'T',"); |
} |
if ($auto_increment) { |
echo_buffer(" 'options' => 'AVCPDR', // auto increment"); |
} |
// timestamps are read-only |
else if (@mysql_field_type($fds, $k) == 'timestamp') { |
if ($ts_cnt > 0) { |
echo_buffer(" 'options' => 'AVCPD',"); |
} else { // first timestamp |
echo_buffer(" 'options' => 'AVCPDR', // updated automatically (MySQL feature)"); |
} |
$ts_cnt++; |
} |
echo_buffer(" 'maxlen' => ".@mysql_field_len($fds,$k).','); |
// blobs -> textarea |
if (@mysql_field_type($fds,$k) == 'blob') { |
echo_buffer(" 'textarea' => array("); |
echo_buffer(" 'rows' => 5,"); |
echo_buffer(" 'cols' => 50),"); |
} |
// SETs and ENUMs get special treatment |
if ((substr($row[1],0,3) == 'set' || substr($row[1],0,4) == 'enum') |
&& ! (($pos = strpos($row[1], '(')) === false)) { |
$indent = str_repeat(' ', 18); |
$outstr = substr($row[1], $pos + 2, -2); |
$outstr = explode("','", $outstr); |
$outstr = str_replace("''", "'", $outstr); |
$outstr = str_replace('"', '\\"', $outstr); |
$outstr = implode('",'.PHP_EOL.$indent.'"', $outstr); |
echo_buffer(" 'values' => array(".PHP_EOL.$indent.'"'.$outstr.'"),'); |
} |
// automatic support for Default values |
if ($row[4] != '' && $row[4] != 'NULL') { |
echo_buffer(" 'default' => '".$row[4]."',"); |
} else if ($auto_increment) { |
echo_buffer(" 'default' => '0',"); |
} |
// check for table constraints |
$outstr = check_constraints($tb, $fd); |
if ($outstr != '') { |
echo_buffer($outstr); |
} |
echo_buffer(" 'sort' => true"); |
//echo_buffer(" 'nowrap' => false,"); |
echo_buffer(');'); |
} |
echo_buffer(" |
// Now important call to phpMyEdit |
require_once 'phpMyEdit.class.php'; |
new phpMyEdit(\$opts); |
?> |
"); |
$css_directive = <<<END |
<style type="text/css"> |
hr.pme-hr { border: 0px solid; padding: 0px; margin: 0px; border-top-width: 1px; height: 1px; } |
table.pme-main { border: #004d9c 1px solid; border-collapse: collapse; border-spacing: 0px; width: 100%; } |
table.pme-navigation { border: #004d9c 0px solid; border-collapse: collapse; border-spacing: 0px; width: 100%; } |
th.pme-header { border: #004d9c 1px solid; padding: 4px; background: #add8e6; } |
td.pme-key-0, td.pme-value-0, td.pme-help-0, td.pme-navigation-0, td.pme-cell-0, |
td.pme-key-1, td.pme-value-1, td.pme-help-0, td.pme-navigation-1, td.pme-cell-1, |
td.pme-sortinfo, td.pme-filter { border: #004d9c 1px solid; padding: 3px; } |
td.pme-buttons { text-align: left; } |
td.pme-message { text-align: center; } |
td.pme-stats { text-align: right; } |
</style> |
END; |
if (! $CSSstylesheet) { |
$css_directive = ''; |
} |
if ($HTMLissues) { |
$buffer = <<<END |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" |
"http://www.w3.org/TR/html4/loose.dtd"> |
<html> |
<head> |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
<title>$pageTitle</title> |
$css_directive |
</head> |
<body> |
$buffer |
</body> |
</html> |
END; |
} else if ($CSSstylesheet) { |
$buffer = $css_directive . $buffer; |
} |
// write the content include file |
echo 'Trying to write content file to: <b>'.'./'.$contentFile.'</b><br>'.PHP_EOL; |
$filehandle = @fopen('./'.$contentFile, 'w+'); |
if ($filehandle) { |
fwrite($filehandle, $buffer); |
flush($filehandle); |
fclose($filehandle); |
echo 'phpMyEdit content file written successfully<br>'; |
} else { |
echo 'phpMyEdit content file was NOT written due to inssufficient privileges.<br>'; |
echo 'Please copy and paste content listed below to <i>'.'./'.$contentFile.'</i> file.'; |
} |
echo '<br><hr>'; |
echo '<pre>'; |
echo_html($buffer); |
echo '</pre><hr>'.PHP_EOL; |
} |
?> |
</body> |
</html> |
/trunk/jrest/util/phpMyEdit.class.php |
---|
New file |
0,0 → 1,3312 |
<?php |
/* |
* phpMyEdit - instant MySQL table editor and code generator |
* |
* phpMyEdit.class.php - main table editor class definition file |
* ____________________________________________________________ |
* |
* Copyright (c) 1999-2002 John McCreesh <jpmcc@users.sourceforge.net> |
* Copyright (c) 2001-2002 Jim Kraai <jkraai@users.sourceforge.net> |
* Versions 5.0 and higher developed by Ondrej Jombik <nepto@php.net> |
* Copyright (c) 2002-2006 Platon Group, http://platon.sk/ |
* All rights reserved. |
* |
* See README file for more information about this software. |
* See COPYING file for license information. |
* |
* Download the latest version from |
* http://platon.sk/projects/phpMyEdit/ |
*/ |
/* $Platon: phpMyEdit/phpMyEdit.class.php,v 1.188 2006-09-08 16:30:31 michal Exp $ */ |
/* This is a generic table editing program. The table and fields to be |
edited are defined in the calling program. |
This program works in three passes. |
* Pass 1 (the last part of the program) displays the selected MySQL |
table in a scrolling table on the screen. Radio buttons are used to |
select a record for editing or deletion. If the user chooses Add, |
Change, Copy, View or Delete buttons. |
* Pass 2 starts, displaying the selected record. If the user chooses |
the Save button from this screen. |
* Pass 3 processes the update and the display returns to the |
original table view (Pass 1). |
*/ |
class phpMyEdit_timer /* {{{ */ |
{ |
var $startTime; |
var $started; |
function phpMyEdit_timer($start = true) |
{ |
$this->started = false; |
if ($start) { |
$this->start(); |
} |
} |
function start() |
{ |
$startMtime = explode(' ', microtime()); |
$this->startTime = (double) $startMtime[0] + (double) $startMtime[1]; |
$this->started = true; |
} |
function end($iterations = 1) |
{ |
// get the time, check whether the timer was started later |
$endMtime = explode(' ', microtime()); |
if ($this->started) { |
$endTime = (double)($endMtime[0])+(double)($endMtime[1]); |
$dur = $endTime - $this->startTime; |
$avg = 1000 * $dur / $iterations; |
$avg = round(1000 * $avg) / 1000; |
return $avg; |
} else { |
return 'phpMyEdit_timer ERROR: timer not started'; |
} |
} |
} /* }}} */ |
if (! function_exists('array_search')) { /* {{{ */ |
function array_search($needle, $haystack) |
{ |
foreach ($haystack as $key => $value) { |
if ($needle == $value) |
return $key; |
} |
return false; |
} |
} /* }}} */ |
if (! function_exists('realpath')) { /* {{{ */ |
function realpath($path) |
{ |
return $path; |
} |
} /* }}} */ |
class phpMyEdit |
{ |
// Class variables {{{ |
// Database handling |
var $hn; // hostname |
var $un; // user name |
var $pw; // password |
var $tb; // table |
var $db; // database |
var $dbp; // database with point |
var $dbh; // database handle |
var $close_dbh; // if database handle should be closed |
// Record manipulation |
var $key; // name of field which is the unique key |
var $key_num; // number of field which is the unique key |
var $key_type; // type of key field (int/real/string/date etc.) |
var $key_delim; // character used for key value quoting |
var $rec; // number of record selected for editing |
var $inc; // number of records to display |
var $fm; // first record to display |
var $fl; // is the filter row displayed (boolean) |
var $fds; // sql field names |
var $fdn; // sql field names => $k |
var $num_fds; // number of fields |
var $options; // options for users: ACDFVPI |
var $fdd; // field definitions |
var $qfn; // value of all filters used during the last pass |
var $sfn; // sort field number (- = descending sort order) |
var $cur_tab; // current selected tab |
// Operation |
var $navop; // navigation buttons/operations |
var $sw; // filter display/hide/clear button |
var $operation; // operation to do: Add, Change, Delete |
var $saveadd; |
var $moreadd; |
var $canceladd; |
var $savechange; |
var $morechange; |
var $cancelchange; |
var $savecopy; |
var $cancelcopy; |
var $savedelete; |
var $canceldelete; |
var $cancelview; |
// Additional features |
var $labels; // multilingual labels |
var $cgi; // CGI variable features array |
var $js; // JS configuration array |
var $dhtml; // DHTML configuration array |
var $url; // URL array |
var $message; // informational message to print |
var $notify; // change notification e-mail adresses |
var $logtable; // name of optional logtable |
var $navigation; // navigation style |
var $tabs; // TAB names |
var $timer = null; // phpMyEdit_timer object |
// Predefined variables |
var $comp_ops = array('<'=>'<','<='=>'<=','='=>'=','>='=>'>=','>'=>'>'); |
var $sql_aggrs = array( |
'sum' => 'Total', |
'avg' => 'Average', |
'min' => 'Minimum', |
'max' => 'Maximum', |
'count' => 'Count'); |
var $page_types = array( |
'L' => 'list', |
'F' => 'filter', |
'A' => 'add', |
'V' => 'view', |
'C' => 'change', |
'P' => 'copy', |
'D' => 'delete' |
); |
var $default_buttons = array( |
'L' => array('<<','<','add','view','change','copy','delete','>','>>','goto','goto_combo'), |
'F' => array('<<','<','add','view','change','copy','delete','>','>>','goto','goto_combo'), |
'A' => array('save','more','cancel'), |
'C' => array('save','more','cancel'), |
'P' => array('save', 'cancel'), |
'D' => array('save','cancel'), |
'V' => array('change','cancel') |
); |
// }}} |
/* |
* column specific functions |
*/ |
function col_has_sql($k) { return isset($this->fdd[$k]['sql']); } |
function col_has_sqlw($k) { return isset($this->fdd[$k]['sqlw']) && !$this->virtual($k); } |
function col_has_values($k) { return isset($this->fdd[$k]['values']) || isset($this->fdd[$k]['values2']); } |
function col_has_php($k) { return isset($this->fdd[$k]['php']); } |
function col_has_URL($k) { return isset($this->fdd[$k]['URL']) |
|| isset($this->fdd[$k]['URLprefix']) || isset($this->fdd[$k]['URLpostfix']); } |
function col_has_multiple($k) |
{ return $this->col_has_multiple_select($k) || $this->col_has_checkboxes($k); } |
function col_has_multiple_select($k) |
{ return $this->fdd[$k]['select'] == 'M' && ! $this->fdd[$k]['values']['table']; } |
function col_has_checkboxes($k) |
{ return $this->fdd[$k]['select'] == 'C' && ! $this->fdd[$k]['values']['table']; } |
function col_has_radio_buttons($k) |
{ return $this->fdd[$k]['select'] == 'O' && ! $this->fdd[$k]['values']['table']; } |
function col_has_datemask($k) |
{ return isset($this->fdd[$k]['datemask']) || isset($this->fdd[$k]['strftimemask']); } |
/* |
* functions for indicating whether navigation style is enabled |
*/ |
function nav_buttons() { return stristr($this->navigation, 'B'); } |
function nav_text_links() { return stristr($this->navigation, 'T'); } |
function nav_graphic_links() { return stristr($this->navigation, 'G'); } |
function nav_up() { return (stristr($this->navigation, 'U') && !($this->buttons[$this->page_type]['up'] === false)); } |
function nav_down() { return (stristr($this->navigation, 'D') && !($this->buttons[$this->page_type]['down'] === false)); } |
/* |
* functions for indicating whether operations are enabled |
*/ |
function add_enabled() { return stristr($this->options, 'A'); } |
function change_enabled() { return stristr($this->options, 'C'); } |
function delete_enabled() { return stristr($this->options, 'D'); } |
function filter_enabled() { return stristr($this->options, 'F'); } |
function view_enabled() { return stristr($this->options, 'V'); } |
function copy_enabled() { return stristr($this->options, 'P') && $this->add_enabled(); } |
function tabs_enabled() { return $this->display['tabs'] && count($this->tabs) > 0; } |
function hidden($k) { return stristr($this->fdd[$k]['input'],'H'); } |
function password($k) { return stristr($this->fdd[$k]['input'],'W'); } |
function readonly($k) { return stristr($this->fdd[$k]['input'],'R') || $this->virtual($k); } |
function virtual($k) { return stristr($this->fdd[$k]['input'],'V') && $this->col_has_sql($k); } |
function add_operation() { return $this->operation == $this->labels['Add'] && $this->add_enabled(); } |
function change_operation() { return $this->operation == $this->labels['Change'] && $this->change_enabled(); } |
function copy_operation() { return $this->operation == $this->labels['Copy'] && $this->copy_enabled(); } |
function delete_operation() { return $this->operation == $this->labels['Delete'] && $this->delete_enabled(); } |
function view_operation() { return $this->operation == $this->labels['View'] && $this->view_enabled(); } |
function filter_operation() { return $this->fl && $this->filter_enabled() && $this->list_operation(); } |
function list_operation() { /* covers also filtering page */ return ! $this->change_operation() |
&& ! $this->add_operation() && ! $this->copy_operation() |
&& ! $this->delete_operation() && ! $this->view_operation(); } |
function next_operation() { return ($this->navop == $this->labels['Next']) || ($this->navop == '>'); } |
function prev_operation() { return ($this->navop == $this->labels['Prev']) || ($this->navop == '<'); } |
function first_operation() { return ($this->navop == $this->labels['First']) || ($this->navop == '<<'); } |
function last_operation() { return ($this->navop == $this->labels['Last']) || ($this->navop == '>>'); } |
function clear_operation() { return $this->sw == $this->labels['Clear']; } |
function add_canceled() { return $this->canceladd == $this->labels['Cancel']; } |
function view_canceled() { return $this->cancelview == $this->labels['Cancel']; } |
function change_canceled() { return $this->cancelchange == $this->labels['Cancel']; } |
function copy_canceled() { return $this->cancelcopy == $this->labels['Cancel']; } |
function delete_canceled() { return $this->canceldelete == $this->labels['Cancel']; } |
function is_values2($k, $val = 'X') /* {{{ */ |
{ |
return $val === null || |
(isset($this->fdd[$k]['values2']) && !isset($this->fdd[$k]['values']['table'])); |
} /* }}} */ |
function processed($k) /* {{{ */ |
{ |
if ($this->virtual($k)) { |
return false; |
} |
$options = @$this->fdd[$k]['options']; |
if (! isset($options)) { |
return true; |
} |
return |
($this->saveadd == $this->labels['Save'] && stristr($options, 'A')) || |
($this->moreadd == $this->labels['More'] && stristr($options, 'A')) || |
($this->savechange == $this->labels['Save'] && stristr($options, 'C')) || |
($this->morechange == $this->labels['Apply'] && stristr($options, 'C')) || |
($this->savecopy == $this->labels['Save'] && stristr($options, 'P')) || |
($this->savedelete == $this->labels['Save'] && stristr($options, 'D')); |
} /* }}} */ |
function displayed($k) /* {{{ */ |
{ |
if (is_numeric($k)) { |
$k = $this->fds[$k]; |
} |
$options = @$this->fdd[$k]['options']; |
if (! isset($options)) { |
return true; |
} |
return |
($this->add_operation() && stristr($options, 'A')) || |
($this->view_operation() && stristr($options, 'V')) || |
($this->change_operation() && stristr($options, 'C')) || |
($this->copy_operation() && stristr($options, 'P')) || |
($this->delete_operation() && stristr($options, 'D')) || |
($this->filter_operation() && stristr($options, 'F')) || |
($this->list_operation() && stristr($options, 'L')); |
} /* }}} */ |
function debug_var($name, $val) /* {{{ */ |
{ |
if (is_array($val) || is_object($val)) { |
echo "<pre>$name\n"; |
ob_start(); |
//print_r($val); |
var_dump($val); |
$content = ob_get_contents(); |
ob_end_clean(); |
echo htmlspecialchars($content); |
echo "</pre>\n"; |
} else { |
echo 'debug_var()::<i>',htmlspecialchars($name),'</i>'; |
echo '::<b>',htmlspecialchars($val),'</b>::',"<br />\n"; |
} |
} /* }}} */ |
function myquery($qry, $line = 0, $debug = 0) /* {{{ */ |
{ |
global $debug_query; |
if ($debug_query || $debug) { |
$line = intval($line); |
echo '<h4>MySQL query at line ',$line,'</h4>',htmlspecialchars($qry),'<hr />',"\n"; |
} |
if (isset($this->db)) { |
$ret = @mysql_db_query($this->db, $qry, $this->dbh); |
} else { |
$ret = @mysql_query($qry, $this->dbh); |
} |
if (! $ret) { |
echo '<h4>MySQL error ',mysql_errno($this->dbh),'</h4>'; |
echo htmlspecialchars(mysql_error($this->dbh)),'<hr />',"\n"; |
} |
return $ret; |
} /* }}} */ |
function make_language_labels($language) /* {{{ */ |
{ |
// just try the first language and variant |
// this isn't content-negotiation rfc compliant |
$language = strtoupper($language); |
// try the full language w/ variant |
$file = $this->dir['lang'].'PME.lang.'.$language.'.inc'; |
if (! file_exists($file)) { |
// try the language w/o variant |
$file = $this->dir['lang'].'PME.lang.'.substr($language,0,2).'.inc'; |
} |
if (! file_exists($file)) { |
// default to classical English |
$file = $this->dir['lang'].'PME.lang.EN.inc'; |
} |
$ret = @include($file); |
if (! is_array($ret)) { |
return $ret; |
} |
$small = array( |
'Search' => 'v', |
'Hide' => '^', |
'Clear' => 'X', |
'Query' => htmlspecialchars('>')); |
if ((!$this->nav_text_links() && !$this->nav_graphic_links()) |
|| !isset($ret['Search']) || !isset($ret['Query']) |
|| !isset($ret['Hide']) || !isset($ret['Clear'])) { |
foreach ($small as $key => $val) { |
$ret[$key] = $val; |
} |
} |
return $ret; |
} /* }}} */ |
function set_values($field_num, $prepend = null, $append = null, $strict = false) /* {{{ */ |
{ |
return (array) $prepend + (array) $this->fdd[$field_num]['values2'] |
+ (isset($this->fdd[$field_num]['values']['table']) || $strict |
? $this->set_values_from_table($field_num, $strict) |
: array()) |
+ (array) $append; |
} /* }}} */ |
function set_values_from_table($field_num, $strict = false) /* {{{ */ |
{ |
$db = &$this->fdd[$field_num]['values']['db']; |
$table = &$this->fdd[$field_num]['values']['table']; |
$key = &$this->fdd[$field_num]['values']['column']; |
$desc = &$this->fdd[$field_num]['values']['description']; |
$dbp = isset($db) ? "$db." : $this->dbp; |
$qparts['type'] = 'select'; |
if ($table) { |
$qparts['select'] = 'DISTINCT '.$table.'.'.$key; |
if ($desc && is_array($desc) && is_array($desc['columns'])) { |
$qparts['select'] .= ',CONCAT('; // ) |
$num_cols = sizeof($desc['columns']); |
if (isset($desc['divs'][-1])) { |
$qparts['select'] .= '"'.addslashes($desc['divs'][-1]).'",'; |
} |
foreach ($desc['columns'] as $key => $val) { |
if ($val) { |
$qparts['select'] .= 'IFNULL('.$val.',"")'; |
if ($desc['divs'][$key]) { |
$qparts['select'] .= ',"'.addslashes($desc['divs'][$key]).'"'; |
} |
$qparts['select'] .= ','; |
} |
} |
$qparts['select']{strlen($qparts['select']) - 1} = ')'; |
$qparts['select'] .= ' AS PMEalias'.$field_num; |
$qparts['orderby'] = 'PMEalias'.$field_num; |
} else if ($desc && is_array($desc)) { |
// TODO |
} else if ($desc) { |
$qparts['select'] .= ','.$table.'.'.$desc; |
$qparts['orderby'] = $desc; |
} else if ($key) { |
$qparts['orderby'] = $key; |
} |
$qparts['from'] = "$dbp$table"; |
$ar = array( |
'table' => $table, |
'column' => $column, |
'description' => $desc); |
$qparts['where'] = $this->substituteVars($this->fdd[$field_num]['values']['filters'], $ar); |
if ($this->fdd[$field_num]['values']['orderby']) { |
$qparts['orderby'] = $this->substituteVars($this->fdd[$field_num]['values']['orderby'], $ar); |
} |
} else { /* simple value extraction */ |
$key = &$this->fds[$field_num]; |
$this->virtual($field_num) && $key = $this->fqn($field_num); |
$qparts['select'] = 'DISTINCT '.$key.' AS PMEkey'; |
$qparts['orderby'] = 'PMEkey'; |
$qparts['from'] = $this->dbp.$this->tb; |
} |
$values = array(); |
$res = $this->myquery($this->get_SQL_query($qparts), __LINE__); |
while ($row = @mysql_fetch_array($res, MYSQL_NUM)) { |
$values[$row[0]] = $desc ? $row[1] : $row[0]; |
} |
return $values; |
} /* }}} */ |
function fqn($field, $dont_desc = false, $dont_cols = false) /* {{{ */ |
{ |
is_numeric($field) || $field = array_search($field, $this->fds); |
// if read SQL expression exists use it |
if ($this->col_has_sql($field)) |
return $this->fdd[$field]['sql']; |
// on copy/change always use simple key retrieving |
if ($this->add_operation() |
|| $this->copy_operation() |
|| $this->change_operation()) { |
$ret = 'PMEtable0.'.$this->fds[$field]; |
} else { |
if ($this->fdd[$this->fds[$field]]['values']['description'] && ! $dont_desc) { |
$desc = &$this->fdd[$this->fds[$field]]['values']['description']; |
if (is_array($desc) && is_array($desc['columns'])) { |
$ret = 'CONCAT('; // ) |
$num_cols = sizeof($desc['columns']); |
if (isset($desc['divs'][-1])) { |
$ret .= '"'.addslashes($desc['divs'][-1]).'",'; |
} |
foreach ($desc['columns'] as $key => $val) { |
if ($val) { |
$ret .= 'PMEjoin'.$field.'.'.$val; |
if ($desc['divs'][$key]) { |
$ret .= ',"'.addslashes($desc['divs'][$key]).'"'; |
} |
$ret .= ','; |
} |
} |
$ret{strlen($ret) - 1} = ')'; |
} else if (is_array($desc)) { |
// TODO |
} else { |
$ret = 'PMEjoin'.$field.'.'.$this->fdd[$this->fds[$field]]['values']['description']; |
} |
// TODO: remove me |
} elseif (0 && $this->fdd[$this->fds[$field]]['values']['column'] && ! $dont_cols) { |
$ret = 'PMEjoin'.$field.'.'.$this->fdd[$this->fds[$field]]['values']['column']; |
} else { |
$ret = 'PMEtable0.'.$this->fds[$field]; |
} |
// TODO: not neccessary, remove me! |
if (is_array($this->fdd[$this->fds[$field]]['values2'])) { |
} |
} |
return $ret; |
} /* }}} */ |
function get_SQL_query($parts) /* {{{ */ |
{ |
foreach ($parts as $k => $v) { |
$parts[$k] = trim($parts[$k]); |
} |
switch ($parts['type']) { |
case 'select': |
$ret = 'SELECT '; |
if ($parts['DISTINCT']) |
$ret .= 'DISTINCT '; |
$ret .= $parts['select']; |
$ret .= ' FROM '.$parts['from']; |
if ($parts['where'] != '') |
$ret .= ' WHERE '.$parts['where']; |
if ($parts['groupby'] != '') |
$ret .= ' GROUP BY '.$parts['groupby']; |
if ($parts['having'] != '') |
$ret .= ' HAVING '.$parts['having']; |
if ($parts['orderby'] != '') |
$ret .= ' ORDER BY '.$parts['orderby']; |
if ($parts['limit'] != '') |
$ret .= ' LIMIT '.$parts['limit']; |
if ($parts['procedure'] != '') |
$ret .= ' PROCEDURE '.$parts['procedure']; |
break; |
case 'update': |
$ret = 'UPDATE '.$parts['table']; |
$ret .= ' SET '.$parts['fields']; |
if ($parts['where'] != '') |
$ret .= ' WHERE '.$parts['where']; |
break; |
case 'insert': |
$ret = 'INSERT INTO '.$parts['table']; |
$ret .= ' VALUES '.$parts['values']; |
break; |
case 'delete': |
$ret = 'DELETE FROM '.$parts['table']; |
if ($parts['where'] != '') |
$ret .= ' WHERE '.$parts['where']; |
break; |
default: |
die('unknown query type'); |
break; |
} |
return $ret; |
} /* }}} */ |
function get_SQL_column_list() /* {{{ */ |
{ |
$fields = array(); |
for ($k = 0; $k < $this->num_fds; $k++) { |
if (! $this->displayed[$k] && $k != $this->key_num) { |
continue; |
} |
$fields[] = $this->fqn($k).' AS qf'.$k; |
if ($this->col_has_values($k)) { |
$fields[] = $this->fqn($k, true, true).' AS qf'.$k.'_idx'; |
} |
if ($this->col_has_datemask($k)) { |
$fields[] = 'UNIX_TIMESTAMP('.$this->fqn($k).') AS qf'.$k.'_timestamp'; |
} |
} |
return join(',', $fields); |
} /* }}} */ |
function get_SQL_join_clause() /* {{{ */ |
{ |
$main_table = 'PMEtable0'; |
$join_clause = $this->tb." AS $main_table"; |
for ($k = 0, $numfds = sizeof($this->fds); $k < $numfds; $k++) { |
$main_column = $this->fds[$k]; |
if($this->fdd[$main_column]['values']['db']) { |
$dbp = $this->fdd[$main_column]['values']['db'].'.'; |
} else { |
$dbp = $this->dbp; |
} |
$table = @$this->fdd[$main_column]['values']['table']; |
$join_column = @$this->fdd[$main_column]['values']['column']; |
$join_desc = @$this->fdd[$main_column]['values']['description']; |
if ($join_desc != '' && $join_column != '') { |
$join_table = 'PMEjoin'.$k; |
$ar = array( |
'main_table' => $main_table, |
'main_column' => $main_column, |
'join_table' => $join_table, |
'join_column' => $join_column, |
'join_description' => $join_desc); |
$join_clause .= " LEFT OUTER JOIN $dbp$table AS $join_table ON ("; |
$join_clause .= isset($this->fdd[$main_column]['values']['join']) |
? $this->substituteVars($this->fdd[$main_column]['values']['join'], $ar) |
: "$join_table.$join_column = $main_table.$main_column"; |
if (isset($this->fdd[$main_column]['values']['filters'])) { |
$join_clause .= ' AND '; |
$join_clause .= $this->substituteVars($this->fdd[$main_column]['values']['filters'], $ar); |
} |
$join_clause .= ')'; |
} |
} |
return $join_clause; |
} /* }}} */ |
function get_SQL_where_from_query_opts($qp = null, $text = 0) /* {{{ */ |
{ |
if ($qp == null) { |
$qp = $this->query_opts; |
} |
$where = array(); |
foreach ($qp as $field => $ov) { |
if (is_numeric($field)) { |
$tmp_where = array(); |
foreach ($ov as $field2 => $ov2) { |
$tmp_where[] = sprintf('%s %s %s', $field2, $ov2['oper'], $ov2['value']); |
} |
$where[] = '('.join(' OR ', $tmp_where).')'; |
} else { |
if (is_array($ov['value'])) { |
$tmp_ov_val = ''; |
foreach ($ov['value'] as $ov_val) { |
strlen($tmp_ov_val) > 0 && $tmp_ov_val .= ' OR '; |
$tmp_ov_val .= sprintf('FIND_IN_SET("%s",%s)', $ov_val, $field); |
} |
$where[] = "($tmp_ov_val)"; |
} else { |
$where[] = sprintf('%s %s %s', $field, $ov['oper'], $ov['value']); |
} |
} |
} |
// Add any coder specified filters |
if (! $text && $this->filters) { |
$where[] = '('.$this->filters.')'; |
} |
if (count($where) > 0) { |
if ($text) { |
return str_replace('%', '*', join(' AND ',$where)); |
} else { |
return join(' AND ',$where); |
} |
} |
return ''; /* empty string */ |
} /* }}} */ |
function gather_query_opts() /* {{{ */ |
{ |
$this->query_opts = array(); |
$this->prev_qfn = $this->qfn; |
$this->qfn = ''; |
if ($this->clear_operation()) { |
return; |
} |
// gathers query options into an array, $this->query_opts |
$qo = array(); |
for ($k = 0; $k < $this->num_fds; $k++) { |
$l = 'qf'.$k; |
$lc = 'qf'.$k.'_comp'; |
$li = 'qf'.$k.'_id'; |
$m = $this->get_sys_cgi_var($l); |
$mc = $this->get_sys_cgi_var($lc); |
$mi = $this->get_sys_cgi_var($li); |
if (! isset($m) && ! isset($mi)) { |
continue; |
} |
if (is_array($m) || is_array($mi)) { |
if (is_array($mi)) { |
$m = $mi; |
$l = $li; |
} |
if (in_array('*', $m)) { |
continue; |
} |
if ($this->col_has_values($k) && $this->col_has_multiple($k)) { |
foreach (array_keys($m) as $key) { |
$m[$key] = addslashes($m[$key]); |
} |
$qo[$this->fqn($k)] = array('value' => $m); |
} else { |
$qf_op = ''; |
foreach (array_keys($m) as $key) { |
if ($qf_op == '') { |
$qf_op = 'IN'; |
$qf_val = '"'.addslashes($m[$key]).'"'; |
$afilter = ' IN ("'.addslashes($m[$key]).'"'; // ) |
} else { |
$afilter = $afilter.',"'.addslashes($m[$key]).'"'; |
$qf_val .= ',"'.addslashes($m[$key]).'"'; |
} |
$this->qfn .= '&'.$this->cgi['prefix']['sys'].$l.'['.rawurlencode($key).']='.rawurlencode($m[$key]); |
} |
$afilter = $afilter.')'; |
// XXX: $dont_desc and $dont_cols hack |
$dont_desc = isset($this->fdd[$k]['values']['description']); |
$dont_cols = isset($this->fdd[$k]['values']['column']); |
$qo[$this->fqn($k, $dont_desc, $dont_cols)] = |
array('oper' => $qf_op, 'value' => "($qf_val)"); // ) |
} |
} else if (isset($mi)) { |
if ($mi == '*') { |
continue; |
} |
if ($this->fdd[$k]['select'] != 'M' && $this->fdd[$k]['select'] != 'D' && $mi == '') { |
continue; |
} |
$afilter = addslashes($mi); |
$qo[$this->fqn($k, true, true)] = array('oper' => '=', 'value' => "'$afilter'"); |
$this->qfn .= '&'.$this->cgi['prefix']['sys'].$li.'='.rawurlencode($mi); |
} else if (isset($m)) { |
if ($m == '*') { |
continue; |
} |
if ($this->fdd[$k]['select'] != 'M' && $this->fdd[$k]['select'] != 'D' && $m == '') { |
continue; |
} |
$afilter = addslashes($m); |
if ($this->fdd[$k]['select'] == 'N') { |
$mc = in_array($mc, $this->comp_ops) ? $mc : '='; |
$qo[$this->fqn($k)] = array('oper' => $mc, 'value' => "'$afilter'"); |
$this->qfn .= '&'.$this->cgi['prefix']['sys'].$l .'='.rawurlencode($m); |
$this->qfn .= '&'.$this->cgi['prefix']['sys'].$lc.'='.rawurlencode($mc); |
} else { |
$afilter = '%'.str_replace('*', '%', $afilter).'%'; |
$ids = array(); |
$ar = array(); |
$ar[$this->fqn($k)] = array('oper' => 'LIKE', 'value' => "'$afilter'"); |
if (is_array($this->fdd[$k]['values2'])) { |
foreach ($this->fdd[$k]['values2'] as $key => $val) { |
if (strlen($m) > 0 && stristr($val, $m)) { |
$ids[] = '"'.addslashes($key).'"'; |
} |
} |
if (count($ids) > 0) { |
$ar[$this->fqn($k, true, true)] |
= array('oper' => 'IN', 'value' => '('.join(',', $ids).')'); |
} |
} |
$qo[] = $ar; |
$this->qfn .= '&'.$this->cgi['prefix']['sys'].$l.'='.rawurlencode($m); |
} |
} |
} |
$this->query_opts = $qo; |
} /* }}} */ |
/* |
* Create JavaScripts |
*/ |
function form_begin() /* {{{ */ |
{ |
$page_name = htmlspecialchars($this->page_name); |
if ($this->add_operation() || $this->change_operation() || $this->copy_operation() |
|| $this->view_operation() || $this->delete_operation()) { |
$field_to_tab = array(); |
for ($tab = $k = $this->cur_tab = 0; $k < $this->num_fds; $k++) { |
if (isset($this->fdd[$k]['tab'])) { |
if ($tab == 0 && $k > 0) { |
$this->tabs[0] = 'PMEtab0'; |
$this->cur_tab = 1; |
$tab++; |
} |
if (is_array($this->fdd[$k]['tab'])) { |
$this->tabs[$tab] = @$this->fdd[$k]['tab']['name']; |
$this->fdd[$k]['tab']['default'] && $this->cur_tab = $tab; |
} else { |
$this->tabs[$tab] = @$this->fdd[$k]['tab']; |
} |
$tab++; |
} |
$field_to_tab[$k] = max(0, $tab - 1); |
} |
if (preg_match('/^'.$this->dhtml['prefix'].'tab(\d+)$/', $this->get_sys_cgi_var('cur_tab'), $parts)) { |
$this->cur_tab = $parts[1]; |
} |
if ($this->tabs_enabled()) { |
// initial TAB styles |
echo '<style type="text/css" media="screen">',"\n"; |
for ($i = 0; $i < count($this->tabs); $i++) { |
echo ' #'.$this->dhtml['prefix'].'tab',$i,' { display: '; |
echo (($i == $this->cur_tab || $this->tabs[$i] == 'PMEtab0' ) ? 'block' : 'none') ,'; }',"\n"; |
} |
echo '</style>',"\n"; |
// TAB javascripts |
echo '<script type="text/javascript"><!--',"\n\n"; |
$css_class_name1 = $this->getCSSclass('tab', $position); |
$css_class_name2 = $this->getCSSclass('tab-selected', $position); |
echo 'var '.$this->js['prefix'].'cur_tab = "'.$this->dhtml['prefix'].'tab',$this->cur_tab,'"; |
function '.$this->js['prefix'].'show_tab(tab_name) |
{'; |
if ($this->nav_up()) { |
echo ' |
document.getElementById('.$this->js['prefix'].'cur_tab+"_up_label").className = "',$css_class_name1,'"; |
document.getElementById('.$this->js['prefix'].'cur_tab+"_up_link").className = "',$css_class_name1,'"; |
document.getElementById(tab_name+"_up_label").className = "',$css_class_name2,'"; |
document.getElementById(tab_name+"_up_link").className = "',$css_class_name2,'";'; |
} |
if ($this->nav_down()) { |
echo ' |
document.getElementById('.$this->js['prefix'].'cur_tab+"_down_label").className = "',$css_class_name1,'"; |
document.getElementById('.$this->js['prefix'].'cur_tab+"_down_link").className = "',$css_class_name1,'"; |
document.getElementById(tab_name+"_down_label").className = "',$css_class_name2,'"; |
document.getElementById(tab_name+"_down_link").className = "',$css_class_name2,'";'; |
} |
echo ' |
document.getElementById('.$this->js['prefix'].'cur_tab).style.display = "none"; |
document.getElementById(tab_name).style.display = "block"; |
'.$this->js['prefix'].'cur_tab = tab_name; |
document.'.$this->cgi['prefix']['sys'].'form.'.$this->cgi['prefix']['sys'].'cur_tab.value = tab_name; |
}',"\n\n"; |
echo '// --></script>', "\n"; |
} |
} |
if ($this->add_operation() || $this->change_operation() || $this->copy_operation()) { |
$first_required = true; |
for ($k = 0; $k < $this->num_fds; $k++) { |
if ($this->displayed[$k] && ! $this->readonly($k) && ! $this->hidden($k) |
&& ($this->fdd[$k]['js']['required'] || isset($this->fdd[$k]['js']['regexp']))) { |
if ($first_required) { |
$first_required = false; |
echo '<script type="text/javascript"><!--',"\n"; |
echo ' |
function '.$this->js['prefix'].'trim(str) |
{ |
while (str.substring(0, 1) == " " |
|| str.substring(0, 1) == "\\n" |
|| str.substring(0, 1) == "\\r") |
{ |
str = str.substring(1, str.length); |
} |
while (str.substring(str.length - 1, str.length) == " " |
|| str.substring(str.length - 1, str.length) == "\\n" |
|| str.substring(str.length - 1, str.length) == "\\r") |
{ |
str = str.substring(0, str.length - 1); |
} |
return str; |
} |
function '.$this->js['prefix'].'form_control(theForm) |
{',"\n"; |
} |
if ($this->col_has_values($k)) { |
$condition = 'theForm.'.$this->cgi['prefix']['data'].$this->fds[$k].'.selectedIndex == -1'; |
$multiple = $this->col_has_multiple_select($k); |
} else { |
$condition = ''; |
$multiple = false; |
if ($this->fdd[$k]['js']['required']) { |
$condition = $this->js['prefix'].'trim(theForm.'.$this->cgi['prefix']['data'].$this->fds[$k].'.value) == ""'; |
} |
if (isset($this->fdd[$k]['js']['regexp'])) { |
$condition .= (strlen($condition) > 0 ? ' || ' : ''); |
$condition .= sprintf('!(%s.test('.$this->js['prefix'].'trim(theForm.%s.value)))', |
$this->fdd[$k]['js']['regexp'], $this->cgi['prefix']['data'].$this->fds[$k]); |
} |
} |
/* Multiple selects have their name like ``name[]''. |
It is not possible to work with them directly, because |
theForm.name[].something will result into JavaScript |
syntax error. Following search algorithm is provided |
as a workaround for this. |
*/ |
if ($multiple) { |
echo ' |
multiple_select = null; |
for (i = 0; i < theForm.length; i++) { |
if (theForm.elements[i].name == "',$this->cgi['prefix']['data'].$this->fds[$k],'[]") { |
multiple_select = theForm.elements[i]; |
break; |
} |
} |
if (multiple_select != null && multiple_select.selectedIndex == -1) {'; |
} else { |
echo ' |
if (',$condition,') {'; |
} |
echo ' |
alert("'; |
if (isset($this->fdd[$k]['js']['hint'])) { |
echo htmlspecialchars($this->fdd[$k]['js']['hint']); |
} else { |
echo $this->labels['Please enter'],' ',$this->fdd[$k]['name'],'.'; |
} |
echo '");'; |
if ($this->tabs_enabled() && $field_to_tab[$k] >= $this->cur_tab) { |
echo ' |
'.$this->js['prefix'].'show_tab("'.$this->dhtml['prefix'].'tab',$field_to_tab[$k],'");'; |
} |
echo ' |
theForm.',$this->cgi['prefix']['data'].$this->fds[$k],'.focus(); |
return false; |
}',"\n"; |
} |
} |
if (! $first_required) { |
echo ' |
return true; |
}',"\n\n"; |
echo '// --></script>', "\n"; |
} |
} |
if ($this->filter_operation()) { |
echo '<script type="text/javascript"><!--',"\n"; |
echo ' |
function '.$this->js['prefix'].'filter_handler(theForm, theEvent) |
{ |
var pressed_key = null; |
if (theEvent.which) { |
pressed_key = theEvent.which; |
} else { |
pressed_key = theEvent.keyCode; |
} |
if (pressed_key == 13) { // enter pressed |
theForm.submit(); |
return false; |
} |
return true; |
}',"\n\n"; |
echo '// --></script>', "\n"; |
} |
if ($this->display['form']) { |
echo '<form class="',$this->getCSSclass('form'),'" method="post"'; |
echo ' action="',$page_name,'" name="'.$this->cgi['prefix']['sys'].'form">',"\n"; |
} |
return true; |
} /* }}} */ |
function form_end() /* {{{ */ |
{ |
if ($this->display['form']) { |
echo '</form>',"\n"; |
} |
} /* }}} */ |
function display_tab_labels($position) /* {{{ */ |
{ |
if (! is_array($this->tabs)) { |
return false; |
} |
echo '<table summary="labels" class="',$this->getCSSclass('tab', $position),'">',"\n"; |
echo '<tr class="',$this->getCSSclass('tab', $position),'">',"\n"; |
for ($i = ($this->tabs[0] == 'PMEtab0' ? 1 : 0); $i < count($this->tabs); $i++) { |
$css_class_name = $this->getCSSclass($i != $this->cur_tab ? 'tab' : 'tab-selected', $position); |
echo '<td class="',$css_class_name,'" id="'.$this->dhtml['prefix'].'tab',$i,'_',$position,'_label">'; |
echo '<a class="',$css_class_name,'" id="'.$this->dhtml['prefix'].'tab',$i,'_',$position,'_link'; |
echo '" href="javascript:'.$this->js['prefix'].'show_tab(\''.$this->dhtml['prefix'].'tab',$i,'\')">'; |
echo $this->tabs[$i],'</a></td>',"\n"; |
} |
echo '<td class="',$this->getCSSclass('tab-end', $position),'"> </td>',"\n"; |
echo '</tr>',"\n"; |
echo '</table>',"\n"; |
} /* }}} */ |
/* |
* Display functions |
*/ |
function display_add_record() /* {{{ */ |
{ |
for ($tab = 0, $k = 0; $k < $this->num_fds; $k++) { |
if (isset($this->fdd[$k]['tab']) && $this->tabs_enabled() && $k > 0) { |
$tab++; |
echo '</table>',"\n"; |
echo '</div>',"\n"; |
echo '<div id="'.$this->dhtml['prefix'].'tab',$tab,'">',"\n"; |
echo '<table class="',$this->getCSSclass('main'),'" summary="',$this->tb,'">',"\n"; |
} |
if (! $this->displayed[$k]) { |
continue; |
} |
if ($this->hidden($k)) { |
echo $this->htmlHiddenData($this->fds[$k], $this->fdd[$k]['default']); |
continue; |
} |
$css_postfix = @$this->fdd[$k]['css']['postfix']; |
$css_class_name = $this->getCSSclass('input', null, 'next', $css_postfix); |
$escape = isset($this->fdd[$k]['escape']) ? $this->fdd[$k]['escape'] : true; |
echo '<tr class="',$this->getCSSclass('row', null, true, $css_postfix),'">',"\n"; |
echo '<td class="',$this->getCSSclass('key', null, true, $css_postfix),'">'; |
echo $this->fdd[$k]['name'],'</td>',"\n"; |
echo '<td class="',$this->getCSSclass('value', null, true, $css_postfix),'"'; |
echo $this->getColAttributes($k),">\n"; |
if ($this->col_has_values($k)) { |
$vals = $this->set_values($k); |
$selected = @$this->fdd[$k]['default']; |
$multiple = $this->col_has_multiple($k); |
$readonly = $this->readonly($k); |
$strip_tags = true; |
//$escape = true; |
if ($this->col_has_checkboxes($k) || $this->col_has_radio_buttons($k)) { |
echo $this->htmlRadioCheck($this->cgi['prefix']['data'].$this->fds[$k], |
$css_class_name, $vals, $selected, $multiple, $readonly, |
$strip_tags, $escape); |
} else { |
echo $this->htmlSelect($this->cgi['prefix']['data'].$this->fds[$k], |
$css_class_name, $vals, $selected, $multiple, $readonly, |
$strip_tags, $escape); |
} |
} elseif (isset ($this->fdd[$k]['textarea'])) { |
echo '<textarea class="',$css_class_name,'" name="',$this->cgi['prefix']['data'].$this->fds[$k],'"'; |
echo ($this->readonly($k) ? ' disabled="disabled"' : ''); |
if (intval($this->fdd[$k]['textarea']['rows']) > 0) { |
echo ' rows="',$this->fdd[$k]['textarea']['rows'],'"'; |
} |
if (intval($this->fdd[$k]['textarea']['cols']) > 0) { |
echo ' cols="',$this->fdd[$k]['textarea']['cols'],'"'; |
} |
if (isset($this->fdd[$k]['textarea']['wrap'])) { |
echo ' wrap="',$this->fdd[$k]['textarea']['wrap'],'"'; |
} else { |
echo ' wrap="virtual"'; |
} |
echo '>'; |
if($escape) echo htmlspecialchars($this->fdd[$k]['default']); |
else echo $this->fdd[$k]['default']; |
echo '</textarea>',"\n"; |
} elseif ($this->col_has_php($k)) { |
echo include($this->fdd[$k]['php']); |
} else { |
// Simple edit box required |
$size_ml_props = ''; |
$maxlen = intval($this->fdd[$k]['maxlen']); |
$size = isset($this->fdd[$k]['size']) ? $this->fdd[$k]['size'] : min($maxlen, 60); |
$size && $size_ml_props .= ' size="'.$size.'"'; |
$maxlen && $size_ml_props .= ' maxlength="'.$maxlen.'"'; |
echo '<input class="',$css_class_name,'" '; |
echo ($this->password($k) ? 'type="password"' : 'type="text"'); |
echo ($this->readonly($k) ? ' disabled="disabled"' : ''); |
echo ' name="',$this->cgi['prefix']['data'].$this->fds[$k],'"'; |
echo $size_ml_props,' value="'; |
if($escape) echo htmlspecialchars($this->fdd[$k]['default']); |
else echo $this->fdd[$k]['default']; |
echo '" />'; |
} |
echo '</td>',"\n"; |
if ($this->guidance) { |
$css_class_name = $this->getCSSclass('help', null, true, $css_postfix); |
$cell_value = $this->fdd[$k]['help'] ? $this->fdd[$k]['help'] : ' '; |
echo '<td class="',$css_class_name,'">',$cell_value,'</td>',"\n"; |
} |
echo '</tr>',"\n"; |
} |
} /* }}} */ |
function display_copy_change_delete_record() /* {{{ */ |
{ |
/* |
* For delete or change: SQL SELECT to retrieve the selected record |
*/ |
$qparts['type'] = 'select'; |
$qparts['select'] = $this->get_SQL_column_list(); |
$qparts['from'] = $this->get_SQL_join_clause(); |
$qparts['where'] = '('.$this->fqn($this->key).'=' |
.$this->key_delim.$this->rec.$this->key_delim.')'; |
$res = $this->myquery($this->get_SQL_query($qparts),__LINE__); |
if (! ($row = @mysql_fetch_array($res, MYSQL_ASSOC))) { |
return false; |
} |
for ($tab = 0, $k = 0; $k < $this->num_fds; $k++) { |
if (isset($this->fdd[$k]['tab']) && $this->tabs_enabled() && $k > 0) { |
$tab++; |
echo '</table>',"\n"; |
echo '</div>',"\n"; |
echo '<div id="'.$this->dhtml['prefix'].'tab',$tab,'">',"\n"; |
echo '<table class="',$this->getCSSclass('main'),'" summary="',$this->tb,'">',"\n"; |
} |
if (! $this->displayed[$k]) { |
continue; |
} |
if ($this->copy_operation() || $this->change_operation()) { |
if ($this->hidden($k)) { |
if ($k != $this->key_num) { |
echo $this->htmlHiddenData($this->fds[$k], $row["qf$k"]); |
} |
continue; |
} |
$css_postfix = @$this->fdd[$k]['css']['postfix']; |
echo '<tr class="',$this->getCSSclass('row', null, 'next', $css_postfix),'">',"\n"; |
echo '<td class="',$this->getCSSclass('key', null, true, $css_postfix),'">'; |
echo $this->fdd[$k]['name'],'</td>',"\n"; |
/* There are two possibilities of readonly fields handling: |
1. Display plain text for readonly timestamps, dates and URLs. |
2. Display disabled input field |
In all cases particular readonly field will NOT be saved. */ |
if ($this->readonly($k) && ($this->col_has_datemask($k) || $this->col_has_URL($k))) { |
echo $this->display_delete_field($row, $k); |
} elseif ($this->password($k)) { |
echo $this->display_password_field($row, $k); |
} else { |
echo $this->display_change_field($row, $k); |
} |
if ($this->guidance) { |
$css_class_name = $this->getCSSclass('help', null, true, $css_postfix); |
$cell_value = $this->fdd[$k]['help'] ? $this->fdd[$k]['help'] : ' '; |
echo '<td class="',$css_class_name,'">',$cell_value,'</td>',"\n"; |
} |
echo '</tr>',"\n"; |
} elseif ($this->delete_operation() || $this->view_operation()) { |
$css_postfix = @$this->fdd[$k]['css']['postfix']; |
echo '<tr class="',$this->getCSSclass('row', null, 'next', $css_postfix),'">',"\n"; |
echo '<td class="',$this->getCSSclass('key', null, true, $css_postfix),'">'; |
echo $this->fdd[$k]['name'],'</td>',"\n"; |
if ($this->password($k)) { |
echo '<td class="',$this->getCSSclass('value', null, true, $css_postfix),'"'; |
echo $this->getColAttributes($k),'>',$this->labels['hidden'],'</td>',"\n"; |
} else { |
$this->display_delete_field($row, $k); |
} |
if ($this->guidance) { |
$css_class_name = $this->getCSSclass('help', null, true, $css_postfix); |
$cell_value = $this->fdd[$k]['help'] ? $this->fdd[$k]['help'] : ' '; |
echo '<td class="',$css_class_name,'">',$cell_value,'</td>',"\n"; |
} |
echo '</tr>',"\n"; |
} |
} |
} /* }}} */ |
function display_change_field($row, $k) /* {{{ */ |
{ |
$css_postfix = @$this->fdd[$k]['css']['postfix']; |
$css_class_name = $this->getCSSclass('input', null, true, $css_postfix); |
$escape = isset($this->fdd[$k]['escape']) ? $this->fdd[$k]['escape'] : true; |
echo '<td class="',$this->getCSSclass('value', null, true, $css_postfix),'"'; |
echo $this->getColAttributes($k),">\n"; |
if ($this->col_has_values($k)) { |
$vals = $this->set_values($k); |
$multiple = $this->col_has_multiple($k); |
$readonly = $this->readonly($k); |
$strip_tags = true; |
//$escape = true; |
if ($this->col_has_checkboxes($k) || $this->col_has_radio_buttons($k)) { |
echo $this->htmlRadioCheck($this->cgi['prefix']['data'].$this->fds[$k], |
$css_class_name, $vals, $row["qf$k"], $multiple, $readonly, |
$strip_tags, $escape); |
} else { |
echo $this->htmlSelect($this->cgi['prefix']['data'].$this->fds[$k], |
$css_class_name, $vals, $row["qf$k"], $multiple, $readonly, |
$strip_tags, $escape); |
} |
} elseif (isset($this->fdd[$k]['textarea'])) { |
echo '<textarea class="',$css_class_name,'" name="',$this->cgi['prefix']['data'].$this->fds[$k],'"'; |
echo ($this->readonly($k) ? ' disabled="disabled"' : ''); |
if (intval($this->fdd[$k]['textarea']['rows']) > 0) { |
echo ' rows="',$this->fdd[$k]['textarea']['rows'],'"'; |
} |
if (intval($this->fdd[$k]['textarea']['cols']) > 0) { |
echo ' cols="',$this->fdd[$k]['textarea']['cols'],'"'; |
} |
if (isset($this->fdd[$k]['textarea']['wrap'])) { |
echo ' wrap="',$this->fdd[$k]['textarea']['wrap'],'"'; |
} else { |
echo ' wrap="virtual"'; |
} |
echo '>'; |
if($escape) echo htmlspecialchars($row["qf$k"]); |
else echo $row["qf$k"]; |
echo '</textarea>',"\n"; |
} elseif ($this->col_has_php($k)) { |
echo include($this->fdd[$k]['php']); |
} else { |
$size_ml_props = ''; |
$maxlen = intval($this->fdd[$k]['maxlen']); |
$size = isset($this->fdd[$k]['size']) ? $this->fdd[$k]['size'] : min($maxlen, 60); |
$size && $size_ml_props .= ' size="'.$size.'"'; |
$maxlen && $size_ml_props .= ' maxlength="'.$maxlen.'"'; |
echo '<input class="',$css_class_name,'" type="text" '; |
echo ($this->readonly($k) ? 'disabled="disabled" ' : ''); |
echo 'name="',$this->cgi['prefix']['data'].$this->fds[$k],'" value="'; |
if($escape) echo htmlspecialchars($row["qf$k"]); |
else echo $row["qf$k"]; |
echo '" />',"\n"; |
} |
echo '</td>',"\n"; |
} /* }}} */ |
function display_password_field($row, $k) /* {{{ */ |
{ |
$css_postfix = @$this->fdd[$k]['css']['postfix']; |
echo '<td class="',$this->getCSSclass('value', null, true, $css_postfix),'"'; |
echo $this->getColAttributes($k),">\n"; |
$size_ml_props = ''; |
$maxlen = intval($this->fdd[$k]['maxlen']); |
$size = isset($this->fdd[$k]['size']) ? $this->fdd[$k]['size'] : min($maxlen, 60); |
$size && $size_ml_props .= ' size="'.$size.'"'; |
$maxlen && $size_ml_props .= ' maxlength="'.$maxlen.'"'; |
echo '<input class="',$this->getCSSclass('value', null, true, $css_postfix),'" type="password" '; |
echo ($this->readonly($k) ? 'disabled="disabled" ' : ''); |
echo 'name="',$this->cgi['prefix']['data'].$this->fds[$k],'" value="'; |
echo htmlspecialchars($row["qf$k"]),'" ',$size_ml_props,' />',"\n"; |
echo '</td>',"\n"; |
} /* }}} */ |
function display_delete_field($row, $k) /* {{{ */ |
{ |
$css_postfix = @$this->fdd[$k]['css']['postfix']; |
$css_class_name = $this->getCSSclass('value', null, true, $css_postfix); |
echo '<td class="',$css_class_name,'"',$this->getColAttributes($k),">\n"; |
echo $this->cellDisplay($k, $row, $css_class_name); |
echo '</td>',"\n"; |
} /* }}} */ |
/** |
* Returns CSS class name |
*/ |
function getCSSclass($name, $position = null, $divider = null, $postfix = null) /* {{{ */ |
{ |
static $div_idx = -1; |
$elements = array($this->css['prefix'], $name); |
if ($this->page_type && $this->css['page_type']) { |
if ($this->page_type != 'L' && $this->page_type != 'F') { |
$elements[] = $this->page_types[$this->page_type]; |
} |
} |
if ($position && $this->css['position']) { |
$elements[] = $position; |
} |
if ($divider && $this->css['divider']) { |
if ($divider === 'next') { |
$div_idx++; |
if ($this->css['divider'] > 0 && $div_idx >= $this->css['divider']) { |
$div_idx = 0; |
} |
} |
$elements[] = $div_idx; |
} |
if ($postfix) { |
$elements[] = $postfix; |
} |
return join($this->css['separator'], $elements); |
} /* }}} */ |
/** |
* Returns field cell HTML attributes |
*/ |
function getColAttributes($k) /* {{{ */ |
{ |
$colattrs = ''; |
if (isset($this->fdd[$k]['colattrs'])) { |
$colattrs .= ' '; |
$colattrs .= trim($this->fdd[$k]['colattrs']); |
} |
if (isset($this->fdd[$k]['nowrap'])) { |
$colattrs .= ' nowrap'; |
} |
return $colattrs; |
} /* }}} */ |
/** |
* Substitutes variables in string |
* (this is very simple but secure eval() replacement) |
*/ |
function substituteVars($str, $subst_ar) /* {{{ */ |
{ |
$array = preg_split('/(\\$\w+)/', $str, -1, PREG_SPLIT_DELIM_CAPTURE); |
$count = count($array); |
for ($i = 1; $i < $count; $i += 2) { |
$key = substr($array[$i], 1); |
if (isset($subst_ar[$key])) { |
$array[$i] = $subst_ar[$key]; |
} |
} |
return join('', $array); |
} /* }}} */ |
/** |
* Print URL |
*/ |
function urlDisplay($k, $link_val, $disp_val, $css, $key) /* {{{ */ |
{ |
$escape = isset($this->fdd[$k]['escape']) ? $this->fdd[$k]['escape'] : true; |
$ret = ''; |
$name = $this->fds[$k]; |
$page = $this->page_name; |
$url = $this->cgi['prefix']['sys'].'rec'.'='.$key.'&'.$this->cgi['prefix']['sys'].'fm' |
.'='.$this->fm.'&'.$this->cgi['prefix']['sys'].'fl'.'='.$this->fl; |
$url .= '&'.$this->cgi['prefix']['sys'].'qfn'.'='.rawurlencode($this->qfn).$this->qfn; |
$url .= '&'.$this->get_sfn_cgi_vars().$this->cgi['persist']; |
$ar = array( |
'key' => $key, |
'name' => $name, |
'link' => $link_val, |
'value' => $disp_val, |
'css' => $css, |
'page' => $page, |
'url' => $url |
); |
$urllink = isset($this->fdd[$k]['URL']) |
? $this->substituteVars($this->fdd[$k]['URL'], $ar) |
: $link_val; |
$urldisp = isset($this->fdd[$k]['URLdisp']) |
? $this->substituteVars($this->fdd[$k]['URLdisp'], $ar) |
: $disp_val; |
$target = isset($this->fdd[$k]['URLtarget']) |
? 'target="'.htmlspecialchars($this->fdd[$k]['URLtarget']).'" ' |
: ''; |
$prefix_found = false; |
$postfix_found = false; |
$prefix_ar = @$this->fdd[$k]['URLprefix']; |
$postfix_ar = @$this->fdd[$k]['URLpostfix']; |
is_array($prefix_ar) || $prefix_ar = array($prefix_ar); |
is_array($postfix_ar) || $postfix_ar = array($postfix_ar); |
foreach ($prefix_ar as $prefix) { |
if (! strncmp($prefix, $urllink, strlen($prefix))) { |
$prefix_found = true; |
break; |
} |
} |
foreach ($postfix_ar as $postfix) { |
if (! strncmp($postfix, $urllink, strlen($postfix))) { |
$postfix_found = true; |
break; |
} |
} |
$prefix_found || $urllink = array_shift($prefix_ar).$urllink; |
$postfix_found || $urllink = $urllink.array_shift($postfix_ar); |
if (strlen($urllink) <= 0 || strlen($urldisp) <= 0) { |
$ret = ' '; |
} else { |
if ($escape) { |
$urldisp = htmlspecialchars($urldisp); |
} |
$urllink = htmlspecialchars($urllink); |
$ret = '<a '.$target.'class="'.$css.'" href="'.$urllink.'">'.$urldisp.'</a>'; |
} |
return $ret; |
} /* }}} */ |
function cellDisplay($k, $row, $css) /* {{{ */ |
{ |
$escape = isset($this->fdd[$k]['escape']) ? $this->fdd[$k]['escape'] : true; |
$key_rec = $row['qf'.$this->key_num]; |
if (@$this->fdd[$k]['datemask']) { |
$value = intval($row["qf$k".'_timestamp']); |
$value = $value ? @date($this->fdd[$k]['datemask'], $value) : ''; |
} else if (@$this->fdd[$k]['strftimemask']) { |
$value = intval($row["qf$k".'_timestamp']); |
$value = $value ? @strftime($this->fdd[$k]['strftimemask'], $value) : ''; |
} else if ($this->is_values2($k, $row["qf$k"])) { |
$value = $row['qf'.$k.'_idx']; |
if ($this->fdd[$k]['select'] == 'M') { |
$value_ar = explode(',', $value); |
$value_ar2 = array(); |
foreach ($value_ar as $value_key) { |
if (isset($this->fdd[$k]['values2'][$value_key])) { |
$value_ar2[$value_key] = $this->fdd[$k]['values2'][$value_key]; |
$escape = false; |
} |
} |
$value = join(', ', $value_ar2); |
} else { |
if (isset($this->fdd[$k]['values2'][$value])) { |
$value = $this->fdd[$k]['values2'][$value]; |
$escape = false; |
} |
} |
} elseif (isset($this->fdd[$k]['values2'][$row["qf$k"]])) { |
$value = $this->fdd[$k]['values2'][$row["qf$k"]]; |
} else { |
$value = $row["qf$k"]; |
} |
$original_value = $value; |
if (@$this->fdd[$k]['strip_tags']) { |
$value = strip_tags($value); |
} |
if ($num_ar = @$this->fdd[$k]['number_format']) { |
if (! is_array($num_ar)) { |
$num_ar = array($num_ar); |
} |
if (count($num_ar) == 1) { |
list($nbDec) = $num_ar; |
$value = number_format($value, $nbDec); |
} else if (count($num_ar) == 3) { |
list($nbDec, $decPoint, $thSep) = $num_ar; |
$value = number_format($value, $nbDec, $decPoint, $thSep); |
} |
} |
if (intval($this->fdd[$k]['trimlen']) > 0 && strlen($value) > $this->fdd[$k]['trimlen']) { |
$value = ereg_replace("[\r\n\t ]+",' ',$value); |
$value = substr($value, 0, $this->fdd[$k]['trimlen'] - 3).'...'; |
} |
if (@$this->fdd[$k]['mask']) { |
$value = sprintf($this->fdd[$k]['mask'], $value); |
} |
if ($this->col_has_php($k)) { |
return include($this->fdd[$k]['php']); |
} |
if ($this->col_has_URL($k)) { |
return $this->urlDisplay($k, $original_value, $value, $css, $key_rec); |
} |
if (strlen($value) <= 0) { |
return ' '; |
} |
if ($escape) { |
$value = htmlspecialchars($value); |
} |
return nl2br($value); |
} /* }}} */ |
/** |
* Creates HTML submit input element |
* |
* @param name element name |
* @param label key in the language hash used as label |
* @param css_class_name CSS class name |
* @param js_validation if add JavaScript validation subroutine to button |
* @param disabled if mark the button as disabled |
* @param js any extra text in tags |
*/ |
function htmlSubmit($name, $label, $css_class_name, $js_validation = true, $disabled = false, $js = NULL) /* {{{ */ |
{ |
// Note that <input disabled> isn't valid HTML, but most browsers support it |
if($disabled == -1) return; |
$markdisabled = $disabled ? ' disabled="disabled"' : ''; |
$ret = '<input'.$markdisabled.' type="submit" class="'.$css_class_name |
.'" name="'.$this->cgi['prefix']['sys'].ltrim($markdisabled).$name |
.'" value="'.(isset($this->labels[$label]) ? $this->labels[$label] : $label); |
if ($js_validation) { |
$ret .= '" onclick="return '.$this->js['prefix'].'form_control(this.form);'; |
} |
$ret .='"'; |
if(isset($js)) $ret .= ' '.$js; |
$ret .= ' />'; |
return $ret; |
} /* }}} */ |
/** |
* Creates HTML hidden input element |
* |
* @param name element name |
* @param value value |
*/ |
function htmlHiddenSys($name, $value) /* {{{ */ |
{ |
return $this->htmlHidden($this->cgi['prefix']['sys'].$name, $value); |
} /* }}} */ |
function htmlHiddenData($name, $value) /* {{{ */ |
{ |
return $this->htmlHidden($this->cgi['prefix']['data'].$name, $value); |
} /* }}} */ |
function htmlHidden($name, $value) /* {{{ */ |
{ |
return '<input type="hidden" name="'.htmlspecialchars($name) |
.'" value="'.htmlspecialchars($value).'" />'."\n"; |
} /* }}} */ |
/** |
* Creates HTML select element (tag) |
* |
* @param name element name |
* @param css CSS class name |
* @param kv_array key => value array |
* @param selected selected key (it can be single string, array of |
* keys or multiple values separated by comma) |
* @param multiple bool for multiple selection |
* @param readonly bool for readonly/disabled selection |
* @param strip_tags bool for stripping tags from values |
* @param escape bool for HTML escaping values |
* @param js string to be in the <select >, ususally onchange='..'; |
*/ |
function htmlSelect($name, $css, $kv_array, $selected = null, /* ...) {{{ */ |
/* booleans: */ $multiple = false, $readonly = false, $strip_tags = false, $escape = true, $js = NULL) |
{ |
$ret = '<select class="'.htmlspecialchars($css).'" name="'.htmlspecialchars($name); |
if ($multiple) { |
$ret .= '[]" multiple size="'.$this->multiple; |
if (! is_array($selected) && $selected !== null) { |
$selected = explode(',', $selected); |
} |
} |
$ret .= '"'.($readonly ? ' disabled="disabled"' : '').$js.'>'."\n"; |
if (! is_array($selected)) { |
$selected = $selected === null ? array() : array($selected); |
} |
$found = false; |
foreach ($kv_array as $key => $value) { |
$ret .= '<option value="'.htmlspecialchars($key).'"'; |
if ((! $found || $multiple) && in_array((string) $key, $selected, 1) |
|| (count($selected) == 0 && ! $found && ! $multiple)) { |
$ret .= ' selected="selected"'; |
$found = true; |
} |
$strip_tags && $value = strip_tags($value); |
$escape && $value = htmlspecialchars($value); |
$ret .= '>'.$value.'</option>'."\n"; |
} |
$ret .= '</select>'; |
return $ret; |
} /* }}} */ |
/** |
* Creates HTML checkboxes or radio buttons |
* |
* @param name element name |
* @param css CSS class name |
* @param kv_array key => value array |
* @param selected selected key (it can be single string, array of |
* keys or multiple values separated by comma) |
* @param multiple bool for multiple selection (checkboxes) |
* @param readonly bool for readonly/disabled selection |
* @param strip_tags bool for stripping tags from values |
* @param escape bool for HTML escaping values |
* @param js string to be in the <select >, ususally onchange='..'; |
*/ |
function htmlRadioCheck($name, $css, $kv_array, $selected = null, /* ...) {{{ */ |
/* booleans: */ $multiple = false, $readonly = false, $strip_tags = false, $escape = true, $js = NULL) |
{ |
$ret = ''; |
if ($multiple) { |
if (! is_array($selected) && $selected !== null) { |
$selected = explode(',', $selected); |
} |
} |
if (! is_array($selected)) { |
$selected = $selected === null ? array() : array($selected); |
} |
$found = false; |
foreach ($kv_array as $key => $value) { |
$ret .= '<input type="'.($multiple ? 'checkbox' : 'radio').'" name="'; |
$ret .= htmlspecialchars($name).'[]" value="'.htmlspecialchars($key).'"'; |
if ((! $found || $multiple) && in_array((string) $key, $selected, 1) |
|| (count($selected) == 0 && ! $found && ! $multiple)) { |
$ret .= ' checked'; |
$found = true; |
} |
if ($readonly) { |
$ret .= ' disabled="disabled"'; |
} |
$strip_tags && $value = strip_tags($value); |
$escape && $value = htmlspecialchars($value); |
$ret .= '>'.$value.'<br>'."\n"; |
} |
return $ret; |
} /* }}} */ |
/** |
* Returns original variables HTML code for use in forms or links. |
* |
* @param mixed $origvars string or array of original varaibles |
* @param string $method type of method ("POST" or "GET") |
* @param mixed $default_value default value of variables |
* if null, empty values will be skipped |
* @return get HTML code of original varaibles |
*/ |
function get_origvars_html($origvars, $method = 'post', $default_value = '') /* {{{ */ |
{ |
$ret = ''; |
$method = strtoupper($method); |
if ($method == 'POST') { |
if (! is_array($origvars)) { |
$new_origvars = array(); |
foreach (explode('&', $origvars) as $param) { |
$parts = explode('=', $param, 2); |
if (! isset($parts[1])) { |
$parts[1] = $default_value; |
} |
if (strlen($parts[0]) <= 0) { |
continue; |
} |
$new_origvars[$parts[0]] = $parts[1]; |
} |
$origvars =& $new_origvars; |
} |
foreach ($origvars as $key => $val) { |
if (strlen($val) <= 0 && $default_value === null) { |
continue; |
} |
$key = rawurldecode($key); |
$val = rawurldecode($val); |
$ret .= $this->htmlHidden($key, $val); |
} |
} else if (! strncmp('GET', $method, 3)) { |
if (! is_array($origvars)) { |
$ret .= $origvars; |
} else { |
foreach ($origvars as $key => $val) { |
if (strlen($val) <= 0 && $default_value === null) { |
continue; |
} |
$ret == '' || $ret .= '&'; |
$ret .= htmlspecialchars(rawurlencode($key)); |
$ret .= '='; |
$ret .= htmlspecialchars(rawurlencode($val)); |
} |
} |
if ($method[strlen($method) - 1] == '+') { |
$ret = "?$ret"; |
} |
} else { |
trigger_error('Unsupported Platon::get_origvars_html() method: ' |
.$method, E_USER_ERROR); |
} |
return $ret; |
} /* }}} */ |
function get_sfn_cgi_vars($alternative_sfn = null) /* {{{ */ |
{ |
if ($alternative_sfn === null) { // FAST! (cached return value) |
static $ret = null; |
$ret == null && $ret = $this->get_sfn_cgi_vars($this->sfn); |
return $ret; |
} |
$ret = ''; |
$i = 0; |
foreach ($alternative_sfn as $val) { |
$ret != '' && $ret .= '&'; |
$ret .= rawurlencode($this->cgi['prefix']['sys'].'sfn')."[$i]=".rawurlencode($val); |
$i++; |
} |
return $ret; |
} /* }}} */ |
function get_default_cgi_prefix($type) /* {{{ */ |
{ |
switch ($type) { |
case 'operation': return 'PME_op_'; |
case 'sys': return 'PME_sys_'; |
case 'data': return 'PME_data_'; |
} |
return ''; |
} /* }}} */ |
function get_sys_cgi_var($name, $default_value = null) /* {{{ */ |
{ |
if (isset($this)) { |
return $this->get_cgi_var($this->cgi['prefix']['sys'].$name, $default_value); |
} |
return phpMyEdit::get_cgi_var(phpMyEdit::get_default_cgi_prefix('sys').$name, $default_value); |
} /* }}} */ |
function get_data_cgi_var($name, $default_value = null) /* {{{ */ |
{ |
if (isset($this)) { |
return $this->get_cgi_var($this->cgi['prefix']['data'].$name, $default_value); |
} |
return phpMyEdit::get_cgi_var(phpMyEdit::get_default_cgi_prefix('data').$name, $default_value); |
} /* }}} */ |
function get_cgi_var($name, $default_value = null) /* {{{ */ |
{ |
if (isset($this) && isset($this->cgi['overwrite'][$name])) { |
return $this->cgi['overwrite'][$name]; |
} |
static $magic_quotes_gpc = null; |
if ($magic_quotes_gpc === null) { |
$magic_quotes_gpc = get_magic_quotes_gpc(); |
} |
$var = @$_GET[$name]; |
if (! isset($var)) { |
$var = @$_POST[$name]; |
} |
if (isset($var)) { |
if ($magic_quotes_gpc) { |
if (is_array($var)) { |
foreach (array_keys($var) as $key) { |
$var[$key] = stripslashes($var[$key]); |
} |
} else { |
$var = stripslashes($var); |
} |
} |
} else { |
$var = @$default_value; |
} |
if (isset($this) && $var === null && isset($this->cgi['append'][$name])) { |
return $this->cgi['append'][$name]; |
} |
return $var; |
} /* }}} */ |
function get_server_var($name) /* {{{ */ |
{ |
if (isset($_SERVER[$name])) { |
return $_SERVER[$name]; |
} |
global $HTTP_SERVER_VARS; |
if (isset($HTTP_SERVER_VARS[$name])) { |
return $HTTP_SERVER_VARS[$name]; |
} |
global $$name; |
if (isset($$name)) { |
return $$name; |
} |
return null; |
} /* }}} */ |
/* |
* Debug functions |
*/ |
function print_get_vars ($miss = 'No GET variables found') // debug only /* {{{ */ |
{ |
// we parse form GET variables |
if (is_array($_GET)) { |
echo "<p> Variables per GET "; |
foreach ($_GET as $k => $v) { |
if (is_array($v)) { |
foreach ($v as $akey => $aval) { |
// $_GET[$k][$akey] = strip_tags($aval); |
// $$k[$akey] = strip_tags($aval); |
echo "$k\[$akey\]=$aval "; |
} |
} else { |
// $_GET[$k] = strip_tags($val); |
// $$k = strip_tags($val); |
echo "$k=$v "; |
} |
} |
echo '</p>'; |
} else { |
echo '<p>'; |
echo $miss; |
echo '</p>'; |
} |
} /* }}} */ |
function print_post_vars($miss = 'No POST variables found') // debug only /* {{{ */ |
{ |
global $_POST; |
// we parse form POST variables |
if (is_array($_POST)) { |
echo "<p>Variables per POST "; |
foreach ($_POST as $k => $v) { |
if (is_array($v)) { |
foreach ($v as $akey => $aval) { |
// $_POST[$k][$akey] = strip_tags($aval); |
// $$k[$akey] = strip_tags($aval); |
echo "$k\[$akey\]=$aval "; |
} |
} else { |
// $_POST[$k] = strip_tags($val); |
// $$k = strip_tags($val); |
echo "$k=$v "; |
} |
} |
echo '</p>'; |
} else { |
echo '<p>'; |
echo $miss; |
echo '</p>'; |
} |
} /* }}} */ |
function print_vars ($miss = 'Current instance variables') // debug only /* {{{ */ |
{ |
echo "$miss "; |
echo 'page_name=',$this->page_name,' '; |
echo 'hn=',$this->hn,' '; |
echo 'un=',$this->un,' '; |
echo 'pw=',$this->pw,' '; |
echo 'db=',$this->db,' '; |
echo 'dbp=',$this->dbp,' '; |
echo 'dbh=',$this->dbh,' '; |
echo 'tb=',$this->tb,' '; |
echo 'key=',$this->key,' '; |
echo 'key_type=',$this->key_type,' '; |
echo 'inc=',$this->inc,' '; |
echo 'options=',$this->options,' '; |
echo 'fdd=',$this->fdd,' '; |
echo 'fl=',$this->fl,' '; |
echo 'fm=',$this->fm,' '; |
echo 'sfn=',htmlspecialchars($this->get_sfn_cgi_vars()),' '; |
echo 'qfn=',$this->qfn,' '; |
echo 'sw=',$this->sw,' '; |
echo 'rec=',$this->rec,' '; |
echo 'navop=',$this->navop,' '; |
echo 'saveadd=',$this->saveadd,' '; |
echo 'moreadd=',$this->moreadd,' '; |
echo 'canceladd=',$this->canceladd,' '; |
echo 'savechange=',$this->savechange,' '; |
echo 'morechange=',$this->morechange,' '; |
echo 'cancelchange=',$this->cancelchange,' '; |
echo 'savecopy=',$this->savecopy,' '; |
echo 'cancelcopy=',$this->cancelcopy,' '; |
echo 'savedelete=',$this->savedelete,' '; |
echo 'canceldelete=',$this->canceldelete,' '; |
echo 'cancelview=',$this->cancelview,' '; |
echo 'operation=',$this->operation,' '; |
echo "\n"; |
} /* }}} */ |
/* |
* Display buttons at top and bottom of page |
*/ |
function display_list_table_buttons($position, $listall = false) /* {{{ */ |
{ |
if (($but_str = $this->display_buttons($position)) === null) |
return; |
if($position == 'down') echo '<hr class="'.$this->getCSSclass('hr', 'down').'" />'."\n"; |
echo '<table summary="navigation" class="',$this->getCSSclass('navigation', $position),'">',"\n"; |
echo '<tr class="',$this->getCSSclass('navigation', $position),'">',"\n"; |
echo '<td class="',$this->getCSSclass('buttons', $position),'">',"\n"; |
echo $but_str,'</td>',"\n"; |
// Message is now written here |
if (strlen(@$this->message) > 0) { |
echo '<td class="',$this->getCSSclass('message', $position),'">',$this->message,'</td>',"\n"; |
} |
if($this->display['num_pages'] || $this->display['num_records']) |
echo '<td class="',$this->getCSSclass('stats', $position),'">',"\n"; |
if($this->display['num_pages']) { |
if ($listall) { |
echo $this->labels['Page'],': 1 ',$this->labels['of'],' 1'; |
} else { |
$current_page = intval($this->fm / $this->inc) + 1; |
$total_pages = max(1, ceil($this->total_recs / abs($this->inc))); |
echo $this->labels['Page'],': ',$current_page; |
echo ' ',$this->labels['of'],' ',$total_pages; |
} |
} |
if($this->display['num_records']) |
echo ' ',$this->labels['Records'],': ',$this->total_recs; |
if($this->display['num_pages'] || $this->display['num_records']) echo '</td>'; |
echo '</tr></table>',"\n"; |
if($position == 'up') echo '<hr class="'.$this->getCSSclass('hr', 'up').'" />'."\n"; |
} /* }}} */ |
/* |
* Display buttons at top and bottom of page |
*/ |
function display_record_buttons($position) /* {{{ */ |
{ |
if (($but_str = $this->display_buttons($position)) === null) |
return; |
if ($position == 'down') { |
if ($this->tabs_enabled()) $this->display_tab_labels('down'); |
echo '<hr class="',$this->getCSSclass('hr', 'down'),'" />',"\n"; |
} |
echo '<table summary="navigation" class="',$this->getCSSclass('navigation', $position),'">',"\n"; |
echo '<tr class="',$this->getCSSclass('navigation', $position),'">',"\n"; |
echo '<td class="',$this->getCSSclass('buttons', $position),'">',"\n"; |
echo $but_str,'</td>',"\n"; |
// Message is now written here |
//echo '</td>',"\n"; |
if (strlen(@$this->message) > 0) { |
echo '<td class="',$this->getCSSclass('message', $position),'">',$this->message,'</td>',"\n"; |
} |
echo '</tr></table>',"\n"; |
if ($position == 'up') { |
if ($this->tabs_enabled()) $this->display_tab_labels('up'); |
echo '<hr class="',$this->getCSSclass('hr', 'up'),'" />',"\n"; |
} |
} /* }}} */ |
function display_buttons($position) /* {{{ */ |
{ |
$nav_fnc = 'nav_'.$position; |
if(! $this->$nav_fnc()) |
return; |
$buttons = (is_array($this->buttons[$this->page_type][$position])) |
? $this->buttons[$this->page_type][$position] |
: $this->default_buttons[$this->page_type]; |
foreach ($buttons as $name) { |
$ret .= $this->display_button($name, $position)."\n"; |
} |
return $ret; |
} /* }}} */ |
function display_button($name, $position = 'up') /* {{{ */ |
{ |
if (is_array($name)) { |
if (isset($name['code'])) return $name['code']; |
return $this->htmlSubmit($name['name'], $name['value'], $name['css'], $name['disabled'], $name['js']); |
} |
$disabled = 1; // show disabled by default |
if ($name[0] == '+') { $name = substr($name, 1); $disabled = 0; } // always show disabled as enabled |
if ($name[0] == '-') { $name = substr($name, 1); $disabled = -1; } // don't show disabled |
if ($name == 'cancel') { |
return $this->htmlSubmit('cancel'.$this->page_types[$this->page_type], 'Cancel', |
$this->getCSSclass('cancel', $position), false); |
} |
if (in_array($name, array('add','view','change','copy','delete'))) { |
$enabled_fnc = $name.'_enabled'; |
$enabled = $this->$enabled_fnc(); |
if ($name != 'add' && ! $this->total_recs && strstr('LF', $this->page_type)) |
$enabled = false; |
return $this->htmlSubmit('operation', ucfirst($name), |
$this->getCSSclass($name, $position), false, $enabled ? 0 : $disabled); |
} |
if ($name == 'savedelete') { |
$enabled = $this->delete_enabled(); |
$js = 'onclick="return confirm(\''.$this->labels['Delete'].' ?\');"'; |
return $this->htmlSubmit('savedelete', 'Delete', |
$this->getCSSclass('save', $position), false, $enabled ? 0 : $disabled, $js); |
} |
if (in_array($name, array('save','more'))) { |
$validation = true; // if js validation |
if ($this->page_type == 'D' && $name == 'save' ) { $value = 'Delete'; $validation = false; } |
elseif ($this->page_type == 'C' && $name == 'more' ) { $value = 'Apply'; } |
else $value = ucfirst($name); |
return $this->htmlSubmit($name.$this->page_types[$this->page_type], $value, |
$this->getCSSclass($name, $position), $validation); |
} |
$listall = $this->inc <= 0; |
if ($listall) { |
$disabledprev = true; |
$disablednext = true; |
$total_pages = 1; |
$current_page = 1; |
} else { |
$disabledprev = $this->fm <= 0; |
$disablednext = $this->fm + $this->inc >= $this->total_recs; |
$total_pages = max(1, ceil($this->total_recs / abs($this->inc))); |
$current_page = ceil($this->fm / abs($this->inc)); // must + 1 |
} |
$disabledfirst = $disabledprev; |
$disabledlast = $disablednext; |
// some statistics first |
if ($name == 'total_pages') return $total_pages; |
if ($name == 'current_page') return ($current_page+1); |
if ($name == 'total_recs') return ($this->total_recs); |
// now some goto buttons/dropdowns/inputs... |
if ($name == 'goto_text') { |
$ret = '<input type="text" class="'.$this->getCSSclass('gotopn', $position).'"'; |
$ret .= ' name="'.$this->cgi['prefix']['sys'].'navpn'.$position.'" value="'.($current_page+1).'"'; |
$ret .= ' size="'.(strlen($total_pages)+1).'" maxlength="'.(strlen($total_pages)+1).'"'; |
// TODO some js here.... on enter submit, on click erase ?... |
$ret .=' oneypress="return PE_filter_handler(this.form, event);" />'; |
return $ret; |
} |
if ($name == 'goto_combo') { |
$disabledgoto = !($listall || ($disablednext && $disabledprev)) ? '' : ' disabled'; |
if ($disablegoto != '' && $disabled < 0) return; |
$kv_array = array(); |
for ($i = 0; $i < $total_pages; $i++) { |
$kv_array[$this->inc * $i] = $i + 1; |
} |
// TODO: add onchange="return this.form.submit();" DONE ??? |
return $this->htmlSelect($this->cgi['prefix']['sys'].ltrim($disabledgoto).'navfm'.$position, |
$this->getCSSclass('goto', $position), $kv_array, (string)$this->fm, false, $disabledgoto, |
false, true, 'onchange="return this.form.submit();"'); |
} |
if ($name == 'goto') { |
return $this->htmlSubmit('navop', 'Go to', $this->getCSSclass('goto', $position), |
false, ($listall || ($disablednext && $disabledprev)) ? $disabled : 0); |
} |
if (in_array($name, array('first','prev','next','last','<<','<','>','>>'))) { |
$disabled_var = 'disabled'.$name; |
$name2 = $name; |
if (strlen($name) <= 2) { |
$nav_values = array('<<' => 'first', '<' => 'prev', '>' => 'next', '>>' => 'last'); |
$disabled_var = 'disabled'.$nav_values[$name]; |
$name2 = $nav_values[$name]; |
} |
return $this->htmlSubmit('navop', ucfirst($name), |
$this->getCSSclass($name2, $position), false, $$disabled_var ? $disabled : 0); |
} |
if(isset($this->labels[$name])) return $this->labels[$name]; |
return $name; |
} /* }}} */ |
function number_of_recs() /* {{{ */ |
{ |
$count_parts = array( |
'type' => 'select', |
'select' => 'count(*)', |
'from' => $this->get_SQL_join_clause(), |
'where' => $this->get_SQL_where_from_query_opts()); |
$res = $this->myquery($this->get_SQL_query($count_parts), __LINE__); |
$row = @mysql_fetch_array($res, MYSQL_NUM); |
$this->total_recs = $row[0]; |
} /* }}} */ |
/* |
* Table Page Listing |
*/ |
function list_table() /* {{{ */ |
{ |
if ($this->fm == '') { |
$this->fm = 0; |
} |
$this->fm = $this->navfm; |
if ($this->prev_operation()) { |
$this->fm = $this->fm - $this->inc; |
if ($this->fm < 0) { |
$this->fm = 0; |
} |
} |
if ($this->first_operation()) { |
$this->fm = 0; |
} // last operation must be performed below, after retrieving total_recs |
if ($this->next_operation()) { |
$this->fm += $this->inc; |
} |
$this->number_of_recs(); |
if ($this->last_operation() || $this->fm > $this->total_recs) { // if goto_text is badly set |
$this->fm = (int)(($this->total_recs - 1)/$this->inc)*$this->inc; |
} |
// If sort sequence has changed, restart listing |
$this->qfn != $this->prev_qfn && $this->fm = 0; |
if (0) { // DEBUG |
echo 'qfn vs. prev_qfn comparsion '; |
echo '[<b>',htmlspecialchars($this->qfn),'</b>]'; |
echo '[<b>',htmlspecialchars($this->prev_qfn),'</b>]<br />'; |
echo 'comparsion <u>',($this->qfn == $this->prev_qfn ? 'proved' : 'failed'),'</u>'; |
echo '<hr />'; |
} |
/* |
* If user is allowed to Change/Delete records, we need an extra column |
* to allow users to select a record |
*/ |
$select_recs = $this->key != '' && |
($this->change_enabled() || $this->delete_enabled() || $this->view_enabled()); |
// Are we doing a listall? |
$listall = $this->inc <= 0; |
/* |
* Display the MySQL table in an HTML table |
*/ |
$this->form_begin(); |
echo $this->get_origvars_html($this->get_sfn_cgi_vars()); |
echo $this->htmlHiddenSys('fl', $this->fl); |
// Display buttons at top and/or bottom of page. |
$this->display_list_table_buttons('up', $listall); |
if ($this->cgi['persist'] != '') { |
echo $this->get_origvars_html($this->cgi['persist']); |
} |
if (! $this->filter_operation()) { |
echo $this->get_origvars_html($this->qfn); |
} |
echo $this->htmlHiddenSys('qfn', $this->qfn); |
echo $this->htmlHiddenSys('fm', $this->fm); |
echo '<table class="',$this->getCSSclass('main'),'" summary="',$this->tb,'">',"\n"; |
echo '<tr class="',$this->getCSSclass('header'),'">',"\n"; |
/* |
* System (navigation, selection) columns counting |
*/ |
$sys_cols = 0; |
$sys_cols += intval($this->filter_enabled() || $select_recs); |
if ($sys_cols > 0) { |
$sys_cols += intval($this->nav_buttons() |
&& ($this->nav_text_links() || $this->nav_graphic_links())); |
} |
/* |
* We need an initial column(s) (sys columns) |
* if we have filters, Changes or Deletes enabled |
*/ |
if ($sys_cols) { |
echo '<th class="',$this->getCSSclass('header'),'" colspan="',$sys_cols,'">'; |
if ($this->filter_enabled()) { |
if ($this->filter_operation()) { |
echo $this->htmlSubmit('sw', 'Hide', $this->getCSSclass('hide'), false); |
echo $this->htmlSubmit('sw', 'Clear', $this->getCSSclass('clear'), false); |
} else { |
echo $this->htmlSubmit('sw', 'Search', $this->getCSSclass('search'), false); |
} |
} else { |
echo ' '; |
} |
echo '</th>',"\n"; |
} |
for ($k = 0; $k < $this->num_fds; $k++) { |
$fd = $this->fds[$k]; |
if (! $this->displayed[$k]) { |
continue; |
} |
$css_postfix = @$this->fdd[$k]['css']['postfix']; |
$css_class_name = $this->getCSSclass('header', null, null, $css_postfix); |
$fdn = $this->fdd[$fd]['name']; |
if (! $this->fdd[$fd]['sort'] || $this->password($fd)) { |
echo '<th class="',$css_class_name,'">',$fdn,'</th>',"\n"; |
} else { |
// Clicking on the current sort field reverses the sort order |
$new_sfn = $this->sfn; |
array_unshift($new_sfn, in_array("$k", $new_sfn, 1) ? "-$k" : $k); |
echo '<th class="',$css_class_name,'">'; |
echo '<a class="',$css_class_name,'" href="'; |
echo htmlspecialchars($this->page_name.'?'.$this->cgi['prefix']['sys'].'fm'.'=0' |
.'&'.$this->cgi['prefix']['sys'].'fl'.'='.$this->fl |
.'&'.$this->cgi['prefix']['sys'].'qfn'.'='.rawurlencode($this->qfn).$this->qfn |
.'&'.$this->get_sfn_cgi_vars($new_sfn).$this->cgi['persist']); |
echo '">',$fdn,'</a></th>',"\n"; |
} |
} |
echo '</tr>',"\n"; |
/* |
* Prepare the SQL Query from the data definition file |
*/ |
$qparts['type'] = 'select'; |
$qparts['select'] = $this->get_SQL_column_list(); |
// Even if the key field isn't displayed, we still need its value |
if ($select_recs) { |
if (!in_array ($this->key, $this->fds)) { |
$qparts['select'] .= ','.$this->fqn($this->key); |
} |
} |
$qparts['from'] = $this->get_SQL_join_clause(); |
$qparts['where'] = $this->get_SQL_where_from_query_opts(); |
// build up the ORDER BY clause |
if (isset($this->sfn)) { |
$sort_fields = array(); |
$sort_fields_w = array(); |
foreach ($this->sfn as $field) { |
if ($field[0] == '-') { |
$field = substr($field, 1); |
$desc = true; |
} else { |
$field = $field; |
$desc = false; |
} |
$sort_field = $this->fqn($field); |
$sort_field_w = $this->fdd[$field]['name']; |
$this->col_has_sql($field) && $sort_field_w .= ' (sql)'; |
if ($desc) { |
$sort_field .= ' DESC'; |
$sort_field_w .= ' '.$this->labels['descending']; |
} else { |
$sort_field_w .= ' '.$this->labels['ascending']; |
} |
$sort_fields[] = $sort_field; |
$sort_fields_w[] = $sort_field_w; |
} |
if (count($sort_fields) > 0) { |
$qparts['orderby'] = join(',', $sort_fields); |
} |
} |
$qparts['limit'] = $listall ? '' : $this->fm.','.$this->inc; |
/* |
* Main list_table() query |
* |
* Each row of the HTML table is one record from the SQL query. We must |
* perform this query before filter printing, because we want to use |
* mysql_field_len() function. We will also fetch the first row to get |
* the field names. |
*/ |
$query = $this->get_SQL_query($qparts); |
$res = $this->myquery($query, __LINE__); |
if ($res == false) { |
$this->error('invalid SQL query', $query); |
return false; |
} |
$row = @mysql_fetch_array($res, MYSQL_ASSOC); |
/* FILTER {{{ |
* |
* Draw the filter and fill it with any data typed in last pass and stored |
* in the array parameter keyword 'filter'. Prepare the SQL WHERE clause. |
*/ |
if ($this->filter_operation()) { |
// Filter row retrieval |
$fields = false; |
$filter_row = $row; |
if (! is_array($filter_row)) { |
unset($qparts['where']); |
$query = $this->get_SQL_query($qparts); |
$res = $this->myquery($query, __LINE__); |
if ($res == false) { |
$this->error('invalid SQL query', $query); |
return false; |
} |
$filter_row = @mysql_fetch_array($res, MYSQL_ASSOC); |
} |
/* Variable $fields is used to get index of particular field in |
result. That index can be passed in example to mysql_field_len() |
function. Use field names as indexes to $fields array. */ |
if (is_array($filter_row)) { |
$fields = array_flip(array_keys($filter_row)); |
} |
if ($fields != false) { |
$css_class_name = $this->getCSSclass('filter'); |
echo '<tr class="',$css_class_name,'">',"\n"; |
echo '<td class="',$css_class_name,'" colspan="',$sys_cols,'">'; |
echo $this->htmlSubmit('filter', 'Query', $this->getCSSclass('query'), false); |
echo '</td>', "\n"; |
for ($k = 0; $k < $this->num_fds; $k++) { |
if (! $this->displayed[$k]) { |
continue; |
} |
$css_postfix = @$this->fdd[$k]['css']['postfix']; |
$css_class_name = $this->getCSSclass('filter', null, null, $css_postfix); |
$this->field_name = $this->fds[$k]; |
$fd = $this->field_name; |
$this->field = $this->fdd[$fd]; |
$l = 'qf'.$k; |
$lc = 'qf'.$k.'_comp'; |
$li = 'qf'.$k.'_id'; |
if ($this->clear_operation()) { |
$m = null; |
$mc = null; |
$mi = null; |
} else { |
$m = $this->get_sys_cgi_var($l); |
$mc = $this->get_sys_cgi_var($lc); |
$mi = $this->get_sys_cgi_var($li); |
} |
echo '<td class="',$css_class_name,'">'; |
if ($this->password($k)) { |
echo ' '; |
} else if ($this->fdd[$fd]['select'] == 'D' || $this->fdd[$fd]['select'] == 'M') { |
// Multiple fields processing |
// Default size is 2 and array required for values. |
$from_table = ! $this->col_has_values($k) || isset($this->fdd[$k]['values']['table']); |
$vals = $this->set_values($k, array('*' => '*'), null, $from_table); |
$selected = $mi; |
$multiple = $this->col_has_multiple_select($k); |
$multiple |= $this->fdd[$fd]['select'] == 'M'; |
$readonly = false; |
$strip_tags = true; |
$escape = true; |
echo $this->htmlSelect($this->cgi['prefix']['sys'].$l.'_id', $css_class_name, |
$vals, $selected, $multiple, $readonly, $strip_tags, $escape); |
} elseif ($this->fdd[$fd]['select'] == 'N' || $this->fdd[$fd]['select'] == 'T') { |
$size_ml_props = ''; |
$maxlen = intval($this->fdd[$k]['maxlen']); |
$maxlen > 0 || $maxlen = intval(@mysql_field_len($res, $fields["qf$k"])); |
$size = isset($this->fdd[$k]['size']) ? $this->fdd[$k]['size'] |
: ($maxlen < 30 ? min($maxlen, 8) : 12); |
$size && $size_ml_props .= ' size="'.$size.'"'; |
$maxlen && $size_ml_props .= ' maxlength="'.$maxlen.'"'; |
if ($this->fdd[$fd]['select'] == 'N') { |
$mc = in_array($mc, $this->comp_ops) ? $mc : '='; |
echo $this->htmlSelect($this->cgi['prefix']['sys'].$l.'_comp', |
$css_class_name, $this->comp_ops, $mc); |
} |
echo '<input class="',$css_class_name,'" value="',htmlspecialchars(@$m); |
echo '" type="text" name="'.$this->cgi['prefix']['sys'].'qf'.$k.'"',$size_ml_props; |
echo ' onkeypress="return '.$this->js['prefix'].'filter_handler(this.form, event);" />'; |
} else { |
echo ' '; |
} |
echo '</td>',"\n"; |
} |
echo '</tr>',"\n"; |
} |
} // }}} |
/* |
* Display sorting sequence |
*/ |
if ($qparts['orderby'] && $this->display['sort']) { |
$css_class_name = $this->getCSSclass('sortinfo'); |
echo '<tr class="',$css_class_name,'">',"\n"; |
echo '<td class="',$css_class_name,'" colspan="',$sys_cols,'">'; |
echo '<a class="',$css_class_name,'" href="'; |
echo htmlspecialchars($this->page_name |
.'?'.$this->cgi['prefix']['sys'].'fl'.'='.$this->fl |
.'&'.$this->cgi['prefix']['sys'].'fm'.'='.$this->fm |
.'&'.$this->cgi['prefix']['sys'].'qfn'.'='.rawurlencode($this->qfn) |
.$this->qfn.$this->cgi['persist']); |
echo '">',$this->labels['Clear'],'</a></td>',"\n"; |
echo '<td class="',$css_class_name,'" colspan="',$this->num_fields_displayed,'">'; |
echo $this->labels['Sorted By'],': ',join(', ', $sort_fields_w),'</td></tr>',"\n"; |
} |
/* |
* Display the current query |
*/ |
$text_query = $this->get_SQL_where_from_query_opts(null, true); |
if ($text_query != '' && $this->display['query']) { |
$css_class_name = $this->getCSSclass('queryinfo'); |
echo '<tr class="',$css_class_name,'">',"\n"; |
echo '<td class="',$css_class_name,'" colspan="',$sys_cols,'">'; |
echo '<a class="',$css_class_name,'" href="'; |
echo htmlspecialchars($this->get_server_var('PHP_SELF') |
.'?'.$this->cgi['prefix']['sys'].'fl'.'='.$this->fl |
.'&'.$this->cgi['prefix']['sys'].'fm'.'='.$this->fm |
.'&'.$this->cgi['prefix']['sys'].'qfn'.'='.rawurlencode($this->qfn) |
.'&'.$this->get_sfn_cgi_vars().$this->cgi['persist']); |
echo '">',$this->labels['Clear'],'</a></td>',"\n"; |
echo '<td class="',$css_class_name,'" colspan="',$this->num_fields_displayed,'">'; |
echo $this->labels['Current Query'],': ',htmlspecialchars($text_query),'</td></tr>',"\n"; |
} |
if ($this->nav_text_links() || $this->nav_graphic_links()) { |
$qstrparts = array(); |
strlen($this->fl) > 0 && $qstrparts[] = $this->cgi['prefix']['sys'].'fl'.'='.$this->fl; |
strlen($this->fm) > 0 && $qstrparts[] = $this->cgi['prefix']['sys'].'fm'.'='.$this->fm; |
count($this->sfn) > 0 && $qstrparts[] = $this->get_sfn_cgi_vars(); |
strlen($this->cgi['persist']) > 0 && $qstrparts[] = $this->cgi['persist']; |
$qpview = $qstrparts; |
$qpcopy = $qstrparts; |
$qpchange = $qstrparts; |
$qpdelete = $qstrparts; |
$qp_prefix = $this->cgi['prefix']['sys'].'operation'.'='.$this->cgi['prefix']['operation']; |
$qpview[] = $qp_prefix.'View'; |
$qpcopy[] = $qp_prefix.'Copy'; |
$qpchange[] = $qp_prefix.'Change'; |
$qpdelete[] = $qp_prefix.'Delete'; |
$qpviewStr = htmlspecialchars($this->page_name.'?'.join('&',$qpview).$this->qfn); |
$qpcopyStr = htmlspecialchars($this->page_name.'?'.join('&',$qpcopy).$this->qfn); |
$qpchangeStr = htmlspecialchars($this->page_name.'?'.join('&',$qpchange).$this->qfn); |
$qpdeleteStr = htmlspecialchars($this->page_name.'?'.join('&',$qpdelete).$this->qfn); |
} |
$fetched = true; |
$first = true; |
$rowCount = 0; |
while ((!$fetched && ($row = @mysql_fetch_array($res, MYSQL_ASSOC)) != false) |
|| ($fetched && $row != false)) { |
$fetched = false; |
echo '<tr class="',$this->getCSSclass('row', null, 'next'),'">',"\n"; |
if ($sys_cols) { /* {{{ */ |
$key_rec = $row['qf'.$this->key_num]; |
$queryAppend = htmlspecialchars('&'.$this->cgi['prefix']['sys'].'rec'.'='.$key_rec); |
$viewQuery = $qpviewStr . $queryAppend; |
$copyQuery = $qpcopyStr . $queryAppend; |
$changeQuery = $qpchangeStr . $queryAppend; |
$deleteQuery = $qpdeleteStr . $queryAppend; |
$viewTitle = htmlspecialchars($this->labels['View']); |
$changeTitle = htmlspecialchars($this->labels['Change']); |
$copyTitle = htmlspecialchars($this->labels['Copy']); |
$deleteTitle = htmlspecialchars($this->labels['Delete']); |
$css_class_name = $this->getCSSclass('navigation', null, true); |
if ($select_recs) { |
if (! $this->nav_buttons() || $sys_cols > 1) { |
echo '<td class="',$css_class_name,'">'; |
} |
if ($this->nav_graphic_links()) { |
$printed_out = false; |
if ($this->view_enabled()) { |
$printed_out = true; |
echo '<a class="',$css_class_name,'" href="',$viewQuery,'"><img class="'; |
echo $css_class_name,'" src="',$this->url['images']; |
echo 'pme-view.png" height="15" width="16" border="0" '; |
echo 'alt="',$viewTitle,'" title="',$viewTitle,'" /></a>'; |
} |
if ($this->change_enabled()) { |
$printed_out && print(' '); |
$printed_out = true; |
echo '<a class="',$css_class_name,'" href="',$changeQuery,'"><img class="'; |
echo $css_class_name,'" src="',$this->url['images']; |
echo 'pme-change.png" height="15" width="16" border="0" '; |
echo 'alt="',$changeTitle,'" title="',$changeTitle,'" /></a>'; |
} |
if ($this->copy_enabled()) { |
$printed_out && print(' '); |
$printed_out = true; |
echo '<a class="',$css_class_name,'" href="',$copyQuery,'"><img class="'; |
echo $css_class_name,'" src="',$this->url['images']; |
echo 'pme-copy.png" height="15" width="16" border="0" '; |
echo 'alt="',$copyTitle,'" title="',$copyTitle,'" /></a>'; |
} |
if ($this->delete_enabled()) { |
$printed_out && print(' '); |
$printed_out = true; |
echo '<a class="',$css_class_name,'" href="',$deleteQuery,'"><img class="'; |
echo $css_class_name,'" src="',$this->url['images']; |
echo 'pme-delete.png" height="15" width="16" border="0" '; |
echo 'alt="',$deleteTitle,'" title="',$deleteTitle,'" /></a>'; |
} |
} |
if ($this->nav_text_links()) { |
if ($this->nav_graphic_links()) { |
echo '<br class="',$css_class_name,'">'; |
} |
$printed_out = false; |
if ($this->view_enabled()) { |
$printed_out = true; |
echo '<a href="',$viewQuery,'" title="',$viewTitle,'" class="',$css_class_name,'">V</a>'; |
} |
if ($this->change_enabled()) { |
$printed_out && print(' '); |
$printed_out = true; |
echo '<a href="',$changeQuery,'" title="',$changeTitle,'" class="',$css_class_name,'">C</a>'; |
} |
if ($this->copy_enabled()) { |
$printed_out && print(' '); |
$printed_out = true; |
echo '<a href="',$copyQuery,'" title="',$copyTitle,'" class="',$css_class_name,'">P</a>'; |
} |
if ($this->delete_enabled()) { |
$printed_out && print(' '); |
$printed_out = true; |
echo '<a href="',$deleteQuery,'" title="',$deleteTitle,'" class="',$css_class_name,'">D</a>'; |
} |
} |
if (! $this->nav_buttons() || $sys_cols > 1) { |
echo '</td>',"\n"; |
} |
if ($this->nav_buttons()) { |
echo '<td class="',$css_class_name,'"><input class="',$css_class_name; |
echo '" type="radio" name="'.$this->cgi['prefix']['sys'].'rec'; |
echo '" value="',htmlspecialchars($key_rec),'"'; |
if (($this->rec == '' && $first) || ($this->rec == $key_rec)) { |
echo ' checked'; |
$first = false; |
} |
echo ' /></td>',"\n"; |
} |
} elseif ($this->filter_enabled()) { |
echo '<td class="',$css_class_name,'" colspan=',$sys_cols,'> </td>',"\n"; |
} |
} /* }}} */ |
for ($k = 0; $k < $this->num_fds; $k++) { /* {{{ */ |
$fd = $this->fds[$k]; |
if (! $this->displayed[$k]) { |
continue; |
} |
$css_postfix = @$this->fdd[$k]['css']['postfix']; |
$css_class_name = $this->getCSSclass('cell', null, true, $css_postfix); |
if ($this->password($k)) { |
echo '<td class="',$css_class_name,'">',$this->labels['hidden'],'</td>',"\n"; |
continue; |
} |
echo '<td class="',$css_class_name,'"',$this->getColAttributes($fd),'>'; |
echo $this->cellDisplay($k, $row, $css_class_name); |
echo '</td>',"\n"; |
} /* }}} */ |
echo '</tr>',"\n"; |
} |
/* |
* Display and accumulate column aggregation info, do totalling query |
* XXX this feature does not work yet!!! |
*/ |
// aggregates listing (if any) |
if ($$var_to_total) { |
// do the aggregate query if necessary |
//if ($vars_to_total) { |
$qp = array(); |
$qp['type'] = 'select'; |
$qp['select'] = $aggr_from_clause; |
$qp['from'] = $this->get_SQL_join_clause(); |
$qp['where'] = $this->get_SQL_where_from_query_opts(); |
$tot_query = $this->get_SQL_query($qp); |
$totals_result = $this->myquery($tot_query,__LINE__); |
$tot_row = @mysql_fetch_array($totals_result, MYSQL_ASSOC); |
//} |
$qp_aggr = $qp; |
echo "\n",'<tr class="TODO-class">',"\n",'<td class="TODO-class"> </td>',"\n"; |
/* |
echo '<td>'; |
echo printarray($qp_aggr); |
echo printarray($vars_to_total); |
echo '</td>'; |
echo '<td colspan="'.($this->num_fds-1).'">'.$var_to_total.' '.$$var_to_total.'</td>'; |
*/ |
// display the results |
for ($k=0;$k<$this->num_fds;$k++) { |
$fd = $this->fds[$k]; |
if (stristr($this->fdd[$fd]['options'],'L') or !isset($this->fdd[$fd]['options'])) { |
echo '<td>'; |
$aggr_var = 'qf'.$k.'_aggr'; |
$$aggr_var = $this->get_sys_cgi_var($aggr_var); |
if ($$aggr_var) { |
echo $this->sql_aggrs[$$aggr_var],': ',$tot_row[$aggr_var]; |
} else { |
echo ' '; |
} |
echo '</td>',"\n"; |
} |
} |
echo '</tr>',"\n"; |
} |
echo '</table>',"\n"; // end of table rows listing |
$this->display_list_table_buttons('down', $listall); |
$this->form_end(); |
} /* }}} */ |
function display_record() /* {{{ */ |
{ |
// PRE Triggers |
$ret = true; |
if ($this->change_operation()) { |
$ret &= $this->exec_triggers_simple('update', 'pre'); |
// if PRE update fails, then back to view operation |
if (! $ret) { |
$this->operation = $this->labels['View']; |
$ret = true; |
} |
} |
if ($this->add_operation() || $this->copy_operation()) { |
$ret &= $this->exec_triggers_simple('insert', 'pre'); |
} |
if ($this->view_operation()) { |
$ret &= $this->exec_triggers_simple('select', 'pre'); |
} |
if ($this->delete_operation()) { |
$ret &= $this->exec_triggers_simple('delete', 'pre'); |
} |
// if PRE insert/view/delete fail, then back to the list |
if ($ret == false) { |
$this->operation = ''; |
$this->list_table(); |
return; |
} |
$this->form_begin(); |
if ($this->cgi['persist'] != '') { |
echo $this->get_origvars_html($this->cgi['persist']); |
} |
echo $this->get_origvars_html($this->get_sfn_cgi_vars()); |
echo $this->get_origvars_html($this->qfn); |
echo $this->htmlHiddenSys('cur_tab', $this->dhtml['prefix'].'tab'.$this->cur_tab); |
echo $this->htmlHiddenSys('qfn', $this->qfn); |
echo $this->htmlHiddenSys('rec', $this->copy_operation() ? '' : $this->rec); |
echo $this->htmlHiddenSys('fm', $this->fm); |
echo $this->htmlHiddenSys('fl', $this->fl); |
$this->display_record_buttons('up'); |
if ($this->tabs_enabled()) { |
echo '<div id="'.$this->dhtml['prefix'].'tab0">',"\n"; |
} |
echo '<table class="',$this->getCSSclass('main'),'" summary="',$this->tb,'">',"\n"; |
if ($this->add_operation()) { |
$this->display_add_record(); |
} else { |
$this->display_copy_change_delete_record(); |
} |
echo '</table>',"\n"; |
if ($this->tabs_enabled()) { |
echo '</div>',"\n"; |
} |
$this->display_record_buttons('down'); |
$this->form_end(); |
} /* }}} */ |
/* |
* Action functions |
*/ |
function do_add_record() /* {{{ */ |
{ |
// Preparing query |
$query = ''; |
$key_col_val = ''; |
$newvals = array(); |
for ($k = 0; $k < $this->num_fds; $k++) { |
if ($this->processed($k)) { |
$fd = $this->fds[$k]; |
if ($this->readonly($k)) { |
$fn = (string) @$this->fdd[$k]['default']; |
} else { |
$fn = $this->get_data_cgi_var($fd); |
} |
if ($fd == $this->key) { |
$key_col_val = $fn; |
} |
$newvals[$fd] = is_array($fn) ? join(',',$fn) : $fn; |
} |
} |
// Creating array of changed keys ($changed) |
$changed = array_keys($newvals); |
// Before trigger, newvals can be efectively changed |
if ($this->exec_triggers('insert', 'before', $oldvals, $changed, $newvals) == false) { |
return false; |
} |
// Real query (no additional query in this method) |
foreach ($newvals as $fd => $val) { |
if ($fd == '') continue; |
if ($this->col_has_sqlw($this->fdn[$fd])) { |
$val_as = addslashes($val); |
$val_qas = '"'.addslashes($val).'"'; |
$value = $this->substituteVars( |
$this->fdd[$this->fdn[$fd]]['sqlw'], array( |
'val_qas' => $val_qas, |
'val_as' => $val_as, |
'val' => $val |
)); |
} else { |
$value = "'".addslashes($val)."'"; |
} |
if ($query == '') { |
$query = 'INSERT INTO `'.$this->tb.'` (`'.$fd.'`'; // ) |
$query2 = ') VALUES ('.$value.''; |
} else { |
$query .= ', `'.$fd.'`'; |
$query2 .= ', '.$value.''; |
} |
} |
$query .= $query2.')'; |
$res = $this->myquery($query, __LINE__); |
$this->message = @mysql_affected_rows($this->dbh).' '.$this->labels['record added']; |
if (! $res) { |
return false; |
} |
$this->rec = mysql_insert_id($this->dbh); |
// Notify list |
if (@$this->notify['insert'] || @$this->notify['all']) { |
$this->email_notify(false, $newvals); |
} |
// Note change in log table |
if ($this->logtable) { |
$query = sprintf('INSERT INTO %s' |
.' (updated, user, host, operation, tab, rowkey, col, oldval, newval)' |
.' VALUES (NOW(), "%s", "%s", "insert", "%s", "%s", "", "", "%s")', |
$this->logtable, addslashes($this->get_server_var('REMOTE_USER')), |
addslashes($this->get_server_var('REMOTE_ADDR')), addslashes($this->tb), |
addslashes($key_col_val), addslashes(serialize($newvals))); |
$this->myquery($query, __LINE__); |
} |
// After trigger |
if ($this->exec_triggers('insert', 'after', $oldvals, $changed, $newvals) == false) { |
return false; |
} |
return true; |
} /* }}} */ |
function do_change_record() /* {{{ */ |
{ |
// Preparing queries |
$query_real = ''; |
$query_oldrec = ''; |
$newvals = array(); |
$oldvals = array(); |
$changed = array(); |
// Prepare query to retrieve oldvals |
for ($k = 0; $k < $this->num_fds; $k++) { |
if ($this->processed($k) && !$this->readonly($k)) { |
$fd = $this->fds[$k]; |
$fn = $this->get_data_cgi_var($fd); |
$newvals[$this->fds[$k]] = is_array($fn) ? join(',',$fn) : $fn; |
if ($query_oldrec == '') { |
$query_oldrec = 'SELECT '.$fd; |
} else { |
$query_oldrec .= ','.$fd; |
} |
} |
} |
$where_part = " WHERE (".$this->key.'='.$this->key_delim.$this->rec.$this->key_delim.')'; |
$query_newrec = $query_oldrec.' FROM ' . $this->tb; |
$query_oldrec .= ' FROM ' . $this->tb . $where_part; |
// Additional query (must go before real query) |
$res = $this->myquery($query_oldrec, __LINE__); |
$oldvals = @mysql_fetch_array($res, MYSQL_ASSOC); |
@mysql_free_result($res); |
// Creating array of changed keys ($changed) |
foreach ($newvals as $fd => $value) { |
if ($value != $oldvals[$fd]) |
$changed[] = $fd; |
} |
// Before trigger |
if ($this->exec_triggers('update', 'before', $oldvals, $changed, $newvals) == false) { |
return false; |
} |
// Build the real query respecting changes to the newvals array |
foreach ($newvals as $fd => $val) { |
if ($fd == '') continue; |
if ($this->col_has_sqlw($this->fdn[$fd])) { |
$val_as = addslashes($val); |
$val_qas = '"'.addslashes($val).'"'; |
$value = $this->substituteVars( |
$this->fdd[$this->fdn[$fd]]['sqlw'], array( |
'val_qas' => $val_qas, |
'val_as' => $val_as, |
'val' => $val |
)); |
} else { |
$value = "'".addslashes($val)."'"; |
} |
if ($query_real == '') { |
$query_real = 'UPDATE '.$this->tb.' SET '.$fd.'='.$value; |
} else { |
$query_real .= ','.$fd.'='.$value; |
} |
} |
$query_real .= $where_part; |
// Real query |
$res = $this->myquery($query_real, __LINE__); |
$this->message = @mysql_affected_rows($this->dbh).' '.$this->labels['record changed']; |
if (! $res) { |
return false; |
} |
// Another additional query (must go after real query) |
if (in_array($this->key, $changed)) { |
$this->rec = $newvals[$this->key]; // key has changed |
} |
$query_newrec .= ' WHERE ('.$this->key.'='.$this->key_delim.$this->rec.$this->key_delim.')'; |
$res = $this->myquery($query_newrec, __LINE__); |
$newvals = @mysql_fetch_array($res, MYSQL_ASSOC); |
@mysql_free_result($res); |
// Creating array of changed keys ($changed) |
$changed = array(); |
foreach ($newvals as $fd => $value) { |
if ($value != $oldvals[$fd]) |
$changed[] = $fd; |
} |
// Notify list |
if (@$this->notify['update'] || @$this->notify['all']) { |
if (count($changed) > 0) { |
$this->email_notify($oldvals, $newvals); |
} |
} |
// Note change in log table |
if ($this->logtable) { |
foreach ($changed as $key) { |
$qry = sprintf('INSERT INTO %s' |
.' (updated, user, host, operation, tab, rowkey, col, oldval, newval)' |
.' VALUES (NOW(), "%s", "%s", "update", "%s", "%s", "%s", "%s", "%s")', |
$this->logtable, addslashes($this->get_server_var('REMOTE_USER')), |
addslashes($this->get_server_var('REMOTE_ADDR')), addslashes($this->tb), |
addslashes($this->rec), addslashes($key), |
addslashes($oldvals[$key]), addslashes($newvals[$key])); |
$this->myquery($qry, __LINE__); |
} |
} |
// After trigger |
if ($this->exec_triggers('update', 'after', $oldvals, $changed, $newvals) == false) { |
return false; |
} |
return true; |
} /* }}} */ |
function do_delete_record() /* {{{ */ |
{ |
// Additional query |
$query = 'SELECT * FROM '.$this->tb.' WHERE ('.$this->key.' = ' |
.$this->key_delim.$this->rec.$this->key_delim.')'; // ) |
$res = $this->myquery($query, __LINE__); |
$oldvals = @mysql_fetch_array($res, MYSQL_ASSOC); |
@mysql_free_result($res); |
// Creating array of changed keys ($changed) |
$changed = array_keys($oldvals); |
$newvals = array(); |
// Before trigger |
if ($this->exec_triggers('delete', 'before', $oldvals, $changed, $newvals) == false) { |
return false; |
} |
// Real query |
$query = 'DELETE FROM '.$this->tb.' WHERE ('.$this->key.' = ' |
.$this->key_delim.$this->rec.$this->key_delim.')'; // ) |
$res = $this->myquery($query, __LINE__); |
$this->message = @mysql_affected_rows($this->dbh).' '.$this->labels['record deleted']; |
if (! $res) { |
return false; |
} |
// Notify list |
if (@$this->notify['delete'] || @$this->notify['all']) { |
$this->email_notify($oldvals, false); |
} |
// Note change in log table |
if ($this->logtable) { |
$query = sprintf('INSERT INTO %s' |
.' (updated, user, host, operation, tab, rowkey, col, oldval, newval)' |
.' VALUES (NOW(), "%s", "%s", "delete", "%s", "%s", "%s", "%s", "")', |
$this->logtable, addslashes($this->get_server_var('REMOTE_USER')), |
addslashes($this->get_server_var('REMOTE_ADDR')), addslashes($this->tb), |
addslashes($this->rec), addslashes($key), addslashes(serialize($oldvals))); |
$this->myquery($query, __LINE__); |
} |
// After trigger |
if ($this->exec_triggers('delete', 'after', $oldvals, $changed, $newvals) == false) { |
return false; |
} |
return true; |
} /* }}} */ |
function email_notify($old_vals, $new_vals) /* {{{ */ |
{ |
if (! function_exists('mail')) { |
return false; |
} |
if ($old_vals != false && $new_vals != false) { |
$action = 'update'; |
$subject = 'Record updated in'; |
$body = 'An item with '.$this->fdd[$this->key]['name'].' = ' |
.$this->key_delim.$this->rec.$this->key_delim .' was updated in'; |
$vals = $new_vals; |
} elseif ($new_vals != false) { |
$action = 'insert'; |
$subject = 'Record added to'; |
$body = 'A new item was added into'; |
$vals = $new_vals; |
} elseif ($old_vals != false) { |
$action = 'delete'; |
$subject = 'Record deleted from'; |
$body = 'An item was deleted from'; |
$vals = $old_vals; |
} else { |
return false; |
} |
$addr = $this->get_server_var('REMOTE_ADDR'); |
$user = $this->get_server_var('REMOTE_USER'); |
$body = 'This notification e-mail was automatically generated by phpMyEdit.'."\n\n".$body; |
$body .= ' table '.$this->tb.' in MySQL database '.$this->db.' on '.$this->page_name; |
$body .= ' by '.($user == '' ? 'unknown user' : "user $user").' from '.$addr; |
$body .= ' at '.date('d/M/Y H:i').' with the following fields:'."\n\n"; |
$i = 1; |
foreach ($vals as $k => $text) { |
$name = isset($this->fdd[$k]['name~']) |
? $this->fdd[$k]['name~'] : $this->fdd[$k]['name']; |
if ($action == 'update') { |
if ($old_vals[$k] == $new_vals[$k]) { |
continue; |
} |
$body .= sprintf("[%02s] %s (%s)\n WAS: %s\n IS: %s\n", |
$i, $name, $k, $old_vals[$k], $new_vals[$k]); |
} else { |
$body .= sprintf('[%02s] %s (%s): %s'."\n", $i, $name, $k, $text); |
} |
$i++; |
} |
$body .= "\n--\r\n"; // \r is needed for signature separating |
$body .= "phpMyEdit\ninstant MySQL table editor and code generator\n"; |
$body .= "http://platon.sk/projects/phpMyEdit/\n\n"; |
$subject = @$this->notify['prefix'].$subject.' '.$this->dbp.$this->tb; |
$subject = trim($subject); // just for sure |
$wrap_w = intval(@$this->notify['wrap']); |
$wrap_w > 0 || $wrap_w = 72; |
$from = (string) @$this->notify['from']; |
$from != '' || $from = 'webmaster@'.strtolower($this->get_server_var('SERVER_NAME')); |
$headers = 'From: '.$from."\n".'X-Mailer: PHP/'.phpversion().' (phpMyEdit)'; |
$body = wordwrap($body, $wrap_w, "\n", 1); |
$emails = (array) $this->notify[$action] + (array) $this->notify['all']; |
foreach ($emails as $email) { |
if (! empty($email)) { |
mail(trim($email), $subject, $body, $headers); |
} |
} |
return true; |
} /* }}} */ |
/* |
* Apply triggers function |
* Run a (set of) trigger(s). $trigger can be an Array or a filename |
* Break and return false as soon as a trigger return false |
* we need a reference on $newvals to be able to change value before insert/update |
*/ |
function exec_triggers($op, $step, $oldvals, &$changed, &$newvals) /* {{{ */ |
{ |
if (! isset($this->triggers[$op][$step])) { |
return true; |
} |
$ret = true; |
$trig = $this->triggers[$op][$step]; |
if (is_array($trig)) { |
ksort($trig); |
for ($t = reset($trig); $t !== false && $ret != false; $t = next($trig)) { |
$ret = include($t); |
} |
} else { |
$ret = include($trig); |
} |
return $ret; |
} /* }}} */ |
function exec_triggers_simple($op, $step) /* {{{ */ |
{ |
$oldvals = $newvals = $changed = array(); |
return $this->exec_triggers($op, $step, $oldvals, $changed, $newvals); |
} /* }}} */ |
/* |
* Recreate functions |
*/ |
function recreate_fdd($default_page_type = 'L') /* {{{ */ |
{ |
// TODO: one level deeper browsing |
$this->page_type = $default_page_type; |
$this->filter_operation() && $this->page_type = 'F'; |
$this->view_operation() && $this->page_type = 'V'; |
if ($this->add_operation() |
|| $this->saveadd == $this->labels['Save'] |
|| $this->moreadd == $this->labels['More']) { |
$this->page_type = 'A'; |
} |
if ($this->change_operation() |
|| $this->savechange == $this->labels['Save'] |
|| $this->morechange == $this->labels['Apply']) { |
$this->page_type = 'C'; |
} |
if ($this->copy_operation() || $this->savecopy == $this->labels['Save']) { |
$this->page_type = 'P'; |
} |
if ($this->delete_operation() || $this->savedelete == $this->labels['Delete']) { |
$this->page_type = 'D'; |
} |
// Restore backups (if exists) |
foreach (array_keys($this->fdd) as $column) { |
foreach (array_keys($this->fdd[$column]) as $col_option) { |
if ($col_option[strlen($col_option) - 1] != '~') |
continue; |
$this->fdd[$column][substr($col_option, 0, strlen($col_option) - 1)] |
= $this->fdd[$column][$col_option]; |
unset($this->fdd[$column][$col_option]); |
} |
} |
foreach (array_keys($this->fdd) as $column) { |
foreach (array_keys($this->fdd[$column]) as $col_option) { |
if (! strchr($col_option, '|')) { |
continue; |
} |
$col_ar = explode('|', $col_option, 2); |
if (! stristr($col_ar[1], $this->page_type)) { |
continue; |
} |
// Make field backups |
$this->fdd[$column][$col_ar[0] .'~'] = $this->fdd[$column][$col_ar[0]]; |
$this->fdd[$column][$col_option.'~'] = $this->fdd[$column][$col_option]; |
// Set particular field |
$this->fdd[$column][$col_ar[0]] = $this->fdd[$column][$col_option]; |
unset($this->fdd[$column][$col_option]); |
} |
} |
} /* }}} */ |
function recreate_displayed() /* {{{ */ |
{ |
$field_num = 0; |
$num_fields_displayed = 0; |
$this->fds = array(); |
$this->fdn = array(); |
$this->displayed = array(); |
$this->guidance = false; |
foreach (array_keys($this->fdd) as $key) { |
if (preg_match('/^\d+$/', $key)) { // skipping numeric keys |
continue; |
} |
$this->fds[$field_num] = $key; |
$this->fdn[$key] = $field_num; |
/* We must use here displayed() function, because displayed[] array |
is not created yet. We will simultaneously create that array as well. */ |
if ($this->displayed[$field_num] = $this->displayed($field_num)) { |
$num_fields_displayed++; |
} |
if (is_array(@$this->fdd[$key]['values']) && ! isset($this->fdd[$key]['values']['table'])) { |
foreach ($this->fdd[$key]['values'] as $val) { |
$this->fdd[$key]['values2'][$val] = $val; |
} |
unset($this->fdd[$key]['values']); |
} |
isset($this->fdd[$key]['help']) && $this->guidance = true; |
$this->fdd[$field_num] = $this->fdd[$key]; |
$field_num++; |
} |
$this->num_fds = $field_num; |
$this->num_fields_displayed = $num_fields_displayed; |
$this->key_num = array_search($this->key, $this->fds); |
/* Adds first displayed column into sorting fields by replacing last |
array entry. Also remove duplicite values and change column names to |
their particular field numbers. |
Note that entries like [0]=>'9' [1]=>'-9' are correct and they will |
have desirable sorting behaviour. So there is no need to remove them. |
*/ |
$this->sfn = array_unique($this->sfn); |
$check_ar = array(); |
foreach ($this->sfn as $key => $val) { |
if (preg_match('/^[-]?\d+$/', $val)) { // skipping numeric keys |
$val = abs($val); |
if (in_array($val, $check_ar) || $this->password($val)) { |
unset($this->sfn[$key]); |
} else { |
$check_ar[] = $val; |
} |
continue; |
} |
if ($val[0] == '-') { |
$val = substr($val, 1); |
$minus = '-'; |
} else { |
$minus = ''; |
} |
if (($val = array_search($val, $this->fds)) === false || $this->password($val)) { |
unset($this->sfn[$key]); |
} else { |
$val = intval($val); |
if (in_array($val, $check_ar)) { |
unset($this->sfn[$key]); |
} else { |
$this->sfn[$key] = $minus.$val; |
$check_ar[] = $val; |
} |
} |
} |
$this->sfn = array_unique($this->sfn); |
return true; |
} /* }}} */ |
function backward_compatibility() /* {{{ */ |
{ |
foreach (array_keys($this->fdd) as $column) { |
// move ['required'] to ['js']['required'] |
if (! isset($this->fdd[$column]['js']['required']) && isset($this->fdd[$column]['required'])) { |
$this->fdd[$column]['js']['required'] = $this->fdd[$column]['required']; |
} |
// move 'HWR' flags from ['options'] into ['input'] |
if (isset($this->fdd[$column]['options'])) { |
stristr($this->fdd[$column]['options'], 'H') && $this->fdd[$column]['input'] .= 'H'; |
stristr($this->fdd[$column]['options'], 'W') && $this->fdd[$column]['input'] .= 'W'; |
stristr($this->fdd[$column]['options'], 'R') && $this->fdd[$column]['input'] .= 'R'; |
} |
} |
} /* }}} */ |
/* |
* Error handling function |
*/ |
function error($message, $additional_info = '') /* {{{ */ |
{ |
echo '<h1>phpMyEdit error: ',htmlspecialchars($message),'</h1>',"\n"; |
if ($additional_info != '') { |
echo '<hr />',htmlspecialchars($additional_info); |
} |
return false; |
} /* }}} */ |
/* |
* Database connection function |
*/ |
function connect() /* {{{ */ |
{ |
if (isset($this->dbh)) { |
return true; |
} |
if (!isset($this->db)) { |
$this->error('no database defined'); |
return false; |
} |
if (!isset ($this->tb)) { |
$this->error('no table defined'); |
return false; |
} |
$this->dbh = @ini_get('allow_persistent') |
? @mysql_pconnect($this->hn, $this->un, $this->pw) |
: @mysql_connect($this->hn, $this->un, $this->pw); |
if (!$this->dbh) { |
$this->error('could not connect to MySQL'); |
return false; |
} |
return true; |
} /* }}} */ |
/* |
* Database disconnection function |
*/ |
function disconnect() /* {{{ */ |
{ |
if ($this->close_dbh) { |
@mysql_close($this->dbh); |
$this->dbh = null; |
} |
} /* }}} */ |
/* |
* The workhorse |
*/ |
function execute() /* {{{ */ |
{ |
// DEBUG - uncomment to enable |
/* |
//phpinfo(); |
$this->print_get_vars(); |
$this->print_post_vars(); |
$this->print_vars(); |
echo "<pre>query opts:\n"; |
echo print_r($this->query_opts); |
echo "</pre>\n"; |
echo "<pre>get vars:\n"; |
echo print_r($this->get_opts); |
echo "</pre>\n"; |
*/ |
// Let's do explicit quoting - it's safer |
set_magic_quotes_runtime(0); |
// Checking if language file inclusion was successful |
if (! is_array($this->labels)) { |
$this->error('could not locate language files', 'searched path: '.$this->dir['lang']); |
return false; |
} |
// Database connection |
if ($this->connect() == false) { |
return false; |
} |
/* |
* ====================================================================== |
* Pass 3: process any updates generated if the user has selected |
* a save or cancel button during Pass 2 |
* ====================================================================== |
*/ |
// Cancel button - Cancel Triggers |
if ($this->add_canceled() || $this->copy_canceled()) { |
$this->exec_triggers_simple('insert', 'cancel'); |
} |
if ($this->view_canceled()) { |
$this->exec_triggers_simple('select', 'cancel'); |
} |
if ($this->change_canceled()) { |
$this->exec_triggers_simple('update', 'cancel'); |
} |
if ($this->delete_canceled()) { |
$this->exec_triggers_simple('delete', 'cancel'); |
} |
// Save/More Button - database operations |
if ($this->saveadd == $this->labels['Save'] || $this->savecopy == $this->labels['Save']) { |
$this->add_enabled() && $this->do_add_record(); |
unset($this->saveadd); |
unset($this->savecopy); |
$this->recreate_fdd(); |
} |
elseif ($this->moreadd == $this->labels['More']) { |
$this->add_enabled() && $this->do_add_record(); |
$this->operation = $this->labels['Add']; // to force add operation |
$this->recreate_fdd(); |
$this->recreate_displayed(); |
$this->backward_compatibility(); |
} |
elseif ($this->savechange == $this->labels['Save']) { |
$this->change_enabled() && $this->do_change_record(); |
unset($this->savechange); |
$this->recreate_fdd(); |
} |
elseif ($this->morechange == $this->labels['Apply']) { |
$this->change_enabled() && $this->do_change_record(); |
$this->operation = $this->labels['Change']; // to force change operation |
$this->recreate_fdd(); |
$this->recreate_displayed(); |
$this->backward_compatibility(); |
} |
elseif ($this->savedelete == $this->labels['Delete']) { |
$this->delete_enabled() && $this->do_delete_record(); |
unset($this->savedelete); |
$this->recreate_fdd(); |
} |
/* |
* ====================================================================== |
* Pass 2: display an input/edit/confirmation screen if the user has |
* selected an editing button on Pass 1 through this page |
* ====================================================================== |
*/ |
if ($this->add_operation() |
|| $this->change_operation() || $this->delete_operation() |
|| $this->view_operation() || $this->copy_operation()) { |
$this->display_record(); |
} |
/* |
* ====================================================================== |
* Pass 1 and Pass 3: display the MySQL table in a scrolling window on |
* the screen (skip this step in 'Add More' mode) |
* ====================================================================== |
*/ |
else { |
$this->list_table(); |
} |
$this->disconnect(); |
if ($this->display['time'] && $this->timer != null) { |
echo $this->timer->end(),' miliseconds'; |
} |
} /* }}} */ |
/* |
* Class constructor |
*/ |
function phpMyEdit($opts) /* {{{ */ |
{ |
// Set desirable error reporting level |
$error_reporting = error_reporting(E_ALL & ~E_NOTICE); |
// Database handle variables |
if (isset($opts['dbh'])) { |
$this->close_dbh = false; |
$this->dbh = $opts['dbh']; |
$this->dbp = ''; |
} else { |
$this->close_dbh = true; |
$this->dbh = null; |
$this->dbp = $opts['db'].'.'; |
$this->hn = $opts['hn']; |
$this->un = $opts['un']; |
$this->pw = $opts['pw']; |
$this->db = $opts['db']; |
} |
$this->tb = $opts['tb']; |
// Other variables |
$this->key = $opts['key']; |
$this->key_type = $opts['key_type']; |
$this->inc = $opts['inc']; |
$this->options = $opts['options']; |
$this->fdd = $opts['fdd']; |
$this->multiple = intval($opts['multiple']); |
$this->multiple <= 0 && $this->multiple = 2; |
$this->filters = @$opts['filters']; |
$this->triggers = @$opts['triggers']; |
$this->notify = @$opts['notify']; |
$this->logtable = @$opts['logtable']; |
$this->page_name = @$opts['page_name']; |
if (! isset($this->page_name)) { |
$this->page_name = basename($this->get_server_var('PHP_SELF')); |
isset($this->page_name) || $this->page_name = $this->tb; |
} |
$this->display['query'] = @$opts['display']['query']; |
$this->display['sort'] = @$opts['display']['sort']; |
$this->display['time'] = @$opts['display']['time']; |
if ($this->display['time']) { |
$this->timer = new phpMyEdit_timer(); |
} |
$this->display['tabs'] = isset($opts['display']['tabs']) |
? $opts['display']['tabs'] : true; |
$this->display['form'] = isset($opts['display']['form']) |
? $opts['display']['form'] : true; |
$this->display['num_records'] = isset($opts['display']['num_records']) |
? $opts['display']['num_records'] : true; |
$this->display['num_pages'] = isset($opts['display']['num_pages']) |
? $opts['display']['num_pages'] : true; |
// Creating directory variables |
$this->dir['root'] = dirname(realpath(__FILE__)) |
. (strlen(dirname(realpath(__FILE__))) > 0 ? '/' : ''); |
$this->dir['lang'] = $this->dir['root'].'lang/'; |
// Creating URL variables |
$this->url['images'] = 'images/'; |
isset($opts['url']['images']) && $this->url['images'] = $opts['url']['images']; |
// CSS classes policy |
$this->css = @$opts['css']; |
!isset($this->css['separator']) && $this->css['separator'] = '-'; |
!isset($this->css['prefix']) && $this->css['prefix'] = 'pme'; |
!isset($this->css['page_type']) && $this->css['page_type'] = false; |
!isset($this->css['position']) && $this->css['position'] = false; |
!isset($this->css['divider']) && $this->css['divider'] = 2; |
$this->css['divider'] = intval(@$this->css['divider']); |
// JS overall configuration |
$this->js = @$opts['js']; |
!isset($this->js['prefix']) && $this->js['prefix'] = 'PME_js_'; |
// DHTML overall configuration |
$this->dhtml = @$opts['dhtml']; |
!isset($this->dhtml['prefix']) && $this->dhtml['prefix'] = 'PME_dhtml_'; |
// Navigation |
$this->navigation = @$opts['navigation']; |
if (! $this->nav_buttons() && ! $this->nav_text_links() && ! $this->nav_graphic_links()) { |
$this->navigation .= 'B'; // buttons are default |
} |
if (! $this->nav_up() && ! $this->nav_down()) { |
$this->navigation .= 'D'; // down position is default |
} |
$this->buttons = $opts['buttons']; |
// Language labels (must go after navigation) |
$this->labels = $this->make_language_labels(isset($opts['language']) |
? $opts['language'] : $this->get_server_var('HTTP_ACCEPT_LANGUAGE')); |
// CGI variables |
$this->cgi = @$opts['cgi']; |
$this->cgi['persist'] = ''; |
if (@is_array($opts['cgi']['persist'])) { |
foreach ($opts['cgi']['persist'] as $key => $val) { |
if (is_array($val)) { |
foreach($val as $key2 => $val2) { |
$this->cgi['persist'] .= '&'.rawurlencode($key) |
.'['.rawurlencode($key2).']='.rawurlencode($val2); |
} |
} else { |
$this->cgi['persist'] .= '&'.rawurlencode($key).'='.rawurlencode($val); |
} |
} |
} |
foreach (array('operation', 'sys', 'data') as $type) { |
if (! isset($this->cgi['prefix'][$type])) { |
$this->cgi['prefix'][$type] = $this->get_default_cgi_prefix($type); |
} |
} |
// Sorting variables |
$this->sfn = $this->get_sys_cgi_var('sfn'); |
isset($this->sfn) || $this->sfn = array(); |
is_array($this->sfn) || $this->sfn = array($this->sfn); |
isset($opts['sort_field']) || $opts['sort_field'] = array(); |
is_array($opts['sort_field']) || $opts['sort_field'] = array($opts['sort_field']); |
$this->sfn = array_merge($this->sfn, $opts['sort_field']); |
// Form variables all around |
$this->fl = intval($this->get_sys_cgi_var('fl')); |
$this->fm = intval($this->get_sys_cgi_var('fm')); |
// $old_page = ceil($this->fm / abs($this->inc)) + 1; |
$this->qfn = $this->get_sys_cgi_var('qfn'); |
$this->sw = $this->get_sys_cgi_var('sw'); |
$this->rec = $this->get_sys_cgi_var('rec', ''); |
$this->navop = $this->get_sys_cgi_var('navop'); |
$navfmup = $this->get_sys_cgi_var('navfmup'); |
$navfmdown = $this->get_sys_cgi_var('navfmdown'); |
$navpnup = $this->get_sys_cgi_var('navpnup'); |
$navpndown = $this->get_sys_cgi_var('navpndown'); |
if($navfmdown!=NULL && $navfmdown != $this->fm) $this->navfm = $navfmdown; |
elseif($navfmup!=NULL && $navfmup != $this->fm) $this->navfm = $navfmup; |
elseif($navpndown!=NULL && ($navpndown-1)*$this->inc != $this->fm) $this->navfm = ($navpndown-1)*$this->inc; |
elseif($navpnup!=NULL && ($navpnup-1)*$this->inc != $this->fm) $this->navfm = ($navpnup-1)*$this->inc; |
else $this->navfm = $this->fm; |
$this->operation = $this->get_sys_cgi_var('operation'); |
$oper_prefix_len = strlen($this->cgi['prefix']['operation']); |
if (! strncmp($this->cgi['prefix']['operation'], $this->operation, $oper_prefix_len)) { |
$this->operation = $this->labels[substr($this->operation, $oper_prefix_len)]; |
} |
$this->saveadd = $this->get_sys_cgi_var('saveadd'); |
$this->moreadd = $this->get_sys_cgi_var('moreadd'); |
$this->canceladd = $this->get_sys_cgi_var('canceladd'); |
$this->savechange = $this->get_sys_cgi_var('savechange'); |
$this->morechange = $this->get_sys_cgi_var('morechange'); |
$this->cancelchange = $this->get_sys_cgi_var('cancelchange'); |
$this->savecopy = $this->get_sys_cgi_var('savecopy'); |
$this->cancelcopy = $this->get_sys_cgi_var('cancelcopy'); |
$this->savedelete = $this->get_sys_cgi_var('savedelete'); |
$this->canceldelete = $this->get_sys_cgi_var('canceldelete'); |
$this->cancelview = $this->get_sys_cgi_var('cancelview'); |
// Filter setting |
if (isset($this->sw)) { |
$this->sw == $this->labels['Search'] && $this->fl = 1; |
$this->sw == $this->labels['Hide'] && $this->fl = 0; |
//$this->sw == $this->labels['Clear'] && $this->fl = 0; |
} |
// TAB names |
$this->tabs = array(); |
// Setting key_delim according to key_type |
if ($this->key_type == 'real') { |
/* If 'real' key_type does not work, |
try change MySQL datatype from float to double */ |
$this->rec = doubleval($this->rec); |
$this->key_delim = ''; |
} elseif ($this->key_type == 'int') { |
$this->rec = intval($this->rec); |
$this->key_delim = ''; |
} else { |
$this->key_delim = '"'; |
// $this->rec remains unmodified |
} |
// Specific $fdd modifications depending on performed action |
$this->recreate_fdd(); |
// Extract SQL Field Names and number of fields |
$this->recreate_displayed(); |
// Issue backward compatibility |
$this->backward_compatibility(); |
// Gathering query options |
$this->gather_query_opts(); |
// Call to action |
!isset($opts['execute']) && $opts['execute'] = 1; |
$opts['execute'] && $this->execute(); |
// Restore original error reporting level |
error_reporting($error_reporting); |
} /* }}} */ |
} |
/* Modeline for ViM {{{ |
* vim:set ts=4: |
* vim600:fdm=marker fdl=0 fdc=0: |
* }}} */ |
?> |
/trunk/jrest/util/extensions/.directory |
---|
New file |
0,0 → 1,5 |
[Dolphin] |
Timestamp=2010,6,10,16,40,51 |
[Settings] |
ShowDotFiles=true |
/trunk/jrest/util/extensions/phpMyEdit-messages.class.php |
---|
New file |
0,0 → 1,329 |
<?php |
/* |
* phpMyEdit - instant MySQL table editor and code generator |
* |
* extensions/phpMyEdit-messages.class.php - phpMyEdit messages extension |
* ____________________________________________________________ |
* |
* Developed by Ondrej Jombik <nepto@platon.sk> |
* Copyright (c) 2002-2006 Platon Group, http://platon.sk/ |
* All rights reserved. |
* |
* See README file for more information about this software. |
* See COPYING file for license information. |
* |
* Download the latest version from |
* http://platon.sk/projects/phpMyEdit/ |
*/ |
/* $Platon: phpMyEdit/extensions/phpMyEdit-messages.class.php,v 1.15 2006-06-17 11:14:54 nepto Exp $ */ |
/* This extension is part of phpMyEzin: Content Management System project, |
where it handles discussion messages for particular articles. It depends on |
some phpMyEzin characteristics, thus extension should not and cannot be used |
outside this project. However there are planned some improvements for future |
to make this extension handle any kind of tree-structured data. */ |
require_once dirname(__FILE__).'/../phpMyEdit.class.php'; |
class phpMyEdit_messages extends phpMyEdit |
{ |
function phpMyEdit_messages($opts) /* {{{ */ |
{ |
$execute = 1; |
isset($opts['execute']) && $execute = $opts['execute']; |
$opts['execute'] = 0; |
parent::phpMyEdit($opts); |
$this->tb2 = $opts['tb2']; |
$this->format_date = $opts['format_date']; |
/* Preserved article ID in CGI environment. */ |
/* TODO: change to $this->article_id or something like this */ |
global $ezin_admin_article; |
$ezin_admin_article = $this->get_data_cgi_var('article_id'); |
$execute && $this->execute(); |
} /* }}} */ |
function list_table() /* {{{ */ |
{ |
$ezin_admin_article_change_up = $this->get_sys_cgi_var('ezin_admin_article_change_up'); |
$ezin_admin_article_change_down = $this->get_sys_cgi_var('ezin_admin_article_change_down'); |
if (isset($ezin_admin_article_change_up)) { |
$ezin_admin_article = $this->get_sys_cgi_var('ezin_admin_article_up'); |
} elseif (isset($ezin_admin_article_change_down)) { |
$ezin_admin_article = $this->get_sys_cgi_var('ezin_admin_article_down'); |
} |
!isset($ezin_admin_article) && $ezin_admin_article = $this->get_data_cgi_var('article_id'); |
$ezin_admin_article = intval($ezin_admin_article); |
$query = sprintf('SELECT article_id, count(id) AS messages FROM %s' |
.' GROUP BY article_id HAVING article_id = %d', |
$this->tb, intval($ezin_admin_article)); |
if (($result = $this->myquery($query)) == false) { |
return false; |
} |
$row = @mysql_fetch_array($result, MYSQL_ASSOC); |
//$ezin_admin_article = intval($row['article_id']); |
$ezin_admin_msgcount = intval($row['messages']); |
@mysql_free_result($result); |
echo '<form class="',$this->getCSSclass('form'); |
echo '" action="',$page_name,'" method="POST">',"\n"; |
if ($this->nav_up() || $ezin_admin_article <= 0) { |
$this->message_nav_buttons($ezin_admin_article, $ezin_admin_msgcount, 'up'); |
echo '<hr class="',$this->getCSSclass('hr', 'up'),'">',"\n"; |
} |
if ($ezin_admin_article > 0) { |
echo '<table class="',$this->getCSSclass('main'),'" summary="',$this->tb,'">',"\n"; |
echo '<tr class="',$this->getCSSclass('header'),'">',"\n"; |
foreach (array('ID', 'Subject', ' ', 'Author', 'Date & Time', 'IP addresses') as $str) { |
echo '<th class="',$this->getCSSclass('header'),'">'; |
echo Platon::htmlspecialchars2($str),'</th>',"\n"; |
} |
echo '</tr>',"\n"; |
echo '<tr class="',$this->getCSSclass('header'),'">',"\n"; |
echo '<th class="',$this->getCSSclass('header'),'" colspan="6">'; |
echo 'Valid messages</td></tr>',"\n"; |
$message_ids = $this->message_process($ezin_admin_article, 0, 0); |
$count_message_ids = count($message_ids); |
if ($count_message_ids == 0) { |
echo '<tr class="',$this->getCSSclass('row', null, 'next'),'">',"\n"; |
echo '<td class="',$this->getCSSclass('cell', null, true),'" colspan="6">',"\n"; |
echo '<i>There are no valid messages for this article.</i>'; |
echo '</td></tr>',"\n"; |
} |
$query = sprintf('SELECT id, parent, article_id, author,' |
.' email, homepage, subject, datetime, ip' |
.' FROM %s WHERE article_id = %d ORDER BY datetime ASC', |
$this->tb, intval($ezin_admin_article)); |
if (($result = $this->myquery($query)) == false) { |
return false; |
} |
$all_ids = array(); |
$parents = array(); |
for ($i = 0; ($row = @mysql_fetch_array($result, MYSQL_ASSOC)); $i++) { |
$all_ids[] = $row['id']; |
$parents[$row['id']] = $row['parent']; |
} |
@mysql_free_result($result); |
$all_ids = array_diff($all_ids, $message_ids); |
echo '<tr class="',$this->getCSSclass('header'),'">',"\n"; |
echo '<th class="',$this->getCSSclass('header'),'" colspan="6">'; |
echo 'Invalid messages</td></tr>',"\n"; |
if (count($all_ids) > 0) { |
/* To force buttons */ |
$count_message_ids = -1; |
while (count($all_ids) > 0) { |
//echo "<p>all_ids: "; var_dump($all_ids);echo '<br>'; |
$sub_ids = $this->message_process($ezin_admin_article, |
$parents[array_shift($all_ids)], 0, true); |
$all_ids = array_diff($all_ids, $sub_ids); |
} |
} else { |
echo '<tr class="',$this->getCSSclass('row', null, 'next'),'">',"\n"; |
echo '<td class="',$this->getCSSclass('cell', null, true),'" colspan="6">',"\n"; |
echo '<i>There are no invalid messages for this article.</i>'; |
echo '</td></tr>',"\n"; |
} |
echo '</table>'; |
} |
if ($this->nav_down() && $ezin_admin_article > 0) { |
echo '<hr class="',$this->getCSSclass('hr', 'down'),'">',"\n"; |
$this->message_nav_buttons($ezin_admin_article, $ezin_admin_msgcount, 'down'); |
} |
echo $this->htmlHiddenData('article_id', $ezin_admin_article); |
echo '</form>',"\n"; |
} /* }}} */ |
function message_process($article_id, $id, $level = 0, $parent = true) /* {{{ */ |
{ |
$id = intval($id); |
$level = intval($level); |
$query = sprintf('SELECT id, parent, article_id, author,' |
.' email, homepage, subject, datetime, ip' |
.' FROM %s WHERE %s = %d AND article_id = %d' |
.' ORDER BY datetime ASC', $this->tb, |
$parent == true ? 'parent' : 'id', intval($id), intval($article_id)); |
if (($result = $this->myquery($query)) == false) { |
return false; |
} |
$ar = array(); |
$ar_out = array(); |
for ($i = 0; ($row = @mysql_fetch_array($result, MYSQL_ASSOC)); $i++) { |
$ar[$i] = $row; |
$ar_out[] = $row['id']; |
} |
$checked = ! $level && $parent ? ' checked' : ''; |
for ($i = 0; $i < count($ar); $i++) { |
echo '<tr class="',$this->getCSSclass('row', null, 'next'),'">',"\n"; |
$css_class_name = $this->getCSSclass('cell', null, true); |
$css_class_name2 = $this->getCSSclass('navigation', null, true); |
echo '<td class="',$css_class_name,'">',$ar[$i]['id'],'</td>',"\n"; |
echo '<td class="',$css_class_name,'">'; |
for ($j = 0; $j < $level; $j++) { |
echo ' '; |
} |
echo htmlspecialchars($ar[$i]['subject']); |
echo '</td>',"\n"; |
echo '<td class="',$css_class_name2,'">'; |
echo '<input',$checked,' class="',$css_class_name2,'"'; |
echo ' type="radio" ','name="',$this->cgi['prefix']['sys'],'rec"'; |
echo ' value="',$ar[$i]['id'],'" class="link"></td>',"\n"; |
echo '<td class="',$css_class_name,'">',htmlspecialchars($ar[$i]['author']), '</td>'; |
echo '<td class="',$css_class_name,'">',htmlspecialchars($ar[$i]['datetime']),'</td>'; |
// TODO: do resolving |
echo '<td class="',$css_class_name,'"><small>'; |
// this shoud be global IP-adress-deliminator |
$output = false; |
$ar_ip = preg_split('|([ ]*[ \\/,;]+[ ]*)|', $ar[$i]['ip'], -1, PREG_SPLIT_DELIM_CAPTURE); |
foreach ($ar_ip as $ip) { |
if (strlen($output) > 0) { |
$output = true; |
} |
$ip = htmlspecialchars($ip); |
if (preg_match('/^(\d{1,3}\.){3}\d{1,3}$/', $ip)) { |
echo '<a class="',$css_class_name,'" target="_blank" href="http://',$ip,'">'; |
echo '<small>',$ip,'</small></a>'; |
} else { |
echo $ip; |
} |
} |
if (! $output) { |
echo ' '; |
} |
echo '</small></td>',"\n"; |
echo '</tr>',"\n"; |
if ($parent) { |
$ar_out = array_merge($ar_out, $this->message_process( |
$article_id, $ar[$i]['id'], $level + 1)); |
} |
strlen($checked) && $checked = ''; |
} |
return $ar_out; |
} /* }}} */ |
function message_nav_buttons($article_id, $messages_count, $position) /* {{{ */ |
{ |
echo '<table class="',$this->getCSSclass('navigation', $position),'">',"\n"; |
echo '<tr class="',$this->getCSSclass('navigation', $position),'">',"\n"; |
echo '<td class="',$this->getCSSclass('buttons', $position),'">',"\n"; |
$this->print_article_select($article_id, 0, $position); |
echo '</td>',"\n"; |
echo '<td class="',$this->getCSSclass('buttons2', $position),'">',"\n"; |
if ($article_id > 0) { |
if ($this->add_enabled()) { |
echo $this->htmlSubmit('operation', 'Add', $this->getCSSclass('add', $position), false, false); |
} |
if ($this->view_enabled()) { |
echo ' '; |
echo $this->htmlSubmit('operation', 'View', $this->getCSSclass('view', $position), |
false, $messages_count <= 0); |
} |
if ($this->change_enabled()) { |
echo ' '; |
echo $this->htmlSubmit('operation', 'Change', $this->getCSSclass('change', $position), |
false, $messages_count <= 0); |
} |
if ($this->delete_enabled()) { |
echo ' '; |
echo $this->htmlSubmit('operation', 'Delete', $this->getCSSclass('delete', $position), |
false, $messages_count <= 0); |
} |
} |
echo '</td></tr></table>',"\n"; |
} /* }}} */ |
function display_record_buttons() /* {{{ */ |
{ |
echo '<table class="',$this->getCSSclass('navigation', $position),'">',"\n"; |
echo '<tr class="',$this->getCSSclass('navigation', $position),'">',"\n"; |
echo '<td class="',$this->getCSSclass('buttons', $position),'">',"\n"; |
$this->print_article_select($article_id, 1, $position); |
echo '</td>',"\n"; |
if (strlen(@$this->message) > 0) { |
echo '<td class="',$this->getCSSclass('message', $position),'">',$this->message,'</td>',"\n"; |
} |
echo '<td class="',$this->getCSSclass('buttons2', $position),'">',"\n"; |
if ($this->change_operation()) { |
echo $this->htmlSubmit('savechange', 'Save', $this->getCSSclass('save', $position), true), ' '; |
echo $this->htmlSubmit('morechange', 'Apply', $this->getCSSclass('more', $position), true), ' '; |
echo $this->htmlSubmit('cancelchange', 'Cancel', $this->getCSSclass('cancel', $position), false); |
} elseif ($this->add_operation()) { |
echo $this->htmlSubmit('saveadd', 'Save', $this->getCSSclass('save', $position), true), ' '; |
echo $this->htmlSubmit('moreadd', 'More', $this->getCSSclass('more', $position), true), ' '; |
echo $this->htmlSubmit('canceladd', 'Cancel', $this->getCSSclass('cancel', $position), false); |
} elseif ($this->delete_operation()) { |
echo $this->htmlSubmit('savedelete', 'Delete', $this->getCSSclass('save', $position), false), ' '; |
echo $this->htmlSubmit('canceldelete', 'Cancel', $this->getCSSclass('cancel', $position), false); |
} elseif ($this->view_operation()) { |
if ($this->change_enabled()) { |
echo $this->htmlSubmit('operation', 'Change', $this->getCSSclass('save', $position), false), ' '; |
} |
echo $this->htmlSubmit('cancelview', 'Cancel', $this->getCSSclass('cancel', $position), false); |
} |
// Message is now written here |
echo '</td>',"\n"; |
echo '</tr></table>',"\n"; |
} /* }}} */ |
function print_article_select($selected_id, $disabled, $position) /* {{{ */ |
{ |
if ($selected_id <= 0) { |
$rec = intval($this->get_sys_cgi_var('rec')); |
if ($rec > 0) { |
$query = sprintf('SELECT article_id FROM %s WHERE id = %d', |
$this->tb, $rec); |
$result = $this->myquery($query); |
if ($result != false) { |
$row = @mysql_fetch_array($result, MYSQL_NUM); |
$selected_id = $row[0]; |
} |
@mysql_free_result($result); |
} |
} |
static $articles = null; |
if ($articles == null) { |
$articles = array(); |
$query = 'SELECT id, title, atitle, UNIX_TIMESTAMP(datetime) AS date' |
.' FROM '.$this->tb2 |
.' ORDER BY date DESC'; |
if (($result = $this->myquery($query)) == false) { |
return false; |
} |
for ($k = 0; ($row = @mysql_fetch_array($result, MYSQL_ASSOC)); $k++) { |
$articles[] = $row; |
} |
@mysql_free_result($result); |
} |
echo '<select',($disabled ? ' disabled' : ''),' name="'; |
echo $this->cgi['prefix']['sys'].'ezin_admin_article_',$position,'" size="1">',"\n"; |
echo '<option value="0">-- Choose article --</option>',"\n"; |
foreach ($articles as $row) { |
$row['title'] = empty($row['title']) ? $row['atitle'] : $row['title']; |
$row['title'] = Platon::pretty_substr(strip_tags($row['title']), 40); |
echo '<option'.($selected_id == $row['id'] ? ' selected' : ''); |
echo ' value="',$row['id'],'">',$row['title']; |
if ($row['date'] > 0) { |
printf(' [%d] (%s)', $row['id'], date($this->format_date, $row['date'])); |
} |
echo '</option>',"\n"; |
} |
echo '</select>',"\n"; |
if (! $disabled) { |
echo $this->htmlSubmit('ezin_admin_article_change_'.$position, ' > ', $this->get_sys_cgi_var('change', $position)), ' ', "\n"; |
} |
return true; |
} /* }}} */ |
} |
/* Modeline for ViM {{{ |
* vim:set ts=4: |
* vim600:fdm=marker fdl=0 fdc=0: |
* }}} */ |
?> |
/trunk/jrest/util/extensions/phpMyEdit-report.class.php |
---|
New file |
0,0 → 1,319 |
<?php |
/* |
* phpMyEdit - instant MySQL table editor and code generator |
* |
* extensions/phpMyEdit-report.class.php - phpMyEdit report extension |
* ____________________________________________________________ |
* |
* Developed by Ondrej Jombik <nepto@platon.sk> |
* Copyright (c) 2002-2006 Platon Group, http://platon.sk/ |
* All rights reserved. |
* |
* See README file for more information about this software. |
* See COPYING file for license information. |
* |
* Download the latest version from |
* http://platon.sk/projects/phpMyEdit/ |
*/ |
/* $Platon: phpMyEdit/extensions/phpMyEdit-report.class.php,v 1.12 2006-01-22 21:44:23 nepto Exp $ */ |
/* Extension TODO: |
- allow user to enable/disable particular field in reporting (maybe 'X' flag |
for indicating that field is forbidden is good idea) |
- support for ['help'] in select fields screen |
- make extension's option for selecting "Select fields" link or button |
*/ |
require_once dirname(__FILE__).'/../phpMyEdit.class.php'; |
class phpMyEdit_report extends phpMyEdit |
{ |
function phpMyEdit_report($opts) /* {{{ */ |
{ |
$opts['options'] = 'L'; |
$execute = 1; |
isset($opts['execute']) && $execute = $opts['execute']; |
$opts['execute'] = 0; |
parent::phpMyEdit($opts); |
$execute && $this->execute(); |
} /* }}} */ |
function make_language_labels($language) /* {{{ */ |
{ |
$ret = parent::make_language_labels($language); |
strlen($ret['Make report']) <= 0 && $ret['Make report'] = 'Make report'; |
strlen($ret['Select fields']) <= 0 && $ret['Select fields'] = 'Select fields'; |
strlen($ret['Records per screen']) <= 0 && $ret['Records per screen'] = 'Records per screen'; |
return $ret; |
} /* }}} */ |
function get_cgi_cookie_var($name, $default_value = null) /* {{{ */ |
{ |
$ret = $this->get_cgi_var($name, null); |
if ($ret === null) { |
global $HTTP_COOKIE_VARS; |
$ret = @$HTTP_COOKIE_VARS[$name.'_'.$this->tb.'_cookie']; |
if (! isset($ret)) { |
$ret = $default_value; |
} |
} |
return $ret; |
} /* }}} */ |
function display_list_table_buttons($total_recs, $position) /* {{{ */ |
{ /* This is mostly copy/paste from core class. */ |
$listall = $this->inc <= 0; // Are we doing a listall? |
echo '<table class="',$this->getCSSclass('navigation', $position),'">',"\n"; |
echo '<tr class="',$this->getCSSclass('navigation', $position),'">',"\n"; |
echo '<td class="',$this->getCSSclass('buttons', $position),'">',"\n"; |
echo '<input class="',$this->getCSSclass('fields-select', $position); |
echo '" type="submit" name="fields_select" value="',$this->labels['Select fields'],'"> '; |
// Note that <input disabled isn't valid HTML, but most browsers support it |
$disabled = ($this->fm > 0 && ! $listall) ? '' : ' disabled'; |
echo '<input',$disabled,' class="',$this->getCSSclass('prev', $position); |
echo '" type="submit" name="',ltrim($disabled),'prev" value="',$this->labels['Prev'],'"> '; |
$disabled = ($this->fm + $this->inc < $total_recs && ! $listall) ? '' : ' disabled'; |
echo '<input',$disabled,' class="',$this->getCSSclass('next', $position); |
echo '" type="submit" name="',ltrim($disabled),'next" value="',$this->labels['Next'],'">'; |
// Message is now written here |
echo '</td>',"\n"; |
if (strlen(@$this->message) > 0) { |
echo '<td class="',$this->getCSSclass('message', $position),'">',$this->message,'</td>',"\n"; |
} |
// Display page and records statistics |
echo '<td class="',$this->getCSSclass('stats', $position),'">',"\n"; |
if ($listall) { |
echo $this->labels['Page'],': 1 ',$this->labels['of'],' 1'; |
} else { |
echo $this->labels['Page'],': ',($this->fm / $this->inc) + 1; |
echo ' ',$this->labels['of'],' ',max(1, ceil($total_recs / abs($this->inc))); |
} |
echo ' ',$this->labels['Records'],': ',$total_recs; |
echo '</td></tr></table>',"\n"; |
} /* }}} */ |
function display_report_selection_buttons($position) /* {{{ */ |
{ |
echo '<table class="',$this->getCSSclass('navigation', $position),'">',"\n"; |
echo '<tr class="',$this->getCSSclass('navigation', $position),'">',"\n"; |
echo '<td class="',$this->getCSSclass('buttons', $position),'">',"\n"; |
echo '<input class="',$this->getCSSclass('make-report', $position); |
echo '" type="submit" name="prepare_filter" value="',$this->labels['Make report'],'">',"\n"; |
echo '</td></tr></table>',"\n"; |
} /* }}} */ |
function get_select_fields_link() /* {{{ */ |
{ |
$link = '<a href="'.htmlspecialchars($this->page_name).'?fields_select=1'; |
for ($i = 0; $i < count($table_cols); $i++) { |
$varname = 'qf'.$i; |
$value = $this->get_cgi_cookie_var($varname); |
if (! empty($value)) { |
$link .= htmlspecialchars( |
'&'.rawurlencode($varname). |
'='.rawurlencode($value)); |
} |
} |
$link .= htmlspecialchars($this->cgi['persist']); |
$link .= '">'.$this->labels['Select fields'].'</a>'; |
return $link; |
} /* }}} */ |
function execute() /* {{{ */ |
{ |
global $HTTP_GET_VARS; |
global $HTTP_POST_VARS; |
/* |
* Extracting field names |
*/ |
$table_cols = array(); |
$all_table_cols = array(); |
if ($this->connect() == false) { |
return false; |
} |
$query_parts = array( |
'type' => 'select', |
'select' => '*', |
'from' => $this->tb, |
'limit' => '1'); |
$result = $this->myquery($this->get_SQL_query($query_parts), __LINE__); |
$all_table_cols = array_keys(@mysql_fetch_array($result, MYSQL_ASSOC)); |
if (count($all_table_cols) <= 0) { |
$this->error('database fetch error'); |
return false; |
} |
foreach (array_keys($this->fdd) as $field_name) { |
if (preg_match('/^\d*$/', $field_name)) |
continue; |
if (($idx = array_search($field_name, $all_table_cols)) !== false) |
$table_cols[$field_name] = mysql_field_len($result, $idx); |
} |
@mysql_free_result($result); |
unset($all_table_cols); |
/* |
* Preparing variables |
*/ |
$fields_select = $this->get_cgi_var('fields_select'); |
$filter = $this->get_cgi_var('filter'); |
$prepare_filter = $this->get_cgi_var('prepare_filter'); |
$this->inc = intval($this->get_cgi_cookie_var('inc')); |
$force_select = true; |
$none_displayed = true; |
$expire_time = time() + (3600 * 24 * 30 * 12 * 5); // five years |
$headers_sent = @headers_sent(); |
foreach (array_merge(array('@inc'), array_keys($table_cols)) as $col) { |
$varname = ($col[0] == '@' ? substr($col, 1) : 'have_'.$col); |
if (isset($HTTP_POST_VARS[$varname]) || isset($HTTP_GET_VARS[$varname])) { |
$value = $HTTP_POST_VARS[$varname]; |
if (isset($HTTP_GET_VARS[$varname])) { |
$value = $HTTP_GET_VARS[$varname]; |
} |
if ($varname != 'inc' && ! empty($value)) { |
$force_select = false; |
} |
$headers_sent || setcookie($varname.'_'.$this->tb.'_cookie', $value, $expire_time); |
$this->cgi['persist'] .= '&'.urlencode($varname); |
$this->cgi['persist'] .= '='.urlencode($value); |
} else { |
$headers_sent || setcookie($varname.'_'.$this->tb.'_cookie', '', time() - 10000); |
} |
} |
$i = -1; |
foreach (array_keys($this->fdd) as $key) { |
$i++; |
if (preg_match('/^\d*$/', $key)) |
continue; |
$varname = 'have_'.$key; |
$value = @$this->get_cgi_cookie_var($varname, ''); |
$options = @$value ? 'LV' : ''; |
$this->fdd[$i]['options'] = $options; |
$this->fdd[$key]['options'] = $options; |
$this->displayed[$i] = @$value ? true : false; |
$value && $none_displayed = false; |
} |
/* |
* Redirecting when neccessary |
* (hackity hack with unregistering/unchecking fields) |
*/ |
if ($prepare_filter && ! $headers_sent) { |
$this->execute_redirect(); |
exit; |
} |
/* |
* Check if field selection report screen has to be displayed |
*/ |
if (isset($fields_select) || $force_select || $none_displayed) { |
$this->execute_report_screen($table_cols); |
return true; |
} |
if (0) { |
$this->message .= $this->get_select_fields_link(); |
} |
// parent class call |
return parent::execute(); |
} /* }}} */ |
function execute_redirect() /* {{{ */ |
{ |
global $HTTP_SERVER_VARS; |
global $HTTP_GET_VARS; |
global $HTTP_POST_VARS; |
$redirect_url = 'http://'.$HTTP_SERVER_VARS['HTTP_HOST'].$HTTP_SERVER_VARS['SCRIPT_NAME']; |
$delim = '?'; |
foreach ($HTTP_POST_VARS + $HTTP_GET_VARS as $cgi_var_name => $cgi_var_value) { |
$cgi_var_name == 'prepare_filter' && $cgi_var_name = 'filter'; |
$redirect_url .= $delim; |
$redirect_url .= rawurlencode($cgi_var_name).'='.rawurlencode($cgi_var_value); |
$delim == '?' && $delim = '&'; |
} |
$redirect_url .= $this->cgi['persist']; |
header('Location: '.$redirect_url); |
exit; |
} /* }}} */ |
function execute_report_screen($table_cols) /* {{{ */ |
{ |
echo '<form class="',$this->getCSSclass('form'),'" action="'; |
echo htmlspecialchars($this->page_name),'" method="POST">',"\n"; |
if ($this->nav_up()) { |
$this->display_report_selection_buttons('up'); |
echo '<hr class="',$this->getCSSclass('hr', 'up'),'">',"\n"; |
} |
echo '<table class="',$this->getCSSclass('main'),'" summary="',$this->tb,'">',"\n"; |
$i = 0; |
foreach ($table_cols as $key => $val) { |
$css_postfix = @$this->fdd[$key]['css']['postfix']; |
$css_class_name = $this->getCSSclass('input', null, true, $css_postfix); |
$varname = 'have_'.$key; |
$value = $this->get_cgi_cookie_var($varname); |
$checked = @$value ? ' checked' : ''; |
echo '<tr class="',$this->getCSSclass('row', null, 'next', $css_postfix),'">',"\n"; |
echo '<td class="',$this->getCSSclass('key', null, true, $css_postfix),'">'; |
echo $this->fdd[$i]['name'],'</td>',"\n"; |
echo '<td class="',$this->getCSSclass('check', null, true, $css_postfix),'">'; |
echo '<input class="',$css_class_name,'" type="checkbox" name="'; |
echo htmlspecialchars($varname),'"',$checked,'>'; |
echo '</td>',"\n"; |
echo '<td class="',$this->getCSSclass('value', null, true, $css_postfix),'"'; |
echo $this->getColAttributes($key),">\n"; |
$varname = 'qf'.$i; |
$value = $this->get_cgi_cookie_var($varname); |
if ($this->fdd[$key]['select'] == 'D' || $this->fdd[$key]['select'] == 'M') { |
$from_table = ! $this->col_has_values($key) || isset($this->fdd[$key]['values']['table']); |
$selected = $value; |
$value = $this->set_values($key, array('*' => '*'), null, $from_table); |
$multiple = $this->col_has_multiple_select($key); |
$multiple |= $this->fdd[$key]['select'] == 'M'; |
$readonly = false; |
$strip_tags = true; |
$escape = true; |
echo $this->htmlSelect($varname.'_id', $css_class_name, $value, $selected, |
$multiple, $readonly, $strip_tags, $escape); |
} else { |
echo '<input class="',$css_class_name,'" type=text name="'; |
echo htmlspecialchars($varname),'" value="',htmlspecialchars($value),'" size="'; |
echo min(40, $val),'" maxlength="',min(40, max(10, $val)),'">'; |
} |
echo '</td>',"\n",'</tr>',"\n"; |
$i++; |
} |
echo '<tr class="',$this->getCSSclass('row', null, 'next', $css_postfix),'">',"\n"; |
echo '<td class="',$this->getCSSclass('key', null, true, $css_postfix),'" colspan="2">'; |
echo $this->labels['Records per screen'],'</td>'; |
echo '<td class="',$this->getCSSclass('value', null, true, $css_postfix),'">'; |
echo '<input class="',$css_class_name,'" type="text" name="inc" value="',$this->inc.'">'; |
echo '</td></tr>',"\n"; |
echo '</table>',"\n"; |
if ($this->nav_down()) { |
echo '<hr class="',$this->getCSSclass('hr', 'down'),'">',"\n"; |
$this->display_report_selection_buttons('down'); |
} |
echo '</form>'; |
} /* }}} */ |
} |
/* Modeline for ViM {{{ |
* vim:set ts=4: |
* vim600:fdm=marker fdl=0 fdc=0: |
* }}} */ |
?> |
/trunk/jrest/util/extensions/phpMyEdit-htmlarea.class.php |
---|
New file |
0,0 → 1,209 |
<?php |
/* |
* phpMyEdit - instant MySQL table editor and code generator |
* |
* extensions/phpMyEdit-htmlarea.class.php - phpMyEdit htmlArea extension |
* ____________________________________________________________ |
* |
* Contribution of Ezudin Kurtowich <ekurtovic@ieee.org>, Sarajevo |
* Copyright (c) 2003-2006 Platon Group, http://platon.sk/ |
* All rights reserved. |
* |
* See README file for more information about this software. |
* See COPYING file for license information. |
* |
* Download the latest version from |
* http://platon.sk/projects/phpMyEdit/ |
*/ |
/* $Platon: phpMyEdit/extensions/phpMyEdit-htmlarea.class.php,v 1.10 2006-01-22 21:44:18 nepto Exp $ */ |
/* |
OVERVIEW |
-------- |
NOTE...This extension will not work with the CVS version of PME. It has |
been replaced by the mce_cal extension. |
htmlArea is a free WYSIWYG textarea replacement from |
http://www.interactivetools.com/ website. |
REQUIREMENTS |
------------ |
The extension requires a properly installed htmlArea script |
as described on the http://www.interactivetools.com/ site. |
USAGE |
----- |
This extension enables WYSIWYG editing of a textarea field. |
In order to use it, you should: |
1. Load htmlArea script in the <head>...</head> section of your |
phpMyEdit calling program as described in the htmlarea manual. |
NOTE: To avoid an unwanted side effect in css style produced |
by phpMyEditSetup.php, delete 'table-width:100%' property. |
2. Call to phpMyEdit-htmlarea.class.php instead |
of phpMyEdit.class.php. |
Example: |
require_once 'extensions/phpMyEdit-htmlarea.class.php'; |
new phpMyEdit_htmlarea($opts); |
3. Add 'html'=>true parameter to the textarea field definition |
in your phpMyEdit calling program. |
Example: |
$opts['fdd']['col_name'] = array( |
'name' => 'Column', |
'select' => 'T', |
'options' => 'ACPVD', |
'required' => true, |
'textarea' => array( |
'html' => true, |
'rows' => 11, |
'cols' => 81) |
); |
SEARCH KEYWORD |
-------------- |
Search for "htmlArea" string in this source code, |
to find all extension related modifications. |
*/ |
require_once dirname(__FILE__).'/../phpMyEdit.class.php'; |
class phpMyEdit_htmlarea extends phpMyEdit |
{ |
/* |
* Display functions overriding |
*/ |
function display_add_record() /* {{{ */ |
{ |
for ($k = 0; $k < $this->num_fds; $k++) { |
if ($this->hidden($k)) { |
echo $this->htmlHidden($this->fds[$k], $row["qf$k"]); |
continue; |
} |
if (! $this->displayed[$k]) { |
continue; |
} |
$css_postfix = @$this->fdd[$k]['css']['postfix']; |
$css_class_name = $this->getCSSclass('input', null, 'next', $css_postfix); |
echo '<tr class="',$this->getCSSclass('row', null, true, $css_postfix),'">',"\n"; |
echo '<td class="',$this->getCSSclass('key', null, true, $css_postfix),'">',$this->fdd[$k]['name'],'</td>',"\n"; |
echo '<td class="',$this->getCSSclass('value', null, true, $css_postfix),'">'."\n"; |
if ($this->col_has_values($k)) { |
$vals = $this->set_values($k); |
$selected = @$this->fdd[$k]['default']; |
$multiple = $this->fdd[$k]['select'] == 'M' && ! $this->fdd[$k]['values']['table']; |
$readonly = $this->readonly($k); |
echo $this->htmlSelect($this->fds[$k], $css_class_name, $vals, $selected, $multiple,$readonly); |
} elseif (isset ($this->fdd[$k]['textarea'])) { |
echo '<textarea class="',$css_class_name,'" name="'.$this->fds[$k].'"'; |
echo ($this->readonly($k) ? ' disabled' : ''); |
if (intval($this->fdd[$k]['textarea']['rows']) > 0) { |
echo ' rows="',$this->fdd[$k]['textarea']['rows'],'"'; |
} |
if (intval($this->fdd[$k]['textarea']['cols']) > 0) { |
echo ' cols="',$this->fdd[$k]['textarea']['cols'],'"'; |
} |
if (isset($this->fdd[$k]['textarea']['wrap'])) { |
echo ' wrap="',$this->fdd[$k]['textarea']['wrap'],'"'; |
} else { |
echo ' wrap="virtual"'; |
} |
echo '>',htmlspecialchars($this->fdd[$k]['default']),'</textarea>',"\n"; |
// EK htmlArea code modification is here |
if (isset($this->fdd[$k]['textarea']['html'])) { |
echo '<script type="text/javascript" language="javascript1.2"><!--',"\n"; |
echo 'editor_generate("',$this->fds[$k],'");',"\n"; |
echo '// --></script>'; |
} |
} else { |
// Simple edit box required |
$size_ml_props = ''; |
$maxlen = intval($this->fdd[$k]['maxlen']); |
//$maxlen > 0 || $maxlen = 300; |
$size = min($maxlen, 60); |
$size && $size_ml_props .= ' size="'.$size.'"'; |
$maxlen && $size_ml_props .= ' maxlength="'.$maxlen.'"'; |
echo '<input class="',$css_class_name,'" type="text" '; |
echo ($this->readonly($k) ? 'disabled ' : ''),' name="',$this->fds[$k],'"'; |
echo $size_ml_props,' value="'; |
echo htmlspecialchars($this->fdd[$k]['default']),'">'; |
} |
echo '</td>',"\n"; |
if ($this->guidance) { |
$css_class_name = $this->getCSSclass('help', null, true, $css_postfix); |
$cell_value = $this->fdd[$k]['help'] ? $this->fdd[$k]['help'] : ' '; |
echo '<td class="',$css_class_name,'">',$cell_value,'</td>',"\n"; |
} |
echo '</tr>',"\n"; |
} |
} /* }}} */ |
function display_change_field($row, $k) /* {{{ */ |
{ |
$css_postfix = @$this->fdd[$k]['css']['postfix']; |
$css_class_name = $this->getCSSclass('input', null, true, $css_postfix); |
echo '<td class="',$this->getCSSclass('value', null, true, $css_postfix),'">',"\n"; |
if ($this->col_has_values($k)) { |
$vals = $this->set_values($k); |
$multiple = $this->fdd[$k]['select'] == 'M' && ! $this->fdd[$k]['values']['table']; |
$readonly = $this->readonly($k); |
echo $this->htmlSelect($this->fds[$k], $css_class_name, $vals, $row["qf$k"], $multiple, $readonly); |
} elseif (isset($this->fdd[$k]['textarea'])) { |
echo '<textarea class="',$css_class_name,'" name="'.$this->fds[$k].'"'; |
echo ($this->readonly($k) ? ' disabled' : ''); |
if (intval($this->fdd[$k]['textarea']['rows']) > 0) { |
echo ' rows="',$this->fdd[$k]['textarea']['rows'],'"'; |
} |
if (intval($this->fdd[$k]['textarea']['cols']) > 0) { |
echo ' cols="',$this->fdd[$k]['textarea']['cols'],'"'; |
} |
if (isset($this->fdd[$k]['textarea']['wrap'])) { |
echo ' wrap="',$this->fdd[$k]['textarea']['wrap'],'"'; |
} else { |
echo ' wrap="virtual"'; |
} |
echo '>',htmlspecialchars($row["qf$k"]),'</textarea>',"\n"; |
// EK htmlArea code modification is here |
if (isset($this->fdd[$k]['textarea']['html'])) { |
echo '<script type="text/javascript" language="javascript1.2"><!--',"\n"; |
echo 'editor_generate("',$this->fds[$k],'");',"\n"; |
echo '// --></script>'; |
} |
} else { |
$size_ml_props = ''; |
$maxlen = intval($this->fdd[$k]['maxlen']); |
//$maxlen > 0 || $maxlen = 300; |
$size = min($maxlen, 60); |
$size && $size_ml_props .= ' size="'.$size.'"'; |
$maxlen && $size_ml_props .= ' maxlength="'.$maxlen.'"'; |
echo '<input class="',$css_class_name,'" type="text" '; |
echo ($this->readonly($k) ? 'disabled ' : ''),'name="',$this->fds[$k],'" value="'; |
echo htmlspecialchars($row["qf$k"]),'" ',$size_ml_props,'>',"\n"; |
} |
echo '</td>',"\n"; |
} /* }}} */ |
} |
/* Modeline for ViM {{{ |
* vim:set ts=4: |
* vim600:fdm=marker fdl=0 fdc=0: |
* }}} */ |
?> |
/trunk/jrest/util/extensions/phpMyEdit-slide.class.php |
---|
New file |
0,0 → 1,144 |
<?php |
/* |
* phpMyEdit - instant MySQL table editor and code generator |
* |
* extensions/phpMyEdit-slide.class.php - slide show extension for phpMyEdit |
* ____________________________________________________________ |
* |
* Developed by Ondrej Jombik <nepto@platon.sk> |
* Copyright (c) 2002-2006 Platon Group, http://platon.sk/ |
* All rights reserved. |
* |
* See README file for more information about this software. |
* See COPYING file for license information. |
* |
* Download the latest version from |
* http://platon.sk/projects/phpMyEdit/ |
*/ |
/* $Platon: phpMyEdit/extensions/phpMyEdit-slide.class.php,v 1.10 2006-01-22 21:44:24 nepto Exp $ */ |
/* |
* Coding elapsed time: from 8:30 to 10:30 at 30th October 2002 |
* with heavy patching phpMyEdit core class. |
* |
* Music used: E-Type (Campione, This is the Way and others) |
*/ |
require_once dirname(__FILE__).'/../phpMyEdit.class.php'; |
class phpMyEdit_slide extends phpMyEdit |
{ |
// Extension options array |
var $ext; |
function phpMyEdit_slide($opts) /* {{{ */ |
{ |
$execute = 1; |
isset($opts['execute']) && $execute = $opts['execute']; |
$opts['execute'] = 0; |
parent::phpMyEdit($opts); |
$this->ext = $opts['ext']; |
$execute && $this->execute($opts); |
} /* }}} */ |
function display_record_buttons() /* {{{ */ |
{ |
// TODO: classify this table and cells |
echo '<table border=0 cellpadding=0 cellspacing=0 width="100%" style="border:0;padding:0;">'; |
echo '<tr><td align=left style="text-align:left;border:0;padding:0;" nowrap>' . "\n"; |
if ($this->change_operation()) { |
echo '<input type="submit" name="savechange" value="'.$this->labels['Save'].'" />'."\n"; |
echo '<input type="submit" name="morechange" value="'.$this->labels['Apply'].'" />'."\n"; |
echo '<input type="button" name="cancel" value="'.$this->labels['Cancel'].'" onClick="form.submit();" />'."\n"; |
echo '<input type="hidden" name="rec_change" value="1">'; |
} elseif ($this->view_operation()) { |
if ($this->change_enabled()) { |
echo '<input type="submit" name="operation" value="'.$this->labels['Change'].'" />'."\n"; |
} |
echo '<input type="submit" name="cancel" value="'.$this->labels['Cancel'].'" />'."\n"; |
} |
if (! $this->ext['prev_disable']) { |
$disabled = $this->ext['prev'] ? '' : ' disabled'; |
echo '<input'.$disabled.' type="submit" name="'.ltrim($disabled).'prev" value="' |
.$this->labels['Prev'].'"> '; |
echo '<input type="hidden" name="rec_prev" value="'.$this->ext['prev'].'">'; |
} |
if (! $this->ext['next_disable']) { |
$disabled = $this->ext['next'] ? '' : ' disabled'; |
echo '<input'.$disabled.' type="submit" name="'.ltrim($disabled).'next" value="' |
.$this->labels['Next'].'">'; |
echo '<input type="hidden" name="rec_next" value="'.$this->ext['next'].'">'; |
} |
echo '</td></tr></table>'."\n"; |
} /* }}} */ |
function execute($opts) /* {{{ */ |
{ |
if ($this->get_cgi_var('rec_change') |
&& ($this->next_operation() || $this->prev_operation())) { |
$this->operation = $this->labels['Change']; |
} |
if (! $this->change_operation()) { |
$this->operation = $this->labels['View']; |
} |
if ($this->prev_operation()) { |
! $this->ext['prev_disabled'] && $this->rec = $this->get_cgi_var('rec_prev'); |
$this->prev = ''; |
} |
if ($this->next_operation()) { |
! $this->ext['next_disabled'] && $this->rec = $this->get_cgi_var('rec_next'); |
$this->next = ''; |
} |
if (! $this->rec) { |
$this->rec = $this->ext['rec']; |
} |
if (! $this->rec |
|| (! $this->ext['prev_disable'] && ! $this->ext['prev']) |
|| (! $this->ext['next_disable'] && ! $this->ext['next'])) { |
if ($this->connect() == false) { |
return false; |
} |
$query_parts = array( |
'type' => 'select', |
// XXX FIXME - simplify query |
'select' => 'PMEtable0.'.$this->key, |
'from' => $this->get_SQL_join_clause(), |
'where' => $this->get_SQL_where_from_query_opts()); |
// TODO: order by clausule according to default sort order options |
$res = $this->myquery($this->get_SQL_query($query_parts), __LINE__); |
$ids = array(); |
while (($row = @mysql_fetch_array($res, MYSQL_NUM)) !== false) { |
$ids[] = $row[0]; |
} |
@mysql_free_result($res); |
if ($this->rec) { |
$idx = array_search($this->rec, $ids); |
$idx === false && $idx = 0; |
} else { |
$idx = 0; |
} |
$this->rec = $ids[$idx]; |
! $this->ext['prev'] && $this->ext['prev'] = $ids[$idx - 1]; |
! $this->ext['next'] && $this->ext['next'] = $ids[$idx + 1]; |
} |
$this->recreate_fdd(); |
$this->recreate_displayed(); |
parent::execute(); |
} /* }}} */ |
} |
/* Modeline for ViM {{{ |
* vim:set ts=4: |
* vim600:fdm=marker fdl=0 fdc=0: |
* }}} */ |
?> |
/trunk/jrest/util/extensions/phpMyEdit-mce-cal.class.php |
---|
New file |
0,0 → 1,509 |
<?php |
/* |
* phpMyEdit - instant MySQL table editor and code generator |
* |
* extensions/phpMyEdit-mce-cal.class.php - phpMyEdit html area & calendar popup extension |
* ____________________________________________________________ |
* |
* Contribution of Adam Hammond <php@pixolet.co.uk>, London, UK |
* Contribution of Ezudin Kurtowich <ekurtovic@ieee.org>, Sarajevo |
* Copyright (c) 2003-2006 Platon Group, http://platon.sk/ |
* All rights reserved. |
* |
* Updated 28th Jul 2005 |
* |
* Updated to use TinyMCE instead of HTMLArea |
* Updated to handle multiple tabs and to use PME prefixes. |
* Updated to include sub-form patch |
* |
* |
* |
* See README file for more information about this software. |
* See COPYING file for license information. |
* |
* Download the latest version from |
* http://platon.sk/projects/phpMyEdit/ |
*/ |
/* $Platon: phpMyEdit/extensions/phpMyEdit-mce-cal.class.php,v 1.6 2006-09-16 18:43:47 nepto Exp $ */ |
/* |
OVERVIEW |
-------- |
mce_cal extends the standard phpMyEdit class to allow |
a calendar popup helper to be put on any text field and for any textarea |
field to turned into an HTML editor. |
This extension uses the free jsCalendar from http://dynarch.com/mishoo |
and the TinyMCE code from http://tinymce.moxiecode.com/ |
REQUIREMENTS |
------------ |
The requirement is a properly installed jsCalendar and TinyMCE script. |
All browsers supported by these scripts are supported by this |
extension. Note that version 1.44 or later for TinyMCE is required. |
USAGE |
----- |
For both features: |
1. Call to phpMyEdit-mce-cal.class.php instead |
of phpMyEdit.class.php. |
Example: |
require_once 'extensions/phpMyEdit-mce-cal.class.php'; |
new phpMyEdit_mce_cal($opts); |
HTML TextArea |
This enables WYSIWYG editing of a textarea field. |
In order to use it, you should: |
1. Load TinyMCE script in the <head>...</head> section of your |
phpMyEdit calling program as described in the htmlarea manual. |
<!-- tinyMCE --> |
<script language="javascript" type="text/javascript" src="js/<path to TinyMCE>"></script> |
<script language="javascript" type="text/javascript"> |
tinyMCE.init({ |
mode : "specific_textareas", |
auto_reset_designmode : true |
}); |
</script> |
<!-- /tinyMCE --> |
where 'js/<path to TinyMCE>' is the path to the javascript code |
NOTES: |
A. The PME implementation uses the "specific_textareas" mode - this |
must always be set |
B. Due to a bug in Mozilla, if any of the textareas being used as HTML |
editors are in tabs and are initially hidden, the width and height |
need to be specified in the tinyMCE initialization and |
'auto_reset_designmode' must be set to 'true': |
tinyMCE.init({ |
mode : "specific_textareas", |
auto_reset_designmode : true, |
width: "800", |
height: "200" |
}); |
2. Add 'html'=>true parameter to the textarea field definition |
in your phpMyEdit calling program. |
Example: |
$opts['fdd']['col_name'] = array( |
'name' => 'Column', |
'select' => 'T', |
'options' => 'ACPVD', |
'required' => true, |
'textarea' => array( |
'html' => true, |
'rows' => 11, |
'cols' => 81) |
); |
3. It is also possible to have multiple text area formats on the same |
form. This is done by specifying a text tag for the textarea: |
$opts['fdd']['col_name'] = array( |
'name' => 'Column', |
'select' => 'T', |
'options' => 'ACPVD', |
'required' => true, |
'textarea' => array( |
'html' => 'format1', |
'rows' => 11, |
'cols' => 81) |
); |
You then need to initialize TinyMCE in the header to recognize all of |
the tags used in the textareas. |
EXAMPLE |
In the following, two formats of tinyMCE editor are defined. |
This example is the default, and will be used for any fields where |
'html' is set to true. |
tinyMCE.init({ |
mode : "specific_textareas", |
auto_reset_designmode : true |
}); |
This second example has an extra parameter, 'textarea_trigger', which is |
set to the text tag given to the textarea in PME with 'mce_' prepended |
to it. |
tinyMCE.init({ |
mode : "specific_textareas", |
auto_reset_designmode : true, |
textarea_trigger : "mce_format1", |
theme : "advanced", |
width: "800", |
height: "200", |
plugins : "table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,zoom,flash,searchreplace,print", |
theme_advanced_buttons1_add_before : "save,separator", |
theme_advanced_buttons1_add : "fontselect,fontsizeselect", |
theme_advanced_buttons2_add : "separator,insertdate,inserttime,preview,zoom,separator,forecolor,backcolor", |
theme_advanced_buttons2_add_before: "cut,copy,paste,separator,search,replace,separator", |
theme_advanced_buttons3_add_before : "tablecontrols,separator", |
theme_advanced_buttons3_add : "emotions,iespell,flash,advhr,separator,print", |
theme_advanced_toolbar_location : "top", |
theme_advanced_toolbar_align : "left", |
theme_advanced_path_location : "bottom", |
content_css : "example_full.css", |
plugin_insertdate_dateFormat : "%Y-%m-%d", |
plugin_insertdate_timeFormat : "%H:%M:%S", |
extended_valid_elements : "a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]" |
}); |
So: |
'html' => 'format1' maps to textarea_trigger : "mce_format1" |
'html' => 'foo' maps to textarea_trigger : "mce_foo" |
'html' => 'bar' maps to textarea_trigger : "mce_bar" |
You can initialize TinyMCE as many times as you need to give you as many |
editor formats as you need. |
CALENDAR |
This extension enables the display of a popup calendar selection |
against selected fields. |
In order to use it, you should: |
1. Load the jsCalendar scripts in the <head>...</head> section of |
your phpMyEdit calling program, substituting the correct paths: |
<script type="text/javascript" src="js/jscalendar/calendar.js"></script> |
<script type="text/javascript" src="js/jscalendar/lang/calendar-en.js"></script> |
<script type="text/javascript" src="js/jscalendar/calendar-setup.js"></script> |
2. Choose your preferred jsCalendar CSS file (see jsCalendar |
documentation) and add the following in the <head>...</head> |
section of your phpMyEdit calling program, substituting the |
correct path: |
<link rel="stylesheet" type="text/css" media="screen" |
href="js/jscalendar/calendar-system.css"> |
3. Add 'calendar' parameter to the field definitions where you |
want a calendar popup in your phpMyEdit calling program. |
Example: |
$opts['fdd']['col_name'] = array( |
'name' => 'Column', |
'select' => 'T', |
'options' => 'ACPVD', |
'required' => true, |
'calendar' => true |
); |
This is will display a button next to the field which pops up |
a calendar when clicked. If that field has a 'strftimemask' |
parameter set, it will use this for the date format. |
For more advanced usage, you can set the 'calendar' parameter |
to an array of valid jsCalendar Calendar.setup options |
(see jSCalendar document for details). Note that not all |
of these options make sense to use in phpMyEdit, and some |
of them will actively break the function. |
Example: |
$opts['fdd']['col_name'] = array( |
'name' => 'Column', |
'select' => 'T', |
'options' => 'ACPVD', |
'required' => true, |
'calendar' => array( |
'ifFormat' => '%Y/%m/%d', // defaults to the ['strftimemask'] |
'firstDay' => 1, // 0 = Sunday, 1 = Monday |
'singleClick' => true, // single or double click to close |
'weekNumbers' => true, // Show week numbers |
'showsTime' => false, // Show time as well as date |
'timeFormat' => '24', // 12 or 24 hour clock |
'button' => true, // Display button (rather then clickable area) |
'label' => '...', // button label (used by phpMyEdit) |
'date' => '2003-12-19 10:00' // Initial date/time for popup |
// (see notes below) |
) |
); |
NOTES |
----- |
1. The popup will normally set the initial value to the current |
field value or to current date/time. 'date' option will always |
override this, even if there is a current date/time value |
in the field. If you want a default value only if the field |
is currently empty, use the phpMyEdit 'default' option. |
2. Only the options listed above may be set by the user, any other |
options will be ignored. |
3. The 'label' option can contain HTML markup which will be displayed as |
the button/clickable area to pull up the calendar |
SEARCH KEYWORD |
-------------- |
Search for "htmlcal" string in this source code, |
to find all extension related modifications. |
*/ |
require_once dirname(__FILE__).'/../phpMyEdit.class.php'; |
class phpMyEdit_mce_cal extends phpMyEdit |
{ |
/* calendar mod start */ |
var $calendars; // Array for collecting list of fields with calendar popups |
/* Array of valid options for passing to Calendar.setup */ |
var $valid_opts = array( |
'button','ifFormat','singleClick','firstDay', |
'weekNumbers','showsTime','timeFormat','date' |
); |
/** |
* Checks to see if the calendar parameter is set on the field |
* |
* @param k current field name |
* @param curval current value of field (set to null for default) |
* |
* If the calendar parameter is set on the field, this function displays |
* the button. It then pushes the Calendar.setup parameters into an array, |
* including the user specified ones in the calling program is they exist. |
* This array is then added to the $calendars array indexed by the field |
* name. This allows for multiple fields with calendar popups. |
*/ |
function calPopup_helper($k, $curval) /* {{{ */ |
{ |
if (@$this->fdd[$k]['calendar']) { |
$cal_ar['ifFormat'] = '%Y-%m-%d %H:%M'; |
$cal_ar['showsTime'] = true; |
$cal_ar['singleClick'] = false; |
if (isset($curval)) { |
if (substr($curval, 0, 4) != '0000') |
$cal_ar['date'] = $curval; |
} |
if (isset($this->fdd[$k]['strftimemask'])) { |
$cal_ar['ifFormat'] = $this->fdd[$k]['strftimemask']; |
} |
if (is_array($this->fdd[$k]['calendar'])) { |
foreach($this->fdd[$k]['calendar'] as $ck => $cv) { |
$cal_ar[$ck] = $cv; |
} |
} |
$cal_ar['button'] = $this->dhtml['prefix'].'calbutton_'.$this->fds[$k]; |
$this->calendars[$this->fds[$k]] = $cal_ar; |
$label = @$this->fdd[$k]['calendar']['label']; |
strlen($label) || $label = '...'; |
$do_button = true; |
if (isset($this->fdd[$k]['calendar']['button'])) { |
$do_button = $this->fdd[$k]['calendar']['button']; |
}; |
if ($do_button) { |
echo '<button id="',$cal_ar['button'],'">',$label,'</button>'; |
} else { |
echo '<span style="cursor: pointer" id="',$cal_ar['button'],'">',$label,'</span>'; |
} |
} |
} /* }}} */ |
/* calendar mod end */ |
function display_add_record() /* {{{ */ |
{ |
for ($tab = 0, $k = 0; $k < $this->num_fds; $k++) { |
if (isset($this->fdd[$k]['tab']) && $this->tabs_enabled() && $k > 0) { |
$tab++; |
echo '</table>',"\n"; |
echo '</div>',"\n"; |
echo '<div id="'.$this->dhtml['prefix'].'tab',$tab,'">',"\n"; |
echo '<table class="',$this->getCSSclass('main'),'" summary="',$this->tb,'">',"\n"; |
} |
if (! $this->displayed[$k]) { |
continue; |
} |
if ($this->hidden($k)) { |
echo $this->htmlHiddenData($this->fds[$k], $this->fdd[$k]['default']); |
continue; |
} |
$css_postfix = @$this->fdd[$k]['css']['postfix']; |
$css_class_name = $this->getCSSclass('input', null, 'next', $css_postfix); |
echo '<tr class="',$this->getCSSclass('row', null, true, $css_postfix),'">',"\n"; |
echo '<td class="',$this->getCSSclass('key', null, true, $css_postfix),'">'; |
echo $this->fdd[$k]['name'],'</td>',"\n"; |
echo '<td class="',$this->getCSSclass('value', null, true, $css_postfix),'"'; |
echo $this->getColAttributes($k),">\n"; |
if ($this->col_has_values($k)) { |
$vals = $this->set_values($k); |
$selected = @$this->fdd[$k]['default']; |
$multiple = $this->col_has_multiple_select($k); |
$readonly = $this->readonly($k); |
$strip_tags = true; |
$escape = true; |
echo $this->htmlSelect($this->cgi['prefix']['data'].$this->fds[$k], $css_class_name, |
$vals, $selected, $multiple, $readonly, $strip_tags, $escape); |
} elseif (isset ($this->fdd[$k]['textarea'])) { |
echo '<textarea class="',$css_class_name,'" name="',$this->cgi['prefix']['data'].$this->fds[$k],'"'; |
echo ($this->readonly($k) ? ' disabled' : ''); |
if (intval($this->fdd[$k]['textarea']['rows']) > 0) { |
echo ' rows="',$this->fdd[$k]['textarea']['rows'],'"'; |
} |
if (intval($this->fdd[$k]['textarea']['cols']) > 0) { |
echo ' cols="',$this->fdd[$k]['textarea']['cols'],'"'; |
} |
if (isset($this->fdd[$k]['textarea']['wrap'])) { |
echo ' wrap="',$this->fdd[$k]['textarea']['wrap'],'"'; |
} else { |
echo ' wrap="virtual"'; |
}; |
// mce mod start |
if (isset($this->fdd[$k]['textarea']['html'])) { |
$mce_tag = 'editable'; |
if (is_string($this->fdd[$k]['textarea']['html'])) { |
$mce_tag = $this->fdd[$k]['textarea']['html']; |
}; |
echo ' mce_'.$mce_tag.'=true '; |
}; |
// mce mod end |
echo '>',htmlspecialchars($this->fdd[$k]['default']),'</textarea>',"\n"; |
} else { |
// Simple edit box required |
$size_ml_props = ''; |
$maxlen = intval($this->fdd[$k]['maxlen']); |
$size = isset($this->fdd[$k]['size']) ? $this->fdd[$k]['size'] : min($maxlen, 60); |
$size && $size_ml_props .= ' size="'.$size.'"'; |
$maxlen && $size_ml_props .= ' maxlength="'.$maxlen.'"'; |
echo '<input class="',$css_class_name,'" '; |
echo ($this->password($k) ? 'type="password"' : 'type="text"'); |
echo ($this->readonly($k) ? ' disabled' : ''); |
/* calendar mod start */ |
echo ' id="',$this->dhtml['prefix'].'fld_'.$this->fds[$k],'"'; |
/* calendar mod end */ |
echo ' name="',$this->cgi['prefix']['data'].$this->fds[$k],'"'; |
echo $size_ml_props,' value="'; |
echo htmlspecialchars($this->fdd[$k]['default']),'">'; |
/* calendar mod start */ |
/* Call htmlcal helper function */ |
$this->calPopup_helper($k, null); |
/* calendar mod end */ |
} |
echo '</td>',"\n"; |
if ($this->guidance) { |
$css_class_name = $this->getCSSclass('help', null, true, $css_postfix); |
$cell_value = $this->fdd[$k]['help'] ? $this->fdd[$k]['help'] : ' '; |
echo '<td class="',$css_class_name,'">',$cell_value,'</td>',"\n"; |
} |
echo '</tr>',"\n"; |
} |
} /* }}} */ |
function display_change_field($row, $k) /* {{{ */ |
{ |
$css_postfix = @$this->fdd[$k]['css']['postfix']; |
$css_class_name = $this->getCSSclass('input', null, true, $css_postfix); |
echo '<td class="',$this->getCSSclass('value', null, true, $css_postfix),'"'; |
echo $this->getColAttributes($k),">\n"; |
if ($this->col_has_values($k)) { |
$vals = $this->set_values($k); |
$multiple = $this->col_has_multiple_select($k); |
$readonly = $this->readonly($k); |
$strip_tags = true; |
$escape = true; |
echo $this->htmlSelect($this->cgi['prefix']['data'].$this->fds[$k], $css_class_name, |
$vals, $row["qf$k"], $multiple, $readonly, $strip_tags, $escape); |
} elseif (isset($this->fdd[$k]['textarea'])) { |
echo '<textarea class="',$css_class_name,'" name="',$this->cgi['prefix']['data'].$this->fds[$k],'"'; |
echo ($this->readonly($k) ? ' disabled' : ''); |
if (intval($this->fdd[$k]['textarea']['rows']) > 0) { |
echo ' rows="',$this->fdd[$k]['textarea']['rows'],'"'; |
} |
if (intval($this->fdd[$k]['textarea']['cols']) > 0) { |
echo ' cols="',$this->fdd[$k]['textarea']['cols'],'"'; |
} |
if (isset($this->fdd[$k]['textarea']['wrap'])) { |
echo ' wrap="',$this->fdd[$k]['textarea']['wrap'],'"'; |
} else { |
echo ' wrap="virtual"'; |
}; |
// mce mod start |
if (isset($this->fdd[$k]['textarea']['html'])) { |
$mce_tag = 'editable'; |
if (is_string($this->fdd[$k]['textarea']['html'])) { |
$mce_tag = $this->fdd[$k]['textarea']['html']; |
}; |
echo ' mce_'.$mce_tag.'=true '; |
}; |
// mce mod end |
echo '>',htmlspecialchars($row["qf$k"]),'</textarea>',"\n"; |
} else { |
$size_ml_props = ''; |
$maxlen = intval($this->fdd[$k]['maxlen']); |
$size = isset($this->fdd[$k]['size']) ? $this->fdd[$k]['size'] : min($maxlen, 60); |
$size && $size_ml_props .= ' size="'.$size.'"'; |
$maxlen && $size_ml_props .= ' maxlength="'.$maxlen.'"'; |
echo '<input class="',$css_class_name,'" type="text" '; |
echo ($this->readonly($k) ? 'disabled ' : ''); |
/* calendar mod start */ |
echo ' id="',$this->dhtml['prefix'].'fld_'.$this->fds[$k],'"'; |
/* calendar mod end */ |
echo 'name="',$this->cgi['prefix']['data'].$this->fds[$k],'" value="'; |
echo htmlspecialchars($row["qf$k"]),'" ',$size_ml_props,'>',"\n"; |
/* calendar mod start */ |
/* Call calPopup helper function */ |
$this->calPopup_helper($k, htmlspecialchars($row["qf$k"])); |
/* calendar mod end */ |
} |
echo '</td>',"\n"; |
} /* }}} */ |
function form_end() /* {{{ */ |
{ |
if ($this->display['form']) { |
echo '</form>',"\n"; |
/* calendar mod start */ |
/* Add script calls to the end of the form for all fields |
with calendar popups. */ |
if (isset($this->calendars)) { |
echo '<script type="text/javascript"><!--',"\n"; |
foreach($this->calendars as $ck => $cv) { |
echo 'Calendar.setup({',"\n"; |
foreach ($cv as $ck1 => $cv1) { |
if (in_array($ck1, $this->valid_opts)) { |
echo "\t",str_pad($ck1, 15),' : "',$cv1,'",',"\n"; |
} |
} |
echo "\t",str_pad('inputField', 15),' : "',$this->dhtml['prefix'].'fld_'.$ck,'"',"\n"; |
echo '});',"\n"; |
}; |
echo '// -->',"\n"; |
echo '</script>',"\n"; |
}; |
/* calendar mod end */ |
}; |
} /* }}} */ |
} |
?> |
/trunk/jrest/util/extensions/phpMyEdit-calpopup.class.php |
---|
New file |
0,0 → 1,357 |
<?php |
/* |
* phpMyEdit - instant MySQL table editor and code generator |
* |
* extensions/phpMyEdit-calpopup.class.php - phpMyEdit calendar popup extension |
* ____________________________________________________________ |
* |
* Contribution of Adam Hammond <php@pixolet.co.uk>, London, UK |
* Copyright (c) 2003-2006 Platon Group, http://platon.sk/ |
* All rights reserved. |
* |
* See README file for more information about this software. |
* See COPYING file for license information. |
* |
* Download the latest version from |
* http://platon.sk/projects/phpMyEdit/ |
*/ |
/* $Platon: phpMyEdit/extensions/phpMyEdit-calpopup.class.php,v 1.9 2006-01-22 21:44:17 nepto Exp $ */ |
/* |
OVERVIEW |
-------- |
NOTE...This extension will not work with the CVS version of PME |
calPopup extends the standard phpMyEdit class to allow |
a calendar popup helper to be put on any text field. |
This extension uses the free jsCalendar code from |
http://dynarch.com/mishoo/calendar.epl website. |
REQUIREMENTS |
------------ |
The requirement is a properly installed jsCalendar script. |
All browsers supported by jsCalendar are supported by this |
extension. |
USAGE |
----- |
This extension enables the display of a popup calendar selection |
against selected fields. |
In order to use it, you should: |
1. Load the jsCalendar scripts in the <head>...</head> section of |
your phpMyEdit calling program, substituting the correct paths: |
<script type="text/javascript" src="js/calendar.js"></script> |
<script type="text/javascript" src="js/lang/calendar-en.js"></script> |
<script type="text/javascript" src="js/calendar-setup.js"></script> |
2. Choose your preferred jsCalendar CSS file (see jsCalendar |
documentation) and add the following in the <head>...</head> |
section of your phpMyEdit calling program, substituting the |
correct path: |
<link rel="stylesheet" type="text/css" media="screen" |
href="css/calendar-system.css"> |
NOTE: To avoid an unwanted side effect in the CSS style |
produced by phpMyEditSetup.php, add a 'width:auto' property |
into the '.calendar table' entry in your selected jsCalendar |
style sheet. |
3. Call to phpMyEdit-calPopup.class.php instead |
of phpMyEdit.class.php. |
Example: |
require_once 'extensions/phpMyEdit-calpopup.class.php'; |
new phpMyEdit_calpopup($opts); |
4. Add 'calendar' parameter to the field definitions where you |
want a calendar popup in your phpMyEdit calling program. |
Example: |
$opts['fdd']['col_name'] = array( |
'name' => 'Column', |
'select' => 'T', |
'options' => 'ACPVD', |
'required' => true, |
'calendar' => true |
); |
This is will display a button next to the field which pops up |
a calendar when clicked. If that field has a 'strftimemask' |
parameter set, it will use this for the date format. |
For more advanced usage, you can set the 'calendar' parameter |
to an array of valid jsCalendar Calendar.setup options |
(see jSCalendar document for details). Note that not all |
of these options make sense to use in phpMyEdit, and some |
of them will actively break the function. |
Example: |
$opts['fdd']['col_name'] = array( |
'name' => 'Column', |
'select' => 'T', |
'options' => 'ACPVD', |
'required' => true, |
'calendar' => array( |
'ifFormat' => '%Y/%m/%d', // defaults to the ['strftimemask'] |
'firstDay' => 1, // 0 = Sunday, 1 = Monday |
'singleClick' => true, // single or double click to close |
'weekNumbers' => true, // Show week numbers |
'showsTime' => false, // Show time as well as date |
'timeFormat' => '24', // 12 or 24 hour clock |
'label' => '...', // button label (used by phpMyEdit) |
'date' => '2003-12-19 10:00' // Initial date/time for popup |
// (see notes below) |
) |
); |
NOTES |
----- |
1. The popup will normally set the initial value to the current |
field value or to current date/time. 'date' option will always |
override this, even if there is a current date/time value |
in the field. If you want a default value only if the field |
is currently empty, use the phpMyEdit 'default' option. |
2. Only the options listed above may be set by the user, any other |
options will be ignored. |
SEARCH KEYWORD |
-------------- |
Search for "CalPopup" string in this source code, |
to find all extension related modifications. |
*/ |
require_once dirname(__FILE__).'/../phpMyEdit.class.php'; |
class phpMyEdit_calpopup extends phpMyEdit |
{ |
/* CalPopup mod start */ |
/* Array for collecting list of fields with calendar popups */ |
var $calendars; |
/* Array of valid options for passing to Calendar.setup */ |
var $valid_opts = array( |
'button','ifFormat','singleClick','firstDay', |
'weekNumbers','showsTime','timeFormat','date' |
); |
/** |
* Checks to see if the calendar parameter is set on the field |
* |
* @param k current field name |
* @param curval current value of field (set to null for default) |
* |
* If the calendar parameter is set on the field, this function displays |
* the button. It then pushes the Calendar.setup parameters into an array, |
* including the user specified ones in the calling program is they exist. |
* This array is then added to the $calendars array indexed by the field |
* name. This allows for multiple fields with calendar popups. |
*/ |
function CalPopup_helper($k, $curval) /* {{{ */ |
{ |
if (@$this->fdd[$k]['calendar']) { |
$cal_ar['ifFormat'] = '%Y-%m-%d %H:%M'; |
$cal_ar['showsTime'] = true; |
$cal_ar['singleClick'] = false; |
if (isset($curval)) { |
if (substr($curval, 0, 4) != '0000') |
$cal_ar['date'] = $curval; |
} |
if (isset($this->fdd[$k]['strftimemask'])) { |
$cal_ar['ifFormat'] = $this->fdd[$k]['strftimemask']; |
} |
if (is_array($this->fdd[$k]['calendar'])) { |
foreach($this->fdd[$k]['calendar'] as $ck => $cv) { |
$cal_ar[$ck] = $cv; |
} |
} |
$cal_ar['button'] = 'pme_calpopup_button_'.$this->fds[$k]; |
$this->calendars[$this->fds[$k]] = $cal_ar; |
$label = @$this->fdd[$k]['calendar']['label']; |
strlen($label) || $label = '...'; |
echo '<button id="',$cal_ar['button'],'">',$label,'</button>'; |
} |
} /* }}} */ |
/* CalPopup mod end */ |
function display_add_record() /* {{{ */ |
{ |
for ($tab = 0, $k = 0; $k < $this->num_fds; $k++) { |
if (isset($this->fdd[$k]['tab']) && $this->tabs_enabled() && $k > 0) { |
$tab++; |
echo '</table>',"\n"; |
echo '</div>',"\n"; |
echo '<div id="phpMyEdit_tab',$tab,'">',"\n"; |
echo '<table class="',$this->getCSSclass('main'),'" summary="',$this->tb,'">',"\n"; |
} |
if (! $this->displayed[$k]) { |
continue; |
} |
if ($this->hidden($k)) { |
echo $this->htmlHidden($this->fds[$k], $row["qf$k"]); |
continue; |
} |
$css_postfix = @$this->fdd[$k]['css']['postfix']; |
$css_class_name = $this->getCSSclass('input', null, 'next', $css_postfix); |
echo '<tr class="',$this->getCSSclass('row', null, true, $css_postfix),'">',"\n"; |
echo '<td class="',$this->getCSSclass('key', null, true, $css_postfix),'">',$this->fdd[$k]['name'],'</td>',"\n"; |
echo '<td class="',$this->getCSSclass('value', null, true, $css_postfix),'"'; |
echo $this->getColAttributes($k),">\n"; |
if ($this->col_has_values($k)) { |
$vals = $this->set_values($k); |
$selected = @$this->fdd[$k]['default']; |
$multiple = $this->col_has_multiple_select($k); |
$readonly = $this->readonly($k); |
$strip_tags = true; |
$escape = true; |
echo $this->htmlSelect($this->fds[$k], $css_class_name, $vals, $selected, |
$multiple, $readonly, $strip_tags, $escape); |
} elseif (isset ($this->fdd[$k]['textarea'])) { |
echo '<textarea class="',$css_class_name,'" name="',$this->fds[$k],'"'; |
echo ($this->readonly($k) ? ' disabled' : ''); |
if (intval($this->fdd[$k]['textarea']['rows']) > 0) { |
echo ' rows="',$this->fdd[$k]['textarea']['rows'],'"'; |
} |
if (intval($this->fdd[$k]['textarea']['cols']) > 0) { |
echo ' cols="',$this->fdd[$k]['textarea']['cols'],'"'; |
} |
if (isset($this->fdd[$k]['textarea']['wrap'])) { |
echo ' wrap="',$this->fdd[$k]['textarea']['wrap'],'"'; |
} else { |
echo ' wrap="virtual"'; |
} |
echo '>',htmlspecialchars($this->fdd[$k]['default']),'</textarea>',"\n"; |
} else { |
// Simple edit box required |
$size_ml_props = ''; |
$maxlen = intval($this->fdd[$k]['maxlen']); |
$size = isset($this->fdd[$k]['size']) ? $this->fdd[$k]['size'] : min($maxlen, 60); |
$size && $size_ml_props .= ' size="'.$size.'"'; |
$maxlen && $size_ml_props .= ' maxlength="'.$maxlen.'"'; |
/* CalPopup mod start */ |
if (@$this->fdd[$k]['calendar']) { |
$size_ml_props .= ' id="pme_calpopup_input_'.$this->fds[$k].'"'; |
} |
/* CalPopup mod end */ |
echo '<input class="',$css_class_name,'" type="text" '; |
echo ($this->readonly($k) ? 'disabled ' : ''),' name="',$this->fds[$k],'"'; |
echo $size_ml_props,' value="'; |
echo htmlspecialchars($this->fdd[$k]['default']),'">'; |
/* CalPopup mod start */ |
/* Call CalPopup helper function */ |
$this->CalPopup_helper($k, null); |
/* CalPopup mod end */ |
} |
echo '</td>',"\n"; |
if ($this->guidance) { |
$css_class_name = $this->getCSSclass('help', null, true, $css_postfix); |
$cell_value = $this->fdd[$k]['help'] ? $this->fdd[$k]['help'] : ' '; |
echo '<td class="',$css_class_name,'">',$cell_value,'</td>',"\n"; |
} |
echo '</tr>',"\n"; |
} |
} /* }}} */ |
function display_change_field($row, $k) /* {{{ */ |
{ |
$css_postfix = @$this->fdd[$k]['css']['postfix']; |
$css_class_name = $this->getCSSclass('input', null, true, $css_postfix); |
echo '<td class="',$this->getCSSclass('value', null, true, $css_postfix),'"'; |
echo $this->getColAttributes($k),">\n"; |
if ($this->col_has_values($k)) { |
$vals = $this->set_values($k); |
$multiple = $this->col_has_multiple_select($k); |
$readonly = $this->readonly($k); |
$strip_tags = true; |
$escape = true; |
echo $this->htmlSelect($this->fds[$k], $css_class_name, $vals, $row["qf$k"], |
$multiple, $readonly, $strip_tags, $escape); |
} elseif (isset($this->fdd[$k]['textarea'])) { |
echo '<textarea class="',$css_class_name,'" name="',$this->fds[$k],'"'; |
echo ($this->readonly($k) ? ' disabled' : ''); |
if (intval($this->fdd[$k]['textarea']['rows']) > 0) { |
echo ' rows="',$this->fdd[$k]['textarea']['rows'],'"'; |
} |
if (intval($this->fdd[$k]['textarea']['cols']) > 0) { |
echo ' cols="',$this->fdd[$k]['textarea']['cols'],'"'; |
} |
if (isset($this->fdd[$k]['textarea']['wrap'])) { |
echo ' wrap="',$this->fdd[$k]['textarea']['wrap'],'"'; |
} else { |
echo ' wrap="virtual"'; |
} |
echo '>',htmlspecialchars($row["qf$k"]),'</textarea>',"\n"; |
} else { |
$size_ml_props = ''; |
$maxlen = intval($this->fdd[$k]['maxlen']); |
$size = isset($this->fdd[$k]['size']) ? $this->fdd[$k]['size'] : min($maxlen, 60); |
$size && $size_ml_props .= ' size="'.$size.'"'; |
$maxlen && $size_ml_props .= ' maxlength="'.$maxlen.'"'; |
/* CalPopup mod start */ |
if (@$this->fdd[$k]['calendar']) { |
$size_ml_props .= ' id="pme_calpopup_input_'.$this->fds[$k].'"'; |
} |
/* CalPopup mod end */ |
echo '<input class="',$css_class_name,'" type="text" '; |
echo ($this->readonly($k) ? 'disabled ' : ''),'name="',$this->fds[$k],'" value="'; |
echo htmlspecialchars($row["qf$k"]),'" ',$size_ml_props,'>',"\n"; |
/* CalPopup mod start */ |
/* Call CalPopup helper function */ |
$this->CalPopup_helper($k, htmlspecialchars($row["qf$k"])); |
/* CalPopup mod end */ |
} |
echo '</td>',"\n"; |
} /* }}} */ |
function form_end() /* {{{ */ |
{ |
if ($this->display['form']) { |
echo '</form>',"\n"; |
/* CalPopup mod start */ |
/* Add script calls to the end of the form for all fields |
with calendar popups. */ |
if (isset($this->calendars)) { |
echo '<script type="text/javascript"><!--',"\n"; |
foreach($this->calendars as $ck => $cv) { |
echo 'Calendar.setup({',"\n"; |
foreach ($cv as $ck1 => $cv1) { |
if (in_array($ck1, $this->valid_opts)) { |
echo "\t",str_pad($ck1, 15),' : "',$cv1,'",',"\n"; |
} |
} |
echo "\t",str_pad('inputField', 15),' : "pme_calpopup_input_',$ck,'"',"\n"; |
echo '});',"\n"; |
}; |
echo '// --></script>',"\n"; |
}; |
/* CalPopup mod end */ |
}; |
} /* }}} */ |
} |
?> |
/trunk/jrest/util/lang/PME.lang.RO.inc |
---|
New file |
0,0 → 1,64 |
<?php |
/* |
* phpMyEdit language file |
* |
* language: romanian |
* encoding: iso-8859-1 |
* date: 2004-12-23 |
* author: Sebastian Proksch <sproksch@yahoo.com> |
*/ |
/* $Platon: phpMyEdit/lang/PME.lang.RO.inc,v 1.2 2004-12-27 20:14:29 nepto Exp $ */ |
return Array( |
'Add' =>'Adauga', |
'Copy' =>'Copiaza', |
'Change' =>'Modifica', |
'Delete' =>'Sterge', |
'View' =>'Vizualizeaza', |
'Prev' =>'Precedentul', |
'Next' =>'Urmatorul', |
'First' =>'First', // untranslated |
'Last' =>'Last', // untranslated |
'Go to' =>'Go to', // untranslated |
'Page' =>'Pagina', |
'Records' =>'Inregistrari', |
'Save' =>'Salveaza', |
'More' =>'Mai mult', |
'Apply' =>'Aplica', |
'Cancel' =>'Anuleaza', |
'Search' =>'Cauta', |
'Hide' =>'Ascunde', |
'Clear' =>'Anuleaza tot', |
'Query' =>'Interogare', |
'Current Query' =>'Interogarea curenta', |
'Sorted By' =>'Sortat dupa', |
'ascending' =>'crescator', |
'descending' =>'descrescator', |
'hidden' =>'ascuns', |
'of' =>'din', |
'record added' =>'inregistrare adaugata', |
'record changed'=>'inregistrare modificata', |
'record deleted'=>'inregistrare stearsa', |
'Please enter' =>'Introduceti va rog', |
'months' => Array( |
'01'=>'Ianuarie', |
'02'=>'Februarie', |
'03'=>'Martie', |
'04'=>'Aprilie', |
'05'=>'Mai', |
'06'=>'Iunie', |
'07'=>'Iulie', |
'08'=>'August', |
'09'=>'Septembrie', |
'10'=>'Octombrie', |
'11'=>'Noiembrie', |
'12'=>'Decembrie'), |
// phpMyEdit-report // untranslated |
'Make report' => 'Make report', |
'Select fields' => 'Select fields', |
'Records per screen' => 'Records per screen', |
); |
?> |
/trunk/jrest/util/lang/PME.lang.ZH.inc |
---|
New file |
0,0 → 1,66 |
<?php |
/* |
* phpMyEdit language file |
* |
* language: chinese (traditional) |
* encoding: big5 |
* date: 2003-06-26, 2004-10-17 |
* authors: |
* Pao-Hsi Huang <doggy@miniasp.com> |
* Manix Sio <manixsio@gmail.com> |
*/ |
/* $Platon: phpMyEdit/lang/PME.lang.ZH.inc,v 1.5 2004-12-27 20:14:29 nepto Exp $ */ |
return Array( |
'Add' =>'·s¼W', |
'Copy' =>'½Æ»s', |
'Change' =>'Åܧó', |
'Delete' =>'§R°£', |
'View' =>'À˵ø', |
'Prev' =>'¤W¤@¶', |
'Next' =>'¤U¤@¶', |
'First' =>'²Ä¤@¶', |
'Last' =>'³Ì¥½¤@¶', |
'Go to' =>'«e©¹', |
'Page' =>'¶¼Æ', |
'Records' =>'¸ê®Æµ§¼Æ', |
'Save' =>'Àx¦s', |
'More' =>'Àx¦s«áÄ~Äò·s¼W', |
'Apply' =>'®M¥Î', |
'Cancel' =>'¨ú®ø', |
'Search' =>'·j´M', |
'Hide' =>'ÁôÂÃ', |
'Clear' =>'²M°£', |
'Query' =>'¬d¸ß', |
'Current Query' =>'¥Ø«e¬d¸ß±ø¥ó', |
'Sorted By' =>'±Æ§Ç¨Ì¾Ú', |
'ascending' =>'¤É¾±Æ§Ç', |
'descending' =>'°¾±Æ§Ç', |
'hidden' =>'ÁôÂÃ', |
'of' =>'Á`¦@¶¼Æ', |
'record added' =>'µ§¸ê®Æ³Q·s¼W', |
'record changed' =>'µ§¸ê®Æ³Q§ó·s', |
'record deleted' =>'µ§¸ê®Æ³Q§R°£', |
'Please enter' =>'½Ð¿é¤J', |
'months' => Array( |
'01'=>'¤@¤ë', |
'02'=>'¤G¤ë', |
'03'=>'¤T¤ë', |
'04'=>'¥|¤ë', |
'05'=>'¤¤ë', |
'06'=>'¤»¤ë', |
'07'=>'¤C¤ë', |
'08'=>'¤K¤ë', |
'09'=>'¤E¤ë', |
'10'=>'¤Q¤ë', |
'11'=>'¤Q¤@¤ë', |
'12'=>'¤Q¤G¤ë'), |
// phpMyEdit-report |
'Make report' => '²£¥Í³øªí', |
'Select fields' => '¿ï¨úÄæ¦ì', |
'Records per screen' => '¨C¶µ§¼Æ', |
); |
?> |
/trunk/jrest/util/lang/PME.lang.PT.inc |
---|
New file |
0,0 → 1,67 |
<?php |
/* |
* phpMyEdit language file |
* |
* language: portuguese (standard) |
* encoding: iso-8859-1 |
* date: 2002-02 |
* author: unknown |
* |
* last_edit: 2006-05-23 by Sérgio Sanches <ssanches@dcc.online.pt> |
* last_edit_purpose: full translation and correction |
*/ |
/* $Platon: phpMyEdit/lang/PME.lang.PT.inc,v 1.6 2006-05-29 08:18:04 nepto Exp $ */ |
return Array( |
'Add' =>'Adicionar', |
'Copy' =>'Copiar', |
'Change' =>'Mudar', |
'Delete' =>'Apagar', |
'View' =>'Ver', |
'Prev' =>'Anterior', |
'Next' =>'Seguinte', |
'First' =>'Primeiro', |
'Last' =>'Último', |
'Go to' =>'Ir para', |
'Page' =>'Página', |
'Records' =>'Registos', |
'Save' =>'Guardar', |
'More' =>'Mais', |
'Apply' =>'Aplicar', |
'Cancel' =>'Cancelar', |
'Search' =>'Procurar', |
'Hide' =>'Esconder', |
'Clear' =>'Limpar', |
'Query' =>'Pesquisa', |
'Current Query' =>'Pesquisa Actual', |
'Sorted By' =>'Ordenado Por', |
'ascending' =>'ascendente', |
'descending' =>'descendente', |
'hidden' =>'escondido', |
'of' =>'de', |
'record added' =>'registo adicionado', |
'record changed' =>'registo alterado', |
'record deleted' =>'registo apagado', |
'Please enter' =>'Por favor introduza ', |
'months' => Array( |
'01'=>'Janeiro', |
'02'=>'Fevereiro', |
'03'=>'Março', |
'04'=>'Abril', |
'05'=>'Maio', |
'06'=>'Junho', |
'07'=>'Julho', |
'08'=>'Agosto', |
'09'=>'Setembro', |
'10'=>'Outubro', |
'11'=>'Novembro', |
'12'=>'Dezembro'), |
// phpMyEdit-report |
'Make report' => 'Criar relatório', |
'Select fields' => 'Escolher campos', |
'Records per screen' => 'Registos por ecran', |
); |
?> |
/trunk/jrest/util/lang/PME.lang.CA.inc |
---|
New file |
0,0 → 1,64 |
<?php |
/* |
* phpMyEdit language file |
* |
* language: català |
* encoding: iso-8859-1 |
* date: 2006-04-06 |
* author: Josep Maria Faura <j.m.faura@telefonica.net> |
*/ |
/* $Platon: phpMyEdit/lang/PME.lang.CA.inc,v 1.2 2006-04-11 10:30:46 nepto Exp $ */ |
return Array( |
'Add' =>'Afegir', |
'Copy' =>'Copiar', |
'Change' =>'Modificar', |
'Delete' =>'Suprimir', |
'View' =>'Visualitzar', |
'Prev' =>'Anterior', |
'Next' =>'Següent', |
'First' =>'Primer', |
'Last' =>'Últim', |
'Go to' =>'Ves a', |
'Page' =>'Pàgina', |
'Records' =>'Registres', |
'Save' =>'Salvar', |
'More' =>'Més', |
'Apply' =>'Aplicar', |
'Cancel' =>'Cancel·lar', |
'Search' =>'Cercar', |
'Hide' =>'Amagar', |
'Clear' =>'Netejar', |
'Query' =>'Consultar', |
'Current Query' =>'Consulta actual', |
'Sorted By' =>'Ordenat per', |
'ascending' =>'ascendent', |
'descending' =>'descendent', |
'hidden' =>'amagat', |
'of' =>'de', |
'record added' =>'Registre afegit', |
'record changed'=>'Registre modificat', |
'record deleted'=>'Registre esborrat', |
'Please enter' =>'Sisplau introdueixi ', |
'months' => Array( |
'01'=>'Gener', |
'02'=>'Febrer', |
'03'=>'Març', |
'04'=>'Abril', |
'05'=>'Maig', |
'06'=>'Juny', |
'07'=>'Juliol', |
'08'=>'Agost', |
'09'=>'Septembre', |
'10'=>'Octubre', |
'11'=>'Novembre', |
'12'=>'Desembre'), |
// phpMyEdit-report |
'Make report' => 'Construir informe', |
'Select fields' => 'Seleccionar camps', |
'Records per screen' => 'Registres per pantalla', |
); |
?> |
/trunk/jrest/util/lang/PME.lang.PT-BR.inc |
---|
New file |
0,0 → 1,64 |
<?php |
/* |
* phpMyEdit language file |
* |
* language: portuguese (brazilian) |
* encoding: iso-8859-1 |
* date: 2002-12-23, 2003-01-14, 2003-05-17, 2004-01-21 |
* author: Roberto Cohen <roberto.cohen@fireman.com.br> |
*/ |
/* $Platon: phpMyEdit/lang/PME.lang.PT-BR.inc,v 1.8 2004-12-27 20:14:29 nepto Exp $ */ |
return Array( |
'Add' =>'Adiciona', |
'Copy' =>'Copia', |
'Change' =>'Edita', |
'Delete' =>'Remove', |
'View' =>'Visualiza', |
'Prev' =>'Anterior', |
'Next' =>'Próximo', |
'First' =>'Primeiro', |
'Last' =>'Último', |
'Go to' =>'Vai para', |
'Page' =>'Página', |
'Records' =>'Registros', |
'Save' =>'Salva', |
'More' =>'Mais', |
'Apply' =>'Aplica', |
'Cancel' =>'Cancela', |
'Search' =>'Pesquisa', |
'Hide' =>'Esconde', |
'Clear' =>'Limpa', |
'Query' =>'Resultado', |
'Current Query' =>'Resultado atual', |
'Sorted By' =>'Ordernado por', |
'ascending' =>'crescente', |
'descending' =>'descendente', |
'hidden' =>'escondido', |
'of' =>'de', |
'record added' =>'registro adicionado', |
'record changed'=>'registro editado', |
'record deleted'=>'registro removido', |
'Please enter' =>'Por favor, entre', |
'months' => Array( |
'01'=>'Janeiro', |
'02'=>'Fevereiro', |
'03'=>'Março', |
'04'=>'Abril', |
'05'=>'Maio', |
'06'=>'Junho', |
'07'=>'Julho', |
'08'=>'Agosto', |
'09'=>'Setembro', |
'10'=>'Outubro', |
'11'=>'Novembro', |
'12'=>'Dezembro'), |
// phpMyEdit-report |
'Gerar relatório' => 'Make report', |
'Selecionar campos' => 'Select fields', |
'Registros por tela' => 'Records per screen', |
); |
?> |
/trunk/jrest/util/lang/PME.lang.TR.inc |
---|
New file |
0,0 → 1,66 |
<?php |
/* |
* phpMyEdit language file |
* |
* language: turkish |
* encoding: iso-8859-9 |
* date: 2003-10-24, 2005-11-13 |
* authors: |
* Nuri Akman <nuri.akman@hazine.gov.tr> |
* Kadan Kongar <kagan.kongar@tsrsb.org.tr> |
*/ |
/* $Platon: phpMyEdit/lang/PME.lang.TR.inc,v 1.4 2005-11-14 03:15:04 nepto Exp $ */ |
return Array( |
'Add' =>'Ekle', |
'Copy' =>'Kopyala', |
'Change' =>'Deðiþtir', |
'Delete' =>'Sil', |
'View' =>'Bak', |
'Prev' =>'Önceki', |
'Next' =>'Sonraki', |
'First' =>'Ýlk', |
'Last' =>'Son', |
'Go to' =>'Git', |
'Page' =>'Sayfa', |
'Records' =>'Kayýt', |
'Save' =>'Kaydet', |
'More' =>'Devamý', |
'Apply' =>'Uygula', |
'Cancel' =>'Ýptal', |
'Search' =>'Ara', |
'Hide' =>'Gizle', |
'Clear' =>'Temizle', |
'Query' =>'Sorgu', |
'Current Query' =>'Aktif Sorgu', |
'Sorted By' =>'Sýralama', |
'ascending' =>'artan', |
'descending' =>'azalan', |
'hidden' =>'gizli', |
'of' =>' / ', |
'record added' =>'kayýt eklendi', |
'record changed' =>'kayýt deðiþtirildi', |
'record deleted' =>'kayýt silindi', |
'Please enter' =>'Lütfen giriniz :', |
'months' => Array( |
'01'=>'Ocak', |
'02'=>'Þubat', |
'03'=>'Mart', |
'04'=>'Nisan', |
'05'=>'Mayýs', |
'06'=>'Haziran', |
'07'=>'Temmuz', |
'08'=>'Auðustos', |
'09'=>'Eylül', |
'10'=>'Ekim', |
'11'=>'Kasým', |
'12'=>'Aralýk'), |
// phpMyEdit-report |
'Make report' => 'Rapor hazýrla', |
'Select fields' => 'Alanlarý seçiniz', |
'Records per screen' => 'Sayfa baþýna kayýt', |
); |
?> |
/trunk/jrest/util/lang/PME.lang.RU.inc |
---|
New file |
0,0 → 1,64 |
<?php |
/* |
* phpMyEdit language file |
* |
* language: russian |
* encoding: windows-1251 |
* date: 2002-11-23 |
* author: Lev Zabudkin <zabudkin@mail.ru> |
*/ |
/* $Platon: phpMyEdit/lang/PME.lang.RU.inc,v 1.11 2004-12-27 20:14:29 nepto Exp $ */ |
return Array( |
'Add' =>'Äîáàâèòü', |
'Copy' =>'Êîïèðîâàòü', |
'Change' =>'Èçìåíèòü', |
'Delete' =>'Óäàëèòü', |
'View' =>'Ïðîñìîòð', |
'Prev' =>'<<', |
'Next' =>'>>', |
'First' =>'I<', |
'Last' =>'>I', |
'Go to' =>'Ïåðåéòè', |
'Page' =>'Ñòð.', |
'Records' =>'Çàïèñåé', |
'Save' =>'Ñîõðàíèòü', |
'More' =>'Áîëüøå', |
'Apply' =>'Ïðèìåíèòü', |
'Cancel' =>'Îòìåíà', |
'Search' =>'Ïîèñê', |
'Hide' =>'Ñêðûòü', |
'Clear' =>'Î÷èñòèòü', |
'Query' =>'Çàïðîñ', |
'Current Query' =>'Òåêóùèé çàïðîñ', |
'Sorted By' =>'Îòñîðòèðîâàíî ïî', |
'ascending' =>'- âîçðàñòàíèþ', |
'descending' =>'- óáûâàíèþ', |
'hidden' =>'ñêðûòî', |
'of' =>'èç', |
'record added' =>'çàïèñü äîáàâëåíà', |
'record changed'=>'çàïèñü îáíîâëåíà', |
'record deleted'=>'çàïèñü óäàëåíà', |
'Please enter' =>'Ïîæàëóéñòà ââåäèòå', |
'months' => Array( |
'01'=>'ßíâàðü', |
'02'=>'Ôåâðàëü', |
'03'=>'Ìàðò', |
'04'=>'Àïðåëü', |
'05'=>'Ìàé', |
'06'=>'Èþíü', |
'07'=>'Èþëü', |
'08'=>'Àâãóñò', |
'09'=>'Ñåíòÿáðü', |
'10'=>'Îêòÿáðü', |
'11'=>'Íîÿáðü', |
'12'=>'Äåêàáðü'), |
// phpMyEdit-report |
'Make report' => 'Ñîçäàòü îò÷åò', |
'Select fields' => 'Âûáðàòü ïîëÿ', |
'Records per screen' => 'Çàïèñåé íà ýêðàíå', |
); |
?> |
/trunk/jrest/util/lang/PME.lang.EN-US.inc |
---|
New file |
0,0 → 1,64 |
<?php |
/* |
* phpMyEdit language file |
* |
* language: english (United States) |
* encoding: iso-8859-1 |
* date: 2002-02, 2003-05-01 |
* author: Jim Kraai <jkraai@users.sourceforge.net> |
*/ |
/* $Platon: phpMyEdit/lang/PME.lang.EN-US.inc,v 1.10 2004-12-27 20:14:29 nepto Exp $ */ |
return Array( |
'Add' =>'Add', |
'Copy' =>'Copy', |
'Change' =>'Change', |
'Delete' =>'Delete', |
'View' =>'View', |
'Prev' =>'Prev', |
'Next' =>'Next', |
'First' =>'First', |
'Last' =>'Last', |
'Go to' =>'Go to', |
'Page' =>'Page', |
'Records' =>'Records', |
'Save' =>'Save', |
'More' =>'More', |
'Apply' =>'Apply', |
'Cancel' =>'Cancel', |
'Search' =>'Search', |
'Hide' =>'Hide', |
'Clear' =>'Clear', |
'Query' =>'Query', |
'Current Query' =>'Current Query', |
'Sorted By' =>'Sorted By', |
'ascending' =>'ascending', |
'descending' =>'descending', |
'hidden' =>'hidden', |
'of' =>'of', |
'record added' =>'record added', |
'record changed' =>'record changed', |
'record deleted' =>'record deleted', |
'Please enter' =>'Please enter', |
'months' => Array( |
'01'=>'January', |
'02'=>'February', |
'03'=>'March', |
'04'=>'April', |
'05'=>'May', |
'06'=>'June', |
'07'=>'July', |
'08'=>'August', |
'09'=>'September', |
'10'=>'October', |
'11'=>'November', |
'12'=>'December'), |
// phpMyEdit-report |
'Make report' => 'Make report', |
'Select fields' => 'Select fields', |
'Records per screen' => 'Records per screen', |
); |
?> |
/trunk/jrest/util/lang/PME.lang.ZH-SG.inc |
---|
New file |
0,0 → 1,64 |
<?php |
/* |
* phpMyEdit language file |
* |
* language: chinese (Singapore) |
* encoding: utf-8 |
* date: 2003-07-03 |
* author: Juraj Benadik <gastan at gastan.sk> |
*/ |
/* $Platon: phpMyEdit/lang/PME.lang.ZH-SG.inc,v 1.4 2004-12-27 20:14:29 nepto Exp $ */ |
return Array( |
'Add' =>'添加', |
'Copy' =>'复制', |
'Change' =>'更改', |
'Delete' =>'删除', |
'View' =>'查看', |
'Prev' =>'上页', |
'Next' =>'下页', |
'First' =>'First', // untranslated |
'Last' =>'Last', // untranslated |
'Go to' =>'Go to', // untranslated |
'Page' =>'页', |
'Records' =>'记录', |
'Save' =>'保存', |
'More' =>'更多', |
'Apply' =>'应用', |
'Cancel' =>'取消', |
'Search' =>'搜寻', |
'Hide' =>'隐藏', |
'Clear' =>'清除', |
'Query' =>'查询', |
'Current Query' =>'当前 查询', |
'Sorted By' =>'排序方式', |
'ascending' =>'上升', |
'descending' =>'递减', |
'hidden' =>'隐藏的', |
'of' =>'总', |
'record added' =>'记录添加', |
'record changed' =>'记录更改', |
'record deleted' =>'记录删除', |
'Please enter' =>'请进入', |
'months' => Array( |
'01'=>'一月', |
'02'=>'二月', |
'03'=>'三月', |
'04'=>'四月', |
'05'=>'五月', |
'06'=>'六月', |
'07'=>'七月', |
'08'=>'八月', |
'09'=>'九月', |
'10'=>'十月', |
'11'=>'十一月', |
'12'=>'十二月'), |
// phpMyEdit-report |
'Make report' => 'Make report', |
'Select fields' => 'Select fields', |
'Records per screen' => 'Records per screen', |
); |
?> |
/trunk/jrest/util/lang/PME.lang.DE.inc |
---|
New file |
0,0 → 1,67 |
<?php |
/* |
* phpMyEdit language file |
* |
* language: german (standard) |
* encoding: iso-8859-1 |
* date: 2002-07 |
* authors: |
* Christof Brandstetter <fellz@users.sourceforge.net> |
* Gerd Xhonneux, http://xsite.xhonneux.com |
* info: http://makeashorterlink.com/?O116223C2 |
*/ |
/* $Platon: phpMyEdit/lang/PME.lang.DE.inc,v 1.14 2004-12-27 20:14:29 nepto Exp $ */ |
return Array( |
'Add' =>'Hinzufügen', |
'Copy' =>'Kopieren', |
'Change' =>'Ändern', |
'Delete' =>'Löschen', |
'View' =>'Anzeigen', |
'Prev' =>'Zurück', |
'Next' =>'Weiter', |
'First' =>'First', // untranslated |
'Last' =>'Last', // untranslated |
'Go to' =>'Go to', // untranslated |
'Page' =>'Seite', |
'Records' =>'Datensätze', |
'Save' =>'Speichern', |
'More' =>'Speichern, weiteren Datensatz hinzufügen', |
'Apply' =>'Anwenden', |
'Cancel' =>'Abbrechen', |
'Search' =>'Suche', |
'Hide' =>'Verstecken', |
'Clear' =>'Löschen', |
'Query' =>'Abfrage', |
'Current Query' =>'Aktuelle Abfrage', |
'Sorted By' =>'Sortiert nach', |
'ascending' =>'aufsteigend', |
'descending' =>'absteigend', |
'hidden' =>'versteckt', |
'of' =>'von', |
'record added' =>'Datensatz hinzugefügt', |
'record changed'=>'Datensatz geändert', |
'record deleted'=>'Datensatz gelöscht', |
'Please enter' =>'Bitte füllen sie dieses Feld aus:', |
'months' => Array( |
'01'=>'Januar', |
'02'=>'Februar', |
'03'=>'März', |
'04'=>'April', |
'05'=>'Mai', |
'06'=>'Juni', |
'07'=>'Juli', |
'08'=>'August', |
'09'=>'September', |
'10'=>'Oktober', |
'11'=>'November', |
'12'=>'Dezember'), |
// phpMyEdit-report |
'Make report' => 'Make report', |
'Select fields' => 'Select fields', |
'Records per screen' => 'Records per screen', |
); |
?> |
/trunk/jrest/util/lang/PME.lang.ES-MX.inc |
---|
New file |
0,0 → 1,64 |
<?php |
/* |
* phpMyEdit language file |
* |
* language: spanish (mexican) |
* encoding: iso-8859-1 |
* date: 2003-04-30 |
* author: unknown |
*/ |
/* $Platon: phpMyEdit/lang/PME.lang.ES-MX.inc,v 1.3 2004-12-27 20:14:29 nepto Exp $ */ |
return Array( |
'Add' =>'Agregar', |
'Copy' =>'Copiar', |
'Change' =>'Cambiar', |
'Delete' =>'Suprimir', |
'View' =>'Ver', |
'Prev' =>'Anterior', |
'Next' =>'Siguiente', |
'First' =>'First', // untranslated |
'Last' =>'Last', // untranslated |
'Go to' =>'Go to', // untranslated |
'Page' =>'Página', |
'Records' =>'Registros', |
'Save' =>'Guardar', |
'More' =>'Más', |
'Apply' =>'Aplicar', |
'Cancel' =>'Cancelar', |
'Search' =>'Buscar', |
'Hide' =>'Ocultar', |
'Clear' =>'Limpiar', |
'Query' =>'Consulta SQL', |
'Current Query' =>'Consulta actual', |
'Sorted By' =>'Ordenado por', |
'ascending' =>'ascendente', |
'descending' =>'descendente', |
'hidden' =>'oculto', |
'of' =>'de', |
'record added' =>'registro agregado', |
'record changed'=>'registro cambiado', |
'record deleted'=>'registro borrado', |
'Please enter' =>'Por favor introduzca ', |
'months' => Array( |
'01'=>'Enero', |
'02'=>'Febrero', |
'03'=>'Marzoa', |
'04'=>'Abril', |
'05'=>'Mayo', |
'06'=>'Junio', |
'07'=>'Julio', |
'08'=>'Agosto', |
'09'=>'Septiembre', |
'10'=>'Octubre', |
'11'=>'Noviembre', |
'12'=>'Diciembre'), |
// phpMyEdit-report |
'Make report' => 'Make report', |
'Select fields' => 'Select fields', |
'Records per screen' => 'Records per screen', |
); |
?> |
/trunk/jrest/util/lang/PME.lang.DK.inc |
---|
New file |
0,0 → 1,64 |
<?php |
/* |
* phpMyEdit language file |
* |
* language: danish |
* encoding: iso-8859-1 |
* date: 2003-03-19 |
* author: Henrik Nielsen <kontakt@innovapage.dk> |
*/ |
/* $Platon: phpMyEdit/lang/PME.lang.DK.inc,v 1.5 2004-12-27 20:14:29 nepto Exp $ */ |
return Array( |
'Add' =>'Tilføj', |
'Copy' =>'Kopier', |
'Change' =>'Ret', |
'Delete' =>'Slet', |
'View' =>'Se', |
'Prev' =>'Tilbage', |
'Next' =>'Næste', |
'First' =>'First', // untranslated |
'Last' =>'Last', // untranslated |
'Go to' =>'Go to', // untranslated |
'Page' =>'Side', |
'Records' =>'Rækker', |
'Save' =>'Gem', |
'More' =>'Mere', |
'Apply' =>'Tilføj', |
'Cancel' =>'Fortryd', |
'Search' =>'Søg', |
'Hide' =>'Skjul', |
'Clear' =>'Tøm', |
'Query' =>'Søg', |
'Current Query' =>'Current Query', // untranslated |
'Sorted By' =>'Sorted By', // untranslated |
'ascending' =>'ascending', // untranslated |
'descending' =>'descending', // untranslated |
'hidden' =>'hidden', // untranslated |
'of' =>'af', |
'record added' =>'række tilføjet', |
'record changed' =>'række ændret', |
'record deleted' =>'række slettet', |
'Please enter' =>'Indtast venligst', |
'months' => Array( |
'01'=>'Januar', |
'02'=>'Februar', |
'03'=>'Marts', |
'04'=>'April', |
'05'=>'Maj', |
'06'=>'Juni', |
'07'=>'Juli', |
'08'=>'August', |
'09'=>'September', |
'10'=>'Oktober', |
'11'=>'November', |
'12'=>'December'), |
// phpMyEdit-report |
'Make report' => 'Make report', |
'Select fields' => 'Select fields', |
'Records per screen' => 'Records per screen', |
); |
?> |
/trunk/jrest/util/lang/PME.lang.EL.inc |
---|
New file |
0,0 → 1,64 |
<?php |
/* |
* phpMyEdit language file |
* |
* language: greek |
* encoding: iso-8859-7 |
* date: 2005-08-03 |
* author: Alexandros Vellis <avel@users.sourceforge.net> |
*/ |
/* $Id$ */ |
return Array( |
'Add' =>'Ðñüóèåóç', |
'Copy' =>'ÁíôéãñáöÞ', |
'Change' =>'ÁëëáãÞ', |
'Delete' =>'ÄéáãñáöÞ', |
'View' =>'ÅìöÜíéóç', |
'Prev' =>'Ðñïçãïýìåíï', |
'Next' =>'Åðüìåíï', |
'First' =>'Ðñþôï', |
'Last' =>'Ôåëåõôáßï', |
'Go to' =>'ÐÞãáéíå óå', |
'Page' =>'Óåëßäá', |
'Records' =>'ÅããñáöÝò', |
'Save' =>'ÁðïèÞêåõóç', |
'More' =>'Ðåñéóóüôåñá', |
'Apply' =>'ÕðïâïëÞ', |
'Cancel' =>'Áêýñùóç', |
'Search' =>'ÁíáæÞôçóç', |
'Hide' =>'Êñýøå', |
'Clear' =>'ÊáèÜñéóå', |
'Query' =>'Åðåñþôçìá', |
'Current Query' =>'ÔñÝ÷ïí Åðåñþôçìá', |
'Sorted By' =>'Ôáîéíüìçóç Ìå', |
'ascending' =>'áýîïõóá', |
'descending' =>'öèßíïõóá', |
'hidden' =>'êñõììÝíï', |
'of' =>'áðü', |
'record added' =>'ç åããñáöÞ ðñïóôÝèçêå', |
'record changed' =>'ç åããñáöÞ Üëëáîå', |
'record deleted' =>'ç åããñáöÞ äéáãñÜöçêå', |
'Please enter' =>'Ðáñáêáëþ åéóÜãåôå', |
'months' => Array( |
'01'=>'ÉáíïõÜñéïò', |
'02'=>'ÖåâñïõÜñéïò', |
'03'=>'ÌÜñôéïò', |
'04'=>'Áðñßëéïò', |
'05'=>'ÌÜéïò', |
'06'=>'Éïýíéïò', |
'07'=>'Éïýëéïò', |
'08'=>'Áýãïõóôïò', |
'09'=>'ÓåðôÝìâñéïò', |
'10'=>'Ïêôþâñéïò', |
'11'=>'ÍïÝìâñéïò', |
'12'=>'ÄåêÝìâñéïò'), |
// phpMyEdit-report |
'Make report' => 'Äçìéïõñãßá áíáöïñÜò', |
'Select fields' => 'ÅðéëïãÞ ðåäßùí', |
'Records per screen' => 'ÅããñáöÝò áíÜ ïèüíç', |
); |
?> |
/trunk/jrest/util/lang/PME.lang.EN.inc |
---|
New file |
0,0 → 1,64 |
<?php |
/* |
* phpMyEdit language file |
* |
* language: english |
* encoding: iso-8859-1 |
* date: 2000, 2001, 2003-05-01 |
* author: John McCreesh <jpmcc@users.sourceforge.net> |
*/ |
/* $Platon: phpMyEdit/lang/PME.lang.EN.inc,v 1.11 2004-12-27 20:14:29 nepto Exp $ */ |
return Array( |
'Add' =>'Add', |
'Copy' =>'Copy', |
'Change' =>'Change', |
'Delete' =>'Delete', |
'View' =>'View', |
'Prev' =>'Prev', |
'Next' =>'Next', |
'First' =>'First', |
'Last' =>'Last', |
'Go to' =>'Go to', |
'Page' =>'Page', |
'Records' =>'Records', |
'Save' =>'Save', |
'More' =>'More', |
'Apply' =>'Apply', |
'Cancel' =>'Cancel', |
'Search' =>'Search', |
'Hide' =>'Hide', |
'Clear' =>'Clear', |
'Query' =>'Query', |
'Current Query' =>'Current Query', |
'Sorted By' =>'Sorted By', |
'ascending' =>'ascending', |
'descending' =>'descending', |
'hidden' =>'hidden', |
'of' =>'of', |
'record added' =>'record added', |
'record changed' =>'record changed', |
'record deleted' =>'record deleted', |
'Please enter' =>'Please enter', |
'months' => Array( |
'01'=>'January', |
'02'=>'February', |
'03'=>'March', |
'04'=>'April', |
'05'=>'May', |
'06'=>'June', |
'07'=>'July', |
'08'=>'August', |
'09'=>'September', |
'10'=>'October', |
'11'=>'November', |
'12'=>'December'), |
// phpMyEdit-report |
'Make report' => 'Make report', |
'Select fields' => 'Select fields', |
'Records per screen' => 'Records per screen', |
); |
?> |
/trunk/jrest/util/lang/PME.lang.ES.inc |
---|
New file |
0,0 → 1,66 |
<?php |
/* |
* phpMyEdit language file |
* |
* language: spanish |
* encoding: iso-8859-1 |
* date: 2003-02, 2003-04-22, 2004-04-04 |
* authors: |
* Jorge Nadal <jornamon@ya.com> |
* Eduardo Diaz <ediaz@pk25.com> |
*/ |
/* $Platon: phpMyEdit/lang/PME.lang.ES.inc,v 1.6 2004-12-27 20:14:29 nepto Exp $ */ |
return Array( |
'Add' =>'Agregar', |
'Copy' =>'Copiar', |
'Change' =>'Cambiar', |
'Delete' =>'Suprimir', |
'View' =>'Visualizar', |
'Prev' =>'Anterior', |
'Next' =>'Siguiente', |
'First' =>'Primero', |
'Last' =>'Último', |
'Go to' =>'Ir a', |
'Page' =>'Página', |
'Records' =>'Registros', |
'Save' =>'Grabar', |
'More' =>'Más', |
'Apply' =>'Aplicar', |
'Cancel' =>'Cancelar', |
'Search' =>'Buscar', |
'Hide' =>'Ocultar', |
'Clear' =>'Limpiar', |
'Query' =>'Consultar', |
'Current Query' =>'Consulta actual', |
'Sorted By' =>'Ordenado por', |
'ascending' =>'ascendente', |
'descending' =>'descendente', |
'hidden' =>'oculto', |
'of' =>'de', |
'record added' =>'Registro añadido', |
'record changed'=>'Registro cambiado', |
'record deleted'=>'Registro borrado', |
'Please enter' =>'Por favor introduzca ', |
'months' => Array( |
'01'=>'Enero', |
'02'=>'Febrero', |
'03'=>'Marzo', |
'04'=>'Abril', |
'05'=>'Mayo', |
'06'=>'Junio', |
'07'=>'Julio', |
'08'=>'Agosto', |
'09'=>'Septiembre', |
'10'=>'Octubre', |
'11'=>'Noviembre', |
'12'=>'Diciembre'), |
// phpMyEdit-report |
'Make report' => 'Realizar Informe', |
'Select fields' => 'Seleccionar campos', |
'Records per screen' => 'Registros por pantalla', |
); |
?> |
/trunk/jrest/util/lang/PME.lang.FR.inc |
---|
New file |
0,0 → 1,67 |
<?php |
/* |
* phpMyEdit language file |
* |
* language: french (standard) |
* encoding: iso-8859-1 |
* date: 2002-02, 2002-11-07, 2002-12-29 |
* authors: |
* Dario <dartar@users.sourceforge.net> |
* Kaid <kaid@fr.st> |
* hbernard <hbernard@gynov.org> |
*/ |
/* $Platon: phpMyEdit/lang/PME.lang.FR.inc,v 1.15 2004-12-27 20:14:29 nepto Exp $ */ |
return Array( |
'Add' =>'Ajouter', |
'Copy' =>'Copier', |
'Change' =>'Modifier', |
'Delete' =>'Supprimer', |
'View' =>'Afficher', |
'Prev' =>'Précédent', |
'Next' =>'Suivant', |
'First' =>'Début', |
'Last' =>'Fin', |
'Go to' =>'Aller à ', |
'Page' =>'Page', |
'Records' =>'Enregistrements', |
'Save' =>'Enregistrer', |
'More' =>'Enregistrer et continuer', |
'Apply' =>'Appliquer', |
'Cancel' =>'Annuler', |
'Search' =>'Rechercher', |
'Hide' =>'Cacher', |
'Clear' =>'Vider', |
'Query' =>'Requête', |
'Current Query' =>'Requête courante', |
'Sorted By' =>'Tri', |
'ascending' =>'croissant', |
'descending' =>'décroissant', |
'hidden' =>'caché', |
'of' =>'/', // untranslated |
'record added' =>'Enregistrement ajouté', |
'record changed'=>'Enregistrement modifié', |
'record deleted'=>'Enregistrement supprimé', |
'Please enter' =>'Entrez s\'il vous plaît', |
'months' => Array( |
'01'=>'Janvier', |
'02'=>'Février', |
'03'=>'Mars', |
'04'=>'Avril', |
'05'=>'Mai', |
'06'=>'Juin', |
'07'=>'Juillet', |
'08'=>'Août', |
'09'=>'Septembre', |
'10'=>'Octobre', |
'11'=>'Novembre', |
'12'=>'Décembre'), |
// phpMyEdit-report |
'Make report' => 'Make report', |
'Select fields' => 'Select fields', |
'Records per screen' => 'Records per screen', |
); |
?> |
/trunk/jrest/util/lang/PME.lang.ES-AR.inc |
---|
New file |
0,0 → 1,59 |
<?php |
/* |
* phpMyEdit language file |
* |
* language: spanish (argentinian) |
* encoding: iso-8859-1 |
* date: 2003-02-28, 2004-02-15 |
* author: Mariano Vassallo <mvassallo@ciudad.com.ar> |
*/ |
/* $Platon: phpMyEdit/lang/PME.lang.ES-AR.inc,v 1.5 2004-12-27 20:14:29 nepto Exp $ */ |
return Array( |
'Add' =>'Agregar', |
'Copy' =>'Copiar', |
'Change' =>'Cambiar', |
'Delete' =>'Suprimir', |
'View' =>'Visualización', |
'Prev' =>'Anterior', |
'Next' =>'Siguiente', |
'First' =>'Primero', |
'Last' =>'Ultimo', |
'Go to' =>'Ir a', |
'Page' =>'Paginación', |
'Records' =>'Registros', |
'Save' =>'Grabar', |
'More' =>'Más', |
'Apply' =>'Aplicar', |
'Cancel' =>'Cancelar', |
'Search' =>'Buscar', |
'Hide' =>'Ocultar', |
'Clear' =>'Limpiar', |
'Query' =>'Consulta', |
'of' =>'/', // intentionaly untranslated. Alternatve: "de" |
'record added' =>'registro añadido', |
'record changed'=>'registro cambiado', |
'record deleted'=>'registro borrado', |
'Please enter' =>'Por favor introduzca ', |
'months' => Array( |
'01'=>'Enero', |
'02'=>'Febrero', |
'03'=>'Marzo', |
'04'=>'Abril', |
'05'=>'Mayo', |
'06'=>'Junio', |
'07'=>'Julio', |
'08'=>'Agosto', |
'09'=>'Septiembre', |
'10'=>'Octubre', |
'11'=>'Noviembre', |
'12'=>'Diciembre'), |
// phpMyEdit-report |
'Make report' => 'Hacer reporte', |
'Select fields' => 'Seleccionar campos', |
'Records per screen' => 'Registros por pantalla', |
); |
?> |
/trunk/jrest/util/lang/PME.lang.SE.inc |
---|
New file |
0,0 → 1,73 |
<?php |
/* |
* phpMyEdit language file |
* |
* language: swedish |
* encoding: iso-8859-1 |
* date: 2004-01-21, 2004-02-07 |
* authors: |
* Björn Hammarbäck <bjorn@hammarback.se> |
* Stefan Lindmark <stefan@lindmark.net> |
*/ |
/* $Platon: phpMyEdit/lang/PME.lang.SE.inc,v 1.4 2004-12-27 20:14:29 nepto Exp $ */ |
/* |
* å = å |
* ä = ä |
* ö = ö |
* Ä = Ä |
*/ |
return Array( |
'Add' =>'Lägg till', |
'Copy' =>'Kopiera', |
'Change' =>'Ändra', |
'Delete' =>'Ta bort', |
'View' =>'Visa detaljer', |
'Prev' =>'Föregående', |
'Next' =>'Nästa', |
'First' =>'Första', |
'Last' =>'Sista', |
'Go to' =>'Gå till sida', |
'Page' =>'Sida', |
'Records' =>'Poster', |
'Save' =>'Spara', |
'More' =>'Mer', |
'Apply' =>'Verkställ', |
'Cancel' =>'Avbryt', |
'Search' =>'Sök', |
'Hide' =>'Dölj', |
'Clear' =>'Rensa', |
'Query' =>'Sök', |
'Current Query' =>'Nuvarande fråga', |
'Sorted By' =>'Sorterad efter', |
'ascending' =>'stigande', |
'descending' =>'fallande', |
'hidden' =>'gömd', |
'of' =>'av', |
'record added' =>'post adderad', |
'record changed' =>'post ändrad', |
'record deleted' =>'post borttagen', |
'Please enter' =>'Fyll i fältet', |
'months' => Array( |
'01'=>'Januari', |
'02'=>'Februari', |
'03'=>'Mars', |
'04'=>'April', |
'05'=>'Maj', |
'06'=>'Juni', |
'07'=>'Juli', |
'08'=>'Augusti', |
'09'=>'September', |
'10'=>'Oktober', |
'11'=>'November', |
'12'=>'December'), |
// phpMyEdit-report |
'Make report' => 'Skapa rapport', |
'Select fields' => 'Välj fält', |
'Records per screen' => 'Poster per skärm', |
); |
?> |
/trunk/jrest/util/lang/PME.lang.ET.inc |
---|
New file |
0,0 → 1,64 |
<?php |
/* |
* phpMyEdit language file |
* |
* language: estonian |
* encoding: any latin |
* date: 2005-09-13 |
* author: Alexia Death <alexiadeath@hotmail.com> |
*/ |
/* $Platon: phpMyEdit/lang/PME.lang.ET.inc,v 1.1 2005-09-14 13:40:19 nepto Exp $ */ |
return Array( |
'Add' =>'Lisa', |
'Copy' =>'Kopeeri', |
'Change' =>'Muuda', |
'Delete' =>'Kustuta', |
'View' =>'Vaata', |
'Prev' =>'Eelmine', |
'Next' =>htmlentities('Järgmine'), |
'First' =>'Esimene', |
'Last' =>'Viimane', |
'Go to' =>'Positsioon', |
'Page' =>'Leht', |
'Records' =>'Kirjed', |
'Save' =>'Salvesta', |
'More' =>htmlentities('Järgneb...'), |
'Apply' =>'Rakenda muutused', |
'Cancel' =>htmlentities('Tühista'), |
'Search' =>'Otsi', |
'Hide' =>'Peida', |
'Clear' =>htmlentities('Tühjenda väljad'), |
'Query' =>htmlentities('Päring'), |
'Current Query' =>htmlentities('Hetke päring'), |
'Sorted By' =>htmlentities('Sorteermisjärjekord'), |
'ascending' =>'kahanevalt', |
'descending' =>'kasvavalt', |
'hidden' =>'peidetud', |
'of' =>'/', |
'record added' =>'kirje lisatud', |
'record changed' =>'kirje muudetud', |
'record deleted' =>'kirje kustutatud', |
'Please enter' =>'Palun sisesta', |
'months' => Array( |
'01'=>'Jaanuar', |
'02'=>'Veebruar', |
'03'=>htmlentities('Märts'), |
'04'=>'Aprill', |
'05'=>'Mai', |
'06'=>'Juuni', |
'07'=>'Juuli', |
'08'=>'August', |
'09'=>'September', |
'10'=>'Oktoober', |
'11'=>'November', |
'12'=>'Detsember'), |
// phpMyEdit-report |
'Make report' => 'Koosta raport', |
'Select fields' => htmlentities('Vali väljad'), |
'Records per screen' => 'Kirjeid lehe kohta', |
); |
?> |
/trunk/jrest/util/lang/PME.lang.NL.inc |
---|
New file |
0,0 → 1,68 |
<?php |
/* |
* phpMyEdit language file |
* |
* language: dutch (standard) |
* encoding: iso-8859-1 |
* date: 2002-09-21, 2002-12-17, 2006-01-05 |
* authors: |
* Paul Barends <pbarends@xs4all.nl> |
* Erwin Janszen <Erwin.Janszen@mail.ing.nl> |
* URL: |
* http://platon.sk/projects/bug_view_advanced_page.php?f_bug_id=197 |
*/ |
/* $Platon: phpMyEdit/lang/PME.lang.NL.inc,v 1.16 2006-01-05 04:45:22 nepto Exp $ */ |
return Array( |
'Add' =>'Toevoegen', |
'Copy' =>'Kopiëren', |
'Change' =>'Bewerken', |
'Delete' =>'Wissen', |
'View' =>'Details', |
'Prev' =>'Vorige', |
'Next' =>'Volgende', |
'First' =>'Eerste', |
'Last' =>'Laatste', |
'Go to' =>'Ga naar', |
'Page' =>'Pagina', |
'Records' =>'Rijen', |
'Save' =>'Bewaren', |
'More' =>'Meer', |
'Apply' =>'Toepassen', |
'Cancel' =>'Annuleren', |
'Search' =>'Zoeken', |
'Hide' =>'Verbergen', |
'Clear' =>'Schonen', // 'Leeg maken', |
'Query' =>'Selecteer', // 'Selectie maken', |
'Current Query' =>'Huidige selectie', |
'Sorted By' =>'Gesorteerd op', |
'ascending' =>'oplopend', |
'descending' =>'aflopend', |
'hidden' =>'verborgen', |
'of' =>'van', |
'record added' =>'rij toegevoegd', |
'record changed' =>'rij aangepast', |
'record deleted' =>'rij gewist', |
'Please enter' =>'Voer a.u.b. in:', |
'months' => Array( |
'01'=>'januari', |
'02'=>'februari', |
'03'=>'maart', |
'04'=>'april', |
'05'=>'mei', |
'06'=>'juni', |
'07'=>'juli', |
'08'=>'augustus', |
'09'=>'september', |
'10'=>'october', |
'11'=>'november', |
'12'=>'december'), |
// phpMyEdit-report |
'Make report' => 'Maak rapport', |
'Select fields' => 'Selecteer velden', |
'Records per screen' => 'Rij per scherm', |
); |
?> |
/trunk/jrest/util/lang/PME.lang.EU.inc |
---|
New file |
0,0 → 1,64 |
<?php |
/* |
* phpMyEdit language file |
* |
* language: basque |
* encoding: iso-8859-1 |
* date: 2004-05-11 |
* author: Ibon Igartua <ibon@zuhar.net> |
*/ |
/* $Platon: phpMyEdit/lang/PME.lang.EU.inc,v 1.1 2004-05-17 10:53:06 nepto Exp $ */ |
return Array( |
'Add' =>'Gehitu', |
'Copy' =>'Kopiatu', |
'Change' =>'Aldatu', |
'Delete' =>'Ezabatu', |
'View' =>'Ikusi', |
'Prev' =>'Aurrekoa', |
'Next' =>'Hurrengoa', |
'First' =>'Lehena', |
'Last' =>'Azkena', |
'Go to' =>'Joan', |
'Page' =>'Orrialdea', |
'Records' =>'Erregistroak', |
'Save' =>'Gorde', |
'More' =>'Gehiago', |
'Apply' =>'Aplikatu', |
'Cancel' =>'Utzi', |
'Search' =>'Bilatu', |
'Hide' =>'Ezkutatu', |
'Clear' =>'Garbitu', |
'Query' =>'Kontsulta', |
'Current Query' =>'Uneko Kontsulta', |
'Sorted By' =>'Orden Irizpidea', |
'ascending' =>'gorantz', |
'descending' =>'beherantz', |
'hidden' =>'ezkutukoa', |
'of' =>'-', |
'record added' =>'erregistroa gehituta', |
'record changed'=>'erregistroa aldatuta', |
'record deleted'=>'erregistroa ezabatuta', |
'Please enter' =>'Mesedez, sartu ezazu ', |
'months' => Array( |
'01'=>'urtarrila', |
'02'=>'otsaila', |
'03'=>'martxoa', |
'04'=>'apirila', |
'05'=>'maiatza', |
'06'=>'ekaina', |
'07'=>'uztaila', |
'08'=>'abuztua', |
'09'=>'iraila', |
'10'=>'urria', |
'11'=>'azaroa', |
'12'=>'abendua'), |
// phpMyEdit-report |
'Make report' => 'Txostena sortu', |
'Select fields' => 'Eremuak aukertau', |
'Records per screen' => 'Erregistroak orrialdeko', |
); |
?> |
/trunk/jrest/util/lang/.directory |
---|
New file |
0,0 → 1,5 |
[Dolphin] |
Timestamp=2010,6,10,16,42,14 |
[Settings] |
ShowDotFiles=true |
/trunk/jrest/util/lang/PME.lang.PL.inc |
---|
New file |
0,0 → 1,60 |
<?php |
/* |
* phpMyEdit language file |
* |
* language: polish |
* encoding: iso-8859-2 |
* date: 2002-10-01, 2003-06-30 |
* author: Piotr Walesiuk <p.walesiuk@bos.com.pl> |
*/ |
/* $Platon: phpMyEdit/lang/PME.lang.PL.inc,v 1.9 2004-12-27 20:14:29 nepto Exp $ */ |
return Array( |
'Add' =>'Dodaj', |
'Copy' =>'Kopiuj', |
'Change' =>'Zmieñ', |
'Delete' =>'Usuñ', |
'View' =>'Poka¿', |
'Prev' =>'Wstecz', |
'Next' =>'Dalej', |
'First' =>'First', // untranslated |
'Last' =>'Last', // untranslated |
'Go to' =>'Go to', // untranslated |
'Page' =>'Strona', |
'Records' =>'Rekordy', |
'Save' =>'Zapisz', |
'More' =>'Wiêcej', |
'Apply' =>'Zastosuj', |
'Cancel' =>'Anuluj', |
'Search' =>'Szukaj', |
'Hide' =>'Ukryj', |
'Clear' =>'Wyczy¶æ', |
'Query' =>'Zapytanie', |
'Current Query' =>'Aktualne zapytanie', |
'Sorted By' =>'Posortowane wed³ug', |
'ascending' =>'rosn±co', |
'descending' =>'malej±co', |
'hidden' =>'ukryte', |
'of' =>'z', |
'record added' =>'rekord dodany', |
'record changed'=>'rekord zmieniony', |
'record deleted'=>'rekord usuniêty', |
'Please enter' =>'Proszê wprowadziæ', |
'months' => Array( |
'01'=>'Styczeñ', |
'02'=>'Luty', |
'03'=>'Marzec', |
'04'=>'Kwiecieñ', |
'05'=>'Maj', |
'06'=>'Czerwiec', |
'07'=>'Lipiec', |
'08'=>'Sierpieñ', |
'09'=>'Wrzesieñ', |
'10'=>'Pa¼dziernik', |
'11'=>'Listopad', |
'12'=>'Grudzieñ') |
); |
?> |
/trunk/jrest/util/lang/PME.lang.IT.inc |
---|
New file |
0,0 → 1,66 |
<?php |
/* |
* phpMyEdit language file |
* |
* language: italian (standard) |
* encoding: iso-8859-1 |
* date: 2002-02, 2002-11-07, 2003-04-13, 2004-03-31 |
* authors: |
* Dario <dartar@users.sourceforge.net> |
* Keatch <raffaele.spangaro@eurika.net> |
*/ |
/* $Platon: phpMyEdit/lang/PME.lang.IT.inc,v 1.15 2004-12-27 20:14:29 nepto Exp $ */ |
return Array( |
'Add' =>'Aggiungi', |
'Copy' =>'Copia', |
'Change' =>'Modifica', |
'Delete' =>'Cancella', |
'View' =>'Visualizza', |
'Prev' =>'Precedente', |
'Next' =>'Seguente', |
'First' =>'Prima', |
'Last' =>'Ultima', |
'Go to' =>'Vai a', |
'Page' =>'Pagina', |
'Records' =>'Voci', |
'Save' =>'Salva', |
'More' =>'Salva & Continua', |
'Apply' =>'Applica', |
'Cancel' =>'Annulla', |
'Search' =>'Cerca', |
'Hide' =>'Nascondi', |
'Clear' =>'Svuota', |
'Query' =>'Chiedi', |
'Current Query' =>'Richiesta Corrente', |
'Sorted By' =>'Ordinato per', |
'ascending' =>'crescente', |
'descending' =>'decrescente', |
'hidden' =>'nascosto', |
'of' =>'/', |
'record added' =>'voce aggiunta', |
'record changed'=>'voce modificata', |
'record deleted'=>'voce eliminata', |
'Please enter' =>'Si prega di riempire il campo: ', |
'months' => Array( |
'01'=>'Gennaio', |
'02'=>'Febbraio', |
'03'=>'Marzo', |
'04'=>'Aprile', |
'05'=>'Maggio', |
'06'=>'Giugno', |
'07'=>'Luglio', |
'08'=>'Agosto', |
'09'=>'Settembre', |
'10'=>'Ottobre', |
'11'=>'Novembre', |
'12'=>'Dicembre'), |
// phpMyEdit-report |
'Make report' => 'Genera report', |
'Select fields' => 'Seleziona campi', |
'Records per screen' => 'Record per schermata', |
); |
?> |
/trunk/jrest/util/lang/PME.lang.CZ.inc |
---|
New file |
0,0 → 1,64 |
<?php |
/* |
* phpMyEdit language file |
* |
* language: czech |
* encoding: iso-8859-2 |
* date: 2005-04-26 |
* author: Jan Cinert <ion_lord@seznam.cz> |
*/ |
/* $Platon: phpMyEdit/lang/PME.lang.CZ.inc,v 1.1 2005-04-26 13:15:38 nepto Exp $ */ |
return Array( |
'Add' =>'Pøidat', |
'Copy' =>'Kopírovat', |
'Change' =>'Zmìnit', |
'Delete' =>'Smazat', |
'View' =>'Zobrazit', |
'Prev' =>'Pøedcházející', |
'Next' =>'Následující', |
'First' =>'První', |
'Last' =>'Poslední', |
'Go to' =>'Otevøít', |
'Page' =>'Stránka', |
'Records' =>'Záznamù', |
'Save' =>'Ulo¾it', |
'More' =>'Více', |
'Apply' =>'Pou¾ít', |
'Cancel' =>'Zru¹it', |
'Search' =>'Hledat', |
'Hide' =>'Skrýt', |
'Clear' =>'Smazat', |
'Query' =>'Dotaz', |
'Current Query' =>'Stávající dotaz', |
'Sorted By' =>'Uspoøádané podle', |
'ascending' =>'vzestupnì', |
'descending' =>'sestupnì', |
'hidden' =>'skrytý', |
'of' =>'z', |
'record added' =>'pøidaný záznam', |
'record changed'=>'zmìnìný záznam', |
'record deleted'=>'smazaný záznam', |
'Please enter' =>'Zadejte prosím', |
'months' => Array( |
'01'=>'Leden', |
'02'=>'Únor', |
'03'=>'Bøezen', |
'04'=>'Duben', |
'05'=>'Kvìten', |
'06'=>'Èerve', |
'07'=>'Èervenec', |
'08'=>'Srpen', |
'09'=>'Záøí', |
'10'=>'Øíjen', |
'11'=>'Listopad', |
'12'=>'Prosinec'), |
// phpMyEdit-report |
'Make report' => 'Vytvoøit zprávu', |
'Select fields' => 'Vybrat pole', |
'Records per screen' => 'Poèet záznamù na stránce', |
); |
?> |
/trunk/jrest/util/lang/PME.lang.SK.inc |
---|
New file |
0,0 → 1,64 |
<?php |
/* |
* phpMyEdit language file |
* |
* language: slovak |
* encoding: iso-8859-2 |
* date: 2002-02-02, 2003-05-01 |
* author: Ondrej Jombik <nepto@php.net> |
*/ |
/* $Platon: phpMyEdit/lang/PME.lang.SK.inc,v 1.12 2004-12-27 20:14:29 nepto Exp $ */ |
return Array( |
'Add' =>'Prida»', |
'Copy' =>'Kopírova»', |
'Change' =>'Zmeni»', |
'Delete' =>'Zmaza»', |
'View' =>'Pozrie»', |
'Prev' =>'Predchádzajúci', |
'Next' =>'Ïal¹í', |
'First' =>'Prvý', |
'Last' =>'Posledný', |
'Go to' =>'Choï na', |
'Page' =>'Stránka', |
'Records' =>'Záznamov', |
'Save' =>'Ulo¾i»', |
'More' =>'Viac', |
'Apply' =>'Pou¾i»', |
'Cancel' =>'Storno', |
'Search' =>'Hµada»', |
'Hide' =>'Skry»', |
'Clear' =>'Zru¹i»', |
'Query' =>'Vyhµada»', |
'Current Query' =>'Aktuálny dotaz', |
'Sorted By' =>'Usporiadané podµa', |
'ascending' =>'vzostupne', |
'descending' =>'zostupne', |
'hidden' =>'skryté', |
'of' =>'z', |
'record added' =>'záznam pridaný', |
'record changed'=>'záznam zmenený', |
'record deleted'=>'záznam zmazaný', |
'Please enter' =>'Prosím zadajte', |
'months' => Array( |
'01'=>'Január', |
'02'=>'Február', |
'03'=>'Marec', |
'04'=>'Apríl', |
'05'=>'Máj', |
'06'=>'Jún', |
'07'=>'Júl', |
'08'=>'August', |
'09'=>'September', |
'10'=>'Október', |
'11'=>'November', |
'12'=>'December'), |
// phpMyEdit-report |
'Make report' => 'Vytvori» report', |
'Select fields' => 'Vybra» ståpce', |
'Records per screen' => 'Poèet záznamov na stránke', |
); |
?> |
/trunk/jrest/util/.directory |
---|
New file |
0,0 → 1,5 |
[Dolphin] |
Timestamp=2010,6,10,16,40,47 |
[Settings] |
ShowDotFiles=true |
/trunk/jrest/.directory |
---|
New file |
0,0 → 1,5 |
[Dolphin] |
Timestamp=2010,6,10,16,42,20 |
[Settings] |
ShowDotFiles=true |
/trunk/jrest/services/ExecuteurLien.php |
---|
New file |
0,0 → 1,48 |
<?php |
/** |
* PHP Version 5 |
* |
* @category PHP |
* @package papyrus_bp |
* @author aurelien <aurelien@tela-botanica.org> |
* @copyright 2010 Tela-Botanica |
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL |
* @version SVN: <svn_id> |
* @link /doc/papyrus_bp/ |
*/ |
Class ExecuteurLien extends JRestService { |
public function getElement($uid){ |
if(isset($uid[0])) { |
$lien_code = $uid[0]; |
$lien = base64_decode($lien_code); |
} else { |
return; |
} |
if(!isset($uid[1])) { |
$retour_ajax = true; |
} else { |
$adresse_retour = base64_decode($uid[1]); |
} |
$requete = file_get_contents($lien); |
echo $lien; |
exit; |
if($retour_ajax) { |
if($requete) { |
$resultat = 'ok'; |
} else { |
$resultat = false; |
} |
$this->envoyer($resultat); |
} else { |
header('Location: http://'.$adresse_retour); |
exit; |
} |
} |
} |
?> |
/trunk/jrest/services/InformationsUtilisateur.php |
---|
New file |
0,0 → 1,27 |
<?php |
/** |
* PHP Version 5 |
* |
* @category PHP |
* @package annuaire |
* @author aurelien <aurelien@tela-botanica.org> |
* @copyright 2010 Tela-Botanica |
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL |
* @version SVN: <svn_id> |
* @link /doc/annuaire/ |
*/ |
Class InformationsUtilisateur extends JRestService { |
public function getElement($uid){ |
$mail_utilisateur = $uid[0]; |
$id_annuaire = Config::get('annuaire_defaut'); |
$controleur = new AnnuaireControleur(); |
$valeurs = $controleur->obtenirInfosUtilisateurOpenId($id_annuaire,$mail_utilisateur, true); |
$this->envoyer($valeurs); |
} |
} |
?> |
/trunk/jrest/services/GestionLettreActu.php |
---|
New file |
0,0 → 1,40 |
<?php |
/** |
* PHP Version 5 |
* |
* @category PHP |
* @package papyrus_bp |
* @author aurelien <aurelien@tela-botanica.org> |
* @copyright 2010 Tela-Botanica |
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL |
* @version SVN: <svn_id> |
* @link /doc/papyrus_bp/ |
*/ |
Class GestionLettreActu extends JRestService { |
public function getElement($uid){ |
// TODO : rajouter controle d'accès ! |
$id_utilisateur = $uid[0]; |
$mail_utilisateur = $uid[1]; |
if(isset($uid[2])) { |
$id_annuaire = $uid[2]; |
} else { |
$id_annuaire = Config::get('annuaire_defaut'); |
} |
$controleur = new AnnuaireControleur(); |
$est_abonne = $controleur->estAbonneLettreActualite($id_annuaire,$id_utilisateur); |
echo 'je suis abonné ? '.$est_abonne; |
$changement = $controleur->abonnerDesabonnerLettreActualite($id_annuaire, $id_utilisateur, !$est_abonne); |
echo 'OK'; |
} |
} |
?> |
/trunk/jrest/services/StatistiquesAnnuaire.php |
---|
New file |
0,0 → 1,30 |
<?php |
/** |
* PHP Version 5 |
* |
* @category PHP |
* @package annuaire |
* @author aurelien <aurelien@tela-botanica.org> |
* @copyright 2010 Tela-Botanica |
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL |
* @version SVN: <svn_id> |
* @link /doc/annuaire/ |
*/ |
Class StatistiquesAnnuaire extends JRestService { |
public function getElement($uid){ |
if(!isset($uid[0])) { |
$id_annuaire = $uid[0]; |
} else { |
$id_annuaire = Config::get('annuaire_defaut'); |
} |
$controleur = new StatistiquesControleur(); |
$valeurs = $controleur->obtenirGraphiques($id_annuaire); |
$this->envoyer($valeurs); |
} |
} |
?> |
/trunk/jrest/services/Gestion.php |
---|
New file |
0,0 → 1,50 |
<?php |
/** |
* PHP Version 5 |
* |
* @category PHP |
* @package papyrus_bp |
* @author aurelien <aurelien@tela-botanica.org> |
* @copyright 2010 Tela-Botanica |
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL |
* @version SVN: <svn_id> |
* @link /doc/papyrus_bp/ |
*/ |
Class Gestion extends JRestService { |
public function getElement($uid){ |
$id_utilisateur = $uid[0]; |
$mail_utilisateur = $uid[1]; |
if(isset($uid[2])) { |
$id_annuaire = $uid[2]; |
} else { |
$id_annuaire = Config::get('annuaire_defaut'); |
} |
$controleur = new AnnuaireControleur(); |
$est_abonne = $controleur->estAbonneLettreActualite($id_annuaire,$id_utilisateur); |
$resume['titre'] = 'Lettre d\'actualité'; |
if($est_abonne == '1') { |
$message = 'Vous êtes abonné à la lettre d\'actualité'; |
} else { |
$message = 'Vous n\'êtes pas abonné à la lettre d\'actualité'; |
} |
$cible_lien_desinscrire = '162.38.234.9/annuaire/jrest/GestionLettreActu/'.$id_utilisateur.DS.$mail_utilisateur.DS.$id_annuaire; |
$cible_lien = '162.38.234.9/annuaire/jrest/GestionLettreActu/'.$id_utilisateur.DS.$mail_utilisateur.DS.$id_annuaire; |
$resume_item = array('element' => $message, 'lien_desinscrire' => $cible_lien_desinscrire, 'lien' => $cible_lien); |
$resume['elements'][] = $resume_item; |
$this->envoyer($resume); |
} |
public function updateElement($uid, $pairs) { |
} |
} |
?> |
/trunk/jrest/services/JRestService.php |
---|
New file |
0,0 → 1,238 |
<?php |
/** |
* Classe mère abstraite contenant les méthodes génériques des services. |
* Encodage en entrée : utf8 |
* Encodage en sortie : utf8 |
* |
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org> |
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt> |
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt> |
* @version $Id$ |
* @copyright 2009 |
*/ |
abstract class JRestService { |
public $config; |
protected $bdd; |
protected $log = array(); |
protected $messages = array(); |
protected $debug = array(); |
protected $distinct = false; |
protected $orderby = null; |
protected $formatRetour = 'objet'; |
protected $start = 0; |
protected $limit = 150; |
public function __construct($config, $demarrer_session = true) { |
// Tableau contenant la config de Jrest |
$this->config = $config; |
// Connection à la base de données |
$this->bdd = $this->connecterPDO($this->config, 'appli'); |
// Nettoyage du $_GET (sécurité) |
if (isset($_GET)) { |
$get_params = array('orderby', 'distinct', 'start', 'limit', 'formatRetour'); |
foreach ($get_params as $get) { |
$verifier = array('NULL', "\n", "\r", "\\", "'", '"', "\x00", "\x1a", ';'); |
$_GET[$get] = str_replace($verifier, '', $_GET[$get]); |
if (isset($_GET[$get]) && $_GET[$get] != '') { |
$this->$get = $_GET[$get]; |
} else { |
$_GET[$get] = null; |
} |
} |
} |
} |
/** |
* Méthode appelée quand aucun paramètre n'est passé dans l'url et avec une requête de type GET. |
*/ |
public function getRessource() { |
$this->getElement(array()); |
} |
protected function envoyer($donnees = null, $mime = 'text/html', $encodage = 'utf-8', $json = true) { |
// Traitements des messages d'erreurs et données |
if (count($this->messages) != 0) { |
header('HTTP/1.1 500 Internal Server Error'); |
$mime = 'text/html'; |
$encodage = 'utf-8'; |
$json = true; |
$sortie = $this->messages; |
} else { |
$sortie = $donnees; |
if (is_null($donnees)) { |
$sortie = 'OK'; |
} |
} |
// Gestion de l'envoie du déboguage |
$this->envoyerDebogage(); |
// Encodage au format et JSON et envoie sur la sortie standard |
$contenu = $json ? json_encode($sortie) : $sortie; |
$this->envoyerContenu($encodage, $mime, $contenu); |
} |
protected function envoyerDebogage() { |
if (!is_array($this->debug)) { |
$this->debug[] = $this->debug; |
} |
if (count($this->debug) != 0) { |
foreach ($this->debug as $cle => $val) { |
if (is_array($val)) { |
$this->debug[$cle] = print_r($val, true); |
} |
} |
header('X-DebugJrest-Data:'.json_encode($this->debug)); |
} |
} |
protected function envoyerContenu($encodage, $mime, $contenu) { |
header("Content-Type: $mime; charset=$encodage"); |
print $contenu; |
} |
private function connecterPDO($config, $base = 'database') { |
$cfg = $config[$base]; |
$dsn = $cfg['phptype'].':dbname='.$cfg['database'].';host='.$cfg['hostspec']; |
try { |
$PDO = new PDO($dsn, $cfg['username'], $cfg['password']); |
} catch (PDOException $e) { |
echo 'La connexion à la base de donnée via PDO a échouée : ' . $e->getMessage(); |
} |
// Passe en UTF-8 la connexion à la BDD |
$PDO->exec("SET NAMES 'utf8'"); |
// Affiche les erreurs détectées par PDO (sinon mode silencieux => aucune erreur affiché) |
$PDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
return $PDO; |
} |
protected function getTxt($id) { |
$sortie = ''; |
switch ($id) { |
case 'sql_erreur' : $sortie = 'Requête echec. Fichier : "%s". Ligne : "%s". Message : %s'; break; |
default : $sortie = $id; |
} |
return $sortie; |
} |
protected function traiterParametresUrl($params_attendu, $params, $pourBDD = true) { |
$sortie = array(); |
foreach ($params_attendu as $num => $nom) { |
if (isset($params[$num]) && $params[$num] != '*') { |
if ($pourBDD) { |
$params[$num] = $this->bdd->quote($params[$num]); |
} |
$sortie[$nom] = $params[$num]; |
} |
} |
return $sortie; |
} |
protected function traiterParametresPost($params) { |
$sortie = array(); |
foreach ($params as $cle => $valeur) { |
$sortie[$cle] = $this->bdd->quote($valeur); |
} |
return $sortie; |
} |
protected function getIdentification(&$params) { |
// Initialisation des variables |
$utilisateur = array(0, session_id()); |
// L'id utilisateur est soit passé par le POST soit dans l'url |
if (is_array($params) && isset($params['cmhl_ce_modifier_par'])) { |
$utilisateur[0] = $params['cmhl_ce_modifier_par']; |
unset($params['cmhl_ce_modifier_par']); |
} else if (is_string($params)) { |
$utilisateur[0] = $params; |
} |
return $utilisateur; |
} |
protected function etreAutorise($id_utilisateur) { |
$autorisation = false; |
if (($_SESSION['coel_utilisateur'] != '') && $_SESSION['coel_utilisateur']['id'] != $id_utilisateur) { |
$this->messages[] = 'Accès interdit.'; |
} else if ($_SESSION['coel_utilisateur'] == '') { |
$this->messages[] = 'Veuillez vous identifiez pour accéder à cette fonction.'; |
} else { |
$autorisation = true; |
} |
return $autorisation; |
} |
private function gererIdentificationPermanente() { |
// Pour maintenir l'utilisateur tjrs réellement identifié nous sommes obligé de recréer une SESSION et de le recharger depuis la bdd |
if ($this->getUtilisateur() == '' |
&& isset($_COOKIE['coel_login']) |
&& ($utilisateur = $this->chargerUtilisateur($_COOKIE['coel_login'], $_COOKIE['coel_mot_de_passe']))) { |
$this->setUtilisateur($utilisateur, $_COOKIE['coel_permanence']); |
} |
} |
protected function getUtilisateur() { |
return (isset($_SESSION['coel_utilisateur']) ? $_SESSION['coel_utilisateur'] : ''); |
} |
/** |
* Méthode prenant en paramètre un chemin de fichier squelette et un tableau associatif de données, |
* en extrait les variables, charge le squelette et retourne le résultat des deux combinés. |
* |
* @param String $fichier le chemin du fichier du squelette |
* @param Array $donnees un tableau associatif contenant les variables a injecter dans le squelette. |
* |
* @return boolean false si le squelette n'existe pas, sinon la chaine résultat. |
*/ |
public static function traiterSquelettePhp($fichier, Array $donnees = array()) { |
$sortie = false; |
if (file_exists($fichier)) { |
// Extraction des variables du tableau de données |
extract($donnees); |
// Démarage de la bufferisation de sortie |
ob_start(); |
// Si les tags courts sont activés |
if ((bool) @ini_get('short_open_tag') === true) { |
// Simple inclusion du squelette |
include $fichier; |
} else { |
// Sinon, remplacement des tags courts par la syntaxe classique avec echo |
$html_et_code_php = self::traiterTagsCourts($fichier); |
// Pour évaluer du php mélangé dans du html il est nécessaire de fermer la balise php ouverte par eval |
$html_et_code_php = '?>'.$html_et_code_php; |
// Interprétation du html et du php dans le buffer |
echo eval($html_et_code_php); |
} |
// Récupèration du contenu du buffer |
$sortie = ob_get_contents(); |
// Suppression du buffer |
@ob_end_clean(); |
} else { |
$msg = "Le fichier du squelette '$fichier' n'existe pas."; |
trigger_error($msg, E_USER_WARNING); |
} |
// Retourne le contenu |
return $sortie; |
} |
/** |
* Fonction chargeant le contenu du squelette et remplaçant les tags court php (<?= ...) par un tag long avec echo. |
* |
* @param String $chemin_squelette le chemin du fichier du squelette |
* |
* @return string le contenu du fichier du squelette php avec les tags courts remplacés. |
*/ |
private static function traiterTagsCourts($chemin_squelette) { |
$contenu = file_get_contents($chemin_squelette); |
// Remplacement de tags courts par un tag long avec echo |
$contenu = str_replace('<?=', '<?php echo ', $contenu); |
// Ajout systématique d'un point virgule avant la fermeture php |
$contenu = preg_replace("/;*\s*\?>/", "; ?>", $contenu); |
return $contenu; |
} |
} |
?> |
/trunk/jrest/services/TestLoginMdp.php |
---|
New file |
0,0 → 1,36 |
<?php |
/** |
* PHP Version 5 |
* |
* @category PHP |
* @package annuaire |
* @author aurelien <aurelien@tela-botanica.org> |
* @copyright 2010 Tela-Botanica |
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL |
* @version SVN: <svn_id> |
* @link /doc/annuaire/ |
*/ |
Class TestLoginMdp extends JRestService { |
public function getElement($uid){ |
if(!isset($uid[0]) || $uid[0] == '' || !isset($uid[1]) || $uid[1] == '') { |
$this->envoyer(false); |
return; |
} |
$mail_utilisateur = $uid[0]; |
$pass = $uid[1]; |
// TODO vérifier que le mot de passe est crypté ! |
$id_annuaire = Config::get('annuaire_defaut'); |
$controleur = new AnnuaireControleur(); |
$id_match_pass = $controleur->comparerIdentifiantMotDePasse($id_annuaire,$mail_utilisateur, $pass, true, true); |
$this->envoyer($id_match_pass); |
} |
} |
?> |
/trunk/jrest/services/.directory |
---|
New file |
0,0 → 1,5 |
[Dolphin] |
Timestamp=2010,5,25,17,11,22 |
[Settings] |
ShowDotFiles=true |
/trunk/jrest/services/UtilisateurExiste.php |
---|
New file |
0,0 → 1,27 |
<?php |
/** |
* PHP Version 5 |
* |
* @category PHP |
* @package annuaire |
* @author aurelien <aurelien@tela-botanica.org> |
* @copyright 2010 Tela-Botanica |
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL |
* @version SVN: <svn_id> |
* @link /doc/annuaire/ |
*/ |
Class UtilisateurExiste extends JRestService { |
public function getElement($uid){ |
$mail_utilisateur = $uid[0]; |
$id_annuaire = Config::get('annuaire_defaut'); |
$controleur = new AnnuaireControleur(); |
$existe = $controleur->UtilisateurExiste($id_annuaire,$mail_utilisateur, true); |
$this->envoyer($existe); |
} |
} |
?> |