source: companies/celepar/expressoCalendar/inc/controller.php @ 763

Revision 763, 2.6 KB checked in by niltonneto, 15 years ago (diff)

Importação inicial do Expresso da Celepar

Line 
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 = 'class.'.$class.'.inc.php';
31        else
32                $filename = '../'.$app.'/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              $dom->loadXML('<retorno>'.utf8_encode($result).'</retorno>');
77        }
78
79      $dom->normalizeDocument();
80                $retorno = $dom->saveXML();
81      header('Pragma: anytextexeptno-cache', true);
82      header('Content-type: text/xml, charset=UTF-8');
83                print $retorno;
84        }
85        else
86                $_SESSION['response'] = $result;
87
88   function encode(&$item, $val = 'encode')
89   {
90      switch( gettype($item) )
91      {
92         case 'object' :
93                     $item = get_object_vars($item);
94                     encode($item);
95         break;
96         case 'array' :
97                     array_walk_recursive($item, 'encode');
98         break;
99         default : $item = utf8_encode($item);
100      }
101   }
102?>
Note: See TracBrowser for help on using the repository browser.