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