source: trunk/controller.php @ 2346

Revision 2346, 2.5 KB checked in by rodsouza, 14 years ago (diff)

Ticket #911 - Flexibilizando o formarto da obtenção do módulo corrente.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1<?php
2        if(!isset($GLOBALS['phpgw_info'])){
3                $GLOBALS['phpgw_info']['flags'] = array(
4                        'nonavbar'   => true,
5                        'currentapp' => $_SESSION['phpgw_info']['expresso']['currentapp'],
6                        'noheader'   => true
7                );
8        }
9        require_once './header.session.inc.php';
10
11        //      Explode action from cExecuteForm function
12        $cExecuteFormReturn = false;
13        if( isset( $_POST['_action'] ) ) {             
14                if($_FILES) {
15                        $count_files = $_POST['countFiles'];
16                        $array_files = array();                 
17                        for($idx = 1; $idx <= $count_files; $idx++) {           
18                                if($_FILES['file_'.$idx] && !$_FILES['file_'.$idx]['error'])
19                                        $array_files[] = $_FILES['file_'.$idx];                                         
20                        }
21                        $_POST['FILES'] = $array_files;
22                }                               
23                list($app,$class,$method) = explode('.',@$_POST['_action']);
24                $cExecuteFormReturn = true;
25        }
26        //      Explode action from cExecute function
27        else if($_GET['action'])
28                list($app,$class,$method) = explode('.',@$_GET['action']);
29        // NO ACTION
30        else
31                return $_SESSION['response'] = 'Post-Content-Length';
32
33        // Load dinamically class file.
34        if ( $app == '$this' )
35        {
36                $url = parse_url( $_SERVER[ 'HTTP_REFERER' ] );
37                if ( ( $pos = strpos( $url[ 'query' ], 'menuaction' ) ) !== false )
38                        $app = strstr( substr( $url[ 'query' ], $pos + 11 ), '.', true );
39                else
40                {
41                        $app = dirname( $_SERVER[ 'PHP_SELF' ] );
42                        if ( $app[ 0 ] != '/' )
43                                $app = "/{$app}";
44                        if ( $app[ strlen( $app ) - 1 ] != '/' )
45                                $app = "{$app}/";
46                        $app = $_SERVER[ 'SERVER_NAME' ] . $app;
47                        $app = dirname( substr( $_SERVER[ 'HTTP_REFERER' ], strpos( $_SERVER[ 'HTTP_REFERER' ], $app ) + strlen( $app ) ) );
48                }
49        }
50        else
51                if( strpos($app, '$this/') == 0 )
52                {
53                        $filename = str_replace('$this/','',$app) . '.php';
54                        include_once($filename);
55                        exit;
56                }
57        $filename = $app.'/inc/class.'.$class.'.inc.php';
58
59        include_once($filename);
60
61        // Create new Object  (class loaded).   
62        $obj = new $class;
63       
64        // Prepare parameters for execution.   
65        $params = array();
66       
67        // If array $_POST is not null , the submit method is POST.
68        if($_POST) {
69                $params = $_POST;
70        }
71        // If array $_POST is null , and the array $_GET > 1, the submit method is GET.
72        else if(count($_GET) > 1)       {               
73                array_shift($_GET);
74                $params = $_GET;
75        }
76
77        $result = array();
78       
79       
80        // if params is not empty, then class method with parameters.   
81        if($params)
82                $result = $obj -> $method($params);
83        else           
84                $result = $obj -> $method();
85               
86        // Return result serialized.   
87       
88
89        if(!$cExecuteFormReturn)
90                echo serialize($result);
91        else
92                $_SESSION['response'] = $result;
93?>
Note: See TracBrowser for help on using the repository browser.