1 | <?php |
---|
2 | // Explode action from cExecuteForm function |
---|
3 | $cExecuteFormReturn = false; |
---|
4 | $returnMode = $_REQUEST['returnMode']; |
---|
5 | if($_POST['_action']) { |
---|
6 | if($_FILES) { |
---|
7 | $count_files = $_POST['countFiles']; |
---|
8 | $array_files = array(); |
---|
9 | for($idx = 1; $idx <= $count_files; $idx++) { |
---|
10 | if($_FILES['file_'.$idx] && !$_FILES['file_'.$idx]['error']) |
---|
11 | $array_files[] = $_FILES['file_'.$idx]; |
---|
12 | } |
---|
13 | $_POST['FILES'] = $array_files; |
---|
14 | } |
---|
15 | list($app,$class,$method) = explode('.',@$_POST['_action']); |
---|
16 | $cExecuteFormReturn = true; |
---|
17 | } |
---|
18 | // Explode action from cExecute function |
---|
19 | else if($_GET['action']) |
---|
20 | { |
---|
21 | unset($_GET['returnMode']); |
---|
22 | list($app,$class,$method) = explode('.',@$_GET['action']); |
---|
23 | } |
---|
24 | // NO ACTION |
---|
25 | else |
---|
26 | return $_SESSION['response'] = 'false'; |
---|
27 | |
---|
28 | // Load dinamically class file. |
---|
29 | if($app == '$this') |
---|
30 | $filename = 'inc/class.'.$class.'.inc.php'; |
---|
31 | else |
---|
32 | $filename = '../'.$app.'/inc/class.'.$class.'.inc.php'; |
---|
33 | |
---|
34 | include_once($filename); |
---|
35 | |
---|
36 | // Create new Object (class loaded). |
---|
37 | $obj = new $class; |
---|
38 | |
---|
39 | // Prepare parameters for execution. |
---|
40 | $params = array(); |
---|
41 | |
---|
42 | // If array $_POST is not null , the submit method is POST. |
---|
43 | if($_POST) { |
---|
44 | $params = $_POST; |
---|
45 | } |
---|
46 | // If array $_POST is null , and the array $_GET > 1, the submit method is GET. |
---|
47 | else if(count($_GET) > 1) { |
---|
48 | array_shift($_GET); |
---|
49 | $params = $_GET; |
---|
50 | } |
---|
51 | |
---|
52 | $result = array(); |
---|
53 | |
---|
54 | |
---|
55 | // if params is not empty, then class method with parameters. |
---|
56 | if($params) |
---|
57 | $result = $obj -> $method($params); |
---|
58 | else |
---|
59 | $result = $obj -> $method(); |
---|
60 | |
---|
61 | // Return result json string into xml object. |
---|
62 | if(!$cExecuteFormReturn) |
---|
63 | { |
---|
64 | $dom = new DOMDocument;//('1.0', 'UTF-8'); |
---|
65 | |
---|
66 | if ( $returnMode == 'JSON') |
---|
67 | { |
---|
68 | $root = $dom->appendChild(new DOMElement('retorno')); |
---|
69 | encode($result, 'encode'); |
---|
70 | $result = ( !is_object($result) && !is_array($result) ) ? $result : json_encode($result); |
---|
71 | |
---|
72 | $root->appendChild($dom->createCDATASection($result)); |
---|
73 | } |
---|
74 | else |
---|
75 | { |
---|
76 | $_SESSION['phpgw_info']['instant_messenger']['debug2'] = $result; |
---|
77 | $dom->loadXML('<retorno>' . utf8_encode($result) . '</retorno>'); |
---|
78 | } |
---|
79 | |
---|
80 | $dom->normalizeDocument(); |
---|
81 | $retorno = $dom->saveXML(); |
---|
82 | header('Pragma: anytextexeptno-cache', true); |
---|
83 | header('Content-type: text/xml, charset=UTF-8'); |
---|
84 | print $retorno; |
---|
85 | } |
---|
86 | else |
---|
87 | $_SESSION['response'] = $result; |
---|
88 | |
---|
89 | function encode(&$item, $val = 'encode') |
---|
90 | { |
---|
91 | switch( gettype($item) ) |
---|
92 | { |
---|
93 | case 'object' : |
---|
94 | $item = get_object_vars($item); |
---|
95 | encode($item); |
---|
96 | break; |
---|
97 | case 'array' : |
---|
98 | array_walk_recursive($item, 'encode'); |
---|
99 | break; |
---|
100 | default : $item = utf8_encode($item); |
---|
101 | } |
---|
102 | } |
---|
103 | ?> |
---|