// desc will be the title of the column
$a['desc'] = $a['Field'];
$a['display'] = true;
-
+
if (substr($a['Type'],0,8) == 'varchar(') {
// limit editing box size
$a['Size'] = $a['Maxlength'] = substr($a['Type'], 8, strlen($a['Type']) - 9);
if ($descr['Type'] == 'timestamp') {
// set readable timestamp
$date =& $entry[$field];
- $date = preg_replace('/([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/', '\3/\2/\1 \4:\5:\6', $date);
+ $date = preg_replace('/([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/', '\3/\2/\1 \4:\5:\6', $date);
}
if ($descr['Type'] == 'date') {
$date =& $entry[$field];
$this->vars[$name]['desc'] = $desc;
$this->vars[$name]['display'] = $display;
}
- // add a join table, when deleting a row corresponding entries will be deleted in these tables
+ // add a join table, when deleting a row corresponding entries will be deleted in these tables
function add_join_table($name,$joinid,$joindel,$joinextra="") {
if ($joindel)
$this->jtables[$name] = array("joinid" => $joinid,"joinextra" => $joinextra?(" AND ".$joinextra):"");
}
$val = "'".addslashes($val)."'";
} elseif (Post::has($field)) {
- $val = Post::v($field);
+ $val = Post::v($field);
if ($descr['Type'] == 'timestamp') {
- $val = preg_replace('/([0-9]{1,2})\/([0-9]{1,2})\/([0-9]{4}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})/', '\3\2\1\4\5\6', $val);
+ $val = preg_replace('/([0-9]{1,2})\/([0-9]{1,2})\/([0-9]{4}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})/', '\3\2\1\4\5\6', $val);
}
elseif ($descr['Type'] == 'date') {
$val = preg_replace('/([0-9]{1,2})\/([0-9]{1,2})\/([0-9]{4})/', '\3-\2-\1', $val);
$val = "'".addslashes($val)."'";
} else {
$cancel = true;
- $page->trig("Il manque le champ ".$field);
+ $page->trig("Il manque le champ ".$field);
}
$values .= $val;
}
<?php
-/******************************************************************************
- * *
- * Original file can be found on http://xmlrpc-epi.sourceforge.net/ *
- * in the module xmlrpc-epi-php v0.51 file samples/utils/utils.php *
- * *
- * The Polytechnique.org TEAM *
- * *
- **************************************************************************{{{*/
-
-/*
- This file is part of, or distributed with, libXMLRPC - a C library for
- xml-encoded function calls.
-
- Author: Dan Libby (dan@libby.com)
- Epinions.com may be contacted at feedback@epinions-inc.com
-*/
-
-/*
- Copyright 2001 Epinions, Inc.
-
- Subject to the following 3 conditions, Epinions, Inc. permits you, free
- of charge, to (a) use, copy, distribute, modify, perform and display this
- software and associated documentation files (the "Software"), and (b)
- permit others to whom the Software is furnished to do so as well.
-
- 1) The above copyright notice and this permission notice shall be included
- without modification in all copies or substantial portions of the
- Software.
-
- 2) THE SOFTWARE IS PROVIDED "AS IS", WITHOUT ANY WARRANTY OR CONDITION OF
- ANY KIND, EXPRESS, IMPLIED OR STATUTORY, INCLUDING WITHOUT LIMITATION ANY
- IMPLIED WARRANTIES OF ACCURACY, MERCHANTABILITY, FITNESS FOR A PARTICULAR
- PURPOSE OR NONINFRINGEMENT.
-
- 3) IN NO EVENT SHALL EPINIONS, INC. BE LIABLE FOR ANY DIRECT, INDIRECT,
- SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES OR LOST PROFITS ARISING OUT
- OF OR IN CONNECTION WITH THE SOFTWARE (HOWEVER ARISING, INCLUDING
- NEGLIGENCE), EVEN IF EPINIONS, INC. IS AWARE OF THE POSSIBILITY OF SUCH
- DAMAGES.
-
-*/
-
-/* xmlrpc utilities (xu)
- * author: Dan Libby (dan@libby.com)
- */
-
-/* generic function to call an http server with post method */
-function xu_query_http_post($request, $host, $uri, $port, $timeout, $user,
- $pass, $secure=false)
-{
- $response_buf = '';
- if ($host && $uri && $port) {
- $content_len = strlen($request);
- $fsockopen = $secure ? 'fsockopen_ssl' : 'fsockopen';
- $query_fd = $fsockopen($host, $port, $errno, $errstr, 10);
-
- if ($query_fd) {
-
- $auth = '';
- if ($user) {
- $auth = 'Authorization: Basic ' . base64_encode($user . ':' . $pass) . "\r\n";
- }
-
- $http_request =
- "POST $uri HTTP/1.0\r\n" .
- "Host: $host:$port\r\n" .
- $auth .
- "User-Agent: xmlrpc-epi-php/0.2 (PHP)\r\n" .
- "Content-Type: text/xml\r\n" .
- "Content-Length: $content_len\r\n" .
- "Connection: Close\r\n" .
- "\r\n" .
- $request;
-
- fputs($query_fd, $http_request, strlen($http_request));
-
- $header_parsed = false;
- while (!feof($query_fd)) {
- $line = fgets($query_fd, 4096);
- if (!$header_parsed) {
- if ($line === "\r\n" || $line === "\n") {
- $header_parsed = 1;
- }
- } else {
- $response_buf .= $line;
- }
- }
-
- fclose($query_fd);
- }
- }
-
- return $response_buf;
-}
-
-function find_and_decode_xml($buf)
-{
- if (strlen($buf)) {
- $xml_begin = substr($buf, strpos($buf, '<?xml'));
- if (strlen($xml_begin)) {
- $retval = xmlrpc_decode($xml_begin);
- }
- }
- return $retval;
-}
-
-
-/**
- * @param params a struct containing 3 or more of these key/val pairs:
- * @param host remote host (required)
- * @param uri remote uri (required)
- * @param port remote port (required)
- * @param method name of method to call
- * @param args arguments to send (parameters to remote xmlrpc server)
- * @param timeout timeout in secs. (0 = never)
- * @param user user name for authentication.
- * @param pass password for authentication
- * @param secure secure. wether to use fsockopen_ssl. (requires special php build).
- */
-function xu_rpc_http_concise($params) {
- $host = $uri = $port = $method = $args = null;
- $timeout = $user = $pass = $secure = null;
-
- extract($params);
-
- // default values
- if (!$port) {
- $port = 80;
- }
- if (!$uri) {
- $uri = '/';
- }
- if ($host && $uri && $port) {
- $request_xml = xmlrpc_encode_request($method, $args);
- $response_buf = xu_query_http_post($request_xml, $host, $uri, $port,
- $timeout, $user, $pass, $secure);
- $retval = find_and_decode_xml($response_buf);
- }
- return $retval;
-}
-
-/*}}}***********************************************************************
+/***************************************************************************
* Copyright (C) 2003-2006 Polytechnique.org *
* http://opensource.polytechnique.org/ *
* *
class XmlrpcClient
{
- var $url;
- var $urlparts;
+ private $url;
+ private $urlparts;
- function XmlrpcClient($url)
+ public function __construct($url)
{
$this->url = $url;
$this->urlparts = parse_url($this->url);
- foreach (array('scheme', 'host', 'user', 'pass', 'path', 'query', 'fragment') as $part) {
- if (!isset($this->urlparts[$part])) {
- $this->urlparts[$part] = null;
- }
+
+ if (empty($this->urlparts['port'])) {
+ $this->urlparts['port'] = 80;
}
+
+ if (empty($this->urlparts['path'])) {
+ $this->urlparts['path'] = '/';
+ }
+ }
+
+ private function http_post($request)
+ {
+ $host = $path = $port = $user = $pass = null;
+ extract($this->urlparts);
+
+ if ($scheme == 'https') {
+ $host = 'ssl://'.$host;
+ }
+
+ $query_fd = fsockopen($host, $port, $errno, $errstr, 10);
+ if (!$query_fd)
+ return null;
+
+ $auth = '';
+ if ($user) {
+ $auth = 'Authorization: Basic ' . base64_encode("$user:$pass") . "\r\n";
+ }
+
+ $content_len = strlen($request);
+ $http_request =
+ "POST $path HTTP/1.0\r\n" .
+ $auth .
+ "Content-Type: text/xml\r\n" .
+ "Content-Length: $content_len\r\n" .
+ "Connection: Close\r\n" .
+ "Host: $host:$port\r\n" .
+ "\r\n" .
+ $request;
+
+ fputs($query_fd, $http_request, strlen($http_request));
+
+ $buf = '';
+ while (!feof($query_fd)) {
+ $buf .= fread($query_fd, 8192);
+ }
+
+ fclose($query_fd);
+ return $buf;
+ }
+
+ private function find_and_decode_xml($buf)
+ {
+ $pos = strpos($buf, '<?xml');
+ if ($pos !== false) {
+ return xmlrpc_decode(substr($buf, $pos));
+ }
+ trigger_error("Cannot parse XML\n".$buf);
}
- function __call($function, $arguments)
+ public function __call($method, $args)
{
- $requestprms['host'] = $this->urlparts['host'];
- $requestprms['port'] = $this->urlparts['port'];
- $requestprms['uri'] = $this->urlparts['path'];
- $requestprms['user'] = $this->urlparts['user'];
- $requestprms['pass'] = $this->urlparts['pass'];
- $requestprms['method'] = $function;
- $requestprms['args'] = $arguments;
- $requestprms['timeout'] = 0;
- $requestprms['secure'] = 0;
-
- $result = xu_rpc_http_concise($requestprms);
+ $query = xmlrpc_encode_request($method, $args);
+ $answer = $this->http_post($query, $this->urlparts);
+ $result = $this->find_and_decode_xml($answer);
+
if (is_array($result) && isset($result['faultCode'])) {
- print('Error in xmlrpc call \''.$function.'\''."\n");
- print(' code : '.$result['faultCode']."\n");
- print(' message: '.$result['faultString']."\n");
+ trigger_error("Error in xmlrpc call $function\n".
+ " code : {$result['faultCode']}\n".
+ " message: {$result['faultString']}\n");
return null;
}
return $result;
}
-
}
// vim:set et sw=4 sts=4 sws=4: