1 | <?php |
---|
2 | /**************************************************************************\ |
---|
3 | * eGroupWare API - XML-RPC Server using builtin php functions * |
---|
4 | * This file written by Miles Lott <milos@groupwhere.org> * |
---|
5 | * Copyright (C) 2003 Miles Lott * |
---|
6 | * ------------------------------------------------------------------------ * |
---|
7 | * This library is free software; you can redistribute it and/or modify it * |
---|
8 | * under the terms of the GNU Lesser General Public License as published by * |
---|
9 | * the Free Software Foundation; either version 2.1 of the License, * |
---|
10 | * or any later version. * |
---|
11 | * This library is distributed in the hope that it will be useful, but * |
---|
12 | * WITHOUT ANY WARRANTY; without even the implied warranty of * |
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * |
---|
14 | * See the GNU Lesser General Public License for more details. * |
---|
15 | * You should have received a copy of the GNU Lesser General Public License * |
---|
16 | * along with this library; if not, write to the Free Software Foundation, * |
---|
17 | * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * |
---|
18 | \**************************************************************************/ |
---|
19 | |
---|
20 | |
---|
21 | // contains useful functions for xmlrpc methods |
---|
22 | class xmlrpc_server_shared |
---|
23 | { |
---|
24 | // convert a date-array or timestamp into a datetime.iso8601 string |
---|
25 | function date2iso8601($date) |
---|
26 | { |
---|
27 | if (!is_array($date)) |
---|
28 | { |
---|
29 | if(strstr($_SERVER['HTTP_USER_AGENT'],"vbXMLRPC")) |
---|
30 | { |
---|
31 | return date('Ymd\TH:i:s',$date); |
---|
32 | } |
---|
33 | return date('Y-m-d\TH:i:s',$date); |
---|
34 | } |
---|
35 | |
---|
36 | $formatstring = "%04d-%02d-%02dT%02d:%02d:%02d"; |
---|
37 | if(strstr($_SERVER['HTTP_USER_AGENT'],"vbXMLRPC")) |
---|
38 | { |
---|
39 | $formatstring = "%04d%02d%02dT%02d:%02d:%02d"; |
---|
40 | } |
---|
41 | return sprintf($formatstring, |
---|
42 | $date['year'],$date['month'],$date['mday'], |
---|
43 | $date['hour'],$date['min'],$date['sec']); |
---|
44 | } |
---|
45 | |
---|
46 | // convert a datetime.iso8601 string into a datearray or timestamp |
---|
47 | function iso86012date($isodate,$timestamp=False) |
---|
48 | { |
---|
49 | if (($arr = split('[-:T]',$isodate)) && count($arr) == 6) |
---|
50 | { |
---|
51 | foreach(array('year','month','mday','hour','min','sec') as $n => $name) |
---|
52 | { |
---|
53 | $date[$name] = (int)$arr[$n]; |
---|
54 | } |
---|
55 | return $timestamp ? mktime($date['hour'],$date['min'],$date['sec'], |
---|
56 | $date['month'],$date['mday'],$date['year']) : $date; |
---|
57 | } |
---|
58 | return False; |
---|
59 | } |
---|
60 | |
---|
61 | // translate cat-ids to array with id-name pairs |
---|
62 | function cats2xmlrpc($cats) |
---|
63 | { |
---|
64 | if (!is_object($GLOBALS['phpgw']->categories)) |
---|
65 | { |
---|
66 | $GLOBALS['phpgw']->categories = CreateObject('phpgwapi.categories'); |
---|
67 | } |
---|
68 | $xcats = array(); |
---|
69 | foreach($cats as $cat) |
---|
70 | { |
---|
71 | if ($cat) |
---|
72 | { |
---|
73 | $xcats[$cat] = stripslashes($GLOBALS['phpgw']->categories->id2name($cat)); |
---|
74 | } |
---|
75 | } |
---|
76 | return $xcats; |
---|
77 | } |
---|
78 | |
---|
79 | // translate cats back to cat-ids, creating / modifying cats on the fly |
---|
80 | function xmlrpc2cats($xcats) |
---|
81 | { |
---|
82 | if (!is_array($xcats)) |
---|
83 | { |
---|
84 | $xcats = array(); |
---|
85 | } |
---|
86 | elseif (!is_object($GLOBALS['phpgw']->categories)) |
---|
87 | { |
---|
88 | $GLOBALS['phpgw']->categories = CreateObject('phpgwapi.categories'); |
---|
89 | } |
---|
90 | $cats = array(); |
---|
91 | foreach($xcats as $cat => $name) |
---|
92 | { |
---|
93 | if ($id = $GLOBALS['phpgw']->categories->name2id($name)) |
---|
94 | { |
---|
95 | // existing cat-name use the id |
---|
96 | $cat = $id; |
---|
97 | } |
---|
98 | elseif (!($org_name = stripslashes($GLOBALS['phpgw']->categories->id2name($cat))) || $org_name == '--') |
---|
99 | { |
---|
100 | // new cat |
---|
101 | $cat = $GLOBALS['phpgw']->categories->add(array('name' => $name,'parent' => 0)); |
---|
102 | } |
---|
103 | elseif ($org_name != $name) |
---|
104 | { |
---|
105 | // cat-name edited |
---|
106 | list($cat_vals) =$GLOBALS['phpgw']->categories->return_single($cat); |
---|
107 | $cat_vals['name'] = $name; |
---|
108 | $GLOBALS['phpgw']->categories->edit($cat_vals); |
---|
109 | } |
---|
110 | $cats[] = (int)$cat; |
---|
111 | } |
---|
112 | return $cats; |
---|
113 | } |
---|
114 | |
---|
115 | // get list (array with id-name pairs) of all cats of $app |
---|
116 | function categories($complete = False,$app = '') |
---|
117 | { |
---|
118 | if (is_array($complete)) $complete = @$complete[0]; |
---|
119 | if (!$app) list($app) = explode('.',$this->last_method); |
---|
120 | |
---|
121 | if (!is_object($GLOBALS['phpgw']->categories)) |
---|
122 | { |
---|
123 | $GLOBALS['phpgw']->categories = CreateObject('phpgwapi.categories'); |
---|
124 | } |
---|
125 | if ($GLOBALS['phpgw']->categories->app_name != $app) |
---|
126 | { |
---|
127 | $GLOBALS['phpgw']->categories->categories('',$app); |
---|
128 | } |
---|
129 | $cats_arr = $GLOBALS['phpgw']->categories->return_sorted_array(0,False,'','','',True); |
---|
130 | $cats = array(); |
---|
131 | if (is_array($cats_arr)) |
---|
132 | { |
---|
133 | foreach($cats_arr as $cat) |
---|
134 | { |
---|
135 | foreach(array('name','description') as $name) |
---|
136 | { |
---|
137 | $cat[$name] = stripslashes($cat[$name]); |
---|
138 | } |
---|
139 | $cats[$cat['id']] = $complete ? $cat : $cat['name']; |
---|
140 | } |
---|
141 | } |
---|
142 | return $cats; |
---|
143 | } |
---|
144 | } |
---|
145 | |
---|
146 | if(empty($GLOBALS['phpgw_info']['server']['xmlrpc_type'])) |
---|
147 | { |
---|
148 | $GLOBALS['phpgw_info']['server']['xmlrpc_type'] = 'php'; |
---|
149 | } |
---|
150 | include_once(PHPGW_API_INC.SEP.'class.xmlrpc_server_' . $GLOBALS['phpgw_info']['server']['xmlrpc_type'] . '.inc.php'); |
---|