source: trunk/instant_messenger/controller.php @ 20

Revision 20, 2.4 KB checked in by niltonneto, 17 years ago (diff)

Inclusão do módulo Mensageiro Instantâneo no CVS.

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