"TYPO3 4.0.1: typo3_src-4.0.1/typo3/sysext/adodb/adodb/contrib/toxmlrpc.inc.php Source File", "datetime" => "Sat Dec 2 19:22:25 2006", "date" => "2 Dec 2006", "doxygenversion" => "1.4.6", "projectname" => "TYPO3 4.0.1", "projectnumber" => "4.0.1" ); get_header($doxygen_vars); ?>

toxmlrpc.inc.php

00001 <?php
00020     require_once('xmlrpc.inc');
00021     if (!defined('ADODB_DIR')) require_once('adodb.inc.php');
00022             
00026     function rs2xmlrpcval(&$adodbrs) {
00027 
00028         $header =& rs2xmlrpcval_header($adodbrs);
00029         $body =& rs2xmlrpcval_body($adodbrs);
00030 
00031         // put it all together and build final xmlrpc struct
00032         $xmlrpcrs =& new xmlrpcval ( array(
00033                 "header" => $header,
00034                 "body" => $body,
00035                 ), "struct");
00036 
00037         return $xmlrpcrs;
00038 
00039     }
00040 
00044     function rs2xmlrpcval_header($adodbrs)
00045     {
00046         $numfields = $adodbrs->FieldCount();
00047         $numrecords = $adodbrs->RecordCount();
00048 
00049         // build structure holding recordset information
00050         $fieldstruct = array();
00051         for ($i = 0; $i < $numfields; $i++) {
00052             $fld = $adodbrs->FetchField($i);
00053             $fieldarray = array();
00054             if (isset($fld->name))
00055                 $fieldarray["name"] =& new xmlrpcval ($fld->name);
00056             if (isset($fld->type))
00057                 $fieldarray["type"] =& new xmlrpcval ($fld->type);
00058             if (isset($fld->max_length))
00059                 $fieldarray["max_length"] =& new xmlrpcval ($fld->max_length, "int");
00060             if (isset($fld->not_null))
00061                 $fieldarray["not_null"] =& new xmlrpcval ($fld->not_null, "boolean");
00062             if (isset($fld->has_default))
00063                 $fieldarray["has_default"] =& new xmlrpcval ($fld->has_default, "boolean");
00064             if (isset($fld->default_value))
00065                 $fieldarray["default_value"] =& new xmlrpcval ($fld->default_value);
00066             $fieldstruct[$i] =& new xmlrpcval ($fieldarray, "struct");
00067         }
00068         $fieldcount =& new xmlrpcval ($numfields, "int");
00069         $recordcount =& new xmlrpcval ($numrecords, "int");
00070         $sql =& new xmlrpcval ($adodbrs->sql);
00071         $fieldinfo =& new xmlrpcval ($fieldstruct, "array");
00072 
00073         $header =& new xmlrpcval ( array(
00074                 "fieldcount" => $fieldcount,
00075                 "recordcount" => $recordcount,
00076                 "sql" => $sql,
00077                 "fieldinfo" => $fieldinfo
00078                 ), "struct");
00079 
00080         return $header;
00081     }
00082 
00087     function rs2xmlrpcval_body($adodbrs)
00088     {
00089         $numfields = $adodbrs->FieldCount();
00090 
00091         // build structure containing recordset data
00092         $adodbrs->MoveFirst();
00093         $rows = array();
00094         while (!$adodbrs->EOF) {
00095             $columns = array();
00096             // This should work on all cases of fetch mode: assoc, num, both or default
00097             if ($adodbrs->fetchMode == 'ADODB_FETCH_BOTH' || count($adodbrs->fields) == 2 * $adodbrs->FieldCount())
00098                 for ($i = 0; $i < $numfields; $i++)
00099                     if ($adodbrs->fields[$i] === null)
00100                         $columns[$i] =& new xmlrpcval ('');
00101                     else
00102                         $columns[$i] =& xmlrpc_encode ($adodbrs->fields[$i]);
00103             else
00104                 foreach ($adodbrs->fields as $val)
00105                     if ($val === null)
00106                         $columns[] =& new xmlrpcval ('');
00107                     else
00108                         $columns[] =& xmlrpc_encode ($val);
00109 
00110             $rows[] =& new xmlrpcval ($columns, "array");
00111 
00112             $adodbrs->MoveNext();
00113         }
00114         $body =& new xmlrpcval ($rows, "array");
00115 
00116         return $body;    
00117     }
00118     
00122     function rs2xmlrpcstring (&$adodbrs) {
00123         $xmlrpc = rs2xmlrpcval ($adodbrs);
00124         if ($xmlrpc)
00125           return $xmlrpc->serialize();
00126         else
00127           return null;
00128     }
00129 
00135     function xmlrpcval2rs (&$xmlrpcval) {
00136 
00137         $fields_array = array();
00138         $data_array = array();
00139  
00140         // rebuild column information  
00141         $header =& $xmlrpcval->structmem('header');
00142         
00143         $numfields = $header->structmem('fieldcount');
00144         $numfields = $numfields->scalarval();
00145         $numrecords = $header->structmem('recordcount');
00146         $numrecords = $numrecords->scalarval();
00147         $sqlstring = $header->structmem('sql');
00148         $sqlstring = $sqlstring->scalarval();
00149         
00150         $fieldinfo =& $header->structmem('fieldinfo');
00151         for ($i = 0; $i < $numfields; $i++) {
00152             $temp =& $fieldinfo->arraymem($i);
00153             $fld =& new ADOFieldObject();
00154             while (list($key,$value) = $temp->structeach()) {
00155                 if ($key == "name") $fld->name = $value->scalarval();
00156                 if ($key == "type") $fld->type = $value->scalarval();
00157                 if ($key == "max_length") $fld->max_length = $value->scalarval();
00158                 if ($key == "not_null") $fld->not_null = $value->scalarval();
00159                 if ($key == "has_default") $fld->has_default = $value->scalarval();
00160                 if ($key == "default_value") $fld->default_value = $value->scalarval();
00161             } // while
00162             $fields_array[] = $fld;
00163         } // for
00164 
00165         // fetch recordset information into php array
00166         $body =& $xmlrpcval->structmem('body');
00167         for ($i = 0; $i < $numrecords; $i++) {
00168             $data_array[$i]= array();
00169             $xmlrpcrs_row =& $body->arraymem($i);
00170             for ($j = 0; $j < $numfields; $j++) {
00171                 $temp =& $xmlrpcrs_row->arraymem($j);
00172                 $data_array[$i][$j] = $temp->scalarval();
00173             } // for j
00174         } // for i
00175 
00176         // finally build in-memory recordset object and return it
00177         $rs =& new ADORecordSet_array();
00178         $rs->InitArrayFields($data_array,$fields_array);
00179         return $rs;
00180 
00181     }
00182 
00183 ?>